Problem: Dora loves adventures quite a lot. During some journey she encountered an amazing city, which is formed by n streets along the Eastern direction and m streets across the Southern direction. Naturally, this city has nm intersections. At any intersection of i-th Eastern street and j-th Southern street there is a monumental skyscraper. Dora instantly became curious and decided to explore the heights of the city buildings.

When Dora passes through the intersection of the i-th Eastern and j-th Southern street she examines those two streets. After Dora learns the heights of all the skyscrapers on those two streets she wonders: how one should reassign heights to the skyscrapers on those two streets, so that the maximum height would be as small as possible and the result of comparing the heights of any two skyscrapers on one street wouldn't change.

Formally, on every of nm intersections Dora solves an independent problem. She sees n + m - 1 skyscrapers and for each of them she knows its real height. Moreover, any two heights can be compared to get a result "greater", "smaller" or "equal". Now Dora wants to select some integer x and assign every skyscraper a height from 1 to x. When assigning heights, Dora wants to preserve the relative order of the skyscrapers in both streets. That is, the result of any comparison of heights of two skyscrapers in the current Eastern street shouldn't change and the result of any comparison of heights of two skyscrapers in current Southern street shouldn't change as well. Note that skyscrapers located on the Southern street are not compared with skyscrapers located on the Eastern street only. However, the skyscraper located at the streets intersection can be compared with both Southern and Eastern skyscrapers. For every intersection Dora wants to independently calculate the minimum possible x.

For example, if the intersection and the two streets corresponding to it look as follows:

<image>

Then it is optimal to replace the heights of the skyscrapers as follows (note that all comparisons "less", "equal", "greater" inside the Eastern street and inside the Southern street are preserved)

<image>

The largest used number is 5, hence the answer for this intersection would be 5.

Help Dora to compute the answers for each intersection.

Input

The first line contains two integers n and m (1 ≤ n, m ≤ 1000) — the number of streets going in the Eastern direction and the number of the streets going in Southern direction.

Each of the following n lines contains m integers a_{i,1}, a_{i,2}, ..., a_{i,m} (1 ≤ a_{i,j} ≤ 10^9). The integer a_{i,j}, located on j-th position in the i-th line denotes the height of the skyscraper at the intersection of the i-th Eastern street and j-th Southern direction.

Output

Print n lines containing m integers each. The integer x_{i,j}, located on j-th position inside the i-th line is an answer for the problem at the intersection of i-th Eastern street and j-th Southern street.

Examples

Input


2 3
1 2 1
2 1 2


Output


2 2 2 
2 2 2 


Input


2 2
1 2
3 4


Output


2 3 
3 2 

Note

In the first example, it's not possible to decrease the maximum used height for the problem at any intersection, hence we don't have to change any heights.

In the second example, the answers are as follows: 

  * For the intersection of the first line and the first column <image>
  * For the intersection of the first line and the second column <image>
  * For the intersection of the second line and the first column <image>
  * For the intersection of the second line and the second column <image>

Solution (in JAVA):

Solution:

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class d {
    public static void main(String[] args) throws IOException {
      //  Scanner s = new Scanner(System.in);
        BufferedReader s=new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb=new StringBuilder();
   String[] st1=s.readLine().trim().split("\\s+");
      int n=Integer.parseInt(st1[0]);
      int m=Integer.parseInt(st1[1]);
      int[][] a=new int[n][m];
      for(int i=0;i<n;i++){
          String[] st=s.readLine().trim().split("\\s+");
          for(int j=0;j<m;j++){
              a[i][j]=Integer.parseInt(st[j]);
          }
      }
      int[] [] verc=new int[n][m];
      int[][] horb=new int[n][m];
        int[][] verb=new int[n][m];
        int[][] horc=new int[n][m];
        int[] b=new int[m];
        for(int i=0;i<n;i++){
          int chota=0;int bada=0;
          HashMap<Integer,Integer> h=new HashMap<>();
            HashMap<Integer,Integer> val=new HashMap<>();

            for(int j=0;j<m;j++) b[j]=a[i][j];
            Arrays.sort(b);  for(int j=0;j<m;j++){

              if(j-1>=0&&b[j-1]==b[j]&&chota>0)
                  horc[i][j]=chota-1;
              else horc[i][j]=chota;
              val.put(b[j],horc[i][j]);
              if(!h.containsKey(b[j])){
                  h.put(b[j],1);
                  chota++;
              }

          }h=new HashMap<>();
            for(int j=0;j<m;j++){
                horc[i][j]=val.get(a[i][j]);
            }val=new HashMap<>();
          for(int j=m-1;j>=0;j--){

              if(j+1<m&&b[j+1]==b[j]&&bada>0)
                  horb[i][j]=bada-1;
              else horb[i][j]=bada;
              val.put(b[j],horb[i][j]);
              if(!h.containsKey(b[j])){
                  h.put(b[j],1);
                  bada++;
              }
          }
            for(int j=0;j<m;j++){
                horb[i][j]=val.get(a[i][j]);
            }
      }    b=new int[n];
        for(int j=0;j<m;j++){
            int chota=0;
            HashMap<Integer,Integer> h=new HashMap<>();
            HashMap<Integer,Integer> val=new HashMap<>();


            for(int i=0;i<n;i++) b[i]=a[i][j];
            Arrays.sort(b);
            for(int i=0;i<n;i++){
                if(i-1>=0&&b[i-1]==b[i]&&chota>0)
                verc[i][j]=chota-1;
                else verc[i][j]=chota;

                val.put(b[i],verc[i][j]);
                if(!h.containsKey(b[i])){
                    h.put(b[i],1);
                    chota++;
                }}
                for(int i=0;i<n;i++){
                verc[i][j]=val.get(a[i][j]);
                }
      int bada=0;h=new HashMap<>();
      val=new HashMap<>();
                for(int i=n-1;i>=0;i--){

                    if(i+1<n&&b[i+1]==b[i]&&bada>0)
                        verb[i][j]=bada-1;
                    else verb[i][j]=bada;
                    val.put(b[i],verb[i][j]);
                    if(!h.containsKey(b[i])){
                        h.put(b[i],1);
                        bada++;
                    }        }
                    for(int i=0;i<n;i++){
                    verb[i][j]=val.get(a[i][j]);
                    }
        }
        int[] [] ans=new int[n][m];
      for(int i=0;i<n;i++){
          for(int j=0;j<m;j++){
             // if(i==0&&j==2)
             // System.out.println(horc[i][j]+" "+horb[i][j]+" "+verc[i][j]+" "+verb[i][j]);
              ans[i][j]=Math.max(horc[i][j],verc[i][j])+Math.max(horb[i][j],verb[i][j])+1;
             sb.append(ans[i][j]+" ");
          }sb.append("\n");
      }
        System.out.println(sb.toString());
    }
    static  void computeLPSArray(String pat, int M, int lps[]) {
        int len = 0;
        int i = 1;
        lps[0] = 0;
        while (i < M) {
            if (pat.charAt(i) == pat.charAt(len)) {
                len++;
                lps[i] = len;
                i++;
            }
            else
            {
                if (len != 0) {
                    len = lps[len - 1];
                }
                else
                {
                    lps[i] = len;
                    i++;
                }
            }
        }
    }
    static boolean isPrime(int n) {
        if (n <= 1) return false;
        if (n <= 3) return true;

        if (n % 2 == 0 || n % 3 == 0) return false;

        for (int i = 5; i * i <= n; i = i + 6)
            if (n % i == 0 || n % (i + 2) == 0)
                return false;

        return true;
    }
    static long powerwithmod(long  x, long y, int p) {
        long  res = 1;
        x = x % p;
        while (y > 0) {
            if ((y & 1) == 1)
                res = (res * x) % p;
            y = y >> 1;
            x = (x * x) % p;
        }
        return res;
    }
    static long  powerwithoutmod(long x, int y) {
        long  temp;
        if( y == 0)
            return 1;
        temp = powerwithoutmod(x, y/2);
        if (y%2 == 0)
            return temp*temp;
        else
        {
            if(y > 0)
                return x * temp * temp;
            else
                return (temp * temp) / x;
        }
    }
    static void fracion(double x) {
        String a = "" + x;
        String spilts[] = a.split("\\."); // split using decimal
        int b = spilts[1].length(); // find the decimal length
        int denominator = (int) Math.pow(10, b); // calculate the denominator
        int numerator = (int) (x * denominator); // calculate the nerumrator Ex
        // 1.2*10 = 12
        int gcd = (int) gcd((long) numerator, denominator); // Find the greatest common
        // divisor bw them
        String fraction = "" + numerator / gcd + "/" + denominator / gcd;
        // System.out.println((denominator/gcd));
        long x1 = modInverse(denominator / gcd, 998244353);
        //  System.out.println(x1);
        System.out.println((((numerator / gcd) % 998244353 * (x1 % 998244353)) % 998244353));
    }
    static int bfs(int i1, ArrayList<Integer>[] h, int[] vis, int n,int val1) {
        Queue<Integer> q = new LinkedList<Integer>();
        q.add(i1);Queue<Integer> aq=new LinkedList<Integer>();
        aq.add(0);
        while(!q.isEmpty()){
            int i=q.poll();
            int val=aq.poll();
            if(i==n){
                return val;
            }
            if(h[i]!=null){
                for(Integer j:h[i]){
                    if(vis[j]==0){
                        q.add(j);vis[j]=1;
                        aq.add(val+1);}
                }
            }
        }return -1;
    }
    static long gcd(long a, long b) {
        if (b == 0)
            return a;
        return gcd(b, a % b);
    }
    static long modInverse(long a, int m)
    {
        return (powerwithmod(a, m - 2, m));
    }
    static int MAXN=100001;
    static int[] spf=new int[MAXN];
    static void sieve() {
        spf[1] = 1;
        for (int i=2; i<MAXN; i++)
            spf[i] = i;
        for (int i=4; i<MAXN; i+=2)
            spf[i] = 2;
        for (int i=3; i*i<MAXN; i++)
        {
            if (spf[i] == i)
            {
                for (int j=i*i; j<MAXN; j+=i)

                    if (spf[j]==j)
                        spf[j] = i;
            }
        }
    }
    static Vector<Integer> getFactorizationUsingSeive(int x) {
        Vector<Integer> ret = new Vector<Integer>();
        while (x != 1)
        {
            ret.add(spf[x]);
            x = x / spf[x];
        }
        return ret;
    }
   /* static long[] fac = new long[MAXN+1];
     static void calculatefac(int mod){
        for (int i = 1 ;i <= MAXN; i++)
            fac[i] = fac[i-1] * i % mod;
     }
      static long nCrModPFermat(int n, int r, int mod) {
         if (r == 0)
            return 1;
        fac[0] = 1;
        return (fac[n]* modInverse(fac[r], mod)
                % mod * modInverse(fac[n-r], mod)
                                    % mod) % mod;
    } */}
class Student {
    int l;int r;
    public Student(int l, int r) {
        this.l = l;
        this.r = r;
    }

    public String toString()
    {
        return this.l+" ";
    }
}
class Sortbyroll implements Comparator<Student> {

    public int compare(Student a, Student b){
        if(a.l==b.l) return a.r-b.r;
        return b.l-a.l;  }
}
class Sortbyroll1 implements Comparator<Student> {
    public int compare(Student a, Student b){
        if(a.r==b.r) return a.l-b.l;
        return b.l-a.l;
    }
}