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>

using namespace std;

signed main(){

   while(1){
      int n;
      cin>> n;
      if(!n) break;

      int w[n];
      for(int i=0; i<n; i++){
         string s;
         cin>> s;
         w[i]=s.size();
      }
      int b[]={5, 7, 5, 7, 7};
      for(int i=0; i<n; i++){
         int a=0, p=0;
         for(int j=i; j<n; j++){
            a+=w[j];
            if(a>b[p]){
               goto turai;
            }else if(a==b[p]){
               p++;
               if(p==5) break;
               a=0;
            }
         }
         cout<< i+1<< endl;
         return 0;
         turai:;
      }

   }

   return 0;
}

C++: #include<iostream>
#include<vector>
#include<string>
using namespace std;
int main(void){
    int n;
    vector<string> w(n);
    while(true){
        cin >>n;
        if(n==0) break;
        for(int i=0;i<n;i++)
        cin >> w[i];
        int tanku[5]={5,7,5,7,7};
        bool judge=false;
        //?§??????????
        for(int i=0;i<n;i++){
            int place=i;
            //tanku ibannme
            for(int j=0;j<5;j++){
    int sum=0;
    //kasan
    while(place<n){
        sum+=w[place].size();
        place++;
        if(sum>=tanku[j])
        break;
    }if(sum>tanku[j])
    break;
    if(j==4&&sum==tanku[4]){
            cout << i+1 << endl;
            judge=true;
            break;
        }
            }
            if(judge)
break;
        }
    }
return 0;
}

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

int tanku[5] = {5,7,5,7,7};

int main(){
    int n;
    while(scanf("%d",&n), n != 0){
        string w[40];
        for(int i=0;i<n;++i)cin >> w[i];
        for(int i=0;i<n;++i){
            int k=0, cnt=0, j=i;
            while(k < 5 && j < n){
                cnt += w[j].size();
                if(cnt > tanku[k])break;
                if(cnt == tanku[k]){
                    ++k;
                    cnt = 0;
                }
                ++j;
            }
            if(k == 5){
                printf("%d\n",i+1);
                break;
            }
        }
    }

    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define REP(i,b,e) for(int i=(b);i<(e);++i)
#define rep(i,e) for(int i=0;i<(e);++i)

int main() {
  int n;
  while(cin >> n){
    if(n==0) return 0;
    vector<string> v(n);
    rep(i, n) cin >> v[i];

    bool good=false;
    rep(i, n){
      int state=0, cur=0;
      if(good) break;
      REP(j, i, n){
        cur += v[j].size();
        if(cur==5 && (state==0 || state==2)){
          cur = 0; state += 1;
        }
        else if(cur==7 && (state==1 || state==3 || state==4)){
          cur = 0; state += 1;
        }
        else if(cur>7) break;
        if(state==5){
          cout << i+1 << endl;
          good = true;
          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>
#define rep(i,n) for(int i = 0; i < n; ++i)
using namespace std;

int main(void){
	int n;
	while(cin >> n,n){
		string words[55];
		rep(i,n) cin >> words[i];

		rep(start,n){
			int num = 0,step = 0;
			int tar[5]={5,7,5,7,7};

			for(int j = start; j < n;++j){
				num += words[j].size();
				if(step < 5 and tar[step] == num){
					step++;
					num = 0;
				}
			}

			if(step == 5){
				cout << start+1 << endl;
				break;
			}
		}
	}

	return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
void format(int a[]){
  for(int i=0;i<5;i++){
    if(i==0||i==2)
      a[i]=5;
    else
      a[i]=7;
  }
}
int main(){
  int n;
  while(cin>>n,n!=0){
    string word[n];
    for(int i=0;i<n;i++)
      cin>>word[i];
    int cnt[n];
    format(cnt);
    for(int j=0;j<n;j++){
      format(cnt);
      int pointer=0;
      for(int i=j;i<n;i++){
	cnt[pointer]-=word[i].size();
	if(cnt[pointer]<0)
	  break;
	else if(cnt[pointer]==0&&pointer==4){
	  cout<<j+1<<endl;return 0;
	}else if(cnt[pointer]==0)
	  pointer++;
      }
    }
  }
  return 0;
}

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

int main(){
  while(true){
    int n;
    cin>>n;
    if(n==0)break;
    vector<int> a(n);
    for(int i=0;i<n;i++){
      string s;
      cin>>s;
      a[i]=s.size();
    }
    int flag=0;
    int sum=0;
    int i;
    int j;
    for(j=0;j<n;j++){
      for(i=j;i<n;i++){
        sum+=a[i];
        if(flag==0&&sum==5){
          flag++;
          sum=0;
        }else if(flag==1&&sum==7){
          flag++;
          sum=0;
        }else if(flag==2&&sum==5){
          flag++;
          sum=0;
        }else if(flag==3&&sum==7){
          flag++;
          sum=0;
        }else if(flag==4&&sum==7){
          flag++;
          sum=0;
        }else if((flag==0||flag==2)&&sum>5){
          flag=0;
          sum=0;
          break;
        }else if((flag==1||flag==3||flag==4)&&sum>7){
          flag=0;
          sum=0;
          break;
        }
        if(flag==5)break;
      }
      if(flag==5)break;
    }
    cout<<j+1<<endl;
  }
}

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

int main(void) {
  int N;
  while (cin >> N, N) {
    vector<string> words(N);
    for (int i = 0; i < N; i++) {
      cin >> words[i];
    }

    int tanku_size[] = {5, 7, 5, 7, 7};
    for (int i = 0; i < N; i++) {
      int tanku_pos = 0;
      int letter_size = 0;
      for (int j = i; j < N; j++) {
        letter_size += words[j].size();
        if (letter_size > tanku_size[tanku_pos]) break;
        if (letter_size == tanku_size[tanku_pos]) {
          tanku_pos++;
          letter_size = 0;
        }
      }
      if (tanku_pos == 5) {
        cout << i + 1 << endl;
        break;
      }
    }
  }
  return 0;
}