#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int layout[500 * 500];
  for (int i = 0; i < 500 * 500; i++) layout[i] = 0;
  int curr = 250 * 500;
  layout[curr] = 1;
  for (int i = 0; i < s.length(); i++) {
    if (s[i] == 'U') {
      curr -= 500;
    } else if (s[i] == 'D') {
      curr += 500;
    } else if (s[i] == 'L') {
      curr -= 1;
    } else {
      curr += 1;
    }
    layout[curr]++;
  }
  int count = 0;
  for (int i = 0; i < 500 * 500; i++) {
    if (layout[i] > 1) {
      int l = layout[i];
      count += l * (l - 1) / 2;
    }
  }
  cout << count;
  return 0;
}
