#K51992. Solve a Linear Equation

    ID: 29210 Type: Default 1000ms 256MiB

Solve a Linear Equation

Solve a Linear Equation

Given a linear equation in one variable in the form \(ax + b = c\) (or a similar variation where spaces may appear arbitrarily), your task is to parse the equation and determine the value of the variable. The coefficient \(a\) may be omitted if it is 1 or may include a sign (+ or -). Similarly, the constant term \(b\) might be absent. You need to correctly extract the coefficient and constant, and then compute \(x\) from the equation \(ax + b = c\), i.e., \(x = \frac{c - b}{a}\).

For instance, for the equation 3x + 2 = 14 and variable x, the answer is 4 since \(3 \times 4 + 2 = 14\).

inputFormat

The input consists of two lines:

  1. The first line contains a string representing the linear equation. The equation may include spaces arbitrarily, e.g., "3x + 2 = 14" or "3 a + 2 = 14".
  2. The second line contains a single character which is the variable to solve for.

outputFormat

Output a single line containing the value of the variable after solving the linear equation. If the result is an integer, it should be printed without a decimal point.

## sample
3x + 2 = 14
x
4