Problem p03674 (python)

Fixed submission:
# -*- coding: utf-8 -*-

from collections import Counter
import re

def pow(a, x):
        y = 1
        p = a % mask
        n = x
        while (n > 0):
                if ((n % 2) == 0):
                        p = (p * p) % mask
                        n /= 2
                else:   
                        y = (y * p) % mask
                        n -= 1
        return y

n = int(raw_input())
a = map(int, re.split("\s", raw_input()))
left = 0
right = 0

mask = 10**9 + 7
invm = 10**9 + 5

com = [1]*(n+2)
inv = [1]*(n+2)

tmp = 1 
for i in range(1, n+2):
        tmp = (tmp * i) % mask
        com[i] = tmp
        inv[i] = pow(tmp, invm) % mask

counter = Counter(a)
dup = counter.most_common(1)[0][0]
left = a.index(dup)
right = a[left+1:].index(dup) + left + 1

for i in range(1, n + 2):
        ans = (com[n + 1] * (inv[i] * inv[n + 1 - i]))

        if ((left + n - right - i + 1) >= 0):
                ans -= (com[left + n - right] * inv[i - 1] * inv[left + n - right - i + 1])
        print ans % mask

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

from collections import Counter
import re

def pow(a, x):
        y = 1
        p = a
        n = x % mask
        while (n > 0):
                if ((n % 2) == 0):
                        p = (p * p) % mask
                        n /= 2
                else:   
                        y = (y * p) % mask
                        n -= 1
        return y

n = int(raw_input())
a = map(int, re.split("\s", raw_input()))
left = 0
right = 0

mask = 10**9 + 7
invm = 10**9 + 5

com = [1]*(n+2)
inv = [1]*(n+2)

tmp = 1
for i in range(1, n+2):
        tmp = (tmp * i) % mask
        com[i] = tmp
        inv[i] = pow(tmp, invm) % mask

counter = Counter(a)
dup = counter.most_common(1)[0][0]
left = a.index(dup)
right = a[left+1:].index(dup)

'''
for i in range(0, n + 1):
        x = a.index(a[i])
        if a[i] in a[x+1:]:
                left = i
                right = a[x+1:].index(a[i]) + x + 1
                break
'''

for i in range(1, n + 2):
        ans = (com[n + 1] * (inv[i] * inv[n + 1 - i])) % mask

        if ((left + n - right - i + 1) > 0):
                ans -= (com[left + n - right] * inv[i - 1] * inv[left + n - right - i + 1]) % mask
        print (ans - x)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

import re

n = int(raw_input())
a = map(int, re.split("\s", raw_input()))
left = 0
right = 0
mask = 10**9 + 7

com = [0]*(n+2)

tmp = 1
for i in range(1, n+2):
        tmp *= i
        com[i] = tmp

for i in range(0, n + 1):
        x = a.index(a[i])
        if a[i] in a[x+1:]:
                left = i  
                right = a[x+1:].index(a[i]) + x + 1
                break

for i in range(1, n + 2):
        ans = (com[n + 1] / (com[i] * com[n + 1 - i]))
        x = (com[left + n - right] / (com[i - 1] * com[left + n - right - i + 1]))
        print (ans - x) % mask

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

import re

n = int(raw_input())
a = map(int, re.split("\s", raw_input()))
left = 0
right = 0
mask = 10**9 + 7

com = [0]*n+2

tmp = 1
for i in range(1, n+2):
        tmp *= i
        com[i] = tmp

for i in range(0, n + 1):
        x = a.index(a[i])
        if a[i] in a[x+1:]:
                left = i  
                right = a[x+1:].index(a[i]) + x + 1
                break

for i in range(1, n + 2):
        ans = (com[n + 1] / (com[i] * com[n + 1 - i]))
        x = (com[left + n - right] / (com[i - 1] * com[left + n - right - i + 1]))
        print (ans - x) % mask

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

import re

n = int(raw_input())
a = map(int, re.split("\s", raw_input()))
left = 0
right = 0
mask = 10**9 + 7

pow = [0]*n+2

tmp = 1
for i in range(1, n+2):
        tmp *= i
        pow[i] = tmp

for i in range(0, n + 1):
        x = a.index(a[i])
        if a[i] in a[x+1:]:
                left = i
                right = a[x+1:].index(a[i]) + x + 1
                break

for i in range(1, n + 2):
        ans = (pow[n + 1] / (pow[i] * pow[n + 1 - i]))
        x = (pow[left + n - right] / (pow[i - 1] * pow[left + n - right - i + 1]))
        print (ans - x) % mask

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

import re



n = int(raw_input())
a = map(int, re.split("\s", raw_input()))
left = 0
right = 0
mask = 10**9 + 7

pow = [0]*n+2

tmp = 1
for i in range(1, n+2):
        tmp *= i
        pow[i] = tmp

for i in range(0, n + 1):
        x = a.index(a[i])
        if a[i] in a[x+1:]:
                left = i
                right = a[x+1:].index(a[i]) + x + 1
                break

for i in range(1, n + 2):
        ans = (pow[n + 1] / (pow[i] * pow[n + 1 - i]))
        x = (pow[left + n - right] / (pow[i - 1] * pow[left + n - right - i + 1]))
        print (ans - x) % mask

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

import re

def comb(n, k):
        a = [0] * 17
        if (n - k < k):
                k = n - k
        if (k == 0):
                return 1
        if (k == 1):
                return n
        if (k > 17):
                return 0
        for i in range(1, k):
                a[i] = i + 2
        for i in range(3, (n - k + 2)):
                a[0] = i
                for j in range(1, k):
                        a[j] += a[j - 1]
        return a[k - 1]

n = int(raw_input())
a = map(int, re.split("\s", raw_input()))
left = 0
right = 0
mask = 10**9 + 7

for i in range(0, n + 1):
        x = a.index(a[i])
        if a[i] in a[x+1:]:
                left = i
                right = a[x+1:].index(a[i]) + x + 1
                break

for i in range(1, n + 2):
        ans = comb(n + 1, i)
        ans -= comb(left + n - right, i - 1)
        print ans % mask

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

import re

def comb(n, k):
        a = [0] * 17
        if (n - k < k):
                k = n - k
        if (k == 0):
                return 1
        if (k == 1):
                return n
        if (k > 17):
                return 0
        for i in range(1, k):
                a[i] = i + 2
        for i in range(3, (n - k + 2)):
                a[0] = i
                for j in range(1, k):
                        a[j] += a[j - 1]
        return a[k - 1]

n = int(raw_input())
a = map(int, re.split("\s", raw_input()))
left = 0
right = 0
mask = 10**9 + 7

for i in range(0, n + 1):
        x = a.index(a[i])
        if a[i] in a[x+1:]:
                left = i
                right = a[x+1:].index(a[i]) + x + 1
                break

for i in range(1, n + 2):
        ans = comb(n + 1, i)
        ans -= comb(left + n - right, i - 1)
        print ans % mask