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 <cmath>
#include <vector>
#include <string>
using namespace std;
 
int main() {
    int n;
    while(cin >> n, n) {
        vector<int> S(n+1);
        string str;
        cin >> str;
        S[0] = 0;
        S[1] = str.size();
        for(int i=2; i<=n; ++i) {
            cin >> str;
            S[i] = S[i-1] + str.size();
        }
        int tmp[5] = {5, 7, 5, 7, 7};
        int ret = 0;
        bool finished = false;
        for(int i=0; i<=n; ++i) {
            if(finished) break;
            int current=i;
            int current_haiku = 0;
            int offset=1;
            ret = i;
            while(current+offset <= S.size()) {
                if(S[current+offset] - S[current] == tmp[current_haiku]) {
                    current += offset;
                    offset = 1;
                    current_haiku++;
                    if(current_haiku == 5) {
                        finished = true;
                        break;
                    }
                } else if(S[current+offset] - S[current] > tmp[current_haiku]) {
                    break;
                } else {
                    offset++;
                }
            }
        }
        cout << ret+1 << endl;
    }
}

C++: #include<iostream>
#include<cstdlib>
#include<cstring>
#include<queue>
using namespace std;

const int maxn = 1000;
string str;
int n;
int mem[maxn];
int sum[maxn];
int memo[40];
queue<int> que;

bool check()
{
	int cnt = 0;
	if(memo[5]) cnt++;
	if(memo[12]) cnt++;
	if(memo[17]) cnt++;
	if(memo[24]) cnt++;
	if(memo[31]) cnt++;

	memo[5] = 0;
	memo[12] = 0;
	memo[17] = 0;
	memo[24] = 0;
	memo[31] = 0; 

	if(cnt == 5) return true;
	else return false;
}

int solve()
{
	for(int i = 0; i <= n; i++)
	{
		if(n >= 1) sum[i] = sum[i-1] + mem[i-1];
		else sum[i] = 0; 
	}

	for(int i = 0; i <= n; i++)
		for(int j = i+5; j <= n; j++)
		{
			if(sum[n] - sum[i] < 31) break;
			int d = sum[j]-sum[i];
			if(d > 31) break;
			else if(d == 31) que.push(i); 
		}
 
	int p, np; 
	while(!que.empty())
	{
		p = que.front(); que.pop();
		np = p + 1;
		//cout << "np " << np << endl;
		int total = 0;
		while(total!=31)
		{
			total += mem[p++];
			memo[total] = 1;
		}
		if(check()) return np;
	}
	return np;
}

bool Input()
{
	scanf("%d", &n); getchar();
	if(!n) return false;
	for(int i = 0; i < n; i++)
	{
		getline(cin, str); 
		mem[i] = str.length();
	}
	return true;
}

void Init()
{
	memset(mem, 0, sizeof(mem));
	memset(sum, 0, sizeof(sum));
	memset(memo, 0, sizeof(memo));
	while(!que.empty()) que.pop();
}

void Print()
{
	cout << "show" << endl;
	for(int i = 0; i <= n; i++)
	{
		printf("%d ", sum[i]);
	}
	cout << endl;
}

int main()
{
	//freopen("my.txt", "w", stdout);
	while(1)
	{
		Init();
		if(!Input()) break;
		printf("%d\n", solve());
		//Print();
	}
	return 0;
}

C++: #include<cstdio>
using namespace std;

int n;
int s[40];

int size(char *w) {
  int counter = 0;
  while (w[counter] != 0) counter++;
  return counter;
}

bool ok(int f, int s) {
  if (s <= 5) return true;
  if (f >= 5 && s <= 12) return true;
  if (f >= 12 && s <= 17) return true;
  if (f >= 17 && s <= 24) return true;
  if (f >= 24 && s <= 31) return true;
  return false;
}

int main() {
  while (1) {
    scanf("%d", &n);
    if (n == 0) break;
    for (int i = 0; i < n; i++) {
      char w[15];
      scanf("%s", w);
      s[i] = size(w);
    }
    for (int i = 0; i < n; i++) {
      int sum = 0;
      for (int j = i; j < n; j++) {
        if (!ok(sum, sum + s[j])) break;
        sum += s[j];
        if (sum == 31) break;
      }
      if (sum == 31) {
        printf("%d\n", i + 1);
        break;
      }
    }
  }
}

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

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

int main(){
    
    for(int n; 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++){
            int flg = 0;
            int x = 0, y = 0;
            for(int j = i; j < n; j++){
                x += v[j];
                if(x > tanku[y])break;
                if(x == tanku[y]){
                    x = 0;
                    y++;
                }
                if(y == 5){
                    flg = 1;
                    break;
                }
            }
            if(flg){
                cout << i + 1 << endl;
                break;
            }
        }
    }

    return 0;
}

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

int main(){
    while(1) {
        int n;
        cin >> n;

        if (n == 0) break;

        vector<int> tmp(n);

        for (int i = 0; i < n; i++){
            string s;
            cin >> s;
            tmp[i] = (int)s.size();
        }

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

            int cnt = i;

            int check = 0;
            while (check < 5){
                check += tmp[cnt];
                cnt++;
            }
            if (check != 5) continue;

            check = 0;
            while (check < 7){
                check += tmp[cnt];
                cnt++;
            }
            if (check != 7) continue;

            check = 0;
            while (check < 5){
                check += tmp[cnt];
                cnt++;
            }
            if (check != 5) continue;

            check = 0;
            while (check < 7){
                check += tmp[cnt];
                cnt++;
            }
            if (check != 7) continue;

            check = 0;
            while (check < 7){
                check += tmp[cnt];
                cnt++;
            }
            if (check != 7) continue;

            cout << i + 1 << endl;
            break;
        }
    }
}

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

using namespace std;

using ll = long long;
#define rep(i,n) for(int i = 0; i < n ;++i)
#define all(v) v.begin(),v.end()

int main() {
  int n;
  while(cin >> n) {
    if (n == 0) {
      break;
    }
  vector<string> w(n);
  vector<int> d(n);
  for (int i =0; i < n; i++) {
    cin >> w[i];
    d[i] = w[i].size();
  }
  for (int i = 0; i < n; i++) {
    bool h = true;
    int st[5] = {0};
    int lm[5] = {5, 7, 5, 7, 7};
    int a = 0;
    for (int j = i; j < n; j++) {
      for (int k = a; k < 5; k++) {
        if (st[k] < lm[k]) {
          st[k] += d[j];
          break;
        } else if (st[k] > lm[k]) {
          h = false;
          break;
        }
        a++;
      }
      if (!h) {
        break;
      } else if (a == 5) {
        break;
      }
    }
    if (h) {
      cout << i+1 << endl;
      break;
    }
  }
  }
  return 0;
}