import java.io.IOException; import java.io.InputStream; import java.util.Arrays; import java.util.NoSuchElementException; class DJSet{ int n; int num; int[] upper; public DJSet(int n_) { n=n_; num=n_; upper=new int[n]; Arrays.fill(upper, -1); } boolean equiv(int x,int y) { return root(x)==root(y); } int root(int x) { return upper[x]<0?x:(upper[x]=root(upper[x])); } void setUnion(int x,int y) { x=root(x);y=root(y); if(x==y)return; if(upper[x]>i)%2!=(s>>(i+1))%2)++cnt; return cnt; } void run() { FastScanner sc=new FastScanner(); int[][] C=new int[5][5]; long[][] sum=new long[5][1<<5]; long z=0; for(int i=0;i<5;++i) { for(int j=0;j<5;++j) { C[i][j]=sc.nextInt(); z=Math.max(z, Math.abs(C[i][j])); } } for(int i=0;i<5;++i) { for(int s=0;s<1<<5;++s) { for(int j=0;j<5;++j) { if((s>>j)%2==1) sum[i][s]+=C[i][j]; else sum[i][s]-=C[i][j]; } } } int[] s=new int[5]; long ans=Long.MAX_VALUE/3; for(int s0=0;s0<1<<5;s0+=2) { if(f(s0)>=3)continue; if(Math.max(Math.abs(sum[0][s0])-20*z,0)>=ans) continue; for(int s1=0;s1<1<<5;++s1) { if((s0&s1)==0&&s0>0&&s1>0)continue; if(Math.max(Math.abs(sum[0][s0]+sum[1][s1])-15*z,0)>=ans) continue; for(int s2=0;s2<1<<5;++s2) { if((s1&s2)==0&&s1>0&&s2>0)continue; if(Math.max(Math.abs(sum[0][s0]+sum[1][s1]+sum[2][s2])-10*z,0)>=ans) continue; for(int s3=0;s3<1<<5;++s3) { if((s2&s3)==0&&s2>0&&s3>0)continue; if(f(s0%2|s1%2<<1|s2%2<<2|s3%2<<3)>=3) continue; if(f((s0>>4)%2|(s1>>4)%2<<1|(s2>>4)%2<<2|(s3>>4)%2<<3)>=3) continue; if(Math.max(Math.abs(sum[0][s0]+sum[1][s1]+sum[2][s2]+sum[3][s3])-5*z,0)>=ans) continue; in:for(int s4=0;s4<1<<5;++s4) { if((s3&s4)==0&&s3>0&&s4>0)continue; if(f(s4)>=3) continue; if(f(s0%2|s1%2<<1|s2%2<<2|s3%2<<3|s4%2<<4)>=3) continue; if(f((s0>>4)%2|(s1>>4)%2<<1|(s2>>4)%2<<2|(s3>>4)%2<<3)>=3) continue; long cur=Math.abs(sum[0][s0]+sum[1][s1]+sum[2][s2]+sum[3][s3]+sum[4][s4]); if(cur>=ans) continue; DJSet ds=new DJSet(5*5); s[0]=s0; s[1]=s1; s[2]=s2; s[3]=s3; s[4]=s4; for(int i=0;i<5;++i) { for(int j=0;j<5;++j) { if(i+1<5&&(s[i]>>j)%2==(s[i+1]>>j)%2) ds.setUnion(i+5*j, (i+1)+5*j); if(j+1<5&&(s[i]>>j)%2==(s[i]>>(j+1))%2) ds.setUnion(i+5*j, i+5*(j+1)); } } if(ds.num!=2) continue in; ans=Math.min(ans, Math.abs(cur)); } } } } } System.out.println(ans); } void tr(Object...objects) {System.out.println(Arrays.deepToString(objects));} } class FastScanner { private final InputStream in = System.in; private final byte[] buffer = new byte[1024]; private int ptr = 0; private int buflen = 0; private boolean hasNextByte() { if (ptr < buflen) { return true; }else{ ptr = 0; try { buflen = in.read(buffer); } catch (IOException e) { e.printStackTrace(); } if (buflen <= 0) { return false; } } return true; } private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;} private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;} public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();} public String next() { if (!hasNext()) throw new NoSuchElementException(); StringBuilder sb = new StringBuilder(); int b = readByte(); while(isPrintableChar(b)) { sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } public long nextLong() { if (!hasNext()) throw new NoSuchElementException(); long n = 0; boolean minus = false; int b = readByte(); if (b == '-') { minus = true; b = readByte(); } if (b < '0' || '9' < b) { throw new NumberFormatException(); } while(true){ if ('0' <= b && b <= '9') { n *= 10; n += b - '0'; }else if(b == -1 || !isPrintableChar(b)){ return minus ? -n : n; }else{ throw new NumberFormatException(); } b = readByte(); } } public int nextInt() { long nl = nextLong(); if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException(); return (int) nl; } public double nextDouble() { return Double.parseDouble(next());} }