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 <string>

using namespace std;

int main(){
  int n,a,b,c,d,e,j;
  string w[40];
  while(true){
    cin >> n;
    if(n == 0) break;

    for(int i = 0; i < n; i++){
      cin >> w[i];
    }
    //cout << "n="<<n << endl;
    for(int i = 0; i < n - 4; i++){
      //start w[i] 5 7 5 7 7
      //cout << i << "=i" <<endl;
      a = 5;
      b = 7;
      c = 5;
      d = 7;
      e = 7;

      int j=i;
      bool flag = true;
      while(flag ){//5

        if(a - w[j].size() == 0){j++; break;}
        else if(j >= n){flag = false;}
        else if(a - w[j].size() > 0){a-=w[j].size(); j++;}
        else {flag = false;}
      }
      //cout << j << endl;
      while(flag){//7

        if(b - w[j].size() == 0){j++; break;}
        else if(j >= n ){flag = false;}
        else if(b - w[j].size() > 0){b-=w[j].size(); j++;}
        else {flag = false;}
      }
      //cout << j << endl;
      while(flag){//5

        if(c - w[j].size() == 0){j++; break;}
        else if(j >= n){flag = false;}
        else if(c - w[j].size() > 0){c-=w[j].size(); j++;}
        else {flag = false;}
      }
      //cout << j << endl;
      while(flag){//7

        if(d - w[j].size() == 0){j++; break;}
        else if(j >= n){flag = false;}
        else if(d - w[j].size() > 0){d-=w[j].size(); j++;}
        else {flag = false;}

      }
      //cout <<  j << endl;
      while(flag){//7

        if(e - w[j].size() == 0){  j++; break;}
        else if(j >= n){flag = false;}
        else if(e - w[j].size() > 0){  e -= w[j].size(); j++;}
        else {flag = false;}
      }
      if(flag){
        cout << i+1 << endl;
        break;
      }
    }
  }

  return 0;

}

C++: #include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i < n;i ++ )
#define ll long long

using namespace std;

// input
ll a[5];

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<int> t(5);
  t[0] = 5;
  t[1] = 7;
  t[2] = 5;
  t[3] = 7;
  t[4] = 7;
  while(true) {
    int num;
    cin >> num;
    if(num == 0)break;
    vector<string> w(num);
    rep(i,num){
        cin >> w[i];
    }
    bool ok = false;

    rep(i,num) {
        if(w[i].size() > 5)continue;
        string buf = "";
        int k = 0;
        for(int j = i; j < num; j++) {
            buf +=w[j];
            if(buf.size() == t[k]) {
                k++;
                buf = "";
            }
            else if(buf.size() > t[k])break;
            if(k == 5)ok =true;
        }
        if(ok) {
            cout << i+1 << endl;
            break;
        }
    }
  }
}

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

#define REP(i,a,b) for(int i=int(a);i<int(b);i++)

using namespace std;

typedef long long int lli;

int main () {
    int n;
    int length[5] = {5, 7, 5, 7, 7};
    while(cin >> n, n) {
        vector<int> v(n);
        REP (i, 0, n) {
            string str;
            cin >> str;
            v[i] = str.size();
        }
        int ans = -1;
        REP (i, 0, n) {
            int pos = 0;
            int total = 0;
            REP (j, i, n) {
                total += v[j];
                if (length[pos] == total) {
                    pos++;
                    total = 0;
                } else if (length[pos] < total) {
                    break;
                }
                if (pos == 5) {
                    ans = i + 1;
                    break;
                }
            }
            if (ans != -1) break;
        }
        cout << ans << endl;
    }
    return 0;
}

C++: #include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<stack>
#include<queue>
#include<string>
#include<set>
#include<map>
using namespace std;
#define rep(i,n) for(int i=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int i=(m);(i)<(n);(i)++)
typedef long long ll;

int main(){
    int n;
    while(cin >> n,n){
        vector<int> len(n);
        rep(i,n){
            string s;cin >> s;
            len[i]=s.size();
        }
        for(int i=0;i<n;i++){
            int now = i;
            int sum=0;
            while(sum<5){
                if(now==n)break;
                sum+=len[now];
                now++;
            }
            if(now==n||sum!=5)continue;
            
            sum=0;
            while(sum<7){
                if(now==n)break;
                sum+=len[now];
                now++;
            }
            if(now==n||sum!=7)continue;
            
            sum=0;
            while(sum<5){
                if(now==n)break;
                sum+=len[now];
                now++;
            }
            if(now==n||sum!=5)continue;
            
            sum=0;
            while(sum<7){
                if(now==n)break;
                sum+=len[now];
                now++;
            }
            if(now==n||sum!=7)continue;

            sum=0;
            while(sum<7){
                if(now==n)break;
                sum+=len[now];
                now++;
            }
            if(sum!=7)continue;
            cout << i+1 << endl;
            break;
        }

    }
    return 0;
}