For the Peace

Time limit8sMemory limit512 MB

Summary
Decide whether n countries can each discard their missiles oldest-first so the gap between the largest and smallest remaining war potential never exceeds d.
Level

Medium5 of 10

Topics
Greedy, Implementation
Solved
No attempts yet

Problem

This is a story about a world far from Earth. The land of that world is divided into countries ruled by empires, and those countries have spent a long time in an arms race.

The race is about missile production. Even so, no country has started a war for years. They cannot fight: they hold far more missiles than it takes to destroy the entire world, so once a war began among them, none of them would remain.

The missiles gave people nothing but fear. The race put heavy financial and psychological pressure on every country. The people are tired, the military is tired, and even the empires are tired. Nobody wants to keep producing missiles.

So the empires and the diplomats of every country met many times about renouncing their missiles and stopping further production. The countries had different interests and the talks were hard, but in the end they agreed on a treaty with these points:

  • Each country disposes of every missile it owns by a certain date.
  • The war potential of any two countries never differs by more than dd.

Here are the details of the second point. Each missile has a capability, which is how much it can destroy its target. The war potential of a country is the sum of the capabilities of the missiles it still owns. The treaty requires the difference between the maximum and the minimum war potential over all countries to stay at most dd at every moment.

Missiles are disposed of one at a time, and the treaty condition is checked after each disposal. Each country disposes of its missiles only in the order they were produced, from the oldest to the newest. Some missiles have a huge capability, and disposing of one of them can throw the potentials out of balance.

Write a program that decides whether every country can dispose of all of its missiles without ever breaking the treaty.

Input

The input is a sequence of datasets. Each dataset has this format:

n d
m1 c1,1 ... c1,m1
...
mn cn,1 ... cn,mn

The first line holds two positive integers, the number of countries nn and the tolerated difference of potential dd, with n≤100n \le 100 and d≤1000d \le 1000. Then nn lines follow. The ii-th line begins with a non-negative integer mim_i, the number of missiles the ii-th country owns, followed by mim_i positive integers. The jj-th of them, ci,jc_{i,j}, is the capability of the jj-th newest missile of the ii-th country, with ci,j≤1000c_{i,j} \le 1000. The integers on a line are separated by a single space. Each country disposes of its missiles in the reverse of the given order.

One dataset holds at most 10000 missiles in total. You may also assume that in the initial state of every dataset the difference between the maximum and the minimum potential is at most dd.

The input ends with a line holding two zeros. Do not process that line.

Output

Print a single line for each dataset. Print Yes if every country can dispose of all of its missiles under the treaty, and No otherwise.

Judging is case sensitive. No extra space or character is allowed.

Examples3

  1. Example 1

    Input
    3 3
    3 4 1 1
    2 1 5
    2 3 3
    3 3
    3 2 3 1
    2 1 5
    2 3 3
    0 0
    
    Expected output
    Yes
    No
    
  2. Example 2

    Input
    1 1
    5 1000 1000 1000 1000 1000
    0 0
    
    Expected output
    Yes
    
  3. Example 3

    Input
    2 1
    3 1 1 1
    1 3
    0 0
    
    Expected output
    No