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

C++: #include<iostream>
#include<vector>
#include<string>
using namespace std;
#define DBG cout<<"!"<<endl;
vector<int> size;
int fin=0;
void dfs(int flag,int count,int i,int now){
  switch(flag){
  case 0:case 2:
    if(count+size[i]>5)
      return;
    if(count+size[i]==5){
      if(flag==0){	
	flag=1;
      }
      if(flag==2)
	flag=3;
    }
    if(flag==0||flag==2)
      dfs(flag,count+size[i],i+1,now);
    else
      dfs(flag,0,i+1,now);
    break;
  case 1:case 3:
    if(count+size[i]>7)
      return;
    if(count+size[i]==7){
      if(flag==1)
	flag=2;
      if(flag==3)
	flag=4;
    }
    if(flag==1||flag==3)
      dfs(flag,count+size[i],i+1,now);
    else
      dfs(flag,0,i+1,now);
    break;
  case 4:
    if(count+size[i]>7)
      return;
    if(count+size[i]==7){
      fin=1;
      cout<<now<<endl;
      return;
    }
    dfs(flag,count+size[i],i+1,now);
  }
}
int main(){
  int n;
  while(cin>>n,n!=0){
    fin=0;
    string str2;
    for(int i=0;i<n;i++){
      cin>>str2;
      size.push_back(str2.size());
    }
    for(int i=0;i<n;i++){
      int flag;
      int cnt=size[i];
      int now=i+1;
      if(fin==1)
	break;
      if(cnt==5){
	flag=1;
	cnt=0;
      }
      else
	flag=0;
      if(cnt>5)
	continue;
      dfs(flag,cnt,i+1,now);
    }
    size.clear();
  }
  return 0;
}

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

using namespace std;

int main(){
    int i,j,k,l;
    int n;
    int d5a=0,d7a=0,d5b=0,d7b=0,d7c=0;
    int stg=0;
    int ok=0,ans,first;
    while(1){
        cin >> n;
        if(n==0) break;
        string str[n];
        for(i=0;i<n;i++){
            cin >> str[i];
        }
        first = 0;
        for(i=0;i<n;i++){
            //i番目から始める
            stg = 0;
            int tmp=0;
            for(j=i;j<n;j++){
                if(first==0){
                    if(stg==0){
                        tmp += str[j].size();
                        if(tmp==5){
                            stg = 1;
                            tmp = 0;
                        } 
                    }else if(stg==1){
                        tmp += str[j].size();
                        if(tmp==7){
                            stg = 2;
                            tmp = 0;
                        }
                    }else if(stg==2){
                        tmp += str[j].size();
                        if(tmp==5){
                            stg = 3;
                            tmp = 0;
                        }
                    }else if(stg==3){
                        tmp += str[j].size();
                        if(tmp==7){
                            stg = 4;
                            tmp = 0;
                        }
                    }else if(stg==4){
                        tmp += str[j].size();
                        if(tmp==7){
                            stg = 5;
                            tmp = 0;
                        }
                    }
                    // cout << tmp << " " << endl; 
                     
                }
                
            }
            if(stg==5&&first==0){
                    first = 1;  
                    cout << i+1 << endl;  
            }
        }
    }   
}

C++: #include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define PB(a) push_back(a)
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(i, (v).size()) { cout << v[i]; if (i != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

const int dx[8] = { 1,1,0,-1,-1,-1,0,1 };
const int dy[8] = { 0,1,1,1,0,-1,-1,-1 };


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
///(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)(?´????????`)///
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	while (1) {
		int n;
		cin >> n;
		if (!n)break;
		vi v(n);
		REP(i, n) {
			string s;
			cin >> s;
			v[i] = s.size();
		}
		vi a = { 5,7,5,7,7 };
		REP(i, n) {
			int k = 0,sum = 0;
			FOR(j, i, n) {
				while (k < 5) {
					while (j < n&&sum < a[k]) {
						sum += v[j];
						j++;
					}
					if (sum == a[k]) {
						sum = 0;
						k++;
						if (k == 5) {
							cout << i + 1 << endl;
							goto ok;
						}
					}
					else break;
				}
			}
		
		}
	ok:;
	}
	return 0;
}