Polar bears Menshykov and Uslada from the zoo of St. Petersburg and elephant Horace from the zoo of Kiev decided to do some painting. As they were trying to create their first masterpiece, they made a draft on a piece of paper. The draft consists of n segments. Each segment was either horizontal or vertical. Now the friends want to simplify the draft by deleting some segments or parts of segments so that the final masterpiece meets three conditions:

  1. Horace wants to be able to paint the whole picture in one stroke: by putting the brush on the paper and never taking it off until the picture is ready. The brush can paint the same place multiple times. That's why all the remaining segments must form a single connected shape. 
  2. Menshykov wants the resulting shape to be simple. He defines a simple shape as a shape that doesn't contain any cycles. 
  3. Initially all the segment on the draft have integer startpoint and endpoint coordinates. Uslada doesn't like real coordinates and she wants this condition to be fulfilled after all the changes. 



As in other parts the draft is already beautiful, the friends decided to delete such parts of the draft that the sum of lengths of the remaining segments is as large as possible. Your task is to count this maximum sum of the lengths that remain after all the extra segments are removed.

Input

The first line of the input contains integer n (1 ≤ n ≤ 2·105) — the number of segments on the draft. The next n lines contain four integers each: x1, y1, x2, y2 ( - 109 ≤ x1 ≤ x2 ≤ 109; - 109 ≤ y1 ≤ y2 ≤ 109) — the two startpoint and the two endpoint coordinates of a segment. All segments are non-degenerative and either are strictly horizontal or strictly vertical.

No two horizontal segments share common points. No two vertical segments share common points.

Output

Print a single integer — the maximum sum of lengths for the remaining segments.

Examples

Input

2
0 0 0 1
1 0 1 1


Output

1

Input

4
0 0 1 0
0 0 0 1
1 -1 1 2
0 1 1 1


Output

5

Note

The shapes that you can get in the two given samples are:

<image>

In the first sample you need to delete any segment as the two segments together do not form a single connected shape.

In the second sample the initial segments form a cycle, there are four ways to break the cycle: delete the first, second or fourth segment altogether or delete the middle of the third segment. The last way is shown on the picture.
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 5;
struct verticalLineEvent {
  int x, l, r, idx;
  verticalLineEvent(int x, int l, int r, int idx)
      : x(x), l(l), r(r), idx(idx) {}
  bool operator<(const verticalLineEvent& B) const { return x > B.x; }
};
struct horizontalLineBeginEvent {
  int x, y, idx;
  horizontalLineBeginEvent(int x, int y, int idx) : x(x), y(y), idx(idx) {}
  bool operator<(const horizontalLineBeginEvent& B) const { return x > B.x; }
};
struct horizontalLineEndEvent {
  int x, y, idx;
  horizontalLineEndEvent(int x, int y, int idx) : x(x), y(y), idx(idx) {}
  bool operator<(const horizontalLineEndEvent& B) const { return x > B.x; }
};
struct DSU {
  int *p, *sz;
  int n;
  DSU() {}
  void init(int _n) {
    n = _n;
    p = new int[n + 1];
    sz = new int[n + 1];
    for (int i = 1; i <= n; i++) {
      p[i] = i;
      sz[i] = 1;
    }
  }
  int get_set(int x) {
    if (p[x] == x) return x;
    return p[x] = get_set(p[x]);
  }
  void union_sets(int x, int y) {
    x = get_set(x);
    y = get_set(y);
    if (x == y) return;
    if (sz[x] > sz[y]) swap(x, y);
    p[x] = y;
    sz[y] += sz[x];
  }
};
DSU dsu;
struct node {
  node *l, *r;
  int x, y, val, toPush;
  node() {}
  node(int x, int val) : l(0), r(0), x(x), y(rand()), val(val), toPush(-1) {}
};
void upd(node* t, int x) {
  if (!t) return;
  if (x == -1) return;
  if (t->toPush == -1) {
    t->toPush = x;
    dsu.union_sets(t->val, t->toPush);
  } else {
    dsu.union_sets(t->toPush, x);
  }
}
void push(node* t) {
  if (!t) return;
  if (t->toPush == -1) return;
  dsu.union_sets(t->val, t->toPush);
  upd(t->l, t->toPush);
  upd(t->r, t->toPush);
  t->toPush = -1;
}
void split(node* t, node*& l, node*& r, int x) {
  if (!t) {
    l = r = 0;
    return;
  }
  push(t);
  if (t->x <= x)
    split(t->r, t->r, r, x), l = t;
  else
    split(t->l, l, t->l, x), r = t;
}
void merge(node*& t, node* l, node* r) {
  if (!l || !r) {
    t = (l ? l : r);
    return;
  }
  push(l);
  push(r);
  if (l->y > r->y)
    merge(l->r, l->r, r), t = l;
  else
    merge(r->l, l, r->l), t = r;
}
const int maxn = 100500 * 2;
int n, x[maxn], y[maxn], xx[maxn], yy[maxn];
priority_queue<verticalLineEvent> verticalLineEvents;
priority_queue<horizontalLineBeginEvent> horizontalLineBeginEvents;
priority_queue<horizontalLineEndEvent> horizontalLineEndEvents;
vector<int> comps[maxn];
node* root;
void dfs(node* v) {
  if (!v) return;
  push(v);
  dfs(v->l);
  dfs(v->r);
}
void addLine(int y, int idx) {
  node *t1, *t2;
  split(root, t1, t2, y);
  merge(root, t1, new node(y, idx));
  merge(root, root, t2);
}
void deleteLine(int y, int idx) {
  node *t1, *t2, *t3;
  split(root, t2, t3, y);
  split(t2, t1, t2, y - 1);
  merge(root, t1, t3);
}
void crossLines(int l, int r, int idx) {
  node *t1, *t2, *t3;
  split(root, t2, t3, r);
  split(t2, t1, t2, l - 1);
  upd(t2, idx);
  merge(root, t1, t2);
  merge(root, root, t3);
}
struct node2 {
  node2 *l, *r;
  int x, y, cnt;
  node2() {}
  node2(int x) : l(0), r(0), x(x), y(rand()), cnt(1) {}
};
int getCnt(node2* v) { return (v ? v->cnt : 0); }
void updCnt(node2* v) {
  if (!v) return;
  v->cnt = getCnt(v->l) + getCnt(v->r) + 1;
}
void split(node2* t, node2*& l, node2*& r, int x) {
  if (!t) {
    l = r = 0;
    return;
  }
  if (t->x <= x)
    split(t->r, t->r, r, x), l = t;
  else
    split(t->l, l, t->l, x), r = t;
  updCnt(l);
  updCnt(r);
}
void merge(node2*& t, node2* l, node2* r) {
  if (!l || !r) {
    t = (l ? l : r);
    return;
  }
  if (l->y > r->y)
    merge(l->r, l->r, r), t = l;
  else
    merge(r->l, l, r->l), t = r;
  updCnt(t);
}
node2* root2;
void addLine2(int y) {
  node2 *t1, *t2;
  split(root2, t1, t2, y);
  merge(root2, t1, new node2(y));
  merge(root2, root2, t2);
}
void deleteLine2(int y) {
  node2 *t1, *t2, *t3;
  split(root2, t2, t3, y);
  split(t2, t1, t2, y - 1);
  merge(root2, t1, t3);
}
int crossLines2(int l, int r) {
  node2 *t1, *t2, *t3;
  split(root2, t2, t3, r);
  split(t2, t1, t2, l - 1);
  int res = getCnt(t2);
  merge(root2, t1, t2);
  merge(root2, root2, t3);
  return res;
}
long long solve(vector<int> comp) {
  while (!verticalLineEvents.empty()) verticalLineEvents.pop();
  while (!horizontalLineBeginEvents.empty()) horizontalLineBeginEvents.pop();
  while (!horizontalLineEndEvents.empty()) horizontalLineEndEvents.pop();
  long long result = 0;
  for (size_t j = 0; j < comp.size(); j++) {
    int i = comp[j];
    if (x[i] > xx[i]) swap(x[i], xx[i]);
    if (y[i] > yy[i]) swap(y[i], yy[i]);
    result += 1LL * (xx[i] - x[i] + yy[i] - y[i] + 1);
    if (x[i] == xx[i]) {
      verticalLineEvents.push(verticalLineEvent(x[i], y[i], yy[i], i));
    } else {
      horizontalLineBeginEvents.push(horizontalLineBeginEvent(x[i], y[i], i));
      horizontalLineEndEvents.push(horizontalLineEndEvent(xx[i], yy[i], i));
    }
  }
  root2 = 0;
  while (!verticalLineEvents.empty() || !horizontalLineBeginEvents.empty() ||
         !horizontalLineEndEvents.empty()) {
    int nowX = INF;
    if (!verticalLineEvents.empty())
      nowX = min(nowX, verticalLineEvents.top().x);
    if (!horizontalLineBeginEvents.empty())
      nowX = min(nowX, horizontalLineBeginEvents.top().x);
    if (!horizontalLineEndEvents.empty())
      nowX = min(nowX, horizontalLineEndEvents.top().x);
    while (!horizontalLineBeginEvents.empty() &&
           horizontalLineBeginEvents.top().x == nowX) {
      horizontalLineBeginEvent t = horizontalLineBeginEvents.top();
      horizontalLineBeginEvents.pop();
      addLine2(t.y);
    }
    while (!verticalLineEvents.empty() && verticalLineEvents.top().x == nowX) {
      verticalLineEvent t = verticalLineEvents.top();
      verticalLineEvents.pop();
      result -= 1LL * crossLines2(t.l, t.r);
    }
    while (!horizontalLineEndEvents.empty() &&
           horizontalLineEndEvents.top().x == nowX) {
      horizontalLineEndEvent t = horizontalLineEndEvents.top();
      horizontalLineEndEvents.pop();
      deleteLine2(t.y);
    }
  }
  return result - 1;
}
int main() {
  srand(time(0));
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d%d%d%d", x + i, y + i, xx + i, yy + i);
    if (x[i] > xx[i]) swap(x[i], xx[i]);
    if (y[i] > yy[i]) swap(y[i], yy[i]);
    if (x[i] == xx[i]) {
      verticalLineEvents.push(verticalLineEvent(x[i], y[i], yy[i], i));
    } else {
      horizontalLineBeginEvents.push(horizontalLineBeginEvent(x[i], y[i], i));
      horizontalLineEndEvents.push(horizontalLineEndEvent(xx[i], yy[i], i));
    }
  }
  dsu.init(n);
  while (!verticalLineEvents.empty() || !horizontalLineBeginEvents.empty() ||
         !horizontalLineEndEvents.empty()) {
    int nowX = INF;
    if (!verticalLineEvents.empty())
      nowX = min(nowX, verticalLineEvents.top().x);
    if (!horizontalLineBeginEvents.empty())
      nowX = min(nowX, horizontalLineBeginEvents.top().x);
    if (!horizontalLineEndEvents.empty())
      nowX = min(nowX, horizontalLineEndEvents.top().x);
    while (!horizontalLineBeginEvents.empty() &&
           horizontalLineBeginEvents.top().x == nowX) {
      horizontalLineBeginEvent t = horizontalLineBeginEvents.top();
      horizontalLineBeginEvents.pop();
      addLine(t.y, t.idx);
    }
    while (!verticalLineEvents.empty() && verticalLineEvents.top().x == nowX) {
      verticalLineEvent t = verticalLineEvents.top();
      verticalLineEvents.pop();
      crossLines(t.l, t.r, t.idx);
    }
    while (!horizontalLineEndEvents.empty() &&
           horizontalLineEndEvents.top().x == nowX) {
      horizontalLineEndEvent t = horizontalLineEndEvents.top();
      horizontalLineEndEvents.pop();
      deleteLine(t.y, t.idx);
    }
  }
  dfs(root);
  for (int i = 1; i <= n; i++) comps[dsu.get_set(i)].push_back(i);
  long long result = 0;
  for (int i = 1; i <= n; i++) {
    result = max(result, solve(comps[i]));
  }
  cout << result << "\n";
  return 0;
}
