Go: package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	io := NewIo()
	defer io.Flush()
	for {
		n := io.NextInt()
		if n == 0 {
			break
		}
		s := make([]string, n)
		for i := 0; i < n; i++ {
			s[i] = io.NextLine()
		}
		w := [5]int{5, 7, 5, 7, 7}
		ans := 0
	OUTER:
		for i := 0; i < n; i++ {
			cnt, wc := 0, 0
			for j := i; j < n; j++ {
				wc += len(s[j])
				if wc == w[cnt] {
					cnt++
					wc = 0
					if cnt == 5 {
						ans = i + 1
						break OUTER
					}
				} else if wc > w[cnt] {
					break
				}
			}
		}
		io.Println(ans)
	}
}

// I/O template
type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func NewIo() *Io {
	return &Io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

func (io *Io) NextLine() string {
	var buff []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buff = append(buff, line...)
		if !isPrefix {
			break
		}
	}
	return string(buff)
}

func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	s := io.tokens[io.nextToken]
	io.nextToken++
	return s
}

func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) NextFloat() float64 {
	i, err := strconv.ParseFloat(io.Next(), 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

func (io *Io) Printf(format string, a ...interface{}) {
	fmt.Fprintf(io.writer, format, a...)
}

func (io *Io) PrintIntSlice(a []int) {
	b := make([]interface{}, 0, len(a))
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func (io *Io) PrintStringSlice(a []string) {
	b := make([]interface{}, 0, len(a))
	for _, x := range a {
		b = append(b, x)
	}
	io.Println(b...)
}

func Log(name string, value interface{}) {
	fmt.Fprintf(os.Stderr, "%s=%+v\n", name, value)
}

func ExampleIo() {
	io := NewIo()
	defer io.Flush()
	a := make([]int, 0, 3)
	a[0], a[1], a[2] = io.NextInt(), io.NextInt(), io.NextInt()
	io.Println(a)
	io.PrintIntSlice(a)
	Log("io", a)
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16
#define mod 1000000007

int n;
vector<int> a;
int b[]={5,7,5,7,7,0};

int main(){
  while(1){
    cin>>n;
    if(n==0)break;
    a.clear();
    rep(i,n){
      string s;
      cin>>s;
      a.push_back(s.size());
    }
    rep(i,n){
      int j=0,rest=b[0];
      repl(k,i,n){
        if(rest<a[k])break;
        rest-=a[k];
        if(rest==0){
          j++; rest=b[j];
          if(j==5)break;
        }
      }
      if(j==5){
        cout<<i+1<<endl;
        break;
      }
    }
  }
  return 0;
}

C++: #include <iostream>
#include <vector>
using namespace std;
int main(){
    int n;
    while(cin>>n,n){
        vector<int> V(n);
        for(int i=0;i<n;i++){
            string s;
            cin>>s;
            V[i]=s.size();
        }
        for(int i=0;i<n;i++){
            int j=i;
            int cnt=0;
            while(cnt<5&&j<n)cnt+=V[j++];
            if(cnt!=5) continue;
            cnt=0;
            while(cnt<7&&j<n)cnt+=V[j++];
            if(cnt!=7) continue;
            cnt=0;
            while(cnt<5&&j<n)cnt+=V[j++];
            if(cnt!=5) continue;
            cnt=0;
            while(cnt<7&&j<n)cnt+=V[j++];
            if(cnt!=7) continue;
            cnt=0;
            while(cnt<7&&j<n)cnt+=V[j++];
            if(cnt!=7) continue;
            else{
                cout<<i+1<<endl;
                break;
            }
        }
    }
    return 0;
}

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

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

int main()
{
    vector<int> ans;
    while (1)
    {
        int n;
        cin >> n;
        if (n == 0)
            break;
        vector<string> w(n);
        for (int i = 0; i < n; i++)
        {
            cin >> w[i];
        }
        for (int i = 0; i < n; i++) //スタート位置
        {
            int turn = 0;
            for (int j = i; j < n; j++)
            {
                int num = 0;
                if (turn == 5)
                    break;
                else if (turn == 0 || turn == 2) //5のとき
                {
                    while (num < 5 && j < n)
                    {
                        num += w[j].size();
                        j++;
                    }
                    j--;
                    if (num != 5)
                        goto End;
                    turn++;
                }
                else if (turn == 1 || turn == 3 || turn == 4) //7のとき
                {
                    while (num < 7 && j < n)
                    {
                        num += w[j].size();
                        j++;
                    }
                    j--;
                    if (num != 7)
                        goto End;
                    turn++;
                }
            }
            ans.push_back(i + 1);
            break;
        End:;
        }
    }
    for (int i = 0; i < ans.size(); i++)
    {
        cout << ans[i] << endl;
    }
}

C++: #include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repp(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;

signed main(){
    int n;
    int cd[6] = {5, 7, 5, 7, 7, 10000};
    while(cin >> n, n){
        string s;
        vector<int> d(n);
        rep(i, 0, n){
            cin >> s;
            d[i] = (int)(s.size());
        }
        int ans = 0;
        rep(i, 0, n){
            int cnt = 0, ind = 0;
            rep(j, i, n){
                cnt += d[j];
                if(cnt == cd[ind]){
                    cnt = 0;
                    ind++;
                }
                if(cnt > cd[ind]) break;
            }
            if(ind == 5){
                ans = i + 1;
                break;
            }
        }
        cout << ans << endl;
    }
}

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

int main(){
  int n;
  while(cin>>n,n){
    string str[50];
    for(int i=0;i<n;i++)cin>>str[i];

    int num[]={5,7,5,7,7},ans=1000000;
    for(int i=0;i<n;i++){
      for(int j=i,idx=0,cnt=0;j<n;j++){
	cnt+=str[j].size();
	if(cnt==num[idx]) idx++,cnt=0;
	if(cnt>num[idx])break;
	if(idx==5) ans=min(ans,i);
      }    
    }
    cout <<ans+1<<endl;
  }
  return 0;
}

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

int main(){
  string w;
  int len[40];
  int tanku[]={5,7,5,7,7};
  int n,sum=0;
  for(;;){
    cin>>n;
    if(n==0) break;
    for(int i=0;i<n;i++){
      cin>>w;
      len[i]=w.size();
      sum+=len[i];
    }
    for(int i=0,jud=0;i<n;i++){
      if(sum<27) break;
      for(int j=i,k=0,m=0;j<n;j++){
	if(m+len[j]>tanku[k]) break;
	else if(m+len[j]==tanku[k]){
	  k++; m=0;
	}
	else m+=len[j];
	if(k==5){
	  cout<<i+1<<endl; jud=1; break;
	}
      }
      if(jud) break;
    }
  }
}