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;

typedef long long ll;
typedef pair<ll, ll> P;

#define each(i,a) for (auto&& i : a)
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    each(x,vec) is >> x;
    return is;
}
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    rep(i,vec.size()) {
        if (i) os << " ";
        os << vec[i];
    }
    return os;
}
template<typename T>
ostream& operator<<(ostream& os, const vector< vector<T> >& vec) {
    rep(i,vec.size()) {
        if (i) os << endl;
        os << vec[i];
    }
    return os;
}

void solve(ll n) {
        vector<ll> v(n);
    vector<ll> w{5,7,5,7,7};
    rep(i, n) {
        string s; cin >> s;
        v[i] = s.size();
    }
    rep(i, n) {
        ll j = i;
        vector<ll> need = w;
        try {
            each(c, need) {
                while (c) {
                    if (j >= n) throw 1;
                    c -= v[j++];
                }
            }
            cout << i+1 << endl;
            return;
        }
        catch (int err) {
        }
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    while (cin >> n, n) solve(n);
}

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

int main(){
  int n;
  int d_words[5]={5,7,5,7,7};
  while(cin>>n && n!=0){
    int* n_words=new int[n];
    for(int i=0;i<n;i++){
      string str;
      cin>>str;
      n_words[i]=str.size();
    }
    int start=0;
    int success=0;
    while(!success){
      int t_words=0;
      int tmp=start;
      int tmp2=0;
      while(1){
        tmp2+=n_words[tmp];
        if(tmp2==d_words[t_words]){
          t_words++;
          if(t_words==5){
            success=start+1;
            break;
          }else if(tmp2>d_words[t_words]){
            break;
          }
        }
        tmp++;
      }
      start++;
    }
    cout<<success<<endl;
  }
}

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

int main() {
    int N;
    while (cin >> N, N) {
        vector<int> v(N);
        for (auto& i : v) {
            string str;
            cin >> str;
            i = str.size();
        }

        for (int i = 1; i < N; i++) {
            v[i] += v[i-1];
        }
        v.insert(v.begin(), 0);

        int idx = 0;
        int seq[] = {5, 12, 17, 24, 31};
        while (1) {
            bool flag = true;
            int idx_ = idx;
            for (int i = 0; flag && i < 5; i++) {
                while (idx_ < N && v[idx_] - v[idx] < seq[i]) {
                    idx_++;
                }
                if (v[idx_] - v[idx] != seq[i]) flag = false;
            }
            if (flag) break;
            idx++;
            if (N <= idx) {
                flag = false;
                break;
            }
        }

        cout << idx + 1 << endl;
    }

    return 0;
}

C++: #include <iostream>
#define REP(i, a, n) for(int i = a; i <= n; i++)
using namespace std;

int N, len[41];
int p[6] = { 0, 5, 7, 5, 7, 7 };

bool check(int s) {
  // cout << s << endl;
  REP(i, 1, 5) {
    int d = 0;
    while(s <= N) {
      d += len[s++];
      // cout << "  " << s << " " << i << " " << d << endl;
      if(d > p[i]) return false;
      if(d == p[i]) break;
    }
    if(d < p[i]) return false;
  }
  return true;
}

int main(void) {
  while(cin >> N, N) {
    REP(i, 1, N) {
      string S; cin >> S;
      len[i] = S.length();
    }

    REP(i, 1, N) {
      if(!check(i)) continue;
      cout << i << endl;
      goto CONTINUE;
    }

CONTINUE: continue;
  }

  return 0;
}

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

int main(){
        string str;
        int i,j,sum,ans,n,x,flg;
        int a[40];

        while(1) {
                cin>>n;

                if(n==0) {
                        break;
                }

                for(i=0; i<n; i++) {
                        cin>>str;
                        a[i]=str.length();
                }

                for(i=0; i<n; i++) {
                        sum=0;
                        flg=1;
                        for(j=i; j<n; j++) {
                                sum=sum+a[j];
                                if(sum==5||sum==12||sum==17||sum==24||sum==31) {
                                        flg++;
                                }
                        }
                        if(flg==6) {
                                cout<<i+1<<endl;
                                break;
                        }
                }
        }
}