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 max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))

typedef long long LL;

int main(){
    int n;
    string s;
    int len[5] = {5,7,5,7,7};
    int count;
    int now;
    int ans;
    while(1){
        cin >> n;
        if(n==0) return 0;
        vector<int> w(n);
        for(int i=0;i<n;i++){
            cin >> s;
            w[i]=s.length();
        }
        ans=-1;
        for(int i=0;i<n;i++){
            count = 0;
            now = 0;
            for(int j=i;j<n;j++){
                count+=w[j];
                if(count==len[now]){
                    now++;
                    count=0;
                    if(now==5){
                        ans=i;
                    }
                }else if(count>len[now]){
                    break;
                }
            }
            if(ans != -1){
                break;
            }
        }
        cout << ans+1 << endl;
    }
    return 0;
}

C++: #include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<cstring>
#include<utility>
#include<set>
#include<stack>
#include<complex>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
#define bv vector<bool>
using namespace std;
typedef pair<int, int>PI;
using namespace std;
#define MAX  999999
int main(){
    int n;
    while(cin >> n,n){
         vi v(10000,0);
        rep(i, n){string s; cin >> s; v[i] = (int)s.length();}
        int ans = 0;
        rep(i, n){
            int temp = 0; int array[] = {5,7,5,7,7}; int counter = 0;
            ans = i+1;
            for(int k = i;k<n;k++){
                temp+=v[k];
                if(temp == array[counter])
                {   temp = 0; counter++;
                    if(temp == 0 && counter == 5) goto L;
                }
            }
        }
    L:cout << ans << endl;
        ans = 0;
        
    }
}

C++: #include "bits/stdc++.h"

using namespace std;

#define ll long long
#define vi  vector<int>
#define vvi vector<vi>
#define pi  pair<int,int>
#define mp  make_pair
#define pb  push_back
#define MOD 1e9 + 7
#define PAI  3.1415
#define all(x) (x).begin(),(x).end()
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
#define pr(x) cout << x << endl
#define Endl endl
#define rep(i,n) for(int i = 0 ; i < n; i++)

const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const int ddx[8] = {-1,0,1,-1,1,-1,0,1};
const int ddy[8] = {-1,-1,-1,0,0,1,1,1};
const int inf = 99999999;
const ll linf = 1LL << 62;

ll gcd(ll a,ll b){
  if(a < b)swap(a , b);
  if(a % b == 0) return b;
  else gcd(b, a%b);
}

ll lcm(ll a,ll b){
  if(a < b)swap(a , b);
  return (a/gcd(a , b))*b;
}

struct UnionFind {
  vi par; //par[i] : iの親番号（例）par[3] = 2 : 3の親は2

  UnionFind(int N) : par(N) { //最初は全てが根として初期化
    rep(i,N) par[i] = i;
  }

  int root(int x){ //データxが属する木の根を再帰で得る : root(x) = {xの木の根}
    if(par[x] == x)return x;
    return par[x] = root(par[x]);
  }

  void unite(int x, int y){ //xとyの木を併合
    int rx = root(x); //xの根をrx
    int ry = root(y); //yの根をry
    if(rx == ry)return; //xとyの根が同じ
    par[rx] = ry; //xとyの根が同じでない時、xの根rxをyの根にryにつける。
  }

  bool same(int x, int y){//2つのデータx，yが属する木が同じならtrueを返す
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
};

int main(){

  int n;
  int tanka[5] ={5,7,5,7,7};

  while(cin >> n,n){
    vi v(100,0);
    string s;
    rep(i,n){
      cin >> s;
      v[i] = s.length();
    }

    int pos = 0,sum = 0,ans = 0;

    rep(i,n){
      sum +=  v[i];
      if(sum == v[i] && pos == 0)ans = i + 1;

      if(sum == tanka[pos]){
        pos++;
        sum = 0;
      }
      else if(sum > tanka[pos]){
        if(ans != 0)i = ans - 1;
        pos = 0;
        sum = 0;
        ans = 0;
      }
      if(pos > 4){
        pr(ans);
        break;
      }
    }

  }

  return 0;

}

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

int main() {
    while (true) {
        int n; cin >> n;
        if (n == 0) break;
        vector<string> s(n);
        for (int i = 0; i < n; i++) {
            cin >> s[i];
        }
        for (int i = 0; i < n; i++) {
            //cout << i << endl;
            int cnt = 0;
            int state = 0;
            for (int j = i; j < n; j++) {
                cnt += s[j].size();
                if (state == 0) {
                    if (cnt == 5) {
                        state = 1;
                    }
                    else if (cnt > 5) {
                        break;
                    }
                }
                else if (state == 1) {
                    if (cnt == 12) {
                        state = 2;
                    }
                    else if (cnt > 12) {
                        break;
                    }
                }
                else if (state == 2) {
                    if (cnt == 17) {
                        state = 3;
                    }
                    else if (cnt > 17) {
                        break;
                    }
                }
                else if (state == 3) {
                    if (cnt == 24) {
                        state = 4;
                    }
                    else if (cnt > 24) {
                        break;
                    }
                }
                else if (state == 4) {
                    if (cnt == 31) {
                        state = 5;
                        break;
                    }
                    else if (cnt > 31) {
                        break;
                    }
                }
            }
            //cout << state << endl;
            if (state == 5) {
                cout << i + 1 << endl;
                break;
            }
        }
    }
    return 0;
}