Harryxun/stf_run huggingface dataset:
import sys
import heapq
input = sys.stdin.readline

n, m = map(int, input().split())
a = list(map(int, input().split()))
for i in range(m):
    a[i] *= -1
heapq.heapify(a)

for cnt in range(m):
    temp = heapq.heappop(a)*(-1)
    if temp == 0:
        break
    heapq.heappush(a, (temp//2)*(-1))

print(sum(a)*(-1))

### FIXED CODE ###

import sys
import heapq
input = sys.stdin.readline
 
n, m = map(int, input().split())
a = list(map(int, input().split()))
for i in range(n):
    a[i] *= -1
heapq.heapify(a)
 
for cnt in range(m):
    temp = heapq.heappop(a)*(-1)
    if temp == 0:
        break
    heapq.heappush(a, (temp//2)*(-1))
    
print(sum(a)*(-1))
s=input()
p=0; m=0
for i in range(0,len(s))
  if s[i]=='+':
    p += 1
  else:
    m += 1
print(p-m)

### FIXED CODE ###

s=input()
p=0; m=0
for i in range(0,4):
  if s[i]=='+':
    p += 1
  else:
    m += 1
print(p-m)
n, m = map(int, input().split())
h = list(map(int, input().split()))
num = [0]*n
chk = [0]*n
for _ in range(m):
    a, b = map(int, input().split())
    num[a-1] += 1
    num[b-1] += 1
    if h[a-1]>h[b-1]:
        chk[a-1] += 1
    elif h[b-1]>h[a-1]:
        chk[b-1] += 1
ans = 0
for i in range(m):
    if num[i]==chk[i]:
        ans += 1
print(ans)

### FIXED CODE ###

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

ma = [0]*n
for _ in range(m):
    a, b = map(int, input().split())
    ma[a-1] = max(h[b-1], ma[a-1])
    ma[b-1] = max(h[a-1], ma[b-1])

ans = 0
for i in range(n):
    if h[i]>ma[i]:
        ans += 1
print(ans)
N=input()
if '7' in S:
    print('Yes')
else:
    print('No')

### FIXED CODE ###

N=input()
if '7' in N:
    print('Yes')
else:
    print('No')
a = list(map(int, input().split()))

for i in a:
  if i==5:
    i5+=1
  elif i==7:
    i7+=1

if i5==2 & i7==1:
  print("YES")
else:
  print("NO")

### FIXED CODE ###

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

i5 = 0
i7 = 0

for i in a:
  if i==5:
    i5+=1
  if i==7:
    i7+=1

if i5==2 and i7==1:
  print("YES")
else:
  print("NO")
l = raw_input().split()
print((int(l[0])-int(l[2]))/(int(l[1])+int(l[2])))

### FIXED CODE ###

l = raw_input().split()
print((int(l[0])-int(l[2]))/(int(l[1])+int(l[2])))
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))




n = int(input())
minsum = [None] * n # (min, sum)
for i in range(n):
    tmp = list(map(int, " ".join(input()).replace("(", "1").replace(")", "-1").split()))
    c = 0
    m = 0
    for item in tmp:
        c += item
        m = min(c, m)
    minsum[i] = (m, sum(tmp))
minsum.sort()
if sum(item[1] for item in minsum)!=0:
    print("No")
else:
    c = 0
    i = n-1
    while True:
        m, s = minsum[i]
        if m<0:
            break
        c += s
        i -= 1
        minsum.pop()
    minsum.sort(key=lambda x: x[1])
#     print(minsum, c)
    i = len(minsum)-1
    while minsum:
        m, s = minsum[i]
        if c+m>=0:
            minsum.pop(i)
            c += s
            i = len(minsum) - 1
        else:
            i -= 1
            if i<0:
                print("No")
                break
    else:
        print("Yes")

### FIXED CODE ###

def main():
    import queue
    import sys
    input = lambda : sys.stdin.readline().rstrip()
    sys.setrecursionlimit(max(1000, 10**9))



    n = int(input())
    minsum = [None] * n # (min, sum)
    for i in range(n):
        tmp = list(map(int, " ".join(input()).replace("(", "1").replace(")", "-1").split()))
        c = 0
        m = 0
        for item in tmp:
            c += item
            m = min(c, m)
        minsum[i] = (m, sum(tmp))
    minsum.sort()

    if sum(item[1] for item in minsum)!=0:
        print("No")
    else:
        minsum1 = [item for item in minsum if item[1]>=0]
        minsum2 = [(item[0]-item[1], -item[1]) for item in minsum if item[1]<0]
        minsum2.sort()
        c = 0
        for m,s in minsum1[::-1]:
            if c+m>=0:
                c += s
            else:
                print("No")
                return
        c = 0
        for m,s in minsum2[::-1]:
            if c+m>=0:
                c+=s
            else:
                print("No")
                return
        print("Yes")
main()
n=input()
x=input()
s=list(x)
list=[]

for i in range(n):
    a=0;
    for j in range(i):
        for k in range(n-i):
            if s[j]=s[k]:
                a+=1
    list.append(a)

f=max(list)
print(f)

### FIXED CODE ###

n=int(input())
x=input()
s=list(x)
list=[]
 
for i in range(n):
    a=0
    moji=[]
    for j in range(i):
        for k in range(n-i):
            if s[j]==s[k+i]:
                if s[j] not in moji:
                    a+=1
                    moji.append(s[j])
    list.append(a)
 
f=max(list)
print(f)
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**6)
N, K = map(int, input().split())
Ps = list(map(int, input().split()))
Cs = list(map(int, input().split()))
scores = list()
max_list = list()
for i in range(N):
    next = Ps[i] - 1
    scores = [Cs[next]]
    while next != i:
        next = Ps[next] - 1
        scores.append(Cs[next]+scores[-1])
    l = len(scores)
    if scores[-1] < 0 or l >= K:
        max_list.append(max(scores[:K]))
    else:
        a, b = divmod(K, l)
        max_list.append(a*scores[-1] + max(scores[:b]))
    #print(scores)
print(max(max_list))


### FIXED CODE ###

# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
N, K = map(int, input().split())
Ps = list(map(int, input().split()))
Cs = list(map(int, input().split()))
max_list = list()
for i in range(N):
    next = Ps[i] - 1
    scores = [Cs[next]]
    while next != i:
        next = Ps[next] - 1
        scores.append(scores[-1] + Cs[next])
    l = len(scores)
    if K <= l:
        max_list.append(max(scores[:K]))
    else:
        if scores[-1] < 0:
            max_list.append(max(scores))
        else:
            a, b = divmod(K, l)
            cand1 = 0
            if b!=0:
                cand1 = a*scores[-1] + max(scores[:b])
            cand2 = (a-1)*scores[-1] + max(scores)
            max_list.append(max(cand1, cand2))
    #print(scores)
print(max(max_list))
N=int(input())
p=[list(map(int, input().split())) for _ in range(N)]
ax, ay, ah = list(filter(lambda x: x[2], p))[0]
for i in range(101):
  for j in range(101):
    center=[i,j,ah+abs(ax-i)+abs(ay-j)]
    if all(t[2]==max(center[2]-abs(t[0]-center[0])-abs(t[1]-center[1]),0) for t in x) :
      print(center[0],center[1],center[2])


### FIXED CODE ###

n = int(input())
p = [list(map(int, input().split()))for _ in range(n)]
ax, ay, ah = list(filter(lambda x: x[2], p))[0]
for x in range(101):
    for y in range(101):
        H = ah+abs(ax-x)+abs(ay-y)
        if all(max(H-abs(t[0]-x)-abs(t[1]-y), 0) == t[2]for t in p):
            print(x, y, H)
N=int(input())
A=list(map(int, input().split()))
A.sort(reverse=True)
sum1=0
sum2=0
for num in range(N+1):
  if num % 2 ==0:
    sum1 += A[num]
  else:
    sum2 += A[num]
print(sum1-sum2)

### FIXED CODE ###

N = int(input())
A = list(map(int, input().split()))
A.sort(reverse=True)
sum1=0
sum2=0
for num in range(N):
  if num % 2 == 0:
    sum1 += A[num]
  else:
    sum2 += A[num]
print(sum1 - sum2)
n,m,c=map(int,input().split())
b=list(map(int,input().split()))
for d in range(n):
  a=[list(map(int,input().split()))]
ans=0
for i in range(n):
    C=c
    for j in range(m):
        C+=a[i][j]*b[j]
    if C>0:
        ans+=1
print(ans)


### FIXED CODE ###

n,m,c=map(int,input().split())
b=list(map(int,input().split()))
a=[list(map(int,input().split())) for d in range(n)]
ans=0
for i in range(n):
    C=c
    for j in range(m):
        C+=a[i][j]*b[j]
    if C>0:
        ans+=1
print(ans)
for i in range(d):
  print(i%26+1)

### FIXED CODE ###

d=int(input())
c=list(map(int, input().split()))
s=[list(map(int, input().split())) for _ in range(d)]
t=[0]*26
ans=0
for i in range(1,d+1):
  tmp=s[i-1].index(max(s[i-1]))
  print(tmp+1)
N=int(input())
can=[]
for i in range(1,N**0.5+1):
  if N%i==0:
    can.append(N-1+N//i-1)
    

print(min(can))

### FIXED CODE ###

N=int(input())
can=[]
for i in range(1,int(N**0.5)+1):
  if N%i==0:
    can.append(i-1+N//i-1)
    

print(min(can))
n=int(input())
x=list(map(int,input().split()))
a=[]
b=[]
ans=[]
yn=0
count=1
count2=0
count3=0
for i in range(n):
    check=i*n+((n-i-1)*(n-i))//2
    if check+i+1<x[i] or x[i]<((i+2)*(i+1))//2:
        yn+=1
        break
lena=len(a)
if yn==1:
    print("No")
else:
    print("Yes")
    for i in range(n):
        for j in range(i):
            a.append(i+1)
    for i in range(n):
        for j in range(n-i-1):
            b.append(i+1)
    for i in range(n*n):
        if x.count(i+1)==1:
            ans.append(count)
            count+=1
        else:
            if count2<lena:
                ans.append(a[count2])
                count2+=1
            else:
                ans.append(b[count3])
                count3+=1
    print(*ans)


### FIXED CODE ###

def solve():
    n=int(input())
    x=list(map(int,input().split()))
    list1=[]
    def ap1(num):
        list1.append(num)
    for i in range(n):
        ap1([x[i],i+1])
    str1= lambda val: val[0]
    list1.sort(key=str1)
    numa=[]
    numb=[]
    for i in range(n):
        num3=list1[i][1]
        numa+=[num3]*(num3-1)
        numb+=[num3]*(n-num3)
    count1=0
    count2=0
    count3=0
    ans=[]
    ansnum=0
    def countnum(num):
        return ans.count(num)
    def apans(num):
        ans.append(num)
    for i in range(n*n):
        yn=0
        if count1!=n:
            if i==list1[count1][0]-1:
                if countnum(list1[count1][1])!=list1[count1][1]-1:
                    ansnum=1
                    break
                apans(list1[count1][1])
                count1+=1
                yn=1
        if yn==0:
            if count2!=len(numa):
                apans(numa[count2])
                count2+=1
            elif count3!=len(numb):
                apans(numb[count3])
                count3+=1
            else:
                if i!=n*n-1:
                    ansnum=1
                    break
    if ansnum==1:
        print("No")
    else:
        print("Yes")
        print(*ans)
solve()
k=int(input())
x,y=map(int,input().split())
d=abs(x)+abs(y)
if k%2==0 and d%2!=0:
  print(-1)
else:
  ans=[]
  if d<k and d%2==1:
    n=3
    td=k-d
    if y>=0:
      ans.append((x,y+td))
      ans.append((x+(k-td//2),y+td//2))
      ans.append((x,y))
    else:
      ans.append((x,y-td))
      ans.append((x+(k-td//2),y-td//2))
      ans.append((x,y))
  print(n)
  for tx,ty in ans:
    print(tx,ty)

### FIXED CODE ###

def editarr(x,y,arr):
  if abs(x)>=abs(y):
    for i in range(len(arr)):
      arr[i][0],arr[i][1]=arr[i][1],arr[i][0]
  if x<0:
    for i in range(len(arr)):
      arr[i][0]*=-1
  if y<0:
    for i in range(len(arr)):
      arr[i][1]*=-1

k=int(input())
x,y=map(int,input().split())
ans=[]
tx=abs(x)
ty=abs(y)
if tx>=ty:
  tx,ty=ty,tx
if k%2==0 and (tx+ty)%2!=0:
  print(-1)
else:
  if tx+ty<k:
    if (tx+ty)%2==0:
      m=(ty-tx)//2
      ans.append([k-m,m])
    else:
      td=k-(tx+ty)
      ans.append([tx,ty+td])
      ans.append([tx+(k-td//2),ty+td//2])
    ans.append([tx,ty])
    n=len(ans)
  elif ty-(k-tx%k)<k and (ty-(k-tx%k))%2!=0:
    if tx<k and ty<k:
      if (2*k-(tx+ty))%2==0:
        td=2*k-(tx+ty)
        ans.append([tx+td//2,k-(tx+td//2)])
        ans.append([tx,ty])
      else:
        ans.append([tx,k-tx])
        td=ty-(k-tx)
        ans.append([tx+(k-td//2),ans[-1][1]+td//2])
        ans.append([tx,ty])
      n=len(ans)
    else:
      if tx+ty<2*k:
        if (2*k-(tx+ty))%2==0:
          td=2*k-(tx+ty)
          ans.append([tx+td//2,k-(tx+td//2)])
          ans.append([tx,ty])
        else:
          ans.append([tx,k-tx])
          td=ty-(k-tx)
          ans.append([tx+(k-td//2),ans[-1][1]+td//2])
          ans.append([tx,ty])
        n=len(ans)
      else:
        ans.append([0,0])  
  else:
    ans.append([0,0])
    for i in range(tx//k):
      ans.append([ans[-1][0]+k,0])
    if ans[-1][0]!=tx:
      ans.append([tx,k-abs(tx-ans[-1][0])])
    td=ty-ans[-1][1]
    if td%k==0:
      flag=True
    else:
      flag=False
    for i in range(td//k):
      if flag==False and (ty-ans[-1][1])%2==0 and (ty-ans[-1][1])<=2*k:
          break
      ans.append([tx,ans[-1][1]+k])
    if ans[-1][1]!=ty:
      td=ty-ans[-1][1]
      ans.append([tx+(k-td//2),ans[-1][1]+td//2])
      ans.append([tx,ty])
    ans.pop(0)
    n=len(ans)
  editarr(x,y,ans)
  print(n)
  for a,b in ans:
    print(a,b)
import collections as cl
from math import factorial

def comb(n, r):
  if n >= r:
    return int(factorial(n) / factorial(r) / factorial(n - r))
  else:
    return 0
  
n = int(input())
a = list(map(int, input().split()))

clc = cl.Counter(a)

# 1. 数字が等しいペアを選ぶ総数
npair = 0
for (k, v) in clc.items():
  npair += comb(v, 2)

# 2. (取り除いた数字と同じ数字を選ぶ総数) - (1)
for a_ in a:
  print(npair - (clc[a_] - 1))

### FIXED CODE ###

#!/usr/bin/env python3
import collections as cl
from math import factorial

def comb(n, r):
    if n >= r:
        return factorial(n) // (factorial(n - r) * factorial(r))
    else:
        return 0
  
n = int(input())
a = list(map(int, input().split()))

clc = cl.Counter(a)

# 1. 数字が等しいペアを選ぶ総数
npair = 0
for (k, v) in clc.items():
    npair += comb(v, 2)

# 2. (取り除いた数字と同じ数字を選ぶ総数) - (1)
for a_ in a:
    print(npair - (clc[a_] - 1))
import math
import sys

def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n, m = map(int,input().split())

if n <= 1:
  print(comb(m, 2))
  sys.exit()
  
if m <=1:
  print(comb(n, 2))
  sys.exit()

if n == 1 and m == 1:
  print('0')
  sys.exit()

print(comb(n, 2) + comb(m, 2))

### FIXED CODE ###

import math
import sys

def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n, m = map(int,input().split())

if n == 1 and m == 1:
  print('0')
  sys.exit()
  
if n <= 1:
  print(comb(m, 2))
  sys.exit()
  
if m <=1:
  print(comb(n, 2))
  sys.exit()

print(comb(n, 2) + comb(m, 2))
import copy
import sys
import math

def main():
	n,y = map(int,input().split())
	for i in range(n+1):
		for j in range(n-i+1):
			k = n-i-j
			if(y == i*10000 + j*5000 + k*1000):
				print(f'{i} {j} {k}')
				sys.exit()
	print('-1 -1 -1')


def listtodict(a):
	b = {}
	for i in a:
		try:
			b[i] += 1
		except:
			b[i] = 1
	return b

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

main()

### FIXED CODE ###

import copy
import sys
import math

def main():
	n,y = map(int,input().split())
	for i in range(n+1):
		for j in range(n-i+1):
			k = n-i-j
			if(y == i*10000 + j*5000 + k*1000):
				print('{} {} {}'.format(i,j,k))
				sys.exit()
	print('-1 -1 -1')


def listtodict(a):
	b = {}
	for i in a:
		try:
			b[i] += 1
		except:
			b[i] = 1
	return b

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

main()
import math
r = int(input())

area = r * r * math.pi
length = r * 2 * pi

print("{0:.6f}".format(area),end=' ')
print("{0:.6f}".format(length))

### FIXED CODE ###

import math
r = float(input())

area = r * r * math.pi
length = r * 2 * math.pi

print("{0:.6f}".format(area),end=' ')
print("{0:.6f}".format(length))
x=int(input())
for i in range(-200,200):
    for j in range(-200,200):
        if a**5-b**5==x:
            print(a,b)
            exit()

### FIXED CODE ###

x=int(input())
for a in range(-200,200):
    for b in range(-200,200):
        if a**5-b**5==x:
            print(a,b)
            exit()
import math
A,B,C,D = map(int,input().split())
if (math.ceil(C/B) =< math.ceil(A/D)):
    print('Yes')
else:
    print('No')

### FIXED CODE ###

import math
A,B,C,D = map(int,input().split())
if (math.ceil(C/B) <= math.ceil(A/D)):
    print('Yes')
else:
    print('No')
list = list(input())
for i in len(list):
    n = 0:
    if int(list[i]) ==1:
        n =+ 1
print(n)


### FIXED CODE ###

L = input()
n=0
for i in range(len(L)):
    if int(L[i]) ==1:
        n += 1
print(n)
N,M,X,Y=map(int,input().split())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
print('No War' if max(max(x),X)<min(min(y),Y) else 'War')

### FIXED CODE ###

s=sorted(map(int,input().split()))
print(int(str(s[2])+str(s[1]))+s[0])
import numpy as np

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

a = 1
for i in range(k, n + 1):
  mmin = summ(i)
  mmax = summ(n, n - i)
  m = mmax - mmin
  a += m
  
def summ(n, nn=0):
  nn = max(nn, 0)
  return n*(n+1)/2 - nn*(nn+1)/2

### FIXED CODE ###

def summ(n, nn=0):
  nn = max(nn, 0)
  return n*(n+1)/2 - nn*(nn+1)/2

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

a = 1
for i in range(k, n + 1):
  mmin = summ(i - 1)
  mmax = summ(n, n - i)
  m = mmax - mmin + 1
  a += m

k = 10**9 + 7
print(int(a%k))
n, k = map(int, input().split())
p = [int(i) for i in input().split()]
maxp = 0
for i in range(n - k + 1):
    sump = sum(p[i: i + k])
    if maxp < sump:
        maxp = sump
        j = i
print((maxp + k) / 2)

### FIXED CODE ###

n = int(input())
a = [int(i) for i in input().split()]
set_a = set(a)
if len(set_a) == len(a):
    print('YES')
else:
    print('NO')
#include<algorithm>
#include<iostream>
int main(argc, **argv) {
	int a, b;
  	cin>>a;
  	cin>>b;
  	int ans = 0;
  	ans = max(ans, a + a-1);
  	ans = max(ans, a + b);
  	ans = max(ans, b + b-1);
  	cout << asn << endl;
}

### FIXED CODE ###

line = input().strip()
line = line.split(' ')
A = int(line[0])
B = int(line[1])
ans = 0
ans = max(ans, A + A - 1)
ans = max(ans, A + B)
ans = max(ans, B + B - 1)
print(ans)
N=int(input())
s=""
for i in range(N):
    s.append(input())
print('AC x '+s.count('AC'))
print('WA x '+s.count('WA'))
print('TLE x '+s.count('TLE'))
print('RE x '+s.count('RE'))

### FIXED CODE ###

N=int(input())
s=[]
for i in range(N):
    s.append(input())
print("AC x ",s.count("AC"))
print("WA x ",s.count("WA"))
print("TLE x ",s.count("TLE"))
print("RE x ",s.count("RE"))
x = str(input())

if x.isupper() = True:
  print("A")
else:
  print("a")

### FIXED CODE ###

x = input()

if str(x).isupper() == True:
  print("A")
else:
  print("a")
n, m = map(int, input().split())
print([2, 1][m > 1])


### FIXED CODE ###

x = int(input())
ans = i = 0
while i < x:
    ans += 1
    i += ans
print(ans)
pgnum = input()
res = Math.ceil(pgnum/2)
print(res)


### FIXED CODE ###

import math
s = input()
s = int(s)
s = s/2
s = math.ceil(s)
print(s)
import itertools

N = int(input)
coords = [list(map(int, input().split())) for i in range(N)]
dis = 0
n = list(range(N))

for order in itertools.permutations(n):
  for i in range(1, N):
    dis += ((coords[order[i]][0]-coords[order[i-1]][0])**2 + (coords[order[i]][1]-coords[order[i-1]][1])**2)**0.5

ave = dis / N
print(ave)

### FIXED CODE ###

import itertools
 
N = int(input())
coord = [list(map(int, input().split())) for _ in range(N)]
dis = 0

for order in itertools.permutations(range(N)):
  for i in range(1, N):
    dis += ((coord[order[i]][0]-coord[order[i-1]][0])**2 + (coord[order[i]][1]-coord[order[i-1]][1])**2)**0.5
 
ave = dis / len(list(itertools.permutations(range(N))))
print(ave)
a,b=minput().split()
if a==b:
    print(3)
elif a!=b:
    print(0)
elif a[0]=b[0] and a[1]=b[1] and a[2]!=b[2]:
    print(2)
elif a[0]=b[0] and a[1]!=b[1] and a[2]=b[2]:
    print(2)
elif a[0]!=b[0] and a[1]=b[1] and a[2]=b[2]:
    print(2)
else:
    print(1)  
     


### FIXED CODE ###

S=input()
T=input()
ans=0
for i in range(3):
 if S[i]==T[i]:
     ans+=1
print(ans)
import sys,collections as cl,bisect as bs,heapq as hq
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))

n = onem()

a = l()

b = l()

t = []

for i in range(n):
    hq.heappush(t,[-b[i],i])
heapify(t)
co = 0
while t:
    k = hq.heappop(t)
    k = [-k[0],k[1]]
    if k[1] == 0:
        ppp = (k[0]-a[k[1]]) // (b[-1] + b[1])
        if ppp == 0:
            print(-1)
            exit()
        co += ppp
        k[0] = (k[0]-a[k[1]]) % (b[-1] + b[1]) + a[k[1]]
    elif k[1] == n-1:
        ppp = (k[0]-a[k[1]]) // (b[-2] + b[0])
        if ppp == 0:
            print(-1)
            exit()
        co += ppp
        k[0] = (k[0]-a[k[1]]) % (b[-2] + b[0]) + a[k[1]]
    else:
        ppp = (k[0]-a[k[1]]) // (b[k[1]+1] + b[k[1]-1])
        if ppp == 0:
            print(-1)
            exit()
        co += ppp
        k[0] = (k[0]-a[k[1]]) % (b[k[1]+1] + b[k[1]-1]) + a[k[1]]
    b[k[1]] = k[0]
    if b[k[1]] != a[k[1]] and len(t) != 0:
        hq.heappush(t,[-b[k[1]],k[1]])

print(co)

### FIXED CODE ###

import heapq as hq
mod = 10**9+7
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())

def onon():
    n = onem()

    a = l()

    b = l()

    t = []

    for i in range(n):
        if b[i] != a[i]:
            hq.heappush(t,(-b[i],i))
    co = 0
    while t:
        k = hq.heappop(t)
        k = (-k[0],k[1])
        q,w = divmod(k[0] - a[k[1]], b[(k[1] - 1) % n] + b[(k[1] + 1) % n])
        co += q
        if q == 0:
            return -1
        w = a[k[1]] + w
        b[k[1]] = w
        if b[k[1]] != a[k[1]]:
            hq.heappush(t,(-w,k[1]))
    return co
print(onon())
import math
from collections import Counter
M = 256

def entropy(ctr):
    ret = 0
    for v in ctr.values():
        ret -= (v / N) * math.log2(v / N)
    return ret

def solve(src):
    ans_h = float('inf')
    ans = None
    for s in range(16):
        for a in range(16):
            for c in range(16):
                ctr = Counter()
                r = s
                for i in src:
                    r = (a*r + c) % M
                    o = (i + r) % M
                    ctr.update([o])
                h = entropy(ctr)
                if h < ans_h:
                    ans = (s,a,c)
                    ans_h = h
                    if ans_h == 0:
                        return ans
    return ans

while True:
    N = int(input())
    if N == 0: break
    src = list(map(int,input().split()))
    print(' '.join(map(str,solve(src))))

### FIXED CODE ###

import math
M = 256

def entropy_if_smallest(ctr,bound):
    ret = 0
    for v in ctr:
        if v == 0: continue
        ret -= (v / N) * math.log2(v / N)
        if ret >= bound:
            return None
    return ret

def solve(src):
    ans_h = float('inf')
    ans = None
    for s in range(16):
        for a in range(16):
            for c in range(16):
                ctr = [0] * M
                r = s
                for i in src:
                    r = (a*r + c) % M
                    o = (i + r) % M
                    ctr[o] += 1
                h = entropy_if_smallest(ctr,ans_h)
                if h is not None:
                    ans = (s,a,c)
                    ans_h = h
                    if ans_h == 0:
                        return ans
    return ans

while True:
    N = int(input())
    if N == 0: break
    src = list(map(int,input().split()))
    print(' '.join(map(str,solve(src))))
N=int(input())
S=input()
len_of_s=len(S)
if len_of_s%2==0 and S[:len_of_s/2]==s[len_of_s/2:]:
  print("Yes")
elif:
  print("No")

### FIXED CODE ###

N=int(input())
S=input()
len_of_s=len(S)
if len_of_s%2==0 and S[:len_of_s//2]==S[len_of_s//2:]:
  print("Yes")
else:
  print("No")
n = int(input())
a = map(int, input().split())

a = reversed(sorted(a))
m = 0

for i in range(n, 2 * n):
    m += a[i]

print(m)

### FIXED CODE ###

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

a = sorted(a, reverse=True)
m = 0

for i in range(1, 2 * n, 2):
    m += a[i]

print(m)