solution
stringlengths
10
983k
difficulty
int64
0
25
language
stringclasses
2 values
#include <bits/stdc++.h> using namespace std; int n; char s[500050]; int sa[500050], height[500050], rk[500050], xx[500050], yy[500050], t[500050]; void getsa() { int *x = xx, *y = yy, m = 200; for (int i = 1; i <= n; ++i) ++t[x[i] = s[i]]; for (int i = 2; i <= m; ++i) t[i] += t[i - 1]; for (int i = n; i; --i) sa[t[x[i]]--] = i; memset(t + 1, 0, m << 2); for (int len = 1;; len <<= 1) { int tot = 0; for (int i = n - len + 1; i <= n; ++i) y[++tot] = i; for (int i = 1; i <= n; ++i) if (sa[i] > len) y[++tot] = sa[i] - len; for (int i = 1; i <= n; ++i) ++t[x[i]]; for (int i = 2; i <= m; ++i) t[i] += t[i - 1]; for (int i = n; i; --i) sa[t[x[y[i]]]--] = y[i]; memset(t + 1, 0, m << 2); swap(x, y); x[sa[1]] = 1; m = 1; for (int i = 2; i <= n; ++i) x[sa[i]] = y[sa[i]] == y[sa[i - 1]] && y[sa[i] + len] == y[sa[i - 1] + len] ? m : ++m; if (m == n) break; } for (int i = 1; i <= n; ++i) rk[sa[i]] = i; for (int i = 1, k = 0; i <= n; ++i) { if (rk[i] == 1) continue; if (k) --k; while (s[i + k] == s[sa[rk[i] - 1] + k]) ++k; height[rk[i]] = k; } } int last[1000010]; vector<int> pos[1000010]; long long ans; int main() { scanf("%d %s", &n, s + 1); getsa(); pos[n].push_back(-n - 1); for (int i = n, cur = n; i; --i) { cur += s[i] == '(' ? 1 : -1; int l = i + height[rk[i]] + 1, r = last[cur + 1] ? last[cur + 1] : n + 1; pos[cur].push_back(-i); if (l <= r) ans += upper_bound(pos[cur].begin(), pos[cur].end(), -l) - lower_bound(pos[cur].begin(), pos[cur].end(), -r); last[cur] = i; } printf("%lld", ans); return 0; }
12
CPP
#include <bits/stdc++.h> using namespace std; int main() { long long n, l, r, x; cin >> n >> l >> r >> x; long long a[n]; for (long long i = 0; i < n; i++) { cin >> a[i]; } int ans = 0; for (long long i = 0; i < (1 << n); i++) { int ct = 0; vector<long long> v; for (long long j = 0; j < n; j++) { if (i & (1 << j)) { ct++; v.push_back(a[j]); } } if (ct < 2) { continue; } long long mi = v[0], ma = v[0], sum = 0; for (long long j = 0; j < v.size(); j++) { if (mi > v[j]) { mi = v[j]; } if (ma < v[j]) { ma = v[j]; } sum += v[j]; } if (sum >= l && sum <= r && ma - mi >= x) { ans++; } } cout << ans; return 0; }
8
CPP
for t in range(int(input())): n = int(input()) st = input() k=0 close = 0 open = 0 for i in range(n): if st[i] == ")" : close+=1 else: open+=1 if close>open: k+=1 close-=1 print( k)
9
PYTHON3
for t in range(int(input())): a = [[int(d) for d in input()] for i in range(9)] def f(x): return 1 if x!=1 else 2 for i in range(9): a[3*(i%3)+(i//3)][i] = f(a[3*(i%3)+(i//3)][i]) for i in range(9): print(''.join([str(x) for x in a[i]]))
10
PYTHON3
a , b , c = map (int , input() . split()) if( a == 1 and b == 0 and b == 0 ): print( "Close" ) elif( a == 0 and b == 1 and c == 0 ): print( "Close" ) elif( a == 1 and b == 1 and c == 0 ): print( "Open" ) elif( a == 0 and b == 0 and c == 1 ): print( "Open" ) elif( a == 0 and b == 0 and c == 0 ): print( "Close" )
0
PYTHON3
import sys import math n,m=map(int,input().split()) if(m==0): print(n,n) elif(n==1): print(n,n) else: store=[0]*(n+1) if(m>=(n*(n-1))//2): print("0","0") else: for i in range(2,n+1): store[i]+=(i*(i-1))//2 if(m>store[i-1] and m<=store[i]): amax=n-i if(m<math.ceil(n/2)): amin=n-2*m else: amin=0 if(m==1): amax=n-2 elif(m==2): amax=n-3 #print(store) print(amin,amax)
8
PYTHON3
#include <bits/stdc++.h> using namespace std; const int MAXN = 3e5 + 10, MOD = 1e9 + 7; struct basis { static constexpr int D = 15; long long base[D] = {}; long long who[D] = {}; void add(long long x, long long me) { for (int i = 0; i < D; i++) if ((x >> i) & 1) { if (!base[i]) { base[i] = x; who[i] = me; return; } x ^= base[i]; me ^= who[i]; } } long long contains(long long x) { long long me = 0; for (int i = 0; i < D; i++) if ((x >> i) & 1) { if (!base[i]) return -1; x ^= base[i]; me ^= who[i]; } return me; } }; const int LEFT = basis::D; void solve() { int n; cin >> n; vector<int> a(n); for (auto& c : a) cin >> c; vector<array<int, 3>> ans; auto op = [&](int i, int j, int k) { a[i] ^= 1, a[j] ^= 1, a[k] ^= 1; ans.push_back({i, j, k}); }; while (int(a.size()) > LEFT) { int l = int(a.size()) - 6, r = int(a.size()) - 1; vector<array<long long, 3>> cur; auto add = [&](int i, int dist) { int prv = i - dist, nxt = i + dist; if (nxt > r || nxt < l) return 0; long long cur_mask = 0; if (i >= l) cur_mask ^= 1ll << (i - l); if (prv >= l) cur_mask ^= 1ll << (prv - l); cur_mask ^= 1ll << (nxt - l); cur.push_back({cur_mask, i, dist}); return 1; }; for (int i = l; i <= r; i++) { int mid = l - 1; add(mid, i - mid); for (int dist = 1;; dist++) { if (!add(i, dist)) break; } } vector<int> choose; long long my_mask = 0; for (int i = l; i <= r; i++) if (a[i]) my_mask ^= 1ll << (i - l); for (int i = 0; i < int(cur.size()); i++) for (int j = i + 1; j < int(cur.size()); j++) { if ((cur[i][0] ^ cur[j][0]) == my_mask) choose = {i, j}; } for (int i = 0; i < int(cur.size()); i++) if (cur[i][0] == my_mask) choose = {i}; for (int i : choose) { int mid = cur[i][1], dist = cur[i][2]; op(mid - dist, mid, mid + dist); } for (int rep = 0; rep < 6; rep++) { assert(a.back() == 0); a.pop_back(); } } int l = 0, r = int(a.size()) - 1; basis b; vector<array<int, 2>> cur; for (int i = l; i <= r; i++) for (int dist = 1;; dist++) { int prv = i - dist, nxt = i + dist; if (nxt > r || prv < l) break; long long cur_mask = 1ll << (i - l); if (prv >= l) cur_mask ^= 1ll << (prv - l); if (prv <= r) cur_mask ^= 1ll << (nxt - l); b.add(cur_mask, 1ll << int(cur.size())); cur.push_back({i, dist}); } long long my_mask = 0; for (int i = l; i <= r; i++) if (a[i]) my_mask ^= 1ll << (i - l); long long chose = b.contains(my_mask); if (chose == -1) { cout << "NO\n"; return; } cout << "YES\n"; for (int i = 0; i < int(cur.size()); i++) if ((chose >> i) & 1) { int mid = cur[i][0], dist = cur[i][1]; op(mid - dist, mid, mid + dist); } cout << int(ans.size()) << '\n'; for (auto c : ans) cout << c[0] + 1 << ' ' << c[1] + 1 << ' ' << c[2] + 1 << '\n'; } int main() { ios::sync_with_stdio(false); cin.tie(0); int T = 1; while (T--) solve(); }
11
CPP
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long t; t = 1; for (long long test = 1; test <= t; test++) { int m, n; cin >> m >> n; int nature[n]; for (int i = 0; i < n; ++i) { cout << 1 << endl; int ans; cin >> ans; if (ans == 0) { return 0; } nature[i] = (ans == 1); } int num = 0, j = 0; for (int i = 29; i >= 0; i--) { int temp = num + (1 << i); if (temp <= m) { cout << temp << endl; int x; cin >> x; if (nature[(j % n)] == 0) x = (-1 * x); if (x == 0) { return 0; } if (x == 1) num = temp; j++; } } return 0; } }
8
CPP
#include <iostream> #include <string> int main(){ int n; // the number of datasets std::cin >> n; std::cin.ignore(); for(int i = 0; i < n; ++i){ std::string text; std::getline(std::cin, text); // input int text_size = text.size(); int moji = text.find("Hoshino"); while(moji != std::string::npos){ text.replace(moji, 7, "Hoshina"); moji = text.find("Hoshino", moji); } std::cout << text << std::endl; //output } return 0; }
0
CPP
#include <bits/stdc++.h> using namespace std; const int maxN = 100000 + 10, maxM = 10000 + 10; long long N, K, H; int m[maxN], num[maxN], ans[maxN]; long long v[maxN]; bool cmp(int a, int b) { return (m[a] > m[b] || (m[a] == m[b] && v[a] > v[b])); } bool check(double T) { long long now = 0; for (int k = K - 1; k >= 0; --k) { ans[k] = -1; while (now < N) { int j = num[now]; if ((double)v[j] * T >= (double)(k + 1) * H) { ans[k] = j; break; } ++now; } if (ans[k] == -1) return false; ++now; } return true; } int main() { scanf("%I64d %I64d %I64d", &N, &K, &H); for (int i = 0; i < N; ++i) scanf("%d", &m[i]); for (int i = 0; i < N; ++i) scanf("%d", &v[i]); for (int i = 0; i < N; ++i) num[i] = i; sort(num, num + N, cmp); double l = 0, r = 1000000007; for (int i = 0; i < 100; ++i) { double mid = (l + r) * 0.5; if (check(mid)) r = mid; else l = mid; } check(r); for (int i = 0; i < K; ++i) { printf("%d", ans[i] + 1); (i == K - 1) ? printf("\n") : printf(" "); } return 0; }
10
CPP
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10, mod = 1e9 + 7; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int k; cin >> k; for (int i = (N - 10) * 10;; i--) { if ((i + k) % 2000 == 0) { int y = (i + k) / 2000; cout << 2000 << endl; int t = 0; for (int j = 0; j < 1998; j++) cout << 0 << " "; cout << -(i - y) << " "; cout << i; return 0; } } return 0; }
8
CPP
n, h = map(int, input().split()) a = [int(i) for i in input().split()] c = 0 for i in range(n): if(a[i] <= h): c = c + 1 else: c = c + 2 print(c)
7
PYTHON3
#include <iostream> #include <cmath> #include <vector> #include <algorithm> using namespace std; long double EPS = 1e-5; class Point { public: long double px, py; Point() : px(0), py(0) {}; Point(long double px_, long double py_) : px(px_), py(py_) {}; bool operator==(const Point& p) const { return fabs(px - p.px) < EPS && fabs(py - p.py) < EPS; } bool operator!=(const Point& p) const { return fabs(px - p.px) > EPS || fabs(py - p.py) > EPS; } bool operator<(const Point& p) const { return p.px - px > EPS ? true : (fabs(px - p.px) < EPS && p.py - py > EPS); } bool operator>(const Point& p) const { return px - p.px > EPS ? true : (fabs(px - p.px) < EPS && py - p.py > EPS); } bool operator<=(const Point& p) const { return !(Point(px, py) > p); } bool operator>=(const Point& p) const { return !(Point(px, py) < p); } Point operator+(const Point& p) const { return Point(px + p.px, py + p.py); } Point operator-(const Point& p) const { return Point(px - p.px, py - p.py); } Point operator/(long double d) const { return Point(px / d, py / d); } friend Point operator*(const Point p, long double d) { return Point(p.px * d, p.py * d); } friend Point operator*(long double d, const Point& p) { return p * d; } Point& operator+=(const Point& p1) { px += p1.px, py += p1.py; return *this; } Point& operator-=(const Point& p1) { px -= p1.px, py -= p1.py; return *this; } Point& operator*=(long double d) { px *= d, py *= d; return *this; } Point& operator/=(long double d) { px /= d, py /= d; return *this; } }; class Line { public: Point p1, p2; Line() : p1(Point()), p2(Point()) {}; Line(Point p1_, Point p2_) : p1(p1_), p2(p2_) {}; Line(long double p1x, long double p1y, long double p2x, long double p2y) : p1(Point(p1x, p1y)), p2(Point(p2x, p2y)) {}; bool operator==(const Line& s) const { return (p1 == s.p1 && p2 == s.p2) || (p1 == s.p2 && p2 == s.p1); } bool operator!=(const Line& s) const { return !(Line(p1, p2) == s); } }; long double norm(const Point& a) { return a.px * a.px + a.py * a.py; } long double crs(const Point& a, const Point& b) { return a.px * b.py - a.py * b.px; } long double abs(const Point& a) { return sqrtl(norm(a)); } long double dot(const Point& a, const Point& b) { return a.px * b.px + a.py * b.py; } long double dist(const Point& a, const Point& b) { return abs(b - a); } int ccw(const Point& p0, const Point& p1, const Point& p2) { Point a = p1 - p0, b = p2 - p0; if (crs(a, b) > EPS) return 1; if (crs(a, b) < -EPS) return -1; if (dot(a, b) < -EPS) return 2; if (norm(b) - norm(a) > EPS) return -2; return 0; } Line calc(Line a) { //return a; if (a.p1 == a.p2) return a; Point E = (a.p1 + a.p2); E.px /= 2.0L; E.py /= 2.0L; long double ex = a.p2.px - E.px, ey = a.p2.py - E.py; long double BAR = 1000.0L / sqrtl(ex * ex + ey * ey); ex *= BAR; ey *= BAR; return Line{ Point{E.px - ex, E.py - ey}, {E.px + ex, E.py + ey} }; } Point crp(Line a, Line b) { a = calc(a); b = calc(b); Point c = b.p2 - b.p1; long double d1 = abs(crs(c, a.p1 - b.p1)); long double d2 = abs(crs(c, a.p2 - b.p1)); return a.p1 + (a.p2 - a.p1) * (d1 / (d1 + d2)); } long double area(vector<Point> v) { long double ret = 0.0L; for (int i = 0; i < v.size(); i++) ret += crs(v[i], v[(i + 1) % v.size()]); return ret / 2; } int contain(vector<Point> v, Point p) { bool in = false; for (int i = 0; i < v.size(); ++i) { Point a = v[i] - p, b = v[(i + 1) % v.size()] - p; if (a.py > b.py) swap(a, b); if (a.py <= EPS && EPS < b.py) if (crs(a, b) < -EPS) in = !in; if (fabs(crs(a, b)) < EPS && dot(a, b) <= EPS) return 1; } return in ? 2 : 0; } vector<Point> convex_hull(vector<Point> v) { if (v.size() < 3) return v; sort(v.begin(), v.end()); vector<Point> u = { v[0], v[1] }, l = { v[v.size() - 1], v[v.size() - 2] }; for (int i = 2; i < v.size(); i++) { for (int n = u.size(); n >= 2 && ccw(u[n - 2], u[n - 1], v[i]) >= 0; n--) u.pop_back(); u.push_back(v[i]); } for (int i = v.size() - 3; i >= 0; i--) { for (int n = l.size(); n >= 2 && ccw(l[n - 2], l[n - 1], v[i]) >= 0; n--) l.pop_back(); l.push_back(v[i]); } reverse(l.begin(), l.end()); for (int i = u.size() - 2; i >= 1; i--) l.push_back(u[i]); return l; } long double Degree(Line r) { long double vx = (r.p2.px - r.p1.px); long double vy = (r.p2.py - r.p1.py); if (vy < 0) { vy *= -1; vx *= -1; } return vx / sqrtl(vx * vx + vy * vy); } int N, M; Point C[19], E[19]; vector<Line>A; vector<Point>B, J[19]; void init() { for (int i = 0; i < 19; i++) { C[i] = Point{ 0,0 }; E[i] = Point{ 0,0 }; J[i].clear(); } B.clear(); A.clear(); N = 0; M = 0; } int main() { while (true) { init(); cin >> N >> M; if (N == 0 && M == 0) break; vector<Point>L; for (int i = 0; i < N; i++) { cin >> C[i].px >> C[i].py; L.push_back(C[i]); } for (int i = 0; i < M; i++) cin >> E[i].px >> E[i].py; for (int i = 0; i < N; i++) A.push_back(Line{ C[i], C[(i + 1) % N] }); for (int i = 0; i < M; i++) { for (int j = i + 1; j < M; j++) { Point T = (E[i] + E[j]); T.px /= 2.0L; T.py /= 2.0L; double e1 = (E[i].px - T.px), e2 = (E[i].py - T.py); Point A1 = Point{ T.px - e2, T.py + e1 }; Point A2 = Point{ T.px + e2, T.py - e1 }; A.push_back(Line{ A1, A2 }); } } for (int i = 0; i < A.size(); i++) { for (int j = i + 1; j < A.size(); j++) { long double T1 = Degree(A[i]); long double T2 = Degree(A[j]); if (fabs(T1 - T2) < EPS) continue; Point F = crp(A[i], A[j]); if (contain(L, F) >= 1) B.push_back(F); } } sort(B.begin(), B.end()); B.erase(unique(B.begin(), B.end()), B.end()); for (int i = 0; i < B.size(); i++) { long double maxn = 1e9; for (int j = 0; j < M; j++) maxn = min(maxn, dist(E[j], B[i])); for (int j = 0; j < M; j++) { long double G = dist(E[j], B[i]); if (G - maxn < EPS) J[j].push_back(B[i]); } } for (int i = 0; i < M; i++) { sort(J[i].begin(), J[i].end()); J[i].erase(unique(J[i].begin(), J[i].end()), J[i].end()); vector<Point> U = convex_hull(J[i]); long double ans = area(U); printf("%.12Lf\n", ans); } } return 0; }
0
CPP
# =__=' n, m = map(int, input().split()) a = [] for i in range(n): a.append(input()) b = (n % 2 == 0) while (b): b = True for i in range(n // 2): if (a[i] != a[n - i - 1]): b = False break b = b and (n % 2 == 0) if (b): n = n // 2 print(n)
8
PYTHON3
#include <bits/stdc++.h> #include <string.h> #define rep(i, n) for(int i = 0; i<(n); i++) using namespace std; typedef long long ll; //pi = 3.14159265358979323846 int main() { int n; cin >> n; int a[4][13] = {}; int x, y; char c[] = "SHCD"; char b; rep(i, n){ cin >> b >> y; rep(j, 4) if(b == c[j]) x = j; a[x][y - 1] = 1; } rep(i, 4){ rep(j, 13){ if(a[i][j] == 0) cout << c[i] << " " << j + 1 << endl; } } }
0
CPP
#include <bits/stdc++.h> int a[1000001]; int s = 1000000; int n, t; int main() { scanf("%d", &n); printf("%d\n", n); for (int i = 0; i < n; i++) { scanf("%d", &t); a[t]++; } for (int i = 1; i <= s; i++) if (a[i] > 0 && a[s - i + 1] == 0) { printf("%d ", s - i + 1); n--; } for (int i = 1; i <= s && n > 0; i++) if (a[i] == 0 && a[s - i + 1] == 0) { printf("%d %d ", i, s - i + 1); n -= 2; } return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; vector<pair<double, double>> crosspoint(double x1, double y1, double r2, double x2, double y2, double r1){ x1 -= x2; y1 -= y2; double S = x1*x1 + y1*y1; double a = (S + r1*r1 - r2*r2) / 2; double D = S*r1*r1-a*a; if(D < 0) return {}; double A1 = a * x1; double B1 = y1 * sqrt(D); double A2 = a * y1; double B2 = x1 * sqrt(D); return { {(A1+B1)/S+x2, (A2-B2)/S+y2}, {(A1-B1)/S+x2, (A2+B2)/S+y2} }; } double EPS = 1e-9; int main(){ int N, K; cin >> N >> K; vector<double> X(N), Y(N), C(N); for(int i=0; i<N; i++) cin >> X[i] >> Y[i] >> C[i]; auto check = [&](double T)->bool{ vector<double> R(N); for(int i=0; i<N; i++) R[i] = T/C[i]; vector<pair<double, double>> cand; for(int i=0; i<N; i++) cand.emplace_back(X[i], Y[i]); for(int i=0; i<N; i++) for(int j=i+1; j<N; j++){ auto res = crosspoint(X[i], Y[i], R[i], X[j], Y[j], R[j]); for(auto& p : res) cand.push_back(p); } for(auto& p : cand){ double x = p.first, y = p.second; int num = 0; for(int i=0; i<N; i++) if(hypot(x-X[i], y-Y[i]) <= R[i] + EPS) num++; if(num >= K) return true; } return false; }; double ok = 1e9, ng = 0; for(int t=0; t<100; t++){ double mid = (ok+ng)/2; (check(mid) ? ok : ng) = mid; } cout << fixed << setprecision(10) << ok << endl; return 0; }
0
CPP
n, m = map(int, input().split(' ')) full_body_line = '#'*m right_body_line = '.'*(m - 1) + '#' left_body_line = '#' + '.'*(m - 1) i = 1 for j in range(n): if (i == 1): print(full_body_line) i = 2 elif (i == 2): print(right_body_line) i = 3 elif (i == 3): print(full_body_line) i = 4 else: print(left_body_line) i = 1
7
PYTHON3
#include <bits/stdc++.h> int d(char *s) { if (*s == 'm') return 0; if (*s == 'w') return 2; if (*s == 'f') return 4; if (*s == 't') return s[1] == 'u' ? 1 : 3; return s[1] == 'a' ? 5 : 6; } int main() { char a[1000], b[1000]; scanf("%s %s", a, b); int k = (d(b) - d(a) + 7) % 7; if (k == 0 || k == 2 || k == 3) printf("YES\n"); else printf("NO\n"); }
7
CPP
#include <bits/stdc++.h> char str[110]; int main() { int len, t, _max = 0; scanf("%s", str); len = strlen(str); for (int i = 0; i < len; i++) for (int j = i + 1; j < len; j++) { t = 0; while (str[i + t] == str[j + t]) t++; if (t > _max) _max = t; } printf("%d", _max); return 0; }
7
CPP
#include<iostream> using namespace std; int main() { int h; int r; cin >> h >> r; if (h < 0 && h + r == 0) { cout << "0" << endl; } else if (h+r>0) { cout << "1"<<endl; } else { cout << "-1"<<endl; } return 0; }
0
CPP
t= int(input()) while t: t -= 1 n,k= map(int,input().split()) a = list(map(int,input().split())) if k%2==0: times=2 else: times=1 for i in range(times): d=max(a) for i in range(n): a[i] = d-(a[i]) print(*a)
8
PYTHON3
#include <stdio.h> int main(void) { int i, j, k, ans = 0, a; for(i = 0; i < 5; ++i) { scanf("%d", &a); ans += a > 40 ? a : 40; } ans /= 5; printf("%d\n", ans); return 0; }
0
CPP
#include <bits/stdc++.h> using namespace std; using VI = vector<int>; using VVI = vector<VI>; using PII = pair<int, int>; using LL = long long; using VL = vector<LL>; using VVL = vector<VL>; using PLL = pair<LL, LL>; using VS = vector<string>; #define ALL(a) begin((a)),end((a)) #define RALL(a) (a).rbegin(), (a).rend() #define PB push_back #define EB emplace_back #define MP make_pair #define SZ(a) int((a).size()) #define SORT(c) sort(ALL((c))) #define RSORT(c) sort(RALL((c))) #define FOR(i,a,b) for(int i=(a);i<(b);++i) #define REP(i,n) FOR(i,0,n) #define FF first #define SS second template<class S, class T> istream& operator>>(istream& is, pair<S,T>& p){ return is >> p.FF >> p.SS; } template<class S, class T> ostream& operator<<(ostream& os, const pair<S,T>& p){ return os << p.FF << " " << p.SS; } template<class T> void maxi(T& x, T y){ if(x < y) x = y; } template<class T> void mini(T& x, T y){ if(x > y) x = y; } const double EPS = 1e-10; const double PI = acos(-1.0); const LL MOD = 1e9+7; const int H = 19; const int W = 15; string bd[H]; int id[H][W]; int dx[] = {1,1,0,-1,-1,-1,0,1}; int dy[] = {0,1,1,1,0,-1,-1,-1}; struct PH{ template<class T, class U> size_t operator()(const pair<T,U>& x) const{ size_t seed = 0; seed ^= hash<T>{}(x.first) + 0x9e3779b9 + (seed<<6) + (seed>>2); seed ^= hash<U>{}(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2); return seed; } }; using D = pair<PII,int>; namespace std{ template<> struct hash<D>{ size_t operator()(const D& d) const{ return PH{}(MP(PH{}(d.FF), d.SS)); } }; } bool isin(const PII& p){ return (0 <= p.FF && p.FF < H && 0 <= p.SS && p.SS < W); } int main(){ cin.tie(0); ios_base::sync_with_stdio(false); REP(i,19) cin >> bd[i]; PII w; int gid = 0; REP(y,H) REP(x,W){ if(bd[y][x] == 'O') w = MP(y,x); else if(bd[y][x] == 'X') id[y][x] = gid++; } int ans = -1; map<D,int> memo; queue<D> q; q.push(D(w,(1<<21)-1)); memo[D(w,(1<<21)-1)] = 0; while(!q.empty()){ D d = q.front(); q.pop(); PII p = d.FF; if(p.FF >= H || (p.FF == H-1 && isin(p))){ ans = memo[d]; break; } if(p.FF < 0 || p.SS < 0 || p.SS >= W) continue; REP(dir,8){ int nb = d.SS; PII np(p.FF+dy[dir], p.SS+dx[dir]); while(isin(np) && bd[np.FF][np.SS] == 'X' && (nb>>id[np.FF][np.SS]&1)){ nb ^= 1 << id[np.FF][np.SS]; np.FF += dy[dir]; np.SS += dx[dir]; } if(nb == d.SS) continue; if(!memo.count(D(np,nb))){ memo[D(np,nb)] = memo[d] + 1; q.push(D(np,nb)); } } } cout << ans << endl; return 0; }
0
CPP
#include<bits/stdc++.h> using namespace std; #define ll long long typedef vector<int> vi; #define OJ \ freopen("input.txt", "r", stdin); \ freopen("output.txt", "w", stdout); typedef pair<int,int> pii; int main() { // OJ int t; cin>>t; while(t--){ int n , m , k; cin>>n>>m>>k; vi data(n); for(int i = 0; i<n; i++) cin>>data[i]; set <pii> ans; for(int i =1; i<=m; i++) ans.insert(make_pair(0 , i)); cout<<"YES"<<endl; for(int i = 0; i<n; i++){ pii tmp = *ans.begin(); cout<<tmp.second<<" "; ans.insert(make_pair(tmp.first + data[i] , tmp.second)); ans.erase(ans.find(tmp)); } cout<<endl; } return 0; }
9
CPP
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int N; cin >> N; while (N-- > 0) { int C, sum; cin >> C >> sum; int ans = 0; int den = C, num = sum; while (den != 0) { ans += (num / den) * (num / den); num -= (num / den); den--; } cout << ans; cout << '\n'; } return 0; }
7
CPP
string = str(input()) print(string.swapcase())
0
PYTHON3
#include <bits/stdc++.h> using namespace std; long long x, y, px, py; int main() { cin >> x >> y >> px >> py; long long a = px - x + 1; long long b = py - y + 1; cout << (a - a / 2) * (b - b / 2) + (a / 2) * (b / 2); return 0; }
11
CPP
#include <cstdio> #include <vector> #include <algorithm> int main() { int N; scanf("%d", &N); std::vector<int64_t> C(N, 0); std::vector<int64_t> D(N + 1, 0); for (int i = 0; i < N; ++i) { int a; scanf("%d", &a); C[--a]++; D[C[a]]++; } std::vector<int64_t> S(N + 1, 0); for (int i = 1; i <= N; ++i) { S[i] = S[i - 1] + D[i]; } for (int K = 1; K <= N; ++K) { int64_t low = 0, high = N + 1; while (high - low > 1) { int64_t x = (low + high) / 2; if (S[x] >= K * x) { low = x; } else { high = x; } } printf("%lld\n", low); } }
0
CPP
#include <bits/stdc++.h> using namespace std; int i, j, n, m, s, t; int l = 0, k = 0; int x = 0, y = 0, X0, Y0, X1, Y1, X2, Y2; const double EPS = 1E-9; struct pt { long double x, y; pt() {} pt(long double xx, long double yy) { x = xx; y = yy; } bool operator<(const pt& p) const { return x < p.x - EPS || abs(x - p.x) < EPS && y < p.y - EPS; } long double ang() { long double res = 0; if (x == 0 && y == 0) res = 0; if (x == 0) res = (y > 0 ? 1 : -1) * 3.141592653569 / 4.; long double d = 0; if (y < 0 && x < 0) d = -3.141592653569; if (y > 0 && x < 0) d = 3.141592653569; res = atan(y / x) + d; return res; } }; vector<pt> f1, f2, f3; struct line { double a, b, c; line() {} line(pt p, pt q) { a = p.y - q.y; b = q.x - p.x; c = -a * p.x - b * p.y; norm(); } void norm() { long double z = sqrt(a * a + b * b); if (abs(z) > EPS) a /= z, b /= z, c /= z; } long double dist(pt p) const { return a * p.x + b * p.y + c; } }; inline bool betw(long double l, long double r, long double x) { return min(l, r) <= x + EPS && x <= max(l, r) + EPS; } inline bool intersect_1d(long double a, long double b, long double c, long double d) { if (a > b) swap(a, b); if (c > d) swap(c, d); return max(a, c) <= min(b, d) + EPS; } bool intersect(pt a, pt b, pt c, pt d, pt& left, pt& right) { if (!intersect_1d(a.x, b.x, c.x, d.x) || !intersect_1d(a.y, b.y, c.y, d.y)) return false; line m(a, b); line n(c, d); long double zn = (m.a * n.b - m.b * n.a); if (abs(zn) < EPS) { if (abs(m.dist(c)) > EPS || abs(n.dist(a)) > EPS) return false; if (b < a) swap(a, b); if (d < c) swap(c, d); left = max(a, c); right = min(b, d); return true; } else { left.x = right.x = -(m.c * n.b - m.b * n.c) / zn; left.y = right.y = -(m.a * n.c - m.c * n.a) / zn; return betw(a.x, b.x, left.x) && betw(a.y, b.y, left.y) && betw(c.x, d.x, left.x) && betw(c.y, d.y, left.y); } } bool cmp(pt a, pt b) { return a.ang() < b.ang(); } long double sq(pt& a, pt& b, pt& c) { return a.x * (b.y - c.y) + b.x * (c.y - a.y) + c.x * (a.y - b.y); } int main() { long double w, h, a; cin >> w >> h >> a; w /= 2.; h /= 2.; a = 3.141592653569 * a / 180.; f1.push_back(pt(-w, h)); f1.push_back(pt(w, h)); f1.push_back(pt(w, -h)); f1.push_back(pt(-w, -h)); f1.push_back(pt(-w, h)); long double sa = sin(a); long double ca = cos(a); f2.push_back(pt(-1 * ca * w - sa * h, -1 * sa * w + ca * h)); f2.push_back(pt(ca * w - sa * h, sa * w + ca * h)); f2.push_back(pt(ca * w + sa * h, sa * w - ca * h)); f2.push_back(pt(-1 * ca * w + sa * h, -1 * sa * w - ca * h)); f2.push_back(pt(-1 * ca * w - sa * h, -1 * sa * w + ca * h)); for (i = 0; i < f1.size() - 1; i++) for (j = 0; j < f2.size() - 1; j++) { pt AA, BB; if (intersect(f1[i], f1[i + 1], f2[j], f2[j + 1], AA, BB)) { f3.push_back(AA); } } sort(f3.begin(), f3.end(), cmp); long double res = 0; f3.push_back(f3[0]); pt pt0(0, 0); for (i = 0; i < f3.size() - 1; i++) { res += fabs(sq(f3[i], f3[i + 1], pt0)); } cout.unsetf(std::ios::floatfield); cout.precision(10); cout << (res / 2.); return 0; }
7
CPP
#include <bits/stdc++.h> using namespace std; void flash() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); } vector<long long int> parent(1024); void build(long long int v) { parent[v] = v; } long long int find_set(long long int v) { if (parent[v] == v) return v; return parent[v] = find_set(parent[v]); } void union_sets(long long int a, long long int b) { a = find_set(a); b = find_set(b); if (a != b) parent[a] = b; } set<char> badl; bool isEqual(string p1, string p2) { if (p1.size() != p2.size()) return false; for (long long int i = 0; i < min(p1.size(), p2.size()); i++) { if (find_set(p1[i]) == find_set(p2[i])) continue; return false; } return true; } signed main() { for (char c = 'a'; c <= 'z'; c++) build((long long int)c); for (char c = 'A'; c <= 'Z'; c++) build((long long int)c); for (char c = '1'; c <= '9'; c++) build((long long int)c); build('_'); for (char i = 'a'; i <= 'z'; i++) { union_sets((long long int)i, (long long int)i - (long long int)'a' + (long long int)'A'); } union_sets((long long int)'l', (long long int)'i'); union_sets((long long int)'1', (long long int)'i'); union_sets((long long int)'0', (long long int)'O'); string password; cin >> password; long long int n; cin >> n; for (long long int i = 0; i < n; i++) { string s; cin >> s; if (isEqual(s, password)) return cout << "No" << '\n', 0; } cout << "Yes" << '\n'; return 0; }
7
CPP
from sys import stdin input=lambda : stdin.readline().strip() from math import ceil,sqrt,factorial,gcd,log from collections import deque from bisect import bisect_left,bisect_right for _ in range(int(input())): n=int(input()) l=list(map(int,input().split())) z=["a"*100] for i in range(n): s=z[-1][:l[i]] if l[i]!=100: t="a" for j in range(97,123): if chr(j)!=z[-1][l[i]]: t=chr(j) break s+=t+"a"*(100-l[i]-1) z.append(s) for i in z: print(i)
7
PYTHON3
""" 10, 3 1 2 3 4 4 3 2 1 1 2 3 4 5 6 7 8 1 2 3 1 2 3 1 2 3 6 5 1 2 2 1 2 1 2 1 2 1 1 2 1 2 1 """ from collections import Counter for i in range(int(input())): n, k = [int(i) for i in input().split(" ")] l = [int(i) for i in input().split(" ")] max_sum = 0 total_window = n - k + 1 for i in range(total_window): total = sum(l[i:i+k]) if total > max_sum: max_sum = total unique_nums = list(Counter(l).keys()) # print(unique_nums) final_list = [] if len(unique_nums) > k: print(-1) continue elif len(unique_nums) == k: cur_index = 0 while cur_index < len(l): for x in unique_nums: if cur_index >= len(l): break if x == l[cur_index]: final_list.append(x) cur_index += 1 else: final_list.append(x) else: repeating_window = [] cur_index = 0 for i in range(k): repeating_window.append(unique_nums[cur_index]) cur_index += 1 if cur_index >= len(unique_nums): cur_index = 0 unique_nums = repeating_window cur_index = 0 while cur_index < len(l): for x in unique_nums: if cur_index >= len(l): break if x == l[cur_index]: final_list.append(x) cur_index += 1 else: final_list.append(x) print(len(final_list)) print(" ".join([str(i) for i in final_list]))
8
PYTHON3
N = int(input()) A = map(int, input().split()) AI = sorted(((a, i) for i, a in enumerate(A, 1)), reverse=True) def solve(a, i, prev): pl, pr, ps = i, 0, 0 for l, r, s in prev: yield l, r-1, max(s+abs(r-i)*a, ps+abs(i-pl)*a) pl, pr, ps = l, r, s yield pl+1, pr, ps+abs(i-pl)*a prev = [(1, N, 0)] for a,i in AI: prev = [*solve(a,i, prev)] print(max(s for l, r, s in prev))
0
PYTHON3
#include <bits/stdc++.h> using namespace std; mt19937 RNG(chrono::steady_clock::now().time_since_epoch().count()); vector<long long> adj[100005], vis(100005), tin(100005), low(100005); bitset<100005> bs; long long timer = 0; void dfs(long long u, long long baap = -1) { vis[u] = true; tin[u] = low[u] = timer++; long long child = 0; for (long long v : adj[u]) { if (v != baap) { if (vis[v]) { low[u] = min(low[u], tin[v]); } else { dfs(v, u); low[u] = min(low[u], low[v]); if (low[v] >= tin[u] && baap != -1) bs[u] = 1; ++child; } } } if (baap == -1 && child > 1) bs[u] = 1; } void find_cutpoints(long long n) { timer = 0; bs.reset(); vis.assign(n + 1, false); tin.assign(n + 1, -1); low.assign(n + 1, -1); for (long long i = 1; i <= n; ++i) { if (!vis[i]) dfs(i); } } void solve() { long long n, m, k = 0; cin >> n >> m; char mat[n][m]; long long g[n][m]; for (long long i = 0; i < n; i++) { for (long long j = 0; j < m; j++) { cin >> mat[i][j]; if (mat[i][j] == '#') g[i][j] = ++k; } } for (long long i = 0; i < n; i++) { for (long long j = 0; j < m; j++) { if (mat[i][j] == '#') { if (i + 1 < n) { if (mat[i + 1][j] == '#') { adj[g[i][j]].push_back(g[i + 1][j]); adj[g[i + 1][j]].push_back(g[i][j]); } } if (i - 1 >= 0) { if (mat[i - 1][j] == '#') { adj[g[i][j]].push_back(g[i - 1][j]); adj[g[i - 1][j]].push_back(g[i][j]); } } if (j + 1 < m) { if (mat[i][j + 1] == '#') { adj[g[i][j + 1]].push_back(g[i][j]); adj[g[i][j]].push_back(g[i][j + 1]); } } if (j - 1 >= 0) { if (mat[i][j - 1] == '#') { adj[g[i][j - 1]].push_back(g[i][j]); adj[g[i][j]].push_back(g[i][j - 1]); } } } } } if (k <= 2) { cout << "-1" << "\n"; return; } find_cutpoints(n); if (bs.count() > 0) { cout << '1' << "\n"; } else cout << '2' << "\n"; } signed main() { ios::sync_with_stdio(false); cin.tie(0); long long t = 1; for (long long i = 1; i < t + 1; i++) { solve(); } cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n"; return 0; }
7
CPP
#include <bits/stdc++.h> using namespace std; const int MAXN = 100010; const int MAXF = 10020; int n, k; struct Item { int r, x, f; bool operator<(const Item &rhs) const { return r > rhs.r; } } it[MAXN]; inline int lowbit(int num) { return num & -num; } int c[MAXF] = {0}; void add(int x, int v) { for (; x <= MAXF - 1; x += lowbit(x)) c[x] += v; } int query(int x) { int sum = 0; for (; x; x -= lowbit(x)) sum += c[x]; return sum; } void clear(int x) { for (; x <= MAXF - 1; x += lowbit(x)) c[x] = 0; } struct dat { int op, x, y, w; bool operator<(const dat &rhs) const { if (x == rhs.x) return op < rhs.op; return x < rhs.x; } } Q[MAXN * 5], t[MAXN * 5]; int cnt = 0; long long ans = 0; void cdq(int L, int R) { if (R - L <= 1) return; int M = (L + R) >> 1; cdq(L, M); cdq(M, R); int p = L, q = M, o = L; while (p < M && q < R) { if (Q[p] < Q[q]) { if (Q[p].op == 0) add(Q[p].y, 1); t[o++] = Q[p++]; } else { if (Q[q].op == 1) ans += query(Q[q].y) * Q[q].w; t[o++] = Q[q++]; } } while (p < M) t[o++] = Q[p++]; while (q < R) { if (Q[q].op == 1) ans += query(Q[q].y) * Q[q].w; t[o++] = Q[q++]; } for (int i = L; i < R; ++i) { if (Q[i].op == 0) clear(Q[i].y); Q[i] = t[i]; } } int main() { scanf("%d%d", &n, &k); for (int i = 0; i < n; ++i) scanf("%d%d%d", &it[i].x, &it[i].r, &it[i].f); sort(it, it + n); for (int i = 0; i < n; ++i) { Item &T = it[i]; int x1 = T.x - T.r, y1 = max(T.f - k, 1); int x2 = T.x + T.r, y2 = T.f + k; Q[cnt++] = (dat){1, x1 - 1, y1 - 1, 1}; Q[cnt++] = (dat){1, x1 - 1, y2, -1}; Q[cnt++] = (dat){1, x2, y1 - 1, -1}; Q[cnt++] = (dat){1, x2, y2, 1}; Q[cnt++] = (dat){0, T.x, T.f, 0}; } cdq(0, cnt); cout << ans << endl; return 0; }
11
CPP
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; string a, b; cin >> a >> b; int zeroComune = 0, zeroA = 0; for (int i = 0; i < n; i++) { if (a[i] == '0') zeroA++; if (a[i] == '0' && b[i] == '0') zeroComune++; } long long sum = 0; for (int i = 0; i < n; i++) { if (a[i] == '1') { if (b[i] == '0') { sum += 1LL * zeroA; } else { sum += 1LL * zeroComune; } } } cout << sum; return 0; }
8
CPP
l = input().split(" ") a = int(l[0]) b = int(l[1]) if b < a: t = a a = b b = t res = 1 for i in range(1,a+1): res = res * i print(res)
7
PYTHON3
for _ in range(int(input())): n, k = map(int, input().split()) a = list(map(int, input().split())) peak = list(0 for i in range(n)) for i in range(1, n-1): if a[i-1] < a[i] > a[i+1]: peak[i] = 1 t, l = 0, 1 cnt = 1 for i in range(1, k-1): if peak[i]: cnt+=1 t = cnt i = k while i<n: if peak[i-1]: cnt+=1 if peak[i-k+1]: cnt-=1 if cnt > t: t = cnt l = i-k+2 i+=1 print(t, l)
8
PYTHON3
n, a = input().split() #k = [input().split() for i in range(int(n))] k = input().split() value = int(k[int(a) - 1]) number_of_comp = 0 for i in k: if int(i) >= value and int(i) != 0: number_of_comp += 1 print(number_of_comp)
7
PYTHON3
# INPUT n = int(input()) W = list(map(int, input().split())) # PROCESS cost = 0 W_sorted = sorted(W) W_min = W_sorted[0] for i in range(n - 1): cycle_min = W_sorted[i] cost_cycle_in = 0 cnt_change = 0 index_cycle_min = W.index(cycle_min) while index_cycle_min != i: cycle_change = W_sorted[index_cycle_min] index_cycle_change = W.index(cycle_change) W[index_cycle_min], W[index_cycle_change] = cycle_change, cycle_min cost_cycle_in += cycle_min + cycle_change cnt_change += 1 index_cycle_min = index_cycle_change if cnt_change: cost_cycle_out = ( cost_cycle_in + (cycle_min + W_min) * 2 - (cycle_min - W_min) * cnt_change ) cost += min(cost_cycle_in, cost_cycle_out) # OUTPUT print(cost)
0
PYTHON3
#include <bits/stdc++.h> int main() { int x; scanf("%d", &x); printf("%d\n", 6 * x * (x - 1) + 1); return 0; }
8
CPP
import os import sys DEBUG = 'DEBUG' in os.environ def inp(): return sys.stdin.readline().rstrip() def Rint(): return int(inp()) def Rints(): return [int(e) for e in inp().split()] # def dprint(*value, sep=' ', end='\n'): # if DEBUG: # print(*value, sep=sep, end=end) ########################################## def main(): n = Rint() res = [None, None] starts, ends = [], [] for _ in range(n): seg = Rints() starts.append(seg[0]) ends.append(seg[1]) res[0] = max(starts) res[1] = min(ends) if res[1] < res[0]: return res[0] - res[1] else: return 0 for _ in range(Rint()): print(main())
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int n, k, cnt[1005]; int main() { scanf("%d%d", &n, &k); for (int i = 1; i <= n; i++) { int x; scanf("%d", &x); cnt[x]++; } int m = ceil(n / 2.0), ans = 0; for (int i = 1; i <= k; i++) { if (cnt[i] > 1) { ans += cnt[i] / 2 * 2; m -= cnt[i] / 2; } if (m <= 0) break; } printf("%d", ans + m); return 0; }
7
CPP
#include <bits/stdc++.h> using namespace std; int main() { int n, r, x, a[105] = {}; cin >> n; for (int i = 0; i < n; ++i) { cin >> r; while (r--) { cin >> x; ++a[x]; } } for (int i = 1; i <= 100; ++i) { if (a[i] == n) cout << i << ' '; } cout << endl; return 0; }
7
CPP
#include <bits/stdc++.h> using namespace std; const int INF = 1E9; const long double eps = 1e-7; int n, nn, vertexes, maxst; bool isst[31]; int id[31], needway[31]; vector<vector<int> > g; vector<int> emp; void addedge(int v, int w) { g[v].push_back(w); g[w].push_back(v); } void gen(int len) { vertexes = 2; int last = 0; g.push_back(emp); g.push_back(emp); for (int i = 0; i < len; i++) { g.push_back(emp); g.push_back(emp); g.push_back(emp); addedge(last, vertexes); addedge(last, vertexes + 1); addedge(vertexes, vertexes + 2); addedge(vertexes + 1, vertexes + 2); last = vertexes + 2; id[len - i - 1] = last; needway[len - i - 1] = (i + 1) * 2; vertexes += 3; } addedge(vertexes - 1, 1); for (int i = len - 1; i >= 0; i--) { if (isst[i]) { int iid = id[i]; last = 0; for (int j = 0; j < int(needway[i] - 1); j++) { g.push_back(emp); addedge(last, vertexes); last = vertexes; vertexes++; } addedge(last, iid); } } } int main() { cin >> n; nn = n; maxst = 0; for (int i = 0; i < 31; i++) { if (nn & 1) { maxst = i; isst[i] = 1; } nn >>= 1; } if (n == 1) { vertexes = 2; g.resize(2); g[0].push_back(1); g[1].push_back(0); } else { gen(maxst); } cout << vertexes << '\n'; string s; for (int i = 0; i < int(vertexes); i++) s += ' '; for (int i = 0; i < int(vertexes); i++) { for (int j = 0; j < int(vertexes); j++) s[j] = 'N'; for (int j = 0; j < int(g[i].size()); j++) s[g[i][j]] = 'Y'; cout << s << '\n'; } return 0; }
8
CPP
// KALAM # include <bits/stdc++.h> using namespace std; const int N = 100000 + 77 , Mod = 1000000007; int n , dp[N][2]; vector < int > a[N]; void dfs(int v , int prev = - 1){ dp[v][1] = dp[v][0] = 1; for(int u : a[v]){ if(u == prev) continue ; dfs(u , v); dp[v][0] = dp[v][0] * 1ll * dp[u][1] % Mod; dp[v][1] = (dp[v][1] * 1ll * (dp[u][0] + dp[u][1])) % Mod; } } int main(){ ios::sync_with_stdio(0);cin.tie(0); cin >> n; for(int v , u , i = 1;i < n;++ i){ cin >> v >> u; a[v].push_back(u); a[u].push_back(v); } dfs(1); cout << (dp[1][0] + dp[1][1]) % Mod; return 0; }
0
CPP
#include<iostream> using namespace std; int main() { long N; cin >> N; long A[200009]; for (int i = 1; i <= N; i++) cin >> A[i]; bool inball[200009] = {}; long res = 0; for (int i = N; i >= 1; i--) {//iの倍数について考える。 long link = 0; for (int j = 2; i * j <= N; j++) if (inball[i * j]) link++; if (link % 2 != A[i]) {inball[i] = true; res++;} } cout << res << endl; for (int i = 1; i <= N; i++) if (inball[i]) cout << i << " "; }
0
CPP
def factor(n): for i in range(2,n+1): if(n%i==0): return i t=int(input()) while(t>0): n,k=map(int,input().split()) if(n%2==0): print(n+2*k) else: print(n+factor(n)+2*(k-1)) t-=1
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); int _; cin >> _; while (_--) { int n; cin >> n; vector<int> v(n), vis(n, 0); for (int i = 0; i < n; i++) { cin >> v[i]; } while (n--) { for (int i = v.size() - 2; i >= 0; i--) { if (!vis[i] && v[i] > v[i + 1]) { swap(v[i], v[i + 1]); vis[i] = 1; } } } for (int i : v) { cout << i << ' '; } cout << endl; } return 0; }
8
CPP
for _ in range(int(input())): x, y = map(int, input().split()) flag = True if x < y: if (x == 2 and y != 3) or (x == 3) or (x == 1): flag = False print("YES" if flag else "NO")
8
PYTHON3
#include <bits/stdc++.h> bool Stay[2100000]; int A[2100000], Cards[2100000], Low[2100000], High[2100000], Pos[2100000], N, K; using namespace std; void updateLow(int x) { int n = x; while (n <= N) { Low[n] = max(Low[n], x); n += (n & -n); } } int queryLow(int x) { int ret = 0; while (x > 0) { ret = max(ret, Low[x]); x -= (x & -x); } return ret; } void updateHigh(int x) { int n = x; while (n > 0) { High[n] = min(High[n], x); n -= (n & -n); } } int queryHigh(int x) { int ret = N + 1; while (x <= N) { ret = min(ret, High[x]); x += (x & -x); } return ret; } void updateCards(int x, int v) { while (x <= N) { Cards[x] += v; x += (x & -x); } } int queryCards(int x) { int ret = 0; while (x > 0) { ret += Cards[x]; x -= (x & -x); } return ret; } int queryCards(int l, int r) { return queryCards(r) - queryCards(l - 1); } int main() { cin >> N >> K; for (int i = 0; i < 2100000; i++) High[i] = N + 1; for (int i = 1; i <= N; i++) { cin >> A[i]; Pos[A[i]] = i; updateCards(i, 1); } for (int i = 1; i <= K; i++) { int x; cin >> x; Stay[x] = true; } long long ans = 0; for (int i = 1; i <= N; i++) if (Stay[i]) { updateLow(Pos[i]); updateHigh(Pos[i]); } else { int l = queryLow(Pos[i]) + 1; int r = queryHigh(Pos[i]) - 1; ans += queryCards(l, r); updateCards(Pos[i], -1); } cout << ans; }
11
CPP
for t in range(int(input())): n0, n1, n2 = map(int, input().split()) s = "" if n0 == 0: s += '1'*(n2+1) s += '01' * (n1//2) if n1 % 2 == 1: s+='0' elif n2 == 0: s += '0' * (n0+1) s += '10' * (n1 // 2) if n1 % 2 == 1: s += '1' else: s += '1' * (n2 + 1) s += '0' * (n0 + 1) s += '10' * ((n1-1) // 2) if n1 % 2 == 0: s += '1' print(s)
12
PYTHON3
for _ in range(int(input())): n = int(input()) s1 = input() s2 = input() r,b = 0,0 for i in range(n): if int(s1[i])>int(s2[i]): r = r + 1 elif int(s1[i])<int(s2[i]): b = b + 1 if r>b: print('RED') elif b>r: print('BLUE') else: print('EQUAL')
7
PYTHON3
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx") using std::abs; using std::cerr; using std::cin; using std::cout; using std::map; using std::max; using std::min; using std::pair; using std::set; using std::string; using std::swap; using std::vector; using ll = long long; using uint = unsigned int; using pii = pair<int, int>; using pll = pair<ll, ll>; template <typename T> void _dbg(const char* _s, T _h) { cerr << _s << " = " << _h << "\n"; } template <typename T, typename... Ts> void _dbg(const char* _s, T _h, Ts... _t) { int _b = 0; while (((_b += *_s == '(') -= *_s == ')') != 0 || *_s != ',') cerr << *_s++; cerr << " = " << _h << ","; _dbg(_s + 1, _t...); } struct init { init() { cin.tie(0); std::iostream::sync_with_stdio(0); cout << std::fixed << std::setprecision(10); cerr << std::fixed << std::setprecision(5); using namespace std::chrono; srand(duration_cast<nanoseconds>( high_resolution_clock::now().time_since_epoch()) .count()); } ~init() {} } init; const int MAXN = 1e5 + 15; const ll INF = 1e16; ll a[MAXN], b[MAXN]; int main() { ll n, m, ca, cb, v; cin >> n >> m >> ca >> cb >> v; a[0] = b[0] = -INF; for (int i = 1; i <= ca; ++i) cin >> a[i]; for (int i = 1; i <= cb; ++i) cin >> b[i]; a[ca + 1] = INF; b[cb + 1] = INF; ca += 2; cb += 2; int q; cin >> q; while (q--) { int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2; if (x1 == x2) { cout << abs(y1 - y2) << '\n'; continue; } ll ans = INF * 10; { vector<ll> l = {*std::lower_bound(a, a + ca, y1), *std::prev(std::lower_bound(a, a + ca, y1)), *std::lower_bound(a, a + ca, y2), *std::prev(std::lower_bound(a, a + ca, y2))}; for (ll y : l) { ll pot = abs(y1 - y) + abs(y2 - y) + abs(x2 - x1); if (ans > pot) { ans = pot; } } } { vector<ll> l = {*std::lower_bound(b, b + cb, y1), *std::prev(std::lower_bound(b, b + cb, y1)), *std::lower_bound(b, b + cb, y2), *std::prev(std::lower_bound(b, b + cb, y2))}; for (ll y : l) { ll pot = abs(y1 - y) + abs(y2 - y) + (abs(x2 - x1) + v - 1) / v; if (ans > pot) { ans = pot; } } } cout << ans << '\n'; } return 0; }
7
CPP
#include <bits/stdc++.h> using namespace std; const int N = (int)5e3 + 10; int n, m, edge[N]; vector<pair<int, int> > adj[N]; pair<int, pair<int, int> > query[N]; vector<int> path[N]; bool visited[N]; bool find_path(int u, int v, int id) { if (u == v) return true; visited[u] = true; for (auto it : adj[u]) if (!visited[it.second]) { path[id].push_back(it.first); if (find_path(it.second, v, id)) return true; path[id].pop_back(); } visited[u] = false; return false; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n; for (int i = 1; i < n; i++) { int u, v; cin >> u >> v; adj[u].push_back(pair<int, int>(i, v)); adj[v].push_back(pair<int, int>(i, u)); } cin >> m; for (int i = 1; i <= m; i++) { int u, v, w; cin >> u >> v >> w; query[i] = pair<int, pair<int, int> >(w, pair<int, int>(u, v)); memset(visited, false, sizeof(visited)); find_path(u, v, i); for (auto it : path[i]) { edge[it] = max(edge[it], w); } } for (int i = 1; i <= m; i++) { int temp = INT_MAX; for (auto it : path[i]) temp = min(temp, edge[it]); if (temp != query[i].first) { cout << -1; return 0; } } for (int i = 1; i < n; i++) { if (edge[i] == 0) edge[i] = 911218; cout << edge[i] << ' '; } return 0; }
12
CPP
t=int(input()) for you in range(t): n=int(input()) s=input() if(n%2==0): poss=0 for i in range(1,n,2): if(int(s[i])%2==0): poss=1 break if(poss): print(2) else: print(1) else: poss=0 for i in range(0,n,2): if(int(s[i])%2==1): poss=1 break if(poss): print(1) else: print(2)
7
PYTHON3
#include <bits/stdc++.h> const double eps = 1e-10; const float epsf = 1e-6; using namespace std; inline long long int __gcd(long long int a, long long int b) { if (a == 0 || b == 0) { return max(a, b); } long long int tempa, tempb; while (1) { if (a % b == 0) return b; else { tempa = a; tempb = b; a = tempb; b = tempa % tempb; } } } inline int compfloat(float& x, float& y) { if (fabs(x - y) < epsf) return 0; else if (x - y > 0) return 1; return -1; } inline int compdouble(double x, double y) { if (fabs(x - y) < eps) return 0; else if (x - y > 0) return 1; else return -1; } bool prime(long long int k) { for (long long int i = 2; i * i <= k; i++) if (k % i == 0) { return false; } return true; } void pdash(int n = 1) { for (int i = 0; i < n; i++) { for (int j = 0; j < 30; j++) { cout << "-"; } cout << "\n"; } } long long int power(long long int x, long long int y) { long long int result = 1; while (y > 0) { if (y & 1) { result = (result * x); } y = y >> 1; x = (x * x); } return result; } long long int power(long long int x, long long int y, long long int z) { long long int result = 1; x = x % z; while (y > 0) { if (y & 1) { result = (result * x) % z; } y = y >> 1; x = (x * x) % z; } return result; } long long int modInverse(long long int n, long long int p) { return power(n, p - 2, p); } long long int nCrF(long long int n, long long int r, long long int p) { if (r == 0) return 1; long long int f[n + 1]; f[0] = 1; for (long long int i = 1; i <= n; i++) f[i] = f[i - 1] * i % p; return (f[n] * modInverse(f[r], p) % p * modInverse(f[n - r], p) % p) % p; } void cordinate_compression(vector<int>& v) { vector<int> p = v; sort(p.begin(), p.end()); p.erase(unique(p.begin(), p.end()), p.end()); for (int i = 0; i < (int)((v).size()); i++) v[i] = (int)(lower_bound(p.begin(), p.end(), v[i]) - p.begin()); } void solve() { int n; cin >> n; vector<int> vec[n + 1]; for (int i = 0; i < n; i++) { int a; cin >> a; vec[a].push_back(i + 1); } int k = 0; vector<int> ans; while (1) { if (k < 0) break; if (vec[k].empty()) k -= 3; else { ans.push_back(vec[k].back()); vec[k].pop_back(); k++; } } if (ans.size() != n) { cout << "Impossible\n"; return; } cout << "Possible\n"; for (auto& j : ans) cout << j << " "; cout << "\n"; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; while (t--) { solve(); } }
10
CPP
#include <bits/stdc++.h> using namespace std; long long k, l, g = 0, h = 0; int a, b, p[3][3], q[3][3], t, u, v, c; vector<pair<int, int> > s; bool con; int gg(int a, int b) { if (a == b + 1 || a == b - 2) return 1; return 0; } void sim(int x, int t, int u) { while (x > 0) { g += gg(t, u); h += gg(u, t); v = t; t = p[t][u]; u = q[v][u]; x--; } } int main() { ios_base::sync_with_stdio(false); cin >> k >> a >> b; a--, b--; for (int i = 0; i < (3); i++) for (int j = 0; j < (3); j++) cin >> p[i][j]; for (int i = 0; i < (3); i++) for (int j = 0; j < (3); j++) cin >> q[i][j]; for (int i = 0; i < (3); i++) for (int j = 0; j < (3); j++) q[i][j]--, p[i][j]--; s.push_back({a, b}); t = p[a][b], u = q[a][b]; while (true) { con = false; for (int i = 0; i < (s.size()); i++) { if (s[i].first == t && s[i].second == u) con = true; } if (con) break; else { s.push_back({t, u}); v = t; t = p[t][u]; u = q[v][u]; } con = false; } for (int i = 0; i < (s.size()); i++) { if (s[i].first == t && s[i].second == u) c = s.size() - i; } if (k < 10000) { sim(k, a, b); } else { l = (k - s.size() + c) / c; sim(c, t, u); g *= l; h *= l; sim(s.size() - c, a, b); sim((k - s.size() + c) % c, t, u); } cout << g << " " << h << endl; }
9
CPP
#include <stdio.h> int main(void) { int a[101]; int n; int i; for (i = 0; i < 101; i++){ a[i] = 0; } while (scanf("%d", &n) != EOF){ a[n]++; if (a[0] < a[n]){ a[0] = a[n]; } } for (i = 1; i <= 100; i++){ if (a[i] == a[0]){ printf("%d\n", i); } } return (0); }
0
CPP
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 50; vector<int> G[N]; int pre[N], nxt[N]; vector<int> ans; int tag[N], n, m; void BFS(int start) { queue<int> q; q.push(start); int cnt = 0; while (q.size()) { int x = q.front(); q.pop(); cnt++; for (auto y : G[x]) tag[y] = x; for (int i = nxt[0]; i <= n; i = nxt[i]) { if (i != start && tag[i] != x) q.push(i), nxt[pre[i]] = nxt[i], pre[nxt[i]] = pre[i]; } } ans.push_back(cnt); } int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n >> m; for (int i = 0, u, v; i < m; i++) { cin >> u >> v; G[u].push_back(v), G[v].push_back(u); } for (int i = 1; i <= n; i++) pre[i] = i - 1, nxt[i] = i + 1; nxt[0] = 1, pre[n + 1] = n; for (int i = nxt[0]; i <= n;) { BFS(i); int nxt_p = nxt[i]; nxt[pre[i]] = nxt[i], pre[nxt[i]] = pre[i]; i = nxt_p; } cout << ans.size() - 1 << endl; return 0; }
10
CPP
#include<bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; int n,ans[maxn],vis[maxn]; vector<int>g[maxn],v[2]; void dfs(int u = 1, int fa = 0, int t = 0) { v[t].push_back(u); for(int i = 0; i < (int) g[u].size(); ++i) { int v = g[u][i]; if(v==fa) continue; dfs(v,u,1-t); } } int main() { int i,u,t; scanf("%d",&n); for(i=1;i<n;++i) { scanf("%d %d",&u,&t); g[u].push_back(t); g[t].push_back(u); } dfs(); if(v[0].size()>v[1].size()) swap(v[0],v[1]); int sum = n/3; if(v[0].size() <= sum) { for(i=1;i<=n;++i) { if(!v[0].size()) break; if(i % 3 == 0) { t = v[0].back(); ans[t] = i; v[0].pop_back(); vis[i]++; } } } else { for(i=1;i<=n;++i) { if(!v[0].size()) break; if(i % 3 == 1) { t = v[0].back(); ans[t] = i; v[0].pop_back(); vis[i]++; } } for(i=1;i<=n;++i) { if(!v[0].size()) break; if(i%3==0) { t = v[0].back(); ans[t] = i; v[0].pop_back(); vis[i]++; } } } for(i=1;i<=n;++i) { if(!v[1].size()) break; if(!vis[i]) { t = v[1].back(); ans[t] = i; v[1].pop_back(); vis[i]++; } } for(i=1;i<=n;++i) printf("%d ",ans[i]); }
0
CPP
cases = int(input()) for i in range(cases): line1 = input().split(' ') n = int(line1[0]) m = int(line1[1]) price1 = int(line1[2]) #shorttile price price2 = int(line1[3]) #longtile price if (price1*2<price2): neveruseprice2 = True else: neveruseprice2 = False total = 0 for j in range(n): row = list(input()) if (neveruseprice2): white = row.count('.') total += white * price1 else: for k in range(len(row)): tile = row[k] if (tile == '*'): continue elif(k!=len(row)-1): #tile must be white tile_next = row[k+1] if (tile == tile_next): row[k] = row[k+1] = '*' total += price2 elif (tile != tile_next): total += price1 row[k] = '*' elif (k == len(row)-1): total += price1 print (total)
8
PYTHON3
#int(x) for x in input().split() #map(int,input().split()) for _ in range(int(input())): n,m=map(int,input().split()) l=[] for i in range(n): l.append([int(x) for x in input().split()]) r=set() co=set() for i in range(n): for j in range(m): if l[i][j]==1: r.add(i) co.add(j) f=0 c=0 while True: c=f for i in range(n): for j in range(m): if l[i][j]==0: if i in r: break if j in co: continue l[i][j]=1 f+=1 r.add(i) co.add(j) if c==f: break if f%2==0: print('Vivek') else: print('Ashish')
7
PYTHON3
#include <bits/stdc++.h> using namespace std; constexpr int inf32 = 0x3f3f3f3f; constexpr long long inf64 = 0x3f3f3f3f3f3f3f3f; constexpr int mod = 998244353; constexpr int G = 3; struct mint { int first; mint(int first = 0) : first(first) {} friend mint operator+(const mint a, const mint &b) { int first = a.first + b.first; return mint(first >= mod ? first - mod : first); } friend mint operator-(const mint a, const mint &b) { int first = a.first - b.first; return mint(first < 0 ? first + mod : first); } friend mint operator*(const mint a, const mint &b) { return mint(1ll * a.first * b.first % mod); } }; int mypow(int a, int first = mod - 2, int res = 1) { for (; first; first >>= 1, a = (mint(a) * a).first) if (first & 1) res = (mint(res) * a).first; return res; } vector<int> rev, w = {0, 1}; void dft(vector<int> &a) { const int n = (int)((a).size()); if ((int)((rev).size()) != n) { rev.resize(n); for (int i = 0; i < (n); ++i) rev[i] = (rev[i / 2] / 2) | ((i & 1) * n / 2); } if ((int)((w).size()) < n) { int szw = (int)((w).size()); for (w.resize(n); szw < n; szw *= 2) { const int wn = mypow(G, (mod - 1) / (szw * 2)); for (int i = szw / 2; i < szw; ++i) w[2 * i] = w[i], w[2 * i + 1] = (mint(w[i]) * wn).first; } } for (int i = 0; i < (n); ++i) if (i < rev[i]) swap(a[i], a[rev[i]]); for (int mid = 1, first; mid < n; mid *= 2) for (int i = 0; i < n; i += mid * 2) for (int j = 0; j < (mid); ++j) { int u = a[i | j], v = 1ll * w[mid | j] * a[mid | i | j] % mod; a[i | j] = (mint(u) + v).first; a[mid | i | j] = (mint(u) - v).first; } } void idft(vector<int> &a) { const int n = (int)((a).size()), in = n == 1 ? 1 : mod - mod / n; reverse(a.begin() + 1, a.end()), dft(a); for (int i = 0; i < (n); ++i) a[i] = (mint(a[i]) * in).first; } struct poly { vector<int> a; poly() {} poly(int first) { if (first) a = {first}; } poly(const vector<int> &a0) : a(a0) { while ((int)((a).size()) && !a.back()) a.pop_back(); } int size() const { return (int)((a).size()); } int operator[](int i) const { return (i < 0 || i >= size()) ? 0 : a[i]; } poly mulxk(int k) const { vector<int> b = a; b.insert(b.begin(), k, 0); return poly(b); } poly divxk(int k) const { return size() <= k ? poly() : poly(vector<int>(a.begin() + k, a.end())); } poly modxk(int k) const { return poly(vector<int>(a.begin(), a.begin() + min(k, size()))); } poly rev() const { vector<int> b = a; reverse((b).begin(), (b).end()); return poly(b); } friend poly operator+(const poly a, const poly &b) { vector<int> res(max((int)((a).size()), (int)((b).size()))); for (int i = 0; i < ((int)((res).size())); ++i) res[i] = (mint(a[i]) + b[i]).first; return poly(res); } friend poly operator-(const poly a, const poly &b) { vector<int> res(max((int)((a).size()), (int)((b).size()))); for (int i = 0; i < ((int)((res).size())); ++i) res[i] = (mint(a[i]) - b[i]).first; return poly(res); } friend poly operator*(poly a, poly b) { int n = 1, mn = (int)((a).size()) + (int)((b).size()) - 1; while (n < mn) n *= 2; a.a.resize(n), b.a.resize(n), dft(a.a), dft(b.a); for (int i = 0; i < (n); ++i) a.a[i] = (mint(a[i]) * b[i]).first; return idft(a.a), poly(a.a); } poly &operator+=(poly b) { return (*this) = (*this) + b; } poly &operator-=(poly b) { return (*this) = (*this) - b; } poly &operator*=(poly b) { return (*this) = (*this) * b; } poly deriv() const { if (!(int)((a).size())) return poly(); vector<int> res(size() - 1); for (int i = 0; i < (size() - 1); ++i) res[i] = (mint(i + 1) * a[i + 1]).first; return poly(res); } poly integr() const { if (!(int)((a).size())) return poly(); vector<int> res(size() + 1); for (int i = 0; i < (size()); ++i) res[i + 1] = (mint(a[i]) * mypow(i + 1)).first; return poly(res); } poly inv(int m) const { poly first(mypow(a[0])); for (int k = 1; k < m;) k *= 2, first = (first * (2 - modxk(k) * first)).modxk(k); return first.modxk(m); } friend poly operator/(const poly a, const poly &b) { int n = (int)((a).size()), m = (int)((b).size()); return (a.rev() * b.rev().inv(n - m + 1)).modxk(n - m + 1).rev(); } poly &operator/=(poly b) { return (*this) = (*this) / b; } poly log(int m) const { return (deriv() * inv(m)).integr().modxk(m); } poly exp(int m) const { poly first(1); for (int k = 1; k < m;) k *= 2, first = (first * (1 - first.log(k) + modxk(k))).modxk(k); return first.modxk(m); } poly sqrt(int m) const { poly first(1); for (int k = 1; k < m;) k *= 2, first = (first + (modxk(k) * first.inv(k)).modxk(k)) * ((mod + 1) / 2); return first.modxk(m); } poly pow(int k, int m) const { return (log(m) * k).exp(m); } }; int main() { ios::sync_with_stdio(false); cin.tie(0), cout.tie(0); int n, a, b; cin >> n >> a >> b; if (a + b - 1 > n) return !(cout << "0\n"); vector<int> fac(n), inv(n + 1), ifac(n); fac[0] = ifac[0] = inv[1] = 1; for (int i = 0; i < (n); ++i) if (i >= 2) inv[i] = (mint(inv[mod % i]) * (mod - mod / i)).first; for (int i = 0; i < (n); ++i) if (i >= 1) fac[i] = (mint(fac[i - 1]) * i).first, ifac[i] = (mint(ifac[i - 1]) * inv[i]).first; auto stir1 = [&](int n, int k) { if (n < 0 || k < 0 || k > n) return 0; return (mint(((poly(inv).divxk(1)).pow(k, n + 1))[n - k]) * fac[n] * ifac[k]) .first; }; auto cho = [&](int n, int m) { if (m > n || n < 0 || m < 0) return 0; return (mint(fac[n]) * ifac[m] * ifac[n - m]).first; }; cout << (mint(stir1(n - 1, a + b - 2)) * cho(a + b - 2, a - 1)).first << '\n'; return 0; }
13
CPP
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main(){ ll r,g,b,n; cin >> r>>g>>b>>n; ll ans=0; for (ll i=0;i<=n/r;i++) { for (ll j=0;j<=(n-r*i)/g;j++) { if ((n-r*i-g*j)%b==0) { ans++; } } } cout<<ans<<endl; }
0
CPP
#include <bits/stdc++.h> using namespace std; int main() { int t, m, n; cin >> t; while (t--) { int changes = 0; cin >> m >> n; vector<vector<char> > paths; for (int i = 0; i < m; i++) { char temp; vector<char> row; for (int j = 0; j < n; j++) { cin >> temp; row.push_back(temp); } paths.push_back(row); } for (int j = 0; j < n; j++) { if (paths[m - 1][j] == 'D') changes++; } for (int i = 0; i < m; i++) { if (paths[i][n - 1] == 'R') changes++; } cout << changes << "\n"; } return 0; }
8
CPP
n = input() ct = 0 while len(n) > 1: n = str(sum(list(map(int, n)))) ct += 1 print(ct)
8
PYTHON3
A, B, C = map(str,input().split()) out = ("YES" if A[-1]==B[0] and B[-1]==C[0] else "NO") print(out)
0
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { long long n, k, minimo, massimo; cin >> n >> k; if (k == 0) { cout << 0 << " " << 0; return 0; } if (3 * k > n) massimo = n - k; else massimo = 2 * k; if (n > k) minimo = 1; else minimo = 0; cout << minimo << " " << massimo; return 0; }
8
CPP
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; int a[N], b[N], c[N]; int main() { ios::sync_with_stdio(false); int t; scanf("%d", &t); while (t--) { int n; vector<pair<int, int> > z; scanf("%d", &n); memset(b, 0, sizeof(b)); memset(c, 0, sizeof(c)); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); int l = n + 1, r = 0; for (int i = 1; i <= n; i++) { if (b[a[i]]) break; l = min(l, a[i]); r = max(r, a[i]); if (l == 1 && r == i) c[i] = 1; b[a[i]] = 1; } l = n + 1; r = 0; memset(b, 0, sizeof(b)); for (int i = n; i >= 1; i--) { if (b[a[i]]) break; l = min(l, a[i]); r = max(r, a[i]); if (l == 1 && r == n - i + 1 && c[i - 1]) z.push_back({i - 1, n - i + 1}); b[a[i]] = 1; } printf("%d\n", z.size()); for (int i = 0; i < z.size(); i++) printf("%d %d\n", z[i].first, z[i].second); } return 0; }
8
CPP
s=input() cap='ABCDEFGHIJKLMNOPQRSTUVWXYZ' sml='abcdefghijklmnopqrstuvwxyz' s1=0 c1=0 for i in s: if i in cap: c1+=1 elif i in sml: s1+=1 if(c1>s1): print(s.upper()) else: print(s.lower())
7
PYTHON3
import sys import math import bisect import itertools import random import re def main(): n = int(input()) if n == 0: print(1) else: n = (n % 4) + 4 r = (8 ** n) % 10 print(r) if __name__ == "__main__": main()
7
PYTHON3
#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 main() { char _1[56][56], _2[56][56]; long long na, ma, nb, mb, x, y; scanf("%I64d%I64d", &na, &ma); for (int i = 0; i < na; i++) scanf("%s", _1[i]); scanf("%lld %lld", &nb, &mb); for (int i = 0; i < nb; i++) scanf("%s", _2[i]); long long sum = -0x7FFFFFFF, ans1, ans2; for (long long i = -50; i < 60; i++) { for (long long j = -50; j < 60; j++) { long long temp = 0; for (int l = 0; l < na; l++) for (int k = 0; k < ma; k++) { if (l + i >= 0 && l + i < nb && k + j >= 0 && k + j < mb) temp += ((_1[l][k] - '0') * (_2[l + i][k + j] - '0')); } if (temp > sum) { sum = temp; ans1 = i; ans2 = j; } } } cout << ans1 << " " << ans2 << endl; return 0; }
8
CPP
#include<iostream> #include<algorithm> #include<vector> #include<queue> #include<functional> #include<string.h> #include<bitset> #include<cstdio> #include<set> using namespace std; int main(){ int n, k, ruiseki[11][2001] = {}, dp[11][2001] ={}; int a, b; vector<int> books[11]; cin >> n >> k; for(int i = 0; i < n;i++){ scanf("%d%d", &a, &b); books[b].push_back(-a); } for(int i = 1; i < 11; i++){ sort(books[i].begin(), books[i].end()); for(int j = 0; j < books[i].size(); j++){ ruiseki[i][j + 1] = -books[i][j] + ruiseki[i][j] + j * 2; } } for(int i = 1; i < 11; i++){ for(int j = 0; j <= k; j++){ for(int l = 0; l + j <= k; l++){ dp[i][l + j] = max(max(dp[i][l + j], dp[i - 1][l + j]), max(dp[i - 1][j] + ruiseki[i][l], dp[i - 1][l] + ruiseki[i][j])); } } } cout << dp[10][k] << endl; }
0
CPP
#include <bits/stdc++.h> #define ll long long using namespace std; bool check(string s1, string s2) { int l1 = 0, l2 = 0, diff = 0; while (l1 < s1.size() || l2 < s2.size()) { if (l1 == s1.size() || l2 == s2.size()) return false; if (s1[l1] != s2[l2]) return false; if (s1[l1] == '"') { l1++; string t1 = ""; while (s1[l1] != '"') t1 += s1[l1++]; l2++; string t2 = ""; while (s2[l2] != '"') t2 += s2[l2++]; l1++; l2++; if (t1 != t2) diff++; } else { l1++; l2++; } } return diff <= 1; } int main() { string s1, s2; while (1) { cin >> s1; if (s1 == ".") break; cin >> s2; if (s1 == s2) { cout << "IDENTICAL" << endl; } else { cout << (check(s1, s2) ? "CLOSE" : "DIFFERENT") << endl; } } return 0; }
0
CPP
#include <bits/stdc++.h> using namespace std; struct Bipartite_Matching { vector< vector< int > > graph; vector< int > dist, match, used; vector< bool > vv; Bipartite_Matching(int n, int m) { graph.resize(n); match.assign(m, -1); used.assign(n, -1); } void add_edge(int u, int v) { graph[u].push_back(v); } void bfs() { dist.assign(graph.size(), -1); queue< int > que; for(int i = 0; i < graph.size(); i++) { if(used[i] == -1) { que.emplace(i); dist[i] = 0; } } while(!que.empty()) { int a = que.front(); que.pop(); for(auto &b : graph[a]) { int c = match[b]; if(c >= 0 && dist[c] == -1) { dist[c] = dist[a] + 1; que.emplace(c); } } } } bool dfs(int a) { vv[a] = true; for(auto &b : graph[a]) { int c = match[b]; if(c < 0 || (!vv[c] && dist[c] == dist[a] + 1 && dfs(c))) { match[b] = a; used[a] = b; return (true); } } return (false); } int bipartite_matching() { int ret = 0; while(true) { bfs(); vv.assign(graph.size(), false); int flow = 0; for(int i = 0; i < graph.size(); i++) { if(used[i] == -1 && dfs(i)) ++flow; } if(flow == 0) return (ret); ret += flow; } } }; vector< int > h[200000]; int p[200000]; bool used[200000]; int dfs(int idx, int par) { if(used[idx]) return 0; used[idx] = true; int times = 1; p[idx] = par; for(auto &to : h[idx]) times += dfs(to, idx); return times; } int main() { int N; cin >> N; Bipartite_Matching flow(N, N); for(int i = 0; i < N - 1; i++) { int k; cin >> k; for(int j = 0; j < k; j++) { int x; cin >> x; --x; flow.add_edge(i, x); } } if(flow.bipartite_matching() < N - 1) { cout << -1 << endl; return 0; } for(int i = 0; i < N; i++) { if(flow.match[i] == -1) { flow.match[i] = N - 1; flow.used[N - 1] = i; } } for(int i = 0; i < N - 1; i++) { for(auto &to : flow.graph[i]) { if(flow.match[to] != i) { h[flow.match[to]].push_back(i); } } } if(dfs(N - 1, -1) < N) { cout << -1 << endl; return 0; } for(int i = 0; i < N - 1; i++) { cout << flow.used[i] + 1 << " " << flow.used[p[i]] + 1 << endl; } }
0
CPP
#include <bits/stdc++.h> using namespace std; const int N = 1e3 + 7, M = 20; vector<int> v[N]; int fp[N], ch[N][2]; int n, q[N], q1[N], dis[N], q2[N], fa[N], fl[N], ft[N], fz[N], fq[N], fw[N], fc[N], fh[N], opt[M][N]; char s[N]; vector<int> vt[N]; inline void query() { int ret = 0; for (int i = 1; i <= n; i++) if (q[i] != 0) ret = 1; if (!ret) { memset(fl, 0, sizeof(fl)); return; } putchar('?'), cout << " "; for (int i = 1; i <= n; i++) printf("%d ", min(q[i], n - 1)); cout << endl; scanf("%s", s + 1); for (int i = 1; i <= n; i++) fl[i] = s[i] - '0'; } inline void solve(int t) { if (t < 0) return; memset(q, 0, sizeof(q)); q[1] = (1 << t); query(); for (int i = 1; i <= n; i++) fw[i] = fl[i]; memset(q, 0, sizeof(q)); for (int i = 1; i <= n; i++) if ((i - 1) % (1 << (t + 2)) == 0) { for (int x = 0; x < v[i].size(); x++) q[v[i][x]] = (1 << t); } query(); for (int i = 1; i <= n; i++) ft[i] = fl[i]; for (int i = 1; i <= n; i++) if (q[i]) q[i]--; for (int i = 1; i <= n; i++) fh[i] = ft[i]; query(); for (int i = 1; i <= n; i++) fz[i] = (ft[i] != fl[i]); memset(q, 0, sizeof(q)); for (int i = 1; i <= n; i++) if ((i - 1) % (1 << (t + 2)) == (1 << (t + 1))) { for (int x = 0; x < v[i].size(); x++) q[v[i][x]] = (1 << t); } query(); for (int i = 1; i <= n; i++) ft[i] = fl[i]; int opq = 0; for (int i = 1; i <= n; i++) if (ft[i] == 1) opq++; for (int i = 1; i <= n; i++) if (q[i]) q[i]--; query(); for (int i = 1; i <= n; i++) if (fq[i] % 2 == 0 && fz[i] && !fc[i]) { fc[i] = fq[i] * (1 << (t + 1)) + (1 << t) + 1; v[fc[i]].push_back(i); } else if (fq[i] % 2 == 1 && (fl[i] != ft[i]) && !fc[i]) { fc[i] = fq[i] * (1 << (t + 1)) + (1 << t) + 1; v[fc[i]].push_back(i); } int opt = 0; for (int i = 0; i <= n; i += 2) { ch[i][0] = opt++; ch[i][1] = opt++; ch[i + 1][1] = opt++; ch[i + 1][0] = opt++; } for (int i = 1; i <= n; i++) if (fh[i]) fq[i] = ch[fq[i]][0]; else if (ft[i]) fq[i] = ch[fq[i]][1]; else if (fq[i] % 2 == 0) fq[i] = ch[fq[i]][1]; else fq[i] = ch[fq[i]][0]; for (int i = 1; i <= n; i++) if (!fw[i]) fq[i] = max(fq[i], 1); solve(t - 1); } int main() { scanf("%d", &n); int t = 0; fc[1] = 1, v[1].push_back(1); while ((1 << (t + 1)) <= n - 1) t++; solve(t); for (int i = 0; i <= 2; i++) { memset(q1, 0, sizeof(q1)); memset(q2, 0, sizeof(q2)); for (int x = 1; x <= n; x++) if (fc[x] % 3 == i % 3) q1[++q1[0]] = x; for (int x = 1; x <= n; x++) if (fc[x] % 3 == (i + 1) % 3) q2[++q2[0]] = x; for (int z = 0; z <= t; z++) { memset(q, 0, sizeof(q)); for (int x = 1; x <= q1[0]; x++) if (x & (1 << z)) q[q1[x]] = 1; query(); for (int x = 1; x <= n; x++) opt[z][x] = fl[x]; } for (int x = 1; x <= q2[0]; x++) { int c = 0; for (int z = 0; z <= t; z++) if (opt[z][q2[x]]) c |= (1 << z); fa[q2[x]] = q1[c]; } } cout << "!" << endl; for (int i = 2; i <= n; i++) printf("%d %d\n", i, fa[i]); cout << endl; }
11
CPP
__file__ = __file__.startswith('/home/a_farazei') def input_(): global __file__ if not __file__: return input() if not hasattr(__file__, 'readline'): __file__ = open('input.txt', 'r') return __file__.readline() a = list(map(int, input_().split())) def f(t, f, tn): s = [[f] * 50 for _ in range(10)] i = 1 while tn > 0: for j in range(1, 50, 2): s[i][j] = t tn -= 1 if tn == 0: break i += 2 return '\n'.join(''.join(x) for x in s) + '\n' res = '' res += f('A', 'B', a[0] - 1) res += f('B', 'A', a[1] - 1) res += f('C', 'D', a[2] - 1) res += f('D', 'C', a[3] - 1) print('40 50') print(res)
9
PYTHON3
from sys import stdin def gcd(a,b): while b!=0: t=int(a) a=int(b) b=t%a return int(a) def lcm(a, b): return int((a*b)/gcd(a, b)) n,m,q=map(int,stdin.readline().strip().split()) b=lcm(n,m)//n a=lcm(n,m)//m for i in range(q): x,y,x1,y1=map(int,stdin.readline().strip().split()) if (x==2): w=y//b if (y%b!=0): w+=1 else: w=y//a if (y%a!=0): w+=1 if (x1==2): w1=y1//b if (y1%b!=0): w1+=1 else: w1=y1//a if (y1%a!=0): w1+=1 if w==w1: print("YES") else: print("NO")
9
PYTHON3
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const double EPS = 1e-9; const int INF = 1e9; long long addMod(long long a, long long b) { if (a + b >= MOD) return a + b - MOD; return a + b; } long long mulMod(long long a, long long b) { return (a * b) % MOD; } long long fast(long long a, long long b) { if (b == 0) return 1; long long tmp = fast(a, b / 2); tmp = mulMod(tmp, tmp); if (b & 1) tmp = mulMod(tmp, a); return tmp; } int n; string str; int cnt1[3], cnt2[3]; void solve() { for (int i = 0; i <= (int)n - 1; i += 1) { if (str[i] == '(') { if (cnt1[0] >= cnt2[0]) { cnt1[0]--; cout << "1"; } else { cnt2[0]--; cout << "0"; } } else { if (cnt1[1] >= cnt2[1]) { cnt1[1]--; cout << "1"; } else { cnt2[1]--; cout << "0"; } } } cout << endl; } int main() { ios_base ::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> str; cnt1[0] = cnt1[1] = (n / 2 - n % 2) / 2; cnt2[0] = cnt2[1] = (n - cnt1[0] * 2) / 2; solve(); return 0; }
10
CPP
#include <bits/stdc++.h> using namespace std; const int N = 1e2 + 10; int sum, mx, cnt[N]; int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); for (int i = 0; i < 5; i++) { int a; cin >> a; cnt[a]++; sum += a; } for (int i = 0; i < N; i++) mx = max(mx, min(3, cnt[i]) * i * (cnt[i] > 1)); cout << sum - mx; }
7
CPP
#include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <iostream> #include <sstream> #include <vector> #include <list> #include <deque> #include <queue> #include <stack> #include <set> #include <map> #include <utility> #include <algorithm> #include <limits> #include <iomanip> #include <bitset> #define INF 1000000000 #define Inf 1000000000000000000 #define mp make_pair #define pb push_back #define EPS 1e-9 using namespace std; typedef long long ll; typedef pair<int,int> ii; typedef vector<ii> vii; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<vii> vvii; const ll MOD = 1000000007; int t, n, k; ll dp[1010][1010][2]; ll solve(int pos, int dk, int dir) { // cout << pos << " " << dk << " " << dir << endl; if (dp[pos][dk][dir] != -1) return dp[pos][dk][dir]; if (dk == 1) return 1; if ((pos == 0 && dir == 1) || (pos == n && dir == 0)) return 1; int nextPos = pos + 1; if (dir == 1) nextPos = pos - 1; // int nn = n - pos; // if (dir == 1) nn = pos; dp[pos][dk][dir] = (solve(nextPos, dk, dir) + solve(pos, dk - 1, 1 - dir)) % MOD; // cout << pos << " " << dk << " " << dir << ": " << dp[pos][dk][dir] << endl; return dp[pos][dk][dir]; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(10); cin >> t; while(t--) { cin >> n >> k; memset(dp, -1, sizeof(dp)); cout << solve(0, k, 0) << endl; } return 0; }
9
CPP
#include <bits/stdc++.h> using namespace std; const int N = 205; const int M = 505; const int mod = 1000000007; int n, m, l1, l2, len, tot, lm, x, ans; int a[N], b[N], dp[N][N][M], ch[N][22], w[N], fail[N]; bool vis[N][N][M]; queue<int> q; void build_fail() { int i, k; for (i = 0; i < m; i++) if (ch[0][i]) q.push(ch[0][i]); while (!q.empty()) { k = q.front(); q.pop(); w[k] += w[fail[k]]; for (i = 0; i < m; i++) if (ch[k][i]) q.push(ch[k][i]), fail[ch[k][i]] = ch[fail[k]][i]; else ch[k][i] = ch[fail[k]][i]; } } int dfs(int l, int p, bool b, int k, int s) { if (!l) return 1; if (!b && vis[l][k][s] && p >= 0) return dp[l][k][s]; int i, r = m - 1, t, sum = 0, u; if (b) r = a[l]; for (i = 0; i <= r; i++) { if (i == 0 && p == -1) t = p, u = 0; else t = i, u = ch[k][i]; if (s + w[u] <= lm) (sum += dfs(l - 1, t, b && (i == r), u, s + w[u])) %= mod; } if (!b && p >= 0) vis[l][k][s] = 1, dp[l][k][s] = sum; return sum; } int main() { int i, j, k; scanf("%d%d%d", &n, &m, &lm); scanf("%d", &l1); for (i = 1; i <= l1; i++) scanf("%d", &a[i]); reverse(a + 1, a + 1 + l1); a[1]--; i = 1; while (a[i] < 0) a[i] += m, a[++i]--; while (a[l1] == 0 && l1) l1--; scanf("%d", &l2); for (i = 1; i <= l2; i++) scanf("%d", &b[i]); reverse(b + 1, b + 1 + l2); for (i = 1; i <= n; i++) { scanf("%d", &len); k = 0; for (j = 1; j <= len; j++) { scanf("%d", &x); if (!ch[k][x]) ch[k][x] = ++tot; k = ch[k][x]; } scanf("%d", &x); w[k] += x; } build_fail(); ans = -dfs(l1, -1, 1, 0, 0); l1 = l2; for (i = 1; i <= l2; i++) a[i] = b[i]; ans += dfs(l1, -1, 1, 0, 0); ans = (ans % mod + mod) % mod; printf("%d\n", ans); return 0; }
9
CPP
s = input() temp = s.count('7') + s.count('4') print('%s' %("YES" if (temp == 7 or temp == 4) else "NO"))
7
PYTHON3
n=int(input()) for i in range(n): t=int(input()) res=0 if t==1: print(0) elif t%3==0: while(t%3==0): if t%6==0: t=t//6 elif t%3==0: t*=2 res+=1 if t==1: print(res) else: print(-1) else: print(-1)
8
PYTHON3
import math,itertools,fractions,heapq,collections,bisect,sys,queue,copy sys.setrecursionlimit(10**7) inf=10**20 mod=10**9+7 dd=[(-1,0),(0,1),(1,0),(0,-1)] ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] def LI(): return [int(x) for x in sys.stdin.readline().split()] # def LF(): return [float(x) for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def LS(): return sys.stdin.readline().split() def S(): return input() def main(): n=I() s=S() ans=0 i=0 while True: if i+1<n: if s[i]!=s[i+1]: i+=2 else: i+=1 ans+=1 else: if i==n: return ans else: i+=1 ans+=1 # main() print(main())
7
PYTHON3
//Name: The Sorcerer's Donut //Level: //Category: //Note: #include <iostream> #include <cstdio> #include <vector> #include <algorithm> #include <string> #include <array> #include <map> using namespace std; #define TIMES(i,n) for(int i = 0; i < (n); ++i) const int DR[] = { 0, -1, -1, -1, 0, 1, 1, 1 }; const int DC[] = { 1, 1, 0, -1, -1, -1, 0, 1 }; array<array<bool,20>,10> visited; string search(int r, int c, int dir, const vector<string> &s, map<string,int> &memo) { const int H = s.size(); const int W = s[0].size(); string res; TIMES(i, H) { TIMES(j, W) { visited[i][j] = false; } } while(!visited[r][c]) { visited[r][c] = true; res += s[r][c]; if(res.size() > 1) memo[res]++; r = (r+DR[dir]+H) % H; c = (c+DC[dir]+W) % W; } return res; } bool solve() { int H, W; cin >> H >> W; if(!H && !W) return false; vector<string> s(H); TIMES(i, H) { cin >> s[i]; } map<string,int> memo; for(int r = 0; r < H; ++r) { for(int c = 0; c < W; ++c) { for(int dir = 0; dir < 8; ++dir) { search(r, c, dir, s, memo); } } } string ans = ""; for(const auto &p : memo) { if(p.second < 2) continue; if(p.first.size() > ans.size() || (p.first.size() == ans.size() && p.first < ans)) { ans = p.first; } } if(ans == "") ans = "0"; cout << ans << endl; return true; } int main() { cin.tie(0); ios::sync_with_stdio(0); while(solve()) ; return 0; }
0
CPP
for _ in range(int(input())): n, x = map(int, input().split(' ')) taken = [False for _ in range(max(100, n + x))] for place in map(int, input().split(' ')): taken[place - 1] = True for i, v in enumerate(taken): if v: continue elif x == 0: print(i) break else: x -= 1 else: print(len(taken))
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { int N, r[1000], w[1000]; bool dp[1000]; while(scanf("%d", &N), N) { for(int i = 0; i < N; i++) { scanf("%d %d", r + i, w + i); } int sum = accumulate(r, r + N, 0); int* big = max_element(r, r + N); int add = 0; if(*big * 2 > sum) { int space = *big * 2 - sum; swap(w[big - r], w[N - 1]); memset(dp, false, sizeof(bool) * (space + 1)); dp[0] = true; for(int i = 0; i < N - 1; i++) { for(int j = space; j >= w[i]; j--) { dp[j] |= dp[j - w[i]]; } } for(int i = space; i >= 0; i--) { if(dp[i]) { add = space - i; break; } } } printf("%d\n", sum + accumulate(w, w + N, 0) + add); } }
0
CPP
n=input() b="." a=["A","a","O","o","Y","y","E","e","U","u","I","i"] for i in range(len(n)): if n[i] in a: if b[-1]==".": continue else: b=b+"." else: d=n[i] d=d.lower() b=b+d if i!=len(n)-1: b=b+"." if b[-1]==".": g=b[0:-1] print(g) else: print(b)
7
PYTHON3
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, f = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); } while (isdigit(ch)) { x = x * 10 + ch - 48; ch = getchar(); } return x * f; } int n, k; int len, l, r; struct node { int l, r, id; } a[300500]; inline bool cmp(node a, node b) { return a.l < b.l; } priority_queue<int> q; int main() { n = read(); k = read(); for (int i = 1; i <= n; i++) { a[i].l = read(); a[i].r = read(); a[i].id = i; } sort(a + 1, a + n + 1, cmp); for (int i = 1; i <= n; i++) { q.push(-a[i].r); if (q.size() > k) q.pop(); if (q.size() == k) { int now = (-q.top()) - a[i].l + 1; if (now > len) { len = now; l = a[i].l; r = (-q.top()); } } } printf("%d\n", len); if (!len) for (int i = 1; i <= k; i++) printf("%d ", i); else for (int i = 1, j = 1; i <= n && j <= k; i++) if (a[i].l <= l && a[i].r >= r) printf("%d ", a[i].id), j++; return 0; }
10
CPP
n=int(input()) a=[int(i) for i in input().split()] a=sorted(a)[::-1] t=a[0]+1 s=0 for i in a: if t>i: s+=i t=i else: t-=1 s+=max(t,0) print(s)
8
PYTHON3
import bisect n=int(input()) a=[int(x) for x in input().split()] m=int(input()) b=[int(x) for x in input().split()] c=[a[0]] for i in range(n-1): c.append(c[i]+a[i+1]) for i in range(m): print(bisect.bisect_left(c,b[i],0,n)+1)
8
PYTHON3
n=int(input()) list1=[] for i in range(n): x=int(input()) list1.append(x) s=set(list1) list2=list(s) if(len(s)!=2): print("NO") else: d=0 t=list2[0]; for i in range(n): if(list1[i]==t): d=d+1 if(2*d==n): print("YES") print(list2[0],list2[1]) else: print("NO")
7
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { long long a, b, c, d = 0, e = 0, f = 0, g = 0, i, j, k = 1, l = 1, r = 1, n[300001], m[300001], q, u, v, w, y, z[400001], h[400001], p[500001]; string s, t, x; cin >> a >> b >> c; for (i = 1; i <= a; i++) { cin >> d >> e; f += (d - g) / c; g = d + e; } cout << f + ((b - g) / c); }
7
CPP
n = int(input()) x = min([int(input()) for _ in range(5)]) print((n+x-1)//x+4)
0
PYTHON3
#include <bits/stdc++.h> typedef struct zuobiao { int x; int y; } zuobiao; zuobiao dian(int a, int b, int c, int d, int e, int f) { zuobiao zb; zb.x = a + e - c; zb.y = b + f - d; return zb; } int main() { zuobiao zb; int n, m; scanf("%d %d", &n, &m); getchar(); char a[101][101] = {'\0'}; int b[3][2] = {0}; int i, j, k = 0; for (i = 0; i < n; i++) { for (j = 0; j < m; j++) { scanf("%c", &a[i][j]); if (a[i][j] == '*') { b[k][0] = i + 1; b[k][1] = j + 1; k++; } } getchar(); } if ((b[0][0] - b[1][0]) * (b[1][0] - b[2][0]) + (b[0][1] - b[1][1]) * (b[1][1] - b[2][1]) == 0) { zb = dian(b[0][0], b[0][1], b[1][0], b[1][1], b[2][0], b[2][1]); } if ((b[0][0] - b[2][0]) * (b[1][0] - b[2][0]) + (b[0][1] - b[2][1]) * (b[1][1] - b[2][1]) == 0) { zb = dian(b[0][0], b[0][1], b[2][0], b[2][1], b[1][0], b[1][1]); } if ((b[0][0] - b[2][0]) * (b[1][0] - b[0][0]) + (b[0][1] - b[2][1]) * (b[1][1] - b[0][1]) == 0) { zb = dian(b[2][0], b[2][1], b[0][0], b[0][1], b[1][0], b[1][1]); } printf("%d %d\n", zb.x, zb.y); return 0; }
7
CPP
#include <bits/stdc++.h> using namespace std; const long long inf = 1e9 + 100500; void solve() { int n1, n2, k1, k2; cin >> n1 >> n2 >> k1 >> k2; if (n1 > n2) cout << "First" << endl; else cout << "Second" << endl; } int main() { solve(); return 0; }
7
CPP
n, b = map(int, input().split()) i = 2; div = [] cnt = [] b1 = b while (i * i <= b1): if (b1 % i == 0): div.append(i); cnt.append(0); while (b1 % i == 0): cnt[-1] += 1; b1 //= i; i+= 1; if (b1 != 1): div.append(b1); cnt.append(1); for i in range(len(div)): curr = div[i]; cnt1 = cnt[i]; ans1 = 0; while (curr <= n): ans1 += n // curr; curr *= div[i]; if (i == 0) : ans = ans1 // cnt1 else: ans = min(ans, ans1 // cnt1); print(int(ans))
9
PYTHON3