//84104971101048411497 - Can you guess what does this mean?
#include <message. h >
#include <stdio. h >
#include "oops. h "
#define MASTER_NODE 7
#define DONE - 2000000000000000008LL
using namespace std;
#include <bits/ stdc++ . h >
#define mapii map<int, int>
#define debug( a) cout << #a << ": " << a << endl
#define debuga1( a, l, r) fto( i, l, r) cout << a[ i] << " "; cout << endl
#define fdto( i, r, l) for ( int i = ( r) ; i >= ( l) ; -- i)
#define fto( i, l, r) for ( int i = ( l) ; i <= ( r) ; ++ i)
#define ftoa( i, l, r, a) for ( int i = ( l) ; i <= ( r) ; i += a)
#define forit( it, var ) for ( __typeof( var . begin ( ) ) it = var . begin ( ) ; it != var . end ( ) ; it++ )
#define fordit( rit, var ) for ( __typeof( var . rbegin ( ) ) rit = var . rbegin ( ) ; rit != var . rend ( ) ; rit++ )
#define ii pair<int, int>
#define iii pair<int, ii>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define ll long long
#define maxN 13
#define oo 2000000000000000007LL
template <class T>
T min( T a, T b, T c) {
return min(a, min(b, c));
}
template <class T>
T max( T a, T b, T c) {
return max(a, max(b, c));
}
int main( ) {
int N = GetN();
int nodes = NumberOfNodes();
int my_id = MyNodeId();
ll maxX = -oo, minX = oo;
ftoa(j, my_id, N-1, nodes) {
maxX = max(maxX, GetNumber(j));
minX = max(minX, GetNumber(j));
}
PutLL( MASTER_NODE, minX) ;
PutLL( MASTER_NODE, maxX) ;
PutLL( MASTER_NODE, DONE) ;
Send( MASTER_NODE) ;
if ( my_id == MASTER_NODE) {
ll maxX = -oo, minX = oo;
fto(node, 0, nodes-1) {
while (true) {
Receive(-1);
ll x = GetLL(node);
if (x == DONE) break;
else {
minX = min(minX, x);
maxX = max(maxX, x);
}
}
}
printf( "%lld\n", maxX- minX) ;
}
return 0 ;
}
Ly84NDEwNDk3MTEwMTA0ODQxMTQ5NyAtIENhbiB5b3UgZ3Vlc3Mgd2hhdCBkb2VzIHRoaXMgbWVhbj8KI2luY2x1ZGUgPG1lc3NhZ2Uua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heE4gMTMKI2RlZmluZSBvbyAyMDAwMDAwMDAwMDAwMDAwMDA3TEwKCnRlbXBsYXRlIDxjbGFzcyBUPgpUIG1pbihUIGEsIFQgYiwgVCBjKSB7CiAgICByZXR1cm4gbWluKGEsIG1pbihiLCBjKSk7Cn0KCnRlbXBsYXRlIDxjbGFzcyBUPgpUIG1heChUIGEsIFQgYiwgVCBjKSB7CiAgICByZXR1cm4gbWF4KGEsIG1heChiLCBjKSk7Cn0KCmludCBtYWluKCkgewogICAgaW50IE4gPSBHZXROKCk7CiAgICBpbnQgbm9kZXMgPSBOdW1iZXJPZk5vZGVzKCk7CiAgICBpbnQgbXlfaWQgPSBNeU5vZGVJZCgpOwoKICAgIGxsIG1heFggPSAtb28sIG1pblggPSBvbzsKICAgIGZ0b2EoaiwgbXlfaWQsIE4tMSwgbm9kZXMpIHsKICAgICAgICBtYXhYID0gbWF4KG1heFgsIEdldE51bWJlcihqKSk7CiAgICAgICAgbWluWCA9IG1heChtaW5YLCBHZXROdW1iZXIoaikpOwogICAgfQogICAgUHV0TEwoTUFTVEVSX05PREUsIG1pblgpOwogICAgUHV0TEwoTUFTVEVSX05PREUsIG1heFgpOwogICAgUHV0TEwoTUFTVEVSX05PREUsIERPTkUpOwogICAgU2VuZChNQVNURVJfTk9ERSk7CgogICAgaWYgKG15X2lkID09IE1BU1RFUl9OT0RFKSB7CiAgICAgICAgbGwgbWF4WCA9IC1vbywgbWluWCA9IG9vOwogICAgICAgIGZ0byhub2RlLCAwLCBub2Rlcy0xKSB7CiAgICAgICAgICAgIHdoaWxlICh0cnVlKSB7CiAgICAgICAgICAgICAgICBSZWNlaXZlKC0xKTsKICAgICAgICAgICAgICAgIGxsIHggPSBHZXRMTChub2RlKTsKICAgICAgICAgICAgICAgIGlmICh4ID09IERPTkUpIGJyZWFrOwogICAgICAgICAgICAgICAgZWxzZSB7CiAgICAgICAgICAgICAgICAgICAgbWluWCA9IG1pbihtaW5YLCB4KTsKICAgICAgICAgICAgICAgICAgICBtYXhYID0gbWF4KG1heFgsIHgpOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICB9CiAgICAgICAgfQoKICAgICAgICBwcmludGYoIiVsbGRcbiIsIG1heFgtbWluWCk7CiAgICB9CgogICAgcmV0dXJuIDA7Cn0K