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

int main()
{
	int n,k,l,m,q,p,a[205],b[205],i,j;
	string s;
	m=0;
	do{
		cin >> n;
		for(i=0; i<n; i++)
		{
			cin >> s;
			a[i]=s.size();
		}
		for(i=0; i<n-4; i++)
		{
			p=0;
			for(j=i; j<=n-4; j++)
			{
				p+=a[j];
				if(p>=5) break;
			}
			if(p==5)
			{
				p=0;
				for(k=j+1; k<=n-3; k++)
				{
					p+=a[k];
					if(p>=7) break;
				}
				if(p==7)
				{
					p=0;
					for(j=k+1; j<=n-2; j++)
					{
						p+=a[j];
						if(p>=5) break;
					}
					if(p==5)
			{
				p=0;
				for(k=j+1; k<=n-1; k++)
				{
					p+=a[k];
					if(p>=7) break;
				}
				if(p==7)
				{
					p=0;
					for(j=k+1; j<=n; j++)
					{
						p+=a[j];
						if(p>=7) break;
					}
					if(p==7) goto shilj;
				}
			}
				}
			}
		}
		
		shilj: b[m]=i+1;
		m++;
	}while(n!=0);
	for(i=0; i<m-1; i++)
		cout << b[i] << "\n";
}

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

using namespace std;

namespace {

    typedef double real;
    typedef long long ll;

    template<class T> ostream& operator<<(ostream& os, const vector<T>& vs) {
        if (vs.empty()) return os << "[]";
        os << "[" << vs[0];
        for (int i = 1; i < vs.size(); i++) os << " " << vs[i];
        return os << "]";
    }
    template<class T> istream& operator>>(istream& is, vector<T>& vs) {
        for (auto it = vs.begin(); it != vs.end(); it++) is >> *it;
        return is;
    }

    int N;
    vector<string> W;
    bool input() {
        cin >> N;
        if (N == 0) return false;
        W.clear(); W.resize(N); cin >> W;
        return true;
    }

    bool check(int i) {
        const vector<int> a = {5, 7, 5, 7, 7};
        int j = 0;
        int c = 0;
        while (j < 5) {
            c += W[i].size();
            if (c < a[j]) {
                i++;
            } else if (c == a[j]) {
                i++;
                j++;
                c = 0;
            } else {
                assert(c > a[j]);
                return false;
            }
        }
        return true;
    }

    void solve() {
        for (int i = 0; i < N; i++) {
            if (check(i)) {
                cout << i + 1 << endl;
                return;
            }
        }
        assert(false);
    }
}

int main() {
    while (input()) solve();
    return 0;
}

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


using namespace std;
typedef long long ll;
ll n,m,a,b;
ll i,j,k;
ll x[100005],y[100005];
char s[100];

bool solve(){
	cin >> n ;
	if(n == 0){
		return false;
	}
	ll ans = 0;
	for(i=0;i<100;i++){
		x[i] = 0;
		y[i] = 0;
	}
	for(i=0;i<n;i++){
		cin >> s;
		m = strlen(s);
		x[i] = m;
	}
	for(i=0;i<n;i++){
		ll sum = 0;
		ll a = 0;
		bool ok = false;
		for(j=i;j<n;j++){
			sum += x[j];
			if(sum == 5)a++;
			if(sum == 12)a++;
			if(sum == 17)a++;
			if(sum == 24)a++;
			if(sum == 31){
				a++;
				if(a == 5){
					ok = true;
					break;
				}else{
					ok = false;
					break;
				}
			}
			if(sum >= 32 && a <= 4){
				ok = false;
				break;
			}
		}
		if(ok){
			cout << i+1 << endl;
			return true;
		}else{
			//cout << "dame" << endl;
		}
	}

}


int main(){
	while(solve());
	return 0;
	
}

C++: /*  -*- coding: utf-8 -*-
 *
 * 1601.cc: Short Phrase
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 40;
const int K = 5;
const int ts[K] = { 5, 7, 5, 7, 7 };

/* typedef */

/* global variables */

char s[16];
int wls[MAX_N];

/* subroutines */

/* main */

int main() {
  for (;;) {
    int n;
    scanf("%d", &n);
    if (n == 0) break;

    for (int i = 0; i < n; i++) {
      scanf("%s", s);
      wls[i] = strlen(s);
    }

    for (int st = 0; st < n; st++) {
      int k = 0, sum = 0;
      for (int i = st; i < n && k < K; i++) {
	sum += wls[i];
	if (sum == ts[k])
	  k++, sum = 0;
	else if (sum > ts[k])
	  break;
      }

      if (k == K && sum == 0) {
	printf("%d\n", st + 1);
	break;
      }
    }
  }
  return 0;
}

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

bool checkCount(int& index, int wantNum, vector<int> v) {
    int sumLength = 0;
    // cout << "index: " << v[index] << " wantNum = " << wantNum << endl;
    for (int i = index; i < v.size(); i++) {
        sumLength += v[i];
        // cout << sumLength << endl;
        if (sumLength >= wantNum) {
            if (sumLength == wantNum) {
                index = i + 1;
                return true;
            }
            return false;
        }
    }
}

int solve(vector<int> v) {
    int right = 0;
    int sumLength = 0;
    for (int left = 0; left < v.size(); ++left) {
        while (right < v.size() && (sumLength + v[right] <= 5)) {
            sumLength += v[right];
            right++;
        }
        if (sumLength == 5) {
            int index = right;
            if (checkCount(index, 7, v)) {
                if (checkCount(index, 5, v)) {
                    if (checkCount(index, 7, v)) {
                        if (checkCount(index, 7, v)) {
                            return left + 1;
                        }
                    }
                }
            }
        }
        if (right == left)
            ++right;
        else
            sumLength -= v[left];
    }

    return 0;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    while (1) {
        int N;
        cin >> N;
        if (!N) break;
        vector<int> tanku(N);
        for (int i = 0; i < N; i++) {
            string ku;
            cin >> ku;
            tanku[i] = ku.size();
        }
        cout << solve(tanku) << endl;
    }
}