#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using Int = long long; template ostream &operator<<(ostream &os, const pair &a) { return os << "(" << a.first << ", " << a.second << ")"; }; template ostream &operator<<(ostream &os, const vector &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; } template void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; } template bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; } template bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; } #define COLOR(s) ("\x1b[" s "m") // floor(a / b) Int divFloor(Int a, Int b) { return a / b - (((a ^ b) < 0 && a % b != 0) ? 1 : 0); } // ceil(a / b) Int divCeil(Int a, Int b) { return a / b + (((a ^ b) > 0 && a % b != 0) ? 1 : 0); } int N; Int K; vector R; vector X; int main() { for (; ~scanf("%d%lld", &N, &K); ) { R.resize(N); X.resize(N); for (int i = 0; i < N; ++i) { scanf("%d%lld", &R[i], &X[i]); } for (int i0 = 0; i0 < N; ++i0) { // a + b t vector as(N), bs(N); vector asSum(N + 1, 0), bsSum(N + 1, 0); for (int i = N; --i >= 0; ) { if (i0 != i) { as[i] = X[i] - (asSum[i + 1] - asSum[R[i]]); bs[i] = 0 - (bsSum[i + 1] - bsSum[R[i]]); } else { as[i] = 0; bs[i] = 1; } asSum[i] = as[i] + asSum[i + 1]; bsSum[i] = bs[i] + bsSum[i + 1]; } // cerr<<"as = "<