Buggy python submission (verdict: Time Limit Exceeded):

import sys


def solv(n):
    r = 0
    m = n / 2
    ps = filter(lambda x: x <= m, primes)
    for p in ps:
        q = n - p
        if q in primes:
            r += 1
    return r


def prime_list(n):
    limit = int(n ** 0.5) + 1
    lis = range(1, n + 1, 2)
    lis[0] = 2
    while True:
        if len(lis) == 0:
            break
        p = lis.pop(0)
        yield p
        if p <= limit:
            lis = [x for x in lis if x % p != 0]


primes = []
for p in prime_list(50000):
    primes.append(p)

while True:
    n = int(sys.stdin.readline())
    if n == 0:
        exit()
    print solv(n)

Fixed submission:

import sys
import itertools


def prime_list(n):
    limit = int(n ** 0.5) + 1
    lis = range(1, n + 1, 2)
    lis[0] = 2
    while True:
        if len(lis) == 0:
            break
        p = lis.pop(0)
        yield p
        if p <= limit:
            lis = [x for x in lis if x % p != 0]


primes = []
for p in prime_list(50000):
    primes.append(p)
c = [0] * 50001 * 2
for i, j in itertools.combinations(primes, 2):
    c[i+j] += 1
for i in primes:
    c[i+i] += 1
while True:
    n = int(sys.stdin.readline())
    if n == 0:
        exit()
    print c[n]

Buggy python submission (verdict: Time Limit Exceeded):

import sys


def solv(n):
    r = 0
    for p in primes:
        if n/2 < p:
            break
        q = n - p
        if q in primes:
            r += 1
    return r


def prime_list(n):
    limit = int(n ** 0.5) + 1
    lis = range(1, n + 1, 2)
    lis[0] = 2
    while True:
        if len(lis) == 0:
            break
        p = lis.pop(0)
        yield p
        if p <= limit:
            lis = [x for x in lis if x % p != 0]


primes = []
for p in prime_list(50000):
    primes.append(p)

while True:
    n = int(sys.stdin.readline())
    if n == 0:
        exit()
    print solv(n)

Fixed submission:

import sys
import itertools


def prime_list(n):
    limit = int(n ** 0.5) + 1
    lis = range(1, n + 1, 2)
    lis[0] = 2
    while True:
        if len(lis) == 0:
            break
        p = lis.pop(0)
        yield p
        if p <= limit:
            lis = [x for x in lis if x % p != 0]


primes = []
for p in prime_list(50000):
    primes.append(p)
c = [0] * 50001 * 2
for i, j in itertools.combinations(primes, 2):
    c[i+j] += 1
for i in primes:
    c[i+i] += 1
while True:
    n = int(sys.stdin.readline())
    if n == 0:
        exit()
    print c[n]

Buggy python submission (verdict: Time Limit Exceeded):

import sys


def solv(n):
    r = 0
    if n % 2 == 1:
        if (n-2) in primes:
            return 1
    else:
        for p in primes:
            if n/2 < p:
                break
            q = n - p
            if q in primes:
                r += 1
    return r


def prime_list(n):
    limit = int(n ** 0.5) + 1
    lis = range(1, n + 1, 2)
    lis[0] = 2
    while True:
        if len(lis) == 0:
            break
        p = lis.pop(0)
        yield p
        if p <= limit:
            lis = [x for x in lis if x % p != 0]


primes = []
for p in prime_list(50000):
    primes.append(p)

while True:
    n = int(sys.stdin.readline())
    if n == 0:
        exit()
    print solv(n)

Fixed submission:

import sys
import itertools


def prime_list(n):
    limit = int(n ** 0.5) + 1
    lis = range(1, n + 1, 2)
    lis[0] = 2
    while True:
        if len(lis) == 0:
            break
        p = lis.pop(0)
        yield p
        if p <= limit:
            lis = [x for x in lis if x % p != 0]


primes = []
for p in prime_list(50000):
    primes.append(p)
c = [0] * 50001 * 2
for i, j in itertools.combinations(primes, 2):
    c[i+j] += 1
for i in primes:
    c[i+i] += 1
while True:
    n = int(sys.stdin.readline())
    if n == 0:
        exit()
    print c[n]

Buggy python submission (verdict: Time Limit Exceeded):

import sys


def solv(n):
    r = 0
    if n % 2 == 1:
        if (n-2) in primes:
            r = 1
    else:
        for p in primes:
            if n/2 < p:
                break
            q = n - p
#            if q in primes:
            if binary_search(primes, q):
                r += 1
    return r


def prime_list(n):
    limit = int(n ** 0.5) + 1
    lis = range(1, n + 1, 2)
    lis[0] = 2
    while True:
        if len(lis) == 0:
            break
        p = lis.pop(0)
        yield p
        if p <= limit:
            lis = [x for x in lis if x % p != 0]


def binary_search(lis, x):
    if len(lis) == 0:
        return None
    i = len(lis) / 2
    if lis[i] == x:
        return x
    elif x < lis[i]:
        return binary_search(lis[:i], x)
    else:
        return binary_search(lis[i+1:], x)


primes = []
for p in prime_list(50000):
    primes.append(p)

while True:
    n = int(sys.stdin.readline())
    if n == 0:
        exit()
    print solv(n)

Fixed submission:

import sys
import itertools


def prime_list(n):
    limit = int(n ** 0.5) + 1
    lis = range(1, n + 1, 2)
    lis[0] = 2
    while True:
        if len(lis) == 0:
            break
        p = lis.pop(0)
        yield p
        if p <= limit:
            lis = [x for x in lis if x % p != 0]


primes = []
for p in prime_list(50000):
    primes.append(p)
c = [0] * 50001 * 2
for i, j in itertools.combinations(primes, 2):
    c[i+j] += 1
for i in primes:
    c[i+i] += 1
while True:
    n = int(sys.stdin.readline())
    if n == 0:
        exit()
    print c[n]

Buggy python submission (verdict: Time Limit Exceeded):

import sys


def solv(n):
    r = 0
    if n % 2 == 1:
#        if (n-2) in primes:
        if binary_search(primes, n-2):
            r = 1
    else:
        for p in primes:
            if n/2 < p:
                break
            q = n - p
#            if q in primes:
            if binary_search(primes, q):
                r += 1
    return r


def prime_list(n):
    limit = int(n ** 0.5) + 1
    lis = range(1, n + 1, 2)
    lis[0] = 2
    while True:
        if len(lis) == 0:
            break
        p = lis.pop(0)
        yield p
        if p <= limit:
            lis = [x for x in lis if x % p != 0]


def binary_search(lis, x):
    if len(lis) == 0:
        return None
    i = len(lis) / 2
    if lis[i] == x:
        return x
    elif x < lis[i]:
        return binary_search(lis[:i], x)
    else:
        return binary_search(lis[i+1:], x)


primes = []
for p in prime_list(50000):
    primes.append(p)

while True:
    n = int(sys.stdin.readline())
    if n == 0:
        exit()
    print solv(n)

Fixed submission:

import sys
import itertools


def prime_list(n):
    limit = int(n ** 0.5) + 1
    lis = range(1, n + 1, 2)
    lis[0] = 2
    while True:
        if len(lis) == 0:
            break
        p = lis.pop(0)
        yield p
        if p <= limit:
            lis = [x for x in lis if x % p != 0]


primes = []
for p in prime_list(50000):
    primes.append(p)
c = [0] * 50001 * 2
for i, j in itertools.combinations(primes, 2):
    c[i+j] += 1
for i in primes:
    c[i+i] += 1
while True:
    n = int(sys.stdin.readline())
    if n == 0:
        exit()
    print c[n]