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<algorithm>
#include<string>
using namespace std;
int n;
string a[10000];
int as[100000];
int ok[5]={5,7,5,7,7};
bool check1(int a){
  int cnt=0;
  int tmp=0;

  for(int i=a;i<n;i++){
    //cout<<i<<" "<<tmp<<endl;
    tmp+=as[i];
      if(tmp==ok[cnt]){
        tmp=0;
        cnt++;
        if(cnt==5)return true;
      }
      //else if(tmp<ok[cnt])tmp+=as[i];
      else if(tmp>ok[cnt]){
        return false;
      }
  }
  //cout<<a<<" ok"<<endl;
  return false;
}

bool check2(int a){
  int cnt=0;
  int tmp=0;
  for(int i=a;i>=0;i--){
    tmp+=as[i];
    if(tmp==ok[cnt]){
      tmp=0;
      cnt++;
      if(cnt==5)return true;
    }
    else if(tmp>ok[cnt])return false;
  }
  return false;
}
int main(){

  while(cin>>n,n){
    for(int i=0;i<n;i++){
      cin>>a[i];
      as[i]=a[i].size();
    }
    int ans1=10000,ans2=10000;
    for(int i=0;i<n;i++){
      if(check1(i)){
        ans1=i;
        break;
      }
  }

  for(int i=n-1;i>=0;i--){
    if(check2(i))ans2=i;
  }
  //cout<<ans1<<endl;
  if(ans1<ans2)cout<<ans1+1<<endl;
  else cout<<ans2+1<<endl;
}
  return 0;
}

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

int len[] = {5, 7, 5, 7, 7};
std::vector< std::string > w(40);

bool check(int start, int n) {
    int i = start, k;
    for(k = 0; k < 5; ++k) {
        int rest = len[k];

        if(i >= n) return false;
        while(i < n && rest > 0) {
            rest -= w[i].length();
            ++i;
        }
        if(rest < 0) {
            return false;
        }
    }
    return true;
}

int main() {
    int n;
    int i;
    while(std::cin >> n, n != 0) {
        for(i = 0; i < n; ++i) {
            std::cin >> w[i];
        }

        for(i = 0; i < n; ++i) {
            if(check(i, n)) {
                std::cout << i + 1 << std::endl;
                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 = 0;
            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 <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FOREQ(i, a, b) for (int i = (a); i <= (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPEQ(i, n) FOREQ(i, 0, n)
#define ALL(c) (c).begin(), (c).end()

template <typename T> inline int size(const T& x) { return x.size(); }

bool is_tanka(const vector<string>& words, int offset) {
    static const int TANKA[] = {5, 7, 5, 7, 7};

    int curr_idx = 0, curr_len = 0;
    FOR(i, offset, size(words)) {
        curr_len += size(words[i]);
        if (curr_len > TANKA[curr_idx])
            return false;
        if (curr_len == TANKA[curr_idx]) {
            curr_idx++;
            curr_len = 0;
            if (curr_idx == 5)
                return true;
        }
    }
    return false;
}

int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);

    int n;
    while (cin >> n, n) {
        vector<string> words(n);
        REP(i, n) cin >> words[i];

        REP(offset, n) {
            if (is_tanka(words, offset)) {
                cout << offset+1 << endl;
                break;
            }
        }
    }
}