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<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
#include<random>
#include<ctime>
#include<set>
using namespace std;


const long long int mod=1000000007;
const long long int INF=99999999999999999;

long long int n;
char returneki[60];
map<char,long long int>eki;

int main() {
    cin>>n;
	while(n!=0){
		string str;
		long long int len[50],tanka[10]={5,7,5,7,7},type=0;
		for(int i=0;i<n;i++){
			cin>>str;
			len[i]=str.length();
		}
		for(int i=0;i<n-4;i++){
			type=0;
			tanka[0]=5;
			tanka[1]=7;
			tanka[2]=5;
			tanka[3]=7;
			tanka[4]=7;
			for(int j=i;j<n;j++){
				tanka[type]-=len[j];
				if(tanka[type]==0){
					if(type<4){type++;}
					else{cout<<i+1<<endl;goto next;}
				}else if(tanka[type]<0){
					break;
				}
			}
		}
		next:
		cin>>n;
	}
	
}

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init))
#define mp(a,b) make_pair(a,b)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

const int mod = 1000000007;
constexpr int inf = ((1<<30)-1)*2+1 ;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0,1,-1,1,-1};
const int dx[] = {0,-1,0,1,1,-1,-1,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}
template<typename T,typename U>
ll FindErase(T &v,U tar){
  ll cnt = 0;
  for(auto it = v.begin(); it != v.end();){
    if(*it == tar){
      it = v.erase(it);
      ++cnt;
    }
    else{
      ++it;
    }
  }
  return cnt;
}

template<typename T>
bool SuffixErase(T &v,size_t suf){
  if(suf > v.size()) return false;
  for(auto it = v.begin(); it != v.end();){
    if(distance(v.begin(),it) == suf){
      v.erase(it);
      return true;
    }
    else{
      ++it;
    }
  }
  return false;
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}
const int arr[] = {5,7,5,7,7};
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;
  while(cin >> n && n){
    string s;
    vector<ll> v(n);
    rep(i,n){
      cin >> s;
      v[i] = s.size();
    }
    rep(i,n){
      int suf = 0,len = 0;
      REP(j,i,n){
        len += v[j];
        if(len == arr[suf]){
          len = 0,++suf;
        }
        else if(len > arr[suf]){
          suf = 0;
          break;
        }
        if(suf == 5){
          break;
        }
      }
      if(suf == 5){
        cout << i+1 << endl;
        break;
      }
    }
  }
  return 0;
}

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

int main(){
  int n;
  while(std::cin >> n, n){
    int length[n];
    string s;
    for (int i = 0; i < n; i++) {
      std::cin >> s;
      length[i] = s.length();
    }
    vector<int> correct = {5, 7, 5, 7, 7};
    for (int i = 0; i < n; i++) {
      int tmp = 0, pos = 0;
      for (int j = i; j < n; j++) {
        tmp += length[j];
        if(tmp == correct[pos])pos++, tmp = 0;
        if(pos == correct.size()){
          std::cout << i + 1 << std::endl;
          i = j = 1e9;
        }
      }
    }
  }
  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
 
int main(){
  int b[5]={5,7,5,7,7};
  while(1){
    int n,a[41]={};
    int count=0,ans=0,j=0,c=0;
    string str;
    cin>>n;
    if(n==0)break;
 
    for(int i=0;i<n;i++){
      cin>>str;
      a[i]=str.size();
    }
 
    for(int i=0;i<n;i++){
      c+=a[i];
      count++;
      if(c==b[j]){
    j++;
    c=0;
      }
      else if(c>b[j]){
    i-=count-1;
    j=0;
    c=0;
    count=0;
       }
      if(j>4){
    ans=i-(count-1);
    break;
      }
    }
 
    cout<<ans+1<<endl;
  }
  return 0;
}

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

int main(){
  int n;
  while(cin>>n,n){
    string str[50];
    for(int i=0;i<n;i++)cin>>str[i];


    int num[]={5,7,5,7,7},ans=1000000;
    for(int i=0;i<n;i++){
      for(int j=i,idx=0,cnt=0;j<n;j++){
	cnt+=str[j].size();
	if(cnt==num[idx]) idx++,cnt=0;
	if(cnt>num[idx])break;
	if(idx==5) ans=min(ans,i);
      }    
    }
    cout <<ans+1<<endl;
  }
  return 0;
}