Skip to content

Instantly share code, notes, and snippets.

@markroxor
Created October 19, 2015 12:33
Show Gist options
  • Save markroxor/73103a0f22a5353296bd to your computer and use it in GitHub Desktop.
Save markroxor/73103a0f22a5353296bd to your computer and use it in GitHub Desktop.
Codechef Long OCT
import sys
def main():
u,l,c = raw_input().split()
U = list(map(int,raw_input().split()))
L = list(map(int,raw_input().split()))
temp1 = [0]*1005
temp2 = [0]*1005
for i in xrange(max(len(U),len(L))):
if i<len(U):
temp1[U[i]]+=1
if i<len(L):
temp2[L[i]]+=1
mod = 1000000007
combo=[]
for i in xrange(1005):
combo.append((temp1[i]%mod)*(temp2[i]%mod)%mod)
c = int(c)
n = len(combo)
b = [0]*n
ans = []
combs=[]
combi2 = []
combs.append(combo[0])
b[0]=combo[0]
for i in xrange(1,n):
combs.append(combs[i-1]+combo[i])
b[i]=combs[i]
combi2.append(combs[i])
ans = []
for j in range(c):
sumi=0
for i in xrange(j,n-1):
sumi=((sumi%mod)+((combo[i+1]%mod)*(b[i]%mod))%mod)%mod
combi2[i]=sumi
for i in xrange(len(b)-1):
b[i+1]=combi2[i]
ans.append(sumi)
sys.stdout.write(" ".join(str(x) for x in ans))
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment