#include <stdio.h>
#include <stdlib.h>
#include <limits.h>

unsigned int multiply (unsigned short a, unsigned short b)
{
  unsigned int result = 0;
  char negflag = 0;
  
  if ( (a < 0) != (b < 0) )
  {
    negflag++;
    a &= 0b0111111111111111;
    b &= 0b0111111111111111;
  }
  char n = 0;
  while ( b >= (1 << (n))  )
  {
    if ( b & (1 << n) )
      result += a << n;
    n++;
  }
  return result;
}

int main(void)
{

  unsigned short a, b;
  //scanf("%hi%hi", &a, &b);
  a = 1;
  b = 1;

  //это типа такое юнит-тестирование. Если оно зависает, значит все норм
  while (multiply(a, b) == a * b)
  {
    if (SHRT_MIN == a)
    {
      b++;
    }
    a++;
    // fprintf(stderr," %i : %i", a,b);
  }
  fprintf(stderr,"my: %i ; norm: %i\n", multiply(a, b), a * b);

  return 0;
}
