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 <utility>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
int n;
string str;
int ans;
int size[50];

int check_tanka(int num,int count,int i,int *size){
    //cout << num <<endl;
    if(num ==0||num ==2){
        if(count+size[i]<5){
            return check_tanka(num,count+size[i],i+1,size);
        }else if(count+size[i]==5){
            return check_tanka(num+1,0,i+1,size);
        }else if(count+size[i]>5){
            return -1;
        }
    }else if(num==1||num == 3){
        if(count+size[i]<7){
            return check_tanka(num,count+size[i],i+1,size);
        }else if(count+size[i]==7){
            return check_tanka(num+1,0,i+1,size);
        }else if(count+size[i]>7){
            return -1;
        }

    }else if(num == 4){
        if(count+size[i]<7){
             return check_tanka(num,count+size[i],i+1,size);
        }else if(count+size[i]==7){
            return 0;
        }else if(count+size[i]>7){
            return -1;
        }
    }
    return -1;
}

int main(){
    while(1){
        cin >>n;
        if(!n)break;
        for(int i=0;i<50;i++){
            size[i] = 0;
        }
        for(int i=0;i<n;i++){
            cin >> str;
            size[i] = str.size();
        }
        for(int i = 0;i<n;i++){
            ans = check_tanka(0,0,i,size);
            if (ans!=-1){
                ans = i+1;
                break;
            }
        }
        cout << ans<<endl;
    }
   
}

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

int main(){

  int n, w[5]={5, 7, 5, 7, 7};
  string s[40];

  while(cin>>n, n){
    for(int i=0;i<n;i++) cin>>s[i];

    for(int i=0;i<n;i++){
      int id=0, sw=0;
      bool f=false;
      for(int j=i;j<n;j++){
        sw+=s[j].size();
        if(sw==w[id]){
          id++;
          sw=0;
        }else if(sw>w[id]) break;
        if(id==5){
          cout<<i+1<<endl;
          f=true;
          break;
        }
      }
      if(f) break;
    }
  }

  return 0;
}

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

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

int main()
{
    int n;
    int a[5]={5,7,5,7,7};
    while(cin >>n,n)
    {
        vector<int> w(n);
        rep(i,n)
        {
            string s;
            cin >>s;
            w[i]=s.size();
        }

        int ans=-1;
        rep(i,n)
        {
            int ct=0;

            bool valid=false;
            int idx=0;
            for(int j=i; j<n; ++j)
            {
                ct+=w[j];
                if(ct==a[idx])
                {
                    ++idx;
                    ct=0;
                }
                else if(ct>a[idx]) break;


                if(idx==5)
                {
                    valid=true;
                    break;
                }
            }

            if(valid)
            {
                ans=i+1;
                break;
            }
        }

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

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

using namespace std;

int check(vector<int> tanka){
	int roule[] = {5,7,5,7,7};
	int index = 0, i = 0, t = 0;
	int sum = 0;
	while(i < 5){
		do{
			sum += tanka[index+t];
			t++;
		}while(sum < roule[i]);
		if(sum > roule[i]){
			index++;
			i = 0;
			t = 0;
		}else{
			i++;
		}
		sum = 0;
	}
	return index+1;
}

int main(){
	vector<int> tanka;
	vector<int> res;
	int n;
	do{
		cin >> n;
		for(int i=0;i<n;i++){
			string tmp;
			cin >> tmp;
			tanka.push_back(tmp.size());
		}
		if(n > 0)
			res.push_back(check(tanka));
		tanka.clear();
		tanka.shrink_to_fit();
	}while(n > 0);

cout << "test" << endl;
	for(auto num : res){
		cout << num << endl;
	}
	
	return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <fstream>
using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
typedef long long ll;

#define INF 1000000000

const int len[] = {5,7,5,7,7};

int main(){
    int n;

    while(cin>>n , n){
        vector<string> w(n);
        rep(i,n) cin>>w[i];

        int res;
        rep(i,n){
            int idx=0;
            int words=i;
            while(idx<5){
                int sz=0;
                while(sz < len[idx]){
                    sz += w[words++].size();
                }
                if(sz>len[idx]) break;
                idx++;
            }
            if(idx==5){res=i+1;break;}
        }

        cout<<res<<endl;

    }

    return 0;
}