#include <cmath>
#include <vector>
#include <iostream>
#include <cstdio>

using namespace std;

int main() {
    int N;
    char temp;
    vector<char> A;
    A.push_back(0);
    scanf("%d",&N);
    for (int i=0;i<N+1;i++) {
    scanf("%c",&temp);
    if(A[i]==0) {
        A[i]=temp;
    }
    if (temp>=A[i-1]) {
        A.push_back(temp);
    }
    }

 for (vector<char>::iterator it = A.begin() ; it != A.end(); ++it)
    cout << ' ' << *it;
  cout << '\n';
  int counter=1;
  long long rez=1,jed,frez;
  for (int i=0;i<=N + 1;i++) {
      if (A[i]==A[i-1]) {
          counter++;
      }
      else if (A[i+1]=='Z'+1) {
          rez=rez*counter;
      }
      else {
          rez=rez*counter;
          counter=1;
      }
      
  }
     jed=(pow(10,9)+7);
     frez=rez%jed;
    cout<<frez<<endl;
  return 0;
}