This page is still under construction.

Parts of this page are still being built. What you see may change.

King

Time limit1sMemory limit128 MB

Summary
Given weighted inequalities on subarray sums, decide whether some integer sequence satisfies all the bounds; output which phrase tells the answer.
Level

Medium6 of 10

Topics
Graph, Shortest path, Prefix sum, Implementation
Solved
No attempts yet

Problem

A queen once gave birth to a son who would become king. Sadly, the prince could do very little arithmetic: he could only add integers and compare a sum against a single given integer bound. Moreover, the numbers he worked with had to be arranged in one sequence, and he could only add up contiguous parts of that sequence.

So that his son could rule after him, the old king decreed that every matter of state be presented as a finite sequence of integers, and every decision be made as an integer bound (an upper or lower limit) on the sum of that sequence.

After the old king died, the young king began to reign, and his decisions soon made him enemies. His opponents brought him a set of problems phrased as subsequences of a single integer sequence S={a1,a2,…,an}S = \{a_1, a_2, \dots, a_n\}. For each subsequence Si={asi,asi+1,…,asi+ni}S_i = \{a_{s_i}, a_{s_i+1}, \dots, a_{s_i+n_i}\} the king declared an integer bound kik_i on its sum, in one of the two forms

asi+asi+1+⋯+asi+ni<kiorasi+asi+1+⋯+asi+ni>ki.a_{s_i} + a_{s_i+1} + \dots + a_{s_i+n_i} < k_i \qquad \text{or} \qquad a_{s_i} + a_{s_i+1} + \dots + a_{s_i+n_i} > k_i.

Later the king realized that some of his declared bounds were mutually inconsistent. He cannot take back a declaration, but he can forge the underlying sequence. Help his advisors: decide whether there exists an integer sequence SS that satisfies all of the declared bounds.

Input

The input consists of several blocks. Every block except the last describes one set of decisions.

The first line of a block contains two integers nn and mm, where 0<n≤1000 < n \le 100 is the length of the sequence SS and 0<m≤1000 < m \le 100 is the number of bounds.

Each of the next mm lines contains one bound as four values si ni oi kis_i\ n_i\ o_i\ k_i:

  • sis_i and nin_i select the subsequence asi,asi+1,…,asi+nia_{s_i}, a_{s_i+1}, \dots, a_{s_i+n_i};
  • oio_i is the comparison operator, given as gt for >> or lt for <<;
  • kik_i is the integer bound applied to the sum of that subsequence.

The last block is a single line containing 0 and must not be processed.

Output

For each block, print one line:

  • successful conspiracy if no integer sequence SS can satisfy all of the block's bounds;
  • lamentable kingdom otherwise.

Print nothing for the final 0 block.

Examples3

  1. Example 1

    Input
    4 2
    1 2 gt 0
    2 2 lt 2
    1 2
    1 0 gt 0
    1 0 lt 0
    0
    
    Expected output
    lamentable kingdom
    successful conspiracy
    
  2. Example 2

    Input
    1 1
    1 0 gt 5
    0
    
    Expected output
    lamentable kingdom
    
  3. Example 3

    Input
    1 2
    1 0 gt 0
    1 0 lt 1
    0
    
    Expected output
    successful conspiracy