시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 128 MB54292550.000%

문제

몇 개의 정점으로 이루어진 트리가 있다. 이 트리는 루트가 있는 트리이며, 각 정점은 몇 개의 자식 정점을 가질 수 있다. 각각의 정점에는 알파벳 대문자가 적혀 있다. 같은 문자가 여러 정점에 적혀 있을 수도 있다.

이 트리를 루트부터 시작해서 탐색하는데, 어떤 한 정점에서는 그 정점의 자식들 중 왼쪽 자식들부터 차례대로 방문해 나간다. 이와 같이 탐색하면 하나의 경로를 얻을 수 있다. 주의할 점은, 자식이 있는 정점의 경우에는 여러 번 방문될 수도 있는데(제일 처음 방문할 때와, 자식 정점을 방문하고 다시 돌아올 때), 그러한 경우에 한 정점이 여러 번 경로에 나타날 수도 있다는 것이다.

위의 그림은 경로가 ABABABA인 경우를 모두 나타낸 것이다. 아래쪽이 루트를 의미하며, 위로 연결된 것이 자식 노드를 의미한다. 위의 그림에서는 왼쪽 자식을 왼쪽에 나타냈는데, 대부분의 사람이 생각하는 그림처럼 루트가 위에 있는 그림으로 고치려면, 좌우 대칭을 해야 한다. 물론 답에는 변화가 없다.

경로가 주어졌을 때, 그러한 경로를 갖는 트리의 개수를 구해내는 프로그램을 작성하시오.

입력

첫째 줄에 경로가 주어진다. 이는 알파벳 대문자로만 이루어지며, 그 길이가 300자를 넘지 않는다.

출력

첫째 줄에 트리의 개수를 1,000,000,000으로 나눈 나머지를 출력한다.

예제 입력 1

ABABABA

예제 출력 1

5
W3sicHJvYmxlbV9pZCI6IjIwODgiLCJwcm9ibGVtX2xhbmciOiIwIiwidGl0bGUiOiJcdWQyYjhcdWI5YWNcdWM3NTggXHVhYzFjXHVjMjE4IiwiZGVzY3JpcHRpb24iOiI8cD5cdWJhODcgXHVhYzFjXHVjNzU4IFx1YzgxNVx1YzgxMFx1YzczY1x1Yjg1YyBcdWM3NzRcdWI4ZThcdWM1YjRcdWM5YzQgXHVkMmI4XHViOWFjXHVhYzAwIFx1Yzc4OFx1YjJlNC4gXHVjNz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