AIOC Banner

Problem: Magic Squares

Want to try solving this problem? You can submit your code online if you log in or register.

Magic Squares

Time Limit: 1 second
Memory Limit: 1 GB
Input File: magicin.txt
Output File: magicout.txt

The summer holidays have just started, but before you can go outside and play, you have to finish all of your maths homework. Your maths teacher insists that you fill out a very specific type of Magic Square. In particular:

Three cells of the magic square have already been filled: the top-left cell, the top-middle cell, and the middle-left cell. You may fill in the remaining squares with any numbers you wish, though your maths teacher prefers some numbers over other numbers. These numbers are explained in the `Subtasks & Constraints' section. You pull out your trusty laptop and get to work!


The first and only line of input will contain three integers: A, B and C.


Your program must output three lines each containing three space-separated integers giving the magic square.

Sample Input

1 2 3

Sample Output A

1 2 -3
3 0 -3
-4 -2 6

Sample Output B

1 2 27
3 26 1
26 2 2

Sample Output C

1 2 14
3 13 1
13 2 2


The sample input corresponds to the following partially filled magic square:

1 2 ?
3 ? ?
? ? ?

Output A is a magic square where every row/column adds up to 0. This would be a correct output for subtask 1 only (see below for more information).
Output B is correct for subtasks 1 and 2. Output C is correct for all subtasks.

Subtasks & Constraints

You are guaranteed that 1 ≤ A, B, C ≤ 9.
For all subtasks, you may only use numbers between -1,000,000,000 and 1,000,000,000 inclusive to create your magic square.

For each subtask, you will be awarded marks based on what numbers you use to fill out the magic square. Namely:


Privacy statement
© Australian Mathematics Trust 2001-2019

Page generated: 24 May 2019,  3:51am AEST