Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p04044 (python)

Fixed submission:
N, L = map(int, input().split())
S = [input() for i in range(N)]
s = sorted(S)
print(*s, sep='')

Buggy submission (verdict: Runtime Error):
N, L = map(int, input().split())
S = [input() for i in range(L)]
s = sorted(S)
print(*s, sep='')

Buggy submission (verdict: Runtime Error):
N, L = map(int, input().split())
S = [input() for i in range(L)]
s = sorted(S)
print(*s, sep='')

Buggy submission (verdict: Runtime Error):
L = int(input())
print(*sorted(input() for i in range(L)), sep='')

Buggy submission (verdict: Runtime Error):
N, L = map(int, input().split())
print(*sorted(input() for i in range(L)))

Buggy submission (verdict: Runtime Error):
N, L = map(int, input().split())
print(*sorted(input() for i in range(L)), sep='')

Buggy submission (verdict: Runtime Error):
N, L = map(int, input().split())
S = [input().split() for i in range(L)]

s = sorted(S)
print(*s)

Buggy submission (verdict: Runtime Error):
N, L = map(int, input().split())
S = [input().rstrip() for i in range(L)]

print(sorted(S))

Buggy submission (verdict: Runtime Error):
N, L = map(int, input().split())
S = [input().split() for i in range(L)]

P = []
s = sorted(S)
for q in s:
  P.append(q)

print(P)

Buggy submission (verdict: Runtime Error):
N, L = map(int, input().split())
P = [input().split() for i in range(L)]

p = sorted(P)
ppp = "".join(map(str, p))
print(ppp)

Buggy submission (verdict: Runtime Error):
N, L = map(int, input().split())
P = [input().split() for i in range(L)]

p = sorted(P)
print(p[0] + p[1] + p[2])
Problem p02923 (python)

Fixed submission:
import sys
import math
from copy import deepcopy
from collections import deque, defaultdict
from operator import mul
from functools import reduce
sys.setrecursionlimit(20000000)

# input = sys.stdin.readline


def main():
    N = int(input())
    Ps = list(map(int, input().split()))

    count = 0

    ans = [0]

    for i in range(len(Ps) - 1):
        if Ps[i] >= Ps[i+1]:
            count += 1
        else:
            ans.append(count)
            count = 0

        if i == len(Ps) - 2:
            ans.append(count)

    print(max(ans))


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
import math
from copy import deepcopy
from collections import deque, defaultdict
from operator import mul
from functools import reduce
sys.setrecursionlimit(20000000)

# input = sys.stdin.readline


def main():
    N = int(input())
    Ps = list(map(int, input().split()))

    count = 0

    ans = []

    for i in range(len(Ps) - 1):
        if Ps[i] >= Ps[i+1]:
            count += 1
        else:
            ans.append(count)
            count = 0

        if i == len(Ps) - 2:
            ans.append(count)

    print(max(ans))


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
import math
from copy import deepcopy
from collections import deque, defaultdict
from operator import mul
from functools import reduce
sys.setrecursionlimit(20000000)

# input = sys.stdin.readline


def main():
    N = int(input())
    Ps = list(map(int, input().split()))

    count = 0

    ans = []

    for i in range(len(Ps) - 1):
        if Ps[i] >= Ps[i+1]:
            count += 1
        else:
            ans.append(count)
            count = 0

        if i == len(Ps) - 2:
            ans.append(count)

    print(max(ans))


if __name__ == '__main__':
    main()
Problem p02953 (python)

Fixed submission:
import sys
from collections import deque
sys.setrecursionlimit(20000000)
input = sys.stdin.readline


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

    nums = list(map(int, input().split()))

    ans = 'Yes'

    for x in reversed(range(1, len(nums))):
        if nums[x-1] - nums[x] >= 2:
            ans = 'No'

        elif nums[x-1] - nums[x] == 1:
            nums[x-1] -= 1

        else:
            continue

    print(ans)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
import sys
from collections import deque
sys.setrecursionlimit(20000000)
input = sys.stdin.readline


# def main():
#     n = int(input())
#
#     nums = list(map(int, input().split()))
#
#     ans = 'Yes'
#
#     for x in reversed(range(1, len(nums))):
#         if nums[x-1] - nums[x] >= 2:
#             ans = 'No'
#
#         elif nums[x-1] - nums[x] == 1:
#             nums[x-1] -= 1
#
#         else:
#             continue
#
#     print(ans)
#
#
# if __name__ == '__main__':
#     main()


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

    nums = list(map(int, input().split()))

    for x in reversed(range(1, len(nums))):
        if nums[x-1] > nums[x]:
            nums[x-1] -= 1

        if nums[x-1] > nums[x]:
            print('No')
            os.exit()

    print('Yes')


if __name__ == '__main__':
    main()
Problem p02615 (python)

Fixed submission:
N = int(input())
A = list(map(int,input().split()))
A = sorted(A)[::-1]

if N == 2:
    print(A[0])

else:
    ans = A[0]
    cnt = 1
    n = N - 2

    while(1):

        ans += A[cnt]
        n -= 1
        if n == 0:  break

        ans += A[cnt]
        n -= 1
        if n == 0:  break

        cnt += 1

    print(ans)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = list(map(int,input().split()))
A = sorted(A)[::-1]

ans = A[0]
cnt = 1
n = N - 2

while(1):
    
    ans += A[cnt]
    n -= 1
    if n == 0:  break
        
    ans += A[cnt]
    n -= 1
    if n == 0:  break
        
    cnt += 1
    
print(ans)
Problem p02664 (python)

Fixed submission:
S = input()
S = S.replace("?", "D")
print(S)

Buggy submission (verdict: Runtime Error):
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#define INF (1e9 + 7)
#define distance(x1, y1, x2, y2) sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
#define rep(i, N) for(ll i = 0; i < N; i++)
#define rep2(i, j, k) for(ll i = j; i < k; i++)
typedef long long int ll;
using namespace std;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vs = vector<string>;
using vvs = vector<vector<string>>;
int main(){
    
    string S;
    cin >> S;
    reverse(S.begin(), S.end());
    int length = S.size();
    string T = "";

    if(S[0] == '?'){
        T.push_back('D');
    }
    else{
        T.push_back(S[0]);
    }

    rep2(i, 1, length){
        if(S[i] == '?'){     
            if(T.back() == 'D'){
                T.push_back('P');
            }
            else{
                T.push_back('D');
            }
        }
        else{
            T.push_back(S[i]);
        }
    }

    reverse(T.begin(), T.end());
    cout << T <<endl;

    return 0;
}
Problem p02684 (python)

Fixed submission:
N, K = list(map(int,input().split()))
A = list(map(int,input().split()))
for i in range(N):
    A[i] -= 1
    
visited = [-1] * N
visited[0] = 0
ret = [0]
next_ = A[0]
roop_start = 10 ** 9 + 7

for i in range(1, K + 1):
    if visited[next_] != -1:
        roop_start = visited[next_]
        break
    ret.append(next_)
    visited[next_] = i
    next_ = A[next_]
    
if K <= roop_start:
    print(ret[K] + 1)
else:
    roop_length = len(ret) - roop_start
    mod = (K - roop_start) % roop_length
    print(ret[roop_start + mod] + 1)

Buggy submission (verdict: Runtime Error):
N, K = list(map(int,input().split()))
A = list(map(int,input().split()))
for i in range(N):
    A[i] -= 1
    
visited = [-1] * N
visited[0] = 0
ret = [0]
next_ = A[0]

for i in range(1, K):
    if visited[next_] != -1:
        roop_start = visited[next_]
        break
    ret.append(next_)
    visited[next_] = i
    next_ = A[next_]
    
if K <= roop_start:
    print(ret[K])
else:
    roop_length = len(ret) - roop_start
    mod = (K - roop_start) % roop_length
    print(ret[roop_start + mod] + 1)
Problem p02696 (python)

Fixed submission:
import math

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

def f(x):
    return math.floor(A * x / B) - A * math.floor(x / B)

if B - 1 <= N:
    ans = f(B - 1)
else:
    ans = f(N)
print(ans)

Buggy submission (verdict: Runtime Error):
A, B, N = list(map(int,input().split()))

def f(x):
    return math.floor(A * x / B) - A * math.floor(x / B)

if B - 1 <= N:
    ans = f(B - 1)
else:
    ans = f(N)
print(ans)

Buggy submission (verdict: Runtime Error):
A, B, N = list(map(int,input().split()))
if B - 1 <= N:
    ans = f(B - 1)
else:
    ans = f(N)
print(ans)
Problem p02732 (python)

Fixed submission:
from operator import mul
from functools import reduce

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

def cmb(n, r):
    if n < r:  return 0
    r = min(n - r, r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under

dic = {}
ma = max(A)
for i in range(N):
    if A[i] in dic:
        dic[A[i]] += 1
    else:
        dic[A[i]] = 1
        
c = [0 for _ in range(ma + 1)]
for i in dic:
    c[i] = cmb(dic[i], 2)
sum_ = sum(c)

for i in range(N):
    ans = sum_ - c[A[i]] + cmb(dic[A[i]] - 1, 2)
    print(ans)

Buggy submission (verdict: Runtime Error):
from operator import mul
from functools import reduce

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

def cmb(n, r):
    if n < r:  return 0
    r = min(n - r, r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1, r + 1))
    return over // under

dic = {}
for i in range(N):
    if A[i] in dic:  dic[A[i]] += 1
    else:  dic[A[i]] = 1
        
sum_ = 0
for i in dic: sum += cmb(dic[i], 2)

for i in range(N):
    ans = sum_ - (dic[A[i]] - 1)
    print(ans)
Problem p02756 (python)

Fixed submission:
from collections import deque
S = input()
Q = int(input())
t = []
f = []
c = []
for i in range(Q):
    in_ = list(input().split())
    if in_[0] == "1":
        t.append(1)
        f.append(0)
        c.append(0)
    else:
        t.append(2)
        f.append(int(in_[1]))
        c.append(in_[2])
acc = [0 for _ in range(Q)]
if t[-1] == 1:  acc[-1] = 1
for i in reversed(range(Q - 1)):
    if t[i] == 1:
        acc[i] = acc[i + 1] + 1
    else:
        acc[i] = acc[i + 1]
        
if acc[0] % 2 == 0:
    ans = deque(S)
else:
    ans = deque(S[::-1])
    
for i in range(Q):
    if t[i] == 2:
        if (f[i] + acc[i]) % 2 == 1:
            ans.appendleft(c[i])
        else:
            ans.append(c[i])
print("".join(ans))

Buggy submission (verdict: Runtime Error):
from collections import deque
s = input()
Q = int(input())
t = []
f = []
c = []
for i in range(Q):
    in_ = list(input().split())
    if in_[0] == "1":
        t.append(1)
        f.append(0)
        c.append(0)
    else:
        t.append(2)
        f.append(int(in_[1]))
        c.append(in_[2])
acc = [0 for _ in range(Q)]
if t[-1] == 1:  acc[-1] = 1
for i in reversed(range(Q - 1)):
    if t[i] == 1:
        acc[i] = acc[i + 1] + 1
    else:
        acc[i] = acc[i + 1]
        
if acc[0] % 2 == 0:
    ans = deque(S)
else:
    ans = deque(S[::-1])
    
for i in range(Q):
    if t[i] == 2:
        if (f[i] + acc[i]) % 2 == 1:
            ans.appendleft(c[i])
        else:
            ans.append(c[i])
print("".join(ans))
Problem p02761 (python)

Fixed submission:
N, M = list(map(int,input().split()))
s = []
c = []
for i in range(M):
    in1, in2 = list(map(int,input().split()))
    s.append(in1 - 1)
    c.append(in2)
    
def solve():
    
    res = [-1 for _ in range(N)]

    for i in range(M):
        if res[s[i]] != -1 and res[s[i]] != c[i]:
            print(-1)
            return
        if s[i] == 0 and c[i] == 0 and N != 1:
            print(-1)
            return
        res[s[i]] = c[i] 

    ans = ""
    
    if N == 1:
        if res[0] == -1:
            print(0)
        else:
            print(res[0])
        return
    
    for i in range(N):
        if res[i] == -1:
            if i == 0:
                ans += "1"
            else:
                ans += "0"
        else:
            ans += str(res[i])
    print(ans)

solve()

Buggy submission (verdict: Runtime Error):
N, M = list(map(int,input().split()))
s = []
c = []
for i in range(M):
    in1, in2 = list(map(int,input().split()))
    s.append(in1 - 1)
    c.append(in2)
    
def solve():
    
    res = [-1 for _ in range(N)]

    for i in range(M):
        if res[s[i]] != -1 and res[s[i]] != c[i]:
            print(-1)
            return
        if s[i] == 0 and c[i] == 0:
            print(-1)
            return
        res[s[i]] = c[i] 

    ans = ""
    for i in range(N):
        if res[i] == -1:
            if i == 0:
                ans += "1"
            else:
                ans += "0"
        else:
            ans += str(res[i])
    print(ans)

else:
    solve()

Buggy submission (verdict: Runtime Error):
N, M = list(map(int,input().split()))
s = []
c = []
for i in range(M):
    in1, in2 = list(map(int,input().split()))
    s.append(in1 - 1)
    c.append(in2)

if M > N:
    print(-1)
else:
    solve()
    
def solve():
    
    res = [-1 for _ in range(N)]

    for i in range(M):
        if res[s[i]] != -1 and res[s[i]] != c[i]:
            print(-1)
            return
        if s[i] == 0 and c[i] == 0:
            print(-1)
            return
        res[s[i]] = c[i] 

    ans = ""
    for i in range(N):
        if res[i] == -1:
            if i == 0:
                ans += "1"
            else:
                ans += "0"
        else:
            ans += str(res[i])
    print(ans)

Buggy submission (verdict: Runtime Error):
N, M = list(map(int,input().split()))
s = []
c = []
for i in range(M):
    in1, in2 = list(map(int,input().split()))
    s.append(in1 - 1)
    c.append(in2)
    
if M > N:
    print(-1)
else:
    solve()
    
def solve():
    
    res = [-1 for _ in range(N)]

    for i in range(M):
        if res[s[i]] != -1 and res[s[i]] != c[i]:
            print(-1)
            return
        res[s[i]] = c[i] 

    ans = ""
    for i in range(N):
        if res[i] == -1:
            if i == 0:
                ans += "1"
            else:
                ans += "0"
        else:
            ans += str(res[i])
    print(ans)
Problem p02882 (python)

Fixed submission:
import math

def cin():
    in_ = list(map(int,input().split()))
    if len(in_) == 1:  return in_[0]
    else:  return in_

a, b, x = cin()
if a * a * b == x:  print(0)
else:
    if 2 * x <= a ** 2 * b:
        p = 2 * x / (a * b)
        print(math.degrees(math.atan(b / p)))
    else:
        S = x / a
        p = 2 * (a * b - S) / a
        print(90 - math.degrees(math.atan(a / p)))

Buggy submission (verdict: Runtime Error):
import math

def cin():
    in_ = list(map(int,input().split()))
    if len(in_) == 1:  return in_[0]
    else:  return in_

a, b, x = cin()

if 2 * x <= a ** 2 * b:
    p = 2 * x / (a * b)
    print(math.degrees(math.atan(b / p)))
else:
    S = x / a
    p = 2 * (a * b - S) / a
    print(90 - math.degrees(math.atan(a / p)))

Buggy submission (verdict: Runtime Error):
import math

a, b, x = cin()

if 2 * x <= a ** 2 * b:
    p = 2 * x / (a * b)
    print(math.degrees(math.atan(b / p)))
else:
    S = x / a
    p = 2 * (a * b - S) / a
    print(90 - math.degrees(math.atan(a / p)))
Problem p02900 (python)

Fixed submission:
import collections

def cin():
    in_ = list(map(int,input().split()))
    if len(in_) == 1:  return in_[0]
    else:  return in_

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:  f += 2
    if n != 1:  a.append(n)
    return a

A, B = cin()
A, B = min(A, B), max(A, B)
res = collections.Counter(prime_factorize(A))
keys = list(res.keys())
keys.append(1)
ans = 0
for i in keys:
    if B % i == 0:
        ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
A, B = cin()

def cin():
    in_ = list(map(int,input().split()))
    if len(in_) == 1:  return in_[0]
    else:  return in_

def sieve(N):
    p = 0
    prime = []
    is_prime = [1 for _ in range(N + 1)]
    is_prime[0], is_prime[1] = 0, 0
    for i in range(2, N + 1):
        if is_prime[i]:
            p += 1
            temp = i
            prime.append(i)
            while(temp <= N):
                is_prime[temp] = 0
                temp += i
            is_prime[i] = 1
    return prime

s = sieve(int(min(A, B) ** 0.5) + 1)
s.append(1)
ans = 0
for i in s:
    if A % i == 0 and B % i == 0:
        ans += 1
print(ans)
Problem p02913 (python)

Fixed submission:
def cin():  return list(map(int,input().split()))

def alpha2num(alpha):
    num = 0
    for index, item in enumerate(list(alpha)):  num += pow(26, len(alpha) - index - 1) * (ord(item) - ord('a') + 1)
    return num

def rol_hash(l):

    b, h = 1007, 10 ** 9 + 9
    base = pow(b, l, h)
    hash_s = 0
    dic = {}
    for i in range(l):  hash_s = (hash_s * b + alpha2num(S[i])) % h
    dic[hash_s] = l - 1
    for i in range(1, N - l + 1):
        hash_s = (hash_s * b - base * alpha2num(S[i - 1]) + alpha2num(S[i + l - 1])) % h
        if hash_s in dic:
            if S[dic[hash_s] - l + 1:dic[hash_s] + 1] == S[i:i + l] and dic[hash_s] < i:  return 1
        else:  dic[hash_s] = i + l - 1
    return 0

def is_ok(mid):  return rol_hash(mid)

def binary_search(left, right):
    while (abs(right - left) > 1):
        mid = (left + right) // 2
        if is_ok(mid):  right = mid
        else:  left = mid
    return right

N = cin()[0]
S = input()

left = N + 1
right = -1
ret = binary_search(left, right)
if ret == right:  print(0)
else:  print(ret)

Buggy submission (verdict: Runtime Error):
N = cin()[0]
S = input()

def alpha2num(alpha):
    num = 0
    for index, item in enumerate(list(alpha)):
        num += pow(26, len(alpha) - index - 1) * (ord(item) - ord('a') + 1)
    return num

def rol_hash(l):

    b, h = 10 ** 6 + 7, 10 ** 9 + 7
    base = pow(b, l, h)
    hash_s = 0
    dic = {}
    for i in range(l):  hash_s = (hash_s * b + alpha2num(S[i])) % h
    dic[hash_s] = l - 1
    for i in range(N - l + 1):
        if i + l < N:
            hash_s = (hash_s * b - base * alpha2num(S[i]) + alpha2num(S[i + l])) % h
            if hash_s in dic:
                if dic[hash_s] < i:  return 1
            else:  dic[hash_s] = i + l - 1
    return 0

def is_ok(mid):
    return rol_hash(mid)

def binary_search(left, right):
    while (abs(right - left) > 1):
        mid = (left + right) // 2
        if is_ok(mid):  right = mid
        else:  left = mid
    return right

left = N + 1
right = -1
ret = binary_search(left, right)
if ret == right:  print(0)
else:  print(ret)
Problem p02928 (python)

Fixed submission:
def cin():  return list(map(int,input().split()))

N, K = cin()
A = cin()
INF = 10 ** 9 + 7

cnt1 = 0
l = len(A)
for i in range(l):
    for j in range(i + 1, l):
        cnt1 += (A[i] > A[j])
        
AA = A + A
l = len(AA)
cnt2 = 0
for i in range(l):
    for j in range(i + 1, l):
        cnt2 += (AA[i] > AA[j])

ans = K * cnt1 + (cnt2 - 2 * cnt1) * K * (K - 1) // 2
print(ans % INF)

Buggy submission (verdict: Runtime Error):
def cin():  return list(map(int,input().split()))

N, K = cin()
A = cin()

cnt1 = 0
l = len(A)
for i in range(l):
    for j in range(i + 1, l):
        cnt1 += (A[i] > A[j])
        
AA = A + A
l = len(AA)
cnt2 = 0
for i in range(l):
    for j in range(i + 1, l):
        cnt2 += (AA[i] > AA[j])

ans = K * cnt1 + (cnt2 - 2 * cnt1) * K * (K - 1) // 2
print(ans % INF)

Buggy submission (verdict: Runtime Error):
N, K = cin()
A = cin()

cnt1 = 0
l = len(A)
for i in range(l):
    for j in range(i + 1, l):
        cnt1 += (A[i] > A[j])
        
AA = A + A
l = len(AA)
cnt2 = 0
for i in range(l):
    for j in range(i + 1, l):
        cnt2 += (AA[i] > AA[j])

ans = K * cnt1 + (cnt2 - 2 * cnt1) * K * (K - 1) // 2
print(ans % INF)
Problem p03130 (python)

Fixed submission:
def cin():  return list(map(int,input().split()))
c = [0] * 4
for i in range(3):
    in1, in2 = cin()
    c[in1 - 1] += 1
    c[in2 - 1] += 1
c = sorted(c)
if c == [1, 1, 2, 2]:  print("YES")
else:  print("NO")

Buggy submission (verdict: Runtime Error):
c = [0] * 4
for i in range(3):
    in1, in2 = cin()
    c[in1 - 1] += 1
    c[in2 - 1] += 1
c = sorted(c)
if c == [1, 1, 2, 2]:  print("YES")
else:  print("NO")
Problem p03138 (python)

Fixed submission:
def cin():  return list(map(int,input().split()))

N, K = cin()
A = cin()

dp = [[-1 for _ in range(2)] for _ in range(100)]
dp[0][0] = 0
MAX_DIGIT = 50

for i in range(1, MAX_DIGIT):
    mask = (1 << (MAX_DIGIT - i - 1))
    cnt = 0
    for j in range(N):  cnt += bool(A[j] & mask)
    cost0 = mask * cnt
    cost1 = mask * (N - cnt)
    if(dp[i - 1][1] != -1):  dp[i][1] = max(dp[i][1], dp[i - 1][1] + max(cost0, cost1))
    if(dp[i - 1][0] != -1):
        if(K & mask):  dp[i][1] = max(dp[i][1], dp[i - 1][0] + cost0)
        if(K & mask):  dp[i][0] = max(dp[i][0], dp[i - 1][0] + cost1)
        else:  dp[i][0] = max(dp[i][0], dp[i - 1][0] + cost0)
        
ans = max(dp[MAX_DIGIT - 1][0], dp[MAX_DIGIT - 1][1])
print(ans)

Buggy submission (verdict: Runtime Error):
def cin():  return list(map(int,input().split()))

N, K = cin()
A = cin()

dp = [[-1 for _ in range(2)] for _ in range(100)]
dp[0][0] = 0
MAX_DIGIT = 50

for i in range(1, MAX_DIGIT):
    mask = (1 << (MAX_DIGIT - i - 1))
    cnt = 0
    for j in range(N):  cnt += bool(A[j] & mask)
    cost0 = mask * cnt
    cost1 = mask * (N - cnt)
    if(dp[i - 1][1] != -1):  dp[i][1] = max(dp[i][1], dp[i - 1][1] + max(cost0, cost1))
    if(dp[i - 1][0] != -1):
        if(K & mask):  dp[i][1] = max(dp[i][1], dp[i - 1][0] + cost0)
        if(K & mask):  dp[i][0] = max(dp[i][0], dp[i - 1][0] + cost1)
        else:  dp[i][0] = max(dp[i][0], dp[i - 1][0] + cost0)
        
ans = max(dp[MAX_DIGHT - 1][0], dp[MAX_DIGHT - 1][1])
print(ans)
Problem p03409 (python)

Fixed submission:
N = int(input())
red = []
blue = []
for i in range(N):
    in1, in2 = list(map(int,input().split()))
    red.append([in1, in2])
for i in range(N):
    in1, in2 = list(map(int,input().split()))
    blue.append([in1, in2])
    
red = sorted(red, key=lambda x: x[0])[::-1]
ans = 0
INF = 10 ** 9 + 7
for i in range(N):
    min_ = INF
    ind = -1
    for j in range(N):
        if red[i][0] <= blue[j][0] and red[i][1] <= blue[j][1] and blue[j][1] < min_:
            ind = j
            min_ = blue[j][1]
    if ind != -1:
        blue[ind][0] = -1
        ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
N = input()
red = sorted([list(map(int,input().split())) for i in range(N)], key=lambda x: x[0])[::-1]
blue = [list(map(int,input().split())) for i in range(N)]
ans = 0
for i in range(N):
    min_ = 10 ** 9 + 7
    ind = -1
    for j in range(N):
        if red[i][0] <= blue[j][0] and red[i][1] <= blue[j][1] and blue[j][1] < min_:
            ind = j
            min_ = blue[j][1]
    if ind != -1:
        blue[ind][0] = -1
        ans += 1
print(ans)