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;

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

int main()
{
    int n;
    int a[5]={5,7,5,7,7};
    while(cin >>n,n)
    {
        vector<int> w(n);
        rep(i,n)
        {
            string s;
            cin >>s;
            w[i]=s.size();
        }

        int ans=-1;
        rep(i,n)
        {
            int ct=0;

            bool valid=false;
            int idx=0;
            for(int j=i; j<n; ++j)
            {
                ct+=w[j];
                if(ct==a[idx])
                {
                    ++idx;
                    ct=0;
                }
                else if(ct>a[idx]) break;


                if(idx==5)
                {
                    valid=true;
                    break;
                }
            }

            if(valid)
            {
                ans=i+1;
                break;
            }
        }

        cout << ans << endl;
    }
    return 0;
}

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

using namespace std;

int check(vector<int> tanka){
	int roule[] = {5,7,5,7,7};
	int index = 0, i = 0, t = 0;
	int sum = 0;
	while(i < 5){
		do{
			sum += tanka[index+t];
			t++;
		}while(sum < roule[i]);
		if(sum > roule[i]){
			index++;
			i = 0;
			t = 0;
		}else{
			i++;
		}
		sum = 0;
	}
	return index+1;
}

int main(){
	vector<int> tanka;
	vector<int> res;
	int n;
	do{
		cin >> n;
		for(int i=0;i<n;i++){
			string tmp;
			cin >> tmp;
			tanka.push_back(tmp.size());
		}
		if(n > 0)
			res.push_back(check(tanka));
		tanka.clear();
		tanka.shrink_to_fit();
	}while(n > 0);

cout << "test" << endl;
	for(auto num : res){
		cout << num << endl;
	}
	
	return 0;
}

C++: #include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <bitset>
#include <fstream>
using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
typedef long long ll;

#define INF 1000000000

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

int main(){
    int n;

    while(cin>>n , n){
        vector<string> w(n);
        rep(i,n) cin>>w[i];

        int res;
        rep(i,n){
            int idx=0;
            int words=i;
            while(idx<5){
                int sz=0;
                while(sz < len[idx]){
                    sz += w[words++].size();
                }
                if(sz>len[idx]) break;
                idx++;
            }
            if(idx==5){res=i+1;break;}
        }

        cout<<res<<endl;

    }

    return 0;
}

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

int check(int num,int start, string w[40]){
  int count = start;
  bool flag = true;
  while(flag){
    if(count >= n){
      flag = false;
      break;
    }
    else if(num - w[count].size() == 0){
      count++;
      break;
    }
    else if(num - w[count].size() > 0){
      num -= w[count].size();
      count++;
      continue;
    }
    else {
      flag = false;
      break;
    }
  }
  if(flag) return count;
  else return -1;
}

int main(){
  string w[40];
  while(true){
    cin >> n;
    //cout << "n="<<n << endl;
    if(n == 0) break;

    for(int i = 0; i < n; i++){
      cin >> w[i];
    }

    for(int i = 0; i < n - 4; i++){
      int point = i;

      point = check(5, i, w);
      if(point == -1) continue;
      point = check(7, point, w);
      if(point == -1) continue;
      point = check(5, point, w);
      if(point == -1) continue;
      point = check(7, point, w);
      if(point == -1) continue;
      point = check(7, point, w);
      if(point != -1){
         cout << i+1 << endl;
         break;
      }
    }
  }
  return 0;
}

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

int main(void){
	int n;
	int t[] = {5,7,5,7,7};
	while(cin >> n, n){
		vector<int> v(n);
		for(int i = 0; i < n; ++i){
			string s;
			cin >> s;
			v[i] = s.size();
		}
		for(int i = 0; i < n; ++i){
			bool a = true;
			int j = i;
			int tn = 0;
			while(tn < 5){
				int sum = 0;
				while(sum < t[tn]){
					sum += v[j];
					j++;
					if(j==n)break;
				}
				if(sum == t[tn]){
					tn++;
				}else{
					a = false;
					break;
				}
			}
			if(a && tn==5){
				cout << i+1 << endl;
				break;
			}
		}
	}
	return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n;
    while(cin >> n, n){
        vector<int> v(n);
        for (int i = 0; i < n; ++i) {
            string s;
            cin >> s;
            v[i] = s.size();
        }
        vector<int> u{5, 7, 5, 7, 7, 100000};
        for (int i = 0; i < n; ++i) {
            int cur = 0, p = 0;
            int valid = true;
            for (int j = i; j < n; ++j) {
                p += v[j];
                if(u[cur] == p) cur++, p = 0;
                else if(u[cur] < p) valid = false;
            }
            if(valid && cur == 5){
                cout << i+1 << "\n";
                break;
            }
        }
    }
    return 0;
}