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.
(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.
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