Single Digit Representations of Natural Numbers Task

Write a program/function that when given a positive integer \$n\$ and a digit \$d\$ which is not 0 outputs a way to represent \$n\$ using only addition, subtraction, multiplication, exponentiation, division, concatenation, parenthesis and the digit \$d\$.

Examples

n =  6, d = 1  =&gt;  (1 + 1) * (1 + 1 + 1)
n =  6, d = 1  =&gt;  1 + 1 + 1 + 1 + 1 + 1
n = 10, d = 1  =&gt;  1 || 1 - 1
n = 12, d = 1  =&gt;  1 || (1 + 1)
n = 64, d = 2  =&gt;  2 ^ (2 + 2 + 2)
n =  1, d = 9  =&gt;  9 / 9


Note: In the examples || represents concatenation

Output Format


Concatenation must be explicit with a separate operator
Output can be a string, list of operations and numbers or a list of lists in place of brackets.
You may choose the precedence of the operators but it must be consistent for all outputs produced by your program/function
Output may be in polish, reverse polish or infix notation but it must be consistent for all outputs produced by your program/function.
You can use custom symbols for representing the digits and operations but the symbols used for representing the digits and operations should be distinct.


Scoring

This is code-challenge, Your score will be

100*B + S


Where B is the number of bytes in the program/function, and S is the sum of the number of times the digit \$d\$ appears in the representation of \$n\$ with the digit \$d\$ as returned by your program/function for all \$n \le 1000\$ and all \$d\$ from 1 to 9

Lowest score wins

Example: if your program is abcd and all representation of \$n\$ returned by your program has 5 occurrences of \$d\$ then its score will be (4 * 100) + (5 * 1000 * 9) = 45400

Rules


Your program/function should run deterministically, so that it always returns the same representation for a given \$n\$ and \$d\$ (and hence always gets the same score).
Your answer must include not only your submission, but also the code you used to calculate the S part of its score. This need not be written in the same language as your submission, and will not be counted towards its byte count. You are encouraged to make it readable.
Your answer must include the precedence of the operators needed to evaluate the outputs produced by your program/function
You must actually run your test program and calculate/verify your score before submitting your entry. If your submission runs too slowly for you to verify its score then it is not qualified to compete, even if you know what its score would be in principle.




Inspired by this video
Python 3, 210 bytes · 100 + 59045 digits = 80045



def f(n,d):
 m={d:d},
 while{n}-{*m[0]}:m={z:(p[x],o,q[y])for p,q in zip(m,m[::-1])for x in p for y in q for z,o in zip([x+y,x-y,x*y,y&lt;9and x**y,x%y&lt;1and x//y,int(f"{x}{y}")],"+-*^/|")if z&gt;0},*m
 return m[0][n]


Try it online!

Scoring

Scoring goes much faster using this modified version that solves 1 through 1000 all at once:

def f_gen(d):
 m={d:d},
 while 1:yield from m[0].items();m={z:(p[x],o,q[y])for p,q in zip(m,m[::-1])for x in p for y in q for z,o in zip([x+y,x-y,x*y,y&lt;9and x**y,x%y&lt;1and x//y,int(f"{x}{y}")],"+-*^/|")if z&gt;0},*m

def size(expr):
    return 1 if isinstance(expr, int) else size(expr[0]) + size(expr[2])

score = 0
for d in range(1, 10):
    s = set(range(1, 1001))
    for n, expr in f_gen(d):
        if n in s:
            s -= {n}
            score += size(expr)
            print(n, expr)
            if not s:
                break
print(score)