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
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include <bits/stdc++.h>
#define uint unsigned int

using namespace std;

int liczpre(uint x)
{
    uint ile=0;
    while(x!=0)
    {
        ile++;
        x &= (x-1);
    }
    return ile;
}

int prep[256]={};

int licz(uint x)
{
    /*int ile=0;
    ile+=prep[x&0xFF];
    cout << ile << " ";
    ile+=prep[(x>>8)&0xFF];
    cout << ile << " ";
    ile+=prep[(x>>16)&0xFF];
    cout << ile << " ";
    ile+=prep[(x>>24)&0xFF];

    return ile;*/
    return (prep[x&0xFF]+prep[(x>>8)&0xFF]+prep[(x>>16)&0xFF]+prep[(x>>24)&0xFF]);
}




int main()
{
    ios_base::sync_with_stdio(0);
    cout.tie(0);
    cin.tie(0);

    for(uint i=0; i<256; i++)
    {
        prep[i]=liczpre(i);
    }


    uint p=0, d=0, t=0, dp=0, dd=0, dt=0, n;
    char b;
    cin >> n;


    cin>>dp;
    for(int i=n-1; i>=0; i--)
    {
        cin >> b;
        if(b=='1')
        {
            p+=(1<<i);
        }
    }
    cin>>dd;
    for(int i=n-1; i>=0; i--)
    {
        cin >> b;
        if(b=='1')
        {
            d+=(1<<i);
        }
    }
    cin>>dt;
    for(int i=n-1; i>=0; i--)
    {
        cin >> b;
        if(b=='1')
        {
            t+=(1<<i);
        }
    }

    uint ile=0, ip, maxp=(1<<n)-1, id, it;
    //2147483648
    for(uint i=0;i<=maxp; i++)
    {
        //if(i%1000000==0)
            //cout << i << endl;
        ip=licz(p^i);
        if(ip<=dp)
        {
            ile++;
        }
        else
        {
            id=licz(d^i);
            if(id<=dd)
            {
                ile++;
            }
            else
            {
                it=licz(t^i);
                if(it<=dt)
                {
                    ile++;
                }
            }
        }
    }

    cout << ile;
}