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>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define debug(x) cout << "debug " << x << endl;
const int INF = 100000000;
using namespace std;

int main(){
    int n;
    while(cin >> n, n){
        int a[41];
        rep(i,n){
            string s;
            cin >> s;
            a[i] = s.size();
        }
        int t[5] = {5,7,5,7,7};
        int k, c, ans = -1;
        rep(i,n){
            k = 0;
            c = 0;
            range(j,i,n){
                c+=a[j];
                if(c == t[k]){
                    k++;
                    c = 0;
                }else if(c > t[k]){
                    break;
                }
                if(k == 5){
                    ans = i;
                    break;
                }
            }
            if(ans != -1) break;
        }
        cout << ans + 1 << endl;
    }
}

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

int main() {
  int n;

  while (cin >> n, n) {
    vector<string> s;
    for (int i = 0; i < n; ++i) {
      string in;
      cin >> in;
      s.push_back(in);
    }

    for (int i = 0; i < s.size(); ++i) {

      int length = 0;
      int cnt = 0;

      for (int j = i; j < s.size() && cnt != 5; ++j) {
        length += s[j].size();

        if ((cnt == 0 || cnt == 2) && length == 5) {
          length = 0;
          cnt++;
          continue;
        }
        if ((cnt == 1 || cnt == 3 || cnt == 4) && length == 7) {
          length = 0;
          cnt++;
          continue;
        }
      }

      if (cnt == 5) {
        cout << i + 1 << endl;
        break;
      }
    }
  }
}

C++: #include <cstdio>
#include <cstring>
int n, l[44]; char c[12];
int main() {
	while (scanf("%d", &n)) {
		for (int i = 0; i < n; i++) scanf("%s", c), l[i] = strlen(c);
		for (int i = 0; i < n; i++) {
			int s = 0, v = 0;
			for (int j = i; j < n && s < 5; j++) {
				v += l[j];
				if (3 % (s + 1) == 0) {
					if (v > 5) break;
					else if (v == 5) s++;
				}
				else {
					if (v > 7) break;
					else if (v == 7) s++;
				}
			}
			if (s == 5) {
				printf("%d\n", i); break;
			}
		}
	}
}

C++: #include<iostream>
#include<string>
using namespace std;
int main() {
	int n;
	const int sp[] = { 5,7,5,7,7 };
	while (cin >> n, n){
		int a[41];
		for (int i = 0; i < n; i++) {
			string s; cin >> s;
			a[i] = s.size();
		}
		for (int i = 0; i < n; i++) {
			int cnt = 0, k = 0;
			for (int j = 0;; j++) {
				cnt += a[i + j];
				if (cnt == sp[k]) {
					k++;
					if (k == 5) {
						cout << i + 1 << endl;
						goto end;
					}
					cnt = 0;
				}
				else if (cnt > sp[k])break;
			}
		}
	end:;
	}
}

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

int main(){
  cin.tie(0);
ios::sync_with_stdio(false);
  int n,a,b,c,d,e,j;
  string w[40];
  while(true){
    cin >> n;
    if(n == 0) break;

    for(int i = 0; i < n; i++){
      cin >> w[i];
    }
    //cout << "n="<<n << endl;
    for(int i = 0; i < n - 4; i++){
      //start w[i] 5 7 5 7 7
      //cout << i << "=i" <<endl;
      a = 5;
      b = 7;
      c = 5;
      d = 7;
      e = 7;

      int j=i;
      bool flag = true;
      while(flag ){//5

        if(a - w[j].size() == 0){j++; break;}
        else if(j >= n){flag = false;}
        else if(a - w[j].size() > 0){a-=w[j].size(); j++;}
        else {flag = false;}
      }
      //cout << j << endl;
      while(flag){//7

        if(b - w[j].size() == 0){j++; break;}
        else if(j >= n ){flag = false;}
        else if(b - w[j].size() > 0){b-=w[j].size(); j++;}
        else {flag = false;}
      }
      //cout << j << endl;
      while(flag){//5

        if(c - w[j].size() == 0){j++; break;}
        else if(j >= n){flag = false;}
        else if(c - w[j].size() > 0){c-=w[j].size(); j++;}
        else {flag = false;}
      }
      //cout << j << endl;
      while(flag){//7

        if(d - w[j].size() == 0){j++; break;}
        else if(j >= n){flag = false;}
        else if(d - w[j].size() > 0){d-=w[j].size(); j++;}
        else {flag = false;}

      }
      //cout <<  j << endl;
      while(flag){//7

        if(e - w[j].size() == 0){  j++; break;}
        else if(j >= n){flag = false;}
        else if(e - w[j].size() > 0){  e -= w[j].size(); j++;}
        else {flag = false;}
      }
      if(flag){
        cout << i+1 << endl;
        break;
      }
    }
  }

  return 0;

}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <cmath>
#include <string>
#define FI first
#define SE second
#define PF push_front
#define PB push_back
#define POF pop_front
#define POB pop_back
#define MA make_pair
#define ll long long
#define VE vector<int>
#define VP vector<pair<int,int> >
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
using namespace std;
//
const int INF=1e9+7;
const int mod=1e9+7;
//
int main(){
  int N;
  while(1){
    cin>>N;
    if(N==0){
      break;
    }
    VE V;
    FOR(i,0,N){
      string S;
      cin>>S;
      V.PB((int)S.size());
    }
    FOR(i,0,N){
      int sum=0;
      int now=i;
      while(sum<31){
        sum+=V[now];
        now++;
      }
      if(sum==31){
        cout<<i+1<<endl;
        break;
      }
    }
  }
  return 0;
}

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

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

int main() {
  int N;
  while (cin >> N, N) {
	vector<string> a(N); for (int i = 0; i < N; ++i) cin >> a[i];
	for (int i = 0; i < N; ++i) {
	  bool ok = true;
	  int j = i;
	  for (int it = 0; it < 5; ++it) {
		string str = "";
		while (j < N && str.size() < len[it]) str += a[j++];
		if (str.size() != len[it]) {
		  ok = false;
		  break;
		}
	  }
	  if (ok) {
		cout << i+1 << endl;
		break;
	  }
	}
  }
}