Problem:
Score : 200 points

Problem Statement

Katsusando loves omelette rice.

Besides, he loves crème brûlée, tenderloin steak and so on, and believes that these foods are all loved by everyone.

To prove that hypothesis, he conducted a survey on M kinds of foods and asked N people whether they like these foods or not.

The i-th person answered that he/she only likes the A_{i1}-th, A_{i2}-th, ..., A_{iK_i}-th food.

Find the number of the foods liked by all the N people.

Constraints

All values in input are integers.

1 \leq N, M \leq 30

1 \leq K_i \leq M

1 \leq A_{ij} \leq M

For each i (1 \leq i \leq N), A_{i1}, A_{i2}, ..., A_{iK_i} are distinct.

Constraints

Input is given from Standard Input in the following format:

N M
K_1 A_{11} A_{12} ... A_{1K_1}
K_2 A_{21} A_{22} ... A_{2K_2}
:
K_N A_{N1} A_{N2} ... A_{NK_N}

Output

Print the number of the foods liked by all the N people.

Sample Input 1

3 4
2 1 3
3 1 2 3
2 3 2

Sample Output 1

1

As only the third food is liked by all the three people, 1 should be printed.

Sample Input 2

5 5
4 2 3 4 5
4 1 3 4 5
4 1 2 4 5
4 1 2 3 5
4 1 2 3 4

Sample Output 2

0

Katsusando's hypothesis turned out to be wrong.

Sample Input 3

1 30
3 5 10 30

Sample Output 3

3

Solution in Rust (1.15.1) (judge verdict: Accepted)

pub trait FromFragments {
    #[doc = " Output type."]
    #[doc = ""]
    #[doc = " In almost all cases, `Output` should be `Self`."]
    #[doc = " This type field exists for implementing 1-origin to 0-origin conversion"]
    #[doc = " by `usize_` etc."]
    type Output;
    #[doc = " Returns how many words are read."]
    fn fragments_count() -> usize;
    #[doc = " Converts words into `Output`s."]
    #[doc = ""]
    #[doc = " If the conversion fails, returns `Err` with error message."]
    #[doc = ""]
    #[doc = " # Panics"]
    #[doc = ""]
    #[doc = " If `fragments.len()` differs from `fragments_count()`,"]
    #[doc = " the method may panic."]
    fn from_fragments(fragments: &[&str]) -> Result<Self::Output, String>;
}
#[macro_export]
macro_rules! readable {
    ( $ t : ty , |$ fragments : ident | $ from_fragments : expr ) => {
        readable!($t, 1, |$fragments| $from_fragments);
    };
    ( $ t : ty , $ fragments_count : expr , |$ fragments : ident | $ from_fragments : expr ) => {
        impl FromFragments for $t {
            type Output = $t;
            fn fragments_count() -> usize {
                $fragments_count
            }
            fn from_fragments($fragments: &[&str]) -> Result<$t, String> {
                Ok($from_fragments)
            }
        }
    };
}
readable!((), |_ss| ());
readable!(String, |ss| ss[0].to_string());
macro_rules ! impl_from_fragments { ( $ ( $ t : ty ) * ) => { $ ( impl FromFragments for $ t { type Output = Self ; fn fragments_count ( ) -> usize { 1 } fn from_fragments ( fragments : & [ & str ] ) -> Result <$ t , String > { use std :: str :: FromStr ; <$ t >:: from_str ( fragments [ 0 ] ) . map_err ( | _ | { format ! ( "cannot parse \"{}\" as {}" , fragments [ 0 ] , stringify ! ( $ t ) ) } ) } } ) * } ; }
impl_from_fragments ! ( i8 u8 i16 u16 i32 u32 i64 u64 isize usize f32 f64 ) ;
macro_rules ! define_one_origin_int_types { ( $ new_t : ident $ int_t : ty ) => { # [ doc = " Convert 1-origin integer into 0-origin when read from input." ] # [ allow ( non_camel_case_types ) ] pub struct $ new_t ( ) ; impl FromFragments for $ new_t { type Output = $ int_t ; fn fragments_count ( ) -> usize { 1 } fn from_fragments ( fragments : & [ & str ] ) -> Result < Self :: Output , String > { <$ int_t >:: from_fragments ( fragments ) . map ( | n | n - 1 ) } } } ; ( $ new_t : ident $ int_t : ty ; $ ( $ inner_new_t : ident $ inner_int_t : ty ) ;* ) => { define_one_origin_int_types ! ( $ new_t $ int_t ) ; define_one_origin_int_types ! ( $ ( $ inner_new_t $ inner_int_t ) ;* ) ; } ; }
define_one_origin_int_types ! ( u64_ u64 ; usize_ usize ) ;
macro_rules ! impl_from_fragments_for_tuples { ( $ t : ident $ var : ident $ count : expr ) => ( ) ; ( $ t : ident $ var : ident $ count : expr ; $ ( $ inner_t : ident $ inner_var : ident $ inner_count : expr ) ;* ) => { impl_from_fragments_for_tuples ! ( $ ( $ inner_t $ inner_var $ inner_count ) ;* ) ; impl <$ t : FromFragments , $ ( $ inner_t : FromFragments ) ,*> FromFragments for ( $ t , $ ( $ inner_t ) ,* ) { type Output = ( <$ t >:: Output , $ ( <$ inner_t >:: Output ) ,* ) ; fn fragments_count ( ) -> usize { let mut n = <$ t >:: fragments_count ( ) ; $ ( n += <$ inner_t >:: fragments_count ( ) ; ) * n } # [ allow ( unused_assignments ) ] fn from_fragments ( fragments : & [ & str ] ) -> Result < Self :: Output , String > { let mut start = 0 ; let $ var = <$ t >:: from_fragments ( & fragments [ start .. start +<$ t >:: fragments_count ( ) ] ) ?; start += <$ t >:: fragments_count ( ) ; $ ( let $ inner_var = <$ inner_t >:: from_fragments ( & fragments [ start .. start +<$ inner_t >:: fragments_count ( ) ] ) ?; start += <$ inner_t >:: fragments_count ( ) ; ) * Ok ( ( $ var , $ ( $ inner_var ) ,* ) ) } } } ; }
impl_from_fragments_for_tuples ! ( T4 x4 4 ; T3 x3 3 ; T2 x2 2 ; T1 x1 1 ) ;
pub trait FromLine: Sized {
    type Output;
    fn from_line(line: &str) -> Result<Self::Output, String>;
}
fn split_into_fragments(line: &str) -> Vec<&str> {
    #[allow(deprecated)]
    line.trim_right_matches('\n').split_whitespace().collect()
}
impl<T: FromFragments> FromLine for T {
    type Output = T::Output;
    fn from_line(line: &str) -> Result<T::Output, String> {
        let fragments = split_into_fragments(line);
        if fragments.len() != T::fragments_count() {
            return Err(format!(
                "line \"{}\" has {} fragments, expected {}",
                line,
                fragments.len(),
                T::fragments_count()
            ));
        }
        T::from_fragments(&fragments)
    }
}
impl<T: FromFragments> FromLine for Vec<T> {
    type Output = Vec<T::Output>;
    fn from_line(line: &str) -> Result<Self::Output, String> {
        let n = T::fragments_count();
        let fragments = split_into_fragments(line);
        if fragments.len() % n != 0 {
            return Err(format!(
                "line \"{}\" has {} fragments, expected multiple of {}",
                line,
                fragments.len(),
                n
            ));
        }
        let mut result = Vec::new();
        for chunk in fragments.chunks(n) {
            match T::from_fragments(chunk) {
                Ok(v) => result.push(v),
                Err(msg) => {
                    let flagment_msg = if n == 1 {
                        format!("fragment {}", result.len())
                    } else {
                        let l = result.len();
                        format!("fragments {}-{}", n * l + 1, (n + 1) * l)
                    };
                    return Err(format!("{} of line \"{}\": {}", flagment_msg, line, msg));
                }
            }
        }
        Ok(result)
    }
}
pub fn read<T: FromLine>() -> T::Output {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).unwrap();
    T::from_line(&line).unwrap()
}
#[macro_export]
macro_rules ! read { ( ) => { let mut line = String :: new ( ) ; std :: io :: stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; } ; ( $ pat : pat = $ t : ty ) => { let $ pat = read ::<$ t > ( ) ; } ; ( $ ( $ pat : pat = $ t : ty ) ,+ ) => { read ! ( ( $ ( $ pat ) ,* ) = ( $ ( $ t ) ,* ) ) ; } ; }
#[macro_export]
macro_rules ! readls { ( $ ( $ pat : pat = $ t : ty ) ,+ ) => { $ ( read ! ( $ pat = $ t ) ; ) * } ; }
pub fn readx<T: FromLine>() -> Vec<T::Output> {
    use std::io::{self, BufRead};
    let stdin = io::stdin();
    let result = stdin
        .lock()
        .lines()
        .map(|line_result| {
            let line = line_result.expect("read from stdin failed");
            T::from_line(&line).unwrap()
        }).collect();
    result
}
#[macro_export]
macro_rules ! readx_loop { ( $ pat : pat = $ t : ty ; $ block : block ) => { use std :: io :: BufRead ; let stdin = std :: io :: stdin ( ) ; for line in stdin . lock ( ) . lines ( ) { let line = line . expect ( "read from stdin failed" ) ; let $ pat = <$ t >:: from_line ( & line ) . unwrap ( ) ; $ block } } ; ( $ ( $ pat : pat = $ t : ty ) ,* ; $ block : block ) => { readx_loop ! ( ( $ ( $ pat ) ,* ) = ( $ ( $ t ) ,* ) ; $ block ) ; } ; }
#[macro_export]
macro_rules ! readn_loop { ( $ n : expr ; $ pat : pat = $ t : ty ; $ block : block ) => { use std :: io :: BufRead ; let stdin = std :: io :: stdin ( ) ; { let lock = stdin . lock ( ) ; for _ in 0 ..$ n { let line = String :: new ( ) ; lock . read_line ( & mut line ) . expect ( "read from stdin failed" ) ; let $ pat = <$ t >:: from_line ( & line ) . unwrap ( ) ; $ block } } } ; ( $ n : expr ; $ ( $ pat : pat = $ t : ty ) ,* ; $ block : block ) => { read_times_loop ! ( $ n ; ( $ ( $ pat ) ,* ) = ( $ ( $ t ) ,* ) ; $ block ) ; } ; }
pub trait ReadExt {
    fn read<T: FromFragments>(&self) -> T::Output;
}
impl<'a> ReadExt for [&'a str] {
    fn read<T: FromFragments>(&self) -> T::Output {
        T::from_fragments(self).unwrap()
    }
}
impl<'a> ReadExt for &'a str {
    fn read<T: FromFragments>(&self) -> T::Output {
        T::from_fragments(&[self]).unwrap()
    }
}

use std::collections::HashMap;

fn main() {
    read!(n = u8, _ = ());
    let mut counts: HashMap<u8, u8> = HashMap::new();
    readx_loop!(k_aa = Vec<u8>; {
        for &a in &k_aa[1..] {
            let count = counts.entry(a).or_insert(0);
            *count += 1;
        }
    });
    println!("{}", counts.values().filter(|&&count| count == n).count());
}