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<math.h>
#include<iomanip>
#include<string>
#include<fstream>
using namespace std;

int main(){
  //std::ifstream in("test.txt");
  //  std::cin.rdbuf(in.rdbuf());
  int n;
  string inp;
  int set[5]={5,12,17,24,31};
  while(1){
    cin >> n;
    if(n==0)return 0;

    //int list[n];
    int shori[n];
    
    int size;
    int ans=0;
    //  int num=0;
    for(int i=0;i<n;i++){
      cin >> inp;
      if(ans==-1)continue;
      size=inp.size();
      shori[i]=0;
      //cout << list[i] << endl;
      for(int j=0;j<=i;j++){
	if(shori[j]==-1)continue;
       
        for(int l=0;l<5;l++){
	  if(shori[j]<set[l]){
	    if(size<=set[l]-shori[j]){
	      shori[j]+=size;
	      break;
	    }else{
	      shori[j]=-1;
	      break;
	    }
	  }
	}
	if(shori[j]==set[4]){
	  cout << j+1 << endl;
	  ans=-1;
	  break;
	}
      }
      
   
    }
 
  }
      
}

C++: #include <iostream>
using namespace std;
int main(){
  int n;
  while(cin >> n, n){
    string w[n];
    for(int i = 0; i < n; ++i){
      cin >> w[i];
    }
    int phrase[] = {5,7,5,7,7};
    bool f = false;
    for(int i = 0; i < n; ++i){
      if(f) break;
      int s = 0, t = 5;
      for(int j = i; j < n; ++j){
	t -= w[j].size();
	if(!t){
	  ++s;
	  if(s == 5){
	    cout << i+1 << endl;
	    f = true;
	    break;
	  }
	  t = phrase[s];
	}else if(t < 0) break;
      }
    }
  }
  return 0;
}

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

using namespace std;

int solve(vector<int> &a)
{
    int N = a.size();
    const int p[] = {5, 7, 5, 7, 7};
    for (int i = 0; i < N; i++) {
        bool poss = 1;
        int q = i;
        for (int j = 0; j < 5; j++) {
            int sum = 0;
            for (; q < N; ) {
                sum += a[q++];
                if (sum >= p[j]) break;
            }
            if (sum != p[j]) {
                poss = 0;
                break;
            }               
        }
        if (poss) {
            return i + 1;
        }
    }
    return -1;
}

int main()
{
    int N;
    while (cin >> N, N) {
        vector<int> a(N);
        string s;
        for (int i = 0; i < N; i++) {
            cin >> s;
            a[i] = s.size();
        }
        cout << solve(a) << endl;
    }
    return 0;
}

C++: #include<iostream>
#include<vector>
#include<string>
using namespace std;
int main(void){
int n;
int tanku[]={5,7,5,7,7};
while(1){
cin>>n;
if(n==0)break;
string a;
vector<int> w(n);
for(int i=0;i<n;i++){
	cin>>a;
	w[i]=a.size();
}
int plase;
for(int i=0;i<n;i++){
plase=i;
int sum=0;
int k=0;
bool flag=false;
for(int j=i;j<n;j++){
sum+=w[j];
if(sum>tanku[k])break;
if(sum==tanku[k]){
	k++;
	sum=0;
}
if(k==5){
	flag=true;
	break;
}
}
if(flag){
	cout<<i+1<<endl;
	break;
}
}
}	
return 0;
}

C++: /* template.cpp {{{ */
#include <bits/stdc++.h>
using namespace std;
#define get_macro(a, b, c, d, name, ...) name
#define rep(...) get_macro(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep(...) get_macro(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define rep1(n) rep2(i_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, b) rep4(i, a, b, 1)
#define rep4(i, a, b, s) for (ll i = (a); i < (ll)(b); i += (ll)(s))
#define rrep1(n) rrep2(i_, n)
#define rrep2(i, n) rrep3(i, 0, n)
#define rrep3(i, a, b) rrep4(i, a, b, 1)
#define rrep4(i, a, b, s) for (ll i = (ll)(b) - 1; i >= (ll)(a); i -= (ll)(s))
#define each(x, c) for (auto &&x : c)
#define fs first
#define sc second
#define all(c) begin(c), end(c)
using ui = unsigned;
using ll = long long;
using ul = unsigned long long;
using ld = long double;
const int inf = 1e9 + 10;
const ll inf_ll = 1e18 + 10;
const ll mod = 1e9 + 7;
const ll mod9 = 1e9 + 9;
const int dx[]{-1, 0, 1, 0, -1, 1, 1, -1};
const int dy[]{0, -1, 0, 1, -1, -1, 1, 1};
template<class T, class U> void chmin(T &x, const U &y){ x = min<T>(x, y); }
template<class T, class U> void chmax(T &x, const U &y){ x = max<T>(x, y); }
struct prepare_ { prepare_(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(12); } } prepare__;
/* }}} */

int n;
string s[40];

int main(){
  while (cin >> n, n){
    rep(i, n) cin >> s[i];
    rep(i, n){
      int m = (1 << 6) | (1 << 13) | (1 << 18) | (1 << 25) | (1 << 30);
      int b = 0;
      rep(j, i, n){
        b <<= s[j].size();
        b |= 1 << s[j].size() - 1;
        if ((b & m) == m){
          cout << i + 1 << endl;
          goto B;
        }
      }
      B:;
    }
  }
}

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

#define rep(i, n) for(int i = 0; i < n; i++)

typedef long long ll;
using namespace std;
int mod = 1000000007;

int main(void){
    int N;
    int tanku[] = {5,7,5,7,7};
    vector<int> ans;
    while(true){
        cin >> N;
        if(N == 0) break;
        vector<int> work(N);
        rep(i, N){
            string temp; cin >> temp;
            work[i] = temp.length();
        }
        rep(i, N){
            int idx = i;
            int acc = 0;
            int phase = 0;
            while(phase < 5 && acc < tanku[phase]){
                acc += work[idx];
                if(acc == tanku[phase]){
                    acc = 0;
                    phase++;
                }
                idx++;
            }
            if(phase == 5){
                ans.push_back(i+1);
                break;
            }
        }
    }
    rep(i, ans.size()) cout << ans[i] << endl;
    return 0;
}

C++: #include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
using namespace std;
int main(){
  int n;
  int flag[5]={5,7,5,7,7};
  while(cin >> n,n){
    string str;
    vector<int> cnt;
    rep(i,n){
      cin >> str;
      int tmp = str.size();
      cnt.push_back(tmp);
    }
    bool finish = false;
    rep(i,n){
      //cout << "#" << endl;
      int stage = 0;
      int sum = cnt[i];
      if(sum > flag[0]) continue;
      else if(sum == flag[0]) {
        stage++;
        sum = 0;
      }
      for(int j=i+1; j<n; j++){
        //cout << stage  << " " << sum << endl;
        sum += cnt[j];
        if(sum > flag[stage]) break;
        else if(sum == flag[stage]){
          stage++;
          sum = 0;
        }
        if(stage == 5) {
          cout << i+1 << endl;
          finish  = true;
          break;
        }
      }
      if(finish == true) break;
    }
  }
  return 0;
}