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 <algorithm>
#include <array>
#include <iostream>
#include <string>

std::string words[40];
const std::array<int, 5> N57577 = { 5, 7, 5, 7, 7 };

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

		if (n == 0) return 0;

		for (int i = 0; i < n; i++) {
			std::cin >> words[i];
		}

		for (int i = 0; i < n; i++) {
			int j = i;
			bool valid_tanka = true;

			for (int wn : N57577) {
				int count = 0;
				while (j < n) {
					count += words[j++].size();
					if (count >= wn) break;
				}
				if (count != wn) {
					valid_tanka = false;
					break;
				}
			}
			
			if (valid_tanka) {
				std::cout << (i + 1) << std::endl;
				break;
			}
		}
	}
}

C++: #include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define LOOP(i,x,n) for(int i=x;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define MP make_pair
#define FR first
#define SC second
#define int long long
using namespace std;
const int MOD=1000000007;
const int INF=1000000009;


signed main(){
  int n;
  while(cin>>n,n){
    vector<int> v(n);
    REP(i,n){
      string s;cin>>s;
      v[i]=s.size();
    }
    REP(i,n){
      int p=i;
      int tmp=v[p];
      while(tmp<5){
        p++;tmp+=v[p];
      }
      if(tmp==5){
        p++;
        tmp=v[p];
        while(tmp<7){
          p++;tmp+=v[p];
        }
        if(tmp==7){
          p++;
          tmp=v[p];
          while(tmp<5){
            p++;tmp+=v[p];
          }
          if(tmp==5){
            p++;
            tmp=v[p];
            while(tmp<7){
              p++;tmp+=v[p];
            }
            if(tmp==7){
              p++;
              tmp=v[p];
              while(tmp<7){
                p++;tmp+=v[p];
              }
              if(tmp==7){
                p++;
                cout<<i+1<<endl;
                break;
              }
            }
          }
        }
      }
    }
  }
  return 0;
}

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

bool check(int start, const vector<string> &words) {
	const array<int, 5> num{{5, 7, 5, 7, 7}};

	int idx = 0;
	int sum = 0;
	for(int i = start; i < words.size(); ++i) {
		sum += words[i].size();

		if(sum == num[idx]) {
			if(++idx == 5) return true;
			sum = 0;
		}
		else if(sum > num[idx]) {
			return false;
		}
	}
	return false;
}

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

	for(int n; cin >> n && n;) {
		vector<string> words(n);
		for(auto &e : words) cin >> e;

		for(int i = 0; i < n; ++i) {
			if(check(i, words)) {
				cout << i + 1 << endl;
				break;
			}
		}
	}

	return EXIT_SUCCESS;
}

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

C++: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
#define ceil(a, b) a / b + !!(a % b)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)

int main() {
    int q;
    while (cin >> q && q) {
        vector<string> v;
        while (q--) {string w; cin >> w; v.push_back(w);}
        int c[] = {5, 7, 5, 7, 7};
        int now = 0;
        int sum = 0;
        int flg = 0;
        rep(i, v.size()) {
            rrep(j, i, v.size()) {
                sum += v[j].size();
                //cout << sum << endl;
                if (sum == c[now]) {
                    sum = 0;
                    now++;
                    if (now == 5) {
                        cout << i + 1 << endl;
                        flg = 1;
                        break;
                    }
                } else if (sum > c[now]) {
                    now = 0;
                    sum = 0;
                    break;
                }
            }
            if (flg) break;
        }
    }
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

const ll MOD = ll(1e9 + 7);
const ll LLINF = LLONG_MAX;
const int IINF = 99999999;
const int MAX_N = int(1e5) + 5;
const double EPS = 1e-8;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)

int main() {
    int ls[] = {5,7,5,7,7};
    while(1){
        int n,w[40];
        cin >> n;
        if(n==0)break;
        for(int i=0;i<n;i++){
            string s;
            cin >> s;
            w[i] = s.size();
        }
        for(int i=0;i<n;i++){
            int k=0,sum=0;
            for(int j=i;j<n;j++){
                if(sum < ls[k])sum += w[j];
                if(sum>ls[k])break;
                if(sum == ls[k]){
                    k++;
                    sum = 0;
                }
                if(k==5)break;
            }
            if(k==5){
                cout << i+1 << endl;
                break;
            }
        }
    }
    return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
int n,w[10000];
string str,kari;
int main(){

  cin >> n;
  while( n != 0){
    fill_n(w,10000,0);
    w[0] = 1;

    for(int i = 0;i < n;i++){
      cin >> kari;
      if(i != 0) w[str.size()] = i+1;
      str += kari;
    }
    
    for(int i = 0;i <= str.size()-31;i++){
      if(w[i]!=0&&w[i+5]!=0&&w[i+12]!=0&&w[i+17]!=0&&w[i+24]!=0){
	if(i+31 == str.size() || w[i+31] != 0){
	  cout << w[i] << endl;
	  break;
	}
      }
    }
    cin >> n;
  }

  return (0);
}

C++: #include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
#define D10 fixed<<setprecision(10)
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-12;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/

int main()
{
	cin.sync_with_stdio(false);
	int n;
	int a[] = { 5,7,5,7,7 };
	while (cin >> n, n)
	{
		vs v(n);
		REP(i, n) cin >> v[i];
		REP(i, n)
		{
			int p = 0, tmp = 0;
			bool f = true;
			FOR(j, i, n)
			{
				if (p == 5) break;
				tmp += v[j].size();
				if (tmp == a[p])
				{
					tmp = 0; p++;
				}
				else if (tmp > a[p])
				{
					f = false;
					break;
				}
			}
			if (f)
			{
				cout << i + 1 << endl;
				break;
			}
		}
	}
	return 0;
}