malteklaes/cpp-code-code_search_net-style huggingface dataset:
#include <bits/stdc++.h>   using namespace std;   inline int gc() {     static const int BUF = 1e7;     static char buf[BUF], *bg = buf + BUF, *ed = bg;     if (bg == ed) fread(bg = buf, 1, BUF, stdin);     return *bg++;   }   inline int ri() {     int x = 0, f = 1, c = gc();     for (; c < 48 || c > 57; f = c ==  -  ? -1 : f, c = gc())       ;     for (; c > 47 && c < 58; x = x * 10 + c - 48, c = gc())       ;     return x * f;   }   const int inf = 0x3f3f3f3f;   const long long infLL = 0x3f3f3f3f3f3f3f3fLL;   const long long mod = 1e9 + 7;   const int maxN = 1e5 + 7;   int n;   int a[maxN];   int ans[maxN];   int BinarySearch(vector<int>& x, int k) {     if (x.size() == 0 || a[x[0]] >= k) return -1;     int l = 0, r = x.size() - 1;     int mid = (l + r) >> 1;     while (l < r) {       if (a[x[mid]] >= k) {         r = mid - 1;         mid = (l + r) >> 1;       } else {         l = mid + 1;         if (a[x[l]] >= k) return x[mid];         mid = (l + r) >> 1;       }     }     return x[r];   }   int main() {     while (cin >> n) {       for (int i = (1); i <= (n); ++i) cin >> a[i];       vector<int> vi;       for (int i = (1); i <= (n); ++i) {         if (vi.empty() || a[i] > a[vi.back()]) {           vi.push_back(i);         } else if (a[i] <= a[vi.back()]) {           vi.pop_back();           --i;         }       }       for (int i = (1); i <= (n); ++i) {         ans[i] = BinarySearch(vi, a[i]);         ans[i] -= i + 1;         if (ans[i] < 0) ans[i] = -1;         cout << ans[i] <<    ;       }     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   signed main() {     int n, k, s;     cin >> n >> k >> s;     vector<int> a(n);     for (int i = 0; i < n; i++) {       cin >> a[i];     }     s = min(s, n * n);     vector<vector<int> > dp1(k + 1, vector<int>(s + 1, 1e9));     dp1[0][0] = 0;     int ans = 1e9;     for (int i = n - 1; i >= 0; i--) {       for (int c = k; c >= 0; c--) {         for (int j = s; j >= 0; j--) {           if (j + c <= s) {             dp1[c][j + c] = min(dp1[c][j + c], dp1[c][j]);           }           if (c + 1 <= k) {             dp1[c + 1][j] = min(dp1[c + 1][j], dp1[c][j] + a[i]);           }           if (c != 0) {             dp1[c][j] = 1e9;           }         }       }     }     for (int j = 0; j <= s; j++) {       ans = min(ans, dp1[k][j]);     }     cout << ans;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   using ll = long long;   ll solve(ll n) {     --n;     ll index = n / 3;     ll off = 1;     for (; index - off >= 0; off <<= 2) {       index -= off;     }     ll fi = index + off;     ll se = off << 1;     for (ll place = off >> 2; place >= 1; place >>= 2) {       ll t = (index / place) % 4;       if (t == 0) {         se += 0 * place;       } else if (t == 1) {         se += 2 * place;       } else if (t == 2) {         se += 3 * place;       } else if (t == 3) {         se += 1 * place;       }     }     ll th = fi ^ se;     if (n % 3 == 0)       return fi;     else if (n % 3 == 1)       return se;     else       return th;   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int t;     cin >> t;     while (t--) {       ll n;       cin >> n;       cout << solve(n) <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   int a[1000 + 10];   int ret[21][21];   int pool[410], two[100];   int main() {     ios::sync_with_stdio(false);     memset(a, 0, sizeof(a));     memset(ret, 0, sizeof(ret));     memset(pool, 0, sizeof(pool));     memset(two, 0, sizeof(two));     int n;     cin >> n;     int t, tag = 0, tt = 0;     for (int i = 0; i < n * n; i++) {       cin >> t;       a[t]++;     }     if (n == 1) {       cout <<  yes             <<   n ;       cout << t <<   n ;       return 0;     }     if (n % 2) {       int cnt = 0;       for (int i = 1; i <= 1000; i++) {         if (a[i] % 4) {           if (a[i] % 2) {             if (cnt == 0) {               ret[n / 2][n / 2] = i;               a[i]--;               cnt = 1;             } else {               cout <<  no                     <<   n ;               return 0;             }           }           if (a[i] % 4) {             two[tt++] = i;             a[i] -= 2;             if (tt > (n - 1)) {               cout <<  no                     <<   n ;               return 0;             }           }         }         while (a[i] > 0) {           pool[tag++] = i;           a[i] -= 4;         }       }       while (tt < (n - 1)) {         two[tt++] = pool[--tag];         two[tt++] = pool[tag];       }       int cnt2 = 0, cnt4 = 0;       for (int i = 0; i * 2 < n; i++) {         for (int j = 0; j * 2 < n; j++) {           if (i == n / 2 && j == n / 2) continue;           if (i == n / 2) {             ret[i][j] = two[cnt2++];             ret[i][n - j - 1] = ret[i][j];           } else if (j == n / 2) {             ret[i][j] = two[cnt2++];             ret[n - i - 1][j] = ret[i][j];           } else {             ret[i][j] = pool[cnt4++];             ret[n - i - 1][n - j - 1] = ret[i][j];             ret[i][n - j - 1] = ret[i][j];             ret[n - i - 1][j] = ret[i][j];           }         }       }     } else {       bool can = true;       for (int i = 1; i <= 1000; i++) {         if (a[i] % 4) {           cout <<  no                 <<   n ;           return 0;         }         while (a[i] > 0) {           pool[tag++] = i;           a[i] -= 4;         }       }       for (int i = 0; i * 2 < n; i++) {         for (int j = 0; j * 2 < n; j++) {           ret[i][j] = pool[i * n / 2 + j];           ret[n - i - 1][n - j - 1] = ret[i][j];           ret[i][n - j - 1] = ret[i][j];           ret[n - i - 1][j] = ret[i][j];         }       }     }     cout <<  yes           <<   n ;     for (int i = 0; i < n; i++) {       for (int j = 0; j < n; j++) {         cout << ret[i][j];         if (j == n - 1)           cout <<   n ;         else           cout <<    ;       }     }   }
#include <bits/stdc++.h>   using namespace std;   struct player {     string name;     long long point;     player() {}     player(string n, long long p) { name = n, point = p; }     bool operator<(const player &p) const {       if (point == p.point) {         return name < p.name;       }       return point > p.point;     }   };   vector<player> vec, tmp;   vector<long long> prize;   long long n, m, x;   string str;   int index_of() {     for (int i = 0; i < vec.size(); i++) {       if (tmp[i].name == str) return i;     }   }   int find_first_pos(int in) {     int j = 0;     for (int i = in; i < tmp.size() && j < prize.size(); i++, j++) {       tmp[i].point += prize[j];     }     for (int i = in - 1; i >= 0 && j < prize.size(); i--, j++) {       tmp[i].point += prize[j];     }     sort(tmp.begin(), tmp.end());     return index_of() + 1;   }   int find_last_pos(int in) {     tmp = vec;     if (prize.size() >= tmp.size()) {       tmp[in].point += prize[tmp.size() - 1];     }     int j = 0;     for (int i = tmp.size() - 1; i >= 0 && j < prize.size(); i--) {       if (i != in) {         player p(tmp[i].name, tmp[i].point + prize[j]);         if (p < tmp[in]) {           tmp[i].point += prize[j];           j++;         }       }     }     sort(tmp.begin(), tmp.end());     return index_of() + 1;   }   bool func(int x, int y) { return x > y; }   int main() {     ios_base::sync_with_stdio(false);     while (cin >> n) {       for (int i = 0; i < n; i++) {         cin >> str >> x;         vec.push_back(player(str, x));       }       sort(vec.begin(), vec.end());       cin >> m;       for (int i = 0; i < m; i++) {         cin >> x;         prize.push_back(x);       }       sort(prize.begin(), prize.end(), func);       cin >> str;       tmp = vec;       long long in = index_of();       long long fir, sec;       fir = find_first_pos(in);       sec = find_last_pos(in);       cout << fir <<     << sec << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long int n, net, i, flag, d;     string str;     cin >> n;     net = 0;     flag = 0;     for (i = 0; i < n; i++) {       cin >> d;       cin >> str;       if ((net == 0) && (str !=  South )) flag = 1;       if ((net == 20000) && (str !=  North )) flag = 1;       if (str ==  South )         net += d;       else if (str ==  North )         net -= d;       if (net > 20000 || net < 0) flag = 1;     }     if (net != 0) flag = 1;     if (flag == 1)       cout <<  NO n ;     else       cout <<  YES n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   char s[1200005];   long long num[30][30];   int b[1200005], c[1200005], cnt, tot;   long long dp[1200005];   int main() {     memset(dp, 0x3f, sizeof dp);     int n, m;     scanf( %d%d , &n, &m);     scanf( %s , s + 1);     for (int i = 1; i <= n; i++) {       if (i >= 2) {         num[s[i - 1] -  a ][s[i] -  a ]++;         num[s[i] -  a ][s[i - 1] -  a ]++;       }       if (i <= n - 1) {         num[s[i + 1] -  a ][s[i] -  a ]++;         num[s[i] -  a ][s[i + 1] -  a ]++;       }     }     int all = (1 << m) - 1;     dp[0] = 0;     for (int i = 1; i <= all; i++) {       tot = cnt = 0;       dp[i] = 1e18;       for (int j = 0; j < m; j++) {         if ((i >> j) & 1) {           b[++cnt] = j;         } else {           c[++tot] = j;         }       }       for (int j = 1; j <= cnt; j++) {         dp[i] = min(dp[i], dp[i ^ (1 << b[j])]);       }       for (int j = 1; j <= cnt; j++) {         for (int k = 1; k <= tot; k++) {           dp[i] += num[b[j]][c[k]] / 2;         }       }     }     cout << dp[all] << endl;   }
#include <bits/stdc++.h>   const int MAXN = 1e6 + 5;   std::vector<int> G[MAXN];   int f[MAXN][26];   void dfs(int v) {     for (register int i = 1; i <= 20; ++i) {       f[v][i] = f[f[v][i - 1]][i - 1];     }     for (auto x : G[v]) {       if (x == f[v][0]) continue;       f[x][0] = v;       dfs(x);     }   }   int n, k;   bool vis[MAXN];   int main() {     scanf( %d%d , &n, &k);     for (register int i = 1; i <= n - 1; ++i) {       int u, v;       scanf( %d%d , &u, &v);       G[u].push_back(v);       G[v].push_back(u);     }     int res = n - k;     f[n][0] = n;     dfs(n);     vis[n] = true;     res--;     for (register int i = n - 1; i >= 1; --i) {       if (vis[i]) continue;       int len = 1, v = i;       for (register int j = 20; j >= 0; --j) {         if (vis[f[v][j]]) continue;         v = f[v][j];         len += (1 << j);       }       if (len <= res) {         res -= len;         int x = i;         while (true) {           if (vis[x]) break;           vis[x] = 1;           x = f[x][0];         }       }     }     for (register int i = 1; i <= n; ++i)       if (!vis[i]) printf( %d  , i);     puts(  );     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int a[100005];   int main() {     int n, x;     cin >> n >> x;     long int sum = 0, zz;     for (int i = 0; i < n; i++) cin >> zz, sum += zz;     if (sum + n - 1 == x)       cout <<  YES n ;     else       cout <<  NO n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   struct qeury {     int a, b, c;   };   const int N = 5000 + 5;   int ans[N][N];   int r[N], cc[N];   int main() {     ios_base ::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     int n, m, k;     cin >> n >> m >> k;     vector<qeury> q;     int a, b, c;     for (int i = 0; i < k; i++) {       cin >> a >> b >> c;       q.push_back({a, b, c});     }     reverse(q.begin(), q.end());     for (int i = 0; i < q.size(); i++) {       a = q[i].a;       b = q[i].b - 1;       c = q[i].c;       if (a == 1) {         if (!r[b]) {           r[b] = 1;           for (int j = 0; j < m; j++) {             if (!ans[b][j]) {               ans[b][j] = c;             }           }         }       } else {         if (!cc[b]) {           cc[b] = 1;           for (int j = 0; j < n; j++) {             if (!ans[j][b]) {               ans[j][b] = c;             }           }         }       }     }     for (int i = 0; i < n; i++) {       for (int j = 0; j < m; j++) {         cout << ans[i][j];         if (j < m - 1) cout <<    ;       }       cout <<   n ;     }   }
#include <bits/stdc++.h>   using namespace std;   const int NMAX = 1e6 + 5;   const int MOD = 998244353;   long long lgput(long long b, long long p) {     long long r = 1;     while (p) {       if (p & 1) {         r = 1LL * r * b % MOD;       }       p >>= 1;       b = b * b % MOD;     }     return r;   }   long long N;   vector<long long> lista[NMAX + 5];   long long good_kids[NMAX + 5];   long long cati[NMAX + 5];   long long total = 0, special = 0;   long long answer = 0;   void solve() {     cin >> N;     for (long long i = 1; i <= N; ++i) {       cin >> cati[i];       for (long long j = 1; j <= cati[i]; ++j) {         long long x;         cin >> x;         good_kids[x]++;         lista[i].push_back(x);       }       total = (total + 1LL * N * cati[i] % MOD) % MOD;     }     for (long long i = 1; i <= N; ++i) {       for (auto gift : lista[i]) {         long long expected =             1LL * lgput(N, MOD - 2) * lgput(cati[i], MOD - 2) % MOD;         expected =             1LL * expected * lgput(N, MOD - 2) % MOD * good_kids[gift] % MOD;         answer = (answer + expected) % MOD;       }     }     cout << answer <<   n ;   }   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     long long t;     t = 1;     while (t--) {       solve();     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     int a, b;     cin >> a >> b;     if (b < a * 2) {       cout <<  NO ;       return 0;     }     cout <<  YES  <<   n ;     for (int i = 0; i < a - 1; i++) cout << 2 <<    ;     cout << b - 2 * (a - 1) <<   n ;     cout << 1 <<   n ;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int N = 1e6 + 4, Mod = 1e9 + 7;   struct Mint {     int res;     Mint() { res = 0; }     Mint(int a) : res(a) {}     friend Mint operator+(Mint A, Mint B) {       return Mint((A.res + B.res >= Mod) ? (A.res + B.res - Mod)                                          : (A.res + B.res));     }     friend Mint& operator+=(Mint& A, Mint B) { return A = A + B; }     friend Mint operator-(Mint A, Mint B) {       B.res = Mod - B.res;       return A + B;     }     friend Mint operator-(Mint A) { return Mint(Mod - A.res); }     friend Mint operator+(Mint A) { return A; }     friend Mint& operator-=(Mint& A, Mint B) { return A = A - B; }     friend Mint operator*(Mint A, Mint B) { return 1ll * A.res * B.res % Mod; }     friend Mint& operator*=(Mint& A, Mint B) { return A = A * B; }     friend Mint operator~(Mint A) {       static Mint res;       res = Mint(1);       static int k;       k = Mod - 2;       for (; k; k >>= 1, A *= A) (k & 1) && (res = res * A, 0);       return res;     }     friend Mint operator/(Mint A, Mint B) { return A * (~B); }     friend Mint& operator/=(Mint& A, Mint B) { return A *= (~B); }     friend Mint operator>>(Mint A, Mint B) { return Mint(A.res / B.res); }     friend Mint& operator>>=(Mint& A, Mint B) { return A = A >> B; }   };   Mint fac[N], ifac[N];   inline Mint C(int n, int k) { return fac[n] * ifac[n - k] * ifac[k]; }   int n, k;   Mint dp[N], pre[N];   int main() {     scanf( %d%d , &n, &k);     fac[0] = Mint(1);     for (register int i = (1); i <= (n); ++i) fac[i] = fac[i - 1] * Mint(i);     ifac[n] = ~fac[n];     for (register int i = (n - 1); i >= (0); --i)       ifac[i] = ifac[i + 1] * Mint(i + 1);     dp[0] = pre[0] = Mint(1);     for (register int i = (1); i <= (n - 1); ++i)       dp[i] =           (pre[i - 1] - ((i - k > 0) ? pre[i - k - 1] : Mint(0))) * fac[i - 1],       pre[i] = pre[i - 1] + dp[i] * ifac[i];     Mint res;     for (register int i = (1); i <= (n); ++i)       res += dp[i - 1] * fac[n - i] * C(n - 1, n - i);     printf( %d n , (fac[n] - res).res);     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main(int argc, char **argv) {     ios_base::sync_with_stdio(false);     cin.tie(0);     ;     int n;     cin >> n;     vector<int> indeg(n);     queue<int> deg1;     vector<int> xorV(n);     for (int i = 0; i < n; i++) {       cin >> indeg[i] >> xorV[i];       if (indeg[i] == 1) deg1.push(i);     }     set<pair<int, int> > edges;     while (deg1.size() > 0) {       int v = deg1.front();       deg1.pop();       int u = xorV[v];       if (--indeg[u] == 1) deg1.push(u);       if (indeg[u] > 0) xorV[u] ^= v;       if (v > u) swap(u, v);       edges.insert({u, v});     }     cout << edges.size() << endl;     for (auto &edg : edges) {       cout << edg.first <<     << edg.second << endl;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   int main() {     long long s, n, in;     cin >> n;     if (n == 1)       cout <<  1  << endl <<  1 ;     else {       for (int i = 1; i <= n; i++) {         s = i * (i + 1);         s = s / 2;         if (n < s) {           in = i - 2;           break;         }       }       cout << in + 1 << endl;       s = 0;       for (int i = 1; i <= in; i++) {         cout << i <<    ;         s += i;       }       cout << n - s;     }     return 0;   }
#include <bits/stdc++.h>   using namespace std;   unsigned int ip[100005];   unsigned int const one = -1;   int main() {     int n, k;     cin >> n >> k;     for (int i = 0; i < n; i++) {       unsigned int a, b, c, d;       scanf( %u.%u.%u.%u , &a, &b, &c, &d);       ip[i] = (a << 24) + (b << 16) + (c << 8) + d;     }     unsigned int mask = 0;     set<unsigned int> S;     for (int i = 1; i < 32; i++) {       mask = one << (32 - i);       for (int j = 0; j < n; j++) {         S.insert(mask & ip[j]);       }       if (S.size() == k) {         unsigned int a, b, c, d;         a = mask >> 24;         b = (mask << 8) >> 24;         c = (mask << 16) >> 24;         d = (mask << 24) >> 24;         printf( %u.%u.%u.%u , a, b, c, d);         return 0;       }       S.clear();     }     cout << -1;     return 0;   }
// Murabito-B 21/04/13   #include <bits/stdc++.h>   using namespace std;   using ll = long long;   void solve() {       int a, b, c;       cin >> a >> b >> c;       for (int i = 0; i <= a - c; ++i) cout << 1;       for (int i = 1; i < c; ++i) cout << 0;       cout <<   1 ;       for (int i = 1; i < b; ++i) cout << 0;       cout <<   n ;   }   int main() {       ios_base::sync_with_stdio(false), cin.tie(0);       int _;       for (cin >> _; _--;) solve();       return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long double pi = acos(-1);   const long long M = 1e9 + 7;   const long long N = 5e5;   const long long INF = 1e9 + 1;   long long n, a[N], x[N], res, ans;   int main() {     cin >> n;     for (int i = 1; i <= n; ++i) {       cin >> a[i];     }     for (int j = 1; j <= n; ++j) {       for (int i = 1; i <= n; ++i) {         if (x[i] != 1 && ans >= a[i]) {           x[i] = 1;           ans++;         }       }       if (ans == n) {         break;       }       res++;       for (int i = n; i >= 1; --i) {         if (x[i] != 1 && ans >= a[i]) {           x[i] = 1;           ans++;         }       }       if (ans == n) {         break;       }       res++;     }     cout << res;     return 0;   }
#include <bits/stdc++.h>   using namespace std;   const int mod = 1e9 + 7;   long long gcd(long long x, long long y) { return y == 0 ? x : gcd(y, x % y); }   long long logg(long long x, long long y) {     if (x == 0) return -1;     return logg(x / y, y) + 1;   }   long long poww(long long a, long long b, long long m) {     if (b == 0) return 1;     long long ans = 1;     ans = poww(a, b >> 1, m);     ans = (ans * ans) % m;     if (b & 1) ans = (ans * a) % m;     return ans;   }   int32_t main() {     ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);     long long n, k;     cin >> n >> k;     long long a[n], b[n];     for (long long i = 0; i < n; i++) cin >> a[i], b[i] = a[i];     sort(b, b + n, greater<long long>());     long long sum = 0;     map<long long, long long> mp;     for (long long i = 0; i < k; i++) sum += b[i], mp[b[i]]++;     long long count = 0;     vector<long long> ans;     for (long long i = 0; i < n; i++) {       if (k == 1) {         ans.push_back(n - i);         break;       }       if (mp.count(a[i]))         count++, ans.push_back(count), count = 0, mp[a[i]]--, k--;       else         count++;       if (mp[a[i]] == 0) mp.erase(a[i]);     }     cout << sum <<   n ;     for (auto i : ans) cout << i <<    ;   }
#include<bits/stdc++.h>   using namespace std;      #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);   #define int long long   #define line cout<< [At  <<__LINE__<< ] <<endl;   #define size(x) ((int)x.size())      namespace Debug{     void __print(signed x){cout << x;}     void __print(long x){cout << x;}     void __print(long long x){cout << x;}     void __print(unsigned x){cout << x;}     void __print(unsigned long x){cout << x;}     void __print(unsigned long long x){cout << x;}     void __print(float x){cout << x;}     void __print(double x){cout << x;}     void __print(long double x){cout << x;}     void __print(char x){cout <<      << x <<     ;}     void __print(const char *x){cout <<     << x <<    ;}     void __print(const string &x){cout <<     << x <<    ;}     void __print(bool x){cout << (x ?  true  :  false );}     template<typename T, typename V> void __print(const pair<T, V> &x){cout <<  { ;__print(x.first);cout <<  , ;__print(x.second);cout <<  } ;}     template<typename T> void __print(const T &x){int f = 0;cout <<  { ;for (auto &i : x) cout << (f++ ?  ,  :   ), __print(i);cout <<  } ;}     void _print(){cout <<  ] <<endl;}     template <typename T, typename... V> void _print(T t, V... v){__print(t);if (sizeof...(v)) cout <<  ,  ;_print(v...);}          #define debug(x...) cout << Line: <<__LINE__<<   [  << #x <<  ] = [ ; _print(x);     #define deb(x...) cout << [  << #x <<  ] = [ ; _print(x);   }using namespace Debug;         const int mod = (int)1e9 + 7ll;      int dp[2000][2000][2], n;      int shoot(int plane, int k, int dir){    if(plane > n || plane < 1 || k == 1)     return 1l;        if(dp[plane][k][dir] != -1)      return dp[plane][k][dir];        int res = 0l;        if(dir == 0){      res = shoot(plane + 1, k, dir);      res += shoot(plane - 1, k - 1, 1 - dir);     }     else{      res = shoot(plane - 1, k, dir);      res += shoot(plane + 1, k - 1, 1 - dir);     }        res %= mod;     return dp[plane][k][dir] = res;   }      void process(){    int k;    cin >> n >> k;    cout << shoot(1, k, 0) <<   n ;   }      signed main() {    IOS;    int t = 1;    cin >> t;    while(t--){     memset(dp, -1, sizeof(dp));     process();    }    return 0;   }
#include <bits/stdc++.h>   using namespace std;   const long long INF = 1e18;   long long n, s, e, x[5001], a[5001], b[5001], c[5001], d[5001];   long long dp[5001][5001], ans = INF;   void init() {     for (int i = 0; i < 5001; i++)       for (int j = 0; j < 5001; j++) dp[i][j] = INF;     cin >> n >> s >> e;     for (int i = 1; i < n + 1; i++) cin >> x[i];     for (int i = 1; i < n + 1; i++) cin >> a[i];     for (int i = 1; i < n + 1; i++) cin >> b[i];     for (int i = 1; i < n + 1; i++) cin >> c[i];     for (int i = 1; i < n + 1; i++) cin >> d[i];   }   long long solve() {     for (int i = 0; i < 5001; i++)       for (int j = 0; j < 5001; j++) dp[i][j] = INF;     dp[0][0] = 0;     for (int i = 1; i < n + 1; i++)       for (int j = 0; j < 5001; j++) {         if (i != n && j == 0) continue;         if (i == s) {           dp[i][j] = min(dp[i][j], dp[i - 1][j + 1] + x[i] + c[i]);           dp[i][j] = min(dp[i][j], dp[i - 1][j - 1] - x[i] + d[i]);         } else if (i == e) {           dp[i][j] = min(dp[i][j], dp[i - 1][j - 1] + b[i] - x[i]);           dp[i][j] = min(dp[i][j], dp[i - 1][j + 1] + a[i] + x[i]);         } else {           if (j >= 2)             dp[i][j] = min(dp[i][j], dp[i - 1][j - 2] + b[i] + d[i] - 2 * x[i]);           if (j > 1 || s < e)             dp[i][j] = min(dp[i][j], dp[i - 1][j] + a[i] + d[i]);           if (j > 1 || s > e)             dp[i][j] = min(dp[i][j], dp[i - 1][j] + c[i] + b[i]);           if (j + 2 <= 5000)             dp[i][j] = min(dp[i][j], dp[i - 1][j + 2] + a[i] + c[i] + 2 * x[i]);         }       }     return dp[n][0];   }   int main() {     init();     ans = min(ans, solve());     cout << ans;   }