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<(int)(n);i++)
#define REP(i,k,n) for(int i=(int)(k);i<(int)(n);i++)

#define vi vector<int>
#define pb push_back

int main(){
//    ifstream in("b_in.txt");
//    cin.rdbuf(in.rdbuf());
    int n;
    while(cin >> n,n){
        string w[50];
        int l[50];
        rep(i,n) cin >> w[i];
        l[0] = 0;
        REP(i,1,n+1) {
            l[i] = l[i-1] + w[i-1].size();
        }

        REP(jj, 1, n) {
            bool finished = false;
            rep(ii, jj) {
                bool muri = false;
                int base = l[jj];
                int cur = jj+1;
                if(l[jj] - l[ii] == 5) {
                    for(; cur<n; cur++) {
                        if(l[cur] == base+7) break;
                        else if(l[cur] > base+7) {
                            muri = true;
                            break;
                        }
                    }
                    if(muri) break;
                    cur++;

                    for(; cur<n; cur++) {
                        if(l[cur] == base+12) break;
                        else if(l[cur] > base+12) {
                            muri = true;
                            break;
                        }
                    }
                    if(muri) break;
                    cur++;

                    for(; cur<n; cur++) {
                        if(l[cur] == base+19) break;
                        else if(l[cur] > base+19) {
                            muri = true;
                            break;
                        }
                    }
                    if(muri) break;
                    cur++;

                    for(; cur<n+1; cur++) {
                        if(l[cur] == base+26) {
                            cout << ii+1 << endl;
                            finished = true;
                            break;
                        }
                        else if(l[cur] > base+26) {
                            break;
                        }
                    }
                }
            }
            if(finished) break;
        }
    }

    return 0;
}

C++: #include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <cstdio>
#include <cassert>
//cin.sync_with_stdio(false);
//streambuf
using namespace std;
typedef long long ll;
//typedef pair<int, int> pii;
using pll = pair<ll, ll>;
using pii = pair<short, short>;
typedef pair<double, double> pdd;
using vi = vector<int>;
using vll = vector<ll>;
using vpii = vector<pii>;
using ti3 = tuple<int, int, int>;
using vti3 = vector<ti3>;
template<class T, class T2> using umap = unordered_map<T, T2>;
template<class T> using uset = unordered_set<T>;
#define ALL(a) a.begin(),a.end()
#define rep(i,a) for(int i=0;i<(a);i++)
#define rep1(i,a) for(int i=1;i<=(a);i++)
#pragma warning(disable:4996)
//#define INF 1000000000000000.0
int main() {
	int n;
	while (cin >> n, n) {
		vector<int> num;
		string buf;
		rep(i, n) {
			cin >> buf;
			num.push_back(buf.length());
		}
		rep(i, n) {
			vi sp(5);
			int pos = 0;
			bool f = 1;
			for (int j = i;; j++) {
				f = 1;
				sp[pos] += num[j];
				if (sp[pos] > (pos & 5 ? 7 : 5)) {
					f = 0;
					break;
				}
				if (sp[pos] == (pos & 5 ? 7 : 5)) {
					pos++;
					if (pos == 5)break;
				}
			}
			if (f) {
				cout << i + 1 << endl;
				break;
			}
		}
	}
}

C++: #include <iostream>
#include <string>
using namespace std;
int main(){
  while(true){
    int n;
    cin>>n;
    if(n==0){
      break;
    }
    int len[40];
    for(int i=0;i<n;i++){
      string w;
      cin>>w;
      len[i]=w.size();
    }
    for(int i=0;i<n;i++){
      bool flg=false;
      int sta=0;
      int sum=0;
      for(int j=1;j<n;j++){
        sum+=len[j];
        if(sum==5||sum==12||sum==17||sum==24||sum==31){
          sta++;
        }
        if(sta==5){
          flg=true;
          break;
        }
        else if(sum>=31){
          break;
        }
      }
      if(flg){
        cout<<i+1<<endl;
        break;
      }
    }
  }
    return 0;
}

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

#define rep(i,j,k) for(int i=j;i<k;i++)
#define INF 2000000000



using namespace std;
int main(void){
    while(1){
    int n;
    cin>>n;
    if(n==0)break;
    vector<int> v;
    
    rep(i,0,n){
        string s;
        cin>>s;
        v.push_back(s.length());
    }
    
    
    
    rep(i,0,n){
        int count=0,sum=0;
        rep(j,i,n){
            sum+=v[j];
            if(count==0){
               if(sum==5)count=1;
               else if(sum>5)break;
            }
            else if(count==1) {
                if(sum==12) count=2;
                else if(sum>12)break;
            }else if(count==2) {
                if(sum==17) count=3;
                else if(sum>17)break;
            }else if(count==3) {
                if(sum==24) count=4;
                else if(sum>24)break;
            }else if(count==4) {
                if(sum==31){
                    count=5;
                    cout<<i+1<<endl;
                    goto Away;
                }
                else if(sum>31)break;
            
            } 
        }    
    }
    cout<<"j"<<endl;
    Away:;
    }
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
  int n,d[]={5,7,5,7,7},i,j,t,k;
  while(cin>>n,n){
    string s[41];
    for(i=0;i<n;i++)cin>>s[i];
    for(i=0,k=0;k!=5;i++)
      for(j=i,t=s[i].size(),k=0;k!=5;t+=s[++j].size())
	if(t==d[k])k++,t=0;
	else if(t>d[k])break;
    cout<<i<<endl;
  }
  return 0;
}

C++: #include <iostream>
#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define REP(i,n) FOR(i,0,n)
using namespace std;


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

int main(){
    int n;
    while(cin >> n && n != 0){
        int w[n],pos = 0;
        string str;
        REP(i,n){
            cin >> str;
            w[i] = str.length();
        }
        REP(i,n){
            int a,s;
            s = i;
            REP(j,5){
                a = 0;
                int l = w[s];
                while(l < gositigo[j]){
                    a++;
                    l += w[s + a];
                }
                if(l != gositigo[j]){goto NEXT;}
                s += a + 1;
            }
            pos = i+1;
            break;
            NEXT: continue;
        }
        cout << pos << endl;
    }
    return 0;
}