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. codeforce469DIV2——E. Data Center Maintenance

    题意: 有n个数据中心,m个客户,每天有h个小时,其中 n,m,h<=100000.每个数据中心i每天都会有一个数据维护的时间0<=u[i]<=h-1,在数据中心维护期间时不可以使用 ...

  2. 【bzoj1050】[HAOI2006]旅行comf

    1050: [HAOI2006]旅行comf Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 2813  Solved: 1534[Submit][St ...

  3. 百度Ueditor编辑器取消多图上传对话框中的图片搜索

    百度Ueditor确实是一个非常强悍的编辑器,功能强大!但是实际开发需求复杂,总会有各种不符合要求的,比如想要取消多图上传的“图片搜索”选项卡(这个图片搜索真心难用)! 以ueditor 1.4.3为 ...

  4. Java虚拟机学习总结之OutOfMemoryError异常

    参考:深入理解java虚拟机一书 开始之前,我们也应当搞清楚连个概念,内存泄漏Memory Leak 内存溢出: 内存泄漏:程序中间动态分配了内存,但是在程序结束时没有释放内存,造成这部分内存不可用. ...

  5. laravel的orm增删改查

    增: //通过模型新增 //使用模型的create方法新增数据 删: //通过模型删除 //通过主键删除 改: //通过模型更新数据库 //结合查询语句批量更新 查:

  6. Part4_lesson1---Bootloader设计蓝图

    1.bootloader的作用 2.u-boot是bootloader业界的老大 u-boot分为自主模式和开发模式 3.建立U-boot工程 uboot不能在window下面进行解压,因为在wind ...

  7. git之创建版本库

    好吧,你知道了git既然有这么多好处,那么我们接下来就可以使用git命令来创建我们的仓库.这一节我们来学习一下如何在windows下面建立自己的仓库.首先我们先在本地创建一个主目录,比如文件名字叫le ...

  8. Ubuntu普通用户使用串口设备

    将普通用户加入dialout组,然后重启或注销登录 sudo gpasswd --add username dialout

  9. Python - selenium_WebDriver 页面元素操作

    代码是自己写了 python WebDriver  页面操作的常用方法. from selenium import webdriver import time driver = webdriver.F ...

  10. bzoj 3224/Tyvj 1728 普通平衡树(splay)

    Description 您需要写一种数据结构(可参考题目标题),来维护一些数,其中需要提供以下操作:1. 插入x数2. 删除x数(若有多个相同的数,因只删除一个)3. 查询x数的排名(若有多个相同的数 ...