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;

using ll = long long;
#define rep(i,n) for(int i = 0; i < n ;++i)
#define all(v) v.begin(),v.end()

int main() {
  int n;
  while(cin >> n) {
    if (n == 0) {
      break;
    }
  vector<string> w(n);
  vector<int> d(n);
  for (int i =0; i < n; i++) {
    cin >> w[i];
    d[i] = w[i].size();
  }
  for (int i = 0; i < n; i++) {
    bool h = true;
    int st[5] = {0};
    int lm[5] = {5, 7, 5, 7, 7};
    int a = 0;
    for (int j = i; j < n; j++) {
      for (int k = a; k < 5; k++) {
        if (st[k] < lm[k]) {
          st[k] += d[j];
          break;
        } else if (st[k] > lm[k]) {
          h = false;
          break;
        }
        a++;
      }
      if (!h) {
        break;
      } else if (a == 5) {
        break;
      }
    }
    if (h) {
      cout << i+1 << endl;
      break;
    }
  }
  }
  return 0;
}

C++: #include<bits/stdc++.h>
#define  INF 1100000000
#define	 MOD 1000000007
using namespace std;

int main(){
	int N;
	while(cin >> N, N != 0){
		string w;
		int size[1000];
		for(int i=0;i<N;i++){
			cin >> w;
			size[i+1] = w.size();
		}
		
		for(int i=1;i<=N;i++){
			int count=0, j=i;
			while(count < 5){
				count += size[j];
				j++;
			}
			if(count != 5){
				continue;
			}
			count = 0;
			while(count < 7){
				count += size[j];
				j++;
			}
			if(count != 7){
				continue;
			}
			count = 0;
			while(count < 5){
				count += size[j];
				j++;
			}
			if(count != 5){
				continue;
			}
			count = 0;
			while(count < 7){
				count += size[j];
				j++;
			}
			if(count != 7){
				continue;
			}
			count = 0;
			while(count < 7){
				count += size[j];
				j++;
			}
			if(count != 7){
				continue;
			}
			cout << i << endl;
			break;
		}
	}
	return 0;
	
}

C++: #include<bits/stdc++.h>
int i,j,d[50],p,n,q,a[5]={5,7,5,7,7};
char s[15];
main(){
	for(;;){
		scanf("%d",&n);
		if(n==0)break;
		for(i=0;i<n;i++){
			scanf("%s",s);
			d[i]=strlen(s);
		}
		for(i=0;i<n;i++){
			p=i;
			for(j=0;j<5;j++){
				q=a[j];
				while(q>0){
					q-=d[p];p++;
				}
				if(q<0)p=-1;
			}
			if(p>=0){
				printf("%d\n",i+1);
				break;
			}
		}
	}
}

C++: #include<iostream>
#include<string>
using namespace std;
int n,w[1000];
string str,kari;
int main(){

  cin >> n;
  while( n != 0){
    fill_n(w,1000,0);
    w[0] = 1;

    for(int i = 0;i < n;i++){
      cin >> kari;
      if(i != 0) w[str.size()] = i+1;
      str += kari;
    }
    
    for(int i = 0;i <= str.size()-31;i++){
      if(w[i]!=0&&w[i+5]!=0&&w[i+12]!=0&&w[i+17]!=0&&w[i+24]!=0){
	if(i+31 == str.size() || w[i+31] != 0){
	  cout << w[i] << endl;
	  break;
	}
      }
    }
    cin >> n;
  }

  return (0);
}

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

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> VI;
typedef vector<VI> VVI;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = numeric_limits<int>::max() / 2;
const int NEG_INF = numeric_limits<int>::min() / 2;
const int MOD=1e9+7;

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

  int n;
  while(true){
      cin>>n;
      if(n==0) break;
      std::vector<string> v(n);
      for(int i=0;i<n;i++){
          cin>>v[i];
      }
      int tanku[5]={5,7,5,7,7};
      for(int i=0;i<n-1;i++){
          int cnt=0,idx=0;
          for(int j=0;i+j<n;j++){
              cnt+=v[i+j].length();
              //cout<<cnt<<" "<<idx<<endl;
              if(cnt<tanku[idx]) continue;
              else if(cnt==tanku[idx]){
                  idx++;
                  cnt=0;
              }
              else{
                  break;
              }
          }
          if(idx==5){
              cout<<i+1<<endl;
              break;
          }
      }
  }
  return 0;
}

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

vector<string> a(40);

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<40;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){
                q=1+make(q,7);
                end=1;
              }
            }
          }
        }
      }
      if(end==1) break;
    }
    printf("%d\n",k+1);
    scanf ("%d",&n);
  }
}


int make(int k,int p){
  int l=0;
  int r=0;
  l=a[k].size();
  if(l==p){
    return k;
  }
  else{
    if(l<p){
      r=make(k+1,p-l);
      return r;
    }
    else{
      return -1;
    }
  }
}