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 <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    int n;
    int w[5] = {5, 7, 5, 7, 7};
    while (cin >> n && n){
        VI a(n);
        REP(i,n) {
            string s;
            cin >> s;
            a[i] = s.length();
        }
        REP(s,n){
            int x = 0, i = s, j = 0, f = 1;
            while (f){
                x += a[i];
                i++;
                if (x == w[j]){
                    x = 0;
                    j++;
                }
                if (x > w[j]) f = 0;
                if (j == 5) break;
            }
            if (f) cout << s+1 << endl;
        }
    }

    return 0;
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
int tanka[5] = {5,7,5,7,7};

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(true) {
        int n;
        cin >> n;
        if(n == 0) break;
        string field[41];
        for(int i = 1; i <= n; i++) cin >> field[i];
        for(int start = 1; start <= n; start++) {
            int nowval = 0;
            int nowindex = 0;
            for(int i = start; i <= n; i++) {
                nowval += field[i].size();
                if(nowval == tanka[nowindex]) {
                    nowval = 0;
                    nowindex++;
                }
                if(nowindex == 5) break;
            }
            if(nowindex == 5) {
                cout << start << endl;
                break;
            }
        }
    }
    return 0;
}

C++: #include <iostream>
using namespace std;
int main(){
  while(true){
    int n;
    cin>>n;
    if(n==0){
      break;
    }
    int len[40];
    for(int i=0;i<n;i++){
      string w;
      cin>>w;
      len[i]=w.size();
    }
    for(int i=0;i<n;i++){
      bool flg=false;
      int sta=0;
      int sum=0;
      for(int j=1;j<n;j++){
        sum+=len[j];
        if(sum==5||sum==12||sum==17||sum==24||sum==31){
          sta++;
        }
        if(sta==5){
          flg=true;
          break;
        }
        else if(sum>=31){
          break;
        }
      }
      if(flg){
        cout<<i+1<<endl;
        break;
      }
    }
  }
    return 0;
}

C++: #include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
using ll = long long;
int main(void){
	while(1){
		int n,sum,flag;
		string str;
		cin >> n;
		if(n==0)	break;
		vector<int> len(n);
		for(int i=0;i<n;i++){
				cin >> str;
				len[i] = str.size();
		}
		for(int i=0;i<n;i++){
			sum=0;
			flag=0;
			for(int j=i;(j<n&&sum<=7);j++){
				sum+=len[j];
				if(sum==5&&flag==0){
					flag=1;
					sum=0;
				}
				if(sum==7&&flag==1){
					flag=2;
					sum=0;
				}
				if(sum==5&&flag==2){
					flag=3;
					sum=0;
				}
				if(sum==7&&flag==3){
					flag=4;
					sum=0;
				}
				if(sum==7&&flag==4){
					cout << i+1 << endl;
					flag=5;
				}
			}
			if(flag==5)	break;
		}
	}
	return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<list>
using namespace std;
int main() {
	int n;
	while (cin >> n&&n != 0) {
		string a[40];
		for (int i = 0; i < n; i++) {
			cin >> a[i];
		}
		int ans = 0;
		for (int i = 0; i < n; i++) {
			int sum=0;
			int i2 = -1;
			for (int j = i; j < n; j++) {
				sum += a[j].length();
				if (sum == 5) {
					i2 = j+1;
					break;
				}
			}
			if (i2 == -1) goto stop;
			if (i2 != -1) {
				sum = 0;
				for (int i = i2; i < n; i++) {
					sum += a[i].length();
					if (sum == 7) {
						i2 = i + 1;
						break;
					}
					i2 = -1;
				}
				if (i2 == -1) goto stop;
				sum = 0;
				for (int i = i2; i < n; i++) {
					sum += a[i].length();
					if (sum == 5) {
						i2 = i + 1;
						break;
					}
					i2 = -1;
				}
				if (i2 == -1) goto stop;
				sum = 0;
				for (int i = i2; i < n; i++) {
					sum += a[i].length();
					if (sum == 7) {
						i2 = i + 1;
						break;
					}
					i2 = -1;
				}
				if (i2 == -1) goto stop;
				bool l = true;
				sum = 0;
				for (int i = i2; i < n; i++) {
					sum += a[i].length();
					if (sum == 7) {
						i2 = i + 1;
						break;
					}
					i2 = -1;
				}
				if (i2 == -1) goto stop;
				ans = i;
				break;
			}
		stop:;
		}
		cout << ans+1 << endl;
	}
}

C++: #include <iostream>
#include <functional>
#include <algorithm>
#include <string>
using namespace std;
int num[5] = { 5,7,5,7,7 };
int main() {
	int n;
	int w[53];
	while (1) {
		cin >> n;
		if (n == 0)break;
		string s;
		for (int i = 0; i < n; i++) {
			cin >> s;
			w[i] = s.length();
		}
		for (int i = 0; i < n; i++) {
			int now = i;
			int x = 0;
			int cnt = 0;
			int judge = 0;
			while (1) {
				if (x == 5) {
					judge = 1;
					break;
				}
				cnt += w[now++];
				if (cnt == num[x]) {
					cnt = 0;
					x += 1;
				}
				if (cnt > num[x] || (now >= n&&x!=5))break;
			}
			if (judge == 1) {
				cout << i + 1 << "\n";
				break;
			}
		}
	}
}