Little Elephant and Magic Square

CodeForces - 259B

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.

Examples

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 sol:小学奥数应该学过九宫格,对于最中间的数字等于左右两边数字之和的二分之一
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
inline ll read()
{
ll s=;
bool f=;
char ch=' ';
while(!isdigit(ch))
{
f|=(ch=='-'); ch=getchar();
}
while(isdigit(ch))
{
s=(s<<)+(s<<)+(ch^); ch=getchar();
}
return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
if(x<)
{
putchar('-'); x=-x;
}
if(x<)
{
putchar(x+''); return;
}
write(x/);
putchar((x%)+'');
return;
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('\n')
int a[][];
int main()
{
int i,j,Sum=;
for(i=;i<=;i++) for(j=;j<=;j++) R(a[i][j]);
a[][]=(a[][]+a[][])/;
a[][]=a[][]*-a[][]-a[][];
a[][]=a[][]*-a[][]-a[][];
for(i=;i<=;i++,puts("")) for(j=;j<=;j++) W(a[i][j]);
return ;
}
/*
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
*/
 

codeforces259B的更多相关文章

  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 ...

随机推荐

  1. Linux并发与同步专题 (1)原子操作和内存屏障

    关键词:. <Linux并发与同步专题 (1)原子操作和内存屏障> <Linux并发与同步专题 (2)spinlock> <Linux并发与同步专题 (3) 信号量> ...

  2. Spark运行模式:cluster与client

    When run SparkSubmit --class [mainClass], SparkSubmit will call a childMainClass which is 1. client ...

  3. Java学习之路- SQL注入

    用户名: __________ 密码:——————— 假如没有使用预处理的Statement 对象 拼接字符串查数据库的话,易收到sql注入攻击: 例如说 : mysql 中   #代表的是单行注释 ...

  4. .Net业务搭配实用技术栈

    前言 昨天有篇文章在讨论webform的设计思路,我已经四五年不用webform了,虽然它也提供了HttpModule和httphandle来处理请求,提供了一般处理程序ashx来简化处理流程,但依然 ...

  5. 面试 15:顺时针从外往里打印数字(剑指 Offer 第 20 题)

    面试 15:顺时针从外往里打印数字 题目:输入一个矩阵,按照从外向里以顺时针的顺序依次打印每一个数字.例如输入: {{1,2,3}, {4,5,6}, {7,8,9}} 则依次打印数字为 1.2.3. ...

  6. pycharm 报错:pycharm please specify a different SDK name

    我在给项目配虚拟环境里的解释器的时候有没有遇到过这个问题的啊,就是一个正常的项目,解释器忽然丢了,解释器是配在虚拟环境里面的,再去选择解释器就一直报这个错,给现有项目添加虚拟环境的时候也是报这个错—— ...

  7. H5 36-背景定位属性

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  8. Python—函数的名称空间

    名称空间 又名name space, 顾名思义就是存放名字的地方,存什么名字呢?举例说明,若变量x=1,1存放于内存中,那名字x存放在哪里呢?名称空间正是存放名字x与1绑定关系的地方 名称空间共3种, ...

  9. hdu1201,hdu6252差分约束系统

    差分约束系统一般用来解决a-b>=c的问题,有n个这样的限制条件,求出某个满足这些条件的解 可以将这个问题转化成最长路问题,即b到a的距离最少为c,而有多条b到a的路的话,我们就取最长的b到a的 ...

  10. Winform MDI窗体切换不闪烁的解决办法(测试通过)

    https://stackoverflow.com/questions/5817632/beginupdate-endupdate-for-datagridview-request SuspendLa ...