using System;
using System.Collections.Generic;
using System.Linq;

class Program {
  static void Main (string[] args) {
    long N = long.Parse (Console.ReadLine ());
    // int _Y = int.Parse (Console.ReadLine ());
    // int _Z = int.Parse (Console.ReadLine ());
    long[] a = new long[100000000];
    // long[] array = new long[1000000000];

    List<long> alist = new List<long> ();

    string[] input = Console.ReadLine ().Split (' ');
    for (int i = 0; i < N; i++) {
      a[i] = long.Parse (input[i]);
    }

    int count=0;

    alist.Add(a[0]);
    alist.Add(0);

    for (int i = 1; i < N; i++) {
      int num = alist.Count;
      for (int j=0;j<num;j++){
         if (alist[j]!=0){
           if (alist[j]+a[i]==0)count++;
         }
         alist[j]+=a[i];
      }
      alist.Add(0);

      string s ="";
      for (int j=0;j<alist.Count;j++){
        s+= a[j]+" ";
      }
      Console.WriteLine (s);
    }
 

    Console.WriteLine (count);

  }

}