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

#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <sstream>
#include <string>
using namespace std;

int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    string line;
    cin >> line;
    string sol = "NA";
    if (line.find('#') != string::npos) {
      bool flag = false;
      string a = "";
      string b = "";
      for (int x = 2; x < line.size() - 1; ++x) {
        if (line[x] == '#') {
          flag = true;
          continue;
        }
        if (!flag) {
          a += line[x];
        } else {
          b += line[x];
        }
      }
      if (line.size() > 3 && line[0] == '>' && line[1] == '\\'' &&
          line[line.size() - 1] == '~' && a == b && a != "")
        sol = "A";
    } else {
      bool flag = true;
      for (int x = 2; line.size() > 4 && x < (line.size() - 3); x += 2) {
        if (line[x] != 'Q' || line[x + 1] != '=')
          flag = false;
      }
      if (line.size() > 4 && line[0] == '>' && line[1] == '^' &&
          line[line.size() - 1] == '~' && line[line.size() - 2] == '~' && flag)
        sol = "B";
    }
    cout << sol << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <sstream>
#include <string>
using namespace std;

int main() {
  int n;
  while (cin >> n, n) {
    for (int x = 0; x < n; ++x) {
      string line;
      cin >> line;
      string sol = "NA";
      if (line.find('#') != string::npos) {
        bool flag = false;
        string a = "";
        string b = "";
        for (int x = 2; x < line.size() - 1; ++x) {
          if (line[x] == '#') {
            flag = true;
            continue;
          }
          if (!flag) {
            a += line[x];
          } else {
            b += line[x];
          }
        }
        if (line.size() > 3 && line[0] == '>' && line[1] == '\\'' &&
            line[line.size() - 1] == '~' && a == b)
          sol = "A";
      } else {
        bool flag = true;
        for (int x = 2; line.size() > 4 && x < (line.size() - 3); x += 2) {

          // cout<<"OK"<<endl;
          if (line[x] != 'Q' || line[x + 1] != '=')
            flag = false;
        }
        if (line.size() > 4 && line[0] == '>' && line[1] == '^' &&
            line[line.size() - 1] == '~' && line[line.size() - 2] == '~' &&
            flag)
          sol = "B";
      }
      cout << sol << endl;
    }
  }
  return 0;
}
Problem p00139 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
#define INF 999999
using namespace std;
int main() {
  int N, j;
  cin >> N;
  while (N--) {
    int runcnt = 0, j;
    char S[128000] = {0};
    cin >> S;
    if (S[0] == '>' && S[1] == 39) {
      int K = 0;
      for (j = 2;; j++) {
        if (S[j] == '=') {
          runcnt++;
          K = 1;
        } else if (S[j] == '#') {
          break;
        } else {
          cout << "NA" << endl;
          goto end;
        }
      }
      for (int i = j + 1;; i++) {
        if (S[i] == '=') {
          runcnt--;
        } else if (runcnt == 0 && S[i] == '~' && K == 1) {
          cout << "A" << endl;
          goto end;
        } else {
          cout << "NA" << endl;
          goto end;
        }
      }
    } else if (S[0] == '>' && S[1] == '^') {
      int F = 0;
      for (j = 2;;) {
        if (S[j] == 'Q' && S[j + 1] == '=') {
          j += 2;
          F = 1;
        } else if (S[j] == '~' && S[j + 1] == '~' && F == 1) {
          cout << "B" << endl;
          goto end;
        } else {
          cout << "NA" << endl;
          goto end;
        }
      }
    } else
      cout << "NA" << endl;
  end:;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
#define INF 999999
using namespace std;
int main() {
  int N, j;
  cin >> N;
  while (N--) {
    int runcnt = 0, j;
    char S[150] = {0};
    cin >> S;
    if (S[0] == '>' && S[1] == 39) {
      int K = 0;
      for (j = 2; j < 1000; j++) {
        if (S[j] == '=') {
          runcnt++;
          K = 1;
        } else if (S[j] == '#') {
          break;
        } else {
          cout << "NA" << endl;
          break;
        }
      }
      for (int i = j + 1; i < 1000; i++) {
        if (S[i] == '=') {
          runcnt--;
        } else if (runcnt == 0 && S[i] == '~' && K == 1) {
          cout << "A" << endl;
          break;
        } else {
          cout << "NA" << endl;
          break;
        }
      }
    } else if (S[0] == '>' && S[1] == '^') {
      int F = 0;
      for (j = 2; j < 1000;) {
        if (S[j] == 'Q' && S[j + 1] == '=') {
          j += 2;
          F = 1;
        } else if (S[j] == '~' && S[j + 1] == '~' && F == 1) {
          cout << "B" << endl;
          break;
        } else {
          cout << "NA" << endl;
          break;
        }
      }
    } else
      cout << "NA" << endl;
  }
  return 0;
}
Problem p00139 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;

int main() {
  string str;
  int n;
  cin >> n;
  while (n--) {
    cin >> str;
    int idx = 2;
    int cnt = 0;
    bool flg = true;
    if (str[0] == '>' && str[1] == 39) {
      bool used = false;
      while (idx < str.size() && str[idx] == '=') {
        used = true;
        cnt++;
        idx++;
      }
      if (str[idx] == '#') {
        idx++;
        while (idx < str.size() && str[idx] == '=') {
          cnt--;
          idx++;
        }
      }
      if (str[idx] == '~' && cnt == 0 && used) {
        cout << "A" << endl;
        flg = false;
      }
    } else if (str[0] == '>' && str[1] == '^') {
      while (idx + 1 < str.size() && str[idx] == 'Q' && str[idx + 1] == '=') {
        idx += 2;
        cnt++;
      }
      if (cnt > 0 && str[idx] == '~' && str[idx + 1] == '~') {
        cout << "B" << endl;
        flg = false;
      }
    }
    if (flg)
      cout << "NA" << endl;
  }
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

int main() {
  string str;
  int n;
  cin >> n;
  while (n--) {
    cin >> str;
    int idx = 2;
    int cnt = 0;
    bool flg = true;
    if (str[0] == '>' && str[1] == 39) {
      while (str[idx] != '#') {
        cnt++;
        idx++;
      }
      idx++;
      while (str[idx] != '~') {
        cnt--;
        idx++;
      }
      if (cnt == 0) {
        cout << "A" << endl;
        flg = false;
      }
    } else if (str[0] == '>' && str[1] == '^') {
      while (str[idx] == 'Q' && str[idx + 1] == '=') {
        idx += 2;
      }
      if (str[idx] == '~' && str[idx + 1] == '~') {
        cout << "B" << endl;
        flg = false;
      }
    }
    if (flg)
      cout << "NA" << endl;
  }
}
Problem p00139 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define REP2(i, x, n) for (int i = x; i < (n); i++)
#define ALL(n) begin(n), end(n)
struct cww {
  cww() {
    ios::sync_with_stdio(false);
    cin.tie(0);
  }
} star;
int check(string S) {
  // A
  if (S[0] == '>' && S[1] == '\\'' && S[S.size() - 1] == '~' && S.size() >= 6) {
    S = S.substr(2, S.size() - 3);
    if (S.find_first_not_of("#=", 0) != string::npos)
      return 0;
    string tmpB = S.substr(0, S.find('#'));
    string tmpA = S.substr(S.find('#') + 1, S.size() - 1);
    return tmpB.size() == tmpA.size() ? 1 : 0;
  }
  // B
  if (S[0] == '>' && S[1] == '^' && S[S.size() - 1] == '~' &&
      S[S.size() - 2] == '~' && S.size() >= 6) {
    S = S.substr(2, S.size() - 4);
    if (S.find_first_not_of("Q=", 0) != string::npos)
      return 0;
    if (S.size() % 2 != 0)
      return 0;
    for (int i = 0; i < S.size(); i += 2) {
      if (S[i] != 'Q' && S[i + 1] != '=')
        return 0;
    }
    return 2;
  }
  return 0;
}
int main() {
  int N;
  cin >> N;

  vector<string> res{"NA", "A", "B"};
  string S;
  while (cin >> S) {
    cout << res[check(S)] << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define REP2(i, x, n) for (int i = x; i < (n); i++)
#define ALL(n) begin(n), end(n)
struct cww {
  cww() {
    ios::sync_with_stdio(false);
    cin.tie(0);
  }
} star;
int check(string S) {
  //????????????¢>???£, ?????°???????¢~???£ ????????????????????????NA
  if (S[0] != '>' || S[S.size() - 1] != '~') {
    return 0;
  }
  // A??¨?
  if (S[1] == '\\'') {
    if (S.substr(2, S.size() - 3).find_first_not_of("#=", 0) != string::npos)
      return 0;
    string tmpB = S.substr(2, S.find('#') - 2);
    string tmpA = S.substr(S.find('#') + 1, S.size() - (S.find('#') + 2));
    return tmpB.size() == tmpA.size() ? 1 : 0;
  }
  // B??¨?
  if (S[1] == '^' && S[S.size() - 2] == '~') {
    if (S.substr(2, S.size() - 4).find_first_not_of("Q=", 0) != string::npos)
      return 0;
    for (int i = 2; i < S.size() - 2; i += 2) {
      if (S[i] != 'Q' && S[i + 1] != '=')
        return 0;
    }
    return 2;
  }
}
int main() {
  int N;
  cin >> N;

  vector<string> res{"NA", "A", "B"};
  string S;
  while (cin >> S) {
    cout << res[check(S)] << endl;
  }
  return 0;
}
Problem p00140 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int busstop[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 5, 4, 3, 2, 1};

int main() {
  int n, s, g, count, k, a;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> s >> g;
    count = 1000000000;
    for (int j = 0; j < 15; ++j) {
      if (busstop[j] == s) {
        int tmp = 0;
        k = j;
        while (busstop[k] != g) {
          ++k;
          k %= 15;
          ++tmp;
        }
        if (tmp < count) {
          count = tmp;
          a = j;
        }
      }
    }
    while (busstop[a] != g) {
      cout << busstop[a++] << " ";
      a %= 15;
    }
    cout << g << endl;
  }
  return 0;
}

Error: 0

Fixed submission:

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

const int INT = -1;
int nextstop[10][2] = {{1, 1}, {0, 2},   {1, 3},   {2, 4},   {3, 5},
                       {4, 6}, {INT, 7}, {INT, 8}, {INT, 9}, {INT, 5}};

int main() {
  int n, start, goal, a;
  vector<int> rout;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> start >> goal;
    for (int j = 0; j < 2; ++j) {
      a = start;
      rout.clear();
      while (a != goal) {
        rout.push_back(a);
        a = nextstop[a][j];
        if (a == -1 || a == 0) {
          break;
        }
      }
      if (a == goal) {
        rout.push_back(a);
        break;
      }
    }
    for (int j = 0; j < rout.size(); ++j) {
      if (j)
        cout << " ";
      cout << rout[j];
    }
    cout << endl;
  }
  return 0;
}
Problem p00140 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <iostream>
#include <vector>

using namespace std;

int line[15];

void init() {
  for (int i = 0; i < 14; i++) {
    line[i] = i + 1;
  }
  line[14] = 0;
}

int main() {
  init();
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int s, g;
    cin >> s >> g;
    vector<int> path;
    int as = s;
    int ag = g;
    if (1 <= s && s <= 5)
      as = 15 - s;
    if (1 <= g && g <= 5)
      ag = 15 - g;

    int c = s;
    while (c != g && c != ag) {
      path.push_back(c);
      c = line[c];
    }
    path.push_back(g);

    if (as != s) {
      vector<int> opath;
      c = as;
      while (c != g && c != ag) {
        opath.push_back(c);
        c = line[c];
      }
      opath.push_back(g);
      if (path.size() > opath.size()) {
        path.resize(opath.size());
        copy(opath.begin(), opath.end(), path.begin());
      }
    }

    if (path[0] >= 10) {
      cout << 15 - path[0];
    } else {
      cout << path[0];
    }
    for (int j = 1; j < path.size(); j++) {
      if (path[j] >= 10) {
        cout << ' ' << 15 - path[j];
      } else {
        cout << ' ' << path[j];
      }
    }
    cout << endl;
  }
  return 0;
}

Error: TLE

Fixed submission:

#include <iostream>

using namespace std;

void print_stops(int from, int to) {
  if (from <= 5 && to <= 5) {
    if (from < to) {
      for (int i = from; i <= to; i++) {
        cout << i << ' ';
      }
    } else {
      for (int i = from; i >= to; i--) {
        cout << i << ' ';
      }
    }
  } else if (from <= 5 && 6 <= to && to <= 9) {
    for (int i = from; i <= to; i++) {
      cout << i << ' ';
    }
  } else if (6 <= from && from <= 9 && to <= 5) {
    for (int i = from; i <= 9; i++) {
      cout << i << ' ';
    }
    for (int i = 5; to <= i; i--) {
      cout << i << ' ';
    }
  } else if (6 <= from && from <= 9 && 6 <= to && to <= 9) {
    if (from < to) {
      for (int i = from; i <= to; i++) {
        cout << i << ' ';
      }
    } else {
      for (int i = from; to <= i; i++) {
        cout << i << ' ';
      }
    }
  }
  cout << endl;
}

int main() {
  int n;
  cin >> n;
  while (n--) {
    int from, to;
    cin >> from >> to;
    print_stops(from, to);
  }
  return 0;
}
Problem p00140 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <stdio.h>

using namespace std;

int main() {

  int n, start, goal;

  scanf("%d", &n);

  for (int i = 0; i < n; i++) {
    scanf("%d %d", &start, &goal);

    if (start <= 5) {
      if (start < goal) {
        printf("%d", start);
        for (int k = start + 1; k <= goal; k++) {
          printf(" %d", k);
        }
        printf("\\n");
      } else {
        printf("%d", start);
        for (int k = start - 1; k >= goal; k--) {
          printf(" %d", k);
        }
        printf("\\n");
      }
    } else {           // start > 6
      if (goal >= 5) { //??´??????????????????
        if (start < goal) {
          printf("%d", start);
          for (int k = start + 1; k <= goal; k++)
            printf(" %d", k);

          printf("\\n");

        } else { // start > goal
          printf("%d", start);
          for (int k = start + 1; k <= 9; k++)
            printf(" %d", k);
          if (goal != 5) {
            printf(" 5 4 3 2 1 0 1 2 3 4");
          }
          for (int k = 5; k <= goal; k++)
            printf(" %d", k);
          printf("\\n");
        }

      } else { // goal <= 4
        printf("%d", start);
        for (int k = start + 1; k <= 9; k++)
          printf(" %d", k);
        for (int k = 5; k >= goal; k--)
          printf(" %d", k);
        printf("\\n");
      }
    }
  }

  return 0;
}


Error: TLE

Fixed submission:

#include <cstdio>

using namespace std;

int main() {
  int n;
  scanf("%d\\n", &n);
  for (int j = 0; j < n; j++) {
    int source = 0, sink = 0;
    scanf("%d %d\\n", &source, &sink);
    if (source <= 5) {
      if (source < sink) {
        for (int i = source; i <= sink; i++) {
          printf("%d ", i);
        }
        printf("\\n");
      } else {
        for (int i = source; i >= sink; i--) {
          printf("%d ", i);
        }
        printf("\\n");
      }
    } else {
      if (sink >= 5) {
        if (source < sink) {
          for (int i = source; i <= sink; i++) {
            printf("%d ", i);
          }
          printf("\\n");
        } else {
          for (int i = source; i <= 9; i++) {
            printf("%d ", i);
          }
          if (sink != 5) {
            printf("5 4 3 2 1 0 1 2 3 4");
          }
          for (int i = 5; i < sink; i++) {
            printf("%d ", i);
          }
          printf("\\n");
        }
      } else {
        for (int i = source; i <= 9; i++) {
          printf("%d ", i);
        }
        for (int i = 5; i >= sink; i++) {
          printf("%d ", i);
        }
        printf("\\n");
      }
    }
  }
  return 0;
}
Problem p00140 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

char stop[] = "0123456789543210123456789";

void solve(int start, int goal) {
  int ans = 10000;
  int pos = 0;
  for (int i = 0; i < 25; i++) {
    if (stop[i] != start + '0')
      continue;
    // stop[i] == goal
    for (int j = i + 1; j < 25; j++) {
      if (stop[j] == goal + '0') {
        ans = min(ans, j - i);
        pos = i;
        continue;
      }
    }
  }
  for (int i = pos; i <= pos + ans; i++) {
    cout << (i == pos ? "" : " ") << stop[i];
  }
  cout << endl;
}

int main() {
  int n, f, t;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> f >> t;
    solve(f, t);
  }
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;

char stop[] = "0123456789543210";

void solve(int start, int goal) {
  int ans = 10000;
  int pos = 0;
  for (int i = 0; i < 16; i++) {
    if (stop[i] != start + '0')
      continue;
    // stop[i] == goal
    for (int j = i + 1; j < 16; j++) {
      if (stop[j] == goal + '0') {
        ans = min(ans, j - i);
        pos = i;
        continue;
      }
    }
  }
  for (int i = pos; i <= pos + ans; i++) {
    cout << (i == pos ? "" : " ") << stop[i];
  }
  cout << endl;
}

int main() {
  int n, f, t;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> f >> t;
    solve(f, t);
  }
}
Problem p00140 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>

using namespace std;

int main() {

  int n;

  int a, b;

  cin >> n;

  for (int loop = 0; loop < n; loop++) {
    cin >> a >> b;
    if (a == b) {
      printf("%d\\n", b);
    } else if (a < b) {
      for (int i = a; i < b; i++) {
        printf("%d ", i);
      }
      printf("%d\\n", b);
    } else if (a <= 5) {
      for (int i = a; i > b; i--) {
        printf("%d ", i);
      }
      printf("%d\\n", b);
    } else if (b <= 5) {
      for (int i = a; i <= 9; i++) {
        printf("%d ", i);
      }
      for (int i = 5; i > b; i--) {
        printf("%d ", i);
      }
      printf("%d\\n", b);
    } else {
      for (int i = a; i <= 9; i++) {
        printf("%d ", i);
      }
      printf("5 4 3 2 1 0 1 2 3 4 5 ");
      for (int i = 6; i < b; i++) {
        printf("%d ", i);
      }
      printf("%d\\n", b);
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>

using namespace std;

int main() {

  int n;

  int a, b;

  cin >> n;

  for (int loop = 0; loop < n; loop++) {
    cin >> a >> b;
    if (a == b) {
      printf("%d\\n", b);
    } else if (a < b) {
      for (int i = a; i < b; i++) {
        printf("%d ", i);
      }
      printf("%d\\n", b);
    } else if (a <= 5) {
      for (int i = a; i > b; i--) {
        printf("%d ", i);
      }
      printf("%d\\n", b);
    } else if (b <= 5) {
      for (int i = a; i <= 9; i++) {
        printf("%d ", i);
      }
      for (int i = 5; i > b; i++) {
        printf("%d ", i);
      }
      printf("%d\\n", b);
    } else {
      for (int i = a; i <= 9; i++) {
        printf("%d ", i);
      }
      printf("5 4 3 2 1 0 1 2 3 4 5 ");
      for (int i = 6; i < b; i++) {
        printf("%d ", i);
      }
      printf("%d\\n", b);
    }
  }

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

#include <iostream>
using namespace std;

#define loop(i, a, b) for (int i = (a); i < int(b); i++)
#define rep(i, b) loop(i, 0, b)

char v[] = "0123456789543210123456789";

void solve(int s, int g) {
  int ans = 10000;
  int p = 0;
  rep(i, 25) {
    if (v[i] != s + '0')
      continue;
    loop(j, i + 1, 25) {
      if (v[j] == g + '0') {
        ans = min(ans, j - i);
        p = i;
        continue;
      }
    }
  }

  for (int i = p; i <= p + ans; i++)
    cout << (i == p ? "" : " ") << v[i];
  cout << endl;
}

int main() {
  int n;
  cin >> n;
  rep(i, n) {
    int f, t;
    cin >> f >> t;
    solve(f, t);
  }
}

Error: 0

Fixed submission:

#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <vector>

using namespace std;

#define rep(i, b) for (int i = 0; i < int(b); i++)

vector<vector<int>> G{{1}, {0, 2}, {1, 3}, {2, 4}, {3, 5},
                      {6}, {7},    {8},    {9},    {5}};

void solve(int a, int b) {
  queue<pair<int, int>> q;

  int prev[10], d[10];
  rep(i, 10) d[i] = 1e9;
  d[a] = 0;
  q.push(make_pair(a, 0));
  while (q.size()) {
    pair<int, int> s = q.front();
    q.pop();
    int v = s.first, dis = s.second;

    for (int i = 0; i < G[v].size(); i++) {
      int e = G[v][i];
      if (d[e] > d[v] + 1) {
        prev[e] = v;
        d[e] = d[v] + 1;
        q.push(make_pair(e, d[e]));
      }
    }
  }

  vector<int> ans{b};
  while (ans.back() != a)
    ans.push_back(prev[ans.back()]);
  for (int i = 0; i < ans.size(); i++) {
    cout << ans[ans.size() - 1 - i] << (i + 1 == ans.size() ? '\\n' : ' ');
  }
}

int main() {
  int n;
  cin >> n;
  rep(i, n) {
    int a, b;
    cin >> a >> b;
    solve(a, b);
  }
}
Problem p00140 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
#include <iostream>

using namespace std;

int main() {
  int n;

  cin >> n;
  for (int i = 0; i < n; i++) {
    int s, e;

    cin >> s >> e;
    if (s <= 5) {
      if (s < e) {
        while (s != e)
          printf("%d ", s++);
        printf("%d\\n", e);
      } else {
        while (s != e)
          printf("%d ", s--);
        printf("%d\\n", e);
      }
    } else if (s < e) {
      while (s < e)
        printf("%d ", s++);
      printf("%d\\n", e);
    } else if (e < s) {
      while (s != 5) {
        printf("%d ", s);
        s = (s + 1) - ((s + 1) / 10) * 5;
      }

      if (e == 5)
        printf("5\\n");
      else {
        printf("5 ");

        s--;
        while (s != e && s != 0)
          printf("%d ", s--);
        if (s == e)
          printf("%d\\n", e);
        else if (e == 0) {
          printf("0\\n");
          break;
        } else {
          while (s != e)
            printf("%d ", s++);
          printf("%d\\n", e);
        }
      }
    }
  }

  return 0;
}

Error: TLE

Fixed submission:

#include <cstdio>
#include <iostream>

using namespace std;

int main() {
  int n;

  cin >> n;
  for (int i = 0; i < n; i++) {
    int s, e;

    cin >> s >> e;

    if (s <= 5) {
      if (s < e) {
        while (s != e)
          printf("%d ", s++);
        printf("%d\\n", e);
      } else {
        while (s != e)
          printf("%d ", s--);
        printf("%d\\n", e);
      }
    } else {
      while (s != e) {
        printf("%d ", s);
        s = (s + 1) - ((s + 1) / 10) * 5;
      }
      printf("%d\\n", e);
    }
  }

  return 0;
}