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

Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n = int(readline())
a = list(map(int,read().split()))
mod = 998244353

sum_a = sum(a)
dp = [ [0] * (sum_a+1) for _ in range(n+1)]
dp_rg = [ [0] * (sum_a+1) for _ in range(n+1)]
dp_rb = [ [0] * (sum_a+1) for _ in range(n+1)]
dp_r = [ [0] * (sum_a+1) for _ in range(n+1)]
dp_r[0][0] = 1
tot = 0

for i in range(1,n+1):
    ai = a[i-1]
    tot += ai
    for j in range(tot+1):
        dp_rg[i][j] += dp_rg[i-1][j] + dp_r[i-1][j]
        dp_rb[i][j] += dp_rb[i-1][j] + dp_r[i-1][j]
        dp[i][j] += dp[i-1][j] * 2 + dp_rb[i-1][j] + dp_rg[i-1][j]

        if(j >= ai):
            dp_r[i][j] += dp_r[i-1][j-ai]
            dp_rg[i][j] += dp_rg[i-1][j-ai]
            dp_rb[i][j] += dp_rb[i-1][j-ai]
            dp[i][j] += dp[i-1][j-ai]
        dp_rg[i][j] %= mod
        dp_rb[i][j] %= mod
        dp[i][j] %= mod

r_over = sum(dp[-1][(1+sum_a)//2:]) % mod
ans = (pow(3,n,mod) - 3*pow(2,n,mod) + 3 - 3*r_over)%mod
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(readline())
a = list(map(int,read().split()))
mod = 998244353

sum_a = sum(a)
dp = [ [0] * (sum_a+1) for _ in range(n+1)]
dp_rg = [ [0] * (sum_a+1) for _ in range(n+1)]
dp_rb = [ [0] * (sum_a+1) for _ in range(n+1)]
dp_r = [ [0] * (sum_a+1) for _ in range(n+1)]
dp_r[0][0] = 1
tot = 0

for i in range(1,n+1):
    ai = a[i-1]
    tot += ai
    for j in range(tot+1):
        dp_rg[i][j] += dp_rg[i-1][j] + dp_r[i-1][j]
        dp_rb[i][j] += dp_rb[i-1][j] + dp_r[i-1][j]
        dp[i][j] += dp[i-1][j] * 2 + dp_rb[i-1][j] + dp_rg[i-1][j]

        if(j >= ai):
            dp_r[i][j] += dp_r[i-1][j-ai]
            dp_rg[i][j] += dp_rg[i-1][j-ai]
            dp_rb[i][j] += dp_rb[i-1][j-ai]
            dp[i][j] += dp[i-1][j-ai]
        dp_rg[i][j] %= mod
        dp_rb[i][j] %= mod
        dp[i][j] %= mod

r_over = sum(dp[-1][(1+sum_a)//2:]) % mod
ans = (pow(3,n,mod) - 3*pow(2,n,mod) + 3 - 3*r_over)%mod
print(ans)
Problem p03161 (python)

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

dp = [0]*n

for i in range(1,n):
    temp = 10**10
    for j in range(1, min(k+1, i+1) ):
        temp = min(temp, abs(h[i] - h[i-j]) + dp[i-j])
    dp[i] = temp

print(dp[n-1])

Buggy submission (verdict: Runtime Error):
import sys
import os
f = open('../../input.txt', 'r')
sys.stdin = f

n,k = map(int, input().split())
h = list(map(int, input().split()))

dp = [0]*(n-1)

for i in range(1,n-1):
    temp = 10**10
    for j in range(1, min(k+1, i+1) ):
        temp = min(temp, abs(h[i] - h[i-j]) + dp[i-j])
    dp[i] = temp

print(dp[n-2])
Problem p03165 (python)

Fixed submission:
s = input()
t = input()

s_len = len(s)
t_len = len(t)

dp = [[0] * (t_len+1) for _ in range(s_len+1)]

for i in range(1,s_len+1):
    s_temp = s[i-1]
    for j in range(1, t_len+1):
        if(s_temp == t[j-1]):
            dp[i][j] = max(dp[i-1][j], dp[i][j-1], dp[i-1][j-1] + 1)
        else:
            dp[i][j] = max(dp[i-1][j], dp[i][j-1])

ans = ''
while(s_len > 0 and t_len > 0):
    if(dp[s_len][t_len] == dp[s_len-1][t_len]):
        s_len -= 1
    elif(dp[s_len][t_len] == dp[s_len][t_len-1]):
        t_len -= 1
    else:
        ans = s[s_len-1]  + ans
        s_len -= 1
        t_len -= 1

print(ans)

Buggy submission (verdict: Runtime Error):
import numpypy as np

s = input()
t = input()

dp = np.full(t , '')
# dp_len = [0]* len(t)

for i in range(len(s)):
    s_temp = s[i]
    temp_max = ''
    max_len = 0
    for j in range(len(t)):
        before = dp[j]
        if(s_temp == t[j]):
            dp[j] = temp_max + s_temp
        if(max_len < len(before)):
            temp_max = before
            max_len = len(temp_max)

ans = ''
for j in range(len(t)):
    if(len(dp[j]) > len(ans)):
        ans = dp[j]

print(ans)

Buggy submission (verdict: Runtime Error):
s = input()
t = input()

dp = ['']* len(t)
# dp_len = [0]* len(t)

for i in range(len(s)):
    s_temp = s[i]
    temp_max = ''
    for j in range(0, len(t)):
        if(s_temp == t[j]):
            dp_temp = temp_max + s_temp
            print(dp_temp)
        else:
            dp_temp = dp[j]

        if( len(dp[j]) > len(temp_max)):
            temp_max = dp[j]
        dp[j] = dp_temp

if( len(dp_temp) > len(temp_max)):
    temp_max = dp_temp

print(temp_max)
Problem p03169 (python)

Fixed submission:
n = int(input())
a = input().split()

c1 = a.count('1')
c2 = a.count('2')
c3 = a.count('3')

dp =[ [[0] * (n+1) for _ in range(c3+c2+1)] for __ in range(c3+1)]
# dp[0][0][0] = 0

for i in range(c3+1):
    for j in range(c3+c2+1-i):
        for k in range(n+1-i-j):
            if(i+j+k == 0):
                dp[i][j][k]=0
            else:
                temp = 0
                if(i > 0):
                    temp += dp[i-1][j+1][k] * i/(k+j+i)
                if(j > 0):
                    temp += dp[i][j-1][k+1] * j/(k+j+i)
                if(k > 0):
                    temp += dp[i][j][k-1] * k/(k+j+i)
                dp[i][j][k] = temp + n/(k+j+i)

print(dp[c3][c2][c1])

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

n = int(input())
a = input().split()

c1 = a.count('1')
c2 = a.count('2')
c3 = a.count('3')

# dp =[ [[-1] * (n+1) for _ in range(n+1)] for __ in range(c3+1)]
# dp = np.full((c3+1, c2+c3+1, n+1), -1.0)
# dp[0][0][0] = 0

from functools import lru_cache
@lru_cache(maxsize=None)
def calc_dp(t3,t2,t1):
    # global dp
    # if(dp[t3][t2][t1] > -1):
    #     return dp[t3][t2][t1]
    if(t3+t2+t1==0):
        return 0

    temp = 0
    if(t3 > 0):
        temp += calc_dp(t3-1,t2+1,t1) * t3/(t1+t2+t3)
    if(t2 > 0):
        temp += calc_dp(t3,t2-1,t1+1) * t2/(t1+t2+t3)
    if(t1 > 0):
        temp += calc_dp(t3,t2,t1-1) * t1/(t1+t2+t3)
    temp = temp + n/(t1+t2+t3)

    # dp[t3][t2][t1] = temp
    return temp

print(calc_dp(c3,c2,c1))

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

n = int(input())
a = input().split()

c1 = a.count('1')
c2 = a.count('2')
c3 = a.count('3')

# dp =[ [[-1] * (n+1) for _ in range(n+1)] for __ in range(c3+1)]
dp = np.full((c3+1, c2+c3+1, n+1), -1.0)
dp[0][0][0] = 0

from functools import lru_cache
@lru_cache(maxsize=None)
def calc_dp(t3,t2,t1):
    # global dp
    if(dp[t3][t2][t1] > -1):
        return dp[t3][t2][t1]

    temp = 0
    if(t3 > 0):
        temp += calc_dp(t3-1,t2+1,t1) * t3/(t1+t2+t3)
    if(t2 > 0):
        temp += calc_dp(t3,t2-1,t1+1) * t2/(t1+t2+t3)
    if(t1 > 0):
        temp += calc_dp(t3,t2,t1-1) * t1/(t1+t2+t3)
    temp = temp + n/(t1+t2+t3)

    # dp[t3][t2][t1] = temp
    return temp

print(calc_dp(c3,c2,c1))

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

n = int(input())
a = input().split()

c1 = a.count('1')
c2 = a.count('2')
c3 = a.count('3')

# dp =[ [[-1] * (n+1) for _ in range(n+1)] for __ in range(c3+1)]
dp = np.full((c3+1, c2+c3+1, n+1), -1.0)
dp[0][0][0] = 0

def calc_dp(t3,t2,t1):
    global dp
    if(dp[t3][t2][t1] > -1):
        return dp[t3][t2][t1]

    temp = 0
    if(t3 > 0):
        temp += calc_dp(t3-1,t2+1,t1) * t3/(t1+t2+t3)
    if(t2 > 0):
        temp += calc_dp(t3,t2-1,t1+1) * t2/(t1+t2+t3)
    if(t1 > 0):
        temp += calc_dp(t3,t2,t1-1) * t1/(t1+t2+t3)
    temp = temp + n/(t1+t2+t3)

    dp[t3][t2][t1] = temp
    return temp

print(calc_dp(c3,c2,c1))
Problem p03404 (python)

Fixed submission:
A,B = map(int, input().split())

w = '.'
b = '#'

ans = [ [b]* 20 + [w] * 20 for _ in range(100)]

for i in range(A-1):
    x = 2 * (i//50)
    y = (i%50) * 2
    ans[y][x] = w
    
for i in range(B-1):
    x = 2 * (i//50) + 21
    y = (i%50) * 2
    ans[y][x] = b
    
print('100 40')
for i in range(100):
    print(''.join(ans[i]))

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

w = '.'
b = '#'

ans = [ [b]* 20 + [w] * 20 for _ in range(100)]

for i in range(A-1):
    x = 2 * i//50
    y = (i%50) * 2
    ans[y][x] = w
    
for i in range(B-1):
    x = 2 * i//50 + 21
    y = (i%50) * 2
    ans[y][x] = b
    
for i in range(100):
    print(''.join(ans[i]))
Problem p03584 (python)

Fixed submission:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n,k = map(int,readline().split())
ab = list(map(int,read().split()))

target = [k]
for i in range(1,30):
    if((k>>i)&1):
        target.append(( k-(1<<i)) | ((1<<i)-1) )

ans = 0
for i in target:
    val = 0
    it = iter(ab)
    for a,b in zip(it,it):
        if( a - (i&a) == 0 ):
            val += b
    ans = max(ans,val)

print(ans)

Buggy submission (verdict: Runtime Error):
n,k = map(int,readline().split())
ab = list(map(int,read().split()))

target = [k]
for i in range(1,30):
    if((k>>i)&1):
        target.append(( k-(1<<i)) | ((1<<i)-1) )

ans = 0
for i in target:
    val = 0
    it = iter(ab)
    for a,b in zip(it,it):
        if( a - (i&a) == 0 ):
            val += b
    ans = max(ans,val)

print(ans)
Problem p04016 (python)

Fixed submission:
n = int(input())
s = int(input())
if(n<s):
    print(-1)
    exit()
elif(n==s):
    print(n+1)
    exit()

lim = 10**6
for i in range(2,lim+1):
    tmp = 0
    x = n
    while(x > 0):
        tmp += x%i
        x //= i
    if(tmp==s):
        print(i)
        exit()

#2桁
ns = n-s
inf = 10**12
ans = inf
for i in range(1,ns+1):
    if(i**2 > ns):
        break

    if(ns%i==0):
        b = ns//i + 1
        y = n-(b*i)
        if(i+y==s)&(0<=y<b):
            ans = min(ans,b)

if(ans==inf):
    print(-1)
else:
    print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
s = int(input())
if(n<s):
    print(-1)
    exit()
elif(n==s):
    print(n+1)
    exit()
elif(s==1):
    print(n+1)
    exit()

lim = 10**6
for i in range(2,lim+1):
    tmp = 0
    x = n
    while(x > 0):
        tmp += x%i
        x //= i
    if(tmp==s):
        print(i)
        exit()

#2桁
ns = n-s
inf = 10**12
ans = inf
for i in range(1,ns+1):
    if(i**2 > ns):
        break

    if(ns%i==0):
        b = ns//i + 1
        y = n-b*i
        if(i+y==s)&(y<b):
            ans = min(ans,j+1)

if(ans==inf):
    print(-1)
else:
    print(ans)
Problem p02705 (python)

Fixed submission:
import math
print(2.*math.pi*int(input()))

Buggy submission (verdict: Runtime Error):
n=int(input())
a=[int(x)for x in input().split()]
c=[0]*n
for e in a:c[e-1]+=1
for e in c:print(e)
Problem p03363 (python)

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

ans = 0;
s = [0]*(n+1);
m = {};
for i in range(0,n):
  s[i+1] = s[i]+a[i];
for i in range(0,n+1):
  m.setdefault(s[i],0);
  m[s[i]]+=1;
for v in m.values():
  ans += v*(v-1)//2
print(ans);

Buggy submission (verdict: Runtime Error):
a
Problem p02658 (python)

Fixed submission:
import sys
n=int(input())
a = list(map(int,input().split()))
ans = 1
a.sort()
for i in range(len(a)):
  ans *= a[i]
  if ans > 1000000000000000000:
    print(-1)
    sys.exit()
print(ans)

Buggy submission (verdict: Runtime Error):
import sys
n=int(input())
a = list(map(int,input().split()))
ans = 1
a.sort()
for i in range(a):
  ans *= a[i]
  if ans > 1000000000000000000:
    print(-1)
    sys.exit()
print(ans)
Problem p03285 (python)

Fixed submission:
n=int(input())
if n % 4 == 0 or n % 7 == 0:
	print("Yes");
else:
	while n > 0:
		n -= 4
		if n % 7 == 0:
			print("Yes")
			exit()
	print("No")

Buggy submission (verdict: Runtime Error):
n=int(input())
if n % 4 == 0 or n % 7 == 0:
  print("Yes");
else:
  while n > 0:
    n -= 4
    if n % 7 == 0:
      print("Yes")
      return
  print("No")

Buggy submission (verdict: Runtime Error):
n=int(input())
if n % 4 == 0 or n % 7 == 0:
  print("Yes");
else:
  while n > 0:
    n -= 4
    if n % 7 == 0:
      print("Yes");
      return
  print("No");
Problem p03861 (python)

Fixed submission:
a,b,x = map(int, input().split())
right = b // x + 1
if a == 0:
  left = 0
else:
  left = (a - 1) // x + 1
print(right - left)

Buggy submission (verdict: Runtime Error):
a,b,x = map(int, input().split())
right = b // x + 1
if a = 0:
  left = 0
else:
  left = (a - 1) // x + 1
print(right - left)
Problem p02555 (python)

Fixed submission:
S = int(input())
DP = [0]*(S+1)
Mod = 10**9+7
if S>=3:
    DP[0] = 1
    DP[1] = 0
    DP[2] = 0
    for TS in range(3,S+1):
        DP[TS] = (DP[TS-1]+DP[TS-3])%Mod
    print(DP[S])
else:
    print(0)

Buggy submission (verdict: Runtime Error):
S = int(input())
DP = [0]*(S+1)
Mod = 10**9+7
DP[0] = 1
DP[1] = 0
DP[2] = 0
for TS in range(3,S+1):
    DP[TS] = (DP[TS-1]+DP[TS-3])%Mod
print(DP[S])

Buggy submission (verdict: Runtime Error):
S = int(input())
DP = [0]*(S+1)
DP[0] = 1
DP[1] = 0
DP[2] = 0
for TS in range(3,S+1):
    DP[TS] = (DP[TS-1]+DP[TS-3])%Mod
print(DP[S])
Problem p02641 (python)

Fixed submission:
X,N = (int(x) for x in input().split())
if N==0:
    print(X)
else:
    P = [int(x) for x in input().split()]
    Target = X
    if Target not in P:
        print(Target)
    else:
        Count = 0 
        Flag  = True
        while Flag:
            Count += 1
            Target = [X-Count,X+Count]
            if Target[1] not in P:
                Flag = False
                Disp = Target[1]
            if Target[0] not in P:
                Flag = False
                Disp = Target[0]
        print(Disp)

Buggy submission (verdict: Runtime Error):
X,N = (int(x) for x in input().split())
if N==0:
    print(X)
else:
    P = [int(x) for x in input().split()]
    Flag   = True
    Target = X
    Count  = 0 
    if Target not in P:
        Flag = False
        print(X)
    else:
        while Flag:
            Count += 1
            Target = [X-Count,X+Count]
            if Target[1] not in P:
                Flag = False
                Disp = Target[1]
            if Target[0] not in P:
                Flag = False
                Disp = Target[0]
    print(Disp)
Problem p02646 (python)

Fixed submission:
A,V = (int(x) for x in input().split())
B,W = (int(x) for x in input().split())
T = int(input())

if V>W and abs(A-B)/(V-W)<=T:
    Flag = True
else:
    Flag = False
    
if Flag:
    print('YES')
else:
    print('NO')

Buggy submission (verdict: Runtime Error):
A,V = (int(x) for x in input().split())
B,W = (int(x) for xin input().split())
T = int(input())

if V>W and abs(A-B)/(V-W)<=T:
    Flag = True
else:
    Flag = False
    
if Flag:
    print('YES')
else:
    print('NO')

Buggy submission (verdict: Runtime Error):
A,V = (int(x) for x in input().split())
B,W = (int(x) for x in input().split())
T = int(input())
if V>W:
    if (A-B)%(V-W)==0:
        if abs(A-B)//(V-W)<=T:
            Flag = 1
    else:
        if abs(A-B)//(V-W)+1<=T:
            Flag = 1
else:
    Flag = False
    
if Flag:
    print('YES')
else:
    print('NO')

Buggy submission (verdict: Runtime Error):
A,V = (int(x) for x in input().split())
B,W = (int(x) for x in input().split())
T = int(input())
if V>W:
    if (A-B)%(V-W)==0:
        if abs(A-B)//(V-W)<=T:
            Flag = 1
    else:
        if abs(A-B)/(V-W)+1<=T:
            Flag = 1
else:
    Flag = False
    
if Flag:
    print('YES')
else:
    print('NO')

Buggy submission (verdict: Runtime Error):
A,V = (int(x) for x in input().split())
B,W = (int(x) for x in input().split())
T = int(input())
if V>W and (A-B)%(V-W)==0 and abs(A-B)//(V-M)<=T:
    Flag = True
else:
    Flag = False
    
if Flag:
    print('YES')
else:
    print('NO')

Buggy submission (verdict: Runtime Error):
A,V = (int(x) for x in input().split())
B,W = (int(x) for x in input().split())
T = int(input())
Flag = False
if V>W and (A-B)%(V-W)==0 and (A-B)//(V-M) <= T:
    Flag = True
    
if Flag:
    print('YES')
else:
    print('NO')
Problem p03087 (python)

Fixed submission:
N,Q = (int(X) for X in input().split())
S = input()
T = [0]*(N+1)
for I in range(0,N):
     T[I+1] = T[I] + (S[I:I+2]=='AC')
for J in range(0,Q):
    L,R = (int(X)-1 for X in input().split())
    print(T[R]-T[L])

Buggy submission (verdict: Runtime Error):
N,Q = (int(X) for X in input().split())
S = input()
AIndex = [Ind for Ind,Str in enumerate(S) if S[Ind:Ind+2]=='AC']
if len(AIndex)==0:
    print('\n'.join(['0']*Q))
else:
    CIndex = [X+1 for X in AIndex]
    for T in range(0,Q):
        L,R = (int(X) for X in input().split())
        LN = [(L-1)<=X for X in AIndex].index(True)
        RN = len(CIndex)-[(R-1)>=X for X in CIndex][::-1].index(True)
        print(RN-LN)

Buggy submission (verdict: Runtime Error):
N,Q = (int(X) for X in input().split())
S = input()
AIndex = [Ind for Ind,Str in enumerate(S) if S[Ind]=='A' and S[Ind+1]=='C']
CIndex = [X+1 for X in AIndex]
for T in range(0,Q):
    L,R = (int(X) for X in input().split())
    LIndex = [(L-1)<=X for X in AIndex]
    RIndex = [(R-1)>=X for X in CIndex]
    print(sum([X and Y for X,Y in zip(LIndex,RIndex)]))
Problem p03192 (python)

Fixed submission:
print(input().count('2'))

Buggy submission (verdict: Runtime Error):
print(input().count('2')
Problem p03231 (python)

Fixed submission:
import math
N,M = (int(T) for T in input().split())
S = input()
T = input()
Length = N*M//math.gcd(N,M)
Flag   = True
SIndex = [Nk*(Length//N) for Nk in range(0,N)]
SList  = list(S)
    
for Mk in range(0,M):
    if Mk%(Length//N)==0:
        MInd = SIndex.index(Mk*(Length//M))
        if SList[MInd]!=T[Mk]:
            Flag = False
            break
        
if Flag:
    print(Length)
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
import math
N,M = (int(T) for T in input().split())
S = input()
T = input()

Length = N*M//math.gcd(N,M)
String = ['']*Length
Flag   = True

for Nk in range(0,N):
    String[Nk*(Length//N)] = S[Nk]

for Mk in range(0,M):
    Target = String[Mk*(Length//M)]
    if Target=='' or Target==T[Mk]:
        String[Mk*(Length//M)] = T[Mk]
    else:
        Flag = False
        break        
if Flag:
    print(Length)
else:
    print(-1)

Buggy submission (verdict: Runtime Error):
import math
N,M = (int(T) for T in input().split())
Length = N*M//math.gcd(N,M)
S = input()
T = input()
String = ['']*Length
Flag   = True
for Nk in range(0,N):
    String[Nk*(Length//N)] = S[Nk]
    
for Mk in range(0,M):
    Target = String[Mk*(Length//M)]
    if Target=='' or Target==T[Mk]:
        String[Mk*(Length//M)] = T[Mk]
    else:
        Flag = False
if Flag:
    print(Length)
else:
    print(-1)
Problem p03240 (python)

Fixed submission:
N = int(input())

Info = [[] for T in range(0,N)]
for I in range(0,N):
    Info[I] = [int(T) for T in input().split()]
Info = sorted(Info,reverse=True,key=lambda X:X[2])
for CX in range(0,101):
    for CY in range(0,101):
        Flag  = True
        BaseH = abs(Info[0][0]-CX)+abs(Info[0][1]-CY)+Info[0][2]
        for I in range(1,N):
            if max(BaseH-abs(Info[I][0]-CX)-abs(Info[I][1]-CY),0)!=Info[I][2]:
                Flag = False
                break
        if Flag:
            Ans = [str(CX),str(CY),str(BaseH)]
            break
    if Flag:
        break
print(' '.join(Ans))

Buggy submission (verdict: Runtime Error):
N = int(input())

Info = [[] for T in range(0,N)]
for I in range(0,N):
    Info[I] = [int(T) for T in input().split()]
Info = sorted(Info,reverse=True,key=lambda X:X[2])

for CX in range(0,101):
    for CY in range(0,101):
        Flag  = True
        BaseH = abs(Info[0][0]-CX)+abs(Info[0][1]-CY)+Info[0][2]
        for I in range(1,N):
            if BaseH-abs(Info[I][0]-CX)-abs(Info[I][1]-CY)!=Info[I][2]:
                Flag = False
                break
        if Flag:
            Ans = [str(CX),str(CY),str(BaseH)]
            break
    if Flag:
        break
print(' '.join(Ans))
Problem p03282 (python)

Fixed submission:
S = input()
K = int(input())
Flag = True
for T in range(0,min(K,len(S))):
    if S[T]!='1':
        Disp = S[T]
        Flag = False
        break
if Flag: print('1')
else: print(Disp)

Buggy submission (verdict: Runtime Error):
S = input()
K = int(input())
for T in range(0,min(K,len(S))):
    if S[T]!='1':
        Disp = S[T]
        Flag = False
        break
if Flag: print('1')
else: print(Disp)
Problem p03503 (python)

Fixed submission:
def ForBaseConvert(Roop,MaxD,Base):
    if all(type(TT) is int for TT in [Roop,MaxD,Base]):
        if Base>=2 and MaxD>=1:
            ConvertN = []
            while Roop>0:
                ConvertN.append(Roop%Base)
                Roop = Roop//Base

            BaseConv = [0]*(MaxD-len(ConvertN))+ConvertN[::-1]
            BaseSInd = [[] for TB in range(0,Base)]
            for TB in range(0,Base):
                BaseSInd[TB] = [SInd for SInd,SNum in enumerate(BaseConv) if SNum==TB]
            return BaseConv,BaseSInd
        else:
            return []
    else:
        return []
      
N = int(input())
F = [[] for TF in range(0,N)]
for TF in range(0,N):
    F[TF] = [int(T) for T in input().split()]
P = [[] for TP in range(0,N)]
for TP in range(0,N):
    P[TP] = [int(T) for T in input().split()]
    
MAXB = -10**9
for TB in range(1,2**10):
    BaseConv,BaseSInd = ForBaseConvert(TB,10,2)
    Benefit = 0
    for TN in range(0,N):        
        Count = sum(1 if F[TN][TT]==1 else 0 for TT in BaseSInd[1])
        Benefit += P[TN][Count]
    if MAXB<Benefit:
        MAXB = Benefit
print(MAXB)

Buggy submission (verdict: Runtime Error):
N = int(input())
F = [[] for TF in range(0,N)]
for TF in range(0,N):
    F[TF] = [int(T) for T in input().split()]
P = [[] for TP in range(0,N)]
for TP in range(0,N):
    P[TP] = [int(T) for T in input().split()]
    
MAXB = -10**9
for TB in range(1,2**10):
    BaseConv,BaseSInd = ForBaseConvert(TB,10,2)
    Benefit = 0
    for TN in range(0,N):        
        Count = sum(1 if F[TN][TT]==1 else 0 for TT in BaseSInd[1])
        Benefit += P[TN][Count]
    if MAXB<Benefit:
        MAXB = Benefit
print(MAXB)
Problem p03583 (python)

Fixed submission:
N = int(input())
A,B,C = 0,0,0
for TA in range(1,3501):
    for TB in range(1,3501):
        Numer = TA*TB*N
        Denom = 4*TA*TB-(TA+TB)*N
        if Denom>0 and Numer>0 and Numer%Denom==0:
            A = TA
            B = TB
            C = Numer//Denom
print('{} {} {}'.format(A,B,C))

Buggy submission (verdict: Runtime Error):
# (A,B,C)<=3500
# 4/N = (1/A)+(1/B)+(1/C)
# (4/N)-(1/A) = (1/B)+(1/C)
# (4A-N)/AN   = (B+C)/BC

# XX-(4A-N)X+AN=0
# X = (-b±sqrt(bb-4c))/2 (a=1)
#   = ((4A-N)±sqrt((4A-N)(4A-N)-4AN))/2
#   = ((4A-N)±sqrt(16AA-12AN+NN))/2


def BiSearch(Func,N):
    Left  = 0
    FLeft = Func(Left)
    Right  = N
    FRight = Func(Right)
    Flag = False
    while Left<=Right:
        Med  = (Left+Right)//2
        FMed = Func(Med)
        if FMed==N:
            Flag = True
            return Med
        elif FMed>N:
            Right  = Med-1
            FRight = Func(Right)
        else:
            Left  = Med+1
            FLeft = Func(Left)
    if not Flag:
        return False
def SquareRootSearch(K):
    return BiSearch(lambda N:N*N,K)

N = int(input())
for TA in range(1,3501):
    SqrtX = SquareRootSearch(16*(TA**2)-(12*TA*N)+(N**2))
    if SqrtX:
        NumerB = (4*TA-N)+SqrtX
        NumerC = (4*TA-N)-SqrtX
        if NumerB%2==0 and NumerC%2==0 and NumerB>0 and NumerC>0:
            A = TA
            B = NumerB//2
            C = NumerC//2
print('{} {} {}'.format(A,B,C))