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: Accepted

Solution code:
#!/usr/bin/env python
"""
This file is part of https://github.com/Cheran-Senthil/PyRival.

Copyright 2018 Cheran Senthilkumar all rights reserved,
Cheran Senthilkumar <hello@cheran.io>
Permission to use, modify, and distribute this software is given under the
terms of the MIT License.

"""
from __future__ import division, print_function

import cmath
import itertools
import math
import operator as op
# import random
import sys
from atexit import register
from bisect import bisect_left, bisect_right
# from collections import Counter, MutableSequence, defaultdict, deque
# from copy import deepcopy
# from decimal import Decimal
# from difflib import SequenceMatcher
# from fractions import Fraction
# from heapq import heappop, heappush

if sys.version_info[0] < 3:
    # from cPickle import dumps
    from io import BytesIO as stream
    # from Queue import PriorityQueue, Queue
else:
    # from functools import reduce
    from io import StringIO as stream
    # from pickle import dumps
    # from queue import PriorityQueue, Queue


if sys.version_info[0] < 3:
    class dict(dict):
        """dict() -> new empty dictionary"""
        def items(self):
            """D.items() -> a set-like object providing a view on D's items"""
            return dict.iteritems(self)

        def keys(self):
            """D.keys() -> a set-like object providing a view on D's keys"""
            return dict.iterkeys(self)

        def values(self):
            """D.values() -> an object providing a view on D's values"""
            return dict.itervalues(self)

    input = raw_input
    range = xrange

    filter = itertools.ifilter
    map = itertools.imap
    zip = itertools.izip


def sync_with_stdio(sync=True):
    """Set whether the standard Python streams are allowed to buffer their I/O.

    Args:
        sync (bool, optional): The new synchronization setting.

    """
    global input, flush

    if sync:
        flush = sys.stdout.flush
    else:
        sys.stdin = stream(sys.stdin.read())
        input = lambda: sys.stdin.readline().rstrip('\r\n')

        sys.stdout = stream()
        register(lambda: sys.__stdout__.write(sys.stdout.getvalue()))


def gcd(x, y):
    """greatest common divisor of x and y"""
    while y:
        x, y = y, x % y
    return x


def main():
    n = int(input())
    h = int(input())
    w = int(input())

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


if __name__ == '__main__':
    sync_with_stdio(False)
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
h = int(input())
w = int(input())
r = (n - h + 1) * (n - w + 1)
print(r)

Submission status: Accepted

Solution code:
N = int(input())
H = int(input())
W = int(input())

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

Submission status: Accepted

Solution code:
import sys
import math
input = sys.stdin.readline
N = int(input())
H = int(input())
W = int(input())
print((N-H+1)*(N-W+1))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import random
import re
import string
import sys

N = int(input())
H = int(input())
W = int(input())

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

Submission status: Accepted

Solution code:
n, h, w = int(raw_input()), int(raw_input()), int(raw_input())

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

n = int(input())
h = int(input())
w = int(input())

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

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

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

Submission status: Accepted

Solution code:
n = int(input())
x = int(input())
y = int(input())

print((n-x+1) * (n-y+1))

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input().rstrip())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

#https://note.nkmk.me/python-union-find/

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

h,w=MI()
uf=UnionFind(h*w)
lis=[[0]*w for i in range(h)]
for i in range(h):
    s=SI()
    for j in range(w):
        if s[j]=="#":
            lis[i][j]=1
step=[[0,1],[0,-1],[-1,0],[1,0]]
for i in range(h):
    for j in range(w):
        for x,y in step:
            if not (0<=i+x<h and 0<=j+y<w):
                continue
            if lis[i][j]!=lis[i+x][j+y]:
                uf.union(w*i+j,w*(i+x)+(j+y))
ans=0
print(ans)
'''for z in uf.roots():
    s=0
    b=0
    for node in uf.members(z):
        if lis[node//w][node%w]==1:
            b+=1
        else:
            s+=1
    ans+=b*s
print(ans)'''

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input().rstrip())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

#https://note.nkmk.me/python-union-find/

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

h,w=MI()
uf=UnionFind(h*w)
lis=[[0]*w for i in range(h)]
for i in range(h):
    s=SI()
    for j in range(w):
        if s[j]=="#":
            lis[i][j]=1
step=[[0,1],[0,-1],[-1,0],[1,0]]
for i in range(h):
    for j in range(w):
        for x,y in step:
            if not (0<=i+x<h and 0<=j+y<w):
                continue
            if lis[i][j]!=lis[i+x][j+y]:
                uf.union(w*i+j,w*(i+x)+(j+y))
'''ans=0
for z in uf.roots():
    s=0
    b=0
    for node in uf.members(z):
        if lis[node//w][node%w]==1:
            b+=1
        else:
            s+=1
    ans+=b*s
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:
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())



def calc(i,j):
    return i*w+j
def calc_inv(x):
    return x//w, x%w
def judge(x,y):
    i0,j0 = calc_inv(x)
    i1,j1 = calc_inv(y)
    if s[i0][j0] != s[i1][j1]:
        return True
    return False


h,w = map(int,input().split())
s = [[(i == "#")*1 for i in list(input())] for _ in range(h)]
uf = UnionFind(h*w)

for i in range(h):
    for j in range(w):
        now = calc(i,j)
        nxt = calc(i+1,j)
        if i+1 < h:
            if judge(now,nxt):
                uf.union(now,nxt)
        nxt = calc(i,j+1)
        if j+1 < w:
            if judge(now,nxt):
                uf.union(now,nxt)


cnt = [[0,0] for _ in range(h*w)]
ind = 0
for l in uf.all_group_members().values():
    for x in l:
        i,j = calc_inv(x)
        if s[i][j]:
            cnt[ind][0] += 1
        else:
            cnt[ind][1] += 1
    ind += 1
ans = 0
for i in range(ind):
    ans += cnt[i][0]*cnt[i][1]
print(ans)

Submission status: Runtime Error

Solution code:
N=input()
H=input()
W=input()

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

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
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)
  return divisors

#####MakePrimes######
def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum

#####GCD#####
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############

N,H,W = IL()

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

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:
n,h,w = map(int,input(),split())
print((n-h+1)*(n-w+1))

Submission status: Runtime Error

Solution code:
from math import floor
n = int(input())
a = int(input())
b = int(input())

print(ceil(n / a) * ceil(n / b))

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:
n = int(input())
h, w = map(int, input().split())

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

Submission status: Runtime Error

Solution code:
h,w = map(int,input().split())
lis = [str(input()) for i in range(h)]
ans = 0
ch = [[0] * w for i in range(h)]

def firstcheck(x,y):
    if lis[x][y] != "#" or ch[x][y] != 0:
        return False
    if x > 0:
        if lis[x-1][y] == ".":
            return True
    if x < h-1:
        if lis[x+1][y] == ".":
            return True
    if y > 0:
        if lis[x][y-1] == ".":
            return True
    if y < w-1:
        if lis[x][y+1] == ".":
            return True
    return False

for sx in range(h):
    for sy in range(w):
        if firstcheck(sx,sy):
            cnt = 1
            nu = 0
            ch[sx][sy] = 1
            num = [[0] * w for i in range(h)]
            now = {(sx,sy,1)}
            while len(now) != 0:
                tmp = set()
                for x,y,iro in now:
                    if x > 0:
                        if lis[x-1][y] != lis[x][y] and num[x-1][y] == 0:
                            nu += iro
                            tmp.add((x-1,y,(iro+1)%2))
                            num[x-1][y] = 1
                            if lis[x-1][y] == "#" and ch[x-1][y] == 0:
                                cnt += 1
                                ch[x-1][y] = 1
                    if x < h-1:
                        if lis[x+1][y] != lis[x][y] and num[x+1][y] == 0:
                            nu += iro
                            tmp.add((x+1,y,(iro+1)%2))
                            num[x+1][y] = 1
                            if lis[x+1][y] == "#" and ch[x+1][y] == 0:
                                cnt += 1
                                ch[x+1][y] = 1
                    if y > 0:
                        if lis[x][y-1] != lis[x][y] and num[x][y-1] == 0:
                            nu += iro
                            tmp.add((x,y-1,(iro+1)%2))
                            num[x][y-1] = 1
                            if lis[x][y-1] == "#" and ch[x][y-1] == 0:
                                cnt += 1
                                ch[x][y-1] = 1
                    if y < w-1:
                        if lis[x][y+1] != lis[x][y] and num[x][y+1] == 0:
                            nu += iro
                            tmp.add((x,y+1,(iro+1)%2))
                            num[x][y+1] = 1
                            if lis[x][y+1] == "#" and ch[x][y+1] == 0:
                                cnt += 1
                                ch[x][y+1] = 1
                now = tmp
            ans += nu * cnt
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:
n,h,w = map(int,input().split())

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

Submission status: Runtime Error

Solution code:
class UnionFind():
    def __init__(self,n):
        self.n=n
        self.root=[-1]*(n+1)
        self.rnk=[0]*(n+1)

    def Find_Root(self,x):
        if self.root[x]<0:
            return x
        else:
            self.root[x]=self.Find_Root(self.root[x])
            return self.root[x]

    def Unite(self,x,y):
        x=self.Find_Root(x)
        y=self.Find_Root(y)
        if x==y:
            return
        elif self.rnk[x]>self.rnk[y]:
            self.root[x]+=self.root[y]
            self.root[y]=x
        else:
            self.root[y]+=self.root[x]
            self.root[x]=y
            if self.rnk[x]==self.rnk[y]:
                self.rnk[y]+=1

    def isSameGroup(self,x,y):
        return self.Find_Root(x)==self.Find_Root(y)

    def Count(self,x):
        return -self.root[self.Find_Root(x)]

h,w=map(int,input().split())
g=[list(input()) for _ in range(h)]
uf=UnionFind(h*w)
dyx=[(1,0),(-1,0),(0,1),(0,-1)]
for i in range(h):
    for j in range(w):
        if g[i][j]==".":
            continue
        p=i*w+j
        for dy,dx in dyx:
            y=i+dy
            x=j+dx
            if 0<=y<h and 0<=x<w:
                if g[y][x]==".":
                    np=y*w+x
                    uf.Unite(p,np)

rt=[0]*(h*w)
for i in range(h*w):
    rt[i]=uf.Find_Root(i)

m=min(rt)
rt=list(map(lambda x:x-m, rt))
m=max(rt)
a=[[0,0] for _ in range(m+1)]
for i in range(h*w):
    y=i//w
    x=i%w
    if g[y][x]=="#":
        a[rt[i]][0]+=1
    else:
        a[rt[i]][1]+=1
ans=0
for i,j in a:
    ans+=i*j

print(ans)

Submission status: Runtime Error

Solution code:
N,H,W=[input() for i in range(3)]
print((N-H+1)*(N-W+1))

Submission status: Runtime Error

Solution code:
n = set[int(input()) for i in range(3)]
print((n[0] - n[1] + 1) * (n[0] - n[2] + 1) )

Submission status: Runtime Error

Solution code:
n = list[int(input()) for i in range(3)]
print((n[0] - n[1] + 1) * (n[0] - n[2] + 1) )

Submission status: Runtime Error

Solution code:
n,h,w=map(int,open(0).read().split);print((n-h+1)*(n-w+1))

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:
a

Submission status: Runtime Error

Solution code:
N,H,W=[int(input()) in _ for range(3)]
print((N-H+1)*(N-W+1))

Submission status: Runtime Error

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

isVisited = [ [False]*W for _ in range(H) ]
dx = [1, -1, 0, 0]
dy = [0, 0, 1, -1]
# (x, y) から行けるペアの数
def dfs( x, y ):
    ans = 0
    isVisited[x][y] = True
    for i in range(4):
        nx = x + dx[i]
        ny = y + dy[i]
        if S[x][y] == '#':
            if 0 <= nx and nx < H and 0 <= ny and ny < W and not isVisited[nx][ny]:
                if S[nx][ny] == '.': ans += dfs( nx, ny )+1
        else:
            if 0 <= nx and nx < H and 0 <= ny and ny < W and not isVisited[nx][ny]:
                if S[nx][ny] == '#': ans += dfs( nx, ny )+1
    return ans


ans = 0
for i in range(H):
    for j in range(W):
        if S[i][j] == '#' and not isVisited:
          ans += dfs( i, j )

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:
n, x, y = map(int, input().split())
print((n - x + 1) * (n - y + 1))

Submission status: Runtime Error

Solution code:
from collections import deque

H, W = map(int, input().split())
S = [input() for _ in range(H)]

res = 0
for i in range(H):
    for j in range(W):
        stack = deque([])
        flag = [[False for _ in range(W)] for _ in range(H)]
        stack.append([i, j])
        flag[i][j] = True
        start = S[i][j]
        while len(stack) > 0:
            y, x = stack.popleft()
            for nx, ny in ([1, 0], [0, 1], [-1, 0], [0, -1]):
                if 0<= x + nx < W and 0 <= y + ny < H:
                    if S[y][x] != S[y+ny][x+nx] and flag[y+ny][x+nx] == False:
                        stack.append([y+ny, x+nx])
                        flag[y+ny][x+nx] = True
                        if S[y+ny][x+nx] != start:
                            res += 1
            
                
            
            
print(res//2)

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:
import collections
import numpy as np
import sys

def search(i, j, S, Q):
    nxt = collections.deque([[i, j]])
    black = 0
    white = 0
    if (S[i][j] == "#"): black += 1
    if (S[i][j] == "."): white += 1
    Q[i][j] = True

    while nxt:
        i, j = nxt.popleft()

        if (j + 1 < S.shape[1]):
            if (S[i][j] != S[i][j + 1] and Q[i][j + 1] == False):
                Q[i][j + 1] = True
                nxt.append([i, j + 1])
                if (S[i][j + 1] == "#"):
                    black += 1
                else:
                    white += 1
        if (i + 1 < S.shape[0]):
            if (S[i][j] != S[i + 1][j] and Q[i + 1][j] == False):
                Q[i + 1][j] = True
                nxt.append([i + 1, j])
                if (S[i + 1][j] == "#"):
                    black += 1
                else:
                    white += 1
        if (j - 1 >= 0 and S[i][j] != S[i][j - 1] and Q[i][j - 1] == False):
            Q[i][j - 1] = True
            nxt.append([i, j - 1])
            if (S[i][j - 1] == "#"):
                black += 1
            else:
                white += 1
        if (i - 1 >= 0 and S[i][j] != S[i - 1][j] and Q[i - 1][j] == False):
            Q[i - 1][j] = True
            nxt.append([i - 1, j])
            if (S[i - 1][j] == "#"):
                black += 1
            else:
                white += 1

    #    print(S)
    #    print(Q)
    return black * white

def parse(inp):
    H, W = map(int, next(inp).split())
    S = np.array([list(next(inp).strip()) for _ in range(H)])
    return S


def main(S):
    H, W = S.shape
    # print(S)
    Q = np.full([H, W], False)
    #     print(Q)

    answer = 0
    for i in range(H):
        for j in range(W):
            if (Q[i][j] == False):
                answer += search(i, j, S, Q)
    return answer

print(main(parse(sys.stdin)))

Submission status: Runtime Error

Solution code:
n,h,w=map(int, input() for i in range(3))
 
print( (n - h + 1) * (n - w + 1))

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:
a,b,c=map(int,input().split())
print((a-b+1)*(a-c+1))

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(200000)

H, W = [int(_) for _ in input().split()]
S = [input() for _ in range(H)]

move = ((1, 0), (-1, 0), (0, 1), (0, -1))
visited = [[False] * W for _ in range(H)]
b, w = 0, 0

def dfs(i, j):
    global b, w

    visited[i][j] = True

    if S[i][j] == '#':
        b += 1
    else:
        w += 1

    for di, dj in move:
        ni, nj = i + di, j + dj
        if 0 <= ni < H and 0 <= nj < W:
            if S[i][j] != S[ni][nj] and not visited[ni][nj]:
                dfs(ni, nj)


result = 0
for i in range(H):
    for j in range(W):
        if visited[i][j]:
            continue
        b, w = 0, 0
        dfs(i, j)
        result += b * w
print(result)

Submission status: Runtime Error

Solution code:
N, Q = list(map(int, input().split(" ")))
A_list = list(map(int, input().split(" ")))

def game(A_list, X, N):
    aoki_A_list = sorted(A_list, key=lambda val: abs(val-X))

    count = 0
    aoki_last_plus = None 
    aoki_minus_plus = None
    aoki_last_minus = None
    while True:
        taka_val = A_list[-count-1]
        aoki_val = aoki_A_list[count]
        aoki_view_val = aoki_val - X

        if aoki_view_val >= 0:
            aoki_last_plus = aoki_val
            now_plus = True
        else:
            now_plus = False

        #print(taka_val, aoki_val, aoki_last_plus, aoki_view_val)

        if aoki_last_plus is not None and aoki_last_plus >= taka_val:
            if not now_plus:
                aoki_fail = False
            if now_plus:
                if aoki_last_plus == taka_val:
                    aoki_fail = True
                else:
                    aoki_fail = False

            break

        if aoki_view_val < 0:
            aoki_last_minus = aoki_val
        
        count += 1

    conflict_count = count

    first_sum = sum(aoki_A_list[:conflict_count])
    if aoki_last_minus is not None:
        aoki_minus_last_i = A_list.index(aoki_last_minus)
    else:
        if conflict_count >= 1:
            aoki_minus_last_i = A_list.index(aoki_A_list[0])
        else:
            aoki_minus_last_i = None

    last_i = aoki_minus_last_i
    if last_i is not None:
        if aoki_fail:
            if last_i >= 1:
                if last_i % 2 == 1:
                    nokori_sum = sum(A_list[0:last_i:2])
                else:
                    nokori_sum = sum(A_list[1:last_i:2])
                
            else:
                nokori_sum = 0
        else:
            if last_i >= 2:
                nokori_sum = sum(A_list[(last_i%2):last_i-1:2])
            else:
                nokori_sum = 0

        out = sum(A_list) - (first_sum + nokori_sum)
    else:
        if N % 2 == 1:
            out = sum(A_list[0::2])
        else:
            out = sum(A_list[1::2])

    return out
        
for i in range(Q):
    X = int(input())
    out = game(A_list, X, N)
    print(out)

Submission status: Runtime Error

Solution code:
h, w = list(map(int, input().split()))
field = []
for i in range(h):
    si = input()
    field.append( [c for c in si] )

def visalizer():
    global field
    print("=========================")
    for i in range(h):
        for j in range(w):
            print(field[i][j], end=' ')
        print('\n')
    print("=========================")

def maeke_last(c):
    if c == "#":
        return "."
    else:
        return "#"

pair_list = []
dx = [0, 0, -1, 1]
dy = [1, -1, 0, 0]
def dfs( last, s_row=0, s_colmun=0, row=0, column=0,):
    global field
    global dict
    if not((0 <= row and row <=h-1) and (0 <=column and column <= w-1)):
        return
    if field[row][column] == '@':
        return

    here = field[row][column]

    if here == last:
        return
    else:
        if not ((s_row, s_colmun) ,(row, column)) in pair_list:
            if here == '.':
                pair_list.append(((s_row, s_colmun) ,(row, column)))


    here_was = field[row][column]
    field[row][column] = '@'
    # visalizer()
    for i in range(len(dx)):
        n_row = row + dx[i]
        n_column = column + dy[i]
        dfs(last = here, s_row = s_row, s_colmun=s_colmun, row=n_row, column=n_column)
    field[row][column] = here_was

# for s_row in range(h):
#     for s_column in range(w):
#         dfs(last = field[s_row][s_column],  s_row=s_row, s_colmun=s_column, row=s_row, column=s_column)

for s_row in range(h):
    for s_column in range(w):
        if field[s_row][s_column] == "#":
            dfs(last = maeke_last(field[s_row][s_column]),  s_row=s_row, s_colmun=s_column, row=s_row, column=s_column)

for ele in pair_list:
    if ele[0]==ele[1] :
        pair_list.remove(ele)
    # pair_list.remove((ele[1], ele[0]))

pair_list2 = []
# for ele in pair_list:
#     if (not (ele[1], ele[0]) in pair_list2) :
#         pair_list2.append(ele)

# for ele in pair_list2:
#     print(ele)
print(len(pair_list))


# visalizer()

Submission status: Runtime Error

Solution code:
from skimage import measure