solution
stringlengths
11
983k
difficulty
int64
0
21
language
stringclasses
2 values
#include <bits/stdc++.h> const int INF = (int)(1e9); const long long INFLL = (long long)(1e18); const double EPS = 1e-13; using namespace std; int main() { ios_base::sync_with_stdio(false); int n; cin >> n; vector<int> nums(n), sorted(n); int diff = 0; for (int i = (0); i < (int)(n); i++) { cin >> nums[i]; sorted[i] = nums[i]; } sort((sorted).begin(), (sorted).end()); for (int i = (0); i < (int)(n); i++) { if (sorted[i] != nums[i]) diff++; } if (diff == 0 || diff == 2) cout << "YES\n"; else cout << "NO\n"; }
9
CPP
#include <bits/stdc++.h> using namespace std; int main() { int n; scanf("%d", &n); vector<int> v, vv; for (int i = 0; i < n; ++i) { int x; scanf("%d", &x); v.push_back(x); vv.push_back(x); } sort(vv.begin(), vv.end()); int cnt = 0; for (int i = 0; i < n; ++i) { if (v[i] != vv[i]) { cnt++; } } if (cnt < 3) cout << "YES"; else cout << "NO"; return 0; }
9
CPP
#include <bits/stdc++.h> using namespace std; struct IOS { struct Input { int readInt() { int x; scanf("%d", &x); return x; } long long readLong() { long long x; scanf("%lld", &x); return x; } char readChar() { char c; scanf("%c", &c); return c; } double readDouble() { double x; scanf("%lf", &x); return x; } string readString() { char str[100005]; scanf("%s", &str); return str; } void readIntArray(int* arr, int st, int en) { for (int i = st; i <= en; i++) arr[i] = readInt(); } } in; struct Output { void newLine() { printf("\n"); } } out; }; struct debugger { template <typename T> debugger& operator,(const T& v) { std::cout << v << ' '; return *this; } } dbg; int arr[100005], temp[100005]; int main(int argc, char const* argv[]) { IOS ios; int n = ios.in.readInt(); ios.in.readIntArray(arr, 0, n - 1); for (int i = 0; i <= n - 1; i++) temp[i] = arr[i]; sort(arr, arr + n); int res = 0; for (int i = 0; i <= n - 1; i++) res += (arr[i] != temp[i]); printf(res <= 2 ? "YES\n" : "NO\n"); return 0; }
9
CPP
n=int(input()) from itertools import permutations as pem List=list(map(int, input().split())) newlist=sorted(List) count=0 for i in range(n): if newlist[i]!=List[i]: count+=1 if count<=2: print("YES") else: print("NO")
9
PYTHON3
import sys input = sys.stdin.readline n = int(input()) a = list(map(int,input().split())) b = sorted(a) ans = 0 for i in range(n): if a[i] != b[i]: ans += 1 print('YES' if ans <= 2 else 'NO')
9
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false), cin.tie(0); int n; cin >> n; vector<int> sorted(n); vector<int> other(n); for (int i = 0; i < n; i++) { cin >> sorted[i]; other[i] = sorted[i]; } sort(sorted.begin(), sorted.end()); bool can = 1; for (int i = 0; i < n; i++) { if (sorted[i] != other[i]) { if (!can) { cout << "NO\n"; return 0; } for (int j = n - 1; j > i; j--) { if (other[j] == sorted[i]) { swap(other[j], other[i]); } } can = 0; } } cout << "YES\n"; return 0; }
9
CPP
n=int(input()) l=list(map(int,input().split())) d=sorted(l) c=0 for i in range(n): if(l[i]!=d[i]): c=c+1 if(c>2): print("NO") else: print("YES")
9
PYTHON3
#include <bits/stdc++.h> using namespace std; const int maxn = 100005; int n; int a[maxn], x[maxn]; bool ok() { for (int i = 0; i < n; ++i) { scanf("%d", &a[i]); x[i] = a[i]; } sort(x, x + n); int c = 0; for (int i = 0; i < n; ++i) { if (a[i] != x[i]) { ++c; } } return c <= 2; } int main() { scanf("%d", &n); printf("%s\n", ok() ? "YES" : "NO"); return 0; }
9
CPP
#include <bits/stdc++.h> using namespace std; ifstream Cin("input.txt"); ofstream Cout("output.txt"); int main() { long long n, x, i, num = 0, m[100001], m1[100001]; m[0] = m1[0] = 0; cin >> n; for (i = 1; i <= n; i++) { cin >> m[i]; m1[i] = m[i]; } sort(m, m + n + 1); for (i = 1; i <= n; i++) { if (m[i] != m1[i]) { num++; } } cout << (num <= 2 ? "YES" : "NO"); }
9
CPP
#include <bits/stdc++.h> using namespace std; int n, a[100010], b[100010]; int main() { scanf("%d", &n); for (int i = 1; i <= n; ++i) { scanf("%d", &a[i]); b[i] = a[i]; } sort(b + 1, b + n + 1); int cont = 0; for (int i = 1; i <= n; ++i) { if (b[i] != a[i]) { cont++; } } if (cont == 2 || cont == 0) { printf("YES"); } else { printf("NO"); } return 0; }
9
CPP
#include <bits/stdc++.h> using namespace std; using vl = vector<long long>; using vpl = vector<pair<long long, long long>>; using vs = vector<string>; using pl = pair<long long, long long>; using ll = long long int; using vb = vector<bool>; void printcase(ll x) { cout << "Case #" << x << ": "; } void read(vector<ll> &v, ll &n) { for (ll i = 0; i < n; ++i) cin >> v[i]; } void read(ll a[], ll &n) { for (ll i = 0; i < n; ++i) cin >> a[i]; } void print() { cout << endl; } void write(vector<ll> &v, ll &n) { for (ll i = 0; i < n; ++i) cout << v[i] << " "; cout << endl; } void write(vector<ll> &v) { ll n = v.size(); for (ll i = 0; i < n; ++i) cout << v[i] << " "; cout << endl; } void write(ll a[], ll &n) { for (ll i = 0; i < n; ++i) cout << a[i] << " "; cout << endl; } bool sorted(vl &v) { ll n = v.size(); for (int i = 0; i < n - 1; i++) { if (v[i] > v[i + 1]) return 0; } return 1; } bool solve() { ll n; cin >> n; vl v(n); read(v, n); if (n <= 2) return 1; vl suff(n), suffind(n), preind(n); suff[n - 1] = v[n - 1]; suffind[n - 1] = n - 1; preind[0] = 0; for (int i = 1; i < n; i++) { if (v[i] == v[i - 1]) preind[i] = preind[i - 1]; else preind[i] = i; } for (int i = n - 2; i >= 0; i--) { if (v[i] < suff[i + 1]) suffind[i] = i; else suffind[i] = suffind[i + 1]; suff[i] = min(v[i], suff[i + 1]); } for (int i = 0; i < n - 1; i++) { if (v[i] > v[i + 1]) { swap(v[preind[i]], v[suffind[i + 1]]); if (sorted(v)) return 1; else return 0; } } return 1; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; if (solve()) cout << "YES" << endl; else cout << "NO" << endl; return 0; }
9
CPP
#include <bits/stdc++.h> using namespace std; int main() { int a[100005] = {0}; int b[100005] = {0}; int n, i; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &a[i]); b[i] = a[i]; } sort(b, b + n); int ret = 0; for (int i = 0; i < n; i++) { if (b[i] != a[i]) ret++; } if (ret <= 2) { printf("YES"); } else { printf("NO"); } }
9
CPP
#include <bits/stdc++.h> using namespace std; map<int, int> mp; int main() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(0); int n, cnt = 0, tk; cin >> n; vector<int> vc, s; for (int i = 1; i <= n; i++) cin >> tk, vc.push_back(tk), s.push_back(tk); sort(s.begin(), s.end()); for (int i = 0; i < n; i++) { if (vc[i] != s[i]) cnt++; } if (cnt > 2) puts("NO"); else puts("YES"); }
9
CPP
#include <bits/stdc++.h> using namespace std; struct IOS { struct Input { int readInt() { int x; scanf("%d", &x); return x; } long long readLong() { long long x; scanf("%lld", &x); return x; } char readChar() { char c; scanf("%c", &c); return c; } double readDouble() { double x; scanf("%lf", &x); return x; } string readString() { char str[100005]; scanf("%s", &str); return str; } void readIntArray(int* arr, int st, int en) { for (int i = st; i <= en; i++) arr[i] = readInt(); } } in; struct Output { void newLine() { printf("\n"); } } out; }; struct debugger { template <typename T> debugger& operator,(const T& v) { std::cout << v << ' '; return *this; } } dbg; int arr[100005], temp[100005]; int main(int argc, char const* argv[]) { IOS ios; int n = ios.in.readInt(); ios.in.readIntArray(arr, 0, n - 1); for (int i = 0; i <= n - 1; i++) temp[i] = arr[i]; sort(arr, arr + n); int res = 0; for (int i = 0; i <= n - 1; i++) res += (arr[i] != temp[i]); if (res <= 2) printf("YES\n"); else printf("NO\n"); return 0; }
9
CPP
#include <bits/stdc++.h> using namespace std; int n, a[100000], b[100000]; int main() { scanf("%d", &n); for (int i = -1; ++i != n; b[i] = a[i]) scanf("%d", a + i); sort(a, a + n); int ans = 0; for (int i = -1; ++i != n;) ans += a[i] != b[i]; puts(ans > 2 ? "NO" : "YES"); return 0; }
9
CPP
#include <bits/stdc++.h> using namespace std; int a[100002], s[100002]; int main() { int n; while (scanf("%d", &n) != EOF) { int i; int k, mx = 1000000000; int f = 0; for (i = 0; i < n; i++) { scanf("%d", &a[i]); s[i] = a[i]; } sort(a, a + n); for (i = 0; i < n; i++) { if (s[i] != a[i]) f++; } if (f > 2) printf("NO\n"); else printf("YES\n"); } return 0; }
9
CPP
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> arr(n); vector<int> sorted(n); for (int i = 0; i < n; i++) { cin >> arr[i]; sorted[i] = arr[i]; } int c = 0; sort(sorted.begin(), sorted.end()); for (int i = 0; i < n; i++) { if (arr[i] != sorted[i]) { c++; } } if (c <= 2) { cout << "YES" << endl; } else { cout << "NO" << endl; } return 0; }
9
CPP
#https://codeforces.com/contest/221/problem/C n=int(input()) a=list(map(int,input().split(' '))) b=[] for i in range(n): b.append(a[i]) b.sort() q=0 R=[] bhul=True for i in range(n): if a[i]!=b[i]: if q>=2: print('NO') bhul=False break else: q+=1 R.append(i) if bhul: if q==0: print('YES') elif q==2: print('YES') else: print('NO')
9
PYTHON3
#include <bits/stdc++.h> using namespace std; int n, m, k, i, c, b, a, energy, ans, s, j, w[2555555], l[2555555], kol; pair<int, int> p[2555555]; int main() { cin >> n; for (i = 1; i <= n; i++) { cin >> w[i]; l[i] = w[i]; } sort(w + 1, w + 1 + n); for (i = 1; i <= n; i++) { if (l[i] != w[i]) a++; if (a > 2) { cout << "NO"; return 0; } } cout << "YES"; return 0; }
9
CPP
#include <bits/stdc++.h> using namespace std; int main() { int a[100050]; int b[100050]; int n; scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &a[i]); b[i] = a[i]; } sort(b, b + n); int ans = 0; for (int i = 0; i < n; i++) if (b[i] != a[i]) ans++; if (ans <= 2) printf("YES"); else printf("NO"); printf("\n"); return 0; }
9
CPP
#include <bits/stdc++.h> using namespace std; long long fpow(long long n, long long k, long long p = 1000000007) { long long r = 1; for (; k; k >>= 1) { if (k & 1) r = r * n % p; n = n * n % p; } return r; } long long inv(long long a, long long p = 1000000007 - 1) { return fpow(a, p - 2, p); } long long Sqrt(long long x) { if (x == 0 || x == 1) return x; long long start = 1, end = x, ans; while (start <= end) { long long mid = (start + end) / 2; if (mid * mid == x) return mid; if (mid * mid < x) { start = mid + 1; ans = mid; } else end = mid - 1; } return ans; } long long power(long long x, long long y) { if (y == 0) return 1; else if (y % 2 == 0) return power(x, y / 2) * power(x, y / 2); else return x * power(x, y / 2) * power(x, y / 2); } long long gcd(long long a, long long b) { long long r; while (b) { r = a % b; a = b; b = r; } return a; } long long lcm(long long a, long long b) { return a / gcd(a, b) * b; } void in(long long &no) { bool neg = false; register long long c; no = 0; c = getchar(); if (c == '-') { neg = true; c = getchar(); } for (; (c > 47 && c < 58); c = getchar()) no = no * 10 + c - 48; if (neg) no *= -1; } long long maxx(long long a, long long b) { if (a > b) return a; return b; } long long minn(long long a, long long b) { if (a < b) return a; return b; } int main() { long long n; cin >> n; long long a[n], b[n]; for (int i = (0); i < (n); i++) { cin >> a[i]; b[i] = a[i]; } sort(b, b + n); long long cnt = 0; for (int i = (0); i < (n); i++) { if (a[i] != b[i]) cnt++; } if (cnt > 2) cout << "NO"; else cout << "YES"; return 0; }
9
CPP
def arr_inp(n): if n == 1: return [int(x) for x in stdin.readline().split()] elif n == 2: return [float(x) for x in stdin.readline().split()] else: return [str(x) for x in stdin.readline().split()] from sys import stdin n, a = int(input()), arr_inp(1) a1, c, ix = sorted(a.copy()), 0, 0 for i in range(n): if a[i] != a1[i]: if c == 0: c += 1 ix = i elif c > 2: exit(print('NO')) else: if a1[ix] == a[i]: c += 1 else: exit(print('NO')) print('YES')
9
PYTHON3
n=int(input()) l=[int(i) for i in input().split()] l1=sorted(l) c=0 for i in range(n): if(l1[i]!=l[i]): c+=1 if(c>2): print("NO") else: print("YES")
9
PYTHON3
#include <bits/stdc++.h> using namespace std; string itoa_cpp(int value, int base) { string buf; if (base < 2 || base > 16) return buf; enum { kMaxDigits = 35 }; buf.reserve(kMaxDigits); int quotient = value; do { buf += "0123456789abcdef"[std::abs(quotient % base)]; quotient /= base; } while (quotient); if (value < 0) buf += '-'; reverse(buf.begin(), buf.end()); return buf; } int main() { int n = ({ int x; scanf("%d", &x); x; }); vector<int> a; for (int i = 0; i < n; i++) a.push_back(({ int x; scanf("%d", &x); x; })); int i, last_pos = 0; for (int i = 0; i < n - 1; i++) { if (a[i] < a[i + 1]) last_pos = i + 1; if (a[i] > a[i + 1]) { int min_pos = i + 1; for (int j = i + 2; j < n; j++) if (a[j] <= a[min_pos]) min_pos = j; swap(a[last_pos], a[min_pos]); break; } } for (i = 0; i < n - 1; i++) if (a[i] > a[i + 1]) { printf("NO"); break; } if (i == n - 1) printf("YES"); return 0; }
9
CPP
#include <bits/stdc++.h> using namespace std; int a[1000 * 100 + 22], b[1000 * 100 + 22]; int main() { int n, k = 0; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; b[i] = a[i]; } sort(a, a + n); for (int i = 0; i < n; i++) if (a[i] != b[i]) k++; if (k > 2) cout << "NO" << endl; else cout << "YES" << endl; return 0; }
9
CPP
import sys import math import itertools import functools import collections def ii(): return int(input()) def mi(): return map(int, input().split()) def li(): return list(map(int, input().split())) def lcm(a, b): return abs(a * b) // math.gcd(a, b) def wr(arr): return ' '.join(map(str, arr)) def revn(n): return str(n)[::-1] def dd(): return collections.defaultdict(int) def ddl(): return collections.defaultdict(list) def sieve(n): if n < 2: return list() prime = [True for _ in range(n + 1)] p = 3 while p * p <= n: if prime[p]: for i in range(p * 2, n + 1, p): prime[i] = False p += 2 r = [2] for p in range(3, n + 1, 2): if prime[p]: r.append(p) return r def divs(n, start=1): r = [] for i in range(start, int(math.sqrt(n) + 1)): if (n % i == 0): if (n / i == i): r.append(i) else: r.extend([i, n // i]) return r def divn(n, primes): divs_number = 1 for i in primes: if n == 1: return divs_number t = 1 while n % i == 0: t += 1 n //= i divs_number *= t def prime(n): if n == 2: return True if n % 2 == 0 or n <= 1: return False sqr = int(math.sqrt(n)) + 1 for d in range(3, sqr, 2): if n % d == 0: return False return True def convn(number, base): newnumber = 0 while number > 0: newnumber += number % base number //= base return newnumber def cdiv(n, k): return n // k + (n % k != 0) n = ii() a = li() b = sorted(a) ans = 0 for i in range(n): if a[i] != b[i]: ans += 1 if ans == 0 or ans == 2: print('YES') else: print('NO')
9
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int n; while (cin >> n) { int *arr = new int[n]; int *sorted = new int[n]; for (int i = 0; i < n; i++) { cin >> arr[i]; sorted[i] = arr[i]; } int c = 0; sort(sorted, sorted + n); for (int i = 0; i < n; i++) { if (arr[i] != sorted[i]) { c++; } } if (c <= 2) { cout << "YES" << endl; } else { cout << "NO" << endl; } delete[] arr; } return 0; }
9
CPP
#include <bits/stdc++.h> using namespace std; void file() {} void fast() { std::ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); } long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); } long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; } int dx[] = {0, 0, 1, -1, 1, 1, -1, -1}; int dy[] = {1, -1, 0, 0, 1, -1, 1, -1}; int main() { file(); fast(); int n; cin >> n; vector<int> a(n), s; for (int i = 0; i < n; i++) cin >> a[i]; s = a; sort(s.begin(), s.end()); vector<int> v; for (int i = 0; i < n && v.size() < 5; i++) if (a[i] != s[i]) v.push_back(i); if (v.size() == 0) { cout << "YES"; return 0; } if (v.size() != 2) { cout << "NO"; return 0; } if (a[v[0]] == s[v[1]] && a[v[1]] == s[v[0]]) cout << "YES"; else cout << "NO"; }
9
CPP
#include <bits/stdc++.h> using namespace std; const int oo = (int)1e9; const double PI = 2 * acos(0.0); const double eps = 1e-9; int main() { int n; while (cin >> n) { vector<int> v(n); for (int i = 0; i < (int)(n); i++) cin >> v[i]; vector<int> b = v; sort(b.begin(), b.end()); int cnt = 0; for (int i = 0; i < (int)(n); i++) cnt += v[i] != b[i]; if (cnt <= 2) cout << "YES" << endl; else cout << "NO" << endl; } return 0; }
9
CPP
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const int infi = INT_MAX; const long long infll = LLONG_MAX; const long double PI = 3.1415926535897932384626; void solve(int test_case) { int n; cin >> n; vector<int> v; vector<int> v2; for (int i = 0; i < n; ++i) { int t; cin >> t; v.push_back(t); v2.push_back(t); } sort((v2).begin(), (v2).end()); int cnt = 0; for (int i = 0; i < n; ++i) { if (v[i] != v2[i]) ++cnt; } if (cnt <= 2) cout << "YES"; else cout << "NO"; } int main() { ios_base ::sync_with_stdio(false); cin.tie(0); cout.tie(0); int tc = 1; while (tc--) solve(tc); return 0; }
9
CPP
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a, b; while (n--) { int c; cin >> c; a.push_back(c); b.push_back(c); } sort(a.begin(), a.end()); int diffs = 0; for (int i = 0; i < (int)a.size(); ++i) { if (a[i] != b[i]) { diffs++; } } if (diffs <= 2) { cout << "YES" << endl; } else { cout << "NO" << endl; } return 0; }
9
CPP
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a(n), b(n), diff; for (int i = 0; i < n; ++i) { cin >> a[i]; b[i] = a[i]; } sort(b.begin(), b.end()); for (int i = 0; i < n; ++i) if (a[i] != b[i]) diff.push_back(i); if (diff.size() == 0) { cout << "YES" << endl; return 0; } if (diff.size() > 2 || diff.size() == 1) { cout << "NO" << endl; return 0; } if (a[diff[0]] == b[diff[1]] && a[diff[1]] == b[diff[0]]) { cout << "YES" << endl; return 0; } cout << "NO" << endl; return 0; }
9
CPP
#include <bits/stdc++.h> using namespace std; int main() { int n, cnt = 0; cin >> n; vector<int> arr(n), b(n); for (int i = 0; i < n; i++) cin >> arr[i], b[i] = arr[i]; sort(b.begin(), b.end()); for (int i = 0; i < n; i++) if (b[i] != arr[i]) cnt++; printf("%s\n", cnt <= 2 ? "YES" : "NO"); return 0; }
9
CPP
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } int lcm(int a, int b) { return (int)a * (b / gcd(a, b)); } int ara[100000 + 10], temp[100000 + 10]; int n; bool ok() { for (int i = 0; i < n - 1; i++) { if (ara[i] > ara[i + 1]) return false; } return true; } int main() { scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &ara[i]); temp[i] = ara[i]; } int left = 0, right = n - 1; if (ok()) { printf("YES\n"); return 0; } sort(ara, ara + n); for (int i = 0; i < n; i++) { if (ara[i] != temp[i]) left++; } if (left > 2) printf("NO\n"); else printf("YES\n"); return 0; }
9
CPP
#include <bits/stdc++.h> using namespace std; template <class T> T abs(T x) { return x > 0 ? x : -x; } inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; } inline long long toll(string s) { long long v; istringstream sin(s); sin >> v; return v; } template <class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); } template <class T> inline T sqr(T x) { return x * x; } template <class T> inline T gcd(T a, T b) { if (a < 0) a = -a; if (b < 0) b = -b; return (b == 0) ? a : gcd(b, a % b); } template <class T> inline T lcm(T a, T b) { return a * (b / gcd(a, b)); } int main() { int n, i, c = 0, f, s; cin >> n; vector<int> A(n), tmp(n); for ((i) = 0; (int)(i) < (n); (i)++) { cin >> A[i]; tmp[i] = A[i]; } sort(A.begin(), A.end()); for ((i) = 0; (int)(i) < (n); (i)++) { if (A[i] != tmp[i]) { c++; } } if (c <= 2) { cout << "YES\n"; } else { cout << "NO\n"; } return 0; }
9
CPP
#include <bits/stdc++.h> using namespace std; int a[200005]; int b[200005]; int main() { int n; cin >> n; int i, j; for (i = 0; i < n; i++) { cin >> a[i]; b[i] = a[i]; } sort(b, b + n); int cnt = 0; for (i = 0; i < n; i++) { if (a[i] != b[i]) cnt++; } if (cnt > 2) cout << "NO" << endl; else cout << "YES" << endl; return 0; }
9
CPP
#include <bits/stdc++.h> using namespace std; const int Maxn = 100000 + 10; const int INF = 0x7f7f7f7f; const double eps = 1e-10; const double pi = acos(-1.0); inline int realcmp(double a, double b) { return (a > b + eps) ? 1 : ((a + eps < b) ? -1 : 0); } int a[Maxn], b[Maxn]; int main() { int cnt = 0, n; ios::sync_with_stdio(0); cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; b[i] = a[i]; } sort(a, a + n); for (int i = 0; i < n; i++) if (a[i] != b[i]) cnt++; if (cnt <= 2) printf("YES\n"); else printf("NO\n"); return 0; }
9
CPP
#include <bits/stdc++.h> using namespace std; int n; void EXEC() { cin >> n; for (int i = 0; i < n; ++i) { int s = 0; int t; for (int j = 0; j < n; ++j) { cin >> t; if (t != -1) s |= t; } cout << s << ' '; } cout << endl; } int main() { EXEC(); return 0; }
10
CPP
#include <bits/stdc++.h> int main() { int n, i, j; int a[110][110]; long long ans[150]; while (scanf("%d", &n) != EOF) { for (i = 1; i <= n; i++) for (j = 1; j <= n; j++) scanf("%d", &a[i][j]); memset(ans, 0, sizeof(ans)); for (i = 1; i <= n; i++) { for (j = 1; j <= n; j++) { if (i == j) continue; if (a[i][j] == -1) continue; ans[i] = ans[i] | a[i][j]; } } for (i = 1; i <= n; i++) if (i == 1) printf("%I64d", ans[i]); else printf(" %I64d", ans[i]); printf("\n"); } return 0; }
10
CPP
#include <bits/stdc++.h> using namespace std; long long in() { int32_t x; scanf("%d", &x); return x; } const long long maxn = 100 + 10; const long long inf = 1e9 + 10; const long long mod = 1e9 + 7; long long b[maxn][maxn], a[maxn]; int32_t main() { long long n = in(); for (long long i = 0; i < n; i++) { for (long long j = 0; j < n; j++) { b[i][j] = in(); if (i - j) for (long long x = 0; x < 30; x++) { if (b[i][j] >> x & 1) a[i] |= (1 << x), a[j] |= (1 << x); } } } for (long long i = 0; i < n; i++) cout << a[i] << " "; }
10
CPP
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); } long long lcm(long long a, long long b) { return (a / gcd(a, b) * b); } long long ncr(long long n, long long r) { long long res = 1; if (r > n) return 0; if (r > n - r) r = n - r; for (long long i = 0; i < r; i++) { res *= (n - i); res /= (i + 1); } return res; } vector<long long> factors(long long n) { vector<long long> f; for (long long x = 2; x * x <= n; x++) { while (n % x == 0) { f.push_back(x); n /= x; } } if (n > 1) f.push_back(n); return f; } struct cor { int x, y; }; const int MaxN = 4e5 + 10; const int MAXN = 120 * 1000; int cD(long long n) { return floor(log10(n) + 1); } long long front[MaxN] = {0}, back[MaxN] = {0}; long long last = 1000000000007; long long y, x2, x3, sum = 0, sum2 = 0, i, j, g, t, mid; long long d1 = 0, d2 = 0; long long x, n, k, q, r, m; long long l; const int mod = 998244353; string s; long long power(long long x, long long y) { int res = 1; x = x % mod; while (y > 0) { if (y & 1) res = (res * x) % mod; y = y >> 1; x = (x * x) % mod; } return res; } long long n1, n2, nc, pc, h, zc, l2, l3, l4; const int No = 3e5 + 5; pair<long long, long long> p[No]; long long an, bn, cn, dn; long long a[101][101]; long long b[MaxN]; void pcheck(long long a) { for (long long i = 2; i <= sqrt(a); i++) { if (a % i == 0) { b[i]++; if (a / i > sqrt(a)) b[a / i]++; } } b[a]++; } int main() { ios_base::sync_with_stdio(false); long long n; 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++) { m = 0; for (int j = (0); j < (n); j++) { if (i != j) b[i] = b[i] | a[i][j]; } } for (int i = (0); i < (n); i++) cout << b[i] << " "; return 0; }
10
CPP
#include <bits/stdc++.h> using namespace std; int num[105]; int main() { int n; while (cin >> n) { int a; memset(num, 0, sizeof(num)); for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) { scanf("%d", &a); if (a != -1) num[i] |= a; } printf("%d", num[0]); for (int i = 1; i < n; i++) printf(" %d", num[i]); cout << endl; } return 0; }
10
CPP
#include <bits/stdc++.h> using namespace std; const int N = 2e3 + 7; int n, a[N][N], ans[N]; int main() { cin >> n; 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 = 1; j <= n; ++j) if (i != j) ans[i] |= a[i][j]; } for (int i = 1; i <= n; ++i) cout << ans[i] << " "; return 0; }
10
CPP
#include <bits/stdc++.h> int n, i, j, k, x, a[200]; int main() { scanf("%d", &n); for (i = 0; i < n; i++) for (j = 0; j < n; j++) { scanf("%d", &x); if (i != j) for (k = 30; k >= 0; k--) if (x >> k & 1) { a[i] |= 1 << k; a[j] |= 1 << k; } } for (i = 0; i < n; i++) printf("%d ", a[i]); puts(""); return 0; }
10
CPP
#include <bits/stdc++.h> using namespace std; const int N = 105; int n; int M[N][N]; int P[N]; inline void load() { scanf("%d", &n); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { scanf("%d", &M[i][j]); } } } inline bool check(int x) { P[0] = x; for (int i = 1; i < n; i++) P[i] = M[0][i] & x; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (i != j && (P[i] & P[j]) != M[i][j]) return false; } } return true; } inline void solve() { for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (i != j) P[i] |= M[i][j], P[j] |= M[i][j]; } } for (int i = 0; i < n; i++) printf("%d ", P[i]); printf("\n"); } int main(void) { load(); solve(); return 0; }
10
CPP
#include <bits/stdc++.h> using namespace std; int ar[101][101], br[101]; void solve() { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) scanf("%d", &ar[i][j]); for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { if (i == j) continue; int e = ar[i][j]; int k = 0; while (e) { bool z = e & 1; if (z) { br[i] |= (1 << k); br[j] |= (1 << k); } e >>= 1; k++; } } } for (int i = 1; i <= n; i++) printf("%d ", br[i]); printf("\n"); } signed main() { solve(); return 0; }
10
CPP
#include <bits/stdc++.h> using namespace std; int main() { int n; int i; int j; cin >> n; int arr[n + 4][n + 4]; int ans[n + 1]; for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { cin >> arr[i][j]; } } for (i = 0; i < n; i++) { ans[i] = 0; for (j = 0; j < n; j++) { if (i != j) { ans[i] = ans[i] | arr[i][j]; } } cout << ans[i] << " "; } puts(""); return 0; }
10
CPP
#include <bits/stdc++.h> using namespace std; const int MOD = 1e6 + 3; const int INFI = 1e9 * 2; const long long LINFI = 1e17; const double pi = acos(-1.0); const int N = 111; const int M = 222222; const int move[8][2] = {1, 0, -1, 0, 0, 1, 0, -1, 1, 1, 1, -1, -1, 1, -1, -1}; int a[N][N]; int main() { int n, m; while (scanf("%d", &n) != EOF) { for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) scanf("%d", &a[i][j]); if (n == 1) printf("%d\n", 0); else { for (int i = 0; i < n; i++) { m = 0; for (int j = 0; j < n; j++) if (i != j) m |= a[i][j]; printf("%d ", m); } printf("\n"); } } return 0; }
10
CPP
#include <bits/stdc++.h> using namespace std; const int N = 1005; int n; int a[N][N]; int num[N]; int main() { scanf("%d", &n); for (int i = 1; i <= n; ++i) for (int j = 1; j <= n; ++j) { scanf("%d", &a[i][j]); if (i == j) continue; num[i] |= a[i][j]; num[j] |= a[i][j]; } for (int i = 1; i <= n; ++i) printf("%d ", num[i]); return 0; }
10
CPP
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); int n; cin >> n; int mat[n][n]; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) cin >> mat[i][j]; for (int i = 0; i < n; i++) { long long cur = 0; for (int j = 0; j < n; j++) { if (j != i) { for (int k = 0; k < 32; k++) { if ((1LL << k) & mat[i][j]) cur |= (1LL << k); } } } cout << cur << " "; } cout << endl; return 0; }
10
CPP
#include <bits/stdc++.h> using namespace std; int main() { bitset<32> a[110]; int b[110][110]; int n; scanf("%d", &n); for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) scanf("%d", &b[i][j]); for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { if (i != j) { int t = b[i][j], bit = 0; while (t) { int res = t % 2; t /= 2; if (res == 1) { a[i].set(bit, res); a[j].set(bit, res); } bit++; } } } } for (int i = 1; i <= n; i++) { printf("%d ", a[i].to_ulong()); } return 0; }
10
CPP
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:500000000") using namespace std; int A[111]; int main() { int n, i, j, a; scanf("%d", &n); for (i = 0; i < n; i++) { int v = 0; for (j = 0; j < n; j++) { scanf("%d", &a); if (i != j) v |= a; } A[i] = v; } printf("%d", A[0]); for (int i = 1; i < n; i++) printf(" %d", A[i]); puts(""); }
10
CPP
#include <bits/stdc++.h> int main() { int n; scanf("%d", &n); int a; for (int i = 0; i != n; ++i) { int o = 0; for (int j = 0; j != n; ++j) { scanf("%d", &a); if (i != j) o |= a; } printf("%d ", o); } putchar('\n'); return 0; }
10
CPP
#include <bits/stdc++.h> using namespace std; int main() { int n, r, b, i, j; cin >> n; for (i = 0; i < n; ++i) { r = 0; for (j = 0; j < n; ++j) { cin >> b; if (b != -1) r |= b; } cout << r << ' '; } return 0; }
10
CPP
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; long long n, v[20001], maxim, nr0, nr1, nr11, x, y, a[1001][1001], ans[200001]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n; for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) { cin >> x; if (i != j) ans[i] = ans[i] | x; } for (int i = 1; i <= n; i++) cout << ans[i] << ' '; return 0; }
10
CPP
#include <bits/stdc++.h> using namespace std; int s[110][110], n; int main() { while (cin >> n) { for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { cin >> s[i][j]; } } for (int i = 1; i <= n; i++) { int a = 0; for (int j = 1; j <= n; j++) if (s[i][j] != -1) a |= s[i][j]; cout << a << " "; } cout << endl; } return 0; }
10
CPP
#include <bits/stdc++.h> using namespace std; int n; int in[110][110]; int ans[110]; int main() { scanf("%d", &n); for (int i = 0; i < n; ++i) { for (int j = 0; j < n; ++j) { scanf("%d", in[i] + j); if (i != j) ans[i] |= in[i][j]; } if (i == n - 1) printf("%d\n", ans[i]); else printf("%d ", ans[i]); } return 0; }
10
CPP
#include <bits/stdc++.h> using namespace std; int main() { int n, x[110][110], a[110]; while (cin >> n) { for (int i = (int)1; i < (int)n + 1; i++) for (int j = (int)1; j < (int)n + 1; j++) cin >> x[i][j]; memset(a, 0, sizeof(a)); for (int i = (int)1; i < (int)n + 1; i++) { for (int j = (int)i + 1; j < (int)n + 1; j++) { int m = x[i][j]; for (int k = (int)0; k < (int)32; k++) { if (m & (1 << k)) a[i] |= (1 << k), a[j] |= (1 << k); } } } cout << a[1]; for (int i = (int)2; i < (int)n + 1; i++) cout << " " << a[i]; puts(""); } return 0; }
10
CPP
#include <bits/stdc++.h> using namespace std; inline void _() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); } void __() {} inline void ___(char *i, char *j) { freopen(i, "r", stdin); freopen(j, "w", stdout); } template <class T1> bool tk(T1 &e1) { if (cin >> e1) return true; return false; } template <class T1, class T2> bool tk(T1 &e1, T2 &e2) { if (cin >> e1 >> e2) return true; return false; } template <class T1, class T2, class T3> bool tk(T1 &e1, T2 &e2, T3 &e3) { if (cin >> e1 >> e2 >> e3) return true; return false; } template <class T1, class T2, class T3, class T4> bool tk(T1 &e1, T2 &e2, T3 &e3, T4 &e4) { if (cin >> e1 >> e2 >> e3 >> e4) return true; return false; } template <class T1, class T2, class T3, class T4, class T5> bool tk(T1 &e1, T2 &e2, T3 &e3, T4 &e4, T5 &e5) { if (cin >> e1 >> e2 >> e3 >> e4 >> e5) return true; return false; } template <class T1, class T2, class T3, class T4, class T5, class T6> bool tk(T1 &e1, T2 &e2, T3 &e3, T4 &e4, T5 &e5, T6 &e6) { if (cin >> e1 >> e2 >> e3 >> e4 >> e5 >> e6) return true; return false; } template <class T1> void put(T1 e) { cout << e << endl; } template <class T1, class T2> void put(T1 e1, T2 e2) { cout << e1 << " " << e2 << endl; } template <class T1, class T2, class T3> void put(T1 e1, T2 e2, T3 e3) { cout << e1 << " " << e2 << " " << e3 << endl; } template <class T1, class T2, class T3, class T4> void put(T1 e1, T2 e2, T3 e3, T4 e4) { cout << e1 << " " << e2 << " " << e3 << " " << e4 << endl; } template <class T1, class T2, class T3, class T4, class T5> void put(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5) { cout << e1 << " " << e2 << " " << e3 << " " << e4 << " " << e5 << endl; } template <class T1, class T2, class T3, class T4, class T5, class T6> void put(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5, T6 e6) { cout << e1 << " " << e2 << " " << e3 << " " << e4 << " " << e5 << " " << e6 << endl; } template <class T1> void putVec(vector<T1> e1) { for (int i = 0; i < (e1).size(); i++) (!i ? cout << e1[i] : cout << " " << e1[i]); cout << endl; } template <class T1> void putArr(T1 arr[], int l) { for (int i = 0; i < l; i++) (!i ? cout << arr[i] : cout << " " << arr[i]); cout << endl; } template <class T1> void bug(T1 e) {} template <class T1, class T2> void bug(T1 e1, T2 e2) {} template <class T1, class T2, class T3> void bug(T1 e1, T2 e2, T3 e3) {} template <class T1, class T2, class T3, class T4> void bug(T1 e1, T2 e2, T3 e3, T4 e4) {} template <class T1, class T2, class T3, class T4, class T5> void bug(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5) {} template <class T1, class T2, class T3, class T4, class T5, class T6> void bug(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5, T6 e6) {} template <class T1> void bugVec(vector<T1> e1) {} template <class T1> void bugArr(T1 arr[], int l) {} namespace gv {}; long long absolute(long long a) { if (a < 0) return -a; return a; } int a, n, b[101]; int main() { _(); tk(n); for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) { tk(a); if (a == -1) continue; for (int k = 0; k < 32; k++) if ((a >> k) & 1) { b[i] |= (1 << k); b[j] |= (1 << k); } } for (int i = 0; i < n; i++) put(b[i]); __(); }
10
CPP
#include <bits/stdc++.h> using namespace std; int main() { int t; int n, i, j; int a[105]; scanf("%d", &n); memset(a, 0, sizeof(int) * n); for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { scanf("%d", &t); if (i != j) { a[i] = a[i] | t; a[j] = a[j] | t; } } } for (i = 0; i < n; i++) { printf("%d ", a[i]); } }
10
CPP
#include <bits/stdc++.h> using namespace std; long long n, a[101][101], sol[101]; vector<long long> V[101]; int main() { cin.sync_with_stdio(0); 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++) for (int j = 0; j < n; j++) if (a[i][j] != -1) sol[i] |= (a[i][j]); for (int i = 0; i < n; i++) cout << sol[i] << " "; cout << endl; return 0; }
10
CPP
#include <bits/stdc++.h> using namespace std; int n; int a[110]; int main() { cin >> n; for (int i = 1; i <= n; ++i) for (int j = 1; j <= n; ++j) { int x; cin >> x; if (i == j) continue; a[i] |= x; } for (int i = 1; i <= n; ++i) cout << a[i] << " "; return 0; }
10
CPP
#include <bits/stdc++.h> int main() { long int N, a[105][105], b[105]; scanf("%ld", &N); for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) scanf("%d", &a[i][j]); memset(b, 0, sizeof(b)); for (int i = 0; i < N; i++) for (int j = i + 1; j < N; j++) { b[i] |= a[i][j]; b[j] |= a[i][j]; } for (int i = 0; i < N; i++) printf("%d ", b[i]); return 0; }
10
CPP
#include <bits/stdc++.h> using namespace std; int tut[1010], ar[1010][1010]; int n; void oku() { int i, j, l, k, s = 0; scanf(" %d", &n); for (i = 1; i <= n; i++) { memset(tut, 0, sizeof(tut)); for (j = 1; j <= n; j++) { scanf(" %d", &ar[i][j]); if (i == j) continue; for (l = 0, k = 1; k <= ar[i][j]; l++, k *= 2) ; for (; k >= 1; l--, k /= 2) if (ar[i][j] >= k) { ar[i][j] -= k; tut[l] = 1; } } s = 0; for (k = 1, l = 0; k <= 1e9; l++, k *= 2) if (tut[l]) s += k; cout << s << ' '; } puts(""); } int main() { oku(); }
10
CPP
#include <bits/stdc++.h> using namespace std; const double eps = 1e-7; const int MAX_N = 100 + 10; int b[MAX_N][MAX_N]; int a[MAX_N], mark[MAX_N]; int n; int main() { cin >> n; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) cin >> b[i][j]; for (int r = 0; (1 << r) <= 1000 * 1000 * 1000; r++) { for (int i = 0; i < n; i++) mark[i] = 0; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) if (i != j) if (b[i][j] & (1 << r)) { mark[i] = 1; mark[j] = 1; } for (int i = 0; i < n; i++) if (mark[i]) a[i] += (1 << r); } for (int i = 0; i < n; i++) cout << a[i] << " "; cout << endl; return 0; }
10
CPP
#include <bits/stdc++.h> using namespace std; int main() { long long i, j, k, l, m, n = 0, r, cnt = 0, ans = 0, ans1 = 0, ans2 = 0, ans3 = 0, sum = 0, sum1 = 0, ca = 1, mn = 0, mx = 0; long long a, b, c, d, e, f, a1, b1, c1, x, y, z, x1, y1, z1; long long ar[101010], ar1[1000], arr[100][100] = {0}; double ff; string s, ss[1000], s2[1000], s3, s1[1000], aa = "", bb = "", cc = "", dd = ""; vector<string> tt; string sss = "hello"; map<string, int> mp; vector<pair<long, long> > t; set<int> g[1010]; cin >> n; for (__typeof(n) i = 0; i < (n); i++) { for (__typeof(n) j = 0; j < (n); j++) { cin >> m; if (i != j) ar[i] |= m; } } for (__typeof(n) i = 0; i < (n); i++) cout << ar[i] << ' '; return 0; }
10
CPP
#include <bits/stdc++.h> using namespace std; int n, b[111][111]; int main() { 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++) { int a = 0; for (int j = 0; j < n; j++) { if (i == j) continue; a |= b[i][j]; } printf("%d%c", a, i == n - 1 ? '\n' : ' '); } return 0; }
10
CPP
#include <bits/stdc++.h> using namespace std; int n; int m[101][101]; int main() { cin >> n; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) cin >> m[i][j]; long long k = 1LL; while (k < 1e9) k *= 2LL; k -= 1; for (int i = 0; i < n; i++) { long long p = 0; for (int j = 0; j < n; j++) { if (j != i) p |= m[i][j]; } cout << (p & k) << " "; } }
10
CPP
#include <bits/stdc++.h> using namespace std; int arr[200][200]; int main() { int n; cin >> n; vector<int> ans(n); for (int i = 0; i < n; i++) for (int l = 0; l < n; l++) cin >> arr[i][l]; for (int i = 0; i < n; i++) { for (int l = 0; l < n; l++) { if (arr[i][l] != -1) { ans[i] |= arr[i][l]; } } } for (int i = 0; i < n; i++) cout << ans[i] << " "; cout << endl; }
10
CPP
#include <bits/stdc++.h> using namespace std; int n, a[105]; int main() { while (cin >> n) { memset(a, 0, sizeof(a)); for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { int k; cin >> k; if (i == j) continue; a[i] |= k; a[j] |= k; } } for (int i = 1; i < n; i++) cout << a[i] << " "; cout << a[n] << endl; } return 0; }
10
CPP
#include <bits/stdc++.h> using namespace std; int n, data[105][105], ans[105]; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) scanf("%d", &data[i][j]); for (int k = 0; k < 31; k++) { for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) if (i != j) { if (data[i][j] & (1 << k)) { ans[i] |= 1 << k; ans[j] |= 1 << k; } } } for (int i = 1; i <= n; i++) printf("%d ", ans[i]); puts(""); }
10
CPP
#include <bits/stdc++.h> using namespace std; long long n, i, j, a, k; bitset<100> A[110], B; int main() { scanf("%lld", &n); for (i = 1; i <= n; i++) for (j = 1; j <= n; j++) { scanf("%d", &a); if (i == j) continue; B = a; for (k = 0; k <= 100; k++) { if (B[k]) A[i][k] = A[j][k] = 1; } } for (i = 1; i <= n; i++) cout << A[i].to_ulong() << " "; return 0; }
10
CPP
#include <bits/stdc++.h> using namespace std; int n; int main() { cin >> n; for (int i = 1; i <= n; i++) { int x = 0; for (int j = 1; j <= n; j++) { int a; cin >> a; if (a == -1) continue; x = x | a; } cout << x << " "; } }
10
CPP
#include <bits/stdc++.h> using namespace std; template <class T> inline T bigmod(T p, T e, T M) { long long int ret = 1; for (; e > 0; e >>= 1) { if (e & 1) ret = (ret * p) % M; p = (p * p) % M; } return (T)ret; } template <class T> inline T modinverse(T a, T M) { return bigmod(a, M - 2, M); } template <class T> inline T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); } long long int n, m; long long int ans[111], bb[111][111]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); ; cin >> n; for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) cin >> bb[i][j]; for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { if (i == j) continue; ans[i] = ans[i] | bb[i][j]; } } for (int i = 1; i <= n; i++) cout << ans[i] << " "; cout << endl; ; return 0; }
10
CPP
#include <bits/stdc++.h> using namespace std; template <class T1> void deb(T1 e) { cout << e << endl; } template <class T1, class T2> void deb(T1 e1, T2 e2) { cout << e1 << " " << e2 << endl; } template <class T1, class T2, class T3> void deb(T1 e1, T2 e2, T3 e3) { cout << e1 << " " << e2 << " " << e3 << endl; } template <class T1, class T2, class T3, class T4> void deb(T1 e1, T2 e2, T3 e3, T4 e4) { cout << e1 << " " << e2 << " " << e3 << " " << 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 << " " << e2 << " " << e3 << " " << e4 << " " << e5 << endl; } template <class T1, class T2, class T3, class T4, class T5, class T6> void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5, T6 e6) { cout << e1 << " " << e2 << " " << e3 << " " << e4 << " " << e5 << " " << e6 << endl; } template <class T> inline T sqr(T n) { return n * n; } template <class T> T Abs(T x) { return (x > 0) ? x : -x; } template <class T> inline double LOG(T a, T b) { return (log(a) / log(b)); } template <class T> T power(T B, T P) { return (P == 0) ? 1 : B * (power(B, (P - 1))); } template <class T> inline T gcd(T a, T b) { if (a < 0) return gcd(-a, b); if (b < 0) return gcd(a, -b); return (b == 0) ? a : gcd(b, a % b); } template <class T> T BigMod(T B, T P, T M) { if (P == 0) return 1; else if (P % 2 == 0) return sqr((BigMod(B, P / 2, M))) % M; else return (B % M) * (BigMod(B, P - 1, M)) % M; } template <class T> T LCM(T a, T b) { if (a < 0) return LCM(-a, b); if (b < 0) return LCM(a, -b); return (a * (b / GCD(a, b))); } long long table[105][105]; int n; long long findRes(int cur) { long long res = 0; long long i, j; for (i = 0; i < n; i++) { if (cur == i) continue; res |= table[cur][i]; } return res; } int main(void) { memset(table, -1, sizeof(table)); scanf("%d", &n); long long i, j, tmp; for (i = 0; i < n; i++) for (j = 0; j < n; j++) scanf("%I64d", &table[i][j]); vector<long long> res; res.clear(); for (i = 0; i < n; i++) res.push_back(findRes(i)); printf("%I64d", res[0]); for (i = 1; i < (int)res.size(); i++) printf(" %I64d", res[i]); printf("\n"); return 0; }
10
CPP
#include <bits/stdc++.h> using namespace std; int mpow(int base, int exp); void ipgraph(long long n, long long m); void dfs(int u, int par); const int mod = 1000000007; const int N = 3e5, M = N; vector<long long> g[N]; int main() { ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); ; long long t, i, j, k, p, q, r, x, y, u, v, n, m; cin >> n; vector<long long> a(n, 0); for (i = 0; i < n; i++) { for (j = 0; j < n; j++) { cin >> x; if (i != j) a[i] = a[i] | x; } } for (i = 0; i < n; i++) cout << a[i] << " "; return 0; } int mpow(int base, int exp) { base %= mod; int result = 1; while (exp > 0) { if (exp & 1) result = ((long long)result * base) % mod; base = ((long long)base * base) % mod; exp >>= 1; } return result; } void ipgraph(long long n, long long m) { int i, u, v; while (m--) { cin >> u >> v; g[u - 1].push_back(v - 1); g[v - 1].push_back(u - 1); } } void dfs(int u, int par) { for (int v : g[u]) { if (v == par) continue; dfs(v, u); } }
10
CPP
#include <bits/stdc++.h> using namespace std; long long ans[300]; long long top, temp; int main() { long long n, tt; while (~scanf("%I64d", &n)) { top = 0; for (int i = 1; i <= n; i++) { temp = 0; for (int j = 1; j <= n; j++) { cin >> tt; if (i == j) continue; temp |= tt; } ans[++top] = temp; } for (int i = 1; i <= top; i++) { if (i < top) printf("%I64d ", ans[i]); else printf("%I64d\n", ans[i]); } } }
10
CPP
#include <bits/stdc++.h> using namespace std; int n, a[200000], x; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) { cin >> x; if (x != -1) a[i] = a[i] | x; } for (int i = 0; i < n; i++) cout << a[i] << " "; }
10
CPP
#include <bits/stdc++.h> time_t st = clock(); using namespace std; 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 / gcd(a, b) * b; } long long p[200][100]; long long n, r, two; long long k[200][200]; int main() { cin >> n; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cin >> k[i][j]; } } for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) if (i != j) { for (int l = 0; l < 40; l++) { if (p[i][l] == 0) p[i][l] = k[i][j] % 2; k[i][j] /= 2; } } } for (int i = 0; i < n; i++) { two = 1; r = 0; for (int l = 0; l < 40; l++) { r += p[i][l] * two; two *= 2; } cout << r << ' '; } return 0; }
10
CPP
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const int MAXN = 105; int ans[MAXN][40]; int a[MAXN][MAXN]; int n; void solved(int cas) { scanf("%d", &n); for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) scanf("%d", &a[i][j]); for (int k = 0; k <= 30; k++) for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) if (i != j && (a[i][j] & (1 << k))) ans[i][k] = ans[j][k] = 1; for (int i = 0; i < n; i++) { if (i) printf(" "); int temp = 0; for (int k = 0; k < 30; k++) temp |= ans[i][k] << k; printf("%d", temp); } printf("\n"); } int main() { int T = 1; for (int i = 1; i <= T; i++) solved(i); return 0; }
10
CPP
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 7; int a[105][105]; int b[105]; int main() { int n; scanf("%d", &n); for (int i = (0); i < (n); ++i) for (int j = (0); j < (n); ++j) scanf("%d", &a[i][j]); for (int i = (0); i < (n); ++i) for (int j = (0); j < (n); ++j) if (i != j) { b[i] |= a[i][j]; b[j] |= a[i][j]; } for (int i = (0); i < (n); ++i) cout << b[i] << " "; return 0; }
10
CPP
#include <bits/stdc++.h> using namespace std; long long n, a[200][200], d[200], deg[100], de; long long take_bit(long long x, long long i) { if (i < 0) return 0; if ((x & (1 << i)) == 0) return 0; else return 1; } 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++) for (int j = 0; j < n; j++) if (i != j) for (int k = 0; k < 32; k++) if (take_bit(a[i][j], k) == 1) { if (take_bit(d[i], k) != 1) d[i] += 1 << k; if (take_bit(d[j], k) != 1) d[j] += 1 << k; } for (int i = 0; i < n; i++) cout << d[i] << " "; }
10
CPP
#include <bits/stdc++.h> using namespace std; int n; int main() { scanf("%d", &n); for (int i = 0; i < n; ++i) { int x = 0, y; for (int j = 0; j < n; ++j) { scanf("%d", &y); if (i == j) continue; for (int k = 0; k < 30; ++k) if (y & (1 << k)) x |= (1 << k); } printf("%d ", x); } return 0; }
10
CPP
#include <bits/stdc++.h> using namespace std; int n; int M[128][128]; bool tenho[128][32]; int v[128]; int main() { scanf("%d", &n); for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) scanf("%d", &M[i][j]); memset(tenho, false, sizeof(tenho)); memset(v, 0, sizeof(v)); for (int b = 0; b < 30; b++) { again:; for (int i = 0; i < n; i++) for (int j = i + 1; j < n; j++) if (M[i][j] & (1 << b)) if (!tenho[i][b] or !tenho[j][b]) { tenho[i][b] = tenho[j][b] = true; v[i] |= (1 << b); v[j] |= (1 << b); goto again; } } for (int i = 0; i < n; i++) { if (i) printf(" "); printf("%d", v[i]); } printf("\n"); return 0; }
10
CPP
#include <bits/stdc++.h> int n, b, a[100][60]; void add(int x, int y) { int z, t = 0; for (z = y; z > 0; z /= 2) { if (z & 1) a[x][t] = 1; t++; } } int res(int x) { int i; int ans = 0; int t = 1; for (i = 0; i < 60; i++) { if (a[x][i]) ans += t; t *= 2; } return ans; } int main() { scanf("%d", &n); int i, j; for (i = 0; i < n; i++) for (j = 0; j < n; j++) { scanf("%d", &b); if (b + 1) { add(i, b); } } for (i = 0; i < n; i++) { printf("%d ", res(i)); } return 0; }
10
CPP
#include <bits/stdc++.h> int a[200], b[200][200]; int main() { int n; while (scanf("%d", &n) == 1) { 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++) a[i] = 0; for (int i = 0; i < n; i++) for (int j = i + 1; j < n; j++) { a[i] |= b[i][j]; a[j] |= b[i][j]; } for (int i = 0; i < n; i++) { if (i) putchar(' '); printf("%d", a[i]); } puts(""); } return 0; }
10
CPP
#include <bits/stdc++.h> using namespace std; int b[100][100]; int a[100]; int main(void) { int n; cin >> n; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) cin >> b[i][j]; memset(a, 0, sizeof(a)); for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { for (int k = 0; k < 32; k++) { if (((1 << k) & b[i][j]) != 0) { if (((1 << k) & a[i]) == 0) a[i] += (1 << k); if (((1 << k) & a[j]) == 0) a[j] += (1 << k); } } } } for (int i = 0; i < n; i++) cout << a[i] << ' '; }
10
CPP
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int and_matrix[n][n], nos[n]; for (int i = 0; i < n; i++) { nos[i] = 0; for (int j = 0; j < n; j++) cin >> and_matrix[i][j]; } for (int i = 0; i < n; i++) for (int j = i + 1; j < n; j++) for (int k = 31; k >= 0; k--) if (and_matrix[i][j] & (1 << k)) { nos[i] = nos[i] | (1 << k); nos[j] = nos[j] | (1 << k); } for (int i = 0; i < n; i++) cout << nos[i] << " "; cout << endl; return 0; }
10
CPP
#include <bits/stdc++.h> using namespace std; long long int A[110][110]; long long int B[110]; int main() { long long int n; while (cin >> n) { for (long long int i = 0; i < n; i++) { for (long long int j = 0; j < n; j++) { cin >> A[i][j]; } } long long int a = 0; for (long long int i = 0; i < n; i++) { long long int sum = 0; long long int num1 = 0; int flag = 0; for (long long int j = 0; j < n; j++) { if (A[i][j] < 0) { continue; } else { sum |= A[i][j]; } } B[a] = sum; a++; } for (long long int i = 0; i < a; i++) { cout << B[i] << ' '; } cout << endl; } return 0; }
10
CPP
#include <bits/stdc++.h> using namespace std; int arr[200][200]; int main() { int n; cin >> n; vector<int> ans(n); for (int i = 0; i < n; i++) for (int l = 0; l < n; l++) cin >> arr[i][l]; for (int i = 0; i < n; i++) { for (int l = 0; l < n; l++) { if (arr[i][l] != -1) { for (int k = 0; k < 32; k++) { ans[i] |= ((1 << k) & arr[i][l]); } } } } for (int i = 0; i < n; i++) cout << ans[i] << " "; cout << endl; }
10
CPP
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { int x = 0; for (int j = 0; j < n; j++) { int temp; cin >> temp; if (i == j) continue; x |= temp; } cout << x << " "; } cout << endl; return 0; }
10
CPP
#include <bits/stdc++.h> using namespace std; long long arr[200100], barr[200100]; long long M = 998244353; multiset<long long> st; int main() { long long t, n, i, j, k, l, m; ios_base::sync_with_stdio(0); cin.tie(0); long long p; t = 1; while (t--) { cin >> n; for (i = 1; i <= n; i++) for (j = 1; j <= n; j++) { cin >> k; if (i != j) arr[i] = arr[i] | k; } for (i = 1; i <= n; i++) cout << arr[i] << ' '; cout << '\n'; } return 0; }
10
CPP
#include <bits/stdc++.h> using namespace std; int b[109][109], a[109]; int main() { int n; while (cin >> n) { memset(a, 0, sizeof(a)); for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { cin >> b[i][j]; if (i != j) a[i] |= b[i][j]; } } for (int i = 1; i <= n; i++) { if (i == 1) cout << a[i]; else cout << " " << a[i]; } cout << endl; } }
10
CPP
#include <bits/stdc++.h> int a[101][101]; int ar[101]; using namespace std; int main() { int n; cin >> n; for (int i = 0; i < n; i++) { for (int f = 0; f < n; f++) { cin >> a[i][f]; } } for (int i = 0; i < n; i++) { int f = i; int cur = 0; for (f = 0; f < n; f++) { if (i != f) { cur |= a[i][f]; } } ar[i] = cur; } for (int i = 0; i < n; i++) { cout << ar[i] << " "; } return 0; }
10
CPP
#include <bits/stdc++.h> using namespace std; int n, a[101][101], b[101]; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { scanf("%d", &a[i][j]); if (i != j) b[i] = b[i] | a[i][j]; } } printf("%d", b[1]); for (int i = 2; i <= n; i++) printf(" %d", b[i]); printf("\n"); return 0; }
10
CPP
#include <bits/stdc++.h> const long long inf = 1000000000; const long long inf64 = inf * inf; const double pi = acos(-1.0); long long Abs(long long x) { return (x >= 0 ? x : -x); } using namespace std; bool solve() { int n; cin >> n; vector<vector<long long> > mat(n, vector<long long>(n)); vector<long long> ans(n, 0); for (int i(0); i < n; i++) for (int j(0); j < n; j++) cin >> mat[i][j]; for (int i(0); i < n; i++) { for (int j(0); j < n; j++) { if (i == j) continue; ans[j] |= mat[i][j]; } } for (int i(0); i < n; i++) cout << ans[i] << ' '; return true; } int main() { solve(); return 0; }
10
CPP
#include <bits/stdc++.h> using namespace std; int a[101]; int main() { int n; cin >> n; for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) { int AND; cin >> AND; if (i != j) a[i] |= AND; } for (int i = 1; i <= n; i++) cout << a[i] << "\t"; return 0; }
10
CPP
#include <bits/stdc++.h> using namespace std; int sir[110], N; int main() { cin >> N; for (int i = 1; i <= N; ++i) for (int j = 1; j <= N; ++j) { int x; cin >> x; if (i != j) { for (int k = 0; k < 32; ++k) if ((1 << k) & x) { if ((sir[i] & (1 << k)) == 0) sir[i] += 1 << k; if ((sir[j] & (1 << k)) == 0) sir[j] += 1 << k; } } } for (int i = 1; i <= N; ++i) cout << sir[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; const int MAXN = 1e2 + 3; const int INF = 1e9; const int MOD = 1e9 + 7; int b[MAXN][MAXN]; int a[MAXN]; int main() { int n; 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 < i; j++) { a[i] = a[i] | b[i][j]; a[j] = a[j] | b[i][j]; } for (int i = 0; i < n; i++) cout << a[i] << ' '; return 0; }
10
CPP