Go: package main

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

func main() {
	io := NewIo()
	defer io.Flush()
	for {
		n := io.NextInt()
		if n == 0 {
			break
		}
		s := make([]string, n)
		for i := 0; i < n; i++ {
			s[i] = io.NextLine()
		}
		w := [5]int{5, 7, 5, 7, 7}
		ans := 0
	OUTER:
		for i := 0; i < n; i++ {
			cnt, wc := 0, 0
			for j := i; j < n; j++ {
				wc += len(s[j])
				if wc == w[cnt] {
					cnt++
					wc = 0
					if cnt == 5 {
						ans = i + 1
						break OUTER
					}
				} else if wc > w[cnt] {
					break
				}
			}
		}
		io.Println(ans)
	}
}

// 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 := make([]interface{}, 0, len(a))
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func (io *Io) PrintStringSlice(a []string) {
	b := make([]interface{}, 0, len(a))
	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 <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#define EPS 1e-10
#define INF 1000000
#define mp make_pair
#define pb push_back

typedef vector<int> vi;
typedef vector<vi> vii;
typedef pair<int,int> pii;
typedef long long ll;

int main() {
	int n;
	while (1) {
		cin >> n;
		if (!n) {
			return 0;
		}
		int temp[] = {5, 7, 5, 7, 7};
		vector<string> s(n);
		for (int i = 0; i < n; i++) {
			cin >> s[i];
		}

		int stock = 0, pos = 0, ans = 0;
		for (int i = 0; i < n; i++) {
			stock = 0;
			pos = 0;
			for (int j = i; j < n; j++) {
				stock += s[j].size();
				if (stock == temp[pos]) {
					pos++;
					stock = 0;
				} else if (stock > temp[pos]) {
					break;
				}
				if (pos == 5) {
					ans = i + 1;
					break;
				}
			}
			if (ans > 0) {
				break;
			}
		}

		cout << ans << endl;
	}
}

C++: #include <bits/stdc++.h>
using namespace std;
#define dump(x) cout << (x) << '\n';
typedef int64_t Int;
Int mod = 1e9+7;
Int INF = 1e9+7;

int main() {
    while (true) {
      Int n;
      cin >> n;
      if (n == 0) break;
      vector<Int> x;
      for (Int i = 0; i < n; i++) {
          string s;
          cin >> s;
          x.emplace_back((Int)s.size());
      }
      for (Int i = 0; i < (Int)x.size(); i++) {
          Int a = 5, b = 7, c = 5, d = 7, e = 7;
          for (Int j = i; j < (Int)x.size(); j++) {
              if (a > 0) {
                  a -= x[j];
              }
              else if (b > 0) {
                  b -= x[j];
              }
              else if (c > 0) {
                  c -= x[j];
              }
              else if (d > 0) {
                  d -= x[j];
              }
              else if (e > 0) {
                  e -= x[j];
              }
              if (a < 0 || b < 0 || c < 0 || d < 0 || e < 0) break;
          }
          if (a == 0 && b == 0 && c == 0 && d == 0 && e == 0) {
              dump(i + 1);
              break;
          }
      }
    }
    return 0;
}

C++: #include <iostream>
#include <queue>

#define REP(i, n) for (int i = 0; i < n; i++)
#define debug(x) cerr << #x << " = " << (x) << endl;

using namespace std;

int main() {
  while (1) {
    int n, j, count, i, ans;
    const int rule[5] = {5, 7, 5, 7, 7};
    string w[41];
    queue<pair<int, int> > kouho;

    cin >> n;
    if (n == 0) break;
    REP(i, n) cin >> w[i];
    j = 0;
    count = 0;
    i = 0;
		ans = 0;
    while (i < n) {
      count += w[i].length();
			if (w[i].length() <= 5) kouho.push(make_pair(i,i));
      //debug(i);
      if (count == rule[j]) {
        //debug(count);
        //debug(j);
        if (j >= 4) {
          cout << ans+1 << endl;
          break;
        }
        count = 0;
        j++;
        i++;
      } else if (count > rule[j]) {
        count = 0;
        if (!kouho.empty()) {
          i = kouho.front().first;
					ans = kouho.front().second;
          kouho.pop();
					//cout << "pushed" << endl;
          j = 0;
        } else {
          i++;
          j = 0;
					ans = i;
        }
      } else {
        i++;
      }
    }
		//cout << "------------" << endl;
  }
  return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = (1LL << 31) - 1;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1
#define MAX_N 100100 * 3

int n;
int a[1000];
int table[] = { 5,12,17,24,31,-1 };

int main() {
	while (cin >> n&&n) {
		rep(i, n) {
			string s;
			cin >> s;
			a[i] = s.size();
		}
		rep(i, n) {
			a[i + 1] += a[i];
		}
		rep(i, n) {
			int pos = 0;
			FOR(j, i, n) {
				if (i != 0) {
					if (table[pos] == a[j] - a[i - 1])pos++;
				}
				else {
					if (table[pos] == a[j])pos++;
				}
			}
			if (pos == 5) {
				cout << i + 1 << endl;
				break;
			}
		}
	}
}

C++: #include<iostream>
#include<cstdio>

#define rep(i, n, m) for(int i=n;i<m;i++)

using namespace std;

const int num[5] = {5,7,5,7,7};

int main() {
    int n;
    while(scanf("%d", &n) && n){
        int a[n+1];
        rep(i, 0, n){
            string s;
            cin >> s;
            a[i+1] = s.length();
        }

        int ans = -1;
        rep(i, 1, n+1){
            int num_i = 0, cnt = 0;
            rep(j, i, n+1){
                cnt += a[j];
                if(num[num_i] == cnt){
                    num_i++;
                    cnt = 0;
                    if(num_i == 5){
                        ans = i;
                        break;
                    }
                }else if(cnt > num[num_i]){
                    break;
                }
            }
            if(ans != -1) break;
        }

        printf("%d\n", ans);
    }
}