# CFR 798 D. Mike and distribution ( Adhoc / Random )

Problem - D - Codeforces

The first line contains integer n (1 ≤ n ≤ 1e5) — the number of elements in the sequences.
On the second line there are n space-separated integers a1, ..., an (1 ≤ ai ≤ 1e9) — elements of sequence A.
On the third line there are also n space-separated integers b1, ..., bn (1 ≤ bi ≤ 1e9) — elements of sequence B.

O( N )

```from functools import cmp_to_key

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

ord = sorted( list( i for i in range( N ) ), key = cmp_to_key( lambda x, y: A[ y ] - A[ x ] ) )

ans = [ ord[ 0 ] ]
for i in range( 1, N, 2 ):
if i + 1 == N:
ans.append( ord[ i ] )
else:
if B[ ord[ i ] ] >= B[ ord[ i + 1 ] ]:
ans.append( ord[ i ] )
else:
ans.append( ord[ i + 1 ] )

print( len( ans ) )
print( *list( map( lambda x: x + 1, ans ) ) )
```

random_shuffle()

```import random
import datetime

random.seed( datetime.datetime.now() )
N = int( input() )
A = list( map( int, input().split() ) )
B = list( map( int, input().split() ) )

def valid( arr ):
return sum( A[ k ] for k in arr ) * 2 > sum( A ) and sum( B[ k ] for k in arr ) * 2 > sum( B )

ans = [ i for i in range( N ) ]
while not valid( ans[ : N // 2 + 1 ] ):
random.shuffle( ans )

print( N // 2 + 1 )
print( *list( map( lambda x: x + 1, ans[ : N // 2 + 1 ] ) ) )
```