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 FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

int a[41];
int x[]={5,7,5,7,7};
int main(){
    int n;
    string s;
    while(cin>>n,n){
        rep(i,n){
            cin>>s;
            a[i]=s.size();
        }
        int ans=-1;
        rep(i,n-5){
            int cur=0,sum=0;
            FOR(j,i,n){
                sum+=a[j];
                if(sum>=x[cur]){
                    if(sum==x[cur]){
                        ++cur;sum=0;
                        if(cur==5){
                            ans=i+1;
                            break;
                        }
                    }
                    else break;
                }
                if(ans!=-1) break;
            }
            if(ans!=-1){
                cout<<ans<<endl;
                break;
            }
        }
    }
    return 0;
}

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

int main() {
	int n;
	int q = 0;
	while (cin >> n) {
		if (q != 0)cout << endl;
		if (n == 0)return 0;
		string w[50];
		for (int i = 0;i < n;i++)cin >> w[i];
		vector<int>v;
		int now = 0;
		for (int i = 0;i < n - 1;i++) {
			for (int j = i;j < n;j++) {
				now += w[j].size();
				if (now == 5) {
					v.push_back(i);
					now = 0;
					break;
				}
				if (now >= 6) {
					now = 0;
					break;
				}
			}
		}
		now=0;
		int k = 0, flag = 0;
		int haiku[5] = { 5,7,5,7,7 };
		for (int i = 0;i < v.size();i++) {
			for (int j = v[i];j < n;j++) {
				now += w[j].size();
				if (now == haiku[k]) {
					k++;
					now = 0;
				}
				if (k == 5) {
					cout << v[i] + 1;
					q++;
					flag = 1;
					break;
				}
			}
			if (flag)break;
			now = 0;
			k = 0;
		}
	}
}

C++: #include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int make(int w,int p);

vector<string> a(50);

int main(){
  int n;
  scanf ("%d",&n);
  while(n){
    for(int t=0;t<n;t++){
      //scanf ("%s",a[t]);
      cin >> a[t];
    }
    for(int t=n;t<50;t++){
      //scanf ("%s",a[t]);
      a[t]="";
    }
    int end=0;
    int k=0;
    for(k=0;k<n;k++){
      int q=k;
      if(make(q,5)>=0){
        q=1+make(q,5);
        if(make(q,7)>=0){
          q=1+make(q,7);
          if(make(q,5)>=0){
            q=1+make(q,5);
            if(make(q,7)>=0){
              q=1+make(q,7);
              if(make(q,7)>=0){
                end=1;
                //printf("qwqw\n");
              }
            }
          }
        }
      }
      if(end==1) break;
    }
    k++;
    printf("%d\n",k);
    scanf ("%d",&n);
  }
}


int make(int w,int p){
  int l=a[w].size();
  if(l==p){
    return w;
  }
  else{
    if(l<p){
      //printf("%d\n",r);
      return make(w+1,p-l);
    }
    else{
      return -1;
    }
  }
}

C++: #include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
using pii=pair<int,int>;
using vlai=valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()

int main(void){
    int n;
    while(cin>>n,n){
        vi l(n);
        rep(i,n) {string s; cin>>s; l[i]=s.length(); }
        rep(i,n){
            int now=0,count=0,ans=-1; vi len={5,7,5,7,7};
            range(j,i,n){
                now+=l[j];
                if(now == len[count]){
                    count++,now=0;
                    if(count==5){
                        ans=i+1;
                    }
                }
                if(now>len[count]){
                    j=n;
                }
            }
            if(ans!=-1){
                cout<<ans<<endl;
                break;
            }
        }
    }
}

C++: #include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int const MOD = 1000000007;

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

signed main() {
    int n;
    while(cin >> n, n) {
        vector<string> w(n);
        rep(i,0,n) cin >> w[i];
        rep(i,0,n) {
            int par = 0;
            int level = 0;
            rep(j,i,n) {
                if(level == 5) break;
                par += w[j].size();
                if(level == 0 || level == 2) {
                    if(par == 5) {
                        level++;
                        par = 0;
                    }
                    else if(par > 5) break;
                }
                else if(level == 1 || level == 3 || level == 4) {
                    if(par == 7) {
                        level++;
                        par = 0;
                    }
                    else if(par > 7) break;
                }
            }
            // printf("level: %lld\n", level);
            if(level == 5) {
                cout << i+1 << endl;
                break;
            }
        }
    }
    return 0;
}

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