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

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

int main() {
  int n, a[100], memory, i = 0, flag = 1, b = 0;

  cin >> n;

  for (i = 0; i < n; i++)
    cin >> a[i];

  i = 0;

  while (flag) {
    flag = 0;

    for (int j = n - 1; j >= i + 1; j--) {

      if (a[j] < a[j - 1]) {
        memory = a[j];

        a[j] = a[j - 1];

        a[j - 1] = memory;

        flag = 1;

        b += 1;
      }
    }

    i++;
  }

  for (i = 0; i < n; i++) {
    cout << a[i];

    if (i == n - 1)
      cout << endl;

    else
      cout << " ";
  }

  printf("%d\\n", b);

  return 0;
}

Error: TLE

Fixed submission:

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

int main() {
  int n, a[100], memory, i = 0, flag = 1, b = 0;

  cin >> n;

  for (i = 0; i < n; i++)
    cin >> a[i];

  i = 0;

  while (flag) {
    for (int j = n - 1; j >= i + 1; j--) {
      flag = 0;

      if (a[j] < a[j - 1]) {
        memory = a[j];

        a[j] = a[j - 1];

        a[j - 1] = memory;

        flag = 1;

        b += 1;
      }
    }

    i++;
  }

  for (i = 0; i < n; i++) {
    cout << a[i];

    if (i == n - 1)
      cout << endl;

    else
      cout << " ";
  }

  printf("%d\\n", b);

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

#include <iostream>
using namespace std;

int bubbleSort(int A[], int N) {
  int sw = 0;
  bool flag = 1;
  for (int i = 0; flag; i++) {
    flag = 0;
    for (int j = N - 1; j >= i + 1; j--) {
      if (A[j] < A[j - 1]) {
        swap(A[j], A[j - 1]);
        flag = 1;
        sw++;
      }
    }
  }
  return sw;
}

int main() {
  int A[100], N, sw;
  cin >> N;
  for (int i = 0; i < N; i++)
    cin >> A[i];

  sw = bubbleSort(A, N);

  for (int i = 0; i < N; i++) {
    if (i)
      cout << " ";
    cout << A[i];
  }
  cout << endl;
  cout << sw << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <iostream>
using namespace std;

int bubbleSort(int A[], int N) {
  int sw = 0;
  bool flag = 1;
  for (int i = 0; flag; i++) {
    for (int j = N - 1; j >= i + 1; j--) {
      if (A[j] < A[j - 1]) {
        swap(A[j], A[j - 1]);
        flag = 1;
        sw++;
      }
    }
  }
  return sw;
}

int main() {
  int A[100], N, sw;
  cin >> N;
  for (int i = 0; i < N; i++)
    cin >> A[i];

  sw = bubbleSort(A, N);

  for (int i = 0; i < N; i++) {
    if (i)
      cout << " ";
    cout << A[i];
  }
  cout << endl;
  cout << sw << endl;
  return 0;
}
Problem p02259 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
#define ll long long int
#define FOR(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, n)
using namespace std;

int main() {
  int n;
  cin >> n;
  int a[n];
  int i, j, k, count, flag, temp;
  REP(i, n) { cin >> a[i]; }
  flag = 1;
  count = 0;
  while (flag) {
    flag = 0;
    for (j = n - 1; j > 0; j--) {
      if (a[j] < a[j - 1]) {
        temp = a[j - 1];
        a[j - 1] = a[j];
        a[j] = temp;
        flag = 1;
        count++;
      }
    }
  }
  cout << a[0];
  REP1(k, n) { cout << " " << a[k]; }
  cout << endl << count << endl;

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long int
#define FOR(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, n)
using namespace std;

int main() {
  int n;
  cin >> n;
  int a[n];
  int i, j, k, count, flag, temp;
  REP(i, n) { cin >> a[i]; }
  flag = 1;
  count = 0;
  while (flag) {
    for (j = n - 1; j > 1; j--) {
      flag = 0;
      if (a[j] < a[j - 1]) {
        temp = a[j - 1];
        a[j - 1] = a[j];
        a[j] = temp;
        flag = 1;
        count++;
      }
    }
  }
  cout << a[0];
  REP1(k, n - 1) { cout << " " << a[k]; }
  cout << endl << count << endl;

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

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

void print_vector(vector<int> &v) {
  for (vector<int>::iterator it = v.begin(); it != v.end(); it++) {
    std::cout << *it;
    if (it != v.end() - 1) {
      std::cout << " ";
    }
  }
  std::cout << endl;
}

int main() {
#ifdef LOCAL
  // ??\\??? cin ?????\\????????? 'xxx.txt' ?????????
  std::ifstream in("alds1_2_a.txt");
  std::cin.rdbuf(in.rdbuf());
#else
#endif

  vector<int> vec;
  int n = 0;
  int change_num = 0;

  cin >> n;
  for (int i = 0; i < n; ++i) {
    int tmp;
    cin >> tmp;
    vec.push_back(tmp);
  }

  for (int i = 0; i < n; i++) {
    for (int j = n - 1; j > 0; j--) {
      if (vec[j - 1] > vec[j]) {
        int tmp = vec[j - 1];
        vec[j - 1] = vec[j];
        vec[j] = tmp;
        change_num++;
      }
    }
  }

  print_vector(vec);
  cout << change_num << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

void print_vector(vector<int> &v) {
  for (int x : v) {
    std::cout << x << " ";
  }
  std::cout << endl;
}

int main() {
#ifdef LOCAL
  // ??\\??? cin ?????\\????????? 'xxx.txt' ?????????
  std::ifstream in("alds1_2_a.txt");
  std::cin.rdbuf(in.rdbuf());
#else
#endif

  vector<int> vec;
  int n = 0;
  int change_num = 0;

  cin >> n;
  for (int i = 0; i < n; ++i) {
    int tmp;
    cin >> tmp;
    vec.push_back(tmp);
  }

  for (int i = 0; i < n; i++) {
    for (int j = n - 1; j > 0; j--) {
      if (vec[j - 1] > vec[j]) {
        int tmp = vec[j - 1];
        vec[j - 1] = vec[j];
        vec[j] = tmp;
        change_num++;
      }
    }
  }

  print_vector(vec);
  cout << change_num << endl;
  return 0;
}
Problem p02259 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  int a[100];
  cin >> n;
  int k = 0, count = 0;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  while (1) {
    for (int i = n - 1; i > 0 + k; i--) {
      if (a[i - 1] > a[i]) {
        swap(a[i - 1], a[i]);
        count++;
      }
    }
    k++;
    if (k == n)
      break;
  }
  for (int i = 0; i < n; i++) {
    if (i == 0)
      cout << a[i];
    else
      cout << " " << a[i];
  }
  cout << endl;
  cout << count << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  int a[100];
  cin >> n;
  int k = 0, count = 0;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  while (1) {
    for (int i = n - 1; i > 0 + k; i--) {
      if (a[i - 1] > a[i]) {
        swap(a[i - 1], a[i]);
        count++;
      }
    }
    k++;
    if (k == n - 1)
      break;
  }
  for (int i = 0; i < n; i++) {
    if (i == 0)
      cout << a[i];
    else
      cout << " " << a[i];
  }
  cout << endl;
  cout << count << endl;
  return 0;
}
Problem p02259 (C++) — buggy submission, verdict: Time Limit Exceeded

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

int bubbleSort(int A[], int N) {
  int sw = 0; //?????????????????°
  bool flag = 1;
  for (int i = 0; flag; i++) {
    flag = 0;
    for (int j = N - 1; j >= i + 1; j--) {
      if (A[j] < A[j - 1]) {
        flag = 1;
        swap(A[j], A[j - 1]);
        sw++;
      }
    }
  }
  return sw;
}

int main() {
  int N, A[100];
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  int sw = bubbleSort(A, N);

  for (int i = 0; i < N; i++) {
    if (i > 0)
      cout << ' ';
    cout << A[i];
  }
  cout << endl;
  cout << sw << endl;
  return 0;
}

Error: TLE

Fixed submission:

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

int bubbleSort(int A[], int N) {
  int sw = 0; //?????????????????°
  bool flag = 1;
  for (int i = 0; flag; i++) {
    for (int j = N - 1; j >= i + 1; j--) {
      flag = 0;
      if (A[j] < A[j - 1]) {
        flag = 1;
        swap(A[j], A[j - 1]);
        sw++;
      }
    }
  }
  return sw;
}

int main() {
  int N, A[100];
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  int sw = bubbleSort(A, N);

  for (int i = 0; i < N; i++) {
    if (i > 0)
      cout << ' ';
    cout << A[i];
  }
  cout << endl;
  cout << sw << endl;
  return 0;
}
Problem p02259 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>
#define MAX 100

int main() {

  int num, i, j, array[MAX], tem, count = 0;

  scanf("%d", &num);
  for (i = 0; i < num; i++) {
    scanf("%d", &array[i]);
  }

  for (i = 0; i <= num - 1; i++) {
    for (j = num - 1; j > i; j--) {
      if (array[j] < array[j - 1]) {
        tem = array[j];
        array[j] = array[j - 1];
        array[j - 1] = tem;
        count++;
      }
    }
  }
  for (i = 0; i < num - 1; i++) {
    printf("%d ", array[i]);
  }
  printf("%d\\n", array[num - 1]);

  printf("%d\\n", count);
}

Error: 0

Fixed submission:


#include <stdio.h>
#define MAX 10

int main() {

  int num, i, j, array[MAX], tem, count = 0;

  scanf("%d", &num);
  for (i = 0; i < num; i++) {
    scanf("%d", &array[i]);
  }

  for (i = 0; i <= num - 1; i++) {
    for (j = num - 1; j > i; j--) {
      if (array[j] < array[j - 1]) {
        tem = array[j];
        array[j] = array[j - 1];
        array[j - 1] = tem;
        count++;
      }
    }
  }
  for (i = 0; i < num - 1; i++) {
    printf("%d ", array[i]);
  }
  printf("%d\\n", array[num - 1]);

  printf("%d\\n", count);
}
Problem p02259 (C++) — buggy submission, verdict: Time Limit Exceeded


#include <iostream>
using namespace std;

void printArr(int *arr, int size) {
  for (int i = 0; i < size; i++) {
    if (i != 0)
      cout << " ";
    cout << arr[i];
  }
  cout << endl;
}

void swap(int *arrA, int *arrB) {
  int temp = *arrA;
  *arrA = *arrB;
  *arrB = temp;
}

int bubbleSort(int *arr, int size) {
  int cnt = 0;
  for (int i = 0; i < size; i++) {
    for (int j = size - 1; j > i; j--) {
      if (arr[j] < arr[j - 1]) {
        swap(&arr[j], &arr[j - 1]);
        cnt++;
      }
    }
  }
  return cnt;
}

int main() {
  int arr[100];
  int N = 0;

  cin >> N;
  for (int i = 0; i < N; i++)
    cin >> arr[i];

  int sortCnt = bubbleSort(arr, N);
  printArr(arr, N);
  cout << sortCnt << endl;

  return 0;
}

Error: TLE

Fixed submission:


#include <stdio.h>

void printArr(int *arr, int size) {
  for (int i = 0; i < size; i++) {
    if (i != 0)
      printf(" ");
    printf("%d", arr[i]);
  }
  printf("\\n");
}

void swap(int *arrA, int *arrB) {
  int temp = *arrA;
  *arrA = *arrB;
  *arrB = temp;
}

int bubbleSort(int *arr, int size) {
  int cnt = 0;
  for (int i = 0; i < size; i++) {
    for (int j = size - 1; j > i; j--) {
      if (arr[j] < arr[j - 1]) {
        swap(&arr[j], &arr[j - 1]);
        cnt++;
      }
    }
  }
  return cnt;
}

int main() {
  int arr[100];
  int N = 0;

  scanf("%d", &N);
  for (int i = 0; i < N; i++)
    scanf("%d", &arr[i]);

  int sortCnt = bubbleSort(arr, N);
  printArr(arr, N);
  printf("%d", sortCnt);

  while (true) {
  }
  return 0;
}
Problem p02259 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <stdio.h>

int bubbleSort(int *A, int N) {
  int flag = 1, count = 0;
  while (flag) {
    flag = 0;
    for (int j = N - 1; j > 0; j--) {
      if (A[j] < A[j - 1]) {
        int tmp = A[j];
        A[j] = A[j - 1];
        A[j - 1] = tmp;
        count++;
        flag = 1;
      }
    }
  }
  return count;
}

void outputArray(int *A, int N) {
  printf("%d", A[0]);
  for (int i = 1; i < N; i++) {
    printf(" %d", A[i]);
  }
  printf("\\n");
}

int main() {
  int n;
  scanf("%d", &n);

  int a[n];
  for (int i = 0; i < n; i++)
    scanf("%d", &a[i]);

  int count = bubbleSort(a, n);
  outputArray(a, n);
  printf("%d\\n", count);

  return 0;
}


Error: TLE

Fixed submission:

#include <stdio.h>

int bubbleSort(int *A, int N) {
  int flag = 1, count = 0;
  while (flag) {
    flag = 0;
    for (int j = N - 1; j > 0; j--) {
      if (A[j] < A[j - 1]) {
        int tmp = A[j];
        A[j] = A[j - 1];
        A[j - 1] = tmp;
        count++;
      }
      flag = 1;
    }
  }
  return count;
}

void outputArray(int *A, int N) {
  printf("%d", A[0]);
  for (int i = 1; i < N; i++) {
    printf(" %d", A[i]);
  }
  printf("\\n");
}

int main() {
  int n;
  scanf("%d", &n);

  int a[n];
  for (int i = 0; i < n; i++)
    scanf("%d", &a[i]);

  int count = bubbleSort(a, n);
  outputArray(a, n);
  printf("%d\\n", count);

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

#include <math.h>
#include <stdio.h>
int main() {
  int n, r, c = 0;
  int A[100];
  int flag = 1;
  int i = 0;
  int temp;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &A[i]);
  }
  i = 0;
  while (flag) {
    flag = 0;
    for (int j = n - 1; j >= i + 1; j--) {
      if (A[j] < A[j - 1]) {
        temp = A[j];
        A[j] = A[j - 1];
        A[j - 1] = temp;
        flag = 1;
        r++;
      }
    }
    i++;
  }
  for (i = 0; i < n; i++) {
    if (c == 1) {
      printf(" ");
    }
    printf("%d", A[i]);
    c = 1;
  }
  printf("\\n%d\\n", r);
  return 0;
}

Error: WA

Fixed submission:

#include <math.h>
#include <stdio.h>
int main() {
  int n, r, c = 0;
  int A[100];
  int flag = 1;
  int i = 0;
  int temp;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &A[i]);
  }
  i = 0;
  while (flag) {
    flag = 0;
    for (int j = n - 1; j <= i + 1; j--) {
      if (A[j] < A[j - 1]) {
        temp = A[j];
        A[j] = A[j - 1];
        A[j - 1] = temp;
        flag = 1;
      }
    }
    i++;
  }
  r = i;
  for (i = 0; i < n; i++) {
    if (c == 1) {
      printf(" ");
    }
    printf("%d", A[i]);
    c = 1;
  }
  printf("\\n%d\\n", r);
  return 0;
}
Problem p02259 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <vector>
template <class T> void printvec(std::vector<T> vec) {
  std::size_t n = vec.size();
  for (int i = 0; i < n - 1; ++i) {
    std::cout << vec[i] << " ";
  }
  std::cout << vec[n - 1] << std::endl;
}

int main(int const argc, char const **argv) {
  int n;
  std::cin >> n;
  std::vector<int> vec;
  for (int i = 0; i < n; ++i) {
    int j;
    std::cin >> j;
    vec.push_back(j);
  }
  int count = 0;
  int flag = 1;

  for (int i = 0; i < n; ++i) {
    for (int j = i; j > 0; --j) {
      if (vec[j - 1] > vec[j]) {
        std::swap(vec[j - 1], vec[j]);
        count++;
      }
    }
  }

  for (int j = n - 1; j != 0; j--) {
    if (vec[j] < vec[j - 1]) {
      std::swap(vec[j], vec[j - 1]);
      count++;
      flag = 1;
    }
  }

  printvec(vec);

  std::cout << count << std::endl;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <vector>
int main(int const argc, char const **argv) {
  int n;
  std::cin >> n;
  std::vector<int> vec;
  for (int i = 0; i < n; ++i) {
    int j;
    std::cin >> j;
    vec.push_back(j);
  }
  int count = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = i - 1; i != 0; --j) {
      if (vec[j - 1] > vec[j]) {
        std::swap(vec[j - 1], vec[j]);
        ++count;
      }
    }
  }
  for (int i = 0; i < n - 1; ++i) {
    std::cout << vec[i] << " ";
  }
  std::cout << vec[n - 1] << std::endl;
  std::cout << count << std::endl;
}
Problem p02259 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cstdio>
using namespace std;

void b_sort(int *a, int N);

int main() {
  int a[100];
  int N;
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%d", &a[i]);
  }

  b_sort(a, N);
}

void b_sort(int *a, int N) {
  int j = N - 1;
  int t;
  int count = 0;

  while (1) {
    for (int i = 0; i < j; i++) {
      if (a[i] > a[i + 1]) {
        t = a[i];
        a[i] = a[i + 1];
        a[i + 1] = t;
        count++;
      }
    }
    if (j != 0)
      j--;
    if (j == 0) {
      break;
    }
  }
  for (int i = 0; i < N; i++) {
    printf("%d", a[i]);
    if (i != N - 1) {
      printf(" ");
    } else {
      printf("\\n");
    }
  }
  printf("%d\\n", count);
}


Error: TLE

Fixed submission:

#include <cstdio>
using namespace std;

void b_sort(int *a, int N);

int main() {
  int a[100];
  int N;
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%d", &a[i]);
  }

  b_sort(a, N);
}

void b_sort(int *a, int N) {
  int j = N - 1;
  int t;
  int count = 0;

  while (1) {
    for (int i = 0; i < j; i++) {
      if (a[i] > a[i + 1]) {
        t = a[i];
        a[i] = a[i + 1];
        a[i + 1] = t;
        count++;
      }
    }
    j--;
    if (j == 0) {
      break;
    }
  }
  for (int i = 0; i < N; i++) {
    printf("%d", a[i]);
    if (i != N - 1) {
      printf(" ");
    } else {
      printf("\\n");
    }
  }
  printf("%d\\n", count);
}
Problem p02259 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;

int BIT[151];
void update(int a) { // a???1????¶????
  while (a <= 150) {
    BIT[a]++;
    a += a & (-a);
  }
}
int n(int a) {
  int sum = 0;
  while (a > 0) {
    sum += BIT[a];
    a -= a & (-a);
  }
  return sum;
}
signed main() {
  int a;
  cin >> a;
  int s[150];
  int sum = 0;
  for (int i = 0; i < a; i++) {
    int k;
    cin >> k;
    s[i] = k;
    k++;
    sum += i - n(k);
    update(k);
  }
  sort(s, s + a);
  for (int l = 0; l < a; l++) {
    if (l)
      cout << " ";
    cout << s[l];
  }
  cout << endl;
  cout << sum << endl;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;

int BIT[101];
void update(int a) { // a???1????¶????
  while (a <= 100) {
    BIT[a]++;
    a += a & (-a);
  }
}
int n(int a) {
  int sum = 0;
  while (a > 0) {
    sum += BIT[a];
    a -= a & (-a);
  }
  return sum;
}
signed main() {
  int a;
  cin >> a;
  int s[100];
  int sum = 0;
  for (int i = 0; i < a; i++) {
    int k;
    cin >> k;
    s[i] = k;
    sum += i - n(k);
    update(k);
  }
  sort(s, s + a);
  for (int l = 0; l < a; l++) {
    if (l)
      cout << " ";
    cout << s[l];
  }
  cout << endl;
  cout << sum << endl;
}
Problem p02259 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

// flag?????¨????????????????????????
int bubbleSort(int A[], int N) {
  int sw = 0;
  bool flag = 1;
  for (int i = 0; flag; i++) {
    flag = 0;
    for (int j = N - 1; j >= i + 1; j--) {
      if (A[j] < A[j - 1]) {
        // ??£??\\????´????????????????
        swap(A[j], A[j - 1]);
        flag = 1;
        sw++;
      }
    }
  }
  return sw;
}

int main() {
  int A[100], N, sw;
  cin >> N;
  for (int i = 0; i < N; i++)
    cin >> A[i];

  sw = bubbleSort(A, N);

  for (int i = 0; i < N; i++) {
    if (i)
      cout << " ";
    cout << A[i];
  }
  cout << endl;
  cout << sw << endl;

  return 0;
}

Error: -11

Fixed submission:

#include <iostream>
using namespace std;

// flag?????¨????????????????????????
int bubbleSort(int A[], int N) {
  int sw = 0;
  bool flag = 1;
  for (int i = 0; flag; i++) {
    flag = 0;
    for (int j = N - 1; j >= i + 1; j++) {
      if (A[j] < A[j - 1]) {
        // ??£??\\????´????????????????
        swap(A[j], A[j - 1]);
        flag = 1;
        sw++;
      }
    }
  }
  return sw;
}

int main() {
  int A[100], N, sw;
  cin >> N;
  for (int i = 0; i < N; i++)
    cin >> A[i];

  sw = bubbleSort(A, N);

  for (int i = 0; i < N; i++) {
    if (i)
      cout << "";
    cout << A[i];
  }
  cout << endl;
  cout << sw << endl;

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

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(), (x).end())
#define all(x) (x).begin(), (x).end()
#define EQ(a, b) (abs((a) - (b)) < eps)
const int MAX = 100000;
const int geta = 100;
struct BIT {
  int bit[MAX + 1];
  void add(int i, int x) {
    while (i <= MAX) {
      bit[i] += x;
      i += i & -i;
    }
  }
  int sum(int i) {
    int res = 0;
    while (i > 0) {
      res += bit[i];
      i -= i & -i;
    }
    return res;
  }
};
BIT bit;
int N, a[105];
int main() {
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%d", &a[i]);
    a[i] += geta;
  }
  int ans = 0;
  for (int i = 0; i < N; i++) {
    ans += bit.sum(a[i]);
    bit.add(a[i], 1);
  }
  sort(a, a + N);
  for (int i = 0; i < N; i++)
    printf("%d%c", a[i] - geta, (i == N - 1) ? '\\n' : ' ');
  printf("%d\\n", N * (N - 1) / 2 - ans);
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(), (x).end())
#define all(x) (x).begin(), (x).end()
#define EQ(a, b) (abs((a) - (b)) < eps)
const int MAX = 100000;
struct BIT {
  int bit[MAX + 1];
  void add(int i, int x) {
    while (i <= MAX) {
      bit[i] += x;
      i += i & -i;
    }
  }
  int sum(int i) {
    int res = 0;
    while (i > 0) {
      res += bit[i];
      i -= i & -i;
    }
    return res;
  }
};
BIT bit;
int N, a[105];
int main() {
  scanf("%d", &N);
  for (int i = 0; i < N; i++)
    scanf("%d", &a[i]);
  int ans = 0;
  for (int i = 0; i < N; i++) {
    ans += bit.sum(a[i]);
    bit.add(a[i], 1);
  }
  sort(a, a + N);
  for (int i = 0; i < N; i++)
    printf("%d%c", a[i], (i == N - 1) ? '\\n' : ' ');
  printf("%d\\n", N * (N - 1) / 2 - ans);
  return 0;
}