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;

int main()
{
  int n;
  int len[51];
  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++;
	}
	if(c==5){
	  ans=i;
	  break;
	}
	if(num[c]<sum)break;
      }
      if(ans!=0)break;
    }
    cout<<ans+1<<endl;
  }

  return 0;
}

C++: #include<iostream>
#include<vector>
#include<string>
#include<cstdlib>
#include<sstream>
#include<queue>
#include<deque>
#include<cmath>
#include<algorithm>
#include<stack>
#include<map>
#include<set>
#include<iomanip>
#define INF 2147483647
#define lli long long int
#define MOD 1000000007
#define pb push_back

using namespace std;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
int main() {
	while(1){
		
		//cout << "n start" << endl;
		int n; cin >> n;
		if (n == 0) break;
		//cout << "n end" << endl;
		
		//cout << "init start" << endl;
		vector<string> str(n);
		for(int i = 0; i < n; i++) {
			cin >> str[i];
		}
		//cout << "init end" << endl;	
		
		//cout << "for i start" << endl;
		int ans = 0;
		for(int i = 0; i < n; i++) {
			int idx = 0;
			ans = i;	
			vi check = {5,7,5,7,7};
			for (int j = i; j < n; j++) {
					if(check[idx] <= 0) {
						idx++;
					}
					if (idx == 6){
						break;
					}
					check[idx] -= str[j].size();
					
			}
			int sum = 0;
			for (int k = 0; k < 5; k++) {
				sum += check[k];
			}
			if (sum == 0){
				break;
			}

		}
		////cout << "for i end" << endl;
		cout << ans + 1 << endl;
		//cout << "end" << endl;
	}
	return 0;
}

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

int n;
char w[50][100];
int len[50];
int main(){
	while(scanf("%d",&n),n){
		for(int i=0;i<n;i++)
			scanf(" %s",w[i]),len[i]=strlen(w[i]);
		int min=0;
		for(int k=0;k<n;k++){
			int a=0,b=0,c=0,d=0,e=0;
			bool E=false,A=false;
			while(a<=5&&b<=7&&c<=5&&d<=7&&e<=7&&E==false){
				 bool f=false;
				for(int m=k;m<n;m++){
					if(a!=5){
						a=a+len[m];
						if(A==false){
							min=m;
							A=true;
						}
						continue;
					}
					if(a==5&&b!=7){
						b=b+len[m];
						continue;
					}
					if(b==7&&c!=5){
						c=c+len[m];
						continue;
					}
					if(c==5&&d!=7){
						d=d+len[m];
						continue;
					}
					if(d==7&&e!=7){
						e=e+len[m];
						continue;
					}
					if(e==7){
						E=true;
						break;
					}
					f=true;
					break;
				}
				if(f)break;
			}
			if(E==true){
				break;
			}
		}
		printf("%d\n",min+1);
	}
}

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


using namespace std;

int main()
{

	while (true) {

		int n;
		cin >> n;
		if (n == 0) {
			return 0;
		}
		string str;
		int nums[41];

		for (int i = 0; i < n; i++) {
			cin >> str;
			nums[i] = str.size();
		}

		int start = 0;
		int tail = 0;
		int sum = 0;
		while (true) {
			while (tail < n && sum < (5 + 7 + 5 + 7 + 7)) {
				tail++;

				sum = 0;
				for (int i = start; i < tail; i++) {
					sum += nums[i];
				}
			}
			if (sum < (5 + 7 + 5 + 7 + 7)) {
				break;
			}
			else if (sum == (5 + 7 + 5 + 7 + 7)) {
				int ns[5] = { 5, 7, 5, 7, 7 };
				int s = start;
				int i = 0;
				while (i < 5) {
					if (nums[s] == ns[i]) {
						i++;
						s++;
					}
					else if (nums[s] > ns[i]) {
						break;
					}
					else {
						ns[i] = ns[i] - nums[s];
						s++;
					}
				}
				if (i == 5) {
					cout << start + 1 << endl;
					break;
				}

			}

			start++;
			sum = 0;
			for (int i = start; i < tail; i++) {
				sum += nums[i];
			}

		}
	}

	return 0;
}

C++: /* template.cpp {{{ */
#include <bits/stdc++.h>
using namespace std;
#define get_macro(a, b, c, d, name, ...) name
#define rep(...) get_macro(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep(...) get_macro(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define rep1(n) rep2(i_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, b) rep4(i, a, b, 1)
#define rep4(i, a, b, s) for (ll i = (a); i < (ll)(b); i += (ll)(s))
#define rrep1(n) rrep2(i_, n)
#define rrep2(i, n) rrep3(i, 0, n)
#define rrep3(i, a, b) rrep4(i, a, b, 1)
#define rrep4(i, a, b, s) for (ll i = (ll)(b) - 1; i >= (ll)(a); i -= (ll)(s))
#define each(x, c) for (auto &&x : c)
#define fs first
#define sc second
#define all(c) begin(c), end(c)
using ui = unsigned;
using ll = long long;
using ul = unsigned long long;
using ld = long double;
const int inf = 1e9 + 10;
const ll inf_ll = 1e18 + 10;
const ll mod = 1e9 + 7;
const ll mod9 = 1e9 + 9;
const int dx[]{-1, 0, 1, 0, -1, 1, 1, -1};
const int dy[]{0, -1, 0, 1, -1, -1, 1, 1};
template<class T, class U> void chmin(T &x, const U &y){ x = min<T>(x, y); }
template<class T, class U> void chmax(T &x, const U &y){ x = max<T>(x, y); }
struct prepare_ { prepare_(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(12); } } prepare__;
/* }}} */

const unsigned m = (1 << 6) | (1 << 13) | (1 << 18) | (1 << 25) | (1 << 30);
int n;
string s[40];

int main(){
  while (cin >> n, n){
    rep(i, n) cin >> s[i];
    rep(i, n){
      unsigned b = 0;
      rep(j, i, n){
        b <<= s[j].size();
        b |= 1 << s[j].size() - 1;
        if ((b & m) == m){
          cout << i + 1 << endl;
          goto B;
        }
      }
    }
    B:;
  }
}

C++: #include<bits/stdc++.h>
using namespace std;
int main(){
    while(1){
        int N;
        cin >> N;
        if(!N) break;
        string s[N];
        for(int i = 0; i < N; i++) cin >> s[i];
        const vector<int> po = {5, 7, 5, 7, 7};
        for(int i = 0; i < N; i++){
            int index = 0;
            vector<int> yo = po;
            for(int j = i; j < N; j++){
                if(index == 5) break;
                if(yo[index] < s[j].size()) break;
                yo[index] -= s[j].size();
                if(!yo[index]) index++;
            }
            if(index == 5){
                cout << i + 1 << endl;
                break;
            }
        }
    }
    return 0;
}