Created
February 2, 2016 05:45
-
-
Save zsrinivas/6687e9341af3f0aaf216 to your computer and use it in GitHub Desktop.
HourRank5 - HR City
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
n = int(raw_input()) | |
d = map(int, raw_input().split()) | |
dist, coun, cdis, corn = [0]*(n + 1), [1]*(n + 1), [0]*(n + 1), [0]*(n + 1) | |
for x in xrange(1, n + 1): | |
dist[x] = (4 * dist[x - 1] + coun[x - 1] * (16 * coun[x - 1] * d[x - 1] + 12 * cdis[x - 1]) + 8 * cdis[x - 1] + 12 * coun[x - 1] * d[x - 1] + d[x - 1]) % 1000000007 | |
coun[x] = (4 * coun[x - 1] + 2) % 1000000007 | |
cdis[x] = (4 * cdis[x - 1] + coun[x - 1] * 8 * d[x - 1] + 3 * coun[x - 1] * corn[x - 1] + 3 * d[x - 1] + 2 * corn[x - 1]) % 1000000007 | |
corn[x] = (2 * corn[x - 1] + 3 * d[x - 1]) % 1000000007 | |
print dist[n] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment