Hi everyone!
It's the round you've been waiting for... Codeforces Round #420 (Div 2). It will take place tomorrow, 25 June 2017, at 17:35 MSK. As always, Div. 1 participants are encouraged to join out of competition. The round will be rated for Div. 2 participants and will have 5 problems to be completed in 2 hours.
I wouldn't be able to create this round without the help of many people: KAN for lots of help in preparing the contest, 300iq and Alladdin for testing and providing feedback, and as always MikeMirzayanov for the Codeforces and Polygon platforms.
This will be my second contest, and I'm glad to get such a nice round number :). Hopefully, you'll find the problems interesting. Of course, you should read all the problems so you can solve problems you find easy or interesting.
To excite some and disappoint others, the round theme will have nothing to do with the number 420. Instead, continuing the anime themes of the last two rounds, round #420 will feature mad scientist Rintaro Okabe (don't read spoilers!) from the anime Steins;Gate. Statements will not contain any spoilers, but you might find the problems slightly more amusing if you've watched the series. Of course, you should watch the series if you havent :)!
As per Codeforces tradition, scoring distribution will be announced shortly before the contest. Good luck, and I hope you can help Okabe with all 5 tasks :D!
Scoring is standard: 500-1000-1500-2000-2500!
Update: Sorry for delays.
Update: Editorial is here: http://codeforces.net/blog/entry/52895
I really apologize for the issues during the round. It's upset a lot of people and I should have taken more care. Hopefully you won't hold this against Okabe or Steins;Gate anime :P
Here are the contest winners! Congratulations!
Div. 1
Div. 2
Thanks for participation everyone! Hope to write more problems in the future (without bugs)!
"EID MOBARAK" in advance to every CODEFORCES user.
Last 2 codeforces rounds was anime-themed and it will be third lol.
It's the work of the Organization !!!
Nope, it must be the work of an enemy stand.
Let's hope JoJo for the next round. :P
Like "As per codeforces tradition, the contest will be anime-themed round". (?)
In addition, last codeforces round (#419) is anime-themed even the editorial, and dalex said a legend comments:
Please hide this anime bullshit. Codeforces is not an anime site. I don't want to see these pictures when I read an editorial.
But I think anime-themed is fun, so in my opinion, anime-themed is one of fun thing in contest.
I think it is very true that anime themed is fun. Just curious, why this comment is highly downvoted (I can't figure out the reason)? Is anime thing is not fun? Or is it to be duty to codeforces problemsetting?
I think porn-themed is fun, so in my opinion, porn-themed is one of fun thing in contest.
Probably in the future, when downvoters become adults, they'll understand what content is appropriate for sites and what is not.
If you want anime pictures, go to /a on your favourite imageboard and be happy.
It's the theme for the round, I never said anything about pictures...
I am not a big fan of anime, but I have no problem with that. It's nice to have some common theme for problems. Why are you such a drag here?
I only complain about pictures, like in the previous round. Today statements are good.
So excited to maybe raise in level :D
Never mind :(
For the people who don't know what send_nodes was talking about when he mentioned number 420 number 420 is the code for smoking marijuana...420blazeit baby.
PS: I don't support, advise or otherwise suggest that you should smoke marijuana I'm just explaining what 420 and 420blazeit mean.
In India a betrayer is called a 420 guy
Yoo niggas, Codeforces is "Still" the best but this round will rise CF to "The Next Episode"...
Go 420 and have fun!!
And my rating will "Drop Like It's Hot"...
Steins' gate! Loved it! :D
m
mayushii desu!
420 BLAZE IT
EL... PSY... CONGROO...
I'm sad that it won't be rated for div 1... i'm TOO HIGH for the contest!
This contest was not rated even in Div.2 ..., so sad!
Funny handle send_nodes
Send_nudes
Hacking... to the gate? There's a joke in there somewhere...
Do i need an IBN 5100 ?
if (Hacks) { will watch o_o the series }
Not a single 420 joke or reference? I'm a bit disappointed.
I'm impressed about the number "420".
420 is 2*2*3*5*7=420, so the number of divisors is 24. In addition, there is only one number which is lower than 420 and the number of divisors is more than or equal to 24. (Only one number is 360.)
So the contest might be one of the period, I think. Good luck! :)
if she didn't send nodes , the round will be hard ?
I think yes. (It is a joke)
If she sent nodes, the problem's constraints would get easier!
Send_edges
If she does, I will be hard.
Please don't insert any image in the first question.Last time my page loaded after about 60 seconds. Everyone simultaneously opens first question and due to higher server load, page is rendered slowly. Actually, it happened with many.You can watch the screencast of reds.I like those images, but please don't add any in the first question.
PS: Here's the link CF419 screen cast by eddy1021 — YouTube
Or maybe load the first problem before the contest, and show them exactly at the start?
Year 2017
Thank god, you are registered, otherwise you would be in 2018...
I can guess from your name that these anime in statements would be hentai
he watches boku no pico
Aw man ... no 420 themed puns ?
In India, #420 means cheating and fraud as defined by a laymen as well as defined in the Section 420 of Indian Penal Code.....hopefully this round hasn't got anything to do with that...Lol :P
What the handle name :> ohhhhhh sorry, I read it wrong...
My favourite anime!! :D
It seems to be intersecting with Google Kickstart.
I hope we have one Game of Thrones themed contest in July.
yeah , i hope so
King in the nor'f!
Yeah ! And you will be asked in the task to calculate DSU between Cersie and Sir Jamie :D
Lol, it won't be DSU, it will be SCC because they both belong to House Lannister :)
TUTURU!!!
i wish all of you get a great rate and have fun :D
Expected a weed themed contest, got a Steins;Gate one. Not disappointed :D
I will just wait for the tutorial and travel back in time using my Phone Microwave (MAD SCIENTIST LAUGH)..
If I register the contest and I can't have the time to do the contest,will I lose rate?
If you don't submit anything, then your rating is not affected.
No, Your rating will not be affected unless you made at least one submission. You can also unregister using the red 'x' icon beside your handle in the registrants' page.
.
CF severs, please, be OK during the contest
I hope girls were more like the Codeforces servers so they'd go down on me more often.
Then it is down now...:(
Down like my rating
EDIT: nvm, round is unrated
The dankest Codeforces Round announcement ever. :D
I think my name should be "send_rating" :) :D
What is score distribution?
Wait for it ...:)
C will be logical question.
I hope, no delays...
From Morocco, i wish you Aid Mubarak Said, hope we enjoy the contest good luck :D
Eid Mobarok to Codeforces. Wishing all the best from Bangladesh :-)
just 3 minutes left, score distribution?
send_nodes, nice nikname though
Auto comment: topic has been updated by send_nodes (previous revision, new revision, compare).
Is it just me or CF is having some server issues? CF isn't loading properly!
Not only the site isn't loading properly, but it was for a few minutes set that the contest will be delayed with 15 minutes. When the page finally got refreshed, I was disappointed to find out that the contest had already started....
After submitting 15 odd times, my A went into judging and now nothing is visible.
yes, really disappointing!
This round really seems to be simulates Steins; Gate.
Who sent a D-mail?
Shroedinger `s round
That's it! I'm not participating today ... I can't even get to submit successfully...
Round should be unrated
Plz, make it unrated! CF is lagging all the time!
Will it be rated?
It has to be unrated. My A which I submitted after 4 minutes went into judging at 17th minute and I had already left the will to do the contest because I thought it will get unrated and so did many other people.
There seems to be a bug: if you press the Submit button and the contest announcement pops up before the problem is actually submitted, the problem isn't actually submitted.
Is the round still rated?
No I guess!
Its not have been officially announced though
Any Extra Registration today?
Good afternoon, I have a problem, I think that not only me, that codeforces began to issue error 502 (504). And so on throughout the tour. For these reasons, I ask you to make a competition without a rating change.
If the contest has been made unrated , Please make an official announcement
Give me answer Contest authors. Send your some questions.
Please help!! Why is output of D's last test case 3?
I already asked problem writers, they haven't responded
Wondering the same thing :/
They said we should note some sample change but I haven't seen any changes.
The last test case was output 4 previously!! They changed correct to incorrect :|
What? I thought the answer is -1 ... Can you help me get why it is 4 ?
When on 1,1, we lit the first row, then we go to cell 1,2.
From 1,2 we go to 2,2 which is lit so we can spend a coin at 2,2 and lit second row and so on.
"To change the row or column that is temporarily lit, he must stand at a cell that is lit initially" Either im an idiot and im not seeing a correct path or there really is no correct path.
Just like the note says, when you step at (4,4) and now if you set the last row light you can go to (5,5) just in one step
But I don't know why the ans changes to 3
I know that! QAQ We can move from (1,1) to (3,3) if we light up the second row
Does that mean correct answer to last test case is still 4 ?
Ohhh... it says he can light up any column and row, not just those which he is standing on...
You can move from cell (1, 1) to cell (3, 3) by temporarily lighting row 2 or column 2
Shoot! I thought we have to stand on the row we temp. lit, given that we are standing on a lit cell.
420? CF BLAZES AWAY
Please someone explain Sample 4 of problem D how it takes only 3 steps previous answer was 4 which seemed correct to me.
same problem confused b/t tc 1 and 4 :(
You can move from cell (1, 1) to cell (3, 3) by temporarily lighting row 2 or column 2
When you are at (1,1) you have to light either row 1 or column 1, right? Then when you come to (2,2) you have to do the same thing. I can't see how you can transport from (1,1) to (3,3) with only one lighting.
I assumed the same thing but turns out we are wrong.. You can light any row and any column if you are standing on an initially lit cell :/
First time in my lifetime i got "Pretests passed" for E during contest! Pl. dont make this round unrated
I guess it will be and it must be problem D still not clear
Yeah they made it unrated :(
I solved E for the first time too. You are sorry too often CF. Almost every second contest. Does anybody knows better contest platform?
Lol ... CF is not that bad. Frankly, its the best platform. All contests being issue-free is not practically possible.
Only a very few contests face major issues and get unrated like this. I happened to me twice in > 60 contests.
but you only joined 59 contests :P
Two were unrated, so that makes 61 contests that were supposed to be rated. :-)
FIrst time I get "Pretests passed" on the first four problems, but still green at the end of the day...
I guess I should not take the ratings too seriously
Okay, that is my first time destroying the contest, sorry folks :/
Codeforces just announced that the round will be unrated due to problems in question D :( . I really worked hard in trying to solve A,B and C.
Why unrated? I do not aware of the changes of D. And my original thought can pass the tests.
I think the problem description is quite clear :(
Yes, the statement was clear enough to notice the issues with the samples. And anyways the round could be rated for problems: A, B, C & E.
problems in codeforces , delay in the round , problems in D , unrated round , all of this because she didn't send nodes ?
or may be because she send n"u"des indeed :P
Oh sorry, I can not understand. I am quite busy watching deathly Hallows right now. :P
Exception in thread "main" java.lang.Error: Unresolved compilation problems: Type mismatch: cannot convert from nudes to nodes
I got 50 points penalty on resubmitting the same solution for A. Did anyone else have the same problem?
I do in problem C.
Let's discuss!
Is E matrix expo?
Contest isn't over yet.
What contest ;)
but unrated :(
clearly
D was harder. Why can't problem writers guess difficulty a little better, as it's a matter of 500 points?
Maybe the nodes were not sent! Jk :P
So sad as both rounds of send_nodes are unrated :(
If i am not mistaken, the authors last round was also made unrated due to some issue. @send_nodes having two contests of yours having issues is a bit frustrating. Pl. be careful next time.
First contest was unrated because of server issues afaik.
it must be unrated.
Codeforces has declared that it will be unrated due to problems in question D and server lagging.
SERN is behind this?!
Happened to me first time that a rated round became unrated . It hurts .
it doesn't hurt if predictor shows -17
But it does when it shows +115...
It does when it shows +70
I liked D, almost ready to press submit! Then I realized I was solving a different problem. If we have to stand on the row/col we temp. lit, it's DP. Now I have to think from scratch :/
Unrated due to D? -_-
or because of server. anyway you could have just removed D...
Maybe from next time CF should have "back up problems". It's kind of depressing when you hear after "2 hours" that a rated contest has become unrated and all those time "when you kept hitting the refresh button and hoping cf will load" become futile. Just sad :(
How exactly do you envision removing problems or having "back up problems" as saving the contest?
I don't know if it is even a good idea but suppose you are a setter and in some moment of the contest you found that your solution was wrong and if you already made another "D category" problem, you can replace it and even extend the contest time. Yes, there's another option that you can remove that problem (which happened in the past on CF as far as i know) but i dont think that will be fair to judge someone's ability. If a contest only had "A Level" difficulty or "E level" difficulty problem, then it would be hard to determine who is really talented.
That's my opinion. I don't know if this thing is really possible or not.
Have you any idea, I've almost completely stopped opening div2 A/B now during contest -_-. Now imagine if C,D,E get replaced. There are others like me.
dont you get pop out notifications when a change has been made during a contest? yeah you have to keep your browser (where you kept the CF tab open) open. So during any modification, you will know. And time should be extended if that happens.
But isn't it better than an unrated contest? Some of us cancel our events just so we can do a rated contest. we can do an unrated contest anytime. Today i canceled my program (and got a lot of scolding -_-) for CF
Imagine I've spent 1 hour on a problem that gets cancelled! Is it fair to me?
Imagine my 2 hours and 40 seconds -_- .
But yes it's not fair for you. It's not fair for me -_-. But does it take so much time to realize that their solution was wrong? i mean isnt there a team? a person can make a mistake. but a team made a mistake? :| that's kind of sad. anyway things like these happen. Life. I remember when i was doing well on a contest and when i just solved C i found out the contest was unrated due to server :|
...and the funny part was my ratings decreased after those two contests. but all of my solutions were correct in that "canceled" contest.... Life
I wasted almost an hour trying to understand the sample before any answer from the contest setter/cf. And then when I gave up I opened problem E and thought instantly "why is this easy matrix problem E while that other one is D?". I'm sure that there are people that did the same as me in div2 and if that's the case it should be unrated because the difference between these people and others that got higher placings are that some skipped problem D and others didn't. The whole problem was because of a wrong sample case.
Actually, it took me maybe 30-60 seconds to know E's approach. D had some cases to handle, so even if D was all correct, E was still easier than D. I think writers should put a little more effort into deciding problem difficulty.
By the time people complained about D, many other contestants had already spent a lot of time trying to solve it. Thats why things are not that simple. It really should be made unrated, as everyone expects a WA to be a WA and so on.
i get it though i didnt get time to even think about D because of loading problem. but still as i said it feels really awful when at the end of the contest you see it's unrated. maybe there could be other ways.
I was really happy that I got 3432 point in pretest and pretty sure would get more than half hundred rating. Then suddenly a window popped out and punched me in the face.
round unrated
Sponsored by Dr. Pepper -- Damn I am glad you didn't missed the meme opportunity.
Making this round unrated made us totally frustrated :(
How do you solve B?
sum of ( sum of first x natural numbers * y, sum of first y natural numbers * x ) for each value of x, such that rectangle is under the line
Notice the line-intercept notation of a line. y/(m*b)+x/b=1. min(m*b,b) = b, which makes linearly checking x feasible.
Sum of
x+y
for all points in the rectangle determined byx
andy
is(1 + x) (1 + y) (x + y)/2
. It is enough to test only points which have integer coordinates, as only lattice points have trees. So, iteratey
from0
tob
, determinex
and use the formula. There are less efficient solutions, and also there may be a O(1) solution, but this works just fine.I can't get the formula to calculate bananas depending on x and y. Can u explain
Sum of all
x
:x * (x+1)/2
Sum of all
y
:y * (y+1)/2
How many times each value of
x
is summed:y+1
How many times each value of
y
is summed:x+1
So:
x*(x+1)/2*(y+1) + y*(y+1)/2*(x+1)
Which is simplified to
(1+x)(1+y)(x+y)/2
at first i tried Ternary Search, but it was false. Then i realized that i just need to use brute-force :v
I used ternary search. Why won't it work?
oh, due to my bad skill :D
i mean the Ternary Search was right, but my code was wrong.
To maximize bananas, you always want the bottom left point of the rectangle to be at point (0, 0). All that's left to do is find the upper right point of the rectangle.
the line intercepts the Y-axis in the value b, so you have at most 10000 possible y values for that point. Iterate through all those 10000 y values and find the maximum value for x at that y by solving y = -x/m + b for x and rounding down the solution to an integer value.
You also need a count_bananas function that for given x and y of the upper right point of the rectangle calculates the number of bananas in the rectangle. the formula for this is:
(sum from 0 to x) * (y + 1) + (sum from 0 to y) * (x + 1).
So you just iterate every possible y value, find the corresponding x value, and calculate the number of bananas for that pair, and print the max bananas at the end. At least this is how I solved it, there might be a better O(1) solution using math.
I think E was a quite straightforward DP, except combinatorics part. I didn't manage to get it. How did you solve E?
Is possible to calculate dp faster with matrix exponentiation
It was matrix exponentiation. If you know the number of ways to get to (a[i], 0), (a[i], 1), ... (a[i], c[i]), then you can determine the number of ways to get to (b[i], 0), (b[i], 1), (b[i], 2), ... (b[i], c[i]). The transition matrix is 16x16.
Say you have x_i ways to be at position (a,i). Then you have x_{j-1} + x_j + x_{j+1} ways to be at (a+1,j), where each indexed x_? is 0 if it goes out of bounds. This is a linear transformation, so for each segment you can make a (c+1)*(c+1) matrix and compute the transitions along it with fast matrix multiplication, then resize cutting off or padding zeroes when moving to the next segment.
why this shit happens even if problems are tested by others???
Maybe author commited a mistake while writing the problem statement, but he described the other problem when telling to others.
In that case answers should not match!!
good contest
You're supposed to post in english under the english part of codeforces. I suggest you edit it before the downvote flood. lol
Guys, it was just a big misunderstanding. Problemsetter didn't know that the nodes would have a "D" in them.
When you're enjoying the contest And then you see this..
How to solve problem E? Thanks.
A naive idea would be trying to dp from one end to the other, you could observe that the state transitions are actually rather simple, try to find a way to exploit it. :)
Hint:
In problem D the first and fourth samples were wrong they should have equaled to 1 and 2 instead of 2 and 3
edit : as walnutwaldo20 pointed out i misunderstood the problem
No they were 2 and 3. You can't get off onto (N-1, M-1) unless it is lit.
int the first you can light row 3 then go like this : 1 1 -> 2 1 — > 3 1 -> 3 2 -> 3 3 -> 3 4 -> 4 4 and pay one and in the second you light collumn 2 and then after going to 3 3 light collumn 4 and go to 5 5 unless i have understood something wrong
But you can't do 3 4 -> 4 4 because 4 4 is not lit up.
oh, sorry i thought you could, you are right!
It seems to me that some people started competing at the 00:00 mark, while others started at the 15 minute mark.
PS: Was it by any chance a synchronization problem, due to the fact that someone tried to delay the contest too close to the beginning, or something else?
This is so true! The problems didn't load for me until after a few minutes of the contest.
Lag was so bad problem A loaded as a PDF for me.
Same here! Initially. I was worried whether I was the only one facing this weird problem.
Nice problems, so sad it's unrated tho :(
Don't worry, send_nodes will send a D-mail about problem D, and the round will be rated (in an alternate world)
If the system can make it unrated just for some people who are effected by the problem D?
http://codeforces.net/contest/821/submission/28036426
Cheaters in an unrated contest.....
why is this cheating?
edit: ok, I think obfuscated code is not allowed, but he's the only one that will loose points because of that (in case of a possible hack that didn't happen)
It's obvious it's cheating. Who writes defines like that? Must have copied someone else and obfuscated the code to bypass the similarity check.
Ah, I see, but I think codeforces cheating detector will find this.
Taken from Codeforces Contest Rules
It is forbidden to obfuscate the solution code as well as create obstacles for its reading and understanding. That is, it is forbidden to use any special techniques aimed at making the code difficult to read and understand the principle of its work.
Do they have a program that can program? What is going on?
A couple rounds back someone else did the same thing, it is done by a program which obfuscates the code so that the code that was copied off someone else won't get detected by the checker.
that's actually smart
His code works just fine, he just used a
#define
for each original line. The compiler will replace the defines with the correct code before compiling.farmersrice we wrote a code to reverse the code and used pretty print and got the real code! check it out! ==> https://pastebin.com/1BQAaw73 hope the codeforces guys do the same with every such code so these cheaters can be caught(if he is a cheater:p XD)!!
How is problem D solved?
I tried just doing a standard shortest path algorithm where you can jump to any tile that is less than or equal to two rows or columns away. It didn't work however, since I got RTE on pretest 14.
your first round Codeforces Round 370 (Div. 2) ended up unrated too, feel sorry for you man :(
relevant profile pic
I did the same and got pretests passed, but now that rejudged it, I got WA on test 4, but the idea woks
Making it unrated made me feel covfefe.
Do it rated :c
Too much math for one round
send_nodes be like : I wont make a contest from next time because my every contest is unrated.
Today was my sister's birthday. She came to my country after 1 year. I was supposed to be at her birthday party. But I chose to sacrifice the birthday party to attend this contest. I was sad first, then I thought I will try to make myself happy by solving problems. The first 10 minutes of the contest, I cannot load the website. Then I tried to solve some problems. I was able to pass pretests of three problems. I was very happy after that. At the last 10 minutes of the contest, there was a notification saying the contest will be unrated. Very sad life for me.
I hope from the next contests, the quality of the problemset will be better and there will be less bugs in the websites as well as in problems.
You seriously chose participating in a CF contest over attending your sister's birthday party?
Are you seriously surprised?
I don't know who is the unlucky one: me, or send_nodes. xD
I perform good in his rounds but unlucky they end up unrated.
Actually it was good round if it is assumed as an educational round. :D
Predictor said high rating change if system tests aren't mean. This is gonna be a great nigh--
screams
The problem statement is quite clear. No ambiguity there. Even if the main solution is incorrect, testers' solutions should somehow end up getting different answers. Why did this end up happening anyway?
I love the problems though.
whats test case 8 for Div2B? this simple solution http://ideone.com/sdPvQD fails test 8 can someone tell why? the check function simply returns true if the point (x, y) lies below or on the given line.
In my solution (that passed pretests) answer for test 1000 10000 is equal to 74133360011484445,meanwhile you print 55049995000.
As Mucosolvan has said, you produce the wrong answer because your search space is too small. You are checking all points within 0 <= x <= 1000, 0 <= y <= 10^4. However, for a sample test case like 1000 10000, the answer exists at (6666000, 3334)
Does it really matter, since the contest is unrated?
Yes, i really want to submit in practice mode.
If round was rated, your rating would be like in this table
Good thing I found a mistake in D, otherwise -18 :X
-18 too lol.
Very cool feature! Is there a way to see this prediction table of rating change in every contest?
Thanks) You could read more about this tool in the my blog or just install extension for your browser:
I could have got 6368 points (if I don't FST and) if there wasn't such a serious bug in D, and I ranked 1st before the announcement... I admire the courage to submit and ignore the 4th sample test.
Anyway, it's originally unrated for me (since I'm in div 1). I'm really happy to solve problems featuring Okabe from my favourite anime Steins;Gate, and I did find the problems slightly more amusing:D
Auto comment: topic has been updated by send_nodes (previous revision, new revision, compare).
*_*
Can I see the final standing before dying ? Why so much delay in everything today ? First the contest then delay in clarification and now system testing too ! GREAT !
At least editorial came fast :D
:D
First time end up solving 3 problems and now the round is unrated .
aka.Foda hacked my C, but after system test......his solution was wrong also!!! LOL!!!! :D
you will be surprised my solution is wrong at the test I hacked you by :3
Really? :o ha ha ha!!!
have they posted the editorials ? i cant find them if anyone can help ?
It is stated in the post: http://codeforces.net/blog/entry/52895
..
Are they just say contest unrated and that's all? They still didn't give any motivation.
Auto comment: topic has been updated by send_nodes (previous revision, new revision, compare).
This D is just a masterpiece.
Square samples (this issue has been raised million times, but who cares, lmao), profound testing leading to total misunderstanding in sample test #4 and ML at test 28 not included in pretests as a cherry on top. Incredible!
Why can't I take my upvote back :/
There were 2 contests from send_nodes and both were unrated. Unlucky :(
Can somebody explain test 48 in D? My code returns -1, while the answer is 20.
Is it possible to move directly from one position to another if both rows and columns differ by more than 1?
Yes. 1 1 and 3 3 you can light the column 2 and go through it.
Thanks — I haven't thought about that...
Nevermind
Do you have any strategy for finding errors like this? lol I have been seeing a lot of these recently (in my own solutions)
actually i just mistyped a as b and didn't notice it before posting , as for finding the error , i printed out the points in sorted order and saw that theres an error in sort.
2010 the first contests codeforces.
The ratings are still not updated..the contest was rated toh
Due to bugs it was made unrated!
What's wrong with my program? Why it's not working? (Problem B)
I figured out.
The problem was casting types.
limits, change some types to ll instead of int