#include <string>
#include <iostream>
#include <set>
std::string addBinary(std::string a, std::string b)
{
std::string result = "";
int s = 0;
int i = a.size() - 1, j = b.size() - 1;
while (i >= 0 || j >= 0 || s == 1)
{
s += ((i >= 0) ? a[i] - '0' : 0);
s += ((j >= 0) ? b[j] - '0' : 0);
result = char(s % 2 + '0') + result;
s /= 2;
i--; j--;
}
return result;
}
std::string intToBinary(int n)
{
std::string s = "";
while (n > 0)
{
s = ((n % 2) == 0 ? "0" : "1") + s;
n = n / 2;
}
return s;
}
int main()
{
int dimensions;
std::set<std::string> solutions;
std::cin >> dimensions;
std::string change;
for (int i = 0; i < 3; ++i)
{
int r;
std::cin >> r;
std::string temp;
std::cin >> temp;
for (int k = 0; k < dimensions; ++k)
{
r = r << k;
change = intToBinary(r);
solutions.insert(addBinary(change, temp));
}
}
std::cout << solutions.size();
return 0;
}