language
stringclasses 5
values | dataset
stringclasses 1
value | code
stringlengths 26
25k
| id
stringlengths 10
10
| test_IO
listlengths 1
1
|
---|---|---|---|---|
C++ | codenet | #include <math.h>
#include <stdio.h>
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
ll gcd(ll x, ll y) {
ll tmp = 0;
if (x < y) {
tmp = x;
x = y;
y = tmp;
}
while (y > 0) {
ll r = x % y;
x = y;
y = r;
}
return x;
}
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll kaijo(ll k) {
ll sum = 1;
for (ll i = 1; i <= k; ++i) {
sum *= i;
sum %= 1000000000 + 7;
}
return sum;
}
ll lmax(ll s, ll t) {
if (s > t) {
return s;
} else {
return t;
}
}
ll lmin(ll s, ll t) {
if (s < t) {
return s;
} else {
return t;
}
}
int main() {
int n, k;
cin >> n >> k;
ll sum = 0;
for (int b = 1; b <= n; b++) {
int cnt = (n + 1) / b;
int md = (n + 1) % b;
sum += cnt * max((b - k), 0) + max((md - k), 0);
if (k == 0) sum--;
}
cout << sum << endl;
return 0;
} | s438435664 | [
{
"input": "5 2\n",
"output": "7\n"
}
] |
C++ | codenet | #pragma GCC optimize("fast-math")
#pragma GCC optimize("unroll-loops")
#include <math.h>
#include <algorithm>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define DEBUG
#define fi first
#define se second
#define pqueue priority_queue
#define pb(x) push_back(x)
#define all(x) x.begin(), x.end()
#define int long long
#define mk(a, b) make_pair(a, b)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ull> vull;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef vector<pair<int, int> > vpii;
typedef pair<ll, ll> pll;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<vector<ll> > vvll;
typedef vector<char> vc;
const ll INF = 1e9 + 228;
const ll INFLL = 1e18;
const ll MOD = 1e9 + 7;
const ld eps = 1e-6;
const ld eps2 = 1e-9;
const ll MOD2 = 998244353;
const ll dosz = 5e5;
const ll SZ = (1 << 18);
const ld PI = atan2l(0, -1);
void fast_io() {
ios_base::sync_with_stdio(0);
cin.tie(0);
}
void solve() {
int n;
cin >> n;
vi nums(n);
int last = 0;
for (int i = 0; i < n; i++) {
cin >> nums[i];
}
vi dp(n + 1, 0);
dp[0] = 1;
map<int, int> kek;
map<int, int> prev;
for (int i = 1; i <= n; i++) {
dp[i] = dp[i - 1] + (prev[nums[i - 1]] != i - 1 ? kek[nums[i - 1]] : 0);
dp[i] %= MOD;
kek[nums[i - 1]] = dp[i];
prev[nums[i - 1]] = i;
}
cout << dp[n] << endl;
}
signed main() {
fast_io();
srand(time(NULL));
cout << fixed << setprecision(12);
int q = 1;
while (q--) solve();
} | s634121896 | [
{
"input": "5\n1\n2\n1\n2\n2\n",
"output": "3\n"
}
] |
C++ | codenet | #include <stdio.h>
int main(void) {
int n, k, x, y, z;
scanf("%d", &n);
scanf("%d", &k);
x = n / k;
y = n % k;
if (y != 0) {
z = x + 1 - x;
} else {
z = x - x;
}
printf("%d\n", z);
return 0;
} | s800506321 | [
{
"input": "7 3\n",
"output": "1\n"
}
] |
C++ | codenet | #include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <vector>
#define ll long long
#define For(i, x, y) for (ll i = x; i <= y; ++i)
#define FOr(i, x, y) for (ll i = x; i >= y; --i)
using namespace std;
inline ll read() {
ll x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
inline void write(ll x) {
if (x < 0) putchar('-'), x = -x;
if (x >= 10) write(x / 10);
putchar(x % 10 + '0');
}
inline void writeln(ll x) {
write(x);
puts("");
}
const ll N = 200010;
ll a[N], q[N], n, tot;
int main() {
n = read();
For(i, 1, n) a[i] = read();
sort(a + 1, a + n + 1);
For(i, 1, n) if (a[i] == a[i + 1]) q[++tot] = a[i], i++;
writeln(q[tot] * q[tot - 1]);
} | s447383972 | [
{
"input": "6\n3 1 2 4 2 1\n",
"output": "2\n"
}
] |
C++ | codenet | #include <stdio.h>
#include <string.h>
int main(void) {
char s[1000];
scanf("%s", s);
int i, flag = 0;
for (i = 0; i < strlen(s); i++) {
if (i % 2 == 0) {
switch (s[i]) {
case 'R':
break;
case 'U':
break;
case 'D':
break;
default:
flag = 1;
break;
}
} else {
switch (s[i]) {
case 'L':
break;
case 'U':
break;
case 'D':
break;
default:
flag = 1;
break;
}
}
}
if (flag == 0) {
puts("Yes");
} else {
puts("No");
}
} | s495283729 | [
{
"input": "RUDLUDR\n",
"output": "Yes\n"
}
] |
C++ | codenet | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define FORR(i, a, b) for (int i = a; i >= b; --i)
#define pi M_PI
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
int main() {
int n;
cin >> n;
while (n--) {
int p, q;
cin >> p >> q;
int l = sqrt(p * p + q * q);
bool isprime = 1;
REP(i, l) REP(j, l) {
int x = i * i + j * j;
if (x <= 1 || x >= p * p + q * q) continue;
if ((i * p + j * q) % x == 0 && (i * q - j * p) % x == 0)
isprime = 0;
}
cout << (isprime ? "P" : "C") << endl;
}
return 0;
} | s973217665 | [
{
"input": "8\n10 0\n0 2\n-3 0\n4 2\n0 -13\n-4 1\n-2 -1\n3 -1\n",
"output": "C\nC\nP\nC\nC\nP\nP\nC\n"
}
] |
C++ | codenet | #include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#define INF 1000000000
using namespace std;
bool debug = false;
int main() {
int n, k, x, y;
cin >> n >> k >> x >> y;
int sum = 0;
for (int i = 1; i <= n; i++) {
if (i > k)
sum += y;
else
sum += x;
}
cout << sum << endl;
return 0;
} | s990022717 | [
{
"input": "5\n3\n10000\n9000\n",
"output": "48000\n"
}
] |
C++ | codenet | #include <iostream>
#include <vector>
int main() {
int n;
std::cin >> n;
std::vector<long long> a(n);
for (int i = 0; i < n; i++) {
std::cin >> a[i];
}
std::vector<long long> abs_a = a;
for (int i = 0; i < n; i++) {
if (abs_a[i] < 0) {
abs_a[i] = -abs_a[i];
}
}
long long ans = 0;
long long min = abs_a[0];
for (auto e : abs_a) {
ans += e;
if (min > e) {
min = e;
}
}
int num_negative = 0;
for (auto e : a) {
if (e < 0) {
num_negative++;
}
}
if (num_negative % 2) {
ans -= min * 2;
}
std::cout << ans << std::endl;
} | s194793609 | [
{
"input": "3\n-10 5 -4\n",
"output": "19\n"
}
] |
C++ | codenet | #define _GLIBCXX_DEBUG
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <string>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
#define ALL(v) (v).begin(), (v).end()
const int inf = 1e9;
const int mod = 1e9 + 7;
bool is_prime(ll x) {
for (ll i = 2; i * i <= x; i++)
if (x % i == 0) return false;
return true;
}
int main() {
int N;
cin >> N;
ll ans = 1;
for (int i = 2; i <= N; i++) {
if (is_prime((ll)i)) {
int NN = N;
int cnt = 0;
while (NN) {
cnt += NN / i;
NN /= i;
}
ans *= cnt + 1;
ans %= mod;
}
}
cout << ans << endl;
return 0;
} | s049366196 | [
{
"input": "3\n",
"output": "4\n"
}
] |
C++ | codenet | #include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <vector>
using namespace std;
typedef long long ll;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
#define MAX_V 100001
#define MOD 1000000007
typedef vector<vector<int> > Graph;
int main() {
int n;
cin >> n;
vector<int> ans(n);
for (int i = 0; i < n - 1; i++) {
int a;
cin >> a;
a--;
ans[a]++;
}
for (int i = 0; i < n; i++) cout << ans[i] << endl;
} | s575944217 | [
{
"input": "5\n1 1 2 2\n",
"output": "2\n2\n0\n0\n0\n"
}
] |
C++ | codenet | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> X(N);
vector<int> Y(N);
for (int i = 0; i < N; i++) {
cin >> X[i];
Y[i] = X[i];
}
sort(Y.begin(), Y.end());
int y = Y[N / 2];
for (int i = 0; i < N; i++) {
if (X[i] < Y[N / 2]) {
cout << Y[N / 2];
} else {
cout << Y[N / 2 - 1];
}
cout << endl;
}
return 0;
} | s107598592 | [
{
"input": "4\n2 4 4 3\n",
"output": "4\n3\n3\n4\n"
}
] |
C++ | codenet | #include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
string s;
cin >> s;
int cnt = 0;
for (int i = 0; i < n; i++) {
cnt++;
int j = i + 1;
for (; j < n; j++) {
if (s[i] != s[j]) {
break;
}
}
i = j - 1;
}
cout << cnt << endl;
} | s014089689 | [
{
"input": "10\naabbbbaaca\n",
"output": "5\n"
}
] |
C++ | codenet | #include <algorithm>
#include <cstring>
#include <iostream>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#define REP(i, k, n) for (int i = k; i < n; i++)
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
int main() {
int n;
cin >> n;
rep(i, n) {
string s;
cin >> s;
set<string> st;
st.insert(s);
REP(j, 1, s.size()) {
stringstream ss;
rep(k, j) { ss << s[k]; }
string res = ss.str();
stringstream ss2;
REP(k, j, s.size()) { ss2 << s[k]; }
string res2 = ss2.str();
string t = res;
reverse(res.begin(), res.end());
string t2 = res2;
reverse(res2.begin(), res2.end());
st.insert(t + t2);
st.insert(t2 + t);
st.insert(t + res2);
st.insert(res2 + t);
st.insert(res + t2);
st.insert(t2 + res);
st.insert(res + res2);
st.insert(res2 + res);
}
cout << st.size() << endl;
}
return 0;
} | s700281300 | [
{
"input": "4\naa\nabba\nabcd\nabcde\n",
"output": "1\n6\n12\n18\n"
}
] |
C++ | codenet | #include <iostream>
using namespace std;
int main() {
int A, B;
int ans = 0;
int out = 1;
cin >> A >> B;
while (out < B) {
out--;
out += A;
ans++;
}
cout << ans << endl;
return 0;
} | s934757053 | [
{
"input": "4 10\n",
"output": "3\n"
}
] |
C++ | codenet | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int a, b, c;
cin >> a >> b >> c;
if ((100 * a + 10 * b + c) % 4 == 0) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
} | s218395502 | [
{
"input": "4 3 2\n",
"output": "YES\n"
}
] |
C++ | codenet | #include <algorithm>
#include <iostream>
using namespace std;
long long N, A[1 << 18];
long long dp[1 << 18][2][20];
int main() {
cin >> N;
for (int i = 1; i <= N; i++) cin >> A[i];
for (int i = 0; i <= N; i++) {
for (int j = 0; j < 20; j++) {
dp[i][0][j] = -(1LL << 60);
dp[i][1][j] = -(1LL << 60);
}
}
dp[0][0][10] = 0;
for (int i = 1; i <= N; i++) {
for (int j = 6; j <= 14; j++) {
if (dp[i - 1][0][j] != (1LL << 60)) {
dp[i][1][j + 1] = max(dp[i][1][j + 1], dp[i - 1][0][j] + A[i]);
dp[i][0][j - 1] = max(dp[i][0][j - 1], dp[i - 1][0][j]);
}
if (dp[i - 1][1][j] != (1LL << 60)) {
dp[i][0][j - 1] = max(dp[i][0][j - 1], dp[i - 1][1][j]);
}
}
}
long long V = 10LL + (N / 2) - (N - (N / 2));
long long T1 = dp[N][0][V];
long long T2 = dp[N][1][V];
cout << max(T1, T2) << endl;
return 0;
} | s395011148 | [
{
"input": "6\n1 2 3 4 5 6\n",
"output": "12\n"
}
] |
C++ | codenet | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <set>
#include <vector>
using namespace std;
const int maxn = 1e5 + 5;
struct Node {
int x, y, id;
} node[maxn];
struct Edge {
int u, v, val;
bool operator<(const Edge &rhs) const { return val < rhs.val; }
} e[maxn << 1];
int par[maxn];
int n;
bool cmp1(const Node &a, const Node &b) { return a.x < b.x; }
bool cmp2(const Node &a, const Node &b) { return a.y < b.y; }
void init() {
for (int i = 0; i <= n; i++) par[i] = i;
}
int findpar(int x) { return par[x] = (par[x] == x ? x : findpar(par[x])); }
void unite(int x, int y) {
x = findpar(x), y = findpar(y);
if (x == y) return;
par[x] = y;
}
int main(int argc, char const *argv[]) {
cin >> n;
init();
for (int i = 1; i <= n; i++) {
scanf("%d%d", &node[i].x, &node[i].y);
node[i].id = i;
}
sort(node + 1, node + n + 1, cmp1);
int cnt = 0;
for (int i = 2; i <= n; i++)
e[cnt++] =
(Edge){node[i - 1].id, node[i].id, node[i].x - node[i - 1].x};
sort(node + 1, node + n + 1, cmp2);
for (int i = 2; i <= n; i++)
e[cnt++] =
(Edge){node[i - 1].id, node[i].id, node[i].y - node[i - 1].y};
sort(e, e + cnt);
long long ans = 0;
for (int i = 0; i < cnt; i++) {
int u = e[i].u, v = e[i].v, val = e[i].val;
if (findpar(u) == findpar(v)) continue;
unite(u, v);
ans += val;
}
cout << ans << endl;
return 0;
} | s350755479 | [
{
"input": "3\n1 5\n3 9\n7 8\n",
"output": "3\n"
}
] |
C++ | codenet | #include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
vector<vector<ll> > table;
vector<P> roads;
vector<P> qs;
int main() {
ll N, X;
cin >> N >> X;
ll ans = 0;
ll min = 1000000000;
for (int i = 0; i < N; i++) {
ll tmp;
cin >> tmp;
X -= tmp;
ans++;
if (tmp < min) min = tmp;
}
ans += X / min;
cout << ans << endl;
return 0;
} | s579031873 | [
{
"input": "3 1000\n120\n100\n140\n",
"output": "9\n"
}
] |
C++ | codenet | #include <math.h>
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
typedef long long ll;
using namespace std;
int main() {
int a, b;
cin >> a >> b;
string bstr = to_string(b);
int num = a * pow(10, bstr.length()) + b;
int i;
for (i = 1; i <= 100100; i++) {
if (i * i == num) break;
}
if (i > 100100)
cout << "No" << endl;
else
cout << "Yes" << endl;
} | s793402552 | [
{
"input": "1 21\n",
"output": "Yes\n"
}
] |
C++ | codenet | #include <math.h>
#include <iostream>
#include <string>
using namespace std;
int main(void) {
int n, x;
string s;
cin >> n;
for (int i = 1; i <= n; i++) {
x = i;
s = std::to_string(x);
if (x % 3 == 0 || x % 10 == 3) {
cout << " " << i;
continue;
} else {
int k = s.size();
while (k > 0) {
k = k - 1;
int j = pow(10, k);
if ((x / j) % 10 == 3) {
cout << " " << i;
break;
}
}
}
}
cout << endl;
return 0;
} | s121463387 | [
{
"input": "30\n",
"output": " 3 6 9 12 13 15 18 21 23 24 27 30\n"
}
] |
C++ | codenet | #include <iostream>
using namespace std;
int main() {
int n, a[101], i;
cin >> n;
for (i = 0; i < n; i++) cin >> a[i];
cout << a[n - 1];
for (i = 1; i < n; i++) cout << " " << a[n - i - 1];
cout << endl;
return 0;
} | s654970460 | [
{
"input": "5\n1 2 3 4 5\n",
"output": "5 4 3 2 1\n"
}
] |
C++ | codenet | #include <algorithm>
#include <cmath>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const int NMAX = 1000010;
ll fac[NMAX], finv[NMAX], inv[NMAX];
void init() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < NMAX; i++) {
fac[i] = fac[i - 1] * i % mod;
inv[i] = mod - inv[mod % i] * (mod / i) % mod;
finv[i] = finv[i - 1] * inv[i] % mod;
}
}
ll C(int n, int k) {
if (n < k) return 0;
if (n < 0 || k < 0) return 0;
return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
int main() {
init();
int X, Y;
cin >> X >> Y;
if ((X + Y) % 3 != 0) {
cout << 0 << endl;
return 0;
}
int n = (X + Y) / 3 + 1;
int k = 2 * (n - 1) - Y + 1;
cout << C(n - 1, k - 1) << endl;
return 0;
} | s582643375 | [
{
"input": "3 3\n",
"output": "2\n"
}
] |
C++ | codenet | #include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;
const long long int MOD = 1e9 + 7;
int main() {
int r;
cin >> r;
cout << r * r << endl;
} | s938564096 | [
{
"input": "2\n",
"output": "4\n"
}
] |
C++ | codenet | #include <cstdio>
#include <iostream>
using namespace std;
int main() {
int a, b, c;
cin >> a >> b >> c;
if (a + b >= c) {
printf("Yes\n");
} else {
printf("No\n");
}
return 0;
} | s459892612 | [
{
"input": "50 100 120\n",
"output": "Yes\n"
}
] |
C++ | codenet | #include <algorithm>
#include <iostream>
#include <vector>
int n, k, t;
std::vector<int> vec;
int ans = 1000000001;
int main() {
std::cin >> n >> k;
for (int i = 0; i < n; i++) {
std::cin >> t;
vec.push_back(t);
}
std::sort(vec.begin(), vec.end());
for (int i = 0; i + k - 1 < n; i++) {
int diff = vec[i + k - 1] - vec[i];
if (diff < ans) {
ans = diff;
}
}
std::cout << ans << std::endl;
} | s353226283 | [
{
"input": "5 3\n10\n15\n11\n14\n12\n",
"output": "2\n"
}
] |
C++ | codenet | #include <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#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;
}
const int INF = (1 << 30) - 1;
const ll INFLL = (1LL << 61) - 1;
const int MOD = 1000000007;
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
ll A, B, C, K;
cin >> A >> B >> C >> K;
if (A + B >= K) {
cout << min(A, K) << endl;
} else {
cout << A - (K - (A + B)) << endl;
}
} | s247537353 | [
{
"input": "2 1 1 3\n",
"output": "2\n"
}
] |
C++ | codenet | #include <stdio.h>
int main() {
int n, k;
long long int l = 0, r = 0;
scanf("%d%d", &n, &k);
if (k % 2 == 0) {
for (int i = 1; i <= n; i++)
if (i % k == k / 2)
l++;
else if (i % k == 0)
r++;
printf("%lld\n", l * l * l + r * r * r);
} else {
for (int i = 1; i <= n; i++)
if (i % k == 0) r++;
printf("%lld\n", r * r * r);
}
} | s323607209 | [
{
"input": "3 2\n",
"output": "9\n"
}
] |
C++ | codenet | #include <stdlib.h>
#include <algorithm>
#include <iostream>
using namespace std;
int gcd(int a, int b) {
if (a == 0) return b;
return gcd(b % a, a);
}
int main() {
int R;
cin >> R;
if (R < 1200)
cout << "ABC" << endl;
else if (R >= 2800)
cout << "AGC" << endl;
else
cout << "ARC" << endl;
} | s628121241 | [
{
"input": "1199\n",
"output": "ABC\n"
}
] |
C++ | codenet | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <list>
#include <numeric>
#include <vector>
using namespace std;
int main() {
int N, M;
cin >> N >> M;
vector<int> L(100000);
int l;
for (int i = 0; i < N; i++) {
scanf("%d", &l);
L[i] = l;
}
sort(L.begin(), L.end());
vector<int>::iterator itr;
for (int i = 0; i < M; i++) {
int max_L = L.back();
if (max_L == 0) {
break;
}
max_L /= 2;
itr = lower_bound(L.begin(), L.end(), max_L);
L.insert(itr, max_L);
L.pop_back();
}
long long ans = accumulate(L.begin(), L.end(), 0LL);
cout << ans << '\n';
} | s013321508 | [
{
"input": "3 3\n2 13 8\n",
"output": "9\n"
}
] |
C++ | codenet | #include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PP;
ll key[1005] = {0};
ll cost[1005] = {0};
ll dp[(1 << 12) + 5][1005] = {0};
const ll INF = 123456789012;
int main() {
ll n, m;
cin >> n >> m;
for (int i = 0; i < (1 << 12) + 5; i++) {
for (int j = 0; j < 1005; j++) {
dp[i][j] = INF;
}
}
dp[0][0] = 0;
for (int i = 1; i <= m; i++) {
ll b;
cin >> cost[i] >> b;
for (int j = 0; j < b; j++) {
ll c;
cin >> c;
key[i] += (1 << (c - 1));
}
}
for (ll i = 0; i < (1 << n); i++) {
for (int j = 0; j < m; j++) {
dp[i][j + 1] = min(dp[i][j], dp[i][j + 1]);
dp[i | key[j + 1]][j + 1] =
min(dp[i | key[j + 1]][j + 1], dp[i][j] + cost[j + 1]);
}
}
if (dp[(1 << n) - 1][m] == INF)
cout << -1 << endl;
else
cout << dp[(1 << n) - 1][m] << endl;
} | s571001771 | [
{
"input": "2 3\n10 1\n1\n15 1\n2\n30 2\n1 2\n",
"output": "25\n"
}
] |
C++ | codenet | #include <algorithm>
#include <cstdlib>
#include <iostream>
#define INF 0x3f3f3f3f
using namespace std;
typedef long long LL;
const int MAXN = 2 * 1e5 + 10;
int a[MAXN], n, L[MAXN / 2], R[MAXN / 2];
LL merge(int left, int mid, int right) {
int i, j, k;
LL cnt = 0;
int n1 = mid - left;
int n2 = right - mid;
for (i = 0; i < n1; ++i) L[i] = a[left + i];
for (i = 0; i < n2; ++i) R[i] = a[mid + i];
L[n1] = R[n2] = INF;
i = j = 0;
for (k = left; k < right; ++k) {
if (L[i] <= R[j])
a[k] = L[i++];
else {
a[k] = R[j++];
cnt += n1 - i;
}
}
return cnt;
}
LL mergesort(int left, int right) {
int mid;
LL v1, v2, v3;
if (left + 1 < right) {
mid = (left + right) / 2;
v1 = mergesort(left, mid);
v2 = mergesort(mid, right);
v3 = merge(left, mid, right);
return v1 + v2 + v3;
}
return 0;
}
int main() {
ios::sync_with_stdio(false);
cin >> n;
for (int i = 0; i < n; ++i) cin >> a[i];
LL ans = mergesort(0, n);
cout << ans << '\n';
return 0;
} | s557795702 | [
{
"input": "5\n3 5 2 1 4\n",
"output": "6\n"
}
] |
C++ | codenet | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
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 = 1e18 + 1;
ll f(ll N) {
vector<ll> a(20, 0);
ll d = 0;
while (N > 0) {
a[d] = N % 10;
N /= 10;
d++;
}
double m = 1e18;
ll res = N;
for (int i = 0; i <= d; i++) {
ll bunsi = 0;
ll bunbo = 9 * i;
for (int j = d - 1; j >= 0; j--) {
bunsi *= 10;
if (j < i)
bunsi += 9;
else
bunsi += a[j];
if (j >= i) bunbo += a[j];
}
double frac = (double)bunsi / (double)bunbo;
if (frac < m) {
m = frac;
res = bunsi;
}
}
return res;
}
int main() {
ll K;
cin >> K;
ll N = f(1);
for (ll i = 0; i < K; i++) {
cout << N << endl;
N = f(N + 1);
}
} | s098326932 | [
{
"input": "10\n",
"output": "1\n2\n3\n4\n5\n6\n7\n8\n9\n19\n"
}
] |
C++ | codenet | #include <iostream>
using namespace std;
static const int N = 100;
static const int WHITE = 0;
static const int GRAY = 1;
static const int BLACK = 2;
int M[N][N], n;
int color[N], d[N], f[N], tt;
void dfs_visit(int u) {
int v;
color[u] = GRAY;
d[u] = ++tt;
for (v = 0; v < n; v++) {
if (M[u][v] == 0) continue;
if (color[v] == WHITE) {
dfs_visit(v);
}
}
color[u] = BLACK;
f[u] = ++tt;
}
void dfs() {
int u;
for (int i = 0; i < n; i++) {
color[i] = WHITE;
}
tt = 0;
for (u = 0; u < n; u++) {
if (color[u] == WHITE) dfs_visit(u);
}
for (int i = 0; i < n; i++)
cout << i + 1 << " " << d[i] << " " << f[i] << endl;
}
int main() {
int k, u, v;
cin >> n;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) M[i][j] = 0;
}
for (int i = 0; i < n; i++) {
cin >> u >> k;
u--;
for (int j = 0; j < k; j++) {
cin >> v;
v--;
M[u][v] = 1;
}
}
dfs();
return 0;
} | s669128523 | [
{
"input": "4\n1 1 2\n2 1 4\n3 0\n4 1 3\n",
"output": "1 1 8\n2 2 7\n3 4 5\n4 3 6\n"
}
] |
C++ | codenet | #include <iostream>
#include <vector>
#define MIN(a, b) ((a < b) ? a : b)
#define INF 1000000001
#define N 100000
using namespace std;
struct edge {
int source;
int target;
int weight;
};
vector<edge> edges;
int distances[N];
int prev_distances[N] = {0};
int main() {
int V, E, r;
cin >> V >> E >> r;
for (int i = 0; i < E; i++) {
int source, target, distance;
cin >> source >> target >> distance;
edge new_edge = {source, target, distance};
edges.push_back(new_edge);
}
for (int i = 0; i < N; i++) {
distances[i] = INF;
}
distances[r] = 0;
for (int i = 1; i < V; i++) {
for (int j = 0; j < V; j++) {
prev_distances[j] = distances[j];
}
for (vector<edge>::iterator edgeptr = edges.begin();
edgeptr != edges.end(); edgeptr++) {
distances[edgeptr->target] =
MIN(distances[edgeptr->source] + edgeptr->weight,
distances[edgeptr->target]);
}
bool same = true;
for (int j = 0; j < V; j++) {
if (distances[j] != prev_distances[j]) {
same = false;
break;
}
}
if (same) break;
}
for (int i = 0; i < V; i++) {
if (distances[i] == INF) {
cout << "INF" << endl;
} else {
cout << distances[i] << endl;
}
}
} | s314711832 | [
{
"input": "4 5 0\n0 1 1\n0 2 4\n1 2 2\n2 3 1\n1 3 5\n",
"output": "0\n1\n3\n4\n"
}
] |
C++ | codenet | #include <iostream>
using namespace std;
int main(void) {
int N;
cin >> N;
int mem[N + 1];
for (int i = 1; i <= N; ++i) {
int P;
cin >> P;
mem[P] = i;
}
int maxcnt = 1;
int cnt = 1;
for (int i = 1; i < N; ++i) {
if (mem[i] < mem[i + 1]) {
cnt++;
} else {
maxcnt = max(maxcnt, cnt);
cnt = 1;
}
if (i == N - 1) {
maxcnt = max(maxcnt, cnt);
}
}
cout << N - maxcnt << endl;
return 0;
} | s501065052 | [
{
"input": "4\n1\n3\n2\n4\n",
"output": "2\n"
}
] |
C++ | codenet | #include <iostream>
#include <string>
using namespace std;
int main() {
int a;
int b;
cin >> a;
cin >> b;
int result;
if (a > b) {
result = 2 * a - 1;
} else if (a == b) {
result = 2 * a;
} else {
result = 2 * b - 1;
}
cout << result << endl;
return 0;
} | s299205600 | [
{
"input": "5 3\n",
"output": "9\n"
}
] |
C++ | codenet | #include <assert.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cstring>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#pragma warning(disable : 4996)
typedef long long ll;
#define MIN(a, b) ((a) > (b) ? (b) : (a))
#define MAX(a, b) ((a) < (b) ? (b) : (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;
int main(int argc, char* argv[]) {
int n;
scanf("%d", &n);
vector<int> a(n);
int i;
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
int curr = 0;
for (i = 0; i < n; i++) {
if (a[i] == curr + 1) curr++;
}
if (curr > 0) {
printf("%d\n", n - curr);
} else {
printf("-1\n");
}
return 0;
} | s983388294 | [
{
"input": "3\n2 1 2\n",
"output": "1\n"
}
] |
C++ | codenet | #include <iostream>
using namespace std;
int main() {
char B, OUT;
cin >> B;
if (B == 'A')
OUT = 'T';
else if (B == 'T')
OUT = 'A';
else if (B == 'C')
OUT = 'G';
else
OUT = 'C';
cout << OUT << endl;
} | s074799395 | [
{
"input": "A\n",
"output": "T\n"
}
] |
C++ | codenet | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
#define int long long
struct Ban {
int l;
int r;
int val;
Ban() {}
Ban(int l_, int r_, int val_) {
l = l_;
r = r_;
val = val_;
}
};
namespace Sp {
const int LIM = 20;
const int N = 2e5 + 7;
int mn[LIM][N];
int pw[N];
void init(vector<int> a) {
int n = (int)a.size();
for (int i = 0; i < n; i++) {
mn[0][i] = a[i];
}
for (int i = 0; i + 1 < LIM; i++) {
for (int j = 0; j + (1 << (i + 1)) <= n; j++) {
mn[i + 1][j] = max(mn[i][j], mn[i][j + (1 << i)]);
}
}
pw[1] = 0;
for (int i = 2; i < N; i++) {
pw[i] = pw[i / 2] + 1;
}
}
int get(int l, int r) {
r++;
int p = pw[r - l];
return min(mn[p][l], mn[p][r - (1 << p)]);
}
} // namespace Sp
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<int> a(n);
for (auto &t : a) {
cin >> t;
}
vector<int> dl(n);
for (int i = 0; i < n; i++) {
if (a[i] > i) {
cout << -1 << endl;
return 0;
}
dl[i] = i - a[i];
}
int ans = 0;
vector<Ban> bans;
for (int i = 0; i < n; i++) {
int r = i;
while (r + 1 < n && a[r] + 1 == a[r + 1]) {
r++;
}
ans += a[r];
i = r;
bans.push_back(Ban(r - a[r], r, r - a[r]));
}
Sp::init(dl);
for (auto t : bans) {
if (Sp::get(t.l, t.r) > t.val) {
cout << -1 << endl;
return 0;
}
}
cout << ans << endl;
} | s134430594 | [
{
"input": "4\n0\n1\n1\n2\n",
"output": "3\n"
}
] |
C++ | codenet | #include <iostream>
using namespace std;
typedef long long ll;
int main() {
ll x1, x2, y1, y2;
cin >> x1 >> y1 >> x2 >> y2;
const ll dx = x2 - x1, dy = y2 - y1;
ll x3 = x2 - dy, y3 = y2 + dx;
ll x4 = x1 - dy, y4 = y1 + dx;
cout << x3 << ' ' << y3 << ' ' << x4 << ' ' << y4 << endl;
return 0;
} | s700369080 | [
{
"input": "0 0 0 1\n",
"output": "-1 1 -1 0\n"
}
] |
C++ | codenet | #include <iostream>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <deque>
#include <map>
#include <queue>
#include <string>
#include <vector>
#define all(x) (x).begin(), (x).end()
void solve() {}
int main() {
int a, b;
cin >> a >> b;
string ans;
if (a == 1 || b == 1) {
if (a == 1 && b == 1) {
ans = "Draw";
} else if (a == 1) {
ans = "Alice";
} else {
ans = "Bob";
}
} else {
if (a == b) {
ans = "Draw";
} else if (a > b) {
ans = "Alice";
} else {
ans = "Bob";
}
}
cout << ans << endl;
return 0;
} | s241624152 | [
{
"input": "8 6\n",
"output": "Alice\n"
}
] |
C++ | codenet | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define FOR(i, b, e) for (int i = (b); i < (e); ++i)
#define FORQ(i, b, e) for (int i = (b); i <= (e); ++i)
#define FORD(i, b, e) for (int i = (b)-1; i >= (e); --i)
#define REP(x, n) for (int x = 0; x < (n); ++x)
#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int, int>
#define pll pair<LL, LL>
#define vi vector<int>
#define vl vector<LL>
#define vii vector<vi>
#define vll vector<vl>
const double pi = 3.14159265358979323846264;
const int mod = 1000000007;
int main() {
int n, m;
cin >> n >> m;
vi s(m), c(m);
FOR(i, 0, m) {
cin >> s[i] >> c[i];
s[i]--;
}
FOR(i, 0, 1000) {
string st = to_string(i);
if (st.length() != n) {
continue;
}
int f = 1;
FOR(j, 0, m) {
if (st[s[j]] == c[j] + '0') {
} else {
f = 0;
}
}
if (f) {
cout << i << endl;
return 0;
}
}
cout << -1 << endl;
} | s509329039 | [
{
"input": "3 3\n1 7\n3 2\n1 7\n",
"output": "702\n"
}
] |
C++ | codenet | #include <iostream>
#include <string>
using namespace std;
int d;
string map[105];
int n;
void visit() {
int dx[4] = {0, 1, 0, -1};
int dy[4] = {-1, 0, 1, 0};
int sum, flg = 0;
int x = 2, y = n;
map[y][x] = ' ';
int ab[4] = {2, 2, 2, 2};
while (1) {
sum = 0;
while (1) {
if (map[y + dy[flg] * 2][x + dx[flg] * 2] != '#' &&
map[y + dy[flg]][x + dx[flg]] != ' ') {
flg++;
break;
}
map[y + dy[flg]][x + dx[flg]] = ' ';
y = y + dy[flg];
x = x + dx[flg];
sum++;
}
if (flg == 4) flg = 0;
if (sum == 0) break;
ab[0] = ab[1];
ab[1] = ab[2];
ab[2] = sum;
if (ab[0] == 1 && ab[2] == 1 && ab[1] == 1) break;
}
}
int main() {
cin >> d;
for (int l = 0; l < d; l++) {
cin >> n;
if (n == 1) {
cout << "#" << endl;
if (l != d - 1) cout << endl;
continue;
}
for (int i = 0; i <= n + 1; i++) {
map[i].resize(n + 2);
for (int j = 0; j <= n + 1; j++) {
map[i][j] = '#';
if (i == 0 || j == 0 || i == n + 1 || j == n + 1)
map[i][j] = '.';
}
}
visit();
for (int i = 1; i <= n; i++) {
for (int j = 1; j < map[i].size() - 1; j++) {
cout << map[i][j];
}
cout << endl;
}
if (l != d - 1) cout << endl;
}
return 0;
} | s102850254 | [
{
"input": "2\n5\n6\n",
"output": "#####\n# #\n# # #\n# # #\n# ###\n\n######\n# #\n# ## #\n# # #\n# # #\n# ####\n"
}
] |
C++ | codenet | #include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
vector<int> m;
m.push_back(10);
m.push_back(50);
m.push_back(100);
m.push_back(500);
bool first = true;
for (int money; cin >> money, money;) {
if (!first) cout << endl;
first = false;
int sum = 0;
vector<int> num(4);
for (int i = 0; i < 4; ++i) {
cin >> num[i];
sum += num[i] * m[i];
}
int change = sum - money;
for (int i = 3; i >= 0; --i) {
if (change / m[i]) {
num[i] = num[i] - change / m[i];
change %= m[i];
}
}
for (int i = 0; i < 4; ++i)
if (num[i] > 0) cout << m[i] << " " << num[i] << endl;
}
return EXIT_SUCCESS;
} | s663381244 | [
{
"input": "160\n1 1 2 0\n160\n1 0 2 10\n0\n",
"output": "10 1\n50 1\n100 1\n\n10 1\n100 2\n"
}
] |
C++ | codenet | #include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;
int main() {
ll H, W;
cin >> H >> W;
ll ans;
if (H == 1 || W == 1) {
ans = 1;
} else {
ll m = H * W;
if (m % 2 == 0)
ans = m / 2;
else
ans = m / 2 + 1;
}
cout << ans << endl;
return 0;
} | s791749917 | [
{
"input": "4 5\n",
"output": "10\n"
}
] |
C++ | codenet | #include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <set>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
int n, d;
cin >> n >> d;
double a = d * 2 + 1;
cout << ceil(n / a) << endl;
return 0;
} | s465977291 | [
{
"input": "6 2\n",
"output": "2\n"
}
] |
C++ | codenet | #include <iostream>
using namespace std;
int main() {
int x;
cin >> x;
cout << x * x * x << endl;
} | s023383699 | [
{
"input": "2\n",
"output": "8\n"
}
] |
C++ | codenet | #include <cmath>
#include <iostream>
using namespace std;
int div(int n);
int main() {
int num;
cin >> num;
cout << num << ":";
while (num != 1) {
cout << " " << div(num);
num = num / div(num);
}
cout << endl;
}
int div(int n) {
if (n % 2 == 0) return 2;
int s = sqrt(n);
for (int i = 3; i <= s; i += 2) {
if (n % i == 0) return i;
}
return n;
} | s605014348 | [
{
"input": "12\n",
"output": "12: 2 2 3\n"
}
] |
C++ | codenet | #include <stdio.h>
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
int s[11], i;
for (i = 0; i < 10; i++) {
scanf("%d", &s[i]);
}
sort(s, s + 10);
for (i = 9; i > 6; i--) {
printf("%d\n", s[i]);
}
return 0;
} | s954770518 | [
{
"input": "1819\n2003\n876\n2840\n1723\n1673\n3776\n2848\n1592\n922\n",
"output": "3776\n2848\n2840\n"
}
] |
C++ | codenet | #include <iostream>
#include <vector>
using namespace std;
int main() {
int N, X;
cin >> N >> X;
vector<int> L(N);
for (int i = 0; i < N; i++) cin >> L[i];
int i;
int d = 0;
for (i = 0; i < N; i++) {
d = d + L[i];
if (d > X) break;
}
cout << i + 1 << endl;
} | s978355948 | [
{
"input": "3 6\n3 4 5\n",
"output": "2\n"
}
] |
C++ | codenet | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
bool check(int n, int wei, vector<int> book) {
int tmp = wei;
n--;
for (int i = 0; i < book.size(); i++) {
if (tmp < book[i]) {
if (n > 0) {
n--;
tmp = wei;
if (tmp < book[i]) return false;
} else
return false;
}
tmp -= book[i];
}
return true;
}
int main() {
int m, n;
for (; cin >> m >> n, m;) {
vector<int> book;
for (int i = 0; i < n; i++) {
int tmp;
cin >> tmp;
book.push_back(tmp);
}
int l = 0;
int r = 1500000;
int ans;
while (l < r) {
if (check(m, (l + r) / 2, book)) {
ans = (l + r) / 2;
if (r == (l + r) / 2) break;
r = (l + r) / 2;
} else {
if (l == (l + r) / 2) break;
l = (l + r) / 2;
}
}
cout << ans << endl;
}
} | s847126533 | [
{
"input": "3 9\n500\n300\n800\n200\n100\n600\n900\n700\n400\n4 3\n1000\n1000\n1000\n0 0\n",
"output": "1800\n1000\n"
}
] |
C++ | codenet | #include <iostream>
#include <vector>
using namespace std;
int main() {
int N, K;
cin >> N >> K;
vector<int> v(N);
for (int i = 0; i < N; ++i) cin >> v[i];
int count = ((N - 1) + ((K - 1) - 1)) / (K - 1);
cout << count << '\n';
} | s296046823 | [
{
"input": "4 3\n2 3 1 4\n",
"output": "2\n"
}
] |
C++ | codenet | #include <iostream>
#include <queue>
using namespace std;
int main() {
int train[2];
int bus[2];
cin >> train[0] >> train[1];
cin >> bus[0] >> bus[1];
cout << (train[0] < train[1] ? train[0] : train[1]) +
(bus[0] < bus[1] ? bus[0] : bus[1])
<< endl;
return 0;
} | s150958471 | [
{
"input": "600\n300\n220\n420\n",
"output": "520\n"
}
] |
C++ | codenet | #include <algorithm>
#include <cmath>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <string>
#include <vector>
using namespace std;
#define IOS ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define prec std::cout << std::fixed << std::setprecision(15);
#define endl "\n"
#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define ssort(z) sort(z.begin(), z.end())
#define rsort(z) sort(z.rbegin(), z.rend())
#define eerase(z) z.erase(unique(z.begin(), z.end()), z.end())
#define ccnt(z, w) count(z.begin(), z.end(), w)
#define rep(i, a, n) for (Int(i) = (a); (i) < (n); (i)++)
#define repq(i, a, n) for (Int(i) = (a); (i) <= (n); (i)++)
const int MAX_N = 1000000;
const Int MAX_N_Int = 1000000000000;
template <typename T>
void printV(const std::vector<T>& v, const char* const separator = " ") {
if (!v.empty()) {
std::copy(v.begin(), --v.end(),
std::ostream_iterator<T>(std::cout, separator));
std::cout << v.back() << "\n";
}
}
bool isPrime(int num) {
if (num < 2)
return false;
else if (num == 2)
return true;
else if (num % 2 == 0)
return false;
double sqrtNum = sqrt(num);
for (int i = 3; i <= sqrtNum; i += 2) {
if (num % i == 0) {
return false;
}
}
return true;
}
Int gcd(Int a, Int b) { return b != 0 ? gcd(b, a % b) : a; }
Int lcm(Int a, Int b) { return a / gcd(a, b) * b; }
int Max(int a, int b, int c) {
int temp = max(a, b);
return max(temp, c);
}
int Min(int a, int b, int c) {
int temp = min(a, b);
return min(temp, c);
}
bool integer(double num) { return floor(num) == num; }
Int fact(int num) {
if (num == 0)
return 1;
else
return num * fact(num - 1);
}
Int yakusu(int n) {
int cnt = 0;
for (int i = 1; i * i <= n; i++) {
if (n % i == 0) {
cnt++;
if (i * i != n) cnt++;
}
}
return cnt;
}
Int fact_mod(Int n, Int mod) {
Int f = 1;
repq(i, 2, n) f = f * (i % MOD) % MOD;
return f;
}
Int mod_pow(Int x, Int n, Int mod) {
Int res = 1;
while (n > 0) {
if (n & 1) res = (res * x) % mod;
x = (x * x) % mod;
n >>= 1;
}
return res;
}
Int combination_mod(Int n, Int r, Int mod) {
if (r > n - r) r = n - r;
if (r == 0) return 1;
Int a = 1;
rep(i, 0, r) a = a * ((n - i) % mod) % mod;
Int b = mod_pow(fact_mod(r, mod), mod - 2, mod);
return (a % mod) * (b % mod) % mod;
}
bool rev(string s) {
string t = s;
reverse(s.begin(), s.end());
return s == t;
}
int main() {
IOS;
prec;
Int a, b, c, n, m, k, x, y = 0, ans = 0;
string str, s, t, u;
cin >> k >> a >> b;
for (int i = a; i <= b; ++i) {
if (i % k == 0) {
cout << "OK" << endl;
return 0;
}
}
cout << "NG";
cout << endl;
return 0;
} | s085554271 | [
{
"input": "7\n500 600\n",
"output": "OK\n"
}
] |
C++ | codenet | #include <iostream>
#include <string>
std::string check(int x, int y) {
if (y % 2 == 0) {
int t = (int)(0.5 * y) - x;
if (t >= 0 && (x - t) >= 0) return "Yes";
}
return "No";
}
int main() {
int x, y;
std::cin >> x >> y;
std::cout << check(x, y) << std::endl;
return 0;
} | s472228164 | [
{
"input": "3 8\n",
"output": "Yes\n"
}
] |
C++ | codenet | #include <algorithm>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;
const int INF = 200000005;
int main() {
int a, b;
cin >> a >> b;
if (a <= 8 && b <= 8)
cout << "Yay!" << endl;
else
cout << ":(" << endl;
return 0;
} | s854821134 | [
{
"input": "5 4\n",
"output": "Yay!\n"
}
] |
C++ | codenet | #include <stdio.h>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <vector>
#define mod 998244353
#define int long long
#define ld long double
#define pb push_back
#define vi vector<int>
#define co(x) cout << x << '\n'
#define dbg(x) cerr << #x << " = " << x << '\n'
#define bitcount(x) (int)__builtin_popcount(x)
#define sz(x) (int)x.size()
#define all(a) a.begin(), a.end()
#define ff first
#define ss second
#define pii pair<int, int>
#define lcm(a, b) (a * b) / __gcd(a, b)
using namespace std;
inline void solve() {
int n, ans = 0;
cin >> n;
co(!n);
}
signed main() {
int n = 1;
while (n--) solve();
return 0;
} | s661446851 | [
{
"input": "1\n",
"output": "0\n"
}
] |
C++ | codenet | #include <iostream>
using namespace std;
typedef long long ll;
ll n, k, ans, L, ans2;
string s;
int main(void) {
cin >> n >> k;
cin >> s;
L = s[0];
ll cnt = 0;
for (int i = 1; i < n; i++) {
if (L == s[i])
cnt++;
else {
L = s[i];
ans += cnt;
ans2++;
cnt = 0;
}
}
ans += cnt;
ans2++;
cout << ans + min(2 * k, ans2 - 1) << endl;
} | s410514868 | [
{
"input": "6 1\nLRLRRL\n",
"output": "3\n"
}
] |
C++ | codenet | #define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;
int time2min(int month, int day, int hour, int min) {
const int total_day_of_month[] = {31, 28, 31, 30, 31, 30,
31, 31, 30, 31, 30, 31};
int total = 0;
for (int i = 1; i < month; i++) {
total += total_day_of_month[i] * 24 * 60;
}
for (int i = 1; i < day; i++) {
total += 24 * 60;
}
total += hour * 60 + min;
return total;
}
int main() {
int N;
while (~scanf("%d", &N)) {
if (N == 0) break;
map<int, vector<int> > log;
for (int i = 0; i < N; i++) {
int month, day, hour, min, id;
char action[2];
scanf("%d/%d %d:%d %s %d", &month, &day, &hour, &min, action, &id);
int t = time2min(month, day, hour, min);
log[id].push_back(t);
}
int total[1000];
memset(total, 0, sizeof(total));
for (int i = 0; i + 1 < log[0].size(); i += 2) {
int god_start = log[0][i];
int god_end = log[0][i + 1];
for (map<int, vector<int> >::iterator it = log.begin();
it != log.end(); it++) {
int id = it->first;
if (id == 0) continue;
vector<int>& schedule = it->second;
for (int j = 0; j < schedule.size(); j += 2) {
int ppl_start = schedule[j];
int ppl_end = schedule[j + 1];
int start = max(god_start, ppl_start);
int end = min(god_end, ppl_end);
total[id] += max(0, end - start);
}
}
}
int max_v = 0;
for (int id = 0; id < 1000; id++) {
max_v = max(total[id], max_v);
}
printf("%d\n", max_v);
}
} | s683946919 | [
{
"input": "14\n04/21 09:00 I 000\n04/21 09:00 I 001\n04/21 09:15 I 002\n04/21 09:30 O 001\n04/21 09:45 O 000\n04/21 10:00 O 002\n04/28 09:00 I 003\n04/28 09:15 I 000\n04/28 09:30 I 004\n04/28 09:45 O 004\n04/28 10:00 O 000\n04/28 10:15 O 003\n04/29 20:00 I 002\n04/29 21:30 O 002\n20\n06/01 09:00 I 001\n06/01 09:15 I 002\n06/01 09:15 I 003\n06/01 09:30 O 002\n06/01 10:00 I 000\n06/01 10:15 O 001\n06/01 10:30 I 002\n06/01 10:45 O 002\n06/01 11:00 I 001\n06/01 11:15 O 000\n06/01 11:30 I 002\n06/01 11:45 O 001\n06/01 12:00 O 002\n06/01 12:15 I 000\n06/01 12:30 I 002\n06/01 12:45 O 000\n06/01 13:00 I 000\n06/01 13:15 O 000\n06/01 13:30 O 002\n06/01 13:45 O 003\n0\n",
"output": "45\n120\n"
}
] |
C++ | codenet | #include <iostream>
#define rep(S, L) for (int i = S; i < L; ++i)
using namespace std;
int main() {
int n, m;
int k, a;
int x[31] = {};
cin >> n >> m;
for (int i = 0; i < n; ++i) {
cin >> k;
for (int j = 0; j < k; ++j) {
cin >> a;
x[a]++;
}
}
int ans = 0;
for (int i = 1; i <= m; ++i) {
if (x[i] == n) {
ans++;
}
}
cout << ans << endl;
return 0;
} | s526060174 | [
{
"input": "3 4\n2 1 3\n3 1 2 3\n2 3 2\n",
"output": "1\n"
}
] |
C++ | codenet | #include <cassert>
#include <climits>
#include <iostream>
#include <vector>
struct TSize {
int r;
int c;
TSize() : r(0), c(0) {}
TSize(int Ar, int Ac) : r(Ar), c(Ac) {}
};
class TMcmSolver {
typedef std::vector<std::vector<int> > TMatrix;
TMatrix FMemo;
const std::vector<TSize>& FChain;
static int Count(const TSize& Left, const TSize& Right) {
return Left.r * Right.c * Left.c;
}
int Solve(int s, int l) {
assert(s <= l);
if (s == l) return 0;
if (FMemo[s][l] != 0) return FMemo[s][l];
if (s + 1 == l) {
FMemo[s][l] = Count(FChain[s], FChain[l]);
} else {
int min = INT_MAX;
for (int i = s; i < l; ++i) {
int c = Solve(s, i) +
Count(TSize(FChain[s].r, FChain[i].c),
TSize(FChain[i + 1].r, FChain[l].c)) +
Solve(i + 1, l);
min = std::min(min, c);
}
FMemo[s][l] = min;
}
return FMemo[s][l];
}
public:
TMcmSolver(const std::vector<TSize>& Chain) : FChain(Chain) {
FMemo.resize(Chain.size());
for (std::size_t i = 0; i < FMemo.size(); ++i) {
FMemo[i].resize(Chain.size(), 0);
}
}
int Answer() { return Solve(0, FMemo.size() - 1); }
void Print() const {
for (std::size_t s = 0; s < FMemo.size(); ++s) {
for (std::size_t l = 0; l < FMemo[0].size(); ++l) {
std::cout << FMemo[s][l] << '\t';
}
std::cout << '\n';
}
}
};
int main() {
int n;
std::cin >> n;
if (n == 1) {
std::cout << 0 << std::endl;
return 0;
}
std::vector<TSize> Chain(n);
for (int i = 0; i < n; ++i) {
std::cin >> Chain[i].r >> Chain[i].c;
}
TMcmSolver Solver(Chain);
std::cout << Solver.Answer() << std::endl;
return 0;
} | s792884768 | [
{
"input": "6\n30 35\n35 15\n15 5\n5 10\n10 20\n20 25\n",
"output": "15125\n"
}
] |
C++ | codenet | #include <iostream>
#include <map>
using namespace std;
int main() {
map<int, int> m;
for (int i = 0; i * 200 < 5001; i++) {
for (int j = 0; j * 300 < 5001; j++) {
for (int k = 0; k * 500 < 5001; k++) {
int w = i * 200 + j * 300 + k * 500;
int p = i / 5 * 5 * 380 * 0.8 + i % 5 * 380 +
j / 4 * 4 * 550 * 0.85 + j % 4 * 550 +
k / 3 * 3 * 850 * 0.88 + k % 3 * 850;
if (m[w])
m[w] = min(m[w], p);
else
m[w] = p;
}
}
}
int n;
while (cin >> n, n) {
cout << m[n] << endl;
}
} | s323743606 | [
{
"input": "500\n2200\n0\n",
"output": "850\n3390\n"
}
] |
C++ | codenet | #include <iostream>
int main() {
int N, A;
std::cin >> N;
std::cin >> A;
std::cout << N * N - A << std::endl;
} | s855845406 | [
{
"input": "3\n4\n",
"output": "5\n"
}
] |
C++ | codenet | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <vector>
using namespace std;
#define sz(a) int((a).size())
#define all(x) x.begin(), x.end()
#define pb push_back
#define endl '\n'
#define watch(x) cout << #x << " : " << x << endl;
#define FastIO \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
const int N = int(2e5) + 10;
const int K = int(2e6) + 10;
const int MOD = int(1e9) + 7;
const int INF = int(1e9) + 5;
const ll INF64 = 2e18;
void solve() {
ll ans = 0;
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
ans += i * 1ll * (n - i + 1);
}
for (int i = 1; i < n; i++) {
int u, v;
cin >> u >> v;
int a = max(u, v);
int b = min(u, v);
ans -= b * 1ll * (n - a + 1);
}
cout << ans << endl;
}
int main() {
FastIO
int t;
t = 1;
while (t--) {
solve();
}
return 0;
} | s146561572 | [
{
"input": "3\n1 3\n2 3\n",
"output": "7\n"
}
] |
C++ | codenet | #include <iostream>
#include <map>
using namespace std;
int main() {
string str;
cin >> str;
int max = 0, cnt = 0;
for (auto sc : str) {
if (sc == 'A' || sc == 'C' || sc == 'G' || sc == 'T') {
cnt++;
} else {
cnt = 0;
}
max = max < cnt ? cnt : max;
}
cout << max << endl;
} | s472290172 | [
{
"input": "ATCODER\n",
"output": "3\n"
}
] |
C++ | codenet | #include <cmath>
#include <iostream>
using namespace std;
int main() {
long long x, y;
cin >> x >> y;
if (abs(x - y) <= 1)
cout << "Brown" << endl;
else
cout << "Alice" << endl;
} | s917269550 | [
{
"input": "2 1\n",
"output": "Brown\n"
}
] |
C++ | codenet | #include <iostream>
using namespace std;
int main() {
int a, b, c;
cin >> a >> b >> c;
cout << ((a + b == c || b + c == a || a + c == b) ? "Yes" : "No") << endl;
} | s271114101 | [
{
"input": "10 30 20\n",
"output": "Yes\n"
}
] |
C++ | codenet | #include <cstdio>
#include <iostream>
#include <map>
#include <string>
using namespace std;
int main() {
int n;
char str[10], com[13];
map<string, bool> T;
cin >> n;
for (int i = 0; i < n; i++) {
scanf("%s%s", com, str);
if (com[0] == 'i')
T[string(str)] = true;
else {
if (T[string(str)])
printf("yes\n");
else
printf("no\n");
}
}
return 0;
} | s129088151 | [
{
"input": "5\ninsert A\ninsert T\ninsert C\nfind G\nfind A\n",
"output": "no\nyes\n"
}
] |
C++ | codenet | #include <math.h>
#include <algorithm>
#include <bitset>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;
template <typename T>
T gcd(T a, T b) {
return b ? gcd(b, a % b) : a;
}
template <typename T>
T lcm(T a, T b) {
return a / gcd(a, b) * b;
}
template <typename T>
map<T, T> getPrimeFactor(T n) {
map<T, T> res;
for (T i = 2; i * i <= n; ++i) {
while (n % i == 0) {
res[i]++;
n /= i;
}
}
if (n != 1) res[n] = 1;
return res;
}
template <typename T>
bool IsPrimeNumber(T num) {
if (num <= 2)
return true;
else if (num % 2 == 0)
return false;
double sqrtNum = sqrt(num);
for (int i = 3; i <= sqrtNum; i += 2) {
if (num % i == 0) {
return false;
}
}
return true;
}
long long modinv(long long a, long long m) {
long long b = m, u = 1, v = 0;
while (b) {
long long t = a / b;
a -= t * b;
swap(a, b);
u -= t * v;
swap(u, v);
}
u %= m;
if (u < 0) u += m;
return u;
}
#define rep(i, s, e) for (ll i = s; i < e; i++)
#define repeq(i, s, e) for (ll i = s; i <= e; i++)
int main() {
ll N, K;
std::cin >> N >> K;
vll A(N + 1);
repeq(i, 1, N) { std::cin >> A[i]; }
ll cur = 1;
vll dic(N + 1, -1);
bool flg = false;
repeq(i, 1, K) {
if (dic[cur] < 0 || flg) {
dic[cur] = i;
cur = A[cur];
} else if (!flg) {
ll tmp = K - (dic[cur] - 1);
tmp %= i - dic[cur];
i = K - tmp;
flg = true;
}
}
std::cout << cur << endl;
return 0;
} | s877835664 | [
{
"input": "4 5\n3 2 4 1\n",
"output": "4\n"
}
] |
C++ | codenet | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
const int M = 1010;
char a[M], b[M];
int n, m, ans = M + 10;
int main() {
scanf("%s", a + 1);
n = strlen(a + 1);
scanf("%s", b + 1);
m = strlen(b + 1);
for (int i = 1; i + m - 1 <= n; i++) {
int sum = 0;
for (int j = 1; j <= m; j++)
if (a[i + j - 1] != b[j]) sum++;
ans = min(ans, sum);
}
printf("%d\n", ans);
return 0;
} | s754383079 | [
{
"input": "cabacc\nabc\n",
"output": "1\n"
}
] |
C++ | codenet | #pragma region
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s)-1; (i) >= 0; --(i))
#define all(x) x.begin(), x.end()
#pragma endregion
int main() {
ll n, k;
cin >> n >> k;
ll MOD = 1e9 + 7;
ll mx = n * (n + 1) / 2 - (n - k) * (n - k + 1) / 2;
ll mn = k * (k - 1) / 2;
ll res = 0;
for (int i = k; i <= n + 1; ++i) {
res += mx - mn + 1;
mx += n - i;
mn += i;
res %= MOD;
}
cout << res << endl;
} | s814769071 | [
{
"input": "3 2\n",
"output": "10\n"
}
] |
C++ | codenet | #include <iostream>
using namespace std;
int main() {
int N, ans, i, count;
cin >> N;
int A[N];
for (i = 0; i < N; i++) {
cin >> A[i];
}
i = 0;
ans = 0;
count = 0;
while (A[i + 1] != NULL) {
if (A[i] == A[i + 1]) {
count++;
if (count % 2 != 0) ans++;
} else
count = 0;
i++;
}
cout << ans << "\n";
return 0;
} | s860472409 | [
{
"input": "5\n1 1 2 2 2\n",
"output": "2\n"
}
] |
C++ | codenet | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;
int main() {
cin.sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
int p[n];
for (int i = 0; i < n; i++) cin >> p[i];
int ans = 0;
for (int i = 0; i < n - 2; i++) {
if (p[i] > p[i + 1] && p[i + 1] > p[i + 2]) ans++;
if (p[i] < p[i + 1] && p[i + 1] < p[i + 2]) ans++;
}
cout << ans << "\n";
return 0;
} | s765257696 | [
{
"input": "5\n1 3 5 4 2\n",
"output": "2\n"
}
] |
C++ | codenet | #include <algorithm>
#include <array>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;
typedef pair<int, int> P;
bool d[10] = {0};
int n, k;
bool hantei = true;
int main() {
cin >> n >> k;
for (int i = 0; i < k; ++i) {
int a;
cin >> a;
d[a] = 1;
}
while (1) {
int x = n;
hantei = 1;
while (x) {
if (d[x % 10]) {
hantei = 0;
break;
}
x /= 10;
}
if (hantei) {
cout << n << endl;
break;
}
n++;
}
} | s930643405 | [
{
"input": "1000 8\n1 3 4 5 6 7 8 9\n",
"output": "2000\n"
}
] |
C++ | codenet | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
using namespace std;
const double PI = acos(-1.0);
int sig(double d) { return fabs(d) < 1e-8 ? 0 : d < 0 ? -1 : 1; }
struct Point {
double x, y;
double k;
Point() {}
Point(double x, double y) : x(x), y(y) {}
void set(double x, double y) {
this->x = x;
this->y = y;
}
double mod() { return sqrt(x * x + y * y); }
double mod_pow() { return x * x + y * y; }
void output() { printf("x = %f, y = %f\n", x, y); }
bool operator<(const Point &p) const {
return sig(x - p.x) != 0 ? x < p.x : sig(y - p.y) < 0;
}
} P[110];
int ch[110];
double ang[110], ans[110];
double dot(Point &o, Point &a, Point &b) {
return (a.x - o.x) * (b.x - o.x) + (a.y - o.y) * (b.y - o.y);
}
double dot(Point &a, Point &b) { return a.x * b.x + a.y * b.y; }
double cross(Point o, Point a, Point b) {
return (a.x - o.x) * (b.y - o.y) - (b.x - o.x) * (a.y - o.y);
}
int btw(Point &x, Point &a, Point &b) { return sig(dot(x, a, b)); }
double dis(Point a, Point b) {
return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
double cos(Point o, Point a, Point b) {
return dot(o, a, b) / dis(o, a) / dis(o, b);
}
int jarvis(Point *p, int n, int *ch) {
static int d, i, o, s, l, t;
for (d = i = 0; i < n; i++)
if (p[i] < p[d]) d = i;
l = s = *ch = d;
d = 1;
do {
o = l;
for (i = 0; i < n; i++)
if ((t = sig(cross(p[o], p[l], p[i]))) > 0 ||
(t == 0 && btw(p[l], p[o], p[i]) <= 0))
l = i;
ch[d++] = l;
} while (l != s);
return d - 1;
}
int main() {
memset(ang, 0, sizeof(ang));
memset(ans, 0, sizeof(ans));
int n, xx, yy;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d%d", &xx, &yy);
P[i].set(xx, yy);
}
if (n == 2) {
puts("0.5");
puts("0.5");
} else {
int m = jarvis(P, n, ch);
double sum = 0;
if (m == 2) {
ans[ch[0]] = 0.5;
ans[ch[1]] = 0.5;
} else {
for (int i = 0; i < m; i++) {
ang[ch[i]] = PI - acos(cos(P[ch[i]], P[ch[(i - 1 + m) % m]],
P[ch[(i + 1) % m]]));
}
for (int i = 0; i < n; i++) {
ans[i] = ang[i] / 2. / PI;
}
}
for (int i = 0; i < n; i++) {
printf("%.20f\n", ans[i]);
}
}
return 0;
} | s143031369 | [
{
"input": "2\n0 0\n1 1\n",
"output": "0.5\n0.5\n"
}
] |
C++ | codenet | #include <cstdio>
const int MAXN = 1E5 + 10;
int n, m, Q;
int a[MAXN];
int b[MAXN], id[MAXN];
bool vis[MAXN];
int cnt[MAXN];
int main() {
scanf("%d%d", &n, &m);
scanf("%d", &Q);
for (int i = 1; i <= Q; ++i) scanf("%d", &a[i]);
for (int k = 0, j = Q; j > 0; --j)
if (!vis[a[j]]) b[++k] = a[j], vis[a[j]] = true;
for (int j = m, i = m; i > 0; --i)
if (!vis[i]) b[j--] = i;
for (int i = 1; i <= m; ++i) id[b[i]] = i;
bool flag = true;
cnt[0] = n;
for (int i = Q; i > 0; --i) {
int t = id[a[i]];
if (cnt[t - 1] > 0) {
--cnt[t - 1];
++cnt[t];
vis[t] = true;
} else if (!vis[t]) {
flag = false;
break;
}
}
int l;
for (l = 0; cnt[l] == 0; ++l)
;
for (int i = l + 1; i < m; ++i) flag &= b[i] < b[i + 1];
puts(flag ? "Yes" : "No");
return 0;
} | s568362035 | [
{
"input": "2 2\n3\n2 1 2\n",
"output": "Yes\n"
}
] |
C++ | codenet | #include <iostream>
#include <string>
using namespace std;
int main() {
int a, b;
char S;
while (true) {
cin >> a >> S >> b;
if (S == '+') cout << a + b << endl;
if (S == '-') cout << a - b << endl;
if (S == '*') cout << a * b << endl;
if (S == '/') cout << a / b << endl;
if (S == '?') break;
}
} | s783753345 | [
{
"input": "1 + 2\n56 - 18\n13 * 2\n100 / 10\n27 + 81\n0 ? 0\n",
"output": "3\n38\n26\n10\n108\n"
}
] |
C++ | codenet | #include <iostream>
#include <vector>
using namespace std;
void A(void);
void B(void);
void C(void);
void D(void);
int main(void) { B(); }
void B(void) {
long long int x, sum;
cin >> x;
int i;
sum = 100;
for (i = 0; sum < x; ++i) {
sum += sum / 100;
}
cout << i << endl;
} | s914373115 | [
{
"input": "103\n",
"output": "3\n"
}
] |
C++ | codenet | #include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
int main(void) {
int n, a[100], b[100], sum = 0;
cin >> n;
rep(i, n) cin >> a[i];
rep(i, n) {
cin >> b[i];
if (a[i] - b[i] > 0) {
sum += a[i] - b[i];
}
}
cout << sum << endl;
} | s598010898 | [
{
"input": "3\n10 2 5\n6 3 4\n",
"output": "5\n"
}
] |
C++ | codenet | #include <iostream>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
int main() {
int h1, h2, m1, m2, k;
cin >> h1 >> m1 >> h2 >> m2 >> k;
int ans = h2 * 60 + m2 - (h1 * 60 + m1);
cout << ans - k << endl;
return 0;
} | s259332673 | [
{
"input": "10 0 15 0 30\n",
"output": "270\n"
}
] |
C++ | codenet | #include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
string s;
cin >> s;
for (char i = 'a'; i <= 'z'; i++) {
int a = 0;
for (int j = 0; j < s.size(); j++) {
if (i == s.at(j)) {
a++;
}
}
if (a == 0) {
cout << i << endl;
break;
}
if (i == 'z') {
cout << "None" << endl;
break;
}
}
} | s726701284 | [
{
"input": "atcoderregularcontest\n",
"output": "b\n"
}
] |
C++ | codenet | #include <iostream>
using namespace std;
int main() {
int a;
cin >> a;
cout << (a + (a * a) + (a * a * a)) << endl;
return 0;
} | s609497560 | [
{
"input": "2\n",
"output": "14\n"
}
] |
C++ | codenet | #include <cmath>
#include <iostream>
using namespace std;
int main() {
int N = 0;
cin >> N;
int A[N];
for (int i = 0; i < N; i++) cin >> A[i];
int m = A[0];
int M = A[0];
for (int i = 0; i < N; i++) {
if (A[i] < m) m = A[i];
if (A[i] > M) M = A[i];
}
cout << M - m << endl;
return 0;
} | s864662146 | [
{
"input": "4\n1 4 6 3\n",
"output": "5\n"
}
] |
C++ | codenet | #include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <iostream>
#include <limits>
#include <numeric>
#include <string>
#include <type_traits>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl
template <class T>
bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
int L, N;
int main() {
cin >> N >> L;
string S[N];
rep(i, N) cin >> S[i];
sort(S, S + N);
rep(i, N) cout << S[i];
cout << endl;
} | s329154546 | [
{
"input": "3 3\ndxx\naxx\ncxx\n",
"output": "axxcxxdxx\n"
}
] |
C++ | codenet | #include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
string s;
cin >> s;
int n = s.size();
int v[26] = {};
for (int i = 0; i < n; i++) v[s[i] - 'a']++;
string ans = "Yes";
for (int i = 0; i < 26; i++) {
if (v[i] % 2 != 0) {
ans = "No";
break;
}
}
cout << ans << endl;
} | s375006529 | [
{
"input": "abaccaba\n",
"output": "Yes\n"
}
] |
C++ | codenet | #include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
const int MAX_N = 4000;
typedef long long ll;
const ll LINF = 1LL << 60;
ll wis[MAX_N], wsums[MAX_N + 1], dp[MAX_N][MAX_N + 1];
int ks[MAX_N][MAX_N + 1];
int main() {
int n;
cin >> n;
wsums[0] = 0;
for (int i = 0; i < n; i++) {
cin >> wis[i];
wsums[i + 1] = wsums[i] + wis[i];
}
for (int i = 0; i < n; i++) {
for (int j = 0; j <= n; j++) dp[i][j] = LINF, ks[i][j] = -1;
dp[i][i + 1] = 0;
ks[i][i + 1] = i;
}
for (int l = 2; l <= n; l++)
for (int i = 0, j = l; j <= n; i++, j++) {
ll mind = LINF;
ll wsum = wsums[j] - wsums[i];
int mink = -1;
for (int k = ks[i][j - 1]; k <= ks[i + 1][j]; k++) {
ll d = dp[i][k] + dp[k][j] + wsum;
if (mind > d) mind = d, mink = k;
}
dp[i][j] = mind;
ks[i][j] = mink;
}
printf("%lld\n", dp[0][n]);
return 0;
} | s113620820 | [
{
"input": "3\n1 2 3\n",
"output": "9\n"
}
] |
C++ | codenet | #include <iostream>
#include <queue>
using namespace std;
struct task {
string name;
int time;
};
int main() {
int n, q;
int elaps = 0;
queue<task> Q;
cin >> n >> q;
for (int i = 0; i < n; i++) {
task tmp;
cin >> tmp.name >> tmp.time;
Q.push(tmp);
}
while (!Q.empty()) {
task p = Q.front();
Q.pop();
if (p.time <= q) {
elaps += p.time;
cout << p.name << " " << elaps << endl;
} else {
p.time -= q;
elaps += q;
Q.push(p);
}
}
return 0;
} | s525470559 | [
{
"input": "5 100\np1 150\np2 80\np3 200\np4 350\np5 20\n",
"output": "p2 180\np5 400\np1 450\np3 550\np4 800\n"
}
] |
C++ | codenet | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;
const int maxn = 200000 + 10;
const int INF = int(1e8);
int maps[maxn];
int num[maxn];
int main() {
int n;
while (~scanf("%d", &n)) {
for (int i = 1; i <= n; i++) {
scanf("%d", &maps[i]);
num[i] = maps[i];
}
sort(maps + 1, maps + n + 1);
int m = n / 2;
for (int i = 1; i <= n; i++) {
if (num[i] <= maps[m])
printf("%d\n", maps[m + 1]);
else
printf("%d\n", maps[m]);
}
}
return 0;
} | s154250720 | [
{
"input": "4\n2 4 4 3\n",
"output": "4\n3\n3\n4\n"
}
] |
C++ | codenet | #include <math.h>
#include <stdio.h>
#include <iostream>
#include <string>
using namespace std;
int main() {
int a, t = 0, h = 0, lt, lh, tt, hh, l;
cin >> a;
string taro, hana;
for (int i = 0; i < a; ++i) {
cin >> taro >> hana;
lt = taro.length();
lh = hana.length();
if (lt > lh) {
l = lt;
} else {
l = lh;
}
tt = 0;
hh = 0;
if (taro > hana) {
t = t + 3;
} else if (hana > taro) {
h = h + 3;
} else if (hana == taro) {
h = h + 1;
t = t + 1;
}
}
cout << t << " " << h << endl;
return 0;
} | s589139355 | [
{
"input": "3\ncat dog\nfish fish\nlion tiger\n",
"output": "1 7\n"
}
] |
C++ | codenet | #include <iostream>
#include <string>
using namespace std;
int mul(const string& str, int& idx) {
int res = str[idx] - '0';
while (idx + 1 < str.size() && str[idx + 1] == '*') {
idx += 2;
res *= str[idx] - '0';
}
return res;
}
int add(const string& str, int& idx) {
int res = mul(str, idx);
while (idx + 1 < str.size() && str[idx + 1] == '+') {
idx += 2;
res += mul(str, idx);
}
return res;
}
int bob(const string& str, int& idx) {
int res = str[idx] - '0';
while (idx + 1 < str.size()) {
if (str[idx + 1] == '+')
res += str[idx + 2] - '0';
else
res *= str[idx + 2] - '0';
idx += 2;
}
return res;
}
int main() {
string s;
int d;
while (cin >> s >> d) {
int idx = 0;
int a = add(s, idx);
idx = 0;
int b = bob(s, idx);
if (a == d) {
cout << (b == d ? "U" : "M") << endl;
} else {
cout << (b == d ? "L" : "I") << endl;
}
}
} | s611392782 | [
{
"input": "1+2*3+4\n11\n",
"output": "M\n"
}
] |
C++ | codenet | #include <iostream>
using namespace std;
int main(void) {
unsigned long n;
cin >> n;
bool flg = false;
if (n < 4) {
cout << "No" << endl;
} else {
for (int i = 0; i <= (n / 4); i++) {
for (int j = 0; j <= (n / 7); j++) {
if ((i * 4 + j * 7) == n) {
flg = true;
break;
}
}
if (flg) break;
}
if (flg) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
} | s573429823 | [
{
"input": "11\n",
"output": "Yes\n"
}
] |
C++ | codenet | #include <bitset>
#include <cmath>
#include <iostream>
#include <string>
using namespace std;
int main() {
string source = "";
cin >> source;
if (source.length() > 10 || source.length() < 1) {
return -1;
}
int max_i = static_cast<int>(pow(2, source.length() - 1));
double sum = 0;
for (int i = 0; i < max_i; ++i) {
bitset<100> plus(i);
double number = 0;
string working = source;
while (plus.any()) {
int i = 0;
while (!plus[i]) ++i;
sum += atof(working.substr(0, i + 1).c_str());
plus >>= i + 1;
working = working.substr(i + 1);
}
sum += atof(working.c_str());
}
cout.precision(0);
cout << fixed << sum << endl;
return 0;
} | s522742913 | [
{
"input": "125\n",
"output": "176\n"
}
] |
C++ | codenet | #include <stdio.h>
#include <string.h>
#define LEN 100005
typedef struct pp {
char name[100];
int t;
} P;
P Q[LEN];
int head, tail, n;
void enqueue(P x) {
Q[tail] = x;
tail = (tail + 1) % LEN;
}
P dequeue() {
P x = Q[head];
head = (head + 1) % LEN;
return x;
}
int min(int a, int b) { return a < b ? a : b; }
int main() {
int elaps = 0, c;
int i, q;
P u;
scanf("%d %d", &n, &q);
for (i = 1; i <= n; i++) {
scanf("%s", Q[i].name);
scanf("%d", &Q[i].t);
}
head = 1;
tail = n + 1;
while (head != tail) {
u = dequeue();
c = min(q, u.t);
u.t -= c;
elaps += c;
if (u.t > 0)
enqueue(u);
else
printf("%s %d\n", u.name, elaps);
}
return 0;
} | s644382798 | [
{
"input": "5 100\np1 150\np2 80\np3 200\np4 350\np5 20\n",
"output": "p2 180\np5 400\np1 450\np3 550\np4 800\n"
}
] |
C++ | codenet | #include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>
using namespace std;
int main() {
int n;
cin >> n;
cout << (n - 2) * 180 << endl;
return 0;
} | s786032937 | [
{
"input": "3\n",
"output": "180\n"
}
] |
C++ | codenet | #include <algorithm>
#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
int a;
cin >> a;
int sum = 0;
int s[n];
for (int i = 0; i < n; i++) {
cin >> s[i];
}
sort(s, s + n);
for (int i = n - 1; i > n - a - 1; i--) {
sum += s[i];
}
cout << sum << endl;
return 0;
} | s970063640 | [
{
"input": "5 3\n1 2 3 4 5\n",
"output": "12\n"
}
] |
C++ | codenet | #include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <vector>
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(c) (c).begin(), (c).end()
#define mp make_pair
#define pb push_back
#define rp(i, c) rep(i, (c).size())
#define fr(i, c) \
for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define dbg(x) cerr << #x << " = " << (x) << endl
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
const int inf = 1 << 28;
const double INF = 1e12, EPS = 1e-9;
bool seg[][7] = {
{0, 1, 1, 1, 1, 1, 1}, {0, 0, 0, 0, 1, 1, 0}, {1, 0, 1, 1, 0, 1, 1},
{1, 0, 0, 1, 1, 1, 1}, {1, 1, 0, 0, 1, 1, 0},
{1, 1, 0, 1, 1, 0, 1}, {1, 1, 1, 1, 1, 0, 1}, {0, 1, 0, 0, 1, 1, 1},
{1, 1, 1, 1, 1, 1, 1}, {1, 1, 0, 1, 1, 1, 1}};
int main() {
int n, t;
bool st[7];
while (cin >> n, ~n) {
rep(i, 7) st[i] = 0;
rep(i, n) {
cin >> t;
char ans[8] = {0};
rep(i, 7) {
ans[i] = st[i] ^ seg[t][i] ? '1' : '0';
st[i] = seg[t][i];
}
cout << ans << endl;
}
}
return 0;
} | s146177123 | [
{
"input": "3\n0\n5\n1\n1\n0\n-1\n",
"output": "0111111\n1010010\n1101011\n0111111\n"
}
] |
C++ | codenet | #include <iostream>
#include <map>
#include <set>
#include <vector>
#define REP(i, n) for (int i = 0; i < (n); i++)
using namespace std;
void solve(long long N, std::vector<long long> T, long long M,
std::vector<long long> P, std::vector<long long> X) {
REP(i, M) {
long long ans = 0;
REP(j, N) {
if (j == P[i] - 1)
ans += X[i];
else
ans += T[j];
}
cout << ans << '\n';
}
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
long long N;
cin >> N;
std::vector<long long> T(N);
REP(i, N) cin >> T[i];
long long M;
cin >> M;
std::vector<long long> P(M);
std::vector<long long> X(M);
REP(i, M) cin >> P[i] >> X[i];
solve(N, std::move(T), M, std::move(P), std::move(X));
return 0;
} | s615507008 | [
{
"input": "3\n2 1 4\n2\n1 1\n2 3\n",
"output": "6\n9\n"
}
] |
C++ | codenet | #include <iostream>
int main() {
int h, w, hh, ww;
std::cin >> h >> w >> hh >> ww;
std::cout << (h - hh) * (w - ww) << '\n';
return 0;
} | s391054810 | [
{
"input": "3 2\n2 1\n",
"output": "1\n"
}
] |
C++ | codenet | #include <iostream>
using namespace std;
int main(void) {
long long int a, b;
cin >> a >> b;
if ((a + b) % 2 == 0) {
cout << (a + b) / 2 << "\n";
} else {
cout << "IMPOSSIBLE\n";
}
} | s698030085 | [
{
"input": "2 16\n",
"output": "9\n"
}
] |
C++ | codenet | #include <algorithm>
#include <climits>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <utility>
using namespace std;
long long a[200000];
int ind_a[200000];
int main() {
int N;
cin >> N;
for (int i = 0; i < N; i++) {
cin >> a[i];
}
for (int i = 0; i < N; i++) {
ind_a[a[i] - 1] = i;
}
set<int> used_inds;
long long ans = 0;
for (int i = 0; i < N; i++) {
long long left_border;
long long right_border;
long long cur_ind = ind_a[i];
auto left_it = used_inds.lower_bound(cur_ind);
auto right_it = used_inds.lower_bound(cur_ind + 1);
if (left_it == used_inds.begin()) {
left_border = -1;
} else {
if (left_it == used_inds.end() || *left_it > cur_ind) {
left_it--;
}
left_border = *left_it;
}
if (right_it == used_inds.end()) {
right_border = N;
} else {
right_border = *right_it;
}
ans += (cur_ind - left_border) * (right_border - cur_ind) *
((long long)i + 1);
used_inds.insert(cur_ind);
}
cout << ans << endl;
return 0;
} | s876796799 | [
{
"input": "3\n2 1 3\n",
"output": "9\n"
}
] |