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 main()
{
	int n,k,l,m,q,p,a[205],b[205],i,j;
	string s;
	m=0;
	do{
		cin >> n;
		for(i=0; i<n; i++)
		{
			cin >> s;
			a[i]=s.size();
		}
		for(i=0; i<n-4; i++)
		{
			p=0;
			for(j=i; j<=n-4; j++)
			{
				p+=a[j];
				if(p>=5) break;
			}
			if(p==5)
			{
				p=0;
				for(k=j+1; k<=n-3; k++)
				{
					p+=a[k];
					if(p>=7) break;
				}
				if(p==7)
				{
					p=0;
					for(j=k+1; j<=n-2; j++)
					{
						p+=a[j];
						if(p>=5) break;
					}
					if(p==5)
			{
				p=0;
				for(k=j+1; k<=n-1; k++)
				{
					p+=a[k];
					if(p>=7) break;
				}
				if(p==7)
				{
					p=0;
					for(j=k+1; j<=n; j++)
					{
						p+=a[j];
						if(p>=7) break;
					}
					if(p==7) goto shilj;
				}
			}
				}
			}
		}
		
		shilj: b[m]=i+1;
		m++;
	}while(n!=0);
	for(i=0; i<m-1; i++)
		cout << b[i] << "\n";
}

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

using namespace std;

namespace {

    typedef double real;
    typedef long long ll;

    template<class T> ostream& operator<<(ostream& os, const vector<T>& vs) {
        if (vs.empty()) return os << "[]";
        os << "[" << vs[0];
        for (int i = 1; i < vs.size(); i++) os << " " << vs[i];
        return os << "]";
    }
    template<class T> istream& operator>>(istream& is, vector<T>& vs) {
        for (auto it = vs.begin(); it != vs.end(); it++) is >> *it;
        return is;
    }

    int N;
    vector<string> W;
    bool input() {
        cin >> N;
        if (N == 0) return false;
        W.clear(); W.resize(N); cin >> W;
        return true;
    }

    bool check(int i) {
        const vector<int> a = {5, 7, 5, 7, 7};
        int j = 0;
        int c = 0;
        while (j < 5) {
            c += W[i].size();
            if (c < a[j]) {
                i++;
            } else if (c == a[j]) {
                i++;
                j++;
                c = 0;
            } else {
                assert(c > a[j]);
                return false;
            }
        }
        return true;
    }

    void solve() {
        for (int i = 0; i < N; i++) {
            if (check(i)) {
                cout << i + 1 << endl;
                return;
            }
        }
        assert(false);
    }
}

int main() {
    while (input()) solve();
    return 0;
}

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


using namespace std;
typedef long long ll;
ll n,m,a,b;
ll i,j,k;
ll x[100005],y[100005];
char s[100];

bool solve(){
	cin >> n ;
	if(n == 0){
		return false;
	}
	ll ans = 0;
	for(i=0;i<100;i++){
		x[i] = 0;
		y[i] = 0;
	}
	for(i=0;i<n;i++){
		cin >> s;
		m = strlen(s);
		x[i] = m;
	}
	for(i=0;i<n;i++){
		ll sum = 0;
		ll a = 0;
		bool ok = false;
		for(j=i;j<n;j++){
			sum += x[j];
			if(sum == 5)a++;
			if(sum == 12)a++;
			if(sum == 17)a++;
			if(sum == 24)a++;
			if(sum == 31){
				a++;
				if(a == 5){
					ok = true;
					break;
				}else{
					ok = false;
					break;
				}
			}
			if(sum >= 32 && a <= 4){
				ok = false;
				break;
			}
		}
		if(ok){
			cout << i+1 << endl;
			return true;
		}else{
			//cout << "dame" << endl;
		}
	}

}


int main(){
	while(solve());
	return 0;
	
}

C++: /*  -*- coding: utf-8 -*-
 *
 * 1601.cc: Short Phrase
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 40;
const int K = 5;
const int ts[K] = { 5, 7, 5, 7, 7 };

/* typedef */

/* global variables */

char s[16];
int wls[MAX_N];

/* subroutines */

/* main */

int main() {
  for (;;) {
    int n;
    scanf("%d", &n);
    if (n == 0) break;

    for (int i = 0; i < n; i++) {
      scanf("%s", s);
      wls[i] = strlen(s);
    }

    for (int st = 0; st < n; st++) {
      int k = 0, sum = 0;
      for (int i = st; i < n && k < K; i++) {
	sum += wls[i];
	if (sum == ts[k])
	  k++, sum = 0;
	else if (sum > ts[k])
	  break;
      }

      if (k == K && sum == 0) {
	printf("%d\n", st + 1);
	break;
      }
    }
  }
  return 0;
}