Problem:
Score : 800 points

Problem Statement

Given are N pairwise distinct non-negative integers A_1,A_2,\ldots,A_N.
Find the number of ways to choose a set of between 1 and K numbers (inclusive) from the given numbers so that the following two conditions are satisfied:

The bitwise AND of the chosen numbers is S.

The bitwise OR of the chosen numbers is T.

Constraints

1 \leq N \leq 50

1 \leq K \leq N

0 \leq A_i < 2^{18}

0 \leq S < 2^{18}

0 \leq T < 2^{18}

A_i \neq A_j (1 \leq i < j \leq N)

Input

Input is given from Standard Input in the following format:

N K S T
A_1 A_2 ... A_N

Output

Print the answer.

Sample Input 1

3 3 0 3
1 2 3

Sample Output 1

2

The conditions are satisfied when we choose \{1,2\} or \{1,2,3\}.

Sample Input 2

5 3 1 7
3 4 9 1 5

Sample Output 2

2

Sample Input 3

5 4 0 15
3 4 9 1 5

Sample Output 3

3

Solution in C# (.NET Core 3.1.201) (judge verdict: Wrong Answer)

using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
public static class P
{
    public static void Main()
    {
        var nkst = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var n = nkst[0];
        var K = nkst[1];
        var s = nkst[2];
        var t = nkst[3];
        var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
        //全部が混血→なにかが純血なものの余事象
        //18bitのうち、純血のbitを定める→だめ
        //ある場所始点とすると、

        List<int> needInd = Enumerable.Range(0, 18).ToList();
        for (int i = 0; i < 18; i++)
        {
            var and = (s >> i & 1);
            var or = (t >> i & 1);
            if (and == or)
            {
                var bit = and;
                a = a.Where(x => (x >> i & 1) == bit).ToArray();
                needInd.Remove(i);
            }
        }

        a = a.Select(x =>
        {
            var binstr = Convert.ToString(x, 2);
            var removedbinstr = string.Join("", binstr.Reverse().Where((_, ind) => needInd.Contains(ind)).Reverse());
            return removedbinstr.Length == 0 ? 0 : Convert.ToInt32(removedbinstr, 2);
        }).ToArray();

        return;

        var max = 1 << needInd.Count;
        long res = 0;
        for (int i = 0; i < a.Length; i++)
        {
            var bits = Max(K, needInd.Count);
            var begin = a[i];
            long[][] dp = Enumerable.Repeat(0, max).Select(_ => new long[bits]).ToArray();
            dp[0][0] = 1;
            for (int j = i + 1; j < a.Length; j++)
            {
                //同じだったらアレできない 違ったらいける
                var mask = begin ^ a[j];
                for (int k = dp.Length - 1; k >= 0; k--)
                {
                    for (int l = dp[k].Length - 2; l >= 0; l--)
                    {
                        dp[k | mask][l + 1] += dp[k][l];
                    }
                }
            }
            res += dp.Last().Sum();
        }
        Console.WriteLine(res);
    }
}