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 <bits/stdc++.h>

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
int const inf = 1<<29;

int main() {

  for(int N; cin >> N && N;) {
    int cnt[41];
    rep(i, N) {
      string s; cin >> s;
      cnt[i] = s.size();
    }
    const array<int, 5> arr{{5,7,5,7,7}};
    rep(st, N) {
      int sum = 0;
      int curr = 0;
      bool ok = 0;
      REP(i, st, N) {
        sum += cnt[i];
        if(sum == arr[curr]) {
          curr++;
          sum = 0;
          if(curr >= arr.size()) {
            ok = 1;
            break;
          }
        }
        if(sum > arr[curr]) {
          break;
        }
      }
      if(ok) {
        cout << st + 1 << 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[n];
  for(int i=0; i<n; i++){
   string w;
   cin >> w;
   len[i] = w.size();
  }

  for(int i=0; i<n; i++){
   bool flag = false;
   int sta = 0; //区切り
   int sum = 0; //文字数の合計

   for(int j=i; j<n; j++){
    sum = sum + len[j];
    
    if(sum==5 || sum==12 || sum==17 || sum==24 || sum==31){
     sta++;
    }

    if(sta==5){
     flag = true;
     break;
    }else if(sum>=31){
     break;
    }
   }

   if(flag){
    cout << i+1 << endl;
   }
  }
 }

 return 0;
}

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

int search(string s[]) {
  int count = 0;
  int t = 0;
  for (int i = 0; ; i++) {
    if (s[i].size() > 5) continue;
    int start = i;
    for (int j = i; ; j++) {
      t += s[j].size();
      if (count == 0 || count == 2) {
	if (t == 5) {
	  count++;
	  t = 0;
	} else if (t > 5) {
	  count = 0;
	  t = 0;
	  break;
	} 
      } else {
	if (t == 7) {
	  count++;
	  if (count == 5) return start;
	  t = 0;
	} else if (t > 7) {
	  count = 0;
	  t = 0;
	  break;
	}
      }
    }
  }
}


int main() {
  while (true) {
    int n;
    cin >> n;
    if (n == 0) return 0;

    string s[n];
    for (int i = 0; i < n; i++)
      cin >> s[i];
    
    int ans = search(s);
    cout << ans + 1 << endl;
  }
}

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;
	  // cout << "OK" << endl;
	  break;
	}
	else if(sum>=31){
	  break;
	}
      }

      if(flg){
	cout << i+1 << endl;
	break;
      }
    }
    // cout << "Not OK" << endl;
  }

  return 0;
}

C++: #include<iostream>
#include<math.h>
#include<iomanip>
#include<string>
#include<fstream>
using namespace std;

int main(){
  //std::ifstream in("input.txt");
  //std::cin.rdbuf(in.rdbuf());
  int n;
  string inp;
  int set[5]={5,12,17,24,31};
  while(1){
    cin >> n;
    if(n==0)return 0;

    //int list[n];
    int shori[n];
    
    int size;
    int ans=0;
    //  int num=0;
    for(int i=0;i<n;i++){
      cin >> inp;
      if(ans==-1)continue;
      size=inp.size();
      shori[i]=0;
      //cout << list[i] << endl;
      for(int j=0;j<=i;j++){
	if(shori[j]==-1)continue;
       
        for(int l=0;l<5;l++){
	  if(shori[j]<set[l]){
	    if(size<=set[l]-shori[j]){
	      shori[j]+=size;
	      break;
	    }else{
	      shori[j]=-1;
	    }
	  }
	}
	if(shori[j]==set[4]){
	  cout << j+1 << endl;
	  ans=-1;
	  break;
	}
      }
      
   
    }
 
  }
      
}

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

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

int main(){
    int n;
    while(cin >> n, n){
        int w[n];
        string s;
        for(int i = 0; i < n; i++){
            cin >> s;
            w[i] = s.length();
        }
        
        int ans;

        for(int i = 0; i < n; i++){
            int pos = 0, tmplen = 0;
            for(int j = i; j < n; j++){
                if(tmplen < a[pos]) tmplen += w[j];
                if(tmplen > a[pos]) break;
                if(tmplen == a[pos])    pos++, tmplen = 0;
                if(pos == 5){
                    ans = i;
                    break;
                }
            }
            if(pos == 5)    break;
        }

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