跳到主要内容
图灵 OJTURING / ONLINE JUDGE

#F1081. Matvey's Birthday

    ID: 1087 传统题 2000ms 256MiB 尝试: 0 已通过: 0 难度: 10 上传者: 标签>位运算图论数学挑战难度共享题库Codeforces英文题面题目来源题面语言

Matvey's Birthday

题目描述

E. Matvey's Birthday
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Today is Matvey's birthday. He never knows what to ask as a present so friends gave him a string s of length n. This string consists of only first eight English letters: 'a', 'b', ..., 'h'.

First question that comes to mind is: who might ever need some string? Matvey is a special boy so he instantly found what to do with this string. He used it to build an undirected graph where vertices correspond to position in the string and there is an edge between distinct positions a and b (1≤a,bn) if at least one of the following conditions hold:

  1. a and b are neighbouring, i.e. |a-b|=1.
  2. Positions a and b contain equal characters, i.e. sa=sb.

Then Matvey decided to find the diameter of this graph. Diameter is a maximum distance (length of the shortest path) among all pairs of vertices. Also, Matvey wants to find the number of pairs of vertices such that the distance between them is equal to the diameter of the graph. As he is very cool and experienced programmer he managed to solve this problem very fast. Will you do the same?

Input

The first line of the input contains a single integer n (2≤n≤100000)− the length of the string.

The second line contains the string s itself. It's guaranteed that s consists of only first eight letters of English alphabet.

Output

Print two integers− the diameter of the graph and the number of pairs of positions with the distance equal to the diameter.

Examples
Input
3
abc
Output
2 1
Input
7
aaabaaa
Output
2 4
Note

Consider the second sample.

The maximum distance is 2. It's obtained for pairs (1,4), (2,4), (4,6) and (4,7).


题目来源:fps-www.educg.net-codeforce-1-2833.xml.zip;FPS 共享题包,题包内第 543 题。保留原作者与原赛事署名。