The 2×2 determinant

One small number tells you whether a 2×2 matrix can be undone.

What to build

Print the determinant of a 2×2 matrix and say whether the matrix is invertible.

Requirements

  • Read the two rows of the matrix.
  • Compute a·d − b·c.
  • Print invertible yes unless the determinant is 0.

Input

Two lines: a b and c d, whole numbers.

Output

Two lines: det D (a whole number) and invertible yes or invertible no.

Constraints

All numbers are between -1000 and 1000.

Example

Input:

4 7
2 6

Output:

det 10
invertible yes

Why it works

The determinant is the signed area of the parallelogram formed by the matrix's columns. If it is 0 the parallelogram is flat, the matrix squashes the plane onto a line or a point, and no inverse can undo that.

Examples

Example 1 · Input
4 7
2 6
Expected output
det 10
invertible yes
Example 2 · Input
1 2
2 4
Expected output
det 0
invertible no

Prompts inside input() are ignored when checking, so input("n: ") is fine.

Hints

Hint 1

The determinant of [[a, b], [c, d]] is a·d − b·c.

Hint 2

The matrix has an inverse exactly when the determinant is not 0.

Hint 3

Whole numbers only, so print the determinant as an integer.

Solution

Show one correct solution (try it yourself first)
a, b = [int(v) for v in input().split()]
c, d = [int(v) for v in input().split()]
det = a * d - b * c
print("det", det)
print("invertible", "no" if det == 0 else "yes")

▶ Open this solution in the compiler, then press Visualize to watch it run step by step

Lesson: Determinants and inverses →