Search is not available for this dataset
name
stringlengths
2
112
description
stringlengths
29
13k
source
int64
1
7
difficulty
int64
0
25
solution
stringlengths
7
983k
language
stringclasses
4 values
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using namespace std; vector<long long> v[100001]; bool compare(pair<long long, long long> x, pair<long long, long long> y) { if (x.first < y.first) retur...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; long long int max(long long int a, long long int b) { if (a > b) return a; else return b; } long long int min(long long int a, long long int b) { if (a < b) return a; else return b; } const int dx[4] = {-1, 1, 0, 0}; const int dy[4] = {0, 0, -1, 1}; ...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
import java.util.*; import java.math.*; import java.io.*; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; public class Hello { static ArrayList<Integer> nb[] = new ArrayList[150005]; public static void main(String[] args) { //Scanner in = new Scanner(System.in); F...
JAVA
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; const long long INF = 1LL << 60; signed main() { long long n, m; cin >> n >> m; long long a[n]; for (long long i = 2; i < n; i++) a[i] = i + 1; vector<long long> b[n]; for (long long i = 0; i < m; i++) { long long x, y; cin >> x >> y; x--; y--; ...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; template <typename Arg1> void __f(const char* name, Arg1&& arg1) { std::cerr << name << " : " << arg1 << '\n'; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(names + 1, ','); std::cerr...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.util.HashSet; import java.util.Set; import java.util.stream.Stream; /** * @author madi.sagimbekov */ public class C1090D { private static Buf...
JAVA
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 1; vector<int> V[N]; int sol1[N], sol2[N]; int n, m, a, b, cnt1 = 1, cnt2 = 2, st = 1, ok = 0; int main() { scanf("%d %d", &n, &m); for (int i = 1; i <= m; i++) { scanf("%d %d", &a, &b); V[a].push_back(b); V[b].push_back(a); } int cur...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; const long long inf = (1ll << 62) - 1; const long long mod = 1e9 + 7; const long long N = 2e5 + 10; long long bPow(long long a, long long b) { long long res = 1; while (b) { if (b & 1) { res = (res * a) % mod; } b >>= 1; a = (a * a) % mod; } re...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; int n, m; set<pair<int, int>> blocked; int main() { cin >> n >> m; for (int i = 0; i < m; ++i) { int a, b; cin >> a >> b; a -= 1; b -= 1; blocked.insert(make_pair(a, b)); blocked.insert(make_pair(b, a)); } if (n * (n - 1) == blocked.size()) {...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
n,m = map(int,input().split()) member = [0 for _ in range(n+1)] linked = set() for i in range(m): a,b = map(int,input().split()) linked.add(str(a)+'-'+str(b)) linked.add(str(b) + '-' + str(a)) member[a]+=1 member[b]+=1 num=0 for i in range(1,n+1): if member[i]<n-1: num=i break # ...
PYTHON3
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0), cin.tie(0); int n, m; cin >> n >> m; vector<set<int>> cmp(n); for (int x, y; m--;) { cin >> x >> y; cmp[--x].insert(--y); cmp[y].insert(x); } int x = -1, y; for (int i = 0; i < n; ++i) if (cmp[i].siz...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; long long n, m; vector<int> graph[1001000]; int a[1001000]; int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n >> m; for (int i = 1; i <= n; i++) graph[i].push_back(i); for (int i = 1; i <= m; i++) { int a, b; cin >> a >> b; graph[a].push_b...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; int a[100005]; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cerr.tie(nullptr); set<pair<int, int>> s; int n, m; cin >> n >> m; for (int i = 0; i < m; i++) { int x, y; cin >> x >> y; if (x > y) swap(x, y); ...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
import java.util.*; import java.io.*; import java.lang.reflect.Array; import java.math.BigInteger; public class A { FastScanner in; PrintWriter out; boolean systemIO = true; public int gcd(int a, int b) { if (a == 0) { return b; } return gcd(b % a, a); } public class Pair { int x; int y; public...
JAVA
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; vector<set<int>> a(n); for (int i = 0; i < m; i++) { int q, w; cin >> q >> w; a[q - 1].insert(w - 1); a[w - 1].insert(q - 1); } for (int i = 0; i < n; i++) { if (a[i].size() != (n - 1)) { int ctr = ...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; int n, m, cnt, a[100100], in[100100], flag2, ans[100100]; map<int, int> mp[100100]; int main() { scanf("%d%d", &n, &m); if (n <= 500 && m == n * (n - 1) / 2) { printf("NO\n"); return 0; } int u, v; for (int i = 1; i <= m; i++) { scanf("%d%d", &u, &v); ...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> const long long INF = 2000000005; const long long BIG_INF = 2000000000000000005; const long long mod = 1000000007; const long long P = 31; const long double PI = 3.141592653589793238462643; const double eps = 1e-9; using namespace std; vector<pair<long long, long long> > dir = {{-1, 0}, {0, 1},...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 100; const int mod = 1e9 + 7; mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count()); int n, m, arr[maxn], nxt = 1; vector<int> adj[maxn]; void no() { cout << "NO\n"; exit(0); } int main() { ios_base::sync_with_stdio(false)...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; vector<int> adj[100000]; int a[100000]; bool chk[100000]; int main() { int N, M; scanf("%d %d", &N, &M); for (int i = 0, u, v; i < M; i++) { scanf("%d %d", &u, &v); --u; --v; adj[u].push_back(v); adj[v].push_back(u); } int u = -1, v = -1; for...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
import java.util.*; import java.io.*; public class Main { public static void main(String args[]) {new Main().run();} Scanner in = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); void run(){ work(); out.flush(); } void work() { int n=in.nextInt(); int m=in.nextInt(); ...
JAVA
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; int n, m; map<pair<int, int>, bool> has; int net[100500], d[100500]; void solve() { scanf("%d %d", &n, &m); if (m == (n * (n - 1)) >> 1) { cout << "NO"; return; } for (int i = 1; i <= m; i++) { int a, b; scanf("%d %d", &a, &b); if (a > b) swap(a,...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; int n, m; int p[100005], d[100005]; bool vis[100005]; int head[100005], cnt; struct edge { int to, next; } e[100005 << 1]; void addedge(int u, int v) { e[++cnt].to = v; e[cnt].next = head[u]; head[u] = cnt; } int main() { scanf("%d%d", &n, &m); for (int i = 1; i...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; int a[N]; vector<int> G[N]; inline void work() { int flag = 0, n, m; scanf("%d%d", &n, &m); while (m--) { int u, v; scanf("%d%d", &u, &v); G[u].push_back(v), G[v].push_back(u); } int k = 2; for (int i = 1; i <= n; i++) if ...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; const int maxe = 100000 + 5; const int maxv = 5000 + 5; const int mod = 1000000; const int maxn = 2 * 1e5 + 5; const int INF = 0x3f3f3f3f; const double PI = acos(-1.0); int n, m, d, e; long long t; vector<int> a[maxn]; bool vis[maxn]; int main() { cin >> n >> m; if (n =...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; using uint = unsigned int; using ll = long long; using ull = unsigned long long; using pii = pair<int, int>; using pll = pair<ll, ll>; template <typename T1, typename T2> ostream &operator<<(ostream &out, const pair<T1, T2> &item) { out << '(' << item.first << ", " << ite...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; pair<int, int> pos; map<int, bool> mp[100010]; int main() { int n, m, a, b; scanf("%d %d", &n, &m); for (int i = 0; i < m; i++) { scanf("%d %d", &a, &b); if (a > b) swap(a, b); mp[a][b] = 1; } if (1ll * n * (n - 1) / 2 <= 1ll * m) { printf("NO\n");...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; int p1[100001] = {0}; int p2[100001] = {0}; set<int> s[100100]; int main() { int n, m; cin >> n >> m; int a, b; for (int i = 0; i < m; i++) { scanf("%d%d", &a, &b); if (a > b) swap(a, b); s[a].insert(b); } for (int i = 1; i <= n; i++) { for (int ...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> const long long INF = 2 * 1e9; using namespace std; map<pair<long long, long long>, bool> used; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); long long n, m; cin >> n >> m; if (n < 2 || m >= (n * (n - 1)) / 2) { cout << "NO"; return 0; } vector<pair<long lo...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; long long int mod = 1e9 + 7; long long int mul(long long int a, long long int b) { return ((a % mod) * (b % mod)) % mod; } long long int add(long long int a, long long int b) { return ((a % mod) + (b % mod)) % mod; } long long int sub(long long int a, long long int b) {...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> #pragma GCC optimize("O3", "unroll-loops") using namespace std; template <class T> inline void sort(T &a) { sort((a).begin(), (a).end()); } template <class T> inline void rsort(T &a) { sort((a).rbegin(), (a).rend()); } template <class T> inline void reverse(T &a) { reverse((a).begin(), (a...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; set<int> gr[100005]; int n, m; bool flag[100005]; int ans[100005]; void go(int p1, int p2) { printf("YES\n"); ans[p1] = 1; ans[p2] = 1; int j = 3, i; for (i = 1; i <= n; i++) { if (ans[i]) continue; else { ans[i] = j++; } } for (i = 1; ...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; vector<int> g[100005]; bool ch[100005]; int main() { int n, m; cin >> n >> m; if (n == 1) { cout << "NO"; return 0; } while (m--) { int a, b; cin >> a >> b; g[a].push_back(b); g[b].push_back(a); } int a = 0, b = 0; for (int i = 1; i <...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; int dx[] = {0, 0, 1, -1, -1, -1, 1, 1}; int dy[] = {1, -1, 0, 0, -1, 1, 1, -1}; template <class T> inline T biton(T n, T pos) { return n | ((T)1 << pos); } template <class T> inline T bitoff(T n, T pos) { return n & ~((T)1 << pos); } template <class T> inline T ison(T n...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.util.HashSet; import java.io.OutputStream; import java.io.PrintWriter; import java.io.BufferedWriter; import java.io.Writer; import java.io.OutputStreamWriter; import java.util.InputMismatchException; import java.io.IOExcep...
JAVA
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0), cin.tie(0); int n, m; cin >> n >> m; pair<int, int> ans(-1, -1); vector<pair<int, int> > v; for (int i = 0; i < m; ++i) { int x, y; cin >> x >> y; --x, --y; v.emplace_back(min(x, y), max(x, y)); } sort(v....
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; long long int p = 1000000007; int main() { long long int n, m; cin >> n >> m; pair<long long int, long long int> a[m + 1]; vector<long long int> adj[n + 1]; long long int ans1[n + 1], ans2[n + 1]; for (long long int i = 1; i <= m; i++) { cin >> a[i].first >>...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 10; int n, m; set<int> s[maxn]; int arr[maxn], brr[maxn]; void solve() { for (int i = 1; i <= n; ++i) { for (int j = i + 1; j <= n; ++j) if (s[i].count(j) == 0) { arr[i] = 1, arr[j] = 2; brr[i] = 1, brr[j] = 1; int ...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; using i64 = long long int; using ii = pair<int, int>; using ii64 = pair<i64, i64>; vector<int> edge[100005]; vector<int> oneWay[100005]; int deg[100005]; int deg2[100005]; bool used[100005]; i64 n, m; bool visit[100005]; void dfs(int root) { visit[root] = true; for (aut...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; vector<int> vec[100004]; vector<pair<int, int> > temp; int main() { int a, b, ans[2][100004], j; long long n, m; scanf("%lld %lld", &n, &m); for (int i = 0; i < m; ++i) { scanf("%d %d", &a, &b); vec[a].push_back(b); vec[b].push_back(a); } if (m == (n...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9 + 7; long long __gcd(long long a, long long b) { if (b == 0) return a; return __gcd(b, a % b); } vector<vector<int> > adj; int main() { std ::ios_base ::sync_with_stdio(false); cin.tie(NULL), cout.tie(NULL); long long n, m; cin >> n >> m; a...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.util.HashSet; import java.io.OutputStream; import java.io.PrintWriter; import java.io.BufferedWriter; import java.io.Writer; import java.io.OutputStreamWriter; import java.util.InputMismatchException; import java.io.IOExcep...
JAVA
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.Scanner; import java.util.StringTokenizer; public class D { public static void main(String[] args) throws NumberFormatExceptio...
JAVA
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5; const int inf = 0x3f3f3f3f; const long long linf = 0x3f3f3f3f3f3f3f3f; const int mod = 1e9 + 7; const double e = exp(1.0); const double pi = acos(-1); const double eps = 1e-6; set<int> s[maxn]; int a[maxn], b[maxn]; int main() { int n, m, l, r; ...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; int vis[100005], vis1[100005]; vector<int> G[100005]; int main() { int n, m, a, b; scanf("%d%d", &n, &m); for (int i = 1; i <= n; i++) G[i].clear(); for (int i = 1; i <= m; i++) scanf("%d%d", &a, &b), vis[a]++, vis[b]++, G[a].push_back(b), G[b].push_back...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> #pragma GCC optimize(2) using namespace std; map<int, int> G[101000]; int n, m, a[101000]; int main() { cin >> n >> m; int u, v; for (; m--;) { scanf("%d%d", &u, &v); G[u][v] = G[v][u] = 233; } for (int i = 1; i <= n; ++i) for (int j = i + 1; j <= n; ++j) if (!G[i].c...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
import java.io.*; import java.math.*; import java.util.*; import static java.lang.Math.*; import static java.util.Arrays.*; import static java.util.Collections.*; import static java.util.Comparator.*; public class Main { FastScanner in; PrintWriter out; private void solve() throws IOException { i...
JAVA
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> #pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC optimize(4) using namespace std; const int N = 1e5 + 10; int a[N]; vector<int> g[N]; int main() { int n, m, u, v; scanf("%d %d", &n, &m); for (int i = 1; i <= m; i++) scanf("%d %d", &u, &v), g[u].push_back(v), g[v].push_back(...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; set<long long> adj[100005]; int main() { long long n, m; cin >> n >> m; for (long long i = 0; i < m; i++) { long long u, v; cin >> u >> v; adj[u].insert(v); adj[v].insert(u); } long long idx = -1; for (long long i = 1; i < n + 1; i++) { if (a...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; const int N = 100004; int a[N], b[N], vis[N]; vector<int> g[N]; int cnt = 3; void dfs(int u, int p) { if (vis[u] == 0) { a[u] = cnt; b[u] = cnt; cnt++; } vis[u] = 1; for (int i = 0; i < g[u].size(); i++) { int v = g[u][i]; if (vis[v]) continue; ...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; long long n, m; vector<long long> v[100010]; long long chk[100010]; long long ans1[100010], ans2[100010]; long long top = 3; int main() { scanf("%lld %lld", &n, &m); long long i, j; long long xx, yy; for (i = 1; i <= m; i++) { long long s, e; scanf("%lld %ll...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> #pragma optimize("", off) #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #pragma comment(linker, "/STACK:36777216") const long long inf = 0x3f3f3f3f3f3f3f3LL; const long long mod = 1e9 + 7; using namesp...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
n, m = map(int, input().split()) d = [set() for q in range(n)] for q in range(m): l, r = map(int, input().split()) l, r = l-1, r-1 d[l].add(r) d[r].add(l) ans = -1 for q in range(n): if len(d[q]) < n-1: ans = q break if ans == -1: print('NO') else: for q in range(n): ...
PYTHON3
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
import java.util.*; import java.io.*; import static java.lang.Math.*; public class Main { static final long MOD = 1_000_000_007, INF = 1_000_000_000_000_000_000L; static final int INf = 1_000_000_000; static FastReader reader; static PrintWriter writer; public static void main(String[] args) { ...
JAVA
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; vector<int> p[100011]; int vis[100011] = {0}; int main() { int n, m; scanf("%d%d", &n, &m); for (int i = 0; i < m; i++) { int a, b; scanf("%d%d", &a, &b); p[a].push_back(b); p[b].push_back(a); } int start = 0, end = 0; for (int i = 1; i <= n; i++...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
def ii(): return int(input()) def mi(): return map(int, input().split()) def li(): return list(mi()) # D. Similar Arrays n, m = mi() g = [[] for i in range(n + 1)] e = [] for i in range(m): a, b = mi() e.append((a, b)) g[a].append(b) g[b].append(a) eq = None if n > 1: for i in range(1...
PYTHON3
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; void scan() {} template <typename T, typename... Args> void scan(T &a, Args &...args) { scanf("%lld", &a); scan(args...); } void err(istream_iterator<string> it) {} template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; const int MM = 1e6; vector<int> G[MM]; vector<int> topo; bool vis[MM]; void dfs(int u) { if (vis[u]) { return; } vis[u] = 1; for (auto v : G[u]) { dfs(v); } topo.push_back(u); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5; int n, m, a[N], b[N], ans1[N], ans2[N]; vector<int> G[N]; bool bo[N]; int main() { cin >> n >> m; for (int i = 1; i <= m; ++i) { scanf("%d %d", a + i, b + i); if (a[i] > b[i]) swap(a[i], b[i]); G[a[i]].push_back(b[i]); } if (n == 1...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; int main() { int n, m, min_elem = 1; cin >> n >> m; vector<vector<int>> g(n); for (int i = 0; i < m; i++) { int a, b; cin >> a >> b; a--; b--; g[a].push_back(b); g[b].push_back(a); } vector<int> used(n); int f = -1; for (int i = 0; i ...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; template <class c> struct rge { c h, n; }; template <class c> rge<c> range(c h, c n) { return rge<c>{h, n}; } template <class c, class F> struct rgm { c h, n; F f; }; template <class c, class F> rgm<c, F> map_range(c b, c e, F f) { retur...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 5; set<int> s[maxn]; int a[maxn], b[maxn]; int main() { int n, m, x, y; scanf("%d%d", &n, &m); for (int i = 1; i <= m; ++i) { scanf("%d %d", &x, &y); if (x > y) swap(x, y); s[x].insert(y); } for (int i = 1; i <= n; ++i) { for...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; int n, m; vector<int> adj[100005]; int main(void) { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> m; for (int i = 1; i <= m; ++i) { int u, v; cin >> u >> v; adj[u].push_back(v); adj[v].push_back(u); } for (int i = 1; i <= n; ++i) ...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; const int INF = 1e9 + 7; int n, m, u, v; vector<int> G[100005]; int main() { scanf("%d%d", &n, &m); for (int i = 0; i < (int)(m); i++) { scanf("%d%d", &u, &v); G[u].push_back(v); G[v].push_back(u); } for (int i = 1; i <= (int)(n); i++) { G[i].push_ba...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; int main() { long long n, k; cin >> n >> k; vector<int> ans1(n + 1, 0); vector<int> ans2(n + 1, 0); set<pair<int, int>> s; for (int i = 0; i < k; i++) { int x, y; cin >> x >> y; if (x > y) { swap(x, y); } s.insert({x, y}); } if (k =...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; using LL = long long; void err() { cout << endl; } template <template <typename...> class T, typename t, typename... Args> void err(T<t> a, Args... args) { for (auto x : a) cout << x << ' '; err(args...); } template <typename T, typename... Args> void err(T a, Args... a...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; vector<int> razliciti[100005]; int a[100005]; int b[100005]; bool mark[100005]; int n, m; int p, q; int indeks; int pronadji(int x) { for (int i = 1; i <= n; i++) { if (i != x) { if (!mark[i]) return i; } } } int main() { ios_base::sync_with_stdio(false)...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 7; bool vis[MAXN]; int n, m, all; vector<int> edge[MAXN]; int ans1[MAXN], ans2[MAXN]; void ini() { all = n; for (int i = 1; i <= n; i++) { vis[i] = 1; edge[i].clear(); } } void solve() { if (n == 1 || (m >= (n * (n - 1) / 2))) { pu...
CPP
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.math.BigInteger; import java.util.ArrayList; import java.util.Arrays; import java.util.BitS...
JAVA
1090_D. Similar Arrays
Vasya had an array of n integers, each element of the array was from 1 to n. He chose m pairs of different positions and wrote them down to a sheet of paper. Then Vasya compared the elements at these positions, and wrote down the results of the comparisons to another sheet of paper. For each pair he wrote either "great...
2
10
#include <bits/stdc++.h> using namespace std; template <typename A, typename B> string to_string(pair<A, B> p); template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p); template <typename A, typename B, typename C, typename D> string to_string(tuple<A, B, C, D> p); string to_string(const string...
CPP
110_A. Nearly Lucky Number
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky d...
2
7
# your code goes here n=int(input()) n=str(n) k=0 for i in range(len(n)): if int(n[i]) == 4 or int(n[i]) == 7: k=k+1 if k==4 or k==7: print('YES') else: print('NO')
PYTHON3
110_A. Nearly Lucky Number
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky d...
2
7
a = input() dontPrint = False x = 0 for l in a: if l=='4' or l=='7': x += 1 if (x==4 or x==7): print("YES") else: print ("NO")
PYTHON3
110_A. Nearly Lucky Number
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky d...
2
7
num = list(raw_input()) stack = 0 for i in num: if i=="4" or i == "7": stack += 1 b = list(str(stack)) #print b sta = 0 for i in b: #print i if i == "4" or i == "7": sta +=1 if sta == len(b):print "YES" else : print "NO"
PYTHON
110_A. Nearly Lucky Number
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky d...
2
7
import sys n = input() a = [4, 7] count_happy = 0 for i in n: if int(i) == 4 or int(i) == 7: count_happy += 1 for i in str(count_happy): if int(i) not in a: print('NO') sys.exit() print('YES')
PYTHON3
110_A. Nearly Lucky Number
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky d...
2
7
n = input() c = 0 for i in range(0,len(n)): if n[i] == '4' or n[i] == '7': c += 1 d = str(c) for i in d: if i != '4' and i != '7': print("NO") exit(0) print("YES")
PYTHON3
110_A. Nearly Lucky Number
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky d...
2
7
n = input() a = n.count('4') b = n.count('7') if a + b == 4 or a + b == 7: print("YES") else: print("NO")
PYTHON3
110_A. Nearly Lucky Number
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky d...
2
7
from sys import stdin, exit def is_lucky(cur, n): if cur == '' or len(cur) <= len(n): if cur != '' and cur == n: print('YES') exit() is_lucky(cur + '4', n) is_lucky(cur + '7', n) is_lucky('4' + cur, n) is_lucky('7' + cur, n) n = stdin.readline().rstri...
PYTHON3
110_A. Nearly Lucky Number
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky d...
2
7
number = input() count4 = number.count('4') count7 = number.count('7') final = count4 + count7 if final == 4 or final == 7: print('YES') else: print('NO')
PYTHON3
110_A. Nearly Lucky Number
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky d...
2
7
a=list(input()) a=map(int,a) a=list(a) r=a.count(7)+a.count(4) if r==4 or r==7: print('YES') else: print('NO')
PYTHON3
110_A. Nearly Lucky Number
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky d...
2
7
num=input() num_num=0 cnt=0 for i in range(len(num)): if num[i]=='4' or num[i]=='7': num_num+=1 num_num=str(num_num) for i in range(len(num_num)): if num_num[i]=='4' or num_num[i]=='7': cnt+=1 if cnt==len(num_num): print('YES') else: print('NO')
PYTHON3
110_A. Nearly Lucky Number
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky d...
2
7
data = list(input()) four = data.count("4") seven = data.count("7") total = four + seven if total == 4 or total == 7: print("YES") else: print("NO")
PYTHON3
110_A. Nearly Lucky Number
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky d...
2
7
s=input() dic={} for i in s: if i in dic: dic[i]+=1 else: dic[i]=1 pas=False if '4' in dic and '7' in dic: if dic['7']+dic['4']==7 or dic['7']+dic['4']==4: print("YES") pas=True elif '4' in dic: if dic['4']==4 or dic['4']==7: print("YES") pas=T...
PYTHON3
110_A. Nearly Lucky Number
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky d...
2
7
a=str(input()) a=list(a) s=a.count('4') + a.count('7') if s==4 or s==7: print("YES") else: print("NO")
PYTHON3
110_A. Nearly Lucky Number
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky d...
2
7
c = 0 for i in input(): if i == '4' or i == '7': c += 1 if c > 7: break print("YES" if c == 7 or c == 4 else "NO")
PYTHON3
110_A. Nearly Lucky Number
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky d...
2
7
number = input() n1 = number.count('7') n2 = number.count('4') if n1+n2 in [7,4]: print("YES\n") else: print("NO\n")
PYTHON3
110_A. Nearly Lucky Number
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky d...
2
7
n = input().strip() s = 0 for i in n: if i == '4' or i == '7': s += 1 x = str(s) if len(set(x)) == 2 and '4' in set(x) and '7' in set(x) or \ len(set(x)) == 1 and ('4' in set(x) or '7' in set(x)): print("YES") else: print("NO")
PYTHON3
110_A. Nearly Lucky Number
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky d...
2
7
input_list = [] num = 0 while True: if num == 1: break line = input() # line = line.split() line = list(map(int, line)) # input_list.append(line) num += 1 # input_list.__delitem__(0) count = 0 for digit in line: if digit == 4 or digit == 7: count += 1 lucky = [int(i) for i...
PYTHON3
110_A. Nearly Lucky Number
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky d...
2
7
import sys if __name__ == "__main__": n = sys.stdin.readline().strip() total = n.count("4") + n.count("7") if total == 4 or total == 7: sys.stdout.write("YES\n") else: sys.stdout.write("NO\n")
PYTHON3
110_A. Nearly Lucky Number
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky d...
2
7
n = input() t = n.count('4') + n.count('7') if t == 4 or t ==7: if t != 0: print('YES') else: print('NO') else: print('NO')
PYTHON3
110_A. Nearly Lucky Number
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky d...
2
7
a = input('') razultat = 0 for i in a: if i == '4' or i == '7': razultat += 1 if razultat == 4 or razultat == 7: print('YES') else: print('NO')
PYTHON3
110_A. Nearly Lucky Number
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky d...
2
7
def isLucky(xx): x = xx if x == 0: return False ans = True while x > 0: if not(x%10 == 4 or x%10 == 7): ans = False break x = x//10 return ans s = input() print('YES' if isLucky(s.count('4') + s.count('7')) else 'NO')
PYTHON3
110_A. Nearly Lucky Number
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky d...
2
7
n = list(input()) a = 0 b = 0 for i in n: if i == "7": a = a + 1 elif i == "4": b = b + 1 if a + b == 4 or a + b == 7: print("YES") else: print("NO")
PYTHON3
110_A. Nearly Lucky Number
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky d...
2
7
n = input() bilangan=n char="4" char2="7" jml=int(bilangan.count(char,0,len(bilangan)))+int(bilangan.count(char2,0,len(bilangan))) if(1<=jml<=10**18) and ((jml==7) or (jml==4)): print('YES') else: print('NO')
PYTHON3
110_A. Nearly Lucky Number
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky d...
2
7
import java.util.Scanner; public class P_110A { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String num = scanner.next(); int luckynum = 0; for (int i=0; i<num.length(); i++) { char c = num.charAt(i); if (c == '4' || c ==...
JAVA
110_A. Nearly Lucky Number
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky d...
2
7
#!/bin/env python3 str = input() s = str.count("4") + str.count("7") if s == 4 or s == 7: print("YES") else: print("NO")
PYTHON3
110_A. Nearly Lucky Number
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky d...
2
7
n = input("") x = 0 for i in n: if i == "7" or i == "4": x += 1 if x == 0 or (x != 4 and x != 7): print("NO") else: print("YES")
PYTHON3
110_A. Nearly Lucky Number
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky d...
2
7
#include <bits/stdc++.h> using namespace std; long long countDig(long long s) { return floor(log10(s) + 1); } int main() { long long num; int luckyNums = 0; string n; cin >> num; int digits = countDig(num); n = to_string(num); for (int i = 0; i < digits; i++) { if (n[i] == '4' || n[i] == '7') luckyNum...
CPP
110_A. Nearly Lucky Number
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky d...
2
7
import java.util.Scanner; public class main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); char[] n = sc.next().toCharArray(); int count = 0; for (int i = 0; i < n.length; i++) { if (n[i] == '4' || n[i] == '7') { count++...
JAVA
110_A. Nearly Lucky Number
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky d...
2
7
n=int(input()) n=list(str(n)) c=n.count("4")+n.count("7") if c==4 or c==7: print("YES") else: print("NO")
PYTHON3
110_A. Nearly Lucky Number
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky d...
2
7
test = input() Lucky = False luckyNumber = [4, 7] counter = 0 for j in range(0, len(test)): if int(test[j]) in luckyNumber: counter += 1 if counter in luckyNumber: Lucky = True if Lucky: print("YES") else: print("NO")
PYTHON3
110_A. Nearly Lucky Number
Petya loves lucky numbers. We all know that lucky numbers are the positive integers whose decimal representations contain only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Unfortunately, not all numbers are lucky. Petya calls a number nearly lucky if the number of lucky d...
2
7
# https://codeforces.com/problemset/problem/110/A n = input() c = sum([1 for x in n if x == "7" or x == "4"]) if c == 4 or c == 7: print("YES") else: print("NO")
PYTHON3