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 <vector>
#include <string>

using namespace std;
int tanku[] = {5, 7, 5, 7, 7};

void solve()
{
	int n;
	while (cin >> n, n)
	{
		vector<int> w(n);
		for (int i = 0; i < n; ++i)
		{
			string s;
			cin >> s;
			w[i] = s.size();
		}
		for (int i = 0; i < n; ++i)
		{
			int pos = 0;
			int cnt = 0;
			for (int j = i; j < n; ++j)
			{
				cnt += w[j];
				if (cnt == tanku[pos])
				{
					++pos;
					cnt = 0;
				}
				if (pos >= 5 || cnt > tanku[pos])
				{
					break;
				}
			}
			if (pos == 5)
			{
				cout << i + 1 << endl;
				break;
			}
		}
	}
}

int main()
{
	solve();
	return(0);
}

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <ctime>
#define INF 999999999
#define mod 1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=(n);i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define MOD(x) (x%(mod))
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool debug=false;
/*---------------------------------------------------*/

int haiku[45];
int num[6]={5,7,5,7,7,0};

void solve(int n){
  int s=0,e=0,cnt=0,sum=haiku[0];
  int dast=0;
  
  rep(i,n-4){
    dast=cnt=0;
    s=e=i;
    sum=haiku[i];
    
    while(s!=n&&e!=n){
      if(debug)cout<<"s: "<<s<<"  e:"<<e<<"  cheack( "<<cnt<<" ): "<<num[cnt]<<"  dast: "<<dast<<"  cnt: "<<cnt<<endl;
      if(cnt==5)break;
      if(sum==num[cnt]){
	s=e=e+1;sum=haiku[s];cnt++;
      }else if(sum<num[cnt]){
	e++;sum+=haiku[e];
      }else if(sum>num[cnt]){
	break;
      }
    }
    if(debug)cout<<endl;
    if(debug)cout<<"s: "<<s<<"  e:"<<e<<"  cheack( "<<cnt<<" ): "<<num[cnt]<<"  dast: "<<dast<<"  cnt: "<<cnt<<endl;
    if(cnt==5){
      cout<<i+1<<endl;
      break;
    } 
  }
}


int main(){
  int n;
  string s;
  while(cin>>n){
    if(n==0)break;
    rep(i,n){cin>>s;haiku[i]=s.size();}
    solve(n);
  }
}

C++: #include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <string.h>

int main (){


  int n,ans = 0,count = 0,temp;
  int cc[5],ku;
  cc[0] = 5;
  cc[1] = 7;
  cc[2] = 5;
  cc[3] = 7;
  cc[4] = 7;

  char moji[40][10];
  while(1){
    scanf("%d",&n);
    if(n == 0) break;
    for(int i = 0;i < n;i++){
      scanf("%s",&moji[i]);
      //printf("%s ",moji[i]);fflush(0);
    }
	ans = 0;
	count = 0;
	temp = 0;
	ku = 0;
	while(1){
		temp += strlen(moji[ans+count]);
		//printf("%d",temp);
		if(cc[ku] == temp){
			if(ku == 4){
				break;
			}
			temp = 0;
			ku++;
		}
		else if(cc[ku] < temp){
			ku = 0;
			temp = 0;
			ans++;
			count = 0;
			continue;
		}
		count++;
	}
    printf("%d\n",ans+1);
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	string s;
	while(cin>>n,n){
		int a[40]={0},j=0,i=0,c,k=0;
		cout<<b[3];
		for(;j<n;j++){
			cin>>s;
			a[i++]=s.size();
		}
		for(j=0;j<35;j++){
			int b[4]={0};
			c=0;
		for(i=j;i<40;i++){
			c+=a[i];
			if(c==5)b[0]++;
			else if(b[0]&&c==12)b[1]++;
			else if(b[1]&&c==17)b[2]++;
			else if(b[2]&&c==24)b[3]++;
			else if(b[3]&&c==31){
				k=j;
				break;
			}
			if(!b[0]&&c>5)break;
		}if(k)break;
	    }
	    
		cout<<k+1<<endl;
	}
}

C++: #include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>

using namespace std;
using ll = long long;

int main()
{
    constexpr int len[5] = {5, 7, 5, 7, 7};
    while (true) {
        int n;
        cin >> n;
        if (n == 0) {
            break;
        }
        vector<int> l(n);
        for (int i = 0; i < n; i++) {
            string s;
            cin >> s;
            l[i] = s.size();
        }

        for (int i = 0; i < n; i++) {
            int ind = 0;
            int sum = 0;
            for (int j = i; j < n; j++) {
                if (ind == 5) {
                    break;
                }
                sum += l[j];
                if (sum > len[ind]) {
                    break;
                } else if (sum == len[ind]) {
                    ind++;
                    sum = 0;
                }
            }
            if (ind == 5) {
                cout << i << endl;
                break;
            }
        }
    }

    return 0;
}

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

int main(){
   while(true){
       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 i = 0; i < n; i++) {
           bool flg=false;
           int sta=0;
           int sum=0;

           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;
}