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;

#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int n;
string w[50];
bool ok(int idx) {
    int now = 0;
    vector<int> vec{5, 7, 5, 7, 7};
    rep(i, n) if (idx <= i) {
        vec[now] -= w[i].size();
        if (vec[now] == 0) {
            now++;
            if (now == vec.size()) return true;
        }
        if (vec[now] < 0) {
            break;
        }
    }
    return false;
}
void solve() {
    rep(i, n) {
        if (ok(i)) {
            cout << i + 1 << endl;
            break;
        }
    }
}
int main() {
    while (cin >> n, n) {
        rep(i, n) cin >> w[i];
        solve();
    }

    return 0;
}

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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = long long;
using P = std::tuple<int,int>;

const int dx[8] = {-1, 1, 0, 0, -1, -1, 1, 1}, dy[8] = {0, 0, -1, 1, -1, 1, -1, 1};

int RHYTHM[6] = {5, 7, 5, 7, 7};

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

    while(true){
        int N;
        std::cin >> N;
        if(!N){break;}

        vector<int> ls;
        for(int i=0;i<N;++i){
            string w;
            std::cin >> w;

            ls.emplace_back(w.size());
        }

        int res = -1;
        for(int i=0;i<N;++i){
            int pos = 0, len = 0;
            for(int j=i;j<N;++j){
                if(len + ls[j] > RHYTHM[pos]){
                    break;
                }else if(len + ls[j] == RHYTHM[pos]){
                    len = 0;
                    ++pos;
                }else{
                    len += ls[j];
                }

                if(pos == 5){
                    break;
                }
            }

            if(pos == 5){
                res = i + 1;
                break;
            }
        }

        std::cout << res << std::endl;
    }
}

C++: #include<cstdio>
main(){puts("hoge");}

C++: #include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int make(int w,int p);

vector<string> a(50);

int main() {
  int n;
  scanf ("%d",&n);
  while(n){

    for(int t=0;t<n;t++){
      //scanf ("%s",a[t]);
      cin >> a[t];
    }
    for(int t=n;t<50;t++){
      //scanf ("%s",a[t]);
      a[t]="";
    }
    int end=0;
    int k=0;
    for(k=0;k<n;k++){
      int q=k;
      if(make(q,5)>=1){
        q=1+make(q,5);
        if(make(q,7)>=1){
          q=1+make(q,7);
          if(make(q,5)>=1){
            q=1+make(q,5);
            if(make(q,7)>=1){
              q=1+make(q,7);
              if(make(q,7)>=1){
                end=1;
                //printf("qwqw\n");
              }
            }
          }
        }
      }
      if(end==1) break;
    }
    printf("%d\n",k+1);
    scanf ("%d",&n);
  }
}


int make(int w,int p){
  int l=a[w].size();
  if(l==p){
    return w;
  }
  else{
    if(l<p){
      //printf("%d\n",r);
      return make(w+1,p-l);
    }
    else{
      return -1;
    }
  }
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	string s;
	while(cin>>n,n){
		int a[40]={0},b[4]={0},j=0,i=0,c=0,k=0;
		for(;j<n;j++){
			cin>>s;
			a[i++]=s.size();
		}
		for(j=0;j<35;j++){
			if(!a[j])break;
		for(i=j;i<40;i++){
			c+=a[i];
			if(c==5)b[0]++;
			else if(b[0]&&c==12)b[1]++;
			else if(b[1]&&c==17)b[2]++;
			else if(b[2]&&c==24)b[3]++;
			else if(b[3]&&c==31){
				k=j;
				break;
			}
		}}
		cout<<n-j+1<<endl;
	}
}

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

int main(){
  while (1){
    int n;
    cin >> n;
    if(n==0) break;

    vector<string> words(n+1);
    for(int i=1; i<=n; i++){
      cin >> words[i];
    }
    
    for(int i=1; i<n+1; i++){
      bool flag = false;
      int tanka[5]={5,7,5,7,7};
      int now = 0;
      for(int j=0; j+i<n+1; j++){
        int len=words[i+j].length();
        if(tanka[now]-len>=0){
          tanka[now] -= len;
        }else{
          break;
        }
        if(tanka[now]==0){
          now++;
        }
        if(now==5){
          cout << i << endl;
          flag = true;
          break;
        }
      }
      if(flag){
        break;
      }
        
    }
    
  }
  return 0;
}

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

int main(void){
  while(true){
    int n;
    cin >> n;
    if(n == 0){ break; }

    string input;
    vector<int> w(n);
    for(int i = 0; i < n; i++){
      cin >> input;
      w[i] = input.length();
    }

    int tank[] = {5, 7, 5, 7, 7};
    for(int i = 0; i < n; i++){
      int phase = 0;
      int nowCount = 0;
      for(int j = i; j < n && phase < 5; j++){
        nowCount += w[j];
        if(nowCount == tank[phase]){
          nowCount = 0;
          phase++;
        }
        else if(nowCount > tank[phase]){ break; }
      }

      if(phase == 5){
        cout << i + 1 << endl;
        break;
      }
    }
  }

  return 0;
}

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

string W[45];
int Len[45];
int haiku[] = {5,7,5,7,7,0};
bool used[45];
int n;

/*
bool rec(int i, int cur, int nokori) {
    
    //printf("i:%d cur:%d nokori:%d\n", i, cur, nokori);
    if(cur >= 5) {
        // 結果を出力

        for(int i = 0; i < n; ++i) {
            if(used[i]) {
                cout << (i+1) << endl;
                break;
            }
        }

        return true;
    }

    // for(int j = i; i < n; ++j) にしていて無限にバグった。。
    for(int j = i; j < n; ++j) {
        if(Len[j] < nokori) {
            used[j] = true;
            bool flg = rec(j+1, cur, nokori - Len[j]);
            if(flg) return true;
            used[j] = false;
        } else if(Len[j] == nokori) {
            used[j] = true;
            bool flg = rec(j+1, cur+1, haiku[cur+1]);
            if(flg) return true;
            used[j] = false;
        }
    }
    return false;
}
*/

bool check(int f){
    int cur = 0, nokori = haiku[0];
    for(int i = f; i < n; ++i) {
        nokori -= Len[i];
        if(nokori < 0) return false;
        else if(nokori == 0) nokori = haiku[++cur];
        
        if(cur >= 5) return true;
    }
    return false;
}

bool solve()
{
    cin >> n;
    if(n == 0) return false;
    for(int i = 0; i < n; ++i) {
        cin >> W[i];
        Len[i] = W[i].size();
        used[i] = false;
    }
    //printf("n:%d\n", n);
    //rec(0, 0, haiku[0]);
    for(int i = 0; i < n; ++i) {
        if(check(i)) { cout << i + 1 << endl; break;}
    }

    return true;
}

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