You will be given three integers a, b, m. Print (ab) mod m. There will be 30 test cases at most in a…
Click here to read the complete problem statement.
If you need help solving this problem, mention your approach and ask specific questions. Please avoid sharing your code and asking the Community to figure out “what’s wrong”.
@hjr265 the testcases are problematic. I tried copy-pasting Submission 1070108 code and it gave me RE, even though someone got AC in that submission previously.
This does not explain why the submission id i gave got an AC though, when I am getting RE. Also, how could there be a integer with 50001 digits!! It does not look possible!!!
Re: Actually I also learnt this today. It seems to covert stuff from map to a list and stores it into a variable.
Ok got it, I forgot that it is a bignum problem while using python. But anyways, my accepted solution does not do anything to fix the error that I can see here. While trying to solve it, I was getting random RE’s.
Also, can you check why my copy pasted submission failed.
Original Sub ID: 1070108
My Sub ID: 1448252
My submission was accepted under Python 3.7, but the exact same code now gets a Runtime Error on newer Python versions. Because of breaking changes made by Python after version released after September, 2022.
Problem
Python introduced a security patch that limits integer-to-string conversion to 4300 digits by default. Since this problem allows a and b to have up to 10^5 digits, int(input()) on those values crashes with a ValueError.
The only in-code fix is to add manually set the max digit by:
import sys
sys.set_int_max_str_digits(0) # removes the limit
at the top, which disables the limit. But this makes the code longer, and therefore makes it impossible for others to beat the shortest code. (Which seems unfair because even the current shortest code won’t get ACCEPTED now)
Solution
Set the environment variable from the judge side:
Setting PYTHONINTMAXSTRDIGITS=0 in the Python execution environment. This disables the limit globally, and is the officially recommended approach for environments that need to handle large integers.
It’s not a necessity, but having this option would let me and others continue our code golfing.
Apart from this, there are lots of submissions that were previously done using older versions of languages which are not currently available in Toph. So, beating those in code golf becomes almost impossible.
Also, for the past couple of days toph’s submissions are hidden. So I couldn’t see @touhidurrr 's approach on how he did it afterwards. But he used Pypy, which had python 3.6 (which did not have that integer limit).
What a crazy way for Python to break backward compatibility!
Thank you for sharing the case in detail. The solution you suggested is a good option. I will look into this.
One trouble for Toph is communicating these small non-standard behavior. Like Python out of the box would behave one way for everyone, but then on Toph this would be something that only someone who cares to read some obscure help page would know.
Python actually didn’t want to break the backward compatibility. But it was a fix to a DoS vulnerability. It was assigned a 7.5 severity rating.
Issue
Conversion between base-10int to str (and vice-versa) has O(n^2) time complexity.
Someone could sneak a little bit of code that would hang the entire server. My rookie example:
someStringNum = "19"
# ... more code
# and later,
otherNum = int(someStringNum*10**6) # it'll hang the server for couple of seconds
# One extra "*" might go unnoticed in many large codebases
In malicious code, people will hide it more neatly. So, python added the limit of 4300 digit conversion between str to int and vice-versa. But it does not affect conversion from one number system to another, like hex, oct etc. Those have O(n) complexity.
I knew about this “limit” for quite a while, but didn’t know the details. Dig up the information after facing issue with this problem in toph.