Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
import math
A,B,H,M=map(int,input().split())
c=abs(H*15-M*6)
k=A*A+B*B-2*A*B*math.cos(c*pi/360)
l=math.sqrt(k)
print(l)

Fixed submission:
import math
A,B,H,M=map(int,input().split())
c=abs(H*30-M*5.5)
k=A*A+B*B-2*A*B*math.cos(c*math.pi/180)
l=math.sqrt(k)
print(l)

Buggy python submission (verdict: Runtime Error):
import math
A,B,H,M=map(int,input().split())
c=abs(H*15-M*6)
k=A*A+B*B-2*A*B*math.cos(c)
l=math.sqrt(k)
print(l:df)

Fixed submission:
import math
A,B,H,M=map(int,input().split())
c=abs(H*30-M*5.5)
k=A*A+B*B-2*A*B*math.cos(c*math.pi/180)
l=math.sqrt(k)
print(l)

Buggy python submission (verdict: Runtime Error):
import math
A,B,H,M=map(int,input().split())
c=abs(H*15-M*6)
k=A*A+B*B-2*A*B*math.cos(c)
l=sqrt.(k)
print(l)

Fixed submission:
import math
A,B,H,M=map(int,input().split())
c=abs(H*30-M*5.5)
k=A*A+B*B-2*A*B*math.cos(c*math.pi/180)
l=math.sqrt(k)
print(l)
Buggy python submission (verdict: Time Limit Exceeded):
n, k = list(map(int, input().split()))
move = []
for i in range(k):
    s, t = list(map(int, input().split()))
    m = list(range(s, t + 1))
    move += m

mod = 998244353

dp = [0] * (n)
dp[0] = 1

for i in range(n):
    p = i
    temp = 0
    for m in move:
        if m <= p:
            temp += dp[p - m]
    dp[p] += temp % mod

print(dp[n-1])


Fixed submission:
n, k = list(map(int, input().split()))
move = []
for i in range(k):
    s, t = list(map(int, input().split()))
    move.append([s, t])

mod = 998244353

dp = [0] * (n + 1)
dp[1] = 1

ruiseki = [0] * (n + 1)
ruiseki[1] = 1

for i in range(n):
    p = i + 1
    temp = 0
    for j in range(k):
        s, t = move[j]
        r = max(0, p - s)
        l = max(0, p - t - 1)
        temp += ruiseki[r] - ruiseki[l]
    dp[p] += temp % mod
    ruiseki[p] = ruiseki[p - 1] + dp[p]

print(dp[n])
Buggy python submission (verdict: Time Limit Exceeded):
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())


n, m = list(map(int, input().split()))
friends = []
for i in range(m):
    f = list(map(int, input().split()))
    f.sort()
    if f not in friends:
        friends.append(f)

friend_map = UnionFind(n)

for f in friends:
    friend_map.union(f[0]-1, f[1]-1)

ans = 0
for i in range(n):
    tmp = friend_map.size(i)
    ans = max(ans, tmp)

print(ans)


Fixed submission:
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())


n, m = list(map(int, input().split()))
friends = []
for i in range(m):
    f = list(map(int, input().split()))
    friends.append(f)

friend_map = UnionFind(n)

for f in friends:
    friend_map.union(f[0]-1, f[1]-1)

ans = 0
for i in range(n):
    tmp = friend_map.size(i)
    ans = max(ans, tmp)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a_list = list(map(int, input().split()))
ans = 'YES'
cheacked = {}

for i in a_list:
    if i in cheacked.keys():
        ans = 'NO'
        break
    else:
        cheacked[i] = 0
        
print(ans)

Fixed submission:
n = int(input())
a_list = list(map(int, input().split()))
ans = 'YES'
cheacked = {}

for i in a_list:
    if i in cheacked.keys():
        ans = 'NO'
        break
    else:
        cheacked[i] = 0
        
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a_list = list(map(int, input().split()))
ans = 'YES'
cheacked = []

for i in a_list:
    if i in cheacked:
        ans = 'NO'
        break
    else:
        cheacked.append(i)
        
print(ans)

Fixed submission:
n = int(input())
a_list = list(map(int, input().split()))
ans = 'YES'
cheacked = {}

for i in a_list:
    if i in cheacked.keys():
        ans = 'NO'
        break
    else:
        cheacked[i] = 0
        
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a_list = list(map(int, input().split()))

DIGIT = 61
MOD = (10**9) +7
count = 0
for i in range(DIGIT):
    one_count = 0
    for num in a_list:
        if (num >> i) % 2 == 1:
            one_count += 1
    comb_1_1 = one_count * (n - one_count)
    count += comb_1_1 * (2**i)
    count = count % MOD
    
print(count)

Fixed submission:
n = int(input())
a_list = list(map(int, input().split()))

DIGIT = 61
MOD = (10**9) +7
count = 0
for i in range(DIGIT):
    one_count = 0
    for num in a_list:
        if (num >> i) % 2 == 1:
            one_count += 1
    comb_1_1 = one_count * (n - one_count)
    count += comb_1_1 * (2**i)
    count = count % MOD
    
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
def check(first, second, third, num_list):
    first_flag = False
    second_flag = False
    third_flag = False
    for num in num_list:
        if first_flag:
            if second_flag:
                if third_flag:
                    return True
                else:
                    if str(num) == third:
                        third_flag = True
            else:
                if str(num) == second:
                    second_flag = True
        else:
            if str(num) == first:
                first_flag = True
        if first_flag and second_flag and third_flag:
            return True
    return False

n = int(input())
s = input()
sl = list(s)

ans = 0

for i in range(1000):
    if i < 10:
        flag = check('0', '0', str(i), sl)
    elif i < 100:
        flag = check('0', str(i//10), str(i%10), sl)
    else:
        flag = check(str(i//100), str((i%100)//10), str(i%10), sl)
        
    if flag:
        ans += 1

print(ans)

Fixed submission:
def check(first, second, third, num_list):
    first_flag = False
    second_flag = False
    third_flag = False
    for num in num_list:
        if first_flag:
            if second_flag:
                if third_flag:
                    return True
                else:
                    if str(num) == third:
                        third_flag = True
            else:
                if str(num) == second:
                    second_flag = True
        else:
            if str(num) == first:
                first_flag = True
        if first_flag and second_flag and third_flag:
            return True
    return False

n = int(input())
s = input()
sl = list(s)

ans = 0

for i in range(1000):
    if i < 10:
        flag = check('0', '0', str(i), sl)
    elif i < 100:
        flag = check('0', str(i//10), str(i%10), sl)
    else:
        flag = check(str(i//100), str((i%100)//10), str(i%10), sl)
        
    if flag:
        ans += 1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
MOD = 998244353

n = int(input())
distances = list(map(lambda x: int(x), input().split()))

# 最初が0であることを確認
canSolve = True
ans = 1

if distances[0] != 0:
    canSolve = False
    ans = 0

dist_list = {}
if canSolve:
    for i in distances:
        if i in dist_list.keys():
            dist_list[i] += 1
        else:
            dist_list[i] = 1
            
            
    keys = list(dist_list.keys())
    keys.sort()
    keys.reverse()
    bigger = None
    smaller = None
    for v in keys:
        if bigger is None:
            bigger = dist_list[v]
            continue
        elif smaller is None:
            smaller = dist_list[v]
        else:
            bigger = smaller
            smaller = dist_list[v]
        
        ans *= (smaller**bigger)
        ans = ans % MOD
        
print(ans)

Fixed submission:
MOD = 998244353

n = int(input())
distances = list(map(lambda x: int(x), input().split()))

# 最初が0であることを確認
canSolve = True
ans = 1

if distances[0] != 0:
    canSolve = False
    ans = 0

dist_list = {}
if canSolve:
    for i in distances:
        if i in dist_list.keys():
            dist_list[i] += 1
        else:
            dist_list[i] = 1
            
            
    keys = list(dist_list.keys())
    keys.sort()
    keys.reverse()
    bigger = None
    smaller = None
    pre_v = None
    for v in keys:
        if bigger is None:
            bigger = dist_list[v]
            pre_v = v
            continue
        elif smaller is None:
            smaller = dist_list[v]
        else:
            bigger = smaller
            smaller = dist_list[v]
        
        if v==0 and smaller > 1:
            ans = 0

        if v == pre_v - 1:
            ans *= (smaller**bigger)
            ans = ans % MOD
            pre_v = v
        else:
            ans = 0
        
print(ans)
Buggy python submission (verdict: Runtime Error):

n = int(input())
tastes = list(map(lambda x:int(x), input().split()))

ans = 0

while len(tastes)>0:
    x = tastes[0]
    del tastes[0]
    for y in tastes:
        ans += x * y
            
print(ans)


Fixed submission:
a, b = list(map(lambda x: int(x), input().split()))

ans = max(0, a - (2*b))

print(ans)

Buggy python submission (verdict: Runtime Error):
n = int(input())
tastes = list(map(lambda x:int(x), input().split()))

ans = 0

while len(tastes)>0:
    x = tastes.pop()
    for y in tastes:
        ans += x * y
        
print(ans)

Fixed submission:
a, b = list(map(lambda x: int(x), input().split()))

ans = max(0, a - (2*b))

print(ans)
Buggy python submission (verdict: Runtime Error):
    n = int(input())
    tastes = list(map(lambda x:int(x), input().split()))
    
    ans = 0
    
    while len(tastes)>0:
        x = tastes.pop()
        for y in tastes:
            ans += x * y
            
    print(ans)

Fixed submission:
n = int(input())
tastes = list(map(lambda x:int(x), input().split()))

ans = 0

while len(tastes)>0:
    x = tastes.pop()
    for y in tastes:
        ans += x * y
            
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
h_list = list(map(lambda x: int(x), input().split()))

max_move = 0
current_move = 0
s = 0
t = 1
continue_flag = True


while continue_flag:
    if h_list[s] >= h_list[t]:
        current_move += 1
        s += 1
        t += 1
    else:
        max_move = max([max_move, current_move])
        current_move = 0
        s += 1
        t += 1
        
    if t == n:
        max_move = max([max_move, current_move])
        continue_flag = False
        
print(max_move)

Fixed submission:
n = int(input())
h_list = list(map(lambda x: int(x), input().split()))

max_move = 0
current_move = 0
s = 0
t = 1
continue_flag = True

if n == 1:
    print(0)
else:
    while continue_flag:
        if h_list[s] >= h_list[t]:
            current_move += 1
            s += 1
            t += 1
        else:
            max_move = max([max_move, current_move])
            current_move = 0
            s += 1
            t += 1

        if t == n:
            max_move = max([max_move, current_move])
            continue_flag = False

    print(max_move)

Buggy python submission (verdict: Runtime Error):
n = int(input())
h_list = list(map(lambda x: int(x), input().split()))

max_move = 0
current_move = 0
s = 0
t = 1
continue_flag = True


while continue_flag:
    if h_list[s] >= h_list[t]:
        current_move += 1
        s += 1
        t += 1
    else:
        max_move = max([max_move, current_move])
        s += 1
        t += 1
        
    if t == n-1 or s == n-2:
        max_move = max([max_move, current_move])
        continue_flag = False
        
print(max_move)

Fixed submission:
n = int(input())
h_list = list(map(lambda x: int(x), input().split()))

max_move = 0
current_move = 0
s = 0
t = 1
continue_flag = True

if n == 1:
    print(0)
else:
    while continue_flag:
        if h_list[s] >= h_list[t]:
            current_move += 1
            s += 1
            t += 1
        else:
            max_move = max([max_move, current_move])
            current_move = 0
            s += 1
            t += 1

        if t == n:
            max_move = max([max_move, current_move])
            continue_flag = False

    print(max_move)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

ans = 0

for i in range(n-1):
    ans += i+1

print(ans)

Fixed submission:
n = int(input())
        
ans = ((n - 1) * (n)) // 2

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = []
for i in range(n):
    p = list(input())
    p.sort()
    s.append(p)

ans = 0
for i in range(n):
    first = s[i]
    for j in range(n):
        if i >= j:
            continue
        second = s[j]
        for k in range(10):
            if first[k] == second[k]:
                if k==9:
                    ans += 1
                continue
            else:
                break


print(ans)

Fixed submission:
n = int(input())
dic = {}
for i in range(n):
    p = list(input())
    p.sort()
    p = ''.join(p)
    if p in dic.keys():
        dic[p] += 1
    else:   
        dic[p] = 1

ans = 0
for i in dic.keys():
    if dic[i] == 1:
        continue
    else:
        ans += (dic[i]*(dic[i] - 1))//2

print(ans)
Buggy python submission (verdict: Runtime Error):
def move(s, i, count, before):
    if s[i] == before:
        if s[i] == 'R':
            return move(s, i+1, count+1, s[i])
        else:
            return move(s, i-1, count+1, s[i])
    else:
        if count % 2 == 0:
            return i
        else:
            if s[i] == 'R':
                return i + 1
            else:
                return i - 1

s = list(input())
ans = [0] * len(s)

for child in range(len(s)):
    if s[child] == 'R':
        ans[move(s, child + 1, 1, s[child])] += 1
    else:
        ans[move(s, child - 1, 1, s[child])] += 1
    
print(*ans)

Fixed submission:
#入力を受け取る
s = list(input())
ans = [0] * len(s)

#左から見ていく.Rだけ位置を決定する.

undifined_childlen = 0

for i in range(len(s)):
    if s[i] == 'R':
        undifined_childlen += 1
    else:
        if undifined_childlen % 2 == 0:
            ans[i] += undifined_childlen // 2
            ans[i-1] += undifined_childlen // 2
        else:
            ans[i] += undifined_childlen // 2
            ans[i-1] += (undifined_childlen // 2) + 1
    
        undifined_childlen = 0
        

#右から見ていく.Lだけ位置を決定する.
undifined_childlen = 0

for i in list(reversed(range(len(s)))):
    if s[i] == 'L':
        undifined_childlen += 1
    else:
        if undifined_childlen % 2 == 0:
            ans[i+1] += undifined_childlen // 2
            ans[i] += undifined_childlen // 2
        else:
            ans[i+1] += (undifined_childlen // 2) + 1
            ans[i] += (undifined_childlen // 2)
    
        undifined_childlen = 0

print(*ans)

Buggy python submission (verdict: Runtime Error):
def move(s, i, count, before):
    if s[i] == before:
        if s[i] == 'R':
            return move(s, i+1, count+1, s[i])
        else:
            return move(s, i-1, count+1, s[i])
    else:
        if count % 2 == 0:
            return i
        else:
            if s[i] == 'R':
                return i + 1
            else:
                return i - 1

s = list(input())
ans = [0] * len(s)

for child in range(len(s)):
    if s[child] == 'R':
        ans[move(s, child + 1, 1, s[child])] += 1
    else:
        ans[move(s, child - 1, 1, s[child])] += 1
    
print(ans)

Fixed submission:
#入力を受け取る
s = list(input())
ans = [0] * len(s)

#左から見ていく.Rだけ位置を決定する.

undifined_childlen = 0

for i in range(len(s)):
    if s[i] == 'R':
        undifined_childlen += 1
    else:
        if undifined_childlen % 2 == 0:
            ans[i] += undifined_childlen // 2
            ans[i-1] += undifined_childlen // 2
        else:
            ans[i] += undifined_childlen // 2
            ans[i-1] += (undifined_childlen // 2) + 1
    
        undifined_childlen = 0
        

#右から見ていく.Lだけ位置を決定する.
undifined_childlen = 0

for i in list(reversed(range(len(s)))):
    if s[i] == 'L':
        undifined_childlen += 1
    else:
        if undifined_childlen % 2 == 0:
            ans[i+1] += undifined_childlen // 2
            ans[i] += undifined_childlen // 2
        else:
            ans[i+1] += (undifined_childlen // 2) + 1
            ans[i] += (undifined_childlen // 2)
    
        undifined_childlen = 0

print(*ans)
Buggy python submission (verdict: Runtime Error):
import math

# x 以下でc, d 両方で割れない条件を満たす自然数の個数をf(x, c, d) とすると
# 求める値は f(b, c, d) - f(a-1, c, d)
# x 以下でk で割れる自然数の個数を g(x, k)とすれば
# f(x, c, d) = x - (g(x, c) + g(x, d) - g(x, lcm(c,d)))
# よって計算すべきは
# g(b, c) + g(b, d) - g(b, lcm(c,d)) - ( g(a-1, c) + g(a-1, d) - g(a-1, lcm(c,d)))

def lcm(p, q):
    return p * q // math.gcd(p, q)

def g(x, k):
    return x//k

def f(x, c, d):
    return x - (g(x, c) + g(x, d) - g(x, lcm(c,d)))

a,b,c,d = list(map(lambda x:int(x) ,input().split()))

print(f(b, c, d) - f(a-1, c, d))

Fixed submission:
# x 以下でc, d 両方で割れない条件を満たす自然数の個数をf(x, c, d) とすると
# 求める値は f(b, c, d) - f(a-1, c, d)
# x 以下でk で割れる自然数の個数を g(x, k)とすれば
# f(x, c, d) = x - (g(x, c) + g(x, d) - g(x, lcm(c,d)))
# よって計算すべきは
# g(b, c) + g(b, d) - g(b, lcm(c,d)) - ( g(a-1, c) + g(a-1, d) - g(a-1, lcm(c,d)))
 
def gcd (p, q):
    temp = max(p, q)
    q = min(p, q)
    p = temp
    if q == 0:
        return p
    else:
        return gcd(q, p%q)
    
def lcm(p, q):
    return p * q // gcd(p, q)
 
def g(x, k):
    return x//k
 
def f(x, c, d):
    return x - (g(x, c) + g(x, d) - g(x, lcm(c,d)))
 
a,b,c,d = list(map(lambda x:int(x) ,input().split()))
 
print(f(b, c, d) - f(a-1, c, d))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = list(input().strip())

min = -1

for i in range(n-1):
    turn = s[0:i].count("W") + s[i+1:n].count("E")
    if min == -1 or min >= turn:
        min = turn
        
    

print(min)


Fixed submission:
n = int(input())
s = list(input().strip())

min = -1

for i in range(n):
    if i == 0:
        turn = s[i+1:n].count("E")
    else:
        if s[i-1] == "W" and s[i] == "W":
            turn += 1
        elif s[i-1] == "W" and s[i] == "E":
            next
        elif s[i-1] =="E" and s[i] =="W":
            next
        else:
            turn -=1
    if min == -1 or min >= turn:
        min = turn
        
    

print(min)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

a_list = list(map(int, input().split()))
a_list.sort()
a_max = a_list[n-1]
temp_max = [1, 0]
bunbo = 1
bunshi = 1
candidate = []
a_set = set(a_list)
for i in range(a_max):
    if i == 0:
        continue
    bunbo *= max(1, i)
    bunshi *= max(1, a_max-i+1)
    if i in a_set:
        if bunshi//bunbo > temp_max[0]:
            temp_max = [bunshi//bunbo, i]

print(a_max, temp_max[1])


Fixed submission:
n = int(input())

a_list = list(map(int, input().split()))
a_list.sort()
a_max = a_list[n - 1]
temp_max = [1, 0]
bunbo = 1
bunshi = 1
center = int((a_max + 1) / 2)
a_set = set(a_list)
diff_min = a_max
ans = 0
for a in a_set:
    diff = abs(a-center)
    if diff_min > diff:
        diff_min = diff
        ans = a

print(a_max, ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

a_list = list(map(int, input().split()))
a_list.sort()
a_max = a_list[n-1]
temp_max = [1, 0]
bunbo = 1
bunshi = 1
candidate = []
a_set = set(a_list)
for i in range(a_max):
    if i == 0:
        continue
    bunbo *= max(1, i)
    bunshi *= max(1, a_max-i+1)
    if i in a_set:
        if bunshi//bunbo > temp_max[0]:
            temp_max = [bunshi//bunbo, i]

print(a_max, temp_max[1])


Fixed submission:
n = int(input())

a_list = list(map(int, input().split()))
a_list.sort()
a_max = a_list[n - 1]
temp_max = [1, 0]
bunbo = 1
bunshi = 1
center = int((a_max + 1) / 2)
a_set = set(a_list)
diff_min = a_max
ans = 0
for a in a_set:
    diff = abs(a-center)
    if diff_min > diff:
        diff_min = diff
        ans = a

print(a_max, ans)
Buggy python submission (verdict: Runtime Error):
n, h = list(map(int, input().split()))
cut = 0
throw = []

for i in range(n):
    a, b = list(map(int, input().split()))
    cut = max(cut, a)
    throw.append(b)

throw.sort(reverse=True)
throw_cam = []
for i in range(n):
    if cut >= throw[i]:
        break
    if i == 0:
        throw_cam.append(throw[0])
    else:
        throw_cam.append(throw[i] + throw_cam[i-1])

if throw_cam[len(throw_cam)-1] < h:
    rh = h - throw_cam[len(throw_cam)-1]
    if rh % cut == 0:
        print(len(throw_cam) + rh//cut)
    else:
        print(len(throw_cam) + rh//cut + 1)
else:
    for i in range(len(throw_cam)):
        d = throw_cam[i]
        if d >= h:
            print(i+1)




Fixed submission:
n, h = list(map(int, input().split()))
cut = 0
throw = []

for i in range(n):
    a, b = list(map(int, input().split()))
    cut = max(cut, a)
    throw.append(b)

throw.sort(reverse=True)
throw_cam = []
for i in range(n):
    if cut > throw[i]:
        break
    if i == 0:
        throw_cam.append(throw[0])
    else:
        throw_cam.append(throw[i] + throw_cam[i-1])

if throw_cam[len(throw_cam)-1] < h:
    rh = h - throw_cam[len(throw_cam)-1]
    if rh % cut == 0:
        print(len(throw_cam) + rh//cut)
    else:
        print(len(throw_cam) + rh//cut + 1)
else:
    for i in range(len(throw_cam)):
        d = throw_cam[i]
        if d >= h:
            print(i+1)
            break