CodeEff/ECCO huggingface dataset:
# Original solution
def solve():
    from bisect import bisect_left
    N, W = list(map(int, input().split()))
    n1 = N//2
    n2 = N-n1
    a = [[tuple(map(int, input().split())) for _ in [0]*n1], [tuple(map(int, input().split())) for _ in [0]*n2]]
    dp = [[(0, 0) for _ in [0]*(2**n1)], [(0, 0) for _ in [0]*(2**n2)]]

    for i in range(2):
        n = len(a[i])
        cdp = dp[i]
        ca = a[i]
        append = cdp.append
        for bit in range(1, 2**n):
            v, w = 0, 0
            for j in range(n):
                if 2**j & bit:
                    v += ca[j][0]
                    w += ca[j][1]
            if w <= W:
                cdp[bit] = (w, v)
        cdp = sorted(cdp)
        dp[i] = [pair for w in [[-1]] for sa in [w.__setitem__] for pair in cdp if pair[1] > w[0] and not sa(0, pair[1])]

    result = 0
    inf = float("inf")
    l = len(dp[1])
    for w, v in dp[0]:
        i = bisect_left(dp[1], (W-w, inf))
        newv = v + dp[1][i-1][1] if i > 0 else 0
        #print(w, v, i, newv)

        if newv > result:
            result = newv

    print(result)

if __name__ == "__main__":
    solve()

# Optimized solution
def solve():
    from bisect import bisect_left
    N, W = list(map(int, input().split()))
    n1 = N//2
    n2 = N-n1
    a = [[tuple(map(int, input().split())) for _ in [0]*n1], [tuple(map(int, input().split())) for _ in [0]*n2]]
    dp = [[(0, 0) for _ in [0]*(2**n1)], [(0, 0) for _ in [0]*(2**n2)]]

    for i in range(2):
        n = len(a[i])
        cdp = dp[i]
        ca = a[i]
        for j in range(n):
            if ca[j][1] > W:
                continue
            for bitset in range(2**j, 2**(j+1)):
                #print(bin(bitset))
                v, w = ca[j]
                for k in range(j):
                    if 2**k & bitset:
                        v += ca[k][0]
                        w += ca[k][1]
                if w <= W:
                    cdp[bitset] = (w, v)
        cdp = sorted(cdp)
        dp[i] = [pair for w in [[-1]] for sa in [w.__setitem__] for pair in cdp if pair[1] > w[0] and not sa(0, pair[1])]

    #print(dp)
    result = 0
    inf = float("inf")
    l = len(dp[1])
    for w, v in dp[0]:
        i = bisect_left(dp[1], (W-w, inf))
        newv = v + dp[1][i-1][1] if i > 0 else 0
        #print(w, v, i, newv)

        if newv > result:
            result = newv

    print(result)

if __name__ == "__main__":
    solve()
# Original solution
def solve():
    from bisect import bisect_left
    N, W = list(map(int, input().split()))
    n1 = N//2
    n2 = N-n1
    a = [[tuple(map(int, input().split())) for _ in [0]*n1], [tuple(map(int, input().split())) for _ in [0]*n2]]
    dp = [[(0, 0) for _ in [0]*(2**n1)], [(0, 0) for _ in [0]*(2**n2)]]

    for i in range(2):
        n = len(a[i])
        cdp = dp[i]
        ca = a[i]
        for j in range(n):
            if ca[j][1] > W:
                continue
            for bitset in range(2**j, 2**(j+1)):
                #print(bin(bitset))
                v, w = ca[j]
                for k in range(j):
                    if 2**k & bitset:
                        v += ca[k][0]
                        w += ca[k][1]
                if w <= W:
                    cdp[bitset] = (w, v)
        cdp = sorted(cdp)
        dp[i] = [pair for w in [[-1]] for sa in [w.__setitem__] for pair in cdp if pair[1] > w[0] and not sa(0, pair[1])]

    #print(dp)
    result = 0
    inf = float("inf")
    l = len(dp[1])
    for w, v in dp[0]:
        i = bisect_left(dp[1], (W-w, inf))
        newv = v + dp[1][i-1][1] if i > 0 else 0
        #print(w, v, i, newv)

        if newv > result:
            result = newv

    print(result)

if __name__ == "__main__":
    solve()

# Optimized solution
def solve():
    from bisect import bisect_right
    N, W = list(map(int, input().split()))
    a = [tuple(map(int, input().split())) for _ in [0]*N]

    def bitdp(items):
        n = len(items)
        dp = [(0, 0) for _ in [0]*(2**n)]
        for bitset in range(1, 2**n):
            for item_num, (item_v, item_w) in enumerate(items):
                if bitset & 2**item_num:
                    w, v = dp[bitset-2**item_num]
                    if w+item_w <= W:
                        dp[bitset] = (w+item_w, v+item_v)
                    break

        dp.sort()
        l, maxv, inf = [(0, 0)], 0, float("inf")
        append = l.append
        for item, (w, v), (nextw, _) in zip(dp, dp, dp[1:]+[(inf, inf)]):
            if w < nextw and maxv < v:
                append(item)
                maxv = v
        return l

    dp1 = bitdp(a[:N//2])
    dp2 = bitdp(a[N//2:])

    inf = float("inf")
    result = 0
    for w, v in dp1:
        total = v + dp2[bisect_right(dp2, (W-w, inf))-1][1]
        if result < total:
            result = total

    print(result)


if __name__ == "__main__":
    solve()
# Original solution
def solve():
    from bisect import bisect_right
    N, W = list(map(int, input().split()))
    a = [tuple(map(int, input().split())) for _ in [0]*N]

    def bitdp(items):
        n = len(items)
        dp = [(0, 0) for _ in [0]*(2**n)]
        for bitset in range(1, 2**n):
            for item_num, (item_v, item_w) in enumerate(items):
                if bitset & 2**item_num:
                    w, v = dp[bitset-2**item_num]
                    if w+item_w <= W:
                        dp[bitset] = (w+item_w, v+item_v)
                    break

        dp.sort()
        l, maxv, inf = [(0, 0)], 0, float("inf")
        append = l.append
        for item, (w, v), (nextw, _) in zip(dp, dp, dp[1:]+[(inf, inf)]):
            if w < nextw and maxv < v:
                append(item)
                maxv = v
        return l

    dp1 = bitdp(a[:N//2])
    dp2 = bitdp(a[N//2:])

    inf = float("inf")
    result = 0
    for w, v in dp1:
        total = v + dp2[bisect_right(dp2, (W-w, inf))-1][1]
        if result < total:
            result = total

    print(result)


if __name__ == "__main__":
    solve()

# Optimized solution
import sys
from bisect import bisect_right


def meet_in_the_middle(a: list, limit: int) -> tuple:
    first_v, first_w, second_v, second_w = [], [], [], []
    for items, v_append, w_append in (
            (a[:len(a)//2], first_v.append, first_w.append),
            (a[len(a)//2:], second_v.append, second_w.append)
    ):
        enumerated = [(0, 0)]
        for v, w in items:
            enumerated += [(w+_w, v+_v) for _w, _v in enumerated]

        enumerated.sort()
        enumerated = enumerated[:bisect_right(enumerated, (limit, float("inf")))] + [(limit+1, 0)]
        max_v = -1
        for (cw, cv), (nw, nv) in zip(enumerated, enumerated[1:]):
            if cw < nw and max_v < cv:
                v_append(cv)
                w_append(cw)
                max_v = cv

    return (first_v, first_w), (second_v, second_w)


N, W = list(map(int, input().split()))
a = [list(map(int, l.split())) for l in sys.stdin]

(first_v, first_w), (second_v, second_w) = meet_in_the_middle(a, W)
ans = 0
for v, w in zip(first_v, first_w):
    i = bisect_right(second_w, W-w)-1
    new_v = v + second_v[i]
    if ans < new_v:
        ans = new_v
print(ans)
# Original solution
a=int(eval(input()))
b=int(eval(input()))
h=int(eval(input()))
print((int((a+b)*h/2)))

# Optimized solution
a = int(eval(input()))
b = int(eval(input()))
h = int(eval(input()))
print(((a + b) * h // 2))
# Original solution
a = int(eval(input()))
b = int(eval(input()))
h = int(eval(input()))
print((int((a + b) * h / 2)))

# Optimized solution
a = int(eval(input()))
b = int(eval(input()))
h = int(eval(input()))
print(((a + b) * h // 2))
# Original solution
# coding: utf-8
a = int(eval(input()))
b = int(eval(input()))
h = int(eval(input()))
print(((a + b) * h // 2))


# Optimized solution
print(((int(eval(input())) + int(eval(input()))) * int(eval(input())) // 2))
# Original solution
a = int(eval(input()))
b = int(eval(input()))
h = int(eval(input()))
print(((a+b)*h//2))

# Optimized solution
a = int(eval(input()))
b = int(eval(input()))
h = int(eval(input()))

print((int((a+b)*h/2)))
# Original solution
a = int(eval(input()))
b = int(eval(input()))
h = int(eval(input()))
print(((a+b)*h//2))


# Optimized solution
a = int(eval(input()))
b = int(eval(input()))
h = int(eval(input()))

print((int((a+b)*h/2)))
# Original solution
a,b,h=list(map(int,[eval(input()) for i in range(3)]))
print((h*(a+b)//2))

# Optimized solution
a,b,h=list(map(int,[eval(input())for i in[0]*3]));print((h*(a+b)//2))
# Original solution
a = int(eval(input()))
b = int(eval(input()))
h = int(eval(input()))

answer = (a + b) * h // 2

print(answer)

# Optimized solution
a = int(eval(input()))
b = int(eval(input()))
h = int(eval(input()))

print(((a + b) * h // 2))
# Original solution
a = int(eval(input()))
b = int(eval(input()))
c = int(eval(input()))

print(((a+b)*c//2))

# Optimized solution
a = int(eval(input()))
b = int(eval(input()))
h = int(eval(input()))

print(((a+b)*h//2))
# Original solution
a, b, h = (int(eval(input())) for i in range(3))
print((int((a + b) / 2 * h)))

# Optimized solution
a = int(eval(input()))
b = int(eval(input()))
h = int(eval(input()))
print((int((a + b) / 2 * h)))
# Original solution
print(((int(eval(input()))+int(eval(input())))*int(eval(input()))//2))

# Optimized solution
x=lambda:int(eval(input()))
print(((x()+x())*x()//2))
# Original solution
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    a = ii()
    b = ii()
    h = ii()
    print((((a+b)*h)//2))


if __name__ == '__main__':
    main()


# Optimized solution
import sys, os, math, bisect, itertools, collections, heapq, queue
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict, deque

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    a, b, h = ii(), ii(), ii()
    print((((a + b) * h) // 2))


if __name__ == '__main__':
    main()
# Original solution
a, b, h = (int(eval(input())) for u in range(3))
print(((a + b) * h // 2))

# Optimized solution
a, b, h = (int(eval(input())) for u in range(3))
print((int((a + b) * h / 2)))
# Original solution
import sys
input = sys.stdin.readline

a = int(eval(input()))
b = int(eval(input()))
h = int(eval(input()))
ans = (a+b) * h * 0.5
print((int(ans)))

# Optimized solution
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

print(((int(readline()) + int(readline())) * int(readline()) // 2))
# Original solution
#!/usr/bin/env python3
import sys, math, itertools, heapq, collections, bisect, fractions
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
ans = count = 0

a,b,h=[int(eval(input())) for i in range(3)]
print(((a+b)*h//2))

# Optimized solution
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

a=int(eval(input()))
b=int(eval(input()))
h=int(eval(input()))
print(((a+b)*h//2))
# Original solution
a, b, h = [int(eval(input())) for _ in range(3)]
print((int((a+b)*h/2)))

# Optimized solution
a, b, h = [int(eval(input())) for i in range(3)]
print((int((a+b)*h/2)))
# Original solution
a=int(eval(input()))
b=int(eval(input()))
h=int(eval(input()))

S=(a+b)*h//2

print(S)

# Optimized solution
a = int(eval(input()))
b = int(eval(input()))
h = int(eval(input()))
print(((a+b)*h//2))
# Original solution
a,b,c,d=eval('['+'int(input()),'*3+'0]');print(((a+b)*c//2))

# Optimized solution
f=lambda:int(eval(input()));print(((f()+f())*f()//2))
# Original solution
for i in range(1,10):
  s = input().split()
  a = list(map(int, s[1:]))
  print(s[0], sum(a), a[0]*200+a[1]*300)

# Optimized solution
for _ in range(1,10):
  a,b,c = input().split()
  b,c = list(map(int, [b,c]))
  print(a, b+c, b*200+c*300)
# Original solution
N = int(eval(input()))
A = list(map(int, input().split()))

K = sum(A) / sum(range(1, N+1))
D = [A[i+1] - A[i] - K for i in range(-1, N-1)]
for d in D:
    if not (d <= 0 and d % N == 0):
        print("NO")
        break
else:
    print("YES")

# Optimized solution
N = int(eval(input()))
A = list(map(int, input().split()))


# 毎回1+2+...+N個の石が取り除かれる
Sum = sum(A)
if Sum % (N * (N + 1) // 2) != 0:
    print('NO')
    exit()


# 操作回数
K = Sum // (N * (N + 1) // 2)

Diff = [A[i] - A[(i - 1)] for i in range(N)]
# 変化量-1が(N-1)箇所、+(N-1)が一か所を、すべて-1した後に、一か所+1と置き換える
Diff = [d - K for d in Diff]

for d in Diff:
    if d < 0:
        if d % N != 0:
            print('NO')
            exit()
        else:
            K -= abs(d // N)

if K == 0:
    print('YES')
else:
    print('NO')
# Original solution
import heapq

n = int(eval(input()))
a = list(map(int, input().split()))

b = []
for i in range(n):
    a[i] *= -1
    b.append(a[i])

heapq.heapify(b)

while True:
    p = heapq.heappop(b)
    q = a.index(p)
    for i in range(n):
        a[q-i] += n-i
        if a[q-i]>0:
            print('NO')
            exit()
    if set(a) == {0}:
        print('YES')
        exit()
    b = [a[i] for i in range(n)]
    heapq.heapify(b)




# Optimized solution
n = int(eval(input()))
a = list(map(int, input().split()))

s = sum(a)

if s%(n*(n+1)//2)!=0:
    print('NO')
    exit()

ss = s//(n*(n+1)//2)

b = [0 for i in range(n)]

# a[i]-a[i-1] = ss-b[i-1]*n
for i in range(n):
    b[i-1] = (ss-a[i]+a[i-1])//n
    if b[i-1]<0:
        print('NO')
        exit()

c = [0 for i in range(n)]
for i in range(n):
    c[0]+=b[i]*(n-i)

for i in range(1,n):
    c[i] = c[i-1] + ss - b[i-1]*n

if a==c:
    print('YES')
else:
    print('NO')
# Original solution
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res

def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    n = I()
    a = LI()
    s = 0
    for i in a:
        s ^= (i%2)
    if s:
        print("NO")
    else:
        print("YES")
    return

#B
def B():
    n = I()
    a = LI()
    while sum(a) != 0:
        b = [0]*2*n
        f = [0]*2*n
        for i in range(n):
            if a[i-1] >= a[i]:
                b[i] += 1
                b[i+n] -= 1
                f[i] += 1
                f[i+n] -= 1+n
        for i in range(2*n-1):
            b[i+1] += b[i]
            f[i+1] += f[i]+b[i]
        for i in range(n):
            f[i] += f[i+n]
            a[i] -= f[i]
            if a[i] < 0:
                print("NO")
                return
    print("YES")
    return

#C
def C():
    n = I()

    return

#D
def D():
    n = I()

    return

#E
def E():
    n = I()

    return

#F
def F():
    n = I()

    return

#Solve
if __name__ == "__main__":
    B()


# Optimized solution
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res

def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    n = I()
    a = LI()
    s = 0
    for i in a:
        s ^= (i%2)
    if s:
        print("NO")
    else:
        print("YES")
    return

#B
def B():
    n = I()
    a = LI()
    m = n*(n+1)>>1
    s = sum(a)
    if s%m:
        print("NO")
        return
    k = s//m
    b = [k+a[i-1]-a[i] for i in range(n)]
    s = 0
    for i in b:
        if i%n or i < 0:
            print("NO")
            return
        s += i//n
    if s == k:
        print("YES")
    else:
        print("NO")
    return

#C
def C():
    n = I()

    return

#D
def D():
    n = I()

    return

#E
def E():
    n = I()

    return

#F
def F():
    n = I()

    return

#Solve
if __name__ == "__main__":
    B()
# Original solution
N = int(eval(input()))
A = [int(a) for a in input().split()]

RejectStones = N * (N+1) // 2
if sum(A) % RejectStones != 0: print("NO")
else:
    TotalOperation = sum(A) // RejectStones
    sumcheck = 0
    for i in range(N-1):
        if (TotalOperation - A[i+1] + A[i]) % N != 0 or TotalOperation < A[i+1] - A[i]:
            print("NO")
            break
        else:
            sumcheck += (TotalOperation - A[i+1] + A[i]) // N
    else:
        if (TotalOperation - A[0] + A[-1]) % N != 0 or TotalOperation < A[0] - A[-1]: print("NO")
        else: 
            sumcheck += (TotalOperation - A[0] + A[-1]) // N
            if sumcheck == TotalOperation: print("YES")
            else: print("NO")

# Optimized solution
import sys

def solve():
    input = sys.stdin.readline
    N = int(eval(input()))
    A = [int(a) for a in input().split()]
    totalA = sum(A)
    if totalA % (N * (N + 1) // 2) != 0: print("NO")
    else:
        Op = totalA // (N * (N + 1) // 2)
        subA = [A[(i + 1) % N] - A[i] for i in range(N)]
        count = 0
        for i, a in enumerate(subA):
            if (Op - a) % N != 0 or a > Op:
                print("NO")
                break
            else: count += (Op - a) // N
        else: 
            if count == Op: print("YES")
            else: print("NO")
    
    return 0

if __name__ == "__main__":
    solve()
# Original solution
import sys

n = eval(input())
v = list(map(int, input().split(' ')))
startHere = [0 for i in range(n)]

if sum(v) % ((n * (n + 1)) / 2) != 0:
	print("NO")
	sys.exit()

operations = sum(v) / ((n * (n + 1)) / 2)

for i in range(n):
	diff = v[(i + 1) % n] - v[i]

	startHere[i] = (operations - diff) / n

contribution = 0
gathered = 0

for i in range(n):
	v[i] -= contribution
	gathered += startHere[i % n]
	contribution += gathered

for i in range(n):
	v[i] -= contribution
	gathered -= startHere[i % n]
	contribution -= startHere[i % n] * n
	contribution += gathered

if min(startHere) >= 0 and sum(startHere) == operations and min(v) == 0 and max(v) == 0:
	print("YES")
else:
	print("NO")


# Optimized solution
import sys

n = eval(input())
v = list(map(int, input().split(' ')))
startHere = [0 for i in range(n)]

if sum(v) % ((n * (n + 1)) / 2) != 0:
	print("NO")
	sys.exit()

operations = sum(v) / ((n * (n + 1)) / 2)
operationsFound = 0

for i in range(n):
	diff = v[(i + 1) % n] - v[i]

	if (operations - diff) % n != 0 or operations - diff < 0:
		print("NO")
		sys.exit()
	else:
		operationsFound += (operations - diff) / n

if operationsFound == operations:
	print("YES")
else:
	print("NO")
# Original solution
n=int(eval(input()))
lis=list(map(int,input().split()))
num=(n*(n+1))//2
if sum(lis)%num!=0:
  print("NO")
  exit()
ans=0
for i in range(n):
  if abs(lis[i]-lis[i-1]-sum(lis)//num)%n!=0:
    print("NO")
    exit()
  ans+=abs(lis[i]-lis[i-1]-sum(lis)//num)//n
if ans == sum(lis)//num:print("YES")
else:print("NO")


# Optimized solution
n=int(eval(input()))
lis=list(map(int,input().split()))
num=(n*(n+1))//2
ll=sum(lis)
if ll%num!=0:
  print("NO")
  exit()
ans=0
for i in range(n):
  if abs(lis[i]-lis[i-1]-ll//num)%n!=0:
    print("NO")
    exit()
  ans+=abs(lis[i]-lis[i-1]-ll//num)//n
if ans == ll//num:print("YES")
else:print("NO")
# Original solution
n,*a=list(map(int,open(0).read().split()))
b,m=sum(a),n*-~n//2
n-=1
c=b//m
f=b%m>0
for i,j in zip(*[iter([a[-1]]+a*2)]*2):
  j-=i
  if n:
    t=min(0,j//n)
    f|=c!=j+n*-t-t
print(('YNEOS'[f::2]))

# Optimized solution
n,*a=list(map(int,open(0).read().split()))
q,m=divmod(sum(a),n*-~n//2)
print(('YNEOS'[any((y-x-q)%n+m or y-x>q for x,y in zip(a,a[1:]))::2]))
# Original solution
from operator import sub
 
N = int(eval(input()))
data = list(map(int, input().split()))
step = N * (N+1) // 2
total = sum(data)
#print("-->", total, step)
if total % step:
  print("NO")
else:
  K = total // step
  #print("-->", total, step, K)
  datar = [data[i % N] for i in range(-1, N)] 
  delta = list(map(sub, datar[1:], datar))
  #print(*delta)
  #print("-->", *list(map(lambda x:(K-x) % N, delta)))
  #print("-->", *list(map(lambda x:(K-x) // N, delta)))
  if any([(K-x) % N for x in delta]):
    print("NO")
  else:    
    ops = list([(K-x) // N for x in delta])
    if sum(ops) == K:
      for i, v in enumerate(data):
        if (i & 1):
          vv = sum([ops[(i-k) % N] * (k+1) for k in range(N)])
          if v != vv:        
            print("NO")
            break
      else:    
        print("YES")
    else:
      print("NO")

# Optimized solution
from operator import sub

N = int(eval(input()))
data = list(map(int, input().split()))
step = N * (N+1) // 2
total = sum(data)
#print("-->", total, step)
if total % step:
  print("NO")
else:
  K = total // step
  #print("-->", total, step, K)
  datar = [data[i % N] for i in range(-1, N)] 
  delta = list(map(sub, datar[1:], datar))
  #print(*delta)
  #print("-->", *list(map(lambda x:(K-x) % N, delta)))
  #print("-->", *list(map(lambda x:(K-x) // N, delta)))
  if any([(K-x) % N for x in delta]):
    print("NO")
  elif any([K-x < 0 for x in delta]): 
    print("NO")
  else:    
    ops = list([(K-x) // N for x in delta])
    if sum(ops) == K:
      for i, v in enumerate(data[0:1]):
        vv = sum([ops[(i-k) % N] * (k+1) for k in range(N)])
        if v != vv:        
          print("NO")
          break
      else:    
        print("YES")
    else:
      print("NO")
# Original solution
n = int(eval(input()))
a = list(map(int,input().split()))

s = sum(a)
one = n * (n+1) // 2
if s % one:
    print('NO')
    exit()
times = s // one

cnt = 0
b = a[1:]+[a[0]]
for i,j in zip(a,b):
    dif = j - i
    if (times - dif) % n:
        print('NO')
        exit()
    if (times-dif) // n < 0:
        print('NO')
        exit()
    cnt += (times-dif) // n
if times != cnt:
    print('NO')
else:
    print('YES')


# Optimized solution
N = int(eval(input()))
A = list(map(int,input().split()))

def solve():
    q = N * (N + 1) // 2
    if sum(A) % q:
        return False
    times = sum(A) // q
    cnt = 0
    for i, j in zip(A, A[1:] + [A[0]]):
        dif = times + i - j
        if dif % N or dif < 0:
            return False
        cnt += dif // N
    return times == cnt

print(('YES' if solve() else 'NO'))