iidai/codenet huggingface dataset:
Language: C++

#include <iostream>
#include <string>
using namespace std;
int kekka[2];
int prime_or_not[1001];
int prime_list[1001];
int prime_num[1001];
int prime_counter = 0;
void sosuubunnpu() {
    for (int i = 1; i <= 1000; ++i) {
        prime_or_not[i] = 0;
    }
    for (int i = 2; i <= 1000; ++i) {
        for (int j = 2; j <= 1000 / i; ++j) {
            if (prime_or_not[i] == 0) {
                prime_or_not[i * j] = 1;
            }
        }
    }
    for (int i = 2; i <= 1000; ++i) {
        if (prime_or_not[i] == 0) {
            prime_list[prime_counter] = i;
            prime_counter += 1;
        }
    }
}
void innsuubunnkai(int N, int n) {
    int time = 0;
    while (1) {
        if (N % n == 0) {
            N = N / n;
            time++;
        } else {
            break;
        }
    }
    kekka[0] = time;
    kekka[1] = N;
}

int main() {
    sosuubunnpu();
    int N;
    cin >> N;
    int innsuu[11];
    int A[N + 1][11];
    for (int i = 0; i <= 1000; ++i) {
        prime_num[i] = 0;
    }
    unsigned long long result = 1;
    for (int current_num = 2; current_num <= N; ++current_num) {
        kekka[1] = current_num;
        for (int i = 0; i < prime_counter; ++i) {
            innsuubunnkai(kekka[1], prime_list[i]);
            prime_num[i] += kekka[0];
        }
    }
    for (int current_num = 2; current_num <= N; ++current_num) {
        for (int i = 0; i < 11; ++i) {
            innsuu[i] += A[current_num][i];
        }
    }
    for (int i = 0; i < prime_counter; ++i) {
        result = (result * (prime_num[i] + 1)) % 1000000007;
    }
    cout << result << endl;

    return 0;
}

Example test case(s):
input: 3

output: 4
Language: C++

#include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <string>
#include <vector>
#define ll long long int
using namespace std;
int h[6], w[6];

int main() {
    int x, ans = 0;

    cin >> x;

    ans = x + x * x + x * x * x;

    cout << ans << endl;

    return 0;
}

Example test case(s):
input: 2

output: 14
Language: C++

#include <iostream>
using namespace std;
int main() {
    int A, B;
    cin >> A >> B;
    int C = A + B;
    if (A % 3 != 0 && B % 3 != 0 && C % 3 != 0) {
        cout << "Impossible" << endl;
    } else {
        cout << "Possible" << endl;
    }
    return 0;
}

Example test case(s):
input: 4 5

output: Possible
Language: C++

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

void sort(vector<int>& a_rvecIntValue);

int main(void) {
    int iNum = 0;
    cin >> iNum;
    vector<int> vecIntValue;
    while (iNum) {
        int iIntValue = 0;
        cin >> iIntValue;
        vecIntValue.push_back(iIntValue);
        iNum--;
    }

    sort(vecIntValue);

    return 0;
}

void sort(vector<int>& a_rvecIntValue) {
    for (unsigned int i = 0; i < a_rvecIntValue.size(); i++) {
        if (i != 0) {
            int iIntValue = a_rvecIntValue.at(i);
            int j = i - 1;
            while ((j >= 0) && (a_rvecIntValue.at(j) > iIntValue)) {
                a_rvecIntValue.at(j + 1) = a_rvecIntValue.at(j);
                j--;
            }
            a_rvecIntValue.at(j + 1) = iIntValue;
        }

        for (unsigned int k = 0; k < a_rvecIntValue.size(); k++) {
            cout << a_rvecIntValue.at(k);
            if (k != a_rvecIntValue.size() - 1) {
                cout << " ";
            }
        }
        cout << endl;
    }
}

Example test case(s):
input: 6
5 2 4 6 1 3

output: 5 2 4 6 1 3
2 5 4 6 1 3
2 4 5 6 1 3
2 4 5 6 1 3
1 2 4 5 6 3
1 2 3 4 5 6
Language: C++

#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;

template <typename T1, typename T2>
inline void chmin(T1 &a, const T2 &b) {
    if (a > b) a = b;
}
template <typename T1, typename T2>
inline void chmax(T1 &a, const T2 &b) {
    if (a < b) a = b;
}

#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()

int main() {
    int n;
    cin >> n;
    vector<lint> a(n);
    vector<lint> acc(n + 1, 0);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        acc[i + 1] = acc[i] + a[i];
        acc[i + 1] %= MOD;
    }

    lint ans = 0;
    for (int i = 0; i < n; i++) {
        ans += a[i] % MOD * (MOD + acc[n] - acc[i + 1]) % MOD;
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}

Example test case(s):
input: 3
1 2 3

output: 11
Language: C++

#include <iostream>
using namespace std;
string str;

int main() {
    cin >> str;
    if (str[2] == str[3] && str[4] == str[5])
        cout << "Yes\n";
    else
        cout << "No\n";
}

Example test case(s):
input: sippuu

output: Yes
Language: C++

#include <iostream>
using namespace std;

int main() {
    int x;
    cin >> x;
    if (x >= 1200)
        cout << "ARC" << endl;
    else
        cout << "ABC" << endl;
    return 0;
}

Example test case(s):
input: 1000

output: ABC
Language: C++

#include <assert.h>
#include <math.h>

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>

using namespace std;

#define REP(i, n) for (int(i) = 0; (i) < (int)(n); ++(i))
#define REPN(i, m, n) for (int(i) = m; (i) < (int)(n); ++(i))
#define INF (int)2e9
#define MOD (1000 * 1000 * 1000 + 7)
#define Ceil(x, n) (((((x)) + ((n)-1)) / n))
#define CeilN(x, n) (((((x)) + ((n)-1)) / n) * n)
#define FloorN(x, n) ((x) - (x) % (n))
#define IsOdd(x) (((x) & 0x01UL) == 0x01UL)
#define IsEven(x) (!IsOdd((x)))
#define ArrayLength(x) (sizeof(x) / sizeof(x[0]))
#define MAX_QWORD ((QWORD)0xFFFFFFFFFFFFFFFF)
#define M_PI 3.14159265358979323846
typedef long long ll;
typedef unsigned long long int QWORD;
typedef pair<ll, ll> P;

int main() {
    int N;
    cin >> N;
    vector<int> a(N);
    REP(i, N) cin >> a[i];

    int idx = 1;
    int ans = 0;
    REP(i, N) {
        if (a[i] == idx) {
            idx++;
        } else {
            ans++;
        }
    }

    if (idx == 1) {
        cout << -1 << endl;
    } else {
        cout << ans << endl;
    }

    return 0;
}

Example test case(s):
input: 3
2 1 2

output: 1
Language: C++

#include <iostream>

typedef long long ll;

int mat[3000][3000];

ll dp[3000][3000][4];
ll dpl[3000];

int main(int argc, char **argv) {
    int rr, cc, k;

    std::cin >> rr >> cc >> k;
    for (int i = 1; i <= k; i++) {
        int r, c, v;
        std::cin >> r >> c >> v;
        mat[r - 1][c - 1] = v;
    }
    dp[0][0][1] = mat[0][0];
    for (int y = 0; y < rr; y++) {
        for (int x = 0; x < cc; x++) {
            for (int c = 0; c < 4; c++) {
                int v = mat[y][x];
                ll q;
                if (c == 0 || v == 0) {
                    q = (x == 0) ? dpl[x] : std::max(dpl[x], dp[y][x - 1][c]);
                } else {
                    q = (x == 0) ? dpl[x] + v
                                 : std::max(dpl[x] + v,
                                            std::max(dp[y][x - 1][c],
                                                     dp[y][x - 1][c - 1] + v));
                }
                dp[y][x][c] = q;
            }
        }
        for (int x = 0; x < cc; x++) {
            dpl[x] = std::max(std::max(dp[y][x][0], dp[y][x][1]),
                              std::max(dp[y][x][2], dp[y][x][3]));
        }
    }
    std::cout << dpl[cc - 1] << std::endl;
    return 0;
}

Example test case(s):
input: 2 2 3
1 1 3
2 1 4
1 2 5

output: 8
Language: C++

#include <iostream>
#include <string>

using namespace std;

int main() {
    string s;
    cin >> s;
    int a, z;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == 'A') {
            a = i;
            break;
        }
    }
    for (int i = s.size() - 1; i >= 0; i--) {
        if (s[i] == 'Z') {
            z = i;
            break;
        }
    }
    cout << z - a + 1 << endl;
    return 0;
}

Example test case(s):
input: QWERTYASDFZXCV

output: 5
Language: C++

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if (a * b % 2 == 1 && (c + d) % 2 == 1) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
}

Example test case(s):
input: 3 5 1 4

output: No
Language: C++

#include <iostream>
using namespace std;

int N, S;

int main() {
    while (cin >> N && N > 0) {
        int M, m, addup, i;
        M = -1;
        m = 1001;
        addup = 0;
        for (i = 0; i < N; i++) {
            cin >> S;
            addup += S;
            if (S > M) M = S;
            if (S < m) m = S;
        }
        cout << (addup - M - m) / (N - 2) << endl;
    }
}

Example test case(s):
input: 3
1000
342
0
5
2
2
9
11
932
5
300
1000
0
200
400
8
353
242
402
274
283
132
402
523
0

output: 342
7
300
326
Language: C++

#include <limits.h>

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i, n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
using namespace std;

int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    vector<int> a(n);
    REP(i, n) cin >> a[i];
    sort(all(a));
    REP(i, n - 1) {
        if (a[i] == a[i + 1]) {
            cout << "NO" << '\n';
            return 0;
        }
    }
    cout << "YES" << '\n';

    return 0;
}

Example test case(s):
input: 5
2 6 1 4 5

output: YES
Language: C++

#include <iostream>

using namespace std;

unsigned long a[100100];

int main(void) {
    int k;
    unsigned long min, max;
    scanf("%d", &k);

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

    max = 3, min = 2;

    if (a[k - 1] != 2) {
        cout << -1 << endl;
        return 0;
    }

    for (int i = k - 2; i >= 0; i--) {
        if (a[i] > max) {
            cout << -1 << endl;
            return 0;
        } else {
            max = ((max / a[i]) + 1) * a[i] - 1;
            if (min % a[i] != 0) {
                min = ((min / a[i]) + 1) * a[i];
            }
        }

        if (max <= min) {
            cout << -1 << endl;
            return 0;
        }
    }

    printf("%ld %ld\n", min, max);

    return 0;
}

Example test case(s):
input: 4
3 4 3 2

output: 6 8
Language: C++

#include <algorithm>
#include <iostream>
#include <string>

using namespace std;

int main() {
    string str1, str2;
    cin >> str1 >> str2;

    sort(str1.begin(), str1.end());
    sort(str2.rbegin(), str2.rend());

    int loop = str1.length() > str2.length() ? str2.length() : str1.length();
    bool flag = false;

    for (int i = 0; loop > i; i++) {
        char ch1 = str1[i];
        char ch2 = str2[i];

        if (ch1 == ch2) {
            if (loop == i + 1 && str1.length() < str2.length()) {
                flag = true;
                break;
            } else {
                continue;
            }
        } else {
            if (ch2 > ch1) {
                flag = true;
                break;
            } else {
                break;
            }
        }
    }

    if (flag) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Example test case(s):
input: yx
axy

output: Yes
Language: C++

#include <stdlib.h>

#include <iostream>
using namespace std;

int main() {
    string str;
    string tmp;
    int sum;

    while (1) {
        cin >> str;
        if (str == "0") break;
        sum = 0;
        for (int i = 0; i < str.size(); i++) {
            tmp = str[i];
            int num = atoi(tmp.c_str());
            sum += num;
        }

        cout << sum << endl;
    }
    return 0;
}

Example test case(s):
input: 123
55
1000
0

output: 6
10
1
Language: C++

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

#define INF 1 << 29
#define LL long long int

LL const MOD = 1000000007;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    LL n, c;
    cin >> n >> c;

    vector<LL> x(n + 1, 0), v(n + 1, 0);

    for (int i = 1; i < n + 1; i++) {
        cin >> x[i] >> v[i];
    }

    vector<LL> lefttotal(n + 1, 0), maxlefttotal(n + 1, 0);
    for (int i = 1; i < n + 1; i++) {
        lefttotal[i] = lefttotal[i - 1] + v[i];
    }

    for (int i = 1; i < n + 1; i++) {
        maxlefttotal[i] = max(maxlefttotal[i - 1], lefttotal[i] - x[i]);
    }

    vector<LL> righttotal(n + 1, 0), maxrighttotal(n + 1, 0);
    for (int i = 1; i < n + 1; i++) {
        righttotal[i] = righttotal[i - 1] + v[n - i + 1];
    }

    for (int i = 1; i < n + 1; i++) {
        maxrighttotal[i] =
            max(maxrighttotal[i - 1], righttotal[i] - (c - x[n + 1 - i]));
    }

    LL ans = 0;

    for (int i = 1; i < n + 1; i++) {
        ans = max(ans, lefttotal[i] - x[i]);
        ans = max(ans, lefttotal[i] - 2 * x[i] + maxrighttotal[n - i]);
        ans = max(ans, righttotal[i] - (c - x[n + 1 - i]));
        ans = max(ans,
                  righttotal[i] - 2 * (c - x[n + 1 - i]) + maxlefttotal[n - i]);
    }

    cout << ans << endl;

    return 0;
}

Example test case(s):
input: 3 20
2 80
9 120
16 1

output: 191
Language: C++

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

using namespace std;
#define PB push_back
#define MP make_pair
#define REP(i, n) for (int i = 0; i < (n); i++)
int main() {
    int n, ii, a, b;
    cin >> n;
    long long cnt[10][10];
    REP(i, 100) cnt[i % 10][i / 10] = 0;
    for (int i = 1; i <= n; i++) {
        b = i % 10;
        a = i;
        while (a >= 10) {
            a /= 10;
        }
        cnt[a][b]++;
    }
    long long ans = 0;
    for (int i = 1; i <= 9; i++) {
        for (int j = 1; j <= 9; j++) {
            ans += cnt[i][j] * cnt[j][i];
        }
    }
    cout << ans << endl;
}

Example test case(s):
input: 25

output: 17
Language: C++

#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, n) for (int i = n; i >= 0; --i)
const int inf = 1e9 + 7;
const ll mod = 1e9 + 7;
const ll mod1 = 998244353;
const ll big = 1e18;
const double PI = 2 * asin(1);

int main() {
    int N;
    cin >> N;
    vector<ll> A(N);
    for (int i = 0; i < N; ++i) cin >> A[i];
    sort(A.begin(), A.end(), greater<ll>());
    int index;
    ll max = inf;
    for (int i = 1; i < N; ++i) {
        if (max > abs(A[0] - 2 * A[i])) {
            max = abs(A[0] - 2 * A[i]);
            index = i;
        }
    }
    cout << A[0] << " " << A[index] << endl;
}

Example test case(s):
input: 5
6 9 4 2 11

output: 11 6
Language: C++

#include <math.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll) INF* INF
#define MOD 1000000007
#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, a, n) for (int i = a; i < (n); i++)
#define all(in) in.begin(), in.end()
#define shosu(x) fixed << setprecision(x)

#define int ll

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef vector<pii> vp;

int gcd(int a, int b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int ans = INF;
int h = 19, w = 15;
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
int dy[] = {1, 0, -1, 0, 1, -1, 1, -1};
vs s(19);

void dfs(int x, int y, int cnt) {
    if (cnt > 20) return;

    if (x == h - 1) {
        ans = min(ans, cnt);
        return;
    }
    rep(i, 8) {
        int nx = x + dx[i];
        int ny = y + dy[i];
        if (nx < 0 || nx >= h || ny < 0 || ny >= w) continue;
        if (s[nx][ny] != 'X') continue;
        bool c = true;
        while (c && s[nx][ny] == 'X') {
            s[nx][ny] = '.';
            nx += dx[i];
            ny += dy[i];
            if (nx < 0 || nx >= h || ny < 0 || ny >= w) {
                if (nx >= h) ans = min(ans, cnt + 1);
                c = false;
            }
        }
        if (c) dfs(nx, ny, cnt + 1);
        while (nx != x || ny != y) {
            nx -= dx[i];
            ny -= dy[i];
            s[nx][ny] = 'X';
        }
        s[x][y] = '.';
    }
}

signed main(void) {
    rep(i, h) cin >> s[i];
    int sx, sy;
    rep(i, h) rep(j, w) if (s[i][j] == 'O') {
        sx = i, sy = j;
        s[i][j] = '.';
    }
    dfs(sx, sy, 0);
    if (ans == INF)
        cout << -1 << endl;
    else
        cout << ans << endl;
}

Example test case(s):
input: ...............
...............
...............
...............
...............
...............
...............
...............
...............
...............
...............
...............
...............
...............
...............
...............
...............
......O........
......X........

output: 1
Language: C++

#include <iostream>
#include <vector>
#define rep(i, k, n) for (int i = k; i < n; ++i)
using namespace std;

template <class T>
inline void chmin(T &a, T b) {
    if (a > b) a = b;
    return;
}
const int INF = 1 << 30;

int main() {
    vector<int> dp(101000, INF);
    dp.at(0) = 0;

    int N, K;
    cin >> N >> K;
    vector<int> h(N);
    rep(i, 0, N) cin >> h[i];

    rep(i, 0, N) {
        rep(j, 1, K + 1) { chmin(dp[i + j], dp[i] + abs(h[i] - h[i + j])); }
    }

    cout << dp[N - 1] << endl;
    return 0;
}

Example test case(s):
input: 5 3
10 30 40 50 20

output: 30
Language: C++

#include <iostream>
using namespace std;

int main() {
    string s, t;
    cin >> s >> t;
    s += s;
    puts(s.find(t) + 1 ? "Yes" : "No");
}

Example test case(s):
input: kyoto
tokyo

output: Yes
Language: C++

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>
#include <vector>
using namespace std;
#define MOD 7007
struct QUEUE {
    int a, b, c, tot;
} Push;
int F[6][3] = {{1, 1, 0}, {1, 0, 1}, {0, 1, 1},
               {2, 0, 0}, {0, 2, 0}, {0, 0, 2}};
vector<int> Hash[MOD];
bool HASH(int n) {
    for (int i = 0; i < Hash[n % MOD].size(); i++)
        if (n == Hash[n % MOD][i]) return false;
    Hash[n % MOD].push_back(n);
    return true;
}
int main() {
    Push.tot = 0;
    queue<QUEUE> que;
    scanf("%d%d%d", &Push.a, &Push.b, &Push.c);
    que.push(Push);
    while (!que.empty()) {
        QUEUE Fro = que.front();
        if (Fro.a == Fro.b && Fro.b == Fro.c) {
            printf("%d\n", Fro.tot);
            return 0;
        }
        for (int i = 0; i < 6; i++) {
            Push = Fro;
            Push.tot++;
            Push.a += F[i][0];
            Push.b += F[i][1];
            Push.c += F[i][2];
            int n = Push.a * 10000 + Push.b * 100 + Push.c;
            if (!HASH(n)) continue;
            que.push(Push);
        }
        que.pop();
    }
    return 0;
}

Example test case(s):
input: 2 5 4

output: 2
Language: C++

#include <iostream>
using namespace std;
int main() {
    int n;
    int array[100];
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> array[i];
    }

    int sum = 0;
    for (int i = 0; i < n - 1; i++) {
        for (int j = i + 1; j < n; j++) {
            sum += array[i] * array[j];
        }
    }

    cout << sum << endl;
    return (0);
}

Example test case(s):
input: 3
3 1 2

output: 11
Language: C++

#include <iostream>
using namespace std;
int main(void) {
    int i, t, n;
    for (i = 0; i < 4; i++) {
        cin >> t >> n;
        if (t == 1) {
            cout << 6000 * n << endl;
        } else if (t == 2) {
            cout << 4000 * n << endl;
        } else if (t == 3) {
            cout << 3000 * n << endl;
        } else if (t == 4) {
            cout << 2000 * n << endl;
        }
    }
}

Example test case(s):
input: 3 10
1 4
4 1
2 5

output: 30000
24000
2000
20000
Language: C++

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
using namespace std;
long long a[200005];
long long pre[200005];
long long last[200005];
int main() {
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%lld", &a[i]);
    }
    long long sumpre = 0, sumlast = 0;
    for (int i = 1; i < n; i++) {
        sumpre = sumpre + a[i];
        pre[i] = sumpre;
    }
    for (int i = n; i > 1; i--) {
        sumlast = sumlast + a[i];
        last[i] = sumlast;
    }
    long long d = (1ll << 60);
    for (int i = 1; i < n; i++) {
        d = min(d, abs(pre[i] - last[i + 1]));
    }
    printf("%lld\n", d);
}

Example test case(s):
input: 6
1 2 3 4 5 6

output: 1
Language: C++

#include <ctype.h>
#include <math.h>

#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <iomanip>
#include <ios>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
int main() {
    string N;
    cin >> N;
    int S = 0;
    for (int i = 0; i < N.size(); i++) {
        S += N[i] - '0';
    }
    if (stoi(N) % S == 0)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

Example test case(s):
input: 12

output: Yes
Language: C++

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

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> l(n);
    for (int i = 0; i < n; i++) {
        cin >> l[i];
    }

    sort(l.begin(), l.end());

    int ans = 0;
    for (int i = 0; i < k; i++) {
        ans += l[n - 1 - i];
    }
    cout << ans << endl;
}

Example test case(s):
input: 5 3
1 2 3 4 5

output: 12
Language: C++

#include <iostream>
using namespace std;

bool isPalindrome(string s) {
    for (int i = 0; i < s.length() / 2; i++) {
        if (s[i] == s[s.length() - 1 - i])
            continue;
        else
            return false;
    }
    return true;
}

int main() {
    string s;
    cin >> s;
    if (isPalindrome(s) && isPalindrome(s.substr(0, s.length() / 2))) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Example test case(s):
input: akasaka

output: Yes
Language: C++

#include <algorithm>
#include <iostream>
using namespace std;
int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if (a > b) {
        swap(a, b);
    }
    if (b > c) {
        swap(b, c);
    }
    if (a > b) {
        swap(a, b);
    }
    cout << a << " " << b << " " << c << endl;
}

Example test case(s):
input: 3 8 1

output: 1 3 8
Language: C++

#include <iostream>
using namespace std;
int main() {
    int a, b;
    cin >> a >> b;
    cout << a * b << endl;
    return 0;
}

Example test case(s):
input: 2 5

output: 10