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>
using namespace std;

const int tanka[] = {5, 7, 5, 7, 7};

int main() {
    int n;
    while(cin >> n, n) {
        vector<int> len(n);
        for (int i = 0; i < n; i++) {
            string s; cin >> s;
            len[i] = s.size();
        }

        for (int i = 0; i < n; i++) {
            int idx = i;
            bool flag = true;
            for (int j = 0; flag && j < 5; j++) {
                int x = 0;
                while(idx < n && x < tanka[j]) {
                    x += len[idx];
                    idx++;
                }
                if (x != tanka[j]) flag = false;
            }
            if (flag) {
                cout << i + 1<< endl;
                break;
            }
        }
    }
}

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]) {
                    break;
                }

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

C++: #include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <queue>
#include <map>
#include <set>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define INF 1<<30
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main() {
	int n;
	while(cin >> n && n) {
		vector<string> v(n);
		rep(i, n) cin >> v[i];

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

		rep(i, n) {
			int j = i;
			bool flag = true;
			rep(k, 5) {
				string  s = "";
				while(s.size() < a[k]) {
					s += v[j];
					j++;
				}
				if(s.size() == a[k]) continue;
				flag = false;
				break;
			}
			if(flag) {
				cout << i + 1 << endl;
				break;
			}
		}
	}


	return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
const long double PI = acos(-1);
typedef long long ll;
typedef pair<int64_t,int64_t> pll;
int dx[]={1,-1,0,0,1,-1,1,-1};
int dy[]={0,0,1,-1,1,-1,-1,1};
#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define ALL(a) begin(a),end(a)
#define sz(s) (s).size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second


int main()
{
    int n;
    while(cin>>n,n)
    {
        int a[n];
        REP(i,n)
        {
            string s;
            cin>>s;
            a[i]=s.size();
        }
        rep(i,0,n-4)
        {
            int j=i;
            int sum=0;
            while(sum<5){sum+=a[j];j++;}
            if(sum!=5)continue;;sum=0;
            while(sum<7){sum+=a[j];j++;}
            if(sum!=7)continue;sum=0;
            while(sum<5){sum+=a[j];j++;}
            if(sum!=5)continue;sum=0;
            while(sum<7){sum+=a[j];j++;}
            if(sum!=7)continue;sum=0;
            while(sum<7){sum+=a[j];j++;}
            if(sum!=7)continue;sum=0;
            cout<<i+1<<endl;break;
        }
    }
    
}

C++: #include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int n;
string s[40];

bool find(int st) {
	int cnt[5] = {5, 7, 5, 7, 7};
	int cor = 0;
	
	for (int i = st; i < n; i++) {
		cnt[cor] -= (int)s[i].length();
		if (cnt[cor] < 0) return false;
		if (cnt[cor] == 0) cor++;
		if (cor == 5) return true;
	}
	return false;
}

int main() {
	while (cin >> n) {
		if (!n) break;
		int i, j;
		
		for (i = 0; i < n; i++) cin >> s[i];
		
		for (i = 0; ; i++) {
			if (find(i)) {
				break;
			}
		}
		cout << i + 1 << endl;
	}
	return 0;
}

C++: #include <iostream>
#include <string>

using namespace std;

int N;
int length[44];

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

int search_len(int s,int l){
    int total=0;
    while(s<=N&&total<l) {
        total+=length[s];
        s++;
    }

    if (total==l) return s;
    else return -1;
}

bool judge(int s){
    int next=s;
    for(int i=0;i<5;i++){
        auto temp=search_len(next,len[i]);
        if (temp==-1) return false;
        next=temp;
    }
    return true;
}

int main(){
    string buf;

    while(true){
        cin>>N;
        if (N==0) break;
        for(int i=1;i<=N;i++){
            cin>>buf;
            length[i]=buf.size();
        }

        int i=1;
        while(i<=N){
            if (judge(i)) {
                printf("%d\n",i);
                break;
            }
            i++;
        }
    }

    return 0;
}

C++: #include <bits/stdc++.h>
#define rep(i,j) for (int (i)=0;(i)<(int)(j);++(i))
#define put(i) cout << (i) << endl
using namespace std;
typedef long long ll;

int main() {
    int n;
    while (cin >> n, n) {
        vector<string> w(n);
        rep(i,n) cin >> w[i];

        int start = 0;
        while (start++ < n) {
            int cnt = 0, f = 1;
            vector<int> lens(5, 0);
            for (int j = start-1; j < n; ++j) {
                lens[cnt] += w[j].length();
                switch (cnt) {
                    case 0:
                    case 2: if (lens[cnt] == 5) { cnt++; } else if (lens[cnt] > 5) { f = 0; j = n+1; } break;
                    case 4: if (lens[cnt] == 7) { j = n+1; } else if (lens[cnt] > 7) { f = 0; j = n+1; } break;
                    default: if (lens[cnt] == 7) { cnt++; } else if (lens[cnt] > 7) { f = 0; j = n+1; } break;
                }
            }
            if (f) {
                cout << start << endl;
                break;
            }
        }
    }
}