Room Assignment

Count students by grade and gender, then combine grades 1-2 into one pool and split grades 3-6 by gender, computing rooms as ceil(count/K).

Easy3MathImplementationInterviewNo attempts yetTime limit2sMemory limit512 MB

Problem

An elementary school is going on a three day field trip. Every student from grade 1 to grade 6 needs a room, and the rules are these.

  • Grades 1 and 2 share a room with no separation by gender and no separation by grade.
  • Grades 3 and 4 share a room with no separation by grade, but boys stay with boys and girls stay with girls.
  • Grades 5 and 6 follow the same rule as grades 3 and 4.
  • A room may hold a single student.

Given the largest number of students KK that one room holds, write a program that finds the minimum number of rooms needed to place every student under these rules.

For example, if the students on the trip are counted as below and K=2K = 2, then 9 rooms are needed.

GradeGirlsBoys
Grade 112
Grade 221
Grade 313
Grade 401
Grade 512
Grade 611

Input

The first line has the number of students on the trip NN (1N1,0001 \le N \le 1{,}000) and the largest number of students one room holds KK (1K1,0001 \le K \le 1{,}000), separated by a space.

Each of the next NN lines has the gender SS and the grade YY (1Y61 \le Y \le 6) of one student, separated by a space. SS is 0 for a girl and 1 for a boy.

Output

Print the minimum number of rooms needed to place every student, on one line.