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 <vector>
#include <string>
using namespace std;

int main() {

  int n;
  int check[5] = {5, 7, 5, 7, 7};
  int count;
  int tmp;
  int ans;

  bool found;
  
  while (1) {
  
    cin >> n;
    if (n == 0) break;

    vector<string> v(n);
    for (int i = 0; i < n; i++) cin >> v[i];

    for (int i = 0; i < n; i++) {
      
      ans = -1;
      count = 0;
      tmp   = 0;
      found = false;
      
      for (int j = i; j < n; j++) {

        //cout << "i: " << i << "  j:" << j << "  tmp: " << tmp << "  size: " << v[j].size() << "  count: " << count << endl;

        if (tmp + v[j].size() > check[count])
          break;

        else if (tmp + v[j].size() == check[count]) {
          count ++;
          tmp = 0;
        }
        else
          tmp += v[j].size();

        if (count == 5) {
          found = true;
          break;
        }
        if (found == true)
          break;
      }
      if (found == true) {
        ans = i + 1;
        break;
      }
    }
    cout << ans << endl;
  }
}

C++: #include<bits/stdc++.h>
#define endl '\n';
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr double INFD = 1e100;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
// ---------------------------------------------------------------------------


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin >> N;
    while(N != 0){
        vector<int> num(N);
        for(int i=0; i<N; i++){
            string S;
            cin >> S;
            num[i] = S.size();
        }
        vector<int> pos = {5,7,5,7,7};
        for(int i=0; i<N; i++){
            int now = 0;
            int sum = 0;
            bool did = false;
            for(int j=i; j<N; j++){
                if(sum+num[j] == pos[now]){
                    now++;
                    if(now == 5){
                        cout << i+1 << endl;
                        did = true;
                        break;
                    }
                    sum = 0;
                }else if(sum+num[j] < pos[now]){
                    sum += num[j];
                }else{
                    break;
                }
            }
            if(did) break;
        }
        cin >> N;
    }
    return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 10e9+9
#define EPS 1e-10
#define MAX_N 100100
#define MAX_M 100100

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

int n;
string s;
vector<string> vs;
int table[] = { 5, 7, 5, 7, 7 };

int main(){
	while (cin >> n&&n){
		REP(i, n){
			cin >> s;
			vs.push_back(s);
		}
		REP(i, vs.size()){
			string s;
			int pos = i, co = 0;
			bool f = 1;
			while (f){
				s += vs[pos];
				if (s.size() == table[co]){
					co++;
					s.clear();
				}
				else if (s.size() > table[co]){
					co = 0;
					f = 0;
					s.clear();
				}
				if (co == 5){
					cout << i + 1 << endl;
					break;
				}
				if (pos == vs.size() - 1)f = 0;
				pos++;
			}
			if (f)break;
		}
		vs.clear();
	}
}

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

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

int main() {

    while(1){

        int n;

        cin >> n;

        if(n==0) break;

        vector<string> w;

        for(int i=0; i<n; i++){
            string input;
            cin >> input;
            w.push_back(input);
        }

        int w_pos = 0;

        while(1){

            int w_itr = w_pos, nowp = 0, pcount = 0;

            while(1){
                if(w[w_itr].size() + pcount > phrase[nowp]){
                    nowp = -1;
                    break;
                }
                else if(w[w_itr].size() + pcount == phrase[nowp]){
                    nowp++;
                    if(nowp == 5){
                        break;
                    }
                    pcount = 0;
                }
                else{
                    pcount += w[w_itr].size();
                }
                w_itr++;
            }

            if(nowp == 5){
                break;
            }

            w_pos++;


        }

        cout << w_pos + 1 << endl;

    }

    return 0;
}