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>
using namespace std;
int n,w[10000];
string str,kari;
int main(){

  cin >> n;
  while( n != 0){
    fill_n(w,10000,0);
    w[0] = 1;

    for(int i = 0;i < n;i++){
      cin >> kari;
      if(i != 0) w[str.size()] = i+1;
      str += kari;
    }
    
    w[str.size()]=n+1;
    
    for(int i = 0;i <= str.size()-31;i++){
      if(w[i]!=0&&w[i+5]!=0&&w[i+12]!=0&&w[i+17]!=0&&w[i+24]!=0&&w[i+31]!=0){
	cout << w[i] << endl;
	break;
      }
    }
    cin >> n;
  }
  return (0);
}

C++: s[50],j,p,q;
main(i){for(;p=atoi(gets(s));printf("%d\n",i)){
for(i=0;i<p;s[i++]=strlen(gets(s+i)));
for(i=j=0;j<7;)for(p=i++,j=q=1;q>0;)for(q=(0x886860>>j++*4)&15;q>1;q-=s[p++]);
}}

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

int main(){
  while(true){
    int n;
    cin >> n;
    if(n == 0)
      break;

    vector<string> w(n);
    for(int i=0; i<n; i++)
      cin >> w[i];
         
    int tanku[5] = {5, 7, 5, 7, 7};
    bool judge = false;
    for(int i=0; i<n; i++){
      int place = i;
      for(int j=0; j<5; j++){
	int sum = 0;
	while(place <= n-1){
	  sum += w[place].size();
	  place++;
	  if(j == 4 && sum == tanku[j]){
	    cout << i+1 << endl;
	    judge = true;
	    break;
	  }
	  if(sum >= tanku[j])
	    break;
	}
	if(sum > tanku[j])
	  break;
      }
      if(judge == true)
	break;
    }
  }
  
  return 0;
}

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

#define ALL(a) (a).begin(), (a).end()
#define ll long long

using namespace std;

signed main(){
    while(true){
        int n; cin >> n;
        if(n == 0)break;
        vector<string> s(n);
        int key[5] ={ 5, 7,5,7,7};
        for(int i = 0; i < n; i++)cin >> s[i];
        for(int i = 0; i < n; i++){
            if(s[i].size() > key[0])continue;
            int c = 0,k = i;
            for(int j = 0; j < 5; j++){
                c = 0;
                while(c < key[j] && k < n){
                    c += s[k].size();
                    k++;
                }
                if(c != key[j]){
                    c = -1;
                    break;
                }
            }
            if(c != -1){
                cout << i+1 << endl;
                break;
            }
        }
    }
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
void format(int a[]){
  for(int i=0;i<5;i++){
    if(i==0||i==2)
      a[i]=5;
    else
      a[i]=7;
  }
}
int main(){
  int n;
  while(cin>>n,n!=0){
    string word[n];
    for(int i=0;i<n;i++)
      cin>>word[i];
    int cnt[n];
    format(cnt);
    for(int j=0;j<n;j++){
      int flag=0;
      format(cnt);
      int pointer=0;
      for(int i=j;i<n;i++){
	cnt[pointer]-=word[i].size();
	if(cnt[pointer]<0)
	  break;
	else if(cnt[pointer]==0&&pointer==4){
	  cout<<j+1<<endl;flag=1;break;
	}else if(cnt[pointer]==0)
	  pointer++;
      }
      if(flag==1)
	break;
    }
  }
  return 0;
}

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

#define for_(i,a,b) for(int i=(a);i<(b);++i)

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

int main() {
	int n;
	while (cin >> n) {
		if (n == 0) break;
		vector< string > s(n);
		for_(i,0,n) cin >> s[i];
		
		for_(i,0,n) {
			int p = 0, sum = 0;
			for_(j,i,n) {
				sum += s[j].size();
				if (sum > len[p]) break;
				if (sum == len[p]) {
					sum = 0;
					++p;
				}
			}
			
			if (p == 5) {
				cout << i + 1 << endl;
				break;
			}
		}
	}
}

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

int main(){
  vector<int> num = {5, 7, 5, 7, 7};
  int n;
  while(std::cin >> n, n){
    vector<string> vs(n);
    for (int i = 0; i < n; i++) std::cin >> vs[i];
    for (int i = 0; i < n; i++) {
    int sum = 0, pos = 0;
      for (int j = i; j < n; j++) {
        sum += vs[j].size();
        if(sum == num[pos])sum = 0, pos++;
        if(pos == 5){
          std::cout << i + 1 << std::endl;
          i = j = 1e9;
        }
      }
    }
  }
  return 0;
}

C++: #include <stdio.h>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
	while(1){
		int n; cin >> n;
		if(!n) return 0;
		vector<int>z;
		for(int i=0;i<n;i++){
			string a; cin >> a; z.push_back(a.size());
		}
		for(int i=0;i<n;i++){
			int cur = 0; int cnt = 0;
			for(int j=i;j<z.size();j++){
				cur += z[j];
				if(cur < 5) continue;
				if(cur > 7) goto fail;
				if(cur == 5 && (cnt==0||cnt==2)){
					cnt++; cur = 0;
				}
				else if(cur == 7 && (cnt==1||cnt==3||cnt==4)){
					cnt++; cur = 0;
				}
				if(cnt == 5){
					printf("%d\n",i+1); goto nxt;
				}
			}
		  fail:;
		}
	  nxt:;
	}
}

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

using std::cin;
using std::cout;
using std::endl;

bool check_tanku(std::vector<std::string> v, int ind) {
	int piv = 0;
	int n = v.size();
	int l = 0;
	for (int i = ind+piv; i < n && l < 5; i++) {
		l += v[i].length();
		if (l > 5) {
			return false;
		}
		piv++;
	}
	l = 0;
	for (int i = ind+piv; i < n && l < 7; i++) {
		l += v[i].length();
		if (l > 7) {
			return false;
		}
		piv++;
	}
	l = 0;
	for (int i = ind+piv; i < n && l < 5; i++) {
		l += v[i].length();
		if (l > 5) {
			return false;
		}
		piv++;
	}
	l = 0;
	for (int i = ind+piv; i < n && l < 7; i++) {
		l += v[i].length();
		if (l > 7) {
			return false;
		}
		piv++;
	}
	l = 0;
	for (int i = ind+piv; i < n && l < 7; i++) {
		l += v[i].length();
		if (l > 7) {
			return false;
		}
		piv++;
	}

	return true;
}

int main(void) {
	int n;
	int limit = 31;
	cin >> n;

	while ( n != 0 ) {
		std::vector<std::string> tan(n);
		std::vector<int> len(n,0);
		bool find = false;
		for (int i = 0; i < n; i++) {
			cin >> tan[i];
		}

		for (int i = 0; i < n; i++) {
			for (int j = i; j < n && len[i] < limit; j++) {
				len[i] += tan[j].length();
			}
		}

		int temp;
		for (int i = 0; i < n && !(find); i++) {
			if (len[i] == limit) {
				if (check_tanku(tan,i)) {
					cout << i+1 << endl;
					find = true;
				}
			}
		}

		cin >> n;
	}

	return 0;
}

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


vector<string> goku;

int checkKu(int bgn, int chlen) {
	int len = 0;
	int i = 0;
	while (1) {
		len += goku[bgn+i].size();
		i+=1;
		if (len > chlen)return -1;
		else if (len == chlen)return i;
	}
}

bool solve(int start) {
	int Ku[5] = { 5,7,5,7,7 }, k = start;
	for (int i = 0; i < 5; i++) {
		int j = checkKu(k, Ku[i]);
		//cout << j << endl;
		if (j > 0)k += j;
		else return false;
	}
	return true;
}

int main() {

	while (1) {
		int n;
		goku.clear();
		cin >> n;
		if (n == 0)break;
		//input
		for (int i = 0; i < n; i++) {
			string str;
			cin >> str;
			goku.push_back(str);
		}

		int s = 0;
		while (1) {
			if (solve(s))break;
			else s++;
		}
		cout << s + 1 << endl;
	}
	return 0;
}