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;
	while(cin>>n){
		if(n==0) break;
		int a[n];
		for(int i=0;i<n;i++){
			string s;
			cin>>s;
			a[i]=s.size();
		}
		int st=0,t=0,ct=0;
		for(int i=0;i<n;i++){
			for(int j=i;j<n;j++){
				t=t+a[j];
				if(ct==0||ct==2){
					if(t>5){
						t=0;
						ct=0;
						break;
					}
					else if(t==5){
						t=0;
						ct++;
					}
				}
				else if(ct==1||ct==3||ct==4){
					if(t>7){
						t=0;
						ct=0;
						break;
					}
					else if(t==7){
						t=0;
						ct++;
					}
				}
			}
			if(ct==5){
				st=i+1;
				break;
			}
		}
		cout<<st<<endl;
	}
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int n,l[45],L[45],a,d[5]={5,7,5,7,7};
string s;
 
int main(){
  while(1){
    cin>>n;
    if(!n)break;
    for(int i=1;i<=n;i++){
      cin>>s,l[i]=s.size();
      L[i]=L[i-1]+l[i];
    }
    a=0;
    for(int i=1;i<=n;i++){
      int x=0,s=i;
      for(int j=i;j<=n;j++){
    if(L[j]-L[s-1]==d[x])x++,s=j+1;
    if(!a&&x==5)a=i,cout<<a<<endl;
      }
    }
  }
  return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

int n;

int main(){
    while(1){
        cin >> n;
        if(n==0)break;
        vector<string> w(n);
        int tan[] = {5,7,5,7,7};
        for(int i=0;i<n;i++){
            cin >> w[i];
        }
        int j=0;
        int ans=0;
        int sum=0;
        for(int i=0;i<n;i++){
            sum += w[i].size();
            if(sum > tan[j]){
                sum = w[i].size();
                j=0;
                ans=i;
            }
            if(sum < tan[j])continue;
            if(sum == tan[j]){
                if(j==4)break;
                else {
                    j++;
                    sum = 0;
                }
            }
        }
        cout << ans << endl;

    }
}

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

int n;
string str[40];
int x[5] = {5,7,5,7,7};

void solve(){
    rep(i,n) cin >> str[i];
    rep(i,n){
        int cnt = 0;
        int sum = 0;
        for(int j = i; j < n; j++){
            sum += str[j].size();
            if(sum == 5) cnt++;
            if(sum == 12) cnt++;
            if(sum == 17) cnt++;
            if(sum == 24) cnt++;
            if(sum == 31) cnt++;
            if(sum >= 31) break;
        }
        if(cnt == 5){
            cout << i+1 << endl;
            break;
        }
    }
}

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

C++: #include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<functional>
#include<queue>
#include <iomanip>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

#define DBG cerr << '!' << endl;
#define REP(i,n) for(int (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(int (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(int (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cerr << v[i] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(10)

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

int ok[] = {5,7,5,7,7};

int main()
{	
	int n;
	
	while(cin >> n,n)
	{
		vector<string> v;
		REP(i,n)
		{
			string tmp;cin >> tmp;
			v.PB(tmp);
		}
		
		REP(i,n)
		{
			int cou = 0;
			int num = 0;
			for(int j = i;j < n;j++)
			{
				num += v[j].size();
				if(num == ok[cou])
				{
					cou++;
					num=0;
					if(cou == 5)
					{
						cout << i+1 << endl;
						goto NEXT;
					}
					
				}
				else if(num > ok[cou])
				{
					break;
				}
			}
		}
		NEXT:;
	}
			
			
	return 0;
}

C++: #include <iostream>
#include <cstdlib>
#include <algorithm>
#include <math.h>

using namespace std;

string w[41];
int n,ans;
int d=0;
int solve(){
    for(int i=0;i<n;i++){
    int a=0;
    d=0;
        for(int j=i;j<n;j++){
            a+=w[j].length();
            if(d==0&&a==5){
            d++;
            a=0;
            }
            if(d==1&&a==7){
             d++;
            a=0;
            }
            if(d==2&&a==5){
             d++;
            a=0;
            }
            if(d==3&&a==7){
             d++;
            a=0;
            }
            if(d==4&&a==7){
            ans=i+1;
            return i;
            }
            if(a>7)break;
        }
    }
    return 0;
}
int main()
{
    while(1){
    cin>>n;
    if(n==0)return 0;
    for(int i=0;i<n;i++)
    cin>>w[i];
    
    d=0;
    solve();
    cout<<ans<<endl;
    }
}

C++: #include<iostream>
#include<string>
using namespace std;
int main(){

  int n,w[430];
  string str,kari;

  cin >> n;
  while( n != 0){
    fill_n(w,430,0);
    w[0] = 1;

    for(int i = 0;i < n;i++){
      cin >> kari;
      if(i != 0) w[str.size()] = i+1;
      str += kari;
    }
    w[str.size()]=n+1;
    
    for(int i = 0;i <= str.size()-31;i++){
      if(w[i]!=0&&w[i+5]!=0&&w[i+12]!=0&&w[i+17]!=0&&w[i+24]!=0&&w[i+31]!=0){
	cout << w[i] << endl;
	break;
      }
    }
    cin >> n;
  }
  return (0);
}