Harryxun/stf_run huggingface dataset:
c=input().split
for i in range(2):
    c[i]=int(c[i])
n=c[0]
m=c[1]
a=input().split()

for i in range(len(a)):
    a[i]=int(a[i])

b=[0 for i in range(m+1)]

for i in range(n-1):
    if(a[i]<a[i+1]):
        for j in range(a[i+1]-a[i]):
            b[a[i]+1+j]+=1
    else:
        for j in range(a[i+1]):
            b[j+1]+=1
        for j in range(m-a[i]):
            b[a[i]+1+j]+=1

max_value=0
max_num=0
for i in range(m):
    if(max_value<=b[i]):
        max_value=b[i]
        max_num=i

def move(x,y):
    result=0
    if(x<y):
        result=y-x
    else:
        result=(m-x)+y

    return result

sum_value=0
for i in range(n-1):
    sum_value+=min(move(max_num,a[i+1]),move(a[i],a[i+1]))
print(sum_value)

### FIXED CODE ###

n=int(input())
a=input().split()

for i in range(len(a)):
    a[i]=int(a[i])

b=[0 for i in range(len(a))]

if(n%2==0):
    for i in range(int(n/2)):
        b[i]=a[n-2*i-1]
    
    for i in range(int(n/2)):
        b[i+int(n/2)]=a[1+2*i-1]
else:
    for i in range(int((n+1)/2)):
        b[i]=a[n-2*i-1]
    for i in range(int((n-1)/2)):
        b[i+int((n+1)/2)]=a[2+2*i-1]
        
for i in range(n):
    print(b[i],end=" ")
X = int(input())
     
    L = 0
    for t in range(1, X) :
        L += t
        if L >= X :
            print(t)
            break

### FIXED CODE ###

X = int(input())
     
L = 0
for i in range(1, X+1) :
  L += i
  if L >= X :
    print(i)
    break
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")

n,m = I()
s = v()
t = v()
l = lcm(n,m)
g = gcd(n,m)

for i in range(g):
    if s[n//g*i] != t[m//g*i]:
        print(-1)
        sys.exit()

print(l)


### FIXED CODE ###

import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")

n,m = I()
s = v()
t = v()
l = lcm(n,m)
g = math.gcd(n,m)

for i in range(g):
    if s[n//g*i] != t[m//g*i]:
        print(-1)
        sys.exit()

print(l)
a = int(input())
b = int(input())

if (a*b)%2 == 0:
    print("Even")
else:
    print("Odd")

### FIXED CODE ###

a,b = map(int,input().split())

if (a*b)%2 == 0:
    print("Even")
else:
    print("Odd")
n = int(input())
moji = str(input())
alphabet = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]
lst = list(moji)
for i in range(len(lst)):
  num = alphabet.index(lst[i])
  if i + n > 25:
    lst[i] = alphabet[i+n-26]
  else:
    lst[i] = alphabet[i+n]
ans = ""
for j in range(len(lst)):
  ans += lst[j]
print(ans)

### FIXED CODE ###

n = int(input())
moji = str(input())
alphabet = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"]
lst = list(moji)
for i in range(len(lst)):
  num = alphabet.index(lst[i])
  if num + n >= 26:
    lst[i] = alphabet[num+n-26]
  else:
    lst[i] = alphabet[num+n]
ans = ""
for j in range(len(lst)):
  ans += lst[j]
print(ans)
import fractions
def lcm(x, y):
    return x * y / fractions.gcd(x, y)

n = int(input())
i = 1
for _ in range(n):
    i = int(lcm(i, int(input())))
print(i)


### FIXED CODE ###

import fractions

def lcm(x, y):
    return x * y // fractions.gcd(x, y)

n = int(input())
i = 1
for _ in range(n):
    i = lcm(i, int(input()))
print(i)
import sys
input = lambda : sys.stdin.readline().rstrip()

def _input():
    lines = open("../tmp_in").readlines()
    for ss in lines:
        yield ss.rstrip()
input = _input().__next__


import heapq
h = []
heapq.heapify(h)

n, m, s = list(map(int, input().split()))
a, b = [[None] * m for _ in range(2)]
c, d = [[None] * n for _ in range(2)]

ns = {}
uv2e = {}
for i in range(m):
    u,v,a[i],b[i] = list(map(int, input().split()))
    ns.setdefault(u-1, set())
    ns.setdefault(v-1, set())
    ns[u-1].add(v-1)
    ns[v-1].add(u-1)
    uv2e[u-1,v-1] = i
    uv2e[v-1,u-1] = i
for i in range(n):
    c[i], d[i] = list(map(int, input().split()))

maxs = max(a)*(n-1)
s = min(s, maxs)
state = (0, 0, s) # (距離, ノード, 銀貨枚数)
ans = [[None] * (maxs+1) for _ in range(n)]
heapq.heappush(h, state)
count = 0
while h:
    count += 1
    dd, u, ss = heapq.heappop(h)
#     print(dd, u, ss)
    if ans[u][ss] is not None and ans[u][ss] <= dd:
        continue
    ans[u][ss] = dd
    
    # グラフの隣接点
    for v in ns[u]:
        e= uv2e[u,v]
        if ss<a[e] or ans[v][ss-a[e]] is not None:
            continue
        heapq.heappush(h, (dd + b[e], v, ss-a[e]))
    # 両替
    if ss+c[u] <= maxs:
        heapq.heappush(h, (dd + d[u], u, ss+c[u]))
    elif ss < maxs:
        heapq.heappush(h, (dd + d[u], u, maxs))

for item in ans[1:]:
    print(min(item))

### FIXED CODE ###



import heapq
from collections import defaultdict
h = []
heapq.heapify(h)

n, m, s = list(map(int, input().split()))
a, b = [[None] * m for _ in range(2)]
c, d = [[None] * n for _ in range(2)]

ns = defaultdict(list)
uv2e = {}
for i in range(m):
    u,v,a[i],b[i] = list(map(int, input().split()))
    ns[u-1].append(v-1)
    ns[v-1].append(u-1)
    uv2e[u-1,v-1] = i
    uv2e[v-1,u-1] = i
for i in range(n):
    c[i], d[i] = list(map(int, input().split()))

maxs = max(a)*(n-1)
s = min(s, maxs)
state = (0, 0, s) # (距離, ノード, 銀貨枚数)
ans = [[None] * (maxs+1) for _ in range(n)]
heapq.heappush(h, state)
count = 0
while h:
    count += 1
    dd, u, ss = heapq.heappop(h)
#     print(dd, u, ss)
    if ans[u][ss] is not None and ans[u][ss] <= dd:
        continue
    ans[u][ss] = dd
    
    # グラフの隣接点
    for v in ns[u]:
        e= uv2e[u,v]
        if ss<a[e] or ans[v][ss-a[e]] is not None:
            continue
        heapq.heappush(h, (dd + b[e], v, ss-a[e]))
    # 両替
    if ss+c[u] <= maxs:
        heapq.heappush(h, (dd + d[u], u, ss+c[u]))
    elif ss < maxs:
        heapq.heappush(h, (dd + d[u], u, maxs))

for item in ans[1:]:
    print(min(item))
N = int(input())
A = list(map(int,input().split()))
from collections import defaultdict
D = defaultdict(int)
for e in A:
    D[e] += 1
possible_length = []
for key,value in D.items():
    if value > 1:
        possible_length.append(key)
if len(possible_length) < 2:
    print(0)
possible_length.sort()
print(possible_length[-1]*possible_length[-2])

### FIXED CODE ###

N = int(input())
A = list(map(int,input().split()))
from collections import defaultdict
D = defaultdict(int)
for e in A:
    D[e] += 1
l1 = []
l2 = []
for key,value in D.items():
    if value > 1:
        l1.append(key)
    if value > 3:
        l2.append(key)
if len(l1) < 2:
    print(0)
    exit()
l1.sort()
l2.sort()
if len(l2) > 0:
    print(max(l1[-1]*l1[-2],l2[-1]*l2[-1]))
else:
    print(l1[-1]*l1[-2])
import heapq
def SME(Whole,start,end,L,ANS):
    A = []
    if end > N : end = N
    count = 0
    for i,x in enumerate(Whole[start:end]):
        heapq.heappush(A,[x,i])
    for j in range(start,end):
        a = heapq.heappop(A)
        for i in range(L):
            idx = a[1] + i
            try :
                if ANS[idx] == 0 and idx <= end:
                    ANS[idx] = a[0]
                    count += 1
            except IndexError : continue
        if count > N * 0.99 : break
    for i in range(L):
        if ANS[i] == 0 : ANS[i] = min(Whole[:i+1])
    for i in range(L,N):
        if ANS[i] == 0 : ANS[i] = min(Whole[i+1-L:i+1])
    return ANS

[N,L] = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
ANS = [0]*N
start = 0
K = L * 2
if K > N : K = N
end = K
while (end <= N):
    ANS = SME(A, i*M, i*M+K, L, ANS)
    start = end
    end += K 
for i in ANS[L-1:-1]:print(i, end=" ")
print(ANS[-1])

### FIXED CODE ###

def ascend(a,b):
    mini = min(A[a:a+L])
    ans[a] = mini
    for i in range(a+1,b):
        if A[i+L-1] <= mini : mini = A[i+L-1]
        elif A[i-1] == mini : mini = min(A[i:i+L])
        ans[i] = mini

def descend(a,b):
    mini = min(A[b-1:b+L-1])
    ans[b-1] = mini
    for i in range(b-2,a-1,-1):
        if A[i] <= mini : mini = A[i]
        elif A[i+L] == mini: mini = min(A[i:i+L])
        ans[i] = mini
    
[N,L] = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
ans = [None]*(N-L+1)
count = 0;
if N > 10 ** 4:
    for i in range(100):
        if A[i+1] > A[i] : count += 1
    if count > 80 : descend(0, N-L+1)
    else : ascend(0,N-L+1)
else :
    ascend(0, N-L+1)
for i in ans[:-1] : print(i, end=" ")
print(ans[-1])
n = int(input())
count = 0
for c in range(n):
    ab = n - c
    if ab % a == 0:
        count += 1
print(count)

### FIXED CODE ###

n = int(input())
count = 0
for a in range(1,n):
    count += (n-1)//a
print(count)
import numpy as np

N, K = map(int, input().split())
hs = np.array(list(map(int, input().split())))

a = np.zeros(N, int)
a[0] = 0
a[1] = abs(hs[1] - hs[0])

b = np.zeros(K, int)
for j in range(K):
    b[j] = a[max(2-(j+1),0)] + abs(hs[2] - hs[max(2-(j+1),0)])
    
for i in range(2, N):
    b = np.hstack((b[1:], np.array([a[max(i-1,0)] + abs(hs[i] - hs[max(i-1,0)])])))
    a[i] = np.min(b)
print(a[-1])
a

### FIXED CODE ###

import numpy as np

N, K = map(int, input().split())
hs = np.array(list(map(int, input().split())))

a = np.zeros(N, int)
a[0] = 0
a[1] = abs(hs[1] - hs[0])

if N == 2:
    print(a[-1])
else:
    for i in range(2, N):
        b = a[max(i-K,0):i] + np.abs(hs[i] - hs[max(i-K,0):i])
        a[i] = np.min(b)
    print(a[-1])
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

def lcm_base(x, y):
	return (x * y) // gcd(x, y)

def lcm_list(numbers):
    ans = lcm_base(numbers[0], numbers[1])
    for x in numbers:
        ans = lcm_base(ans, x)
    return ans

n = int(input())
t = [int(input()) for i in range(n)]

result = lcm_list(t)
print(result)


### FIXED CODE ###

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

def lcm_base(x, y):
	return (x * y) // gcd(x, y)

def lcm_list(numbers):
    ans = lcm_base(numbers[0], numbers[1])
    for x in numbers:
        ans = lcm_base(ans, x)
    return ans

n = int(input())
t = [int(input()) for i in range(n)]

result = lcm_list(t) if len(t) != 1 else t[0]
print(result)
x=int(input())
n = 1000
l = [x**5 for x in range(-n, n)]
for i,y in enumerate(l):
    if y+x in l:
        print(f'{int(l.index(y+x)-len(l)/2+1)} {int(i-len(l)/2+1)}')
        break
    elif y-x in l:
        print(f'{int(i-len(l)/2+1)} {int(l.index(y-x)-len(l)/2+1)}')
	break

### FIXED CODE ###

x = int(input())
for a in range(1000):
    for b in range(1000):
        if a**5 - b**5 == x:
            print(f"{a} {b}")
            break
        elif a**5 - (-b)**5 == x:
            print(f"{a} {-b}")
            break
    else:
        continue
    break
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 10**6
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

r1,c1,r2,c2 = map(int, input().split())
ans = cmb(r2+c2+2,c2+1,mod)-cmb(r2+c1+1,c1,mod)-cmb(r1+c2+1,c2+1,mod)+cmb(r1+c1,c1,mod)
print(ans)

### FIXED CODE ###

def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = 2*10**6+10
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

r1, c1, r2, c2 = map(int, input().split())

def g(r, c):
  return cmb(r+c+2,c+1,mod)-1

ans = g(r2,c2)-g(r2,c1-1)-g(r1-1,c2)+g(r1-1,c1-1)
print(ans%mod)
I=lambda:list(map(int,input().split()))
a=I()
if a[0]>=0:
    print("Positive")
else:
    d=list(range(a[0],a[1]+1))
    if 0 in d:
        print("Zero")
    elif len(d)%2==0:
        print("Positive")
    else:
        print("Negative")

### FIXED CODE ###

import sys
# import numpy as np 
 
def main():
    a, b = map(int, sys.stdin.read().split())
 
    if 0 < a:
        ans = 'Positive'
    elif 0 <= b:
        ans = 'Zero'
    else:
        if (b - a + 1) % 2 == 0:
            ans = 'Positive'
        else:
            ans = 'Negative'
    
    print(ans)
 
if __name__ == '__main__':
    main()
n, a, b = map(int, input().split())
x = map(int, input().split())

ans = 0
for i in range(1, len(x)):
  ans += min(b, (x[i]-x[i-1]+a-1)//a*a)

print(ans)

### FIXED CODE ###

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

ans = 0
for i in range(1, len(x)):
  ans += min(b, (x[i]-x[i-1])*a)

print(ans)
from collections import Counter

N = int(inputs[0])
a_list = list(map(int, inputs[1].split()))

def check(N, a_list):
    mc = Counter(a_list).most_common()
    n = len(mc)
    if n == 1:
        if mc[0][0] == 0:
            print('Yes')
            return
    elif n == 2:
        if mc[0][1] == 2*N // 3 and mc[1][0] == 0:
            print('Yes')
            return
    elif n == 3:
        if mc[0][1] == mc[1][1] == mc[2][1] and mc[0][0] ^ mc[1][0] ^ mc[2][0] == 0:
            print('Yes')
            return
    print('No')

check(N, a_list)

### FIXED CODE ###

import sys
inputs = sys.stdin.readlines()

N = int(inputs[0])
a_list = list(map(int, inputs[1].split()))

from collections import Counter

def all_zeros(a_list):
    return sum(a_list) == 0

def check(N, a_list):
    if all_zeros(a_list):
        print('Yes')
        return
    elif N % 3 == 0:
        x = N // 3
        if not all([v % x == 0 for v in Counter(a_list).values()]):
            print('No')
            return
        while not all_zeros(a_list):
            counter = Counter([a & 1 for a in a_list])
            if counter[0] == x or counter[0] == N:
                a_list = [a >> 1 for a in a_list]
            else:
                print('No')
                return
        print('Yes')
    else:
        print('No')

check(N, a_list)
#JMD
#Nagendra Jha-4096

 
import sys
import math

#import fractions
#import numpy
 
###File Operations###
fileoperation=1
if(fileoperation):
    orig_stdout = sys.stdout
    orig_stdin = sys.stdin
    inputfile = open('W:/Competitive Programming/input.txt', 'r')
    outputfile = open('W:/Competitive Programming/output.txt', 'w')
    sys.stdin = inputfile
    sys.stdout = outputfile

###Defines...###
mod=1000000007
 
###FUF's...###
def nospace(l):
    ans=''.join(str(i) for i in l)
    return ans
 
 
 
##### Main ####
t=1
for tt in range(t):
    n=str(input())
    if '7' in n:
        print("Yes")
    else:
        print("No")
    #n,k,s= map(int, sys.stdin.readline().split(' '))
    #a=list(map(int,sys.stdin.readline().split(' ')))
    
    
#####File Operations#####
if(fileoperation):
    sys.stdout = orig_stdout
    sys.stdin = orig_stdin
    inputfile.close()
    outputfile.close()

### FIXED CODE ###

#JMD
#Nagendra Jha-4096

 
import sys
import math

#import fractions
#import numpy
 
###File Operations###
fileoperation=0
if(fileoperation):
    orig_stdout = sys.stdout
    orig_stdin = sys.stdin
    inputfile = open('W:/Competitive Programming/input.txt', 'r')
    outputfile = open('W:/Competitive Programming/output.txt', 'w')
    sys.stdin = inputfile
    sys.stdout = outputfile

###Defines...###
mod=1000000007
 
###FUF's...###
def nospace(l):
    ans=''.join(str(i) for i in l)
    return ans
 
 
 
##### Main ####
t=1
for tt in range(t):
    n=str(input())
    if '7' in n:
        print("Yes")
    else:
        print("No")
    #n,k,s= map(int, sys.stdin.readline().split(' '))
    #a=list(map(int,sys.stdin.readline().split(' ')))
    
    
#####File Operations#####
if(fileoperation):
    sys.stdout = orig_stdout
    sys.stdin = orig_stdin
    inputfile.close()
    outputfile.close()
import math

n = int(input())
x_list = list(map(int, input().split()))

mi_stamina = math.inf
for i in range(-1000, 1000):
    print(x_list)
    double_list = list(map(lambda x: (x-i)**2, x_list))
    print(double_list)
    stamina = sum(double_list)
    if mi_stamina > stamina:
        mi_stamina = stamina

print(mi_stamina)

### FIXED CODE ###

import math


n = int(input())
x_list = list(map(int, input().split()))


mi_stamina = 1000000000
for i in range(-1000, 1000):
    def _distance(x):
        return (x-i)**2
    double_list = list(map(_distance, x_list))
    stamina = sum(double_list)
    if mi_stamina > stamina:
        mi_stamina = stamina

print(mi_stamina)
a, b = map(int,raw_input().split())

if a > b:
 print("a > b")
if a < b:
 print("a < b")
if a == b:
 print("a == b")
else:
 print("none")

### FIXED CODE ###

a, b = map(int, input().split())
if a < b:
    print('a < b')
elif a > b:
    print('a > b')
else:
    print('a == b')
a,b = map(int,input().split())
a_interval = list(map(int,[a/0.08,(a+1)/0.08]))
b_interval = list(map(int,[b/0.1,(b+1)/0.1]))
a_interval = [x for x in range(a_interval[0],a_interval[1]+1)]
b_interval = [x for x in range(b_inaterval[0],b_interval[1]+1)]
tmp = set(a_interval) & set(b_interval)
if tmp == set():
    print(-1)
else:
    print(min(tmp))

### FIXED CODE ###

A, B = map(int,input().split())

import math 
a = [x for x in range(math.ceil(A*12.5),math.ceil((A+1)*12.5))]
b = [x for x in range(math.ceil(B*10),math.ceil((B+1)*10))]

c = set(a) & set(b)

if c != set():
  print(min(c))
else:
  print(-1)
n=int(n)
m=int(m)
x=[false for i in range(n)]
count=[0 for i in range(n)]
for i in range(m):
  p,s=input().split()
  p=int(p)
  if(not x[p-1]):
    if(s=="AC"):
      x[p-1]=true
    else:
      count[p-1]=count[p-1]+1
ans=0
ans2=0
for i in range(ansn):
  if(x[i]):
    ans+=1
    ans2+=count[i]
print(ans,ans2)

### FIXED CODE ###

import math
import itertools
n=int(input())

a=list(map(str,input().split()))
b=list(map(str,input().split()))

p=str(math.factorial(n))

a_list = [''.join(v) for v in itertools.permutations(a)]
a_int = [int(i) for i in a_list]
a_int.sort()

a_=[int(i) for i in a]
b_=[int(j) for j in b]
x="".join(a)
y="".join(b)

p_=a_int.index(int(x))+1
q_=a_int.index(int(y))+1

sum=abs(p_-q_)
print(sum)
import numpy as np
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline

def resolve():

    from collections import deque

    H, W = map(int, input().split())
    maze = [input() for i in range(H)]
    visited = [[-1] * W for j in range(H)]
    start_list=[]
    for i in range(H):
        for j in range(W):
            if maze[i][j]=='#':
                start_list.append([i,j])



    def bfs(maze, visited, sy, sx):
        queue = deque([[sy, sx]])
        visited[sy][sx] = 0
        while queue:
            y, x = queue.popleft()
            for j, k in ([1, 0], [-1, 0], [0, 1], [0, -1]):
                ny, nx = y + j, x + k
                if 0 <= ny < H and 0 <= nx < W and \
                        maze[ny][nx] == "." and (visited[ny][nx]==-1 or (visited[ny][nx]!=-1 and visited[y][x] + 1<visited[ny][nx])):
                    visited[ny][nx] = visited[y][x] + 1
                    queue.append([ny, nx])
                if 0 <= ny < H and 0 <= nx < W and \
                        maze[ny][nx] == "#":
                    return visited

    for [i,j] in start_list:
        bfs(maze, visited, i, j)
    print(np.amax(visited)+1)


resolve()

### FIXED CODE ###

def resolve():

    from collections import deque

    H, W = map(int, input().split())
    maze = [input() for i in range(H)]
    start_list=[]
    for i in range(H):
        for j in range(W):
            if maze[i][j]=='#':
                start_list.append([i,j])
    INF = 10 ** 20

    visited = [[INF] * W for j in range(H)]


    def bfs(maze):
        queue = deque()
        for [i,j] in start_list:
            queue.append([i,j])
            visited[i][j]=0
        while queue:
            y, x = queue.popleft()
            cnt=0
            for j, k in ([1, 0], [-1, 0], [0, 1], [0, -1]):
                ny, nx = y + j, x + k
                if 0 <= ny < H and 0 <= nx < W and \
                        maze[ny][nx] == "." and visited[ny][nx]==INF:
                        visited[ny][nx] = visited[y][x] + 1
                        queue.append([ny, nx])
        return visited


    bfs(maze)
    ans=0
    for i in range(H):
        for j in range(W):
            ans=max(ans,visited[i][j])

    print(ans)


resolve()
n=int(input())
a=[int(i) for i in input().split()]


j_Aj=[0]
i_Ai=[0]*(10**9+2*10**5)

for j,aj in enumerate(a):
    j_Aj.append(j+1-aj)
ans=0
for j,j_aj in enumerate(j_Aj):
    if j==0:
        continue
    if j_aj>=2:
        ans+=i_Ai[j_aj]
    i_Ai[j+a[j-1]]+=1
print(ans)

### FIXED CODE ###

n = int(input())
a = [int(i) for i in input().split()]

j_Aj = [0]

for j, aj in enumerate(a):
    j_Aj.append(j + 1 - aj)
maxj=max(j_Aj)
i_Ai = [0] * (maxj+1)
ans = 0
for j, j_aj in enumerate(j_Aj):
    if j == 0:
        continue
    if j_aj >= 2:
        ans += i_Ai[j_aj]
    if j + a[j - 1]<=maxj:
        i_Ai[j + a[j - 1]] += 1
print(ans)
N,M = map(int,input().split())
H = [int(h) for h in input().split()]

d = {}

for i in range(N):
    d[i+1] = H[i]

for _ in range(M):
    A,B = map(int,input().split())

    if H[B-1] > H[A]:
        d[A] = 0

    elif H[B-1] < H[A]:
        d[B] = 0

    elif H[B-1] == H[A]:
        d[A] = 0
        d[B] = 0


print(N - list(d.values()).count(0))

### FIXED CODE ###

N,M = map(int,input().split())
H = [int(h) for h in input().split()]

d = {}

for i in range(N):
    d[i+1] = H[i]

for _ in range(M):
    A,B = map(int,input().split())

    if H[B-1] >= H[A-1]:
        d[A] = 0

    if H[B-1] <= H[A-1]:
        d[B] = 0

print(N - list(d.values()).count(0))
n, m = [int(i) for i in input().split()]

matrix = []
for ni in range(n):
    matrix.append([int(a) for a in input().split])

vector = []
for mi in range(m):
    vector.append(int(input()))


print(matrix)
print()
print(vector)

### FIXED CODE ###

(n, m) = [int(i) for i in input().split()]
A = []
b = []
for i in range(n):
    A.append([int(j) for j in input().split()])
 
for i in range(m):
    b.append(int(input()))
 
for i in range(n):
    s = 0
    for j in range(m):
        s += A[i][j] * b[j]
    print(s)
# encoding: utf-8


import sys


def solve(a, b, h):
    return (a + b) / h / 2.


def main():
    a = sys.stdin.readline().rstrip()
    int(a)
    b = sys.stdin.readline().rstrip()
    int(b)
    h = sys.stdin.readline().rstrip()
    int(h)
    print solve(a, b, h)


if __name__ == "__main__":
    main()


### FIXED CODE ###

def solve(a, b, h):
    return (a + b) * h / 2


a = raw_input()
a = int(a)
b = raw_input()
b = int(b)
h = raw_input()
h = int(h)
ans = solve(a, b, h)
print ans
# -*- coding: utf-8 -*-
S = []
for i in range(3):
    S.append(input())
for i in range(3):
    S[i] = S[i].replace('a', '0').replace('b', '1').replace('c', '2')
    
idx = int(S[0][0])
S[0] = S[0][1:]

while True:
    tmp = int(S[idx][0])
    S[idx] = S[idx][1:]
    idx = tmp
    if S[idx] == '':
        print(['A', 'B', 'C'][idx])
        break


### FIXED CODE ###

SA = input()
SB = input()
SC = input()

Aidx, Bidx, Cidx = 0, -1, -1
X = SA[0]
i = 0

while True:
    if X == 'a':
        Aidx += 1
        if Aidx == len(SA):
            ans = 'A'
            break
        X = SA[Aidx]
    elif X == 'b':
        Bidx += 1
        if Bidx == len(SB):
            ans = 'B'
            break
        X = SB[Bidx]
    elif X == 'c':
        Cidx += 1
        if Cidx == len(SC):
            ans = 'C'
            break
        X = SC[Cidx]


print(ans)