#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define SIZE 155

struct LOC{
	LOC(int arg_y,int arg_x){
		y = arg_y;
		x = arg_x;
	}
	int y,x;
};

struct Info{

	Info(int arg_loc,char arg_ch){
		loc = arg_loc;
		ch = arg_ch;
	}
	bool operator<(const struct Info &arg) const{

		return loc < arg.loc;
	}

	char ch;
	int loc;
};

int N;
int H = 210,W = 210;
int small_H = 5,small_W = 3;

char MAP[215][215];
char words[9][5][4] = {
   {"###",
	"#.#",
	"#.#",
	"#.#",
	"###",}
	,
   {"###",
	"..#",
	"###",
	"#..",
	"###",}
	,
   {"###",
	"..#",
	"###",
	"..#",
	"###",}
   ,
   {"#.#",
	"#.#",
	"###",
	"..#",
	"..#",}
	,
   {"###",
	"#..",
	"###",
	"..#",
	"###",}
	,
   {"###",
	"#..",
	"###",
	"#.#",
	"###",}
	,

   {"###",
	"#.#",
	"###",
	"#.#",
	"###",}
   ,
   {"###",
   	"#.#",
   	"###",
   	"..#",
   	"###",}
   ,
   {"###",
  	"..#",
  	"..#",
  	"..#",
  	"..#",}
  	,
   	};
char table[9] = {'0','2','3','4','5','6','8','9','7'};
char line[SIZE],work_line[SIZE];
int diff[13] =   {0,1,0,0,0,0,0,0,0,0,0,0,1};
int ans_len = -1;

int calc_E(int left,int right);
int calc_T(int left,int right);
int calc_F(int left,int right);
int calc_NUM(int left,int right);


int calc_E(int left,int right){

	int depth = 0;
	queue<int> Q;

	//深さ0の、プラスまたは-を探す
	for(int i = left; i <= right; ){
		if(line[i] == '(')depth++;
		else if(line[i] == ')')depth--;

		if(depth != 0){
			i++;
		}else if(line[i] != '+' && line[i] != '-'){
			i++;
		}else{
			if(line[i] == '+'){
				Q.push(i);
				i++;
			}else{ //line[i] == '-'
				if((i != left) && ((line[i-1] >= '0' && line[i-1] <= '9') || line[i-1] == ')')){ //-は、depthが0でもnegの場合あり
					Q.push(i);
				}
				while(i <=right && line[i] == '-')i++; //negの-が続いている場合があるので、読み飛ばす
			}
		}
	}

	if(Q.empty()){ //深さ0の+-がない
		return calc_T(left,right);
	}

	int tmp = calc_E(left,Q.front()-1),tmp_right;

	if(tmp == BIG_NUM)return BIG_NUM;

	while(!Q.empty()){
		int loc = Q.front();
		Q.pop();

		if(Q.empty()){
			tmp_right = calc_T(loc+1,right);
		}else{
			tmp_right = calc_T(loc+1,Q.front()-1);
		}

		if(tmp_right == BIG_NUM){
			return BIG_NUM;
		}

		if(line[loc] == '+'){
			tmp += tmp_right;
		}else{
			tmp -= tmp_right;
		}
	}

	return tmp;
}

int calc_T(int left,int right){

	int depth = 0;
	queue<int> Q;

	//深さ0の、*,/を探す
	for(int i = left; i <= right; ){
		if(line[i] == '(')depth++;
		else if(line[i] == ')')depth--;

		if(depth != 0){
			i++;
		}else if(line[i] != '*' && line[i] != '/'){
			i++;
		}else{
			Q.push(i);
			i++;
		}
	}

	if(Q.empty()){ //深さ0の*がない
		return calc_F(left,right);
	}

	int tmp = calc_T(left,Q.front()-1),tmp_right;

	if(tmp == BIG_NUM)return BIG_NUM;

	while(!Q.empty()){
		int loc = Q.front();
		Q.pop();

		if(Q.empty()){
			tmp_right = calc_F(loc+1,right);
		}else{
			tmp_right = calc_F(loc+1,Q.front()-1);
		}

		if(tmp_right == BIG_NUM){
			return BIG_NUM;
		}

		if(line[loc] == '*'){
			tmp *= tmp_right;
		}else{
			tmp /= tmp_right;
		}
	}
	return tmp;
}

int calc_F(int left,int right){

	if(line[left] >= '0' && line[left] <= '9'){
		return calc_NUM(left,right);
	}else if(line[left] == '-'){
		return -1*calc_F(left+1,right);
	}else if(line[left] == '('){

		int depth = 0;
		int close_pos = BIG_NUM;

		for(int i = left; i <= right; i++){
			if(line[i] == '(')depth++;
			else if(line[i] == ')'){
				depth--;
				if(depth == 0){
					close_pos = i;
					break;
				}
			}
		}

		if(close_pos == BIG_NUM || close_pos != right)return BIG_NUM;

		return calc_E(left+1,close_pos-1);
	}else{
		return BIG_NUM;
	}
}

int calc_NUM(int left,int right){

	int ret = 0;
	for(int i = left; i <= right; i++){
		ret = 10*ret+line[i]-'0';
	}
	return ret;
}

bool recursive(int col,int index){

	if(col == W){//探索完了

		for(int i = 0; i < index; i++){

			line[i] = work_line[i];
		}
		ans_len = index;

		return true;
	}

	//この列の黒マス数を調べる
	int num_black = 0;

	for(int row = 0; row < H; row++){
		if(MAP[row][col] == '#'){

			num_black++;
		}
	}

	if(num_black == 0){ //この行には'#'がないので、次の行へ行く

		return recursive(col+1,index);
	}

	//どの文字かを調べる

	for(int row = 0; row < H; row++){
		if(MAP[row][col] == '.')continue;

		int match_word = -1;
		vector<LOC> V_LOC;

		//まずはわかりやすい9種でチェック
		for(int a = 0; a < 9; a++){
			bool FLG = true;
			V_LOC.clear();
			for(int y = 0; y < small_H; y++){
				for(int x = 0; x < small_W; x++){
					if(MAP[row+y][col+x] != words[a][y][x]){
						FLG = false;
						break;
					}
					if(MAP[row+y][col+x] == '#'){
						V_LOC.push_back(LOC(row+y,col+x)); //塗られている場所を保存
					}
				}
				if(!FLG)break;
			}
			if(!FLG)continue;

			match_word = a;
			break;
		}

		if(match_word != -1){ //一致する文字あり

			//とりあえず、黒マスを消す
			for(int k = 0; k < V_LOC.size(); k++){

				MAP[V_LOC[k].y][V_LOC[k].x] = '.';
			}

			//この列の黒マスが全て消えたかを調べる
			for(int tmp_row = 0; tmp_row < H; tmp_row++){
				if(MAP[tmp_row][col] == '#'){

					//状態を復元し、falseを返す
					for(int k = 0; k < V_LOC.size(); k++){

						MAP[V_LOC[k].y][V_LOC[k].x] = '#';
					}

					return false;
				}
			}

			//この列の黒マスは全て消えた

			work_line[index] = table[match_word];

			if(recursive(col+1,index+1)){

				return true; //trueなら復元不要

			}else{
				//falseなら復元
				for(int k = 0; k < V_LOC.size(); k++){

					MAP[V_LOC[k].y][V_LOC[k].x] = '#';
				}
				return false;
			}
		}

		if(MAP[row+1][col] == '#'){ //1しか該当するものがない場合

			if(num_black != 5)return false;

			for(int tmp_row = 0; tmp_row < 5; tmp_row++){ //とりあえず黒マスを消す

				if(MAP[row+tmp_row][col] == '#'){

					V_LOC.push_back(LOC(row+tmp_row,col));
				}

				MAP[row+tmp_row][col] = '.';
			}

			//この列の黒マスが全て消えたかを調べる
			for(int tmp_row = 0; tmp_row < H; tmp_row++){
				if(MAP[tmp_row][col] == '#'){

					//状態を復元し、falseを返す
					for(int k = 0; k < V_LOC.size(); k++){

						MAP[V_LOC[k].y][V_LOC[k].x] = '#';
					}
					return false;
				}
			}

			//この列の黒マスは全て消えた
			work_line[index] = '1';

			if(recursive(col+1,index+1)){

				return true; //trueなら復元不要

			}else{
				//falseなら復元
				for(int k = 0; k < V_LOC.size(); k++){

					MAP[V_LOC[k].y][V_LOC[k].x] = '#';
				}
				return false;
			}

		}else{ //[+,-,*]のいずれか

			if(num_black != 1)return false;

			//+
			if(MAP[row-1][col+1] == '#' && MAP[row][col+1] == '#' && MAP[row+1][col+1] == '#' && MAP[row][col+2] == '#'){

				//とりあえず黒マスを消す
				MAP[row][col] = '.';
				MAP[row-1][col+1] = '.';
				MAP[row][col+1] = '.';
				MAP[row+1][col+1] = '.';
				MAP[row][col+2] = '.';

				work_line[index] = '+';

				if(recursive(col+1,index+1)){

					return true; //trueなら復元不要

				}else{
					//falseなら復元
					MAP[row][col] = '#';
					MAP[row-1][col+1] = '#';
					MAP[row][col+1] = '#';
					MAP[row+1][col+1] = '#';
					MAP[row][col+2] = '#';
				}
			}

			//-
			if(MAP[row][col+1] == '#' && MAP[row][col+2] == '#'){

				//とりあえず黒マスを消す
				MAP[row][col] = '.';
				MAP[row][col+1] = '.';
				MAP[row][col+2] = '.';

				work_line[index] = '-';

				if(recursive(col+1,index+1)){

					return true; //trueなら復元不要

				}else{
					//falseなら復元
					MAP[row][col] = '#';
					MAP[row][col+1] = '#';
					MAP[row][col+2] = '#';
				}
			}

			//*
			//とりあえず黒マスを消す
			MAP[row][col] = '.';

			work_line[index] = '*';

			if(recursive(col+1,index+1)){

				return true; //trueなら復元不要

			}else{
				//falseなら復元
				MAP[row][col] = '#';
			}
		}
		break;
	}
	return false;
}

int main(){

	for(int row = 0; row < H; row++){
		for(int col = 0; col < W; col++){

			MAP[row][col] = '.';
		}
	}

	scanf("%d",&N);

	int x1,y1,x2,y2;

	//マップを塗る
	for(int loop = 0; loop < N; loop++){

		scanf("%d %d %d %d",&x1,&y1,&x2,&y2);

		if(x1 == x2){ //縦

			for(int y = min(y1,y2); y <= max(y1,y2); y++){

				MAP[y][x1] = '#';
			}

		}else{ //y1 == y2:横

			for(int x = min(x1,x2); x <= max(x1,x2); x++){

				MAP[y1][x] = '#';
			}
		}
	}

	recursive(0,0);

	printf("%d\n",calc_E(0,ans_len-1));

	return 0;
}



Measured memory_bytes: 3328