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() {

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

		string word;
		int *length = new int[n];
		int key[5] = { 5,7,5,7,7 };
		for (int i = 0; i < n; i++) {
			cin >> word;
			length[i] = word.size();
			cout << length[i] << endl;
		}

		int count = 0;
		int section = 0;
		int index = 0;
		int output = 0;
		int start = 0;
		bool found = false;
		while (index != n) {
			index = output;
			output++;

			while (count <= 5) {
				if (key[count] > section) {
					section += length[index++];
				}
				else if (key[count] == section) {
					section = 0;
					count++;
				}
				else {
					break;
				}

				if (count == 5) {
					cout << output << endl;
					found = true;
				}
			}
			count = 0;
			section = 0;
			if (found)
				break;
		}
	}
	return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
string S[1000]; int  n, p[5] = { 5,12,17,24,31 };
int main() {
	while (true) {
		cin >> n; if (n == 0)break;
		for (int i = 0; i < n; i++)cin >> S[i];
		for (int i = 0; i < n; i++) {
			int cnt = 0, sum = 0;
			for (int j = i; j < n; j++) {
				if (cnt >= 5)continue;
				sum += S[j].size();
				if (p[cnt] == sum)cnt++;
			}
			if (cnt == 5) { cout << i + 1 << endl; break; }
		}
	}
	return 0;
}

C++: #include<cstdio>
#include<cstring>

int n,len[40];
char word[11];

int solve(int pos) {
	int rest;
	rest = 5;
	while (rest > 0) {
		rest -= len[pos++];
		if (rest < 0)return 0;
	}
	rest = 7;
	while (rest > 0) {
		rest -= len[pos++];
		if (rest < 0)return 0;
	}
	rest = 5;
	while (rest > 0) {
		rest -= len[pos++];
		if (rest < 0)return 0;
	}
	rest = 7;
	while (rest > 0) {
		rest -= len[pos++];
		if (rest < 0)return 0;
	}
	rest = 7;
	while (rest > 0) {
			rest -= len[pos++];
			if (rest < 0) return 0;
	}
	return 1;
}

int main() {
	while (1) {
		scanf("%d\n", &n);
		for (int i = 0; i < n; i++) {
			scanf("%s\n", word);
			len[i] = strlen(word);
		}
		for (int j = 0; j < n; j++) {
			if (solve(j)) {
				printf("%d\n", j + 1);
				break;
			}
		}
	}
}

C++: #include <iostream>
#include <string>
using namespace std;

int w[42]; // 1-origin
int n;
static const int secToNum[6] = {0, 5, 7, 5, 7, 7};

bool solve(int x) {
  int sum;
  for (int sec = 1; sec <= 5; sec++) {
    sum = 0;
    while (sum < secToNum[sec]) {
      sum += w[x];
      x++;
    }
    if (sum > secToNum[sec]) {
      return false;
    }
  }
  return true;
}

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

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

    for(int i = 1; i <= n; i++){
        if(solve(i))cout << i << endl;
        break;
    }
  }

  return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
#define inf 1e9
#define ll long long
#define ull unsigned long long
#define M 1000000007
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define RFOR(i,m,n) for(int i=m;i>=n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265

int a[10]={5,7,5,7,7};

void f(int n){
  string s[100];
  rep(i,n){
    cin>>s[i];
  }

  rep(i,n){
    int k=0;
    int t=0;
    FOR(j,i,n){
      t+=s[j].length();
      if(t==a[k]){
        k++;
        t=0;
      }
    }
    if(k==5){
      cout<<i+1<<endl;
      return;
    }
  }
}



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

  return 0;
}

C++: /*** ?????\ ***/

#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, n) for(int i=a; i<n; i++)

int main() {
	int N;
	while(cin>>N, N){
		int len[41]={};
		REP(i, 0, N){
			string s;
			cin >> s;
			len[i]=s.size();
		}
		
		REP(i, 0, N){
			int num=0;
			int haiku[5]={5, 7, 5, 7, 7};
			bool flag=false;
			
			REP(j, i, N){
				haiku[num]-=len[j];
				if(haiku[num]<0) break;
				if(haiku[num]==0) num++;
				if(num==5){
					flag=true;
					break;
				}
			}
			
			if(flag){
				cout << i+1 << endl;
				break;
			}
		}
	}
	return 0;
}

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

bool isHaiku(vector<string>::iterator t){
  
  int count;
  string s;

  count = 0;
  while(count < 5){
    s = *t;
    count+=s.size();
    t++;
  }
  if(count>5)return false;



  count = 0;
  while(count < 7){
    s = *t;
    count+=s.size();
    t++;
  }
  if(count>7)return false;



  count = 0;
  while(count < 5){
    s = *t;
    count+=s.size();
    t++;
  }
  if(count>5)return false;



  count = 0;
  while(count < 7){
    s = *t;
    count+=s.size();
    t++;
  }
  if(count>7)return false;



  count = 0;
  while(count < 7){
    s = *t;
    count+=s.size();
    t++;
  }
  if(count>7)return false;



  return true;

}

int main(){

  vector<string> s(0);
  int n;

  while( cin >> n , n){
    s.resize(n);
    for(int i=0; i<n;i++)cin>>s[i];
   
    // for(int i=0; i<n;i++)cout<<s[i]<<' ';

    int indx=0;
    while(isHaiku(s.begin()+indx)==false ){ indx++; }

    cout << indx+1 << endl;

  }


  return 0;
}