Problem p00256 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cctype>
#include <cstdio>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;
long long n[5];
long long ma[5] = {144000, 7200, 360, 20, 1};
long long tuki[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
long long p = 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + 21;
int seireki() {
  long long ans[6] = {0};
  long long kin = 0;
  int i, j;
  /*for(i=0;i<5;i++){
          cout<<n[i]<<endl;
  }*/
  kin = 0;
  for (i = n[0] - 1; i >= 2012; i--) {
    if (i % 4 == 0 && i % 100 != 0 || i % 4 == 0 && i % 400 == 0) {
      kin += 366;
    } else {
      kin += 365;
    }
  }
  for (i = n[1] - 1; i >= 1; i--) {
    kin += tuki[i];
  }
  if (n[0] % 4 == 0 && n[0] % 100 != 0 || n[0] % 4 == 0 && n[0] % 400 == 0) {
    if (n[1] >= 3) {
      kin++;
    }
  }
  kin += n[2];
  kin -= p;
  kin %= 1872000;
  for (i = 0; i < 5; i++) {
    ans[i] = kin / ma[i];
    kin %= ma[i];
  }
  for (i = 0; i < 5; i++) {
    cout << ans[i];
    if (i < 4) {
      cout << ".";
    } else {
      cout << endl;
    }
  }
}
void maya(void) {
  long long ans[3];
  long long kin = 0;
  int i, j;
  /*for(i=0;i<5;i++){
          kin=kin+n[i]*ma[i];
  }*/
  kin = kin + n[0] * 144000;
  kin = kin + n[1] * 7200;
  kin = kin + n[2] * 360;
  kin = kin + n[3] * 20;
  kin += n[4];
  ans[0] = 2012;
  ans[1] = 12;
  ans[2] = 21;
  // cout<<kin<<endl;
  while (kin--) {
    ans[2]++;
    if (ans[2] > tuki[ans[1]] + (ans[1] == 2 &&
                                 (ans[0] % 400 == 0 ||
                                  (ans[0] % 4 == 0 && ans[0] % 100 != 0)))) {
      ans[1]++;
      ans[2] = 1;
    }
    if (ans[1] > 12) {
      ans[0]++;
      ans[1] = 1;
    }
  }
  printf("%lld.%lld.%lld\\n", ans[0], ans[1], ans[2]);
}
int main() {
  char koyomi[50];
  int i, j;
  while (1) {
    cin >> koyomi;
    if (koyomi[0] == '#') {
      break;
    }
    memset(n, 0, sizeof(n));
    j = 0;
    // out<<strlen(koyomi)<<endl;
    for (i = 0; i < strlen(koyomi); i++) {
      if (koyomi[i] == '.') {
        j++;
      }
    }
    // printf("%lld.%lld.%lld.%lld.%lld\\n",n[0],n[1],n[2],n[3],n[4]);
    if (j == 2) {
      sscanf(koyomi, "%lld.%lld.%lld", &n[0], &n[1], &n[2]);
      seireki();
    } else {
      sscanf(koyomi, "%lld.%lld.%lld.%lld.%lld", &n[0], &n[1], &n[2], &n[3],
             &n[4]);
      maya();
    }
  }
  return 0;
}


Error: -11

Fixed submission:

#include <iostream>
#include <stdlib.h>
#include <string.h>
#include <time.h>
using namespace std;
struct tm T;
struct tm *a;
int maya[5] = {144000, 7200, 360, 20, 1};
int sugi[5] = {1, 20, 20, 18, 20};
int main() {
  time_t tt, kin, ans, s = 1356015600;
  char koyomi[50];
  int i;
  long long n[5] = {0};
  while (1) {
    cin >> koyomi;
    if (koyomi[0] == '#') {
      break;
    }
    memset(n, 0, sizeof(n));
    n[0] = atoi(strtok(koyomi, "."));
    for (i = 1; i < 5; i++) {
      n[i] = atoi(strtok(NULL, "."));
    }
    if (n[0] >= 2012) {
      T.tm_year = n[0] - 1900;
      T.tm_mon = n[1] - 1;
      T.tm_mday = n[2];
      tt = (mktime(&T) - s) / 86400 % 1872000;
      // cout<<tt<<endl;
      for (i = 0; i < 5; i++) {
        if (i > 0) {
          cout << ".";
        }
        if (i > 0) {
          cout << tt / maya[i];
        } else {
          cout << tt / maya[i] % sugi[i];
        }
      }
      cout << endl;
    }
  }
  return 0;
}