Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
b = list((x,i) for i,x in enumerate(a))
b.sort(reverse=True)
dp = [[0]*(n+1-i) for i in range(n+1)]
for i in range(n):
    x,idx = b[i]
    for j in range(i+1):
        k = i-j
        if dp[j+1][k] < dp[j][k] + x*(idx-j):
            dp[j+1][k] = dp[j][k] + x*(idx-j)
        if dp[j][k+1] < dp[j][k] + x*((n-1-k)-idx):
            dp[j][k+1] = dp[j][k] + x*((n-1-k)-idx)
ans = 0
for i in range(n+1):
    if ans < dp[i][n-i]:
        ans = dp[i][n-i]
print(ans)


Fixed submission:
n = int(input())
a = list(map(int,input().split()))
b = list((x,i) for i,x in enumerate(a))
b.sort(reverse=True)
dp = [[0]*(n+1-i) for i in range(n+1)]
for i in range(n):
    x,idx = b[i]
    for j in range(i+1):
        k = i-j
        if dp[j+1][k] < dp[j][k] + x*(idx-j):
            dp[j+1][k] = dp[j][k] + x*(idx-j)
        if dp[j][k+1] < dp[j][k] + x*((n-1-k)-idx):
            dp[j][k+1] = dp[j][k] + x*((n-1-k)-idx)
ans = 0
for i in range(n+1):
    if ans < dp[i][n-i]:
        ans = dp[i][n-i]
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
b = list((x,i) for i,x in enumerate(a))
b.sort(reverse=True)
dp = [[0]*(n+1) for i in range(n+1)]
for i in range(n):
    for j in range(i+1):
        k = i-j
        x,idx = b[i]
        if dp[j+1][k] < dp[j][k] + x*(idx-j):
            dp[j+1][k] = dp[j][k] + x*(idx-j)
        if dp[j][k+1] < dp[j][k] + x*((n-1-k)-idx):
            dp[j][k+1] = dp[j][k] + x*((n-1-k)-idx)
ans = 0
for i in range(n+1):
    if ans < dp[i][n-i]:
        ans = dp[i][n-i]
print(ans)


Fixed submission:
n = int(input())
a = list(map(int,input().split()))
b = list((x,i) for i,x in enumerate(a))
b.sort(reverse=True)
dp = [[0]*(n+1-i) for i in range(n+1)]
for i in range(n):
    x,idx = b[i]
    for j in range(i+1):
        k = i-j
        if dp[j+1][k] < dp[j][k] + x*(idx-j):
            dp[j+1][k] = dp[j][k] + x*(idx-j)
        if dp[j][k+1] < dp[j][k] + x*((n-1-k)-idx):
            dp[j][k+1] = dp[j][k] + x*((n-1-k)-idx)
ans = 0
for i in range(n+1):
    if ans < dp[i][n-i]:
        ans = dp[i][n-i]
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import math
n = int(input())
ans = 0
for a in range(1,n+1):
    for b in range(1,n+1):
        for c in range(1,n+1):
            ans += math.gcd(a,math.gcd(b,c))
print(ans)


Fixed submission:
import math
n = int(input())
ans = 0
for a in range(1,n+1):
    for b in range(1,n+1):
        for c in range(1,n+1):
            ans += math.gcd(a,math.gcd(b,c))
print(ans)
Buggy python submission (verdict: Runtime Error):
print((int(input()+1)//2))

Fixed submission:
print((int(input())+1)//2)
Buggy python submission (verdict: Time Limit Exceeded):
MOD = 1000000007

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

ans = 0
for k in range(60):
    cnt1 = 0
    for x in a:
        if ((x>>k)&1) == 1:
            cnt1 += 1
    ans += cnt1*(n-cnt1)*(1<<k)
print(ans%MOD)

Fixed submission:
MOD = 1000000007

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

ans = 0
for k in range(60):
    mask = 1<<k
    cnt1 = sum(1 for x in a if x&mask != 0)
    ans += cnt1*(n-cnt1)*(1<<k)
print(ans%MOD)

Buggy python submission (verdict: Time Limit Exceeded):
MOD = 1000000007

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

ans = 0
for k in range(60):
    cnt1 = 0
    for x in a:
        if ((x>>k)&1) == 1:
            cnt1 += 1
    ans += cnt1*(n-cnt1)*(1<<k)
    if ans > MOD:
        ans %= MOD
print(ans)

Fixed submission:
MOD = 1000000007

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

ans = 0
for k in range(60):
    mask = 1<<k
    cnt1 = sum(1 for x in a if x&mask != 0)
    ans += cnt1*(n-cnt1)*(1<<k)
print(ans%MOD)
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
a = [None]*m
c = [0]*m
for i in range(m):
    a[i], b = map(int, input().split())
    ls = list(map(int,input().split()))
    for j in ls:
        c[i] |= 1<<(j-1)
n2 = 1<<n
dp = [1e9]*(n2)
dp[0] = 0
for i in range(m):
    for S in range(n2):
        dp[S|c[i]] = min(dp[S|c[i]], dp[S]+a[i])
if dp[(n2)-1] < 1e9:
    print(dp[(n2)-1])
else:
    print(-1)

Fixed submission:
n, m = map(int, input().split())
a = [None]*m
c = [0]*m
for i in range(m):
    a[i], b = map(int, input().split())
    ls = list(map(int,input().split()))
    for j in ls:
        c[i] |= 1<<(j-1)

dp = [[1e9]*(1<<n) for i in range(m+1)]
dp[0][0] = 0
for i in range(m):
    for S in range(1<<n):
        dp[i+1][S] = min(dp[i+1][S], dp[i][S])
        dp[i+1][S|c[i]] = min(dp[i+1][S|c[i]], dp[i][S]+a[i])
if dp[m][(1<<n)-1] < 1e9:
    print(dp[m][(1<<n)-1])
else:
    print(-1)

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
a = [None]*m
c = [0]*m
for i in range(m):
    a[i], b = map(int, input().split())
    ls = list(map(int,input().split()))
    for j in ls:
        c[i] |= 1<<(j-1)

dp = [[1e9]*(1<<n) for i in range(m+1)]
dp[0][0] = 0
for i in range(m):
    for S in range(1<<n):
        dp[i+1][S] = min(dp[i+1][S], dp[i][S])
        dp[i+1][S|c[i]] = min(dp[i+1][S|c[i]], dp[i][S]+a[i])
if dp[m][(1<<n)-1] < 1e9:
    print(dp[m][(1<<n)-1])
else:
    print(-1)

Fixed submission:
n, m = map(int, input().split())
a = [None]*m
c = [0]*m
for i in range(m):
    a[i], b = map(int, input().split())
    ls = list(map(int,input().split()))
    for j in ls:
        c[i] |= 1<<(j-1)

dp = [[1e9]*(1<<n) for i in range(m+1)]
dp[0][0] = 0
for i in range(m):
    for S in range(1<<n):
        dp[i+1][S] = min(dp[i+1][S], dp[i][S])
        dp[i+1][S|c[i]] = min(dp[i+1][S|c[i]], dp[i][S]+a[i])
if dp[m][(1<<n)-1] < 1e9:
    print(dp[m][(1<<n)-1])
else:
    print(-1)
Buggy python submission (verdict: Time Limit Exceeded):
r,g,b,n = map(int,input().split())
ans = 0
x=n//r+1
y=n//g+1
for i in range(x):
    for j in range(y):
        if r*i+g*j > n:
            break
        if (n-r*i-g*j)%b == 0:
            ans+=1
print(ans)

Fixed submission:
r,g,b,n = map(int,input().split())
ans = 0
x=n//r+1
y=n//g+1
for i in range(x):
    for j in range(y):
        if r*i+g*j > n:
            break
        if (n-r*i-g*j)%b == 0:
            ans+=1
print(ans)
Buggy python submission (verdict: Runtime Error):
n=int(input())
ans=0.0
for i in range(n):
  a=list(input().split())
  if a[1] is "JPY":
    ans += int(a[0])
  else:
    ans += int(a[0])*380000
print(ans)

Fixed submission:
n=int(input())
ans=0.0
for i in range(n):
  a=input().split()
  if a[1] == "JPY":
    ans += float(a[0])
  else:
    ans += float(a[0])*380000
print(ans)
Buggy python submission (verdict: Runtime Error):
a,b,k=map(list(input().split(" ")),int)
if b-a+1 <= k*2:
   for i in range(a,b+1):
      print(i)
else:
   for i in range(a,a+k):
      print(i)
   for i in range(b-k+1,b+1):
      print(i)


Fixed submission:
a,b,k=map(int,list(input().split(" ")))
if b-a+1 <= k*2:
   for i in range(a,b+1):
      print(i)
else:
   for i in range(a,a+k):
      print(i)
   for i in range(b-k+1,b+1):
      print(i)
Buggy python submission (verdict: Runtime Error):
n=input()
a=1
while a*2<=n:
 a*=2
print(a)

Fixed submission:
n=int(input())
a=1
while a*2<=n:
 a*=2
print(a)
Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
a=[]
for i in range(n):
 a+=map(input().split())
a.sort()
ans=0
for i in range(k):
 ans+=a[i]
print(ans)

Fixed submission:
n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
ans=0
for i in range(k):
 ans+=a[n-1-i]
print(ans)

Buggy python submission (verdict: Runtime Error):
n,k=map(int,input().split())
a=[]
for i in range(n)
 a+=map(input().split())
a.sort()
ans=0
for i in range(k)
 ans+=a[i]
print(ans)

Fixed submission:
n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
ans=0
for i in range(k):
 ans+=a[n-1-i]
print(ans)
Buggy python submission (verdict: Runtime Error):
import math
a = input().split()
p = int(a[0])
q = int(a[1]*100)
print(p*q//100)

Fixed submission:
a = input().split()
p = int(a[0])
q = round(float(a[1])*100)
print(p*q//100)
Buggy python submission (verdict: Time Limit Exceeded):
# 日立製作所 社会システム事業部 プログラミングコンテスト2020: B – Nice Shopping
A, B, M = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(j) for j in input().split()]
x, y, c = [], [], []
for k in range(M):
    tmp = [int(i) for i in input().split()]
    x.append(tmp[0])
    y.append(tmp[1])
    c.append(tmp[2])

prices = []

for i in range(A):
    for j in range(B):
        prices.append(a[i] + b[j])

for k in range(M):
    prices.append(a[x[k] - 1] + b[y[k] - 1] - c[k])

print(min(prices))

Fixed submission:
# 日立製作所 社会システム事業部 プログラミングコンテスト2020: B – Nice Shopping
A, B, M = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = [int(j) for j in input().split()]
x, y, c = [], [], []
for k in range(M):
    tmp = [int(i) for i in input().split()]
    x.append(tmp[0])
    y.append(tmp[1])
    c.append(tmp[2])

prices = []

prices.append(min(a) + min(b))

for k in range(M):
    prices.append(a[x[k] - 1] + b[y[k] - 1] - c[k])

print(min(prices))
Buggy python submission (verdict: Runtime Error):
# ABC 133: B – Good Distance
from itertools import combinations

n, d = [int(s) for s in input().split()]

x = []
for _ in range(n):
    x.append([int(s) for s in input().split()])

pairs = list(combinations(x, 2))
the_number_of_pairs = 0

for i in range(n):
    distance = 0

    for j in range(d):
        distance += (abs(pairs[i][0][j] - pairs[i][1][j])) ** 2
    
    distance = distance ** 0.5

    if distance == int(distance):
        the_number_of_pairs += 1

print(the_number_of_pairs)

Fixed submission:
# ABC 133: B – Good Distance
from itertools import combinations

n, d = [int(s) for s in input().split()]

x = []
for _ in range(n):
    x.append([int(s) for s in input().split()])

pairs = list(combinations(x, 2))
the_number_of_pairs = 0

#print(pairs)

for i in range(len(pairs)):
    distance = 0

    for j in range(d):
        distance += (abs(pairs[i][0][j] - pairs[i][1][j])) ** 2
    
    distance = distance ** 0.5

    if distance == int(distance):
#        print(pairs[i])
        the_number_of_pairs += 1

print(the_number_of_pairs)
Buggy python submission (verdict: Runtime Error):
# ABC 130: B – Bounding
n, x = [int(s) for s in input().split()]
l = [int(s) for s in input().split()]

d = 0
times = 0

while d <= x and times <= n:
    d += l[times]
    times += 1

print(times)

Fixed submission:
# ABC 130: B – Bounding
N, X = map(int, input().split())
L = [int(s) for s in input().split()]

D = [0]

for i in range(N):
    D.append(D[i] + L[i])

print(len([d for d in D if d <= X]))

Buggy python submission (verdict: Runtime Error):
# ABC 130: B – Bounding
n, x = [int(s) for s in input().split()]
l = [int(s) for s in input().split()]

d = 0
times = 0

while d <= x:
    d = d + l[times]
    times += 1

print(times)

Fixed submission:
# ABC 130: B – Bounding
N, X = map(int, input().split())
L = [int(s) for s in input().split()]

D = [0]

for i in range(N):
    D.append(D[i] + L[i])

print(len([d for d in D if d <= X]))
Buggy python submission (verdict: Runtime Error):
# ABC 122: B – ATCoder
S = input()
ACGT = 'AGCT'
longest = 0

for start in range(len(S)):
    current = 0
    if S[start] in ACGT:
        current += 1

        if start + 1 < len(S):
            next = start + 1
            while S[next] in ACGT:
                current += 1
                next += 1
        
        longest = max(longest, current)

print(longest)

Fixed submission:
# ABC 122: B – ATCoder
s = input()
acgt = 'ACGT'

length = 0
max_length = 0

for i in range(len(s)):
    if s[i] in acgt:
        for j in range(len(s) - i):
            if s[i + j] in acgt:
                length += 1
            else:
                break

        max_length = max(max_length, length)
        length = 0

print(max_length)
Buggy python submission (verdict: Runtime Error):
----

Fixed submission:
# ABC 101: A – Eating Symbols Easy
s = input()
print(s.count('+') - s.count('-'))
Buggy python submission (verdict: Runtime Error):
v

Fixed submission:
# ABC 100: B – Ringo's Favorite Numbers
d, n = map(int, input().split())
print(n * 100 ** d if n != 100 else (n + 1) * 100 ** d)
Buggy python submission (verdict: Runtime Error):
# ABC 093: B – Small and Large Integers
a, b, k = [int(s) for s in input().split()]
nums = list(range(a, b + 1))
result = []

if k >= len(nums):
    result = nums
else:
    result = [nums[i] for i in set(list(range(0, k)) + list(range(len(nums) - k, len(nums))))]

for num in result:
    print(num)

Fixed submission:
# ABC 093: B – Small and Large Integers
a, b, k = [int(s) for s in input().split()]

if k >= b - a + 1:
    for c in list(range(a, b + 1)):
        print(c)
else:
    s = set(list(range(a, a + k)) + list(range(b - k + 1, b + 1)))
    list_s = list(s)
    list_s.sort()

    for c in list_s:
        print(c)

Buggy python submission (verdict: Runtime Error):
# ABC 093: B – Small and Large Integers
a, b, k = [int(s) for s in input().split()]
nums = list(range(a, b + 1))
result = []

if k > len(nums):
    result = nums
else:
    result = [nums[i] for i in set(list(range(0, k)) + list(range(len(nums) - k, len(nums))))]

for num in result:
    print(num)

Fixed submission:
# ABC 093: B – Small and Large Integers
a, b, k = [int(s) for s in input().split()]

if k >= b - a + 1:
    for c in list(range(a, b + 1)):
        print(c)
else:
    s = set(list(range(a, a + k)) + list(range(b - k + 1, b + 1)))
    list_s = list(s)
    list_s.sort()

    for c in list_s:
        print(c)
Buggy python submission (verdict: Runtime Error):
#  ABC 079: B – Lucas Number
n = int(input())

l0 = 2
l1 = 1

if n == 1:
    print(l1)
else:
    for i in range(2, n + 1):
        l = l0 + l1
        l0 = l1
        l1 = l

print(l)

Fixed submission:
# ABC 079: B – Lucas Number
n = int(input())
lucas = [2, 1]

for i in range(2, n + 1):
    lucas.append(lucas[i - 1] + lucas[i - 2])

print(lucas[n])

Buggy python submission (verdict: Runtime Error):
#  ABC 079: B – Lucas Number
n = int(input())

l0 = 2
l1 = 1

for i in range(2, n + 1):
    l = l0 + l1
    l0 = l1
    l1 = l

print(l)

Fixed submission:
# ABC 079: B – Lucas Number
n = int(input())
lucas = [2, 1]

for i in range(2, n + 1):
    lucas.append(lucas[i - 1] + lucas[i - 2])

print(lucas[n])
Buggy python submission (verdict: Runtime Error):
# CODE FESTIVAL 2017 予選 A: A – Snuke's favorite YAKINIKU
s = input()
if len(s) < 4:
    print('No')
else:
    print('Yes' if s.index('YAKI') == 0 else 'No')

Fixed submission:
# CODE FESTIVAL 2017 予選 A: A – Snuke's favorite YAKINIKU
s = input()
print('Yes' if s[:4] == 'YAKI' else 'No')

Buggy python submission (verdict: Runtime Error):
# CODE FESTIVAL 2017 予選 A: A – Snuke's favorite YAKINIKU
s = input()
print('Yes' if len(s) >= 4 and s.index('YAKI') == 0 else 'No')

Fixed submission:
# CODE FESTIVAL 2017 予選 A: A – Snuke's favorite YAKINIKU
s = input()
print('Yes' if s[:4] == 'YAKI' else 'No')
Buggy python submission (verdict: Time Limit Exceeded):
# ABC 065: B – Trained?
n = int(input())
a = [int(input()) - 1 for _ in range(n)]

lightned = []
lightning = 0

while a[lightning] not in lightned:
    if a[lightning] == 1:
        break

    lightned.append(a[lightning])
    lightning = a[lightning]

print(len(lightned) + 1 if a[lightning] == 1 else -1)

Fixed submission:
# ABC 065: B – Trained?
n = int(input())
a = [int(input()) for _ in range(n)]
lighting = 1
number = 0

for i in range(n):
    if lighting == 2:
        print(number)
        break
    else:
        number += 1
        lighting = a[lighting - 1]
else:
    print(-1)
Buggy python submission (verdict: Runtime Error):
# AGC 015: A – A+...+B Problem
from itertools import combinations_with_replacement

n, a, b = [int(s) for s in input().split()]


if a == b:
    print(1)
elif a > b or n <= 2:
    print(0)
else:
    candidates = list(combinations_with_replacement(range(a, b + 1), n - 2))
    sum_variations = []

    for candidate in candidates:
        if sum(candidate) not in sum_variations:
            sum_variations.append(sum(candidate))
    
    print(len(sum_variations))

Fixed submission:
# AGC 015: A – A+...+B Problem
from itertools import combinations_with_replacement

n, a, b = [int(s) for s in input().split()]


if a == b:
    print(1)
elif a > b or n <= 2:
    print(0)
else:
    print((b - a) * (n - 2) + 1)

Buggy python submission (verdict: Runtime Error):
# AGC 015: A – A+...+B Problem
from itertools import combinations_with_replacement

n, a, b = [int(s) for s in input().split()]


if a == b:
    print(1)
elif a > b or n == 1:
    print(0)
else:
    candidates = list(combinations_with_replacement(range(a, b + 1), n - 2))
    sum_variations = []

    for candidate in candidates:
        if sum(candidate) not in sum_variations:
            sum_variations.append(sum(candidate))
    
    print(len(sum_variations))

Fixed submission:
# AGC 015: A – A+...+B Problem
from itertools import combinations_with_replacement

n, a, b = [int(s) for s in input().split()]


if a == b:
    print(1)
elif a > b or n <= 2:
    print(0)
else:
    print((b - a) * (n - 2) + 1)

Buggy python submission (verdict: Runtime Error):
# AGC 015: A – A+...+B Problem
from itertools import combinations_with_replacement

n, a, b = [int(s) for s in input().split()]

if a > b or n == 1:
    print(0)
elif a == b:
    print(1)
else:
    candidates = list(combinations_with_replacement(range(a, b + 1), n - 2))
    sum_variations = []

    for candidate in candidates:
        if sum(candidate) not in sum_variations:
            sum_variations.append(sum(candidate))
    
    print(len(sum_variations))

Fixed submission:
# AGC 015: A – A+...+B Problem
from itertools import combinations_with_replacement

n, a, b = [int(s) for s in input().split()]


if a == b:
    print(1)
elif a > b or n <= 2:
    print(0)
else:
    print((b - a) * (n - 2) + 1)

Buggy python submission (verdict: Runtime Error):
# AGC 015: A – A+...+B Problem
from itertools import combinations_with_replacement

n, a, b = [int(s) for s in input().split()]

if a > b:
    print(0)
elif a == b:
    print(1)
else:
    candidates = list(combinations_with_replacement(range(a, b + 1), n - 2))
    sum_variations = []

    for candidate in candidates:
        if sum(candidate) not in sum_variations:
            sum_variations.append(sum(candidate))
    
    print(len(sum_variations))

Fixed submission:
# AGC 015: A – A+...+B Problem
from itertools import combinations_with_replacement

n, a, b = [int(s) for s in input().split()]


if a == b:
    print(1)
elif a > b or n <= 2:
    print(0)
else:
    print((b - a) * (n - 2) + 1)
Buggy python submission (verdict: Runtime Error):
# ABC 061: C – Big Array
N, K = [int(i) for i in input().split()]
a, b = [], []
for _ in range(N):
    tmp = input().split()
    a.append(int(tmp[0]))
    b.append(int(tmp[1]))

cnt = [0] * 100000

for i in range(N):
    cnt[a[i]] += b[i]

for j in range(100000):
    if K <= cnt[j]:
        print(j)
        break
    K -= cnt[j]

Fixed submission:
# ABC 061: C – Big Array
N, K = [int(i) for i in input().split()]
a, b = [], []
for _ in range(N):
    tmp = input().split()
    a.append(int(tmp[0]))
    b.append(int(tmp[1]))

cnt = [0] * (100000 + 1)

for i in range(N):
    cnt[a[i]] += b[i]

for j in range(100000 + 1):
    if K <= cnt[j]:
        print(j)
        break
    K -= cnt[j]

Buggy python submission (verdict: Time Limit Exceeded):
# ABC 061: C – Big Array
N, K = [int(i) for i in input().split()]
a, b = [], []
for _ in range(N):
    tmp = input().split()
    a.append(int(tmp[0]))
    b.append(int(tmp[1]))

sequence = []

for i in range(N):
    sequence += [a[i]] * b[i]

sequence.sort()
print(sequence[K - 1])

Fixed submission:
# ABC 061: C – Big Array
N, K = [int(i) for i in input().split()]
a, b = [], []
for _ in range(N):
    tmp = input().split()
    a.append(int(tmp[0]))
    b.append(int(tmp[1]))

cnt = [0] * (100000 + 1)

for i in range(N):
    cnt[a[i]] += b[i]

for j in range(100000 + 1):
    if K <= cnt[j]:
        print(j)
        break
    K -= cnt[j]
Buggy python submission (verdict: Time Limit Exceeded):
# ABC 055: B – Training Camp
from math import factorial

n = int(input())
power = 1

for i in range(1, n + 1):
    power *= i

print(power % (10 ** 9 + 7))

Fixed submission:
# ABC 055: B – Training Camp
from math import factorial

n = int(input())

print(factorial(n) % (10 ** 9 + 7))
Buggy python submission (verdict: Time Limit Exceeded):
# ABC 051: B – Sum of Three Integers
k, s = [int(s) for s in input().split()]
number = 0

for a in range(k + 1):
    for b in range(k + 1):
        for c in range(k + 1):
            if a + b + c == s:
                number += 1

print(number)

Fixed submission:
# ABC 051: B – Sum of Three Integers
k, s = [int(s) for s in input().split()]
number = 0

for a in range(k + 1):
    for b in range(k + 1):
            if 0 <= (s - a - b) <= k:
                number += 1

print(number)
Buggy python submission (verdict: Time Limit Exceeded):
# AGC 007: A – Shik and Stone
H, W = [int(s) for s in input().split()]
A = [input() for _ in range(H)]

isExact = 'Possible'

i, j = 0, 0

while i < H - 1 or j < W - 1:
    A[i] = A[i][:j] + '.' + A[i][j + 1:]

    if (i + 1 < H and A[i + 1][j] != '#') and (j + 1 < W and A[i][j + 1] != '#'):
        isExact = 'Impossible'
        break
    if j + 1 < W and A[i][j + 1] == '#':
        j += 1
    elif i + 1 < H and A[i + 1][j] == '#':
        i += 1

if isExact == 'Possible':
    A[H - 1] = A[H - 1][:W - 1] + '.'

    for line in A:
        if '#' in line:
            isExact = 'Impossible'
            break

print(isExact)

Fixed submission:
# AGC 007: A – Shik and Stone
h, w = [int(s) for s in input().split()]
a = [input() for _ in range(h)]

the_number_of_stones = 0

for i in range(h):
    the_number_of_stones += a[i].count('#')

print('Possible' if the_number_of_stones == h + w - 1 else 'Impossible')

Buggy python submission (verdict: Runtime Error):
# AGC 007: A – Shik and Stone
H, W = [int(s) for s in input().split()]
A = [input() for _ in range(H)]

isExact = 'Possible'

i, j = 0, 0

while i < H - 1 or j < W - 1:
    A[i] = A[i][:j] + '.' + A[i][j + 1:]

    if A[i + 1][j] != '#' and A[i][j + 1] != '#':
        isExact = 'Impossible'
        break
    if j + 1 < W and A[i][j + 1] == '#':
        j += 1
    elif i + 1 < H and A[i + 1][j] == '#':
        i += 1

if isExact == 'Possible':
    A[H - 1] = A[H - 1][:W - 1] + '.'

    for line in A:
        if '#' in line:
            isExact = 'Impossible'
            break

print(isExact)

Fixed submission:
# AGC 007: A – Shik and Stone
h, w = [int(s) for s in input().split()]
a = [input() for _ in range(h)]

the_number_of_stones = 0

for i in range(h):
    the_number_of_stones += a[i].count('#')

print('Possible' if the_number_of_stones == h + w - 1 else 'Impossible')

Buggy python submission (verdict: Time Limit Exceeded):
# AGC 007: A – Shik and Stone
H, W = [int(s) for s in input().split()]
A = [input() for _ in range(H)]

isExact = 'Possible'

i, j = 0, 0

while i < H - 1 or j < W - 1:
    A[i] = A[i][:j] + '.' + A[i][j + 1:]
    
    if j + 1 < W and A[i][j + 1] == '#':
        j += 1
    elif i + 1 < H and A[i + 1][j] == '#':
        i += 1

if isExact == 'Possible':
    A[H - 1] = A[H - 1][:W - 1] + '.'

    for line in A:
        if '#' in line:
            isExact = 'Impossible'
            break

print(isExact)

Fixed submission:
# AGC 007: A – Shik and Stone
h, w = [int(s) for s in input().split()]
a = [input() for _ in range(h)]

the_number_of_stones = 0

for i in range(h):
    the_number_of_stones += a[i].count('#')

print('Possible' if the_number_of_stones == h + w - 1 else 'Impossible')
Buggy python submission (verdict: Time Limit Exceeded):
# CODE FESTIVAL 2016 予選 A: B – 仲良しうさぎ / Friendly Rabbits
N = int(input()) - 1
a = [int(s) - 1 for s in input().split()]

friends = []

for i in range(N):
    if a[a[i]] == i and ([i, a[i]] not in friends and [a[i], i] not in friends):
        friends.append([i, a[i]])

print(len(friends))

Fixed submission:
# CODE FESTIVAL 2016 予選 A: B – 仲良しうさぎ / Friendly Rabbits
N = int(input()) - 1
a = [int(s) - 1 for s in input().split()]

pairs = 0

for i in range(N):
    if a[i] != 0 and a[a[i]] == i:
        pairs += 1
        a[i] = 0
        a[a[i]] = 0

print(pairs)