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 <vector>
#include <string>

int solve(const std::vector<int>& ls) {
	int cs[] = { 5, 12, 17, 24, 31 };
	for (int i = 0; i < ls.size(); i++) {
		int c = 0;
		int l = 0;
		for (int j = i; j < ls.size(); j++) {
			l += ls.at(j);
			if (cs[c] == l) {
				c++;

				if (c >= 5) {
					return i+1;
				}
			}
			else if (cs[c] < l) {
				break;
			}
		}
	}
	return -1;
}

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

		std::vector<int>ws;
		ws.resize(n);

		for (int i = 0; i < n; i++) {
			std::string s;
			std::cin >> s;
			ws.at(i) = s.size();
		}

		std::cout << solve(ws) << std::endl;


	}
}

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);

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

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

int main(){
  int step,flag=0,n,l,x;
  while(1){
    cin >> n;
    if(n==0){break;}
    string w[n];
    for(int i=0;i<n;i++){
      cin >> w[i];
    }
    for(int i=0;i<n;i++){
      l=0;
      step=1;
      flag=0;
      x=i;
      while(1){
        if(flag==1){break;}
        l+=w[x].length();
        switch(step){
          case 1:
          if(l>5){flag=1;}
          else if(l==5){step++;}
          break;
          case 2:
          if(l>12){flag=1;}
          else if(l==12){step++;}
          break;
          case 3:
          if(l>17){flag=1;}
          else if(l==17){step++;}
          break;
          case 4:
          if(l>22){flag=1;}
          else if(l==22){step++;}
          break;
          case 5:
          if(l>29){flag=1;}
          else if(l==29){flag=2;}
          break;
        }
        if(flag==2){break;}
        x++;
      }
      if(flag=2){x=i+1;break;}
    }
    if(flag=2){cout << x << endl;}
  }
  return 0;
}

C++: #define _USE_MATH_DEFINES
#include<stdio.h>
#include<string>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include<iomanip>
using namespace std;



int main(){
	
int n;
while(1){
	cin>>n;
	if(!n)break;
	int p[50]={};;
	for(int i=0;i<n;i++){
		string y;
		cin>>y;
		p[i]=y.size();
	}
	
	for(int i=0;i<n;i++){
		bool a=0,b=0,c=0,d=0,e=0;
		int r=0;
		for(int j=i;j<n;j++){
			r+=p[j];
			if(!a&&r==5)a++;
			if(!a&&r>5)break;
			if(r==12)b++;
			if(!b&&r>12)break;
			if(r==17)c++;
			if(!c&&r>17)break;
			if(r==24)d++;
			if(!d&&r>24)break;
			if(r==31)e++;
			if(!e&&r>31)break;
			if(a&&b&&c&&d&&e){
				cout<<i+1<<endl;
				break;
			}
		}
		if(a&&b&&c&&d&&e){
				
				break;
			}
	}

}

	return 0;
}

C++: # define _CRT_SECURE_NO_WARNINGS 1
# include <iostream>
# include <numeric>
# include <string>
# include <bitset>
# include <vector>
# include <algorithm>
# include <cstdlib>
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iomanip>
# include <queue>
# include <sstream>
# include <climits>
# include <cmath>
# include <list>
# include <functional>
# include <string>
# include <ctime>
# include <set>
# include <map>
# include <stack>
using namespace std;
//# define M_PI 3.141592
# define INF ((int)(1<<30))
# define FOR(i,n) for(int i=0;i<(int)n;i++)
# define FORI(i,k,n) for(int i=k;i<(int)n;i++)
# define toRad 2.0*M_PI/360.0
# define inin(x) int x;cin>>x;
# define all(x) x.begin(),x.end()
# define debug(x) cout<<#x<<" :"<<x<<endl;
# define rep(i,n) for(int i=0;i<(int)n;i++)
# define EPS 1e-12
# define CHECK(i,a) FOR(i,a.size())cout<<#a<<"["<<i<<"] : "<<a[i]<<endl; 
typedef vector<int> vi;
typedef vector<string> vs;

int main()
{
	int n;
	while (cin >> n&&n)
	{
		vs a;
		FOR(i, n)
		{
			string s; cin >> s;
			a.push_back(s);
		}
		FOR(i, n)
		{
			int s[5] = { 5,7,5,7,7 };
			int now = i;
			bool ok = true;
			for (int j = 0; j < 5; j++)
			{
				for (; now < n; now++)
				{
					if (s[j] == 0)break;
					if (s[j] < 0)
					{
						ok = false;
						break;
					}
					s[j] -= a[now].size();
				}
			}
			for (int j = 0; j < 5; j++)
			{
				if (s[j] != 0)ok = false;
			}
			if (ok)
			{
				cout << i + 1 << endl;
				break;
			}
		}
	}
}

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

using namespace std;

int main()
{
    int n;
    while(cin >> n, n){
	int len[] = {5, 7, 5, 7, 7};
	string w[44];
	for(int i = 0; i < n; i++) cin >> w[i];
	int ans = 0;
	for(int i = 0; i < n; i++){
	    int cnt = 0, idx = 0;
	    for(int j = i; j < n; j++){
		cnt += w[j].size();
		if(cnt == len[idx]){
		    cnt = 0, idx++;
		    if(idx == 5) break;
		}else if(cnt > len[idx]){ idx = -1; break;}
	    }
	    if(idx == 5){ ans = i; break;}
	}
	cout << ans+1 << endl;
    }
    return 0;
}

C++: #define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 0
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
bool check(int x, vector<string>v) {
	int table[] = { 5,7,5,7,7 };
	int idx = 0, tmp = 0;
	rep(i, x, v.size()) {
		tmp += v[i].size();
		if (tmp == table[idx]) {
			idx++;
			tmp = 0;
		}
		else if (tmp > table[idx]) {
			return false;
		}
		if (idx == 5) {
			return true;
		}
	}
	return false;
}
signed main() {
	int n;
	while (cin >> n, n) {
		vector<int>v; vector<string>s; v.push_back(0);
		rep(i, 0, n) {
			string t;
			cin >> t;
			s.push_back(t);
			v.push_back(t.size());
		}
		rep(i, 1, n + 1) {
			v[i] += v[i - 1];
		}
		int ans;
		for (ans = 0; ans < n + 1; ans++) {
			rep(j, ans, n + 1) {
				int x = v[j] - v[ans];
				if (x > 31)continue;
				else if (x == 31 && check(ans, s))goto there;
			}
		}

	there:; cout << ans + 1 << endl;
		dumpc(v);

	}
	return 0;
}

C++: i,j,k,L[99];main(n){for(;scanf("%d",&n)*n;i=j=k=!printf("%d\n",j)){for(;n--;scanf("%*s%n",L+i++));for(;k<7;)for(n=j++,k=i=1;i>0;)for(i=k++>5?0:k-2&&k-4?8:6;i>1;i-=L[n++]);}}