Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

s = []
ans = 0
for i in range(n):
    si = input()
    si = sorted(si)
    ss = ""
    for a in si:
        ss += a
    s.append(ss)

sset = list(set(s))

if(len(sset) == len(s)):
    print(0)
else:
    for e in sset:
        if(s.count(e) == 1):
            continue
        ans += s.count(e) * (s.count(e) - 1) // 2

    print(ans)

Fixed submission:
n = int(input())

s = []
dic = {}
ans = 0
for i in range(n):
    si = input()
    si = sorted(si)
    ss = ""
    for a in si:
        ss += a
    if(ss in dic):
        dic[ss] += 1
    else:
        dic[ss] = 1

for e in dic:
    if(dic[e] == 1):
        continue
    ans += dic[e] * (dic[e] - 1) // 2

print(ans)

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

al = [0] * (n + 10)
al[0] = 1
al[1] = 1
for i in range(2, n + 1):
    al[i] = al[i-1] * i

s = []
ans = 0
for i in range(n):
    si = input()
    si = sorted(si)
    ss = ""
    for a in si:
        ss += a
    s.append(ss)

sset = list(set(s))

if(len(sset) == len(s)):
    print(0)
else:
    for e in sset:
        if(s.count(e) == 1):
            continue
        ans += s.count(e) * (s.count(e) - 1) // 2

    print(ans)

Fixed submission:
n = int(input())

s = []
dic = {}
ans = 0
for i in range(n):
    si = input()
    si = sorted(si)
    ss = ""
    for a in si:
        ss += a
    if(ss in dic):
        dic[ss] += 1
    else:
        dic[ss] = 1

for e in dic:
    if(dic[e] == 1):
        continue
    ans += dic[e] * (dic[e] - 1) // 2

print(ans)
Buggy python submission (verdict: Runtime Error):

class FermatCombination():
    def __init__(self, size, mod):
        self.mod = mod
        self.factrial = [1]
        self.inverse = [1]
        for i in range(1, size + 1):
            self.factrial.append((self.factrial[i-1]*i) % self.mod)
            self.inverse.append(self.modpow(self.factrial[i], self.mod - 2) % self.mod)

    def modpow(self, x, n):
        ret = 1
        while(n > 0):
            if n & 1:
                ret = ret * x % self.mod
            x = x * x % self.mod
            n >>= 1
        return ret

    def combine(self, n, k):
        return self.factrial[n] * self.inverse[k] % self.mod * self.inverse[n - k] % self.mod


N, K = map(int, input().split())
mod = 10**9+7

fermat = FermatCombination(N - K + 2, mod)

for i in range(1, K+1):
    print(fermat.combine(N-K+1, i) * fermat.combine(K-1, i-1))




Fixed submission:

class FermatCombination():
    def __init__(self, size, mod):
        self.mod = mod
        self.factrial = [1]
        self.inverse = [1]
        for i in range(1, size + 1):
            self.factrial.append((self.factrial[i-1]*i) % self.mod)
            self.inverse.append(self.modpow(self.factrial[i], self.mod - 2) % self.mod)

    def modpow(self, x, n):
        ret = 1
        while(n > 0):
            if n & 1:
                ret = ret * x % self.mod
            x = x * x % self.mod
            n >>= 1
        return ret

    def combine(self, n, k):
        return self.factrial[n] * self.inverse[k] % self.mod * self.inverse[n - k] % self.mod


N, K = map(int, input().split())
mod = 10**9+7

fermat = FermatCombination(N + 2, mod)

for i in range(1, K+1):
    if N-K+1 < i:
        print(0)
    else:
        print(fermat.combine(N-K+1, i) * fermat.combine(K-1, i-1) % mod)
Buggy python submission (verdict: Time Limit Exceeded):
S = list(input().replace("BC", "D"))
l = []
ans = 0
for i in range(len(S)-1):
    if(S[i] == "A" and S[i+1] == "D"):
        l.append(i+1)
        l.append(i-1)
        S[i] = "D"
        S[i+1] = "A"
        ans += 1

while(len(l)):
    target = l[0]
    if(target < len(S) - 1 and target >= 0):
        if(S[target] == "A" and S[target+1] == "D"):
            ans += 1
            S[target+1] = "A"
            S[target] = "D"
            l.append(target+1)
            l.append(target-1)
    l.pop(0)

print(ans)


Fixed submission:
S = list(input().replace("BC", "D"))
l = []
ans = 0
a_cnt = 1
d_cnt = 1
for i in range(len(S)-1):
    if (S[i] == "A" and S[i + 1] == "D"):
        ans += a_cnt
        S[i] = "D"
        S[i + 1] = "A"
    else:
        if(S[i] == "A" and S[i+1] == "A"):
            a_cnt += 1
        else:
            a_cnt = 1

print(ans)
Buggy python submission (verdict: Runtime Error):
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
using namespace std;
int main() {
  int n, m;
  long long ans = 0;
  cin >> n >> m;
  vector<int> a(n), b(n);
  vector<pair<int, int> > ab(n);
  for(int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
  }
  for(int i = 0; i < n; i++) {
    ab[i] = make_pair(a[i], b[i]);
  }
  sort(ab.begin(), ab.end());  
  for(int i = 0; i < n; i++) {
    int buy = min(m, ab[i].second);
    ans += buy * ab[i].first;
    m -= buy;
  }
  
  cout << ans << endl;
}

Fixed submission:
import numpy as np
n, m = map(int, input().split())
a = []
b = []
bot = m
ans = 0
for i in range(n):
  l,m = map(int, input().split())
  a.append(l)
  b.append(m)
  
a = np.array(a)
b = np.array(b)
s = np.argsort(a)
for i in s:
  if(bot >= b[i]):
    bot -= b[i]
    ans += a[i] * b[i]
  else: 
    ans += a[i] * (bot)
    bot = 0
    break

print(ans)
Buggy python submission (verdict: Runtime Error):
A, B, K = map(int, input().split())
cnt = 0
ans = 0
for i in range(1, 101): # 1から100まで
	if(A % i == 0 and B % i == 0):
		cnt = cnt + 1
	if(cnt == k):
		ans = i
print(ans)

Fixed submission:
a,b,c = map(int, input().split())
num = []
for i in range(1, 101):
  if(a % i == 0 and b % i == 0):
    num.append(i)
num.reverse()
print(num[c-1])

Buggy python submission (verdict: Runtime Error):
A, B, K = map(int, input().split())
cnt = 0
ans = 0
for i in range(1, 101): # 1から100まで
	if(A % i == 0 and B % i == 0):
 		cnt = cnt + 1
 	if(cnt == k):
 		ans = i
print(ans)

Fixed submission:
a,b,c = map(int, input().split())
num = []
for i in range(1, 101):
  if(a % i == 0 and b % i == 0):
    num.append(i)
num.reverse()
print(num[c-1])
Buggy python submission (verdict: Time Limit Exceeded):
a = input()
a = list(a)
prev = '0'
i = 0
c = 0
d = True
while(d):
  if(a != []):
    if(i > 0 and a[i] != prev):
      a.pop(i-1)
      a.pop(i-1)
      c += 2
      i = 0
      continue
    prev = a[i]
    if(i == len(a) - 1):
      break
  else:
    d = False 
  i += 1
print(c)

Fixed submission:
a = input()

z = 0
i = 0
for b in a:
  if(b == '0'):
    z += 1
  else:
    i += 1
if(z >= i):
  print(i * 2)
else:
  print(z * 2)
Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int, input().split())
v = [0] * N
w = [0] * N
for i in range(N):
    w[i], v[i] = map(int, input().split())
dp = [[0 for i in range (W+5)] for i in range(N + 5)]

for i in range(N):
    for j in range(W+1):
        dp[i+1][j] = max(dp[i+1][j], dp[i][j])
        if(j + w[i] <= W):
            dp[i+1][j+w[i]] = max(dp[i+1][j+w[i]], dp[i][j] + v[i])

print(dp[N][W])

Fixed submission:
N, W = map(int, input().split())
v = [0] * N
w = [0] * N
for i in range(N):
    w[i], v[i] = map(int, input().split())
dp = [[0 for i in range (W+5)] for i in range(N + 5)]

for i in range(N):
    for j in range(W+1):
        dp[i+1][j] = max(dp[i+1][j], dp[i][j])
        if(j + w[i] <= W):
            dp[i+1][j+w[i]] = max(dp[i+1][j+w[i]], dp[i][j] + v[i])

print(dp[N][W])
Buggy python submission (verdict: Time Limit Exceeded):
n1 = [0] * 100005
n2 = [0] * 100005
v1 = []
v2 = []
n = int(input())
v = list(map(int, input().split()))
for i in range(n):
    if(i % 2 == 0):
        n1[v[i]] += 1
        v1.append(v[i])
    else:
        n2[v[i]] += 1
        v2.append(v[i])
v1s = list(set(v1))
v2s = list(set(v2))
v1s.append(0)
v2s.append(0)
ans = 10000000
for num1 in v1s:
    for num2 in v2s:
        if(num2 == num1):
            continue
        ans = min(ans, n//2-n2[num2] + n//2-n1[num1])
print(ans)


Fixed submission:
n1 = [[j, 0] for j in range(100005)]
n2 = [[j, 0] for j in range(100005)]
n = int(input())
v = list(map(int, input().split()))
for i in range(n):
    if(i % 2 == 0):
        n1[v[i]][1] += 1
    else:
        n2[v[i]][1] += 1
n1 = sorted(n1, key=lambda x:x[1], reverse=True)
n2 = sorted(n2, key=lambda x:x[1], reverse=True)

if(n1[0][0] == n2[0][0]):
    ans1 = n//2 - n1[0][1] + n//2 - n2[1][1]
    ans2 = n//2 - n1[1][1] + n//2 - n2[0][1]
    ans = min(ans1, ans2)
    print(ans)
else:
    ans = n//2 - n1[0][1] + n//2 - n2[0][1]
    print(ans)
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
x = list(map(int, input().split()))
ans = 1e13
for i in range(n-k+1):
    l = x[i]
    r = x[i+k]
    ans = min(ans, abs(l)+abs(r-l))
print(ans)


Fixed submission:
n, k = map(int, input().split())
x = list(map(int, input().split()))
ans = 1e13
for i in range(n-k+1):
    l = x[i]
    r = x[i+k-1]
    ans = min(ans, abs(r)+abs(l-r))
    ans = min(ans, abs(l)+abs(r-l))
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
def gcd(a, b):
    if(a < b):
        a, b = b, a

    while b:
        a, b = b, a % b
    return a

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

n = int(input())
a = list(map(int, input().split()))
nums = 1
for i in range(n):
    nums = lcm(nums, a[i])
ans = 0
for i in a:
    ans += (nums - 1) % i
print(int(ans))


Fixed submission:
n = int(input())
a = list(map(int, input().split()))
nums = a[0]
for num in a:
    if(nums % num != 0):
        nums *= num
ans = 0
nums -= 1
for i in a:
    ans += nums % i
print(ans)
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
print(1900*m + 100(n - m) * 2**m)

Fixed submission:
n, m = map(int, input().split())
print((1900*m + 100*(n - m)) * 2**m)
Buggy python submission (verdict: Runtime Error):
a = input().split(',')
ans = ""
for i in a:
  ans += a[i] + " "
ans -= " "
print(ans)

Fixed submission:
a = input().replace(",", " ")
print(a)
Buggy python submission (verdict: Time Limit Exceeded):
a, b, x = map(int, input().split())
ans = 0
for i in range(a, b+1):
    if(i % x == 0):
        ans += 1
print(ans)

Fixed submission:
a, b, x = map(int, input().split())
a -= 1
ansa = a // x
ansb = b // x
print(ansb - ansa)
Buggy python submission (verdict: Runtime Error):
b = input()
d = []
isWhite = False
cnt = 0
for i in range(len(b-1)):
  if b[i] != b[i+1]:
    d.append(cnt)
  else:
    cnt+=1

print(len(d))
  
  

Fixed submission:
b = input()
d = []
isWhite = False
cnt = 0
for i in range(len(b)-1):
  if b[i] != b[i+1]:
    d.append(cnt)
  else:
    cnt+=1

print(len(d))
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
a = list(map(int, input().split()))

prev = 1
for i in range(k):
    prev *= a[i]

res = []
for i in range(k, n):
    curr = prev // a[i - k] * a[i]
    res.append(curr > prev)
    prev = curr

#print(res)
for b in res:
    if(b): print("Yes")
    else: print("No")

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

res = []
for i in range(k, n):
    res.append(a[i-k] < a[i])

#print(res)
for b in res:
    if(b): print("Yes")
    else: print("No")
Buggy python submission (verdict: Time Limit Exceeded):
h, n = map(int, input().split())

ab = []
for i in range(n):
    a, b = map(int, input().split())
    ab.append([a, b])

INF = 1 << 60
dp = [INF for _ in range(h+10001)]

dp[0] = 0

for i in range(1, h+10001):
    for j in range(n):
        if(i<ab[j][0]): continue
        dp[i] = min(dp[i-ab[j][0]] + ab[j][1], dp[i])

res = INF
for i in range(h, h+10001):
    res = min(res, dp[i])
print(res)

Fixed submission:
h, n = map(int, input().split())
 
ab = []
for i in range(n):
    a, b = map(int, input().split())
    ab.append([a, b])
 
INF = 1 << 60
dp = [INF for _ in range(h+10001)]
 
dp[0] = 0
 
for i in range(1, h+10001):
    for j in range(n):
        if(i<ab[j][0]): continue
        dp[i] = min(dp[i-ab[j][0]] + ab[j][1], dp[i])
 
res = INF
for i in range(h, h+10001):
    res = min(res, dp[i])
print(res)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
 
def gcd(n, m):
    if(m): return gcd(m, n%m)
    else: return n
 
def lcm(n, m):
    return n // gcd(n, m) * m
 
LCM = a[0]
for i in range(1, n):
    LCM = lcm(a[i], LCM)
 
res = 0
MOD = 1000000007
for i in range(n):
    res += LCM//a[i]
    
print(res % MOD)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
 
def gcd(n, m):
    if(m): return gcd(m, n%m)
    else: return n
 
def lcm(n, m):
    return n // gcd(n, m) * m
 
LCM = a[0]
for i in range(1, n):
    LCM = lcm(a[i], LCM)
 
res = 0
MOD = 1000000007
for i in range(n):
    res += LCM//a[i]
    
print(res % MOD)

Buggy python submission (verdict: Time Limit Exceeded):
import fractions
n = int(input())
a = list(map(int, input().split()))

def lcm(n, m):
    return n // fractions.gcd(n, m) * m

LCM = a[0]
for i in range(1, n):
    LCM = lcm(a[i], LCM)

res = 0
MOD = 1000000007
for i in range(n):
    res = (res + LCM//a[i]) % MOD
print(res)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
 
def gcd(n, m):
    if(m): return gcd(m, n%m)
    else: return n
 
def lcm(n, m):
    return n // gcd(n, m) * m
 
LCM = a[0]
for i in range(1, n):
    LCM = lcm(a[i], LCM)
 
res = 0
MOD = 1000000007
for i in range(n):
    res += LCM//a[i]
    
print(res % MOD)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))

def gcd(n, m):
    if(m): return gcd(m, n%m)
    else: return n

def lcm(n, m):
    return n // gcd(n, m) * m

LCM = a[0]
for i in range(1, n):
    LCM = lcm(a[i], LCM)

res = 0
MOD = 1000000007
for i in range(n):
    res = (res + LCM//a[i]) % MOD
print(res)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
 
def gcd(n, m):
    if(m): return gcd(m, n%m)
    else: return n
 
def lcm(n, m):
    return n // gcd(n, m) * m
 
LCM = a[0]
for i in range(1, n):
    LCM = lcm(a[i], LCM)
 
res = 0
MOD = 1000000007
for i in range(n):
    res += LCM//a[i]
    
print(res % MOD)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))

def gcd(n, m):
    if(m): return gcd(m, n%m)
    else: return n

def lcm(n, m):
    return n // gcd(n, m) * m

LCM = a[0]
for i in range(1, n):
    LCM = lcm(a[i], LCM)

res = 0
MOD = 1000000007
for i in range(n):
    res = (res + LCM//a[i]) % MOD
print(res)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
 
def gcd(n, m):
    if(m): return gcd(m, n%m)
    else: return n
 
def lcm(n, m):
    return n // gcd(n, m) * m
 
LCM = a[0]
for i in range(1, n):
    LCM = lcm(a[i], LCM)
 
res = 0
MOD = 1000000007
for i in range(n):
    res += LCM//a[i]
    
print(res % MOD)
Buggy python submission (verdict: Runtime Error):
n, m = map(int, input().split())
q_re = set()
ac = 0
wa = 0
dic_wa = {}
for i in range(m):
    q, re = input().split()
    if(re == "WA" and q not in q_re): 
        if(q not in dic_wa): dic_wa[q] = 1
        else: dic_wa[q] += 1
    if(re == "AC" and q not in q_re): 
        ac += 1
        q_re.add(q)
        wa += dic_wa[q]
print(ac, wa)

Fixed submission:
n, m = map(int, input().split())
q_re = set()
ac = 0
wa = 0
dic_wa = {}
for i in range(m):
    q, re = input().split()
    if(re == "WA" and q not in q_re): 
        if(q not in dic_wa): dic_wa[q] = 1
        else: dic_wa[q] += 1
    if(re == "AC" and q not in q_re): 
        ac += 1
        q_re.add(q)
        if(q in dic_wa): wa += dic_wa[q]
print(ac, wa)
Buggy python submission (verdict: Runtime Error):
H, W, A, B = map(int, input().split())

res = [[0 for i in range(4)] for j in range(4)]
h_cnt = [0] * W

for h in range(H):
    w_cnt = 0
    
    for w in range(W):
        
        if((w_cnt < A or A == 0) and (h_cnt[w] < B or B == 0)):
            res[h][w] = 1
            w_cnt += 1
            h_cnt[w] += 1
            
        elif(w_cnt == A): break
        
        elif(W -  w > A): pass
        
        else:
            print('No')
            quit()
if(h_cnt != [B] * H and B != 0):
    print('No')
    quit()

for h in range(H):
    
    for w in range(W):
        print(res[h][w], end = '')
    print()

Fixed submission:
H, W, A, B = map(int, input().split())
 
for r in range(H):
    for c in range(W):
        if (c < A) ^ (r < B):
            print(str('1'), end="")
        else:
            print(str('0'), end="")
    print("")
Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
 
N, K, Q = map(int, input().split())
A = [int(input()) for _ in range(Q)]
 
member = np.ones(N) * K
 
for a in A:
    member -= 1
    member[a - 1] += 1
 
res = np.array(['No', 'Yes'])[(member > 0).astype('int')]
 
for r in res:
    print(r)

Fixed submission:
N, K, Q = map(int, input().split())
A = [int(input()) for _ in range(Q)]

member = [K - Q] * N

for a in A:
    member[a - 1] += 1

for m in member:
    if m > 0: print("Yes")
    else: print("No")

Buggy python submission (verdict: Runtime Error):
import numpy as np

N, K, Q = map(int, input().split())
A = [int(input()) for _ in range(Q)]

member = np.ones(N) * K

for a in A:
    member -= 1
    member[a - 1] += 1

res = np.array(['No', 'Yes'])[(member > 0).astype('int')]

for r in res:
    print(r)

Fixed submission:
N, K, Q = map(int, input().split())
A = [int(input()) for _ in range(Q)]

member = [K - Q] * N

for a in A:
    member[a - 1] += 1

for m in member:
    if m > 0: print("Yes")
    else: print("No")
Buggy python submission (verdict: Time Limit Exceeded):
n, q = map(int, input().split())

s = input()

lr = []
for i in range(q):
    l, r = map(int, input().split())
    l -= 1
    lr.append([l, r])

for l, r in lr:
    substr = s[l: r]
    print(substr.count('AC'))

Fixed submission:
n, q = map(int, input().split())
s = input()
dp = [0 for _ in range(len(s))]

for i in range(1, len(s)):
    if(s[i-1: i+1] == 'AC'): dp[i] = dp[i-1] + 1
    else: dp[i] = dp[i-1]

for _ in range(q):
    l, r = map(int, input().split())
    print(dp[r-1] - dp[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
S = input()
lr = [list(map(int, input().split())) for _ in range(Q)]

for lr_ in lr:
    l, r = lr_[0], lr_[1]
    cnt = 0
    
    for i in range(len(S[l - 1: r])):
        
        if(S[l - 1: r][i: i + 2] == 'AC'):
            cnt += 1
        
    print(cnt)

Fixed submission:
n, q = map(int, input().split())
s = input()
dp = [0 for _ in range(len(s))]

for i in range(1, len(s)):
    if(s[i-1: i+1] == 'AC'): dp[i] = dp[i-1] + 1
    else: dp[i] = dp[i-1]

for _ in range(q):
    l, r = map(int, input().split())
    print(dp[r-1] - dp[l-1])

Buggy python submission (verdict: Time Limit Exceeded):
N, Q = map(int, input().split())
S = input()
lr = [list(map(int, input().split())) for _ in range(Q)]
 
for lr_ in lr:
    l, r = lr_[0], lr_[1]
    
    print(S[l - 1: r].count('AC'))

Fixed submission:
n, q = map(int, input().split())
s = input()
dp = [0 for _ in range(len(s))]

for i in range(1, len(s)):
    if(s[i-1: i+1] == 'AC'): dp[i] = dp[i-1] + 1
    else: dp[i] = dp[i-1]

for _ in range(q):
    l, r = map(int, input().split())
    print(dp[r-1] - dp[l-1])

Buggy python submission (verdict: Runtime Error):
N, Q = map(int, input().split())
S = input()
lr = [list(map(int, input().split())) for _ in range(N)]

for lr_ in lr:
    l, r = lr_[0], lr_[1]
    
    print(S[l - 1: r].count('AC'))

Fixed submission:
n, q = map(int, input().split())
s = input()
dp = [0 for _ in range(len(s))]

for i in range(1, len(s)):
    if(s[i-1: i+1] == 'AC'): dp[i] = dp[i-1] + 1
    else: dp[i] = dp[i-1]

for _ in range(q):
    l, r = map(int, input().split())
    print(dp[r-1] - dp[l-1])
Buggy python submission (verdict: Runtime Error):
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
A = [list(map(int, input().split())) for _ in range(N)]

cnt = 0

for a in A:
    
    if(sum([ta * tb for ta, tb in zip(a, B)]) + C > 0):
        cnt += 1

print(cnt)

Fixed submission:
H, W = map(int, input().split())
h, w = map(int, input().split())
print((H - h) * (W - w))
Buggy python submission (verdict: Runtime Error):
N = int(input())

A = [map(int, input().split())]
B = [map(int, input().split())]
C = [map(int, input().split())]

dp = [[0, 0, 0] for _ in range(N)]

dp[0][0] = A[0]
dp[0][1] = B[0]
dp[0][2] = C[0]

for i in range(1, N):
    
    dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + A[i]
    dp[i][1] = max(dp[i - 1][2], dp[i - 1][0]) + B[i]
    dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + C[i]

print(max(dp[-1]))

Fixed submission:
N = int(input())

A = [0 for _ in range(N)]
B = [0 for _ in range(N)]
C = [0 for _ in range(N)]

for i in range(N):
    A[i], B[i], C[i] = map(int, input().split())

dp = [[0, 0, 0] for _ in range(N)]

dp[0][0] = A[0]
dp[0][1] = B[0]
dp[0][2] = C[0]

for i in range(1, N):
    
    dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + A[i]
    dp[i][1] = max(dp[i - 1][2], dp[i - 1][0]) + B[i]
    dp[i][2] = max(dp[i - 1][0], dp[i - 1][1]) + C[i]

print(max(dp[-1]))
Buggy python submission (verdict: Runtime Error):
A = int(input())
B = int(input())
C = int(input())
X = int(input())

for a in range(A + 1):
    
    for b in range(B + 1):
        
        for c in range(C + 1):
            
            if(a * 500 + b * 100 + c * 50 == X):
                cnt += 1

print(cnt)

Fixed submission:
A = int(input())
B = int(input())
C = int(input())
X = int(input())
cnt = 0

for a in range(A + 1):
    
    for b in range(B + 1):
        
        for c in range(C + 1):
            
            if(a * 500 + b * 100 + c * 50 == X):
                cnt += 1

print(cnt)