Problem Statement
This week the ICPC finals are taking place in Dhaka, Bangladesh. We send them our greetings by theming some of the problems in this SRM.
Three teams were fighting for the lead in an ICPC competition. The first successful submission was made by one of these three teams, and from that point until the end of the competition it was always true that (at least) one of these three teams had the maximum number of problems solved, and no team other than these three ever had this property. For this problem you can therefore safely pretend that the other teams do not exist and the only three teams in the competition are our three teams.
We say that a team is leading clearly if that team currently has strictly more solved problems than any other team.
One time in the lead is a largest possible continuous interval of time during which a particular team was leading clearly. (Except for a team that leads until the end of the contest the interval is half-open: it starts at the moment the team gained the lead and contains all moments until the moment when some other team caught up to them.)
For each of the three teams (x=0,1,2) you are given the total number of problems solved during the competition: solved[x] and the number of times this team was in the lead: lead[x].
A contest history is a sequence of successful submissions made by our three teams - i.e., a sequence of moments when a particular team's number of solved problems increased by 1. There can never be two (or more) submissions made at the same time. A contest history with X events can be represented as a string of 0s, 1s and 2s of length X; each number representing the corresponding team's successful submission. Two contest histories differ if the strings describing them differ.
Count all contest histories consistent with the given information. Return that count modulo 10^9 + 7.
Definition
- Class:
- InTheLead
- Method:
- count
- Parameters:
- int[], int[]
- Returns:
- int
- Method signature:
- int count(int[] solved, int[] lead)
- (be sure your method is public)
Constraints
- solved will contain exactly 3 elements.
- Each element of solved will be between 0 and 24, inclusive.
- The sum of solved will be positive.
- lead will contain exactly 3 elements.
- Each element of lead will be between 0 and 24, inclusive.
Examples
{1, 1, 1}
{0, 0, 0}
Returns: 0
This is impossible. The data claims that none of the teams were ever in the lead. However, as they all solved a problem, one of them had to be the first to solve a problem, and at that point in time that team would be in the lead.
{1, 1, 1}
{0, 1, 0}
Returns: 2
Team 1 (the one that should have been in the lead once) must have been the first team to solve a problem. Afterwards there are two possibilities: either the other two teams each solved a problem in the order team 0, team 2, or they did it in the opposite order.
{1, 1, 1}
{0, 2, 0}
Returns: 0
This is also impossible. One argument that shows why: once you stop being in the lead, you cannot regain the lead without solving at least one additional problem.
{1, 2, 1}
{0, 2, 0}
Returns: 4
Here we can tell that team 1 must have made the very first successful submission of the first contest, and that at least one of teams 0+2 had to solve their only problem before team 1 could solve their second.
{1, 2, 3}
{1, 1, 1}
Returns: 3
{4, 5, 6}
{1, 2, 2}
Returns: 15631
{24, 24, 24}
{8, 8, 8}
Returns: 785165557
{24, 24, 24}
{9, 8, 7}
Returns: 942619740
{24, 24, 24}
{20, 2, 2}
Returns: 725878448
{24, 24, 24}
{0, 24, 0}
Returns: 974672469
{2, 0, 3}
{0, 2, 1}
Returns: 0
{4, 3, 3}
{2, 1, 1}
Returns: 242
{0, 0, 2}
{0, 0, 1}
Returns: 1
{4, 0, 2}
{2, 1, 1}
Returns: 0
{4, 2, 3}
{1, 0, 0}
Returns: 96
{4, 2, 5}
{0, 2, 3}
Returns: 16
{1, 1, 5}
{0, 0, 0}
Returns: 0
{1, 2, 0}
{0, 0, 1}
Returns: 0
{3, 4, 4}
{1, 0, 1}
Returns: 272
{1, 5, 2}
{0, 1, 0}
Returns: 54
{5, 0, 3}
{1, 2, 1}
Returns: 0
{4, 2, 2}
{1, 2, 1}
Returns: 0
{4, 3, 2}
{2, 0, 2}
Returns: 16
{1, 3, 3}
{0, 0, 2}
Returns: 13
{1, 3, 0}
{0, 0, 1}
Returns: 0
{5, 0, 0}
{0, 0, 2}
Returns: 0
{4, 3, 3}
{1, 0, 1}
Returns: 209
{2, 5, 4}
{0, 1, 3}
Returns: 211
{2, 0, 4}
{1, 0, 0}
Returns: 0
{2, 3, 5}
{1, 0, 0}
Returns: 0
{3, 1, 1}
{0, 0, 0}
Returns: 0
{1, 5, 4}
{0, 1, 1}
Returns: 117
{0, 2, 3}
{0, 0, 0}
Returns: 0
{5, 0, 3}
{0, 0, 0}
Returns: 0
{2, 0, 2}
{0, 0, 0}
Returns: 0
{1, 1, 5}
{1, 2, 1}
Returns: 0
{3, 4, 4}
{0, 0, 0}
Returns: 0
{5, 0, 1}
{0, 0, 1}
Returns: 0
{2, 5, 0}
{2, 1, 1}
Returns: 0
{20, 24, 22}
{1, 1, 5}
Returns: 82080211
{24, 24, 20}
{5, 8, 5}
Returns: 276636140
{23, 20, 23}
{6, 7, 5}
Returns: 448084971
{22, 24, 20}
{4, 5, 8}
Returns: 218440136
{22, 24, 22}
{4, 4, 5}
Returns: 402354682
{20, 24, 23}
{4, 5, 2}
Returns: 849882787
{23, 22, 23}
{4, 6, 4}
Returns: 185831007
{22, 20, 22}
{1, 2, 0}
Returns: 920808888
{23, 23, 21}
{1, 4, 11}
Returns: 544109482
{24, 24, 21}
{10, 5, 6}
Returns: 179536060
{24, 23, 20}
{3, 5, 4}
Returns: 601076509
{23, 24, 20}
{5, 8, 6}
Returns: 517193421
{23, 22, 20}
{3, 3, 2}
Returns: 17338591
{21, 24, 21}
{4, 5, 7}
Returns: 6962072
{23, 20, 24}
{6, 2, 4}
Returns: 659143061
{21, 20, 21}
{7, 4, 5}
Returns: 614516615
{22, 20, 22}
{2, 0, 1}
Returns: 498169145
{21, 22, 20}
{0, 2, 8}
Returns: 646885322
{23, 23, 23}
{8, 8, 5}
Returns: 173523296
{23, 23, 24}
{7, 3, 5}
Returns: 413588647
{20, 24, 22}
{0, 0, 1}
Returns: 0
{24, 20, 22}
{5, 3, 3}
Returns: 324484220
{22, 24, 22}
{3, 6, 4}
Returns: 542829531
{22, 23, 20}
{0, 0, 0}
Returns: 0
{23, 21, 23}
{3, 4, 4}
Returns: 258076867
{22, 20, 21}
{3, 3, 0}
Returns: 710720915
{20, 24, 24}
{0, 0, 0}
Returns: 0
{22, 24, 21}
{5, 8, 4}
Returns: 752889771
{20, 24, 21}
{5, 5, 6}
Returns: 352725279
{20, 20, 22}
{3, 10, 6}
Returns: 58073065
{21, 22, 20}
{0, 0, 0}
Returns: 0
{24, 24, 21}
{3, 0, 1}
Returns: 465285730
{23, 23, 23}
{6, 4, 12}
Returns: 905441486
{21, 20, 20}
{2, 0, 2}
Returns: 494746209
{22, 24, 24}
{3, 1, 9}
Returns: 350352236
{21, 20, 21}
{0, 6, 3}
Returns: 569852968
{24, 21, 20}
{1, 9, 3}
Returns: 143687078
{24, 22, 21}
{5, 3, 6}
Returns: 397743230
{22, 22, 21}
{6, 8, 5}
Returns: 488762931
{21, 23, 24}
{5, 1, 4}
Returns: 77459049
{16, 24, 10}
{20, 20, 17}
Returns: 0
{6, 20, 7}
{1, 11, 12}
Returns: 0
{24, 5, 15}
{19, 23, 23}
Returns: 0
{5, 6, 12}
{23, 21, 1}
Returns: 0
{15, 10, 17}
{17, 2, 8}
Returns: 0
{3, 4, 21}
{16, 23, 18}
Returns: 0
{21, 6, 8}
{19, 12, 3}
Returns: 0
{8, 17, 11}
{3, 12, 11}
Returns: 0
{20, 17, 7}
{9, 8, 19}
Returns: 0
{21, 22, 20}
{10, 18, 1}
Returns: 0
{24, 19, 6}
{9, 14, 24}
Returns: 0
{10, 24, 3}
{4, 18, 5}
Returns: 0
{8, 10, 8}
{3, 9, 6}
Returns: 0
{1, 24, 8}
{19, 20, 6}
Returns: 0
{6, 21, 15}
{15, 2, 12}
Returns: 0
{20, 0, 20}
{24, 18, 4}
Returns: 0
{3, 13, 9}
{7, 13, 24}
Returns: 0
{6, 2, 6}
{20, 20, 21}
Returns: 0
{7, 17, 2}
{17, 13, 9}
Returns: 0
{10, 11, 3}
{2, 22, 10}
Returns: 0
{24, 24, 24 }
{24, 24, 24 }
Returns: 0
{24, 24, 24 }
{20, 20, 20 }
Returns: 0
{24, 24, 0 }
{24, 0, 0 }
Returns: 1