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


using namespace std;

int main()
{

	while (true) {

		int n;
		cin >> n;
		if (n == 0) {
			return 0;
		}
		string str;
		int nums[41];

		for (int i = 0; i < n; i++) {
			cin >> str;
			nums[i] = str.size();
		}

		int start = 0;
		int tail = 0;
		int sum = 0;
		while (true) {
			while (tail < n && sum < (5 + 7 + 5 + 7 + 7)) {
				tail++;

				sum = 0;
				for (int i = start; i < tail; i++) {
					sum += nums[i];
				}
			}
			if (sum < (5 + 7 + 5 + 7 + 7)) {
				break;
			}
			else if (sum == (5 + 7 + 5 + 7 + 7)) {
				int ns[5] = { 5, 7, 5, 7, 7 };
				int s = start;
				int i = 0;
				while (i < 5) {
					if (nums[s] == ns[i]) {
						i++;
						s++;
					}
					else if (nums[s] > ns[i]) {
						break;
					}
					else {
						ns[i] = ns[i] - nums[s];
						s++;
					}
				}
				if (i == 5) {
					cout << start + 1 << endl;
					break;
				}

			}

			while (start < tail && sum >(5 + 7 + 5 + 7 + 7)) {
				start++;

				sum = 0;
				for (int i = start; i < tail; i++) {
					sum += nums[i];
				}
			}

		}
	}

	return 0;
}

C++: def main():
    while True:
        n = int(input().strip())

        if n == 0:
            break

        phrases = []
        for _ in range(n):
            word = input().strip()
            phrases.append(word)

        PHRASE_LEN = [5,7,5,7,7]
        found_flag = False

        for i in range(n):
            acc_len = 0
            phrase_idx = 0
            for j in range(i, n):
                acc_len += len(phrases[j])

                if acc_len == PHRASE_LEN[phrase_idx]:
                    if phrase_idx == (len(PHRASE_LEN)-1):
                        found_flag = True
                        break

                    acc_len = 0
                    phrase_idx += 1
                elif acc_len > PHRASE_LEN[phrase_idx]:
                    break

            if found_flag:
                print(i+1)
                break

if __name__ == "__main__":
    main()

C++: #include<iostream>
#include<vector>
#include<string>
using namespace std;
int main(void){
    int n;
    vector<string> w(n);
    while(true){
        cin >>n;
        if(n==0) break;
        for(int i=0;i<n;i++)
        cin >> w[i];
        int tanku[5]={5,7,5,7,7};
        bool judge=false;
        //?§??????????
        for(int i=0;i<n;i++){
            int place=i;
            //tanku ibannme
            for(int j=0;j<5;j++){
    int sum=0;
    //kasan
    while(place<n){
        sum+=w[place].size();
        place++;
        if(spum>=tanku[j])
        break;
    }if(sum>tanku[j])
    break;
    if(j==4&&sum==tanku[4]){
            cout << i+1 << endl;
            judge=true;
            break;
        }
            }
            if(judge)
break;
        }
    }
return 0;
}

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

bool acceptable(const vector<int> w, int i) {
  const vector<int> tanku = {5, 7, 5, 7, 7};
  for (int ku : tanku) {
    int sum = 0;
    while (sum < ku) {
      sum += w[i++];
    }
    if (sum != ku) {
      return false;
    }
  }
  return true;
}

int main() {
  int N;
  while (cin >> N && N) {
    vector<int> W(N);
    for (int i = 0; i < N; ++i) {
      string str;
      cin >> str;
      W[i] = str.length();
    }
    for (int i = 1; i <= N; ++i) {
      if (acceptable(W, i - 1)) {
        cout << i << endl;
        break;
      }
    }
  }
}

C++: #include<bits/stdc++.h>
int i,j,d[50],p,n,q,a[5]={5,7,5,7,7};
char s[15];
main(){
	for(n=1;n;){
		scanf("%d\n",&n);
		for(i=0;i<n;i++)d[i]=strlen(gets(s));
		for(i=0;i<n;i++){
			p=i;
			for(j=0;j<5;j++){
				q=a[j];
				while(q>0){
					q-=d[p];p++;
				}
				if(q)p=-1;
			}
			if(p>0){
				printf("%d\n",i+1);
				break;
			}
		}
	}
}

C++: #include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
const int INF=(ll)(1LL<<31)-1;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
//int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int n;
int w[40];
int tanka[5]={5,7,5,7,7};
vector<int> ans;

int main(){
	while(1){
		cin>>n;
		if(n==0)break;
		for(int i=0;i<n;i++){
			string t;
			cin>>t;
			w[i]=t.size();
		}
		for(int i=0;i<n-4;i++){
			int nn=i;
			int nc=0;
			int tn=0;
			while(tn<5){
				if(nc+w[nn]>tanka[tn]){
					//cout<<1<<endl;
					break;
				}else if(nc+w[nn]<tanka[tn]){
					//cout<<nc<<endl;
					nc+=w[nn];
					nn++;
				}else{
					//cout<<3<<endl;	
					tn++;
					nn++;
					nc=0;
				}
			}
			if(tn==5){
				ans.push_back(i+1);
				break;
			}
		}
	}
	REP(i,(int)ans.size()){
		cout<<ans[i]<<endl;
	}
	return 0;
}