#include #include #include using namespace std; int main() { int N; cin >> N; vector A(N); for (int i = 0; i < N; ++i) { cin >> A[i]; } unordered_map> di; for (int i = 0; i < N; ++i) { di[A[i]].push_back(i); } int ans = 0; for (int i = 0; i < N - 3; ++i) { for (int j = i + 1; j < N - 2; ++j) { if (di.find(A[i] + 10) != di.end()) { for (int k : di[A[i] + 10]) { if (A[k] > A[j]) break; if (di.find(A[j] + 1) != di.end()) { for (int l : di[A[j] + 1]) { if (A[i] + 10 == A[k] && A[j] + 1 == A[l] && A[i] < A[j] && A[j] > A[k] && A[k] < A[l] && i < j && j < k && k < l) { ans++; } } } } } } } cout << ans << endl; return 0; }