/*
 * d.cc: 
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

const int MAX_N = 150;
const int H = 201;
const int W = 201;
//const int H = 30;
//const int W = 30;
const int CH = 5;
const int CW = 3;

const int INF = 1 << 30;

const int dxs[] = {1, 0, -1, 0}, dys[] = {0, -1, 0, 1};

/* typedef */

typedef pair<int,int> pii;
typedef vector<pii> vpii;

enum { OP_PLUS = 10, OP_MINUS = 11, OP_MUL = 12 };

/* global variables */

bool flds[H][W], used[H][W];
vpii e;

/* subroutines */

inline char chs(int c) {
  if (c == OP_PLUS) return '+';
  if (c == OP_MINUS) return '-';
  if (c == OP_MUL) return '*';
  return '0' + c;
}

int num(vpii &e, int &pos) {
  int d = 0;
  while (pos < e.size() && e[pos].second <= 9)
    d = d * 10 + e[pos++].second;
  return d;
}

int term(vpii &e, int &pos) {
  int t0 = num(e, pos);
  while (pos < e.size() && e[pos].second == OP_MUL) {
    pos++; // OP_MUL
    int t1 = num(e, pos);
    t0 *= t1;
  }
  return t0;
}

int expr(vpii &e, int &pos) {
  int e0 = term(e, pos);
  while (pos < e.size() &&
	 (e[pos].second == OP_PLUS || e[pos].second == OP_MINUS)) {
    int sign = (e[pos].second == OP_PLUS) ? 1 : -1;
    pos++; // OP_PLUS || OP_MINUS
    int e1 = term(e, pos);
    e0 += e1 * sign;
  }
  return e0;
}

/* main */

int main() {
  int n;
  cin >> n;

  for (int i = 0; i < n; i++) {
    int x0, y0, x1, y1;
    cin >> x0 >> y0 >> x1 >> y1;

    if (x0 > x1) swap(x0, x1);
    if (y0 > y1) swap(y0, y1);
    int dx = ((x0 == x1) ? 0 : 1), dy = ((y0 == y1) ? 0 : 1);

    for (int x = x0, y = y0; x != x1 || y != y1; x += dx, y += dy)
      flds[y][x] = true;
    flds[y1][x1] = true;
  }

  if (false)
    for (int y = 0; y < H; y++) {
      for (int x = 0; x < W; x++) putchar(flds[y][x] ? 'X' : '.');
      putchar('\n');
    }

  for (int y0 = 0; y0 < H; y0++)
    for (int x0 = 0; x0 < W; x0++)
      if (flds[y0][x0] && ! used[y0][x0]) {
	used[y0][x0] = true;
	int minx = x0, maxx = x0, miny = y0, maxy = y0;
	int size = 1;
	queue<pii> q;
	q.push(pii(x0, y0));

	while (! q.empty()) {
	  pii u = q.front(); q.pop();
	  int &ux = u.first, &uy = u.second;
	  for (int di = 0; di < 4; di++) {
	    int vx = ux + dxs[di], vy = uy + dys[di];
	    if (vx >= 0 && vx < W && vy >= 0 && vy < H &&
		flds[vy][vx] && ! used[vy][vx]) {
	      used[vy][vx] = true;
	      size++;
	      q.push(pii(vx, vy));
	      if (minx > vx) minx = vx;
	      if (maxx < vx) maxx = vx;
	      if (miny > vy) miny = vy;
	      if (maxy < vy) maxy = vy;
	    }
	  }
	}

	if (false) {
	  printf("(%d,%d)-(%d,%d) %d\n", minx, miny, maxx, maxy, size);
	  for (int y = miny; y <= maxy; y++) {
	    for (int x = minx; x <= maxx; x++) putchar(flds[y][x] ? 'X' : '.');
	    putchar('\n');
	  }
	}

	int num = -1;
	int dx = maxx - minx + 1, dy = maxy - miny + 1;

	if (size == 1) num = OP_MUL;
	else if (size == 3) num = OP_MINUS;
	else if (size == 5) {
	  if (dx == 1) num = 1;
	  else num = OP_PLUS;
	}
	else if (size == 7) num = 7;
	else if (size == 9) num = 4;
	else if (size == 11) {
	  bool b0 = flds[miny + 1][minx], b1 = flds[miny + 3][minx];
	  if (! b0 && b1) num = 2;
	  else if (! b0 && ! b1) num = 3;
	  else num = 5;
	}
	else if (size == 12) {
	  if (! flds[miny + 2][minx + 1]) num = 0;
	  else if (! flds[miny + 1][maxx]) num = 6;
	  else num = 9;
	}
	else num = 8;

	e.push_back(pii(minx, num));
      }

  sort(e.begin(), e.end());
  //for (int i = 0; i < e.size(); i++) putchar(chs(e[i].second)); putchar('\n');

  int pos = 0;
  int ans = expr(e, pos);

  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 1192