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 <bits/stdc++.h>
#include <string>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define shosu(n) setprecision(n)
using namespace std;

int main() {
  int n;
  while (cin >> n, n) {
    int ans = 0, key = 0, ke2 = 0;
    string s[n];
    rep(i, n) cin >> s[i];
    for (int i = 0; i < n; i++) {
      ans = 0;
      key = 0;
      for (int j = i; j < n; j++) {
        ans += s[j].size();
        if (ans == 5 && key == 0) {
          key = 1;
          ans = 0;
        } else if (ans > 5 && key == 0 || ans > 7 && key == 1 ||
                   ans > 5 && key == 2 || ans > 7 && key == 3 ||
                   ans > 7 && key == 4) {
          ans = 0;
          key = 0;
          break;
        } else if (ans == 7 && key == 1) {
          key = 2;
          ans = 0;
        } else if (ans == 5 && key == 2) {
          ans = 0;
          key = 3;
        } else if (ans == 7 && key == 3) {
          ans = 0;
          key = 4;
        } else if (ans == 7 && key == 4) {
          cout << i + 1 << endl;
          ke2 = 1;
          break;
        }
      }
      if (ke2 == 1)
        break;
    }
  }
  return 0;
}

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

#define rep(i, n, m) for(int i=n;i<m;i++)

using namespace std;

const int num[5] = {5,7,5,7,7};

int main() {
    int n;
    while(scanf("%d", &n) && n){
        int a[n+1];
        rep(i, 0, n){
            string s;
            cin >> s;
            a[i+1] = s.length();
        }

        int ans = -1;
        rep(i, 1, n+1){
            int num_i = 0, cnt = 0;
            rep(j, i, n+1){
                cnt += a[j];
                if(num[num_i] == cnt){
                    num_i++;
                    cnt = 0;
                    if(num_i == 5){
                        ans = i;
                        break;
                    }
                }else if(cnt > num[num_i]){
                    break;
                }
            }
            if(ans != -1) break;
        }

        printf("%d\n", ans);
    }
}

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

int main(void) {
  int n;
  int tanku[]={5,7,5,7,7};
  while (true) {
    cin >> n;
    if (n==0) {
      break;
    }
    string a;
    vector<int> w(n);
    for (int i=0; i<n; i++) {
      cin >> a;
      w[i]=a.size();
    }
    for (int i=0; i<n; i++) {
      int sum=0;
      int k=0;
      bool flag=false;
      for (int j=i; j<n; j++) {
        sum+=w[j];
        if (sum>tanku[k]) {
          break;
        }
        if (sum==tanku[k]) {
          k++;
          sum=0;
        }
        if (k==5) {
          flag=true;
          break;
        }
      }
      if (flag) {
        cout<<i+1<<endl;
        break;
      }
    }
  }
  return 0;
}

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

int n, len, ans, cnt, tanka[5] = {5, 7, 5, 7, 7};
string s[50];
bool flag;

int main(void){ 
  cin.tie(0);
  ios::sync_with_stdio(false);

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

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

    cnt = len = ans = 0;
    flag = false;

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

      ans = i + 1;
      len = 0;

      for (int j = i; j < n; ++j) {
        len += s[j].size();
        //cout << len << " " << s[j] << endl;

        if (len == tanka[cnt]) {
          cnt++;
          len = 0;
          if (cnt == 5) {
            cout << ans << endl;
            flag = true;
          }
        }
        else if (len < tanka[cnt]) {
          continue;
        }
        else if (len > tanka[cnt]) {
          len = 0;
          cnt = 0;
          break;
        }
      }

    }

      for (int i = 0; i < 49; ++i) s[i] = "";
  }

  return 0;
}

C++: #include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
using namespace std;
int main(){
  int n;
  int flag[5]={5,7,5,7,7};
  while(cin >> n,n){
    string str;
    vector<int> cnt;
    rep(i,n){
      cin >> str;
      int tmp = str.size();
      cnt.push_back(tmp);
    }
    bool finish = false;
    rep(i,n){
      //cout << "#" << endl;
      int stage = 0;
      int sum = cnt[i];
      if(sum > flag[0]) continue;
      else if(sum == flag[0]) {
        stage++;
        sum = 0;
      }
      for(int j=i+1; j<n; j++){
        //cout << stage  << " " << sum << endl;
        sum += cnt[j];
        if(sum > flag[stage]) break;
        else if(sum == flag[stage]){
          stage++;
          sum = 0;
        }
        if(stage == 5) {
          cout << i+1 << endl;
          finish  = true;
          break;
        }
      }
      if(finish == true) break;
    }
  }
  return 0;
}

C++: #include <iostream>
#include <vector>
#include <string>
#define pb push_back

using namespace std;
int main(void){
  int i,j,n;
  string s;
  int t,tmpi;
  while(cin>>n,n){
    vector<string> a;
    for(i=0;i<n;i++){
      cin>>s;
      a.pb(s);
    }
    
    for(i=0;i<n;){
      tmpi=i+1;
      t=0;
      while(t<5){
	t+=a[i].size();
	i++;
      }
      if(t>5) {i=tmpi;continue;}
      //cout<<":5"<<endl;
      t=0;
      while(t<7){
	t+=a[i].size();i++;
      }
      if(t>7) {i=tmpi;continue;}
      //cout<<":7"<<endl;
      t=0;
      while(t<5){
	t+=a[i].size();i++;
      }
      if(t>5) {i=tmpi;continue;}
      //cout<<":5"<<endl;
      t=0;
      while(t<7){
	t+=a[i].size();i++;
      }
      if(t>7) {i=tmpi;continue;}
      //cout<<":7"<<endl;
      t=0;
      while(t<7){
	t+=a[i].size();i++;
      }
      if(t>7) {i=tmpi;continue;}
      //cout<<":7"<<endl;
      if(t==7) break;
    }
    cout<<tmpi<<endl;
  }
  return 0;
}