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;

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

bool check(vector<int> &wl, int l, int r) {
    int cnt = 0, k = 0;
    for (int i=l; i<r; ++i) {
        cnt += wl[i];
        if (cnt == ph[k]) {
            cnt = 0;
            k ++;
        }
    }
    return k == 5;
}

int main() {
    int n;
    while (cin >> n) {
        if (!n) break;
        vector<int> wl(n);
        for (int i=0; i<n; ++i) {
            string w;
            cin >> w;
            wl[i] = w.size();
        }
        
        int ans = -1;
        int i=0, len = 0;
        for (int j=1; j<=n; ++j) {
            len += wl[j-1];
            while (31 < len) {
                len -= wl[i];
                i++;
            }
            if (len == 31 && check(wl, i, j)) {
                ans = i+1;
                break;
            }
        }
        cout << ans << endl;
    }
    return 0;
}

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 = 0; 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<math.h>
#include<iomanip>
#include<string>
#include<fstream>
using namespace std;

int main(){
  std::ifstream in("test.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;
	      break;
	    }
	  }
	}
	if(shori[j]==set[4]){
	  cout << j+1 << endl;
	  ans=-1;
	  break;
	}
      }
      
   
    }
 
  }
      
}

C++: //
//  main.cpp
//  Short Phrase
//
//  Created by x15071xx on 2017/06/18.
//  Copyright ?? 2017??´ AIT. All rights reserved.
//

#include <iostream>
#include <vector>
#include <string>
#include <cstdio>

using namespace std;
int main(int argc, const char * argv[]) {
    
    while (1) {
        int n,i,j;
        vector<string> str;
        cin >> n;
        
        if (n == 0) {
            break;
        }
        
        string tmp;
        for (i = 0; i < n; i++) {
            
            cin >> tmp;
            str.push_back(tmp);
            
        }
        
        for (i = 0; i < n; i++) {
            int flag = 0;
            j = i;
            int numsum = 0;
            while (1) {
                if (flag == -1) {
                    break;
                }
                
                if (flag == 5) {
                    cout << i+1 << endl;
                    break;
                }
                
                
                numsum+=str[i+j].length();
                
//                if (i == 5) {
//                    cout << numsum << str[i+j] <<endl;
//                }
                if (flag == 0 || flag == 2) {
                    
                    if (numsum > 5) {
                        flag = -1;
                    } else if (numsum < 5){
                        j++;
                    } else if (numsum == 5) {
                        flag++;
                        numsum = 0;
                        j++;
                    }
                } else {
                    if (numsum > 7) {
                        flag = -1;
                    } else if (numsum < 7) {
                        j++;
                    } else if (numsum == 7) {
                        flag++;
                        numsum = 0;
                        j++;
                    }
                }
            }
            
            if (flag == 5) {
                break;
            }
        }
        
    }
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
 
int main()
{
  int n;
  string w[40];
  int lengths[] = {5, 7, 5, 7, 7};
 
  while(cin >> n, n) {
    for(int i = 0; i < n; i++) {
      cin >> w[i];
    }
    for(int i = 4; i < n; i++) {
      int beforreadidx = 4, len = 0;
      for(int j = i; j >= 0; j--) {
        len += w[j].length();
        if(lengths[beforreadidx] == len) {
          len = 0;
          beforreadidx--;
          if(beforreadidx == -1) {
            cout << j + 1 << endl;
            break;
          }
        }
      }
      if(beforreadidx == -1) break;
    }
  }
  return(0);
 
}