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,b,e) for(int i=(b);i<(e);++i)
#define rep(i,e) for(int i=0;i<(e);++i)

int main() {
  int n;
  while(cin >> n){
    if(n==0) return 0;
    vector<string> v(n);
    rep(i, n) cin >> v[i];

    bool good=false;
    rep(i, n){
      int state=0, cur=0;
      if(good) break;
      REP(j, i, n){
        cur += v[j].size();
        if(cur==5 && (state==0 || state==2)){
          cur = 0; state += 1;
        }
        else if(cur==7 && (state==1 || state==3 || state==4)){
          cur = 0; state += 1;
        }
        else if(cur>7) break;
        if(state==5){
          cout << i+1 << endl;
          good = true;
          break;
        }
      }
    }
  }
  return 0;
}

C++: #include <bits/stdc++.h>
 
using namespace std;
 
int solve(vector<int> &a)
{
    int N = a.size();
    const int p[] = {5, 7, 5, 7, 7};
    for (int i = 0; i < N; i++) {
        bool poss = 1;
        int q = i;
        for (int j = 0; j < 5; j++) {
            int sum = 0;
            for (; q < N; ) {
                sum += a[q++];
                if (sum >= p[j]) break;
            }
            if (sum != p[j]) {
                poss = 0;
                break;
            }               
        }
        if (poss) {
            return i + 1;
        }
    }
    return -1;
}
 
int main()
{
    int N;
    while (cin >> N, N) {
        vector<int> a(N);
        string s;
        for (int i = 0; i < N; i++) {
            cin >> s;
            a[i] = s.size();
        }
        cout << solve(a) << endl;
    }
    return 0;
}

C++: #include <iostream>
#define rep(i,n) for(int i = 0; i < n; ++i)
using namespace std;

int main(void){
	int n;
	while(cin >> n,n){
		string words[55];
		rep(i,n) cin >> words[i];

		rep(start,n){
			int num = 0,step = 0;
			int tar[5]={5,7,5,7,7};

			for(int j = start; j < n;++j){
				num += words[j].size();
				if(step < 5 and tar[step] == num){
					step++;
					num = 0;
				}
			}

			if(step == 5){
				cout << start+1 << endl;
				break;
			}
		}
	}

	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
void format(int a[]){
  for(int i=0;i<5;i++){
    if(i==0||i==2)
      a[i]=5;
    else
      a[i]=7;
  }
}
int main(){
  int n;
  while(cin>>n,n!=0){
    string word[n];
    for(int i=0;i<n;i++)
      cin>>word[i];
    int cnt[n];
    format(cnt);
    for(int j=0;j<n;j++){
      format(cnt);
      int pointer=0;
      for(int i=j;i<n;i++){
	cnt[pointer]-=word[i].size();
	if(cnt[pointer]<0)
	  break;
	else if(cnt[pointer]==0&&pointer==4){
	  cout<<j+1<<endl;return 0;
	}else if(cnt[pointer]==0)
	  pointer++;
      }
    }
  }
  return 0;
}

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

int main(){
  while(true){
    int n;
    cin>>n;
    if(n==0)break;
    vector<int> a(n);
    for(int i=0;i<n;i++){
      string s;
      cin>>s;
      a[i]=s.size();
    }
    int flag=0;
    int sum=0;
    int i;
    int j;
    for(j=0;j<n;j++){
      for(i=j;i<n;i++){
        sum+=a[i];
        if(flag==0&&sum==5){
          flag++;
          sum=0;
        }else if(flag==1&&sum==7){
          flag++;
          sum=0;
        }else if(flag==2&&sum==5){
          flag++;
          sum=0;
        }else if(flag==3&&sum==7){
          flag++;
          sum=0;
        }else if(flag==4&&sum==7){
          flag++;
          sum=0;
        }else if((flag==0||flag==2)&&sum>5){
          flag=0;
          sum=0;
          break;
        }else if((flag==1||flag==3||flag==4)&&sum>7){
          flag=0;
          sum=0;
          break;
        }
        if(flag==5)break;
      }
      if(flag==5)break;
    }
    cout<<j+1<<endl;
  }
}

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

int main(void) {
  int N;
  while (cin >> N, N) {
    vector<string> words(N);
    for (int i = 0; i < N; i++) {
      cin >> words[i];
    }

    int tanku_size[] = {5, 7, 5, 7, 7};
    for (int i = 0; i < N; i++) {
      int tanku_pos = 0;
      int letter_size = 0;
      for (int j = i; j < N; j++) {
        letter_size += words[j].size();
        if (letter_size > tanku_size[tanku_pos]) break;
        if (letter_size == tanku_size[tanku_pos]) {
          tanku_pos++;
          letter_size = 0;
        }
      }
      if (tanku_pos == 5) {
        cout << i + 1 << endl;
        break;
      }
    }
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

int a[41];
int x[]={5,7,5,7,7};
int main(){
    int n;
    string s;
    while(cin>>n,n){
        rep(i,n){
            cin>>s;
            a[i]=s.size();
        }
        int ans=-1;
        rep(i,n-5){
            int cur=0,sum=0;
            FOR(j,i,n){
                sum+=a[j];
                if(sum>=x[cur]){
                    if(sum==x[cur]){
                        ++cur;sum=0;
                        if(cur==5){
                            ans=i+1;
                            break;
                        }
                    }
                    else break;
                }
                if(ans!=-1) break;
            }
            if(ans!=-1){
                cout<<ans<<endl;
                break;
            }
        }
    }
    return 0;
}