#include <bits/stdc++.h>
using namespace std;
// Code by : toshit3q34
int row_solve(vector<int> vect)
{
int ans = 0;
for (int i = 0; i < 3; i++)
{
if (vect[i] != 0)
{
if (vect[i + 1] == vect[i])
{
vect[i + 1] = 2 * vect[i];
vect[i] = 0;
}
else if (vect[i + 1] == 0)
{
vect[i + 1] = vect[i];
vect[i] = 0;
}
}
}
for (int i = 0; i < 4; i++)
{
if (vect[i] == 0)
{
ans++;
}
}
return ans;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int arr[4][4];
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{
cin >> arr[i][j];
}
}
char c;
cin >> c;
vector<int> new_arr[4];
for (int i = 0; i < 4; i++)
{
vector<int> vect(4);
new_arr[i] = vect;
}
if (c == 'R')
{
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{
new_arr[i][j] = arr[i][3 - j];
}
}
}
else if (c == 'L')
{
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{
new_arr[i][j] = arr[i][j];
}
}
}
else if (c == 'D')
{
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{
new_arr[i][j] = arr[j][i];
}
}
}
else
{
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 4; j++)
{
new_arr[i][j] = arr[3 - j][i];
}
}
}
int ans = 0;
for (int i = 0; i < 4; i++)
{
ans += row_solve(new_arr[i]);
}
cout << ans << '\n';
}