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(){
	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 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>

#define REP(i, n) for(decltype(n) i = 0; i < n; i++)

#define ALL(c)   c.begin(), c.end()
#define SORT(c)  std::sort(ALL(c))
#define RSORT(c) std::sort(ALL(c), std::greater<decltype(c)::value_type>())

using namespace std;
using ll = long long;

const int MOD  = (int)1e9 + 7;
const int INF  = (int)1e9 + 1;
const ll  LINF = (ll)1e18 + 1;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    while(true) {
        int N;
        std::cin >> N;
        if(N == 0) break;

        vector<string> S(N);
        REP(i, N) {
            std::cin >> S[i];
        }

        REP(i, N) {
            int tmp_i = i;
            auto f = [&](int num) {
                         int cnt = 0;
                         while(cnt < num) {
                             cnt += S[tmp_i].size();
                             tmp_i++;
                         }
                         return cnt != num ? false : true;
                     };
            if(f(5) && f(7) && f(5) && f(7) && f(7)) {
                std::cout << i + 1 << std::endl;
                break;
            }
        }
    }

    return 0;
}

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

int main(){
  while(1){
    int N, i, j, s = 0;
    scanf("%d", &N);
    if(N == 0){
      return 0;
    }
    vector<string> w(N);
    for(i = 0; i < N; i++){
      cin >> w[i];
      s += w[i].size();
    }
    vector<int> a(s + 1, 0);
    for(i = 0, j = 0; i < N; i++){
      a[j] = 1;
      j += w[i].size();
    }
    a[j] = 1;
/*    for(i = 0; i < a.size(); i++){
      printf("%d", a[i]);
    }
    printf("\n");
*/    s = 0;
    for(i = 0; i < N; i++){
//      printf("i = %d\n", i);
//      printf("s = %d\n", s);
      if(a[s] == 1 && a[s + 5] == 1 && a[s + 12] == 1 && a[s + 17] == 1 && a[s + 24] == 1 && a[s + 31] == 1){
        printf("%d\n", i + 1);
        break;
      }
      s += w[i].size();
    }
  }
}

C++: #include <iostream>
using namespace???std;
int main(){
  int a[]={5,7,5,7,7},n,i,j,c,k;
  while(cin>>n,n){
    string s[n];
    for(i=0;i<n;i++)cin>>s[i];
    for(i=0;i<n;i++){
      c=k=0;
      for(j=i;j<n;j++){
        c+=s[j].size();
        if(c==a[k]){
          c=0;
          if(++k==5)goto L:
        }
      }
    }
    L: if(k==5)cout<<i<<endl;
  }
}

C++: #include <bits/stdc++.h>
 
using namespace std;
 
int main() {
 
    int n;
    string w[40];
    int lens[] = {5, 7, 5, 7, 7};
 
    while(cin >> n, n) {
 
        for(int i = 0; i < n; ++i) {
            cin >> w[i];
        }
 
        for(int i = 0; i < n; ++i) {
 
            int len = 0, phrase = 0;
 
            for(int j = i; j < n; ++j) {
 
                len += w[j].size();
 
                if(len == lens[phrase]) {
                    len = 0;
                    ++phrase;
                    if(phrase == 5) {
                        cout << i + 1 << endl;
                        break;
                    }
                }
            }
 
            if(phrase == 5) {
                break;
            }
 
        }
 
    }
 
}

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

C++: #include <iostream>
#include <string>
#include <vector>
#include <cstdio>
using namespace std;
vector<int> T={5,7,5,7,7};
int solve(const vector<string>&v){
	for(int i=0;i<v.size();i++){
		for(int j=i,n=0,y=0;j<v.size();j++){
			n+=v[j].size();
			if(n==T[y]){
				if(++y==T.size())return i+1;
				n=0;
			}
		}
	}
	return -1;
}
int main(){
	int N;
	for(;cin>>N,N;){
		vector<string>v(N);
		for(int i=0;i<N;i++)cin>>v[i];
		printf("%d\n",solve(v));
	}
}

C++: #include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
const double PI  = 3.1415926535897932384626433832795028841971;
const int    INF = 100000000;
const double EPS = 1e-10;
const int    MOD = 1000000007;
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
string str[40];

void solve(){
	rep(i,n) cin >> str[i];
	rep(i,n){
		int cnt[5] = {5,7,5,7,7};
		for(int j = i; j < n; j++){
			rep(k,5){
				if(cnt[k] != 0){
					cnt[k] -= str[j].size();
					break;
				}
			}
		}
		bool ok = true;
		rep(j,5) if(cnt[j] != 0) ok = false;
		if(ok){
			cout << i+1 << endl;
			break;
		}
	}
}

int main(){
	while(cin >> n){
		if(n == 0) break;
		solve();
	}
}