#include <bits/stdc++.h>
using namespace std;
long long n, i, j, l = 2, t = 0, k = 1, cost, ind, r = 3, x = 1, ans = 0, y = 0;
string s;
map<pair<long long, long long>, long long> dp;
map<pair<long long, long long>, long long>::iterator it;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  x = 0;
  y = 0;
  cin >> s;
  dp[{x, y}]++;
  for (i = 0; i < n; i++) {
    if (s[i] == 'U')
      y++;
    else if (s[i] == 'D')
      y--;
    else if (s[i] == 'L')
      x--;
    else
      x++;
    dp[{x, y}]++;
  }
  for (it = dp.begin(); it != dp.end(); it++) {
    k = it->second;
    ans += (k * (k - 1)) / 2;
  }
  cout << ans << '\n';
  return 0;
}
