This page is still under construction.

Parts of this page are still being built. What you see may change.

Magic Squares

Time limit2sMemory limit512 MB

Summary
Given a 4x4 grid, check whether all four row sums and all four column sums are equal, then print whether it is magic.
Level

Easy2 of 10

Topics
Implementation, Matrix
Solved
No attempts yet

Problem

A magic square is a square array of numbers in which every row sums to the same total and every column sums to that same total.

A 4×44 \times 4 array of integers is given. Decide whether it is a magic square. This problem compares the four row sums and the four column sums only, and does not look at the diagonals.

Input

The input consists of four lines. Each line holds 4 space-separated integers.

Output

Print magic if the input is a magic square, or not magic if it is not.

Examples2

  1. Example 1

    Input
    16 3 2 13
    5 10 11 8
    9 6 7 12
    4 15 14 1
    
    Expected output
    magic
    
  2. Example 2

    Input
    5 10 1 3
    10 4 2 3
    1 2 8 5
    3 3 5 0
    
    Expected output
    not magic