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 <fstream>
#include <stdio.h>

using namespace std;


int ch_len(char ch[]){
    int cnt = 0;
    for(int i=0; i<20; i++){
        if(ch[i] == '\0' || ch[i] == '\n')break;
        cnt++;
    }
    return cnt;
}

int cir(char w[][20], int first, int n){
    
    int now_vocab = 0;
    int mojisu = 0;
    
    for(int i=first; i<n; i++){
        int len = ch_len(w[i]);
        
        
        mojisu+=len;
        switch(now_vocab){
            case 0:
                if(mojisu == 5){
                    now_vocab++;
                    mojisu = 0;
                }
                else if(mojisu >5){
                    return cir(w, first+1, n);
                }
                break;
            case 1:
                if(mojisu == 7){
                    now_vocab++;
                    mojisu = 0;
                }
                else if(mojisu >7){
                    return cir(w, first+1, n);
                }
                break;
            case 2:
                if(mojisu == 5){
                    now_vocab++;
                    mojisu = 0;
                }
                else if(mojisu >5){
                    return cir(w, first+1, n);
                }
                break;
            case 3:
                if(mojisu == 7){
                    now_vocab++;
                    mojisu = 0;
                }
                else if(mojisu >7){
                    return cir(w, first+1, n);
                }
                break;
            case 4:
                if(mojisu == 7){
                    now_vocab++;
                    mojisu = 0;
                }
                else if(mojisu >7){
                    return cir(w, first+1, n);
                }
                break;
        }
        
        if(now_vocab >=5)return first;
    }
    
    return 0;
}

int main(int argc, const char * argv[]) {
    // insert code here...
    
    
    /////////
    //write//
    /////////
    
    int res;
    
    while(1){
        int n;cin >> n;
        char w[50][20];//<50
        if(n==0)break;
        
        for(int i=0; i<n; i++){
            cin >> w[i];
        }
        
        res = cir(w, 0, n)+1;
        cout << res << endl;
    }
    
    return 0;
}

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

int main(){
    
    int array[5] = {5, 7, 5, 7, 7};

    while(1){
        int n; cin >> n;
        if(!n) break;
        vector<string> tanka(n);
        for(int i = 0; i < n; i++){
            cin >> tanka[i];
        }
        int ans;
        bool flag = false;
        for(int i = 0; i < n; i++){

            int counter = 0;
            int k = 0;
            for(int j = i; j < n; j++){
                counter += tanka[j].size();
                if(array[k] == counter){
                    counter = 0;
                    k++;
                }else if(array[k] < counter){
                    break;
                }

                if(k == 5){
                    ans = i + 1;
                    flag = true;
                    break;
                } 
            }

            if(flag) break;
        }

        cout << ans << endl;
    }
    return 0;
    
}

C++: #include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vii;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip> vip;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 :1e9;
int main(){
	int n;
	while(cin>>n,n){
		vs in(n);
		rep(i,n)cin>>in[i];
		int q[]={5,7,5,7,7};
		rep(i,n){
			int t=0,I=i,s=0;
			while(I<n){
				s+=in[I].size();
				if(s>q[t])break;
				if(s==q[t]){
					t++;
					s=0;
				}
				if(t==5){
					cout<<i+1<<endl;
					goto end;
				}
				I++;
			}
		}
		end:;
	}
}

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

using namespace std;

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

bool search(int n,vector<int> &list,int p,int s){
  int c=0,i=p;
  if(s==5) return true;
  do{
    c+=list[i];
    i++;
  }while(c<range[s] && i<n);
  //  cout << c << endl;                                                                        
  // cout << "a " << s << endl;                                                                 
    if(c==range[s]) return search(n,list,i,s+1);
    else return false;
}

int main(){
  while(true){
    int n;
    cin >> n;
    if(n==0)break;
    string temp;
    vector<int> list(n,0);
    for(int i=0;i<n;i++){
      cin >>temp;
      list[i]=temp.length();
      //  cout << list[i] << endl;                                                              
    }
    bool flag;
    for(int i=0;i<n;i++){
      flag=search(n,list,i,0);
      if(flag){
        cout << i+1 << endl;
	break;
      }
    }
  }
  return 0;
}