All problems

Problem 864

Complex Number Multiplication

Medium · 20 pts · Math, String

Problem

A complex number is written as a+bi, where a is the real part, b the imaginary part, and i² = -1. A negative part is written with its minus sign after the plus, as in 1+-1i. Multiply two complex numbers and print the result in the same format: (a + bi)(c + di) = (ac - bd) + (ad + bc)i. Parse each number by splitting at the plus sign and dropping the final i.

Input

Two lines, each containing one complex number in the form a+bi.

Output

Print the product in the form x+yi.

Constraints

-100 <= every real and imaginary part <= 100

Example input

1+1i
1+1i

Example output

0+2i

Explanation

(1 + 1i)(1 + 1i) = 1 + 2i + i² = 1 + 2i - 1 = 0 + 2i, which is written 0+2i.

Every problem here can be used in a RelayTrixCode team match. Create a room.

Previous: Count Integers With Even Digit Sum Next: Valid Square