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 <functional>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;

int k[5] = {5,7,5,7,7};
int n; 
string str[50];

bool dfs(int s, int c, int sum) {
    if (sum + str[s].length() == k[c]) {
        if (c == 4) return true;
        else return dfs(s+1, c+1, 0);
    }
    else if (sum + str[s].length() > k[c]) return false;
    else return dfs(s+1, c, sum + str[s].length());
}

int main(void){
    while (1) {
        cin >> n;
        if (!n) break;
        for (int i = 0; i < n; i++) cin >> str[i];
        for (int i = 0; i < n; i++) {
            int x = dfs(i, 0, 0);
            if (x == false) continue;
            cout << i+1 << endl;
            break;
        }
    }
    
    return 0;
}

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

C++: #include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)

using namespace std;

string str[41];
int k;
int n;

bool check(int p, int c)
{
	int cnt =0;
	for(int i=p;i<n;i++){
		cnt += str[i].length();
		k++;
		if(cnt == c) return true;
		else if(cnt > c)return false;
	}
	return false;
}

int main(){
	while(cin>>n, n){
		rep(i,n) cin >> str[i];
		rep(i,n){
			k = i;
			if(check(k,5) && check(k,7) && check(k,5) && check(k,7) && check(k,7)) {
				cout << i+1 << endl;
				break;
			}
		}
	}
	return 0;
}

C++: #define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);

signed main() {
	int n;
	while (cin >> n, n) {
		vector<int>v; vector<string>s; v.push_back(0);
		rep(i, 0, n) {
			string t;
			cin >> t;
			s.push_back(t);
			v.push_back(t.size());
		}
		rep(i, 1, n + 1) {
			v[i] += v[i - 1];
		}
		int ans;
		for (ans = 0; ans < n + 1; ans++) {
			rep(j, ans, n + 1) {
				int x = v[j] - v[ans];
				if (x > 31)continue;
				else if (x == 31)goto there;
			}
		}

	there:; cout << ans + 1 << endl;

	}
	return 0;
}

C++: #include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int main(int argc, char *argv[])
{
  for(;;) {
    int n;
    cin >> n;
    if(n == 0) break;
    vector<int> ls;
    for(int i = 0; i < n; i++) {
      string s;
      cin >> s;
      ls.push_back(s.length());
    }
    for(int i = 0; i < n; i++) {
      int j = i, k = 0;
      int tls[] = {5,7,5,7,7};
      for(;;) {
        if(ls[j] <= tls[k]) {
          tls[k]-=ls[j];
          j++;
        } else {
          break;
        }
        if(tls[k] == 0) k++;
        if(k == 5) {
          cout << (i+1) << endl;
          i = n;
          break;
        }
      }
    }
  }
  return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define RFOR(i, s, n) for (int i = (n) - 1; i >= (s); i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(a) a.begin(), a.end()
#define IN(a, x, b) (a <= x && x < b)
const long long MOD = 1e9+7, INF = 1e18;
template<class T>inline bool CHMAX(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool CHMIN(T&a,T b){if(a>b){a=b;return true;}return false;}

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

int f(){
	vector<int>a(N);
	string s;
	REP(i,N){
		cin>>s;
		a[i] = s.size();
	}
	int now = 0,tmp = 0;
	REP(i,N){
		now = i;
		tmp = 0;
		REP(j,5){
			while(tmp<tanka[j]){
				tmp += a[now];
				now++;
			}
			if(tmp>tanka[j])break;
			else if(j==4)return i+1;
			tmp = 0;
		}
	}
}

signed main(){
	vector<int>ans;
	while(cin>>N,N)ans.push_back(f());
	for(auto e:ans)cout<<e<<endl;
}

C++: #include<stdio.h>
#include<string.h>

int main(void){
	int n,n_l[40],count=0,cap=0;
	char w[10];
	scanf("%d",&n);

	int i;
	while(n!=0){
		for(i=0;i<n;i++){
			scanf("%s",w);
			n_l[i]=strlen(w);
		}
		for(i=0;;i++){
			count=0;
			cap=0;
			while(count<5){
				count+=n_l[i+cap];
				cap++;
			}
			if(count!=5)
				continue;
			count=0;
			while(count<7){
				count+=n_l[i+cap];
				cap++;
			}
			if(count!=7)
				continue;
			count=0;
			while(count<5){
				count+=n_l[i+cap];
				cap++;
			}
			if(count!=5)
				continue;
			count=0;
			while(count<7){
				count+=n_l[i+cap];
				cap++;
			}
			if(count!=7)
				continue;
			while(count<7){
				count+=n_l[i+cap];
				cap++;
			}
			if(count!=7)
				continue;
			break;
		}
		printf("%d\n",i+1);
		scanf("%d",&n);
	}
	return 0;
}

C++: #include<vector>
#include<iostream>
#include<string>
using namespace std;
int a0 = 5;
int a1 = 7;
int a2 = 5;
int a3 = 7;
int a4 = 7;
int main() {
	int n;
	while (cin >> n, n != 0) {
		vector<int>v(n);
		for (int i = 0; i < n; i++) {
			string str;
			cin >> str;
			int x = str.size();
			v[i] = x;
		}
		for (int i = 0; i < n; i++) {
			int k = i;
			int ans = i;
			int a = a0;
			while (a > 0) {
				a -= v[k];
				k++;
				if (k == n) {
					goto OUT;
				}
				if (a == 0) {
					break;
				}
				else if (a < 0) {
					goto OUT;
				}
				

			}
			a = a1;
			while (a > 0) {
				a -= v[k];
				k++;
				if (k == n) {
					goto OUT;
				}
				if (a == 0) {
					break;
				}
				else if (a < 0) {
					goto OUT;
				}
				
			}
			a = a2;
			while (a > 0) {
				a -= v[k];
				k++;
				if (k == n) {
					goto OUT;
				}
				if (a == 0) {
					break;
				}
				else if (a < 0) {
					goto OUT;
				}
				
			}
			a = a3;
			while (a > 0) {
				a -= v[k];
				k++;
				if (k == n) {
					goto OUT;
				}
				if (a == 0) {
					break;
				}
				else if (a < 0) {
					goto OUT;
				}
				
			}
			a = a4;
			while (a > 0) {
				a -= v[k];
				k++;
				if (k == n) {
					goto OUT;
				}
				if (a == 0) {
					cout << ans + 1 << endl;
				}
				else if (a < 0) {
					goto OUT;
				}
				
			}
		OUT:
			;
		}

	}
	return 0;
}


// 5 12 17 24 31