# -*- coding:utf-8 -*-
class Solution:
# array 二维列表
def Find(self, N, array):
# write code here
num = 0
for i in range(N-1):
for j in range(i+1,N):
num += (max(array[i:j+1]) - min(array[i:j+1]))
return num
while (True):
try:
n = input()
array = input()
N = int(n)
arr = array.split(' ')
for i in range(N):
arr[i] = eval(arr[i])
s = Solution()
num = s.Find(N,arr)
print(num)
except:
break
# -*- coding:utf-8 -*-
class Solution:
# array 二维列表
def Find(self, arr, ran):
# write code here
n, p1, p2, p3, t1, t2 = arr[0],arr[1],arr[2],arr[3],arr[4],arr[5]
num1 = s.ran_nei(ran,p1)
num2 = s.ran_wai(ran, t1, t2, p1, p2, p3)
return (num1+num2)
def ran_nei(self,ran,p):
score = 0
for i in range(len(ran)):
score += (ran[i][1] - ran[i][0])*p
return score
def ran_wai(self,ran,t1,t2,p1,p2,p3):
score = 0
for i in range(len(ran)-1):
sub_ran = ran[i+1][0] - ran[i][1]
if sub_ran <= t1:
score += sub_ran*p1
elif t1 < sub_ran <= (t2+t1):
score += (t1*p1 + (sub_ran-t1)*p2)
elif sub_ran > (t2+t1):
score += (t1*p1 +t2*p2 + (sub_ran-t2-t1)*p3)
return score
while (True):
try:
ran = []
array = input()
arr = array.split(' ')
for i in range(len(arr)):
arr[i] = eval(arr[i])
for i in range(arr[0]):
a = input()
b = a.split(' ')
c,d = eval(b[0]),eval(b[1])
ran.append([c,d])
s = Solution()
num = s.Find(arr,ran)
print(num)
except:
break
# -*- coding:utf-8 -*-
class Solution:
# array 二维列表
def Find(self, array):
# write code here
return 4
while (True):
try:
dic = {}
arr = input()
print(arr)
a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13 = [],[],[],[],[],[],[],[],[],[],[],[],[]
for i in range(len(arr)):
if arr[i] == 'A':
a1.append(arr[i])
elif arr[i] == '2':
a2.append(arr[i])
elif arr[i] == '3':
a3.append(arr[i])
elif arr[i] == '4':
a4.append(arr[i])
elif arr[i] == '5':
a5.append(arr[i])
elif arr[i] == '6':
a6.append(arr[i])
elif arr[i] == '7':
a7.append(arr[i])
elif arr[i] == '8':
a8.append(arr[i])
elif arr[i] == '9':
a9.append(arr[i])
elif arr[i] == 'T':
a10.append(arr[i])
elif arr[i] == 'J':
a11.append(arr[i])
elif arr[i] == 'Q':
a12.append(arr[i])
elif arr[i] == 'K':
a13.append(arr[i])
dic[1], dic[2], dic[3], dic[4], dic[5], dic[6], dic[7], dic[8], dic[9], dic[10], dic[11], dic[12], dic[13] = a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13
s = Solution()
num = s.Find(dic)
print(num)
except:
break