import java.util.*; import java.io.*; /** * * @author Umang Upadhyay */ public class MagicSquareForming { public static void main(String[] args) { InputReader in = new InputReader(System.in); PrintWriter w = new PrintWriter(System.out); int[][] arr = new int[3][3]; int[][] a1 = new int[3][3]; int[][] a2 = new int[3][3]; int[][] a3 = new int[3][3]; int[][] a4 = new int[3][3]; int[][] a5 = new int[3][3]; int[][] a6 = new int[3][3]; int[][] a7 = new int[3][3]; int[][] a8 = new int[3][3]; int i,j; int cost=0; for(i=0;i<3;i++){ for(j=0;j<3;j++){ arr[i][j]=in.nextInt(); } } a1[0][0]=2; a1[0][1]=7; a1[0][2]=6; a1[1][0]=9; a1[1][1]=5; a1[1][2]=1; a1[2][0]=4; a1[2][1]=3; a1[2][2]=8; a2[0][0]=2; a2[0][1]=9; a2[0][2]=4; a2[1][0]=7; a2[1][1]=5; a2[1][2]=3; a2[2][0]=6; a2[2][1]=1; a2[2][2]=8; a3[0][0]=6; a3[0][1]=7; a3[0][2]=2; a3[1][0]=1; a3[1][1]=5; a3[1][2]=9; a3[2][0]=8; a3[2][1]=3; a3[2][2]=4; a4[0][0]=6; a4[0][1]=1; a4[0][2]=8; a4[1][0]=7; a4[1][1]=5; a4[1][2]=3; a4[2][0]=2; a4[2][1]=9; a4[2][2]=4; a5[0][0]=4; a5[0][1]=3; a5[0][2]=8; a5[1][0]=9; a5[1][1]=5; a5[1][2]=1; a5[2][0]=2; a5[2][1]=7; a5[2][2]=6; a6[0][0]=4; a6[0][1]=9; a6[0][2]=2; a6[1][0]=3; a6[1][1]=5; a6[1][2]=7; a6[2][0]=8; a6[2][1]=1; a6[2][2]=6; a7[0][0]=8; a7[0][1]=3; a7[0][2]=4; a7[1][0]=1; a7[1][1]=5; a7[1][2]=9; a7[2][0]=6; a7[2][1]=7; a7[2][2]=2; a8[0][0]=8; a8[0][1]=1; a8[0][2]=6; a8[1][0]=3; a8[1][1]=5; a8[1][2]=7; a8[2][0]=4; a8[2][1]=9; a8[2][2]=2; int min=1000000; cost=0; for(i=0;i<3;i++){ for(j=0;j<3;j++){ cost+=Math.abs(a1[i][j]-arr[i][j]); } } if(cost= snumChars) { curChar = 0; try { snumChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (snumChars <= 0) return -1; } return buf[curChar++]; } public int nextInt() { int c = snext(); while (isSpaceChar(c)) c = snext(); int sgn = 1; if (c == '-') { sgn = -1; c = snext(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = snext(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = snext(); while (isSpaceChar(c)) c = snext(); int sgn = 1; if (c == '-') { sgn = -1; c = snext(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = snext(); } while (!isSpaceChar(c)); return res * sgn; } public int[] nextIntArray(int n) { int a[] = new int[n]; for (int i = 0; i < n; i++) a[i] = nextInt(); return a; } public String readString() { int c = snext(); while (isSpaceChar(c)) c = snext(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = snext(); } while (!isSpaceChar(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } }