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 REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
typedef pair<int,int> P;

//-----------------------------------------------------------------------

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

    int n;
    while(cin>>n,n){
        vector<int> v(n);
        REP(i,n){
            string s; cin>>s;
            v[i]=s.size();
        }

        REP(i,n){
            int pos=i;
            int A[]={5,7,5,7,7};
            REP(j,5){
                int cnt=0;
                while(pos<n && cnt<A[j]) cnt+=v[pos++];
                if(cnt!=A[j]) goto g;
            }
            cout<<i+1<<endl;
            break;
        g:;
        }
    }
}

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

vector<int> v;
int d[5] = {5 ,7, 5, 7, 7};

int main(){
while(1){//start	
	
	int n;
	cin >> n;
	if(n == 0) break;
	for(int i = 0; i < n; i++){
		string s;
		cin >> s;
		v.push_back((int)s.size());
	}
	
	//debug
	//for(int i = 0; i < n; i++) cout << v[i] << endl;
	
	int ans = 0;
	for(int i = 0; i < n - 1; i++){
		int len = 0;
		int tmp = 0;
		int next = 0;
		for(int j = i; j < n; j++){
			len += v[j];
			tmp += v[j];
			if(next == 4 and len == 31){
				ans = i + 1;
				goto end;
			}
			else if(d[next] == tmp){
				//cout << tmp << endl;
				tmp = 0;
				next++;
			}
		}
		//cout << endl;
	}
	
	end:
	cout << ans << endl;
	
	v.clear();
}//end
	return 0;
}

C++: #include <iostream>
#include <string>

using namespace std;

int main(void){
  while(1){
    int n;
    cin >> n;
    if(n == 0){return 0;}

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

    int ans = -1;

    for(int i = 0 ; i < n - 4 ; i++){
      int  cur = i;
      bool istanku = true;

      int sum = 0;
      for(int j = 0 ; cur + j < n ; j++){
        sum += w[cur + j];
        if(sum == 5){
          cur = i + j + 1;
          break;
        }else if(sum > 5){
          istanku = false;
        }
      }

      if(istanku == true){
        sum = 0;
        for(int j = 0 ; cur + j < n ; j++){
          sum += w[cur + j];
          if(sum == 7){
            cur = cur + j + 1;
            break;
          }else if(sum > 7){
            istanku = false;
          }
        }
      }

      if(istanku == true){
        sum = 0;
        for(int j = 0 ; cur + j < n ; j++){
          sum += w[cur + j];
          if(sum == 5){
            cur = cur + j + 1;
            break;
          }else if(sum > 5){
            istanku = false;
          }
        }
      }

      if(istanku == true){
        sum = 0;
        for(int j = 0 ; cur + j < n ; j++){
          sum += w[cur + j];
          if(sum == 7){
            cur = cur + j + 1;
            break;
          }else if(sum > 7){
            istanku = false;
          }
        }
      }

      if(istanku == true){
        sum = 0;
        for(int j = 0 ; cur + j < n ; j++){
          sum += w[cur + j];
          if(sum == 7){
            cur = cur + j + 1;
            break;
          }else if(sum > 7){
            istanku = false;
          }
        }
      }

      if(istanku == true){
        ans = i + 1;
        break;
      }
    }

    cout << ans << endl;

  }
}

C++: #include <iostream>
#include <vector>
#include <string>

using namespace std;

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

    int n;
    vector<int> v;
    int checkPoint[] = {5, 7, 5, 7, 7};
    while(cin >> n && n){
        v.resize(n);
        for(auto&& i : v){
            string str;
            cin >> str;
            i = str.size();
        }
        for(int i = 0; i < n; i++){
            int cnt = 0, p = 0;
            for(int j = i; j < n; j++){
                cnt += v[j];
                if(checkPoint[p] < cnt){
                    break;
                }
                if(checkPoint[p] == cnt){
                    cnt = 0;
                    p++;
                    if(p == 5){
                        break;
                    }
                }
            }
            if(p == 5){
                cout << i + 1 << "\n";
                break;
            }
        }
    }
}

C++: #include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pi M_PI
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  int c[5]={5,7,5,7,7};
  int n;
  while(R n && n) {
    vector<int> a(n);
    rep(i,n) {
      string s;
      R s;
      a[i]=s.size();
    }
    rep(i,n) {
      int x=i;
      rep(j,5) {
        int cnt=0;
        while(x<n&&cnt<c[j]) cnt+=a[x++];
        if(cnt!=c[j]) goto next;
      }
      pr(i+1);
      break;
    next:;
    }
  }
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();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(n=1;n;){
		scanf("%d",&n);
		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)p=-1;
			}
			if(p>0){
				printf("%d\n",i+1);
				break;
			}
		}
	}
}