solution
stringlengths 11
983k
| difficulty
int64 0
21
| language
stringclasses 2
values |
---|---|---|
#include <bits/stdc++.h>
using namespace std;
int a[111];
int b[111][111];
int n;
int main() {
cin >> n;
memset(a, 0, sizeof(a));
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= n; ++j) scanf("%d", &b[i][j]);
for (int i = 2; i <= n; ++i)
for (int j = 1; j < i; ++j) {
a[i] |= b[i][j];
a[j] |= b[i][j];
}
for (int i = 1; i <= n; ++i) {
printf("%d", a[i]);
if (i < n) printf(" ");
}
printf("\n");
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 105;
int b[MAXN][MAXN], a[MAXN];
int main() {
;
int n = 0;
scanf("%d", &n);
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++) scanf("%d", &b[i][j]);
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
if (i != j) a[i] |= b[i][j];
for (int i = 0; i < n; i++) printf("%d ", a[i]);
printf("\n");
;
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
int a[100];
int t[100][100];
int main() {
int n, i, j, k;
scanf("%d", &n);
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) scanf("%d", &t[i][j]);
}
for (i = 0; i < n; i++) {
for (j = i + 1; j < n; j++) {
if (i != j) {
for (k = 0; k < 30; k++) {
if ((t[i][j] >> k) & 1) {
a[i] |= 1 << k, a[j] |= 1 << k;
}
}
}
}
}
for (i = 0; i < n; i++) {
printf("%d ", a[i]);
}
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
for (int i = 0; i < N; i++) {
int res = 0;
for (int j = 0; j < N; j++) {
int num;
cin >> num;
if (j != i) res |= num;
}
cout << res;
if (i < N - 1) cout << " ";
}
cout << "\n";
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int M = 1e9 + 7;
template <class T>
T ABS(const T &x) {
return x > 0 ? x : -x;
}
long long int gcd(long long int n1, long long int n2) {
return n2 == 0 ? ABS(n1) : gcd(n2, n1 % n2);
}
long long int lcm(long long int n1, long long int n2) {
return n1 == 0 && n2 == 0 ? 0 : ABS(n1 * n2) / gcd(n1, n2);
}
const int N = 32;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
int foo;
bitset<N> a[n][n];
bitset<N> tmp;
for (int i = 0; i < (n); ++i) {
for (int j = 0; j < (n); ++j) {
cin >> foo;
tmp = foo;
a[i][j] = tmp;
}
}
bitset<N> res[n];
for (int i = 0; i < (n); ++i) {
for (int j = 0; j < (n); ++j) {
if (i == j) {
continue;
}
for (int l = 0; l < (N); ++l) {
if (a[i][j][l] == 1) {
res[i][l] = 1;
res[j][l] = 1;
}
}
}
}
for (int i = 0; i < (n); ++i) {
cout << res[i].to_ulong() << " ";
}
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, b[110], a;
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> a;
if (i != j) {
b[i] |= a;
}
}
}
for (int i = 0; i < n; i++) cout << b[i] << ' ';
fclose(stdout);
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
int a[110][40], n;
int b[110][110], ans[110];
int main() {
scanf("%d", &n);
int ma = 0, tmp, i;
memset(a, 0, sizeof(a));
for (i = 0; i < n; i++)
for (int j = 0; j < n; j++) {
scanf("%d", &b[i][j]);
ma = max(ma, b[i][j]);
}
i = 0;
tmp = ma;
while (ma) {
for (int j = 0; j < n; j++)
for (int k = j + 1; k < n; k++) {
if (b[j][k] & (1 << i)) a[j][i] = 1, a[k][i] = 1;
}
i++;
ma /= 2;
}
for (int j = 0; j < n; j++) {
ans[j] = i = 0;
ma = tmp;
while (ma) {
ans[j] += a[j][i] * (1 << i);
i++;
ma /= 2;
}
}
for (int j = 0; j < n; j++) {
printf("%d", ans[j]);
if (j == n - 1)
printf("\n");
else
printf(" ");
}
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int* data = new int[n];
for (int i = 0; i < n; i++) {
int res = 0;
for (int j = 0; j < n; j++) {
int v;
cin >> v;
if (v != -1) res = (res | v);
}
data[i] = res;
}
for (int i = 0; i < n; i++) {
cout << data[i] << " ";
}
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long a[103];
long long bb[103][103];
int main() {
int test;
while (scanf("%d", &test) != EOF) {
memset(a, 0, sizeof(a));
for (int i = 1; i <= test; i++) {
for (int j = 1; j <= test; j++) cin >> bb[i][j];
}
for (int i = 1; i <= test; i++) {
for (int j = i + 1; j <= test; j++) {
a[i] |= bb[i][j];
a[j] |= bb[i][j];
}
}
for (int i = 1; i <= test; i++) cout << a[i] << " ";
cout << endl;
}
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> v(n);
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
int a;
cin >> a;
if (i == j) continue;
for (int k = 0; k < 30; k++) {
if (a & (1 << k)) {
v[i] |= (1 << k);
v[j] |= (1 << k);
}
}
}
}
for (int x : v) cout << x << " ";
cout << endl;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
template <class T>
T _abs(T n) {
return (n < 0 ? -n : n);
}
template <class T>
T sq(T x) {
return x * x;
}
template <class T>
T gcd(T a, T b) {
return (b != 0 ? gcd<T>(b, a % b) : a);
}
template <class T>
T lcm(T a, T b) {
return (a / gcd<T>(a, b) * b);
}
template <class T>
T _max(T a, T b) {
return (!(a < b) ? a : b);
}
template <class T>
T _min(T a, T b) {
return (a < b ? a : b);
}
template <class T>
inline T MOD(T n, T m) {
return (n % m + m) % m;
}
const int INF = 0x7f7f7f7f;
struct debugger {
template <typename T>
debugger& operator,(const T& v) {
cerr << v << " ";
return *this;
}
} dbg;
template <class T>
void deb(T e) {
cout << e << endl;
}
template <class T1, class T2>
void deb(T1 e1, T2 e2) {
cout << e1 << "\t" << e2 << endl;
}
template <class T1, class T2, class T3>
void deb(T1 e1, T2 e2, T3 e3) {
cout << e1 << "\t" << e2 << "\t" << e3 << endl;
}
template <class T1, class T2, class T3, class T4>
void deb(T1 e1, T2 e2, T3 e3, T4 e4) {
cout << e1 << "\t" << e2 << "\t" << e3 << "\t" << e4 << endl;
}
template <class T1, class T2, class T3, class T4, class T5>
void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5) {
cout << e1 << "\t" << e2 << "\t" << e3 << "\t" << e4 << "\t" << e5 << endl;
}
template <class T>
void deb(vector<T> e) {
int i;
for (i = 0; i < (int)e.size(); i++) cout << e[i] << " ";
cout << endl;
}
template <class T>
void deb(vector<T> e, int n) {
int i;
for (i = 0; i < n; i++) cout << e[i] << " ";
cout << endl;
}
template <class T>
void deb(vector<basic_string<T> > e) {
int i, j;
for (i = 0; i < (int)e.size(); i++) {
for (j = 0; j < (int)e[i].size(); j++) cout << e[i][j];
cout << endl;
}
cout << endl;
}
template <class T>
void deb(vector<basic_string<T> > e, int row, int col) {
int i, j;
for (i = 0; i < row; i++) {
for (j = 0; j < col; j++) cout << e[i][j];
cout << endl;
}
cout << endl;
}
template <class T>
void deb(vector<vector<T> > e, int row, int col) {
int i, j;
for (i = 0; i < row; i++) {
for (j = 0; j < col; j++) cout << e[i][j] << "\t";
cout << endl;
}
cout << endl;
}
template <class T>
void deb(T e[100005][100005], int row, int col) {
int i, j;
for (i = 0; i < row; i++) {
for (j = 0; j < col; j++) cout << e[i][j] << " ";
cout << endl;
}
}
template <class T>
void deb(T e[], int row) {
int i;
for (i = 0; i < row; i++) cout << e[i] << " ";
cout << endl;
}
double deg2rad(double x) { return (acos(-1) * x) / 180.0; }
double rad2deg(double x) { return (180.0 * x) / acos(-1); }
template <class T>
inline bool isPrime(T n) {
if (n <= 1) return false;
for (T i = 2; i * i <= n; i++)
if (n % i == 0) return false;
return true;
}
template <class T>
string toString(T n) {
ostringstream oss;
oss << n;
oss.flush();
return oss.str();
}
int toInt(string s) {
int r = 0;
istringstream sin(s);
sin >> r;
return r;
}
bool IsVowel(char ch) {
ch = tolower(ch);
if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u')
return true;
return false;
}
bool isUpper(char c) { return c >= 'A' && c <= 'Z'; }
bool isLower(char c) { return c >= 'a' && c <= 'z'; }
long long int Pow(long long int B, long long int P) {
long long int R = 1;
while (P > 0) {
if (P % 2 == 1) R = (R * B);
P /= 2;
B = (B * B);
}
return R;
}
int BigMod(long long int B, long long int P, long long int M) {
long long int R = 1;
while (P > 0) {
if (P % 2 == 1) {
R = (R * B) % M;
}
P /= 2;
B = (B * B) % M;
}
return (int)R;
}
void binprint(long long int mask, long long int n) {
long long int i;
string s = "";
do {
s += (mask % 2 + '0');
mask /= 2;
} while (mask);
reverse(s.begin(), s.end());
s = string(max(n - (int)s.size(), 0LL), '0') + s;
for (i = (int)s.size() - n; i < (int)s.size(); i++) printf("%c", s[i]);
printf("\n");
}
void ASCII_Chart() {
int i, j, k;
printf("ASCII Chart:(30-129)\n");
for (i = 30; i < 50; i++) {
for (j = 0; j < 5; j++) {
k = i + j * 20;
printf("%3d---> '%c' ", k, k);
}
printf("\n");
}
}
vector<int> seq;
int main() {
int i, j, k, result, t = 0, tcase, n, x;
while (scanf("%d", &n) != EOF) {
for (i = 0; i < n; i++) {
result = 0;
for (k = 0; k < n; k++) {
scanf("%d", &x);
if (x == -1) continue;
result |= x;
}
seq.push_back(result);
}
int flag = 0;
for (i = 0; i < n; i++) {
if (flag) printf(" ");
printf("%d", seq[i]);
flag = 1;
}
cout << endl;
seq.clear();
}
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a, sum = 0;
cin >> n;
for (int i = 0; i < n; ++i) {
int temp = 0;
for (int j = 0; j < n; ++j) {
cin >> a;
if (j != i) {
temp |= a;
}
}
cout << temp << ' ';
}
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
while (cin >> n) {
int b;
int num[120][120];
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) cin >> num[i][j];
}
for (int i = 1; i <= n; i++) {
b = 0;
for (int j = 1; j <= n; j++)
if (num[i][j] != -1) b = b | num[i][j];
cout << b << " ";
}
cout << endl;
}
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
int a[110][110], num[110][40];
void conv(int i, int j, int num);
void cal(int ind);
int main() {
int i, j, k, l, test, t = 1, n;
scanf("%d", &n);
for (i = 1; i <= n; i++) {
for (j = 1; j <= n; j++) {
scanf("%d", &a[i][j]);
if (i == j) continue;
conv(i, j, a[i][j]);
}
}
for (i = 1; i <= n; i++) {
if (i > 1) printf(" ");
cal(i);
}
return 0;
}
void cal(int ind) {
int i, j, k, l;
int val = 0;
for (i = 30; i >= 0; i--) {
val *= 2;
if (num[ind][i] == 1) val++;
}
printf("%d", val);
}
void conv(int i, int j, int numb) {
int k, l;
k = 0;
while (numb) {
l = numb % 2;
if (l == 1) {
num[i][k] = 1;
num[j][k] = 1;
} else {
if (num[i][k] == 1) num[j][k] = 2;
if (num[j][k] == 1) num[i][k] = 2;
}
k++;
numb /= 2;
}
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
int a[105][105];
int bit[105][105];
int main() {
int n;
cin >> n;
memset(a, 0, sizeof(a));
memset(bit, 0, sizeof(bit));
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
cin >> a[i][j];
}
}
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n; j++) {
int sum = a[i][j];
int bit1 = 63;
while (sum) {
int s = sum % 2;
if (s == 1) {
bit[i][bit1] = 1;
bit[j][bit1] = 1;
}
sum /= 2;
bit1--;
}
}
}
for (int i = 1; i <= n; i++) {
int aa = 0;
for (int j = 0; j <= 63; j++) {
if (bit[i][j] == 1) {
aa = aa * 2 + 1;
} else
aa = aa * 2;
}
if (i == n)
cout << aa << endl;
else
cout << aa << " ";
}
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
const long double eps = 1e-9;
const double pi = acos(-1.0);
const long long inf = 1e18;
using namespace std;
int a[111], n;
int main(int argc, const char* argv[]) {
cin >> n;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++) {
int b;
scanf("%d", &b);
if (b != -1) a[i] = (a[i] | b), a[j] = (a[j] | b);
}
for (int i = 1; i <= n; i++) cout << a[i] << " ";
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
int a[101][101];
bool must[101][101];
int er[30];
void work(int x, int y, int z) {
int u = 0, u1 = 0;
while (z != 0) {
u = z % 2;
z /= 2;
u1++;
if (u == 1) must[x][u1] = must[y][u1] = true;
}
}
int main() {
int n;
scanf("%d", &n);
er[1] = 1;
for (int i = 2; i <= 30; i++) er[i] = er[i - 1] * 2;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++) scanf("%d", &a[i][j]);
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++) work(i, j, a[i][j]);
for (int i = 1; i <= n; i++) {
int u = 0;
for (int j = 1; j <= 30; j++)
if (must[i][j] == true) u += er[j];
printf("%d ", u);
}
printf("\n");
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, -1, 0, 1};
using namespace std;
int n;
int a[110][110];
void work() {
int ans;
for (int i = 1; i <= n; ++i) {
ans = 0;
for (int j = 1; j <= n; ++j)
if (j != i) ans = ans | a[i][j];
if (i == 1)
cout << ans;
else
cout << " " << ans;
}
cout << endl;
}
int main() {
while (cin >> n) {
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= n; ++j) {
cin >> a[i][j];
}
work();
}
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
int arr[123][123];
int main() {
ios_base::sync_with_stdio(0);
int N;
cin >> N;
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
cin >> arr[i][j];
}
}
for (int i = 0; i < N; i++) {
int x = 0;
for (int j = 0; j < N; j++) {
if (arr[i][j] != -1) x |= arr[i][j];
}
cout << x << endl;
}
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n;
char str[6000];
int pol1[6000];
int pol2[6000];
void p1() {
for (int i = 0; str[i]; ++i) {
for (int j = 0; i - j >= 0 && str[i + j]; ++j) {
if (str[i - j] == str[i + j]) {
++pol1[i];
} else {
break;
}
}
}
}
void p2() {
for (int i = 0; str[i]; ++i) {
for (int j = 0; i - j >= 0 && str[i + j + 1]; ++j) {
if (str[i - j] == str[i + j + 1]) {
++pol2[i];
} else {
break;
}
}
}
}
int fun1(int j, int a, int b) {
return min(min(pol1[j], j - a + 1), b - j + 1);
}
int fun2(int j, int a, int b) { return min(min(pol2[j], j - a + 1), b - j); }
int arr[5001][5001];
void init() {
for (int a = 0; str[a]; ++a) {
for (int b = a; str[b]; ++b) {
int sum = 0;
for (int j = a; j <= b; ++j) {
sum += fun1(j, a, b);
sum += fun2(j, a, b);
}
arr[a][b] = sum;
}
}
}
int sx[2], sy[2];
void zadacha() {
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
int t, x, y;
scanf("%d%d%d", &t, &x, &y);
sx[t - 1] += x;
sy[t - 1] += y;
}
if (sx[0] >= sy[0]) {
cout << "LIVE\n";
} else {
cout << "DEAD\n";
}
if (sx[1] >= sy[1]) {
cout << "LIVE\n";
} else {
cout << "DEAD\n";
}
}
void B() {
cin >> str;
int st = 3;
if (str[0] == 'f') {
cout << "ftp://";
st = 3;
} else {
cout << "http://";
st = 4;
}
int size = strlen(str);
int i = size - 1;
int en = 0;
for (; i >= 0; --i) {
if (str[i] == 'u' && str[i - 1] == 'r') {
en = i - 1;
break;
}
}
for (int j = st; j < en; ++j) {
cout << str[j];
}
cout << ".ru";
en += 2;
if (en != size) {
cout << '/';
}
for (int j = en; j < size; ++j) {
cout << str[j];
}
}
void C() {
cin >> str;
int m_plus = 0;
int m_minus = 0;
int plus = 0;
int minus = 0;
for (int i = 0; str[i]; ++i) {
if (str[i] == '+') {
plus++;
m_plus = max(m_plus, plus);
if (minus > 0) --minus;
} else {
minus++;
m_minus = max(m_minus, minus);
if (plus > 0) --plus;
}
}
cout << max(m_minus, m_plus);
}
int mas[101][101];
void D() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= n; ++j) {
scanf("%d", &mas[i][j]);
}
}
for (int i = 1; i <= n; ++i) {
int rez = 0;
for (int j = 1; j <= n; ++j) {
if (i == j) continue;
rez |= mas[i][j] | mas[j][i];
}
printf("%d ", rez);
}
}
int main() {
D();
return 0;
C();
return 0;
B();
return 0;
zadacha();
return 0;
scanf("%s", str);
p1();
p2();
scanf("%d", &n);
init();
for (int i = 0; i < n; ++i) {
int a, b;
scanf("%d%d", &a, &b);
--a;
--b;
printf("%d\n", arr[a][b]);
}
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
int a[200];
int main() {
int i, j, b, N;
scanf("%d", &N);
for (i = 0; i < N; i++)
for (j = 0; j < N; j++) {
scanf("%d", &b);
if (i == j) continue;
a[i] |= b;
a[j] |= b;
}
for (i = 0; i < N; i++) printf("%d ", a[i]);
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long n, a[1005][1005], ans[1005];
int main() {
ios::sync_with_stdio(0);
cin.tie();
cout.tie();
cin >> n;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> a[i][j];
if (i == j) continue;
ans[i] |= a[i][j];
}
}
for (int i = 0; i < n; i++) cout << ans[i] << " ";
cout << endl;
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
int f(int a, int b) { return a > b; }
int n;
int b[100][100][30];
int a[100][30];
int t[100];
int main(void) {
scanf("%d", &n);
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++) {
int x;
scanf("%d", &x);
if (x == -1) continue;
for (int k = 0; k < 30; k++)
if (x & (1 << k))
b[i][j][k] = 1;
else
b[i][j][k] = 0;
}
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
for (int k = 0; k < 30; k++)
if (b[i][j][k]) {
a[i][k] = 1;
a[j][k] = 1;
}
for (int i = 0; i < n; i++)
for (int k = 0; k < 30; k++)
if (a[i][k]) t[i] += 1 << k;
for (int i = 0; i < n; i++) cout << t[i] << " ";
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
int a[101][101];
int b[101];
int main() {
int n;
scanf("%d", &n);
memset(b, 0, sizeof(b));
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n; j++) {
scanf("%d", &a[i][j]);
if (i != j) b[i] |= a[i][j];
}
}
for (int i = 1; i < n; i++) printf("%d ", b[i]);
printf("%d\n", b[n]);
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, s[1005][1005], len;
int main() {
scanf("%d", &n);
int a;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++) {
scanf("%d", &a);
if (a == -1) continue;
int w = 0;
while (a) {
w++;
if (a % 2 == 1) s[i][w] = s[j][w] = 1;
a /= 2;
}
len = max(len, w);
}
for (int i = 1; i <= n; i++) {
int p = 0;
for (int j = len; j >= 1; j--) p = p * 2 + s[i][j];
printf("%d ", p);
}
printf("\n");
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int mas[105][105] = {0};
int n;
scanf("%d ", &n);
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
scanf("%d ", &mas[i][j]);
}
}
int res[105] = {0};
for (int i = 0; i < n; i++) {
int buf = 0;
for (int j = 0; j < n; j++) {
if (i == j) continue;
buf |= mas[i][j];
}
res[i] = buf;
}
for (int i = 0; i < n; i++) printf("%d ", res[i]);
printf("\n");
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
int a[102];
int main() {
int n, b;
scanf("%d", &n);
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++) {
scanf("%d", &b);
if (i == j) continue;
for (int k = 0; b; k++, b >>= 1) {
if (b & 1) {
a[i] |= 1 << k;
a[j] |= 1 << k;
}
}
}
for (int i = 0; i < n; i++) {
if (i) printf(" ");
printf("%d", a[i]);
}
puts("");
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
int n, ans[110], a[110][110][33];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= n; ++j) {
int p;
scanf("%d", &p);
for (int k = 0; k <= 30; ++k) a[i][j][k] = p & (1 << k);
}
for (int k = 0; k <= 30; ++k) {
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= n; ++j)
if ((i != j) && (a[i][j][k])) ans[i] |= 1 << k, ans[j] |= 1 << k;
}
for (int i = 1; i < n; ++i) printf("%d ", ans[i]);
printf("%d\n", ans[n]);
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
int a[n][n];
int b[n], ans = 0;
for (int i = 0; i < n; i++) {
ans = 0;
for (int j = 0; j < n; j++) {
cin >> a[i][j];
if (a[i][j] != -1) ans = ans | a[i][j];
}
b[i] = ans;
}
for (int i = 0; i < n; i++) {
cout << b[i] << " ";
}
cout << "\n";
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
int N;
int b[105][105];
int a[105];
int main() {
cin >> N;
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= N; j++) {
cin >> b[i][j];
}
}
for (int i = 1; i <= N; i++) {
for (int j = 1; j <= N; j++) {
if (i != j) {
a[i] = a[i] | b[i][j];
}
}
}
for (int i = 1; i <= N; i++) {
cout << a[i] << " ";
}
cout << endl;
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, a[200], b[150][150];
int main() {
cin >> n;
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j) cin >> b[i][j];
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j)
if (i != j) a[i] |= b[i][j];
for (int i = 0; i < n; ++i) cout << a[i] << " ";
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
int main() {
int n, i, j;
int b[142][142], a[142];
scanf("%d\n", &n);
for (i = 0; i < n; i++) {
scanf("%d", &b[i][0]);
a[i] = 0;
for (j = 1; j < n; j++) {
scanf(" %d", &b[i][j]);
}
scanf("\n");
}
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
if (i != j) a[i] |= b[i][j];
}
}
for (i = 0; i < n; i++) {
printf("%d ", a[i]);
}
putchar('\n');
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, at, sum;
int ati[110];
bool er[110][10010];
void ikilik(int a, int x, int y) {
while (a) {
++at;
if (a % 2) {
if (at > ati[x]) {
ati[x] = at;
}
if (at > ati[y]) {
ati[y] = at;
}
er[x][at] = 1;
er[y][at] = 1;
}
a /= 2;
}
}
void oku() {
int i, j, a, k;
scanf("%d", &n);
for (i = 1; i <= n; i++) {
for (j = 1; j <= n; j++) {
at = 0;
scanf("%d", &a);
if (i != j) {
ikilik(a, i, j);
}
}
}
for (i = 1; i <= n; i++) {
sum = 0;
for (j = 1, k = 1; j <= ati[i]; j++, k *= 2) {
sum += er[i][j] * k;
}
printf("%d ", sum);
}
puts("");
}
int main() {
oku();
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
const double pi = acos(-1.0);
const double eps = 1e-11;
const int p = 1000000007;
int countbit(int n) { return n == 0 ? 0 : countbit(n / 2) + n % 2; }
int lowbit(int n) { return (n ^ (n - 1)) & n; }
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
long long toInt64(string s) {
istringstream sin(s);
long long t;
sin >> t;
return t;
}
string toStr(long long t) {
stringstream sin;
sin << t;
string s;
sin >> s;
return s;
}
template <typename T>
T sqr(T n) {
return n * n;
}
template <typename T>
void out(T &v) {
for (int i = 0; i < v.size(); i++) cout << v[i] << ' ';
cout << endl;
}
class Timer {
public:
double start;
Timer() { start = static_cast<double>(clock()); }
void out() { cout << "TIME: " << (clock() - start) / CLOCKS_PER_SEC << endl; }
};
void set0(int &n, int k) { n = n & ~(1 << k); }
void set1(int &n, int k) { n = n | (1 << k); }
int get(int n, int k) { return (n >> k) % 2; }
void solve() {
int n;
cin >> n;
vector<vector<int> > b(n, vector<int>(n));
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++) cin >> b[i][j];
vector<int> a(n);
for (int bit = 0; bit < 32; bit++)
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
if (b[i][j] != -1 && get(b[i][j], bit) == 1) set1(a[i], bit);
for (int i = 0; i < n; i++) cout << a[i] << ' ';
cout << endl;
}
int main() {
cout.sync_with_stdio(false);
cin.sync_with_stdio(false);
solve();
return EXIT_SUCCESS;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 101;
int n, a[N][30];
long long nd[N][N], num[N];
int main() {
ios_base::sync_with_stdio(false);
cin >> n;
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= n; ++j) cin >> nd[i][j];
memset(a, 0, sizeof(a));
for (int i = 1; i <= n; ++i)
for (int j = i + 1; j <= n; ++j) {
int run = 29;
while (run >= 0) {
if (nd[i][j] & (1 << (29 - run))) a[i][run] = a[j][run] = 1;
--run;
}
}
for (int i = 1; i <= n; ++i)
for (int k = 0; k <= 29; ++k) num[i] += (1 << k) * (a[i][29 - k]);
for (int i = 1; i <= n; ++i) cout << num[i] << " ";
cout << "\n";
}
| 10 | CPP |
#include <bits/stdc++.h>
int bitmap[105][105];
int bitnum[105][32];
int num[105];
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++) scanf("%d", &bitmap[i][j]);
for (int i = 0; i < n; i++)
for (int j = i + 1; j < n; j++) {
int s = bitmap[i][j];
int k = 31;
while (s) {
if (s & 1) bitnum[i][k] = bitnum[j][k] = 1;
s = s / 2;
k--;
}
}
int ans = 0;
for (int i = 0; i < n; i++) {
ans = 0;
for (int j = 0; j < 32; j++) ans = ans * 2 + bitnum[i][j];
if (i == n - 1)
printf("%d\n", ans);
else
printf("%d ", ans);
}
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
void solve() {
int size = 0;
std::cin >> size;
std::vector<int> ans(size);
int curr = 0;
for (int i = 0; i < size; ++i) {
for (int j = 0; j < size; j++) {
std::cin >> curr;
if (curr != -1) {
ans[i] |= curr;
ans[j] |= curr;
}
}
}
for (int i = 0; i < size; ++i) {
std::cout << ans[i] << ' ';
}
std::cout << std::endl;
}
int main() { solve(); }
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
int data[109][109];
int ans[109][34];
int main(void) {
int i, j, k, n;
while (scanf("%d", &n) == 1) {
for (i = 1; i <= n; i++) {
for (j = 1; j <= n; j++) {
scanf("%d", &data[i][j]);
}
}
for (i = 1; i <= n; i++) {
for (j = 1; j <= n; j++) {
if (j == i) continue;
int t = data[i][j];
for (k = 32; t > 0; k--) {
if (t % 2 == 1) ans[i][k] = 1;
t /= 2;
}
}
}
for (i = 1; i <= n; i++) {
int tt = 0;
int k = 1;
for (j = 32; j >= 1; j--, k *= 2) {
if (ans[i][j] == 1) tt += k;
}
printf("%d ", tt);
}
}
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a[101][101];
int n, i, j, k;
cin >> n;
for (i = 0; i < n; i++)
for (j = 0; j < n; j++) cin >> a[i][j];
for (i = 0; i < n; i++) {
k = 0;
for (j = 0; j < n; j++)
if (i != j) k = k | a[i][j];
cout << k << " ";
}
cout << endl;
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
int a[110][110], n;
int main() {
cin >> n;
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++) cin >> a[i][j];
for (int i = 0; i < n; i++) {
int x = 0;
for (int j = 0; j < n; j++)
if (i != j) x |= a[i][j];
cout << x << " ";
}
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 100021;
long long int a[N];
int main() {
long long int n;
cin >> n;
for (long long int i = 1; i <= n; i++) {
for (long long int j = 1; j <= n; j++) {
long long int pp;
cin >> pp;
if (i != j) a[i] |= pp;
}
}
for (long long int i = 1; i <= n; i++) cout << a[i] << " ";
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
template <class T>
bool umin(T& a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
template <class T>
bool umax(T& a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
int a, b, c, d[1009][1009], n, m, rr[1009];
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
c = -1;
for (int j = 1; j <= n; j++) {
cin >> d[i][j];
if (i != j) {
if (c == -1)
c = d[i][j];
else
c |= d[i][j];
}
}
if (c == -1) c = 0;
rr[i] = c;
}
for (int i = 1; i <= n; i++) cout << rr[i] << " ";
cout << endl;
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
int main() {
int a[100];
int e, n, i, j;
scanf("%d", &n);
for (i = 0; i < n; i++) {
a[i] = 0;
}
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
scanf("%d", &e);
if (i >= j) {
continue;
}
a[i] |= e;
a[j] |= e;
}
}
for (i = 0; i < n; i++) {
printf("%d ", a[i]);
}
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
int c[100];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
int a;
cin >> a;
if (a != -1) c[i] = c[i] | a;
}
}
for (int i = 0; i < n; i++) cout << c[i] << " ";
cout << endl;
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
int gcd(int m, int n) {
if (n == 0) return m;
return gcd(n, m % n);
}
long long binpow(int a, int n) {
if (n == 0)
return 1;
else if (n % 2 == 1)
return binpow(a, n - 1) * a;
return binpow(a, n / 2) * binpow(a, n / 2);
}
vector<char> eratosphen(long long n) {
vector<char> prime(n + 1, true);
prime[0] = false;
prime[1] = false;
for (long long i = 2; i * i <= n; i++)
if (prime[i])
if (i * 1ll * i <= n)
for (long long j = i * i; j <= n; j += i) prime[j] = false;
return prime;
}
int g(int n) { return n ^ (n >> 1); }
double c(int n, int m) {
int B[500][500];
for (int i = 0; i <= n; ++i) {
B[i][0] = 1;
B[i][i] = 1;
for (int j = 1; j < i; ++j) {
B[i][j] = B[i - 1][j - 1] + B[i - 1][j];
}
}
return B[n][m];
}
const int inf = 100000005;
const int nax = 5005;
int degree[nax];
bool t[nax][nax];
int main() {
ifstream f("INPUT.TXT");
ofstream o("OUTPUT.TXT");
int n = 0;
long long r = 0;
long long a[100][100];
cin >> n;
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++) cin >> a[i][j];
for (int i = 0; i < n; i++) {
r = 0;
for (int j = 0; j < n; j++)
if (a[i][j] != -1) r |= a[i][j];
cout << r << " ";
}
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
int a[100 + 10];
int mat[110][110];
int main() {
int n, n1;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
a[i] = 0;
for (int j = 0; j < n; j++) {
scanf("%d", &n1);
mat[i][j] = n1;
if (i != j) {
a[i] = (a[i] | n1);
}
}
}
for (int i = 0; i < n; i++) cout << a[i] << " ";
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, b[105][105], a[105];
int main() {
cin >> n;
for (int i = 0; i < n; ++i)
for (int j = 0; j < n; ++j) {
cin >> b[i][j];
if (b[i][j] != -1) {
a[i] |= b[i][j];
a[j] |= b[i][j];
}
}
for (int i = 0; i < n; ++i) cout << max(a[i], 0) << ' ';
cout << endl;
}
| 10 | CPP |
#include <bits/stdc++.h>
int w[101][101], n, i, j, R[101];
int main() {
scanf("%d", &n);
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
scanf("%d", &w[i][j]);
}
for (j = 0; j < n; j++) {
if (i == j) continue;
R[i] = R[i] | w[i][j];
}
}
for (i = 0; i < n; i++) printf("%d ", R[i]);
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, i, j, k, x;
cin >> n;
vector<vector<int>> a(n, vector<int>(n));
vector<int> ans(n, 0);
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) cin >> a[i][j];
}
for (k = 0; k < 30; k++) {
x = 1 << k;
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
if ((i != j) && (a[i][j] & x)) {
ans[i] |= x;
ans[j] |= x;
}
}
}
}
for (i = 0; i < n; i++) cout << ans[i] << " ";
cout << "\n";
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
int f[105][105];
int a[105];
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= n; ++j) {
int x;
cin >> x;
if (i != j) a[i] |= x, a[j] |= x;
}
for (int i = 1; i <= n; ++i) cout << a[i] << ' ';
cout << endl;
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long i, x, p, n, j, ans[100];
int main() {
cin >> n;
long long nums[n][n];
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
cin >> nums[i][j];
}
}
if (n == 1) {
cout << 0;
return 0;
}
for (i = 0; i < n; i++) {
for (j = 0; j < n; j++) {
if (i != j) ans[i] = ans[i] | nums[i][j];
}
cout << ans[i] << " ";
}
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
int b[101][101];
int a[101];
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++) scanf("%d", b[i] + j);
for (int i = 0; i < n; i++)
for (int j = 0; j < i; j++) {
a[i] |= b[i][j];
a[j] |= b[i][j];
}
for (int i = 0; i < n; i++) printf("%d ", a[i]);
printf("\n");
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
bool solve() {
int n;
if (scanf("%d", &n) == EOF) return false;
int b[100][100];
for (int i = 0; i < n; ++i) {
int a = 0, x;
for (int j = 0; j < n; ++j) {
scanf("%d", &x);
if (i != j) a |= x;
}
printf("%d ", a);
}
return true;
}
int main() {
solve();
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long a[101], b[101][101], tmp;
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> tmp;
if (i == j) continue;
a[i] = a[i] | tmp;
}
}
for (int i = 0; i < n; i++) cout << a[i] << " ";
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
int main() {
int i, j, k, N;
int B[101][101];
scanf("%d", &N);
for (i = 1; i <= N; ++i) {
for (j = 1; j <= N; ++j) {
scanf("%d", &B[i][j]);
}
}
for (i = 1; i <= N; ++i) {
for (k = 0, j = 1; j <= N; ++j) {
if (i != j) {
k |= B[i][j];
}
}
printf("%d ", k);
}
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, x, ans = 0;
cin >> n;
for (int i = 0; i < n; i++) {
ans = 0;
for (int j = 0; j < n; j++) {
cin >> x;
if (x != -1) ans |= x;
}
cout << ans << " ";
}
return 0;
}
| 10 | CPP |
n = int(input())
if n > 1:
p = [0] * n
r = format(n - 1, 'b')[:: -1]
l = len(r) - 1
for i in range(n):
t = list(map(int, input().split()))
t.pop(i)
s = 0
for j in range(l):
if r[j] == '1': s |= t.pop()
t = [t[k] | t[k + 1] for k in range(0, len(t), 2)]
p[i] = s | t[0]
print(' '.join(map(str, p)))
else: print(0) | 10 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int t[150][150], a[150];
int main() {
int i, j, n;
while (cin >> n) {
memset(a, 0, sizeof(a));
for (i = 1; i <= n; i++)
for (j = 1; j <= n; j++) scanf("%d", &t[i][j]);
if (n == 1) {
printf("0\n");
continue;
}
for (i = 1; i <= n; i++) {
for (j = 1; j <= n; j++) {
if (i == j) continue;
a[i] = a[i] | t[i][j];
}
}
for (i = 1; i <= n; i++) {
printf("%d", a[i]);
if (i != n)
printf(" ");
else
printf("\n");
}
}
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a[105][105], b[105] = {0}, i, j;
cin >> n;
for (i = 1; i <= n; i++) {
for (j = 1; j <= n; j++) {
cin >> a[i][j];
if (i > 1 && j == 1 || i == 1 && j == 2) b[i] = a[i][j];
}
}
for (i = 1; i <= n; i++) {
for (j = 1; j <= n; j++) {
if (i != j) b[i] |= a[i][j];
}
}
for (i = 1; i <= n; i++) cout << b[i] << " ";
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int number = 0;
for (int j = 0; j < n; j++) {
int next;
cin >> next;
if (j != i) number |= next;
}
cout << number << " ";
}
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
scanf("%d", &n);
int ant;
scanf("%d", &ant);
int max_mes = 0;
for (int i = 1; i < n; i++) {
int aux;
scanf("%d", &aux);
if (aux < ant) max_mes = i;
ant = aux;
}
printf("%d\n", max_mes);
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int a[100010];
int main() {
int i, j, k, n;
cin >> n;
for (i = 0; i < n; i++) cin >> a[i];
for (i = n - 1; i > 0; i--)
if (a[i] < a[i - 1]) break;
printf("%d\n", i);
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int i = n - 1;
while (i > 0 && a[i - 1] < a[i]) {
i--;
}
cout << i << endl;
}
| 8 | CPP |
n = int(input())
arr = list(map(int,input().split()))
ans = n-1
for i in range(-1,-n,-1):
if arr[i]>arr[i-1]:
ans-=1
else:
break
print(ans) | 8 | PYTHON3 |
n = int(input())
l = [int(x) for x in input().split()]
l.reverse()
for i in range(1, n):
if l[i] > l[i - 1]:
print(n - i)
exit(0)
print(0)
| 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, a[200005], ans = 0, i;
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i];
for (i = n - 1; i >= 0; i--)
if (a[i] < a[i - 1]) break;
if (i < 0)
cout << 0;
else
cout << i;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
const long long mod = 1000000007;
using namespace std;
const int N = 2e5 + 5;
vector<int> e[N];
int vis[N], visi[N];
int pr[N];
int a;
long long binpow(long long a, long long b, long long m) {
if (a == 0) return a;
if (b == 0) return 1;
if (b == 1) return a % m;
long long temp = binpow(a, b / 2, m) % m;
if (b & 1) return (a * temp * temp) % m;
return (temp * temp) % m;
}
int k = -1;
void dfs(int i, int p) {
if (vis[i]) {
k = i;
return;
}
vis[i] = 1;
for (auto j : e[i]) {
if (j != p) {
dfs(j, i);
}
}
return;
}
void dfsi(int i, int p, int h) {
if (visi[i]) return;
visi[i] = 1;
pr[i] = p;
for (auto j : e[i]) {
if (j != p) {
if (j == h) {
pr[j] = i;
return;
}
dfsi(j, i, h);
}
}
return;
}
long long nck(long long n, long long k) {
long long g = 1;
map<long long, long long> m;
for (long long i = n - k + 1; i <= n; i++) {
g *= i;
for (long long j = 2; j <= k; j++) {
if (m[j] == 0 && g % j == 0) {
g /= j;
m[j]++;
}
}
}
return g;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int T = 1;
while (T--) {
int n;
cin >> n;
int a[n];
bool y = true;
for (int i = 0; i < n; i++) cin >> a[i];
int j = 0;
for (int i = n - 1; i > 0; i--) {
if (a[i] < a[i - 1]) {
j = i;
break;
}
}
cout << j << endl;
}
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n;
int a[131072];
int AnswerProblem;
int main() {
cin >> n;
int i;
for (i = 0; i < n; i++) cin >> a[i];
int mint = n;
for (i = n - 1; i >= 0; i--) {
if (a[i] > mint) AnswerProblem = max(AnswerProblem, i + 1);
if (a[i] < mint) mint = a[i];
}
cout << AnswerProblem << endl;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
int n;
int C[100005], a[100005];
inline int lowbit(int x) { return x & -x; }
void update(int x, int val) {
while (x <= n) {
C[x] += val;
x += lowbit(x);
}
}
int sum(int x) {
int res = 0;
while (x > 0) {
res += C[x];
x -= lowbit(x);
}
return res;
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
std::reverse(a + 1, a + n + 1);
int ans = 0;
for (int i = 1; i <= n; ++i) {
update(a[i], 1);
if (sum(a[i] - 1) > 0) {
printf("%d\n", n - i + 1);
return 0;
}
}
printf("0\n");
return 0;
}
| 8 | CPP |
n= int(input())
lista = input().split()
cont = 0
i = n-1
if n == 1:
print("0")
else:
while i > 0:
if int(lista[i]) > int(lista[i-1]):
cont += 1
i -= 1
if i == 0:
cont+= 1
else:
cont += 1
break
print(n-cont)
| 8 | PYTHON3 |
#include <bits/stdc++.h>
const int INF = (int)1e9;
int main() {
int n;
while (std::cin >> n) {
std::vector<int> arr(n);
for (auto& it : arr) {
std::cin >> it;
}
int min = INF, answ = 0;
for (int i = n - 1; i >= 0; --i) {
min = std::min(arr[i], min);
if (arr[i] > min) {
answ = i + 1;
break;
}
}
std::cout << answ << std::endl;
}
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int i, j, k, m[100005], n[100005];
int main() {
while (scanf("%d", &k) != EOF) {
for (i = 1; i <= k; i++) scanf("%d", &n[i]);
j = 0;
for (i = k; i >= 2; i--) {
if (n[i] > n[i - 1])
continue;
else {
j = i - 1;
break;
}
}
printf("%d\n", j);
}
return 0;
}
| 8 | CPP |
N = int(input())
X = list(map(int, input().split()))
Index = N-1
for i in range(N-1 , 0, -1):
if X[i] <X[i-1]:
print(i)
exit()
print(0)
# Hope the best for Ravens member
| 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int a[110000];
int main() {
int n;
cin >> n;
if (n == 1) {
cout << 0;
return 0;
}
int count = 1;
int ans = 0;
for (int i = 0; i < n; ++i) cin >> a[i];
for (int i = 0; i < n - 1; ++i) {
if (a[i + 1] > a[i])
count++;
else {
ans += count;
count = 1;
}
}
cout << ans;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, a[100001], res;
int main() {
scanf("%d", &n);
for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
res = n - 1;
for (int i = n - 2; i >= 0; --i)
if (a[i] < a[i + 1])
res = i;
else
break;
cout << res;
return 0;
}
| 8 | CPP |
n, ar = int(input()), [int(x) for x in input().split()][::-1]
ans = 0
for i in range(1, n):
if ar[i] > ar[i - 1]:
ans = n - i
break
print(ans)
| 8 | PYTHON3 |
n = int(input())
threads = list(map(int, input().split()))
count = 0
for i in range(n - 1):
if threads[i] > threads[i + 1]:
count = i + 1
print(count) | 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int v[1000000];
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%d", &v[i]);
int count = n - 1;
for (int i = n - 2; i >= 0; i--, count--) {
if (v[i] > v[i + 1]) break;
}
printf("%d\n", count);
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, arr[100005], i, ans = 0;
int main() {
cin >> n;
for (int i = 1; i <= n; i++) cin >> arr[i];
for (i = n - 1; i > 0; i--)
if (arr[i] >= arr[i + 1]) break;
cout << i << endl;
}
| 8 | CPP |
n=int(input())
arr=list(map(int,input().split()))
i=n-1
while arr[i]>arr[i-1]:
i-=1
print(i)
| 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a[100001], i, q = 0;
cin >> n;
for (i = 0; i < n; i++) cin >> a[i];
for (i = 0; i < n - 1; i++) {
if (a[i] > a[i + 1]) {
q = i + 1;
}
}
cout << q;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int c[100010];
int lowbit(int x) { return x & (-x); }
void add(int x) {
for (int i = x; i < 100010; i += lowbit(i)) c[i] += 1;
}
int sum(int x) {
int ret = 0;
for (int i = x; i > 0; i -= lowbit(i)) ret += c[i];
return ret;
}
int main() {
int n;
while (~scanf("%d", &n)) {
for (int i = 0; i < n; i++) {
scanf("%d", &c[i]);
}
if (n == 1) {
printf("0\n");
continue;
}
int num = 0;
for (int i = n - 2; i >= 0; i--)
if (c[i + 1] < c[i]) {
num = i + 1;
break;
}
printf("%d\n", num);
}
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int a[100010];
int main() {
int n;
scanf("%d", &n);
int i;
for (i = 1; i <= n; ++i) {
scanf("%d", &a[i]);
}
for (i = n - 1; i >= 1; --i) {
if (a[i] >= a[i + 1]) {
break;
}
}
cout << i << endl;
return 0;
}
| 8 | CPP |
n = int(input())
aux = input().split()
first = int(aux[0])
flag = 1
for i in range(1,n):
if int(aux[i]) < first: flag=1
else: flag+=1
first = int(aux[i])
print(n-flag)
| 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, A[100000], i, c = 1;
scanf("%d", &n);
for (i = 0; i < n; i++) scanf("%d", &A[i]);
for (i = n - 2; i >= 0; i--) {
if (A[i] < A[i + 1]) {
c++;
} else {
break;
}
}
printf("%d\n", n - c);
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
int arr[n];
int i = 0, cnt = 0;
for (i = 0; i < n; i++) {
cin >> arr[i];
}
for (i = 1; i < n; i++) {
if (arr[i] > arr[i - 1]) {
cnt++;
} else {
cnt = 0;
}
}
cnt++;
cout << n - cnt;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int cnt = 0;
int a[100100];
int n;
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i];
a[n] = 10000000;
for (int i = n - 1; i >= 0; i--)
if (a[i + 1] > a[i])
cnt++;
else
break;
cout << n - cnt << endl;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-9;
const int N = 1e3 + 2, M = 3e5 + 5, OO = 0x3f3f3f3f;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
vector<int> v(n + 1);
for (int i = 1; i <= n; ++i) cin >> v[i];
int l = n - 1;
while (l > 0 && v[l] < v[l + 1]) l--;
cout << l << '\n';
return 0;
}
| 8 | CPP |
n = int(input())
a = list(map(int,input().split()))
i = n-1
while(a[i] > a[i-1]):
i -= 1
print(i) | 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int arr[n];
for (int i = 0; i < n; i++) cin >> arr[i];
int count = 1;
for (int i = 0; i < n - 1; i++) {
if (arr[n - 1 - i] > arr[n - i - 2])
count++;
else
break;
}
cout << n - count << endl;
return 0;
}
| 8 | CPP |
n=int(input())
l=list(map(int,input().split()))
ans=-1
for i in range(n-1):
if l[i]>l[i+1]:
ans=i
print(ans+1) | 8 | PYTHON3 |
__author__ = 'asmn'
n=int(input())
a=list(reversed(list(map(int,input().split()))))
for i in range(1,len(a)):
if a[i]>a[i-1]:
print(len(a)-i)
break
else:
print(0)
| 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int arr[100002];
int main() {
ios::sync_with_stdio(false);
int n;
cin >> n;
for (int i = 0; i <= n - 1; ++i) cin >> arr[i];
int res = n - 1;
while (res > 0 && arr[res - 1] < arr[res]) --res;
cout << res << "\n";
return 0;
}
| 8 | CPP |
# ANDRE CHEKER BURIHAN RA 194071
noth = int(input())
oldpos = [int(num) for num in input().split()]
newpos = [i+1 for i in range(noth)]
counter = 0
if oldpos != newpos:
for i in reversed(range(1, noth)):
if oldpos[i-1] > oldpos[i]:
counter = i
break
print(counter)
| 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int a[100005];
set<int> s;
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
a[i] = -a[i];
}
for (int i = n - 1; i >= 0; i--) {
set<int>::iterator it = s.lower_bound(a[i]);
if (it != s.end()) {
cout << i + 1 << endl;
return 0;
}
s.insert(a[i]);
}
cout << 0 << endl;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long fact(long long n);
void swap(long long n, long long m);
long long check(long long n, long long a[], long long key);
void swap(long long a, long long b) {
int n;
n = a;
a = b;
b = n;
}
long long check(long long n, long long a[], long long key) {
long long s = 0, j;
long long e = n - 1;
while (s <= e) {
long long mid = (s + e) / 2;
if (a[mid] == key) {
if (a[mid] != a[mid + 1])
return mid;
else {
j = mid + 1;
while (a[mid] == a[j] && j <= n - 1) {
j++;
}
return j - 1;
}
}
if (a[mid] > key) {
if (mid > 0) {
if (a[mid - 1] <= key)
return mid - 1;
else
e = mid - 1;
} else {
return -1;
}
} else if (a[mid] < key) {
if (mid < n - 1) {
if (a[mid + 1] > key)
return mid;
else if (a[mid + 1] == key)
return mid + 1;
else
s = mid + 1;
} else {
return n - 1;
}
}
}
return -1;
}
long long po(long long x, long long y) {
long long res = 1;
while (y > 0) {
if (y & 1) res = res * x;
y = y >> 1;
x = x * x;
}
return res;
}
long long fact(long long n) {
long long i = 2, s = 1;
while (i <= n) {
s = s * i;
i++;
}
return s;
}
void cp() {}
int main() {
cp();
long long k = 0, i, c = 0, x = 0;
long long n;
cin >> n;
;
long long a[n];
for (int i = 0; i < n; i++) cin >> a[i];
;
for (i = n - 1; i >= 1; i--) {
if (a[i] < a[i - 1]) {
k = 1;
x = i;
break;
}
}
if (k == 1)
cout << x << endl;
else {
cout << "0" << endl;
}
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
const int MAXN = 100001;
int base[MAXN];
int a[MAXN];
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
int num = 0;
bool done = false;
for (int i = n - 1; i >= 1; --i) {
if (a[i - 1] > a[i]) {
done = true;
++num;
} else if (done) {
++num;
}
}
printf("%d\n", num);
return 0;
}
| 8 | CPP |
n = int(input())
t = list(map(int, input().split()))
i = n - 1
while t[i] > t[i - 1]: i -= 1
print(i) | 8 | PYTHON3 |
#include <bits/stdc++.h>
int main() {
int n, i;
int ans = 0;
scanf("%d", &n);
int a[n];
for (i = 0; i < n; i++) scanf("%d", &a[i]);
for (i = n - 2; i >= 0; i--)
if (a[i] < a[i + 1])
ans++;
else
break;
printf("%d\n", n - ans - 1);
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a[n];
int cnt = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int j = 0;
while (a[j] != 1) {
j++;
}
cnt = j;
int temp = 0;
for (int i = n - 1; i >= 0; i--) {
if (a[i] == 1) break;
if (i == n - 1)
temp++;
else if (a[i] < a[i + 1])
temp++;
else
break;
}
if (temp == n - 1 - j)
cout << cnt;
else
cout << cnt + n - j - temp;
return 0;
}
| 8 | CPP |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.