Problem:
Score : 100 points

Problem Statement

Takahashi is a user of a site that hosts programming contests.

When a user competes in a contest, the rating of the user (not necessarily an integer) changes according to the performance of the user, as follows:

Let the current rating of the user be a.

Suppose that the performance of the user in the contest is b.

Then, the new rating of the user will be the avarage of a and b.

For example, if a user with rating 1 competes in a contest and gives performance 1000, his/her new rating will be 500.5, the average of 1 and 1000.

Takahashi's current rating is R, and he wants his rating to be exactly G after the next contest.

Find the performance required to achieve it.

Constraints

0 \leq R, G \leq 4500

All input values are integers.

Input

Input is given from Standard Input in the following format:

R
G

Output

Print the performance required to achieve the objective.

Sample Input 1

2002
2017

Sample Output 1

2032

Takahashi's current rating is 2002.

If his performance in the contest is 2032, his rating will be the average of 2002 and 2032, which is equal to the desired rating, 2017.

Sample Input 2

4500
0

Sample Output 2

-4500

Although the current and desired ratings are between 0 and 4500, the performance of a user can be below 0.

Solution in Python (3.4.3) (judge verdict: Runtime Error)

#区間ごとの面積を計算する
def calc_area(v_end, v_start, v_max, dt):
    kouten_v = (v_end + v_start + dt) / 2
    kouten_t = kouten_v - v_start
    if 0 < kouten_t < dt:
        area = (v_start + kouten_v) * kouten_t / 2 #左側
        area +=  (v_end + kouten_v) * (dt - kouten_t) / 2 #右側
        area -=  max(0, (kouten_v - v_max))** 2 #上の三角形
    else:
        area = (v_start + v_end) *  dt / 2
    return area

def main():
    #与えられた入力を受け取る
    n=int(input())
    t=[int(i) for i in input().split()]
    v=[int(i) for i in input().split()]

    #各区間の許容最大速度を計算する
    #（この段階では傾きが-1未満になる可能性がある）
    max_velocity = [0]
    for i in range(1, n):
        max_velocity_ = min(v[i-1], v[i], max_velocity[i-1] + t[i-1])
        max_velocity.append(max_velocity_)
    max_velocity.append(0)

    #後ろから走査して、傾きが-1以上を満たすように許容速度をfittingする
    for i in range(n-1):
        if  max_velocity[-(i+1)] - max_velocity[-(i+2)] < -t[-(i+1)]:
            max_velocity[-(i+2)] = max_velocity[-(i+1)] + t[-(i+1)]

    #各区間の面積を計算して足し合わせる
    ans = 0
    for i in range(n):
        ans += calc_area(max_velocity[i+1], max_velocity[i], v[i], t[i])
    print(ans)

main()