The Prestige

All submissions for this problem are available.
Every fests in a college will always have a Gamindrome event dedicated to ardent gamers. Usually the games offered to play
will be Counterstrike, FIFA, NFS etc. Krishna is appointed as the organiser of this Gamindrome event in Kurukshetra 2016.
Being an innovative person, Krishna decides to try something different this time. In addition to the traditional games
which were offered to play, Krishna introduces a new game called "Ballindrome". The game definition is as follows:
It is a singleplayer game. Krishna has 'n' boxes with various coloured balls in it. There are 'm' different colours
numbered from 1 through m. Krishna decided that he will choose some boxes in a way that atleast one ball in each colour is
present. The player must determine the number of ways in which Krishna can do this. If the player finds the answer
correctly, he wins the game. Otherwise he has to give 5 bucks to Krishna. Many coders have lost this game to Krishna.
Krishna has now earned 1000 bucks from that. Being greedy, Krishna wants to earn more quickly. You, being a great
programmer is challenged by Krishna. If you solved it, you will get all of those 1000 bucks. Otherwise, you will have to
pay another 1000 bucks. It has now become a prestige issue for you. Can you win this game ? Let's wait and watch
who wins :P
Input
There will be multiple test case files.
One such file will be as follows:
The first line contains two space separated integers 'n' and 'm'.
Each of the following 'n' lines contain an integer ki (0 <= ki <= m) followed by ki distinct integers from interval [1,m],
representing the balls in that box.
Output
For each test case, output on a single line, the requested number of ways modulo 10^9+7.
Constraints
1 <= n <= 10^6
1 <= m <= 20
Example
Input #1: 3 3 3 1 2 3 3 1 2 3 3 1 2 3 Output #1: 7 Input #2: 3 3 1 1 1 2 1 3 Output #2: 1 Input #3: 4 5 2 2 3 2 1 2 4 1 2 3 5 4 1 2 4 5 Output #3: 6
Explanation
Example case 1
There are 3 boxes. There are 3 colours. All the three boxes contains balls of all three colours. Krishna can choose in the
following ways:
{1}, {1,2}, {1,3}, {2}, {2,3}, {3}, {1,2,3}. So, total = 7.
Example case 2 There are 3 boxes and three different colours. Box 1 contains balls of colour 1, box 2 contains balls of colour 2 and box 3 contains balls of colour 3. So, there is only one way of choosing boxes which consists of balls of all 3 colours, i.e., {1,2,3}. So, total = 1.
Author:  lakshmi8 
Tags  lakshmi8 
Date Added:  13022016 
Time Limit:  1 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.5, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, SCM chicken, CLOJ, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
HELP
If you are still having problems, see a sample solution here. 