题目描述
The only difference between easy and hard versions is constraints.
A session has begun at Beland State University. Many students are taking exams.
Polygraph Poligrafovich is going to examine a group of nn students. Students will take the exam one-by-one in order from 11 -th to nn -th. Rules of the exam are following:
- The ii -th student randomly chooses a ticket.
- if this ticket is too hard to the student, he doesn't answer and goes home immediately (this process is so fast that it's considered no time elapses). This student fails the exam.
- if the student finds the ticket easy, he spends exactly t_iti minutes to pass the exam. After it, he immediately gets a mark and goes home.
Students take the exam in the