#include <bits/stdc++.h>
using namespace std;
#define MIN_N 1
#define MAX_N 10000
#define MIN_M 1
#define MAX_M 20000
#define MIN_F 1
#define MAX_F 10000
#define MIN_W 1
#define MAX_W 1000
#define MIN_C 1
#define MAX_C 2000
#define MIN_S 1
#define MAX_S 10000
string SAMPLE[] =
{
"4 7 4 8",
"18",
"9",
"5",
"4",
"1 2 500",
"2 4 250",
"1 4 1000",
"3 1 750",
"4 3 100",
"3 2 200",
"2 2 400"
};
int rand_between(int low, int high)
{
assert(low <= high);
return low + rand() % (high - low + 1);
}
void generate(int seed)
{
if(seed == 0)
{
for(auto line : SAMPLE) cout << line << endl;
return;
}
srand(seed);
int N = rand_between(MIN_N, MAX_N);
int M = rand_between(N, min(N*N, MAX_M));
int C = rand_between(MIN_C, MAX_C);
int S = rand_between(MIN_S, MAX_S);
vector<int> F(N), A(M), B(M), W(M);
set< pair<int, int> > edges;
for (int i = 0; i < N; ++i) F[i] = rand_between(MIN_F, MAX_F);
for (int i = 0; i < M; ++i)
{
do
{
A[i] = rand_between(1, N);
B[i] = rand_between(1, N);
}
while (edges.count(make_pair(A[i], B[i])) != 0);
edges.insert(make_pair(A[i], B[i]));
W[i] = rand_between(MIN_W, MAX_W);
}
cout << N << ' ' << M << ' ' << C << ' ' << S << endl;
for (int i = 0; i < N; ++i) cout << F[i] << endl;
for (int i = 0; i < M; ++i) cout << A[i] << ' ' << B[i] << ' ' << W[i] << endl;
}
int main(int argc, char *argv[])
{
int seed = 0;
if (argc > 1) istringstream(argv[1]) >> seed;
generate(seed);
return 0;
};