Leaving Yharnam
Time limit0.5sMemory limit1024 MB
Given N seat pairs and G easygoing, I introvert, and E extrovert passengers boarding in that order, find the expected bus happiness as a fraction modulo 1e9+7.
- Level
Medium7 of 10
- Topics
- Probability, Combinatorics, Math
- Solved
- No attempts yet
Problem
Eileen works for the municipal bus company in a city called Yharnam. As a classic overachiever, she always wants to make sure the passengers are as happy as they can be. That was not hard, since few people wanted to leave the great city. Recently, though, some strange diseases have appeared in town, and many citizens of Yharnam have decided to leave. By bus, of course.
Each bus in Yharnam is made of pairs of seats. Each pair has two seats: a window seat and an aisle seat. These two seats are next to each other. Each seat is either empty or full. A full seat has someone sitting on it.
Passengers fall into three types:
- introvert: happy if they get a seat and the seat next to them is empty.
- extrovert: happy if they get a seat and the seat next to them is full.
- easygoing: happy as long as they get a seat.
Passengers board in a fixed order. Each person picks a seat and sits down before the next person chooses. Once a seat is chosen, it cannot be changed. Introverts try to avoid sitting next to another introvert. Otherwise, each person chooses as follows:
- If there is an empty seat that makes them happy, they choose one of those seats uniformly at random.
- If there is an empty seat but none makes them happy, an extrovert chooses one empty seat uniformly at random. An introvert chooses uniformly at random among the empty seats that are not next to an introvert, or among all empty seats if every empty seat is next to an introvert. This case cannot happen to an easygoing person.
- If there are no empty seats, the person leaves the bus grumbling.
The happiness of a bus is the number of happy passengers when the bus is ready to go, that is, after everyone has boarded or there are no empty seats.
Eileen's current strategy is to let all easygoing people board first, then all extroverts, and finally all introverts. A bus with N pairs of seats is about to leave. G easygoing people, I introverts, and E extroverts are ready to board. Find the expected happiness of the bus when the easygoing people board first, then the extroverts, and finally the introverts.
Input
The input is a single line with four integers N, G, I, and E, as described in the statement. The constraints are .
Output
The expected happiness of the bus can be written as an irreducible fraction . Output , where is the modular multiplicative inverse of , that is, .