Problem:
Score : 500 points

Problem Statement

There are N points on the 2D plane, i-th of which is located on (x_i, y_i).
There can be multiple points that share the same coordinate.
What is the maximum possible Manhattan distance between two distinct points?

Here, the Manhattan distance between two points (x_i, y_i) and (x_j, y_j) is defined by |x_i-x_j| + |y_i-y_j|.

Constraints

2 \leq N \leq 2 \times 10^5

1 \leq x_i,y_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
x_1 y_1
x_2 y_2
:
x_N y_N

Output

Print the answer.

Sample Input 1

3
1 1
2 4
3 2

Sample Output 1

4

The Manhattan distance between the first point and the second point is |1-2|+|1-4|=4, which is maximum possible.

Sample Input 2

2
1 1
1 1

Sample Output 2

0

Solution in C++ (GCC 9.2.1) (judge verdict: Accepted)

#include <bits/stdc++.h>
using namespace std;
#define REP(i,b,e) for(int i=(b);i<(e);++i)
#define RREP(i,b,e) for(int i=(b)-1;i>=e;--i)
#define rep(i,e) for(int i=0;i<(e);++i)

constexpr int MOD = 1000000007;
constexpr int INF = 1LL << 30;
constexpr long long LLINF = 1LL << 62;
constexpr double EPS = 1e-9;

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15) << boolalpha;
  }
} initializer;

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[";
  for (auto it = vec.begin(); it != vec.end(); ++it) {
    if (it != vec.begin()) os << ", ";
    os << *it;
  }
  return os << "]";
}

template<typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &pa) {
  return os << "(" << pa.first << ", " << pa.second << ")";
}

template<typename Tuple, size_t N>
struct TuplePrinter {
  static void print(const Tuple &t) {
    TuplePrinter<Tuple, N-1>::print(t);
    cout << ", " << get<N-1>(t);
  }
};

template<typename Tuple>
struct TuplePrinter<Tuple, 1> {
  static void print(const Tuple &t) {
    cout << get<0>(t);
  }
};

template<typename... T>
ostream &operator<<(ostream &os, const tuple<T...> &tup) {
  os << "(";
  TuplePrinter<decltype(tup), sizeof...(T)>::print(tup);
  return os << ")";
}

template<typename T>
ostream &operator<<(ostream &os, const set<T> &se) {
  os << "{";
  for (auto it = se.begin(); it != se.end(); ++it) {
    if (it != se.begin()) os << ", ";
    os << *it;
  }
  return os << "}";
}

template<typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &ma) {
  os << "{";
  for (auto it = ma.begin(); it != ma.end(); ++it) {
    if (it != ma.begin()) os << ", ";
    os << it->first << ": " << it->second;
  }
  return os << "}";
}

inline void print(void) { cout<<'\n'; }
template<class T> inline void print(const T &x) { cout<<x<<'\n'; }
template<class T, class... U> inline void print(const T &x, const U&... y) { cout<<x<<" "; print(y...); }

// Return the sum of distance of one axis. 
int distancesum(vector<long long> arr, int n) 
{ 
    // sorting the array.
    sort(arr.begin(), arr.end());
  
    // for each point, finding the distance. 
    int res = 0, sum = 0; 
    for (int i = 0; i < n; i++) { 
        res += (arr[i] * i - sum); 
        sum += arr[i]; 
    } 
  
    return res; 
} 
  
int totaldistancesum(vector<long long> x, vector<long long> y, int n) 
{ 
    return distancesum(x, n) + distancesum(y, n); 
} 

int main() {
  int n; cin>>n;
  vector<long long> x(n), y(n);
  rep(i, n) cin>>x[i]>>y[i];

  long long min_a = LLINF, max_a = -LLINF;
  int min_a_idx = 0, max_a_idx = 0;
  rep(i, n) {
    long long tmp = x[i] + y[i];
    if (tmp < min_a) {
      min_a = tmp;
      min_a_idx = i;
    }
    if (tmp > max_a) {
      max_a = tmp;
      max_a_idx = i;
    }
  }

  long long ans_a = abs(x[max_a_idx] - x[min_a_idx]) + abs(y[max_a_idx] - y[min_a_idx]);

  long long min_b = LLINF, max_b = -LLINF;
  int min_b_idx = 0, max_b_idx = 0;
  rep(i, n) {
    long long tmp = x[i] - y[i];
    if (tmp < min_b) {
      min_b = tmp;
      min_b_idx = i;
    }
    if (tmp > max_b) {
      max_b = tmp;
      max_b_idx = i;
    }
  }
  long long ans_b = abs(x[max_b_idx] - x[min_b_idx]) + abs(y[max_b_idx] - y[min_b_idx]);

  print(max(ans_a, ans_b));


  return 0;
}