CARL - Carl

Professor Octastichs has invented a new programming language, Carl. An expression in Carl may be a positive or negative integer, or may be of the form (p e1 e2) where p is a real number between 0 and 1 (inclusive) and e1 and e2 are Carl expressions. An integer represents itself and (p e1 e2) represents x + y where x is the value of e1 and y is the value of e2 with probability p, otherwise it represents x - y.

Given a Carl expression, what is its expected value?

Input

Input consists of several Carl expressions, one per line, followed by a line containing ().

Output

For each expression, output its expected value to two decimal places.

Score

Score is the length of your source program.

Example

Input:
7
(.5 3 9)
()

Output:
7.00
3.00

Added by:Fudan University Problem Setters
Date:2008-04-19
Time limit:0.200s
Source limit:512B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: C99 ERL JS-RHINO NODEJS PERL6 VB.NET
Resource:Waterloo Local Contest

hide comments
2013-07-21 12:25:48 Ouditchya Sinha
Nice problem! For those getting WA, use doubles. A sample test case for you-
(.5 (.5 1 2) 3)
()
Answer is
1.00

P.S. : Assuming a string length of 999 worked fine for me. :)

@__KIRA__ : 0 => 0.00

Last edit: 2013-07-23 15:23:19
2012-11-05 18:50:18 legrand
always wa, but working with my testcases. Are there tricky inputs?
2012-02-12 11:46:41 __KIRA__
@xiling why wa always any tricky inputs??
0 => 0.00 or 0
wat's wrong with my sol ID 6277614 ?? it working on my system

Last edit: 2012-01-01 08:43:06
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.