/*
Copyright 2011 Marek "p2004a" Rusinowski
Merge sort
*/
#include <cstdio>
#define MAXN 1000000
int array[ MAXN] ;
int tmp_array[ MAXN] ;
void merge( int * begin, int * center, int * end) {
int * i1 = begin, * i2 = center, i = 0 ;
while ( i1 ! = center || i2 ! = end) {
if ( ( ( * i1 < * i2) || ( i2 == end) ) && ( i1 ! = center) ) {
tmp_array[ i++ ] = * ( i1++ ) ;
} else {
tmp_array[ i++ ] = * ( i2++ ) ;
}
}
for ( int j = 0 ; begin ! = end; ++ j) {
* ( begin++ ) = tmp_array[ j] ;
}
}
void sort( int * begin, int * end) {
if ( begin + 1 >= end) return ;
int * center = ( end - begin) / 2 + begin;
sort( begin, center) ;
sort( center, end) ;
merge( begin, center, end) ;
}
int main( ) {
int n;
scanf ( "%d" , & n) ;
for ( int i = 0 ; i < n; ++ i) {
scanf ( "%d" , & array[ i] ) ;
}
sort( array, array + n) ;
for ( int i = 0 ; i < n; ++ i) {
printf ( "%d " , array[ i] ) ;
}
printf ( "\n " ) ;
return 0 ;
}
LyoKICBDb3B5cmlnaHQgMjAxMSBNYXJlayAicDIwMDRhIiBSdXNpbm93c2tpCiAgTWVyZ2Ugc29ydAoqLwojaW5jbHVkZSA8Y3N0ZGlvPgoKI2RlZmluZSBNQVhOIDEwMDAwMDAKCmludCBhcnJheVtNQVhOXTsKaW50IHRtcF9hcnJheVtNQVhOXTsKCnZvaWQgbWVyZ2UoaW50ICpiZWdpbiwgaW50ICpjZW50ZXIsIGludCAqZW5kKSB7CiAgaW50ICppMSA9IGJlZ2luLCAqaTIgPSBjZW50ZXIsIGkgPSAwOwogIHdoaWxlIChpMSAhPSBjZW50ZXIgfHwgaTIgIT0gZW5kKSB7CiAgICBpZiAoKCgqaTEgPCAqaTIpIHx8IChpMiA9PSBlbmQpKSAmJiAoaTEgIT0gY2VudGVyKSkgewogICAgICB0bXBfYXJyYXlbaSsrXSA9ICooaTErKyk7CiAgICB9IGVsc2UgewogICAgICB0bXBfYXJyYXlbaSsrXSA9ICooaTIrKyk7CiAgICB9CiAgfQogIGZvciAoaW50IGogPSAwOyBiZWdpbiAhPSBlbmQ7ICsraikgewogICAgKihiZWdpbisrKSA9IHRtcF9hcnJheVtqXTsKICB9Cn0KCnZvaWQgc29ydChpbnQgKmJlZ2luLCBpbnQgKmVuZCkgewogIGlmIChiZWdpbiArIDEgPj0gZW5kKSByZXR1cm47CiAgaW50ICpjZW50ZXIgPSAoZW5kIC0gYmVnaW4pIC8gMiArIGJlZ2luOwogIHNvcnQoYmVnaW4sIGNlbnRlcik7CiAgc29ydChjZW50ZXIsIGVuZCk7CiAgbWVyZ2UoYmVnaW4sIGNlbnRlciwgZW5kKTsKfQoKaW50IG1haW4oKSB7CiAgaW50IG47CiAgc2NhbmYoIiVkIiwgJm4pOwogIGZvciAoaW50IGkgPSAwOyBpIDwgbjsgKytpKSB7CiAgICBzY2FuZigiJWQiLCAmYXJyYXlbaV0pOwogIH0KICBzb3J0KGFycmF5LCBhcnJheSArIG4pOwogIGZvciAoaW50IGkgPSAwOyBpIDwgbjsgKytpKSB7CiAgICBwcmludGYoIiVkICIsIGFycmF5W2ldKTsKICB9CiAgcHJpbnRmKCJcbiIpOwogIHJldHVybiAwOwp9Cg==
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:36: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result
prog.cpp:38: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result
stdout