1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#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;
}