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

N, Q = map(int, input().split())
s = str(input())

t = []
d = []

for _ in range(Q):
    ti, di = map(str, input().split())
    t.append(ti)
    d.append(di)
    
class Golem:
    def __init__(self, number, text):
        self.number = number
        self.text = text
        #self.life = True
        
    def move(self, dist):
        if dist == 'L':
            if self.number == 0:
                return 'DEL'
            else:
                self.number -= 1
                self.text = s[self.number]
                return self.text
        if dist == 'R':
            if self.number == len(s)-1:
                return 'DEL'
            else:
                self.number += 1
                self.text = s[self.number]
                return self.text
                

c_dict = {}
for i, c in enumerate(s):
    if c in c_dict:
        c_dict[c].append(Golem(i, c))
    else:
        c_dict[c] = [Golem(i, c)]
        
for ti, di in zip(t, d):
    if not ti in c_dict:
        continue
    golems = c_dict[ti][:]
    c_dict[ti] = []
    for g in golems:
        res = g.move(di)
        if res != 'DEL':
            c_dict[res].append(g)

#print(c_dict)
ans = 0
for k, v in c_dict.items():
    ans += len(v)
print(ans)

    

### FIXED CODE ###

N, Q = map(int, input().split())
s = str(input())

t = []
d = []

for _ in range(Q):
    ti, di = input().split()
    t.append(ti)
    d.append(di)
    
LEFT_DIE = -1
RIGHT_DIE = N

def is_dead(i):
    for ti, di in zip(t, d):
        if s[i] == ti:
            if di == 'L':
                i -= 1
            if di == 'R':
                i += 1
            if i == LEFT_DIE:
                return LEFT_DIE
            if i == RIGHT_DIE:
                return RIGHT_DIE
    return 0

low = -1
high = N;
# LEFT
while high - low > 1:
    mid = (low + high) // 2;
    if is_dead(mid) == LEFT_DIE:
        low = mid
    else:
        high = mid
left_edge = high

low = -1
high = N;
# RIGHT
while high - low > 1:
    mid = (low + high) // 2;
    if is_dead(mid) == RIGHT_DIE:
        high = mid
    else:
        low = mid
right_edge = low

#print(left_edge, right_edge)
ans_s = s[left_edge:right_edge+1]
#print(ans_s)
ans = len(ans_s)
print(ans)
### BUGGY CODE ###

import math
import sys

sys.setrecursionlimit(10 ** 7)

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


def split(word):
    return [char for char in word]


normalized_s_list = [''.join(sorted(split(s))) for s in s_list]

uniqued_s_list = set(normalized_s_list)
result = 0
for s in uniqued_s_list:
    count = normalized_s_list.count(s)
    result += (1 / 2) * count * (count - 1)

print(int(result))


### FIXED CODE ###

import copy
import math
import sys

sys.setrecursionlimit(10 ** 7)

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


def split(word):
    return [char for char in word]


normalized_s_list = sorted([''.join(sorted(split(s))) for s in s_list])

uniqued_s_list = sorted(list(set(normalized_s_list)))

j = 0
counter = 0
result = 0
for s in normalized_s_list:
    if s == uniqued_s_list[j]:
        counter += 1
    else:
        result += (1 / 2) * counter * (counter - 1)
        j += 1
        counter = 1  # このとき s と uniqued_s_list[j] は同じはずなので

result += (1 / 2) * counter * (counter - 1)
print(int(result))
### BUGGY CODE ###

def manipulate(x, k):
	return abs(x - k)
	

n, k = list(map(int, input().split()))

while n > k / 2:
	if k == 1:
		n = 0
		break
		
	if k == 0:
		break
		
	n = manipulate(n, k)
	
	
print(n)

### FIXED CODE ###

def manipulate(x, k):
	return abs(x - k)

n, k = list(map(int, input().split()))
n = n % k

while n > k / 2:	
	n = manipulate(n, k)
	
print(n)
### BUGGY CODE ###

import sys
import heapq
import copy

n = int(input())
a = []

for _ in range(n):
	a.append(-1 * int(input()))

for i in range(n):
	b = copy.deepcopy(a)
	b.remove(a[i])
	heapq.heapify(b)
	maximum = heapq.heappop(b) * (-1)
	if maximum == a[i]:
		print(heapq.heappop(b) + (-1))
	else:
		print(maximum)


### FIXED CODE ###

import sys
import heapq
import copy

n = int(input())
a = []

for _ in range(n):
	a.append(-1 * int(input()))

b = copy.deepcopy(a)
heapq.heapify(b)

for i in range(n):
	maximum = heapq.heappop(b)
	if maximum == a[i]:
		tmp = maximum
		maximum = heapq.heappop(b)
		print(maximum * (-1))
		heapq.heappush(b,tmp)
	else:
		print(maximum * (-1))
	heapq.heappush(b,maximum)
### BUGGY CODE ###

n=int(input())
a=list(map(int,input().split()))
b=[]
for i in range(n):
  x=a.index(i+1)
  b.append(str(x+1))
print(" ".join(b))

### FIXED CODE ###

n=int(input())
a=list(map(int,input().split()))
b=[0]*n
for i in range(n):
  b[a[i]-1]=str(i+1)
print(" ".join(b))
### BUGGY CODE ###

N,X,Y=map(int,input().split())

cost=[[float("inf") for i in range(N)] for i in range(N)]
for i in range(N-1):
  cost[i][i+1]=1
  cost[i+1][i]=1  
cost[X-1][Y-1]=1
cost[Y-1][X-1]=1
#print(cost)

def dijkstra(s,n,w,cost):
    #始点sから各頂点への最短距離
    #n:頂点数,　w:辺の数, cost[u][v] : 辺uvのコスト(存在しないときはinf)
    d = [float("inf")] * n
    used = [False] * n
    d[s] = 0
    
    while True:
        v = -1
        #まだ使われてない頂点の中から最小の距離のものを探す
        for i in range(n):
            if (not used[i]) and (v == -1):
               v = i
            elif (not used[i]) and d[i] < d[v]:
                v = i
        if v == -1:
               break
        used[v] = True
               
        for j in range(n):
               d[j] = min(d[j],d[v]+cost[v][j])
    return d

################################

d=dict()
for i in range(N):
  a = dijkstra(i,N,N,cost)
  for item in a:
    if item in d: 
      d[item] += 1
    else:
      d[item] =1
#print(d)

for j in range(1,N):
  if j in d:
    print(d[j]//2)
  else:
    print(0)

### FIXED CODE ###

N,X,Y=map(int,input().split())
cost=[[] for _ in range(N)]

for i in range(N-1):
  cost[i].append(i+1)
for j in range(1,N):
  cost[j].append(j-1)

cost[X-1].append(Y-1)
cost[Y-1].append(X-1)
#print(cost)

def bfs(v):
    d=[-1]*N
    d[v]=0
    q=[v]
    c=1
    while q:
        q1=[]
        for i in q:
            for j in cost[i]:
                if d[j]==-1:
                    d[j]=c
                    q1.append(j)
        q=q1
        c+=1
        #print(d,q)
    return d

d=dict()
for m in range(N):
  tmp=bfs(m)
  #print(tmp)
  for num in tmp:
    if num not in d:
      d[num]=1
    else:
      d[num] += 1
#print(d)

for z in range(1,N):
  if z in d:
    print(d[z]//2)
  else:
    print(0)
### BUGGY CODE ###

import sys, bisect, copy
# import numpy as np
# import scipy
from collections import defaultdict
input = sys.stdin.readline
mod = 998244353
def main():
    n,s = map(int,input().split())
    a = list(map(int, input().split()))
    dp = [[defaultdict(int) for _ in range(s+1)] for _ in range(n+1)]
    dp[0][0][0] = 1
    ans = 0
    for i in range(n):
        for j in range(s,-1,-1):
            if j-a[i] < 0:
                continue
            if dp[i][j-a[i]] == []:
                continue
            for e in dp[i][j-a[i]]:
                if not dp[i][j-a[i]][e]:
                    continue
                dp[i+1][j][e+1] += dp[i][j-a[i]][e]
            if j == s and len(dp[i+1][j]):
                for e in dp[i+1][j]:
                    ans += dp[i+1][j][e]*pow(2,n-e,mod)
                    ans %= mod
        for j in range(s-1,-1,-1):
            for e in dp[i][j]:
                dp[i+1][j][e] += dp[i][j][e]
    print(ans)
if __name__ == "__main__":
    main()

### FIXED CODE ###

import sys
from collections import defaultdict
input = sys.stdin.readline
mod = 998244353
def extgcd(a,b):
    r = [1,0,a]
    w = [0,1,b]
    while w[2] != 1:
        q = r[2]//w[2]
        r2 = w
        w2 = [r[0]-q*w[0],r[1]-q*w[1],r[2]-q*w[2]]
        r = r2
        w = w2
    return [w[0],w[1]]
def mod_inv(a,m):
    x = extgcd(a,m)[0]
    return ( m + x%m ) % m
def main():
    n,s = map(int,input().split())
    a = list(map(int, input().split()))
    dp = [[0 for _ in range(s+1)] for _ in range(n+1)]
    dp[0][0] = pow(2,n,mod)
    MODINV2 = mod_inv(2,mod)
    ans = 0
    for i in range(n):
        for j in range(s,-1,-1):
            if j-a[i] < 0:
                continue
            dp[i+1][j] += dp[i][j-a[i]]*MODINV2
            dp[i+1][j] %= mod
        for j in range(s,-1,-1):
            if j == s:
                ans += dp[i+1][j]
                ans %= mod
            else:
                dp[i+1][j] += dp[i][j]
                dp[i+1][j] %= mod
    print(ans)
if __name__ == "__main__":
    main()
### BUGGY CODE ###

import sys
input = sys.stdin.readline

N, K = map(int,input().split())
td = [list(map(int, input().split())) for _ in range(N)]
td.sort(key=lambda x: (x[0],x[1]),reverse=True)

x= []
y= []
y.append(td[0][1])
for i in range(1,N):
    if td[i][0] != td[i-1][0]:
        y.append(td[i][1])
    else:
        x.append(td[i][1])
x.sort(reverse=True)
y.sort(reverse=True)
ans = 0
for i in range(1,min(K,len(y))+1):
    ans = max(ans, sum(y[:i])+sum(x[:max(0,K-i)])+i*i)
print(ans)


### FIXED CODE ###

import sys
input = sys.stdin.readline

N, K = map(int,input().split())
td = [list(map(int, input().split())) for _ in range(N)]
td.sort(key=lambda x: (x[0],x[1]),reverse=True)

x= []
y= []
y.append(td[0][1])
for i in range(1,N):
    if td[i][0] != td[i-1][0]:
        y.append(td[i][1])
    else:
        x.append(td[i][1])
x.sort(reverse=True)
y.sort(reverse=True)
ans = 0
sum_y = 0
sum_x = []
tmp = 0
sum_x.append(0)
for i in range(len(x)):
    tmp += x[i]
    sum_x.append(tmp)

for i in range(1,min(K,len(y))+1):
    sum_y += y[i-1]
    if len(sum_x) < K-i+1: continue
    ans = max(ans, sum_y + sum_x[K-i] + i*i)
    
print(ans)
### BUGGY CODE ###

import sys
import math
import itertools
# num = []
# for e in sys.stdin:
#     num.append(map(int, e.split()))

N = int(input())





for n in range(1, N+1):
    count = 0;
    max = min(int(math.sqrt(n)), int(n/2))
    l = []
    for i in range(1, max+1):
        l.append(i)
    h = itertools.combinations_with_replacement(l, 3)

    for i,j,k in h:
        if n == i**2 + j**2 + k**2 + i*j + j*k + k*i:
            if(i==j==k):
                count+=1
            elif(i==j or j==k or i == k):
                count+=3
            else:
                count+=6
    print(count)
    # for i in range(1, max+1):
    #     for j in range(1, max+1):
    #         for k in range(1, max+1):
    #             num = i**2 + j**2 + k**2 + i*j + j*k + k*i
    #             if n == num:
    #                 count+=1
    # print(count)


    # print(max)


### FIXED CODE ###

import sys
import math
import itertools
# num = []
# for e in sys.stdin:
#     num.append(map(int, e.split()))

N = int(input())

count = []
for i in range(N):
    count.append(0)

max = min(int(math.sqrt(N)), int(N/2))
l = []

for i in range(1, max+1):
    l.append(i)

h = itertools.combinations_with_replacement(l, 3)

# print(h)
for i,j,k in h:
    n = (i+j+k)**2 - i*j - j*k - k*i
    # print(n)

    if(n <=N):
        if(i==j==k):
            count[n-1]+=1
        elif(i==j or j==k or i == k):
            count[n-1]+=3
        else:
            count[n-1]+=6


for c in count:
    print(c)

# for n in range(1, N+1):
#     count = 0;
#     max = min(int(math.sqrt(n)), int(n/2))
#     l = []
#
#     for i in range(1, max+1):
#         l.append(i)
#
#     h = list(itertools.combinations_with_replacement(l, 3))
#     for i,j,k in h:
#         if n == (i+j+k)**2 - i*j - j*k - k*i:
#             if(i==j==k):
#                 count+=1
#             elif(i==j or j==k or i == k):
#                 count+=3
#             else:
#                 count+=6

    # for i in range(1, max+1):
    #     for j in range(1, max+1):
    #         for k in range(1, max+1):
    #             num = i**2 + j**2 + k**2 + i*j + j*k + k*i
    #             if n == num:
    #                 count+=1
    # print(count)


    # print(max)


    # l = []
    #
    # for i in range(1, max+1):
    #     l.append(i)
    #
    # # h = itertools.combinations_with_replacement(l, 3)
    #
    # for i,j,k in h:
    #     if n == i**2 + j**2 + k**2 + i*j + j*k + k*i:
    #         if(i==j==k):
    #             count+=1
    #         elif(i==j or j==k or i == k):
    #             count+=3
    #         else:
    #             count+=6
    # print(count)
### BUGGY CODE ###

# -*- coding: utf-8 -*-

"""
全探索
・再帰で作る
"""

N = int(input())
aN = list(map(int, input().split()))
Q = int(input())
mQ = list(map(int, input().split()))

def dfs(cur, depth, ans):
    # 終了条件
    if cur == ans:
        return True
    # 全探索
    for i in range(depth, N):
        if dfs(cur+aN[i], i+1, ans):
            return True
    # 見つからなかった
    return False

for i in range(Q):
    if dfs(0, 0, mQ[i]):
        print('yes')
    else:
        print('no')



### FIXED CODE ###

# -*- coding: utf-8 -*-

"""
全探索
・再帰で作る
・2^20でTLEするからメモ化した
"""

N = int(input())
aN = list(map(int, input().split()))
Q = int(input())
mQ = list(map(int, input().split()))

def dfs(cur, depth, ans):
    # 終了条件
    if cur == ans:
        return True
    # memo[現在位置]に数値curがあれば、そこから先はやっても同じだからやらない
    if cur in memo[depth]:
        return False
    memo[depth].add(cur)
    # 全探索
    for i in range(depth, N):
        if dfs(cur+aN[i], i+1, ans):
            return True
    # 見つからなかった
    return False

for i in range(Q):
    memo = [set() for j in range(N+1)]
    if dfs(0, 0, mQ[i]):
        print('yes')
    else:
        print('no')
### BUGGY CODE ###

import copy
N = int(input())
v = list(map(int,input().split()))
values = list(set(v))
d = {}
for i in range(len(values)):
    number  = v.count(values[i])
    d[values[i]] = number
d  = sorted(d.items(), key=lambda x: x[1],reverse=True)

most_common = d[0][0]
#v_ = [i for i in v if i != most_common]
try:
    second_common = d[1][0]
except:
    second_common = most_common + 1
#print(v)
vv = copy.deepcopy(v)
cnt = 0
for j in range(N):
    if j % 2 != 0:
        if v[j] != most_common:
            #v[j] = most_common
            cnt += 1
    else:
        if v[j] != second_common:
            #v[j] = second_common
            cnt += 1
ccnt = 0
for j in range(N):
    if j % 2 != 0:
        if vv[j] != second_common:
            #vv[j] = second_common
            ccnt += 1
    else:
        if vv[j] != most_common:
            #vv[j] = most_common
            ccnt += 1
#print(v,cnt)
#print(vv,ccnt)
print(min(cnt,ccnt))

### FIXED CODE ###

from collections import Counter
n = int(input())
v = list(map(int,input().split()))
o = Counter(v[::2]).most_common()
o.append((0,0))
e = Counter(v[1::2]).most_common()
e.append((0,0))
if o[0][0] == e[0][0]:
    ans = min(n - o[0][1] - e[1][1], n - o[1][1] - e[0][1])
else:
    ans = n - o[0][1] - e[0][1]
print(ans)
### BUGGY CODE ###

MOD = 998244353

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

F = [0 for _ in range(S + 1)]
res = 0

for i in range(N):
    F[0] += 1
    for j in range(S + 1)[::-1]:
        if j - A[i] >= 0:
            F[j] += F[j - A[i]]
    res += F[S]
    res %= MOD

print(res)

### FIXED CODE ###

MOD = 998244353

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

F = [0 for _ in range(S + 1)]
res = 0

for i in range(N):
    F[0] += 1
    for j in range(S + 1)[::-1]:
        if j - A[i] >= 0:
            F[j] += F[j - A[i]]
    res += F[S]
    res %= MOD

print(res)
### BUGGY CODE ###

def count(num_lst):
    count = [0]*60
    for num in num_lst:
        for i in range(60):
            if num & (1<<i):
                count[i] += 1
    return count

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

count = count(num_list)
ans = 0
for i in range(60):
    ans += (2**i * count[i] * (n - count[i])) % mod
    ans %= mod
print(ans)

### FIXED CODE ###

import numpy as np

n = int(input())
num_list = np.array(input().split(), dtype = np.int64)
mod = 10**9 + 7

ans = 0
for i in range(60):
    b = np.count_nonzero(num_list >> i & 1)
    if i==0:
        pow_two = 1
    else:
        pow_two = pow_two * 2 % mod
    ans += pow_two * b * (n-b) % mod
    ans %= mod
    
print(ans)
### BUGGY CODE ###

n = int(input())
list = []
ans = 0
for i in range(n):
  list.append(input())
  list[i] = ''.join(sorted(list[i]))
  ans += list.count(list[i]) -1
print(ans)

### FIXED CODE ###

n = int(input())
dict= {}
ans = 0
for i in range(n):
  temp = ''.join(sorted(input()))
  if temp in dict:
    dict[temp] += 1
    ans += dict[temp]
  else:
    dict.update([(temp, 0)])
print(ans)
### BUGGY CODE ###

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

def cal(a,b,c):
  a1 = b+c
  b1 = a+c
  c1 = b+c
  return(a1,b1,c1)
  
  
for i in range(K):
  A,B,C=cal(A,B,C)
  
if A-B>10**18:
  print('Unfair')
  
else:
  print(A-B)



### FIXED CODE ###

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

if K%2==0:
  print(A-B)
  
else:
  print(-A+B)
### BUGGY CODE ###

n,k =map(int,input().split())
h = list(map(int,input().split()))
#print(n,k,h)

ans = [0]*n

for i in range(n):
  s = float("inf")
  for j in range(1,k+1):
    if i == 0:
      s = 0
    if (i - j) >= 0:
      x = abs(h[i] - h[i-j]) + ans[i-j]
      if s > x:
        s = x
  ans[i] = s


#print(ans)
print(ans[n-1])

### FIXED CODE ###

n,k =map(int,input().split())
h = list(map(int,input().split()))
#print(n,k,h)
 
ans = [0]*n
 
for i in range(n):
  s = float("inf")
  for j in range(1,k+1):
    if i == 0:
      s = 0
    if (i - j) >= 0:
      x = abs(h[i] - h[i-j]) + ans[i-j]
      if s > x:
        s = x
  ans[i] = s
 
 
#print(ans)
print(ans[n-1])
### BUGGY CODE ###


N = int(input())
aA = sorted([int(_) for _ in input().split()],reverse=True)
aA1 = [ _ for _ in aA if _ % 2 ]
aA0 = [ _ for _ in aA if _ % 2 == 0 ]


def searchPair(aD):
    iL = len(aD)
    dsT =set()
    iC = 0
    for i in range(iL):
        for j in range(i+1,iL):
            if i in dsT or j in dsT:
                continue
            iWa =  aD[i] + aD[j]
            if not ( iWa & (iWa - 1)):
                dsT.add(i)
                dsT.add(j)
                iC += 1
                break

    return iC
iC = 0
iC += searchPair(aA1)
iC += searchPair(aA0)
print(iC)


### FIXED CODE ###

N = int(input())
dA1 ={}
dA0 ={}
def lenbin(a):
    return len(bin(a)) - 2
def addData(oDict,a):
    if a in oDict:
        oDict[a]+=1
    else:
        oDict[a]=1
for a in input().split():
    a = int(a)
    if a % 2 :
        addData(dA1,a)
    else:
        addData(dA0,a)
def searchPair(oD):
    iC = 0
    for a in sorted(oD.keys(),reverse=True):
        t = ( 1 << lenbin(a)) - a
        if t == a:
            iAT = oD[a] // 2
            iC += iAT
            oD[a] -= iAT *2
        elif t in oD:
            iAT = min(oD[a],oD[t])
            iC += iAT
            oD[a] -= iAT
            oD[t] -= iAT
    return iC
#iC = 0
#iC += searchPair(dA1)
#iC += searchPair(dA0)
print(searchPair(dA1)+searchPair(dA0))
### BUGGY CODE ###

import sys
largenum = 10**18
def main():
    n = int(input())
    a = list(map(int, input().split()))

    r = 1
    for i1 in range(n):
        r *= a[i1]
    if r > largenum:
        print('-1')
        sys.exit()
    else:
        print(r)

if __name__ == '__main__':
    main()


### FIXED CODE ###

import sys
input = sys.stdin.readline
largenum = 10**18
from functools import reduce
from operator import mul
def main():
    n = int(input())
    a = list(map(int, input().split()))

    if 0 in a:
        print(0)
        sys.exit()
    r = 1
    for i1 in range(n):
        r *= a[i1]
        if r > largenum:
            print(-1)
            sys.exit()
    print(r)


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

N, K = map(int, input().split())
P = list(map(int, input().split()))
lst = []
for x in P:
  res = 0
  for y in range(x):
    c = 1/x
    res += (y+1)*c

  lst.append(res)

s = [0] 
s[0] = 0
for i in range(0, N):
  s.append(s[i] + lst[i])

res = -1
for i in range(N-K+1):
  sum = s[i+K]-s[i]
  res = max(res, sum)

print("{:.6f}".format(res))
 

### FIXED CODE ###

N, K = map(int, input().split())
P = list(map(int, input().split()))
lst = [0]
for x in P:
  lst.append(lst[-1] + (x+1)/2)

res = -1
for i in range(N-K+1):
  sum = lst[i+K]-lst[i]
  res = max(res, sum)

print("{:.6f}".format(res))
### BUGGY CODE ###

S = input()
Q = int(input())
r = False
for i in range(Q):
  q = list(input().split())
  if q[0] == '1':
    if r:
      r = False
    else:
      r = True
  else:
    if (q[1] == '1' and not r) or (q[1] == '2' and r):
      S = q[2]+S
    else:
      S = S+q[2]
print(''.join(list(reversed(S))) if r else S)


### FIXED CODE ###

S = input()
Q = int(input())
r = False
F = []
B = []
for i in range(Q):
  q = list(input().split())
  if q[0] == '1':
    if r:
      r = False
    else:
      r = True
  else:
    if (q[1] == '1' and not r) or (q[1] == '2' and r):
      F.append(q[2])
    else:
      B.append(q[2])

if r:
  print(''.join(B[::-1]+list(reversed(S))+F))
else:
  print(''.join(F[::-1]+list(S)+B))
### BUGGY CODE ###

import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(IN())
mod=1000000007

#+++++

def main():
	#a = int(input())
	#b , c = tin()
	s = list(input())
	while True:
		p=''
		pi=-1
		#pa(s)
		for i, c in enumerate(s):
			if p == 'S' and c == 'T':
				s[pi] = 'e'
				s[i] = 'e'
				#print(s)
				break
			elif c == 'e':
				pass
			else:
				p=c
				pi=i
		else:
			break
		
	return len(s)-s.count('e')
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

### FIXED CODE ###

import sys

input_methods=['clipboard','file','key']
using_method=1
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(IN())
mod=1000000007

#+++++

def main():
	#a = int(input())
	#b , c = tin()
	s = list(input())[:-1]

	count_s = 0
	delete_num=0
	for c in s:
		if c == 'S':
			count_s+=1
		else: #if c == 'T':
			if count_s == 0:
				pass
			else:
				count_s-=1
				delete_num+=2
	return len(s)-delete_num
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)
### BUGGY CODE ###

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

is_possible = False
for i in range(n+1):
    for j in range(n-i+1):
        for k in range(n-i-j+1):
            if (i + j + k) != n:
                continue
            total = i*10000 + j*5000 + k*1000
            if total == y:
                is_possible = True
                print("{} {} {}".format(i, j, k))
                break
        else:
            continue
        break
    else:
        continue
    break

if is_possible is False:
    print("-1 -1 -1")


### FIXED CODE ###

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

is_possible = False

for i in range(n+1):
    for j in range(n-i+1):
        k = n - i - j
        total = i*10000 + j*5000 + k*1000
        if total == y:
            is_possible = True
            print("{} {} {}".format(i, j, k))
            break
    if is_possible:
        break

if is_possible is False:
    print("-1 -1 -1")