#include <iostream>
#include <vector>
#include <cstdint>
#include <algorithm>
typedef std::vector<std::uint64_t> DType;
typedef std::vector<DType> RType;
DType MakeSeq(std::size_t S, std::uint64_t N){
DType D;
for (std::uint64_t i = 0; i < N; i++){
for (std::size_t j = 0; j < S; j++){
D.push_back(i+1);
}
}
return D;
}
bool Check(DType& D){
std::size_t j = 0;
for (std::size_t i = 0; i < D.size()-1; i++){
for (j = 0; j < D[i]; j++){
if (D[i + j+1] == D[i])return false;
}
if (i + D[i] + 1 == D.size()) continue;
if (D[i+D[i]+1] != D[i])return false;
}
return true;
}
RType MakeHoge(std::size_t S, std::uint64_t N){
DType D = MakeSeq(S, N);
RType R;
do{
if (Check(D) == true) R.push_back(D);
} while (std::next_permutation(D.begin(), D.end()));
return R;
}
bool Show(RType& R){
for (auto& oo : R){
for (auto& o : oo){
std::cout << o << ",";
}
std::cout << std::endl;
}
std::cout <<"Dump Done!"<< std::endl;
return true;
}
int main(){
std::size_t S = 0;//S枚
std::size_t N = 0;//apper Lim N
RType R;
S = 2;
N = 3;
R = MakeHoge(S, N);
Show(R);
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZSA8Y3N0ZGludD4KI2luY2x1ZGUgPGFsZ29yaXRobT4KdHlwZWRlZiBzdGQ6OnZlY3RvcjxzdGQ6OnVpbnQ2NF90PiBEVHlwZTsKdHlwZWRlZiBzdGQ6OnZlY3RvcjxEVHlwZT4gUlR5cGU7CgpEVHlwZSBNYWtlU2VxKHN0ZDo6c2l6ZV90IFMsIHN0ZDo6dWludDY0X3QgTil7CglEVHlwZSBEOwoKCWZvciAoc3RkOjp1aW50NjRfdCBpID0gMDsgaSA8IE47IGkrKyl7CgkJZm9yIChzdGQ6OnNpemVfdCBqID0gMDsgaiA8IFM7IGorKyl7CgkJCUQucHVzaF9iYWNrKGkrMSk7CgkJfQoJfQoKCXJldHVybiBEOwp9Cgpib29sIENoZWNrKERUeXBlJiBE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