input stringlengths 20 127k | target stringlengths 20 119k | problem_id stringlengths 6 6 |
|---|---|---|
def ans():
a, b = list(map(int,input().split()))
if(b%a == 0):
print((a+b))
else:
print((b-a))
ans() | A, B = list(map(int,input().split()))
if(B%A == 0):
print((A+B))
else:
print((B-A)) | p03125 |
a,b = list(map(int,input().split()))
if b%a == 0:
print((b+a))
else:
print((b-a)) | a,b = list(map(int,input().split()))
if b%a==0:print((a+b))
else:print((b-a)) | p03125 |
while 1:
r,a=input().split()
if r=='0' and a=='0': break
h = b = 0
for i in range(4):
if r[i]==a[i]: h+=1
for i in range(10):
b += min(r.count(chr(ord('0')+i)),a.count(chr(ord('0')+i)))
print(h,b-h) | while 1:
r,a=input().split()
if r=='0' and a=='0': break
h = b = 0
for i in range(4):
if r[i]==a[i]: h+=1
for s in r:
for t in a:
if s==t:
b+=1; break;
print(h,b-h) | p00226 |
H, W , N = list(map(int,input().split()))
from bisect import bisect_left
from bisect import bisect_right
matrix = []
for _ in range(N):
x,y = list(map(int,input().split()))
x -= 1
y -= 1
matrix.append([x,y])
matrix.sort()
ans = [0 for _ in range(10)]
from bisect import bisect_left
cand = {}
for l in matrix:
for x_r in [-2, -1 , 0]:
for y_r in [-2, -1 , 0]:
nowx = l[0] + x_r
nowy = l[1] + y_r
if nowx < 0 or nowy < 0 or nowx + 2>= H or nowy+ 2 >= W:
continue
#ここで起点(左上)nowx, nowy として 9マスに着目する
name = str(nowx) + str(nowy)
try: cand[name] += 1
except: cand[name] = 1
tmp = ((H - 2) * (W - 2))
for x in list(cand.values()):
if x > 9:
while True:
print(W)
ans[x] += 1
tmp -= 1
ans[0] = tmp
for x in ans:
print(x)
| H, W , N = list(map(int,input().split()))
from bisect import bisect_left
from bisect import bisect_right
matrix = []
for _ in range(N):
x,y = list(map(int,input().split()))
x -= 1
y -= 1
matrix.append([x,y])
matrix.sort()
ans = [0 for _ in range(10)]
cand = {}
for l in matrix:
for x_r in [-2, -1 , 0]:
for y_r in [-2, -1 , 0]:
nowx = l[0] + x_r
nowy = l[1] + y_r
if nowx < 0 or nowy < 0 or nowx + 2>= H or nowy+ 2 >= W:
continue
#ここで起点(左上)nowx, nowy として 9マスに着目する
name = str(nowx) +"hoge" +str(nowy)
try: cand[name] += 1
except: cand[name] = 1
tmp = ((H - 2) * (W - 2))
for x in list(cand.values()):
ans[x] += 1
tmp -= 1
ans[0] = tmp
for x in ans:
print(x)
| p04000 |
H, W , N = list(map(int,input().split()))
from bisect import bisect_left
from bisect import bisect_right
matrix = []
for _ in range(N):
x,y = list(map(int,input().split()))
x -= 1
y -= 1
matrix.append([x,y])
matrix.sort()
ans = [0 for _ in range(10)]
cand = {}
for l in matrix:
for x_r in [-2, -1 , 0]:
for y_r in [-2, -1 , 0]:
nowx = l[0] + x_r
nowy = l[1] + y_r
if nowx < 0 or nowy < 0 or nowx + 2>= H or nowy+ 2 >= W:
continue
#ここで起点(左上)nowx, nowy として 9マスに着目する
name = str(nowx) +"hoge" +str(nowy)
try: cand[name] += 1
except: cand[name] = 1
tmp = ((H - 2) * (W - 2))
for x in list(cand.values()):
ans[x] += 1
tmp -= 1
ans[0] = tmp
for x in ans:
print(x)
| H, W , N = list(map(int,input().split()))
from bisect import bisect_left
from bisect import bisect_right
matrix = []
for _ in range(N):
x,y = list(map(int,input().split()))
x -= 1
y -= 1
matrix.append([x,y])
matrix.sort()
ans = [0 for _ in range(10)]
cand = {}
for l in matrix:
for x_r in [-2, -1 , 0]:
for y_r in [-2, -1 , 0]:
nowx = l[0] + x_r
nowy = l[1] + y_r
if nowx < 0 or nowy < 0 or nowx + 2>= H or nowy+ 2 >= W:
continue
#ここで起点(左上)nowx, nowy として 9マスに着目する
name = str(nowx) + 'sakoda' +str(nowy)
try: cand[name] += 1
except: cand[name] = 1
tmp = ((H - 2) * (W - 2))
for x in list(cand.values()):
ans[x] += 1
tmp -= 1
ans[0] = tmp
for x in ans:
print(x)
| p04000 |
H, W , N = list(map(int,input().split()))
from bisect import bisect_left
from bisect import bisect_right
matrix = []
for _ in range(N):
x,y = list(map(int,input().split()))
x -= 1
y -= 1
matrix.append([x,y])
matrix.sort()
ans = [0 for _ in range(10)]
cand = {}
for l in matrix:
for x_r in [-2, -1 , 0]:
for y_r in [-2, -1 , 0]:
nowx = l[0] + x_r
nowy = l[1] + y_r
if nowx < 0 or nowy < 0 or nowx + 2>= H or nowy+ 2 >= W:
continue
#ここで起点(左上)nowx, nowy として 9マスに着目する
name = str(nowx) + 'sakoda' +str(nowy)
try: cand[name] += 1
except: cand[name] = 1
tmp = ((H - 2) * (W - 2))
for x in list(cand.values()):
ans[x] += 1
tmp -= 1
ans[0] = tmp
for x in ans:
print(x)
| H, W , N = list(map(int,input().split()))
from bisect import bisect_left
from bisect import bisect_right
matrix = []
for _ in range(N):
x,y = list(map(int,input().split()))
x -= 1
y -= 1
matrix.append([x,y])
matrix.sort()
ans = [0 for _ in range(10)]
cand = {}
for l in matrix:
for x_r in [-2, -1 , 0]:
for y_r in [-2, -1 , 0]:
nowx = l[0] + x_r
nowy = l[1] + y_r
if nowx < 0 or nowy < 0 or nowx + 2>= H or nowy+ 2 >= W:
continue
#ここで起点(左上)nowx, nowy として 9マスに着目する
name = str(nowx) + ' ' +str(nowy)
try: cand[name] += 1
except: cand[name] = 1
tmp = ((H - 2) * (W - 2))
for x in list(cand.values()):
ans[x] += 1
tmp -= 1
ans[0] = tmp
for x in ans:
print(x)
| p04000 |
a={}
h,w,n=list(map(int,input().split()))
for i in range(n):
y,x=list(map(int,input().split()))
for j in range(max(2,x-1),min(w-1,x+1)+1):
for k in range(max(2,y-1),min(h-1,y+1)+1):
if j*(10**10)+k in a:
a[j*(10**10)+k]+=1
else:
a[j*(10**10)+k]=1
ans=[0]*10
ans[0]=(h-2)*(w-2)
for key in a:
ans[0]-=1
ans[a[key]]+=1
for i in ans:
print(i) | h,w,n=list(map(int,input().split()))
dic={}
INF=10**10
for i in range(n):
y,x=list(map(int,input().split()))
for j in range(max(2,x-1),min(w-1,x+1)+1):
for k in range(max(2,y-1),min(h-1,y+1)+1):
if j*INF+k in dic:
dic[j*INF+k]+=1
else:
dic[j*INF+k]=1
ans=[0]*10
ans[0]=(h-2)*(w-2)
for i in dic:
ans[0]-=1
ans[dic[i]]+=1
for i in ans:
print(i)
| p04000 |
from collections import defaultdict
import sys
input = sys.stdin.readline
H,W,N = map(int,input().split())
D = defaultdict(bool)
B = []
for _ in range(N):
a,b = map(lambda x: int(x)-1,input().split())
D[(a,b)] = True
B.append((a,b))
ans = [0 for _ in range(10)]
for a,b in B:
for i in range(9):
ix,iy = divmod(i,3)
if a-ix<0 or b-iy<0:
continue
black_count = 0
for j in range(9):
jx,jy = divmod(j,3)
if H<=a-ix+jx or W<=b-iy+jy:
break
if D[(a-ix+jx,b-iy+jy)]:
if -ix+jx<0 or (-ix+jx==0 and -iy+jy<0):
break
black_count += 1
else:
ans[black_count] += 1
ans[0] = (H-2)*(W-2)-sum(ans)
print(*ans,sep='\n')
| from collections import defaultdict
import sys
input = sys.stdin.readline
H,W,N = map(int,input().split())
D = defaultdict(bool)
B = []
for _ in range(N):
a,b = map(lambda x: int(x)-1,input().split())
D[(a,b)] = True
B.append((a,b))
ans = [0 for _ in range(10)]
for a,b in B:
for i in range(9):
ix,iy = divmod(i,3)
if a-ix<0 or b-iy<0:
continue
black_count = 0
for j in range(9):
jx,jy = divmod(j,3)
if H<=a-ix+jx or W<=b-iy+jy:
break
if (a-ix+jx,b-iy+jy) in D:
if -iy+jy<0 or (-iy+jy==0 and -ix+jx<0):
break
black_count += 1
else:
ans[black_count] += 1
ans[0] = (H-2)*(W-2)-sum(ans)
print(*ans,sep='\n')
| p04000 |
from collections import Counter
import sys
import itertools
input = sys.stdin.readline
c = Counter()
H,W,N = list(map(int,input().split()))
for _ in range(N):
a,b = list(map(int,input().split()))
# そのセルを含む正方形の中心を記録
for dx,dy in itertools.product([-1,0,1],repeat = 2):
aa = a + dx
bb = b + dy
if 2 <= aa <= H-1 and 2 <= bb <= W-1:
c[(aa,bb)] += 1
result = Counter(list(c.values()))
result[0] = (H-2)*(W-2) - sum(result.values())
for j in range(10):
print((result[j])) | from collections import defaultdict, Counter
import sys
import itertools
input = sys.stdin.readline
c = defaultdict(int)
H,W,N = list(map(int,input().split()))
for _ in range(N):
a,b = list(map(int,input().split()))
# そのセルを含む正方形の中心を記録
for dx,dy in itertools.product([-1,0,1],repeat = 2):
aa = a + dx
bb = b + dy
if 2 <= aa <= H-1 and 2 <= bb <= W-1:
c[(aa,bb)] += 1
result = Counter(list(c.values()))
result[0] = (H-2)*(W-2) - sum(result.values())
for j in range(10):
print((result[j]))
| p04000 |
import sys
from bisect import bisect_left
from collections import defaultdict
def input(): return sys.stdin.readline().strip()
def main():
H, W, N = list(map(int, input().split()))
black = []
d = defaultdict(list)
for _ in range(N):
a, b = list(map(int, input().split()))
black.append((a - 1, b - 1))
d[a - 1].append(b - 1)
for key in d: d[key].sort()
ans = [0] * 10
checked = set()
# (a, b)がテンプレートのどこにいるかで9通り試す
for i in range(9):
for a, b in black:
h, w = a - i // 3, b - i % 3
if (h, w) in checked: continue
if h < 0 or w < 0: continue
if h > H - 3 or w > W - 3: continue
cnt = 0
idx1 = bisect_left(d[h], w)
idx2 = bisect_left(d[h], w + 3)
cnt += idx2 - idx1
idx1 = bisect_left(d[h + 1], w)
idx2 = bisect_left(d[h + 1], w + 3)
cnt += idx2 - idx1
idx1 = bisect_left(d[h + 2], w)
idx2 = bisect_left(d[h + 2], w + 3)
cnt += idx2 - idx1
#print("({}, {})=>{}".format(h, w, cnt))
ans[cnt] += 1
checked.add((h, w))
ans[0] = (H - 2) * (W - 2) - sum(ans[1:])
for a in ans: print(a)
if __name__ == "__main__":
main()
| import sys
def input(): return sys.stdin.readline().strip()
def main():
"""
https://atcoder.jp/contests/abc045/submissions/14945636
が高速に動作していたので参考に写経する。
各黒マスに対して、それを含むテンプレートを左上の座標値で管理する。
(写経元は右下座標で管理してる)
このテンプレート及びそこに黒マスが何個入っているかを管理しておけば
黒マス位置をソートして全体位置を把握していなくてもオンラインで更新が可能。
"""
H, W, N = list(map(int, input().split()))
ans = [0] * 10
templates = {}
for _ in range(N):
a, b = list(map(int, input().split()))
for i in range(9):
# (h, w)がテンプレートの左上座標
h, w = (a - 3) + i // 3, (b - 3) + i % 3
if h < 0 or w < 0: continue
if h > H - 3 or w > W - 3: continue
idx = h * W + w
if idx in templates:
ans[templates[idx]] -= 1
templates[idx] += 1
ans[templates[idx]] += 1
else:
templates[idx] = 1
ans[1] += 1
ans[0] = (H - 2) * (W - 2) - sum(ans[1:])
for a in ans: print(a)
if __name__ == "__main__":
main()
| p04000 |
def sol():
import sys
input=sys.stdin.readline
h,w,n=list(map(int,input().split()))
d={}
for i in range(n):
y,x=list(map(int,input().split()))
if (y,x) in d:
d[(y,x)]+=1
else:
d[(y,x)]=1
if y+1<=h and (y+1,x) in d:
d[(y+1,x)]+=1
elif y+1<=h:
d[(y+1,x)]=1
if y+2<=h and (y+2,x) in d:
d[(y+2,x)]+=1
elif y+2<=h:
d[(y+2,x)]=1
if x+1<=w and (y,x+1) in d:
d[(y,x+1)]+=1
elif x+1<=w:
d[(y,x+1)]=1
if x+2<=w and (y,x+2) in d:
d[(y,x+2)]+=1
elif x+2<=w:
d[(y,x+2)]=1
if x+1<=w and y+1<=h and (y+1,x+1) in d:
d[(y+1,x+1)]+=1
elif x+1<=w and y+1<=h:
d[(y+1,x+1)]=1
if x+2<=w and y+1<=h and (y+1,x+2) in d:
d[(y+1,x+2)]+=1
elif x+2<=w and y+1<=h:
d[(y+1,x+2)]=1
if x+1<=w and y+2<=h and (y+2,x+1) in d:
d[(y+2,x+1)]+=1
elif x+1<=w and y+2<=h:
d[(y+2,x+1)]=1
if x+2<=w and y+2<=h and (y+2,x+2) in d:
d[(y+2,x+2)]+=1
elif x+2<=w and y+2<=h:
d[(y+2,x+2)]=1
ans=[0]*10
for i in d:
if i[0]>2 and i[1]>2:
ans[d[i]]+=1
ans[0]=h*w-sum(ans)-w*2-h*2+4
for i in ans:
print(i)
if __name__=="__main__":
sol() | def sol():
import sys
input=sys.stdin.readline
h,w,n=list(map(int,input().split()))
d={}
t=[(0,0),(0,1),(0,2),(1,0),(1,1),(1,2),(2,0),(2,1),(2,2)]
for i in range(n):
y,x=list(map(int,input().split()))
for a,b in t:
a+=y
b+=x
if 0<a<=h and 0<b<=w and (a,b) in d: d[(a,b)]+=1
elif 0<a<=h and 0<b<=w: d[(a,b)]=1
ans=[0]*10
for i in d:
if i[0]>2 and i[1]>2:
ans[d[i]]+=1
ans[0]=h*w-sum(ans)-w*2-h*2+4
for i in ans:
print(i)
if __name__=="__main__":
sol() | p04000 |
from collections import defaultdict
H,W,N = list(map(int,input().split()))
d = defaultdict(lambda:0)
ab = [tuple(map(int,input().split())) for _ in range(N)]
for i in range(N):
d[ab[i]] = 1
ans = defaultdict(lambda:0)
def count(a,b):
for dx1 in [-1,0,1]:
for dy1 in [-1,0,1]:
x,y = a+dx1,b+dy1
if 2<=x<H and 2<=y<W:
n = 0
for dx2 in [-1,0,1]:
for dy2 in [-1,0,1]:
n += d[(x+dx2,y+dy2)]
ans[n] += 1
for i in range(N):
count(*ab[i])
ans[0] = (H-2)*(W-2)
for i in range(1,10):
ans[0] -= ans[i]//i
ans[i] //= i
for i in range(10):
print((ans[i])) | from collections import defaultdict
H,W,N = list(map(int,input().split()))
ab = [tuple(map(int,input().split())) for _ in range(N)]
d = defaultdict(lambda:0)
def count(a,b):
for dx1 in [-1,0,1]:
for dy1 in [-1,0,1]:
x,y = a+dx1,b+dy1
if 2<=x<H and 2<=y<W:
d[(x,y)] += 1
for i in range(N):
count(*ab[i])
ans = defaultdict(lambda:0)
for x,y in d:
ans[d[(x,y)]] += 1
ans[0] = (H-2)*(W-2)
for i in range(1,10):
ans[0] -= ans[i]
for i in range(10):
print((ans[i])) | p04000 |
import sys
#sys.stdin = open('input1.txt', 'r')
H, W , N = list(map(int, input().split()))
squares = {}
results = [0 for _ in range(10)]
for _ in range(N):
h, w = list(map(int, input().split()))
for x in [(0, 0), (0, -1), (0, -2), (-1, 0), (-1, -1), (-1, -2), (-2, 0), (-2, -1), (-2, -2)]:
nh, nw = h + x[0], w + x[1]
if ((nh < 1) or (nw < 1) or (nh + 2 > H) or (nw + 2 > W)):
pass
else:
if (nh, nw) in squares:
squares[(nh, nw)] += 1
else:
squares[(nh, nw)] = 1
for k in list(squares.keys()):
results[squares[k]] += 1
subtotal = 0
for x in range(1, 10, 1):
subtotal += results[x]
results[0] = (H - 2) * (W - 2) - subtotal
for x in range(10):
print(str(results[x]))
| import sys
#sys.stdin = open('input1.txt', 'r')
H, W , N = list(map(int, input().split()))
squares = {}
results = [0 for _ in range(10)]
for _ in range(N):
h, w = list(map(int, input().split()))
for x in [(0, 0), (0, -1), (0, -2), (-1, 0), (-1, -1), (-1, -2), (-2, 0), (-2, -1), (-2, -2)]:
nh, nw = h + x[0], w + x[1]
if ((nh < 1) or (nw < 1) or (nh + 2 > H) or (nw + 2 > W)):
pass
else:
if (nh, nw) in squares:
squares[(nh, nw)] += 1
else:
squares[(nh, nw)] = 1
for v in list(squares.values()):
results[v] += 1
subtotal = 0
for x in range(1, 10, 1):
subtotal += results[x]
results[0] = (H - 2) * (W - 2) - subtotal
for x in range(10):
print(str(results[x]))
| p04000 |
import sys
#sys.stdin = open('input1.txt', 'r')
H, W , N = list(map(int, input().split()))
squares = {}
results = [0 for _ in range(10)]
for _ in range(N):
h, w = list(map(int, input().split()))
for x in [(0, 0), (0, -1), (0, -2), (-1, 0), (-1, -1), (-1, -2), (-2, 0), (-2, -1), (-2, -2)]:
nh, nw = h + x[0], w + x[1]
if ((nh < 1) or (nw < 1) or (nh + 2 > H) or (nw + 2 > W)):
pass
else:
if (nh, nw) in squares:
squares[(nh, nw)] += 1
else:
squares[(nh, nw)] = 1
for v in list(squares.values()):
results[v] += 1
subtotal = 0
for x in range(1, 10, 1):
subtotal += results[x]
results[0] = (H - 2) * (W - 2) - subtotal
for x in range(10):
print(str(results[x]))
| import sys
#sys.stdin = open('input1.txt', 'r')
H, W , N = list(map(int, input().split()))
squares = {}
results = [0 for _ in range(10)]
for _ in range(N):
h, w = list(map(int, input().split()))
for x in [(0, 0), (0, -1), (0, -2), (-1, 0), (-1, -1), (-1, -2), (-2, 0), (-2, -1), (-2, -2)]:
nh, nw = h + x[0], w + x[1]
if ((nh < 1) or (nw < 1) or (nh + 2 > H) or (nw + 2 > W)):
pass
else:
if (nh, nw) in squares:
squares[(nh, nw)] += 1
else:
squares[(nh, nw)] = 1
for v in list(squares.values()):
results[v] += 1
results[0] = (H - 2) * (W - 2) - sum(results[1:])
for x in range(10):
print(str(results[x]))
| p04000 |
import bisect
from operator import itemgetter
h,w,n = list(map(int, input().split()))
# 黒マス
black = []
# 周囲に黒マスがあるマス
search = set()
for i in range(n):
a,b = list(map(int, input().split()))
a-=1
b-=1
black.append([a,b])
for x in [-1,0,1]:
for y in [-1,0,1]:
if 1<=a+y<h-1 and 1<=b+x<w-1:
search.add((a+y,b+x)) # タプル。set()内にリストは格納できない。
# 二分探索のためソート
black.sort(key=itemgetter(1))
black.sort(key=itemgetter(0))
ans = [0]*10
# 探索すべき全マスに対して、周囲の黒マスの数を数える。
for a,b in search:
p = 0
for y in [-1,0,1]:
for x in [-1,0,1]:
try:
if [a+y,b+x]==black[bisect.bisect_left(black,[a+y,b+x])]:
p+=1
except:
continue
ans[p]+=1
ans[0]=(h-2)*(w-2)-sum(ans[1:])
for a in ans:
print(a) | h,w,n = list(map(int, input().split()))
# 黒マス black[y座標] = [x1,x2,...]
black = dict()
# 周囲に黒マスがあるマス
search = set()
for i in range(n):
a,b = list(map(int, input().split()))
a-=1
b-=1
for x in [-1,0,1]:
for y in [-1,0,1]:
if 1<=a+y<h-1 and 1<=b+x<w-1:
search.add((a+y,b+x)) # タプル。set()内にリストは格納できない。
try:
black[a][b]=1
except:
black[a]=dict()
black[a][b]=1
ans = [0]*10
# 探索すべき全マスに対して、周囲の黒マスの数を数える。
for a,b in search:
p = 0
for y in [-1,0,1]:
for x in [-1,0,1]:
try:
if black[a+y][b+x]==1:
p+=1
except:
continue
ans[p]+=1
ans[0]=(h-2)*(w-2)-sum(ans[1:])
for a in ans:
print(a) | p04000 |
H,W,N = map(int,input().split())
A = {}
for i in range(N):
a,b = map(int,input().split())
a-=1;b-=1
for t in range(3):
for s in range(3):
if 0<=a-t<H-2 and 0<=b-s<W-2:
if (a-t,b-s) not in A:
A[(a-t,b-s)] = 1
else:
A[(a-t,b-s)] += 1
#print(A)
ans = [-1]
temp = list(A.values())
total = 0
for i in range(1,10):
c = temp.count(i)
total += c
ans.append(c)
ans[0] = (H-2)*(W-2)-total
print(*ans, sep="\n")
| H,W,N = list(map(int,input().split()))
B = set([])
for i in range(N):
a,b = list(map(int,input().split()))
a-=1;b-=1
B.add((a,b))
#print(B)
BB = list(B)
ans = [0 for _ in range(10)]
for i in range(N):
cnt = 0; temp = 0
x,y = BB[i]
#print(x,y)
for sx in range(max(0,x-2),min(x,H-3)+1):
for sy in range(max(0,y-2),min(y,W-3)+1):
temp = 0
for p in range(3):
for q in range(3):
if (sx+p,sy+q) in B:
temp += 1
#print(sx,sy,temp)
ans[temp] += 1
for i in range(1,10):
ans[i] = ans[i]//i
ans[0] = (H-2)*(W-2)-sum(ans[1:])
for t in ans:
print(t)
| p04000 |
import bisect
import heapq
H,W,N = list(map(int,input().split()))
P = list(list(map(int,input().split()))for i in range(N))
P.sort()
def index(a,x):
i = bisect.bisect_left(a,x)
if i != len(a) and a[i] == x:
return 0
return -1
def around(a,b):
out = []
for i in [-1,0,1]:
if not 1 < a+i < H:
continue
for j in [-1,0,1]:
if not 1 < b+j < W:
continue
out.append([a+i,b+j])
return out
def search(a,b):
hoge = 0
for i in [-1,0,1]:
for j in [-1,0,1]:
x,y = a+i,b+j
if index(P,[x,y]) != -1:
hoge += 1
return hoge
A = []
for a,b in P:
for x,y in around(a,b):
heapq.heappush(A,[search(x,y),x,y])
a,b = 0,0
ans = [0]*10
while A:
a = heapq.heappop(A)
if a != b:
ans[a[0]] += 1
b = a[:]
ans[0] = (H-2)*(W-2)-sum(ans[1:])
for i in ans:
print(i) | import sys
input = sys.stdin.readline
H,W,N = list(map(int,input().split()))
A = []
for i in range(N):
a,b = list(map(int,input().split()))
for i in [-1,0,1]:
for j in [-1,0,1]:
if (1< a+i <H) and (1 < b+j < W):
A.append([a+i,b+j])
A.sort()
ans = [0]*10
hoge = 0
for i in range(len(A)):
if A[i] == A[i-1]:
hoge += 1
else:
ans[hoge]+= 1
hoge = 1
ans[hoge]+= 1
ans[0] = (W-2)*(H-2)-sum(ans[1:])
for i in ans:
print(i) | p04000 |
import sys
input = sys.stdin.readline
lst = []
lst_append = lst.append
H, W, N = map(int, input().split())
tmplst = [-1, 0, 1]
for _ in range(N):
a, b = map(int, input().split())
a -= 1
b -= 1
for i in range(-1, 2):
for j in range(-1, 2):
if 1 <= a + i <= H - 2 and 1 <= b + j <= W - 2:
lst_append((a + i, b + j))
lst.sort()
ans = [0] * 10
ans[0] = (H - 2) * (W - 2)
tmp = None
count = 0
for i in lst:
if i == tmp:
count += 1
else:
ans[0] -= 1
ans[count] += 1
count = 1
tmp = i
ans[0] -= 1
ans[count] += 1
print (*ans, sep = '\n')
| import sys
input = sys.stdin.readline
lst = []
lst_append = lst.append
H, W, N = map(int, input().split())
tmplst = [-1, 0, 1]
for _ in range(N):
a, b = map(int, input().split())
a -= 1
b -= 1
for i in tmplst:
if 1 <= a + i <= H - 2:
for j in tmplst:
if 1 <= b + j <= W - 2:
lst_append((a + i, b + j))
lst.sort()
ans = [0] * 10
ans[0] = (H - 2) * (W - 2)
tmp = None
count = 0
for i in lst:
if i == tmp:
count += 1
else:
ans[0] -= 1
ans[count] += 1
count = 1
tmp = i
ans[0] -= 1
ans[count] += 1
print (*ans, sep = '\n')
| p04000 |
from collections import Counter
H,W,N = list(map(int,input().split()))
Bs = []
for i in range(N):
x,y = list(map(int,input().split()))
for xx in range(3):
for yy in range(3):
tx,ty = x-xx,y-yy
if 1<=tx and tx<=H-2 and 1<=ty and ty<=W-2:
Bs.append((tx,ty))
C = [0]*10
for (x,y),v in Counter(Bs).most_common():
C[v] += 1
C[0] = (H-2)*(W-2)-sum(C)
for i in range(10):
print((C[i]))
| H,W,N = list(map(int,input().split()))
dic = {}
for i in range(N):
a,b = list(map(int,input().split()))
for dh in range(3):
for dw in range(3):
if 0<a-dh<=H-2 and 0<b-dw<=W-2:
if (a-dh,b-dw) not in list(dic.keys()):
dic[(a-dh,b-dw)] = 1
else:
dic[(a-dh,b-dw)] += 1
Ans = [0]*10
total = 0
for v in list(dic.values()):
Ans[v] += 1
total += 1
Ans[0] = (H-2)*(W-2) - total
for ans in Ans:
print(ans)
| p04000 |
# python3 (3.4.3)
import sys
input = sys.stdin.readline
# main
from collections import defaultdict
H,W,N = list(map(int,input().split()))
AB = [list(map(int,input().split())) for _ in range(N)]
dic = defaultdict(int)
for a,b in AB:
for dh in range(3):
for dw in range(3):
if 0 < a-dh <= H-2 and 0 < b-dw <= W-2:
dic[(a-dh,b-dw)] += 1
Ans = [0]*10
total = 0
for v in list(dic.values()):
Ans[v] += 1
total += 1
Ans[0] = (H-2)*(W-2) - total
for ans in Ans:
print(ans)
| # python3 (3.4.3)
import sys
input = sys.stdin.readline
# main
from collections import defaultdict
from collections import Counter
H,W,N = list(map(int,input().split()))
AB = [list(map(int,input().split())) for _ in range(N)]
dic = defaultdict(int)
for a,b in AB:
for dh in range(3):
for dw in range(3):
if 0 < a-dh <= H-2 and 0 < b-dw <= W-2:
dic[(a-dh,b-dw)] += 1
Ans = Counter(list(dic.values()))
Ans[0] = (H-2)*(W-2) - sum(Ans.values())
for i in range(10):
print((Ans[i])) | p04000 |
import sys
input = sys.stdin.readline
def main():
h,w,n = list(map(int,input().split()))
dg = 10**10
d = dict()
def f(z):
x,y = z//dg,z%dg
if 2 <= x <= h-1 and 2 <= y <= w-1:
return True
else:
False
for i in range(n):
a,b = list(map(int,input().split()))
if f((a-1)*dg + b-1):
if (a-1)*dg + b-1 in d:
d[(a-1)*dg + b-1] += 1
else:
d[(a-1)*dg + b-1] = 1
if f((a-1)*dg + b):
if (a-1)*dg + b in d:
d[(a-1)*dg + b] += 1
else:
d[(a-1)*dg + b] = 1
if f((a-1)*dg + b+1):
if (a-1)*dg + b+1 in d:
d[(a-1)*dg + b+1] += 1
else:
d[(a-1)*dg + b+1] = 1
if f((a)*dg + b-1):
if (a)*dg + b-1 in d:
d[(a)*dg + b-1] += 1
else:
d[(a)*dg + b-1] = 1
if f(a*dg + b):
if a*dg + b in d:
d[a*dg + b] += 1
else:
d[a*dg + b] = 1
if f((a)*dg + b+1):
if (a)*dg + b+1 in d:
d[(a)*dg + b+1] += 1
else:
d[(a)*dg + b+1] = 1
if f((a+1)*dg + b+1):
if (a+1)*dg + b+1 in d:
d[(a+1)*dg + b+1] += 1
else:
d[(a+1)*dg + b+1] = 1
if f((a+1)*dg + b):
if (a+1)*dg + b in d:
d[(a+1)*dg + b] += 1
else:
d[(a+1)*dg + b] = 1
if f((a+1)*dg + b-1):
if (a+1)*dg + b-1 in d:
d[(a+1)*dg + b-1] += 1
else:
d[(a+1)*dg + b-1] = 1
res = [0]*10
for e in d:
res[d[e]] += 1
res[0] = (h-2)*(w-2)-sum(res)
for e in res:
print(e)
if __name__ == "__main__":
main() | import sys
input = sys.stdin.readline
def main():
h,w,n = list(map(int,input().split()))
dg = 10**10
d = dict()
def f(z):
x,y = divmod(z,dg)
if 2 <= x <= h-1 and 2 <= y <= w-1:
return True
else:
False
for i in range(n):
a,b = list(map(int,input().split()))
if f((a-1)*dg + b-1):
if (a-1)*dg + b-1 in d:
d[(a-1)*dg + b-1] += 1
else:
d[(a-1)*dg + b-1] = 1
if f((a-1)*dg + b):
if (a-1)*dg + b in d:
d[(a-1)*dg + b] += 1
else:
d[(a-1)*dg + b] = 1
if f((a-1)*dg + b+1):
if (a-1)*dg + b+1 in d:
d[(a-1)*dg + b+1] += 1
else:
d[(a-1)*dg + b+1] = 1
if f((a)*dg + b-1):
if (a)*dg + b-1 in d:
d[(a)*dg + b-1] += 1
else:
d[(a)*dg + b-1] = 1
if f(a*dg + b):
if a*dg + b in d:
d[a*dg + b] += 1
else:
d[a*dg + b] = 1
if f((a)*dg + b+1):
if (a)*dg + b+1 in d:
d[(a)*dg + b+1] += 1
else:
d[(a)*dg + b+1] = 1
if f((a+1)*dg + b+1):
if (a+1)*dg + b+1 in d:
d[(a+1)*dg + b+1] += 1
else:
d[(a+1)*dg + b+1] = 1
if f((a+1)*dg + b):
if (a+1)*dg + b in d:
d[(a+1)*dg + b] += 1
else:
d[(a+1)*dg + b] = 1
if f((a+1)*dg + b-1):
if (a+1)*dg + b-1 in d:
d[(a+1)*dg + b-1] += 1
else:
d[(a+1)*dg + b-1] = 1
res = [0]*10
for e in d:
res[d[e]] += 1
res[0] = (h-2)*(w-2)-sum(res)
for e in res:
print(e)
if __name__ == "__main__":
main() | p04000 |
from collections import defaultdict
from collections import Counter
H, W, N = list(map(int, input().split()))
# 3*3マスの処理用リスト
dir = [[0, 0], [1, 0], [1, 1], [0, 1], [-1, 1],
[-1, 0], [-1, -1], [0, -1], [1, -1]]
# そのマスを中心とする3*3グリッドに含まれる黒マスの数
dict = defaultdict(int)
for i in range(N):
a, b = list(map(int, input().split()))
for dy, dx in dir:
# 3*3グリッドは、H*Wの中に完全に含まれていなければならないことに注意
if 2 <= a + dy <= H - 1 and 2 <= b + dx <= W - 1:
dict[(a + dy, b + dx)] += 1
c = Counter(list(dict.values()))
ans = [0 for _ in range(10)]
# ans[1], ans[2], ..., ans[9]を確定させる(ans[0]は後述)
for k, v in list(c.items()):
if v > 0:
ans[k] = v
# 全体で作れる3*3グリッドは(H-2)*(W-2)個
# ans[1],...,ans[9]の総和を引くとans[0]になる
ans[0] = (H - 2) * (W - 2) - sum(ans[1:])
for i in range(10):
print((ans[i]))
| from collections import Counter
H, W, N = list(map(int, input().split()))
# 3*3マスの処理用リスト
dir = [[0, 0], [1, 0], [1, 1], [0, 1], [-1, 1],
[-1, 0], [-1, -1], [0, -1], [1, -1]]
# そのマスを中心とする3*3グリッドに含まれる黒マスの数
dict = {}
for i in range(N):
a, b = list(map(int, input().split()))
for dy, dx in dir:
# 3*3グリッドは、H*Wの中に完全に含まれていなければならないことに注意
if 2 <= a + dy <= H - 1 and 2 <= b + dx <= W - 1:
if (a + dy, b + dx) not in dict:
dict[(a + dy, b + dx)] = 1
else:
dict[(a + dy, b + dx)] += 1
c = Counter(list(dict.values()))
ans = [0 for _ in range(10)]
# ans[1], ans[2], ..., ans[9]を確定させる(ans[0]は後述)
for k, v in list(c.items()):
if v > 0:
ans[k] = v
# 全体で作れる3*3グリッドは(H-2)*(W-2)個
# ans[1],...,ans[9]の総和を引くとans[0]になる
ans[0] = (H - 2) * (W - 2) - sum(ans[1:])
for i in range(10):
print((ans[i]))
| p04000 |
from collections import Counter
H, W, N = list(map(int, input().split()))
# 3*3マスの処理用リスト
dir = [[0, 0], [1, 0], [1, 1], [0, 1], [-1, 1],
[-1, 0], [-1, -1], [0, -1], [1, -1]]
# そのマスを中心とする3*3グリッドに含まれる黒マスの数
dict = {}
for i in range(N):
a, b = list(map(int, input().split()))
for dy, dx in dir:
# 3*3グリッドは、H*Wの中に完全に含まれていなければならないことに注意
if 2 <= a + dy <= H - 1 and 2 <= b + dx <= W - 1:
if (a + dy, b + dx) not in dict:
dict[(a + dy, b + dx)] = 1
else:
dict[(a + dy, b + dx)] += 1
c = Counter(list(dict.values()))
ans = [0 for _ in range(10)]
# ans[1], ans[2], ..., ans[9]を確定させる(ans[0]は後述)
for k, v in list(c.items()):
if v > 0:
ans[k] = v
# 全体で作れる3*3グリッドは(H-2)*(W-2)個
# ans[1],...,ans[9]の総和を引くとans[0]になる
ans[0] = (H - 2) * (W - 2) - sum(ans[1:])
for i in range(10):
print((ans[i]))
| from collections import defaultdict
from collections import Counter
H, W, N = list(map(int, input().split()))
# 3*3マスの処理用リスト
dir = [[0, 0], [1, 0], [1, 1], [0, 1], [-1, 1],
[-1, 0], [-1, -1], [0, -1], [1, -1]]
# そのマスを中心とする3*3グリッドに含まれる黒マスの数
dict = defaultdict(int)
for i in range(N):
a, b = list(map(int, input().split()))
for dy, dx in dir:
# 3*3グリッドは、H*Wの中に完全に含まれていなければならないことに注意
if 2 <= a + dy <= H - 1 and 2 <= b + dx <= W - 1:
dict[(a + dy, b + dx)] += 1
c = Counter(list(dict.values()))
ans = [0 for _ in range(10)]
# ans[1], ans[2], ..., ans[9]を確定させる(ans[0]は後述)
for k, v in list(c.items()):
if v > 0:
ans[k] = v
# 全体で作れる3*3グリッドは(H-2)*(W-2)個
# ans[1],...,ans[9]の総和を引くとans[0]になる
ans[0] = (H - 2) * (W - 2) - sum(ans[1:])
for i in range(10):
print((ans[i]))
| p04000 |
#in1 = '4 5 8'
#in2 = ['1 1', '1 4', '1 5', '2 3', '3 1', '3 2', '3 4', '4 4']
#in1 = '10 10 20'
#in2 = ['1 1', '1 4', '1 9', '2 5', '3 10', '4 2', '4 7', '5 9', '6 4', '6 6', '6 7', '7 1', '7 3', '7 7', '8 1', '8 5', '8 10', '9 2', '10 4', '10 9']
#in1 = '1000000000 1000000000 0'
#h, w, n = map(int, in1.split())
h, w, n = list(map(int, input().split()))
"""
10010
00000
00000
00000
"""
idx1 = 0
ab = [[0 for i in range(2)] for j in range(n)]
black_cnt = [0] * 10
black_cnt[0] = (h - 2) * (w - 2)
if n != 0:
while idx1 < n:
x = input().split()
#x = in2[idx1].split()
ab[idx1] = [int(x[0]), int(x[1])]
idx1 += 1
for idx1 in range(len(ab)):
if ab[idx1][0] < 3:
sr = 0
else:
sr = ab[idx1][0] - 3
if ab[idx1][0] > h - 2:
lr = h - 2
else:
lr = ab[idx1][0]
if ab[idx1][1] < 3:
sc = 0
else:
sc = ab[idx1][1] - 3
if ab[idx1][1] > w - 2:
lc = w - 2
else:
lc = ab[idx1][1]
#print('s_Row:{} l_Row:{} s_Col:{} l_Col:{}'.format(sr, lr, sc, lc))
for nowRow in range(sr, lr):
for nowCol in range(sc, lc):
#print('nowRow:{} nowCol:{}'.format(nowRow, nowCol))
w_black = 0
for idx2 in range(idx1):
if nowRow < ab[idx2][0] <= nowRow + 3 and nowCol < ab[idx2][1] <= nowCol + 3:
w_black += 1
black_cnt[w_black] -= 1
black_cnt[w_black + 1] += 1
#print(black_cnt)
for idx1 in range(len(black_cnt)):
print((black_cnt[idx1]))
| #in1 = '4 5 8'
#in2 = ['1 1', '1 4', '1 5', '2 3', '3 1', '3 2', '3 4', '4 4']
#in1 = '10 10 20'
#in2 = ['1 1', '1 4', '1 9', '2 5', '3 10', '4 2', '4 7', '5 9', '6 4', '6 6', '6 7', '7 1', '7 3', '7 7', '8 1', '8 5', '8 10', '9 2', '10 4', '10 9']
#in1 = '1000000000 1000000000 0'
#h, w, n = map(int, in1.split())
h, w, n = list(map(int, input().split()))
idx1 = 0
ab = [[0 for i in range(2)] for j in range(n)]
black_cnt = [0] * 10
black_cnt[0] = (h - 2) * (w - 2)
if n != 0:
while idx1 < n:
x = input().split()
#x = in2[idx1].split()
ab[idx1] = [int(x[0]), int(x[1])]
idx1 += 1
myDict = {}
for abitem in ab:
if abitem[0] < 3:
sr = 0
else:
sr = abitem[0] - 3
if abitem[0] > h - 3:
lr = h - 2
else:
lr = abitem[0]
if abitem[1] < 3:
sc = 0
else:
sc = abitem[1] - 3
if abitem[1] > w - 3:
lc = w - 2
else:
lc = abitem[1]
for nowRow in range(sr, lr):
for nowCol in range(sc, lc):
key = str(nowRow) + ',' + str(nowCol)
if key in myDict:
myDict[key] += 1
else:
myDict[key] = 1
for bcnt in list(myDict.values()):
black_cnt[bcnt] += 1
black_cnt[0] -= 1
for item in black_cnt:
print(item)
| p04000 |
H, W, N = list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(N)]
from itertools import product
S = [set() for _ in range(10)]
N = [0]*10
N[0] = (H-2)*(W-2)
# S[i]: set(黒いマスをi個こ含む3*3マスの中心セル)
for a,b in AB:
for x,y in product([-1,0,1], repeat=2):
X = a+x-1
Y = b+y-1
if X<=0 or H-1<=X or Y<=0 or W-1<=Y:
continue
for i in range(10):
if (X, Y) in S[i]:
S[i].remove((X, Y))
S[i+1].add((X, Y))
N[i] -=1
N[i+1] +=1
break
else:
S[1].add((X, Y))
N[1] +=1
N[0] -=1
for n in N:
print(n) | H, W, N = list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(N)]
from itertools import product
S = [set() for _ in range(10)]
# S[i]: set(黒いマスをi個こ含む3*3マスの中心セル)
for a,b in AB:
for x,y in product([-1,0,1], repeat=2):
X = a+x-1
Y = b+y-1
if X<=0 or H-1<=X or Y<=0 or W-1<=Y:
continue
for i in range(10):
if (X, Y) in S[i]:
S[i].remove((X, Y))
S[i+1].add((X, Y))
break
else:
S[1].add((X, Y))
L = [len(s) for s in S[1:]]
print(((H-2)*(W-2) - sum(L)))
for l in L:
print(l) | p04000 |
h,w,n = list(map(int, input().split()))
l=[list(map(int,input().split())) for i in range(n)]
from collections import defaultdict
d = defaultdict(int)
for tmp in l:
y=tmp[0]-1
x=tmp[1]-1
for i in [-1,0,1]:
for j in [-1,0,1]:
if 1<=x+i<w-1 and 1<=y+j <h-1:
s = str(x+i) + "_" + str(y+j)
d[s]+=1
import collections
lis = list(d.values())
c = collections.Counter(lis)
ans=[0]*10
for itm in list(c.items()):
ans[itm[0]]=itm[1]
ans[0]=(h-2)*(w-2)-sum(ans)
for a in ans:
print(a) | import sys
input=sys.stdin.readline
h,w,n = list(map(int, input().split()))
l=[list(map(int,input().split())) for i in range(n)]
from collections import defaultdict
d = defaultdict(int)
for tmp in l:
y=tmp[0]-1
x=tmp[1]-1
for i in [-1,0,1]:
for j in [-1,0,1]:
if 1<=x+i<w-1 and 1<=y+j <h-1:
s = str(x+i) + "_" + str(y+j)
d[s]+=1
import collections
lis = list(d.values())
c = collections.Counter(lis)
ans=[0]*10
for itm in list(c.items()):
ans[itm[0]]=itm[1]
ans[0]=(h-2)*(w-2)-sum(ans)
for a in ans:
print(a) | p04000 |
from collections import defaultdict
h, w, n = list(map(int, input().split()))
d = defaultdict(int)
for i in range(n):
a, b = list(map(int, input().split()))
for k in range(3):
if 1 <= a - k <= h - 2:
for l in range(3):
if 1 <= b - l <= w - 2:
x = (a - k, b - l)
d[x] += 1
ans = [0] * 10
for v in list(d.values()):
ans[v] += 1
ans[0] = (h - 2) * (w - 2) - sum(ans[1:])
for i in range(10):
print((ans[i]))
| from collections import defaultdict
h, w, n = list(map(int, input().split()))
d = defaultdict(int)
for i in range(n):
a, b = list(map(int, input().split()))
for k in range(max(1, a - 2), min(h - 2, a) + 1):
for l in range(max(1, b - 2), min(w - 2, b) + 1):
x = (k, l)
d[x] += 1
ans = [0] * 10
for v in list(d.values()):
ans[v] += 1
ans[0] = (h - 2) * (w - 2) - sum(ans[1:])
for i in range(10):
print((ans[i]))
| p04000 |
import math
import fractions
#import sys
#input = sys.stdin.readline
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5)+1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n//i)
# divisors.sort()
return divisors
def ValueToBits(x,digit):
res = [0 for i in range(digit)]
now = x
for i in range(digit):
res[i]=now%2
now = now >> 1
return res
def BitsToValue(arr):
n = len(arr)
ans = 0
for i in range(n):
ans+= arr[i] * 2**i
return ans
def ZipArray(a):
aa = [[a[i],i]for i in range(n)]
aa.sort(key = lambda x : x[0])
for i in range(n):
aa[i][0]=i+1
aa.sort(key = lambda x : x[1])
b=[aa[i][0] for i in range(len(a))]
return b
def ValueToArray10(x, digit):
ans = [0 for i in range(digit)]
now = x
for i in range(digit):
ans[digit-i-1] = now%10
now = now //10
return ans
def Zeros(a,b):
if(b<=-1):
return [0 for i in range(a)]
else:
return [[0 for i in range(b)] for i in range(a)]
class Bit:
def __init__(self, n):
self.size = n
self.tree = [0] * (n + 1)
def sum(self, i):
s = 0
while i > 0:
s += self.tree[i]
i -= i & -i
return s
def add(self, i, x):
while i <= self.size:
self.tree[i] += x
i += i & -i
'''
def cmb(n, r, p):
if (r < 0) or (n < r):
return 0
r = min(r, n - r)
return fact[n] * factinv[r] * factinv[n-r] % p
p = 2
N = 10 ** 6 + 2
fact = [1, 1] # fact[n] = (n! mod p)
factinv = [1, 1] # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1] # factinv 計算用
for i in range(2, N + 1):
fact.append((fact[-1] * i) % p)
inv.append((-inv[p % i] * (p // i)) % p)
factinv.append((factinv[-1] * inv[-1]) % p)
'''
#a = list(map(int, input().split()))
#################################################
#################################################
#################################################
#################################################
h,w,n = list(map(int, input().split()))
painted = []
for i in range(n):
t = list(map(int, input().split()))
for j in range(3):
for k in range(3):
painted.append([t[0]-2+j, t[1]-2+k])
painted.sort(key = lambda x : x[1])
painted.sort(key = lambda x : x[0])
p2 = []
for i in painted:
if(i[0]>=1 and i[0]<h-1 and i[1]>=1 and i[1]<w-1):
p2.append(i)
#print(p2)
ans = [0 for i in range(10)]
chain=0
if(len(p2)>0):
before = p2[0]
chain = 1
for ii in range(len(p2)-1):
i = ii+1
if(p2[i][0] == before[0] and p2[i][1] == before[1]):
chain += 1
else:
ans[chain]+=1
chain=1
before[0],before[1] = p2[i]
if(len(p2)>0): ans[chain]+=1
ans[0] = (h-2)*(w-2) - sum(ans[1:])
for i in ans:
print(i)
| import math
import fractions
import sys
input = sys.stdin.readline
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5)+1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n//i)
# divisors.sort()
return divisors
def ValueToBits(x,digit):
res = [0 for i in range(digit)]
now = x
for i in range(digit):
res[i]=now%2
now = now >> 1
return res
def BitsToValue(arr):
n = len(arr)
ans = 0
for i in range(n):
ans+= arr[i] * 2**i
return ans
def ZipArray(a):
aa = [[a[i],i]for i in range(n)]
aa.sort(key = lambda x : x[0])
for i in range(n):
aa[i][0]=i+1
aa.sort(key = lambda x : x[1])
b=[aa[i][0] for i in range(len(a))]
return b
def ValueToArray10(x, digit):
ans = [0 for i in range(digit)]
now = x
for i in range(digit):
ans[digit-i-1] = now%10
now = now //10
return ans
def Zeros(a,b):
if(b<=-1):
return [0 for i in range(a)]
else:
return [[0 for i in range(b)] for i in range(a)]
class Bit:
def __init__(self, n):
self.size = n
self.tree = [0] * (n + 1)
def sum(self, i):
s = 0
while i > 0:
s += self.tree[i]
i -= i & -i
return s
def add(self, i, x):
while i <= self.size:
self.tree[i] += x
i += i & -i
'''
def cmb(n, r, p):
if (r < 0) or (n < r):
return 0
r = min(r, n - r)
return fact[n] * factinv[r] * factinv[n-r] % p
p = 2
N = 10 ** 6 + 2
fact = [1, 1] # fact[n] = (n! mod p)
factinv = [1, 1] # factinv[n] = ((n!)^(-1) mod p)
inv = [0, 1] # factinv 計算用
for i in range(2, N + 1):
fact.append((fact[-1] * i) % p)
inv.append((-inv[p % i] * (p // i)) % p)
factinv.append((factinv[-1] * inv[-1]) % p)
'''
#a = list(map(int, input().split()))
#################################################
#################################################
#################################################
#################################################
h,w,n = list(map(int, input().split()))
painted = []
for i in range(n):
t = list(map(int, input().split()))
for j in range(3):
for k in range(3):
painted.append([t[0]-2+j, t[1]-2+k])
painted.sort(key = lambda x : x[1])
painted.sort(key = lambda x : x[0])
p2 = []
for i in painted:
if(i[0]>=1 and i[0]<h-1 and i[1]>=1 and i[1]<w-1):
p2.append(i)
#print(p2)
ans = [0 for i in range(10)]
chain=0
if(len(p2)>0):
before = p2[0]
chain = 1
for ii in range(len(p2)-1):
i = ii+1
if(p2[i][0] == before[0] and p2[i][1] == before[1]):
chain += 1
else:
ans[chain]+=1
chain=1
before[0],before[1] = p2[i]
if(len(p2)>0): ans[chain]+=1
ans[0] = (h-2)*(w-2) - sum(ans[1:])
for i in ans:
print(i)
| p04000 |
inp=input().split(" ")
H=int(inp[0])
W=int(inp[1])
N=int(inp[2])
square=[]
plot=[]
times=[0 for i in range(10)]
times[0]=(H-2)*(W-2)
from collections import defaultdict
count=defaultdict(lambda:0)
def check(a,b,square):
for i in range(3):
for j in range(3):
if a-i>=0 and b-j>=0 and a+2-i<=H-1 and b+2-j<=W-1:
square.append([a-i,b-j])
for i in range(N):
plot.append(list(map(int,input().split(" "))))
check(plot[i][0]-1,plot[i][1]-1,square)
for i in range(len(square)):
count[str(square[i])]+=1
for i in list(count.values()):
times[i]+=1
times[0]-=1
for i in range(len(times)):
print((times[i])) | inp=input().split(" ")
H=int(inp[0])
W=int(inp[1])
N=int(inp[2])
plot=[]
times=[0 for i in range(10)]
times[0]=(H-2)*(W-2)
from collections import defaultdict
count=defaultdict(lambda:0)
def check(a,b,count):
for i in range(3):
for j in range(3):
if a-i>=0 and b-j>=0 and a+2-i<=H-1 and b+2-j<=W-1:
count[str([a-i,b-j])]+=1
for i in range(N):
plot.append(list(map(int,input().split(" "))))
check(plot[i][0]-1,plot[i][1]-1,count)
for i in list(count.values()):
times[i]+=1
times[0]-=1
for i in range(len(times)):
print((times[i])) | p04000 |
h, w, n = list(map(int, input().split()))
ab = [list(map(int, input().split())) for _ in range(n)]
from collections import defaultdict
d = defaultdict(int)
dp = [0] * 10
dp[0] = (h - 2) * (w - 2)
for i in range(n):
a = ab[i][0] - 1
b = ab[i][1] - 1
for dx in [-1, 0, 1]:
for dy in [-1, 0, 1]:
nx, ny = a + dx, b + dy # center
if nx >= 1 and nx <= h - 2 and ny >= 1 and ny <= w - 2:
# print(nx, ny)
tmp = 0
for dx2 in [-1, 0, 1]:
for dy2 in [-1, 0, 1]:
if d[str(nx + dx2) + ' ' + str(ny + dy2)] == 1:
tmp += 1
dp[tmp] -= 1
dp[tmp + 1] += 1
d[str(a) + ' ' + str(b)] = 1
# print(dp)
for d in dp:
print(d)
| h, w, n = list(map(int, input().split()))
ab = [list(map(int, input().split())) for _ in range(n)]
d = dict()
for i in range(len(ab)):
a = ab[i][0] - 1
b = ab[i][0] - 1
d[a] = set()
dp = [0] * 10
dp[0] = (h - 2) * (w - 2)
for i in range(n):
a = ab[i][0] - 1
b = ab[i][1] - 1
for dx in [-1, 0, 1]:
for dy in [-1, 0, 1]:
nx, ny = a + dx, b + dy # center
if nx >= 1 and nx <= h - 2 and ny >= 1 and ny <= w - 2:
# print(nx, ny)
tmp = 0
for dx2 in [-1, 0, 1]:
for dy2 in [-1, 0, 1]:
if nx + dx2 in d and ny + dy2 in d[nx + dx2]:
tmp += 1
dp[tmp] -= 1
dp[tmp + 1] += 1
d[a].add(b)
for x in dp:
print(x)
| p04000 |
from collections import defaultdict
H, W, N, *L = map(int, open(0).read().split())
dic = defaultdict(int)
for a, b in zip(*[iter(L)]*2):
for i in range(a-2,a+1):
for j in range(b-2,b+1):
if 0<i and i+2<=H and 0<j and j+2<=W:
dic[(i,j)] += 1
ans = [0]*10
ans[0] = (W-2)*(H-2)
for k in dic.keys():
ans[dic[k]] += 1
ans[0] -= 1
print(*ans,sep='\n')
| H, W, N, *L = list(map(int, open(0).read().split()))
dic = {}
for a, b in zip(*[iter(L)]*2):
for i in range(a-2,a+1):
for j in range(b-2,b+1):
if 0<i and i+2<=H and 0<j and j+2<=W:
dic[i*W+j] = dic.get(i*W+j,0)+1
ans = [0]*10
ans[0] = (W-2)*(H-2)
for k in list(dic.keys()):
ans[dic[k]] += 1
ans[0] -= 1
print(('\n'.join(map(str,ans)))) | p04000 |
import sys
input=sys.stdin.readline
H,W,N=list(map(int,input().split()))
point=set([])
ans=[0 for i in range(0,10)]
ans[0]=(H-2)*(W-2)
def black(x,y):
ans=0
if x!=1:
if y!=1:
if (x-1,y-1) in point:
ans+=1
if (x-1,y) in point:
ans+=1
if y!=W:
if (x-1,y+1) in point:
ans+=1
if y!=1:
if (x,y-1) in point:
ans+=1
if (x,y) in point:
ans+=1
if y!=W:
if (x,y+1) in point:
ans+=1
if x!=H:
if y!=1:
if (x+1,y-1) in point:
ans+=1
if (x+1,y) in point:
ans+=1
if y!=W:
if (x+1,y+1) in point:
ans+=1
return ans
for _ in range(0,N):
a,b=list(map(int,input().split()))
if a>2:
if b>2:
ss=black(a-1,b-1)
ans[ss]-=1
ans[ss+1]+=1
if W>b>1:
ss=black(a-1,b)
ans[ss]-=1
ans[ss+1]+=1
if W-1>b:
ss=black(a-1,b+1)
ans[ss]-=1
ans[ss+1]+=1
if H>a>1:
if b>2:
ss=black(a,b-1)
ans[ss]-=1
ans[ss+1]+=1
if W>b>1:
ss=black(a,b)
ans[ss]-=1
ans[ss+1]+=1
if W-1>b:
ss=black(a,b+1)
ans[ss]-=1
ans[ss+1]+=1
if H-1>a:
if b>2:
ss=black(a+1,b-1)
ans[ss]-=1
ans[ss+1]+=1
if W>b>1:
ss=black(a+1,b)
ans[ss]-=1
ans[ss+1]+=1
if W-1>b:
ss=black(a+1,b+1)
ans[ss]-=1
ans[ss+1]+=1
point.add((a,b))
for i in range(0,10):
print((ans[i]))
| import sys
input=sys.stdin.readline
H,W,N=list(map(int,input().split()))
point=set([])
ans=[0 for i in range(0,10)]
ans[0]=(H-2)*(W-2)
def black(x,y):
ans=0
if (x-1,y-1) in point:
ans+=1
if (x-1,y) in point:
ans+=1
if (x-1,y+1) in point:
ans+=1
if (x,y-1) in point:
ans+=1
if (x,y) in point:
ans+=1
if (x,y+1) in point:
ans+=1
if (x+1,y-1) in point:
ans+=1
if (x+1,y) in point:
ans+=1
if (x+1,y+1) in point:
ans+=1
return ans
for _ in range(0,N):
a,b=list(map(int,input().split()))
if a>2:
if b>2:
ss=black(a-1,b-1)
ans[ss]-=1
ans[ss+1]+=1
if W>b>1:
ss=black(a-1,b)
ans[ss]-=1
ans[ss+1]+=1
if W-1>b:
ss=black(a-1,b+1)
ans[ss]-=1
ans[ss+1]+=1
if H>a>1:
if b>2:
ss=black(a,b-1)
ans[ss]-=1
ans[ss+1]+=1
if W>b>1:
ss=black(a,b)
ans[ss]-=1
ans[ss+1]+=1
if W-1>b:
ss=black(a,b+1)
ans[ss]-=1
ans[ss+1]+=1
if H-1>a:
if b>2:
ss=black(a+1,b-1)
ans[ss]-=1
ans[ss+1]+=1
if W>b>1:
ss=black(a+1,b)
ans[ss]-=1
ans[ss+1]+=1
if W-1>b:
ss=black(a+1,b+1)
ans[ss]-=1
ans[ss+1]+=1
point.add((a,b))
for i in range(0,10):
print((ans[i]))
| p04000 |
import sys
from collections import deque
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7
def resolve():
H, W, n = map(int, input().split())
AB = set(tuple(tuple(map(lambda x: int(x) - 1, input().split())) for _ in range(n)))
d = ((1, 1), (1, 0), (1, -1), (0, 1), (0, 0), (0, -1), (-1, 1), (-1, 0), (-1, -1))
total = (H - 2) * (W - 2)
res = [0] * 10
used = set()
for a, b in AB:
if (a, b) in used:
continue
que = deque([(a, b)])
while que:
h, w = que.popleft()
if (h, w) in used:
continue
used.add((h, w))
cnt = 0
flg = True
tmp = []
for dh, dw in d:
next_h, next_w = h + dh, w + dw
if next_h < 0 or next_h >= H or next_w < 0 or next_w >= W:
flg = False
else:
if (next_h, next_w) in AB:
cnt += 1
if (next_h, next_w) not in used:
tmp.append((next_h, next_w))
if flg and cnt:
res[cnt] += 1
if cnt:
for next_h, next_w in tmp:
que.append((next_h, next_w))
res[0] = total - sum(res)
print(*res, sep="\n")
if __name__ == '__main__':
resolve()
| import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7
def resolve():
H, W, n = map(int, input().split())
AB = set(tuple(tuple(map(lambda x: int(x) - 1, input().split())) for _ in range(n)))
d = ((1, 1), (1, 0), (1, -1), (0, 1), (0, 0), (0, -1), (-1, 1), (-1, 0), (-1, -1))
target = set()
res = [0] * 10
for h, w in AB:
cnt = 0
flg = True
for dh, dw in d:
next_h, next_w = h + dh, w + dw
if next_h < 0 or next_h >= H or next_w < 0 or next_w >= W:
flg = False
if (next_h, next_w) in AB:
cnt += 1
else:
target.add((next_h, next_w))
if flg:
res[cnt] += 1
for h, w in target:
cnt = 0
for dh, dw in d:
next_h, next_w = h + dh, w + dw
if next_h < 0 or next_h >= H or next_w < 0 or next_w >= W:
break
if (next_h, next_w) in AB:
cnt += 1
else:
res[cnt] += 1
total = (H - 2) * (W - 2)
res[0] = total - sum(res)
print(*res, sep="\n")
if __name__ == '__main__':
resolve()
| p04000 |
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7
def resolve():
H, W, n = map(int, input().split())
AB = set(tuple(tuple(map(lambda x: int(x) - 1, input().split())) for _ in range(n)))
d = ((1, 1), (1, 0), (1, -1), (0, 1), (0, 0), (0, -1), (-1, 1), (-1, 0), (-1, -1))
target = set()
res = [0] * 10
for h, w in AB:
cnt = 0
flg = True
for dh, dw in d:
next_h, next_w = h + dh, w + dw
if next_h < 0 or next_h >= H or next_w < 0 or next_w >= W:
flg = False
if (next_h, next_w) in AB:
cnt += 1
else:
if (next_h, next_w) != (h, w):
target.add((next_h, next_w))
if flg:
res[cnt] += 1
for h, w in target:
cnt = 0
for dh, dw in d:
next_h, next_w = h + dh, w + dw
if next_h < 0 or next_h >= H or next_w < 0 or next_w >= W:
break
if (next_h, next_w) in AB:
cnt += 1
else:
res[cnt] += 1
total = (H - 2) * (W - 2)
res[0] = total - sum(res)
print(*res, sep="\n")
if __name__ == '__main__':
resolve()
| import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7
def resolve():
H, W, n = map(int, input().split())
AB = set(tuple(tuple(map(lambda x: int(x) - 1, input().split())) for _ in range(n)))
d = ((1, 1), (1, 0), (1, -1), (0, 1), (0, 0), (0, -1), (-1, 1), (-1, 0), (-1, -1))
target = set()
res = [0] * 10
for h, w in AB:
cnt = 0
flg = True
for dh, dw in d:
next_h, next_w = h + dh, w + dw
if next_h < 0 or next_h >= H or next_w < 0 or next_w >= W:
flg = False
if (next_h, next_w) in AB:
cnt += 1
else:
if (next_h, next_w) not in AB:
target.add((next_h, next_w))
if flg:
res[cnt] += 1
for h, w in target:
cnt = 0
for dh, dw in d:
next_h, next_w = h + dh, w + dw
if next_h < 0 or next_h >= H or next_w < 0 or next_w >= W:
break
if (next_h, next_w) in AB:
cnt += 1
else:
res[cnt] += 1
total = (H - 2) * (W - 2)
res[0] = total - sum(res)
print(*res, sep="\n")
if __name__ == '__main__':
resolve()
| p04000 |
import sys
from collections import defaultdict
def input():
return sys.stdin.readline().strip()
def recordnum(a,b):
if not (0 < a < H-1 and 0 < b < W-1):
return
res = M[(a,b)]
for i,j in vector:
res += M[(a+i,b+j)]
num[res] += 1
return
def dfs(a,b,color):
if visited[(a,b)]:
return
recordnum(a,b)
visited[(a,b)] = True
if color == "b":
for i,j in vector:
x = a+i
y = b+j
if 0 < x < H-1 and 0 < y < W-1 and M[(x,y)] == 0:
dfs(x,y,"w")
return
H,W,N = list(map(int,input().split()))
M = defaultdict(int)
visited = defaultdict(int)
ab = []
for _ in range(N):
a,b = list(map(int,input().split()))
ab.append((a-1,b-1))
M[(a-1,b-1)] = 1
vector = [(0,1),(0,-1),(1,0),(-1,0),(1,1),(-1,-1),(1,-1),(-1,1)]
num = [0]*10
for a,b in ab:
dfs(a,b,"b")
num[0] = (H-2)*(W-2) - sum(num)
for i in num:
print(i) | """
参考(神様)
https://atcoder.jp/contests/abc045/submissions/6046010
"""
###かぶるやつを考える.例えばあるマスのかぶり値が9だとしたら,
###周囲はすべて黒->j=9のが1つとカウントしてよい,他の値についても同様.
import sys
from collections import defaultdict,Counter
def input():
return sys.stdin.readline().strip()
H,W,N = list(map(int,input().split()))
covered = defaultdict(int)
vector = [(0,0),(0,1),(0,-1),(1,0),(-1,0),(1,1),(-1,-1),(1,-1),(-1,1)]
for _ in range(N):
a,b = list(map(int,input().split()))
for i,j in vector:
x = a+i-1
y = b+j-1
if 0 < x < H-1 and 0 < y < W-1:
covered[(x,y)] += 1
num = Counter(list(covered.values()))
##print(num)
num[0] = (H-2)*(W-2)-sum(num.values())
for i in range(10):
print((num[i])) | p04000 |
"""
参考(神様)
https://atcoder.jp/contests/abc045/submissions/6046010
"""
###かぶるやつを考える.例えばあるマスのかぶり値が9だとしたら,
###周囲はすべて黒->j=9のが1つとカウントしてよい,他の値についても同様.
import sys
from collections import defaultdict,Counter
def input():
return sys.stdin.readline().strip()
H,W,N = list(map(int,input().split()))
covered = defaultdict(int)
vector = [(0,0),(0,1),(0,-1),(1,0),(-1,0),(1,1),(-1,-1),(1,-1),(-1,1)]
for _ in range(N):
a,b = list(map(int,input().split()))
for i,j in vector:
x = a+i-1
y = b+j-1
if 0 < x < H-1 and 0 < y < W-1:
covered[(x,y)] += 1
num = Counter(list(covered.values()))
##print(num)
num[0] = (H-2)*(W-2)-sum(num.values())
for i in range(10):
print((num[i])) | from collections import defaultdict
from itertools import product
H,W,N = list(map(int,input().split()))
covered = defaultdict(int)
vector = [[-1,-1],[-1,0],[-1,1],[1,0],[1,1],[0,0],[0,-1],[0,1],[1,-1]]
for _ in range(N):
a,b = list(map(int,input().split()))
for dx,dy in vector:
x = a+dx-1
y = b+dy-1
if 1 <= x < H-1 and 1 <= y < W-1:
covered[(x,y)] += 1
values = [0]*10
for i in list(covered.values()):
values[i] += 1
values[0] = (H-2)*(W-2) - sum(values)
for v in values:
print(v)
| p04000 |
h,w,n=list(map(int,input().split()))
ab=[list(map(int,input().split())) for _ in [0]*n]
ab_d={a*(10**6)+b for a,b in ab}
ans=[set() for _ in range(9)]
for a,b in ab:
temp=[[2 for _ in [0]*5] for _ in [0]*5]
for i in range(5):
for j in range(5):
if 0<a+i-2<=h and 0<b+j-2<=w:
if (a+i-2)*(10**6)+b+j-2 in ab_d:
temp[i][j]=1
else:
temp[i][j]=0
for i in range(3):
for j in range(3):
cnt=[temp[i+k][j+l] for k in range(3) for l in range(3)]
if 2 not in cnt:
ans[sum(cnt)-1].add((a+i-2)*(10**6)+b+j-2)
for i in range(9):
ans[i]=len(ans[i])
print(((h-2)*(w-2)-sum(ans)))
for i in ans:
print(i) | h,w,n=list(map(int,input().split()))
ab=[list(map(int,input().split())) for _ in [0]*n]
ab_d={a*(10**10)+b for a,b in ab}
ans=[set() for _ in range(9)]
for a,b in ab:
temp=[None for _ in [0]*25]
for i in range(5):
for j in range(5):
if 0<a+i-2<=h and 0<b+j-2<=w:
if (a+i-2)*(10**10)+b+j-2 in ab_d:
temp[i*5+j]=1
else:
temp[i*5+j]=0
for i in range(3):
for j in range(3):
cnt=[temp[(i+k)*5+j+l] for k in range(3) for l in range(3)]
if None not in cnt:
ans[sum(cnt)-1].add((a+i-2)*(10**10)+b+j-2)
for i in range(9):
ans[i]=len(ans[i])
print(((h-2)*(w-2)-sum(ans)))
for i in ans:
print(i) | p04000 |
h,w,n=list(map(int,input().split()))
jl=[0]*10
ab=[]
if n==0:
print(((w-2)*(h-2)))
for i in range(9):
print((0))
exit()
for i in range(n):
a,b=list(map(int,input().split()))
a-=1
b-=1
for j in range(max(0,b-2),min(w-2,b+1)):
for k in range(max(0,a-2),min(h-2,a+1)):
ab=ab+[[k,j]]
ab.sort(key=lambda x: x[1])
ab.sort()
flag=False
count=1
now=ab[0]
for i in ab[1:]:
if i==now:
count+=1
else:
jl[count]+=1
count=1
now=i
jl[count]+=1
jl[0]=(h-2)*(w-2)-sum(jl[1:])
for i in range(10):
print((jl[i])) | h,w,n=list(map(int,input().split()))
jl=[0]*10
cnt={}
if n==0:
print(((w-2)*(h-2)))
for i in range(9):
print((0))
exit()
for i in range(n):
a,b=list(map(int,input().split()))
a-=1
b-=1
for j in range(max(0,b-2),min(w-2,b+1)):
for k in range(max(0,a-2),min(h-2,a+1)):
if (k, j) in cnt:
cnt[(k, j)]+=1
else:
cnt[(k, j)]=1
jl[0]=(h-2)*(w-2)
for i in list(cnt.values()):
jl[0]-=1
jl[i]+=1
for i in jl:
print(i) | p04000 |
from collections import defaultdict
def main():
H, W, N = map(int, input().split())
d = defaultdict(int)
for _ in range(N):
a, b = map(int, input().split())
for y in range(-2, 1):
for x in range(-2, 1):
n_y, n_x = y + a, x + b
if 0 < n_y <= H - 2 and 0 < n_x <= W - 2:
d[(n_y, n_x)] += 1
ans = [0] * 10
for k, v in d.items():
ans[v] += 1
ans[0] = (H - 2) * (W - 2) - sum(ans)
print(*ans, sep="\n")
if __name__ == '__main__':
main()
| from collections import defaultdict
def main():
H, W, N = map(int, input().split())
d = defaultdict(int)
for _ in range(N):
a, b = map(int, input().split())
a, b = a - 1, b - 1
for y in range(-2, 1):
for x in range(-2, 1):
ny, nx = a + y, b + x
if 0 <= ny < H - 2 and 0 <= nx < W - 2:
d[(ny, nx)] += 1
ans = [0] * 10
for v in d.values():
ans[v] += 1
ans[0] = (H - 2) * (W - 2) - sum(ans)
print(*ans, sep="\n")
if __name__ == '__main__':
main()
| p04000 |
from collections import Counter
H, W, N, *AB = list(map(int, open(0).read().split()))
C = Counter()
for a, b in zip(*[iter(AB)] * 2):
C.update(
(a - i, b - j)
for i in range(-1, 2) for j in range(-1, 2)
if 2 <= a - i <= H - 1 and 2 <= b - j <= W - 1
)
D = Counter(v for _, v in list(C.items()))
print(((H - 2) * (W - 2) - sum(D.values())))
for i in range(1, 10):
print((D[i]))
| from collections import Counter
from itertools import product
H, W, N, *AB = list(map(int, open(0).read().split()))
C = Counter()
for a, b in zip(*[iter(AB)] * 2):
C.update(
(a - i, b - j)
for i, j in product((-1, 0, 1), repeat=2)
if 2 <= a - i <= H - 1 and 2 <= b - j <= W - 1
)
D = Counter(v for _, v in list(C.items()))
print(((H - 2) * (W - 2) - sum(D.values())))
for i in range(1, 10):
print((D[i]))
| p04000 |
from collections import Counter
from itertools import product
H, W, N, *AB = list(map(int, open(0).read().split()))
move = [
(-1, -1), (-1, 0), (-1, 1),
(0, -1), (0, 0), (0, 1),
(1, -1), (1, 0), (1, 1),
]
C = Counter()
for a, b in zip(*[iter(AB)] * 2):
C.update(
(a - i, b - j)
for i, j in move
if 2 <= a - i <= H - 1 and 2 <= b - j <= W - 1
)
D = Counter(v for _, v in list(C.items()))
print(((H - 2) * (W - 2) - sum(D.values())))
for i in range(1, 10):
print((D[i]))
| from collections import Counter
H, W, N, *AB = list(map(int, open(0).read().split()))
move = [
(-1, -1), (-1, 0), (-1, 1),
(0, -1), (0, 0), (0, 1),
(1, -1), (1, 0), (1, 1),
]
C = Counter()
for a, b in zip(*[iter(AB)] * 2):
C.update(
(a - i, b - j)
for i, j in move
if 2 <= a - i <= H - 1 and 2 <= b - j <= W - 1
)
D = Counter(v for _, v in list(C.items()))
print(((H - 2) * (W - 2) - sum(D.values())))
for i in range(1, 10):
print((D[i]))
| p04000 |
from collections import Counter
H, W, N, *AB = list(map(int, open(0).read().split()))
move = [
(-1, -1), (-1, 0), (-1, 1),
(0, -1), (0, 0), (0, 1),
(1, -1), (1, 0), (1, 1),
]
C = Counter()
for a, b in zip(*[iter(AB)] * 2):
C.update(
(a - i, b - j)
for i, j in move
if 2 <= a - i <= H - 1 and 2 <= b - j <= W - 1
)
D = [0] * 10
for v in list(C.values()):
D[v] += 1
D[0] = (H - 2) * (W - 2) - len(C)
print(("\n".join(map(str, D))))
| from collections import Counter
H, W, N, *AB = list(map(int, open(0).read().split()))
move = [
(-1, -1), (-1, 0), (-1, 1),
(0, -1), (0, 0), (0, 1),
(1, -1), (1, 0), (1, 1),
]
C = Counter()
for a, b in zip(*[iter(AB)] * 2):
C.update(
(a - i, b - j)
for i, j in move
if 2 <= a - i <= H - 1 and 2 <= b - j <= W - 1
)
D = [0] * 10
for v in list(C.values()):
D[v] += 1
D[0] = (H - 2) * (W - 2) - len(C)
for d in D:
print(d)
| p04000 |
import itertools
from collections import defaultdict
H,W,N=list(map(int, input().split()))
d=[-1,0,1]
D=list(itertools.product(d,d))
C=set() #Center
A=defaultdict(lambda: 0)
for i in range(N):
a,b=list(map(int, input().split()))
A[(a,b)]=1
for dx,dy in D:
cx=a+dx
cy=b+dy
if cx>=2 and cx<=H-1 and cy>=2 and cy<=W-1:
C.add( (cx,cy) )
l=defaultdict(lambda: 0)
for x,y in C:
cnt=0
for i,j in D:
if A[(x+i,y+j)]==1:
cnt+=1
l[cnt]+=1
for i in range(10):
if i==0:
print((H-2)*(W-2)-sum(l.values()))
else:
print(l[i])
| import itertools
from collections import defaultdict
from collections import Counter
H,W,N=list(map(int, input().split()))
d=[-1,0,1]
D=list(itertools.product(d,d))
A=defaultdict(lambda: 0)
for i in range(N):
a,b=list(map(int, input().split()))
for dx,dy in D:
cx=a+dx
cy=b+dy
if cx>=2 and cx<=H-1 and cy>=2 and cy<=W-1:
A[(cx,cy)]+=1
C=Counter(list(A.values()))
for i in range(10):
if i==0:
print((H-2)*(W-2)-sum(C.values()))
else:
print(C[i])
| p04000 |
H,W,N = list(map(int,input().split()))
Nli=[]
for k in range(N):
a,b=list(map(int,input().split()))
for n in range(-1,2):
for m in range(-1,2):
if 0<=a-2-m<H-2 and 0<=b-2-n<W-2:
Nli.append((b-n)*(H)+(a-m))
import collections
s = collections.Counter(Nli)
v = list(s.values())
print(((H-2)*(W-2)-len(set(Nli))))
for k in range(1,10):
print((v.count(k))) | H,W,N = list(map(int,input().split()))
Nli=[0 for j in range(9*N)]
q=0
for k in range(N):
a,b=list(map(int,input().split()))
for n in range(-1,2):
for m in range(-1,2):
if 0<=a-2-m<H-2 and 0<=b-2-n<W-2:
Nli[q]=(b-n)*(H)+(a-m)
q+=1
del Nli[q:]
import collections
s = collections.Counter(Nli)
v = list(s.values())
print(((H-2)*(W-2)-len(set(Nli))))
for k in range(1,10):
print((v.count(k))) | p04000 |
H,W,N = list(map(int,input().split()))
from collections import defaultdict
t =defaultdict(int)
L = defaultdict(int)
for i in range(N):
a,b = list(map(int,input().split()))
t[(a-1,b-1)] = 1
for p in [-1,0,1]:
for q in [-1,0,1]:
if a+p < 2 or b+q < 2 or a+p >H-1 or b+q >W-1:
continue
L[(a+p-1,b+q-1)] = 1
ans = [0]*10
for k in list(L.keys()):
a,b = k[0],k[1]
if a < 1 or b < 1 or a >H-2 or b >W-2:
continue
c = 0
for p in [-1,0,1]:
for q in [-1,0,1]:
c +=t[(a+p,b+q)]
ans[c] += 1
ans[0] = (H-2)*(W-2) - sum(ans)
for i in range(10):
print((ans[i]))
| H,W,N = list(map(int,input().split()))
from collections import defaultdict
t =defaultdict(int)
L = defaultdict(int)
for i in range(N):
a,b = list(map(int,input().split()))
t[(a-1,b-1)] = 1
for p in [-1,0,1]:
for q in [-1,0,1]:
if a+p < 2 or b+q < 2 or a+p >H-1 or b+q >W-1:
continue
L[(a+p-1,b+q-1)] += 1
ans = [0]*10
for v in list(L.values()):
ans[v] += 1
ans[0] = (H-2)*(W-2) - sum(ans)
for i in range(10):
print((ans[i]))
| p04000 |
H,W,N = list(map(int,input().split()))
from collections import defaultdict
t =defaultdict(int)
L = defaultdict(int)
for i in range(N):
a,b = list(map(int,input().split()))
t[(a-1,b-1)] = 1
for p in [-1,0,1]:
for q in [-1,0,1]:
if a+p < 2 or b+q < 2 or a+p >H-1 or b+q >W-1:
continue
L[(a+p-1,b+q-1)] += 1
ans = [0]*10
for v in list(L.values()):
ans[v] += 1
ans[0] = (H-2)*(W-2) - sum(ans)
for i in range(10):
print((ans[i]))
| H,W,N = list(map(int,input().split()))
from collections import defaultdict
L = defaultdict(int)
for i in range(N):
a,b = list(map(int,input().split()))
for p in [-1,0,1]:
for q in [-1,0,1]:
if a+p < 2 or b+q < 2 or a+p >H-1 or b+q >W-1:
continue
L[(a+p-1,b+q-1)] += 1
ans = [0]*10
for v in list(L.values()):
ans[v] += 1
ans[0] = (H-2)*(W-2) - sum(ans)
for i in range(10):
print((ans[i]))
| p04000 |
H,W,N = list(map(int,input().split()))
from collections import defaultdict
L = defaultdict(int)
for i in range(N):
a,b = list(map(int,input().split()))
for p in [-1,0,1]:
for q in [-1,0,1]:
if a+p < 2 or b+q < 2 or a+p >H-1 or b+q >W-1:
continue
L[(a+p-1,b+q-1)] += 1
ans = [0]*10
for v in list(L.values()):
ans[v] += 1
ans[0] = (H-2)*(W-2) - sum(ans)
for i in range(10):
print((ans[i]))
| H,W,N = list(map(int,input().split()))
from collections import defaultdict
L = defaultdict(int)
#黒く塗りつぶしたマスとその周りだけ探索すればよい
for i in range(N):
a,b = list(map(int,input().split()))
for p in [-1,0,1]:
for q in [-1,0,1]:
if a+p < 2 or b+q < 2 or a+p >H-1 or b+q >W-1:
continue
L[(a+p-1,b+q-1)] += 1
ans = [0]*10
for v in list(L.values()):
ans[v] += 1
ans[0] = (H-2)*(W-2) - sum(ans)
for i in range(10):
print((ans[i]))
| p04000 |
H, W, N = list(map(int, input().split()))
graph = {}
for _ in range(N):
a, b = list(map(int, input().split()))
for i in [-1, 0, 1]:
for j in [-1, 0, 1]:
na, nb = a-1+i, b-1+j
if 1 <= na <= H-2 and 1 <= nb <= W-2:
if not graph.get(na, False):
graph[na] = {nb: 1}
elif not graph[na].get(nb, False):
graph[na][nb] = 1
else:
graph[na][nb] += 1
#print(graph)
ans = [0 for _ in range(10)]
S = 0
for a, v_graph in list(graph.items()):
for b, v in list(v_graph.items()):
ans[v] += 1
S += 1
ans[0] = (H-2)*(W-2) - S
for a in ans:
print(a) | H, W, N = list(map(int, input().split()))
graph = {}
for _ in range(N):
a, b = list(map(int, input().split()))
for i in [-1, 0, 1]:
for j in [-1, 0, 1]:
na, nb = a-1+i, b-1+j
if 1 <= na <= H-2 and 1 <= nb <= W-2:
if not na in list(graph.keys()):
graph[na] = {nb: 1}
elif not nb in list(graph[na].keys()):
graph[na][nb] = 1
else:
graph[na][nb] += 1
#print(graph)
ans = [0 for _ in range(10)]
S = 0
for a, v_graph in list(graph.items()):
for b, v in list(v_graph.items()):
ans[v] += 1
S += 1
ans[0] = (H-2)*(W-2) - S
for a in ans:
print(a) | p04000 |
import sys
import bisect
import collections
import fractions
import heapq
import math
from operator import mul
from functools import reduce
from functools import lru_cache
def slove():
input = sys.stdin.readline
mod = 10 ** 9 + 7
h, w, n = list(map(int, input().rstrip('\n').split()))
d = collections.defaultdict(int)
for i in range(n):
a, b = list(map(int, input().rstrip('\n').split()))
a -= 1
b -= 1
for j in range(max(1, a - 1), min(h-1, a + 2)):
for k in range(max(1, b - 1), min(w-1, b + 2)):
d[j, k] += 1
ls = [0] * 10
for k, v in sorted(list(d.items()), key=lambda x: x[1]):
ls[v] += 1
ls[0] = (h - 3 + 1) * (w - 3 + 1) - sum(ls)
for i in range(10):
print((ls[i]))
if __name__ == '__main__':
slove()
| import sys
import collections
def solve():
sys.setrecursionlimit(2000)
input = sys.stdin.readline
mod = 10 ** 9 + 7
h, w, n = list(map(int, input().rstrip('\n').split()))
d = collections.defaultdict(int)
for _ in range(n):
a, b = list(map(int, input().rstrip('\n').split()))
for i in range(-1, 2):
for j in range(-1, 2):
if 1 <= a-1+i < h-1 and 1 <= b-1+j < w-1:
d[a-1+i, b-1+j] += 1
nd = []
for k, v in list(d.items()):
nd.append(v)
nd = collections.Counter(nd)
print(((h - 2) * (w - 2) - sum(nd.values())))
for i in range(1, 10):
print((nd[i]))
if __name__ == '__main__':
solve()
| p04000 |
from collections import Counter
H,W,N = map(int,input().split())
src = [tuple(map(int,input().split())) for i in range(N)]
blacks = Counter()
for y,x in src:
for i in range(-1,2):
if not 0 <= y+i < H: continue
for j in range(-1,2):
if not 0 <= x+j < W: continue
blacks[(x+j, y+i)] += 1
ans = [0] * 10
for (x,y),v in blacks.items():
if x<2 or y<2: continue
ans[v] += 1
ans[0] = (H-2)*(W-2) - sum(ans[1:])
print(*ans,sep='\n')
| import sys
input = sys.stdin.readline
H,W,N = map(int,input().split())
AB = [tuple(map(int,input().split())) for i in range(N)]
from collections import defaultdict
dic = defaultdict(lambda: 0)
for y,x in AB:
for dx in range(-1,2):
for dy in range(-1,2):
nx,ny = x+dx,y+dy
if not 1 <= nx <= W: continue
if not 1 <= ny <= H: continue
dic[(nx,ny)] += 1
ans = [0] * 10
for (x,y),c in dic.items():
if x==1 or x==W or y==1 or y==H: continue
ans[c] += 1
s = sum(ans)
ans[0] = (W-2)*(H-2)-s
print(*ans, sep='\n')
| p04000 |
import math
H, W, N = list(map(int, input().split()))
count = [0]*10
count[0] = (H-2)*(W-2)
rectmap=[]
#print(board)
for i in range(0,N):
a, b = input().split()
a = int(a)
b = int(b)
al = max(a-1, 2)
au = min(a+2, H)
bl = max(b-1, 2)
bu = min(b+2, W)
for j in range(al, au):
for k in range(bl, bu):
rectmap.append([j-1, k-1])
## for j in range(a-1, a+2):
## for k in range(b-1, b+2):
## if j>1 and j<H and k>1 and k<W:
## rectmap.append([j-1, k-1])
#print(rectmap)
rectmap.sort()
while len(rectmap)!=0 :
c = rectmap.count(rectmap[0])
del rectmap[:c]
count[c]+=1
count[0]-=1
for i in range(0, 10):
print((count[i]))
#print(H,W,N)
#print(ab)
| import math
H, W, N = list(map(int, input().split()))
count = [0]*10
count[0] = (H-2)*(W-2)
rectmap={}
#print(board)
for i in range(0,N):
a, b = input().split()
a = int(a)
b = int(b)
ab = (a, b)
al = max(a-1, 2)
au = min(a+2, H)
bl = max(b-1, 2)
bu = min(b+2, W)
for j in range(al, au):
for k in range(bl, bu):
if (j,k) in rectmap:
rectmap[(j,k)] +=1
else:
rectmap[(j,k)] = 1
# print(rectmap)
## for j in range(a-1, a+2):
## for k in range(b-1, b+2):
## if j>1 and j<H and k>1 and k<W:
## rectmap.append([j-1, k-1])
#print(rectmap)
for i in list(rectmap.values()):
count[i]+=1
count[0]-=1
for c in count:
print(c)
#print(H,W,N)
#print(ab)
| p04000 |
from collections import Counter
h, w, n = [int(i) for i in input().split()]
cnt = Counter()
vs = []
for i in range(-1, 2):
for j in range(-1, 2):
vs.append((i,j))
for _ in range(n):
a, b = [int(i) for i in input().split()]
for v in vs:
aa = a + v[0]
bb = b + v[1]
if 2<=aa<=h-1 and 2<=bb<=w-1:
cnt.update([(aa, bb)])
cnt2 = [0] * 10
cnt2[0] = (h-2)*(w-2)
for k in cnt:
c = cnt[k]
cnt2[c] += 1
cnt2[0] -= 1
for i in cnt2:
print(i)
| from collections import Counter
h, w, n = [int(i) for i in input().split()]
vs = []
for i in range(-1, 2):
for j in range(-1, 2):
vs.append((i,j))
cnt = []
for _ in range(n):
a, b = [int(i) for i in input().split()]
for v in vs:
aa = a + v[0]
bb = b + v[1]
if 2<=aa<=(h-1) and 2<=bb<=(w-1):
cnt.append(aa*w+bb)
cnt = Counter(cnt)
cnt2 = [0] * 10
cnt2[0] = (h-2)*(w-2)
for k in cnt:
c = cnt[k]
cnt2[c] += 1
cnt2[0] -= 1
for i in cnt2:
print(i)
| p04000 |
from collections import defaultdict as dd
H,W,N=list(map(int,input().split()))
ab = [tuple(map(int,input().split())) for _ in range(N)]
tpl = [(-1,-1),(-1,0),(-1,1),(0,-1),(0,0),(0,1),(1,-1),(1,0),(1,1)]
edge_WtoB = dd(list)
edge_BtoB = dd(list)
node_B = set(ab)
node_W = set()
res = dd(int)
# 今見てるマスが黒
for a,b in ab:
for s,t in tpl:
tgt = (a+s,b+t)
# 隣接マスも黒
if tgt in node_B:
if not (1 < a < H and 1 < b < W):
continue
edge_BtoB[(a,b)].append(tgt)
# 隣接マスは白
else:
if not (1 < a + s < H and 1 < b + t < W):
continue
edge_WtoB[tgt].append((a,b))
node_W.add(tgt)
for tgt in node_W:
res[len(edge_WtoB[tgt])] += 1
for tgt in node_B:
res[len(edge_BtoB[tgt])] += 1
zero = (H-2)*(W-2)
for j in range(1,10):
zero -= res[j]
res[0] = zero
for j in range(10):
print((res[j])) | from collections import defaultdict as dd
H,W,N=list(map(int,input().split()))
ab = [tuple(map(int,input().split())) for _ in range(N)]
tpl = [(-1,-1),(-1,0),(-1,1),(0,-1),(0,0),(0,1),(1,-1),(1,0),(1,1)]
edge_WtoB = dd(int)
edge_BtoB = dd(int)
node_B = set(ab)
# node_W = set()
res = dd(int)
# 今見てるマスが黒
for a,b in ab:
for s,t in tpl:
tgt = (a+s,b+t)
# 隣接マスも黒
if tgt in node_B:
if not (1 < a < H and 1 < b < W):
continue
edge_BtoB[(a,b)] += 1
# 隣接マスは白
else:
if not (1 < a + s < H and 1 < b + t < W):
continue
edge_WtoB[tgt] += 1
# node_W.add(tgt)
for val in list(edge_WtoB.values()):
res[val] += 1
for val in list(edge_BtoB.values()):
res[val] += 1
zero = (H-2)*(W-2)
for j in range(1,10):
zero -= res[j]
res[0] = zero
for j in range(10):
print((res[j])) | p04000 |
pos_black_mapping = {}
pos_num_mapping = {}
H, W, N = list(map(int, input().split()))
for i in range(N):
a, b = list(map(int, input().split()))
a, b = a-1, b-1
pos_black_mapping[a, b] = 1
for dy in range(-2, 3):
for dx in range(-2, 3):
na, nb = a+dx, b+dy
if (0 <= na < H-2) and (0 <= nb < W-2):
pos_num_mapping[na, nb] = 1
ans = [0 for _ in range(10)]
for a, b in list(pos_num_mapping.keys()):
cnt = 0
for dy in range(3):
for dx in range(3):
na, nb = a+dx, b+dy
if (na, nb) in pos_black_mapping:
cnt += 1
ans[cnt] += 1
ans[0] = (W-2)*(H-2) - sum(ans[1:])
for v in ans:
print(v) | pos_black_mapping = {}
pos_num_mapping = {}
H, W, N = list(map(int, input().split()))
for i in range(N):
a, b = list(map(int, input().split()))
a, b = a-1, b-1
if (a, b) in pos_black_mapping:
continue
pos_black_mapping[a, b] = 1
for da in range(-1, 2):
for db in range(-1, 2):
na, nb = a+da, b+db
if (0 < na < H-1) and (0 < nb < W-1):
if not (na, nb) in pos_num_mapping:
pos_num_mapping[na, nb] = 0
pos_num_mapping[na, nb] += 1
ans = [0 for _ in range(10)]
for a, b in list(pos_num_mapping.keys()):
ans[pos_num_mapping[a, b]] += 1
ans[0] = (W-2)*(H-2) - sum(ans[1:])
for v in ans:
print(v) | p04000 |
import collections
h, w, n = list(map(int, input().split()))
pos = collections.defaultdict(lambda: collections.defaultdict(bool))
squares = collections.defaultdict(lambda: collections.defaultdict(bool))
for index in range(n):
a, b = list(map(int, input().split()))
a -= 1
b -= 1
pos[a][b] = True
for i in range(-2, 1):
for j in range(-2, 1):
y = a + i
x = b + j
if 0 <= x < w - 2 and 0 <= y < h - 2:
squares[y][x] = True
counter = collections.Counter()
for y, xs in list(squares.items()):
for x in xs:
count = 0
for i in range(3):
for j in range(3):
if pos[y + i][x + j]:
count += 1
counter[count] += 1
print(((h - 2) * (w - 2) - sum(counter.values())))
for i in range(1, 10):
print((counter[i])) | import collections
h, w, n = list(map(int, input().split()))
squares = collections.defaultdict(lambda: collections.defaultdict(int))
for index in range(n):
a, b = list(map(int, input().split()))
a -= 1
b -= 1
for i in range(-2, 1):
for j in range(-2, 1):
y = a + i
x = b + j
if 0 <= x < w - 2 and 0 <= y < h - 2:
squares[y][x] += 1
counter = collections.Counter()
for y, xs in list(squares.items()):
for x, count in list(xs.items()):
counter[count] += 1
print(((h - 2) * (w - 2) - sum(counter.values())))
for i in range(1, 10):
print((counter[i])) | p04000 |
import sys
from collections import defaultdict
input = sys.stdin.readline
H, W, N = list(map(int, input().split()))
board = defaultdict(int)
black = []
for _ in range(N):
a, b = list(map(int, input().split()))
black.append((a - 1, b - 1))
board[(a-1) * 10 ** 10 + (b - 1)] = 1
num = [0] * 10
for p in black:
for ch in range(max(p[0] - 1, 1), min(p[0] + 2, H - 1)):
for cw in range(max(p[1] - 1, 1), min(p[1] + 2, W - 1)):
count = 0
for h in range(ch - 1, ch + 2):
for w in range(cw - 1, cw + 2):
if board[h * 10 ** 10 + w] == 1:
count += 1
num[count] += 1
for i in range(1, 10):
num[i] //= i
print(((H - 2) * (W - 2) - sum(num)))
for i in range(1, 10):
print((num[i]))
| import sys
from collections import defaultdict
input = sys.stdin.readline
H, W, N = list(map(int, input().split()))
board = defaultdict(int)
black = []
for _ in range(N):
a, b = list(map(int, input().split()))
black.append((a - 1, b - 1))
board[(a-1) * W + (b - 1)] = 1
num = [0] * 10
for p in black:
for ch in range(max(p[0] - 1, 1), min(p[0] + 2, H - 1)):
for cw in range(max(p[1] - 1, 1), min(p[1] + 2, W - 1)):
count = 0
for h in range(ch - 1, ch + 2):
for w in range(cw - 1, cw + 2):
if board[h * W + w] == 1:
count += 1
num[count] += 1
for i in range(1, 10):
num[i] //= i
print(((H - 2) * (W - 2) - sum(num)))
for i in range(1, 10):
print((num[i]))
| p04000 |
from collections import defaultdict
H, W, N = list(map(int,input().split()))
ans =[(H-2)*(W-2)]+[0]*9
blacks = defaultdict(int)
for i in range(N):
a, b = list(map(int,input().split()))
for dx in [-1,0,1]:
for dy in [-1,0,1]:
if 2 <= a+dx <H and 2 <= b+dy <W:
ans[blacks[(a+dx,b+dy)]]-=1
ans[blacks[(a+dx,b+dy)]+1]+=1
blacks[(a+dx,b+dy)]+=1
for i in range(10): print((ans[i]))
| h,w,n=list(map(int,input().split()))
dic={}
dx=[-2,-1,0]
dy=[-2,-1,0]
ans=[0]*10
for _ in range(n):
a,b=list(map(int,input().split()))
for x in dx:
for y in dy:
if 1<=a+y and a+y+2<=h and 1<=b+x and b+x+2<=w:
if (a+y,b+x) not in dic:
dic[(a+y,b+x)]=1
else:
dic[(a+y,b+x)]+=1
ans[0]=(h-2)*(w-2)-len(dic)
for v in list(dic.values()):
ans[v]+=1
for i in range(10):
print((ans[i]))
| p04000 |
H, W, N = map(int, input().split())
ab = set(tuple(map(int, input().split())) for i in range(N))
dxy = {0:[0, 1, 2], 1:[-1, 0, 1], 2:[-2, -1, 0]}
num_all = (H - 2) * (W - 2)
num = [0] * 10
for a, b in ab:
for i in range(3):
Da = dxy[i]
for j in range(3):
n = 0
flag = False
Db = dxy[j]
for da in Da:
aa = a + da
for db in Db:
bb = b + db
if aa < 1 or H < aa or bb < 1 or W < bb:
flag = True
break
if (aa, bb) in ab:
n += 1
if flag:
break
if flag:
continue
num[n] += 1
for i in range(2, 10):
num[i] //= i
num[0] = num_all - sum(num[1:])
print(*num, sep='\n')
| import sys
input = sys.stdin.readline
H, W, N = map(int, input().split())
ab = set(tuple(map(int, input().split())) for i in range(N))
dxy = {0:[0, 1, 2], 1:[-1, 0, 1], 2:[-2, -1, 0]}
num_all = (H - 2) * (W - 2)
num = [0] * 10
for a, b in ab:
for i in range(3):
Da = dxy[i]
for j in range(3):
n = 0
flag = False
Db = dxy[j]
for da in Da:
aa = a + da
for db in Db:
bb = b + db
if aa < 1 or H < aa or bb < 1 or W < bb:
flag = True
break
if (aa, bb) in ab:
n += 1
if flag:
break
if flag:
continue
num[n] += 1
for i in range(2, 10):
num[i] //= i
num[0] = num_all - sum(num[1:])
print(*num, sep='\n')
| p04000 |
from collections import Counter
h,w,n = list(map(int,input().split()))
need = []
for i in range(n):
a,b = list(map(int,input().split()))
for x in range(-2,1):
for y in range(-2,1):
s = a + x
t = b + y
if 1 <= s <= h-2 and 1 <= t <= w-2:
need.append(s*10**10 + t)
data = Counter(need).most_common()
ans = [0 for i in range(10)]
for x,y in data:
ans[y] += 1
print(((h-2)*(w-2)-sum(ans)))
for i in ans[1:]:
print(i)
| from collections import Counter
h,w,n = list(map(int,input().split()))
need = []
append = need.append
for i in range(n):
a,b = list(map(int,input().split()))
for x in range(-2,1):
for y in range(-2,1):
s = a + x
t = b + y
if 1 <= s <= h-2 and 1 <= t <= w-2:
append(s*10**10 + t)
data = Counter(need).most_common()
ans = [0 for i in range(10)]
for x,y in data:
ans[y] += 1
print(((h-2)*(w-2)-sum(ans)))
for i in ans[1:]:
print(i) | p04000 |
def solve(h,w,n,black_list):
idx_list = []
for idx, (a,b) in enumerate(black_list):
left = max(0, b-3)
top = max(0, a-3)
for row in range(top, a):
if row+2 >= h:
continue
for col in range(left, b):
if col+2 >= w:
continue
idx_list.append(row*h+col)
set_count = set(idx_list)
ans = [0]*len(set_count)
for idx,i in enumerate(set_count):
ans[idx] = idx_list.count(i)
ret = [(h-2)*(w-2)-len(set_count)]
for i in range(1, 10):
ret.append(ans.count(i))
return ret
if __name__ == "__main__":
h,w,n = list(map(int,input().split()))
black_list = [tuple(map(int,input().split())) for _ in range(n)]
ret = solve(h,w,n,black_list)
for i in ret:
print(i)
| def solve(h,w,n,black_list):
if len(black_list) == 0:
return [(h-2)*(w-2)]+[0]*9
idx_list = []
for idx, (a,b) in enumerate(black_list):
left = max(0, b-3)
top = max(0, a-3)
for row in range(top, a):
if row+2 >= h:
continue
for col in range(left, b):
if col+2 >= w:
continue
idx_list.append(row*w+col)
set_count = set(idx_list)
idx_list = sorted(idx_list)
ans = [0]*9
now = idx_list[0]
count = 0
for item in idx_list:
if item == now:
count += 1
else:
now = item
if count == 10:
print(item)
ans[count-1] += 1
count = 1
ans[count-1] += 1
return [(h-2)*(w-2)-len(set_count)]+ans
if __name__ == "__main__":
h,w,n = list(map(int,input().split()))
black_list = [tuple(map(int,input().split())) for _ in range(n)]
ret = solve(h,w,n,black_list)
for i in ret:
print(i)
| p04000 |
n = int(input())
s = input()
uppercase = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
t = ''
for ch in s:
ind = uppercase.index(ch)
ind = (ind + n) % 26
t += uppercase[ind]
print(t) | s = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
n= int(input())
x = input()
a = ord('A')
print(''.join([s[(ord(c) - a + n) % 26] for c in x])) | p02848 |
# 2019-11-24 20:59:47(JST)
import sys
from string import ascii_uppercase as alphabet
alpha_num = dict((alpha, num) for num, alpha in enumerate(alphabet, 0))
def main():
n, s = sys.stdin.read().split()
n = int(n)
t = ''
for char in s:
t += alphabet[(alpha_num[char] + n) % 26]
print(t)
if __name__ == '__main__':
main()
| # 2019-11-24 20:59:47(JST)
import sys
from string import ascii_uppercase as alphabet
# alpha_num = dict((alpha, num) for num, alpha in enumerate(alphabet, 0))
alpha_ind = dict((alphabet[i], i) for i in range(26))
def main():
n, s = sys.stdin.read().split()
n = int(n)
t = ''
for char in s:
t += alphabet[(alpha_ind[char] + n) % 26]
print(t)
if __name__ == '__main__':
main()
| p02848 |
"""
author : halo2halo
date : 8, Jan, 2020
"""
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)
word = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
N = int(readline())
S = readline().decode('utf8').rstrip()
ans = [None] * len(S)
for i in range(len(S)):
ans[i] = word[(word.index(S[i]) + N) % len(word)]
ans=''.join(ans)
print(ans)
| """
author : halo2halo
date : 8, Jan, 2020
"""
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)
# word = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
N = int(readline())
S = [int(x)-ord('A') for x in read().rstrip()]
S=[(x+N)%26 for x in S]
ans = ''.join(chr(x+ord('A')) for x in S)
print(ans)
| p02848 |
import sys
def solve():
readline = sys.stdin.buffer.readline
mod = 10 ** 9 + 7
n = int(readline())
s = str(readline().rstrip().decode('utf-8'))
al = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
ans = []
for i in range(len(s)):
for j in range(len(al)):
if s[i] == al[j]:
ans.append(al[(j+n) % 26])
break
print(("".join(ans)))
if __name__ == '__main__':
solve()
| import sys
def solve():
readline = sys.stdin.buffer.readline
mod = 10 ** 9 + 7
n = int(readline())
s = str(readline().rstrip().decode('utf-8'))
ls = {i - 65: chr(i) for i in range(65, 91)}
ans = []
for i in range(len(s)):
ans.append(ls[(ord(s[i]) - 65 + n) % 26])
print(("".join(ans)))
if __name__ == '__main__':
solve()
| p02848 |
l = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
n = int(input())
s = input()
for i in s:
k = l.index(i)+n
print(l[k%26], end="")
print("")
| n = int(input())
s = input()
l = [chr(ord("A")+i) for i in range(26)]*2
for i in s:
print(l[l.index(i)+n], end="")
print()
| p02848 |
n = int(eval(input()))
a = []
for i in range(n):
a.append(int(eval(input())))
b = a[1] - a[0]
for i in range(n):
for j in range(i+1 , n):
if b < a[j] - a[i]:
b = a[j] - a[i]
print(b)
| n = int(eval(input()))
a = []
for i in range(n):
a.append(int(eval(input())))
mini = a[0]
b = -10000000000
del a[0]
for i in a:
if b < i - mini:
b = i - mini
if mini > i:
mini = i
print(b)
| p02258 |
n = eval(input())
R = [eval(input())]
Rmin = 0
maxdif = -999999999
for i in range(n-1):
Rt = eval(input())
for j in range(Rmin, len(R)):
if (Rt - R[j]) > maxdif:
maxdif = Rt - R[j]
if Rt < Rmin:
Rmin = i + 1
R.append(Rt)
print(maxdif) | n = eval(input())
R = [eval(input())]
Rmin = 0
maxdif = -999999999
for i in range(n-1):
Rt = eval(input())
for j in range(Rmin, len(R)):
if (Rt - R[j]) > maxdif:
maxdif = Rt - R[j]
if Rt < R[Rmin]:
Rmin = i + 1
R.append(Rt)
print(maxdif) | p02258 |
n = eval(input())
R = [eval(input())]
Rmin = 0
maxdif = -999999999
for i in range(n-1):
Rt = eval(input())
for j in range(Rmin, len(R)):
if (Rt - R[j]) > maxdif:
maxdif = Rt - R[j]
if Rt < R[Rmin]:
Rmin = i + 1
R.append(Rt)
print(maxdif) | n = eval(input())
R = [eval(input()) for i in range(n)]
Rmin = n
maxdif = R[1] - R[0]
while Rmin > 0:
tRmin = R.index(min(R[0:Rmin]))
Rmax = R.index(max(R[tRmin:Rmin]))
if tRmin == Rmax:
if tRmin == n-1:
tRmin-=1
elif tRmin < n-1:
Rmax = tRmin + 1
Rmin = tRmin
if (R[Rmax] - R[Rmin]) > maxdif:
maxdif = R[Rmax] - R[Rmin]
print(maxdif) | p02258 |
#coding:utf-8
n = int(eval(input()))
pri_list = [int(eval(input())) for i in range(n)]
gap_list = []
for i in range(n-1):
gap = max(pri_list[i+1:]) - pri_list[i]
gap_list.append(gap)
max_ben = max(gap_list)
print(max_ben)
| #coding:utf-8
n = int(eval(input()))
minv = int(eval(input()))
maxv = -10000000000
for i in range(n-1):
price = int(eval(input()))
maxv = max([maxv, price - minv])
minv = min([minv, price])
print(maxv)
| p02258 |
n = int(input())
R = list()
max = -10000000000
for i in range(n):
R.append(int(input()))
for j in range(i):
if max < R[i] - R[j]:
max = R[i] - R[j]
print(max) | n = int(input())
R = list()
max = -10000000000
min = 10000000000
for i in range(n):
R.append(int(input()))
if max < R[i] - min:
max = R[i] - min
if min > R[i]:
min = R[i]
print(max)
| p02258 |
n=int(eval(input()))
list=[int(eval(input())) for i in range(n)]
max=list[1]-list[0]
for i in range(n-1,-1,-1):
for j in range(i):
x=list[i]-list[j]
if x>max:
max=x
print(max)
|
n=int(eval(input()))
a=[int(eval(input())) for i in range(n)]
min1=a[0]
max1=-float('inf')
for i in range(1, n):
max1=max(a[i]-min1,max1)
min1=min(a[i],min1)
print(max1)
| p02258 |
i = 1
n = int(eval(input()))
maxR = -10**9
minR = int(eval(input()))
while i < n:
R = int(eval(input()))
maxR = max(maxR, R-minR)
minR = min(minR, R)
i += 1
print(maxR) | a, b = -1e9, 1e10
for n in range(int(eval(input()))):
c = int(eval(input()))
a, b = max(a, c - b), min(b, c)
print(a) | p02258 |
a, b = -1e9, 1e10
for n in range(int(eval(input()))):
c = int(eval(input()))
a, b = max(a, c - b), min(b, c)
print(a) | a = -1e9
b = 2e9
for n in range(int(eval(input()))):
r = int(eval(input()))
a = max(a, r - b)
b = min(b, r)
print(a) | p02258 |
n = eval(input())
n = int(n)
price_list = []
x = eval(input())
x = int(x)
price_list.append(x)
max_profit_candidate = 1 - 10**9
for i in range(n - 1):
x = eval(input())
x = int(x)
diff = x - min(price_list)
if diff > max_profit_candidate:
max_profit_candidate = diff
price_list.append(x)
print(max_profit_candidate) | n = eval(input())
n = int(n)
x = eval(input())
x = int(x)
present_min_value = x
max_profit_candidate = 1 - 10**9
for i in range(n - 1):
a = eval(input())
a = int(a)
diff = a - present_min_value
if diff > max_profit_candidate:
max_profit_candidate = diff
if a < present_min_value:
present_min_value = a
print(max_profit_candidate) | p02258 |
from collections import defaultdict
import math
if __name__ == '__main__' :
n = int(eval(input()))
R = [int(eval(input())) for i in range(n)]
tmp = [max(R[i+1::]) - R[i] for i in range(n-1)]
print((max(tmp)))
| from collections import defaultdict
import math
if __name__ == '__main__' :
n = int(eval(input()))
R = [int(eval(input())) for i in range(n)]
maxv = R[1]-R[0]
minv = min(R[0],R[1])
for j in range(2,n):
maxv = max(maxv,R[j]-minv)
minv = min(minv,R[j])
print(maxv)
| p02258 |
n = int(eval(input()))
prices = [int(eval(input())) for i in range(n)]
ans = 1 - (10 ** 9)
for x in range(n-1):
for y in range(x+1, n):
ans = max(ans, prices[y] - prices[x])
print(ans)
| n = int(eval(input()))
min_v = int(eval(input()))
ans = 1 - min_v
for i in range(1, n):
j = int(eval(input()))
ans = max(ans, j - min_v)
min_v = min(min_v, j)
print(ans)
| p02258 |
N = int(eval(input()))
a = []
for i in range(N):
a.append(int(eval(input())))
max_dist = -10e10
for i in range(N-1):
for j in range(i + 1, N):
if a[j] - a[i] > max_dist:
max_dist = a[j] - a[i]
print(max_dist)
| N = int(eval(input()))
a = []
for i in range(N):
a.append(int(eval(input())))
maxv = -10e10
minv = a[0]
for i in range(1, N):
maxv = a[i] - minv if maxv < a[i] - minv else maxv
minv = a[i] if minv > a[i] else minv
print(maxv)
| p02258 |
#import time
N = int(eval(input()))
datas = [int(eval(input())) for _ in range(N)]
#start = time.time()
now_max = max(datas[1:])
max_index = datas.index(now_max)
diff = now_max - datas[0]
for i in range(1,N-1):
if i == max_index:
d = datas[i+1:]
now_max = max(d)
max_index = d.index(now_max)+i+1
new_diff = now_max - datas[i]
if diff < new_diff:
diff = new_diff
print(diff)
#print('time :',time.time()-start)
| #import time
N = int(eval(input()))
datas = [int(eval(input())) for _ in range(N)]
#start = time.time()
now_max = max(datas[1:])
max_index = datas.index(now_max)
diff = now_max - datas[0]
for i in range(1,N-1):
if i == max_index:
now_max = max(datas[i+1:])
max_index = datas.index(now_max,i+1)
new_diff = now_max - datas[i]
if diff < new_diff:
diff = new_diff
print(diff)
#print('time :',time.time()-start)
| p02258 |
from sys import stdin
N,*datas = [int(i) for i in stdin.readlines()]
now_max = max(datas[1:])
max_index = (N-1) - list(reversed(datas)).index(now_max)
_min = min(datas)
min_index = datas.index(_min)
if max_index > min_index:
diff = now_max - _min
else:
diff = now_max - datas[0]
for i in range(1,N-1):
if i == max_index:
now_max = max(datas[i+1:])
max_index = datas.index(now_max,i+1)
new_diff = now_max - datas[i]
if diff < new_diff:
diff = new_diff
print(diff)
| from sys import stdin
N,*datas = [int(i) for i in stdin.readlines()]
now_max = max(datas[1:])
max_index = datas.index(now_max)
diff = now_max - datas[0]
for i in range(1,N-1):
if i == max_index:
now_max = max(datas[i+1:])
max_index = datas.index(now_max,i+1)
new_diff = now_max - datas[i]
if diff < new_diff:
diff = new_diff
print(diff)
| p02258 |
n = int(input())
R = [0 for i in range(n)]
ans = 1 - 10**9
for i in range(n):
R[i] = int(input())
if i == 0:
min_R = R[0]
continue
if R[i] - min_R > ans:
ans = R[i] - min_R
if R[i] < min_R:
min_R = R[i]
print(ans)
| n = int(input())
R = [0 for i in range(n)]
ans = 1 - 10**9
min_R = int(input())
for i in range(n-1):
R[i] = int(input())
if R[i] - min_R > ans:
ans = R[i] - min_R
if R[i] < min_R:
min_R = R[i]
print(ans)
| p02258 |
amount = int(eval(input()))
numbers = [int(eval(input())) for i in range(amount)]
max_profit = -1 * (numbers[0] - numbers[1])
for i in range(amount - 1):
for j in range(i + 1, amount):
if (-1 * (numbers[i] - numbers[j])) >= max_profit:
max_profit = -1 * (numbers[i] - numbers[j])
print(max_profit) | maxv = -2 * 10 ** 9
minv = 2 * 10 ** 9
n = int(eval(input()))
for i in range(n):
x = int(eval(input()))
maxv = max(x - minv, maxv)
minv = min(x, minv)
print(maxv) | p02258 |
# -*- coding: utf-8 -*-
n = int(input())
R_List = []
Max = 0
for i in range(n):
R_List.append(int(input()))
if i == 0:
continue
elif i == 1:
Max = R_List[1]-R_List[0]
else:
for j in range(i):
Max = max(Max, R_List[i]-R_List[j])
print(Max) | # -*- coding: utf-8 -*-
n = int(input())
R_List = []
Max = 0
R_min = 0
for i in range(n):
R_List.append(int(input()))
if i == 0:
R_min = R_List[0]
elif i == 1:
Max = R_List[1]-R_min
R_min = min(R_min, R_List[1])
else:
Max = max(Max, R_List[i]-R_min)
R_min = min(R_min, R_List[i])
print(Max) | p02258 |
n = int(eval(input()))
t = []
for i in range(n):
t.append(int(eval(input())))
buy = t[0]
prev_sell = max(t[1:])
val = prev_sell - buy
for i in range(n-1):
if i == 0 or t[i - 1] < t[i]:
continue
prev_sell = max(t[i+1:])
val2 = prev_sell - t[i]
if val2 > val:
val = val2
print(val)
| n = int(eval(input()))
t = []
for i in range(n):
t.append(int(eval(input())))
buy = t[0]
val = t[-1] - buy
for i in range(1, n):
if t[i] - buy > val:
val = t[i] - buy
if t[i] < buy:
buy = t[i]
print(val)
| p02258 |
import sys
n=int(eval(input()))
r=list(map(int,sys.stdin.read().split()))
print((max([max(r[i+1:])-r[i]for i in range(n-1)]))) | n=int(eval(input()))
r=[int(eval(input()))for _ in range(n)]
s=r[0];b=r[1]-s
for i in range(1,n):
b=max(b,r[i]-s)
s=min(s,r[i])
print(b)
| p02258 |
import sys
b,s=-1e10,1e10
eval(input())
for r in map(int,sys.stdin):
if b<r-s:b=r-s
if s>r:s=r
print(b)
| import sys
s=1e10;b=-s
eval(input())
for r in map(int,sys.stdin):
if b<r-s:b=r-s
if s>r:s=r
print(b)
| p02258 |
import sys
s=1e10;b=-s
eval(input())
for r in map(int,sys.stdin.readlines()):
if b<r-s:b=r-s
if s>r:s=r
print(b)
| import sys
def m():
s=1e10;b=-s
eval(input())
for r in map(int,sys.stdin):
if b<r-s:b=r-s
if s>r:s=r
print(b)
if'__main__'==__name__:m()
| p02258 |
import sys
s=1e10;b=-s
eval(input())
for r in map(int,sys.stdin):
if b<r-s:b=r-s
if s>r:s=r
print(b)
| import sys
def f():
s=1e10;b=-s
eval(input())
for r in map(int,sys.stdin):
if b<r-s:b=r-s
if s>r:s=r
print(b)
f()
| p02258 |
n=int(eval(input()))
Rt=[]
for i in range(n):
Rt.append(int(eval(input())))
a=-999999999
for i in range(1,n):
for j in range(i):
if a<Rt[i]-Rt[j]:
a=Rt[i]-Rt[j]
print(a)
| n=int(eval(input()))
Rt=[]
for i in range(n):
Rt.append(int(eval(input())))
maxv=Rt[1]-Rt[0]
minv=Rt[0]
for j in range(1,n):
maxv=max(maxv,Rt[j]-minv)
minv=min(minv,Rt[j])
print(maxv)
| p02258 |
N = int(eval(input()))
purchase_price = int(eval(input()))
profit = -2000000000
for _ in range(N-1):
price = int(eval(input()))
profit = max(profit, (price-purchase_price))
purchase_price = min(price, purchase_price)
print(profit)
| N = int(eval(input()))
r1 = int(eval(input()))
r2 = int(eval(input()))
R = [int(eval(input())) for i in range(N-2)]
res = r2 - r1
min_r = min(r1, r2)
for r in R:
res = max(res, r - min_r)
min_r = min(min_r, r)
print(res)
| p02258 |
N =int(eval(input()))
R = []
for i in range(N):
R.append(int(eval(input())))
maxv=-2000000000
minv=R[0]
for i in range(1,N):
maxv=max(maxv,R[i]-minv)
minv=min(minv,R[i])
print(maxv) | import sys
i=input
n =int(i())
r0=int(i())
r1=int(i())
maxv=r1-r0
minv=min(r1,r0)
for i in map(int,sys.stdin.readlines()):
maxv=max(maxv,i-minv)
minv=min(minv,i)
print(maxv) | p02258 |
#16D8101012J 伊藤惇 dj Python3
import sys
def Maximum_Profit(n,A):
Max=-sys.maxsize
for i in range(n-1):
tmp=(max(A[i+1:])-A[i])
if Max<tmp:
Max=tmp
return Max
if __name__ == "__main__":
n=int(eval(input()))
A=[]
for i in range(n):
A.append(int(eval(input())))
Max=Maximum_Profit(n,A)
print(Max)
| #16D8101012J 伊藤惇 dj Python3
def Maximum_Profit(n,A):
Max=A[1]-A[0]
Min=A[0]
for j in range(1,n):
Max=max(Max,A[j]-Min)
Min=min(Min,A[j])
return Max
if __name__ == "__main__":
n=int(eval(input()))
A=[]
for i in range(n):
A.append(int(eval(input())))
Max=Maximum_Profit(n,A)
print(Max)
| p02258 |
n = int(input())
nums = [int(input()) for i in range(n)]
maxv = nums[1] - nums[0]
for j in range(1, n):
for i in range(j):
maxv = max(maxv, nums[j]-nums[i])
print(maxv)
| # coding: utf-8
# 答えを見た。。。
n = int(input())
R = [int(input()) for i in range(n)]
maxv = -2000000000
minv = R[0]
for r in R[1:]:
maxv = max(maxv, r - minv)
minv = min(minv, r)
print(maxv)
| p02258 |
arr = []
for i in range(int(eval(input()))):
arr.append(int(eval(input())))
m = 0
for i in range(len(arr)-1):
for j in range(i+1, len(arr)):
if i == 0 and j == 1:
m = arr[j] - arr[i]
else:
m = max(m, arr[j] - arr[i])
print(m) | n = int(eval(input()))
arr = [int(eval(input())) for i in range(n)]
m = 1 - 10**9
minv = arr[0]
for i in range(1,len(arr)):
if arr[i] - minv > m:
m = arr[i] - minv
minv = min(minv, arr[i])
print(m) | p02258 |
r = []
N = int(eval(input()))
for i in range(0, N):
r.append(int(eval(input())))
min = r[N-2]
max = r[N-1]
for i in range(N-1)[::-1]:
for j in range(i+1, N):
if r[j] - r[i] > max - min:
max = r[j]
min = r[i]
print((max - min)) | r = []
N = int(eval(input()))
for i in range(0, N):
r.append(int(eval(input())))
min_i = N-2
max_i = N-1
for i in range(N-1)[::-1]:
if (r[i] - r[i+1]) * r[max_i] - r[min_i] < 0:
for j in range(i+1, N):
if r[j] - r[i] > r[max_i] - r[min_i]:
max_i = j
min_i = i
print((r[max_i] - r[min_i])) | p02258 |
r = []
N = int(eval(input()))
for i in range(0, N):
r.append(int(eval(input())))
min_i = N-2
max_i = N-1
for i in range(N-1)[::-1]:
if r[i] < r[i+1]:
for j in range(i+1, N):
if r[j] - r[i] > r[max_i] - r[min_i]:
max_i = j
min_i = i
if r[max_i] - r[min_i] < 0:
if r[i+1] - r[i] > r[max_i] - r[min_i]:
max_i = i+1
min_i = i
print((r[max_i] - r[min_i])) | N = int(eval(input()))
r = [int(eval(input())) for i in range(N)]
min = r[0]
max = -9999999999999999
for i in range(1, N):
if r[i] - min > max:
max = r[i] - min
if r[i] < min:
min = r[i]
print(max) | p02258 |
import sys
def solve():
n = int(input())
R = []
for i in range(n):
R.append(int(input()))
#for i in xrange(n):
# print R[i]
max_profit = -sys.maxsize
for i in range(n):
for j in range(i + 1, n):
if R[j] - R[i] > max_profit:
max_profit = R[j] - R[i]
print(max_profit)
if __name__ == "__main__":
solve() | import sys
def solve():
n = int(input())
R = []
for i in range(n):
R.append(int(input()))
#for i in xrange(n):
# print R[i]
max_profit = -sys.maxsize
min_R = R[0]
for i in range(1, n):
if R[i] - min_R > max_profit:
max_profit = R[i] - min_R
if min_R > R[i]:
min_R = R[i]
print(max_profit)
if __name__ == "__main__":
solve() | p02258 |
num = n = int(eval(input()))
price = []
max_profit = -999999999999999
while(n>0):
x = int(eval(input()))
price.append(x)
n -= 1
for i in range(1,num):
for n in range(0,i):
pro = price[i] - price[n]
if pro > max_profit:
max_profit = pro
print(("{0}".format(max_profit))) | num= n = int(eval(input()))
price = []
max_pro = -999999999
while(n>0):
x = int(eval(input()))
price.append(x)
n -= 1
min = price[0]
for i in range(1,num):
pro = price[i]-min
if(max_pro < pro):
max_pro = pro
if(min > price[i]):
min = price[i]
print(("{0}".format(max_pro))) | p02258 |
n = eval(input())
n = int(n)
pl = []
for i in range(n):
pl.append(int(eval(input())))
l = []
for i, p in enumerate(pl[:-1]):
l.append(max(pl[i+1:])-p)
m = max(l)
print(m) | n = eval(input())
n = int(n)
pl = []
for i in range(n):
pl.append(int(eval(input())))
m = pl[0]
M = pl[0]
difM = pl[1]-pl[0]
for i, p in enumerate(pl[1:]):
if p < m:
m = p
continue
if p - m > difM:
difM = p - m
print(difM)
| p02258 |
n = int(eval(input()))
a = []
for i in range(n):
a.append(int(eval(input())))
ans = a[1]-a[0]
for i in range(n-1):
k = max(a[i+1:]) - a[i]
if k > ans:
ans = k
print(ans)
| n = int(eval(input()))
a = []
for i in range(n):
a.append(int(eval(input())))
nowmin = a[0]
ans = a[1]-a[0]
for i in range(n-1):
if a[i] <= nowmin:
k = max(a[i+1:]) - a[i]
if k > ans:
ans = k
nowmin = a[i]
print(ans)
| p02258 |
n = int(eval(input()))
a = []
for i in range(n):
a.append(int(eval(input())))
nowmin = a[0] + 1
ans = a[1]-a[0]
for i in range(n-1):
if a[i] < nowmin:
k = max(a[i+1:]) - a[i]
if k > ans:
ans = k
nowmin = a[i]
print(ans)
| n = int(eval(input()))
a = []
for i in range(n):
a.append(int(eval(input())))
nowmin = a[0]
nowmax = max(a[1:])
ans = nowmax - nowmin
for i in range(n-1):
if a[i] == nowmax:
nowmax = max(a[i+1:])
if a[i] < nowmin:
k = nowmax - a[i]
if k > ans:
ans = k
nowmin = a[i]
print(ans)
| p02258 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.