problem_id stringlengths 6 6 | buggy_code stringlengths 8 526k ⌀ | fixed_code stringlengths 12 526k ⌀ | labels listlengths 0 15 ⌀ | buggy_submission_id int64 1 1.54M ⌀ | fixed_submission_id int64 2 1.54M ⌀ | user_id stringlengths 10 10 ⌀ | language stringclasses 9
values |
|---|---|---|---|---|---|---|---|
p03160 | #include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pii pair<ll, ll>
#define vi vector<ll>
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define pf(n) printf("%lld\n", n)
#define sf(n) scanf("%lld", &n)
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define all(x) x.begin(), x.end()
#define ms(n, i) memset(n, i, sizeof n)
#define sz(x) (ll) x.size()
#define pi 3.141592653589793238
#define hell 1000000007
#define hell2 1000000009
#define endl '\n'
#define inf 1e18
#define N 100005
int main() {
ll n;
cin >> n;
ll i, j, k;
vi a(n), dp(n);
for (i = 0; i < n; i++)
cin >> a[i], dp[i] = inf;
dp[0] = 0;
for (i = 1; i < n; i++) {
if (i > 1)
dp[i] = min(dp[i], dp[i - 2] + abs(a[i - 2] - a[i]));
dp[i] = min(dp[i], dp[i - 1] + abs(a[i - 1] - a[i]));
}
cout << dp[n] << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pii pair<ll, ll>
#define vi vector<ll>
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define pf(n) printf("%lld\n", n)
#define sf(n) scanf("%lld", &n)
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define all(x) x.begin(), x.end()
#define ms(n, i) memset(n, i, sizeof n)
#define sz(x) (ll) x.size()
#define pi 3.141592653589793238
#define hell 1000000007
#define hell2 1000000009
#define endl '\n'
#define inf 1e18
#define N 100005
int main() {
ll n;
cin >> n;
ll i, j, k;
vi a(n), dp(n);
for (i = 0; i < n; i++)
cin >> a[i], dp[i] = inf;
dp[0] = 0;
for (i = 1; i < n; i++) {
if (i > 1)
dp[i] = min(dp[i], dp[i - 2] + abs(a[i - 2] - a[i]));
dp[i] = min(dp[i], dp[i - 1] + abs(a[i - 1] - a[i]));
}
cout << dp[n - 1] << endl;
} | [
"expression.operation.binary.add"
] | 956,606 | 956,607 | u501976062 | cpp |
p03160 | #include <bits/stdc++.h>
using namespace std;
#define FC ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define FIN freopen("in.txt", "r", stdin)
#define FOUT freopen("out.txt", "w", stdout)
#define deb(x) \
cerr << "DEBUG------" << '\n'; \
cerr << #x << "------>"; \
err(x)
template <typename T> void err(T a) {
cerr << a << '\n';
cerr << "END OF DEBUG" << '\n' << '\n';
}
const long double PI = acos(-1.0);
const long double eps = 1e-6;
const long long maxw = (long long)1e17 + (long long)10;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
/*head------[@cordercorder]*/
const int maxn = (int)1e5 + 10;
int a[maxn], n;
int dp[maxn];
void solve() {
dp[1] = 0;
int mine;
for (int i = 2; i <= n; i++) {
mine = (int)1e5 + 10;
for (int j = i - 1; j >= i - 2 && j >= 1; j--) {
mine = min(mine, dp[j] + abs(a[i] - a[j]));
}
dp[i] = mine;
}
printf("%d\n", dp[n]);
}
int main(void) {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
solve();
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define FC ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define FIN freopen("in.txt", "r", stdin)
#define FOUT freopen("out.txt", "w", stdout)
#define deb(x) \
cerr << "DEBUG------" << '\n'; \
cerr << #x << "------>"; \
err(x)
template <typename T> void err(T a) {
cerr << a << '\n';
cerr << "END OF DEBUG" << '\n' << '\n';
}
const long double PI = acos(-1.0);
const long double eps = 1e-6;
const long long maxw = (long long)1e17 + (long long)10;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
/*head------[@cordercorder]*/
const int maxn = (int)1e5 + 10;
int a[maxn], n;
int dp[maxn];
void solve() {
dp[1] = 0;
int mine;
for (int i = 2; i <= n; i++) {
mine = (int)1e9 + 10;
for (int j = i - 1; j >= i - 2 && j >= 1; j--) {
mine = min(mine, dp[j] + abs(a[i] - a[j]));
}
dp[i] = mine;
}
printf("%d\n", dp[n]);
}
int main(void) {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
solve();
return 0;
} | [
"literal.number.change",
"assignment.value.change",
"expression.operation.binary.change"
] | 956,610 | 956,611 | u890662292 | cpp |
p03160 | // https://atcoder.jp/contests/dp/tasks/dp_a
// shauryakr
#include <bits/stdc++.h>
using namespace std;
int arr[200010];
int dp[200010];
int n;
int solve(int ind) {
if (ind == n - 1)
return 0;
if (dp[ind] != -1)
return dp[ind];
int ans = 0;
ans = solve(ind + 1) + abs(arr[ind + 1] - arr[ind]);
if (ind + 2 <= n - 1)
ans = max(ans, solve(ind + 2) + abs(arr[ind + 2] - arr[ind]));
dp[ind] = ans;
return ans;
}
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
memset(dp, -1, sizeof dp);
cout << solve(1) << endl;
return 0;
} | // https://atcoder.jp/contests/dp/tasks/dp_a
// shauryakr
#include <bits/stdc++.h>
using namespace std;
int arr[200010];
int dp[200010];
int n;
int solve(int ind) {
if (ind == n - 1)
return 0;
if (dp[ind] != -1)
return dp[ind];
int ans = 0;
ans = solve(ind + 1) + abs(arr[ind + 1] - arr[ind]);
if (ind + 2 <= n - 1)
ans = min(ans, solve(ind + 2) + abs(arr[ind + 2] - arr[ind]));
dp[ind] = ans;
return ans;
}
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
memset(dp, -1, sizeof dp);
cout << solve(0) << endl;
return 0;
} | [
"misc.opposites",
"assignment.value.change",
"identifier.change",
"call.function.change",
"literal.number.change",
"io.output.change"
] | 956,614 | 956,615 | u009824133 | cpp |
p03160 | #include <bits/stdc++.h>
#define ll long long int
#define mp make_pair
#define pa pair<int, int>
#define ld long double
#define BOOST ios_base::sync_with_stdio(false)
#define pb push_back
using namespace std;
const int MAX = 1e5 + 5;
int dp[MAX];
int main() {
int n;
scanf("%d", &n);
int tab[n];
dp[0] = 0;
dp[1] = 0;
for (int i = 1; i <= n; i++) {
scanf("%d", &tab[i]);
}
tab[0] = tab[2];
for (int i = 2; i <= n; i++) {
dp[i] = min(dp[i - 1] + abs(tab[i] - tab[i - 1]),
dp[i - 2] + abs(tab[i] - tab[i - 2]));
}
printf("%d", dp[n]);
return 0;
}
| #include <bits/stdc++.h>
#define ll long long int
#define mp make_pair
#define pa pair<int, int>
#define ld long double
#define BOOST ios_base::sync_with_stdio(false)
#define pb push_back
using namespace std;
const int MAX = 1e5 + 5;
int dp[MAX];
int main() {
int n;
scanf("%d", &n);
int tab[n];
dp[0] = 0;
dp[1] = 0;
for (int i = 1; i <= n; i++) {
scanf("%d", &tab[i]);
}
tab[0] = -10000000;
for (int i = 2; i <= n; i++) {
dp[i] = min(dp[i - 1] + abs(tab[i] - tab[i - 1]),
dp[i - 2] + abs(tab[i] - tab[i - 2]));
}
printf("%d", dp[n]);
return 0;
}
| [] | 956,616 | 956,617 | u668264508 | cpp |
p03160 |
// jha4032
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long int
#define mp make_pair
#define M 1000000007
#define N 1000006
void fast() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
ll power(ll a, ll b) {
if (b == 0)
return 1;
ll tmp = power(a, b / 2) % M;
tmp = (tmp * tmp) % M;
if (b & 1)
return (tmp * a) % M;
return tmp;
}
ll fact[N], invfact[N];
ll ans = 0;
void pre1() {
fact[0] = 1;
invfact[0] = power(fact[0], M - 2);
for (int i = 1; i < N; i++) {
fact[i] = (i * fact[i - 1]) % M;
invfact[i] = power(fact[i], M - 2);
}
}
ll n;
ll a[100005];
ll dp[100005];
int main() {
memset(dp, -1, sizeof dp);
// dp[0]=0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
dp[0] = 0;
dp[1] = abs(a[0] - a[1]);
for (int i = 1; i < n; i++) {
dp[i] =
min(dp[i - 1] + abs(a[i] - a[i - 1]), dp[i - 2] + abs(a[i - 2] - a[i]));
}
cout << dp[n - 1] << endl;
} |
// jha4032
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long int
#define mp make_pair
#define M 1000000007
#define N 1000006
void fast() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
ll power(ll a, ll b) {
if (b == 0)
return 1;
ll tmp = power(a, b / 2) % M;
tmp = (tmp * tmp) % M;
if (b & 1)
return (tmp * a) % M;
return tmp;
}
ll fact[N], invfact[N];
ll ans = 0;
void pre1() {
fact[0] = 1;
invfact[0] = power(fact[0], M - 2);
for (int i = 1; i < N; i++) {
fact[i] = (i * fact[i - 1]) % M;
invfact[i] = power(fact[i], M - 2);
}
}
ll n;
ll a[100005];
ll dp[100005];
int main() {
memset(dp, -1, sizeof dp);
// dp[0]=0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
dp[0] = 0;
dp[1] = abs(a[0] - a[1]);
for (int i = 2; i < n; i++) {
dp[i] =
min(dp[i - 1] + abs(a[i] - a[i - 1]), dp[i - 2] + abs(a[i - 2] - a[i]));
}
cout << dp[n - 1] << endl;
} | [
"literal.number.change",
"variable_declaration.value.change",
"control_flow.loop.for.initializer.change",
"expression.off_by_one"
] | 956,621 | 956,622 | u897346581 | cpp |
p03160 |
// jha4032
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long int
#define mp make_pair
#define M 1000000007
#define N 1000006
void fast() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
ll power(ll a, ll b) {
if (b == 0)
return 1;
ll tmp = power(a, b / 2) % M;
tmp = (tmp * tmp) % M;
if (b & 1)
return (tmp * a) % M;
return tmp;
}
ll fact[N], invfact[N];
ll ans = 0;
void pre1() {
fact[0] = 1;
invfact[0] = power(fact[0], M - 2);
for (int i = 1; i < N; i++) {
fact[i] = (i * fact[i - 1]) % M;
invfact[i] = power(fact[i], M - 2);
}
}
ll n;
ll a[100005];
ll dp[100005];
ll fn(int i) {
if (i == n - 1)
return 0;
if (dp[i] != -1)
return dp[i];
ll a1 = 1e15, a2 = 1e15;
a1 = abs(a[i + 1] - a[i]) + fn(i + 1);
if (i < n - 1)
a2 = abs(a[i + 2] - a[i]) + fn(i + 2);
return dp[i] = min(a1, a2);
}
int main() {
memset(dp, -1, sizeof dp);
// dp[0]=0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
cout << fn(0) << endl;
} |
// jha4032
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long int
#define mp make_pair
#define M 1000000007
#define N 1000006
void fast() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
ll power(ll a, ll b) {
if (b == 0)
return 1;
ll tmp = power(a, b / 2) % M;
tmp = (tmp * tmp) % M;
if (b & 1)
return (tmp * a) % M;
return tmp;
}
ll fact[N], invfact[N];
ll ans = 0;
void pre1() {
fact[0] = 1;
invfact[0] = power(fact[0], M - 2);
for (int i = 1; i < N; i++) {
fact[i] = (i * fact[i - 1]) % M;
invfact[i] = power(fact[i], M - 2);
}
}
ll n;
ll a[100005];
ll dp[100005];
ll fn(int i) {
if (i == n - 1)
return 0;
if (dp[i] != -1)
return dp[i];
ll a1 = 1e15, a2 = 1e15;
a1 = abs(a[i + 1] - a[i]) + fn(i + 1);
if (i < n - 2)
a2 = abs(a[i + 2] - a[i]) + fn(i + 2);
return dp[i] = min(a1, a2);
}
int main() {
memset(dp, -1, sizeof dp);
// dp[0]=0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
cout << fn(0) << endl;
} | [
"literal.number.change",
"control_flow.branch.if.condition.change"
] | 956,623 | 956,624 | u897346581 | cpp |
p03160 | #include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
int main() {
// FASTIO
int n;
int arr[n];
long long dp[n];
cin >> n;
for (int i = 0; i < n; i++)
cin >> arr[i];
fill(dp, dp + n, INF);
dp[0] = 0;
for (int i = 1; i < n; ++i) {
dp[i] = min(dp[i], dp[i - 1] + abs(arr[i] - arr[i - 1]));
if (i > 1)
dp[i] = min(dp[i], dp[i - 2] + abs(arr[i] - arr[i - 2]));
}
cout << dp[n - 1];
return 0;
} | #include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
int main() {
// FASTIO
int n;
int arr[110000];
long long dp[110000];
cin >> n;
for (int i = 0; i < n; i++)
cin >> arr[i];
fill(dp, dp + n, INF);
dp[0] = 0;
for (int i = 1; i < n; ++i) {
dp[i] = min(dp[i], dp[i - 1] + abs(arr[i] - arr[i - 1]));
if (i > 1)
dp[i] = min(dp[i], dp[i - 2] + abs(arr[i] - arr[i - 2]));
}
cout << dp[n - 1] << endl;
return 0;
} | [
"identifier.replace.remove",
"literal.replace.add",
"variable_declaration.array_dimensions.change",
"io.output.newline.add"
] | 956,629 | 956,628 | u506632698 | cpp |
p03160 | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
const int Maxn = 100010;
const int INF = 100010;
int dp[Maxn], h[Maxn];
int main() {
int n, k;
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> h[i];
}
fill(dp, dp + Maxn, INF);
dp[0] = 0;
for (int i = 0; i < n; ++i) {
for (int j = 1; j < 3; ++j) {
dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]));
}
}
cout << dp[n - 1] << endl;
return 0;
} | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
const int Maxn = 100010;
const int INF = (int)1e9;
int dp[Maxn], h[Maxn];
int main() {
int n, k;
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> h[i];
}
fill(dp, dp + Maxn, INF);
dp[0] = 0;
for (int i = 0; i < n; ++i) {
for (int j = 1; j < 3; ++j) {
dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]));
}
}
cout << dp[n - 1] << endl;
return 0;
} | [
"type_conversion.add"
] | 956,630 | 956,631 | u456333842 | cpp |
p03160 | #include <bits/stdc++.h>
using namespace std;
int pd[1000000];
int v[1000000], n;
int ms() {
pd[1] = 0;
pd[2] = abs(v[2] - v[1]);
for (int i = 3; i <= n - 1; i++) {
pd[i] =
min(pd[i - 1] + abs(v[i] - v[i - 1]), pd[i - 2] + abs(v[i] - v[i - 2]));
}
return pd[n - 1];
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &v[i]);
}
printf("%d\n", ms());
} | #include <bits/stdc++.h>
using namespace std;
int pd[1000000];
int v[1000000], n;
int ms() {
pd[1] = 0;
pd[2] = abs(v[2] - v[1]);
for (int i = 3; i <= n; i++) {
pd[i] =
min(pd[i - 1] + abs(v[i] - v[i - 1]), pd[i - 2] + abs(v[i] - v[i - 2]));
}
return pd[n];
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &v[i]);
}
printf("%d\n", ms());
} | [
"control_flow.loop.for.condition.change",
"expression.operation.binary.remove"
] | 956,643 | 956,644 | u201928240 | cpp |
p03160 | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define all(a) a.begin(), a.end()
#define pb push_back
#define ll long long
#define index(a) order_of_key(a)
#define value(a) find_by_order(a)
#define count_1 __builtin_popcount
#define mod(x, m) ((((x) % (m)) + (m)) % (m))
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
indexed_set;
ll dp[100005], h[100005];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout << setprecision(12);
int n;
cin >> n;
for (int i = 1; i <= n; i++)
cin >> h[i];
dp[1] = h[1];
for (int i = 2; i <= n; i++) {
dp[i] =
min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
}
cout << dp[n];
return 0;
} | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define all(a) a.begin(), a.end()
#define pb push_back
#define ll long long
#define index(a) order_of_key(a)
#define value(a) find_by_order(a)
#define count_1 __builtin_popcount
#define mod(x, m) ((((x) % (m)) + (m)) % (m))
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
indexed_set;
ll dp[100005], h[100005];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout << setprecision(12);
int n;
cin >> n;
for (int i = 1; i <= n; i++)
cin >> h[i];
dp[0] = INT_MAX;
for (int i = 2; i <= n; i++) {
dp[i] =
min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
}
cout << dp[n];
return 0;
} | [
"literal.number.change",
"assignment.variable.change",
"variable_access.subscript.index.change",
"assignment.value.change"
] | 956,645 | 956,646 | u156373316 | cpp |
p03160 | // slight modification similar logic errichto's code
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 5;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
vector<int> h(n);
for (int &x : h) {
cin >> x;
}
vector<int> dp(n, INF);
dp[0] = 0;
for (int i = 0; i < n; ++i) {
for (int j : {i + 1, i + 2}) {
if (j < n) {
dp[j] = min(dp[j], dp[i] + abs(h[i] - h[j]));
}
}
}
cout << dp[n - 1] << "\n";
return 0;
} | // slight modification similar logic errichto's code
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 5;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
vector<int> h(n);
for (int &x : h) {
cin >> x;
}
vector<int> dp(n, INF);
dp[0] = 0;
for (int i = 0; i < n; ++i) {
for (int j : {i + 1, i + 2}) {
if (j < n) {
dp[j] = min(dp[j], dp[i] + abs(h[i] - h[j]));
}
}
}
cout << dp[n - 1] << "\n";
return 0;
} | [] | 956,654 | 956,655 | u280634298 | cpp |
p03160 | #include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int N;
cin >> N;
vector<int> vi(N);
for (int i = 0; i < N; ++i) {
cin >> vi[i];
}
if (N <= 1) {
cout << 0 << "\n";
return 0;
}
/*
vector<int> dp(N);
dp[0] = 0, dp[1] = abs(vi[1] - vi[0]);
for(int i = 2; i < N ; ++i){
dp[i] = min (abs(vi[i] - vi[i-1]) + dp[i-1], abs(vi[i] - vi[i-2])+
dp[i-2]);
}
*/
int d1 = 0, d2 = abs(vi[1] - vi[0]), d3 = 0;
for (int i = 2; i < N; ++i) {
d3 = min(abs(vi[i] - vi[i - 1]) + d2, abs(vi[i] - vi[i - 2]) + d1);
d1 = d2;
d2 = d3;
}
cout << d3 << "\n";
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int N;
cin >> N;
vector<int> vi(N);
for (int i = 0; i < N; ++i) {
cin >> vi[i];
}
if (N <= 1) {
cout << 0 << "\n";
return 0;
}
/*
vector<int> dp(N);
dp[0] = 0, dp[1] = abs(vi[1] - vi[0]);
for(int i = 2; i < N ; ++i){
dp[i] = min (abs(vi[i] - vi[i-1]) + dp[i-1], abs(vi[i] - vi[i-2])+
dp[i-2]);
}
*/
int d1 = 0, d2 = abs(vi[1] - vi[0]), d3 = 0;
for (int i = 2; i < N; ++i) {
d3 = min(abs(vi[i] - vi[i - 1]) + d2, abs(vi[i] - vi[i - 2]) + d1);
d1 = d2;
d2 = d3;
}
cout << d2 << "\n";
return 0;
} | [
"identifier.change",
"io.output.change"
] | 956,656 | 956,657 | u280634298 | cpp |
p03160 | #include <bits/stdc++.h>
using namespace std;
const int INF = 1e5 + 9;
int main() {
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// ios_base::sync_with_stdio(0); cin.tie(NULL);
int n;
cin >> n;
vector<int> a(n);
for (int &x : a) {
scanf("%d", &x);
}
vector<int> dp(n, INF);
dp[0] = 0;
for (int i = 0; i < n; i++) {
for (int j : {i + 1, i + 2}) {
if (j < n)
dp[j] = min(dp[j], dp[i] + abs(a[i] - a[j]));
}
}
cout << dp[n - 1];
// return 0;
} | #include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 5;
int main() {
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// ios_base::sync_with_stdio(0); cin.tie(NULL);
int n;
cin >> n;
vector<int> a(n);
for (int &x : a) {
scanf("%d", &x);
}
vector<int> dp(n, INF);
dp[0] = 0;
for (int i = 0; i < n; i++) {
for (int j : {i + 1, i + 2}) {
if (j < n)
dp[j] = min(dp[j], dp[i] + abs(a[i] - a[j]));
}
}
cout << dp[n - 1];
// return 0;
}
| [
"literal.number.change",
"expression.operation.binary.change"
] | 956,658 | 956,659 | u327949948 | cpp |
p03160 | #include <iostream>
using namespace std;
int N;
int H[100005];
int DP[100005];
int main() {
cin >> N;
for (int i = 0; i < N; i++)
cin >> H[i + 1];
H[0] = H[1];
for (int i = 2; i < N + 1; i++)
DP[i] =
min(DP[i - 1] + abs(H[i] - H[i - 1]), DP[i - 2] + abs(H[i] - H[i - 1]));
cout << DP[N];
} | #include <iostream>
using namespace std;
int N;
int H[100005];
int DP[100005];
int main() {
cin >> N;
for (int i = 0; i < N; i++)
cin >> H[i + 1];
H[0] = H[1];
for (int i = 2; i < N + 1; i++)
DP[i] =
min(DP[i - 1] + abs(H[i] - H[i - 1]), DP[i - 2] + abs(H[i] - H[i - 2]));
cout << DP[N];
} | [
"literal.number.change",
"assignment.value.change",
"variable_access.subscript.index.change",
"call.arguments.change",
"expression.operation.binary.change"
] | 956,664 | 956,665 | u462369736 | cpp |
p03160 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int niza[n];
for (int i = 0; i < n; i++) {
cin >> niza[i];
}
int dp[n];
memset(dp, -1, sizeof(dp));
dp[0] = niza[0];
dp[1] = abs(niza[1] - niza[0]);
for (int i = 2; i < n; i++) {
dp[i] = min(dp[i - 1] + abs(niza[i] - niza[i - 1]),
dp[i - 2] + abs(niza[i] - niza[i - 2]));
}
cout << dp[n - 1] << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int niza[n];
for (int i = 0; i < n; i++) {
cin >> niza[i];
}
int dp[n];
memset(dp, -1, sizeof(dp));
dp[0] = 0;
dp[1] = abs(niza[1] - niza[0]);
for (int i = 2; i < n; i++) {
dp[i] = min(dp[i - 1] + abs(niza[i] - niza[i - 1]),
dp[i - 2] + abs(niza[i] - niza[i - 2]));
}
cout << dp[n - 1] << endl;
return 0;
} | [] | 956,686 | 956,687 | u430341757 | cpp |
p03160 | #include "bits/stdc++.h"
using namespace std;
#define sim template <class c
#define ris return *this
#define dor > debug &operator<<
#define eni(x) \
sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<( \
c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c *x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i;
ris;
} eni(==) ris << range(begin(i), end(i));
}
sim, class b dor(pair<b, c> d) {
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
*this << "[";
for (auto it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
#else
sim dor(const c &) { ris; }
#endif
}
;
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
using vii = vector<ii>;
const ll oo = 1e18L + 7;
int abso(ll a) {
if (a < 0)
return -a;
return a;
}
vector<ll> h, dp;
int n;
int main() {
scanf("%d", &n);
h.resize(n + 1);
for (int i = 1; i <= n; ++i) {
scanf("%lld", &h[i]);
}
dp.assign(n + 1, oo);
dp[0] = 0;
for (int i = 1; i <= n; ++i) {
for (int j = i + 1; j <= i + 2 && j <= n; ++j) {
dp[j] = min(dp[j], dp[i] + abso(h[i] - h[j]));
}
}
printf("%lld\n", dp[n]);
return 0;
}
| #include "bits/stdc++.h"
using namespace std;
#define sim template <class c
#define ris return *this
#define dor > debug &operator<<
#define eni(x) \
sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<( \
c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c *x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i;
ris;
} eni(==) ris << range(begin(i), end(i));
}
sim, class b dor(pair<b, c> d) {
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
*this << "[";
for (auto it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
#else
sim dor(const c &) { ris; }
#endif
}
;
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
using vii = vector<ii>;
const ll oo = 1e18L + 7;
int abso(ll a) {
if (a < 0)
return -a;
return a;
}
vector<ll> h, dp;
int n;
int main() {
scanf("%d", &n);
h.resize(n + 1);
for (int i = 1; i <= n; ++i) {
scanf("%lld", &h[i]);
}
dp.assign(n + 1, oo);
dp[1] = 0;
for (int i = 1; i <= n; ++i) {
for (int j = i + 1; j <= i + 2 && j <= n; ++j) {
dp[j] = min(dp[j], dp[i] + abso(h[i] - h[j]));
}
}
printf("%lld\n", dp[n]);
return 0;
}
| [
"literal.number.change",
"assignment.variable.change",
"variable_access.subscript.index.change"
] | 956,696 | 956,697 | u286318237 | cpp |
p03160 | #include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define nl '\n'
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define flood(x) memset(x, 0x3f, sizeof x)
#define drain(x) memset(x, 0, sizeof x)
#define dcit \
cin.sync_with_stdio(0); \
cin.tie(0);
#define frp(x, y) \
freopen(x, "r", stdin); \
freopen(y, "w", stdout);
typedef pair<int, int> pii;
typedef long long ll;
#ifdef LOCAL_PROJECT
#define gc getchar()
#define pc(x) putchar(x)
#endif
#ifndef LOCAL_PROJECT
#define gc getchar_unlocked()
#define pc(x) putchar_unlocked(x)
#endif
template <typename T> void scani(T &x) {
x = 0;
register bool _ = 0;
register T c = gc;
_ = c == 45;
c = _ ? gc : c;
while (c < 48 || c > 57)
c = gc;
for (; c < 48 || c > 57; c = gc)
;
for (; c > 47 && c < 58; c = gc)
x = (x << 3) + (x << 1) + (c & 15);
x = _ ? -x : x;
}
template <typename T> void printi(T n) {
register bool _ = 0;
_ = n < 0;
n = _ ? -n : n;
char snum[65];
int i = 0;
do {
snum[i++] = n % 10 + 48;
n /= 10;
} while (n);
--i;
if (_)
pc(45);
while (i >= 0)
pc(snum[i--]);
pc(10);
}
string nextstring() {
string r;
register char c = gc;
while (c == 32 || c == 10)
c = gc;
while (!(c == 32 || c == 10)) {
r += c;
c = gc;
}
return r;
}
char nextgetchar() {
register char c = gc;
while (c == 32 || c == 10)
c = gc;
return c;
}
void prints(string k) {
for (int i = 0; i < k.length(); i++)
pc(k[i]);
}
void scani() {}
template <typename First, typename... Ints>
void scani(First &arg, Ints &...rest) {
scani(arg);
scani(rest...);
}
int N;
ll a[100005], dp[100005];
int main() {
flood(dp);
scani(N);
for (int i = 1; i <= N; i++)
scani(a[i]);
dp[1] = dp[0] = 0;
for (int i = 2; i <= N; i++)
dp[i] =
min(abs(a[i] - a[i - 1]) + dp[i - 1], abs(a[i] - a[i - 2]) + dp[i - 2]);
printi(dp[N]);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define nl '\n'
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define flood(x) memset(x, 0x3f, sizeof x)
#define drain(x) memset(x, 0, sizeof x)
#define dcit \
cin.sync_with_stdio(0); \
cin.tie(0);
#define frp(x, y) \
freopen(x, "r", stdin); \
freopen(y, "w", stdout);
typedef pair<int, int> pii;
typedef long long ll;
#ifdef LOCAL_PROJECT
#define gc getchar()
#define pc(x) putchar(x)
#endif
#ifndef LOCAL_PROJECT
#define gc getchar_unlocked()
#define pc(x) putchar_unlocked(x)
#endif
template <typename T> void scani(T &x) {
x = 0;
register bool _ = 0;
register T c = gc;
_ = c == 45;
c = _ ? gc : c;
while (c < 48 || c > 57)
c = gc;
for (; c < 48 || c > 57; c = gc)
;
for (; c > 47 && c < 58; c = gc)
x = (x << 3) + (x << 1) + (c & 15);
x = _ ? -x : x;
}
template <typename T> void printi(T n) {
register bool _ = 0;
_ = n < 0;
n = _ ? -n : n;
char snum[65];
int i = 0;
do {
snum[i++] = n % 10 + 48;
n /= 10;
} while (n);
--i;
if (_)
pc(45);
while (i >= 0)
pc(snum[i--]);
pc(10);
}
string nextstring() {
string r;
register char c = gc;
while (c == 32 || c == 10)
c = gc;
while (!(c == 32 || c == 10)) {
r += c;
c = gc;
}
return r;
}
char nextgetchar() {
register char c = gc;
while (c == 32 || c == 10)
c = gc;
return c;
}
void prints(string k) {
for (int i = 0; i < k.length(); i++)
pc(k[i]);
}
void scani() {}
template <typename First, typename... Ints>
void scani(First &arg, Ints &...rest) {
scani(arg);
scani(rest...);
}
int N;
ll a[100005], dp[100005];
int main() {
flood(dp);
scani(N);
for (int i = 1; i <= N; i++)
scani(a[i]);
dp[1] = 0;
for (int i = 2; i <= N; i++)
dp[i] =
min(abs(a[i] - a[i - 1]) + dp[i - 1], abs(a[i] - a[i - 2]) + dp[i - 2]);
printi(dp[N]);
return 0;
}
| [
"assignment.change"
] | 956,698 | 956,699 | u777445689 | cpp |
p03160 | #include <bits/stdc++.h>
#define foru(a, b, c) for (int a = b; a <= c; ++a)
#define int long long
using namespace std;
int n, a[100001];
int h[100001];
main() {
cin >> n;
foru(i, 1, n) cin >> h[i];
foru(i, 2, n) a[i] = INT_MAX;
a[1] = 0;
foru(i, 1, n - 2) {
a[i + 1] = min(a[i + 1], a[i] + abs(h[i + 1] - h[i]));
a[i + 2] = min(a[i + 2], a[i] + abs(h[i + 2] - h[i]));
}
cout << a[n];
}
| #include <bits/stdc++.h>
#define foru(a, b, c) for (int a = b; a <= c; ++a)
#define int long long
using namespace std;
int n, a[100001];
int h[100001];
main() {
cin >> n;
foru(i, 1, n) cin >> h[i];
foru(i, 2, n) a[i] = INT_MAX;
a[1] = 0;
foru(i, 1, n - 1) {
a[i + 1] = min(a[i + 1], a[i] + abs(h[i + 1] - h[i]));
a[i + 2] = min(a[i + 2], a[i] + abs(h[i + 2] - h[i]));
}
cout << a[n];
}
| [
"literal.number.change",
"call.arguments.change",
"expression.operation.binary.change"
] | 956,702 | 956,703 | u089870626 | cpp |
p03160 | #include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> sassi;
int numSassi;
cin >> numSassi;
sassi.resize(numSassi);
for (int i = 0; i < sassi.size(); i++) {
cin >> sassi[i];
}
int costoPrec, costoPrecPrec, temp;
costoPrec = abs(sassi[0] - sassi[1]);
costoPrecPrec = 0;
for (int i = 2; i < numSassi; i++) {
temp = costoPrec;
costoPrec = min(costoPrec + abs(sassi[i] - sassi[i - 1]),
costoPrecPrec + abs(sassi[i] - sassi[i - 1]));
costoPrecPrec = temp;
}
cout << costoPrec << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> sassi;
int numSassi;
cin >> numSassi;
sassi.resize(numSassi);
for (int i = 0; i < sassi.size(); i++) {
cin >> sassi[i];
}
int costoPrec, costoPrecPrec, temp;
costoPrec = abs(sassi[0] - sassi[1]);
costoPrecPrec = 0;
for (int i = 2; i < numSassi; i++) {
temp = costoPrec;
costoPrec = min(costoPrec + abs(sassi[i] - sassi[i - 1]),
costoPrecPrec + abs(sassi[i] - sassi[i - 2]));
costoPrecPrec = temp;
}
cout << costoPrec << endl;
return 0;
}
| [
"literal.number.change",
"assignment.value.change",
"variable_access.subscript.index.change",
"call.arguments.change",
"expression.operation.binary.change"
] | 956,706 | 956,707 | u845396889 | cpp |
p03160 | #include <bits/stdc++.h>
#define int long long
using namespace std;
// typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<PII> VP;
// REPEAT
//------------------------------------------
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define RFOR(i, m, n) for (int i = m; i > n; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, m) RFOR(i, m, 0)
// container util
//------------------------------------------
#define pb(a) push_back(a)
#define fst first
#define snd second
#define SORT(V) sort((V).begin(), (V).end())
#define REV(V) reverse((V).begin(), (V).end())
// constant
//------------------------------------------
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI = acos(-1.0);
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
// grobal variable
//------------------------------------------
// def function
//------------------------------------------
// main
//------------------------------------------
signed main() {
int N;
VI h(N);
cin >> N;
REP(i, N) { cin >> h.at(i); }
VI dp(10010);
dp.at(1) = abs(h.at(0) - h.at(1));
FOR(i, 1, N) {
dp.at(i + 1) = min(dp.at(i) + abs(h.at(i) - h.at(i + 1)),
dp.at(i - 1) + abs(h.at(i - 1) - h.at(i + 1)));
}
cout << dp.at(N - 1) << endl;
return 0;
}
| #include <bits/stdc++.h>
#define int long long
using namespace std;
// typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<PII> VP;
// REPEAT
//------------------------------------------
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define RFOR(i, m, n) for (int i = m; i > n; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, m) RFOR(i, m, 0)
// container util
//------------------------------------------
#define pb(a) push_back(a)
#define fst first
#define snd second
#define SORT(V) sort((V).begin(), (V).end())
#define REV(V) reverse((V).begin(), (V).end())
// constant
//------------------------------------------
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI = acos(-1.0);
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
// grobal variable
//------------------------------------------
// def function
//------------------------------------------
// main
//------------------------------------------
signed main() {
int N;
VI h(100010);
cin >> N;
REP(i, N) { cin >> h.at(i); }
VI dp(100010);
dp.at(1) = abs(h.at(0) - h.at(1));
FOR(i, 1, N) {
dp.at(i + 1) = min(dp.at(i) + abs(h.at(i) - h.at(i + 1)),
dp.at(i - 1) + abs(h.at(i - 1) - h.at(i + 1)));
}
cout << dp.at(N - 1) << endl;
return 0;
}
| [
"literal.number.change",
"call.arguments.change"
] | 956,710 | 956,709 | u055131803 | cpp |
p03160 | #include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
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(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
#define REP(i, n) for (ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for (ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
const ll INF = 1LL << 60;
int N;
ll h[100010];
ll dp[10010];
ll rec(int i) {
if (dp[i] < INF)
return dp[i];
if (i == 0)
return 0;
ll res = INF;
chmin(res, rec(i - 1) + abs(h[i] - h[i - 1]));
if (i > 1)
chmin(res, rec(i - 2) + abs(h[i] - h[i - 2]));
return dp[i] = res;
}
int main() {
int N;
cin >> N;
REP(i, N) cin >> h[i];
REP(i, 100010) dp[i] = INF;
cout << rec(N - 1) << endl;
} | #include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
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(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
#define REP(i, n) for (ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for (ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
const ll INF = 1LL << 60;
int N;
ll h[100010];
ll dp[100010];
ll rec(int i) {
if (dp[i] < INF)
return dp[i];
if (i == 0)
return 0;
ll res = INF;
chmin(res, rec(i - 1) + abs(h[i] - h[i - 1]));
if (i > 1)
chmin(res, rec(i - 2) + abs(h[i] - h[i - 2]));
return dp[i] = res;
}
int main() {
int N;
cin >> N;
REP(i, N) cin >> h[i];
REP(i, 100010) dp[i] = INF;
cout << rec(N - 1) << endl;
} | [
"literal.number.change",
"variable_declaration.array_dimensions.change"
] | 956,711 | 956,712 | u824337972 | cpp |
p03160 | #include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for (ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
const int MOD = 1000000007;
void print(const std::vector<int> &v) {
std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
std::cout << std::endl;
}
int main() {
int N;
vector<int> h(N);
REP(i, N) cin >> h[i];
vector<int> cost(N, 0);
for (int i = 1; i < N; i++) {
int tcost;
if (i > 1) {
int cost_1 = cost[i - 1] + abs(h[i] - h[i - 1]);
int cost_2 = cost[i - 2] + abs(h[i] - h[i - 2]);
tcost = min(cost_1, cost_2);
} else {
tcost = cost[i - 1] + abs(h[i] - h[i - 1]);
}
cost[i] = tcost;
}
cout << cost[N - 1] << endl;
return 0;
} | #include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for (ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
const int MOD = 1000000007;
void print(const std::vector<int> &v) {
std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
std::cout << std::endl;
}
int main() {
int N;
cin >> N;
vector<int> h(N);
REP(i, N) cin >> h[i];
vector<int> cost(N, 0);
for (int i = 1; i < N; i++) {
int tcost;
if (i > 1) {
int cost_1 = cost[i - 1] + abs(h[i] - h[i - 1]);
int cost_2 = cost[i - 2] + abs(h[i] - h[i - 2]);
tcost = min(cost_1, cost_2);
} else {
tcost = cost[i - 1] + abs(h[i] - h[i - 1]);
}
cost[i] = tcost;
}
cout << cost[N - 1] << endl;
return 0;
} | [] | 956,713 | 956,714 | u824337972 | cpp |
p03160 | #include <bits/stdc++.h>
using namespace std;
int n, a[100005], f[100005];
int main() {
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
f[1] = a[1];
f[2] = abs(a[2] - a[1]);
for (int i = 3; i <= n; i++)
f[i] =
min(f[i - 1] + abs(a[i] - a[i - 1]), f[i - 2] + abs(a[i] - a[i - 2]));
cout << f[n];
}
| #include <bits/stdc++.h>
using namespace std;
int n, a[100005], f[100005];
int main() {
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
f[1] = 0;
f[2] = abs(a[2] - a[1]);
for (int i = 3; i <= n; i++)
f[i] =
min(f[i - 1] + abs(a[i] - a[i - 1]), f[i - 2] + abs(a[i] - a[i - 2]));
cout << f[n];
}
| [
"assignment.value.change",
"identifier.replace.remove",
"literal.replace.add"
] | 956,731 | 956,732 | u119908442 | cpp |
p03160 | #include <bits/stdc++.h>
#define INF (1 << 31) - 1 // INT_MAX/2
#define MOD 1000000007
#define PI acos(-1)
using ll = long long;
using ull = unsigned long long;
using P = std::pair<int, int>;
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(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
int main(int argc, char *argv[]) {
int N;
std::cin >> N;
std::vector<int> h(N);
for (int i = 0; i < N; i++) {
std::cin >> h[i];
}
// dp table
std::vector<ll> dp(N, INF);
// init dp table
// ok
// init condition
dp[0] = 0;
// loop
for (int i = 0; i < N; i++) {
chmin(dp[i + 1], dp[i] + std::abs(h[i + 1] - h[i]));
chmin(dp[i + 2], dp[i] + std::abs(h[i + 2] - h[i]));
}
std::cout << dp[N - 1] << std::endl;
return 0;
} | #include <bits/stdc++.h>
#define INF (1 << 31) - 1 // INT_MAX/2
#define MOD 1000000007
#define PI acos(-1)
using ll = long long;
using ull = unsigned long long;
using P = std::pair<int, int>;
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(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
int main(int argc, char *argv[]) {
int N;
std::cin >> N;
std::vector<int> h(N);
for (int i = 0; i < N; i++) {
std::cin >> h[i];
}
// dp table
std::vector<ll> dp(N + 2, INF);
// init dp table
// ok
// init condition
dp[0] = 0;
// loop
for (int i = 0; i < N; i++) {
chmin(dp[i + 1], dp[i] + std::abs(h[i + 1] - h[i]));
chmin(dp[i + 2], dp[i] + std::abs(h[i + 2] - h[i]));
}
std::cout << dp[N - 1] << std::endl;
return 0;
} | [
"assignment.change"
] | 956,738 | 956,739 | u458798873 | cpp |
p03160 | #include <bits/stdc++.h>
#define INF (1 << 31) - 1 // INT_MAX/2
#define MOD 1000000007
#define PI acos(-1)
using ll = long long;
using ull = unsigned long long;
using P = std::pair<int, int>;
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(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
int main(int argc, char *argv[]) {
int N;
std::cin >> N;
std::vector<int> h(N);
for (int i = 0; i < N; i++) {
std::cin >> h[i];
}
// dp table
std::vector<ll> dp(N, INF);
// init dp table
// ok
// init condition
dp[0] = 0;
// loop
for (int i = 0; i < N - 2; i++) {
chmin(dp[i + 1], dp[i] + std::abs(h[i + 1] - h[i]));
chmin(dp[i + 2], dp[i] + std::abs(h[i + 2] - h[i]));
}
std::cout << dp[N - 1] << std::endl;
return 0;
} | #include <bits/stdc++.h>
#define INF (1 << 31) - 1 // INT_MAX/2
#define MOD 1000000007
#define PI acos(-1)
using ll = long long;
using ull = unsigned long long;
using P = std::pair<int, int>;
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(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
int main(int argc, char *argv[]) {
int N;
std::cin >> N;
std::vector<int> h(N);
for (int i = 0; i < N; i++) {
std::cin >> h[i];
}
// dp table
std::vector<ll> dp(N + 2, INF);
// init dp table
// ok
// init condition
dp[0] = 0;
// loop
for (int i = 0; i < N; i++) {
chmin(dp[i + 1], dp[i] + std::abs(h[i + 1] - h[i]));
chmin(dp[i + 2], dp[i] + std::abs(h[i + 2] - h[i]));
}
std::cout << dp[N - 1] << std::endl;
return 0;
} | [
"control_flow.loop.for.condition.change",
"expression.operation.binary.remove"
] | 956,740 | 956,739 | u458798873 | cpp |
p03160 | #include <bits/stdc++.h>
#define endl '\n'
#define FIO \
ios_base::sync_with_stdio(false); \
cin.tie(NULL)
#define ll long long
using namespace std;
const int N = 1e5 + 10;
const int M = 1e9 + 7;
int main() {
FIO;
int n;
cin >> n;
int a[n + 2], b[n + 2];
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
b[0] = a[0];
b[1] = abs(a[1] - a[0]);
for (int i = 2; i < n; ++i) {
b[i] =
min(b[i - 1] + abs(a[i] - a[i - 1]), b[i - 2] + abs(a[i] - a[i - 2]));
}
// for (int i = 0; i < n; ++i)
// {
// cout << b[i] << " ";
// }
cout << b[n - 1];
} | #include <bits/stdc++.h>
#define endl '\n'
#define FIO \
ios_base::sync_with_stdio(false); \
cin.tie(NULL)
#define ll long long
using namespace std;
const int N = 1e5 + 10;
const int M = 1e9 + 7;
int main() {
FIO;
int n;
cin >> n;
int a[n + 2], b[n + 2];
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
b[0] = 0;
b[1] = abs(a[1] - a[0]);
for (int i = 2; i < n; ++i) {
b[i] =
min(b[i - 1] + abs(a[i] - a[i - 1]), b[i - 2] + abs(a[i] - a[i - 2]));
}
// for (int i = 0; i < n; ++i)
// {
// cout << b[i] << " ";
// }
cout << b[n - 1];
} | [] | 956,745 | 956,746 | u714262341 | cpp |
p03160 | #include <bits/stdc++.h>
using namespace std;
int n, h[100010], dp[100010];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", h + i);
if (i == 1)
dp[1] = 0;
else {
dp[i] = 2e9;
dp[i] = min(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));
if (i >= 3)
dp[i] = min(dp[i], dp[i - 2] + abs(h[i] - h[i - 1]));
}
}
printf("%d", dp[n]);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int n, h[100010], dp[100010];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", h + i);
if (i == 1)
dp[1] = 0;
else {
dp[i] = 2e9;
dp[i] = min(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));
if (i >= 3)
dp[i] = min(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
}
}
printf("%d", dp[n]);
return 0;
} | [
"literal.number.change",
"assignment.value.change",
"variable_access.subscript.index.change",
"call.arguments.change",
"expression.operation.binary.change"
] | 956,750 | 956,751 | u825075571 | cpp |
p03160 | #include "bits/stdc++.h"
using namespace std;
#define fast \
ios_base::sync_with_stdio(0); \
cin.tie(NULL); \
cout.tie(NULL)
const int N = 1e6 + 5;
const int MOD = 1e9 + 7;
typedef long long int ll;
vector<pair<ll, ll>> vp;
map<ll, ll> mp, mpp;
vector<ll> v, v1, v2;
ll dp[N], visit[N];
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
const char *comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << " : " << arg1 << " ";
__f(comma + 1, args...);
}
#else
#define trace(...)
#endif
int a[N];
ll go(int n) {
int x = 1e9 + 5, y = 1e9 + 5;
if (dp[n] != -1)
return dp[n];
if (n <= 1)
return 0;
if (n >= 2)
x = abs(a[n] - a[n - 2]) + go(n - 2);
if (n >= 1)
y = abs(a[n] - a[n - 1]) + go(n - 1);
return dp[n] = min(x, y);
}
int main() {
fast;
ll n, m, val, k, d, mi = 1e9, mx(0);
ll sum(0), ct(0), p(0), q(0);
string s;
cin >> n;
memset(dp, -1, sizeof(dp));
for (int i = 1; i <= n; i++)
cin >> a[i];
cout << go(n);
}
| #include "bits/stdc++.h"
using namespace std;
#define fast \
ios_base::sync_with_stdio(0); \
cin.tie(NULL); \
cout.tie(NULL)
const int N = 1e6 + 5;
const int MOD = 1e9 + 7;
typedef long long int ll;
vector<pair<ll, ll>> vp;
map<ll, ll> mp, mpp;
vector<ll> v, v1, v2;
ll dp[N], visit[N];
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
const char *comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << " : " << arg1 << " ";
__f(comma + 1, args...);
}
#else
#define trace(...)
#endif
int a[N];
ll go(int n) {
int x = 1e9 + 5, y = 1e9 + 5;
if (dp[n] != -1)
return dp[n];
if (n <= 1)
return 0;
if (n > 2)
x = abs(a[n] - a[n - 2]) + go(n - 2);
if (n > 1)
y = abs(a[n] - a[n - 1]) + go(n - 1);
return dp[n] = min(x, y);
}
int main() {
fast;
ll n, m, val, k, d, mi = 1e9, mx(0);
ll sum(0), ct(0), p(0), q(0);
string s;
cin >> n;
memset(dp, -1, sizeof(dp));
for (int i = 1; i <= n; i++)
cin >> a[i];
cout << go(n);
}
| [
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 956,752 | 956,753 | u162220269 | cpp |
p03160 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
const ll INF = 1LL << 60;
int N;
ll h[100001];
ll dp[100001];
ll f(int i) {
if (dp[i] < INF)
return dp[i];
if (i == 1)
return 0;
ll res = INF;
chmin(res, f(i - 1) + abs(h[i] - h[i - 1]));
if (i > 2)
chmin(res, f(i - 2) + abs(h[i] - h[i - 1]));
return dp[i] = res;
}
int main() {
ios::sync_with_stdio(false);
cin >> N;
for (int i = 0; i < 100001; ++i)
dp[i] = INF;
for (int i = 1; i <= N; i++) {
cin >> h[i];
}
/*
dp[1] = 0;
for(int i = 2; i <= N; ++i){
chmin(dp[i], dp[i-1] + abs(h[i] - h[i-1]));
if(i > 2) chmin(dp[i], dp[i-2] + abs(h[i] - h[i-2]));
}
*/
/*
for (int i = 1; i <= N; i++) {
chmin(dp[i+1], dp[i] + abs(h[i] - h[i+1]));
chmin(dp[i+2], dp[i] + abs(h[i] - h[i+2]));
}
cout << dp[N] << endl;
*/
cout << f(N) << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
const ll INF = 1LL << 60;
int N;
ll h[100001];
ll dp[100001];
ll f(int i) {
if (dp[i] < INF)
return dp[i];
if (i == 1)
return 0;
ll res = INF;
chmin(res, f(i - 1) + abs(h[i] - h[i - 1]));
if (i > 2)
chmin(res, f(i - 2) + abs(h[i] - h[i - 2]));
return dp[i] = res;
}
int main() {
ios::sync_with_stdio(false);
cin >> N;
for (int i = 0; i <= 100001; ++i)
dp[i] = INF;
for (int i = 1; i <= N; i++) {
cin >> h[i];
}
/*
dp[1] = 0;
for(int i = 2; i <= N; ++i){
chmin(dp[i], dp[i-1] + abs(h[i] - h[i-1]));
if(i > 2) chmin(dp[i], dp[i-2] + abs(h[i] - h[i-2]));
}
*/
/*
for (int i = 1; i <= N; i++) {
chmin(dp[i+1], dp[i] + abs(h[i] - h[i+1]));
chmin(dp[i+2], dp[i] + abs(h[i] - h[i+2]));
}
cout << dp[N] << endl;
*/
cout << f(N) << endl;
return 0;
}
| [
"literal.number.change",
"variable_access.subscript.index.change",
"call.arguments.change",
"expression.operation.binary.change",
"expression.operator.compare.change",
"control_flow.loop.for.condition.change",
"expression.off_by_one"
] | 956,758 | 956,759 | u257960005 | cpp |
p03160 | #include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define lli long long int
#define ulli unsigned long long int
#define ld long double
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define loop(i, a, b) for (lli i = a; i < b; i++)
#define initialize(array, size, value) \
for (lli i = 0; i < size; i++) \
array[i] = value
#define couta(array, size) \
for (lli i = 0; i < size; i++) \
cout << array[i] << " "
#define vl vector<lli>
#define vp vector<pair<lli, lli>>
#define sl set<lli>
#define msp multiset<pair<long long, long long>> S;
#define pll pair<lli, lli>
#define mll \
map<lli, \
lli> // for( map<lli, lli>::iterator
// i=temp.begin();i!=temp.end();i++)cout<<i->fi<<" "<<i->se<<endl;
#define mvl map<lli, vl>
#define umll unordered_map<lli, lli>
#define vt vector<pair<lli, pll>>
#define vf vector<pair<pll, pll>>
#define qu queue<lli>
#define pq priority_queue<lli>
#define dq deque<lli>
#define ptr vector<lli>::iterator
#define bs(array, x) \
binary_search(array.begin(), array.end(), \
x) // also valid for set and multiset
#define lb(array, x) lower_bound(array.begin(), array.end(), x)
#define ub(array, x) upper_bound(array.begin(), array.end(), x)
#define nobw(array, i, j) \
upper_bound(array.begin(), array.end(), j) - \
lower_bound(array.begin(), array.end(), \
i) // number of numbers between i & j
#define vc clear()
#define endl '\n'
#define sp system("pause");
#define INF 9223372036854775807
#define MINF -9223372036854775808
typedef tree<pll, null_type, less<pll>, rb_tree_tag,
tree_order_statistics_node_update>
indexed_set;
int main() {
// ios::sync_with_stdio(0);
// cin.tie(0);
lli n;
cin >> n;
lli a[n];
for (lli i = 0; i < n; i++)
cin >> a[i];
lli ans[n + 1];
ans[0] = 0, ans[1] = abs(a[1] - a[0]);
for (lli i = 2; i < n; i++)
ans[i] = min(ans[i - 1] + abs(a[i] - a[i - 1]), ans[i - 2] + abs(a[i - 2]));
cout << ans[n - 1];
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define lli long long int
#define ulli unsigned long long int
#define ld long double
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define loop(i, a, b) for (lli i = a; i < b; i++)
#define initialize(array, size, value) \
for (lli i = 0; i < size; i++) \
array[i] = value
#define couta(array, size) \
for (lli i = 0; i < size; i++) \
cout << array[i] << " "
#define vl vector<lli>
#define vp vector<pair<lli, lli>>
#define sl set<lli>
#define msp multiset<pair<long long, long long>> S;
#define pll pair<lli, lli>
#define mll \
map<lli, \
lli> // for( map<lli, lli>::iterator
// i=temp.begin();i!=temp.end();i++)cout<<i->fi<<" "<<i->se<<endl;
#define mvl map<lli, vl>
#define umll unordered_map<lli, lli>
#define vt vector<pair<lli, pll>>
#define vf vector<pair<pll, pll>>
#define qu queue<lli>
#define pq priority_queue<lli>
#define dq deque<lli>
#define ptr vector<lli>::iterator
#define bs(array, x) \
binary_search(array.begin(), array.end(), \
x) // also valid for set and multiset
#define lb(array, x) lower_bound(array.begin(), array.end(), x)
#define ub(array, x) upper_bound(array.begin(), array.end(), x)
#define nobw(array, i, j) \
upper_bound(array.begin(), array.end(), j) - \
lower_bound(array.begin(), array.end(), \
i) // number of numbers between i & j
#define vc clear()
#define endl '\n'
#define sp system("pause");
#define INF 9223372036854775807
#define MINF -9223372036854775808
typedef tree<pll, null_type, less<pll>, rb_tree_tag,
tree_order_statistics_node_update>
indexed_set;
int main() {
// ios::sync_with_stdio(0);
// cin.tie(0);
lli n;
cin >> n;
lli a[n];
for (lli i = 0; i < n; i++)
cin >> a[i];
lli ans[n + 1];
ans[0] = 0, ans[1] = abs(a[1] - a[0]);
for (lli i = 2; i < n; i++)
ans[i] = min(ans[i - 1] + abs(a[i] - a[i - 1]),
ans[i - 2] + abs(a[i] - a[i - 2]));
cout << ans[n - 1];
// couta(ans,n);
return 0;
}
| [
"assignment.change"
] | 956,762 | 956,763 | u774144672 | cpp |
p03160 | #define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <vector>
using namespace std;
#define read freopen("in.in", "r", stdin)
#define write freopen("out.out", "w", stdout)
#define FastIO ios::sync_with_stdio(0)
typedef long long ll;
int n;
int cost[100005];
int memo[100005];
int dp(int idx) {
if (idx > n)
return 9999999;
if (idx == n - 1)
return 0;
int &ret = memo[idx];
if (ret != -1)
return ret;
ret = min(dp(idx + 1) + abs(cost[idx + 1] - cost[idx]),
dp(idx + 2) + abs(cost[idx] - cost[idx + 2]));
return ret;
}
int main() {
FastIO;
#ifndef ONLINE_JUDGE
write;
read;
#endif
memset(memo, -1, sizeof memo);
cin >> n;
for (int i = 0; i < n; i++)
cin >> cost[i];
cout << dp(0) << endl;
return 0;
} | #define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <vector>
using namespace std;
#define read freopen("in.in", "r", stdin)
#define write freopen("out.out", "w", stdout)
#define FastIO ios::sync_with_stdio(0)
typedef long long ll;
int n;
int cost[100005];
int memo[100005];
int dp(int idx) {
if (idx > n)
return 9999999;
if (idx == n - 1)
return 0;
int &ret = memo[idx];
if (ret != -1)
return ret;
ret = min(dp(idx + 1) + abs(cost[idx + 1] - cost[idx]),
dp(idx + 2) + abs(cost[idx] - cost[idx + 2]));
return ret;
}
int main() {
FastIO;
#ifndef ONLINE_JUDGE
// write; read;
#endif
memset(memo, -1, sizeof memo);
cin >> n;
for (int i = 0; i < n; i++)
cin >> cost[i];
cout << dp(0) << endl;
return 0;
} | [] | 956,771 | 956,772 | u511749049 | cpp |
p03160 | #include <algorithm>
#include <climits>
#include <iostream>
using namespace std;
int n;
int h[10010];
int dp[10010];
int main() {
cin >> n;
for (int i = 0; i < n; ++i)
cin >> h[i];
for (int i = 0; i < n; i++)
dp[i] = INT_MAX;
dp[0] = 0;
dp[1] = abs(dp[0] - h[1]);
for (int i = 1; i < n - 1; ++i) {
dp[i + 1] =
min(dp[i] + abs(h[i] - h[i + 1]), dp[i - 1] + abs(h[i - 1] - h[i + 1]));
}
cout << dp[n - 1] << endl;
}
| #include <algorithm>
#include <climits>
#include <iostream>
using namespace std;
int n;
int h[100010];
int dp[100010];
int main() {
cin >> n;
for (int i = 0; i < n; ++i)
cin >> h[i];
for (int i = 0; i < n; i++)
dp[i] = INT_MAX;
dp[0] = 0;
dp[1] = abs(h[0] - h[1]);
for (int i = 1; i < n - 1; ++i) {
dp[i + 1] =
min(dp[i] + abs(h[i] - h[i + 1]), dp[i - 1] + abs(h[i - 1] - h[i + 1]));
}
cout << dp[n - 1] << endl;
}
| [
"literal.number.change",
"variable_declaration.array_dimensions.change",
"assignment.value.change",
"identifier.change",
"call.arguments.change",
"expression.operation.binary.change"
] | 956,773 | 956,774 | u542670845 | cpp |
p03160 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int h[n];
int cost[n] = {};
for (int i = 0; i < n; i++) {
cin >> h[i];
}
for (int i = 0; i < n; i++) {
if (i == 0)
continue;
if (i == 1) {
cost[i] = abs(cost[i - 1] - cost[i]);
continue;
}
cost[i] = min(abs(cost[i - 1] - cost[i]) + cost[i - 1],
abs(cost[i - 2] - cost[i]) + cost[i - 2]);
}
cout << cost[n - 1] << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int h[n];
int cost[n] = {};
for (int i = 0; i < n; i++) {
cin >> h[i];
}
for (int i = 0; i < n; i++) {
if (i == 0)
continue;
if (i == 1) {
cost[i] = abs(h[i - 1] - h[i]);
continue;
}
cost[i] = min(abs(h[i - 1] - h[i]) + cost[i - 1],
abs(h[i - 2] - h[i]) + cost[i - 2]);
}
cout << cost[n - 1] << endl;
}
| [
"assignment.value.change",
"identifier.change",
"call.arguments.change",
"expression.operation.binary.change"
] | 956,782 | 956,783 | u798086274 | cpp |
p03160 | #include <bits/stdc++.h>
#define pb push_back
#define nl "\n"
#define fastScan \
ios_base::sync_with_stdio(0); \
cin.tie(NULL);
#define int long long int
using namespace std;
int dp[123456];
int h[123456];
signed main() {
fastScan;
int n;
cin >> n;
for (int i = 1; i <= n; i++)
cin >> h[i];
dp[1] = 0;
dp[2] = dp[1] + abs(h[1] - h[2]);
for (int i = 2; i <= n; i++)
dp[i] =
min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
cout << dp[n] << nl;
}
| #include <bits/stdc++.h>
#define pb push_back
#define nl "\n"
#define fastScan \
ios_base::sync_with_stdio(0); \
cin.tie(NULL);
#define int long long int
using namespace std;
int dp[123456];
int h[123456];
signed main() {
fastScan;
int n;
cin >> n;
for (int i = 1; i <= n; i++)
cin >> h[i];
dp[1] = 0;
dp[2] = dp[1] + abs(h[1] - h[2]);
for (int i = 3; i <= n; i++)
dp[i] =
min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
cout << dp[n] << nl;
}
| [
"literal.number.change",
"variable_declaration.value.change",
"control_flow.loop.for.initializer.change",
"expression.off_by_one"
] | 956,794 | 956,795 | u273451465 | cpp |
p03160 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
#define pb push_back
#define mp make_pair
#define MAX 1000000
#define mod 1000000007
#define all(_) _.begin(), _.end()
#define F first
#define S second
int main() {
ios_base ::sync_with_stdio(false);
cin.tie(NULL), cout.tie(NULL);
ll n, i;
cin >> n;
vll a(n), dp(n);
for (i = 0; i < n; i++)
cin >> a[i];
dp[0] = 0;
dp[1] = abs(a[0] - a[1]);
for (i = 2; i < n; i++)
dp[i] =
min(dp[i - 1] + abs(a[i] - a[i - 1]), dp[i - 2] + abs(a[i] - a[i - 2]));
cout << dp[n] << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
#define pb push_back
#define mp make_pair
#define MAX 1000000
#define mod 1000000007
#define all(_) _.begin(), _.end()
#define F first
#define S second
int main() {
ios_base ::sync_with_stdio(false);
cin.tie(NULL), cout.tie(NULL);
ll n, i;
cin >> n;
vll a(n), dp(n);
for (i = 0; i < n; i++)
cin >> a[i];
dp[0] = 0;
dp[1] = abs(a[0] - a[1]);
for (i = 2; i < n; i++)
dp[i] =
min(dp[i - 1] + abs(a[i] - a[i - 1]), dp[i - 2] + abs(a[i] - a[i - 2]));
cout << dp[n - 1] << endl;
return 0;
} | [
"expression.operation.binary.add"
] | 956,796 | 956,797 | u924895886 | cpp |
p03160 | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
typedef long long ll;
#define INF 1000000000
#define MOD 1000000007
using namespace std;
ll dp[100001];
int main() {
ll n;
cin >> n;
ll h[n];
for (int i = 0; i < n; i++)
cin >> h[i];
dp[0] = 0;
dp[1] = abs(h[2] - h[1]);
for (int i = 2; i < n; i++) {
dp[i] =
min(abs(h[i] - h[i - 1]) + dp[i - 1], abs(h[i] - h[i - 2]) + dp[i - 2]);
}
cout << dp[n - 1] << endl;
}
| #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
typedef long long ll;
#define INF 1000000000
#define MOD 1000000007
using namespace std;
ll dp[100001];
int main() {
ll n;
cin >> n;
ll h[n];
for (int i = 0; i < n; i++)
cin >> h[i];
dp[0] = 0;
dp[1] = abs(h[1] - h[0]);
for (int i = 2; i < n; i++) {
dp[i] =
min(abs(h[i] - h[i - 1]) + dp[i - 1], abs(h[i] - h[i - 2]) + dp[i - 2]);
}
cout << dp[n - 1] << endl;
}
| [
"literal.number.change",
"assignment.value.change",
"variable_access.subscript.index.change",
"call.arguments.change",
"expression.operation.binary.change"
] | 956,798 | 956,799 | u387055019 | cpp |
p03160 | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
typedef long long ll;
#define INF 1000000000
#define MOD 1000000007
using namespace std;
ll dp[100001];
int main() {
ll n;
cin >> n;
ll h[n];
for (int i = 0; i < n; i++)
cin >> h[i];
dp[0] = 0;
dp[1] = abs(h[2] - h[1]);
for (int i = 3; i <= n; i++) {
dp[i] =
min(abs(h[i] - h[i - 1]) + dp[i - 1], abs(h[i] - h[i - 2]) + dp[i - 2]);
}
cout << dp[n] << endl;
}
| #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
typedef long long ll;
#define INF 1000000000
#define MOD 1000000007
using namespace std;
ll dp[100001];
int main() {
ll n;
cin >> n;
ll h[n];
for (int i = 0; i < n; i++)
cin >> h[i];
dp[0] = 0;
dp[1] = abs(h[1] - h[0]);
for (int i = 2; i < n; i++) {
dp[i] =
min(abs(h[i] - h[i - 1]) + dp[i - 1], abs(h[i] - h[i - 2]) + dp[i - 2]);
}
cout << dp[n - 1] << endl;
}
| [
"literal.number.change",
"assignment.value.change",
"variable_access.subscript.index.change",
"call.arguments.change",
"expression.operation.binary.change",
"variable_declaration.value.change",
"control_flow.loop.for.initializer.change",
"expression.off_by_one",
"expression.operator.compare.change",... | 956,800 | 956,799 | u387055019 | cpp |
p03160 | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
typedef long long ll;
#define INF 1000000000
#define MOD 1000000007
using namespace std;
ll dp[100001];
int main() {
ll n;
cin >> n;
ll h[n];
for (int i = 0; i < n; i++)
cin >> h[i];
dp[0] = 0;
dp[1] = abs(h[2] - h[1]);
for (int i = 3; i < n; i++) {
dp[i] =
min(abs(h[i] - h[i - 1]) + dp[i - 1], abs(h[i] - h[i - 2]) + dp[i - 2]);
}
cout << dp[n] << endl;
}
| #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
typedef long long ll;
#define INF 1000000000
#define MOD 1000000007
using namespace std;
ll dp[100001];
int main() {
ll n;
cin >> n;
ll h[n];
for (int i = 0; i < n; i++)
cin >> h[i];
dp[0] = 0;
dp[1] = abs(h[1] - h[0]);
for (int i = 2; i < n; i++) {
dp[i] =
min(abs(h[i] - h[i - 1]) + dp[i - 1], abs(h[i] - h[i - 2]) + dp[i - 2]);
}
cout << dp[n - 1] << endl;
}
| [
"literal.number.change",
"assignment.value.change",
"variable_access.subscript.index.change",
"call.arguments.change",
"expression.operation.binary.change",
"variable_declaration.value.change",
"control_flow.loop.for.initializer.change",
"expression.off_by_one"
] | 956,801 | 956,799 | u387055019 | cpp |
p03160 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, i;
scanf("%d", &n);
vector<int> a(n);
vector<int> dp(n);
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
auto isValid = [&](int i) {
if (i < n)
return true;
return false;
};
dp[n - 1] = 0;
for (i = n - 2; i >= 0; i--) {
dp[i] = dp[i + 1] + abs(a[i + 1] - a[i]);
if (isValid(i + 1)) {
dp[i] = min(dp[i], dp[i + 2] + abs(a[i + 2] - a[i]));
}
}
printf("%d\n", dp[0]);
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, i;
scanf("%d", &n);
vector<int> a(n);
vector<int> dp(n);
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
auto isValid = [&](int i) {
if (i < n)
return true;
return false;
};
dp[n - 1] = 0;
for (i = n - 2; i >= 0; i--) {
dp[i] = dp[i + 1] + abs(a[i + 1] - a[i]);
if (isValid(i + 2)) {
dp[i] = min(dp[i], dp[i + 2] + abs(a[i + 2] - a[i]));
}
}
printf("%d\n", dp[0]);
} | [
"literal.number.change",
"control_flow.branch.if.condition.change"
] | 956,806 | 956,807 | u294609931 | cpp |
p03160 | #include <algorithm>
#include <string>
namespace olymplib {
namespace {
template <class T> void writeInt(T x);
template <class T> void writeUInt(T x);
void writeChar(int x);
void writeWord(const char *s);
void writeDouble(double x, int len = 0);
static const int buf_size = 4096;
static int write_pos = 0;
static char write_buf[buf_size];
static char buf[buf_size];
static int buf_len = 0, buf_pos = 0;
//-- read
template <class T = int> T readInt();
double readDouble();
int readUInt();
int readChar();
void readWord(char *s);
bool readLine(char *s); // do not save '\n'
bool isEof();
int peekChar();
bool seekEof();
void flush();
//--------------------------
bool isEof() {
if (buf_pos == buf_len) {
buf_pos = 0, buf_len = fread(buf, 1, buf_size, stdin);
if (buf_pos == buf_len)
return 1;
}
return 0;
}
int getChar() { return isEof() ? -1 : buf[buf_pos++]; }
int peekChar() { return isEof() ? -1 : buf[buf_pos]; }
bool seekEof() {
int c;
while ((c = peekChar()) != -1 && c <= 32)
buf_pos++;
return c == -1;
}
int readChar() {
int c = getChar();
while (c != -1 && c <= 32)
c = getChar();
return c;
}
int readUInt() {
int c = readChar(), x = 0;
while ('0' <= c && c <= '9')
x = x * 10 + c - '0', c = getChar();
return x;
}
template <class T> T readInt() {
int s = 1, c = readChar();
T x = 0;
if (c == '-')
s = -1, c = getChar();
while ('0' <= c && c <= '9')
x = x * 10 + c - '0', c = getChar();
return s == 1 ? x : -x;
}
template <class Double = double> double readDouble() {
int s = 1, c = readChar();
Double x = 0;
if (c == '-')
s = -1, c = getChar();
while ('0' <= c && c <= '9')
x = x * 10 + c - '0', c = getChar();
if (c == '.') {
c = getChar();
double coef = 1;
while ('0' <= c && c <= '9')
x += (c - '0') * (coef *= 1e-1), c = getChar();
}
return s == 1 ? x : -x;
}
void readWord(char *s) {
int c = readChar();
while (c > 32)
*s++ = c, c = getChar();
*s = 0;
}
bool readLine(char *s) {
int c = getChar();
while (c != '\n' && c != -1)
*s++ = c, c = getChar();
*s = 0;
return c != -1;
}
// only supports fixed precision for now (hence huge values are not allowed)
void writeDouble(double x, int output_len) {
if (x < 0)
writeChar('-'), x = -x;
int t = (int)x;
writeUInt(t), x -= t;
writeChar('.');
for (int i = output_len - 1; i > 0; i--) {
x *= 10;
t = 9 < (int)x ? 9 : x;
writeChar('0' + t), x -= t;
}
x *= 10;
t = 9 < (int)(x + 0.5) ? 9 : (int)(x + 0.5);
writeChar('0' + t);
}
void writeChar(int x) {
if (write_pos == buf_size)
fwrite(write_buf, 1, buf_size, stdout), write_pos = 0;
write_buf[write_pos++] = x;
}
template <class T> void writeUInt(T x) {
char s[24];
int n = 0;
while (x || !n)
s[n++] = '0' + x % 10, x /= 10;
while (n--)
writeChar(s[n]);
}
template <> void writeInt<int>(int x) {
if (x < 0)
writeChar('-'), x = -x;
char s[10];
int n = 0;
while (x || !n)
s[n++] = '0' + x % 10, x /= 10;
while (n--)
writeChar(s[n]);
}
template <class T> void writeInt(T x) {
if (x < 0)
writeChar('-'), x = -x;
char s[24];
int n = 0;
while (x || !n)
s[n++] = '0' + x % 10, x /= 10;
while (n--)
writeChar(s[n]);
}
void writeWord(const char *s) {
while (*s)
writeChar(*s++);
}
void flush() {
if (write_pos) {
fwrite(write_buf, 1, write_pos, stdout), write_pos = 0;
}
}
} // namespace
class TOutputStream {
int precision_;
public:
void precision(int new_prec) { precision_ = new_prec; }
TOutputStream &operator<<(bool arg) {
writeChar('0' + arg);
return *this;
}
TOutputStream &operator<<(char arg) {
writeChar(arg);
return *this;
}
TOutputStream &operator<<(const char *arg) {
writeWord(arg);
return *this;
}
TOutputStream &operator<<(float arg) {
writeDouble(arg, precision_);
return *this;
}
TOutputStream &operator<<(double arg) {
writeDouble(arg, precision_);
return *this;
}
TOutputStream &operator<<(long double arg) {
writeDouble(arg, precision_);
return *this;
}
TOutputStream &operator<<(int arg) {
writeInt(arg);
return *this;
}
TOutputStream &operator<<(long long arg) {
writeInt(arg);
return *this;
}
TOutputStream &operator<<(const std::string &arg) {
writeWord(arg.c_str());
return *this;
}
void flush() { olymplib::flush(); }
typedef TOutputStream &(*MyStreamManipulator)(TOutputStream &);
TOutputStream &operator<<(const MyStreamManipulator &manip) {
return manip(*this);
}
~TOutputStream() { flush(); }
};
class TInputStream {
public:
TInputStream &operator>>(bool &arg) {
arg = readChar() - '0';
return *this;
}
TInputStream &operator>>(char &arg) {
arg = readChar();
return *this;
}
// please know what you're doing.
TInputStream &operator>>(char *&arg) {
readWord(arg);
return *this;
}
TInputStream &operator>>(float &arg) {
arg = readDouble<float>();
return *this;
}
TInputStream &operator>>(double &arg) {
arg = readDouble<double>();
return *this;
}
TInputStream &operator>>(long double &arg) {
arg = readDouble<long double>();
return *this;
}
TInputStream &operator>>(int &arg) {
arg = readInt<int>();
return *this;
}
TInputStream &operator>>(long long arg) {
arg = readInt<long long>();
return *this;
}
TInputStream &operator>>(std::string &arg) {
arg.clear();
arg.reserve(16);
arg.push_back(readChar());
while (char c = peekChar()) {
if (c == -1 || c <= 32)
break;
arg.push_back(getChar());
}
arg.shrink_to_fit();
return *this;
}
};
static TInputStream cin;
static TOutputStream cout;
static TOutputStream &endl(TOutputStream &stream) {
stream << '\n';
stream.flush();
return stream;
}
} // namespace olymplib
using namespace olymplib;
using namespace std;
const int N = 1e5;
const int INF = 1e9;
int h[N];
int dp[N];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> h[i];
}
for (int i = 1; i < n; ++i) {
dp[i] = INF;
for (int j = i - 1; j > 0 && j >= i - 2; --j) {
dp[i] = min(dp[i], dp[j] + abs(h[i] - h[j]));
}
}
cout << dp[n - 1] << endl;
return 0;
} | #include <algorithm>
#include <string>
namespace olymplib {
namespace {
template <class T> void writeInt(T x);
template <class T> void writeUInt(T x);
void writeChar(int x);
void writeWord(const char *s);
void writeDouble(double x, int len = 0);
static const int buf_size = 4096;
static int write_pos = 0;
static char write_buf[buf_size];
static char buf[buf_size];
static int buf_len = 0, buf_pos = 0;
//-- read
template <class T = int> T readInt();
double readDouble();
int readUInt();
int readChar();
void readWord(char *s);
bool readLine(char *s); // do not save '\n'
bool isEof();
int peekChar();
bool seekEof();
void flush();
//--------------------------
bool isEof() {
if (buf_pos == buf_len) {
buf_pos = 0, buf_len = fread(buf, 1, buf_size, stdin);
if (buf_pos == buf_len)
return 1;
}
return 0;
}
int getChar() { return isEof() ? -1 : buf[buf_pos++]; }
int peekChar() { return isEof() ? -1 : buf[buf_pos]; }
bool seekEof() {
int c;
while ((c = peekChar()) != -1 && c <= 32)
buf_pos++;
return c == -1;
}
int readChar() {
int c = getChar();
while (c != -1 && c <= 32)
c = getChar();
return c;
}
int readUInt() {
int c = readChar(), x = 0;
while ('0' <= c && c <= '9')
x = x * 10 + c - '0', c = getChar();
return x;
}
template <class T> T readInt() {
int s = 1, c = readChar();
T x = 0;
if (c == '-')
s = -1, c = getChar();
while ('0' <= c && c <= '9')
x = x * 10 + c - '0', c = getChar();
return s == 1 ? x : -x;
}
template <class Double = double> double readDouble() {
int s = 1, c = readChar();
Double x = 0;
if (c == '-')
s = -1, c = getChar();
while ('0' <= c && c <= '9')
x = x * 10 + c - '0', c = getChar();
if (c == '.') {
c = getChar();
double coef = 1;
while ('0' <= c && c <= '9')
x += (c - '0') * (coef *= 1e-1), c = getChar();
}
return s == 1 ? x : -x;
}
void readWord(char *s) {
int c = readChar();
while (c > 32)
*s++ = c, c = getChar();
*s = 0;
}
bool readLine(char *s) {
int c = getChar();
while (c != '\n' && c != -1)
*s++ = c, c = getChar();
*s = 0;
return c != -1;
}
// only supports fixed precision for now (hence huge values are not allowed)
void writeDouble(double x, int output_len) {
if (x < 0)
writeChar('-'), x = -x;
int t = (int)x;
writeUInt(t), x -= t;
writeChar('.');
for (int i = output_len - 1; i > 0; i--) {
x *= 10;
t = 9 < (int)x ? 9 : x;
writeChar('0' + t), x -= t;
}
x *= 10;
t = 9 < (int)(x + 0.5) ? 9 : (int)(x + 0.5);
writeChar('0' + t);
}
void writeChar(int x) {
if (write_pos == buf_size)
fwrite(write_buf, 1, buf_size, stdout), write_pos = 0;
write_buf[write_pos++] = x;
}
template <class T> void writeUInt(T x) {
char s[24];
int n = 0;
while (x || !n)
s[n++] = '0' + x % 10, x /= 10;
while (n--)
writeChar(s[n]);
}
template <> void writeInt<int>(int x) {
if (x < 0)
writeChar('-'), x = -x;
char s[10];
int n = 0;
while (x || !n)
s[n++] = '0' + x % 10, x /= 10;
while (n--)
writeChar(s[n]);
}
template <class T> void writeInt(T x) {
if (x < 0)
writeChar('-'), x = -x;
char s[24];
int n = 0;
while (x || !n)
s[n++] = '0' + x % 10, x /= 10;
while (n--)
writeChar(s[n]);
}
void writeWord(const char *s) {
while (*s)
writeChar(*s++);
}
void flush() {
if (write_pos) {
fwrite(write_buf, 1, write_pos, stdout), write_pos = 0;
}
}
} // namespace
class TOutputStream {
int precision_;
public:
void precision(int new_prec) { precision_ = new_prec; }
TOutputStream &operator<<(bool arg) {
writeChar('0' + arg);
return *this;
}
TOutputStream &operator<<(char arg) {
writeChar(arg);
return *this;
}
TOutputStream &operator<<(const char *arg) {
writeWord(arg);
return *this;
}
TOutputStream &operator<<(float arg) {
writeDouble(arg, precision_);
return *this;
}
TOutputStream &operator<<(double arg) {
writeDouble(arg, precision_);
return *this;
}
TOutputStream &operator<<(long double arg) {
writeDouble(arg, precision_);
return *this;
}
TOutputStream &operator<<(int arg) {
writeInt(arg);
return *this;
}
TOutputStream &operator<<(long long arg) {
writeInt(arg);
return *this;
}
TOutputStream &operator<<(const std::string &arg) {
writeWord(arg.c_str());
return *this;
}
void flush() { olymplib::flush(); }
typedef TOutputStream &(*MyStreamManipulator)(TOutputStream &);
TOutputStream &operator<<(const MyStreamManipulator &manip) {
return manip(*this);
}
~TOutputStream() { flush(); }
};
class TInputStream {
public:
TInputStream &operator>>(bool &arg) {
arg = readChar() - '0';
return *this;
}
TInputStream &operator>>(char &arg) {
arg = readChar();
return *this;
}
// please know what you're doing.
TInputStream &operator>>(char *&arg) {
readWord(arg);
return *this;
}
TInputStream &operator>>(float &arg) {
arg = readDouble<float>();
return *this;
}
TInputStream &operator>>(double &arg) {
arg = readDouble<double>();
return *this;
}
TInputStream &operator>>(long double &arg) {
arg = readDouble<long double>();
return *this;
}
TInputStream &operator>>(int &arg) {
arg = readInt<int>();
return *this;
}
TInputStream &operator>>(long long arg) {
arg = readInt<long long>();
return *this;
}
TInputStream &operator>>(std::string &arg) {
arg.clear();
arg.reserve(16);
arg.push_back(readChar());
while (char c = peekChar()) {
if (c == -1 || c <= 32)
break;
arg.push_back(getChar());
}
arg.shrink_to_fit();
return *this;
}
};
static TInputStream cin;
static TOutputStream cout;
static TOutputStream &endl(TOutputStream &stream) {
stream << '\n';
stream.flush();
return stream;
}
} // namespace olymplib
using namespace olymplib;
using namespace std;
const int N = 1e5;
const int INF = 1e9;
int h[N];
int dp[N];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> h[i];
}
for (int i = 1; i < n; ++i) {
dp[i] = INF;
for (int j = i - 1; j >= 0 && j >= i - 2; --j) {
dp[i] = min(dp[i], dp[j] + abs(h[i] - h[j]));
}
}
cout << dp[n - 1] << endl;
return 0;
} | [
"expression.operator.compare.change",
"control_flow.loop.for.condition.change",
"expression.operation.binary.change"
] | 956,811 | 956,812 | u217145434 | cpp |
p03160 | #include <algorithm>
#include <string>
namespace olymplib {
namespace {
template <class T> void writeInt(T x);
template <class T> void writeUInt(T x);
void writeChar(int x);
void writeWord(const char *s);
void writeDouble(double x, int len = 0);
static const int buf_size = 4096;
static int write_pos = 0;
static char write_buf[buf_size];
static char buf[buf_size];
static int buf_len = 0, buf_pos = 0;
//-- read
template <class T = int> T readInt();
double readDouble();
int readUInt();
int readChar();
void readWord(char *s);
bool readLine(char *s); // do not save '\n'
bool isEof();
int peekChar();
bool seekEof();
void flush();
//--------------------------
bool isEof() {
if (buf_pos == buf_len) {
buf_pos = 0, buf_len = fread(buf, 1, buf_size, stdin);
if (buf_pos == buf_len)
return 1;
}
return 0;
}
int getChar() { return isEof() ? -1 : buf[buf_pos++]; }
int peekChar() { return isEof() ? -1 : buf[buf_pos]; }
bool seekEof() {
int c;
while ((c = peekChar()) != -1 && c <= 32)
buf_pos++;
return c == -1;
}
int readChar() {
int c = getChar();
while (c != -1 && c <= 32)
c = getChar();
return c;
}
int readUInt() {
int c = readChar(), x = 0;
while ('0' <= c && c <= '9')
x = x * 10 + c - '0', c = getChar();
return x;
}
template <class T> T readInt() {
int s = 1, c = readChar();
T x = 0;
if (c == '-')
s = -1, c = getChar();
while ('0' <= c && c <= '9')
x = x * 10 + c - '0', c = getChar();
return s == 1 ? x : -x;
}
template <class Double = double> double readDouble() {
int s = 1, c = readChar();
Double x = 0;
if (c == '-')
s = -1, c = getChar();
while ('0' <= c && c <= '9')
x = x * 10 + c - '0', c = getChar();
if (c == '.') {
c = getChar();
double coef = 1;
while ('0' <= c && c <= '9')
x += (c - '0') * (coef *= 1e-1), c = getChar();
}
return s == 1 ? x : -x;
}
void readWord(char *s) {
int c = readChar();
while (c > 32)
*s++ = c, c = getChar();
*s = 0;
}
bool readLine(char *s) {
int c = getChar();
while (c != '\n' && c != -1)
*s++ = c, c = getChar();
*s = 0;
return c != -1;
}
// only supports fixed precision for now (hence huge values are not allowed)
void writeDouble(double x, int output_len) {
if (x < 0)
writeChar('-'), x = -x;
int t = (int)x;
writeUInt(t), x -= t;
writeChar('.');
for (int i = output_len - 1; i > 0; i--) {
x *= 10;
t = 9 < (int)x ? 9 : x;
writeChar('0' + t), x -= t;
}
x *= 10;
t = 9 < (int)(x + 0.5) ? 9 : (int)(x + 0.5);
writeChar('0' + t);
}
void writeChar(int x) {
if (write_pos == buf_size)
fwrite(write_buf, 1, buf_size, stdout), write_pos = 0;
write_buf[write_pos++] = x;
}
template <class T> void writeUInt(T x) {
char s[24];
int n = 0;
while (x || !n)
s[n++] = '0' + x % 10, x /= 10;
while (n--)
writeChar(s[n]);
}
template <> void writeInt<int>(int x) {
if (x < 0)
writeChar('-'), x = -x;
char s[10];
int n = 0;
while (x || !n)
s[n++] = '0' + x % 10, x /= 10;
while (n--)
writeChar(s[n]);
}
template <class T> void writeInt(T x) {
if (x < 0)
writeChar('-'), x = -x;
char s[24];
int n = 0;
while (x || !n)
s[n++] = '0' + x % 10, x /= 10;
while (n--)
writeChar(s[n]);
}
void writeWord(const char *s) {
while (*s)
writeChar(*s++);
}
void flush() {
if (write_pos) {
fwrite(write_buf, 1, write_pos, stdout), write_pos = 0;
}
}
} // namespace
class TOutputStream {
int precision_;
public:
void precision(int new_prec) { precision_ = new_prec; }
TOutputStream &operator<<(bool arg) {
writeChar('0' + arg);
return *this;
}
TOutputStream &operator<<(char arg) {
writeChar(arg);
return *this;
}
TOutputStream &operator<<(const char *arg) {
writeWord(arg);
return *this;
}
TOutputStream &operator<<(float arg) {
writeDouble(arg, precision_);
return *this;
}
TOutputStream &operator<<(double arg) {
writeDouble(arg, precision_);
return *this;
}
TOutputStream &operator<<(long double arg) {
writeDouble(arg, precision_);
return *this;
}
TOutputStream &operator<<(int arg) {
writeInt(arg);
return *this;
}
TOutputStream &operator<<(long long arg) {
writeInt(arg);
return *this;
}
TOutputStream &operator<<(const std::string &arg) {
writeWord(arg.c_str());
return *this;
}
void flush() { olymplib::flush(); }
typedef TOutputStream &(*MyStreamManipulator)(TOutputStream &);
TOutputStream &operator<<(const MyStreamManipulator &manip) {
return manip(*this);
}
~TOutputStream() { flush(); }
};
class TInputStream {
public:
TInputStream &operator>>(bool &arg) {
arg = readChar() - '0';
return *this;
}
TInputStream &operator>>(char &arg) {
arg = readChar();
return *this;
}
// please know what you're doing.
TInputStream &operator>>(char *&arg) {
readWord(arg);
return *this;
}
TInputStream &operator>>(float &arg) {
arg = readDouble<float>();
return *this;
}
TInputStream &operator>>(double &arg) {
arg = readDouble<double>();
return *this;
}
TInputStream &operator>>(long double &arg) {
arg = readDouble<long double>();
return *this;
}
TInputStream &operator>>(int &arg) {
arg = readInt<int>();
return *this;
}
TInputStream &operator>>(long long arg) {
arg = readInt<long long>();
return *this;
}
TInputStream &operator>>(std::string &arg) {
arg.clear();
arg.reserve(16);
arg.push_back(readChar());
while (char c = peekChar()) {
if (c == -1 || c <= 32)
break;
arg.push_back(getChar());
}
arg.shrink_to_fit();
return *this;
}
};
static TInputStream cin;
static TOutputStream cout;
static TOutputStream &endl(TOutputStream &stream) {
stream << '\n';
stream.flush();
return stream;
}
} // namespace olymplib
using namespace olymplib;
using namespace std;
const int N = 1e5;
const int INF = 1e9;
int h[N];
int dp[N];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> h[i];
}
for (int i = 1; i < n; ++i) {
dp[i] = INF;
for (int j = i - 1; j >= i - 2; --j) {
dp[i] = min(dp[i], dp[j] + abs(h[i] - h[j]));
}
}
cout << dp[n - 1] << endl;
return 0;
} | #include <algorithm>
#include <string>
namespace olymplib {
namespace {
template <class T> void writeInt(T x);
template <class T> void writeUInt(T x);
void writeChar(int x);
void writeWord(const char *s);
void writeDouble(double x, int len = 0);
static const int buf_size = 4096;
static int write_pos = 0;
static char write_buf[buf_size];
static char buf[buf_size];
static int buf_len = 0, buf_pos = 0;
//-- read
template <class T = int> T readInt();
double readDouble();
int readUInt();
int readChar();
void readWord(char *s);
bool readLine(char *s); // do not save '\n'
bool isEof();
int peekChar();
bool seekEof();
void flush();
//--------------------------
bool isEof() {
if (buf_pos == buf_len) {
buf_pos = 0, buf_len = fread(buf, 1, buf_size, stdin);
if (buf_pos == buf_len)
return 1;
}
return 0;
}
int getChar() { return isEof() ? -1 : buf[buf_pos++]; }
int peekChar() { return isEof() ? -1 : buf[buf_pos]; }
bool seekEof() {
int c;
while ((c = peekChar()) != -1 && c <= 32)
buf_pos++;
return c == -1;
}
int readChar() {
int c = getChar();
while (c != -1 && c <= 32)
c = getChar();
return c;
}
int readUInt() {
int c = readChar(), x = 0;
while ('0' <= c && c <= '9')
x = x * 10 + c - '0', c = getChar();
return x;
}
template <class T> T readInt() {
int s = 1, c = readChar();
T x = 0;
if (c == '-')
s = -1, c = getChar();
while ('0' <= c && c <= '9')
x = x * 10 + c - '0', c = getChar();
return s == 1 ? x : -x;
}
template <class Double = double> double readDouble() {
int s = 1, c = readChar();
Double x = 0;
if (c == '-')
s = -1, c = getChar();
while ('0' <= c && c <= '9')
x = x * 10 + c - '0', c = getChar();
if (c == '.') {
c = getChar();
double coef = 1;
while ('0' <= c && c <= '9')
x += (c - '0') * (coef *= 1e-1), c = getChar();
}
return s == 1 ? x : -x;
}
void readWord(char *s) {
int c = readChar();
while (c > 32)
*s++ = c, c = getChar();
*s = 0;
}
bool readLine(char *s) {
int c = getChar();
while (c != '\n' && c != -1)
*s++ = c, c = getChar();
*s = 0;
return c != -1;
}
// only supports fixed precision for now (hence huge values are not allowed)
void writeDouble(double x, int output_len) {
if (x < 0)
writeChar('-'), x = -x;
int t = (int)x;
writeUInt(t), x -= t;
writeChar('.');
for (int i = output_len - 1; i > 0; i--) {
x *= 10;
t = 9 < (int)x ? 9 : x;
writeChar('0' + t), x -= t;
}
x *= 10;
t = 9 < (int)(x + 0.5) ? 9 : (int)(x + 0.5);
writeChar('0' + t);
}
void writeChar(int x) {
if (write_pos == buf_size)
fwrite(write_buf, 1, buf_size, stdout), write_pos = 0;
write_buf[write_pos++] = x;
}
template <class T> void writeUInt(T x) {
char s[24];
int n = 0;
while (x || !n)
s[n++] = '0' + x % 10, x /= 10;
while (n--)
writeChar(s[n]);
}
template <> void writeInt<int>(int x) {
if (x < 0)
writeChar('-'), x = -x;
char s[10];
int n = 0;
while (x || !n)
s[n++] = '0' + x % 10, x /= 10;
while (n--)
writeChar(s[n]);
}
template <class T> void writeInt(T x) {
if (x < 0)
writeChar('-'), x = -x;
char s[24];
int n = 0;
while (x || !n)
s[n++] = '0' + x % 10, x /= 10;
while (n--)
writeChar(s[n]);
}
void writeWord(const char *s) {
while (*s)
writeChar(*s++);
}
void flush() {
if (write_pos) {
fwrite(write_buf, 1, write_pos, stdout), write_pos = 0;
}
}
} // namespace
class TOutputStream {
int precision_;
public:
void precision(int new_prec) { precision_ = new_prec; }
TOutputStream &operator<<(bool arg) {
writeChar('0' + arg);
return *this;
}
TOutputStream &operator<<(char arg) {
writeChar(arg);
return *this;
}
TOutputStream &operator<<(const char *arg) {
writeWord(arg);
return *this;
}
TOutputStream &operator<<(float arg) {
writeDouble(arg, precision_);
return *this;
}
TOutputStream &operator<<(double arg) {
writeDouble(arg, precision_);
return *this;
}
TOutputStream &operator<<(long double arg) {
writeDouble(arg, precision_);
return *this;
}
TOutputStream &operator<<(int arg) {
writeInt(arg);
return *this;
}
TOutputStream &operator<<(long long arg) {
writeInt(arg);
return *this;
}
TOutputStream &operator<<(const std::string &arg) {
writeWord(arg.c_str());
return *this;
}
void flush() { olymplib::flush(); }
typedef TOutputStream &(*MyStreamManipulator)(TOutputStream &);
TOutputStream &operator<<(const MyStreamManipulator &manip) {
return manip(*this);
}
~TOutputStream() { flush(); }
};
class TInputStream {
public:
TInputStream &operator>>(bool &arg) {
arg = readChar() - '0';
return *this;
}
TInputStream &operator>>(char &arg) {
arg = readChar();
return *this;
}
// please know what you're doing.
TInputStream &operator>>(char *&arg) {
readWord(arg);
return *this;
}
TInputStream &operator>>(float &arg) {
arg = readDouble<float>();
return *this;
}
TInputStream &operator>>(double &arg) {
arg = readDouble<double>();
return *this;
}
TInputStream &operator>>(long double &arg) {
arg = readDouble<long double>();
return *this;
}
TInputStream &operator>>(int &arg) {
arg = readInt<int>();
return *this;
}
TInputStream &operator>>(long long arg) {
arg = readInt<long long>();
return *this;
}
TInputStream &operator>>(std::string &arg) {
arg.clear();
arg.reserve(16);
arg.push_back(readChar());
while (char c = peekChar()) {
if (c == -1 || c <= 32)
break;
arg.push_back(getChar());
}
arg.shrink_to_fit();
return *this;
}
};
static TInputStream cin;
static TOutputStream cout;
static TOutputStream &endl(TOutputStream &stream) {
stream << '\n';
stream.flush();
return stream;
}
} // namespace olymplib
using namespace olymplib;
using namespace std;
const int N = 1e5;
const int INF = 1e9;
int h[N];
int dp[N];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> h[i];
}
for (int i = 1; i < n; ++i) {
dp[i] = INF;
for (int j = i - 1; j >= 0 && j >= i - 2; --j) {
dp[i] = min(dp[i], dp[j] + abs(h[i] - h[j]));
}
}
cout << dp[n - 1] << endl;
return 0;
} | [
"control_flow.loop.for.condition.change"
] | 956,813 | 956,812 | u217145434 | cpp |
p03160 | #include <algorithm>
#include <iostream>
#include <math.h>
#include <numeric>
#include <string>
#include <vector>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<ULL> VULL;
class MYCP {
public:
//数値を区切って文字列にする
static string MakeString_LongLong(vector<long long> const &numbers,
string const &str) {
if (numbers.size() == 0)
return "";
string result = "" + to_string(numbers[0]);
for (long long i = 1; i < numbers.size(); i++) {
result += str;
result += to_string(numbers[i]);
}
return result;
}
//空白で区切る為のオーバーロード
static string MakeString_LongLong(vector<long long> const &numbers) {
if (numbers.size() == 0)
return "";
string result = "" + to_string(numbers[0]);
for (long long i = 1; i < numbers.size(); i++) {
result += " ";
result += to_string(numbers[i]);
}
return result;
}
//文字列の配列を改行を挟んでまとめる
static string MakeString_VectorString(vector<string> const &str) {
string result = "";
for (long long i = 0; i < str.size(); i++) {
result += str[i] + "\n";
}
return result;
}
//文字列を必要な個数だけ読み取る
static vector<string> MyReadLineSplit(LL n) {
vector<string> str(n);
for (long long i = 0; i < n; i++) {
std::cin >> str[i];
}
return str;
}
//数値を必要な個数だけ読み取る
static vector<long long> ReadInts(long long number) {
vector<long long> a(number);
for (int i = 0; i < number; i++) {
std::cin >> a[i];
}
return a;
}
//渡された自然数が素数ならtureを返す
static bool PrimeCheck_Int(long long number) {
if (number < 2)
return false;
for (ULL i = 2; i * i <= number; i++) {
if (number % i == 0)
return false;
}
return true;
}
//渡された数値以下の素数表を作る
static vector<long long> MakePrimeList(long long n) {
vector<long long> list;
LL i, j, p;
bool flag;
for (i = 2; i <= n; i++) {
flag = true;
for (j = 0; j < list.size(); j++) {
if (!(list[j] * list[j] <= i))
break;
if (i % list[j] == 0) {
flag = false;
break;
}
}
if (flag)
list.push_back(i);
}
return list;
}
//文字列の分割
static vector<string> split(string const &str, char sep) {
vector<std::string> v; // 分割結果を格納するベクター
auto first = str.begin(); // テキストの最初を指すイテレータ
while (first != str.end()) { // テキストが残っている間ループ
auto last = first; // 分割文字列末尾へのイテレータ
while (last != str.end() &&
*last != sep) // 末尾 or セパレータ文字まで進める
last++;
v.push_back(string(first, last)); // 分割文字を出力
if (last != str.end())
last++;
first = last; // 次の処理のためにイテレータを設定
}
return v;
}
//合計を求める
static LL Sum(vector<LL> a) {
LL i, sum = 0;
for (i = 0; i < a.size(); i++) {
sum += a[i];
}
return sum;
}
//小文字ならtrueを返す
static bool Komoji(char a) {
if (a >= 'a' && a <= 'z')
return true;
return false;
}
//大文字ならtrueを返す
static bool Oomoji(char a) {
if (a >= 'A' && a <= 'Z')
return true;
return false;
}
static LL GreatestCommonFactor(LL a, LL b) {
LL temp;
if (a < b) {
temp = b;
b = a;
a = temp;
}
while (true) {
temp = a % b;
a = b;
b = temp;
if (b == 0)
break;
}
return a;
}
static LL LeastCommonMultiple(LL a, LL b) {
return (a / GreatestCommonFactor(a, b)) * b;
}
};
//累積和を求めるクラス
class Syakutori {
private:
vector<LL> list;
public:
void MakeArray(vector<LL> data) {
LL i;
list = data;
list.push_back(0);
list[0] = 0;
for (i = 1; i < list.size(); i++) {
list[i] = list[i - 1] + data[i - 1];
}
}
LL Sum(LL start, LL end) {
if (end < start) {
cout << "startがendより大きいです";
return 0;
}
if (start < 0 || end >= list.size()) {
cout << "範囲が異常";
return 0;
}
return list[end] - list[start];
}
};
int main(void) {
int n;
cin >> n;
vector<int> h(n);
for (int i = 0; i < n; i++) {
cin >> h[i];
}
vector<int> dp(n + 100);
dp[1] = h[0] - h[0];
dp[2] = abs(h[1] - h[0]) + dp[1];
for (int i = 3; i < n; i++) {
dp[i] = min(abs(h[i - 1] - h[i - 3]) + dp[i - 2],
abs(h[i - 1] - h[i - 2]) + dp[i - 1]);
}
cout << dp[n] << endl;
return 0;
}
| #include <algorithm>
#include <iostream>
#include <math.h>
#include <numeric>
#include <string>
#include <vector>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<ULL> VULL;
class MYCP {
public:
//数値を区切って文字列にする
static string MakeString_LongLong(vector<long long> const &numbers,
string const &str) {
if (numbers.size() == 0)
return "";
string result = "" + to_string(numbers[0]);
for (long long i = 1; i < numbers.size(); i++) {
result += str;
result += to_string(numbers[i]);
}
return result;
}
//空白で区切る為のオーバーロード
static string MakeString_LongLong(vector<long long> const &numbers) {
if (numbers.size() == 0)
return "";
string result = "" + to_string(numbers[0]);
for (long long i = 1; i < numbers.size(); i++) {
result += " ";
result += to_string(numbers[i]);
}
return result;
}
//文字列の配列を改行を挟んでまとめる
static string MakeString_VectorString(vector<string> const &str) {
string result = "";
for (long long i = 0; i < str.size(); i++) {
result += str[i] + "\n";
}
return result;
}
//文字列を必要な個数だけ読み取る
static vector<string> MyReadLineSplit(LL n) {
vector<string> str(n);
for (long long i = 0; i < n; i++) {
std::cin >> str[i];
}
return str;
}
//数値を必要な個数だけ読み取る
static vector<long long> ReadInts(long long number) {
vector<long long> a(number);
for (int i = 0; i < number; i++) {
std::cin >> a[i];
}
return a;
}
//渡された自然数が素数ならtureを返す
static bool PrimeCheck_Int(long long number) {
if (number < 2)
return false;
for (ULL i = 2; i * i <= number; i++) {
if (number % i == 0)
return false;
}
return true;
}
//渡された数値以下の素数表を作る
static vector<long long> MakePrimeList(long long n) {
vector<long long> list;
LL i, j, p;
bool flag;
for (i = 2; i <= n; i++) {
flag = true;
for (j = 0; j < list.size(); j++) {
if (!(list[j] * list[j] <= i))
break;
if (i % list[j] == 0) {
flag = false;
break;
}
}
if (flag)
list.push_back(i);
}
return list;
}
//文字列の分割
static vector<string> split(string const &str, char sep) {
vector<std::string> v; // 分割結果を格納するベクター
auto first = str.begin(); // テキストの最初を指すイテレータ
while (first != str.end()) { // テキストが残っている間ループ
auto last = first; // 分割文字列末尾へのイテレータ
while (last != str.end() &&
*last != sep) // 末尾 or セパレータ文字まで進める
last++;
v.push_back(string(first, last)); // 分割文字を出力
if (last != str.end())
last++;
first = last; // 次の処理のためにイテレータを設定
}
return v;
}
//合計を求める
static LL Sum(vector<LL> a) {
LL i, sum = 0;
for (i = 0; i < a.size(); i++) {
sum += a[i];
}
return sum;
}
//小文字ならtrueを返す
static bool Komoji(char a) {
if (a >= 'a' && a <= 'z')
return true;
return false;
}
//大文字ならtrueを返す
static bool Oomoji(char a) {
if (a >= 'A' && a <= 'Z')
return true;
return false;
}
static LL GreatestCommonFactor(LL a, LL b) {
LL temp;
if (a < b) {
temp = b;
b = a;
a = temp;
}
while (true) {
temp = a % b;
a = b;
b = temp;
if (b == 0)
break;
}
return a;
}
static LL LeastCommonMultiple(LL a, LL b) {
return (a / GreatestCommonFactor(a, b)) * b;
}
};
//累積和を求めるクラス
class Syakutori {
private:
vector<LL> list;
public:
void MakeArray(vector<LL> data) {
LL i;
list = data;
list.push_back(0);
list[0] = 0;
for (i = 1; i < list.size(); i++) {
list[i] = list[i - 1] + data[i - 1];
}
}
LL Sum(LL start, LL end) {
if (end < start) {
cout << "startがendより大きいです";
return 0;
}
if (start < 0 || end >= list.size()) {
cout << "範囲が異常";
return 0;
}
return list[end] - list[start];
}
};
int main(void) {
int n;
cin >> n;
vector<int> h(n);
for (int i = 0; i < n; i++) {
cin >> h[i];
}
vector<int> dp(n + 100);
dp[1] = h[0] - h[0];
dp[2] = abs(h[1] - h[0]) + dp[1];
for (int i = 3; i < n + 1; i++) {
dp[i] = min(abs(h[i - 1] - h[i - 3]) + dp[i - 2],
abs(h[i - 1] - h[i - 2]) + dp[i - 1]);
}
cout << dp[n] << endl;
return 0;
}
| [
"control_flow.loop.for.condition.change",
"misc.off_by_one"
] | 956,816 | 956,817 | u196798307 | cpp |
p03160 | #include <algorithm>
#include <iostream>
#include <math.h>
#include <numeric>
#include <string>
#include <vector>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<ULL> VULL;
class MYCP {
public:
//数値を区切って文字列にする
static string MakeString_LongLong(vector<long long> const &numbers,
string const &str) {
if (numbers.size() == 0)
return "";
string result = "" + to_string(numbers[0]);
for (long long i = 1; i < numbers.size(); i++) {
result += str;
result += to_string(numbers[i]);
}
return result;
}
//空白で区切る為のオーバーロード
static string MakeString_LongLong(vector<long long> const &numbers) {
if (numbers.size() == 0)
return "";
string result = "" + to_string(numbers[0]);
for (long long i = 1; i < numbers.size(); i++) {
result += " ";
result += to_string(numbers[i]);
}
return result;
}
//文字列の配列を改行を挟んでまとめる
static string MakeString_VectorString(vector<string> const &str) {
string result = "";
for (long long i = 0; i < str.size(); i++) {
result += str[i] + "\n";
}
return result;
}
//文字列を必要な個数だけ読み取る
static vector<string> MyReadLineSplit(LL n) {
vector<string> str(n);
for (long long i = 0; i < n; i++) {
std::cin >> str[i];
}
return str;
}
//数値を必要な個数だけ読み取る
static vector<long long> ReadInts(long long number) {
vector<long long> a(number);
for (int i = 0; i < number; i++) {
std::cin >> a[i];
}
return a;
}
//渡された自然数が素数ならtureを返す
static bool PrimeCheck_Int(long long number) {
if (number < 2)
return false;
for (ULL i = 2; i * i <= number; i++) {
if (number % i == 0)
return false;
}
return true;
}
//渡された数値以下の素数表を作る
static vector<long long> MakePrimeList(long long n) {
vector<long long> list;
LL i, j, p;
bool flag;
for (i = 2; i <= n; i++) {
flag = true;
for (j = 0; j < list.size(); j++) {
if (!(list[j] * list[j] <= i))
break;
if (i % list[j] == 0) {
flag = false;
break;
}
}
if (flag)
list.push_back(i);
}
return list;
}
//文字列の分割
static vector<string> split(string const &str, char sep) {
vector<std::string> v; // 分割結果を格納するベクター
auto first = str.begin(); // テキストの最初を指すイテレータ
while (first != str.end()) { // テキストが残っている間ループ
auto last = first; // 分割文字列末尾へのイテレータ
while (last != str.end() &&
*last != sep) // 末尾 or セパレータ文字まで進める
last++;
v.push_back(string(first, last)); // 分割文字を出力
if (last != str.end())
last++;
first = last; // 次の処理のためにイテレータを設定
}
return v;
}
//合計を求める
static LL Sum(vector<LL> a) {
LL i, sum = 0;
for (i = 0; i < a.size(); i++) {
sum += a[i];
}
return sum;
}
//小文字ならtrueを返す
static bool Komoji(char a) {
if (a >= 'a' && a <= 'z')
return true;
return false;
}
//大文字ならtrueを返す
static bool Oomoji(char a) {
if (a >= 'A' && a <= 'Z')
return true;
return false;
}
static LL GreatestCommonFactor(LL a, LL b) {
LL temp;
if (a < b) {
temp = b;
b = a;
a = temp;
}
while (true) {
temp = a % b;
a = b;
b = temp;
if (b == 0)
break;
}
return a;
}
static LL LeastCommonMultiple(LL a, LL b) {
return (a / GreatestCommonFactor(a, b)) * b;
}
};
//累積和を求めるクラス
class Syakutori {
private:
vector<LL> list;
public:
void MakeArray(vector<LL> data) {
LL i;
list = data;
list.push_back(0);
list[0] = 0;
for (i = 1; i < list.size(); i++) {
list[i] = list[i - 1] + data[i - 1];
}
}
LL Sum(LL start, LL end) {
if (end < start) {
cout << "startがendより大きいです";
return 0;
}
if (start < 0 || end >= list.size()) {
cout << "範囲が異常";
return 0;
}
return list[end] - list[start];
}
};
int main(void) {
int n;
cin >> n;
vector<int> h(n);
for (int i = 0; i < n; i++) {
cin >> h[i];
}
vector<int> dp(n + 100);
dp[1] = h[0] - h[0];
dp[2] = abs(h[1] - h[0]) + dp[1];
for (int i = 3; i < n; i++) {
dp[i] = min(abs(h[i - 1] - h[i - 3]) + dp[i - 2],
abs(h[i - 1] - h[i - 2] + dp[i - 1]));
}
cout << dp[n] << endl;
return 0;
}
| #include <algorithm>
#include <iostream>
#include <math.h>
#include <numeric>
#include <string>
#include <vector>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<ULL> VULL;
class MYCP {
public:
//数値を区切って文字列にする
static string MakeString_LongLong(vector<long long> const &numbers,
string const &str) {
if (numbers.size() == 0)
return "";
string result = "" + to_string(numbers[0]);
for (long long i = 1; i < numbers.size(); i++) {
result += str;
result += to_string(numbers[i]);
}
return result;
}
//空白で区切る為のオーバーロード
static string MakeString_LongLong(vector<long long> const &numbers) {
if (numbers.size() == 0)
return "";
string result = "" + to_string(numbers[0]);
for (long long i = 1; i < numbers.size(); i++) {
result += " ";
result += to_string(numbers[i]);
}
return result;
}
//文字列の配列を改行を挟んでまとめる
static string MakeString_VectorString(vector<string> const &str) {
string result = "";
for (long long i = 0; i < str.size(); i++) {
result += str[i] + "\n";
}
return result;
}
//文字列を必要な個数だけ読み取る
static vector<string> MyReadLineSplit(LL n) {
vector<string> str(n);
for (long long i = 0; i < n; i++) {
std::cin >> str[i];
}
return str;
}
//数値を必要な個数だけ読み取る
static vector<long long> ReadInts(long long number) {
vector<long long> a(number);
for (int i = 0; i < number; i++) {
std::cin >> a[i];
}
return a;
}
//渡された自然数が素数ならtureを返す
static bool PrimeCheck_Int(long long number) {
if (number < 2)
return false;
for (ULL i = 2; i * i <= number; i++) {
if (number % i == 0)
return false;
}
return true;
}
//渡された数値以下の素数表を作る
static vector<long long> MakePrimeList(long long n) {
vector<long long> list;
LL i, j, p;
bool flag;
for (i = 2; i <= n; i++) {
flag = true;
for (j = 0; j < list.size(); j++) {
if (!(list[j] * list[j] <= i))
break;
if (i % list[j] == 0) {
flag = false;
break;
}
}
if (flag)
list.push_back(i);
}
return list;
}
//文字列の分割
static vector<string> split(string const &str, char sep) {
vector<std::string> v; // 分割結果を格納するベクター
auto first = str.begin(); // テキストの最初を指すイテレータ
while (first != str.end()) { // テキストが残っている間ループ
auto last = first; // 分割文字列末尾へのイテレータ
while (last != str.end() &&
*last != sep) // 末尾 or セパレータ文字まで進める
last++;
v.push_back(string(first, last)); // 分割文字を出力
if (last != str.end())
last++;
first = last; // 次の処理のためにイテレータを設定
}
return v;
}
//合計を求める
static LL Sum(vector<LL> a) {
LL i, sum = 0;
for (i = 0; i < a.size(); i++) {
sum += a[i];
}
return sum;
}
//小文字ならtrueを返す
static bool Komoji(char a) {
if (a >= 'a' && a <= 'z')
return true;
return false;
}
//大文字ならtrueを返す
static bool Oomoji(char a) {
if (a >= 'A' && a <= 'Z')
return true;
return false;
}
static LL GreatestCommonFactor(LL a, LL b) {
LL temp;
if (a < b) {
temp = b;
b = a;
a = temp;
}
while (true) {
temp = a % b;
a = b;
b = temp;
if (b == 0)
break;
}
return a;
}
static LL LeastCommonMultiple(LL a, LL b) {
return (a / GreatestCommonFactor(a, b)) * b;
}
};
//累積和を求めるクラス
class Syakutori {
private:
vector<LL> list;
public:
void MakeArray(vector<LL> data) {
LL i;
list = data;
list.push_back(0);
list[0] = 0;
for (i = 1; i < list.size(); i++) {
list[i] = list[i - 1] + data[i - 1];
}
}
LL Sum(LL start, LL end) {
if (end < start) {
cout << "startがendより大きいです";
return 0;
}
if (start < 0 || end >= list.size()) {
cout << "範囲が異常";
return 0;
}
return list[end] - list[start];
}
};
int main(void) {
int n;
cin >> n;
vector<int> h(n);
for (int i = 0; i < n; i++) {
cin >> h[i];
}
vector<int> dp(n + 100);
dp[1] = h[0] - h[0];
dp[2] = abs(h[1] - h[0]) + dp[1];
for (int i = 3; i < n + 1; i++) {
dp[i] = min(abs(h[i - 1] - h[i - 3]) + dp[i - 2],
abs(h[i - 1] - h[i - 2]) + dp[i - 1]);
}
cout << dp[n] << endl;
return 0;
}
| [
"control_flow.loop.for.condition.change",
"misc.off_by_one",
"call.arguments.change"
] | 956,818 | 956,817 | u196798307 | cpp |
p03160 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int ans[n];
ans[0] = 0;
ans[1] = a[1] - a[0];
for (int i = 2; i < n; i++) {
ans[i] = min(ans[i - 1] + abs(a[i] - a[i - 1]),
ans[i - 2] + abs(a[i - 2] - a[i]));
}
cout << ans[n - 1];
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int ans[n];
ans[0] = 0;
ans[1] = abs(a[1] - a[0]);
for (int i = 2; i < n; i++) {
ans[i] = min(ans[i - 1] + abs(a[i] - a[i - 1]),
ans[i - 2] + abs(a[i - 2] - a[i]));
}
cout << ans[n - 1];
}
| [
"call.add",
"call.arguments.change"
] | 956,821 | 956,822 | u591744342 | cpp |
p03160 | #include <bits/stdc++.h>
using namespace std;
int f[100005] = {0}, h[100001] = {0}, n;
int main() {
scanf("%d", &n);
f[100004] = 10007;
for (int i = 1; i <= n; i++)
scanf("%d", &h[i]);
f[1] = 0;
for (int i = 2; i <= n; i++) {
f[i] = 10007;
for (int j = max(1, i - 2); j < i; j++) {
f[i] = min(f[i], abs(h[i] - h[j]) + f[j]);
}
}
cout << f[n];
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int f[100010] = {0}, h[100010] = {0}, n;
int main() {
scanf("%d", &n);
f[100004] = 10007;
for (int i = 1; i <= n; i++)
scanf("%d", &h[i]);
f[1] = 0;
for (int i = 2; i <= n; i++) {
f[i] = 2000000000;
for (int j = max(1, i - 2); j < i; j++) {
f[i] = min(f[i], abs(h[i] - h[j]) + f[j]);
}
}
cout << f[n];
return 0;
} | [
"literal.number.change",
"variable_declaration.array_dimensions.change",
"assignment.value.change"
] | 956,823 | 956,824 | u001863524 | cpp |
p03160 | #include <bits/stdc++.h>
using namespace std;
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define start_routine() int begtime = clock();
#define end_routine() \
int endtime = clock(); \
cerr << "\n\n" \
<< "Time elapsed: " << (endtime - begtime) * 1000 / CLOCKS_PER_SEC \
<< " ms\n\n"; \
return 0
#define ll long long int
#define ull unsigned long long int
#define db long double
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pii pair<int, int>
#define pdd pair<db, db>
#define pll pair<ll, ll>
#define vpl vector<pll>
#define vll vector<ll>
#define mod 1000000007
#define inf 100000000000000007
#define eps 0.000001
#define stp fixed << setprecision(20)
#define endl '\n'
ll dp[100005];
int main() {
start_routine();
fastio;
ll n;
cin >> n;
ll k = 1;
// cin>>k;
ll h[n + 1] = {0};
for (ll i = 1; i <= n; i++) {
dp[i] = inf;
cin >> h[i];
}
dp[1] = 0;
for (ll i = 2; i <= n; i++) {
ll mn = inf;
for (ll j = i - 1; j >= max(i - k, 1ll); j--)
mn = min(mn, dp[j] + abs(h[j] - h[i]));
dp[i] = mn;
}
cout << dp[n];
end_routine();
} | #include <bits/stdc++.h>
using namespace std;
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define start_routine() int begtime = clock();
#define end_routine() \
int endtime = clock(); \
cerr << "\n\n" \
<< "Time elapsed: " << (endtime - begtime) * 1000 / CLOCKS_PER_SEC \
<< " ms\n\n"; \
return 0
#define ll long long int
#define ull unsigned long long int
#define db long double
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pii pair<int, int>
#define pdd pair<db, db>
#define pll pair<ll, ll>
#define vpl vector<pll>
#define vll vector<ll>
#define mod 1000000007
#define inf 100000000000000007
#define eps 0.000001
#define stp fixed << setprecision(20)
#define endl '\n'
ll dp[100005];
int main() {
start_routine();
fastio;
ll n;
cin >> n;
ll k = 2;
// cin>>k;
ll h[n + 1] = {0};
for (ll i = 1; i <= n; i++) {
dp[i] = inf;
cin >> h[i];
}
dp[1] = 0;
for (ll i = 2; i <= n; i++) {
ll mn = inf;
for (ll j = i - 1; j >= max(i - k, 1ll); j--)
mn = min(mn, dp[j] + abs(h[j] - h[i]));
dp[i] = mn;
}
cout << dp[n];
end_routine();
} | [
"literal.number.change",
"variable_declaration.value.change"
] | 956,827 | 956,828 | u266509174 | cpp |
p03160 | /*input
3
10 20 10
*/
// author - Madhav Thakker
#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("O2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
#define ll long long
#define ld long double
#define int ll
#define endl '\n'
typedef pair<int, int> pii;
typedef pair<ld, ld> pdd;
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define FileIn(file) freopen(file, "r", stdin)
#define FileOut(file) freopen(file, "w", stdout)
#define all(c) c.begin(), c.end()
#define tr(container, it) \
for (__typeof__(container.begin()) it = container.begin(); \
it != container.end(); it++)
#define present(container, element) \
(container.find(element) != container.end()) // map, set
#define cpresent(container, element) \
(find(aint(container), element) != container.end()) // vector
#define what_is(x) cout << #x << " is " << x << endl;
#define all(c) c.begin(), c.end()
// #define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
const char *comma = strchr(names + 1, ',');
cout.write(names, comma - names) << " : " << arg1 << " | ";
__f(comma + 1, args...);
}
#else
#define trace(...)
#endif
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
const int MOD = 1e9 + 7;
int fast_pow(int a, int b) {
int res = a, ret = 1;
while (b > 0) {
if (b % 2)
ret = (ret * res) % MOD;
res = (res * res) % MOD;
b /= 2;
}
return ret;
}
// --
// --
// --
// std::cout << std::fixed;
// std::cout << std::setprecision(26) << f << '\n';
// str = to_string(n)
// stoi , stoll, stol
// sort(arr, arr+n, greater<int>());
// fill(prefix.begin(), prefix.end(), 0);
//
//
////
const int maxN = 1e5 + 7;
int arr[maxN];
int dp[maxN];
////
signed main() {
fastio;
time_t time_t1, time_t2;
time_t1 = clock();
////////////////////////////////
int t = 1;
// cin >> t ;
while (t--) {
memset(dp, 0, sizeof dp);
int n;
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> arr[i];
}
dp[0] = 0;
dp[1] = abs(arr[1] - arr[0]) + dp[0];
dp[2] = abs(arr[2] - arr[0]) + dp[0];
dp[2] = min(dp[2], abs(arr[1] - arr[0]) + dp[1]);
for (int i = 3; i < n; ++i) {
dp[i] = abs(arr[i] - arr[i - 1]) + dp[i - 1];
dp[i] = min(dp[i], abs(arr[i] - arr[i - 2]) + dp[i - 2]);
}
cout << dp[n - 1] << endl;
}
///////////////////////////////
//
time_t2 = clock();
// cerr << "time taken :" << time_t2 - time_t1 << endl;
return 0;
}
| /*input
3
10 20 10
*/
// author - Madhav Thakker
#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("O2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
#define ll long long
#define ld long double
#define int ll
#define endl '\n'
typedef pair<int, int> pii;
typedef pair<ld, ld> pdd;
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define FileIn(file) freopen(file, "r", stdin)
#define FileOut(file) freopen(file, "w", stdout)
#define all(c) c.begin(), c.end()
#define tr(container, it) \
for (__typeof__(container.begin()) it = container.begin(); \
it != container.end(); it++)
#define present(container, element) \
(container.find(element) != container.end()) // map, set
#define cpresent(container, element) \
(find(aint(container), element) != container.end()) // vector
#define what_is(x) cout << #x << " is " << x << endl;
#define all(c) c.begin(), c.end()
// #define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
const char *comma = strchr(names + 1, ',');
cout.write(names, comma - names) << " : " << arg1 << " | ";
__f(comma + 1, args...);
}
#else
#define trace(...)
#endif
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
const int MOD = 1e9 + 7;
int fast_pow(int a, int b) {
int res = a, ret = 1;
while (b > 0) {
if (b % 2)
ret = (ret * res) % MOD;
res = (res * res) % MOD;
b /= 2;
}
return ret;
}
// --
// --
// --
// std::cout << std::fixed;
// std::cout << std::setprecision(26) << f << '\n';
// str = to_string(n)
// stoi , stoll, stol
// sort(arr, arr+n, greater<int>());
// fill(prefix.begin(), prefix.end(), 0);
//
//
////
const int maxN = 1e5 + 7;
int arr[maxN];
int dp[maxN];
////
signed main() {
fastio;
time_t time_t1, time_t2;
time_t1 = clock();
////////////////////////////////
int t = 1;
// cin >> t ;
while (t--) {
memset(dp, 0, sizeof dp);
int n;
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> arr[i];
}
dp[0] = 0;
dp[1] = abs(arr[1] - arr[0]) + dp[0];
dp[2] = abs(arr[2] - arr[0]) + dp[0];
dp[2] = min(dp[2], abs(arr[2] - arr[1]) + dp[1]);
for (int i = 3; i < n; ++i) {
dp[i] = abs(arr[i] - arr[i - 1]) + dp[i - 1];
dp[i] = min(dp[i], abs(arr[i] - arr[i - 2]) + dp[i - 2]);
}
cout << dp[n - 1] << endl;
}
///////////////////////////////
//
time_t2 = clock();
// cerr << "time taken :" << time_t2 - time_t1 << endl;
return 0;
}
| [
"literal.number.change",
"assignment.value.change",
"variable_access.subscript.index.change",
"call.arguments.change",
"expression.operation.binary.change"
] | 956,831 | 956,832 | u110507182 | cpp |
p03160 | #include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n;
int a[N];
int dp[N];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
scanf("%d", a + i);
dp[i] = 1e9 + 123;
}
dp[1] = 0;
for (int i = 2; i <= n; ++i) {
if (i > 1) {
dp[i] = min(dp[i], dp[i - 1] + abs(a[i] - a[i - 1]));
}
if (i > 2) {
dp[i] = min(dp[i], dp[i - 2] + abs(a[i] - a[i - 1]));
}
}
printf("%lld\n", dp[n]);
}
| #include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n;
int a[N];
int dp[N];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
scanf("%d", a + i);
dp[i] = 1e9 + 123;
}
dp[1] = 0;
for (int i = 2; i <= n; ++i) {
if (i > 1) {
dp[i] = min(dp[i], dp[i - 1] + abs(a[i] - a[i - 1]));
}
if (i > 2) {
dp[i] = min(dp[i], dp[i - 2] + abs(a[i] - a[i - 2]));
}
}
printf("%lld\n", dp[n]);
}
| [
"literal.number.change",
"assignment.value.change",
"call.arguments.change",
"expression.operation.binary.change"
] | 956,837 | 956,838 | u434765267 | cpp |
p03160 | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, a, b) for (int(i) = (a); (i) <= (b); (i)++)
#define per(i, a, b) for (int(i) = (a); (i) >= (b); (i)--)
#define clr(a) memset(a, 0, sizeof(a))
#define ass(a, sum) memset(a, sum, sizeof(a))
#define lowbit(x) (x & -x)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define enter cout << endl
#define siz(x) ((int)x.size())
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef map<string, int> msi;
const int N = 100010;
const int INF = 0x3f3f3f3f;
const int iinf = 1 << 30;
const ll linf = 1e15;
const int MOD = 1000000007;
void print(int x) {
cout << x << endl;
exit(0);
}
void PRINT(string x) {
cout << x << endl;
exit(0);
}
void douout(double x) { printf("%lf\n", x + 0.0000000001); }
int n;
ll a[N], dp[N];
signed main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%lld", &a[i]);
for (int i = 1; i <= n; i++)
dp[i] = linf;
dp[1] = 0ll;
for (int i = 2; i <= n; i++)
dp[i] = min(dp[i], min(dp[i - 1] + abs(a[i] - a[i - 1]),
dp[i - 2] + abs(a[i] - a[i - 2])));
printf("%lld\n", dp[n]);
return 0;
}
/*
写代码时请注意:
1.ll?数组大小,边界?数据范围?
2.精度?
3.特判?
4.至少做一些
思考提醒:
1.最大值最小->二分?
2.可以贪心么?不行dp可以么
3.可以优化么
4.维护区间用什么数据结构?
5.统计方案是用dp?模了么?
*/
| #include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, a, b) for (int(i) = (a); (i) <= (b); (i)++)
#define per(i, a, b) for (int(i) = (a); (i) >= (b); (i)--)
#define clr(a) memset(a, 0, sizeof(a))
#define ass(a, sum) memset(a, sum, sizeof(a))
#define lowbit(x) (x & -x)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define enter cout << endl
#define siz(x) ((int)x.size())
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef map<int, int> mii;
typedef map<string, int> msi;
const int N = 100010;
const int INF = 0x3f3f3f3f;
const int iinf = 1 << 30;
const ll linf = 1e15;
const int MOD = 1000000007;
void print(int x) {
cout << x << endl;
exit(0);
}
void PRINT(string x) {
cout << x << endl;
exit(0);
}
void douout(double x) { printf("%lf\n", x + 0.0000000001); }
int n;
ll a[N], dp[N];
signed main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++)
scanf("%lld", &a[i]);
for (int i = 0; i <= n; i++)
dp[i] = linf;
dp[1] = 0ll;
for (int i = 2; i <= n; i++)
dp[i] = min(dp[i], min(dp[i - 1] + abs(a[i] - a[i - 1]),
dp[i - 2] + abs(a[i] - a[i - 2])));
printf("%lld\n", dp[n]);
return 0;
}
/*
写代码时请注意:
1.ll?数组大小,边界?数据范围?
2.精度?
3.特判?
4.至少做一些
思考提醒:
1.最大值最小->二分?
2.可以贪心么?不行dp可以么
3.可以优化么
4.维护区间用什么数据结构?
5.统计方案是用dp?模了么?
*/
| [
"literal.number.change",
"variable_declaration.value.change",
"control_flow.loop.for.initializer.change",
"expression.off_by_one"
] | 956,841 | 956,842 | u049262741 | cpp |
p03160 | #include <bits/stdc++.h>
#define int long long
#define f(i, n) for (int i = 0; i < n; i++)
#define F first
#define S second
#define mod 1000000007
using namespace std;
int x[100010], y[100010];
signed main() {
int a;
cin >> a;
x[0] = 0;
f(i, a) {
cin >> y[i];
if (i >= 2)
x[i] =
min(x[i - 2] + abs(y[i - 2] - y[i]), x[i - 1] + abs(y[i - 1] - y[i]));
else if (i) {
x[i] = abs(x[i - 1] - x[i]);
}
}
cout << x[a - 1] << endl;
return 0;
}
| #include <bits/stdc++.h>
#define int long long
#define f(i, n) for (int i = 0; i < n; i++)
#define F first
#define S second
#define mod 1000000007
using namespace std;
int x[100010], y[100010];
signed main() {
int a;
cin >> a;
x[0] = 0;
f(i, a) {
cin >> y[i];
if (i >= 2)
x[i] =
min(x[i - 2] + abs(y[i - 2] - y[i]), x[i - 1] + abs(y[i - 1] - y[i]));
else if (i) {
x[i] = abs(y[i - 1] - y[i]);
}
}
cout << x[a - 1] << endl;
return 0;
}
| [
"assignment.value.change",
"identifier.change",
"call.arguments.change",
"expression.operation.binary.change"
] | 956,851 | 956,852 | u259210975 | cpp |
p03160 | #include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
int n; // the number of temperatures to analyse
vector<int> h;
int cost[100000];
cin >> n;
cin.ignore();
for (int i = 0; i < n; i++) {
int t; // a temperature expressed as an integer ranging from -273 to 5526
cin >> t;
cin.ignore();
h.push_back(t);
}
cost[0] = h[0];
cost[1] = abs(h[1] - h[0]);
for (int i = 2; i < n; i++) {
cost[i] = min(cost[i - 1] + abs(h[i] - h[i - 1]),
cost[i - 2] + abs(h[i] - h[i - 2]));
}
cout << cost[n - 1] << endl;
}
| #include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
int n; // the number of temperatures to analyse
vector<int> h;
int cost[100000];
cin >> n;
cin.ignore();
for (int i = 0; i < n; i++) {
int t; // a temperature expressed as an integer ranging from -273 to 5526
cin >> t;
cin.ignore();
h.push_back(t);
}
cost[0] = 0;
cost[1] = abs(h[1] - h[0]);
for (int i = 2; i < n; i++) {
cost[i] = min(cost[i - 1] + abs(h[i] - h[i - 1]),
cost[i - 2] + abs(h[i] - h[i - 2]));
}
cout << cost[n - 1] << endl;
}
| [] | 956,853 | 956,854 | u103094881 | cpp |
p03160 | #include <bits/stdc++.h>
#define ll long long
#define inf 1e18
using namespace std;
ll dp[100007];
ll vis[100007];
ll arr[100007];
int n;
ll rec(int now) {
if (now > n)
return inf;
if (now == n)
return 0;
if (vis[now])
return dp[now];
ll q1 = llabs(arr[now + 1] - arr[now]) + rec(now + 1);
ll q2 = llabs(arr[now + 2] - arr[now]) + rec(now + 2);
vis[now] = 1;
return dp[now] = min(q1, q2);
}
int main() {
cin >> n;
for (int i = 0; i < n; i++)
cin >> arr[i];
cout << rec(1) << endl;
}
| #include <bits/stdc++.h>
#define ll long long
#define inf 1e18
using namespace std;
ll dp[100007];
ll vis[100007];
ll arr[100007];
int n;
ll rec(int now) {
if (now >= n)
return inf;
if (now == n - 1)
return 0;
if (vis[now])
return dp[now];
ll q1 = llabs(arr[now + 1] - arr[now]) + rec(now + 1);
ll q2 = llabs(arr[now + 2] - arr[now]) + rec(now + 2);
vis[now] = 1;
return dp[now] = min(q1, q2);
}
int main() {
cin >> n;
for (int i = 0; i < n; i++)
cin >> arr[i];
cout << rec(0) << endl;
}
| [
"expression.operator.compare.change",
"control_flow.branch.if.condition.change",
"literal.number.change",
"io.output.change"
] | 956,861 | 956,862 | u050698382 | cpp |
p03160 | #include <bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 1e5 + 50;
const int mod = 1e9 + 7;
int dp[maxn];
int h[maxn];
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++)
cin >> h[i];
dp[1] = 0;
dp[2] = h[2] - h[1];
for (int i = 3; i <= n; i++)
dp[i] =
min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
cout << dp[n] << endl;
} | #include <bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 1e5 + 50;
const int mod = 1e9 + 7;
int dp[maxn];
int h[maxn];
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++)
cin >> h[i];
dp[1] = 0;
dp[2] = abs(h[2] - h[1]);
for (int i = 3; i <= n; i++)
dp[i] =
min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
cout << dp[n] << endl;
} | [
"call.add",
"call.arguments.change"
] | 956,863 | 956,864 | u475950249 | cpp |
p03160 | #include <bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 1e5 + 50;
const int mod = 1e9 + 7;
int dp[maxn];
int h[maxn];
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++)
cin >> h[i];
dp[1] = 0;
dp[2] = h[2] - h[1];
for (int i = 3; i <= n; i++)
dp[i] =
min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 1]));
cout << dp[n] << endl;
} | #include <bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 1e5 + 50;
const int mod = 1e9 + 7;
int dp[maxn];
int h[maxn];
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++)
cin >> h[i];
dp[1] = 0;
dp[2] = abs(h[2] - h[1]);
for (int i = 3; i <= n; i++)
dp[i] =
min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
cout << dp[n] << endl;
} | [
"call.add",
"call.arguments.change",
"literal.number.change",
"assignment.value.change",
"variable_access.subscript.index.change",
"expression.operation.binary.change"
] | 956,865 | 956,864 | u475950249 | cpp |
p03160 | #include <algorithm>
#include <cmath>
#include <iostream>
#include <stdio.h>
using namespace std;
long long num[100005];
long long mn[100005];
int main() {
int n, i, a;
scanf(" %d", &n);
for (i = 0; i < n; i++)
mn[i] = 1000000;
mn[0] = 0;
for (i = 0; i < n; i++) {
scanf(" %lld", &num[i]);
if (i >= 1)
mn[i] = min(mn[i], abs(num[i] - num[i - 1]) + mn[i - 1]);
if (i >= 2)
mn[i] = min(mn[i], abs(num[i] - num[i - 2]) + mn[i - 2]);
// cout<<mn[i]<<" ";
}
printf("%lld\n", mn[n - 1]);
} | #include <algorithm>
#include <cmath>
#include <iostream>
#include <stdio.h>
using namespace std;
long long num[100005];
long long mn[100005];
int main() {
long long n, i, a;
scanf(" %lld", &n);
for (i = 0; i < n; i++)
mn[i] = 1000000000;
mn[0] = 0;
for (i = 0; i < n; i++) {
scanf(" %lld", &num[i]);
if (i >= 1)
mn[i] = min(mn[i], abs(num[i] - num[i - 1]) + mn[i - 1]);
if (i >= 2)
mn[i] = min(mn[i], abs(num[i] - num[i - 2]) + mn[i - 2]);
// cout<<mn[i]<<" ";
}
printf("%lld\n", mn[n - 1]);
} | [
"variable_declaration.type.primitive.change",
"variable_declaration.type.widen.change",
"literal.string.change",
"call.arguments.change",
"literal.number.change",
"assignment.value.change"
] | 956,872 | 956,871 | u520996989 | cpp |
p03160 | #include <bits/stdc++.h>
using namespace std;
const int inf = 1e5 + 9;
long long dp[inf], a[inf];
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
dp[1] = 0;
dp[2] = abs(a[1] - a[2]);
for (int i = 2; i <= n; i++) {
long long x = dp[i - 1] + abs(a[i] - a[i - 1]);
long long y = dp[i - 2] + abs(a[i - 2] - a[i]);
dp[i] = min(x, y);
}
cout << dp[n] << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e5 + 9;
long long dp[inf], a[inf];
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
dp[1] = 0;
dp[2] = abs(a[1] - a[2]);
for (int i = 3; i <= n; i++) {
long long x = dp[i - 1] + abs(a[i] - a[i - 1]);
long long y = dp[i - 2] + abs(a[i - 2] - a[i]);
dp[i] = min(x, y);
}
cout << dp[n] << endl;
}
| [
"literal.number.change",
"variable_declaration.value.change",
"control_flow.loop.for.initializer.change",
"expression.off_by_one"
] | 956,874 | 956,875 | u664259916 | cpp |
p03160 | #include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
vector<int> stones;
vector<int> costs;
int hops(int stone) {
if (stone < 1) {
return 0;
}
if (stone == 1) {
return abs(costs[stone] - costs[stone - 1]);
}
if (stones[stone] != -1) {
return stones[stone];
}
int cost1 = hops(stone - 1) + abs(costs[stone] - costs[stone - 1]);
int cost2 = hops(stone - 2) + abs(costs[stone] - costs[stone - 2]);
int preferable = min(cost1, cost2);
stones[stone] = preferable;
return preferable;
}
int main() {
int n;
cin >> n;
stones.assign(1000000000, -1);
for (int i = 0; i < n; i++) {
int cost;
cin >> cost;
costs.push_back(cost);
}
cout << hops(n - 1) << endl;
} | #include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
vector<int> stones;
vector<int> costs;
int hops(int stone) {
if (stone < 1) {
return 0;
}
if (stone == 1) {
return abs(costs[stone] - costs[stone - 1]);
}
if (stones[stone] != -1) {
return stones[stone];
}
int cost1 = hops(stone - 1) + abs(costs[stone] - costs[stone - 1]);
int cost2 = hops(stone - 2) + abs(costs[stone] - costs[stone - 2]);
int preferable = min(cost1, cost2);
stones[stone] = preferable;
return preferable;
}
int main() {
int n;
cin >> n;
stones.assign(n, -1);
for (int i = 0; i < n; i++) {
int cost;
cin >> cost;
costs.push_back(cost);
}
cout << hops(n - 1) << endl;
} | [
"identifier.replace.add",
"literal.replace.remove",
"call.arguments.change"
] | 956,878 | 956,879 | u660253398 | cpp |
p03160 | #include <bits/stdc++.h>
using namespace std;
#define IOS \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define int long long
int mod = 998244353;
int32_t main() {
IOS;
int n;
cin >> n;
int arr[n + 1];
for (int i = 1; i <= n; i++)
cin >> arr[i];
int dp[n + 1];
dp[1] = 0;
dp[2] = arr[2] - arr[1];
for (int i = 3; i <= n; i++) {
dp[i] = min(abs(arr[i] - arr[i - 1]) + dp[i - 1],
abs(arr[i] - arr[i - 2]) + dp[i - 2]);
// cout<<dp[i]<<endl;
}
cout << dp[n] << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define IOS \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define int long long
int mod = 998244353;
int32_t main() {
IOS;
int n;
cin >> n;
int arr[n + 1];
for (int i = 1; i <= n; i++)
cin >> arr[i];
int dp[n + 1];
dp[1] = 0;
dp[2] = abs(arr[2] - arr[1]);
for (int i = 3; i <= n; i++) {
dp[i] = min(abs(arr[i] - arr[i - 1]) + dp[i - 1],
abs(arr[i] - arr[i - 2]) + dp[i - 2]);
// cout<<dp[i]<<endl;
}
cout << dp[n] << endl;
}
| [
"call.add",
"call.arguments.change"
] | 956,881 | 956,882 | u165454560 | cpp |
p03160 | #include <bits/stdc++.h>
using namespace std;
constexpr int MAX_N = 100100;
constexpr int INF = 1e9 + 5;
int n;
int arr[MAX_N];
int dp[MAX_N];
int main() {
scanf(" %d", &n);
for (int i = 1; i <= n; ++i) {
scanf(" %d", &arr[i]);
}
dp[1] = 0;
for (int i = 2; i <= n; ++i) {
dp[i] = -1;
for (int j = 1; j <= 2; ++j) {
if (i - j < 0)
continue;
if (dp[i - j] == -1)
continue;
int cur = dp[i - j] + abs(arr[i] - arr[i - j]);
if (dp[i] == -1 || cur < dp[i]) {
dp[i] = cur;
}
}
}
printf("%d\n", dp[n]);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
constexpr int MAX_N = 100100;
constexpr int INF = 1e9 + 5;
int n;
int arr[MAX_N];
int dp[MAX_N];
int main() {
scanf(" %d", &n);
for (int i = 1; i <= n; ++i) {
scanf(" %d", &arr[i]);
}
dp[1] = 0;
for (int i = 2; i <= n; ++i) {
dp[i] = -1;
for (int j = 1; j <= 2; ++j) {
if (i - j <= 0)
continue;
if (dp[i - j] == -1)
continue;
int cur = dp[i - j] + abs(arr[i] - arr[i - j]);
if (dp[i] == -1 || cur < dp[i]) {
dp[i] = cur;
}
}
}
printf("%d\n", dp[n]);
return 0;
}
| [
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 956,885 | 956,886 | u928667792 | cpp |
p03160 | /*
author: orthodoxparadox
09-Jan-2019
10:50:00
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define dbl long double
#define int ll
#define ll long long
#define pii pair<int, int>
#define fup(i, begin, end) \
for (__typeof(end) i = (begin) - ((begin) > (end)); \
i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define fnu for (ll i = 0; i < n; i++)
#define rev(Y) reverse(all(Y))
#define oiint ostream_iterator<int>(cout, " ")
#define pb emplace_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'
#define all(a) a.begin(), a.end()
#define initialise(a, x) memset(a, x, sizeof(a))
#define onlyunique(v) v.erase(unique(all(v)), v.end()); // only for sorted
// vector
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("O2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#ifdef __APPLE__
#define dbg(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
const char *comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << " : " << arg1 << " ";
__f(comma + 1, args...);
}
#else
#define dbg(...)
#endif
template <typename X> ostream &operator<<(ostream &x, const vector<X> &v) {
for (int i = 0; i < v.size(); ++i)
x << v[i] << " ";
return x;
}
template <typename X> ostream &operator<<(ostream &x, const set<X> &v) {
for (auto it : v)
x << it << " ";
return x;
}
template <typename X, typename Y>
ostream &operator<<(ostream &x, const pair<X, Y> &v) {
x << v.ff << " " << v.ss;
return x;
}
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
struct pair_hash {
inline std::size_t operator()(const std::pair<int, int> &v) const {
return v.first * 31 + v.second;
}
};
const int mod = 1e9 + 7;
int takemod(int a) { return ((a % mod) + mod) % mod; }
int fast_exp(int base, int expo) {
int res = 1;
while (expo > 0) {
if (expo & 1)
res = (res * base) % mod;
base = (base * base) % mod;
expo >>= 1;
}
return res;
}
int modinv(int a) { return takemod(fast_exp(takemod(a), mod - 2)); }
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
#ifdef __APPLE__
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
freopen("error.txt", "w", stderr);
#endif
clock_t t1, t2;
t1 = clock();
int n;
cin >> n;
int h[n + 1];
for (int i = 0; i < n; i++)
cin >> h[i + 1];
h[0] = 0;
int dp[n + 1];
dp[0] = 0;
dp[1] = 0;
for (int i = 2; i <= n; i++) {
dp[i] =
min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
dbg(i, dp[i]);
}
cout << dp[n];
t2 = clock();
cerr << "time taken: " << (t2 - t1) / (dbl)CLOCKS_PER_SEC;
return 0;
} | /*
author: orthodoxparadox
09-Jan-2019
10:50:00
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define dbl long double
#define int ll
#define ll long long
#define pii pair<int, int>
#define fup(i, begin, end) \
for (__typeof(end) i = (begin) - ((begin) > (end)); \
i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define fnu for (ll i = 0; i < n; i++)
#define rev(Y) reverse(all(Y))
#define oiint ostream_iterator<int>(cout, " ")
#define pb emplace_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'
#define all(a) a.begin(), a.end()
#define initialise(a, x) memset(a, x, sizeof(a))
#define onlyunique(v) v.erase(unique(all(v)), v.end()); // only for sorted
// vector
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("O2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#ifdef __APPLE__
#define dbg(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
const char *comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << " : " << arg1 << " ";
__f(comma + 1, args...);
}
#else
#define dbg(...)
#endif
template <typename X> ostream &operator<<(ostream &x, const vector<X> &v) {
for (int i = 0; i < v.size(); ++i)
x << v[i] << " ";
return x;
}
template <typename X> ostream &operator<<(ostream &x, const set<X> &v) {
for (auto it : v)
x << it << " ";
return x;
}
template <typename X, typename Y>
ostream &operator<<(ostream &x, const pair<X, Y> &v) {
x << v.ff << " " << v.ss;
return x;
}
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
struct pair_hash {
inline std::size_t operator()(const std::pair<int, int> &v) const {
return v.first * 31 + v.second;
}
};
const int mod = 1e9 + 7;
int takemod(int a) { return ((a % mod) + mod) % mod; }
int fast_exp(int base, int expo) {
int res = 1;
while (expo > 0) {
if (expo & 1)
res = (res * base) % mod;
base = (base * base) % mod;
expo >>= 1;
}
return res;
}
int modinv(int a) { return takemod(fast_exp(takemod(a), mod - 2)); }
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
#ifdef __APPLE__
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
freopen("error.txt", "w", stderr);
#endif
clock_t t1, t2;
t1 = clock();
int n;
cin >> n;
int h[n + 1];
for (int i = 0; i < n; i++)
cin >> h[i + 1];
h[0] = h[1];
int dp[n + 1];
dp[0] = 0;
dp[1] = 0;
for (int i = 2; i <= n; i++) {
dp[i] =
min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
dbg(i, dp[i]);
}
cout << dp[n];
t2 = clock();
cerr << "time taken: " << (t2 - t1) / (dbl)CLOCKS_PER_SEC;
return 0;
} | [
"assignment.value.change",
"identifier.replace.add",
"literal.replace.remove"
] | 956,889 | 956,890 | u202833686 | cpp |
p03160 | #include <bits/stdc++.h>
using namespace std;
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(0)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define debug(x) cout << "### x is: " << x << "###" << endl
#define all(a) a.begin(), a.end()
#define tc \
int t; \
scanf("%d", &t); \
while (t-- 0)
#define int long long
typedef vector<int> vll;
typedef vector<vll> vvll;
const int N = 2e5 + 5;
const int MOD = 1e9 + 7;
int power(int x, int p) {
int res = 1;
while (p) {
if (p % 2) {
res = (res * x) % MOD;
--p;
} else {
x = (x * x) % MOD;
p /= 2;
}
}
return res;
}
int invmod(int x) { return power(x, MOD - 2); }
int dp[N];
int a[N];
int n, k;
void go(int s, int pre, int p) {
if (s > n)
return;
dp[s] = min(dp[s], pre + abs(a[p] - a[s]));
for (int i = 1; i <= k; i++) {
go(s + i, dp[s], s);
}
}
int32_t main() {
cin >> n >> k;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 0; i <= n + 5; i++) {
dp[i] = LLONG_MAX;
}
dp[1] = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= 2; j++) {
if (i + j <= n) {
dp[i + j] = min(dp[i + j], dp[i] + abs(a[i + j] - a[i]));
}
}
}
cout << dp[n] << endl;
}
| #include <bits/stdc++.h>
using namespace std;
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(0)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define debug(x) cout << "### x is: " << x << "###" << endl
#define all(a) a.begin(), a.end()
#define tc \
int t; \
scanf("%d", &t); \
while (t-- 0)
#define int long long
typedef vector<int> vll;
typedef vector<vll> vvll;
const int N = 2e5 + 5;
const int MOD = 1e9 + 7;
int power(int x, int p) {
int res = 1;
while (p) {
if (p % 2) {
res = (res * x) % MOD;
--p;
} else {
x = (x * x) % MOD;
p /= 2;
}
}
return res;
}
int invmod(int x) { return power(x, MOD - 2); }
int dp[N];
int a[N];
int n, k;
void go(int s, int pre, int p) {
if (s > n)
return;
dp[s] = min(dp[s], pre + abs(a[p] - a[s]));
for (int i = 1; i <= k; i++) {
go(s + i, dp[s], s);
}
}
int32_t main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 0; i <= n + 5; i++) {
dp[i] = LLONG_MAX;
}
dp[1] = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= 2; j++) {
if (i + j <= n) {
dp[i + j] = min(dp[i + j], dp[i] + abs(a[i + j] - a[i]));
}
}
}
cout << dp[n] << endl;
}
| [
"expression.operation.binary.remove"
] | 956,899 | 956,900 | u496698613 | cpp |
p03160 | #include <bits/stdc++.h>
using namespace std;
#define ms(x, t) memset(x, t, sizeof(x))
typedef long long int ll;
typedef unsigned long long int ull;
const int limit = 1e2 + 1;
const int inf = 1e7;
int h[limit];
int m[limit];
int abs(int i) {
if (i < 0) {
return -i;
}
return i;
}
int dp(int i) {
if (i < 1) {
return inf;
}
if (i == 1) {
return 0;
}
if (m[i] != -1) {
return m[i];
}
m[i] =
min(dp(i - 1) + abs(h[i] - h[i - 1]), dp(i - 2) + abs(h[i] - h[i - 2]));
return m[i];
}
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> h[i];
}
ms(m, -1);
cout << dp(n) << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define ms(x, t) memset(x, t, sizeof(x))
typedef long long int ll;
typedef unsigned long long int ull;
const int limit = 1e5 + 2;
const int inf = 1e7;
ll h[limit];
ll m[limit];
int abs(int i) {
if (i < 0) {
return -i;
}
return i;
}
int dp(int i) {
if (i < 1) {
return inf;
}
if (i == 1) {
return 0;
}
if (m[i] != -1) {
return m[i];
}
m[i] =
min(dp(i - 1) + abs(h[i] - h[i - 1]), dp(i - 2) + abs(h[i] - h[i - 2]));
return m[i];
}
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> h[i];
}
ms(m, -1);
cout << dp(n) << endl;
return 0;
} | [
"literal.number.change",
"expression.operation.binary.change",
"variable_declaration.type.change"
] | 956,901 | 956,902 | u290948881 | cpp |
p03160 | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> h(N + 1);
for (int i = 1; i <= N; i++)
cin >> h[i];
vector<int> dp(N + 1);
dp[1] = 0;
dp[2] = abs(h[2] - h[1]);
for (int i = 3; i < N; i++) {
dp[i] =
min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
}
cout << dp[N] << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> h(N + 1);
for (int i = 1; i <= N; i++)
cin >> h[i];
vector<int> dp(N + 1);
dp[1] = 0;
dp[2] = abs(h[2] - h[1]);
for (int i = 3; i <= N; i++) {
dp[i] =
min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
}
cout << dp[N] << endl;
}
| [
"expression.operator.compare.change",
"control_flow.loop.for.condition.change",
"expression.off_by_one",
"expression.operation.binary.change"
] | 956,906 | 956,907 | u119098168 | cpp |
p03160 | #include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll N = 1e5 + 5;
ll n;
ll d[N], dp[N];
int main() {
cin >> n;
for (ll i = 0; i < n; i++)
cin >> d[i];
memset(dp, 0, sizeof dp);
dp[n - 2] = dp[n - 1] + abs(d[n - 2] - d[n - 1]);
for (int i = n - 2; i >= 0; i--)
dp[i] =
min(dp[i + 1] + abs(d[i] - d[i + 1]), dp[i + 2] + abs(d[i] - d[i + 2]));
cout << dp[0] << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll N = 1e5 + 5;
ll n;
ll d[N], dp[N];
int main() {
cin >> n;
for (ll i = 0; i < n; i++)
cin >> d[i];
memset(dp, 0, sizeof dp);
dp[n - 2] = dp[n - 1] + abs(d[n - 2] - d[n - 1]);
for (int i = n - 3; i >= 0; i--)
dp[i] =
min(dp[i + 1] + abs(d[i] - d[i + 1]), dp[i + 2] + abs(d[i] - d[i + 2]));
cout << dp[0] << endl;
} | [
"literal.number.change",
"control_flow.loop.for.initializer.change",
"expression.off_by_one",
"expression.operation.binary.change"
] | 956,908 | 956,909 | u389308389 | cpp |
p03160 | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e5 + 5;
const int inf = 1e4 + 5;
ll dp[N];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, k = 2;
cin >> n;
vector<int> a(n);
a[0] = dp[0] = inf;
for (int i = 1; i <= n; i++) {
cin >> a[i];
dp[i] = inf;
}
dp[1] = 0;
for (int i = 2; i <= n; i++) {
for (int j = 1; j <= k; j++) {
if (i - j >= 1) {
dp[i] = min(dp[i - j] + abs(a[i] - a[i - j]), dp[i]);
}
}
}
cout << dp[n] << '\n';
return 0;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e5 + 5;
const int inf = 1e9;
ll dp[N];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, k = 2;
cin >> n;
vector<int> a(n);
a[0] = dp[0] = inf;
for (int i = 1; i <= n; i++) {
cin >> a[i];
dp[i] = inf;
}
dp[1] = 0;
for (int i = 2; i <= n; i++) {
for (int j = 1; j <= k; j++) {
if (i - j >= 1) {
dp[i] = min(dp[i - j] + abs(a[i] - a[i - j]), dp[i]);
}
}
}
cout << dp[n] << '\n';
return 0;
} | [
"literal.number.change",
"variable_declaration.value.change",
"expression.operation.binary.change",
"expression.operation.binary.remove"
] | 956,910 | 956,911 | u070200692 | cpp |
p03160 | #include <cmath>
#include <cstdio>
#include <vector>
using namespace std;
int main() {
int n, k = 2;
scanf("%d %d", &n);
vector<int> h(n), dp(n, 2000000000);
dp[0] = 0;
for (int i = 0; i < n; ++i)
scanf("%d", &h[i]);
for (int i = 1; i < n; ++i)
for (int p = max(0, i - k); p < i; ++p)
dp[i] = min(dp[i], dp[p] + (int)abs(h[p] - h[i]));
printf("%d\n", dp[n - 1]);
return 0;
} | #include <cmath>
#include <cstdio>
#include <vector>
using namespace std;
int main() {
int n, k = 2;
scanf("%d", &n);
vector<int> h(n), dp(n, 2000000000);
dp[0] = 0;
for (int i = 0; i < n; ++i)
scanf("%d", &h[i]);
for (int i = 1; i < n; ++i)
for (int p = max(0, i - k); p < i; ++p)
dp[i] = min(dp[i], dp[p] + (int)abs(h[p] - h[i]));
printf("%d\n", dp[n - 1]);
return 0;
} | [
"literal.string.change",
"call.arguments.change"
] | 956,912 | 956,913 | u904217313 | cpp |
p03160 | #include <bits/stdc++.h>
using namespace std;
#define fto(i, s, e) for (int i = s; i <= e; ++i)
#define fto1(i, s, e) for (int i = s; i < e; ++i)
#define fdto(i, s, e) for (int i = s; i >= e; --i)
#define fit(var, it) \
for (__typeof(var.begin()) it = var.begin(); it != var.end(); ++it)
#define frit(var, it) \
for (__typeof(var.rbegin()) it = var.rbegin(); it != var.rend(); ++it)
#define newl '\n'
#define debugt cerr << 0.001 * clock() << newl
#define debug1(x, i) cout << #x << '[' << i << "] = " << x[i] << newl
#define debug(v, l, r) fto(_i, l, r) debug1(v, _i)
#define debug2(x, i, j) \
cout << #x << '[' << i << "][" << j << "] = " << x[i][j] << newl
#define debug3(x, i, j, k) \
cout << #x << '[' << i << "][" << j << "][" << k << "] = " << x[i][j][k] \
<< newl
#define ll long long
#define ii pair<int, int>
#define ff first
#define ss second
#define pb push_back
#define glen(v) int((v).size())
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> const &v) {
return os << '(' << v.ff << ", " << v.ss << ')';
}
#define eps 1e-15
#define oo 1000000007
#define OO 1000000000000000003LL
#define maxn 100003
int n;
int h[maxn], f[maxn];
int main() {
#ifndef ONLINE_JUDGE
// freopen("main.inp", "r", stdin);
// freopen("main.out", "w", stdout);
#endif
// ios_base::sync_with_stdio(0); cin.tie(0);
scanf("%d", &n);
fto(i, 1, n) scanf("%d", &h[i]);
f[0] = -oo;
fto(i, 2, n) f[i] =
min(f[i - 1] + abs(h[i] - h[i - 1]), f[i - 2] + abs(h[i] - h[i - 2]));
printf("%d\n", f[n]);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define fto(i, s, e) for (int i = s; i <= e; ++i)
#define fto1(i, s, e) for (int i = s; i < e; ++i)
#define fdto(i, s, e) for (int i = s; i >= e; --i)
#define fit(var, it) \
for (__typeof(var.begin()) it = var.begin(); it != var.end(); ++it)
#define frit(var, it) \
for (__typeof(var.rbegin()) it = var.rbegin(); it != var.rend(); ++it)
#define newl '\n'
#define debugt cerr << 0.001 * clock() << newl
#define debug1(x, i) cout << #x << '[' << i << "] = " << x[i] << newl
#define debug(v, l, r) fto(_i, l, r) debug1(v, _i)
#define debug2(x, i, j) \
cout << #x << '[' << i << "][" << j << "] = " << x[i][j] << newl
#define debug3(x, i, j, k) \
cout << #x << '[' << i << "][" << j << "][" << k << "] = " << x[i][j][k] \
<< newl
#define ll long long
#define ii pair<int, int>
#define ff first
#define ss second
#define pb push_back
#define glen(v) int((v).size())
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> const &v) {
return os << '(' << v.ff << ", " << v.ss << ')';
}
#define eps 1e-15
#define oo 1000000007
#define OO 1000000000000000003LL
#define maxn 100003
int n;
int h[maxn], f[maxn];
int main() {
#ifndef ONLINE_JUDGE
// freopen("main.inp", "r", stdin);
// freopen("main.out", "w", stdout);
#endif
// ios_base::sync_with_stdio(0); cin.tie(0);
scanf("%d", &n);
fto(i, 1, n) scanf("%d", &h[i]);
f[0] = oo;
fto(i, 2, n) f[i] =
min(f[i - 1] + abs(h[i] - h[i - 1]), f[i - 2] + abs(h[i] - h[i - 2]));
printf("%d\n", f[n]);
return 0;
}
| [
"expression.operation.unary.arithmetic.remove"
] | 956,919 | 956,920 | u645891928 | cpp |
p03160 | #include <iostream>
#include <vector>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> h(n + 1);
vector<int> dp(n + 1, 2'000'000'000);
for (auto i = 1; i <= n; i++) {
cin >> h[i];
}
dp[1] = h[1];
for (auto i = 1; i <= n; i++) {
int i1 = i + 1;
int i2 = i + 2;
if (i1 <= n) {
dp[i1] =
min(dp[i1], dp[i] + (dp[i] < h[i1] ? h[i1] - dp[i] : dp[i] - h[i1]));
}
if (i2 <= n) {
dp[i2] =
min(dp[i2], dp[i] + (dp[i] < h[i2] ? h[i2] - dp[i] : dp[i] - h[i2]));
}
}
cout << dp[n] - dp[1] << endl;
}
| #include <iostream>
#include <vector>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> h(n + 1);
vector<int> dp(n + 1, 2'000'000'000);
for (auto i = 1; i <= n; i++) {
cin >> h[i];
}
dp[1] = h[1];
for (auto i = 1; i <= n; i++) {
int i1 = i + 1;
int i2 = i + 2;
if (i1 <= n) {
dp[i1] =
min(dp[i1], dp[i] + (h[i] < h[i1] ? h[i1] - h[i] : h[i] - h[i1]));
}
if (i2 <= n) {
dp[i2] =
min(dp[i2], dp[i] + (h[i] < h[i2] ? h[i2] - h[i] : h[i] - h[i2]));
}
}
cout << dp[n] - dp[1] << endl;
}
| [
"assignment.value.change",
"control_flow.branch.if.condition.change",
"call.arguments.change",
"expression.operation.binary.change"
] | 956,921 | 956,922 | u081445141 | cpp |
p03160 | #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define boost() \
ios_base ::sync_with_stdio(0); \
cin.tie(); \
cout.tie(); \
cout << fixed; \
cout << setprecision(15); \
srand(time(NULL))
#define all(x) x.begin(), x.end()
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
int n, h[100010];
int dp[100010][5];
int sol(int idx, int jump) {
if (idx + jump >= n)
return INT_MAX;
if (idx == n - 1)
return 0;
int &ret = dp[idx][jump];
if (ret != -1)
return ret;
ret = INT_MAX;
ret = min(ret, sol(idx + jump, 1) + abs(h[idx] - h[idx + jump]));
ret = min(ret, sol(idx + jump, 2) + abs(h[idx] - h[idx + jump]));
return ret;
}
signed main() {
cin >> n;
memset(dp, -1, sizeof dp);
for (int i = 0; i < n; i++)
cin >> h[i];
cout << min(sol(0, 1), sol(0, 2)) << endl;
return 0;
}
| #include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define boost() \
ios_base ::sync_with_stdio(0); \
cin.tie(); \
cout.tie(); \
cout << fixed; \
cout << setprecision(15); \
srand(time(NULL))
#define all(x) x.begin(), x.end()
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
int n, h[100010];
int dp[100010][5];
int sol(int idx, int jump) {
if (idx >= n)
return INT_MAX;
if (idx == n - 1)
return 0;
int &ret = dp[idx][jump];
if (ret != -1)
return ret;
ret = INT_MAX;
ret = min(ret, sol(idx + jump, 1) + abs(h[idx] - h[idx + jump]));
ret = min(ret, sol(idx + jump, 2) + abs(h[idx] - h[idx + jump]));
return ret;
}
signed main() {
cin >> n;
memset(dp, -1, sizeof dp);
for (int i = 0; i < n; i++)
cin >> h[i];
cout << min(sol(0, 1), sol(0, 2)) << endl;
return 0;
}
| [
"expression.operation.binary.remove"
] | 956,923 | 956,924 | u243631447 | cpp |
p03160 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
const ll MOD = 1e9 + 7;
const int maxn = 1e6 + 10;
int main() {
ll n;
cin >> n;
vll nums(n);
vll dp(n);
for (int i = 0; i < n; ++i) {
cin >> nums[i];
}
dp[0] = 0;
dp[1] = abs(nums[1] - nums[0]);
for (int i = 2; i < n; ++i) {
dp[i] = min(dp[i - 1] + abs(nums[i] - nums[i - 1]),
dp[i - 2] + abs(nums[i] - nums[i - 2]));
}
cout << dp[n] << endl;
return 0;
}
static int speedUp = []() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
return 0;
}();
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<int> vi;
const ll MOD = 1e9 + 7;
const int maxn = 1e6 + 10;
int main() {
ll n;
cin >> n;
vll nums(n);
vll dp(n);
for (int i = 0; i < n; ++i) {
cin >> nums[i];
}
dp[0] = 0;
dp[1] = abs(nums[1] - nums[0]);
for (int i = 2; i < n; ++i) {
dp[i] = min(dp[i - 1] + abs(nums[i] - nums[i - 1]),
dp[i - 2] + abs(nums[i] - nums[i - 2]));
}
cout << dp[n - 1] << endl;
return 0;
}
static int speedUp = []() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
return 0;
}();
| [
"expression.operation.binary.add"
] | 956,925 | 956,926 | u666721654 | cpp |
p03160 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define int ll
#define double ld
#define faster ios_base::sync_with_stdio(false);
typedef pair<int, int> pii;
///------------------------------------------------------------------------
const int inf = 1e18;
const int mod = 1e9 + 7;
ifstream in("input.txt");
ofstream out("output.txt");
signed main() {
int n;
cin >> n;
vector<int> vec(n);
for (int i = 0; i < n; i++)
cin >> vec[i];
vector<int> dp(n);
dp[1] = abs(vec[1] - vec[0]);
for (int i = 2; i < n; i++) {
dp[i] = max(dp[i - 1] + abs(vec[i] - vec[i - 1]),
dp[i - 2] + abs(vec[i] - vec[i - 2]));
}
cout << dp[n - 1];
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define int ll
#define double ld
#define faster ios_base::sync_with_stdio(false);
typedef pair<int, int> pii;
///------------------------------------------------------------------------
const int inf = 1e18;
const int mod = 1e9 + 7;
ifstream in("input.txt");
ofstream out("output.txt");
signed main() {
int n;
cin >> n;
vector<int> vec(n);
for (int i = 0; i < n; i++)
cin >> vec[i];
vector<int> dp(n);
dp[1] = abs(vec[1] - vec[0]);
for (int i = 2; i < n; i++) {
dp[i] = min(dp[i - 1] + abs(vec[i] - vec[i - 1]),
dp[i - 2] + abs(vec[i] - vec[i - 2]));
}
cout << dp[n - 1];
return 0;
}
| [
"misc.opposites",
"assignment.value.change",
"identifier.change",
"call.function.change"
] | 956,927 | 956,928 | u493500152 | cpp |
p03160 | #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 DEBUG
#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
const char *comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << " : " << arg1 << " | ";
__f(comma + 1, args...);
}
#else
#define debug(...)
#endif
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define RFOR(i, a, b) for (int i = a; i >= b; --i)
#define ln "\n"
#define mp make_pair
#define pb push_back
#define sz(a) ll(a.size())
#define F first
#define S second
#define all(c) c.begin(), c.end()
#define trace(c, x) for (auto &x : c)
#define pii pair<ll, ll>
typedef long long ll;
typedef long double ld;
typedef priority_queue<pii, std::vector<pii>, greater<pii>> revpr;
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
pbds;
// ordered_set X
// K-th smallest
//*X.find_by_order(k-1)
// NO OF ELEMENTS < A
// X.order_of_key(A)
const int L = 1e6 + 7;
int a[L], n, dp[L];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
FOR(i, 0, n) cin >> a[i];
dp[n] = 0;
dp[n - 1] = abs(a[n] - a[n - 1]);
RFOR(i, n - 2, 1)
dp[i] =
min(dp[i + 1] + abs(a[i + 1] - a[i]), dp[i + 2] + abs(a[i + 2] - a[i]));
cout << dp[1];
return 0;
} | #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 DEBUG
#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
const char *comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << " : " << arg1 << " | ";
__f(comma + 1, args...);
}
#else
#define debug(...)
#endif
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define RFOR(i, a, b) for (int i = a; i >= b; --i)
#define ln "\n"
#define mp make_pair
#define pb push_back
#define sz(a) ll(a.size())
#define F first
#define S second
#define all(c) c.begin(), c.end()
#define trace(c, x) for (auto &x : c)
#define pii pair<ll, ll>
typedef long long ll;
typedef long double ld;
typedef priority_queue<pii, std::vector<pii>, greater<pii>> revpr;
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update>
pbds;
// ordered_set X
// K-th smallest
//*X.find_by_order(k-1)
// NO OF ELEMENTS < A
// X.order_of_key(A)
const int L = 1e6 + 7;
int a[L], n, dp[L];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
FOR(i, 1, n + 1) cin >> a[i];
dp[n] = 0;
dp[n - 1] = abs(a[n] - a[n - 1]);
RFOR(i, n - 2, 1)
dp[i] =
min(dp[i + 1] + abs(a[i + 1] - a[i]), dp[i + 2] + abs(a[i + 2] - a[i]));
cout << dp[1];
return 0;
} | [
"literal.number.change",
"call.arguments.change"
] | 956,929 | 956,930 | u547372544 | cpp |
p03160 | #include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
int min(int x, int y) { return x < y ? x : y; }
int abs(int x) { return x >= 0 ? x : (-1 * x); }
int main() {
int n, arr[105];
cin >> n;
int memo[105];
for (int i = 0; i < n; ++i) {
cin >> arr[i];
}
memo[0] = 0;
memo[1] = abs(arr[0] - arr[1]);
// memo[2] = abs(arr[0] - arr[2]);
for (int i = 2; i < n; ++i) {
memo[i] = min(memo[i - 1] + abs(arr[i - 1] - arr[i]),
memo[i - 2] + abs(arr[i - 2] - arr[i]));
}
cout << memo[n - 1] << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
int min(int x, int y) { return x < y ? x : y; }
int abs(int x) { return x >= 0 ? x : (-1 * x); }
int main() {
int n, arr[100005];
cin >> n;
int memo[100005];
for (int i = 0; i < n; ++i) {
cin >> arr[i];
}
memo[0] = 0;
memo[1] = abs(arr[0] - arr[1]);
// memo[2] = abs(arr[0] - arr[2]);
for (int i = 2; i < n; ++i) {
memo[i] = min(memo[i - 1] + abs(arr[i - 1] - arr[i]),
memo[i - 2] + abs(arr[i - 2] - arr[i]));
}
cout << memo[n - 1] << endl;
return 0;
} | [
"literal.number.change",
"variable_declaration.array_dimensions.change"
] | 956,931 | 956,932 | u576847925 | cpp |
p03160 | #include <bits/stdc++.h>
using namespace std;
long long dp[100005];
int main() {
int n;
cin >> n;
int i;
long long a[n + 1];
for (i = 1; i <= n; i++) {
cin >> a[i];
}
dp[1] = a[1];
dp[2] = abs(a[1] - a[2]);
for (i = 3; i <= n; i++) {
dp[i] =
min(dp[i - 1] + abs(a[i - 1] - a[i]), dp[i - 2] + abs(a[i - 2] - a[i]));
}
cout << dp[n] << endl;
}
| #include <bits/stdc++.h>
using namespace std;
long long dp[100005];
int main() {
int n;
cin >> n;
int i;
long long a[n + 1];
for (i = 1; i <= n; i++) {
cin >> a[i];
}
dp[1] = 0;
dp[2] = abs(a[1] - a[2]);
for (i = 3; i <= n; i++) {
dp[i] =
min(dp[i - 1] + abs(a[i - 1] - a[i]), dp[i - 2] + abs(a[i - 2] - a[i]));
}
cout << dp[n] << endl;
}
| [
"assignment.value.change",
"identifier.replace.remove",
"literal.replace.add"
] | 956,937 | 956,938 | u859075846 | cpp |
p03160 | //#include<bits/stdc++.h>
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
int arr[n];
for (int i = 0; i < n; i++)
cin >> arr[i];
int dp[n];
dp[0] = 0;
dp[1] = abs(arr[0] - arr[1]);
for (int i = 2; i < n; i++) {
dp[i] = min(dp[i - 1] + abs(arr[i] - arr[i - 1]),
dp[i - 2] + abs(arr[i] - arr[i - 2]));
}
// cout << dp[n-1];
return dp[n - 1];
} | //#include<bits/stdc++.h>
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
int arr[n];
for (int i = 0; i < n; i++)
cin >> arr[i];
int dp[n];
dp[0] = 0;
dp[1] = abs(arr[0] - arr[1]);
for (int i = 2; i < n; i++) {
dp[i] = min(dp[i - 1] + abs(arr[i] - arr[i - 1]),
dp[i - 2] + abs(arr[i] - arr[i - 2]));
}
cout << dp[n - 1];
return 0;
// return dp[n-1];
} | [
"io.output.change",
"control_flow.return.add",
"control_flow.return.0.add"
] | 956,939 | 956,940 | u800497197 | cpp |
p03160 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, h[1000000], dp[1000000], a, b;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> h[i];
}
dp[0] = h[0];
dp[1] = abs(h[0] - h[1]);
for (int i = 2; i < n; i++) {
a = abs(h[i - 1] - h[i]);
b = abs(h[i - 2] - h[i]);
dp[i] = min(a + dp[i - 1], b + dp[i - 2]);
}
cout << dp[n - 1] << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int n, h[1000000], dp[1000000], a, b;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> h[i];
}
dp[0] = 0;
dp[1] = abs(h[0] - h[1]);
for (int i = 2; i < n; i++) {
a = abs(h[i - 1] - h[i]);
b = abs(h[i - 2] - h[i]);
dp[i] = min(a + dp[i - 1], b + dp[i - 2]);
}
cout << dp[n - 1] << endl;
}
| [] | 956,949 | 956,950 | u962104148 | cpp |
p03160 | #include <bits/stdc++.h>
#include <string.h>
using namespace std;
#define IOS \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define endl "\n"
#define Max(x, y, z) max(x, max(y, z))
#define Min(x, y, z) min(x, min(y, z))
#define fr(i, s, e) for (i = s; i < e; i++)
#define rf(i, s, e) for (i = s - 1; i >= e; i--)
#define pb push_back
#define eb emblace_back
#define mp make_pair
#define ff first
#define ss second
#define int long long
#define ll long long
#define trace1(x) cerr << #x << ": " << x << endl
#define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl
#define trace3(x, y, z) \
cerr << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " \
<< z << endl
#define trace4(a, b, c, d) \
cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \
<< c << " | " << #d << ": " << d << endl
#define trace5(a, b, c, d, e) \
cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \
<< c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl
#define trace6(a, b, c, d, e, f) \
cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \
<< c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " \
<< #f << ": " << f << endl
#define vl vector<long long>
#define inf (1LL << 61)
#define vi vector<int>
#define vii vector<vector<int>>
#define vll vector<vector<long long>>
#define vpi vector<pair<int, int>>
#define vpl vector<pair<ll, ll>>
#define viii vector<vector<vector<int>>>
typedef pair<pair<int, int>, int> P;
#define cd complex<double>
#define PI 4 * atan(1)
#define mod 1000000007
#define pi 3.14159265358979323846 // 20 decimals
#define ld long double
#define all(c) (c).begin(), (c).end()
#define N 100002
int dp[N];
int n;
vi v(N);
int rec(int i) {
if (i >= n)
return inf;
if (i == n - 1)
return 0;
if (dp[i] == -1) {
int ans = 0;
ans = min(abs(v[i + 1] - v[i]) + rec(i + 1),
abs(v[i + 2] - v[i] + rec(i + 2)));
dp[i] = ans;
return ans;
} else
return dp[i];
}
int32_t main() {
IOS;
memset(dp, -1, sizeof(dp));
cin >> n;
v[n] = 1e9;
v[n + 1] = 1e9;
for (int i = 0; i < n; i++) {
cin >> v[i];
}
cout << rec(0);
return 0;
} | #include <bits/stdc++.h>
#include <string.h>
using namespace std;
#define IOS \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define endl "\n"
#define Max(x, y, z) max(x, max(y, z))
#define Min(x, y, z) min(x, min(y, z))
#define fr(i, s, e) for (i = s; i < e; i++)
#define rf(i, s, e) for (i = s - 1; i >= e; i--)
#define pb push_back
#define eb emblace_back
#define mp make_pair
#define ff first
#define ss second
#define int long long
#define ll long long
#define trace1(x) cerr << #x << ": " << x << endl
#define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl
#define trace3(x, y, z) \
cerr << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " \
<< z << endl
#define trace4(a, b, c, d) \
cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \
<< c << " | " << #d << ": " << d << endl
#define trace5(a, b, c, d, e) \
cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \
<< c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl
#define trace6(a, b, c, d, e, f) \
cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \
<< c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " \
<< #f << ": " << f << endl
#define vl vector<long long>
#define inf (1LL << 61)
#define vi vector<int>
#define vii vector<vector<int>>
#define vll vector<vector<long long>>
#define vpi vector<pair<int, int>>
#define vpl vector<pair<ll, ll>>
#define viii vector<vector<vector<int>>>
typedef pair<pair<int, int>, int> P;
#define cd complex<double>
#define PI 4 * atan(1)
#define mod 1000000007
#define pi 3.14159265358979323846 // 20 decimals
#define ld long double
#define all(c) (c).begin(), (c).end()
#define N 100002
int dp[N];
int n;
vi v(N);
int rec(int i) {
if (i >= n)
return inf;
if (i == n - 1)
return 0;
if (dp[i] == -1) {
int ans = 0;
ans = min(abs(v[i + 1] - v[i]) + rec(i + 1),
abs(v[i + 2] - v[i]) + rec(i + 2));
dp[i] = ans;
return ans;
} else
return dp[i];
}
int32_t main() {
IOS;
memset(dp, -1, sizeof(dp));
cin >> n;
v[n] = 1e9;
v[n + 1] = 1e9;
for (int i = 0; i < n; i++) {
cin >> v[i];
}
cout << rec(0);
return 0;
} | [
"call.arguments.change"
] | 956,953 | 956,954 | u811982971 | cpp |
p03160 | #include <bits/stdc++.h>
#include <string.h>
using namespace std;
#define IOS \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define endl "\n"
#define Max(x, y, z) max(x, max(y, z))
#define Min(x, y, z) min(x, min(y, z))
#define fr(i, s, e) for (i = s; i < e; i++)
#define rf(i, s, e) for (i = s - 1; i >= e; i--)
#define pb push_back
#define eb emblace_back
#define mp make_pair
#define ff first
#define ss second
#define int long long
#define ll long long
#define trace1(x) cerr << #x << ": " << x << endl
#define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl
#define trace3(x, y, z) \
cerr << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " \
<< z << endl
#define trace4(a, b, c, d) \
cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \
<< c << " | " << #d << ": " << d << endl
#define trace5(a, b, c, d, e) \
cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \
<< c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl
#define trace6(a, b, c, d, e, f) \
cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \
<< c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " \
<< #f << ": " << f << endl
#define vl vector<long long>
#define inf (1LL << 61)
#define vi vector<int>
#define vii vector<vector<int>>
#define vll vector<vector<long long>>
#define vpi vector<pair<int, int>>
#define vpl vector<pair<ll, ll>>
#define viii vector<vector<vector<int>>>
typedef pair<pair<int, int>, int> P;
#define cd complex<double>
#define PI 4 * atan(1)
#define mod 1000000007
#define pi 3.14159265358979323846 // 20 decimals
#define ld long double
#define all(c) (c).begin(), (c).end()
#define N 100002
int dp[N];
int n;
vi v(N);
int rec(int i) {
if (i >= n)
return -inf;
if (i == n - 1)
return 0;
if (dp[i] == -1) {
int ans = 0;
ans = min(abs(v[i + 1] - v[i]) + rec(i + 1),
abs(v[i + 2] - v[i] + rec(i + 2)));
dp[i] = ans;
return ans;
} else
return dp[i];
}
int32_t main() {
IOS;
memset(dp, -1, sizeof(dp));
cin >> n;
v[n + 1] = 1e9;
v[n + 2] = 1e9;
for (int i = 0; i < n; i++) {
cin >> v[i];
}
cout << rec(0);
return 0;
} | #include <bits/stdc++.h>
#include <string.h>
using namespace std;
#define IOS \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define endl "\n"
#define Max(x, y, z) max(x, max(y, z))
#define Min(x, y, z) min(x, min(y, z))
#define fr(i, s, e) for (i = s; i < e; i++)
#define rf(i, s, e) for (i = s - 1; i >= e; i--)
#define pb push_back
#define eb emblace_back
#define mp make_pair
#define ff first
#define ss second
#define int long long
#define ll long long
#define trace1(x) cerr << #x << ": " << x << endl
#define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl
#define trace3(x, y, z) \
cerr << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " \
<< z << endl
#define trace4(a, b, c, d) \
cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \
<< c << " | " << #d << ": " << d << endl
#define trace5(a, b, c, d, e) \
cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \
<< c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl
#define trace6(a, b, c, d, e, f) \
cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " \
<< c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " \
<< #f << ": " << f << endl
#define vl vector<long long>
#define inf (1LL << 61)
#define vi vector<int>
#define vii vector<vector<int>>
#define vll vector<vector<long long>>
#define vpi vector<pair<int, int>>
#define vpl vector<pair<ll, ll>>
#define viii vector<vector<vector<int>>>
typedef pair<pair<int, int>, int> P;
#define cd complex<double>
#define PI 4 * atan(1)
#define mod 1000000007
#define pi 3.14159265358979323846 // 20 decimals
#define ld long double
#define all(c) (c).begin(), (c).end()
#define N 100002
int dp[N];
int n;
vi v(N);
int rec(int i) {
if (i >= n)
return inf;
if (i == n - 1)
return 0;
if (dp[i] == -1) {
int ans = 0;
ans = min(abs(v[i + 1] - v[i]) + rec(i + 1),
abs(v[i + 2] - v[i]) + rec(i + 2));
dp[i] = ans;
return ans;
} else
return dp[i];
}
int32_t main() {
IOS;
memset(dp, -1, sizeof(dp));
cin >> n;
v[n] = 1e9;
v[n + 1] = 1e9;
for (int i = 0; i < n; i++) {
cin >> v[i];
}
cout << rec(0);
return 0;
} | [
"expression.operation.unary.arithmetic.remove",
"call.arguments.change",
"expression.operation.binary.remove",
"literal.number.change",
"assignment.variable.change",
"variable_access.subscript.index.change",
"expression.operation.binary.change"
] | 956,955 | 956,954 | u811982971 | cpp |
p03160 | #include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
ll t;
cin >> t;
while (t--) {
ll n;
cin >> n;
ll arr[n], i, ans[n], x, y;
for (i = 0; i < n; i++)
cin >> arr[i];
ans[0] = 0;
x = abs(arr[1] - arr[0]);
ans[1] = ans[0] + x;
for (i = 2; i < n; i++)
ans[i] = min((ans[i - 1] + abs(arr[i - 1] - arr[i])),
(ans[i - 2] + abs(arr[i - 2] - arr[i])));
cout << ans[n - 1] << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
ll t = 1;
while (t--) {
ll n;
cin >> n;
ll arr[n], i, ans[n], x, y;
for (i = 0; i < n; i++)
cin >> arr[i];
ans[0] = 0;
x = abs(arr[1] - arr[0]);
ans[1] = ans[0] + x;
for (i = 2; i < n; i++)
ans[i] = min((ans[i - 1] + abs(arr[i - 1] - arr[i])),
(ans[i - 2] + abs(arr[i - 2] - arr[i])));
cout << ans[n - 1] << endl;
}
return 0;
} | [
"expression.operation.binary.remove"
] | 956,956 | 956,957 | u549346094 | cpp |
p03160 | /*----------------by syr----------------*/
/*
----- ----- -----
| | |---| _/
| | | \_ /
----- | \ -----
|---\ \ / |\ /|
| | \_/ | \/ |
| | / \ | |
|---/ / \ | |
*/
#include <bits/stdc++.h>
using namespace std;
#define PH push
#define MP make_pair
#define PB push_back
#define fst first
#define snd second
#define FOR(i, x, y) for (int i = (x); i < (y); ++i)
#define REP(i, x, y) for (int i = (x); i <= (y); ++i)
#define x0 x0123456789
#define y0 y0123456789
#define x1 x1234567890
#define y1 y1234567890
#define x2 x2345678901
#define y2 y2345678901
typedef double db;
typedef long long ll;
typedef long double ldb;
typedef pair<int, int> pii;
const int INF = 1e9 + 7;
const int maxn = 1e5 + 5;
int n;
int h[maxn], dp[maxn];
int main() {
scanf("%d", &n);
REP(i, 1, n) scanf("%d", h + i);
dp[1] = 0;
REP(i, 2, n) {
dp[i] = dp[i - 1] + abs(h[i] - h[i - 1]);
if (i > 1)
dp[i] = min(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
}
printf("%d\n", dp[n]);
return 0;
}
| /*----------------by syr----------------*/
/*
----- ----- -----
| | |---| _/
| | | \_ /
----- | \ -----
|---\ \ / |\ /|
| | \_/ | \/ |
| | / \ | |
|---/ / \ | |
*/
#include <bits/stdc++.h>
using namespace std;
#define PH push
#define MP make_pair
#define PB push_back
#define fst first
#define snd second
#define FOR(i, x, y) for (int i = (x); i < (y); ++i)
#define REP(i, x, y) for (int i = (x); i <= (y); ++i)
#define x0 x0123456789
#define y0 y0123456789
#define x1 x1234567890
#define y1 y1234567890
#define x2 x2345678901
#define y2 y2345678901
typedef double db;
typedef long long ll;
typedef long double ldb;
typedef pair<int, int> pii;
const int INF = 1e9 + 7;
const int maxn = 1e5 + 5;
int n;
int h[maxn], dp[maxn];
int main() {
scanf("%d", &n);
REP(i, 1, n) scanf("%d", h + i);
dp[1] = 0;
REP(i, 2, n) {
dp[i] = dp[i - 1] + abs(h[i] - h[i - 1]);
if (i > 2)
dp[i] = min(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
}
printf("%d\n", dp[n]);
return 0;
}
| [
"literal.number.change",
"control_flow.branch.if.condition.change"
] | 956,958 | 956,959 | u904221771 | cpp |
p03160 | #include <iostream>
using namespace std;
#define N 100000
#define Q
#define INF 1 << 18
#define MIN(X, Y) ((X) < (Y) ? (X) : (Y))
#define ABS(X) ((X) < 0 ? -(X) : (X))
int dp[N + 1];
int main(void) {
int n;
int h[N + 1];
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> h[i];
dp[i] = INF;
}
dp[1] = 0;
for (int i = 2; i <= n; i++) {
dp[i] = dp[i - 1] + ABS(h[i] - h[i - 1]);
if (i - 2 >= 0)
dp[i] = MIN(dp[i], dp[i - 2] + ABS(h[i] - h[i - 2]));
// cout << dp[i] << " ";
}
cout << dp[n] << endl;
return 0;
}
| #include <iostream>
using namespace std;
#define N 100000
#define Q
#define INF 1 << 18
#define MIN(X, Y) ((X) < (Y) ? (X) : (Y))
#define ABS(X) ((X) < 0 ? -(X) : (X))
int dp[N + 1];
int main(void) {
int n;
int h[N + 1];
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> h[i];
dp[i] = INF;
}
dp[1] = 0;
for (int i = 2; i <= n; i++) {
dp[i] = dp[i - 1] + ABS(h[i] - h[i - 1]);
if (i - 2 >= 1)
dp[i] = MIN(dp[i], dp[i - 2] + ABS(h[i] - h[i - 2]));
// cout << dp[i] << " ";
}
cout << dp[n] << endl;
return 0;
}
| [
"literal.number.change",
"control_flow.branch.if.condition.change"
] | 956,960 | 956,961 | u023463844 | cpp |
p03160 | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll, ll> ii;
#define M 1000000
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define sz(x) (ll) x.size()
#define fill(a, x) memset(a, x, sizeof(a))
#define F first
#define S second
#define FOR(i, a, b) for (ll i = a; i <= b; ++i)
#define NFOR(i, a, b) for (ll i = a; i >= b; --i)
#define fast ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
const ll INF = 1e18;
const ll mod = 1e9 + 7;
const ll N = 5e5 + 10;
inline ll add(ll x, ll y) {
x += y;
if (x >= mod)
x -= mod;
return x;
}
inline ll mul(ll x, ll y) {
x = (1LL * x * y) % mod;
return x;
}
int main() {
ll n;
cin >> n;
ll a[n + 1];
FOR(i, 1, n) cin >> a[i];
ll dp[n + 1] = {0};
dp[1] = 0;
dp[2] = abs(a[2] - a[1]);
FOR(i, 2, n) {
dp[i] =
min(dp[i - 1] + abs(a[i] - a[i - 1]), dp[i - 2] + abs(a[i] - a[i - 2]));
}
cout << dp[n];
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll, ll> ii;
#define M 1000000
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define sz(x) (ll) x.size()
#define fill(a, x) memset(a, x, sizeof(a))
#define F first
#define S second
#define FOR(i, a, b) for (ll i = a; i <= b; ++i)
#define NFOR(i, a, b) for (ll i = a; i >= b; --i)
#define fast ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
const ll INF = 1e18;
const ll mod = 1e9 + 7;
const ll N = 5e5 + 10;
inline ll add(ll x, ll y) {
x += y;
if (x >= mod)
x -= mod;
return x;
}
inline ll mul(ll x, ll y) {
x = (1LL * x * y) % mod;
return x;
}
int main() {
ll n;
cin >> n;
ll a[n + 1];
FOR(i, 1, n) cin >> a[i];
ll dp[n + 1] = {0};
dp[1] = 0;
dp[2] = abs(a[2] - a[1]);
FOR(i, 3, n) {
dp[i] =
min(dp[i - 1] + abs(a[i] - a[i - 1]), dp[i - 2] + abs(a[i] - a[i - 2]));
}
cout << dp[n];
return 0;
} | [
"literal.number.change",
"call.arguments.change"
] | 956,968 | 956,969 | u183138131 | cpp |
p03160 | #include <fstream>
#include <iomanip>
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
long arr[200000];
long dp[200000];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, k;
cin >> n >> k;
for (int i = 1; i < n + 1; i++)
cin >> arr[i];
arr[0] = 10000000;
dp[0] = dp[1] = 0;
for (int i = 2; i < n + 1; i++) {
dp[i] = dp[i - 1] + abs(arr[i] - arr[i - 1]);
for (int j = i - 1; (j > 0) && (j >= i - k); j--) {
dp[i] = min(dp[i], dp[j] + abs(arr[i] - arr[j]));
}
}
cout << dp[n] << endl;
return 0;
}
| #include <fstream>
#include <iomanip>
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
long arr[200000];
long dp[200000];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, k;
cin >> n;
k = 2;
for (int i = 1; i < n + 1; i++)
cin >> arr[i];
arr[0] = 10000000;
dp[0] = dp[1] = 0;
for (int i = 2; i < n + 1; i++) {
dp[i] = dp[i - 1] + abs(arr[i] - arr[i - 1]);
for (int j = i - 1; (j > 0) && (j >= i - k); j--) {
dp[i] = min(dp[i], dp[j] + abs(arr[i] - arr[j]));
}
}
cout << dp[n] << endl;
return 0;
}
| [
"expression.operation.binary.remove",
"assignment.add"
] | 956,970 | 956,971 | u283777760 | cpp |
p03160 | #include <algorithm>
#include <bitset>
#include <chrono>
#include <cstdio>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define REP(i, x, y) for (ll i = x; i <= y; i++)
#define SIZE(a) ll(a.size())
#define vll vector<ll>
#define MEMSET(a, n, m) \
for (ll i = 0; i <= n; i++) \
a[i] = m
#define BIT(n) (ll(1) << n)
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define UNIQUE_ARRAY(a, n) n = unique(a + 1, a + x + 1) - a - 1
#define SORT(a, n) sort(a + 1, a + n + 1)
#define SORT_O(a, n, order) sort(a + 1, a + n + 1, order)
#define PER(i, y, x) for (ll i = y; i >= x; i--)
typedef long long ll;
using namespace std;
/*
struct point
{
long long dist; long long name;
bool operator<(const point& rhs) const {
return dist > rhs.dist;
}
};
*/
ll const MAX = 1e5 + 4;
ll h[MAX];
ll dp[MAX];
int main() {
ll n;
cin >> n;
REP(i, 1, n) { cin >> h[i]; }
h[0] = 0;
dp[1] = 0;
dp[0] = 0;
REP(i, 2, n) {
dp[i] =
min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
}
cout << dp[n] << endl;
} | #include <algorithm>
#include <bitset>
#include <chrono>
#include <cstdio>
#include <fstream>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define REP(i, x, y) for (ll i = x; i <= y; i++)
#define SIZE(a) ll(a.size())
#define vll vector<ll>
#define MEMSET(a, n, m) \
for (ll i = 0; i <= n; i++) \
a[i] = m
#define BIT(n) (ll(1) << n)
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define UNIQUE_ARRAY(a, n) n = unique(a + 1, a + x + 1) - a - 1
#define SORT(a, n) sort(a + 1, a + n + 1)
#define SORT_O(a, n, order) sort(a + 1, a + n + 1, order)
#define PER(i, y, x) for (ll i = y; i >= x; i--)
typedef long long ll;
using namespace std;
/*
struct point
{
long long dist; long long name;
bool operator<(const point& rhs) const {
return dist > rhs.dist;
}
};
*/
ll const MAX = 1e5 + 4;
ll h[MAX];
ll dp[MAX];
int main() {
ll n;
cin >> n;
REP(i, 1, n) { cin >> h[i]; }
h[0] = h[1];
dp[1] = 0;
dp[0] = 0;
REP(i, 2, n) {
dp[i] =
min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
}
cout << dp[n] << endl;
} | [
"assignment.value.change",
"identifier.replace.add",
"literal.replace.remove"
] | 956,972 | 956,973 | u834354741 | cpp |
p03160 | #include <bits/stdc++.h>
using namespace std;
#define int long long
//#define uint __int128_t
#define pb push_back
#define fi first
#define se second
#define rep(i, s, n) for (int i = s; i < n; i++)
#define repe(i, s, n) for (int i = s; i <= n; i++)
#define rrep(i, s, n) for (int i = (n)-1; i >= (s); i--)
#define all(v) (v).begin(), (v).end()
#define chmin(a, b) a = min((a), (b))
#define chmax(a, b) a = max((a), (b))
#define low(a, b) lower_bound(all(a), (b)) - (a).begin()
#define upp(a, b) upper_bound(all(a), (b)) - (a).begin()
#define endl '\n'
#define IOS() \
ios_base::sync_with_stdio(0); \
cin.tie(0)
typedef long long ll;
typedef pair<int, int> pint;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<pint> vpint;
typedef pair<pint, int> P1;
typedef pair<int, pint> P2;
typedef pair<pint, pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD = 1000000007;
const ll INF = 1e18;
int N;
int h[100010];
int dp[100010];
signed main() {
IOS();
//(1ll<<N)シフト演算のオーバーフローに気をつける
cin >> N;
rep(i, 1, N + 1) cin >> h[i];
rep(i, 2, N + 1) {
if (i == 1)
dp[i] = dp[i - 1] + abs(h[i] - h[i - 1]);
else {
dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]),
dp[i - 2] + abs(h[i] - h[i - 2]));
}
}
cout << dp[N] << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define int long long
//#define uint __int128_t
#define pb push_back
#define fi first
#define se second
#define rep(i, s, n) for (int i = s; i < n; i++)
#define repe(i, s, n) for (int i = s; i <= n; i++)
#define rrep(i, s, n) for (int i = (n)-1; i >= (s); i--)
#define all(v) (v).begin(), (v).end()
#define chmin(a, b) a = min((a), (b))
#define chmax(a, b) a = max((a), (b))
#define low(a, b) lower_bound(all(a), (b)) - (a).begin()
#define upp(a, b) upper_bound(all(a), (b)) - (a).begin()
#define endl '\n'
#define IOS() \
ios_base::sync_with_stdio(0); \
cin.tie(0)
typedef long long ll;
typedef pair<int, int> pint;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef vector<pint> vpint;
typedef pair<pint, int> P1;
typedef pair<int, pint> P2;
typedef pair<pint, pint> PP;
static const ll maxLL = (ll)1 << 62;
const ll MOD = 1000000007;
const ll INF = 1e18;
int N;
int h[100010];
int dp[100010];
signed main() {
IOS();
//(1ll<<N)シフト演算のオーバーフローに気をつける
cin >> N;
rep(i, 1, N + 1) cin >> h[i];
rep(i, 2, N + 1) {
if (i == 2)
dp[i] = dp[i - 1] + abs(h[i] - h[i - 1]);
else {
dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]),
dp[i - 2] + abs(h[i] - h[i - 2]));
}
}
cout << dp[N] << endl;
return 0;
} | [
"literal.number.change",
"control_flow.branch.if.condition.change"
] | 956,974 | 956,975 | u693027786 | cpp |
p03160 | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(c) c.begin(), c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
template <class S, class T>
ostream &operator<<(ostream &o, const pair<S, T> &p) {
return o << "(" << p.fs << "," << p.sc << ")";
}
template <class T> ostream &operator<<(ostream &o, const vector<T> &vc) {
o << "{";
for (const T &v : vc)
o << v << ",";
o << "}";
return o;
}
using ll = long long;
template <class T> using V = vector<T>;
template <class T> using VV = vector<vector<T>>;
int main() {
int N;
cin >> N;
V<int> a(N);
rep(i, N) cin >> a[i];
int inf = 1e9;
V<int> dp(N + 1, inf);
dp[0] = 0;
rep(i, N) {
rep1(t, 2) {
int j = i + t;
if (j <= N)
chmin(dp[j], dp[i] + abs(a[i] - a[j]));
}
}
cout << dp[N] << endl;
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define all(c) c.begin(), c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
template <class S, class T>
ostream &operator<<(ostream &o, const pair<S, T> &p) {
return o << "(" << p.fs << "," << p.sc << ")";
}
template <class T> ostream &operator<<(ostream &o, const vector<T> &vc) {
o << "{";
for (const T &v : vc)
o << v << ",";
o << "}";
return o;
}
using ll = long long;
template <class T> using V = vector<T>;
template <class T> using VV = vector<vector<T>>;
int main() {
int N;
cin >> N;
V<int> a(N);
rep(i, N) cin >> a[i];
int inf = 1e9;
V<int> dp(N + 1, inf);
dp[0] = 0;
rep(i, N) {
rep1(t, 2) {
int j = i + t;
if (j < N)
chmin(dp[j], dp[i] + abs(a[i] - a[j]));
}
}
cout << dp[N - 1] << endl;
} | [
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 956,980 | 956,981 | u309470177 | cpp |
p03160 | #include <bits/stdc++.h>
#define maxn 505050
using namespace std;
typedef long long ll;
ll dp[maxn], a[maxn], n;
int main() {
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
dp[1] = 0;
dp[2] = abs(dp[2] - dp[1]);
for (int i = 3; i <= n; i++)
dp[i] =
min(dp[i - 2] + abs(a[i] - a[i - 2]), dp[i - 1] + abs(a[i] - a[i - 1]));
cout << dp[n] << endl;
return 0;
} | #include <bits/stdc++.h>
#define maxn 505050
using namespace std;
typedef long long ll;
ll dp[maxn], a[maxn], n;
int main() {
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
dp[1] = 0;
dp[2] = abs(a[2] - a[1]);
for (int i = 3; i <= n; i++)
dp[i] =
min(dp[i - 2] + abs(a[i] - a[i - 2]), dp[i - 1] + abs(a[i] - a[i - 1]));
cout << dp[n] << endl;
return 0;
}
| [
"assignment.value.change",
"identifier.change",
"call.arguments.change",
"expression.operation.binary.change"
] | 956,984 | 956,985 | u797074342 | cpp |
p03161 | #include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 1;
vector<int> v(N, 0);
vector<int> memo(N, -1);
int cost(int pos, int n, int x) {
if (memo[pos] != -1)
return memo[pos];
else if (pos == n)
return 0;
else {
int min_cost = INT_MAX;
int curr_cost = 0;
for (int k = pos + 1; k <= (n, pos + x); k++) {
curr_cost = abs(v[pos] - v[k]) + cost(k, n, x);
min_cost = min(curr_cost, min_cost);
}
memo[pos] = min_cost;
return memo[pos];
}
}
int main() {
int n, x;
cin >> n >> x;
for (int i = 1; i != n + 1; i++)
cin >> v[i];
cout << cost(1, n, x) << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 1;
vector<int> v(N, 0);
vector<int> memo(N, -1);
int cost(int pos, int n, int x) {
if (memo[pos] != -1)
return memo[pos];
else if (pos == n)
return 0;
else {
int min_cost = INT_MAX;
int curr_cost = 0;
for (int k = pos + 1; k <= min(n, pos + x); k++) {
curr_cost = abs(v[pos] - v[k]) + cost(k, n, x);
min_cost = min(curr_cost, min_cost);
}
memo[pos] = min_cost;
return memo[pos];
}
}
int main() {
int n, x;
cin >> n >> x;
for (int i = 1; i != n + 1; i++)
cin >> v[i];
cout << cost(1, n, x) << endl;
return 0;
} | [
"call.add",
"control_flow.branch.if.condition.change"
] | 956,986 | 956,987 | u018679195 | cpp |
p03161 | #include <bits/stdc++.h>
using namespace std;
#define Me3za() \
ios_base::sync_with_stdio(0); \
cout.tie(0); \
cin.tie(0); \
srand(time(NULL))
#define endl "\n"
int n, k;
int l;
int arr[100005];
long long mem[100005];
long long solve(int i, long long cur) {
if (i >= n - 1)
return 0;
if (mem[i] != -1)
return mem[i];
mem[i] = LLONG_MAX;
for (int j = 1; j <= min(k, n - i); j++) {
/* if(i+j>=n){
return 0;
}*/
long long sol = solve(i + j, arr[i + j]) + abs(cur - arr[i + j]);
// cout<<i<<" "<<sol<<" "<<i+j<<" "<<min(k,n-i)<<endl;
mem[i] = min(sol, mem[i]);
}
return mem[i];
}
int main() {
Me3za();
cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
memset(mem, -1, sizeof mem);
cout << solve(0, arr[0]);
}
| #include <bits/stdc++.h>
using namespace std;
#define Me3za() \
ios_base::sync_with_stdio(0); \
cout.tie(0); \
cin.tie(0); \
srand(time(NULL))
#define endl "\n"
int n, k;
int l;
int arr[100005];
long long mem[100005];
long long solve(int i, long long cur) {
if (i >= n - 1)
return 0;
if (mem[i] != -1)
return mem[i];
mem[i] = LLONG_MAX;
for (int j = 1; i + j <= min(i + k, n - 1); j++) {
long long sol = solve(i + j, arr[i + j]) + abs(cur - arr[i + j]);
mem[i] = min(sol, mem[i]);
}
return mem[i];
}
int main() {
Me3za();
cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
memset(mem, -1, sizeof mem);
cout << solve(0, arr[0]);
}
| [
"control_flow.loop.for.condition.change",
"identifier.replace.remove",
"literal.replace.add",
"call.arguments.change",
"expression.operation.binary.change"
] | 956,990 | 956,991 | u018679195 | cpp |
p03161 | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww {
cww() {
ios::sync_with_stdio(false);
cin.tie(0);
}
} star;
const long long INF = numeric_limits<long long>::max();
long long h[110000];
long long dp[110000];
int main()
{
int n, k;
cin >> n >> k;
h[0] = 0;
rep(i, n) { cin >> h[i + 1]; }
dp[0] = 0;
dp[1] = 0;
for (int i = 1; i <= n; i++) {
dp[i] = 100000000;
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j < k + 1; j++) {
if (i - j < 1)
continue;
dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
}
}
cout << dp[n] << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww {
cww() {
ios::sync_with_stdio(false);
cin.tie(0);
}
} star;
const long long INF = numeric_limits<long long>::max();
long long h[110000];
long long dp[110000];
int main()
{
int n, k;
cin >> n >> k;
h[0] = 0;
rep(i, n) { cin >> h[i + 1]; }
dp[0] = 0;
dp[1] = 0;
for (int i = 2; i <= n; i++) {
dp[i] = 1001001001;
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j < k + 1; j++) {
if (i - j < 1)
continue;
dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
}
}
cout << dp[n] << endl;
return 0;
}
| [
"literal.number.change",
"variable_declaration.value.change",
"control_flow.loop.for.initializer.change",
"expression.off_by_one",
"assignment.value.change"
] | 957,000 | 957,001 | u818349438 | cpp |
p03161 | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww {
cww() {
ios::sync_with_stdio(false);
cin.tie(0);
}
} star;
const long long INF = numeric_limits<long long>::max();
long long h[110000];
long long dp[110000];
int main()
{
int n, k;
cin >> n >> k;
h[0] = 0;
rep(i, n) { cin >> h[i + 1]; }
dp[0] = 0;
dp[1] = 0;
for (int i = 2; i <= n; i++) {
dp[i] = 100000000;
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j < k + 1; j++) {
if (i - j < 0)
continue;
dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
}
}
cout << dp[n] << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww {
cww() {
ios::sync_with_stdio(false);
cin.tie(0);
}
} star;
const long long INF = numeric_limits<long long>::max();
long long h[110000];
long long dp[110000];
int main()
{
int n, k;
cin >> n >> k;
h[0] = 0;
rep(i, n) { cin >> h[i + 1]; }
dp[0] = 0;
dp[1] = 0;
for (int i = 2; i <= n; i++) {
dp[i] = 1001001001;
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j < k + 1; j++) {
if (i - j < 1)
continue;
dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
}
}
cout << dp[n] << endl;
return 0;
}
| [
"literal.number.change",
"assignment.value.change",
"control_flow.branch.if.condition.change"
] | 957,002 | 957,001 | u818349438 | cpp |
p03161 | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww {
cww() {
ios::sync_with_stdio(false);
cin.tie(0);
}
} star;
int h[110000];
int dp[110000];
const int INF = 1001001001;
int main()
{
int n, k;
cin >> n >> k;
rep(i, n) { cin >> h[i]; }
dp[1] = 0;
for (int i = 2; i <= n; i++) {
dp[i] = INF;
}
for (int i = 2; i <= n; i++) {
for (int j = k; j >= 1; j--) {
if (i - j == 0)
continue;
dp[i] = min(dp[i], dp[i - j] + abs(h[i - 1] - h[i - j - 1]));
}
}
cout << dp[n] << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww {
cww() {
ios::sync_with_stdio(false);
cin.tie(0);
}
} star;
int h[110000];
int dp[110000];
const int INF = 1001001001;
int main()
{
int n, k;
cin >> n >> k;
rep(i, n) { cin >> h[i]; }
dp[1] = 0;
for (int i = 2; i <= n; i++) {
dp[i] = INF;
}
for (int i = 2; i <= n; i++) {
for (int j = k; j >= 1; j--) {
if (i - j <= 0)
continue;
dp[i] = min(dp[i], dp[i - j] + abs(h[i - 1] - h[i - j - 1]));
}
}
cout << dp[n] << endl;
return 0;
}
| [
"expression.operator.compare.change",
"control_flow.branch.if.condition.change"
] | 957,004 | 957,005 | u818349438 | cpp |
p03161 | #include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define ll long long int
#define ld long double
#define MAX 100000
int main() {
ll n, k;
cin >> n >> k;
ll a1, i;
vector<ll> a;
for (i = 0; i < n; i++) {
cin >> a1;
a.push_back(a1);
}
ll dp[n];
for (i = 0; i < n; i++) {
dp[i] = MAX;
}
dp[0] = 0;
for (i = 1; i < n; i++) {
for (ll j = 1; j <= k; j++) {
if (i >= j) {
dp[i] = min(dp[i - j] + abs(a[i] - a[i - j]), dp[i]);
}
}
}
cout << dp[n - 1] << endl;
}
| #include <bits/stdc++.h>
#include <iostream>
using namespace std;
#define ll long long int
#define ld long double
#define MAX 1000000000
int main() {
ll n, k;
cin >> n >> k;
ll a1, i;
vector<ll> a;
for (i = 0; i < n; i++) {
cin >> a1;
a.push_back(a1);
}
ll dp[n];
for (i = 0; i < n; i++) {
dp[i] = MAX;
}
dp[0] = 0;
for (i = 1; i < n; i++) {
for (ll j = 1; j <= k; j++) {
if (i >= j) {
dp[i] = min(dp[i - j] + abs(a[i] - a[i - j]), dp[i]);
}
}
}
cout << dp[n - 1] << endl;
}
| [
"preprocessor.define.value.change",
"literal.integer.change"
] | 957,010 | 957,011 | u904020199 | cpp |
p03161 | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define sz 100100
ll a[sz];
ll ans[sz];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll n, k;
cin >> n >> k;
for (ll i = 0; i < n; ++i)
cin >> a[i];
ans[0] = 0;
for (ll i = 1; i < n; i++) {
ans[i] = ans[i - 1] + abs(a[i - 1] - a[i]);
for (ll j = i - 2; j >= i - k; j--)
ans[i] = min(ans[i], ans[j] + abs(a[j] - a[i]));
}
cout << ans[n - 1];
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define sz 100100
ll a[sz];
ll ans[sz];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll n, k;
cin >> n >> k;
for (ll i = 0; i < n; ++i)
cin >> a[i];
ans[0] = 0;
for (ll i = 1; i < n; i++) {
ans[i] = ans[i - 1] + abs(a[i - 1] - a[i]);
for (ll j = i - 2; j >= i - k && j > -1; j--)
ans[i] = min(ans[i], ans[j] + abs(a[j] - a[i]));
}
cout << ans[n - 1];
return 0;
} | [
"control_flow.loop.for.condition.change"
] | 957,017 | 957,018 | u155834868 | cpp |
p03161 | #include <algorithm>
#include <cmath>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define REP(i, n) for (lint i{}, i##_len = (n); i < i##_len; ++i)
#define DOUBLE_LOOP(i, h, j, w) \
for (lint i{}; i < (lint)(h); ++i) \
for (lint j{}; j < (lint)(w); ++j)
#define DOUBLE_LOOP2(i, j, n) \
for (lint i{}; i < (lint)(n - 1); ++i) \
for (lint j{i + 1}; j < (lint)(n); ++j)
#define SZ(x) ((lint)(x).size())
using lint = long long;
lint N, M, H, W;
using namespace std;
const long long INF{1LL << 60};
const long double PI{3.1415926535897932};
const long long NUM97{1000000007};
template <class T> inline bool chmax(T &x, T y) {
if (x < y) {
x = y;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &x, T y) {
if (x > y) {
x = y;
return 1;
}
return 0;
}
std::vector<std::string> field;
std::vector<std::vector<bool>> seen(H, std::vector<bool>(W));
const std::vector<int> dx{1, 0, -1, 0};
const std::vector<int> dy{0, 1, 0, -1};
lint DP_1_Memoization(lint i, std::vector<lint> dp, std::vector<lint> h) {
if (dp[i] < INF) {
return dp[i];
}
if (i == 0) {
return 0;
}
lint ans{INF};
chmin(ans, DP_1_Memoization(i - 1, dp, h) + std::abs(h[i] - h[i - 1]));
if (i > 1) {
chmin(ans, DP_1_Memoization(i - 2, dp, h) + std::abs(h[i] - h[i - 2]));
}
return dp[i] = ans;
} // memoization
void DP_1() {
lint n;
std::cin >> n;
std::vector<lint> dp;
dp.resize(N);
for (auto &r : dp)
r = INF;
std::vector<lint> h;
h.resize(n);
for (auto &r : h)
std::cin >> r;
dp[0] = 0;
for (int i = 1; i < N; ++i) {
chmin(dp[i], dp[i - 1] + std::abs(h[i] - h[i - 1]));
if (i > 1) {
chmin(dp[i], dp[i - 2] + std::abs(h[i] - h[i - 2]));
}
}
std::cout << dp[N - 1] << DP_1_Memoization(N - 1, dp, h) << std::endl;
}
void DP_stairs() {
lint N, M;
std::cin >> N >> M;
std::vector<bool> issafe(N + 1, true);
std::vector<lint> dp(N + 1, 0);
for (int i = 0; i < M; ++i) {
int a;
cin >> a;
issafe[a] = false;
}
dp[0] = 1;
if (issafe[1] == true)
dp[1] = 1;
for (int i = 2; i <= N; ++i) {
if (issafe[i - 1])
dp[i] += dp[i - 1];
if (issafe[i - 2])
dp[i] += dp[i - 2];
dp[i] %= NUM97;
}
std::cout << dp[N] << std::endl;
}
int main() {
lint n, K;
std::cin >> n >> K;
std::vector<lint> dp;
dp.resize(n);
for (auto &r : dp)
r = INF;
std::vector<lint> h;
h.resize(n);
for (auto &r : h)
std::cin >> r;
dp[0] = 0;
for (int i = 0; i < n; ++i) {
for (int j = 1; j <= K; ++j) {
chmin(dp[i + j], dp[i] + std::abs(h[i] - h[i + j]));
}
}
std::cout << dp[n - 1] << std::endl;
} | #include <algorithm>
#include <cmath>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define REP(i, n) for (lint i{}, i##_len = (n); i < i##_len; ++i)
#define DOUBLE_LOOP(i, h, j, w) \
for (lint i{}; i < (lint)(h); ++i) \
for (lint j{}; j < (lint)(w); ++j)
#define DOUBLE_LOOP2(i, j, n) \
for (lint i{}; i < (lint)(n - 1); ++i) \
for (lint j{i + 1}; j < (lint)(n); ++j)
#define SZ(x) ((lint)(x).size())
using lint = long long;
lint N, M, H, W;
using namespace std;
const long long INF{1LL << 60};
const long double PI{3.1415926535897932};
const long long NUM97{1000000007};
template <class T> inline bool chmax(T &x, T y) {
if (x < y) {
x = y;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &x, T y) {
if (x > y) {
x = y;
return 1;
}
return 0;
}
std::vector<std::string> field;
std::vector<std::vector<bool>> seen(H, std::vector<bool>(W));
const std::vector<int> dx{1, 0, -1, 0};
const std::vector<int> dy{0, 1, 0, -1};
lint DP_1_Memoization(lint i, std::vector<lint> dp, std::vector<lint> h) {
if (dp[i] < INF) {
return dp[i];
}
if (i == 0) {
return 0;
}
lint ans{INF};
chmin(ans, DP_1_Memoization(i - 1, dp, h) + std::abs(h[i] - h[i - 1]));
if (i > 1) {
chmin(ans, DP_1_Memoization(i - 2, dp, h) + std::abs(h[i] - h[i - 2]));
}
return dp[i] = ans;
} // memoization
void DP_1() {
lint n;
std::cin >> n;
std::vector<lint> dp;
dp.resize(N);
for (auto &r : dp)
r = INF;
std::vector<lint> h;
h.resize(n);
for (auto &r : h)
std::cin >> r;
dp[0] = 0;
for (int i = 1; i < N; ++i) {
chmin(dp[i], dp[i - 1] + std::abs(h[i] - h[i - 1]));
if (i > 1) {
chmin(dp[i], dp[i - 2] + std::abs(h[i] - h[i - 2]));
}
}
std::cout << dp[N - 1] << DP_1_Memoization(N - 1, dp, h) << std::endl;
}
void DP_stairs() {
lint N, M;
std::cin >> N >> M;
std::vector<bool> issafe(N + 1, true);
std::vector<lint> dp(N + 1, 0);
for (int i = 0; i < M; ++i) {
int a;
cin >> a;
issafe[a] = false;
}
dp[0] = 1;
if (issafe[1] == true)
dp[1] = 1;
for (int i = 2; i <= N; ++i) {
if (issafe[i - 1])
dp[i] += dp[i - 1];
if (issafe[i - 2])
dp[i] += dp[i - 2];
dp[i] %= NUM97;
}
std::cout << dp[N] << std::endl;
}
int main() {
lint n, K;
std::cin >> n >> K;
std::vector<lint> dp;
dp.resize(100000);
for (auto &r : dp)
r = INF;
std::vector<lint> h;
h.resize(1000000);
for (auto &r : h)
std::cin >> r;
dp[0] = 0;
for (int i = 0; i < n; ++i) {
for (int j = 1; j <= K; ++j) {
chmin(dp[i + j], dp[i] + std::abs(h[i] - h[i + j]));
}
}
std::cout << dp[n - 1] << std::endl;
} | [
"identifier.replace.remove",
"literal.replace.add",
"call.arguments.change"
] | 957,028 | 957,029 | u917678406 | cpp |
p03161 | #include <algorithm>
#include <cmath>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define REP(i, n) for (lint i{}, i##_len = (n); i < i##_len; ++i)
#define DOUBLE_LOOP(i, h, j, w) \
for (lint i{}; i < (lint)(h); ++i) \
for (lint j{}; j < (lint)(w); ++j)
#define DOUBLE_LOOP2(i, j, n) \
for (lint i{}; i < (lint)(n - 1); ++i) \
for (lint j{i + 1}; j < (lint)(n); ++j)
#define SZ(x) ((lint)(x).size())
using lint = long long;
lint N, M, H, W;
using namespace std;
const long long INF{1LL << 60};
const long double PI{3.1415926535897932};
const long long NUM97{1000000007};
template <class T> inline bool chmax(T &x, T y) {
if (x < y) {
x = y;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &x, T y) {
if (x > y) {
x = y;
return 1;
}
return 0;
}
std::vector<std::string> field;
std::vector<std::vector<bool>> seen(H, std::vector<bool>(W));
const std::vector<int> dx{1, 0, -1, 0};
const std::vector<int> dy{0, 1, 0, -1};
lint DP_1_Memoization(lint i, std::vector<lint> dp, std::vector<lint> h) {
if (dp[i] < INF) {
return dp[i];
}
if (i == 0) {
return 0;
}
lint ans{INF};
chmin(ans, DP_1_Memoization(i - 1, dp, h) + std::abs(h[i] - h[i - 1]));
if (i > 1) {
chmin(ans, DP_1_Memoization(i - 2, dp, h) + std::abs(h[i] - h[i - 2]));
}
return dp[i] = ans;
} // memoization
void DP_1() {
lint n;
std::cin >> n;
std::vector<lint> dp;
dp.resize(N);
for (auto &r : dp)
r = INF;
std::vector<lint> h;
h.resize(n);
for (auto &r : h)
std::cin >> r;
dp[0] = 0;
for (int i = 1; i < N; ++i) {
chmin(dp[i], dp[i - 1] + std::abs(h[i] - h[i - 1]));
if (i > 1) {
chmin(dp[i], dp[i - 2] + std::abs(h[i] - h[i - 2]));
}
}
std::cout << dp[N - 1] << DP_1_Memoization(N - 1, dp, h) << std::endl;
}
void DP_stairs() {
lint N, M;
std::cin >> N >> M;
std::vector<bool> issafe(N + 1, true);
std::vector<lint> dp(N + 1, 0);
for (int i = 0; i < M; ++i) {
int a;
cin >> a;
issafe[a] = false;
}
dp[0] = 1;
if (issafe[1] == true)
dp[1] = 1;
for (int i = 2; i <= N; ++i) {
if (issafe[i - 1])
dp[i] += dp[i - 1];
if (issafe[i - 2])
dp[i] += dp[i - 2];
dp[i] %= NUM97;
}
std::cout << dp[N] << std::endl;
}
int main() {
lint n, K;
std::cin >> n >> K;
std::vector<lint> dp;
dp.resize(n);
for (auto &r : dp)
r = INF;
std::vector<lint> h;
h.resize(n);
for (auto &r : h)
std::cin >> r;
dp[0] = 0;
for (int i = 0; i < n; ++i) {
for (int j = 1; j <= K; ++j) {
chmin(dp[i + j], dp[i] + std::abs(h[i] - h[i - j]));
}
}
std::cout << dp[n - 1] << std::endl;
} | #include <algorithm>
#include <cmath>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define REP(i, n) for (lint i{}, i##_len = (n); i < i##_len; ++i)
#define DOUBLE_LOOP(i, h, j, w) \
for (lint i{}; i < (lint)(h); ++i) \
for (lint j{}; j < (lint)(w); ++j)
#define DOUBLE_LOOP2(i, j, n) \
for (lint i{}; i < (lint)(n - 1); ++i) \
for (lint j{i + 1}; j < (lint)(n); ++j)
#define SZ(x) ((lint)(x).size())
using lint = long long;
lint N, M, H, W;
using namespace std;
const long long INF{1LL << 60};
const long double PI{3.1415926535897932};
const long long NUM97{1000000007};
template <class T> inline bool chmax(T &x, T y) {
if (x < y) {
x = y;
return 1;
}
return 0;
}
template <class T> inline bool chmin(T &x, T y) {
if (x > y) {
x = y;
return 1;
}
return 0;
}
std::vector<std::string> field;
std::vector<std::vector<bool>> seen(H, std::vector<bool>(W));
const std::vector<int> dx{1, 0, -1, 0};
const std::vector<int> dy{0, 1, 0, -1};
lint DP_1_Memoization(lint i, std::vector<lint> dp, std::vector<lint> h) {
if (dp[i] < INF) {
return dp[i];
}
if (i == 0) {
return 0;
}
lint ans{INF};
chmin(ans, DP_1_Memoization(i - 1, dp, h) + std::abs(h[i] - h[i - 1]));
if (i > 1) {
chmin(ans, DP_1_Memoization(i - 2, dp, h) + std::abs(h[i] - h[i - 2]));
}
return dp[i] = ans;
} // memoization
void DP_1() {
lint n;
std::cin >> n;
std::vector<lint> dp;
dp.resize(N);
for (auto &r : dp)
r = INF;
std::vector<lint> h;
h.resize(n);
for (auto &r : h)
std::cin >> r;
dp[0] = 0;
for (int i = 1; i < N; ++i) {
chmin(dp[i], dp[i - 1] + std::abs(h[i] - h[i - 1]));
if (i > 1) {
chmin(dp[i], dp[i - 2] + std::abs(h[i] - h[i - 2]));
}
}
std::cout << dp[N - 1] << DP_1_Memoization(N - 1, dp, h) << std::endl;
}
void DP_stairs() {
lint N, M;
std::cin >> N >> M;
std::vector<bool> issafe(N + 1, true);
std::vector<lint> dp(N + 1, 0);
for (int i = 0; i < M; ++i) {
int a;
cin >> a;
issafe[a] = false;
}
dp[0] = 1;
if (issafe[1] == true)
dp[1] = 1;
for (int i = 2; i <= N; ++i) {
if (issafe[i - 1])
dp[i] += dp[i - 1];
if (issafe[i - 2])
dp[i] += dp[i - 2];
dp[i] %= NUM97;
}
std::cout << dp[N] << std::endl;
}
int main() {
lint n, K;
std::cin >> n >> K;
std::vector<lint> dp;
dp.resize(100000);
for (auto &r : dp)
r = INF;
std::vector<lint> h;
h.resize(1000000);
for (auto &r : h)
std::cin >> r;
dp[0] = 0;
for (int i = 0; i < n; ++i) {
for (int j = 1; j <= K; ++j) {
chmin(dp[i + j], dp[i] + std::abs(h[i] - h[i + j]));
}
}
std::cout << dp[n - 1] << std::endl;
} | [
"identifier.replace.remove",
"literal.replace.add",
"call.arguments.change",
"misc.opposites",
"expression.operator.arithmetic.change",
"variable_access.subscript.index.change",
"expression.operation.binary.change"
] | 957,030 | 957,029 | u917678406 | cpp |
p03161 | #include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <set>
#include <vector>
#define vi vector<int>
#define tests \
int t; \
cin >> t; \
while (t--)
#define ll long long
#define vll vector<long long>
#define srt(v) sort(v.begin(), v.end())
#define srtg(v) sort(v.begin(), v.end(), greater<int>())
#define FOR(k, n) for (int k = 0; k < n; k++)
using namespace std;
char nums[10] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
char alphsl[26] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I',
'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R',
'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
const ll MOD = 1000000007;
char alphs[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
void solve() {
int n, k;
cin >> n >> k;
vi v(n);
for (auto &x : v)
cin >> x;
vll dp(n);
if (k >= n - 1) {
cout << abs(v[0] - v[n - 1]) << endl;
}
for (int i = n - 1; i >= n - k; i--) {
dp[i] = abs(v[i] - v[n - 1]);
return;
}
for (int i = n - k - 1; i >= 0; i--) {
ll miny = abs(v[i] - v[i + 1]) + dp[i + 1];
for (int j = 1; j <= k; j++) {
miny = min(miny, abs(v[i] - v[i + j]) + dp[i + j]);
}
dp[i] = miny;
}
cout << dp[0] << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
solve();
return 0;
}
| #include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <set>
#include <vector>
#define vi vector<int>
#define tests \
int t; \
cin >> t; \
while (t--)
#define ll long long
#define vll vector<long long>
#define srt(v) sort(v.begin(), v.end())
#define srtg(v) sort(v.begin(), v.end(), greater<int>())
#define FOR(k, n) for (int k = 0; k < n; k++)
using namespace std;
char nums[10] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
char alphsl[26] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I',
'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R',
'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
const ll MOD = 1000000007;
char alphs[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
void solve() {
int n, k;
cin >> n >> k;
vi v(n);
for (auto &x : v)
cin >> x;
vll dp(n);
if (k >= n - 1) {
cout << abs(v[0] - v[n - 1]) << endl;
return;
}
for (int i = n - 1; i >= n - k; i--) {
dp[i] = abs(v[i] - v[n - 1]);
}
for (int i = n - k - 1; i >= 0; i--) {
ll miny = abs(v[i] - v[i + 1]) + dp[i + 1];
for (int j = 1; j <= k; j++) {
miny = min(miny, abs(v[i] - v[i + j]) + dp[i + j]);
}
dp[i] = miny;
}
cout << dp[0] << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
solve();
return 0;
}
| [
"control_flow.return.add"
] | 957,032 | 957,033 | u955610038 | cpp |
p03161 | #include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <set>
#include <vector>
#define vi vector<int>
#define tests \
int t; \
cin >> t; \
while (t--)
#define ll long long
#define vll vector<long long>
#define srt(v) sort(v.begin(), v.end())
#define srtg(v) sort(v.begin(), v.end(), greater<int>())
#define FOR(k, n) for (int k = 0; k < n; k++)
using namespace std;
char nums[10] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
char alphsl[26] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I',
'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R',
'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
const ll MOD = 1000000007;
char alphs[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
void solve() {
int n, k;
cin >> n >> k;
vi v(n);
for (auto &x : v)
cin >> x;
vll dp(n);
if (k >= n - 1) {
cout << abs(v[0] - v[n - 1]) << endl;
}
for (int i = n - 1; i >= n - k; i--) {
dp[i] = abs(v[i] - v[n - 1]);
}
for (int i = n - k - 1; i >= 0; i--) {
ll miny = abs(v[i] - v[i + 1]) + dp[i + 1];
for (int j = 1; j <= k; j++) {
miny = min(miny, abs(v[i] - v[i + j]) + dp[i + j]);
}
dp[i] = miny;
}
cout << dp[0] << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
solve();
return 0;
} | #include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <set>
#include <vector>
#define vi vector<int>
#define tests \
int t; \
cin >> t; \
while (t--)
#define ll long long
#define vll vector<long long>
#define srt(v) sort(v.begin(), v.end())
#define srtg(v) sort(v.begin(), v.end(), greater<int>())
#define FOR(k, n) for (int k = 0; k < n; k++)
using namespace std;
char nums[10] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
char alphsl[26] = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I',
'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R',
'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
const ll MOD = 1000000007;
char alphs[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
void solve() {
int n, k;
cin >> n >> k;
vi v(n);
for (auto &x : v)
cin >> x;
vll dp(n);
if (k >= n - 1) {
cout << abs(v[0] - v[n - 1]) << endl;
return;
}
for (int i = n - 1; i >= n - k; i--) {
dp[i] = abs(v[i] - v[n - 1]);
}
for (int i = n - k - 1; i >= 0; i--) {
ll miny = abs(v[i] - v[i + 1]) + dp[i + 1];
for (int j = 1; j <= k; j++) {
miny = min(miny, abs(v[i] - v[i + j]) + dp[i + j]);
}
dp[i] = miny;
}
cout << dp[0] << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
solve();
return 0;
}
| [
"control_flow.return.add"
] | 957,034 | 957,033 | u955610038 | cpp |
p03161 | #include <bits/stdc++.h>
using namespace std;
#define rep(i, k, n) for (int i = (int)(k); i < (int)(n); i++)
int main() {
int N, K;
cin >> N >> K;
vector<int> dp(N), c(N);
rep(i, 0, N) cin >> c[i];
dp[0] = 0;
rep(i, 1, K) dp[i] = abs(c[0] - c[i]);
rep(i, K, N) {
dp[i] = dp[i - 1] + abs(c[i - 1] - c[i]);
rep(j, 1, K) dp[i] = min(dp[i], dp[i - j - 1] + abs(c[i - j - 1] - c[i]));
}
cout << dp[N - 1] << endl;
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, k, n) for (int i = (int)(k); i < (int)(n); i++)
int main() {
int N, K;
cin >> N >> K;
vector<int> dp(100005), c(N);
rep(i, 0, N) cin >> c[i];
dp[0] = 0;
rep(i, 1, K) dp[i] = abs(c[0] - c[i]);
rep(i, K, N) {
dp[i] = dp[i - 1] + abs(c[i - 1] - c[i]);
rep(j, 1, K) dp[i] = min(dp[i], dp[i - j - 1] + abs(c[i - j - 1] - c[i]));
}
cout << dp[N - 1] << endl;
} | [] | 957,039 | 957,040 | u882098164 | cpp |
p03161 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
int arr[n], cost[n] = {0};
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
for (int i = 1; i < n; i++) {
if (k > 0) {
int mini = INT_MAX;
for (int j = 1; j <= min(k, n - 1); j++) {
mini = min(mini, cost[i - j] + abs(arr[i] - arr[i - j]));
}
cost[i] = mini;
}
}
cout << cost[n - 1];
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
int arr[n], cost[n] = {0};
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
for (int i = 1; i < n; i++) {
if (k > 0) {
int mini = INT_MAX;
for (int j = 1; j <= min(k, i); j++) {
mini = min(mini, cost[i - j] + abs(arr[i] - arr[i - j]));
}
cost[i] = mini;
}
}
cout << cost[n - 1];
}
| [
"control_flow.branch.if.condition.change",
"control_flow.loop.for.condition.change",
"expression.operation.binary.remove"
] | 957,046 | 957,047 | u231101364 | cpp |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.