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<string>
using namespace std;

int k[5] = { 5,7,5,7,7 };
int main() {
	int a;
	while (cin >> a, a) {
		int b[40];
		for (int c = 0; c < a; c++) {
			string d; cin >> d;
			b[c] = d.length();
		}
		for (int i = 0; i < a; i++) {
			int x = 0, y = 0;
			for (int j = i; j < a; j++) {
				if (y + b[j] > k[x])break;
				else if (y + b[j] < k[x])y += b[j];
				else { 
					x++; y = 0;
				if (x == 5) { cout << i + 1 << endl; goto l; }
				}
			}
		}
	l:;
	}
}

C++: #include<iostream>
#include<string>
int a[40],n;
int haiku(int);
using namespace std;
int main(){
  while(1){
    string x;
    cin >> n;
    if(n==0)break;
    for(int i=0;i<n;i++){
      cin >> x;
      a[i]=x.size();
    }
    int f;
    for(int i=0;i<n;i++){
      f=haiku(i);
      if(f==1){
	cout << i+1 << endl;
	break;
      }
    }
  }
  return 0;
}
int haiku(int x){
  int c=0,c2=0;
  for(int i=x;i<n;i++){
    c+=a[i];
    if(c2==0||c2==2){
      if(c<5)continue;
      else if(c==5){
	c=0;
	c2++;
	continue;
      }
      else return 0;
    }
    else{
      if(c<7)continue;
      if(c==7){
	c=0;
	c2++;
	if(c2==5)return 1;
	continue;
      }
      else return 0;
    }
  }
  return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <stack>
using namespace std;
int n, m;
string s;
int main() {
	while (cin >> n, n) {
		vector<string> v;
		for (int i = 0; i < n; ++i) {
			string str; cin >> str;
			v.push_back(str);
		}
		int point = 0;
		int cnt = 0;
		int i = 0; int j = 0;
		while (i < n) {
			cnt += v[i].size();
			i++;
			if (point == 0||point == 2) {
				if (cnt == 5) {
					point++;
                    cnt=0;
				}
				else if (cnt > 5) {
					cnt = 0;
					point = 0;
					j++;
					i = j;
				}
			}
			else if (point == 1||point == 3||point == 4) {
				if (cnt == 7) {
					point++;
					cnt=0;
				}
				else if (cnt > 7) {
					cnt = 0;
					point = 0;
					j++;
					i = j;
				}
			}
			if (point == 5) {
                cout << j+1 << endl;
                break;
            }
		}
	}
}

C++: #define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
  
using namespace std;
  
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
  
static const double EPS = 1e-8;
  
int tx[] = {0,1,0,-1};
int ty[] = {-1,0,1,0};

int main(){
  int num_word;
  while(~scanf("%d",&num_word)) {
    if (num_word == 0) break;
    
    vector<string> words;
    for (int word_i = 0; word_i < num_word; word_i++) {
      string word;
      cin >> word;
      words.push_back(word);
    }
    int res = 0;
    for (int start = 0; start < num_word; start++) {
      bool has_end[50];
      memset(has_end, 0, sizeof(has_end));
      int pos = 0;
      for (int word_i = start; word_i < num_word; word_i++) {
	pos += words[word_i].size();
	has_end[pos] = true;
      }

      if (has_end[5] && has_end[5 + 7] && has_end[5 + 7 + 5]
	  && has_end[5 + 7 + 5 + 7] && has_end[5 + 7 + 5 + 7 + 7]) {
	res = start + 1;
	break;
      }
    }
    printf("%d\n",res);
  }
}

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

int main() {
  int n;
  while (cin >> n, n) {
    auto c = vector<int>(n);
    for (int i = 0; i < n; ++i) {
      string w; cin >> w;
      c[i] = w.length();
    }
    auto solve = [&]() {
      for (int i = 0; i < n; ++i) {
        auto phrase = vector<int>{5, 7, 5, 7, 7};
        int idx = 0;
        for (int j = i; j < n; ++j) {
          if (phrase[idx] > 0) phrase[idx] -= c[j];
          if (phrase[idx] < 0) break;
          if (phrase[idx] == 0) ++idx;
          if (idx == 5) return i + 1;
        }
      }
      return 0;
    };
    cout << solve() << endl;
  }
  return 0;
}

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

using namespace std;

int main(void) {
    while (1) {
        int n;
        cin >> n;
        if (n == 0) break;

        int len[n + 1];
        for (int i = 1; i <= n; ++i) {
            string w;
            cin >> w;
            len[i] = w.length();
        }

        int cumulativesum[n + 1];
        cumulativesum[1] = len[1];
        for (int i = 2; i <= n; ++i) {
            cumulativesum[i] = cumulativesum[i - 1] + len[i];
        }

        bool cnt5 = false, cnt12 = false, cnt17 = false, cnt24 = false, cnt31 = false;
        int ans = 0;
        for (int i = 1; i <= n; ++i) {
//            for (int j = 1; j <= n; ++j) {
//                printf("%d ", cumulativesum[j]);
//            }
//            printf("\n");
            for (int j = i; j <= n; ++j) {
                if (cumulativesum[j] == 5) cnt5 = true;
                if (cumulativesum[j] == 12) cnt12 = true;
                if (cumulativesum[j] == 17) cnt17 = true;
                if (cumulativesum[j] == 24) cnt24 = true;
                if (cumulativesum[j] == 31) cnt31 = true;

                if (cnt5 && cnt12 && cnt17 && cnt24 && cnt31) ans = i;
            }
            if (ans != 0) break;
            for (int j = 1; j <= n; ++j) {
                cumulativesum[j] -= len[i];
            }
            cnt5 = false, cnt12 = false, cnt17 = false, cnt24 = false, cnt31 = false;
        }

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