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<cstdio>
#include<cstring>

int i,j,d[50],p,n,q,a[5]={5,7,5,7,7};
char s[15];
int main(){
	for(;;){
		scanf("%d",&n);
		if(n==0)break;
		for(i=0;i<n;i++){
			scanf("%s",s);
			d[i]=strlen(s);
		}
		for(i=0;i<n;i++){
			p=i;
			for(j=0;j<5;j++){
				q=a[j];
				while(q>0){
					q-=d[p];p++;
				}
				if(q<0)p=-1;
			}
			if(p>=0){
				printf("%d\n",i+1);
				break;
			}
		}
	}
	return 0;
}

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

int main(){
    int n;
    int tanka[]={5,7,5,7,7};
    while(cin>>n,n){
        vector<string> w(n);
        for(int i=0;i<n;i++)cin>>w[i];

        for(int i=0;i<n;i++){
            int inde=0;
            int cnt=0;
            for(int j=i;j<n;j++){
                cnt+=w[j].size();
                if(cnt==tanka[inde]){
                    inde++;
                    cnt=0;
                }
                if(inde==5) break;
            }
            if(inde==5){
                cout<<i+1<<endl;
                break;
            }

        }

    }

    return 0;
}

C++: #include <cstdio>
#include <cstring>

int l[40];

bool check(int *p, int n) {
  int i;
  for (i=0;i<n;i+=l[(*p)++]);
  return (i == n);
}

int main() {
  int n;
  while (scanf("%d", &n), n!=0) {
    for (int i=0;i<n;i++) {
      char s[11];
      scanf("%s", s);
      l[i] = strlen(s);
    }
    for (int i=0;i<n-4;i++) {
      int p = i;
      if (!check(&p, 5)) continue;
      if (!check(&p, 7)) continue;
      if (!check(&p, 5)) continue;
      if (!check(&p, 7)) continue;
      if (!check(&p, 7)) continue;
      printf("%d\n", i+1);
      break;
    }
  }
  return 0;
}

C++: #include<bits/stdc++.h>
char s[50],a[9]={6,8,6,8,8};
main(){for(int i,j,p,n,q;scanf("%d\n",&n),n;){for(i=0;i<n;s[i++]=strlen(gets(s+i)));
for(i=j=0;j<6;i++)for(p=i,j=q=0;q+1;)for(q=a[j++]-1;q>0;q-=s[p++]);
printf("%d\n",i);
}}

C++: #include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	string s;
	while(cin>>n,n){
		int a[40]={0},j=0,i=0,c,k=0;
		for(;j<n;j++){
			cin>>s;
			a[i++]=s.size();
		}
		for(j=0;j<35;j++){
			int b[4]={0};
			c=0;
		for(i=j;i<40;i++){
			c+=a[i];
			if(c==5)b[0]++;
			else if(b[0]&&c==12)b[1]++;
			else if(b[1]&&c==17)b[2]++;
			else if(b[2]&&c==24)b[3]++;
			else if(b[3]&&c==31){
				k=j;
				break;
			}
			if(!b[0]&&c>5)break;
			else if(b[0]&&c>12)break;
			else if(b[1]&&c>17)break;
			else if(b[2]&&c>24)break;
			else if(b[3]&&c>31)break;
		}if(k)break;
	    }
	    
		cout<<k+1<<endl;
	}
}

C++: #include <iostream>
#include <string>

using namespace std;

int main(void) {
    while (1) {
        int n;
        cin >> n;
        if (n == 0) break;

        int len[n + 1];
        for (int i = 1; i <= n; ++i) {
            string w;
            cin >> w;
            len[i] = w.length();
        }

        int cumulativesum[n + 1];
        cumulativesum[1] = len[1];
        for (int i = 2; i <= n; ++i) {
            cumulativesum[i] = cumulativesum[i - 1] + len[i];
        }

        bool cnt5 = false, cnt12 = false, cnt17 = false, cnt24 = false, cnt31 = false;
        int ans = 0;
        for (int i = 1; i <= n; ++i) {
//            for (int j = 1; j <= n; ++j) {
//                printf("%d ", cumulativesum[j]);
//            }
//            printf("\n");
            for (int j = i; j <= n; ++j) {
                if (cumulativesum[j] == 5) cnt5 = true;
                if (cumulativesum[j] == 12) cnt12 = true;
                if (cumulativesum[j] == 17) cnt17 = true;
                if (cumulativesum[j] == 24) cnt24 = true;
                if (cumulativesum[j] == 31) cnt31 = true;

                if (cnt5 && cnt12 && cnt17 && cnt24 && cnt31) ans = i;
            }
            if (ans != 0) break;
            for (int j = 1; j <= n; ++j) {
                cumulativesum[j] -= len[i];
            }
        }

        cout << ans << endl;
    }
    return 0;
}

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

using namespace std;

int check(vector<int> tanka){
	int roule[] = {5,7,5,7,7};
	int index = 0, i = 0, t = 0;
	int sum = 0;
	while(i < 5){
		do{
			sum += tanka[index+t];
			t++;
		}while(sum < roule[i]);
		if(sum > roule[i]){
			index++;
			i = 0;
			t = 0;
		}else{
			i++;
		}
		sum = 0;
	}
	return index+1;
}

int main(){
	vector<int> tanka;
	vector<int> res;
	int n;
	do{
		cin >> n;
		for(int i=0;i<n;i++){
			string tmp;
			cin >> tmp;
			tanka.push_back(tmp.size());
		}
		if(n > 0)
			res.push_back(check(tanka));
		tanka.clear();
		tanka.shrink_to_fit();
	}while(n > 0);

cout << "test" << endl;
	for(auto num : res){
		cout << num << endl;
	}
	
	return 0;
}

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

int main(void){
    int n;
    int w[41];
    string s;
    while(cin >> n && n) {
        rep(j, n) {
            cin >> s;
            w[j] = s.size();
        }
        bool clear;
        int i;
        for(i=0; i<n; ++i) {
            int j = i;
            int stage = 0;
            clear = false;
            int tmp = 0;
            while(j < n) {
                tmp += w[j] ;
                if(stage == 0) {
                   if(tmp == 5) stage++, tmp = 0;
                   if(tmp > 5) break;
                }
                if(stage == 1) {
                   if(tmp == 7) stage++, tmp = 0;
                   if(tmp > 7) break;
                }
                if(stage == 2) {
                   if(tmp == 5) stage++, tmp = 0;
                   if(tmp > 5) break;
                }
                if(stage == 3) {
                   if(tmp == 7) stage++, tmp = 0;
                   if(tmp > 7) break;
                }
                if(stage == 4) {
                   if(tmp == 7) stage++, clear = true;
                   if(tmp > 7) break;
                }
                j++;
            }
            if(clear) {
                cout << i+1 << endl;
                break;
            }
        }
    }
}