'''
第一题:
'''
num=int(input())
#设tmp是要处理的字符串
#如何按方向键最少,感觉就只有一种方案啊.
#先改编码
dict={'ABC':(1,2),'DEF':(1,3),'GHI':(2,1),'JKL':(2,2),'MNO':(2,3),
'PQRS':(3,1),'TUV':(3,2),'WXYZ':(3,3)}
last=(1,1)
sum=0
for i in range(num):
tmp=input()
last=(1,1)
sum=0
for jj in tmp:
for j in dict:
if jj in j:
now=dict[j]
break
#now是jj的编码
sum+=abs(now[0]-last[0])+abs(now[1]-last[1])
last=now
'''
第二题:棋盘
'''
#数组b的最右面少的需要数组a最左边的搬过来
num=int(input())
list1=input().split(' ')
list2=input().split(' ')
for i in range(len(list1)):
list1[i]=int(list1[i])
for i in range(len(list2)):
list2[i]=int(list2[i])
sum=0
tmp=0
i=len(list1)-1
while i in range(len(list1)-1,-1,-1):
if list1[i]<list2[i]:
que=list2[i]-list1[i]
#找到最前面是1的那个位
while 1:
if list1[tmp]==0:
tmp+=1
continue
else:
if list1[tmp]>=que:
list1[tmp]-=que
list1[i]+=que
sum+=que*(tmp+i)
break
else:
list1[i]+=list1[tmp]
sum+=list1[tmp]*(tmp+i)
list1[tmp]=0
break
if list1[i]==list2[i]:
i-=1
continue
if list1[i]>list2[i]:
sum+=list1[i]-list2[i]
list1[i-1]+=-(list2[i]-list1[i])
list1[i]-=-(list2[i]-list1[i])
i-=1
print(sum)
View Code
print(sum)