# Submissions

{% hint style="danger" %}
**Under construction.**
{% endhint %}

## Sumbit solution

<mark style="color:green;">`POST`</mark> `https://api.sort-me.org/submit`

:key: [<mark style="color:orange;">Authorization required</mark>](/tricky/authorization.md)<mark style="color:orange;">.</mark>

Submit solution to judging.

This method has low, context-adaptive rate limit, so it can't be described with some specific constants.\
If you encounter 429 (Too Many Requests) HTTP error, just retry after 30-60 secs.

#### Request Body

| Name                                          | Type    | Description                                                                |
| --------------------------------------------- | ------- | -------------------------------------------------------------------------- |
| problem\_id<mark style="color:red;">\*</mark> | int     | ID of the task you trying to submit                                        |
| environment<mark style="color:red;">\*</mark> | string  | Language code you are trying to submit                                     |
| files<mark style="color:red;">\*</mark>       | \[]file | Source code of your solution                                               |
| contest\_id                                   | int     | If you are submitting solution during contest, you need to specify its ID. |

{% tabs %}
{% tab title="201: Created Solution submitted" %}

```javascript
{
    id: 1337 // id of your new submission
}
```

{% endtab %}

{% tab title="404: Not Found Problem not found" %}

```javascript
{
    "error": "no such problem or rights to view it"
}
```

{% endtab %}

{% tab title="404: Not Found Contest not found" %}

```javascript
{
    "error": "you are not participant of this contest or is does not exist"
}
```

{% endtab %}

{% tab title="413: Payload Too Large Too big submission" %}

```javascript
{
    "error": "submission is too big",
}
```

{% endtab %}

{% tab title="429: Too Many Requests You are sending submissions too frequent" %}

{% endtab %}
{% endtabs %}

## Get default environments

<mark style="color:blue;">`GET`</mark> `https://api.sort-me.org/submissions/getAvailableLanguages`

On Sort Me, environment is similar to language/compiler on other platforms - for example, GNU C++ 20 or Python 3.11.

With this method, you get default environments, with which you can submit most of publically available problems.

{% tabs %}
{% tab title="200: OK " %}

<pre class="language-javascript"><code class="lang-javascript">[
    {
        "id": 1,
        "name": "Python 3.11",
        <a data-footnote-ref href="#user-content-fn-1">"cmh"</a>: "python",
        "additional_files": true
        "files": {
            {
                "name": "solution.py",
                "type": "text",
                "placeholder": "a, b = map(int, input().split())"
            },
        },
    },
    {
        "name": "PyPy 3.9",
        "highlight": "python",
        "api": "pypy",
        "ext": "py"
    },
    {
        "name": "GNU C++20",
        "highlight": "cpp",
        "api": "c++",
        "ext": "cpp:cc:C"
    }
]
</code></pre>

{% endtab %}
{% endtabs %}

## Get submissions

<mark style="color:blue;">`GET`</mark> `https://api.sort-me.org/submissions/get`

:card\_box: [Pagination applies.](/tricky/pagination.md)

This is universal method for receiving submissions of certain user, problem, contest, or from any intersection of this parameters.

However, submissions on Sort Me are **not public**, so access to submissions is a bit tricky. In general, you can get response, if you are trying to get:

– Your own submissions;\
– Submissions sent during contest where you are admin;\
– Submissions which solves problem you are admin of.

#### Query Parameters

| Name        | Type | Description                                                                                                                                                                                                                                                                                                                                                                   |
| ----------- | ---- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| user\_id    | int  | <p>ID of user whose submissions you want to get.<br><br>If specified, it must be your ID or ID of participant of contest from <code>contest\_id</code> parameter.<br><br>If not specified, get submissions of all users. You must be admin of contest from <code>contest\_id</code> to do this.</p>                                                                           |
| problem\_id | int  | <p>ID of the task you want to get submissions for.</p><p></p><p>If specified, at least one rule must be satisfied:<br>– You are admin of the task</p><p>– You are requesting your own submissions<br>– You are admin of the contest from <code>contest\_id</code> parameter, and that contest contains this task.<br><br>If not specified, get submissions for all tasks.</p> |
| contest\_id | int  | <p>ID of contest, submissions of which you want to get.<br><br>If specified, you must be either admin of the contest or requesting only your own submissions (by providing your ID in <code>user\_id</code> parameter)<br><br>If not specified, get submissions sent not during contests.</p>                                                                                 |
| offset      | int  | <p>Pagination parameter.<br>Use <strong><code>id</code></strong> field.</p>                                                                                                                                                                                                                                                                                                   |

{% tabs %}
{% tab title="200: OK Returns list of submissions" %}

```javascript
{
    "count": 19,
    "submissions": [
        {
            "id": 53459,       // Unique ID of submission
            
            "user": {
                "id": 578,
                "handle": "imachug",
                "avatar": "https://pic.sort-me.org/bd62e50c-7cfa-40d8-9009-f4753d696289g",
            },
            
            "task_id": 2025,
            "contest_id": 35,
            
            "worst_metrics": {
                "time": 961,     // Millisecconds
                "memory": 253,   // Megabytes
            },
            
            "submitted_at": 1665081384,  // Unixtime
            "environment": {
                "name": "GNU C++20",
            },
            
            "verdict": 1,
            "verdict_text": "Full solution",
            "total_points": 100
        }
    ]
}
```

{% endtab %}
{% endtabs %}

## Get submission by ID

<mark style="color:blue;">`GET`</mark> `https://api.sort-me.org/submissions/getByID`

#### Query Parameters

| Name                                 | Type | Description              |
| ------------------------------------ | ---- | ------------------------ |
| id<mark style="color:red;">\*</mark> | int  | ID of target submission. |

{% tabs %}
{% tab title="200: OK Submission found" %}
{% tabs %}
{% tab title="Accepted" %}
Verdicts are set per problem, per subtask and per test. Here are all the types:

* `0` - **Judging.** Solution is still judging.
* `1` - <mark style="color:green;">**Full solution**</mark> (for problem and subtasks) or <mark style="color:green;">**OK**</mark> (for test).
* `2` - <mark style="color:red;">**Wrong Answer**</mark>
* `3` - <mark style="color:red;">**Time limit exceeded**</mark>
* `4` - <mark style="color:red;">**Runtime Error**</mark>
* `5` - <mark style="color:red;">**Compilation Error**</mark>
* `6` - <mark style="color:red;">**Compilation Time Limit Exceeded**</mark>
* `7` - <mark style="color:red;">**Memory Limit Exceeded**</mark>
* `8` - <mark style="color:red;">**Wrong Output Format**</mark>
* `9` - <mark style="color:red;">**Checker Error**</mark>
* `11` - <mark style="color:red;">**Judging Error**</mark>
* `12` - <mark style="color:red;">**Malicious Code**</mark>
* `13` - <mark style="color:orange;">**Skipped**</mark>
* `20` - <mark style="color:orange;">**Partial Solution**</mark>

{% code fullWidth="false" %}

```javascript
{
    "id": 193478,

    "user": {
        "id": 1,
        "handle": "sadfun",
        "avatar": "https://pic.sort-me.org/bd62e50c-7cfa-40d8-9009-f4753d696289"
    },

    "environment": {
        "id": 1,
        "name": "Python 3.11",
        "highlight": "python"
    },

    "files": [
        {
            "name": "solution.py",
            "type": "text",

            "content": "a, b = map(int, input().split())\nprint(a + b)"
        }
    ],

    "submitted_at": 1633036128,

    "results": {
        "points": 100,

        "verdict": 1,
        "verdict_text": "Accepted",

        "worst_metrics": {
            "time": 10,
            "memory": 91
        },

        "subtasks": [
            {
                "points": 100,
                "worst_metrics": {
                    "time": 10,
                    "memory": 91
                },

                "tests": [
                    {
                        "n": 1,
                        "verdict": 1,
                        "verdict_text": "OK",
                        "worst_metrics": {
                            "time": 9,
                            "memory": 87
                        }
                    },
                    {
                        "n": 2,
                        "verdict": 1,
                        "verdict_text": "OK",
                        "worst_metrics": {
                            "time": 9,
                            "memory": 91
                        }
                    },
                    {
                        "n": 3,
                        "verdict": 1,
                        "verdict_text": "OK",
                        "worst_metrics": {
                            "time": 10,
                            "memory": 81
                        }
                    }
                ]
            }
        ]
    }
}
```

{% endcode %}
{% endtab %}

{% tab title="Accepted with subtasks" %}

```javascript
{
    "id": 193478,
    
    "user": {
        "id": 1,
        "handle": "sadfun",
        "avatar": "https://pic.sort-me.org/bd62e50c-7cfa-40d8-9009-f4753d696289"
    },
    
    "environment": {
        "id": 1,
        "name": "Python 3.11",
        "highlight": "python",
    },
    
    "files": [
        {
            "name": "solution.py",
            "type": "text",
            
            "content": "a, b = map(int, input().split())\nprint(a + b)"
        }
    ]
    
    "submitted_at": 1633036128,
    
    "results": {
        "points": 100,
        
        "verdict": 1,
        "verdict_text": "Accepted",
        
        "worst_metrics": {
            "time": 25,
            "memory": 158
        },
        
        "subtasks": [
            {
                "points": 50,
                "worst_metrics": {
                    "time": 25,
                    "memory": 121
                }
            },
            {
                "points": 50,
                "worst_metrics": {
                    "time": 19,
                    "memory": 158
                }
            }
        ]
    }
}
```

{% endtab %}

{% tab title="ZIP submission" %}

<pre class="language-javascript"><code class="lang-javascript">{
    "id": 193478,
    
    "user": {
        "id": 1,
        "handle": "sadfun",
        "avatar": "https://pic.sort-me.org/bd62e50c-7cfa-40d8-9009-f4753d696289"
    },
    
    "environment": {
        "id": 1,
        "name": "Python 3.11",
        "highlight": "python",
    },
    
    "files": [
        {
            "name": "answers.zip",
            "type": "binary",
            "size": 32, // in bytes
            
            <a data-footnote-ref href="#user-content-fn-2">"retain"</a>: 1440,
        }
    ]
    
    "submitted_at": 1633036128,
    
    "results": {
        "points": 100,
        
        "verdict": 1,
        "verdict_text": "Accepted",
        
        "worst_metrics": {
            "time": 25,
            "memory": 158
        },
    }
}
</code></pre>

{% endtab %}

{% tab title="Compilation error" %}
{% code fullWidth="false" %}

```javascript
{
    "id": 2,
    "user": {
        "id": 1,
        "handle": "sadfun",
        "avatar": "https://pic.sort-me.org/bd62e50c-7cfa-40d8-9009-f4753d696289"
    },
    
    "environment": {
        "id": 1,
        "name": "Python 3.11",
        "highlight": "python",
        "ext": "py"
    },
    
    "code": "print(\"Hello world\")",
    "submitted_at": 1664657437,
    "results": {
        "points": 0,
        "verdict": 5,
        "verdict_text": "Compilation error",
        "compiler_log": "solution.cpp:1:6: error: expected constructor, destructor, or type conversion before '(' token\n    1 | print(\"Hello world\")\n      |      ^\ncompilation terminated due to -Wfatal-errors.\nExited with error status 1",
        "worst_metrics": {
            "time": 0,
            "memory": 0
        }
    }
}
```

{% endcode %}
{% endtab %}

{% tab title="Partial solution (TL)" %}

```javascript
{
    "id": 8890,
    "user": {
        "id": 1,
        "handle": "sadfun",
        "avatar": "https://pic.sort-me.org/bd62e50c-7cfa-40d8-9009-f4753d696289"
    },
    "lang": {
        "name": "Python 3.11",
        "highlight": "python",
        "api": "python",
        "ext": "py"
    },
    "code": "c = 0\nfor r in input():\n    if r == \"(\":\n        c += 1\n    else:\n        c -= 1\n        if c < 0:\n            print(\"NO\")\n            break\nelse:\n    print(\"YES\" if c == 0 else \"NO\")",
    "submitted_at": 1642874680,
    "results": {
        "points": 29,
        "verdict": 3,
        "verdict_text": "Time limit exceeded",
        "worst_metrics": {
            "time": 1016,
            "memory": 0
        },
        "subtasks": [
            {
                "points": 29,
                "worst_metrics": {
                    "time": 35,
                    "memory": 0
                }
            },
            {
                "points": 0,
                "worst_metrics": {
                    "time": 1016,
                    "memory": 0
                },
                "failed_tests": [
                    {
                        "n": 26,
                        "verdict": 3,
                        "verdict_text": "Time limit exceeded",
                        "worst_metrics": {
                            "time": 1016,
                            "memory": 0
                        }
                    }
                ]
            }
        ]
    }
}
```

{% endtab %}

{% tab title="Judging in progress" %}

```javascript
{
    "id": 4,
    "user": {
        "id": 1,
        "handle": "sadfun",
        "avatar": "https://pic.sort-me.org/bd62e50c-7cfa-40d8-9009-f4753d696289"
    },
    "lang": {
        "name": "GNU C++20",
        "highlight": "c_cpp",
        "api": "c++",
        "ext": "cpp:cxx:cc"
    },
    "code": "#include <bits/stdc++.h>\r\n\r\n#include <ext/pb_ds/assoc_container.hpp>\r\n\r\n\r\n#define in(x) freopen(x, \"r\", stdin)\r\n#define out(x) freopen(x, \"w\", stdout)\r\n#define F first\r\n#define S second\r\n#define pb push_back\r\n#define sz(x) int(x.size())\r\n#define el '\\n'\r\n#define all(x) x.begin(), x.end()\r\n\r\nusing namespace std;\r\nusing namespace __gnu_pbds;\r\n\r\ntypedef long long ll;\r\ntypedef long double ld;\r\ntypedef short int si;\r\ntypedef unsigned long long ull;\r\ntypedef tree <ll, null_type, less_equal <ll> , rb_tree_tag, tree_order_statistics_node_update> ordered_set;\r\n\r\n\r\nconst int N = (int)5e5 + 50;\r\n\r\nll up[N][20];\r\nll a[N], b[N];\r\nint r[N], n, p[N];\r\n\r\nvector <pair <int, int> > t[2];\r\nvector <int> le[2], ri[2], adds[N];\r\nint root[N][2];\r\n\r\nint make(int p) {\r\n    t[p].pb({0, 0});\r\n    le[p].pb(0);\r\n    ri[p].pb(0);\r\n    return sz(t[p]) - 1;\r\n}\r\n\r\nint make(int v, int p) {\r\n    t[p].pb(t[p][v]);\r\n    le[p].pb(le[p][v]);\r\n    ri[p].pb(ri[p][v]);\r\n    return sz(t[p]) - 1;\r\n}\r\n\r\nvoid upd(int v, int l, int r, int ps, pair <int, int> val, int p) {\r\n    if (l == r) {\r\n        t[p][v] = max(t[p][v], val);\r\n    } else {\r\n        int md = (l + r) >> 1;\r\n        if (ps <= md) {\r\n            int to;\r\n            if (!le[p][v]) {\r\n                to = make(p);\r\n            } else {\r\n                to = make(le[p][v], p);\r\n            }\r\n            le[p][v] = to;\r\n            upd(le[p][v], l, md, ps, val, p);\r\n        } else {\r\n            int to;\r\n            if (!ri[p][v]) {\r\n                to = make(p);\r\n            } else {\r\n                to = make(ri[p][v], p);\r\n            }\r\n            ri[p][v] = to;\r\n            upd(ri[p][v], md + 1, r, ps, val, p);\r\n        }\r\n        t[p][v] = {0, 0};\r\n        if (le[p][v]) {\r\n            t[p][v] = max(t[p][v], t[p][le[p][v]]);\r\n        }\r\n        if (ri[p][v]) {\r\n            t[p][v] = max(t[p][v], t[p][ri[p][v]]);\r\n        }\r\n    }\r\n}\r\n\r\npair <int, int> get(int v, int l, int r, int tl, int tr, int p) {\r\n    if (l > r || tl > tr || tl > r || l > tr) {\r\n        return {-1e9, 0};\r\n    }\r\n    if (l >= tl && r <= tr) {\r\n        return t[p][v];\r\n    }\r\n    int md = (l + r) >> 1;\r\n    pair <int, int> cur = {-(int)1e9, 0};\r\n    if (le[p][v]) {\r\n        cur = max(cur, get(le[p][v], l, md, tl, tr, p));\r\n    }\r\n    if (ri[p][v]) {\r\n        cur = max(cur, get(ri[p][v], md + 1, r, tl, tr, p));\r\n    }\r\n    return cur;\r\n}\r\n\r\nll get(int l, int r) {\r\n    int len = r - l + 1;\r\n    int st = p[len];\r\n    return __gcd(up[l][st], up[r - (1 << st) + 1][st]);\r\n}\r\n\r\nint main() {\r\n//    freopen(\"input.txt\", \"r\", stdin);\r\n//    freopen(\"output.txt\", \"w\", stdout);\r\n    ios::sync_with_stdio(false);\r\n    cin.tie(NULL);\r\n    ll k;\r\n    cin >> n >> k;\r\n    for (int i = 1; i <= n; i++) {\r\n        cin >> a[i];\r\n    }\r\n    for (int i = 1; i < n; i++) {\r\n        b[i] = abs(a[i] - a[i + 1]);\r\n    }\r\n    for (int i = 1; i < n; i++) {\r\n        up[i][0] = b[i];\r\n    }\r\n    p[0] = -1;\r\n    for (int i = 1; i <= n; i++) {\r\n        p[i] = p[i / 2] + 1;\r\n    }\r\n\r\n    for (int st = 1; st <= p[n]; st++) {\r\n        for (int i = 1; i < n; i++) {\r\n            up[i][st] = __gcd(up[i][st - 1], up[min(n - 1, i + (1 << (st - 1)))][st - 1]);\r\n        }\r\n    }\r\n    int ans = 0;\r\n    for (int i = 1, j = 1; i < n; i++) {\r\n        j = max(j, i);\r\n        while (j < n && get(i, j) != 1) {\r\n            j++;\r\n        }\r\n        r[i] = j - 1;\r\n    }\r\n    root[n][0] = make(0); root[n][1] = make(1);\r\n    for (int i = n - 1; i >= 1; i--) {\r\n        root[i][0] = make(root[i + 1][0], 0);\r\n        if (r[i] >= i) {\r\n            upd(root[i][0], 1, n, r[i], {r[i] - i + 2, i}, 0);\r\n            adds[r[i]].pb(i);\r\n        }\r\n    }\r\n    for (int i = n - 1; i >= 1; i--) {\r\n        root[i][1] = make(root[i + 1][1], 1);\r\n        for (auto l : adds[i]) {\r\n            upd(root[i][1], 1, n, l, {n - l, l}, 1);\r\n        }\r\n    }\r\n\r\n    int q, l, r;\r\n    cin >> q;\r\n    while (q--) {\r\n        cin >> l >> r;\r\n        l = (l + ans * 1ll * k - 1) % n + 1; r = (r + ans * 1ll * k - 1) % n + 1;\r\n        if (l > r) {\r\n            swap(l, r);\r\n        }\r\n        r--;\r\n        if (l > r) {\r\n            cout << l << \" \" << l << el;\r\n            ans = 1;\r\n            continue;\r\n        }\r\n        pair <int, int> cur1 = max(get(root[l][0], 1, n, l, r, 0), {1, l});\r\n        pair <int, int> cur2 = get(root[r + 1][1], 1, n, l, r, 1);\r\n        cur2.F = r - (n - cur2.F) + 2;\r\n        if (cur1.F < cur2.F) {\r\n            cout << cur2.S << \" \" << cur2.S + cur2.F - 1 << el;\r\n        } else {\r\n            cout << cur1.S << \" \" << cur1.S + cur1.F - 1 << el;\r\n        }\r\n        ans = max(cur1.F, cur2.F);\r\n    }\r\n}\r\n",
    "submitted_at": 1658142512,
    "results": {
        "points": 0,
        "verdict": 0,
        "verdict_text": "Judging",
        "worst_metrics": {
            "time": 0,
            "memory": 0
        }
    }
}
```

{% endtab %}
{% endtabs %}
{% endtab %}

{% tab title="404: Not Found Submission not found" %}

```javascript
{
    "error": "no submission with such id or you have no rights to view it"
}
```

{% endtab %}
{% endtabs %}

[^1]: Name of language for CodeMirror config.

[^2]: If submitted file is big, Sort Me can decide to store it only for limited amount of time.\
    \
    In this case, `retain` field is presented: it is countdown in minutes to file deletion. If retail is presented and equals to \`-1\`, then file is deleted and cannot be downloaded.&#x20;


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.sort-me.org/api/submissions.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
