Competitive Pro Template (Python)

Following on from Templates for C ++, I decided to create a Python template as well. Codeforces, which I'm addicted to recently, requires faster input, so I decided to introduce it unavoidably.

Template description

(1)itertools It is the most capable module in the competition pro. If you don't know how to use it, read My article. By the way, I have also used combinations \ _with \ _replacement, but I omitted it because the function name is long.

(2)collections A deque that can be added / deleted from both directions, a Counter that can save the number of each element, and both are effective data structures. By the way, Counter is a subclass of a dictionary, so you can use it like a dictionary.

(3)bisect This module is used for binary search. If you don't know how to use it, read My article.

(4)math I actually use only gcd, lcm, sqrt. That said, I've used trigonometric functions in Kodofo (see see).

(5)fractions,decimal This module is used to avoid decimal point error. fractions keeps rational numbers without error, and decimal keeps decimal numbers without error. I think it was the first and last time I used it in ABC169-C Multiplication 3 (My commentary article is [here](https: /) /qiita.com/DaikiSuyama/items/58f7ccbe3ad3abea9d2e#c%E5%95%8F%E9%A1%8C)).

(6)sys,input Speed up input. It is no exaggeration to say that it is essential in Kodofo.

(7)MOD,INF Both will be used frequently if you are a competitive pro. Please change the value as appropriate.

History of additions / corrections / deletions

Added (2020/11/04) setrecursionlimit raises the upper limit of the number of recursion. I set it to $ 10 ^ 7 $ times. By the way, if you submit with Codeforces including setrecursionlimit in PyPy3, it will be MLE, so I commented it out (mystery ...).

code

template.py


from itertools import accumulate,chain,combinations,groupby,permutations,product
from collections import deque,Counter
from bisect import bisect_left,bisect_right
from math import gcd,sqrt,sin,cos,tan,degrees,radians
from fractions import Fraction
from decimal import Decimal
import sys
#You may need rstrip
input=sys.sys.stdin.readline
#from sys import setrecursionlimit
#setrecursionlimit(10**7)
MOD=10**9+7
INF=10**20

Recommended Posts

Competitive Pro Template (Python)
[Python] Competitive template [At Coder]
python argparse template
[Python] Tkinter template
Competitive programming diary python 20201213
Competitive programming diary python 20201220
Competitive programming with python
Python data analysis template
Jinja2 | Python template engine
python unit test template
Competitive programming diary python
Python template engine empy
Python3 standard input (competition pro)
Python template for Codeforces-manual test-
Python Competitive Programming Site Summary
Python Design Pattern --Template method
A collection of competitive pro techniques to solve with Python
Python3 standard input for competitive programming
Python
[Competitive Pro Struggle] Implemented Union Find
Preprocessing template for data analysis (Python)
Template AtCoder ABC 179 Python (A ~ E)
template
Competitive programming with python Local environment settings
Template for writing batch scripts in python
Competitive Pro Debut Senki AtCorder Beginner Contest 160
The Python project template I think of.
[Competitive programming] [Python3] Required knowledge, for myself
Competitive Pro with Python and VSCode-Simplification of standard input and automation of sample case judgment-