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. C++ Solution
```cpp
#include <bits/stdc++.h>

using namespace std;

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

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

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

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

int n, k;

void read() { cin >> n >> k; }

void solve() {
    /*
     * A funny (Euclid) string of length n with sum k is the discretized line
     * y = (k/n) x: every term is either floor(k/n) or that plus one. Start with
     * all terms equal to a = k/n; d = k % n of them must be bumped by one. Find
     * the step t (1 <= t < n) with t*d == -1 (mod n), then walk positions
     * x = t, 2t, ... mod n incrementing each until reaching index n-1; those d
     * positions form the staircase pattern that makes the string funny.
     */

    int a = k / n;
    int d = k % n;

    vector<int> ans(n, a);

    for(int t = 1; t < n; t++) {
        if(t * d % n == n - 1) {
            int x = 0;
            do {
                x = (x + t) % n;
                ans[x]++;
            } while(x != n - 1);
            break;
        }
    }

    cout << ans << '\n';
}

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

    int T = 1;
    // cin >> T;
    for(int test = 1; test <= T; test++) {
        read();
        // cout << "Case #" << test << ": ";
        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.