#include <bits/stdc++.h>
using namespace std;
bool vis[1003][1003];
int ans[1003][1003];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, a = 500, b = 500, cnt = 0;
  cin >> n;
  string second;
  cin >> second;
  vis[a][b] = true;
  for (int i = 0; i < n; i++) {
    if (second[i] == 'U') {
      a++;
    }
    if (second[i] == 'D') {
      a--;
    }
    if (second[i] == 'R') {
      b++;
    }
    if (second[i] == 'L') {
      b--;
    }
    if (vis[a][b] == true) {
      ans[a][b]++;
    }
    vis[a][b] = true;
  }
  for (int i = 0; i < 1000; i++) {
    for (int j = 0; j < 1000; j++) {
      cnt += (ans[i][j] * (ans[i][j] + 1)) / 2;
    }
  }
  cout << cnt;
  return 0;
}
