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>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	int n;
	while(cin>>n,n){
		string s[n];
		int num[n];
		rep(i,n)cin>>s[i];
		rep(i,n)num[i]=s[i].size();
		rep(i,n){
			int check=0,sum=0;
			for(int j=i;sum<=31;j++){
				sum+=num[j];
				if(sum==5)check|=1;
				else if(sum==12)check|=(1<<1);
				else if(sum==17)check|=(1<<2);
				else if(sum==24)check|=(1<<3);
				else if(sum==31)check|=(1<<4);
			}
			if(check==(31)){
				cout<<i+1<<endl;
				break;
			}
		}
	}
	return 0;

}

C++: #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<ll>;
using VV = vector<VI>;
using VS = vector<string>;

// tourist set
template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}

template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << '\n'; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
// tourist set end

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

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,b) FOR(i, 0, b)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<'\n'
#define p2(s, t) cout << (s) << " " << (t) << '\n'
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << '\n'
#define p_yes() p("YES")
#define p_no() p("NO")
#define SZ(x) ((int)(x).size())
#define SORT(A) sort(ALL(A))
#define RSORT(A) sort(ALL(A), greater<ll>())

void no(){p_no(); exit(0);}
void yes(){p_yes(); exit(0);}

const ll mod = 1e9 + 7;
const ll inf = 1e18;
const double PI = acos(-1);

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    // input
    ll N;
    debug(N);
    
    while(cin>>N){
      debug(N);
      if(N==0) return 0;

      VI A;
      rep(i, N){
        string s; cin >> s;
        A.push_back(s.size());
      }
      debug(A);

      rep(i, N){
        bool ok = true;
        ll now = i;
        rep(j, 5){
          ll sum = 0;
          while(sum<len[j]) sum+=A[now++];
          if(sum==len[j]){
            continue;
          }else{
            ok = false;
            break;
          }
        }
        if(ok){
          p(i+1);
          break;
        }
      }
    }
    
    return 0;
}

C++: #include <iostream>
#include <string>
#include <vector>
#include <cstdio>
using namespace std;
vector<int> T={5,7,5,7,7};
int solve(const vector<string>&v){
	for(int i=0;i<v.size();i++){
		for(int j=i,n=0,y=0;j<v.size();j++){
			n+=v[j].size();
			if(n==T[y]){
				if(++y==T.size())return i+1;
				n=0;
			}
		}
	}
	return -1;
}
int main(){
	int N;
	for(;cin>>N,N;){
		vector<string>v(N);
		for(int i=0;i<N;i++)cin>>v[i];
		printf("%d\n",solve(v));
	}
}

C++: #include <cstdint>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int32_t find_len(vector<uint32_t> &nums, uint32_t start, uint32_t len) {
  int32_t end = -1;
  int32_t index = start;
  int32_t remain = len;
  while (remain > 0 && index < nums.size()) {
    remain -= nums[index];
    index++;
  }

  if (remain == 0) {
    end = index;
  }

  return end;
}
int32_t main() {
  while (true) {
    uint32_t n;
    cin >> n;

    if (n == 0) break;

    vector<uint32_t> nums;
    for (uint32_t _ = 0; _ < n; _++) {
      string str;
      cin >> str;
      nums.push_back(str.size());
    }

    for (uint32_t i = 0; i < nums.size(); i++) {
      int32_t index = find_len(nums, i, 5);
      if (index == -1) continue;
      index = find_len(nums, index, 7);
      if (index == -1) continue;
      index = find_len(nums, index, 5);
      if (index == -1) continue;
      index = find_len(nums, index, 7);
      if (index == -1) continue;
      index = find_len(nums, index, 7);
      if (index == -1) continue;
      cout << i + 1 << endl;
      break;
    }
  }

  return 0;
}