#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define input freopen("1.txt","r",stdin);
#define output freopen("output.txt","w",stdout);
#define ll long long int
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#define vi vector<int>
#define vii vector<vi>
#define vl vector<ll>
#define vll vector<vl>
#define pii pair<int, int>
#define pll pair<ll,ll>
#define mp make_pair
#define vpi vector<pii>
#define vpl vector<pll> 
#define ss second 
#define ff first

using namespace std;

const int p = 1e9 + 7;
const int maxn = 1e5 + 1;

void solve() {
    int n; cin >> n;
    int l[n];
    // vi psides;
    for(int i = 0; i < n; i++) cin >> l[i];
    int ans = 0;
    for(int i = 0; i < n; i++) {
        for(int j = i+1; j < n; j++) {
            for(int k = j+1; k < n; k++) {
                if(l[i] != l[j] && l[i] != l[k] && l[j] != l[k]) {
                    vi sides = {l[i], l[j], l[k]};
                    sort(sides.begin(), sides.end());
                    if(sides[0] + sides[1] > sides[2]) ans++;
                }
            }
        }
    }
    cout << ans;
}

int main() {
    fast
    int t = 1; 
    // cin >> t;
    while(t--) solve();
    return 0;
}
#include<bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

char in[1000100];

int main(){
	fgets(in, sizeof(in), stdin);
	vector<pi> v;
	int cnt = 0, ans = 0;
	
	for(int i = 0; ; i++){
		if(i && in[i] != in[i - 1]){
			v.pb(mp(in[i - 1], cnt));
			cnt = 1;
		}
		else cnt++;
		if(!in[i]) break;
	}
	
	rep(i, v.size() - 2) if(v[i].first == 'J'
		&& v[i + 1].first == 'O'
		&& v[i + 2].first == 'I'){
		
		if(v[i + 1].second <= v[i].second && v[i + 1].second <= v[i + 2].second)
		ans = max(ans, v[i + 1].second);
	}
	
	cout << ans << endl;
	
	return 0;
}