1. Abridged Problem Statement  
Given integers N (2≤N≤1000) and K (1≤K≤30000) with gcd(N,K)=1, construct a non-negative integer array S of length N summing to K, such that if you form S′ by doing “S′₁ = S₁+1, S′ₙ = Sₙ–1, and S′ᵢ = Sᵢ for 2≤i≤n–1”, then S′ is a cyclic rotation of S. Output any such S.

2. Detailed Editorial  

Definition and Rewriting the Condition  
We seek S = [S₀,S₁,…,S_{n−1}] (0-indexed for convenience) with ∑Sᵢ = k and all Sᵢ ≥0, so that the transformed array  
  S′₀ = S₀+1,  
  S′_{n−1} = S_{n−1}–1,  
  S′ᵢ = Sᵢ for 1 ≤ i ≤ n−2  
is exactly S rotated by some shift t (0 < t < n). Equivalently, there exists t such that for every i:  
  S′ᵢ = S_{(i+t) mod n}.  

Key Observations  
1. Let a = ⌊K/N⌋ and d = K mod N.  Then if we start with all entries equal to a, the sum is N·a ≤ K, and we still need to distribute d extra “+1” units among the N positions.  
2. Because gcd(N,K)=1, also gcd(N,d)=1.  Hence d is invertible modulo N: there is a unique integer t in [1..N−1] satisfying  
   d · t ≡ −1  (mod N)  
   ⟺ d·t ≡ N−1 (mod N).  

Why this t works  
- Adding 1 to S₀ and subtracting 1 from S_{n−1} shifts total sum by 0, as required.  
- If we then rotate S by t positions, the location that originally got the +1 ends up at index (n−1) after rotation, and the –1 ends up at index preceding 0, exactly matching the transform of the rotated array.  
- Distributing the d extra “+1” units along the cycle generated by stepping by size t ensures that after rotation the pattern aligns perfectly.

Construction Algorithm  
1. Compute a = K/N, d = K%N.  
2. Initialize ans[i]=a for i=0..n−1.  
3. Find t∈[1..n−1] such that (d·t)%n==n−1.  
4. Starting from x=0, repeat:  
     x = (x + t) mod n  
     ans[x]++  
   until x reaches n−1.  You will have distributed exactly d increments.  
5. Output ans.

Time Complexity  
O(n²) in the worst-case search for t, but n≤1000 so this is more than fast enough.

3. Provided C++ Solution with Line-by-Line Comments  
#include <bits/stdc++.h>  
using namespace std;

// Overload << for outputting pairs  
template<typename T1, typename T2>
ostream& operator<<(ostream& out, const pair<T1, T2>& x) {
    return out << x.first << ' ' << x.second;
}

// Overload >> for reading pairs  
template<typename T1, typename T2>
istream& operator>>(istream& in, pair<T1, T2>& x) {
    return in >> x.first >> x.second;
}

// Overload >> for reading vectors  
template<typename T>
istream& operator>>(istream& in, vector<T>& a) {
    for(auto& x: a) {
        in >> x;
    }
    return in;
}

// Overload << for outputting vectors  
template<typename T>
ostream& operator<<(ostream& out, const vector<T>& a) {
    for(auto x: a) {
        out << x << ' ';
    }
    return out;
}

int n, k;

// Read n and k from stdin  
void read() {
    cin >> n >> k;
}

void solve() {
    // Compute base value and remainder
    int a = k / n;      // integer division
    int d = k % n;      // how many +1 we still need to distribute

    // Start with all entries = a
    vector<int> ans(n, a);

    // Find the rotation shift t satisfying d*t ≡ n-1 (mod n)
    for(int t = 1; t < n; t++) {
        if ((long long)t * d % n == n - 1) {
            // Distribute the d extra +1's along the cycle generated by step size t
            int x = 0;
            do {
                // Move x forward by t modulo n
                x = (x + t) % n;
                // Place one increment here
                ans[x]++;
                // Stop once we have reached the last index (n-1)
            } while(x != n - 1);
            break;
        }
    }

    // Output the final funny string
    cout << ans << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int T = 1;
    // If there were multiple test cases, we'd read T
    // cin >> T;
    for(int test = 1; test <= T; test++) {
        read();
        solve();
    }
    return 0;
}

4. Python Solution with Detailed Comments  
```python
import sys

def main():
    data = sys.stdin.read().split()
    n, k = map(int, data)
    # Base value for each position
    a = k // n
    # Remainder to distribute
    d = k % n

    # Initialize all positions with a
    ans = [a] * n

    # Find t such that d * t ≡ n-1 (mod n)
    # Since gcd(n,d)=1, such t exists uniquely
    for t in range(1, n):
        if (d * t) % n == (n - 1):
            # Distribute the d extra ones around the cycle
            x = 0
            # We must do exactly d increments; the cycle length is d+1 steps to land on n-1
            while True:
                x = (x + t) % n
                ans[x] += 1
                if x == n - 1:
                    break
            break

    # Print the result
    print(" ".join(map(str, ans)))

if __name__ == "__main__":
    main()
```

5. Compressed Editorial  
Set each entry to ⌊K/N⌋, then distribute the leftover d = K mod N ones along a cyclic step of size t, where t solves d·t ≡ −1 mod N. This ensures that adding 1 to the first element and subtracting 1 from the last element corresponds exactly to rotating the array by t positions.