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;
#define MOD 1000000007
#define BIG 1000000010
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
typedef long long int ll;


int main(){
  int n;
  string s[40];
  int a[40];
  int check[5]={5,7,5,7,7};
  int cnt=0;
  bool b=false;
  while(1){
    cin>>n;
    if(n==0) break;
    b=false;
    rep(i,n){
      cin>>s[i];
      a[i]=s[i].size();
    }
    rep(i,n){
      cnt=0;
      int now=0;
      rep(j,5){
	cnt+=a[i+now];
	if(cnt<check[j]) j--;
	else if(cnt>check[j]) break;
	else cnt=0;
	if(j==4){cout<<i+1<<endl;b=true;break;}
	now++;
      }
      if(b) 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[n];
  for(int i=0; i<n; i++){
   string w;
   cin >> w;
   len[i] = w.size();
  }

  for(int i=0; i<n; i++){
   bool flag = false;
   int sta = 0; //区切り
   int sum = 0; //文字数の合計

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

    if(sta==5){
     flag = true;
     break;
    }else if(sum>=31){
     break;
    }
   }

   if(flag){
    cout << i+1 << endl;
    break;
   }
  }
 }

 return 0;
}

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

using namespace std;

bool ok(vector<int> v, int start) {
    int nums[5] = { 5, 7, 5, 7, 7 };
    int i = 0;
    auto itr = v.begin() + start;
    while (i < 5) {
        for (; itr != v.end(); ++itr) {
            if (*itr == nums[i]) {
                i++;
                continue;
            }
            else if (*itr >= nums[i]) {
                return false;
            }
            else {
                nums[i] -= *itr;
            }
        }
        return true;
    }
}

int main()
{
    int n;
    while (true) {
        cin >> n;
        if (n == 0) {
            return 0;
        }

        vector<int> v(n);
        for (int i = 0; i < n; i++) {
            string str;
            cin >> str;
            v[i] = str.size();
        }

        int start = 0, tail = 0;
        int sum = 0;
        while (true) {
            if (tail == n) {
                cout << 0 << endl;
                break;
            }

            while (tail < n && sum < (5 + 7 + 5 + 7 + 7)) {
                tail++;
                sum = accumulate(v.begin() + start, v.begin() + tail, 0);
            }

            if (sum == (5 + 7 + 5 + 7 + 7)) {
                if (ok(v, start)) {
                    cout << start << endl;
                    break;
                }
                else {
                    start++;
                    sum = accumulate(v.begin() + start, v.begin() + tail, 0);
                }
            }
            while (sum > (5 + 7 + 5 + 7 + 7)) {
                start++;
                sum = accumulate(v.begin() + start, v.begin() + tail, 0);
            }
        }
    }
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
const long long INF = 1e7 + 1;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector < pair<ll, ll > > vp;
typedef vector <string> vs;
typedef vector <char> vc;
typedef list <ll> lst;

ll n, m, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;


/*--------------------template--------------------*/

int main()
{
	while (1) {
	NEXT:
		cin >> n;
		if (n == 0) {
			return 0;
		} else {
			vi v;
			REP(i, n)
			{
				cin >> s;
				v.push_back(s.size());
			}
			cnt = 0;
			for (int i = cnt; i < n; i++) {
				ll j = cnt;
				ll flag = 0;
				sum = 0;
				while (1) {
					sum += v[j];
					j++;
					if (flag == 0) {
						if (sum == 5) {
							sum = 0;
							flag = 1;
						}
						if (sum > 5) {
							break;
						}
					} else if (flag == 1) {
						if (sum == 7) {
							sum = 0;
							flag = 2;
						}
						if (sum > 7) {
							break;
						}
					} else if (flag == 2) {
						if (sum == 5) {
							sum = 0;
							flag = 3;
						}
						if (sum > 5) {
							break;
						}
					} else if (flag == 3) {
						if (sum == 7) {
							sum = 0;
							flag = 4;
						}
						if (sum > 7) {
							break;
						}
					} else if (flag == 4) {
						if (sum == 7) {
							cout << cnt + 1 << endl;
							goto NEXT;
						}
						if (sum > 7) {
							break;
						}
					}
				}
				cnt++;
			}
		}
	}
}