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;
 
int main()
{
  int n;
  string w[40];
  int lengths[] = {5, 7, 5, 7, 7};
 
  while(cin >> n, n) {
    for(int i = 0; i < n; i++) {
      cin >> w[i];
    }
    for(int i = 4; i < n; i++) {
      int beforreadidx = 4, len = 0;
      for(int j = i; j >= 0; j--) {
        len += w[j].length();
        if(lengths[beforreadidx] == len) {
          len = 0;
          beforreadidx--;
          if(beforreadidx == -1) {
            cout << j + 1 << endl;
            break;
          }
        }
      }
      if(beforreadidx == -1) break;
    }
  }
  return(0);
 
}

C++: #include<bits/stdc++.h>
#define INF 2000000000
#define int long long int
#define MOD 1000000007
#define pb push_back
#define cin1(n) (cin >> n)
#define cin2(a,b) (cin >> a >> b)
#define cin3(a,b,c) (cin >> a >> b >> c)
#define cout(n) (cout << n << endl)
#define for_(i,a,b) for(int i=(a);i<(b);++i)
#define fr first 
#define sc second 
#define EPS (1e-10)

using namespace std;

typedef vector<int> vi;
typedef vector< vector<int> > vvi;
typedef vector<pair<int,int>> vpii;
typedef vector<string> vs;
typedef vector<vector<string>> vss;
typedef pair<int,int> pii;

int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};
int n,m;
int a,b;
int p,q;


signed main() {
	while(1){
		cin1(n);
		if (n == 0) break;
		
		vs str(n);
		for_(i,0,n) {
			cin1(str[i]);
		}
		
		int ans = 0;
		for_(i,0,n) {
			int idx = 0;
			ans = i;	
			vi check = {5,7,5,7,7};
			for_(j,i,n) {
					if(check[idx] <= 0) {
						idx++;
					}
					if (idx == 6){
						break;
					}
					check[idx] -= str[j].size();
					
			}
			int sum = 0;
			for_(k,0,5) {
				sum += check[k];
			}
			if (sum == 0){
				break;
			}

		}
		cout(ans+1);
	}
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> VI;
typedef vector<VI> VVI;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max() / 2;
const int NEG_INF = numeric_limits<int>::min() / 2;
const int MOD = 1e9 + 7;

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

    int n;
    while (true)
    {
        cin >> n;
        if (n == 0)
            break;
        std::vector<string> v(n);
        for (int i = 0; i < n; i++)
        {
            cin >> v[i];
        }
        int tanku[5] = {5, 7, 5, 7, 7};
        for (int i = 0; i < n - 1; i++)
        {
            int cnt = 0, idx = 0;
            for (int j = 0; i + j < n; j++)
            {
                cnt += v[i + j].length();
                //cout<<cnt<<" "<<idx<<endl;
                if (cnt < tanku[idx])
                    continue;
                else if (cnt == tanku[idx])
                {
                    idx++;
                    cnt = 0;
                }
                else
                {
                    break;
                }
            }
            if (idx == 5)
            {
                cout << i + 1 << endl;
                break;
            }
        }
    }
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1 ; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1 ; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1e9+100;
const bool debug = 0;
/***************************************/

int N;
int wc[40];
int nec[5] = {5,7,5,7,7};

int main() {
  while (cin >> N, N) {
    REP(i, N) {
      string str;
      cin >> str;
      wc[i] = str.size();
    }
    
    int nec[5] = {5, 7, 5, 7, 7};
    bool en = false;
    REP(i, N) {
      if (en) break;
      int cur = 0, cnt = 0;
      FOR(j, i, N) {
        cnt += wc[j];
        if (cnt == nec[cur]) {
          cur++;
          cnt = 0;
          if (cur == 5) {
            cout << i + 1 << endl;
            en = true;
            break;
          }
        }
      }
    }
  }
  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int len[] = {5,7,5,7,7};
int main(){
  int n;
  while(cin >> n , n){
    string str[n+1];
    for(int i=0;i<n;i++){
      cin >> str[i];
    }
    for(int i=0;i<n;i++){
      int sum = 0;
      int idx = 0;
      bool flag = false;
      for(int j=i;j<n;j++){
	sum += str[j].size();
	if(len[idx] == sum){
	  sum = 0;
	  idx++;
	} else if(len[idx] < sum) break;
	if(idx == 5){
	  flag = true;
	  break;
	}
      }
      if(flag){
	cout << i+1 << endl;
	break;
      }
    }
  }
}

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

using namespace std;

using i64 = long long int;
using ui64 = unsigned long long int;

////////

int main(){
    int n;
    const vector<int> tanku = {5,7,5,7,7};
    while(cin >> n,n){
        vector<int> a(n);
        for(int i=0;i<n;i++){
            string s;
            cin >> s;
            a[i] = s.length();
        }
        int res = -1;
        for(int i=0;i<n;i++){
            int id = 0;
            vector<int> p = tanku;
            for(int j=i;j<n;j++){
                // cerr << i << " " << j << " " << a[j] << " " << p[id] << endl;
                if(a[j] < p[id])p[id] -= a[j];
                else if(a[j] == p[id])id++;
                else if(a[j] > p[id]){
                    // cerr << i << ": " <<  id << endl;
                    break;
                }
                if(id==p.size()){
                    res = i + 1;
                    goto output;
                }
            }
        }
output:
        cout << res << endl;
    }
}

C++: #include<iostream>
#include<math.h>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#define N (1000000000+7)
typedef long long ll;
using namespace std;

int main(void){
    int n;
    cin>>n;
    int b[5]={5,12,17,24,31};
    while(n!=0){
        string s;
        vector<int>a(n),sum(n+1);
        for(int i=0;i<n;i++){
            cin>>s;
            a[i]=s.length();
        }
        sum[0]=0;
        int num=0;
        for(int i=1;i<=n;i++){
            sum[i]=sum[i-1]+a[i-1];
        }
        for(int i=1;i<n;i++){
            num=0;
            for(int j=i;j<=n;j++){
                if(sum[j]==b[num]){
                    num++;
                    //cout<<sum[j]<<endl;
                }
                if(num==5)break;
            }
            if(num==5){
                cout<<i<<endl;
                break;
            }
            //cout<<"ks"<<endl;
            for(int k=1;k<=n;k++)sum[k]-=a[i-1];
        }
        cin>>n;
    }
    return 0;
}