This page is still under construction.

Parts of this page are still being built. What you see may change.

Anagrams divisible by 11

Time limit1sMemory limit128 MB

Summary
Count distinct digit permutations of N with no leading zero that are multiples of 11, modulo 1e9+7.
Level

Medium7 of 10

Topics
Dynamic programming, Combinatorics, Math
Solved
No attempts yet

Problem

A natural number can be written as a sequence of digits, and a sequence of digits can be read back as a natural number. A leading zero is not allowed. For example, N=2090N = 2090 gives the sequence {2,0,9,0}\{2, 0, 9, 0\}, while the sequence {0,0,1,0}\{0, 0, 1, 0\} represents no natural number.

An anagram of a sequence keeps the same elements and only changes their order. Anagrams of a natural number are defined the same way. The anagrams of N=2090N = 2090 are 2009, 2090, 2900, 9002, 9020, 9200.

Given a natural number NN, write a program that counts how many anagrams of NN are multiples of 11. For N=2090N = 2090, only 2090 and 9020 are multiples of 11, so the answer is 2.

Input

The first line contains a natural number NN with no leading zero. (1≤N≤101001 \le N \le 10^{100})

Output

Print how many anagrams of NN are multiples of 11. The answer can be very large, so print it modulo 109+710^9 + 7.

Examples1

  1. Example 1

    Input
    2090
    
    Expected output
    2