#include <iostream>
using namespace std;
#include <stdio.h> // C style input and output
#define ARRAY_SIZE(a) (sizeof(a)/sizeof(a[0]))
// largest value <= key
// Invariant: A[l] <= key and A[r] > key
// Boundary: |r - l| = 1
// Input: A[l .... r-1]
// Precondition: A[l] <= key <= A[r]
int Floor(int A[], int l, int r, int key) {
int m;
while( r - l > 1 ) {
m = l + (r - l)/2;
if( A[m] <= key )
l = m;
else
r = m;
}
return A[l];
}
int Floor(int A[], int size, int key) {
// Error checking
if( key < A[0] )
return -1; // There is no floor value
return Floor(A, 0, size, key);
}
void TestCase_01() {
int A[] = { 1, 3, 4, 7, 9, 13, 18, 23 };
int size = ARRAY_SIZE(A);
int key;
scanf("%d", &key);
while( key != -1 ) {
printf("%d\n", Floor(A, size, key));
scanf("%d", &key);
}
}
int main() {
TestCase_01();
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKI2luY2x1ZGUgPHN0ZGlvLmg+IC8vIEMgc3R5bGUgaW5wdXQgYW5kIG91dHB1dAoKI2RlZmluZSBBUlJBWV9TSVpFKGEpIChzaXplb2YoYSkvc2l6ZW9mKGFbMF0pKQoKLy8gbGFyZ2VzdCB2YWx1ZSA8PSBrZXkKLy8gSW52YXJpYW50OiAgIEFbbF0gPD0ga2V5IGFuZCBBW3JdID4ga2V5Ci8vIEJvdW5kYXJ5OiAgICB8ciAtIGx8ID0gMQovLyBJbnB1dDogICAgICAgQVtsIC4uLi4gci0xXQovLyBQcmVjb25kaXRpb246IEFbbF0gPD0ga2V5IDw9IEFbcl0KaW50IEZsb29yKGludCBBW10sIGludCBsLCBpbnQgciwgaW50IGtleSkgewogICAgaW50IG07CgogICAgd2hpbGUoIHIgLSBsID4gMSApIHsKICAgICAgICBtID0gbCArIChyIC0gbCkvMjsKCiAgICAgICAgaWYoIEFbbV0gPD0ga2V5ICkKICAgICAgICAgICAgbCA9IG07CiAgICAgICAgZWxzZQogICAgICAgICAgICByID0gbTsKICAgIH0KCiAgICByZXR1cm4gQVtsXTsKfQoKaW50IEZsb29yKGludCBBW10sIGludCBzaXplLCBpbnQga2V5KSB7CiAgICAvLyBFcnJvciBjaGVja2luZwogICAgaWYoIGtleSA8IEFbMF0gKQogICAgICAgIHJldHVybiAtMTsgLy8gVGhlcmUgaXMgbm8gZmxvb3IgdmFsdWUKCiAgICByZXR1cm4gRmxvb3IoQSwgMCwgc2l6ZSwga2V5KTsKfQoKdm9pZCBUZXN0Q2FzZV8wMSgpIHsKICAgIGludCBBW10gPSB7IDEsIDMsIDQsIDcsIDksIDEzLCAxOCwgMjMgfTsKICAgIGludCBzaXplID0gQVJSQVlfU0laRShBKTsKCiAgICBpbnQga2V5OwoKICAgIHNjYW5mKCIlZCIsICZrZXkpOwoKICAgIHdoaWxlKCBrZXkgIT0gLTEgKSB7CiAgICAgICAgcHJpbnRmKCIlZFxuIiwgRmxvb3IoQSwgc2l6ZSwga2V5KSk7CiAgICAgICAgc2NhbmYoIiVkIiwgJmtleSk7CiAgICB9Cn0KCmludCBtYWluKCkgewogICAgVGVzdENhc2VfMDEoKTsKICAgIAogICAgcmV0dXJuIDA7Cn0K