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;

int solve(int n) {
    vector<string> words(n);
    for (int i = 0; i < n; i++) {
        cin >> words[i];
    }
    int a;
    int count = 0;
    while (1) {
        int first  = 0;
        int second = 0;
        int serd   = 0;
        int forth  = 0;
        int fifth  = 0;
        for (a = count; first < 5; a++) {
            first += words[a].size();
        }
        if (first != 5) {
            count++;
            continue;
        }
        for (; second < 7; a++) {
            second += words[a].size();
        }
        if (second != 7) {
            count++;
            continue;
        }
        for (; serd < 5; a++) {
            serd += words[a].size();
        }
        if (serd != 5) {
            count++;
            continue;
        }
        for (; forth < 7; a++) {
            forth += words[a].size();
        }
        if (forth != 7) {
            count++;
            continue;
        }
        for (; fifth < 7; a++) {
            fifth += words[a].size();
        }
        if (fifth != 7) {
            count++;
            continue;
        }
        return ++count;
    }
}

int main() {
    int n;
    vector<int> ans;
    while (1) {
        cin >> n;
        if (!n) break;
        ans.push_back(solve(n));
    }
    for (int i : ans) cout << i << endl;
}

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

using namespace std;

int main() {

    int n;
    string w[40];
    int lens[] = {5, 7, 5, 7, 7};

    while(cin >> n, n) {

        for(int i = 0; i < n; ++i) {
            cin >> w[i];
        }

        for(int i = 0; i < n; ++i) {

            int len = 0, phrase = 0;

            for(int j = i; j < n; ++j) {

                len += w[j].size();

                if(len == lens[phrase]) {
                    len = 0;
                    ++phrase;
                    if(phrase == 5) {
                        cout << i + 1 << endl;
                        break;
                    }
                }
            }

            if(phrase == 5) {
                break;
            }

        }

    }

}

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <ctime>
#define INF 999999999
#define mod 1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=(n);i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define MOD(x) (x%(mod))
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool debug=false;
/*---------------------------------------------------*/

int haiku[45];
int num[6]={5,7,5,7,7,0};

void solve(int n){
  int s=0,e=0,cnt=0,sum=haiku[0];
  int dast=0;
  
  rep(i,n-5){
    dast=cnt=0;
    s=e=i;
    sum=haiku[i];
    
    while(s!=n&&e!=n){
      if(debug)cout<<"s: "<<s<<"  e:"<<e<<"  cheack( "<<cnt<<" ): "<<num[cnt]<<"  dast: "<<dast<<"  cnt: "<<cnt<<endl;
      if(cnt==5)break;
      if(sum==num[cnt]){
	s=e=e+1;sum=haiku[s];cnt++;
      }else if(sum<num[cnt]){
	e++;sum+=haiku[e];
      }else if(sum>num[cnt]){
	break;
      }
    }
    if(debug)cout<<endl;
    if(debug)cout<<"s: "<<s<<"  e:"<<e<<"  cheack( "<<cnt<<" ): "<<num[cnt]<<"  dast: "<<dast<<"  cnt: "<<cnt<<endl;
    if(cnt==5){
      cout<<i+1<<endl;
      break;
    } 
  }
}


int main(){
  int n;
  string s;
  while(cin>>n){
    if(n==0)break;
    rep(i,n){cin>>s;haiku[i]=s.size();}
    solve(n);
  }
}

C++: #include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>
#include <cmath>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <functional>
#define rep(i,n) for (int i = 0; i < (n); ++i)

using namespace std;
const int MOD = 1000000007;


typedef long long int ll; 
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;

void floatOutPutSetup(){
    cout << fixed;
    cout << setprecision(10);
}

bool isku(vector<string> w,int s){
    int cor[]={5,7,5,7,7};
    int st = s;
    vector<int> m;
    rep(i,5){
        int t = cor[i];
        int sum = 0;
        for(int o = st;;o++ ){
            sum+=w[o].size();
            if(sum == t){
                st = o+1;
                break;
            }
            else if(sum > t)return false;
        }
    }
    return true;
}

int main(){
    int n;
    cin >>n;
    while(n){
        vector<string> w(n,"");
        rep(i,n)cin >> w[i];
        rep(i,n){
            if(isku(w,i)){
                cout<<i+1<<endl;
                break;
            }
        }
        cin>>n;
    }
    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

int a[41];
int x[]={5,7,5,7,7};
int main(){
    int n;
    string s;
    while(cin>>n,n){
        rep(i,n){
            cin>>s;
            a[i]=s.size();
        }
        int ans=-1;
        rep(i,n){
            int cur=0,sum=0;
            FOR(j,i,n){
                sum+=a[j];
                if(sum>=x[cur]){
                    if(sum==x[cur]){
                        ++cur;sum=0;
                        if(cur==5){
                            ans=i+1;
                            break;
                        }
                    }
                    else break;
                }
                if(ans!=-1) break;
            }
            if(ans!=-1){
                cout<<ans<<endl;
                break;
            }
        }
    }
    return 0;
}

C++: #include <cstdio>
#include <string>
#include <vector>

int solve_testcase() {
    size_t n;
    scanf("%zu", &n);
    if (n == 0)
        return 1;

    std::vector<std::string> w(n);
    for (size_t i=0; i<n; ++i) {
        char buf[16];
        scanf("%s", buf);
        w[i] = buf;
    }

    const size_t sph[]={5, 7, 5, 7, 7};
    for (size_t res=0; res<n; ++res) {
        size_t counter=0, index=0;
        for (size_t i=0; res+i<n; ++i) {
            if (counter + w[res+i].length() > sph[index])
                break;  // match failed

            counter += w[res+i].length();
            if (counter == sph[index]) {
                ++index;
                counter = 0;
            }

            if (index == 5)
                return !printf("%zu\n", res+1);
        }
    }

    // maybe not reached
    return 0;
}

int main() {
    while (!solve_testcase()) {}

    return 0;
}