#include <iostream>
#include <vector>
using namespace std;
int coord[101][101];
int dir[][2] = { {1,0}, {0,-1}, {-1,0}, {0, 1} };
int turn_clock(int d) {
return (d + 1) % 4;
}
void dragon_curve(vector<int> dragon_dir, int x, int y, int d, int g, int g_temp) {
if (g < g_temp) return;
if (g_temp == 0) {
coord[x][y] = 1;
dragon_dir.push_back(d);
coord[x + dir[d][0]][y + dir[d][1]] = 1;
dragon_curve(dragon_dir, x + dir[d][0], y + dir[d][1], d, g, g_temp + 1);
}
else {
//coord[x][y] = 1;
int next_x = x;
int next_y = y;
int i = dragon_dir.size() - 1;
for (; i >= 0; i--) {
int next_d = turn_clock(dragon_dir[i]);
next_x += dir[next_d][0];
next_y += dir[next_d][1];
coord[next_x][next_y] = 1;
dragon_dir.push_back(next_d);
}
dragon_curve(dragon_dir, next_x, next_y, d, g, g_temp + 1);
}
}
int main() {
int N;
int count = 0;
cin >> N;
for (int t = 0; t < N; t++) {
vector<int> dragon_dir;
int x, y, d, g;
cin >> x >> y >> d >> g;
dragon_curve(dragon_dir, x, y, d, g, 0);
}
for (int i = 0; i < 100; i++) {
for (int j = 0; j < 100; j++) {
if (coord[i][j] == 1 && coord[i + 1][j] == 1 && coord[i][j + 1] == 1 && coord[i + 1][j + 1] == 1)
count++;
}
}
cout << count << endl;
return 0;
}