TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: There are N sightseeing spots on the x-axis, numbered 1, 2, ..., N. Spot i is at the point with coordinate A_i. It costs |a - b| yen (the currency of Japan) to travel from a point with coordinate a to another point with coordinate b along the axis.  You planned a trip along the axis. In this plan, you first depart from the point with coordinate 0, then visit the N spots in the order they are numbered, and finally return to the point with coordinate 0.  However, something came up just before the trip, and you no longer have enough time to visit all the N spots, so you decided to choose some i and cancel the visit to Spot i. You will visit the remaining spots as planned in the order they are numbered. You will also depart from and return to the point with coordinate 0 at the beginning and the end, as planned.  For each i = 1, 2, ..., N, find the total cost of travel during the trip when the visit to Spot i is canceled.

Submission attempts (in order):
N = int(input())
A = [0] * (N + 2)
for i, v in enumerate(input().split()):
    A[i+1] = int(v)
num = sum([abs(A[i] - A[i+1]) for i in range(N+1)])
for i in range(N):
    ret = num + abs(A[i-1] - A[i+1]) - (abs(A[i-1] - A[i]) + abs(A[i] - A[i+1]))
    print(ret)

N = int(input())
A = [0] * (N + 2)
for i, v in enumerate(input().split()):
    A[i+1] = int(v)
num = sum([abs(A[i] - A[i+1]) for i in range(N+1)])
for i in range(1,N+1):
    ret = num + abs(A[i-1] - A[i+1]) - (abs(A[i-1] - A[i]) + abs(A[i] - A[i+1]))
    print(ret)

Verdicts: Wrong Answer

Accepted
Problem: There are N sightseeing spots on the x-axis, numbered 1, 2, ..., N. Spot i is at the point with coordinate A_i. It costs |a - b| yen (the currency of Japan) to travel from a point with coordinate a to another point with coordinate b along the axis.  You planned a trip along the axis. In this plan, you first depart from the point with coordinate 0, then visit the N spots in the order they are numbered, and finally return to the point with coordinate 0.  However, something came up just before the trip, and you no longer have enough time to visit all the N spots, so you decided to choose some i and cancel the visit to Spot i. You will visit the remaining spots as planned in the order they are numbered. You will also depart from and return to the point with coordinate 0 at the beginning and the end, as planned.  For each i = 1, 2, ..., N, find the total cost of travel during the trip when the visit to Spot i is canceled.

Submission attempts (in order):
n = int(input())
a = np.array([0] + list(map(int, input().split())) + [0])

whole = np.abs((np.diff(a))).sum()

for i in range(n):
    print(whole - abs(a[i + 1] - a[i]) -
          abs(a[i + 2] - a[i + 1]) + abs(a[i + 2] - a[i]))

import numpy as np

N = int(input())
A = np.array([0] + list(map(int, input().split())) + [0])

diff = np.diff(A)

rev = [x < 0 for x in diff]

is_true = []
for i in range(len(rev) - 1):
    is_true.append(rev[i] & rev[i + 1])

whole = np.abs(diff).sum()

result = []
for i in range(N):
    if is_true[i]:
        result.append(whole)
    else:
        result.append(whole - np.abs(diff)[i] * 2)

print(*result, sep="\n")

import numpy as np
n = int(input())
a = np.array([0] + list(map(int, input().split())) + [0])

whole = np.abs((np.diff(a))).sum()

for i in range(n):
    print(whole - abs(a[i + 1] - a[i]) -
          abs(a[i + 2] - a[i + 1]) + abs(a[i + 2] - a[i]))

Verdicts: Runtime Error

Wrong Answer

Accepted
Problem: There are N sightseeing spots on the x-axis, numbered 1, 2, ..., N. Spot i is at the point with coordinate A_i. It costs |a - b| yen (the currency of Japan) to travel from a point with coordinate a to another point with coordinate b along the axis.  You planned a trip along the axis. In this plan, you first depart from the point with coordinate 0, then visit the N spots in the order they are numbered, and finally return to the point with coordinate 0.  However, something came up just before the trip, and you no longer have enough time to visit all the N spots, so you decided to choose some i and cancel the visit to Spot i. You will visit the remaining spots as planned in the order they are numbered. You will also depart from and return to the point with coordinate 0 at the beginning and the end, as planned.  For each i = 1, 2, ..., N, find the total cost of travel during the trip when the visit to Spot i is canceled.

Submission attempts (in order):
n = int(input())
a = list(map(int, input().split()))

b = [0] + a + [0]
c = []
for i in range(n+1):
    c.append(abs(b[i] - b[i+1]))

for i in range(n):
    ans = l - c[i] - c[i+1]
    ans += abs(b[i] - b[i+2])
    print(ans)


n = int(input())
a = list(map(int, input().split()))

b = [0] + a + [0]
c = []
for i in range(n+1):
    c.append(abs(b[i] - b[i+1]))

l = sum(c)

for i in range(n):
    ans = l - c[i] - c[i+1]
    ans += abs(b[i] - b[i+2])
    print(ans)



Verdicts: Runtime Error

Accepted
Problem: There are N sightseeing spots on the x-axis, numbered 1, 2, ..., N. Spot i is at the point with coordinate A_i. It costs |a - b| yen (the currency of Japan) to travel from a point with coordinate a to another point with coordinate b along the axis.  You planned a trip along the axis. In this plan, you first depart from the point with coordinate 0, then visit the N spots in the order they are numbered, and finally return to the point with coordinate 0.  However, something came up just before the trip, and you no longer have enough time to visit all the N spots, so you decided to choose some i and cancel the visit to Spot i. You will visit the remaining spots as planned in the order they are numbered. You will also depart from and return to the point with coordinate 0 at the beginning and the end, as planned.  For each i = 1, 2, ..., N, find the total cost of travel during the trip when the visit to Spot i is canceled.

Submission attempts (in order):
n=input()
l=[0]+list(map(int,input().split()))+[0]
ans=0
pre=0
for i in l:ans+=abs(pre-i);pre=i
for i in range(1,int(n)+1):
  dif=-abs(l[i]-l[i-1])-abs(l[i]-l[i+1])+abs(l[i-1]-l[i+1])
  if l[i]in(l[i-1],l[i+1]):print(ans)
  elif l[i]<l[i-1]:
    print(ans if l[i+1]<l[i] else ans+dif)
  else:print(ansans if l[i+1]>l[i] else ans+dif)

n=input()
l=[0]+list(map(int,input().split()))+[0]
ans=0
pre=0
for i in l:ans+=abs(pre-i);pre=i
for i in range(1,int(n)+1):
  dif=-abs(l[i]-l[i-1])-abs(l[i]-l[i+1])+abs(l[i-1]-l[i+1])
  if l[i]in(l[i-1],l[i+1]):print(ans)
  elif l[i]<l[i-1]:
    print(ans if l[i+1]<l[i] else ans+dif)
  else:print(ans if l[i+1]>l[i] else ans+dif)

Verdicts: Runtime Error

Accepted
Problem: There are N sightseeing spots on the x-axis, numbered 1, 2, ..., N. Spot i is at the point with coordinate A_i. It costs |a - b| yen (the currency of Japan) to travel from a point with coordinate a to another point with coordinate b along the axis.  You planned a trip along the axis. In this plan, you first depart from the point with coordinate 0, then visit the N spots in the order they are numbered, and finally return to the point with coordinate 0.  However, something came up just before the trip, and you no longer have enough time to visit all the N spots, so you decided to choose some i and cancel the visit to Spot i. You will visit the remaining spots as planned in the order they are numbered. You will also depart from and return to the point with coordinate 0 at the beginning and the end, as planned.  For each i = 1, 2, ..., N, find the total cost of travel during the trip when the visit to Spot i is canceled.

Submission attempts (in order):
N = int(input())
A = [0]
A = A + list(map(int, input().split()))
A.append(0)
print(A)
sumOfRoute = 0
tmp = 0
for a in A:
    sumOfRoute += abs(tmp-a)
    tmp = a

prev = 0
for i in range(1, N+1):
    nexti = A[i+1]
    print(sumOfRoute + abs(prev - nexti) - abs(A[i] - nexti) - abs(prev - A[i]))
    prev = A[i]


N = int(input())
A = [0]
A = A + list(map(int, input().split()))
A.append(0)
sumOfRoute = 0
tmp = 0
for a in A:
    sumOfRoute += abs(tmp-a)
    tmp = a

prev = 0
for i in range(1, N+1):
    nexti = A[i+1]
    print(sumOfRoute + abs(prev - nexti) - abs(A[i] - nexti) - abs(prev - A[i]))
    prev = A[i]


Verdicts: Wrong Answer

Accepted
Problem: There are N sightseeing spots on the x-axis, numbered 1, 2, ..., N. Spot i is at the point with coordinate A_i. It costs |a - b| yen (the currency of Japan) to travel from a point with coordinate a to another point with coordinate b along the axis.  You planned a trip along the axis. In this plan, you first depart from the point with coordinate 0, then visit the N spots in the order they are numbered, and finally return to the point with coordinate 0.  However, something came up just before the trip, and you no longer have enough time to visit all the N spots, so you decided to choose some i and cancel the visit to Spot i. You will visit the remaining spots as planned in the order they are numbered. You will also depart from and return to the point with coordinate 0 at the beginning and the end, as planned.  For each i = 1, 2, ..., N, find the total cost of travel during the trip when the visit to Spot i is canceled.

Submission attempts (in order):
n = int(input())
a = list(map(int, input().split()))
a.append(0)
a.insert(0, 0)
dis = [0] * (n+1)
for i in range(1, n+2):
    dis[i-1] = abs(a[i] - a[i-1])

S = sum(dis)
print(S)
for i in range(1, n+1):
    A = a[i-1]
    B = a[i]
    C = a[i+1]
    if A > C:
        A, C = C, A
    if A<=B<=C:
        print(S)
    else:
        print(S-2*min(abs(A-B), abs(C-B)))

n = int(input())
a = list(map(int, input().split()))
a.append(0)
a.insert(0, 0)
dis = [0] * (n+1)
for i in range(1, n+2):
    dis[i-1] = abs(a[i] - a[i-1])

S = sum(dis)
for i in range(1, n+1):
    A = a[i-1]
    B = a[i]
    C = a[i+1]
    if A > C:
        A, C = C, A
    if A<=B<=C:
        print(S)
    else:
        print(S-2*min(abs(A-B), abs(C-B)))

Verdicts: Wrong Answer

Accepted
Problem: There are N sightseeing spots on the x-axis, numbered 1, 2, ..., N. Spot i is at the point with coordinate A_i. It costs |a - b| yen (the currency of Japan) to travel from a point with coordinate a to another point with coordinate b along the axis.  You planned a trip along the axis. In this plan, you first depart from the point with coordinate 0, then visit the N spots in the order they are numbered, and finally return to the point with coordinate 0.  However, something came up just before the trip, and you no longer have enough time to visit all the N spots, so you decided to choose some i and cancel the visit to Spot i. You will visit the remaining spots as planned in the order they are numbered. You will also depart from and return to the point with coordinate 0 at the beginning and the end, as planned.  For each i = 1, 2, ..., N, find the total cost of travel during the trip when the visit to Spot i is canceled.

Submission attempts (in order):
N = int(input())
A = list(map(int, input().split()))
A.append(0)
sum_val = 0
now = 0
for i in range(N + 1):
    sum_val += abs(A[i] - now)
    now = A[i]

for i in range(1 , N + 1):
    if A[i - 1] >= 0:
        if A[i - 1] > A[i]:
            print(sum_val - abs(A[i - 1] - A[i - 2]) * 2)
        else:
            print(sum_val)
    elif A[i - 1] < 0:
        if A[i - 1] < A[i]:
            print(sum_val - abs(A[i - 1] - A[i - 2]) * 2)
        else:
            print(sum_val)


N = int(input())
A = list(map(int, input().split()))
A.append(0)
A.insert(0, 0)
sum_val = 0
now = 0
for i in range(N + 1):
    sum_val += abs(A[i] - A[i + 1])

for i in range(1 , N + 1):
    print(sum_val - (abs(A[i-1] - A[i]) + abs(A[i] - A[i + 1])) + abs(A[i - 1] - A[i + 1]))


Verdicts: Wrong Answer

Accepted
Problem: There are N sightseeing spots on the x-axis, numbered 1, 2, ..., N. Spot i is at the point with coordinate A_i. It costs |a - b| yen (the currency of Japan) to travel from a point with coordinate a to another point with coordinate b along the axis.  You planned a trip along the axis. In this plan, you first depart from the point with coordinate 0, then visit the N spots in the order they are numbered, and finally return to the point with coordinate 0.  However, something came up just before the trip, and you no longer have enough time to visit all the N spots, so you decided to choose some i and cancel the visit to Spot i. You will visit the remaining spots as planned in the order they are numbered. You will also depart from and return to the point with coordinate 0 at the beginning and the end, as planned.  For each i = 1, 2, ..., N, find the total cost of travel during the trip when the visit to Spot i is canceled.

Submission attempts (in order):
N = int(input())
A = list(map(int,input().split()))
 
for i in range(N):
  now = 0
  ans = 0
  for j in range(N):
    if i != j:
      next = A[j]
      ans += abs(next - now)
      now = next
  ans += abs(A[-1])
  print(ans)

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

for i in range(N):
  now = 0
  ans = 0
  B = [A[j] for j in range(N) if j != i]
  for next in A:
    ans += abs(next - now)
    now = next
  ans += abs(B[-1])
  print(ans)


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

for i in range(N):
  now = 0
  ans = 0
  for j in range(N):
    if i != j:
      next = A[j]
      ans += abs(next - now)
      now = next
  ans += abs(B[-1])
  print(ans)


N = int(input())
A = [0]
A = A + list(map(int,input().split()))
A = A + [0]

D = 0

for i in range(N + 1):
  D += abs(A[i + 1] - A[i])
  
for i in range(1,N + 1):
  ans = D + abs(A[i + 1] - A[i - 1]) - (abs(A[i] - A[i - 1]) + abs(A[i + 1] - A[i]))
  print(ans)

Verdicts: Wrong Answer

Wrong Answer

Runtime Error

Accepted
Problem: On a two-dimensional plane, there are N red points and N blue points. The coordinates of the i-th red point are (a_i, b_i), and the coordinates of the i-th blue point are (c_i, d_i).  A red point and a blue point can form a _friendly pair_ when, the x-coordinate of the red point is smaller than that of the blue point, and the y-coordinate of the red point is also smaller than that of the blue point.  At most how many friendly pairs can you form? Note that a point cannot belong to multiple pairs.

Submission attempts (in order):
# ARC092C - 2D Plane 2N Points (ABC091C)
# greedy algorithm
def main():
    N = int(input())
    A = sorted(
        [tuple(map(int, input().split())) for _ in range(N)],
        key=lambda x: x[1],
        reverse=1,
    )
    B = sorted([tuple(map(int, input().split())) for _ in range(N)])
    ans, memo = 0, set()
    for bx, by in B:
        for i, (ax, ay) in enumerate(A):
            if i not in memo and ax < bx and ay < by:
                ans += 1
                memo |= {i}
    print(ans)


if __name__ == "__main__":
    main()

# ABC091C - 2D Plane 2N Points (ARC092C)
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    A = sorted(
        [tuple(map(int, input().split())) for _ in range(N)],
        key=lambda x: x[1],
        reverse=1,
    )
    B = sorted([tuple(map(int, input().split())) for _ in range(N)])
    ans, memo = 0, set()
    for bx, by in B:
        for i, (ax, ay) in enumerate(A):
            if i not in memo and ax < bx and ay < by:
                ans += 1
                memo |= {i}
                break
    print(ans)


if __name__ == "__main__":
    main()


Verdicts: Wrong Answer

Accepted
Problem: On a two-dimensional plane, there are N red points and N blue points. The coordinates of the i-th red point are (a_i, b_i), and the coordinates of the i-th blue point are (c_i, d_i).  A red point and a blue point can form a _friendly pair_ when, the x-coordinate of the red point is smaller than that of the blue point, and the y-coordinate of the red point is also smaller than that of the blue point.  At most how many friendly pairs can you form? Note that a point cannot belong to multiple pairs.

Submission attempts (in order):
n = int(input())
R = [list(map(int, input().split())) for i in range(n)]
B = [list(map(int, input().split())) for i in range(n)]
B.sort(key = lambda x:x[0])
R.sort(key = lambda x:x[1], reverse = True)

print(R)
ans = 0
for bx,by in B:
    print(bx,by)
    for i in range(len(R)):
        if R[i][0] < bx and R[i][1] < by:
            print(R[i],"とマッチ")
            del R[i]
            ans += 1
            break
print(ans)



n = int(input())
R = [list(map(int, input().split())) for i in range(n)]
B = [list(map(int, input().split())) for i in range(n)]
B.sort(key = lambda x:x[0])
R.sort(key = lambda x:x[1], reverse = True)

#print(R)
ans = 0
for bx,by in B:
 #   print(bx,by)
    for i in range(len(R)):
        if R[i][0] < bx and R[i][1] < by:
  
            del R[i]
            ans += 1
            break
print(ans)



Verdicts: Wrong Answer

Accepted
Problem: On a two-dimensional plane, there are N red points and N blue points. The coordinates of the i-th red point are (a_i, b_i), and the coordinates of the i-th blue point are (c_i, d_i).  A red point and a blue point can form a _friendly pair_ when, the x-coordinate of the red point is smaller than that of the blue point, and the y-coordinate of the red point is also smaller than that of the blue point.  At most how many friendly pairs can you form? Note that a point cannot belong to multiple pairs.

Submission attempts (in order):
N = int(input())
R = [tuple(map(int, input().split())) for _ in range(N)]
B = [tuple(map(int, input().split())) for _ in range(N)]


def solve(i, p):
    if i == N:
        print(p)
        return len(p)

    s = []
    a, b = R[i]
    for c, d in B:
        if (c, d) in p:
            continue
        if a < c and b < d:
            
            s.append(solve(i+1, p + [(c, d)]))
    
    s.append(solve(i+1, p))
    return max(s)


print(solve(0, []))


N = int(input())
R = [tuple(map(int, input().split())) for _ in range(N)]
B = [tuple(map(int, input().split())) for _ in range(N)]


R.sort(reverse=True, key=lambda k: k[1])
B.sort()

p = []
q = []
for c, d in B:
    for a, b in R:
        if (a, b) in p:
            continue
        if a < c and b < d:
            p.append((a, b))
            q.append((c, d))
            break

print(len(p))


Verdicts: Wrong Answer

Accepted
Problem: On a two-dimensional plane, there are N red points and N blue points. The coordinates of the i-th red point are (a_i, b_i), and the coordinates of the i-th blue point are (c_i, d_i).  A red point and a blue point can form a _friendly pair_ when, the x-coordinate of the red point is smaller than that of the blue point, and the y-coordinate of the red point is also smaller than that of the blue point.  At most how many friendly pairs can you form? Note that a point cannot belong to multiple pairs.

Submission attempts (in order):
N = int(input())
r = [list(map(int, input().split())) for _ in range(N)]
b = [list(map(int, input().split())) for _ in range(N)]

r.sort(key=lambda val:val[1], reverse=True)
b.sort()

ans = 0

for bb in b:
    for i in range(N):
        if bb[0] > r[i][0]:
            ans += 1
            N -= 1
            r.pop(i)
            break

print(ans)
print(r)
print(b)


N = int(input())
r = [list(map(int, input().split())) for _ in range(N)]
b = [list(map(int, input().split())) for _ in range(N)]

r.sort(key=lambda val:val[1], reverse=True)
b.sort(reverse=True)

ans = 0

for bb in b:
    for i in range(N):
        if bb[1] > r[i][1]:
            ans += 1
            N -= 1
            r.pop(i)
            break

print(ans)


N = int(input())
r = [list(map(int, input().split())) for _ in range(N)]
b = [list(map(int, input().split())) for _ in range(N)]

r.sort(key=lambda val:val[1], reverse=True)
b.sort()

ans = 0

for bb in b:
    for i in range(N):
        if bb[0] > r[i][0] and bb[1] > r[i][1]:
            ans += 1
            N -= 1
            r.pop(i)
            break

print(ans)


Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: On a two-dimensional plane, there are N red points and N blue points. The coordinates of the i-th red point are (a_i, b_i), and the coordinates of the i-th blue point are (c_i, d_i).  A red point and a blue point can form a _friendly pair_ when, the x-coordinate of the red point is smaller than that of the blue point, and the y-coordinate of the red point is also smaller than that of the blue point.  At most how many friendly pairs can you form? Note that a point cannot belong to multiple pairs.

Submission attempts (in order):
N=int(input())
R=sorted([list(map(int,input().split())) for i in range(N)])
B=sorted([list(map(int,input().split())) for i in range(N)])
ans=0
for i in range(N-1,-1,-1):
    a=[-1,-1]
    x=-1
    for j in range(len(R)):
        if B[i][0]>R[j][0] and B[i][1]>R[j][1]:
            if a[1]<R[j][1]:
                a=R[j]
                x=j
    if x>=0:
        print(i,x)
        del R[x]
        ans+=1
print(ans)

N=int(input())
R=sorted([list(map(int,input().split())) for i in range(N)])
B=sorted([list(map(int,input().split())) for i in range(N)])
ans=0
for i in range(N):
    a=[-1,-1]
    x=-1
    for j in range(len(R)):
        if B[i][0]>R[j][0] and B[i][1]>R[j][1]:
            if a[1]<R[j][1]:
                a=R[j]
                x=j
    if x>=0:
        del R[x]
        ans+=1
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: On a two-dimensional plane, there are N red points and N blue points. The coordinates of the i-th red point are (a_i, b_i), and the coordinates of the i-th blue point are (c_i, d_i).  A red point and a blue point can form a _friendly pair_ when, the x-coordinate of the red point is smaller than that of the blue point, and the y-coordinate of the red point is also smaller than that of the blue point.  At most how many friendly pairs can you form? Note that a point cannot belong to multiple pairs.

Submission attempts (in order):
from collections import namedtuple

Point = namedtuple('Point', ['x', 'y'])

N = int(input())

R = []
for _ in range(N):
    x, y = map(int, input().split())
    R.append(Point(x, y))

B = []
for _ in range(N):
    x, y = map(int, input().split())
    B.append(Point(x, y))

E = [[] for _ in range(N)]
for i, r in enumerate(R):
    for j, b in enumerate(B):
        if r.x < b.x and r.y < b.y:
            E[i].append(j)


class BipartiteMatching:
    def __init__(self, max_u: int, max_v: int, edges):
        self.max_u = max_u
        self.max_v = max_v
        self.edges = edges  
        self.__match = None

    def dfs(self, v: int, visited: set) -> bool:
        for u in self.edges[v]:
            if u in visited:
                continue
            visited.add(u)

            if self.__match[u] == -1 or self.dfs(self.__match[u], visited):
                self.__match[u] = v
                return True
        return False

    def execute(self):
        self.__match = [-1 for _ in range(self.max_u)]
        return sum(self.dfs(u, set()) for u in range(self.max_u))


print(BipartiteMatching(N, E).execute())


from collections import namedtuple

Point = namedtuple('Point', ['x', 'y'])

N = int(input())

R = []
for _ in range(N):
    x, y = map(int, input().split())
    R.append(Point(x, y))

B = []
for _ in range(N):
    x, y = map(int, input().split())
    B.append(Point(x, y))

E = [[] for _ in range(N)]
for i, r in enumerate(R):
    for j, b in enumerate(B):
        if r.x < b.x and r.y < b.y:
            E[i].append(j)


class BipartiteMatching:
    def __init__(self, max_u: int, edges):
        self.max_u = max_u
        self.edges = edges  
        self.__match = None

    def dfs(self, v: int, visited: set) -> bool:
        for u in self.edges[v]:
            if u in visited:
                continue
            visited.add(u)

            if self.__match[u] == -1 or self.dfs(self.__match[u], visited):
                self.__match[u] = v
                return True
        return False

    def execute(self):
        self.__match = [-1 for _ in range(self.max_u)]
        return sum(self.dfs(u, set()) for u in range(self.max_u))


print(BipartiteMatching(N, E).execute())


Verdicts: Runtime Error

Accepted
Problem: On a two-dimensional plane, there are N red points and N blue points. The coordinates of the i-th red point are (a_i, b_i), and the coordinates of the i-th blue point are (c_i, d_i).  A red point and a blue point can form a _friendly pair_ when, the x-coordinate of the red point is smaller than that of the blue point, and the y-coordinate of the red point is also smaller than that of the blue point.  At most how many friendly pairs can you form? Note that a point cannot belong to multiple pairs.

Submission attempts (in order):
N = int(input())
ab = [[0, 0] for i in range(N)]
b = [0]*N
cd = [[0, 0] for i in range(N)]
d = [0]*N

for i in range(N):
    ab[i] = list(map(int, input().split()))
for i in range(N):
    cd[i] = list(map(int, input().split()))

points2 = [[] for i in range(N)]
ab.sort(key=lambda x: x[0])
ab.sort(key=lambda x: x[1])

for i in range(N):
    for j in range(N):
        if ab[i][0] < cd[j][0] and ab[i][1] < cd[j][1]:
            points2[j].append(i)

points2.sort(key=lambda x: len(x))
ans = 0

for i in range(N):
    if len(points[i]) == 0:
        continue
    for j in range(i+1, N):
        if points[i][0] in points[j]:
            points[j].pop(points[j].index(points[i][0]))
    ans += 1
print(ans)

N = int(input())
ab = [[0, 0] for i in range(N)]
b = [0]*N
cd = [[0, 0] for i in range(N)]
d = [0]*N

for i in range(N):
    ab[i] = list(map(int, input().split()))
for i in range(N):
    cd[i] = list(map(int, input().split()))

points = [[] for i in range(N)]
points2 = [[] for i in range(N)]
cd.sort(key=lambda x: x[0])
ab.sort(key=lambda x: x[1], reverse=True)

points.sort(key=lambda x: len(x))
ans = 0

for i in range(N):
    for j in range(N):
        if ab[i][0] < cd[j][0] and ab[i][1] < cd[j][1]:
            ans += 1
            cd[j][0] = -1
            break
print(ans)


Verdicts: Runtime Error

Accepted
Problem: On a two-dimensional plane, there are N red points and N blue points. The coordinates of the i-th red point are (a_i, b_i), and the coordinates of the i-th blue point are (c_i, d_i).  A red point and a blue point can form a _friendly pair_ when, the x-coordinate of the red point is smaller than that of the blue point, and the y-coordinate of the red point is also smaller than that of the blue point.  At most how many friendly pairs can you form? Note that a point cannot belong to multiple pairs.

Submission attempts (in order):
n=int(input())
a=[list(map(int,input().split()))for i in range(n)]
b=[list(map(int,input().split()))for i in range(n)]
a.sort(key=lambda x:x[0])
b.sort(key=lambda x:x[1],reverse=1)
ans=0
i,j=0,0
while i<n and j<n:
  if a[i][0]>b[j][0]:
    j+=1
    continue
  elif a[i][1]>b[j][1]:
    i+=1
  else:
    ans+=1
print(ans)

n=int(input())
a=[list(map(int,input().split()))for i in range(n)]
b=[list(map(int,input().split()))for i in range(n)]
a.sort(key=lambda x:x[1],reverse=1)
b.sort(key=lambda x:x[0])
ans=0
for i in a:
  for j in b:
    if i[0]<j[0] and i[1]<j[1]:
      b.remove(j)
      ans+=1
      break
print(ans)

Verdicts: Time Limit Exceeded

Accepted
Problem: On a two-dimensional plane, there are N red points and N blue points. The coordinates of the i-th red point are (a_i, b_i), and the coordinates of the i-th blue point are (c_i, d_i).  A red point and a blue point can form a _friendly pair_ when, the x-coordinate of the red point is smaller than that of the blue point, and the y-coordinate of the red point is also smaller than that of the blue point.  At most how many friendly pairs can you form? Note that a point cannot belong to multiple pairs.

Submission attempts (in order):
N=int(input())

red=[]
blue=[]

for i in range(N):
    a,b=map(int,input().split())
    red.append((a,b))

for i in range(N):
    c,d=map(int,input().split())
    blue.append((c,d))

red=sorted(red,key=lambda x:-x[1])
blue=sorted(blue,key=lambda x:x[0])

answer=0
for i,b in enumerate(blue):
    for j,r in enumerate(red):
        if red[0]<blue[0] and red[1]<blue[1]:
            answer+=1
            red.pop(j)
            break

print(answer)

N=int(input())

red=[]
blue=[]

for i in range(N):
    a,b=map(int,input().split())
    red.append((a,b))

for i in range(N):
    c,d=map(int,input().split())
    blue.append((c,d))

red=sorted(red,key=lambda x:-x[1])
blue=sorted(blue,key=lambda x:x[0])

answer=0
for i,b in enumerate(b):
    for j,r in enumerate(r):
        if red[0]<blue[0] and red[1]<blue[1]:
            answer+=1
            red.pop(j)
            break

print(answer)

N=int(input())

red=[]
blue=[]

for i in range(N):
    a,b=map(int,input().split())
    red.append((a,b))

for i in range(N):
    c,d=map(int,input().split())
    blue.append((c,d))

red=sorted(red,key=lambda x:-x[1])
blue=sorted(blue,key=lambda x:x[0])

answer=0
for i,b in enumerate(blue):
    for j,r in enumerate(red):
        if r[0]<b[0] and r[1]<b[1]:
            answer+=1
            red.pop(j)
            break

print(answer)

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: On a two-dimensional plane, there are N red points and N blue points. The coordinates of the i-th red point are (a_i, b_i), and the coordinates of the i-th blue point are (c_i, d_i).  A red point and a blue point can form a _friendly pair_ when, the x-coordinate of the red point is smaller than that of the blue point, and the y-coordinate of the red point is also smaller than that of the blue point.  At most how many friendly pairs can you form? Note that a point cannot belong to multiple pairs.

Submission attempts (in order):
s=input()
k=int(input())
l=list(s)
for i in range(len(s)):
 if 26-(ord(s[i])-ord("a"))<=k:k-=26-(ord(s[i])-ord("a"));l[i]="a"
print("".join(l[:-1]+list(chr((ord(l[-1])-97+k)%26+97))))

n = int(input())
ab = [list(map(int, input().split())) for i in range(n)]
cd = [list(map(int, input().split())) for i in range(n)]
ab.sort()
cd.sort()
ans = 0
for i in cd:
    c, d = i
    flag = False
    cur = 0
    difference = float("inf")
    for i in range(n):
        a, b = ab[i]
        if a < c and b < d:
            if difference > d - b:
                difference = min(difference, d - b)
                flag = True
                cur = i
    if flag:
        ab[cur] = [float("inf"), float("inf")]
        ans += 1
print(ans)

Verdicts: Runtime Error

Accepted
Problem: On a two-dimensional plane, there are N red points and N blue points. The coordinates of the i-th red point are (a_i, b_i), and the coordinates of the i-th blue point are (c_i, d_i).  A red point and a blue point can form a _friendly pair_ when, the x-coordinate of the red point is smaller than that of the blue point, and the y-coordinate of the red point is also smaller than that of the blue point.  At most how many friendly pairs can you form? Note that a point cannot belong to multiple pairs.

Submission attempts (in order):
N = int(input())
A = list(map(int, input().split()))

sum_even = sum(map(lambda i: A[i] if A[i] > 0 else 0, range(1, N, 2)))
sum_odd  = sum(map(lambda i: A[i] if A[i] > 0 else 0, range(0, N, 2)))

if sum_even == 0 and sum_odd == 0:
    max_ = max(A)
    print(max_)
    index = A.index(max_)
    print(len(A)-1)
    for _ in range(index):
        print(1)
    for j in range(N-index-1):
        print(N - index - j)
    exit()

print(max(sum_even, sum_odd))
EVEN = sum_even >= sum_odd
ans = []

if EVEN:
    A = A[1:]
    ans.append(1)
if len(A)%2 == 0:
    ans.append(len(A))
    A = A[:-1]

while len(A) > 1:
    if A[0] <= 0:
        ans.append(1)
        ans.append(1)
        A = A[2:]
    else:
        if A[2] <= 0:
            ans.append(3)
            A.pop(2)
            if len(A) == 2:
                ans.append(2)
                A.pop(1)
            else:
                ans.append(3)
                A.pop(2)
        else:
            ans.append(2)
            A.pop(1)
            A[0] += A.pop(1)
print(len(ans))
for a in ans:
    print(a)

N = int(input())

red = []
blue = []
count = 0

dellist = lambda items, indexes: [item for index, item in enumerate(items) if index not in indexes]

for n in range(2*N):
    v = list(map(int, input().split()))
    if n < N:
        red.append(v)
    else:
        blue.append(v)


for x in range(2*N):

    for k in range(2):
        r_remove_list = []
        b_remove_list = []

        for i, b in enumerate(blue):
            if b[k] == x:
                cand = -1
                max_ = -1
                max_j = -1
                for j, r in enumerate(red):
                    if r[k] < x:
                        if r[1-k] < b[1-k] and max_ < r[1-k]:
                            cand = j
                            max_ = r[1-k]
                            max_j = j
                if cand >= 0:
                    r_remove_list.append(max_j)
                    b_remove_list.append(i)

        blue = dellist(blue,b_remove_list)
        red = dellist(red,r_remove_list)
        count += len(b_remove_list)


print(count)

Verdicts: Runtime Error

Accepted
Problem: On a two-dimensional plane, there are N red points and N blue points. The coordinates of the i-th red point are (a_i, b_i), and the coordinates of the i-th blue point are (c_i, d_i).  A red point and a blue point can form a _friendly pair_ when, the x-coordinate of the red point is smaller than that of the blue point, and the y-coordinate of the red point is also smaller than that of the blue point.  At most how many friendly pairs can you form? Note that a point cannot belong to multiple pairs.

Submission attempts (in order):
 N = int(input())
 ab = [tuple(map(int,input().split())) for i in range(N)]
 cd = [tuple(map(int,input().split())) for i in range(N)]
 result = []
 for i in range(N):
     xr , yr = ab[i]
     xb, yb = cd[i]
     if xr < xb or yr < yb:
         print(xr, yr, xb, yb)
         result.append('BINGO!!!')
 print(len(result))

 N = int(input())
 ab = sorted([ tuple(map(int, input().split())) for x in range(N)], key=lambda x:x[1], reverse=True)
 cd = sorted([ tuple(map(int, input().split())) for x in range(N)])
 resultx = []
 resulty = []
 for xb, yb in list(cd):
     for xr, yr in list(ab):
         if (xr, yr) in resultx:
             continue
         if xr < xb and yr < yb:
             resultx.append((xr,yr))
             resulty.append((xb,yb))
             break

 print(len(resultx))

 N = int(input())
 ab = [tuple(map(int,input().split())) for i in range(N)]
 cd = [tuple(map(int,input().split())) for i in range(N)]
 result = []
 for i in range(N):
     xr , yr = ab[i]
     xb, yb = cd[i]
     if xr < xb or yr < yb:
        print(xr, yr, xb, yb)
        result.append('BINGO!!!')
 print(len(result))


 N = int(input())
 ab = [tuple(map(int,input().split())) for i in range(N)]
 cd = [tuple(map(int,input().split())) for i in range(N)]
 result = []
 for i in range(N):
     xr , yr = ab[i]
     xb, yb = cd[i]
     if xr < xb and yr < yb:
         result.append('BINGO!!!')
 print(len(result))

N = int(input())
ab = [tuple(map(int,input().split())) for i in range(N)]
cd = [tuple(map(int,input().split())) for i in range(N)]
result = []
for i in range(N):
    xr , yr = ab[i]
    xb, yb = cd[i]
    if xr < xb or yr < yb:
        result.append('BINGO!!!')
print(len(result))

N = int(input())
ab = sorted([ tuple(map(int, input().split())) for x in range(N)], key=lambda x:x[1],reverse=True)
cd = sorted([ tuple(map(int, input().split())) for x in range(N)])
resultx = []
resulty = []
for xb, yb in list(cd):
    for xr, yr in list(ab):
        if (xr, yr) in resultx:
            continue
        if xr < xb and yr < yb:
            resultx.append((xr,yr))
            resulty.append((xb,yb))
            break

print(len(resultx))

Verdicts: Runtime Error

Runtime Error

Runtime Error

Runtime Error

Wrong Answer

Accepted
Problem: There is a grid with infinitely many rows and columns. In this grid, there is a rectangular region with consecutive N rows and M columns, and a card is placed in each square in this region. The front and back sides of these cards can be distinguished, and initially every card faces up.  We will perform the following operation once for each square contains a card:    * For each of the following nine squares, flip the card in it if it exists: the target square itself and the eight squares that shares a corner or a side with the target square.  It can be proved that, whether each card faces up or down after all the operations does not depend on the order the operations are performed. Find the number of cards that face down after all the operations.

Submission attempts (in order):
n,m=map(int,input().split())
if n==1 and m==1:
    print(1)
elif n==1 or M==1:
    print(n*m-2)
else:
    print((m-2)*(n-2))


n,m=map(int,input().split())
if n==1 and m==1:
    print(1)
elif n==1 or m==1:
    print(n*m-2)
else:
    print((m-2)*(n-2))


Verdicts: Runtime Error

Accepted
Problem: There is a grid with infinitely many rows and columns. In this grid, there is a rectangular region with consecutive N rows and M columns, and a card is placed in each square in this region. The front and back sides of these cards can be distinguished, and initially every card faces up.  We will perform the following operation once for each square contains a card:    * For each of the following nine squares, flip the card in it if it exists: the target square itself and the eight squares that shares a corner or a side with the target square.  It can be proved that, whether each card faces up or down after all the operations does not depend on the order the operations are performed. Find the number of cards that face down after all the operations.

Submission attempts (in order):
if N > 1 and M > 1:
    four = 4
    six = (N - 2) * 2 + (M - 2) * 2
    nine = N * M - four - six
    print(nine)
else:
    two = 2
    three = N * M - two
    print(three)

import sys

N, M = map(int, sys.stdin.readline().split())

if N == 1 and M == 1:
    print(1)
elif N == 1 or M == 1:
    two = 2
    three = N * M - two
    print(three)
else:
    four = 4
    six = (N - 2) * 2 + (M - 2) * 2
    nine = N * M - four - six
    print(nine)

Verdicts: Runtime Error

Accepted
Problem: There is a grid with infinitely many rows and columns. In this grid, there is a rectangular region with consecutive N rows and M columns, and a card is placed in each square in this region. The front and back sides of these cards can be distinguished, and initially every card faces up.  We will perform the following operation once for each square contains a card:    * For each of the following nine squares, flip the card in it if it exists: the target square itself and the eight squares that shares a corner or a side with the target square.  It can be proved that, whether each card faces up or down after all the operations does not depend on the order the operations are performed. Find the number of cards that face down after all the operations.

Submission attempts (in order):
N,M=map(int,input().split())
if N==1:
  if M==1:
    print(1)
  else:
    print(M-2)
elif M==1:
  print(N-2)
else:
  print(N*M-max(0,N-2)-max(0,M-2))

N,M=map(int,input().split())
if N==1:
  if M==1:
    print(1)
  else:
    print(M-2)
elif M==1:
  print(N-2)
else:
  print(N*M-2*max(0,N-1)-2*max(0,M-1))

Verdicts: Wrong Answer

Accepted
Problem: There is a grid with infinitely many rows and columns. In this grid, there is a rectangular region with consecutive N rows and M columns, and a card is placed in each square in this region. The front and back sides of these cards can be distinguished, and initially every card faces up.  We will perform the following operation once for each square contains a card:    * For each of the following nine squares, flip the card in it if it exists: the target square itself and the eight squares that shares a corner or a side with the target square.  It can be proved that, whether each card faces up or down after all the operations does not depend on the order the operations are performed. Find the number of cards that face down after all the operations.

Submission attempts (in order):
N,N = list(map(int,input().split()))
if N == 1 and M == 1:
    print(1)
elif N == 1 or M == 1:
    print(max([N,M]) -2)
else:
    print( N * M + 4 - 2*(N+M))


N,M = list(map(int,input().split()))
if N == 1 and M == 1:
    print(1)
elif N == 1 or M == 1:
    print(max([N,M]) -2)
else:
    print( N * M + 4 - 2*(N+M))


Verdicts: Runtime Error

Accepted
Problem: There is a grid with infinitely many rows and columns. In this grid, there is a rectangular region with consecutive N rows and M columns, and a card is placed in each square in this region. The front and back sides of these cards can be distinguished, and initially every card faces up.  We will perform the following operation once for each square contains a card:    * For each of the following nine squares, flip the card in it if it exists: the target square itself and the eight squares that shares a corner or a side with the target square.  It can be proved that, whether each card faces up or down after all the operations does not depend on the order the operations are performed. Find the number of cards that face down after all the operations.

Submission attempts (in order):
n,m=map(int,input())
n,m=min(n,m),max(n,m)
if n==1:
    print(max(0,m-2))
    exit()
else:
    print(max(0,(n-2)*(m-2)))

n,m=map(int,input().split())
n,m=min(n,m),max(n,m)
if n==1:
    if m==1:
        print(1)
    else:
        print(max(0,m-2))
        exit()
else:
    print(max(0,(n-2)*(m-2)))

Verdicts: Runtime Error

Accepted
Problem: There is a grid with infinitely many rows and columns. In this grid, there is a rectangular region with consecutive N rows and M columns, and a card is placed in each square in this region. The front and back sides of these cards can be distinguished, and initially every card faces up.  We will perform the following operation once for each square contains a card:    * For each of the following nine squares, flip the card in it if it exists: the target square itself and the eight squares that shares a corner or a side with the target square.  It can be proved that, whether each card faces up or down after all the operations does not depend on the order the operations are performed. Find the number of cards that face down after all the operations.

Submission attempts (in order):
def main():
    n = int(input())
    res = 0

    for (a, k) in [[int(x) for x in input().split()] for _ in range(n)]:
        while a >= k:
            m, u, v = a // k, (a - k * m), (m + 1)
            if a % k == 0 or u % v == 0:
                res ^= m
                break
            x = (u // v)
            a -= (x + 1) * v

    print('Takahashi' if res != 0 else 'Aoki')


if __name__ == "__main__":
    main()


def main():
    n, m = map(int, input().split())
    print(compute(min(n, m), max(n, m)))


def compute(n, m):
    if n == 1 and m == 1:
        return 1
    if n == 1:
        return max(0, m - 2)
    return (n - 2) * (m - 2)


if __name__ == "__main__":
    main()


Verdicts: Runtime Error

Accepted
Problem: There is a grid with infinitely many rows and columns. In this grid, there is a rectangular region with consecutive N rows and M columns, and a card is placed in each square in this region. The front and back sides of these cards can be distinguished, and initially every card faces up.  We will perform the following operation once for each square contains a card:    * For each of the following nine squares, flip the card in it if it exists: the target square itself and the eight squares that shares a corner or a side with the target square.  It can be proved that, whether each card faces up or down after all the operations does not depend on the order the operations are performed. Find the number of cards that face down after all the operations.

Submission attempts (in order):
    H, W =[int(i) for i in input().split()]
    if H==1 and W!=1:
      print(max(0, W-2))
    elif W==1 and H!=1:
      print(max(0, H-2))
    else:
      print(max(H-2, 0)*max(W-2, 0))

H, W =[int(i) for i in input().split()]
if H*W=1:
     print(1)
elif H==1 and W!=1:
     print(max(0, W-2))
elif W==1 and H!=1:
     print(max(0, H-2))
else:
     print(max(H-2, 0)*max(W-2, 0))

H,W =[int(i) for i in input().split()]
if H*W=1:
    print(1)
elif H==1 and W!=1:
    print(max(0, W-2))
elif W==1 and H!=1:
    print(max(0, H-2))
else:
    print(max(H-2, 0)*max(W-2, 0))


H,W =[int(i) for i in input().split()]
if H*W==1:
    print(1)
elif H==1 and W!=1:
    print(max(0, W-2))
elif W==1 and H!=1:
    print(max(0, H-2))
else:
    print(max(H-2, 0)*max(W-2, 0))


Verdicts: Runtime Error

Runtime Error

Runtime Error

Accepted
Problem: There is a grid with infinitely many rows and columns. In this grid, there is a rectangular region with consecutive N rows and M columns, and a card is placed in each square in this region. The front and back sides of these cards can be distinguished, and initially every card faces up.  We will perform the following operation once for each square contains a card:    * For each of the following nine squares, flip the card in it if it exists: the target square itself and the eight squares that shares a corner or a side with the target square.  It can be proved that, whether each card faces up or down after all the operations does not depend on the order the operations are performed. Find the number of cards that face down after all the operations.

Submission attempts (in order):


n, m = map(int, input().split())

if n == 1 or m == 1:  
    print(f"kasu")
    print(1 / 0)



n, m = map(int, input().split())
if n == m == 1:
    print(1)
elif n == 1 or m == 1:
    print(max(n, m) - 2)
else:
    print(n * m - (n * 2 + (m - 2) * 2))


Verdicts: Runtime Error

Accepted
Problem: There is a grid with infinitely many rows and columns. In this grid, there is a rectangular region with consecutive N rows and M columns, and a card is placed in each square in this region. The front and back sides of these cards can be distinguished, and initially every card faces up.  We will perform the following operation once for each square contains a card:    * For each of the following nine squares, flip the card in it if it exists: the target square itself and the eight squares that shares a corner or a side with the target square.  It can be proved that, whether each card faces up or down after all the operations does not depend on the order the operations are performed. Find the number of cards that face down after all the operations.

Submission attempts (in order):
print(-1)

def solve():
    N, M = map(int, input().split())

    if N == 1 and M == 1:
        print(1)
        return

    if N == 1:
        print(M-2)
        return

    if M == 1:
        print(N-2)
        return

    print((N-2) * (M-2))


if __name__ == "__main__":
    solve()




Verdicts: Wrong Answer

Accepted
Problem: There is a grid with infinitely many rows and columns. In this grid, there is a rectangular region with consecutive N rows and M columns, and a card is placed in each square in this region. The front and back sides of these cards can be distinguished, and initially every card faces up.  We will perform the following operation once for each square contains a card:    * For each of the following nine squares, flip the card in it if it exists: the target square itself and the eight squares that shares a corner or a side with the target square.  It can be proved that, whether each card faces up or down after all the operations does not depend on the order the operations are performed. Find the number of cards that face down after all the operations.

Submission attempts (in order):
n,m = map(int,input().split())

print(max(n-2,1)*max(m-2,1))

n,m = map(int,input().split())

if n>1:
    uraN=n-2
else:
    uraN=1
    
if m>1:
    uraM=m-2
else:
    uraM=1
    
print(uraN*uraM)

Verdicts: Wrong Answer

Accepted