Valera had two bags of potatoes, the first of these bags contains x (x ≥ 1) potatoes, and the second — y (y ≥ 1) potatoes. Valera — very scattered boy, so the first bag of potatoes (it contains x potatoes) Valera lost. Valera remembers that the total amount of potatoes (x + y) in the two bags, firstly, was not gerater than n, and, secondly, was divisible by k.
Help Valera to determine how many potatoes could be in the first bag. Print all such possible numbers in ascending order.
Input
The first line of input contains three integers y, k, n (1 ≤ y, k, n ≤ 109; ≤ 105).
Output
Print the list of whitespace-separated integers — all possible values of x in ascending order. You should print each possible value of x exactly once.
If there are no such values of x print a single integer -1.
Examples
Input
10 1 10
Output
-1
Input
10 6 40
Output
2 8 14 20 26
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 need to understand the problem: We have two bags of potatoes, first bag contained x potatoes (x >= 1), second bag contains y potatoes (y >= 1). The first bag is lost, but we know y, k, n. We also know that total x+y <= n, and (x+y) is divisible by k. We need to find all possible x (positive integers) that satisfy these conditions. Output in ascending order, separated by spaces. If none, output -1.
Constraints: y, k, n up to 1e9, but perhaps number of outputs is limited: something ≤ 10^5? Actually problem statement: "1 ≤ y, k, n ≤ 109; ≤ 105". Probably it means that the output size (the number of x) is at most 1e5. So we need to generate all x values that satisfy:
x >= 1
x + y <= n
(x + y) % k == 0
We can rearrange: x = t * k - y, where t is some integer (since (x+y) = t * k). Then we need:
x >= 1 -> tk - y >= 1 -> tk >= y+1 -> t >= ceil((y+1)/k)
Also x + y = tk <= n -> tk <= n -> t <= floor(n/k)
Also x >= 1 integer, t integer positive (since x+y >= y+? Actually x>=1 so x+y>= y+1, so tk >= y+1 >0, so t>=1). But also t must be integer. Also x is automatically integer if tk - y is integer, which it is.
Thus x = kt - y, for integer t in range [t_min, t_max] where t_min = ceil((y+1)/k) and t_max = floor(n/k). Also note that x must be >= 1, but the condition tk - y >= 1 already ensures it.
But also is there any upper bound on x? Not explicitly besides x+y <= n, so x <= n-y. That is automatically satisfied by tk - y <= n - y -> tk <= n, which is our condition.
Thus all x = kt - y for t = ceil((y+1)/k), ..., floor(n/k). However, we need x >= 1 and also x can be 0? No x>=1. So we must ensure tk - y >=1.
But careful: The condition "the first bag of potatoes (it contains x potatoes) Valera lost." It says x>=1. And second bag contains y>=1. Also "Valera remembers that the total amount of potatoes (x + y) in the two bags, firstly, was not greater than n, and, secondly, was divisible by k." So that's it.
Now we need to print all possible x in ascending order. However, note that the output size may be up to 1e5 due to constraints? Actually n up to 1e9, but k can be 1, then the number of x could be up to n - y, which could be up to 1e9, too large to output. But the problem states something like ≤ 10^5. In many Codeforces problems, they guarantee that the number of solutions is at most 10^5. The problem statement: "1 ≤ y, k, n ≤ 109; ≤ 105". Possibly the image shows something like "The number of such x's does not exceed 10^5". This is typical. So we can iterate over t in the range and generate x, but if the range is large, we might need to iterate many t values. However, if the range of t is huge (like up to 1e9/k), but the number of solutions is guaranteed not to exceed 1e5, so we can simply iterate over t from something? Actually the number of t in the range could be huge but the number of valid x (i.e., t such that x >= 1 and tk <= n) might be huge. But they claim it doesn't exceed 10^5. So that suggests the difference between floor(n/k) and ceil((y+1)/k) is at most 1e5? Possibly because of the constraints? Let's check: n up to 1e9, k can be 1, then floor(n/k) ~ 1e9, ceil((y+1)/k)~ y+1 ~ up to 1e9, difference could be up to ~1e9, so number of possible t would be huge, but then number of x would also be huge. However the problem might have additional constraint: The maximum number of x's is at most 1e5. So they guarantee that the answer set is small; we can generate them by iterating over possible t? But if t range is huge but answer set small, it might be because many t produce x <=0? Actually condition x>=1 already filters. If k is 1, then x = t - y. t must be from y+1 to n (since t must be <= n because t1 <= n). That gives x from 1 to n-y. That's up to 1e9 possibilities. That would violate the claimed bound. So maybe the problem statement mis-copied? Let's look at the examples: Input: 10 1 10 -> output -1. For y=10, k=1, n=10. Then x = t*1 - 10, with t integer from ceil(11/1)=11 to floor(10/1)=10. So t_min > t_max, no solution. That's consistent.
Second example: y=10, k=6, n=40. t_min = ceil(11/6) = ceil(1.833)=2. t_max = floor(40/6)=6 (since 66=36, 76=42 >40). So t = 2,3,4,5,6. Compute x = 6t-10: t=2->2, t=3->8, t=4->14, t=5->20, t=6->26. That's 5 numbers. Output: 2 8 14 20 26. So works.
Thus the set of x is all numbers of the form k*t - y where t runs through a contiguous integer interval. The number of such x equals max(0, t_max - t_min + 1). That could be as large as n/k - (y+1)/k approx (n-y)/k. For k=1, up to n-y. So n-y could be up to 1e9 - 1. That would be too many. But maybe there is an additional condition: " ≤ 105". This might be misrepresented. Actually in Codeforces problem 61A? No, let's recall: This looks like Codeforces problem "Little Elephant and Numbers"? Not sure. Another problem: "Valera and X"? Hmm.
Wait, I recall a Codeforces problem: "A. Little Elephant and Numbers" or "A. Cheap Travel"? Not.
Maybe it's from Codeforces Round #... Actually there is a problem: "A. Two Bags of Potatoes" (CF #239? I think it's Codeforces 239A?). Yes, I remember: Codeforces Round #239 (Div. 2), problem A: "Two Bags of Potatoes". The constraints: 1 ≤ y, k, n ≤ 10^9. And the output size does not exceed 10^5. Actually in that problem, the solution is: print all x = k*i - y for i from 1 to n/k, with x >= 1, x <= n-y. But there is an upper bound on number of answers: n/k <= 10^5? But n/k could be up to 10^9 if k=1. However maybe they guarantee that k is such that n/k <= 10^5? Not exactly.
Let's look up the exact problem: I think it's Codeforces 239A - "Two Bags of Potatoes". I recall the problem: "Valera had two bags of potatoes, the first of these bags contains x (x ≥ 1) potatoes, and the second — y (y ≥ 1) potatoes. Valera — very scattered boy, so the first bag of potatoes (it contains x potatoes) Valera lost. Valera remembers that the total amount of potatoes (x + y) in the two bags, firstly, was not greater than n, and, secondly, was divisible by k. Help Valera to determine how many potatoes could be in the first bag. Print all such possible numbers in ascending order." Input: y, k, n (1 ≤ y, k, n ≤ 10^9; n ≤ 10^5?). Hmm, maybe I misremember.
Let's check typical CF 239A: I recall the constraints: 1 ≤ y, k, n ≤ 10^9; n ≤ 10^5? Actually maybe the problem had a constraint that n ≤ 10^5? Or maybe they said the number of x values does not exceed 10^5? Many problems have such note. Actually in the problem statement on Codeforces, it says: "It is guaranteed that all possible values of x are distinct and do not exceed 10^5." Or something? Let's look online. I'm not connected, but I'll reconstruct: The typical solution for CF 239A is to iterate from i = 1 to n/k (or something) and check condition. Since n can be up to 10^9, that could be too many iterations, but they note: "It is guaranteed that the number of different values of x is not greater than 10^5." So you can iterate over i from 1 while ik <= n, but only consider those ik > y. And the number of i such that ik <= n is n/k which could be 10^9, but they guarantee that the number of valid x is <= 10^5, which means that maybe k is large enough? Actually n/k could still be large if k small. But the guarantee "number of x's ≤ 10^5" implies that we don't need to iterate over all i, but we can find all x directly by starting from the smallest multiple of k greater than y and then adding k each step until exceeding n-y. That would produce at most 10^5 numbers. That's okay: we can start from the first multiple of k that is > y, i.e., m = ((y // k) + 1) * k if y%k!=0 else y+k? Actually we need (x+y) divisible by k, so (x+y) must be a multiple of k and > y? Because x >=1 => x+y >= y+1, so the smallest multiple of k that is at least y+1. Let's define s = ceil((y+1)/k) * k? Actually we want t such that tk >= y+1. So the smallest possible total = t_min * k = ceil((y+1)/k) * k. Then x = total - y. So we can start from total = smallest multiple of k that is > y (since y is integer, total must be > y to have x >=1). Actually if total = y, then x=0 invalid, so we need total > y. So total = ((y // k) + 1) * k if y%k!=0? If y is divisible by k, then y itself is a multiple of k, but x=0 invalid, so we need the next multiple. So total = (y/k + 1) * k = y + k if y divisible by k, else ceil(y/k)*k which might equal something > y. Actually ceil(y/k)*k is the smallest multiple of k not less than y. But if that multiple equals y (i.e., y%k==0), then we need the next one: y+k. So the starting total = ((y/k)+1)*k if y%k==0 else ceil(y/k)*k. More simply, total = (floor((y)/k) + 1) * k. Because floor(y/k) is integer division. Then total = (y//k + 1) * k. That always gives a multiple of k that is > y? Let's check: If y=10, k=6: y//k =1, +1=2, total=12, which is >10. Works. If y=6, k=3: y//k=2, +1=3, total=9>6. But is that the smallest? y+? 6+? Actually smallest multiple >6 is 9 indeed because 6 itself is a multiple but not >6, we need >6. So it's correct. If y=5, k=5: y//k=1, +1=2, total=10>5, correct. So total_start = (y // k + 1) * k.
Then x_start = total_start - y. Then we can generate subsequent x by adding k each time? Because if we increase total by k, then x = (total + k) - y = (total - y) + k. So x values form an arithmetic progression with difference k. And we continue while total <= n, i.e., (total_start + ik) <= n. So x_i = x_start + ik, with i >=0, and total = total_start + i*k <= n. So the condition x + y = total <= n.
Thus we can generate all x by starting from x = ((y // k + 1) * k) - y, and then while x + y <= n: print x, then x += k. But careful: x must be >=1. The starting x ensures that because total_start > y so x >0. Also x must be <= n - y? That's automatic.
Now we need to output in ascending order. The AP is increasing.
Now, the number of x values is floor((n - total_start) / k) + 1, if total_start <= n. If total_start > n, none.
This number could be huge if k is small: e.g., y=1, k=1, n=1e9, total_start = (1//1+1)*1 = 2, so x_start=1, then x values are 1,2,3,..., up to n-y=1e9-1? Actually n-y=1e9-1, but our x sequence: x_start = 1, then x=2,3,...? Wait with k=1, difference=1. So x would be 1,2,3,..., up to n - y? Let's check: total_start = (1//1+1)*1 = 2; total <= n => 2 <= n, so total_max = n (largest multiple of k ≤ n). Actually total_max = floor(n/k)k = n (since k=1). So total runs from 2 to n step 1. Then x = total - y = total - 1. So x runs from 1 to n-1. That's about 1e9 numbers. But the problem statement says " ≤ 105". This suggests that there is a constraint on output size. In the original problem (CF 239A), the constraint is 1 ≤ y, k, n ≤ 10^9, and there is also a note: "It is guaranteed that the number of different possible values of x is not greater than 10^5." That is typical. So they guarantee that the answer set is small. But in this version, the example input "10 1 10" gives no answer, but if y=1, k=1, n=10, the answer would be 1,2,3,4,5,6,7,8,9 (9 numbers). That is ≤10^5. So they must have some guarantee. However, I recall that the problem CF 239A indeed had a guarantee that the number of x is at most 10^5, and many solutions iterate from 1 to something? Actually typical solution: iterate over multiples of k from 1 to n? Let's recall: The classic solution is: find the smallest x such that x+y <= n and (x+y)%k==0. That is x = k - y%k if y%k!=0 else 0? But careful: (x+y)%k==0 => x ≡ -y (mod k). So x ≡ (k - y%k) mod k (if y%k !=0, else x ≡ 0 mod k). So the smallest positive x satisfying that congruence is something like: if y%k != 0: x0 = k - y%k; else x0 = k? Actually if y%k==0, then x ≡ 0 mod k, smallest positive is k. But we also require x+y <= n, so x <= n-y. So the set is all x = x0 + tk for t=0,1,... while x <= n-y, with x0 defined as the smallest positive integer such that x0 ≡ -y (mod k). So that is consistent with total_start = y + x0 must be multiple of k; x0 = ( (k - (y%k)) % k )? Actually if y%k = r, then -y mod k is (k - r) mod k, which gives 0 if r=0 else k-r. So x0 = (k - r) % k. If r=0, then x0=0, but we need positive x, so then the next one is k. So x0 = (k - y%k) % k, but that gives 0 when y%k=0. So we need to adjust: if x0 == 0, then x0 = k. So starting x = (k - y%k) % k; if x==0, x=k. But does this give the same as total_start? total_start = (y//k + 1)*k. Then x_start = total_start - y = (y//k + 1)k - y = k - (y % k) if y%k !=0? Actually compute: y = qk + r, with 0 ≤ r < k. Then total_start = (q+1)*k = qk + k. So x_start = (qk + k) - (qk + r) = k - r. If r>0, x_start = k - r >0. If r=0, then x_start = k - 0 = k. So indeed x_start = k - r when r>0, else k. That matches the formula: x0 = k - r if r>0, else k. So we can compute r = y % k; if r == 0: x_start = k; else x_start = k - r. That's simple.
Thus the sequence: x = x_start, x_start + k, x_start + 2k, ..., as long as x <= n - y. We need x >= 1 automatically satisfied.
Now we need to output them. The number of such x is floor((n - y - x_start)/k) + 1 if x_start <= n - y.
Given constraints up to 1e9 but answer set size ≤ 1e5, we can simply generate in a loop.
Check edge cases: y can be up to n? If y==n, then n-y=0, so x <=0, but x must be >=1, so no solution unless maybe if x_start <=0? Actually x_start is positive, so if n-y = 0, then there is no x >=1 such that x <=0, so none. So we need to check if x_start > n - y, then output -1.
Also note that n may be less than y? The constraints: y, n >=1, but they didn't specify that n ≥ y. Possibly n could be less than y. Then x+y <= n implies x <= n - y < 0, impossible because x >=1. So also no solutions. So we need to handle that: if n <= y? Actually if n < y? Then n - y < 0, so impossible. But if n == y, then n-y=0, same. So if n <= y, no solution except possibly? Actually if n == y, then x+y <= n => x <=0, so only x=0 which invalid, so none. So only possible if n > y.
Thus algorithm:
Read y, k, n.
If n <= y: print -1 and exit? Actually we could still check, but it will be empty because x_start >=1 and >0 > n-y => none. So we can check condition n > y else -1.
Compute r = y % k.
If r == 0: x_start = k
else: x_start = k - r
If x_start > n - y: print -1
else:
Initialize current = x_start.
While current <= n - y:
print current
current += k
But careful: n - y can be large, but number of iterations is bounded by answer set size which is <= 1e5.
Now let's test with examples:
y=10, k=1, n=10.
n <= y? n=10, y=10 => n - y =0. n == y so condition n > y is false. So output -1. Good.
y=10, k=6, n=40.
n>y (40>10). r = 10%6=4, x_start = 6-4=2. n-y=30. So current=2, while <=30: print 2,8,14,20,26,32? 2+5*6=32, but 32<=30? Actually 32>30, so stops at 26. So output: 2 8 14 20 26. matches.
Now consider edge case: y=5, k=5, n=20.
r=0, x_start = k =5. n-y=15. So sequence: 5,10,15. Should we include 20? 20>15 so no. So output 5 10 15. Check: x=5, total=10 divisible by5; x=10 total=15 divisible? 15 divisible by5 yes; x=15 total=20 divisible by5 yes. But wait, x=15 gives total 20 which is <=20. Yes. Good.
Now consider y=5, k=5, n=5: n-y=0, so no solution, even though x_start=5>0, but 5>0? Actually x_start=5 >0? n-y=0, so 5>0 => no solution. So output -1.
Now consider y=1, k=1, n=10. n>y. r=1%1=0, x_start = k =1. n-y=9. Sequence: 1,2,...,9. That's 9 numbers. This is okay if answer set size <= 1e5.
But if y=1, k=1, n=1e9, that would produce 1e9-1 numbers, which would exceed 1e5. But the problem statement says " ≤ 105". Probably it's that the number of outputs does not exceed 10^5. So they guarantee such test cases will not be present. So it's fine.
Thus the solution is straightforward.
Now the input format: "The first line of input contains three integers y, k, n". So read three ints.
Now we need to output the list of numbers separated by spaces, or -1 if none.
Implementation:
Pseudo:
read y, k, n
if n <= y:
print(-1)
return
r = y % k
if r == 0:
start = k
else:
start = k - r
if start > n - y:
print(-1)
return
generate
ans = []
cur = start
while cur <= n - y:
ans.append(cur)
cur += k
print(' '.join(map(str, ans)))
But careful: Starting from start, we need to ensure that cur <= n - y. However, note that total = cur + y = start + y + i*k? Actually start + y = ( (y//k)+1 )*k as earlier. So total <= n automatically ensures cur <= n - y. So okay.
Now let's test with more cases:
Case: y=2, k=3, n=10.
n>y? yes.
r = 2%3=2, start = 3-2=1.
n-y=8.
Sequence: 1,4,7? Let's see: 1 -> total 3 divisible by3; 4->total6;7->total9; next 10? 10 would be 10, but cur=10? 1+33=10? Actually 1+33=10? 1+9=10, but 10 <=8? No. So only 1,4,7. Check if 7+2=9 <=10, yes. So output 1 4 7. Seems fine.
Case: y=9, k=5, n=20.
n>y? yes (20>9).
r=9%5=4, start=5-4=1.
n-y=11.
Sequence: 1,6,11? 11+9=20 <=20; next 16>11, so stop. So output 1 6 11. Check: 11+9=20 divisible by5? 20/5=4, yes.
Case: y=9, k=5, n=14.
n-y=5. start=1 <=5. Sequence: 1,6? 6>5, so only 1. Output 1. Check: 1+9=10 divisible by5, yes, and <=14.
Now, what about the condition that x must be >=1, but start could be 0? In our calculation, r==0 gives start = k, which is >=1 since k>=1. If k=0? But k>=1, so fine. For r!=0, start = k - r, which is between 1 and k-1, positive. So start always >=1.
Thus solution is correct.
Now we should ensure that we don't miss any x due to overflow? Use long long (Python int is fine). The loop is while cur <= n - y, and we increment by k. Since answer size is guaranteed ≤ 1e5, loop is okay.
But caution: In some languages, need to be careful about n - y being negative. Already we check if n <= y, then no solution. So n - y >=0? Actually if n=y, n-y=0, but we have n <= y case? We used n <= y to print -1. But if n == y, we would print -1 because start >0? Actually start>0 > n-y=0, so also no solution. But our early check n <= y would cover that, but might be too broad: If n < y, then n - y negative, definitely no solution. So it's fine.
But what if n > y but start > n - y? Then also print -1. So we can just handle with the later condition; we don't need the early check, but it's okay to have it to avoid negative n-y in case n < y.
But we must be careful: n could be less than y, but then n - y is negative, but start is positive, so start > negative is always true, and our loop would incorrectly iterate because cur <= negative? Actually if n < y, then n - y is negative, and start is positive, so the condition start > n - y? Actually we check if start > n - y? start > negative is true, but we should not generate because there is no x satisfying x+y <= n because y already > n, then x must be <= n - y <0, impossible. So we need to output -1. So we must catch that case. Our early check n <= y covers that. So it's fine.
Thus implement accordingly.
Now for output, we can collect results in a list and join. Or print one by one using sys.stdout.write.
Time complexity: O(number of solutions) ≤ 1e5.
Now ensure that we print each value exactly once, and they are in ascending order (which they are since we start from smallest and add k).
Now confirm constraints: Input numbers up to 1e9, Python int is fine.
Thus the solution is ready.
But wait, the problem statement: "the first line of input contains three integers y, k, n (1 ≤ y, k, n ≤ 109; ≤ 105)." This "" is maybe a placeholder for "the number of possible x". Actually typical CF problem: "It is guaranteed that all possible values of x are distinct and do not exceed 10^5." Or "the number of different possible values of x is not greater than 10^5." So we assume that's the case.
Now we can produce final answer.
However, note there might be nuance: The condition x ≥ 1, but also the bag that contains x potatoes was lost, so x is positive integer. Also y is positive. So we are good.
Now test with some random:
y=100, k=7, n=200.
r=100%7=2? Actually 714=98, remainder 2. start=7-2=5. n-y=100. Sequence: 5,12,19,26,33,40,47,54,61,68,75,82,89,96,103? 5+147=103? Actually 5+14*7=103? 5+98=103, but 103 >100, so stop at 96. So many numbers.
Now check if x=5: total=105 divisible by7? 105/7=15, yes. x=96: total=196 divisible by7? 196/7=28, yes, and ≤200. Good.
All fine.
Now, think about if start could be 0? I said no, but let's double-check: If y%k == 0, start = k, not 0. Could there be a scenario where k = 0? No, k>=1. So fine.
But some solutions on CF set start = k - y % k; if that equals 0, then set start = k. That's it.
Now, I recall some solutions just loop from i = 1 to n/k and check condition: if (i*k - y) >= 1, print. But they rely on number of i being not too large? Actually n/k could be up to 1e9, but they guarantee that answer set is ≤ 1e5, so the loop over all i would be too slow. However, the simple while loop generating x directly is efficient.
Now implement in Python:
def solve():
import sys
data = sys.stdin.read().strip().split()
if not data:
return
y, k, n = map(int, data)
if n <= y:
print(-1)
return
r = y % k
if r == 0:
start = k
else:
start = k - r
if start > n - y:
print(-1)
return
res = []
cur = start
limit = n - y
while cur <= limit:
res.append(str(cur))
cur += k
print(' '.join(res))
That's it.
Now let's test with some edge cases:
Case: y=9, k=10, n=10. n <= y? 10 <= 9? false, n > y? 10 > 9 true. r = 9%10=9, start = 10-9=1. limit = n-y=1. So cur=1 <=1 -> output 1. But is this valid? x=1, total=10, divisible by10? yes, total<=n? 10 <=10 yes. So output 1. Good.
Case: y=10, k=10, n=20. r=0, start=10. limit=10. cur=10 <=10 -> output 10. Next 20 >10, stop. So output 10. Check: x=10, total=20 divisible by10, yes. Also x could be 20? 20+10=30>20, so no. So correct.
Now, I'm thinking about if there is any scenario where start could be 0 and we incorrectly produce 0? For r=0, we set start=k, so fine. For r !=0, start = k - r, where 1 <= r <= k-1 => 1 <= start <= k-1, so fine.
Thus solution is robust.
Now, the problem statement might require that we print each possible x exactly once, and they are naturally distinct because we start from smallest and add k, so no duplicates.
Now the answer.
Now about the constraints: I'd like to double-check the guarantee: In the original CF problem, it says: "It is guaranteed that the number of different possible values of x is not greater than 10^5." But the problem statement on some online judges may omit this note. The given problem statement here says " ≤ 105". Possibly that's a placeholder for "the number of different possible x" in the constraints. So I'm comfortable.
Thus final answer: implement as described.
Now I'll provide explanation.
But as ChatGPT, I need to output final solution code? The user asked: "Help Valera to determine how many potatoes could be in the first bag. Print all such possible numbers in ascending order." The user provided examples. So they likely expect a solution.
The question: The user posted a problem statement and examples, and likely expects solution algorithm, maybe code? The context: This is a standard problem from Codeforces. The user might be asking for explanation. However the format: The user wrote "Valera had two bags..." and then examples. Usually these posts are asking for solution. So I will provide an explanation and then Python code.
Since it's a typical programming contest problem, I will answer with the solution approach and code.
But the instruction: "You are ChatGPT, a large language model trained by OpenAI..." So I need to respond as ChatGPT. Usually for these types of questions, we give a solution description and code. I'll do that.
Thus final answer: Provide explanation and code.
Now write final response. We need to find all positive integers (x) such that:
(x + y \le n),
((x + y)) is divisible by (k).
Let (r = y \bmod k).
If (r = 0), the smallest total (> y) that is a multiple of (k) is (y + k), so the smallest (x = k).
If (r > 0), the smallest total (> y) that is a multiple of (k) is (y + (k - r)), so the smallest (x = k - r).
In both cases (x_{\text{start}} \ge 1). Then all valid (x) form an arithmetic progression:
Complexity: The number of answers is at most (10^5) (guaranteed), so a simple loop works.
python
import sys
def solve() -> None:
data = sys.stdin.read().strip().split()
if not data:
return
y, k, n = map(int, data)
if n <= y:
print(-1)
return
r = y % k
if r == 0:
start = k
else:
start = k - r
if start > n - y:
print(-1)
return
res = []
cur = start
limit = n - y
while cur <= limit:
res.append(str(cur))
cur += k
print(' '.join(res))
if __name__ == "__main__":
solve()