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 int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;

bool tanku(const V& a, int s) {
    const V li = {5, 7, 5, 7, 7};
    int w = 0, p = 0;
    for (int i = s; p < 5; i++) {
        w += a[i];
        if (w == li[p]) {
            w = 0;
            p++;
        } else if (w > li[p]) {
            return false;
        }
    }
    return true;
}

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

    int n;
    while (cin >> n, n) {
        V a;
        rep(i, n) {
            string s;
            cin >> s;
            a.emplace_back(s.size());
        }

        rep(i, n) {
            if (tanku(a, i)) {
                cout << i + 1 << endl;
                break;
            }
        }
    }
}

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<iostream>
#include<vector>
#include<string>
#include<numeric>

using namespace std;

bool ok(vector<int> v, int start) {
    int nums[5] = { 5, 7, 5, 7, 7 };
    int i = 0;
    auto itr = v.begin() + start;
    while (i < 5) {
        for (; itr != v.end(); ++itr) {
            if (*itr == nums[i]) {
                i++;
                continue;
            }
            else if (*itr >= nums[i]) {
                return false;
            }
            else {
                nums[i] -= *itr;
            }
        }
        return true;
    }
}

int main()
{
    int n;
    while (true) {
        cin >> n;
        if (n == 0) {
            return 0;
        }

        vector<int> v(n);
        for (int i = 0; i < n; i++) {
            string str;
            cin >> str;
            v[i] = str.size();
        }

        int start = 0, tail = 0;
        int sum = 0;
        while (true) {
            if (tail == n) {
                cout << 0 << endl;
                break;
            }

            while (tail < n && sum < (5 + 7 + 5 + 7 + 7)) {
                tail++;
                sum = accumulate(v.begin() + start, v.begin() + tail, 0);
            }

            if (sum == (5 + 7 + 5 + 7 + 7)) {
                if (ok(v, start)) {
                    cout << start << endl;
                    break;
                }
                else {
                    start++;
                    sum = accumulate(v.begin() + start, v.begin() + tail, 0);
                }
            }
            while (sum > (5 + 7 + 5 + 7 + 7)) {
                start++;
                sum = accumulate(v.begin() + start, v.begin() + tail, 0);
            }
        }
    }
    return 0;
}

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

int main(){
  int n,a,b,c,d,e,j;
  string w[40];
  while(true){
    cin >> n;
    if(n == 0) break;

    for(int i = 0; i < n; i++){
      cin >> w[i];
    }
    //cout << "n="<<n << endl;
    for(int i = 0; i < n - 4; i++){
      //start w[i] 5 7 5 7 7
      //cout << i << "=i" <<endl;
      a = 5;
      b = 7;
      c = 5;
      d = 7;
      e = 7;

      int j=i;
      bool flag = true;
      while(flag ){//5

        if(a - w[j].size() == 0){j++; break;}
        else if(j >= n){flag = false;}
        else if(a - w[j].size() > 0){a-=w[j].size(); j++;}
        else {flag = false;}
      }
      //cout << j << endl;
      while(flag){//7

        if(b - w[j].size() == 0){j++; break;}
        else if(j >= n ){flag = false;}
        else if(b - w[j].size() > 0){b-=w[j].size(); j++;}
        else {flag = false;}
      }
      //cout << j << endl;
      while(flag){//5

        if(c - w[j].size() == 0){j++; break;}
        else if(j >= n){flag = false;}
        else if(c - w[j].size() > 0){c-=w[j].size(); j++;}
        else {flag = false;}
      }
      //cout << j << endl;
      while(flag){//7

        if(d - w[j].size() == 0){j++; break;}
        else if(j >= n){flag = false;}
        else if(d - w[j].size() > 0){d-=w[j].size(); j++;}
        else {flag = false;}

      }
      //cout <<  j << endl;
      while(flag){//7

        if(e - w[j].size() == 0){  j++; break;}
        else if(j >= n){flag = false;}
        else if(e - w[j].size() > 0){  e -= w[j].size(); j++;}
        else {flag = false;}
      }
      if(flag){
        cout << i+1 << endl;
        break;
      }
    }
  }

  return 0;

}

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

int s[]={5,7,5,7,7};

int main(){
    int n;
    while(cin>>n&&n!=0){
        vector<int> w(n);
        string tmp;
        for(int i=0;i<n;i++){
            cin >> tmp;
            w[i] = tmp.size();
        }
        for(int i=0;i<n;i++){
            int x=0;
            int y=0;
            for(int j=i;j<n;j++){
                x += w[j];
                if(x==s[y]){
                    if(y==4){
                        cout << i+1 << endl;
                        goto lll;
                    }
                    x = 0;
                    y++;
                }else if(x>s[y]){
                    break;
                }
            }
        }
        lll:;
    }
    return 0;
}

C++: #include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF (1e9+1)
//#define INF (1LL<<59)

int 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 now;
			int pos = i;
			
			int p[]={5,7,5,7,7};
			rep(j,5){
				now=0;
				while(now<p[j]){
					now+=v[pos++];
					if(now==p[j])break;
					if(now>p[j])goto next;
				}
			}
			cout<<i+1<<endl;
			break;
next:;
		}
	}
}