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 <vector>
#include <string>
#define pb push_back

using namespace std;
int main(void){
  int i,j,n;
  string s;
  int t,tmpi;
  while(cin>>n,n){
    vector<string> a;
    for(i=0;i<n;i++){
      cin>>s;
      a.pb(s);
    }
    
    for(i=0;i<n;){
      tmpi=i+1;
      t=0;
      while(t<5){
	t+=a[i].size();
	i++;
      }
      if(t>5) {i=tmpi;continue;}
      //cout<<":5"<<endl;
      t=0;
      while(t<7){
	t+=a[i].size();i++;
      }
      if(t>7) {i=tmpi;continue;}
      //cout<<":7"<<endl;
      t=0;
      while(t<5){
	t+=a[i].size();i++;
      }
      if(t>5) {i=tmpi;continue;}
      //cout<<":5"<<endl;
      t=0;
      while(t<7){
	t+=a[i].size();i++;
      }
      if(t>7) {i=tmpi;continue;}
      //cout<<":7"<<endl;
      t=0;
      while(t<7){
	t+=a[i].size();i++;
      }
      if(t>7) {i=tmpi;continue;}
      //cout<<":7"<<endl;
      if(t==7) break;
    }
    cout<<tmpi<<endl;
  }
  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
    while(1){
        int n;
        cin >> n;
        if(n == 0)  break;
        vector<string> S(n);
        vector<int> N(n);
        for(int i=0;i<n;i++){
                cin >> S.at(i);
                N.at(i) = S.at(i).size();
        }

        for(int i=0;i<n;i++){
            int j=i;
            int m=N.at(j);
            while(m<5){
                m += N.at(j+1);
                j++;
            }
            if(m>5) continue;
            j++;

            m=N.at(j);
            while(m<7){
                m += N.at(j+1);
                j++;
            }
            if(m>7) continue;
            j++;
            
            m=N.at(j);
            while(m<5){
                m += N.at(j+1);
                j++;
            }
            if(m>5) continue;
            j++;

            m=N.at(j);
            while(m<7){
                m += N.at(j+1);
                j++;
            }
            if(m>7) continue;
            j++;

            m=N.at(j);
            while(m<7){
                m += N.at(j+1);
                j++;
            }
            if(m>7) continue;

            cout << i+1 << endl;
            break;
        }


    }
}

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; break;
				}
			}
			if(p>=0){
				printf("%d\n",i+1);
				break;
			}
		}
	}
}

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

int main() {
  while (true) {
    int n;
    cin >> n;

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

    int cnt1 = 0;
    int cnt2 = 0;
    for (int i = 0; i < n; i++) {
      for (int j = i; j < n; j++) {
	cnt2 += w[j].size();
	if ((cnt1 == 0 || cnt1 == 2) && cnt2 > 5 || cnt2 > 7) {
	  cnt1 = 0;
	  cnt2 = 0;
	  break;
	}

	if ((cnt1 == 0 || cnt1 == 2) && cnt2 == 5 ||
	    (cnt1 == 1 || cnt1 == 3) && cnt2 == 7) {
	  cnt1++;
	  cnt2 = 0;
	}
	if (cnt1 == 4 && cnt2 == 7) {
	  cout << i + 1 << endl;
	  i = n;
	  break;
	}
      }
    }
  }

  return 0;
}

C++: #include<bits/stdc++.h>
#define inf 1<<29
#define linf 1e18
#define eps (1e-8)
#define mod 1000000007
#define pi M_PI
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define pd(a) printf("%.10f\n",(double)(a))
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(a)-1;(b)<=i;i--)
#define equals(a,b) (fabs((a)-(b))<eps)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<double,int> pdi;
typedef vector<int> vi;
typedef vector<pii> vpi;
const int dx[8]={1,0,-1,0,1,1,-1,-1};
const int dy[8]={0,1,0,-1,1,-1,1,-1};

int main()
{
  int n;
  int len[101];
  string s;
  int num[5]={5,7,5,7,7};
 
  while(1){
    cin>>n;
    if(n==0)break;
    for(int i=0;i<n;i++){
      cin>>s;
      len[i]=s.length();
    }
 
    int ans=0;
    for(int i=0;i<n;i++){
      int sum=0,c=0;
      for(int j=i;j<n;j++){
    sum+=len[j];
    if(sum==num[c]){
      sum=0;
      c++;
    }
    else if(num[c]<sum)break;
    if(c==5)break;
      }
      if(c==5){
    ans=i;
    break;
      }
    }
    cout<<ans+1<<endl;
  }
 
  return 0;
}

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

int main() {
    int n;

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

        vector<string> w(n);

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

        for(int i = 0; i < n; i++) {
            vector<int> tanku{ 5, 7, 5 ,7, 7 };
            int k = 0;
            for(int j = 0; i+j < n; j++) {
                tanku[k] -= w[i+j].size();
                if(tanku[k] == 0) k++;
                else if(tanku[k] < 0) break;
            }
            if(tanku[0] == 0 && tanku[1] == 0 
            && tanku[2] == 0 && tanku[3] == 0 
            && tanku[4] == 0) {
                cout << i+1 << endl;
                break;
            }
            else continue;
        }
    }
    return 0;
}

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

int main (){
	int n;
	while(cin>>n && n){
		vector<int> v(n);
		for(int i=0;i<n;i++){
			string s;
			cin>>s;
			v[i]=s.size();
		}

		for(int i=0;i<n;i++){
			int count=0;
			int j=i;
			vector<bool> ok(5,false); 
			while(j<=n-1){
				count+=v[j];
				j++;
				if(count==5)ok[0]=true;
				if(ok[0] && count==12)ok[1]=true;
				if(ok[1] && count==17)ok[2]=true;
				if(ok[2] && count==24)ok[3]=true;
				if(ok[3] && count==31)ok[4]=true;
				if(ok[4]){
					cout<<i+1<<endl;
					goto END;
				}
			}
		}
		END:;
	}
}

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

C++: *s,j,p,q;
main(i,j){for(s=j;p=j=atoi(gets(s));printf("%d\n",i)){
for(;j;s[p-j--]=strlen(gets(s+p)));
for(i=0;j<7;)for(p=i++,j=q=1;q>0;)for(q=8939616>>j++*4&15;q>1;q-=s[p++]);
}}