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;
#define rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++)

int main()
{
    vector<int> A = {5, 7, 5, 7, 7};
    while (true)
    {
        int N;
        cin >> N;
        if(N == 0)return 0;

        vector<int> S(N);
        rep(i, N)
        {
            string tmp;
            cin >> tmp;
            S[i] = tmp.size();
        }

        rep(i, N)
        {
            int now = i;
            bool flag = true;
            rep(j, 5)
            {
                int sum = 0;
                while(true)
                {
                    sum += S[now];
                    now++;
                    if(A[j] < sum)
                    {
                        flag = false;
                        break;
                    }
                    else if (sum == A[j]) {
                        break;
                    }
                    
                }
                if (!flag) {
                    break;
                }
                
            }

            if (flag) {
                cout << (i + 1) << "\n";
                break;
            }
            
        }
    }
}

C++: // 2018/01/05 Tazoe

#include <iostream>
#include <string>
using namespace std;

int main()
{
	while(true){
		int n;
		cin >> n;

		if(n==0)
			break;

		int len[40];			// 単語の長さ
		for(int i=0; i<n; i++){
			string w;
			cin >> w;

			len[i] = w.size();
		}

		for(int i=0; i<n; i++){
			bool flg = false;		// 見つかったフラグ
			int sta = 0;			// 区切り
			int sum = 0;			// 文字数の合計

			for(int j=i; j<n; j++){
				sum += len[j];

				// 区切りなら
				if(sum==5 || sum==12 || sum==17 || sum==24 || sum==31){
					sta++;
				}

				if(sta==5){			// 見つかった
					flg = true;
					break;
				}
				else if(sum>=31){		// 見つからなかった
					break;
				}
			}

			if(flg){			// 見つかったら
				cout << i+1 << endl;
				break;
			}
		}
	}

	return 0;
}

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

string s;
int n, ans;

int main() {
  int i, j;
  while(1) {
    cin >> n;
    if(n == 0) break;
    vector<int> v;
    for(i = 0; i < n; ++i) {
      cin >> s;
      v.push_back(s.size());
    }
    ans = 0;
    for(i = 0; i < n; ++i) {
      if(ans != 0) break;
      int now = 0, ch = 0;
      for(j = i; j < n; ++j) {
        now += v[j];
        if(now == 5 || now == 12 || now == 17 || now == 24 || now == 31) ++ch;
        if(now > 31) break;
      }
      if(ch == 5) ans = ++i;
    }
    cout << ans << endl;
  }
  return 0;
}

C++: #include<iostream>

using namespace std;

signed main(){

   while(1){
      int n;
      cin>> n;
      if(!n) break;

      int w[n];
      for(int i=0; i<n; i++){
         string s;
         cin>> s;
         w[i]=s.size();
      }
      int b[]={5, 7, 5, 7, 7};
      for(int i=0; i<n; i++){
         int a=0, p=0;
         for(int j=i; j<n; j++){
            a+=w[j];
            if(a>b[p]){
               goto turai;
            }else if(a==b[p]){
               p++;
               a=0;
            }
         }
         cout<< i+1<< endl;
         return 0;
         turai:;
      }

   }

   return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
using namespace std;;

int main(){
    while(1){
        int n;
        cin >> n;
        if(n == 0) break;
        vector<int> a(n);
        rep(i, 0, n){
            string s;
            cin >> s;
            a[i] = s.size();
        }
        int d[6] = {5, 7, 5, 7, 7, 114514};
        int ans = -1;
        rep(i, 0, n){
            int now = 0;
            int tmp = 0;
            rep(j, i, n){
                if(a[j] + tmp < d[now]){
                    tmp += a[j];
                }else if(a[j] + tmp == d[now]){
                    now++;
                    tmp = 0;
                }else{
                    break;
                }
                // cout << now << " " << tmp << endl;
                if(now == 5){
                    cout << i + 1 << endl;
                    i = n;
                    break;
                }
            }
        }
    }
}

C++: #include<bits/stdc++.h>
using namespace std;
int f[]={5,7,5,7,7};
int n;
int t[50];
string str;
 
int solve(){
  for(int i=0;i<n;i++){
    int a=i,j;
    for(j=0;j<5;j++){
      int b=0;
      while(b<f[j])b+=t[a++];
      if(b>f[j])break;
    }
    if(j==5)return i;
  }
  return 0;
}
 
int main(){
  while(1){
    cin>>n;
    if(n==0)break;
    for(int i=0;i<n;i++){
      cin>>str;
      t[i]=str.size();
    }
    cout<<solve()+1<<endl;
  }
  return 0;
}

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

int main(){
while(1){
 int n;
 cin>>n;

 if(n==0)break;
 
 int  len[40];
 for(int  i=0;i<n;i++){
	string w;
	cin>>w;

	len[i]=w.size();
 }

 for(int i=0;i<n;i++){
	bool flg=false;
	int sta=0;
	int sum=0;

	for(int j=i;j<n;j++){
		sum+=len[j];

		if(sum==5||sum==12||sum==17||sum==24||sum==31){
			sta++;
		}
		if(sta==5){
			flg=true;
			break;
		}else if(sum>=31){
			break;
		}
	}
 	if(flg){
		cout<<i+1<<endl;
		break;
	}
 }
}
return 0;
}

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

int main() {

  while(1) {
    bool end = false;

    int n;
    cin >> n;
    if(n == 0) return 0;
    int w[n];
    for(int i = 0; i < n; i++) {
      string s;
      cin >> s;
      w[i] = s.size();
    }

    // for(int i = 0; i < n; i++) cout << w[i] << " ";
    // cout << endl;
    int tanku[5] = {5, 7, 5, 7, 7};
    for(int i = 0; i < n; i++) {
      if(end) break;
      int k = 0;
      for(int j = 0; j < 5; j++) {
        if(end) break;
        int sum = 0;
        while(sum < tanku[j]) {
          sum += w[i+k];
          k++;
        }
        // cout << sum << " :" << j << " ";
        if(sum != tanku[j]) break;
        if(j == 4) {
          cout << i+1 << endl;
          end = true;
        }
      }
    }
  }
}