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;

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF   = 1e9;
const ll  INFLL = 1e18;
typedef pair<int, int> PII;
typedef vector<vector<int>> Graph;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

int main()
{
    ios::sync_with_stdio(false);

    vector<int> length = {5, 7, 5, 7, 7};

    int N;
    while (cin >> N || N) {
        vector<string> S(N);
        rep(i, N) cin >> S[i];

        for (int i=0; i<N; i++) {
            int current = 0;
            int step = 0;
            bool ok = false;

            for (int j=i; j<N; j++) {
                if (current < length[step]) {
                    current += S[j].size();
                }

                if (current > length[step]) {
                    step = 0;
                    current = 0;
                }
                if (current == length[step]) {
                    step++;
                    current = 0;
                }
                
                if (step == length.size()) {
                    ok = true;
                    cout << i+1 << endl;
                    break;
                }
            }
            if (ok) break;
        }
    }
}

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 <bits/stdc++.h>
using namespace std;

int cnt[501];

int main()
{
	int n;
	while (cin >> n, n) {
		fill(cnt, cnt + 501, 0);
		int p = 0;
		cnt[p] = 1;
		for (int i = 0; i < n; i++) {
			string w;
			cin >> w;
			p += w.size();
			cnt[p] = i + 2;
		}
		vector<int> v = { 5, 7, 5, 7, 7 };
		vector<int> sum(6);
		for (int i = 0; i < 5; i++) {
			sum[i + 1] = sum[i] + v[i];
		}
		for (int i = 0; i <= 400; i++) {
			bool ok = true;
			for (int j = 0; j < 6; j++) {
				ok &= cnt[i + sum[j]] > 0;
			}
			if (ok) {
				cout << cnt[i] << endl;
				break;
			}
		}
	}
	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < int(n); ++i)

int solve(int n, const vector<string>& w) {
    vector<int> five(n + 1, -1), seven(n + 1, -1);
    rep(i, n) {
        for (int j = i, l = 0; j < n && l < 7; ++j) {
            l += w[j].size();
            if (l == 5) five[i] = j;
            if (l == 7) seven[i] = j;
        }
    }
    rep (i, n) {
        int k = i;
        bool ok = true;
        rep(j, 5) {
            k = (j == 0 || j == 2 ? five[k] : seven[k]) + 1;
            if (k == 0) {
                ok = false;
                break;
            }
        }
        if (ok) return i + 1;
    }
    return -1;
}

int main() {
    for (int n; cin >> n, n;) {
        vector<string> w(n);
        for (auto& e : w) cin >> e;
        cout << solve(n, w) << endl;
    }
}

C++: #include <iostream>
#include <string>
using namespace std;
int main(void){
    int n,j,i,a[41],sum,count;
    string w[41] = {}; 
    while(1){
        
        cin >> n;
        if(n == 0) break;
        
        for(i=1;i<n+1;i++){
            cin >> w[i];
            a[i] = w[i].length();
          //  cout << w[i] << ":" << a[i] << endl;
        }
        
        sum = 0;
        count = 5;
        
        for(j = 1;j<=n-4;j++){
            sum = 0;
            count = 5;
            for(i=j;i<n+1;i++){
                
                sum = sum + a[i];
                if(sum == 5) count--;
                else if ( sum == 12) count--;
                else if ( sum == 17) count--;
                else if ( sum == 24) count--;
                else if ( sum == 31) count--;
                
     //       cout << j << ":" << sum << ":" << count  << endl;
                if ( sum >= 31) break;
        
            }
            
            if(count == 0){
                cout << j << endl;
                break;
            }
        }
        
    
    }
    return 0;
    
    
}