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>
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
#define _all(arg) begin(arg),end(arg)

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0; }
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0; }

using namespace std;

bool check(vector<string> w, int begin) {
	bool res;
	int cur = begin;
	int buf = 0;
	int i = 0;
	vector<int> hoge = {5,7,5,7,7};
	for(i = 0; i < hoge.size() && cur < w.size(); cur++) {
		buf += w[cur].size();
		if(buf == hoge[i]) {
			buf = 0;
			i++;
		}
		if(buf > hoge[i]) {
			break;
		}
	}
	if(i == 5) {
		return true;
	}
	else {
		return false;
	}
}

int main(void){
	int n;
	while(cin>>n,n) {
		vector<string> W(n);
		rep(i,n) cin >> W[i];
		rep(i,n) {
			if(check(W, i-1)) {
				cout << i << endl;
				break;
			}
		}
	}
        
	return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

int n;

int main(){
    while(1){
        cin >> n;
        if(n==0)break;
        vector<string> w(n);
        int tan[] = {5,7,5,7,7};
        for(int i=0;i<n;i++){
            cin >> w[i];
        }
        int j=0;
        int ans=0;
        int sum=0;
        for(int k=0;k<n;k++){
            sum=0;
            ans=k;
            j=0;
            for(int i=k;i<n;i++){
                sum += w[i].size();
                if(sum > tan[j]){
                    sum = w[i].size();
                    j=0;
                    ans=i;
                }
                if(sum < tan[j])continue;
                if(sum == tan[j]){
                    if(j==4)break;
                    else {
                        j++;
                        sum = 0;
                    }
                }
            }
            if(j==4 && sum == tan[j])break;
        }
        cout << ans+1 << endl;

    }
}

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

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

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

int main(){
  int a,sum,k,l,sta,suc,h[50],han[5]={5,7,5,7,7};
  string s;
  while(cin>>a){
    if(a==0)break;
    for(int i=0;i<a;i++){
      cin>>s;
      h[i]=s.size();
    }
    suc=0;
    for(int i=0;i<a;i++){
      sum=0;k=0;l=0;
      while(1){
	sum+=h[i+k];
	  if(sum==han[l]){
	    l++;
	    sum=0;
	  }else if(sum>han[l])break;
	if(l==5){
	  suc=1;
	  break;
	}
	k++;
	if(k>=a)break;
      }
      if(suc==1){
	sta=i;
	break;
      }
    }
    cout<<sta+1<<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;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

ll n;
ll table[] = {5,7,5,7,7};

int main(){
    while(cin >> n && n){
        vector<ll> v(n);
        rep(i,n){
            string s;
            cin >> s;
            v[i] = s.size();
        }
        rep(i,n){
            bool ok = true;
            ll cnt = 0;
            ll pos = 0;
            FOR(j,i,n){
                cnt += v[j];
                if(cnt > table[pos])ok = false;
                else if(cnt == table[pos]){
                    pos++;
                    cnt = 0;
                }
                if(pos == 5)break;
            }
            if(ok){
                cout << i+1 << endl;
                break;
            }
        }
    }
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <cmath>
#include <string>
#define FI first
#define SE second
#define PF push_front
#define PB push_back
#define POF pop_front
#define POB pop_back
#define MA make_pair
#define ll long long
#define VE vector<int>
#define VP vector<pair<int,int> >
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
using namespace std;
//
const int INF=1e9+7;
const int mod=1e9+7;
//
int main(){
  int N;
  while(1){
    cin>>N;
    if(N==0){
      break;
    }
    VE V;
    FOR(i,0,N){
      string S;
      cin>>S;
      V.PB((int)S.size());
    }
    FOR(i,0,N){
      int sum=0;
      int now=i;
      while(sum<5){
        sum+=V[now];
        now++;
      }
      if(sum!=5){
        continue;
      }
      while(sum<12){
        sum+=V[now];
        now++;
      }
      if(sum!=12){
        continue;
      }
      while(sum<17){
        sum+=V[now];
        now++;
      }
      if(sum!=17){
        continue;
      }
      while(sum<24){
        sum+=V[now];
        now++;
      }
      if(sum!=24){
        continue;
      }
      while(sum<31){
        sum+=V[now];
        now++;
      }
      if(sum==31){
        cout<<i+1<<endl;
      }
    }
  }
  return 0;
}

C++: #include<iostream>

using namespace std;

signed main(){

   while(1){
      int n;
      cin>> n;
      if(!n) break;

      int w[n];
      for(int i=0; i<n; i++){
         string s;
         cin>> s;
         w[i]=s.size();
      }
      int b[]={5, 7, 5, 7, 7};
      for(int i=0; i<n; i++){
         int a=0, p=0;
         for(int j=i; j<n; j++){
            a+=w[j];
            if(a>b[p]){
               goto turai;
            }else if(a==b[p]){
               p++;
               if(p==4) break;
               a=0;
            }
         }
         if(p==4){
            cout<< i+1<< endl;
            return 0;
         }
         turai:;
      }

   }

   return 0;
}