This problem is identical to the problem D1 in every aspect except the training dataset. Please refer to that problem for the full problem statement.
2000 ms 256 Mb Правила оформления программ и список ошибок при автоматической проверке задач