(I3
I114
I8
(dp0
Vswap.%l
p1
(Vswap_greedy.cpp
p2
S'#include <iostream>\r\n#include <vector>\r\n\r\nusing namespace std;\r\n\r\nint main ()\r\n{\r\n    cin.tie (nullptr);\r\n    ios::sync_with_stdio (false);\r\n    int N;\r\n    cin >> N;\r\n    basic_string <int> P;\r\n    int for_changeing = 0;\r\n    for (int i = 0 ; i < N ; i ++)\r\n    {\r\n        int a;\r\n        cin >> a;\r\n        P += a;\r\n        if (a != i + 1)\r\n            for_changeing ++;\r\n    }\r\n    vector < pair < int, int > > ans;\r\n    int diff = 0;\r\n    for (int k = 0 ; k < for_changeing ; k ++)\r\n    {\r\n        int Min = -1;\r\n        for (int i = 0 ; i < N ; i ++)\r\n        {\r\n            if (P [i] != i + 1 and P [i] != diff)\r\n            {\r\n                if (Min == -1)\r\n                    Min = i;\r\n                else if (P [i] < P [Min])\r\n                    Min = i;\r\n            }\r\n        }\r\n        if (Min == -1)\r\n            break;\r\n        ///cout << "Move " << P [Min] << " from " << Min << " to " << P [Min] - 1 << "\\n";\r\n        int from = Min, to = P [Min] - 1, step = 1;\r\n        if (from > to)\r\n           step = -1;\r\n        bool error = 0;\r\n        for (int from1 = from ; ((step == -1) ? (from1 > to) : (from1 < to)) ; from1 += step)\r\n            if (P [from1] != from1 + 1 and P [from1 + step] != from1 + step + 1)\r\n            {\r\n\r\n            }\r\n            else\r\n            {\r\n                ///cout << "Try to swap " << P [from1] << " and " << P [from1 + step] << "... Failed!\\n";\r\n                error = 1;\r\n            }\r\n        if (error)\r\n        {\r\n            for_changeing ++;\r\n            diff = P [Min];\r\n            continue;\r\n        }\r\n        else\r\n        {\r\n            diff = 0;\r\n        }\r\n        for (from ; ((step == -1) ? (from > to) : (from < to)) ; from += step)\r\n        {\r\n            swap (P [from], P [from + step]);\r\n            ans.push_back ({from + 1, from + 1 + step});\r\n        }\r\n    }\r\n    cout << ans.size () << "\\n";\r\n    for (auto& x : ans)\r\n        cout << x.first << " " << x.second << "\\n";\r\n}\r\n'
p3
tp4
stp5
.