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(){
	int n;
	while(cin >> n and n){
		vector<int> v;
		for(int i = 0 ; i < n ; i++){
			string s;
			cin >> s;
			v.push_back(s.size());
		}
		for(int i = 0 ; i < n ; i++){
			int j = i;
			int s = 0;
			int f = 1;
			while( j < n and s < 5 ) s += v[j++];
			
			if( s != 5 ) f = 0;
			s = 0;
			while( j < n and s <7 ) s += v[j++];
			if( s != 7 ) f = 0;
			s = 0;
			while( j < n and s < 5 ) s += v[j++];
			if( s != 5 ) f = 0;
			s = 0;
			while( j < n and s < 7 ) s += v[j++];
			if( s != 7 ) f = 0;
			s = 0;
			
			while( j < n and s < 7) s += v[j++];
			if( s != 7 ) f = 0;
			
			if( f ){
				cout << i+1 << endl;
				break;
			}
		}
	}
}

C++: #pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using ull=unsigned long long int;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
while(1){
  int n;
  cin>>n;
  if(n==0)return 0;
  V<ll> a(n);
  for(int i=0;i<n;i++){
    string s;
    cin>>s;
    a[i]=(ll)s.size();
  }
  for(int i=0;i<n;i++){
    ll sum=0;int ind=i;
    while(ind<n&&sum<5)sum+=a[ind++];
    if(sum!=5)continue;
    sum=0;
    while(ind<n&&sum<7)sum+=a[ind++];
    if(sum!=7)continue;
    sum=0;
    while(ind<n&&sum<5)sum+=a[ind++];
    if(sum!=5)continue;
    sum=0;
    while(ind<n&&sum<7)sum+=a[ind++];
    if(sum!=7)continue;
    sum=0;
     while(ind<n&&sum<7)sum+=a[ind++];
    if(sum!=7)continue;
    cout<<i+1<<"\n";
    break;
  }
}
}

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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF = 1e9;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

int main()
{
    int N;
    vector<int> num = {5, 7, 5, 7, 7};

    while (cin >> N, N) {
        vector<string> S(N);
        rep(i, N) cin >> S[i];

        rep(i, N) {
            int tmp_len = 0;
            int num_idx = 0;
            bool ok = false;
            
            for (int j=i; j<N; j++) {
                if (tmp_len < num[num_idx]) {
                    tmp_len += S[j].size();
                }

                if (tmp_len == num[num_idx]) {
                    num_idx++;
                    tmp_len = 0;
                } else if (tmp_len > num[num_idx]) {
                    break;
                }

                if (num_idx == 5) {
                    ok = true;
                    break;
                }
            }
            if (ok) {
                cout << i+1 << endl;
                break;
            }
        }
    }
}

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

const int MAX_N=41;

int n,sum,t,ok; string w;
vector<int> words(MAX_N);
vector<int> each={5,7,5,7,7};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(cin >> n,n){
        for (int i=0;i<n;++i){
            cin >> w; words[i]=(int)w.size();
        }
        for (int i=0;i<n;++i){
            t=i,ok=1;
            for (int j=0;j<5;++j){
                sum=0;
                for (int k=t;k<n;++k){
                    sum+=words[k];
                    if (sum==each[j]){t=k+1; break;}
                    if (sum>each[j]){ok=0; break;}
                }
            }
            if (ok){
                cout << i+1 << '\n';
                break;
            }
        }
    }
}

C++: #include<bits/stdc++.h>
main(){for(char s[50],i,j,p,q;p=atoi(gets(s));printf("%d\n",i)){for(i=0;i<p;s[i++]=strlen(gets(s+i)));for(i=j=0;j<7;)for(p=i++,j=q=1;q>0;)for(q=j++>5?0:j-2&&j-4?8:6;q>1;q-=s[p++]);}}

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

int main(){
    while(true){
        int n;
        cin >> n;
        if(n == 0){
            break;
        }
        int phraseCount[] = {5, 7, 5, 7, 7};
        int currentPhraseIndex = 0;
        int currentPhraseCount = 0;
        string phrases[n];
        for(int i = 0; i < n; i++){
            cin >> phrases[i];
        }
        bool isFinished = false;
        for(int k = 0; k < n; k++){
        for(int i = k; i < n; i++){
            string s;
            s = phrases[i];
            currentPhraseCount += s.length();
            if(currentPhraseCount == phraseCount[currentPhraseIndex]){
                currentPhraseIndex++;
                currentPhraseCount = 0;
                if(currentPhraseIndex == 5){
                    cout << k + 1 << endl;
                    isFinished = true;
                    break;
                }
            }else if(currentPhraseCount > phraseCount[currentPhraseIndex]){
                currentPhraseIndex = 0;
                currentPhraseCount = 0;
                break;
            }
        }
        if(isFinished){
        	break;
        }
        }
    }
    return 0;
}

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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  while (cin >> n, n) {
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
      string w;
      cin >> w;
      a[i] = w.size();
    }
    for (int i = 0; i < n; ++i) {
      int s = 0;
      set<int> se;
      for (int j = i; j < n; ++j) {
        se.insert(s += a[j]);
      }
      if (se.count(5) and se.count(12) and se.count(17) and se.count(24) and se.count(31)) {
        cout << i + 1 << '\n';
        break;
      }
    }
  }
}

C++: #include<bits/stdc++.h>
using namespace std;
 
int main()
{
  int n;
  string w[40];
  int lengths[] = {5, 7, 5, 7, 7};
 
  while(cin >> n, n) {
    for(int i = 0; i < n; i++) {
      cin >> w[i];
    }
    for(int i = 4; i < n; i++) {
      int beforreadidx = 4, len = 0;
      for(int j = i; j >= 0; j--) {
        len += w[j].length();
        if(lengths[beforreadidx] == len) {
          len = 0;
          beforreadidx--;
          if(beforreadidx == -1) {
            cout << j + 1 << endl;
            break;
          }
        }
      }
      if(beforreadidx == -1) break;
    }
  }
  return(0);
 
}