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 phrase[5] = {5,7,5,7,7};

int main() {

    while(1){

        int n;

        cin >> n;

        if(n==0) break;

        vector<string> w;

        for(int i=0; i<n; i++){
            string input;
            cin >> input;
            w.push_back(input);
        }

        int w_pos = 0;

        while(1){

            int w_itr = w_pos, nowp = 0, pcount = 0;

            while(1){
                if(w[w_itr].size() + pcount > phrase[nowp]){
                    nowp = -1;
                    break;
                }
                else if(w[w_itr].size() + pcount == phrase[nowp]){
                    nowp++;
                    if(nowp == 5){
                        break;
                    }
                    pcount = 0;
                }
                else{
                    pcount += w[w_itr].size();
                }
                w_itr++;
            }

            if(nowp == 5){
                break;
            }

            w_pos++;


        }

        cout << w_pos + 1 << endl;

    }

    return 0;
}

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

using namespace std;
int tanku[] = {5, 7, 5, 7, 7};

void solve()
{
	int n;
	while (cin >> n, n)
	{
		vector<int> w(n);
		for (int i = 0; i < n; ++i)
		{
			string s;
			cin >> s;
			w[i] = s.size();
		}
		for (int i = 0; i < n; ++i)
		{
			int pos = 0;
			int cnt = 0;
			for (int j = i; j < n; ++j)
			{
				cnt += w[j];
				if (cnt == tanku[pos])
				{
					++pos;
					cnt = 0;
				}
				if (pos >= 5 || cnt > tanku[pos])
				{
					break;
				}
			}
			if (pos == 5)
			{
				cout << i + 1 << endl;
				break;
			}
		}
	}
}

int main()
{
	solve();
	return(0);
}

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <ctime>
#define INF 999999999
#define mod 1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=(n);i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define MOD(x) (x%(mod))
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool debug=false;
/*---------------------------------------------------*/

int haiku[45];
int num[6]={5,7,5,7,7,0};

void solve(int n){
  int s=0,e=0,cnt=0,sum=haiku[0];
  int dast=0;
  
  rep(i,n-4){
    dast=cnt=0;
    s=e=i;
    sum=haiku[i];
    
    while(s!=n&&e!=n){
      if(debug)cout<<"s: "<<s<<"  e:"<<e<<"  cheack( "<<cnt<<" ): "<<num[cnt]<<"  dast: "<<dast<<"  cnt: "<<cnt<<endl;
      if(cnt==5)break;
      if(sum==num[cnt]){
	s=e=e+1;sum=haiku[s];cnt++;
      }else if(sum<num[cnt]){
	e++;sum+=haiku[e];
      }else if(sum>num[cnt]){
	break;
      }
    }
    if(debug)cout<<endl;
    if(debug)cout<<"s: "<<s<<"  e:"<<e<<"  cheack( "<<cnt<<" ): "<<num[cnt]<<"  dast: "<<dast<<"  cnt: "<<cnt<<endl;
    if(cnt==5){
      cout<<i+1<<endl;
      break;
    } 
  }
}


int main(){
  int n;
  string s;
  while(cin>>n){
    if(n==0)break;
    rep(i,n){cin>>s;haiku[i]=s.size();}
    solve(n);
  }
}

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

int main (){


  int n,ans = 0,count = 0,temp;
  int cc[5],ku;
  cc[0] = 5;
  cc[1] = 7;
  cc[2] = 5;
  cc[3] = 7;
  cc[4] = 7;

  char moji[40][10];
  while(1){
    scanf("%d",&n);
    if(n == 0) break;
    for(int i = 0;i < n;i++){
      scanf("%s",&moji[i]);
      //printf("%s ",moji[i]);fflush(0);
    }
	ans = 0;
	count = 0;
	temp = 0;
	ku = 0;
	while(1){
		temp += strlen(moji[ans+count]);
		//printf("%d",temp);
		if(cc[ku] == temp){
			if(ku == 4){
				break;
			}
			temp = 0;
			ku++;
		}
		else if(cc[ku] < temp){
			ku = 0;
			temp = 0;
			ans++;
			count = 0;
			continue;
		}
		count++;
	}
    printf("%d\n",ans+1);
  }
  return 0;
}

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;
		cout<<b[3];
		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;
		}if(k)break;
	    }
	    
		cout<<k+1<<endl;
	}
}

C++: #include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <numeric>

using namespace std;
using ll = long long;

int main()
{
    constexpr int len[5] = {5, 7, 5, 7, 7};
    while (true) {
        int n;
        cin >> n;
        if (n == 0) {
            break;
        }
        vector<int> l(n);
        for (int i = 0; i < n; i++) {
            string s;
            cin >> s;
            l[i] = s.size();
        }

        for (int i = 0; i < n; i++) {
            int ind = 0;
            int sum = 0;
            for (int j = i; j < n; j++) {
                if (ind == 5) {
                    break;
                }
                sum += l[j];
                if (sum > len[ind]) {
                    break;
                } else if (sum == len[ind]) {
                    ind++;
                    sum = 0;
                }
            }
            if (ind == 5) {
                cout << i << endl;
                break;
            }
        }
    }

    return 0;
}

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

int main(){
   while(true){
       int n;
       cin>>n;

       if(n==0) break;

       int len[40];
       for (int i = 0; i < n; i++) {
           string w;
           cin>>w;

           len[i]=w.size();
       }
       for (int i = 0; i < n; i++) {
           bool flg=false;
           int sta=0;
           int sum=0;

           for (int j = i; j < n; j++) {
               sum+=len[j];
               if(sum==5||sum==12||sum==17||sum==24||sum==31){
                   sta++;
               }
               if (sta==5) {
                   flg=true;
                   break;
               } else if(sum>=31){
                   break;
               }
           }

           if(flg){
               cout<<i+1<<endl;
               break;
           }
       }
    }
    return 0;
}