#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll MOD = 1000000007;

bool check(int a,int b,int c)
{
    if((a+b)>c && (c+b)>a && (a+c)>b)
        return true;
    return false;
}

int main()
{
    // freopen("input01.txt", "r", stdin);
    // freopen("output01.txt", "w", stdout);
    int n;
    cin>>n;
    map<ll int,int> mp;
    ll int a;
    int l,ct=0;
    for(l=0;l<n;l++)
    {
        cin>>a;
        mp[a]++;
    }

    if(mp.size()<3)
    {
        cout<<0;
        return 0;
    }

    for(auto i=mp.begin();next(next(i))!=mp.end();i++)
    {
        for(auto j=next(i);next(j)!=mp.end();j++)
        {
            for(auto k=next(j);k!=mp.end();k++)
            {
                if(check(i->first,j->first,k->first))
                    ct+=(i->second*j->second*k->second);
            }
        }
    }

    cout<<ct;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ","; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ","; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << "," << pa.second << ")"; return os; }
#define dbg(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;

void Yes()
{
    puts("Yes");
    exit(0);
}

void No()
{
    puts("No");
    exit(0);
}

// 1-indexed BIT (i : [1, len])
template<typename T>
struct BIT : std::vector<T>
{
    BIT(int len = 0) : std::vector<T>(len + 1) {}
    void reset() { fill(this->begin(), this->end(), 0); }
    void add(int pos, T v) {
        while (pos > 0 and pos < (int)this->size()) (*this)[pos] += v, pos += pos & -pos;
    }
    T sum(int pos) const { // (0, pos]
        T res = 0;
        while (pos > 0) res += (*this)[pos], pos -= pos & -pos;
        return res;
    }
    friend std::ostream &operator<<(std::ostream &os, const BIT &bit) {
        T prv = 0;
        os << '[';
        for (int i = 1; i < (int)bit.size(); i++) {
            T now = bit.sum(i);
            os << now - prv << ",";
            prv = now;
        }
        os << ']';
        return os;
    }
};

vector<int> parity(vector<int> V)
{
    int N = 1e5;
    BIT<int> bit(N);
    vector<int> ret(V.size() * 2 - 1);
    lint ten = 0;
    REP(i, V.size()) {
        int dest = (V[i] - 1);
        ret[dest * 2] += abs(dest - i);
        // if (i) {
        //     // int nb_empty = i - bit.sum(i);
        //     // ret[i * 2 - 1] += nb_empty;
        // }
        ten += bit.sum(N) - bit.sum(V[i]);
        bit.add(V[i], 1);
    }
    ret[1] += ten % 2;
    // dbg(V);
    // dbg(ret);
    return ret;
}

int main()
{
    int N;
    cin >> N;
    vector<vector<int>> A(3, vector<int>(N));
    cin >> A;
    vector<vector<int>> val(2);
    vector<int> inv;
    REP(i, N) {
        REP(d, 2) if (abs(A[d][i] - A[d + 1][i]) != 1) No();
        int invtmp = 0;
        if (A[0][i] > A[2][i]) invtmp = 1;
        int tmp = min(A[0][i], A[2][i]) / 3;
        if (abs(tmp - i) % 2) No();
        val[i % 2].emplace_back(tmp / 2 + 1), inv.emplace_back(invtmp);
    }
    // dbg(val);
    vector<int> v1 = parity(val[0]);
    vector<int> v2 = parity(val[1]);
    REP(i, v1.size()) inv.at(i) ^= v1.at(i) % 2;
    REP(i, v2.size()) inv.at(i + 1) ^= v2.at(i) % 2;
    // dbg(inv);
    vector<int> cou(4);
    REP(i, N) cou[i % 4] ^= inv[i];
    // dbg(cou);
    int tot = accumulate(cou.begin(), cou.end(), 0);
    if (tot % 4 == 0) Yes();
    if (tot % 2) No();
    if (tot % 4 == 0 or (cou[0] ^ cou[2]) == 0) Yes();

    No();
}


#include <cstdio>
#include <iostream>
#include <cmath>
#include <ctype.h>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>

using namespace std;

int main()
{
	int n;
	while(1){
		cin >> n;
		if(n == 0) break;
		int key[200];
		char s[200], right_s[200], ch;
		for(int i = 0; i < n; i++){
			cin >> key[i];
		}
		ch = getchar();
		fgets(s, sizeof(s), stdin);
		int wronglist[200]={0}, rightlist[200];
		for(int i = 0; i < strlen(s)-1; i++){
			wronglist[i] = s[i] - 'A';
			if(wronglist[i] > 25) wronglist[i] -= 6;
			rightlist[i] = wronglist[i] - key[i%n];
			if(rightlist[i] < 0) rightlist[i] = 52 + rightlist[i];
			if(rightlist[i] > 25) rightlist[i] += 6;
			right_s[i] = rightlist[i] + 'A';
		}
		right_s[strlen(s)-1] = '\0';
		cout << right_s << endl;
	}
	return 0;
}

//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <queue>

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

void sub(char& ch, int d){
  REP(i,d)
	if(ch == 'a')
	  ch = 'Z';
	else if(ch == 'A')
	  ch = 'z';
	else
	  --ch;
}

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N;
  while(cin>>N, N){
	VI key(N);
	REP(i,N) cin >> key[i];
	string str; cin >> str;
	REP(i,SZ(str)){
	  sub(str[i], key[i%N]);
	}
	cout << str << endl;
  }

  return 0;
}


#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<vector>
#include<utility>
#include<stack>
#include<queue>

#define FOR(i, a, b) for(int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define MOD 1000000007

using namespace std;

int main(void) {
	int total = 0;
	int n;
	int t;

	while (cin >> n) {
		total = 0;
		t = 600 - n;
		while (t>0) {
			total += t*t*n;
			t -= n;
		}
		cout << total << endl;
	}

	return 0;
}

#include <iostream>
#include <iomanip>
using namespace std;
#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,j) for(int i=0;i<j;i++)

bool has3(int p){
	while(p){
		if(p % 10 == 3) return true;
		p /= 10;
	}
	return false;
}

void call(int n){
	REP(i,1,n + 1){
		if(i % 3 == 0 || has3(i))
			cout << " " << i;
	}
}

int main(void){
	int a;
	cin >> a;
	call(a);
	cout << endl;
}


#include<bits/stdc++.h>
using namespace std;
#define rep(i,n); for(int i = 0;i < (int)(n);i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
int main(){
    int n;
    cin >> n;
    string s,t;
    cin >> s >> t;
    int ans = 2*n;
    for(int i = 1;i <= n;i++){
        string sx = s.substr(n-i,i);
        string tx = t.substr(0,i);
        if(sx == tx)ans = 2*n - i;
    }
    cout << ans << endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)

bool isJudge(lli bit){
    REP(i,0,10){
        if( (bit&(1LL<<i)) && ( bit& (1LL<< (i+1) ) ) )return false;
    }
    return true;
}

lli dp[120][10];

void func(long long H, long long W, long long K){

    dp[0][0]=1;

    REP(i,0,H){
        for(lli bit=0;bit<(1LL<<W);bit++){
            if(!isJudge(bit))continue;
            if((bit&(1LL<<(W-1))))continue;

            REP(j,0,W){
                if((bit&(1LL<<j))){
                    dp[i+1][j+1] += dp[i][j];
                    dp[i+1][j+1] %= MOD;
                    dp[i+1][j]   += dp[i][j+1];
                    dp[i+1][j]   %= MOD;
                    j++;
                }
                else{
                    dp[i+1][j] += dp[i][j];
                    dp[i+1][j] %= MOD;
                }
            }
        }
    }
    cout<<dp[H][K-1]%MOD<<endl;

}

int main(){
    // cout << fixed << setprecision(5);

    long long H;
    scanf("%lld",&H);
    long long W;
    scanf("%lld",&W);
    long long K;
    scanf("%lld",&K);
    func(H, W, K);
    return 0;
}


#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
const int need[10] = {0, 2,5,5,4,5,6,3,7,6};
const int N = 10005;
string dp[N];
void chmax (string& s, string t) {
  if ((int) s.size() < (int) t.size()) s = t;
  else if ((int) s.size() < (int) t.size()) return;
  for (int i = 0; i < (int) s.size(); i++) {
    if (s[i] != t[i]) {
      if (t[i] > s[i]) {
        s = t;
        return;
      } else {
        return;
      }
    }
  }
}
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  //string test = "74";
  //chmax(test, "47");
  int n, m;
  cin >> n >> m;
  vector<int> a(m);
  for (int i = 0; i < m; i++) cin >> a[i];
  dp[0] = "";
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j < m; j++) {
      if (i + need[a[j]] <= n && (i == 0 || dp[i] != "")) {
        chmax(dp[i + need[a[j]]], dp[i] + (char) (a[j] + '0'));
      }
    }
  }
  cout << dp[n] << endl;
  return 0;
}

#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
using ll=long long;
constexpr ll mod=1000000007;
constexpr int inf=1000000000;
constexpr ll linf=1000000000000000000;

ll modpow(ll x,ll n){
    ll res=1;
    while(n>0){
        if(n&1)res=res*x%mod;
        x=x*x%mod;
        n>>=1;
    }
    return res;
}

ll dp[201][100001];

int main(){
    int n,x;
    cin>>n>>x;
    ll s[n];
    rep(i,n)cin>>s[i];
    sort(s,s+n,greater<ll>());
    dp[0][x]=1;
    for(int i=0;i<n;++i){
        ll p=modpow(n-i,mod-2);
        for(int j=0;j<=x;++j){
            dp[i+1][j%s[i]]=(dp[i+1][j%s[i]]+dp[i][j]*p)%mod;
            dp[i+1][j]=(dp[i+1][j]+dp[i][j]*(mod+1-p))%mod;
        }
    }
    ll ans=0;
    for(int i=0;i<=x;++i){
        ans=(ans+i*dp[n][i])%mod;
    }
    rep(i,n){
        ans=(ans*(i+1))%mod;
    }
    cout<<ans<<endl;
}


#include <bits/stdc++.h>
using namespace std;
using pii = pair<int,int>;
using pll = pair<long long, long long>;
const long long INF = 1<<29;

const int MOD = 1000000007;
long long ruizyou(long long m,long long n){
  if(m == 0)return 0;
  if(m == 1)return 1;
  long long ans = 1;
  long long tmp = m;
  for(int i=0;i<=30;i++){
    if(n & (1<<i)){
      ans *= tmp;
      ans %= MOD;
    }
    tmp *= tmp;
    tmp %= MOD;
  }
  return ans;
}
long long kaizyou(long long x){
  if(x == 0)return 1;
  return x * kaizyou(x-1) % MOD;
}
long long comb(long long x,long long y){
  long long bunsi = kaizyou(x);
  long long bunbo = kaizyou(x-y) * kaizyou(y) % MOD;
  return bunsi * ruizyou((int)bunbo,MOD-2) % MOD;
}
struct unionfind{
  vector<int> par;
  vector<int> hukasa;
  unionfind(int n){
    par = vector<int>(n);
    hukasa = vector<int>(n,0);
    for(int i=0;i<n;i++){
      par.at(i) = i;
    }
  }
  int root(int x){
    if(par.at(x) == x)return x;
    return root(par.at(x));
  }
  void unite(int x,int y){
    int rx = root(x);
    int ry = root(y);
    if(rx == ry)return;
    if(hukasa.at(rx) >= hukasa.at(ry)){
      par.at(ry) = rx;
      hukasa.at(rx) = max(hukasa.at(ry) + 1,hukasa.at(rx));
    }
    else{
      par.at(rx) = ry;
    }
  }
  bool same(int x,int y){
    return root(x) == root(y);
  }
};
int ctoi(char a){
  return a - '0';
}
long long gcd(long long a,long long b){
  long long c = max(a,b);
  long long d = min(a,b);
  if(d % c == 0)return c;
  return gcd(c,d%c);
}
long long lcm(long long a,long long b){
  return a * b / gcd(a,b);
}
int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i=0;i<n;i++)cin >> a.at(i);
  vector<int> dp(3,0);
  int count2 = 0,count3 = 0;
  bool flag = false;
  for(int i=0;i<n;i++){
    int m = 3;
    int count = 0;
    for(int j=0;j<3;j++){
      if(dp.at(j) == a.at(i)){
        m = min(m,j);
        count++;
      }
    }
    if(m == 3){
      flag = true;
      break;
    }
    dp.at(m)++;
    if(count == 2)count2++;
    if(count == 3)count3++;
  }
  if(flag)cout << 0 << endl;
  else{
  long long ans = 1;
  ans *= ruizyou(2,count2);
  ans *= ruizyou(3,count3);
  cout << ans % MOD << endl;
  }
}

#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>
#include <bitset>
#include<stack>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;

template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T>
map<T, T> getPrimeFactor(T n) {
	map<T, T> res;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			res[i] ++;
			n /= i;
		}
	}
	if (n != 1) res[n] = 1;
	return res;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	if (num <= 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	return true;
}

long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

// 繰り返し二乗法
ll pow2(ll n, ll p, ll mod) {
	if (p == 0 || n == 1) {
		return 1;
	}
	else {
		ll ret = pow2(n * n % mod, p / 2, mod);
		if (p % 2 == 1) {
			ret *= n;
		}
		return ret % mod;
	}
}

#define rep(i,s,e) for(ll i=s;i<e;i++)
#define repeq(i,s,e) for(ll i=s;i<=e;i++)

int main() {
	const ll mod = 1e9 + 7;

	ll N;
	std::cin >> N;

	ll ans = 1;
	vll c(N+1, 0);
	c[0] = 3;
	rep(i, 0, N) {
		ll A;
		std::cin >> A;
		ans *= c[A];
		ans %= mod;
		c[A]--;
		c[A + 1]++;
	}

	std::cout << ans << endl;
	return 0;
}


const long long MOD = 1e9 + 7;
const int N = 203010;

#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <time.h>
#include <unordered_set>
#include <bitset>
#include <deque>

using namespace std;

#define int long long

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<ll> vi;

#define forn(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define fi first
#define se second
#define re return
#define uniq(x) sort(all(x)); (x).resize(unique(all(x)) - (x).begin())

#ifdef LOCAL
#define dbg(x) cerr << __LINE__ << " " << #x << " " << x << endl
#define ln cerr << __LINE__ << endl
#else
#define dbg(x) void(0)
#define ln void(0)
#endif // LOCAL

int cx[4] = {-1, 0, 1, 0};
int cy[4] = {0, -1, 0, 1};

ll inq(ll x, ll y)
{
    if (!y) re 1 % MOD;
    ll l = inq(x, y / 2);
    if (y % 2) re l * l % MOD * x % MOD;
    re l * l % MOD;
}

ll rev(ll x)
{
    return inq(x, MOD - 2);
}

bool __precomputed_combinatorics = 0;
vector<ll> __fact, __ufact, __rev;

void __precompute_combinatorics()
{
    __precomputed_combinatorics = 1;
    __fact.resize(N);
    __ufact.resize(N);
    __rev.resize(N);
    __rev[1] = 1;
    for (int i = 2; i < N; i++) __rev[i] = MOD - __rev[MOD % i] * (MOD / i) % MOD;
    __fact[0] = 1, __ufact[0] = 1;
    for (int i = 1; i < N; i++) __fact[i] = __fact[i - 1] * i % MOD, __ufact[i] = __ufact[i - 1] * __rev[i] % MOD;
}

ll fact(int x)
{
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[x];
}

ll cnk(int n, int k)
{
    if (k < 0 || k > n) return 0;
    if (!__precomputed_combinatorics) __precompute_combinatorics();
    return __fact[n] * __ufact[n - k] % MOD * __ufact[k] % MOD;
}

int n, m, v, p;
int a[N];

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> m >> v >> p;
    for (int i = 0; i < n; i++) cin >> a[i];
    sort(a, a + n);
    int L = -1, R = n - p;
    while (L + 1 < R)
    {
        int M = (L + R) / 2;
        int le = M;
        int ri = p - 1;
        int t = 0;
        dbg(M);
        dbg(le + ri + 1);
        {
            int V = v - (le + ri + 1);
            int WE = a[M] + m;
            vector<int> maxvote;
            for (int i = M + 1; i <= n - p; i++)
            {
                maxvote.push_back(WE - a[i]);
            }
            if (maxvote.back() < 0)
            {
                t = 0;
            }
            else
            {
                ll si = 0;
                for (int i = 0; i < maxvote.size(); i++) si += maxvote[i];
                if (si >= V * m) t = 1;
            }
        }
        if (t) R = M;
        else L = M;
    }
    cout << n - R;
}

/* Note:
Check constants at the beginning of the code.
    N is set to 4e5 but be careful in problems with large constant factor.
    Setting N in every problem is more effective.
Check corner cases.
    N = 1
No def int long long for now.
Add something here.
*/

#include <cstring>
#include <algorithm>
#include <cstdio>
#define int long long
#define ri register int
#define N 100005
using namespace std;
int n,m,v,p,t=0,ans,a[N]= {0};
template <typename T> inline void read(T &x) {
    T c=getchar(),f=0;
    for (; c<48||57<c; c=getchar()) if (c=='-') f=1;
    for (x=0; 48<=c&&c<=57; c=getchar()) x=(x<<3)+(x<<1)+(c^48);
    if (f) x=-x;
}
template <typename T> inline void print(T x) {
    if (x<0) x=-x,putchar('-');
    if (x>9) print(x/10);
    putchar(x%10+48);
}
signed main() {
	read(n),read(m),read(v),read(p),ans=p;
	for (ri i=1; i<=n; i++) read(a[i]);
	sort(a+1,a+1+n),reverse(a+1,a+1+n);
	for (ri i=p+1; i<=n; i++) {
		if (a[i]+m<a[p]) break;
		if (v<=(p-1)+(n-i+1)) ans++;
		else if ((v-p-n+i)*m<=t) ans++;
		else if (((v-p-n+i)*m-t-1)/(i-p)+1+a[p]<=a[i]+m) ans++;
		t+=a[p]-a[i];
	}
	print(ans),putchar('\n');
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int  ll;
ll  v[200009];
int main() {
	// #ifndef ONLINE_JUDGE
	// 	// for getting input from input.txt
	// 	freopen("input.txt", "r", stdin);
	// 	// for writing output to output.txt
	// 	freopen("output.txt", "w", stdout);
	// #endif
	ll n,t,ans =0;
	cin>>n>>t;
	// ans = t;
	// vector<ll> v(n,0);
	for (ll i = 1; i <=n; ++i)
	{
		cin>>v[i];
	}
	for (ll i = 1; i <= n-1; ++i)
	{
		if(v[i+1] - v[i] <= t){
			ans = ans + (v[i+1]-v[i]);
		}
		else{
			ans = ans + t;
		}
	}

	cout<<ans+t<<"\n";
	return 0;
    }

#include <bits/stdc++.h>
using namespace std;

int main() {
  int A, B;
  cin >> A >> B;

  int ret = 0;

  for (int i = A; i <= B; i++) {
    int s1, s2, s4, s5;
    s1 = i / 10000;
    s5 = i % 10;

    if (s1 != s5) {
      continue;
    }

    s2 = (i / 1000) % 10;
    s4 = (i / 10) % 10;

    if (s2 == s4)
      ret++;
  }

  cout << ret << endl;
}


#include <bits/stdc++.h>
#define MAX 60
#define browse for (int i = 0; i < MAX; ++i) for (int j = 0; j < MAX; ++j) for (int ii = 0; ii < MAX; ++ii) for (int jj = 0; jj < MAX; ++jj)

using namespace std;

int n, cnt[MAX][MAX], a, b;
long long y, ans;
long double x;

int main() {
    cin >> n;

    while (n--) {
        cin >> x;

        y = (long long)(x * 1e9 + 0.5);
        a = 0;
        b = 0;

        while (y % 2 == 0) {
            y /= 2;
            ++a;
        }

        while (y % 5 == 0) {
            y /= 5;
            ++b;
        }

        ++cnt[a][b];
    }

    browse
        if (make_pair(i, j) <= make_pair(ii, jj) && i + ii >= 18 && j + jj >= 18) {
            if (i == ii && j == jj)
                ans += (long long) cnt[i][j] * (cnt[i][j] - 1) / 2;
            else
                ans += (long long) cnt[i][j] * cnt[ii][jj];
        }

    cout << ans;
    return 0;
}

// https://atcoder.jp/contests/abc134/tasks/abc134_d
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    bitset<200001> bs;
    FOR(i, 1, N + 1) {
        int t;
        cin >> t;
        if (t) {
            bs.set(i);
        }
    }
    bitset<200001> ans;
    int cnt = 0;
    for (int i = N; i >= 1; i--) {
        int sum = 0;
        for (int j = i * 2; j <= N; j += i) {
            sum += ans[j];
        }
        if (sum % 2 != bs[i]) {
            ans.set(i);
            cnt++;
        }
    }
    cout << cnt << "\n";
    for (int i = 1; i <= N; i++) {
        if (ans[i]) {
            cout << i << (--cnt ? " " : "\n");
        }
    }

    return 0;
}


#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <functional>

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int,int> PII;
typedef long long ll;
typedef unsigned long long ull;

#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); i++ )
#define UREP( i, m, n ) for ( unsigned int i = (unsigned int)( m ); i < (unsigned int)( n ); i++ )

#define ITER( c ) __typeof( (c).begin() )
#define IREP( c, it ) for ( ITER(c) it = c.begin(); it != c.end(); ++it )
#define ALL( c ) (c).begin(), (c).end()
#define RALL( c ) (c).rbegin(), (c).rend()

#define PB( n ) push_back( n )
#define MP( a, b ) make_pair( ( a ), ( b ) )
#define EXIST( c, e ) ( (c).find( e ) != (c).end() )

#define fst first
#define snd second

#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define DEBUG( x ) cerr << __FILE__ << ":" << __LINE__ << ": " << #x << " = " << ( x ) << endl

int main()
{
	string buffer;

	while ( getline( cin, buffer ) )
	{
		UREP( i, 0, buffer.length() )
		{
			if ( buffer[i] == ',' )
			{
				buffer[i] = ' ';
			}
		}

		vector<int> l;
		l.PB( 0 );
		istringstream iss( buffer );

		REP( i, 0, 10 )
		{
			int input;
			iss >> input;
			l.PB( l.back() + input );
		}

		int v1, v2, res;
		iss >> v1 >> v2;

		UREP( i, 0, 11 )
		{
			if ( l[i] / (double)v1 < ( l.back() - l[i] ) / (double)v2 )
			{
				res = i;
			}
			else
			{
				res++;
				break;
			}
		}

		cout << res << endl;
	}

	return 0;
}

#include<iostream>
#include<vector>
#include<string>
#include<sstream>
using namespace  std;
vector<string> split(const string &s, char delimiter)
{
	vector<string> ret;
	size_t now = 0, find;
	while ((find = s.find_first_of(delimiter, now)) != string::npos)
	{
		ret.push_back(string(s, now, find - now));
		now = find + 1;
	}
	ret.push_back(string(s, now, s.size() - now));
	return ret;
}
int main()
{
	string in;
	while (cin >> in)
	{
		vector<string> v = split(in, ',');
		int disSum = 0;
		int dis[10];
		int sp[2];
		for (int i = 0; i < v.size(); i++)
		{
			stringstream ss;
			ss << v[i];
			if (i < 10)
			{
				ss >> dis[i];
				disSum += dis[i];
			}
			else
			{
				ss >> sp[i - 10];
			}
		}
		double a = disSum * sp[0] / (sp[0] + sp[1]);
		double b = disSum * sp[1] / (sp[0] + sp[1]);

		double fromStart = 0.0;
		double fromEnd = 0.0;
		int i = 0, j = 0;
		for (i = 0; i < 10; i++)
		{
			if (fromStart >= a)
			{
				break;
			}
			fromStart += dis[i];
		}
		for (j = 9; j >= 0; j--)
		{
			if (fromEnd >= b)
			{
				break;
			}
			fromEnd += dis[j];
		}
		/*cout << i << " " << j << endl;
		cout << a << " " << b << " " << fromStart << " " << fromEnd << endl;*/
		if (fromStart == a && fromEnd == b)
		{
			cout << i << endl;
		}
		else
		{
			if (fromStart == fromEnd)i++;
			cout << i << endl;
		}

	}
	return 0;
}


#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <string>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  int cnt = 0;
  while (1) {
    rep(i, n) {
      if (a[i] % 2 != 0) {
        cout << cnt << endl;
        return 0;
      }
      a[i] *= 0.5;
    }
    cnt++;
  }

  return 0;
}

#include <bits/stdc++.h>
using namespace std;

int main() {
  int N,A,s,r=999;
  cin>>N;
  for(int i=0;i<N;i++){
    cin>>A;
    s=0;
    while(A%2==0){
      s++;
      A/=2;
    }
    if(s<r)r=s;
  }
  cout<<r<<endl;
}


#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;

struct Node {
  int key;
  Node *parent, *left, *right;
};

Node* NIL;

int m;
Node* root;

void init() {
  NIL = new Node;
  NIL->parent = NIL;
  NIL->left = NIL;
  NIL->right = NIL;
  root = NIL;
}

void insert(int k) {
  Node* z = new Node {k, NIL, NIL, NIL};
  Node* y = NIL;
  Node* x = root;
  while (x != NIL) {
    y = x;
    if (z->key < x->key) x = x->left;
    else x = x->right;
  }
  z->parent = y;

  if (y == NIL) root = z;
  else if (z->key < y->key) y->left = z;
  else y->right = z;
}

void preParse(Node* u) {
  if (u == NIL) return;
  cout << " " << u->key;
  preParse(u->left);
  preParse(u->right);
}

void inParse(Node* u) {
  if (u == NIL) return;
  inParse(u->left);
  cout << " " << u->key;
  inParse(u->right);
}

Node* find(int k) {
  Node* c = root;
  while (c != NIL) {
    if (c->key == k) return c;
    else if (k < c->key) c = c->left;
    else c = c->right;
  }
  return NIL;
}

Node* getMinimum(Node* x) {
  while (x->left != NIL) x = x->left;
  return x;
}

Node* getSucessor(Node* x) {
  if (x->right != NIL) return getMinimum(x->right);

  Node* y = x->parent;
  while (y != NIL && x == y->right) {
    x = y;
    y = y->parent;
  }
  return y;
}

void deleteNode(Node* z) {
  Node* y;
  if (z->left == NIL | z->right == NIL) y = z;
  else y = getSucessor(z);

  Node* x;
  if (y->left != NIL) x = y->left;
  else x = y->right;

  if (x != NIL) x->parent = y->parent;

  if (y->parent == NIL) {
    root = x;
  } else if (y == y->parent->left) {
    y->parent->left = x;
  } else {
    y->parent->right = x;
  }

  if (y != z) z->key = y->key;
}

int main() {
  cin >> m;
  rep(i, m) {
    string com;
    cin >> com;
    int key;
    if (com == "insert") {
      cin >> key;
      insert(key);
    } else if (com == "print") {
      inParse(root);
      cout << endl;
      preParse(root);
      cout << endl;
    } else if (com == "find") {
      cin >> key;
      if (find(key) != NIL) cout << "yes" << endl;
      else cout << "no" << endl;
    } else if (com == "delete") {
      cin >> key;
      deleteNode(find(key));
    } else {
      cout << "error" << endl;
    }
  }
  return 0;
}

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;

class Dice
{
private:
  int surf[6];
public:
  void set_surf(int* input);
  void roll(char orient);
  void disp_top();
};

void Dice::set_surf(int* input)
{
  memcpy(surf, input, 6*sizeof(int));
}

void Dice::roll(char orient){
  int temp[6];

  switch(orient){
  case 'S':
    temp[0]=surf[4];
    temp[1]=surf[0];
    temp[2]=surf[2];
    temp[3]=surf[3];
    temp[4]=surf[5];
    temp[5]=surf[1];
    break;
  case 'N':
    temp[0]=surf[1];
    temp[1]=surf[5];
    temp[2]=surf[2];
    temp[3]=surf[3];
    temp[4]=surf[0];
    temp[5]=surf[4];
    break;
  case 'W':
    temp[0]=surf[2];
    temp[1]=surf[1];
    temp[2]=surf[5];
    temp[3]=surf[0];
    temp[4]=surf[4];
    temp[5]=surf[3];
    break;
  case 'E':
    temp[0]=surf[3];
    temp[1]=surf[1];
    temp[2]=surf[0];
    temp[3]=surf[5];
    temp[4]=surf[4];
    temp[5]=surf[2];
    break;
  }

  memcpy(surf, temp, 6*sizeof(int));

}

void Dice::disp_top(){
  cout << surf[0] << endl;
}

int main()
{
  int input[6];
  Dice dice;
  string order;

  for(int i=0; i<6; i++){
    cin >> input[i];
  }
  dice.set_surf(input);

  cin >> order;

  for(int i=0; i<order.size(); i++){
    dice.roll(order[i]);
  }

  dice.disp_top();

  return(0);
}


#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
#include <climits>
#include <queue>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < (ll)(n); ++i)
template<class T> inline bool chmax(T& a, T b) { if(a < b){ a=b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if(a > b){ a=b; return 1; } return 0;}

int main(){
	int n;
	string s;
	cin >> n >> s;

	vector<int> w(n+1), e(n+1);
	w[0] = 0;
	e[0] = 0;
	REP(i,n){
		w[i+1] = w[i];
		e[i+1] = e[i];
		if(s[i]=='W') w[i+1]++;
		if(s[n-1-i]=='E') e[i+1]++;
	}

	int ans=1000000;
	REP(i,n){
		chmin(ans, w[i+1]+e[n-i]-1);
	}

	cout << ans << endl;

	return 0;
}

/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int N,X;
LL b[SIZE],l[SIZE],u[SIZE];
bool used[SIZE];
int main(){
    R(N,X);
    LL need=0;
    priority_queue<PLL>h0,h1,h2;
    REP(i,N){
        R(b[i],l[i],u[i]);
        need+=b[i]*l[i];
        h0.push({l[i]*b[i]+u[i]*(X-b[i]),i});
    }
    LL an=0;
    while(need>=h0.top().F){
        an+=X;
        used[h0.top().S]=1;
        need-=h0.top().F;
        h0.pop();
    }
    if(need<=0){
        W(an);
        return 0;
    }
    int add_id=h0.top().S;
    LL add_v=l[add_id]*b[add_id]+u[add_id]*(X-b[add_id]);
    LL mi=1e18;
    REP(i,N){
        if(used[i]){
            LL need2=need-add_v+l[i]*b[i]+u[i]*(X-b[i]);

            if(l[i]*b[i]>=need2){
                mi=min(mi,(need2+l[i]-1)/l[i]);
            }
            else{
                mi=min(mi,(need2-l[i]*b[i]+u[i]-1)/u[i]+b[i]);
            }
        }
        else{
            if(l[i]*b[i]+u[i]*(X-b[i])<need)continue;
            if(l[i]*b[i]>=need){
                mi=min(mi,(need+l[i]-1)/l[i]);
            }
            else{
                mi=min(mi,(need-l[i]*b[i]+u[i]-1)/u[i]+b[i]);
            }
        }
    }
    an+=mi;
    W(an);
    return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define pi pair<int, int>
#define l first
#define r second
#define all(x) x.begin(), x.end()

const int maxn = 5e5 + 1;

using namespace std;

int n;
string s;

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    string s; cin >> s;
    int n = s.size();
    bitset<26> bt;
    if (n < 26) {
        for (int i = 0; i < n; i++)
            bt[s[i] - 'a'] = 1;
        cout << s;
        for (int x = 0; x < 26; x++)
            if (!bt[x]) {
                cout << (char)(x + 'a');
                break;
            }
        return 0;
    }
    for (int i = n - 1; i >= 0; i--) {
        bool fg = 0;
        for (char j = s[i] + 1; j <= 'z'; j++) {
            fg = 1;
            for (int l = 0; l < i; l++) {
                if (s[l] == j) {
                    fg = 0;
                    break;
                }
            }
            if (!fg) continue;
            s[i] = j;
            cout << s.substr(0, i + 1);
            return 0;
        }
    }
    cout << -1;
    return 0;
}

#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<deque>
#include<functional>
#include<iterator>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<utility>
using namespace std;
typedef long long ll;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(n);i>=1;i--)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;
template<class T> inline bool chmin(T& a, T b){if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a=b;return true;}return false;}
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll digsz(ll x){if(x==0) return 1;else{ll ans=0;while(x){x/=10;ans++;}return ans;}}
ll digsum(ll x){ll sum=0;while(x){sum+=x%10;x/=10;}return sum;}
vector<ll> pw2(62,1);vector<ll> pw10(19,1);

int main(){
    {rep1(i,61) pw2[i]=2*pw2[i-1];}
    {rep1(i,18) pw10[i]=10*pw10[i-1];}

    string s; cin>>s;
    vector<ll> X(26,0);
    rep(i,sz(s)){
        X[(ll)(s[i]-'a')]++;
    }

    string t="";
    rrep(i,26){
        t+=('a'+i);
    }
    if(s==t){
        cout<<-1<<endl;
        return 0;
    }

    ll tmp=INF;
    rep(i,26){
        if(X[i]==0){
            tmp=i;
            break;
        }
    }

    //全文字
    if(tmp==INF){
        ll c;
        vector<ll> Y;
        rrep1(i,sz(s)-1){
            Y.pb((ll)(s[i]-'a'));
            if(s[i]>s[i-1]){
                c=i-1;
                break;
            }
        }
        sort(all(Y));
        rep(i,sz(s)){
            if(c==i){
                ll d=(ll)(s[i]-'a');
                cout<<(char)('a'+*(upper_bound(Y.bg,Y.ed,d)));
                return 0;
            }
            else cout<<s[i];
        }
    }
    else{
        cout<<s<<(char)('a'+tmp)<<endl;
    }
}


#include <stdio.h>
const int MAX_V = 1000000;
int prime[MAX_V];
int main() {
  int i, k, v, n, max = 0;
  for(i = 2; i <= MAX_V; i++) {
    prime[i] = 1;
  }
  for(i = 2; i*i <= MAX_V; i++) {
    if(prime[i]){
      for(k = 2 * i; k <= MAX_V; k += i) {
        prime[k] = 0;
      }
    }
  }
  while(1){
    scanf("%d", &n);
    if(n == 0) break;
    for(i = n;i > 0;i--){
      if(prime[i] == 1 && prime[i - 2] == 1){
        max = i;
        break;
      }
    }
  printf("%d %d\n", max - 2, max);
  }
  return 0;
}

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <bitset>
#include <cstring>
#include <string.h>
#include <cmath>
#include <queue>
#include <string>
#include <stack>
#include <utility>
#include <queue>
#include <cmath>
#define mp make_pair
#define pii pair<int,int>
#define ff first
#define ss second
#define ll long long
#define vi vector<int>

using namespace std;

ll _sieve_size;
bitset<10000010> bs;
vi primes;
void sieve(ll upperbound) {
_sieve_size = upperbound + 1;
bs.set();
bs[0] = bs[1] = 0;
for (ll i = 2; i <= _sieve_size; i++) if (bs[i]) {
for (ll j = i * i; j <= _sieve_size; j += i) bs[j] = 0;
primes.push_back((int)i);
} }
bool isPrime(ll N) {
if (N <= _sieve_size) return bs[N];
for (int i = 0; i < (int)primes.size(); i++)
if (N % primes[i] == 0) return false;
return true;
}

int a;

int main()
{
	sieve(11000);
	while(1)
	{
		scanf("%d",&a);
		if(a==0)break;
		if(a%2==0)
		a-=3;
		else
		a-=2;
		//printf("%d",b);
		while(1)
		{
			if(isPrime(a)&&isPrime(a+2))
			{
				printf("%d %d\n",a,a+2);
				break;
			}
			a-=2;
		}
	}
}


#include <iostream>
#include <algorithm>
#include <fstream>
using namespace std;

int N = 0, M = 0;
int points[1001];
int scores[1002001];

bool check(int a, int c){
    if(a >= (N + 2) * (N + 1) / 2 - 1){
        return true;
    }
    return (scores[a] <= c && scores[a + 1] > c);
}

int search2(int a, int b, int c){
    int pib = a + b - b / 2;
    if(check(pib, c)){
        return pib;
    }else if(scores[pib] < c){
        return search2(pib, b / 2, c);
    }else{
        return search2(a, b / 2, c);
    }
}

int main(){
    for(;;){
        for(int i = 0; i < 1001; i++){
            points[i] = 0;
        }
        for(int i = 0; i < 1002001; i++){
            scores[i] = 0;
        }
        if(cin >> N){
            if(N == 0){
                break;
            }
            cin >> M;
            for(int i = 1; i <= N; i++){
                cin >> points[i];
            }
            for(int i = 0; i <= N; i++){
                for(int j = i; j <= N; j++){
                    scores[(2 * N - i + 1) * i / 2 + j] = points[i] + points[j];
                }
            }
            int mxsco = 0;
            sort(scores, scores + ((N + 2) * (N + 1)) / 2);
            for(int i = 0; i < (N + 2) * (N + 1) / 2; i++){
                if(scores[i] > M){
                    break;
                }
                int nosco = scores[i] + scores[search2(0, (N + 2) * (N + 1) / 2, M - scores[i])];
                if(nosco >= mxsco &&  nosco <= M){
                    mxsco = nosco;
                }
            }
            cout << mxsco << endl;
        }else{
            break;
        }
    }
    return 0;
}

#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
int lislis[1003000];
int main(){
    while(1){
        int N,M;
        cin>>N>>M;
        if(N==0&&M==0)break;
        int lis[1002]={0};
        for(int i=1;i<=N;i++)cin>>lis[i];
        for(int i=0;i<1003000;i++)lislis[i]=0;
        for(int i=0;i<=N;i++){
            for(int j=0;j<=N;j++)lislis[i*(N+1)+j]=lis[i]+lis[j];
        }
        sort(lislis,lislis+((N+1)*(N+1)));
        lislis[(N+1)*(N+1)]=lislis[(N+1)*(N+1)-1];
        int maxans=0;
        for(int i=0;i<(N+1)*(N+1);i++){
            int l=0,r=(N+1)*(N+1),mid=(l+r)/2;
            for(int j=0;j<30;j++){
                if(lislis[i]+lislis[mid]<=M)l=mid;
                else r=mid;
                mid=(l+r)/2;
            }
            /*
            printf("[%d] [%d][%d][%d]\n",i,l,mid,r);
            */
            if(lislis[i]+lislis[l]<=M)maxans=max(maxans,lislis[i]+lislis[l]);
        }
        /*
        for(int i=0;i<20;i++)printf("[%d]",lis[i]);
        puts("");
        for(int i=0;i<30;i++)printf("[%d]",lislis[i]);
        puts("");
        */
        cout<<maxans<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
#define L long long
#define vi vector<int>
#define pb push_back
#define pi pair<int,int>
#define pii pair<pi,int>
#define aa first
#define bb second
#define xx aa.aa
#define yy aa.bb
#define zz bb
#define mp make_pair
#define mpp(a,b,c) mp(mp(a,b),c)
using namespace std;
int n,m,p;
L f[600000],g[600000],q,ans;
inline void modify(L f[],int i,int j,int k,int x,L p)
{
	f[i]=min(f[i],p);
	if(j<k)
	  if(x<=(j+k>>1))
	    modify(f,i<<1,j,j+k>>1,x,p);
	  else
	    modify(f,i<<1|1,(j+k>>1)+1,k,x,p);
}
inline L minn(L f[],int i,int j,int k,int l,int r)
{
	if(l<=j && k<=r)
	  return f[i];
	else
	  {
	   L p=1e18;;
	   if(l<=(j+k>>1))
	     p=min(p,minn(f,i<<1,j,j+k>>1,l,r));
	   if(r>(j+k>>1))
	     p=min(p,minn(f,i<<1|1,(j+k>>1)+1,k,l,r));
	   return p;
	  }
}
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int i,j;
	L k;
	scanf("%d%d",&n,&m);
	for(p=1;p<n;p<<=1);
	for(i=1;i<2*p;i++)
	  f[i]=g[i]=1e18;
	scanf("%d%d",&i,&j);
	modify(f,1,1,p,i,-i);
	modify(g,1,1,p,i,i);
	while(m--)
	  {
	   scanf("%d",&i);
	   q+=abs(i-j);
	   ans+=abs(i-j);
	   k=min(minn(f,1,1,p,1,i)+i,minn(g,1,1,p,i,n)-i)-abs(i-j);
	   modify(f,1,1,p,j,k-j);
	   modify(g,1,1,p,j,k+j);
	   ans=min(ans,q+k);
	   j=i;
	  }
	printf("%lld\n",ans);
	return 0;
}

#include <bits/stdc++.h>
using namespace std;

const int N = 200005;
const long long inf = 1e18;

int n, MAX, A, B;
int x[N];
long long sum[N];

struct SegmentTree {
	long long T[N << 2], lz[N << 2];
	void init() {
		for (int i = 1; i < (N << 2); ++i) {
			T[i] = inf;
			lz[i] = 0;
		}
	}

	#define mid ((l + r) >> 1)
	void push(int v, int l, int r) {
		if (lz[v] == 0) return;
		if (l < r) lz[v << 1] += lz[v], lz[v << 1 | 1] += lz[v];
		T[v] += lz[v];
		lz[v] = 0;
		if (T[v] > inf) T[v] = inf;
	}

	void upd_pos(int v, int l, int r, int pos, long long val) {
		push(v, l, r);
		if (l > r || r < pos || l > pos) return;
		if (l == r) { T[v] = val; return; }
		upd_pos(v << 1, l, mid, pos, val); upd_pos(v << 1 | 1, mid + 1, r, pos, val);
		T[v] = min(T[v << 1], T[v << 1 | 1]);
	}
	void upd_seg(int v, int l, int r, int L, int R, int val) {
		push(v, l, r);
		if (l > r || R < l || L > r) return;
		if (L <= l && r <= R) { lz[v] = val; push(v, l, r); return; }
		upd_seg(v << 1, l, mid, L, R, val); upd_seg(v << 1 | 1, mid + 1, r, L, R, val);
		T[v] = min(T[v << 1], T[v << 1 | 1]);
	}

	long long get(int v, int l, int r, int L, int R) {
		push(v, l, r);
		if (l > r || R < l || L > r) return inf;
		if (L <= l && r <= R) return T[v];
		return min(get(v << 1, l, mid, L, R), get(v << 1 | 1, mid + 1, r, L, R));
	}
	#undef mid

	void upd_pos(int pos, long long val) { upd_pos(1, 0, MAX, pos, val); }
	void upd_seg(int l, int r, int val) { upd_seg(1, 0, MAX, l, r, val); }
	long long get(int l, int r) { return get(1, 0, MAX, l, r); }
} seg1, seg2;

long long ans = inf;

void solve() {
	//x[0] = B;
	// first move: A
	seg1.init(); // seg1 for xi >= xj (i > j)
	seg2.init(); // seg2 for xi < xj (i > j)
	seg1.upd_pos(B, abs(x[1] - A) - B);
	seg2.upd_pos(B, abs(x[1] - A) + B);

	for (int i = 2; i <= n; ++i) {
		long long cur = min(seg1.get(0, x[i]) + x[i], seg2.get(x[i], MAX) - x[i]);
		seg1.upd_seg(0, MAX, abs(x[i] - x[i-1]));
		seg2.upd_seg(0, MAX, abs(x[i] - x[i-1]));
		seg1.upd_pos(x[i-1], cur - x[i-1]);
		seg2.upd_pos(x[i-1], cur + x[i-1]);
	}

	for (int i = 1; i <= MAX; ++i) {
		ans = min(ans, seg1.get(i, i) + i);
	}
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> MAX >> n >> A >> B; // initial positions
	for (int i = 1; i <= n; ++i) cin >> x[i];
	solve();
	swap(A,B);
	solve();
	printf("%lld\n", ans);
}


#include <bits/stdc++.h>
using namespace std;

int main(){
   int x;
   cin>>x;
   int ans,count,s;
   ans=x%500;
   count=ans%5;
   s=(x-ans)/500*1000+(ans-count)/5*5;
   cout<<s<<endl;
}

#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	int ans = 180 * (n-2);
	cout << ans << endl;
	return 0;
}


#include <algorithm>
#include <complex>
#include <cstdlib>
#include <ctime>
#include <time.h>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <numeric>
#include <limits>
#include <type_traits>
#include <locale>
#include <omp.h>

using namespace std;
#define SAY_YES cout << "YES" << endl;
#define SAY_Yes cout << "Yes" << endl;
#define SAY_NO cout << "NO" << endl;
#define SAY_No cout << "No" << endl;
#define IFYES(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "YES" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "NO" << endl;  \
    }
#define IFYes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "Yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "No" << endl;  \
    }
#define IFyes(TRUE_OR_FALSE)   \
    if (TRUE_OR_FALSE)         \
    {                          \
        cout << "yes" << endl; \
    }                          \
    else                       \
    {                          \
        cout << "no" << endl;  \
    }
#define DEBUG_OUTPUT_ARRAY(XXX, ONE)                            \
    for (int i = 0; i < (ONE); i++)                             \
    {                                                           \
        cout << "DEBUG: i = " << i << " -> " << XXX[i] << endl; \
    }
#define DEBUG_OUTPUT_ARRAY2(XXX, ONE, TWO)                             \
    for (int i = 0; i < (ONE); i++)                                    \
    {                                                                  \
        cout << "<<< i = " << i << " >>>" << endl;                     \
        for (int j = 0; j < (TWO); j++)                                \
        {                                                              \
            cout << "DEBUG: j = " << j << " -> " << XXX[i][j] << endl; \
        }                                                              \
    }
#define DEBUG_OUTPUT_ARRAY2_BOX(XXX, ONE, TWO) \
    for (int i = 0; i < (ONE); i++)            \
    {                                          \
        cout << i << "  ";                     \
        for (int j = 0; j < (TWO); j++)        \
        {                                      \
            cout << XXX[i][j] << " ";          \
        }                                      \
        cout << endl;                          \
    }

typedef pair<long long int, long long int> pll;
typedef pair<long long int, pll> lpll;

const long long int mod = 1000000007;
const long long int INF = 1e18;
const long double PI=3.14159265358979323;
//const long long int pl=1000000;

long long int N,a[200200],sum=0;
int main(){

    cout << fixed << setprecision(18);
    cin>>N;
    for(long long int i = 0; i < N; i++){
        cin>>a[i];
        sum+=a[i];
        a[i]*=N;
    }
    long long int x=INF;
    for(long long int i = 0; i < N; i++){
        x=min(x,abs(a[i]-sum));
    }
    for(long long int i = 0; i < N; i++){
        if(x==abs(a[i]-sum)){cout<<i<<endl;return 0;}
    }
}

#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int n, k, ans;
int a[maxn];
bool sec[maxn];
vector<int> E[maxn];
int dfs(int x)
{
	int ret = 0;
	for(auto v : E[x])
		ret = max(ret, dfs(v));
	++ret;
	if(ret == k && !sec[x]) ++ans, ret = 0;
	return ret;
}
int main()
{
	scanf("%d%d", &n, &k);
	for(int i = 1; i <= n; ++i) scanf("%d", &a[i]);
	ans += (a[1] != 1);
	for(int i = 2; i <= n; ++i) E[a[i]].push_back(i);
	sec[1] = 1;
	for(auto v : E[1]) sec[v] = 1;
	dfs(1);
	printf("%d\n", ans);
	return 0;
}


#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

void dfs(vector<vector<int>> &tree, vector<int> &d, int p){
  for(auto i : tree.at(p)){
    if(d.at(i) != -1) continue;
    d.at(i) = d.at(p) + 1;
    dfs(tree, d, i);
  }
}

int main(){
  int n, ta, ao;
  cin >> n >> ta >> ao;
  ta--; ao--;
  vector<vector<int>> tree(n, vector<int>());
  rep(i, n-1){
    int a, b;
    cin >> a >> b;
    a--; b--;
    tree.at(a).push_back(b);
    tree.at(b).push_back(a);
  }

  vector<int> dta(n, -1), dao(n, -1);
  dta.at(ta) = 0; dao.at(ao) = 0;
  dfs(tree, dta, ta);
  dfs(tree, dao, ao);
  // rep(i, n){
  //   cerr << dta.at(i) << " ";
  // }
  // cerr << endl;
  // rep(i, n){
  //   cerr << dao.at(i) << " ";
  // }
  // cerr << endl;

  int ans = 0;
  rep(i, n){
    if(dao.at(i) > dta.at(i)){
      ans = max(ans, dao.at(i)-1);
    }
  }
  cout << ans << endl;

  return 0;
}

#include <bits/stdc++.h>
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define nyan "(=^･ω･^=)"
#define mkp make_pair
#define lP pair<ll, ll>
#define iP pair<int,int>
typedef long long ll;
using namespace std;

int N, M, K, A, B, C, D[100000], vis[100000];
map<int, vector<pair<int,bool>>>v[100000];
queue<int>q;

void dfs(int x, int a, int t) {
	vector<pair<int,bool>>&V = v[x][a];
	for (int i = 0; i < V.size(); ++i) {
		if (!V[i].second) {
			V[i].second = true;
			if (D[V[i].first] == t + 1 && vis[V[i].first] != a) {
				vis[V[i].first] = a;
				dfs(V[i].first, a, t);
			}
			if (D[V[i].first] == -1) {
				D[V[i].first] = t + 1;
				q.push(V[i].first);
				dfs(V[i].first, a, t);
			}
		}
	}
}

int main() {
	cin >> N >> M;
	while (M--) {
		cin >> A >> B >> C;
		--A;
		--B;
		v[A][C].push_back(mkp(B, false));
		v[B][C].push_back(mkp(A, false));
	}
	memset(D, -1, sizeof D);
	D[0] = 0;
	q.push(0);
	while (!q.empty()) {
		int x = q.front();
		q.pop();
		for (auto it = v[x].begin(); it != v[x].end(); ++it) {
			dfs(x, it->first, D[x]);
		}
	}
	cout << D[N - 1] << endl;
}


#include<iostream>
using namespace std;
const int BUF = 2000005;
const int MOD = 1000000007;

int add(int a, int b) {
    return (a + b) % MOD;
}

int sub(int a, int b) {
    return (a - b + MOD) % MOD;
}

int mul(int a, int b) {
    return 1LL * a * b % MOD;
}

int nNum;
int a[BUF], b[BUF];

void read() {
    cin >> nNum;
    for (int i = 0; i < nNum; ++i) cin >> a[i];
    for (int i = 0; i < nNum; ++i) cin >> b[i];
}

void work() {
    static int s[BUF];
    static int t[BUF];
    for (int i = 0; i < nNum; ++i) {
        s[i] = a[i] ^ a[(i + 1) % nNum];
        t[i] = b[i] ^ b[(i + 1) % nNum];
    }

    const int P = 1<<30;

    int sHash = 0;
    int tHash = 0;
    for (int i = 0; i < nNum; ++i) {
        sHash = add(mul(sHash, P), s[i]);
        tHash = add(mul(tHash, P), t[i]);
    }

    int pPowNNum = 1;
    for (int i = 0; i < nNum - 1; ++i) {
        pPowNNum = mul(pPowNNum, P);
    }

    for (int shift = 0; shift < nNum; ++shift) {
        if (sHash == tHash) {
            cout << shift << ' ' << (a[shift] ^ b[0]) << endl;
        }
        sHash = sub(sHash, mul(s[shift], pPowNNum));
        sHash = mul(sHash, P);
        sHash = add(sHash, s[shift]);
    }
}

int main() {
    read();
    work();
    return 0;
}

#include <bits/stdc++.h>
using namespace std;

int main() {
  long N;
  cin >> N;
  vector<long> A(N);
  for (long i = 0; i < N; i++) cin >> A.at(i);
  sort(A.rbegin(), A.rend());

  long a = 0, b = 0;
  for (long i = 0; i + 1 < N; i++) {
    if (A.at(i) == A.at(i + 1)) {
      if (!a) a = A.at(i++);

      else b = A.at(i++);

      if (b) break;
    }
  }
  cout << a * b << "\n";
}


#include<iostream>
#include<algorithm>
using namespace std;

int main()
{
  int n;
  for(;cin>>n;)
    {
      int data[n];
      int dmax=0;
      for(int i=0;i<n;i++)
	{
	  cin>>data[i];
	  dmax=max(dmax,data[i]);
	}
      for(int i=1;i<=dmax/2;i++)
	{
	  bool flag=true;
	  for(int j=0;j<n;j++)
	    {
	      if(data[j]%i!=0)
		{
		  flag=false;
		  break;
		}
	    }
	  if(flag)
	    cout<<i<<endl;
	}
    }
}

#include <iostream>
using namespace std;

bool isMatch(int x) {
  if (x % 3 == 0) return true;

  do {
    if (x % 10 == 3) return true;
  } while (x /= 10);

  return false;
}

int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    if (isMatch(i)) cout << ' ' << i;
  }
  cout << endl;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using vst=vector<string>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };

map<ll,int> prf(ll n){
  map<ll,int> ret;
  for(ll i=2;i*i<=n;i++){
    while(n%i==0){
     ret[i]++;
      n/=i;
    }
  }
  if(n!=1){
    ret[n]=1;
  }
  return ret;
}

int main(){cout<<fixed<<setprecision(10);
		   int n,h,w;
           cin>>n>>h>>w;
           n++;
           cout<<(n-w)*(n-h)<<endl;
}

#include "bits/stdc++.h"
#define int long long
#define endl '\n'
using namespace std;

typedef long long ll;
#define db(x) cerr << #x << ": " << x << '\n';
#define read(a) int a; cin >> a;
#define readb(a, b) int a, b; cin >> a >> b;
#define readc(a, b, c) int a, b, c; cin >> a >> b >> c;
#define readarr(a, n) int a[(n) + 1] = {}; FOR(i, 1, (n)) {cin >> a[i];}
#define readmat(a, n, m) int a[n + 1][m + 1] = {}; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];}

#define print(a) cout << a << endl;
#define printarr(a, n) FOR (i, 1, n) cout << a[i] << " "; cout << endl;
#define printv(v) for (int i: v) cout << i << " "; cout << endl;
#define printmat(a, n, m) FOR (i, 1, n) {FOR (j, 1, m) cout << a[i][j] << " "; cout << endl;} cout << endl;
#define all(v) v.begin(), v.end()
#define sz(v) (int)(v.size())
#define rz(v, n) v.resize((n) + 1);
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define vpi vector <pi>
#define vvi vector <vi>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const ll N = 2e5 + 1;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	readc(n, h, w);
	int cnt = 0;
	FOR (i, 1, n)
	    FOR (j, 1, n)
	        if (i + h - 1 <= n && j + w - 1 <= n) cnt++;

	        print(cnt);
}


#include <bits/stdc++.h>
#include <vector>
#include <queue>
using namespace std;

int main(){
    int N, M;
    cin >> N >> M;

    vector<bool> IsCorrect(N, false);
    vector<int> Penalties(N, 0);

    for(int i=0; i<M; i++){
        int p;
        string s;
        cin >> p >> s;

        p=p-1;
        if(s=="AC"){
           IsCorrect[p] = true;
        }

        if(s=="WA" && IsCorrect[p]==false){
            Penalties[p] += 1;
        }

    }

    int c_ans = 0;
    int c_pena = 0;
    for(int i=0; i<N; i++){
        if(IsCorrect[i]== true){
            c_ans++;
            c_pena += Penalties[i];
        }
    }
    cout << c_ans << " " << c_pena << endl;
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

const int N = 1e6 + 10;

inline int read(){
    register int x=0,f=1;register char ch=getchar();
    while(ch<'0'||ch>'9')f=ch=='-'?-1:f,ch=getchar();
    while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
    return x*f;
}
int last[N], root[N];
struct seg{
	int l, r;
	int val;
}tr[N * 30];
int tot;

void build(int &rt, int l, int r)
{
	rt = ++tot;
	tr[rt].val = 0;
	if(l == r) return ;
	int mid =l + r >> 1;
	build(tr[rt].l, l, mid), build(tr[rt].r, mid + 1, r);
}

void update(int &p, int q, int x, int c, int l, int r)
{
	p = ++ tot;
	tr[p] = tr[q];
	tr[p].val += c;
	if(l == r) return ;
	int mid = l + r >> 1;
	if(x <= mid) update(tr[p].l, tr[q].l, x,c, l, mid);
	else update(tr[p].r, tr[q].r, x, c,mid + 1, r);
}

int query(int p, int q, int L, int R, int l, int r)
{
	if(L <= l && R >= r)
	return tr[q].val - tr[p].val;
	int mid = l + r >> 1;
	int res = 0;
	if(L <= mid) res += query(tr[p].l, tr[q].l, L, R, l, mid);
	if(R >  mid) res += query(tr[p].r, tr[q].r, L, R, mid + 1, r);
	return res;
}

int main()
{
	int n, m;
	n = read(); m = read();
	build(root[0], 0, n);
	for (int i = 1; i <= n; i ++)
	{
		int x;
		x = read();
		update(root[i], root[i - 1], last[x], 1, 0, n);
		last[x] = i;
	}
	while(m --)
	{
		int x, y;
		x = read(), y = read();
		printf("%d\n", query(root[x - 1], root[y], 0, x - 1, 0, n));
	}
}


#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
using namespace std;

struct Node{
	int key;
	Node *parent, *left, *right;
};

Node *root, *NIL;

void insert(int k){
	Node *y = NIL;
	Node *x = root;
	Node *z;

	z = (Node *)malloc(sizeof(Node));
	z->key = k;
	z->left = NIL;
	z->right = NIL;

	while(x != NIL){
		y = x;
		if(z->key < x->key){
			x = x->left;
		} else {
			x = x->right;
		}
	}
	z->parent = y;
	if( y == NIL){
		root = z;
	} else {
		if(z->key < y->key){
			y->left = z;
		} else {
			y->right = z;
		}
	}
}

bool find(int k, Node *u){
	if(u == NIL) return false;
	if(u->key == k) return true;
	return (u->key > k)?find(k,u->left):find(k,u->right);
}

Node * treeMinimum(Node *x){
	while(x->left != NIL) x = x->left;
	return x;
}

Node * _find(Node *u, int k){
	while(u != NIL && k != u->key){
		if(k < u->key) u = u ->left;
		else u = u->right;
	}
	return u;
}

Node * treeSuccessor(Node * x){
	if(x->right != NIL) return treeMinimum(x->right);
	Node  *y = x->parent;
	while(y != NIL && x == y->right){
		x = y;
		y = y->parent;
	}
	return y;
}
void treeDelete(Node *z){
	Node *y;
	Node *x;

	if(z->left == NIL  || z->right == NIL) y = z;
	else y = treeSuccessor(z);

	if(y->left != NIL){
		x = y->left;
	} else {
		x = y->right;
	}

	if(x != NIL){
		x->parent = y->parent;
	}

	if(y->parent == NIL){
		root = x;
	} else {
		if(y == y->parent->left){
			y->parent->left = x;
		} else {
			y->parent->right = x;
		}
	}

	if(y != z){
		z->key = y->key;
	}

	free(y);
}

void inorder(Node *u){
	if( u == NIL) return;
	inorder(u->left);
	printf(" %d", u->key);
	inorder(u->right);
}

void preoder(Node *u){
	if( u == NIL) return;
	printf(" %d", u->key);
	preoder(u->left);
	preoder(u->right);
}

int main(){
	int n;
	string s;

	cin>>n;
	scanf("%d", &n);

	for(int i = 0; i < n; i++){
		// scanf("%s", s);
		cin>>s;
		if(s == "print"){
			inorder(root);
			printf("\n");
			preoder(root);
			printf("\n");
		} else if(s == "insert"){
			int x;
			scanf("%d", &x);
			insert(x);
		} else if(s == "find"){
			int k;
			scanf("%d", &k);
			printf(("%s",find(k,root)?"yes":"no"));
			printf("\n");
		} else if(s == "delete"){
			int k;
			scanf("%d", &k);
			treeDelete(_find(root,k));
		}
	}

	return 0;
}

#include "stdio.h"
#include"queue"
#include "climits"
using namespace std;

queue<int>Q;

int island;
int query;
int kind;
int start;
int goal;
int connect[101][101] = {};
int price;
int dis[101] = {};

int main() {
	scanf("%d %d", &island, &query);
	while (island != 0) {
		for (int i = 0; i < 101; i++) {
			for (int j = 0; j < 101; j++) {
				connect[i][j] = INT_MAX;
			}
		}
		for (int i = 0; i < query; i++) {
			scanf("%d", &kind);
			if (kind == 1) {
				scanf("%d %d %d", &start, &goal, &price);
				if (connect[start][goal] > price) {
					connect[start][goal] = price;
					connect[goal][start] = price;
				}
			}
			else {
				scanf("%d %d", &start, &goal);
				Q.push(start);
				for (int i = 1; i < 101; i++) {
					dis[i] = INT_MAX;
				}
				dis[start] = 0;
				while (!Q.empty()) {
					for (int i = 1; i <= island; i++) {
						if (connect[Q.front()][i] != INT_MAX) {
							if (dis[i] > dis[Q.front()] + connect[Q.front()][i]) {
								dis[i] = dis[Q.front()] + connect[Q.front()][i];
								Q.push(i);
							}
						}
					}
					Q.pop();
				}
				if (dis[goal] == INT_MAX)printf("-1\n");
				else printf("%d\n", dis[goal]);
			}
		}
		scanf("%d %d", &island, &query);
	}
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int main(){
  int H, W, N; cin >> H >> W >> N;
  if (H < W) swap(H, W);
  int ans = N / H;
  if (N % H != 0) ans++;
  cout << ans << endl;

  return 0;
}

#include <bits/stdc++.h>

using namespace std;

#ifdef KACTL
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define sz(x) (int)(x).size()
#endif
#define all(x) begin(x), end(x)

using ll = int64_t;
using ld = long double;
using pii = pair<int32_t, int32_t>;
using vi = vector<int32_t>;

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    int h, w, a, b;
    cin >> h >> w >> a >> b;

    /* h = w, a = b
     * do the jagged thing
     *
     * XX.
     * .XX
     * X.X
     *
     * XX..
     * .XX.
     * ..XX
     * X..X
     *
     *
     * some can be 1s and some can be zeros
     * 2 4 1 1
     *
     * 3 3 1 1
     */

    vector<string> res(h, string(w, '0'));
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            res[i][j] ^= (i < b) ^ (j < a);
        }
    }

    for (auto& row : res)
        cout << row << '\n';

    return 0;
}


#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const ll INF=1e18;

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int n,m;
    cin>>n>>m;
    set<int> st;
    for(int i=1;i<n;i++){
        st.insert(i);
    }
    int k=1;
    int pr=-1;
    set<int> check;
    while(k<=m){
        int v=*rbegin(st);
        st.erase(v);
        while(pr-v==1||check.count(n-v)||2*v==n){
            v=*rbegin(st);
            st.erase(v);
        }
        pr=v;
        check.insert(v);
        printf("%d %d\n",k,k+v);
        k++;
    }
}

#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;

#define all(a) (a).begin(), (a).end()

int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, m; cin>>n>>m;

    int head = 2, tail = n;
    vector<P> ans;
    if(n % 2 == 1){
        for(int i=0; i<m; i++){
            ans.emplace_back(head, tail);
            head++, tail--;
        }
    }
    else{
        set<int> length;
        for(int i=0; i<m; i++){
            int over = (n - tail) + head, under = tail - head;
            if(over == under || length.count(over) || length.count(under)) tail--;

            ans.emplace_back(head, tail);
            length.emplace(over);
            length.emplace(under);
            head++, tail--;
        }
    }

    for(auto i : ans) cout << i.first << " " << i.second << endl;

    return 0;
}


#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<tuple>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
#define mp(a1,a2) make_pair(a1,a2)
#define YMAX 250001
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
bool arr[10001];
int Nmax=10001;
vint sosu;
void Eratosthenes(){
	for(int i = 0; i < Nmax; i++){
		arr[i] = true;
	}
	arr[0]=false; arr[1]=false;
	for(int i = 2; i < sqrt(Nmax); i++){
		if(arr[i]){
			for(int j = 0; i * (j + 2) < Nmax; j++){
				arr[i *(j + 2)] = false;
			}
		}
	}
	rep1(i,Nmax){
		if(arr[i]) sosu.push_back(i);
	}
}
ll gcd(ll x,ll y){
	if(y==0) return x;
	return gcd(y,x%y);
}
ll lcm(ll x,ll y){
	return x/gcd(x,y)*y;
}
int main(){
	Eratosthenes();
	int N;
	ll a[502][502];
	ll ichimatsu1[501][501],ichimatsu2[501][501];
	scan(N);
	int NMAX=500;
	int sosucount=0;
	for(int kyori=0;kyori<=NMAX*2-2;kyori+=2){
		for(int j=0;j<=NMAX-1;j++){
			int i=kyori-j;
			if(i<0||i>NMAX-1) continue;
			//printf("kyori:%d i:%d j:%d sosu:%d\n",kyori,i,j,sosu[sosucount]);
			ichimatsu1[i][j]=sosu[sosucount];
		}
		sosucount++;
	}
	for(int kyori=NMAX-1;kyori<=NMAX*2-2&&kyori>=0;kyori+=(kyori<=NMAX-1 ? 2*(NMAX-1-kyori)+2 : 2*(NMAX-1-kyori))){
		for(int j=NMAX-1;j>=0;j--){
			int i=j-kyori+NMAX-1;
			if(i<0||i>NMAX-1) continue;
			ichimatsu2[i][j]=sosu[sosucount];
		}
		sosucount++;
	}
	/*rep(i,N){
		rep(j,N){
			if((i+j)%2==0) printf("%lld ",ichimatsu1[i][j]);
			else printf("-- ");
		}
		kaigyo;
	}
	kaigyo;
	rep(i,N){
		rep(j,N){
			if((i+j)%2==0) printf("%lld ",ichimatsu2[i][j]);
			else printf("-- ");
		}
		kaigyo;
	}*/
	rep(i,NMAX){
		rep(j,NMAX){
			if((i+j)%2==0) a[i+1][j+1]=ichimatsu1[i][j]*ichimatsu2[i][j];
		}
	}
	rep(i,NMAX+2){
		a[i][0]=1;
		a[i][NMAX+1]=1;
	}
	rep(j,NMAX+2){
		a[0][j]=1;
		a[NMAX+1][j]=1;
	}
	rep(i,NMAX){
		rep(j,NMAX){
			if((i+j)%2==1) a[i+1][j+1]=lcm(lcm(a[i][j+1],a[i+2][j+1]),lcm(a[i+1][j],a[i+1][j+2]))+1;
		}
	}
	rep1(i,N){
		rep1(j,N){
			printf("%lld ",a[i][j]);
		}
		kaigyo;
	}
	return 0;
}

#include <iostream>
#include <fstream>
#include <vector>
using namespace std;

#define NMAX 502
#define DIM 7920

int d[DIM], p[DIM];
long long sol[NMAX][NMAX];

void ciur(int n) {
    for (int i = 2; i <= n; i++) {
        if (d[i] == 0) {
            p[++p[0]] = i;
            for (int j = i + i; j <= n; j += i) {
                d[j] = 1;
            }
        }
    }
}

__int128 gcd(__int128 a, __int128 b) {
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

__int128 lcm(vector <long long>& v) {
    __int128 l = 1;
    for (const long long x : v) {
        if (x == 0)
            continue;
        __int128 d = gcd(l, (__int128)x);
        l = l * x / d;

    }
    return (long long)l;
}

int main()
{
    ios::sync_with_stdio(false);

    int n;
    cin >> n;

    if (n == 2) {
        cout << "4 7\n23 10\n";
        return 0;
    }
    ciur(DIM - 1);

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            sol[i][j] = 1;
        }
    }

    int cnt = 1;
    for (int j = 1; j <= n; j += 2) {
        int col = j;
        for (int i = 1; i <= n; i++) {
            if (col > n)
                break;
            sol[i][col] *= p[cnt];
            col++;
        }
        cnt++;
    }

    for (int i = 3; i <= n; i += 2) {
        int lin = i;
        for (int j = 1; j <= n; j++) {
            if (lin > n)
                break;
            sol[lin][j] *= p[cnt];
            lin++;
        }
        cnt++;
    }

    for (int j = 1; j <= n; j += 2) {
        int col = j;
        for (int i = 1; i <= n; i++) {
            if (col <= 0)
                break;
            sol[i][col] *= p[cnt];
            col--;
        }
        cnt++;
    }

    for (int i = n; i > 1; i -= 2) {
        int lin = i;
        for (int j = n; j >= 1; j--) {
            if (lin > n)
                break;
            sol[lin][j] *= p[cnt];
            lin++;
        }
        cnt++;
    }

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            if ((i + j) % 2 == 0)
                continue;
            vector <long long> v = {sol[i - 1][j], sol[i + 1][j], sol[i][j - 1], sol[i][j + 1]};
            sol[i][j] = lcm(v) + 1;
        }
    }

    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            cout << sol[i][j] << " ";
        }
        cout << '\n';
    }
    return 0;
}


#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1001001001LL;
constexpr long long LINF = 1001001001001001001;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
  int n; cin >> n;
  vector<ll> A(n);
  ll sum = 0;
  rep(i, n){
    cin >> A[i];
    sum += A[i];
  }
  double avg = sum / (double)n;
  double sa = LINF, res = -1;
  rep(i, n){
    if(sa > abs(avg - A[i])){
      sa = abs(avg - A[i]);
      res = i;
    }
  }
  cout << res << ln;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    long int n,tem;
    cin>>n;
    vector<long int>p;
    for(long int i=0;i<n;i++)
    {
        cin>>tem;
        p.push_back(tem);
    }
    long int c=1,mini=p[0];
     for(long int i=1;i<n;i++)
    {
       if(mini>=p[i])
       {
           c++;
           mini=p[i];
       }
    }
    cout<<c<<"\n";
return 0;}


#include <bits/stdc++.h> // {{{

#define ARG4(_1, _2, _3, _4, ...) _4
#define rep(...) ARG4(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define REP(i, a) FOR(i, 0, a)
#define FOR(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define rrep(...) ARG4(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define RREP(i, a) RFOR(i, 0, a)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (int)(a); --i)
#define ALL(c) (c).begin(), (c).end()
#define TEN(n) ((ll)(1e##n))
#define pb emplace_back
#define mp make_pair
#define fi first
#define se second
#define let const auto
#define USE_T template <typename T>
#define USE_Ti template <typename T = int>
#define USE_TU template <typename T, typename U>

USE_Ti using duo = std::pair<T, T>;
USE_Ti using vec = std::vector<T>;
using ll = long long;
// clang-format off
USE_TU inline bool chmax(T&x,U a){return x<a&&(x=a,1);}
USE_TU inline bool chmin(T&x,U a){return a<x&&(x=a,1);}
USE_Ti inline T in(){T x;std::cin>>x;return x;}
USE_Ti inline vec<T> in(int n){vec<T> v;v.reserve(n);rep(i,n)v.pb(in<T>());return v;}
USE_T inline void in(T*x,int n){rep(i,n)x[i]=in<T>();}
struct IoSetup {
  IoSetup(){
    using namespace std;
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<setprecision(10);
    cerr<<setprecision(10);
  }
} iosetup;
// clang-format on
// }}}
using namespace std;
const int inf = 1001001001;
const ll infll = 1001001001001001001ll;
const int dd[] = {0, 1, 0, -1, 0};

signed main() {
  auto S = in(6);
  int tot = std::accumulate(ALL(S), 0);
  tot -= *min_element(ALL(S) - 2);
  tot -= *min_element(4 + ALL(S));
  cout << tot << endl;
  return 0;
}

/* template.cpp [[[ */
#include <bits/stdc++.h>
using namespace std;
#define get_macro(a, b, c, d, name, ...) name
#define rep(...) get_macro(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep(...) get_macro(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define rep1(n) rep2(i_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, b) rep4(i, a, b, 1)
#define rep4(i, a, b, s) for (ll i = (a); i < (ll)(b); i += (ll)s)
#define rrep1(n) rrep2(i_, n)
#define rrep2(i, n) rrep3(i, 0, n)
#define rrep3(i, a, b) rrep4(i, a, b, 1)
#define rrep4(i, a, b, s) for (ll i = (ll)(b) - 1; i >= (ll)(a); i -= (ll)s)
#define each(x, c) for (auto &&x : c)
#define fs first
#define sc second
#define all(c) begin(c), end(c)
using ui = unsigned;
using ll = long long;
using ul = unsigned long long;
using ld = long double;
const int INF = 1e9 + 10;
const ll INF_LL = 1e18 + 10;
const int dx[]{-1, 0, 1, 0, -1, 1, 1, -1};
const int dy[]{0, -1, 0, 1, -1, -1, 1, 1};
template<class T, class U> void chmin(T &x, const U &y){ x = min<T>(x, y); }
template<class T, class U> void chmax(T &x, const U &y){ x = max<T>(x, y); }
/* ]]] */

int main(){
  int a, b, c, d, e, f;
  cin >> a >> b >> c >> d >> e >> f;
  cout << a + b + c + d - min({a, b, c, d}) + max(e, f) << endl;
}


#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
inline void read(int &x) {
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int N = 1060000,mo=998244353,inv2=(mo+1)/2;
int n,m,fac[N],ifac[N];
int power(int a, int n){
	int res=1;
	while(n){
		if(n&1)res=1LL*res*a%mo;a=1LL*a*a%mo;n>>=1;
	}
	return res;
}
int C(int n, int m){return m>=0&&m<=n?1LL*fac[n]*ifac[m]%mo*ifac[n-m]%mo:0;}
int main() {
	read(n);read(m);if(n>m)swap(n,m);
	int mx=N-1;fac[0]=1;rep(i,1,mx)fac[i]=1LL*fac[i-1]*i%mo;
	ifac[mx]=power(fac[mx],mo-2);per(i,mx-1,0)ifac[i]=1LL*ifac[i+1]*(i+1)%mo;
	ll res=m;int ni=power(C(n+m,n),mo-2);
	rep(i,0,n-1)res=(res+1LL*inv2*C(n-i+n-i,n-i)%mo*C(i+i+m-n,i)%mo*ni)%mo;cout<<res;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = (0); i < (n); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define DEBUG(val) cout << #val << " : " << val << endl
#define MOD 1000000007

int main() {
  string str;
  cin >> str;
  int s = 0;
  int t = 0;
  int remove_count = 0;
  REP(i, str.length()) {
    if (str[i] == 'S') {
      s++;
    } else {
      if (s > 0) {
        s--;
        remove_count += 2;
      }
    }
  }
  cout << str.length() - remove_count << endl;
}

# include <iostream>
# include <deque>
using namespace std;

string X;
deque<char> dchar;

int main()
{
    cin>>X;

    for (int i=0; i<X.size(); i++)
    {
        dchar.push_back(X[i]);

        if (dchar.size()>=2 && dchar[dchar.size()-2]=='S' && dchar[dchar.size()-1]=='T')
        {
            dchar.pop_back();
            dchar.pop_back();
        }
    }

    cout<<dchar.size()<<endl;
}


#include <iostream>
#include <vector>
#include <algorithm>

int main(void){
    int N, x, ans=0;
    std::cin >> N >> x;
    std::vector<int> a(N);
    for (int i=0; i<N; ++i){
        std::cin >> a.at(i);
    }

    std::sort(a.begin(), a.end());

    for (int i: a) {
        x -= i;
        if (x < 0){
            break;
        } else {
            ++ans;
        }
    }

    if (x > 0 && ans > 0) {
        --ans;
    }

    std::cout << ans << std::endl;

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using pii=pair<ll,ll>;
#define For(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define sz(x) ((ll)x.size())
#define MOD (ll)(998244353)
#define INF (9e18)
#define EPS (1e-6)
#ifdef LOCAL_TEST
#define debug(...) do{\
	cerr<<__PRETTY_FUNCTION__<<" - "<<__LINE__<<\
	" : ("#__VA_ARGS__<<") = ";\
	_OUT(__VA_ARGS__);\
}while(0)
template<typename T>void _OUT(T x){cerr<<x<<endl;}
template<typename T,typename...I>void _OUT(T x,I ...tail){cerr<<x<<", ";_OUT(tail...);}
#else
#define debug(...)
#endif

void INIT(){
#ifdef LOCAL_TEST
	freopen("D:\\input.in","r",stdin);
	freopen("D:\\output.out","w",stdout);
	freopen("D:\\error.out","w",stderr);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0);
}

ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }
ll lcm(ll a,ll b) { return a/gcd(a,b)*b; }
ll fpow(ll b,ll p){
	b%=MOD;
	ll ans=1;
	while(p>0){
		if(p&1) ans=(ans*b)%MOD;
		p/=2;
		b=(b*b)%MOD;
	}
	return ans;
}

int32_t main() {
	INIT();
	//code...
	int n; cin>>n;
	vector<int> cnt(n,0);
	int t; cin>>t;
	if(t!=0){
		cout<<"0\n";
		return 0;
	}
	cnt[0]++;
	For(i,1,n-1){
		cin>>t;
		if(t==0){
			cout<<"0\n";
			return 0;
		}
		cnt[t]++;
	}
	int now=1;
	ll ans=1;
	For(i,1,n-1){
		if(cnt[i]==0 && now!=n){
			cout<<"0\n";
			return 0;
		}
		ans=(ans*fpow(cnt[i-1],cnt[i]))%MOD;
		now+=cnt[i];
	}
	cout<<ans<<"\n";
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define db long double
#define pb push_back
#define ppb pop_back
#define F first
#define S second
#define mp make_pair
#define all(x) (x).begin(), (x).end()

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

const int N = 1e5 + 123;
int n;
ll a[N];
vector <ll> basis;

void add(ll x) {
	for (ll i : basis) {
		x = min(x, x ^ i);
	}
	if (x > 0) {
		basis.pb(x);
	}
}

int f(ll x) {
	for (int i = 59; i >= 0; i--) {
		if (x >> i & 1) {
			return i;
		}
	}
	return -1;
}

int main() {
	ios_base::sync_with_stdio(false), cin.tie(NULL);
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
	#endif

	cin >> n;
	ll t = 0;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		t ^= a[i];
	}
	ll ans = t, rt = t ^ ((1ll << 60) - 1);
	for (int i = 1; i <= n; i++) {
		a[i] &= rt;
		add(a[i]);
	}
	sort(all(basis));
	reverse(all(basis));
	ll res = 0;
	for (ll i : basis) {
		if (res >> f(i) & 1) {
			continue;
		}
		res ^= i;
	}
	ans += 2 * res;
	cout << ans;
}

//hail to jwalaji
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define mod 1000000007
int main(){
    //ios::sync_with_stdio(false);
    //cin.tie(NULL);
//lli t;
//cin>>t;
//while(t--){
    lli n;
    cin>>n;
    vector<lli> arr(n),store(n);
    for(lli i=0;i<n;i++){
        cin>>arr[i];
    }
    store[0]=arr[0]%mod;
    for(lli i=1;i<n;i++){
        store[i]=(arr[i]+store[i-1])%mod;
    }
    lli ans=0;
    for(lli i=1;i<n;i++){
        ans=(ans+store[i-1]*arr[i])%mod;
    }
    cout<<ans<<endl;
//}
return 0;
}


#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

long long MOD = 10000000000 + 7;

int main(){
  cout << setprecision(10);
  ll N; cin >> N;

  ll ans = 0;
  for(ll i = 1; i <= N; i++){
    if( i%3 == 0 || i%5 == 0){

    } else {
      ans += i;
    }
  }
  cout << ans << endl;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
const ll mod = 1000000007;
const ll INF = 1e+14;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define _GLIBCXX_DEBUG

int main(){
    ll N;
    cin>>N;
    vector<ll> ex(N+10, 0);
    if(N!=1){
    for (ll i=2; i<N+1; i++){
        ll onway=i; //途中の数
        for(ll a=2; a*a<=onway; a++){
            if(onway%a!=0)continue;
            while(onway%a==0){
                ex[a]++;
                onway/=a;
            }
        }
        if(onway!=1) ex[onway]++;
    }
    }
    if(N==1) cout<<1<<endl;
    else {
        ll count=1;
        for(ll i=2; i<=N; i++){
            if(ex[i]==0)continue;
            count*=ex[i]+1;
            count%=mod;
        }
        cout<<count<<endl;
    }

}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0);

	int n;
	cin >> n;
	ll a, b;
	vector<pair<ll, ll>> v;
	for (int i = 0; i < n; ++i)
	{
		cin >> a >> b;
		v.push_back({a, b});
	}

	vector<vector<ll>> dp(n, vector<ll>(n, -1));
	function<ll(int, int)> f = [&](int i, int j)
	{
		if (i == j)
			return 0LL;

		if (dp[i][j] != -1)
			return dp[i][j];

		ll r = 1LL<<62;
		for (int k = i; k < j; ++k)
			r = min(r, f(i, k)+f(k+1, j)+v[i].first*v[j].second*v[k].second);

		return dp[i][j]=r;
	};

	cout << f(0, n-1) << "\n";

	return 0;
}

#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>

using vvi = std::vector<std::vector<int>>;

void solve()
{
    using namespace std;

    constexpr int inf = (1 << 23);

    int n;
    cin >> n;

    vector<int> d(n + 1);

    for (int i = 0; i < n; ++i)
    {
        cin >> d[i];
        if(i + 1 != n)
            cin.ignore(numeric_limits<streamsize>::max(), ' ');
    }

    cin.ignore(numeric_limits<streamsize>::max(), ' ');
    cin >> d[n];

    vvi dp (n, vector<int>(n, 0));

    //自分自身との積は乗算が発生しない
    for (int i = 0; i < n; ++i)
        dp[i][i] = 0;

    for (int l = 1; l < n; ++l)
    {
        for (int i = 0; i < n - l; ++i)
        {
            int j = i + l;
            dp[i][j] = inf;
            for (int k = i; k < j; ++k)
            {
                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k + 1][j] + d[i] * d[k + 1] * d[j + 1]);
            }
        }
    }

    cout << dp[0][n - 1] << endl;
}

int main()
{
    solve();
        return 0;
}


#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
//C++11
#if __cplusplus == 201103L
#include <tuple>
#endif

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;

int main(){
  string s;
  map<char, int> m;
  m['J'] = 0;
  m['O'] = 1;
  m['I'] = 2;
  while(cin>>s){
    s = "I" + s;
    int N = s.size();
    int cnt[3]={};
    int ans = 0;
    for(int i = 1; i < N; i++){
      int n = m[s[i]];
      int b = m[s[i-1]];
      if(n < b){
        REP(i, 3) cnt[i] = 0;
        if(n == 0) cnt[0]++;
      }else{
        cnt[n]++;
        if(cnt[0]>=cnt[1]&&cnt[1]==cnt[2]) ans = max(ans, cnt[1]);
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

#include <iostream>
#include <string>
using namespace std;

int k = 0, sum = 0, a[1000000];
string s;

int main() {
	cin >> s;

	for(int i = 0; i < s.size(); i++){
		sum++;
		if(s[i] != s[i + 1]){
			for(int j = i - sum + 1; j <= i; j++){
				a[j] = sum;
				sum--;
			}
			sum = 0;
		}
	}

	for(int i = 0; i < s.size(); i++){
		if(a[i] > k && s[i] == 'J'){
			if(a[i + a[i]] == a[i] && s[i + a[i]] == 'O' && a[i + a[i] * 2] >= a[i] && s[i + a[i] * 2] == 'I'){
				k = a[i];
			}
		}
	}

	cout << k << endl;

	return 0;
}


/**
DufauX-XuafuD
**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define reset(x) memset(x,-1,sizeof(x))
#define CheckBit(a,b) (a&(1ll<<b))
#define SetBit(a,b) a=(a|(1ll<<b))
#define UnSetBit(a,b) a=(a&(~(1ll<<b)))
#define maxx 10000006
#define PI 2*acos(0.0)
const long long INF = 2000000000000000000LL;	// 2e18
const int inf = 0x3f3f3f3f;	// 1061109567
const long double EPS = 1e-9;
//bitset<maxx/2>vis;
//bitset<maxx>pr;
//int mobi[maxx+10];
//vector<ll>prime;
//void sieve(){
//    ll x=maxx/2, y=sqrt(maxx)/2;
//    for(ll i=1;i<=y;i++){
//        if(vis[i]==0){
//            for(ll j=(i*(i+1)*2);j<x;j+=(2*i)+1)
//                vis[j]=1;
//        }
//    }
//    prime.push_back(2);
//    for(ll i=3;i<maxx;i+=2)
//        if(vis[i/2]==0)
//        prime.push_back(i);
//}
//void generate_mobius()
//{
//    for(int i=0;i<maxx;i++)mobi[i]=1;
//    for(int i=2;i<maxx;i++){
//        if(!pr[i]){
//            mobi[i]*=-1;
//            for(int j=i+i;j<maxx;j+=i){
//                pr[j]=1;
//                mobi[j]*=(j%(i*i)?-1:0);
//            }
//        }
//    }
//}
//bool isprime(ll a)
//{
//    if(a==1)return false;
//    if(a==2)return true;
//    if(a%2==0)return false;
//    for(ll i=0;i<prime.size() && prime[i]*prime[i]<=a;i++)
//        if(a%prime[i]==0)return false;
//    return true;
//}
/* Calculate ( a*b ) %c */
inline ll mulmod(ll a, ll b, ll c) {
    ll ret = 0 , cur = a % c ;
    while(b) { if(b%2) ret=(ret+cur)%c; cur=(cur<<1)%c; b=b>>1; }
    return ret%c;
}
//Calculate (b^p)%m || modular inverse: b^-1 = bigmod(b, m-2, m)
inline ll bigmod(ll b, ll p, ll m){
    ll ret = 1, cur = b % m;
    while(p) { if(p&1) ret=(ret*cur)%m; cur=(cur*cur)%m; p=p>>1; }
    return ret;
}
inline ll modulo(ll a,ll b,ll c) { //Same as big mod, use for numbers over 1e10
    ll ret = 1 , cur = a%c ;
    while(b) { if(b%2) ret=mulmod(ret,cur,c); cur=mulmod(cur,cur,c); b=b>>1; }
    return ret%c ;
}
inline ll power(ll b, ll p){
    ll ret = 1, cur = b;
    while(p) { if(p&1) ret=(ret*cur); cur=(cur*cur); p=p>>1; }
    return ret;
}
ll lcm(ll a,ll b)
{
    return (a/__gcd(a,b))*b;
}
ll gcd(ll a,ll b)
{
    return __gcd(a,b);
}
void Dufaux()
{
    ll sx,sy,tx,ty;
    cin>>sx>>sy>>tx>>ty;
    string ans="";
    for(int i=0;i<ty-sy;i++)ans+="U";
    for(int i=0;i<tx-sx;i++)ans+="R";
    for(int i=0;i<ty-sy;i++)ans+="D";
    for(int i=0;i<tx-sx;i++)ans+="L";
    ans+="L";
    for(int i=0;i<ty-sy+1;i++)ans+="U";
    for(int i=0;i<tx-sx+1;i++)ans+="R";
    ans+="D";
    ans+="R";
    for(int i=0;i<ty-sy+1;i++)ans+="D";
    for(int i=0;i<tx-sx+1;i++)ans+="L";
    ans+="U";
    cout<<ans<<endl;
}
int main()
{
    FastIO;
	///sieve();
	///generate_mobius();
	int test=1;
	while(test--){
        Dufaux();
	}
	return 0;
}

#include <bits/stdc++.h>
using namespace std;

int64_t modpow(int64_t x, int64_t n) {
    const int MOD = 998244353;
    x = x%MOD;
    if(n==0) return 1;  //再帰の終了条件

    else if(n%2==1) {
        return (x*modpow(x, n-1))%MOD;  //nが奇数ならnを1ずらす
    }
    else return modpow((x*x)%MOD, n/2)%MOD;  //nが偶数ならnが半分になる
}

int main() {
  int64_t n,m,k;
  cin>>n>>m>>k;
  const int MOD = 998244353;

  int64_t m_1[k+1];
  int64_t start = n-1-k;
  m_1[0] = modpow(m-1, start);
  for(int i=1; i<=k; i++) {
    m_1[i] = (m_1[i-1]*(m-1))%MOD;
  }

  int64_t ans = 0;
  int64_t comb = 1;
  for(int i=0; i<=k; i++) {
    int64_t add = (comb*m_1[k-i])%MOD;
    ans += add;
    ans = ans%MOD;
    comb = (comb*(n-1-i))%MOD;
    int64_t div = modpow((i+1), MOD-2);
    comb = (comb*div)%MOD;
  }

  ans = (ans*m)%MOD;

  cout<<ans<<endl;

  return 0;
}


#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; i++)
#define reps(i, n) for (int i = 1, i##_len = (int)(n); i <= i##_len; i++)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define repi(i, x) \
	for (auto i = (x).begin(), i##_fin = (x).end(); i != i##_fin; i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
string solve(bool a) { return ((a) ? "Yes" : "No"); }
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int, int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long, long long> P;
typedef vector<P> VP;
template <class T>
inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return 1;
	}
	return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return 1;
	}
	return 0;
}
template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os << "(" << p.first << "," << p.second << ")";
	return os;
}
template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	os << "{";
	rep(i, v.size()) {
		if (i) os << ",";
		os << v[i];
	}
	os << "}";
	return os;
}
template <class T, class U>
istream& operator>>(istream& is, pair<T, U>& p) {
	is >> p.first >> p.second;
	return is;
}
template <class T>
istream& operator>>(istream& is, vector<T>& v) {
	rep(i, v.size()) { is >> v[i]; }
	return is;
}
const long long INFLL = 1LL << 60;
const int INF         = 1 << 30;
const double PI       = acos(-1);

int main() {
	int n;
	string s;
	ll ans = 0LL;
	cin >> n >> s;
	vector<string> dis1, dis2;
	string bef = "";
	for (int bit = 0; bit < (1 << n); bit++) {
		bef = "";
		for (int i = 0; i < n; i++) {
			if (bit & (1 << i)) {
				bef += s[i];
			}
		}
		bef += '0';
		for (int i = n - 1; i >= 0; i--) {
			if ((bit & (1 << i)) == 0) {
				bef += s[i];
			}
		}
		dis1.pb(bef);
		// clog << bef << endl;
		bef = "";
		//--------//

		for (int i = n - 1; i >= 0; i--) {
			if ((bit & (1 << i)) == 0) {
				bef += s[i + n];
			}
		}
		bef += '0';
		for (int i = 0; i < n; i++) {
			if (bit & (1 << i)) {
				bef += s[i + n];
			}
		}

		dis2.pb(bef);
		//	clog << bef << endl;
	}
	sort(all(dis1));
	sort(all(dis2));
	repi(i,dis1){
		ans +=
		    distance(lower_bound(all(dis2), *i), upper_bound(all(dis2), *i) );
	//	clog << ans << endl;
	}
	cout << ans << endl;
}
/*
半分全挙列
chose red; head last: blue
chose bule: head last: red

top!= head: rr- bb- -> 2n:: n
2^n * log(n^2)

cabaacba = caba \ acba
c  -> /  aba ->
aba   <-/ <- c
== c aba   /  c aba
ab  ->/ ac
ca <-/ ba
== ab ac / ab ac
*/

#include <bits/stdc++.h>
#define owo(i,a, b) for(int i=(a);i<(b); ++i)
#define uwu(i,a, b) for(int i=(a)-1; i>=(b); --i)
#define senpai push_back
#define ttgl pair<int, int>
#define ayaya cout<<"ayaya~"<<endl

using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
gpu_hash_map<int, int> mp;*/
using ll = long long;
using ld = long double;
const ll MOD = 1000000007;
const ll root = 62;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
ll binpow(ll a,ll b){ll res=1;while(b){if(b&1)res=(res*a)%MOD;a=(a*a)%MOD;b>>=1;}return res;}
ll modInv(ll a){return binpow(a, MOD-2);}
const double PI = acos(-1);
const double eps = -1e6;
const int INF = 0x3f3f3f3f;
const int NINF = 0xc0c0c0c0;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const ll NINFLL = 0xc0c0c0c0c0c0c0c0;
const int mxN = 1001;
ll arr[mxN];
ll b[mxN];
int cnt[mxN*mxN];
ll n, m;
int main() {
    //freopen("file.in", "r", stdin);
    //freopen("file.out", "w", stdout);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    cin.tie(0)->sync_with_stdio(0);
    cin>>n>>m;
    owo(i, 0, n) {
        cin>>arr[i];
        cnt[arr[i]]++;
        if(cnt[arr[i]]>1) {
            cout<<"0\n";
            exit(0);
        }
    }
    memset(cnt, 0, sizeof(cnt));
    owo(i, 0, m) {
        cin>>b[i];
        cnt[b[i]]++;
        if(cnt[b[i]]>1) {
            cout<<"0\n";
            exit(0);
        }
    }
    ll ans = 1;
    sort(arr, arr+n);
    sort(b, b+m);
    reverse(arr, arr+n);
    reverse(b, b+m);
    ll aidx = 0;
    ll bidx = 0;
    for(ll nxt=n*m; nxt>0; --nxt) {
        while(aidx<n&&arr[aidx]>=nxt)aidx++;
        while(bidx<m&&b[bidx]>=nxt)bidx++;
        if(arr[aidx-1]==nxt&&b[bidx-1]==nxt) {
            ans = (ans*1LL)%MOD;
        }else if(arr[aidx-1]==nxt) {
            ans = (ans * bidx)%MOD;
        }else if(b[bidx-1]==nxt) {
            ans = (ans * aidx)%MOD;
        }else {
            ans = (ans * max((aidx * bidx - n * m + nxt), 0LL))%MOD;
        }
    }
    cout<<ans<<"\n";
    return 0;
}


#include <bits/stdc++.h>
#define lid id << 1
#define rid id << 1 | 1

using namespace std;
const int MAXN = 2e5 + 5;
const int INF = 1e9;

int h, w, a[MAXN], L[MAXN], R[MAXN], ans[MAXN];

template <class T>
void read(T &x, T f = 1, char ch = getchar()) {
    x = 0;
    while (ch < '0' || ch > '9') f = (ch == '-' ? -1 : 1), ch = getchar();
    while (ch >= '0' && ch <= '9') x = x * 10 + ch - 48, ch = getchar();
    x *= f;
}

// a[i] = a[i-1]  i∉[L,R]
// a[i] = a[L-1] -L + 1 + i  i∈[L,R];

struct Node {
    int l, r, mi, lval;
    bool tag;
    Node() { mi = lval = 0, tag = 0; }
    // mi denotes the minimum a in [l,r]
    // lval denotes the value of the left end point of [l,r]
} tr[MAXN * 4];

void update(int id) {
    tr[id].mi = min(tr[lid].mi, tr[rid].mi);
    tr[id].lval = tr[lid].lval;
}

void pushdown(int id) {
    if (tr[id].tag) {
        tr[lid].tag = 1;
        tr[lid].lval = tr[lid].mi = tr[id].lval;
        tr[rid].tag = 1;
        tr[rid].lval = tr[rid].mi = tr[id].lval + tr[rid].l - tr[lid].l;
        tr[id].tag = 0;
    }
}

void build(int id, int l, int r) {
    tr[id].l = l, tr[id].r = r;
    if (l == r) return;
    int mid = l + r >> 1;
    build(lid, l, mid);
    build(rid, mid + 1, r);
}

void modify(int id, int l, int r, int val) {
    if (tr[id].l == l && tr[id].r == r) {
        tr[id].mi = tr[id].lval = val;
        tr[id].tag = 1;
        return;
    }
    pushdown(id);
    int mid = tr[id].l + tr[id].r >> 1;
    if (r <= mid)
        modify(lid, l, r, val);
    else if (l > mid)
        modify(rid, l, r, val);
    else {
        modify(lid, l, mid, val);
        modify(rid, mid + 1, r, val + mid + 1 - l);
    }
    update(id);
}

int query(int id, int l, int r) {
    if (r < 1) return INF;
    if (tr[id].l == l && tr[id].r == r) {
        return tr[id].mi;
    }
    pushdown(id);
    int mid = tr[id].l + tr[id].r >> 1;
    if (r <= mid)
        return query(lid, l, r);
    else if (l > mid)
        return query(rid, l, r);
    else
        return min(query(lid, l, mid), query(rid, mid + 1, r));
}

int main() {
    read(h), read(w);
    for (int i = 1; i <= h; i++) read(L[i]), read(R[i]);
    fill(ans + 1, ans + h + 2, -1);
    build(1, 1, w);
    for (int i = 2; i <= h + 1; i++) {
        int tmp = query(1, L[i - 1] - 1, L[i - 1] - 1);
        modify(1, L[i - 1], R[i - 1], tmp + 1);
        int mi = query(1, 1, w);
        if (mi >= INF) break;
        ans[i] = mi + i - 1;
    }
    for (int i = 2; i <= h + 1; i++) printf("%d\n", ans[i]);
    return 0;
}

#include <iostream>
#include <algorithm>

using namespace std;

int main() {
  int n;
  cin >> n;

  long long l[n];
  for (int i = 0; i < n; ++i) cin >> l[i];
  sort(l, l + n);

  int cnt = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      if (l[i] == l[j]) continue;
      for (int k = j + 1; k < n; ++k) {
        if (l[i] == l[k] || l[j] == l[k]) continue;
        if (l[i] + l[j] <= l[k]) break;
        cnt++;
      }
    }
  }

  cout << cnt << endl;
}


#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<numeric>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

using ll = long long;

class Stream{
public:
    Stream(){

    }
    //配列以外の入力を受け取る
    void read(){

    }
    template<typename First, typename... Rest>
    void read(First& first, Rest&... rest){
        cin >> first;
        read(rest...);
    }
    //配列を区切って出力する
    template<typename T>
    void write_vec(vector<T>& v, char divider){
        for(size_t i = 0; i < v.size(); i++){
            cout << v[i] << divider;
        }
    }
};

int main(){
    Stream io;

    int N, K;
    io.read(N, K);
    if(N % K == 0) cout << 0;
    else cout << 1;
    return 0;
}

// J'aime
// Chemise Blanche

#include <bits/stdc++.h>
using namespace std;

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr << __LINE__ << " > " << #x << " = " << (x) << endl

void MAIN() {
  string s;
  cin >> s;
  for (int i = 0; i < s.size() - 1; i++) {
    if (s.substr(i, 2) == "AC") {
      cout << "Yes" << '\n';
      return;
    }
  }
  cout << "No" << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}