ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2063B - Subsequence Update
Language: PyPy 3-64

Previous submission (verdict: Wrong answer on test 2):
import math

from collections import deque, defaultdict, Counter

import heapq



def solution():

  n, l ,r = list(map(int, input().split(" ")))

  l -= 1

  r -= 1

  a = list(map(int, input().split(" ")))

  segment = a[l:r+1]

  res = sum(segment)

  left, right = a[:l], a[r+1:]

  left.sort()

  right.sort()

  i, j = 0, len(segment) - 1

  while i < len(left) and j >= 0:

    if left[i] < segment[j]:

      segment[j] = left[i]

      i += 1

      j -= 1

    else:

      break

  res = min(res, sum(segment))

  segment = a[l:r+1]

  i, j = 0, len(segment) - 1

  while i < (len(right)) and j >= 0:

    if right[i] < segment[j]:

      segment[j] = right[i]

      i += 1

      j -= 1

    else:

      break

  res = min(res, sum(segment))

  return res





t = int(input())

for i in range(t):

  print(solution())

Submission (verdict: Wrong answer on test 2):
import math

from collections import deque, defaultdict, Counter

import heapq



def solution():

  n, l ,r = list(map(int, input().split(" ")))

  l -= 1

  r -= 1

  a = list(map(int, input().split(" ")))

  segment = a[l:r+1]

  res = sum(segment)

  left, right = a[:l], a[r+1:]

  segment.sort()

  left.sort()

  right.sort()

  i, j = 0, len(segment) - 1

  while i < len(left) and j >= 0:

    if left[i] < segment[j]:

      segment[j] = left[i]

      i += 1

      j -= 1

    else:

      break

  res = min(res, sum(segment))

  segment = a[l:r+1]

  i, j = 0, len(segment) - 1

  while i < (len(right)) and j >= 0:

    if right[i] < segment[j]:

      segment[j] = right[i]

      i += 1

      j -= 1

    else:

      break

  res = min(res, sum(segment))

  return res





t = int(input())

for i in range(t):

  print(solution())
Problem: 2063B - Subsequence Update
Language: PyPy 3-64


Submission (verdict: Wrong answer on test 2):
import math

from collections import deque, defaultdict, Counter

import heapq



def solution():

  n, l ,r = list(map(int, input().split(" ")))

  l -= 1

  r -= 1

  a = list(map(int, input().split(" ")))

  segment = a[l:r+1]

  res = sum(segment)

  left, right = a[:l], a[r+1:]

  left.sort()

  right.sort()

  i, j = 0, len(segment) - 1

  while i < l and j >= 0:

    if left[i] < segment[j]:

      segment[j] = left[i]

      i += 1

      j -= 1

    else:

      break

  res = min(res, sum(segment))

  segment = a[l:r+1]

  i, j = 0, len(segment) - 1

  while i < (len(a) - r-1) and j >= 0:

    if right[i] < segment[j]:

      segment[j] = right[i]

      i += 1

      j -= 1

    else:

      break

  res = min(res, sum(segment))

  return res





t = int(input())

for i in range(t):

  print(solution())
Problem: 2063B - Subsequence Update
Language: PyPy 3-64

Previous submission (verdict: Wrong answer on test 2):
import math

from collections import deque, defaultdict, Counter

import heapq



def solution():

  n, l ,r = list(map(int, input().split(" ")))

  l -= 1

  r -= 1

  a = list(map(int, input().split(" ")))

  segment = a[l:r+1]

  res = sum(segment)

  left, right = a[:l], a[r+1:]

  left.sort()

  right.sort()

  i, j = 0, len(segment) - 1

  while i < l and j >= 0:

    if left[i] < segment[j]:

      segment[j] = left[i]

      i += 1

      j -= 1

    else:

      break

  res = min(res, sum(segment))

  segment = a[l:r+1]

  i, j = 0, len(segment) - 1

  while i < (len(a) - r-1) and j >= 0:

    if right[i] < segment[j]:

      segment[j] = right[i]

      i += 1

      j -= 1

    else:

      break

  res = min(res, sum(segment))

  return res





t = int(input())

for i in range(t):

  print(solution())

Submission (verdict: Wrong answer on test 2):
import math

from collections import deque, defaultdict, Counter

import heapq



def solution():

  n, l ,r = list(map(int, input().split(" ")))

  l -= 1

  r -= 1

  a = list(map(int, input().split(" ")))

  segment = a[l:r+1]

  res = sum(segment)

  left, right = a[:l], a[r+1:]

  left.sort()

  right.sort()

  i, j = 0, len(segment) - 1

  while i < l and j >= 0:

    if left[i] < segment[j]:

      segment[j] = left[i]

      i += 1

      j -= 1

    else:

      break

  res = min(res, sum(segment))

  segment = a[l:r+1]

  i, j = 0, len(segment) - 1

  while i < (len(right)) and j >= 0:

    if right[i] < segment[j]:

      segment[j] = right[i]

      i += 1

      j -= 1

    else:

      break

  res = min(res, sum(segment))

  return res





t = int(input())

for i in range(t):

  print(solution())
Problem: 2063B - Subsequence Update
Language: PyPy 3-64

Previous submission (verdict: Wrong answer on test 2):
import math

from collections import deque, defaultdict, Counter

import heapq



def solution():

  n, l ,r = list(map(int, input().split(" ")))

  l -= 1

  r -= 1

  a = list(map(int, input().split(" ")))

  segment = a[l:r+1]

  res = sum(segment)

  left, right = a[:l], a[r+1:]

  segment.sort()

  left.sort()

  right.sort()

  i, j = 0, len(segment) - 1

  while i < len(left) and j >= 0:

    if left[i] < segment[j]:

      segment[j] = left[i]

      i += 1

      j -= 1

    else:

      break

  res = min(res, sum(segment))

  segment = a[l:r+1]

  i, j = 0, len(segment) - 1

  while i < (len(right)) and j >= 0:

    if right[i] < segment[j]:

      segment[j] = right[i]

      i += 1

      j -= 1

    else:

      break

  res = min(res, sum(segment))

  return res





t = int(input())

for i in range(t):

  print(solution())

Submission (verdict: Accepted):
import math

from collections import deque, defaultdict, Counter

import heapq



def solution():

  n, l ,r = list(map(int, input().split(" ")))

  l -= 1

  r -= 1

  a = list(map(int, input().split(" ")))

  segment = a[l:r+1]

  res = sum(segment)

  left, right = a[:l], a[r+1:]

  segment.sort()

  left.sort()

  right.sort()

  i, j = 0, len(segment) - 1

  while i < len(left) and j >= 0:

    if left[i] < segment[j]:

      segment[j] = left[i]

      i += 1

      j -= 1

    else:

      break

  res = min(res, sum(segment))

  segment = a[l:r+1]

  segment.sort()

  i, j = 0, len(segment) - 1

  while i < (len(right)) and j >= 0:

    if right[i] < segment[j]:

      segment[j] = right[i]

      i += 1

      j -= 1

    else:

      break

  res = min(res, sum(segment))

  return res





t = int(input())

for i in range(t):

  print(solution())
Problem: 2063B - Subsequence Update
Language: PyPy 3-64

Previous submission (verdict: Wrong answer on test 2):
import math

from collections import deque, defaultdict, Counter

import heapq



def solution():

  n, l ,r = list(map(int, input().split(" ")))

  l -= 1

  r -= 1

  a = list(map(int, input().split(" ")))

  segment = a[l:r+1]

  res = sum(segment)

  left, right = a[:l], a[r+1:]

  left.sort()

  right.sort()

  i, j = 0, len(segment) - 1

  while i < l and j >= 0:

    if left[i] < segment[j]:

      segment[j] = left[i]

      i += 1

      j -= 1

    else:

      break

  res = min(res, sum(segment))

  segment = a[l:r+1]

  i, j = 0, len(segment) - 1

  while i < (len(right)) and j >= 0:

    if right[i] < segment[j]:

      segment[j] = right[i]

      i += 1

      j -= 1

    else:

      break

  res = min(res, sum(segment))

  return res





t = int(input())

for i in range(t):

  print(solution())

Submission (verdict: Wrong answer on test 2):
import math

from collections import deque, defaultdict, Counter

import heapq



def solution():

  n, l ,r = list(map(int, input().split(" ")))

  l -= 1

  r -= 1

  a = list(map(int, input().split(" ")))

  segment = a[l:r+1]

  res = sum(segment)

  left, right = a[:l], a[r+1:]

  left.sort()

  right.sort()

  i, j = 0, len(segment) - 1

  while i < len(left) and j >= 0:

    if left[i] < segment[j]:

      segment[j] = left[i]

      i += 1

      j -= 1

    else:

      break

  res = min(res, sum(segment))

  segment = a[l:r+1]

  i, j = 0, len(segment) - 1

  while i < (len(right)) and j >= 0:

    if right[i] < segment[j]:

      segment[j] = right[i]

      i += 1

      j -= 1

    else:

      break

  res = min(res, sum(segment))

  return res





t = int(input())

for i in range(t):

  print(solution())
Problem: 2060D - Subtract Min Sort
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>

using namespace std;



typedef long long ll;

typedef unsigned long long ull;



#define entf          cout << endl

#define ent           cout << "\n"

#define REP(i, a, b)  for (int i = a; i < b; ++i)

#define REPV(i, a, b) for (int i = a; i >= b; --i)

#define MOD           1000000007

#define PRINT(x) cout << x << endl

#define d(x) cerr << #x << " = " << x << endl  // Pass a variable name and it will print it with the value



#define TESTCASES true



void solve(int tt) {

int n;

cin >> n;



int val;

vector<int> a;

a.reserve(n);

REP(i, 0, n){

cin >> val;

a.push_back(val);

}

if(a[0] > a[1]) {

cout << "NO" << endl;

return;

}



bool ans = true;

for(int i = 0; i < n -2; i++) {

if(a[i] > a[i+1]) {

ans = false;

break;

}

a[i+1] -= a[i];

a[i] -= a[i];

}



cout << (ans ? "YES": "NO") << endl;





}



int main() {

ios::sync_with_stdio(0);

cin.tie(0);



if (TESTCASES) {

int tt; cin >> tt;

REP(i, 1, tt+1) {

solve(i);

}

} else solve(1);



return 0;

}

Submission (verdict: Accepted):
#include <bits/stdc++.h>

using namespace std;



typedef long long ll;

typedef unsigned long long ull;



#define entf          cout << endl

#define ent           cout << "\n"

#define REP(i, a, b)  for (int i = a; i < b; ++i)

#define REPV(i, a, b) for (int i = a; i >= b; --i)

#define MOD           1000000007

#define PRINT(x) cout << x << endl

#define d(x) cerr << #x << " = " << x << endl  // Pass a variable name and it will print it with the value



#define TESTCASES true



void solve(int tt) {

int n;

cin >> n;



int val;

vector<int> a;

a.reserve(n);

REP(i, 0, n){

cin >> val;

a.push_back(val);

}

if(a[0] > a[1]) {

cout << "NO" << endl;

return;

}



bool ans = true;

for(int i = 0; i < n -1; i++) {

if(a[i] > a[i+1]) {

ans = false;

break;

}

int diff = min(a[i], a[i+1]);

a[i+1] -= a[i];

a[i] -= a[i];

}



cout << (ans ? "YES": "NO") << endl;

}



int main() {

ios::sync_with_stdio(0);

cin.tie(0);



if (TESTCASES) {

int tt; cin >> tt;

REP(i, 1, tt+1) {

solve(i);

}

} else solve(1);



return 0;

}
Problem: 2060D - Subtract Min Sort
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>

using namespace std;



typedef long long ll;

typedef unsigned long long ull;



#define entf          cout << endl

#define ent           cout << "\n"

#define REP(i, a, b)  for (int i = a; i < b; ++i)

#define REPV(i, a, b) for (int i = a; i >= b; --i)

#define MOD           1000000007

#define PRINT(x) cout << x << endl

#define d(x) cerr << #x << " = " << x << endl  // Pass a variable name and it will print it with the value



#define TESTCASES true



void solve(int tt) {

int n;

cin >> n;



int val;

vector<int> a;

a.reserve(n);

REP(i, 0, n){

cin >> val;

a.push_back(val);

}

if(a[n-1] < a[n-2]) {

cout << "NO" << endl;

return;

} else {

cout << "YES" << endl;

return;

}



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

if(a[i] > a[i-1]) {

int minVal = min(a[i], a[i+1]);

a[i] -= minVal;

a[i+1] -= minVal;

}

}



// Check if sorted ?

for(int val: a) {

cout << val << ' ';

}

cout << endl;

}



int main() {

ios::sync_with_stdio(0);

cin.tie(0);



if (TESTCASES) {

int tt; cin >> tt;

REP(i, 1, tt+1) {

solve(i);

}

} else solve(1);



return 0;

}
Problem: 2060D - Subtract Min Sort
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>

using namespace std;



typedef long long ll;

typedef unsigned long long ull;



#define entf          cout << endl

#define ent           cout << "\n"

#define REP(i, a, b)  for (int i = a; i < b; ++i)

#define REPV(i, a, b) for (int i = a; i >= b; --i)

#define MOD           1000000007

#define PRINT(x) cout << x << endl

#define d(x) cerr << #x << " = " << x << endl  // Pass a variable name and it will print it with the value



#define TESTCASES true



void solve(int tt) {

int n;

cin >> n;



int val;

vector<int> a;

a.reserve(n);

REP(i, 0, n){

cin >> val;

a.push_back(val);

}

// if(a[0] > a[1]) {

//     cout << "NO" << endl;

//     return;

// }



bool ans = true;

for(int i = 0; i < n -2; i++) {

if(a[i] > a[i+1]) {

ans = false;

break;

}

a[i+1] -= a[i];

a[i] -= a[i];

}



cout << (ans ? "YES": "NO") << endl;





}



int main() {

ios::sync_with_stdio(0);

cin.tie(0);



if (TESTCASES) {

int tt; cin >> tt;

REP(i, 1, tt+1) {

solve(i);

}

} else solve(1);



return 0;

}

Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>

using namespace std;



typedef long long ll;

typedef unsigned long long ull;



#define entf          cout << endl

#define ent           cout << "\n"

#define REP(i, a, b)  for (int i = a; i < b; ++i)

#define REPV(i, a, b) for (int i = a; i >= b; --i)

#define MOD           1000000007

#define PRINT(x) cout << x << endl

#define d(x) cerr << #x << " = " << x << endl  // Pass a variable name and it will print it with the value



#define TESTCASES true



void solve(int tt) {

int n;

cin >> n;



int val;

vector<int> a;

a.reserve(n);

REP(i, 0, n){

cin >> val;

a.push_back(val);

}

if(a[0] > a[1]) {

cout << "NO" << endl;

return;

}



bool ans = true;

for(int i = 0; i < n -2; i++) {

if(a[i] > a[i+1]) {

ans = false;

break;

}

a[i+1] -= a[i];

a[i] -= a[i];

}



cout << (ans ? "YES": "NO") << endl;





}



int main() {

ios::sync_with_stdio(0);

cin.tie(0);



if (TESTCASES) {

int tt; cin >> tt;

REP(i, 1, tt+1) {

solve(i);

}

} else solve(1);



return 0;

}
Problem: 2060D - Subtract Min Sort
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>

using namespace std;



typedef long long ll;

typedef unsigned long long ull;



#define entf          cout << endl

#define ent           cout << "\n"

#define REP(i, a, b)  for (int i = a; i < b; ++i)

#define REPV(i, a, b) for (int i = a; i >= b; --i)

#define MOD           1000000007

#define PRINT(x) cout << x << endl

#define d(x) cerr << #x << " = " << x << endl  // Pass a variable name and it will print it with the value



#define TESTCASES true



void solve(int tt) {

int n;

cin >> n;



int val;

vector<int> a;

a.reserve(n);

REP(i, 0, n){

cin >> val;

a.push_back(val);

}

if(a[n-1] < a[n-2]) {

cout << "NO" << endl;

return;

} else {

cout << "YES" << endl;

return;

}



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

if(a[i] > a[i-1]) {

int minVal = min(a[i], a[i+1]);

a[i] -= minVal;

a[i+1] -= minVal;

}

}



// Check if sorted ?

for(int val: a) {

cout << val << ' ';

}

cout << endl;

}



int main() {

ios::sync_with_stdio(0);

cin.tie(0);



if (TESTCASES) {

int tt; cin >> tt;

REP(i, 1, tt+1) {

solve(i);

}

} else solve(1);



return 0;

}

Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>

using namespace std;



typedef long long ll;

typedef unsigned long long ull;



#define entf          cout << endl

#define ent           cout << "\n"

#define REP(i, a, b)  for (int i = a; i < b; ++i)

#define REPV(i, a, b) for (int i = a; i >= b; --i)

#define MOD           1000000007

#define PRINT(x) cout << x << endl

#define d(x) cerr << #x << " = " << x << endl  // Pass a variable name and it will print it with the value



#define TESTCASES true



void solve(int tt) {

int n;

cin >> n;



int val;

vector<int> a;

a.reserve(n);

REP(i, 0, n){

cin >> val;

a.push_back(val);

}

// if(a[0] > a[1]) {

//     cout << "NO" << endl;

//     return;

// }



bool ans = true;

for(int i = 0; i < n -2; i++) {

if(a[i] > a[i+1]) {

ans = false;

break;

}

a[i+1] -= a[i];

a[i] -= a[i];

}



cout << (ans ? "YES": "NO") << endl;





}



int main() {

ios::sync_with_stdio(0);

cin.tie(0);



if (TESTCASES) {

int tt; cin >> tt;

REP(i, 1, tt+1) {

solve(i);

}

} else solve(1);



return 0;

}
Problem: 2057C - Trip to the Olympiad
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main()
{

    ll t;
    cin >> t;

    while (t--)
    {

        ll l, r;
        cin >> l >> r;

        ll a = 0, b = 0;
        bool found = false;

        for (int i = 20; i >= 0; i--)
        {

            if (((l & (1 << i)) == (r & (1 << i))) && (l & (1 << i)))
            {

                a += (1 << i);
                b += (1 << i);
            }
            else if(((l & (1 << i)) != (r & (1 << i))))
            {

                a += (1 << i);
                for (int j = i - 1; j >= 0; j--)
                    b += (1 << j);
                break;
            }
        }

        ll c;
        for(int i=l;i<=r;i++){
            if(i!=a && i!=b){
                c=i;
                break;
            }
        }
        cout << a << " " << c << " " << b << endl;
    }
}

Submission (verdict: Wrong answer on test 3):
#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main()
{

    ll t;
    cin >> t;

    while (t--)
    {

        ll l, r;
        cin >> l >> r;

        ll a = 0, b = 0;
        bool found = false;

        for (int i = 20; i >= 0; i--)
        {

            if (((l & (1 << i)) == (r & (1 << i))) && (l & (1 << i)))
            {

                a += (1 << i);
                b += (1 << i);
            }
            else if(((l & (1 << i)) != (r & (1 << i))))
            {

                a += (1 << i);
                for (int j = i - 1; j >= 0; j--)
                    b += (1 << j);
                break;
            }
        }

        ll c;
        for(int i=r;i>=l;i--){
            if(i!=a && i!=b){
                c=i;
                break;
            }
        }
        cout << a << " " << c << " " << b << endl;
    }
}
Problem: 2057C - Trip to the Olympiad
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 3):
#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main()
{

    ll t;
    cin >> t;

    while (t--)
    {

        ll l, r;
        cin >> l >> r;

        ll a = 0, b = 0;
        bool found = false;

        for (int i = 20; i >= 0; i--)
        {

            if (((l & (1 << i)) == (r & (1 << i))) && (l & (1 << i)))
            {

                a += (1 << i);
                b += (1 << i);
            }
            else if(((l & (1 << i)) != (r & (1 << i))))
            {

                a += (1 << i);
                for (int j = i - 1; j >= 0; j--)
                    b += (1 << j);
                break;
            }
        }

        ll c;
        for(int i=r;i>=l;i--){
            if(i!=a && i!=b){
                c=i;
                break;
            }
        }
        cout << a << " " << c << " " << b << endl;
    }
}

Submission (verdict: Accepted):
#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main()
{

    ll t;
    cin >> t;

    while (t--)
    {

        ll l, r;
        cin >> l >> r;

        ll a = 0, b = 0;
        bool found = false;

        for (int i = 31; i >= 0; i--)
        {

            if (((l & (1 << i)) == (r & (1 << i))) && (l & (1 << i)))
            {

                a += (1 << i);
                b += (1 << i);
            }
            else if(((l & (1 << i)) != (r & (1 << i))))
            {

                a += (1 << i);
                for (int j = i - 1; j >= 0; j--)
                    b += (1 << j);
                break;
            }
        }

        ll c;
        for(int i=r;i>=l;i--){
            if(i!=a && i!=b){
                c=i;
                break;
            }
        }
        cout << a << " " << c << " " << b << endl;
    }
}
Problem: 2057C - Trip to the Olympiad
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main()
{

    ll t;
    cin >> t;

    while (t--)
    {

        ll l, r;
        cin >> l >> r;

        ll a = 0, b = 0;
        bool found = false;

        for (int i = 20; i >= 0; i--)
        {

            if (((l & (1 << i)) == (r & (1 << i))) && (l & (1 << i)))
            {

                a += (1 << i);
                b += (1 << i);
            }
            else if(((l & (1 << i)) != (r & (1 << i))))
            {

                a += (1 << i);
                for (int j = i - 1; j >= 0; j--)
                    b += (1 << j);
                break;
            }
        }

        ll c;
        for(int i=l;i<=r;i++){
            if(i!=a && i!=b){
                c=i;
                break;
            }
        }
        cout << a << " " << c << " " << b << endl;
    }
}
Problem: 2052A - Adrenaline Rush
Language: C++20 (GCC 13-64)


Submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>

#ifndef ONLINE_JUDGE
#include "template.cpp"
#else
#define debug(...)
#define debugArr(...)
#endif

#define F first
#define S second
// #define int long long
#define double long double
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) (int)x.size()
#define mp(x, y) make_pair(x, y)
#define lb lower_bound
#define ub upper_bound
#define ins insert
#define INF (int)1e18
using namespace std;

using pii = pair<int, int>;
using pdd = pair<double, double>;
using pbb = pair<bool, bool>;
using pcc = pair<char, char>;
using pss = pair<string, string>;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vpii = vector<pair<int, int>>;
using vpdd = vector<pair<double, double>>;
using vpbb = vector<pair<bool, bool>>;
using vpcc = vector<pair<char, char>>;
using vpss = vector<pair<string, string>>;
using vvi = vector<vector<int>>;
using vvd = vector<vector<double>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvs = vector<vector<string>>;
using vvpii = vector<vector<pair<int, int>>>;
using vvpdd = vector<vector<pair<double, double>>>;
using vvpbb = vector<vector<pair<bool, bool>>>;
using vvpcc = vector<vector<pair<char, char>>>;
using vvpss = vector<vector<pair<string, string>>>;

// clang-format off
template <class T> using pq = priority_queue<T>;
template <class T> using pqg = priority_queue<T, vector<T>, greater<T>>;
template <class T> T sqrt_(T elem) {int l=1,r=elem;while(l<=r){int mid=l+(r-l)/2LL;if(mid>elem/mid){r=mid-1;}else{int val=mid*mid;if(val<=elem){l=mid+1;}else{r=mid-1;}}}return r;}
template <class T> T ceil_(T a,T b) {return(a+b-1)/b;};
template <class T> T mod_add(T a,T b,T mod){return((a%mod)+(b%mod))% mod;}
template <class T> T mod_sub(T a,T b,T mod){return((a%mod)-(b%mod)+mod)%mod;}
template <class T> T mod_mul(T a,T b,T mod){return((a%mod)*(b%mod))%mod;}
template <class T> T mod_inv(T a,T mod){T m0=mod,y=0,x=1;if(mod==1)return 0;while(a>1){T q=a/mod;T t=mod;mod=a%mod,a=t;t=y;y=x-q*y;x=t;}if(x<0)x+=m0;return x;}
template <class T> T mod_div(T a,T b,T mod){return mod_mul(a,mod_inv(b,mod),mod);}
// clang-format on
void solve() {
  int n;
  cin >> n;
  vi a(n + 1), pos(n + 1);
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    pos[a[i]] = i;
  }

  vpii ans;

  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      if (pos[i] < pos[j] && i < j) {
        ans.eb(j, i);
        ans.eb(i, j);
      } else if (pos[i] < pos[j]) {
        ans.eb(i, j);
      }
    }
  }

  sort(all(ans));

  cout << sz(ans) << '\n';
  for (const auto &[x, y] : ans) {
    cout << x << ' ' << y << '\n';
  }
  return;
}

signed main() {

  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);

  int tt = 1, count = 1;
  // cin >> tt;
  while (tt--) {
    // cout << "Case #" << count << ": ";
    solve();
    ++count;
  }
  return 0;
}