alexjercan/bugnet huggingface dataset:
Problem p00017 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <stack>
#include <string>
#include <vector>

using namespace std;

int main() {
  string tmp;
  string key[] = {"the", "this", "that"};
  int alfabet;
  bool clearFlag;
  while (getline(cin, tmp)) {
    clearFlag = false;
    alfabet = 26;
    while (alfabet--) {

      for (string::iterator it = tmp.begin(); it != tmp.end(); it++) {
        if (*it == '\\n') {
          it = tmp.erase(it);
        }
        if (*it >= 'a' && *it <= 'z') {
          (*it)++;
          if (*it > 'z') {
            *it = 'a';
          }
        }
      }
      for (int j = 0; j < 3; j++) {
        if (tmp.find(key[j]) != string::npos) {
          cout << tmp << endl;
          clearFlag = true;
          break;
        }
      }

      if (clearFlag == true) {
        break;
      }
    }
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <stack>
#include <string>
#include <vector>

using namespace std;

int main() {
  string tmp;
  string key[] = {"the", "this", "that"};
  int alfabet = 26;
  bool clearFlag;
  while (getline(cin, tmp)) {
    clearFlag = false;

    while (alfabet--) {

      for (string::iterator it = tmp.begin(); it != tmp.end(); it++) {
        if (*it >= 'a' && *it <= 'z') {
          (*it)++;
          if (*it >= 'z') {
            *it = 'a';
          }
        }
      }
      for (int j = 0; j < 3; j++) {
        if (tmp.find(key[j]) != string::npos) {
          cout << tmp << endl;
          clearFlag = true;
          break;
        }
      }

      if (clearFlag == true) {
        break;
      }
    }
  }
  return 0;
}
Problem p00017 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <ctype.h>
#include <iostream>
#include <string>

using namespace std;

string slide(string s) {
  string r = s;
  for (int i = 0; i < r.length(); i++) {
    if (islower(r[i])) {
      if (r[i] == 'z')
        r[i] = 'a';
      else
        r[i] += 1;
    }
  }
  return r;
}

bool check_word(string s) {
  string dic[3] = {"this", "the", "that"};
  for (int i = 0; i < 3; i++)
    if (s.find(dic[i]) != string::npos)
      return true;
  return false;
}

int main() {
  string in, temp;
  bool found;
  while (1) {
    getline(cin, in);
    if (cin.eof())
      break;
    for (temp = in, found = false;; temp = slide(temp)) {
      found = check_word(temp);
      if (found)
        break;
    }
    cout << temp << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <sstream>
#include <string>

using namespace std;

string slide(string s) {
  string r = s;
  for (int i = 0; i < r.length(); i++) {
    if (islower(r[i])) {
      if (r[i] == 'z')
        r[i] = 'a';
      else
        r[i] += 1;
    }
  }
  return r;
}

bool check_word(string s) {
  string dic[3] = {"this", "the", "that"};
  stringstream ss;
  string word;
  ss << s;
  for (int i = 0; i < 3; i++) {
    ss >> word;
    if (dic[i] == word)
      return true;
  }
  return false;
}

int main() {
  string in, temp;
  bool found;
  while (!cin.eof()) {
    getline(cin, in);
    for (temp = in, found = false;; temp = slide(temp)) {
      found = check_word(temp);
      if (found)
        break;
    }
    cout << temp << endl;
  }
  return 0;
}
Problem p00017 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int main() {

  char a[1000];
  while (scanf("%[^\\n]", a) != EOF) {
    getchar();
    bool flg = 0;
    for (int i = 0; i < 26; i++) {
      unsigned char ans[1000] = {0};
      for (int j = 0; j < strlen(a); j++) {
        if (a[j] == ' ' || a[j] == '.')
          ans[j] = a[j];
        else
          ans[j] = a[j] + i;
        if (ans[j] > 'z')
          ans[j] -= 26;
      }
      for (int j = 0; j < strlen(a); j++) {
        if (ans[j] == 't' && ans[j + 1] == 'h') {
          if (ans[j + 2] == 'e' && ans[j + 3] == ' ' || ans[j + 3] == 0 ||
              ans[j + 3] == '.')
            flg = 1;
          if (ans[j + 2] == 'i' && ans[j + 3] == 's' && ans[j + 4] == ' ' ||
              ans[j + 4] == 0 || ans[j + 4] == '.')
            flg = 1;
          if (ans[j + 2] == 'a' && ans[j + 3] == 't' && ans[j + 4] == ' ' ||
              ans[j + 4] == 0 || ans[j + 4] == '.')
            flg = 1;
        }
        if (flg) {
          if (j == 0) {
            cout << ans << endl;
            goto end;
          } else {
            if (ans[j - 1] == ' ') {
              cout << ans << endl;
              goto end;
            }
          }
        }
      }
    }
  end:;
    for (int i = 0; i < 1000; i++)
      a[i] = 0;
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int main() {

  char a[1000];
  while (scanf("%[^\\n]", a) != EOF) {
    bool flg = 0;
    for (int i = 1; i < 26; i++) {
      unsigned char ans[1000] = {0};
      for (int j = 0; j < strlen(a); j++) {
        if (a[j] == ' ' || a[j] == '.')
          ans[j] = a[j];
        else
          ans[j] = a[j] + i;
        if (ans[j] > 'z')
          ans[j] -= 26;
      }
      for (int j = 0; j < strlen(a); j++) {
        if (ans[j] == 't' && ans[j + 1] == 'h') {
          if (ans[j + 2] == 'e' && ans[j + 3] == ' ')
            flg = 1;
          if (ans[j + 2] == 'i' && ans[j + 3] == 's' && ans[j + 4] == ' ')
            flg = 1;
          if (ans[j + 2] == 'a' && ans[j + 3] == 't' && ans[j + 4] == ' ')
            flg = 1;
        }
        if (flg) {
          if (j == 0) {
            cout << ans << endl;
            goto end;
          } else {
            if (ans[j - 1] == ' ') {
              cout << ans << endl;
              goto end;
            }
          }
        }
      }
    }
  end:;
    fflush(stdin);
  }

  return 0;
}
Problem p00017 (C++) — buggy submission, verdict: Runtime Error

#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <sstream>
#include <string>

using namespace std;

string rotate(string str) {
  for (int i = 0; i < str.size(); i++) {
    if ('a' <= str[i] && str[i] < 'z')
      str[i]++;
    else if (str[i] == 'z')
      str[i] = 'a';
  }
  return str;
}

int main() {
  string str;
  while (getline(cin, str)) {
    for (int i = 0; i < 26; i++) {
      str = rotate(str);
      /*
      string tmp;
      bool flg = false;
      for (int i = 0; i < str.size(); i++) {
          if (str[i] != '.')tmp += str[i];
      }
      stringstream ss(tmp);
      while(ss >> tmp) {
          if (tmp == "the" || tmp == "this" || tmp == "that")flg = true;
          break;
      }
      if (flg) {
          cout << str << endl;
          break;
      }
      */
      if (str.find("the") != string::npos || str.find("this") != string::npos ||
          str.find("that") != string::npos) {
        cout << str << endl;
        break;
      }
    }
  }
  return 0;
}

Error: 0

Fixed submission:

#include <cmath>
#include <complex>
#include <cstdio>
#include <iostream>
#include <sstream>
#include <string>

using namespace std;

string rotate(string str) {
  for (int i = 0; i < str.size(); i++) {
    if ('a' <= str[i] && str[i] < 'z')
      str[i]++;
    if (str[i] == 'z')
      str[i] = 'a';
  }
  return str;
}

int main() {
  string str;
  while (getline(cin, str)) {
    for (int i = 0; i < 26; i++) {
      str = rotate(str);
      string tmp;
      bool flg = false;
      for (int i = 0; i < str.size(); i++) {
        if (str[i] != '.')
          tmp += str[i];
      }
      stringstream ss(tmp);
      while (ss >> tmp) {
        if (tmp == "the" || tmp == "this" || tmp == "that")
          flg = true;
        break;
      }
      if (flg) {
        cout << str << endl;
        break;
      }
      if (i == 25)
        return 1;
    }
  }
  return 0;
}
Problem p00017 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <list>
#include <map>
#include <stdio.h>
#include <string.h>
#include <vector>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) range(i, 0, b)
#define debug(x) cout << x << endl;
using namespace std;

int main() {
  string s;
  int i, j;

  while (getline(cin, s)) {
    while (s.find("the") == s.npos && s.find("this") == s.npos &&
           s.find("that") == s.npos) {
      for (i = 0; s[i]; i++) {
        if (s[i] >= 'a' && s[i] <= 'z')
          s[i]++;
        if (s[i] == 'z' + 1) {
          s[i] = 'a';
        }
      }
    }
    cout << s << endl;
  }
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <list>
#include <map>
#include <stdio.h>
#include <string.h>
#include <vector>
#define range(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, b) range(i, 0, b)
#define debug(x) cout << x << endl;
using namespace std;

int main() {
  string s;
  int i, j;
  bool check;

  while (getline(cin, s)) {
    check = true;
    while (check) {
      i = 0;
      while (s[i] >= 'a' && s[i] <= 'z') {
        s[i]++;
        if (s[i] == 'z' + 1) {
          s[i] = 'a';
        }
        i++;
      }
      if (s.find("the") != s.npos || s.find("this") != s.npos ||
          s.find("that") != s.npos) {
        check = false;
      }
    }
    cout << s << endl;
  }
}
Problem p00017 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cctype>
#include <iostream>
#include <string>

using namespace std;

void CaesarCipher(const string &);
int main() {
  string str;
  while (getline(cin, str)) {
    CaesarCipher(str);
  }
}

void CaesarCipher(const string &str) {
  string diffstr = str;
  int diff = 1;
  while (diffstr.find("the") == string::npos &&
         diffstr.find("this") == string::npos &&
         diffstr.find("that") == string::npos) {
    for (int i = 0; i < str.length(); i++) {
      if (!isalpha(str[i]))
        continue;
      diffstr[i] = (diff + str[i] - 'a') % 26 + 'a';
    }
    diff++;
  }
  cout << diffstr << endl;
}

Error: TLE

Fixed submission:

#include <cctype>
#include <iostream>
#include <string>

using namespace std;

void CaesarCipher(const string &);
int main() {
  string str;
  while (getline(cin, str)) {
    CaesarCipher(str);
  }
}

void CaesarCipher(const string &str) {
  string diffstr = str;
  while (diffstr.find("the") == string::npos &&
         diffstr.find("this") == string::npos &&
         diffstr.find("that") == string::npos) {
    for (int i = 0; i < str.length(); i++) {
      diffstr[i] += isalpha(str[i]) ? 1 : 0;
    }
  }
}
Problem p00017 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <string>
using namespace std;

int main() {
  string str;
  while (getline(cin, str)) {
    for (int j = 0; j < 26; j++) {
      if (str.find("the") != string::npos || str.find("this") != string::npos ||
          str.find("that") != string::npos) {
        cout << str << endl;
        break;
      }
      for (unsigned int i = 0; i < str.size(); i++) {
        if (str[i] <= 'z' && 'a' <= str[i]) {
          str[i] -= 97;
          str[i]++;
          str[i] %= 26;
          str[i] += 97;
        }
      }
    }
  }
}

Error: 0

Fixed submission:

#include <iostream>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

int main() {
  string str, s;
  int key, word;
  vector<string> seq;
  char decode[4], ans;
  while (getline(cin, str)) {
    seq.clear();
    stringstream ss;
    ss << str;
    while (ss >> s) {
      seq.push_back(s);
    }
    ss.str("");
    ss.clear(stringstream::goodbit);

    word = seq.size();
    key = 100;

    for (int i = 0; i < word; i++) {

      decode[0] = *seq[i].substr(0, 1).c_str();
      decode[1] = *seq[i].substr(1, 1).c_str();
      decode[2] = *seq[i].substr(2, 1).c_str();
      decode[3] = *seq[i].substr(3, 1).c_str();

      for (int j = 1; j < 27; j++) {
        for (int k = 0; k < 4; k++) {
          decode[k] -= 97; // a-z 0-25
          decode[k]++;     // 1-26
          decode[k] %= 26; // 0-25
          decode[k] += 97; // 97-122
        }
        if ((decode[0] == 't' && decode[1] == 'h' && decode[2] == 'e') &&
            (seq[i].size() == 3)) {
          key = j;
          break;
        }
        if ((decode[0] == 't' && decode[1] == 'h' && decode[2] == 'i' &&
             decode[3] == 's') &&
            (seq[i].size() == 4)) {
          key = j;
          break;
        }
        if ((decode[0] == 't' && decode[1] == 'h' && decode[2] == 'a' &&
             decode[3] == 't') &&
            (seq[i].size() == 4)) {
          key = j;
          break;
        }
      }

      if (key != 100)
        break;
    }

    for (int i = 0; i < word; i++) {
      for (unsigned int j = 0; j < seq[i].size(); j++) {
        ans = *seq[i].substr(j, 1).c_str();
        if (ans <= 'z' && 'a' <= ans) {
          ans -= 97;
          ans += key;
          ans %= 26;
          ans += 97;
        }
        cout << ans;
      }
      if (i == word - 1) {
        break;
      }
      cout << " ";
    }
    cout << endl;
  }
}
Problem p00017 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <cstring>
#include <iostream>

#define REP(n) for (int i = 0; i < n; i++)

using namespace std;

int main() {
  char a[100];

  while (NULL != fgets(a, 80, stdin)) {
    int n = strlen(a);

    while (NULL == strstr(a, "the") && NULL == strstr(a, "this") &&
           NULL == strstr(a, "that")) {
      REP(n) {
        if ('a' <= a[i] && a[i] < 'z')
          a[i]++;
        else if ('z' == a[i])
          a[i] = 'a';
      }
    }

    printf("%s", a);
  }

  return 0;
}

Error: WA

Fixed submission:

#include <cstdio>

using namespace std;

char shiftch(char p, int n) {
  int t;
  if ('A' <= p && p <= 'Z') {
    p -= 'A';
    if (n < 0)
      n += 26;
    p += n;
    p %= 26;
    p += 'A';
    return p;
  } else if ('a' <= p && p <= 'z') {
    p -= 'a';
    if (n < 0)
      n += 26;
    p += n;
    p %= 26;
    p += 'a';
    return p;
  } else
    return p;
}

int main() {

  int i, j, n;
  char in[1000], *p, *tp;
  p = in;

  //	scanf("%[^\\n]", in);
  fgets(in, 1000, stdin);
  for (n = 0; 16 <= in[n] && in[n] <= 126; n++)
    ;

  while (1) {
    tp = p;
    for (i = 0; *(p++) != ' '; i++)
      ;
    if (i == 3 || i == 4) {

      j = *tp - 't';
      if (*(tp + 1) == 'h' + j)
        break;
      j = *tp - 'T';
      if (*(tp + 1) == 'h' + j) {
        j += 'a' - 'A';
        break;
      }
    }
  }
  for (i = 0; i < n; i++)
    in[i] = shiftch(in[i], -j);

  printf("%s\\n", in);

  return 0;
}
Problem p00017 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
using namespace std;
int main() {
  string w[3] = {"the", "this", "that"}, st;
  int wn[3] = {3, 4, 4}, k, i, j, s, f;
  while (getline(cin, st)) {
    k = 0;
    while (k < st.size()) {
      for (i = 0; i < 3; i++) {
        s = 0;
        f = 0;
        if (st.size() < k + wn[i])
          break;
        for (j = 0; j < wn[i] - 1; j++)
          if (((w[i][j] - w[i][j + 1] + 26) % 26) ==
              ((st[k + j] - st[k + j + 1] + 26) % 26))
            s++;
        if (s == wn[i] - 1) {
          f = 1;
          i = 5;
        }
      }
      if (f == 1)
        break;
      for (k; st[k] >= 'a' && st[k] <= 'z'; k++)
        ;
      k++;
    }
    if (f == 0)
      cout << st;
    else {
      for (i = 0; i < st.size(); i++)
        if ((st[i] >= 'a' && st[i] <= 'z'))
          cout << (char)(((st[i] - st[k] + 't') - 97 + 26) % 26 + 97);
        else
          cout << st[i];
    }
    cout << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
using namespace std;
int main() {
  string w[3] = {"the", "this", "that"}, st;
  int wn[3] = {3, 4, 4}, k, i, j, s, f;
  while (true) {
    k = 0;
    getline(cin, st);
    while (k < st.size()) {
      for (i = 0; i < 3; i++) {
        s = 0;
        f = 0;
        if (st.size() < k + wn[i])
          break;
        for (j = 0; j < wn[i] - 1; j++)
          if ((w[i][j] - w[i][j + 1]) == (st[k + j] - st[k + j + 1]))
            s++;
        if (s == wn[i] - 1) {
          f = 1;
          i = 5;
        }
      }
      if (f == 1)
        break;
      for (k; st[k] >= 'a' && st[k] <= 'z' && k < 80; k++)
        ;
      k++;
    }
    if (f == 0)
      cout << st;
    else {
      for (i = 0; i < st.size(); i++)
        if ((st[i] >= 'a' && st[i] <= 'z'))
          cout << (char)(((st[i] - st[k] + 't') - 97 + 26) % 26 + 97);
        else
          cout << st[i];
    }
    cout << endl;
  }
  return 0;
}
Problem p00017 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <string.h>
#include <string>
using namespace std;
int main() {
  string s;
  while (getline(cin, s)) {
    while (true) {
      for (int i = 0; i < s.size(); i++) {
        if (s[i] == 'z') {
          s[i] = 'a';
        } else if (s[i] != ' ' && s[i] != '.') {
          s[i]++;
        }
      }
      if (s.find("the") != -1)
        break;
      if (s.find("this") != -1)
        break;
      if (s.find("that") != -1)
        break;
    }
    cout << s << endl;
  }
}

Error: 0

Fixed submission:

#include <iostream>
#include <string.h>
#include <string>
using namespace std;
bool search(string);
int main() {
  string s;
  getline(cin, s);
  while (true) {
    for (int i = 0; i < s.size(); i++) {
      if (s[i] == 'a') {
        s[i] = 'z';
      } else if (s[i] > 'a' && s[i] <= 'z') {
        s[i]--;
      }
    }
    if (search(s)) {
      cout << s << endl;
      break;
    }
  }
}
bool search(string s) {
  string p[] = {{"the"}, {"this"}, {"that"}};
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 't') {
      for (int j = 0; j < 3; j++) {
        int count = 0;
        for (int i2 = i; i2 < i + p[j].size(); i2++, count++) {
          if (p[j][count] != s[i2]) {
            break;
          }
        }
        if (count == p[i].size() - 1) {
          return true;
        }
      }
    }
  }
  return false;
}
Problem p00017 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <string>

using namespace std;

int main(void) {
  int i, len;
  string encrypted, tmp, decoded;

  while (getline(cin, encrypted)) {
    len = encrypted.size();

    while (encrypted.find("this") == string::npos &&
           encrypted.find("that") == string::npos &&
           encrypted.find("the") == string::npos) {
      for (i = 0; i < len; i++) {
        if (encrypted[i] >= 97 &&
            encrypted[i] <= 122) { // isAlphabet(encrypted[i]);
          encrypted[i] += 1;
          if (encrypted[i] == 123)
            encrypted[i] = 97; // z->a
        }
      }
    }

    cout << encrypted << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
#include <string>

using namespace std;

int main(void) {
  int i, len;
  string encrypted, tmp, decoded;

  getline(cin, encrypted);
  len = encrypted.size();

  while (encrypted.find("this") == string::npos ||
         encrypted.find("that") == string::npos ||
         encrypted.find("the") == string::npos) {
    for (i = 0; i < len; i++) {
      if (encrypted[i] >= 97 &&
          encrypted[i] <= 122) { // isAlphabet(encrypted[i]);
        encrypted[i] += 1;
        if (encrypted[i] == 123)
          encrypted[i] = 97; // z->a
      }
    }
  }

  cout << encrypted << endl;

  return 0;
}
Problem p00019 (C++) — buggy submission, verdict: Time Limit Exceeded


#include <algorithm>
#include <cctype>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>

using namespace std;

int main() {
  long long int n;
  long long result = 1;
  cin >> n;
  while (n > 1) {
    result *= n;
    n--;
  }
  cout << result << endl;
  // while(1);
  return 0;
}


Error: TLE

Fixed submission:


#include <algorithm>
#include <cctype>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>

using namespace std;

int main() {
  long long int n;
  long long result = 1;
  cin >> n;
  while (n > 1) {
    result *= n;
  }
  cout << result << endl;
  // while(1);
  return 0;
}
Problem p00019 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
using namespace std;
int main() {
  int n;
  cin >> n;
  long long int i = 1;
  while (n >= 1) {
    i *= n;
    n--;
  }
  cout << i << endl;
  ;

  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>
using namespace std;
int fac(int x) {
  if (x == 1) {
    return 1;
  } else {
    return fac(x - 1) * x;
  }
}
int main() {
  int n;
  while (n <= 20 && n >= 1) {
    cin >> n;
  }
  cout << fac(n) << endl;
  return 0;
}
Problem p00019 (C++) — buggy submission, verdict: Runtime Error

#include <cstdio>
#include <iostream>
using namespace std;

int main() {
  int n;
  scanf("%d", &n);
  long long int Fraction = 1;
  for (int i = 0; i < n; i++) {
    Fraction *= n - i;
  }
  printf("%lld\\n", Fraction);
  return 0;
}

Error: -11

Fixed submission:

#include <cstdio>
#include <iostream>
using namespace std;

int main() {
  int n;
  scanf("%d", n);
  int Fraction = 1;
  for (int i = 0; i < n; i++) {
    Fraction *= n - i;
  }
  printf("%d\\n", Fraction);
  return 0;
}
Problem p00019 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <iostream>

using namespace std;

long long fact(int n) {
  if (n == 0)
    return 1;
  else
    return n * (fact(n - 1));
}

int main() {
  int n;
  cin >> n;
  long long result = fact(n);
  cout << result << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <stdio.h>
long long int numbers[21];
int last_added = 1;

long long int facto(int key) {
  long long int m = 1;

  if (numbers[key] != 0)
    return numbers[key];

  else {
    for (int i = last_added; i <= key; i++) {
      if (numbers[i] != 0) {
        m *= numbers[i];
      } else {
        m *= i;
        numbers[i] = m;
        if (i > last_added)
          last_added = i;
      }
    }
    return m;
  }
}
int main() {
  int n;
  while (scanf("%d", &n)) {
    printf("%lld\\n", facto(n));
  }
  return 0;
}
Problem p00019 (C++) — buggy submission, verdict: Time Limit Exceeded

#include "bits/stdc++.h"
#include <unordered_map>
#include <unordered_set>
#pragma warning(disable : 4996)
using namespace std;
using ld = long double;
template <class t> using table = vector<vector<t>>;
const ld eps = 1e-9;

//// < "d:\\d_download\\visual studio
///2015\\projects\\programing_contest_c++\\debug\\a.txt" > "d:\\d_download\\visual
///studio 2015\\projects\\programing_contest_c++\\debug\\b.answer"
int main() {
  int N;
  cin >> N;
  long long int ans = 1;
  while (N) {
    ans *= N;
    N--;
  }
  cout << ans << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include "bits/stdc++.h"
#include <unordered_map>
#include <unordered_set>
#pragma warning(disable : 4996)
using namespace std;
using ld = long double;
template <class t> using table = vector<vector<t>>;
const ld eps = 1e-9;

//// < "d:\\d_download\\visual studio
///2015\\projects\\programing_contest_c++\\debug\\a.txt" > "d:\\d_download\\visual
///studio 2015\\projects\\programing_contest_c++\\debug\\b.answer"
int main() {
  int N;
  cin >> N;
  long long int ans = 1;
  while (1) {
    ans *= N;
    N--;
  }
  cout << ans << endl;
  return 0;
}