We are given: n heroes with strengths s_i. There is a sequence of m actions (m <= min(n,20)). Each action is either pick (p) by team 1 or 2, or ban (b) by team 1 or 2. Each team makes at least one pick, and each team has the same number of picks and same number of bans. So total picks per team equal, total bans per team equal. The sequence is predetermined: we know the order and type and which team acts.
Both captains play optimally: they want to maximize the difference (team 1 strength - team 2 strength). When a captain misses a pick, a random hero is added to his team from the available pool. That is not optimal usually, but they might choose to skip? Actually they can miss a pick or ban. In optimal play they will never miss deliberately unless that is beneficial? But missing a pick gives a random hero from the available ones, which is essentially a uniformly random choice from the set of remaining heroes? The problem statement: "If he misses a pick, a random hero is added to his team from those that were available at that moment, and if he misses a ban, no hero is banned, as if there was no ban." So missing a pick is not controlled; it yields a random hero. Since both captains are optimal and rational, they will not miss if they can choose something better; but maybe missing a pick could be beneficial in some cases? Since the outcome is random, it's not deterministic; but typical minimax/optimal play assumes that the random outcome could be any available hero with equal probability? The problem statement: "captains of both teams will act optimally well." Usually in such game problems, random outcomes are considered worst-case? Actually they are not controlled by the opponent, but rather by chance. In game theory, optimal play might involve considering expected value if there is randomness. However, note that the captains can choose to miss a pick intentionally (they may decide not to pick). The outcome then is random, which might have a better expected value than any deterministic pick they could make? Possibly if they want to avoid giving information? But since the game is full information (all strengths known), and both are rational, the random pick is not under control; they would prefer to choose a specific hero if they can. Unless there is some strategic reason like they want to keep some hero for later? But a pick consumes a hero; if they pick, they remove that hero from the pool; if they miss, a random hero is removed and given to them. That could be worse because they cannot control which hero they get. So I think optimal captains will never miss a pick or ban. However, they might be forced to miss if they cannot perform the action? No, they can always pick or ban any available hero? They can pick any hero that hasn't been banned or picked yet. So they have choices. So missing is suboptimal. So we can assume both captains will always pick or ban a specific hero when it's their turn.
But wait: The problem says: "The team captain may miss a pick or a ban. If he misses a pick, a random hero is added to his team from those that were available at that moment, and if he misses a ban, no hero is banned, as if there was no ban." That means they have an additional action: do nothing. But since they want to maximize difference, they might consider doing nothing if it leads to a better outcome. However, is doing nothing ever beneficial? Let's analyze: In a ban, doing nothing means no hero is banned, so the set of available heroes stays larger, which could be beneficial to both? But since the opponent may later pick or ban, a ban is used to deny a strong hero to the opponent. Usually, you want to ban strong heroes if you think opponent might pick them. So missing a ban is like wasting a ban; you could always ban a hero that you don't care about (maybe the weakest) which essentially is like not banning because the weakest hero wouldn't be picked anyway? But banning a weak hero is not harmful; it removes that hero from the pool. Could that be beneficial? If you ban a weak hero, you reduce the pool, possibly forcing the opponent to pick from slightly stronger heroes? Actually if you ban a weak hero, it doesn't affect the strong ones; it might increase the average strength of remaining heroes, which could be bad if you are going to pick later? But you can choose to ban a hero that you don't want the opponent to get; but if you ban a weak hero, the opponent wouldn't pick it anyway, so it's effectively no ban. But the act of banning still consumes a hero; but maybe you could use that ban to remove a strong hero that you think opponent will pick. So missing a ban is not optimal because you could always ban a hero that is worthless to you (like the weakest) and that would be at least as good as missing? But need to see: Banning a weak hero removes it from the pool, which could be detrimental if you later might want to pick that weak hero? No, you wouldn't want to pick weak heroes anyway. So it's not harmful. But is there a scenario where banning a hero (even a weak one) could be strictly worse than not banning? Consider if both teams have same number of picks and bans; if you ban a weak hero, the pool becomes smaller, which might force the opponent to pick a slightly stronger hero later, which could be bad for you. For example, suppose there are only strong heroes left, then opponent will get strong heroes regardless. But if you ban a weak hero, you remove a low-value option; if the opponent later has a pick and the remaining heroes include some weak ones, they would choose the strongest among them. Removing a weak hero may not change the maximum available, but it could reduce the set of weak heroes that could be given away in a forced random pick? But we assume picks are intentional, not random (unless missed). So opponent will always pick the best available if it's beneficial to them. So banning a weak hero doesn't affect the maximum available; it just removes a low option that wouldn't be picked anyway. So it's neutral. So missing a ban is essentially equivalent to banning the weakest hero (or any hero that won't affect the future optimal picks). So we can assume optimal players will always perform picks and bans (they will not miss) because they can always choose a hero to ban or pick that is at least as good as missing, and there is no downside. However, there is a nuance: When it's your pick, you could miss, leading to a random hero. That random hero could be better than any hero you could deliberately pick? No, because if you pick, you can select the best available hero. If you miss, you might get a hero that is not the best, possibly worse. So the expected value of missing is the average strength of remaining heroes, which is at most the maximum strength (unless all equal). So it's worse. So you would never miss a pick. So we can ignore missing as suboptimal.
Thus the game is deterministic: Two players alternately (according to a given sequence) either pick a hero for their team or ban a hero (remove from pool). Both want to maximize the difference (team1 - team2). This is a two-player zero-sum game with perfect information. The state is the set of available heroes, the remaining actions, and the current scores. Since m <= 20, and n <= 100, we can use dynamic programming over subsets? m=20, the number of actions is small, but the number of heroes is up to 100, so the state cannot be a subset of all heroes. However, we can note that the strengths matter and the order in which they are picked matters. The game is akin to a sequential selection from a multiset. Typically such problems can be solved with DP over the number of picks and bans performed, but also the relative ordering of strengths? There is a known technique: Since both players are rational and the heroes are valued, the optimal strategies for picks/ bans can be derived by sorting heroes by strength and then considering that picks will take the strongest available, and bans will remove the strongest to deny the opponent. However, that intuition may hold only for simple alternating turn sequences. But here the sequence of actions is arbitrary, with picks and bans interleaved and designated teams. The optimal strategy might be more complex.
Given m <= 20, we can potentially do DP over the set of heroes chosen/picked/banned. Since each action consumes one hero (pick or ban), and there are m actions, the total number of heroes involved is exactly m? No, note: The game ends after m actions. But there are n heroes total; after m actions, some heroes will remain unused. However, only heroes that are picked or banned are removed from the pool; the rest remain but are irrelevant because no more actions. The game's outcome depends only on which heroes were picked by team1 and team2. The rest are ignored. So essentially, we are selecting a subset of heroes for picks: each team picks some number of heroes (say k picks each, since same number of picks per team). Also some heroes are banned (bans per team also equal, say b bans each). So total actions = 2k + 2b = m. Because each team has same number of picks and same number of bans. So m = 2*(picks + bans). Let P = number of picks per team, B = number of bans per team. Then total actions = 2P + 2B = 2(P+B) = m. So m is even. And each action is assigned to a team and type.
Now, since both players are optimizing the difference, this is a finite game. The number of possible choices at each step can be large (choose any remaining hero to pick/ban). However, with m <= 20, we can try to do DP with state being a bitmask of which heroes have been taken? n <= 100, so 2^100 is impossible. But we can compress by noting that only the relative strengths matter, and we only need to consider the top m heroes? Not exactly, because bans and picks may involve lower-strength heroes if forced by strategy. But since m is small (<=20), the number of heroes that will actually be picked or banned is m, but which ones? Possibly not just the top m because players might choose to ban some strong ones and pick others; but obviously the strongest heroes will be the most contested. In zero-sum selection games with perfect information and additive utility, often optimal play can be determined by sorting heroes and then using minimax on the ordering of picks. However, the presence of bans complicates.
Observation: The game is similar to a turn-based selection from a sorted list, where each turn you either pick (add to your sum) or remove (ban) a hero, with the goal of maximizing difference in sum. Since the strengths are linear and independent, the optimal strategy is to consider the heroes sorted descending. At any point, the decision of which hero to pick/ban is essentially about controlling which heroes are available for future picks.
There is known result: In such a game where each player on their turn can either take the largest remaining or ban (remove) the largest, the optimal strategy is something like... But here the sequence is given with specific types (pick/ban) for each team. That means that at some steps a player must pick, at some steps must ban. So it's a predetermined sequence of moves with alternating control. This is similar to a "priority" order: the heroes are sorted, and the outcome is determined by which heroes go to which team based on the order of picks.
But there is an extra twist: bans are removal without benefit, and they can be used to deny the opponent. Since both players are rational, they will always ban the strongest available hero if they want to deny it, because that hero would otherwise be picked by the opponent later. However, sometimes they might want to ban a slightly weaker hero to preserve a stronger one for their own pick? But if they can pick later, they would want the strongest for themselves, not ban it. So ban is used to remove a hero that would otherwise be taken by the opponent. Since picks are also forced at specific times, the decision might be more subtle.
Given the small m, we can solve the game using minimax with DP over the set of remaining heroes? But n can be up to 100, and the set of remaining heroes can be any subset of up to 100. However, we only care about the multiset of strengths. Since strengths are integers up to 1e6, but only up to 100 items, we could use DP over the number of remaining strongest heroes? But the state could be represented by an index representing how many of the top heroes have been taken? Let's explore.
Consider that at any point, the players only care about the relative order of heroes by strength. Since all actions are based on strengths, the optimal move will always involve either picking the strongest available hero or banning the strongest available hero (or maybe not?). Let's test: Suppose it's your turn to pick. Your objective is to maximize your own sum minus opponent's sum. If you pick a hero, you immediately gain its strength, and remove it from pool. You could pick any hero. Is it ever optimal to pick a weaker hero instead of the strongest? Possibly if you want to leave the strongest for later and you think the opponent will be forced to pick something else? But since the opponent can also pick later, if you leave the strongest, the opponent might take it on their pick. So you should take the strongest when you can, unless there is some strategic benefit to picking a weaker hero now and later using a ban to remove the strongest? But bans are separate actions, and you may have a ban later. However, picking the strongest now gives you the maximum immediate gain and also denies it to opponent. Usually, in zero-sum take-away games with picks only, it's optimal to always pick the largest available (greedy) if the turn order is fixed? Actually, that is not always true. For example, suppose there are three items: 10, 5, 5. Two players alternate picks. If player 1 picks 10, then player 2 gets both 5 and 5, total 10, tie. If player 1 picks 5, then player 2 picks 10, and player 1 gets the other 5, total 10 vs 10 tie. So both yield tie. So picking largest is not strictly better? Actually picking 10 yields 10 vs 10 (since player2 gets 5+5=10). So equal. But if the values are 10, 9, 1, and two picks each. Player1 picks 10 (gains 10), Player2 picks 9 (gains 9), Player1 picks 1 (total 11), Player2 gets nothing? Actually two picks each, after three picks, one left? Let's compute: items: [10,9,1]. Two picks each means total picks =4, but only 3 items, so maybe one pick left? Not consistent. Actually typical game: each player picks one item per turn until all items are taken. But here we have fixed number of picks per player. So if each picks 2 items from a set of 4, then picking largest first may be optimal. There is known result: In a sequential picking game where players alternately pick one item from a common set, each player's optimal strategy is to always pick the largest remaining, assuming they have complete information and the payoff is sum of their picks. This is because the game is a special case of the "greedy algorithm" for partition? Actually, it's known that if both players play optimally, the outcome can be determined by sorting items and then players take turns picking the largest remaining; this is optimal because the game is a zero-sum game with perfect information and the utility is sum. I recall that in the "pick the largest" game, the greedy strategy (pick the largest) is optimal. Let's reason: Consider any state with multiset of items. Player's turn to pick. Suppose the largest remaining item is L. If the player picks L, the game proceeds to the next state with L removed, and the opponent's optimal response yields some difference. If the player picks some other item X < L, then the state after his move still contains L, and the opponent can pick L on his turn (if he gets a pick). Since picking L gives the opponent a larger item, it seems picking L is at least as good as picking X, because you can think of swapping: if you pick X and opponent picks L, that's worse than you picking L and opponent picking X, given that the rest of the game is symmetric? However, the rest of the game might be affected because the order of picks may change. But there is a known theorem: In the game where players alternately pick items from a set, with each player trying to maximize his total sum, the optimal strategy is to always pick the largest available item. This can be proven by exchange argument.
Now with bans: On a ban turn, a player can remove an item from the pool without gaining it. The aim is to deny the opponent. Similarly, it seems optimal to ban the largest available item, because that denies the biggest potential gain to the opponent. But is it always optimal? Consider a scenario: You have a pick coming up soon, and you might want to keep the largest for yourself. Banning the largest would remove it from both, which could be worse than banning the second largest, leaving the largest for your upcoming pick. But if you have a pick right after, you could pick the largest. So banning the largest may be suboptimal if you intend to pick it. But on a ban turn, you cannot pick; you can only ban. So if you have a pick later, you might want to preserve the largest for your own pick, so you would ban a different hero, perhaps the second largest, to reduce opponent's options while saving the largest for your own pick. However, the opponent may also have a pick before your next pick, and they could take the largest. So you need to consider the move order. This is a classic game known as "Drafting" in card games (like in autochess or Dota drafting). The optimal move depends on the future sequence.
Given m <= 20, we can solve the game with DP using the concept of "remaining heroes" but we need to reduce the state. Since m is small, the number of heroes that will be involved in the game is at most m (because each action consumes one hero). However, the initial pool has n heroes, many of which will never be used. In optimal play, only the top m heroes (by strength) are relevant? Possibly, because any hero weaker than the m-th strongest will never be picked or banned if there are at least m stronger heroes? Not necessarily: Suppose there are many strong heroes, but bans might target the very strongest, and picks take the strongest. If there are more than m strong heroes, the ones beyond the top m might be irrelevant because only m heroes will be taken (picked or banned). However, could it be optimal to ever pick or ban a hero that is not among the top m? Consider that if there are more than m heroes, the players have the option to ignore the weakest ones. Since they always want to maximize difference, they will never waste a pick on a weak hero if a stronger one is available, because picking a weaker hero gives less immediate benefit and leaves the stronger for opponent. Similarly, for bans, they would ban the strongest available to hurt opponent, unless they want to preserve a strong hero for their own pick, but even then they would ban the next strongest. So it seems that the game will only involve the top m heroes, because there are exactly m actions, and each action will take some hero. The players will always choose from the strongest available, but they might sometimes choose a weaker hero if they are forced to? They are never forced to choose a weak one; they can always choose any hero. So they will always choose the hero that maximizes their outcome. Since the utility only cares about which heroes are picked by each team, and bans remove heroes, the set of heroes that are taken (picked or banned) will be a subset of the original heroes. Because they want to affect the outcome, they will likely pick/ban the strongest ones, because those have the most impact. Could there be a scenario where it's optimal to pick a hero that is not among the top m? Suppose m=4, there are heroes: 100, 99, 1, 1, 1. The top 4 are 100, 99, 1, 1. But maybe a player might pick a 1 instead of 99? That would be suboptimal because 99 > 1. So not. What about bans? They might ban a 1 instead of a stronger hero? That would be wasteful; banning a weak hero doesn't harm opponent much. So they would ban a strong one. Therefore, only the top m heroes will be used.
But is it always true that the set of heroes used will be exactly the m strongest? Consider that there are m actions. Each action removes one hero from the pool. The players have control over which heroes are removed. If they always remove the strongest among the remaining, then indeed the m strongest will be removed. If they sometimes choose not to remove the strongest, then some weaker hero gets removed, leaving a stronger hero still in the pool. But that stronger hero will then be available for future actions. Since there are exactly m removals, after all actions, some heroes will remain in the pool, including possibly some strong ones if they were never removed. Could that happen? For example, if a player wants to preserve a strong hero for his own pick but the sequence doesn't allow him to pick it before opponent does, he might ban it to deny opponent, but that still removes it. So the only way a strong hero remains is if both players decide not to remove it, but then it's not picked by anyone. That would be suboptimal for both? Since the hero would then be unused, and if it's strong, one of the players could have taken it for themselves (if they had a pick) or banned it to prevent opponent from getting it. So leaving a strong hero unused is a missed opportunity for the player who could have taken it. If a player has a pick later, they would want to take it. If they have no more picks, they might want to ban it to prevent opponent from taking it. So in optimal play, the m strongest heroes will all be removed? Not necessarily: Suppose there are exactly m actions, but each team has equal number of picks. After all actions, the remaining heroes are irrelevant. If a strong hero remains, that means that neither team picked it and it wasn't banned. That would be suboptimal for the team that had the last chance to pick or ban it; they could have taken it to improve their own sum or deny opponent. So in optimal play, every strong hero that is stronger than some hero that was taken would have been taken instead. More formally, the set of taken heroes (picked+banned) will be exactly the set of the m strongest heroes, because if any weaker hero is taken while a stronger remains, then the player who took the weaker hero could have taken the stronger instead and improved his outcome (or at least not worsened). However, there is a nuance: because picks give the hero to the player, while bans simply remove it. Taking a stronger hero as a pick is always beneficial for the picker. Taking a weaker hero as a pick is never beneficial if a stronger is available. Similarly, banning a stronger hero is more damaging to the opponent than banning a weaker one, unless you plan to pick that stronger hero later. But if you ban a weaker hero while a stronger remains, you could have banned the stronger instead to more hurt opponent, and your future pick of the stronger is unaffected? Actually if you ban a weaker hero, you leave the stronger, which opponent might pick later. So it's worse. So any deviation from always picking/banning the strongest available (subject to strategy) seems suboptimal. But is there a scenario where picking a weaker hero could lead to a better outcome because of future bans? Let's attempt a counterexample.
Consider a sequence: actions: p1, b2, p2, b1. So team1 picks first, then team2 bans, then team2 picks, then team1 bans. Suppose strengths: [10, 9, 8, 1]. m=4 actions. After all actions, each team picks 1 hero (since total picks per team =1? Actually let's compute: Each team has same number of picks and bans. In this sequence: p1 (team1 pick), b2 (team2 ban), p2 (team2 pick), b1 (team1 ban). So each team has 1 pick and 1 ban. So each team ends with 1 hero. Now, what is optimal? Team1 picks first. If team1 picks 10, then team2 bans: team2 will want to maximize his advantage. After team1 picks 10, remaining: 9,8,1. Team2's ban: He wants to reduce team1's future? Actually team2's next action is pick after ban? Sequence: b2 then p2. So after ban, team2 will pick. He can ban 9 to deny team1? But team1 has no more picks (only one pick and one ban, and his next action is ban after team2's pick). Actually order: p1 (team1 pick), then b2 (team2 ban), then p2 (team2 pick), then b1 (team1 ban). So team1 will have a ban after team2's pick. So after p1, team2 bans. If team2 bans 9, then remaining: 8,1. Then team2 picks: he will pick 8 (since it's strongest). Then team1 bans: he can ban 1, but that's irrelevant because no picks left. So final: team1 has 10, team2 has 8, difference = 2. If team1 instead picks 9? Then remaining: 10,8,1. Team2 bans: he could ban 10 to deny team1? Actually team1 has no more picks; only a ban later. So after team1 picks 9, team2 bans: if he bans 10, remaining: 8,1. Then team2 picks: picks 8. Team1 bans: bans 1. Outcome: team1 9, team2 8, diff = 1. If team2 bans 8 instead, leaving 10,1: then team2 picks: picks 10. Outcome: team1 9, team2 10, diff = -1. So team2 will choose the ban that maximizes his advantage. Which is better for team2? He wants to minimize team1 - team2, i.e., maximize (team2 - team1). After team1 picks 9, if he bans 10, team2 gets 8, diff = 9-8=1. If he bans 8, team2 gets 10, diff = 9-10=-1 (which is better for team2 because -1 < 1? Actually team2 wants difference (team1 - team2) to be as low as possible, i.e., negative means team2 ahead. So -1 is better for team2 than 1. So team2 will ban 8, because then he can pick 10. So outcome: team1 9, team2 10, diff = -1. So picking 9 leads to diff -1, worse for team1 than picking 10 which gave diff 2. So team1 picks 10.
Now consider if team1 picks 8 initially? Remaining 10,9,1. Team2 bans: he could ban 10 or 9. If he bans 10, remaining 9,1; then picks 9 -> diff 8-9=-1. If he bans 9, remaining 10,1; picks 10 -> diff 8-10=-2. He will choose ban leading to higher team2 advantage, i.e., more negative diff for team1. So he picks ban that gives lower diff? Actually he wants to minimize team1 - team2. For diff = 8-9 = -1, team1 - team2 = -1. For diff = 8-10 = -2, that's -2, which is even lower, better for team2. So he would ban 9 to get 10, diff -2. So picking 8 yields -2, worse than 2 and -1. So best is 10.
Now try picking 1? That would be even worse. So greedy pick largest works.
Now consider a scenario with bans before picks, etc. Could it ever be optimal to ban a weaker hero? Suppose sequence: b1, p2, p1, b2. Each team: team1 has 1 ban and 1 pick; team2 has 1 pick and 1 ban? Actually let's check: b1 (team1 ban), p2 (team2 pick), p1 (team1 pick), b2 (team2 ban). So team1: ban then pick; team2: pick then ban. Heroes: 10,9,8,1.
Team1 bans first. If he bans 10, then remaining: 9,8,1. Then team2 picks: picks 9. Then team1 picks: picks 8. Then team2 bans: bans 1 (irrelevant). Diff = 8-9 = -1. If team1 bans 9, remaining: 10,8,1. Team2 picks: picks 10. Team1 picks: picks 8. Diff = 8-10 = -2. If team1 bans 8, remaining: 10,9,1. Team2 picks: picks 10. Team1 picks: picks 9. Diff = 9-10 = -1. If team1 bans 1, remaining: 10,9,8. Team2 picks: picks 10. Team1 picks: picks 9. Diff = 9-10 = -1. So best for team1 is to ban 10 leading to -1 (or banning 9 gives -2, etc). So team1 bans the strongest. Good.
Now consider a more complex scenario: maybe banning the strongest is not always best if you have a pick soon after and the opponent also has picks. For example, sequence: b1, p1, b2, p2. Each team: team1 has ban and pick; team2 has ban and pick. Heroes: 10,9,8,7. Team1 bans first. Options:
- Ban 10: remaining 9,8,7. Then p1: team1 picks best available = 9. Then b2: team2 bans: will ban the best remaining to deny team1? But team1 already picked, team2 will pick later. After p1, remaining: 8,7. Team2 bans: best remaining is 8, so bans 8 (since if he bans 7, then p2 would get 8; but he wants to minimize team1 - team2, he will pick on p2. If he bans 8, then remaining 7, p2 picks 7 -> team2 gets 7. Diff = team1 (9) - team2 (7) = 2. If he bans 7, then p2 picks 8 -> diff = 9-8=1. So team2 will ban 8 to make diff 2? Wait diff = team1 - team2, team2 wants this as low as possible. 2 is higher than 1, so team2 prefers diff=1 (since 1 < 2? Actually lower means more negative or less positive. 1 is lower than 2, so team2 would prefer diff=1 because it's smaller positive; that is better for team2. So between diff 2 and diff 1, team2 chooses diff=1. So he would ban 7? Let's compute: if he bans 7, p2 picks 8 -> team2 gets 8, diff = 9-8=1. If he bans 8, p2 picks 7 -> diff = 9-7=2. So team2 will ban 7 to get diff=1. So after team1 bans 10 and picks 9, team2 bans 7 and picks 8 => diff=1. Actually check: after p1, remaining: 8,7. If team2 bans 8, remaining: 7, then p2 picks 7 => team2=7, team1=9 diff=2. If bans 7, remaining: 8, p2 picks 8 => team2=8 diff=1. So team2 chooses ban that leads to smaller diff, i.e., bans 7 (so that he gets 8). So diff=1.
- Ban 9: remaining 10,8,7. Then p1: team1 picks best = 10. Then b2: remaining: 8,7. Team2 bans: to minimize diff. If bans 8, p2 gets 7 => diff = 10-7=3. If bans 7, p2 gets 8 => diff=10-8=2. So team2 bans 7 to get diff=2. So diff=2.
- Ban 8: remaining 10,9,7. p1 picks 10. remaining 9,7. b2: if bans 9, p2 gets 7 => diff=10-7=3; if bans 7, p2 gets 9 => diff=10-9=1. So team2 bans 7 to get diff=1? Actually if bans 7, p2 gets 9 => diff=1; if bans 9, p2 gets 7 => diff=3. So chooses ban leading to smaller diff =1 (ban 7). So diff=1.
- Ban 7: remaining 10,9,8. p1 picks 10. remaining 9,8. b2: if bans 9, p2 gets 8 => diff=10-8=2; if bans 8, p2 gets 9 => diff=10-9=1. So chooses ban 8 to get diff=1. So diff=1.
So best for team1 is to achieve the highest diff. Options: ban 10 gave diff=1; ban 9 gave diff=2; ban 8 gave diff=1; ban 7 gave diff=1. So best is ban 9 giving diff=2. So team1 bans the second strongest (9) rather than the strongest (10). Why? Because by banning 9, he leaves 10,8,7. Then he picks 10 (the strongest), and then team2's best outcome is diff=2. If he bans 10, he gets 9 and team2 gets 8 => diff=1. So banning the second strongest is better because it allows him to secure the strongest for himself, while also preventing the opponent from getting a very strong second pick? Let's analyze: When he bans 10, he cannot pick it; he picks 9, and opponent later picks 8 (since after team2's ban of 7, they get 8). So opponent gets 8. When he bans 9, he picks 10, opponent ends up with 8? Actually after ban 9, p1 picks 10, remaining 8,7. Then team2 bans 7 (to get 8) and picks 8, so opponent gets 8. So team1 gets 10 vs 8 diff=2. So banning the second best allowed team1 to get the best and opponent gets third best. So indeed banning the strongest would have denied himself the best. So in this sequence, the optimal ban for team1 is not the strongest, but the second strongest, to preserve the strongest for his own pick. So the greedy "always ban strongest" is not optimal in all sequences.
Thus, we need a more thorough analysis. The game is a perfect-information zero-sum game with a fixed order of actions. The state can be represented by the set of available heroes. Since n <= 100 and m <= 20, we could use DP with memoization over the set of available heroes, but that's 2^100 impossible. However, because only m heroes will be taken, we can focus on the top m heroes? But from the example, the top 4 heroes were all used. In the scenario above, the set of heroes taken was the top 4: 10,9,8,7. So indeed, the players used the top 4. So we can argue that in optimal play, only the top m heroes are relevant, because any hero outside the top m will be weaker than at least one hero among the top m, and since there are exactly m actions, if a player ever picks/ban a hero outside the top m, they could have instead picked/banned a stronger hero among the top m that hasn't been taken yet, leading to a better outcome (or at least not worse) by an exchange argument. However, we need to be careful: Suppose there are more than m heroes, and some top heroes might be left unused because the players purposely avoid them? But if a hero is among the top m and remains unused, then some weaker hero must have been taken in its place. Could that be beneficial? Possibly if the weaker hero is taken as a ban, and leaving the stronger hero allows the opponent to pick it later? But if you ban a weaker hero, you could have banned the stronger hero instead, which would be at least as good (denying a stronger hero to opponent). So banning a weaker hero when a stronger is available is suboptimal because you are leaving a stronger hero for opponent. If you pick a weaker hero when a stronger is available, you are giving up the stronger for yourself, which is suboptimal unless you have a reason: maybe you want to leave the stronger for later because you will have another pick? But if you have another pick later, you could pick the stronger now and the weaker later, but the opponent might take the weaker in between. However, if you pick the weaker now, the stronger remains, and opponent might take it before your next pick. So that seems worse. So picking a weaker now is never beneficial because you could have picked the stronger now and gotten more points, and the opponent's future opportunities are the same (the set of remaining heroes after your pick is the same except you swapped which one you took). More formally, if at your pick you choose a hero x when there is a stronger hero y available, consider swapping: you could have chosen y instead, and then the set of remaining heroes would be the same except x replaces y. Since y > x, your sum is higher, and the opponent's future options are the same set of heroes (just x instead of y). Since x is weaker than y, the opponent's potential to gain from those heroes is less (or equal). So your outcome is at least as good. So picking the strongest available is always optimal at a pick turn. This can be proven by a simple exchange argument: any strategy that picks a non-strongest can be transformed into one that picks the strongest instead, without harming the player's final sum and possibly improving.
But is that always true when there are bans? Possibly the presence of bans could affect the argument because the opponent's future bans might be affected by which hero you pick. However, bans are also under control of the opponent. If you pick the strongest, the opponent may ban a different hero than if you had picked a weaker. Could that lead to a situation where picking a weaker hero induces the opponent to make a ban that is less harmful to you? Let's test with an example. Suppose sequence: p1, b2, p1 (so team1 has two picks, team2 one ban). Heroes: 10,9,8,7 (and maybe others). p1 first: if team1 picks 10, then b2: team2 will ban the strongest remaining to hurt team1's next pick? After p1, remaining: 9,8,7. Team2 bans: he wants to minimize team1's total. He can ban 9, leaving 8,7 for team1's next pick. Then team1 picks the best among remaining: 8. So team1 gets 10+8=18, team2 gets 0 (no picks). Diff = 18. If team1 instead picks 9 first, then remaining: 10,8,7. Team2 bans: if he bans 10, then team1 picks 8 -> total 9+8=17; if he bans 8, then team1 picks 10 -> total 19; if he bans 7, team1 picks 10 -> total 19. Team2 will choose ban that minimizes team1 total, so bans 10 if that yields lower total? Let's compute: ban 10 => team1 total 9+8=17; ban 8 => 9+10=19; ban 7 => 9+10=19. So team2 bans 10, yielding total 17. So diff = 17. So picking 10 first yields diff 18, picking 9 first yields 17. So picking strongest is better.
What about picking 8 first? Then remaining 10,9,7. Team2 bans: ban 10 => team1 picks 9 -> total 8+9=17; ban 9 => 8+10=18; ban 7 => 8+10=18 => team2 bans 10? Actually to minimize total, he will ban 10? Let's compute: ban 10 -> total 17; ban 9 -> 18; ban 7 -> 18, so ban 10 yields 17. Diff=17. So best is picking 10.
Thus picking strongest seems optimal.
Now consider a scenario with bans before picks, like the earlier one where banning the strongest was not optimal. But that was a ban action, not a pick. For pick actions, we argued it's optimal to pick the strongest. Is there any counterexample where picking a weaker hero could be beneficial due to future bans? Let's attempt to construct one. Suppose team1 has a pick, then team2 has a ban, then team2 has a pick, then team1 has a pick. So sequence: p1, b2, p2, p1. Heroes: 10,9,8,7,6. Each team: team1 has 2 picks? Actually p1 appears twice, team2 has one pick and one ban. So team1 gets two picks, team2 gets one pick and one ban. Let's simulate optimal strategies. We'll see if picking strongest at first is optimal.
We can compute using DP. Let's try to see if picking something other than the strongest could be better.
State: sorted strengths descending: [10,9,8,7,6]. Actions: p1, b2, p2, p1.
Goal: maximize (team1 - team2).
We can brute force small state manually. But let's try to reason.
If p1 picks 10:
Remaining: 9,8,7,6.
b2: team2 bans a hero to minimize final diff. After ban, p2 will pick, then p1 picks.
We need to compute for each possible ban what is the outcome, and team2 chooses ban that minimizes diff.
After b2, remaining 3 heroes (since ban removes one). Then p2 picks the best among remaining for itself (since it's a pick for team2). Then p1 picks the best among the last two? Actually after p2 picks, one hero left for p1 (since total picks: p1 picks two, p2 picks one, plus one ban, total 4 actions, using 4 heroes). So after p2 picks, one hero remains, which p1 picks. So after ban, there are 3 heroes left, p2 picks best, then p1 picks the remaining (only one). So team1 gets initial 10 + final pick; team2 gets the pick from p2.
So if p1=10, and b2 bans X, then the set S = {9,8,7,6} \ {X} -> three heroes. p2 will pick max(S). Then p1 gets the remaining one (the only left). So team1 total = 10 + (sum of remaining after p2 pick) = 10 + (sum(S) - max(S)). Team2 = max(S). Diff = 10 + sum(S) - max(S) - max(S) = 10 + sum(S) - 2max(S).
Team2 wants to minimize diff, so chooses X to minimize (10 + sum(S) - 2max(S)). Since 10 constant, minimize f(S) = sum(S) - 2*max(S). S is three numbers from {9,8,7,6} after removing X.
Let's compute all possibilities:
- Ban 9: S = {8,7,6}, sum=21, max=8 -> f=21-16=5. Diff = 10+5=15.
- Ban 8: S = {9,7,6}, sum=22, max=9 -> f=22-18=4. Diff=14.
- Ban 7: S = {9,8,6}, sum=23, max=9 -> f=23-18=5. Diff=15.
- Ban 6: S = {9,8,7}, sum=24, max=9 -> f=24-18=6. Diff=16.
Team2 will pick the ban that gives minimal diff, which is 14 (ban 8). So if p1 picks 10, optimal ban is 8, resulting diff=14.
Now, if p1 picks 9 initially:
Remaining: 10,8,7,6.
b2 bans some X, then p2 picks max of remaining three, p1 picks the last.
Team1 total = 9 + (sum(S) - max(S)). Diff = 9 + sum(S) - 2*max(S). S = {10,8,7,6} \ {X}. Options:
- Ban 10: S={8,7,6}, sum=21, max=8, f=21-16=5, diff=14.
- Ban 8: S={10,7,6}, sum=23, max=10, f=23-20=3, diff=12.
- Ban 7: S={10,8,6}, sum=24, max=10, f=24-20=4, diff=13.
- Ban 6: S={10,8,7}, sum=25, max=10, f=25-20=5, diff=14.
Team2 minimizes diff: chooses ban 8 giving diff=12 (or ban 7 gives 13, ban 10 gives 14, ban 6 gives 14). So diff=12.
If p1 picks 8 initially:
Remaining: 10,9,7,6.
b2 bans X:
- Ban 10: S={9,7,6}, sum=22, max=9, f=22-18=4, diff=8+? Actually team1 initial 8, diff = 8 + sum(S) - 2*max(S) = 8+4=12.
- Ban 9: S={10,7,6}, sum=23, max=10, f=23-20=3, diff=11.
- Ban 7: S={10,9,6}, sum=25, max=10, f=25-20=5, diff=13.
- Ban 6: S={10,9,7}, sum=26, max=10, f=26-20=6, diff=14.
Team2 min diff = 11 (ban 9). So diff=11.
If p1 picks 7 initially:
Remaining: 10,9,8,6.
b2:
- Ban10: S={9,8,6}, sum=23, max=9, f=23-18=5, diff=7+5=12.
- Ban9: S={10,8,6}, sum=24, max=10, f=24-20=4, diff=11.
- Ban8: S={10,9,6}, sum=25, max=10, f=25-20=5, diff=12.
- Ban6: S={10,9,8}, sum=27, max=10, f=27-20=7, diff=14.
Min diff = 11 (ban9). So diff=11.
If p1 picks 6 initially:
Remaining: 10,9,8,7.
b2:
- Ban10: S={9,8,7}, sum=24, max=9, f=24-18=6, diff=6+6=12.
- Ban9: S={10,8,7}, sum=25, max=10, f=25-20=5, diff=11.
- Ban8: S={10,9,7}, sum=26, max=10, f=26-20=6, diff=12.
- Ban7: S={10,9,8}, sum=27, max=10, f=27-20=7, diff=13.
Min diff=11 (ban9). So diff=11.
So the best for team1 is picking 10 giving diff=14. So picking strongest is best.
Thus it seems picking the strongest is always optimal at a pick move. I haven't found a counterexample yet. Let's attempt a more complex scenario with multiple picks and bans interleaved. The typical argument: at a pick move, the player gains the strength of the chosen hero. Since the player's objective is to maximize the difference (their sum minus opponent's sum), picking a stronger hero is always at least as good as picking a weaker one, because the rest of the game is symmetric with respect to which hero is removed. More formally, consider two strategies that are identical except at the current pick: one picks hero x, the other picks hero y, with x > y. After the pick, the set of remaining heroes differs only by having y instead of x (since x is taken in one, y in the other). From that point onward, both players will play optimally. We can compare the outcomes. Since the game is zero-sum and the strengths are additive, we can use a swapping argument: suppose the optimal outcome after picking x (with set R{x}) leads to some difference D_x (team1 - team2, from that point onward, plus x). If we instead pick y, we can simulate the same sequence of moves but swapping the roles of x and y? However, because future moves may depend on the actual values, we need to show that D_x >= D_y + (x-y). I think it's plausible that picking the strongest is optimal because the game is monotonic: having a stronger hero in your own pool is always better, and having a weaker hero available to opponent is better. But we need to be careful: the future actions include bans, which are decisions based on the set. If you pick a weaker hero, you leave a stronger hero in the pool, which the opponent might later pick or ban. If you pick the stronger hero, you remove it from the pool, which could be beneficial. So intuitively, picking stronger is better. The exchange argument: Suppose you have a strategy S where at a pick turn you choose a non-maximum hero a, while there is a stronger hero b available. Consider an alternative strategy S' where you choose b instead, and then for the rest of the game, you "pretend" that a is b and b is a? But the values are different. However, we can define a mapping: In any future state, treat the hero a as if it were b and b as a. Since the only difference is the strengths, and all decisions are based on strengths, if the opponent's optimal play depends on the strengths, swapping might change their decisions. So it's not straightforward.
Nevertheless, I suspect that for picks, it's optimal to pick the strongest available. Similarly, for bans, it's not always optimal to ban the strongest; the optimal ban may depend on the future sequence, as shown. So we need a DP that can compute optimal play given the strengths.
Given m <= 20, we can perhaps use DP with state represented by a bitmask over the heroes, but we need to limit the number of heroes considered. Since only the top m heroes are relevant, we could sort heroes descending and consider only the first m (or maybe more?) Let's reason more rigorously: In any optimal play, the set of heroes that are ever picked or banned will be exactly the set of the strongest m heroes. Because if there is a hero outside the top m that is selected while a stronger hero (among the top m) remains unselected, then we can swap them to improve the outcome for the player who made the suboptimal selection. However, we must consider that the selection might be a ban, and swapping could affect the opponent's decisions. But we can argue by contradiction: Suppose in some optimal play, a hero x with strength s_x is selected (picked or banned) while a stronger hero y (s_y > s_x) is never selected (remains available after all actions). Then we can modify the play by replacing the selection of x with y (i.e., at that action, choose y instead) and then continue with the same choices (but treat the identities swapped). Since y is stronger, any player who picks y gains more; any player who bans y removes a stronger hero, which is at least as harmful to the opponent. The rest of the game proceeds identically except that the roles of x and y are swapped. Because y is stronger, the player who benefits from picking or banning y would be better off. However, we must consider that future decisions might depend on which heroes are available. In the original play, after the action, the set of available heroes includes y but not x. In the modified play, it includes x but not y. Since s_y > s_x, having y available is more valuable to the player who will later pick, and more harmful if left for opponent. So if we simply swap the identities, the outcome for the player who made the change would be at least as good? Let's analyze carefully.
We need to prove that there exists an optimal strategy where only the top m heroes are used. Since m is the total number of actions, at most m heroes are removed from the pool. If there are more than m heroes, the players could ignore the weakest ones. Suppose we have sorted strengths: a1 >= a2 >= ... >= an. We claim that in any optimal play, the set of heroes that are removed (picked or banned) is exactly {a1, a2, ..., am}. That is, the m strongest heroes. Because if some weaker hero a_k with k > m is removed while a stronger a_j with j <= m remains, then we can swap them to improve the outcome for the player who made the move, or at least not worsen, by considering that all moves are based on strengths.
A formal proof: Consider an optimal play. Let R be the set of heroes removed (size m). Suppose there exists a hero x not in R such that s_x > s_y for some y in R. Let y be the weakest hero in R that is weaker than x (or the one with smallest strength among those that are less than x). Then we can modify the play by replacing y with x in the action where y was selected. That is, when the player selected y, they instead select x. Since x is stronger, if the action was a pick, the player gains more strength directly. If the action was a ban, the player removes a stronger hero, which is at least as beneficial because it denies a stronger hero to the opponent (the opponent would have lost the opportunity to get that stronger hero). After this change, the set of removed heroes becomes (R \ {y}) ∪ {x}, which now includes x instead of y. The rest of the game, we keep the same choices of heroes for all subsequent actions, but we need to ensure consistency: originally, after that action, the set of available heroes is R_complement, which included x and excluded y. After modification, it includes y and excludes x. Since y is weaker than x, any future pick by either player will now get y instead of x if they would have picked x originally, which is worse for the picker and better for the opponent. However, we need to compare the overall outcome. The change may affect the opponents' decisions, because they may choose different actions when faced with different strengths. But we can argue that there exists an optimal strategy where they always pick the strongest available, etc. But we are not assuming that; we are trying to show that an optimal play can be transformed into one using only top m.
I think a common approach in such drafting problems is to note that the optimal strategies can be determined by considering only the top m heroes because the rest are irrelevant. This is often true when the number of actions is limited and players act optimally. Typically in problems like "pick and ban" with small m, solutions sort heroes and use DP over which of the top m are taken. I've seen similar problems on Codeforces (maybe problem 436D? Actually there is a known problem "Dota 2" CF 312B? Not sure). I recall a Codeforces problem "Dota 2" maybe #... I think it's from CF Round #... The solution uses DP with bitmask over the top m heroes. Indeed, m <= 20 suggests bitmask DP over the set of used heroes among the top m. So we can sort heroes descending and consider only the first m heroes. But is it always sufficient? Let's test with an example where n > m and maybe a weaker hero is chosen while a stronger remains unused because of strategic reasons? Consider m=2, heroes: [100, 1, 1]. n=3. Sequence: p1, b2. Team1 picks, team2 bans. Each team has 1 pick? Actually picks per team? Must have at least one pick each, and same number of picks and bans. Here m=2, so picks per team =? Since each team same picks and bans, and total actions =2, possibilities: each team has 1 pick and 0 bans? But then bans not equal. Condition: each team has the same number of picks and the same number of bans. So if m=2, it could be each team has 1 pick and 0 bans? Then number of bans per team equal (0). But the problem says each team makes at least one pick. So it's possible: picks: team1=1, team2=1, bans: both 0. So sequence: p1, p2. Then each picks one hero. Obviously, both will pick the strongest: team1 picks 100, team2 picks 1. So top 2 heroes used: 100 and 1. The second strongest is 1, but there are two 1's. Actually top 2 are 100 and 1 (any of the 1s). So the set of used heroes includes a 1, but there is another 1 unused. So it's consistent: the used set is among the top m, but not necessarily exactly the top m because there may be ties? Actually the top m are the m highest strengths, but if there are ties at the boundary, there could be multiple heroes with the same strength as the m-th. In that case, which ones are used could be arbitrary but still among the top m (since there are at least m heroes with strength >= the m-th strongest). So we can say that the used heroes are a subset of the top m, but may not include all if there are duplicates? Wait, there are exactly m actions, so exactly m heroes are removed. If we have more than m heroes, we claim that the removed set will consist of the m strongest heroes (considering multiplicities). Because if a weaker hero is removed while a stronger remains, we could swap to improve. So the removed set is exactly the set of the m strongest. So we can limit our attention to the m strongest heroes.
But is it always true that the m strongest will be removed? Consider a scenario with m=3, heroes: 10,9,8,7. Top 3 are 10,9,8. Could it be optimal for some hero outside top 3 (7) to be removed while 8 remains? That would require that 8 is never picked or banned, but 7 is. That would mean the players voluntarily ignore 8 and take 7. But why would they do that? If at any action, a player has the option to pick or ban 8, they could instead pick or ban 7, but that seems strictly worse for them because 8 is stronger (if picking) or more harmful to opponent if banning (since denying a stronger hero is better). However, could there be a situation where picking 8 now would cause the opponent to later take 10 and 9, resulting in a worse outcome than picking 7 now? But if you pick 8 now, you gain 8. If you pick 7, you gain 7, but the set of remaining heroes changes: picking 8 removes 8, leaving 10,9,7; picking 7 leaves 10,9,8. Which is better? The opponent may later get 10 and 9, so your gain is 7 vs 8, and opponent gets 10+9 in both cases? Let's simulate a simple game: m=3, actions: p1, p2, p1? But each team same picks? m=3 odd? Actually m must be even because each team same picks and same bans, so total actions = 2*(picks+bans) is even. So m even. But let's test with m=4 earlier we had top 4 used. So far seems consistent.
We should attempt to construct a counterexample where it's optimal to not take the strongest hero. Suppose m=4, heroes: 100, 99, 1, 1, 1 (n=5). Sequence: b1, p2, p1, b2. Each team: team1 has 1 ban and 1 pick, team2 has 1 pick and 1 ban. If team1 bans 100, then remaining: 99,1,1,1. p2 picks 99. p1 picks 1 (the best is 1). b2 bans 1. Team1 total=1, team2=99 -> diff=-98. If team1 bans 99, then remaining: 100,1,1,1. p2 picks 100. p1 picks 1. diff=-99. If team1 bans 1 (a weak one), then remaining: 100,99,1,1. p2 picks 100 (or 99? picks strongest=100). p1 picks 99. diff=99-100=-1? Actually team1 picks 99, team2 has 100 -> diff=-1. So banning a weak hero (1) yields diff -1, which is better than banning 100 or 99. So team1's optimal ban is a weak hero (1), not a strong one. In this case, the set of removed heroes: ban 1, pick 100 by team2, pick 99 by team1, ban 1 by team2. So removed heroes: 100,99,1,1. The top 4 heroes are 100,99,1,1. Indeed, the removed set is exactly the top 4 (since there are four 1's? Actually we have strengths: 100,99,1,1,1. The top 4 are 100,99,1,1. So the removed set includes two 1's and the two strong ones. So it still uses the top 4. Note that team1 banned a 1, which is among the top 4 (since there are three 1's, but the fourth strongest is 1). So it's still among top m. So it didn't take a hero outside top m.
Now, suppose there are many strong heroes, and we have m=4, heroes: 100, 99, 98, 97, 1,1. Top 4 are 100,99,98,97. Could an optimal play involve banning or picking a 1 instead of 97? Let's test a sequence where that might be beneficial. Sequence: p1, b2, p2, b1. Team1 picks first, then team2 bans, then team2 picks, then team1 bans. Let's compute optimal play with all heroes, and see if a 1 is ever used. We'll compute DP.
We need to see if it's ever optimal to pick/ban a hero outside the top m. Since m is small (<=20) and n up to 100, maybe we can just take all heroes into DP? But we cannot do 2^n. However, we can compress by noting that only relative ordering of strengths matters, and we can use DP over the number of heroes taken from the top? Perhaps we can treat the multiset of strengths and use DP on index? Because the actions are sequential and we can sort heroes descending. Since the optimal strategies likely involve only the top m, we can restrict to those. But we need to be absolutely sure.
Let's try to find a potential counterexample. Consider n=5, m=4, strengths: 10,9,8,7,6 (top 4: 10,9,8,7). Sequence: b1, p2, b2, p1. Each team: team1: ban, pick; team2: pick, ban. Let's compute optimal play.
We want to see if team1 might ever ban 6 (the weakest) instead of a stronger hero.
Compute with all 5 heroes: strengths: 10,9,8,7,6.
Actions: b1, p2, b2, p1.
We'll compute the outcome for team1's ban choice.
Let team1 ban X. Then remaining 4 heroes. Then p2: team2 picks the best among remaining. Then b2: team2 bans one from the remaining 3 (after pick). Then p1: team1 picks from the remaining 2? Actually after p2, 3 heroes left. Then b2 removes one, leaving 2 heroes. Then p1 picks one of those 2? Wait: Initially 5 heroes. b1 removes one => 4 left. p2 picks one => 3 left. b2 bans one => 2 left. p1 picks one => 1 left (unused). So team1 gets: the hero from p1; team2 gets: the hero from p2. Bans just remove.
Team1 wants to maximize (team1 - team2). Team2 wants to minimize that.
We can compute by recursion.
Let S be set of remaining heroes after b1. Let the sorted list of S be s1 >= s2 >= s3 >= s4.
p2 will pick s1 (since it's a pick, optimal to pick strongest). Then after p2, remaining {s2,s3,s4}. b2 will ban one to minimize team1's eventual pick. After b2, two heroes remain, and p1 will pick the larger of those two (since pick strongest). So team1's eventual pick is max of the two remaining after b2. Team2's pick is s1.
Thus, given S, team2's pick = max(S). Team1's pick = after b2, team2 will ban one of {s2,s3,s4} to minimize the maximum of the remaining two. So team1's pick = min_{y in {s2,s3,s4}} ( max( S{max(S), y} ) )? Actually after removing s1 (picked by team2), the set is T = {s2,s3,s4}. Team2 (on ban) will choose a hero y in T to remove to minimize the maximum of the remaining two elements. Since after removal, the two remaining are T \ {y}, and team1 will pick the larger of those two. So team1's gain = max( T \ {y} ), and team2 chooses y to minimize that. So team1's gain = min_{y in T} ( max( T \ {y} ) ). This is essentially the second largest after removing the element that minimizes the maximum of the remaining two. That value is the median of the three? For three numbers a >= b >= c, T = {a,b,c}. If you remove a, remaining {b,c}, max = b. If you remove b, remaining {a,c}, max = a. If you remove c, remaining {a,b}, max = a. The minimum over these max values is min(b, a, a) = b (since b <= a). So team1 gets b, the middle value (second largest of T). So team1's pick = the second largest among {s2,s3,s4}, which is the median of the three, essentially the second smallest? Actually for sorted s2>=s3>=s4, T = [s2,s3,s4]. The min over y of max(T{y}) is: if y=s2, max(s3,s4)=s3; if y=s3, max(s2,s4)=s2; if y=s4, max(s2,s3)=s2. Minimum is min(s3, s2, s2) = s3 (since s3 <= s2). So team1 gets s3, the smallest of the three? Wait s3 is the middle? Actually s2 >= s3 >= s4, so s3 is the middle (could be equal to s2 or s4). So team1 gets the middle value (the second largest among the three, which is s3). So team1 gets s3, team2 gets s1.
Thus, after b1 bans X, S = all heroes except X. The resulting diff = team1 - team2 = s3 - s1, where s1 is max of S, and s3 is the third largest in the original set after removing X? Actually S has 4 elements. Sort S descending: let them be a1 >= a2 >= a3 >= a4. Then team2 gets a1. Team1 gets a3 (the third largest). So diff = a3 - a1.
Now we need to choose X (which hero to ban initially) to maximize this diff.
Compute for each possible X among the 5 heroes.
Original set = {10,9,8,7,6}.
Case X=10: S = {9,8,7,6}. Sorted: a1=9, a2=8, a3=7, a4=6. Then diff = a3 - a1 = 7-9 = -2.
X=9: S = {10,8,7,6}. a1=10, a2=8, a3=7, a4=6. diff = 7-10 = -3.
X=8: S = {10,9,7,6}. a1=10, a2=9, a3=7, a4=6. diff = 7-10 = -3.
X=7: S = {10,9,