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>
#include <string>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define shosu(n) setprecision(n)
using namespace std;

int main() {
  int n;
  while (cin >> n, n) {
    int ans = 0, key = 0, ke2 = 0;
    string s[n];
    rep(i, n) cin >> s[i];
    for (int i = 0; i < n; i++) {
      ans = 0;
      key = 0;
      for (int j = i; j < n; j++) {
        ans += s[j].size();
        if (ans == 5 && key == 0) {
          key = 1;
          ans = 0;
        } else if (ans > 5 && key == 0 || ans > 7 && key == 1 ||
                   ans > 5 && key == 2 || ans > 7 && key == 3 ||
                   ans > 7 && key == 4) {
          ans = 0;
          key = 0;
          break;
        } else if (ans == 7 && key == 1) {
          key = 2;
          ans = 0;
        } else if (ans == 5 && key == 2) {
          ans = 0;
          key = 3;
        } else if (ans == 7 && key == 3) {
          ans = 0;
          key = 4;
        } else if (ans == 7 && key == 4) {
          cout << i + 1 << endl;
          ke2 = 1;
          break;
        }
      }
      if (ke2 == 1)
        break;
    }
  }
  return 0;
}

C++: #include <cstdio>
#include <cassert>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>

bool nya(std::vector<int> const& w, size_t k) {
  std::vector<int> haiku{5, 7, 5, 7, 7};
  int j = 0;
  for (size_t i = k; i < w.size(); ++i) {
    if (haiku[j] < w[i]) return false;
    haiku[j] -= w[i];
    if (haiku[j] == 0) {
      if (++j == 5) return true;
    }
  }
  return false;
}

int testcase_ends() {
  size_t n;
  scanf("%zu", &n);
  if (n == 0) return 1;

  std::vector<int> w(n);
  for (auto& wi: w) {
    char buf[16];
    scanf("%s", buf);
    wi = std::string(buf).length();
  }

  for (size_t i = 0; i < n; ++i)
    if (nya(w, i)) return !printf("%zu\n", i+1);

  assert(false);
}

int main() {
  while (!testcase_ends()) {}
}

C++: #include <iostream>
#include <vector>
#include <stack>
#include <utility>

using namespace std;

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

bool isword(int s,int n,vector<string> list){
    if(s==5)return true;
    int sum=0;
    bool flag;
    for(int i=n;i<list.size();i++){
        sum+=list[i].length();
        if(sum==seq[s]){
            flag=isword(s+1,i+1,list);
            break;
        }
        if(sum>seq[s]){
            flag=false;
            break;
        }
    }
    if(flag)return true;
    return false;
}

int main(){
    while(true){
        int n;
        cin >> n;
        if(n==0)break;
        vector<string> list(n);
        for(int i=0;i<n;i++){
            cin >> list[i];
        }
        int ans;
        for(int i=0;i<n;i++){
            if(isword(0,i,list)){
                ans=i+1;
                break;
            }
        }
        cout << ans << endl;
    }
    return 0;
}

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

using namespace std;

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

int main(){
	
	while(1){
		
		int n;
		cin >> n;
		if(n==0) break;
		
		string a;
		int t[n]={};
		
		for(int i=0;i<n;i++){
			cin >> a;
			t[i]=(int)a.size();
		}
		int c,ans=0;
		for(int i=0;i<n;i++){
			c=i;
			int j;
			for(j=0;j<5;j++){
				int b=0;
				while(b<k[j]){
					b+=t[c];
					c++;
				}
				if(b>k[j]) break;
			}
			if(j==5){
				ans=i;
				break;
			}
		}
		cout << ans+1 << endl;
	}
		
		
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
#define int ll

signed main(void)
{
  while(true) {
    int n;
    cin >> n;
    if(!n) break;
    string s[45];
    REP(i, n) cin >> s[i];

    REP(i, n) {
      int tmp = 0, cnt = 0;
      FOR(j, i, n) {
        tmp += s[j].size();
        //cout << cnt << " " << tmp << endl;
        if(cnt == 0) {
          if(tmp == 5) {cnt = 1; tmp = 0;}
          else if(tmp > 5) break;
        } else if(cnt == 1) {
          if(tmp == 7) {cnt = 2; tmp = 0;}
          else if(tmp > 7) break;
        } else if(cnt == 2) {
          if(tmp == 5) {cnt = 3; tmp = 0;}
          else if(tmp > 5) break;
        } else if(cnt == 3) {
          if(tmp == 7) {cnt = 4; tmp = 0;}
          else if(tmp > 7) break;
        } else if(cnt == 4) {
          if(tmp == 7) {cnt = 5; tmp = 0;}
          else if(tmp > 7) break;
        }
      }
      if(cnt == 5) {
        cout << i+1 << endl;
        break;
      }
    }
  }

  return 0;
}

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

int main(){
  while(1){
    int n;
    cin>>n;
    if(n==0)break;
    vector<int> a(n);
    for(int i=0;i<n;i++){
      string s;
      cin>>s;
      a[i]=s.size();
      //cout<<a[i]<<endl;
    }
    int ok=0;
    for(int i=0;i<n;i++){
      if(ok==1)break;
      int sum=0;
      int sta=0;
      int j=i;
      while(1){
        //cout<<sta<<" "<<sum<<endl;
        if(sta==0||sta==2){
          if(sum+a[j]==5){
            sta++;
            sum=0;
          }else{
            sum+=a[j];
            if(sum>5)break;
          }
        }else{
          if(sum+a[j]==7){
            sta++;
            if(sta==5){
              cout<<i+1<<endl;
              ok=1;
              break;
            }
            sum=0;
          }else{
            sum+=a[j];
            if(sum>7)break;
          }
        }
        j++;
      }
    }
  }
}

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

int main(){
  int n,h[40];
  string a;
  while(cin>>n,n){
    for(int i=0;i<n;i++)cin>>a,h[i]=a.size();
    for(int i=0;i<n;i++){
      int now=i,nt=0,nn=0,f=0;
      while(1){
	if(nt==5){
	  f=1;
	  break;
	}
	if(nt==0||nt==2){
	  if(nn>5)break;
	  if(nn==5)nt++,nn=0;
	}else{
	  if(nn>7)break;
	  if(nn==7)nt++,nn=0;
	}
	nn+=h[now];
	now++;
      }
      if(f){
	cout<<i+1<<endl;
	break;
      }
    }
  }
  return 0;
}