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;
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>
#include<algorithm>
using namespace std;
int len[50];
int d[5]={5,7,5,7,7};
int main(){
	int n;
	string s;
	while(true){
	cin>>n;
	if(n==0)break;
	for(int i=0;i<n;i++){
		cin>>s;
		len[i]=s.size();
	}
	int ans=100000;
	for(int i=0;i<n;i++){
		int cnt=0;
		int set=0;
		int j=i;
		bool ok=true;
		while(true){
			cnt+=len[j];
			if(cnt==d[set]){
				cnt=0;
				set++;
				if(set==5)break;
			}
			if(cnt>d[set]){
				ok=false;
				break;
			}
			j++;
			if(j==n){
				ok=false;
				break;
			}
		}
		if(ok){
			ans=min(ans,i+1);
		}
	}
	cout<<ans<<endl;
	}
	return 0;
}

C++: 
#include <iostream>

using namespace std;

int main()
{
    int n;
    while (cin >> n, n)
    {
        int w[n] = {0};
        for (int i = 0; i < n; i++)
        {
            string s;
            cin >> s;
            w[i] = s.size();
        }
        bool clear = false;
        int ans = 0;
        for (int i = 0; i < n && !clear; i++)
        {
            int phrase = 0;
            int tmp = 0;
            for (int j = i; j < n; j++)
            {
                tmp += w[j];
                if (phrase == 0 || phrase == 2)
                {
                    if (tmp == 5)
                    {
                        phrase++;
                        tmp = 0;
                    }
                    else if (tmp > 5)
                    {
                        break;
                    }
                }
                else
                {
                    if (tmp == 7)
                    {
                        if (phrase == 4)
                        {
                            clear = true;
                            ans = i + 1;
                            break;
                        }
                        else
                        {
                            phrase++;
                            tmp = 0;
                        }
                    }
                    else if (tmp > 7)
                    {
                        break;
                    }
                }
            }
        }
        cout << ans << endl;
    }
}

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

int main(){

  int len[5] = {5,7,5,7,7};
  int n, i;
  string str[41];
  while(cin >> n, n){
    for(i = 0; i < n; i++){
      cin >> str[i];
    }
    for(i = 0; i < n; i++){
      int sum = 0, idx = 0, flag = 0;
      for(int j = i; j < n; j++){
        sum += str[j].size();
        if(len[idx] == sum){
          sum = 0;
          idx++;
        }else if(len[idx] < sum){
          break;
        }
        if(idx == 5){
          flag = 1;
          break;
        }
      }
      if(flag){
        cout << i + 1 << endl;
        break;
      }
    }
  }
  return 0;
}

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int64 n;
	int64 num[5] = {5, 7, 5, 7, 7};
	while (cin >> n && n) {
		vector<int64> a(n);
		REP(i, n) {
			string s;
			cin >> s;
			a[i] = s.size();
		}
		int64 res = -1;
		REP(i, n) {
			int64 s = 0, idx = 0;
			FOR(j, i, n) {
				s += a[j];
				if (num[idx] == s) idx++, s = 0;
				if (idx == 5) break;
				if (num[idx] < s) break;
			}
			if (idx == 5) {
				res = i;
				break;
			}
		}
		cout << res+1 << endl;
	}
}

C++: #include<iostream>
#define f(X) for(c=0;c<X;c+=v[p++]);if(c-X)continue;
using namespace std;main(){for(int n,v[50],s,p,c;cin>>n,n;){string t;for(s=0;s<n;)cin>>t,v[++s]=t.size();for(s=p=1;p=++s;){f(5)f(7)f(5)f(7)f(7)cout<<s<<endl;p=0;}}}