text: // DRUNKWATER TEMPLATE(add description and prototypes)
  // Question Title and Description on leetcode.com
  // Function Declaration and Function Prototypes on leetcode.com
  //174. Dungeon Game
  //The demons had captured the princess (P) and imprisoned her in the bottom-right corner of a dungeon. The dungeon consists of M x N rooms laid out in a 2D grid. Our valiant knight (K) was initially positioned in the top-left room and must fight his way through the dungeon to rescue the princess.
  //The knight has an initial health point represented by a positive integer. If at any point his health point drops to 0 or below, he dies immediately.
  //Some of the rooms are guarded by demons, so the knight loses health (negative integers) upon entering these rooms; other rooms are either empty (0's) or contain magic orbs that increase the knight's health (positive integers).
  //In order to reach the princess as quickly as possible, the knight decides to move only rightward or downward in each step.
  //  Write a function to determine the knight's minimum initial health so that he is able to rescue the princess.
  //For example, given the dungeon below, the initial health of the knight must be at least 7 if he follows the optimal path RIGHT-> RIGHT -> DOWN -> DOWN.
  //-2 (K) -3 3
  //-5 -10 1
  //10 30 -5 (P)
  //Notes:
  //The knight's health has no upper bound.
  //Any room can contain threats or power-ups, even the first room the knight enters and the bottom-right room where the princess is imprisoned.
  //  Credits:
  //Special thanks to @stellari for adding this problem and creating all test cases.
  //int calculateMinimumHP(int** dungeon, int dungeonRowSize, int dungeonColSize) {
  //}
  
  
  
  #include<stdio.h>
  #include<stdlib.h>
  #include<string.h>
  #include<stdint.h>
  
  
  #include<time.h>
  
  
  #include<limits.h>
  #include<math.h>
  
  
  
  /* import kernel list in user space */
  #include"list.h"
  
  
  
  /**
   * Note: The returned array must be malloced, assume caller calls free().
   */
  
  int* twoSum(int* nums, int numsSize, int target) {
  	/* sanity check */
  	int *p = NULL;
  
  
  
  	return p;
  }
  
  
  void printTime(void)
  {
  	/* sanity check */
  	time_t rawtime;
  	struct tm *timeinfo;
  
  	time ( &rawtime );
  	timeinfo = localtime ( &rawtime );
  	printf ( "\n Current date and time is : %s\n", asctime (timeinfo) );
  }
  
  
  static union
  {
  	char c[4];
  	unsigned long l;
  } endian_test = {{'l', '?', '?', 'b'}};
  
  #define ENDIANNESS ((char)endian_test.l)
  
  void dprint_platform(void)
  {
  	/* sanity check */
  
  	fprintf(stderr, "  int8_t = %ld \n", sizeof(int8_t));
  	fprintf(stderr, " uint8_t = %ld \n", sizeof(uint8_t));
  	fprintf(stderr, " int16_t = %ld \n", sizeof(int16_t));
  	fprintf(stderr, "uint16_t = %ld \n", sizeof(uint16_t));
  	fprintf(stderr, " int32_t = %ld \n", sizeof(int32_t));
  	fprintf(stderr, "uint32_t = %ld \n", sizeof(uint32_t));
  	fprintf(stderr, " int64_t = %ld \n", sizeof(int64_t));
  	fprintf(stderr, "uint64_t = %ld \n", sizeof(uint64_t));
  
  
  	fprintf(stderr, "ENDIANNESS=%c \n", ENDIANNESS);
  
  
  
  	int n = 0x04030201;
  	if (*(char *)&n == 0x01)
  	{
  		fprintf(stderr, "little endian\n");
  	}
  	else
  	{
  		fprintf(stderr, "   big endian\n");
  	}
  
  
  	fprintf(stderr, "\n\n");
  }
  
  
  
  void test_list(void)
  {
  	typedef struct
  	{
  		struct list_head entry;
  		int data;
  	
  	}STACK_T;
  
  	/* sanity check */
  	fprintf(stderr, "\n[%s]%s : %d, enter \n\n",  __TIME__" "__DATE__, __FILE__, __LINE__);
  
  
  	LIST_HEAD(stack);
  	STACK_T *e = NULL;
  	int i=0;
  
  	for (i=0; i<10; i++)
  	{
  		e = (STACK_T *)malloc(sizeof(STACK_T));
  		if(NULL == e)
  		{
  			fprintf(stderr, "malloc failed!");
  			return;
  		}
  		e->data = (i + 1);
  		list_add(&(e->entry), &stack);
  		fprintf(stderr, "[%d]data=%d\n", i, (e->data));
  	}
  
  	if (list_empty(&stack))
  	{
  		fprintf(stderr, "list_empty\n");
  	}
  
  	fprintf(stderr, "\n dump stack \n");
  	i = 0;
  	list_for_each_entry(e, &stack, entry)
  	{
  		fprintf(stderr, "[%d]data=%d\n", i, (e->data));
  		i++;
  	}
  
  
  	fprintf(stderr, "\n reverse dump stack \n");
  	i = 0;
  	list_for_each_entry_reverse(e, &stack, entry)
  	{
  		fprintf(stderr, "[%d]data=%d\n", i, (e->data));
  		i++;
  	}
  
  
  	fprintf(stderr, "\n free stack \n");
  	i=0;
  	struct list_head *pos, *next;
  	list_for_each_safe(pos, next, &stack)
  	{
  		e = list_entry(pos, STACK_T, entry);
  		fprintf(stderr, "[%d]data=%d\n", i, (e->data));
  
  		list_del_init(pos);
  		free(e);
  		e=NULL;
  		i++;
  	}
  
  
  	fprintf(stderr, "\n[%s]%s : %d, leave \n\n",  __TIME__" "__DATE__, __FILE__, __LINE__);
  }
  
  
  
  int main( int argc, char *argv[] )
  {
  	/* sanity check */
  	fprintf(stderr, "\n[%s]%s : %d, enter \n\n",  __TIME__" "__DATE__, __FILE__, __LINE__);
  	printTime();
  
  
  	struct timespec start,end;	/* seconds and nanoseconds */
  	clock_gettime(CLOCK_MONOTONIC, &start);
  	fprintf(stderr, "\n [start]%lu, %lu \n\n",  start.tv_sec, start.tv_nsec);
  
  	time_t s,e;
  	s=time(NULL);
  
  
  
  	/* add your codes here */
  	//dprint_platform();
  	//test_list();
  
  
  
  
  
  
  
  
  
  
  
  #if 0/* disable 'no operation' */
  	int i = 0;
  	for(i=0;i<0xCFFFFFFF;i++)
  	{
  		//fprintf(stderr, "*");
  		asm("nop ; nop ; nop ; nop");
  	}
  #endif
  
  
  	e=time(NULL);
  	fprintf(stderr, "\n Worked time is : %6.6f\n\n",difftime(e, s));
  
  
  	clock_gettime(CLOCK_MONOTONIC, &end);
  	fprintf(stderr, "\n [  end]%lu, %lu \n\n",  end.tv_sec, end.tv_nsec);
  
  
  	printTime();
  
  
  
  	fprintf(stderr, "\n[%s]%s : %d, leave \n\n",  __TIME__" "__DATE__, __FILE__, __LINE__);
  	return 0;
  }
  