import scala.collection.mutable import scala.io.StdIn /** * Created by Administrator on 2016/12/24 0024. */ object Sub { def intersection(arrSet: mutable.HashSet[Array[Int]]): mutable.HashSet[Int] = { var count = 0 var set = new mutable.HashSet[Int]() for(arr<-arrSet){ if(count==0){ for(i<-arr){ set.add(i) } }else{ set={ val tempSet = new mutable.HashSet[Int]() for(i<-arr){ if(set.contains(i)){ tempSet.add(i) } } tempSet } } count+=1 } set } def intersection(intSet: mutable.HashSet[Int], numbers: mutable.TreeSet[Int]): Int = { for(i<-numbers){ if(intSet.contains(i)){ return i } } return -1 } } object Main extends App { val numbers = new mutable.TreeSet[Int]() for (i <- 0 to 9) { numbers += i } val count = StdIn.readInt() val yesSet = new mutable.HashSet[Array[Int]]() for (_ <- 1 to count) { val input = StdIn.readLine().split(" ") val array = input.toList.slice(0, 4).toArray.map(i => i.toInt) if (input.last == "YES") { yesSet.add(array) } else { for (i <- array) { numbers.remove(i) } } } if (yesSet.size > 0) { println(Sub.intersection(Sub.intersection(yesSet), numbers)) } else { println(numbers.toArray.apply(0)) } }