Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- import sys
- a = sys.stdin.readline().strip()
- leng, _ = map(int, a.split())
- a = sys.stdin.readline().strip()
- opors = map(int, a.split())
- if len(opors) < 4:
- print leng
- else:
- res = opors[1] + leng - opors[-2]
- for i in xrange(1, len(opors) - 2):
- right = hi = opors[i + 1]
- left = lo = opors[i]
- if left < (right - left):
- hi = left * 2
- if leng - right < (right - left):
- lo = 2*right - leng
- if hi < lo:
- res += right - left
- else:
- res += (right - hi)
- res += (lo - left)
- print res
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement