Mirror Strings

시간 제한1초메모리 제한1024 MB

요약
각 문자가 상하·좌우로 뒤집혀도 같은 문자열인 거울 문자열의 개수를 길이 L부터 R까지 세어 1e9+7로 나눈 나머지를 구한다.
난이도

보통10점 중 6점

유형
동적 계획법, 조합론, 수학, 문자열
정답자
아직 제출이 없습니다

문제

A character is called a “mirror character” if it looks the same when flipped up and down, and the same when flipped left and right. The uppercase mirror characters, H, I, O, X. The lowercase mirror characters are l (since people often write this as a vertical line), o, and x.

In the same way, a string that looks the same when flipped up and down or when flipped left and right is called a “mirror string”. For example, XXOOOOXX is a mirror string.

The height of the character affects the construction of the mirror string. For example, llll and oooo are both mirror strings. However, lool is not a mirror string because it looks different when it is flipped up and down. The uppercase characters H, I, O, X and the lowercase character l are both of height 22 while the lowercase letters x and o are of height 1.

Tommy wants to construct mirror strings with lower characters and upper characters. He wants to know how many different mirror strings have length in the range \[L,R]\[L, R] (i.e. how many mirror strings have a length mm satisfying L≤m≤RL \leq m \leq R).

For example, the 77 mirror strings of length 11 are H, I, O, X, l, o, or x. There are also 77 mirror strings of length 22, namely HH, II, OO, XX, ll, oo, and xx. But there are many more mirror strings of bigger lengths, for example there are 2929 mirror strings of length 33.

입력

The first and only line of input contains two integers LL and RR (1≤L≤R≤1061 \leq L \leq R \leq 10^6), indicating the range of the lengths of mirror strings that Tommy wants to count.

출력

Output the number of mirror strings that have a length mm satisfing L≤m≤RL \leq m \leq R. Since there can be many such strings, you should output the answer modulo 109+710^9 + 7 (i.e. the remainder of the answer when it is divided by 109+710^9 + 7).

예제3

  1. 예제 1

    입력
    1 4
    
    예상 출력
    72
    
  2. 예제 2

    입력
    2 3
    
    예상 출력
    36
    
  3. 예제 3

    입력
    2 1000000
    
    예상 출력
    664868576