#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  string S;
  cin >> S;
  map<pair<int, int>, int> M;
  M[make_pair(0, 0)]++;
  int currx = 0, curry = 0;
  for (int i = 0; i < S.size(); ++i) {
    if (S[i] == 'U') {
      curry++;
      M[make_pair(currx, curry)]++;
    } else if (S[i] == 'D') {
      curry--;
      M[make_pair(currx, curry)]++;
    } else if (S[i] == 'R') {
      currx++;
      M[make_pair(currx, curry)]++;
    } else if (S[i] == 'L') {
      currx--;
      M[make_pair(currx, curry)]++;
    }
  }
  int sum = 0;
  for (map<pair<int, int>, int>::iterator it = M.begin(); it != M.end(); ++it) {
    sum = sum + (it->second) * (it->second - 1) / 2;
  }
  cout << sum << endl;
  return 0;
}
