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 <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <set>
#include <map>
#include <queue>
#include <stack>

using namespace std;

#define INF 1010001000
#define EPS 1e-10
#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back

typedef pair<int, int> i_i;
typedef long long int llong;
typedef pair<llong, llong> ll_ll;
typedef struct edge {int f, t;}Edge;


int main()
{
    int n;
    while (cin >> n, n) {
        vector<int> in(n);
        rep(i, n) {
            string st;
            cin >> st;
            in[i] = st.length();
        }
        bool ret = false;
        rep(i, n) {
            int tnk = 0, state = 0;
            if (ret) {
                break;
            }
            for (int j = i; j < n; j++) {
                if (state == 0) {
                    tnk += in[j];
                    if (tnk == 5) {
                        state++;
                        tnk = 0;
                    } else if (tnk > 5) {
                        break;
                    }
                } else if (state == 1) {
                    tnk += in[j];
                    if (tnk == 7) {
                        state++;
                        tnk = 0;
                    } else if (tnk > 7) {
                        break;
                    }
                } else if (state == 2) {
                    tnk += in[j];
                    if (tnk == 5) {
                        state++;
                        tnk = 0;
                    } else if (tnk > 5) {
                        break;
                    }
                } else if (state == 3) {
                    tnk += in[j];
                    if (tnk == 7) {
                        state++;
                        tnk = 0;
                    } else if (tnk > 7) {
                        break;
                    }
                } else if (state == 4) {
                    tnk += in[j];
                    if (tnk == 7) {
                        cout << i+1 << endl;
                        ret = true;
                        break;
                    } else if (tnk > 7) {
                        break;
                    }
                }
            }
        }
    }
    return 0;
}

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

int main() {
  int n;
  while (cin >> n, n) {
    int ans = 0, key = 0;
    string s[n];
    rep(i, n) cin >> s[i];
    for (int i = 0; i < n; i++) {
      ans = 0;
      key = 0;
      for (int j = i; j < n; j++) {
        ans += s[j].size();
        if (ans == 5 && key == 0) {
          key = 1;
          ans = 0;
        } else if (ans > 5 && key == 0 || ans > 7 && key == 1 ||
                   ans > 5 && key == 2 || ans > 7 && key == 3 ||
                   ans > 7 && key == 4) {
          ans = 0;
          key = 0;
          break;
        } else if (ans == 7 && key == 1) {
          key = 2;
          ans = 0;
        } else if (ans == 5 && key == 2) {
          ans = 0;
          key = 3;
        } else if (ans == 7 && key == 3) {
          ans = 0;
          key = 4;
        } else if (ans == 7 && key == 4) {
          cout << i + 1 << endl;
        }
      }
    }
  }
  return 0;
}

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


int main(){
  while(1){
    int n;
    cin>>n;
    if(n==0) break;
    int a[50];
    string memo;
    lp(i,n){
      cin>>memo;
      a[i]=memo.size();
    }
    lp(i,n){
      int ans=0;
      int count=0,stats=0;
      for(int j=i;j<n;j++){
	if(stats==0||stats==2){
	  count+=a[j];
	  if(count==5){
	    stats++;
	    count=0;
	  }
	  if(count>5) break;
	}
	else if(stats==1||stats==3||stats==4){
	  count+=a[j];
	  if(count==7){
	    stats++;
	    count=0;
	  }
	  if(count>7) break;
	}
	if(stats==5) {
	  ans=1;
	  break;
	}
      }
      if(ans==1) {
	cout<<i+1<<endl;
	break;
      }
    }
  }
  return 0;
}

C++: #include<iostream>
#include<vector>
#include<string>
#include<cstdlib>
#include<sstream>
#include<queue>
#include<deque>
#include<cmath>
#include<algorithm>
#include<stack>
#include<map>
#include<set>
#include<iomanip>
#define INF 2147483647
#define lli long long int
#define MOD 1000000007
#define pb push_back

using namespace std;
typedef vector<int> vi;
typedef vector< vector<int> > vvi;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
int main() {
	while(1){
		int n; cin >> n;
		if (n == 0) break;
		
		vector<string> str(n);
		for(int i = 0; i < n; i++) {
			cin >> str[i];	
		}

		int ans = 0;
		for(int i = 0; i < n; i++) {
			ans = i;	
			vector<int> check = {5,7,5,7,7};
			int idx = 0;
			for (int j = i; j < n; j++) {
					if (check[idx] > 0){
						check[idx] -= str[j].size();
					}else if(check[idx] <= 0){
						idx++;
						check[idx] -= str[j].size();
					}
					
			}
			int sum = 0;
			for (int k = 0; k < 5; k++){
				sum += check[k];
			}
			if (sum == 0){
				break;
			}

		}
		cout << ans + 1 << endl;
	}

	return 0;
}