Problem: There is a farm whose length and width are A yard and B yard, respectively. A farmer, John, made a vertical road and a horizontal road inside the farm from one border to another, as shown below: (The gray part represents the roads.)    What is the area of this yard excluding the roads? Find it.

Submission attempts (in order):
l = input().split()
num_city    = int(l[0])
num_train   = int(l[1])
num_qa      = int(l[2])


str_train = []
end_train = []
for i in range(num_train):
    l = input().split()
    dist = 0
    str_train.append( int(l[dist]) )
    dist = 1
    end_train.append( int(l[dist]) )

str_qa = []
end_qa = []

for i in range(num_qa):
    l = input().split()
    dist = 0
    str_qa.append( int(l[dist]) )
    dist = 1
    end_qa.append( int(l[dist]) )




S_str = []
s = {}
for i in range(num_city + 1):
    S_str.append(s)

for i in range(num_qa):
    str_v = str_qa[i]
    for j in range(0,str_v + 1):
        S_str[j].add(str_v)

S_end = []
s = {}
for i in range(num_city + 1):
    S_end.append(s)

for i in range(num_qa):
    end_v = end_qa[i]
    for j in range(end_v , num_city + 1):
        S_end[j].add(end_v)

for i in range(0,num_qa):
    str_v = str_qa[i]
    s1 = S_str[ str_v ]

    end_v = end_qa[i]
    s2 = S_end[ end_v ]

    s_intersection = s1 & s2

    print(len(s_intersection))


l = input().split()
num_city    = int(l[0])
num_train   = int(l[1])
num_qa      = int(l[2])


str_train = []
end_train = []
for i in range(num_train):
    l = input().split()
    dist = 0
    str_train.append( int(l[dist]) )
    dist = 1
    end_train.append( int(l[dist]) )

str_qa = []
end_qa = []

for i in range(num_qa):
    l = input().split()
    dist = 0
    str_qa.append( int(l[dist]) )
    dist = 1
    end_qa.append( int(l[dist]) )




S_str = []
s = {}
for i in range(num_city + 1):
    S_str.append(s)

for i in range(num_qa):
    str_v = str_qa[i]
    for j in range(0,str_v + 1):
        S_str[j].add(str_v)

S_end = []
s = {}
for i in range(num_city + 1):
    S_end.append(s)

for i in range(num_qa):
    end_v = end_qa[i]
    for j in range(end_v , num_city + 1):
        S_end[j].add(end_v)

for i in range(0,num_qa):
    str_v = str_qa[i]
    s1 = S_str[ str_v ]

    end_v = end_qa[i]
    s2 = S_end[ end_v ]

    s_intersection = s1 & s2

    print(len(s_intersection))


l = input().split()
num_city    = int(l[0])
num_train   = int(l[1])
num_qa      = int(l[2])


str_train = []
end_train = []
for i in range(num_train):
    l = input().split()
    dist = 0
    str_train.append( int(l[dist]) )
    dist = 1
    end_train.append( int(l[dist]) )

str_qa = []
end_qa = []

for i in range(num_qa):
    l = input().split()
    dist = 0
    str_qa.append( int(l[dist]) )
    dist = 1
    end_qa.append( int(l[dist]) )




S_str = []
s = {}
for i in range(num_city + 1):
    S_str.append(s)

for i in range(num_qa):
    str_v = str_qa[i]
    for j in range(0,str_v + 1):
        S_str[j].add(str_v)

S_end = []
s = {}
for i in range(num_city + 1):
    S_end.append(s)

for i in range(num_qa):
    end_v = end_qa[i]
    for j in range(end_v , num_city + 1):
        S_end[j].add(end_v)

for i in range(0,num_qa):
    str_v = str_qa[i]
    s1 = S_str[ str_v ]

    end_v = end_qa[i]
    s2 = S_end[ end_v ]

    s_intersection = s1 & s2

    print(len(s_intersection))


l = input().split()
num_city    = int(l[0])
num_train   = int(l[1])
num_qa      = int(l[2])


str_train = []
end_train = []
for i in range(num_train):
    l = input().split()
    dist = 0
    str_train.append( int(l[dist]) )
    dist = 1
    end_train.append( int(l[dist]) )

str_qa = []
end_qa = []

for i in range(num_qa):
    l = input().split()
    dist = 0
    str_qa.append( int(l[dist]) )
    dist = 1
    end_qa.append( int(l[dist]) )




S_str = []
s = {}
for i in range(num_city + 1):
    S_str.append(s)

for i in range(num_qa):
    str_v = str_qa[i]
    for j in range(0,str_v + 1):
        S_str[j].add(str_v)

S_end = []
s = {}
for i in range(num_city + 1):
    S_end.append(s)

for i in range(num_qa):
    end_v = end_qa[i]
    for j in range(end_v , num_city + 1):
        S_end[j].add(end_v)

for i in range(0,num_qa):
    str_v = str_qa[i]
    s1 = S_str[ str_v ]

    end_v = end_qa[i]
    s2 = S_end[ end_v ]

    s_intersection = s1 & s2

    print(len(s_intersection))


l = input().split()
A = int(l[0])
B = int(l[1])

total = A * B
michi = A + B - 1
hatake = total - michi


print(hatake)

l = input().split()
A = int(l[0])
B = int(l[1])

total = A * B
michi = A + B - 1
hatake = total - michi


print(hatake)

l = input().split()
A = int(l[0])
B = int(l[1])

total = A * B
michi = A + B - 1
hatake = total - michi


print(hatake)

l = input().split()
A = int(l[0])
B = int(l[1])

total = A * B
michi = A + B - 1
hatake = total - michi


print(hatake)

Verdicts: Runtime Error

Runtime Error

Runtime Error

Runtime Error

Accepted

Accepted

Accepted

Accepted