This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as n | |
from numpy.linalg import det | |
from sys import stdin | |
from itertools import permutations,product | |
[(lambda g:g(g,0))(lambda g,i: any(r.update((j,(r[i][0]@p,r[i][0]@(a[k]-p@b[1])+r[i][1])) for p in (n.take(n.identity(3,int),p,axis=0)*s for p in permutations(range(3)) for s in product(*[[-1,1]]*3)) if det(p)==1 for k in (0,1) if n.array_equal(a[k]-a[1-k],p@(b[1]-b[0]))) or g(g,j) for j in range(len(d)) if j not in r for v in [next(iter(set(d[i].keys())&set(d[j].keys())),0)] if v for a,b in [(d[i][v],d[j][v])])) or print(max(sum(n.abs(r[i][1]-r[j][1])) for i in r for j in r)) for r in [{0:(n.identity(3,int),n.zeros(3,int))}] for d in [[dict(filter(lambda x:len(set(x[0]))==3, ((tuple(n.sort(n.abs(s[i]-s[j]))),(s[i],s[j])) for i in range(len(s)) for j in range(i)))) for s in [s.startswith('--') and not m.append([]) or len(s)>1 and m[-1].append(n.fromstring(s,int,sep=',')) or m for m in [[]] for s in stdin.readlines()][-1]]]] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from regex import search,sub,subn | |
from functools import reduce | |
from itertools import islice,accumulate | |
from math import ceil | |
from sys import stdin | |
print((lambda l:max((lambda g,s:int(g(g,s)))(lambda g,s:s[0]=='[' and g(g,sub('\[(\d+),(\d+)\]',lambda p:str(3*int(p[1])+2*int(p[2])),s)) or s,(lambda g,s:g(g,s))(lambda g,s: (lambda n: n and g(g,n) or s)((lambda i: i and (lambda m:sub('(?r)\d+',lambda v:str(int(v[0])+int(m[1])),s[:m.start()-1],count=1)+'0'+sub('\d+',lambda v:str(int(v[0])+int(m[2])),s[m.end()+1:],count=1))(search('(\d+),(\d+)',s,pos=i[0])))(next(filter(lambda x: x[1]==5, enumerate(accumulate((c=='[')-(c==']') for c in s))),0)) or (lambda r:r[1] and r[0])(subn('\d\d',lambda v:'[%s,%s]'%(int(v[0])//2,ceil(int(v[0])/2)),s,count=1))),'[%s,%s]'%(a,b))) for a in l for b in l if a!=b))([x.rstrip() for x in stdin.readlines()])) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
x1,x2,y1,y2=88,125,-157,-103 | |
print(sum(any(x1<=(k*x-k*(k-1)//2 if k<=x else x*(x+1)//2)<=x2 and y1<=k*y-k*(k-1)//2<=y2 for k in range(-2*y1+1)) for x in range(x2+1) for y in range(y1,-y1+1))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from re import findall | |
from sys import stdin | |
from collections import Counter | |
K=40 | |
print((lambda c: c[0][1]-c[len(c)-1][1])((lambda o,r,c,m: c.update(o) or (lambda s: any(c.update(s(s,o[i:i+2],K)) for i in range(len(o)-1)))(lambda s,p,k: ((p,k) in m or not m.update({(p,k): k>0 and p in r and Counter([r[p]])+s(s,p[0]+r[p],k-1)+s(s,r[p]+p[1],k-1) or Counter()})) and m[p,k]) or c.most_common())(stdin.readline().rstrip(),dict(findall(r'(\w+) -> (\w)',stdin.read())),Counter(),{}))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sys import stdin | |
N,M=82,14 | |
(lambda d: any(print(''.join((x,y) in d and '#' or ' ' for x in range(N))) for y in range(M))) (set((min(p[0]%N,N-2-p[0]%N), min(p[1]%M,M-2-p[1]%M)) for s in stdin.readlines() for p in [list(map(int,s.split(',')))])) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from itertools import count | |
from sys import stdin | |
print((lambda m: next(filter(lambda x:x,(any((lambda g,v:g(g,v))(lambda g,v: v in m and m[v]<10 and (m.update({v:m[v]+1}) or m[v]>9 and any(g(g,(v[0]+i,v[1]+j)) for i in (-1,0,1) for j in (-1,0,1) if (i,j)!=(0,0))), v) for v in list(m.keys())) or sum(m[v]>9 and not m.update({v:0}) for v in list(m.keys()))==len(m) and k for k in count(1)))))(dict(((i,j),int(e)) for i,l in enumerate(stdin.readlines()) for j,e in enumerate(l.rstrip())))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from functools import reduce | |
from regex import sub,search | |
from statistics import median | |
from sys import stdin | |
#print(sum((lambda m: m and {')':3,']':57,'}':1197,'>':25137}[m.group(0)] or 0)(search('\)|\}|\]|>',sub(r'\((?R)*\)|\[(?R)*\]|\{(?R)*\}|<(?R)*>', '', s))) for s in stdin.readlines())) | |
print(median([reduce(lambda v,c: 5*v+'\n([{<'.index(c), reversed(s), 0) for s in (sub(r'\((?R)*\)|\[(?R)*\]|\{(?R)*\}|<(?R)*>', '', s) for s in stdin.readlines()) if not search('\)|\}|\]|>', s)])) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
print((lambda h: (lambda b: b[-1]*b[-2]*b[-3])(sorted(((lambda s,v: s(s,v))(lambda s,v: v in h and (h.remove(v) or 1+sum(s(s,(v[0]+x,v[1]+y)) for x,y in ((-1,0),(1,0),(0,-1),(0,1)))), v) for v in list(h)))))(set((i,j) for i,l in enumerate(sys.stdin.readlines()) for j,d in enumerate(l.rstrip()) if d!='9')) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re, sys | |
print(sum((lambda w,d: any(d.update({(3,2,5,0,9,6)[x[0]*3+(x[1]>(d[4]-d[1]))-(x[1]>d[1])-14] if 4<x[0]<7 else (1,7,4,0,0,8)[x[0]-2]: x[1]}) for x in sorted(w)) or d.update((v,k) for k,v in list(d.items())) or int(''.join(str(d[x[1]]) for x in w[10:])))([(len(x), frozenset(x)) for x in re.findall(r'\w+',l)], {}) for l in sys.stdin.readlines())) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
import sys | |
from collections import Counter | |
from itertools import chain | |
print((lambda l: sum(1 for v in Counter(chain.from_iterable((lambda k: (((x1*i+x2*(k-i))//k, (y1*i+y2*(k-i))//k) for i in range(k+1)))(max(abs(x1-x2), abs(y1-y2))) for x1, y1, x2, y2 in l)).values() if v>1))(tuple(map(int, re.findall(r'\d+', l))) for l in sys.stdin.readlines())) |