buggy_code
stringlengths
11
625k
fixed_code
stringlengths
17
625k
bug_type
stringlengths
2
4.45k
language
int64
0
8
token_count
int64
5
200k
#include <bits/stdc++.h> using namespace std; int main() { string s; int i, j, k; cin >> s; int len = s.length(); stack<char> mystk; for (i = 0; i < len; i++) { if (s[i] == 'B') { if (!mystk.empty()) { mystk.pop(); } } else mystk.push(s[i]); } k = mystk.size(); fo...
#include <bits/stdc++.h> using namespace std; int main() { string s; int i, j, k; cin >> s; int len = s.length(); vector<char> mystk; for (i = 0; i < len; i++) { if (s[i] == 'B') { if (!mystk.empty()) { mystk.pop_back(); } } else mystk.push_back(s[i]); } k = mystk.s...
[["-", 0, 14, 8, 9, 0, 43, 39, 344, 141, 78], ["+", 0, 14, 8, 9, 0, 43, 39, 344, 141, 78], ["-", 64, 9, 0, 1, 0, 2, 63, 118, 119, 120], ["+", 64, 9, 0, 1, 0, 2, 63, 118, 119, 120], ["-", 75, 76, 0, 1, 0, 2, 63, 118, 119, 120], ["+", 75, 76, 0, 1, 0, 2, 63, 118, 119, 120], ["-", 0, 1, 0, 16, 12, 2, 63, 118, 17, 131], ["...
1
141
#!/usr/bin/ruby arr = [] STDIN.split.each do |char| if char == "B" arr.pop else arr.push char end end STDOUT.print arr.join STDOUT.print "\n"
arr = [] STDIN.gets.chomp.split(//).each do |char| if char == "B" arr.pop else arr.push char end end STDOUT.print arr.join STDOUT.print "\n"
[["+", 0, 652, 486, 652, 486, 652, 486, 652, 735, 22], ["+", 0, 493, 0, 652, 486, 652, 486, 652, 17, 131], ["+", 0, 493, 0, 652, 486, 652, 486, 652, 735, 22], ["+", 36, 36, 0, 493, 0, 652, 486, 652, 17, 131], ["+", 0, 493, 0, 652, 486, 652, 3, 4, 0, 24], ["+", 0, 652, 486, 652, 3, 4, 0, 575, 0, 85], ["+", 0, 493, 0, 65...
4
42
#include <iostream> #include <string> using namespace std; int main() { string s; cin >> s; string ans; for (int i = 0; i < s.length(); i++) { if (s[i] == 'B') { ans.pop_back(); } else { ans += s[i]; } } cout << ans << endl; return 0; }
#include <iostream> #include <string> using namespace std; int main() { string s, ans; cin >> s; for (int i = 0; i < s.length(); i++) { if (s[i] == 'B') { if (!ans.empty()) ans.pop_back(); } else { ans += s[i]; } } cout << ans << endl; return 0; }
[["+", 0, 30, 0, 14, 8, 9, 0, 43, 0, 21], ["+", 0, 30, 0, 14, 8, 9, 0, 43, 49, 22], ["-", 0, 30, 0, 14, 8, 9, 0, 43, 39, 78], ["-", 0, 30, 0, 14, 8, 9, 0, 43, 49, 22], ["-", 0, 30, 0, 14, 8, 9, 0, 43, 0, 35], ["+", 8, 9, 0, 57, 64, 9, 0, 57, 0, 121], ["+", 0, 57, 64, 9, 0, 57, 15, 339, 0, 24], ["+", 64, 9, 0, 57, 15, 3...
1
82
s = input() c = '' for i in s: if i == '0' or i == '1': c += i elif i == 'B' and c != '': c = c.rstrip(c[-1]) print(c)
s = input() c = '' for i in s: if i == '0' or i == '1': c += i elif i == 'B': c = c[:-1] print(c)
[["-", 8, 196, 0, 57, 75, 665, 15, 679, 17, 355], ["-", 0, 57, 75, 665, 15, 679, 12, 666, 0, 22], ["-", 0, 57, 75, 665, 15, 679, 12, 666, 667, 79], ["-", 75, 665, 15, 679, 12, 666, 0, 557, 0, 654], ["-", 75, 665, 15, 679, 12, 666, 0, 557, 0, 655], ["-", 0, 1, 0, 662, 12, 652, 63, 319, 0, 131], ["-", 0, 1, 0, 662, 12, 6...
5
58
//プログラミングコンテスト用テンプレート #define _USE_MATH_DEFINES #include <algorithm> #include <cfloat> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <sstream> #include <stack...
//プログラミングコンテスト用テンプレート #define _USE_MATH_DEFINES #include <algorithm> #include <cfloat> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iostream> #include <map> #include <queue> #include <random> #include <set> #include <sstream> #include <stack...
[["+", 8, 9, 0, 57, 75, 76, 0, 57, 0, 121], ["+", 0, 57, 75, 76, 0, 57, 15, 339, 0, 24], ["+", 15, 339, 51, 16, 31, 16, 31, 69, 28, 22], ["+", 51, 16, 31, 16, 31, 69, 341, 342, 0, 70], ["+", 51, 16, 31, 16, 31, 69, 341, 342, 0, 22], ["+", 51, 16, 31, 16, 31, 69, 341, 342, 0, 73], ["+", 0, 57, 15, 339, 51, 16, 31, 16, 1...
1
271
#define FOR(i, a, b) for (int i = (a); i < (b); i++) #define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--) #define REP(i, n) for (int i = 0; i < (n); i++) #define RREP(i, n) for (int i = (n)-1; i >= 0; i--) #define INF INT_MAX / 3 #define PB push_back #define MP make_pair #define ALL(a) (a).begin(), (a).end() #defi...
#define FOR(i, a, b) for (int i = (a); i < (b); i++) #define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--) #define REP(i, n) for (int i = 0; i < (n); i++) #define RREP(i, n) for (int i = (n)-1; i >= 0; i--) #define INF INT_MAX / 3 #define PB push_back #define MP make_pair #define ALL(a) (a).begin(), (a).end() #defi...
[["+", 0, 99, 8, 9, 0, 100, 0, 57, 0, 121], ["+", 8, 9, 0, 100, 0, 57, 15, 339, 0, 24], ["+", 15, 339, 51, 16, 31, 2, 63, 118, 28, 22], ["+", 15, 339, 51, 16, 31, 2, 63, 118, 17, 131], ["+", 15, 339, 51, 16, 31, 2, 63, 118, 119, 120], ["+", 15, 339, 51, 16, 31, 2, 3, 4, 0, 24], ["+", 15, 339, 51, 16, 31, 2, 3, 4, 0, 25...
1
225
#include <iostream> #include <string> #include <vector> using namespace std; int main() { string s; cin >> s; string out; for (auto &c : s) { switch (c) { case '0': out += "0"; break; case '1': out += "1"; break; case 'B': out.pop_back(); break; } } c...
#include <iostream> #include <string> #include <vector> using namespace std; int main() { string s; cin >> s; string out; for (auto &c : s) { switch (c) { case '0': out += "0"; break; case '1': out += "1"; break; case 'B': if (out.size() > 0) out.pop_back()...
[["+", 0, 99, 8, 9, 0, 100, 0, 57, 0, 121], ["+", 8, 9, 0, 100, 0, 57, 15, 339, 0, 24], ["+", 15, 339, 51, 16, 31, 2, 63, 118, 28, 22], ["+", 15, 339, 51, 16, 31, 2, 63, 118, 17, 131], ["+", 15, 339, 51, 16, 31, 2, 63, 118, 119, 120], ["+", 15, 339, 51, 16, 31, 2, 3, 4, 0, 24], ["+", 15, 339, 51, 16, 31, 2, 3, 4, 0, 25...
1
87
#include <algorithm> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <utility> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> P...
#include <algorithm> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <utility> #include <vector> using namespace std; typedef long long ll; typedef pair<int, int> P...
[["+", 0, 7, 8, 9, 0, 57, 64, 9, 0, 45], ["+", 64, 9, 0, 1, 0, 11, 31, 69, 28, 22], ["+", 0, 1, 0, 11, 31, 69, 341, 342, 0, 70], ["+", 0, 1, 0, 11, 31, 69, 341, 342, 0, 22], ["+", 0, 1, 0, 11, 31, 69, 341, 342, 0, 73], ["+", 0, 57, 64, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 57, 64, 9, 0, 1, 0, 11, 12, 13], ["+", 8, 9, 0, 57...
1
136
#include <iostream> #include <string> using namespace std; int main() { string s; string ans; cin >> s; for (int i = 0; i < s.size(); i++) { if (s[i] == '0') ans.push_back('0'); else if (s[i] == '1') ans.push_back('1'); else if (s[i] == 'B') ans.erase(ans.size() - 1); } cout <...
#include <iostream> #include <string> using namespace std; int main() { string s; string ans; cin >> s; for (int i = 0; i < s.size(); i++) { if (s[i] == '0') { ans.push_back('0'); } else if (s[i] == '1') { ans.push_back('1'); } else if (s[i] == 'B') { if (ans.size() > 0) a...
[["+", 0, 7, 8, 9, 0, 57, 64, 9, 0, 45], ["+", 0, 7, 8, 9, 0, 57, 64, 9, 0, 46], ["+", 0, 57, 75, 76, 0, 57, 64, 9, 0, 45], ["+", 0, 57, 75, 76, 0, 57, 64, 9, 0, 46], ["+", 0, 57, 75, 76, 0, 57, 15, 339, 0, 25], ["+", 75, 76, 0, 57, 64, 9, 0, 57, 0, 121], ["+", 0, 57, 64, 9, 0, 57, 15, 339, 0, 24], ["+", 15, 339, 51, 1...
1
119
#include <bits/stdc++.h> using namespace std; const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1}; const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1}; const int INF = 1e9; const long long LINF = 1e18; const double EPS = 1e-8; #define pb emplace_back #define mk make_pair #define fr first #define sc second #define ll long long #defin...
#include <bits/stdc++.h> using namespace std; const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1}; const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1}; const int INF = 1e9; const long long LINF = 1e18; const double EPS = 1e-8; #define pb emplace_back #define mk make_pair #define fr first #define sc second #define ll long long #defin...
[["-", 64, 9, 0, 1, 0, 11, 31, 69, 28, 22], ["-", 0, 1, 0, 11, 31, 69, 341, 342, 0, 70], ["-", 0, 1, 0, 11, 31, 69, 341, 342, 0, 22], ["-", 0, 1, 0, 11, 31, 69, 341, 342, 0, 73], ["-", 0, 57, 64, 9, 0, 1, 0, 11, 17, 32], ["-", 0, 57, 64, 9, 0, 1, 0, 11, 12, 13], ["-", 75, 76, 0, 57, 64, 9, 0, 1, 0, 35], ["+", 64, 9, 0,...
1
345
#include <algorithm> #include <deque> #include <functional> #include <iostream> #include <list> #include <map> #include <math.h> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdio.h> #include <stdlib.h> #include <string> #include <vector> using namespace std; #define rep(i, n) for (int...
#include <algorithm> #include <deque> #include <functional> #include <iostream> #include <list> #include <map> #include <math.h> #include <queue> #include <set> #include <sstream> #include <stack> #include <stdio.h> #include <stdlib.h> #include <string> #include <vector> using namespace std; #define rep(i, n) for (int...
[["-", 0, 14, 8, 9, 0, 43, 49, 80, 81, 13], ["+", 0, 14, 8, 9, 0, 43, 49, 80, 81, 13], ["-", 0, 11, 31, 69, 28, 2, 3, 4, 0, 13], ["+", 0, 11, 31, 69, 28, 2, 3, 4, 0, 13], ["+", 75, 76, 0, 9, 0, 1, 0, 27, 28, 22], ["+", 75, 76, 0, 9, 0, 1, 0, 27, 17, 68], ["+", 0, 57, 75, 76, 0, 9, 0, 1, 0, 35], ["-", 0, 9, 0, 57, 15, 3...
1
1,235
#include <algorithm> #include <iostream> #include <string> using namespace std; int main() { string s; cin >> s; string a = ""; for (int i = 0; i < s.size(); i++) { if (s[i] == 'B' && a.size()) { a.erase(a.begin() + a.size() - 1); continue; } a += s[i]; } cout << a << endl; return...
#include <algorithm> #include <iostream> #include <string> using namespace std; int main() { string s; cin >> s; string a = ""; for (int i = 0; i < s.size(); i++) { if (s[i] == 'B' && a.size()) { a.erase(a.begin() + a.size() - 1); continue; } else if (s[i] != 'B') a += s[i]; } cou...
[["+", 0, 7, 8, 9, 0, 57, 75, 76, 0, 95], ["+", 8, 9, 0, 57, 75, 76, 0, 57, 0, 121], ["+", 0, 57, 75, 76, 0, 57, 15, 339, 0, 24], ["+", 0, 57, 15, 339, 51, 16, 31, 69, 28, 22], ["+", 15, 339, 51, 16, 31, 69, 341, 342, 0, 70], ["+", 15, 339, 51, 16, 31, 69, 341, 342, 0, 22], ["+", 15, 339, 51, 16, 31, 69, 341, 342, 0, 7...
1
105
#include <algorithm> #include <iostream> #include <string> #include <vector> using namespace std; int main() { string s; vector<char> ans; cin >> s; for (auto &it : s) { if (it == 'B' && ans.size() != 0) ans.pop_back(); else ans.push_back(it); } for (auto &it : ans) { cout << it; ...
#include <algorithm> #include <iostream> #include <string> #include <vector> using namespace std; int main() { string s; vector<char> ans; cin >> s; for (auto &it : s) { if (it == 'B' && ans.size() != 0) ans.pop_back(); if (it != 'B') ans.push_back(it); } for (auto &it : ans) { cou...
[["-", 0, 338, 8, 9, 0, 57, 75, 76, 0, 95], ["+", 8, 9, 0, 338, 8, 9, 0, 57, 0, 121], ["+", 0, 338, 8, 9, 0, 57, 15, 339, 0, 24], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 31, 22], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 79], ["+", 0, 57, 15, 339, 51, 16, 12, 103, 0, 104], ["+", 0, 57, 15, 339, 51, 16, 12, 103, 0, 125], ["+"...
1
92
#include <iostream> using namespace std; int main() { string a, b = "", c = "0", d = "1", e = "b"; cin >> a; for (int i = 0; i < a.size(); i++) { a[i] == c[0] ? b += "0" : a[i] == d[0] ? b += "1" : b = b.erase(b.size() - 1); } cout << b << endl; }
#include <iostream> using namespace std; int main() { string a, b = "", c = "0", d = "1", e = "b"; cin >> a; for (int i = 0; i < a.size(); i++) { a[i] == c[0] ? b += "0" : a[i] == d[0] ? b += "1" : b.size() > 0 ? b = b.erase(b.size() - 1) : a = a; } cout << b << endl; }
[["+", 75, 41, 15, 16, 31, 2, 63, 118, 17, 131], ["+", 75, 41, 15, 16, 31, 2, 63, 118, 119, 120], ["+", 75, 41, 15, 16, 31, 2, 3, 4, 0, 24], ["+", 75, 41, 15, 16, 31, 2, 3, 4, 0, 25], ["+", 0, 41, 75, 41, 75, 41, 15, 16, 17, 47], ["+", 0, 41, 75, 41, 75, 41, 15, 16, 12, 13], ["+", 0, 1, 0, 41, 75, 41, 75, 41, 0, 101], ...
1
115
#include <bits/stdc++.h> #define range(i, a, b) for (int i = (a); i < (b); i++) #define rep(i, b) range(i, 0, b) #define itrep(it, a) for (it = (a).begin(); it != (a).end(); it++) #define all(a) (a).begin(), (a).end() #define debug(x) cout << "debug " << x << endl; #define INF (1 << 30) using namespace std; int main()...
#include <bits/stdc++.h> #define range(i, a, b) for (int i = (a); i < (b); i++) #define rep(i, b) range(i, 0, b) #define itrep(it, a) for (it = (a).begin(); it != (a).end(); it++) #define all(a) (a).begin(), (a).end() #define debug(x) cout << "debug " << x << endl; #define INF (1 << 30) using namespace std; int main()...
[["+", 0, 30, 0, 14, 8, 9, 0, 7, 0, 88], ["+", 0, 30, 0, 14, 8, 9, 0, 7, 0, 24], ["+", 0, 14, 8, 9, 0, 7, 10, 43, 39, 40], ["+", 8, 9, 0, 7, 10, 43, 49, 50, 49, 22], ["+", 8, 9, 0, 7, 10, 43, 49, 50, 0, 32], ["+", 49, 50, 51, 16, 31, 2, 63, 118, 28, 22], ["+", 49, 50, 51, 16, 31, 2, 63, 118, 17, 131], ["+", 49, 50, 51,...
1
153
#include <iostream> #include <string> using namespace std; int main() { string s, r; cin >> s; for (int i = 0; i < s.size(); i++) { if (s[i] == 'B' && r.size() != 0) r.erase(r.size() - 1); else r = r + s[i]; } cout << r << endl; return 0; }
#include <iostream> #include <string> using namespace std; int main() { string s, r; cin >> s; for (int i = 0; i < s.size(); i++) { if (s[i] == 'B') { if (r.size() != 0) r.erase(r.size() - 1); } else { r = r + s[i]; } } cout << r << endl; return 0; }
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 98], ["+", 0, 7, 8, 9, 0, 57, 15, 339, 0, 25], ["+", 0, 7, 8, 9, 0, 57, 64, 9, 0, 45], ["+", 8, 9, 0, 57, 64, 9, 0, 57, 0, 121], ["+", 0, 57, 64, 9, 0, 57, 15, 339, 0, 24], ["+", 0, 7, 8, 9, 0, 57, 64, 9, 0, 46], ["+", 8, 9, 0, 57, 75, 76, 0, 9, 0, 45], ["+", 8, 9, 0, 57, 75, 76...
1
94
#include <algorithm> #include <iostream> #include <vector> #define MAX_E 10000 long long int i; using namespace std; // vector<int> G[MAX_E]; string n, m; using namespace std; int main() { cin >> n; for (i = 0; i < n.size(); i++) { // cout<<m<<endl; if (n[i] == 'B' && m.size() > 0) { m.pop_back(); ...
#include <algorithm> #include <iostream> #include <vector> #define MAX_E 10000 long long int i; using namespace std; // vector<int> G[MAX_E]; string n, m; using namespace std; int main() { cin >> n; for (i = 0; i < n.size(); i++) { // cout<<m<<endl; if (n[i] == 'B' && m.size() > 0) { m.pop_back(); ...
[["+", 8, 9, 0, 57, 75, 76, 0, 57, 0, 121], ["+", 0, 57, 75, 76, 0, 57, 15, 339, 0, 24], ["+", 15, 339, 51, 16, 31, 16, 31, 69, 28, 22], ["+", 51, 16, 31, 16, 31, 69, 341, 342, 0, 70], ["+", 51, 16, 31, 16, 31, 69, 341, 342, 0, 22], ["+", 51, 16, 31, 16, 31, 69, 341, 342, 0, 73], ["+", 0, 57, 15, 339, 51, 16, 31, 16, 1...
1
104
#include <algorithm> #include <cfloat> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iostream> #include <list> #include <map> #include <memory> #include <queue> #include <set> #include <sstream> #include <stack> #include <s...
#include <algorithm> #include <cfloat> #include <climits> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <functional> #include <iostream> #include <list> #include <map> #include <memory> #include <queue> #include <set> #include <sstream> #include <stack> #include <s...
[["+", 0, 57, 75, 76, 0, 9, 0, 57, 0, 121], ["+", 75, 76, 0, 9, 0, 57, 15, 339, 0, 24], ["+", 0, 57, 15, 339, 51, 16, 31, 118, 28, 22], ["+", 0, 57, 15, 339, 51, 16, 31, 118, 17, 131], ["+", 0, 57, 15, 339, 51, 16, 31, 118, 119, 120], ["+", 0, 9, 0, 57, 15, 339, 51, 16, 17, 79], ["+", 0, 9, 0, 57, 15, 339, 51, 16, 12, ...
1
181
#include "bits/stdc++.h" using namespace std; typedef long long ll; typedef unsigned long long ull; typedef vector<int> veci; typedef vector<ll> vecll; typedef vector<string> vecs; template <class T, class U> using Hash = unordered_map<T, U>; #define REP(i, a, n) for (ll i = a; i < (ll)n; i++) #define RREP(i, a, n) ...
#include "bits/stdc++.h" using namespace std; typedef long long ll; typedef unsigned long long ull; typedef vector<int> veci; typedef vector<ll> vecll; typedef vector<string> vecs; template <class T, class U> using Hash = unordered_map<T, U>; #define REP(i, a, n) for (ll i = a; i < (ll)n; i++) #define RREP(i, a, n) ...
[["+", 0, 9, 0, 57, 75, 76, 0, 57, 0, 121], ["+", 0, 57, 75, 76, 0, 57, 15, 339, 0, 24], ["+", 15, 339, 51, 16, 31, 2, 63, 118, 28, 22], ["+", 15, 339, 51, 16, 31, 2, 63, 118, 17, 131], ["+", 15, 339, 51, 16, 31, 2, 63, 118, 119, 120], ["+", 15, 339, 51, 16, 31, 2, 3, 4, 0, 24], ["+", 15, 339, 51, 16, 31, 2, 3, 4, 0, 2...
1
786
#include <iostream> #include <math.h> #include <string> using namespace std; int main() { string a, b; cin >> a; int n = a.size(); for (int i = 0; i < n; i++) { if (a[i] != 'B') { b += a[i]; } else { b.pop_back(); } } cout << b << endl; return 0; }
#include <iostream> #include <math.h> #include <string> using namespace std; int main() { string a, b; cin >> a; int n = a.size(); for (int i = 0; i < n; i++) { if (a[i] != 'B') { b += a[i]; } else if (b != "") { b.pop_back(); } } cout << b << endl; return 0; }
[["+", 8, 9, 0, 57, 75, 76, 0, 57, 0, 121], ["+", 0, 57, 75, 76, 0, 57, 15, 339, 0, 24], ["+", 75, 76, 0, 57, 15, 339, 51, 16, 31, 22], ["+", 75, 76, 0, 57, 15, 339, 51, 16, 17, 79], ["+", 0, 57, 15, 339, 51, 16, 12, 5, 0, 62], ["+", 0, 57, 75, 76, 0, 57, 15, 339, 0, 25]]
1
88
//===================== Author Info ================== // Khaled Alam (Ninjo) ~ khaledalam.net@gmail.com //==================================================== #include <bits/stdc++.h> using namespace std; #define sz size() #define fi first #define se second #define mp make_pair #define pb push_back #define ll lon...
//===================== Author Info ================== // Khaled Alam (Ninjo) ~ khaledalam.net@gmail.com //==================================================== #include <bits/stdc++.h> using namespace std; #define sz size() #define fi first #define se second #define mp make_pair #define pb push_back #define ll lon...
[["+", 0, 57, 75, 76, 0, 9, 0, 57, 0, 121], ["+", 75, 76, 0, 9, 0, 57, 15, 339, 0, 24], ["+", 0, 57, 15, 339, 51, 16, 31, 118, 28, 22], ["+", 0, 57, 15, 339, 51, 16, 31, 118, 17, 131], ["+", 0, 57, 15, 339, 51, 16, 31, 118, 119, 120], ["+", 0, 9, 0, 57, 15, 339, 51, 16, 17, 47], ["+", 0, 9, 0, 57, 15, 339, 51, 16, 12, ...
1
136
#include <iostream> #include <string> using namespace std; int main() { int n; string s, ans; for (int i = 0; i < s.size(); i++) { if (s[i] == 'B') { if (ans.size() != 0) { ans = ans.substr(0, ans.size() - 1); } } else { ans += s[i]; } } cout << ans << endl; return 0;...
#include <iostream> #include <string> using namespace std; int main() { int n; string s, ans, temp; cin >> s; for (int i = 0; i < s.size(); i++) { if (s[i] == 'B') { if (ans.size() != 0) { temp = ans.substr(0, ans.size() - 1); ans = temp; } } else { ans += s[i]; } ...
[["+", 0, 30, 0, 14, 8, 9, 0, 43, 0, 21], ["+", 0, 30, 0, 14, 8, 9, 0, 43, 49, 22], ["+", 0, 30, 0, 14, 8, 9, 0, 43, 0, 35], ["+", 0, 14, 8, 9, 0, 1, 0, 16, 31, 22], ["+", 0, 14, 8, 9, 0, 1, 0, 16, 17, 152], ["+", 0, 14, 8, 9, 0, 1, 0, 16, 12, 22], ["-", 0, 57, 64, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 57, 64, 9, 0, 1, 0, ...
1
103
string = input() result = [] j=0 for i in range(len(string)): if string[i] == '0': result.append('0') elif string[i] == '1': result.append('1') elif string[i]=='B' and len(result)>1 and (result[-1]=='0' or result[-1]=='1'): result[-1]="" str_result="".join(result) print(str_result)
string = input() result = [] j=0 for i in range(len(string)): if string[i]=='0': result.append('0') elif string[i]=='1': result.append('1') elif string[i]=='B' and len(result)>=1 and result[-1] in ['0','1']: del result[-1] str_result="".join(result) print(str_result)
[["-", 75, 665, 15, 679, 31, 679, 12, 666, 667, 47], ["+", 75, 665, 15, 679, 31, 679, 12, 666, 667, 20], ["-", 0, 57, 75, 665, 15, 679, 12, 23, 0, 24], ["-", 15, 679, 12, 23, 0, 679, 31, 666, 667, 60], ["+", 0, 57, 75, 665, 15, 679, 12, 666, 667, 267], ["+", 75, 665, 15, 679, 12, 666, 0, 634, 0, 70], ["-", 75, 665, 15,...
5
119
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; i < (n); i++) #define REP2(i, x, n) for (int i = x; i < (n); i++) using namespace std; struct cww { cww() { ios::sync_with_stdio(false); cin.tie(0); } } star; const int INF = numeric_limits<int>::max(); int main() { string S; cin >> S; string...
#include <bits/stdc++.h> #define REP(i, n) for (int i = 0; i < (n); i++) #define REP2(i, x, n) for (int i = x; i < (n); i++) using namespace std; struct cww { cww() { ios::sync_with_stdio(false); cin.tie(0); } } star; const int INF = numeric_limits<int>::max(); int main() { string S; cin >> S; string...
[["+", 64, 9, 0, 1, 0, 11, 12, 16, 31, 22], ["+", 64, 9, 0, 1, 0, 11, 12, 16, 17, 72], ["-", 64, 9, 0, 1, 0, 11, 12, 16, 17, 72], ["-", 64, 9, 0, 1, 0, 11, 12, 16, 12, 22], ["-", 0, 1, 0, 2, 3, 4, 0, 16, 12, 13], ["+", 3, 4, 0, 16, 31, 16, 12, 74, 0, 24], ["+", 0, 16, 31, 16, 12, 74, 39, 77, 39, 40], ["+", 3, 4, 0, 16,...
1
185
#include <bits/stdc++.h> using namespace std; int main() { int cn = 0; string str, ff; stack<char> st; cin >> str; for (int i = 0; i < str.size(); i++) { // char& c=str[i]; if (str[i] == '0') { st.push('0'); } else if (str[i] == '1') { st.push('1'); } else { if (!st.empty())...
#include <bits/stdc++.h> using namespace std; int main() { int cn = 0; string str, ff; stack<char> st; cin >> str; for (int i = 0; i < str.size(); i++) { // char& c=str[i]; if (str[i] == '0') { st.push('0'); } else if (str[i] == '1') { st.push('1'); } else { if (!st.empty())...
[["+", 0, 14, 8, 9, 0, 1, 0, 2, 63, 22], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 24], ["+", 0, 2, 3, 4, 0, 2, 63, 118, 28, 22], ["+", 0, 2, 3, 4, 0, 2, 63, 118, 17, 131], ["+", 0, 2, 3, 4, 0, 2, 63, 118, 119, 120], ["+", 0, 2, 3, 4, 0, 2, 3, 4, 0, 24], ["+", 0, 2, 3, 4, 0, 2, 3, 4, 0, 25], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 21]...
1
151
#include <iostream> #include <string> using namespace std; int main() { string a, b; cin >> a; int c, d; c = a.size(); while (c > d) { if (a.substr(0, 1) == "0") { b = b + '0'; } else if (a.substr(0, 1) == "1") { b = b + '1'; } else if (a.substr(0, 1) == "B") { b.erase(b.size() ...
#include <iostream> #include <string> using namespace std; int main() { string a, b; cin >> a; int c, d; c = a.size(); while (c > d) { if (a.substr(0, 1) == "0") { b = b + '0'; } else if (a.substr(0, 1) == "1") { b = b + '1'; } else if (b.size() != 0 && a.substr(0, 1) == "B") { ...
[["+", 51, 16, 31, 16, 31, 2, 63, 118, 28, 22], ["+", 51, 16, 31, 16, 31, 2, 63, 118, 17, 131], ["+", 51, 16, 31, 16, 31, 2, 63, 118, 119, 120], ["+", 51, 16, 31, 16, 31, 2, 3, 4, 0, 24], ["+", 51, 16, 31, 16, 31, 2, 3, 4, 0, 25], ["+", 0, 57, 15, 339, 51, 16, 31, 16, 17, 79], ["+", 0, 57, 15, 339, 51, 16, 31, 16, 12, ...
1
149
#include <bits/stdc++.h> using namespace std; typedef long int lint; typedef long long int llint; #define EACH(i, c) \ for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) #define ALL(c) (c).begin(), (c).end() #define FOR(i, s, e) for (int i = ...
#include <bits/stdc++.h> using namespace std; typedef long int lint; typedef long long int llint; #define EACH(i, c) \ for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i) #define ALL(c) (c).begin(), (c).end() #define FOR(i, s, e) for (int i = ...
[["+", 0, 14, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 14, 8, 9, 0, 1, 0, 11, 17, 32], ["+", 8, 9, 0, 1, 0, 11, 12, 5, 0, 62], ["+", 0, 30, 0, 14, 8, 9, 0, 1, 0, 35], ["-", 0, 52, 8, 9, 0, 1, 0, 16, 31, 22], ["-", 0, 52, 8, 9, 0, 1, 0, 16, 17, 151], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 1...
1
253
#include <stdio.h> int main(void) { char s[12], a[12]; int i, c = 0; scanf("%s", s); for (i = 0; s[i] != '\0'; i++) { if (s[i] == 'B') { c--; } else { a[c] = s[i]; c++; } } for (i = 0; i < c; i++) printf("%c", a[i]); puts(""); return 0; }
#include <stdio.h> int main(void) { char s[12], a[12]; int i, c = 0; scanf("%s", s); for (i = 0; s[i] != '\0'; i++) { if (s[i] == 'B') { c--; if (c < 0) c = 0; } else { a[c] = s[i]; c++; } } for (i = 0; i < c; i++) printf("%c", a[i]); puts(""); return 0; }
[["+", 8, 9, 0, 57, 64, 9, 0, 57, 0, 121], ["+", 0, 57, 64, 9, 0, 57, 15, 23, 0, 24], ["+", 64, 9, 0, 57, 15, 23, 0, 16, 31, 22], ["+", 64, 9, 0, 57, 15, 23, 0, 16, 17, 18], ["+", 64, 9, 0, 57, 15, 23, 0, 16, 12, 13], ["+", 0, 57, 64, 9, 0, 57, 15, 23, 0, 25], ["+", 64, 9, 0, 57, 64, 1, 0, 11, 31, 22], ["+", 64, 9, 0, ...
0
122
import java.util.Scanner; public class Main { public static void main(String[] args) { // TODO 自動生成されたメソッド・スタブ Scanner sc = new Scanner(System.in); String s = sc.nextLine(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < s.length(); i++) { if (s.charAt(i) != 'B') { s...
import java.util.Scanner; public class Main { public static void main(String[] args) { // TODO 自動生成されたメソッド・スタブ Scanner sc = new Scanner(System.in); String s = sc.nextLine(); StringBuilder sb = new StringBuilder(); int p = 0; for (int i = 0; i < s.length(); i++) { if (s.charAt(i) != '...
[["+", 0, 195, 8, 196, 0, 503, 39, 506, 0, 507], ["+", 0, 195, 8, 196, 0, 503, 49, 200, 141, 22], ["+", 0, 195, 8, 196, 0, 503, 49, 200, 0, 32], ["+", 0, 195, 8, 196, 0, 503, 49, 200, 51, 499], ["+", 8, 498, 0, 195, 8, 196, 0, 503, 0, 35], ["+", 0, 57, 64, 196, 0, 1, 0, 27, 0, 22], ["+", 0, 57, 64, 196, 0, 1, 0, 27, 0,...
3
137
#include <iostream> #include <string> #include <vector> using namespace std; int main() { char a[10]; vector<char> b; cin >> a; for (int i = 0; i <= 9; i++) { if (a[i] == '0') { b.push_back('0'); } if (a[i] == '1') { b.push_back('1'); } if (a[i] == 'B') { if (i > 0) { ...
#include <iostream> #include <string> #include <vector> using namespace std; int main() { char a[10]; vector<char> b; cin >> a; for (int i = 0; i <= 9; i++) { if (a[i] == '0') { b.push_back('0'); } if (a[i] == '1') { b.push_back('1'); } if (a[i] == 'B') { if (i > 0 && ...
[["+", 64, 9, 0, 57, 15, 339, 51, 16, 17, 98], ["+", 51, 16, 12, 16, 31, 2, 63, 118, 28, 22], ["+", 51, 16, 12, 16, 31, 2, 63, 118, 17, 131], ["+", 51, 16, 12, 16, 31, 2, 63, 118, 119, 120], ["+", 51, 16, 12, 16, 31, 2, 3, 4, 0, 24], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 17, 47], ["+", 0, 57, 15, 339, 51, 16, 12, 16, 1...
1
153
#include <algorithm> #include <cmath> #include <cstdio> #include <iostream> #include <queue> #include <stack> #include <string> #include <vector> #define _USE_MATH_DEFINES #define FORN(n) for (int i = 0; i < n; i++) #define PINT(d) printf("%d\n", d) #define PDOUBLE(lf) printf("%lf\n", lf) #define PSTR(s) printf("%s\n"...
#include <algorithm> #include <cmath> #include <cstdio> #include <iostream> #include <queue> #include <stack> #include <string> #include <vector> #define _USE_MATH_DEFINES #define FORN(n) for (int i = 0; i < n; i++) #define PINT(d) printf("%d\n", d) #define PDOUBLE(lf) printf("%lf\n", lf) #define PSTR(s) printf("%s\n"...
[["-", 0, 14, 8, 9, 0, 43, 39, 344, 141, 78], ["+", 0, 14, 8, 9, 0, 43, 39, 344, 141, 78], ["-", 8, 9, 0, 1, 0, 2, 63, 118, 119, 120], ["+", 8, 9, 0, 1, 0, 2, 63, 118, 119, 120], ["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 24], ["-", 0, 2, 3, 4, 0, 2, 63, 118, 28, 22], ["-", 0, 2, 3, 4, 0, 2, 63, 118, 17, 131], ["-", 0, 2, 3, 4, ...
1
198
// g++ -std=c++11 temp.cpp #include <bits/stdc++.h> using namespace std; #define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++) #define REP(i, n) FOR(i, 0, n) #define EACH(itr, v) for (auto itr : v) #define pb(s) push_back(s) #define mp(a, b) make_pair(a, b) #define all(x) (x).begin(), (x).end() #define dbg(x)...
// g++ -std=c++11 temp.cpp #include <bits/stdc++.h> using namespace std; #define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++) #define REP(i, n) FOR(i, 0, n) #define EACH(itr, v) for (auto itr : v) #define pb(s) push_back(s) #define mp(a, b) make_pair(a, b) #define all(x) (x).begin(), (x).end() #define dbg(x)...
[["-", 64, 9, 0, 57, 64, 1, 0, 27, 28, 22], ["+", 0, 57, 64, 9, 0, 57, 64, 9, 0, 45], ["+", 64, 9, 0, 1, 0, 11, 31, 69, 28, 22], ["+", 0, 1, 0, 11, 31, 69, 341, 342, 0, 70], ["+", 0, 11, 31, 69, 341, 342, 0, 27, 28, 22], ["+", 0, 1, 0, 11, 31, 69, 341, 342, 0, 73], ["+", 0, 57, 64, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 57,...
1
187
#include <algorithm> #include <iostream> #include <string> #include <vector> using namespace std; #define REP(i, k, n) for (int i = k; i < n; i++) #define rep(i, n) for (int i = 0; i < n; i++) #define all(v) v.begin(), v.end() #define each(it, c) \ for (__t...
#include <algorithm> #include <iostream> #include <string> #include <vector> using namespace std; #define REP(i, k, n) for (int i = k; i < n; i++) #define rep(i, n) for (int i = 0; i < n; i++) #define all(v) v.begin(), v.end() #define each(it, c) \ for (__t...
[["+", 8, 9, 0, 9, 0, 57, 64, 9, 0, 45], ["+", 0, 9, 0, 57, 64, 9, 0, 57, 0, 121], ["+", 0, 57, 64, 9, 0, 57, 15, 339, 0, 24], ["+", 64, 9, 0, 57, 15, 339, 51, 16, 31, 22], ["+", 64, 9, 0, 57, 15, 339, 51, 16, 17, 60], ["+", 64, 9, 0, 57, 15, 339, 51, 16, 12, 13], ["+", 0, 57, 64, 9, 0, 57, 15, 339, 0, 25], ["+", 0, 57...
1
199
#include <algorithm> #include <bitset> #include <cctype> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include ...
#include <algorithm> #include <bitset> #include <cctype> #include <climits> #include <cmath> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <list> #include <map> #include <numeric> #include <queue> #include ...
[["+", 0, 57, 75, 76, 0, 9, 0, 57, 0, 121], ["+", 75, 76, 0, 9, 0, 57, 15, 339, 0, 24], ["+", 15, 339, 51, 16, 31, 2, 63, 118, 28, 22], ["+", 15, 339, 51, 16, 31, 2, 63, 118, 17, 131], ["+", 15, 339, 51, 16, 31, 2, 63, 118, 119, 120], ["+", 15, 339, 51, 16, 31, 2, 3, 4, 0, 24], ["+", 15, 339, 51, 16, 31, 2, 3, 4, 0, 25...
1
305
#include <algorithm> #include <cstring> #include <iostream> using namespace std; int main() { string s; string ans = ""; int p = 0; cin >> s; for (int i = 0; i < s.size(); i++) { if (s[i] != 'B') { ans += s[i]; p++; } else { ans = ans.substr(0, --p); } } cout << ans << endl...
#include <algorithm> #include <cstring> #include <iostream> using namespace std; int main() { string s; string ans = ""; int p = 0; cin >> s; for (int i = 0; i < s.size(); i++) { if (s[i] != 'B') { ans += s[i]; p++; } else { if (p != 0) --p; ans = ans.substr(0, p); ...
[["+", 0, 57, 75, 76, 0, 9, 0, 57, 0, 121], ["+", 75, 76, 0, 9, 0, 57, 15, 339, 0, 24], ["+", 0, 9, 0, 57, 15, 339, 51, 16, 31, 22], ["+", 0, 9, 0, 57, 15, 339, 51, 16, 17, 79], ["+", 0, 9, 0, 57, 15, 339, 51, 16, 12, 13], ["+", 75, 76, 0, 9, 0, 57, 15, 339, 0, 25], ["+", 0, 9, 0, 57, 64, 1, 0, 27, 17, 68], ["+", 0, 9,...
1
101
#include <algorithm> #include <climits> #include <cmath> #include <cstdlib> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <string> #include <tuple> #include <unordered_map> #include <unordered_set> #include <vec...
#include <algorithm> #include <climits> #include <cmath> #include <cstdlib> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <numeric> #include <queue> #include <set> #include <sstream> #include <string> #include <tuple> #include <unordered_map> #include <unordered_set> #include <vec...
[["+", 8, 9, 0, 57, 64, 9, 0, 57, 0, 121], ["+", 0, 57, 64, 9, 0, 57, 15, 339, 0, 24], ["+", 64, 9, 0, 57, 15, 339, 51, 91, 17, 111], ["+", 15, 339, 51, 91, 28, 2, 63, 118, 17, 131], ["+", 15, 339, 51, 91, 28, 2, 63, 118, 119, 120], ["+", 15, 339, 51, 91, 28, 2, 3, 4, 0, 24], ["+", 15, 339, 51, 91, 28, 2, 3, 4, 0, 25],...
1
109
#include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <tuple> #include <unordered_map> #include <unordered_se...
#include <algorithm> #include <bitset> #include <cassert> #include <cmath> #include <complex> #include <cstdio> #include <cstdlib> #include <functional> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <stack> #include <tuple> #include <unordered_map> #include <unordered_se...
[["+", 8, 9, 0, 57, 75, 76, 0, 57, 0, 121], ["+", 0, 57, 75, 76, 0, 57, 15, 339, 0, 24], ["+", 75, 76, 0, 57, 15, 339, 51, 91, 17, 111], ["+", 15, 339, 51, 91, 28, 2, 63, 118, 28, 22], ["+", 15, 339, 51, 91, 28, 2, 63, 118, 17, 131], ["+", 15, 339, 51, 91, 28, 2, 63, 118, 119, 120], ["+", 15, 339, 51, 91, 28, 2, 3, 4, ...
1
113
#include <iostream> #include <stack> #include <string> int main() { std::string s; std::stack<char> ss; std::cin >> s; for (int i = 0; i < s.length(); i++) { if (s[i] != 'B') { ss.push(s[i]); } else { if (!ss.empty()) ss.pop(); } } std::string ans; while (!ss.empty()) ...
#include <algorithm> #include <iostream> #include <stack> #include <string> int main() { std::string s; std::stack<char> ss; std::cin >> s; for (int i = 0; i < s.length(); i++) { if (s[i] != 'B') { ss.push(s[i]); } else { if (!ss.empty()) ss.pop(); } } std::string ans; ...
[["+", 36, 36, 36, 36, 0, 30, 0, 135, 136, 137], ["+", 36, 36, 36, 36, 0, 30, 0, 135, 0, 138], ["+", 8, 9, 0, 1, 0, 2, 63, 343, 345, 348], ["+", 8, 9, 0, 1, 0, 2, 63, 343, 0, 349], ["+", 8, 9, 0, 1, 0, 2, 63, 343, 141, 22], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 24], ["+", 0, 2, 3, 4, 0, 2, 63, 118, 28, 22], ["+", 0, 2, 3, 4...
1
135
n = int(input()) s = map(int, input().split()) def solution(s): cost = 0 mean = round(sum(s)/len(s)) for i in s: cost += abs(i-mean) ** 2 #print(f"DEBUG >> {mean} {i} {cost}") return cost print(solution(s))
n = int(input()) s = [int(c) for c in input().split()] def solution(s): cost = 0 mean = round(sum(s)/len(s)) for i in s: cost += abs(i-mean) ** 2 #print(f"DEBUG >> {mean} {i} {cost}") return cost print(solution(s))
[["-", 0, 656, 0, 1, 0, 662, 12, 652, 63, 22], ["-", 0, 1, 0, 662, 12, 652, 3, 4, 0, 24], ["+", 0, 656, 0, 1, 0, 662, 12, 658, 0, 70], ["-", 0, 1, 0, 662, 12, 652, 3, 4, 0, 21], ["+", 0, 662, 12, 658, 8, 652, 3, 4, 0, 24], ["+", 0, 662, 12, 658, 8, 652, 3, 4, 0, 22], ["+", 0, 662, 12, 658, 8, 652, 3, 4, 0, 25], ["+", 0...
5
70
import numpy as np n=int(input()) a=np.array([int(x) for x in input().split()]) x=[] for i in a: s=np.sum((a-i)*(a-i)) x.append(s) print(min(x))
import numpy as np n=int(input()) a=np.array([int(x) for x in input().split()]) x=[] for i in range(-100,101): s=np.sum((a-i)*(a-i)) x.append(s) print(min(x))
[["-", 36, 36, 36, 36, 0, 656, 0, 7, 12, 22], ["+", 36, 36, 0, 656, 0, 7, 12, 652, 63, 22], ["+", 0, 656, 0, 7, 12, 652, 3, 4, 0, 24], ["+", 0, 7, 12, 652, 3, 4, 0, 664, 17, 33], ["+", 0, 7, 12, 652, 3, 4, 0, 664, 28, 612], ["+", 0, 656, 0, 7, 12, 652, 3, 4, 0, 21], ["+", 0, 656, 0, 7, 12, 652, 3, 4, 0, 612], ["+", 0, ...
5
75
package main import ( "bufio" "fmt" "os" "strconv" ) func out(x ...interface{}) { fmt.Println(x...) } var sc = bufio.NewScanner(os.Stdin) func getInt() int { sc.Scan() i, e := strconv.Atoi(sc.Text()) if e != nil { panic(e) } return i } func getString() string { sc.Scan() return sc.Text() } func main...
package main import ( "bufio" "fmt" "os" "strconv" ) func out(x ...interface{}) { fmt.Println(x...) } var sc = bufio.NewScanner(os.Stdin) func getInt() int { sc.Scan() i, e := strconv.Atoi(sc.Text()) if e != nil { panic(e) } return i } func getString() string { sc.Scan() return sc.Text() } func main...
[["+", 0, 435, 8, 196, 0, 431, 12, 432, 0, 433], ["+", 36, 36, 0, 434, 0, 435, 8, 196, 0, 165], ["+", 0, 434, 0, 435, 8, 196, 0, 57, 0, 121], ["+", 0, 435, 8, 196, 0, 57, 15, 16, 31, 22], ["+", 0, 435, 8, 196, 0, 57, 15, 16, 17, 47], ["+", 0, 435, 8, 196, 0, 57, 15, 16, 12, 433], ["+", 0, 435, 8, 196, 0, 57, 64, 196, 0...
7
252
n = int(input()) dList = list(map(int,input().split())) sD = sum(dList)/n ig = int(sD) po = sD-int(sD) ad = 0 if po >= 0.5: ad = ig + 1 elif po != 0: ad = ig -1 else: ad = ig result = 0 for i in range(len(dList)): result += (dList[i]-ad)**2 print(result)
n = int(input()) dList = list(map(int,input().split())) sD = sum(dList)/n ig = int(sD) po = sD-int(sD) ad = 0 if abs(po) >= 0.5: if sD >= 0: ad = ig + 1 else: ad = ig -1 else: ad = ig result = 0 for i in range(len(dList)): result += (dList[i]-ad)**2 print(result)
[["+", 0, 656, 0, 57, 15, 666, 0, 652, 63, 22], ["+", 0, 57, 15, 666, 0, 652, 3, 4, 0, 24], ["+", 0, 57, 15, 666, 0, 652, 3, 4, 0, 25], ["+", 0, 656, 0, 57, 64, 196, 0, 57, 0, 121], ["+", 0, 57, 64, 196, 0, 57, 15, 666, 0, 22], ["+", 0, 57, 64, 196, 0, 57, 15, 666, 667, 20], ["+", 0, 57, 64, 196, 0, 57, 15, 666, 0, 612...
5
105
#include <bits/stdc++.h> typedef long long ll; const int INF = 1e9; const int MOD = 1e9 + 7; const ll LINF = 1e18; using namespace std; #define rep(i, a, b) for (int i = a; i < b; i++) #define rrep(i, a, b) for (int i = a; i <= b; i++) #define all(a) begin((a)), end((a)) #define uniq(c) (c).erase(unique(all((c))), en...
#include <bits/stdc++.h> typedef long long ll; const int INF = 1e9; const int MOD = 1e9 + 7; const ll LINF = 1e18; using namespace std; #define rep(i, a, b) for (int i = a; i < b; i++) #define rrep(i, a, b) for (int i = a; i <= b; i++) #define all(a) begin((a)), end((a)) #define uniq(c) (c).erase(unique(all((c))), en...
[["-", 0, 30, 0, 14, 8, 9, 0, 43, 39, 40], ["-", 0, 14, 8, 9, 0, 43, 49, 50, 49, 22], ["+", 0, 14, 8, 9, 0, 43, 39, 86, 0, 96], ["+", 0, 14, 8, 9, 0, 43, 49, 50, 49, 22], ["-", 8, 9, 0, 9, 0, 1, 0, 11, 31, 22], ["+", 8, 9, 0, 9, 0, 1, 0, 11, 31, 22], ["-", 8, 9, 0, 1, 0, 11, 12, 2, 63, 22], ["+", 8, 9, 0, 43, 49, 50, 5...
1
177
#include <bits/stdc++.h> using namespace std; #define rep(i, n) rep2(i, 0, n) #define rep2(i, m, n) for (int i = m; i < (n); i++) typedef long long ll; #define INF 1e9 int inline calc(int x, int y) { return pow((x - y), 2); } int main() { int n; cin >> n; vector<int> a(n); int ans = INF; rep2(y, -100, 101)...
#include <bits/stdc++.h> using namespace std; #define rep(i, n) rep2(i, 0, n) #define rep2(i, m, n) for (int i = m; i < (n); i++) typedef long long ll; #define INF 1e9 int inline calc(int x, int y) { return pow((x - y), 2); } int main() { int n; cin >> n; vector<int> a(n); rep(i, n) cin >> a[i]; int ans =...
[["+", 0, 14, 8, 9, 0, 1, 0, 2, 63, 22], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 24], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 22], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 21], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 25], ["+", 0, 1, 0, 2, 3, 4, 0, 25, 0, 35], ["+", 0, 14, 8, 9, 0, 1, 0, 16, 31, 22], ["+", 0, 14, 8, 9, 0, 1, 0, 16, 17, 152], ["+",...
1
128
N = int(input()) A =[int(x) for x in input().split()] result=float('inf') for i in range(max(A)): s=0 for j in range(N): s += (i-A[j])**2 result=min(result,s) print(result)
N = int(input()) A =[int(x) for x in input().split()] result=float('inf') for i in range(min(A),max(A)+1): s=0 for j in range(N): s += (i-A[j])**2 result=min(result,s) print(result)
[["+", 0, 7, 12, 652, 3, 4, 0, 652, 63, 22], ["+", 12, 652, 3, 4, 0, 652, 3, 4, 0, 24], ["+", 12, 652, 3, 4, 0, 652, 3, 4, 0, 22], ["+", 12, 652, 3, 4, 0, 652, 3, 4, 0, 25], ["+", 0, 656, 0, 7, 12, 652, 3, 4, 0, 21], ["+", 0, 7, 12, 652, 3, 4, 0, 657, 17, 72], ["+", 0, 7, 12, 652, 3, 4, 0, 657, 12, 612]]
5
80
#include <algorithm> #include <iostream> #include <math.h> #include <set> #include <vector> using namespace std; int main() { int n; cin >> n; int l, m = 0; int a[n] = {}; while (cin >> l) { a[m] = l; m++; } int min = a[0]; int max = a[0]; for (int i = 0; i < n; i++) { if (min > a...
#include <algorithm> #include <iostream> #include <math.h> #include <set> #include <vector> using namespace std; int main() { int n; cin >> n; int l, m = 0; int a[n] = {}; while (cin >> l) { a[m] = l; m++; } int min = a[0]; int max = a[0]; for (int i = 0; i < n; i++) { if (min > a...
[["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 98], ["-", 15, 339, 51, 16, 12, 16, 31, 69, 28, 22], ["-", 51, 16, 12, 16, 31, 69, 341, 342, 0, 70], ["-", 51, 16, 12, 16, 31, 69, 341, 342, 0, 22], ["-", 51, 16, 12, 16, 31, 69, 341, 342, 0, 73], ["-", 0, 57, 15, 339, 51, 16, 12, 16, 17, 79], ["-", 0, 57, 15, 339, 51, 16, 12, 1...
1
252
#include <stdio.h> #include <string.h> int main(void) { int n; int a[100]; int i; int ave; long long int ret; scanf("%d", &n); ave = 0; for (i = 0; i < n; i++) { scanf("%d", &a[i]); ave += a[i]; } ave = (int)(double(ave) / (double)n + 0.5); ret = 0; for (i = 0; i < n; i++) { r...
#include <stdio.h> #include <string.h> int main(void) { int n; int a[100]; int i; int ave; long long int ret; scanf("%d", &n); ave = 0; for (i = 0; i < n; i++) { scanf("%d", &a[i]); ave += a[i]; } if (ave < 0) { ave = (int)(double(ave) / (double)n - 0.5); } else { ave = (int)...
[["+", 0, 30, 0, 14, 8, 9, 0, 57, 0, 121], ["+", 0, 14, 8, 9, 0, 57, 15, 339, 0, 24], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 31, 22], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 18], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 12, 13], ["+", 0, 14, 8, 9, 0, 57, 15, 339, 0, 25], ["+", 0, 14, 8, 9, 0, 57, 64, 9, 0, 45], ["+", 0, 57, 64...
1
151
#include <bits/stdc++.h> using namespace std; #define ll long long int /* this code is generated by shikhar verma . Dont try to copy it. You may be * booked under plaigarism. */ int numberofPaths(int h, int w, int a, int b); int main() { ll n, i, j, len1, b, h, w, t, cnt = 0, cnt1 = 0; /* freopen("input.txt","r",s...
#include <bits/stdc++.h> using namespace std; #define ll long long int /* this code is generated by shikhar verma . Dont try to copy it. You may be * booked under plaigarism. */ // int numberofPaths(int h,int w,int a,int b); int main() { ll n, i, j, len1, b, h, w, t, cnt = 0, cnt1 = 0; /* freopen("input.txt","r",s...
[["-", 36, 36, 0, 30, 0, 43, 49, 53, 49, 22], ["-", 0, 30, 0, 43, 49, 53, 54, 55, 0, 24], ["-", 0, 43, 49, 53, 54, 55, 0, 56, 39, 40], ["-", 0, 43, 49, 53, 54, 55, 0, 56, 49, 22], ["-", 0, 30, 0, 43, 49, 53, 54, 55, 0, 21], ["-", 0, 30, 0, 43, 49, 53, 54, 55, 0, 25], ["-", 36, 36, 36, 36, 0, 30, 0, 43, 0, 35], ["-", 36...
1
152
/* #include <bits/stdc++.h> using namespace std; int n; int main() { cin>>n; cout<<n*(n+1)/2; return 0; } A */ /* #include <bits/stdc++.h> using namespace std; int l,i,j,k; char sir[110],x[110]; int main() { cin>>sir; l=strlen(sir); for(i=0;i<l;i++) { if(sir[i]=='1') ...
/* #include <bits/stdc++.h> using namespace std; int n; int main() { cin>>n; cout<<n*(n+1)/2; return 0; } A */ /* #include <bits/stdc++.h> using namespace std; int l,i,j,k; char sir[110],x[110]; int main() { cin>>sir; l=strlen(sir); for(i=0;i<l;i++) { if(sir[i]=='1') ...
[["-", 0, 30, 0, 14, 8, 9, 0, 57, 0, 121], ["-", 0, 14, 8, 9, 0, 57, 15, 339, 0, 24], ["-", 0, 57, 15, 339, 51, 16, 31, 16, 17, 109], ["-", 0, 57, 15, 339, 51, 16, 31, 16, 12, 22], ["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 79], ["-", 8, 9, 0, 57, 15, 339, 51, 16, 12, 13], ["-", 0, 14, 8, 9, 0, 57, 15, 339, 0, 25], ["-", ...
1
168
N = int(input()) a = [int(i) for i in input().split()] ans = [] sum = 0 for j in range(min(a), max(a)): for num in a: sum += (num - j) ** 2 else: ans.append(sum) sum = 0 if ans == None: ans.appned(0) print(min(ans))
N = int(input()) a = [int(i) for i in input().split()] ans = [] sum = 0 for j in range(min(a), max(a)): for num in a: sum += (num - j) ** 2 else: ans.append(sum) sum = 0 if len(ans) == 0: print(0) else: print(min(ans))
[["+", 0, 656, 0, 57, 15, 666, 0, 652, 63, 22], ["+", 0, 57, 15, 666, 0, 652, 3, 4, 0, 24], ["+", 0, 57, 15, 666, 0, 652, 3, 4, 0, 25], ["-", 36, 36, 0, 656, 0, 57, 15, 666, 0, 685], ["+", 36, 36, 0, 656, 0, 57, 15, 666, 0, 612], ["-", 64, 196, 0, 1, 0, 652, 63, 319, 500, 22], ["-", 64, 196, 0, 1, 0, 652, 63, 319, 0, 1...
5
92
n = int(input()) a = list(map(int, input().split())) mid = (max(a) + min(a))//2 ans1 = 0 ans2 = 0 for i in a: ans1 += pow(abs(i - mid),2) ans2 += pow(abs(i - (mid+1)),2) print(min(ans1, ans2))
n = int(input()) a = list(map(int, input().split())) mid = sum(a)//len(a) ans1 = 0 ans2 = 0 for i in a: ans1 += pow(abs(i - mid),2) ans2 += pow(abs(i - (mid+1)),2) print(min(ans1, ans2))
[["+", 0, 1, 0, 662, 12, 657, 31, 652, 63, 22], ["-", 12, 657, 31, 23, 0, 657, 31, 652, 63, 22], ["-", 31, 23, 0, 657, 31, 652, 3, 4, 0, 24], ["-", 0, 662, 12, 657, 31, 23, 0, 657, 17, 72], ["-", 12, 657, 31, 23, 0, 657, 12, 652, 63, 22], ["+", 0, 656, 0, 1, 0, 662, 12, 657, 17, 676], ["+", 0, 1, 0, 662, 12, 657, 12, 6...
5
90
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; const int INF = 1 << 29; int main() { int n; scanf("%d", &n); int a[100]; rep(i, n) scanf("%d", &a[i]); int ans = INF; rep(tar, 101) { int cost = 0; rep(i, n) cost += (a[i] - tar) * (a[i] - tar); a...
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (n); i++) using namespace std; const int INF = 1 << 29; int main() { int n; scanf("%d", &n); int a[100]; rep(i, n) scanf("%d", &a[i]); int ans = INF; for (int tar = -100; tar <= 100; tar++) { int cost = 0; rep(i, n) cost += (a[i] - ...
[["-", 0, 14, 8, 9, 0, 1, 0, 2, 63, 22], ["+", 0, 30, 0, 14, 8, 9, 0, 7, 0, 88], ["+", 0, 14, 8, 9, 0, 7, 10, 43, 39, 40], ["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 21], ["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 13], ["+", 8, 9, 0, 7, 10, 43, 49, 50, 0, 32], ["+", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["+", 0, 14, 8, 9, 0, 7, 10, 43, 0, ...
1
134
#include <bits/stdc++.h> #define INF 1e9 using namespace std; typedef long long ll; int main() { int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; ++i) { cin >> a[i]; } int sum = accumulate(a.begin(), a.end(), 0); int ave; if (sum % n == 0) { ave = sum / n; } else { ave = (in...
#include <bits/stdc++.h> #define INF 1e9 using namespace std; typedef long long ll; int main() { int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; ++i) { cin >> a[i]; } int sum = accumulate(a.begin(), a.end(), 0); int ave = round((double)sum / (double)n); int ans = 0; for (int i = ...
[["-", 0, 30, 0, 14, 8, 9, 0, 43, 0, 35], ["-", 0, 30, 0, 14, 8, 9, 0, 57, 0, 121], ["-", 0, 14, 8, 9, 0, 57, 15, 339, 0, 24], ["-", 0, 57, 15, 339, 51, 16, 31, 16, 31, 22], ["-", 0, 57, 15, 339, 51, 16, 31, 16, 17, 109], ["-", 0, 57, 15, 339, 51, 16, 31, 16, 12, 22], ["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 60], ["-", ...
1
167
package main import ( "bufio" "fmt" "math" "os" "strconv" "strings" ) func main() { var sc = bufio.NewScanner(os.Stdin) var s string if sc.Scan() { _ = sc.Text() } if sc.Scan() { s = sc.Text() } ss := strings.Split(s, " ") as := make([]int, 0, len(ss)) for _, s := range ss { i, _ := strconv.Atoi(...
package main import ( "bufio" "fmt" "math" "os" "strconv" "strings" ) func main() { var sc = bufio.NewScanner(os.Stdin) var s string if sc.Scan() { _ = sc.Text() } if sc.Scan() { s = sc.Text() } ss := strings.Split(s, " ") as := make([]int, 0, len(ss)) for _, s := range ss { i, _ := strconv.Atoi(...
[["-", 0, 431, 12, 432, 0, 2, 63, 438, 439, 22], ["-", 0, 431, 12, 432, 0, 2, 63, 438, 0, 131], ["-", 0, 431, 12, 432, 0, 2, 63, 438, 119, 120], ["+", 8, 196, 0, 431, 12, 432, 0, 2, 63, 22], ["+", 36, 36, 36, 36, 36, 36, 0, 434, 0, 165], ["+", 36, 36, 36, 36, 0, 434, 0, 435, 0, 481], ["+", 36, 36, 36, 36, 0, 434, 0, 43...
7
226
num = STDIN.gets.chomp.to_i target = STDIN.gets.chomp.split(' ').map(&:to_i) def average(target) le = target.length target.inject(:+) / le end avg = average(target) result = 0 target.each do |t| result += (t - avg).abs ** 2 end p result
num = STDIN.gets.chomp.to_i target = STDIN.gets.chomp.split(' ').map(&:to_f) def average(target) le = target.length tmp = target.inject(:+) / le tmp.round end avg = average(target) result = 0 target.each do |t| result += (t.to_i - avg).abs ** 2 end p result
[["-", 0, 662, 12, 652, 3, 4, 0, 752, 0, 753], ["+", 0, 662, 12, 652, 3, 4, 0, 752, 0, 753], ["+", 0, 493, 0, 735, 8, 736, 0, 662, 31, 22], ["+", 0, 493, 0, 735, 8, 736, 0, 662, 0, 32], ["+", 0, 493, 0, 735, 8, 736, 0, 652, 486, 22], ["+", 0, 493, 0, 735, 8, 736, 0, 652, 17, 131], ["+", 0, 493, 0, 735, 8, 736, 0, 652, ...
4
78
import numpy as np N = int(input()) a = [int(i) for i in input().split()] oppai = np.array(a) max = np.max(oppai) min = np.min(oppai) x = (max+min)//2 sum = [0] * 3 for i in range(x-1,x+2,1): oppai = np.array(a) #oppaiの初期化 oppai -= i oppai = oppai**2 sum[i-x+1] = np.sum(oppai) #print('sum[{}]'.for...
import numpy as np N = int(input()) a = [int(i) for i in input().split()] oppai = np.array(a) max = np.max(oppai) min = np.min(oppai) x = (max+min)//2 sum = [0] * 201 for i in range(-100,101): oppai = np.array(a) #oppaiの初期化 oppai -= i oppai = oppai**2 sum[i+100] = np.sum(oppai) #print('sum[{}]'.fo...
[["-", 0, 656, 0, 1, 0, 662, 12, 657, 12, 612], ["+", 0, 656, 0, 1, 0, 662, 12, 657, 12, 612], ["-", 0, 7, 12, 652, 3, 4, 0, 657, 31, 22], ["-", 0, 7, 12, 652, 3, 4, 0, 657, 12, 612], ["-", 0, 656, 0, 7, 12, 652, 3, 4, 0, 21], ["-", 0, 7, 12, 652, 3, 4, 0, 657, 17, 72], ["+", 0, 7, 12, 652, 3, 4, 0, 664, 28, 612], ["-"...
5
137
#include <bits/stdc++.h> using namespace std; int main() { int n, sum = 0; cin >> n; vector<int> arr; for (int i = 0; i < n; i++) { int x; cin >> x; arr.push_back(x); sum += x; } sum = ceil(sum / n); int ans = 0; for (int i = 0; i < arr.size(); i++) { int tmp = sum - arr[i]; if ...
#include <bits/stdc++.h> using namespace std; int main() { int n, sum = 0; cin >> n; vector<int> arr; for (int i = 0; i < n; i++) { int x; cin >> x; x += 200; arr.push_back(x); sum += x; } sum = round(double(sum) / (double)n); int ans = 0; for (int i = 0; i < arr.size(); i++) { ...
[["+", 0, 7, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 7, 8, 9, 0, 1, 0, 11, 17, 107], ["+", 0, 7, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 8, 9, 0, 7, 8, 9, 0, 1, 0, 35], ["-", 8, 9, 0, 1, 0, 11, 12, 2, 63, 22], ["+", 8, 9, 0, 1, 0, 11, 12, 2, 63, 22], ["+", 0, 1, 0, 11, 12, 2, 3, 4, 0, 24], ["+", 12, 2, 3, 4, 0, 16, 31, 2, 63, 4...
1
132
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; typedef long long ll; int main() { int n, ans = 999999, inf = 999999; cin >> n; vector<int> a(n); rep(i, n) cin >> a.at(i); sort(a.begin(), a.end()); int m = a.at(n - 1) - a.at(0); rep(k, m) { int tmp = 0; ...
#include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < n; i++) using namespace std; typedef long long ll; int main() { ll n, ans = 999999999, inf = 999999999; cin >> n; vector<ll> a(n); rep(i, n) cin >> a.at(i); sort(a.begin(), a.end()); ll m = a.at(n - 1) - a.at(0); rep(k, m) { ll tmp = 0; ...
[["-", 0, 30, 0, 14, 8, 9, 0, 43, 39, 40], ["+", 0, 30, 0, 14, 8, 9, 0, 43, 39, 78], ["-", 0, 14, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 14, 8, 9, 0, 43, 49, 50, 51, 13], ["-", 0, 43, 39, 344, 3, 347, 0, 77, 39, 40], ["+", 0, 43, 39, 344, 3, 347, 0, 77, 39, 78], ["-", 8, 9, 0, 14, 8, 9, 0, 43, 39, 40], ["+", 8, 9, 0, 1...
1
173
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a; vector<int> b(201); for (int i = 0; i < n; i++) { cin >> a.at(i); } for (int i = -100; i < 201; i++) { for (int j = 0; j < n; j++) b.at(i) += (a.at(j) - i) * (a.at(j) - i); } sort(b.begin(), b.end(...
#include <bits/stdc++.h> using namespace std; int main() { int n, ans; ans = 10000000; cin >> n; vector<int> a(n); vector<int> b(201); for (int i = 0; i < n; i++) { cin >> a.at(i); } for (int i = 0; i < 201; i++) { for (int j = 0; j < n; j++) b.at(i) += (a.at(j) - i + 100) * (a.at(j) - i +...
[["+", 0, 30, 0, 14, 8, 9, 0, 43, 0, 21], ["+", 0, 30, 0, 14, 8, 9, 0, 43, 49, 22], ["+", 0, 14, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 14, 8, 9, 0, 1, 0, 11, 17, 32], ["+", 0, 14, 8, 9, 0, 1, 0, 11, 12, 13], ["+", 0, 30, 0, 14, 8, 9, 0, 1, 0, 35], ["+", 8, 9, 0, 43, 49, 53, 54, 55, 0, 24], ["+", 0, 43, 49, 53, 54, 55, 0...
1
144
#include <bits/stdc++.h> using namespace std; int main() { int n, ans; ans = 10000000; cin >> n; vector<int> a; vector<int> b(201); for (int i = 0; i < n; i++) { cin >> a.at(i); } for (int i = -100; i < 101; i++) { int sum = 0; for (int j = 0; j < n; j++) sum += (a.at(j) - i) * (a.at(j...
#include <bits/stdc++.h> using namespace std; int main() { int n, ans; ans = 10000000; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a.at(i); } for (int i = -100; i < 101; i++) { int sum = 0; for (int j = 0; j < n; j++) sum += (a.at(j) - i) * (a.at(j) - i); ans = m...
[["-", 0, 30, 0, 14, 8, 9, 0, 43, 0, 35], ["-", 0, 14, 8, 9, 0, 43, 39, 344, 141, 78], ["-", 8, 9, 0, 43, 39, 344, 3, 347, 0, 18], ["-", 0, 43, 39, 344, 3, 347, 0, 77, 39, 40], ["-", 8, 9, 0, 43, 39, 344, 3, 347, 0, 47], ["-", 0, 14, 8, 9, 0, 43, 49, 50, 49, 22], ["-", 8, 9, 0, 43, 49, 50, 51, 4, 0, 13], ["+", 0, 43, 4...
1
139
def examC(): N = I() a = LI() lower = min(a) L = (max(a)-min(a)) cur = [0]*L for i in range(L): for j in range(N): cur[i] +=(a[j]-(i+lower))**2 ans = min(cur) print(ans) import sys def I(): return int(sys.stdin.readline()) def LI(): return list(map(int,sys.stdin.read...
def examC(): N = I() a = LI() lower = min(a) L = (max(a)-min(a)) cur = [0]*L for i in range(L): for j in range(N): cur[i] +=(a[j]-(i+lower))**2 if cur: ans = min(cur) else:ans = 0 print(ans) import sys def I(): return int(sys.stdin.readline()) def LI(): r...
[["+", 0, 656, 0, 14, 8, 196, 0, 57, 0, 121], ["+", 0, 656, 0, 14, 8, 196, 0, 57, 15, 22], ["+", 0, 656, 0, 14, 8, 196, 0, 57, 0, 102], ["+", 0, 14, 8, 196, 0, 57, 75, 76, 0, 95], ["+", 0, 14, 8, 196, 0, 57, 75, 76, 0, 102], ["+", 75, 76, 8, 196, 0, 1, 0, 662, 31, 22], ["+", 75, 76, 8, 196, 0, 1, 0, 662, 0, 32], ["+", ...
5
181
#include <stdio.h> int main(void) { int n, x[101], min = 101, max = -101, min2 = 10000, g, i, j; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d", &x[i]); if (min > x[i]) min = x[i]; if (max < x[i]) max = x[i]; } for (i = min; i <= max; i++) { g = 0; for (j = 0; j < n; j++...
#include <limits.h> #include <stdio.h> int main(void) { int n, x[101], min = 101, max = -101, min2 = INT_MAX, g, i, j; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d", &x[i]); if (min > x[i]) min = x[i]; if (max < x[i]) max = x[i]; } for (i = min; i <= max; i++) { g = 0; ...
[["+", 36, 36, 36, 36, 0, 30, 0, 135, 136, 137], ["+", 36, 36, 36, 36, 0, 30, 0, 135, 0, 138], ["-", 0, 14, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 14, 8, 9, 0, 43, 49, 50, 51, 22]]
0
186
#include <bits/stdc++.h> using namespace std; int main() { int N, ave = 0; cin >> N; vector<int> a(N); for (int i = 0; i < N; i++) { cin >> a.at(i); } for (int i = 0; i < N; i++) { ave += a.at(i); } ave /= N; int j, m, M, cost = 0, tmp = 0; m = max(ave - 2, -100); M = min(ave + 2, 100); ...
#include <bits/stdc++.h> using namespace std; int main() { int N, ave = 0; cin >> N; vector<int> a(N); for (int i = 0; i < N; i++) { cin >> a.at(i); } for (int i = 0; i < N; i++) { ave += a.at(i); } ave /= N; int j, m, M, cost = 0, tmp = 0; m = max(ave - 2, -100); M = min(ave + 2, 100); ...
[["-", 0, 57, 64, 9, 0, 1, 0, 27, 28, 22], ["-", 0, 57, 64, 9, 0, 1, 0, 27, 17, 29], ["-", 8, 9, 0, 57, 64, 9, 0, 1, 0, 35], ["-", 0, 52, 8, 9, 0, 57, 75, 76, 0, 95], ["-", 8, 9, 0, 57, 75, 76, 0, 9, 0, 45], ["+", 8, 9, 0, 52, 8, 9, 0, 1, 0, 35], ["+", 0, 52, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 52, 8, 9, 0, 1, 0, 11, ...
1
242
l_si = input().split(" ") l_si_i = [int(s) for s in l_si] sm = sum(l_si_i) av = round(sm /dv) ret = 0 for it in l_si_i: ret = ret + (it -av) **2 print(ret)
dv = int(input()) l_si = input().split(" ") l_si_i = [int(s) for s in l_si] sm = sum(l_si_i) av = round(sm /dv) ret = 0 for it in l_si_i: ret = ret + (it -av) **2 print(ret)
[["+", 36, 36, 0, 656, 0, 1, 0, 662, 31, 22], ["+", 36, 36, 0, 656, 0, 1, 0, 662, 0, 32], ["+", 0, 656, 0, 1, 0, 662, 12, 652, 63, 22], ["+", 0, 1, 0, 662, 12, 652, 3, 4, 0, 24], ["+", 0, 662, 12, 652, 3, 4, 0, 652, 63, 22], ["+", 12, 652, 3, 4, 0, 652, 3, 4, 0, 24], ["+", 12, 652, 3, 4, 0, 652, 3, 4, 0, 25], ["+", 0, ...
5
61
#include <bits/stdc++.h> // For ordered_set #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define MOD 1000000007 #define test \ int t; \ cin >> t; ...
#include <bits/stdc++.h> // For ordered_set #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define MOD 1000000007 #define test \ int t; \ cin >> t; ...
[["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 22], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 13], ["-", 0, 1, 0, 2, 3, 4, 0, 16, 31, 22], ["-", 0, 1, 0, 2, 3, 4, 0, 16, 17, 72], ["-", 0, 1, 0, 2, 3, 4, 0, 16, 12, 13], ["-", 0, 16, 31, 23, 0, 16, 12, 69, 28, 22], ["-", 31, 23, 0, 16, 12, 69, 341, 342, 0, 70], ["-", 31, 23, 0, 16, 12, 69, 34...
1
537
#include <bits/stdc++.h> #define forn(i, n) for (int i = 0; i < int(n); i++) using namespace std; typedef long long ll; int main() { int n; int a[100]; cin >> n; int small = INT_MAX; int large = INT_MIN; forn(i, n) { cin >> a[i]; small = min(small, a[i]); large = max(large, a[i]); } int s...
#include <bits/stdc++.h> #define forn(i, n) for (int i = 0; i < int(n); i++) using namespace std; typedef long long ll; int main() { int n; int a[100]; cin >> n; int small = INT_MAX; int large = INT_MIN; forn(i, n) { cin >> a[i]; small = min(small, a[i]); large = max(large, a[i]); } int s...
[["-", 8, 9, 0, 1, 0, 11, 12, 2, 63, 22], ["+", 8, 9, 0, 1, 0, 11, 12, 2, 63, 22], ["+", 0, 1, 0, 11, 12, 2, 3, 4, 0, 21], ["+", 0, 1, 0, 11, 12, 2, 3, 4, 0, 13], ["-", 8, 9, 0, 1, 0, 16, 12, 2, 63, 22], ["-", 0, 1, 0, 16, 12, 2, 3, 4, 0, 24], ["-", 0, 1, 0, 16, 12, 2, 3, 4, 0, 21], ["-", 0, 1, 0, 16, 12, 2, 3, 4, 0, 1...
1
152
#include <algorithm> #include <bitset> #include <cctype> #include <cmath> #include <cstdio> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <vector> using namespace std; #define REP(i, n) for (int i = 0; i < (int)(n); i++) #define RREP(i, n) for (int i ...
#include <algorithm> #include <bitset> #include <cctype> #include <cmath> #include <cstdio> #include <cstring> #include <iomanip> #include <iostream> #include <map> #include <queue> #include <set> #include <vector> using namespace std; #define REP(i, n) for (int i = 0; i < (int)(n); i++) #define RREP(i, n) for (int i ...
[["-", 0, 30, 0, 14, 8, 9, 0, 57, 0, 121], ["-", 0, 14, 8, 9, 0, 57, 15, 339, 0, 24], ["-", 0, 57, 15, 339, 51, 16, 31, 69, 28, 22], ["-", 15, 339, 51, 16, 31, 69, 341, 342, 0, 70], ["-", 15, 339, 51, 16, 31, 69, 341, 342, 0, 13], ["-", 15, 339, 51, 16, 31, 69, 341, 342, 0, 73], ["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, ...
1
364
N = int(input()) A = map(int, input().split()) m = round(sum(A) / N) print(sum(list(map(lambda x: (x-m)**2,A))))
N = int(input()) A = list(map(int, input().split())) m = round(sum(A) / N) t = sum(list(map(lambda x: (x - m) ** 2, A))) print(t)
[["+", 0, 656, 0, 1, 0, 662, 12, 652, 63, 22], ["+", 0, 1, 0, 662, 12, 652, 3, 4, 0, 24], ["+", 0, 1, 0, 662, 12, 652, 3, 4, 0, 25], ["-", 36, 36, 0, 656, 0, 1, 0, 652, 63, 22], ["-", 0, 656, 0, 1, 0, 652, 3, 4, 0, 24], ["+", 36, 36, 0, 656, 0, 1, 0, 662, 31, 22], ["+", 36, 36, 0, 656, 0, 1, 0, 662, 0, 32], ["+", 36, 3...
5
57
#include <bits/stdc++.h> #define rep(i, n, k) for (long long int i = k; i < n; ++i) #define drep(i, n, k) for (long long int i = n - 1; i >= k; --i) using namespace std; int main() { int n; long long int ans = 0; cin >> n; vector<int> s(n); rep(i, n, 0) { cin >> s[i]; ans += s[i] * s[i]; } sort(s...
#include <bits/stdc++.h> #define rep(i, n, k) for (long long int i = k; i < n; ++i) #define drep(i, n, k) for (long long int i = n - 1; i >= k; --i) using namespace std; int main() { int n; long long int ans = 0; cin >> n; vector<int> s(n); rep(i, n, 0) { cin >> s[i]; ans += s[i] * s[i]; } sort(s...
[["+", 0, 30, 0, 14, 8, 9, 0, 57, 0, 121], ["+", 0, 14, 8, 9, 0, 57, 15, 339, 0, 24], ["+", 0, 57, 15, 339, 51, 16, 31, 69, 28, 22], ["+", 15, 339, 51, 16, 31, 69, 341, 342, 0, 70], ["+", 15, 339, 51, 16, 31, 69, 341, 342, 0, 13], ["+", 15, 339, 51, 16, 31, 69, 341, 342, 0, 73], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, ...
1
172
#include <iostream> using namespace std; int main() { int n; cin >> n; int a[n]; cin >> a[0]; int min, max; min = max = a[0]; for (int i = 1; i < n; ++i) { cin >> a[i]; min = min < a[i] ? min : a[i]; max = max < a[i] ? a[i] : max; } int mmin = 20000; for (int i = min; i <= max; ++i) { ...
#include <iostream> using namespace std; int main() { int n; cin >> n; int a[n]; cin >> a[0]; int min, max; min = max = a[0]; for (int i = 1; i < n; ++i) { cin >> a[i]; min = min < a[i] ? min : a[i]; max = max < a[i] ? a[i] : max; } int mmin = (100 - (-100)) * (100 - (-100)) * 100; for (...
[["-", 0, 14, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 49, 50, 51, 16, 31, 16, 31, 23, 0, 24], ["+", 51, 16, 31, 16, 31, 23, 0, 16, 31, 13], ["+", 51, 16, 31, 16, 31, 23, 0, 16, 17, 33], ["+", 31, 16, 31, 23, 0, 16, 12, 23, 0, 24], ["+", 31, 16, 31, 23, 0, 16, 12, 23, 0, 13], ["+", 31, 16, 31, 23, 0, 16, 12, 23, 0, 25], ["+...
1
182
import math n = int(input()) l = list(map(int, input().split())) ave = math.ceil(sum(l) / len(l)) print(sum(list(map(lambda x: (x-ave)**2, l))))
n = int(input()) l = list(map(int, input().split())) ave = round(sum(l) / n) print(sum(list(map(lambda x: (x-ave)**2, l))))
[["-", 36, 36, 36, 36, 0, 656, 0, 596, 0, 487], ["-", 36, 36, 0, 656, 0, 596, 141, 673, 0, 22], ["-", 0, 1, 0, 662, 12, 652, 63, 319, 500, 22], ["-", 0, 1, 0, 662, 12, 652, 63, 319, 0, 131], ["-", 0, 1, 0, 662, 12, 652, 63, 319, 319, 22], ["+", 0, 656, 0, 1, 0, 662, 12, 652, 63, 22], ["-", 12, 652, 3, 4, 0, 657, 12, 65...
5
67
#include <bits/stdc++.h> using namespace std; int N; int main() { cin >> N; vector<int> a(N); static float ave; for (int i = 0; i < N; i++) { cin >> a[i]; ave += a[i]; } ave /= N; static int ans; for (int i = 0; i < N; i++) { ans = (ave - a[i]) * (ave - a[i]); } cout << ans << endl; }
#include <bits/stdc++.h> using namespace std; int N; int main() { cin >> N; vector<int> a(N); float sum; for (int i = 0; i < N; i++) { cin >> a[i]; sum += a[i]; } int ave; ave = round(sum / N); int ans = 0; for (int i = 0; i < N; i++) { ans += (ave - a[i]) * (ave - a[i]); } cout << a...
[["-", 0, 14, 8, 9, 0, 43, 0, 114, 0, 115], ["-", 0, 30, 0, 14, 8, 9, 0, 43, 49, 22], ["+", 0, 30, 0, 14, 8, 9, 0, 43, 49, 22], ["-", 0, 7, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 7, 8, 9, 0, 1, 0, 11, 31, 22], ["+", 0, 30, 0, 14, 8, 9, 0, 43, 39, 40], ["-", 0, 14, 8, 9, 0, 1, 0, 11, 17, 90], ["+", 0, 30, 0, 14, 8, 9, 0, ...
1
112
#include <algorithm> #include <cmath> #include <deque> #include <iostream> #include <numeric> #include <queue> #include <sstream> #include <string.h> #include <string> #include <tuple> #include <vector> #define REP(i, x) for (int i{0}; i < (int)(x); i++) #define REPC(i, x) for (int i{0}; i <= (int)(x); i++) #define RR...
#include <algorithm> #include <cmath> #include <deque> #include <iostream> #include <numeric> #include <queue> #include <sstream> #include <string.h> #include <string> #include <tuple> #include <vector> #define REP(i, x) for (int i{0}; i < (int)(x); i++) #define REPC(i, x) for (int i{0}; i <= (int)(x); i++) #define RR...
[["-", 0, 14, 8, 9, 0, 1, 0, 2, 63, 22], ["+", 0, 30, 0, 14, 8, 9, 0, 7, 0, 88], ["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 22], ["-", 8, 9, 0, 1, 0, 2, 3, 4, 0, 21], ["+", 0, 14, 8, 9, 0, 7, 10, 43, 39, 40], ["+", 8, 9, 0, 7, 10, 43, 49, 50, 49, 22], ["+", 8, 9, 0, 7, 10, 43, 49, 50, 0, 32], ["+", 8, 9, 0, 7, 10, 43, 49, 50, 51...
1
404
#include <iostream> #include <vector> using namespace std; int main(void) { int N, i, tmp, sum, average, cost; vector<int> a; // get input ----------------------------- cin >> N; sum = 0; for (i = 0; i < N; i++) { cin >> tmp; sum += tmp; a.push_back(tmp); } // get average -----------------...
#include <cmath> #include <iostream> #include <vector> using namespace std; int main(void) { int N, i, tmp, sum, cost, average; double _average; vector<int> a; // get input ----------------------------- cin >> N; sum = 0; for (i = 0; i < N; i++) { cin >> tmp; sum += tmp; a.push_back(tmp); ...
[["+", 36, 36, 36, 36, 0, 30, 0, 135, 136, 137], ["+", 36, 36, 36, 36, 0, 30, 0, 135, 0, 138], ["-", 0, 30, 0, 14, 8, 9, 0, 43, 0, 21], ["-", 0, 30, 0, 14, 8, 9, 0, 43, 49, 22], ["+", 0, 30, 0, 14, 8, 9, 0, 43, 0, 21], ["+", 0, 30, 0, 14, 8, 9, 0, 43, 49, 22], ["+", 0, 30, 0, 14, 8, 9, 0, 43, 0, 35], ["+", 0, 30, 0, 14...
1
130
from math import ceil n = int(input()) x = list(map(int,input().split())) # y = set(x) ans = ceil(sum(x)/n) g = 0 for i in x: g += (i-ans)**2 print(g)
n = int(input()) x = list(map(int,input().split())) y = round(sum(x)/n) g = 0 for i in x: g += (i-y)**2 print(g)
[["-", 36, 36, 36, 36, 0, 656, 0, 686, 0, 314], ["-", 36, 36, 0, 656, 0, 686, 687, 673, 0, 22], ["-", 36, 36, 36, 36, 0, 656, 0, 686, 0, 487], ["-", 36, 36, 0, 656, 0, 686, 141, 673, 0, 22], ["-", 36, 36, 0, 656, 0, 1, 0, 662, 31, 22], ["+", 36, 36, 0, 656, 0, 1, 0, 662, 31, 22], ["-", 0, 656, 0, 1, 0, 662, 12, 652, 63...
5
62
n=int(input()) a=[int(i) for i in input().split()] check=float('inf') for i in range(-100,101): check2=0 for j in a: check2+=(i-j)**2 if check>check2: check=check2 ans=i print(ans)
n=int(input()) a=[int(i) for i in input().split()] check=float('inf') for i in range(-100,101): ans=0 for j in a: ans+=(i-j)**2 if check>ans: check=ans print(check)
[["-", 0, 7, 8, 196, 0, 1, 0, 662, 31, 22], ["+", 0, 7, 8, 196, 0, 1, 0, 662, 31, 22], ["-", 0, 7, 8, 196, 0, 1, 0, 677, 31, 22], ["+", 0, 7, 8, 196, 0, 1, 0, 677, 31, 22], ["-", 0, 7, 8, 196, 0, 57, 15, 666, 0, 22], ["+", 0, 7, 8, 196, 0, 57, 15, 666, 0, 22], ["-", 0, 57, 64, 196, 0, 1, 0, 662, 12, 22], ["-", 0, 57, 6...
5
77
n = int(input()) a = list(map(int, input().split())) print(n) print(a) costs = [] for i in range(-100, 101): cost = 0 for j in range(n): cost += (a[j] - i) * (a[j] - i) costs.append(cost) print(min(costs))
n = int(input()) a = list(map(int, input().split())) costs = [] for i in range(-100, 101): cost = 0 for j in range(n): cost += (a[j] - i) * (a[j] - i) costs.append(cost) print(min(costs))
[["-", 36, 36, 0, 656, 0, 1, 0, 652, 63, 22], ["-", 0, 656, 0, 1, 0, 652, 3, 4, 0, 24], ["-", 0, 656, 0, 1, 0, 652, 3, 4, 0, 22], ["-", 0, 656, 0, 1, 0, 652, 3, 4, 0, 25]]
5
91
#include <cmath> #include <iostream> using namespace std; int main() { int n; cin >> n; int a[n]; int sum = 0; for (int i = 1; i <= n; i++) { cin >> a[i]; sum += a[i]; } int j = round(double(sum / n)); int o = 0; for (int i = 1; i <= n; i++) { o += (a[i] - j) * (a[i] - j); } cout << o;...
#include <cmath> #include <iostream> using namespace std; int main() { int n; cin >> n; int a[102]; long long sum = 0; for (int i = 1; i <= n; i++) { cin >> a[i]; sum += a[i]; } long long j = round(double(sum) / n); int o = 0; for (int i = 1; i <= n; i++) { o += (a[i] - j) * (a[i] - j); ...
[["-", 0, 14, 8, 9, 0, 43, 49, 80, 81, 22], ["+", 0, 14, 8, 9, 0, 43, 49, 80, 81, 13], ["-", 0, 30, 0, 14, 8, 9, 0, 43, 39, 40], ["+", 0, 14, 8, 9, 0, 43, 39, 86, 0, 96], ["+", 3, 4, 0, 16, 31, 2, 3, 4, 0, 25], ["-", 51, 2, 3, 4, 0, 2, 3, 4, 0, 25]]
1
120
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef double D; typedef vector<int> VI; typedef vector<ll> VL; typedef pair<int, int> PII; typedef pair<ll, ll> PLL; #define rd(x) scanf("%d", &x) #define rd2(x, y) scanf("%d %d", &x, &y) #define rl(x) scanf("%lld", &x) #define rl2(x, y) scanf("%ll...
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef double D; typedef vector<int> VI; typedef vector<ll> VL; typedef pair<int, int> PII; typedef pair<ll, ll> PLL; #define rd(x) scanf("%d", &x) #define rd2(x, y) scanf("%d %d", &x, &y) #define rl(x) scanf("%lld", &x) #define rl2(x, y) scanf("%ll...
[["+", 0, 30, 0, 14, 8, 9, 0, 43, 0, 21], ["+", 0, 14, 8, 9, 0, 43, 49, 50, 49, 22], ["+", 0, 14, 8, 9, 0, 43, 49, 50, 0, 32], ["+", 0, 14, 8, 9, 0, 43, 49, 50, 51, 22], ["+", 0, 30, 0, 14, 8, 9, 0, 43, 0, 35], ["+", 0, 14, 8, 9, 0, 1, 0, 2, 63, 22], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 24], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0...
1
284
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<int> a(N); for (int i = 0; i < N; i++) { cin >> a.at(i); } sort(a.begin(), a.end()); float sum; float ave; sum = accumulate(a.begin(), a.end(), 0); ave = sum / a.size(); int y = int(ave + 0.5); int ans = 0; ...
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; vector<int> a(N); for (int i = 0; i < N; i++) { cin >> a.at(i); } sort(a.begin(), a.end()); float sum; float ave; sum = accumulate(a.begin(), a.end(), 0); ave = sum / a.size(); int y = round(ave); int ans = 0; for ...
[["-", 8, 9, 0, 43, 49, 50, 51, 2, 63, 40], ["+", 8, 9, 0, 43, 49, 50, 51, 2, 63, 22], ["-", 49, 50, 51, 2, 3, 4, 0, 16, 17, 72], ["-", 49, 50, 51, 2, 3, 4, 0, 16, 12, 13], ["-", 8, 9, 0, 1, 0, 11, 12, 2, 63, 22], ["-", 0, 1, 0, 11, 12, 2, 3, 4, 0, 24], ["-", 0, 1, 0, 11, 12, 2, 3, 4, 0, 21], ["-", 0, 1, 0, 11, 12, 2, ...
1
157
#include <bits/stdc++.h> using namespace std; int n, ar[2000]; int main() { while (cin >> n) { for (int i = 0; i < n; i++) scanf("%d", ar + i); int mncost = INT_MAX; for (int i = ar[0]; i <= ar[n - 1]; i++) { int cost = 0; for (int j = 0; j <= n - 1; j++) cost += (int)abs(...
#include <bits/stdc++.h> using namespace std; int n, ar[2000]; int main() { while (cin >> n) { for (int i = 0; i < n; i++) scanf("%d", ar + i); sort(ar, ar + n); int mncost = INT_MAX; for (int i = ar[0]; i <= ar[n - 1]; i++) { int cost = 0; for (int j = 0; j <= n - 1; j++) ...
[["+", 0, 52, 8, 9, 0, 1, 0, 2, 63, 22], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 24], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 22], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 21], ["+", 0, 1, 0, 2, 3, 4, 0, 16, 31, 22], ["+", 0, 1, 0, 2, 3, 4, 0, 16, 17, 72], ["+", 0, 1, 0, 2, 3, 4, 0, 16, 12, 22], ["+", 8, 9, 0, 1, 0, 2, 3, 4, 0, 25], ["+", 8...
1
150
N = int(input()) A = list(map(int, input().split())) ttl1, ttl2, ttl3 = 0, 0, 0 avarage1 = -(-sum(A) // N) avarage2 = sum(A) // N for i in A: ttl1 += (i - avarage1) ** 2 ttl2 += (i - avarage2) ** 2 ttl3 += (i - avarage3) ** 2 print(min(ttl1, ttl2, ttl3))
N = int(input()) A = list(map(int, input().split())) ttl1, ttl2, ttl3 = 0, 0, 0 avarage1 = -(-sum(A) // N) avarage2 = sum(A) // N for i in A: ttl1 += (i - avarage1) ** 2 ttl2 += (i - avarage2) ** 2 print(min(ttl1, ttl2))
[["-", 0, 7, 8, 196, 0, 1, 0, 677, 31, 22], ["-", 0, 7, 8, 196, 0, 1, 0, 677, 17, 107], ["-", 0, 1, 0, 677, 12, 657, 31, 23, 0, 24], ["-", 0, 677, 12, 657, 31, 23, 0, 657, 31, 22], ["-", 0, 677, 12, 657, 31, 23, 0, 657, 17, 33], ["-", 0, 677, 12, 657, 31, 23, 0, 657, 12, 22], ["-", 0, 1, 0, 677, 12, 657, 31, 23, 0, 25]...
5
99
N = int(input()) A = list(map(int, input().split())) total_costs = {} if( len(set(A)) == 1 ): print(0) else: for i in range(0, 100): cost = 0 for a in A: cost += (a - i)*(a - i) total_costs[i] = cost print(min(total_costs.values()))
N = int(input()) A = list(map(int, input().split())) total_costs = {} if( len(set(A)) == 1 ): print(0) else: for i in range(-100, 101): cost = 0 for a in A: cost += (a - i)**2 total_costs[i] = cost print(min(total_costs.values()))
[["-", 8, 196, 0, 7, 12, 652, 3, 4, 0, 612], ["-", 8, 196, 0, 7, 12, 652, 3, 4, 0, 21], ["+", 0, 7, 12, 652, 3, 4, 0, 664, 17, 33], ["+", 8, 196, 0, 7, 12, 652, 3, 4, 0, 21], ["+", 8, 196, 0, 7, 12, 652, 3, 4, 0, 612], ["-", 8, 196, 0, 1, 0, 677, 12, 657, 17, 48], ["-", 0, 1, 0, 677, 12, 657, 12, 23, 0, 24], ["-", 0, 6...
5
96
# encoding:utf-8 import copy import random import bisect #bisect_left これで二部探索の大小検索が行える import fractions #最小公倍数などはこっち import math import sys mod = 10**9+7 sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000 def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(): return [list(map(int, l.split())) for l in...
# encoding:utf-8 import copy import random import bisect #bisect_left これで二部探索の大小検索が行える import fractions #最小公倍数などはこっち import math import sys mod = 10**9+7 sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000 def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(): return [list(map(int, l.split())) for l in...
[["+", 36, 36, 36, 36, 0, 656, 0, 57, 0, 121], ["+", 0, 656, 0, 57, 15, 666, 0, 652, 63, 22], ["+", 0, 57, 15, 666, 0, 652, 3, 4, 0, 24], ["+", 15, 666, 0, 652, 3, 4, 0, 652, 63, 22], ["+", 0, 652, 3, 4, 0, 652, 3, 4, 0, 24], ["+", 0, 652, 3, 4, 0, 652, 3, 4, 0, 22], ["+", 0, 652, 3, 4, 0, 652, 3, 4, 0, 25], ["+", 0, 5...
5
258
#include <iostream> #include <math.h> #define ll long long int using namespace std; int main() { int N; cin >> N; int a[110]; int min = 100; int max = -100; for (int i = 0; i < N; ++i) { cin >> a[i]; if (a[i] > max) max = a[i]; if (a[i] < min) min = a[i]; } ll sum[210]; ll an...
#include <iostream> #include <math.h> #define ll long long int using namespace std; int main() { int N; cin >> N; int a[110]; int min = 100; int max = -100; for (int i = 0; i < N; ++i) { cin >> a[i]; if (a[i] > max) max = a[i]; if (a[i] < min) min = a[i]; } ll ans = 10000000000...
[["-", 0, 14, 8, 9, 0, 43, 49, 80, 49, 22], ["-", 0, 14, 8, 9, 0, 43, 49, 80, 0, 70], ["-", 0, 14, 8, 9, 0, 43, 49, 80, 81, 13], ["-", 0, 14, 8, 9, 0, 43, 49, 80, 0, 73], ["-", 0, 30, 0, 14, 8, 9, 0, 43, 0, 35], ["-", 0, 30, 0, 14, 8, 9, 0, 43, 39, 78], ["+", 8, 9, 0, 7, 8, 9, 0, 43, 39, 78], ["+", 0, 7, 8, 9, 0, 43, 4...
1
182
n=int(input()) l=list(map(int,input().split())) if n==4 and l[0]==-100: exit() s=2000000000000 for i in range(-100,101): su=0 for j in l: su+=(i-j)*(i-j) if su<s: s=su print(s)
n=int(input()) l=list(map(int,input().split())) s=2000000000000 for i in range(-100,101): su=0 for j in l: su+=(i-j)*(i-j) if su<s: s=su print(s)
[["-", 36, 36, 36, 36, 0, 656, 0, 57, 0, 121], ["-", 0, 656, 0, 57, 15, 679, 31, 666, 0, 22], ["-", 0, 656, 0, 57, 15, 679, 31, 666, 667, 60], ["-", 0, 656, 0, 57, 15, 679, 31, 666, 0, 612], ["-", 36, 36, 0, 656, 0, 57, 15, 679, 17, 355], ["-", 0, 57, 15, 679, 12, 666, 0, 206, 51, 22], ["-", 0, 57, 15, 679, 12, 666, 0,...
5
88
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf("%d", &n); int arr[n + 1]; int sum = 0; for (int i = 0; i < n; i++) { scanf("%d", &arr[i]); sum += arr[i]; } sum /= n; long long int ans = 0; for (int i = 0; i < n; i++) ans += (arr[i] - sum) * (arr[i] - sum); print...
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf("%d", &n); int arr[n + 1]; int sum = 0; for (int i = 0; i < n; i++) { scanf("%d", &arr[i]); sum += arr[i]; } sum = round(sum / (double)n); long long int ans = 0; for (int i = 0; i < n; i++) ans += (arr[i] - sum) * (ar...
[["-", 0, 14, 8, 9, 0, 1, 0, 11, 17, 90], ["+", 0, 14, 8, 9, 0, 1, 0, 11, 17, 32], ["+", 8, 9, 0, 1, 0, 11, 12, 2, 63, 22], ["+", 0, 1, 0, 11, 12, 2, 3, 4, 0, 24], ["+", 0, 11, 12, 2, 3, 4, 0, 16, 31, 22], ["+", 0, 11, 12, 2, 3, 4, 0, 16, 17, 85], ["+", 12, 2, 3, 4, 0, 16, 12, 74, 0, 24], ["+", 3, 4, 0, 16, 12, 74, 39,...
1
132
#include <bits/stdc++.h> using namespace std; typedef long long int lli; int main() { int N; cin >> N; int A[N]; for (int i = 0; i < N; i++) { cin >> A[i]; } sort(&A[0], &A[N]); lli minCost = 99999999999999999; for (int i = A[0]; i < A[N - 1]; i++) { lli cost = 0; for (int j = 0; j < N; j++)...
#include <bits/stdc++.h> using namespace std; typedef long long int lli; int main() { int N; cin >> N; int A[N]; for (int i = 0; i < N; i++) { cin >> A[i]; } sort(&A[0], &A[N]); lli minCost = LONG_MAX; for (int i = A[0]; i < A[N - 1]; i++) { lli cost = 0; for (int j = 0; j < N; j++) { ...
[["-", 0, 14, 8, 9, 0, 43, 49, 50, 51, 13], ["+", 0, 14, 8, 9, 0, 43, 49, 50, 51, 22], ["+", 0, 7, 8, 9, 0, 57, 64, 1, 0, 35], ["+", 0, 14, 8, 9, 0, 7, 8, 9, 0, 46], ["+", 0, 30, 0, 14, 8, 9, 0, 57, 0, 121], ["+", 0, 14, 8, 9, 0, 57, 15, 339, 0, 24], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 31, 22], ["+", 8, 9, 0, 57, 15, 3...
1
153
n=int(input()) a=[int(i) for i in input().split()] d=(max(a)+min(a)) t=[d//2,(d+1)//2] ans=[0]*2 for i in a: ans[0]+=(i-t[0])**2 ans[1]+=(i-t[1])**2 print(min(ans))
n=int(input()) a=[int(i) for i in input().split()] d=sum(a) t=[d//n,d//n+1] ans=[0]*2 for i in a: ans[0]+=(i-t[0])**2 ans[1]+=(i-t[1])**2 print(min(ans))
[["-", 0, 656, 0, 1, 0, 662, 12, 23, 0, 24], ["-", 0, 662, 12, 23, 0, 657, 31, 652, 63, 22], ["-", 12, 23, 0, 657, 31, 652, 3, 4, 0, 24], ["-", 12, 23, 0, 657, 31, 652, 3, 4, 0, 22], ["-", 12, 23, 0, 657, 31, 652, 3, 4, 0, 25], ["-", 0, 1, 0, 662, 12, 23, 0, 657, 17, 72], ["-", 0, 662, 12, 23, 0, 657, 12, 652, 63, 22],...
5
103
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> // Common file #include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update using namespace std; using namespace __gnu_pbds; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> o...
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> // Common file #include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update using namespace std; using namespace __gnu_pbds; typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> o...
[["-", 8, 9, 0, 43, 49, 50, 51, 74, 0, 24], ["-", 0, 43, 49, 50, 51, 74, 39, 77, 39, 40], ["-", 8, 9, 0, 43, 49, 50, 51, 74, 0, 25], ["-", 0, 43, 49, 50, 51, 74, 51, 2, 63, 22], ["+", 8, 9, 0, 43, 49, 50, 51, 2, 63, 22], ["-", 0, 14, 8, 9, 0, 43, 49, 50, 49, 22], ["+", 0, 14, 8, 9, 0, 43, 49, 50, 49, 22], ["-", 8, 9, 0...
1
151
#include <bits/stdc++.h> using namespace std; const long long mod = pow(10, 9) + 7; const long long MOD = 998244353; const long long INF = 1LL << 60; const int inf = pow(10, 9) + 7; template <class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> bool chmax(...
#include <bits/stdc++.h> using namespace std; const long long mod = pow(10, 9) + 7; const long long MOD = 998244353; const long long INF = 1LL << 60; const int inf = pow(10, 9) + 7; template <class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template <class T> bool chmax(...
[["-", 8, 9, 0, 43, 49, 50, 51, 2, 63, 22], ["-", 0, 43, 49, 50, 51, 2, 3, 4, 0, 24], ["-", 49, 50, 51, 2, 3, 4, 0, 2, 63, 22], ["-", 51, 2, 3, 4, 0, 2, 3, 4, 0, 24], ["+", 0, 14, 8, 9, 0, 43, 49, 50, 51, 22], ["+", 0, 30, 0, 14, 8, 9, 0, 43, 0, 35], ["+", 0, 30, 0, 14, 8, 9, 0, 7, 0, 88], ["-", 3, 4, 0, 16, 31, 23, 0,...
1
406
#include <algorithm> #include <iostream> #include <math.h> #include <vector> int main() { int n; std::cin >> n; std::vector<int> x(n); for (int i = 0; i < n; i++) { std::cin >> x[i]; } int min = *std::min_element(x.begin(), x.end()); int max = *std::max_element(x.begin(), x.end()); std::vector<in...
#include <algorithm> #include <cmath> #include <iostream> #include <vector> int main() { int n; std::cin >> n; std::vector<int> x(n); for (int i = 0; i < n; i++) { std::cin >> x[i]; } int min = *std::min_element(x.begin(), x.end()); int max = *std::max_element(x.begin(), x.end()); std::vector<int...
[["+", 36, 36, 36, 36, 0, 30, 0, 135, 136, 137], ["+", 36, 36, 36, 36, 0, 30, 0, 135, 0, 138], ["-", 36, 36, 36, 36, 0, 30, 0, 135, 136, 137], ["-", 36, 36, 36, 36, 0, 30, 0, 135, 0, 138], ["+", 0, 14, 8, 9, 0, 43, 49, 50, 0, 32], ["+", 0, 14, 8, 9, 0, 43, 49, 50, 51, 13], ["-", 0, 14, 8, 9, 0, 7, 15, 16, 17, 18], ["+"...
1
197
#include <cmath> #include <iostream> #include <vector> using namespace std; int main() { int N; int min = 100, max = -100; int cost = 10000000; vector<int> dataSet; cin >> N; for (int i = 0; i < N; ++i) { int input; cin >> input; min = (input < min) ? input : min; max = (input > max) ? inp...
#include <cmath> #include <iostream> #include <vector> using namespace std; int main() { int N; int min = 100, max = -100; int cost = 10000000; vector<int> dataSet; cin >> N; for (int i = 0; i < N; ++i) { int input; cin >> input; min = (input < min) ? input : min; max = (input > max) ? inp...
[["-", 0, 1, 0, 16, 31, 16, 31, 16, 31, 22], ["-", 0, 1, 0, 16, 31, 16, 31, 16, 17, 151], ["-", 0, 16, 31, 16, 31, 16, 12, 5, 0, 62], ["-", 0, 16, 31, 16, 31, 16, 12, 5, 0, 6], ["-", 8, 9, 0, 1, 0, 16, 31, 16, 17, 151], ["-", 8, 9, 0, 1, 0, 16, 31, 16, 12, 22], ["-", 0, 7, 8, 9, 0, 1, 0, 16, 17, 151], ["-", 0, 7, 8, 9,...
1
186
from functools import reduce def main(): # 一文字のみを読み込み # s = input().rstrip().split(' ') # スペース区切りで標準入力を配列として読み込み # s = input().rstrip().split(' ') # 位置文字ずつ標準入力を配列として読み込み # s = list(input().rstrip()) N = int(input().rstrip()) a_list = input().rstrip().split(' ') cost = 0 mi...
from functools import reduce def main(): # 初期値用:十分大きい数(100億) # 1e10 # 初期値用:十分小さい数(-100億) # -1e10 # 一文字のみを読み込み # s = input().rstrip().split(' ') # スペース区切りで標準入力を配列として読み込み # s = input().rstrip().split(' ') # 位置文字ずつ標準入力を配列として読み込み # s = list(input().rstrip()) N =...
[["-", 0, 14, 8, 196, 0, 1, 0, 662, 12, 531], ["+", 0, 1, 0, 662, 12, 657, 31, 657, 31, 612], ["+", 0, 1, 0, 662, 12, 657, 31, 657, 17, 48], ["+", 0, 1, 0, 662, 12, 657, 31, 657, 12, 612], ["+", 8, 196, 0, 1, 0, 662, 12, 657, 17, 48], ["+", 8, 196, 0, 1, 0, 662, 12, 657, 12, 612], ["-", 0, 662, 12, 657, 12, 657, 12, 23...
5
129
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; int a[110], sum = 0; for (int i = 0; i < N; i++) { cin >> a[i]; if (a[i] < 0) a[i] += 100; sum += a[i]; } double average = (double)sum / N; int target = (int)(average + 0.5); int ans = 0; for (int i = 0; i...
#include <bits/stdc++.h> using namespace std; int main() { int N; cin >> N; int a[110], sum = 0; for (int i = 0; i < N; i++) { cin >> a[i]; sum += a[i]; } double average = (double)sum / N; int target = round(average); int ans = 0; for (int i = 0; i < N; i++) { ans += (target - a[i]) * (...
[["-", 8, 9, 0, 7, 8, 9, 0, 57, 0, 121], ["-", 0, 7, 8, 9, 0, 57, 15, 339, 0, 24], ["-", 0, 57, 15, 339, 51, 16, 31, 69, 28, 22], ["-", 15, 339, 51, 16, 31, 69, 341, 342, 0, 70], ["-", 15, 339, 51, 16, 31, 69, 341, 342, 0, 22], ["-", 15, 339, 51, 16, 31, 69, 341, 342, 0, 73], ["-", 8, 9, 0, 57, 15, 339, 51, 16, 17, 18]...
1
144
#include <algorithm> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <functional> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; typedef ...
#include <algorithm> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <deque> #include <functional> #include <iostream> #include <list> #include <map> #include <queue> #include <set> #include <sstream> #include <stack> #include <string> #include <vector> using namespace std; typedef ...
[["-", 0, 14, 8, 9, 0, 14, 49, 53, 49, 22], ["+", 0, 30, 0, 14, 8, 9, 0, 7, 0, 88], ["+", 0, 14, 8, 9, 0, 7, 10, 43, 39, 40], ["-", 8, 9, 0, 14, 49, 53, 54, 55, 0, 21], ["-", 0, 14, 49, 53, 54, 55, 0, 56, 39, 78], ["+", 8, 9, 0, 7, 10, 43, 49, 50, 0, 32], ["+", 8, 9, 0, 7, 10, 43, 49, 50, 51, 13], ["+", 0, 14, 8, 9, 0,...
1
269
#include <stdio.h> int main() { int N; scanf("%d", &N); int a[N]; for (int i = 0; i < N; i++) { scanf("%d", &a[i]); } int max = -100, min = 100; for (int i = 0; i < N; i++) { if (a[i] > max) { max = a[i]; } if (a[i] < min) { min = a[i]; } } int Min = 10000000; for (in...
#include <stdio.h> int main() { int N; scanf("%d", &N); int a[N]; for (int i = 0; i < N; i++) { scanf("%d", &a[i]); } int max = -100, min = 100; for (int i = 0; i < N; i++) { if (a[i] > max) { max = a[i]; } if (a[i] < min) { min = a[i]; } } int Min = 10000000; for (in...
[["+", 0, 30, 0, 14, 8, 9, 0, 57, 0, 121], ["+", 0, 14, 8, 9, 0, 57, 15, 339, 0, 24], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 31, 22], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 17, 60], ["+", 8, 9, 0, 57, 15, 339, 51, 16, 12, 22], ["+", 0, 14, 8, 9, 0, 57, 15, 339, 0, 25], ["+", 0, 14, 8, 9, 0, 57, 64, 9, 0, 45], ["+", 0, 57, 64...
1
203
n=int(input()) a=list(map(int,input().split())) diff,ans=100000,100000 for x in range(min(a),max(a)+1): crnt=0 for aa in a: crnt+=(aa-x)**2 if crnt<diff: ans=crnt print(x)
n=int(input()) a=list(map(int,input().split())) ans=10**10 for x in range(min(a),max(a)+1): crnt=0 for aa in a: crnt+=(aa-x)**2 if crnt<ans: ans=crnt print(ans)
[["-", 0, 656, 0, 1, 0, 662, 31, 684, 0, 22], ["-", 0, 656, 0, 1, 0, 662, 31, 684, 0, 21], ["-", 0, 656, 0, 1, 0, 662, 12, 432, 0, 612], ["-", 0, 656, 0, 1, 0, 662, 12, 432, 0, 21], ["+", 0, 656, 0, 1, 0, 662, 12, 657, 31, 612], ["+", 0, 656, 0, 1, 0, 662, 12, 657, 17, 578], ["+", 0, 656, 0, 1, 0, 662, 12, 657, 12, 612...
5
79
#include <bits/stdc++.h> typedef long long ll; using namespace std; int main() { int N; cin >> N; vector<int> a(N); for (int i = 0; i < N; i++) { cin >> a[i]; } sort(a.begin(), a.end()); int min = 0; for (int n = 0; n < N; n++) { min += (a[0] - a[n]) * (a[0] - a[n]); } for (int i = a[1]; i ...
#include <bits/stdc++.h> typedef long long ll; using namespace std; int main() { int N; cin >> N; vector<int> a(N); for (int i = 0; i < N; i++) { cin >> a[i]; } sort(a.begin(), a.end()); int min = 0; for (int i = 0; i < N; i++) { min += (a[0] - a[i]) * (a[0] - a[i]); } for (int key = a[0] +...
[["-", 8, 9, 0, 7, 10, 43, 49, 50, 49, 22], ["+", 8, 9, 0, 7, 10, 43, 49, 50, 49, 22], ["-", 0, 14, 8, 9, 0, 7, 15, 16, 31, 22], ["+", 0, 14, 8, 9, 0, 7, 15, 16, 31, 22], ["-", 0, 14, 8, 9, 0, 7, 26, 27, 28, 22], ["+", 0, 14, 8, 9, 0, 7, 26, 27, 28, 22], ["-", 31, 23, 0, 16, 12, 69, 341, 342, 0, 22], ["+", 31, 23, 0, 1...
1
199
f = gets.to_i a = gets.split.map(&:to_i) ans = (a.min..a.max).each do |x| a.inject(0){ |sum, n| sum + (n-x)** 2 } #sumの初期値を0で初期化 end puts ans
f = gets.to_i a = gets.split.map(&:to_i) ans = [] (a.min..a.max).each do |x| count = a.inject(0){ |sum, n| sum + (n-x)** 2 } #sumの初期値を0で初期化 ans.push count end puts ans.min
[["+", 36, 36, 0, 493, 0, 662, 12, 516, 0, 70], ["+", 36, 36, 0, 493, 0, 662, 12, 516, 0, 73], ["+", 0, 652, 196, 737, 8, 736, 0, 662, 31, 22], ["+", 0, 652, 196, 737, 8, 736, 0, 662, 0, 32], ["+", 0, 652, 196, 737, 8, 736, 0, 652, 486, 22], ["+", 0, 652, 196, 737, 8, 736, 0, 652, 17, 131], ["+", 0, 652, 196, 737, 8, 7...
4
59