Problem:


Score : 100 points

Problem Statement

It has been decided that a programming contest sponsored by company A will be held, so we will post the notice on a bulletin board.

The bulletin board is in the form of a grid with N rows and N columns, and the notice will occupy a rectangular region with H rows and W columns.

How many ways are there to choose where to put the notice so that it completely covers exactly HW squares?

Constraints

1 \leq H, W \leq N \leq 100

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
H
W

Output

Print the answer.

Sample Input 1

3
2
3

Sample Output 1

2

There are two ways to put the notice, as follows:

###   ...
###   ###
...   ###

Here, # represents a square covered by the notice, and . represents a square not covered.

Sample Input 2

100
1
1

Sample Output 2

10000

Sample Input 3

5
4
2

Sample Output 3

8



Sample input:
3
2
3


Sample output:
2

Submission status: Runtime Error

Solution code:
def searchAokiGetCard(xi, A):
    Adistance = list(map(lambda ai: abs(ai-xi), A))
    Adismin = min(Adistance)
    geta = xi - Adismin
    if geta not in A:
        geta = xi + Adismin
    A.remove(geta)
    return A


N, Q = map(int, input().split())
A = list(map(int, input().split()))
Aorig = A.copy()

X = []
for i in range(Q):
    X.append(int(input()))

A.sort()
for xi in X:
    sum = 0
    A = Aorig.copy()
    for _ in A:
        At = A.pop()
        sum = sum + At
        if A != []:
            A = searchAokiGetCard(xi, A)

    if A != []:
        print(sum + max(A))
    else:
        print(sum)

Submission status: Runtime Error

Solution code:
import numpy as np
H, W = map(int,input().split())
S_pre = []
for i in range(H):
    S_i = list(input().split())
    S_pre.append(S_i)
    black = [j for j,x in enumerate(S_i) if x == '#']
       
S = np.array(S_pre)

Submission status: Runtime Error

Solution code:
class UnionFind(object):
    def __init__(self, n=1):
        self.par = [ii for ii in range(n)]
        self.rank = [0 for _ in range(n)]

    def find(self, x):
        """
        x が属するグループを探索
        """
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def union(self, x, y):
        """
        x と y のグループを結合
        """
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                x, y = y, x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1
            self.par[y] = x

    def is_same(self, x, y):
        """
        x と y が同じグループか否か
        """
        return self.find(x) == self.find(y)


H, W = map(int, input().split())
S = [input() for _ in range(H)]
if H == 1:
    for i in range(10000000001110010):
        print(" ghbjnkm")

def kake(iii, jjj):
    return iii * W + jjj


u = UnionFind(H * W)

for i in range(H):
    for j in range(W):
        if i != 0:
            if S[i][j] != S[i - 1][j]:
                u.union(kake(i, j), kake(i - 1, j))
        if i != H - 1:
            if S[i][j] != S[i + 1][j]:
                u.union(kake(i, j), kake(i + 1, j))
        if j != 0:
            if S[i][j] != S[i][j - 1]:
                u.union(kake(i, j), kake(i, j - 1))
        if j != W - 1:
            if S[i][j] != S[i][j + 1]:
                u.union(kake(i, j), kake(i, j + 1))

ans = [[0, 0] for _ in range(H * W)]

for i in range(H):
    for j in range(W):
        if (i+j) % 2 == 0:
            ans[u.par[kake(i, j)]][0] += 1
        else:
            ans[u.par[kake(i, j)]][1] += 1

pri = 0

for i in range(H):
    for j in range(W):
        pri += ans[kake(i, j)][0] * ans[kake(i, j)][1]

print(pri)

Submission status: Runtime Error

Solution code:
#coding:utf-8
n = input()
a,b = map(int,input().split())
p = list(map(int,input().split()))

first=0
second=0
third=0

for i in p:
  if i <= a:
    first +=1
  elif i <= b:
    second +=1
  else:
    third +=1

print(min([first,second,third]))

Submission status: Runtime Error

Solution code:
N = int(input())
H = int(input())
W = int(input())
 
ANS = (N-(H-1))(N-(W-1))
 
print(ANS)

Submission status: Runtime Error

Solution code:
H, W = map(int, input().split())
S = []
for i in range(H):
    S.append(input())

#white = ".", black = "#"
def search(x, y, color):
    global ans
    if color == ".":
        for m in [1, -1]:
            if 0 <= x+m <= H-1:
                if S[x+m][y] == "#" and not dp[x+m][y]:
                    dp[x+m][y] = True
                    color = "#"
                    search(x+m, y, color)
        for n in [1, -1]:
            if 0 <= y+n <= W-1:
                if S[x][y+n] == "#" and not dp[x][y+n]:
                    dp[x][y+n] = True
                    color = "#"
                    search(x, y+n, color)

    else:
        for m in [1, -1]:
            if 0 <= x+m <= H-1:
                if S[x+m][y] == "." and not dp[x+m][y]:
                    ans += 1
                    dp[x+m][y] = True
                    color = "."
                    search(x+m, y, color)

        for n in [1, -1]:
            if 0 <= y+n <= W-1:
                if S[x][y+n] == "." and not dp[x][y+n]:
                    ans += 1
                    dp[x][y+n] = True
                    color = "."
                    search(x, y+n, color)


ans = 0
for i in range(H):
    for j in range(W):
        if S[i][j] == "#":
            dp = [[False] * W for a in range(H)]
            dp[i][j] = True
            search(i, j, "#")

print(ans)

Submission status: Runtime Error

Solution code:
n, q = map(int,input().split())
card_num = list(map(int,input().split()))
card_num.sort()
x_i = []
for i in range(q):
    x_i.append(int(input()))
for i in range(q):
    card = []
    for num in range(n):
        card.append(card_num[num])
    taka = []
    for j in range(n//2):
        temp = max(card)
        card.remove(temp)
        taka.append(temp)
        up = [x for x in card if x >= x_i[i]]
        down = [y for y in card if y < x_i[i]]
        if up == []:
            card.remove(down[-1])
        elif down == []:
            card.remove(up[0])
        elif up[0]-x_i[i]<x_i[i]-down[-1]:
            card.remove(up[0])
        else:
            card.remove(down[-1])
    if n%2==1:
        taka.append(card[0])
    print(sum(taka))

Submission status: Runtime Error

Solution code:
H, W = map(int, input().split())
S = [input() for i in range(H)]
 
 
b_list = []
for row in S:
    tmp_raw = []
    for j, t in enumerate(row):
        if t == '#':
            tmp_raw.append(j)
    b_list.append(tmp_raw)
tmp = -1
res = {}
raw_before = []
for i, raw in enumerate(b_list):
    res[i] = {}
    for j in raw:
        res[i][j] = []
        if not((j - 1) in raw or j == 0):
            res[i][j].append((i, j-1))
        if not((j + 1) in raw or j == W -1):
            res[i][j].append((i, j+1))
        if not(i == 0 or j in raw_before):
            res[i][j].append((i-1, j))
        if not(i == H - 1):
            if not(j in b_list[i+1]):
                res[i][j].append((i+1, j))
    raw_before = raw
 
 
 
before = 0
for i, raw in enumerate(b_list):
    for j in raw:
         before += len(res[i][j])
while True:
    for i, raw in enumerate(b_list):
        for j in raw:
            try:
                if S[i-1][j] == '.' or S[i][j-1] == '.':
                    res[i][j] += res[i-1][j-1]
            except:
                pass
            try:
                if S[i+1][j] == '.' or S[i][j-1] == '.':
                    res[i][j] += res[i+1][j-1]
            except:
                pass
            try:
                if S[i-1][j] == '.' or S[i][j+1] == '.':
                    res[i][j] += res[i-1][j+1]
            except:
                pass
            try:
                if S[i+1][j] == '.' or S[i][j+1] == '.':
                    res[i][j] += res[i+1][j+1]
            except:
                pass
    before = result
    for i, raw in enumerate(b_list):
        for j in raw:
            res[i][j] = list(set(res[i][j]))
    result = 0
    for i, raw in enumerate(b_list):
        for j in raw:
             result += len(res[i][j])
    if before == result:
        break
print(result)

Submission status: Runtime Error

Solution code:
import itertools
import sys
sys.setrecursionlimit(2000)
h, w = map(int, input().split())
s_list = []
for i in range(h):
  s_list.append(list(input()))
res = 0
check_list = set()

def rec_create_area(point, tmp_area, current_str):
  new_point_list = []
  new_point_list.append((point[0] + 1, point[1]))
  new_point_list.append((point[0], point[1] + 1))
  new_point_list.append((point[0] - 1, point[1]))
  new_point_list.append((point[0], point[1] - 1))
  for new_point in new_point_list:
    if new_point[0] >= h or new_point[1] >= w or new_point[0] < 0 or new_point[1]  < 0:
      continue
    if new_point in check_list:
      continue
    new_str = s_list[new_point[0]][new_point[1]]
    if new_str == current_str:
      continue
    if new_str == "#":
      tmp_area[0] += 1
    else:
      tmp_area[1] += 1
    check_list.add(new_point)
    rec_create_area(new_point, tmp_area, new_str)
  
for a, b in itertools.product(range(h), range(w)):
  check_point = (a, b)
  if check_point in check_list:
    continue
  check_list.add(check_point)
  current_str = s_list[check_point[0]][check_point[1]]
  if current_str == "#":
    tmp_area = [1, 0]
  else:
    tmp_area = [0, 1]
  rec_create_area(check_point, tmp_area, current_str)
  res += tmp_area[0] * tmp_area[1]
  
print(res)

Submission status: Runtime Error

Solution code:
num=int(input())
line=input().split(" ")
a=int(line[0])
b=int(line[1])
low=[]
middle=[]
high=[]

lines=input().split(" ")


for i in range(num):
    n=int(lines[i])
    if n<=a:
        low.append(n)
    elif n<=b:
        middle.append(n)
    else:
        high.append(n)

print(min(len(low),len(middle),len(high)))

Submission status: Runtime Error

Solution code:
#coding:utf-8
n = input()
h = input()
w = input()

print((n-h+1)*(n-w+1))

Submission status: Runtime Error

Solution code:
import itertools
h, w = map(int, input().split())
s_list = []
for i in range(h):
  s_list.append(list(input()))
area_list = []
check_list = set()

def rec_create_area(point, tmp_area, current_str):
  new_point_list = []
  new_point_list.append((point[0] + 1, point[1]))
  new_point_list.append((point[0], point[1] + 1))
  for new_point in new_point_list:
    if new_point[0] >= h or new_point[1] >= w:
      continue
    if new_point in check_list:
      continue
    new_str = s_list[new_point[0]][new_point[1]]
    if new_str == current_str:
      continue
    if new_str == "#":
      tmp_area[0] += 1
    else:
      tmp_area[1] += 1
    check_list.add(new_point)
    rec_create_area(new_point, tmp_area, new_str)
  
for a, b in itertools.product(range(h), range(w)):
  check_point = (a, b)
  if check_point in check_list:
    continue
  check_list.add(check_point)
  current_str = s_list[0][0]
  if current_str == "#":
    tmp_area = [1, 0]
  else:
    tmp_area = [0, 1]
  rec_create_area(check_point, tmp_area, current_str)
  area_list.append(tmp_area)
  
print(sum([x[0] * x[1] for x in area_list]))

Submission status: Runtime Error

Solution code:
#codibg:utf-8
n = input()
h = input()
w = input()

print((n-h+1)*(n-w+1))

Submission status: Runtime Error

Solution code:
# H,W = 3,3
# s = [".#.", "..#", "#.."]

from collections import deque
H,W = map(int, input().split())
s = [input() for _ in range(H)]

ans = 0
kaburi = 0
for i in range(H):
    for j in range(W):
        if s[i][j]==".": continue
        stk = deque([(i,j)]) # stktack
        visited = set([(i,j)])
        while stk: # なくなるまで
            y,x = stk.popleft()

            for dy,dx in ([1,0],[0,1],[-1,0],[0,-1]):
                if 0 <= y+dy < H and 0 <= x+dx < W:
                    if ((s[y][x]=="." and s[y+dy][x+dx] == "#")
                     or (s[y][x]=="#" and s[y+dy][x+dx] == ".") ):
                        if (y+dy,x+dx) in visited: continue
                        stk.append([y+dy,x+dx])
                        visited.add((y+dy,x+dx))
                        # print(i,j, y+dy,x+dx, ans)
                        if s[y+dy][x+dx]=="#": kaburi += 1
                        ans += 1
print(ans-kaburi)

Submission status: Runtime Error

Solution code:
def trace(i, j, S, col, num_color):
    next_col = 1 - col
    num_color[col] += 1
    S[i][j] = 2
    if S[i-1][j] == next_col:
        trace(i-1, j, S, next_col, num_color)
    if S[i][j-1] == next_col:
        trace(i, j-1, S, next_col, num_color)
    if S[i+1][j] == next_col:
        trace(i+1, j, S, next_col, num_color)
    if S[i][j+1] == next_col:
        trace(i, j+1, S, next_col, num_color)
    return num_color[0] * num_color[1]

def main():
    H, W = map(int, input().split())
    # 黒0，白1，padding2
    S = [[2] * (W+2)]
    for _ in range(H):
        S.append([2] + [0 if s == '#' else 1 for s in input()] + [2])
    S.append([2] * (W+2))
    num_comb = 0
    for i in range(1, H+1):
        for j in range(1, W+1):
            if S[i][j] == 0:
                num_color = [0, 0]
                num_comb += trace(i, j, S, 0, num_color)
    print(num_comb)

main()

Submission status: Runtime Error

Solution code:
def trace(i, j, S, col, num_color):
    next_col = 1 - col
    num_color[col] += 1
    S[i][j] = 2
    if S[i-1][j] == next_col:
        trace(i-1, j, S, next_col, num_color)
    if S[i][j-1] == next_col:
        trace(i, j-1, S, next_col, num_color)
    if S[i+1][j] == next_col:
        trace(i+1, j, S, next_col, num_color)
    if S[i][j+1] == next_col:
        trace(i, j+1, S, next_col, num_color)
    return num_color[0] * num_color[1]

H, W = map(int, input().split())
# 黒0，白1，padding2
S = [[2] * (W+2)]
for _ in range(H):
    S.append([2] + [0 if s == '#' else 1 for s in input()] + [2])
S.append([2] * (W+2))
# print(S)
num_comb = 0
for i in range(1, H+1):
    for j in range(1, W+1):
        if S[i][j] == 0:
            num_color = [0, 0]
            num_comb += trace(i, j, S, 0, num_color)
print(num_comb)

Submission status: Runtime Error

Solution code:
N = int(input())
A,B = map(int,input().split())
P=list(map(int,input().split()))
a = sum(x<=A for x in P)
b = sum(x<=B and x>A for x in P) 
c = sum(x>B for x in P)

print(min(a,b,c))

Submission status: Runtime Error

Solution code:
import copy
n, q = [int(i) for i in input().split()]
As = sorted([int(i) for i in input().split()])
for i in range(q):
    x = int(input())
    As_tmp = copy.copy(As)
    As_abs = [abs(a - x) for a in As]
    ans = 0
    # print(As_abs)
    while As_abs:
        ans += As_tmp[-1]
        # print(ans)
        As_tmp.pop(-1)
        As_abs.pop(-1)
        if not As_abs:
            break
        # ans += As[As_abs.index(min(As_abs))]
        idx = As_abs.index(min(As_abs))
        As_tmp.pop(idx)
        As_abs.pop(idx)
        # print(As_abs)
 
    print(ans)

Submission status: Runtime Error

Solution code:
import sys 

sys.setrecursionlimit(100000000)

def dfs(row, column, black):
    global S, H, W, X, Y, visited, ans
    if black:
        for dx, dy in zip(X, Y):
            n_row = row + dx
            n_column = column + dy
            if 0 <= n_row < H and 0 <= n_column < W:
                if visited[n_row][n_column] == False and S[n_row][n_column] == '.':
                    visited[n_row][n_column] = True
                    ans += 1
                    dfs(n_row, n_column, False)
    
    else:
        for dx, dy in zip(X, Y):
            n_row = row + dx
            n_column = column + dy
            if 0 <= n_row < H and 0 <= n_column < W:
                if visited[n_row][n_column] == False and S[n_row][n_column] == '#':
                    visited[n_row][n_column] = True
                    dfs(n_row, n_column, True)






if __name__ == "__main__":
    H, W = map(int, input().split())

    S = [None] * H
    X = [0, 0, 1, -1]
    Y = [1, -1, 0, 0]
    for i in range(H):
        S[i] = list(input())
    black_row = []
    black_column = []
    for row in range(H):
        for column in range(W):
            if S[row][column] == "#":
                black_row.append(row)
                black_column.append(column)
    ans = 0
    for row, column in zip(black_row, black_column):
        visited = [[False] * W for i in range(H)]
        dfs(row, column, True)
    print(ans)

Submission status: Runtime Error

Solution code:
import sys

lines = sys.stdin.readlines()

N = lines[0]
H = lines[1]
W = lines[2]

p_row = H - N + 1
p_column = W - N + 1

ans = p_row * p_column
print(ans)

Submission status: Runtime Error

Solution code:
from math import *
log = lambda *x: print(*x)

n, = cin(int)
h, = cin(int)
w, = cin(int)

tw, th = 0, ceil(n/h)

while w <= n:
    tw += 1
    w += 1

log(th * tw)

Submission status: Runtime Error

Solution code:
n,h,w=map(int,input().split())
ans=(n-h+1)*(n-w+1)
print(ans)

Submission status: Runtime Error

Solution code:
n = input()
h = input()
w = input()

ans = (n-h+1) * (n-w+1)
print(ans)

Submission status: Runtime Error

Solution code:
N = input()
H = input()
W = input()
print((N - H + 1) * (N - W + 1))

Submission status: Runtime Error

Solution code:
# from sys import stdout
# from math import *
# from math import log as lg
# from bisect import bisect_left as bs
log = lambda *x: print(*x)

def cin(*fn, def_fn=str):
    i, r = 0, []
    if fn:
        def_fn = fn[0]
    for c in input().split(' '):
        r += [(fn[i] if len(fn) > i else def_fn) (c)]
        i += 1
    return r
##################################################

n,h,w = cin(int)

log(round(n/h) * round(n/h))

Submission status: Runtime Error

Solution code:
n,h,w=map(int, input().split())
ans=(n-h+1)*(n-w+1)
print(ans)

Submission status: Runtime Error

Solution code:
n,h,w=map(int, input().split())
print((n-h+1)*(n-w+1))

Submission status: Runtime Error

Solution code:
n1=input()
n2=input()
n3=input()
out=(n1-n2+1)*(n1-n3+1)
print(out)

Submission status: Runtime Error

Solution code:
N, W, H = map(int, input().split())

print((N - W + 1) * (N - H + 1))

Submission status: Runtime Error

Solution code:
n1, n2, n3 = list(map(int, input().split()))
print((n1-n2+1)*(n1-n3+1))

Submission status: Runtime Error

Solution code:
def main():
  n, h, w = map(int, input().strip().split())
  print((n-h+1)*(n-w+1))


if __name__ == '__main__':
  main()

Submission status: Runtime Error

Solution code:
N=int(input())
H=int(input())
W==int(input())
print((N-H+1)*(N-W+1))

Submission status: Runtime Error

Solution code:
n1, n2, n3 = list(map(int, input().split()))
print((n1-n2)*(n1-n3))

Submission status: Runtime Error

Solution code:
N=int(input())
H=int(input())
W==int(input())
print((N-H+1)*(N-W+1))

Submission status: Runtime Error

Solution code:
N, H, W = input(), input(), input()
print((N-H+1)*(N-W+1))

Submission status: Runtime Error

Solution code:
n, h, w = map(int, input().split())
print((n-h+1)*(n-w+1))