Way to go! Heidi now knows how many brains there must be for her to get one. But throwing herself in the midst of a clutch of hungry zombies is quite a risky endeavor. Hence Heidi wonders: what is the smallest number of brains that must be in the chest for her to get out at all (possibly empty-handed, but alive)?
The brain dinner night will evolve just as in the previous subtask: the same crowd is present, the N - 1 zombies have the exact same mindset as before and Heidi is to make the first proposal, which must be accepted by at least half of the attendees for her to survive.
Input
The only line of input contains one integer: N, the number of attendees (1 ≤ N ≤ 109).
Output
Output one integer: the smallest number of brains in the chest which allows Heidi to merely survive.
Examples
Input
1
Output
0
Input
3
Output
1
Input
99
Output
49
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
We are given a problem: It's about a game of proposals on how to distribute brains among N attendees (including Heidi). There are N-1 zombies and Heidi. They are all rational: each wants to maximize the number of brains they get; if they are indifferent, they prefer that fewer people die? Actually the previous subtask had conditions about when they vote. But here the problem says: "the same crowd is present, the N - 1 zombies have the exact same mindset as before and Heidi is to make the first proposal, which must be accepted by at least half of the attendees for her to survive." So this refers to the earlier subtask which likely had some description about voting on a distribution of brains, with zombies preferring to minimize survivors? Let's parse carefully.
We need to understand the game. I recall a classic problem: "Zombies and brains" possibly from a contest like "Heidi and the Zombies". The problem statement is about a group of N participants (Heidi plus N-1 zombies). They have a chest with some number of brains (integer). They propose distributions. The one who proposes must get at least half of the votes (including his own?) to survive; otherwise the proposer is killed. Then the next in line makes a proposal, and so on. The zombies are rational and have preferences: they want to maximize their own number of brains; if tied, they prefer fewer survivors (i.e., they like to kill others? Actually in many such games, voters might prefer outcomes where they live, but here being killed might be a downside? In the standard "pirate game", pirates vote on a distribution; if the proposal gets at least half (or 50% depending) they accept; else proposer is killed. The classic puzzle: pirates (or zombies) are rational, want to maximize gold, and if indifferent, prefer to kill the proposer. But here they want to minimize the number of survivors? Possibly that was a twist.
But the problem says: "the N - 1 zombies have the exact same mindset as before". That implies we need to know the previous subtask's description. Since we don't have it, we need to infer from examples and known puzzles.
We have inputs and outputs:
N=1 -> output 0.
N=3 -> output 1.
N=99 -> output 49.
Let's see pattern: For N=1, only Heidi, so she survives trivially even if empty chest (0). For N=3, she needs at least 1 brain to survive. For N=99, she needs 49 brains.
Maybe the answer is ceil((N-1)/2)? For N=3, (3-1)/2=1 => 1. For N=99, (99-1)/2=49 => 49. For N=1, (1-1)/2=0 =>0. So that fits: output = floor((N-1)/2)? Actually (N-1)/2 rounded up? For N=3, (3-1)/2=1 exactly. For N=99, (99-1)/2=98/2=49 exactly integer. So it's (N-1)/2 if N odd? But for even N? Not given. Let's test N=2: According to formula, (2-1)/2=0.5, ceil would be 1? But we don't know. Let's think: If N=2, Heidi and one zombie. The condition: proposal must be accepted by at least half of the attendees. At least half of 2 is 1? "at least half" meaning >= N/2? Typically, "at least half" might mean >= N/2? For N=2, half is 1, so she needs at least 1 vote, which could be her own? Usually the proposer's vote counts. So if only Heidi and one zombie, she can survive if she gets her own vote? That would be 1 vote, which is at least half? 1 >= 1, yes. So she could survive with 0 brains? But the zombie wants brains? He might vote no if he gets nothing? But Heidi can propose distribution: maybe give 0 to zombie, keep all brains (if any). The zombie will vote no if he gets 0? But if no brains, maybe he would vote no. However, in rational behavior, if the proposal is rejected, what happens? The proposer is killed? Then the next in line? But if Heidi is killed, then the zombie becomes the proposer? Actually with N=2, if Heidi's proposal is rejected, she dies, and then the zombie is the only attendee? But the process: "Heidi is to make the first proposal, which must be accepted by at least half of the attendees for her to survive." So if she doesn't get enough votes, she is killed. Then presumably the next in line (maybe the zombie) makes a proposal, but that doesn't involve Heidi. The question: "what is the smallest number of brains that must be in the chest for her to get out at all (possibly empty-handed, but alive)?" So we want the minimal B such that there exists a proposal that Heidi can make that will be accepted, ensuring she survives (though she might get 0 brains). She could propose to give all brains to the zombie, keep 0? That would give the zombie all brains, so zombie would vote yes because it's better than alternative? What is the alternative if proposal fails? Heidi dies, then the zombie is alone? With just the zombie, he would get all brains anyway, and survive? Let's think.
The standard "pirates and gold" game: There are N pirates (including proposer). They are rational, value gold first, then life (i.e., they want to survive). The proposer makes a distribution. If at least half (including proposer) vote yes, it's accepted. If not, proposer is killed and the next in line proposes. In that game, the analysis yields a specific distribution that works for any number of gold coins. But here the number of brains is variable; we want the minimal number such that Heidi can survive. That sounds like: given N, what is the minimum B such that there exists a distribution of B brains among N participants that will be accepted by at least half.
But from examples, N=3 -> B_min=1. In standard pirate game with N=3, the proposer (lowest rank) needs to secure votes from himself and one other. The classic solution: for 3 pirates (A, B, C with A being highest? Actually there's a ranking). But here there is no ranking; they are all equal? But there is an ordering? In these types of games, there is a fixed order of who proposes next if the current proposer is killed. That influences voting because voters compare the proposal to what they would get if the proposer is killed. So there is an order. Typically, it's assumed there is a hierarchy: maybe the attendees are lined up by age or something: Heidi first, then zombie1, zombie2, ... etc. The problem statement: "the same crowd is present, the N - 1 zombies have the exact same mindset as before and Heidi is to make the first proposal, which must be accepted by at least half of the attendees for her to survive." This hints that there is a known game from a previous subtask. Perhaps it's the classic "brain dinner" problem: N participants (including Heidi) with a chest of B brains. They are arranged in a fixed order (maybe by decreasing age or something). The youngest (Heidi) proposes first. She must get at least half (ceil(N/2)? Or N/2? "at least half" might mean strictly more than half? Usually "at least half" means >= N/2. Since votes are integer, and if N is odd, N/2 is not integer; e.g., N=3, half is 1.5, at least half means >= 1.5 => 2 votes. That would be a typical condition: the proposer needs a strict majority? Actually many puzzles say "more than half". But "at least half" is ambiguous. They say "must be accepted by at least half of the attendees". In the context of voting, "at least half" usually means at least N/2, meaning if N is even, exactly half is sufficient; if N is odd, at least (N+1)/2 because N/2 is fractional but they compare to integer votes. For example, with N=3, half is 1.5, so at least half means at least 2 votes? Or could it be interpreted as "at least half" meaning "at least 50%", so you need ceil(N/2) votes? Typically in puzzles, they require strict majority: >50%, i.e., more than half, which for N=3 is 2, for N=4 it's 3. But they say "at least half", which is less strict: for N=3, 2 is at least half (2 >= 1.5) but 1 is not (1<1.5). So it's the same as ceil(N/2)? Because ceil(N/2) yields: N=3 ->2, N=4->2? Wait ceil(4/2)=2, but is 2 at least half of 4? 2 is exactly half, so it qualifies. So "at least half" means >= N/2, not necessarily > N/2. So if N is even, exactly half is enough; if N is odd, you need at least (N+1)/2 because N/2 is not integer, so the condition is >= N/2, meaning the smallest integer >= N/2, which is ceil(N/2). So effectively it's ceil(N/2). That matches typical "at least half". For N=4, ceil(4/2)=2. So proposer needs 2 votes out of 4. That is a weaker condition than majority. This could affect results.
Now the examples: N=3, answer=1. If Heidi needs 2 votes out of 3 (herself plus at least one zombie). The minimal brains required to get at least one zombie to vote yes is 1? Possibly. For N=99, answer=49. If Heidi needs ceil(99/2)=50 votes? Actually ceil(99/2)=50. But she herself votes yes always? She would vote yes if she stays alive? In rational voting, she votes yes if the proposal gives her at least as much as she'd get if it fails (i.e., if she dies, she gets nothing, so she'd vote yes if she gets 0? Actually if she dies, she gets 0; but if proposal passes she lives, and maybe gets some brains. But she values survival? The zombies also value survival? The description: "the same crowd is present, the N - 1 zombies have the exact same mindset as before". Without the full description, we need to reconstruct the mindset.
Let's search memory: There is a known problem from Codeforces? Maybe "Brain Dinner" or "Heidi and the Zombies" is from a competition like the ICPC? I recall a problem from Google Code Jam? Hmm.
Alternatively, maybe it's a simpler reasoning: Heidi wants to survive, not necessarily get a brain. She can propose to give away all brains to some subset of zombies to secure their votes. The zombies are rational: they will vote for the proposal if and only if they get at least as many brains as they would get if the proposal fails (and Heidi is killed) and then the next in line (maybe the next youngest zombie) makes a proposal. However, the zombies also prefer that fewer people survive? There might be a tie-breaking rule: if they are indifferent between the proposal outcome and the alternative (i.e., the number of brains they get is the same), then they vote in a way that minimizes the number of survivors (or maximizes kills). In the classic "pirate game", the tie-breaker is that they would vote to kill the proposer if they are indifferent (i.e., they enjoy killing). But here maybe the zombies want to minimize survivors? Or perhaps they prefer to kill Heidi? I need to check examples: For N=3, answer is 1. Let's simulate with N=3, B=1, and see if Heidi can survive. With B=0, maybe she can't. Why? Let's hypothesize the rules.
Assume participants are ordered: Heidi is the youngest? Or something like that. Typical "pirate game" has a hierarchy: the oldest is the captain first, but if he dies, the next oldest becomes captain. However, here "Heidi is to make the first proposal". So she is first proposer. Then there is an ordering of the zombies: perhaps they are ordered by age (oldest to youngest) or something. The previous subtask might have defined that: "the N - 1 zombies have the exact same mindset as before" so we need that info. Possibly the mindset: each zombie wants to maximize the number of brains they get; if they are indifferent, they would like to see Heidi dead (or fewer survivors). Or maybe they want to minimize the number of survivors? Let's attempt to derive from logic.
In many voting games, the voters' preferences: first priority: stay alive (if they are at risk of being killed). But in this game, only the proposer is at risk if the proposal fails. The voters (other than proposer) are not killed if the proposal fails, only the proposer is killed. So they do not risk their lives by voting no; they only affect whether the proposer dies. So the tie-breaking might include a preference about deaths. In the classic pirate game, pirates want to maximize gold, and if they are indifferent, they prefer to see the proposer die (so they vote no in ties). That ensures a stable solution.
Given the output B_min = (N-1)/2 (when N odd) and possibly B_min = floor((N-1)/2) for even? Let's test N=2: According to that pattern, (2-1)/2 = 0.5 -> rounding up gives 1? But maybe for even N, answer is (N/2) - 1? For N=4, (4-1)/2=1.5, ceil=2? Or floor=1? Let's see if we can infer from logic.
Maybe the rule is: the proposal must be accepted by at least half of the attendees, i.e., >= N/2 votes. Heidi always votes for her own survival (since she wants to survive). So she needs at least ceil(N/2) - 1 other votes if she votes yes. But does she always vote yes? She wants to survive. If the proposal fails, she dies. So she will vote yes regardless of brains, because she'd rather survive (presumably). So Heidi's vote is guaranteed yes.
Now zombies will vote yes if the proposal gives them at least as many brains as they would get if the proposal fails (i.e., if Heidi dies). To compute that, we need to consider what happens after Heidi's death. The game continues with the remaining N-1 participants (the zombies). The order among zombies is fixed (maybe by age). The next proposer (the youngest? or oldest?) will make a proposal. That proposal will also require at least half of the then attendees to pass (>= (N-1)/2). The process continues until maybe only one remains.
We are asked: smallest number B such that Heidi can survive (i.e., there exists a distribution that will get at least half votes). She can allocate brains arbitrarily to zombies (and possibly keep some for herself). She wants to minimize B needed to secure enough votes.
So this is reminiscent of the classic "pirates and gold" problem where the minimal number of gold coins needed for the first proposer to survive is something like floor((N-1)/2) or something. Actually, in the classic puzzle, with 5 pirates, 100 gold coins, the proposer (lowest rank) can secure votes by giving 1 coin to two other pirates. The pattern: the proposer needs votes from half (or majority) of the pirates. In the classic version, the proposer needs to buy off the pirates who would get nothing in the next round. The number of votes needed (besides his own) is floor((N-1)/2) for strict majority? Let's recall: Classic puzzle: There are N pirates, they are rational, they value gold > life, and if a proposal is rejected, the proposer is killed. They have a strict hierarchy (oldest to youngest) and the oldest proposes first. They need a majority ( > 50%) to accept. The solution: for N=1, he takes all. For N=2, the older needs the vote of the younger; younger will get all if older dies, so older must give all to younger to survive. For N=3, the oldest needs 2 votes (including his own). He can buy the youngest by offering 1 coin (because if he dies, the middle will propose giving nothing to youngest, and youngest gets 0; so 1 coin is better). So he gives 1 to youngest, keeps rest, gets votes from himself and youngest. For N=4, he needs 3 votes. He can buy two pirates: the ones who would get 0 in the N=3 scenario. The N=3 scenario: if he dies, the next oldest (call him 2) will propose, and in that scenario, 2 would keep 99? Actually with 3 pirates (2,3,4), the proposer (2) would need 2 votes; he would take 1 vote from the youngest (4) by offering 1 coin, and keep the rest. So pirate 3 gets 0 in that scenario. So for N=4, the proposer (1) can offer 1 coin to pirate 3 (who would get 0 otherwise), and maybe also to pirate 4? But he needs 3 votes total, his own plus 2 others. He could give 1 coin to pirates 3 and 4? But pirate 4 would get 1 coin in the N=3 scenario? Actually let's compute: With N=4: Pirates: A (oldest), B, C, D (youngest). The order: A proposes first. If he dies, B proposes to {B,C,D}. In that subgame with 3 pirates, B (the oldest among remaining) proposes. In that subgame, B needs 2 votes out of 3 (since majority > 50%? Actually need > 1.5, so 2). B can secure his own vote and one other. The optimal proposal for B: he gives 1 coin to D (youngest), 0 to C, and keeps the rest. Because if B dies, then C proposes to {C,D}. In that subgame with 2, C needs both votes? Actually with 2, C proposes; he needs at least half? In strict majority > 50% for 2, need >1, so need 2 votes (including himself). He would give all to D to secure D's vote, and keep 0? But then he dies if D votes no? Let's do properly: The classic puzzle uses strict majority: > N/2. For N=2, >1 => 2 votes needed, so proposer must get both votes. So in subgame with 2 pirates (C and D), C proposes. He can offer all coins to D, keep 0, and D votes yes (gets all), C votes yes? Actually C will vote yes because if proposal fails, C dies, and D becomes sole survivor and gets all coins. So C gets 0 either way, but he might vote yes to stay alive? In classic puzzle, the pirates prioritize gold over life? Actually typical: they value gold first, survival second. So C would compare: if proposal passes: he gets 0 gold, lives; if fails: he dies, gets 0 gold (since dead). Since gold equal, he would prefer to stay alive, so he votes yes. But in many versions, they consider that pirates are bloodthirsty and would vote to kill if indifferent. There are variations.
Anyway, the classic solution yields a pattern: the proposer always gets votes from pirates who would get 0 in the next round. The number of such pirates is something like floor((N-1)/2). Actually, for N odd, the proposer can secure (N-1)/2 votes by giving 1 coin each to those who would get 0. For N even, the proposer might need to give 1 coin to (N/2) - 1? Let's derive.
Alternatively, there is known problem: "Heidi and the Zombies" from some contest. I recall a problem on Codeforces: "Heidi and the Brain Dinner" maybe? Let me search memory: I think there is a problem from Codeforces Round #618 (Div. 2) or something? Actually, I recall a problem named "Heidi and the Brain" from Google Kick Start? Not sure.
Maybe we can find pattern: The answer for N=1 is 0, N=3 is 1, N=99 is 49. That's floor((N-1)/2) for N odd. For N=2, floor((2-1)/2)=0. So if N=2, answer would be 0. Is that plausible? With Heidi and one zombie. Heidi needs at least half votes: For N=2, half=1 (since at least half means >=1). She has her own vote. So if she votes yes, that's 1 vote, enough. So she can survive with 0 brains, regardless of zombie's vote? But does the condition require acceptance by at least half of the attendees, and does it count only yes votes? Usually voting: each attendee votes yes or no; if number of yes votes is at least half, it's accepted. Heidi can vote yes. So 1 yes out of 2 is enough. So she would survive with B=0. However, the zombie might also vote, but even if he votes no, total yes=1, which is half (since half of 2 is 1), so accepted. So yes, she survives. So answer for N=2 should be 0. That fits floor((N-1)/2) = 0.
Now test N=4: According to floor((4-1)/2)=1. So answer would be 1. Let's see if that makes sense. With N=4: Heidi plus three zombies. She needs at least half: N/2 = 2, so needs 2 yes votes (since half is 2, at least half means >=2). She votes yes herself, so she needs at least one more yes. So with B=1, can she buy one zombie's vote? Possibly. But need to consider what zombies would get if she dies. We need to model the subgame.
Let's try to formalize:
We have N participants, including Heidi (call her H) and zombies Z1, Z2, ..., Z_{N-1}. There is an order: maybe by age? The previous subtask likely defined: they are arranged by increasing age (or something), and Heidi is the youngest? Or maybe Heidi is the one who makes the first proposal because she's the "youngest" (or because she's the human). In many puzzles, the proposer is the one with the least seniority. But here Heidi is making the first proposal. The problem states: "Heidi is to make the first proposal". It doesn't specify order after that. But we can infer that after Heidi dies, the next proposer is the one with the next attribute (maybe the oldest zombie). Could be that the zombies are ordered by age (the older, the more respected). So there is a known ordering. Let's assume zombies are ordered: Z1 (oldest), Z2, ..., Z_{N-1} (youngest). After Heidi dies, the oldest zombie (Z1) proposes, then if he dies, Z2, etc. Or maybe it's the youngest? Actually, typical pirate game: the captain is the oldest; when he dies, the next oldest becomes captain. So that is a common ordering: oldest first. But here Heidi is not necessarily the oldest; she's making the first proposal. That could be because she's the human. So maybe she's considered the "youngest" and thus goes first? In some versions, the youngest proposes first. But we can define order arbitrarily; but the answer pattern might be symmetric.
Given the examples, we can try to derive the recursion for minimal brains required for a proposer to survive given that they have to secure at least half votes.
Let's define f(N) as the minimal total brains needed for the first proposer (call him player 1) to be able to survive (i.e., propose some distribution that gets at least half votes). Possibly the distribution can allocate 0 to some and give away brains. The proposer wants to survive, but may get 0 brains; we just want existence of some proposal that gets the votes.
We assume that participants are rational and have the following preferences (likely from previous subtask):
Primary: Maximize number of brains they get.
Secondary: Minimize number of survivors (or maximize deaths) — because they are zombies? Actually maybe they prefer to eat brains, and if they get same number of brains, they'd like to see more people die (i.e., fewer survivors) because they are hungry? Or maybe they want to kill Heidi? The phrase "the N - 1 zombies have the exact same mindset as before" suggests we need to recall the prior subtask.
Given the minimal B for N=3 is 1, we can attempt to determine the tie-breaking rule.
Let's try to model with N=3: H, Z1, Z2. Suppose ordering: after H, perhaps Z1 then Z2? Or Z2 then Z1? The result may vary. We need to know which zombies get what in the subgame.
We can attempt to solve using standard rational voting with the following assumptions:
Each voter votes yes if the proposal gives them strictly more brains than they would get if the proposal fails.
If the proposal gives them exactly the same number of brains, then they vote according to some tie-breaker: maybe they vote no (because they like to see the proposer dead) or they vote yes? In many puzzles, they vote no in ties to cause death.
Also, voters consider their survival? In subgames, only proposers are at risk; voters are not at risk. So their survival is not on the line; only the proposer's survival is at stake. So they don't have a survival incentive; they only care about brains.
But wait: In the subgame, if a voter is the proposer later, his survival might be at risk when he proposes. However, when voting on Heidi's proposal, zombies consider the outcome if Heidi dies: then the game proceeds with the remaining zombies. In that continuation, each zombie could be the proposer at some point, and their survival might be at risk in those future proposals. So they care about both brains and survival (since if they die later, they get no brains). So we need to model full game-theoretic rationality: each zombie, when voting, compares the expected payoff (brains they ultimately receive) in the two branches: if Heidi's proposal passes vs if it fails and the game continues. They want to maximize their expected number of brains; if equal, they might have a secondary preference about the number of survivors (maybe they prefer more deaths?).
This is a classic sequential voting game with perfect information. It can be solved by backward induction.
Given the constraints N up to 1e9, the answer likely has a simple closed form like floor((N-1)/2). So it's plausible that the solution is independent of the tie-breaking details (maybe because we are looking for minimal B to survive, and with B = floor((N-1)/2) Heidi can always secure enough votes by giving 1 brain to a certain set of zombies). Let's test that hypothesis with a few small N by manually solving the game under some reasonable assumptions.
Assumption 1: Ordering: The participants have a predetermined order. After a proposer is killed, the next proposer is the one with the highest seniority among the survivors? Or maybe the lowest? We need to decide.
Often in such puzzles, the order is from oldest to youngest, and the oldest proposes first. But here Heidi is the first proposer; perhaps she is the youngest. So if she dies, the next proposer is the oldest zombie? Or the next youngest? Let's think: If ordering is by age (older more powerful), usually the oldest gets to propose first. But the problem says "Heidi is to make the first proposal". Maybe because she's the human, she gets to go first regardless of age. Then after she dies, the zombies might follow some order among themselves, perhaps from oldest to youngest (or something). But we can treat the ordering as H, then Z1, Z2, ..., Z_{N-1} in some order. The order will affect who gets what in subgames.
Given the pattern floor((N-1)/2) emerges from simple majority logic without needing ordering? Could be that the minimal number of brains needed is the number of voters that would vote against her if she offers nothing, and to win she needs to secure votes from enough zombies by giving each at least 1 brain, but some zombies might accept 0 if they would get 0 anyway in the subgame. The number of zombies that would get 0 in the subgame might be floor((N-1)/2). Then giving them 1 brain each ensures their vote.
Thus the minimal B = number of zombies that would get 0 in the subgame (if Heidi dies). That number may be floor((N-1)/2). Let's test for N=3: N-1=2 zombies. floor(2/2)=1. So one zombie gets 0 in the subgame, need to give him 1. That matches answer=1. For N=99: 98 zombies, floor(98/2)=49. Good. For N=1: 0 zombies, floor(0/2)=0. Good.
Now we need to verify for N=2: 1 zombie, floor(1/2)=0, so answer 0. That matches our earlier reasoning that Heidi can survive with 0 brains because she only needs her own vote? But does she need any other votes? With N=2, half=1, so she just needs 1 yes vote. She votes yes, so she doesn't need any zombie's vote. So 0 is indeed sufficient.
Now N=4: floor(3/2)=1. So answer would be 1. But is that correct? Let's simulate N=4 with some ordering assumptions to see if B=1 is indeed sufficient.
Let participants: H, Z1, Z2, Z3 (maybe ordered by something). Suppose the order after H dies is: Z1 then Z2 then Z3 (say Z1 is oldest, then Z2, then Z3). We'll do backward induction to determine what each zombie would get in the subgame if H dies, assuming there are B brains in the chest initially (but we are varying B). However, note that the number of brains is fixed; they are all to be distributed in the proposal. In the subgame, the total brains remain the same (they are not consumed). So the proposer at each stage proposes a distribution of the same total B brains among the remaining participants.
Thus for a given total B, we can compute the equilibrium outcome (via backward induction) of the game, assuming all are rational and have preferences: they want to maximize their own brains; if indifferent, perhaps they prefer to kill the proposer? But careful: In subgames, the proposer might also get killed if his proposal fails. So the equilibrium will be a subgame perfect Nash equilibrium (SPNE), typically unique given tie-breaking rules.
We need to find the minimal B such that in the initial subgame (with H proposing), there exists some proposal that will be accepted (i.e., get at least half votes). H can propose any division of the B brains among the N participants. She aims to survive (the question asks: smallest number of brains that must be in the chest for her to get out at all, i.e., to survive). She can be strategic. So we need to find if there is any proposal that, given the rational responses of others, will yield acceptance. She can choose to give away brains to secure votes.
Thus we need to characterize, for each B, the set of proposals that would be accepted. Then find minimal B where this set is non-empty.
Given N up to 1e9, the answer likely is simple: floor((N-1)/2) or maybe ceil((N-1)/2). For odd N, both are same. For even N, floor((N-1)/2) = (N-2)/2, ceil = (N)/2? Let's compute: N even, say N=4, N-1=3, floor(3/2)=1, ceil(3/2)=2. Which one is correct? Let's test with manual reasoning for N=4.
We need to derive the subgame outcomes for general B. Let's try to define the game formally.
Game G(N, B, proposer index i). Participants are ordered 1,2,...,N (maybe 1 is first proposer, then 2, etc.). In our initial state, proposer is Heidi (position 1). She proposes a division of B brains among the N participants. Then all participants vote. If the number of Yes votes is at least half of the current participants (i.e., >= ceil(N/2)? Actually "at least half" means >= N/2, which is integer if N even? But since votes are integer, condition is Yes >= ceil(N/2)? Because if N is odd, half is non-integer, so at least half means Yes >= (N+1)/2? For N=3, half = 1.5, so Yes must be >=2? Yes, because Yes is integer, the smallest integer >=1.5 is 2. So condition = ceil(N/2). For N even, ceil(N/2)=N/2. So condition is ceil(N/2). So needed Yes votes = M = ceil(N/2).
If the proposal gets at least M votes, it is accepted, brains are distributed accordingly, and everyone leaves (the game ends). If not, the proposer is killed (dies, gets 0 brains and out), and the game continues with the remaining N-1 participants, with the same total brains B, and the next in order (i+1, if we had ordering) becomes the proposer. The process repeats.
Participants are rational. They aim to maximize the number of brains they receive. If two outcomes give them the same number of brains, they have a secondary preference: they prefer that fewer participants survive (i.e., more deaths). This is common in such puzzles because zombies are hungry and want to eat brains? Or maybe they just like killing. The previous subtask probably stated something like: "Each zombie cares first about the number of brains they get; if that's equal, they want as few survivors as possible." This secondary preference is crucial to break ties, especially when a voter gets 0 in both branches.
In the classic pirate game, the tie-breaker is that pirates would vote to kill the proposer if they are indifferent, because they enjoy killing. That is analogous to preferring fewer survivors (since the proposer's death reduces survivors). But here "fewer survivors" might be the preference. We'll assume that.
Now we need to compute, for a given N and B, what is the outcome of the game under SPNE, and in particular, determine if there exists a proposal by player 1 (Heidi) that will be accepted.
Given the pattern, it's plausible that the minimal B is the number of players (other than Heidi) who would receive 0 brains in the continuation game if Heidi dies. Those players can be bribed with 1 brain to vote Yes, because they would otherwise get 0. But if there are players who would get 1 or more in the continuation, they would need at least that many to vote Yes. But Heidi might not need to bribe them if she can secure enough votes using only the zero-receivers. The number of zero-receivers might be floor((N-1)/2). However, we need to confirm.
Let's attempt to solve the game recursively.
Define f(N) as the minimal number of brains that the first proposer (player 1) needs to have in the chest to be able to survive. But actually, we need to determine, for a given B, whether she can survive. So we want the smallest B such that she can survive.
Given the recursion of the game, we can compute, for any state (k players remaining, total B, and the proposer being the first among them), the set of possible outcomes and the minimal bribe needed for the proposer to secure acceptance.
But maybe we can derive that for any B, the equilibrium outcome is deterministic: the proposer will propose a distribution that gives 1 brain to certain players (those who would otherwise get 0) and 0 to others, and keep the rest. And this proposal will be accepted. This is typical when B is sufficiently large relative to the number of needed bribes. If B is too small (less than needed bribes), the proposer cannot get enough votes and will die. So the minimal B to survive for the first proposer equals the number of votes (besides her own) she needs to buy, each costing 1 brain, because she can bribe exactly those who would get 0 in the next round.
But is it always 1 brain per bribe? Could some need more than 1? Possibly if in the continuation they would get more than 0, they'd need that many plus 1? But we might not need to bribe them if we can get enough votes from zero-receivers. The number of zero-receivers may be enough to reach the required votes.
Let's compute the number of votes needed: The proposer (player 1) needs M = ceil(N/2) Yes votes. She always votes Yes (since if proposal fails she dies, and if it passes she lives; even if she gets 0 brains, she lives, so she prefers Yes). So she has 1 Yes. She needs M-1 additional Yes votes from others.
Now, in the continuation game after her death, there will be N-1 players. Let's denote what each of those players would get in that subgame (call it their "continuation payoff"). Under rational play, the subgame has a unique equilibrium outcome (given B). For each player i among the remaining, let c_i be the number of brains they would get if Heidi dies (i.e., in the subgame starting with the next proposer). This depends on B.
If Heidi proposes to give player i some amount x_i. Player i will compare x_i to c_i. If x_i > c_i, they will vote Yes (since they strictly gain). If x_i < c_i, they vote No. If x_i = c_i, they are indifferent: they must use tie-breaking. Under the secondary preference (minimize survivors), they would consider the number of survivors in each outcome. If they vote Yes, Heidi lives => survivors count = N (all live). If they vote No and that causes proposal to fail (if exactly enough votes are missing), then Heidi dies => survivors count = N-1 (since only Heidi dies). So fewer survivors if they vote No. Since they prefer fewer survivors, they would vote No when indifferent. Thus in the case x_i = c_i, they vote No. So effectively, to secure a Yes vote from player i, Heidi must offer strictly more than what they would get in the continuation. So she must offer at least c_i + 1 (since brains are integer). Actually if c_i is integer, offering c_i + 1 ensures > c_i. So the cost to bribe player i is (c_i + 1) if she wants their vote.
Thus, Heidi needs to choose a subset S of the other N-1 players, such that |S| >= M-1, and for each i in S, she offers at least c_i + 1 brains. She can offer others 0 (or any amount less). She wants to minimize the total brains she needs to give away (so that she can survive with as small total B as possible). But she can also keep some for herself; she doesn't care about maximizing her own brains, only survival. So given B, she can offer any distribution as long as sum of offered brains <= B. So the condition for existence of a proposal that gets accepted is: there exists a subset S of size at least M-1 such that sum_{i in S} (c_i+1) <= B (since she can give the rest to anyone, e.g., to herself). Actually she could give more to some, but minimal needed is that sum. Also, she must also consider that she might give brains to players not in S, but that would be wasteful; she can give them 0. So the necessary and sufficient condition (for a given B) is that the sum of the smallest (M-1) values of (c_i+1) among the N-1 players is <= B. Because she can pick the cheapest (M-1) players to bribe. Also, she could bribe more than needed, but minimal sum is to take the cheapest votes.
Thus, the minimal B that allows survival is exactly the sum of the smallest (M-1) of (c_i+1). But c_i themselves depend on B! Because c_i are the payoffs in the subgame which also depend on B. This is a recursive definition.
However, we might be able to show that in equilibrium, for the subgame of size k (with the same B), the minimal B needed for the proposer to survive is something like floor((k-1)/2) maybe? But let's try to solve recursively assuming that for smaller numbers, the pattern holds.
Let's denote for a game with n participants (ordered 1..n), total brains B. We want to know whether the current proposer (player 1) can survive. But we are interested in the minimal B for which player 1 can survive. For the initial game, n=N.
Define g(n) = the minimum total brains B such that in the game with n players (ordered, first proposer is player 1), the first proposer can guarantee survival (i.e., there exists a proposal that will be accepted in SPNE). Note: The existence of such a proposal depends on the subgame outcome for the remaining n-1 players, which itself depends on B. But we can define recursively.
Let's attempt to compute g(n) for small n under the assumptions.
Assumptions:
Players are numbered 1,2,...,n in order of proposing: player 1 proposes first, then if killed, player 2 proposes, etc.
All players are rational: they maximize their own brains; if tie, they prefer fewer survivors.
Voting rule: Proposal passes if Yes votes >= ceil(n/2). (At least half.)
Let’s also define, for a given n and B, the equilibrium outcome (what each player gets) under SPNE. This is similar to the classic "pirates and gold" problem but with "at least half" instead of "strict majority" and possibly different tie-breaking.
I recall known results: For the classic pirates game with "majority" (> half) and tie-breaking that they vote to kill if indifferent, the required number of coins to avoid death for the proposer is something like: for n pirates, the proposer needs to bribe the pirates who would get 0 in the next round; the number of such pirates is floor((n-1)/2). Actually, the classic: for 5 pirates, the proposer (captain) needs 2 votes besides his own, and gives 1 coin to pirates 3 and 5 (or something). So number of bribes = floor((n-1)/2). And the total coins needed for the proposer to survive is also floor((n-1)/2) if he has at least that many coins; if he has fewer, he dies. So the minimal coins needed is floor((n-1)/2). This matches our pattern for odd n but for even n, floor((n-1)/2) = (n-2)/2. Let's test for n=2: floor((2-1)/2)=0. So proposer (pirate 1) needs 0 extra votes? But with 2 pirates and strict majority, need >1 vote, i.e., 2 votes, so he needs the other's vote. In classic, with 2 pirates, the proposer must give all coins to the other to survive. So minimal coins needed? Actually if he has 0 coins, can he survive? He gives 0 to the other; the other gets 0; in the continuation if proposal fails, the other becomes sole survivor and gets all coins (0). So both outcomes give the other 0. According to tie-breaking, the other votes to kill (since prefers fewer survivors? Actually if the proposal fails, only one survivor (the other) vs two survivors if it passes. So they prefer fewer survivors, so they vote No. So proposer dies. So with 0 coins, he cannot survive. He needs to give at least 1 coin to the other? But if B=0, there is no coin to give. So minimal B might be 1 for n=2 in classic? But wait, in classic pirate puzzle, gold coins are indivisible and they have a fixed number like 100. But if there are 0 coins, does the proposer survive? I've seen variations: With 2 pirates and 0 gold, the proposer might die because the other pirate would vote no to kill. So minimal B=1. But our pattern gave 0 for n=2. That conflicts.
But in our problem, for N=2, we thought Heidi could survive with 0 because she needs only 1 vote (her own) since "at least half" with 2 is 1, so she doesn't need the other's vote. That is a key difference: classic requires > half (strict majority). Here it's "at least half", which for even n allows exactly half. So with n=2, she needs 1 Yes vote, which she can provide herself. So she doesn't need the zombie's vote. So she can survive regardless of B? But we must check: If she votes yes, that's 1 vote. The zombie may vote no, but total yes =1, which meets the threshold (1 >= 1). So the proposal passes. Does the zombie's vote matter? The rule is: accepted by at least half of the attendees. If yes votes >= ceil(n/2)? Actually we determined it's ceil(n/2). For n=2, ceil(2/2)=1. So yes, 1 yes is enough. So even if all others vote no, the proposal passes as long as she votes yes. So she always survives, independent of B. So answer for N=2 should be 0. That matches floor((N-1)/2)=0. Good.
Now for n=4, she needs M = ceil(4/2) = 2 Yes votes. She votes yes, so needs at least 1 more Yes. So she must bribe at least one zombie. So B must be at least the minimal cost to bribe one zombie. So B_min = min_i (c_i+1). The c_i are what each zombie gets in the subgame (with 3 players). So we need to compute c_i for a game with 3 players and total brains B. But c_i depends on B. However, we are looking for the smallest B overall such that there exists a proposal that passes. So we need to find B such that there exists at least one zombie i with c_i such that c_i+1 <= B (i.e., we can bribe that zombie with 1 brain if c_i=0, or with more if c_i>0). Since we want minimal B, we would hope there is a zombie with c_i=0 for some B, so that we can bribe with 1 brain. So the minimal B might be 1 if there exists a zombie who gets 0 in the subgame when total brains = 1? But we need consistency: c_i are defined based on B, so we need to solve the subgame for each B.
Let's attempt to compute c_i for n=3 (the subgame after Heidi dies) as a function of B.
We have three zombies (ordered say Z1, Z2, Z3). The proposer is the first among them (Z1). The game rules same: need at least half of the participants: ceil(3/2)=2 Yes votes. Z1 votes Yes (to survive). So he needs at least 1 more Yes from Z2 or Z3. He will propose a distribution of B brains among Z1, Z2, Z3. He wants to survive, and also wants to maximize his own brains (but for the purpose of computing c_i, we need to determine the equilibrium outcome; Z1 will choose a proposal that gets accepted and maximizes his own brains; if no proposal gets accepted, he dies and the game continues with two players, etc. But the question is: for a given B, what will happen? However, note that when computing c_i for the subgame, we don't care about Z1's desire to maximize his own brains? Actually, we need to determine what payoff each zombie gets in the subgame, assuming rational play. That payoff is the result of the SPNE where the proposer (Z1) chooses an optimal proposal that will be accepted if possible, and if not, he dies and the game goes to next stage.
But importantly, the subgame's outcome might be such that some zombies get 0, some get something.
Let's compute for n=3.
Case n=3, players: 1 (proposer), 2, 3.
We need to find for any B, the equilibrium.
First, consider the base case n=1: If only one player, that player gets all B brains, no vote needed (since no voting? Actually with 1 attendee, proposal automatically accepted? But rule says "accepted by at least half of the attendees". With 1, half is 0.5, so at least half means 1 vote? Actually if only one attendee, they vote; the proposer is also the only voter. They need at least half, i.e., ceil(1/2)=1? 1/2=0.5, ceil=1. So they need their own vote. Since they will vote yes (they survive), it's accepted. So yes, they get all B.)
But we need to compute recursively for n=2, n=3, etc.
Let's define for a given n and total brains B, the SPNE outcome as a vector (p1, p2, ..., pn) of brains each receives (with sum = B) if the proposer survives; if the proposer dies, then the outcome is determined by the subgame with n-1 players (with the same B). Actually, if proposer dies, we go to next stage, so the final distribution is determined eventually when a proposal is accepted.
We can define for each state (set of players, order, B) the expected payoff for each player at the start of that state, assuming optimal play.
We want to compute for the state with n players, B brains, player 1 proposer.
Let M = ceil(n/2). Player 1 needs M votes. He can propose a distribution (x1,...,xn) with sum = B. The players will vote: player i (i!=1) votes Yes iff x_i > y_i, where y_i is the payoff they would get in the continuation if this proposal fails (i.e., if player 1 dies). Player 1 votes Yes (since if proposal fails he dies, so he always prefers Yes, unless he is indifferent about survival? But he prefers survival because that gives him at least x1 >=0 vs death with 0; plus if he is indifferent about brains, survival gives him chance to get brains; so Yes).
If x_i = y_i, then due to tie-breaking (prefer fewer survivors), they vote No because fewer survivors occur if proposal fails (since player 1 dies). So Yes requires x_i > y_i.
Thus, for player 1 to get his proposal accepted, he must choose a set S of at least M-1 other players such that for each i in S, x_i > y_i, and for i not in S, he can set x_i arbitrarily (maybe 0). He wants to maximize his own x1, but we just need existence.
The continuation payoffs y_i are known (from the subgame with players 2..n, with proposer = player 2). Note that those y_i sum to B (since total brains are distributed eventually). Also, y_2 is the payoff of player 2 as proposer if player 1 dies, etc.
So we have a recursion.
Now, we are interested in the minimal B for which player 1 can survive. In other words, find smallest B such that there exists a proposal that gets accepted. Since player 1 can always propose to give away brains, we need to check if there exists a set S of size at least M-1 for which sum_{i in S} (y_i + 1) <= B (since he can give exactly y_i+1 to each in S, and give 0 to others, and keep the rest (including possibly 0) for himself). But we must also consider that the y_i themselves depend on B. This is a fixed point.
But perhaps the minimal B is simply the number of players that would get 0 in the continuation when B equals that number? Let's try to compute for small n to see pattern.
We'll compute for n=1: M=ceil(1/2)=1. Player 1 always survives (needs 1 vote, his own). So g(1)=0 (no brains needed). Actually with B=0, he can propose (0) and it passes. So g(1)=0.
Now n=2: M=ceil(2/2)=1. So player 1 needs only his own vote to pass. He doesn't need any other votes. So he can survive for any B>=0. So g(2)=0. That matches floor((2-1)/2)=0.
Now n=3: M=ceil(3/2)=2. So player 1 needs his own vote + at least 1 other Yes. So he must bribe at least one player i (i=2 or 3) with x_i > y_i. Minimal extra cost is min_i (y_i+1). We need to compute y_i for n=3 subgame (players 2 and 3? Actually continuation after player 1 dies is a game with n-1=2 players, with players 2 and 3, and proposer = player 2). So we need to compute the payoffs for players 2 and 3 in a 2-player game with total brains B.
Let's compute y_2 and y_3 as functions of B for the 2-player game.
Game with n=2, players (2,3). M=ceil(2/2)=1. Proposer (player 2) needs at least 1 Yes vote. He votes Yes, so he needs 0 other votes. Therefore, he can always survive regardless of B, by simply voting Yes and proposing any distribution. But he wants to maximize his own payoff? Actually we need to determine the equilibrium outcome. In SPNE, the proposer will propose a distribution that maximizes his own payoff, subject to being accepted. Since he only needs his own vote, he can propose to give all B to himself and 0 to player 3. Will player 3 vote? He can vote No, but it doesn't matter because only 1 Yes vote is needed. So the proposal passes with just player 2's Yes. So the outcome: player 2 gets B, player 3 gets 0. But is there any reason player 2 would give anything to player 3? No, because he wants to maximize his own brains. So the equilibrium outcome for n=2 is: (B,0). So y_2 = B, y_3 = 0. (We need to check tie-breaking: player 3 gets 0. In the proposal, x_3=0. If proposal fails, player 2 dies, then player 3 becomes sole survivor and gets B. So player 3's continuation payoff if proposal fails is B. So for player 3, y_3 (the payoff if the proposal of player 2 fails) is B? Wait careful: y_i defined earlier is the payoff player i gets in the continuation if the current proposer (player 1) dies. That continuation is the game with players 2 and 3, starting with player 2 as proposer. The eventual payoffs from that subgame are not necessarily the same as if player 2's proposal fails; they are the equilibrium outcome of that subgame. In the subgame with players 2 and 3, player 2 as proposer will propose a distribution. In equilibrium, that proposal will be accepted (since he can always get his own vote). So the outcome is (B,0). So indeed, player 2 gets B, player 3 gets 0. So y_2 = B, y_3 = 0.
Thus, for n=3, the continuation payoffs are: y_2 = B, y_3 = 0.
Now player 1 needs to bribe at least one player with x_i > y_i. For player 2, that would require x_2 > B, i.e., at least B+1, which is impossible because total brains are B. For player 3, requires x_3 > 0 => x_3 >= 1. So the cheapest bribe is to give 1 brain to player 3. So player 1 can survive if he can offer at least 1 to player 3. That requires B >= 1? But he also needs to allocate something to himself? He can keep the rest (B-1) for himself. So condition: B >= 1. Thus g(3)=1. That matches the example.
Now n=4: We need to compute g(4). M = ceil(4/2)=2. Player 1 needs at least 1 other Yes. Continuation after player 1 dies: game with players 2,3,4, proposer=player 2. We need to compute the payoffs y_2, y_3, y_4 for that 3-player game, as functions of B. Denote f3(B) as the payoff vector for a 3-player game (players 1,2,3 with player 1 proposer). But here the players are 2,3,4 with player 2 proposer. Since the game is symmetric aside from labeling, the payoffs for the proposer, second, third in a 3-player game depend on B. Let's compute the equilibrium for n=3 for any B.
We already have analysis for n=3: The proposer (call him P) can survive if B >= 1? But wait, for n=3, we determined that the proposer always can survive? Actually from earlier, for n=3, player 1 (proposer) needed to bribe at least one player. The cheapest bribe was to give 1 to the player who gets 0 in the continuation of the 2-player subgame. In the 2-player subgame, the proposer (player 2) gets all, the other gets 0. So in the 3-player game, the proposer can always survive if B >= 1? But what if B = 0? Then he cannot bribe player 3 because he would need to give at least 1. So with B=0, can he survive? Let's check: For n=3, B=0. Then continuation after his death is a 2-player game with B=0; in that subgame, player 2 (proposer) gets 0, player 3 gets 0. So y_2 = 0, y_3 = 0. Player 1 needs at least one Yes from others. To get player 2's Yes, he needs x_2 > 0 => x_2 >= 1, impossible. Same for player 3. So no bribe possible. Therefore, with B=0, player 1's proposal will be rejected (since only his own vote, which is 1, but needs 2 votes). So he dies. So for n=3, the proposer survives iff B >= 1. So the minimal B for survival is 1. That's consistent with our earlier g(3)=1.
Now we need to compute the equilibrium payoffs for n=3 when B is arbitrary (>=1). In the equilibrium, what will player 1 (proposer) propose? He will maximize his own share. He needs to secure 1 additional vote. The cheapest is to bribe player 3 (since y_3=0), giving him 1 brain. He can give 0 to player 2. He will keep B-1 for himself. Player 2 gets 0. Player 3 gets 1. This proposal will be accepted: player 3 votes Yes (since 1 > 0), player 2 votes No (0 = y_2? Actually y_2 =? For n=3, y_2 is the payoff player 2 would get if player 1 dies. In the 2-player subgame with B, player 2 (proposer) would get B, player 3 gets 0. So y_2 = B. Since x_2=0, 0 < B, so player 2 votes No. Player 1 votes Yes. Total Yes votes: player 1 and player 3 => 2, meets M=2. So accepted.
Thus equilibrium outcome for n=3 (when B >= 1) is: (B-1, 0, 1). If B = 0, the proposer dies, and then the subgame with players 2 and 3 leads to outcome (0,0) (since 2-player game with B=0 gives 0 to both). So payoffs: (0,0,0)? Actually after player 1 dies, player 2 proposes with B=0, he gets 0, player 3 gets 0. So final distribution is (0,0,0). So for B=0, all get 0.
Now back to n=4. The continuation payoffs y_2, y_3, y_4 are the equilibrium payoffs of a 3-player game with players 2,3,4 and total brains B, with player 2 as proposer. That depends on B.
Case 1: B = 0. Then in the 3-player subgame, with B=0, as argued, the proposer (player 2) dies because cannot bribe (since B=0). Then the game reduces to 2-player (3,4) with B=0, where player 3 as proposer gets 0, player 4 gets 0. So final payoffs: player 2 dies? Actually if player 2 dies, he gets 0. Then players 3 and 4 get 0 each. So the outcome is (0,0,0) for players 2,3,4? But careful: After player 1 dies, the game starts with players 2,3,4. Player 2 proposes. If his proposal is rejected, he dies. Then players 3,4 remain. Player 3 proposes. With B=0, player 3 can survive (since n=2, he only needs his own vote). He will propose (0,0) and it passes. So final: player 2 gets 0 (dead, so 0), player 3 gets 0, player 4 gets 0. So y_2 = 0, y_3 = 0, y_4 = 0.
Now for n=4 with B=0, player 1 needs M=2 votes. He votes yes, needs 1 more. To get a Yes from any other, he must offer > y_i. Since all y_i=0, he needs to offer >=1 to some i. But B=0, impossible. So he dies. So B=0 not sufficient.
Case 2: B = 1. Then in the 3-player subgame (players 2,3,4) with B=1, what are the equilibrium payoffs? We have analysis for 3-player: if B >=1, the proposer (player 2) can survive and will propose: keep B-1 = 0 for himself? Actually B=1, so he gives 1 to the cheapest bribe. Who is the cheapest? In that subgame, the continuation after player 2 dies is a 2-player game with players 3,4 and B=1. In that 2-player game, the proposer (player 3) would get all 1, and player 4 gets 0. So the continuation payoffs for players 3 and 4 are: if player 2 dies, then player 3 gets 1, player 4 gets 0. So for player 2's proposal, the y'_3 (payoff if his proposal fails) = 1, y'_4 = 0. (Here we use primes to distinguish levels.) Player 2 needs 1 additional Yes (since M=2 for n=3). He can bribe player 4 (cheapest) by offering 1 (since y'_4=0, need >0 => at least 1). He gives 1 to player 4, 0 to player 3, and keeps 0 for himself. That yields proposal: (0,0,1) for (2,3,4). Player 4 votes Yes (1>0), player 3 votes No (0<1), player 2 votes Yes. So accepted. So outcome: player 2 gets 0, player 3 gets 0, player 4 gets 1.
Thus y_2 = 0, y_3 = 0, y_4 = 1. (But wait, is that the only equilibrium? Could player 2 bribe player 3 by offering >1? That would require at least 2, not possible. So yes.)
Now, with B=1 for n=4, player 1 needs to secure 1 additional Yes. She can bribe any player i with x_i > y_i. y_2=0, y_3=0, y_4=1. The cheapest bribe is to player 2 or 3 with at least 1 brain. So she could give 1 brain to player 2 (or 3). That would cost 1. Since total B=1, she can give that 1 to player 2, and 0 to others, and keep 0 for herself. Then votes: player 1 Yes, player 2 Yes (1 > 0), player 3 No (0 = 0? Actually y_3=0, so 0 is not >0, so No), player 4 No (0 < 1? Actually y_4=1, 0<1 so No). Total Yes = 2 (players 1 and 2) which meets M=2. So passes. So Heidi survives with B=1.
Thus g(4) <= 1. We already saw B=0 fails, so g(4)=1. That matches floor((4-1)/2)=1. Good.
Now n=5: Let's test to see if pattern holds: predicted g(5)= floor((5-1)/2)=2. Let's simulate with our recursion to verify.
First, compute g(5) minimal B for player 1 survival.
M = ceil(5/2)=3 (since 5/2=2.5, ceil=3). So player 1 needs 2 other Yes votes.
Continuation after player 1 death: 4-player game (players 2,3,4,5) with proposer player 2. We need to know the payoffs y_i for i=2..5 as functions of B. Let's compute the equilibrium for n=4 as a function of B. We already have for n=4, we know that for B=0, outcome (0,0,0,0) (proposer dies). For B=1, outcome we computed: player 1 (of that subgame) = player 2 gets 0, player 3 gets 0, player 4 gets 1? Wait we computed for n=4 subgame earlier with players 2,3,4, B=1, we got y_2=0, y_3=0, y_4=1. But we need general pattern.
Let's compute the 4-player game in general.
Define state with n=4, players A (proposer), B, C, D. Let total brains = T. We need to find equilibrium payoffs as function of T.
We know the continuation after A dies is a 3-player game with players B,C,D, proposer B, total brains T.
Let’s denote for the 3-player subgame the equilibrium payoffs: (p_B, p_C, p_D) where p_B = if T>=1 then T-1? Actually from earlier, for n=3, the proposer (call him P) gets T-1 (if T>=1) and the third player (the one who would get 0 in 2-player) gets 1, the second gets 0. But careful: In the 3-player game, players are ordered: 1 (proposer), 2, 3. The continuation after proposer death is 2-player (2 and 3). In that 2-player, the proposer (player 2) gets all T, player 3 gets 0. So in the 3-player equilibrium, the proposer will bribe player 3 (the one who gets 0 in continuation) with 1, keep T-1, and give 0 to player 2. So payoffs: (T-1, 0, 1) if T>=1. If T=0, proposer dies, all get 0.
Thus for the 3-player subgame (players B, C, D with B as proposer), the payoffs are:
If T>=1: (T-1 for B, 0 for C, 1 for D).
If T=0: (0,0,0).
Now back to the 4-player game: Proposer A needs M=ceil(4/2)=2 votes. So he needs at least 1 other Yes.
Continuation payoffs if A dies: for players B,C,D, those are the above: y_B = (if T>=1 then T-1 else 0), y_C = (if T>=1 then 0 else 0), y_D = (if T>=1 then 1 else 0). (T is the total brains, which is the same B of the overall game; I'll use B_total.)
Now A can propose a distribution (x_A, x_B, x_C, x_D) summing to B_total.
He needs to secure at least one other Yes. He will choose the cheapest bribe(s). He wants to survive, and also maximize his own share, but for determining minimal B_total for survival, we only need existence.
The cost to bribe player B: need x_B > y_B. y_B = (B_total - 1) if B_total >=1 else 0. So to bribe B, need x_B >= y_B+1. For B_total >=1, y_B = B_total-1, so x_B >= B_total. That would require giving all brains to B, leaving 0 for others, and then A gets 0, but total sum would be B_total, so it's possible: x_B = B_total, others 0. But that would satisfy x_B > y_B? Since y_B = B_total-1, x_B = B_total > B_total-1, yes. But then A gets 0, but he survives. So bribe B is possible but costly: requires giving all brains to B. However, maybe bribing C or D is cheaper.
For player C: y_C = 0 (if B_total>=1) or 0 (if 0). So need x_C >= 1 to bribe C (if B_total>=1). For B_total=0, no bribe possible anyway.
For player D: y_D = 1 (if B_total>=1) else 0. So need x_D >= 2 to bribe D (since >1). That's more expensive than C.
Thus the cheapest bribe is player C with cost 1 (provided B_total>=1). So if B_total >=1, A can give 1 to C, 0 to others, keep B_total-1 for himself. Then votes: A Yes, C Yes (1>0), B? x_B=0, y_B = B_total-1 if B_total>=1. For B_total>=2, y_B = B_total-1 >=1, so 0 < y_B, B votes No. D: x_D=0, y_D=1, so 0<1, D votes No. So total Yes = 2, which meets M=2. So proposal passes for any B_total >=1? Check B_total=1: then y_B = 0 (since B_total-1=0), B votes? x_B=0, y_B=0 => tie, but tie-breaking: prefers fewer survivors, so votes No. C: gets 1>0 => Yes. D: y_D=1, x_D=0 => 0<1 => No. So Yes votes: A and C =>2, passes. So indeed for n=4, proposer can survive for any B_total >=1. So the minimal B for survival is 1, which matches g(4)=1.
Now we can compute the equilibrium payoffs for n=4 when B>=1. The proposer A will maximize his own share; he will bribe the cheapest voter (C) with 1, keep B-1 for himself, give 0 to B and D. So payoffs: A gets B-1, B gets 0, C gets 1, D gets 0. But is that always optimal? Let's check if B_total=1, then A gets 0, C gets 1, others 0. That matches. For B_total=2, A gets 1, C gets 1, others 0. For B_total=3, A gets 2, C gets 1, others 0. So pattern: (B-1, 0, 1, 0). However, we need to confirm that bribing C is indeed the cheapest; it is, with cost 1. But what about B_total=0, no survival. So that's consistent.
Now back to n=5. For n=5, M=3, need 2 other Yes votes.
Continuation after player 1 dies: 4-player game with players 2,3,4,5, total B, proposer player 2. We have equilibrium payoffs for that 4-player game as function of B: as derived, if B>=1, payoffs: player 2 gets B-1, player 3 gets 0, player 4 gets 1, player 5 gets 0. If B=0, all get 0.
Now player 1 needs to secure 2 Yes votes from among 2,3,4,5. He can bribe multiple players. The cost to bribe each:
Player 2: need x_2 > y_2 = B-1 (if B>=1) => at least B.
Player 3: need >0 => at least 1.
Player 4: need >1 => at least 2.
Player 5: need >0 => at least 1.
So cheapest bribes: players 3 and 5 cost 1 each; player 4 costs 2; player 2 costs B.
To get 2 votes, Heidi can bribe players 3 and 5, each with 1 brain, total cost 2. She could also bribe player 3 and 5 (or 3 and 5). So she needs B >= 2 (since she must give away at least 2). Also, she must ensure that the bribed players indeed vote Yes; and the others may vote No, but that's fine as long as she gets at least 2 Yes besides herself.
Check: With B=2, she can give 1 to player 3, 1 to player 5, 0 to others, keep 0. Then votes: herself Yes; player 3 Yes (1>0); player 5 Yes (1>0); player 2: x_2=0, y_2 = B-1 = 1, so 0<1 => No; player 4: x_4=0, y_4=1 => 0<1 => No. Total Yes = 3 (herself, 3,5) which meets M=3. So she survives.
What about B=1? Then y_2=0, y_3=0, y_4=1, y_5=0 (since B>=1). Costs: bribe player2 needs >=1? Actually y_2=0, so bribe cost 1; player3 cost 1; player4 cost 2; player5 cost1. She needs 2 bribes. Minimum total cost = 1+1=2 (e.g., players 3 and 5). But total B=1, insufficient. Could she bribe player2 with 1? That would use all B, but then only one bribe (player2), giving 1 vote besides herself; total Yes = 2, but need 3 votes? Wait she needs 2 other Yes votes because M=3. So if she bribes only player2, she gets herself + player2 = 2 votes, which is less than 3. So fails. Could she bribe player2 and also get someone else without giving brains? No, must bribe. So B=1 insufficient. Could she bribe player3 and player5? That would cost 2 >1. So B=1 not enough.
What about B=0? All y_i=0; costs: each bribe requires at least 1; need 2 bribes => need at least 2, so impossible. So minimal B = 2. That matches floor((5-1)/2)=2.
Thus pattern holds for n=1..5.
Now n=6: Let's test predicted answer floor((6-1)/2)= floor(5/2)=2. So g(6) should be 2? Let's simulate.
n=6: M = ceil(6/2)=3. So player 1 needs 2 other Yes votes.
Continuation after player 1 dies: 5-player game (players 2..6) with proposer player 2, total B. We need equilibrium payoffs for n=5 as function of B. We have derived for n=5 (but from the perspective of player 2 as proposer). We have derived that for n=5, if B >= 2, the proposer can survive and the equilibrium payoffs are? Let's compute the 5-player game equilibrium payoffs similarly.
We already analyzed n=5 from the perspective of player 1 (Heidi). But now we need the outcome for a 5-player game where the proposer is the first among those 5 (player 2 in the overall ordering). We can compute recursively.
We'll compute for n=5, players P (proposer), Q,R,S,T (in order). The continuation after P dies is a 4-player game (Q,R,S,T) with proposer Q. We have equilibrium for n=4 as function of B: if B>=1, payoffs: (B-1, 0, 1, 0) for (Q,R,S,T). (Note: careful: In n=4, the proposer (Q) gets B-1, next (R) gets 0, next (S) gets 1, next (T) gets 0). That's what we derived: for n=4, proposer gets B-1, third gets 1, others 0.
Thus, for the 5-player game, continuation payoffs if P dies:
y_Q = B-1 (if B>=1 else 0)
y_R = 0
y_S = 1
y_T = 0
But wait, the 4-player game has 4 players: Q,R,S,T. Their order is Q (proposer), R, S, T. So after P dies, the game reduces to that. So indeed y_Q = (B-1) if B>=1, else 0; y_R=0; y_S=1; y_T=0.
Now, the proposer P needs M5 = ceil(5/2)=3 votes. So needs 2 other Yes votes. He can bribe players. Cost to bribe each:
Q: need > y_Q = B-1 => at least B (if B>=1)
R: need >0 => at least 1
S: need >1 => at least 2
T: need >0 => at least 1
Cheapest bribes: R and T each cost 1, total 2; or R and something else. So P can bribe R and T with 1 each, total cost 2. But also need to ensure that the bribed votes plus his own reach 3. He will have his own vote, plus R and T => 3 votes. Others may vote No. So for B >=2, he can survive by giving 1 to R, 1 to T, and keep B-2 for himself. Check for B=2: give 1 to R, 1 to T, keep 0. Votes: P Yes; R Yes (1>0); T Yes (1>0); Q: x_Q=0, y_Q = B-1=1 => 0<1 => No; S: x_S=0, y_S=1 => 0<1 => No. Total Yes =3, meets M=3. So for n=5, proposer can survive if B>=2. For B=1: then y_Q = 0 (since B-1=0), y_R=0, y_S=1, y_T=0. Costs: R cost1, T cost1, Q cost1? Actually Q: need >0 =>1. But total B=1, can bribe at most one voter. Need 2 votes, impossible. So B=1 insufficient. B=0 insufficient. So minimal B =2. That matches our earlier g(5)=2. And the equilibrium payoffs for n=5 when B>=2: P gets B-2, R gets 1, T gets 1, Q gets 0, S gets 0? Actually from the proposal: P gives 1 to R, 1 to T, 0 to others, keeps B-2. So payoffs: (B-2, 0, 1, 0, 1) for (P, Q, R, S, T)? Wait ordering: players: P (proposer), Q, R, S, T. The proposal: x_P = B-2, x_Q=0, x_R=1, x_S=0, x_T=1. So payoffs: P gets B-2, Q gets 0, R gets 1, S gets 0, T gets 1. But note that R is the second in order? Actually order: P (1), Q(2), R(3), S(4), T(5). So the second player (Q) gets 0, third (R) gets 1, fourth (S) gets 0, fifth (T) gets 1. So pattern: the proposer gets B-2, and players at positions that are "even"? Actually not exactly.
Now we need n=6. So for n=6, M=3, need 2 other Yes.
Continuation after player 1 dies: 5-player game with players 2..6, proposer player 2. Total B. We need the payoffs y_2..y_6 for the 5-player game equilibrium.
From above, for n=5 (players 2..6, with 2 as proposer), when B >= 2, the equilibrium payoffs (according to our derived pattern) are:
Player 2 (proposer) gets B-2.
Player 3 gets 0.
Player 4 gets 1? Wait careful: In our 5-player equilibrium we derived, the players were P (proposer), Q, R, S, T. The payoffs were: P gets B-2, Q gets 0, R gets 1, S gets 0, T gets 1. So mapping: player2 = P gets B-2; player3 = Q gets 0; player4 = R gets 1; player5 = S gets 0; player6 = T gets 1.
But we need to verify the ordering: In our 5-player derivation, we assumed the order of the continuation after P dies is Q,R,S,T (4 players). And we had that the cheapest bribes for P were R and T? Actually we bribed R and T. That corresponds to players 3 and 5 in the 5-player ordering? Let's label more clearly:
In the 5-player game, players are: 1 (proposer), 2, 3, 4, 5 (in order). The continuation after player1 dies is a 4-player game with players 2,3,4,5 (order 2 proposer, then 3,4,5). In that 4-player game, we had equilibrium payoffs: player2 gets B-1, player3 gets 0, player4 gets 1, player5 gets 0 (for B>=1). So that is the continuation payoffs for player1's decision.
Now, player1 (in 5-player) needed 2 other votes. He found cheapest bribes: player3 (cost 1, since y_3=0) and player5 (cost 1, since y_5=0). He did not bribe player4 because y_4=1, cost 2; player2 cost B. So his proposal gave 1 to player3 and 1 to player5, keep B-2.
Thus, the equilibrium payoffs for the 5-player game (when B>=2) are:
Player1 (proposer) gets B-2.
Player2 gets 0 (since x_2=0)
Player3 gets 1
Player4 gets 0
Player5 gets 1
Yes. So that matches the mapping: In our overall n=6 case, the 5-player subgame (players 2..6) has player2 as proposer, player3 as second, player4 as third, player5 as fourth, player6 as fifth. So according to this pattern, for B >= 2, the payoffs are:
Player2: B-2
Player3: 0
Player4: 1
Player5: 0
Player6: 1
But we need to verify for B=2: then player2 gets 0, player4 gets 1, player6 gets 1, others 0. That's consistent with earlier: for B=2, the proposal by player2 in the 5-player game would be: give 1 to player4, 1 to player6, keep 0. That matches.
Now for B=1: the 5-player subgame: Since B=1 < 2, the proposer (player2) cannot survive? Let's analyze n=5 with B=1: we earlier concluded that for n=5, proposer cannot survive if B=1. So the equilibrium outcome when B=1 would be that player2 dies, and then the game reduces to 4 players (3,4,5,6) with proposer player3, total B=1. For that 4-player subgame with B=1, we already have equilibrium: proposer (player3) can survive (since B>=1) and will get B-1=0, give 1 to player5 (since in 4-player, third player gets 1), others 0. So final payoffs: player2 dies (gets 0), player3 gets 0, player4 gets 0? Actually in 4-player (players 3,4,5,6) with B=1, equilibrium: player3 (proposer) gets 0, player4 gets 0, player5 gets 1, player6 gets 0. So overall: player2=0, player3=0, player4=0, player5=1, player6=0. But we need to also consider that after player2 dies, player3 proposes and passes; so final distribution is as above. So for B=1, the payoffs in the 5-player subgame are: player2=0, player3=0, player4=0, player5=1, player6=0.
For B=0, all get 0.
Now back to n=6: player1 (Heidi) needs 2 other Yes votes. The continuation payoffs y_i depend on B.
We need to find minimal B such that there exists a subset S of {2,3,4,5,6} with |S| >= 2 and sum_{i in S} (y_i+1) <= B. Actually need to give > y_i, so cost for each i is at least y_i+1. But we can give exactly y_i+1 to those in S, and 0 to others.
We'll compute for possible B.
First, try B=2. For B=2, we need to determine y_i for the 5-player subgame with total B=2. According to pattern, for B>=2, the 5-player subgame yields y_2 = B-2 = 0; y_3=0; y_4=1; y_5=0; y_6=1. So we have:
y2=0, cost to bribe = 1
y3=0, cost=1
y4=1, cost=2
y5=0, cost=1
y6=1, cost=2
The two cheapest bribes are 1 and 1 (e.g., players 2,3,5). Actually players 2,3,5 each cost 1. So we can pick any two of them, total cost 2. That equals B=2. So Heidi can give 1 to player2 and 1 to player3, keep 0. Then votes: Heidi Yes, player2 Yes (1>0), player3 Yes (1>0). Others: player4: x4=0, y4=1 => 0<1 => No; player5: x5=0, y5=0 => tie? Actually y5=0, x5=0, so tie, and tie-breaking prefers fewer survivors => vote No. Player6: x6=0, y6=1 => No. So total Yes = 3, meets M=3. So she survives with B=2. Good.
Now check B=1: For B=1, the 5-player subgame payoffs are as above for B=1: (y2,y3,y4,y5,y6) = (0,0,0,1,0) (since player2 dies and final gives player5=1). Let's compute precisely: For B=1, we said player2 dies. The eventual distribution is: player2=0, player3=0, player4=0, player5=1, player6=0. So y2=0, y3=0, y4=0, y5=1, y6=0. Costs: player2 cost1, player3 cost1, player4 cost1, player5 cost2, player6 cost1. Cheapest two bribes cost 1+1=2. But total B=1 <2, so impossible. Also could we bribe one player and rely on something else? Need two other Yes votes; bribing only one gives only one extra Yes; so fails. So B=1 insufficient.
Thus g(6)=2, matching floor((6-1)/2)=2. Good.
Now n=7: Predicted g(7)= floor((7-1)/2)=3. Let's test quickly to confirm.
We can attempt to prove by induction that g(n) = floor((n-1)/2). The recursion seems consistent.
Thus the answer for any N is floor((N-1)/2).
But wait, check N=2 gave 0, floor((2-1)/2)=0. Good.
Now what about N=0? Not allowed.
Thus the solution seems to be (N-1)//2 integer division.
But the examples: N=3 -> 1, N=99 -> 49. That's (N-1)//2 indeed.
Now the problem statement: "what is the smallest number of brains that must be in the chest for her to get out at all (possibly empty-handed, but alive)?" So we output that minimal number.
Thus answer is (N-1)//2.
But wait: We must double-check for even N values that are large, e.g., N=100, predicted answer = 99//2 = 49. So floor(99/2)=49. Let's simulate maybe N=100 to ensure pattern holds.
The recursion we did for even N (4,6) gave floor((N-1)/2). For N=4, (4-1)//2=1; N=6 gave 2. So seems consistent.
Thus the solution is simply (N-1)//2.
But we must ensure that the voting rule is "at least half" and that tie-breaking is "prefer fewer survivors" (i.e., vote No when indifferent). Our analysis used that.
Also, note that we assumed the ordering: Heidi is first, then zombies in some order. The pattern we derived didn't depend on the specific ordering of zombies beyond the natural ordering based on their indices; the pattern of who gets 0 and who gets 1 etc. emerged from the recursion and the fact that the cheapest bribes are always the ones who get 0 in the continuation, and their number is floor((n-1)/2). More formally, we can prove by induction that for any n, the minimal B for survival of the first proposer is floor((n-1)/2), and that the set of players who get 0 in the continuation is exactly the players with even indices? Actually the pattern from our computations: for n=3, zero-receivers: player2? Actually in 3-player continuation (n=2) we had player3 got 0, player2 got B. For n=4, zero-receivers in continuation (n=3) were players 2 and 4? Actually we had y_2 = B-1, y_3=0, y_4=1. Wait zero-receivers: y_3=0, y_? Actually zero: y_3=0, and maybe others? y_2 and y_4 non-zero. So number of zero-receivers is 1? For n=4, floor((4-1)/2)=1, and indeed there is exactly 1 zero-receiver (player3) who can be bribed with 1. For n=5, zero-receivers in continuation (n=4): we had y_3=0, y_5=0? Actually for n=4 continuation (players 2,3,4,5) we had y_2=B-1, y_3=0, y_4=1, y_5=0. So zero-receivers: players 3 and 5 (two). That's floor((5-1)/2)=2. For n=6, zero-receivers in continuation (n=5) we had y_2= B-2? Actually for n=5 continuation we had y_2= B-2, y_3=0, y_4=1, y_5=0, y_6=1. Zero-receivers: players 3 and 5? That's two? But floor((6-1)/2)=2, yes. Actually y_3=0, y_5=0, that's 2 zeros. Also maybe y_? y_2 and y_4 and y_6 are non-zero. So number of zero-receivers equals floor((n-1)/2) for the subgame of size n-1? In general, by induction, the number of players who receive 0 in the equilibrium of a game of size k (with first proposer) might be floor(k/2) or something. But we don't need to prove in detail.
Given the problem constraints up to 1e9, the answer is straightforward.
But before finalizing, we must consider edge cases: N=1 -> output 0, as given. So answer is (N-1)//2.
But wait: Example for N=3 output 1, which is (3-1)//2 =1. For N=99 output 49, (99-1)//2=49. So matches.
Thus, the solution: read N, output (N-1)//2.
But we should also consider if there is any nuance about "at least half" meaning strictly more than half? The phrase "at least half" is ambiguous, but based on examples, it aligns with our interpretation. If it required > N/2 (i.e., strict majority), then for even N, e.g., N=2, she would need 2 votes (since >1) and would need to bribe the zombie, requiring at least 1 brain, so answer would be floor(N/2) perhaps. But N=3 would need 2 votes, answer 1 still. N=4 would need 3 votes, so she'd need to bribe 2 zombies, and minimal brains might be 2? Let's test: If rule were strict majority (> N/2), then for N=4, needed Yes >2 => at least 3. She needs 2 other Yes. In our analysis with strict majority, the subgame analysis would change because the threshold changes. Let's check if that would yield different results. For N=4, M = floor(N/2)+1? Actually > N/2 means for N=4, >2 => 3. So she needs 2 other Yes votes. In our earlier analysis for N=4 with B=1, she could only bribe 1 voter (cost 1). So with B=1, she would have only 2 Yes votes (herself + one bribed) => 2 <3, so fails. So minimal B might be 2. Let's test N=4 with strict majority: would g(4) be 2? Then (N-1)//2=1, not matching. Since the example only gives odd N, we can't be sure. However, the problem statement says "at least half". So we stick with that.
Also, the previous subtask (which we don't have) might have defined "at least half" meaning ceil(N/2) votes. So we are consistent.
Thus final answer: (N-1)//2.
But wait: Could there be a scenario where with even N, the minimal B is actually (N/2) - 1? For N=4, (4/2)-1 =1, matches. For N=6, (6/2)-1=2, matches floor((N-1)/2). Actually floor((N-1)/2) = (N/2)-1 when N even, and (N-1)/2 when N odd. So it's the same expression.
Thus answer = (N-1)//2 in integer division.
Now confirm with N=1: (0)//2=0, OK.
Thus solution is trivial.
But we need to output an integer. So just compute that.
But we must be careful: The input N up to 1e9 fits in 32-bit int? 1e9 < 2^31, so fine.
Thus answer: print (N-1)//2.
Now let's ensure there is no off-by-one: For N=2, output 0, as reasoned. For N=3, 1. For N=4, 1. For N=5, 2. For N=6, 2. For N=7, 3. So pattern: it's essentially floor((N-1)/2). This matches examples.
Now we should also consider if the problem might have a twist: "Heidi is to make the first proposal, which must be accepted by at least half of the attendees for her to survive." Could "attendees" mean all N, but does Heidi count as an attendee? Yes, all N include her. So she is part of the voting. She wants to survive, meaning she wants the proposal to be accepted. She could also be killed if not enough votes.
Now the phrase "what is the smallest number of brains that must be in the chest for her to get out at all (possibly empty-handed, but alive)?" That means we want the minimal B such that there exists a proposal that leads to her survival. She may get 0 brains, but she lives.
Our reasoning indicates that with B = floor((N-1)/2), she can survive. Could there be a smaller B? For N=4, we saw B=0 fails, so 1 is minimal. For N=6, B=1 fails. So seems correct.
Thus answer: (N-1)//2.
Now, the problem might be from some contest where the solution is indeed (N-1)//2, known as "Brain Dinner". I recall a problem "Heidi and the brain dinner" where part A was something else, part B this. So it's plausible.
Thus final code: read integer N, compute (N-1)//2, output.
But we should also handle N=0? Not in range.
Thus final answer.
But let's double-check with N=1: (1-1)//2=0, matches.
So answer is correct.
Now I'll produce the final response. The minimal number of brains required for Heidi to survive is (N - 1) // 2.
This is derived from the game-theoretic analysis: Heidi needs the vote of at least half of the N attendees. Since she always votes for her own survival, she must secure ceil(N/2) - 1 additional votes. By backward induction, the cheapest way is to bribe exactly those zombies who would receive 0 brains if she were to die, each at a cost of 1 brain. The number of such zombies is ⌊(N-1)/2⌋, which gives the minimal total brains needed.
python
import sys
def main():
N = int(sys.stdin.readline().strip())
print((N - 1) // 2)
if __name__ == "__main__":
main()