Problem:


Score : 800 points

Problem Statement

For a positive integer n, we denote the integer obtained by reversing the decimal notation of n (without leading zeroes) by rev(n). For example, rev(123) = 321 and rev(4000) = 4.

You are given a positive integer D. How many positive integers N satisfy rev(N) = N + D?

Constraints

D is an integer.

1 ≤ D < 10^9

Input

Input is given from Standard Input in the following format:

D

Output

Print the number of the positive integers N such that rev(N) = N + D.

Sample Input 1

63

Sample Output 1

2

There are two positive integers N such that rev(N) = N + 63: N = 18 and 29.

Sample Input 2

75

Sample Output 2

0

There are no positive integers N such that rev(N) = N + 75.

Sample Input 3

864197532

Sample Output 3

1920



Sample input:
63


Sample output:
2

Submission status: Wrong Answer

Solution code:

"""

https://atcoder.jp/contests/arc075/tasks/arc075_d

桁数を決め打ちする？
 abcd
-dcba
 ABCD

999a+90b-90c-999d = ABCD

みたいな感じになる
これをいい感じに満たせばおk
aとd,bとcをまとめる
-9～9の19通り


19**4 = 2476099通り
aとdの分配の仕方の通り数をあらかじめ数えておけばおｋ
ただし、a != 0
差は、9999109999
      9999019999
差があるとDを超える場合は探索を打ち切ればおｋ

"""
import sys

def dfs(dig,nd,nsum):

    P = 10**((dig-1)-nd) - 10**nd #この桁の寄与の基準
    if nd == dig//2:
        if nsum == D:
            if dig % 2 == 0:
                return 1
            else:
                return 10
        return 0
    elif nd != 0:
        ret = 0
        for i in range(-9,10):
            if nsum+P*i < 0 or nsum+P*i > D:
                continue
            ret += dfs(dig,nd+1,nsum+P*i) * sums[i]
        #print (ret,"y")
        return ret
    else:
        ret = 0
        for i in range(-9,10):
            if nsum+P*i < 0 or nsum+P*i > D:
                continue
            tmp = dfs(dig,nd+1,nsum+P*i) * sums_z[i]
            #if tmp > 0:
            #    print (dig,nd+1,i,"is 1",tmp)
            ret += tmp
        return ret
            

D = int(input())
ans = 0
sums = [0] * 30
for i in range(-9,10):
    for x in range(-9,1):
        for y in range(0,10):
            if x+y == i:
                sums[i] += 1
print (sums , file=sys.stderr)
sums_z = [0] * 30
for i in range(-9,10):
    for x in range(-9,0):
        for y in range(1,10):
            if x+y == i:
                sums_z[i] += 1
print (sums_z , file=sys.stderr)

for dig in range(1,20):

    now = dfs(dig,0,0)
    #print (dig,now)
    ans += now

print (ans)

Submission status: Wrong Answer

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


d = int(input())
from collections import defaultdict
vals = defaultdict(int)
vals2 = defaultdict(int)
for i in range(10):
    for j in range(10):
        vals[i-j] += 1
        if j>0:
            vals2[i-j] += 1
def sub(n):
    vs = []
    if pow(10,n)-1>d:
        return 0
    for i in range(n):
        if i>=n-i:
            break
        vs.append(pow(10,n-i) - pow(10,i))
#     if 9*sum(vs)<d:
#         return 0
    def _sub(val, i):
        """vs[i:]以降でvalを作る通り数
        """
        if i==len(vs):
            if val==0:
                return 1
            else:
                return 0
        ans = 0
        for j in range(-9, 10):
            if (vs[i]*j)%pow(10,i+1)==val%(pow(10,i+1)):
                ans += _sub(val-vs[i]*j, i+1) * vals[j]
        return ans
                
    ans = 0
    for i in range(-9,10):
        if (vs[0]*i)%10==d%10:
            ans += _sub(d-vs[0]*i, 1) * vals2[i]
    if n%2==0:
        ans *= 10
    return ans
ans = 0
i = 1
while True:
    val = sub(i)
    ans += val
    if i>20:
        break
#     if pow(10,i)-1>d:
#         break
    i += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


d = int(input())
from collections import defaultdict
vals = defaultdict(int)
vals2 = defaultdict(int)
for i in range(10):
    for j in range(10):
        vals[i-j] += 1
        if j>0:
            vals2[i-j] += 1
def sub(n):
    vs = []
    if pow(10,n)-1>d:
        return 0
    for i in range(n):
        if i>=n-i:
            break
        vs.append(pow(10,n-i) - pow(10,i))
#     if 9*sum(vs)<d:
#         return 0
    def _sub(val, i):
        """vs[i:]以降でvalを作る通り数
        """
        if i==len(vs):
            if val==0:
                return 1
            else:
                return 0
        ans = 0
        for j in range(-9, 10):
            if (vs[i]*j)%pow(10,i+1)==val%(pow(10,i+1)):
                ans += _sub(val-vs[i]*j, i+1) * vals[j]
        return ans
                
    ans = 0
    for i in range(1,10):
        if (vs[0]*i)%10==d%10:
            ans += _sub(d-vs[0]*i, 1) * vals2[i]
    if n%2==0:
        ans *= 10
    return ans
ans = 0
i = 1
while True:
    val = sub(i)
    ans += val
    if i>20:
        break
#     if pow(10,i)-1>d:
#         break
    i += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


d = int(input())
from collections import defaultdict
vals = defaultdict(int)
vals2 = defaultdict(int)
for i in range(10):
    for j in range(10):
        vals[i-j] += 1
        if j>0:
            vals2[i-j] += 1
def sub(n):
    vs = []
    if pow(10,n)-1>d:
        return 0
    for i in range(n):
        if i>=n-i:
            break
        vs.append(pow(10,n-i) - pow(10,i))
#     if 9*sum(vs)<d:
#         return 0
    def _sub(val, i):
        """vs[i:]以降でvalを作る通り数
        """
        if i==len(vs):
            if val==0:
                return 1
            else:
                return 0
        ans = 0
        for j in range(-9, 19):
            if (vs[i]*j)%pow(10,i+1)==val%(pow(10,i+1)):
                ans += _sub(val-vs[i]*j, i+1) * vals[j]
        return ans
                
    ans = 0
    for i in range(1,10):
        if (vs[0]*i)%10==d%10:
            ans += _sub(d-vs[0]*i, 1) * vals2[i]
    if n%2==0:
        ans *= 10
    return ans
ans = 0
i = 1
while True:
    val = sub(i)
    ans += val
    if i>20:
        break
#     if pow(10,i)-1>d:
#         break
    i += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


d = int(input())
from collections import defaultdict
vals = defaultdict(int)
vals2 = defaultdict(int)
for i in range(10):
    for j in range(10):
        vals[i-j] += 1
        if j>0:
            vals2[i-j] += 1
def sub(n):
    vs = []
    if pow(10,n)-1>d:
        return 0
    for i in range(n):
        if i>=n-i:
            break
        vs.append(pow(10,n-i) - pow(10,i))
#     if 9*sum(vs)<d:
#         return 0
    def _sub(val, i):
        """vs[i:]以降でvalを作る通り数
        """
        if i==len(vs):
            if val==0:
                return 1
            else:
                return 0
        ans = 0
        for j in range(-9, 19):
            if (vs[i]*j)%pow(10,i+1)==val%(pow(10,i+1)):
                ans += _sub(val-vs[i]*j, i+1) * vals[j]
        return ans
                
    ans = 0
    for i in range(1,10):
        if (vs[0]*i)%10==d%10:
            ans += _sub(d-vs[0]*i, 1) * vals2[i]
    if n%2==0:
        ans *= 10
    return ans
ans = 0
i = 1
while True:
    val = sub(i)
    ans += val
    if pow(10,i)-1>d:
        break
    i += 1
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


d = int(input())
from collections import defaultdict
vals = defaultdict(int)
vals2 = defaultdict(int)
for i in range(10):
    for j in range(10):
        vals[i-j] += 1
        if j>0:
            vals2[i-j] += 1
def sub(n):
    vs = []
    if pow(10,n)-1>d:
        return 0
    for i in range(n):
        if i>=n-i:
            break
        vs.append(pow(10,n-i) - pow(10,i))
    if 9*sum(vs)<d:
        return 0
    def _sub(val, i):
        """vs[i:]以降でvalを作る通り数
        """
        if i==len(vs):
            if val==0:
                return 1
            else:
                return 0
        ans = 0
        for j in range(-9, 19):
            if (vs[i]*j)%pow(10,i+1)==val%(pow(10,i+1)):
                ans += _sub(val-vs[i]*j, i+1) * vals[j]
        return ans
                
    ans = 0
    for i in range(1,10):
        if (vs[0]*i)%10==d%10:
            ans += _sub(d-vs[0]*i, 1) * vals2[i]
    if n%2==0:
        ans *= 10
    return ans
ans = 0
i = 1
while True:
    val = sub(i)
    ans += val
    if pow(10,i)-1>d:
        break
    i += 1
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline

def f(i,d):
    """
    i 桁の n で、r(n)-n = d
    """
    n = i-1
    m = 0
    res = []
    while n>m:
        x = 10**n-10**m
        if m:
            res.append(tuple((x*k,v) for k,v in d2.items()))
        else:
            res.append(tuple((x*k,v) for k,v in d1.items()))
        n -= 1
        m += 1
    
    def sums(lsts):
        dic = {0:1}
        for lst in lsts:
            ndic = {}
            for k1,v1 in dic.items():
                for k2,v2 in lst:
                    k = k1+k2
                    v = v1*v2
                    if k in ndic: ndic[k] += v
                    else: ndic[k] = v
            dic = ndic
        
        return dic.items()
    
    L = len(res)
    #print(res[L//2:])
    s1 = sums(res[:L//2])
    s2 = sorted(sums(res[L//2:]))
    
    #print(s1)
    #print(s2)
    #print(d)

    v = 0
    from bisect import bisect_left
    for k1,v1 in s1:
        idx = bisect_left(s2,(d-k1,0))
        if idx < len(s2) and s2[idx][0] == d-k1:
            #print(k1,v1,idx,s2[idx])
            v += v1*s2[idx][1]
    return v*(1 if i%2==0 else 10)


d, = map(int,read().split())

ans = 0

from collections import Counter

d1 = Counter()
for i in range(10):
    for j in range(1,10):
        d1[i-j] += 1
        
d2 = Counter()
for i in range(10):
    for j in range(10):
        d2[i-j] += 1

for i in range(2,18):
#for i in range(2,19):
    r = f(i,d)    
    #print(r,i)
    ans += r
    if d%(10**9-10**8)==0:
        r = d//(10**9-10**8)
        
        
        ans += d2[r]*(10**7)*9

print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline

def f(i,d):
    """
    i 桁の n で、r(n)-n = d
    """
    n = i-1
    m = 0
    res = []
    while n>m:
        x = 10**n-10**m
        if m:
            res.append(tuple((x*k,v) for k,v in d2.items()))
        else:
            res.append(tuple((x*k,v) for k,v in d1.items()))
        n -= 1
        m += 1
    
    def sums(lsts):
        dic = {0:1}
        for lst in lsts:
            ndic = {}
            for k1,v1 in dic.items():
                for k2,v2 in lst:
                    k = k1+k2
                    v = v1*v2
                    if k in ndic: ndic[k] += v
                    else: ndic[k] = v
            dic = ndic
        
        return dic.items()
    
    L = len(res)
    #print(res[L//2:])
    s1 = sums(res[:L//2])
    s2 = sorted(sums(res[L//2:]))
    
    #print(s1)
    #print(s2)
    #print(d)

    v = 0
    from bisect import bisect_left
    for k1,v1 in s1:
        idx = bisect_left(s2,(d-k1,0))
        if idx < len(s2) and s2[idx][0] == d-k1:
            #print(k1,v1,idx,s2[idx])
            v += v1*s2[idx][1]
    return v*(1 if i%2==0 else 10)


d, = map(int,read().split())

ans = 0

from collections import Counter

d1 = Counter()
for i in range(10):
    for j in range(1,10):
        d1[i-j] += 1
        
d2 = Counter()
for i in range(10):
    for j in range(10):
        d2[i-j] += 1

for i in range(2,18):
#for i in range(2,19):
    r = f(i,d)    
    #print(r,i)
    ans += r
    if d%(10**9-10**8)==0:
        r = d//(10**9-10**8)
        
        
        ans += d2[r]*10**8

print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline

def f(i,d):
    """
    i 桁の n で、r(n)-n = d
    """
    n = i-1
    m = 0
    res = []
    while n>m:
        x = 10**n-10**m
        if m:
            res.append(tuple((x*k,v) for k,v in d2.items()))
        else:
            res.append(tuple((x*k,v) for k,v in d1.items()))
        n -= 1
        m += 1
    
    def sums(lsts):
        dic = {0:1}
        for lst in lsts:
            ndic = {}
            for k1,v1 in dic.items():
                for k2,v2 in lst:
                    k = k1+k2
                    v = v1*v2
                    if k in ndic: ndic[k] += v
                    else: ndic[k] = v
            dic = ndic
        
        return dic.items()
    
    L = len(res)
    #print(res[L//2:])
    s1 = sums(res[:L//2])
    s2 = sorted(sums(res[L//2:]))
    
    #print(s1)
    #print(s2)
    #print(d)

    v = 0
    from bisect import bisect_left
    for k1,v1 in s1:
        idx = bisect_left(s2,(d-k1,0))
        if idx < len(s2) and s2[idx][0] == d-k1:
            #print(k1,v1,idx,s2[idx])
            v += v1*s2[idx][1]
    return v*(1 if i%2==0 else 10)


d, = map(int,read().split())

ans = 0

from collections import Counter

d1 = Counter()
for i in range(10):
    for j in range(1,10):
        d1[i-j] += 1
        
d2 = Counter()
for i in range(10):
    for j in range(10):
        d2[i-j] += 1

for i in range(2,18):
#for i in range(2,19):
    r = f(i,d)    
    #print(r,i)
    ans += r

print(ans)

Submission status: Wrong Answer

Solution code:
def solve(NUM):
    s = str(NUM)
    sz = len(str(NUM))
    if s=='9':
        return '12'
    if s=='99':
        return '102'
    if(s[0]=='9'):
        if(s[-1]=='9'):
            for i in range(2,sz-1):
                if(s[i]!=s[i-1]):
                    return -1
            ans = '1'
            for i in range(sz-1):
                ans+='0'
            ans+='2'
            if s[1]==0:
                ans = '11'+ans[2:]
                return ans
            if s[1]==9:
                return ans
            return -1
        else:
            return -1
    for i in range(10**(sz-1),2*(10**(sz-1))):
        ri = int(str(i)[::-1])
        if i+NUM==ri:
            return str(i)
    return -1

D = int(input())
s = solve(D)
if s==-1:
    print(0)
else:
    n = len(s)
    ans = 1
    for i in range(n):
        j = n-1-i
        if j<i:
            break
        x = int(s[i])
        y = int(s[j])
        xy = max(x,y)
        ans *= 10-xy
    print(ans)

Submission status: Wrong Answer

Solution code:
D=int(input())

ans=0
for i in range(1,1000):
    val=str(i)
    val=val[::-1]
    rev=int(val)
    if rev-i==D:
        ans+=1

for d in range(4,18):
    dic1={}
    dic2={}
    if d%2==0:
        k=d//2
        l=k//2
        def dfs(n,a):
            if n==l:
                val=0
                res=1
                for i in range(len(a)):
                    val+=a[i]*(10**(d-1-i)-10**i)
                    if i!=0:
                        res*=10-abs(a[i])
                    else:
                        res*=9-abs(a[i])
                if val not in dic1:
                    dic1[val]=0
                dic1[val]+=res
                return 0

            for i in range(-9,10):
                dfs(n+1,a+[i])

        dfs(0,[])

        def dfs2(n,a):
            if n==k:
                val=0
                res=1
                for i in range(len(a)):
                    val+=a[i]*(10**(d-1-l-i)-10**(i+l))
                    if i!=0:
                        res*=10-abs(a[i])
                    else:
                        res*=10-abs(a[i])
                if val not in dic2:
                    dic2[val]=0
                dic2[val]+=res
                return 0

            for i in range(-9,10):
                dfs2(n+1,a+[i])

        dfs2(l,[])
        for i in dic1:
            if D-i in dic2:
                ans+=dic1[i]*dic2[D-i]

    else:
        k=d//2
        l=k//2
        def dfs(n,a):
            if n==l:
                val=0
                res=1
                for i in range(len(a)):
                    val+=a[i]*(10**(d-1-i)-10**i)
                    if i!=0:
                        res*=10-abs(a[i])
                    else:
                        res*=9-abs(a[i])
                if val not in dic1:
                    dic1[val]=0
                dic1[val]+=res
                return 0

            for i in range(-9,10):
                dfs(n+1,a+[i])

        dfs(0,[])

        def dfs2(n,a):
            if n==k:
                val=0
                res=1
                for i in range(len(a)):
                    val+=a[i]*(10**(d-1-l-i)-10**(i+l))
                    if i!=0:
                        res*=10-abs(a[i])
                    else:
                        res*=10-abs(a[i])
                if val not in dic2:
                    dic2[val]=0
                dic2[val]+=res
                return 0

            for i in range(-9,10):
                dfs2(n+1,a+[i])

        dfs2(l,[])

        for i in dic1:
            if D-i in dic2:
                ans+=dic1[i]*dic2[D-i]*10

print(ans)

Submission status: Wrong Answer

Solution code:
D=int(input())

ans=0
for d in range(1,18):
    dic1={}
    dic2={}
    if d%2==0:
        k=d//2
        l=k//2
        def dfs(n,a):
            if n==l:
                val=0
                res=1
                for i in range(len(a)):
                    val+=a[i]*(10**(d-1-i)-10**i)
                    if i!=0:
                        res*=10-abs(a[i])
                    else:
                        res*=9-abs(a[i])
                if val not in dic1:
                    dic1[val]=0
                dic1[val]+=res
                return 0

            for i in range(-9,10):
                dfs(n+1,a+[i])

        dfs(0,[])

        def dfs2(n,a):
            if n==k:
                val=0
                res=1
                for i in range(len(a)):
                    val+=a[i]*(10**(d-1-l-i)-10**(i+l))
                    if i!=0:
                        res*=10-abs(a[i])
                    else:
                        res*=10-abs(a[i])
                if val not in dic2:
                    dic2[val]=0
                dic2[val]+=res
                return 0

            for i in range(-9,10):
                dfs2(n+1,a+[i])

        dfs2(l,[])
        for i in dic1:
            if D-i in dic2:
                ans+=dic1[i]*dic2[D-i]

    else:
        k=d//2
        l=k//2
        def dfs(n,a):
            if n==l:
                val=0
                res=1
                for i in range(len(a)):
                    val+=a[i]*(10**(d-1-i)-10**i)
                    if i!=0:
                        res*=10-abs(a[i])
                    else:
                        res*=9-abs(a[i])
                if val not in dic1:
                    dic1[val]=0
                dic1[val]+=res
                return 0

            for i in range(-9,10):
                dfs(n+1,a+[i])

        dfs(0,[])

        def dfs2(n,a):
            if n==k:
                val=0
                res=1
                for i in range(len(a)):
                    val+=a[i]*(10**(d-1-l-i)-10**(i+l))
                    if i!=0:
                        res*=10-abs(a[i])
                    else:
                        res*=10-abs(a[i])
                if val not in dic2:
                    dic2[val]=0
                dic2[val]+=res
                return 0

            for i in range(-9,10):
                dfs2(n+1,a+[i])

        dfs2(l,[])

        for i in dic1:
            if D-i in dic2:
                ans+=dic1[i]*dic2[D-i]*10

print(ans)

Submission status: Wrong Answer

Solution code:
d = int(input())
ans = 1
if d%9:
  print(0)
  exit()
flgx = 0
if d == 9:
  print(8)
  exit()
while d%10 == 0:
  flgx = 1
  ans *= 9
  d //= 10
flg = 0
if d%10 == 9:
  s = list("0"+str(d))
else:
  s = list(str(d))
k = len(s)//2
for i in range(k):
  x = int(s[i])+int(s[-i-1])+flg
  if x == 18:
    ans *= 10
    continue
  if x <= 8 or x >= 11:
    print(0)
    exit()
  if flgx == 1:
    ans *= int(s[-i-1])
  elif flg:
    ans *= int(s[-i-1])+1
  elif flg == 0:
    ans *= int(s[-i-1])-1
  if x == 10:
    flg = 1
  else:
    s[i+1],s[-i-2] = s[-i-2],s[i+1]
    flgx = 1
if len(s)%2:
  if s[k] == "9":
    ans *= 10
  else:
    print(0)
    exit()
print(ans)

Submission status: Wrong Answer

Solution code:
d = int(input())
ans = 1
if d%9:
  print(0)
  exit()
flgx = 0
if d == 9:
  print(8)
  exit()
while d%10 == 0:
  flgx = 1
  ans *= 9
  d //= 10
k = len(str(d))//2
flg = 0
if d%10 == 9:
  s = list("0"+str(d))
else:
  s = list(str(d))
for i in range(k):
  x = int(s[i])+int(s[-i-1])+flg
  if x == 18:
    ans *= 10
    continue
  if x <= 8 or x >= 11:
    print(0)
    exit()
  if flgx == 1:
    ans *= int(s[-i-1])
  elif flg:
    ans *= int(s[-i-1])+1
  elif flg == 0:
    ans *= int(s[-i-1])-1
  if x == 10:
    flg = 1
  else:
    s[i+1],s[-i-2] = s[-i-2],s[i+1]
    flgx = 1
if len(s)%2:
  if s[k] == "9":
    ans *= 10
  else:
    print(0)
    exit()
print(ans)

Submission status: Wrong Answer

Solution code:
def f(d,x,y):n=int("9"*x+"0"*y);return d==0 if x<1 else sum(f(d%n+i,x-2,y+1)*(10-abs(d/n+i)-(y<1))for i in[0,1]if -10<i<10)
D=input();print sum(f(D,i,0)*(10-i%2*9)for i in range(1,21))

Submission status: Wrong Answer

Solution code:
import itertools as ite
import math
import random

INF = 10 ** 18
MOD = 10 ** 9 + 7

def func(diff, cnt9, cnt0):
    if cnt9 <= 0:
        return (diff == 0)
    num = int("9" * cnt9 + "0" * cnt0)
    return sum(func(diff + i * num, cnt9 - 2, cnt0 + 1) * (9 - abs(i) + 1 - (cnt0 < 1)) for i in range(-9, 10) if abs(diff + i * num) < num)

D = input()
print sum(func(D, d, 0) * (1 + (d % 2) * 9) for d in range(1, 21))

Submission status: Wrong Answer

Solution code:
import itertools as ite
import math
import random

INF = 10 ** 18
MOD = 10 ** 9 + 7

def func(diff, cnt9, cnt0):
    if diff == 0:
        return 1
    if cnt9 <= 0:
        return 0
    num = int("9" * cnt9 + "0" * cnt0)
    ret = 0
    for i in range(-9, 10):
        if abs(diff + i * num) < num:
            MUL = 9 - abs(i) + 1
            MUL -= (cnt0 == 0)
            ret += func(diff + i * num, cnt9 - 2, cnt0 + 1) * MUL
    return ret

D = input()

ans = 0
for d in range(1, 21):
    MUL = 1 if d % 2 == 1 else 10
    ans += func(D, d, 0) * MUL
print ans

Submission status: Wrong Answer

Solution code:
from collections import deque
D=int(input())
def f(d,k):
  if 0<=k<=1:
    if d!=0:
      return "Unko"
    if k==1:
      return deque([0])
    else:
      return deque([])
  s=10-(d%10)
  if s==10:
    A=f(d//10,k-2)
    s=0
  #print(d,s,d-s*(10**(k-1))+s)
  else:
    A=f((d-s*(10**(k-1))+s)//10,k-2)
  if A=="Unko":
    return "Unko"
  A.appendleft(s)
  A.append(-s)
  return A
ans=0
for k in range(1,50):
  A=f(D,k)
  if A=="Unko":
    continue
 # print(A)
  res=1
  for j in range((k+1)//2):
    if j==0:
      res*=9-abs(A[j])
    else:
      if A[j]==0:
        res*=10
      else:
        res*=10-abs(A[j])
  ans+=res
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
D=int(input())
def f(d,k):
  if 0<=k<=1:
    if d!=0:
      return "Unko"
    if k==1:
      return deque([0])
    else:
      return deque([])
  s=10-(d%10)
  if s==10:
    A=f(d//10,k-2)
    s=0
  #print(d,s,d-s*(10**(k-1))+s)
  else:
    A=f((d-s*(10**(k-1))+s)//10,k-2)
  if A=="Unko":
    return "Unko"
  A.appendleft(s)
  A.append(-s)
  return A
ans=0
for k in range(1,50):
  A=f(D,k)
  if A=="Unko":
    continue
  #print(A)
  res=1
  for j in range((k+1)//2):
    if j==0:
      res*=9-abs(A[j])
    else:
      if A[j]==0:
        res*=10
      else:
        res*=9-abs(A[j]-1)
  ans+=res
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
D=int(input())
def f(d,k):
  if 0<=k<=1:
    if d!=0:
      return "Unko"
    if k==1:
      return deque([0])
    else:
      return deque([])
  s=10-(d%10)
  if s==10:
    A=f(d//10,k-2)
    s=0
  #print(d,s,d-s*(10**(k-1))+s)
  else:
    A=f((d-s*(10**(k-1))+s)//10,k-2)
  if A=="Unko":
    return "Unko"
  A.appendleft(s)
  A.append(-s)
  return A
ans=0
for k in range(1,50):
  A=f(D,k)
  if A=="Unko":
    continue
  print(A)
  res=1
  for j in range((k+1)//2):
    if j==0:
      res*=9-abs(A[j])
    else:
      if A[j]==0:
        res*=10
      else:
        res*=9-abs(A[j]-1)
  ans+=res
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
D=int(input())
def f(d,k):
  if 0<=k<=1:
    if d!=0:
      return "Unko"
    if k==1:
      return deque([0])
    else:
      return deque([])
  s=10-(d%10)
  if s==10:
    A=f(d//10,k-2)
    s=0
  #print(d,s,d-s*(10**(k-1))+s)
  else:
    A=f((d-s*(10**(k-1))+s)//10,k-2)
  if A=="Unko":
    return "Unko"
  A.appendleft(s)
  A.append(-s)
  return A
ans=0
for k in range(1,20):
  A=f(D,k)
  if A=="Unko":
    continue
 # print(A)
  res=1
  for j in range((k+1)//2):
    if j==0:
      res*=9-abs(A[j])
    else:
      if A[j]==0:
        res*=10
      else:
        res*=9-abs(A[j]-1)
  ans+=res
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
D=int(input())
def f(d,k):
  if 0<=k<=1:
    if d!=0:
      return "Unko"
    if k==1:
      return deque([0])
    else:
      return deque([])
  s=10-(d%10)
  #print(d,s,d-s*(10**(k-1))+s)
  A=f((d-s*(10**(k-1))+s)//10,k-2)
  if A=="Unko":
    return "Unko"
  A.appendleft(s)
  A.append(-s)
  return A
ans=0
for k in range(1,20):
  A=f(D,k)
  if A=="Unko":
    continue
  #print(A)
  res=1
  for j in range((k+1)//2):
    if j==0:
      res*=9-abs(A[j])
    else:
      if A[j]==0:
        res*=10
      else:
        res*=9-abs(A[j]-1)
  ans+=res
print(ans)

Submission status: Wrong Answer

Solution code:
def plus_one(x):
	num = int(x)+1
	return "0"*(len(x)-len(str(num))) + str(num)

def f(x):
	#print(x)
	global ans, first
	if x == "":
		return
	elif len(x) == 1:
		if x == "0":
			ans *= 10
			return
		else:
			ans *= 0
			return
	else:
		if first:
			ans *= int(x[-1])-1
		else:
			ans *= int(x[-1])
		if int(x[0]) + int(x[-1]) == 10:
			first = False
			if len(x) == 2:
				ans *= 0
				return
			else:
				f(plus_one(x[1:-1]))
		elif int(x[0]) + int(x[-1]) == 9:
			first = False
			if len(x) == 2:
				return
			else:
				f(str(10**(len(x)-2) - 1 - int(x[1:-1])))
		else:
			ans *= 0
		return

d = input()
ans = 1
mul = 1
first = True
if d[-1] == "0":
	mul = 9
	d = d[:-1]
	while d[-1] == "0":
		mul *= 10
		d = d[:-1]
	first = False

if d[-1] == "9":
	second = first
	f(d)
	ans2 = ans
	ans = 1
	first = second
	f("0"+d)
	print((ans + ans2) * mul)
else:
	f(d)
	print(ans * mul)

Submission status: Wrong Answer

Solution code:
def f(x):
	#print(x)
	global ans, first
	if x == "":
		return
	elif len(x) == 1:
		if x == "0":
			ans *= 10
			return
		else:
			ans *= 0
			return
	else:
		if first:
			ans *= int(x[-1])-1
		else:
			ans *= int(x[-1])
		if int(x[0]) + int(x[-1]) == 10:
			first = False
			if len(x) == 2:
				ans *= 0
				return
			else:
				f(str(int(x[1:-1]) + 1))
		elif int(x[0]) + int(x[-1]) == 9:
			first = False
			if len(x) == 2:
				return
			else:
				f(str(10**(len(x)-2) - 1 - int(x[1:-1])))
		else:
			ans *= 0
		return

d = input()
ans = 1
mul = 1
first = True
if d[-1] == "0":
	mul = 9
	d = d[:-1]
	while d[-1] == "0":
		mul *= 10
		d = d[:-1]
	first = False

if d[-1] == "9":
	f(d)
	ans2 = ans
	ans = 1
	f("0"+d)
	print((ans + ans2) * mul)
else:
	f(d)
	print(ans * mul)

Submission status: Wrong Answer

Solution code:
def f(x):
	#print(x)
	global ans, first
	if x == "":
		return
	elif len(x) == 1:
		if x == "0":
			ans *= 10
			return
		else:
			ans *= 0
			return
	else:
		if first:
			ans *= int(x[-1])-1
		else:
			ans *= int(x[-1])
		if int(x[0]) + int(x[-1]) == 10:
			first = False
			if len(x) == 2:
				ans *= 0
				return
			else:
				f(str(int(x[1:-1]) + 1))
		elif int(x[0]) + int(x[-1]) == 9:
			first = False
			if len(x) == 2:
				return
			else:
				f(str(10**(len(x)-2) - 1 - int(x[1:-1])))
		else:
			ans *= 0
		return

d = input()
ans = 1
mul = 1
first = True
if d[-1] == "0":
	mul = 9
	d = d[:-1]
	while d[-1] == "0":
		mul *= 10
		d = d[:-1]

if d[-1] == "9":
	f(d)
	ans2 = ans
	ans = 1
	f("0"+d)
	print((ans + ans2) * mul)
else:
	f(d)
	print(ans * mul)

Submission status: Wrong Answer

Solution code:
def f(x):
	#print(x)
	global ans, first
	if x == "":
		return
	elif len(x) == 1:
		if x == "0":
			ans *= 10
			return
		else:
			ans *= 0
			return
	else:
		if first:
			ans *= int(x[-1])-1
		else:
			ans *= int(x[-1])
		if int(x[0]) + int(x[-1]) == 10:
			first = False
			if len(x) == 2:
				return
			else:
				f(str(int(x[1:-1]) + 1))
		elif int(x[0]) + int(x[-1]) == 9:
			first = False
			if len(x) == 2:
				return
			else:
				f(str(10**(len(x)-2) - 1 - int(x[1:-1])))
		else:
			ans *= 0
		return

d = input()
ans = 1
mul = 1
first = True
if d[-1] == "0":
	mul = 9
	d = d[:-1]
	while d[-1] == "0":
		mul *= 10
		d = d[:-1]

if d[-1] == "9":
	f(d)
	ans2 = ans
	ans = 1
	f("0"+d)
	print((ans + ans2) * mul)
else:
	f(d)
	print(ans * mul)

Submission status: Wrong Answer

Solution code:
def f(x):
	#print(x)
	global ans, first
	if x == "":
		return
	elif len(x) == 1:
		if x == "0":
			ans *= 10
			return
		else:
			ans *= 0
			return
	else:
		if first:
			ans *= int(x[-1])-1
		else:
			ans *= int(x[-1])
		if int(x[0]) + int(x[-1]) == 10:
			first = False
			if len(x) == 2:
				return
			else:
				f(str(int(x[1:-1]) + 1))
		elif int(x[0]) + int(x[-1]) == 9:
			first = False
			if len(x) == 2:
				return
			else:
				f(str(10**(len(x)-2) - 1 - int(x[1:-1])))
		else:
			ans *= 0
		return

d = input()
ans = 1
first = True
if d[-1] == "9":
	f(d)
	ans2 = ans
	ans = 1
	f("0"+d)
	print(ans + ans2)
elif d[-1] == "0":
	mul = 9
	d = d[:-1]
	while d[-1] == "0":
		mul *= 10
		d = d[:-1]
	f(d)
	print(ans * mul)
else:
	f(d)
	print(ans)

Submission status: Wrong Answer

Solution code:
D = int(input())

def table(i, k):
    if i == k:
        return list(range(9, -1, -1)) + [0]*9
    else:
        return list(range(10, 0, -1)) + list(range(1, 10))

def nine(i):
    return 10**i - 1

def rec(d, i, k):
    res = 0
    num  = table(i, k)
    if i == 1:
        for j in range(-9, 10):
            if 9*j == d:
                return num[j]
        return 0
    if i == 2:
        for j in range(-9, 10):
            if d == 99*j:
                return 10*num[j]
    if not -10*nine(i) <= d <= 10*nine(i):
        return 0
    for j in range(-9, 10):
        if d%10 == j*nine(i)%10:
            res += num[j] * rec((d-j*nine(i))//10, i-2, k)
    return res

l = 0
while D % 10 == 0:
    D//= 10
    l += 1

if l == 0:
    a = 1
else:
    a = 9*10**(l-1)

ans = 0
for i in range(1, 17):
    if not l:
        ans += rec(D, i, i)
    else:
        ans += rec(D, i, 100)
if ans % 9 != 0:
    ans = 0
print(a * ans)