The Rust code which calculates the currency are in O(n^2). It's possible to reduce it to O(n) by pre-processing the arrays.