### TomaKapec's blog

By TomaKapec, history, 9 months ago,

So I found fast I/O for Python and I used it before and it worked and now it doesn't. I don't know why, I tried everything! I use it for this task https://codeforces.com/contest/1850/problem/G, and here is my code. If anyone can explain why that would be great. (To clarify the code may be optimal, or maybe not but the question isn't about the task itself but rather about fast input)

import io, os
#so this here should work but doesn't
t = int(input())

def solve(n, points):
d_plus, d_minus, red, stupac = {}, {}, {}, {}
r=0

for i in points:
x, y = i
a, b, c, d = red.get(x, 0), stupac.get(y, 0), d_plus.get(x+y, 0), d_minus.get(x-y, 0)
r+=(a+b+c+d)*2; red[x], stupac[y], d_plus[x+y], d_minus[x-y] = a+1, b+1, c+1, d+1;

return r

for i in range(t):
n = int(input())
points = [list(map(int, (input().decode()).split())) for i in range(n)]
print(solve(n, points))

• 0

 » 9 months ago, # |   0 It is getting TL with both python and Pypy, I recon os stdin,stdout are the fastest
•  » » 9 months ago, # ^ |   0 No, it doesn't matter if it gets TLE or not, but when i use fast input it says compilation error!
 » 9 months ago, # |   +10 Dictionary in python is also very common issue.
 » 9 months ago, # |   0 Auto comment: topic has been updated by TomaKapec (previous revision, new revision, compare).
 » 2 months ago, # |   0 jebiga kapec valjda si rijesio ovo