Buggy python submission (verdict: Time Limit Exceeded):
import sys
for line in sys.stdin:
    n = int(line)
    count = 0
    for i in range(2,n+1):
        k = 2
        flag = True
        while k**2 <= i:
            if i%k == 0:
                flag = False
                break
            k += 1
        if flag:
            count += 1
    print (count)

Fixed submission:
import sys
prime = [0]
isPrime = [1 for i in range(1000000)]
isPrime[0] = 0
isPrime[1] = 0
for i in sys.stdin:
    n = int(i)
    if prime[len(prime)-1] < n:
        for i in range(prime[len(prime)-1]+1,n+1):
            if isPrime[i] == 1:
                prime.append(i)
                for j in range(i*2, 1000000, i):
                    isPrime[j] = 0
    print(sum(isPrime[:n+1]))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
for line in sys.stdin:
    n = int(line)
    arr = [i for i in range(0,n+1)]
    k = 2
    while k**2 <= n:
        for i in range(len(arr)):
            if arr[i]%k == 0 and arr[i] != 2:
                arr[i] = 0
        print(k, arr)
        k += 1
    count = 0
    for i in range(len(arr)):
        if arr[i] != 0 and arr[i] != 1:
            count += 1
    print(count)

Fixed submission:
import sys
prime = [0]
isPrime = [1 for i in range(1000000)]
isPrime[0] = 0
isPrime[1] = 0
for i in sys.stdin:
    n = int(i)
    if prime[len(prime)-1] < n:
        for i in range(prime[len(prime)-1]+1,n+1):
            if isPrime[i] == 1:
                prime.append(i)
                for j in range(i*2, 1000000, i):
                    isPrime[j] = 0
    print(sum(isPrime[:n+1]))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
import math

def isPrime(n):
    if n < 2:
        return False
    elif n == 2:
        return True

    if n % 2 == 0:
        return False

    for i in range(3,math.ceil(math.sqrt(n))+1):
         if n % i == 0:
            return False
    return True

for line in sys.stdin:
    n = int(line)
    count = 0
    for i in range(2,n+1):
        if isPrime(i):
            count += 1
    print(count)

Fixed submission:
import sys
prime = [0]
isPrime = [1 for i in range(1000000)]
isPrime[0] = 0
isPrime[1] = 0
for i in sys.stdin:
    n = int(i)
    if prime[len(prime)-1] < n:
        for i in range(prime[len(prime)-1]+1,n+1):
            if isPrime[i] == 1:
                prime.append(i)
                for j in range(i*2, 1000000, i):
                    isPrime[j] = 0
    print(sum(isPrime[:n+1]))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
for i in sys.stdin:
    n = int(i)
    arr = [i for i in range(0,n+1)]
    for i in range(2, len(arr)):
        if arr[i] != 0:
            j = 2
            while i*j <= n:
                if arr[i*j] != 0:
                    arr[i*j] = 0
                j += 1
    primNum = 0
    for i in arr:   
        if i > 1:
            primNum += 1
    print(primNum)

Fixed submission:
import sys
prime = [0]
isPrime = [1 for i in range(1000000)]
isPrime[0] = 0
isPrime[1] = 0
for i in sys.stdin:
    n = int(i)
    if prime[len(prime)-1] < n:
        for i in range(prime[len(prime)-1]+1,n+1):
            if isPrime[i] == 1:
                prime.append(i)
                for j in range(i*2, 1000000, i):
                    isPrime[j] = 0
    print(sum(isPrime[:n+1]))

Buggy python submission (verdict: Time Limit Exceeded):
p = [0, 0, 1, 1, 0, 1]
while True:
    try:
        n = int(input())
        if len(p) < n+1:
            i = len(p)
            while i < n+1:
                j = 2
                flag = True
                while j <= i**0.5:
                    if i % j == 0:
                        p.append(0)
                        flag = False
                        break
                    j += 1
                if flag == True:
                    p.append(1)
                i += 1
        print(sum(p[0:n+1]))
    except:
        break

Fixed submission:
import sys
prime = [0]
isPrime = [1 for i in range(1000000)]
isPrime[0] = 0
isPrime[1] = 0
for i in sys.stdin:
    n = int(i)
    if prime[len(prime)-1] < n:
        for i in range(prime[len(prime)-1]+1,n+1):
            if isPrime[i] == 1:
                prime.append(i)
                for j in range(i*2, 1000000, i):
                    isPrime[j] = 0
    print(sum(isPrime[:n+1]))

Buggy python submission (verdict: Runtime Error):
import sys
prime = [0 for i in range(1000000)]
isPrime = [1 for i in range(1000000)]
isPrime[0] = 0
isPrime[1] = 0
p = 0

for i in sys.stdin:
    n = int(i)
    for i in range(2,n+1):
        if isPrime[i] == 1:
            p += 1
            prime[p] = i
            for j in range(i*2, n+1, i):
                isPrime[j] = 0
    print(sum(isPrime[:n+1]))

Fixed submission:
import sys
prime = [0]
isPrime = [1 for i in range(1000000)]
isPrime[0] = 0
isPrime[1] = 0
for i in sys.stdin:
    n = int(i)
    if prime[len(prime)-1] < n:
        for i in range(prime[len(prime)-1]+1,n+1):
            if isPrime[i] == 1:
                prime.append(i)
                for j in range(i*2, 1000000, i):
                    isPrime[j] = 0
    print(sum(isPrime[:n+1]))