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<iostream>
#include<string>
using namespace std;

int main(){
  int n;
  int d_words[5]={5,7,5,7,7};
  while(cin>>n && n!=0){
    int* n_words=new int[n];
    for(int i=0;i<n;i++){
      string str;
      cin>>str;
      n_words[i]=str.size();
    }
    int start=0;
    int success=0;
    while(!success){
      int t_words=0;
      int tmp=start;
      int tmp2=0;
      while(1){
        tmp2+=n_words[tmp];
        if(tmp2==d_words[t_words]){
          t_words++;
          if(t_words==5){
            success=start+1;
            break;
          }
}else if(tmp2>d_words[t_words]){
            break;
          }
        
        tmp++;
      }
      start++;
    }
    cout<<success<<endl;
  }
}

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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))

typedef long long LL;

int main(){
  int n;
  string s;
  int len[5]={5,7,5,7,7};
  int count;
  int now;
  int ans;
  while(1){
    cin >> n;
    if(n==0) return 0;
    vector<int> w(n);
    for(int i=0;i<n;i++){
      cin >> s;
      w[i]=s.length();
    }
    ans=-1;
    for(int i=0;i<n;i++){
      count=0;
      now=0;
      for(int j=i;j<n;j++){
        count+=w[j];
        if(count==len[now]){
          now++;
          count=0;
          if(now==5){
            ans=i;
          }
        }else if(count>len[now]){
          break;
        }
      }
      if(ans!=-1){
        break;
      }
    }
    cout << ans+1 << endl;
  }
  return 0;
}

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

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

signed main() {
	for (int n; cin >> n&&n;) {
		vector<string> w(n); rep(i, 0, n) { cin >> w[i]; }
		rep(i, 0, n) {
			int a[5] = { 5,7,5,7,7 };
			int idx = 0;
			rep(j, i, n) {
				a[idx] -= w[j].size();
				if (a[idx] == 0) {
					if (idx == 4) {
						cout << i + 1 << endl;
						i = INF;
						break;
					}
					idx++;
				}
				if (a[idx] < 0)break;
			}
		}
	}
	return 0;
}

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

int main(){
  int n;
  const int haiku[5]={5,7,5,7,7};
  while(cin>>n,n){
    vector<string> w(n);
    for(int i=0;i<n;i++) cin>>w[i];
    int res=-1;
    for(int i=0;i<n && res==-1;i++){
      int stage=0;
      int cnt=0;
      for(int j=i;j<n;j++){
	cnt+=w[j].size();
	if(cnt==haiku[stage]){
	  stage++;
	  cnt=0;
	}
	if(stage==5){
	  res=i+1;
	  break;
	}

      }
    }
    cout<<res<<endl;
  }
  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 emplace_back
#define INF (1e9+1)
//#define INF (1LL<<59)

int main(){
    int n;
    while(cin>>n&&n){
        vector<string> vs(n);
        rep(i,n)cin>>vs[i];
        
        rep(i,n){
            int count;
            int pos = i;

            count = 0;
            while(count<5 && pos<n) count+=vs[pos++].size();
            if(count!=5)continue;

            count = 0;
            while(count<7 && pos<n) count+=vs[pos++].size();
            if(count!=7)continue;

            count = 0;
            while(count<5 && pos<n) count+=vs[pos++].size();
            if(count!=5)continue;

            count = 0;
            while(count<7 && pos<n) count+=vs[pos++].size();
            if(count!=7)continue;

            count = 0;
            while(count<7 && pos<n) count+=vs[pos++].size();
            if(count!=7)continue;

            cout<<i+1<<endl;
            break;
        }
    }
}

C++: #include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
    int n;
    while(cin >> n, n){
    int len[] = {5, 7, 5, 7, 7};
    string w[44];
    for(int i = 0; i < n; i++) cin >> w[i];
    int ans = 0;
    for(int i = 0; i < n; i++){
        int cnt = 0, idx = 0;
        for(int j = i; j < n; j++){
        cnt += w[j].size();
        if(cnt == len[idx]){
            cnt = 0, idx++;
            if(idx == 5) break;
        }else if(cnt > len[idx]){ idx = -1; break;}
        }
        if(idx == 5){ ans = i; break;}
    }
    cout << ans+1 << endl;
    }
    return 0;
}

C++: #include<iostream>
#include<vector>
#include<string>
#include<cstdlib>
#include<sstream>
#include<queue>
#include<deque>
#include<cmath>
#include<algorithm>
#include<stack>
#include<map>
#include<set>
#include<iomanip>
#define INF 2147483647
#define lli long long int
#define MOD 1000000007
#define pb push_back

using namespace std;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
int main() {
	while(1){
		int n; cin >> n;
		if (n == 0) break;
		
		vector<string> str(n);
		for(int i = 0; i < n; i++) {
			cin >> str[i];	
		}

		int ans = 0;
		for(int i = 0; i < n; i++) {
			ans = i;	
			vector<int> check = {5,7,5,7,7};
			int idx = 0;
			for (int j = i; j < n; j++) {
					if (check[idx] > 0){
						check[idx] -= str[j].size();
					}else if(check[idx] <= 0){
						idx++;
						check[idx] -= str[j].size();
					}
					
			}
			int sum = 0;
			for (int k = 0; k < 5; k++){
				sum += check[k];
			}
			if (sum == 0){
				break;
			}

		}
		cout << ans + 1 << endl;
	}

	return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<complex>
#include<string>
#include<cstring>

using namespace std;
#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
#define INF 100000000
#define all(x) x.begin(),x.end()
typedef pair<int,int> P;
typedef pair<int,P> PP;
int n;
string s;
vector<int> array;
int hai[5]={5,7,5,7,7};
int now;
int Count;
int flag;
int owari;
int main()
{
	while(1)
	{
		owari=0;
		array.clear();
		cin>>n;
		if(n==0)break;
		rep(i,n)
		{
			cin>>s;
			array.push_back(s.size());
		}
		rep(i,n)
		{
			flag=0;
			now=i;
			Count=0;
			while(1)
			{
				if(now==n)break;
				Count+=array[now];
				if(Count>hai[flag])break;
				else if(Count==hai[flag])
				{
					if(flag!=4)
					{
						flag++;
						Count=0;
					}
					else
					{
						cout<<i+1<<endl;
						owari=1;
						break;
					}
				}
				now++;
			}
			if(owari==1)break;
		}
	}
	return 0;
}