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 <cstdio>
#include <cassert>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>

bool nya(std::vector<int> const& w, size_t k) {
  std::vector<int> haiku{5, 7, 5, 7, 7};
  int j = 0;
  for (size_t i = k; i < w.size(); ++i) {
    if (haiku[j] < w[i]) return false;
    haiku[j] -= w[i];
    if (haiku[j] == 0) {
      if (++j == 5) return true;
    }
  }
  return false;
}

int testcase_ends() {
  size_t n;
  scanf("%zu", &n);
  if (n == 0) return 1;

  std::vector<int> w(n);
  for (auto& wi: w) {
    char buf[16];
    scanf("%s", buf);
    wi = std::string(buf).length();
  }

  for (size_t i = 0; i < n; ++i)
    if (nya(w, i)) return !printf("%zu\n", i+1);

  assert(false);
}

int main() {
  while (!testcase_ends()) {}
}

C++: #include <iostream>
#include <vector>
#include <stack>
#include <utility>

using namespace std;

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

bool isword(int s,int n,vector<string> list){
    if(s==5)return true;
    int sum=0;
    bool flag;
    for(int i=n;i<list.size();i++){
        sum+=list[i].length();
        if(sum==seq[s]){
            flag=isword(s+1,i+1,list);
            break;
        }
        if(sum>seq[s]){
            flag=false;
            break;
        }
    }
    if(flag)return true;
    return false;
}

int main(){
    while(true){
        int n;
        cin >> n;
        if(n==0)break;
        vector<string> list(n);
        for(int i=0;i<n;i++){
            cin >> list[i];
        }
        int ans;
        for(int i=0;i<n;i++){
            if(isword(0,i,list)){
                ans=i+1;
                break;
            }
        }
        cout << ans << endl;
    }
    return 0;
}

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

using namespace std;

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

int main(){
	
	while(1){
		
		int n;
		cin >> n;
		if(n==0) break;
		
		string a;
		int t[n]={};
		
		for(int i=0;i<n;i++){
			cin >> a;
			t[i]=(int)a.size();
		}
		int c,ans=0;
		for(int i=0;i<n;i++){
			c=i;
			int j;
			for(j=0;j<5;j++){
				int b=0;
				while(b<k[j]){
					b+=t[c];
					c++;
				}
				if(b>k[j]) break;
			}
			if(j==5){
				ans=i;
				break;
			}
		}
		cout << ans+1 << endl;
	}
		
		
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
#define int ll

signed main(void)
{
  while(true) {
    int n;
    cin >> n;
    if(!n) break;
    string s[45];
    REP(i, n) cin >> s[i];

    REP(i, n) {
      int tmp = 0, cnt = 0;
      FOR(j, i, n) {
        tmp += s[j].size();
        //cout << cnt << " " << tmp << endl;
        if(cnt == 0) {
          if(tmp == 5) {cnt = 1; tmp = 0;}
          else if(tmp > 5) break;
        } else if(cnt == 1) {
          if(tmp == 7) {cnt = 2; tmp = 0;}
          else if(tmp > 7) break;
        } else if(cnt == 2) {
          if(tmp == 5) {cnt = 3; tmp = 0;}
          else if(tmp > 5) break;
        } else if(cnt == 3) {
          if(tmp == 7) {cnt = 4; tmp = 0;}
          else if(tmp > 7) break;
        } else if(cnt == 4) {
          if(tmp == 7) {cnt = 5; tmp = 0;}
          else if(tmp > 7) break;
        }
      }
      if(cnt == 5) {
        cout << i+1 << endl;
        break;
      }
    }
  }

  return 0;
}

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

int main(){
  while(1){
    int n;
    cin>>n;
    if(n==0)break;
    vector<int> a(n);
    for(int i=0;i<n;i++){
      string s;
      cin>>s;
      a[i]=s.size();
      //cout<<a[i]<<endl;
    }
    int ok=0;
    for(int i=0;i<n;i++){
      if(ok==1)break;
      int sum=0;
      int sta=0;
      int j=i;
      while(1){
        //cout<<sta<<" "<<sum<<endl;
        if(sta==0||sta==2){
          if(sum+a[j]==5){
            sta++;
            sum=0;
          }else{
            sum+=a[j];
            if(sum>5)break;
          }
        }else{
          if(sum+a[j]==7){
            sta++;
            if(sta==5){
              cout<<i+1<<endl;
              ok=1;
              break;
            }
            sum=0;
          }else{
            sum+=a[j];
            if(sum>7)break;
          }
        }
        j++;
      }
    }
  }
}

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

int main(){
  int n,h[40];
  string a;
  while(cin>>n,n){
    for(int i=0;i<n;i++)cin>>a,h[i]=a.size();
    for(int i=0;i<n;i++){
      int now=i,nt=0,nn=0,f=0;
      while(1){
	if(nt==5){
	  f=1;
	  break;
	}
	if(nt==0||nt==2){
	  if(nn>5)break;
	  if(nn==5)nt++,nn=0;
	}else{
	  if(nn>7)break;
	  if(nn==7)nt++,nn=0;
	}
	nn+=h[now];
	now++;
      }
      if(f){
	cout<<i+1<<endl;
	break;
      }
    }
  }
  return 0;
}