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<cstdio>
#include<cstring>

int n,len[40];
char word[11];

int solve(int pos) {
	int rest;
	rest = 5;
	while (rest > 0) {
		rest -= len[pos++];
		if (rest < 0)return 0;
	}
	rest = 7;
	while (rest > 0) {
		rest -= len[pos++];
		if (rest < 0)return 0;
	}
	rest = 5;
	while (rest > 0) {
		rest -= len[pos++];
		if (rest < 0)return 0;
	}
	rest = 7;
	while (rest > 0) {
		rest -= len[pos++];
		if (rest < 0)return 0;
	}
	rest = 7;
	while (rest > 0) {
			rest -= len[pos++];
			if (rest < 0) return 0;
	}
	return 1;
}

int main() {
	while (1) {
		scanf("%d\n", &n);
		if (n == 0)break;
		for (int i = 0; i < n; i++) {
			scanf("%s\n", word);
			len[i] = strlen(word);
		}
		for (int j = 0; j < n; j++) {
			if (solve(j)) {
				printf("%d\n", j + 1);
				break;
			}
		}
	}
}

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

template <class T>
void readVector(int n, vector<T> &v){
	for(int i=0; i<n; ++i){
		T t;
		cin >> t;
		v.push_back(t);
	}
}

int a[5] = {5, 12, 17, 24, 31};
void solve(int n){
	vector<string> v;
	readVector(n, v);
	for(int i=0; i<n; ++i){
		int cnt = 0;
		int flag = 0;
		for(int j=i; j<n; ++j){
			cnt += v[j].size();
			for(int k=0; k<5; ++k)
				if(cnt == a[k])
					flag += (1 << k);
		}
		if(flag == 31){
			cout << i+1 << "\n";
			return;
		}
	}
}

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	while(1){
		int n;
		cin >> n;
		if(n == 0) return 0;
		solve(n);
	}
}

C++: #include<bits/stdc++.h>
using namespace std;
 
#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false
 
typedef long long ll;
typedef pair<int, int> ii;

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

int main() {

	int n;
	while(cin >> n, n){
		vector<int> w(n);
		rep(i, n){
			string s;
			cin >> s;
			w[i] = s.size();
		}
		
		int ans = -1;
		rep(i, n){
			if(ans != -1) break;
			int pos = 0;
			int cnt = 0;
			REP(j, i, n){
				if(cnt + w[j] > phrase[pos]) break;
				else if(cnt + w[j] == phrase[pos]){
					pos++;
					cnt = 0;
				}
				else cnt += w[j];
				
				if(pos == 5) {
					ans = i + 1;
					break;
				}
			}
		}
		cout << ans << endl;
		
		
	}

	return 0;
}

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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16
#define mod 1000000007

int n;
vector<int> a;
int b[]={5,7,5,7,7,0};

int main(){
  while(1){
    cin>>n;
    if(n==0)break;
    a.clear();
    rep(i,n){
      string s;
      cin>>s;
      a.push_back(s.size());
    }
    rep(i,n){
      int j=0,rest=b[0];
      repl(k,i,n){
        if(rest<a[k])break;
        rest-=a[k];
        if(rest==0){
          j++; rest=b[j];
          if(j==5)break;
        }
      }
      if(j==5){
        cout<<i+1<<endl;
        break;
      }
    }
  }
  return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;
int main(){
    int n;
    while(cin>>n,n){
        vector<int> V(n);
        for(int i=0;i<n;i++){
            string s;
            cin>>s;
            V[i]=s.size();
        }
        for(int i=0;i<n;i++){
            int j=i;
            int cnt=0;
            while(cnt<5&&j<n)cnt+=V[j++];
            if(cnt!=5) continue;
            cnt=0;
            while(cnt<7&&j<n)cnt+=V[j++];
            if(cnt!=7) continue;
            cnt=0;
            while(cnt<5&&j<n)cnt+=V[j++];
            if(cnt!=5) continue;
            cnt=0;
            while(cnt<7&&j<n)cnt+=V[j++];
            if(cnt!=7) continue;
            cnt=0;
            while(cnt<7&&j<n)cnt+=V[j++];
            if(cnt!=7) continue;
            else{
                cout<<i+1<<endl;
                break;
            }
        }
    }
    return 0;
}

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

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

int main()
{
    vector<int> ans;
    while (1)
    {
        int n;
        cin >> n;
        if (n == 0)
            break;
        vector<string> w(n);
        for (int i = 0; i < n; i++)
        {
            cin >> w[i];
        }
        for (int i = 0; i < n; i++) //スタート位置
        {
            int turn = 0;
            for (int j = i; j < n; j++)
            {
                int num = 0;
                if (turn == 5)
                    break;
                else if (turn == 0 || turn == 2) //5のとき
                {
                    while (num < 5 && j < n)
                    {
                        num += w[j].size();
                        j++;
                    }
                    j--;
                    if (num != 5)
                        goto End;
                    turn++;
                }
                else if (turn == 1 || turn == 3 || turn == 4) //7のとき
                {
                    while (num < 7 && j < n)
                    {
                        num += w[j].size();
                        j++;
                    }
                    j--;
                    if (num != 7)
                        goto End;
                    turn++;
                }
            }
            ans.push_back(i + 1);
            break;
        End:;
        }
    }
    for (int i = 0; i < ans.size(); i++)
    {
        cout << ans[i] << endl;
    }
}