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. LDAP1-安装部署LDAP服务

    基于Linux部署openldap服务 参考文档: https://blog.csdn.net/computer1024/article/details/78172785 参考文档:  https:/ ...

  2. BZOJ1061 NOI2008 志愿者招募 线性规划、费用流

    传送门 一道思路很妙的线性规划网络流 设\(X_i\)表示第\(i\)天需要的人数,\(P_i\)表示第\(i\)种人雇佣的个数 那么我们可以列出一系列式子 比如说样例就可以列出三个式子: \(P_1 ...

  3. notpad++常用操作与快捷键

    1.列编辑模式 按住alt+shift进入列编辑模式

  4. [Spark][Flume]Flume 启动例子

    Flume 启动例子: flume-ng agent --conf /etc/flume-ng/conf --conf-file /etc/flume-ng/conf/flume.conf --nam ...

  5. Volley使用

    Volley是常用的网络请求框架,主要的用法如下: 获取字符串: public static void volleyTest1(final Context context){ RequestQueue ...

  6. Node.js配合jQuery UI autocomplete的应用

    Node.js擅长的领域为: 不需要很多运算 吞吐量要求高 进消息轻并且要求快 出消息轻并且要求快 网上的例子都是socket.io的,我一直在想到底能用在什么地方?根据node.js的优点(擅长领域 ...

  7. mybatis源码- 反射模块一(跟着MyBatis学反射):类级别信息的封装

    目录 1 JavaBean 规范 2 Reflector和ReflectorFactory 2.1 Reflector 属性 2.1.1 属性 2.1.2 Invoker 接口 2.2 Reflect ...

  8. 来,看看MySQL 5.6, 5.7, 8.0的新特性

    对于MySQL的历史,相信很多人早已耳熟能详,这里就不要赘述.下面仅从产品特性的角度梳理其发展过程中的里程碑事件. 1995年,MySQL 1.0发布,仅供内部使用. 1996年,MySQL 3.11 ...

  9. 微信小程序页面跳转方法总结

    微信小程序页面跳转目前有以下方法(不全面的欢迎补充): 1. 利用小程序提供的 API 跳转: // 保留当前页面,跳转到应用内的某个页面,使用wx.navigateBack可以返回到原页面.// 注 ...

  10. flask 单元测试

    程序开发过程中,代码是为了完成需求,当代码编译通过后,能不能保证功能的正常实现,需要我们编写测试代码,模拟程序运行过程,检验功能是否符合预期. 单元测试主要面向一些功能单一的模块进行. 单元测试,实际 ...