buggy_code
stringlengths
11
625k
fixed_code
stringlengths
17
625k
bug_type
stringlengths
2
4.45k
language
int64
0
8
token_count
int64
5
200k
N, K = map(int, input().split()) P = list(map(int, input().split())) C = list(map(int, input().split())) seen = [] roots = [] candidates = [] for i in range(N): if i+1 in seen: continue root = [i+1] seen.append(i+1) to = P[i] while(root[0] != to): root.append(to) seen.appen...
N, K = map(int, input().split()) P = list(map(int, input().split())) C = list(map(int, input().split())) seen = [] roots = [] candidates = [] for i in range(N): if i+1 in seen: continue root = [i+1] seen.append(i+1) to = P[i] while(root[0] != to): root.append(to) seen.appen...
[["+", 0, 7, 8, 196, 0, 57, 15, 679, 17, 355], ["+", 8, 196, 0, 57, 15, 679, 12, 666, 0, 22], ["+", 8, 196, 0, 57, 15, 679, 12, 666, 667, 47], ["+", 8, 196, 0, 57, 15, 679, 12, 666, 0, 612]]
5
327
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; #define pb push_back #define f(i, n) for (int i = 0; i < n; ++i) #define fi(i, st, n) for (int i = st; i <= n; ++i) #define veci vector<int> #define vecp vector<pair<int, int>> #define vecl vector<ll> int prime[100000 + ...
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; #define pb push_back #define f(i, n) for (int i = 0; i < n; ++i) #define fi(i, st, n) for (int i = st; i <= n; ++i) #define veci vector<int> #define vecp vector<pair<int, int>> #define vecl vector<ll> int prime[100000 + ...
[["+", 0, 11, 12, 2, 3, 4, 0, 16, 17, 72], ["+", 3, 4, 0, 16, 12, 16, 31, 69, 28, 22], ["+", 0, 16, 12, 16, 31, 69, 341, 342, 0, 70], ["+", 0, 16, 12, 16, 31, 69, 341, 342, 0, 22], ["+", 0, 16, 12, 16, 31, 69, 341, 342, 0, 73]]
1
830
N,K=map(int,input().split()) P=list(map(int,input().split())) C=list(map(int,input().split())) A=[] S=[] p=2**N-1 for i in range(N): if p>>i&1: s=i+1 tmp=[C[i]] while s!=P[i]: i=P[i]-1 tmp.append(C[i]) p^=1<<i A.append(tmp) S.append(sum(tmp)) ans=-1*(10**9)-1 for i in range(len(A...
N,K=map(int,input().split()) P=list(map(int,input().split())) C=list(map(int,input().split())) A=[] S=[] p=2**N-1 for i in range(N): if p>>i&1: s=i+1 tmp=[C[i]] while s!=P[i]: i=P[i]-1 tmp.append(C[i]) p^=1<<i A.append(tmp) S.append(sum(tmp)) ans=-1*(10**9)-1 for i in range(len(A...
[["+", 0, 57, 64, 196, 0, 1, 0, 662, 31, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 662, 0, 32], ["+", 64, 196, 0, 1, 0, 662, 12, 657, 31, 22], ["+", 64, 196, 0, 1, 0, 662, 12, 657, 17, 109], ["+", 64, 196, 0, 1, 0, 662, 12, 657, 12, 22]]
5
289
#include <bits/stdc++.h> using namespace std; int main() { long long int N, K; cin >> N; cin >> K; vector<long long int> P(N + 1); vector<long long int> C(N + 1); long long int i, j; for (i = 1; i < N + 1; i++) { cin >> P[i]; } for (i = 1; i < N + 1; i++) { cin >> C[i]; } vector<vector<lo...
#include <bits/stdc++.h> using namespace std; int main() { long long int N, K; cin >> N; cin >> K; vector<long long int> P(N + 1); vector<long long int> C(N + 1); long long int i, j; for (i = 1; i < N + 1; i++) { cin >> P[i]; } for (i = 1; i < N + 1; i++) { cin >> C[i]; } vector<vector<lo...
[["-", 28, 23, 0, 2, 3, 4, 0, 16, 17, 72], ["-", 28, 23, 0, 2, 3, 4, 0, 16, 12, 13]]
1
607
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep2(i, s, n) for (int i = (s); i < (int)(n); i++) #define _GLIBCXX_DEBUG template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; // aをbで更新 return true; } return false; } template ...
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define rep2(i, s, n) for (int i = (s); i < (int)(n); i++) #define _GLIBCXX_DEBUG template <typename T> bool chmax(T &a, const T &b) { if (a < b) { a = b; // aをbで更新 return true; } return false; } template ...
[["-", 0, 14, 8, 9, 0, 43, 39, 361, 0, 190], ["+", 8, 9, 0, 14, 8, 9, 0, 43, 39, 78], ["-", 0, 43, 49, 50, 51, 2, 3, 4, 0, 13], ["+", 0, 43, 49, 50, 51, 2, 3, 4, 0, 13], ["-", 0, 16, 12, 16, 12, 2, 3, 4, 0, 13], ["+", 0, 16, 12, 16, 12, 2, 3, 4, 0, 13]]
1
324
#define _USE_MATH_DEFINES #include <algorithm> #include <bitset> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; ...
#define _USE_MATH_DEFINES #include <algorithm> #include <bitset> #include <cmath> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <string> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; ...
[["-", 8, 9, 0, 82, 15, 23, 0, 16, 17, 60], ["+", 8, 9, 0, 82, 15, 23, 0, 16, 17, 79]]
1
321
#include <stdio.h> #define N 5005 typedef long long ll; int to[N][40]; ll sum[N][40], dp[N][40]; // dp[i][j]:i节点走2^j步得到的最大分 #define mx(a, b) ((a) > (b) ? (a) : (b)) int main() { int n, i, j, now, nex; ll k, ans = -1000000009, cnt, tot, packup; scanf("%d%lld", &n, &k); for (i = 1; i <= n; ++i) scanf("%d", to...
// wa&ac #include <stdio.h> #define N 5005 typedef long long ll; int to[N][40]; ll sum[N][40], dp[N][40]; // dp[i][j]:i节点走2^j步得到的最大分 #define mx(a, b) ((a) > (b) ? (a) : (b)) int main() { int n, i, j, now, nex; ll k, ans = -1000000009, cnt, tot, packup; scanf("%d%lld", &n, &k); for (i = 1; i <= n; ++i) scanf...
[["-", 0, 7, 8, 9, 0, 57, 64, 1, 0, 35], ["+", 0, 57, 64, 1, 0, 34, 12, 34, 0, 21]]
1
408
#include <bits/stdc++.h> using namespace std; #define int long long #define REP(i, n) for (int i = 0; i < n; i++) template <typename T> void chmax(T &a, T b) { if (a < b) a = b; } int ans = -1e18, v[5555], c[5555], used[5555]; signed main() { int n, k; cin >> n >> k; REP(i, n) cin >> v[i]; REP(i, n) cin...
#include <bits/stdc++.h> using namespace std; #define int long long #define REP(i, n) for (int i = 0; i < n; i++) template <typename T> void chmax(T &a, T b) { if (a < b) a = b; } int ans = -1e18, v[5555], c[5555], used[5555]; signed main() { int n, k; cin >> n >> k; REP(i, n) cin >> v[i]; REP(i, n) cin...
[["+", 8, 9, 0, 1, 0, 11, 12, 16, 17, 33], ["+", 8, 9, 0, 1, 0, 11, 12, 16, 12, 13]]
1
310
#include <bits/stdc++.h> using namespace std; #define MOD 1000000007 #define ff first #define ss second typedef long long ll; ll power(ll a, ll b) { // a^b ll res = 1; a = a % MOD; while (b > 0) { if (b & 1) { res = (res * a) % MOD; b--; } a = (a * a) % MOD; b >>= 1; } return res; ...
#include <bits/stdc++.h> using namespace std; #define MOD 1000000007 #define ff first #define ss second typedef long long ll; ll power(ll a, ll b) { // a^b ll res = 1; a = a % MOD; while (b > 0) { if (b & 1) { res = (res * a) % MOD; b--; } a = (a * a) % MOD; b >>= 1; } return res; ...
[["-", 0, 14, 8, 9, 0, 1, 0, 16, 31, 22], ["-", 0, 14, 8, 9, 0, 1, 0, 16, 17, 152], ["-", 0, 14, 8, 9, 0, 1, 0, 16, 12, 22], ["-", 0, 30, 0, 14, 8, 9, 0, 1, 0, 35]]
1
604
#include <bits/stdc++.h> #define ll long long using namespace std; const ll mod = 1e9L + 7; int n; vector<vector<ll>> inp; vector<vector<ll>> dp; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); // freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); /*#ifndef ONLINE_JUDGE ...
#include <bits/stdc++.h> #define ll long long using namespace std; const ll mod = 1e9L + 7; int n; vector<vector<ll>> inp; vector<vector<ll>> dp; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); // freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); /*#ifndef ONLINE_JUDGE ...
[["+", 12, 2, 3, 4, 0, 16, 31, 2, 63, 22], ["+", 3, 4, 0, 16, 31, 2, 3, 4, 0, 24], ["+", 3, 4, 0, 16, 31, 2, 3, 4, 0, 21], ["+", 3, 4, 0, 16, 31, 2, 3, 4, 0, 13], ["+", 3, 4, 0, 16, 31, 2, 3, 4, 0, 25]]
1
287
#include <bits/stdc++.h> #define int long long using namespace std; int n, k, ans, c[5001], p[5001]; signed main() { scanf("%lld %lld", &n, &k); for (int i = 1; i <= n; i++) scanf("%lld", &p[i]); for (int i = 1; i <= n; i++) { scanf("%lld", &c[i]); ans = max(ans, c[i]); } for (int i = 1; i <= n; i...
#include <bits/stdc++.h> #define int long long using namespace std; int n, k, ans = -114514114514114514, c[5001], p[5001]; signed main() { scanf("%lld %lld", &n, &k); for (int i = 1; i <= n; i++) scanf("%lld", &p[i]); for (int i = 1; i <= n; i++) { scanf("%lld", &c[i]); ans = max(ans, c[i]); } for...
[["+", 36, 36, 0, 30, 0, 43, 49, 50, 0, 32], ["+", 36, 36, 0, 30, 0, 43, 49, 50, 51, 13], ["-", 0, 43, 49, 50, 51, 41, 15, 23, 0, 24], ["-", 0, 43, 49, 50, 51, 41, 15, 23, 0, 25]]
1
276
from math import log2 n,k=map(int,input().split()) p=list(map(int,input().split())) c=list(map(int,input().split())) k-=1 m=int(log2(k)) nxt=[[0]*n for _ in range(m+1)] point=[[0]*n for _ in range(m+1)] for i in range(n): p[i]-=1 nxt[0][i]=p[i] point[0][i]=c[p[i]] for j in range(m): for i in range(n): nxt...
from math import log2 n,k=map(int,input().split()) p=list(map(int,input().split())) c=list(map(int,input().split())) k-=1 m=int(log2(k)) if 1<k else 1 nxt=[[0]*n for _ in range(m+1)] point=[[0]*n for _ in range(m+1)] for i in range(n): p[i]-=1 nxt[0][i]=p[i] point[0][i]=c[p[i]] for j in range(m): for i in ran...
[["+", 0, 656, 0, 1, 0, 662, 12, 41, 0, 121], ["+", 0, 1, 0, 662, 12, 41, 0, 666, 0, 612], ["+", 0, 1, 0, 662, 12, 41, 0, 666, 667, 18], ["+", 0, 1, 0, 662, 12, 41, 0, 666, 0, 22], ["+", 0, 656, 0, 1, 0, 662, 12, 41, 0, 95], ["+", 0, 656, 0, 1, 0, 662, 12, 41, 0, 612]]
5
384
#include <bits/stdc++.h> using namespace std; #define rep(i, n) REP(i, 0, n) #define REP(i, s, e) for (int i = (s); i < (int)(e); i++) #define repr(i, n) REPR(i, n, 0) #define REPR(i, s, e) for (int i = (int)(s - 1); i >= (int)(e); i--) #define all(r) r.begin(), r.end() #define rall(r) r.rbegin(), r.rend() typedef lon...
#include <bits/stdc++.h> using namespace std; #define rep(i, n) REP(i, 0, n) #define REP(i, s, e) for (int i = (s); i < (int)(e); i++) #define repr(i, n) REPR(i, n, 0) #define REPR(i, s, e) for (int i = (int)(s - 1); i >= (int)(e); i--) #define all(r) r.begin(), r.end() #define rall(r) r.rbegin(), r.rend() typedef lon...
[["+", 0, 16, 12, 23, 0, 16, 31, 23, 0, 24], ["+", 12, 2, 3, 4, 0, 16, 12, 23, 0, 25]]
1
628
def main(): (n,k),p,c=[[*map(int,t.split())]for t in open(0)] m=-10**18 for i in range(n): s=i t=1 x=c[s] while p[s]-1!=i: s=p[s]-1 t+=1 x+=c[s] if x>0: a=k//t*x if a>m:m=a s=i for _ i...
def main(): (n,k),p,c=[[*map(int,t.split())]for t in open(0)] m=-10**18 for i in range(n): s=i t=1 x=c[s] while p[s]-1!=i: s=p[s]-1 t+=1 x+=c[s] if x>0: a=(k//t-1)*x if a>m:m=a s=i for...
[["+", 0, 1, 0, 662, 12, 657, 31, 23, 0, 24], ["+", 0, 662, 12, 657, 31, 23, 0, 657, 17, 33], ["+", 0, 662, 12, 657, 31, 23, 0, 657, 12, 612], ["+", 0, 1, 0, 662, 12, 657, 31, 23, 0, 25], ["+", 12, 652, 3, 4, 0, 657, 31, 657, 12, 22], ["+", 0, 7, 12, 652, 3, 4, 0, 657, 17, 72]]
5
195
#include <bits/stdc++.h> #define fint register int #define h 5010 #define p h #define int long long using namespace std; struct node { int to; int nxt; int val; int from; } e[p]; int cnt; int head[p]; int a[p], pt[p]; int st[p]; int f[h][h]; bool vis[p]; int n, k; int tot; int maxxs = -1e18; inline int read(); ...
#include <bits/stdc++.h> #define fint register int #define h 5010 #define p h #define int long long using namespace std; struct node { int to; int nxt; int val; int from; } e[p]; int cnt; int head[p]; int a[p], pt[p]; int st[p]; int f[h][h]; bool vis[p]; int n, k; int tot; int maxxs = -1e18; inline int read(); ...
[["-", 0, 57, 15, 339, 51, 16, 31, 69, 28, 22], ["-", 15, 339, 51, 16, 31, 69, 341, 342, 0, 70], ["-", 15, 339, 51, 16, 31, 69, 341, 342, 0, 22], ["-", 15, 339, 51, 16, 31, 69, 341, 342, 0, 73], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 31, 22]]
1
579
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> P; typedef long long ll; #define int ll const ll mod = 1e9 + 7; ll cir[5000][5000]; ll sum[5000][5000]; int num[5000]; int n; ll k; int p[5000]; ll c[5000]; ll solver1() { for (int s = 0; s < n; s++) { int t = p[s]; int u = 0; ci...
#include <bits/stdc++.h> using namespace std; typedef pair<int, int> P; typedef long long ll; #define int ll const ll mod = 1e9 + 7; ll cir[5000][5001]; ll sum[5000][5001]; int num[5001]; int n; ll k; int p[5000]; ll c[5000]; ll solver1() { for (int s = 0; s < n; s++) { int t = p[s]; int u = 0; ci...
[["-", 36, 36, 0, 30, 0, 43, 49, 80, 81, 13], ["+", 36, 36, 0, 30, 0, 43, 49, 80, 81, 13], ["-", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["+", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["-", 15, 16, 12, 2, 3, 4, 0, 16, 17, 33], ["-", 15, 16, 12, 2, 3, 4, 0, 16, 12, 13]]
1
423
n,k = map(int,input().split()) pn = list(map(int,input().split())) cn = list(map(int,input().split())) ans = -float("inf") for i in range(n): start=i now=start total = 0 #ループ計 ls = [0] for j in range(1, k+1): now = pn[now]-1 total += cn[now] ans = max(ans, total) ...
n,k = map(int,input().split()) pn = list(map(int,input().split())) cn = list(map(int,input().split())) ans = -float("inf") for i in range(n): start=i now=start total = 0 #ループ計 ls = [0] for j in range(1, k+1): now = pn[now]-1 total += cn[now] ans = max(ans, total) ...
[["-", 3, 4, 0, 206, 206, 663, 0, 657, 31, 22], ["+", 0, 206, 206, 663, 0, 657, 31, 657, 31, 22], ["+", 0, 206, 206, 663, 0, 657, 31, 657, 17, 109], ["+", 0, 206, 206, 663, 0, 657, 31, 657, 12, 22]]
5
208
#include <bits/stdc++.h> using namespace std; #define rep(i, n) rep2(i, 0, n) #define rep2(i, m, n) for (int i = m; i < (n); i++) using ll = long long; using pii = pair<int, int>; using Vi = vector<int>; int main() { long long N, K; cin >> N >> K; Vi P(N); Vi C(N); rep(i, N) { cin >> P[i]; P[i]--;...
#include <bits/stdc++.h> using namespace std; #define rep(i, n) rep2(i, 0, n) #define rep2(i, m, n) for (int i = m; i < (n); i++) using ll = long long; using pii = pair<int, int>; using Vi = vector<int>; int main() { long long N, K; cin >> N >> K; Vi P(N); Vi C(N); rep(i, N) { cin >> P[i]; P[i]--;...
[["+", 0, 52, 8, 9, 0, 1, 0, 27, 28, 22], ["+", 0, 52, 8, 9, 0, 1, 0, 27, 17, 29], ["+", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35]]
1
269
import numpy as np n, k = map(int, input().split()) p = list(map(int, input().split())) c = list(map(int, input().split())) cycles, check = [], [False]*n for pi in p: if not check[pi-1]: curr, cycle = pi, [] check[pi-1] = True while pi != p[curr-1]: check[curr-1] = True ...
import numpy as np n, k = map(int, input().split()) p = list(map(int, input().split())) c = list(map(int, input().split())) cycles, check = [], [False]*n for pi in p: if not check[pi-1]: curr, cycle = pi, [] check[pi-1] = True while pi != p[curr-1]: check[curr-1] = True ...
[["-", 63, 319, 500, 206, 206, 663, 0, 657, 17, 33], ["-", 63, 319, 500, 206, 206, 663, 0, 657, 12, 612]]
5
296
#include <bits/stdc++.h> #include <iostream> //#include <algorithm> // #include <iomanip> #define ll long long #define map unordered_map #define set unordered_set #define pll pair<ll, ll> #define vll vector<ll> #define mll map<ll, ll> using namespace std; const ll MOD = 1000000007LL; const ll INF = (1LL << 60LL); i...
#include <bits/stdc++.h> #include <iostream> //#include <algorithm> // #include <iomanip> #define ll long long #define map unordered_map #define set unordered_set #define pll pair<ll, ll> #define vll vector<ll> #define mll map<ll, ll> using namespace std; const ll MOD = 1000000007LL; const ll INF = (1LL << 60LL); i...
[["+", 12, 16, 12, 23, 0, 16, 31, 23, 0, 24], ["+", 12, 23, 0, 16, 12, 2, 3, 4, 0, 25]]
1
319
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 5005; ll p[N], c[N]; ll cnt[N]; int n, k; int main() { scanf("%d %d", &n, &k); for (int i = 1; i <= n; i++) scanf("%lld", &p[i]); for (int i = 1; i <= n; i++) scanf("%lld", &c[i]); ll ans = -1e18; for (int i = 1; i <= n...
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 5005; ll p[N], c[N]; ll cnt[N]; int n, k; int main() { scanf("%d %d", &n, &k); for (int i = 1; i <= n; i++) scanf("%lld", &p[i]); for (int i = 1; i <= n; i++) scanf("%lld", &c[i]); ll ans = -1e18; for (int i = 1; i <= n...
[["-", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44], ["+", 0, 1, 0, 2, 3, 4, 0, 5, 0, 44]]
1
267
#include <bits/stdc++.h> using namespace std; using vi = vector<int>; using vc = vector<char>; using vs = vector<string>; using vvi = vector<vector<int>>; using vvc = vector<vector<char>>; typedef long long ll; struct edge { int to; ll score; }; using Graph = vector<edge>; int main() { int N; ll K, ans = -10...
#include <bits/stdc++.h> using namespace std; using vi = vector<int>; using vc = vector<char>; using vs = vector<string>; using vvi = vector<vector<int>>; using vvc = vector<vector<char>>; typedef long long ll; struct edge { int to; ll score; }; using Graph = vector<edge>; int main() { int N; ll K, ans = -10...
[["-", 8, 9, 0, 57, 15, 339, 51, 11, 17, 32], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 60]]
1
379
#include <algorithm> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <stack> #include <string> #include <vector> #define PI 3.14159265359 typedef long long ll; const int MOD = 1e9 + 7; const ll LLINF = 1e18; using namespace std; ll llmax(ll x, ll y) { ...
#include <algorithm> #include <deque> #include <iomanip> #include <iostream> #include <map> #include <math.h> #include <queue> #include <stack> #include <string> #include <vector> #define PI 3.14159265359 typedef long long ll; const int MOD = 1e9 + 7; const ll LLINF = 1e18; using namespace std; ll llmax(ll x, ll y) { ...
[["+", 12, 16, 12, 23, 0, 16, 31, 23, 0, 24], ["+", 49, 50, 51, 16, 12, 16, 12, 23, 0, 25]]
1
299
import java.util.ArrayList; import java.util.NoSuchElementException; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = nextInt(scanner); int k = nextInt(scanner); int[] p = new int[n]; int[] c = new int[n]; ...
import java.util.ArrayList; import java.util.NoSuchElementException; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int n = nextInt(scanner); int k = nextInt(scanner); int[] p = new int[n]; long[] c = new long[n]; ...
[["-", 8, 196, 0, 503, 39, 224, 468, 506, 0, 507], ["+", 8, 196, 0, 503, 39, 224, 468, 506, 0, 96], ["-", 0, 503, 49, 200, 51, 227, 39, 506, 0, 507], ["+", 0, 503, 49, 200, 51, 227, 39, 506, 0, 96], ["-", 8, 196, 0, 503, 39, 513, 0, 237, 0, 78], ["+", 8, 196, 0, 503, 39, 513, 0, 237, 0, 78]]
3
595
n, k = map(int, input().split()) p = list(map(int, input().split())) c = list(map(int, input().split())) for i in range(n): p[i] -= 1 ans = -float('inf') for st in range(n): x = st score = [] tot = 0 while True: x = p[x] score.append(c[x]) tot += c[x] if x == st: ...
n, k = map(int, input().split()) p = list(map(int, input().split())) c = list(map(int, input().split())) for i in range(n): p[i] -= 1 ans = -float('inf') for st in range(n): x = st score = [] tot = 0 while True: x = p[x] score.append(c[x]) tot += c[x] if x == st: ...
[["-", 0, 7, 8, 196, 0, 1, 0, 677, 31, 22], ["+", 0, 7, 8, 196, 0, 1, 0, 677, 31, 22]]
5
193
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(n) for (ll i = 0; i < n; ++i) #define rep2(i, n) for (ll i = 0; i < n; ++i) #define rep3(i, a, b) for (ll i = a; i < b; ++i) #define rep4(i, a, b, c) for (ll i = a; i < b; i += c) #define erep(n) for (ll i = 0; i <= n; ++i) #define erep2(i,...
#include <bits/stdc++.h> using namespace std; using ll = long long; #define rep(n) for (ll i = 0; i < n; ++i) #define rep2(i, n) for (ll i = 0; i < n; ++i) #define rep3(i, a, b) for (ll i = a; i < b; ++i) #define rep4(i, a, b, c) for (ll i = a; i < b; i += c) #define erep(n) for (ll i = 0; i <= n; ++i) #define erep2(i,...
[["-", 0, 14, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 14, 8, 9, 0, 43, 49, 50, 51, 22]]
1
507
import sys input = sys.stdin.readline n, k = map(int, input().split()) p = list(map(int, input().split())) c = list(map(int, input().split())) js = [None for _ in range(n)] # 周期とスコア増分 for s in range(n): if js[s]: continue m = s tmp = 0 memo = [[] for _ in range(n)] i = 0 while True: ...
import sys input = sys.stdin.readline n, k = map(int, input().split()) p = list(map(int, input().split())) c = list(map(int, input().split())) js = [None for _ in range(n)] # 周期とスコア増分 for s in range(n): if js[s]: continue m = s tmp = 0 memo = [[] for _ in range(n)] i = 0 while True: ...
[["-", 0, 656, 0, 1, 0, 662, 12, 664, 28, 612], ["+", 0, 656, 0, 1, 0, 662, 12, 664, 28, 612], ["+", 3, 4, 0, 657, 12, 657, 12, 23, 0, 24], ["+", 3, 4, 0, 657, 12, 657, 12, 23, 0, 25]]
5
337
#include <bits/stdc++.h> using namespace std; inline long long read() { long long s = 0, w = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') w = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { s = s * 10 + ch - '0'; ch = getchar(); } return s * w; } lon...
#include <bits/stdc++.h> using namespace std; inline long long read() { long long s = 0, w = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') w = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { s = s * 10 + ch - '0'; ch = getchar(); } return s * w; } lon...
[["-", 0, 7, 8, 9, 0, 57, 75, 76, 0, 95], ["+", 0, 11, 12, 16, 31, 23, 0, 16, 17, 33], ["+", 0, 11, 12, 16, 31, 23, 0, 16, 12, 13], ["+", 0, 43, 49, 50, 51, 16, 31, 16, 12, 22], ["+", 64, 9, 0, 43, 49, 50, 51, 16, 17, 72]]
1
360
#include <algorithm> #include <cctype> #include <cmath> #include <cstdio> #include <cstring> #include <deque> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> #define fir first #define sec second using namesp...
#include <algorithm> #include <cctype> #include <cmath> #include <cstdio> #include <cstring> #include <deque> #include <functional> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> #define fir first #define sec second using namesp...
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 20], ["-", 3, 4, 0, 16, 12, 2, 3, 4, 0, 22], ["+", 3, 4, 0, 16, 12, 2, 3, 4, 0, 22]]
1
527
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; vector<int> p(n), c(n); for (int i = 0; i < n; i++) { cin >> p.at(i); p.at(i)--; } for (int i = 0; i < n; i++) { cin >> c.at(i); } vector<vector<int>> G(n, vector<int>()); int64_t ans = -1e18; for (int i ...
#include <bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; vector<int> p(n), c(n); for (int i = 0; i < n; i++) { cin >> p.at(i); p.at(i)--; } for (int i = 0; i < n; i++) { cin >> c.at(i); } vector<vector<int>> G(n, vector<int>()); int64_t ans = -1e18; for (int i ...
[["+", 12, 16, 12, 23, 0, 16, 31, 23, 0, 24], ["+", 3, 4, 0, 16, 12, 16, 12, 23, 0, 25]]
1
300
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) #define INF 1000000007 using namespace std; int main() { long n, k; cin >> n >> k; long p[n], c[n]; rep(i, n) { cin >> p[i]; p[i]--; } rep(i, n) cin >> c[i]; long ans = -INF; long flag[n][n]; rep(i, n) rep(j, n) flag[i][j]...
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) #define INF 1000000007 using namespace std; int main() { long n, k; cin >> n >> k; long p[n], c[n]; rep(i, n) { cin >> p[i]; p[i]--; } rep(i, n) cin >> c[i]; long ans = -INF; long flag[n][n]; rep(i, n) rep(j, n) flag[i][j]...
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 20]]
1
312
def solve(): from collections import defaultdict class UnionFind(): def __init__(self, n): self.n = n self.par = [-1] * n def find(self, x): if self.par[x] < 0: return x else: while self.par[x] > 0: ...
def solve(): from collections import defaultdict class UnionFind(): def __init__(self, n): self.n = n self.par = [-1] * n def find(self, x): if self.par[x] < 0: return x else: while self.par[x] >= 0: ...
[["-", 75, 76, 8, 196, 0, 52, 15, 666, 667, 47], ["+", 75, 76, 8, 196, 0, 52, 15, 666, 667, 20]]
5
436
import bisect import collections import copy import functools import heapq import math import sys from collections import deque from collections import defaultdict input = sys.stdin.readline sys.setrecursionlimit(10**9) MOD = 10**9+7 N,K = map(int,input().split()) P = list(map(int,input().split())) C = list(map(int,in...
import bisect import collections import copy import functools import heapq import math import sys from collections import deque from collections import defaultdict input = sys.stdin.readline sys.setrecursionlimit(10**9) MOD = 10**9+7 N,K = map(int,input().split()) P = list(map(int,input().split())) C = list(map(int,in...
[["+", 0, 657, 12, 652, 3, 4, 0, 206, 0, 70], ["+", 12, 652, 3, 4, 0, 206, 206, 663, 0, 102], ["+", 12, 652, 3, 4, 0, 206, 206, 663, 0, 22], ["+", 0, 657, 12, 652, 3, 4, 0, 206, 0, 73]]
5
497
#include <bits/stdc++.h> using namespace std; #define ll long long int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll n, k; cin >> n >> k; vector<ll> p(n), v(n); for (ll i = 0; i < n; i++) cin >> p[i]; for (ll i = 0; i < n; i++) cin >> v[i]; ll ans = INT_MIN; for (ll i = 0; i < n...
#include <bits/stdc++.h> using namespace std; #define ll long long int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ll n, k; cin >> n >> k; vector<ll> p(n), v(n); for (ll i = 0; i < n; i++) cin >> p[i]; for (ll i = 0; i < n; i++) cin >> v[i]; ll ans = INT_MIN; for (ll i = 0; i < n...
[["-", 64, 9, 0, 43, 49, 50, 51, 16, 12, 22], ["+", 64, 9, 0, 43, 49, 50, 51, 16, 12, 22], ["-", 64, 9, 0, 82, 8, 9, 0, 1, 0, 35], ["-", 0, 82, 8, 9, 0, 1, 0, 27, 28, 22], ["-", 0, 82, 8, 9, 0, 1, 0, 27, 17, 29]]
1
315
#include <algorithm> #include <bits/stdc++.h> #include <cctype> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #includ...
#include <algorithm> #include <bits/stdc++.h> #include <cctype> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <utility> #includ...
[["-", 36, 36, 36, 36, 0, 30, 0, 43, 39, 40], ["+", 36, 36, 36, 36, 0, 30, 0, 43, 39, 78], ["-", 0, 1, 0, 11, 12, 69, 341, 342, 0, 22], ["+", 0, 1, 0, 11, 12, 69, 341, 342, 0, 22]]
1
1,306
def max(a,b); a > b ? a : b; end def min(a,b); a < b ? a : b; end def extract_cycle(s, used) cycle = [] u = s until used[u] used[u] = true cycle << u u = P[u] end return cycle end N, K = gets.split.map(&:to_i) P = gets.split.map(&:to_i).tap{|array| array.unshift(0) } C = gets.split.map(&:to_i)...
def max(a,b); a > b ? a : b; end def min(a,b); a < b ? a : b; end def extract_cycle(s, used) cycle = [] u = s until used[u] used[u] = true cycle << u u = P[u] end return cycle end N, K = gets.split.map(&:to_i) P = gets.split.map(&:to_i).tap{|array| array.unshift(0) } C = gets.split.map(&:to_i)...
[["-", 0, 738, 31, 738, 12, 652, 486, 742, 500, 22], ["+", 0, 738, 31, 738, 12, 652, 486, 742, 500, 22], ["-", 196, 196, 8, 734, 0, 738, 12, 742, 500, 22], ["+", 196, 196, 8, 734, 0, 738, 12, 742, 500, 22]]
4
316
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; using ll = long long; using pii = pair<int, int>; int main() { int n, k; cin >> n >> k; vector<int> p(n), c(n); rep(i, n) { cin >> p[i]; p[i]--; } rep(i, n) { cin >> c[i]; } ll ans = -1e18; rep(i, n) {...
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; using ll = long long; using pii = pair<int, int>; int main() { int n, k; cin >> n >> k; vector<int> p(n), c(n); rep(i, n) { cin >> p[i]; p[i]--; } rep(i, n) { cin >> c[i]; } ll ans = -1e18; rep(i, n) {...
[["+", 12, 16, 12, 23, 0, 16, 31, 23, 0, 24], ["+", 0, 1, 0, 11, 12, 16, 12, 23, 0, 25]]
1
250
/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* 4.cpp :+: :+: :+: ...
#include <bits/stdc++.h> #define _GLIBCXX_DEBUG #define vv(T) std::vector<std::vector<T>> #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() using namespace std; using ll = long long; int main(void) { int n, k; cin >> n >> k; vector<int> P(n); for (int i = 0; i < n; i++) { cin...
[["+", 8, 9, 0, 1, 0, 11, 12, 16, 17, 33], ["+", 8, 9, 0, 1, 0, 11, 12, 16, 12, 13], ["+", 0, 7, 15, 16, 12, 16, 31, 16, 12, 22], ["+", 8, 9, 0, 7, 15, 16, 12, 16, 17, 72]]
1
315
#include <bits/stdc++.h> //Ithea Myse Valgulious namespace chtholly { typedef long long ll; #define re0 register int #define rel register ll #define rec register char #define gc getchar //#define gc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<23,stdin),p1==p2)?-1:*p1++) #define pc putchar #define p32 pc(' ') #define pl puts...
#include <bits/stdc++.h> //Ithea Myse Valgulious namespace chtholly { typedef long long ll; #define re0 register int #define rel register ll #define rec register char #define gc getchar //#define gc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<23,stdin),p1==p2)?-1:*p1++) #define pc putchar #define p32 pc(' ') #define pl puts...
[["-", 0, 43, 39, 344, 3, 347, 0, 77, 39, 40], ["+", 0, 43, 39, 344, 3, 347, 0, 77, 39, 78]]
1
646
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for (int i = 0; i < n; i++) #define REPR(i, n) for (int i = n; i >= 0; i--) #define FOR(i, m, n) for (int i = m; i < n; i++) #define ALL(obj) (obj).begin(), (obj).end() #define INF 1e9 #define LINF 1e18 typedef long long ll; int main() { ll N, K; cin...
#include <bits/stdc++.h> using namespace std; #define REP(i, n) for (int i = 0; i < n; i++) #define REPR(i, n) for (int i = n; i >= 0; i--) #define FOR(i, m, n) for (int i = m; i < n; i++) #define ALL(obj) (obj).begin(), (obj).end() #define INF 1e9 #define LINF 1e18 typedef long long ll; int main() { ll N, K; cin...
[["+", 0, 9, 0, 43, 49, 50, 51, 16, 17, 72], ["+", 0, 9, 0, 43, 49, 50, 51, 16, 12, 22], ["+", 0, 9, 0, 43, 49, 50, 51, 16, 17, 33], ["+", 0, 9, 0, 43, 49, 50, 51, 16, 12, 13]]
1
386
#include <bits/stdc++.h> using std::cin; using std::cout; const int N = 5005; int n, c[N], p[N]; long long ans = -0x3f3f3f3f3f3f3f3f, k; int main() { std::ios::sync_with_stdio(false); cin >> n >> k; for (int i = 1; i <= n; ++i) cin >> p[i]; for (int i = 1; i <= n; ++i) cin >> c[i]; for (int i = 1; i <...
#include <bits/stdc++.h> using std::cin; using std::cout; const int N = 5005; int n, c[N], p[N]; long long ans = -0x3f3f3f3f3f3f3f3f, k; int main() { std::ios::sync_with_stdio(false); cin >> n >> k; for (int i = 1; i <= n; ++i) cin >> p[i]; for (int i = 1; i <= n; ++i) cin >> c[i]; for (int i = 1; i <...
[["-", 8, 9, 0, 1, 0, 11, 12, 69, 28, 22], ["+", 8, 9, 0, 1, 0, 11, 12, 69, 28, 22]]
1
255
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; using ll = long long; int main() { // ios::sync_with_stdio(false); int N, K; cin >> N >> K; vector<int> P(N + 1); rep(i, N) cin >> P[i + 1]; vector<ll> C(N + 1); rep(i, N) cin >> C[i + 1]; ll ans = -1e10; f...
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; using ll = long long; int main() { // ios::sync_with_stdio(false); int N, K; cin >> N >> K; vector<int> P(N + 1); rep(i, N) cin >> P[i + 1]; vector<ll> C(N + 1); rep(i, N) cin >> C[i + 1]; ll ans = -1e10; f...
[["+", 0, 11, 12, 16, 31, 23, 0, 16, 17, 33], ["+", 0, 11, 12, 16, 31, 23, 0, 16, 12, 13], ["+", 0, 1, 0, 11, 12, 16, 31, 16, 12, 22], ["+", 0, 9, 0, 1, 0, 11, 12, 16, 17, 72]]
1
344
#include <algorithm> #include <bitset> #include <cmath> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <vector> typedef long long ll; using namespace std; const ll MOD = 10000000...
#include <algorithm> #include <bitset> #include <cmath> #include <cstring> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <stack> #include <string> #include <vector> typedef long long ll; using namespace std; const ll MOD = 10000000...
[["+", 64, 16, 12, 23, 0, 16, 31, 23, 0, 24], ["+", 12, 23, 0, 41, 64, 16, 12, 23, 0, 25]]
1
274
#include <bits/stdc++.h> using namespace std; int main() { long long N, K; cin >> N >> K; vector<long long> P(N), C(N); for (int i = 0; i < N; i++) { cin >> P[i]; P[i]--; } for (int i = 0; i < N; i++) cin >> C[i]; long long ans = C[0]; for (int i = 0; i < N; i++) { long long cnt = 1, n...
#include <bits/stdc++.h> using namespace std; int main() { long long N, K; cin >> N >> K; vector<long long> P(N), C(N); for (int i = 0; i < N; i++) { cin >> P[i]; P[i]--; } for (int i = 0; i < N; i++) cin >> C[i]; long long ans = C[0]; for (int i = 0; i < N; i++) { long long cnt = 1, n...
[["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 106], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 31, 22], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 17, 60], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 12, 22]]
1
282
#include <bits/stdc++.h> // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> // using namespace __gnu_pbds; using namespace std; #define ll long long #define PI acos(-1) #define pb push_back #define ins insert #define INF 5000000000000000007 // 1e18+7 #define mk make_pair #define ff fi...
#include <bits/stdc++.h> // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> // using namespace __gnu_pbds; using namespace std; #define ll long long #define PI acos(-1) #define pb push_back #define ins insert #define INF 5000000000000000007 // 1e18+7 #define mk make_pair #define ff fi...
[["-", 0, 57, 64, 9, 0, 7, 15, 16, 17, 19], ["-", 0, 57, 64, 9, 0, 7, 15, 16, 12, 22], ["+", 0, 57, 64, 9, 0, 7, 15, 16, 17, 18], ["+", 64, 9, 0, 7, 15, 16, 12, 2, 63, 22], ["+", 0, 7, 15, 16, 12, 2, 3, 4, 0, 24], ["+", 0, 7, 15, 16, 12, 2, 3, 4, 0, 22], ["+", 0, 7, 15, 16, 12, 2, 3, 4, 0, 25]]
1
1,068
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; //#define ll long long template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1;...
#include <bits/stdc++.h> using namespace std; using ll = long long; using ull = unsigned long long; //#define ll long long template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1;...
[["+", 0, 1, 0, 2, 3, 4, 0, 16, 17, 72], ["+", 0, 1, 0, 2, 3, 4, 0, 16, 12, 22]]
1
530
import sys from itertools import accumulate input = sys.stdin.readline class UnionFind: """Union Find class. "Path compression" and "Union by rank" are used. References: <https://en.wikipedia.org/wiki/Disjoint-set_data_structure> """ def __init__(self, N): self.N = N se...
import sys from itertools import accumulate input = sys.stdin.readline class UnionFind: """Union Find class. "Path compression" and "Union by rank" are used. References: <https://en.wikipedia.org/wiki/Disjoint-set_data_structure> """ def __init__(self, N): self.N = N se...
[["+", 0, 7, 12, 652, 3, 4, 0, 657, 17, 72], ["+", 0, 7, 12, 652, 3, 4, 0, 657, 12, 612]]
5
740
/* Author: Ayush Agrawal, IIT Ropar */ #include <iostream> //#include <bits/stdc++.h> #include <algorithm> #include <chrono> #include <cmath> #include <cstdio> #include <cstring> #include <deque> #include <iomanip> #include <limits.h> #include <list> #include <map> #include <queue> #include <random> #include <set> #inc...
/* Author: Ayush Agrawal, IIT Ropar */ #include <iostream> //#include <bits/stdc++.h> #include <algorithm> #include <chrono> #include <cmath> #include <cstdio> #include <cstring> #include <deque> #include <iomanip> #include <limits.h> #include <list> #include <map> #include <queue> #include <random> #include <set> #inc...
[["-", 8, 9, 0, 57, 64, 1, 0, 11, 12, 22], ["+", 8, 9, 0, 57, 64, 1, 0, 11, 12, 22]]
1
1,629
/*BISMILLAH THE WHITE WOLF NO DREAM IS TOO BIG AND NO DREAMER IS TOO SMALL*/ #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; typedef vector<long long> vll; typedef vector<int> vi; #define io ios_base::sync_with_stdio(false) #define pb pus...
/*BISMILLAH THE WHITE WOLF NO DREAM IS TOO BIG AND NO DREAMER IS TOO SMALL*/ #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pii; typedef vector<long long> vll; typedef vector<int> vi; #define io ios_base::sync_with_stdio(false) #define pb pus...
[["+", 0, 11, 12, 69, 341, 342, 0, 69, 28, 22], ["+", 12, 69, 341, 342, 0, 69, 341, 342, 0, 70], ["+", 12, 69, 341, 342, 0, 69, 341, 342, 0, 73]]
1
431
from itertools import accumulate N, K = map(int, input().split()) P = [i-1 for i in map(int, input().split())] C = list(map(int, input().split())) seen = [0] * N ans = -10**20 for i in range(N): if not seen[i]: seen[i] = 1 loop = [C[i]] while True: i = P[i] if seen...
from itertools import accumulate N, K = map(int, input().split()) P = [i-1 for i in map(int, input().split())] C = list(map(int, input().split())) seen = [0] * N ans = -10**20 for i in range(N): if not seen[i]: seen[i] = 1 loop = [C[i]] while True: i = P[i] if seen...
[["-", 8, 196, 0, 57, 64, 196, 0, 116, 0, 117], ["-", 12, 652, 3, 4, 0, 657, 31, 657, 31, 22], ["-", 12, 652, 3, 4, 0, 657, 31, 657, 17, 72]]
5
401
#include <bits/stdc++.h> using namespace std; #define repd(i, a, b) for (ll i = (a); i < (b); i++) #define rep(i, n) repd(i, 0, n) #define all(x) (x).begin(), (x).end() template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax...
#include <bits/stdc++.h> using namespace std; #define repd(i, a, b) for (ll i = (a); i < (b); i++) #define rep(i, n) repd(i, 0, n) #define all(x) (x).begin(), (x).end() template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> inline bool chmax...
[["+", 0, 43, 49, 50, 51, 16, 31, 23, 0, 24], ["+", 49, 50, 51, 16, 31, 23, 0, 16, 17, 33], ["+", 49, 50, 51, 16, 31, 23, 0, 16, 12, 13], ["+", 0, 43, 49, 50, 51, 16, 31, 23, 0, 25]]
1
446
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); ++i) #define MOD 1000000007 using namespace std; using ll = long long; int main() { ll n, k, ans = -10000000000; cin >> n >> k; vector<ll> p(n), c(n); rep(i, n) { cin >> p[i]; --p[i]; } rep(i, n) cin >> c[i]; vector<ll> dp(...
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); ++i) #define MOD 1000000007 using namespace std; using ll = long long; int main() { ll n, k, ans = -10000000000; cin >> n >> k; vector<ll> p(n), c(n); rep(i, n) { cin >> p[i]; --p[i]; } rep(i, n) cin >> c[i]; vector<ll> dp(...
[["-", 64, 9, 0, 43, 49, 50, 51, 16, 17, 109], ["+", 64, 9, 0, 43, 49, 50, 51, 16, 17, 33], ["+", 0, 43, 49, 50, 51, 16, 12, 23, 0, 24], ["+", 49, 50, 51, 16, 12, 23, 0, 16, 17, 48], ["+", 49, 50, 51, 16, 12, 23, 0, 16, 12, 22], ["+", 0, 43, 49, 50, 51, 16, 12, 23, 0, 25]]
1
259
import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.Scanner; public class Main { public static void main(String[] args) { Main main = new Main(); main.solve(); } public void solve() { Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in))...
import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.Scanner; public class Main { public static void main(String[] args) { Main main = new Main(); main.solve(); } public void solve() { Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in))...
[["+", 51, 16, 12, 16, 31, 23, 0, 16, 17, 33], ["+", 51, 16, 12, 16, 31, 23, 0, 16, 12, 499], ["+", 0, 11, 12, 16, 12, 23, 0, 16, 17, 33], ["+", 0, 11, 12, 16, 12, 23, 0, 16, 12, 499], ["+", 0, 16, 12, 16, 12, 23, 0, 16, 17, 33], ["+", 0, 16, 12, 16, 12, 23, 0, 16, 12, 499]]
3
939
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) typedef long long ll; typedef pair<int, int> P; const int INF = 1001001001; int main() { ll n, k; ll p[5005], c[5005] = {}; cin >> n >> k; rep(i, n) cin >> p[i]; rep(i, n) cin >> c[i]; if (k < n) { ll an...
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) typedef long long ll; typedef pair<int, int> P; const int INF = 1001001001; int main() { ll n, k; ll p[5005], c[5005] = {}; cin >> n >> k; rep(i, n) cin >> p[i]; rep(i, n) cin >> c[i]; if (k < n) { ll an...
[["-", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["+", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13]]
1
386
import java.util.HashSet; import java.util.Scanner; import java.util.Set; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); long K = sc.nextLong(); long max = Long.MIN_VALUE; int A[] = new int[N]; int C[] = new int[N]; ...
import java.util.HashSet; import java.util.Scanner; import java.util.Set; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); long K = sc.nextLong(); long max = Long.MIN_VALUE; int A[] = new int[N]; int C[] = new int[N]; ...
[["-", 75, 196, 0, 7, 15, 16, 12, 16, 31, 22], ["-", 75, 196, 0, 7, 15, 16, 12, 16, 17, 109]]
3
439
#include <bits/stdc++.h> using namespace std; int main() { int N; long long int ans = -1e9, K; cin >> N >> K; vector<int> P(N); for (int i = 0; i < N; i++) { cin >> P[i]; P[i]--; } vector<long long int> C(N); for (int i = 0; i < N; i++) { cin >> C[i]; } for (int i = 0; i < N; i++) { ...
#include <bits/stdc++.h> using namespace std; int main() { int N; long long int ans = -1e9, K; cin >> N >> K; vector<int> P(N); for (int i = 0; i < N; i++) { cin >> P[i]; P[i]--; } vector<long long int> C(N); for (int i = 0; i < N; i++) { cin >> C[i]; } for (int i = 0; i < N; i++) { ...
[["+", 0, 16, 31, 16, 31, 23, 0, 16, 17, 33], ["+", 0, 16, 31, 16, 31, 23, 0, 16, 12, 13]]
1
427
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0), cout.tie(0); int n, k; cin >> n >> k; vector<int> c(n), p(n); for (int i = 0; i < n; ++i) { cin >> p[i]; --p[i]; } for (int i = 0; i < n; ++i) cin >> c[i]; long long ans = -1e18; for (int i...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0), cout.tie(0); int n, k; cin >> n >> k; vector<int> c(n), p(n); for (int i = 0; i < n; ++i) { cin >> p[i]; --p[i]; } for (int i = 0; i < n; ++i) cin >> c[i]; long long ans = -1e18; for (int i...
[["-", 64, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["+", 64, 9, 0, 7, 10, 43, 49, 50, 51, 13]]
1
309
// #define MODULAR_ARITHMETIC // #define INDEXED_SET #pragma region #ifndef LOCAL_DEBUG #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #endif #include <assert.h> #include <math.h> #include <algorithm> #include <iomanip> #include <iostream> #include <vector> #define pb push_back #define mp make_pair ...
// #define MODULAR_ARITHMETIC // #define INDEXED_SET #pragma region #ifndef LOCAL_DEBUG #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #endif #include <assert.h> #include <math.h> #include <algorithm> #include <iomanip> #include <iostream> #include <vector> #define pb push_back #define mp make_pair ...
[["-", 8, 9, 0, 9, 0, 1, 0, 16, 31, 22], ["-", 8, 9, 0, 9, 0, 1, 0, 16, 17, 151], ["-", 8, 9, 0, 9, 0, 1, 0, 16, 12, 22], ["-", 0, 338, 8, 9, 0, 9, 0, 1, 0, 35]]
1
1,205
#include <algorithm> #include <cmath> #include <iostream> #include <string> #include <vector> using ll = long long; #define rep(i, n) for (ll i = 0; i < (n); i++) #define rep2(i, s, n) for (ll i = s; i < (n); i++) using namespace std; int main() { ll n, k; cin >> n >> k; vector<ll> p(n), c(n); rep(i, n) { ...
#include <algorithm> #include <cmath> #include <iostream> #include <string> #include <vector> using ll = long long; #define rep(i, n) for (ll i = 0; i < (n); i++) #define rep2(i, s, n) for (ll i = s; i < (n); i++) using namespace std; int main() { ll n, k; cin >> n >> k; vector<ll> p(n), c(n); rep(i, n) { ...
[["-", 0, 14, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 14, 8, 9, 0, 43, 49, 50, 51, 22], ["-", 0, 14, 49, 53, 54, 55, 0, 56, 39, 78], ["+", 0, 14, 49, 53, 54, 55, 0, 56, 39, 78]]
1
316
#include <bits/stdc++.h> #define rep(i, n) for (long long i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<ll, ll>; const ll MOD = 1000000007; const ll INF = 10000000000000; #define all(v) v.begin(), v.end() int main() { ll N, K; cin >> N >> K; vector<ll> X(N), C(N); vector<vector...
#include <bits/stdc++.h> #define rep(i, n) for (long long i = 0; i < (n); ++i) using namespace std; using ll = long long; using P = pair<ll, ll>; const ll MOD = 1000000007; const ll INF = 10000000000000; #define all(v) v.begin(), v.end() int main() { ll N, K; cin >> N >> K; vector<ll> X(N), C(N); vector<vector...
[["-", 0, 14, 49, 53, 54, 55, 0, 56, 39, 78], ["+", 0, 14, 49, 53, 54, 55, 0, 56, 39, 78]]
1
626
(N, K) = [int(x) for x in input().split()] P = [int(x) - 1 for x in input().split()] # 0 indexed C = [int(x) for x in input().split()] inf = float("inf") ans = max(C) # at least one move for pos in range(N): i = pos score = 0 cycleLen = None cycleGain = None bestInc = 0 k = 0 while k <...
(N, K) = [int(x) for x in input().split()] P = [int(x) - 1 for x in input().split()] # 0 indexed C = [int(x) for x in input().split()] inf = float("inf") ans = max(C) # at least one move for pos in range(N): i = pos score = 0 cycleLen = None cycleGain = None bestInc = 0 k = 0 while k <...
[["+", 3, 4, 0, 657, 31, 23, 0, 657, 17, 33], ["+", 3, 4, 0, 657, 31, 23, 0, 657, 12, 22]]
5
177
import time startTimeProblem=time.time() import fileinput, sys, itertools, functools from math import * from bisect import * from heapq import * from collections import * def lcm(a, b): return (a*b)/gcd(a, b) class InputHelper: def __init__(self): self.myinput = fileinput.input() def isLocal(s...
import time startTimeProblem=time.time() import fileinput, sys, itertools, functools from math import * from bisect import * from heapq import * from collections import * def lcm(a, b): return (a*b)/gcd(a, b) class InputHelper: def __init__(self): self.myinput = fileinput.input() def isLocal(s...
[["+", 0, 1, 0, 662, 12, 657, 31, 23, 0, 24], ["+", 0, 1, 0, 662, 12, 657, 31, 23, 0, 25], ["+", 64, 196, 0, 1, 0, 662, 12, 657, 17, 33], ["+", 64, 196, 0, 1, 0, 662, 12, 657, 12, 612]]
5
627
import sys sys.setrecursionlimit(700000) def s_in(): return input() def n_in(): return int(input()) def l_in(): return list(map(int, input().split())) n,k = l_in() P = l_in() C = l_in() s = min(k,n) res = -(10**10) for start in range(n): j = start current = 0 tmp = -(10**10) for i in r...
import sys sys.setrecursionlimit(700000) def s_in(): return input() def n_in(): return int(input()) def l_in(): return list(map(int, input().split())) n,k = l_in() P = l_in() C = l_in() s = min(k,n) res = -(10**10) for start in range(n): j = start current = 0 tmp = -(10**10) for i in r...
[["+", 0, 57, 64, 196, 0, 1, 0, 662, 31, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 662, 0, 32], ["+", 0, 57, 64, 196, 0, 1, 0, 662, 12, 22], ["-", 0, 57, 64, 196, 0, 57, 15, 666, 667, 47], ["-", 0, 57, 64, 196, 0, 57, 15, 666, 0, 612], ["+", 0, 57, 64, 196, 0, 57, 15, 666, 667, 20], ["+", 0, 57, 64, 196, 0, 57, 15, 666, 0, 6...
5
276
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define repr(i, n) for (int i = (int)(n); i >= 0; i--) #define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++) #define all(v) v.begin(), v.end() typedef long long ll; template <class T> inline bool chmax(T &a, T ...
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define repr(i, n) for (int i = (int)(n); i >= 0; i--) #define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++) #define all(v) v.begin(), v.end() typedef long long ll; template <class T> inline bool chmax(T &a, T ...
[["-", 0, 14, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 14, 8, 9, 0, 1, 0, 11, 31, 22], ["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 22], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 22]]
1
432
N,K=map(int,input().split()) P=list(map(int,input().split())) C=list(map(int,input().split())) a=[] ans=-10**10 for i in range(N): idx=P[i]-1 z=set() rl=[] c=0 tc=0 while idx not in z and c<K: tc+=C[idx] rl.append(tc) ans=max(ans.tc) z.add(idx) idx=P[idx]-...
N,K=map(int,input().split()) P=list(map(int,input().split())) C=list(map(int,input().split())) a=[] ans=-10**10 for i in range(N): idx=P[i]-1 z=set() rl=[] c=0 tc=0 while idx not in z and c<K: tc+=C[idx] rl.append(tc) ans=max(ans,tc) z.add(idx) idx=P[idx]-...
[["-", 0, 662, 12, 652, 3, 4, 0, 319, 0, 131], ["+", 0, 1, 0, 662, 12, 652, 3, 4, 0, 21]]
5
191
#include <bits/stdc++.h> using namespace std; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } using ll = long long; using P = pair<int, int>; const i...
#include <bits/stdc++.h> using namespace std; template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } using ll = long long; using P = pair<int, int>; const i...
[["+", 64, 9, 0, 1, 0, 11, 12, 16, 17, 72], ["+", 64, 9, 0, 1, 0, 11, 12, 16, 12, 22], ["-", 0, 57, 64, 9, 0, 1, 0, 11, 12, 13], ["+", 0, 57, 64, 9, 0, 1, 0, 11, 12, 13]]
1
895
#include <bits/stdc++.h> #define x first #define y second #define pb push_back #define eb emplace_back #define all(a) (a).begin(), (a).end() #define SZ(a) (int)(a).size() #define FOR(i, a, b) for (int i = (a); i <= (b); ++i) #define ROF(i, a, b) for (int i = (a); i >= (b); --i) #define make_unique(a) ...
#include <bits/stdc++.h> #define x first #define y second #define pb push_back #define eb emplace_back #define all(a) (a).begin(), (a).end() #define SZ(a) (int)(a).size() #define FOR(i, a, b) for (int i = (a); i <= (b); ++i) #define ROF(i, a, b) for (int i = (a); i >= (b); --i) #define make_unique(a) ...
[["+", 12, 16, 12, 23, 0, 16, 31, 23, 0, 24], ["+", 3, 4, 0, 16, 12, 16, 12, 23, 0, 25]]
1
479
# -*- coding: utf-8 -*- ############# # Libraries # ############# import sys input = sys.stdin.readline import math #from math import gcd import bisect import heapq from collections import defaultdict from collections import deque from collections import Counter from functools import lru_cache ############# # Const...
# -*- coding: utf-8 -*- ############# # Libraries # ############# import sys input = sys.stdin.readline import math #from math import gcd import bisect import heapq from collections import defaultdict from collections import deque from collections import Counter from functools import lru_cache ############# # Const...
[["+", 3, 4, 0, 206, 206, 663, 0, 657, 17, 72], ["+", 3, 4, 0, 206, 206, 663, 0, 657, 12, 612]]
5
1,371
N, K = map(int, input().split()) P = list(map(int, input().split())) C = list(map(int, input().split())) for i in range(N): P[i] -= 1 ans = -10**10 for i in range(N): T = [] Check = [0]*N move = i count = 1 while(True): if Check[move] != 0: break Check[move] = count ...
N, K = map(int, input().split()) P = list(map(int, input().split())) C = list(map(int, input().split())) for i in range(N): P[i] -= 1 ans = -10**10 for i in range(N): T = [] Check = [0]*N move = i count = 1 while(True): if Check[move] != 0: break Check[move] = count ...
[["+", 0, 7, 8, 196, 0, 57, 75, 76, 0, 95], ["+", 0, 7, 8, 196, 0, 57, 75, 76, 0, 102]]
5
412
n, k = map(int,input().split()) p = list(map(int,input().split())) c = list(map(int,input().split())) ans = -10**18 for now in range(n): ruisekiwa = [] tansaku = set() for i in range(n+1): targ = p[now]-1 if len(ruisekiwa) >= 1: ruisekiwa.append(c[targ]+ruisekiwa[-1]) else: ruisekiwa.append(c[targ]) if...
n, k = map(int,input().split()) p = list(map(int,input().split())) c = list(map(int,input().split())) ans = -10**18 for now in range(n): ruisekiwa = [] tansaku = set() for i in range(n+1): targ = p[now]-1 if len(ruisekiwa) >= 1: ruisekiwa.append(c[targ]+ruisekiwa[-1]) else: ruisekiwa.append(c[targ]) if...
[["+", 31, 657, 31, 652, 3, 4, 0, 206, 0, 70], ["+", 31, 652, 3, 4, 0, 206, 206, 663, 0, 102], ["+", 3, 4, 0, 206, 206, 663, 0, 664, 17, 33], ["+", 3, 4, 0, 206, 206, 663, 0, 664, 28, 612], ["+", 31, 657, 31, 652, 3, 4, 0, 206, 0, 73]]
5
323
n, k = map(int, input().split()) p = list(map(int, input().split())) c = list(map(int, input().split())) p = [i-1 for i in p] MINI = -10**9-1 class UnionFind: def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x ...
n, k = map(int, input().split()) p = list(map(int, input().split())) c = list(map(int, input().split())) p = [i-1 for i in p] MINI = -10**9-1 class UnionFind: def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x ...
[["+", 0, 1, 0, 662, 12, 657, 31, 23, 0, 24], ["+", 31, 23, 0, 657, 12, 652, 3, 4, 0, 25], ["+", 64, 196, 0, 1, 0, 662, 12, 657, 17, 33], ["+", 64, 196, 0, 1, 0, 662, 12, 657, 12, 612]]
5
639
#include <algorithm> #include <bitset> #include <cassert> #include <cctype> #include <chrono> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #in...
#include <algorithm> #include <bitset> #include <cassert> #include <cctype> #include <chrono> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #in...
[["-", 64, 9, 0, 57, 15, 339, 51, 16, 17, 47], ["+", 64, 9, 0, 57, 15, 339, 51, 16, 17, 20]]
1
1,951
N,K=map(int,input().split()) P=list(map(int,input().split())) C=list(map(int,input().split())) for i in range(N): P[i]-=1 INF=-(10**20) X=[[INF]*(N+1) for i in range(N)] Y=[0]*N Z=[0]*N R=[0]*N S=set() V=0 for i in range(N): S=set() V=i S.add(i) for j in range(N): V=P[V] if V in S: Z[i]=V ...
N,K=map(int,input().split()) P=list(map(int,input().split())) C=list(map(int,input().split())) for i in range(N): P[i]-=1 INF=-(10**20) X=[[INF]*(N+1) for i in range(N)] Y=[0]*N Z=[0]*N R=[0]*N S=set() V=0 for i in range(N): S=set() V=i S.add(i) for j in range(N): V=P[V] if V in S: Z[i]=V ...
[["-", 75, 76, 8, 196, 0, 1, 0, 677, 12, 22], ["+", 75, 76, 8, 196, 0, 1, 0, 677, 12, 22]]
5
464
// This is free and unencumbered software released into the public domain. // Anyone is free to copy, modify, publish, use, compile, sell, or // distribute this software, either in source code form or as a compiled // binary, for any purpose, commercial or non-commercial, and by any // means. // In jurisdictions that...
// This is free and unencumbered software released into the public domain. // Anyone is free to copy, modify, publish, use, compile, sell, or // distribute this software, either in source code form or as a compiled // binary, for any purpose, commercial or non-commercial, and by any // means. // In jurisdictions that...
[["+", 0, 1, 0, 11, 12, 16, 31, 23, 0, 24], ["+", 0, 11, 12, 16, 31, 23, 0, 16, 17, 33], ["+", 0, 11, 12, 16, 31, 23, 0, 16, 12, 13], ["+", 0, 1, 0, 11, 12, 16, 31, 23, 0, 25], ["+", 0, 7, 15, 16, 12, 16, 31, 16, 12, 22], ["+", 8, 9, 0, 7, 15, 16, 12, 16, 17, 72]]
1
5,273
// -------------- // Tejas Pandey | // 13 - 08 - 20 | // Atcoder BC 175| // -------------- #include <bits/stdc++.h> using namespace std; #define mod 1000000007 #define vi vector<int> typedef long long int ll; int main(void) { // freopen("in.txt","r",stdin); // freopen("out.txt","w",stdout); ios_base::sync_wi...
// -------------- // Tejas Pandey | // 13 - 08 - 20 | // Atcoder BC 175| // -------------- #include <bits/stdc++.h> using namespace std; #define mod 1000000007 #define vi vector<int> typedef long long int ll; int main(void) { // freopen("in.txt","r",stdin); // freopen("out.txt","w",stdout); ios_base::sync_wi...
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 18], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 47]]
1
405
import sys sys.setrecursionlimit(10 ** 7) input = sys.stdin.readline f_inf = float('inf') mod = 10 ** 9 + 7 def resolve(): n, k = map(int, input().split()) P = list(map(int, input().split())) C = list(map(int, input().split())) res = -f_inf for now in range(n): cnt = 0 score = [0...
import sys sys.setrecursionlimit(10 ** 7) input = sys.stdin.readline f_inf = float('inf') mod = 10 ** 9 + 7 def resolve(): n, k = map(int, input().split()) P = list(map(int, input().split())) C = list(map(int, input().split())) res = -f_inf for now in range(n): cnt = 0 score = [0...
[["+", 3, 4, 0, 657, 12, 657, 12, 23, 0, 24], ["+", 0, 657, 12, 657, 12, 23, 0, 657, 17, 33], ["+", 0, 657, 12, 657, 12, 23, 0, 657, 12, 612], ["+", 3, 4, 0, 657, 12, 657, 12, 23, 0, 25]]
5
306
# ------------------- fast io -------------------- import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode...
# ------------------- fast io -------------------- import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode...
[["+", 75, 76, 8, 196, 0, 1, 0, 662, 31, 22], ["+", 75, 76, 8, 196, 0, 1, 0, 662, 0, 32], ["+", 75, 76, 8, 196, 0, 1, 0, 662, 12, 22], ["-", 12, 23, 0, 657, 31, 23, 0, 657, 31, 22], ["+", 12, 23, 0, 657, 31, 23, 0, 657, 31, 22]]
5
884
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; const ll M = 1e9 + 7; const ll MAXN = 1e6 + 7; const ld pi = acos(-1); #define gi(n) ll n = read() #define endl '\n' #define rep(i, a, b) for (ll i = a; i < b; ++i) #define per(i, a, b) for (ll i = b - 1; i >= a; --i) typedef...
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; const ll M = 1e9 + 7; const ll MAXN = 1e6 + 7; const ld pi = acos(-1); #define gi(n) ll n = read() #define endl '\n' #define rep(i, a, b) for (ll i = a; i < b; ++i) #define per(i, a, b) for (ll i = b - 1; i >= a; --i) typedef...
[["-", 0, 1, 0, 16, 12, 16, 12, 16, 31, 22], ["+", 0, 1, 0, 16, 12, 16, 12, 16, 31, 22], ["-", 75, 76, 0, 1, 0, 16, 12, 16, 31, 22], ["+", 75, 76, 0, 1, 0, 16, 12, 16, 31, 22]]
1
646
import sys input = sys.stdin.readline def main(): X, K, D = map(int, input().split()) M = X%D S = X//D C = K - S if C < 0: ans = abs(X) - K*D else: if M <= abs(M-D): if C%2 == 0: ans = M else: ans = abs(M - D) else:...
import sys input = sys.stdin.readline def main(): X, K, D = map(int, input().split()) M = abs(X)%D S = abs(X)//D C = K - S if C < 0: ans = abs(X) - K*D else: if M <= abs(M-D): if C%2 == 0: ans = M else: ans = abs(M - D) ...
[["+", 0, 1, 0, 662, 12, 657, 31, 652, 63, 22], ["+", 0, 662, 12, 657, 31, 652, 3, 4, 0, 24], ["+", 0, 662, 12, 657, 31, 652, 3, 4, 0, 25]]
5
133
#include <algorithm> #include <array> #include <cassert> #include <cctype> #include <cfloat> #include <climits> #include <cmath> #include <deque> #include <iomanip> #include <iostream> #include <iterator> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stac...
#include <algorithm> #include <array> #include <cassert> #include <cctype> #include <cfloat> #include <climits> #include <cmath> #include <deque> #include <iomanip> #include <iostream> #include <iterator> #include <list> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <stac...
[["-", 0, 9, 0, 57, 15, 339, 51, 16, 31, 22], ["+", 0, 9, 0, 57, 15, 339, 51, 16, 31, 22]]
1
1,454
X, K, D = map(int, input().split()) if X < 0: X = -1 * X if K * D <= X: print(X - K * D) else: n = X // D if X % D > 0: n += 1 if K - n % 2 == 0: print(-1 * (X - n * D)) else: print(X - n * D + D)
X, K, D = map(int, input().split()) if X < 0: X = -1 * X if K * D <= X: print(X - K * D) else: n = X // D if X % D > 0: n += 1 if (K - n) % 2 == 0: print(-1 * (X - n * D)) else: print(X - n * D + D)
[["+", 0, 57, 15, 666, 0, 657, 31, 23, 0, 24], ["+", 0, 57, 15, 666, 0, 657, 31, 23, 0, 25]]
5
95
x,k,d=map(int,input().split()) if x>=0: a=1 else: a=-1 if x*a-k*d>0: print(x*a-k*d) else: b=x//d if b%2==0: print(x%d) else: print(d-x%d)
x,k,d=map(int,input().split()) if x>=0: a=1 else: a=-1 if x*a-k*d>0: print(x*a-k*d) else: b=x//d if (k-b)%2==0: print(x%d) else: print(d-x%d)
[["+", 0, 57, 15, 666, 0, 657, 31, 23, 0, 24], ["+", 15, 666, 0, 657, 31, 23, 0, 657, 31, 22], ["+", 15, 666, 0, 657, 31, 23, 0, 657, 17, 33], ["+", 0, 57, 15, 666, 0, 657, 31, 23, 0, 25]]
5
83
#include <bits/stdc++.h> using namespace std; #define reps(i, a, n) for (int i = (a); i < (n); ++i) #define rep(i, n) reps(i, 0, n) #define deps(i, a, n) for (int i = (a); i >= (n); --i) #define dep(i, n) deps(i, n, 0) #define inf 2147483647 #define int long long signed main(void) { int x, k, d; cin >> x >> k >> d...
#include <bits/stdc++.h> using namespace std; #define reps(i, a, n) for (int i = (a); i < (n); ++i) #define rep(i, n) reps(i, 0, n) #define deps(i, a, n) for (int i = (a); i >= (n); --i) #define dep(i, n) deps(i, n, 0) #define inf 2147483647 #define int long long signed main(void) { int x, k, d; cin >> x >> k >> d...
[["+", 0, 16, 31, 16, 12, 16, 31, 91, 17, 33], ["-", 0, 1, 0, 16, 31, 16, 12, 16, 17, 72], ["+", 0, 1, 0, 16, 31, 16, 12, 16, 17, 33]]
1
231
x, k, d = map(int, input().split()) count = abs(x)/d if count.is_integer(): count = int(count) else: count = int(count)+1 if x >= 0: if count >= k: print(abs(x-k*d)) else: if (k-count)%2 == 0: print(abs(x-d*count)) else: print(x-d*count+d) else: ...
x, k, d = map(int, input().split()) count = abs(x)/d if count.is_integer(): count = int(count) else: count = int(count)+1 if x >= 0: if count >= k: print(abs(x-k*d)) else: if (k-count)%2 == 0: print(abs(x-d*count)) else: print(x-d*count+d) else: ...
[["+", 0, 1, 0, 652, 3, 4, 0, 652, 63, 22], ["+", 0, 652, 3, 4, 0, 652, 3, 4, 0, 24], ["+", 0, 652, 3, 4, 0, 652, 3, 4, 0, 25]]
5
158
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define ll long long #define P pair<int, int> #define PI 3.141592653589793 const int INF = 1001001001; const ll MX = 1e18; const int mod = 1000000007; int main() { ll x, k, d; cin >> x >> k >> d; if (x < 0) x *...
#include <bits/stdc++.h> using namespace std; #define rep(i, n) for (int i = 0; i < (int)(n); i++) #define ll long long #define P pair<int, int> #define PI 3.141592653589793 const int INF = 1001001001; const ll MX = 1e18; const int mod = 1000000007; int main() { ll x, k, d; cin >> x >> k >> d; if (x < 0) x *...
[["+", 0, 57, 15, 339, 51, 16, 31, 16, 17, 85], ["+", 0, 57, 15, 339, 51, 16, 31, 16, 12, 22], ["-", 0, 57, 15, 339, 51, 16, 12, 16, 17, 48], ["-", 0, 57, 15, 339, 51, 16, 12, 16, 12, 22]]
1
135
#include <bits/stdc++.h> using namespace std; #pragma optimize("-O3") #define int long long int #define f first #define s second #define pb push_back #define endl '\n' main() { int x, k, d; cin >> x >> k >> d; x = abs(x); if (x > d) { int steps = (x / d); if (steps > k) { cout << x - k * d; ...
#include <bits/stdc++.h> using namespace std; #pragma optimize("-O3") #define int long long int #define f first #define s second #define pb push_back #define endl '\n' main() { int x, k, d; cin >> x >> k >> d; x = abs(x); if (x > d) { int steps = (x / d); if (steps > k) { cout << x - k * d; ...
[["-", 0, 57, 15, 339, 51, 16, 31, 16, 31, 22], ["+", 0, 57, 15, 339, 51, 16, 31, 16, 31, 22]]
1
164
#pragma GCC optimize("O3") #pragma GCC target("sse4") #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef vector<int> vi; typedef pair<int, int> pi; #define debug(x) cerr << #x << ": " << x << endl #define debug2(x, y) debug(x), debug(y) #define repn(i, a, b) for (int i =...
#pragma GCC optimize("O3") #pragma GCC target("sse4") #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef vector<int> vi; typedef pair<int, int> pi; #define debug(x) cerr << #x << ": " << x << endl #define debug2(x, y) debug(x), debug(y) #define repn(i, a, b) for (int i =...
[["+", 15, 339, 51, 16, 31, 16, 31, 91, 17, 33], ["-", 64, 9, 0, 57, 15, 339, 51, 16, 17, 19], ["+", 64, 9, 0, 57, 15, 339, 51, 16, 17, 20]]
1
355
#include <bits/stdc++.h> using namespace std; #define int long long #define PB push_back #define ALL(x) (x).begin(), (x).end() #define ALLR(x) (x).rbegin(), (x).rend() #define MP make_pair template <typename A, typename B> string to_string(pair<A, B> p); template <typename A, typename B, typename C> string to_stri...
#include <bits/stdc++.h> using namespace std; #define int long long #define PB push_back #define ALL(x) (x).begin(), (x).end() #define ALLR(x) (x).rbegin(), (x).rend() #define MP make_pair template <typename A, typename B> string to_string(pair<A, B> p); template <typename A, typename B, typename C> string to_stri...
[["-", 0, 9, 0, 43, 49, 50, 51, 16, 12, 22], ["+", 0, 9, 0, 43, 49, 50, 51, 16, 12, 22]]
1
1,169
#include <bits/stdc++.h> using namespace std; #define INF 1000000007 #define LINF (1LL << 62) #define PI 3.14159265358979 typedef long long i64; typedef pair<i64, i64> P; inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; } template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return ...
#include <bits/stdc++.h> using namespace std; #define INF 1000000007 #define LINF (1LL << 62) #define PI 3.14159265358979 typedef long long i64; typedef pair<i64, i64> P; inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; } template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return ...
[["+", 12, 2, 3, 4, 0, 16, 31, 2, 63, 22], ["+", 3, 4, 0, 16, 31, 2, 3, 4, 0, 24], ["+", 3, 4, 0, 16, 31, 2, 3, 4, 0, 25], ["+", 0, 1, 0, 16, 31, 16, 12, 2, 63, 22], ["+", 0, 16, 31, 16, 12, 2, 3, 4, 0, 24], ["+", 0, 16, 31, 16, 12, 2, 3, 4, 0, 25]]
1
278
x, k, d = [int(e) for e in input().split()] if x < 0: x = -x a = x // d if k <= a: print(x - k * d) b = k - a if b % 2 == 0: print(x - a * d) else: print( -(x - (a + 1) * d))
x, k, d = [int(e) for e in input().split()] if x < 0: x = -x a = x // d if k <= a: print(x - k * d) else: b = k - a if b % 2 == 0: print(x - a * d) else: print( -(x - (a + 1) * d))
[["+", 36, 36, 0, 656, 0, 57, 75, 76, 0, 95], ["+", 36, 36, 0, 656, 0, 57, 75, 76, 0, 102]]
5
86
x,k,d = map(int,input().split()) n = x//d if k<n: print(x-k*d) exit() if n%2==0: if k%2==0: ans = x - n*d else: ans = (n+1)*d - x else: if k%2==1: ans = x - n*d else: ans = (n+1)*d - x print(ans)
x,k,d = map(int,input().split()) x = abs(x) n = x//d if k<n: print(x-k*d) exit() if n%2==0: if k%2==0: ans = x - n*d else: ans = (n+1)*d - x else: if k%2==1: ans = x - n*d else: ans = (n+1)*d - x print(ans)
[["+", 36, 36, 0, 656, 0, 1, 0, 662, 31, 22], ["+", 36, 36, 0, 656, 0, 1, 0, 662, 0, 32], ["+", 0, 656, 0, 1, 0, 662, 12, 652, 63, 22], ["+", 0, 1, 0, 662, 12, 652, 3, 4, 0, 24], ["+", 0, 1, 0, 662, 12, 652, 3, 4, 0, 22], ["+", 0, 1, 0, 662, 12, 652, 3, 4, 0, 25]]
5
106
#pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; // defines typedef long long ll; using namespace std; double pi = 1.57079632679489661923; ll modu = 1e9 + 7; ll t = 1, n = 1, q; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll x, k, d; cin >> x >> k >> d; x = ...
#pragma GCC optimize("O3") #include <bits/stdc++.h> using namespace std; // defines typedef long long ll; using namespace std; double pi = 1.57079632679489661923; ll modu = 1e9 + 7; ll t = 1, n = 1, q; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll x, k, d; cin >> x >> k >> d; x = ...
[["-", 0, 14, 8, 9, 0, 43, 49, 50, 51, 22], ["+", 0, 14, 8, 9, 0, 43, 49, 50, 51, 13]]
1
224
//#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; using ll = long long; #define INF 0x6fffffff #define INFL 0x6fffffffffffffffLL int main() { ll a, b, c, d, w, h, i, j, k, l, m, n, x, y, z; ll ans = 0; string s; cin >> x >> k >> d; a = abs(x); if (k * d < a) { ans = a - k * d; ...
//#define _GLIBCXX_DEBUG #include <bits/stdc++.h> using namespace std; using ll = long long; #define INF 0x6fffffff #define INFL 0x6fffffffffffffffLL int main() { ll a, b, c, d, w, h, i, j, k, l, m, n, x, y, z; ll ans = 0; string s; cin >> x >> k >> d; a = abs(x); if (k < a / d) { ans = a - k * d; ...
[["-", 0, 57, 15, 339, 51, 16, 31, 16, 17, 48], ["-", 0, 57, 15, 339, 51, 16, 31, 16, 12, 22], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 17, 85], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 12, 22]]
1
149
from sys import stdin,stdout from collections import defaultdict import math #input=stdin.readline #def print(x):stdout.write(str(x)+'\n') x,n,d=map(int,input().split()) ans=x if x>0: if x-n*d<0: c=x//d n=n-c ans=x-c*d a=abs(ans-d) b=ans if n%2==0: print(b...
from sys import stdin,stdout from collections import defaultdict import math #input=stdin.readline #def print(x):stdout.write(str(x)+'\n') x,n,d=map(int,input().split()) ans=x if x>0: if x-n*d<0: c=x//d n=n-c ans=x-c*d a=abs(ans-d) b=ans if n%2==0: print(b...
[["+", 0, 1, 0, 652, 3, 4, 0, 652, 63, 22], ["+", 0, 652, 3, 4, 0, 652, 3, 4, 0, 24], ["+", 0, 652, 3, 4, 0, 652, 3, 4, 0, 25]]
5
197
#include <bits/stdc++.h> #include <iostream> #include <math.h> #include <numeric> #define ll long long #define ull long #define mpa make_pair #define pb push_back #define ff first #define pii pair<ll, ll> #define dd long long #define trace(x) cerr << #x << " : " << x << endl #define ss second #define boost ios_base::sy...
#include <bits/stdc++.h> #include <iostream> #include <math.h> #include <numeric> #define ll long long #define ull long #define mpa make_pair #define pb push_back #define ff first #define pii pair<ll, ll> #define dd long long #define trace(x) cerr << #x << " : " << x << endl #define ss second #define boost ios_base::sy...
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 31, 22], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 31, 22]]
1
246
x, k, d = map(int, input().split()) q, r = divmod(x, d) # print(q, r) if k <= q: print(x - k * d) else: k -= q # print(f'{k=}') if k % 2 == 0: print(r) else: print(abs(r - d))
x, k, d = map(int, input().split()) x = abs(x) q, r = divmod(x, d) # print(q, r) if k <= q: print(x - k * d) else: k -= q # print(f'{k=}') if k % 2 == 0: print(r) else: print(abs(r - d))
[["+", 36, 36, 0, 656, 0, 1, 0, 662, 31, 22], ["+", 36, 36, 0, 656, 0, 1, 0, 662, 0, 32], ["+", 0, 656, 0, 1, 0, 662, 12, 652, 63, 22], ["+", 0, 1, 0, 662, 12, 652, 3, 4, 0, 24], ["+", 0, 1, 0, 662, 12, 652, 3, 4, 0, 22], ["+", 0, 1, 0, 662, 12, 652, 3, 4, 0, 25]]
5
70
#include <algorithm> #include <iomanip> #include <iostream> #include <math.h> #include <queue> #include <stack> #include <stdlib.h> #include <string> #include <vector> using namespace std; #define PI 3.14159265358979 typedef long long ll; #define rep(i, n) for (int i = 0; i < n; i++) #include <set> int main(void) { l...
#include <algorithm> #include <iomanip> #include <iostream> #include <math.h> #include <queue> #include <stack> #include <stdlib.h> #include <string> #include <vector> using namespace std; #define PI 3.14159265358979 typedef long long ll; #define rep(i, n) for (int i = 0; i < n; i++) #include <set> int main(void) { l...
[["+", 0, 1, 0, 16, 31, 16, 12, 2, 63, 22], ["+", 0, 16, 31, 16, 12, 2, 3, 4, 0, 24], ["+", 0, 16, 31, 16, 12, 2, 3, 4, 0, 25]]
1
158
#include <bits/stdc++.h> using namespace std; int main() { long long x, k, d; cin >> x >> k >> d; long long ans; if (x > 0) { if (k <= x / d) ans = x - d * k; else { if ((x / d) % 2 == k) ans = x % d; else ans = -(x % d - d); } } else if (x < 0) { if (k <= -...
#include <bits/stdc++.h> using namespace std; int main() { long long x, k, d; cin >> x >> k >> d; long long ans; if (x > 0) { if (k <= x / d) ans = x - d * k; else { if ((x / d) % 2 == k % 2) ans = x % d; else ans = -(x % d - d); } } else if (x < 0) { if (k ...
[["+", 0, 57, 15, 339, 51, 16, 12, 16, 17, 109], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 12, 13]]
1
178
x,k,d = map(int, input().split()) #正の処理 if x > 0: neededmove = x//d amari = x%d if abs(amari - d) < abs(amari): amari = abs(amari - d) neededmove += 1 if k < neededmove: print(x-k*d) elif k == neededmove: print(abs(amari)) else: hoge = k - neededmove ...
x,k,d = map(int, input().split()) #正の処理 if x > 0: neededmove = x//d amari = x%d if abs(amari - d) < abs(amari): amari = abs(amari - d) neededmove += 1 if k < neededmove: print(abs(x-k*d)) elif k == neededmove: print(abs(amari)) else: hoge = k - neededmove...
[["+", 0, 1, 0, 652, 3, 4, 0, 652, 63, 22], ["+", 0, 652, 3, 4, 0, 652, 3, 4, 0, 24], ["+", 0, 652, 3, 4, 0, 652, 3, 4, 0, 25], ["+", 64, 196, 0, 1, 0, 652, 3, 4, 0, 24]]
5
267
import sys x,k,d=map(int,input().split()) if(abs(x%d)<abs(x%d-d)): min_num=x%d min_num2=x%d-d else: min_num=x%d-d min_num2=x%d kaisuu=(x-min_num)/d if(kaisuu>k): print(abs(x-d*k)) sys.exit() if((k%2==0 and kaisuu%2==0)or(k%2==1 and kaisuu%2==1)): print(abs(min_num)) else: print(abs(min_num2))
import sys x,k,d=map(int,input().split()) x=abs(x) if(abs(x%d)<abs(x%d-d)): min_num=x%d min_num2=x%d-d else: min_num=x%d-d min_num2=x%d kaisuu=(x-min_num)/d if(kaisuu>k): print(abs(x-d*k)) sys.exit() if((k%2==0 and kaisuu%2==0)or(k%2==1 and kaisuu%2==1)): print(abs(min_num)) else: print(abs(min_num2)...
[["+", 36, 36, 0, 656, 0, 1, 0, 662, 31, 22], ["+", 36, 36, 0, 656, 0, 1, 0, 662, 0, 32], ["+", 0, 656, 0, 1, 0, 662, 12, 652, 63, 22], ["+", 0, 1, 0, 662, 12, 652, 3, 4, 0, 24], ["+", 0, 1, 0, 662, 12, 652, 3, 4, 0, 22], ["+", 0, 1, 0, 662, 12, 652, 3, 4, 0, 25]]
5
144