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 pair<int, int> C;
typedef pair<int, C> iC;
#define fs first
#define sc second

string s;
bool overflow = false;

// index, number
pair<int, int> num(int i) {
  int ret = 0;
  while ('0' <= s[i] && s[i] <= '9') {
    int x = s[i] - '0';
    ret = 10 * ret + x;
    i++;
  }

  return make_pair(i, ret);
}

C multiplication(C a, C b) {
  return C(a.fs * b.fs - a.sc * b.sc, a.fs * b.sc + a.sc * b.fs);
}

C addition(C a, C b) {
  return C(a.fs + b.fs, a.sc + b.sc);
}

C subtraction(C a, C b) {
  return C(a.fs - b.fs, a.sc - b.sc);
}

void check_overflow(C a) {
  if (a.fs < -10000 || 10000 < a.fs) overflow = true;
  if (a.sc < -10000 || 10000 < a.sc) overflow = true;
}

// index, number
pair<int, C> dfs(int i = 0, C sum = C(0, 0)) {
  iC ans = make_pair(i, C(0, 0));

  while (i < s.size()) {
     if (s[i] == '(') {
      return dfs(i + 1);
    }

    if (s[i] == ')') {
      return iC(i, sum);
    }

    if (s[i] == '*') {
      iC a = dfs(i + 1);
      return iC(a.fs, multiplication(sum, a.sc));
    }

    if (s[i] == '+') {
      iC a = dfs(i + 1);
      return iC(a.fs, addition(sum, a.sc));
    }

    if (s[i] == '-') {
      iC a = dfs(i + 1);
      return iC(a.fs, subtraction(sum, a.sc));
    }

    if ('0' <= s[i] && s[i] <= '9') {
      pair<int, int> a = num(i);
      sum.fs += a.sc;
      i = a.fs;
    }

    if (s[i] == 'i') {
      return iC(i + 1, C(0, 1));
    }
  }
  return ans;
}

int main() {
  while (cin >> s) {
    iC ans = dfs();

    if (overflow) {
      cout << "overflow" << endl;
    } else {
      int real = ans.sc.fs;
      int imag = ans.sc.sc;

      if (real && imag) {
        printf("%d%c%di\n", real, (imag > 0 ? '+' : '-'), abs(imag));
      }
      else if (real) {
        printf("%d\n", real);
      }
      else if (imag) {
        printf("%di", imag);
      }
      else {
        puts("0");
      }
    }
  }
}

C++: #include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>

using namespace std;

int ans,table[41],n;

struct Info{
	Info(int arg_start,int arg_grade,int arg_tmp){
		start = arg_start;
		grade = arg_grade;
		tmp = arg_tmp;
	}
	Info(){
		start = grade = tmp = 0;
	}
	int grade,tmp,start;
};

void recursive(int index,Info info){

	if(info.grade == 5){
		ans = min(ans,info.start);
		return;
	}

	if(index == n+1)return;

	switch(info.grade){
	case 0: //5
		if(table[index]+info.tmp < 5){
			recursive(index+1,Info(info.start,0,info.tmp+table[index]));
		}else if(table[index]+info.tmp == 5){
			recursive(index+1,Info(info.start,1,0));
		}else{
			return;
		}
		break;
	case 1: //7
		if(table[index]+info.tmp < 7){
			recursive(index+1,Info(info.start,1,info.tmp+table[index]));
		}else if(table[index]+info.tmp == 7){
			recursive(index+1,Info(info.start,2,0));
		}else{
			return;
		}
		break;
	case 2: //5
		if(table[index]+info.tmp < 5){
			recursive(index+1,Info(info.start,2,info.tmp+table[index]));
		}else if(table[index]+info.tmp == 5){
			recursive(index+1,Info(info.start,3,0));
		}else{
			return;
		}
		break;
	case 3: //7
		if(table[index]+info.tmp < 7){
			recursive(index+1,Info(info.start,3,info.tmp+table[index]));
		}else if(table[index]+info.tmp == 7){
			recursive(index+1,Info(info.start,4,0));
		}else{
			return;
		}
		break;
	case 4: //7
		if(table[index]+info.tmp < 7){
			recursive(index+1,Info(info.start,4,info.tmp+table[index]));
		}else if(table[index]+info.tmp == 7){
			recursive(index+1,Info(info.start,5,0));
		}else{
			return;
		}
		break;
	}
}


void func(){
	int length;
	char tmp[11];

	for(int loop = 1; loop <= n; loop++){
		scanf("%s",tmp);

		for(length = 0; tmp[length] != '\0'; length++);

		table[loop] = length;
	}

	for(int i = 1; i <= n-4; i++){
		recursive(i,Info(i,0,0));
	}

	printf("%d\n",ans);
}


int main(){

	while(true){
		scanf("%d",&n);
		if(n == 0)break;

		ans = 1000000;
		func();
	}
    return 0;
}

C++: #include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>

using namespace std;
using ll = long long;

int main()
{
    constexpr int len[5] = {5, 7, 5, 7, 7};
    while (true) {
        int n;
        cin >> n;
        if (n == 0) {
            break;
        }
        vector<int> l(n);
        for (int i = 0; i < n; i++) {
            string s;
            cin >> s;
            l[i] = s.size();
        }

        for (int i = 0; i < n; i++) {
            int ind = 0;
            int sum = 0;
            for (int j = i; j < n; j++) {
                if (ind == 5) {
                    break;
                }
                sum += l[j];
                if (sum > len[ind]) {
                    break;
                } else if (sum == len[ind]) {
                    ind++;
                    sum = 0;
                }
            }
            if (ind == 5) {
                cout << i+1 << endl;
                break;
            }
        }
    }

    return 0;
}