CodeforcesAug 18, 2025

Walking Between Houses

Hazrat Ali

Codeforces

You have to perform k moves to other house. In one move you go from your current house to some other house. You can't stay where you are (i.e., in each move the new house differs from the current house). If you go from the house x to the house y, the total distance you walked increases by |xy| units of distance, where |a| is the absolute value of a. It is possible to visit the same house multiple times (but you can't visit the same house in sequence).

Your goal is to walk exactly s units of distance in total.

If it is impossible, print "NO". Otherwise print "YES" and any of the ways to do that. Remember that you should do exactly k moves.

Input

The first line of the input contains three integers nks (2n1091k21051s1018) — the number of houses, the number of moves and the total distance you want to walk.

Output

If you cannot perform k moves with total walking distance equal to s, print "NO".

Otherwise print "YES" on the first line and then print exactly k integers hi (1hin) on the second line, where hi is the house you visit on the i-th move.

For each j from 1 to k1 the following condition should be satisfied: hjhj+1. Also h11 should be satisfied.

Examples
Input
10 2 15
Output
YES
10 4
Input
10 9 45
Output
YES
10 1 10 1 2 1 2 1 6
Input
10 9 81
Output
YES
10 1 10 1 10 1 10 1 10
Input
10 9 82
Output
NO

Solution

#include <bits/stdc++.h>
using namespace std;

int main() {
  long long n, k, s;
  cin >> n >> k >> s;
  if (k * (n - 1) < s) {
    cout << "NO" << "\n";
    return 0;
  }
  if (s < k) {
    cout << "NO" << "\n";
    return 0;
  }
  cout << "YES" << "\n";
  long long q = s / k;
  long long r = s % k;
  long long cur = 1;
  for (int i = 0; i < k; i++) {
    int step = q;
    if (r > 0) {
      step++;
      r--;
    }
    if (i % 2 == 0) {
      cur += step;
    } else {
      cur -= step;
    }
    cout << cur << " ";
  }
  cout << "\n";
  return 0;
}





Comments