Infectious Disease
Time limit5sMemory limit1024 MB
Find the expected number of days until a random infection and vaccine-persuasion process ends in a city of n people, modulo 1e9+7.
- Level
Hard9 of 10
- Topics
- Probability, Math, Dynamic programming
- Solved
- No attempts yet
Problem
In the year 2202, a strange disease begins to spread in a city of people. To stop the spread, experts invented a strong vaccine called Mysterious Oscar. On day , one citizen is infected and another citizen is vaccinated. A vaccinated person is cured immediately and can neither catch nor spread the disease. On each later day (), every citizen who was infected strictly before day chooses one uninfected and unvaccinated citizen with equal probability and infects that citizen. If an infected citizen has no uninfected and unvaccinated citizen left to choose, that citizen does nothing. After the infection step, every citizen who was vaccinated strictly before day chooses 2 different unvaccinated citizens with equal probability and persuades them to take the vaccine, one by one. If a vaccinated citizen has fewer than 2 unvaccinated citizens to choose from, that citizen persuades all the remaining unvaccinated citizens. Grammy wants to know how many days pass before the disease is fully extinguished. Find the expected number of days until all patients are cured.
Output
It can be shown that the answer is an irreducible fraction , where and are integers and . Output the integer . In other words, output the integer with and .
Input
The only line contains an integer (), the population of the city.
Output format
Output a single integer, the expected number of days before all patients are cured, modulo .