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 <algorithm>
#include <vector>
using namespace std;
using ll = long long;
int main(void){
	while(1){
		int n,sum,flag;
		string str;
		cin >> n;
		if(n==0)	break;
		vector<int> len(n);
		for(int i=0;i<n;i++){
				cin >> str;
				len[i] = str.size();
		}
		for(int i=0;i<n;i++){
			sum=0;
			flag=0;
			for(int j=i;(j<n&&sum<=7);j++){
				sum+=len[j];
				if(sum==5&&flag==0){
					flag=1;
					sum=0;
				}
				if(sum==7&&flag==1){
					flag=2;
					sum=0;
				}
				if(sum==5&&flag==2){
					flag=3;
					sum=0;
				}
				if(sum==7&&flag==3){
					flag=4;
					sum=0;
				}
				if(sum==7&&flag==4){
					cout << i+1 << endl;
					flag=5;
				}
			}
			if(flag==5)	break;
		}
	}
	return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<list>
using namespace std;
int main() {
	int n;
	while (cin >> n&&n != 0) {
		string a[40];
		for (int i = 0; i < n; i++) {
			cin >> a[i];
		}
		int ans = 0;
		for (int i = 0; i < n; i++) {
			int sum=0;
			int i2 = -1;
			for (int j = i; j < n; j++) {
				sum += a[j].length();
				if (sum == 5) {
					i2 = j+1;
					break;
				}
			}
			if (i2 == -1) goto stop;
			if (i2 != -1) {
				sum = 0;
				for (int i = i2; i < n; i++) {
					sum += a[i].length();
					if (sum == 7) {
						i2 = i + 1;
						break;
					}
					i2 = -1;
				}
				if (i2 == -1) goto stop;
				sum = 0;
				for (int i = i2; i < n; i++) {
					sum += a[i].length();
					if (sum == 5) {
						i2 = i + 1;
						break;
					}
					i2 = -1;
				}
				if (i2 == -1) goto stop;
				sum = 0;
				for (int i = i2; i < n; i++) {
					sum += a[i].length();
					if (sum == 7) {
						i2 = i + 1;
						break;
					}
					i2 = -1;
				}
				if (i2 == -1) goto stop;
				bool l = true;
				sum = 0;
				for (int i = i2; i < n; i++) {
					sum += a[i].length();
					if (sum == 7) {
						i2 = i + 1;
						break;
					}
					i2 = -1;
				}
				if (i2 == -1) goto stop;
				ans = i;
				break;
			}
		stop:;
		}
		cout << ans+1 << endl;
	}
}

C++: #include <iostream>
#include <functional>
#include <algorithm>
#include <string>
using namespace std;
int num[5] = { 5,7,5,7,7 };
int main() {
	int n;
	int w[53];
	while (1) {
		cin >> n;
		if (n == 0)break;
		string s;
		for (int i = 0; i < n; i++) {
			cin >> s;
			w[i] = s.length();
		}
		for (int i = 0; i < n; i++) {
			int now = i;
			int x = 0;
			int cnt = 0;
			int judge = 0;
			while (1) {
				if (x == 5) {
					judge = 1;
					break;
				}
				cnt += w[now++];
				if (cnt == num[x]) {
					cnt = 0;
					x += 1;
				}
				if (cnt > num[x] || (now >= n&&x!=5))break;
			}
			if (judge == 1) {
				cout << i + 1 << "\n";
				break;
			}
		}
	}
}

C++: #include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

int main(void){
    while(true){
        int n; cin >> n;
        if(n == 0) return 0;
        else{
            vector<string> s(n);
            vector<int> A(n);
            REP(i, n) cin >> s[i];
            REP(i, n) A[i] = s[i].size();
            int ans;
            bool ok = false;
            REP(i, n + 1){
                int a = 0;
                bool tanka =  false;
                int now = 0; 
                FOR(j, i, A.size()){
                    a += A[j];
                    if(a > 7) break;
                    if((now == 0 or now == 2) and a == 5){
                        now++;
                        a = 0;
                    }
                    if((now == 1 or now == 3) and a == 7){
                        now++;
                        a = 0;
                    }
                    if(now == 4 and a == 7){
                        ok = true;
                        ans = i + 1;
                        break;
                    }
                }
                if(ok) break;
            }
            cout << ans << endl;
        }
    }
}

C++: #include<bits/stdc++.h>
int i,j,p,n,q,a[9]={5,7,5,7,7,-1},d[50];char s[50];
main(){for(;scanf("%d\n",&n),n;){for(i=0;i<n;)d[i++]=strlen(gets(s));
for(i=j=0;j<6;i++)for(p=i,j=q=0;q>=0;)for(q=a[j++];q>0;q-=d[p++]);
printf("%d\n",i);
}}

C++: #include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<ll,pll> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-11;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

const int NPrime=3000000;
bool prime[NPrime+1];
vi EnumeratePrime(){
	fill(prime+2,prime+NPrime+1,true);
	vi a;
	for(int i=2;i<=NPrime;i++) if(prime[i]){
		a.emplace_back(i);
		for(int j=2*i;j<=NPrime;j+=i) prime[j]=0;
	}
	return a;
}

int n;

int main(){
	while(1){
		cin>>n;
		if(n==0) break;
		vi a(n);
		for(int i=0;i<n;i++){
			string s;
			cin>>s;
			a[i]=s.size();
		}
		int b[5]={5,7,5,7,7};
		for(int i=0;i<n;i++){
			int I=i;
			bool B=1;
			for(int j=0;j<5;j++){
				int t=0;
				while(t<b[j]&&I<n) t+=a[I++];
				if(t!=b[j]){
					B=0;
					break;
				}
			}
			if(B){
				cout<<i+1<<endl;
				break;
			}
		}
	}
}