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 <iostream>
#include <algorithm>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <random>
#include <complex>
#include <assert.h>

using namespace std;
typedef unsigned long long ll;
#define endl '\n'

template<typename T>
inline bool chmin(T& x, T a) {
	if (x >= a) { x = a; return true; }
	return false;
}

template<typename T>
inline bool chmax(T& x, T a) {
	if (x <= a) { x = a; return true; }
	return false;
}

int main() {
	ios::sync_with_stdio(false);
	std::cin.tie(0);

	while (1) {
		int n; cin >> n;
		if (n == 0) { break; }
		vector<int> v(n, 0);
		for (int i = 0; i < n; i++) {
			string str; cin >> str;
			v[i] = str.size();
		}
		set<int> st;
		{
			int temp = 0;
			for (int i = 0; i < n; i++) {
				temp += v[i];
				st.insert(temp);
			}
		}
		int temp = 0;
		for (int i = 0; i < n; i++) {
			if (
				st.find(temp + 5) != st.end() &&
				st.find(temp + 12) != st.end() &&
				st.find(temp + 17) != st.end() &&
				st.find(temp + 24) != st.end() &&
				st.find(temp + 31) != st.end()
				) {
				cout << i + 1 << endl;
				break;
			}
			temp += v[i];
		}
	}

	return 0;
}

C++: #include<iostream>
#include<vector>
#include<string>
using namespace std;

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

typedef long long ll;

const int INF=1e9+7;
const int MAX_N=1e2;
int data[MAX_N];
int s[5]={5,7,5,7,7};
int main(){
	int n;
	while(cin>>n && n){
		fill(data,data+MAX_N,0);
		rep(i,n){
			string str;
			cin>>str;
			data[i]=str.size();
		}
		int ans=0;
		rep(i,n){
			if(ans!=0)break;
			int k=0;
			rep(j,5){
				int tmp=0;
				while(tmp<s[j] && i+k<n){
					tmp+=data[i+k++];
				}
				if(tmp!=s[j])break;
				if(j==4)ans=i+1;
			}
		}
		cout<<ans<<endl;
	}
}

C++: #include <iostream>
using namespace std;
int main(){
  int a[]={5,7,5,7,7,-1},n,i,j,c,k;
  while(cin>>n,n){
    string s[n];
    for(i=0;i<n;i++)cin>>s[i];
    for(i=0;i<n;i++){
      c=k=0;
      for(j=i;j<n;j++){
        c+=s[j].size();
        if(c==a[k]){
          c=0;
          if(++k==5)cout<<i+1<<endl;
          }
        }
      }
    }
  }

C++: #include<iostream>
#include<vector>
#include<cassert>
#include<string>
#include<algorithm>
using namespace std;

#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define repeat(i, j, k) for(int i = (j); i < (int)(k); i++)
#define all(v) v.begin(),v.end()
// vector
template<class T> istream& operator >> (istream &is , vector<T> &v) {
    for(T &a : v) is >> a; return is;
}

bool solve() {
    int n; cin >> n;
    if(n == 0) return 0;
    vector<string> s(n); cin >> s;

    rep(i, n) {
        vector<int> haiku = {5, 7, 5, 7, 7};
        reverse(all(haiku));
        repeat(j, i, n) {
            haiku.back() -= s[j].size();
            if(haiku.back() < 0) break;
            else if(haiku.back() == 0) {
                haiku.pop_back();
                if(haiku.size() == 0) {
                    cout << i + 1 << endl;
                    return 1;
                }
            }
        }
    }
    assert(0);
    return 1;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(solve());
    return 0;
}

C++: #include <iostream>
#include <vector>
#include <string>

using std::cin;
using std::cout;
using std::endl;
using std::vector;
using std::string;


int main(void) {
    int n;
    while (cin >> n) {
        if (n == 0) {
            break;
        }
        int tanka[5] = {5, 7, 5, 7, 7};
        string s;
        vector<int> l;
        for (int i = 0; i < n; i++) {
            cin >> s;
            l.push_back(s.length()); 
        }

        for (int i = 0; i < l.size(); i++) {
            int posi = 0;
            vector<int> work(5, 0);
            for (int j = i; j < l.size(); j++) {
                int length = l[j];
                if (work[posi] + length < tanka[posi]) {
                    work[posi] += length; 
                } else if (work[posi] + length == tanka[posi]) {
                    posi++; 
                    if (posi == 5) {
                        cout << i + 1 << endl;
                        break;
                    }
                } else {
                    break;
                }
            }
            if (posi == 5) {
                break;
            }
        }
    }

    return 0;
}