Go: // Short Phrase(短句)
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1601&lang=jp
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	for {
		n := nextInt(sc)
		if n == 0 {
			break
		}

		var words []string
		for i := 0; i < n; i++ {
			words = append(words, nextString(sc))
		}

		res := 0
		for i := 0; i < n; i++ {
			tmpWords := words[i:]
			ok := checkRule(tmpWords, 0)
			if ok {
				res = i + 1
				break
			}
		}

		fmt.Println(res)
	}
}

var rule = [5]int{5, 7, 5, 7, 7}

func checkRule(words []string, depth int) bool {
	var shortPhrase = ""
	var i = depth

	if depth == 5 {
		return true
	}

	for len(words) > 0 {
		shortPhrase += words[0]
		words = words[1:]

		if rule[i] == len(shortPhrase) {
			return checkRule(words, i+1) // 短句のルールを満たしたので次の文節へ
		} else if rule[i] < len(shortPhrase) {
			return false // 文節の語数オーバー
		}
	}

	return false // 文節を満たす単語が足りない
}

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func nextString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    string s;
    while (cin>>n) {
        if (n==0) {
            break;
        } else {
            std::deque<string> words;
            for (int i=0;i<n;i++) {
                cin>>s;
                words.emplace_back(s);
            }
            for (int j=0;j<words.size();j++) {
                std::deque<int> num{5,7,5,7,7};
                int itr=0;
                int now=j;
                while (itr<5) {
                    if (words[now].size()<=num[itr]) {
                        num[itr]-=words[now].size();
                        if (num[itr]==0) {
                            itr++;
                            now++;
                        } else if (num[itr]>0) {
                            now++;
                        } else {
                            break;
                        }
                    } else {
                        break;
                    }
                }
                if (itr==5) {
                    cout<<j+1<<endl;
                    break;
                }
            }
        }
    }
}

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

int main(){
    while(1){
        int n;
        cin >> n;
        if(n==0) break;

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

        for(int i=0; i<n; i++){
            int sp[5] = {5,7,5,7,7};
            int now = 0;
            for(int j=0; j<n; j++){
                sp[now] -= str[i+j].length();
                if(sp[now]<0) break;
                if(sp[now]==0) now++;
                if(now==5){
                    cout << i+1 << endl;
                    i=1e9;
                    break;
                }
            }
        }
    }   
    return 0;
}

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();
	}
}