We are asked: AtCoder Mart sells 1,000,000 of each of six items, with prices: 100,101,102,103,104,105 yen. Takahashi wants to buy some of them that cost exactly X yen in total. Determine whether this is possible.
We need to output 1 if possible, else 0.
Constraints: 1 ≤ X ≤ 100000.
This is essentially a coin change / subset sum problem with unlimited (but large) copies of six coin denominations: 100,101,102,103,104,105. Need to check if X can be expressed as a non-negative integer combination of these denominations.
But note the constraints are relatively small: X ≤ 100000. So we can do DP with boolean array of size X (or up to X). However there is perhaps a smarter observation.
Given the denominations: they are six consecutive integers from 100 to 105. This is reminiscent of the "Frobenius coin problem" and we can check if X is greater or equal to a certain threshold. Since 100 is the smallest, any number that is a multiple of 100 can be formed, but we have other denominations that can adjust the sum by 1,2,3,4,5 mod 100. Actually note: The set of denominations includes 100,101,...,105. So we can produce any integer that is at least some minimal amount? Let's analyze.
We want to represent X as a linear combination a100 + b101 + c102 + d103 + e104 + f105, with nonnegative integers a,b,c,d,e,f.
We can think of modulo 100. Each price is ≡ 0,1,2,3,4,5 mod 100. So the sum modulo 100 is (b + 2c + 3d + 4e + 5f) mod 100 (since 100 multiples don't affect modulo). So the possible residues mod 100 that can be obtained are the nonnegative integer combinations of 1,2,3,4,5 (with unlimited counts) modulo 100. Since we can also include any number of 100 items (which add 0 mod 100). So the set of achievable residues modulo 100 is the semigroup generated by {1,2,3,4,5} modulo 100, but actually we don't need modulo 100, we need actual numbers, but the condition for existence is that for X, we need to find nonnegative integers such that X ≡ some combination of 1-5 mod 100, and the total sum is X.
But there is also the constraint on total value: we can overshoot? No, we need exactly X.
Now, given unlimited copies, the coin problem with set that includes a consecutive set of integers from 100 to 105 likely can represent all integers >= 100*? Actually we need to find the largest integer that cannot be represented (Frobenius number). For coin sets that are relatively prime, but here gcd of denominations is 1? Check: gcd(100,101,102,103,104,105). 100=2^25^2, 101 prime, 102=2317, 103 prime, 104=2^313, 105=357. The gcd is 1. So all sufficiently large integers can be represented. But the threshold might be something like 100101 - 100 - 101? That's for two coins, but for multiple consecutive numbers, there might be a known result: All integers >= 100? Actually there's known "Chicken McNugget" with 6,9,20 etc. But here we have 6 numbers that are consecutive from 100 to 105 inclusive. Since they cover a complete set of residues modulo 100? Actually they are 0,1,2,3,4,5 mod 100. With these we can generate any integer mod 100? Because we can get any remainder r (0 <= r <= 5) simply by taking one item of price 100+r (if we need exactly r). For r > 5, we can combine multiple items. Since we have 1,2,3,4,5 we can generate all integers from 0 up to some number? The semigroup generated by 1,2,3,4,5 is all nonnegative integers except possibly 1? Actually 1 is possible directly (use a 101 item). 2: 102. 3:103. 4:104. 5:105. 6: 101+105? 101+105=206 but that gives 6 mod 100? Actually 206 mod 100 =6. But we also can combine 101+101=202 -> 2 mod 100, not 6. But to get remainder 6, we need sum of residues =6. Since we have 1 and 5 gives 6. So we can get 6. 7=2+5 or 3+4 or 1+1+5? but all produce remainders 7. Actually 2+5=7. So we can get 7. 8=3+5 or 4+4 or 1+2+5 etc. 9=4+5 or 3+3+3? But note that we also can use many copies: the residues can be summed to any integer >= 0? Since 1 and 5 can generate any integer >=? The set {1,2,3,4,5} has gcd 1, so all sufficiently large integers can be represented as a nonnegative combination. The Frobenius number for {1,2,3,4,5} is? Since 1 is present, everything is possible. Wait, we have the residue 1 itself (101) gives remainder 1. That means we can achieve any remainder modulo 100? Because if we can achieve any integer remainder r by using some combination of items whose total modulo 100 equals r, as long as we can also add multiples of 100 to adjust the total sum to exactly X. But careful: The sum of the residues (b+2c+3d+4e+5f) must equal the remainder of X mod 100. Since we have item with residue 1, we can always represent any remainder r by using r copies of 101 (or mix). But there might be a constraint: The total value contributed by those items may exceed X? Because if X is small, using many items could overshoot? However, the residues part is only part of the total value: each item also contributes a multiple of 100. For example, if X = 1, remainder 1 mod 100. To get remainder 1, we could use one 101 item, but that costs 101 which is > 1. That's not allowed because we need total exactly X, not just modulo. So the modulo condition is necessary but not sufficient: we also need the total sum to equal X exactly. That means we need to allocate items such that the sum of 100 * (some number) + some combination of the residues equals X. The 100 multiples come from the base 100 per item, but note each item contributes at least 100 (since the cheapest is 100). So any item adds at least 100 to the total. So if X is less than 100, it's impossible unless X=0? But X≥1. So any representation must use items whose individual costs are at least 100, so if X < 100, it's impossible. For X between 1 and 99, answer 0.
But also for X = 100, we can use one riceball (100). So possible.
For X = 101, use sandwich (101). For X=102, cookie; 103, cake; 104, candy; 105, computer.
For X=106? Is that possible? 106 = 101 + 5? But 5 corresponds to 105? That sum 101+105=206 >106. So maybe 100+6? But we have no 6. Actually 106 = 100 + 6. But we need to get total 106. Could we use two items: 100+? 6? But no item costs 6. Could we use 101+? 5? 105 again too high. So maybe 100+101=201 >106. So 106 might be impossible? But we can also use 102+? 4? 104? 102+104=206 >106. 103+? 3? 103+103=206? Actually 103+103=206. So not possible. But maybe use 100+? Actually, we can use more than two items? But any item is at least 100, so if we use two items sum >=200 >106. So only 0 or 1 item possible for X<200. 0 items sum to 0 not allowed. So only possibility for X between 100 and 199 is exactly one item. So only X in {100,101,102,103,104,105} are possible. So 106-199 are impossible.
Now for X=200: we can use two 100 items => 200, possible. Also 200 = 100+100. Could we get 200 as 101+99? Not possible. So only multiples of 100? Actually 101+? 99? no. So 200 possible. 201? Could be 100+101=201, yes possible. 202? 100+102=202 or 101+101=202? 101+101=202, yes possible. 203? 100+103=203 or 101+102=203 possible. 204? 100+104=204 or 102+102=204 or 101+103=204 possible. 205? 100+105=205 or 101+104=205 or 102+103=205 possible. 206? 101+105=206 or 100+106? but 106 not item; also 102+104=206, 103+103=206, so 206 possible. 207? 102+105=207 or 101+106? no; 103+104=207, also 100+107? none. So 207 possible. 208? 103+105=208, 104+104=208, 101+107? no; so 208 possible. 209? 104+105=209, 100+109? no; 101+108? no; 102+107? no; 103+106? no; but 209 = 100+109? not; 101+108? no; 102+107? no; 103+106? no; 104+105=209 so yes possible. 210? 105+105=210, 100+110? not; 101+109? no; 102+108? no; 103+107? no; 104+106? no; but 105+105=210 so possible. 211? 100+111? not; 101+110? no; 102+109? no; 103+108? no; 104+107? no; 105+106? no; could we use three items? The minimum sum with three items is 300, too high. So 211 seems impossible. But wait, maybe we can use items with total 211 using more than two items? The smallest three-item sum is 100+100+100=300 >211, so three items not allowed. So for X between 200 and 299, at most two items possible. So the set of achievable sums in [200,299] are all sums of two items from {100,101,102,103,104,105}. Let's list all possible two-item sums:
100+100=200
100+101=201
100+102=202
100+103=203
100+104=204
100+105=205
101+101=202 (duplicate)
101+102=203
101+103=204
101+104=205
101+105=206
102+102=204
102+103=205
102+104=206
102+105=207
103+103=206
103+104=207
103+105=208
104+104=208
104+105=209
105+105=210
So possible sums: from 200 to 210 inclusive, but not all numbers? Check: 200,201,202,203,204,205,206,207,208,209,210. That's 11 numbers. 211 is not present. So 211-299 (except those <=210) are impossible? Wait, up to 299 we are still in the range where two items max sum is 210, but three items minimum is 300. So for any X from 211 to 299, it's impossible because you would need at least three items (sum >=300) or one item (max 105) which is too low. So all numbers 211-299 are impossible.
Now for X=300: three items: min sum 300 (three 100's) => possible. Also 300 = 100+100+100. So possible. 301? 100+100+101=301 possible. 302? 100+100+102=302; also 100+101+101=302. So possible. Continue up to? The maximum sum with three items is 105+105+105=315. So for X from 300 to 315 inclusive, there exist three-item combinations? Need to check if all integers in [300,315] are achievable with three items. Since the set of three-item sums is all sums of three numbers each from 100 to 105. That's like the set {300 + (i+j+k) where i,j,k in {0,1,2,3,4,5}}. So the sum is 300 + S, where S = a+b+c with a,b,c ∈ {0,...,5}. The minimum S is 0 (all a=0) and maximum S=15 (all a=5). So the achievable sums are exactly 300,301,...,315? Is every integer in that range representable as sum of three numbers each 0-5? This is like the possible sums of three dice. The possible sums range from 0 to 15, and all integers in between are possible because the minimum increments of 1 can be achieved. Indeed, the number of combinations for each sum: 0: only (0,0,0); 1: (0,0,1) etc. So yes, all sums from 0 to 15 inclusive are achievable. So 300-315 are all possible.
What about 316? That would require S=16, but maximum S is 15 for three items. So three items cannot produce 316. Could four items be used? Minimum sum with four items is 400, which exceeds 316. So 316 is impossible. Similarly, X from 316 to 399 are impossible? Because the maximum sum with three items is 315, and minimum with four items is 400. So numbers 316-399 are unreachable.
Thus pattern: For any nonnegative integer k, the achievable sums with exactly n items? Actually, if we have n items, the total cost = 100*n + S, where S is sum of n increments each in {0,1,2,3,4,5}. So S can range from 0 to 5n. So total cost can range from 100n to 100n+5n = 105n.
Thus for a given X, we need to see if there exists n such that 100n ≤ X ≤ 105n, and also that X - 100n (call it D) is achievable as sum of n numbers each between 0 and 5 inclusive. That is, D must be between 0 and 5n, and also we must be able to partition D into n parts each ≤5. But if D is any integer between 0 and 5n, is it always possible to represent D as sum of n numbers each between 0 and 5? Not necessarily: For n=2, D can be 0..10, but we saw that D=1? That would require one 1 and one 0, so sum 1 possible: (0,1) works. D=2: (0,2) or (1,1) works. D=3: (0,3) or (1,2) works. D=4: (0,4) or (2,2) or (1,3) works. D=5: (0,5) or (1,4) or (2,3) works. D=6: (1,5) or (2,4) or (3,3) works. D=7: (2,5) or (3,4) works. D=8: (3,5) or (4,4) works. D=9: (4,5) works. D=10: (5,5) works. So all from 0 to 10 inclusive are possible. For n=2, all D in [0,10] are achievable. For n=1, D in [0,5] all achievable? Yes, D=0..5 correspond to items. For n=3, D from 0 to 15 are all achievable (like sum of three dice). For n=4, D from 0 to 20. Is every integer from 0 to 20 achievable as sum of four numbers each 0-5? Let's test: The minimum is 0, max 20. Is there any gap? The possible sums are all integers because you can increment by 1 by changing one of the numbers from 0 to 1, etc. More formally, the set of achievable sums for n increments is the set of integers from 0 to 5n, because the steps of 1 are possible: Starting from all zeros, you can increase one increment by 1 up to 5, covering all sums up to 5. Actually, with n numbers each ranging 0..5, the set of achievable sums is every integer from 0 to 5n. Reason: It's like having n digits each base 6 but with max 5, and you can represent any integer as a sum in mixed radix? For n=2, we saw all from 0..10. For n=3, 0..15. For n=4, does 19 achievable? 5+5+5+4=19 yes. 18? 5+5+5+3=18. 17? 5+5+5+2=17. 16? 5+5+5+1=16. 15? 5+5+5+0=15. 14? 5+5+4+0=14 etc. So yes, it seems all integers from 0 to 5n are achievable. Is there any n for which there is a gap? This is essentially the property of having n copies of {0,...,5}, which is a complete set of residues mod something? The set is an interval [0,5], so the sumset of n copies is [0,5n] (since it's the n-fold sumset of an interval; the sumset of intervals is an interval). More formally, if A = {0,1,...,5}, then A + A = {0,...,10}, and by induction, nA = {0,...,5n}. This holds because A contains consecutive integers, so the Minkowski sum of intervals is an interval. So indeed, for any n, the possible sums D are exactly all integers from 0 to 5n.
Thus the condition reduces to: There exists integer n >= 0 such that 100n ≤ X ≤ 105n. Because if X is between 100n and 105n inclusive, then set D = X - 100n is between 0 and 5n, which is achievable. So the problem reduces to checking if there exists n (non-negative integer, but at least maybe 0? X≥1 so n must be positive) satisfying X ∈ [100n, 105n].
We also have unlimited number of items, but n is the number of items purchased. There is no upper bound because we have up to 1,000,000 of each, but X ≤ 100000, so n cannot exceed 1000 (since 100*1000=100000). So we can simply loop n from 1 to floor(X/100) maybe up to 1000 and check. But there might be a direct condition.
We need to find if X can be expressed as 100n + D where 0 ≤ D ≤ 5n. That's equivalent to existence of n such that X is within that interval.
This can be restated as: X must be at least 100, and also there exists n such that n ≤ X/100 and n ≥ X/105 (since from X ≤ 105n => n ≥ X/105). So we need ceil(X/105) ≤ floor(X/100) and also n integer in that range. So check if ceil(X/105) ≤ floor(X/100). That is a necessary and sufficient condition? Also for X < 100, floor(X/100)=0, but n must be positive, so condition fails. For X=100, ceil(100/105)=1? 100/105 ≈0.952, ceil=1. floor(100/100)=1, so 1 ≤ 1, true. For X=101, ceil(101/105)=1, floor(101/100)=1, true. For X=102, same. ... For X=105, ceil(105/105)=1, floor(105/100)=1, true. For X=106, ceil(106/105)=2 (since 106/105>1), floor(106/100)=1 (since 106/100=1.06 floor=1). So 2 ≤ 1 false. So 106 fails. For X=200, ceil(200/105)=2 (200/105≈1.9048 ceil=2), floor(200/100)=2, true. X=201, ceil(201/105)=2 (1.914→2), floor(201/100)=2, true. ... up to X=210, ceil(210/105)=2, floor(210/100)=2, true. For X=211, ceil(211/105)=3? 211/105≈2.0095 ceil=3, floor(211/100)=2, so false. So 211 fails. This matches our earlier enumeration.
Thus the condition is: X is representable if and only if there exists integer n such that 100n ≤ X ≤ 105n. Equivalent to ceil(X/105) ≤ floor(X/100). Since X ≤ 100000, we could simply loop n from 1 to 1000, but the direct inequality is also easy.
But wait, is it always sufficient that X is between 100n and 105n for some n? Because D = X-100n is between 0 and 5n, and we argued that any D in that range can be expressed as sum of n numbers each between 0 and 5. But is it always possible when D is, say, 5n-1? That is sum of n numbers max 5, sum = 5n-1. Since we can have n-1 items of 5 and one item of 4 => total 5(n-1)+4 = 5n-1, yes. Similarly any D can be expressed as: let k = floor(D/5), then use k items of 5, one item of D-5k (which is between 0 and 4), and the rest 0. But careful: we need exactly n items total. So if we use k items of 5 and one item of r = D - 5k (where 0 ≤ r ≤ 4), that totals k+1 items if r>0, or k items if r=0. We need exactly n items. So we need to distribute the remaining items as zeros (i.e., choose 100 yen items). So we can always set the rest of the items as the base 100 yen items (which correspond to increment 0). So indeed, we have n items total: we choose some number of non-100 items? Actually each item type corresponds to a specific increment: 100->0, 101->1, 102->2, 103->3, 104->4, 105->5. So to achieve a given D, we need to select n items, each with increment a_i ∈ {0,1,2,3,4,5}, such that sum a_i = D. Since we can always use zeros (riceballs) to fill up the count, as long as the required number of non-zero increments does not exceed n. But if D is large, we might need many items with positive increments; but we have at most n items, and the maximum sum with n items if we use max increments 5 is 5n. Since D ≤ 5n, it's possible. Moreover, we can always achieve any D by using floor(D/5) items of increment 5, one item of increment D mod 5 (if non-zero), and the rest zeros. This uses at most floor(D/5) + (1 if D%5>0 else 0) items. That number is ≤ ceil(D/5) ≤ ceil(5n/5)=n. So we can fill the rest with zeros to reach n items. So yes, condition is sufficient.
Thus the problem reduces to checking existence of integer n with 100n ≤ X ≤ 105n.
Now, we can compute n_min = ceil(X/105) and n_max = floor(X/100). If n_min ≤ n_max, answer 1, else 0.
But careful: X could be 0? X≥1 per constraints. So okay.
Now check edge cases: X = 100000. n_min = ceil(100000/105) = ceil(952.3809...) = 953. n_max = floor(100000/100) = 1000. So 953 ≤ 1000 => true. So 100000 should be representable. Let's test: 953100 = 95300, 953105=100065, so X=100000 is within. So yes.
X=99999? n_min = ceil(99999/105)=ceil(952.3714)=953, n_max = floor(99999/100)=999, 953 ≤ 999 true. So possible.
X=953100=95300, possible. X=953105=100065 > 100000 so not relevant.
Thus answer is simple.
But wait: There might be a nuance: The Mart sells exactly 1,000,000 of each item. That suggests there is an upper bound on the number of each item we can take. However, X ≤ 100000. The maximum number of any single item needed is at most X/100 = 1000. Since 1000 is far less than 1,000,000, the limitation is irrelevant. So we can treat as unlimited.
Thus the solution is straightforward.
Given that, the problem seems to be from AtCoder ABC and likely expects to use DP? But the smarter solution is as derived. However, the input constraint small enough that DP of size X with 6 items is fine (X up to 100k). But the O(X*6) is acceptable. But I'll propose the mathematical condition for efficiency.
Let's implement: read X. Then compute lo = (X + 104) // 105? Wait ceil division: ceil(X/105) = (X + 104) // 105? Since 105-1=104. Actually ceil(a/b) = (a+b-1)//b. So n_min = (X + 104) // 105. n_max = X // 100 (since floor division). Then if n_min <= n_max: print 1 else 0.
But careful: For X < 100, n_max = 0, n_min = 1 (since X+104 // 105 >=1). So condition fails. Good.
Test examples: X=615. n_min = ceil(615/105)= ceil(5.857)=6? 1055=525, 1056=630, so ceil=6. n_max = floor(615/100)=6. 6<=6 => 1. matches.
X=217. n_min = ceil(217/105)= ceil(2.0667)=3. n_max = floor(217/100)=2. 3<=2 false =>0. matches.
Thus answer.
But double-check: 217: possible combinations? 2 items max 210, 3 items min 300, so impossible.
Now also test X=1000. n_min = ceil(1000/105)=10 (since 1059=945, 10510=1050) =>10, n_max = floor(1000/100)=10 => possible? 10 items: sum could be from 1000 to 1050. So 1000 is possible using ten 100 items.
X=1001: n_min = ceil(1001/105)=10 (since 1050>=1001? Actually 1059=945, 10105=1050, 1001<1050, so ceil=10), n_max = floor(1001/100)=10, condition holds? 10<=10. So 1001 should be possible? 10 items total sum between 1000 and 1050. To get 1001, we need D=1 across 10 items. Since D=1, we can use one 101 and nine 100s: 101+9*100=1001. Yes possible. So fine.
Edge: X=1050: n_min = ceil(1050/105)=10, n_max = floor(1050/100)=10, so possible: ten 105s => 1050. Good.
X=1051: n_min = ceil(1051/105)=11 (since 10510=1050, 10511=1155), n_max = floor(1051/100)=10 => fails. So 1051 cannot be represented? Could it be with 11 items? Min 1100, too high. 10 items max 1050, too low. So impossible.
Thus condition works.
Now for completeness, we might need to consider n up to some maximum? Since X <= 100000, n_max <= 1000. So alternative solution: loop n from 1 to 1000, check if 100n <= X <= 105n. That's also fine.
But the integer division method is simpler.
Thus answer: compute and output accordingly.
We need to write the code in the required language? The problem statement doesn't specify language, but we are to provide a solution. Usually it's in Python. So:
def solve():
X = int(input())
lower = (X + 104) // 105
upper = X // 100
if lower <= upper:
print(1)
else:
print(0)
But careful: (X + 104) // 105 for X=0 gives 0? But X≥1.
Test with X=100: (100+104)=204 //105=1, upper=1 -> ok.
X=105: (105+104)=209 //105=1 (since 209//105=1) Actually 209//105=1 remainder 104, so gives 1, but we want ceil(105/105)=1. Good.
X=106: (106+104)=210//105=2 -> lower=2, upper=1 => fail.
Thus correct.
Now let's consider if X=0 (though not in constraints). If X=0, lower = (0+104)//105=0? Actually 104//105=0, so lower=0, upper=0, would output 1, but we don't need to consider.
All good.
But the problem says: "AtCoder Mart sells 1000000 of each of the six items below" implying limited quantity, but as argued, we never need more than 1000, so fine.
Thus solution is O(1).
We should provide the reasoning and the code.
Given the instruction: "You are an AI... provide answer", I think we need to output the final answer? The prompt says: "AtCoder problem ... determine whether possible... print 1 or 0". But the conversation might be asking to provide the solution code? Usually, AtCoder tasks require code. The user likely expects the code solution. However, the system message says: "You are an AI assistant designed to provide high-quality answers to programming contest problems." And "Write a complete solution... include explanation and code." So we need to output a full solution explanation and code.
Thus I'll produce a thorough explanation, then code in Python.
But note: The problem may be from AtCoder Beginner Contest, typical solution is simple.
Let me produce final answer: Explanation of the condition and code.
Potential pitfalls: Need to handle X less than 100 correctly. The condition covers it because lower bound is at least 1 and upper bound 0, so false.
Now ensure to use integer arithmetic.
Edge: X=1: lower = (1+104)//105 =105//105=1, upper=0, false -> 0. correct.
Now any X between 100 and 105? Works.
All good.
Thus final solution.
Now I'll craft the answer.
But the user message: "AtCoder Mart sells 1000000 of each of the six items below: ... Takahashi wants to buy some of them that cost exactly X yen ... Determine whether possible... print 1 or 0." They might just want the code. But I'll include explanation as typical.
I'll output:
import sys
def main():
X = int(sys.stdin.readline().strip())
# smallest n such that 105*n >= X
n_min = (X + 104) // 105
# largest n such that 100*n <= X
n_max = X // 100
if n_min <= n_max:
print(1)
else:
print(0)
if __name__ == "__main__":
main()
And maybe include comment.
But also note the constraints: X up to 100000, so fine.
Thus final. We can solve the problem by observing that if we buy (n) items, the total cost lies between (100n) (all riceballs) and (105n) (all computers). Moreover, for any integer (D) with (0 \le D \le 5n), we can achieve a total cost of (100n + D) by choosing appropriate items (e.g., use (\lfloor D/5 \rfloor) computers, one item of price (100 + (D \bmod 5)) if needed, and fill the rest with riceballs). Therefore, an amount (X) is achievable exactly when there exists an integer (n) such that
[
100n \le X \le 105n.
]
Since (X \le 100000), the number of items (n) is at most (1000). The condition can be checked directly by computing
[
n_{\min} = \left\lceil \frac{X}{105} \right\rceil, \qquad
n_{\max} = \left\lfloor \frac{X}{100} \right\rfloor,
]
and verifying whether (n_{\min} \le n_{\max}). This also correctly handles the case (X < 100) (where (n_{\max}=0) and the inequality fails).
The solution runs in (O(1)) time.
import sys
def main():
X = int(sys.stdin.readline().strip())
# smallest n with 105*n >= X
n_min = (X + 104) // 105 # ceil division
# largest n with 100*n <= X
n_max = X // 100 # floor division
print(1 if n_min <= n_max else 0)
if __name__ == "__main__":
main()