Ivan has a robot which is situated on an infinite grid. Initially the robot is standing in the starting cell (0, 0). The robot can process commands. There are four types of commands it can perform:  U — move from the cell (x, y) to (x, y + 1);  D — move from (x, y) to (x, y - 1);  L — move from (x, y) to (x - 1, y);  R — move from (x, y) to (x + 1, y). Ivan entered a sequence of n commands, and the robot processed it. After this sequence the robot ended up in the starting cell (0, 0), but Ivan doubts that the sequence is such that after performing it correctly the robot ends up in the same cell. He thinks that some commands were ignored by robot. To acknowledge whether the robot is severely bugged, he needs to calculate the maximum possible number of commands that were performed correctly. Help Ivan to do the calculations!

The first line contains one number n — the length of sequence of commands entered by Ivan (1 ≤ n ≤ 100). The second line contains the sequence itself — a string consisting of n characters. Each character can be U, D, L or R.

Print the maximum possible number of commands from the sequence the robot could perform to end up in the starting cell.

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
    int n;
    cin>>n;
    char a[n];
    int tl=0;
    int tr=0;
    int tu=0;
    int td=0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(a[i]=='L')
            tl++;
        else if(a[i]=='R')
            tr++;
        else if(a[i]=='U')
            tu++;
        else if(a[i]=='D')
            td++;
    }
    int col;
    int row;
    if(tl<tr)
        row=tl;
    else
        row=tr;
    if(tu<td)
        col=tu;
    else
        col=td;
    cout<<2*(row+col);
    return 0;
}

#include<bits/stdc++.h>
#define ll long long int
#define bra string
#define fuck while
#define pi acos(-1)
using namespace std;

int main()
{

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  //freopen("input.txt","r",stdin);
  //freopen("output.txt","w",stdout);

  ll t,i,j,k;
  bra s;
  cin>>t;
  cin>>s;
  ll l=s.size();
  ll x=0,y=0;
  for(i=0;i<l;i++)
  {
    if(s[i]=='U')
    {
      y=y+1;
    }
    else if(s[i]=='D')
    {
      y=y-1;
    }
    else if(s[i]=='L')
    {
      x=x-1;
    }
    else if(s[i]=='R')
    {
      x=x+1;
    }
  }

  //cout<<x<<" "<<y<<endl;
  cout<<t-(abs(x)+abs(y))<<endl;
}

  //rOkY
  //FuCk

  //######################### kOpAl ##########################

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

/* msi1427 */

#define ll           long long
#define ull          long long unsigned
#define LD           long double
#define FOR(i,n)     for(int i=0;i<n;i++)
#define FLR(i,n)     for(ll i=0;i<n;i++)
#define RFOR(i,n)   for(int i=n-1;i>=0;i--)
#define RFLR(i,n)    for(ll i=n-1;i>=0;i--)
#define rep(i,a,b)    for(int i=a;i<=b;i++)
#define repl(i,a,b)  for(ll i=a;i<=b;i++)
#define casep(z)     cout << "Case " << z << ": ";
#define Fast         ios_base::sync_with_stdio(0);cin.tie(0);
#define sz(a)        a.size()
#define all(x)       x.begin(),x.end()
#define SORT(a,n)    sort(a,a+n)
#define RSORT(a,n)   sort(a,a+n,greater<ll>())
#define pii          pair<int,int>
#define pll          pair<ll,ll>
#define VSORT(v)     sort(all(v))
#define VRSORT(v)    sort(all(v),greater<ll>())
#define pb           push_back
#define pf            push_front
#define pob          pop_back()
#define pof          pop_front()
#define ff           first
#define ss           second
#define tt           true
#define fs           false
#define MP           make_pair
#define MEM(x,n)      memset((x),n,sizeof(x))
#define bsrch(a,n,x) binary_search(a,a+n,x)
#define vi           vector<int>
#define vll          vector<ll>
#define PI          acos(-1.0)
#define LB(a,x)      (lower_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which does not compare less than val.
#define UB(a,x)      (upper_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which compares greater than val.
#define PQ           priority_queue
#define heap       PQ< ll , vll , greater < ll > >
#define REV(x)       reverse(all(x))
#define mpii         map<int,int>
#define mpll         map<ll,ll>
#define cig          cin.ignore()
#define INF          (ll)1e10
#define EPS          1e-9
#define prec(n)      fixed << setprecision(n)
#define lb           lower_bound
#define ub           upper_bound
#define fin          freopen("in.txt","r",stdin)
#define fout         freopen("out.txt","w",stdout)
#define sc           scanf
#define pt           printf
#define np           next_permutation
#define IT(it,x)     for(it=x.begin();it!=x.end();it++)
#define sci(x)       scanf("%d",&x);
#define scl(x)       scanf("%lld",&x);
#define scd(x)       scanf("%lf",&x);

#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(min(a,b),min(c,d))
#define max4(a,b,c,d)   max(max(a,b),max(c,d))
#define max5(a,b,c,d,e) max(max3(a,b,c),max(d,e))
#define min5(a,b,c,d,e) min(min3(a,b,c),min(d,e))

typedef
tree<
  ll,
  null_type,
  less<ll>,
  rb_tree_tag,
  tree_order_statistics_node_update>
ordered_set;

ll dx[] = {1,-1,0,0};
ll dy[] = {0,0,1,-1};

ll ceiling(ll x,ll y)
{
    if(x%y) return ((x/y)+1);
    else return (x/y);
}

ll gcd(ll x,ll y)
{
    return ((y==0)?x:gcd(y,x%y));
}

ll lcm(ll x,ll y)
{
    return ((x*y)/gcd(x,y));
}

ll BMod(ll B,ll P,ll M)
{
    ll R=1;
    while(P)
    {
        if(P&1)
            R=(R*B)%M;
        P >>= 1;
        B=(B*B)%M;
    }
    return R;
}

bool check(ll n,ll pos) {return (n&(1<<pos));}
ll SET(ll n,ll pos){return (n|(1<<pos));}
ll RESET(ll n,ll pos) {return(n&~(1<<pos));}

#define MOD 1000000007
#define MAX 1000005
#define NUM 105

ll n,cc;
string s;
bool vis[212];

int main()
{
    Fast
    cin>>n;
    cin>>s;
    FLR(i,sz(s)){
    if(s[i]=='L' && !vis[i]){
            vis[i]=true;
        repl(j,i+1,sz(s)-1){
        if(s[j]=='R' && !vis[j]) {
                cc+=2;
                vis[j]=true;
                break;
        }
        }
    }
    else if(s[i]=='R'&& !vis[i]){
        vis[i]=true;
        repl(j,i+1,sz(s)-1){
        if(s[j]=='L'&& !vis[j]) {
                cc+=2;
               vis[j]=true;
               break;
        }
        }
    }
    else if(s[i]=='U'&& !vis[i]){
        vis[i]=true;
        repl(j,i+1,sz(s)-1){
        if(s[j]=='D'&& !vis[j]) {
                cc+=2;
               vis[j]=true;
               break;
        }
        }
    }
    else if(s[i]=='D'&& !vis[i]){
        vis[i]=true;
        repl(j,i+1,sz(s)-1){
        if(s[j]=='U'&& !vis[j]) {
                cc+=2;
               vis[j]=true;
               break;
        }
        }
    }
    }
    cout << cc << "\n";
}
/*
6
LDURUD
*/

#include<iostream>
#include<string>
using namespace std;
void main()
{
	int n,var1,var2, cnt1 = 0, cnt2 = 0, cnt3 = 0, cnt4 = 0;
	string a;
	cin >> n;
	cin >> a;
	for (int i = 0; i<n; i++){

		if (a[i] == 'U') cnt1++;

		if (a[i] == 'D') cnt2++;

		if (a[i] == 'R') cnt3++;

		if (a[i] == 'L') cnt4++;

	}
	if (cnt1 > cnt2)var1 = cnt2;
	else var1 = cnt1;
	if (cnt3 > cnt4)var2 = cnt4;
	else var2 = cnt3;

	cout << 2 * var1 + 2 * var2;

}

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
char str[105];
int main()
{
	int n;
	while(cin>>n)
	{
		cin>>str;
		int l=0,r=0,u=0,d=0;
		int len=strlen(str);
		for(int i=0;i<len;i++)
		{
			if(str[i]=='L')
			l++;
			if(str[i]=='R')
			r++;
			if(str[i]=='U')
			u++;
			if(str[i]=='D')
			d++;
		}
		int ans=2*min(l,r)+2*min(u,d);
		cout<<ans<<endl;
	}
return 0;
}

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <sstream>
#include <cstring>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <fstream>
#define inf 0x3f3f3f3f
#define INF 0x7ffffffffffffffffff
#define LL long long
#define llu unsigned long long
#define MAXN 1000100
#define PI acos(-1.0)
using namespace std;
const int mod = 1e9 + 7;
int main(){
    int n, ans, l, r, u, d;
    l = r = u = d = 0;
    ans = 0;
    char ch;
    scanf("%d", &n);
    getchar();
    for(int i = 1; i <= n; ++i){
        scanf("%c", &ch);
        if(ch == 'L'){
            if(r != 0){
                --r;
                ans += 2;
            }
            else
                ++l;
        }
        if(ch == 'R'){
            if(l != 0){
                --l;
                ans += 2;
            }
            else
                ++r;
        }
        if(ch == 'U'){
            if(d != 0){
                --d;
                ans += 2;
            }
            else
                ++u;
        }
        if(ch == 'D'){
            if(u != 0){
                --u;
                ans += 2;
            }
            else
                ++d;
        }

    }
    printf("%d\n", ans);
    return 0;
}

#include <iostream>
#include <string>

using namespace std;

int main()
{
    int n,Ucount = 0,Dcount = 0,Lcount = 0,Rcount = 0,result = 0;
    cin >> n;
    string commands;
    cin >> commands;
    for(register int i = 0;i < n;i++)
    {
        if(commands[i] == 'U')
            Ucount++;
        else if(commands[i] == 'D')
            Dcount++;
        else if(commands[i] == 'R')
            Rcount++;
        else
            Lcount++;
    }
    if(Ucount > Dcount)
        result += (Dcount*2);
    else
        result += (Ucount*2);
    if(Rcount > Lcount)
        result += (Lcount*2);
    else
        result += (Rcount*2);
    cout << result;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<ll> vi;
#define mp make_pair
#define pb push_back
#define fo(i,n) for(int i=0;i<n;i++)
#define fp(i,k,n) for(int i=k;i<n;i++)
#define Fo(i,n) for(int i=1;i<=n;i++)
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll n,countr=0,countl=0,countd=0,countu=0;
    cin>>n;
    Fo(i,n)
    {
        char c;
        cin>>c;
        if(c=='U')
            countu++;
        else if(c=='D')
            countd++;
        else if(c=='R')
            countr++;
        else
            countl++;
    }
    cout<<(min(countd,countu)+min(countl,countr))*2;
    return 0;
}

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

using namespace std;
using namespace __gnu_pbds;
using ll = long long;
template<typename key> using ordered_set = tree <key, null_type, less<key>, rb_tree_tag, tree_order_statistics_node_update>;

int main () {
   IO;
   int n, ans = 0, fin = 0;
   string s;
   cin >> n >> s;
   pair< int, int > h, v;
   for(int i = 1; i <= n; i++) {
      if(s[i - 1] == 'R')
         h.first++;
      if(s[i - 1] == 'L')
         h.second++;
      if(s[i - 1] == 'U')
         v.first++;
      if(s[i - 1] == 'D')
         v.second++;
   }
   cout << 2 * min(h.first, h.second) + 2 * min(v.first, v.second);
   return 0;
}

#include<bits/stdc++.h>
using namespace std;
int n,x,y;
string s;
int main() {
    cin>>n;
    cin >> s;
    for (char c : s) {
        switch (c) {
            case 'U': y++; break;
            case 'D': y--; break;
            case 'L': x--; break;
            case 'R': x++; break;
        }
    }
    cout << n-abs(x)-abs(y) <<endl;
}

// acm_training.cpp: определяет точку входа для консольного приложения.
//

#include "stdio.h"
#include <iostream>
#include <string>

using namespace std;

int main()
{
	int n, L = 0, R = 0, U = 0, D = 0, res;
	char cur;
	string str;

	cin >> n;
	cin >> str;

	for (int i = 0; i < n; i++)
	{
		cur = str[i];
		switch (cur)
		{
		case 'L': L++; break;
		case 'R': R++; break;
		case 'U': U++; break;
		case 'D': D++; break;
		}
	}
	res = (min(L, R) * 2) + (min(U, D) * 2);
	cout << res;

	return 0;
}

#include <iostream>

using namespace std;

int main()
{
   long long int n,x=0,y=0,count=0,i,W;
   string s;
   cin >> n;
   cin >> s;
   for(i=0;i<s.length();i++)
   {
       if(s[i]=='L')
       {
           x=x-1;
           y=y;

       }
       else if(s[i]=='R')
       {
           x=x+1;
           y=y;

       }
       else if(s[i]=='U')
       {
           x=x;
           y=y+1;

       }
       else if(s[i]=='D')
       {
           x=x;
           y=y-1;

       }
   }
   W=abs(x)+abs(y);
   cout << n-W<< endl;
}

#include <iostream>
#include <cmath>

using namespace std;

int main(){
    int n;
    cin >> n;
    int x, y;
    x = 0;
    y = 0;
    char a;
    //cout << n << endl;
    for(int i = 0; i < n; i++){
        //cout << "ok";
        cin >> a;

        if(a == 'U'){
            x++;
        }else if(a == 'D'){
            x--;
        }else if(a == 'L'){
            y++;
        }else if(a == 'R'){
            y--;
        }
    }
    cout << (n - abs(x) - abs(y)) << endl;
}

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<queue>
#include<stack>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<stdlib.h>
#include<cmath>
#include<string>
#include<algorithm>
#include<iostream>
using namespace std;
#define lson k*2
#define rson k*2+1
#define M (t[k].l+t[k].r)/2
#define ll long long
int main()
{
    int n,i,j;
    int x=0,y=0,ans=0;
    char s[105];
    int a[5];
    memset(a,0,sizeof(a));
    scanf("%d%s",&n,s);
    for(i=0;i<strlen(s);i++)
    {
        switch(s[i])
        {
            case 'L':a[0]++;break;
            case 'R':a[1]++;break;
            case 'U':a[2]++;break;
            case 'D':a[3]++;break;
        }
    }
    if(a[0]!=0&&a[1]!=0)
    {
        ans+=min(a[0],a[1])*2;
    }
    if(a[2]!=0&&a[3]!=0)
    {
        ans+=min(a[2],a[3])*2;
    }
    printf("%d\n",ans);
    return 0;
}

#include<iostream>
using namespace std;
int main()
{
	int n,i,a1=0,a2=0,a3=0,a4=0;
	string a;
	cin>>n>>a;
	for(i=0;i<n;i++)
	{
		if(a[i]=='L')
			a1++;
		if(a[i]=='R')
			a2++;
		if(a[i]=='U')
			a3++;
		if(a[i]=='D')
			a4++;
	}
	cout<<2*(min(a1,a2)+min(a3,a4));
	return 0;
}

#include <iostream>
using namespace std;
int n,u,d,l,r,i,ans;
char a;
int main()
{
	cin>>n;
	for(i=1;i<=n;i++)
	{
		cin>>a;
		if(a=='D')
			d++;
		if(a=='L')
			l++;
		if(a=='R')
			r++;
		if(a=='U')
			u++;
	}
	if(l<r)
		ans+=2*l;
	if(l>=r)
		ans+=2*r;
	if(u<d)
		ans+=2*u;
	if(u>=d)
		ans+=2*d;
	cout<<ans;
	return 0;
}

#include<bits/stdc++.h>
#define int long long
using namespace std;

char cnt[101];

main ()
{
    int n;
    cin>>n;
    int ans=n;
    int x=0;
    int y=0;
    for (int i=1;i<=n;++i){
        char ch;
        cin>>ch;
        if (ch=='L')--x;
        if (ch=='R')++x;
        if (ch=='U')++y;
        if (ch=='D')--y;
    }
    ans-=abs(x);
    ans-=abs(y);
    cout<<ans;
}

#include <bits/stdc++.h>
using namespace std;
int main(){
int n,i,sl=0,sr=0,su=0,sd=0,z=-1;
string s;
int ans=0,x=0,y=0;
cin>>n;
cin>>s;
for(i=0;i<n;i++){
        if(s[i]=='U') su++;
        else if(s[i]=='D') sd++;
        else if(s[i]=='L') sl++;
        else if(s[i]=='R') sr++;
    }
    cout<<n-abs(su-sd)-abs(sl-sr);
return 0;}

#include <iostream>
#include <string>
#include <math.h>

int main()
{
    int n = 0;
    std::cin >> n;
    std::cin.get();
    std::string command;
    getline(std::cin, command);
    int countD = 0, countU = 0, countL = 0, countR = 0;
    for(int i(0); i < n; i++)
    {
        if(command[i] == 'D')
            countD++;
        if(command[i] == 'U')
            countU++;
        if(command[i] == 'L')
            countL++;
        if(command[i] == 'R')
            countR++;
    }
    std::cout << 2*(std::min(countR,countL)+std::min(countD, countU)) << std::endl;
    return 0;
}

#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<deque>
#include<cstdlib>
#include<cmath>
#include<numeric>
#include<string.h>
#include <queue>
#include <functional>

using namespace std;

const string FILENAME = "";
const bool FILE_IO = 1;

void init()
{
#ifdef ONLINE_JUDGE
	if (!FILENAME.empty())
	{
		freopen((FILENAME + ".in").c_str(), "r", stdin);
		freopen((FILENAME + ".out").c_str(), "w", stdout);
	}
#else
	if (FILE_IO)
	{
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	}
#endif
}

int main()
{
	init();
	int n, l = 0, r = 0, d = 0, u = 0;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		char c;
		cin >> c;
		if (c == 'R')
			r++;
		if (c == 'L')
			l++;
		if (c == 'D')
			d++;
		if (c == 'U')
			u++;
	}
	cout << 2 * (min(r, l) + min(d, u));
	return 0;
}

#include<iostream>
#include<string>
#include<cstring>
#include<cmath>
using namespace std;
int main()
{
	int n,i,k=0,s1=0,s2=0,s3=0,s4=0;
	char a[101];
	cin>>n;
	for(i=1;i<=n;i++)
		cin>>a[i];
	for(i=1;i<=n;i++)
	{
		if(a[i]=='U')
			s1++;
		if(a[i]=='D')
			s2++;
		if(a[i]=='L')
			s3++;
		if(a[i]=='R')
			s4++;
	}
	cout<<(min(s1,s2)+min(s3,s4))*2<<endl;
	return 0;
}

#include <iostream>
#include <memory.h>
#include <string.h>
#include <map>
using namespace std;
int num[105];
map<char,int> mp;
int main(){
	string command;
	int len;
	cin>>len;
	cin>>command;
	mp['L']=1;
	mp['R']=2;
	mp['U']=3;
	mp['D']=4;
	for(int i=0;i<len;i++){
		num[mp[command[i]]]++;
	}
	cout<<min(num[1],num[2])*2+min(num[3],num[4])*2<<endl;
}

#include <bits/stdc++.h>
using namespace std;
int main(){ int x=0,y=0;
    int n ;cin>>n; string a; cin>>a;
    for(int i=0;i<n;i++){
        if (a[i]=='R')x++;
        if (a[i]=='L')x--;
        if (a[i]=='U')y++;
        if (a[i]=='D')y--;
    }
if (x<0) x=x*-1;
if (y<0) y=y*-1;
cout<<n-x-y;
}

#include<bits/stdc++.h>
using namespace std;
map<pair<int,int>,pair<int,int> >mp;
int main()
{
    int n,x,y,i,ans,l=0,r=0,d=0,u=0;
    scanf("%d",&n);
    string st;
    cin>>st;
    for(i=0;i<n;i++)
    {
        if(st[i]=='L')
        l++;
        if(st[i]=='R')
        r++;
        if(st[i]=='U')
        u++;
        if(st[i]=='D')
        d++;
    }
    ans=2*(min(l,r)+min(u,d));
    printf("%d\n",ans);
}

#include<iostream>
#include<string>
using namespace std;
void main()
{
	int n,var1,var2, cnt1 = 0, cnt2 = 0, cnt3 = 0, cnt4 = 0;
	string a;
	cin >> n;
	cin >> a;
	for (int i = 0; i<n; i++){

		if (a[i] == 'U') cnt1++;

		if (a[i] == 'D') cnt2++;

		if (a[i] == 'R') cnt3++;

		if (a[i] == 'L') cnt4++;

	}
	if (cnt1 > cnt2)var1 = cnt2;
	else var1 = cnt1;
	if (cnt3 > cnt4)var2 = cnt4;
	else var2 = cnt3;

	cout << 2 * var1 + 2 * var2;

}

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#define ll long long
#include <map>
#define pair<int, int> pii
using namespace std;

int l;
char s[100000];
int c[256];
int main(){
    memset(c, 0, sizeof(c));
    scanf("%d", &l);
    scanf("%s", &s);
    for(int i=0; i<l; i++)
    {
        c[s[i]]++;
    }
    printf("%d\n", (min(c['U'], c['D']) + min(c['L'], c['R']))*2);
    return 0;
}

#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
string s;
int main()
{
    ios::sync_with_stdio(0),cin.tie(0);
//    freopen(".in","r",stdin);
//    freopen(".out","w",stdout);
    int i,j,a[5];
    memset(a,0,sizeof(a));
    cin>>i;
    cin>>s;
    for(i=0;i<s.length();i++)
    {
        if(s[i]=='L')
            a[1]++;
        if(s[i]=='R')
            a[2]++;
        if(s[i]=='D')
            a[3]++;
        if(s[i]=='U')
            a[4]++;
    }
    cout<<2*(min(a[1],a[2])+min(a[3],a[4]));
    return 0;
}

#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<string>
#include<cstdlib>
#include<algorithm>
using namespace std;
int n,a[101],s=0;
char sr[100];
int main()
{
	int i;
	scanf("%d",&n);
	scanf("%s",&sr);
	for(i=1;i<=n;i++)
	{
		if(sr[i-1]=='L')
		{
			a[1]++;
		}
		if(sr[i-1]=='R')
		{
			a[2]++;
		}
		if(sr[i-1]=='U')
		{
			a[3]++;
		}
		if(sr[i-1]=='D')
		{
			a[4]++;
		}
	}
	s=s+min(a[1],a[2])*2+min(a[3],a[4])*2;
	printf("%d",s);
	return 0;
}

#include<iostream>
#include<string>
int b[4];
using namespace std;
int main()
{
	int n,sum1=0,sum2=0;
	string a;
	cin >> n;
	cin >> a;
	if (a.size() == n)
	{
		for (int i = 0; i < n; i++)
		{
			if (a[i] == 'U')b[0]++;
			else if (a[i] == 'D')b[1]++;
			else if (a[i] == 'L')b[2]++;
			else if (a[i] == 'R')b[3]++;
		}
		if (b[0] > b[1])sum1 = b[1];
		else sum1 = b[0];
		if (b[2] > b[3])sum2 = b[3];
		else sum2 = b[2];
		cout << sum1 * 2 + sum2 * 2 << endl;
	}
}

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
    int vis[5],n;
    char str[110];
    memset(vis,0,sizeof(vis));
    scanf("%d",&n);
    scanf("%s",str);
    for(int i=0; str[i]!='\0' ;i++)
    {
        if(str[i]=='U')
        {
            vis[1]++;
        }
        else if(str[i]=='D')
        {
            vis[2]++;
        }
        else if(str[i]=='L')
        {
            vis[3]++;
        }
        else
            vis[4]++;
    }
    int ans=0;
    ans+=min(vis[1],vis[2])*2+min(vis[3],vis[4])*2;
    printf("%d\n",ans);
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
int r,l,u,d;
int main(){
	int n;
	cin >> n;
	string s;
	cin >> s;
	for(int i = 0;i < n;++i){
		if(s[i] == 'R') r++;
		else if(s[i] == 'L') l++;
		else if(s[i] == 'U') u++;
		else if(s[i] == 'D') d++;
	}
	cout << 2 * (min(r,l) + min(u,d)) << "\n";
	return 0;
}

#include<iostream>
#include<cmath>
using namespace std;
int main(){
	int m1=0,l1=0,n,l=0,m=0,i,s=0;
	cin>>n;
	char ch[n];
	for(i=0;i<n;++i)cin>>ch[i];
	for(i=0;i<n;++i){
		if(ch[i]=='L')l++;
		if(ch[i]=='R')l1++;
		if(ch[i]=='D')m++;
		if(ch[i]=='U')m1++;
	}
	s+=2*min(l1,l)+2*min(m1,m);
	cout<<s;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long int  ll;
int main()
{
	#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output 2.txt", "w", stdout);
    #endif

   int n;
   cin >> n;
   string s;
   cin >> s;
   int x,y;
   x=y=0;
   for(int i=0;i<s.length();i++)
   {
    if(s[i]=='L')
    {
        x--;
    }
    if(s[i]=='R')
    {
        x++;
    }
    if(s[i]=='U')
    {
        y++;
    }
    if(s[i]=='D')
    {
        y--;
    }
   }
   int ans=abs(x)+abs(y);
   cout<<n-ans<<endl;

    return 0;
}

#include <iostream>
#include <string>
using namespace std;
int a[100002];
int main(){
    string s;
    int n;
    cin>>n;
    cin>>s;
    for(int i=0;i<s.size();i++){
        if(s[i]=='L')
        a[0]++;
        if(s[i]=='R')
        a[1]++;
        if(s[i]=='D')
        a[2]++;
        if(s[i]=='U')
        a[3]++;
    }
    cout<<2*(min(a[0],a[1])+min(a[2],a[3]))<<endl;
    return 0;
}

#include <iostream>
#include <cmath>
#include <stdlib.h>
#include <algorithm>
#include <fstream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <map>
#include <time.h>

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define ll long long

const int N = 5*1e5+1;
const int M = 1e6+1;
const int inf = 1e9;
const int base = 1e9+7;

using namespace std;

int a[N],n;
string s;

int main()
{
    //ifstream cin ("input.txt");
    //ofstream cout ("output.txt");
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    char c;
    cin >> n;
    for (int i = 1; i <= n; i++){
        cin >> c;
        a[c]++;
    }
    cout << 2 * min(a['L'], a['R']) + 2 * min(a['U'], a['D']) << endl;
}

// http://codeforces.com/problemset/problem/888/B
// B. Buggy Robot

#include <iostream>
using std::cin;

int main()
{
	int n;
	cin >> n;
	int u = 0, d = 0, l = 0, r = 0;
	cin.get();
	for (int i = 0; i < n; i++)
	{
		char temp;
		cin >> temp;
		if (temp == 'U') u++;
		else if (temp == 'D') d++;
		else if (temp == 'L') l++;
		else r++;
	}
	std::cout << n - abs(u - d)-abs(l - r);
	cin.get();
	cin.get();
	return 0;
}

/*Author--Vishwas Agrawal*/
/*Author--Vishwas Agrawal*/
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define vll vector<ll>
#define pb push_back
#define mp make_pair
#define test \
   ll t;     \
   cin >> t; \
   while (t--)
#define fio                          \
   ios_base::sync_with_stdio(false); \
   cin.tie(NULL);                    \
   cout.tie(NULL);
#define M 1000000007LL
#define input(v, n)    \
   inc(i, 0, n)        \
   {                   \
      ll x;            \
      x = fastinput(); \
      v.pb(x);         \
   }
#define print(v, n) \
   inc(i, 0, n) { cout << v[i] << " "; }
#define all(x) x.begin(), x.end()
#define sortall(x) sort(all(x))
#define inc(i, a, n) for (ll i = a; i < n; i++)
#define dec(i, a, n) for (ll i = n - 1; i >= a; i--)
long long binpow(long long base, long long exp, int mod)
{
   long long res = 1;
   while (exp > 0)
   {
      if (exp % 2 == 1)
         res = (res * base) % mod;
      exp = exp >> 1;
      base = (base * base) % mod;
   }
   return res;
}
long long mod(long long x)
{
   return ((x % M + M) % M);
}

long long add(long long a, long long b)
{
   return mod(mod(a) + mod(b));
}

long long mul(long long a, long long b)
{
   return mod(mod(a) * mod(b));
}
long long int fastinput()
{
   bool negative = false;
   register int c;
   long long number = 0;
   c = _getchar_nolock();
   if (c == '-')
   {
      negative = true;
      c = _getchar_nolock();
   }
   for (; (c > 47 && c < 58); c = _getchar_nolock())
      number = number * 10 + c - 48;
   if (negative)
      number *= -1;
   return number;
}

int main()
{
   //fio;
   ll n;
   n = fastinput();
   string s;
   cin >> s;
   ll arr[4] = {0};
   inc(i, 0, s.length())
   {
      if (s[i] == 'L')
      {
         arr[0]++;
      }
      if (s[i] == 'U')
      {
         arr[2]++;
      }
      if (s[i] == 'R')
      {
         arr[1]++;
      }
      if (s[i] == 'D')
      {
         arr[3]++;
      }
   }
   cout << 2 * (min(arr[1], arr[0])) + 2 * (min(arr[2], arr[3])) << endl;

   return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
# define mod 1000000007;
int main()
{	int t,i,j,x,h,v,y;
	cin>>t;
	string str;
	cin>>str;
	 x = 0 ,y=0;
	for(i=0;i<t;i++)
	{
		if(str[i]=='L')
			x--;
		else if(str[i]=='D')
			y--;
		else if(str[i]=='R')
			x++;
		else if(str[i] == 'U')
			y++;

	}
	cout<<t-(abs(x)+abs(y));
	return 0;
}

#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
    int n;
    int x=0,y=0;
    char a[105];
    scanf("%d",&n);
    //getchar();
    int sum=0;
    scanf("%s",a);
    for(int i=0;i<n;++i)
    {
        for(int j=i+1;j<n;++j)
        {
            if(a[i]=='U'&&a[j]=='D')
            {
                sum=sum+2;
                a[i]=1;
                a[j]=1;
            }
            else if(a[i]=='D'&&a[j]=='U')
            {
               sum=sum+2;
                a[i]=1;
                a[j]=1;
            }
            else if(a[i]=='L'&&a[j]=='R')
            {
                sum=sum+2;
                a[i]=1;
                a[j]=1;
            }
            else if(a[i]=='R'&&a[j]=='L')
            {
               sum=sum+2;
                a[i]=1;
                a[j]=1;
            }
        }
    }
    printf("%d\n",sum);
    return 0;

}

#include <iostream>
#include <map>
#include <algorithm>
using namespace std;

int N; int ans = 0;
char str[105]; map<char, int> ofeach;

int main() {
    cin >> N >> str;
    for (int i=0; i<N; i++) {
        ofeach[str[i]]++;
    }
    ans += min(ofeach['D'], ofeach['U']);
    ans += min(ofeach['R'], ofeach['L']);
    cout << ans * 2;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
char c[150];
int a[150];
int main()
{
	memset(a,0,sizeof(a));
	int n;
	scanf("%d",&n);
	getchar();
	for(int i=0;i<n;i++)
	{
		scanf("%c",&c[i]);
		a[c[i]]++;
	}
	printf("%d\n",2*(min(a['U'],a['D'])+min(a['R'],a['L'])));
}

#include <algorithm>
#include <cmath>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <climits>
#define sync                                                                   \
        ios_base::sync_with_stdio(0);                                                \
        cin.tie(0);                                                                  \
        cout.tie(0)
#define ss second
#define ff first
#define ll long long
#define mp make_pair
#define endl "\n"
#define pb push_back
#define ld long double
#define M_PI 3.14159265358979323846
#define puss vector
#define ull unsigned long long
double EPS = 0.00001;
const ll INF = 1000000007;
using namespace std;

int main() {
        int n;
        cin>>n;
        string s;
        cin>>s;
        int ans=0;
        vector<int> a(500, 0);
        for (int i=0;i<n;i++){
                a[s[i]]++;
        }
        ans=min(a['D'], a['U'])*2+min(a['R'], a['L'])*2;
        cout<<ans;

}

#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
	string a;
	int  y2 = 0, i, n, x2 = 0, x1 = 0, y1 = 0;
	cin >> n;
		cin >> a;
	for (i = 0; i < a.length(); i++)
	{
		if (a[i] == 'U')
			y1++;
		else if (a[i] == 'D')
			y2++;
		else if (a[i] == 'L')
			x1++;
		else if (a[i] == 'R')
			x2++;
	}
	cout << (2*min(y1,y2)+2*min(x1,x2));
}

#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main()
{
	int n;
	int x = 0, y = 0;
	string orders;

	cin >> n;
	cin >> orders;

	for (int i = 0; i < orders.size(); ++i)
	{
		switch (orders[i])
		{
			case 'R': x++; break;
			case 'L': x--; break;
			case 'U': y++; break;
			case 'D': y--; break;
		}
	}
	cout << n - abs(x) - abs(y) << endl;

	//system("pause");
	return 0;
}

#include<iostream>
#include<string>
#include<cmath>
using namespace std;
int f[4];
string A;
int main(){
  int N;
  cin>>N;
  cin>>A;
  for(int i=0; i<A.length(); i++){
    if(A[i]=='L') f[0]++;
    if(A[i]=='R') f[1]++;
    if(A[i]=='U') f[2]++;
    if(A[i]=='D') f[3]++;
  }
  cout<<(min(f[0],f[1])+min(f[2],f[3]))*2;
  return 0;
}

#include<iostream>
using namespace std;
#include <cstring>
#include <stack>
#include <algorithm>
int N ;
int U, D, L, R;
int ans;
int main(){

    cin>>N;
    char p;
    for(int i = 0 ; i < N ; i++ ){
        cin>>p;
        if(p =='U')  U++ ;
        if(p =='D')  D++;
        if(p =='L')  L++;
        if(p =='R')  R++;
        }
    if(U!=0&&D!= 0)
        ans +=min(U,D)*2;

    if(L!=0&&R!= 0)
        ans+=min(L,R)*2;
    cout<< ans;

}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    string arr;
    cin>>arr;
    int u=0,l=0,d=0,r=0;
    int result=0;

    for(int i=0;i<n;i++){
        if(arr[i]=='U'){
            u++;
        }
        else if(arr[i]=='D'){
            d++;
        }
        else if(arr[i]=='L'){
            l++;
        }
        else if(arr[i]=='R'){
            r++;
        }
    }
    if(d>u)
        result=result+2*u;
    else
        result=result+2*d;
    if(l>r)
        result=result+2*r;
    else
        result=result+2*l;

        printf("%d\n",result);

    return 0;
}

#include<bits/stdc++.h>

using namespace std;

int main()
{
    int n, u=0, d=0, l=0, r=0;
    string s;
    cin>>n>>s;

    for(int i=0;i<n;i++)
    {
        if(s[i]=='L')
            l++;
        else if(s[i]=='R')
            r++;
        else if(s[i]=='U')
            u++;
        else if(s[i]=='D')
            d++;
    }
    cout<<min(l, r)*2+min(u, d)*2;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
int r,l,u,d;
int main(){
	int n;
	cin >> n;
	string s;
	cin >> s;
	for(int i = 0;i < n;++i){
		if(s[i] == 'R') r++;
		else if(s[i] == 'L') l++;
		else if(s[i] == 'U') u++;
		else if(s[i] == 'D') d++;
	}
	cout << 2 * (min(r,l) + min(u,d)) << "\n";
	return 0;
}

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
    int n;
    cin>>n;
    char a[n];
    int tl=0;
    int tr=0;
    int tu=0;
    int td=0;
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(a[i]=='L')
            tl++;
        else if(a[i]=='R')
            tr++;
        else if(a[i]=='U')
            tu++;
        else if(a[i]=='D')
            td++;
    }
    int col;
    int row;
    if(tl<tr)
        row=tl;
    else
        row=tr;
    if(tu<td)
        col=tu;
    else
        col=td;
    cout<<2*(row+col);
    return 0;
}

#include<iostream>
using namespace std;
main ()
{
    int n;
    int u=0;
    int d=0;
    int r=0;
    int l=0;
    cin>>n;
    string s;
    cin>>s;
    for(int i=0;i<n;i++)
    {
        if(s[i]=='U')
        {
            u++;
        }
        if(s[i]=='D')
        {
            d++;
        }
        if(s[i]=='R')
        {
            r++;
        }
        if(s[i]=='L')
        {
            l++;
        }
    }
    int poz=r*1+l*-1;
    int pion=u*1+d*-1;
    if(poz<0)
        poz=poz*-1;
    if(pion<0)
        pion=pion*-1;
    int licz=n-poz-pion;
    cout<<licz;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,a,n) for(int i=(a);i<(n);++i)
#define per(i,a,n) for(int i=(n-1);i>=(a);--i)
#define pb push_back
const int Inf=1e9;
#define N 1000010
#define M 26

int main(){
    ios::sync_with_stdio(0);
    string str;
    int n;
    cin>>n;
    cin>>str;
    int x,y;
    x=y=0;
    int ans=0;
    int a,b,c,d;
    a=b=c=d=0;
    rep(i,0,n){
        if(str[i]=='L') ++a;
        else if(str[i]=='R')++b;
        else if(str[i]=='U') ++c;
        else if(str[i]=='D') ++d;

    }
    cout<<min(a,b)*2+min(c,d)*2;
    return 0;
}

#include <bits/stdc++.h>

#define ll int
#define fort(i,a,b) for(ll i=(a);i<=(b);++i)

using namespace std;

string s;
ll n,f[203][203][103],ans[203][203][103];

ll px(ll x,ll i){
    if (s[i-1]=='L') x--;else
    if (s[i-1]=='R') x++;
    return x;
}

ll py(ll y,ll i){
    if (s[i-1]=='U') y++;else
    if (s[i-1]=='D') y--;
    return y;
}

ll lui(ll x,ll y,ll i){
    if (f[x][y][i]!=-1)
        return f[x][y][i];
    if (i>n)
        return f[x][y][i]=(x==100&&y==100);
    ll xx=px(x,i);
    ll yy=py(y,i);
    ll t=lui(xx,yy,i+1);
    ll t1=lui(x,y,i+1);
    if (t==1) ans[i][x][y]=max(ans[i][x][y],ans[i+1][xx][yy]+1);
    if (t1==1) ans[i][x][y]=max(ans[i][x][y],ans[i+1][x][y]);
    return f[x][y][i]=max(t,t1);
}

int main(){
    //freopen("t.inp","r",stdin);
    //freopen("t.out","w",stdout);
    ios_base::sync_with_stdio(false);
    cin>>n;
    cin>>s;
    memset(f,-1,sizeof(f));
    lui(100,100,1);
    cout<<ans[1][100][100];
    return 0;
}

#include <iostream>
#include <string>
using namespace std;
int main()
{
	int x, y, n;
	string S;
	cin >> n;
	cin >> S;
	x = 0;
	y = 0;
	for (int i = 0; i < S.length(); ++i)
	{
		if (S[i] == 'U')
			y++;
		if (S[i] == 'D')
			y--;
		if (S[i] == 'L')
			x--;
		if (S[i] == 'R')
			x++;
	}
	int ans = S.length() - abs(x) - abs(y);
	if (ans > 0)
		cout << ans;
	else
		cout << "0";
	return 0;
}

#include <iostream>
#include<string>
using namespace std;

int main()
{

    int arr[4];
    int n;
    string str;
    while(cin>>n){
        cin>>str;
     for(int i=0;i<4;i++)arr[i]=0;
     for(int i=0;i<str.size();i++)
         if(str[i]=='U')arr[0]++;
         else if(str[i]=='D')arr[1]++;
         else if(str[i]=='R')arr[2]++;
         else if(str[i]=='L')arr[3]++;

    cout<<((min(arr[0],arr[1])*2)+(min(arr[2],arr[3])*2))<<endl;
    }
    return 0;
}

#include<bits/stdc++.h>
using namespace std;

int main()
{
	int a=0,b=0,c=0,d=0,n;char p;
	scanf("%d\n",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%c",&p);
		if(p=='L')a++;
		if(p=='R')b++;
		if(p=='U')c++;
		if(p=='D')d++;
	}
	printf("%d",2*(min(a,b)+min(c,d)));
	return 0;
}

#include <bits/stdc++.h>

using namespace std;
typedef long long int lli;
typedef long long ll;
const int mn = 1e5 + 5;

string s;
std::map<char, int> f;

int main() {
	int n;
	cin >> n;
	cin >> s;
	int x, y;
	x = 0; y = 0;
	for(int i = 0 ; i < n; i++){
	    f[s[i]]++;
	}
	cout << min(f['U'], f['D'])*2 + min(f['L'], f['R'])*2;
}

#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n;
    cin>>n;
    string s;
    int x=0,y=0;
    cin>>s;
    int flag=0;
    for(int i=0;i<n;i++)
    {
        if(s[i]=='L')x--;
        else if(s[i]=='R')x++;
        else if(s[i]=='D')y--;
        else if(s[i]=='U')y++;
    }
    cout<<n-(abs(x)+abs(y));
    return 0;
}

#include<bits/stdc++.h>
using namespace std;

int main()
{
    int l=0,r=0,u=0,d=0,t;
    cin>>t;
    string s;
    cin>>s;
    for(int i=0;i<s.size();i++)
    {
            if(s[i]=='U')u=u+1;
            if(s[i]=='D')d=d+1;
            if(s[i]=='L')l=l+1;
            if(s[i]=='R')r=r+1;
    }
    int t1=min(l,r);
    int t2=min(u,d);
    cout<<(t1+t2)*2<<endl;
    return 0;
}

#include <bits/stdc++.h>

#define inf 0x3f3f3f3f

#define INF 0x3f3f3f3f3f3f3f3fLL

#define mod 1000000007

#define pb push_back

#define sq(x) ((x)*(x))

#define sz(a) ((int)a.size())

#define x first

#define y second

#define eps 1e-8

#define bpt(x) (__builtin_popcount(x))

#define bptl(x) (__builtin_popcountll(x))

#define bit(x, y) (((x)>>(y))&1)

#define bclz(x) (__builtin_clz(x))

#define bclzl(x) (__builtin_clzll(x))

#define bctz(x) (__builtin_ctz(x))

#define bctzl(x) (__builtin_ctzll(x))

#define PQ priority_queue<pii, vector<pii>, greater<pii> >

#define rep(i, a, b) for(int i=a; i<b; i++)

using namespace std;

typedef long long INT;

typedef vector<int> VI;

typedef pair<int, int> pii;

typedef pair<INT, INT> PII;

typedef pair<pii, int> ppi;

typedef double DO;

template<typename T, typename U> inline void smin(T &a, U b) {if (a>b) a=b;}

template<typename T, typename U> inline void smax(T &a, U b) {if (a<b) a=b;}

template<class T>inline void gn(T &x) {char c, sg=0; while (c=getchar(), (c>'9' || c<'0') && c!='-');for((c=='-'?sg=1, c=getchar():0), x=0; c>='0' && c<='9'; c=getchar()) x=(x<<1)+(x<<3)+c-'0';if (sg) x=-x;}

template<class T>inline void print(T x) {if (x<0) {putchar('-');return print(-x);}if (x<10) {putchar('0'+x);return;} print(x/10);putchar(x%10+'0');}

int power(int a, int b, int m, int ans=1) {

	for (; b; b>>=1, a=1LL*a*a%m) if (b&1) ans=1LL*ans*a%m;

	return ans;

}

#if ( ( _WIN32 || __WIN32__ ) && __cplusplus < 201103L)

    #define lld "%I64d"

#else

    #define lld "%lld"

#endif

char s[111];

int cnt[1111];

int main() {

#ifndef ONLINE_JUDGE

	freopen("in.in", "r", stdin);

	freopen("out.out", "w", stdout);

	int _time=clock();

#endif

	int n;

	cin >> n;

	scanf("%s", s);

	for(int i=0; i<n; i++) cnt[s[i]]++;

	cout <<2*min(cnt['D'], cnt['U']) + 2*min(cnt['L'] , cnt['R']) << endl;

#ifndef ONLINE_JUDGE

	cerr<<(int)(clock()-_time)<<endl;

#endif

	return 0;

}

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main() {
	// your code goes here
	int n;
	cin>>n;

	string s;
	cin>>s;

	int l=0,r=0,d=0,u=0,x=0,y=0,z=0;

	for(int i=0;i<s.length();i++)
	{
		if(s[i]=='L')
			l++;
		else if(s[i]=='U')
			u++;
		else if(s[i]=='D')
			d++;
		else
			r++;
	}
	//if(l && r && u && d)
	//{
	//cout<<l<<r<<u<<d<<endl;
		x=min(l,min(r,min(u,d)));
		y=min(l,r)-x;
		z=min(u,d)-x;
		x*=4;
		y*=2;
		z*=2;
		cout<<x+y+z;
	//}

	return 0;
}

#include <bits/stdc++.h>
#include <math.h>
#include <iterator>
#include <map>
#include <stack>
#include <list>
#include <cmath>
#include <queue>
using namespace std;
#define fo(i, n) for (ll i = 0; i < n; ++i)
#define ll long long
#define mod 1000000007
void sor(vector<ll> &x)
{
    sort(x.begin(), x.end());
}

void rev(vector<ll> &x)
{
    reverse(x.begin(), x.end());
}

ll gcd(ll x, ll y)
{
    if (y == 0)
    {
        return x;
    }
    return gcd(y, x % y);
}

list<ll> a[5];
void bfs(int src)
{
    queue<int> q;
    bool *vis = new bool[5 + 1]{0};
    q.push(src);
    vis[src] = true;
    while (!q.empty())
    {
        int node = q.front();
        cout << node << " ";
        q.pop();
        for (int n : a[node])
        {
            if (!vis[n])
            {
                q.push(n);
                vis[n] = true;
            }
        }
    }
}

ll max(ll x, ll y)
{
    if (x > y)
    {
        return x;
    }
    else
    {
        return y;
    }
}

ll min(ll x, ll y)
{
    if (x > y)
    {
        return y;
    }
    else
    {
        return x;
    }
}

void primeFactors(ll n, vector<ll> &vec)
{

    while (n % 2 == 0)
    {
        vec.push_back(2);
        n = n / 2;
    }

    for (ll i = 3; i <= sqrt(n); i = i + 2)
    {
        while (n % i == 0)
        {
            vec.push_back(i);
            n = n / i;
        }
    }

    if (n > 2)
        vec.push_back(n);
}

ll lcm(ll x, ll y)
{
    return x * y / gcd(x, y);
}

ll g(ll x)
{
    for (ll i = 2; i <= sqrt(x); i++)
    {
        if (x % i == 0)
        {
            return i;
        }
    }
    return 0;
}

ll bina(vector<ll> a, ll n, ll m)
{
    ll start = 0, end = n - 1;
    ll c = 0;
    if (m >= a[n - 1])
    {
        return n;
    }
    while (start <= end)
    {
        ll mid = (start + end) / 2;
        if (m >= a[mid])
        {
            c = mid + 1;
            start = mid + 1;
        }
        else
        {
            end = mid - 1;
        }
    }
    return c;
}
ll binarySearch(vector<ll> arr, ll l, ll r, ll x)
{
    if (r >= l)
    {
        ll mid = l + (r - l) / 2;
        if (arr[mid] == x)
            return mid;
        if (arr[mid] > x)
            return binarySearch(arr, l, mid - 1, x);
        return binarySearch(arr, mid + 1, r, x);
    }

    return 0;
}
int subArraylen(ll arr[], ll n, ll K)
{
    // Stores the frequency of
    // prefix sums in the array
    unordered_map<int, int> mp;

    mp[arr[0]] = 0;

    for (int i = 1; i < n; i++)
    {

        arr[i] = arr[i] + arr[i - 1];
        mp[arr[i]] = i;
    }

    // Initialize len as INT_MAX
    int len = INT_MAX;

    for (int i = 0; i < n; i++)
    {

        // If sum of array till i-th
        // index is less than K
        if (arr[i] < K)

            // No possible subarray
            // exists till i-th index
            continue;

        else
        {

            // Find the exceeded value
            int x = arr[i] - K;

            // If exceeded value is zero
            if (x == 0)
                len = min(len, i);

            if (mp.find(x) == mp.end())
                continue;
            else
            {
                len = min(len, i - mp[x]);
            }
        }
    }

    return len;
}

ll prime(ll n)
{
    for (ll i = 2; i <= sqrt(n); i++)
    {
        if (n % i == 0)
        {
            return i;
        }
    }
    return 0;
}

ll nextPowerOf2(ll n)
{
    ll p = 1;
    if (n && !(n & (n - 1)))
        return n;

    while (p < n)
        p <<= 1;

    return p;
}
ll countBits(ll number)
{
    // log function in base 2
    // take only integer part
    return (ll)log2(number) + 1;
}

ll comb(ll c, ll n)
{
    ll num = 1, d = 1;
    for (ll i = c; i > max(n, c - n); i--)
    {
        num *= i;
    }
    for (ll i = 2; i <= min(n, c - n); i++)
    {
        d *= i;
    }
    return (num / d);
}
ll countDivisors(ll n)
{
    ll cnt = 0;
    for (ll i = 1; i <= sqrt(n); i++)
    {
        if (n % i == 0)
        {
            // If divisors are equal,
            // count only one
            if (n / i == i)
                cnt++;

            else // Otherwise count both
                cnt = cnt + 2;
        }
    }
    return cnt;
}
void solve()
{
    ll n;
    cin >> n;
    string s;
    cin >> s;
    // reverse(s.begin(), s.end());
    vector<ll> a;
    a.push_back(0);

    cout << (min(count(s.begin(), s.end(), 'U'), count(s.begin(), s.end(), 'D')) + min(count(s.begin(), s.end(), 'R'), count(s.begin(), s.end(), 'L'))) * 2;
}

vector<ll> adj[105];
ll mat[105];
void dfs(ll v, ll p)
{
    mat[v] = mat[p] + 1;
    for (auto u : adj[v])
        if (u != p)
            dfs(u, v);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t;
    t = 1;
    //cin >> t;
    fo(tt, t)
    {
        solve();
    }

    return 0;
}

//0 3 1 0 5 2 6
//0 0 1 2 3 5 6
/*
5

binary for a no just greater than that no:

ll start = 0, end = n - 1;
        ll c = 0;
        while (start <= end)
        {
            ll mid = (start + end) / 2;
            if (m >= a[mid])
            {
                c = mid + 1;
                start = mid + 1;
            }
            else
            {
                end = mid - 1;
            }
        }
        cout << c << endl;

        */

#include <iostream>
#include <string>

using namespace std;

void main ()
{
	int n, i, u=0, d=0, j=0, l=0, r=0, x = 0, y = 0;
	char a[101];

	cin >> n;

	for (i = 1; i <= n; i++)
		cin >> a[i];

	for (i = 1; i <= n; i++)
	{
		if (a[i]=='U')
			u++;
		else
			if (a[i]=='D')
				d++;
			else
				if (a[i]=='L')
					l++;
				else
					if (a[i]=='R')
						r++;
	}
	j = n - abs(l - r) - abs (u - d);
	cout << j;
}

#include <iostream>
#include <memory.h>
#include <string.h>
#include <map>
using namespace std;
int num[105];
map<char,int> mp;
int main(){
	string command;
	int len;
	cin>>len;
	cin>>command;
	mp['L']=1;
	mp['R']=2;
	mp['U']=3;
	mp['D']=4;
	for(int i=0;i<len;i++){
		num[mp[command[i]]]++;
	}
	cout<<min(num[1],num[2])*2+min(num[3],num[4])*2<<endl;
}

#include <bits/stdc++.h>

using namespace std;

int n,A[1005];
string s;

int main(){

    cin>>n;
    cin>>s;

    int x = 0, y = 0, x1 = 0 , y1 = 0;
    int ans = 0;
        for (int i = 0 ; i < s.size() ; i++){
            if (s[i] == 'U')y++;
            if (s[i] == 'D')y1++;
            if (s[i] == 'L')x1++;
            if (s[i] == 'R')x++;
        }
    ans = min(y,y1);
    int ans1 = min(x1,x);

    cout<<ans * 2 + ans1 * 2<<"\n";
return 0;

}

#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <string.h>
using namespace std;

int main()
{
	int n;
	cin >> n;
	int max=0;
	int j2=0;
	char a;
	int X=0,Y=0,D=0,U=0,L=0,R=0;
	for(int i=1;i<=n;i++)
	{
		cin >> a;
		if (a =='U') {U+=1;};
		if (a =='D') {D+=1;};
		if (a =='L') {L+=1;};
		if (a =='R') {R+=1;};
};
	if (U<D) max+=2*U; else max+=2*D;
	if (L<R) max+=2*L; else max+=2*R;
	cout << max;
};

#include<stdio.h>
#include<string.h>
char s[101];
int main()
{
    int n;
   scanf("%d",&n);

   scanf("%s",s);

    int a=0,b=0;
    for(int i=0;i<n;i++)
    {
        if(s[i]=='L')a--;
        else if(s[i]=='R')a++;
        if(s[i]=='U')b++;
        else if(s[i]=='D')b--;
    }
    int ans=(a>0)?a:-a;
    ans+=(b>0)?b:-b;
    printf("%d",n-ans);
    return 0;
}

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define  mod  1e9+7
#define MOD 998244353
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define t() int test;cin>>test;while(test--)
#define que_max priority_queue <int>
#define ii pair<int,int>
#define IOS ios::sync_with_stdio(0); cin.tie(0);
#define endl "\n"
typedef tree<int,null_type, less<int>,rb_tree_tag, tree_order_statistics_node_update> pbds;
#define TRACE

int main()
{
    int n;
    cin>>n;

    string z;
    cin>>z;
    int x=0,y=0;
    for(int i=0;i<n;i++)
    {
        if(z[i]=='U')
        y++;
        else if(z[i]=='D')
        y--;
        else if(z[i]=='R')
        x++;
        else
        x--;
    }cout<<n-abs(x)-abs(y);

}

#include<iostream>
using namespace std;

int n,c[256];
string s;

int main()
{
	cin>>n>>s;
	for(int i=0;i<n;i++)
		c[s[i]]++;
	cout<<min(c['U'],c['D'])*2+min(c['L'],c['R'])*2;
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	string s;
	cin>>s;
	int sum=0;
	int l=0,r=0,d=0,u=0;

	for(int k=0;k<n;k++){
		if(s[k]=='L')l++;
		if(s[k]=='R')r++;
        if(s[k]=='D')d++;
		if(s[k]=='U')u++;
		}
	sum=min(l,r)+min(d,u);
	cout<<sum*2;

	return 0;
}

#include<iostream>
using namespace std;
int main()
{
	int n, u=0, d=0, l=0, r=0, k=0, m=0;
	cin >> n;
	char s[101];
	cin >> s;
	for(int i=0; i<n; i++){
		switch (s[i])
		{
		case 'U': u++; break;
		case 'D': d++; break;
		case 'L': l++; break;
		case 'R': r++; break;
		default:
			break;
		}
	}
	if(u!=0&&d!=0)m=(u>d)?d:u;
	if(l!=0&&r!=0)k=(r>l)?l:r;
	cout<<2*(k+m);
	return 0;
}

#include <bits/stdc++.h>
#define ll long long
#define gcd(a,b) __gcd(a,b)
#define pi 3.1415926536
using namespace std;
int lcm(int a,int b){return (a*b)/(gcd(a,b));}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	//----↯ Enter your code here ↯----
	int n,u,d,r,l,ans=0;cin>>n;string a;cin>>a;u=d=r=l=0;
	for(int i=0;i<n;i++)
	{
		if(a[i]=='U')u++;
		else if(a[i]=='D')d++;
		else if(a[i]=='R')r++;
		else l++;
	}
	ans+=min(l,r)*2;
	l-=min(l,r);r-=min(l,r);
	////////////////////////
	ans+=min(u,d)*2;
	u-=min(u,d);d-=min(u,d);
	////////////////////////
	cout<<ans<<"\n";
}

#include<bits/stdc++.h>
std::string s;
int main(){
    int n,l=0,r=0,u=0,d=0;scanf("%d",&n);std::cin>>s;
    for(register int i=0;i<s.size();++i){
        if(s[i]=='L')++l;
        if(s[i]=='R')++r;
        if(s[i]=='U')++u;
        if(s[i]=='D')++d;
    }
    printf("%d",2*(std::min(l,r)+std::min(u,d)));
}

#include <iostream>
#include <string>
#include <math.h>

int main()
{
    int n = 0;
    std::cin >> n;
    std::cin.get();
    std::string command;
    getline(std::cin, command);
    int countD = 0, countU = 0, countL = 0, countR = 0;
    for(int i(0); i < n; i++)
    {
        if(command[i] == 'D')
            countD++;
        if(command[i] == 'U')
            countU++;
        if(command[i] == 'L')
            countL++;
        if(command[i] == 'R')
            countR++;
    }
    std::cout << 2*(std::min(countR,countL)+std::min(countD, countU)) << std::endl;
    return 0;
}

#include<bits/stdc++.h>
#define all(s) (s).begin(),(s).end()
using namespace std;
int main()
{
	ios::sync_with_stdio(0),cin.tie(0);
	int n;
	string s;
	cin>>n>>s;
	cout<<2*min(count(all(s),'L'),count(all(s),'R'))+2*min(count(all(s),'D'),count(all(s),'U'));
}

#include <iostream>
#include <vector>
#include <fstream>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <iomanip>
using namespace std;

int main(){

	int n;
	cin >> n;
	string s;
	cin >> s;
	int x = 0, y = 0;
	int index = 0;
	for (int i = 0; i < n; i++)
		switch(s[i]){
			case 'U': y++; break;
			case 'D': y--; break;
			case 'L': x--; break;
			case 'R': x++; break;
		}

	cout << n - abs(x) - abs(y);
	return 0;
}

#include <bits/stdc++.h>
using namespace std;

int main()
{

    int n; cin>>n;
    string s; cin>>s;
    char c;

    int u=0,d=0,l=0,r=0;

    for(int i=0;i<n;i++)
    {
        c=s[i];

        if(c=='L')
        {
            l++;
        }
        else if(c=='R')
        {
            r++;
        }
        else if(c=='U')
        {
            u++;
        }
        else if(c=='D')
        {
            d++;
        }
    }

    cout<<min(u,d)*2 + min(l,r)*2<<endl;

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
map<char,int> operation={{'U',0},{'D',1},{'L',2},{'R',3}};
int movement[4]={0,0,0,0};
int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        char a;
        cin>>a;
        movement[operation[a]]++;
    }
    cout<<(2*min(movement[0],movement[1]))+(2*min(movement[2],movement[3]));
}

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>

using namespace std;

int main() {
	string s1;
	getline(cin, s1);
	string s;
	getline(cin, s);
	int x = 0, y = 0;
	for (int i = 0; i < s.length(); ++i) {
		if (s[i] == 'L') {
			--x;
		}
		if (s[i] == 'R') {
			++x;
		}
		if (s[i] == 'D') {
			--y;
		}
		if (s[i] == 'U') {
			++y;
		}
	}
	cout <<s.length() - abs(x) - abs(y);
 //   system("pause");
	return 0;
}

#include <bits/stdc++.h>

using namespace std;
int main()
{
    int n;
    string s;
    cin>>n>>s;
    int x = 0 , y = 0,l = 0, u = 0 , r = 0 , d = 0;

    for(int i = 0 ; i < s.size() ;i++)
    {
        if(s[i] == 'U') u++;
        else if(s[i] == 'R')    r++;
        else if(s[i] == 'D')    d++;
        else                    l++;
    }
    x = min(l,r);
    y = min(u,d);

    if(l == 0 && r == 0) cout<<2*y<<endl;
    else if(u == 0 && d == 0) cout<<2*x<<endl;
    else
        cout<<2*x+2*y<<endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const ll N = 2e5+100;
int n,m,k;
int x,y;
vector<int> gr[N];
set<int> fx;
string s;
int main(){
    scanf("%d",&n);
    cin>>s;
    x = 0,y = 0;
    int ans =0;
    bool f = false;
    int i;
    for(i=0;i<n;++i){
        if(s[i]=='L')x += 1;
        else if(s[i] == 'R')x-=1;
        else if(s[i] == 'U')y+=1;
        else y -= 1;
    }
    ans = n-abs(x)-abs(y);
    cout<<ans<<endl;
}

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
    int vis[5],n;
    char str[110];
    memset(vis,0,sizeof(vis));
    scanf("%d",&n);
    scanf("%s",str);
    for(int i=0; str[i]!='\0' ;i++)
    {
        if(str[i]=='U')
        {
            vis[1]++;
        }
        else if(str[i]=='D')
        {
            vis[2]++;
        }
        else if(str[i]=='L')
        {
            vis[3]++;
        }
        else
            vis[4]++;
    }
    int ans=0;
    ans+=min(vis[1],vis[2])*2+min(vis[3],vis[4])*2;
    printf("%d\n",ans);
    return 0;
}

#include<iostream>
#include<string>
using namespace std;
void main()
{
	int n,var1,var2, cnt1 = 0, cnt2 = 0, cnt3 = 0, cnt4 = 0;
	string a;
	cin >> n;
	cin >> a;
	for (int i = 0; i<n; i++){

		if (a[i] == 'U') cnt1++;

		if (a[i] == 'D') cnt2++;

		if (a[i] == 'R') cnt3++;

		if (a[i] == 'L') cnt4++;

	}
	if (cnt1 > cnt2)var1 = cnt2;
	else var1 = cnt1;
	if (cnt3 > cnt4)var2 = cnt4;
	else var2 = cnt3;

	cout << 2 * var1 + 2 * var2;

}

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{
    int n,i,d=0,u=0,r=0,l=0;
    char s[1005];
    scanf("%d",&n);
    scanf("%s",s);
    int ans=0;
    for(i=0;i<n;i++){
        if(s[i]=='L')l++;
        else if(s[i]=='R')r++;
        else if(s[i]=='U')u++;
        else if(s[i]=='D')d++;
    }
    int x=min(l,r);
    int y=min(u,d);
    if(l==0&&r==0)
    printf("%d\n",2*y);
    else if(u==0&&d==0)
    printf("%d\n",2*x);
    else
    printf("%d\n",2*x+2*y);
}

#include <iostream>
#include <cstdio>
using namespace std;
string ch;
int L,R,U,D;
int main()
{
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	int n;
	cin>>n>>ch;
	for(int i=0;i<n;++i)
	{
		if(ch[i]=='L') ++L;
		if(ch[i]=='R') ++R;
		if(ch[i]=='U') ++U;
		if(ch[i]=='D') ++D;
	}
	printf("%d",2*(min(L,R)+min(U,D)));
	return 0;
}

#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cmath>
#include <algorithm>
#include <bitset>
#include <list>
#define INF (int)1e9
#define MAX (int)1e7
using namespace std;
typedef long long llong;
typedef unsigned long long uint64;
typedef vector<int> VI;
typedef vector<VI> VII;

struct Point {
    int x,y;
};

int main() {

    int N;
    Point p;
    p.x = 0;
    p.y = 0;
    string steps;
    cin >> N >> steps;

    for(int i = 0; i < N; i++) {
        if (steps[i] == 'U')
            p.y += 1;
        else if (steps[i] == 'D')
            p.y -= 1;
        else if (steps[i] == 'L')
            p.x -= 1;
        else if (steps[i] == 'R')
            p.x += 1;
    }

    int dx = abs(p.x);
    int dy = abs(p.y);
    cout << N - dx - dy << endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    string A;
    cin>>n;
    cin>>A;
    int x=0;
    int y=0;
    for(int i=0;i<n;i++)
    {
        if(A[i]=='U')
            y++;
        else if(A[i]=='D')
            y--;
        else if(A[i]=='R')
            x++;
        else if(A[i]=='L')
            x--;
    }
    int S=abs(x) + abs(y);
    cout<<n-S<<endl;
    return 0;
}

#include "bits/stdc++.h"
using namespace std;
int L, D, U, R;

int main()
{
        int n;
        cin >> n;
        string s;
        cin >> s;
        for(auto x : s) {
                if(x == 'L')L++;
                if(x == 'D')D++;
                if(x == 'U')U++;
                if(x == 'R')R++;
        }
        cout << min( U, D ) * 2 + min( L, R ) * 2 << "\n";

        return 0;
}

#include <iostream>
using namespace std;

int lrdu[4];
char b[101];

enum
{
	LEFT,
	RIGHT,
	DOWN,
	UP
};

int min(int a, int b)
{
	if (a < b)
	{
		return a;
	}
	return b;
}

int main()
{
	int n;
	scanf("%d", &n);

	scanf("%s", b);

	for (int i = 0; i < n; i++)
	{
		switch (b[i])
		{
		case 'L':
			lrdu[LEFT]++;
			break;
		case 'R':
			lrdu[RIGHT]++;
			break;
		case 'D':
			lrdu[DOWN]++;
			break;
		case 'U':
			lrdu[UP]++;
			break;
		}
	}
	printf("%d\n", min(lrdu[LEFT], lrdu[RIGHT]) * 2 + min(lrdu[DOWN], lrdu[UP]) * 2);

	return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,cnt=0,x=0,y=0,x1=0,y1=0;
    cin>>n;
    char b[110],a;
    for(int i=0; i<n; i++)
    {
        cin>>b[i];
    }
    for(int i=0; i<n; i++)
    {
        x=0;
        y=0;
        for(int j=i; j<n; j++)
        {
            a=b[j];
            if(a=='U')
            {
                y=y+1;
            }
            if(a=='D')
            {
                y=y-1;
            }
            if(a=='L')
            {
                x--;
            }
            if(a=='R')
            {
                x++;
            }
            if(x==0&&y==0)
            {
                cnt=max(cnt,j+1);
                break;
            }
        }
    }
    cout<<cnt<<endl;
    return 0;
}

#include "iostream"
#include "fstream"
#include "algorithm"
#include "iomanip"
#include "stack"
#include "queue"
#include "string"
#include "vector"
#include "iterator"
#include "cmath"

#define forn(i,n) for(int i=0; i<n;i++)
#define rforn(i,n) for(int i=n-1; i>=0;i--)

using namespace std;

int main()
{
	int L = 0, R = 0, U = 0, D = 0;

	string move;

	cin >> move;

	for (int i = 0; i < move.size(); i++)
	{
		if (move[i] == 'L')
			L++;
		if (move[i] == 'R')
			R++;
		if (move[i] == 'U')
			U++;
		if (move[i] == 'D')
			D++;
	}

	cout << 2*min(L, R) + 2*min(U, D);
}

#include <iostream>
#include<algorithm>
#include<string.h>
#include<vector>
#include<sstream>
using namespace std;
int main()
{
    int n;string s;float dp[4]={1,-1,-2.4,2.4};
    cin>>n>>s;
    float sum=0,p,m=0;
    for(int i=0;i<s.length();i++)
    {
        if(s[i]=='U')sum+=dp[0],p++;
        if(s[i]=='D')sum+=dp[1],p++;
        if(s[i]=='L')sum+=dp[2],p++;
        if(s[i]=='R')sum+=dp[3],p++;
        if(sum==0)
            m=max(p,m);
    }
    cout<<m;
}

#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main()
{
    int n, kol = 0;
    cin >> n;
    string S, S1;
    cin >> S;
    vector <int> X;
    vector <int> Y;
    X.push_back(0);
    Y.push_back(0);
    for(int i = 1; i <= n; i++)
    {
        S1 = S[i-1];
        if(S1 == "U")
        {
            X.push_back(X[X.size()-1]);
            Y.push_back(Y[Y.size()-1]+1);
        }
        if(S1 == "D")
        {
            X.push_back(X[X.size()-1]);
            Y.push_back(Y[Y.size()-1]-1);
        }
        if(S1 == "L")
        {
            X.push_back(X[X.size()-1]-1);
            Y.push_back(Y[Y.size()-1]);
        }
        if(S1 == "R")
        {
            X.push_back(X[X.size()-1]+1);
            Y.push_back(Y[Y.size()-1]);
        }
        if(X[X.size()-1] == 0 && Y[Y.size()-1] == 0)
            kol = i;
    }
    cout << kol;
	return 0;

}

#include<iostream>
using namespace std;
int main(){
	int n,u=0,l=0,step=0;
	char str[110];
	cin>>n;
	cin>>str;
	for(int i=0;i<n;i++){
//		cin>>str[i];
		if(str[i]=='U'){
			u++;
		}
		else if(str[i]=='D'){
			u--;
		}
		else if(str[i]=='L'){
			l++;
		}
		else if(str[i]=='R'){
			l--;
		}

		if(u==0&&l==0){
			step=i+1;
		}
	}
//	a=(u<d)?u:d;
//	b=(l<r)?l:r;
	cout<<step;
	return 0;
}

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
    int n;
    cin>>n;
    char a[n];
    int tl=0;
    int tr=0;
    int tu=0;
    int td=0;
    int i;
    for(i=0;i<n;i++){
        cin>>a[i];
        if(a[i]=='L')
            tl++;
        else if(a[i]=='R')
            tr++;
        else if(a[i]=='U')
            tu++;
        else if(a[i]=='D')
            td++;
        if(tl==tr&&tu==td)
            break;
    }
    if(tl==tr&&tu==td)
        cout<<i+1;
    else
        cout<<0;

    return 0;
}

#include <bits/stdc++.h>
#define lp(i,n) for(int i=0;i<n;i++)
#define I int
#define LL long long
#define ULL unsigned long long
#define D double
#define F float
#define PI 3.14159
#define IO ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
bool isprime(long long n);
long long fibonacci(long long x);
long long factorial(long long x);
long long permutations(long long x,long long y);
long double combinations(long double x,long double y);

using namespace std;
void SieveOfEratosthenes(int n, bool prime[],
                         bool primesquare[], int a[])
{
    // Create a boolean array "prime[0..n]" and
    // initialize all entries it as true. A value
    // in prime[i] will finally be false if i is
    // Not a prime, else true.
    for (int i = 2; i <= n; i++)
        prime[i] = true;

    // Create a boolean array "primesquare[0..n*n+1]"
    // and initialize all entries it as false. A value
    // in squareprime[i] will finally be true if i is
    // square of prime, else false.
    for (int i = 0; i <= (n * n + 1); i++)
        primesquare[i] = false;

    // 1 is not a prime number
    prime[1] = false;

    for (int p = 2; p * p <= n; p++)
    {
        // If prime[p] is not changed, then
        // it is a prime
        if (prime[p] == true)
        {
            // Update all multiples of p
            for (int i = p * 2; i <= n; i += p)
                prime[i] = false;
        }
    }

    int j = 0;
    for (int p = 2; p <= n; p++)
    {
        if (prime[p])
        {
            // Storing primes in an array
            a[j] = p;

            // Update value in primesquare[p*p],
            // if p is prime.
            primesquare[p * p] = true;
            j++;
        }
    }
}

// Function to count divisors
int countDivisors(int n)
{
    // If number is 1, then it will have only 1
    // as a factor. So, total factors will be 1.
    if (n == 1)
        return 1;

    bool prime[n + 1], primesquare[n * n + 1];

    int a[n]; // for storing primes upto n

    // Calling SieveOfEratosthenes to store prime
    // factors of n and to store square of prime
    // factors of n
    SieveOfEratosthenes(n, prime, primesquare, a);

    // ans will contain total number of distinct
    // divisors
    int ans = 1;

    // Loop for counting factors of n
    for (int i = 0;; i++)
    {
        // a[i] is not less than cube root n
        if (a[i] * a[i] * a[i] > n)
            break;

        // Calculating power of a[i] in n.
        int cnt = 1; // cnt is power of prime a[i] in n.
        while (n % a[i] == 0) // if a[i] is a factor of n
        {
            n = n / a[i];
            cnt = cnt + 1; // incrementing power
        }

        // Calculating number of divisors
        // If n = a^p * b^q then total divisors of n
        // are (p+1)*(q+1)
        ans = ans * cnt;
    }

    // if a[i] is greater than cube root of n

    // First case
    if (prime[n])
        ans = ans * 2;

    // Second case
    else if (primesquare[n])
        ans = ans * 3;

    // Third casse
    else if (n != 1)
        ans = ans * 4;

    return ans; // Total divisors
}
long long Divisors(long long x)
{
    long long c = 0;
    for (long long i = 1; i <= x; i++)
    {
        if (x % i == 0)
        {
            c++;
        }
    }
    return c;
}
long long division(long long x)
{
    int c=0, i;
    for (i = 1; i * i < x; i++)
        if (x % i == 0)
            c += 2;

    if (i * i == x)
        c++;
    return c;
}
int countDivisors2(int n)
{
    int cnt = 0;
    for (int i = 1; i <= sqrt(n); i++)
    {
        if (n % i == 0)
        {
            if (n / i == i)
                cnt++;
            else
                cnt = cnt + 2;
        }
    }
    return cnt;
}

ULL div(ULL x)
{
    ULL counter=0,i;
    for (i=1; i*i<x; i++)
    {
        if (x%i==0)
        {
            counter+=2;
        }
    }
    if (i*i==x)
        counter++;
    return counter;

}
unsigned GCD(unsigned u, unsigned v)
{
    while ( v != 0)
    {
        unsigned r = u % v;
        u = v;
        v = r;
    }
    return u;
}
LL lcm(LL a,LL b)
{
    return (a*b)/GCD(a,b);
}

int main(){
    IO
    //bool bl = false;
    I n, y = 0, x = 0, v = 0;
    cin >> n;
    char arr[n];
    for (I i = 0; i < n; i++)
        cin >> arr[i];;
    for (I i = 0; i < n; i++){
        if (arr[i] == 'D')
            y--;
        else if (arr[i] == 'U')
            y++;
        else if (arr[i] == 'R')
            x++;
        else if (arr[i] == 'L')
            x--;
        if (x == 0 && y == 0){
            v = i + 1;
            break;
        }
    }
    cout << v;
    return 0;
}

long long factorial(long long x)
{
    long long fact=1;
    for(long long i=1; i<=x; i++)
    {
        fact*=i;
    }
    return fact;
}

long long permutations(long long x,long long y)
{
    long long fact1=1;
    for(long long i=1; i<=max(x,y); i++)
    {
        fact1*=i;
    }
    long long fact2=1;
    for(long long i=1; i<=abs(x-y); i++)
    {
        fact2*=i;
    }
    return fact1/fact2;
}

long double combinations(long double x, long double y)
{
    long long ans =1;
    for(long double i=0,w=min(y,abs(x-y)); i<w; i++)
    {
        ans *=(x-i)/(i+1);
    }
    return ans;
}

long long fibonacci(long long x)
{
    if(x==1) return 1;
    if(x==0) return 0;
    return fibonacci(x-1)+fibonacci(x-2);
}

bool isprime(long long n)
{
    if (n == 1)
        return false;
    else if (n == 2)
        return true;
    for (long long i = 2; i < n; i++)
    {
        if (n % i == 0)
        {
            return false;
        }
    }
    return true;
}

#include <iostream>
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <sstream>
#include <stdlib.h>
#define pb push_back
#define all(x) (x).begin(), x.end()
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vector<int> >
#define vll vector<long long>
#define SQ(a) (a)*(a)
#define pb push_back
#define mk make_pair
#define rep(i, a, n) for(int i = a; i < n; i++)
#define per(i, n, a) for(int i = n-1; i >= a; i--)
#define fr first
#define sc second
#define FILE "474"
#define standart 1
typedef long long ll;
typedef __int64 i64;
using namespace std;
const int INF = 1e9 + 322;
const ll LINF = 2e18 + 228;
const int MAXN = 1e5 + 228;
const int MOD = 1e9 + 7;
const double eps = 1e-14;
int n,ans,x,y;
string s;
void solve(){
    cin >> n;
    cin >> s;
    for(int i=0; i < n ;i++){
        if(s[i]=='L') x--;
        if(s[i]=='R') x++;
        if(s[i]=='U') y++;
        if(s[i]=='D') y--;
        if(x==0 && y==0) {
            ans=i+1;
        }
    }
    cout << ans;
}
int main(){
    if(!standart) {
        freopen(FILE".in", "r", stdin);
        freopen(FILE".out", "w", stdout);
    }
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int T = 1;
    while(T--)
        solve();
    return 0;
}

#include <iostream>

using namespace std;

int main() {
	int n;
	int counterU = 0;
	int counterR = 0;
	int counterD = 0;
	int counterL = 0;
	int counter = 0;
	cin >> n;
	char k[100];
	for (int i = 0; i < n; i++)
	{
		cin >> k[i];
	}
	for (int i = 0; i < n; i++)
	{
		if (k[i] == 'U')
		{
			counterU++;
		}
		if (k[i] == 'R')
		{
			counterR++;
		}
		if (k[i] == 'D')
		{
			counterD++;
		}
		if (k[i] == 'L')
		{
			counterL++;
		}
	}
	if ((counterU == counterD)&(counterR == counterL))
	{
		counter = counterU + counterR + counterD + counterL;
		cout<<counter;
	}
	else
	{
		cout << 0;
	}
	return 0;
}

#include<bits/stdc++.h>

using namespace std;

int main(){
    int n;
    cin>>n;
    string s;
    cin>>s;
    int u=0,l=0,d=0,r=0;
    for(int i=0;i<n;i++){
        if(s[i]=='U')
            u++;
        else if(s[i]=='L')
            l++;
        else if(s[i]=='R')
            r++;
        else
            d++;
    }
    cout<<min(l,min(r,min(u,d)))*4;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;

int main()
{
	int n;
	cin>>n;

	string s;
	cin>>s;

	int c1=0,c2=0;

	int count=0;

	for(int i=0;i<n;i++)
	{
		if(s[i]=='R')
			c1++;
		else if(s[i]=='L')
			c1--;
		else if(s[i]=='U')
			c2++;
		else
			c2--;

		if(c1==0 && c2==0)
		{
			count=i+1;
		}
	}

	cout<<count;

 return 0;
}

#include<bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    cin>>n;
    string s;
    cin>>s;
    int x=0,y=0,ans=0;
    for(int i=0;i<n;i++)
    {

        if(s[i] == 'U')y++;
        else if(s[i] == 'D')y--;
        else if(s[i] == 'R')x++;
        else x--;
    }
    cout<<n-x-y;
    return 0;
}

#include<bits/stdc++.h>

using namespace std;

int main(){
    int n,x=0,y=0;
    cin>>n;
    string s="";
    cin>>s;
    int mx=0;
    for(int i=0;i<n;i++)
    {
        if(s[i]=='U') y++;
        else if(s[i]=='D') y--;
        else if(s[i]=='L') x--;
        else if(s[i]=='R') x++;

        if(x==0 && y==0)
            mx=i;
    }
    if(mx>0)
        cout<<mx+1<<endl;
    else
        cout<<0<<endl;
}

#include<bits/stdc++.h>
using namespace std;

int main(){

int n,l=0,r=0,u,D,ans=0,i;
cin>>n;
char d;
for( i=0;i<n;i++)
{
 cin>>d;

if(d=='L')
{
	l++;

}
else if(d=='R')
{
	r++;

}
else if(d=='U')
{
	u++;

}
else if(d=='D')
{
	D++;

}

}
ans=min(l,r)+min(u,D);
cout<<2*ans;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,ans=0;
    char command;
    scanf("%d",&n);
    for(int i=0,x=0,y=0;i<n;i++)
    {
        scanf(" %c",&command);
        if(command=='L')
            y--;
        else if(command=='R')
            y++;
        else if(command=='U')
            x--;
        else
            x++;
        if(x==0&&y==0)
            ans=i+1;
    }
    printf("%d",ans);
    return 0;
}

#include<bits/stdc++.h>

using namespace std;

main()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    int u = 0, d = 0, l = 0, r = 0;
    int cnt = 0;
    for(int i = 0; i < s.size(); i ++)
    {
        if(s[i] == 'U'){
            u++;
        }else
        if(s[i]== 'D'){
            d++;
        }else
        if(s[i] == 'L'){
            l++;
        }else
        if(s[i] == 'R'){
            r++;
        }
    }
    if( u == d == l == r){
        cout<< u + d + l + r;
    }else
    if( l < r){
        cout << 2*l;
    }else
    if(r < l){
        cout << 2 * r;
    }else
    if(u < d){
        cout << 2 * u;
    }else
    if(d < u)
    {
        cout << 2 * d;
    }else
    {
        cout << 0;
    }
}

#include <bits/stdc++.h>
using namespace std;
map <char,long long> a;
long long n,x,y,kol;
char z;
int main()
{
  cin>>n;
  if(n%2==1)
  {
    cout<<"0";
    return 0;
  }
  for(int i=0;i<n;i++)
  {
    cin>>z;
    if(z=='U')
      y++;
    if(z=='D')
      y--;
    if(z=='L')
      x--;
    if(z=='R')
      x++;
    if(x==0&&y==0)
      kol=i+1;
  }

  cout<<kol;
}

#include<bits/stdc++.h>
#define fint register int
#define h 5001
#define p 398435
using namespace std;
int main()
{
	int n;
	cin>>n;
	char x;
	int u,d,l,r;
	for(fint i=1;i<=n;i++)
	{
		cin>>x;
		if(x=='U')
		u++;
		if(x=='D')
		d++;
		if(x=='L')
		l++;
		if(x=='R')
		r++;
	}
	cout<<2*(min(l,r)+min(u,d));
	return 0;
}

#include <bits/stdc++.h>
#define sz 30
#define sz2 70000
#define llf long long
#define inf 10000000
using namespace std ;
int main ()
{
    char s[110] ;
    llf n  , i;
    cin >> n ;
    getchar ();
    gets (s) ;
    llf x = 0 , y = 0 ;
    llf tx=  0 , ty = 0  , mx = 0;
    for (i = 0; i < n ; i++)
    {
        if (s[i]=='L')
        {
            tx-=1;
           // ty = y ;
        }
        if (s[i]=='D')
        {
            //tx = x;
            ty -= 1 ;
        }
        if (s[i]=='R')
        {
            tx+=1;
            //ty = y ;
        }
        if (s[i]=='U')
        {
            //tx=x;
            ty += 1 ;
        }
        if (tx==x && ty==y)
        {
            mx = i+1 ;
        }

    }
    cout << mx ;
    return 0;

}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,a,n) for(int i=(a);i<(n);++i)
#define per(i,a,n) for(int i=(n-1);i>=(a);--i)
#define pb push_back
const int Inf=1e9;
#define N 1000010
#define M 26

int main(){
    ios::sync_with_stdio(0);
    string str;
    int n;
    cin>>n;
    cin>>str;
    int x,y;
    x=y=0;
    int ans=0;
    rep(i,0,n){
        if(str[i]=='L') --x;
        else if(str[i]=='R') ++x;
        else if(str[i]=='U') --y;
        else if(str[i]=='D') ++y;
        if(x==0&&y==0){
            ans=max(ans,i+1);
        }
    }
    cout<<ans;
    return 0;
}

#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <set>
#include <map>
#include <deque>
#include <cmath>
#include <queue>
#include <random>
#include <bitset>
#include <time.h>
#include <string>
#include <chrono>
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
#define itn int
//#define endl '\n'
#define mp make_pair
#define pbc push_back
#define pob pop_back()
#define empb emplace_back
#define sp system("pause")
#define queuel queue<long long>
#define matrix vector<vector<ll>>
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pin(p) cin >> p.first >> p.second;
#define rev(v) reverse(v.begin(),v.end());
#define mx(v) max_element(v.begin(), v.end());
#define mn(v) min_element(v.begin(), v.end());
#define dig(c) (c >=' 0' && c <= '9') ? 1 : 0
#define sout(s, c) for(auto i : s) cout << i << c;
#define pout(p) cout << p.first << " " << p.second;
#define er(v, l, r) erase(v.begin() + l, v.begin() + r);
#define vin(v) for(ll i = 0; i < v.size(); ++i) cin >> v[i];
#define vout(v, c) for(int i = 0; i < v.size(); ++i) cout << v[i] << c;
#define pushi(v, a) for(int i = 0; i < a.size(); ++i) v.push_back(a[i]);
#define sin(s, n) for(int i = 0; i < n; ++i){int a; cin >> a; s.insert(a);}
#define fastio() ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0);
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
using namespace std;
/*▄███████▀▀▀▀▀▀███████▄
░▐████▀▒ЗАПУСКАЕМ▒▀██████▄
░███▀▒▒▒▒▒ДЯДЮ▒▒▒▒▒▒▀█████
░▐██▒▒▒▒▒БОГДАНА▒▒▒▒▒████▌
░▐█▌▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒████▌
░░█▒▄▀▀▀▀▀▄▒▒▄▀▀▀▀▀▄▒▐███▌
░░░▐░░░▄▄░░▌▐░░░▄▄░░▌▐███▌
░▄▀▌░░░▀▀░░▌▐░░░▀▀░░▌▒▀▒█▌
░▌▒▀▄░░░░▄▀▒▒▀▄░░░▄▀▒▒▄▀▒▌
░▀▄▐▒▀▀▀▀▒▒▒▒▒▒▀▀▀▒▒▒▒▒▒█
░░░▀▌▒▄██▄▄▄▄████▄▒▒▒▒█▀
░░░░▄██████████████▒▒▐▌
░░░▀███▀▀████▀█████▀▒▌
░░░░░▌▒▒▒▄▒▒▒▄▒▒▒▒▒▒▐
░░░░░▌▒▒▒▒▀▀▀▒▒▒▒▒▒▒▐*/
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
//++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++--++
const ll INF = 1000LL * 1000 * 1000 * 1000 * 1000 * 1000;
const ll inf = 1000 * 1000 * 1000;
const ld PI = acos(-1.0);
const ll mod1 = inf * inf + 1337 * 42 + 57 * 179 + 228;
const ll mod2 = inf + 7;
const ll bigmod = 1LL * inf * 100 + 3;
const int MAXN = 300005;
const ld EPS = 1e-10;
const int N = 300228;
ll hp = 1e6 + 3;
ll ans = 0;
signed main()
{
	fastio();
	int n;
	cin >> n;
	string s;
	cin >> s;
	int mn = inf;
	vector<char> x{ 'L', 'D', 'U','R' };
	for (auto i : x)
	{
		mn = min(mn, count(all(s), i));
	}
	cout << mn * 4;
	return 0;
	sp;
}

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    string A;
    cin>>n;
    cin>>A;
    int x=0;
    int y=0;
    for(int i=0;i<n;i++)
    {
        if(A[i]=='U')
            y++;
        if(A[i]=='D')
            y--;
        if(A[i]=='R')
            x++;
        if(A[i]=='L')
            x--;
    }
    cout<<n-(x+y)<<endl;
    return 0;
}

#include <iostream>
#include <string>
using namespace std;
int main()
{
	int a(0), b(0), c(0), d(0), max = 0;
	int n;
	cin >> n;
	cin.ignore(100, '\n');
	char s[100];
	cin.get(s, 100, '\n');
	cin.ignore(100, '\n');
	for (int i = 0; i < strlen(s); i++)
	{
		if (s[i] == 'U')a++;
		if (s[i] == 'D')b++;
		if (s[i] == 'L')c++;
		if (s[i] == 'R')d++;
		int k1 = a - b, k2 = c - d;
		if (k1 == 0 && k2 == 0)
		{
			max=a*2+c*2;
		}
	}
	cout<<max<<endl;
}

#include <iostream>
#include <string>

using namespace std;

int min(int a, int b) {

	return (a < b) ? a : b;

}

int main(void) {

	int iN;
	string str;
	string::iterator it;
	int iU, iD, iL, iR;

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin >> iN >> str;

	iU = 0;
	iD = 0;
	iL = 0;
	iR = 0;

	for (it = str.begin(); it != str.end(); it++) {

		if (*it == 'U') iU++;
		if (*it == 'D') iD++;
		if (*it == 'L') iL++;
		if (*it == 'R') iR++;

	}

	cout << min(iU, iD) + min(iL, iR) << endl;

	return 0;

}

#include <bits/stdc++.h>
using namespace std;

int main() {
    int n,c=0,x=0,y=0;
    std::vector<int> v;
    string s;
    cin>>n>>s;
    for(int i=0;i<n;i++)
    {
        if(s[i]=='L')
            x--;
        else if(s[i]=='R')
            x++;
        else if(s[i]=='D')
            y--;
        else if(s[i]=='U')
            y++;

        if(x==0 && y==0)
            v.push_back(i+1);
    }
    if(v.empty())
        cout<<0<<"\n";
    else
        cout<<v.back();

	return 0;
}

#include <bits/stdc++.h>

using namespace std;

int n,x,y,m;

char s;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    x=y=0;
    m=0;
    cin >> n;
    for (int i=1; i<=n; ++i)
    {
        cin >> s;
        if (s=='U') ++y;
        if (s=='D') --y;
        if (s=='L') --x;
        if (s=='R') ++x;
        if (x==0 && y==0) m=i;
    }
    cout << m;
}

#include<bits/stdc++.h>
using namespace std;

int main()
{

	int n;
	cin >> n;

	string s;
	cin >> s;
	int count = 0;

	int x = 0,y = 0;

	for(int i = 0;i<s.size();i++)
	{
		if(s[i] == 'U') y++;
		else if(s[i] == 'D') y--;
		else if(s[i] == 'L') x--;
		else x++;

		if(x == 0 && y == 0) count = i+1;
	}

	cout << count << endl;

	return 0;
}

#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
	int n, x = 0, y = 0, count = 0;
	string s;
	cin >> n >> s;
	bool flag = true;
	for (int i = 0; i < n; i++)
	{
		if(flag)
			count++;
		switch (s.at(i))
		{
		case 'U':
			y += 1;
			break;
		case 'D':
			y -= 1;
			break;
		case 'L':
			x -= 1;
			break;
		case 'R':
			x += 1;
			break;
		}
		if (i > 1 && x == 0 && y == 0)
		{
			break;
		}
	}
	if (x == 0 && y == 0)
		cout << count;
	else
		cout << 0;
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
string s;
int n, x,y;
int main(){
    cin>>n>>s;
    for(int i=0;i<n;i++){
        if(s[i]=='L')x--;
        else if(s[i]=='R')x++;
        else if(s[i]=='U')y++;
        else x--;
    }

    cout<<n- abs(x)+abs(y)<<endl;

    return 0;
}

#include<bits/stdc++.h>

using namespace std ;

long long int n , cnt , lnt , mx = -1e9 ;
vector < long long int > V ;
string s ;

int main ()
{
    cin >> n >> s ;
    for ( int i = 0 ; i < s.size() ; i++ )
    {
        if ( s[i] == 'U' )
            cnt++ ;
        if ( s[i] == 'D' )
            cnt-- ;
        if ( s[i] == 'L' )
            lnt-- ;
        if ( s[i] == 'R' )
            lnt++ ;
        if ( cnt == 0 && lnt == 0 )
        {
            V.push_back(i+1);
        }
    }
    if (V.size()==0)
        cout <<0;
    else
    {
        for ( int i = 0 ; i < V.size() ; i++ )
        {
            mx = max ( V[i] , mx ) ;
        }
        cout << mx ;
    }
}

//
//  main.cpp
//  educational32
//
//  Created by Administrator on 09.11.17.
//  Copyright © 2017 Administrator. All rights reserved.
//

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>

using namespace std;

typedef long long ll;

int main() {
    int n;
    cin >> n;
    ll x = 0, y = 0, zz = 0;
    for(int i = 0;i < n; ++i) {
        char temp;
        cin >> temp;
        if (temp == 'U') {
            ++y;
        }
        if (temp == 'D') {
            --y;
        }
        if (temp == 'R') {
            ++y;
        }
        if (temp == 'L') {
            --y;
        }
        if(x == 0 && y == 0) {
            zz = i + 1;
        }
    }
    cout << zz;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,x=0,y=0,c=0;
    string s;
    cin>>n;
    cin>>s;
    for(int i=0;i<n;i++){
        if(s[i]=='U') y+=1;
        else if(s[i]=='D') y-=1;
        else if(s[i]=='R') x+=1;
        else if(s[i]=='L') x-=1;
        c++;
        if(x==0&&y==0){
            cout<<c<<endl;
            return 0;
        }
    }
    cout<<"0"<<endl;
    return 0;
}

/******************************************
          Mobarak Hosen Shakil
        ICE, Islamic University
     ID: mhiceiuk(all), 29698(LOJ)
   E-mail: mhiceiuk @ (Gmail/Yahoo/FB)
 Blog: https://iuconvergent.wordpress.com
*******************************************/

#include<bits/stdc++.h>
using namespace std;

int main()
{
    int n;
    string s;
    cin>>n>>s;

    int x, y, c, res, xx, yy;
    x=y=xx=yy=c=res=0;

    for(int i=0; i<n; i++)
    {
        if(s[i]=='D')
            yy--;
        else if(s[i]=='U')
            yy++;
        else if(s[i]=='L')
            xx--;
        else if(s[i]=='R')
            xx++;
        c++;
        if(x==xx && y==yy)
            res=max(c, res);

    }
    printf("%d\n", res);
    return 0;
}

#include <iostream>

using namespace std;

int main() {
    int n,count = 0,x = 0,y = 0,j = 0,z = 0,f = 0;
    cin >> n;
    string s;
    cin >> s;
    for(int i = 0;i < n;i++){
            if (s[i] == 'L') {
                count++;
                x++;
            }
            if (s[i] == 'U') {
                j++;
                x++;
            }
            if (s[i] == 'R') {
                z++;
                x++;
            }
            if (s[i] == 'D') {
                f++;
                x++;
            }
        if(z == count && f == j){
            cout << x;
            break;
        }
    }
    if(z != count || f != j){
        cout << 0;
    }
}

#include <iostream>
#include<string>
#include <sstream>
#include<vector>
#include<bits/stdc++.h>
#include <sys/types.h>
#include <string.h>

using namespace std;

int main()
{

int n,x=0,y=0;
string s;

cin>>n>>s;

for(int i=0;i<n;i++)
{

    if(s[i]=='U'||s[i]=='D')
    {
        if(s[i]=='U')
            y++;

        else
        y--;

    }

    else
    {

        if(s[i]=='R')
        x++;

        else
        x--;
    }

}

cout<<n-abs(x)+abs(y);

}

#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;

int main()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    cout << s;
    int ls = 0, ds = 0, us = 0, rs = 0;
    for(int i = 0 ; i < n; i++)
    {
        switch(s[i])
        {
            case 'R':rs++;break;
            case 'D':ds++;break;
            case 'U':++us;break;
            case 'L':++ls;break;
        }
    }
    cout << 2 * min(ls, rs) + 2 * min(us, ds);
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    char a[1002];
    while(scanf("%d",&n)!=EOF)
    {
        scanf("%s",a);
        int x=0,y=0,sum=0,ans=0;
        for(int i=0;i<n;i++)
        {
            if(a[i]=='L')x--;
            if(a[i]=='R')x++;
            if(a[i]=='U')y++;
            if(a[i]=='D')y--;
            sum++;
            if(x==0&&y==0)
            {
                ans+=sum;
                sum=0;
            }
        }
        printf("%d\n",ans);
    }
}

#include <iostream>

using namespace std;

int main() {
	int n;
	int counterU = 0;
	int counterR = 0;
	int counterD = 0;
	int counterL = 0;
	int counter = 0;
	cin >> n;
	char k[100];
	for (int i = 0; i < n; i++)
	{
		cin >> k[i];
	}
	for (int i = 0; i < n; i++)
	{
		if (k[i] == 'U')
		{
			counterU++;
		}
		if (k[i] == 'R')
		{
			counterR++;
		}
		if (k[i] == 'D')
		{
			counterD++;
		}
		if (k[i] == 'L')
		{
			counterL++;
		}
	}
	if ((counterU == counterD)&(counterR == counterL))
	{
		counter = counterU + counterR + counterD + counterL;
		cout<<counter;
	}
	else
	{
		cout << '0';
	}
	return 0;
}

#include <bits/stdc++.h>
#define ll long long
#define Start ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define dbg(...) cerr << "LINE(" << LINE << ") -> [" << #__VA_ARGS__ << "]: [", DBG(VA_ARGS)
#define fr first
#define sc second
#define PI 3.14159265
#define ullt unsigned long long int
using namespace std;
void solve()
{
    int ans=0,ans1=0,ans2=0;
    int n;
    cin>>n;
    string s;
    cin>>s;
    int last=-1;
    for(int i=0;i<s.size();i++){
        if(s[i]=='L')
            ans1--;
        if(s[i]=='R')
            ans1++;
        if(s[i]=='U')
            ans2++;
        if(s[i]=='D')
            ans2--;
        if(ans1==0&&ans2==0)
            ans+=i-last,last=i;
    }
    cout<<ans;

}

int main()
{
    Start;
    int t=1;
    //cin>>t;
    while(t--)
        solve(),cout<<"\n";

}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    char c;
    int a[]={1,-1,0,0};
    int b[]={0,0,1,-1};
    int n,x=0,y=0,i,p=0,temp;
    cin>>n;
    int l=0,u=0,d=0,r=0;
    for(i=0;i<n;i++)
    {
        cin>>c;
        if(c=='U') u++;
        else if(c=='D') d++;
        else if(c=='R') r++;
        else if(c=='L') l++;

    }
    cout<<l<<u<<d<<r<<endl;
    cout<<2*(min(l,r)+min(u,d));
}

#include <bits/stdc++.h>
using namespace std;

int main()
{
	int n, x = 0, y = 0, ans = 0;

	cin >> n;
	string s;
	cin >> s;

	for(int i = 0; i < n; i++)
	{
		if(s[i] == 'U') y = y+1;
		else if(s[i] == 'D') y = y-1;
		else if(s[i] == 'L') x = x-1;
		else if(s[i] == 'R') x = x+1;

		if(x == 0 && y == 0){
			ans = i+1;
		}
	}

	cout << ans << endl;

	return 0;
}

#include <bits/stdc++.h>
using namespace std;

int main() {
	int n;
	cin >> n;
	char s[105];
	scanf("%s", s);
	int x = 0, y = 0;
	int ans = 0;
	int len = strlen(s);
	for(int i=0; i<len; i++) {
		x = 0, y = 0;
		for(int j=i; j<len; j++) {
			if(s[j] == 'U') {
				y++;
			}
			if(s[j] == 'D') {
				y--;
			}
			if(s[j] == 'L') {
				x--;
			}
			if(s[j] == 'R') {
				x++;
			}
			if(x==0 && y==0) ans = max(ans, j-i+1);
		}

	}
	cout << ans << endl;
	return 0;
}

#include<iostream>
#include<string>
#include<fstream>
#include<algorithm>
#include<cmath>
#include<map>
#include<vector>
using namespace std;
ofstream fo("test.out");
ifstream fi("test.inp");
int n, rs;
int a[105], b[105];
int x[105], y[105];
int main()
{
	cin >> n ;
	for (int i = 1; i <= n; i++)
	{
		char t;
		cin >> t;
		if (t == 'L') a[i]--;
		if (t == 'R') a[i]++;
		if (t == 'U') b[i]++;
		if (t == 'D') b[i]--;
	}
	for (int i = 1; i <= n; i++)
	{
		a[i] += a[i - 1];
		b[i] += b[i - 1];
	}
	for (int i = 0; i <= n; i++)
	{
		if (!a[i] && !b[i])
			rs = max(rs, i - rs);
	}
	cout << rs;
}

#pragma comment(linker, "/stack:640000000")

#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<stdio.h>
using namespace std;
#define ll long long int
#define scanl(a) scanf("%lld",&a)
#define scanii(a,b) scanf("%d%d",&a,&b)
#define scaniii(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define scanll(a,b) scanf("%lld%lld",&a,&b)
#define scanlll(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define scani(a) scanf("%d",&a)
#define clr(a) memset(a,0,sizeof(a))
#define clr_(a) memset(a,-1,sizeof(a))
#define pb(a) push_back(a)
#define pii pair<int,int>
#define sqr(a) a*a
#define eps 1e-9
#define inf INT_MAX
#define pi acos(-1.0)
#define ff first
#define ss second
#define INF (ll)1e18
#define m_p make_pair
#define vsort(v) sort(v.begin(),v.end())
#define all(v) v.begin(),v.end()
#define UNIQUE(X) sort(all(X)) X.resize( unique( all(X)) - X.begin() )
int fx[]={0,0,-1,1,-1,1,1,-1};
int fy[]={1,-1,0,0,1,1,-1,-1};
ll lcm(ll a,ll b){return (a/__gcd(a,b))*b;}
ll bigmod(ll a,ll p,ll mod){ll ans=1;while(p){if(p&1)ans=ans*a%mod;a=a*a%mod;p>>=1;}return ans;}
ll power(ll x,ll n){if(n==0)return 1;else if(n%2==0){ll y=power(x,n/2);return y*y;}else return x*power(x,n-1);}
struct point{double x,y;point(){}point(double xx,double yy){x=xx;y=yy;}};
inline double Distance(point  a,point b){return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));}
#ifdef shaft
     #define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template < typename Arg1 >
    void __f(const char* name, Arg1&& arg1){
        cerr << name << " is " << arg1 << std::endl;
    }
    template < typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names+1, ',');
        cerr.write(names, comma - names) << " is " << arg1 <<endl;
        __f(comma+1, args...);
    }
#else
    #define debug(...)
#endif
const int N=(int)1e6;
const ll mod=(ll)1e9+7;
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    #ifdef shaft
       // freopen("in.txt","r",stdin);
        ///freopen("out.txt","w",stdout);
    #endif ///shaft
    int n;
    cin>>n;
    string s;
    cin >> s;
    int ans = 0;
    for(int i = -100 ; i <= 100 ; i++){
        for(int j = -100 ; j <= 100 ; j++){
            int x = abs(i);
            int y = abs(j);
            if(i<=0 && j<=0){
                int k = 0 , flag = 0;
                int cntx = 0 , cnty = 0;
                for(k = 0 ; k < n ; k++){
                    if(cntx >= x && cnty>=y){
                        flag = 1  ;break;
                    }
                    if(s[k] == 'D')cntx ++;
                    if(s[k] == 'R')cnty ++;
                    if(cntx >= x && cnty>=y){
                        flag = 1  ; k++;break;
                    }
                }
                if(flag){
                    flag = 0;
                    cntx = 0 , cnty = 0;
                    for(; k < n ; k++){
                        if(cntx >= x && cnty>=y){
                        flag = 1  ;break;
                        }
                        if(s[k] == 'U')cntx ++;
                        if(s[k] == 'L')cnty ++;
                        if(cntx >= x && cnty>=y){
                        flag = 1  ;k++;break;
                    }
                    }
                    if(flag){

                        ans = max(ans , 2 * (x + y));
                    }
                }
            }
              if(i<=0 && j >= 0){
                int k = 0 , flag = 0;
                int cntx = 0 , cnty = 0;
                for(k = 0 ; k < n ; k++){
                    if(cntx >= x && cnty>=y){
                        flag = 1  ;break;
                    }
                    if(s[k] == 'D')cntx ++;
                    if(s[k] == 'L')cnty ++;
                    if(cntx >= x && cnty>=y){
                        flag = 1  ;k++;break;
                    }
                }
                if(i == -1 && j==1){
                    debug(cntx,cnty,x,y);
                }
                if(flag){
                    flag = 0;
                    cntx = 0 , cnty = 0;

                    for(; k < n ; k++){
                        if(cntx >= x && cnty>=y){
                        flag = 1  ;break;
                        }
                        if(s[k] == 'U')cntx ++;
                        if(s[k] == 'R')cnty ++;
                        if(cntx >= x && cnty>=y){
                        flag = 1  ;k++;break;
                    }
                    }
                    if(flag){
                         debug(i,j);
                        ans = max(ans , 2 * (x + y));
                    }
                }
            }
            if(i>=0 && j >= 0){
                int k = 0 , flag = 0;
                int cntx = 0 , cnty = 0;
                for(k = 0 ; k < n ; k++){
                    if(cntx >= x && cnty>=y){
                        flag = 1  ;break;
                    }
                    if(s[k] == 'U')cntx ++;
                    if(s[k] == 'L')cnty ++;
                    if(cntx >= x && cnty>=y){
                        flag = 1  ;k++;break;
                    }
                }
                if(flag){
                    flag = 0;
                    cntx = 0 , cnty = 0;
                    for(; k < n ; k++){
                        if(cntx >= x && cnty>=y){
                        flag = 1  ;break;
                        }
                        if(s[k] == 'D')cntx ++;
                        if(s[k] == 'R')cnty ++;
                        if(cntx >= x && cnty>=y){
                        flag = 1  ;k++;break;
                    }
                    }
                    if(flag){
                        ans = max(ans , 2 * (x + y));
                    }
                }
            }
              if(i>=0 && j <= 0){
                int k = 0 , flag = 0;
                int cntx = 0 , cnty = 0;
                for(k = 0 ; k < n ; k++){
                    if(cntx >= x && cnty>=y){
                        flag = 1  ;break;
                    }
                    if(s[k] == 'U')cntx ++;
                    if(s[k] == 'R')cnty ++;
                    if(cntx >= x && cnty>=y){
                        flag = 1  ;k++;break;
                    }
                }
                if(flag){
                    flag = 0;
                    cntx = 0 , cnty = 0;
                    for(; k < n ; k++){
                        if(cntx >= x && cnty>=y){
                        flag = 1  ;break;
                        }
                        if(s[k] == 'D')cntx ++;
                        if(s[k] == 'L')cnty ++;
                        if(cntx >= x && cnty>=y){
                        flag = 1  ;k++;break;
                    }

                    }
                    if(flag){
                        ans = max(ans , 2 * (x + y));
                    }
                }
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

#include <iostream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <ctime>
#include <cstdio>

#define f(a,i,b) for (i=a; i<=b; i++)
#define sqr(a) (a)*(a)
#define fast_io ios_base::sync_with_stdio(0);cin.tie(0);

using namespace std;
typedef long long ll;

ll m,n,g,h,j,k,l,i,mx=-1e9,mn=1e9,a[100001],b[10001],a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,x,y;
char c;
int main()
{
    fast_io;
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    cin >> n;
    for(i=1;i<=n;i++)
    {
        cin >> c;
        if(c=='U')a1++;
        if(c=='D')a2++;
        if(c=='L')a3++;
        if(c=='R')a4++;
    }

    cout << n-((abs(a1-a3)-(abs(a2-a4)))) << endl;
}

#include <iostream>
using namespace std;
void pos(string s,int n)
{
    int x=0,y=0,c=0;
    for(int i=0;i<n;i++){
        if(s[i]=='U'){
            y++;
            c++;
        }
        else if(s[i]=='D'){
            y--;
            c++;
        }
        else if(s[i]=='R'){
            x++;
            c++;
        }
        else if(s[i]=='L'){
            x--;
            c++;
        }

        if((x==0)&&(y==0)){

            break;
        }
    }
    if((x!=0)||(y!=0)){

        c=0;
    }
    cout <<c<<endl;
}
int main()
{
    int n;
    string s;
    cin >>n;
    cin >>s;
    pos(s,n);
    return 0;
}

#pragma comment(linker, "/stack:640000000")

#include<bits/stdc++.h>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<stdio.h>
using namespace std;
#define ll long long int
#define scanl(a) scanf("%lld",&a)
#define scanii(a,b) scanf("%d%d",&a,&b)
#define scaniii(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define scanll(a,b) scanf("%lld%lld",&a,&b)
#define scanlll(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define scani(a) scanf("%d",&a)
#define clr(a) memset(a,0,sizeof(a))
#define clr_(a) memset(a,-1,sizeof(a))
#define pb(a) push_back(a)
#define pii pair<int,int>
#define sqr(a) a*a
#define eps 1e-9
#define inf INT_MAX
#define pi acos(-1.0)
#define ff first
#define ss second
#define INF (ll)1e18
#define m_p make_pair
#define vsort(v) sort(v.begin(),v.end())
#define all(v) v.begin(),v.end()
#define UNIQUE(X) sort(all(X)) X.resize( unique( all(X)) - X.begin() )
int fx[]={0,0,-1,1,-1,1,1,-1};
int fy[]={1,-1,0,0,1,1,-1,-1};
ll lcm(ll a,ll b){return (a/__gcd(a,b))*b;}
ll bigmod(ll a,ll p,ll mod){ll ans=1;while(p){if(p&1)ans=ans*a%mod;a=a*a%mod;p>>=1;}return ans;}
ll power(ll x,ll n){if(n==0)return 1;else if(n%2==0){ll y=power(x,n/2);return y*y;}else return x*power(x,n-1);}
struct point{double x,y;point(){}point(double xx,double yy){x=xx;y=yy;}};
inline double Distance(point  a,point b){return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));}
#ifdef shaft
     #define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template < typename Arg1 >
    void __f(const char* name, Arg1&& arg1){
        cerr << name << " is " << arg1 << std::endl;
    }
    template < typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names+1, ',');
        cerr.write(names, comma - names) << " is " << arg1 <<endl;
        __f(comma+1, args...);
    }
#else
    #define debug(...)
#endif
const int N=(int)1e6;
const ll mod=(ll)1e9+7;
string s;
int n;
int dp[101][101];
int call(int pos , int x , int y , int tot){
    if(pos >= n) {
            if(x == 100 && y == 100) return tot;
            return 0;
    }
    int &ans = dp[pos][tot];
    if(ans != -1)return ans;
    ans = call(pos + 1, x , y , tot);
    int xx = x, yy = y;
    if(s[pos] == 'U') yy = y + 1;
    if(s[pos] == 'D') yy = y - 1;
    if(s[pos] == 'L') xx = x - 1;
    if(s[pos] == 'R') xx = x + 1;
    int p2 = call(pos + 1 , xx , yy , tot + 1);
    return ans = max(ans,p2);

}
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    #ifdef shaft
       // freopen("in.txt","r",stdin);
        ///freopen("out.txt","w",stdout);
    #endif ///shaft
    cin>>n;
    clr_(dp);
    cin >> s;
    cout<<call(0 , 100 , 100 , 0)<<endl;
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define Abs(x)((x) < 0 ? (x) * -1 : (x))
#define rep(x, y) for ((x) = 0; (x) < (y); (x)++)
#define repin(x, y) for ((x) = 0; (x) <= (y); (x)++)
#define nep(x, y) for ((x) = (y) - 1; 0 <= (x); (x)--)
#define nepi(x, y, z) for ((x) = (y) - 1; (z) <= (x); (x)--)
#define repi(x, y, z) for ((x) = (z); (x) < (y); (x)++)
#define repiin(x, y, z) for ((x) = (z); (x) <= (y); (x)++)
#define reps(x, y, z) for ((x) = 0; (x) < (y); (x) += (z))
#define repit(x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define nepit(x) for (__typeof((x).rbegin()) it = (x).rbegin(); it != (x).rend(); it++)
#define All(x) (x).begin(),(x).end()
#define Mem0(x) memset(x, 0, sizeof(x))
#define Mem1(x) memset(x, -1, sizeof(x))
#define End '\n'
#define Out(x) cout<<(x)<<End
template<typename T> inline bool Max(T &x, const T &y) { return x < y ? x = y, 1 : 0; }
template<typename T> inline bool Min(T &x, const T &y) { return x > y ? x = y, 1 : 0; }
template<typename T> using V = vector<T>;
template<typename T> using VV = V<V<T> >;

#define pb push_back
#define mp make_pair
#define X first
#define Y second

static const ll MOD = 1e9 + 7;
static const double PI = 3.141592653589793;

#define LOCAL 0

int main()
{
#if LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
#endif

    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;

    cin >> n;

    string seq;
    map<char, int> table;
    int x = 0;
    int y = 0;
    int up = 0;
    int down = 0;
    int left = 0;
    int right = 0;
    int ans = 0;

    table['U'] = 0;
    table['D'] = 0;
    table['L'] = 0;
    table['R'] = 0;

    cin >> seq;

    int i;

    rep(i, n) {
        table[seq[i]]++;

        if (seq[i] == 'U') y++;
        else if (seq[i] == 'D') y--;
        else if (seq[i] == 'L') x--;
        else if (seq[i] == 'R') x++;
    }

    if (y < 0) down = y * -1;
    else if (0 < y) up = y;

    if (x < 0) left = x * -1;
    else if (0 < x) right = x;

    if (table['U'] - up < 0 || table['D'] - down < 0 || table['L'] - left < 0 || table['R'] - right < 0) {
        Out(0);
    } else {
        if (0 < up) ans += Abs(table['U'] - up);
        else if (0 < down) ans += Abs(table['D'] - down);

        if (0 < left) ans += Abs(table['L'] - left);
        else if (0 < right) ans += Abs(table['R'] - right);

        Out(n - ans);
    }

    return 0;
}

/*                        ______
 _______   /\     |``\   |        |  /
    |     /  \    |__/   |____    |/
    |    / _ _\   |  \   |        |\
    |   /      \  |   \  |______  |  \

            Dept. of CSE
        Comilla  University

*/
#include<bits/stdc++.h>
#define pi 2*acos(0.0)
#define ll long long
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Node struct node
#define spc " "

using namespace std;
///check n=1;
///check corner case;

int main()
{
   ll n,i,j,cc=0,ans=0;
   cin>>n;
   string str;
   cin>>str;
   ll l=0,r=0;
   for(i=0;i<n;i++){
      if(str[i]=='L' )l++;
      else if(str[i]=='R')l--;
      else if(str[i]=='U')r++;
      else r--;
      cc++;
      if(l==0 && r==0)ans=max(cc,ans),cc=0;
   }
   cout<<ans<<endl;
return 0;
}

#include<bits/stdc++.h>
#include <iostream>
#define lln long long int
using namespace std;

int main() {
	lln n,i,c=0,x,y,x1,y1;
	string s;
	cin>>n;
	cin>>s;
	x=0;
	y=0;
	for(i=0;i<n;i++){
	if(s[i]=='L'){
		x++;
	}else if(s[i]=='R'){
		x1++;
	}else if(s[i]=='U'){
		y++;
	}else if(s[i]=='D'){
		y1++;
	}
	}
	x=min(x1,x);
	y=min(y1,y);
	cout<<2*(x+y)<<endl;
	return 0;
}

#include<stdio.h>
int main(){
	int n;
	char com[100];
	scanf("%d",&n);
	getchar();
	scanf("%s",com);
	int u=0,d=0,l=0,r=0;
	for(int i=0;i<n;i++){
		if(com[i]=='U')u++;
		if(com[i]=='D')d++;
		if(com[i]=='L')l++;
		if(com[i]=='R')r++;}
	if(u>d) u-=d;
	else if(u<d) d-=u;
	if(l>r) l-=r;
	else if(l<r) r-=l;
	int s=l+r+u+d;
	if((l && r)||(u && d))
		printf("%d",s);
	else puts("0");
	return 0;
}

#include<iostream>
#include<string>
using namespace std;
int main(){
    int x = 0, y = 0, n, count = 0, j = 0;
    cin >> n;
    char command[n+1];
    int rcount[n];
    for(int i = 0; i<n; i++){
        rcount[i] = 0;
    }
    for(int i = 0; i<n; i++){
        cin >> command[i];
    }
    for(int i = 0; i<n; i++){
    if(command[i] == 'L') x--;
    if(command[i] == 'R') x++;
    if(command[i] == 'D') y--;
    if(command[i] == 'U') y++;
    count++;
    if(x == 0 && y == 0 && i!=0){
        rcount[j] = count;
        count = 0;
        j++;
    }
    }
    int r = 0;
    for(int i = 0; i<n; i++){
        r = r + rcount[i];
    }
    cout << r;
}

#include<bits/stdc++.h>
using namespace std;

int a,b,c,d,e,f,g,h,i,j,n,U,D,L,R;

int main () {
	string k;
	cin >>n >>k;
	a=0
;
b=0;
c=0;
d=0;
for	(i=0; i<n; i++) if(k[i]=='U') a++;
 if(k[i]=='D') b++;
 if(k[i]=='L') c++;
 if(k[i]=='R') d++;
e=a+b-max(a,b);
f=c+d-max(c,d);
cout<<2*e+2*f<<endl;}

#include <iostream>
using namespace std;

int get_xvalue(char c) {
	if (c == 'L') return -1;
	else if (c == 'R') return 1;
	else return 0;
}

int get_yvalue(char c) {
	if (c == 'U') return 1;
	else if (c == 'D') return -1;
	else return 0;
}
const int maxn = 100 + 5;
char a[maxn];
int n;

bool check(int k) {
	for (int i = 0; i + k <= n; i++) {
		int xsum = 0, ysum = 0;
		for (int j = i; j - i < k; j++) {
			xsum += get_xvalue(a[j]);
			ysum += get_yvalue(a[j]);
		}
		// cout << i << ":" << xsum << "," << ysum << endl;
		if (xsum == 0 && ysum == 0) {
			return true;
		}
	}
	return false;
}

int main() {
	scanf("%d", &n);
	scanf("%s", a);
	int ans = 0;
	for (int i = n; i > 0; i--) {
		if (check(i)) {
			ans = i; break;
		}
	}
	cout << ans << endl;
}

#include <bits/stdc++.h>

using namespace std;

int main()
{
    long int n,j=0,k=0,i,l,x=0,y=0;string s;cin>>n>>s;l=s.length();
    vector <long int> p;
    p.push_back(0);
    for(i=0;i<l;i++)
    {
        if(s[i]=='U')
            y++;
        if(s[i]=='D')
            y--;
        if(s[i]=='L')
            x--;
        if(s[i]=='R')
            x++;
        if(x!=0||y!=0)
            k++;
        if(x==0&&y==0)
        {
            j=j+k+1;
            p.push_back(j);
            k=0;
        }
    }
    cout<<*max_element(p.begin(),p.end());
    return 0;
}

#include<bits/stdc++.h>
using namespace std;

//defines
#define openin freopen("input.txt","r",stdin)
#define openout freopen("output.txt","w",stdout)
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ll long long
#define int long long
#define mod 1000000007
#define repr(i,x,y) for (__typeof(x) i=x;i>=y;i--)
#define rep(i,x,y) for (__typeof(x) i=x;i<=y;i++)
#define all(c) (c).begin(),(c).end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair

/* Print pair */
template <typename T,typename S>
ostream & operator << (ostream &os , const pair<T,S> &v) {
    os << "(" ;
    os << v.first << "," << v.second << ")" ;
    return os ;
}
/* Print vector */
template <typename T>
ostream & operator << (ostream &os , const vector<T> &v) {
    os << "[" ;
    int sz = v.size() ;
    for(int i = 0 ; i < sz ; ++i) {
        os << v[i] ;
        if(i!=sz-1)os << "," ;
    }
    os << "]\n" ;
    return os ;
}
/* Print set */
template <typename T>
ostream & operator << (ostream &os , const set<T> &v) {
    T last = *v.rbegin() ;
    os << "[" ;
    for(auto it : v) {
        os << it  ;
        if(it != last) os << "," ;
    }
    os << "]\n" ;
    return os ;
}
/* Print Map */
template <typename T,typename S>
ostream & operator << (ostream &os , const map<T,S> &v) {
    for(auto it : v) {
        os << it.first << " : " << it.second << "\n" ;
    }
    return os ;
}
int power(int a , int b)
{
    int res = 1 ;
    while(b)
    {
        if(b%2) {
            res = (res * a) % mod ;
        }
        b/=2 ;
        a = (a*a) % mod ;
    }
    return res ;
}

//debug
#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
        cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

const int N = 3e5 + 5 ;

int forwar[N] , backwar[N] ;
string str;
pair<pair<int,int>,int> arr[N] ;
long long temp, res;
int32_t main() {
  int n;
  cin>>n;
     cin>>str;
     temp = 0, res = 0;
     int stringSize = str.size();
     int x = 0, y = 0;
     rep(i, 1, stringSize){
         if(str[i-1] == 'L'){
           x--;
           temp++;
         }
         else if(str[i-1] == 'R'){
           x++;
           temp++;
         }
         else if(str[i-1] == 'U'){
           y++;
           temp++;
         }
         else if(str[i-1]  == 'D'){
           y--;
           temp++;
         }
         if(x == 0 && y == 0){
             res += temp;
             temp = 0;
         }
     }
     cout<<res<<endl;

      return 0;
}

    #include<iostream>
    using namespace std;
    int main()
    {
    	int n,i; cin >> n;
    	char a[101];
    	for ( i = 0; i < n; i++)
    	{
    		cin >> a[i];
    	}
    	a[n] = '\0';
    	int x = 0; int y = 0; int sum,f=0,k=0;
    	for (int j=0;j<n;j++)
    	{
    		if (a[j] == 'U')
    		y++;
    		else if (a[j] == 'D')
    		y--;
    		else if (a[j] == 'R')
    		x++;
    		else if (a[j] == 'L')
    		x--;
    		if(x==0 && y==0){
    		    k=1;
    		    f=j;
    		    break;
    		}

    	}
    	if(k)
    	cout << f+1;
    	else
    	cout<< 0;
    }

#include <bits/stdc++.h>

using namespace std;

#define EPS 1e-9
#define For(i,N) FOR(i,N)
#define Forr(i,a,b) FORR(i,a,b)
#define Fotr(i,a,b,c) FOTR(i,a,b,c)
#define FOR(i,N) FORR(i, 0, N)
#define FORR(i,a,b) FOTR(i, a, b, 1)
#define FOTR(i,a,b,c) for(int i=(a);i<(b);i+=(c))
#define FOREACH(i,x) for(__typeof__((x).begin())i=(x).begin();i!=(x).end();i++)
#define MEM(a,x) memset(a,x,sizeof(a))
#define BCHK(a,x) (((a)>>(x))&1)
#define BSET(a,x) ((a)|(1<<(x)))
#define BCLR(a,x) ((a)&(~(1<<(x))))
#define BTGL(a,x) ((a)^(1<<(x)))
#define FMT(...) (sprintf(CRTBUFF, __VA_ARGS__)?CRTBUFF:0)
#define read() freopen("input.txt","r",stdin)
#define write() freopen("output.txt","w",stdout)
#define cpp_io() {ios_base::sync_with_stdio(false);cin.tie(NULL);}
#define BUFFSIZE 30000
#define INF 1000000000
#define MAX 300010
#define MOD 1000000007
#define pb push_back
#define mkpr make_pair
#define pii pair<int, int>
#define PI acos(-1)
#define ll long long
#define fi first
#define si second
#define all(x) x.begin(), x.end()

char CRTBUFF[BUFFSIZE];
#define dbg(args...) {cerr<<"-->";debugger::call(#args,args);cerr<<"\n";}
struct debugger {
    static void call(const char* it) {}
    template<typename T, typename ... aT>
    static void call(const char* it, T a, aT... rest) {
        string b;
        for (; *it&&*it != ','; ++it) if (*it != ' ')b += *it;
        cerr << b << "=" << a << " ";
        call(++it, rest...);
    }
};

int main(){
    cpp_io();
    #ifdef LOCAL
        //read();
        //write();
    #endif
    int n,x=0,y=0,k=0,ans=0;
    cin>>n;
    string s;
    cin>>s;
    for(int j=0;j<n;j++){
        x=0;y=0;k=0;
        for(int i=j;i<n;i++){
            if(s[i]=='L') x--;
            else if(s[i]=='R') x++;
            else if(s[i]=='U') y++;
            else if(s[i]=='D') y--;
            k++;
            if(x==0 && y==0){
                ans = ans+k;
                k = 0;
            }
        }
    }
    cout<<ans<<endl;

}

#include <bits/stdc++.h>
using namespace std;

int main()
{
   int n;
   cin>>n;
   string s;
   cin>>s;
   int cnt=0,val;
   int a=0,b=0,f=0;
   for(int i=0;i<n;i++){
       if(s[i]=='L')a--;
       else if(s[i]=='R')a++;
       else if(s[i]=='U')b++;
       else if(s[i]=='D')b--;
       cnt++;
       if(a==0&&b==0){
           f=1;
           val=cnt;
           //break;
       }

   }
   if(f)cout<<val;
   else cout<<"0";
}

 #include<bits/stdc++.h>
#define   io            ios::sync_with_stdio(false),cin.tie(NULL)
#define   pi            acos(-1)
#define   si(a)         scanf("%d",&a)
#define   si2(a,b)      scanf("%d %d",&a,&b)
#define   sl(a)         scanf("%lld",&a)
#define   sl2(a,b)      scanf("%lld %lld",&a,&b)
#define   sd(a)         scanf("%lf",&a)
#define   loopi(i,x,n)  for(int i=x;i<n;i++)
#define   loopl(i,x,n)  for(long long i=x;i<n;i++)
#define   fout          freopen("out.txt","w",stdout)
#define   fin           freopen("in.txt","r",stdin)
#define   mk(a,b)       make_pair(a,b)
#define   pb(a)         push_back(a)
#define   sorta(v)      sort(v.begin(),v.end())
#define   sortd(v)      sort(v.rbegin(),v.rend())
#define   sortc(v)      sort(v.begin(),v.end(),cmp)
#define   lli           long long int
#define   pii           pair < int,int >
#define   pll           pair< long long,long long >
#define   ff            first
#define   ss            second
  //king move(4) or grid
const int dx[] =  {1,-1,0,0,1,-1,1,-1};
const int  dy[] = {0,0,1,-1,1,1,-1,-1};
//knight moves..
const int kx[] = {2,2,-2,-2,1,-1,1,-1};
const int ky[] = {1,-1,1,-1,2,2,-2,-2};
bool check(int a,int p)
{
    return (bool)(a&(1<<p));
}
int  on(int a,int p)
{
    return   ( a |(1<<p));
}
using namespace std;
map<char,int > mov;
int n;
string s;

//int  dp[110][210][210];
//
//int back_track(int now,int x,int y,int v)
//{
//    int mx=0;
//    if(x==0 && y==0)
//        mx=v;
////    if(now>=n)
////       return 0;
//  int   a=x+100;
//   int  b=x+100;
//    if(dp[now][a][b]!=-1)
//        return dp[now][a][b];
//
//   for(int i=now;i<n;i++)
//    {
//     mx=max(mx,   back_track(now+1,x+dx[mov[s[i]]],y+dy[mov[s[i]]],v+1));
//   }
//    return dp[now][a][b]=mx;
//
//}
int main()
{

  mov['U']=2;
  mov['D']=3;
  mov['L']=1;
  mov['R']=0;
  cin >>n>>s;

  int last=0;
  int x=0,y=0;
 for(int i=0;i<n;i++)
 {
      x+=dx[mov[s[i]]];
      y+=dy[mov[s[i]]];

  }

x=x+y;
 cout <<s.size()-x;

}

#include<iostream>
#include<bits/stdc++.h>
using namespace std;

#define F first
#define S second
#define pb push_back
#define mp make_pair
#define _for(i,a,n) for(int i=a; i<n; i++)
#define clr(a,b) memset(a,b,sizeof(a))
#define all(v) v.begin(),v.end()
#define si(n) scanf("%d",&n)
#define sld(n) scanf("%lld",&n)
#define pi(n) printf("%d",n)
#define pld(n) printf("%lld\n",n)
#define mod 1000000007
#define eps 1e-6
#define infi 1000000002
#define infll 1000000000000000000ll

typedef long long ll;
typedef map<int, int> mii;
typedef map<ll,ll> mll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef set<int> si;

int main()
{
  	ios::sync_with_stdio(0);
  	cin.tie(0);
  	cout.tie(0);
	int n,tmp=0;
	cin>>n;
  	string s;
	cin>>s;
	int cnt=0;
	int flag=0;
	_for(i,0,n)
	{
		if(s[i]=='L')
		{

			flag+=-1;
			cnt++;
		}
		else if(s[i]=='R')
		{
			flag+=1;
			cnt++;
		}
		else if(s[i]=='D')
		{
			flag+=-2;
			cnt++;
		}
		else if(s[i]=='U')
		{
			flag+=2;
			cnt++;
		}
		if(flag==0)
		{
			tmp=max(tmp,cnt);
		}
	}
	cout<<tmp;
  	return 0;
}

#include <iostream>
#include <string>

using namespace std;
int main()
{

    int  b[100], n, x = 0, y = 0, sum = 0, k = 0, beg, kon;
    char a[200];
    cin >> n;
    for (int i = 0; i < n; i++){
        cin >> a[i];
        //if (a[i] == "U") y++;
        //if (a[i] == "D") y--;
        //if (a[i] == "L") x--;
        //if (a[i] == "R") x++;
    }
    for (int i = 0; i < n; i++){
        for (int j = 0; j < n; j++){
            if (a[j] == 'U') y++;
            if (a[j] == 'D') y--;
            if (a[j] == 'L') x--;
            if (a[j] == 'R') x++;
            if (a[i] == 0){
                cout << sum;
                return 0;
            }
            k++;
            if ((x == 0) && (y == 0)){
                beg = i;
                kon = j;
                sum += k;
                for (int i1 = beg; i < kon; i++){
                    a[i1] = a[i+1];
                }
                k = 0;
            }
        }
    }

    cout << sum;
}

//U — перейти из клетки (x, y) в (x, y + 1);
//D — перейти из (x, y) в (x, y - 1);
//L — перейти из (x, y) в (x - 1, y);
//R — перейти из (x, y) в (x + 1, y).

/*****************Bismillahir Rahmanir Rahim***********************/

#include<bits/stdc++.h>
using namespace std;
/********Mohammad********/

/**********SOHAG***********/
#define     ll              long long int
#define pf                  printf()
#define s1(a)              scanf("%lld",&a)
#define s2(a,b)            scanf("%lld %lld",&a,&b)
#define s3(a,b,c)          scanf("%lld %lld %lld",&a,&b,&c)
#define s4(a,b,c,d)        scanf("%lld %lld %lld %lld",&a,&b,&c,&d)
#define s5(a,b,c,d,e)      scanf("%lld %lld %lld %lld %lld",&a,&b,&c,&d,&e)
#define     pb              push_back
#define     popb            pop_back
#define     ull             unsigned long long int
#define     max3(a,b,c)     max(a,max(b,c))
#define     max4(a,b,c,d)   max(max3(a,b,c),d)
#define     min3(a,b,c)     min(a,min(b,c))
#define     min4(a,b,c,d)   min(a,min3(b,c,d))
#define     MOD             1000000007
#define     f               first
#define     s               second
#define     mem(a,v)        memset(a,v,sizeof(a))
#define     mp              make_pair
#define     check           printf("check")
#define     sqr(x)          (x)*(x)
#define     all(v)          v.begin(),v.end()
#define     fast            ios_base::sync_with_stdio(0);cin.tie(0)
#define     pii             pair<int,int>
#define     pll            pair<ll,ll>
#define     MAX             999999999999999999
#define     MIN             -100000000000014
#define     Fread           freopen("input.txt","r",stdin);
#define     Fwrite          freopen("output.txt","w",stdout);

/************************Alhamdulillah*************************/
int main()
{
    ll a,b,n,i,j,mx=0,c=0,s=0,d,k,l,p,x=0,y=0;
    string S;
    s1(n);
    cin>>S;
    for(i=0;i<n;i++)
    {
         if(S[i]=='R')
         {
              x=x+1;
         }
         else if(S[i]=='D')
         {
                 y=y-1;

         }
         else if(S[i]=='U')
         {

              y=y+1;
         }
         else if(S[i]=='L')
         {
              x=x-1;
         }
    }
    cout<<n-x-y<<endl;

    return 0;
}

#include <bits/stdc++.h>
using namespace std;

int move(int &x, int &y, char c)
{
	if (c == 'L' )
	{
		x--;
		return x;
	}

	if (c == 'R')
	{
		x++;
		return x;
	}

	if (c == 'U')
	{
		y++;
		return y;
	}
	if (c == 'D')
	{
		y--;
		return y;
	}
}
int main()
{
	int x = 0, y = 0, dem = 0,i,n, vt, check = 0;
	cin >> n;
	string s;
	cin >> s;

	if (s.length() != 0)
	{

		vt = 0;
		while (vt < s.length())
		{
			i = vt;
			check = 0;
			while ( i < s.length())
			{
				move(x,y,s[i]);
				if (x == 0 && y == 0)
				{
					dem += i - vt +1 ;
					vt = i+1;
					check = 1;
				}
				i++;
			}
			if (check == 0)
				vt++;
			x = 0; y = 0;
		}

		//cout << x << " " << y<<endl;
		cout << dem;
	}

}

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    string A;
    cin>>n;
    cin>>A;
    int x=0;
    int y=0;
    int C=0;
    int S=0;
    for(int i=0;i<n;i++)
    {
        if(A[i]=='U'){
            y++;
            C++;}
        if(A[i]=='D'){
            y--;
            C++;}
        if(A[i]=='L'){
            x--;
            C++;}
        if(A[i]=='R'){
            x++;
            C++;}
        if(x==0 && y==0){
            S=C;
            break;}
    }
    cout<<S<<endl;
    return 0;

}

#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
int main() {
	int x = 0, y = 0;
	int t = 0, ans = 0; string s = "";
	cin >> t;
	for (int i = 0; i < t; i++) {
		char temp;
		cin >> temp; s += temp;
		if (temp == 'L')
			x++;
		else if (temp == 'R')
			x--;
		else if (temp == 'U')
			y++;
		else if(temp == 'D')
			y--;
		if (x == 0 && y == 0)
			ans = i + 1;
	}if (ans == 40)cout << s << endl;
	cout << ans << endl;
	return 0;
 }

#include <iostream>
#include <string>
using namespace std;
int main()
{
	int a(0), b(0), c(0), d(0), max = 0;
	int n;
	cin >> n;
	cin.ignore(100, '\n');
	char s[100];
	cin.get(s, 100, '\n');
	cin.ignore(100, '\n');
	for (int i = 0; i < strlen(s); i++)
	{
		if (s[i] == 'U')a++;
		if (s[i] == 'D')b++;
		if (s[i] == 'L')c++;
		if (s[i] == 'R')d++;
		int k1 = a - b, k2 = c - d;
		if (k1 == 0 && k2 == 0)
		{
			if (i > max)
				max = i;
		}
	}
		if (max != 0)
			cout << max + 1;
		else cout << 0;
}

#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
	int n;
	string s;
	cin >> n;
	cin >> s;

	int ans = 0;
	for (int i = 0; i < n; ++i) {
		switch (s[i])
		{
		case'U': ++ans; break;
		case'D': --ans; break;
		case'L': --ans; break;
		case'R': ++ans; break;
		default:
			break;
		}
	}
	cout << abs(n-ans);
	return 0;
}

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <set>

using namespace std;

int main() {
	string s;
	getline(cin, s);
	int x = 0, y = 0;
	for (int i = 0; i < s.length(); ++i) {
		if (s[i] == 'L') {
			--x;
		}
		if (s[i] == 'R') {
			++x;
		}
		if (s[i] == 'D') {
			--y;
		}
		if (s[i] == 'U') {
			++y;
		}
	}
	cout <<s.length() - abs(x) - abs(y);
  //  system("pause");
	return 0;
}

#include <bits/stdc++.h>
#include <chrono>
#define FOR(i,a,b) for(int _a = (a),_b = (b),i = _a;i <= _b;i++)
#define FORN(i,a,b) for(int _a = (a),_b = (b),i = _a;i >= _b;i--)
#define rep(i,n) for(int i = 0;i < n;i++)
#define HKL ""
#define Catherine 1e2
using namespace std;
const int N = Catherine + 12;

int n,x,y,ans;
char c;
string xx = "ULDR";
int dx[] = {0,-1,0,1};
int dy[] = {1,0,-1,0};

int main()
{
    ios::sync_with_stdio(0);cout.tie(0);cin.tie(0);
//    ifstream cin(HKL".inp");
    cin >> n;
    FOR(i,1,n)
    {
        cin >> c;
        int k = xx.find(c);
        x += dx[k],y += dy[k];
        if(x == 0 && y == 0) ans = i;
    }
    cout << ans;
}

#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;

int main() {
    int n,sum=0;
    cin>>n;
    string s;
    cin>>s;
    int x=0,y=0;
    bool flag =false ;
    int fimax=-1;
    for(int i=0;i<n;i++){
        if(s[i]=='U'){
            y+=1;
        }else if(s[i]=='D'){
            y=y-1;
        }else if(s[i]=='L'){
            x=x-1;
        }else if(s[i]=='R'){
            x=x+1;
        }
        sum++;
        if(x==0 && y==0){
          flag=true;
            fimax=sum;
        }
    }
    if(flag){
        cout<<fimax<<endl;
    }else cout<<0<<endl;
    return 0;
}

#include <bits/stdc++.h>
using namespace std;

int cnt[256];

int main() {
    int mx = 0;
    int n; char S[1005];
    cin >> n;
    scanf("%s", S+1);
    for(int i = 1; i <= n; ++i) {
        cnt[S[i]]++;
        if(cnt['U'] == cnt['D'] && cnt['L'] == cnt['R']) mx = i;
    }
    cout << mx;
}

#include <bits/stdc++.h>

#define pb push_back
#define F first
#define S second

#define ld long double

#define pf push_front

using namespace std;
int l, d, u, r;
vector <int> g[100];
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
  //  freopen ( "input.txt", "r", stdin );
 //   freopen ( "output.txt", "w", stdout );
    int n;
    cin >> n;
    string s;
    cin >> s;

    for(int i = 0; i < n; i++) {
        if (s[i] == 'L') l++;
        if (s[i] == 'D') d++;
        if (s[i] == 'U') u++;
        if (s[i] == 'R') r++;
    }
    int ans = 0;
    int ll = l%4;
    int uu = u%4;
    int dd = d%4;
    int rr = r%4;
    if (l % 4 == 0) ans +=(l-ll);
    if (u % 4 == 0) ans +=(u-uu);
    if (r % 4 == 0) ans +=(r-rr);
    if (d % 4 == 0) ans +=(d-dd);
    l = ll;
    r = rr;
    d = dd;
    u = uu;
     ans += (min(min(u, r), min(l, d)))*4;
    cout << ans << endl;

}

#include<bits/stdc++.h>
#define ll long long int
using namespace std;

int main()
{
    int t;
    //cin>>t;
    t=1;
    while(t--)
    {
       ll n;
       cin>>n;
       string s;
       cin>>s;
       int x=0,y=0,ans=0;
       for(int i=0;i<n;i++)
       {
           if(s[i]=='R')
           {
               x++;
           }
           else if(s[i]=='L')
           {
               x--;
           }
           else if(s[i]=='U')
           {
               y++;
           }
           else
           {
               y--;
           }
           if(x==0 && y==0)
           {
               ans=i+1;
           }
       }
       cout<<ans<<endl;

    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n;
    cin>>n;
    string s;
    cin>>s;

    int mx=0;

    int cntu=0,cntd=0,cntl=0,cntr=0;

    for(int i=0; i<n; i++)
    {
        if(s[i]=='U')
            cntu++;
        else if(s[i]=='D')
            cntd++;
        else if(s[i]=='L')
            cntl++;
        else if(s[i]=='R')
            cntr++;

    }

    int mx1=0,mx2=0,mx3=0,mx4=0;

    if(cntl>0 && cntr>0)
        mx1=min(cntl,cntr);

    if(cntu>0 && cntd>0)
        mx2=min(cntu,cntd);

    if(cntl>0 && cntr>0 && cntu>0 && cntd>0)
        mx3=min(cntu,min(cntd,min(cntl,cntr)));

    ///cout<<mx1<<" "<<mx2<<" "<<mx3<<endl;
    mx4=max(2*mx1,2*mx2);
    mx=max(4*mx3,mx4);

    if(mx==0)
        cout<<"0"<<endl;
    else
        cout<<mx<<endl;

}

#include<bits/stdc++.h>

using namespace std;

int n,Ar[105];
string A;
bool ok(int l,int r)
{
    pair<int,int> curr(0,0);
    //cout<<"segment "<<l<<" to "<<r<<endl;
    //cout<<curr.first<<" "<<curr.second<<"\n";
    for(int i=l;i<=r;i++)
    {
        if(A[i]=='L') curr.first--;
        if(A[i]=='R') curr.first++;
        if(A[i]=='U') curr.second++;
        if(A[i]=='D') curr.second--;
    }

    //cout<<curr.first<<" "<<curr.second<<"\n";

    if(curr.first==0&&curr.second==0) return 1;
    return 0;
}
int main ()
{
    cin >> n;

    cin >> A;

    int ans=0;

    for(int i=0;i<n;i++)
    {
       /* for(int j=i;j<n;j++)
        {*/
            if(ok(0,i)==1) ans = max(ans,(i+1));
        //}
    }
    cout<<ans;
    return 0;
}

#pragma GCC omptimize("unroll-loops")
#pragma GCC optimize("no-stack-protector")

#include <bits/stdc++.h>

#define int long long
#define double long double
#define forn(a, b) for (int a=0; a<b; a++)
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define pb push_back
#define pf push_front

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pi;

const double PI = acos(-1.0);
const double eps = 1e-7;

signed main()
{
	int n, max = 0;
	fastio
	cin >> n;
	string s;
	cin >> s;
	int x = 0, y = 0;
	forn(i, s.size())
	{
		if (s[i]=='U') y++;
		else if (s[i]=='D') y--;
		else if (s[i]=='L') x--;
		else if (s[i]=='R') x++;
		if (x==0 && y==0)
		{
			max = i+1;
		}
	}
	cout << max;
	return 0;
}

#include <iostream>

using namespace std;

int main()
{
    int n;
    while(cin>>n)
    {
        string s;
        cin>>s;
        int u=0;
        int d=0;
        int l=0;
        int r=0;
        int cnt=0;
        for(int i=0; i<n; i++)
        {
            if(s[i]=='U')
                u++;
            if(s[i]=='D')
                d++;
            if(s[i]=='L')
                l++;
            if(s[i]=='R')
                r++;
        }
        if(u==d)
            cnt=cnt+u+d;
        if(u!=0&&d!=0)
        {
            if(u>d)
                cnt+=d;
            if(u<d)
                cnt+=u;
        }
        if(l==r)
            cnt=cnt+l+r;
        if(l!=0&&r!=0)
        {
            if(l>r)
                cnt+=r;
            if(l<r)
                cnt+=l;
        }
        cout<<cnt<<endl;
        cnt=0;
    }
    return 0;
}

#include <cstdlib>
#include <iostream>

int main()
{
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);

    std::string in;
    std::getline(std::cin, in);

    std::ptrdiff_t us = 0;
    std::ptrdiff_t ds = 0;
    std::ptrdiff_t ls = 0;
    std::ptrdiff_t rs = 0;

    for (size_t i = 0; i != in.size(); ++i)
    {
        switch (in[i])
        {
        case 'U': ++us; break;
        case 'D': ++ds; break;
        case 'L': ++ls; break;
        case 'R': ++rs; break;
        }
    }

    std::cout << in.size() - (std::abs(us - ds) + std::abs(ls - rs));
}

#include<bits/stdc++.h>
using namespace std;
string s;
int n, x,y;
int main(){
    cin>>n>>s;
    for(int i=0;i<n;i++){
        if(s[i]=='L')x--;
        else if(s[i]=='R')x++;
        else if(s[i]=='U')y++;
        else x--;
    }

    cout<<n- abs(x)+abs(y)<<endl;

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main(){
    int x=0, y=0;
    int n, ans=0;
    string s;
    cin >> n >> s;
    for(int i=0; i<s.length(); i++){
        if(s[i]=='L'){
            x--;
        }
        else if(s[i]=='R'){
            x++;
        }
        else if(s[i]=='U'){
            y++;
        }
        else if(s[i]=='D'){
            y--;
        }
        //cout << x << " - " << y << " - " << s[i] << endl;
        if(x==0 && y==0){
            ans=i+1;
        }
    }
    printf("%d\n", ans);
}

#include <bits/stdc++.h>
#include <chrono>
#define FOR(i,a,b) for(int _a = (a),_b = (b),i = _a;i <= _b;i++)
#define FORN(i,a,b) for(int _a = (a),_b = (b),i = _a;i >= _b;i--)
#define rep(i,n) for(int i = 0;i < n;i++)
#define HKL ""
#define Catherine 1e2
using namespace std;
const int N = Catherine + 12;

int n,x,y,ans;
char c;
string xx = "ULDR";
short dx[] = {0,-1,0,1};
short dy[] = {1,0,-1,0};

int main()
{
    ios::sync_with_stdio(0);cout.tie(0);cin.tie(0);
//    ifstream cin(HKL".inp");
    cin >> n;
    FOR(i,1,n)
    {
        c = getchar();
        int k = xx.find(c);
        x += dx[k],y += dy[k];
        if(x == 0 && y == 0) ans = i;
    }
    cout << ans;
}

#include <bits/stdc++.h>

using namespace std;

int n;
int x=0,y=0,dem=0;

int main()
{
    char c;
    cin>>n;

    cin>>c;
    dem++;
    if(c=='U') x++;
    else if(c=='D') x--;
    else if(c=='L') y--;
    else if(c=='R') y++;

    for(int i=1; i<n; i++)
    {
        cin>>c;
        if(c=='U') x++;
        else if(c=='D') x--;
        else if(c=='L') y--;
        else if(c=='R') y++;
        if(x==0&&y==0) { cout<<dem<<"\n"; break; }
        dem++;
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;

int main()
{
   int n;
   cin>>n;
   string s;
   cin>>s;
   int cnt=0;
   int a=0,b=0,f=0;
   for(int i=0;i<n;i++){
       if(s[i]=='L')a--;
       else if(s[i]=='R')a++;
       else if(s[i]=='U')b++;
       else if(s[i]=='D')b--;
       cnt++;
       if(a==0&&b==0){
           f=1;
           break;
       }
   }
   if(f)cout<<cnt;
   else cout<<"0";
}

#include<iostream>
#include<string.h>
#include<string>
using namespace std;

int main()
{
	int i,j,k,m,n,a=0,b=0,ok;
	int x=0, y=0;
	string s;
	cin >> n;

	cin >> s;

	for(i=0; i<s.size(); i++){
		if(s[i]=='U'){
			x = x;
			y+=1;
		}
		else if(s[i]=='D'){
			 x=x;
			 y-=1;
		}
		else if(s[i]=='L'){
			x-=1;
			y=y;
		}
		else if(s[i]=='R'){
			x+=1;
			y=y;
		}
		a++;
		if(x==0 && y==0){
			b=1;
			ok=a;

		}

	}
	if(b==0){
		cout << 0 << endl;
	}
	else{
		cout << ok << endl;
	}

	return 0;

}

#include <iostream>
#include <memory.h>
#include <string.h>

using namespace std;

int main(){
	string command;
	int len;
	cin>>len;
	cin>>command;

	bool vis[105];
	memset(vis,0,sizeof(vis));
	for(int i=0;i<len;i++){
		if(command[i]=='L'){
			for(int j=i+1;j<len;j++){
				if(vis[j]){
					continue;
				}
				if(command[j]=='R'){
					vis[i]=vis[j]=1;
					break;
				}
			}
		}
		if(command[i]=='R'){
			for(int j=i+1;j<len;j++){
				if(vis[j]){
					continue;
				}
				if(command[j]=='L'){
					vis[i]=vis[j]=1;
					break;
				}
			}
		}
		if(command[i]=='D'){
			for(int j=i+1;j<len;j++){
				if(vis[j]){
					continue;
				}
				if(command[j]=='U'){
					vis[i]=vis[j]=1;
					break;
				}
			}
		}
		if(command[i]=='U'){
			for(int j=i+1;j<len;j++){
				if(vis[j]){
					continue;
				}
				if(command[j]=='D'){
					vis[i]=vis[j]=1;
					break;
				}
			}
		}
	}
	int count=0;
	for(int i=0;i<len;i++){
		if(vis[i]==1){
			count++;
		}
	}
	cout<<count<<endl;
}

#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ll n;
	cin >> n;
	string s;
	cin >> s;
	ll countL = 0, countD = 0, countU = 0, countR = 0;
	ll k;
	for (ll i = 0; i < n; i++)
	{
		if (s[i] == 'L')
		{
			if (countR > 0)
				countR--;
			else
				countL++;
		}
		else if (s[i] == 'R')
		{
			if (countL > 0)
				countL--;
			else
				countR++;
		}
		else if (s[i] == 'D')
		{
			if (countU > 0)
				countU--;
			else
				countD++;
		}
		else
		{
			if (countD > 0)
				countD--;
			else
				countU++;
		}
		if (countL == 0 && countR == 0 && countD == 0 && countU == 0)
			k = i + 1;
	}
	cout << k << endl;

}

#include<bits/stdc++.h>
#define ll long long int
using namespace std;

int main()
{
    int t;
    //cin>>t;
    t=1;
    while(t--)
    {
       ll n;
       cin>>n;
       string s;
       cin>>s;
       int x=0,y=0,ans=0;
       for(int i=0;i<n;i++)
       {
           if(s[i]=='R')
           {
               x++;
           }
           else if(s[i]=='L')
           {
               x--;
           }
           else if(s[i]=='U')
           {
               y++;
           }
           else
           {
               y--;
           }
           if(x==0 && y==0)
           {
               ans=i+1;
               break;
           }
       }
       cout<<ans<<endl;

    }
    return 0;
}

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main(void)
{
	int n;
	char command[110];
	while (scanf("%d", &n) != EOF)
	{
		int sum = 0;
		memset(command, 0, sizeof(command));
		scanf("%s", command);

		int x = 0, y = 0;
		for (int i = 0; i <= strlen(command); i++)
		{
			if (command[i] == 'U')
				y++;
			else if (command[i] == 'D')
				y--;
			else if (command[i] == 'L')
				x--;
			else if (command[i] == 'R')
				x++;

			if (x == 0 && y == 0)
				sum = i + 1;
		}
		printf("%d\n", sum);
	}

	return 0;
}

#include<bits/stdc++.h>

using namespace std;

int main()
{
    int n;
    cin>>n;
    string s;
    cin>>s;
    int x=0,y=0,ans=0;
    for(int i=0;i<n;i++)
    {

        if(s[i] == 'U')y++;
        else if(s[i] == 'D')y--;
        else if(s[i] == 'R')x++;
        else x--;
        if(x == 0 && y == 0)ans=i+1;
    }
    cout<<ans;
    return 0;
}

#include <iostream>
#include <string>
#include <math.h>
using namespace std ;

int main ()
{
	int x = 0 , y = 0 ;
	int count = 0 ;
	int n ;
	cin >> n ;
	cin.ignore () ;
	string c ;
	getline (cin,c) ;
	for (int i = 0; i < n; i++)
	{
		if (c[i]=='U')
		{
			y++ ;
			count++ ;
		}
		if (c[i]=='R')
		{
			x++ ;
			count++ ;
		}
		if (c[i]=='L')
		{
			x-- ;
			count++ ;
		}
		if (c[i]=='D')
		{
			y-- ;
			count++ ;
		}
		if ((x==0)&&(y==0))
		{
			cout << count ;
			return 0 ;
		}
	}
	cout << "0" ;
	return 0 ;

}

#include <iostream>
#include <math.h>
using namespace std;

int main()
{
    long long n;
    cin >> n;
    char array[n];
    long long x = 0, y = 0;
    long long t = 0;
	for (long long i = 1; i <= n; i++)
    {
    	cin >> array[i];
	}
	for (long long i = 1; i <= n; i++)
    {
    	if(array[i] == 'U')
		{
			y+=1;
		}
		if(array[i] == 'D')
		{
			y-=1;
		}
		if(array[i] == 'R')
		{
			x+=1;
		}
		if(array[i] == 'L')
		{
			x-=1;
		}
		if(x == 0 && y == 0)
		{
		     t = i;
		     cout<<t;
		     return 0;
		}

	}
	cout<<0;
    return 0;
}

/*#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/
#include<bits/stdc++.h>
using namespace std;
# define ll long long
# define int long long  //comment it out when MLE
# define endl "\n"
#define gok ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//# define m 163577857
//# define MOD 163577857
# define pi acos(-1)
# define fi first
# define se second
#define REP(i,n) for (int i = 1; i <= n; i++)
const ll mod = 998244353;
const int K = 2;
//typedef vector<vector<int> > matrix;
int add(int a, int b,int mod) {
    a%=mod;
    b%=mod;
	a += b;
	if (a >= mod) a -= mod;
	if(a<0)
    {
        a += mod;
        a %= mod;
    }
	return a;
}

int mul(ll a, int b,int mod) {
    a%=mod;
    b%=mod;
	a *= b;
	a += mod;
	return a % mod;
}
int po(int a,int b,int mod)
{
    if(b==0)
        return 1;
    if(b%2==0)
        return po(mul(a,a,mod),b/2,mod);
    return mul(a,po(mul(a,a,mod),(b-1)/2,mod),mod);
}

ll fact[1000003];
ll inv[1000003];

void fact0()
{
	int i,j;
	fact[0]=1;
	for(i=1;i<=200000;i++)
	{
		fact[i]=i*fact[i-1]%mod;
	}
	inv[0]=1;
	inv[1]=1;
	ll p=mod;
	for (i=2; i<=200000; i++)
		inv[i] = (p - (p/i) * inv[p%i] % p) % p;

	for(i=2;i<=200000;i++)
	{
		inv[i]*=inv[i-1];
		inv[i]%=mod;
	}
}

signed main(){

      int n;
      cin>>n;
      string s;
      cin>>s;
      int x=0,y=0,an=0;
      for(int i=0;i<n;i++)
      {
          if(s[i]=='U')
            y++;
          else if(s[i]=='D')
            y--;
          else if(s[i]=='L')
            x--;
          else
            x++;
          if(x==0 && y==0)
            an=i+1;
      }
      cout<<an;

	return 0;
}

#include <bits/stdc++.h>
#define PI 2*acos(0.0)
using namespace std;
int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    #endif
    int n, x = 0 , y = 0;
    scanf("%d",&n);
    string s;
    cin>>s;
    int len = s.length();
    for(int i = 0 ; i < len ; i++)
    {
        if(s[i] == 'L')x--;
        else if(s[i] == 'R')x++;
        else if(s[i] == 'U')y++;
        else y--;
        if(x==0 && y==0)
        {
            cout<<i+1<<endl;
            return 0;
        }
    }
    printf("0\n");
}