Go: package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
	"strings"
)

func main() {
	io := NewIo()
	defer io.Flush()
	for {
		t, d, l := io.NextInt(), io.NextInt(), io.NextInt()
		if t == 0 {
			break
		}
		cnt := 0
		elapsed := math.MaxInt32
		for i := 0; i < t-1; i++ {
			x := io.NextInt()
			if x >= l {
				cnt++
				elapsed = 1
			} else if elapsed < d {
				cnt++
				elapsed++
			}
		}
		_ = io.NextInt()
		io.Println(cnt)
	}
}

// I/O template
type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func NewIo() *Io {
	return &Io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

func (io *Io) NextLine() string {
	var buff []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buff = append(buff, line...)
		if !isPrefix {
			break
		}
	}
	return string(buff)
}

func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	s := io.tokens[io.nextToken]
	io.nextToken++
	return s
}

func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) NextFloat() float64 {
	i, err := strconv.ParseFloat(io.Next(), 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

func (io *Io) Printf(format string, a ...interface{}) {
	fmt.Fprintf(io.writer, format, a...)
}

func (io *Io) PrintIntSlice(a []int) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func (io *Io) PrintStringSlice(a []string) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func Log(name string, value interface{}) {
	fmt.Fprintf(os.Stderr, "%s=%+v\n", name, value)
}

func ExampleIo() {
	io := NewIo()
	defer io.Flush()
	a := make([]int, 0, 3)
	a[0], a[1], a[2] = io.NextInt(), io.NextInt(), io.NextInt()
	io.Println(a)
	io.PrintIntSlice(a)
	Log("io", a)
}

C++: #include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)

int main(){
    int t,d,l;
    while(cin >> t >> d >> l && t!=0){
        int s = 0;
        int res = 0;
        rep(i,t){
            if(s > 0)res++;
            int x;
            cin >> x;
            if(x >= l){
                s = d+1;
            }
            s--;
        }
        cout << res << endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;

int main() {
    int T, D, L;
    while (cin >> T >> D >> L, T | D | L) {
        int x, cnt = 0, sum = 0;
        for (int i = 0; i < T; i++) {
            cin >> x;
            if (x >= L) {
                cnt = D;
            } else {
                cnt--;
                cnt = max(cnt, 0);
            }
            if (cnt > 0) sum++;
        }
        if (cnt > 0) sum--;
        cout << sum << endl;
    }
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  int T,D,L;
  while(1){
    cin>>T>>D>>L;
    if(T==0)break;
    int ans=0,a,last=-1e9;
    for(int i=0;i<T;i++){
      if( i-last <=D ){
        ans++;
      }
      cin>>a;
      if(a>=L)last=i;
    }
    cout<<ans<<endl;
  }
}

C++: #include <bits/stdc++.h>
using namespace std;

int main()
{
    int T, D, L;
    while (cin >> T >> D >> L)
    {
        if (T == 0 && D == 0 && L == 0)
            return 0;
        vector<int> x(T);
        for (int i = 0; i < T; i++)
            cin >> x[i];
        vector<int> imos(222222);
        for (int i = 0; i < T; i++)
        {
            if (L <= x[i])
            {
                imos[i]++;
                imos[i + D]--;
            }
        }
        for (int i = 0; i < T + D + 1; i++)
        {
            imos[i + 1] += imos[i];
        }
        int ans = 0;
        for (int i = 0; i < T - 1; i++)
        {
            if (imos[i])
                ans++;
        }

        cout << ans << endl;
    }
}

C++: #include <bits/stdc++.h>
#define loop for(;;)
#define rep(i, n) for(long i = 0; i < (long)(n); ++i)
typedef std::vector<long> LI;

struct Solver {
   void solve() {
      long t, d, l; std::cin >> t >> d >> l;
      if( t == 0 or d == 0 or l == 0 ) exit(0);
      long rem = 0;
      LI xs(t); rep(i, t) std::cin >> xs[i];
      long res = 0;
      LI ys(t+d, 0);
      for(long i = 0; i < t; ++i) {
         if( l <= xs[i] ) {
            ys[i]   += 1;
            ys[i+d-1] -= 1;
         }
      }
      long s = 0;
      for(long i = 0; i < t + d - 1; ++i) {
         s += ys[i];
         if( s != 0 ) res += 1;
      }
      printf("%ld\n", res);
   }
};

int main() { loop std::shared_ptr<Solver>(new Solver())->solve(); }

C++: #include <bits/stdc++.h>
#define int long long
#define double long double
#define INF 1e18
using namespace std;
signed main() {
  int T, D, L;
  while(cin>>T>>D>>L,T+D+L!=0) {
    int ans = 0, elapse = 0;;
    for (int i = 0; i < T; i++) {
      int x; cin >> x;
      if (x >= L) {
        elapse = 1;
        if (i!=T-1) ans++;
      } else {
        if (elapse == D) {
          elapse = 0;
        } else if(elapse != 0) {
          elapse++;
          if (i!=T-1) ans++;
        }
      }
    }  
    cout << ans << endl;
  }
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<stack>
#include<queue>
#include<string>
#include<set>
#include<map>
#include<cmath>
#include<cstring>
using namespace std;
#define rep(i,n) for(int i=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int i=(m);(i)<(n);(i)++)
#define All(v) (v).begin(),(v).end()
#define MP make_pair
#define pb push_back
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int INF = 1<<30;
const ll LINF = 1LL<<61;
const int MOD = 1e9+7;

int main(){
    int T,D,L;
    while(cin >> T >> D >> L,T|D|L){
        int wet = 0;
        int res = 0;
        vector<int> wave(T);
        for (int i = 0;i<T;i++){
            cin >> wave[i];
        }
        for (int t = 0; t < T-1; t++)
        {
            if (wave[t] >= L)
            {
                wet = D;
            }
            if (wet > 0)
                res++;
            wet--;
        }
        cout << res << endl;
    }
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG true
// sort(a.begin(), a.end(), std::greater<int>());

/*
std::vector<std::string> split(const std::string &input, char delimiter)
{
    std::istringstream stream(input);

    std::string field;
    std::vector<std::string> result;
    while (std::getline(stream, field, delimiter))
    {
        result.push_back(field);
    }
    return result;
}
*/

int main()
{
    int n, m;
    while (cin >> n >> m)
    {
        if (n == 0 && m == 0)
            break;
        vector<int> mx(n + 1);
        vector<int> mn(n + 1);
        int a, b;
        rep(j, m)
        {
            cin >> a >> b;

            rep(i, b)
            {
                int temp;
                cin >> temp;
                if (b == 1)
                    mn[temp] += a;
                mx[temp] += a;
            }
        }
        int hoge = 0;
        int hogeposi = 0;
        int piyo = 0;
        int piyoposi = 0;
        REP(i,1, mx.size())
        {
            if (hoge < mx[i])
            {
                hoge = mx[i];
                hogeposi = i;
            }
        }
        REP(i,1, mn.size())
        {
            if (piyo < mn[i] && i != hogeposi)
            {
                piyo = mn[i];
                piyoposi = i;
            }
        }
        cout << hoge-piyo + 1 << endl;
    }
    return 0;
}