#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <functional>
#include <complex>
#include <queue>
#include <stack>
#include <cmath>
#include <cassert>
using namespace std;
typedef long long LL;
typedef long double LD;
typedef complex<LD> CMP;

class RotatingBot { public:
	int minArea(vector <int> moves)
	{
		if( moves.size() == 1 ) {
			int w = moves[0]+1;
			return w;
		}
		if( moves.size() == 2 ) {
			int w = moves[0]+1;
			int h = moves[1]+1;
			return w*h;
		}
		if( moves.size() == 3 ) {
			int w1 = moves[0]+1;
			int h = moves[1]+1;
			int w2 = moves[2]+1;
			return max(w1,w2)*h;
		}
		if( moves.size() == 4 ) {
			int w1 = moves[0]+1;
			int h1 = moves[1]+1;
			int w2 = moves[2]+1;
			int h2 = moves[3]+1;
			if( w1 > w2 )
				return -1;
			if( w1 == w2 ) {
				if( h1 <= h2 )
					return -1;
				else
					return w1*h1;
			}
			return w2*max(h1,h2);
		}

		int w1 = moves[0]+1;
		int h1 = moves[1]+1;
		int w2 = moves[2]+1;
		int h2 = moves[3]+1;
		if( w1 > w2 )
			return -1;
		if( w1 == w2 ) {
			vector<int> rm = simulate(w1, h1, 0, 0);
			if( match(rm, moves) )
				return w1*h1;
			else
				return -1;
		} else {
			if( h2<h1 )
				return -1;
			vector<int> rm = simulate(w2, h2, w2-w1, h2-h1);
			if( match(rm, moves) )
				return w2*h2;
			else
				return -1;
		}
	}

	vector<int> simulate(int w, int h, int x, int y)
	{
		vector<int> moves;
		vector< vector<bool> > vis(h, vector<bool>(w));
		int dx[]={+1,0,-1,0};
		int dy[]={0,+1,0,-1};
		int d = 0;
		vis[y][x] = true;
		for(;;) {
			int cnt = 0;
			for(;;) {
				int xx=x+dx[d];
				int yy=y+dy[d];
				if( yy<0||h<=yy||xx<0||w<=xx||vis[yy][xx] )
					break;
				y=yy, x=xx;
				vis[y][x] = true;
				++cnt;
			}
			d = (d+1)%4;
			if( cnt == 0 )
				break;
			moves.push_back(cnt);
		}
		return moves;
	}

	bool match(const vector<int>& rm, const vector<int>& m)
	{
		if(rm.size() < m.size())
			return false;
		for(int i=0; i+1<m.size(); ++i)
			if(rm[i] != m[i])
				return false;
		return rm[m.size()-1] >= m[m.size()-1];
	}
};

// BEGIN CUT HERE
#include <ctime>
double start_time; string timer()
 { ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v)
 { os << "{ ";
   for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it)
   os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; }
void verify_case(const int& Expected, const int& Received) {
 bool ok = (Expected == Received);
 if(ok) cerr << "PASSED" << timer() << endl;  else { cerr << "FAILED" << timer() << endl;
 cerr << "\to: \"" << Expected << '\"' << endl << "\tx: \"" << Received << '\"' << endl; } }
#define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock();
#define END	 verify_case(_, RotatingBot().minArea(moves));}
int main(){

CASE(0)
	int moves_[] = {15};
	  vector <int> moves(moves_, moves_+sizeof(moves_)/sizeof(*moves_)); 
	int _ = 16; 
END
CASE(1)
	int moves_[] = {3,10};
	  vector <int> moves(moves_, moves_+sizeof(moves_)/sizeof(*moves_)); 
	int _ = 44; 
END
CASE(2)
	int moves_[] = {1,1,1,1};
	  vector <int> moves(moves_, moves_+sizeof(moves_)/sizeof(*moves_)); 
	int _ = -1; 
END
CASE(3)
	int moves_[] = {9,5,11,10,11,4,10};
	  vector <int> moves(moves_, moves_+sizeof(moves_)/sizeof(*moves_)); 
	int _ = 132; 
END
CASE(4)
	int moves_[] = {12,1,27,14,27,12,26,11,25,10,24,9,23,8,22,7,21,6,20,5,19,4,18,3,17,2,16,1,15};
	  vector <int> moves(moves_, moves_+sizeof(moves_)/sizeof(*moves_)); 
	int _ = 420; 
END
CASE(5)
	int moves_[] = {8,6,6,1};
	  vector <int> moves(moves_, moves_+sizeof(moves_)/sizeof(*moves_)); 
	int _ = -1; 
END
CASE(6)
	int moves_[] = {8,6,6};
	  vector <int> moves(moves_, moves_+sizeof(moves_)/sizeof(*moves_)); 
	int _ = 63; 
END
CASE(7)
	int moves_[] = {5,4,5,3,3};
	  vector <int> moves(moves_, moves_+sizeof(moves_)/sizeof(*moves_)); 
	int _ = 30; 
END
CASE(8)
int moves_[] = {2,2,2,1};
	  vector <int> moves(moves_, moves_+sizeof(moves_)/sizeof(*moves_)); 
	int _ = 9; 
END
/*
CASE(9)
	int moves_[] = ;
	  vector <int> moves(moves_, moves_+sizeof(moves_)/sizeof(*moves_)); 
	int _ = ; 
END
*/
}
// END CUT HERE
