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 rep(i, n) for (int i = 0; i < int(n); ++i)

int solve(int n, const vector<string>& w) {
    vector<int> five(n + 1, -1), seven(n + 1, -1);
    rep(i, n) {
        for (int j = i, l = 0; j < n && l < 7; ++j) {
            l += w[j].size();
            if (l == 5) five[i] = j;
            if (l == 7) seven[i] = j;
        }
    }
    rep (i, n) {
        int k = i;
        bool ok = true;
        rep(j, 5) {
            k = (j == 0 || j == 2 ? five[k] : seven[k]) + 1;
            if (k == 0) {
                ok = false;
                break;
            }
        }
        if (ok) return i + 1;
    }
    return -1;
}

int main() {
    for (int n; cin >> n, n;) {
        vector<string> w(n);
        for (auto& e : w) cin >> e;
        cout << solve(n, w) << endl;
    }
}

C++: #include <iostream>
#include <string>
using namespace std;
int main(void){
    int n,j,i,a[41],sum,count;
    string w[41] = {}; 
    while(1){
        
        cin >> n;
        if(n == 0) break;
        
        for(i=1;i<n+1;i++){
            cin >> w[i];
            a[i] = w[i].length();
          //  cout << w[i] << ":" << a[i] << endl;
        }
        
        sum = 0;
        count = 5;
        
        for(j = 1;j<=n-4;j++){
            sum = 0;
            count = 5;
            for(i=j;i<n+1;i++){
                
                sum = sum + a[i];
                if(sum == 5) count--;
                else if ( sum == 12) count--;
                else if ( sum == 17) count--;
                else if ( sum == 24) count--;
                else if ( sum == 31) count--;
                
     //       cout << j << ":" << sum << ":" << count  << endl;
                if ( sum >= 31) break;
        
            }
            
            if(count == 0){
                cout << j << endl;
                break;
            }
        }
        
    
    }
    return 0;
    
    
}

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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int t[]={5,7,5,7,7};

signed main(){
    int N;
    while(cin>>N,N){
        vector<string>S(N);
        rep(i,N)cin>>S[i];
        rep(i,N){
            bool ok=true;
            int cur=i;
            rep(j,5){
                int sum=0;
                while(cur<N&&sum<t[j]){
                    sum+=S[cur++].size();
                }
                if(sum!=t[j])ok=false;
            }
            if(ok){
                cout<<i+1<<endl;
                break;
            }
        }
    }
    return 0;
}

C++: #include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1 << 28;
//constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;

using namespace std;
typedef unsigned long long ull;
typedef long long ll;

int main()
{
	/*
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	*/

	int kkt = 89;
	while (kkt) {
		int n; cin >> n; if (n == 0) break;
		vector<string> vs(n); for (int i = 0; i < n; i++) cin >> vs[i];
		int res = -1;
		for (int i = 0; i < n; i++) {
			int f = 0;
			int sum = 0;

			for (int j = i; j < n; j++) {
				sum += vs[j].size();
				if (f == 0 or f == 2) {
					if (sum == 5) {
						f++;
						sum = 0;
					}
					else if (sum > 5) {
						break;
					}
				}
				else {
					if (sum == 7) {
						f++;
						sum = 0;
					}
					else if (sum > 7) break;
				}
				if (f == 5) {
					res = i + 1;
					break;
				}
			}
			if (res != -1) break;
		}
		cout << res << "\n";
	}
	return 0;

}

C++: #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
#define int long long

signed main() {
  while (true) {
    int n;
    cin >> n;
    if (!n) return 0;
    string s[n];
    for (int i = 0; i < n; i++) {
      cin >> s[i];
    }
    for (int i = 0; i < n; i++) {
      int count;
      int res = 0;
      count = 0;
      int j = i;
      while (res < 5) {
        count += s[j].size();
        if (res == 0 || res == 2) {
          if (count > 5) break;
          else if (count == 5) {
            res++;
            count = 0;
          }
        } else {
          if (count > 7) break;
          else if (count == 7) {
            res++;
            count = 0;
          }
        }
        j++;
      }
      if (res == 5) {
        cout << i + 1 << endl;
        break;
      }
    }
  }
}