Little Elephant loves magic squares very much.

A magic square is a 3 × 3 table, each cell contains some positive integer. At that the sums of integers in all rows, columns and diagonals of the table are equal. The figure below shows the magic square, the sum of integers in all its rows, columns and diagonals equals 15.

The Little Elephant remembered one magic square. He started writing this square on a piece of paper, but as he wrote, he forgot all three elements of the main diagonal of the magic square. Fortunately, the Little Elephant clearly remembered that all elements of the magic square did not exceed 105.

Help the Little Elephant, restore the original magic square, given the Elephant's notes.

Input

The first three lines of the input contain the Little Elephant's notes. The first line contains elements of the first row of the magic square. The second line contains the elements of the second row, the third line is for the third row. The main diagonal elements that have been forgotten by the Elephant are represented by zeroes.

It is guaranteed that the notes contain exactly three zeroes and they are all located on the main diagonal. It is guaranteed that all positive numbers in the table do not exceed 105.

Output

Print three lines, in each line print three integers — the Little Elephant's magic square. If there are multiple magic squares, you are allowed to print any of them. Note that all numbers you print must be positive and not exceed 105.

It is guaranteed that there exists at least one magic square that meets the conditions.

Example

Input
0 1 1
1 0 1
1 1 0
Output
1 1 1
1 1 1
1 1 1
Input
0 3 6
5 0 5
4 7 0
Output
6 3 6
5 5 5
4 7 4 本题为数学题,列方程可得解
将第一个至第九个元素分别用字母代表,即方阵为 a b c
                       d e f
                       g h i
a,e,h为未知数 代码如下
 #include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
using namespace std;
 
int main()
{
    int A,B,C,D,E,F,G,H,I;
    scanf("%d%d%d%d%d%d%d%d%d",&A,&B,&C,&D,&E,&F,&G,&H,&I);
    I = D + (F - H)/;
    A = (F+H)/;
    E = B+C - I;
    printf("%d %d %d\n%d %d %d\n%d %d %d\n",A,B,C,D,E,F,G,H,I);
    return ;
}

Little Elephant and Magic Square的更多相关文章

  1. CodeForces-259B]Little Elephant and Magic Square

      Little Elephant loves magic squares very much. A magic square is a 3 × 3 table, each cell contains ...

  2. codeforces 711B B. Chris and Magic Square(水题)

    题目链接: B. Chris and Magic Square 题意: 问在那个空位子填哪个数可以使行列对角线的和相等,就先找一行或者一列算出那个数,再验证是否可行就好; AC代码: #include ...

  3. Xtreme8.0 - Magic Square 水题

    Xtreme8.0 - Magic Square 题目连接: https://www.hackerrank.com/contests/ieeextreme-challenges/challenges/ ...

  4. Codeforces Round #369 (Div. 2) B. Chris and Magic Square 水题

    B. Chris and Magic Square 题目连接: http://www.codeforces.com/contest/711/problem/B Description ZS the C ...

  5. Chris and Magic Square CodeForces - 711B

    ZS the Coder and Chris the Baboon arrived at the entrance of Udayland. There is a n × n magic grid o ...

  6. B. Chris and Magic Square

    time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...

  7. zoj 2835 Magic Square(set)

    Magic Square Time Limit: 2 Seconds      Memory Limit: 65536 KB In recreational mathematics, a magic ...

  8. Codeforces Round #369 (Div. 2) B. Chris and Magic Square (暴力)

    Chris and Magic Square 题目链接: http://codeforces.com/contest/711/problem/B Description ZS the Coder an ...

  9. codeforces #369div2 B. Chris and Magic Square

    题目:在网格某一处填入一个正整数,使得网格每行,每列以及两条主对角线的和都相等 题目链接:http://codeforces.com/contest/711/problem/B 分析:题目不难,找到要 ...

随机推荐

  1. idea maven项目依赖项有红色波浪线

    在maven面板选中所有报错的maven项目,右键选择移除(remove),之后重新添加.

  2. 在VMware中为Red Hat配置静态ip并可访问网络-Windows下的VMware

    首先确保虚拟网卡(VMware Network Adapter VMnet8)是开启的,然后在windows的命令行里输入“ipconfig /all”,找到VMware Network Adapte ...

  3. hdu3530 Subsequence

    题意:There is a sequence of integers. Your task is to find the longest subsequence that satisfies the ...

  4. 【bzoj2190】[SDOI2008]仪仗队

    2190: [SDOI2008]仪仗队 Time Limit: 10 Sec  Memory Limit: 259 MBSubmit: 2638  Solved: 1674[Submit][Statu ...

  5. jquery触发两次onchange事件

    在项目中需要给select绑定改变事件,来触发动作,但是发现改变一次select,onchange方法执行两遍 //这是那个标签,用的是我们公司内部的selectlist <select cla ...

  6. IDEA02 利用Maven创建Web项目、为Web应用添加Spring框架支持、bean的创建于获取、利用注解配置Bean、自动装配Bean、MVC配置

    1 环境版本说明 Jdk : 1.8 Maven : 3.5 IDEA : 专业版 2017.2 2 环境准备 2.1 Maven安装及其配置 2.2 Tomcat安装及其配置 3 详细步骤 3.1 ...

  7. jq获取table总行数

    var rows = $('table').find("tr").length;

  8. ByteUnit

    JDK里面有TimeUnit,看spark源码有个ByteUnit.这个类还是挺不错的. public enum ByteUnit { BYTE (1), KiB (1024L), MiB ((lon ...

  9. Linux、Windows中的相对路径和绝对路径

    获取系统的分隔符的方式:System.getProperty("file.separator")   Windows为 \   Linux为/ Windows绝对路径: 以盘符开始 ...

  10. Java集合类总结 (四)

    PriorityQueue类 优先队列不管你按照什么顺序插入元素,出队列的时候元素都是按顺序输出的.也就是每次调用remove的时候,都返回当前队列中最小的元素.然后队列中的元素不是维持排序状态的,如 ...