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<iostream>
#include<string>
#include<algorithm>
using namespace std;
int len[50];
int d[5]={5,7,5,7,7};
int main(){
	int n;
	string s;
	while(true){
	cin>>n;
	if(n==0)break;
	for(int i=0;i<n;i++){
		cin>>s;
		len[i]=s.size();
	}
	int ans=100000;
	for(int i=0;i<n;i++){
		int cnt=0;
		int set=0;
		int j=i;
		bool ok=true;
		while(true){
			cnt+=len[j];
			if(cnt==d[set]){
				cnt=0;
				set++;
				if(set==5)break;
			}
			if(cnt>d[set]){
				ok=false;
				break;
			}
			j++;
			if(j==n){
				ok=false;
				break;
			}
		}
		if(ok){
			ans=min(ans,i+1);
		}
	}
	cout<<ans<<endl;
	}
	return 0;
}

C++: 
#include <iostream>

using namespace std;

int main()
{
    int n;
    while (cin >> n, n)
    {
        int w[n] = {0};
        for (int i = 0; i < n; i++)
        {
            string s;
            cin >> s;
            w[i] = s.size();
        }
        bool clear = false;
        int ans = 0;
        for (int i = 0; i < n && !clear; i++)
        {
            int phrase = 0;
            int tmp = 0;
            for (int j = i; j < n; j++)
            {
                tmp += w[j];
                if (phrase == 0 || phrase == 2)
                {
                    if (tmp == 5)
                    {
                        phrase++;
                        tmp = 0;
                    }
                    else if (tmp > 5)
                    {
                        break;
                    }
                }
                else
                {
                    if (tmp == 7)
                    {
                        if (phrase == 4)
                        {
                            clear = true;
                            ans = i + 1;
                            break;
                        }
                        else
                        {
                            phrase++;
                            tmp = 0;
                        }
                    }
                    else if (tmp > 7)
                    {
                        break;
                    }
                }
            }
        }
        cout << ans << endl;
    }
}

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

int main(){

  int len[5] = {5,7,5,7,7};
  int n, i;
  string str[41];
  while(cin >> n, n){
    for(i = 0; i < n; i++){
      cin >> str[i];
    }
    for(i = 0; i < n; i++){
      int sum = 0, idx = 0, flag = 0;
      for(int j = i; j < n; j++){
        sum += str[j].size();
        if(len[idx] == sum){
          sum = 0;
          idx++;
        }else if(len[idx] < sum){
          break;
        }
        if(idx == 5){
          flag = 1;
          break;
        }
      }
      if(flag){
        cout << i + 1 << endl;
        break;
      }
    }
  }
  return 0;
}

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int64 n;
	int64 num[5] = {5, 7, 5, 7, 7};
	while (cin >> n && n) {
		vector<int64> a(n);
		REP(i, n) {
			string s;
			cin >> s;
			a[i] = s.size();
		}
		int64 res = -1;
		REP(i, n) {
			int64 s = 0, idx = 0;
			FOR(j, i, n) {
				s += a[j];
				if (num[idx] == s) idx++, s = 0;
				if (idx == 5) break;
				if (num[idx] < s) break;
			}
			if (idx == 5) {
				res = i;
				break;
			}
		}
		cout << res+1 << endl;
	}
}

C++: #include<iostream>
#define f(X) for(c=0;c<X;c+=v[p++]);if(c-X)continue;
using namespace std;main(){for(int n,v[50],s,p,c;cin>>n,n;){string t;for(s=0;s<n;)cin>>t,v[++s]=t.size();for(s=p=1;p=++s;){f(5)f(7)f(5)f(7)f(7)cout<<s<<endl;p=0;}}}

C++: #include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>

using namespace std;

int main() {
  int n;
  const int tank[] = {5, 7, 5, 7, 7};
  while (cin >> n && n) {
    vector<int> w(n);
    for (int i = 0; i < n; i++) {
      string ww;
      cin >> ww;
      w[i] = ww.length();
    }
    int ans = -1;

    for (int i = 0; i < n; i++) {  //??????????????°?????????????????????
      int tmp = 0;
      int cnt = 0;
      for (int j = i; j < n; j++) {
        tmp += w[j];
        //cerr << tmp << " ";
        if (tmp < tank[cnt]) {
          //?¶???????????????§?????????????¬???????????????????
        } else if (tmp == tank[cnt]) {
          //????????????????????§?¬???????????????????
          tmp = 0;
          cnt++;
          if (cnt == 5) {
            // 57577????????£???
            ans = i + 1;
            goto FIN;
          }

        } else {
          //??¢???????????§??±???
          break;
        }
      }
      //cerr << endl;
    }

  FIN:
    cout << ans << endl;
  }
  return 0;
}

C++: #include "bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = int(b) - 1; i >= (int)(a); --i)
using pii = pair<int, int>;
using vi = vector<int>;

int solve(int n) {
	vi a(n);
	rep(i, 0, n) {
		string s;
		cin >> s;
		a[i] = s.size();
	}

	const vi seq = { 5, 7, 5, 7, 7 };
	rep(i, 0, n) {
		int s = 0;
		int idx = 0;
		bool ng = false;
		rep(j, i, n) {
			s += a[j];
			if (s == seq[idx]) {
				s = 0;
				idx++;
				if (idx == seq.size())break;
			}
			else if (s > seq[idx]) {
				ng = true;
				break;
			}
		}
		if (!ng) {
			return i + 1;
		}
	}
	return -1;
}

signed main() {
	while (1) {
		int n;
		cin >> n;
		if (n == 0) break;
		cout << solve(n) << endl;
	}
}