language
stringclasses 5
values | dataset
stringclasses 1
value | code
stringlengths 26
25k
| id
stringlengths 10
10
| test_IO
listlengths 1
1
|
---|---|---|---|---|
C++ | codenet | #include <iostream>
#include <string>
using namespace std;
int kekka[2];
int prime_or_not[1001];
int prime_list[1001];
int prime_num[1001];
int prime_counter = 0;
void sosuubunnpu() {
for (int i = 1; i <= 1000; ++i) {
prime_or_not[i] = 0;
}
for (int i = 2; i <= 1000; ++i) {
for (int j = 2; j <= 1000 / i; ++j) {
if (prime_or_not[i] == 0) {
prime_or_not[i * j] = 1;
}
}
}
for (int i = 2; i <= 1000; ++i) {
if (prime_or_not[i] == 0) {
prime_list[prime_counter] = i;
prime_counter += 1;
}
}
}
void innsuubunnkai(int N, int n) {
int time = 0;
while (1) {
if (N % n == 0) {
N = N / n;
time++;
} else {
break;
}
}
kekka[0] = time;
kekka[1] = N;
}
int main() {
sosuubunnpu();
int N;
cin >> N;
int innsuu[11];
int A[N + 1][11];
for (int i = 0; i <= 1000; ++i) {
prime_num[i] = 0;
}
unsigned long long result = 1;
for (int current_num = 2; current_num <= N; ++current_num) {
kekka[1] = current_num;
for (int i = 0; i < prime_counter; ++i) {
innsuubunnkai(kekka[1], prime_list[i]);
prime_num[i] += kekka[0];
}
}
for (int current_num = 2; current_num <= N; ++current_num) {
for (int i = 0; i < 11; ++i) {
innsuu[i] += A[current_num][i];
}
}
for (int i = 0; i < prime_counter; ++i) {
result = (result * (prime_num[i] + 1)) % 1000000007;
}
cout << result << endl;
return 0;
} | s539273394 | [
{
"input": "3\n",
"output": "4\n"
}
] |
C++ | codenet | #include <algorithm>
#include <cmath>
#include <functional>
#include <iostream>
#include <string>
#include <vector>
#define ll long long int
using namespace std;
int h[6], w[6];
int main() {
int x, ans = 0;
cin >> x;
ans = x + x * x + x * x * x;
cout << ans << endl;
return 0;
} | s837925207 | [
{
"input": "2\n",
"output": "14\n"
}
] |
C++ | codenet | #include <iostream>
using namespace std;
int main() {
int A, B;
cin >> A >> B;
int C = A + B;
if (A % 3 != 0 && B % 3 != 0 && C % 3 != 0) {
cout << "Impossible" << endl;
} else {
cout << "Possible" << endl;
}
return 0;
} | s275739084 | [
{
"input": "4 5\n",
"output": "Possible\n"
}
] |
C++ | codenet | #include <iostream>
#include <vector>
using namespace std;
void sort(vector<int>& a_rvecIntValue);
int main(void) {
int iNum = 0;
cin >> iNum;
vector<int> vecIntValue;
while (iNum) {
int iIntValue = 0;
cin >> iIntValue;
vecIntValue.push_back(iIntValue);
iNum--;
}
sort(vecIntValue);
return 0;
}
void sort(vector<int>& a_rvecIntValue) {
for (unsigned int i = 0; i < a_rvecIntValue.size(); i++) {
if (i != 0) {
int iIntValue = a_rvecIntValue.at(i);
int j = i - 1;
while ((j >= 0) && (a_rvecIntValue.at(j) > iIntValue)) {
a_rvecIntValue.at(j + 1) = a_rvecIntValue.at(j);
j--;
}
a_rvecIntValue.at(j + 1) = iIntValue;
}
for (unsigned int k = 0; k < a_rvecIntValue.size(); k++) {
cout << a_rvecIntValue.at(k);
if (k != a_rvecIntValue.size() - 1) {
cout << " ";
}
}
cout << endl;
}
} | s110965154 | [
{
"input": "6\n5 2 4 6 1 3\n",
"output": "5 2 4 6 1 3\n2 5 4 6 1 3\n2 4 5 6 1 3\n2 4 5 6 1 3\n1 2 4 5 6 3\n1 2 3 4 5 6\n"
}
] |
C++ | codenet | #include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;
template <typename T1, typename T2>
inline void chmin(T1 &a, const T2 &b) {
if (a > b) a = b;
}
template <typename T1, typename T2>
inline void chmax(T1 &a, const T2 &b) {
if (a < b) a = b;
}
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
int main() {
int n;
cin >> n;
vector<lint> a(n);
vector<lint> acc(n + 1, 0);
for (int i = 0; i < n; i++) {
cin >> a[i];
acc[i + 1] = acc[i] + a[i];
acc[i + 1] %= MOD;
}
lint ans = 0;
for (int i = 0; i < n; i++) {
ans += a[i] % MOD * (MOD + acc[n] - acc[i + 1]) % MOD;
ans %= MOD;
}
cout << ans << endl;
return 0;
} | s480704678 | [
{
"input": "3\n1 2 3\n",
"output": "11\n"
}
] |
C++ | codenet | #include <iostream>
using namespace std;
string str;
int main() {
cin >> str;
if (str[2] == str[3] && str[4] == str[5])
cout << "Yes\n";
else
cout << "No\n";
} | s275513165 | [
{
"input": "sippuu\n",
"output": "Yes\n"
}
] |
C++ | codenet | #include <iostream>
using namespace std;
int main() {
int x;
cin >> x;
if (x >= 1200)
cout << "ARC" << endl;
else
cout << "ABC" << endl;
return 0;
} | s263967574 | [
{
"input": "1000\n",
"output": "ABC\n"
}
] |
C++ | codenet | #include <assert.h>
#include <math.h>
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
using namespace std;
#define REP(i, n) for (int(i) = 0; (i) < (int)(n); ++(i))
#define REPN(i, m, n) for (int(i) = m; (i) < (int)(n); ++(i))
#define INF (int)2e9
#define MOD (1000 * 1000 * 1000 + 7)
#define Ceil(x, n) (((((x)) + ((n)-1)) / n))
#define CeilN(x, n) (((((x)) + ((n)-1)) / n) * n)
#define FloorN(x, n) ((x) - (x) % (n))
#define IsOdd(x) (((x) & 0x01UL) == 0x01UL)
#define IsEven(x) (!IsOdd((x)))
#define ArrayLength(x) (sizeof(x) / sizeof(x[0]))
#define MAX_QWORD ((QWORD)0xFFFFFFFFFFFFFFFF)
#define M_PI 3.14159265358979323846
typedef long long ll;
typedef unsigned long long int QWORD;
typedef pair<ll, ll> P;
int main() {
int N;
cin >> N;
vector<int> a(N);
REP(i, N) cin >> a[i];
int idx = 1;
int ans = 0;
REP(i, N) {
if (a[i] == idx) {
idx++;
} else {
ans++;
}
}
if (idx == 1) {
cout << -1 << endl;
} else {
cout << ans << endl;
}
return 0;
} | s744854383 | [
{
"input": "3\n2 1 2\n",
"output": "1\n"
}
] |
C++ | codenet | #include <iostream>
typedef long long ll;
int mat[3000][3000];
ll dp[3000][3000][4];
ll dpl[3000];
int main(int argc, char **argv) {
int rr, cc, k;
std::cin >> rr >> cc >> k;
for (int i = 1; i <= k; i++) {
int r, c, v;
std::cin >> r >> c >> v;
mat[r - 1][c - 1] = v;
}
dp[0][0][1] = mat[0][0];
for (int y = 0; y < rr; y++) {
for (int x = 0; x < cc; x++) {
for (int c = 0; c < 4; c++) {
int v = mat[y][x];
ll q;
if (c == 0 || v == 0) {
q = (x == 0) ? dpl[x] : std::max(dpl[x], dp[y][x - 1][c]);
} else {
q = (x == 0) ? dpl[x] + v
: std::max(dpl[x] + v,
std::max(dp[y][x - 1][c],
dp[y][x - 1][c - 1] + v));
}
dp[y][x][c] = q;
}
}
for (int x = 0; x < cc; x++) {
dpl[x] = std::max(std::max(dp[y][x][0], dp[y][x][1]),
std::max(dp[y][x][2], dp[y][x][3]));
}
}
std::cout << dpl[cc - 1] << std::endl;
return 0;
} | s035123609 | [
{
"input": "2 2 3\n1 1 3\n2 1 4\n1 2 5\n",
"output": "8\n"
}
] |
C++ | codenet | #include <iostream>
#include <string>
using namespace std;
int main() {
string s;
cin >> s;
int a, z;
for (int i = 0; i < s.size(); i++) {
if (s[i] == 'A') {
a = i;
break;
}
}
for (int i = s.size() - 1; i >= 0; i--) {
if (s[i] == 'Z') {
z = i;
break;
}
}
cout << z - a + 1 << endl;
return 0;
} | s907227314 | [
{
"input": "QWERTYASDFZXCV\n",
"output": "5\n"
}
] |
C++ | codenet | #include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
int a, b, c, d;
cin >> a >> b >> c >> d;
if (a * b % 2 == 1 && (c + d) % 2 == 1) {
cout << "No" << endl;
} else {
cout << "Yes" << endl;
}
} | s531853923 | [
{
"input": "3 5 1 4\n",
"output": "No\n"
}
] |
C++ | codenet | #include <iostream>
using namespace std;
int N, S;
int main() {
while (cin >> N && N > 0) {
int M, m, addup, i;
M = -1;
m = 1001;
addup = 0;
for (i = 0; i < N; i++) {
cin >> S;
addup += S;
if (S > M) M = S;
if (S < m) m = S;
}
cout << (addup - M - m) / (N - 2) << endl;
}
} | s992338735 | [
{
"input": "3\n1000\n342\n0\n5\n2\n2\n9\n11\n932\n5\n300\n1000\n0\n200\n400\n8\n353\n242\n402\n274\n283\n132\n402\n523\n0\n",
"output": "342\n7\n300\n326\n"
}
] |
C++ | codenet | #include <limits.h>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define REP(i, n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
#define eb emplace_back
typedef long long ll;
using namespace std;
int main(void) {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
vector<int> a(n);
REP(i, n) cin >> a[i];
sort(all(a));
REP(i, n - 1) {
if (a[i] == a[i + 1]) {
cout << "NO" << '\n';
return 0;
}
}
cout << "YES" << '\n';
return 0;
} | s129191754 | [
{
"input": "5\n2 6 1 4 5\n",
"output": "YES\n"
}
] |
C++ | codenet | #include <iostream>
using namespace std;
unsigned long a[100100];
int main(void) {
int k;
unsigned long min, max;
scanf("%d", &k);
for (int i = 0; i < k; i++) scanf("%ld", &a[i]);
max = 3, min = 2;
if (a[k - 1] != 2) {
cout << -1 << endl;
return 0;
}
for (int i = k - 2; i >= 0; i--) {
if (a[i] > max) {
cout << -1 << endl;
return 0;
} else {
max = ((max / a[i]) + 1) * a[i] - 1;
if (min % a[i] != 0) {
min = ((min / a[i]) + 1) * a[i];
}
}
if (max <= min) {
cout << -1 << endl;
return 0;
}
}
printf("%ld %ld\n", min, max);
return 0;
} | s028542090 | [
{
"input": "4\n3 4 3 2\n",
"output": "6 8\n"
}
] |
C++ | codenet | #include <algorithm>
#include <iostream>
#include <string>
using namespace std;
int main() {
string str1, str2;
cin >> str1 >> str2;
sort(str1.begin(), str1.end());
sort(str2.rbegin(), str2.rend());
int loop = str1.length() > str2.length() ? str2.length() : str1.length();
bool flag = false;
for (int i = 0; loop > i; i++) {
char ch1 = str1[i];
char ch2 = str2[i];
if (ch1 == ch2) {
if (loop == i + 1 && str1.length() < str2.length()) {
flag = true;
break;
} else {
continue;
}
} else {
if (ch2 > ch1) {
flag = true;
break;
} else {
break;
}
}
}
if (flag) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
} | s240156356 | [
{
"input": "yx\naxy\n",
"output": "Yes\n"
}
] |
C++ | codenet | #include <stdlib.h>
#include <iostream>
using namespace std;
int main() {
string str;
string tmp;
int sum;
while (1) {
cin >> str;
if (str == "0") break;
sum = 0;
for (int i = 0; i < str.size(); i++) {
tmp = str[i];
int num = atoi(tmp.c_str());
sum += num;
}
cout << sum << endl;
}
return 0;
} | s074619936 | [
{
"input": "123\n55\n1000\n0\n",
"output": "6\n10\n1\n"
}
] |
C++ | codenet | #include <algorithm>
#include <climits>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define INF 1 << 29
#define LL long long int
LL const MOD = 1000000007;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
LL n, c;
cin >> n >> c;
vector<LL> x(n + 1, 0), v(n + 1, 0);
for (int i = 1; i < n + 1; i++) {
cin >> x[i] >> v[i];
}
vector<LL> lefttotal(n + 1, 0), maxlefttotal(n + 1, 0);
for (int i = 1; i < n + 1; i++) {
lefttotal[i] = lefttotal[i - 1] + v[i];
}
for (int i = 1; i < n + 1; i++) {
maxlefttotal[i] = max(maxlefttotal[i - 1], lefttotal[i] - x[i]);
}
vector<LL> righttotal(n + 1, 0), maxrighttotal(n + 1, 0);
for (int i = 1; i < n + 1; i++) {
righttotal[i] = righttotal[i - 1] + v[n - i + 1];
}
for (int i = 1; i < n + 1; i++) {
maxrighttotal[i] =
max(maxrighttotal[i - 1], righttotal[i] - (c - x[n + 1 - i]));
}
LL ans = 0;
for (int i = 1; i < n + 1; i++) {
ans = max(ans, lefttotal[i] - x[i]);
ans = max(ans, lefttotal[i] - 2 * x[i] + maxrighttotal[n - i]);
ans = max(ans, righttotal[i] - (c - x[n + 1 - i]));
ans = max(ans,
righttotal[i] - 2 * (c - x[n + 1 - i]) + maxlefttotal[n - i]);
}
cout << ans << endl;
return 0;
} | s343280137 | [
{
"input": "3 20\n2 80\n9 120\n16 1\n",
"output": "191\n"
}
] |
C++ | codenet | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
#define PB push_back
#define MP make_pair
#define REP(i, n) for (int i = 0; i < (n); i++)
int main() {
int n, ii, a, b;
cin >> n;
long long cnt[10][10];
REP(i, 100) cnt[i % 10][i / 10] = 0;
for (int i = 1; i <= n; i++) {
b = i % 10;
a = i;
while (a >= 10) {
a /= 10;
}
cnt[a][b]++;
}
long long ans = 0;
for (int i = 1; i <= 9; i++) {
for (int j = 1; j <= 9; j++) {
ans += cnt[i][j] * cnt[j][i];
}
}
cout << ans << endl;
} | s324508229 | [
{
"input": "25\n",
"output": "17\n"
}
] |
C++ | codenet | #include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, n) for (int i = n; i >= 0; --i)
const int inf = 1e9 + 7;
const ll mod = 1e9 + 7;
const ll mod1 = 998244353;
const ll big = 1e18;
const double PI = 2 * asin(1);
int main() {
int N;
cin >> N;
vector<ll> A(N);
for (int i = 0; i < N; ++i) cin >> A[i];
sort(A.begin(), A.end(), greater<ll>());
int index;
ll max = inf;
for (int i = 1; i < N; ++i) {
if (max > abs(A[0] - 2 * A[i])) {
max = abs(A[0] - 2 * A[i]);
index = i;
}
}
cout << A[0] << " " << A[index] << endl;
} | s240627521 | [
{
"input": "5\n6 9 4 2 11\n",
"output": "11 6\n"
}
] |
C++ | codenet | #include <math.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define LINF (ll) INF* INF
#define MOD 1000000007
#define rep(i, n) for (int i = 0; i < (n); i++)
#define loop(i, a, n) for (int i = a; i < (n); i++)
#define all(in) in.begin(), in.end()
#define shosu(x) fixed << setprecision(x)
#define int ll
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef vector<pii> vp;
int gcd(int a, int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
int ans = INF;
int h = 19, w = 15;
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
int dy[] = {1, 0, -1, 0, 1, -1, 1, -1};
vs s(19);
void dfs(int x, int y, int cnt) {
if (cnt > 20) return;
if (x == h - 1) {
ans = min(ans, cnt);
return;
}
rep(i, 8) {
int nx = x + dx[i];
int ny = y + dy[i];
if (nx < 0 || nx >= h || ny < 0 || ny >= w) continue;
if (s[nx][ny] != 'X') continue;
bool c = true;
while (c && s[nx][ny] == 'X') {
s[nx][ny] = '.';
nx += dx[i];
ny += dy[i];
if (nx < 0 || nx >= h || ny < 0 || ny >= w) {
if (nx >= h) ans = min(ans, cnt + 1);
c = false;
}
}
if (c) dfs(nx, ny, cnt + 1);
while (nx != x || ny != y) {
nx -= dx[i];
ny -= dy[i];
s[nx][ny] = 'X';
}
s[x][y] = '.';
}
}
signed main(void) {
rep(i, h) cin >> s[i];
int sx, sy;
rep(i, h) rep(j, w) if (s[i][j] == 'O') {
sx = i, sy = j;
s[i][j] = '.';
}
dfs(sx, sy, 0);
if (ans == INF)
cout << -1 << endl;
else
cout << ans << endl;
} | s345215315 | [
{
"input": "...............\n...............\n...............\n...............\n...............\n...............\n...............\n...............\n...............\n...............\n...............\n...............\n...............\n...............\n...............\n...............\n...............\n......O........\n......X........\n",
"output": "1\n"
}
] |
C++ | codenet | #include <iostream>
#include <vector>
#define rep(i, k, n) for (int i = k; i < n; ++i)
using namespace std;
template <class T>
inline void chmin(T &a, T b) {
if (a > b) a = b;
return;
}
const int INF = 1 << 30;
int main() {
vector<int> dp(101000, INF);
dp.at(0) = 0;
int N, K;
cin >> N >> K;
vector<int> h(N);
rep(i, 0, N) cin >> h[i];
rep(i, 0, N) {
rep(j, 1, K + 1) { chmin(dp[i + j], dp[i] + abs(h[i] - h[i + j])); }
}
cout << dp[N - 1] << endl;
return 0;
} | s189738089 | [
{
"input": "5 3\n10 30 40 50 20\n",
"output": "30\n"
}
] |
C++ | codenet | #include <iostream>
using namespace std;
int main() {
string s, t;
cin >> s >> t;
s += s;
puts(s.find(t) + 1 ? "Yes" : "No");
} | s807902500 | [
{
"input": "kyoto\ntokyo\n",
"output": "Yes\n"
}
] |
C++ | codenet | #include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>
#include <vector>
using namespace std;
#define MOD 7007
struct QUEUE {
int a, b, c, tot;
} Push;
int F[6][3] = {{1, 1, 0}, {1, 0, 1}, {0, 1, 1},
{2, 0, 0}, {0, 2, 0}, {0, 0, 2}};
vector<int> Hash[MOD];
bool HASH(int n) {
for (int i = 0; i < Hash[n % MOD].size(); i++)
if (n == Hash[n % MOD][i]) return false;
Hash[n % MOD].push_back(n);
return true;
}
int main() {
Push.tot = 0;
queue<QUEUE> que;
scanf("%d%d%d", &Push.a, &Push.b, &Push.c);
que.push(Push);
while (!que.empty()) {
QUEUE Fro = que.front();
if (Fro.a == Fro.b && Fro.b == Fro.c) {
printf("%d\n", Fro.tot);
return 0;
}
for (int i = 0; i < 6; i++) {
Push = Fro;
Push.tot++;
Push.a += F[i][0];
Push.b += F[i][1];
Push.c += F[i][2];
int n = Push.a * 10000 + Push.b * 100 + Push.c;
if (!HASH(n)) continue;
que.push(Push);
}
que.pop();
}
return 0;
} | s085712108 | [
{
"input": "2 5 4\n",
"output": "2\n"
}
] |
C++ | codenet | #include <iostream>
using namespace std;
int main() {
int n;
int array[100];
cin >> n;
for (int i = 0; i < n; i++) {
cin >> array[i];
}
int sum = 0;
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1; j < n; j++) {
sum += array[i] * array[j];
}
}
cout << sum << endl;
return (0);
} | s780006912 | [
{
"input": "3\n3 1 2\n",
"output": "11\n"
}
] |
C++ | codenet | #include <iostream>
using namespace std;
int main(void) {
int i, t, n;
for (i = 0; i < 4; i++) {
cin >> t >> n;
if (t == 1) {
cout << 6000 * n << endl;
} else if (t == 2) {
cout << 4000 * n << endl;
} else if (t == 3) {
cout << 3000 * n << endl;
} else if (t == 4) {
cout << 2000 * n << endl;
}
}
} | s475106338 | [
{
"input": "3 10\n1 4\n4 1\n2 5\n",
"output": "30000\n24000\n2000\n20000\n"
}
] |
C++ | codenet | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
using namespace std;
long long a[200005];
long long pre[200005];
long long last[200005];
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%lld", &a[i]);
}
long long sumpre = 0, sumlast = 0;
for (int i = 1; i < n; i++) {
sumpre = sumpre + a[i];
pre[i] = sumpre;
}
for (int i = n; i > 1; i--) {
sumlast = sumlast + a[i];
last[i] = sumlast;
}
long long d = (1ll << 60);
for (int i = 1; i < n; i++) {
d = min(d, abs(pre[i] - last[i + 1]));
}
printf("%lld\n", d);
} | s422352362 | [
{
"input": "6\n1 2 3 4 5 6\n",
"output": "1\n"
}
] |
C++ | codenet | #ifdef _WIN32
#pragma warning(disable : 4996)
#endif
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <unordered_map>
using namespace std;
FILE* _fin = stdin;
FILE* _fout = stdout;
#define PI 3.141592653589793238462643383279502884197169399375105820974
#define ten5p1 100001
#define ten6p1 1000001
#define ten8p1 100000001
#define ten9p1 1000000001
#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define rep(var, n) for (int var = 0; var < n; ++var)
#define repi(n) rep(i, n)
#define repj(n) rep(j, n)
#define repi1(n) for (int i = 1; i < n; ++i)
#define repj1(n) for (int j = 1; j < n; ++j)
#define _min(a, b) (a) < (b) ? (a) : (b)
#define _max(a, b) (a) > (b) ? (a) : (b)
#define zeroi(data, n) memset(data, 0, sizeof(int) * n);
#define zeroll(data, n) memset(data, 0, sizeof(long long) * n);
#define one(data, n) \
{ \
for (int _ONEI = 0; _ONEI < n; ++_ONEI) data[_ONEI] = 1; \
}
char readc() {
char var;
fscanf(_fin, "%c", &var);
return var;
}
int readi() {
int var;
fscanf(_fin, "%d", &var);
return var;
}
ll readll() {
ll var;
fscanf(_fin, "%lld", &var);
return var;
}
void repread(int* data, int n) { repi(n) data[i] = readi(); }
void repread(ll* data, int n) { repi(n) data[i] = readll(); }
int reads(char* str, int maxsize) {
for (;;) {
if (fgets(str, maxsize, _fin) == NULL) break;
if (str[0] != '\n' && str[0] != '\r') break;
}
int slen = strlen(str);
if (slen == 0) return 0;
if (str[slen - 1] == '\n' || str[slen - 1] == '\r') str[--slen] = 0;
return slen;
}
#define writec(var) fprintf(_fout, "%c", var)
#define writecsp(var) fprintf(_fout, "%c ", var)
#define writecln(var) fprintf(_fout, "%c\n", var)
#define writei(var) fprintf(_fout, "%d", var)
#define writeisp(var) fprintf(_fout, "%d ", var)
#define writellsp(var) fprintf(_fout, "%lld ", var)
#define writeiln(var) fprintf(_fout, "%d\n", var)
#define writellln(var) fprintf(_fout, "%lld\n", var)
#define writeulln(var) fprintf(_fout, "%llu\n", var)
#define writefln(var) fprintf(_fout, "%f\n", var)
#define writes(str) fprintf(_fout, "%s", str)
#define writesp() fprintf(_fout, " ")
#define writeln() fprintf(_fout, "\n")
#define iseven(x) ((x & 1) == 0 ? 1 : 0)
#define RUN_LOCAL(testfilename) \
{ \
_fin = fopen(testfilename, "r"); \
if (_fin == NULL) _fin = stdin; \
}
#define swap(type, a, b) \
{ \
type t = a; \
a = b; \
b = t; \
}
#define swapxor(a, b) \
{ \
a ^= b; \
b ^= a; \
a ^= b; \
}
#define sort(data, n) std::sort(data, data + n)
#define mod(a, b) b == 0 ? 0 : a == 0 ? 0 : (a > 0 ? a % b : b + a % b)
ll gcd(ll a, ll b) {
if (b == 0) return a;
return gcd(b, a % b);
}
void reversei(int* data, int n) {
int k = n >> 1;
repi(k) {
int tmp = data[i];
data[i] = data[n - i - 1];
data[n - i - 1] = tmp;
}
}
int bsearch(int val, int* data, int n) {
if (data[0] > val) return -1;
if (data[n - 1] < val) return n;
int l = 0;
int r = n - 1;
for (; l < r;) {
int mid = (l + r + 1) >> 1;
if (data[mid] <= val)
l = mid;
else
r = mid - 1;
}
if (data[r] != val) ++r;
return r;
}
#define _Vec(type, name) \
struct name { \
type* data; \
int size; \
int n; \
}; \
void init(name* t, int size) { \
t->data = (type*)malloc(sizeof(type) * size); \
t->size = size; \
t->n = 0; \
} \
void resize(name* t) { \
int ns = t->size * 1.2f; \
t->data = (type*)realloc(t->data, sizeof(type) * ns); \
t->size = ns; \
} \
void add(name* t, type val) { \
if (t->n >= t->size) resize(t); \
int k = t->n; \
t->data[k] = val; \
t->n = k + 1; \
} \
void free(name* t) { free(t->data); }
_Vec(int, Veci) _Vec(long long, Vecll) _Vec(char*, Vecs)
#define _ispal(type, name) \
int name(type* a, type* b, int n) { \
repi(n) { \
if (a[i] != b[n - i - 1]) { \
return 0; \
} \
} \
return 1; \
}
_ispal(int, ispali) _ispal(char, ispalc)
#define _Pair(type, name) \
struct name { \
type x, y; \
}; \
int cmp_##name(const void* _a, const void* _b) { \
name* a = (name*)_a; \
name* b = (name*)_b; \
if (a->x == b->x) { \
if (a->y < b->y) \
return -1; \
else \
return 1; \
} \
if (a->x < b->x) \
return -1; \
else \
return 1; \
} \
void sort_##name(name* d, int n) { \
qsort(d, n, sizeof(name), cmp_##name); \
}
_Pair(int, Pairi)
int cmp_Str(const void* _a, const void* _b) {
char* a = *((char**)_a);
char* b = *((char**)_b);
return strcmp(a, b);
}
void sort_Str(char** str, int n) { qsort(str, n, sizeof(char*), cmp_Str); }
ll expmod(ll x, ll n, ll m) {
ll ans = 1;
for (; n;) {
if (n & 1) ans = (ans * x) % m;
x = (x * x) % m;
n >>= 1;
}
return ans;
}
ll combmod(ll n, ll k, ll m) {
ll ret = 1;
ll div = 1;
for (ll i = 0; i < k; ++i) {
ret = (ret * (n - i) % m) % m;
div = (div * (i + 1)) % m;
}
div = expmod(div, m - 2, m) % m;
return (ret * div) % m;
}
int main() {
RUN_LOCAL("dataabc155A.txt");
int a = readi();
int b = readi();
if (a < b) {
repi(b) writei(a);
writeln();
} else {
repi(a) writei(b);
writeln();
}
return 0;
} | s976558978 | [
{
"input": "4 3\n",
"output": "3333\n"
}
] |
C++ | codenet | #include <ctype.h>
#include <math.h>
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <iomanip>
#include <ios>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>
using namespace std;
int main() {
string N;
cin >> N;
int S = 0;
for (int i = 0; i < N.size(); i++) {
S += N[i] - '0';
}
if (stoi(N) % S == 0)
cout << "Yes" << endl;
else
cout << "No" << endl;
return 0;
} | s527973537 | [
{
"input": "12\n",
"output": "Yes\n"
}
] |
C++ | codenet | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
vector<int> l(n);
for (int i = 0; i < n; i++) {
cin >> l[i];
}
sort(l.begin(), l.end());
int ans = 0;
for (int i = 0; i < k; i++) {
ans += l[n - 1 - i];
}
cout << ans << endl;
} | s623008479 | [
{
"input": "5 3\n1 2 3 4 5\n",
"output": "12\n"
}
] |
C++ | codenet | #include <iostream>
using namespace std;
bool isPalindrome(string s) {
for (int i = 0; i < s.length() / 2; i++) {
if (s[i] == s[s.length() - 1 - i])
continue;
else
return false;
}
return true;
}
int main() {
string s;
cin >> s;
if (isPalindrome(s) && isPalindrome(s.substr(0, s.length() / 2))) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
return 0;
} | s221616550 | [
{
"input": "akasaka\n",
"output": "Yes\n"
}
] |
C++ | codenet | #include <algorithm>
#include <iostream>
using namespace std;
int main() {
int a, b, c;
cin >> a >> b >> c;
if (a > b) {
swap(a, b);
}
if (b > c) {
swap(b, c);
}
if (a > b) {
swap(a, b);
}
cout << a << " " << b << " " << c << endl;
} | s661916956 | [
{
"input": "3 8 1\n",
"output": "1 3 8\n"
}
] |
C++ | codenet | #include <iostream>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
cout << a * b << endl;
return 0;
} | s300263829 | [
{
"input": "2 5\n",
"output": "10\n"
}
] |
C++ | codenet | #include <cstdio>
#define int long long
int n, m, mod, C[310][310], pre[310][310], f[310][310];
using namespace std;
signed main() {
scanf("%lld%lld%lld", &n, &m, &mod);
C[0][0] = 1;
for (int i = 1; i <= n; i++) {
C[i][0] = C[i][i] = 1;
for (int j = 1; j < i; j++)
C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % mod;
}
for (int i = 0; i <= m; i++) f[1][i] = 1, pre[1][i] = m - i + 1;
for (int i = 2; i <= n + 1; i++) {
for (int j = 0; j <= m; j++)
for (int k = 1; k < i; k++)
(f[i][j] +=
f[i - k][j] * pre[k][j + 1] % mod * C[i - 2][k - 1]) %= mod;
for (int j = m; j >= 0; j--)
pre[i][j] = (pre[i][j + 1] + f[i][j]) % mod;
}
printf("%lld\n", f[n + 1][0]);
} | s343804973 | [
{
"input": "2 2 100\n",
"output": "5\n"
}
] |
C++ | codenet | #include <iostream>
using namespace std;
int N, A;
int main() {
cin >> N >> A;
cout << (N % 500 <= A ? "Yes" : "No") << endl;
return 0;
} | s208784214 | [
{
"input": "2018\n218\n",
"output": "Yes\n"
}
] |
C++ | codenet | #include <cstring>
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
template <int V>
struct BitMatching {
vector<int> G[2 * V];
int match[2 * V];
bool used[2 * V];
void init() {
for (int i = 0; i < 2 * V; i++) {
G[i].clear();
}
}
void add(int a, int b) {
G[a].push_back(b + V);
G[b + V].push_back(a);
}
bool dfs(int v) {
used[v] = true;
for (int i = 0; i < G[v].size(); i++) {
int u = G[v][i], w = match[u];
if (w < 0 || (!used[w] && dfs(w))) {
match[v] = u;
match[u] = v;
return true;
}
}
return false;
}
int exec() {
int res = 0;
memset(match, -1, sizeof(match));
for (int v = 0; v < V; v++) {
if (match[v] < 0) {
memset(used, 0, sizeof(used));
if (dfs(v)) {
res++;
}
}
}
return res;
}
};
const int MN = 520;
BitMatching<MN> bm;
ll gcd(ll a, ll b) {
if (b == 0) return a;
return gcd(b, a % b);
}
int main() {
while (true) {
int n, m;
cin >> n >> m;
if (!n) break;
bm.init();
int a[n], b[m];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < m; i++) {
cin >> b[i];
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (gcd(a[i], b[j]) != 1) {
bm.add(i, j);
}
}
}
cout << bm.exec() << endl;
}
return 0;
} | s620821061 | [
{
"input": "4 3\n2 6 6 15\n2 3 5\n2 3\n4 9\n8 16 32\n4 2\n4 9 11 13\n5 7\n5 5\n2 3 5 1001 1001\n7 11 13 30 30\n10 10\n2 3 5 7 9 11 13 15 17 29\n4 6 10 14 18 22 26 30 34 38\n20 20\n195 144 903 63 137 513 44 626 75 473\n876 421 568 519 755 840 374 368 570 872\n363 650 155 265 64 26 426 391 15 421\n373 984 564 54 823 477 565 866 879 638\n100 100\n195 144 903 63 137 513 44 626 75 473\n876 421 568 519 755 840 374 368 570 872\n363 650 155 265 64 26 426 391 15 421\n373 984 564 54 823 477 565 866 879 638\n117 755 835 683 52 369 302 424 513 870\n75 874 299 228 140 361 30 342 750 819\n761 123 804 325 952 405 578 517 49 457\n932 941 988 767 624 41 912 702 241 426\n351 92 300 648 318 216 785 347 556 535\n166 318 434 746 419 386 928 996 680 975\n231 390 916 220 933 319 37 846 797 54\n272 924 145 348 350 239 563 135 362 119\n446 305 213 879 51 631 43 755 405 499\n509 412 887 203 408 821 298 443 445 96\n274 715 796 417 839 147 654 402 280 17\n298 725 98 287 382 923 694 201 679 99\n699 188 288 364 389 694 185 464 138 406\n558 188 897 354 603 737 277 35 139 556\n826 213 59 922 499 217 846 193 416 525\n69 115 489 355 256 654 49 439 118 961\n0 0\n",
"output": "3\n1\n0\n4\n9\n18\n85\n"
}
] |
C++ | codenet | #define _USE_MATH_DEFINES
#include <assert.h>
#include <math.h>
#include <algorithm>
#include <array>
#include <bitset>
#include <chrono>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < n; i++)
#define show(s) cout << s << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define LINF (1000000000000000000ll)
#define MOD (1e9 + 7)
#define rep1(i, n) for (int i = 1; i <= n; i++)
typedef pair<ll, ll> P;
ll gcd(ll a, ll b) {
if (b == 0) return a;
return gcd(b, a % b);
}
ll lcd(ll a, ll b) {
if (b == 0) return a;
return (a / gcd(a, b)) * b;
}
vector<int> divnum(ll num) {
int dig;
vector<int> p;
while (num) {
dig = num % 10;
p.push_back(dig);
num /= 10;
}
return p;
}
int digiter(ll num) {
int dig;
vector<int> p;
while (num) {
dig = num % 10;
p.push_back(dig);
num /= 10;
}
return p.size();
}
vector<int> convertstring(string s) {
vector<int> d;
ll n = s.size();
rep(i, n) { d.push_back(s[i] - '0'); }
return d;
}
map<ll, int> prime_factor(ll n) {
map<ll, int> ret;
for (ll i = 2; i * i <= n; i++) {
while (n % i == 0) {
ret[i]++;
n /= i;
}
}
if (n != 1) ret[n] = 1;
return ret;
}
vector<ll> divisor(ll n) {
vector<ll> res;
for (ll i = 1; i * i <= n; i++) {
if (n % i != 0) continue;
res.push_back(i);
if (i * i != n) res.push_back(n / i);
}
return res;
}
ll myPow(ll x, ll n, ll m) {
if (n == 0) return 1;
if (n % 2 == 0)
return myPow(x * x % m, n / 2, m);
else
return x * myPow(x, n - 1, m) % m;
}
std::vector<int> Eratosthenes(const int N) {
std::vector<bool> is_prime(N + 1);
for (int i = 0; i <= N; i++) {
is_prime[i] = true;
}
std::vector<int> P;
for (int i = 2; i <= N; i++) {
if (is_prime[i]) {
for (int j = 2 * i; j <= N; j += i) {
is_prime[j] = false;
}
P.emplace_back(i);
}
}
return P;
}
const ll mod = MOD;
struct mint {
ll x;
mint(ll x = 0) : x((x % mod + mod) % mod) {}
mint operator-() const { return mint(-x); }
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 { return mint(*this) += a; }
mint operator-(const mint a) const { return mint(*this) -= a; }
mint operator*(const mint a) const { return mint(*this) *= a; }
mint pow(ll t) const {
if (!t) return 1;
mint a = pow(t >> 1);
a *= a;
if (t & 1) a *= *this;
return a;
}
mint inv() const { return pow(mod - 2); }
mint& operator/=(const mint a) { return *this *= a.inv(); }
mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }
struct combination {
vector<mint> fact, ifact;
combination(ll n) : fact(n + 1), ifact(n + 1) {
assert(n < mod);
fact[0] = 1;
for (ll i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
ifact[n] = fact[n].inv();
for (ll i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
}
mint operator()(ll n, ll k) {
if (k < 0 || k > n) return 0;
return fact[n] * ifact[k] * ifact[n - k];
}
} comb(1000005);
mint f(ll n, ll k) {
if (n < 0) return 0;
mint res = comb(n, k);
res *= comb.fact[k];
return res;
}
int N, M;
int H[100005];
vector<int> G[100005];
int main() {
cin >> N >> M;
rep(i, N) cin >> H[i];
rep(i, M) {
int u, v;
cin >> u >> v;
u--;
v--;
G[u].push_back(v);
G[v].push_back(u);
}
ll ans = 0;
rep(u, N) {
bool flag = true;
for (int v : G[u]) {
if (H[u] <= H[v]) flag = false;
}
if (flag) ans++;
}
cout << ans << endl;
} | s853750785 | [
{
"input": "4 3\n1 2 3 4\n1 3\n2 3\n2 4\n",
"output": "2\n"
}
] |
C++ | codenet | #include <algorithm>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
int main(void) {
ios::sync_with_stdio(false);
int N;
cin >> N;
vector<int64_t> A(N);
rep(i, N) cin >> A[i];
int64_t answer = 0;
for (int i = 0; i < N - 1; ++i) {
for (int j = i + 1; j < N; ++j) {
int64_t diff = abs(A[i] - A[j]);
answer = max(answer, diff);
}
}
cout << answer << endl;
return 0;
} | s495709932 | [
{
"input": "4\n1 4 6 3\n",
"output": "5\n"
}
] |
C++ | codenet | #include <iostream>
using namespace std;
int main() {
int A, B;
cin >> A >> B;
if (A < 13 && A >= 6) {
cout << B / 2 << endl;
}
if (A < 6) {
cout << 0 << endl;
}
if (A >= 13) {
cout << B << endl;
}
} | s387994967 | [
{
"input": "30 100\n",
"output": "100\n"
}
] |
C++ | codenet | #include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(void) {
int minA = pow(10, 9) + 1;
int num = 0;
int n, t, f = 0;
cin >> n >> t;
vector<int> A(n);
for (int i = 0; i < n; i++) {
cin >> A[i];
}
for (int i = 0; i < n; i++) {
if (minA > A[i]) {
minA = A[i];
} else {
if (f == A[i] - minA)
num++;
else if (f < A[i] - minA) {
num = 1;
f = A[i] - minA;
}
}
}
cout << num << endl;
} | s107204188 | [
{
"input": "3 2\n100 50 200\n",
"output": "1\n"
}
] |
C++ | codenet | #include <iostream>
using namespace std;
class Cube {
public:
int f[6];
Cube() {}
void roll_z() { roll(1, 2, 4, 3); }
void roll_y() { roll(0, 2, 5, 3); }
void roll_x() { roll(0, 1, 5, 4); }
void roll(int i, int j, int k, int l) {
int t = f[i];
f[i] = f[j];
f[j] = f[k];
f[k] = f[l];
f[l] = t;
}
};
bool eq(Cube c1, Cube c2) {
for (int i = 0; i < 6; i++)
if (c1.f[i] != c2.f[i]) return false;
return true;
}
bool equal(Cube c1, Cube c2) {
for (int i = 0; i < 6; i++) {
for (int j = 0; j < 4; j++) {
if (eq(c1, c2)) return true;
c1.roll_z();
}
if (i % 2 == 0)
c1.roll_y();
else
c1.roll_x();
}
return false;
}
int main() {
Cube c1, c2;
for (int i = 0; i < 6; i++) cin >> c1.f[i];
for (int i = 0; i < 6; i++) cin >> c2.f[i];
if (equal(c1, c2))
cout << "Yes" << endl;
else
cout << "No" << endl;
return 0;
} | s367896206 | [
{
"input": "1 2 3 4 5 6\n6 2 4 3 5 1\n",
"output": "Yes\n"
}
] |
C++ | codenet | #include <iostream>
#include <vector>
using namespace std;
int main() {
int i, n, ans;
cin >> n;
vector<int> p(n);
for (i = 0; i < n; i++) {
cin >> p[i];
}
ans = 0;
for (i = 0; i < n - 1; i++) {
if (p[i] == i + 1) {
p[i + 1] = p[i];
ans += 1;
}
}
if (p[n - 1] == n) {
ans += 1;
}
cout << ans << endl;
} | s064900223 | [
{
"input": "5\n1 4 3 5 2\n",
"output": "2\n"
}
] |
C++ | codenet | #include <math.h>
#include <iostream>
using namespace std;
typedef long long ll;
int n, a[50], p, b = 0, c = 0;
ll nPr(ll n, ll r) {
ll res = 1;
for (int i = 0; i < r; i++) {
res *= (n - i);
}
return res;
}
ll nCr(ll n, ll r) {
double res = 1;
for (int i = 0; i < r; i++) {
res *= (n - i);
res /= (i + 1);
}
return (ll)res;
}
int main() {
cin >> n >> p;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] % 2 == 0) {
b++;
} else {
c++;
}
}
ll bsum = 0, csum = 0;
bsum = (ll)pow(2, b);
if (p == 0) {
for (int i = 0; i <= c; i++) {
if (i % 2 == 0) {
csum += nCr(c, i);
}
}
} else {
for (int i = 0; i <= c; i++) {
if (i % 2 == 1) {
csum += nCr(c, i);
}
}
}
ll ans = bsum * csum;
cout << ans << endl;
} | s788730767 | [
{
"input": "2 0\n1 3\n",
"output": "2\n"
}
] |
C++ | codenet | #include <algorithm>
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef pair<int, string> P;
P v[22];
vector<int> d[33];
int main(void) {
int n;
while (cin >> n && n) {
int m;
for (int i = 0; i < 33; i++) d[i].clear();
for (int i = 0; i < n; i++) {
v[i].first = 0;
cin >> v[i].second >> m;
for (int j = 0; j < m; j++) {
int a;
cin >> a;
v[i].first += n - (int)d[a].size();
for (int k = 0; k < (int)d[a].size(); k++) {
v[d[a][k]].first--;
}
d[a].push_back(i);
}
}
sort(v, v + n);
cout << v[0].first << " " << v[0].second << endl;
}
} | s814403222 | [
{
"input": "4\nakzakr 2 1 8\nfnmyi 5 2 3 4 6 9\ntsnukk 5 2 3 4 7 9\nyskwcnt 6 3 4 7 8 9 10\n4\nakzakr 1 2\nfnmyi 3 10 11 12\ntsnukk 2 1 8\nyskwcnt 2 1 8\n5\nknmmdk 2 13 19\nakmhmr 4 13 15 19 22\nmksyk 6 3 7 12 13 15 19\nskrkyk 3 1 4 8\ntmemm 3 1 17 24\n5\nknmmdk 5 5 6 16 18 26\nakmhmr 9 3 4 7 11 14 15 17 18 20\nmksyk 5 6 13 25 27 28\nskrkyk 4 3 16 23 24\ntmemm 3 6 12 20\n14\nhrkamm 6 4 6 8 10 20 22\nmkhsi 6 1 10 12 15 22 27\nhbkgnh 2 4 9\nchyksrg 8 3 4 12 15 16 20 25 28\nmktkkc 6 0 1 8 15 17 20\ntknsj 6 6 8 18 19 25 26\nyyitktk 3 3 12 18\nykhhgwr 5 3 9 10 11 24\namftm 7 2 6 8 12 13 14 17\nmmftm 4 6 12 16 18\nrtkakzk 3 14 15 21\nazsmur 7 1 2 4 12 15 18 20\niormns 2 4 20\nktrotns 6 7 12 14 17 20 25\n14\nhrkamm 2 4 21\nmkhsi 6 2 3 8 11 18 20\nhbkgnh 4 4 16 28 29\nchyksrg 5 0 3 9 17 22\nmktkkc 2 7 18\ntknsj 3 3 9 23\nyyitktk 3 10 13 25\nykhhgwr 2 18 26\namftm 3 13 18 22\nmmftm 4 1 20 24 27\nrtkakzk 2 1 10\nazsmur 5 2 5 10 14 17\niormns 3 9 15 16\nktrotns 5 7 12 16 17 20\n0\n",
"output": "7 akzakr\n4 akzakr\n6 knmmdk\n12 tmemm\n19 iormns\n24 mktkkc\n"
}
] |
C++ | codenet | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
int N, T;
cin >> N >> T;
int A[N];
vector<int> B(N);
for (int i = 0; i < N; i++) cin >> A[i];
int m = A[0];
B[1] = A[1] - m;
m = min(m, A[1]);
for (int i = 2; i < N; i++) {
B[i] = A[i] - m;
m = min(m, A[i]);
}
cout << count(B.begin(), B.end(), *max_element(B.begin(), B.end())) << endl;
} | s798522572 | [
{
"input": "3 2\n100 50 200\n",
"output": "1\n"
}
] |
C++ | codenet | #include <math.h>
#include <string.h>
#include <algorithm>
#include <bitset>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define REP(i, n) for (long long i = 0; i < (long long)(n); i++)
#define pb push_back
#define INF (ll)1e18
ll mod = 1e9 + 7;
int main() {
ll N, K;
cin >> N >> K;
ll A[N];
REP(i, N) cin >> A[i];
ll ans1 = 0;
REP(i, N) {
REP(j, N) {
if (i >= j) continue;
if (A[i] > A[j]) ans1++;
ans1 %= mod;
}
}
ll count[2005] = {0};
REP(i, N) { count[A[i] - 1]++; }
ll ans2 = 0;
ll remain = N;
REP(i, 2005) {
remain -= count[i];
ans2 += count[i] * remain;
}
ll ans = 0;
ll tmp = K * (K - 1);
tmp /= 2;
tmp %= mod;
tmp *= ans2;
tmp %= mod;
ans += ans1 * K;
ans %= mod;
ans += tmp;
ans %= mod;
cout << ans << endl;
} | s166776347 | [
{
"input": "2 2\n2 1\n",
"output": "3\n"
}
] |
C++ | codenet | #include <algorithm>
#include <iostream>
#include <string>
int main() {
using namespace std;
string s, t;
cin >> s;
t = s[0];
t += to_string(s.size() - 2);
t += s[s.size() - 1];
cout << t << endl;
} | s628937234 | [
{
"input": "internationalization\n",
"output": "i18n\n"
}
] |
C++ | codenet | #include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <vector>
using namespace std;
bool solve() {
int maxsize = 0;
int maxcnt = 0;
int ans_num;
int ans_num2;
vector<string> str_v;
string in;
while (cin >> in) {
str_v.push_back(in);
if (maxsize < in.size()) {
maxsize = in.size();
ans_num = str_v.size() - 1;
}
}
for (int i = 0; i < str_v.size(); i++) {
int cnt = 0;
for (int j = 0; j < str_v.size(); j++) {
if (str_v[i] == str_v[j]) cnt++;
}
if (maxcnt < cnt) {
maxcnt = cnt;
ans_num2 = i;
}
}
cout << str_v[ans_num2] << " " << str_v[ans_num] << endl;
return true;
}
int main() {
cout.setf(ios::fixed);
cout.precision(10);
solve();
return 0;
} | s794872785 | [
{
"input": "Thank you for your mail and your lectures\n",
"output": "your lectures\n"
}
] |
C++ | codenet | #include <algorithm>
#include <array>
#include <cmath>
#include <deque>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
using ll = long long int;
int gcd(int a, int b) {
if (a < b) swap(a, b);
int r;
while ((r = a % b) > 0) {
a = b;
b = r;
}
return b;
}
int main() {
int n;
cin >> n;
int ans;
cin >> ans;
for (int i = 1; i < n; ++i) {
int a;
cin >> a;
ans = gcd(ans, a);
}
cout << ans << endl;
return 0;
} | s208096306 | [
{
"input": "4\n2 10 8 40\n",
"output": "2\n"
}
] |
C++ | codenet | #include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
typedef long long ll;
typedef long double ld;
int dy[4] = {-1, 0, +1, 0};
int dx[4] = {0, +1, 0, -1};
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s) {
return f.second > s.second;
}
int gcd(int a, int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
int main(void) {
int n;
cin >> n;
string s = "";
if (n == 0) {
cout << '0' << endl;
return 0;
}
int i = 1;
while (n != 0) {
if (n % 2 == 0) {
s += '0';
} else {
s += '1';
}
n -= abs(n % 2);
n /= -2;
}
reverse(s.begin(), s.end());
cout << s << endl;
} | s353737529 | [
{
"input": "-9\n",
"output": "1011\n"
}
] |
C++ | codenet | #include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
using Pll = pair<ll, ll>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
int main() {
ll a, b;
cin >> a >> b;
cout << max(a + b, max(a - b, a * b)) << endl;
return 0;
} | s929864256 | [
{
"input": "-13 3\n",
"output": "-10\n"
}
] |
C++ | codenet | #include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define MOD2 1000000007
#define MOD 998244353
#define INF ((1 << 30) - 1)
#define LINF (1LL << 60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;
Int fact[1100000];
Int revfact[1100000];
Int rev[1100000];
void init() {
Int m = MOD;
fact[0] = 1;
revfact[0] = 1;
rev[0] = 0;
rev[1] = 1;
for (int i = 1; i < 1100000; i++) {
fact[i] = fact[i - 1] * i % m;
if (i > 1) rev[i] = MOD / i * (MOD - rev[MOD % i]) % MOD;
revfact[i] = revfact[i - 1] * rev[i] % MOD;
}
}
Int comb[1100][1100];
Int nCk(Int n, Int k) {
if (n < k) return 0;
if (comb[n][k] != 0) return comb[n][k];
Int &res = comb[n][k];
return res = fact[n] * revfact[n - k] % MOD * revfact[k] % MOD;
}
Int mod_pow(Int x, Int a, Int m = MOD) {
if (a == 0) return 1;
Int res = mod_pow(x, a / 2, m);
res = res * res % m;
if (a % 2) res *= x;
return res % m;
}
Int inv(Int x, Int m = MOD) { return mod_pow(x, m - 2, m); }
Int aall, ball;
Int n, ans;
Int a[440], b[440];
Int dp[440][440][2][2];
int main() {
init();
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i] >> b[i];
aall += a[i];
ball += b[i];
}
dp[0][0][0][0] = 1;
for (int i = 1; i <= n; i++) {
int id = i % 2;
for (int asum = aall; asum >= 0; asum--) {
for (int cnt = 0; cnt <= ball; cnt++) {
for (int p = 0; p < 2; p++) {
if (asum - a[i - 1] < 0) continue;
Int pw = 1;
for (int use = 0; use < b[i - 1]; use++) {
if (cnt - use >= 0) {
Int tmp = nCk(cnt, use) % MOD * pw % MOD;
dp[asum][cnt][p][0] +=
dp[asum - a[i - 1]][cnt - use][p ^ 1][0] * tmp %
MOD;
dp[asum][cnt][p][1] +=
dp[asum - a[i - 1]][cnt - use][p ^ 1][1] * tmp %
MOD;
} else
break;
pw = pw * a[i - 1] % MOD;
}
if (cnt - b[i - 1] + 1 >= 0)
dp[asum][cnt][p][1] +=
dp[asum - a[i - 1]][cnt - b[i - 1] + 1][p ^ 1][0] *
nCk(cnt, b[i - 1] - 1) % MOD * pw % MOD;
dp[asum][cnt][p][0] %= MOD;
dp[asum][cnt][p][1] %= MOD;
}
}
}
}
for (int asum = 0; asum <= aall; asum++) {
Int rev_asum_pow = 1;
for (int cnt = 0; cnt <= ball; cnt++) {
rev_asum_pow = rev_asum_pow * rev[asum] % MOD;
for (int p = 0; p < 2; p++) {
Int x = dp[asum][cnt][p][1] * rev_asum_pow % MOD * (cnt + 1) %
MOD * aall % MOD * rev[asum] % MOD;
if (p == 1)
ans += x;
else
ans -= x;
ans %= MOD;
}
}
}
if (ans < 0) ans += MOD;
cout << ans << endl;
return 0;
} | s338629964 | [
{
"input": "2\n1 1\n1 1\n",
"output": "3\n"
}
] |
C++ | codenet | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
const int SIZE = (1e5 * 2) + 13;
vector<int> a;
vector<int> cnt(SIZE);
int main() {
int n, k;
cin >> n >> k;
for (int i = 0; i < n; ++i) {
int x;
cin >> x;
cnt[x]++;
}
for (int i = 0; i < cnt.size(); ++i) {
if (cnt[i] > 0) a.push_back(cnt[i]);
}
int ans = 0;
sort(a.begin(), a.end());
int m = a.size() - k;
for (int i = 0; i < m; ++i) {
ans += a[i];
}
cout << ans << endl;
} | s684825280 | [
{
"input": "5 2\n1 1 2 2 5\n",
"output": "1\n"
}
] |
C++ | codenet | #include <algorithm>
#include <cmath>
#include <iostream>
#include <limits>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
int main() {
int r;
cin >> r;
cout << (r * r) << endl;
} | s397891977 | [
{
"input": "2\n",
"output": "4\n"
}
] |
C++ | codenet | #include <math.h>
#include <stdio.h>
#include <algorithm>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
ll pow(ll a, ll n) {
ll res = 1;
while (n > 0) {
if (n & 1) res *= a;
a *= a;
n >>= 1;
}
return res;
}
ll mod_pow(ll a, ll n, ll mod) {
ll res = 1;
while (n > 0) {
if (n & 1) res = res * a % mod;
a = a * a % mod;
n >>= 1;
}
return res;
}
ll mod_inv(ll a, ll mod) { return mod_pow(a, mod - 2, mod); }
ll mod_nCk(int n, int k, int mod) {
if (n == 0 || k == 0) return 1;
ll p = 1, q = 1;
for (int i = n - k + 1; i <= n; i++) p = (p * i) % MOD;
for (int i = 2; i <= k; i++) q = (q * i) % MOD;
q = mod_inv(q, MOD);
return (p * q) % MOD;
}
int main() {
int n, k;
cin >> n >> k;
cout << mod_nCk(k, n, MOD) << endl;
} | s950360470 | [
{
"input": "3 5\n",
"output": "10\n"
}
] |
C++ | codenet | #include <algorithm>
#include <cstdio>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define reps(i, f, n) for (int i = f; i < int(n); i++)
#define rep(i, n) reps(i, 0, n)
int here[100001];
int dp1[100001];
int dp2[100001];
int main() {
while (1) {
int n, m;
cin >> n >> m;
if (n == 0) break;
rep(i, 100001) here[i] = dp1[i] = dp2[i] = 0;
bool dpflg = false;
rep(i, m) {
int a;
cin >> a;
if (a == 0) dpflg = true;
here[a] = 1;
}
int maxi1 = 0;
int maxi2 = 0;
reps(i, 1, n + 1) {
if (here[i] == 1) dp1[i] = dp1[i - 1] + 1;
maxi1 = max(dp1[i], maxi1);
}
reps(i, 1, n + 1) {
if (here[i] == 1)
dp2[i] = dp2[i - 1] + 1;
else
dp2[i] = dp1[i - 1] + 1;
maxi2 = max(dp2[i], maxi2);
}
if (!dpflg) {
printf("%d\n", maxi1);
} else {
printf("%d\n", maxi2);
}
}
} | s970719454 | [
{
"input": "7 5\n6\n2\n4\n7\n1\n7 5\n6\n2\n0\n4\n7\n0 0\n",
"output": "2\n4\n"
}
] |
C++ | codenet | #include <cstdio>
#include <iostream>
using namespace std;
inline int read() {
int k = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
k = k * 10 + ch - '0';
ch = getchar();
}
return k * f;
}
inline void write(int x) {
if (x < 0) x = -x, putchar('-');
if (x > 9) write(x / 10);
putchar(x % 10 + '0');
}
inline void writeln(int x) {
write(x);
puts("");
}
int n, m, l, r, vi, fa[100005], v[200005];
inline int get(int x) {
if (x == fa[x]) return x;
int f = get(fa[x]);
v[x] += v[fa[x]];
return fa[x] = f;
}
int main() {
n = read();
m = read();
for (int i = 1; i <= n; i++) fa[i] = i;
for (int i = 1; i <= m; i++) {
l = read();
r = read();
vi = read();
int li = get(l), ri = get(r);
if (li != ri) {
v[ri] = vi - v[r] + v[l];
fa[ri] = li;
} else {
if (v[r] - v[l] != vi) {
cout << "No\n";
return 0;
}
}
}
cout << "Yes\n";
return 0;
} | s448220316 | [
{
"input": "3 3\n1 2 1\n2 3 1\n1 3 2\n",
"output": "Yes\n"
}
] |
C++ | codenet | #include <stdio.h>
int main() {
int A[100], n, i, j, t, sw = 0, mini;
scanf("%d", &n);
for (i = 0; i < n; i++) scanf("%d", &A[i]);
for (i = 0; i < n; i++) {
mini = i;
for (j = i; j < n; j++) {
if (A[j] < A[mini]) mini = j;
}
t = A[i];
A[i] = A[mini];
A[mini] = t;
if (i != mini) sw++;
}
for (i = 0; i < n; i++) {
if (i) printf(" ");
printf("%d", A[i]);
}
printf("\n");
printf("%d\n", sw);
return 0;
} | s151802561 | [
{
"input": "6\n5 6 4 2 1 3\n",
"output": "1 2 3 4 5 6\n4\n"
}
] |
C++ | codenet | #include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
typedef long long ll;
int main() {
int a, b, c, d;
cin >> a >> b >> c >> d;
cout << (a - c) * (b - d) << endl;
} | s680076196 | [
{
"input": "3 2\n2 1\n",
"output": "1\n"
}
] |
C++ | codenet | #include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <set>
#include <vector>
using namespace std;
#define int long long int
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
string str;
cin >> str;
int sum = 0;
for (char x : str) {
sum += (x - 48);
}
if (sum % 9 == 0) {
cout << "Yes" << endl;
} else
cout << "No" << endl;
} | s257064825 | [
{
"input": "123456789\n",
"output": "Yes\n"
}
] |
C++ | codenet | #include <iostream>
using namespace std;
long long Euclid(long long x, long long y) {
long long tmp;
if (x < y) {
tmp = x;
x = y;
y = tmp;
}
if (!(x % y)) return y;
return Euclid(y, x % y);
}
int main() {
long long A, B;
cin >> A >> B;
cout << (A * B) / Euclid(A, B) << endl;
} | s097779718 | [
{
"input": "2 3\n",
"output": "6\n"
}
] |
C++ | codenet | #include <algorithm>
#include <cmath>
#include <complex>
#include <cstdlib>
#include <functional>
#include <iostream>
using namespace std;
int main(void) {
int n, a[100];
double avg = 0, s, ans;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
avg += a[i];
}
avg /= n;
s = abs(a[0] - avg);
ans = 0;
for (int i = 1; i < n; i++) {
if (s > abs(a[i] - avg)) {
s = abs(a[i] - avg);
ans = i;
}
}
cout << ans << endl;
return 0;
} | s716198307 | [
{
"input": "3\n1 2 3\n",
"output": "1\n"
}
] |
C++ | codenet | #include <algorithm>
#include <cmath>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
int main() {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int ans = 0;
bool ok = true;
while (ok) {
for (int i = 0; i < n; i++) {
if (a[i] % 2 == 1) {
cout << ans << endl;
return 0;
} else {
a[i] /= 2;
}
}
ans++;
}
cout << ans << endl;
} | s569774535 | [
{
"input": "3\n8 12 40\n",
"output": "2\n"
}
] |
C++ | codenet | #include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define int long long
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define MAX_L 22
int N;
vector<P> G[100000];
int U[MAX_L][100000], R[100000];
long long L[100000];
void dfs(int x, int p, int r, long long l) {
U[0][x] = p;
R[x] = r;
L[x] = l;
for (P pp : G[x]) {
int t = pp._1;
if (t == p) continue;
dfs(t, x, r + 1, l + pp._2);
}
}
int lca(int a, int b) {
if (R[a] > R[b]) swap(a, b);
for (int k = 0; k < MAX_L; k++) {
if ((R[a] - R[b]) >> k & 1) b = U[k][b];
}
if (a == b) return a;
for (int k = MAX_L - 1; k >= 0; k--) {
if (U[k][a] != U[k][b]) {
a = U[k][a];
b = U[k][b];
}
}
return U[0][a];
}
long long dist(int x, int y) {
int g = lca(x, y);
return L[x] + L[y] - 2LL * L[g];
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> N;
rep(i, N - 1) {
int a, b, c;
cin >> a >> b >> c;
a--, b--;
G[a].pb(P(b, c));
G[b].pb(P(a, c));
}
rep(i, MAX_L) rep(j, N) U[i][j] = -1;
dfs(0, -1, 0, 0);
for (int i = 0; i < MAX_L - 1; i++) {
for (int v = 0; v < N; v++) {
if (U[i][v] == -1) U[i + 1][v] = -1;
U[i + 1][v] = U[i][U[i][v]];
}
}
int Q, K;
cin >> Q >> K;
K--;
rep(i, Q) {
int x, y;
cin >> x >> y;
x--, y--;
cout << dist(x, K) + dist(K, y) << "\n";
}
return 0;
} | s285212630 | [
{
"input": "5\n1 2 1\n1 3 1\n2 4 1\n3 5 1\n3 1\n2 4\n2 3\n4 5\n",
"output": "3\n2\n4\n"
}
] |
C++ | codenet | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>
using namespace std;
#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define MAX (1 << 29)
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)
using Pi = pair<int, int>;
using ll = long long;
const int INF = 1 << 28;
string to_string(string s) { return s; }
template <class S, class T>
string to_string(pair<S, T> p) {
return "{" + to_string(p.first) + "," + to_string(p.second) + "}";
}
template <class T>
string to_string(vector<T> v) {
string ret = "{";
for (int i = 0; i < v.size() - 1; ++i) {
ret += to_string(v[i]) + ",";
}
if (v.size() > 0) {
ret += to_string(v.back());
}
ret += "}";
return ret;
}
void debug() { cerr << endl; }
template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
cerr << to_string(head) << " ";
debug(tail...);
}
void print() { cout << endl; }
template <class Head, class... Tail>
void print(Head head, Tail... tail) {
cout << to_string(head);
print(tail...);
}
void get() {}
template <class Head, class... Tail>
void get(Head& head, Tail&... tail) {
cin >> head;
get(tail...);
}
template <class T>
void getv(vector<T>& vec) {
for (int i = 0; i < vec.size(); ++i) cin >> vec[i];
}
int main() {
string S;
cin >> S;
if (S == "Sunny") {
print("Cloudy");
} else if (S == "Cloudy") {
print("Rainy");
} else {
print("Sunny");
}
return 0;
} | s501882481 | [
{
"input": "Sunny\n",
"output": "Cloudy\n"
}
] |
C++ | codenet | #include <math.h>
#include <stdlib.h>
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <queue>
#include <string>
#include <vector>
using namespace std;
#define PI 3.14159265358979
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
#include <set>
int main(void) {
int n, m;
cin >> n >> m;
int ans = 0;
ans += n * (n - 1) / 2;
ans += m * (m - 1) / 2;
cout << ans << endl;
} | s531812249 | [
{
"input": "2 1\n",
"output": "1\n"
}
] |
C++ | codenet | #pragma GCC optimize(2)
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define mod 1000000007
#define mod9 998244353
#define ld long double
#define ull unsigned long long
#define db double
#define ll long long
const db eps = 1e-7;
const int INF = 0x3f3f3f3f;
const ll inf = 0x3f3f3f3f3f3f3f3f;
#define rep(i, be, en) for (ll i = be; i <= en; i++)
#define per(i, be, en) for (int i = en; i >= be; i--)
using namespace std;
const int N = 1e5 + 7;
int tc, n, m, fl = 0;
int main() {
scanf("%d%d%d", &tc, &n, &m);
if (n > m) swap(n, m);
for (int i = 1; i <= m; i++) {
if (i * tc >= n && i * tc <= m) {
printf("OK\n");
fl = 1;
break;
}
}
if (fl == 0) puts("NG");
return 0;
} | s968402497 | [
{
"input": "7\n500 600\n",
"output": "OK\n"
}
] |
C++ | codenet | #include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <algorithm>
#include <iostream>
#include <queue>
using namespace std;
int main() {
long long int a, b, x;
scanf("%lld%lld%lld", &a, &b, &x);
long long int s = (b / x - a / x);
if (a % x == 0) s++;
printf("%lld\n", s);
return 0;
} | s452437940 | [
{
"input": "4 8 2\n",
"output": "3\n"
}
] |
C++ | codenet | #include <iostream>
#include <vector>
int main() {
int n, m;
std::cin >> n >> m;
std::vector<int> foods(m);
for (int i = 0; i < n; i++) {
int k;
std::cin >> k;
for (int j = 0; j < k; j++) {
int temp;
std::cin >> temp;
temp--;
foods[temp]++;
}
}
int ans = 0;
for (auto elem : foods) {
if (elem == n) {
ans++;
}
}
std::cout << ans << std::endl;
} | s571373151 | [
{
"input": "3 4\n2 1 3\n3 1 2 3\n2 3 2\n",
"output": "1\n"
}
] |
C++ | codenet | #include <iostream>
using namespace std;
int main() {
int m, f, r;
while (cin >> m >> f >> r && (m != -1 || f != -1 || r != -1)) {
if (m == -1 || f == -1)
cout << "F";
else if (m + f >= 80)
cout << "A";
else if (m + f >= 65)
cout << "B";
else if (m + f >= 50 || r >= 50)
cout << "C";
else if (m + f >= 30)
cout << "D";
else
cout << "F";
cout << endl;
}
return 0;
} | s698205968 | [
{
"input": "40 42 -1\n20 30 -1\n0 2 -1\n-1 -1 -1\n",
"output": "A\nC\nF\n"
}
] |
C++ | codenet | #include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <set>
#include <vector>
using namespace std;
#define int long long
#define REP(i, s, e) for ((i) = (s); (i) < (e); (i)++)
#define RREP(i, s, e) for ((i) = ((s)-1); (i) >= (e); (i)--)
#define FOR(i, n) for ((i) = (0); (i) < (n); (i)++)
#define RFOR(i, n) for ((i) = ((n)-1); (i) >= (0); (i)--)
#define MOD 1000000007
signed main() {
vector<string> v;
int N, L;
cin >> N >> L;
for (int i = 0; i < N; i++) {
string s;
cin >> s;
v.push_back(s);
}
sort(v.begin(), v.end());
for (int i = 0; i < v.size(); i++) {
cout << v[i];
}
cout << endl;
} | s672953945 | [
{
"input": "3 3\ndxx\naxx\ncxx\n",
"output": "axxcxxdxx\n"
}
] |
C++ | codenet | #include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(void) {
string W;
cin >> W;
sort(W.begin(), W.end());
for (string::iterator itr = W.begin(); itr != W.end(); itr += 2) {
if (*itr != *(itr + 1)) {
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
return 0;
} | s941927127 | [
{
"input": "abaccaba\n",
"output": "Yes\n"
}
] |
C++ | codenet | #include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
int r, g, b, n;
cin >> r >> g >> b >> n;
int ans = 0;
for (int i = 0; i <= n / r; ++i) {
for (int j = 0; j <= n / g; ++j) {
int num = n - r * i - g * j;
if (num >= 0 && num % b == 0) {
++ans;
}
}
}
cout << ans << endl;
return 0;
} | s050708710 | [
{
"input": "1 2 3 4\n",
"output": "4\n"
}
] |
C++ | codenet | #include <iostream>
#include <string>
using namespace std;
int main() {
int n;
cin >> n;
int ac_count = 0;
int wa_count = 0;
int tle_count = 0;
int re_count = 0;
for (int i = 0; i < n; ++i) {
string s;
cin >> s;
if (s == "AC") {
ac_count += 1;
} else if (s == "WA") {
wa_count += 1;
} else if (s == "TLE") {
tle_count += 1;
} else if (s == "RE") {
re_count += 1;
}
}
cout << "AC x " << ac_count << endl;
cout << "WA x " << wa_count << endl;
cout << "TLE x " << tle_count << endl;
cout << "RE x " << re_count << endl;
} | s173139590 | [
{
"input": "6\nAC\nTLE\nAC\nAC\nWA\nTLE\n",
"output": "AC x 3\nWA x 1\nTLE x 2\nRE x 0\n"
}
] |
C++ | codenet | #include <algorithm>
#include <chrono>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define fs first
#define sc second
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001
int main() {
int X, Y, Z, K;
cin >> X >> Y >> Z >> K;
vector<ll> A(X);
vector<ll> B(Y);
vector<ll> C(Z);
for (ll &a : A) cin >> a;
for (ll &b : B) cin >> b;
for (ll &c : C) cin >> c;
sort(A.begin(), A.end(), greater<ll>());
sort(B.begin(), B.end(), greater<ll>());
sort(C.begin(), C.end(), greater<ll>());
vector<ll> AB;
for (int i = 0; i < X; i++) {
for (int j = 0; j < Y; j++) {
AB.push_back(A[i] + B[j]);
}
}
sort(AB.begin(), AB.end(), greater<ll>());
vector<ll> ABC;
for (int i = 0; i < min(K, (int)AB.size()); i++) {
for (int j = 0; j < Z; j++) {
ABC.push_back(AB[i] + C[j]);
}
}
sort(ABC.begin(), ABC.end(), greater<ll>());
for (int i = 0; i < K; i++) {
cout << ABC[i] << endl;
}
return 0;
} | s123678341 | [
{
"input": "2 2 2 8\n4 6\n1 5\n3 8\n",
"output": "19\n17\n15\n14\n13\n12\n10\n8\n"
}
] |
C++ | codenet | #include <math.h>
#include <algorithm>
#include <cstdint>
#include <iostream>
#include <map>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
ll ans, mx, sum, mn = 1e8, cnt = 1;
int main() {
ll h;
cin >> h;
while (h != 1) {
if (h % 2 != 0) h--;
h /= 2;
cnt *= 2;
ans += cnt;
}
cout << ans + 1 << endl;
} | s984540390 | [
{
"input": "2\n",
"output": "3\n"
}
] |
C++ | codenet | #include <iostream>
using namespace std;
int main() {
int a, b;
cin >> a;
cout << a / (60 * 60) << ":" << a % (60 * 60) / 60 << ":"
<< a % (60 * 60) % 60 << endl;
return 0;
} | s844285682 | [
{
"input": "46979\n",
"output": "13:2:59\n"
}
] |
C++ | codenet | #include <iostream>
#include <vector>
using namespace std;
int main() {
int n;
int sq[10000], fr[5000];
vector<int> com;
int tmp;
while (1) {
cin >> n;
if (!n) break;
for (int i = 1; i < n; i++) sq[i] = (i * i) % n;
com.clear();
for (int i = 1; i < n; i++) {
bool f = true;
for (int j = 0; j < com.size(); j++) {
if (com[j] == sq[i]) {
f = false;
break;
}
}
if (f) com.push_back(sq[i]);
}
for (int i = 0; i <= (n - 1) / 2; i++) fr[i] = 0;
for (int i = 0; i < com.size(); i++) {
for (int j = 0; j < com.size(); j++) {
if (i != j) {
tmp = com[i] - com[j];
if (tmp < 0) tmp += n;
if (tmp > (n - 1) / 2) tmp = n - tmp;
fr[tmp]++;
}
}
}
for (int i = 1; i <= (n - 1) / 2; i++) cout << fr[i] << endl;
}
} | s391929974 | [
{
"input": "11\n15\n0\n",
"output": "4\n4\n4\n4\n4\n2\n2\n4\n2\n4\n4\n2\n"
}
] |
C++ | codenet | #define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
int main(int argc, char *args[]) {
int N, D, X;
int num_of_chocolate;
int counter;
int days;
int A[101];
cin >> N >> D >> X;
for (int i = 0; i < N; i++) {
cin >> A[i];
}
num_of_chocolate = 0;
for (int i = 0; i < N; i++) {
days = 0;
counter = 0;
for (int j = 0;; j++) {
days = j * A[i] + 1;
if (days <= D) {
counter++;
} else {
break;
}
}
num_of_chocolate = num_of_chocolate + counter;
}
num_of_chocolate = num_of_chocolate + X;
cout << num_of_chocolate << endl;
} | s209567491 | [
{
"input": "3\n7 1\n2\n5\n10\n",
"output": "8\n"
}
] |
C++ | codenet | #include <math.h>
#include <stdio.h>
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define REPD(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) REPD(i, 0, n)
typedef long long ll;
#define fin(ans) cout << (ans) << '\n'
int main() {
ll N, K;
ll A[200100];
ll B[200100] = {-1};
int now = 1;
ll cnt = 0;
cin >> N >> K;
REP(i, N) { cin >> A[i + 1]; }
REP(i, 200100) { B[i] = -1; }
ll j;
B[1] = 0;
for (j = 1; j <= K; j++) {
now = A[now];
if (B[now] == -1) {
B[now] = j;
} else {
cnt = j;
break;
}
}
if (j < K) {
ll tmp;
tmp = (K - B[now]) % (cnt - B[now]);
for (ll j = 0; j < tmp; j++) {
now = A[now];
}
}
fin(now);
return 0;
} | s466967233 | [
{
"input": "4 5\n3 2 4 1\n",
"output": "4\n"
}
] |
C++ | codenet | #include <cstdio>
#include <iostream>
using namespace std;
void binPrint(int x, int bits) {
for (int i = bits - 1; i >= 0; i--) {
cout << (x & (1 << i) ? 1 : 0);
}
cout << endl;
}
int main(void) {
unsigned a, b;
cin >> a >> b;
binPrint(a & b, 32);
binPrint(a | b, 32);
binPrint(a ^ b, 32);
return 0;
} | s575600334 | [
{
"input": "8 10\n",
"output": "00000000000000000000000000001000\n00000000000000000000000000001010\n00000000000000000000000000000010\n"
}
] |
C++ | codenet | #include <algorithm>
#include <iostream>
#include <string>
using namespace std;
#define rep(i, n) for (int i = 0; i < int(n); i++)
string input, ss;
int a[3], it, cnt;
int Not(int x) { return 2 - x; }
int And(int x, int y) {
if (x * y == 0) return 0;
if (x == 2 && y == 2) return 2;
return 1;
}
int Or(int x, int y) {
if (x == 2 || y == 2) return 2;
if (x == 1 || y == 1) return 1;
return 0;
}
int parse() {
char c = ss[it++];
if ('0' <= c && c <= '2') return c - '0';
if (c == '-') return Not(parse());
int x = parse();
c = ss[it++];
int y = parse();
++it;
return c == '*' ? And(x, y) : Or(x, y);
}
int main() {
while (cin >> input && input != ".") {
rep(i, 3) a[i] = i;
cnt = 0;
rep(i, 3) rep(j, 3) rep(k, 3) {
a[0] = i;
a[1] = j;
a[2] = k;
ss = input;
for (char& c : ss) {
if (c == 'P') c = a[0] + '0';
if (c == 'Q') c = a[1] + '0';
if (c == 'R') c = a[2] + '0';
}
it = 0;
if (parse() == 2) cnt++;
}
cout << cnt << endl;
}
} | s469969316 | [
{
"input": "(P*Q)\n(--R+(P*Q))\n(P*-P)\n2\n1\n(-1+(((---P+Q)*(--Q+---R))*(-R+-P)))\n.\n",
"output": "3\n11\n0\n27\n0\n7\n"
}
] |
C++ | codenet | #include <algorithm>
#include <iostream>
using namespace std;
int main() {
int n, ans = 0;
string a, b, c;
cin >> n;
cin >> a >> b >> c;
for (int i = 0; i < n; i++) {
if (a[i] == b[i] && b[i] == c[i]) {
} else if (a[i] == b[i] || b[i] == c[i] || a[i] == c[i]) {
ans++;
} else {
ans += 2;
}
}
cout << ans << endl;
} | s812763520 | [
{
"input": "4\nwest\neast\nwait\n",
"output": "3\n"
}
] |
C++ | codenet | #include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
using namespace std;
#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i, a, N) for ((i) = (a); (i) < (N); (i)++)
#define rrp(i, N, a) for ((i) = (N)-1; (i) >= (a); (i)--)
#define llfor ll i, j
#define sc(a) cin >> a
#define pr(a) cout << a << endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define all(a) a.begin(), a.end()
#define push(a, b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define size(a, b) (a, vector<ll>(b))
#define llpvec vector<pair<ll, ll>>
double pi = acos(-1);
ll cei(ll x, ll y) {
ll ans = x / y;
if (x % y != 0) ans++;
return ans;
}
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll llpow(ll x, ll n) {
ll i, ans = 1;
rep(i, 0, n) ans *= x;
return ans;
}
ll fact(ll x) {
ll i, ans = 1;
rep(i, 0, x) ans *= (x - i);
return ans;
}
ll ncr(ll n, ll r) { return fact(n) / fact(r) / fact(n - r); }
ll npr(ll n, ll r) { return fact(n) / fact(n - r); }
bool prime(ll a) {
if (a <= 1) return false;
ll i;
for (i = 2; i * i <= a; i++) {
if (a % i == 0) return false;
}
return true;
}
ll fib(ll x) {
ll i, fibo[x + 10];
fibo[0] = 1;
fibo[1] = 1;
fibo[2] = 1;
rep(i, 3, x + 1) fibo[i] = fibo[i - 1] + fibo[i - 2];
return fibo[x];
}
ll dig(ll n) {
ll d = 0, i = 0;
while (n / 10 > 0) {
i++;
d++;
}
return d;
}
llfor;
ll ans = 0;
int main() {
ll h, w;
cin >> h >> w;
char t[10], s[10] = "snuke";
rep(i, 0, h) {
rep(j, 0, w) {
sc(t);
if (!strcmp(s, t)) {
char c = 'A' + j;
cout << c << i + 1 << endl;
return 0;
}
}
}
return 0;
} | s144923291 | [
{
"input": "15 10\nsnake snake snake snake snake snake snake snake snake snake\nsnake snake snake snake snake snake snake snake snake snake\nsnake snake snake snake snake snake snake snake snake snake\nsnake snake snake snake snake snake snake snake snake snake\nsnake snake snake snake snake snake snake snake snake snake\nsnake snake snake snake snake snake snake snuke snake snake\nsnake snake snake snake snake snake snake snake snake snake\nsnake snake snake snake snake snake snake snake snake snake\nsnake snake snake snake snake snake snake snake snake snake\nsnake snake snake snake snake snake snake snake snake snake\nsnake snake snake snake snake snake snake snake snake snake\nsnake snake snake snake snake snake snake snake snake snake\nsnake snake snake snake snake snake snake snake snake snake\nsnake snake snake snake snake snake snake snake snake snake\nsnake snake snake snake snake snake snake snake snake snake\n",
"output": "H6\n"
}
] |
C++ | codenet | #include <algorithm>
#include <cstdio>
using std::sort;
int main(void) {
int *a, *b, i, N;
int frontHalf, backHalf;
scanf("%d", &N);
a = new int[N];
b = new int[N];
for (i = 0; i < N; i++) {
scanf("%d", a + i);
b[i] = a[i];
}
sort(b, b + N);
frontHalf = b[N / 2 - 1];
backHalf = b[N / 2];
delete[] b;
for (i = 0; i < N; i++) {
if (a[i] < backHalf)
printf("%d\n", backHalf);
else
printf("%d\n", frontHalf);
}
delete[] a;
return 0;
} | s360529905 | [
{
"input": "4\n2 4 4 3\n",
"output": "4\n3\n3\n4\n"
}
] |
C++ | codenet | #include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main() {
int A, B, C, D, E, F;
cin >> A >> B >> C >> D >> E >> F;
int m1 = 0, m2 = 0;
float maxD = 0.f;
for (size_t i = 0; 100 * A * i <= F; i++) {
int mA = 100 * A * i;
for (size_t j = 0; mA + 100 * B * j <= F; j++) {
int mB = 100 * B * j;
for (size_t k = 0; mA + mB + C * k <= F; k++) {
int mC = C * k;
for (size_t l = 0; mA + mB + mC + D * l <= F; l++) {
int mD = D * l;
if ((mA + mB) * E / 100 < mD + mC) {
break;
}
float d = (float)(mD + mC) / (float)(mA + mB + mC + mD);
if (d > maxD) {
m1 = mA + mB + mC + mD;
m2 = mC + mD;
maxD = d;
}
}
}
}
}
if (m1 == 0) {
m1 = 100 * A;
}
cout << m1 << " " << m2 << endl;
return 0;
} | s438448326 | [
{
"input": "1 2 10 20 15 200\n",
"output": "110 10\n"
}
] |
C++ | codenet | #include <iostream>
using namespace std;
int main() {
int A, B, C, X;
cin >> A >> B >> C >> X;
int cnt = 0;
for (int a = 0; a <= A; a++) {
for (int b = 0; b <= B; b++) {
for (int c = 0; c <= C; c++) {
int total = 500 * a + 100 * b + 50 * c;
if (total == X) cnt++;
}
}
}
cout << cnt << endl;
} | s593850729 | [
{
"input": "2\n2\n2\n100\n",
"output": "2\n"
}
] |
C++ | codenet | #include <iostream>
using namespace std;
int main() {
int W, H, x, y, r;
cin >> W >> H >> x >> y >> r;
if (x - r < 0 || x + r > W || y - r < 0 || y + r > H) {
cout << "No" << endl;
} else if (x - r >= 0 && x + r <= W && y - r >= 0 && y + r <= W) {
cout << "Yes" << endl;
}
return 0;
} | s330459995 | [
{
"input": "5 4 2 2 1\n",
"output": "Yes\n"
}
] |
C++ | codenet | #include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define ALL(v) (v).begin, (v).end()
#define INF 1e9
#define MOD 1e9 + 7
typedef long long llong;
using namespace std;
int main() {
int n;
cin >> n;
vector<int> cnt(26, 1);
vector<char> s(n);
REP(i, n) {
cin >> s[i];
cnt[s[i] - 'a']++;
}
llong ans = cnt[0];
for (int i = 1; i < 26; ++i) {
ans *= cnt[i];
ans %= (int)MOD;
}
cout << ans - 1 << endl;
return 0;
} | s384319383 | [
{
"input": "4\nabcd\n",
"output": "15\n"
}
] |
C++ | codenet | #include <iostream>
#include <vector>
typedef long long LL;
using namespace std;
#define MOD 1000000007
LL mod_pow(LL x, LL n) {
LL ans = 1;
while (n > 0) {
if ((n & 1) == 1) {
ans = ans * x % MOD;
}
x = x * x % MOD;
n >>= 1;
}
return ans;
}
LL comb_s(LL n, LL r) {
LL tmp_n = 1;
LL tmp_d = 1;
LL ans;
for (int i = 1; i <= r; i++) {
tmp_n = (tmp_n * (n + 1 - i)) % MOD;
tmp_d = (tmp_d * i) % MOD;
ans = tmp_n * mod_pow(tmp_d, MOD - 2);
}
return ans;
}
int main() {
LL n;
LL n_tmp;
LL a;
LL b;
LL ans = 1;
cin >> n >> a >> b;
ans = mod_pow(2, n);
ans--;
LL tmp_nd;
tmp_nd = comb_s(n, a);
ans = (ans - tmp_nd) % MOD;
while (ans < 0) {
ans += MOD;
}
tmp_nd = comb_s(n, b);
ans = (ans - tmp_nd) % MOD;
while (ans < 0) {
ans += MOD;
}
cout << ans << endl;
return 0;
} | s789380051 | [
{
"input": "4 1 3\n",
"output": "7\n"
}
] |
C++ | codenet | #include <iostream>
#include <vector>
using namespace std;
vector<int> G[100000];
bool used[100000];
int grundy[100000];
void dfs(int v) {
used[v] = true;
grundy[v] = 0;
for (int i = 0; i < G[v].size(); i++) {
if (!used[G[v][i]]) {
dfs(G[v][i]);
grundy[v] ^= (grundy[G[v][i]] + 1);
}
}
}
int main() {
int N;
cin >> N;
for (int i = 0; i < N - 1; i++) {
int x, y;
cin >> x >> y;
x--;
y--;
G[x].push_back(y);
G[y].push_back(x);
}
dfs(0);
if (grundy[0] != 0) {
cout << "Alice" << endl;
} else {
cout << "Bob" << endl;
}
} | s772335512 | [
{
"input": "5\n1 2\n2 3\n2 4\n4 5\n",
"output": "Alice\n"
}
] |
C++ | codenet | #include <algorithm>
#include <cmath>
#include <iostream>
#include <limits>
#include <numeric>
#include <string>
#include <vector>
using namespace std;
int main() {
int a, b;
cin >> a >> b;
cout << 6 - a - b << endl;
} | s659042676 | [
{
"input": "3\n1\n",
"output": "2\n"
}
] |
C++ | codenet | #include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
using vi = vector<int>;
using vi2 = vector<vi>;
int pow2(int a) {
int ret = 1;
for (int i = 0; i < a; i++) ret *= 2;
return ret;
}
int count(vi2 hw, int a, int b) {
int sum = 0;
for (int i = 0; i < hw.size(); i++) {
for (int j = 0; j < hw[0].size(); j++) {
if (a >> i & 1 && b >> j & 1 && hw[i][j] == 1) sum++;
}
}
return sum;
}
int main() {
int h, w, k;
cin >> h >> w >> k;
vi2 hw(h, vi(w, 0));
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
char c;
cin >> c;
if (c == '#') hw[i][j] = 1;
}
}
int sum = 0;
for (int i = 0; i < pow2(h); i++) {
for (int j = 0; j < pow2(w); j++) {
if (count(hw, i, j) == k) sum++;
}
}
cout << sum << endl;
} | s612033342 | [
{
"input": "2 3 2\n..#\n###\n",
"output": "5\n"
}
] |
C++ | codenet | #include <algorithm>
#include <iostream>
#include <string>
using namespace std;
string divide[4] = {"dream", "dreamer", "erase", "eraser"};
int main() {
string S;
cin >> S;
reverse(S.begin(), S.end());
for (int i = 0; i < 4; ++i) reverse(divide[i].begin(), divide[i].end());
bool can = true;
for (int i = 0; i < S.size();) {
bool can2 = false;
for (int j = 0; j < 4; ++j) {
string d = divide[j];
if (S.substr(i, d.size()) == d) {
can2 = true;
i += d.size();
}
}
if (!can2) {
can = false;
break;
}
}
if (can)
cout << "YES" << endl;
else
cout << "NO" << endl;
} | s023282516 | [
{
"input": "erasedream\n",
"output": "YES\n"
}
] |
C++ | codenet | #include <algorithm>
#include <cstdio>
int main() {
int n, m, x;
int a[105] = {};
scanf("%d %d %d", &n, &m, &x);
for (int i = 0; i < m; ++i) {
int temp;
scanf("%d", &temp);
a[temp] = 1;
}
int ansl = 0, ansr = 0, i;
for (i = x; i <= n; ++i) {
ansr += a[i];
}
for (i = x; i >= 0; --i) {
ansl += a[i];
}
printf("%d\n", std::min(ansl, ansr));
return 0;
} | s778828888 | [
{
"input": "5 3 3\n1 2 4\n",
"output": "1\n"
}
] |
C++ | codenet | #include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
int main() {
int a, b, c, d, e, k;
cin >> a >> b >> c >> d >> e >> k;
cout << (e - a <= k ? "Yay!" : ":(") << endl;
return 0;
} | s956589471 | [
{
"input": "1\n2\n4\n8\n9\n15\n",
"output": "Yay!\n"
}
] |
C++ | codenet | #include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const int mod = (1 ? 1e9 + 7 : 998244353);
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
ll a, b, c, d, e, f, g, T;
string z;
cin >> z;
a = z.size();
for (int i = 0; i < a - 1; i++) {
if (z[i] == z[i + 1]) {
cout << "Bad" << endl;
return 0;
}
}
cout << "Good" << endl;
} | s559238064 | [
{
"input": "3776\n",
"output": "Bad\n"
}
] |
C++ | codenet | #include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define dep(i, a, b) for (int i = a; i >= b; i--)
#define Rep(i, a) for (int i = 0; i < a; i++)
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define ab(x) ((x) < 0 ? -(x) : (x))
using namespace std;
typedef long long LL;
typedef map<int, int>::iterator mit;
typedef set<int>::iterator sit;
typedef pair<int, int> pii;
#define x first
#define y second
const int N = 1e5 + 10;
struct edge {
int to, pre, c;
} e[N << 1];
int u[N], l = 0;
void ins(int a, int b, int c) { e[++l] = (edge){b, u[a], c}, u[a] = l; }
#define v e[i].to
#define ec e[i].c
#define reg(i, a) for (int i = u[a]; i; i = e[i].pre)
int n, m;
bool vis[N], ok;
LL cnt[3];
int d[N];
int T;
void dfs(int x, int l) {
vis[x] = true;
cnt[l]++;
d[x] = l;
reg(i, x) {
T++;
if (!vis[v])
dfs(v, (l + ec) % 3);
else if ((l + ec) % 3 != d[v])
ok = false;
}
}
int main() {
scanf("%d%d", &n, &m);
rep(i, 1, m) {
int a, b;
scanf("%d%d", &a, &b);
ins(a, b, 1), ins(b, a, 2);
}
LL ans = 0;
rep(i, 1, n) if (!vis[i]) {
T = 0;
rep(j, 0, 2) cnt[j] = 0;
ok = true;
dfs(i, 0);
LL s = cnt[0] + cnt[1] + cnt[2];
if (!ok)
ans += s * s;
else {
if (cnt[0] && cnt[1] && cnt[2])
ans += cnt[0] * cnt[1] + cnt[1] * cnt[2] + cnt[2] * cnt[0];
else
ans += T / 2;
}
}
cout << ans << endl;
} | s003531724 | [
{
"input": "3 2\n1 2\n2 3\n",
"output": "3\n"
}
] |
C++ | codenet | #include <algorithm>
#include <iostream>
#include <set>
using namespace std;
int main() {
int s, x, d = 2;
cin >> s;
set<int> a;
a.insert(s);
while (1) {
if (s % 2 == 0) {
x = s / 2;
if (a.find(x) != a.end()) {
cout << d << endl;
return 0;
}
a.insert(x);
} else {
x = 3 * s + 1;
if (a.find(x) != a.end()) {
cout << d << endl;
return 0;
}
a.insert(x);
}
s = x;
d++;
}
cout << d << endl;
return 0;
} | s550008428 | [
{
"input": "8\n",
"output": "5\n"
}
] |
C++ | codenet | #include <iostream>
using namespace std;
const int MAX_N = 1e3;
int data[MAX_N];
int main() {
int m, nmi, nma;
while (cin >> m >> nmi >> nma && nmi != 0) {
for (int i = 0; i < m; i++) cin >> data[i];
int ma = 0;
int ans = 0;
for (int i = nmi - 1; i < nma; i++) {
if (ma <= data[i] - data[i + 1]) {
ans = i + 1;
ma = data[i] - data[i + 1];
}
}
cout << ans << endl;
}
} | s798006876 | [
{
"input": "5 2 4\n100\n90\n82\n70\n65\n5 2 4\n100\n90\n80\n75\n65\n3 1 2\n5000\n4000\n3000\n4 2 3\n10000\n10000\n8000\n8000\n4 2 3\n10000\n10000\n10000\n8000\n5 2 3\n100\n80\n68\n60\n45\n0 0 0\n",
"output": "3\n4\n2\n2\n3\n2\n"
}
] |
C++ | codenet | #include <iostream>
#include <map>
using u64 = unsigned long long;
const u64 B = 13131;
const int N = 500000 + 7;
int n;
char s[N];
u64 f[N];
int g[N];
std::map<u64, u64> map;
u64 cnt;
u64 pow(u64 a, u64 k) {
if (k < 0) k += (1llu << 63) - 1;
u64 t = 1;
for (; k; a = a * a, k >>= 1)
if (k & 1) t = t * a;
return t;
}
int main() {
scanf("%d%s", &n, s + 1);
for (int i = 1; i <= n; ++i)
if (s[i] == '+' || s[i] == '-')
f[i] = f[i - 1] + (s[i] == '+' ? 1 : -1) * pow(B, g[i] = g[i - 1]);
else
f[i] = f[i - 1], g[i] = g[i - 1] + (s[i] == '<' ? -1 : 1);
for (int i = n; i; --i)
++map[f[i]], cnt += map[f[n] * pow(B, g[i - 1]) + f[i - 1]];
printf("%lld\n", cnt);
return 0;
} | s615050061 | [
{
"input": "5\n+>+<-\n",
"output": "3\n"
}
] |
End of preview. Expand
in Dataset Viewer.
README.md exists but content is empty.
Use the Edit dataset card button to edit it.
- Downloads last month
- 57