#include "testlib.h" using namespace std; int main(int argc, char **argv) { registerValidation(argc, argv); while (!inf.seekEof()) { int n = inf.readInt(2, 8000, "n"); inf.readSpace(); int w = inf.readInt(1, 30, "w"); inf.readSpace(); int d = inf.readInt(1, w, "d"); inf.readSpace(); int tot = inf.readInt(1, INT_MAX, "tot"); inf.readEoln(); int x = w * (n * (n - 1) / 2) - tot; int ans = x / d; ensuref(0 <= x && x % d == 0, "impossible case"); ensuref(0 <= ans && ans < n, "the light coins can't be in the n-th basket unless 'tot == w * (n * (n - 1) / 2) (i.e. ans == 0)'"); } inf.readEof(); }