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 rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
using namespace std;

char c[40][15];

int main(){
	int n;
	while (scanf("%d", &n), n){
		int want[] = { 5, 7, 5, 7, 7 };
		int cnt = 0;
		int j = 0;
		for (int i = 0; i < n; i++){
			scanf("%s", c[i]);
		}
		int t;
		for (t = 0; t < n; t++){
			for (int i = t; i < n; i++){
				cnt += strlen(c[i]);
				if (cnt == want[j]){
					cnt = 0;
					if (++j == 5)break;
				}
				if (cnt > want[j])break;
			}
			if (j == 5)break;
			j = 0;
			cnt = 0;
		}
		printf("%d\n", t+1);
	}
	return 0;
}

C++: #include <bits/stdc++.h> // {{{
// clang-format off
#define ARG4(_1, _2, _3, _4, ...) _4
#define rep(...) ARG4(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define REP(i, a) FOR(i, 0, a)
#define FOR(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define rrep(...) ARG4(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define RREP(i, a) RFOR(i, 0, a)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (int)(a); --i)
#define ALL(c) (c).begin(), (c).end()
#define TEN(n) ((ll)(1e##n))
#define pb emplace_back
#define mp make_pair
#define fi first
#define se second
#define USE1(T) template <typename T> inline
#define USE2(T, U) template <typename T, typename U> inline
#define mygc(c) (c) = getchar_unlocked()
#define mypc(c) putchar_unlocked(c)
 
template<typename T> using vec = std::vector<T>;
template<typename T> using withi = std::pair<T, int>;
using ll = long long;
USE2(T,U)bool chmax(T&x,U a){return x<a&&(x=a,1);}
USE2(T,U)bool chmin(T&x,U a){return a<x&&(x=a,1);}
USE1(T=int)T in(){T x;std::cin>>x;return x;}
USE1(T=int)vec<T>in(int n){vec<T>v;v.reserve(n);rep(i,n)v.pb(in<T>());return v;}
USE2(T,U=withi<T>)vec<U>zipi(const vec<T>&x,int s=0){int N=x.size();vec<U>v;v.reserve(N);rep(i,N)v.pb(x[i],s+i);return v;}
USE1(T)vec<T>ndvec(T v,int n){return vec<T>(n,v);}
USE2(T,...Ts)auto ndvec(T v,int n,Ts...ns)->vec<decltype(ndvec(v,ns...))>{return ndvec(ndvec(v,ns...),n);}
USE1(T)void pr(T x){std::cout<<x<<'\n';}
USE2(T,...Ts)void pr(T x,Ts...xs){std::cout<<x<<' ';pr(xs...);}
USE1(T=int)T rd(){T x=0,m=0,k;for(;;){mygc(k);if(k=='-'){m=1;break;}if('0'<=k&&k<='9'){x=k-'0';break;}}for(;;){mygc(k);if(k<'0'||'9'<k)break;x=x*10+k-'0';}return x;}
USE1(T=int)void wr(T x,char c='\n'){int s=0,m=0;char b[32];if(x<0)m=1,x=-x;for(;x;x/=10)b[s++]=x%10;if(!s)b[s++]=0;if(m)mypc('-');for(;s--;)mypc(b[s]+'0');mypc(c);}
// clang-format on
// }}}
struct IoSetup { // {{{
  IoSetup() {
    std::ios::sync_with_stdio(0);
    std::cin.tie(0);
    std::cout.precision(10);
    std::cerr.precision(10);
  }
} iosetup; //}}}
using namespace std;
const int inf = 1001001001;
const ll infl = 1001001001001001001ll;
const int dd[] = {0, 1, 0, -1, 0};

bool is_haiku(const vector<int>& w, int s) {
  int word[] = {5, 7, 5, 7, 7};
  int st = 0;
  rep(i, s, w.size()) {
    word[st] -= w[i];
    if (word[st] < 0) return false;
    if (word[st] == 0) {
      st++;
      if (st == 5) return true;
    }
  }
  return false;
}

signed main() {
  int N;
  while (N = in(), N) {
    vector<int> w;
    rep(i, N) { w.pb(in<string>().size()); }
    rep(i, N) {
      if (is_haiku(w, i)) {
        pr(i + 1);
        break;
      }
    }
  }
  return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
  int a[]={5,7,5,7,7},n,i,j,c,k;
  while(cin>>n,n){
    string s[n];
    for(i=0;i<n;i++)cin>>s[i];
    for(i=0;i<n;i++){
      c=k=0;
      for(j=i;j<n;j++){
        c+=s[j].size();
        if(c==a[k]){
          c=0;
          if(++k==5)goto L;
        }
      }
    }
    L: if(k==5)cout<<i<<endl;
  }
}

C++: #include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    int n;
    int w[5] = {5, 7, 5, 7, 7};
    while (cin >> n && n){
        VI a(n);
        REP(i,n) {
            string s;
            cin >> s;
            a[i] = s.length();
        }
        REP(s,n){
            int x = 0, i = s, j = 0, f = 1;
            while (f){
                x += a[i];
                i++;
                if (x == w[j]){
                    x = 0;
                    j++;
                }
                if (x > w[j]) f = 0;
                if (j == 5) break;
            }
            if (f) cout << s+1 << endl;
        }
    }

    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
int tanka[5] = {5,7,5,7,7};

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(true) {
        int n;
        cin >> n;
        if(n == 0) break;
        string field[41];
        for(int i = 1; i <= n; i++) cin >> field[i];
        for(int start = 1; start <= n; start++) {
            int nowval = 0;
            int nowindex = 0;
            for(int i = start; i <= n; i++) {
                nowval += field[i].size();
                if(nowval == tanka[nowindex]) {
                    nowval = 0;
                    nowindex++;
                }
                if(nowindex == 5) break;
            }
            if(nowindex == 5) {
                cout << start << endl;
                break;
            }
        }
    }
    return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
  while(true){
    int n;
    cin>>n;
    if(n==0){
      break;
    }
    int len[40];
    for(int i=0;i<n;i++){
      string w;
      cin>>w;
      len[i]=w.size();
    }
    for(int i=0;i<n;i++){
      bool flg=false;
      int sta=0;
      int sum=0;
      for(int j=1;j<n;j++){
        sum+=len[j];
        if(sum==5||sum==12||sum==17||sum==24||sum==31){
          sta++;
        }
        if(sta==5){
          flg=true;
          break;
        }
        else if(sum>=31){
          break;
        }
      }
      if(flg){
        cout<<i+1<<endl;
        break;
      }
    }
  }
    return 0;
}