URAL - 2020
#include <bits/stdc++.h>
#include<iomanip>
#include<string>
#include<cstring>
#include<queue>
#include<stack>
#include<map>
#include<vector>
#include<cmath>
using namespace std;
# define maxn
# define inf 0x3f3f3f3f
int main()
{
string N,S;
int ans=0;
cin>>N>>S;
int NL,SL;
NL=N.size();
SL=S.size();
int i=0,j=0;
while(1)
{
if(i==NL&&j==SL)
break;
else if(i==NL&&j<SL)
{
ans+=SL-j;
break;
}
else if(i<NL&&j==SL)
{
ans+=NL-i;
break;
}
if(N[i]==S[j])
{
i++;
j++;
ans++;
}
else
{
if(N[i]=='F'&&S[j]=='L')
{
i++;
ans++;
}
else if(N[i]=='F'&&S[j]=='R')
{
j++;
i++;
ans+=1;
}
else if(N[i]=='R'&&S[j]=='L')
{
i++;
ans++;
}
else if(N[i]=='R'&&S[j]=='F')
{
i++;
j++;
ans+=1;
}
else if(N[i]=='L'&&S[j]=='F')
{
j++;
ans++;
}
else if(N[i]=='L'&&S[j]=='R')
{
j++;
ans++;
}
}
}
cout<<ans<<endl;
return 0;
}