We need to understand problem: We have daily login gives A coins each login. Additionally, if you log in for 7 consecutive days from Monday to Sunday (i.e., a full week consecutive login covering all days of the week), you get an extra B coins each time? Wait "if you log in for 7 consecutive days from Monday to Sunday, you will get an additional B coins each time." I think it means: For each set of 7 consecutive days (starting from Monday, i.e., each full week that you log in every day of that week), you get an additional B coins. The phrasing "each time" might refer to each time you complete a full week. Let's read examples.
Example 2: A=1, B=2, C=10. They say: "If you log in consecutively from Monday to Sunday, you will get 2 coins in addition to 7 daily coins, so you will get a total of 9 coins. Therefore, if you log in one more time, you will get 10 coins." So if you log in for 7 days (Monday to Sunday), you get A*7 = 7, plus an extra B=2, total 9. Then logging in an 8th day gives an additional A=1, making 10. That matches: 7 days consecutive yields a bonus of B only once? Actually they said "you will get 2 coins in addition to 7 daily coins, so you will get a total of 9 coins." So the bonus B is given for that week of consecutive logins. But if you log in for longer than 7 days, do you get bonus for each full week? The description: "if you log in for 7 consecutive days from Monday to Sunday, you will get an additional B coins each time." It might be that each time you achieve a full week of consecutive logins (i.e., every 7 days of consecutive logins that start on a Monday and end on a Sunday) you get a bonus B. But careful: It says "from Monday to Sunday" meaning that the 7-day period must exactly cover Monday to Sunday. So likely, the bonus is awarded per calendar week (Monday-Sunday) where you log in every day of that week. So if you log in for 8 days, starting Monday, you have Monday to Monday? But the second week would be Monday to Sunday? Actually consecutive days: If you log in Monday through Monday (8 days), you have covered two weeks partially. The first week (Monday to Sunday) you logged in all days, so you get B. The second week, you logged in Monday only, not full week, so no bonus. If you log in for 14 consecutive days starting Monday, you'd have two full weeks (Monday-Sunday of week1, and Monday-Sunday of week2), so you'd get B for each week. So that seems plausible.
But we need to verify: Example 1: A=3, B=0, C=10. They say: "JOI can get 12 coins by logging in for 4 consecutive days from Monday." That yields 4*3=12, which meets 10. Minimum number is 4. No bonus. So trivial.
Given constraints A up to 1000, B up to 1000, C up to 1e6. We need minimal number of logins (i.e., days you log in, each day at most once) to accumulate at least C coins. Since you can only log in up to once per day, and days are sequential starting from Monday. But the decision is when to log in? The problem likely expects we can choose any pattern of logins (i.e., which days to log in) as long as we can achieve at least C coins, and we want minimum number of logins (i.e., count of days where we log in). Since we can only log in once per day and days are infinite, we can decide to log in on specific days. The extra bonus B is earned for each full week (Monday to Sunday) in which you log in all 7 days. So if we skip a day in a week, that week will not give bonus. So to maximize coins for a given number of logins, we should aim to concentrate logins to achieve full weeks because the bonus yields extra coins per 7 logins if they are arranged consecutively covering a full week. However, we also might consider overlapping weeks? Since the bonus is per week that you log in every day, you could get multiple bonuses if you have multiple full weeks consecutively. For instance, if you log in for 14 consecutive days starting Monday, you get two bonuses, because the first 7 days (Mon-Sun) are a full week, and the next 7 days (Mon-Sun) are another full week. So essentially, if you log in consecutively for N days, the number of full weeks completed (i.e., number of sets of 7 consecutive days that are entirely within your login streak and align with Monday-Sunday boundaries?) Actually careful: The bonus is given "if you log in for 7 consecutive days from Monday to Sunday". That suggests the set of days must be exactly a Monday through Sunday period. So if you start on a Monday and log in each day for 7 days, you get one B. If you continue for 8 days, you still only have the first full week; the second week you only have Monday, so no bonus. If you continue to 14 days, you have two full weeks: days 1-7 (Mon-Sun) and days 8-14 (Mon-Sun). Indeed the days 8-14 are also a Monday to Sunday period (since day 1 is Monday, day 8 is next Monday, day 14 next Sunday). So that matches: For a login streak that starts on Monday and continues, each full 7-day block that starts on Monday yields a bonus. But what if you start on a Tuesday? Then you could log in for 7 consecutive days from Tuesday to Monday? But that would not be from Monday to Sunday. So you would not get the bonus unless your 7-day period exactly aligns with Monday to Sunday. So to get a bonus, you must have a week where you log in every day of that calendar week (Monday to Sunday). This implies that to earn multiple bonuses, you need to log in every day of multiple consecutive weeks. That is, you need to have a streak that covers full weeks. But note: you could have non-consecutive logins across weeks, but still if in a given week you log in every day, you get the bonus for that week even if there are gaps before or after? The statement: "if you log in for 7 consecutive days from Monday to Sunday, you will get an additional B coins each time." The phrase "consecutive days" might imply the logins must be on consecutive days covering those days. But if you skip a day, it's not consecutive. So to get the bonus for a particular week, you need to log in every day from Monday to Sunday consecutively (i.e., no gaps in that week). However, if there's a gap before the Monday, it's fine as long as you log in Monday through Sunday without missing a day. But if you skip Wednesday, then it's not consecutive. So essentially, the bonus is awarded for any run of consecutive logins that includes an entire Monday-to-Sunday period. But to maximize bonuses for a given number of logins, it is best to have a single long consecutive login streak that covers as many full weeks as possible, because that yields multiple bonuses with minimal extra logins (since each bonus requires 7 logins anyway). Could there be a more efficient pattern like having two separate full weeks separated by gaps? That would require 7+7=14 logins and yield 2 bonuses. But if you do a consecutive streak of 14 days, you also get 2 bonuses (and same number of logins). So it's the same. So essentially, to maximize coins for a given number of logins N, the optimal strategy is to log in on a set of days that consists of a consecutive block of N days, ideally starting on Monday, to maximize the number of full Monday-Sunday weeks fully contained in that block. Because any other distribution of logins that yields a full week would also require at least 7 logins in that week, but possibly some weeks partially done might waste logins that don't contribute to a bonus. Since bonus per week is B, which is at most 1000, and A is also up to 1000, we want to maximize total coins. The total coins for N logins arranged as a consecutive block starting on Monday is: Coins = NA + floor(N/7)B (if N mod 7 = 0? Actually careful: If N is not a multiple of 7, we need to count how many full Monday-Sunday weeks are completely covered. If we start on Monday, then the block covers days 1..N. The full weeks are: days 1-7, 8-14, 15-21, ... up to 7k where 7k ≤ N. So number of full weeks = floor(N/7). That yields B per full week. If we start on a different day, the number of full weeks might be less. So the optimal starting day is Monday (or any day that ensures alignment? Actually if you start on Tuesday, the first week you would have Tuesday through Monday? That's not a Monday-Sunday period. So you might only get full weeks after you cover a Monday through Sunday. For a block of N consecutive days starting on day d (where d=1 is Monday), the block includes some full weeks only if it contains a set of days that includes a Monday through Sunday. The maximum number of full weeks you can get from any block of N consecutive days is floor((N + offset)/7) maybe? But if you can choose the start day, you can maximize full weeks. Since we can choose any pattern of logins, we could pick the optimal start day. So the optimal strategy is to choose a block of N consecutive days that is aligned to maximize full weeks. In fact, the maximum possible number of full weeks from N consecutive days is floor((N)/7) if we start on Monday; if we start on other days, we might get one fewer full week if N mod 7 is not enough to cover the missing days. So indeed starting on Monday yields floor(N/7) full weeks. Starting on other days yields at most floor((N - something)/7). Let's test: Suppose N=7. Starting on Monday: covers Monday-Sunday, 1 full week => 1*B. Starting on Tuesday: covers Tuesday-Monday (next week Monday). This includes Monday? Actually days: Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday, Monday. That includes a full Monday-Sunday? It includes Tuesday to Monday, missing Tuesday? Wait a Monday-Sunday week is a specific set of 7 days: the days of that calendar week. Starting on Tuesday, the block includes days: Tuesday (week1), Wednesday, Thursday, Friday, Saturday, Sunday (week1), Monday (week2). The days of week1 from Monday to Sunday: we have Tuesday through Sunday, but not Monday of week1. So we do not have all 7 days of week1. For week2, we have Monday but not Tuesday-Sunday. So we have no full week. So 0 bonus. So starting on Monday is best. So the optimal way to maximize coins per login is to have a consecutive streak starting on Monday.
But is there any scenario where non-consecutive logins could give more coins than a consecutive block for the same number of logins? Suppose you log in on 7 days that are not consecutive but still cover all days of a particular week? To cover all days of a week, they must be exactly Monday, Tuesday, ..., Sunday, which are consecutive. So they must be consecutive. So to get the bonus for a week, you need to log in on those 7 consecutive days. So if you want multiple bonuses, you need multiple weeks, and the weeks must be consecutive (or at least, if you skip a day between weeks, then the second week's Monday through Sunday might still be consecutive within that week, but there is a gap before Monday. That's fine: you could have two separate full weeks: one week you log in all days, then you skip some days, then another week you log in all days. That would give two bonuses, using 14 logins. But if you do a consecutive block of 14 days, you also get two bonuses, but also you have logins on the days between weeks (which are the same as the second week's days anyway). Actually if you have two separate full weeks separated by a gap, you would have the same number of logins (14) but with extra days skipped, so the total days elapsed is larger, but that's irrelevant. However, could you get a bonus with fewer than 7 logins? No. So the maximum coins for N logins is achieved by making as many full weeks as possible, which requires grouping logins into groups of 7 consecutive days aligned to Monday-Sunday. If N is not a multiple of 7, the extra logins beyond the full weeks may be placed in a partial week. Where should we place the partial week? They can be placed at the beginning or end of the streak. Starting on Monday gives the maximum full weeks = floor(N/7). So total coins for N logins (optimal) = N*A + floor(N/7)*B. But is there any possibility to get more than floor(N/7) bonuses with N logins? Possibly if the partial week overlaps with another full week? For instance, N=8, floor(8/7)=1. Could we get 2 bonuses? That would require two full weeks, needing at least 14 logins. So no. So floor(N/7) is maximum.
But what about if B is large, maybe it's beneficial to have more than floor(N/7) bonuses by aligning the partial week to be part of two different weeks? That doesn't make sense because each bonus requires 7 specific days; a single login cannot contribute to two full weeks simultaneously (except overlapping weeks? But weeks are discrete Monday-Sunday blocks; they don't overlap. So each day belongs to exactly one week. So to get a bonus for a week, you need all 7 days of that week. So each bonus uses exactly 7 logins, each belonging to that week. So the maximum number of bonuses from N logins is at most floor(N/7), as each bonus uses 7 distinct logins. So yes.
Thus, the maximum total coins for N logins (under optimal login schedule) is: f(N) = AN + B * floor(N/7). And this is achievable by logging in on the first N days starting from Monday (or any consecutive block starting Monday). So the problem reduces to: Find the minimum N such that AN + B * floor(N/7) >= C.
But is there any scenario where we could achieve more coins with the same N by not logging in consecutively? For example, suppose we have N=8. With consecutive from Monday: coins = 8A + B (since floor(8/7)=1). Could we get 8A + 2B? Only if we had two full weeks, but that would require 14 logins. So not possible. Could we get 8A + B but also maybe extra from overlapping? No. So f(N) as above is maximum.
Thus, we need to find minimal N satisfying A*N + B * floor(N/7) >= C. With A,B,C up to 1e6 (C up to 1e6). N could be up to? Since each login gives at least A coins, N can be as large as ceil(C/A) which could be up to 1e6 when A=1. So N up to about 1e6. B up to 1000, but C up to 1e6, so N could be around 1e6. That's fine for a simple loop. But we can compute directly.
But we need to consider the possibility of B being 0, then it's trivial: N = ceil(C/A). For general, we need to account for floor(N/7) term.
Since constraints are small, we could simply iterate N from 0 upwards until condition holds. But maximum N could be up to 1e6, which is fine. But we must be careful: if A is very small (1) and B is also small, then N could be ~1e6. That's okay for loop in Python (1 million iterations) within time limit. But there might be more efficient method using division.
Alternatively, we can solve: For a given number of full weeks k = floor(N/7), then N = 7k + r, with 0 <= r <= 6. Then total coins = A*(7k+r) + Bk = (7A + B)k + Ar. We need >= C. So we can iterate over r from 0 to 6, solve for minimal k such that (7A+B)k + Ar >= C, then N = 7k + r. Then choose minimal N across r. Since k can be up to ceil(C/(7A+B)) which is at most ~1e6/8? Actually if A=1, B=0, then 7A+B=7, k up to ceil(C/7) ~ 143k. So that's fine. But we can solve directly: For each r, k_min = max(0, ceil((C - Ar) / (7A+B))) if C > A*r, else k=0. Then N = 7k + r. But careful: if k is negative? So we compute integer ceil. Then take min over r where k >= 0. But also note that N must be at least 0. We also need to ensure that for given r, the representation N = 7k + r with r in 0..6 is valid; but any integer N can be expressed uniquely as 7k + r with 0 <= r <=6, so this covers all N. So we can compute the minimal N directly by solving:
Let k = floor(N/7), r = N mod 7. Condition: (7A+B)k + Ar >= C. For each r, compute required k. Then N = 7k + r. Then minimal N among valid (k,r) pairs. However, we must also consider that for a given r, the k we compute may not correspond to exactly that r because if we set k, N = 7k + r, then floor(N/7) = k, r = N mod 7. So it's consistent. So the approach yields the exact minimal N.
We have to be careful about integer division ceiling. Compute needed = C - Ar. If needed <= 0, then k = 0 works (since r itself yields enough). Then N = r. But need to ensure r >= something: Actually if needed <= 0, then we can achieve with N = r logins, provided we can achieve that schedule? For r in 0..6, does there exist a schedule of r logins giving at least C? But if C is positive and A >0, r must be at least ceil(C/A) if B=0, but with bonus maybe we could achieve with fewer than ceil(C/A)? Actually if B>0, maybe r=6 could give enough if B is large? But B bonus only applies for full weeks, so if r <7, floor(N/7)=0, so no bonus. So for r<7, total coins = Ar. So condition Ar >= C. So if C <= Ar, then N = r works. But is r=0 allowed? N must be at least 1? Actually "minimum number of times JOI must log in", and C>=1, so N>=1. So we can ignore r=0 if needed.
Thus for each r from 0 to 6, we compute:
if Ar >= C: candidate = r (since k=0 works)
else: need = C - Ar; k = ceil(need / (7A+B)); candidate = 7*k + r.
Then answer = min(candidate) over r=0..6.
But we must be careful: For r values where A*r < C, we compute k = ceil(need / (7A+B)). However, k may be zero if need <=0? Already handled. So okay.
Now, is it always optimal to consider all r? Since N = 7k + r, with r in 0..6, any integer N is covered. So this method yields the minimal N.
But we need to confirm that for given r and k, we can actually achieve that many logins with the schedule that yields exactly floor(N/7) = k full weeks? Yes, by logging in for N consecutive days starting Monday, we get exactly k = floor(N/7) full weeks, because N = 7k + r. So that schedule yields coins = AN + Bk. So the condition is exactly that.
Thus answer is min over r.
But careful: If r = 0, then N = 7k. That's fine. But if r > 0, floor(N/7)=k. So yes.
Now compute minimal candidate.
We must also check if there is any alternative better schedule that yields more than floor(N/7) bonuses with the same N? We argued no. So the formula f(N) is the maximum achievable for given N. So the condition we solve is necessary and sufficient: There exists a schedule achieving at least C if and only if there exists N with f(N) >= C. And f(N) is as defined. So the minimal N is the smallest integer such that f(N) >= C.
But wait: Could there be a schedule where the bonus is obtained for a week that is not fully consecutive with the rest? For example, suppose we log in on Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday (full week), then skip a day, then log in on Monday of next week. That gives total N=8, with full week 1, plus an extra Monday. But floor(8/7)=1, so f(8)=8A+B. The actual total coins would be 8A+B (since you only get one bonus). So matches f(8). So it's consistent.
What about logging in on days that are not a contiguous block but still have two full weeks with gaps in between: For example, first week full, skip whole next week, then second week full. That's N=14, f(14)=14A+2B, which matches. So yes.
Thus f(N) is achievable and optimal.
Hence we can compute answer.
Let's test with examples:
Example1: A=3, B=0, C=10. Compute.
r=0: A0=0 <10, need=10, k=ceil(10/(21+0? Actually 7A+B = 21) => ceil(10/21)=1? 10/21 <1, ceil=1? Actually 10/21 =0.476..., ceil=1, candidate=71+0=7.
r=1: 3<10, need=7, k=ceil(7/21)=1? 7/21=0.333, ceil=1, candidate=7+1=8? Wait 7*1+1=8.
r=2: 6<10, need=4, ceil(4/21)=1, candidate=7+2=9.
r=3: 9<10, need=1, ceil(1/21)=1, candidate=7+3=10.
r=4: 12>=10, candidate=4.
r=5: 15>=10, candidate=5 (but 4 already smaller).
r=6: 18>=10, candidate=6.
Min is 4. Correct.
Example2: A=1, B=2, C=10.
7A+B=7+2=9.
r=0: 0<10, need=10, k=ceil(10/9)=2? Actually 10/9=1.111, ceil=2? Wait ceil(10/9) = 2? Because 1*9=9 <10, need 2. So k=2, candidate=14.
r=1: 1<10, need=9, ceil(9/9)=1, candidate=7+1=8.
r=2: 2<10, need=8, ceil(8/9)=1, candidate=7+2=9.
r=3: 3<10, need=7, ceil(7/9)=1, candidate=7+3=10.
r=4: 4<10, need=6, ceil(6/9)=1, candidate=7+4=11.
r=5: 5<10, need=5, ceil(5/9)=1, candidate=7+5=12.
r=6: 6<10, need=4, ceil(4/9)=1, candidate=7+6=13.
But also r=1 gave candidate=8, which is minimal? But example output is 8. So answer 8. Good.
Now check r=1 candidate: k= ceil((10-1)/9) = ceil(9/9)=1, N=7+1=8. Yes.
Now check if r=7? Not needed as r in 0..6 covers all N mod 7. So correct.
Thus algorithm: Read A, B, C. Compute ans = large number. For r in range(0,7): if A * r >= C: ans = min(ans, r). else: need = C - A * r; k = (need + (7A+B) - 1) // (7A+B); candidate = 7*k + r; ans = min(ans, candidate). Output ans.
But be careful: When r=0, candidate = 7*k. That's fine. But also note: If r=0 and C=0? But C>=1, so fine.
Edge cases: B=0, then 7A+B=7A. Then we might get candidate = 7ceil((C - Ar)/(7A)) + r. This could be larger than direct ceil(C/A). But we take min. This method should still yield optimal.
But wait: In the case B=0, is it always optimal to have r = C mod A? Actually we can simply compute ceil(C/A). But our method yields that as well. For B=0, r= C mod A? Let's test: A=3, C=10: ceil(10/3)=4. Our method gave r=4 candidate=4. For r=1: candidate = 7ceil((10-3)/21) + 1 = 7ceil(7/21) +1 = 7*1+1=8, etc. So min is 4. So fine.
Now consider large C=1e6, A=1, B=1000. Then 7A+B=1007. r values 0..6. For each, compute k and candidate. The minimal N would likely be something like: To maximize bonus per login, maybe it's beneficial to have many full weeks because each full week gives extra 1000 coins for 7 logins (so average per login = A + B/7 ≈ 1 + 142.86 ≈ 143.86). Actually A=1, B=1000 gives 1001 coins per 7 logins? Wait 7*A + B = 7+1000 = 1007 coins per full week (plus if we have extra logins they give only A). So it's very efficient. So the minimal N will be around C / (average) maybe. Our method works.
Now ensure that integer overflow not an issue. Python handles big ints. But C max 1e6, A,B up to 1000, so computations within ~1e9 safe.
Now the problem statement mentions "minimum number of times JOI must log in" and examples output numbers. So we output integer.
Potential pitfalls: When computing need = C - Ar, if r is such that Ar > C? Already handled as direct candidate. So else.
Now confirm with some more tests:
Test B=0, A=1, C=1e6 => ans = 1e6. Our method: r in 0..6. For r=0: need=1e6, k=ceil(1e6/7)=142858? Actually 1e6/7 ≈142857.14, ceil=142858? Let's compute: 1428577=999999, so need 1e6, so ceil(1e6/7)=142858? Actually (1e6)/7 = 142857.142857..., ceil = 142858 because 1428577=999,999 <1,000,000, so need one more. So candidate=7142858=1,000,006? Wait 7142858 = 1,000,006. That's larger than 1e6. For r=1: need=1e6-1=999,999, k=ceil(999,999/7)=142857? Since 1428577=999,999 exactly, so k=142857, candidate=7142857+1=999,999+1=1,000,000. That's exactly 1e6. For r=2: need=999,998, k=ceil(999,998/7)=142857? 1428577=999,999 >999,998? Actually 1428577=999,999 > 999,998, so we need 142857? But 1428577=999,999, which is > need, so ceil(999,998/7)=142857? Let's compute: 999,998/7 ≈ 142856.857..., ceil = 142857. So candidate = 7142857+2 = 999,999+2=1,000,001. So min is 1,000,000 from r=1. So answer is 1e6. Good.
Test: A=1000, B=1000, C=1000000. 7A+B=7000+1000=8000? Actually 71000=7000, +1000=8000. r=0: need=1e6, k=ceil(1e6/8000)=125? 1258000=1,000,000 exactly, so k=125, candidate=7125=875? Wait 7k = 875? Actually N = 7k + r = 7125 +0 = 875. That gives coins = AN + Bk = 1000875 + 1000125 = 875,000 + 125,000 = 1,000,000. So candidate=875. But we need to check if that is feasible: N=875, floor(875/7)=125, so yes. So answer might be 875. Check r=1: Ar=1000<1e6, need=999000, k=ceil(999000/8000)= ceil(124.875)=125? 1248000=992,000 <999,000, 1258000=1,000,000>=999,000, so k=125, candidate=7125+1=875+1=876. So min=875. Good.
Now test: A=1, B=0, C=10 => ans=10? Actually ceil(10/1)=10. Our method gave r=10? r only up to 6. For r=3 candidate=7+3=10; r=4 candidate=4? Wait A=1, B=0, C=10. r=4: A4=4 <10 so not direct. Actually we need to check: For r=4: A4=4 <10, need=6, k=ceil(6/7)=1, candidate=7+4=11. r=5: 5<10 need=5, k=ceil(5/7)=1, candidate=7+5=12. r=6: 6<10 need=4, k=ceil(4/7)=1, candidate=7+6=13. r=0: need=10, k=ceil(10/7)=2? Actually 71=7<10, so k=2, candidate=14. r=1: need=9, k=ceil(9/7)=2, candidate=14+1=15? Wait 72+1=15. r=2: need=8, k=ceil(8/7)=2, candidate=14+2=16. r=3: need=7, k=ceil(7/7)=1, candidate=7+3=10. So min=10. So matches ceil(10/1)=10. Actually direct ceil would be 10. Good.
Now ensure that candidate from r=3 gave 10, which is minimal.
Now check scenario where it's better to have extra full week even though you exceed C? That's what min finds.
Thus solution is correct.
But is there any scenario where the optimal schedule might involve not starting on Monday? That would reduce the number of full weeks for given N, thus decreasing coins, so you would need larger N to achieve same C. So the minimal N must use Monday start. So our f(N) is maximum possible for given N, so it's the best.
Thus answer is as above.
Now let's consider if there is any nuance: The problem says "you can log in up to once a day". So each day you can log in at most once. Also, "if you log in for 7 consecutive days from Monday to Sunday, you will get an additional B coins each time." It might be interpreted as: Each time you log in for a full week (i.e., each time you complete a streak of 7 consecutive days), you get B coins. And the streak could start any day, not necessarily Monday? But phrase "from Monday to Sunday" suggests it has to be exactly those days. So it's as we used.
But check the original JOI problem (maybe 2018/2019 qualifying?). Actually this is from JOI 2018/2019 Qual? I think it's problem "Coin" or something? Possibly it's JOI 2019? Let me recall: The problem about login and bonuses is typical. I think I've seen a problem "Game" from JOI 2019? Or maybe it's from AtCoder? Anyway, the typical solution is as we described.
But also consider: Could there be multiple bonuses overlapping? For example, if you log in for 8 consecutive days starting Monday, you have Monday to Monday. The first Monday to Sunday gives a bonus. But also is there a bonus for Tuesday to Monday? That would not be Monday to Sunday, so no. So it's fine.
Thus solution stands.
Now about implementation: simple.
But careful: The input example includes words "Four" but that's likely just explanation; actual output is number. So we output integer.
Now about constraints: A, B, C are integers. Output integer.
Edge: B=0, but our formula works.
Edge: B > 0, and maybe C is small enough that N < 7 can achieve with just A*N. So our r loop catches that.
Now complexity O(1).
Now double-check the formula: Need to ensure that when we compute k = ceil(need / denom), denom = 7A + B. But is it correct? Because for a given N = 7k + r, total coins = A(7k+r) + Bk = (7A+B)k + Ar. So if we set k and r, coins = denomk + Ar. So to achieve at least C, we need denomk + Ar >= C. Given r, we need minimal k such that denomk >= C - Ar. So k = max(0, ceil((C - Ar) / denom)). But note that if C - A*r <= 0, then k=0 works.
But careful: For a given r, if we choose k = ceil((C - Ar)/denom), then coins = denomk + A*r >= C. However, is it always possible to achieve exactly that k and r? Since N = 7k + r. That yields floor(N/7) = k indeed because r < 7. So yes.
Thus ans = min_{r=0..6} { 7k_r + r } where k_r = max(0, ceil((C - Ar)/denom) if A*r < C else 0).
Now ensure we treat negative need: If Ar > C, then we can set k=0, and candidate = r. So we can unify: candidate = r if Ar >= C else 7ceil((C - Ar)/denom) + r.
But careful: If A*r > C, it's obviously better to take k=0 because adding weeks would increase N, so candidate = r. So yes.
Now one more nuance: The minimal N might be 0? But C >= 1, so N>=1. So fine.
Now test with some random values to verify consistency with brute-force.
Let's brute for some small numbers to be safe.
We'll write a brute function: For each N from 1 to, say, 100, compute f(N) = N*A + floor(N/7)*B. Then find minimal N with f(N)>=C. Compare to formula.
We'll test several A,B,C.
We'll do manually: A=2, B=3, C=20.
Compute brute: N=1:2; 2:4;3:6;4:8;5:10;6:12;7:27+3=14+3=17;8:16+3=19;9:18+3=21. So minimal N=9. Our formula: denom=72+3=14+3=17? Actually 7A+B = 14+3=17. r from 0 to 6. r=0: A0=0<20, need=20, k=ceil(20/17)=2? 217=34>=20, candidate=14? Actually 72+0=14. That gives coins = 214 + 32 = 28+6=34 >=20. N=14. But we found minimal 9, so this candidate not minimal. r=1: A1=2<20, need=18, k=ceil(18/17)=2? 217=34>=18, candidate=72+1=15, coins=215+32=30+6=36>=20. r=2: 4<20 need=16, k=ceil(16/17)=1? Actually 16/17<1, ceil=1, candidate=7+2=9, coins=29+31=18+3=21>=20. r=3: 6<20 need=14, ceil(14/17)=1, candidate=7+3=10, coins=20+3=23? Actually 2*10=20 +3=23. r=4: 8<20 need=12, ceil(12/17)=1, candidate=11, coins=22+3=25. r=5: 10<20 need=10, ceil(10/17)=1, candidate=12, coins=24+3=27. r=6: 12<20 need=8, ceil(8/17)=1, candidate=13, coins=26+3=29. So min candidate is 9 (r=2). That matches brute. Good.
Now test edge: A=10, B=10, C=1. Obviously N=1 works because A=10 >=1. Our formula: For r=1: A*1=10>=1, candidate=1. Good.
Now test: A=1, B=10, C=15. Brute: N=1:1;2:2;3:3;4:4;5:5;6:6;7:7+10=17 (>=15) -> N=7. Our formula: denom=7+10=17. r=0: need=15, k=ceil(15/17)=1, candidate=7; r=1: need=14, ceil(14/17)=1, candidate=8; r=2: need=13, ceil(13/17)=1, candidate=9; ... r=6: need=9, ceil(9/17)=1, candidate=13. So min is 7. Good.
Now test: A=1, B=10, C=17. N=7 gives 17 exactly. So N=7. Our formula: r=0: need=17, k=ceil(17/17)=1 -> 7. So good.
Now test: A=1, B=10, C=16. N=7 gives 17 >=16, so N=7. Our formula: r=0: need=16, ceil(16/17)=1 ->7. So fine.
Now test: A=1, B=10, C=10. Brute: N=6 gives 6, N=7 gives 17, so N=7. But maybe we could do N=5? 5. So minimal N=7. Our formula: r=5: A*5=5<10, need=5, ceil(5/17)=1, candidate=12; r=6: 6<10 need=4, ceil=1, candidate=13; r=0: need=10, ceil(10/17)=1, candidate=7; r=1: need=9, ceil=1, candidate=8; ... So min is 7. That seems right. But wait, is there any schedule with N=6 that gives bonus? No, because need 7 days for bonus. So correct.
Now test: A=1000, B=0, C=5000 -> N=5 because 10005=5000. Our formula: denom=7000. r=0: need=5000, ceil(5000/7000)=1? Actually 5000/7000 <1, ceil=1, candidate=7, but r=5 gives candidate=5 because A5=5000>=C, candidate=5. So min=5. Good.
Now all good.
Thus we can implement.
But before finalizing, we need to consider the case where B is large relative to A, could the optimal N be something like you don't need to take the full weeks exactly as we think because you could get more than floor(N/7) bonuses if you arrange logins in separate weeks? But that would still be floor(N/7) because each full week uses 7 logins. Could there be a situation where you can get a bonus with fewer than 7 logins? The statement says "if you log in for 7 consecutive days from Monday to Sunday, you will get an additional B coins". So it's exactly 7. So no.
Thus solution stands.
Now we must produce answer as integer.
Implementation details:
- Read line: A, B, C = map(int, input().split())
- denom = 7*A + B
- ans = large (like 10**9)
- for r in range(0, 7):
if A * r >= C:
ans = min(ans, r)
else:
need = C - A * r
k = (need + denom - 1) // denom # integer ceil
candidate = 7 * k + r
ans = min(ans, candidate)
- print(ans)
But we must ensure that r can be 0; candidate = 7*k. But if C is 0? Not possible. So fine.
Now check boundary: If denom is 0? Since A>=1, denom >=7, so fine.
Now also consider that candidate may be 0? r=0 and k=0 would be candidate=0, but that only if need <=0. Since C>0, need = C >0, so k at least 1 if r=0? Actually if r=0 and C>0, need=C>0, so k>=1. So candidate >=7. So ans won't be 0.
Now confirm with some random test using code mentally: A=1000, B=1000, C=1 -> r=1 gives candidate=1. So ans=1.
Now it seems solved.
But wait: The problem statement might be ambiguous: "if you log in for 7 consecutive days from Monday to Sunday, you will get an additional B coins each time." Could "each time" mean each day you log in during that streak? That would be different: maybe you get B coins for each login within the 7-day streak? But the example clarifies: Example 2: A=1, B=2, C=10. They said: "If you log in consecutively from Monday to Sunday, you will get 2 coins in addition to 7 daily coins, so you will get a total of 9 coins." So it's a one-time bonus of 2 coins for the week, not per day. So our interpretation is correct.
Thus answer is correct.
Now there might be a nuance: The "each time" could refer to each time you achieve such a streak. But that's what we used.
Now I'll produce final answer.
But the solution can also be simplified by binary search on N from 0 to something, but the direct formula is O(1).
I'll write code accordingly.
Now I'm ChatGPT, I need to output a Python solution.
But I'll also consider any potential off-by-one: For r values, we are using k = ceil((C - Ar)/(7A+B)). However, careful: When we compute candidate = 7k + r, that gives N. But is it always true that for that N, floor(N/7) = k? Since r < 7, yes. But we must also ensure that this N indeed yields coins >= C. Let's confirm: coins = AN + Bfloor(N/7) = A*(7k+r) + Bk = (7A+B)k + Ar. Since we chose k such that (7A+B)k >= C - A*r, coins >= C. Good.
But we also need to consider if there exists a smaller N with same r? For each r, we found minimal k that satisfies. Since increasing k increases N, the minimal N for that residue class is this. So min across residues yields global min.
Thus final answer.
I'll produce code.
Now about the input format: The examples show "3 0 10" and output "4". So we output integer.
Now additional tests: Let's test with A=1, B=1, C=1000000. denom=8. Then we can compute: For each r, candidate = 7ceil((C - r)/8) + r. Let's compute for r=0: need=1e6, k=ceil(1e6/8)=125000 (since 1250008=1,000,000 exactly? 1250008 = 1,000,000, yes), candidate=7125000=875,000. r=1: need=999,999, k=ceil(999,999/8)=125000 (since 1249998=999,992 < 999,999, so 1250008=1,000,000>=999,999) candidate=875,000+1=875,001. So minimal N likely 875,000. That seems plausible.
But check if maybe a smaller N could be achieved with a different residue? r=7 is not considered, but r=0 gave 875,000. Is it possible to get N less than 875,000? Let's approximate: Each full week gives 8 coins per 7 days (since 7 A + B = 8). So average per login = 8/7 ≈ 1.142857. To get 1e6 coins, need about 1e6 / (8/7) = 1e6 * 7/8 = 875,000. That's exactly 875,000. So that seems optimal. So our answer matches.
Now check if maybe using a combination where we have some extra days beyond full weeks could reduce N? Actually full weeks are most efficient because they give extra B. So the minimal N is achieved by having as many full weeks as possible. So N=875,000 is the theoretical lower bound? Let's see if we can achieve with N=874,999? That would have floor(N/7) = floor(874,999/7). 7124,999 = 874,993? Actually 124,9997 = 874,993. Then remainder 6. So full weeks = 124,999. Coins = 874,9991 + 124,9991 = 874,999+124,999=999,998 < 1e6. So not enough. So indeed 875,000 is minimal.
So formula works.
Now we need to output integer.
Now implementation in Python:
def solve():
import sys
A, B, C = map(int, sys.stdin.read().split())
denom = 7A + B
ans = float('inf')
for r in range(7):
if A * r >= C:
ans = min(ans, r)
else:
need = C - A * r
k = (need + denom - 1) // denom
candidate = 7k + r
ans = min(ans, candidate)
print(ans)
But we should consider that r=0 case: candidate = 7k. If A0>=C? only if C<=0, not possible.
Now one more nuance: There is also the possibility of not using a consecutive block but still achieving more coins? We already argued no. But let's double-check with a small case: A=1, B=5, C=10. Our formula: denom=7+5=12. r=0: need=10, k=ceil(10/12)=1, candidate=7. Coins for N=7: 7+5=12 >=10. So answer 7. Is there any schedule with N=6 that yields >=10? Without bonus, max=6. With bonus, to get bonus need 7 days. So 6 insufficient. So 7 is minimal.
Now test A=2, B=5, C=15. Brute: N=6: 12 + 0=12; N=7: 14+5=19 -> N=7. Our formula: denom=14+5=19? Actually 7A+B=14+5=19. r=0: need=15, k=ceil(15/19)=1 -> 7; r=1: 2<15 need=13, ceil(13/19)=1 ->8; r=2:4<15 need=11 ceil=1->9; r=3:6<15 need=9 ceil=1->10; etc. So min=7. Works.
Now test A=5, B=1, C=100. denom=35+1=36. r=0: need=100, k=ceil(100/36)=3 (since 236=72<100,336=108) -> candidate=21. Coins=521+13=105+3=108>=100. r=1:5<100 need=95, k=ceil(95/36)=3 -> candidate=21+1=22, coins=110+3=113. r=2:10<100 need=90, k=ceil(90/36)=3 -> candidate=21+2=23 coins=115+3=118. r=3:15<100 need=85, k=ceil(85/36)=3 -> 24 coins=120+3=123. r=4:20<100 need=80, k=ceil(80/36)=3 -> 25 coins=125+3=128. r=5:25<100 need=75, ceil(75/36)=3 ->26 coins=130+3=133. r=6:30<100 need=70, ceil(70/36)=2? 236=72 >=70, so k=2, candidate=14+6=20 coins=520+12=100+2=102>=100. So candidate=20 is less than 21! So min=20. Let's verify: N=20, floor(20/7)=2, coins = 520 + 2*1 = 100+2=102. That's >=100. N=19: floor=2? 19/7=2, remainder 5, coins=95+2=97 <100. So indeed minimal N=20. Our formula gives min 20. So okay.
Now test A=5, B=1, C=99. Then N=20 yields 102>=99, but maybe N=19 yields 97 insufficient. So 20. Our formula: r=6 gave candidate=20, r others gave larger? r=0 gave 21; so min 20. Good.
Now this shows that sometimes the residue r=6 yields a smaller N than r=0 because we can get an extra partial week of 6 days after some full weeks? Actually in that case, with r=6 we used k=2 (2 full weeks) and 6 extra days, total 20 logins. That's less than 3 full weeks (21 logins). So the optimal is not necessarily to maximize full weeks; it's to find balance between extra days and full weeks. So our r loop accounts for that.
Thus algorithm is correct.
Now we just output the integer.
Now final step: Produce answer.
But wait: In some problems, there may be an alternative interpretation: The bonus B is given each time you log in for 7 consecutive days (i.e., each streak of 7 consecutive logins regardless of week alignment). The phrase "from Monday to Sunday" might be just indicating a week period. However, in typical JOI problem "Coin" (maybe from JOI 2018/2019?), it's exactly as we used.
Let me search memory: There is a JOI problem "Coins" or "Login Bonus" from 2019? Actually I recall a JOI 2019/2020 qualifying problem "Login" about logging in to get coins with daily bonus and weekly bonus. But I think it's "Game" maybe. But no matter, the examples fit.
Now we can produce final answer.
But also note that in the problem statement, it says "JOI decided to start a new social game from tomorrow." And "Tomorrow is Monday." So the first day is Monday. So starting on Monday is natural.
Thus solution.
Now consider potential pitfalls: The input may have extra spaces or newline. We'll handle.
Now produce final code.
But for completeness, we should mention that we treat the case where B may be zero, and denominator = 7A, fine.
Now I'll output solution.
Given the output should be just the number, not with extra text.
Now finalize.
But wait: In the problem statement, the sample output says "Four" but that's likely just description. In the actual required output, it's numeric. So we output integer.
Thus done.
Now write final answer.
One more test: A=10, B=10, C=100. denom=80. r=0: need=100, k=ceil(100/80)=2 ->14, candidate=14? Actually 72=14, coins=1014+102=140+20=160>=100. r=6: A6=60<100 need=40, ceil(40/80)=1 -> candidate=7+6=13, coins=130+10=140>=100. r=5: 50<100 need=50, ceil(50/80)=1 ->12, coins=120+10=130. r=4:40<100 need=60, ceil(60/80)=1 ->11, coins=110+10=120. r=3:30<100 need=70, ceil=1 ->10, coins=100+10=110. r=2:20<100 need=80, ceil(80/80)=1 ->9, coins=90+10=100 (exact). So candidate=9 yields coins=100 exactly. So answer 9. Check brute: N=8: floor=1, coins=80+10=90<100. N=9: floor(9/7)=1, coins=90+10=100. So correct. So our formula yields 9. Good.
Now note: For r=2, candidate=9, which is smaller than 14. So minimal N=9.
All good.
Now let's think about possible optimization: None needed.
Now answer.
But before finalizing, I'll also think about potential alternative: Could there be a schedule that yields coins greater than AN + Bfloor(N/7) by having overlapping full weeks? For example, if you log in for 8 days starting Monday, you get one full week (Monday-Sunday) and also maybe a full week starting Tuesday? But that week would be Tuesday-Monday, not Monday-Sunday. So no. So our bound is tight.
Now one more nuance: The phrase "each time" might mean that each login during the 7 consecutive days gives additional B coins. But example 2 says: "If you log in consecutively from Monday to Sunday, you will get 2 coins in addition to 7 daily coins, so you will get a total of 9 coins." That is clearly one B of 2 for the whole streak. If it were per day, they'd get 7*2=14 extra, total 21, not 9. So confirmed.
Thus final solution.
Now I'll write final answer in Python. We need to find the minimum number of logins N such that the maximum possible coins obtainable with N logins is at least C.
The optimal strategy is to log in on consecutive days starting on Monday, which yields
[
\text{coins} = A \cdot N + B \cdot \left\lfloor \frac{N}{7} \right\rfloor .
]
Thus we need the smallest integer N satisfying
[
A N + B \left\lfloor \frac{N}{7} \right\rfloor \ge C .
]
Writing (N = 7k + r) with (0 \le r \le 6), the condition becomes
[
(7A + B)k + A r \ge C .
]
For each remainder (r), the smallest (k) that works is
[
k = \max!\left(0,; \left\lceil \frac{C - A r}{7A + B} \right\rceil \right) ,
]
and the corresponding candidate is (N = 7k + r).
The answer is the minimum over (r = 0,1,\dots,6).
import sys
def solve() -> None:
A, B, C = map(int, sys.stdin.read().split())
denom = 7 * A + B # 7A + B
ans = 10 ** 9
for r in range(7):
if A * r >= C:
ans = min(ans, r)
else:
need = C - A * r
k = (need + denom - 1) // denom # ceil division
candidate = 7 * k + r
ans = min(ans, candidate)
print(ans)
if __name__ == "__main__":
solve()