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 C++14 (GCC 5.4.1) (judge verdict: Runtime Error)

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<functional>
#include<vector>
#include<queue>
using namespace std;
#define f(i,n) for(int i=0;i<(int)n;i++)
#define MOD 1000000009

int main(void){
	int a[100];
	double b[100];
	double max[20001];
	double seg[20001];
	bool c[20001];
	f(i, 100){
		a[i] = 0;
		b[i] = 0.0;
	}
	f(i, 20001){
		max[i] = 1000000000.0;
		seg[i] = 1000000000.0;
		c[i] = true;
	}
	int k, s;
	int n, m;
	int x, y, z;
	long double ans = 0.0;
	s = 0;
	scanf("%d", &n);
	f(i, n){
		scanf("%d", &a[i]);
	}
	f(i, n){
		scanf("%lf", &b[i]);
		f(j, a[i] + 1)seg[s + j] = min(seg[s + j], b[i]);
		s += a[i];
	}
	c[0] = 0;
	c[s] = 0;
	f(i, s + 1){
		if (i == 0 || i == s)max[i] = 0;
		else{
			max[i] = min(max[i - 1] + 1, seg[i]);
			if (min(max[i - 1] + 1, seg[i]) != seg[i])c[i] = false;
		}
	}

	for (int i = s; i >= 0; i--){
		if (i == 0 || i == s)max[i] = 0;
		else{
			max[i] = min(max[i + 1] + 1, max[i]);
			if (min(max[i + 1] + 1, max[i]) != max[i])c[i] = false;
		}
	}
	f(i, s){
		if (max[i]!=max[i+1])ans += min(max[i], max[i + 1]) + 0.500000;
		else {
			if (max[i] != seg[i] || max[i+1] != seg[i+1])ans += max[i] + 0.2500000;
			else ans += max[i];
		}
	}
	printf("%f\n", ans);

	return 0;
}