Buggy python submission (verdict: Time Limit Exceeded):
import sys
import bisect
from operator import itemgetter


def _ia(): return map(int, sys.stdin.readline().strip().split())


def main():
    _ = sys.stdin.readline()
    a = list(_ia())
    l = {}
    r = {}
    for i, ai in enumerate(a):
        li = ai + i + 1
        ri = i + 1 - ai
        l[li] = l.get(li, 0) + 1
        r[ri] = r.get(ri, 0) + 1
    ra = list(r.keys())
    ra.sort()
    n = len(ra)

    li = 0
    ans = 0
    for kl, vl in sorted(l.items(), key=itemgetter(0)):
        li += bisect.bisect_left(ra[li:], kl)
        if li >= n:
            break
        kr = ra[li]
        if kl == kr:
            ans += vl * r[kr]
    return ans


if __name__ == "__main__":
    print(main())


Fixed submission:
import sys
from collections import Counter


def _ia(): return map(int, sys.stdin.readline().strip().split())


def main():
    _ = sys.stdin.readline()
    a = list(_ia())
    l = Counter(ai+i+1 for i, ai in enumerate(a))
    r = Counter(i+1-ai for i, ai in enumerate(a))
    return sum(v*r.get(k, 0) for k, v in l.items())


if __name__ == "__main__":
    print(main())

Buggy python submission (verdict: Time Limit Exceeded):
#!/bin/bash
''':'
docker run --rm -it -v $(cd $(dirname $0) && pwd):/vo:ro pypy:3-2.4.0 \
   /bin/bash -c "pypy3 /vo/$(basename $0) < /vo/input.txt"
exit $?
'''
import sys
import bisect
from operator import itemgetter


def _i(): return int(sys.stdin.readline().strip())


def _ia(): return map(int, sys.stdin.readline().strip().split())


def main():
    n = _i()
    a = list(_ia())
    l = {}
    for i, ai in enumerate(a):
        aip = ai + i + 1
        l[aip] = l.get(aip, 0) + 1

    r = list(i+1-ai for i, ai in enumerate(a))
    r.sort()
    li = 0
    ans = 0
    for k in sorted(l.keys()):
        r = r[li:]
        li = bisect.bisect_right(r, k)
        ans += l[k] * (li - bisect.bisect_left(r[:li], k))
        if li >= n:
            break
    return ans


if __name__ == "__main__":
    print(main())


Fixed submission:
import sys
from collections import Counter


def _ia(): return map(int, sys.stdin.readline().strip().split())


def main():
    _ = sys.stdin.readline()
    a = list(_ia())
    l = Counter(ai+i+1 for i, ai in enumerate(a))
    r = Counter(i+1-ai for i, ai in enumerate(a))
    return sum(v*r.get(k, 0) for k, v in l.items())


if __name__ == "__main__":
    print(main())

Buggy python submission (verdict: Time Limit Exceeded):
import sys
import bisect
from operator import itemgetter


def _i(): return int(sys.stdin.readline().strip())


def _ia(): return map(int, sys.stdin.readline().strip().split())


def main():
    n = _i()
    a = list(_ia())
    l = {}
    for i, ai in enumerate(a):
        aip = ai + i + 1
        l[aip] = l.get(aip, 0) + 1

    r = list(i+1-ai for i, ai in enumerate(a))
    r.sort()
    li = 0
    ans = 0
    for k, v in sorted(l.items(), key=itemgetter(0)):
        r = r[li:]
        li = bisect.bisect_right(r, k)
        ans += v * (li - bisect.bisect_left(r[:li], k))
        if li >= n:
            break
    return ans


if __name__ == "__main__":
    print(main())


Fixed submission:
import sys
from collections import Counter


def _ia(): return map(int, sys.stdin.readline().strip().split())


def main():
    _ = sys.stdin.readline()
    a = list(_ia())
    l = Counter(ai+i+1 for i, ai in enumerate(a))
    r = Counter(i+1-ai for i, ai in enumerate(a))
    return sum(v*r.get(k, 0) for k, v in l.items())


if __name__ == "__main__":
    print(main())

Buggy python submission (verdict: Time Limit Exceeded):
#!/bin/bash
''':'
docker run --rm -it -v $(cd $(dirname $0) && pwd):/vo:ro pypy:3-2.4.0 \
   /bin/bash -c "pypy3 /vo/$(basename $0) < /vo/input.txt"
exit $?
'''
import sys
import bisect
from operator import itemgetter


def _i(): return int(sys.stdin.readline().strip())


def _ia(): return map(int, sys.stdin.readline().strip().split())


def main():
    n = _i()
    a = tuple(_ia())
    l = {}
    for i, ai in enumerate(a):
        aip = ai + i + 1
        l[aip] = l.get(aip, 0) + 1
    r = tuple(sorted(i+1-ai for i, ai in enumerate(a)))
    li = 0
    ans = 0
    for k, v in sorted(l.items(), key=itemgetter(0)):
        r = r[li:]
        li = bisect.bisect_right(r, k)
        ans += v * (li - bisect.bisect_left(r[:li], k))
        if li >= n:
            break
    return ans


if __name__ == "__main__":
    print(main())


Fixed submission:
import sys
from collections import Counter


def _ia(): return map(int, sys.stdin.readline().strip().split())


def main():
    _ = sys.stdin.readline()
    a = list(_ia())
    l = Counter(ai+i+1 for i, ai in enumerate(a))
    r = Counter(i+1-ai for i, ai in enumerate(a))
    return sum(v*r.get(k, 0) for k, v in l.items())


if __name__ == "__main__":
    print(main())

Buggy python submission (verdict: Time Limit Exceeded):
#!/bin/bash
''':'
docker run --rm -it -v $(cd $(dirname $0) && pwd):/vo:ro pypy:3-2.4.0 \
   /bin/bash -c "pypy3 /vo/$(basename $0) < /vo/input.txt"
exit $?
'''
import sys
import bisect
from operator import itemgetter


def _i(): return int(sys.stdin.readline().strip())


def _ia(): return map(int, sys.stdin.readline().strip().split())


def main():
    n = _i()
    a = tuple(_ia())
    l = {}
    for i, ai in enumerate(a):
        aip = ai + i + 1
        l[aip] = l.get(aip, 0) + 1
    r = tuple(sorted(i+1-ai for i, ai in enumerate(a)))
    li = 0
    ans = 0
    for k, v in sorted(l.items(), key=itemgetter(0)):
        r = r[li:]
        li = bisect.bisect_right(r, k)
        ans += v * (li - bisect.bisect_left(r, k))
        if li >= n:
            break
    return ans


if __name__ == "__main__":
    print(main())


Fixed submission:
import sys
from collections import Counter


def _ia(): return map(int, sys.stdin.readline().strip().split())


def main():
    _ = sys.stdin.readline()
    a = list(_ia())
    l = Counter(ai+i+1 for i, ai in enumerate(a))
    r = Counter(i+1-ai for i, ai in enumerate(a))
    return sum(v*r.get(k, 0) for k, v in l.items())


if __name__ == "__main__":
    print(main())