#include <iostream>
using namespace std;

int n;
int arr[50000];
int ans = 0;

int main()
{
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> arr[i];
    }

    for (int i = 0; i < n; i++)
    {
        int min = arr[i];
        int max = arr[i];
        for (int j = i; j < n; j++)
        {

            if (arr[j] > max)
                max = arr[j];
            if (arr[j] < min)
                min = arr[j];
            if (max - min + 1 == j - i + 1)
                ans++;
        }
    }
    cout << ans;
    return 0;
}
