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<algorithm>
#include<string.h>
#include<stdio.h>
using namespace std;

int main(){
  int n,wa[41],flag[5];
  char s[40][20];
  while(1){
    cin>>n;
    if(n==0)
      break;
    wa[0]=0;
    for(int i=0;i<n;i++){
      scanf("%s",s[i]);
      wa[i+1]=strlen(s[i])+wa[i];
    }
    for(int i=0;i<n-1;i++){
      for(int j=0;j<5;j++)
        flag[j]=0;
      for(int k=i;k<=n;k++){
        if(wa[k]-wa[i]==5)
          flag[0]=1;
        else if(wa[k]-wa[i]==12)
          flag[1]=1;
        else if(wa[k]-wa[i]==17)
          flag[2]=1;
        else if(wa[k]-wa[i]==24)
          flag[3]=1;
        else if(wa[k]-wa[i]==31)
          flag[4]=1;
      }
      if(flag[0]==1&&flag[1]==1&&flag[2]==1&&flag[3]==1&&flag[4]==1){
        cout<<i+1<<endl;
        break;
      }
    }
  }
}

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

using namespace std;

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

// container util
#define all(x) (x).begin(), (x).end()

// debug
#define dump(x) cerr << #x << " = " << (x) << endl;
#define debug(x)                                         \
  cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
       << " " << __FILE__ << endl;

// typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

// constant
const int MOD = (int)1e9 + 7;
const int INF = (int)1e18;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};

// conversion
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
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;
}
//

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

  int n;
  while (cin >> n, n) {
    string w[44];
    rep(i, n) cin >> w[i];

    int c[6] = {5, 7, 5, 7, 7};
    int cnt = 0, len = 0, ans = -1;
    bool flag = false;
    rep(j, n) {
      cnt = 0, len = 0;
      FOR(i, j, n) {
        len += (int)w[i].size();
        if (len == c[cnt]) {
          cnt++;
          len = 0;
        } else if (c[cnt] < len) {
          break;
        }

        if (cnt == 5) {
          ans = j + 1;
          flag = true;
          break;
        }
      }
      if (flag) break;
    }
    cout << ans << "\n";
  }

  return 0;
}

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

int main(){
    int n;
    while(cin>>n,n){
        vector<int> V(n);
        for(auto &v:V){
            string s;
            cin>>s;
            v=s.size();
        }
        for(int i=0;i<n;i++){
            int cnt=0;
            int ans=i+1;
            int j=i;
            while(cnt<5) cnt+=V[j++];
            if(cnt!=5) continue;
            cnt=0;
            while(cnt<7) cnt+=V[j++];
            if(cnt!=7) continue;
            cnt=0;
            while(cnt<5) cnt+=V[j++];
            if(cnt!=5) continue;
            cnt=0;
            while(cnt<7) cnt+=V[j++];
            if(cnt!=7) continue;
            cnt=0;
            while(cnt<7) cnt+=V[j++];
            if(cnt==7){
                cout<<ans<<endl;
                break;
            }
        }
    }

    return 0;
}

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

typedef long long ll;
typedef pair<int,int> P;

int n;
int cnt[101];
int cal[5]={5,7,5,7,7,};

int main(void){
	while(1){
		scanf("%d",&n);
		if(n==0)break;
		for(int i=0;i<n;i++){
			string str;
			cin >> str;
			cnt[i]=str.size();
		}
		int res=-1;
		for(int i=0;i<n;i++){
			if(res!=-1)continue;
			int now=0;
			int len=0;
			for(int j=i;j<n;j++){
				len+=cnt[j];
				if(len==cal[now]){
					now++;
					len=0;
				}else if(len>cal[now]){
					break;
				}
				if(now==5){
					res=i;
					break;
				}
			}
		}
		printf("%d\n",res+1);
	}
	return 0;
}

C++: #include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<int, lint> pil;
typedef pair<lint, lint> pll;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod*mod;
constexpr int MAX = 100010;

int f(vector<string> &s, int cur, int L){
    int len = 0, ret = 0;
    while(cur < s.size() && len < L){
        len += s[cur].size();
        ++cur;
        ++ret;
    }
    return len == L ? ret : -1;
}

int main(){
    int n;
    while(scanf("%d", &n) && n){
        vector<string> s(n);
        for(auto &i: s) cin >> i;
        vector<int> a(n), b(n);
        rep(i, n){
            a[i] = f(s, i, 5);
            b[i] = f(s, i, 7);
        }
        int ans;
        rep(i, n){
            int cur = i;
            if(a[cur] < 0) continue;
            cur += a[cur];
            if(b[cur] < 0) continue;
            cur += b[cur];
            if(a[cur] < 0) continue;
            cur += a[cur];
            if(b[cur] < 0) continue;
            cur += b[cur];
            if(b[cur] < 0) continue;
            cur += b[cur];
            ans = i;
            break;
        }
        printf("%d\n", ans+1);
    }
}

C++: #include <bits/stdc++.h>
using namespace std;
bool check575(vector<int> &v,int pos) {
    int sum;
    sum=0;
    while(pos<v.size()&&sum<5) sum+=v[pos++];
    if(sum!=5) return 0;
    sum=0;
    while(pos<v.size()&&sum<7) sum+=v[pos++];
    if(sum!=7) return 0;
    sum=0;
    while(pos<v.size()&&sum<5) sum+=v[pos++];
    if(sum!=5) return 0;
    sum=0;
    while(pos<v.size()&&sum<7) sum+=v[pos++];
    if(sum!=7) return 0;
    sum=0;
    while(pos<v.size()&&sum<7) sum+=v[pos++];
    if(sum!=7) return 0;
    return 1;
}
int main() {
    int n;
    string w;
    while(cin>>n,n) {
        vector<int> v;
        for(int i=0;i<n;i++) {
            cin>>w;
            v.push_back(w.size());
        }
        for(int i=0;i<v.size();i++) {
            if(check575(v,i)) {
                printf("%d\n",i+1);
                break;
            }
        }
    }
}