#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 TeamContest { public:
int worstRank(vector <int> s)
{
int N = s.size()/3;
int us = str(s[0], s[1], s[2]);
sort(s.begin()+3, s.end());
int L = 0; // |<=us| <= 0 is impossible
int R = N-1; // |<=us| <= N-1 is possible
while(R-L>1)
{
int C = (L+R)/2;
(possible(us, C, s) ? R : L) = C;
}
return N-R;
}
int str(int a, int b, int c)
{
return max(max(a,b),c) + min(min(a,b),c);
}
// |<=us| <= UB possible?
bool possible(int us, int UB, const vector<int>& s)
{
int si = 3;
// from weak teams
while(UB > 0) {
if(si==s.size())
return true;
si += 3;
--UB;
}
if(si==s.size())
return true; // no more team left
// can we make every other teams stronger than ourselves?
vector<int> ss(s.begin()+si, s.end());
while(!ss.empty())
if(!takeOut(us, ss))
return false;
return true;
}
bool takeOut(int us, vector<int>& s)
{
int a = s[0];
s.erase(s.begin());
int b = s[0];
s.erase(s.begin());
for(int i=0; i<s.size(); ++i) {
int c = s[i];
if(str(a,b,c) > us) {
s.erase(s.begin()+i);
return true;
}
}
return false;
}
};
// 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(_, TeamContest().worstRank(strength));}
int main(){
CASE(0)
int strength_[] = {5, 7, 3, 5, 7, 3, 5, 7, 3};
vector <int> strength(strength_, strength_+sizeof(strength_)/sizeof(*strength_));
int _ = 2;
END
CASE(1)
int strength_[] = {5, 7, 3}
;
vector <int> strength(strength_, strength_+sizeof(strength_)/sizeof(*strength_));
int _ = 1;
END
CASE(2)
int strength_[] = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
vector <int> strength(strength_, strength_+sizeof(strength_)/sizeof(*strength_));
int _ = 1;
END
CASE(3)
int strength_[] = {3,9,4,6,2,6,1,6,9,1,4,1,3,8,5}
;
vector <int> strength(strength_, strength_+sizeof(strength_)/sizeof(*strength_));
int _ = 3;
END
CASE(4)
int strength_[] = {53,47,88,79,99,75,28,54,65,14,22,13,11,31,43}
;
vector <int> strength(strength_, strength_+sizeof(strength_)/sizeof(*strength_));
int _ = 3;
END
CASE(5)
int strength_[] = {2,2,2,1,1,1,1,1,5};
vector <int> strength(strength_, strength_+sizeof(strength_)/sizeof(*strength_));
int _ = 2;
END
/*
CASE(6)
int strength_[] = ;
vector <int> strength(strength_, strength_+sizeof(strength_)/sizeof(*strength_));
int _ = ;
END
*/
}
// END CUT HERE