Harryxun/stf_run huggingface dataset:
import sys,time
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    start = time.time()
    n,m = LI()
    e = [[] for _ in range(n)]
    for _ in range(m):
        l,r,d = LI()
        e[l-1].append((r-1,d))
        e[r-1].append((l-1,-d))

    b = [False] * n
    def g(i,c):
        if c == False:
            c = 0
        b[i] = c
        for r,d in e[i]:
            if b[r] != False:
                if b[r] != c+d:
                    return False
            else:
                if not g(r,c+d):
                    return False
        return True

    for i in range(n):
        if b[i] != False:
            continue
        gt = time.time() - start
        if gt > 0.9:
            return True
        if not g(i,False):
            return 'No'
    return 'Yes'


print(main())





### FIXED CODE ###

import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n,m = LI()
    e = [[] for _ in range(n)]
    if m > 0:
        for _ in range(m):
            l,r,d = LI()
            e[l-1].append((r-1,d))
            e[r-1].append((l-1,-d))

    b = [None] * n

    for i in range(n):
        if not b[i] is None:
            continue
        b[i] = 0
        q = [i]
        qi = 0
        nq = []
        while True:
            if len(q) == qi:
                if not nq:
                    break
                q = nq
                qi = 0
                nq = []
            j = q[qi]
            qi += 1
            c = b[j]
            for r,d in e[j]:
                if b[r] is None:
                    b[r] = c+d
                    nq.append(r)
                else:
                    if b[r] != c+d:
                        return 'No'

    return 'Yes'


print(main())
#my answer
n = int(input())
k = int(input())

L = []
R = []

for i in range(n):
    x = int(input())
    if(x < 0):
        L.append(abs(x))
    elif(x >= 0):
        R.append(abs(x))

x = L + R

l = len(L) - k
if(l < 0):
    l = 0
r = l + k - 1

ans = 99999999;
for i in range(n - k):
    ans = min(ans, x[r]*2 + x[l])
    ans = min(ans, x[l]*2 + x[r])
    r += 1
    l += 1
    
if(k == 1):
    ans = min(x[r], x[r-1])
    
print(ans)

### FIXED CODE ###

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

ans = 999999999

for i in range(n - k + 1):
    a = abs(x[i]) + (x[i + k - 1] - x[i])
    b = abs(x[i + k - 1]) + (x[i + k - 1] - x[i])
    ans = min(ans, a, b)
    
print(ans)
N,M=map(int,input().split(" "))

s=[]
for i in range(M):
    s.append(list(map(int,input().split(" "))))

s.sort()

if(N==1 and s[0][0]==1):
    print(s[0][1])
    exit()
elif(N==1 and s[0][0]!=1):
    print(-1)
    exit()
numlist=[0,0,0]

for i in s:

    if(numlist[i[0]-1]!=0 and numlist[i[0]-1]!=i[1]):
        print(-1)
        exit()
    else:
        numlist[i[0]-1]=i[1]

if(numlist[0]==0):
    print(-1)
    exit()

num=""
for i in range(N):
    num+=str(numlist[i])
    
print(num)

### FIXED CODE ###

N,M=map(int,input().split(" "))

if(M==0):
    if(N==1):
        print(0)
    elif(N==2):
        print(10)
    elif(N==3):
        print(100)
    exit()



listing=[]

for i in range(M):
    a=list(map(int,input().split(" ")))
    listing.append(a)


aa=list(map(list, set(map(tuple, listing))))




a1=[]
a2=[]
for i in aa:
    a1.append(i[0])
    a2.append(i[0])
if(len(a1)!=len(set(a2))):
    print(-1)
    exit()

if(N==1 and aa[0][0]==1):
    print(aa[0][1])
    exit()
num=""
#print(aa)
digit=1
digit1=1
for i in range(N):
    digit1=digit
    for j in aa:
        if(j[0]==1 and j[1]==0):
            print(-1)
            exit()
        if(j[0]==digit):
            num+=str(j[1])
            digit1=digit+1
            break
    if(digit1==digit):
        if(digit==1):
            num+="1"
        else:
            num+="0"
    digit+=1
print(num)
N=str(input())
A=sum(list(map(int, list(N))))
if N % A ==0:
  print("Yes")
else:
  print("No")

### FIXED CODE ###

N=int(input())
X=sum(list(map(int,str(N))))
if N % X ==0:
  print("Yes")
else:
  print("No")
n = int(input())
bs = list(map(int, input().split()))
arr = []
for i in range(n):
    if i == 0 or i == 1:
        arr.append(bs[0])
    else:
        arr.append(bs[i-1])
        if bs[i-1] < arr[i-1]:
            arr[i-1] = bs[i]
print(sum(arr))


### FIXED CODE ###

n = int(input())
bs = list(map(int, input().split()))
arr = []
for i in range(n):
    if i == 0 or i == 1:
        arr.append(bs[0])
    else:
        arr.append(bs[i-1])
        if bs[i-1] < arr[i-1]:
            arr[i-1] = bs[i-1]
print(sum(arr))
def Base_10_to_n(x,n):
  tmp=x
  out=''
  while tmp>0:
    out=str(tmp%n)+out
    tmp=int(tmp/n)
  return out
n,a,b,c=map(int,input().split())
l=[int(input()) for i in range(n)]
ans=10**18
for i in range(4**n):
  cost=0
  d=[[] for i in range(4)]
  s=Base_10_to_n(i,4).zfill(n)
  for j in range(n):
    k=int(s[j])
    d[k].append(l[j])
  if len(d[1])*len(d[2])*len(d[3])==0:
    continue
  for i in range(1,4):
    cost+=(len(d[k])-1)*10
  d1=sum(d[1])
  d2=sum(d[2])
  d3=sum(d[3])
  l=[abs(d1-a)+abs(d2-b)+abs(d3-c),abs(d1-a)+abs(d2-c)+abs(d3-b),abs(d1-b)+abs(d2-a)+abs(d3-c),abs(d1-b)+abs(d2-c)+abs(d3-a),abs(d1-c)+abs(d2-a)+abs(d3-b),abs(d1-c)+abs(d2-b)+abs(d3-a)]
  cost=min(l)
  ans=min(ans,cost)
print(ans)

### FIXED CODE ###

def Base_10_to_n(x,n):
  tmp=x
  out=''
  while tmp>0:
    out=str(tmp%n)+out
    tmp=int(tmp/n)
  return out
n,a,b,c=map(int,input().split())
l=[int(input()) for i in range(n)]
ans=10**18
for i in range(4**n):
  cost=0
  d=[[] for j in range(4)]
  s=Base_10_to_n(i,4).zfill(n)
  for j in range(n):
    k=int(s[j])
    d[k].append(l[j])
  if len(d[1])*len(d[2])*len(d[3])==0:
    continue
  for j in range(1,4):
    cost+=(len(d[j])-1)*10
  d1=sum(d[1])
  d2=sum(d[2])
  d3=sum(d[3])
  L=[abs(d1-a)+abs(d2-b)+abs(d3-c),abs(d1-a)+abs(d2-c)+abs(d3-b),abs(d1-b)+abs(d2-a)+abs(d3-c),abs(d1-b)+abs(d2-c)+abs(d3-a),abs(d1-c)+abs(d2-a)+abs(d3-b),abs(d1-c)+abs(d2-b)+abs(d3-a)]
  cost+=min(L)
  ans=min(ans,cost)
print(ans)
n = int(input())
h = list(map(int, input().split()))

ans = 1
if h[0] <= h[1]:
  ans += 1

isCount = True
for i in range(2,n):
  if h[0] <= h[i]:
    if h[1] <= h[i]:
      for j in range(1,i):
        if h[j] > h[i]:
          isCount = False
      if isCount:
        ans += 1
print(ans)

### FIXED CODE ###

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

ans = 1
if len(h) >= 2:
  if h[0] <= h[1]:
    ans += 1
  for i in range(2,n):
    isCount = True
    if h[0] <= h[i]:
      if h[1] <= h[i]:
      	for j in range(1,i):
          if h[j] > h[i]:
          	isCount = False
      	if isCount:
          ans += 1
print(ans)
import math
N, D = map(int, input().split())
for i in range(N):
    x = list(map(int, input().split()))

cnt = 0
for i in range(D):
    for j in range(i+1, D):
        tmp = 0.0
        for k in range(D):
            tmp += (x[i][k]-x[j][k])**2
        if(math.sqrt(tmp).is_integer()):
            cnt += 1
print(cnt)

### FIXED CODE ###

import math
N, D = map(int, input().split())
x = [list(map(int, input().split())) for _ in range(N)]

cnt = 0
for i in range(N):
    for j in range(i+1, N):
        tmp = 0
        for k in range(D):
            tmp+=(x[i][k]-x[j][k])**2
        if(math.sqrt(tmp).is_integer()):
            cnt += 1
print(cnt)
MOD = (10**9) + 7
n = int(input())
a = list(map(int,intput().split()))

cnt = [0] * 60

for num in a:
  for j in range(60):
    cnt[j] += (num >> j) % 2
ans = 0
for b in range(60):
  ans += cnt[b] * (n-cnt[b]) << b
  
ans %= MOD
print(ans)

### FIXED CODE ###

MOD = (10**9) + 7
n = int(input())
a = list(map(int,input().split()))

cnt = [0] * 60

for num in a:
  for j in range(60):
    cnt[j] += (num >> j) % 2
ans = 0
for b in range(60):
  ans += cnt[b] * (n-cnt[b]) << b
  
ans %= MOD
print(ans)
x = int(input())
for i in range(2,10):
    if i <= x/200 < i+1:
        print(10-i):

### FIXED CODE ###

x = int(input())
if 400 <= x <= 599:
    print ("8")
if 600 <= x <= 799:
    print ("7")
if 800 <= x <= 999:
    print ("6")
if 1000 <= x <= 1199:
    print ("5")
if 1200 <= x <= 1399:
    print ("4")
if 1400 <= x <= 1599:
    print ("3")
if 1600 <= x <= 1799:
    print ("2")
if 1800 <= x <= 1999:
    print ("1")
import math
a,b,x=map(int,input().split())
theta=0

if x<=a**2*b/2:
	theta=math.degrees(math.atan(2*x/(a*b**2)))
else:
	theta=math.degrees(math.atan(a**3/(2*(a**2*b-x))))

print(90-theta)

### FIXED CODE ###

import math
a,b,x=map(int,input().split())
theta=0

if x<=a**2*b/2:
	theta=math.degrees(math.atan(a*b**2/(2*x)))
else:
	theta=math.degrees(math.atan(2*(a**2*b-x)/a**3))

print(theta)
n = int(input())

s = m = int(input())

for i in range(n):
  in_car, out_car = map(int, input().split())
  
  m += in_car - out_car
  
  if m < 0:
    s = 0
    break
  else:
    s = max(s, m)

print(s)

### FIXED CODE ###

n = int(input())

s = m = int(input())

for i in range(n):
  in_car, out_car = map(int, input().split())
  
  m += in_car - out_car
  
  if m < 0:
    s = 0
    break
  else:
    s = max(s, m)

print(s)
import sys
s = input().split()
weather_forecast = s[0]
weather_real = s[1]
weather_forecast_s = list(weather_forecast)
weather_real_s = list(weather_real)
hit = 0
for i in range(3):
    if weather_forecast_s[i] == weather_real_s[i]:
        hit+=1
print(hit)

### FIXED CODE ###

import sys
weather_forecast = input()
weather_real = input()
weather_forecast_s = list(weather_forecast)
weather_real_s = list(weather_real)
hit = 0
for i in range(3):
    if weather_forecast_s[i] == weather_real_s[i]:
        hit+=1
print(hit)
k,x=map(int,input(),split())

ans=range(x-k+1,x+k-1)
print(*ans)

### FIXED CODE ###

k,x=map(int,input().split())

ans=range(x-k+1,x+k)
print(*ans)
dic = {}
dic['A'] = T
dic['T'] = A
dic['C'] = G
dic['G'] = C

def a(b):
	return dic[b]

a=input()
print(a(a))

### FIXED CODE ###

dic = {}
dic['A'] = 'T'
dic['T'] = 'A'
dic['C'] = 'G'
dic['G'] = 'C'

def C(b):
    return dic[b]

a=input()
print(C(a))
s = input()

ans = 0

if (len(s) >= 4):
    if (s[0:4] == "YAKI"):
        ans = 1

if(ans == 1)
    print("Yes")
else:
    print("No")

### FIXED CODE ###

s = input()

ans = 0

if (len(s) >= 4):
    if (s[0:4] == "YAKI"):
        ans = 1

if (ans == 1):
    print("Yes")
else:
    print("No")
import math
class Mobile:
    def __init__(self,leftratio=0,rightratio=0,left=-1,right=-1):
        self.weight = 0
        self.leftratio = leftratio
        self.rightratio = rightratio
        self.left = left
        self.leftweight = 0
        self.right = right
        self.rightweight = 0

    def calc(self):
        if self.weight != 0 : return self.weight

        if self.left == -1:
            self.leftweight = 1
        else:
            self.leftweight = Mobile.calc(self.left)
        if self.right == -1:
            self.rightweight = 1
        else:
            self.rightweight = Mobile.calc(self.right)

        lmoment = self.leftratio*self.leftweight
        rmoment = self.rightratio*self.rightweight
        lcs = lmoment * rmoment // math.gcd(lmoment,rmoment)
        self.weight = (lcs//self.leftratio) + (lcs//self.rightratio)

        return self.weight

    def stdout(self):
        print(self.left, self.right)
while True:
    n = int(input())
    if n==0: break
    barlist = [Mobile() for i in range(n)]
    for i in range(n):
        p,q,r,b = map(int, input().split())
        barlist[i].leftratio = p
        barlist[i].rightratio = q
        if r != 0 : barlist[i].left = barlist[r-1]
        if b != 0 : barlist[i].right = barlist[b-1]

    maxi = 0
    for i in range(n):
        maxi = max(barlist[i].calc(),maxi)

    print(maxi)

### FIXED CODE ###

'''
Created on 2017/03/09

@author: 03key
'''

def gcd(x,y):
    if x<y:
        tmp = x
        x = y
        y = tmp
    ans = y
    if x%y != 0:
        ans = gcd(y,x%y)
    return ans

class Mobile:
    def __init__(self,leftratio=0,rightratio=0,left=-1,right=-1):
        self.weight = 0
        self.leftratio = leftratio
        self.rightratio = rightratio
        self.left = left
        self.leftweight = 0
        self.right = right
        self.rightweight = 0

    def calc(self):
        if self.weight != 0 : return self.weight

        if self.left == -1:
            self.leftweight = 1
        else:
            self.leftweight = Mobile.calc(self.left)
        if self.right == -1:
            self.rightweight = 1
        else:
            self.rightweight = Mobile.calc(self.right)

        lmoment = self.leftratio*self.leftweight
        rmoment = self.rightratio*self.rightweight
        lcs = lmoment * rmoment // gcd(lmoment,rmoment)
        self.weight = (lcs//self.leftratio) + (lcs//self.rightratio)

        return self.weight

    def stdout(self):
        print(self.left, self.right)

while True:
    n = int(input())
    if n==0: break
    barlist = [Mobile() for i in range(n)]
    for i in range(n):
        p,q,r,b = map(int, input().split())
        barlist[i].leftratio = p
        barlist[i].rightratio = q
        if r != 0 : barlist[i].left = barlist[r-1]
        if b != 0 : barlist[i].right = barlist[b-1]

    maxi = 0
    for i in range(n):
        maxi = max(barlist[i].calc(),maxi)

    print(maxi)
n,y=map(int,input().split())
a,b,c=-1,-1,-1
x=y//1000-n
if y%1000==0:
  for i in range(n+1):
    for j in range(n+1-j):
      if x==9*i+4*j:
        a=i
        b=j
        c=n-i-j
        break
    if a!=-1:
      break
print(a,b,c)

### FIXED CODE ###

n,y=map(int,input().split())
a,b,c=-1,-1,-1
x=y//1000-n
if y%1000==0:
  for i in range(n+1):
    for j in range(n+1-i):
      if x==9*i+4*j:
        a=i
        b=j
        c=n-i-j
        break
    if a!=-1:
      break
print(a,b,c)
H , W = map(int, input().split())
S = H * W

if S % 2 = 0:
    print(S//2)
else:
    print(S//2+1)

### FIXED CODE ###

H , W = map(int, input().split())
S = H * W
s = S//2

if H == 1 or W ==1:
    print("1")
elif S % 2 == 0:
    print(s)
else:
    print(s+1)
a=int(input())
b=list(map(int,input().split()))
cost=999999
for i in range(-100,1,101):
    c=0
    for j in b:
        c=c+(i-j)**2
    if c<cost:
        cost=c
print(cost)

### FIXED CODE ###

a=int(input())
ans=0
for i in range(a+1):
  ans+=i
print(ans)
a,b,c =map(int.input().split())
print(a * b // 2)

### FIXED CODE ###

a,b,c = map(int,input().split())
print(a * b // 2)
a, b, n = map(int, input().split())
 
tmp = 0
for x in (range(1, b+1, b)) #if b<=n else range(1, n+1, n-1)):
#for x in range(1, n+1):
    calc = a*x//b - a*(x//b)
    if calc > tmp:
        tmp = calc
 
print(tmp)

### FIXED CODE ###

a, b, n = map(int, input().split())
 
tmp = 0
for x in (range(1, b+1, b-2) if b<=n else range(1, n+1, n-1)):
#for x in range(1, n+1):
    calc = a*x//b - a*(x//b)
    if calc > tmp:
        tmp = calc
 
print(tmp)
print(‘x’*len(input()))

### FIXED CODE ###

s = input()
print('x' * len(s))
N=int(input())
a=[int(i) for i in input().split()]
data={}
for num in a:
    data[num]+=1
 
ans=0
for key in data.keys():
        if data[key]<key:
                ans+=data[key]
        else:
                ans+=data[key]-key
print(ans)

### FIXED CODE ###

N=int(input())
a=[int(i) for i in input().split()]
data={}
for num in a:
        if num in data:
                data[num]+=1
        else:
                data[num]=1

ans=0
for key in data.keys():
        if data[key]<key:
                ans+=data[key]
        else:
                ans+=data[key]-key
print(ans)
a,b,c,k=map(int,input().split())

if k%2 == 0 and abs(a-b)<=10**18:print(a-b)
elif k%2 != 0 and ans(b-a)<=10**18:print(b-a)
else:print("Unfair")

### FIXED CODE ###

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

if k%2 == 0 and abs(a-b)<=10**18:print(a-b)
elif k%2 != 0 and abs(b-a)<=10**18:print(b-a)
else:print("Unfair")
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
s=0
for i in range(N):
  s+=B[A[i]-1]
  if i>=1 and A[i]==A[i-1}+1:
    s+=C[i-1]
print(s)

### FIXED CODE ###

N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
s=0
temp=""
for i in A:
  s+=B[i-1]
  if temp==i-1:
    s+=C[temp-1]
  temp=i
print(s)
import collections
n=int(input())
D=list(map(int,input().split()))
D.sort()
m=d[-1]
MOD=998244353
if D[0] != 0 or D[0] >= 2:
  print(0)
  exit()
D=collections.Counter(D)
cnt=1
for i in range(1,m):
  if D[i] == 0:
    print(cnt % MOD)
    exit()
  else:
    cnt *= D[i] ** D[i+1]
print(cnt % MOD)

### FIXED CODE ###

import collections
n=int(input())
D=list(map(int,input().split()))
m=max(D)
MOD=998244353
if D[0] != 0:
  print(0)
  exit()
D=collections.Counter(D)
if D[0] >= 2:
  print(0)
  exit()
cnt=1
for i in range(1,m):
  cnt *= D[i] ** D[i+1]
print(cnt % MOD)
H,W = map(int,input().split())
 
if (H == 1)or(W == 1):
    sum = 1
elif H % 2 == 0:
    sum = W * H / 2
elif W % 2 == 0:
    sum = (W * (H-1) / 2) + (W / 2)
else:
    sum = (W * (H-1) / 2) + ((W+1) / 2)
 
print(int(sum))

### FIXED CODE ###

K=int(input())

if (K==1)or(K==2)or(K==3)or(K==5)or(K==7)or(K==11)or(K==13)or(K==15)or(K==17)or(K==19)or(K==23)or(K==29)or(K==31):
    print(1)
if (K==4)or(K==6)or(K==9)or(K==10)or(K==14)or(K==21)or(K==22)or(K==25)or(K==26):
    print(2)
if (K==8)or(K==12)or(K==18)or(K==20)or(K==27):
    print(5)
if K==16:
    print(14)
if K==24:
    print(15)
if (K==28)or(K==30):
    print(4)
if K==32:
    print(51)
h,w = map(int, input().split())
Array = [list(map(int, input().split())) for _ in range(h)]
dx = [1,1,0,-1,-1,-1,0,1]
dy = [0,1,1,1,0,-1,-1,-1]
for i in range(h):
  for j in range(w):
    if Array[i][j]='#':
      continue
      
    num=0
    for d in range(8):
      ni = i+dy[d]
      nj = j+dx[d]
      if ni<0 or h<=ni:
        continue
      if nj<0 or w<=nj:
        continue
      if Array[ni][nj]=='#':
        num=num+1
        
    Array[i][j]=char(num)
    
for i in Array:
  print(*Array)

### FIXED CODE ###

h,w = map(int,input().split())
Array = [list(map(str,input())) for _ in range(h)]
dx = [1,1,0,-1,-1,-1,0,1]
dy = [0,1,1,1,0,-1,-1,-1]
for i in range(h):
  for j in range(w):
    if Array[i][j]=='#':
      continue
    num=0
    for d in range(8):
      ni = i+dy[d]
      nj = j+dx[d]
      if ni<0 or h<=ni:
        continue
      if nj<0 or w<=nj:
        continue
      if Array[ni][nj]=='#':
        num=num+1
    Array[i][j]=str(num)
    
for i in Array:
  print(*i, sep='')
h,w,k = map(int,input().split())

s = [input() for i in range(h)]

#print(s)

ans = [[0 for i in range(w)]for j in range(h)]

now_h = 0
now_w = 0
num = 1

li = []

for i in range(h):
    now_w = 0
    for j in range(w):
        #print(i,j,now_w)
        if s[i][j] == '#':
            #print(now_h+1>=i,i,j)
            #if now_h+1 >= i:
                #print(now_h==i)
            for k in range(j-now_w+1):
                ans[i][now_w+k] = num
            """
            else:
                for k in range(now_w-j+1):
                    if s[i][k] == 1:
                        a = 1
            """
            now_h = i
            now_w = j+1
            num += 1


for i in range(h):
    for j in range(w):
        if ans[i][j] == 0:
            ans[i][j] = ans[i][j-1]


for i in range(h):
    for j in range(w):
        if ans[i][j] == 0:
            if i != h-1:
                for k in range(h):
                    if ans[i+1+k][j] != 0:
                        ans[i][j] = ans[i+1+k][j]
                        break
            else:
                for k in range(h):
                    if ans[i-k][j] != 0:
                        ans[i][j] = ans[i-k][j]
                        break

for i in range(h):
    print(*ans[i])

### FIXED CODE ###

h,w,k = map(int,input().split())

s = [input() for i in range(h)]

#print(s)

ans = [[0 for i in range(w)]for j in range(h)]

now_h = 0
now_w = 0
num = 1

li = []

for i in range(h):
    now_w = 0
    for j in range(w):
        #print(i,j,now_w)
        if s[i][j] == '#':
            #print(now_h+1>=i,i,j)
            #if now_h+1 >= i:
                #print(now_h==i)
            for k in range(j-now_w+1):
                ans[i][now_w+k] = num
            """
            else:
                for k in range(now_w-j+1):
                    if s[i][k] == 1:
                        a = 1
            """
            now_h = i
            now_w = j+1
            num += 1


for i in range(h):
    for j in range(w):
        if ans[i][j] == 0:
            ans[i][j] = ans[i][j-1]


for i in range(h):
    for j in range(w):
        if ans[i][j] == 0:
            flag = False
            for k in range(h):
                if i+1+k >= h:
                    break
                if ans[i+1+k][j] != 0:
                    ans[i][j] = ans[i+1+k][j]
                    flag = True
                    break
            if flag == False:
                for k in range(h):
                    if i-1-k < 0:
                        break
                    if ans[i-1-k][j] != 0:
                        ans[i][j] = ans[i-1-k][j]
                        break

for i in range(h):
    print(*ans[i])
N = int(input())
hlist = list(map(int, input().split()))

dp = [float('inf')] * N
def f(i):
  if dp[i] < float('inf'):
    return dp[i]
  if i==0:
    return 0
  if i==1:
    return abs(hlist[1]-hlist[0])
  
  res = float('inf')
  res = min(res, f(i-1) + abs(hlist[i]-hlist[i-1]))
  res = min(res, f(i-2) + abs(hlist[i]-hlist[i-2]))
  dp[i] = res
  
  return dp[i]
print(f(N-1))


### FIXED CODE ###

N = int(input())
hlist = list(map(int, input().split()))

dp = [-1 for _ in range(N)]
dp[0] = 0
for n in range(N-2):
  cost = dp[n] + abs(hlist[n]-hlist[n+1])
  dp[n+1] = min(dp[n+1], cost) if dp[n+1] != -1 else cost
  cost = dp[n] + abs(hlist[n]-hlist[n+2])
  dp[n+2] = min(dp[n+2], cost) if dp[n+2] != -1 else cost
cost = dp[-2] + abs(hlist[-2]-hlist[-1])
dp[-1] = min(dp[-1], cost) if dp[-1] != -1 else cost
print(dp[-1])
#!/usr/bin python3
# -*- coding: utf-8 -*-

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

def check(l):
    ret = True
    for i in range(n-1):
        if a[i]>a[i+1]:
            ret = False
            break
    return ret

def solv(ret):
    print(len(ret))
    for i in ret:
        print("{} {}".format(*i))

if check(a):
    print(0); exit()

m = 0
for i, ai in enumerate(a):
    if abs(ai) > m:
        m = ai
        mi = i

ret = []
if m > 0:
    for i in range(n):
        ret.append([mi+1, i+1])
        a[i] += a[mi]
        if check(a):
            solv(ret)
            exit()
    for i in range(n-1):
        ret.append([i+1, i+2])
        a[i+1] += a[i]
        if check(a):
            solv(ret)
            exit()
else:
    for i in range(n):
        ret.append([mi+1, i+1])
        a[i] += a[mi]
        if check(a):
            solv(ret)
            exit()
    for i in range(n-1, -1, -1):
        ret.append([i+1, i+2])
        a[i+1] += a[i]
        if check(a):
            solv(ret)
            exit()


### FIXED CODE ###

#!/usr/bin python3
# -*- coding: utf-8 -*-

n = int(input())
a = list(map(int, input().split()))
m = 0
for i, ai in enumerate(a):
    if abs(ai) >= m:
        m = abs(ai)
        mi = i
ret= [[mi+1, i+1] for i in range(n)]
if a[mi] >= 0:
    for i in range(n-1):
        ret.append([i+1, i+2])
else:
    for i in range(n-2, -1, -1):
        ret.append([i+2, i+1])  #i+1->i
print(2*n-1)
for x in ret:
    print(" ".join(map(str, x)))