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 <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>

using namespace std;

int main() {
  int n;
  const int tank[] = {5, 7, 5, 7, 7};
  while (cin >> n && n) {
    vector<int> w(n);
    for (int i = 0; i < n; i++) {
      string ww;
      cin >> ww;
      w[i] = ww.length();
    }
    int ans = -1;

    for (int i = 0; i < n; i++) {  //??????????????°?????????????????????
      int tmp = 0;
      int cnt = 0;
      for (int j = i; j < n; j++) {
        tmp += w[j];
        //cerr << tmp << " ";
        if (tmp < tank[cnt]) {
          //?¶???????????????§?????????????¬???????????????????
        } else if (tmp == tank[cnt]) {
          //????????????????????§?¬???????????????????
          tmp = 0;
          cnt++;
          if (cnt == 5) {
            // 57577????????£???
            ans = i + 1;
            goto FIN;
          }

        } else {
          //??¢???????????§??±???
          break;
        }
      }
      //cerr << endl;
    }

  FIN:
    cout << ans << endl;
  }
  return 0;
}

C++: #include "bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = int(b) - 1; i >= (int)(a); --i)
using pii = pair<int, int>;
using vi = vector<int>;

int solve(int n) {
	vi a(n);
	rep(i, 0, n) {
		string s;
		cin >> s;
		a[i] = s.size();
	}

	const vi seq = { 5, 7, 5, 7, 7 };
	rep(i, 0, n) {
		int s = 0;
		int idx = 0;
		bool ng = false;
		rep(j, i, n) {
			s += a[j];
			if (s == seq[idx]) {
				s = 0;
				idx++;
				if (idx == seq.size())break;
			}
			else if (s > seq[idx]) {
				ng = true;
				break;
			}
		}
		if (!ng) {
			return i + 1;
		}
	}
	return -1;
}

signed main() {
	while (1) {
		int n;
		cin >> n;
		if (n == 0) break;
		cout << solve(n) << endl;
	}
}

C++: #include <bits/stdc++.h>

using namespace std;

#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int n;
string w[50];
bool ok(int idx) {
    int now = 0;
    vector<int> vec{5, 7, 5, 7, 7};
    rep(i, n) if (idx <= i) {
        vec[now] -= w[i].size();
        if (vec[now] == 0) {
            now++;
            if (now == vec.size()) return true;
        }
        if (vec[now] < 0) {
            break;
        }
    }
    return false;
}
void solve() {
    rep(i, n) {
        if (ok(i)) {
            cout << i + 1 << endl;
            break;
        }
    }
}
int main() {
    while (cin >> n, n) {
        rep(i, n) cin >> w[i];
        solve();
    }

    return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = long long;
using P = std::tuple<int,int>;

const int dx[8] = {-1, 1, 0, 0, -1, -1, 1, 1}, dy[8] = {0, 0, -1, 1, -1, 1, -1, 1};

int RHYTHM[6] = {5, 7, 5, 7, 7};

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

    while(true){
        int N;
        std::cin >> N;
        if(!N){break;}

        vector<int> ls;
        for(int i=0;i<N;++i){
            string w;
            std::cin >> w;

            ls.emplace_back(w.size());
        }

        int res = -1;
        for(int i=0;i<N;++i){
            int pos = 0, len = 0;
            for(int j=i;j<N;++j){
                if(len + ls[j] > RHYTHM[pos]){
                    break;
                }else if(len + ls[j] == RHYTHM[pos]){
                    len = 0;
                    ++pos;
                }else{
                    len += ls[j];
                }

                if(pos == 5){
                    break;
                }
            }

            if(pos == 5){
                res = i + 1;
                break;
            }
        }

        std::cout << res << std::endl;
    }
}

C++: #include<cstdio>
main(){puts("hoge");}

C++: #include <stdio.h>
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int make(int w,int p);

vector<string> a(50);

int main() {
  int n;
  scanf ("%d",&n);
  while(n){

    for(int t=0;t<n;t++){
      //scanf ("%s",a[t]);
      cin >> a[t];
    }
    for(int t=n;t<50;t++){
      //scanf ("%s",a[t]);
      a[t]="";
    }
    int end=0;
    int k=0;
    for(k=0;k<n;k++){
      int q=k;
      if(make(q,5)>=1){
        q=1+make(q,5);
        if(make(q,7)>=1){
          q=1+make(q,7);
          if(make(q,5)>=1){
            q=1+make(q,5);
            if(make(q,7)>=1){
              q=1+make(q,7);
              if(make(q,7)>=1){
                end=1;
                //printf("qwqw\n");
              }
            }
          }
        }
      }
      if(end==1) break;
    }
    printf("%d\n",k+1);
    scanf ("%d",&n);
  }
}


int make(int w,int p){
  int l=a[w].size();
  if(l==p){
    return w;
  }
  else{
    if(l<p){
      //printf("%d\n",r);
      return make(w+1,p-l);
    }
    else{
      return -1;
    }
  }
}

C++: #include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	string s;
	while(cin>>n,n){
		int a[40]={0},b[4]={0},j=0,i=0,c=0,k=0;
		for(;j<n;j++){
			cin>>s;
			a[i++]=s.size();
		}
		for(j=0;j<35;j++){
			if(!a[j])break;
		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;
			}
		}}
		cout<<n-j+1<<endl;
	}
}