SETNJA - Setnja

In an infinite binary tree:

  • Each node has exactly two children – a left and a right child.
  • If a node is labeled with the integer X, then its left child is labeled 2*X and its right child 2*X+1.
  • The root of the tree is labeled 1.

A walk on the binary tree starts in the root. Each step in the walk is either a jump onto the left child, onto the right child, or pause for rest (stay in the same node).

A walk is described with a string of letters 'L', 'R' and 'P':

  • 'L' represents a jump to the left child;
  • 'R' represents a jump to the right child;
  • 'P' represents a pause.

The value of the walk is the label of the node we end up on. For example, the value of the walk LR is 5, while the value of the walk RPP is 3.

A set of walks is described by a string of characters 'L', 'R', 'P' and '*'. Each '*' can be any of the three moves; the set of walks contains all walks matching the pattern.

For example, the set L*R contains the walks LLR, LRR and LPR. The set ** contains the walks LL, LR, LP, RL, RR, RP, PL, PR and PP.

Finally, the value of a set of walks is the sum of values of all walks in the set.

Calculate the value of the given set of walks.

Input

A string describing the set. Only characters 'L', 'R', 'P' and '*' will appear and there will be at most 10000 of them.

Output

Output the value of the set.

Example

Input:
L*R

Output:
25

Được gửi lên bởi:Race with time
Ngày:2008-11-16
Thời gian chạy:1s
Giới hạn mã nguồn:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Ngôn ngữ cho phép:Tất cả ngoại trừ: ERL GOSU JS-RHINO NODEJS PERL6 PYPY RUST SED VB.NET
Nguồn bài:COCI 2008-2009

hide comments
2021-05-27 18:04:14
Tham khảo: https://vnspoj.github.io/problems/SETNJA
2017-12-18 10:10:18
BigNum base = 10^9 ae cẩn thận
2017-11-22 02:12:17
sao ko số lớn là một tội ác :)))
2016-08-03 05:07:07
Code tối ưu thì để int64 vẫn AC nhé :)
2016-08-02 10:40:01
viết sai số lớn làm mất 1 hit :(
2016-07-29 05:48:51 Phong
vkl đổi sang Qword hết tle ... Quỳ ..
2016-07-02 12:27:06 Nguyễn Vĩnh Thịnh
cảm ơn comment qword
bạn đã cứu rỗi mình =))
2016-04-23 05:21:13
QHD mà sao vẫn không AC :=((
2016-01-03 10:00:47 Prismatic
để qword tránh tle :v
2015-05-13 09:46:13 Stupid Dog
bó tay với TLE, chỉ còn cách dùng BigInteger Java
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.