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<cstdlib>
#include<cstring>
#include<queue>
using namespace std;

const int maxn = 1000;
string str;
int n;
int mem[maxn];
int sum[maxn];
int memo[40];
queue<int> que;

bool check()
{
	int cnt = 0;
	if(memo[5]) cnt++;
	if(memo[12]) cnt++;
	if(memo[17]) cnt++;
	if(memo[24]) cnt++;
	if(memo[31]) cnt++;

	memo[5] = 0;
	memo[12] = 0;
	memo[17] = 0;
	memo[24] = 0;
	memo[31] = 0; 

	if(cnt == 5) return true;
	else return false;
}

int solve()
{
	for(int i = 0; i <= n; i++)
	{
		if(n >= 1) sum[i] = sum[i-1] + mem[i-1];
		else sum[i] = 0; 
	}

	for(int i = 0; i <= n; i++)
		for(int j = i+5; j <= n; j++)
		{
			if(sum[n] - sum[i] < 31) break;
			int d = sum[j]-sum[i];
			if(d > 31) break;
			else if(d == 31) que.push(i); 
		}
 
	int p, np; 
	while(!que.empty())
	{
		p = que.front(); que.pop();
		np = p + 1;
		//cout << "np " << np << endl;
		int total = 0;
		while(total!=31)
		{
			total += mem[p++];
			memo[total] = 1;
		}
		if(check()) return np;
	}
	return np;
}

bool Input()
{
	scanf("%d", &n); getchar();
	if(!n) return false;
	for(int i = 0; i < n; i++)
	{
		getline(cin, str); 
		mem[i] = str.length();
	}
	return true;
}

void Init()
{
	memset(mem, 0, sizeof(mem));
	memset(sum, 0, sizeof(sum));
	memset(memo, 0, sizeof(memo));
	while(!que.empty()) que.pop();
}

void Print()
{
	cout << "show" << endl;
	for(int i = 0; i <= n; i++)
	{
		printf("%d ", sum[i]);
	}
	cout << endl;
}

int main()
{
	//freopen("my.txt", "w", stdout);
	while(1)
	{
		Init();
		if(!Input()) break;
		printf("%d\n", solve());
		//Print();
	}
	return 0;
}

C++: #include<cstdio>
using namespace std;

int n;
int s[40];

int size(char *w) {
  int counter = 0;
  while (w[counter] != 0) counter++;
  return counter;
}

bool ok(int f, int s) {
  if (s <= 5) return true;
  if (f >= 5 && s <= 12) return true;
  if (f >= 12 && s <= 17) return true;
  if (f >= 17 && s <= 24) return true;
  if (f >= 24 && s <= 31) return true;
  return false;
}

int main() {
  while (1) {
    scanf("%d", &n);
    if (n == 0) break;
    for (int i = 0; i < n; i++) {
      char w[15];
      scanf("%s", w);
      s[i] = size(w);
    }
    for (int i = 0; i < n; i++) {
      int sum = 0;
      for (int j = i; j < n; j++) {
        if (!ok(sum, sum + s[j])) break;
        sum += s[j];
        if (sum == 31) break;
      }
      if (sum == 31) {
        printf("%d\n", i + 1);
        break;
      }
    }
  }
}

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

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

int main(){
    
    for(int n; cin >> n, n;){
        vector<int>v(n);
        for(int i = 0; i < n; i++){
            string s;
            cin >> s;
            v[i] = s.size();
        }
        for(int i = 0; i < n; i++){
            int flg = 0;
            int x = 0, y = 0;
            for(int j = i; j < n; j++){
                x += v[j];
                if(x > tanku[y])break;
                if(x == tanku[y]){
                    x = 0;
                    y++;
                }
                if(y == 5){
                    flg = 1;
                    break;
                }
            }
            if(flg){
                cout << i + 1 << endl;
                break;
            }
        }
    }

    return 0;
}

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

int main(){
    while(1) {
        int n;
        cin >> n;

        if (n == 0) break;

        vector<int> tmp(n);

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

        for (int i = 0; i < n; i++){

            int cnt = i;

            int check = 0;
            while (check < 5){
                check += tmp[cnt];
                cnt++;
            }
            if (check != 5) continue;

            check = 0;
            while (check < 7){
                check += tmp[cnt];
                cnt++;
            }
            if (check != 7) continue;

            check = 0;
            while (check < 5){
                check += tmp[cnt];
                cnt++;
            }
            if (check != 5) continue;

            check = 0;
            while (check < 7){
                check += tmp[cnt];
                cnt++;
            }
            if (check != 7) continue;

            check = 0;
            while (check < 7){
                check += tmp[cnt];
                cnt++;
            }
            if (check != 7) continue;

            cout << i + 1 << endl;
            break;
        }
    }
}

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

using namespace std;

using ll = long long;
#define rep(i,n) for(int i = 0; i < n ;++i)
#define all(v) v.begin(),v.end()

int main() {
  int n;
  while(cin >> n) {
    if (n == 0) {
      break;
    }
  vector<string> w(n);
  vector<int> d(n);
  for (int i =0; i < n; i++) {
    cin >> w[i];
    d[i] = w[i].size();
  }
  for (int i = 0; i < n; i++) {
    bool h = true;
    int st[5] = {0};
    int lm[5] = {5, 7, 5, 7, 7};
    int a = 0;
    for (int j = i; j < n; j++) {
      for (int k = a; k < 5; k++) {
        if (st[k] < lm[k]) {
          st[k] += d[j];
          break;
        } else if (st[k] > lm[k]) {
          h = false;
          break;
        }
        a++;
      }
      if (!h) {
        break;
      } else if (a == 5) {
        break;
      }
    }
    if (h) {
      cout << i+1 << endl;
      break;
    }
  }
  }
  return 0;
}