problem_id stringlengths 6 6 | language stringclasses 2 values | original_status stringclasses 3 values | original_src stringlengths 19 243k | changed_src stringlengths 19 243k | change stringclasses 3 values | i1 int64 0 8.44k | i2 int64 0 8.44k | j1 int64 0 8.44k | j2 int64 0 8.44k | error stringclasses 270 values | stderr stringlengths 0 226k |
|---|---|---|---|---|---|---|---|---|---|---|---|
p02737 | C++ | Runtime Error | #include <bits/stdc++.h>
#define Rint register int
#define MP make_pair
#define fi first
#define se second
#define PB push_back
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
const int N = 100003, M = 1024, mod = 998244353;
template <typename T> void read(T &x) {
int ch = getchar();
x = 0;
bool f = false;
for (; ch < '0' || ch > '9'; ch = getchar())
f |= ch == '-';
for (; ch >= '0' && ch <= '9'; ch = getchar())
x = x * 10 + ch - '0';
if (f)
x = -x;
}
void qmo(int &x) { x += (x >> 31) & mod; }
int ksm(int a, int b) {
int res = 1;
for (; b; b >>= 1, a = (LL)a * a % mod)
if (b & 1)
res = (LL)res * a % mod;
return res;
}
template <typename T> inline bool chmax(T &a, const T &b) {
if (a < b)
return a = b, 1;
return 0;
}
template <typename T> inline bool chmin(T &a, const T &b) {
if (a > b)
return a = b, 1;
return 0;
}
int n, m, head[N], to[N], nxt[N], cnt, f[3][M], sg[N], pw[N], ans;
bool vis[N];
void add(int a, int b) {
static int cnt = 0;
to[++cnt] = b;
nxt[cnt] = head[a];
head[a] = cnt;
}
void solve(int t) {
cnt = 0;
read(m);
for (Rint i = 1; i <= n; ++i)
head[i] = sg[i] = 0;
for (Rint i = 1, u, v; i <= m; ++i) {
read(u);
read(v);
if (u > v)
swap(u, v);
add(u, v);
}
for (Rint i = n; i; --i) {
for (Rint j = head[i]; j; j = nxt[j])
vis[sg[to[j]]] = true;
for (; vis[sg[i]]; ++sg[i])
;
qmo(f[t][sg[i]] += pw[i] - mod);
for (Rint j = head[i]; j; j = nxt[j])
vis[sg[to[j]]] = false;
}
}
int main() {
read(n);
pw[0] = 1;
pw[1] = 716070898;
for (Rint i = 2; i <= n; ++i)
pw[i] = (LL)pw[i - 1] * pw[1] % mod;
for (Rint t = 0; t < 3; ++t)
solve(t);
for (Rint i = 0; i < M; ++i)
for (Rint j = 0; j < M; ++j)
qmo(ans += (LL)f[0][i] * f[1][j] % mod * f[2][i ^ j] % mod - mod);
printf("%d\n", ans);
} | #include <bits/stdc++.h>
#define Rint register int
#define MP make_pair
#define fi first
#define se second
#define PB push_back
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
const int N = 100003, M = 1024, mod = 998244353;
template <typename T> void read(T &x) {
int ch = getchar();
x = 0;
bool f = false;
for (; ch < '0' || ch > '9'; ch = getchar())
f |= ch == '-';
for (; ch >= '0' && ch <= '9'; ch = getchar())
x = x * 10 + ch - '0';
if (f)
x = -x;
}
void qmo(int &x) { x += (x >> 31) & mod; }
int ksm(int a, int b) {
int res = 1;
for (; b; b >>= 1, a = (LL)a * a % mod)
if (b & 1)
res = (LL)res * a % mod;
return res;
}
template <typename T> inline bool chmax(T &a, const T &b) {
if (a < b)
return a = b, 1;
return 0;
}
template <typename T> inline bool chmin(T &a, const T &b) {
if (a > b)
return a = b, 1;
return 0;
}
int n, m, head[N], to[N], nxt[N], cnt, f[3][M], sg[N], pw[N], ans;
bool vis[N];
void add(int a, int b) {
to[++cnt] = b;
nxt[cnt] = head[a];
head[a] = cnt;
}
void solve(int t) {
cnt = 0;
read(m);
for (Rint i = 1; i <= n; ++i)
head[i] = sg[i] = 0;
for (Rint i = 1, u, v; i <= m; ++i) {
read(u);
read(v);
if (u > v)
swap(u, v);
add(u, v);
}
for (Rint i = n; i; --i) {
for (Rint j = head[i]; j; j = nxt[j])
vis[sg[to[j]]] = true;
for (; vis[sg[i]]; ++sg[i])
;
qmo(f[t][sg[i]] += pw[i] - mod);
for (Rint j = head[i]; j; j = nxt[j])
vis[sg[to[j]]] = false;
}
}
int main() {
read(n);
pw[0] = 1;
pw[1] = 716070898;
for (Rint i = 2; i <= n; ++i)
pw[i] = (LL)pw[i - 1] * pw[1] % mod;
for (Rint t = 0; t < 3; ++t)
solve(t);
for (Rint i = 0; i < M; ++i)
for (Rint j = 0; j < M; ++j)
qmo(ans += (LL)f[0][i] * f[1][j] % mod * f[2][i ^ j] % mod - mod);
printf("%d\n", ans);
} | delete | 42 | 43 | 42 | 42 | 0 | |
p02738 | C++ | Runtime Error | /*{{{*/
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) \
(sort(c.begin(), c.end()), \
c.resize(distance(c.begin(), unique(c.begin(), c.end()))))
#define GET_POS(c, x) (lower_bound(c.begin(), c.end(), x) - c.begin())
#define CASET \
int ___T; \
scanf("%d", &___T); \
for (int cs = 1; cs <= ___T; cs++)
#define MP make_pair
#define PB emplace_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL, LL> PLL;
typedef vector<PLL> VPLL;
template <class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template <class T, class... U> void R(T &head, U &...tail) {
_R(head);
R(tail...);
}
template <class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template <class T, class U> void _W(const pair<T, U> &x) {
_W(x.F);
putchar(' ');
_W(x.S);
}
template <class T> void _W(const vector<T> &x) {
for (auto i = x.begin(); i != x.end(); _W(*i++))
if (i != x.cbegin())
putchar(' ');
}
void W() {}
template <class T, class... U> void W(const T &head, const U &...tail) {
_W(head);
putchar(sizeof...(tail) ? ' ' : '\n');
W(tail...);
}
#ifdef HOME
#define DEBUG(...) \
{ \
printf("# "); \
printf(__VA_ARGS__); \
puts(""); \
}
#else
#define DEBUG(...)
#endif
int MOD = 1e9 + 7;
void ADD(LL &x, LL v) {
x = (x + v) % MOD;
if (x < 0)
x += MOD;
}
/*}}}*/
const int SIZE = 6001;
int N;
LL dp[SIZE][2001][2];
LL fac[SIZE], inv[SIZE];
LL mypow(LL x, LL y) {
LL res = 1;
while (y) {
if (y & 1)
res = res * x % MOD;
y >>= 1;
x = x * x % MOD;
}
return res;
}
LL C(int x, int y) {
if (y < 0 || y > x)
return 0;
return fac[x] * inv[y] % MOD * inv[x - y] % MOD;
}
void build() {
assert(MOD >= SIZE);
fac[0] = 1;
REPP(i, 1, SIZE) fac[i] = fac[i - 1] * i % MOD;
inv[SIZE - 1] = mypow(fac[SIZE - 1], MOD - 2);
for (int i = SIZE - 2; i >= 0; i--)
inv[i] = inv[i + 1] * (i + 1) % MOD;
}
int get(int x, int y) {
if (y == 1)
return x;
return (x + 2) / 3;
}
LL calc(int n, int x, int y) {
if (n > 3 * N)
return 0;
if (n == 3 * N)
return 1;
if (dp[n][x][y] != -1)
return dp[n][x][y];
LL &ret = dp[n][x][y];
ret = 0;
int use3 = (n - (y + 1) * x) / 3;
if (use3 + 1 + get(x, y) <= N)
ADD(ret, calc(n + 3, x, y) * (3 * N - n - 1LL) % MOD * (3 * N - n - 2LL));
if (y == 1 || x == 0) {
if (use3 + get(x + 1, 1) <= N)
ADD(ret, calc(n + 2, x + 1, 1) * (3 * N - n - 1LL));
} else {
if (use3 + 1 + get(x - 1, 0) <= N)
ADD(ret, calc(n + 2, x - 1, 0) * (3 * N - n - 1LL));
}
if (y == 0 || x == 0) {
if (use3 + get(x + 1, 0) <= N)
ADD(ret, calc(n + 1, x + 1, 0));
} else {
if (use3 + 1 + get(x - 1, 1) <= N)
ADD(ret, calc(n + 1, x - 1, 1));
}
return ret;
}
int main() {
build();
MS1(dp);
R(N, MOD);
W(calc(0, 0, 0));
return 0;
}
| /*{{{*/
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) \
(sort(c.begin(), c.end()), \
c.resize(distance(c.begin(), unique(c.begin(), c.end()))))
#define GET_POS(c, x) (lower_bound(c.begin(), c.end(), x) - c.begin())
#define CASET \
int ___T; \
scanf("%d", &___T); \
for (int cs = 1; cs <= ___T; cs++)
#define MP make_pair
#define PB emplace_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL, LL> PLL;
typedef vector<PLL> VPLL;
template <class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template <class T, class... U> void R(T &head, U &...tail) {
_R(head);
R(tail...);
}
template <class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template <class T, class U> void _W(const pair<T, U> &x) {
_W(x.F);
putchar(' ');
_W(x.S);
}
template <class T> void _W(const vector<T> &x) {
for (auto i = x.begin(); i != x.end(); _W(*i++))
if (i != x.cbegin())
putchar(' ');
}
void W() {}
template <class T, class... U> void W(const T &head, const U &...tail) {
_W(head);
putchar(sizeof...(tail) ? ' ' : '\n');
W(tail...);
}
#ifdef HOME
#define DEBUG(...) \
{ \
printf("# "); \
printf(__VA_ARGS__); \
puts(""); \
}
#else
#define DEBUG(...)
#endif
int MOD = 1e9 + 7;
void ADD(LL &x, LL v) {
x = (x + v) % MOD;
if (x < 0)
x += MOD;
}
/*}}}*/
const int SIZE = 6001;
int N;
LL dp[SIZE][SIZE][2];
LL fac[SIZE], inv[SIZE];
LL mypow(LL x, LL y) {
LL res = 1;
while (y) {
if (y & 1)
res = res * x % MOD;
y >>= 1;
x = x * x % MOD;
}
return res;
}
LL C(int x, int y) {
if (y < 0 || y > x)
return 0;
return fac[x] * inv[y] % MOD * inv[x - y] % MOD;
}
void build() {
assert(MOD >= SIZE);
fac[0] = 1;
REPP(i, 1, SIZE) fac[i] = fac[i - 1] * i % MOD;
inv[SIZE - 1] = mypow(fac[SIZE - 1], MOD - 2);
for (int i = SIZE - 2; i >= 0; i--)
inv[i] = inv[i + 1] * (i + 1) % MOD;
}
int get(int x, int y) {
if (y == 1)
return x;
return (x + 2) / 3;
}
LL calc(int n, int x, int y) {
if (n > 3 * N)
return 0;
if (n == 3 * N)
return 1;
if (dp[n][x][y] != -1)
return dp[n][x][y];
LL &ret = dp[n][x][y];
ret = 0;
int use3 = (n - (y + 1) * x) / 3;
if (use3 + 1 + get(x, y) <= N)
ADD(ret, calc(n + 3, x, y) * (3 * N - n - 1LL) % MOD * (3 * N - n - 2LL));
if (y == 1 || x == 0) {
if (use3 + get(x + 1, 1) <= N)
ADD(ret, calc(n + 2, x + 1, 1) * (3 * N - n - 1LL));
} else {
if (use3 + 1 + get(x - 1, 0) <= N)
ADD(ret, calc(n + 2, x - 1, 0) * (3 * N - n - 1LL));
}
if (y == 0 || x == 0) {
if (use3 + get(x + 1, 0) <= N)
ADD(ret, calc(n + 1, x + 1, 0));
} else {
if (use3 + 1 + get(x - 1, 1) <= N)
ADD(ret, calc(n + 1, x - 1, 1));
}
return ret;
}
int main() {
build();
MS1(dp);
R(N, MOD);
W(calc(0, 0, 0));
return 0;
}
| replace | 86 | 87 | 86 | 87 | -11 | |
p02738 | C++ | Runtime Error | #include <bits/stdc++.h>
#define f(i, j) f[i][j + 3000]
#define int long long
using namespace std;
const int N = 2100;
int n, P;
int f[N][N + 3000];
signed main(void) {
cin >> n >> P;
f(0, 0) = 1;
for (int i = 0; i < n * 3; ++i)
for (int j = -n; j <= 3 * n; ++j) {
f(i + 1, j + 1) = (f(i + 1, j + 1) + f(i, j)) % P;
f(i + 2, j - 1) = (f(i + 2, j - 1) + f(i, j) * (i + 1) % P) % P;
f(i + 3, j) = (f(i + 3, j) + f(i, j) * (i + 1) % P * (i + 2) % P) % P;
}
int res = 0;
for (int i = 0; i <= n; ++i)
res = (res + f(n * 3, i * 3)) % P;
cout << res << endl;
return 0;
} | #include <bits/stdc++.h>
#define f(i, j) f[i][j + 3000]
#define int long long
using namespace std;
const int N = 6100;
int n, P;
int f[N][N + 3000];
signed main(void) {
cin >> n >> P;
f(0, 0) = 1;
for (int i = 0; i < n * 3; ++i)
for (int j = -n; j <= 3 * n; ++j) {
f(i + 1, j + 1) = (f(i + 1, j + 1) + f(i, j)) % P;
f(i + 2, j - 1) = (f(i + 2, j - 1) + f(i, j) * (i + 1) % P) % P;
f(i + 3, j) = (f(i + 3, j) + f(i, j) * (i + 1) % P * (i + 2) % P) % P;
}
int res = 0;
for (int i = 0; i <= n; ++i)
res = (res + f(n * 3, i * 3)) % P;
cout << res << endl;
return 0;
} | replace | 5 | 6 | 5 | 6 | 0 | |
p02738 | C++ | Runtime Error | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#define N ()
#define M ()
#define inf (0x7f7f7f7f)
#define rg register int
#define Label puts("NAIVE")
#define spa print(' ')
#define ent print('\n')
#define rand() (((rand()) << (15)) ^ (rand()))
#define file(s) freopen(s ".in", "r", stdin), freopen(s ".out", "w", stdout)
typedef long double ld;
typedef long long LL;
typedef unsigned long long ull;
using namespace std;
namespace fastIO1 {
inline char read() {
static const int IN_LEN = 1000000;
static char buf[IN_LEN], *s, *t;
return (s == t ? t = (s = buf) + fread(buf, 1, IN_LEN, stdin),
(s == t ? -1 : *s++) : *s++);
}
template <class T> inline void read(T &x) {
static bool iosig;
static char c;
for (iosig = false, c = read(); !isdigit(c); c = read()) {
if (c == '-')
iosig = true;
if (c == -1)
return;
}
for (x = 0; isdigit(c); c = read())
x = ((x + (x << 2)) << 1) + (c ^ '0');
if (iosig)
x = -x;
}
inline char readc(char &c) {
for (c = read(); !isalpha(c) && !isdigit(c); c = read())
if (c == -1)
return 0;
}
const int OUT_LEN = 10000000;
char obuf[OUT_LEN], *ooh = obuf;
inline void print(char c) {
if (ooh == obuf + OUT_LEN)
fwrite(obuf, 1, OUT_LEN, stdout), ooh = obuf;
*ooh++ = c;
}
template <class T> inline void print(T x) {
static int buf[30], cnt;
if (x == 0)
print('0');
else {
if (x < 0)
print('-'), x = -x;
for (cnt = 0; x; x /= 10)
buf[++cnt] = x % 10 + 48;
while (cnt)
print((char)buf[cnt--]);
}
}
inline void flush() { fwrite(obuf, 1, ooh - obuf, stdout); }
} // namespace fastIO1
namespace fastIO2 {
template <class T> inline void read(T &x) {
static bool iosig;
static char c;
for (iosig = false, c = getchar(); !isdigit(c); c = getchar()) {
if (c == '-')
iosig = true;
if (c == -1)
return;
}
for (x = 0; isdigit(c); c = getchar())
x = ((x + (x << 2)) << 1) + (c ^ '0');
if (iosig)
x = -x;
}
} // namespace fastIO2
using namespace fastIO1;
int n, P, f[1210][1610], ans;
void add(int &x, int y) { x = x + y > P ? x + y - P : x + y; }
int main() {
read(n);
read(P);
f[0][n] = 1;
for (int i = 1; i <= 3 * n; i++)
for (int j = -n; j <= 3 * n; j++) {
if (j + n > 0)
add(f[i][j + n], f[i - 1][j - 1 + n]);
if (i >= 2)
add(f[i][j + n], 1ll * (i - 1) * f[i - 2][j + 1 + n] % P);
if (i >= 3)
add(f[i][j + n], 1ll * (i - 1) * (i - 2) % P * f[i - 3][j + n] % P);
}
for (int i = n; i <= 4 * n; i += 3)
add(ans, f[n * 3][i]);
printf("%d\n", ans);
} | #include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#define N ()
#define M ()
#define inf (0x7f7f7f7f)
#define rg register int
#define Label puts("NAIVE")
#define spa print(' ')
#define ent print('\n')
#define rand() (((rand()) << (15)) ^ (rand()))
#define file(s) freopen(s ".in", "r", stdin), freopen(s ".out", "w", stdout)
typedef long double ld;
typedef long long LL;
typedef unsigned long long ull;
using namespace std;
namespace fastIO1 {
inline char read() {
static const int IN_LEN = 1000000;
static char buf[IN_LEN], *s, *t;
return (s == t ? t = (s = buf) + fread(buf, 1, IN_LEN, stdin),
(s == t ? -1 : *s++) : *s++);
}
template <class T> inline void read(T &x) {
static bool iosig;
static char c;
for (iosig = false, c = read(); !isdigit(c); c = read()) {
if (c == '-')
iosig = true;
if (c == -1)
return;
}
for (x = 0; isdigit(c); c = read())
x = ((x + (x << 2)) << 1) + (c ^ '0');
if (iosig)
x = -x;
}
inline char readc(char &c) {
for (c = read(); !isalpha(c) && !isdigit(c); c = read())
if (c == -1)
return 0;
}
const int OUT_LEN = 10000000;
char obuf[OUT_LEN], *ooh = obuf;
inline void print(char c) {
if (ooh == obuf + OUT_LEN)
fwrite(obuf, 1, OUT_LEN, stdout), ooh = obuf;
*ooh++ = c;
}
template <class T> inline void print(T x) {
static int buf[30], cnt;
if (x == 0)
print('0');
else {
if (x < 0)
print('-'), x = -x;
for (cnt = 0; x; x /= 10)
buf[++cnt] = x % 10 + 48;
while (cnt)
print((char)buf[cnt--]);
}
}
inline void flush() { fwrite(obuf, 1, ooh - obuf, stdout); }
} // namespace fastIO1
namespace fastIO2 {
template <class T> inline void read(T &x) {
static bool iosig;
static char c;
for (iosig = false, c = getchar(); !isdigit(c); c = getchar()) {
if (c == '-')
iosig = true;
if (c == -1)
return;
}
for (x = 0; isdigit(c); c = getchar())
x = ((x + (x << 2)) << 1) + (c ^ '0');
if (iosig)
x = -x;
}
} // namespace fastIO2
using namespace fastIO1;
int n, P, f[6010][8010], ans;
void add(int &x, int y) { x = x + y > P ? x + y - P : x + y; }
int main() {
read(n);
read(P);
f[0][n] = 1;
for (int i = 1; i <= 3 * n; i++)
for (int j = -n; j <= 3 * n; j++) {
if (j + n > 0)
add(f[i][j + n], f[i - 1][j - 1 + n]);
if (i >= 2)
add(f[i][j + n], 1ll * (i - 1) * f[i - 2][j + 1 + n] % P);
if (i >= 3)
add(f[i][j + n], 1ll * (i - 1) * (i - 2) % P * f[i - 3][j + n] % P);
}
for (int i = n; i <= 4 * n; i += 3)
add(ans, f[n * 3][i]);
printf("%d\n", ans);
} | replace | 88 | 89 | 88 | 89 | 0 | |
p02738 | C++ | Time Limit Exceeded | #include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
typedef long long int LL;
typedef pair<int, int> P;
typedef pair<LL, int> LP;
const int INF = 1 << 30;
const LL MAX = 1e9 + 7;
void array_show(int *array, int array_n, char middle = ' ') {
for (int i = 0; i < array_n; i++)
printf("%d%c", array[i], (i != array_n - 1 ? middle : '\n'));
}
void array_show(LL *array, int array_n, char middle = ' ') {
for (int i = 0; i < array_n; i++)
printf("%lld%c", array[i], (i != array_n - 1 ? middle : '\n'));
}
void array_show(vector<int> &vec_s, int vec_n = -1, char middle = ' ') {
if (vec_n == -1)
vec_n = vec_s.size();
for (int i = 0; i < vec_n; i++)
printf("%d%c", vec_s[i], (i != vec_n - 1 ? middle : '\n'));
}
void array_show(vector<LL> &vec_s, int vec_n = -1, char middle = ' ') {
if (vec_n == -1)
vec_n = vec_s.size();
for (int i = 0; i < vec_n; i++)
printf("%lld%c", vec_s[i], (i != vec_n - 1 ? middle : '\n'));
}
LL kai[6600];
long long int pow_mod(long long int p_a, long long int p_n,
long long int p_p = 1e9 + 7) {
// p_a^p_n mod p_p
long long int p_b = 1, p_t = 1;
for (; p_b <= p_n; p_b <<= 1)
;
for (p_b >>= 1; p_b > 0; p_b >>= 1) {
p_t *= p_t;
if (p_t >= p_p)
p_t %= p_p;
if (p_n & p_b)
p_t *= p_a;
if (p_t >= p_p)
p_t %= p_p;
}
return p_t;
}
long long int gcd(long long int g_a, long long int g_b) {
if (g_a < g_b)
gcd(g_b, g_a);
if (g_b == 0)
return g_a;
return gcd(g_b, g_a % g_b);
}
long long int divide(long long int d_a, long long int d_b,
long long int d_p = 1e9 + 7) {
// d_a/d_b mod d_p
// prime:d_p is prime
if (d_a >= d_p)
d_a %= d_p;
if (d_a < 0)
d_a += d_p;
if (d_b >= d_p)
d_b %= d_p;
if (d_b < 0)
d_b += d_p;
d_a *= pow_mod(d_b, d_p - 2, d_p);
return d_a % d_p;
}
int main() {
int n, m;
int i, j, k;
LL a, b, c;
LL p, q, r;
LL s = 0;
cin >> n >> m;
kai[0] = 1;
for (i = 1; i <= 3 * n; i++) {
kai[i] = kai[i - 1] * i % m;
}
for (i = 0, p = 1; i <= n; i++) {
for (j = 0, q = 1; i + j <= n; j++) {
a = divide(kai[3 * n], p, m);
a = divide(a, q, m);
a = divide(a, kai[i], m);
a = divide(a, kai[j], m);
a = divide(a, kai[3 * n - 3 * i - 2 * j], m);
s += a;
if (s >= m)
s %= m;
q *= 2;
if (q >= m)
q %= m;
}
p *= 3;
if (p >= m)
p %= m;
}
cout << s << endl;
} | #include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <tuple>
#include <vector>
using namespace std;
typedef long long int LL;
typedef pair<int, int> P;
typedef pair<LL, int> LP;
const int INF = 1 << 30;
const LL MAX = 1e9 + 7;
void array_show(int *array, int array_n, char middle = ' ') {
for (int i = 0; i < array_n; i++)
printf("%d%c", array[i], (i != array_n - 1 ? middle : '\n'));
}
void array_show(LL *array, int array_n, char middle = ' ') {
for (int i = 0; i < array_n; i++)
printf("%lld%c", array[i], (i != array_n - 1 ? middle : '\n'));
}
void array_show(vector<int> &vec_s, int vec_n = -1, char middle = ' ') {
if (vec_n == -1)
vec_n = vec_s.size();
for (int i = 0; i < vec_n; i++)
printf("%d%c", vec_s[i], (i != vec_n - 1 ? middle : '\n'));
}
void array_show(vector<LL> &vec_s, int vec_n = -1, char middle = ' ') {
if (vec_n == -1)
vec_n = vec_s.size();
for (int i = 0; i < vec_n; i++)
printf("%lld%c", vec_s[i], (i != vec_n - 1 ? middle : '\n'));
}
LL kai[6600];
long long int pow_mod(long long int p_a, long long int p_n,
long long int p_p = 1e9 + 7) {
// p_a^p_n mod p_p
long long int p_b = 1, p_t = 1;
for (; p_b <= p_n; p_b <<= 1)
;
for (p_b >>= 1; p_b > 0; p_b >>= 1) {
p_t *= p_t;
if (p_t >= p_p)
p_t %= p_p;
if (p_n & p_b)
p_t *= p_a;
if (p_t >= p_p)
p_t %= p_p;
}
return p_t;
}
long long int gcd(long long int g_a, long long int g_b) {
if (g_a < g_b)
gcd(g_b, g_a);
if (g_b == 0)
return g_a;
return gcd(g_b, g_a % g_b);
}
long long int divide(long long int d_a, long long int d_b,
long long int d_p = 1e9 + 7) {
// d_a/d_b mod d_p
// prime:d_p is prime
if (d_a >= d_p)
d_a %= d_p;
if (d_a < 0)
d_a += d_p;
if (d_b >= d_p)
d_b %= d_p;
if (d_b < 0)
d_b += d_p;
d_a *= pow_mod(d_b, d_p - 2, d_p);
return d_a % d_p;
}
int main() {
int n, m;
int i, j, k;
LL a, b, c;
LL p, q, r;
LL s = 0;
cin >> n >> m;
kai[0] = 1;
for (i = 1; i <= 3 * n; i++) {
kai[i] = kai[i - 1] * i % m;
}
for (i = 0, p = 1; i <= n; i++) {
for (j = 0, q = 1; i + j <= n; j++) {
b = p * q % m;
b = b * kai[i] % m;
b = b * kai[j] % m;
b = b * kai[3 * n - 3 * i - 2 * j] % m;
a = divide(kai[3 * n], b, m);
s += a;
if (s >= m)
s %= m;
q *= 2;
if (q >= m)
q %= m;
}
p *= 3;
if (p >= m)
p %= m;
}
cout << s << endl;
} | replace | 98 | 103 | 98 | 103 | TLE | |
p02738 | C++ | Runtime Error | #define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#pragma comment(linker, "/STACK:526000000")
#include "bits/stdc++.h"
using namespace std;
typedef string::const_iterator State;
#define eps 1e-8L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL
#define MOD 998244353LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a, b) for (long long(a) = 0; (a) < (b); ++(a))
#define ALL(x) (x).begin(), (x).end()
// geometry library
typedef complex<long double> Point;
typedef pair<complex<long double>, complex<long double>> Line;
typedef struct Circle {
complex<long double> center;
long double r;
} Circle;
long double dot(Point a, Point b) {
return (a.real() * b.real() + a.imag() * b.imag());
}
long double cross(Point a, Point b) {
return (a.real() * b.imag() - a.imag() * b.real());
}
long double Dist_Line_Point(Line a, Point b) {
if (dot(a.second - a.first, b - a.first) < eps)
return abs(b - a.first);
if (dot(a.first - a.second, b - a.second) < eps)
return abs(b - a.second);
return abs(cross(a.second - a.first, b - a.first)) / abs(a.second - a.first);
}
int is_intersected_ls(Line a, Line b) {
return (cross(a.second - a.first, b.first - a.first) *
cross(a.second - a.first, b.second - a.first) <
eps) &&
(cross(b.second - b.first, a.first - b.first) *
cross(b.second - b.first, a.second - b.first) <
eps);
}
Point intersection_l(Line a, Line b) {
Point da = a.second - a.first;
Point db = b.second - b.first;
return a.first + da * cross(db, b.first - a.first) / cross(db, da);
}
long double Dist_Line_Line(Line a, Line b) {
if (is_intersected_ls(a, b) == 1) {
return 0;
}
return min({Dist_Line_Point(a, b.first), Dist_Line_Point(a, b.second),
Dist_Line_Point(b, a.first), Dist_Line_Point(b, a.second)});
}
pair<Point, Point> intersection_Circle_Circle(Circle a, Circle b) {
long double dist = abs(a.center - b.center);
assert(dist <= eps + a.r + b.r);
assert(dist + eps >= abs(a.r - b.r));
Point target = b.center - a.center;
long double pointer =
target.real() * target.real() + target.imag() * target.imag();
long double aa = pointer + a.r * a.r - b.r * b.r;
aa /= 2.0L;
Point l{(aa * target.real() +
target.imag() * sqrt(pointer * a.r * a.r - aa * aa)) /
pointer,
(aa * target.imag() -
target.real() * sqrt(pointer * a.r * a.r - aa * aa)) /
pointer};
Point r{(aa * target.real() -
target.imag() * sqrt(pointer * a.r * a.r - aa * aa)) /
pointer,
(aa * target.imag() +
target.real() * sqrt(pointer * a.r * a.r - aa * aa)) /
pointer};
r = r + a.center;
l = l + a.center;
return mp(l, r);
}
// end of geometry
ll gcd(int a, int b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
template <typename A> A pows(A val, ll b) {
assert(b >= 1);
A ans = val;
b--;
while (b) {
if (b % 2) {
ans *= val;
}
val *= val;
b /= 2LL;
}
return ans;
}
template <typename A> class Compressor {
public:
bool is_zipped = false;
map<A, ll> zipper;
map<ll, A> unzipper;
queue<A> fetcher;
Compressor() {
is_zipped = false;
zipper.clear();
unzipper.clear();
}
void add(A now) {
assert(is_zipped == false);
zipper[now] = 1;
fetcher.push(now);
}
void exec() {
assert(is_zipped == false);
int cnt = 0;
for (auto i = zipper.begin(); i != zipper.end(); ++i) {
i->second = cnt;
unzipper[cnt] = i->first;
cnt++;
}
is_zipped = true;
}
ll fetch() {
assert(is_zipped == true);
A hoge = fetcher.front();
fetcher.pop();
return zipper[hoge];
}
ll zip(A now) {
assert(is_zipped == true);
assert(zipper.find(now) != zipper.end());
return zipper[now];
}
A unzip(ll a) {
assert(is_zipped == true);
assert(a < unzipper.size());
return unzipper[a];
}
ll next(A now) {
auto x = zipper.upper_bound(now);
if (x == zipper.end())
return zipper.size();
return (ll)((*x).second);
}
ll back(A now) {
auto x = zipper.lower_bound(now);
if (x == zipper.begin())
return -1;
x--;
return (ll)((*x).second);
}
};
template <typename A> class Matrix {
public:
vector<vector<A>> data;
Matrix(vector<vector<A>> a) : data(a) {}
Matrix operator+(const Matrix obj) {
vector<vector<A>> ans;
assert(obj.data.size() == this->data.size());
assert(obj.data[0].size() == this->data[0].size());
REP(i, obj.data.size()) {
ans.push_back(vector<A>());
REP(q, obj.data[i].size()) {
A hoge = obj.data[i][q] + (this->data[i][q]);
ans.back().push_back(hoge);
}
}
return Matrix(ans);
}
Matrix operator-(const Matrix obj) {
vector<vector<A>> ans;
assert(obj.data.size() == this->data.size());
assert(obj.data[0].size() == this->data[0].size());
REP(i, obj.data.size()) {
ans.push_back(vector<A>());
REP(q, obj.data[i].size()) {
A hoge = this->data[i][q] - obj.data[i][q];
ans.back().push_back(hoge);
}
}
return Matrix(ans);
}
Matrix operator*(const Matrix obj) {
vector<vector<A>> ans;
assert(obj.data.size() == this->data[0].size());
REP(i, this->data.size()) {
ans.push_back(vector<A>());
REP(q, obj.data[0].size()) {
A hoge = ((this->data[i][0]) * (obj.data[0][q]));
for (int t = 1; t < obj.data.size(); ++t) {
hoge += ((this->data[i][t]) * obj.data[t][q]);
}
ans.back().push_back(hoge);
}
}
return Matrix(ans);
}
Matrix &operator*=(const Matrix obj) {
*this = (*this * obj);
return *this;
}
Matrix &operator+=(const Matrix obj) {
*this = (*this + obj);
return *this;
}
Matrix &operator-=(const Matrix obj) {
*this = (*this - obj);
return *this;
}
};
struct Fraction {
ll a;
ll b;
Fraction() : a(0LL), b(1LL) {}
Fraction(ll c, ll d) {
int hoge = gcd(llabs(c), llabs(d));
c /= hoge;
d /= hoge;
if (d < 0) {
d *= -1;
c *= -1;
}
a = c;
b = d;
}
bool operator<(Fraction rhs) const { return a * rhs.b < rhs.a * b; }
};
template <std::uint_fast64_t mod> class modint {
public:
using u64 = std::uint_fast64_t;
u64 value = 0;
modint() : value(0LL) {}
modint(ll a) : value(((a % mod) + 2 * mod) % mod) {}
constexpr modint operator+(const modint rhs) const {
return modint(*this) += rhs;
}
constexpr modint operator-(const modint rhs) const {
return modint(*this) -= rhs;
}
constexpr modint operator*(const modint rhs) const {
return modint(*this) *= rhs;
}
constexpr modint operator/(const modint rhs) const {
return modint(*this) /= rhs;
}
constexpr modint &operator+=(const modint rhs) {
value += rhs.value;
if (value >= mod) {
value -= mod;
}
return *this;
}
constexpr modint &operator-=(const modint rhs) {
if (value < rhs.value) {
value += mod;
}
value -= rhs.value;
return *this;
}
constexpr modint &operator*=(const modint rhs) {
value = (value * rhs.value) % mod;
return *this;
}
constexpr modint &operator/=(modint rhs) {
ll rem = mod - 2;
while (rem) {
if (rem % 2) {
*this *= rhs;
}
rhs *= rhs;
rem /= 2LL;
}
return *this;
}
bool operator<(modint rhs) const { return value < rhs.value; }
friend ostream &operator<<(ostream &os, modint &p) {
os << p.value;
return (os);
}
};
class Dice {
public:
vector<ll> vertexs;
// Up: 0,Left: 1,Center: 2,Right: 3,Adj: 4, Down: 5
Dice(vector<ll> init) : vertexs(init) {}
// Look from Center
void RtoL() {
for (int q = 1; q < 4; ++q) {
swap(vertexs[q], vertexs[q + 1]);
}
}
void LtoR() {
for (int q = 3; q >= 1; --q) {
swap(vertexs[q], vertexs[q + 1]);
}
}
void UtoD() {
swap(vertexs[5], vertexs[4]);
swap(vertexs[2], vertexs[5]);
swap(vertexs[0], vertexs[2]);
}
void DtoU() {
swap(vertexs[0], vertexs[2]);
swap(vertexs[2], vertexs[5]);
swap(vertexs[5], vertexs[4]);
}
bool ReachAble(Dice now) {
set<Dice> hoge;
queue<Dice> next;
next.push(now);
hoge.insert(now);
while (next.empty() == false) {
Dice seeing = next.front();
next.pop();
if (seeing == *this)
return true;
seeing.RtoL();
if (hoge.count(seeing) == 0) {
hoge.insert(seeing);
next.push(seeing);
}
seeing.LtoR();
seeing.LtoR();
if (hoge.count(seeing) == 0) {
hoge.insert(seeing);
next.push(seeing);
}
seeing.RtoL();
seeing.UtoD();
if (hoge.count(seeing) == 0) {
hoge.insert(seeing);
next.push(seeing);
}
seeing.DtoU();
seeing.DtoU();
if (hoge.count(seeing) == 0) {
hoge.insert(seeing);
next.push(seeing);
}
}
return false;
}
bool operator==(const Dice &a) {
for (int q = 0; q < 6; ++q) {
if (a.vertexs[q] != (*this).vertexs[q]) {
return false;
}
}
return true;
}
bool operator<(const Dice &a) const { return (*this).vertexs < a.vertexs; }
};
pair<Dice, Dice> TwoDimDice(int center, int up) {
int target = 1;
while (true) {
if (center != target && 7 - center != target && up != target &&
7 - up != target) {
break;
}
target++;
}
return mp(
Dice(vector<ll>{up, target, center, 7 - target, 7 - center, 7 - up}),
Dice(vector<ll>{up, 7 - target, center, target, 7 - center, 7 - up}));
}
tuple<Dice, Dice, Dice, Dice> OneDimDice(int center) {
int bo = min(center, 7 - center);
pair<int, int> goa;
if (bo == 1) {
goa = mp(2, 3);
} else if (bo == 2) {
goa = mp(1, 3);
} else if (bo == 3) {
goa = mp(1, 2);
}
tuple<Dice, Dice, Dice, Dice> now =
make_tuple(Dice(vector<ll>{goa.first, goa.second, center, 7 - goa.second,
7 - center, 7 - goa.first}),
Dice(vector<ll>{goa.first, 7 - goa.second, center, goa.second,
7 - center, 7 - goa.first}),
Dice(vector<ll>{7 - goa.first, goa.second, center,
7 - goa.second, 7 - center, goa.first}),
Dice(vector<ll>{7 - goa.first, 7 - goa.second, center,
goa.second, 7 - center, goa.first}));
return now;
}
template <typename A, typename B> class Dijkstra {
public:
vector<vector<pair<int, A>>> vertexs;
B Cost_Function;
Dijkstra(int n, B cost) : Cost_Function(cost) {
vertexs = vector<vector<pair<int, A>>>(n, vector<pair<int, A>>{});
}
~Dijkstra() { vertexs.clear(); }
void add_edge(int a, int b, A c) { vertexs[a].push_back(mp(b, c)); }
vector<ll> build_result(int StartPoint) {
vector<ll> dist(vertexs.size(), 2e18);
dist[StartPoint] = 0;
priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>>
next;
next.push(make_pair(0, StartPoint));
while (next.empty() == false) {
pair<ll, int> now = next.top();
next.pop();
if (dist[now.second] != now.first)
continue;
for (auto x : vertexs[now.second]) {
ll now_cost = now.first + Cost_Function(x.second);
if (dist[x.first] > now_cost) {
dist[x.first] = now_cost;
next.push(mp(now_cost, x.first));
}
}
}
return dist;
}
};
class Dinic {
public:
struct edge {
int to;
int cap;
int rev;
};
vector<vector<edge>> Graph;
vector<int> level;
vector<int> itr;
Dinic(int n) { Graph = vector<vector<edge>>(n, vector<edge>()); }
void add_edge(int a, int b, int cap) {
Graph[a].push_back(edge{b, cap, (int)Graph[b].size()});
Graph[b].push_back(edge{a, 0, (int)Graph[a].size() - 1});
}
void bfs(int s) {
level = vector<int>(Graph.size(), -1);
level[s] = 0;
queue<int> next;
next.push(s);
while (next.empty() == false) {
int now = next.front();
next.pop();
for (auto x : Graph[now]) {
if (x.cap == 0)
continue;
if (level[x.to] == -1) {
level[x.to] = level[now] + 1;
next.push(x.to);
}
}
}
}
int dfs(int now, int goal, int val) {
if (goal == now)
return val;
for (int &i = itr[now]; i < (int)Graph[now].size(); ++i) {
edge &target = Graph[now][i];
if (target.cap > 0 && level[now] < level[target.to]) {
int d = dfs(target.to, goal, min(val, target.cap));
if (d > 0) {
target.cap -= d;
Graph[target.to][target.rev].cap += d;
return d;
}
}
}
return 0;
}
int run(int s, int t) {
int ans = 0;
int f = 0;
while (bfs(s), level[t] >= 0) {
itr = vector<int>(Graph.size(), 0);
while ((f = dfs(s, t, 1e9)) > 0) {
ans += f;
}
}
return ans;
}
};
class HLDecomposition {
public:
vector<vector<int>> vertexs;
vector<int> depth;
vector<int> backs;
vector<int> connections;
vector<int> zip, unzip;
HLDecomposition(int n) {
vertexs = vector<vector<int>>(n, vector<int>());
depth = vector<int>(n);
zip = vector<int>(n);
unzip = zip;
}
void add_edge(int a, int b) {
vertexs[a].push_back(b);
vertexs[b].push_back(a);
}
int depth_dfs(int now, int back) {
depth[now] = 0;
for (auto x : vertexs[now]) {
if (x == back)
continue;
depth[now] = max(depth[now], 1 + depth_dfs(x, now));
}
return depth[now];
}
void dfs(int now, int backing) {
zip[now] = backs.size();
unzip[backs.size()] = now;
backs.push_back(backing);
int now_max = -1;
int itr = -1;
for (auto x : vertexs[now]) {
if (depth[x] > depth[now])
continue;
if (now_max < depth[x]) {
now_max = depth[x];
itr = x;
}
}
if (itr == -1)
return;
connections.push_back(connections.back());
dfs(itr, backing);
for (auto x : vertexs[now]) {
if (depth[x] > depth[now])
continue;
if (x == itr)
continue;
connections.push_back(zip[now]);
dfs(x, backs.size());
}
return;
}
void build() {
depth_dfs(0, -1);
connections.push_back(-1);
dfs(0, -1);
}
vector<pair<int, int>> query(int a, int b) {
a = zip[a];
b = zip[b];
vector<pair<int, int>> ans;
while (backs[a] != backs[b]) {
if (a < b)
swap(a, b);
ans.push_back(mp(backs[a], a + 1));
a = connections[a];
}
if (a > b)
swap(a, b);
ans.push_back(mp(a, b + 1));
return ans;
}
int lca(int a, int b) {
a = zip[a];
b = zip[b];
while (backs[a] != backs[b]) {
if (a < b)
swap(a, b);
a = connections[a];
}
return unzip[min(a, b)];
}
};
// by ei1333
// https://ei1333.github.io/luzhiled/snippets/structure/segment-tree.html
template <typename Monoid> struct SegmentTree {
using F = function<Monoid(Monoid, Monoid)>;
int sz;
vector<Monoid> seg;
const F f;
const Monoid M1;
SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1) {
sz = 1;
while (sz < n)
sz <<= 1;
seg.assign(2 * sz + 1, M1);
}
void set(int k, const Monoid &x) { seg[k + sz] = x; }
void build() {
for (int k = sz - 1; k > 0; k--) {
seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
}
}
void update(int k, const Monoid &x) {
k += sz;
seg[k] = x;
while (k >>= 1) {
seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
}
}
Monoid query(int a, int b) {
Monoid L = M1, R = M1;
for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
if (a & 1)
L = f(L, seg[a++]);
if (b & 1)
R = f(seg[--b], R);
}
return f(L, R);
}
Monoid operator[](const int &k) const { return seg[k + sz]; }
template <typename C>
int find_subtree(int a, const C &check, Monoid &M, bool type) {
while (a < sz) {
Monoid nxt = type ? f(seg[2 * a + type], M) : f(M, seg[2 * a + type]);
if (check(nxt))
a = 2 * a + type;
else
M = nxt, a = 2 * a + 1 - type;
}
return a - sz;
}
template <typename C> int find_first(int a, const C &check) {
Monoid L = M1;
if (a <= 0) {
if (check(f(L, seg[1])))
return find_subtree(1, check, L, false);
return -1;
}
int b = sz;
for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
if (a & 1) {
Monoid nxt = f(L, seg[a]);
if (check(nxt))
return find_subtree(a, check, L, false);
L = nxt;
++a;
}
}
return -1;
}
template <typename C> int find_last(int b, const C &check) {
Monoid R = M1;
if (b >= sz) {
if (check(f(seg[1], R)))
return find_subtree(1, check, R, true);
return -1;
}
int a = sz;
for (b += sz; a < b; a >>= 1, b >>= 1) {
if (b & 1) {
Monoid nxt = f(seg[--b], R);
if (check(nxt))
return find_subtree(b, check, R, true);
R = nxt;
}
}
return -1;
}
};
template <typename Monoid, typename OperatorMonoid = Monoid>
struct LazySegmentTree {
using F = function<Monoid(Monoid, Monoid)>;
using G = function<Monoid(Monoid, OperatorMonoid)>;
using H = function<OperatorMonoid(OperatorMonoid, OperatorMonoid)>;
int sz, height;
vector<Monoid> data;
vector<OperatorMonoid> lazy;
const F f;
const G g;
const H h;
const Monoid M1;
const OperatorMonoid OM0;
LazySegmentTree(int n, const F f, const G g, const H h, const Monoid &M1,
const OperatorMonoid OM0)
: f(f), g(g), h(h), M1(M1), OM0(OM0) {
sz = 1;
height = 0;
while (sz < n)
sz <<= 1, height++;
data.assign(2 * sz, M1);
lazy.assign(2 * sz, OM0);
}
void set(int k, const Monoid &x) { data[k + sz] = x; }
void build() {
for (int k = sz - 1; k > 0; k--) {
data[k] = f(data[2 * k + 0], data[2 * k + 1]);
}
}
inline void propagate(int k) {
if (lazy[k] != OM0) {
lazy[2 * k + 0] = h(lazy[2 * k + 0], lazy[k]);
lazy[2 * k + 1] = h(lazy[2 * k + 1], lazy[k]);
data[k] = reflect(k);
lazy[k] = OM0;
}
}
inline Monoid reflect(int k) {
return lazy[k] == OM0 ? data[k] : g(data[k], lazy[k]);
}
inline void recalc(int k) {
while (k >>= 1)
data[k] = f(reflect(2 * k + 0), reflect(2 * k + 1));
}
inline void thrust(int k) {
for (int i = height; i > 0; i--)
propagate(k >> i);
}
void update(int a, int b, const OperatorMonoid &x) {
thrust(a += sz);
thrust(b += sz - 1);
for (int l = a, r = b + 1; l < r; l >>= 1, r >>= 1) {
if (l & 1)
lazy[l] = h(lazy[l], x), ++l;
if (r & 1)
--r, lazy[r] = h(lazy[r], x);
}
recalc(a);
recalc(b);
}
Monoid query(int a, int b) {
thrust(a += sz);
thrust(b += sz - 1);
Monoid L = M1, R = M1;
for (int l = a, r = b + 1; l < r; l >>= 1, r >>= 1) {
if (l & 1)
L = f(L, reflect(l++));
if (r & 1)
R = f(reflect(--r), R);
}
return f(L, R);
}
Monoid operator[](const int &k) { return query(k, k + 1); }
template <typename C>
int find_subtree(int a, const C &check, Monoid &M, bool type) {
while (a < sz) {
propagate(a);
Monoid nxt =
type ? f(reflect(2 * a + type), M) : f(M, reflect(2 * a + type));
if (check(nxt))
a = 2 * a + type;
else
M = nxt, a = 2 * a + 1 - type;
}
return a - sz;
}
template <typename C> int find_first(int a, const C &check) {
Monoid L = M1;
if (a <= 0) {
if (check(f(L, reflect(1))))
return find_subtree(1, check, L, false);
return -1;
}
thrust(a + sz);
int b = sz;
for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
if (a & 1) {
Monoid nxt = f(L, reflect(a));
if (check(nxt))
return find_subtree(a, check, L, false);
L = nxt;
++a;
}
}
return -1;
}
template <typename C> int find_last(int b, const C &check) {
Monoid R = M1;
if (b >= sz) {
if (check(f(reflect(1), R)))
return find_subtree(1, check, R, true);
return -1;
}
thrust(b + sz - 1);
int a = sz;
for (b += sz; a < b; a >>= 1, b >>= 1) {
if (b & 1) {
Monoid nxt = f(reflect(--b), R);
if (check(nxt))
return find_subtree(b, check, R, true);
R = nxt;
}
}
return -1;
}
};
class KMP {
public:
vector<ll> table;
vector<ll> Pattern;
KMP(vector<ll> a) { build(a); }
void build(vector<ll> a) {
Pattern = a;
table = vector<ll>(a.size() + 1, -1);
int j = -1;
for (int i = 0; i < a.size(); ++i) {
while (j >= 0 && Pattern[i] != Pattern[j]) {
j = table[j];
}
table[i + 1] = ++j;
}
return;
}
vector<ll> search(vector<ll> a) {
vector<ll> ans;
for (int i = 0, k = 0; i < a.size(); ++i) {
while (k >= 0 && a[i] != Pattern[k])
k = table[k];
++k;
if (k >= Pattern.size()) {
ans.push_back(i - Pattern.size() + 1);
k = table[k];
}
}
return ans;
}
};
unsigned long xor128() {
static unsigned long x = 123456789, y = 362436069, z = 521288629,
w = 88675123;
unsigned long t = (x ^ (x << 11));
x = y;
y = z;
z = w;
return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}
void init() {
iostream::sync_with_stdio(false);
cout << fixed << setprecision(20);
}
#define int ll
int dp[4000][4000];
void solve() {
int n, m;
cin >> n >> m;
dp[0][0] = 1;
REP(i, 3 * n) {
REP(q, n + 1) {
dp[i + 1][q] += dp[i][q];
dp[i + 2][q + 1] += (dp[i][q] * (i + 1LL)) % m;
dp[i + 3][q + 1] += ((dp[i][q] * (i + 1LL)) % m * (i + 2LL)) % m;
dp[i + 1][q] %= m;
dp[i + 2][q + 1] %= m;
dp[i + 3][q + 1] %= m;
}
}
int ans = 0;
REP(q, n + 1) { ans += dp[n * 3][q]; }
ans %= m;
cout << ans << endl;
}
#undef int
int main() {
init();
solve();
} | #define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#pragma comment(linker, "/STACK:526000000")
#include "bits/stdc++.h"
using namespace std;
typedef string::const_iterator State;
#define eps 1e-8L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL
#define MOD 998244353LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a, b) for (long long(a) = 0; (a) < (b); ++(a))
#define ALL(x) (x).begin(), (x).end()
// geometry library
typedef complex<long double> Point;
typedef pair<complex<long double>, complex<long double>> Line;
typedef struct Circle {
complex<long double> center;
long double r;
} Circle;
long double dot(Point a, Point b) {
return (a.real() * b.real() + a.imag() * b.imag());
}
long double cross(Point a, Point b) {
return (a.real() * b.imag() - a.imag() * b.real());
}
long double Dist_Line_Point(Line a, Point b) {
if (dot(a.second - a.first, b - a.first) < eps)
return abs(b - a.first);
if (dot(a.first - a.second, b - a.second) < eps)
return abs(b - a.second);
return abs(cross(a.second - a.first, b - a.first)) / abs(a.second - a.first);
}
int is_intersected_ls(Line a, Line b) {
return (cross(a.second - a.first, b.first - a.first) *
cross(a.second - a.first, b.second - a.first) <
eps) &&
(cross(b.second - b.first, a.first - b.first) *
cross(b.second - b.first, a.second - b.first) <
eps);
}
Point intersection_l(Line a, Line b) {
Point da = a.second - a.first;
Point db = b.second - b.first;
return a.first + da * cross(db, b.first - a.first) / cross(db, da);
}
long double Dist_Line_Line(Line a, Line b) {
if (is_intersected_ls(a, b) == 1) {
return 0;
}
return min({Dist_Line_Point(a, b.first), Dist_Line_Point(a, b.second),
Dist_Line_Point(b, a.first), Dist_Line_Point(b, a.second)});
}
pair<Point, Point> intersection_Circle_Circle(Circle a, Circle b) {
long double dist = abs(a.center - b.center);
assert(dist <= eps + a.r + b.r);
assert(dist + eps >= abs(a.r - b.r));
Point target = b.center - a.center;
long double pointer =
target.real() * target.real() + target.imag() * target.imag();
long double aa = pointer + a.r * a.r - b.r * b.r;
aa /= 2.0L;
Point l{(aa * target.real() +
target.imag() * sqrt(pointer * a.r * a.r - aa * aa)) /
pointer,
(aa * target.imag() -
target.real() * sqrt(pointer * a.r * a.r - aa * aa)) /
pointer};
Point r{(aa * target.real() -
target.imag() * sqrt(pointer * a.r * a.r - aa * aa)) /
pointer,
(aa * target.imag() +
target.real() * sqrt(pointer * a.r * a.r - aa * aa)) /
pointer};
r = r + a.center;
l = l + a.center;
return mp(l, r);
}
// end of geometry
ll gcd(int a, int b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
template <typename A> A pows(A val, ll b) {
assert(b >= 1);
A ans = val;
b--;
while (b) {
if (b % 2) {
ans *= val;
}
val *= val;
b /= 2LL;
}
return ans;
}
template <typename A> class Compressor {
public:
bool is_zipped = false;
map<A, ll> zipper;
map<ll, A> unzipper;
queue<A> fetcher;
Compressor() {
is_zipped = false;
zipper.clear();
unzipper.clear();
}
void add(A now) {
assert(is_zipped == false);
zipper[now] = 1;
fetcher.push(now);
}
void exec() {
assert(is_zipped == false);
int cnt = 0;
for (auto i = zipper.begin(); i != zipper.end(); ++i) {
i->second = cnt;
unzipper[cnt] = i->first;
cnt++;
}
is_zipped = true;
}
ll fetch() {
assert(is_zipped == true);
A hoge = fetcher.front();
fetcher.pop();
return zipper[hoge];
}
ll zip(A now) {
assert(is_zipped == true);
assert(zipper.find(now) != zipper.end());
return zipper[now];
}
A unzip(ll a) {
assert(is_zipped == true);
assert(a < unzipper.size());
return unzipper[a];
}
ll next(A now) {
auto x = zipper.upper_bound(now);
if (x == zipper.end())
return zipper.size();
return (ll)((*x).second);
}
ll back(A now) {
auto x = zipper.lower_bound(now);
if (x == zipper.begin())
return -1;
x--;
return (ll)((*x).second);
}
};
template <typename A> class Matrix {
public:
vector<vector<A>> data;
Matrix(vector<vector<A>> a) : data(a) {}
Matrix operator+(const Matrix obj) {
vector<vector<A>> ans;
assert(obj.data.size() == this->data.size());
assert(obj.data[0].size() == this->data[0].size());
REP(i, obj.data.size()) {
ans.push_back(vector<A>());
REP(q, obj.data[i].size()) {
A hoge = obj.data[i][q] + (this->data[i][q]);
ans.back().push_back(hoge);
}
}
return Matrix(ans);
}
Matrix operator-(const Matrix obj) {
vector<vector<A>> ans;
assert(obj.data.size() == this->data.size());
assert(obj.data[0].size() == this->data[0].size());
REP(i, obj.data.size()) {
ans.push_back(vector<A>());
REP(q, obj.data[i].size()) {
A hoge = this->data[i][q] - obj.data[i][q];
ans.back().push_back(hoge);
}
}
return Matrix(ans);
}
Matrix operator*(const Matrix obj) {
vector<vector<A>> ans;
assert(obj.data.size() == this->data[0].size());
REP(i, this->data.size()) {
ans.push_back(vector<A>());
REP(q, obj.data[0].size()) {
A hoge = ((this->data[i][0]) * (obj.data[0][q]));
for (int t = 1; t < obj.data.size(); ++t) {
hoge += ((this->data[i][t]) * obj.data[t][q]);
}
ans.back().push_back(hoge);
}
}
return Matrix(ans);
}
Matrix &operator*=(const Matrix obj) {
*this = (*this * obj);
return *this;
}
Matrix &operator+=(const Matrix obj) {
*this = (*this + obj);
return *this;
}
Matrix &operator-=(const Matrix obj) {
*this = (*this - obj);
return *this;
}
};
struct Fraction {
ll a;
ll b;
Fraction() : a(0LL), b(1LL) {}
Fraction(ll c, ll d) {
int hoge = gcd(llabs(c), llabs(d));
c /= hoge;
d /= hoge;
if (d < 0) {
d *= -1;
c *= -1;
}
a = c;
b = d;
}
bool operator<(Fraction rhs) const { return a * rhs.b < rhs.a * b; }
};
template <std::uint_fast64_t mod> class modint {
public:
using u64 = std::uint_fast64_t;
u64 value = 0;
modint() : value(0LL) {}
modint(ll a) : value(((a % mod) + 2 * mod) % mod) {}
constexpr modint operator+(const modint rhs) const {
return modint(*this) += rhs;
}
constexpr modint operator-(const modint rhs) const {
return modint(*this) -= rhs;
}
constexpr modint operator*(const modint rhs) const {
return modint(*this) *= rhs;
}
constexpr modint operator/(const modint rhs) const {
return modint(*this) /= rhs;
}
constexpr modint &operator+=(const modint rhs) {
value += rhs.value;
if (value >= mod) {
value -= mod;
}
return *this;
}
constexpr modint &operator-=(const modint rhs) {
if (value < rhs.value) {
value += mod;
}
value -= rhs.value;
return *this;
}
constexpr modint &operator*=(const modint rhs) {
value = (value * rhs.value) % mod;
return *this;
}
constexpr modint &operator/=(modint rhs) {
ll rem = mod - 2;
while (rem) {
if (rem % 2) {
*this *= rhs;
}
rhs *= rhs;
rem /= 2LL;
}
return *this;
}
bool operator<(modint rhs) const { return value < rhs.value; }
friend ostream &operator<<(ostream &os, modint &p) {
os << p.value;
return (os);
}
};
class Dice {
public:
vector<ll> vertexs;
// Up: 0,Left: 1,Center: 2,Right: 3,Adj: 4, Down: 5
Dice(vector<ll> init) : vertexs(init) {}
// Look from Center
void RtoL() {
for (int q = 1; q < 4; ++q) {
swap(vertexs[q], vertexs[q + 1]);
}
}
void LtoR() {
for (int q = 3; q >= 1; --q) {
swap(vertexs[q], vertexs[q + 1]);
}
}
void UtoD() {
swap(vertexs[5], vertexs[4]);
swap(vertexs[2], vertexs[5]);
swap(vertexs[0], vertexs[2]);
}
void DtoU() {
swap(vertexs[0], vertexs[2]);
swap(vertexs[2], vertexs[5]);
swap(vertexs[5], vertexs[4]);
}
bool ReachAble(Dice now) {
set<Dice> hoge;
queue<Dice> next;
next.push(now);
hoge.insert(now);
while (next.empty() == false) {
Dice seeing = next.front();
next.pop();
if (seeing == *this)
return true;
seeing.RtoL();
if (hoge.count(seeing) == 0) {
hoge.insert(seeing);
next.push(seeing);
}
seeing.LtoR();
seeing.LtoR();
if (hoge.count(seeing) == 0) {
hoge.insert(seeing);
next.push(seeing);
}
seeing.RtoL();
seeing.UtoD();
if (hoge.count(seeing) == 0) {
hoge.insert(seeing);
next.push(seeing);
}
seeing.DtoU();
seeing.DtoU();
if (hoge.count(seeing) == 0) {
hoge.insert(seeing);
next.push(seeing);
}
}
return false;
}
bool operator==(const Dice &a) {
for (int q = 0; q < 6; ++q) {
if (a.vertexs[q] != (*this).vertexs[q]) {
return false;
}
}
return true;
}
bool operator<(const Dice &a) const { return (*this).vertexs < a.vertexs; }
};
pair<Dice, Dice> TwoDimDice(int center, int up) {
int target = 1;
while (true) {
if (center != target && 7 - center != target && up != target &&
7 - up != target) {
break;
}
target++;
}
return mp(
Dice(vector<ll>{up, target, center, 7 - target, 7 - center, 7 - up}),
Dice(vector<ll>{up, 7 - target, center, target, 7 - center, 7 - up}));
}
tuple<Dice, Dice, Dice, Dice> OneDimDice(int center) {
int bo = min(center, 7 - center);
pair<int, int> goa;
if (bo == 1) {
goa = mp(2, 3);
} else if (bo == 2) {
goa = mp(1, 3);
} else if (bo == 3) {
goa = mp(1, 2);
}
tuple<Dice, Dice, Dice, Dice> now =
make_tuple(Dice(vector<ll>{goa.first, goa.second, center, 7 - goa.second,
7 - center, 7 - goa.first}),
Dice(vector<ll>{goa.first, 7 - goa.second, center, goa.second,
7 - center, 7 - goa.first}),
Dice(vector<ll>{7 - goa.first, goa.second, center,
7 - goa.second, 7 - center, goa.first}),
Dice(vector<ll>{7 - goa.first, 7 - goa.second, center,
goa.second, 7 - center, goa.first}));
return now;
}
template <typename A, typename B> class Dijkstra {
public:
vector<vector<pair<int, A>>> vertexs;
B Cost_Function;
Dijkstra(int n, B cost) : Cost_Function(cost) {
vertexs = vector<vector<pair<int, A>>>(n, vector<pair<int, A>>{});
}
~Dijkstra() { vertexs.clear(); }
void add_edge(int a, int b, A c) { vertexs[a].push_back(mp(b, c)); }
vector<ll> build_result(int StartPoint) {
vector<ll> dist(vertexs.size(), 2e18);
dist[StartPoint] = 0;
priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>>
next;
next.push(make_pair(0, StartPoint));
while (next.empty() == false) {
pair<ll, int> now = next.top();
next.pop();
if (dist[now.second] != now.first)
continue;
for (auto x : vertexs[now.second]) {
ll now_cost = now.first + Cost_Function(x.second);
if (dist[x.first] > now_cost) {
dist[x.first] = now_cost;
next.push(mp(now_cost, x.first));
}
}
}
return dist;
}
};
class Dinic {
public:
struct edge {
int to;
int cap;
int rev;
};
vector<vector<edge>> Graph;
vector<int> level;
vector<int> itr;
Dinic(int n) { Graph = vector<vector<edge>>(n, vector<edge>()); }
void add_edge(int a, int b, int cap) {
Graph[a].push_back(edge{b, cap, (int)Graph[b].size()});
Graph[b].push_back(edge{a, 0, (int)Graph[a].size() - 1});
}
void bfs(int s) {
level = vector<int>(Graph.size(), -1);
level[s] = 0;
queue<int> next;
next.push(s);
while (next.empty() == false) {
int now = next.front();
next.pop();
for (auto x : Graph[now]) {
if (x.cap == 0)
continue;
if (level[x.to] == -1) {
level[x.to] = level[now] + 1;
next.push(x.to);
}
}
}
}
int dfs(int now, int goal, int val) {
if (goal == now)
return val;
for (int &i = itr[now]; i < (int)Graph[now].size(); ++i) {
edge &target = Graph[now][i];
if (target.cap > 0 && level[now] < level[target.to]) {
int d = dfs(target.to, goal, min(val, target.cap));
if (d > 0) {
target.cap -= d;
Graph[target.to][target.rev].cap += d;
return d;
}
}
}
return 0;
}
int run(int s, int t) {
int ans = 0;
int f = 0;
while (bfs(s), level[t] >= 0) {
itr = vector<int>(Graph.size(), 0);
while ((f = dfs(s, t, 1e9)) > 0) {
ans += f;
}
}
return ans;
}
};
class HLDecomposition {
public:
vector<vector<int>> vertexs;
vector<int> depth;
vector<int> backs;
vector<int> connections;
vector<int> zip, unzip;
HLDecomposition(int n) {
vertexs = vector<vector<int>>(n, vector<int>());
depth = vector<int>(n);
zip = vector<int>(n);
unzip = zip;
}
void add_edge(int a, int b) {
vertexs[a].push_back(b);
vertexs[b].push_back(a);
}
int depth_dfs(int now, int back) {
depth[now] = 0;
for (auto x : vertexs[now]) {
if (x == back)
continue;
depth[now] = max(depth[now], 1 + depth_dfs(x, now));
}
return depth[now];
}
void dfs(int now, int backing) {
zip[now] = backs.size();
unzip[backs.size()] = now;
backs.push_back(backing);
int now_max = -1;
int itr = -1;
for (auto x : vertexs[now]) {
if (depth[x] > depth[now])
continue;
if (now_max < depth[x]) {
now_max = depth[x];
itr = x;
}
}
if (itr == -1)
return;
connections.push_back(connections.back());
dfs(itr, backing);
for (auto x : vertexs[now]) {
if (depth[x] > depth[now])
continue;
if (x == itr)
continue;
connections.push_back(zip[now]);
dfs(x, backs.size());
}
return;
}
void build() {
depth_dfs(0, -1);
connections.push_back(-1);
dfs(0, -1);
}
vector<pair<int, int>> query(int a, int b) {
a = zip[a];
b = zip[b];
vector<pair<int, int>> ans;
while (backs[a] != backs[b]) {
if (a < b)
swap(a, b);
ans.push_back(mp(backs[a], a + 1));
a = connections[a];
}
if (a > b)
swap(a, b);
ans.push_back(mp(a, b + 1));
return ans;
}
int lca(int a, int b) {
a = zip[a];
b = zip[b];
while (backs[a] != backs[b]) {
if (a < b)
swap(a, b);
a = connections[a];
}
return unzip[min(a, b)];
}
};
// by ei1333
// https://ei1333.github.io/luzhiled/snippets/structure/segment-tree.html
template <typename Monoid> struct SegmentTree {
using F = function<Monoid(Monoid, Monoid)>;
int sz;
vector<Monoid> seg;
const F f;
const Monoid M1;
SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1) {
sz = 1;
while (sz < n)
sz <<= 1;
seg.assign(2 * sz + 1, M1);
}
void set(int k, const Monoid &x) { seg[k + sz] = x; }
void build() {
for (int k = sz - 1; k > 0; k--) {
seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
}
}
void update(int k, const Monoid &x) {
k += sz;
seg[k] = x;
while (k >>= 1) {
seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
}
}
Monoid query(int a, int b) {
Monoid L = M1, R = M1;
for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
if (a & 1)
L = f(L, seg[a++]);
if (b & 1)
R = f(seg[--b], R);
}
return f(L, R);
}
Monoid operator[](const int &k) const { return seg[k + sz]; }
template <typename C>
int find_subtree(int a, const C &check, Monoid &M, bool type) {
while (a < sz) {
Monoid nxt = type ? f(seg[2 * a + type], M) : f(M, seg[2 * a + type]);
if (check(nxt))
a = 2 * a + type;
else
M = nxt, a = 2 * a + 1 - type;
}
return a - sz;
}
template <typename C> int find_first(int a, const C &check) {
Monoid L = M1;
if (a <= 0) {
if (check(f(L, seg[1])))
return find_subtree(1, check, L, false);
return -1;
}
int b = sz;
for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
if (a & 1) {
Monoid nxt = f(L, seg[a]);
if (check(nxt))
return find_subtree(a, check, L, false);
L = nxt;
++a;
}
}
return -1;
}
template <typename C> int find_last(int b, const C &check) {
Monoid R = M1;
if (b >= sz) {
if (check(f(seg[1], R)))
return find_subtree(1, check, R, true);
return -1;
}
int a = sz;
for (b += sz; a < b; a >>= 1, b >>= 1) {
if (b & 1) {
Monoid nxt = f(seg[--b], R);
if (check(nxt))
return find_subtree(b, check, R, true);
R = nxt;
}
}
return -1;
}
};
template <typename Monoid, typename OperatorMonoid = Monoid>
struct LazySegmentTree {
using F = function<Monoid(Monoid, Monoid)>;
using G = function<Monoid(Monoid, OperatorMonoid)>;
using H = function<OperatorMonoid(OperatorMonoid, OperatorMonoid)>;
int sz, height;
vector<Monoid> data;
vector<OperatorMonoid> lazy;
const F f;
const G g;
const H h;
const Monoid M1;
const OperatorMonoid OM0;
LazySegmentTree(int n, const F f, const G g, const H h, const Monoid &M1,
const OperatorMonoid OM0)
: f(f), g(g), h(h), M1(M1), OM0(OM0) {
sz = 1;
height = 0;
while (sz < n)
sz <<= 1, height++;
data.assign(2 * sz, M1);
lazy.assign(2 * sz, OM0);
}
void set(int k, const Monoid &x) { data[k + sz] = x; }
void build() {
for (int k = sz - 1; k > 0; k--) {
data[k] = f(data[2 * k + 0], data[2 * k + 1]);
}
}
inline void propagate(int k) {
if (lazy[k] != OM0) {
lazy[2 * k + 0] = h(lazy[2 * k + 0], lazy[k]);
lazy[2 * k + 1] = h(lazy[2 * k + 1], lazy[k]);
data[k] = reflect(k);
lazy[k] = OM0;
}
}
inline Monoid reflect(int k) {
return lazy[k] == OM0 ? data[k] : g(data[k], lazy[k]);
}
inline void recalc(int k) {
while (k >>= 1)
data[k] = f(reflect(2 * k + 0), reflect(2 * k + 1));
}
inline void thrust(int k) {
for (int i = height; i > 0; i--)
propagate(k >> i);
}
void update(int a, int b, const OperatorMonoid &x) {
thrust(a += sz);
thrust(b += sz - 1);
for (int l = a, r = b + 1; l < r; l >>= 1, r >>= 1) {
if (l & 1)
lazy[l] = h(lazy[l], x), ++l;
if (r & 1)
--r, lazy[r] = h(lazy[r], x);
}
recalc(a);
recalc(b);
}
Monoid query(int a, int b) {
thrust(a += sz);
thrust(b += sz - 1);
Monoid L = M1, R = M1;
for (int l = a, r = b + 1; l < r; l >>= 1, r >>= 1) {
if (l & 1)
L = f(L, reflect(l++));
if (r & 1)
R = f(reflect(--r), R);
}
return f(L, R);
}
Monoid operator[](const int &k) { return query(k, k + 1); }
template <typename C>
int find_subtree(int a, const C &check, Monoid &M, bool type) {
while (a < sz) {
propagate(a);
Monoid nxt =
type ? f(reflect(2 * a + type), M) : f(M, reflect(2 * a + type));
if (check(nxt))
a = 2 * a + type;
else
M = nxt, a = 2 * a + 1 - type;
}
return a - sz;
}
template <typename C> int find_first(int a, const C &check) {
Monoid L = M1;
if (a <= 0) {
if (check(f(L, reflect(1))))
return find_subtree(1, check, L, false);
return -1;
}
thrust(a + sz);
int b = sz;
for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
if (a & 1) {
Monoid nxt = f(L, reflect(a));
if (check(nxt))
return find_subtree(a, check, L, false);
L = nxt;
++a;
}
}
return -1;
}
template <typename C> int find_last(int b, const C &check) {
Monoid R = M1;
if (b >= sz) {
if (check(f(reflect(1), R)))
return find_subtree(1, check, R, true);
return -1;
}
thrust(b + sz - 1);
int a = sz;
for (b += sz; a < b; a >>= 1, b >>= 1) {
if (b & 1) {
Monoid nxt = f(reflect(--b), R);
if (check(nxt))
return find_subtree(b, check, R, true);
R = nxt;
}
}
return -1;
}
};
class KMP {
public:
vector<ll> table;
vector<ll> Pattern;
KMP(vector<ll> a) { build(a); }
void build(vector<ll> a) {
Pattern = a;
table = vector<ll>(a.size() + 1, -1);
int j = -1;
for (int i = 0; i < a.size(); ++i) {
while (j >= 0 && Pattern[i] != Pattern[j]) {
j = table[j];
}
table[i + 1] = ++j;
}
return;
}
vector<ll> search(vector<ll> a) {
vector<ll> ans;
for (int i = 0, k = 0; i < a.size(); ++i) {
while (k >= 0 && a[i] != Pattern[k])
k = table[k];
++k;
if (k >= Pattern.size()) {
ans.push_back(i - Pattern.size() + 1);
k = table[k];
}
}
return ans;
}
};
unsigned long xor128() {
static unsigned long x = 123456789, y = 362436069, z = 521288629,
w = 88675123;
unsigned long t = (x ^ (x << 11));
x = y;
y = z;
z = w;
return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}
void init() {
iostream::sync_with_stdio(false);
cout << fixed << setprecision(20);
}
#define int ll
int dp[7000][4000];
void solve() {
int n, m;
cin >> n >> m;
dp[0][0] = 1;
REP(i, 3 * n) {
REP(q, n + 1) {
dp[i + 1][q] += dp[i][q];
dp[i + 2][q + 1] += (dp[i][q] * (i + 1LL)) % m;
dp[i + 3][q + 1] += ((dp[i][q] * (i + 1LL)) % m * (i + 2LL)) % m;
dp[i + 1][q] %= m;
dp[i + 2][q + 1] %= m;
dp[i + 3][q + 1] %= m;
}
}
int ans = 0;
REP(q, n + 1) { ans += dp[n * 3][q]; }
ans %= m;
cout << ans << endl;
}
#undef int
int main() {
init();
solve();
} | replace | 878 | 879 | 878 | 879 | -11 | |
p02738 | C++ | Time Limit Exceeded | // #include <bits/stdc++.h>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
// #include "boost/multiprecision/cpp_int.hpp"
// typedef boost::multiprecision::cpp_int LL;
typedef long double dd;
// #define i_7 (ll)(1E9+7)
// #define i_7 998244353
// #define i_5 i_7-2
ll i_7;
ll mod(ll a) {
ll c = a % i_7;
if (c >= 0)
return c;
return c + i_7;
}
typedef pair<ll, ll> l_l;
typedef pair<dd, dd> d_d;
ll inf = (ll)1E16;
#define rep(i, l, r) for (ll i = l; i <= r; i++)
#define pb push_back
ll max(ll a, ll b) {
if (a < b)
return b;
else
return a;
}
ll min(ll a, ll b) {
if (a > b)
return b;
else
return a;
}
void Max(ll &pos, ll val) { pos = max(pos, val); } // Max(dp[n],dp[n-1]);
void Min(ll &pos, ll val) { pos = min(pos, val); }
void Add(ll &pos, ll val) { pos = mod(pos + val); }
dd EPS = 1E-9;
#define fastio \
ios::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define fi first
#define se second
#define endl "\n"
#define SORT(v) sort(v.begin(), v.end())
#define ERASE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define POSL(v, x) (lower_bound(v.begin(), v.end(), x) - v.begin())
#define POSU(v, x) (upper_bound(v.begin(), v.end(), x) - v.begin())
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
//////////////////////////
int main() {
fastio
ll n;
cin >> n >> i_7;
ll ofs = 10000;
ll dp[4][ofs * 2];
memset(dp, 0, sizeof(dp));
dp[0][ofs] = 1;
rep(i, 1, 3 * n) {
rep(j, 0, 2 * ofs - 1) { dp[i & 3][j] = 0; }
rep(j, 0, 2 * ofs - 1) {
if (i - 1 >= 0 && j + 1 <= 2 * ofs - 1)
Add(dp[i & 3][j], dp[(i + 3) & 3][j + 1]);
if (i - 2 >= 0 && j - 1 >= 0)
Add(dp[i & 3][j], mod(dp[(i + 2) & 3][j - 1] * (3 * n - i + 1)));
if (i - 3 >= 0)
Add(dp[i & 3][j],
mod(dp[(i + 1) & 3][j] * mod((3 * n - i + 2) * (3 * n - i + 1))));
}
}
ll ans = 0;
rep(j, 0, ofs) Add(ans, dp[(3 * n) & 3][j]);
cout << mod(ans) << endl;
return 0;
}
| // #include <bits/stdc++.h>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
// #include "boost/multiprecision/cpp_int.hpp"
// typedef boost::multiprecision::cpp_int LL;
typedef long double dd;
// #define i_7 (ll)(1E9+7)
// #define i_7 998244353
// #define i_5 i_7-2
ll i_7;
ll mod(ll a) {
ll c = a % i_7;
if (c >= 0)
return c;
return c + i_7;
}
typedef pair<ll, ll> l_l;
typedef pair<dd, dd> d_d;
ll inf = (ll)1E16;
#define rep(i, l, r) for (ll i = l; i <= r; i++)
#define pb push_back
ll max(ll a, ll b) {
if (a < b)
return b;
else
return a;
}
ll min(ll a, ll b) {
if (a > b)
return b;
else
return a;
}
void Max(ll &pos, ll val) { pos = max(pos, val); } // Max(dp[n],dp[n-1]);
void Min(ll &pos, ll val) { pos = min(pos, val); }
void Add(ll &pos, ll val) { pos = mod(pos + val); }
dd EPS = 1E-9;
#define fastio \
ios::sync_with_stdio(false); \
cin.tie(0); \
cout.tie(0);
#define fi first
#define se second
#define endl "\n"
#define SORT(v) sort(v.begin(), v.end())
#define ERASE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define POSL(v, x) (lower_bound(v.begin(), v.end(), x) - v.begin())
#define POSU(v, x) (upper_bound(v.begin(), v.end(), x) - v.begin())
template <class T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
//////////////////////////
int main() {
fastio
ll n;
cin >> n >> i_7;
ll ofs = 6005;
ll dp[4][ofs * 2];
memset(dp, 0, sizeof(dp));
dp[0][ofs] = 1;
rep(i, 1, 3 * n) {
rep(j, 0, 2 * ofs - 1) { dp[i & 3][j] = 0; }
rep(j, 0, 2 * ofs - 1) {
if (i - 1 >= 0 && j + 1 <= 2 * ofs - 1)
Add(dp[i & 3][j], dp[(i + 3) & 3][j + 1]);
if (i - 2 >= 0 && j - 1 >= 0)
Add(dp[i & 3][j], mod(dp[(i + 2) & 3][j - 1] * (3 * n - i + 1)));
if (i - 3 >= 0)
Add(dp[i & 3][j],
mod(dp[(i + 1) & 3][j] * mod((3 * n - i + 2) * (3 * n - i + 1))));
}
}
ll ans = 0;
rep(j, 0, ofs) Add(ans, dp[(3 * n) & 3][j]);
cout << mod(ans) << endl;
return 0;
}
| replace | 71 | 72 | 71 | 72 | TLE | |
p02738 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 5005;
int n, m, f[N][N], M;
signed main() {
scanf("%lld%lld", &n, &M);
f[0][n + 1] = 1;
for (int i = 0; i <= 3 * n; i++)
for (int j = -n; j <= 3 * n; j++) {
(f[i + 1][j + 1 + (n + 1)] += f[i][j + (n + 1)]) %= M;
(f[i + 2][j - 1 + (n + 1)] += f[i][j + (n + 1)] * (i + 1)) %= M;
(f[i + 3][j + (n + 1)] += f[i][j + (n + 1)] * (i + 2) % M * (i + 1)) %= M;
}
int ans = 0;
for (int i = 0; i <= n; i++)
(ans += f[3 * n][3 * i + (n + 1)]) %= M;
printf("%lld\n", ans);
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 8005;
int n, m, f[N][N], M;
signed main() {
scanf("%lld%lld", &n, &M);
f[0][n + 1] = 1;
for (int i = 0; i <= 3 * n; i++)
for (int j = -n; j <= 3 * n; j++) {
(f[i + 1][j + 1 + (n + 1)] += f[i][j + (n + 1)]) %= M;
(f[i + 2][j - 1 + (n + 1)] += f[i][j + (n + 1)] * (i + 1)) %= M;
(f[i + 3][j + (n + 1)] += f[i][j + (n + 1)] * (i + 2) % M * (i + 1)) %= M;
}
int ans = 0;
for (int i = 0; i <= n; i++)
(ans += f[3 * n][3 * i + (n + 1)]) %= M;
printf("%lld\n", ans);
return 0;
}
| replace | 3 | 4 | 3 | 4 | -11 | |
p02738 | C++ | Runtime Error | #include <bits/stdc++.h>
#define cs const
using namespace std;
int Mod;
int add(int a, int b) { return a + b >= Mod ? a + b - Mod : a + b; }
int dec(int a, int b) { return a - b < 0 ? a - b + Mod : a - b; }
int mul(int a, int b) { return 1ll * a * b % Mod; }
void Add(int &a, int b) { a = add(a, b); }
void Dec(int &a, int b) { a = dec(a, b); }
void Mul(int &a, int b) { a = mul(a, b); }
cs int N = 2050;
int n, f[N][N * 12];
int main() {
#ifdef FSYolanda
freopen("1.in", "r", stdin);
#endif
scanf("%d%d", &n, &Mod);
n *= 3;
f[0][0 + n] = 1;
for (int i = 1, u = n; i <= u; i++) {
for (int j = -(i >> 1); j <= i; j++) {
Add(f[i][j + 1 + n], f[i - 1][j + n]);
if (i > 1)
Add(f[i][j - 1 + n], mul(f[i - 2][j + n], i - 1));
if (i > 2)
Add(f[i][j + n], mul(f[i - 3][j + n], (i - 1) * (i - 2)));
}
}
int as = 0;
for (int i = n; i <= n + n; i++)
Add(as, f[n][i]);
cout << as;
return 0;
} | #include <bits/stdc++.h>
#define cs const
using namespace std;
int Mod;
int add(int a, int b) { return a + b >= Mod ? a + b - Mod : a + b; }
int dec(int a, int b) { return a - b < 0 ? a - b + Mod : a - b; }
int mul(int a, int b) { return 1ll * a * b % Mod; }
void Add(int &a, int b) { a = add(a, b); }
void Dec(int &a, int b) { a = dec(a, b); }
void Mul(int &a, int b) { a = mul(a, b); }
cs int N = 6e3 + 50;
int n, f[N][N * 2];
int main() {
#ifdef FSYolanda
freopen("1.in", "r", stdin);
#endif
scanf("%d%d", &n, &Mod);
n *= 3;
f[0][0 + n] = 1;
for (int i = 1, u = n; i <= u; i++) {
for (int j = -(i >> 1); j <= i; j++) {
Add(f[i][j + 1 + n], f[i - 1][j + n]);
if (i > 1)
Add(f[i][j - 1 + n], mul(f[i - 2][j + n], i - 1));
if (i > 2)
Add(f[i][j + n], mul(f[i - 3][j + n], (i - 1) * (i - 2)));
}
}
int as = 0;
for (int i = n; i <= n + n; i++)
Add(as, f[n][i]);
cout << as;
return 0;
} | replace | 10 | 12 | 10 | 12 | -11 | |
p02738 | C++ | Runtime Error | #include <bits/stdc++.h>
const int N3 = 3005;
const int N4 = 4005;
int inv2;
int n, n3, n4, mod;
int f[N3][N4];
inline void add(int &x, int y) {
x += y;
x >= mod ? x -= mod : 0;
}
int main() {
scanf("%d%d", &n, &mod);
f[0][n] = 1;
n3 = n * 3;
n4 = n * 4;
inv2 = mod + 1 >> 1;
for (int i = 0; i < n3; ++i)
for (int j = 0; j <= n4; ++j)
if (f[i][j]) {
if (i + 1 <= n3 && j + 1 <= n4)
add(f[i + 1][j + 1], f[i][j]);
if (i + 2 <= n3 && j - 1 >= 0)
f[i + 2][j - 1] = (1ll * f[i][j] * (i + 1) + f[i + 2][j - 1]) % mod;
if (i + 3 <= n3)
f[i + 3][j] = (1ll * f[i][j] * (i + 1) * (i + 2) + f[i + 3][j]) % mod;
}
int ans = 0;
for (int j = n; j <= n4; ++j)
add(ans, f[n3][j]);
printf("%d\n", ans);
} | #include <bits/stdc++.h>
const int N3 = 6005;
const int N4 = 8005;
int inv2;
int n, n3, n4, mod;
int f[N3][N4];
inline void add(int &x, int y) {
x += y;
x >= mod ? x -= mod : 0;
}
int main() {
scanf("%d%d", &n, &mod);
f[0][n] = 1;
n3 = n * 3;
n4 = n * 4;
inv2 = mod + 1 >> 1;
for (int i = 0; i < n3; ++i)
for (int j = 0; j <= n4; ++j)
if (f[i][j]) {
if (i + 1 <= n3 && j + 1 <= n4)
add(f[i + 1][j + 1], f[i][j]);
if (i + 2 <= n3 && j - 1 >= 0)
f[i + 2][j - 1] = (1ll * f[i][j] * (i + 1) + f[i + 2][j - 1]) % mod;
if (i + 3 <= n3)
f[i + 3][j] = (1ll * f[i][j] * (i + 1) * (i + 2) + f[i + 3][j]) % mod;
}
int ans = 0;
for (int j = n; j <= n4; ++j)
add(ans, f[n3][j]);
printf("%d\n", ans);
} | replace | 2 | 4 | 2 | 4 | 0 | |
p02738 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#include <iostream>
#include <string.h>
using namespace std;
int modadd(int a, int b, int m) {
int da = m - a;
if (da <= b) {
return b - da;
} else {
return a + b;
}
}
int modmul(int n, int b, int m) {
int ans = 0;
for (int i = 0; i < n; i++) {
ans = modadd(ans, b, m);
}
return ans;
}
int main(void) {
int n, m;
cin >> n;
cin >> m;
int *f = (int *)malloc(sizeof(int) * (3 * n + 1) * (n + 1));
for (int i = 0; i <= 3 * n; i++) {
for (int j = 0; j <= n; j++) {
if (i <= 1) {
f[i * (n + 1) + j] = 1;
} else {
if (n - j > (3 * n) - i) {
f[i * (n + 1) + j] = 0;
} else {
int ans = f[(i - 1) * (n + 1) + j];
if (i - 3 >= 0 && j > 0)
ans = modadd(
ans,
modmul((i - 1),
modmul((i - 2), f[(i - 3) * (n + 1) + j - 1], m), m),
m);
if (i - 2 >= 0 && j > 0)
ans = modadd(ans, modmul((i - 1), f[(i - 2) * (n + 1) + j - 1], m),
m);
f[i * (n + 1) + j] = ans;
}
}
}
}
cout << f[3 * n * (n + 1) + n];
} | #include <bits/stdc++.h>
#include <iostream>
#include <string.h>
using namespace std;
int modadd(int a, int b, int m) {
int da = m - a;
if (da <= b) {
return b - da;
} else {
return a + b;
}
}
int modmul(int n, int b, int m) {
long long int tmp = (long long int)b;
tmp *= n;
return tmp % m;
int ans = 0;
for (int i = 0; i < n; i++) {
ans = modadd(ans, b, m);
}
return ans;
}
int main(void) {
int n, m;
cin >> n;
cin >> m;
int *f = (int *)malloc(sizeof(int) * (3 * n + 1) * (n + 1));
for (int i = 0; i <= 3 * n; i++) {
for (int j = 0; j <= n; j++) {
if (i <= 1) {
f[i * (n + 1) + j] = 1;
} else {
if (n - j > (3 * n) - i) {
f[i * (n + 1) + j] = 0;
} else {
int ans = f[(i - 1) * (n + 1) + j];
if (i - 3 >= 0 && j > 0)
ans = modadd(
ans,
modmul((i - 1),
modmul((i - 2), f[(i - 3) * (n + 1) + j - 1], m), m),
m);
if (i - 2 >= 0 && j > 0)
ans = modadd(ans, modmul((i - 1), f[(i - 2) * (n + 1) + j - 1], m),
m);
f[i * (n + 1) + j] = ans;
}
}
}
}
cout << f[3 * n * (n + 1) + n];
} | insert | 15 | 15 | 15 | 18 | TLE | |
p02738 | C++ | Runtime Error | #define _USE_MATH_DEFINES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
#define MOD 1000000007
#define rep(i, m, n) for (int(i) = (int)(m); i < (int)(n); i++)
#define REP(i, n) rep(i, 0, n)
#define FOR(i, c) \
for (decltype((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(), (hoge).end()
typedef pair<ll, ll> P;
const long long INF = 1LL << 60;
typedef vector<ll> Array;
typedef vector<Array> Matrix;
string operator*(const string &s, int k) {
if (k == 0)
return "";
string p = (s + s) * (k / 2);
if (k % 2 == 1)
p += s;
return p;
}
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;
}
struct Edge { // グラフ
ll to, cap, rev;
Edge(ll _to, ll _cap, ll _rev) {
to = _to;
cap = _cap;
rev = _rev;
}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
void add_edge(Graph &G, ll from, ll to, ll cap, bool revFlag,
ll revCap) { // 最大フロー求める Ford-fulkerson
G[from].push_back(Edge(to, cap, (ll)G[to].size()));
if (revFlag)
G[to].push_back(Edge(
from, revCap, (ll)G[from].size() - 1)); // 最小カットの場合逆辺は0にする
}
ll max_flow_dfs(Graph &G, ll v, ll t, ll f, vector<bool> &used) {
if (v == t)
return f;
used[v] = true;
for (int i = 0; i < G[v].size(); ++i) {
Edge &e = G[v][i];
if (!used[e.to] && e.cap > 0) {
ll d = max_flow_dfs(G, e.to, t, min(f, e.cap), used);
if (d > 0) {
e.cap -= d;
G[e.to][e.rev].cap += d;
return d;
}
}
}
return 0;
}
// 二分グラフの最大マッチングを求めたりも出来る また二部グラフの最大独立集合は頂点数-最大マッチングのサイズ
ll max_flow(Graph &G, ll s, ll t) // O(V(V+E))
{
ll flow = 0;
for (;;) {
vector<bool> used(G.size());
REP(i, used.size()) used[i] = false;
ll f = max_flow_dfs(G, s, t, INF, used);
if (f == 0) {
return flow;
}
flow += f;
}
}
void BellmanFord(Graph &G, ll s, Array &d, Array &negative) { // O(|E||V|)
d.resize(G.size());
negative.resize(G.size());
REP(i, d.size()) d[i] = INF;
REP(i, d.size()) negative[i] = false;
d[s] = 0;
REP(k, G.size() - 1) {
REP(i, G.size()) {
REP(j, G[i].size()) {
if (d[i] != INF && d[G[i][j].to] > d[i] + G[i][j].cap) {
d[G[i][j].to] = d[i] + G[i][j].cap;
}
}
}
}
REP(k, G.size() - 1) {
REP(i, G.size()) {
REP(j, G[i].size()) {
if (d[i] != INF && d[G[i][j].to] > d[i] + G[i][j].cap) {
d[G[i][j].to] = d[i] + G[i][j].cap;
negative[G[i][j].to] = true;
}
if (negative[i] == true)
negative[G[i][j].to] = true;
}
}
}
}
void Dijkstra(Graph &G, ll s, Array &d) { // O(|E|log|V|)
d.resize(G.size());
REP(i, d.size()) d[i] = INF;
d[s] = 0;
priority_queue<P, vector<P>, greater<P>> q;
q.push(make_pair(0, s));
while (!q.empty()) {
P a = q.top();
q.pop();
if (d[a.second] < a.first)
continue;
REP(i, G[a.second].size()) {
Edge e = G[a.second][i];
if (d[e.to] > d[a.second] + e.cap) {
d[e.to] = d[a.second] + e.cap;
q.push(make_pair(d[e.to], e.to));
}
}
}
}
void WarshallFloyd(Graph &G, Matrix &d) { // O(V^3)
d.resize(G.size());
REP(i, d.size()) d[i].resize(G.size());
REP(i, d.size()) {
REP(j, d[i].size()) { d[i][j] = INF; }
}
REP(i, G.size()) {
REP(j, G[i].size()) { d[i][G[i][j].to] = G[i][j].cap; }
}
REP(i, G.size()) {
REP(j, G.size()) {
REP(k, G.size()) { chmin(d[j][k], d[j][i] + d[i][k]); }
}
}
}
bool tsort(Graph &graph, vector<int> &order) { // トポロジカルソートO(E+V)
int n = graph.size(), k = 0;
Array in(n);
for (auto &es : graph)
for (auto &e : es)
in[e.to]++;
priority_queue<ll, Array, greater<ll>> que;
REP(i, n)
if (in[i] == 0)
que.push(i);
while (que.size()) {
int v = que.top();
que.pop();
order.push_back(v);
for (auto &e : graph[v])
if (--in[e.to] == 0)
que.push(e.to);
}
if (order.size() != n)
return false;
else
return true;
}
class lca {
public:
const int n = 0;
const int log2_n = 0;
std::vector<std::vector<int>> parent;
std::vector<int> depth;
lca() {}
lca(const Graph &g, int root)
: n(g.size()), log2_n(log2(n) + 1), parent(log2_n, std::vector<int>(n)),
depth(n) {
dfs(g, root, -1, 0);
for (int k = 0; k + 1 < log2_n; k++) {
for (int v = 0; v < (int)g.size(); v++) {
if (parent[k][v] < 0)
parent[k + 1][v] = -1;
else
parent[k + 1][v] = parent[k][parent[k][v]];
}
}
}
void dfs(const Graph &g, int v, int p, int d) {
parent[0][v] = p;
depth[v] = d;
for (auto &e : g[v]) {
if (e.to != p)
dfs(g, e.to, v, d + 1);
}
}
int get(int u, int v) {
if (depth[u] > depth[v])
std::swap(u, v);
for (int k = 0; k < log2_n; k++) {
if ((depth[v] - depth[u]) >> k & 1) {
v = parent[k][v];
}
}
if (u == v)
return u;
for (int k = log2_n - 1; k >= 0; k--) {
if (parent[k][u] != parent[k][v]) {
u = parent[k][u];
v = parent[k][v];
}
}
return parent[0][u];
}
};
void visit(const Graph &g, int v, Matrix &scc, stack<ll> &S, Array &inS,
Array &low, Array &num, int &time) {
low[v] = num[v] = ++time;
S.push(v);
inS[v] = true;
FOR(e, g[v]) {
int w = e->to;
if (num[w] == 0) {
visit(g, w, scc, S, inS, low, num, time);
low[v] = min(low[v], low[w]);
} else if (inS[w])
low[v] = min(low[v], num[w]);
}
if (low[v] == num[v]) {
scc.push_back(Array());
while (1) {
int w = S.top();
S.pop();
inS[w] = false;
scc.back().push_back(w);
if (v == w)
break;
}
}
}
void stronglyConnectedComponents(const Graph &g,
Matrix &scc) { // 強連結成分分解 O(E+V)
const int n = g.size();
Array num(n), low(n);
stack<ll> S;
Array inS(n);
int time = 0;
REP(u, n) if (num[u] == 0) visit(g, u, scc, S, inS, low, num, time);
}
class UnionFind {
vector<int> data;
ll num;
public:
UnionFind(int size) : data(size, -1), num(size) {}
bool unite(int x, int y) { // xとyの集合を統合する
x = root(x);
y = root(y);
if (x != y) {
if (data[y] < data[x])
swap(x, y);
data[x] += data[y];
data[y] = x;
}
num -= (x != y);
return x != y;
}
bool findSet(int x, int y) { // xとyが同じ集合か返す
return root(x) == root(y);
}
int root(int x) { // xのルートを返す
return data[x] < 0 ? x : data[x] = root(data[x]);
}
int size(int x) { // xの集合のサイズを返す
return -data[root(x)];
}
int numSet() { // 集合の数を返す
return num;
}
};
class SumSegTree {
private:
ll _sum(ll a, ll b, ll k, ll l, ll r) {
if (r <= a || b <= l)
return 0; // 交差しない
if (a <= l && r <= b)
return dat[k]; // a,l,r,bの順で完全に含まれる
else {
ll s1 = _sum(a, b, 2 * k + 1, l, (l + r) / 2); // 左の子
ll s2 = _sum(a, b, 2 * k + 2, (l + r) / 2, r); // 右の子
return s1 + s2;
}
}
public:
ll n, height;
vector<ll> dat;
// 初期化(_nは最大要素数)
SumSegTree(ll _n) {
n = 1;
height = 1;
while (n < _n) {
n *= 2;
height++;
}
dat = vector<ll>(2 * n - 1, 0);
}
// 場所i(0-indexed)にxを加算
void add(ll i, ll x) {
i += n - 1; // i番目の葉ノードへ
dat[i] += x;
while (i > 0) { // 下から上がっていく
i = (i - 1) / 2;
dat[i] += x;
}
}
// 区間[a,b)の総和。ノードk=[l,r)に着目している。
ll sum(ll a, ll b) { return _sum(a, b, 0, 0, n); }
};
class RmqTree {
private:
ll _find(ll a, ll b, ll k, ll l, ll r) {
if (r <= a || b <= l)
return INF; // 交差しない
if (a <= l && r <= b)
return dat[k]; // a,l,r,bの順で完全に含まれる
else {
ll s1 = _find(a, b, 2 * k + 1, l, (l + r) / 2); // 左の子
ll s2 = _find(a, b, 2 * k + 2, (l + r) / 2, r); // 右の子
return min(s1, s2);
}
}
public:
ll n, height;
vector<ll> dat;
// 初期化(_nは最大要素数)
RmqTree(ll _n) {
n = 1;
height = 1;
while (n < _n) {
n *= 2;
height++;
}
dat = vector<ll>(2 * n - 1, INF);
}
// 場所i(0-indexed)をxにする
void update(ll i, ll x) {
i += n - 1; // i番目の葉ノードへ
dat[i] = x;
while (i > 0) { // 下から上がっていく
i = (i - 1) / 2;
dat[i] = min(dat[i * 2 + 1], dat[i * 2 + 2]);
}
}
// 区間[a,b)の最小値。ノードk=[l,r)に着目している。
ll find(ll a, ll b) { return _find(a, b, 0, 0, n); }
};
// 約数求める //約数
void divisor(ll n, vector<ll> &ret) {
for (ll i = 1; i * i <= n; i++) {
if (n % i == 0) {
ret.push_back(i);
if (i * i != n)
ret.push_back(n / i);
}
}
sort(ret.begin(), ret.end());
}
vector<ll> lis_fast(const vector<ll> &a) { // 最長部分増加列
const ll n = a.size();
vector<ll> A(n, INT_MAX);
vector<ll> id(n);
for (int i = 0; i < n; ++i) {
id[i] = distance(A.begin(), lower_bound(A.begin(), A.end(), a[i]));
A[id[i]] = a[i];
}
ll m = *max_element(id.begin(), id.end());
vector<ll> b(m + 1);
for (int i = n - 1; i >= 0; --i)
if (id[i] == m)
b[m--] = a[i];
return b;
}
bool z_algorithm(string &str, vector<int> &z,
ll s) { // s&tを渡してtにsが含まれるかを返す
const int L = str.size();
z.resize(str.size());
for (int i = 1, left = 0, right = 0; i < L; i++) {
if (i > right) {
left = right = i;
for (; right < L && str[right - left] == str[right]; right++)
;
z[i] = right - left;
right--;
} else {
int k = i - left;
if (z[k] < right - i + 1) {
z[i] = z[k];
} else {
left = i;
for (; right < L && str[right - left] == str[right]; right++)
;
z[i] = right - left;
right--;
}
}
if (z[i] == s)
return true;
}
return false;
}
bool z_algorithm(string &str,
vector<int> &z) { // z[i]==|s|のときstr[i]からsが含まれる
const int L = str.size();
z.resize(str.size());
for (int i = 1, left = 0, right = 0; i < L; i++) {
if (i > right) {
left = right = i;
for (; right < L && str[right - left] == str[right]; right++)
;
z[i] = right - left;
right--;
} else {
int k = i - left;
if (z[k] < right - i + 1) {
z[i] = z[k];
} else {
left = i;
for (; right < L && str[right - left] == str[right]; right++)
;
z[i] = right - left;
right--;
}
}
}
return true;
}
// ローリングハッシュ
// 二分探索で LCP を求める機能つき
struct RollingHash {
static const int base1 = 1007, base2 = 2009;
static const int mod1 = 1000000007, mod2 = 1000000009;
vector<long long> hash1, hash2, power1, power2;
// construct
RollingHash(const string &S) {
int n = (int)S.size();
hash1.assign(n + 1, 0);
hash2.assign(n + 1, 0);
power1.assign(n + 1, 1);
power2.assign(n + 1, 1);
for (int i = 0; i < n; ++i) {
hash1[i + 1] = (hash1[i] * base1 + S[i]) % mod1;
hash2[i + 1] = (hash2[i] * base2 + S[i]) % mod2;
power1[i + 1] = (power1[i] * base1) % mod1;
power2[i + 1] = (power2[i] * base2) % mod2;
}
}
// get hash of S[left:right]
inline pair<long long, long long> get(int l, int r) const {
long long res1 = hash1[r] - hash1[l] * power1[r - l] % mod1;
if (res1 < 0)
res1 += mod1;
long long res2 = hash2[r] - hash2[l] * power2[r - l] % mod2;
if (res2 < 0)
res2 += mod2;
return {res1, res2};
}
// get lcp of S[a:] and T[b:]
inline int getLCP(int a, int b) const {
int len = min((int)hash1.size() - a, (int)hash1.size() - b);
int low = 0, high = len;
while (high - low > 1) {
int mid = (low + high) >> 1;
if (get(a, a + mid) != get(b, b + mid))
high = mid;
else
low = mid;
}
return low;
}
};
ll mod_pow(ll x, ll n, ll mod) {
ll res = 1LL;
while (n > 0) {
if (n & 1)
res = res * x % mod;
x = x * x % mod;
n >>= 1;
}
return res;
}
ll mod_inv(ll x, ll mod) { return mod_pow(x, mod - 2, mod); }
// nCrとか
class Combination {
public:
Array fact;
Array inv;
ll mod;
ll mod_inv(ll x) {
ll n = mod - 2LL;
ll res = 1LL;
while (n > 0) {
if (n & 1)
res = res * x % mod;
x = x * x % mod;
n >>= 1;
}
return res;
}
ll nCr(ll n, ll r) { return ((fact[n] * inv[r] % mod) * inv[n - r]) % mod; }
ll nPr(ll n, ll r) { return (fact[n] * inv[n - r]) % mod; }
ll nHr(ll n, ll r) { return nCr(r + n - 1, r); }
Combination(ll n, ll _mod) {
mod = _mod;
fact.resize(n + 1);
fact[0] = 1;
REP(i, n) { fact[i + 1] = (fact[i] * (i + 1LL)) % mod; }
inv.resize(n + 1);
inv[n] = mod_inv(fact[n]);
for (int i = n; i > 0; i--) {
inv[i - 1] = inv[i] * i % mod;
}
}
};
ll gcd(ll m, ll n) {
if (n == 0)
return m;
return gcd(n, m % n);
} // gcd
ll lcm(ll m, ll n) { return m / gcd(m, n) * n; }
Matrix mIdentity(ll n) {
Matrix A(n, Array(n));
for (int i = 0; i < n; ++i)
A[i][i] = 1;
return A;
}
Matrix mMul(const Matrix &A, const Matrix &B) {
Matrix C(A.size(), Array(B[0].size()));
for (int i = 0; i < C.size(); ++i)
for (int j = 0; j < C[i].size(); ++j)
for (int k = 0; k < A[i].size(); ++k)
(C[i][j] += (A[i][k] % MOD) * (B[k][j] % MOD)) %= MOD;
return C;
}
// O( n^3 log e )
Matrix mPow(const Matrix &A, ll e) {
return e == 0 ? mIdentity(A.size())
: e % 2 == 0 ? mPow(mMul(A, A), e / 2)
: mMul(A, mPow(A, e - 1));
}
template <class T> class RectangleSum {
public:
vector<vector<T>> sum;
T GetSum(int left, int right, int top,
int bottom) { //[left, right], [top, bottom]
T res = sum[bottom][right];
if (left > 0)
res -= sum[bottom][left - 1];
if (top > 0)
res -= sum[top - 1][right];
if (left > 0 && top > 0)
res += sum[top - 1][left - 1];
return res;
}
RectangleSum(const vector<vector<T>> &s, int h, int w) {
sum.resize(h);
for (int i = 0; i < h; i++)
sum[i].resize(w, 0);
for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) {
sum[y][x] = s[y][x];
if (y > 0)
sum[y][x] += sum[y - 1][x];
if (x > 0)
sum[y][x] += sum[y][x - 1];
if (y > 0 && x > 0)
sum[y][x] -= sum[y - 1][x - 1];
}
}
}
};
// NTT
ll _garner(Array &xs, Array &mods) {
int M = xs.size();
Array coeffs(M, 1), constants(M, 0);
for (int i = 0; i < M - 1; ++i) {
ll mod_i = mods[i];
// coffs[i] * v + constants[i] == mr[i].val (mod mr[i].first) を解く
ll v = (xs[i] - constants[i] + mod_i) % mod_i;
v = (v * mod_pow(coeffs[i], mod_i - 2, mod_i)) % mod_i;
for (int j = i + 1; j < M; j++) {
ll mod_j = mods[j];
constants[j] = (constants[j] + coeffs[j] * v) % mod_j;
coeffs[j] = (coeffs[j] * mod_i) % mod_j;
}
}
return constants.back();
}
template <typename T> inline void bit_reverse(vector<T> &a) {
int n = a.size();
int i = 0;
for (int j = 1; j < n - 1; ++j) {
for (int k = n >> 1; k > (i ^= k); k >>= 1)
;
if (j < i)
swap(a[i], a[j]);
}
}
template <long long mod, long long primitive_root> class NTT {
public:
long long get_mod() { return mod; }
void _ntt(vector<long long> &a, int sign) {
const int n = a.size();
assert((n ^ (n & -n)) == 0); // n = 2^k
const long long g = primitive_root; // g is primitive root of mod
long long tmp = (mod - 1) * mod_pow(n, mod - 2, mod) % mod; // -1/n
long long h = mod_pow(g, tmp, mod); // ^n√g
if (sign == -1)
h = mod_pow(h, mod - 2, mod);
bit_reverse(a);
for (int m = 1; m < n; m <<= 1) {
const int m2 = 2 * m;
long long _base = mod_pow(h, n / m2, mod);
long long _w = 1;
for (int x = 0; x < m; ++x) {
for (int s = x; s < n; s += m2) {
long long u = a[s];
long long d = (a[s + m] * _w) % mod;
a[s] = (u + d) % mod;
a[s + m] = (u - d + mod) % mod;
}
_w = (_w * _base) % mod;
}
}
}
void ntt(vector<long long> &input) { _ntt(input, 1); }
void intt(vector<long long> &input) {
_ntt(input, -1);
const long long n_inv = mod_pow(input.size(), mod - 2, mod);
for (auto &x : input)
x = (x * n_inv) % mod;
}
// 畳み込み演算を行う
vector<long long> convolution(const vector<long long> &a,
const vector<long long> &b) {
int result_size = a.size() + b.size() - 1;
int n = 1;
while (n < result_size)
n <<= 1;
vector<long long> _a = a, _b = b;
_a.resize(n, 0);
_b.resize(n, 0);
ntt(_a);
ntt(_b);
for (int i = 0; i < n; ++i)
_a[i] = (_a[i] * _b[i]) % mod;
intt(_a);
_a.resize(result_size);
return _a;
}
};
vector<long long> convolution_ntt(vector<long long> &a, vector<long long> &b,
long long mod = 1224736769LL) {
for (auto &x : a)
x %= mod;
for (auto &x : b)
x %= mod;
ll maxval = max(a.size(), b.size()) * *max_element(a.begin(), a.end()) *
*max_element(b.begin(), b.end());
if (maxval < 1224736769) {
NTT<1224736769, 3> ntt3;
return ntt3.convolution(a, b);
}
NTT<167772161, 3> ntt1;
NTT<469762049, 3> ntt2;
NTT<1224736769, 3> ntt3;
vector<long long> x1 = ntt1.convolution(a, b);
vector<long long> x2 = ntt2.convolution(a, b);
vector<long long> x3 = ntt3.convolution(a, b);
vector<long long> ret(x1.size());
vector<long long> mods{167772161, 469762049, 1224736769, mod};
for (int i = 0; i < x1.size(); ++i) {
vector<long long> xs{x1[i], x2[i], x3[i], 0};
ret[i] = _garner(xs, mods);
}
return ret;
}
int popcount3(int x) {
x = (x & 0x55555555) + (x >> 1 & 0x55555555);
x = (x & 0x33333333) + (x >> 2 & 0x33333333);
x = (x & 0x0F0F0F0F) + (x >> 4 & 0x0F0F0F0F);
x = (x & 0x00FF00FF) + (x >> 8 & 0x00FF00FF);
x = (x & 0x0000FFFF) + (x >> 16 & 0x0000FFFF);
return x;
}
template <typename T>
void rowReduction(vector<T> mat, vector<T> &basis) { // 掃き出し法
for (auto e : mat) {
for (auto b : basis)
chmin(e, e ^ b);
if (e)
basis.push_back(e);
}
sort(all(basis), greater<T>());
}
struct SegT {
private:
int n;
vector<ll> node, lazy;
const ll init_c = 0;
public:
SegT(int sz) {
n = 1;
while (n < sz)
n <<= 1;
node.resize(2 * n - 1, 0);
lazy.resize(2 * n - 1, 0);
}
ll f(ll a, ll b) { return max(a, b); }
void eval(int k, int l, int r) {
node[k] += lazy[k];
if (r - l > 1) {
lazy[2 * k + 1] += lazy[k];
lazy[2 * k + 2] += lazy[k];
}
lazy[k] = 0;
}
void add(ll x, int a, int b, int k = 0, int l = 0, int r = -1) {
if (r < 0)
r = n;
eval(k, l, r);
if (r <= a || b <= l)
return;
if (a <= l && r <= b) {
lazy[k] += x;
eval(k, l, r);
} else {
add(x, a, b, k * 2 + 1, l, (l + r) / 2);
add(x, a, b, k * 2 + 2, (l + r) / 2, r);
node[k] = f(node[k * 2 + 1], node[k * 2 + 2]);
}
}
ll query(int a, int b, int k = 0, int l = 0, int r = -1) {
if (r < 0)
r = n;
eval(k, l, r);
if (r <= a || b <= l)
return init_c;
if (a <= l && r <= b)
return node[k];
else {
ll vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
ll vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
return f(vl, vr);
}
}
};
ll dp[2020][2020];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
ll n, m;
cin >> n >> m;
dp[0][0] = 1;
n *= 3;
REP(i, n) {
REP(j, n + 1) {
(dp[i + 1][j] += dp[i][j]) %= m;
(dp[i + 2][j + 1] += dp[i][j] * (n - i - 1) % m) %= m;
(dp[i + 3][j + 1] += dp[i][j] * (n - i - 1) * (n - i - 2) % m) %= m;
}
}
ll ans = 0;
REP(i, n / 3 + 1)(ans += dp[n][i]) %= m;
cout << ans << "\n";
return 0;
} | #define _USE_MATH_DEFINES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;
#define MOD 1000000007
#define rep(i, m, n) for (int(i) = (int)(m); i < (int)(n); i++)
#define REP(i, n) rep(i, 0, n)
#define FOR(i, c) \
for (decltype((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(), (hoge).end()
typedef pair<ll, ll> P;
const long long INF = 1LL << 60;
typedef vector<ll> Array;
typedef vector<Array> Matrix;
string operator*(const string &s, int k) {
if (k == 0)
return "";
string p = (s + s) * (k / 2);
if (k % 2 == 1)
p += s;
return p;
}
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;
}
struct Edge { // グラフ
ll to, cap, rev;
Edge(ll _to, ll _cap, ll _rev) {
to = _to;
cap = _cap;
rev = _rev;
}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
void add_edge(Graph &G, ll from, ll to, ll cap, bool revFlag,
ll revCap) { // 最大フロー求める Ford-fulkerson
G[from].push_back(Edge(to, cap, (ll)G[to].size()));
if (revFlag)
G[to].push_back(Edge(
from, revCap, (ll)G[from].size() - 1)); // 最小カットの場合逆辺は0にする
}
ll max_flow_dfs(Graph &G, ll v, ll t, ll f, vector<bool> &used) {
if (v == t)
return f;
used[v] = true;
for (int i = 0; i < G[v].size(); ++i) {
Edge &e = G[v][i];
if (!used[e.to] && e.cap > 0) {
ll d = max_flow_dfs(G, e.to, t, min(f, e.cap), used);
if (d > 0) {
e.cap -= d;
G[e.to][e.rev].cap += d;
return d;
}
}
}
return 0;
}
// 二分グラフの最大マッチングを求めたりも出来る また二部グラフの最大独立集合は頂点数-最大マッチングのサイズ
ll max_flow(Graph &G, ll s, ll t) // O(V(V+E))
{
ll flow = 0;
for (;;) {
vector<bool> used(G.size());
REP(i, used.size()) used[i] = false;
ll f = max_flow_dfs(G, s, t, INF, used);
if (f == 0) {
return flow;
}
flow += f;
}
}
void BellmanFord(Graph &G, ll s, Array &d, Array &negative) { // O(|E||V|)
d.resize(G.size());
negative.resize(G.size());
REP(i, d.size()) d[i] = INF;
REP(i, d.size()) negative[i] = false;
d[s] = 0;
REP(k, G.size() - 1) {
REP(i, G.size()) {
REP(j, G[i].size()) {
if (d[i] != INF && d[G[i][j].to] > d[i] + G[i][j].cap) {
d[G[i][j].to] = d[i] + G[i][j].cap;
}
}
}
}
REP(k, G.size() - 1) {
REP(i, G.size()) {
REP(j, G[i].size()) {
if (d[i] != INF && d[G[i][j].to] > d[i] + G[i][j].cap) {
d[G[i][j].to] = d[i] + G[i][j].cap;
negative[G[i][j].to] = true;
}
if (negative[i] == true)
negative[G[i][j].to] = true;
}
}
}
}
void Dijkstra(Graph &G, ll s, Array &d) { // O(|E|log|V|)
d.resize(G.size());
REP(i, d.size()) d[i] = INF;
d[s] = 0;
priority_queue<P, vector<P>, greater<P>> q;
q.push(make_pair(0, s));
while (!q.empty()) {
P a = q.top();
q.pop();
if (d[a.second] < a.first)
continue;
REP(i, G[a.second].size()) {
Edge e = G[a.second][i];
if (d[e.to] > d[a.second] + e.cap) {
d[e.to] = d[a.second] + e.cap;
q.push(make_pair(d[e.to], e.to));
}
}
}
}
void WarshallFloyd(Graph &G, Matrix &d) { // O(V^3)
d.resize(G.size());
REP(i, d.size()) d[i].resize(G.size());
REP(i, d.size()) {
REP(j, d[i].size()) { d[i][j] = INF; }
}
REP(i, G.size()) {
REP(j, G[i].size()) { d[i][G[i][j].to] = G[i][j].cap; }
}
REP(i, G.size()) {
REP(j, G.size()) {
REP(k, G.size()) { chmin(d[j][k], d[j][i] + d[i][k]); }
}
}
}
bool tsort(Graph &graph, vector<int> &order) { // トポロジカルソートO(E+V)
int n = graph.size(), k = 0;
Array in(n);
for (auto &es : graph)
for (auto &e : es)
in[e.to]++;
priority_queue<ll, Array, greater<ll>> que;
REP(i, n)
if (in[i] == 0)
que.push(i);
while (que.size()) {
int v = que.top();
que.pop();
order.push_back(v);
for (auto &e : graph[v])
if (--in[e.to] == 0)
que.push(e.to);
}
if (order.size() != n)
return false;
else
return true;
}
class lca {
public:
const int n = 0;
const int log2_n = 0;
std::vector<std::vector<int>> parent;
std::vector<int> depth;
lca() {}
lca(const Graph &g, int root)
: n(g.size()), log2_n(log2(n) + 1), parent(log2_n, std::vector<int>(n)),
depth(n) {
dfs(g, root, -1, 0);
for (int k = 0; k + 1 < log2_n; k++) {
for (int v = 0; v < (int)g.size(); v++) {
if (parent[k][v] < 0)
parent[k + 1][v] = -1;
else
parent[k + 1][v] = parent[k][parent[k][v]];
}
}
}
void dfs(const Graph &g, int v, int p, int d) {
parent[0][v] = p;
depth[v] = d;
for (auto &e : g[v]) {
if (e.to != p)
dfs(g, e.to, v, d + 1);
}
}
int get(int u, int v) {
if (depth[u] > depth[v])
std::swap(u, v);
for (int k = 0; k < log2_n; k++) {
if ((depth[v] - depth[u]) >> k & 1) {
v = parent[k][v];
}
}
if (u == v)
return u;
for (int k = log2_n - 1; k >= 0; k--) {
if (parent[k][u] != parent[k][v]) {
u = parent[k][u];
v = parent[k][v];
}
}
return parent[0][u];
}
};
void visit(const Graph &g, int v, Matrix &scc, stack<ll> &S, Array &inS,
Array &low, Array &num, int &time) {
low[v] = num[v] = ++time;
S.push(v);
inS[v] = true;
FOR(e, g[v]) {
int w = e->to;
if (num[w] == 0) {
visit(g, w, scc, S, inS, low, num, time);
low[v] = min(low[v], low[w]);
} else if (inS[w])
low[v] = min(low[v], num[w]);
}
if (low[v] == num[v]) {
scc.push_back(Array());
while (1) {
int w = S.top();
S.pop();
inS[w] = false;
scc.back().push_back(w);
if (v == w)
break;
}
}
}
void stronglyConnectedComponents(const Graph &g,
Matrix &scc) { // 強連結成分分解 O(E+V)
const int n = g.size();
Array num(n), low(n);
stack<ll> S;
Array inS(n);
int time = 0;
REP(u, n) if (num[u] == 0) visit(g, u, scc, S, inS, low, num, time);
}
class UnionFind {
vector<int> data;
ll num;
public:
UnionFind(int size) : data(size, -1), num(size) {}
bool unite(int x, int y) { // xとyの集合を統合する
x = root(x);
y = root(y);
if (x != y) {
if (data[y] < data[x])
swap(x, y);
data[x] += data[y];
data[y] = x;
}
num -= (x != y);
return x != y;
}
bool findSet(int x, int y) { // xとyが同じ集合か返す
return root(x) == root(y);
}
int root(int x) { // xのルートを返す
return data[x] < 0 ? x : data[x] = root(data[x]);
}
int size(int x) { // xの集合のサイズを返す
return -data[root(x)];
}
int numSet() { // 集合の数を返す
return num;
}
};
class SumSegTree {
private:
ll _sum(ll a, ll b, ll k, ll l, ll r) {
if (r <= a || b <= l)
return 0; // 交差しない
if (a <= l && r <= b)
return dat[k]; // a,l,r,bの順で完全に含まれる
else {
ll s1 = _sum(a, b, 2 * k + 1, l, (l + r) / 2); // 左の子
ll s2 = _sum(a, b, 2 * k + 2, (l + r) / 2, r); // 右の子
return s1 + s2;
}
}
public:
ll n, height;
vector<ll> dat;
// 初期化(_nは最大要素数)
SumSegTree(ll _n) {
n = 1;
height = 1;
while (n < _n) {
n *= 2;
height++;
}
dat = vector<ll>(2 * n - 1, 0);
}
// 場所i(0-indexed)にxを加算
void add(ll i, ll x) {
i += n - 1; // i番目の葉ノードへ
dat[i] += x;
while (i > 0) { // 下から上がっていく
i = (i - 1) / 2;
dat[i] += x;
}
}
// 区間[a,b)の総和。ノードk=[l,r)に着目している。
ll sum(ll a, ll b) { return _sum(a, b, 0, 0, n); }
};
class RmqTree {
private:
ll _find(ll a, ll b, ll k, ll l, ll r) {
if (r <= a || b <= l)
return INF; // 交差しない
if (a <= l && r <= b)
return dat[k]; // a,l,r,bの順で完全に含まれる
else {
ll s1 = _find(a, b, 2 * k + 1, l, (l + r) / 2); // 左の子
ll s2 = _find(a, b, 2 * k + 2, (l + r) / 2, r); // 右の子
return min(s1, s2);
}
}
public:
ll n, height;
vector<ll> dat;
// 初期化(_nは最大要素数)
RmqTree(ll _n) {
n = 1;
height = 1;
while (n < _n) {
n *= 2;
height++;
}
dat = vector<ll>(2 * n - 1, INF);
}
// 場所i(0-indexed)をxにする
void update(ll i, ll x) {
i += n - 1; // i番目の葉ノードへ
dat[i] = x;
while (i > 0) { // 下から上がっていく
i = (i - 1) / 2;
dat[i] = min(dat[i * 2 + 1], dat[i * 2 + 2]);
}
}
// 区間[a,b)の最小値。ノードk=[l,r)に着目している。
ll find(ll a, ll b) { return _find(a, b, 0, 0, n); }
};
// 約数求める //約数
void divisor(ll n, vector<ll> &ret) {
for (ll i = 1; i * i <= n; i++) {
if (n % i == 0) {
ret.push_back(i);
if (i * i != n)
ret.push_back(n / i);
}
}
sort(ret.begin(), ret.end());
}
vector<ll> lis_fast(const vector<ll> &a) { // 最長部分増加列
const ll n = a.size();
vector<ll> A(n, INT_MAX);
vector<ll> id(n);
for (int i = 0; i < n; ++i) {
id[i] = distance(A.begin(), lower_bound(A.begin(), A.end(), a[i]));
A[id[i]] = a[i];
}
ll m = *max_element(id.begin(), id.end());
vector<ll> b(m + 1);
for (int i = n - 1; i >= 0; --i)
if (id[i] == m)
b[m--] = a[i];
return b;
}
bool z_algorithm(string &str, vector<int> &z,
ll s) { // s&tを渡してtにsが含まれるかを返す
const int L = str.size();
z.resize(str.size());
for (int i = 1, left = 0, right = 0; i < L; i++) {
if (i > right) {
left = right = i;
for (; right < L && str[right - left] == str[right]; right++)
;
z[i] = right - left;
right--;
} else {
int k = i - left;
if (z[k] < right - i + 1) {
z[i] = z[k];
} else {
left = i;
for (; right < L && str[right - left] == str[right]; right++)
;
z[i] = right - left;
right--;
}
}
if (z[i] == s)
return true;
}
return false;
}
bool z_algorithm(string &str,
vector<int> &z) { // z[i]==|s|のときstr[i]からsが含まれる
const int L = str.size();
z.resize(str.size());
for (int i = 1, left = 0, right = 0; i < L; i++) {
if (i > right) {
left = right = i;
for (; right < L && str[right - left] == str[right]; right++)
;
z[i] = right - left;
right--;
} else {
int k = i - left;
if (z[k] < right - i + 1) {
z[i] = z[k];
} else {
left = i;
for (; right < L && str[right - left] == str[right]; right++)
;
z[i] = right - left;
right--;
}
}
}
return true;
}
// ローリングハッシュ
// 二分探索で LCP を求める機能つき
struct RollingHash {
static const int base1 = 1007, base2 = 2009;
static const int mod1 = 1000000007, mod2 = 1000000009;
vector<long long> hash1, hash2, power1, power2;
// construct
RollingHash(const string &S) {
int n = (int)S.size();
hash1.assign(n + 1, 0);
hash2.assign(n + 1, 0);
power1.assign(n + 1, 1);
power2.assign(n + 1, 1);
for (int i = 0; i < n; ++i) {
hash1[i + 1] = (hash1[i] * base1 + S[i]) % mod1;
hash2[i + 1] = (hash2[i] * base2 + S[i]) % mod2;
power1[i + 1] = (power1[i] * base1) % mod1;
power2[i + 1] = (power2[i] * base2) % mod2;
}
}
// get hash of S[left:right]
inline pair<long long, long long> get(int l, int r) const {
long long res1 = hash1[r] - hash1[l] * power1[r - l] % mod1;
if (res1 < 0)
res1 += mod1;
long long res2 = hash2[r] - hash2[l] * power2[r - l] % mod2;
if (res2 < 0)
res2 += mod2;
return {res1, res2};
}
// get lcp of S[a:] and T[b:]
inline int getLCP(int a, int b) const {
int len = min((int)hash1.size() - a, (int)hash1.size() - b);
int low = 0, high = len;
while (high - low > 1) {
int mid = (low + high) >> 1;
if (get(a, a + mid) != get(b, b + mid))
high = mid;
else
low = mid;
}
return low;
}
};
ll mod_pow(ll x, ll n, ll mod) {
ll res = 1LL;
while (n > 0) {
if (n & 1)
res = res * x % mod;
x = x * x % mod;
n >>= 1;
}
return res;
}
ll mod_inv(ll x, ll mod) { return mod_pow(x, mod - 2, mod); }
// nCrとか
class Combination {
public:
Array fact;
Array inv;
ll mod;
ll mod_inv(ll x) {
ll n = mod - 2LL;
ll res = 1LL;
while (n > 0) {
if (n & 1)
res = res * x % mod;
x = x * x % mod;
n >>= 1;
}
return res;
}
ll nCr(ll n, ll r) { return ((fact[n] * inv[r] % mod) * inv[n - r]) % mod; }
ll nPr(ll n, ll r) { return (fact[n] * inv[n - r]) % mod; }
ll nHr(ll n, ll r) { return nCr(r + n - 1, r); }
Combination(ll n, ll _mod) {
mod = _mod;
fact.resize(n + 1);
fact[0] = 1;
REP(i, n) { fact[i + 1] = (fact[i] * (i + 1LL)) % mod; }
inv.resize(n + 1);
inv[n] = mod_inv(fact[n]);
for (int i = n; i > 0; i--) {
inv[i - 1] = inv[i] * i % mod;
}
}
};
ll gcd(ll m, ll n) {
if (n == 0)
return m;
return gcd(n, m % n);
} // gcd
ll lcm(ll m, ll n) { return m / gcd(m, n) * n; }
Matrix mIdentity(ll n) {
Matrix A(n, Array(n));
for (int i = 0; i < n; ++i)
A[i][i] = 1;
return A;
}
Matrix mMul(const Matrix &A, const Matrix &B) {
Matrix C(A.size(), Array(B[0].size()));
for (int i = 0; i < C.size(); ++i)
for (int j = 0; j < C[i].size(); ++j)
for (int k = 0; k < A[i].size(); ++k)
(C[i][j] += (A[i][k] % MOD) * (B[k][j] % MOD)) %= MOD;
return C;
}
// O( n^3 log e )
Matrix mPow(const Matrix &A, ll e) {
return e == 0 ? mIdentity(A.size())
: e % 2 == 0 ? mPow(mMul(A, A), e / 2)
: mMul(A, mPow(A, e - 1));
}
template <class T> class RectangleSum {
public:
vector<vector<T>> sum;
T GetSum(int left, int right, int top,
int bottom) { //[left, right], [top, bottom]
T res = sum[bottom][right];
if (left > 0)
res -= sum[bottom][left - 1];
if (top > 0)
res -= sum[top - 1][right];
if (left > 0 && top > 0)
res += sum[top - 1][left - 1];
return res;
}
RectangleSum(const vector<vector<T>> &s, int h, int w) {
sum.resize(h);
for (int i = 0; i < h; i++)
sum[i].resize(w, 0);
for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) {
sum[y][x] = s[y][x];
if (y > 0)
sum[y][x] += sum[y - 1][x];
if (x > 0)
sum[y][x] += sum[y][x - 1];
if (y > 0 && x > 0)
sum[y][x] -= sum[y - 1][x - 1];
}
}
}
};
// NTT
ll _garner(Array &xs, Array &mods) {
int M = xs.size();
Array coeffs(M, 1), constants(M, 0);
for (int i = 0; i < M - 1; ++i) {
ll mod_i = mods[i];
// coffs[i] * v + constants[i] == mr[i].val (mod mr[i].first) を解く
ll v = (xs[i] - constants[i] + mod_i) % mod_i;
v = (v * mod_pow(coeffs[i], mod_i - 2, mod_i)) % mod_i;
for (int j = i + 1; j < M; j++) {
ll mod_j = mods[j];
constants[j] = (constants[j] + coeffs[j] * v) % mod_j;
coeffs[j] = (coeffs[j] * mod_i) % mod_j;
}
}
return constants.back();
}
template <typename T> inline void bit_reverse(vector<T> &a) {
int n = a.size();
int i = 0;
for (int j = 1; j < n - 1; ++j) {
for (int k = n >> 1; k > (i ^= k); k >>= 1)
;
if (j < i)
swap(a[i], a[j]);
}
}
template <long long mod, long long primitive_root> class NTT {
public:
long long get_mod() { return mod; }
void _ntt(vector<long long> &a, int sign) {
const int n = a.size();
assert((n ^ (n & -n)) == 0); // n = 2^k
const long long g = primitive_root; // g is primitive root of mod
long long tmp = (mod - 1) * mod_pow(n, mod - 2, mod) % mod; // -1/n
long long h = mod_pow(g, tmp, mod); // ^n√g
if (sign == -1)
h = mod_pow(h, mod - 2, mod);
bit_reverse(a);
for (int m = 1; m < n; m <<= 1) {
const int m2 = 2 * m;
long long _base = mod_pow(h, n / m2, mod);
long long _w = 1;
for (int x = 0; x < m; ++x) {
for (int s = x; s < n; s += m2) {
long long u = a[s];
long long d = (a[s + m] * _w) % mod;
a[s] = (u + d) % mod;
a[s + m] = (u - d + mod) % mod;
}
_w = (_w * _base) % mod;
}
}
}
void ntt(vector<long long> &input) { _ntt(input, 1); }
void intt(vector<long long> &input) {
_ntt(input, -1);
const long long n_inv = mod_pow(input.size(), mod - 2, mod);
for (auto &x : input)
x = (x * n_inv) % mod;
}
// 畳み込み演算を行う
vector<long long> convolution(const vector<long long> &a,
const vector<long long> &b) {
int result_size = a.size() + b.size() - 1;
int n = 1;
while (n < result_size)
n <<= 1;
vector<long long> _a = a, _b = b;
_a.resize(n, 0);
_b.resize(n, 0);
ntt(_a);
ntt(_b);
for (int i = 0; i < n; ++i)
_a[i] = (_a[i] * _b[i]) % mod;
intt(_a);
_a.resize(result_size);
return _a;
}
};
vector<long long> convolution_ntt(vector<long long> &a, vector<long long> &b,
long long mod = 1224736769LL) {
for (auto &x : a)
x %= mod;
for (auto &x : b)
x %= mod;
ll maxval = max(a.size(), b.size()) * *max_element(a.begin(), a.end()) *
*max_element(b.begin(), b.end());
if (maxval < 1224736769) {
NTT<1224736769, 3> ntt3;
return ntt3.convolution(a, b);
}
NTT<167772161, 3> ntt1;
NTT<469762049, 3> ntt2;
NTT<1224736769, 3> ntt3;
vector<long long> x1 = ntt1.convolution(a, b);
vector<long long> x2 = ntt2.convolution(a, b);
vector<long long> x3 = ntt3.convolution(a, b);
vector<long long> ret(x1.size());
vector<long long> mods{167772161, 469762049, 1224736769, mod};
for (int i = 0; i < x1.size(); ++i) {
vector<long long> xs{x1[i], x2[i], x3[i], 0};
ret[i] = _garner(xs, mods);
}
return ret;
}
int popcount3(int x) {
x = (x & 0x55555555) + (x >> 1 & 0x55555555);
x = (x & 0x33333333) + (x >> 2 & 0x33333333);
x = (x & 0x0F0F0F0F) + (x >> 4 & 0x0F0F0F0F);
x = (x & 0x00FF00FF) + (x >> 8 & 0x00FF00FF);
x = (x & 0x0000FFFF) + (x >> 16 & 0x0000FFFF);
return x;
}
template <typename T>
void rowReduction(vector<T> mat, vector<T> &basis) { // 掃き出し法
for (auto e : mat) {
for (auto b : basis)
chmin(e, e ^ b);
if (e)
basis.push_back(e);
}
sort(all(basis), greater<T>());
}
struct SegT {
private:
int n;
vector<ll> node, lazy;
const ll init_c = 0;
public:
SegT(int sz) {
n = 1;
while (n < sz)
n <<= 1;
node.resize(2 * n - 1, 0);
lazy.resize(2 * n - 1, 0);
}
ll f(ll a, ll b) { return max(a, b); }
void eval(int k, int l, int r) {
node[k] += lazy[k];
if (r - l > 1) {
lazy[2 * k + 1] += lazy[k];
lazy[2 * k + 2] += lazy[k];
}
lazy[k] = 0;
}
void add(ll x, int a, int b, int k = 0, int l = 0, int r = -1) {
if (r < 0)
r = n;
eval(k, l, r);
if (r <= a || b <= l)
return;
if (a <= l && r <= b) {
lazy[k] += x;
eval(k, l, r);
} else {
add(x, a, b, k * 2 + 1, l, (l + r) / 2);
add(x, a, b, k * 2 + 2, (l + r) / 2, r);
node[k] = f(node[k * 2 + 1], node[k * 2 + 2]);
}
}
ll query(int a, int b, int k = 0, int l = 0, int r = -1) {
if (r < 0)
r = n;
eval(k, l, r);
if (r <= a || b <= l)
return init_c;
if (a <= l && r <= b)
return node[k];
else {
ll vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
ll vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
return f(vl, vr);
}
}
};
ll dp[6060][6060];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
ll n, m;
cin >> n >> m;
dp[0][0] = 1;
n *= 3;
REP(i, n) {
REP(j, n + 1) {
(dp[i + 1][j] += dp[i][j]) %= m;
(dp[i + 2][j + 1] += dp[i][j] * (n - i - 1) % m) %= m;
(dp[i + 3][j + 1] += dp[i][j] * (n - i - 1) * (n - i - 2) % m) %= m;
}
}
ll ans = 0;
REP(i, n / 3 + 1)(ans += dp[n][i]) %= m;
cout << ans << "\n";
return 0;
} | replace | 832 | 833 | 832 | 833 | 0 | |
p02738 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <map>
#include <queue>
#include <vector>
using namespace std;
#define N 6005
#define INF 0x3f3f3f3f
#define LL long long
int n, MOD, f[4][N];
int rd() {
int x = 0, f = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-')
f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
x = (x << 3) + (x << 1) + (c ^ 48);
c = getchar();
}
return f * x;
}
int main() {
n = rd(), MOD = rd();
f[0][N] = 1;
for (int i = 1; i <= 3 * n; i++) {
int l = N - (i - 1), r = N + (i - 1);
for (int j = l; j <= r; j++) {
for (int k = 3; k >= 1; k--)
f[k][j] = f[k - 1][j];
f[0][j] = 0;
}
for (int j = l; j <= r; j++) {
f[0][j + 1] = (f[0][j + 1] + f[1][j]) % MOD;
int del = i - 1;
f[0][j - 1] = (f[0][j - 1] + 1ll * f[2][j] * del % MOD) % MOD;
del = 1ll * (i - 1) * (i - 2) % MOD;
f[0][j] = (f[0][j] + 1ll * f[3][j] * del % MOD) % MOD;
}
}
int ans = 0;
for (int i = N; i <= N + 3 * n; i++)
ans = (ans + f[0][i]) % MOD;
printf("%d\n", ans);
return 0;
} | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <map>
#include <queue>
#include <vector>
using namespace std;
#define N 6005
#define INF 0x3f3f3f3f
#define LL long long
int n, MOD, f[4][N * 2];
int rd() {
int x = 0, f = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-')
f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
x = (x << 3) + (x << 1) + (c ^ 48);
c = getchar();
}
return f * x;
}
int main() {
n = rd(), MOD = rd();
f[0][N] = 1;
for (int i = 1; i <= 3 * n; i++) {
int l = N - (i - 1), r = N + (i - 1);
for (int j = l; j <= r; j++) {
for (int k = 3; k >= 1; k--)
f[k][j] = f[k - 1][j];
f[0][j] = 0;
}
for (int j = l; j <= r; j++) {
f[0][j + 1] = (f[0][j + 1] + f[1][j]) % MOD;
int del = i - 1;
f[0][j - 1] = (f[0][j - 1] + 1ll * f[2][j] * del % MOD) % MOD;
del = 1ll * (i - 1) * (i - 2) % MOD;
f[0][j] = (f[0][j] + 1ll * f[3][j] * del % MOD) % MOD;
}
}
int ans = 0;
for (int i = N; i <= N + 3 * n; i++)
ans = (ans + f[0][i]) % MOD;
printf("%d\n", ans);
return 0;
} | replace | 12 | 13 | 12 | 13 | 0 | |
p02738 | C++ | Runtime Error | #pragma GCC optimize("O3")
#pragma GCC target("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double PI = acos(-1.0);
#define t1(x) cerr << #x << "=" << x << endl
#define t2(x, y) cerr << #x << "=" << x << " " << #y << "=" << y << endl
#define t3(x, y, z) \
cerr << #x << "=" << x << " " << #y << "=" << y << " " << #z << "=" << z \
<< endl
#define t4(a, b, c, d) \
cerr << #a << "=" << a << " " << #b << "=" << b << " " << #c << "=" << c \
<< " " << #d << "=" << d << endl
#define t5(a, b, c, d, e) \
cerr << #a << "=" << a << " " << #b << "=" << b << " " << #c << "=" << c \
<< " " << #d << "=" << d << " " << #e << "=" << e << endl
#define t6(a, b, c, d, e, f) \
cerr << #a << "=" << a << " " << #b << "=" << b << " " << #c << "=" << c \
<< " " << #d << "=" << d << " " << #e << "=" << e << " " << #f << "=" \
<< f << endl
#define GET_MACRO(_1, _2, _3, _4, _5, _6, NAME, ...) NAME
#define t(...) GET_MACRO(__VA_ARGS__, t6, t5, t4, t3, t2, t1)(__VA_ARGS__)
#define __ \
freopen("input.txt", "r", stdin); \
freopen("output.txt", "w", stdout);
#define fastio() \
ios::sync_with_stdio(0); \
cin.tie(0)
#define MEMS(x, t) memset(x, t, sizeof(x));
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
/*-------------------------------------------------------------------------------------------------------------------------------------*/
// #define MOD 1000000007
#define endl "\n"
#define int long long
#define inf 1e18
#define ld long double
/*-------------------------------------------------------------------------------------------------------------------------------------*/
int dp[2005][12005];
int n, MOD;
int rec(int ind, int balance) {
if (ind == 0) {
return (balance >= 0 && balance % 3 == 0);
}
int &ans = dp[ind][balance + 3 * n];
if (ans >= 0)
return ans;
ans = rec(ind - 1, balance + 1);
if (ind > 1)
ans += (ind - 1) * rec(ind - 2, balance - 1);
if (ind > 2)
ans += (ind - 1) * (ind - 2) * rec(ind - 3, balance);
ans %= MOD;
return ans;
}
int32_t main() {
fastio();
cin >> n >> MOD;
MEMS(dp, -1);
cout << rec(3 * n, 0) << endl;
}
| #pragma GCC optimize("O3")
#pragma GCC target("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double PI = acos(-1.0);
#define t1(x) cerr << #x << "=" << x << endl
#define t2(x, y) cerr << #x << "=" << x << " " << #y << "=" << y << endl
#define t3(x, y, z) \
cerr << #x << "=" << x << " " << #y << "=" << y << " " << #z << "=" << z \
<< endl
#define t4(a, b, c, d) \
cerr << #a << "=" << a << " " << #b << "=" << b << " " << #c << "=" << c \
<< " " << #d << "=" << d << endl
#define t5(a, b, c, d, e) \
cerr << #a << "=" << a << " " << #b << "=" << b << " " << #c << "=" << c \
<< " " << #d << "=" << d << " " << #e << "=" << e << endl
#define t6(a, b, c, d, e, f) \
cerr << #a << "=" << a << " " << #b << "=" << b << " " << #c << "=" << c \
<< " " << #d << "=" << d << " " << #e << "=" << e << " " << #f << "=" \
<< f << endl
#define GET_MACRO(_1, _2, _3, _4, _5, _6, NAME, ...) NAME
#define t(...) GET_MACRO(__VA_ARGS__, t6, t5, t4, t3, t2, t1)(__VA_ARGS__)
#define __ \
freopen("input.txt", "r", stdin); \
freopen("output.txt", "w", stdout);
#define fastio() \
ios::sync_with_stdio(0); \
cin.tie(0)
#define MEMS(x, t) memset(x, t, sizeof(x));
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
/*-------------------------------------------------------------------------------------------------------------------------------------*/
// #define MOD 1000000007
#define endl "\n"
#define int long long
#define inf 1e18
#define ld long double
/*-------------------------------------------------------------------------------------------------------------------------------------*/
int dp[6005][12005];
int n, MOD;
int rec(int ind, int balance) {
if (ind == 0) {
return (balance >= 0 && balance % 3 == 0);
}
int &ans = dp[ind][balance + 3 * n];
if (ans >= 0)
return ans;
ans = rec(ind - 1, balance + 1);
if (ind > 1)
ans += (ind - 1) * rec(ind - 2, balance - 1);
if (ind > 2)
ans += (ind - 1) * (ind - 2) * rec(ind - 3, balance);
ans %= MOD;
return ans;
}
int32_t main() {
fastio();
cin >> n >> MOD;
MEMS(dp, -1);
cout << rec(3 * n, 0) << endl;
}
| replace | 40 | 41 | 40 | 41 | -11 | |
p02738 | C++ | Runtime Error | #include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
#define cmin(a, b) (a > b ? a = b : a)
#define cmax(a, b) (a < b ? a = b : a)
#define mem(a, k) memset(a, k, sizeof(a))
#define lop(i, s, t) for (int i = s; i < (t); ++i)
#define rep(i, s, t) for (int i = s; i <= (t); ++i)
#define dec(i, s, t) for (int i = s; i >= (t); --i)
#define fore(i, v) \
for (int i = g[v], d = es[i].d; i; i = es[i].nxt, d = es[i].d)
using namespace std;
#ifdef CURIOUSCAT
#define Pr(f, ...) fprintf(stderr, f, ##__VA_ARGS__), fflush(stderr)
#else
#define Pr(f, ...)
#endif
typedef long long ll;
template <typename T> void read(T &x) {
x = 0;
char c;
for (c = getchar(); !isdigit(c); c = getchar())
;
for (; isdigit(c); c = getchar())
x = x * 10 + c - '0';
}
const int N = 1e6 + 50;
int P;
int mul(int a, int b) { return 1ll * a * b % P; }
int add(int a, int b) {
a += b;
return a >= P ? a - P : a;
}
void upd(int &a, int b) { a = a + b >= P ? a + b - P : a + b; }
int sub(int a, int b) {
a -= b;
return a < 0 ? a + P : a;
}
int gcd(int a, int b) { return !b ? a : gcd(b, a % b); }
int C(int n, int m) {
if (m < 0 || m > n)
return 0;
if (m == 0)
return 1;
if (m == 1)
return n;
if (m == 2)
return n & 1 ? mul(n, (n - 1) / 2) : mul(n / 2, n - 1);
}
int n, dp[2005][2005], ans;
int main(int argc, char *argv[]) {
#ifdef CURIOUSCAT
#endif
read(n);
read(P);
dp[0][0] = 1;
rep(i, 0, n * 3) rep(j, 0, n) {
upd(dp[i + 1][j], dp[i][j]);
upd(dp[i + 2][j + 1], mul(dp[i][j], C(i + 1, 1)));
upd(dp[i + 3][j + 1], mul(dp[i][j], mul(C(i + 2, 2), 2)));
}
rep(j, 0, n) ans = add(ans, dp[n * 3][j]);
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
#define cmin(a, b) (a > b ? a = b : a)
#define cmax(a, b) (a < b ? a = b : a)
#define mem(a, k) memset(a, k, sizeof(a))
#define lop(i, s, t) for (int i = s; i < (t); ++i)
#define rep(i, s, t) for (int i = s; i <= (t); ++i)
#define dec(i, s, t) for (int i = s; i >= (t); --i)
#define fore(i, v) \
for (int i = g[v], d = es[i].d; i; i = es[i].nxt, d = es[i].d)
using namespace std;
#ifdef CURIOUSCAT
#define Pr(f, ...) fprintf(stderr, f, ##__VA_ARGS__), fflush(stderr)
#else
#define Pr(f, ...)
#endif
typedef long long ll;
template <typename T> void read(T &x) {
x = 0;
char c;
for (c = getchar(); !isdigit(c); c = getchar())
;
for (; isdigit(c); c = getchar())
x = x * 10 + c - '0';
}
const int N = 1e6 + 50;
int P;
int mul(int a, int b) { return 1ll * a * b % P; }
int add(int a, int b) {
a += b;
return a >= P ? a - P : a;
}
void upd(int &a, int b) { a = a + b >= P ? a + b - P : a + b; }
int sub(int a, int b) {
a -= b;
return a < 0 ? a + P : a;
}
int gcd(int a, int b) { return !b ? a : gcd(b, a % b); }
int C(int n, int m) {
if (m < 0 || m > n)
return 0;
if (m == 0)
return 1;
if (m == 1)
return n;
if (m == 2)
return n & 1 ? mul(n, (n - 1) / 2) : mul(n / 2, n - 1);
}
int n, dp[6005][2005], ans;
int main(int argc, char *argv[]) {
#ifdef CURIOUSCAT
#endif
read(n);
read(P);
dp[0][0] = 1;
rep(i, 0, n * 3) rep(j, 0, n) {
upd(dp[i + 1][j], dp[i][j]);
upd(dp[i + 2][j + 1], mul(dp[i][j], C(i + 1, 1)));
upd(dp[i + 3][j + 1], mul(dp[i][j], mul(C(i + 2, 2), 2)));
}
rep(j, 0, n) ans = add(ans, dp[n * 3][j]);
cout << ans << endl;
return 0;
}
| replace | 57 | 58 | 57 | 58 | 0 | |
p02738 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
const int maxn = 1003;
int n, m;
long long fast_pow(long long num, int deg) {
long long ans = 1, pow = num;
while (deg) {
if (deg & 1)
ans = ans * pow % m;
deg >>= 1;
pow = pow * pow % m;
}
return ans;
}
long long add(long long a, long long b) {
a += b;
if (a >= m)
a -= m;
return a;
}
void read() { cin >> n >> m; }
long long dp[maxn * 3][maxn * 6];
void solve() {
dp[0][3 * n + 1] = 1;
for (int i = 1; i <= 3 * n; i++) {
auto to_mult = fast_pow(i, m - 2);
for (int j = -3 * n; j <= 3 * n; j++) {
dp[i][j + 3 * n + 1] =
add(dp[i][j + 3 * n + 1], dp[i - 1][j - 1 + 3 * n + 1]);
if (i >= 2)
dp[i][j + 3 * n + 1] =
add(dp[i][j + 3 * n + 1], dp[i - 2][j + 1 + 3 * n + 1]);
if (i >= 3)
dp[i][j + 3 * n + 1] =
add(dp[i][j + 3 * n + 1], dp[i - 3][j + 3 * n + 1]);
dp[i][j + 3 * n + 1] = dp[i][j + 3 * n + 1] * to_mult % m;
}
}
long long ans = 0;
for (int j = 0; j <= 3 * n; j++)
ans = add(ans, dp[3 * n][j + 3 * n + 1]);
for (int i = 1; i <= 3 * n; i++)
ans = ans * i % m;
cout << ans << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
read();
solve();
}
| #include <bits/stdc++.h>
using namespace std;
const int maxn = 2003;
int n, m;
long long fast_pow(long long num, int deg) {
long long ans = 1, pow = num;
while (deg) {
if (deg & 1)
ans = ans * pow % m;
deg >>= 1;
pow = pow * pow % m;
}
return ans;
}
long long add(long long a, long long b) {
a += b;
if (a >= m)
a -= m;
return a;
}
void read() { cin >> n >> m; }
long long dp[maxn * 3][maxn * 6];
void solve() {
dp[0][3 * n + 1] = 1;
for (int i = 1; i <= 3 * n; i++) {
auto to_mult = fast_pow(i, m - 2);
for (int j = -3 * n; j <= 3 * n; j++) {
dp[i][j + 3 * n + 1] =
add(dp[i][j + 3 * n + 1], dp[i - 1][j - 1 + 3 * n + 1]);
if (i >= 2)
dp[i][j + 3 * n + 1] =
add(dp[i][j + 3 * n + 1], dp[i - 2][j + 1 + 3 * n + 1]);
if (i >= 3)
dp[i][j + 3 * n + 1] =
add(dp[i][j + 3 * n + 1], dp[i - 3][j + 3 * n + 1]);
dp[i][j + 3 * n + 1] = dp[i][j + 3 * n + 1] * to_mult % m;
}
}
long long ans = 0;
for (int j = 0; j <= 3 * n; j++)
ans = add(ans, dp[3 * n][j + 3 * n + 1]);
for (int i = 1; i <= 3 * n; i++)
ans = ans * i % m;
cout << ans << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
read();
solve();
}
| replace | 4 | 5 | 4 | 5 | -11 | |
p02738 | C++ | Runtime Error | #include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
#define N 2000001
using namespace std;
typedef long long ll;
typedef long double ld;
const ll INF = 1e18, MOD = 1e9 + 7, MOD2 = 1e6 + 3;
ll d[3001][6003], n, P, offset = 3000;
int main() {
cin >> n >> P;
d[0][offset] = 1;
d[1][offset + 1] = 1;
for (int i = 2; i <= 3 * n; i++)
for (int j = -i / 2; j <= i; j++) {
d[i][offset + j] += d[i - 1][offset + j - 1];
if (d[i][offset + j] >= P)
d[i][offset + j] -= P;
d[i][offset + j] += d[i - 2][offset + j + 1] * (i - 1) % P;
if (d[i][offset + j] >= P)
d[i][offset + j] -= P;
if (i > 2)
d[i][offset + j] += d[i - 3][offset + j] * (i - 1) * (i - 2) % P;
}
ll ans = 0;
for (int i = 0; i <= 3 * n; i++) {
ans += d[3 * n][offset + i];
if (ans >= P)
ans -= P;
}
cout << ans;
} | #include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
#define N 2000001
using namespace std;
typedef long long ll;
typedef long double ld;
const ll INF = 1e18, MOD = 1e9 + 7, MOD2 = 1e6 + 3;
ll d[10001][10003], n, P, offset = 3000;
int main() {
cin >> n >> P;
d[0][offset] = 1;
d[1][offset + 1] = 1;
for (int i = 2; i <= 3 * n; i++)
for (int j = -i / 2; j <= i; j++) {
d[i][offset + j] += d[i - 1][offset + j - 1];
if (d[i][offset + j] >= P)
d[i][offset + j] -= P;
d[i][offset + j] += d[i - 2][offset + j + 1] * (i - 1) % P;
if (d[i][offset + j] >= P)
d[i][offset + j] -= P;
if (i > 2)
d[i][offset + j] += d[i - 3][offset + j] * (i - 1) * (i - 2) % P;
}
ll ans = 0;
for (int i = 0; i <= 3 * n; i++) {
ans += d[3 * n][offset + i];
if (ans >= P)
ans -= P;
}
cout << ans;
} | replace | 14 | 15 | 14 | 15 | -11 | |
p02738 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
long long f[6005][6005 << 1], mod, ans;
int n;
int main() {
cin >> n >> mod;
f[0][3 * n] = 1;
for (int i = 1; i <= 3 * n; i++)
for (int j = -i / 2; j <= i; j++) {
f[i][j + 3 * n] += f[i - 1][j + 3 * n - 1];
f[i][j + 3 * n] += (i - 1) * f[i - 2][j + 1 + 3 * n];
f[i][j + 3 * n] += (i - 1) * (i - 2) * f[i - 3][j + 3 * n];
f[i][j + 3 * n] %= mod;
}
for (int i = 3 * n; i <= 6 * n; i++)
ans = (ans + f[3 * n][i]) % mod;
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
long long f[6005][6005 << 1], mod, ans;
int n;
int main() {
cin >> n >> mod;
f[0][3 * n] = 1;
for (int i = 1; i <= 3 * n; i++)
for (int j = -3 * n; j <= 3 * n; j++) {
if (i)
f[i][j + 3 * n] += f[i - 1][j + 3 * n - 1];
if (i > 1)
f[i][j + 3 * n] += (i - 1) * f[i - 2][j + 1 + 3 * n];
if (i > 2)
f[i][j + 3 * n] += (i - 1) * (i - 2) * f[i - 3][j + 3 * n];
f[i][j + 3 * n] %= mod;
}
for (int i = 3 * n; i <= 6 * n; i++)
ans = (ans + f[3 * n][i]) % mod;
cout << ans << endl;
} | replace | 10 | 14 | 10 | 17 | -11 | |
p02740 | C++ | Runtime Error | #include <bits/stdc++.h>
#define For(i, x, y) for (register int i = (x); i <= (y); i++)
#define FOR(i, x, y) for (register int i = (x); i < (y); i++)
#define Dow(i, x, y) for (register int i = (x); i >= (y); i--)
#define Debug(v) \
for (auto i : v) \
printf("%lld ", i); \
puts("")
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define ep emplace_back
#define siz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define fil(a, b) memset((a), (b), sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pa;
typedef pair<ll, ll> PA;
typedef vector<int> poly;
inline ll read() {
ll x = 0, f = 1;
char c = getchar();
while ((c < '0' || c > '9') && (c != '-'))
c = getchar();
if (c == '-')
f = -1, c = getchar();
while (c >= '0' && c <= '9')
x = x * 10 + c - '0', c = getchar();
return x * f;
}
const int N = 35, inf = 1e9;
int n, m, q, tot, cnt[N], id[N][N];
ll pre[N];
struct node {
ll s, p, c;
} a[N][N];
namespace MCMF {
const int N = 1010, M = 10010;
int tot = -1, first[N], to[M << 1], last[M << 1];
ll flow[M << 1], cost[M << 1];
inline void init() { fil(first, -1); }
inline void add(int x, int y, ll w, ll f) {
to[++tot] = y, flow[tot] = w, cost[tot] = f, last[tot] = first[x],
first[x] = tot;
}
inline void Add(int x, int y, ll w, ll f) { add(x, y, w, f), add(y, x, 0, -f); }
const ll inf = 1ll << 60;
ll dis[N], Flow[N];
int pre[N], pos[N];
bool vis[N];
inline bool spfa(int s, int t, int n) {
For(i, 1, n) vis[i] = 0, dis[i] = Flow[i] = inf;
queue<int> q;
q.push(s), dis[s] = 0;
while (!q.empty()) {
int u = q.front();
q.pop(), vis[u] = 0;
for (int i = first[u]; i != -1; i = last[i]) {
int v = to[i];
if (dis[u] + cost[i] < dis[v] && flow[i]) {
dis[v] = dis[u] + cost[i], Flow[v] = min(Flow[u], flow[i]), pre[v] = u,
pos[v] = i;
if (!vis[v])
q.push(v), vis[v] = 1;
}
}
}
return dis[t] != inf;
}
inline vector<ll> solve(int S, int T, int n) {
vector<ll> ans;
while (spfa(S, T, n)) {
if (Flow[T] > 100000000)
return ans.pb(dis[T]), ans;
For(i, 1, Flow[T]) ans.pb(dis[T]);
for (int i = T; i != S; i = pre[i])
flow[pos[i]] -= Flow[T], flow[pos[i] ^ 1] += Flow[T];
}
return ans;
}
}; // namespace MCMF
int main() {
n = read();
int S = 1, T = 2;
tot = 2, MCMF::init();
For(i, 1, n) {
cnt[i] = read(), id[i][0] = ++tot;
For(j, 1, cnt[i]) {
a[i][j] = (node){read(), read(), read()};
id[i][j] = ++tot;
}
MCMF::Add(S, id[i][0], inf, 0), MCMF::Add(id[i][cnt[i]], T, inf, 0);
sort(a[i] + 1, a[i] + 1 + cnt[i], [](node a, node b) { return a.s < b.s; });
For(j, 1, cnt[i]) {
MCMF::Add(id[i][j - 1], id[i][j], a[i][j].p, 0);
MCMF::Add(id[i][j - 1], id[i][j], 1e9, a[i][j].c);
}
}
m = read();
while (m--) {
int u = read(), v = read(), w = read(), l = 0;
For(i, 1, cnt[u]) {
while (l < cnt[v] && a[v][l + 1].s <= a[u][i].s + w)
++l;
if (l == cnt[v])
break;
MCMF::Add(id[v][l], id[u][i], 1e9, 0);
}
}
auto p = MCMF::solve(S, T, tot);
pre[0] = p[0];
FOR(i, 1, siz(p)) pre[i] = pre[i - 1] + p[i];
q = read();
while (q--) {
ll A = read();
int pos = lower_bound(all(p), A) - p.begin();
if (pos == siz(p))
puts("-1");
else
printf("%lld\n", A * pos - (pos == 0 ? 0 : pre[pos - 1]));
}
} | #include <bits/stdc++.h>
#define For(i, x, y) for (register int i = (x); i <= (y); i++)
#define FOR(i, x, y) for (register int i = (x); i < (y); i++)
#define Dow(i, x, y) for (register int i = (x); i >= (y); i--)
#define Debug(v) \
for (auto i : v) \
printf("%lld ", i); \
puts("")
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define ep emplace_back
#define siz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define fil(a, b) memset((a), (b), sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pa;
typedef pair<ll, ll> PA;
typedef vector<int> poly;
inline ll read() {
ll x = 0, f = 1;
char c = getchar();
while ((c < '0' || c > '9') && (c != '-'))
c = getchar();
if (c == '-')
f = -1, c = getchar();
while (c >= '0' && c <= '9')
x = x * 10 + c - '0', c = getchar();
return x * f;
}
const int N = 35, inf = 1e9;
int n, m, q, tot, cnt[N], id[N][N];
ll pre[100010];
struct node {
ll s, p, c;
} a[N][N];
namespace MCMF {
const int N = 1010, M = 10010;
int tot = -1, first[N], to[M << 1], last[M << 1];
ll flow[M << 1], cost[M << 1];
inline void init() { fil(first, -1); }
inline void add(int x, int y, ll w, ll f) {
to[++tot] = y, flow[tot] = w, cost[tot] = f, last[tot] = first[x],
first[x] = tot;
}
inline void Add(int x, int y, ll w, ll f) { add(x, y, w, f), add(y, x, 0, -f); }
const ll inf = 1ll << 60;
ll dis[N], Flow[N];
int pre[N], pos[N];
bool vis[N];
inline bool spfa(int s, int t, int n) {
For(i, 1, n) vis[i] = 0, dis[i] = Flow[i] = inf;
queue<int> q;
q.push(s), dis[s] = 0;
while (!q.empty()) {
int u = q.front();
q.pop(), vis[u] = 0;
for (int i = first[u]; i != -1; i = last[i]) {
int v = to[i];
if (dis[u] + cost[i] < dis[v] && flow[i]) {
dis[v] = dis[u] + cost[i], Flow[v] = min(Flow[u], flow[i]), pre[v] = u,
pos[v] = i;
if (!vis[v])
q.push(v), vis[v] = 1;
}
}
}
return dis[t] != inf;
}
inline vector<ll> solve(int S, int T, int n) {
vector<ll> ans;
while (spfa(S, T, n)) {
if (Flow[T] > 100000000)
return ans.pb(dis[T]), ans;
For(i, 1, Flow[T]) ans.pb(dis[T]);
for (int i = T; i != S; i = pre[i])
flow[pos[i]] -= Flow[T], flow[pos[i] ^ 1] += Flow[T];
}
return ans;
}
}; // namespace MCMF
int main() {
n = read();
int S = 1, T = 2;
tot = 2, MCMF::init();
For(i, 1, n) {
cnt[i] = read(), id[i][0] = ++tot;
For(j, 1, cnt[i]) {
a[i][j] = (node){read(), read(), read()};
id[i][j] = ++tot;
}
MCMF::Add(S, id[i][0], inf, 0), MCMF::Add(id[i][cnt[i]], T, inf, 0);
sort(a[i] + 1, a[i] + 1 + cnt[i], [](node a, node b) { return a.s < b.s; });
For(j, 1, cnt[i]) {
MCMF::Add(id[i][j - 1], id[i][j], a[i][j].p, 0);
MCMF::Add(id[i][j - 1], id[i][j], 1e9, a[i][j].c);
}
}
m = read();
while (m--) {
int u = read(), v = read(), w = read(), l = 0;
For(i, 1, cnt[u]) {
while (l < cnt[v] && a[v][l + 1].s <= a[u][i].s + w)
++l;
if (l == cnt[v])
break;
MCMF::Add(id[v][l], id[u][i], 1e9, 0);
}
}
auto p = MCMF::solve(S, T, tot);
pre[0] = p[0];
FOR(i, 1, siz(p)) pre[i] = pre[i - 1] + p[i];
q = read();
while (q--) {
ll A = read();
int pos = lower_bound(all(p), A) - p.begin();
if (pos == siz(p))
puts("-1");
else
printf("%lld\n", A * pos - (pos == 0 ? 0 : pre[pos - 1]));
}
} | replace | 36 | 37 | 36 | 37 | 0 | |
p02741 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> a = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int k;
cin >> k;
cout << a.at(k) << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> a = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int k;
cin >> k;
cout << a.at(k - 1) << endl;
return 0;
} | replace | 10 | 11 | 10 | 11 | 0 | |
p02741 | C++ | Runtime Error | #include <iostream>
#include <utility>
#include <vector>
using namespace std;
int main(void) {
int K;
vector<int> L = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
cin >> K;
cout << L.at(K) << endl;
return 0;
}
| #include <iostream>
#include <utility>
#include <vector>
using namespace std;
int main(void) {
int K;
vector<int> L = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
cin >> K;
cout << L.at(K - 1) << endl;
return 0;
} | replace | 10 | 11 | 10 | 11 | 0 | |
p02741 | C++ | Runtime Error | #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define coyes cout << "Yes" << endl;
#define cono cout << "No" << endl;
#define coYes cout << "YES" << endl;
#define coNo cout << "NO" << endl;
using namespace std;
using ll = long long int;
string large_al = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string small_al = "abcdefghijklmnopqrstuvwxyz";
using Graph = vector<vector<int>>;
using i64 = int64_t;
int main() {
int k;
cin >> k;
string s1 = "111212152215121#1515221#2254141";
if (1 <= k <= 15) {
cout << s1.at(k - 1) << endl;
} else if (k == 16) {
cout << 14 << endl;
} else if (17 <= k <= 23) {
cout << s1.at(k - 1) << endl;
} else if (k == 24) {
cout << 15 << endl;
} else if (25 <= k <= 31) {
cout << s1.at(k - 1) << endl;
} else {
cout << 51 << endl;
}
}
| #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define coyes cout << "Yes" << endl;
#define cono cout << "No" << endl;
#define coYes cout << "YES" << endl;
#define coNo cout << "NO" << endl;
using namespace std;
using ll = long long int;
string large_al = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string small_al = "abcdefghijklmnopqrstuvwxyz";
using Graph = vector<vector<int>>;
using i64 = int64_t;
int main() {
int k;
cin >> k;
vector<int> s = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
cout << s.at(k - 1) << endl;
}
| replace | 17 | 31 | 17 | 20 | 0 | |
p02741 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int K;
cin >> K;
string t = "1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, "
"2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51,";
int sum = 0;
for (int i = 0; i < t.size(); i++) {
if (t.at(i) == ',') {
sum += 1;
if (sum == K) {
if (t.at(i - 2) == ' ') {
cout << t.at(i - 1) << endl;
} else {
cout << t.at(i - 2) << t.at(i - 1) << endl;
}
}
}
}
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int K;
cin >> K;
string t = "1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, "
"2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51,";
int sum = 0;
for (int i = 0; i < t.size(); i++) {
if (t.at(i) == ',') {
sum += 1;
if (sum == K) {
if (K == 1) {
cout << 1 << endl;
break;
}
if (t.at(i - 2) == ' ') {
cout << t.at(i - 1) << endl;
} else {
cout << t.at(i - 2) << t.at(i - 1) << endl;
}
}
}
}
} | insert | 15 | 15 | 15 | 19 | 0 | |
p02741 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int K;
cin >> K;
vector<int> a = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
cout << a.at(K) << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int K;
cin >> K;
vector<int> a = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
cout << a.at(K - 1) << endl;
} | replace | 10 | 11 | 10 | 11 | 0 | |
p02741 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int K;
cin >> K;
vector<int> vec = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
cout << vec.at(K) << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int K;
cin >> K;
vector<int> vec = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
cout << vec.at(K - 1) << endl;
}
| replace | 8 | 9 | 8 | 9 | 0 | |
p02741 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> vec = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int a;
cin >> a;
cout << vec.at(a) << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> vec = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int a;
cin >> a;
cout << vec.at(a - 1) << endl;
return 0;
}
| replace | 8 | 9 | 8 | 9 | 0 | |
p02741 | C++ | Runtime Error | #define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <unordered_map>
#define stop(x) \
{ \
cout << x << endl; \
exit(0); \
}
#define all(x) x.begin(), x.end()
#define szz(s) int(s.size())
#define endl '\n'
int dx[] = {0, 0, 1, -1, 1, -1, 1, -1};
int dy[] = {1, -1, 0, 0, -1, 1, 1, -1};
typedef long long ll;
using namespace std;
void file() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifndef ONLINE_JUDGE
if (freopen("input.txt", "r", stdin))
;
if (freopen("output.txt", "w", stdout))
;
#endif
}
int main() {
file();
int ar[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int k;
cin >> k;
cout << ar[k - 1] << endl;
} | #define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <unordered_map>
#define stop(x) \
{ \
cout << x << endl; \
exit(0); \
}
#define all(x) x.begin(), x.end()
#define szz(s) int(s.size())
#define endl '\n'
int dx[] = {0, 0, 1, -1, 1, -1, 1, -1};
int dy[] = {1, -1, 0, 0, -1, 1, 1, -1};
typedef long long ll;
using namespace std;
void file() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifndef ONLINE_JUDGE
if (freopen("input.txt", "r", stdin))
;
if (freopen("output.txt", "w", stdout))
;
#endif
}
int main() {
// file();
int ar[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int k;
cin >> k;
cout << ar[k - 1] << endl;
} | replace | 29 | 30 | 29 | 30 | -11 | |
p02741 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> vec = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int K;
cin >> K;
cout << vec.at(K) << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> vec = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int K;
cin >> K;
cout << vec.at(K - 1) << endl;
} | replace | 8 | 9 | 8 | 9 | 0 | |
p02741 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef vector<int> vec1;
typedef vector<string> vec2;
int main() {
int k;
cin >> k;
vec1 t = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
cout << t.at(k + 1) << endl;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef vector<int> vec1;
typedef vector<string> vec2;
int main() {
int k;
cin >> k;
vec1 t = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
cout << t.at(k - 1) << endl;
} | replace | 12 | 13 | 12 | 13 | 0 | |
p02741 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> vec = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int K;
cin >> K;
cout << vec.at(K) << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> vec = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int K;
cin >> K;
cout << vec.at(K - 1) << endl;
}
| replace | 10 | 11 | 10 | 11 | 0 | |
p02741 | Python | Runtime Error | num = [
1,
1,
1,
2,
1,
2,
1,
5,
2,
2,
1,
5,
1,
2,
1,
14,
1,
5,
1,
5,
2,
2,
1,
15,
2,
2,
5,
4,
1,
4,
1,
51,
]
input = int(input())
print(num[input])
| num = [
1,
1,
1,
2,
1,
2,
1,
5,
2,
2,
1,
5,
1,
2,
1,
14,
1,
5,
1,
5,
2,
2,
1,
15,
2,
2,
5,
4,
1,
4,
1,
51,
]
input = int(input())
print(num[input - 1])
| replace | 35 | 36 | 35 | 36 | 0 | |
p02741 | Python | Runtime Error | import math
a, b, c = map(int, input().split())
result = math.sqrt(a) + math.sqrt(b) < math.sqrt(c)
if result:
print("Yes")
else:
print("No")
| l = [
1,
1,
1,
2,
1,
2,
1,
5,
2,
2,
1,
5,
1,
2,
1,
14,
1,
5,
1,
5,
2,
2,
1,
15,
2,
2,
5,
4,
1,
4,
1,
51,
]
N = int(input())
print(l[N - 1])
| replace | 0 | 10 | 0 | 36 | ValueError: not enough values to unpack (expected 3, got 1) | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02741/Python/s700954713.py", line 2, in <module>
a, b, c = map(int, input().split())
ValueError: not enough values to unpack (expected 3, got 1)
|
p02741 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int K;
vector<int> a = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
cin >> K;
cout << a.at(K);
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int K;
vector<int> a = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
cin >> K;
cout << a.at(K - 1);
} | replace | 7 | 8 | 7 | 8 | 0 | |
p02741 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repp(i, n) for (int i = 1; i <= (int)(n); i++)
#define co(x) cout << x << endl
typedef long long int lint;
int main() {
vector<int> X = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int K;
cin >> K;
co(X.at(K + 1));
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repp(i, n) for (int i = 1; i <= (int)(n); i++)
#define co(x) cout << x << endl
typedef long long int lint;
int main() {
vector<int> X = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int K;
cin >> K;
co(X.at(K - 1));
} | replace | 12 | 13 | 12 | 13 | 0 | |
p02741 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int K;
cin >> K;
vector<int> vec(32);
vec = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
cout << vec.at(K) << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int K;
cin >> K;
vector<int> vec(32);
vec = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
cout << vec.at(K - 1) << endl;
}
| replace | 9 | 11 | 9 | 10 | 0 | |
p02741 | C++ | Runtime Error | // I am so vegetable
#include <bits/stdc++.h>
#define FIO ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define _for(i, a, b) for (int i = (a); i < (b); ++i)
#define _defor(i, a, b) for ((i) = (a); (i) < (b); ++i)
#define _rfor(i, a, b) for (int i = (a); i > (b); --i)
#define _sfor(p, st) for (auto &p : st)
#define _LOCAL_
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const ll N = 1e5 + 5;
const int MOD = 1e9 + 7;
const double exps = 1e-8;
int main() {
#ifdef _LOCAL_
ifstream cin("E:\\acm dream\\in.txt");
ofstream cout("E:\\acm dream\\out.txt");
#endif
// srand((unsigned)time(nullptr));
FIO;
int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int n;
cin >> n;
cout << a[n - 1] << '\n';
return 0;
} | // I am so vegetable
#include <bits/stdc++.h>
#define FIO ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define _for(i, a, b) for (int i = (a); i < (b); ++i)
#define _defor(i, a, b) for ((i) = (a); (i) < (b); ++i)
#define _rfor(i, a, b) for (int i = (a); i > (b); --i)
#define _sfor(p, st) for (auto &p : st)
// #define _LOCAL_
using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const ll N = 1e5 + 5;
const int MOD = 1e9 + 7;
const double exps = 1e-8;
int main() {
#ifdef _LOCAL_
ifstream cin("E:\\acm dream\\in.txt");
ofstream cout("E:\\acm dream\\out.txt");
#endif
// srand((unsigned)time(nullptr));
FIO;
int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int n;
cin >> n;
cout << a[n - 1] << '\n';
return 0;
} | replace | 7 | 8 | 7 | 8 | -11 | |
p02741 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> nb = {1, 1, 1, 2, 1};
int input;
cin >> input;
cout << nb.at(input - 1) << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> nb = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int input;
cin >> input;
cout << nb.at(input - 1) << endl;
} | replace | 4 | 5 | 4 | 6 | -6 | terminate called after throwing an instance of 'std::out_of_range'
what(): vector::_M_range_check: __n (which is 5) >= this->size() (which is 5)
|
p02741 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int K;
vector<int> vec;
vec = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
cin >> K;
cout << vec.at(K) << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int K;
vector<int> vec;
vec = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
cin >> K;
cout << vec.at(K - 1) << endl;
}
| replace | 9 | 10 | 9 | 10 | 0 | |
p02741 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int a[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int k;
cin >> k;
cout << a[k - 1] << '\n';
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int a[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int k;
cin >> k;
cout << a[k - 1] << '\n';
} | delete | 3 | 7 | 3 | 3 | -11 | |
p02741 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> vec(32);
vec = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int k;
cin >> k;
cout << vec.at(k);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> vec(32);
vec = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int k;
cin >> k;
cout << vec.at(k - 1);
return 0;
} | replace | 9 | 10 | 9 | 10 | 0 | |
p02741 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main() {
int K;
cin >> K;
vector<int> a = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
cout << a.at(K) << endl;
return 0;
} | #include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main() {
int K;
cin >> K;
vector<int> a = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
cout << a.at(K - 1) << endl;
return 0;
} | replace | 9 | 10 | 9 | 10 | 0 | |
p02741 | C++ | Runtime Error | // P.C.2.0.
#include <bits/stdc++.h>
#include <unordered_map>
using namespace std;
#define speed \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
#define ll long long int
#define ul unsigned long int
#define mod 1000007
#define endl "\n"
////fast power
ll power(ll a, ll b) {
if (b == 0)
return 1;
ll smallans = power(a, b / 2);
smallans = smallans * smallans;
if (b % 2 == 0)
return smallans;
else
return a * smallans;
}
////
int main() {
////
speed
////
int arr[33];
for (int i = 1; i < 33; i++) {
cin >> arr[i];
}
int temp;
cin >> temp;
cout << arr[temp];
} | // P.C.2.0.
#include <bits/stdc++.h>
#include <unordered_map>
using namespace std;
#define speed \
ios_base::sync_with_stdio(false); \
cin.tie(NULL);
#define ll long long int
#define ul unsigned long int
#define mod 1000007
#define endl "\n"
////fast power
ll power(ll a, ll b) {
if (b == 0)
return 1;
ll smallans = power(a, b / 2);
smallans = smallans * smallans;
if (b % 2 == 0)
return smallans;
else
return a * smallans;
}
////
int main() {
////
speed
////
int arr[33] = {0, 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
// for(int i=1;i<33;i++){
// cin>>arr[i];
// }
int temp;
cin >> temp;
cout << arr[temp];
} | replace | 27 | 31 | 27 | 32 | -11 | |
p02741 | C++ | Runtime Error | #include <cstdio>
#include <iostream>
using namespace std;
int main() {
int K;
cin >> K;
int list[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
return list[K];
}
| #include <cstdio>
#include <iostream>
using namespace std;
int main() {
int K;
cin >> K;
int arr[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
cout << arr[K - 1] << endl;
}
| replace | 9 | 12 | 9 | 13 | 1 | |
p02741 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> a = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
cout << a.at(n + 1) << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> a = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
cout << a.at(n - 1) << endl;
}
| replace | 9 | 10 | 9 | 10 | 0 | |
p02741 | C++ | Runtime Error | #include <iostream>
#include <vector>
using namespace std;
#define N 32
int main() {
vector<int> data = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int K;
cin >> K;
cout << data.at(K) << endl;
} | #include <iostream>
#include <vector>
using namespace std;
#define N 32
int main() {
vector<int> data = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int K;
cin >> K;
cout << data.at(K - 1) << endl;
} | replace | 12 | 13 | 12 | 13 | 0 | |
p02741 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> vec; // int型の配列変数vecを宣言
int K;
cin >> K;
vec = {
1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1,
5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51}; // 25, 100, 64
// という整数(int)の列を代入
cout << vec.at(K) << endl; // 1つめである25を出力
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> vec; // int型の配列変数vecを宣言
int K;
cin >> K;
vec = {
1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1,
5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51}; // 25, 100, 64
// という整数(int)の列を代入
cout << vec.at(K - 1) << endl; // 1つめである25を出力
}
| replace | 14 | 15 | 14 | 15 | 0 | |
p02741 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
int main() {
int k;
cin >> k;
vector<int> v = {1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1,
5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
cout << v.at(k - 1);
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
int main() {
int k;
cin >> k;
vector<int> v = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
cout << v.at(k - 1);
} | replace | 8 | 10 | 8 | 10 | 0 | |
p02741 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s = "1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, "
"2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51";
string ans = "";
int cnt = 0;
int i = -1;
while (cnt < n) {
i++;
switch (s[i]) {
case ',':
cnt++;
if (cnt < n)
ans = "";
case ' ':
break;
default:
ans += s[i];
break;
}
}
cout << ans << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s = "1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, "
"2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51,";
string ans = "";
int cnt = 0;
int i = -1;
while (cnt < n) {
i++;
switch (s[i]) {
case ',':
cnt++;
if (cnt < n)
ans = "";
case ' ':
break;
default:
ans += s[i];
break;
}
}
cout << ans << endl;
} | replace | 7 | 8 | 7 | 8 | 0 | |
p02741 | C++ | Runtime Error | #include <algorithm>
#include <iostream>
#include <numeric>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
int main() {
int K;
cin >> K;
vector<int> vec{1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
cout << vec.at(K);
}
| #include <algorithm>
#include <iostream>
#include <numeric>
#include <stdio.h>
#include <string>
#include <vector>
using namespace std;
int main() {
int K;
cin >> K;
vector<int> vec{1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
cout << vec.at(K - 1);
} | replace | 13 | 14 | 13 | 14 | 0 | |
p02741 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int K;
cin >> K;
vector<int> vec;
vec = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
cout << vec.at(K) << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int K;
cin >> K;
vector<int> vec;
vec = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
cout << vec.at(K - 1) << endl;
}
| replace | 10 | 11 | 10 | 11 | 0 | |
p02741 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> num{100, 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int k;
cin >> k;
cout << num.at(k + 1) << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> num{100, 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int k;
cin >> k;
cout << num.at(k) << endl;
} | replace | 11 | 12 | 11 | 12 | 0 | |
p02741 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> data = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int K;
cin >> K;
cout << data.at(K + 1) << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> data = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int K;
cin >> K;
cout << data.at(K - 1) << endl;
} | replace | 8 | 9 | 8 | 9 | 0 | |
p02741 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> S;
S = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
cout << S.at(N) << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> S;
S = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
cout << S.at(N - 1) << endl;
}
| replace | 8 | 9 | 8 | 9 | 0 | |
p02741 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> vec;
vec = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int K;
cin >> K;
cout << vec.at(K) << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> vec;
vec = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int K;
cin >> K;
cout << vec.at(K - 1) << endl;
} | replace | 10 | 11 | 10 | 11 | 0 | |
p02741 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int K = 0;
cin >> K;
vector<int> suretsu(32);
suretsu = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
cout << suretsu.at(K + 1) << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int K = 0;
cin >> K;
vector<int> suretsu(32);
suretsu = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
cout << suretsu.at(K - 1) << endl;
}
| replace | 10 | 11 | 10 | 11 | 0 | |
p02741 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int K;
cin >> K;
vector<int> S = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
cout << S.at(K + 1) << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int K;
cin >> K;
vector<int> S = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
cout << S.at(K - 1) << endl;
}
| replace | 8 | 9 | 8 | 9 | 0 | |
p02741 | C++ | Runtime Error | /*
─────────────────────
───────────████████──
──────────███▄███████
──────────███████████
──────────███████████
──────────██████─────
──────────█████████──
█───────███████──────
██────████████████───
███──██████████──█───
███████████████──────
███████████████──────
─█████████████───────
──███████████────────
────████████─────────
─────███──██─────────
─────██────█─────────
─────█─────█─────────
─────██────██────────
─────────────────────
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define read(a) \
int a; \
cin >> a;
#define readarr(a, n) \
int a[(n) + 1] = {}; \
fori(i, 1, (n)) { cin >> a[i]; }
#define readmat(a, n, m) \
int a[n + 1][m + 1] = {}; \
fori(i, 1, n) { fori(j, 1, m) cin >> a[i][j]; }
#define pb push_back
#define fi first
#define se second
#define rz resize
#define sz(s) (int)(s.size())
#define fori(i, a, b) for (int i = (a); i <= (b); i++)
#define ford(i, a, b) for (int i = (a); i >= (b); i--)
#define sort1(v) sort(v.begin(), v.end())
#define endl '\n'
using namespace std;
using namespace __gnu_pbds;
typedef tree<long long, null_type, less<long long>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pair<int, int>> vpi;
typedef vector<vector<int>> vvi;
const int INF = 4e18;
const int mod = 1e9 + 7;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("INPUT.txt", "r", stdin);
freopen("OUTPUT.txt", "w", stdout);
freopen("OUTPUT_ERROR.txt", "w", stderr);
#endif
// start from here
int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
read(k);
cout << a[k - 1];
return 0;
}
| /*
─────────────────────
───────────████████──
──────────███▄███████
──────────███████████
──────────███████████
──────────██████─────
──────────█████████──
█───────███████──────
██────████████████───
███──██████████──█───
███████████████──────
███████████████──────
─█████████████───────
──███████████────────
────████████─────────
─────███──██─────────
─────██────█─────────
─────█─────█─────────
─────██────██────────
─────────────────────
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define read(a) \
int a; \
cin >> a;
#define readarr(a, n) \
int a[(n) + 1] = {}; \
fori(i, 1, (n)) { cin >> a[i]; }
#define readmat(a, n, m) \
int a[n + 1][m + 1] = {}; \
fori(i, 1, n) { fori(j, 1, m) cin >> a[i][j]; }
#define pb push_back
#define fi first
#define se second
#define rz resize
#define sz(s) (int)(s.size())
#define fori(i, a, b) for (int i = (a); i <= (b); i++)
#define ford(i, a, b) for (int i = (a); i >= (b); i--)
#define sort1(v) sort(v.begin(), v.end())
#define endl '\n'
using namespace std;
using namespace __gnu_pbds;
typedef tree<long long, null_type, less<long long>, rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pair<int, int>> vpi;
typedef vector<vector<int>> vvi;
const int INF = 4e18;
const int mod = 1e9 + 7;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
// start from here
int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
read(k);
cout << a[k - 1];
return 0;
}
| delete | 68 | 74 | 68 | 68 | -7 | |
p02741 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int K;
cin >> K;
vector<int> vec = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
cout << vec.at(K) << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int K;
cin >> K;
vector<int> vec = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
cout << vec.at(K - 1) << endl;
return 0;
}
| replace | 8 | 9 | 8 | 9 | 0 | |
p02741 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> vec = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int N;
cin >> N;
int K;
K = N + 1;
cout << vec.at(K) << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> vec = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int N;
cin >> N;
int K;
K = N - 1;
cout << vec.at(K) << endl;
}
| replace | 10 | 11 | 10 | 11 | 0 | |
p02741 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> yama;
yama = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int k;
cin >> k;
cout << yama.at(k) << endl;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> yama;
yama = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int k;
cin >> k;
k = k - 1;
cout << yama.at(k) << endl;
} | insert | 10 | 10 | 10 | 11 | 0 | |
p02741 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
int K;
cin >> K;
// 配列
vector<int> vec; // int型の配列変数vecを宣言
vec = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
cout << vec.at(K) << endl; //
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
int K;
cin >> K;
// 配列
vector<int> vec; // int型の配列変数vecを宣言
vec = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
cout << vec.at(K - 1) << endl; //
}
| replace | 13 | 14 | 13 | 14 | 0 | |
p02741 | C++ | Runtime Error | //*******Abhijit Burman***********//
// Jalpaiguri Government Engineering College//
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mk make_pair
#define MAXX (1000000000000000000 + 7)
#define fio \
ios_base::sync_with_stdio(0); \
cin.tie(NULL); \
cout.tie(NULL)
int solve() {
int a[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int k;
cin >> k;
cout << a[k - 1] << endl;
return 0;
}
int main() {
fio;
#ifndef ONLINE_JUDGE
// for getting input from input.txt
freopen("input.txt", "r", stdin);
// for writing output to output.txt
freopen("output.txt", "w", stdout);
#endif
ll t = 1;
// cin>>t;
while (t--) {
solve();
}
return 0;
}
| //*******Abhijit Burman***********//
// Jalpaiguri Government Engineering College//
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mk make_pair
#define MAXX (1000000000000000000 + 7)
#define fio \
ios_base::sync_with_stdio(0); \
cin.tie(NULL); \
cout.tie(NULL)
int solve() {
int a[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int k;
cin >> k;
cout << a[k - 1] << endl;
return 0;
}
int main() {
fio;
// #ifndef ONLINE_JUDGE
// // for getting input from input.txt
// freopen("input.txt", "r", stdin);
// // for writing output to output.txt
// freopen("output.txt", "w", stdout);
// #endif
ll t = 1;
// cin>>t;
while (t--) {
solve();
}
return 0;
}
| replace | 26 | 32 | 26 | 32 | -7 | |
p02742 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using ulint = unsigned long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios {
fast_ios() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(20);
};
} fast_ios_;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) \
for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) \
for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
for (auto &v : vec)
is >> v;
return is;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
os << "[";
for (auto v : vec)
os << v << ",";
os << "]";
return os;
}
template <typename T> ostream &operator<<(ostream &os, const deque<T> &vec) {
os << "deq[";
for (auto v : vec)
os << v << ",";
os << "]";
return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &vec) {
os << "{";
for (auto v : vec)
os << v << ",";
os << "}";
return os;
}
template <typename T>
ostream &operator<<(ostream &os, const unordered_set<T> &vec) {
os << "{";
for (auto v : vec)
os << v << ",";
os << "}";
return os;
}
template <typename T> ostream &operator<<(ostream &os, const multiset<T> &vec) {
os << "{";
for (auto v : vec)
os << v << ",";
os << "}";
return os;
}
template <typename T>
ostream &operator<<(ostream &os, const unordered_multiset<T> &vec) {
os << "{";
for (auto v : vec)
os << v << ",";
os << "}";
return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &pa) {
os << "(" << pa.first << "," << pa.second << ")";
return os;
}
template <typename TK, typename TV>
ostream &operator<<(ostream &os, const map<TK, TV> &mp) {
os << "{";
for (auto v : mp)
os << v.first << "=>" << v.second << ",";
os << "}";
return os;
}
template <typename TK, typename TV>
ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp) {
os << "{";
for (auto v : mp)
os << v.first << "=>" << v.second << ",";
os << "}";
return os;
}
template <typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template <typename T, typename... Args>
void ndarray(vector<T> &vec, int len, Args... args) {
vec.resize(len);
for (auto &v : vec)
ndarray(v, args...);
}
template <typename T> bool mjjj(T &m, const T q) {
if (m < q) {
m = q;
return true;
} else
return false;
}
template <typename T> bool mmin(T &m, const T q) {
if (m > q) {
m = q;
return true;
} else
return false;
}
template <typename T1, typename T2>
pair<T1, T2> operator+(const pair<T1, T2> &l, const pair<T1, T2> &r) {
return make_pair(l.first + r.first, l.second + r.second);
}
template <typename T1, typename T2>
pair<T1, T2> operator-(const pair<T1, T2> &l, const pair<T1, T2> &r) {
return make_pair(l.first - r.first, l.second - r.second);
}
#define dbg(x) \
cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tag_and_trait.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds; // find_by_order(), order_of_key()
template<typename TK> using pbds_set = tree<TK, null_type, less<TK>,
rb_tree_tag, tree_order_statistics_node_update>; template<typename TK, typename
TV> using pbds_map = tree<TK, TV, less<TK>, rb_tree_tag,
tree_order_statistics_node_update>;
*/
template <typename T> struct edge {
int src, to;
T cost;
// edge(int to) : src(-1),to(to),cost(-1){}
edge(int to, T cost) : src(-1), to(to), cost(cost) {}
edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
edge &operator=(const int &x) {
to = x;
return *this;
}
operator int() const { return to; }
};
template <typename T> using Edges = vector<edge<T>>;
template <typename T> using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<lint>>;
template <typename T> using Matrix = vector<vector<T>>;
#define INF 1e+9
#define MAX_V 100000
// <最短距離, 頂点の番号>
using P = pair<lint, lint>;
lint V;
vector<edge<lint>> G[MAX_V];
lint d[MAX_V];
// void dijkstra(lint s) {
// priority_queue<P, vector<P>, greater<P> > que;
// fill(d, d+V, INF);
// d[s] = 0;
// que.push(P(0, s));
// while (!que.empty()) {
// P p = que.top();
// que.pop();
// lint v = p.second;
// if (d[v] < p.first) continue;
// for (lint i=0; i<G[v].size(); ++i) {
// edge<lint> e = G[v][i];
// if (d[e.to] > d[v] + e.cost) {
// d[e.to] = d[v] + e.cost;
// que.push(P(d[e.to], e.to));
// }
// }
// }
// }
const lint mod = 1000000007;
struct mint {
lint x; // typedef long long lint;
mint(lint x = 0) : x((x % mod + mod) % mod) {}
mint &operator+=(const mint a) {
if ((x += a.x) >= mod)
x -= mod;
return *this;
}
mint &operator-=(const mint a) {
if ((x += mod - a.x) >= mod)
x -= mod;
return *this;
}
mint &operator*=(const mint a) {
(x *= a.x) %= mod;
return *this;
}
mint operator+(const mint a) const {
mint res(*this);
return res += a;
}
mint operator-(const mint a) const {
mint res(*this);
return res -= a;
}
mint operator*(const mint a) const {
mint res(*this);
return res *= a;
}
mint pow(lint t) const {
if (!t)
return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1)
a *= *this;
return a;
}
// for prime mod
mint inv() const { return pow(mod - 2); }
mint &operator/=(const mint a) { return (*this) *= a.inv(); }
mint operator/(const mint a) const {
mint res(*this);
return res /= a;
}
};
map<lint, lint> prime_factor(lint n) {
map<lint, lint> ret;
for (lint i = 2; i * i <= n; i++) {
while (n % i == 0) {
ret[i]++;
n /= i;
}
}
if (n != 1)
ret[n] = 1;
return ret;
}
lint MAX = 1000000000;
vector<lint> co;
bool dfs(lint from, lint to, lint par = -1) {
if (from == to) {
return true;
}
for (edge<lint> v : G[from]) {
if (v.to == par)
continue;
if (dfs(v.to, to, from)) {
co.push_back(v.cost);
return true;
}
}
return false;
}
lint digit(lint a, lint b) {
lint ad = 1, bd = 1;
while (a > 9) {
ad++;
a /= 10;
}
while (b > 9) {
bd++;
b /= 10;
}
return max(ad, bd);
}
int main() {
lint h, w;
cin >> h >> w;
if (h == 1 || w == 1) {
return 1;
}
if (w % 2 == 0) {
cout << h * w / 2;
return 0;
} else {
cout << (lint)((h + 1) / 2) * (lint)((w + 1) / 2) +
(lint)(w / 2) * (lint)(h / 2);
return 0;
}
}
lint gcd(lint a, lint b) {
if (a < b) {
a ^= b;
b ^= a;
a ^= b;
}
return b ? gcd(b, a % b) : a;
}
lint lcm(lint a, lint b) { return a * b / gcd(a, b); } | #include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using ulint = unsigned long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios {
fast_ios() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(20);
};
} fast_ios_;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) \
for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) \
for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
for (auto &v : vec)
is >> v;
return is;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
os << "[";
for (auto v : vec)
os << v << ",";
os << "]";
return os;
}
template <typename T> ostream &operator<<(ostream &os, const deque<T> &vec) {
os << "deq[";
for (auto v : vec)
os << v << ",";
os << "]";
return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &vec) {
os << "{";
for (auto v : vec)
os << v << ",";
os << "}";
return os;
}
template <typename T>
ostream &operator<<(ostream &os, const unordered_set<T> &vec) {
os << "{";
for (auto v : vec)
os << v << ",";
os << "}";
return os;
}
template <typename T> ostream &operator<<(ostream &os, const multiset<T> &vec) {
os << "{";
for (auto v : vec)
os << v << ",";
os << "}";
return os;
}
template <typename T>
ostream &operator<<(ostream &os, const unordered_multiset<T> &vec) {
os << "{";
for (auto v : vec)
os << v << ",";
os << "}";
return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &pa) {
os << "(" << pa.first << "," << pa.second << ")";
return os;
}
template <typename TK, typename TV>
ostream &operator<<(ostream &os, const map<TK, TV> &mp) {
os << "{";
for (auto v : mp)
os << v.first << "=>" << v.second << ",";
os << "}";
return os;
}
template <typename TK, typename TV>
ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp) {
os << "{";
for (auto v : mp)
os << v.first << "=>" << v.second << ",";
os << "}";
return os;
}
template <typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template <typename T, typename... Args>
void ndarray(vector<T> &vec, int len, Args... args) {
vec.resize(len);
for (auto &v : vec)
ndarray(v, args...);
}
template <typename T> bool mjjj(T &m, const T q) {
if (m < q) {
m = q;
return true;
} else
return false;
}
template <typename T> bool mmin(T &m, const T q) {
if (m > q) {
m = q;
return true;
} else
return false;
}
template <typename T1, typename T2>
pair<T1, T2> operator+(const pair<T1, T2> &l, const pair<T1, T2> &r) {
return make_pair(l.first + r.first, l.second + r.second);
}
template <typename T1, typename T2>
pair<T1, T2> operator-(const pair<T1, T2> &l, const pair<T1, T2> &r) {
return make_pair(l.first - r.first, l.second - r.second);
}
#define dbg(x) \
cerr << #x << " = " << (x) << " (L" << __LINE__ << ") " << __FILE__ << endl;
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tag_and_trait.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds; // find_by_order(), order_of_key()
template<typename TK> using pbds_set = tree<TK, null_type, less<TK>,
rb_tree_tag, tree_order_statistics_node_update>; template<typename TK, typename
TV> using pbds_map = tree<TK, TV, less<TK>, rb_tree_tag,
tree_order_statistics_node_update>;
*/
template <typename T> struct edge {
int src, to;
T cost;
// edge(int to) : src(-1),to(to),cost(-1){}
edge(int to, T cost) : src(-1), to(to), cost(cost) {}
edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
edge &operator=(const int &x) {
to = x;
return *this;
}
operator int() const { return to; }
};
template <typename T> using Edges = vector<edge<T>>;
template <typename T> using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<lint>>;
template <typename T> using Matrix = vector<vector<T>>;
#define INF 1e+9
#define MAX_V 100000
// <最短距離, 頂点の番号>
using P = pair<lint, lint>;
lint V;
vector<edge<lint>> G[MAX_V];
lint d[MAX_V];
// void dijkstra(lint s) {
// priority_queue<P, vector<P>, greater<P> > que;
// fill(d, d+V, INF);
// d[s] = 0;
// que.push(P(0, s));
// while (!que.empty()) {
// P p = que.top();
// que.pop();
// lint v = p.second;
// if (d[v] < p.first) continue;
// for (lint i=0; i<G[v].size(); ++i) {
// edge<lint> e = G[v][i];
// if (d[e.to] > d[v] + e.cost) {
// d[e.to] = d[v] + e.cost;
// que.push(P(d[e.to], e.to));
// }
// }
// }
// }
const lint mod = 1000000007;
struct mint {
lint x; // typedef long long lint;
mint(lint x = 0) : x((x % mod + mod) % mod) {}
mint &operator+=(const mint a) {
if ((x += a.x) >= mod)
x -= mod;
return *this;
}
mint &operator-=(const mint a) {
if ((x += mod - a.x) >= mod)
x -= mod;
return *this;
}
mint &operator*=(const mint a) {
(x *= a.x) %= mod;
return *this;
}
mint operator+(const mint a) const {
mint res(*this);
return res += a;
}
mint operator-(const mint a) const {
mint res(*this);
return res -= a;
}
mint operator*(const mint a) const {
mint res(*this);
return res *= a;
}
mint pow(lint t) const {
if (!t)
return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1)
a *= *this;
return a;
}
// for prime mod
mint inv() const { return pow(mod - 2); }
mint &operator/=(const mint a) { return (*this) *= a.inv(); }
mint operator/(const mint a) const {
mint res(*this);
return res /= a;
}
};
map<lint, lint> prime_factor(lint n) {
map<lint, lint> ret;
for (lint i = 2; i * i <= n; i++) {
while (n % i == 0) {
ret[i]++;
n /= i;
}
}
if (n != 1)
ret[n] = 1;
return ret;
}
lint MAX = 1000000000;
vector<lint> co;
bool dfs(lint from, lint to, lint par = -1) {
if (from == to) {
return true;
}
for (edge<lint> v : G[from]) {
if (v.to == par)
continue;
if (dfs(v.to, to, from)) {
co.push_back(v.cost);
return true;
}
}
return false;
}
lint digit(lint a, lint b) {
lint ad = 1, bd = 1;
while (a > 9) {
ad++;
a /= 10;
}
while (b > 9) {
bd++;
b /= 10;
}
return max(ad, bd);
}
int main() {
lint h, w;
cin >> h >> w;
if (h == 1 || w == 1) {
cout << 1;
return 0;
}
if (w % 2 == 0) {
cout << h * w / 2;
return 0;
} else {
cout << (lint)((h + 1) / 2) * (lint)((w + 1) / 2) +
(lint)(w / 2) * (lint)(h / 2);
return 0;
}
}
lint gcd(lint a, lint b) {
if (a < b) {
a ^= b;
b ^= a;
a ^= b;
}
return b ? gcd(b, a % b) : a;
}
lint lcm(lint a, lint b) { return a * b / gcd(a, b); } | replace | 276 | 277 | 276 | 278 | 0 | |
p02742 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
long long h, w;
int main() {
scanf("%lld%lld", &h, &w);
if (h == 1 || w == 1)
return puts("1");
printf("%lld\n", (h * w + 1) / 2);
} | #include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
long long h, w;
int main() {
scanf("%lld%lld", &h, &w);
if (h == 1 || w == 1)
return puts("1") * 0;
printf("%lld\n", (h * w + 1) / 2);
} | replace | 7 | 8 | 7 | 8 | 0 | |
p02742 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int main() {
int h;
cin >> h;
int w;
cin >> w;
pair<int, int> p;
vector<pair<int, int>> chess;
for (int i = 0; i < h; ++i) {
for (int j = 0; j < w; ++j) {
p = make_pair(i, j);
chess.push_back(p);
}
}
int count = 0;
for (int i = 0; i < int(chess.size()); ++i) {
pair<int, int> hoge;
hoge = chess.at(i);
if ((hoge.first + hoge.second) % 2 == 0)
++count;
}
cout << count << endl;
}
| #include <bits/stdc++.h>
using namespace std;
int main() {
long long h, w;
cin >> h >> w;
if (h == 1 || w == 1)
cout << 1 << endl;
else
cout << (h * w) / 2 + ((h * w) % 2) << endl;
}
| replace | 4 | 25 | 4 | 10 | TLE | |
p02742 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
const ll mod = 1e9 + 7;
const ll maxn = 2e5 + 5;
const double pi =
3.1415926535897932384626433832795028841971693993751058209749445923078;
// iostream::sync_with_stdio(false);
int main() {
int m[35] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int n;
cin >> n;
cout << m[n - 1] << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
const ll mod = 1e9 + 7;
const ll maxn = 2e5 + 5;
const double pi =
3.1415926535897932384626433832795028841971693993751058209749445923078;
// iostream::sync_with_stdio(false);
int main() {
ll n, m;
cin >> n >> m;
if (n == 1 || m == 1) {
cout << 1 << endl;
} else if (n % 2) {
if (m % 2) {
cout << (n + 1) / 2 * (m + 1) / 2 + (n / 2) * (m / 2);
} else {
cout << (n + 1) / 2 * (m / 2) + (n / 2) * (m / 2);
}
} else {
cout << (n / 2) * m;
}
return 0;
}
| replace | 14 | 19 | 14 | 27 | 0 | |
p02742 | Python | Runtime Error | H, W = map(int, input().split())
if H == 1 or W == 1:
print(1)
else:
if (H * W) % 2 == 1:
ans = H * W // 2 + 1
else:
ans = H * W // 2
print(ans)
| H, W = map(int, input().split())
if H == 1 or W == 1:
print(1)
else:
if (H * W) % 2 == 1:
ans = H * W // 2 + 1
else:
ans = H * W // 2
print(ans)
| replace | 9 | 10 | 9 | 10 | 0 | |
p02742 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
unsigned long long int h, w;
cin >> h >> w;
unsigned long long int bh = 0;
unsigned long long int sh = 0;
if (h == 1 or w == 1) {
return 1;
}
if (h & 1) {
bh = (h / 2) + 1;
sh = bh - 1;
} else {
bh = h / 2;
sh = bh;
}
unsigned long long int total = 0;
unsigned long long int half = w / 2;
if (w & 1) {
total = (half + 1) * bh + (half * sh);
} else {
total = half * bh + half * sh;
}
cout << total << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
unsigned long long int h, w;
cin >> h >> w;
unsigned long long int bh = 0;
unsigned long long int sh = 0;
if (h == 1 or w == 1) {
cout << 1 << endl;
return 0;
}
if (h & 1) {
bh = (h / 2) + 1;
sh = bh - 1;
} else {
bh = h / 2;
sh = bh;
}
unsigned long long int total = 0;
unsigned long long int half = w / 2;
if (w & 1) {
total = (half + 1) * bh + (half * sh);
} else {
total = half * bh + half * sh;
}
cout << total << endl;
return 0;
} | replace | 10 | 11 | 10 | 12 | 0 | |
p02742 | C++ | Runtime Error | // #pragma GCC optimize("O3")
// #pragma GCC target("avx")
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
// Types
using ll = long long int;
using str = string;
template <class T> using u_set = unordered_set<T>;
template <class K, class V> using u_map = unordered_map<K, V>;
template <class V> using graph = u_map<V, u_set<V>>;
namespace io {
// Input
using IS = istream;
IS &in(IS &);
IS &in(IS &i) { return i; }
template <class T, class... Ts> IS &in(IS &i, T &a, Ts &...as) {
return in(i >> a, as...);
}
template <class V> IS &operator>>(IS &i, vector<V> &a) {
for_each(a.begin(), a.end(), [&i](auto &e) { i >> e; });
return i;
}
template <class F, class S> IS &operator>>(IS &i, pair<F, S> &p) {
return in(i, p.first, p.second);
}
template <class... Ts, size_t... I>
IS &tuple_in(IS &i, tuple<Ts...> &t, index_sequence<I...>) {
return in(i, get<I>(t)...);
}
template <class... Ts> IS &operator>>(IS &i, tuple<Ts...> &t) {
return tuple_in(i, t, make_index_sequence<sizeof...(Ts)>());
}
// Output
using OS = ostream;
OS &out(OS &o) { return o << endl; }
template <class T> OS &out(OS &o, T const &a) { return o << a << endl; }
template <class T, class... Ts> OS &out(OS &o, T const &a, Ts const &...as) {
return out(o << a << " ", as...);
}
template <class F, class S> OS &operator<<(OS &o, pair<F, S> const &p) {
return o << p.first << ":" << p.second;
}
template <class... Ts> OS &args_out(OS &o, Ts const &...ts);
OS &args_out(OS &o) { return o; }
template <class T> OS &args_out(OS &o, T const &t) { return o << t; }
template <class T0, class T1, class... Ts>
OS &args_out(OS &o, T0 const &t0, T1 const &t1, Ts const &...ts) {
return args_out(o << t0 << ",", t1, ts...);
}
template <class... Ts, size_t... I>
OS &tuple_out(OS &o, tuple<Ts...> const &t, index_sequence<I...>) {
return args_out(o, get<I>(t)...);
}
template <class... Ts> OS &operator<<(OS &o, tuple<Ts...> const &t) {
return tuple_out(o << "(", t, make_index_sequence<sizeof...(Ts)>()) << ")";
}
template <class T> struct Joiner {
str const pre;
str const post;
str const delim;
vector<T> const container;
Joiner(vector<T> v, str const &delim, str const &pre, str const &post)
: pre(pre), post(post), delim(delim), container(v) {}
};
template <class T> OS &operator<<(OS &o, Joiner<T> const &joiner) {
auto itr = joiner.container.begin();
auto end = joiner.container.end();
o << joiner.pre;
if (itr != end)
o << *(itr++);
while (itr != end)
o << joiner.delim << *(itr++);
return o << joiner.post;
}
template <class Itr, class T = typename iterator_traits<Itr>::value_type>
Joiner<T> join(Itr b, Itr e, str const &delim = ""s, str const &pre = ""s,
str const &post = ""s) {
return Joiner<T>(vector<T>(b, e), delim, pre, post);
}
template <
class C,
class T = typename iterator_traits<typename C::iterator>::value_type,
typename enable_if<!is_same<C, str>::value, nullptr_t>::type = nullptr>
OS &operator<<(OS &o, C const &a) {
return o << join(a.begin(), a.end(), ",", "[", "]");
}
} // namespace io
auto input = [](auto &...a) { io::in(cin, a...); };
auto print = [](auto const &...a) { io::out(cout, a...); };
#ifdef JUMPAKU_DEBUG
auto dump = [](auto const &...a) { io::out(cerr, a...); };
#else
auto dump = [](auto const &...) {};
#endif
using io::join;
// Hash
namespace hashcode {
template <class... Ts> uint64_t hash_args(uint64_t h, Ts const &...ts);
uint64_t hash_args(uint64_t h) { return h; }
template <class T, class... Ts>
uint64_t hash_args(uint64_t h, T const &t, Ts const &...ts) {
constexpr hash<T> hasher;
return hash_args(((h << 19) - h) ^ hasher(t), ts...);
}
template <class... Ts, size_t... I>
uint64_t hash_tuple(tuple<Ts...> const &t, index_sequence<I...>) {
return hash_args(17, get<I>(t)...);
}
} // namespace hashcode
namespace std {
template <class... Ts> struct hash<tuple<Ts...>> {
size_t operator()(tuple<Ts...> const &t) const {
uint64_t h = hashcode::hash_tuple(t, index_sequence_for<Ts...>());
return h ^ (h >> 32);
}
};
} // namespace std
// Range
namespace ranges {
template <class T, class Itr> struct iterator_base {
using difference_type = ll;
using value_type = T;
using pointer = T *;
using reference = T &;
using iterator_category = random_access_iterator_tag;
ll i;
iterator_base(ll const &i = 0) : i(i) {}
bool operator==(Itr const &itr) const { return i == itr.i; }
bool operator!=(Itr const &itr) const { return i != itr.i; }
ll operator-(Itr const &itr) const { return i - itr.i; }
Itr operator++(int) { return with(i++); }
Itr operator--(int) { return with(i--); }
Itr operator+(ll const &n) const { return with(i + n); }
Itr operator-(ll const &n) const { return with(i - n); }
Itr &operator+=(ll const &n) {
i += n;
return self();
}
Itr &operator-=(ll const &n) { return self() += (-n); }
Itr &operator++() { return self() += 1; }
Itr &operator--() { return self() -= 1; }
protected:
virtual Itr with(ll i) const = 0;
virtual Itr &self() = 0;
};
template <class T> struct seq_base {
ll const b;
ll const e;
seq_base(ll b, ll e) : b(b), e(e) {}
ll size() const { return e - b; }
bool empty() const { return size() == 0; }
};
template <class T> struct seq : seq_base<T> {
struct iterator : iterator_base<T, iterator> {
seq<T> const &s;
iterator(seq<T> const &s, ll const &i)
: iterator_base<T, iterator>(i), s(s) {}
iterator with(ll i) const override { return iterator(s, i); }
iterator &self() override { return *this; }
T operator*() const { return s[this->i]; }
iterator &operator=(iterator const &itr) {
this->i = itr.i;
return *this;
}
};
function<T(ll)> const f;
seq(ll b, ll e, function<T(ll)> const &f) : seq_base<T>(b, e), f(f) {}
iterator begin() const { return iterator(*this, 0); }
iterator end() const { return iterator(*this, this->size()); }
T operator[](ll i) const { return f(i + this->b); }
};
struct range : seq_base<ll> {
struct iterator : iterator_base<ll, iterator> {
iterator(ll const &i) : iterator_base<ll, iterator>(i) {}
iterator with(ll i) const override { return iterator(i); }
iterator &self() override { return *this; }
ll operator*() const { return i; }
};
range(ll n) : range(0LL, n) {}
range(ll b, ll e) : seq_base<ll>(b, e) {}
iterator begin() const { return iterator(b); }
iterator end() const { return iterator(e); }
ll operator[](ll i) const { return i + b; }
};
} // namespace ranges
using range = ranges::range;
range::iterator end(ll i) { return range::iterator(i); }
range::iterator begin(ll i) { return range::iterator(i); }
template <class F> auto seq(ll b, ll e, F const &f) {
using T = decltype(f(declval<ll>()));
return ranges::seq<T>(b, e, f);
}
template <class F> auto seq(ll n, F const &f) { return seq(0, n, f); }
template <class T = ll> vector<T> vec(size_t n, T const &init = T()) {
return vector<T>(n, init);
}
ll gcd(ll p, ll q) { return (q == 0) ? p : gcd(q, p % q); }
ll lcm(ll p, ll q) { return p / gcd(q, p) * q; }
bool odd(ll n) { return n & 1; }
bool even(ll n) { return !odd(n); }
constexpr ll MOD = 1e9 + 7;
void solve();
int main() {
ll t = 1;
/** input(t); /**/
for ([[maybe_unused]] auto &&i : range(t)) {
solve();
}
}
void f(str const &s, ll m, ll n) {
if (s.size() == n) {
print(s);
return;
}
for (auto &&i : range(m)) {
f(s + to_string(('a' + i)), (i + 'a' == s.back()) ? m : (m + 1), n);
}
}
void solve() {
ll H, W;
input(H, W);
if (H == 1 || W == 1) {
throw 1;
}
ll ans = W * (H / 2) + (((W + 1) / 2) * (H % 2));
print(ans);
}
| // #pragma GCC optimize("O3")
// #pragma GCC target("avx")
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
// Types
using ll = long long int;
using str = string;
template <class T> using u_set = unordered_set<T>;
template <class K, class V> using u_map = unordered_map<K, V>;
template <class V> using graph = u_map<V, u_set<V>>;
namespace io {
// Input
using IS = istream;
IS &in(IS &);
IS &in(IS &i) { return i; }
template <class T, class... Ts> IS &in(IS &i, T &a, Ts &...as) {
return in(i >> a, as...);
}
template <class V> IS &operator>>(IS &i, vector<V> &a) {
for_each(a.begin(), a.end(), [&i](auto &e) { i >> e; });
return i;
}
template <class F, class S> IS &operator>>(IS &i, pair<F, S> &p) {
return in(i, p.first, p.second);
}
template <class... Ts, size_t... I>
IS &tuple_in(IS &i, tuple<Ts...> &t, index_sequence<I...>) {
return in(i, get<I>(t)...);
}
template <class... Ts> IS &operator>>(IS &i, tuple<Ts...> &t) {
return tuple_in(i, t, make_index_sequence<sizeof...(Ts)>());
}
// Output
using OS = ostream;
OS &out(OS &o) { return o << endl; }
template <class T> OS &out(OS &o, T const &a) { return o << a << endl; }
template <class T, class... Ts> OS &out(OS &o, T const &a, Ts const &...as) {
return out(o << a << " ", as...);
}
template <class F, class S> OS &operator<<(OS &o, pair<F, S> const &p) {
return o << p.first << ":" << p.second;
}
template <class... Ts> OS &args_out(OS &o, Ts const &...ts);
OS &args_out(OS &o) { return o; }
template <class T> OS &args_out(OS &o, T const &t) { return o << t; }
template <class T0, class T1, class... Ts>
OS &args_out(OS &o, T0 const &t0, T1 const &t1, Ts const &...ts) {
return args_out(o << t0 << ",", t1, ts...);
}
template <class... Ts, size_t... I>
OS &tuple_out(OS &o, tuple<Ts...> const &t, index_sequence<I...>) {
return args_out(o, get<I>(t)...);
}
template <class... Ts> OS &operator<<(OS &o, tuple<Ts...> const &t) {
return tuple_out(o << "(", t, make_index_sequence<sizeof...(Ts)>()) << ")";
}
template <class T> struct Joiner {
str const pre;
str const post;
str const delim;
vector<T> const container;
Joiner(vector<T> v, str const &delim, str const &pre, str const &post)
: pre(pre), post(post), delim(delim), container(v) {}
};
template <class T> OS &operator<<(OS &o, Joiner<T> const &joiner) {
auto itr = joiner.container.begin();
auto end = joiner.container.end();
o << joiner.pre;
if (itr != end)
o << *(itr++);
while (itr != end)
o << joiner.delim << *(itr++);
return o << joiner.post;
}
template <class Itr, class T = typename iterator_traits<Itr>::value_type>
Joiner<T> join(Itr b, Itr e, str const &delim = ""s, str const &pre = ""s,
str const &post = ""s) {
return Joiner<T>(vector<T>(b, e), delim, pre, post);
}
template <
class C,
class T = typename iterator_traits<typename C::iterator>::value_type,
typename enable_if<!is_same<C, str>::value, nullptr_t>::type = nullptr>
OS &operator<<(OS &o, C const &a) {
return o << join(a.begin(), a.end(), ",", "[", "]");
}
} // namespace io
auto input = [](auto &...a) { io::in(cin, a...); };
auto print = [](auto const &...a) { io::out(cout, a...); };
#ifdef JUMPAKU_DEBUG
auto dump = [](auto const &...a) { io::out(cerr, a...); };
#else
auto dump = [](auto const &...) {};
#endif
using io::join;
// Hash
namespace hashcode {
template <class... Ts> uint64_t hash_args(uint64_t h, Ts const &...ts);
uint64_t hash_args(uint64_t h) { return h; }
template <class T, class... Ts>
uint64_t hash_args(uint64_t h, T const &t, Ts const &...ts) {
constexpr hash<T> hasher;
return hash_args(((h << 19) - h) ^ hasher(t), ts...);
}
template <class... Ts, size_t... I>
uint64_t hash_tuple(tuple<Ts...> const &t, index_sequence<I...>) {
return hash_args(17, get<I>(t)...);
}
} // namespace hashcode
namespace std {
template <class... Ts> struct hash<tuple<Ts...>> {
size_t operator()(tuple<Ts...> const &t) const {
uint64_t h = hashcode::hash_tuple(t, index_sequence_for<Ts...>());
return h ^ (h >> 32);
}
};
} // namespace std
// Range
namespace ranges {
template <class T, class Itr> struct iterator_base {
using difference_type = ll;
using value_type = T;
using pointer = T *;
using reference = T &;
using iterator_category = random_access_iterator_tag;
ll i;
iterator_base(ll const &i = 0) : i(i) {}
bool operator==(Itr const &itr) const { return i == itr.i; }
bool operator!=(Itr const &itr) const { return i != itr.i; }
ll operator-(Itr const &itr) const { return i - itr.i; }
Itr operator++(int) { return with(i++); }
Itr operator--(int) { return with(i--); }
Itr operator+(ll const &n) const { return with(i + n); }
Itr operator-(ll const &n) const { return with(i - n); }
Itr &operator+=(ll const &n) {
i += n;
return self();
}
Itr &operator-=(ll const &n) { return self() += (-n); }
Itr &operator++() { return self() += 1; }
Itr &operator--() { return self() -= 1; }
protected:
virtual Itr with(ll i) const = 0;
virtual Itr &self() = 0;
};
template <class T> struct seq_base {
ll const b;
ll const e;
seq_base(ll b, ll e) : b(b), e(e) {}
ll size() const { return e - b; }
bool empty() const { return size() == 0; }
};
template <class T> struct seq : seq_base<T> {
struct iterator : iterator_base<T, iterator> {
seq<T> const &s;
iterator(seq<T> const &s, ll const &i)
: iterator_base<T, iterator>(i), s(s) {}
iterator with(ll i) const override { return iterator(s, i); }
iterator &self() override { return *this; }
T operator*() const { return s[this->i]; }
iterator &operator=(iterator const &itr) {
this->i = itr.i;
return *this;
}
};
function<T(ll)> const f;
seq(ll b, ll e, function<T(ll)> const &f) : seq_base<T>(b, e), f(f) {}
iterator begin() const { return iterator(*this, 0); }
iterator end() const { return iterator(*this, this->size()); }
T operator[](ll i) const { return f(i + this->b); }
};
struct range : seq_base<ll> {
struct iterator : iterator_base<ll, iterator> {
iterator(ll const &i) : iterator_base<ll, iterator>(i) {}
iterator with(ll i) const override { return iterator(i); }
iterator &self() override { return *this; }
ll operator*() const { return i; }
};
range(ll n) : range(0LL, n) {}
range(ll b, ll e) : seq_base<ll>(b, e) {}
iterator begin() const { return iterator(b); }
iterator end() const { return iterator(e); }
ll operator[](ll i) const { return i + b; }
};
} // namespace ranges
using range = ranges::range;
range::iterator end(ll i) { return range::iterator(i); }
range::iterator begin(ll i) { return range::iterator(i); }
template <class F> auto seq(ll b, ll e, F const &f) {
using T = decltype(f(declval<ll>()));
return ranges::seq<T>(b, e, f);
}
template <class F> auto seq(ll n, F const &f) { return seq(0, n, f); }
template <class T = ll> vector<T> vec(size_t n, T const &init = T()) {
return vector<T>(n, init);
}
ll gcd(ll p, ll q) { return (q == 0) ? p : gcd(q, p % q); }
ll lcm(ll p, ll q) { return p / gcd(q, p) * q; }
bool odd(ll n) { return n & 1; }
bool even(ll n) { return !odd(n); }
constexpr ll MOD = 1e9 + 7;
void solve();
int main() {
ll t = 1;
/** input(t); /**/
for ([[maybe_unused]] auto &&i : range(t)) {
solve();
}
}
void f(str const &s, ll m, ll n) {
if (s.size() == n) {
print(s);
return;
}
for (auto &&i : range(m)) {
f(s + to_string(('a' + i)), (i + 'a' == s.back()) ? m : (m + 1), n);
}
}
void solve() {
ll H, W;
input(H, W);
if (H == 1 || W == 1) {
print(1);
return;
}
ll ans = W * (H / 2) + (((W + 1) / 2) * (H % 2));
print(ans);
}
| replace | 251 | 252 | 251 | 253 | 0 | |
p02742 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define debug(x) \
cout << "DEBUG" \
<< " " << #x << ":" << x << '\n'
// n回繰り返し
#define rep(i, n) for (int i = 0; i < ((int)(n)); i++) // 0-indexed昇順
#define rep1(i, n) for (int i = 1; i <= ((int)(n)); i++) // 1-indexed昇順
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--) // 0-indexed降順
#define rrep1(i, n) for (int i = ((int)(n)); i >= 1; i--) // 1-indexed降順
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii; // 2次元配列
typedef vector<ll> vll;
typedef vector<double> vd;
typedef pair<int, int> PII;
template <typename T> using vec = vector<T>;
template <class T> using maxheap = std::priority_queue<T>;
template <class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template <class T, class U> inline bool chmax(T &a, const U &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T, class U> inline bool chmin(T &a, const U &b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
const ld Pi = std::acos(-1.0L);
const ll infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;
const int mod = 1000000007;
// const int mod = 998244353;
/*FUNCs=================================================*/
/*MAIN==================================================*/
signed main() {
int _StartTime_ = clock();
cin.tie(nullptr);
ios::sync_with_stdio(false); // cin cout 高速化
// cout << fixed << setprecision(15);
ll h, w;
cin >> h >> w;
ll ans = 0;
if (w == 1 || h == 1) {
cout << 1 << '\n';
return 1;
}
rep(i, h) {
if (i % 2 == 0)
ans += (w + 1) / 2;
else
ans += w / 2;
}
cout << ans << '\n';
// printf("ExecutionTime: %d
// /ms\n",1000*(int)((clock()-_StartTime_)/CLOCKS_PER_SEC));
} | #include <bits/stdc++.h>
using namespace std;
#define debug(x) \
cout << "DEBUG" \
<< " " << #x << ":" << x << '\n'
// n回繰り返し
#define rep(i, n) for (int i = 0; i < ((int)(n)); i++) // 0-indexed昇順
#define rep1(i, n) for (int i = 1; i <= ((int)(n)); i++) // 1-indexed昇順
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--) // 0-indexed降順
#define rrep1(i, n) for (int i = ((int)(n)); i >= 1; i--) // 1-indexed降順
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii; // 2次元配列
typedef vector<ll> vll;
typedef vector<double> vd;
typedef pair<int, int> PII;
template <typename T> using vec = vector<T>;
template <class T> using maxheap = std::priority_queue<T>;
template <class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template <class T, class U> inline bool chmax(T &a, const U &b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T, class U> inline bool chmin(T &a, const U &b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
const ld Pi = std::acos(-1.0L);
const ll infll = (1LL << 62) - 1;
const int inf = (1 << 30) - 1;
const int mod = 1000000007;
// const int mod = 998244353;
/*FUNCs=================================================*/
/*MAIN==================================================*/
signed main() {
int _StartTime_ = clock();
cin.tie(nullptr);
ios::sync_with_stdio(false); // cin cout 高速化
// cout << fixed << setprecision(15);
ll h, w;
cin >> h >> w;
ll ans = 0;
if (w == 1 || h == 1) {
cout << 1 << '\n';
return 0;
}
rep(i, h) {
if (i % 2 == 0)
ans += (w + 1) / 2;
else
ans += w / 2;
}
cout << ans << '\n';
// printf("ExecutionTime: %d
// /ms\n",1000*(int)((clock()-_StartTime_)/CLOCKS_PER_SEC));
} | replace | 63 | 64 | 63 | 64 | 0 | |
p02742 | C++ | Runtime Error | #include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
// repマクロ定義
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
// allマクロ定義
#define all(v) v.begin(), v.end()
using namespace std;
int main() {
long long h, w, ans;
cin >> h >> w;
if (h == 1 || w == 1) {
ans = 1;
} else {
ans = (h * w + 1) / 2;
}
cout << ans << endl;
vector<vector<int>> cell(h, vector<int>(h));
} | #include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
// repマクロ定義
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
// allマクロ定義
#define all(v) v.begin(), v.end()
using namespace std;
int main() {
long long h, w, ans;
cin >> h >> w;
if (h == 1 || w == 1) {
ans = 1;
} else {
ans = (h * w + 1) / 2;
}
cout << ans << endl;
} | delete | 19 | 20 | 19 | 19 | 0 | |
p02742 | C++ | Runtime Error | // https://atcoder.jp/contests/abcXXX/tasks/abcXXX_x
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pll = pair<ll, ll>;
static const ll INF = 1001001001;
static const ll LLINF = 1001001001001001001;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define RANGE(i, m, n) for (ll i = (m); i <= (n); ++i)
#define RRANGE(i, m, n) for (ll i = (m); i >= (n); --i)
#define POSITIVE(x) (x) = ((x) < 0) ? 0 : (x)
ll power(ll x, ll y) {
ll ret = 1;
while (y-- > 0)
ret *= x;
return ret;
}
ll gcd(ll a, ll b) {
assert(a >= 0);
assert(b >= 0);
if (b == 0)
return a;
return gcd(b, a % b);
}
ll extgcd(ll a, ll b, ll &x, ll &y) {
x = 1;
y = 0;
assert(a >= 0);
assert(b >= 0);
if (b == 0)
return a;
ll X, Y;
auto d = extgcd(b, a % b, X, Y);
x = Y;
y = X - (a / b) * Y;
return d;
}
int run(istream &in, ostream &out) {
ll H, W;
in >> H >> W;
if (H == 1 || W == 1)
return 1;
ll ans = 0;
auto a = (W + 1) / 2;
auto b = W / 2;
ans = (H + 1) / 2 * a + H / 2 * b;
out << ans << endl;
return 0;
}
int main() { return run(cin, cout); }
| // https://atcoder.jp/contests/abcXXX/tasks/abcXXX_x
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pll = pair<ll, ll>;
static const ll INF = 1001001001;
static const ll LLINF = 1001001001001001001;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define RANGE(i, m, n) for (ll i = (m); i <= (n); ++i)
#define RRANGE(i, m, n) for (ll i = (m); i >= (n); --i)
#define POSITIVE(x) (x) = ((x) < 0) ? 0 : (x)
ll power(ll x, ll y) {
ll ret = 1;
while (y-- > 0)
ret *= x;
return ret;
}
ll gcd(ll a, ll b) {
assert(a >= 0);
assert(b >= 0);
if (b == 0)
return a;
return gcd(b, a % b);
}
ll extgcd(ll a, ll b, ll &x, ll &y) {
x = 1;
y = 0;
assert(a >= 0);
assert(b >= 0);
if (b == 0)
return a;
ll X, Y;
auto d = extgcd(b, a % b, X, Y);
x = Y;
y = X - (a / b) * Y;
return d;
}
int run(istream &in, ostream &out) {
ll H, W;
in >> H >> W;
if (H == 1 || W == 1) {
out << 1 << endl;
return 0;
}
ll ans = 0;
auto a = (W + 1) / 2;
auto b = W / 2;
ans = (H + 1) / 2 * a + H / 2 * b;
out << ans << endl;
return 0;
}
int main() { return run(cin, cout); }
| replace | 60 | 62 | 60 | 64 | 0 | |
p02742 | C++ | Runtime Error | /* ꧁༒☬महाकाल☬༒꧂ ꧁༒ঔमहाकालঔ༒꧂
ঔৣमहाकालᴳᵒᵈঔৣ
*/
#include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// template <typename T, typename cmp=less<T>> using oset =tree<T, null_type,
// cmp, rb_tree_tag, tree_order_statistics_node_update>;
#define ll long long
#define mod 1000000007
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define _it iterator
#define all(_x) _x.begin(), _x.end()
#define f first
#define s second
#define pb push_back
void mahakal() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
freopen("error.txt", "w", stderr);
#endif
}
int main() {
mahakal(), fast;
ll n, m;
cin >> n >> m;
ll ans = ceil(n * m / 2.0);
cout << ans << endl;
return 0;
} | /* ꧁༒☬महाकाल☬༒꧂ ꧁༒ঔमहाकालঔ༒꧂
ঔৣमहाकालᴳᵒᵈঔৣ
*/
#include <bits/stdc++.h>
using namespace std;
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// template <typename T, typename cmp=less<T>> using oset =tree<T, null_type,
// cmp, rb_tree_tag, tree_order_statistics_node_update>;
#define ll long long
#define mod 1000000007
#define fast \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
#define _it iterator
#define all(_x) _x.begin(), _x.end()
#define f first
#define s second
#define pb push_back
void mahakal() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
freopen("error.txt", "w", stderr);
#endif
}
int main() {
// mahakal(),fast;
ll n, m, mm, nn;
cin >> nn >> mm;
if (nn == 1 || mm == 1) {
cout << 1 << endl;
return 0;
}
n = max(nn, mm);
m = min(nn, mm);
ll st = (n - 1) / 2 + 1;
ll nd = (n - 2) / 2 + 1;
ll ans = (ll)ceil(m / 2.0) * st + (m / 2) * nd;
cout << ans << endl;
return 0;
} | replace | 31 | 35 | 31 | 44 | 0 | |
p02742 | Python | Runtime Error | import math
h, w = map(int, input().split())
if h == 1 or w == 1:
print(1)
elif (h * w) % 2 == 0:
ans = (h * w) // 2
else:
ans = (h // 2) * w + math.ceil(w / 2)
print(ans)
| import math
h, w = map(int, input().split())
if h == 1 or w == 1:
ans = 1
elif (h * w) % 2 == 0:
ans = (h * w) // 2
else:
ans = (h // 2) * w + math.ceil(w / 2)
print(ans)
| replace | 5 | 6 | 5 | 6 | 0 | |
p02742 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
int main() {
ios ::sync_with_stdio(false);
cin.tie(0);
long long n, m, s;
cin >> n >> m;
s = n * m;
if (n == 1 or m == 1)
return 1;
cout << (s % 2 == 0 ? s / 2 : (s / 2) + 1);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int main() {
ios ::sync_with_stdio(false);
cin.tie(0);
long long n, m, s;
cin >> n >> m;
s = n * m;
if (n == 1 or m == 1)
cout << 1;
else
cout << (s % 2 == 0 ? s / 2 : (s / 2) + 1);
return 0;
} | replace | 10 | 12 | 10 | 13 | 0 | |
p02743 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using vi = vector<int>;
using P = pair<int, int>;
using Graph = vector<vector<int>>;
using ld = long double;
const ld eps = 1.0e-9; // 許容される誤差
ld mysqrtl(ld x) {
ld a = sqrt((double)x); // 近似値
do {
a = (a + x / a) / 2.0L;
} while (fabsl(x - a * a) > eps);
return a;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ld a, b, c;
cin >> a >> b >> c;
ld d = 2 * mysqrtl(a * b);
if (a + b + d < c) {
cout << "Yes"
<< "\n";
return 0;
} else {
cout << "No"
<< "\n";
return 0;
}
} | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using vi = vector<int>;
using P = pair<int, int>;
using Graph = vector<vector<int>>;
using ld = long double;
const ld eps = 1.0e-9; // 許容される誤差
ld mysqrtl(ld x) {
ld a = sqrt((double)x); // 近似値
do {
a = (a + x / a) / 2.0L;
} while (fabsl(x - a * a) > eps);
return a;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
ld a, b, c;
cin >> a >> b >> c;
ld eps = 1.0E-14;
if (sqrt(a) + sqrt(b) + eps < sqrt(c)) {
cout << "Yes"
<< "\n";
return 0;
} else {
cout << "No"
<< "\n";
return 0;
}
} | replace | 24 | 26 | 24 | 26 | TLE | |
p02743 | Python | Runtime Error | a, b, c = input().split()
if c - a - b > 0:
if 4 * a * b < (c - a - b) ** 2:
print("Yes")
else:
print("No")
else:
print("No")
| a, b, c = map(int, input().split())
if c - a - b > 0:
if 4 * a * b < (c - a - b) ** 2:
print("Yes")
else:
print("No")
else:
print("No")
| replace | 0 | 1 | 0 | 1 | TypeError: unsupported operand type(s) for -: 'str' and 'str' | Traceback (most recent call last):
File "/home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02743/Python/s899697147.py", line 3, in <module>
if c - a - b > 0:
TypeError: unsupported operand type(s) for -: 'str' and 'str'
|
p02743 | C++ | Runtime Error | #include <bits/stdc++.h>
int main() {
using namespace std;
unsigned long a, b, c;
cin >> a >> b >> c;
unsigned long k{4 * a * b}, l{max(a + b, c) - min(a + b, c)};
if (k == l * l)
abort();
puts(k < l * l ? "Yes" : "No");
return 0;
} | #include <bits/stdc++.h>
int main() {
using namespace std;
unsigned long a, b, c;
cin >> a >> b >> c;
unsigned long k{4 * a * b}, l{c - a - b};
puts(a + b < c && k < l * l ? "Yes" : "No");
return 0;
} | replace | 6 | 10 | 6 | 8 | 0 | |
p02743 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ll a, b, c;
cin >> a >> b >> c;
auto f = [](long double d) {
long double a = sqrt((double)d);
do {
a = (a + d / a) / 2.0L;
} while (fabsl(d - a * a) > (long double)1.0e-9);
return a;
};
long double x = f(a * b) * 2.0L;
bool yes = x < (long double)(c - a - b);
if (yes)
cout << "Yes" << endl;
else
cout << "No" << endl;
} | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ll a, b, c;
cin >> a >> b >> c;
long double x = sqrt((long double)(4 * a * b));
bool yes = x < (long double)(c - a - b);
if (yes)
cout << "Yes" << endl;
else
cout << "No" << endl;
} | replace | 8 | 17 | 8 | 9 | TLE | |
p02743 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define fr(i, a, b) for (int i = a; i < b; i++)
#define bfr(i, a, b) for (int i = a; i >= b; i--)
#define fio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL), cout.tie(NULL);
#define tc \
int t; \
cin >> t; \
while (t--)
#define mod 1000000007
#define all(vec) vec.begin(), vec.end()
#define ld long double
int main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
fio
lli a,
b, c;
cin >> a >> b >> c;
if (a >= c || b >= c)
cout << "No";
else if (2 * sqrtl(a * b) < c - b - a)
cout << "Yes";
else
cout << "No";
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define fr(i, a, b) for (int i = a; i < b; i++)
#define bfr(i, a, b) for (int i = a; i >= b; i--)
#define fio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL), cout.tie(NULL);
#define tc \
int t; \
cin >> t; \
while (t--)
#define mod 1000000007
#define all(vec) vec.begin(), vec.end()
#define ld long double
int main() {
fio
lli a,
b, c;
cin >> a >> b >> c;
if (a >= c || b >= c)
cout << "No";
else if (2 * sqrtl(a * b) < c - b - a)
cout << "Yes";
else
cout << "No";
return 0;
} | delete | 18 | 23 | 18 | 18 | 0 | |
p02743 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
const long double eps = 1.0e-10;
long double mysqrt(long double x) {
long double a = sqrt(x);
do {
a = (a + x / a) / 2.0L;
} while (fabsl(x - a * a) > eps);
return a;
}
int main() {
long double a, b, c;
string ans;
cin >> a >> b >> c;
long double sqsum = mysqrt(a * b);
if ((long double)(a + b) + 2 * sqsum < c) {
ans = "Yes";
}
else
ans = "No";
cout << ans << endl;
return 0;
} | #include <bits/stdc++.h>
using namespace std;
const long double eps = 1.0e-10;
long double mysqrt(long double x) {
long double a = sqrt(x);
do {
a = (a + x / a) / 2.0L;
} while (fabsl(x - a * a) > eps);
return a;
}
int main() {
long double a, b, c;
string ans;
cin >> a >> b >> c;
long double sqsum = mysqrt(a) * mysqrt(b);
if ((long double)(a + b) + 2 * sqsum < c) {
ans = "Yes";
}
else
ans = "No";
cout << ans << endl;
return 0;
} | replace | 21 | 22 | 21 | 22 | TLE | |
p02743 | C++ | Runtime Error | #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
int main() {
int64_t a, b, c;
cin >> a >> b >> c;
if (a == b)
cout << (2 * (a + b) < c ? "Yes" : "No") << '\n';
assert(a == b);
return 0;
}
| #include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
int main() {
int64_t a, b, c;
cin >> a >> b >> c;
if (a == b)
cout << (2 * (a + b) < c ? "Yes" : "No") << '\n';
else {
if (2 * (a + b) <= c) {
cout << "Yes" << '\n';
} else {
cout << (sqrt(a) + sqrt(b) < sqrt(c) ? "Yes" : "No") << '\n';
}
}
return 0;
}
| replace | 9 | 10 | 9 | 16 | -6 | c4d3f54b-3e00-4444-8898-160a0c52f6c5.out: /home/alex/Documents/bug-detection/input/Project_CodeNet/data/p02743/C++/s711826243.cpp:9: int main(): Assertion `a == b' failed.
|
p02743 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define IOS \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define int long long int
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<vector<int>> vvi;
typedef unordered_map<int, int> uoii;
typedef unordered_map<string, int> uosi;
const int MOD = 1e9 + 7;
const int INF = 1e10;
int32_t main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
IOS double x, y, z;
cin >> x >> y >> z;
double xx = 2 * sqrt(y * x);
if (x + y + xx < z)
cout << "Yes";
else
cout << "No";
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
#define IOS \
ios::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0);
#define int long long int
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef vector<vector<int>> vvi;
typedef unordered_map<int, int> uoii;
typedef unordered_map<string, int> uosi;
const int MOD = 1e9 + 7;
const int INF = 1e10;
int32_t main() {
IOS int a, b, c;
cin >> a >> b >> c;
int d = c - a - b;
if (d > 0 && 4 * a * b < (c - a - b) * (c - a - b)) {
cout << "Yes\n";
} else {
cout << "No\n";
}
return 0;
}
| replace | 27 | 38 | 27 | 36 | 0 | |
p02743 | C++ | Runtime Error | #include <bits/stdc++.h>
#define N 100005
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define ll long long
using namespace std;
ll a, b, c;
int main() {
ios_base::sync_with_stdio(0);
cin.tie();
cout.tie();
freopen("C.inp", "r", stdin);
freopen("C.out", "w", stdout);
cin >> a >> b >> c;
ll d = c - a - b;
if (d > 0 && d * d > 4 * a * b)
cout << "Yes";
else
cout << "No";
}
| #include <bits/stdc++.h>
#define N 100005
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define ll long long
using namespace std;
ll a, b, c;
int main() {
ios_base::sync_with_stdio(0);
cin.tie();
cout.tie();
cin >> a >> b >> c;
ll d = c - a - b;
if (d > 0 && d * d > 4 * a * b)
cout << "Yes";
else
cout << "No";
}
| replace | 11 | 13 | 11 | 12 | 0 | |
p02743 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
typedef long double ld;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define F first
#define S second
const int mx = 200010;
const ll mod = 1e9 + 7;
const ld eps = 1.0e-18; // 許容される誤差
ld mysqrtl(ld x) {
ld a = sqrt((double)x); // 近似値
do {
a = (a + x / a) / 2.0L;
} while (fabsl(x - a * a) > eps);
return a;
}
int main() {
ld a, b, c;
cin >> a >> b >> c;
if (mysqrtl(a) + mysqrtl(b) < mysqrtl(c)) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> P;
typedef long long ll;
typedef long double ld;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
#define REP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define F first
#define S second
const int mx = 200010;
const ll mod = 1e9 + 7;
const ld eps = 1.0e-18; // 許容される誤差
ld mysqrtl(ld x) {
ld a = sqrt((double)x); // 近似値
do {
a = (a + x / a) / 2.0L;
} while (fabsl(x - a * a) > eps);
return a;
}
int main() {
ld a, b, c;
cin >> a >> b >> c;
if (a + 2 * sqrt(a * b) + b < c) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
return 0;
} | replace | 28 | 29 | 28 | 29 | TLE | |
p02743 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using P = pair<ll, ll>;
template <typename T> using pq = priority_queue<T>;
template <typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template <typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for (ll i = ll(n - 1); i >= 0; i--)
#define each(i, mp) for (auto &i : mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()
template <class T> ostream &operator<<(ostream &out, const vector<T> &list) {
ll n = list.size();
rep(i, n) out << list[i] << ' ';
return out;
}
template <class T> istream &operator>>(istream &in, vector<T> &list) {
ll n = list.size();
rep(i, n) in >> list[i];
return in;
}
template <class T>
ostream &operator<<(ostream &out, const vector<vector<T>> &list) {
ll n = list.size();
rep(i, n) out << list[i] << '\n';
return out;
}
/* ------------- ANSWER ------------- */
/* ---------------------------------- */
const long double eps = 1.0e-6; // 許容される誤差
long double mysqrtl(long double x) {
long double a = sqrt((double)x); // 近似値
do {
a = (a + x / a) / 2.0L;
} while (fabsl(x - a * a) > eps);
return a;
}
void solve() {
long double a, b, c;
cin >> a >> b >> c;
if (a / 2 + b / 2 + mysqrtl(a * b) < c / 2) {
cout << "Yes" << '\n';
} else {
cout << "No" << '\n';
}
}
int main() {
#ifdef MY_DEBUG
while (true) {
#endif
solve();
#ifdef MY_DEBUG
}
#endif
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using P = pair<ll, ll>;
template <typename T> using pq = priority_queue<T>;
template <typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template <typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for (ll i = ll(n - 1); i >= 0; i--)
#define each(i, mp) for (auto &i : mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()
template <class T> ostream &operator<<(ostream &out, const vector<T> &list) {
ll n = list.size();
rep(i, n) out << list[i] << ' ';
return out;
}
template <class T> istream &operator>>(istream &in, vector<T> &list) {
ll n = list.size();
rep(i, n) in >> list[i];
return in;
}
template <class T>
ostream &operator<<(ostream &out, const vector<vector<T>> &list) {
ll n = list.size();
rep(i, n) out << list[i] << '\n';
return out;
}
/* ------------- ANSWER ------------- */
/* ---------------------------------- */
const long double eps = 1.0e-6; // 許容される誤差
long double mysqrtl(long double x) {
long double a = sqrt((double)x); // 近似値
do {
a = (a + x / a) / 2.0L;
} while (fabsl(x - a * a) > eps);
return a;
}
void solve() {
long double a, b, c;
cin >> a >> b >> c;
if (a / 2 + b / 2 + mysqrtl(a) * mysqrtl(b) < c / 2) {
cout << "Yes" << '\n';
} else {
cout << "No" << '\n';
}
}
int main() {
#ifdef MY_DEBUG
while (true) {
#endif
solve();
#ifdef MY_DEBUG
}
#endif
return 0;
}
| replace | 61 | 62 | 61 | 62 | TLE | |
p02743 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
#define pb push_back
#define f(i, n) for (i = 0; i < n; i++)
#define F(i, a, b) for (i = a; a <= b; i++)
#define arr(a, n) \
for (i = 0; i < n; i++) \
cin >> a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a, a + n);
#define sr() sort(a, a + n, greater<ll>());
#define v() sort(v.begin(), v.end());
#define vr() sort(v.begin(), v.end(), greater<ll>());
#define mod 1000000007
#define fast() \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
ll gcd(ll a, ll b) {
if (!b)
return a;
return gcd(b, a % b);
}
ll power(ll x, ll y, ll p) {
ll res = 1;
x %= p;
while (y > 0) {
if (y & 1)
res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
int main() {
#ifndef ONLINE_JUDGE
// for getting input from input.txt
freopen("input.txt", "r", stdin);
// for writing output to output.txt
freopen("output.txt", "w", stdout);
#endif
/*
Ofcourse it's Hard.
It's supposed to be Hard.
If it's easy everyone would do it.
HARD IS WHAT MAKES IT GREAT
YESTERDAY U SAID TOMORROW
SLOWLY BECOMING THE PERSON I
SHOULD HAVE BEEN A LONG TIME AGO
SAME TASK CAN'T BE FOUND DIFFICULT TWICE
BTBHWSITW
SPRH TU KAB P
IT ALWAYS SEEMS IMPOSSIBLE
UNTIL ITS DONE ->WILLIAM LIN
*/
fast();
// ll t;cin>>t>>while(t--)
{
long double a, b, c;
cin >> a >> b >> c;
if ((2 * sqrt(a * b)) < (c - a - b))
Yes
else No
}
return 0;
} | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
#define pb push_back
#define f(i, n) for (i = 0; i < n; i++)
#define F(i, a, b) for (i = a; a <= b; i++)
#define arr(a, n) \
for (i = 0; i < n; i++) \
cin >> a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;
#define yes cout << "yes" << endl;
#define no cout << "no" << endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a, a + n);
#define sr() sort(a, a + n, greater<ll>());
#define v() sort(v.begin(), v.end());
#define vr() sort(v.begin(), v.end(), greater<ll>());
#define mod 1000000007
#define fast() \
ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
ll gcd(ll a, ll b) {
if (!b)
return a;
return gcd(b, a % b);
}
ll power(ll x, ll y, ll p) {
ll res = 1;
x %= p;
while (y > 0) {
if (y & 1)
res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
int main() {
/*#ifndef ONLINE_JUDGE
// for getting input from input.txt
freopen("input.txt", "r", stdin);
// for writing output to output.txt
freopen("output.txt", "w", stdout);
#endif*/
/*
Ofcourse it's Hard.
It's supposed to be Hard.
If it's easy everyone would do it.
HARD IS WHAT MAKES IT GREAT
YESTERDAY U SAID TOMORROW
SLOWLY BECOMING THE PERSON I
SHOULD HAVE BEEN A LONG TIME AGO
SAME TASK CAN'T BE FOUND DIFFICULT TWICE
BTBHWSITW
SPRH TU KAB P
IT ALWAYS SEEMS IMPOSSIBLE
UNTIL ITS DONE ->WILLIAM LIN
*/
fast();
// ll t;cin>>t>>while(t--)
{
long double a, b, c;
cin >> a >> b >> c;
if ((2 * sqrt(a * b)) < (c - a - b))
Yes
else No
}
return 0;
} | replace | 51 | 57 | 51 | 57 | 0 | |
p02744 | C++ | Runtime Error | #include <bits/stdc++.h>
#define pf printf
#define sc(x) scanf("%d", &x);
#define scs(x) scanf("%s", x);
#define scl(x) scanf("%lld", &x);
#define rep(i, s, e) for (int i = s; i <= e; ++i)
#define dep(i, s, e) for (int i = s; i >= e; --i)
typedef long long ll;
using namespace std;
int end, k;
char s[100];
void solve(int end) {
char v = 'a';
rep(i, 1, end - 1) if (v < s[i]) v = s[i];
rep(i, 0, v - 'a' + 1) {
s[end] = 'a' + i;
if (end == k)
pf("%s\n", s + 1);
else
solve(end + 1);
}
}
int main() {
sc(k);
s[1] = 'a';
solve(2);
} | #include <bits/stdc++.h>
#define pf printf
#define sc(x) scanf("%d", &x);
#define scs(x) scanf("%s", x);
#define scl(x) scanf("%lld", &x);
#define rep(i, s, e) for (int i = s; i <= e; ++i)
#define dep(i, s, e) for (int i = s; i >= e; --i)
typedef long long ll;
using namespace std;
int end, k;
char s[100];
void solve(int end) {
char v = 'a';
rep(i, 1, end - 1) if (v < s[i]) v = s[i];
rep(i, 0, v - 'a' + 1) {
s[end] = 'a' + i;
if (end == k)
pf("%s\n", s + 1);
else
solve(end + 1);
}
}
int main() {
sc(k);
s[1] = 'a';
if (k == 1) {
pf("%s\n", s + 1);
return 0;
}
solve(2);
} | insert | 25 | 25 | 25 | 29 | -11 | |
p02744 | C++ | Time Limit Exceeded | #include <bits/stdc++.h>
using namespace std;
int N;
void dfs(string s) {
if (s.length() == N) {
cout << s << endl;
return;
}
char moji = 'a';
for (char c : s) {
moji = max(c, moji);
}
for (char str = 'a'; str <= moji + 1; str++) {
s += str;
dfs(s);
}
}
int main() {
cin >> N;
string s = "a";
dfs(s);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
int N;
void dfs(string s) {
if (s.length() == N) {
cout << s << endl;
return;
}
char moji = 'a';
for (char c : s) {
moji = max(c, moji);
}
for (char str = 'a'; str <= moji + 1; str++) {
dfs(s + str);
}
}
int main() {
cin >> N;
string s = "a";
dfs(s);
return 0;
} | replace | 14 | 16 | 14 | 16 | TLE | |
p02744 | C++ | Runtime Error | #include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> llP;
ll mod(ll a, ll b) {
ll ret = a % b;
if (ret < 0)
ret += b;
return ret;
}
ll modpow(ll a, ll b, ll c) {
ll res = 1;
while (b > 0) {
if (b & 1)
res = mod(res * a, c);
a = mod(a * a, c);
b >>= 1;
}
return res;
}
void dfs(char c, int n, string s) {
if (s.size() == n) {
cout << s << endl;
}
for (char h = 'a'; h <= (c - 'a') + 1 + 'a'; h = h - 'a' + 1 + 'a') {
if (h < (c - 'a') + 1 + 'a')
dfs(c, n, s + h);
else
dfs(c + 1, n, s + h);
}
}
int main() {
int n;
cin >> n;
dfs('a', n, "a");
return 0;
} | #include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> llP;
ll mod(ll a, ll b) {
ll ret = a % b;
if (ret < 0)
ret += b;
return ret;
}
ll modpow(ll a, ll b, ll c) {
ll res = 1;
while (b > 0) {
if (b & 1)
res = mod(res * a, c);
a = mod(a * a, c);
b >>= 1;
}
return res;
}
void dfs(char c, int n, string s) {
if (s.size() == n) {
cout << s << endl;
} else {
for (char h = 'a'; h <= (c - 'a') + 1 + 'a'; h = (h - 'a') + 1 + 'a') {
if (h < (c - 'a') + 1 + 'a')
dfs(c, n, s + h);
else
dfs(c + 1, n, s + h);
}
}
}
int main() {
int n;
cin >> n;
dfs('a', n, "a");
return 0;
} | replace | 28 | 34 | 28 | 35 | -6 | terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
|
p02744 | C++ | Runtime Error | #include <algorithm>
#include <array>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctype.h>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <unordered_map>
#include <utility>
#include <vector>
#define _USE_MATH_DEFINES
#include <iostream>
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, double> pld;
typedef pair<double, double> pdd;
typedef pair<double, ll> pdl;
typedef pair<int, char> pic;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef priority_queue<ll, vector<ll>, greater<ll>> llgreaterq;
typedef priority_queue<pll, vector<pll>, greater<pll>> pllgreaterq;
typedef priority_queue<pair<ll, pll>, vector<pair<ll, pll>>,
greater<pair<ll, pll>>>
plpllgreaterq;
typedef priority_queue<vi, vector<vi>, greater<vi>> vigreaterq;
typedef priority_queue<vl, vector<vl>, greater<vl>> vlgreaterq;
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};
#define bit(x, v) ((ll)x << v)
#define rep(x, n) for (int x = 0; x < n; x++)
#define rep2(x, f, v) for (int x = f; x < v; x++)
// 許容する誤差ε
#define EPS (1e-10)
// 2つのスカラーが等しいかどうか
#define EQ(a, b) (std::abs(a - b) < EPS)
// 2つのベクトルが等しいかどうか
#define EQV(a, b) (EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()))
#define all(a) a.begin(), a.end()
#define all0(a) memset(a, 0, sizeof(a))
#define alm1(a) memset(a, -1, sizeof(a))
const ll INF = 1000000007;
const int MAX = 1000010;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; 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;
}
}
// 二項係数計算
long long COM(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;
}
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
int pr[100010];
int lank[100010];
void uini(int n) {
for (size_t i = 0; i <= n; i++) {
pr[i] = i;
lank[i] = 1;
}
}
int parent(int x) {
if (x == pr[x])
return x;
return pr[x] = parent(pr[x]);
}
int same(int x, int y) { return parent(x) == parent(y); }
bool unit(int x, int y) {
int px = parent(x);
int py = parent(y);
if (px == py)
return false;
if (lank[py] < lank[px]) {
pr[py] = px;
lank[px] += lank[py];
} else {
pr[px] = py;
lank[py] += lank[px];
}
return true;
}
ll bit[200010];
int max_n = 200000;
int pm = 0;
void add(int x) {
while (max_n >= x) {
bit[x]++;
x += x & -x;
}
}
void sub(int x) {
while (max_n >= x) {
bit[x]--;
x += x & -x;
}
}
ll merge(ll *a, int left, int mid, int right) {
ll n1 = mid - left;
ll n2 = right - mid;
vector<int> L(n1 + 1);
vector<int> R(n2 + 1);
for (size_t i = 0; i < n1; i++) {
L[i] = a[left + i];
}
for (size_t i = 0; i < n2; i++) {
R[i] = a[mid + i];
}
L[n1] = INF;
R[n2] = INF;
ll i = 0;
ll j = 0;
ll r = 0;
for (size_t k = left; k < right; k++) {
if (L[i] <= R[j]) {
a[k] = L[i];
i++;
} else {
a[k] = R[j];
r += n1 - i;
j++;
}
}
return r;
}
ll merge2(pair<int, char> *a, int left, int mid, int right) {
ll n1 = mid - left;
ll n2 = right - mid;
vector<pair<int, char>> L(n1 + 1);
vector<pair<int, char>> R(n2 + 1);
for (size_t i = 0; i < n1; i++) {
L[i] = a[left + i];
}
for (size_t i = 0; i < n2; i++) {
R[i] = a[mid + i];
}
L[n1] = make_pair(INF, ' ');
R[n2] = make_pair(INF, ' ');
ll i = 0;
ll j = 0;
ll r = 0;
for (size_t k = left; k < right; k++) {
if (L[i].first <= R[j].first) {
a[k] = L[i];
i++;
} else {
a[k] = R[j];
r += n1 - i;
j++;
}
}
return r;
}
ll mergeSort2(pair<int, char> *a, int left, int right) {
ll res = 0;
if (left + 1 < right) {
int mid = (left + right) / 2;
res = mergeSort2(a, left, mid);
res += mergeSort2(a, mid, right);
res += merge2(a, left, mid, right);
}
return res;
}
ll mergeSort(ll *a, int left, int right) {
ll res = 0;
if (left + 1 < right) {
int mid = (left + right) / 2;
res = mergeSort(a, left, mid);
res += mergeSort(a, mid, right);
res += merge(a, left, mid, right);
}
return res;
}
int partition(pair<int, char> *a, int p, int r) {
pair<int, char> x = a[r];
int i = p - 1;
for (size_t j = p; j < r; j++) {
if (a[j].first <= x.first) {
i++;
swap(a[i], a[j]);
}
}
swap(a[i + 1], a[r]);
return i + 1;
}
void quick(pair<int, char> *a, int p, int r) {
if (p < r) {
int q = partition(a, p, r);
quick(a, p, q - 1);
quick(a, q + 1, r);
}
}
ll n;
int ci = 0;
ll P[1000010];
struct Node {
int key;
int priority;
Node *parent, *left, *right;
Node(int key, int priority);
Node() {}
};
Node NIL;
Node::Node(int key, int priority) : key(key), priority(priority) {
left = &NIL;
right = &NIL;
}
Node *root = new Node();
void cenrec(Node *k) {
if (k->key == NIL.key)
return;
cenrec(k->left);
cout << " " << k->key;
cenrec(k->right);
}
void fastrec(Node *k) {
if (k->key == NIL.key)
return;
cout << " " << k->key;
fastrec(k->left);
fastrec(k->right);
}
void insert(Node *v) {
Node *y = &NIL;
Node *x = root;
while (x->key != NIL.key) {
y = x;
if (v->key < x->key) {
x = x->left;
} else {
x = x->right;
}
}
v->parent = y;
if (y->key == NIL.key) {
root = v;
} else if (v->key < y->key) {
y->left = v;
} else {
y->right = v;
}
}
Node *find(Node *k, ll v) {
if (k->key == NIL.key)
return &NIL;
if (k->key == v)
return k;
if (v < k->key)
return find(k->left, v);
return find(k->right, v);
}
void delp12(Node *x) {
if (x->key == NIL.key)
return;
Node *l = x->left;
Node *r = x->right;
Node *pr = x->parent;
if (l->key == NIL.key && r->key == NIL.key) {
if (pr->left == x) {
pr->left = &NIL;
} else
pr->right = &NIL;
} else if (l->key != NIL.key) {
if (pr->left == x) {
pr->left = l;
} else
pr->right = l;
l->parent = pr;
} else if (r->key != NIL.key) {
if (pr->left == x) {
pr->left = r;
} else
pr->right = r;
r->parent = pr;
}
}
Node *get_next(Node *k) {
if (k->key == NIL.key)
return &NIL;
Node *res = get_next(k->left);
if (res->key != NIL.key)
return res;
return k;
}
void del(Node *x) {
if (x->key == NIL.key)
return;
Node *l = x->left;
Node *r = x->right;
Node *pr = x->parent;
if (l->key != NIL.key && r->key != NIL.key) {
Node *nex = get_next(r);
x->key = nex->key;
delp12(nex);
} else {
delp12(x);
}
}
Node *rightRotate(Node *t) {
Node *s = t->left;
t->left = s->right;
s->right = t;
return s;
}
Node *leftRotate(Node *t) {
Node *s = t->right;
t->right = s->left;
s->left = t;
return s;
}
Node *_insert(Node *t, int key, int priority) {
if (t->key == NIL.key) {
return new Node(key, priority);
}
if (key == t->key) {
return t;
}
if (key < t->key) {
t->left = _insert(t->left, key, priority);
if (t->priority < t->left->priority) {
t = rightRotate(t);
}
} else {
t->right = _insert(t->right, key, priority);
if (t->priority < t->right->priority) {
t = leftRotate(t);
}
}
return t;
}
Node *delete1(Node *t, int key);
Node *_delete(Node *t, int key) {
if (t->left->key == NIL.key && t->right->key == NIL.key) {
return &NIL;
} else if (t->left->key == NIL.key) {
t = leftRotate(t);
} else if (t->right->key == NIL.key) {
t = rightRotate(t);
} else {
if (t->left->priority > t->right->priority) {
t = rightRotate(t);
} else
t = leftRotate(t);
}
return delete1(t, key);
}
Node *delete1(Node *t, int key) {
if (t->key == NIL.key) {
return &NIL;
}
if (key < t->key) {
t->left = delete1(t->left, key);
} else if (key > t->key) {
t->right = delete1(t->right, key);
} else
return _delete(t, key);
return t;
}
int H;
int left(int i) { return i * 2 + 1; }
int right(int i) { return i * 2 + 2; }
struct edge {
int from, to;
ll val;
edge(int from, int to, ll val) : from(from), to(to), val(val) {}
};
int k;
int _rank[1010];
int temp[1010];
bool compare_sa(int i, int j) {
if (_rank[i] != _rank[j])
return _rank[i] < _rank[j];
else {
int ri = i + k <= n ? _rank[i + k] : -1;
int rj = j + k <= n ? _rank[j + k] : -1;
return ri < rj;
}
}
void construct_sa(string S, int *sa) {
n = S.length();
for (size_t i = 0; i <= n; i++) {
sa[i] = i;
_rank[i] = i < n ? S[i] : -1;
}
for (k = 1; k <= n; k *= 2) {
sort(sa, sa + n + 1, compare_sa);
// saはソート後の接尾辞の並びになっている、rankは元の位置のindexを保持したまま、更新されている。
// ピンとこなかった部分
temp[sa[0]] = 0;
for (size_t i = 1; i <= n; i++) {
temp[sa[i]] = temp[sa[i - 1]] + (compare_sa(sa[i - 1], sa[i]) ? 1 : 0);
}
for (size_t i = 0; i <= n; i++) {
_rank[i] = temp[i];
}
}
}
bool contain(string S, int *sa, string T) {
int a = 0, b = S.length();
// sa は 接尾辞が辞書順に並んでいる、入っているのはその位置のインデックス
while (b - a > 1) {
int c = (a + b) / 2;
if (S.compare(sa[c], T.length(), T) < 0)
a = c;
else
b = c;
}
return S.compare(sa[b], T.length(), T) == 0;
}
#define bit(x, v) ((ll)x << v)
class BIT {
static const int MAX_N = 500010;
public:
BIT() { memset(bit, 0, sizeof(bit)); }
ll bit[MAX_N + 1], n;
ll sum(int i) {
ll s = 0;
while (i > 0) {
s += bit[i];
i -= i & -i;
}
return s;
}
void add(int i, int x) {
while (i <= n) {
bit[i] += x;
i += i & -i;
}
}
};
struct UnionFind {
vector<int> A;
UnionFind(int n) : A(n, -1) {}
int find(int x) {
if (A[x] < 0)
return x;
return A[x] = find(A[x]);
}
void unite(int x, int y) {
x = find(x), y = find(y);
if (x == y)
return;
if (A[x] > A[y])
swap(x, y);
A[x] += A[y];
A[y] = x;
}
int ngroups() {
int ans = 0;
for (auto a : A)
if (a < 0)
ans++;
return ans;
}
};
void yes() {
cout << "Yes\n";
exit(0);
}
void no() {
cout << "No\n";
exit(0);
}
vector<ll> getp(ll n) {
vector<ll> res;
ll a = 2;
if (n % 2 == 0) {
res.push_back(2);
while (n % 2 == 0)
n /= 2;
}
for (ll i = 3; i * i <= n; i += 2) {
if (n % i == 0) {
res.push_back(i);
while (n % i == 0)
n /= i;
}
}
if (n != 1)
res.push_back(n);
return res;
}
vector<ll> getp2(ll n) {
vector<ll> res;
ll a = 2;
if (n % 2 == 0) {
while (n % 2 == 0) {
n /= 2;
res.push_back(2);
}
}
for (ll i = 3; i * i <= n; i += 2) {
if (n % i == 0) {
while (n % i == 0) {
n /= i;
res.push_back(i);
}
}
}
if (n != 1)
res.push_back(n);
return res;
}
vector<pll> getp3(ll n) {
vector<pll> res;
ll a = 2;
int si = 0;
if (n % 2 == 0) {
res.push_back(make_pair(2, 0));
while (n % 2 == 0) {
n /= 2;
res[si].second++;
}
si++;
}
for (ll i = 3; i * i <= n; i += 2) {
if (n % i == 0) {
res.push_back(make_pair(i, 0));
while (n % i == 0) {
n /= i;
res[si].second++;
}
si++;
}
}
if (n != 1) {
res.push_back(make_pair(n, 1));
}
return res;
}
vector<ll> getDivisors(ll n) {
vector<ll> res;
ll a = 2;
res.push_back(1);
for (ll i = 2; i * i <= n; i++) {
if (n % i == 0) {
res.push_back(i);
if (n / i != i)
res.push_back(n / i);
}
}
return res;
}
struct ve {
public:
vector<ve> child;
int _t = INF;
ve(int t) : _t(t) {}
ve(ve _left, ve _right) {
_t = _left._t + _right._t;
child.push_back(_left);
child.push_back(_right);
}
bool operator<(const ve &t) const { return _t > t._t; }
};
vector<bool> elas(ll n) {
vector<bool> r(n);
fill(r.begin(), r.end(), 1);
r[0] = 0;
r[1] = 0;
for (ll i = 2; i * i < n; i++) {
if (!r[i])
continue;
ll ti = i * 2;
while (ti < n) {
r[ti] = false;
ti += i;
}
}
return r;
}
bool isPrime(ll v) {
for (ll i = 2; i * i <= v; i++) {
if (v % i == 0)
return false;
}
return true;
}
ll getpow(ll b, ll x, ll md) {
ll t = b;
ll res = 1;
while (x > 0) {
if (x & 1) {
res *= t;
res %= md;
}
x >>= 1;
t *= t;
t %= md;
}
return res;
}
ll getpow(ll b, ll x) { return getpow(b, x, INF); }
class SegTree {
public:
const static int MAX_N = 100010;
const static int DAT_SIZE = (1 << 18) - 1;
int N, Q;
int A[MAX_N];
ll data[DAT_SIZE], datb[DAT_SIZE];
void init(int _n) {
N = 1;
while (N < _n)
N <<= 1;
memset(data, 0, sizeof(data));
memset(datb, 0, sizeof(datb));
}
void init(int _n, ll iv) {
N = 1;
while (N < _n)
N <<= 1;
rep(i, DAT_SIZE) {
data[i] = iv;
datb[i] = iv;
}
}
void add(int a, int b, int x) { add(a, b + 1, x, 0, 0, N); }
void add(int a, int b, int x, int k, int l, int r) {
if (a <= l && r <= b) {
data[k] += x;
} else if (l < b && a < r) {
datb[k] += (min(b, r) - max(a, l)) * x;
add(a, b, x, k * 2 + 1, l, (l + r) / 2);
add(a, b, x, k * 2 + 2, (l + r) / 2, r);
}
}
void change(int a, int b, int x) { change(a, b + 1, x, 0, 0, N); }
void change(int a, int b, int x, int k, int l, int r) {
if (a <= l && r <= b) {
data[k] = x;
} else if (l < b && a < r) {
datb[k] = x;
change(a, b, x, k * 2 + 1, l, (l + r) / 2);
change(a, b, x, k * 2 + 2, (l + r) / 2, r);
}
}
ll sum(int a, int b) { return sum(a, b + 1, 0, 0, N); }
ll sum(int a, int b, int k, int l, int r) {
if (b <= l || r <= a) {
return 0;
}
if (a <= l && r <= b) {
return data[k] * (r - l) + datb[k];
}
ll res = (min(b, r) - max(a, l)) * data[k];
res += sum(a, b, k * 2 + 1, l, (l + r) / 2);
res += sum(a, b, k * 2 + 2, (l + r) / 2, r);
return res;
}
};
class Segment;
class Point {
public:
double x, y;
Point(double x = 0, double y = 0) : x(x), y(y) {}
Point operator+(Point p) { return Point(x + p.x, y + p.y); }
Point operator-(Point p) { return Point(x - p.x, y - p.y); }
Point operator*(double a) { return Point(a * x, a * y); }
Point operator/(double a) { return Point(x / a, y / a); }
double abs() { return sqrt(norm()); }
double norm() { return x * x + y * y; }
bool operator<(const Point &p) const { return x != p.x ? x < p.x : y < p.y; }
bool operator==(const Point &p) const {
return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
}
static double dot(Point a, Point b) { return a.x * b.x + a.y * b.y; }
static double cross(Point a, Point b) { return a.x * b.y - a.y * b.x; }
static bool isOrthogonal(Point a, Point b) { return EQ(dot(a, b), 0.0); }
static bool isOrthogonal(Point a1, Point a2, Point b1, Point b2) {
return isOrthogonal(a1 - a2, b1 - b2);
}
static bool isOrthogonal(Segment s1, Segment s2);
static bool isPalallel(Point a, Point b) { return EQ(cross(a, b), 0.0); }
static bool isPalallel(Point a1, Point a2, Point b1, Point b2) {
return isPalallel(a1 - a2, b1 - b2);
}
static bool isPalallel(Segment s1, Segment s2);
static const int COUNTER_CLOCKWISE = 1;
static const int CLOCKWISE = -1;
static const int ONLINE_BACK = 2;
static const int ONLINE_FRONT = -2;
static const int ON_SEGMENT = 0;
static int ccw(Point p0, Point p1, Point p2) {
Point a = p1 - p0;
Point b = p2 - p0;
if (cross(a, b) > EPS)
return COUNTER_CLOCKWISE;
if (cross(a, b) < -EPS)
return CLOCKWISE;
if (dot(a, b) < -EPS)
return ONLINE_BACK;
if (a.norm() < b.norm())
return ONLINE_FRONT;
return ON_SEGMENT;
}
static bool intersect(Point p1, Point p2, Point p3, Point p4) {
return (ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0 &&
ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0);
}
static bool intersect(Segment s1, Segment s2);
static Point project(Segment s, Point p);
static Point reflect(Segment s, Point p);
static Point getDistance(Point a, Point b) { return (a - b).abs(); }
static double getDistanceLP(Segment s, Point p);
static double getDistanceSP(Segment s, Point p);
static double getDistance(Segment s1, Segment s2);
};
class Segment {
public:
Point p1, p2;
Segment(Point p1, Point p2) : p1(p1), p2(p2) {}
};
bool Point::isOrthogonal(Segment s1, Segment s2) {
return EQ(dot(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0);
}
bool Point::isPalallel(Segment s1, Segment s2) {
return EQ(cross(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0);
}
bool Point::intersect(Segment s1, Segment s2) {
return intersect(s1.p1, s1.p2, s2.p1, s2.p2);
}
Point Point::project(Segment s, Point p) {
Point base = s.p2 - s.p1;
double r = Point::dot(p - s.p1, base) / base.norm();
return s.p1 + base * r;
}
Point Point::reflect(Segment s, Point p) { return (project(s, p) * 2) - p; }
double Point::getDistanceLP(Segment s, Point p) {
return std::abs(cross(s.p2 - s.p1, p - s.p1) / (s.p2 - s.p1).abs());
}
double Point::getDistanceSP(Segment s, Point p) {
if (dot(s.p2 - s.p1, p - s.p1) < 0.0)
return (p - s.p1).abs();
if (dot(s.p1 - s.p2, p - s.p2) < 0.0)
return (p - s.p2).abs();
return getDistanceLP(s, p);
}
double Point::getDistance(Segment s1, Segment s2) {
if (intersect(s1, s2))
return 0.0;
return min({getDistanceSP(s1, s2.p1), getDistanceSP(s1, s2.p2),
getDistanceSP(s2, s1.p1), getDistanceSP(s2, s1.p2)});
}
ll divRm(string s, ll x) {
ll r = 0;
for (size_t i = 0; i < s.size(); i++) {
r *= 10;
r += s[i] - '0';
r %= x;
}
return r;
}
ll cmbi(ll x, ll b) {
ll res = 1;
for (size_t i = 0; i < b; i++) {
res *= x - i;
res %= INF;
res *= inv[b - i];
res %= INF;
}
return res;
}
vector<string> res;
void create(int _n, int u, string s) {
if (_n == n) {
res.push_back(s);
return;
}
for (int i = 0; i <= u; i++) {
char c = 'a' + i;
create(_n + 1, (i == u) ? u + 1 : u, s + c);
}
}
void dfs(string s, char mx) {
if (s.length() == n) {
res.push_back(s);
} else {
for (char c = 'a'; c <= mx; c++) {
dfs(s + c, ((c == mx) ? (char)(mx + 1) : mx));
}
}
}
string combine(string s, string t) {
string res = s + t;
for (int i = s.size() - 1; i >= 0; i--) {
int p = s.size() - i;
bool ok = true;
for (int j = 0; j < p && ok; j++) {
if (!(s[i + j] == t[j] || s[i + j] == '?' || t[j] == '?')) {
ok = false;
}
}
if (!ok)
continue;
string v = "";
for (int j = 0; j < i; j++) {
v += s[j];
}
for (int j = 0; j < t.size(); j++) {
if (j < p) {
if (s[i + j] == '?' && t[j] != '?') {
v += t[j];
} else if (s[i + j] != '?' && t[j] == '?') {
v += s[i + j];
} else {
v += t[j];
}
} else
v += t[j];
}
res = v;
}
return res;
}
string cmc(string a, string b, string c) {
string a1 = combine(a, b);
return combine(a1, c);
}
void solv() {
// string a, b, c;
// cin >> a >> b >> c;
// size_t res = INF;
// string a1 = cmc(a, b, c);
// res = min(res, a1.size());
// string a2 = cmc(a, c, b);
// res = min(res, a2.size());
// string a3 = cmc(b, a, c);
// res = min(res, a3.size());
// string a4 = cmc(b, c, a);
// res = min(res, a4.size());
// string a5 = cmc(c, a, b);
// res = min(res, a5.size());
// string a6 = cmc(c, b, a);
// res = min(res, a6.size());
// cout << res << endl;
cin >> n;
// dfs("", 'a');
create(1, 1, "a");
sort(all(res));
string bef = "";
ll tb[4][4];
all0(tb);
map<ll, string> mp;
for (auto v : res) {
ll p = 0;
ll ap = 0;
rep(i, n) {
rep2(j, i + 1, n) {
ap *= 10;
if (v[i] == v[j]) {
ap += 1;
tb[i][j] = 1;
}
}
}
if (mp.count(ap)) {
cout << mp[ap] << endl;
cout << v << endl;
}
mp[ap] = v;
cout << v << endl;
}
// double a, b, c;
// cin >> a >> b >> c;
// double sa = log(a * b);
// double sc = log(c);
// if (sa / sc < 1.0) {
// cout << "Yes" << endl;
// }
// else {
// cout << "No" << endl;
// }
}
int main() {
// COMinit();
solv();
return 0;
} | #include <algorithm>
#include <array>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctype.h>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string.h>
#include <unordered_map>
#include <utility>
#include <vector>
#define _USE_MATH_DEFINES
#include <iostream>
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, double> pld;
typedef pair<double, double> pdd;
typedef pair<double, ll> pdl;
typedef pair<int, char> pic;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef priority_queue<ll, vector<ll>, greater<ll>> llgreaterq;
typedef priority_queue<pll, vector<pll>, greater<pll>> pllgreaterq;
typedef priority_queue<pair<ll, pll>, vector<pair<ll, pll>>,
greater<pair<ll, pll>>>
plpllgreaterq;
typedef priority_queue<vi, vector<vi>, greater<vi>> vigreaterq;
typedef priority_queue<vl, vector<vl>, greater<vl>> vlgreaterq;
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};
#define bit(x, v) ((ll)x << v)
#define rep(x, n) for (int x = 0; x < n; x++)
#define rep2(x, f, v) for (int x = f; x < v; x++)
// 許容する誤差ε
#define EPS (1e-10)
// 2つのスカラーが等しいかどうか
#define EQ(a, b) (std::abs(a - b) < EPS)
// 2つのベクトルが等しいかどうか
#define EQV(a, b) (EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()))
#define all(a) a.begin(), a.end()
#define all0(a) memset(a, 0, sizeof(a))
#define alm1(a) memset(a, -1, sizeof(a))
const ll INF = 1000000007;
const int MAX = 1000010;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
fac[0] = fac[1] = 1;
finv[0] = finv[1] = 1;
inv[1] = 1;
for (int i = 2; i < MAX; 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;
}
}
// 二項係数計算
long long COM(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;
}
ll gcd(ll a, ll b) {
if (b == 0)
return a;
return gcd(b, a % b);
}
int pr[100010];
int lank[100010];
void uini(int n) {
for (size_t i = 0; i <= n; i++) {
pr[i] = i;
lank[i] = 1;
}
}
int parent(int x) {
if (x == pr[x])
return x;
return pr[x] = parent(pr[x]);
}
int same(int x, int y) { return parent(x) == parent(y); }
bool unit(int x, int y) {
int px = parent(x);
int py = parent(y);
if (px == py)
return false;
if (lank[py] < lank[px]) {
pr[py] = px;
lank[px] += lank[py];
} else {
pr[px] = py;
lank[py] += lank[px];
}
return true;
}
ll bit[200010];
int max_n = 200000;
int pm = 0;
void add(int x) {
while (max_n >= x) {
bit[x]++;
x += x & -x;
}
}
void sub(int x) {
while (max_n >= x) {
bit[x]--;
x += x & -x;
}
}
ll merge(ll *a, int left, int mid, int right) {
ll n1 = mid - left;
ll n2 = right - mid;
vector<int> L(n1 + 1);
vector<int> R(n2 + 1);
for (size_t i = 0; i < n1; i++) {
L[i] = a[left + i];
}
for (size_t i = 0; i < n2; i++) {
R[i] = a[mid + i];
}
L[n1] = INF;
R[n2] = INF;
ll i = 0;
ll j = 0;
ll r = 0;
for (size_t k = left; k < right; k++) {
if (L[i] <= R[j]) {
a[k] = L[i];
i++;
} else {
a[k] = R[j];
r += n1 - i;
j++;
}
}
return r;
}
ll merge2(pair<int, char> *a, int left, int mid, int right) {
ll n1 = mid - left;
ll n2 = right - mid;
vector<pair<int, char>> L(n1 + 1);
vector<pair<int, char>> R(n2 + 1);
for (size_t i = 0; i < n1; i++) {
L[i] = a[left + i];
}
for (size_t i = 0; i < n2; i++) {
R[i] = a[mid + i];
}
L[n1] = make_pair(INF, ' ');
R[n2] = make_pair(INF, ' ');
ll i = 0;
ll j = 0;
ll r = 0;
for (size_t k = left; k < right; k++) {
if (L[i].first <= R[j].first) {
a[k] = L[i];
i++;
} else {
a[k] = R[j];
r += n1 - i;
j++;
}
}
return r;
}
ll mergeSort2(pair<int, char> *a, int left, int right) {
ll res = 0;
if (left + 1 < right) {
int mid = (left + right) / 2;
res = mergeSort2(a, left, mid);
res += mergeSort2(a, mid, right);
res += merge2(a, left, mid, right);
}
return res;
}
ll mergeSort(ll *a, int left, int right) {
ll res = 0;
if (left + 1 < right) {
int mid = (left + right) / 2;
res = mergeSort(a, left, mid);
res += mergeSort(a, mid, right);
res += merge(a, left, mid, right);
}
return res;
}
int partition(pair<int, char> *a, int p, int r) {
pair<int, char> x = a[r];
int i = p - 1;
for (size_t j = p; j < r; j++) {
if (a[j].first <= x.first) {
i++;
swap(a[i], a[j]);
}
}
swap(a[i + 1], a[r]);
return i + 1;
}
void quick(pair<int, char> *a, int p, int r) {
if (p < r) {
int q = partition(a, p, r);
quick(a, p, q - 1);
quick(a, q + 1, r);
}
}
ll n;
int ci = 0;
ll P[1000010];
struct Node {
int key;
int priority;
Node *parent, *left, *right;
Node(int key, int priority);
Node() {}
};
Node NIL;
Node::Node(int key, int priority) : key(key), priority(priority) {
left = &NIL;
right = &NIL;
}
Node *root = new Node();
void cenrec(Node *k) {
if (k->key == NIL.key)
return;
cenrec(k->left);
cout << " " << k->key;
cenrec(k->right);
}
void fastrec(Node *k) {
if (k->key == NIL.key)
return;
cout << " " << k->key;
fastrec(k->left);
fastrec(k->right);
}
void insert(Node *v) {
Node *y = &NIL;
Node *x = root;
while (x->key != NIL.key) {
y = x;
if (v->key < x->key) {
x = x->left;
} else {
x = x->right;
}
}
v->parent = y;
if (y->key == NIL.key) {
root = v;
} else if (v->key < y->key) {
y->left = v;
} else {
y->right = v;
}
}
Node *find(Node *k, ll v) {
if (k->key == NIL.key)
return &NIL;
if (k->key == v)
return k;
if (v < k->key)
return find(k->left, v);
return find(k->right, v);
}
void delp12(Node *x) {
if (x->key == NIL.key)
return;
Node *l = x->left;
Node *r = x->right;
Node *pr = x->parent;
if (l->key == NIL.key && r->key == NIL.key) {
if (pr->left == x) {
pr->left = &NIL;
} else
pr->right = &NIL;
} else if (l->key != NIL.key) {
if (pr->left == x) {
pr->left = l;
} else
pr->right = l;
l->parent = pr;
} else if (r->key != NIL.key) {
if (pr->left == x) {
pr->left = r;
} else
pr->right = r;
r->parent = pr;
}
}
Node *get_next(Node *k) {
if (k->key == NIL.key)
return &NIL;
Node *res = get_next(k->left);
if (res->key != NIL.key)
return res;
return k;
}
void del(Node *x) {
if (x->key == NIL.key)
return;
Node *l = x->left;
Node *r = x->right;
Node *pr = x->parent;
if (l->key != NIL.key && r->key != NIL.key) {
Node *nex = get_next(r);
x->key = nex->key;
delp12(nex);
} else {
delp12(x);
}
}
Node *rightRotate(Node *t) {
Node *s = t->left;
t->left = s->right;
s->right = t;
return s;
}
Node *leftRotate(Node *t) {
Node *s = t->right;
t->right = s->left;
s->left = t;
return s;
}
Node *_insert(Node *t, int key, int priority) {
if (t->key == NIL.key) {
return new Node(key, priority);
}
if (key == t->key) {
return t;
}
if (key < t->key) {
t->left = _insert(t->left, key, priority);
if (t->priority < t->left->priority) {
t = rightRotate(t);
}
} else {
t->right = _insert(t->right, key, priority);
if (t->priority < t->right->priority) {
t = leftRotate(t);
}
}
return t;
}
Node *delete1(Node *t, int key);
Node *_delete(Node *t, int key) {
if (t->left->key == NIL.key && t->right->key == NIL.key) {
return &NIL;
} else if (t->left->key == NIL.key) {
t = leftRotate(t);
} else if (t->right->key == NIL.key) {
t = rightRotate(t);
} else {
if (t->left->priority > t->right->priority) {
t = rightRotate(t);
} else
t = leftRotate(t);
}
return delete1(t, key);
}
Node *delete1(Node *t, int key) {
if (t->key == NIL.key) {
return &NIL;
}
if (key < t->key) {
t->left = delete1(t->left, key);
} else if (key > t->key) {
t->right = delete1(t->right, key);
} else
return _delete(t, key);
return t;
}
int H;
int left(int i) { return i * 2 + 1; }
int right(int i) { return i * 2 + 2; }
struct edge {
int from, to;
ll val;
edge(int from, int to, ll val) : from(from), to(to), val(val) {}
};
int k;
int _rank[1010];
int temp[1010];
bool compare_sa(int i, int j) {
if (_rank[i] != _rank[j])
return _rank[i] < _rank[j];
else {
int ri = i + k <= n ? _rank[i + k] : -1;
int rj = j + k <= n ? _rank[j + k] : -1;
return ri < rj;
}
}
void construct_sa(string S, int *sa) {
n = S.length();
for (size_t i = 0; i <= n; i++) {
sa[i] = i;
_rank[i] = i < n ? S[i] : -1;
}
for (k = 1; k <= n; k *= 2) {
sort(sa, sa + n + 1, compare_sa);
// saはソート後の接尾辞の並びになっている、rankは元の位置のindexを保持したまま、更新されている。
// ピンとこなかった部分
temp[sa[0]] = 0;
for (size_t i = 1; i <= n; i++) {
temp[sa[i]] = temp[sa[i - 1]] + (compare_sa(sa[i - 1], sa[i]) ? 1 : 0);
}
for (size_t i = 0; i <= n; i++) {
_rank[i] = temp[i];
}
}
}
bool contain(string S, int *sa, string T) {
int a = 0, b = S.length();
// sa は 接尾辞が辞書順に並んでいる、入っているのはその位置のインデックス
while (b - a > 1) {
int c = (a + b) / 2;
if (S.compare(sa[c], T.length(), T) < 0)
a = c;
else
b = c;
}
return S.compare(sa[b], T.length(), T) == 0;
}
#define bit(x, v) ((ll)x << v)
class BIT {
static const int MAX_N = 500010;
public:
BIT() { memset(bit, 0, sizeof(bit)); }
ll bit[MAX_N + 1], n;
ll sum(int i) {
ll s = 0;
while (i > 0) {
s += bit[i];
i -= i & -i;
}
return s;
}
void add(int i, int x) {
while (i <= n) {
bit[i] += x;
i += i & -i;
}
}
};
struct UnionFind {
vector<int> A;
UnionFind(int n) : A(n, -1) {}
int find(int x) {
if (A[x] < 0)
return x;
return A[x] = find(A[x]);
}
void unite(int x, int y) {
x = find(x), y = find(y);
if (x == y)
return;
if (A[x] > A[y])
swap(x, y);
A[x] += A[y];
A[y] = x;
}
int ngroups() {
int ans = 0;
for (auto a : A)
if (a < 0)
ans++;
return ans;
}
};
void yes() {
cout << "Yes\n";
exit(0);
}
void no() {
cout << "No\n";
exit(0);
}
vector<ll> getp(ll n) {
vector<ll> res;
ll a = 2;
if (n % 2 == 0) {
res.push_back(2);
while (n % 2 == 0)
n /= 2;
}
for (ll i = 3; i * i <= n; i += 2) {
if (n % i == 0) {
res.push_back(i);
while (n % i == 0)
n /= i;
}
}
if (n != 1)
res.push_back(n);
return res;
}
vector<ll> getp2(ll n) {
vector<ll> res;
ll a = 2;
if (n % 2 == 0) {
while (n % 2 == 0) {
n /= 2;
res.push_back(2);
}
}
for (ll i = 3; i * i <= n; i += 2) {
if (n % i == 0) {
while (n % i == 0) {
n /= i;
res.push_back(i);
}
}
}
if (n != 1)
res.push_back(n);
return res;
}
vector<pll> getp3(ll n) {
vector<pll> res;
ll a = 2;
int si = 0;
if (n % 2 == 0) {
res.push_back(make_pair(2, 0));
while (n % 2 == 0) {
n /= 2;
res[si].second++;
}
si++;
}
for (ll i = 3; i * i <= n; i += 2) {
if (n % i == 0) {
res.push_back(make_pair(i, 0));
while (n % i == 0) {
n /= i;
res[si].second++;
}
si++;
}
}
if (n != 1) {
res.push_back(make_pair(n, 1));
}
return res;
}
vector<ll> getDivisors(ll n) {
vector<ll> res;
ll a = 2;
res.push_back(1);
for (ll i = 2; i * i <= n; i++) {
if (n % i == 0) {
res.push_back(i);
if (n / i != i)
res.push_back(n / i);
}
}
return res;
}
struct ve {
public:
vector<ve> child;
int _t = INF;
ve(int t) : _t(t) {}
ve(ve _left, ve _right) {
_t = _left._t + _right._t;
child.push_back(_left);
child.push_back(_right);
}
bool operator<(const ve &t) const { return _t > t._t; }
};
vector<bool> elas(ll n) {
vector<bool> r(n);
fill(r.begin(), r.end(), 1);
r[0] = 0;
r[1] = 0;
for (ll i = 2; i * i < n; i++) {
if (!r[i])
continue;
ll ti = i * 2;
while (ti < n) {
r[ti] = false;
ti += i;
}
}
return r;
}
bool isPrime(ll v) {
for (ll i = 2; i * i <= v; i++) {
if (v % i == 0)
return false;
}
return true;
}
ll getpow(ll b, ll x, ll md) {
ll t = b;
ll res = 1;
while (x > 0) {
if (x & 1) {
res *= t;
res %= md;
}
x >>= 1;
t *= t;
t %= md;
}
return res;
}
ll getpow(ll b, ll x) { return getpow(b, x, INF); }
class SegTree {
public:
const static int MAX_N = 100010;
const static int DAT_SIZE = (1 << 18) - 1;
int N, Q;
int A[MAX_N];
ll data[DAT_SIZE], datb[DAT_SIZE];
void init(int _n) {
N = 1;
while (N < _n)
N <<= 1;
memset(data, 0, sizeof(data));
memset(datb, 0, sizeof(datb));
}
void init(int _n, ll iv) {
N = 1;
while (N < _n)
N <<= 1;
rep(i, DAT_SIZE) {
data[i] = iv;
datb[i] = iv;
}
}
void add(int a, int b, int x) { add(a, b + 1, x, 0, 0, N); }
void add(int a, int b, int x, int k, int l, int r) {
if (a <= l && r <= b) {
data[k] += x;
} else if (l < b && a < r) {
datb[k] += (min(b, r) - max(a, l)) * x;
add(a, b, x, k * 2 + 1, l, (l + r) / 2);
add(a, b, x, k * 2 + 2, (l + r) / 2, r);
}
}
void change(int a, int b, int x) { change(a, b + 1, x, 0, 0, N); }
void change(int a, int b, int x, int k, int l, int r) {
if (a <= l && r <= b) {
data[k] = x;
} else if (l < b && a < r) {
datb[k] = x;
change(a, b, x, k * 2 + 1, l, (l + r) / 2);
change(a, b, x, k * 2 + 2, (l + r) / 2, r);
}
}
ll sum(int a, int b) { return sum(a, b + 1, 0, 0, N); }
ll sum(int a, int b, int k, int l, int r) {
if (b <= l || r <= a) {
return 0;
}
if (a <= l && r <= b) {
return data[k] * (r - l) + datb[k];
}
ll res = (min(b, r) - max(a, l)) * data[k];
res += sum(a, b, k * 2 + 1, l, (l + r) / 2);
res += sum(a, b, k * 2 + 2, (l + r) / 2, r);
return res;
}
};
class Segment;
class Point {
public:
double x, y;
Point(double x = 0, double y = 0) : x(x), y(y) {}
Point operator+(Point p) { return Point(x + p.x, y + p.y); }
Point operator-(Point p) { return Point(x - p.x, y - p.y); }
Point operator*(double a) { return Point(a * x, a * y); }
Point operator/(double a) { return Point(x / a, y / a); }
double abs() { return sqrt(norm()); }
double norm() { return x * x + y * y; }
bool operator<(const Point &p) const { return x != p.x ? x < p.x : y < p.y; }
bool operator==(const Point &p) const {
return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
}
static double dot(Point a, Point b) { return a.x * b.x + a.y * b.y; }
static double cross(Point a, Point b) { return a.x * b.y - a.y * b.x; }
static bool isOrthogonal(Point a, Point b) { return EQ(dot(a, b), 0.0); }
static bool isOrthogonal(Point a1, Point a2, Point b1, Point b2) {
return isOrthogonal(a1 - a2, b1 - b2);
}
static bool isOrthogonal(Segment s1, Segment s2);
static bool isPalallel(Point a, Point b) { return EQ(cross(a, b), 0.0); }
static bool isPalallel(Point a1, Point a2, Point b1, Point b2) {
return isPalallel(a1 - a2, b1 - b2);
}
static bool isPalallel(Segment s1, Segment s2);
static const int COUNTER_CLOCKWISE = 1;
static const int CLOCKWISE = -1;
static const int ONLINE_BACK = 2;
static const int ONLINE_FRONT = -2;
static const int ON_SEGMENT = 0;
static int ccw(Point p0, Point p1, Point p2) {
Point a = p1 - p0;
Point b = p2 - p0;
if (cross(a, b) > EPS)
return COUNTER_CLOCKWISE;
if (cross(a, b) < -EPS)
return CLOCKWISE;
if (dot(a, b) < -EPS)
return ONLINE_BACK;
if (a.norm() < b.norm())
return ONLINE_FRONT;
return ON_SEGMENT;
}
static bool intersect(Point p1, Point p2, Point p3, Point p4) {
return (ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0 &&
ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0);
}
static bool intersect(Segment s1, Segment s2);
static Point project(Segment s, Point p);
static Point reflect(Segment s, Point p);
static Point getDistance(Point a, Point b) { return (a - b).abs(); }
static double getDistanceLP(Segment s, Point p);
static double getDistanceSP(Segment s, Point p);
static double getDistance(Segment s1, Segment s2);
};
class Segment {
public:
Point p1, p2;
Segment(Point p1, Point p2) : p1(p1), p2(p2) {}
};
bool Point::isOrthogonal(Segment s1, Segment s2) {
return EQ(dot(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0);
}
bool Point::isPalallel(Segment s1, Segment s2) {
return EQ(cross(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0);
}
bool Point::intersect(Segment s1, Segment s2) {
return intersect(s1.p1, s1.p2, s2.p1, s2.p2);
}
Point Point::project(Segment s, Point p) {
Point base = s.p2 - s.p1;
double r = Point::dot(p - s.p1, base) / base.norm();
return s.p1 + base * r;
}
Point Point::reflect(Segment s, Point p) { return (project(s, p) * 2) - p; }
double Point::getDistanceLP(Segment s, Point p) {
return std::abs(cross(s.p2 - s.p1, p - s.p1) / (s.p2 - s.p1).abs());
}
double Point::getDistanceSP(Segment s, Point p) {
if (dot(s.p2 - s.p1, p - s.p1) < 0.0)
return (p - s.p1).abs();
if (dot(s.p1 - s.p2, p - s.p2) < 0.0)
return (p - s.p2).abs();
return getDistanceLP(s, p);
}
double Point::getDistance(Segment s1, Segment s2) {
if (intersect(s1, s2))
return 0.0;
return min({getDistanceSP(s1, s2.p1), getDistanceSP(s1, s2.p2),
getDistanceSP(s2, s1.p1), getDistanceSP(s2, s1.p2)});
}
ll divRm(string s, ll x) {
ll r = 0;
for (size_t i = 0; i < s.size(); i++) {
r *= 10;
r += s[i] - '0';
r %= x;
}
return r;
}
ll cmbi(ll x, ll b) {
ll res = 1;
for (size_t i = 0; i < b; i++) {
res *= x - i;
res %= INF;
res *= inv[b - i];
res %= INF;
}
return res;
}
vector<string> res;
void create(int _n, int u, string s) {
if (_n == n) {
cout << s << endl;
return;
}
for (int i = 0; i <= u; i++) {
char c = 'a' + i;
create(_n + 1, (i == u) ? u + 1 : u, s + c);
}
}
void dfs(string s, char mx) {
if (s.length() == n) {
res.push_back(s);
} else {
for (char c = 'a'; c <= mx; c++) {
dfs(s + c, ((c == mx) ? (char)(mx + 1) : mx));
}
}
}
string combine(string s, string t) {
string res = s + t;
for (int i = s.size() - 1; i >= 0; i--) {
int p = s.size() - i;
bool ok = true;
for (int j = 0; j < p && ok; j++) {
if (!(s[i + j] == t[j] || s[i + j] == '?' || t[j] == '?')) {
ok = false;
}
}
if (!ok)
continue;
string v = "";
for (int j = 0; j < i; j++) {
v += s[j];
}
for (int j = 0; j < t.size(); j++) {
if (j < p) {
if (s[i + j] == '?' && t[j] != '?') {
v += t[j];
} else if (s[i + j] != '?' && t[j] == '?') {
v += s[i + j];
} else {
v += t[j];
}
} else
v += t[j];
}
res = v;
}
return res;
}
string cmc(string a, string b, string c) {
string a1 = combine(a, b);
return combine(a1, c);
}
void solv() {
// string a, b, c;
// cin >> a >> b >> c;
// size_t res = INF;
// string a1 = cmc(a, b, c);
// res = min(res, a1.size());
// string a2 = cmc(a, c, b);
// res = min(res, a2.size());
// string a3 = cmc(b, a, c);
// res = min(res, a3.size());
// string a4 = cmc(b, c, a);
// res = min(res, a4.size());
// string a5 = cmc(c, a, b);
// res = min(res, a5.size());
// string a6 = cmc(c, b, a);
// res = min(res, a6.size());
// cout << res << endl;
cin >> n;
// dfs("", 'a');
create(1, 1, "a");
sort(all(res));
string bef = "";
ll tb[4][4];
all0(tb);
map<ll, string> mp;
for (auto v : res) {
ll p = 0;
ll ap = 0;
rep(i, n) {
rep2(j, i + 1, n) {
ap *= 10;
if (v[i] == v[j]) {
ap += 1;
tb[i][j] = 1;
}
}
}
if (mp.count(ap)) {
cout << mp[ap] << endl;
cout << v << endl;
}
mp[ap] = v;
cout << v << endl;
}
// double a, b, c;
// cin >> a >> b >> c;
// double sa = log(a * b);
// double sc = log(c);
// if (sa / sc < 1.0) {
// cout << "Yes" << endl;
// }
// else {
// cout << "No" << endl;
// }
}
int main() {
// COMinit();
solv();
return 0;
} | replace | 863 | 864 | 863 | 864 | 0 | |
p02744 | C++ | Runtime Error |
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
string s = "";
int dfs(int n, int mask) {
if (n == 0) {
cout << s << endl;
} else {
int i;
for (i = 0; i < 26; i++) {
if (mask & (1 << i)) {
s += string(1, i + 'a');
dfs(n - 1, mask);
s.pop_back();
} else {
break;
}
}
s += string(1, i + 'a');
dfs(n - 1, mask | (1 << i));
s.pop_back();
}
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
freopen("INPUT.txt", "r", stdin);
freopen("OUTPUT.txt", "w", stdout);
freopen("OUTPUT_ERROR.txt", "w", stderr);
int n;
cin >> n;
dfs(n, 0);
}
|
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
string s = "";
int dfs(int n, int mask) {
if (n == 0) {
cout << s << endl;
} else {
int i;
for (i = 0; i < 26; i++) {
if (mask & (1 << i)) {
s += string(1, i + 'a');
dfs(n - 1, mask);
s.pop_back();
} else {
break;
}
}
s += string(1, i + 'a');
dfs(n - 1, mask | (1 << i));
s.pop_back();
}
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
if (fopen("INPUT.txt", "r")) {
freopen("INPUT.txt", "r", stdin);
freopen("OUTPUT.txt", "w", stdout);
freopen("OUTPUT_ERROR.txt", "w", stderr);
}
int n;
cin >> n;
dfs(n, 0);
}
| replace | 33 | 37 | 33 | 38 | TLE | |
p02744 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const double eps = 1e-8;
const int NINF = 0xc0c0c0c0;
const int INF = 0x3f3f3f3f;
const ll mod = 1e9 + 7;
const ll maxn = 1e6 + 5;
int n, a[100];
void dfs(int p, int lim) {
if (p == n + 1) {
for (int i = 1; i <= n; i++) {
cout << char(a[i] + 'a' - 1);
}
cout << endl;
}
for (int i = 1; i <= lim; i++) {
a[p] = i;
dfs(p + 1, lim + (i == lim));
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
dfs(1, 1);
return 0;
} | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const double eps = 1e-8;
const int NINF = 0xc0c0c0c0;
const int INF = 0x3f3f3f3f;
const ll mod = 1e9 + 7;
const ll maxn = 1e6 + 5;
int n, a[100];
void dfs(int p, int lim) {
if (p == n + 1) {
for (int i = 1; i <= n; i++) {
cout << char(a[i] + 'a' - 1);
}
cout << endl;
return;
}
for (int i = 1; i <= lim; i++) {
a[p] = i;
dfs(p + 1, lim + (i == lim));
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
dfs(1, 1);
return 0;
} | insert | 18 | 18 | 18 | 19 | -11 | |
p02744 | C++ | Runtime Error | #include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>
long long int dfs(std::string &S, long long int N, char tmpmax,
long long int i) {
// if last letter
if (i == N - 1) {
for (char ctmp = 'a'; (int)ctmp <= (int)tmpmax + 1; ctmp++) {
S[i] = ctmp;
std::cout << S << std::endl;
}
return 0;
}
// other cases
for (char ctmp = 'a'; ctmp <= tmpmax; ctmp++) {
S[i] = ctmp;
dfs(S, N, tmpmax, i + 1);
}
S[i] = tmpmax + 1;
dfs(S, N, (char)((int)tmpmax + 1), i + 1);
return 0;
}
int main() {
long long int N;
std::cin >> N;
std::string S(N, 'a');
std::cerr << S << std::endl;
dfs(S, N, 'a', 1);
return 0;
}
| #include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>
long long int dfs(std::string &S, long long int N, char tmpmax,
long long int i) {
// if last letter
if (i == N - 1) {
for (char ctmp = 'a'; (int)ctmp <= (int)tmpmax + 1; ctmp++) {
S[i] = ctmp;
std::cout << S << std::endl;
}
return 0;
}
// other cases
for (char ctmp = 'a'; ctmp <= tmpmax; ctmp++) {
S[i] = ctmp;
dfs(S, N, tmpmax, i + 1);
}
S[i] = tmpmax + 1;
dfs(S, N, (char)((int)tmpmax + 1), i + 1);
return 0;
}
int main() {
long long int N;
std::cin >> N;
std::string S(N, 'a');
std::cerr << S << std::endl;
if (N == 1) {
std::cout << "a" << std::endl;
} else {
dfs(S, N, 'a', 1);
}
return 0;
}
| replace | 43 | 44 | 43 | 48 | -11 | a
|
p02744 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
void f(int n, int now, int nmax);
string ans = "a";
int main() {
int n;
cin >> n;
f(n, 1, 0);
}
void f(int n, int now, int nmax) {
if (now == n - 1) {
int i = 0;
while (i <= nmax + 1) {
ans += 'a' + i;
cout << ans << endl;
ans = ans.substr(0, now);
i++;
}
} else {
int j = 0;
int nmaxnow = nmax;
while (j <= nmax + 1) {
ans += 'a' + j;
if (j == nmax + 1)
f(n, now + 1, j);
else
f(n, now + 1, nmax);
ans = ans.substr(0, now);
j++;
}
}
return;
} | #include <bits/stdc++.h>
using namespace std;
void f(int n, int now, int nmax);
string ans = "a";
int main() {
int n;
cin >> n;
if (n != 1)
f(n, 1, 0);
else
cout << 'a' << endl;
}
void f(int n, int now, int nmax) {
if (now == n - 1) {
int i = 0;
while (i <= nmax + 1) {
ans += 'a' + i;
cout << ans << endl;
ans = ans.substr(0, now);
i++;
}
} else {
int j = 0;
int nmaxnow = nmax;
while (j <= nmax + 1) {
ans += 'a' + j;
if (j == nmax + 1)
f(n, now + 1, j);
else
f(n, now + 1, nmax);
ans = ans.substr(0, now);
j++;
}
}
return;
} | replace | 11 | 12 | 11 | 15 | -11 | |
p02744 | C++ | Runtime Error | #include <stdio.h>
char f(int x) {
char S;
S = 'a' + x - 1;
return S;
}
int main(void) {
char s[11][2268000][11];
int a[11][2268000];
int c[11];
int n, i, j, k, l, p;
s[1][1][1] = 'a';
a[1][1] = 1;
c[1] = 1;
for (i = 2; i <= 10; i++) {
p = 0;
for (j = 1; j <= c[i - 1]; j++) {
for (k = 1; k <= a[i - 1][j] + 1; k++) {
for (l = 1; l <= i - 1; l++) {
s[i][p + k][l] = s[i - 1][j][l];
}
s[i][p + k][i] = f(k);
if (k == a[i - 1][j] + 1) {
a[i][p + k] = a[i - 1][j] + 1;
} else {
a[i][p + k] = a[i - 1][j];
}
}
p = p + a[i - 1][j] + 1;
}
c[i] = p;
}
scanf("%d", &n);
for (j = 1; j <= c[n]; j++) {
for (l = 1; l <= n; l++) {
printf("%c", s[n][j][l]);
}
printf("\n");
}
return 0;
} | #include <stdio.h>
char f(int x) {
char S;
S = 'a' + x - 1;
return S;
}
int main(void) {
char s[11][115976][11];
int a[11][115976];
int c[11];
int n, i, j, k, l, p;
s[1][1][1] = 'a';
a[1][1] = 1;
c[1] = 1;
for (i = 2; i <= 10; i++) {
p = 0;
for (j = 1; j <= c[i - 1]; j++) {
for (k = 1; k <= a[i - 1][j] + 1; k++) {
for (l = 1; l <= i - 1; l++) {
s[i][p + k][l] = s[i - 1][j][l];
}
s[i][p + k][i] = f(k);
if (k == a[i - 1][j] + 1) {
a[i][p + k] = a[i - 1][j] + 1;
} else {
a[i][p + k] = a[i - 1][j];
}
}
p = p + a[i - 1][j] + 1;
}
c[i] = p;
}
scanf("%d", &n);
for (j = 1; j <= c[n]; j++) {
for (l = 1; l <= n; l++) {
printf("%c", s[n][j][l]);
}
printf("\n");
}
return 0;
} | replace | 9 | 11 | 9 | 11 | -11 | |
p02744 | C++ | Runtime Error | #include <algorithm>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
using namespace std;
typedef long long ll;
int gCount = 0;
string list[100000];
void addChar(string str, int level, int n) {
if (str.length() == n) {
list[gCount] = str;
gCount++;
} else {
for (int i = 0; i < level + 2; i++) {
addChar(str + (char)(97 + i), i > level ? i : level, n);
}
}
}
int main() {
int N;
scanf("%d", &N);
string s = "a";
addChar(s, 0, N);
sort(list, list + gCount);
for (int i = 0; i < gCount; i++) {
printf("%s\n", list[i].c_str());
}
return 0;
} | #include <algorithm>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
using namespace std;
typedef long long ll;
int gCount = 0;
string list[120000];
void addChar(string str, int level, int n) {
if (str.length() == n) {
list[gCount] = str;
gCount++;
} else {
for (int i = 0; i < level + 2; i++) {
addChar(str + (char)(97 + i), i > level ? i : level, n);
}
}
}
int main() {
int N;
scanf("%d", &N);
string s = "a";
addChar(s, 0, N);
sort(list, list + gCount);
for (int i = 0; i < gCount; i++) {
printf("%s\n", list[i].c_str());
}
return 0;
} | replace | 11 | 12 | 11 | 12 | 0 | |
p02744 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define uni(x) x.erase(unique(rng(x)), x.end())
#define PQ(T) priority_queue<T, v(T), greater<T>>
#define dup(x, y) (((x) + (y)-1) / (y))
#define v(T) vector<T>
#define vv(T) v(v(T))
using ll = int64_t;
using ull = uint64_t;
using uint = uint32_t;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pil = pair<int, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
template <typename T> inline istream &operator>>(istream &i, v(T) & v) {
rep(j, v.size()) i >> v[j];
return i;
}
template <typename T> string join(const v(T) & v) {
stringstream s;
rep(i, v.size()) s << ' ' << v[i];
return s.str().substr(1);
}
template <typename T> inline ostream &operator<<(ostream &o, const v(T) & v) {
if (v.size())
o << join(v);
return o;
}
template <typename T1, typename T2>
inline istream &operator>>(istream &i, pair<T1, T2> &v) {
return i >> v.fi >> v.se;
}
template <typename T1, typename T2>
inline ostream &operator<<(ostream &o, const pair<T1, T2> &v) {
return o << v.fi << "," << v.se;
}
const double eps = 1e-6;
const ll LINF = 100200300400500600ll;
const int INF = 1001001001;
//--------------------------------------------------------
#define fastio \
cin.tie(nullptr); \
std::ios::sync_with_stdio(false);
#define myio \
ifstream iofi; \
if (argc > 1) { \
iofi.open(argv[1]); \
std::cin.rdbuf(iofi.rdbuf()); \
}
#define myloopset \
int loop = 1; \
if (argc > 2) \
loop = stoi(argv[2]); \
rep(i, loop)
//--------------------------------------------------------------
template <class T> T chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
} else
return 0;
}
template <class T> T chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
} else
return 0;
}
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {-1, 0, 1, 0};
const int mod = 1000000007;
void Main() {
int n;
cin >> n;
vv(string) ans(10);
ans[0].pb("a");
rep(i, n) {
for (auto s : ans[i]) {
set<char> se;
for (int sk = 0; sk < s.length(); sk++) {
se.insert(s[sk]);
}
rep(j, se.size() + 1) {
char c = 'a' + j;
ans[i + 1].pb(s + (string){c});
}
}
}
sort(rng(ans[n - 1]));
for (auto s : ans[n - 1]) {
cout << s << endl;
}
}
signed main(int argc, char **argv) {
fastio;
myio;
myloopset Main();
}
| #include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define uni(x) x.erase(unique(rng(x)), x.end())
#define PQ(T) priority_queue<T, v(T), greater<T>>
#define dup(x, y) (((x) + (y)-1) / (y))
#define v(T) vector<T>
#define vv(T) v(v(T))
using ll = int64_t;
using ull = uint64_t;
using uint = uint32_t;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pil = pair<int, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
template <typename T> inline istream &operator>>(istream &i, v(T) & v) {
rep(j, v.size()) i >> v[j];
return i;
}
template <typename T> string join(const v(T) & v) {
stringstream s;
rep(i, v.size()) s << ' ' << v[i];
return s.str().substr(1);
}
template <typename T> inline ostream &operator<<(ostream &o, const v(T) & v) {
if (v.size())
o << join(v);
return o;
}
template <typename T1, typename T2>
inline istream &operator>>(istream &i, pair<T1, T2> &v) {
return i >> v.fi >> v.se;
}
template <typename T1, typename T2>
inline ostream &operator<<(ostream &o, const pair<T1, T2> &v) {
return o << v.fi << "," << v.se;
}
const double eps = 1e-6;
const ll LINF = 100200300400500600ll;
const int INF = 1001001001;
//--------------------------------------------------------
#define fastio \
cin.tie(nullptr); \
std::ios::sync_with_stdio(false);
#define myio \
ifstream iofi; \
if (argc > 1) { \
iofi.open(argv[1]); \
std::cin.rdbuf(iofi.rdbuf()); \
}
#define myloopset \
int loop = 1; \
if (argc > 2) \
loop = stoi(argv[2]); \
rep(i, loop)
//--------------------------------------------------------------
template <class T> T chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
} else
return 0;
}
template <class T> T chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
} else
return 0;
}
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {-1, 0, 1, 0};
const int mod = 1000000007;
void Main() {
int n;
cin >> n;
vv(string) ans(11);
ans[0].pb("a");
rep(i, n) {
for (auto s : ans[i]) {
set<char> se;
for (int sk = 0; sk < s.length(); sk++) {
se.insert(s[sk]);
}
rep(j, se.size() + 1) {
char c = 'a' + j;
ans[i + 1].pb(s + (string){c});
}
}
}
sort(rng(ans[n - 1]));
for (auto s : ans[n - 1]) {
cout << s << endl;
}
}
signed main(int argc, char **argv) {
fastio;
myio;
myloopset Main();
}
| replace | 87 | 88 | 87 | 88 | 0 | |
p02744 | Python | Runtime Error | N = int(input())
A = {
1: ["a"],
2: ["aa", "ab"],
3: ["aaa", "aab", "aba", "abb", "abc"],
4: [
"aaaa",
"aaab",
"aabb",
"aabc",
"abaa",
"abab",
"abac",
"abba",
"abbb",
"abbc",
"abca",
"abcb",
"abcc",
"abcd",
],
5: [
"aaaaa",
"aaaab",
"aaaba",
"aaabb",
"aaabc",
"aabba",
"aabbb",
"aabbc",
"aabca",
"aabcb",
"aabcc",
"aabcd",
"abaaa",
"abaab",
"abaac",
"ababa",
"ababb",
"ababc",
"abaca",
"abacb",
"abacc",
"abacd",
"abbaa",
"abbab",
"abbac",
"abbba",
"abbbb",
"abbbc",
"abbca",
"abbcb",
"abbcc",
"abbcd",
"abcaa",
"abcab",
"abcac",
"abcad",
"abcba",
"abcbb",
"abcbc",
"abcbd",
"abcca",
"abccb",
"abccc",
"abccd",
"abcda",
"abcdb",
"abcdc",
"abcdd",
"abcde",
],
}
Ans = A[N]
for i in range(len(Ans)):
print(Ans[i])
| N = int(input())
D = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]
Ans = [["a"]]
for i in range(1, 10):
before = Ans[i - 1]
# print(before)
next = []
for j in before:
L = set(list(j))
# print(L)
for k in range(len(L) + 1):
# print(j)
next.append(j + D[k])
Ans.append(next)
# print(Ans)
print(*Ans[N - 1], sep="\n")
| replace | 1 | 76 | 1 | 16 | 0 | |
p02745 | C++ | Runtime Error | #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template <typename T> ostream &operator<<(ostream &os, vector<T> &v) {
string sep = " ";
if (v.size())
os << v[0];
for (int i = 1; i < v.size(); i++)
os << sep << v[i];
return os;
}
template <typename T> istream &operator>>(istream &is, vector<T> &v) {
for (int i = 0; i < v.size(); i++)
is >> v[i];
return is;
}
#ifdef DBG
void debug_() { cout << endl; }
template <typename T, typename... Args> void debug_(T &&x, Args &&...xs) {
cout << x << " ";
debug_(forward<Args>(xs)...);
}
#define dbg(...) debug_(__VA_ARGS__)
#else
#define dbg(...)
#endif
bool match(char x, char y) { return x == '?' || y == '?' || x == y; }
int main() {
ios_base::sync_with_stdio(false);
cout << setprecision(20) << fixed;
string a, b, c;
cin >> a >> b >> c;
int z = 5;
vector<bool> ab(2 * z, true), bc(2 * z, true), ca(2 * z, true);
for (int i = 0; i < a.size(); i++)
for (int j = 0; j < b.size(); j++) {
if (!match(a[i], b[j]))
ab[i - j + z] = false;
}
for (int i = 0; i < b.size(); i++)
for (int j = 0; j < c.size(); j++) {
if (!match(b[i], c[j]))
bc[i - j + z] = false;
}
for (int i = 0; i < c.size(); i++)
for (int j = 0; j < a.size(); j++) {
if (!match(c[i], a[j]))
ca[i - j + z] = false;
}
int ans = 1e9;
for (int i = -2 * z; i < 2 * z; i++)
for (int j = -2 * z; j < 2 * z; j++) {
int p = i + z;
int q = j - i + z;
int r = -j + z;
if (0 <= p && p < 2 * z && !ab[p])
continue;
if (0 <= q && q < 2 * z && !bc[q])
continue;
if (0 <= r && r < 2 * z && !ca[r])
continue;
int s = max({(int)a.size(), (int)b.size() + i, (int)c.size() + j});
int t = min({0, i, j});
dbg(i, j, p, q, r, s, t, s - t);
ans = min(ans, s - t);
}
cout << ans << endl;
return 0;
}
| #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template <typename T> ostream &operator<<(ostream &os, vector<T> &v) {
string sep = " ";
if (v.size())
os << v[0];
for (int i = 1; i < v.size(); i++)
os << sep << v[i];
return os;
}
template <typename T> istream &operator>>(istream &is, vector<T> &v) {
for (int i = 0; i < v.size(); i++)
is >> v[i];
return is;
}
#ifdef DBG
void debug_() { cout << endl; }
template <typename T, typename... Args> void debug_(T &&x, Args &&...xs) {
cout << x << " ";
debug_(forward<Args>(xs)...);
}
#define dbg(...) debug_(__VA_ARGS__)
#else
#define dbg(...)
#endif
bool match(char x, char y) { return x == '?' || y == '?' || x == y; }
int main() {
ios_base::sync_with_stdio(false);
cout << setprecision(20) << fixed;
string a, b, c;
cin >> a >> b >> c;
int z = 2005;
vector<bool> ab(2 * z, true), bc(2 * z, true), ca(2 * z, true);
for (int i = 0; i < a.size(); i++)
for (int j = 0; j < b.size(); j++) {
if (!match(a[i], b[j]))
ab[i - j + z] = false;
}
for (int i = 0; i < b.size(); i++)
for (int j = 0; j < c.size(); j++) {
if (!match(b[i], c[j]))
bc[i - j + z] = false;
}
for (int i = 0; i < c.size(); i++)
for (int j = 0; j < a.size(); j++) {
if (!match(c[i], a[j]))
ca[i - j + z] = false;
}
int ans = 1e9;
for (int i = -2 * z; i < 2 * z; i++)
for (int j = -2 * z; j < 2 * z; j++) {
int p = i + z;
int q = j - i + z;
int r = -j + z;
if (0 <= p && p < 2 * z && !ab[p])
continue;
if (0 <= q && q < 2 * z && !bc[q])
continue;
if (0 <= r && r < 2 * z && !ca[r])
continue;
int s = max({(int)a.size(), (int)b.size() + i, (int)c.size() + j});
int t = min({0, i, j});
dbg(i, j, p, q, r, s, t, s - t);
ans = min(ans, s - t);
}
cout << ans << endl;
return 0;
}
| replace | 39 | 40 | 39 | 40 | 0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.