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>
using namespace std;

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

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

signed main(){
    int N;
    while(cin>>N,N){
        vector<string>S(N);
        rep(i,N)cin>>S[i];
        rep(i,N){
            bool ok=true;
            int cur=i;
            rep(j,5){
                int sum=0;
                while(cur<N&&sum<t[j]){
                    sum+=S[cur++].size();
                }
                if(sum!=t[j])ok=false;
            }
            if(ok){
                cout<<i+1<<endl;
                break;
            }
        }
    }
    return 0;
}

C++: #include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1 << 28;
//constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;

using namespace std;
typedef unsigned long long ull;
typedef long long ll;

int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/

	int kkt = 89;
	while (kkt) {
		int n; cin >> n; if (n == 0) break;
		vector<string> vs(n); for (int i = 0; i < n; i++) cin >> vs[i];
		int res = -1;
		for (int i = 0; i < n; i++) {
			int f = 0;
			int sum = 0;

			for (int j = i; j < n; j++) {
				sum += vs[j].size();
				if (f == 0 or f == 2) {
					if (sum == 5) {
						f++;
						sum = 0;
					}
					else if (sum > 5) {
						break;
					}
				}
				else {
					if (sum == 7) {
						f++;
						sum = 0;
					}
					else if (sum > 7) break;
				}
				if (f == 5) {
					res = i + 1;
					break;
				}
			}
			if (res != -1) break;
		}
		cout << res << "\n";
	}
	return 0;

}

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
#define int long long

signed main() {
  while (true) {
    int n;
    cin >> n;
    if (!n) return 0;
    string s[n];
    for (int i = 0; i < n; i++) {
      cin >> s[i];
    }
    for (int i = 0; i < n; i++) {
      int count;
      int res = 0;
      count = 0;
      int j = i;
      while (res < 5) {
        count += s[j].size();
        if (res == 0 || res == 2) {
          if (count > 5) break;
          else if (count == 5) {
            res++;
            count = 0;
          }
        } else {
          if (count > 7) break;
          else if (count == 7) {
            res++;
            count = 0;
          }
        }
        j++;
      }
      if (res == 5) {
        cout << i + 1 << endl;
        break;
      }
    }
  }
}

C++: #include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
const double PI = 3.14159265358979;
const double E = 2.718281828459045;
const double root2 = sqrt(2);
typedef pair<int, int> P;
typedef unsigned int ui;
int main() {
	int n;
	while(cin>>n){
		if (n == 0)break;
		vector<string> v;
		string s; int out=0;
		for (int i = 0; i < n; i++) {
			cin >> s;
			v.push_back(s);
		}
		while (true) {
			int x = out;
			bool f = true;
			int cnt = 0;
			while (x<n&&cnt+(int)v[x].size() <= 5) {
				cnt+=v[x].size();
				x++;
			}
			if (cnt != 5) {
				f = false;
			}
			cnt = 0;
			while (x<n&&cnt + (int)v[x].size() <= 7) {
				cnt += v[x].size();
				x++;
			}
			if (cnt != 7) {
				f = false;
			}
			cnt = 0;
			while (x<n&&cnt + (int)v[x].size() <= 5) {
				cnt += v[x].size();
				x++;
			}
			if (cnt != 5) {
				f = false;
			}
			cnt = 0;
			while (x<n&&cnt + (int)v[x].size()<=7){
				cnt += v[x].size();
				x++;
			}
			if (cnt != 7) {
				f = false;
			}
			cnt = 0;
			while (x<n&&cnt + (int)v[x].size() <= 7) {
				cnt += v[x].size();
				x++;
			}
			if (cnt != 7) {
				f = false;
			}
			if (f)break;
			out++;
		}
		cout << out+1 << endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>
#define ll long long
#define all(a) (a).begin(),(a).end()

using namespace std;

int main(int argc, char const *argv[]) {
  while (1) {
    int chars=0;int tanku[5]={5,7,5,7,7};int block=0;//block???tanku??????????????´??°???v?????£??????leng???tanku??¨??????????????£?????´???
    int leng=0,istart=1;
    scanf("%d",&chars);
    if(chars==0){
      return 0;
    }
    std::vector<string> v(chars);
    for (size_t i = 0; i < chars; i++) {
      std::cin >> v[i];
    }

    //???????????§????????¨??\???
    //??????????????????

    for (size_t i = 0; block<=4; i++) {
      leng+=v[i].size();
      if (leng>tanku[block]) {
        block=0;leng=0;
        i=istart-1;istart++;
      }else if(leng==tanku[block]){
        block++;leng=0;
      }
    }
    printf("%d\n",istart);
  }
  return 0;
}

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

int main(){
    int n;
    while(cin >> n, n){
        vector<int> len(n);
        for(int i = 0 ; i < n ; i++){
            string w;
            cin >> w;
            len[i] = w.size();
        }

        int ans = -1;
        int tanku[] = {5, 7, 5, 7, 7};
        for(int i = 0 ; i < n ; i++){
            int cnt = 0, now = 0;
            bool ok = true;
            for(int j = i ; j < n ; j++){
                cnt += len[j];
                if(cnt == tanku[now]){
                    now++;
                    cnt = 0;
                }else if(cnt > tanku[now]){
                    ok = false;
                }
                if(now >= 5){
                    break;
                }
            }
            if(ok){
                ans = i + 1;
                break;
            }
        }

        cout << ans << endl;
    }

    return 0;
}