Under construction

Still being built. Things may change

Integral

Time limit2sMemory limit512 MB

Summary
Given f at a set of integer points, extend it to a monotone piecewise linear function so the integral from 0 to n equals y.
Level

Hard8 of 10

Topics
Intervals
Solved
No attempts yet

Problem

For a positive integer nn, let [n][n] be the real interval {x:0≤x≤n}\{x : 0 \le x \le n\}. A function f:[n]→Rf : [n] \to \mathbb{R} is only partly specified: the values of ff are given at the points of a subset SS of [n][n].

The set SS has these properties:

  1. Every point of SS is an integer.
  2. Both endpoints 00 and nn of [n][n] belong to SS.

The function ff has these properties:

  1. At every integer point of [n][n], the value of ff is an integer.
  2. Between two consecutive points of SS, ff is monotone. If LL and RR are consecutive points of SS with L<RL < R, then f(L)≤f(L+1)≤⋯≤f(R)f(L) \le f(L+1) \le \cdots \le f(R) or f(L)≥f(L+1)≥⋯≥f(R)f(L) \ge f(L+1) \ge \cdots \ge f(R).
  3. At a point xx of [n][n] that is not an integer, f(x)f(x) is the linear interpolation of f(⌊x⌋)f(\lfloor x \rfloor) and f(⌈x⌉)f(\lceil x \rceil), that is, f(x)=(⌈x⌉−x)f(⌊x⌋)+(x−⌊x⌋)f(⌈x⌉)f(x) = (\lceil x \rceil - x) f(\lfloor x \rfloor) + (x - \lfloor x \rfloor) f(\lceil x \rceil).

The values of ff at the integer points of [n]∖S[n] \setminus S are still yours to choose. (SS can already contain every integer point of [n][n].) For a given yy, decide whether those values can be chosen so that ∫0nf(x) dx=y\int_0^n f(x)\,dx = y, that is, so that the area under ff between 00 and nn equals yy.

Input

The input holds several test cases and ends at the end of the file.

The first line of a test case has three integers NN, MM and YY: the length of the interval, the size of SS, and the value of yy. Each of the next MM lines describes ff at one point of SS with two integers XX and FF, meaning f(X)=Ff(X) = F. The values of XX are not necessarily in increasing order.

Constraints

  • 1≤N≤1061 \le N \le 10^6
  • the sum of NN over all test cases is at most 10610^6
  • 0≤X≤N0 \le X \le N, and the MM values of XX are distinct integers that include 00 and NN
  • 0≤F≤1060 \le F \le 10^6, FF integer
  • 0≤Y≤1090 \le Y \le 10^9, YY integer
  • ∫0nf(x) dx≤109\int_0^n f(x)\,dx \le 10^9 for every assignment of values to ff at the integer points of [n]∖S[n] \setminus S that obeys the rules above

Output

For each test case, decide whether values can be assigned to ff at the integer points x∈[n]∖Sx \in [n] \setminus S so that ∫0nf(x) dx=y\int_0^n f(x)\,dx = y, that is, so that the area under ff between 00 and nn equals yy.

If they cannot, print a line containing only the character N. If they can, print a line containing the character S followed by the values of f(x)f(x) at the integer points x∈[n]∖Sx \in [n] \setminus S, in increasing order of xx. Separate the leading character and each value by one blank space. When more than one assignment works, print the one whose sequence of values is the smallest in lexicographic order.

Examples3

  1. Example 1

    Input
    5 6 10
    0 2
    1 2
    5 2
    2 2
    3 2
    4 2
    5 2 10
    0 0
    5 10
    2 2 5
    0 1
    2 2
    10 3 18
    0 2
    6 4
    10 0
    2 2 1
    0 0
    2 1
    
    Expected output
    S
    S 0 0 0 5
    N
    S 2 2 2 2 2 1 1 1
    N
    
  2. Example 2

    Input
    4 2 10
    0 4
    4 0
    4 2 6
    0 4
    4 0
    4 2 0
    0 0
    4 0
    4 2 12
    0 4
    4 0
    
    Expected output
    S 3 3 2
    S 2 1 1
    S 0 0 0
    S 4 3 3
    
  3. Example 3

    Input
    5 2 25
    0 2
    5 8
    7 4 7
    7 1
    0 1
    3 0
    5 2
    
    Expected output
    S 2 2 8 8
    S 0 0 2 2