#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>
#include <cstring>
using namespace std;
typedef long long LL;
typedef complex<double> CMP;

class PointErasingTwo { public:
	int getMaximum(vector <int> y)
	{
		int ans = 0;
		for(int i=0; i<y.size(); ++i)
			for (int j = i+1; j < y.size(); j++)
			{
				if(y[i] != y[j]) {
					int er = 0;
					for (int k = i+1; k < j; k++)
						if( min(y[i],y[j])<y[k] && y[k]<max(y[i],y[j]) )
							++er;
					ans = max(ans, er);
				}
			}
		return ans;
	}
};

// 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(_, PointErasingTwo().getMaximum(y));}
int main(){

CASE(0)
	int y_[] = { 1, 2, 1, 1, 0, 4, 3 };
	  vector <int> y(y_, y_+sizeof(y_)/sizeof(*y_)); 
	int _ = 2; 
END
CASE(1)
	int y_[] = { 0, 1 };
	  vector <int> y(y_, y_+sizeof(y_)/sizeof(*y_)); 
	int _ = 0; 
END
CASE(2)
	int y_[] = { 0, 1, 2, 3, 4 };
	  vector <int> y(y_, y_+sizeof(y_)/sizeof(*y_)); 
	int _ = 3; 
END
CASE(3)
	int y_[] = { 10, 19, 10, 19 };
	  vector <int> y(y_, y_+sizeof(y_)/sizeof(*y_)); 
	int _ = 0; 
END
CASE(4)
	int y_[] = { 0, 23, 49, 50, 32, 0, 18, 50, 0, 28, 50, 27, 49, 0 };
	  vector <int> y(y_, y_+sizeof(y_)/sizeof(*y_)); 
	int _ = 5; 
END
/*
CASE(5)
	int y_[] = ;
	  vector <int> y(y_, y_+sizeof(y_)/sizeof(*y_)); 
	int _ = ; 
END
CASE(6)
	int y_[] = ;
	  vector <int> y(y_, y_+sizeof(y_)/sizeof(*y_)); 
	int _ = ; 
END
*/
}
// END CUT HERE
