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 <bits/stdc++.h>
using namespace std;
#define rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++)

int main()
{
    vector<int> A = {5, 7, 5, 7, 7};
    while (true)
    {
        int N;
        cin >> N;
        if(N == 0)return 0;

        vector<int> S(N);
        rep(i, N)
        {
            string tmp;
            cin >> tmp;
            S[i] = tmp.size();
        }

        rep(i, N)
        {
            int now = i;
            bool flag = true;
            rep(j, 5)
            {
                int sum = 0;
                while(true)
                {
                    sum += S[now];
                    now++;
                    if(A[j] < sum)
                    {
                        flag = false;
                        break;
                    }
                    else if (sum == A[j]) {
                        break;
                    }
                    
                }
                if (!flag) {
                    break;
                }
                
            }

            if (flag) {
                cout << (i + 1) << "\n";
                break;
            }
            
        }
    }
}

C++: // 2018/01/05 Tazoe

#include <iostream>
#include <string>
using namespace std;

int main()
{
	while(true){
		int n;
		cin >> n;

		if(n==0)
			break;

		int len[40];			// 単語の長さ
		for(int i=0; i<n; i++){
			string w;
			cin >> w;

			len[i] = w.size();
		}

		for(int i=0; i<n; i++){
			bool flg = false;		// 見つかったフラグ
			int sta = 0;			// 区切り
			int sum = 0;			// 文字数の合計

			for(int j=i; j<n; j++){
				sum += len[j];

				// 区切りなら
				if(sum==5 || sum==12 || sum==17 || sum==24 || sum==31){
					sta++;
				}

				if(sta==5){			// 見つかった
					flg = true;
					break;
				}
				else if(sum>=31){		// 見つからなかった
					break;
				}
			}

			if(flg){			// 見つかったら
				cout << i+1 << endl;
				break;
			}
		}
	}

	return 0;
}

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

string s;
int n, ans;

int main() {
  int i, j;
  while(1) {
    cin >> n;
    if(n == 0) break;
    vector<int> v;
    for(i = 0; i < n; ++i) {
      cin >> s;
      v.push_back(s.size());
    }
    ans = 0;
    for(i = 0; i < n; ++i) {
      if(ans != 0) break;
      int now = 0, ch = 0;
      for(j = i; j < n; ++j) {
        now += v[j];
        if(now == 5 || now == 12 || now == 17 || now == 24 || now == 31) ++ch;
        if(now > 31) break;
      }
      if(ch == 5) ans = ++i;
    }
    cout << ans << endl;
  }
  return 0;
}

C++: #include<iostream>

using namespace std;

signed main(){

   while(1){
      int n;
      cin>> n;
      if(!n) break;

      int w[n];
      for(int i=0; i<n; i++){
         string s;
         cin>> s;
         w[i]=s.size();
      }
      int b[]={5, 7, 5, 7, 7};
      for(int i=0; i<n; i++){
         int a=0, p=0;
         for(int j=i; j<n; j++){
            a+=w[j];
            if(a>b[p]){
               goto turai;
            }else if(a==b[p]){
               p++;
               a=0;
            }
         }
         cout<< i+1<< endl;
         return 0;
         turai:;
      }

   }

   return 0;
}

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

int main(){
    while(1){
        int n;
        cin >> n;
        if(n == 0) break;
        vector<int> a(n);
        rep(i, 0, n){
            string s;
            cin >> s;
            a[i] = s.size();
        }
        int d[6] = {5, 7, 5, 7, 7, 114514};
        int ans = -1;
        rep(i, 0, n){
            int now = 0;
            int tmp = 0;
            rep(j, i, n){
                if(a[j] + tmp < d[now]){
                    tmp += a[j];
                }else if(a[j] + tmp == d[now]){
                    now++;
                    tmp = 0;
                }else{
                    break;
                }
                // cout << now << " " << tmp << endl;
                if(now == 5){
                    cout << i + 1 << endl;
                    i = n;
                    break;
                }
            }
        }
    }
}

C++: #include<bits/stdc++.h>
using namespace std;
int f[]={5,7,5,7,7};
int n;
int t[50];
string str;
 
int solve(){
  for(int i=0;i<n;i++){
    int a=i,j;
    for(j=0;j<5;j++){
      int b=0;
      while(b<f[j])b+=t[a++];
      if(b>f[j])break;
    }
    if(j==5)return i;
  }
  return 0;
}
 
int main(){
  while(1){
    cin>>n;
    if(n==0)break;
    for(int i=0;i<n;i++){
      cin>>str;
      t[i]=str.size();
    }
    cout<<solve()+1<<endl;
  }
  return 0;
}

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

int main(){
while(1){
 int n;
 cin>>n;

 if(n==0)break;
 
 int  len[40];
 for(int  i=0;i<n;i++){
	string w;
	cin>>w;

	len[i]=w.size();
 }

 for(int i=0;i<n;i++){
	bool flg=false;
	int sta=0;
	int sum=0;

	for(int j=i;j<n;j++){
		sum+=len[j];

		if(sum==5||sum==12||sum==17||sum==24||sum==31){
			sta++;
		}
		if(sta==5){
			flg=true;
			break;
		}else if(sum>=31){
			break;
		}
	}
 	if(flg){
		cout<<i+1<<endl;
		break;
	}
 }
}
return 0;
}