(use srfi-1) (define N (read)) (define A (list-tabulate N (^_ (read)))) (define (memorize f) (let ([cache (make-hash-table equal-comparator)]) (lambda x (or (hash-table-get cache x #f) (let ([result (apply f x)]) (hash-table-put! cache x result) result))))) (let loop ([A A] [ht (hash-table-r7 'eqv? 0 1)]) (cond [(null? A) (print (hash-table-fold ht (^(k v s) (remainder (+ s (* k v)) 998244353)) 0))] [else (let ([nxt (make-hash-table)]) (hash-table-for-each ht (^(k v) (let ([a (remainder (+ k (car A)) 998244353)] [b (remainder (abs (- k (car A))) 998244353)]) (hash-table-put! nxt a (+ v (hash-table-get nxt a 0))) (hash-table-put! nxt b (+ v (hash-table-get nxt b 0)))))) (loop (cdr A) nxt))]))