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++: #pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using ull=unsigned long long int;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
while(1){
  int n;
  cin>>n;
  if(n==0)return 0;
  V<ll> a(n);
  for(int i=0;i<n;i++){
    string s;
    cin>>s;
    a[i]=(ll)s.size();
  }
  for(int i=0;i<n;i++){
    ll sum=0;int ind=i;
    while(ind<n&&sum<5)sum+=a[ind++];
    if(sum!=5)continue;
    sum=0;
    while(ind<n&&sum<7)sum+=a[ind++];
    if(sum!=7)continue;
    sum=0;
    while(ind<n&&sum<5)sum+=a[ind++];
    if(sum!=5)continue;
    sum=0;
    while(ind<n&&sum<7)sum+=a[ind++];
    if(sum!=7)continue;
    sum=0;
     while(ind<n&&sum<7)sum+=a[ind++];
    if(sum!=7)continue;
    cout<<i+1<<"\n";
    break;
  }
}
}

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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

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

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF = 1e9;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

int main()
{
    int N;
    vector<int> num = {5, 7, 5, 7, 7};

    while (cin >> N, N) {
        vector<string> S(N);
        rep(i, N) cin >> S[i];

        rep(i, N) {
            int tmp_len = 0;
            int num_idx = 0;
            bool ok = false;
            
            for (int j=i; j<N; j++) {
                if (tmp_len < num[num_idx]) {
                    tmp_len += S[j].size();
                }

                if (tmp_len == num[num_idx]) {
                    num_idx++;
                    tmp_len = 0;
                } else if (tmp_len > num[num_idx]) {
                    break;
                }

                if (num_idx == 5) {
                    ok = true;
                    break;
                }
            }
            if (ok) {
                cout << i+1 << endl;
                break;
            }
        }
    }
}

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

const int MAX_N=41;

int n,sum,t,ok; string w;
vector<int> words(MAX_N);
vector<int> each={5,7,5,7,7};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(cin >> n,n){
        for (int i=0;i<n;++i){
            cin >> w; words[i]=(int)w.size();
        }
        for (int i=0;i<n;++i){
            t=i,ok=1;
            for (int j=0;j<5;++j){
                sum=0;
                for (int k=t;k<n;++k){
                    sum+=words[k];
                    if (sum==each[j]){t=k+1; break;}
                    if (sum>each[j]){ok=0; break;}
                }
            }
            if (ok){
                cout << i+1 << '\n';
                break;
            }
        }
    }
}

C++: #include<bits/stdc++.h>
main(){for(char s[50],i,j,p,q;p=atoi(gets(s));printf("%d\n",i)){for(i=0;i<p;s[i++]=strlen(gets(s+i)));for(i=j=0;j<7;)for(p=i++,j=q=1;q>0;)for(q=j++>5?0:j-2&&j-4?8:6;q>1;q-=s[p++]);}}

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

int main(){
    while(true){
        int n;
        cin >> n;
        if(n == 0){
            break;
        }
        int phraseCount[] = {5, 7, 5, 7, 7};
        int currentPhraseIndex = 0;
        int currentPhraseCount = 0;
        string phrases[n];
        for(int i = 0; i < n; i++){
            cin >> phrases[i];
        }
        bool isFinished = false;
        for(int k = 0; k < n; k++){
        for(int i = k; i < n; i++){
            string s;
            s = phrases[i];
            currentPhraseCount += s.length();
            if(currentPhraseCount == phraseCount[currentPhraseIndex]){
                currentPhraseIndex++;
                currentPhraseCount = 0;
                if(currentPhraseIndex == 5){
                    cout << k + 1 << endl;
                    isFinished = true;
                    break;
                }
            }else if(currentPhraseCount > phraseCount[currentPhraseIndex]){
                currentPhraseIndex = 0;
                currentPhraseCount = 0;
                break;
            }
        }
        if(isFinished){
        	break;
        }
        }
    }
    return 0;
}

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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  while (cin >> n, n) {
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
      string w;
      cin >> w;
      a[i] = w.size();
    }
    for (int i = 0; i < n; ++i) {
      int s = 0;
      set<int> se;
      for (int j = i; j < n; ++j) {
        se.insert(s += a[j]);
      }
      if (se.count(5) and se.count(12) and se.count(17) and se.count(24) and se.count(31)) {
        cout << i + 1 << '\n';
        break;
      }
    }
  }
}