#include <bits/stdc++.h>
using namespace std;
int n;
string s;
map<pair<int, int>, int> been;
int ans;
int ix, iy;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cerr.tie(0);
  cout.tie(0);
  cin >> n;
  cin >> s;
  been[{0, 0}] = 1;
  for (auto it : s) {
    if (it == 'U') iy++;
    if (it == 'D') iy--;
    if (it == 'R') ix++;
    if (it == 'L') ix--;
    ans += been[{ix, iy}];
    been[{ix, iy}]++;
  }
  return cout << ans, 0;
}
