solution
stringlengths 10
983k
| difficulty
int64 0
25
| language
stringclasses 2
values |
---|---|---|
#include <bits/stdc++.h>
using namespace std;
char grid[1010][1010];
int n, m, dist[5][1010][1010], dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0},
ans = 1061109567, col[5][5];
queue<pair<int, int> > q;
int main() {
int i, j, k, l, x, y, tx, ty;
cin >> n >> m;
memset(dist, 63, sizeof(dist));
for (i = 0; i < n; i++) {
for (j = 0; j < m; j++) {
cin >> grid[i][j];
}
}
for (i = 0; i < 3; i++) {
for (j = 0; j < n; j++) {
for (k = 0; k < m; k++) {
if ((grid[j][k] - '1') == i) {
q.push(make_pair(j, k));
dist[i][j][k] = 0;
}
}
}
while (!q.empty()) {
x = q.front().first;
y = q.front().second;
q.pop();
for (j = 0; j < 4; j++) {
tx = x + dx[j];
ty = y + dy[j];
if (tx < 0 || tx >= n || ty < 0 || ty >= m) {
continue;
}
if (grid[tx][ty] == '#') {
continue;
}
if (dist[i][tx][ty] > dist[i][x][y] + 1) {
dist[i][tx][ty] = dist[i][x][y] + 1;
q.push(make_pair(tx, ty));
}
}
}
}
for (i = 0; i < n; i++) {
for (j = 0; j < m; j++) {
if (dist[0][i][j] >= 1000000000 || dist[1][i][j] >= 1000000000 ||
dist[2][i][j] >= 1000000000) {
continue;
}
ans = min(ans, dist[0][i][j] + dist[1][i][j] + dist[2][i][j] - 2);
}
}
for (i = 0; i < 3; i++) {
for (j = 0; j < 3; j++) {
col[i][j] = 1000000000;
for (k = 0; k < n; k++) {
for (l = 0; l < m; l++) {
if (grid[k][l] - '1' == j) {
col[i][j] = min(col[i][j], dist[i][k][l] - 1);
}
}
}
}
}
ans = min(ans, min(col[0][1] + col[0][2],
min(col[0][1] + col[1][2], col[0][2] + col[2][1])));
if (ans >= 1000000000) {
cout << -1 << endl;
} else {
cout << ans << endl;
}
return 0;
}
| 9 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
long long l, r;
cin >> l >> r;
long long l1, r1;
l1 = l * pow(-1, l);
r1 = r * pow(-1, r);
long long dif = r - l + 1;
if (dif % 2 == 0) {
if (l1 > 0) {
cout << (-1) * (dif / 2) << endl;
} else
cout << dif / 2 << endl;
} else {
if (l1 > 0) {
cout << (-1) * (dif / 2) + r1 << endl;
} else
cout << (dif / 2) + r1 << endl;
}
}
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const long long N = 53, INF = 1e18, MOD = 1e9 + 7;
long long dis[N][N][2], way[N][N][2];
long long POW(long long a, long long b) {
if (b == 0) return 1;
long long ans = POW(a, b / 2);
ans *= ans;
ans %= MOD;
if (b % 2) ans *= a;
ans %= MOD;
return ans;
}
long long C(long long a, long long b) {
if (b == 0) return 1;
long long ans = 1, res = 1;
for (long long i = b - a + 1; i <= b; i++) ans *= i, ans %= MOD;
for (long long i = 1; i <= a; i++) res *= i, res %= MOD;
return (ans * POW(res, MOD - 2)) % MOD;
}
inline void BFS(long long a, long long b, long long k) {
queue<pair<pair<long long, long long>, bool> > q;
for (long long i = 0; i <= a; i++)
for (long long j = 0; j <= b; j++) dis[i][j][0] = dis[i][j][1] = INF;
dis[a][b][0] = 0;
way[a][b][0] = 1;
q.push({{a, b}, 0});
while (!q.empty()) {
long long x = q.front().first.first, y = q.front().first.second,
t = q.front().second;
q.pop();
if (t) {
x = a - x;
y = b - y;
}
for (long long i = 0; i <= x; i++) {
for (long long j = 0; j <= y; j++) {
if (i + j > 0 && i * 50 + j * 100 <= k) {
long long nx, ny;
if (t) {
x = a - x;
y = b - y;
nx = x + i, ny = y + j;
} else {
nx = x - i, ny = y - j;
}
if (dis[nx][ny][!t] > dis[x][y][t] + 1) {
dis[nx][ny][!t] = dis[x][y][t] + 1;
q.push({{nx, ny}, !t});
}
if (dis[nx][ny][!t] == dis[x][y][t] + 1) {
if (t)
way[nx][ny][!t] +=
(way[x][y][t] * C(i, a - x) * C(j, b - y)) % MOD;
else
way[nx][ny][!t] += (way[x][y][t] * C(i, x) * C(j, y)) % MOD;
way[nx][ny][!t] %= MOD;
}
if (t) {
x = a - x;
y = b - y;
}
}
}
}
}
}
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
long long n, k;
cin >> n >> k;
long long a = 0, b = 0;
for (long long i = 0; i < n; i++) {
long long x;
cin >> x;
if (x == 50)
a++;
else
b++;
}
BFS(a, b, k);
if (dis[0][0][1] >= INF)
cout << -1 << endl << 0;
else
cout << dis[0][0][1] << endl << way[0][0][1];
return 0;
}
| 11 | CPP |
n,m = map(int,input().split(' '))
arr = list(map(int,input().split(' ')))
r = 0
for i in range(0,n):
r+=arr[i]
print(r//m)
r = r%m
| 7 | PYTHON3 |
import math
t=int(input())
while t:
n,m,k=list(map(int,input().split()))
p=n//k
if p>=m:
print(m)
else:
x=p
m=m-p
y=m//(k-1)
if m%(k-1)>0:
y+=1
print(x-y)
t-=1
| 7 | PYTHON3 |
a=int(input())
faces=0
for i in range(a):
data=input()
if(data=="Tetrahedron"): faces+=4
elif(data=="Cube"): faces+=6
elif(data=="Octahedron"): faces+=8
elif(data=="Dodecahedron"): faces+=12
elif(data=="Icosahedron"): faces+=20
print(faces) | 7 | PYTHON3 |
a=[]
count=0
for i in range (5):
a.append(list(map(int, input().split())))
for i in range(5):
for j in range(5):
if a[i][j]==1:
x=i
y=j
print((abs(2-x))+(abs(2-y))) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using VI = vector<int>;
using VL = vector<long long>;
using VVI = vector<VI>;
using VVL = vector<VL>;
using MII = map<int, int>;
using MIVI = map<int, VI>;
using MLL = map<LL, LL>;
int READ_INT() {
int temp;
cin >> temp;
return temp;
}
LL READ_LONG() {
LL temp;
cin >> temp;
return temp;
}
const int MOD = int(1e9) + 7;
const int INF = 1e9 + 5;
const double PI = acos(-1.0);
const double EPS = 1e-9;
LL n;
vector<pair<LL, LL>> boxes;
bool is_possible(LL side) {
for (auto b : boxes) {
LL cur_side = b.first;
if (side - cur_side >= 16) continue;
if (cur_side >= side) return false;
LL capacity = pow(4, side - cur_side);
if (capacity < b.second) return false;
}
return true;
}
int main() {
ios::sync_with_stdio(false);
n = READ_INT();
for (int i = 0; i < n; ++i) boxes.push_back({READ_LONG(), READ_LONG()});
sort(boxes.rbegin(), boxes.rend());
LL r = 1e18, l = 1, m;
while (r > l) {
m = l + (r - l) / 2;
if (is_possible(m))
r = m;
else
l = m + 1;
}
cout << r << "\n";
return 0;
}
| 9 | CPP |
#!/usr/bin/env python3
def main():
w = input()
words = set()
for i in range(len(w)):
words.add(w[i:] + w[:i])
return len(words)
if __name__ == '__main__':
print(main())
| 7 | PYTHON3 |
#include<iostream>
#include<queue>
#include<utility>
using namespace std;
int main(){
int n,m;
while(cin>>n>>m,n){
int a,b,ans=0;
priority_queue< pair<int,int> > c;
for(int i=0;i<n;i++){
cin>>a>>b;
c.push(make_pair(b,a));
}
while(!c.empty()){
if(c.top().second>m){
c.push(make_pair(c.top().first,c.top().second-m));
c.pop();
break;
}
else {
m-=c.top().second;
c.pop();
}
}
while(!c.empty()){
ans+=c.top().first*c.top().second;
c.pop();
}
cout<<ans<<endl;
}
return 0;
} | 0 | CPP |
n,k = list(map(int, input().strip().split()))
# creating a mapping array
array = [0]*(2**k)
for _ in range(n):
t = int(''.join(input().strip().split()), 2)
array[t] += 1
# now creating a compatibility array
comp = [[] for i in range(2**k)]
for i in range(2**k):
for j in range(2**k):
if i&j == 0:
comp[i].append(j)
# now doing the math
flag = False
if array[0] > 0:
print('YES')
flag = True
for i in range(1, 2**k):
if flag:
break
if array[i] > 0:
for j in comp[i]:
if array[j] > 0:
print('YES')
flag = True
break
if not flag:
print('NO') | 9 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
int a[n], y, i;
for (i = 0; i < n; i++) {
cin >> a[i];
}
std::map<int, int> code;
for (int j = 0; j < m; j++) {
cin >> y;
for (i = 0; i < n; i++) {
if (a[i] == y) {
code[i] = y;
}
}
}
auto it = code.begin();
while (it != code.end()) {
cout << it->second << " ";
it++;
}
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
int p[120000], size[120000], br[120000], is[120000];
void make(int x) {
size[x] = 1;
p[x] = x;
}
int find(int x) {
if (x == p[x]) return x;
return p[x] = find(p[x]);
}
void uni(int x, int y) {
x = find(x);
y = find(y);
if (x != y) {
if (x < y) swap(x, y);
p[y] = x;
size[x] += size[y];
}
}
int main() {
int x, y, n, m, k, i, j;
cin >> n >> m;
for (i = 0; i < n; i++) make(i);
for (i = 0; i < m; i++) {
cin >> x >> y;
x--;
y--;
uni(x, y);
}
cin >> k;
for (i = 0; i < k; i++) {
cin >> x >> y;
x--;
y--;
j = find(x);
if (j == find(y)) br[j] = 1;
}
int mx = 0;
for (i = 0; i < n; i++) {
j = find(i);
is[j] = 1;
}
for (i = 0; i < n; i++)
if (size[i] > mx && br[i] == 0 && is[i]) {
mx = size[i];
}
cout << mx << endl;
return 0;
}
| 9 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
inline int read() {
int w = 1, s = 0;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-') w = -1;
ch = getchar();
}
while (isdigit(ch)) {
s = s * 10 + ch - '0';
ch = getchar();
}
return w * s;
}
inline long long ksm(long long x, long long y) {
long long res = 1;
while (y) {
if (y & 1) res = res * x % mod;
x = x * x % mod;
y >>= 1;
}
return res;
}
inline int pls(int a, int b) {
a += b;
return a >= mod ? a - mod : a;
}
inline int mns(int a, int b) {
a -= b;
return a < 0 ? a + mod : a;
}
int n, k, m, Idx[15][222], cnt;
pair<int, int> tmp[101000];
struct Ma {
int a[417][417];
inline void I() {
memset(a, 0, sizeof(a));
for (register int i = 1; i <= cnt; ++i) a[i][i] = 1;
}
} trs, Ans;
inline Ma operator*(Ma p, Ma q) {
Ma res;
memset(res.a, 0, sizeof(res.a));
for (register int i = 1; i <= cnt; ++i)
for (register int j = 1; j <= cnt; ++j) {
int k = 1, v = 0;
unsigned long long w = 0;
for (; k + 15 <= cnt; k += 16)
v = (v + (unsigned long long)p.a[i][k] * q.a[k][j] +
(unsigned long long)p.a[i][k + 1] * q.a[k + 1][j] +
(unsigned long long)p.a[i][k + 2] * q.a[k + 2][j] +
(unsigned long long)p.a[i][k + 3] * q.a[k + 3][j] +
(unsigned long long)p.a[i][k + 4] * q.a[k + 4][j] +
(unsigned long long)p.a[i][k + 5] * q.a[k + 5][j] +
(unsigned long long)p.a[i][k + 6] * q.a[k + 6][j] +
(unsigned long long)p.a[i][k + 7] * q.a[k + 7][j] +
(unsigned long long)p.a[i][k + 8] * q.a[k + 8][j] +
(unsigned long long)p.a[i][k + 9] * q.a[k + 9][j] +
(unsigned long long)p.a[i][k + 10] * q.a[k + 10][j] +
(unsigned long long)p.a[i][k + 11] * q.a[k + 11][j] +
(unsigned long long)p.a[i][k + 12] * q.a[k + 12][j] +
(unsigned long long)p.a[i][k + 13] * q.a[k + 13][j] +
(unsigned long long)p.a[i][k + 14] * q.a[k + 14][j] +
(unsigned long long)p.a[i][k + 15] * q.a[k + 15][j]) %
mod;
for (; k <= cnt; k++) w += (unsigned long long)p.a[i][k] * q.a[k][j];
res.a[i][j] = (v + w) % mod;
}
return res;
}
inline Ma ksm(Ma x, int y) {
Ma res;
res.I();
while (y) {
if (y & 1) res = res * x;
x = x * x;
y >>= 1;
}
return res;
}
inline void Solve() {
memset(trs.a, 0, sizeof(trs.a));
memset(Ans.a, 0, sizeof(Ans.a));
for (register int i = 1; i <= cnt; ++i) {
pair<int, int> o = tmp[i];
int fir = o.first, sec = o.second, bit = __builtin_popcount(sec);
if (sec & 1) {
sec >>= 1;
trs.a[i][Idx[fir][sec]] = bit;
sec |= (1 << m);
fir++;
trs.a[i][Idx[fir][sec]] = bit;
} else {
sec >>= 1;
trs.a[i][Idx[fir][sec]] = 1;
sec |= (1 << m);
fir++;
trs.a[i][Idx[fir][sec]] = 1;
}
}
for (register int i = 1; i <= cnt; ++i) {
pair<int, int> o = tmp[i];
int fir = o.first, sec = o.second, bit = __builtin_popcount(sec);
if (fir == bit) Ans.a[1][i] = 1;
}
Ans = Ans * ksm(trs, n - m - 1);
long long ans = 0;
for (register int i = 1; i <= cnt; ++i) {
pair<int, int> o = tmp[i];
int fir = o.first, sec = o.second, bit = __builtin_popcount(sec);
int oo = 1;
for (register int i = 1; i <= bit; ++i) oo *= i;
if (fir == k) {
ans = pls(ans, 1ll * Ans.a[1][i] * oo % mod);
}
}
cout << ans;
}
int main() {
n = read(), k = read(), m = read();
m = min(m, n - 1);
int all = 1 << (m + 1);
all--;
for (register int i = 0; i <= k; ++i) {
for (register int j = 0; j <= all; ++j) {
Idx[i][j] = ++cnt;
tmp[cnt] = make_pair(i, j);
}
}
Solve();
return 0;
}
| 12 | CPP |
for r in range(5):
row=input().split()
for c in range(5):
if row[c]=='1':
moves=abs(r-2)+abs(c-2)
print(moves) | 7 | PYTHON3 |
#include<cstdio>
long long a[4] = {1};
char c;
int main(){
while(EOF != scanf("%c", &c)) for(int j = 3; j >= 0; j--)
a[j] = (a[j]*(c-'?'?1:3) + (j&&!(c-'?'&&c-'A'-j+1)?a[j-1]:0))%1000000007;
printf("%lld\n", a[3]);
} | 0 | CPP |
n = input()
a = n.count('4') + n.count('7')
a = str(a)
if set(a) | {'4','7'} == {'4','7'}:
print('YES')
else:
print('NO')
| 7 | PYTHON3 |
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int n;
struct Data{
int t,m;
bool operator<(const Data& another) const {
if (t != another.t) return t < another.t;
else return m < another.m;
}
};
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
while(true){
cin >> n;
if(n == 0) break;
int m,a,b;
vector<Data> d;
for (int i = 0;i < n;i++){
cin >> m >> a >> b;
d.push_back({a,m});
d.push_back({b,-m});
}
sort(d.begin(),d.end());
int sum = 0;
bool ans = true;
for (int i = 0;i < d.size();i++){
sum += d[i].m;
if(sum > 150){
ans = false;
}
}
cout << (ans?"OK":"NG") << endl;
}
return 0;
}
| 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3 * 1e5;
const long long mod = 1e9 + 7;
long long k[maxn + 5];
long long fac2[maxn + 5];
long long sumfac2[maxn + 5];
int n;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
scanf("%lld", &k[i]);
}
sort(k + 1, k + 1 + n);
fac2[0] = 1ll;
sumfac2[1] = 1ll;
for (int i = 1; i <= n; ++i) {
fac2[i] = fac2[i - 1] * 2ll % mod;
sumfac2[i + 1] = (sumfac2[i] + fac2[i]) % mod;
}
int l = n - 1, r = 0;
long long ans = 0ll;
for (int i = n; i >= 1; --i) {
ans = (ans + (k[i] * sumfac2[l--] - k[i] * sumfac2[r++]) % mod + mod) % mod;
}
printf("%lld\n", ans);
return 0;
}
| 7 | CPP |
n = int(input())
arr = [int(x) for x in input().strip().split()]
m = int(input())
curr = 0
q = []
for i in range(0,m):
k = [int(x) for x in input().strip().split()]
q.append(k)
# if arr[w-1]+h>w:
# k = arr[w-1]
# for i in range(w-1,min(arr[w-1]+h,n)):
# arr[i] = max(k+h,arr[i])
# #print(arr,"2")
# for i in range(0,w-1):
# arr[i]=arr[w-1]
# #print(arr,"3")
for i in q:
w,h=i
print(max(curr,arr[w-1]))
#print(arr,"1")
curr = max(curr,max(curr,arr[w-1])+h)
arr[w-1] = curr | 7 | PYTHON3 |
n = int(input())
a = [list(map(int, input().split())) for i in range(n)]
p = [0] * n
got = [0, 1]
if n == 2:
print(2, 1)
exit()
for i in range(n):
if set(a[i]) == {0, 1}:
p[i] = 1
break
for need in range(1, n):
for i in range(n):
if set(a[i]) == set(got+[need]):
p[i] = need
got.append(need)
break
for i in range(n):
if p[i] == 0:
p[i] = n
print(*p) | 8 | PYTHON3 |
a, b = map(int,input().split())
n = 1
while True:
if a*(3**n)>b*(2**n):
break
n+=1
print(n)
| 7 | PYTHON3 |
n = int(input())
if n%3 ==0:
print("Oh, my keyboard!")
else:
x = list(map(int,input().split()))
y = list(map(int,input().split()))
l = []
for i in range(1,n+1):
l.append(i)
for i in y:
x.append(i)
x.sort()
for i in x:
if i == 0:
x.remove(i)
s = list(set(x))
if s == l:
print("I become the guy.")
else:
print("Oh, my keyboard!") | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
namespace geometry {
using type = long double;
const type EPS = 1e-9;
const type PI = cosl(-1.0);
const type INF = 1e9;
struct Point {
type x;
type y;
Point(type x_ = 0.0, type y_ = 0.0) : x(x_), y(y_) {}
Point operator+(const Point o) const {
return Point(this->x + o.x, this->y + o.y);
}
Point *operator+=(const Point o) {
this->x += o.x;
this->y += o.y;
return this;
}
Point operator-(const Point o) const {
return Point(this->x - o.x, this->y - o.y);
}
Point *operator-=(const Point o) {
this->x -= o.x;
this->y -= o.y;
return this;
}
Point operator*(const type c) const {
return Point(this->x * c, this->y * c);
}
Point *operator*=(const type c) {
this->x *= c;
this->y *= c;
return this;
}
Point operator/(const type c) const {
return Point(this->x / c, this->y / c);
}
Point *operator/=(const type c) {
this->x /= c;
this->y /= c;
return this;
}
Point rot(const type rad) const {
return Point(this->x * cosl(rad) - this->y * sinl(rad),
this->x * sinl(rad) + this->y * cosl(rad));
}
type rot_diff(const Point o) const {
type rot1 = atan2(this->y, this->x);
type rot2 = atan2(o.y, o.x);
type res = rot2 - rot1;
return res;
}
};
type dot(Point a, Point b) { return (a.x * b.x) + (a.y * b.y); }
type cross(Point a, Point b) { return (a.x * b.y) - (a.y * b.x); }
int sign(type o) {
if (o > 0) return +1;
if (o < 0) return -1;
return 0;
}
bool in_triangle(Point A, Point B, Point C, Point P) {
if (sign(cross(A - C, B - C)) != sign(cross(P - C, B - C))) return false;
if (sign(cross(B - A, C - A)) != sign(cross(P - A, C - A))) return false;
if (sign(cross(C - B, A - B)) != sign(cross(P - B, A - B))) return false;
if (sign(cross(B - C, A - C)) != sign(cross(P - C, A - C))) return false;
if (sign(cross(C - A, B - A)) != sign(cross(P - A, B - A))) return false;
if (sign(cross(A - B, C - B)) != sign(cross(P - B, C - B))) return false;
return true;
}
using Shape = vector<Point>;
type get_area(Shape s) {
type res = 0.0;
int sz = s.size();
for (int i = 0; i < sz; i++) {
res += s[i].x * s[(i + 1) % sz].y;
res -= s[i].y * s[(i + 1) % sz].x;
}
res /= 2.0;
return res;
}
void print_shape(Shape s) {
int sz = s.size();
Shape tmp;
tmp.emplace_back(s[0]);
for (int i = 1; i < sz; i++)
if (hypotl(s[i].x - s[i - 1].x, s[i].y - s[i - 1].y) > EPS)
tmp.emplace_back(s[i]);
s = tmp;
sz = s.size();
cout << sz << " ";
for (int i = 0; i < sz; i++) cout << s[i].x << " " << s[i].y << " ";
cout << "\n";
}
Shape read_shape() {
Shape res;
Point in;
int n;
cin >> n;
while (n--) {
cin >> in.x >> in.y;
res.emplace_back(in);
}
return res;
}
} // namespace geometry
using namespace geometry;
struct Operation {
Shape start_shape;
vector<Shape> cut_shapes;
vector<Shape> tape_shapes;
Shape final_shape;
Operation() {}
};
class Scissors_and_Tape {
private:
Shape Start, Target;
type Area;
vector<Operation> reverse_operations(vector<Operation> op) {
reverse(op.begin(), op.end());
for (auto &i : op) swap(i.start_shape, i.final_shape);
for (auto &i : op) swap(i.cut_shapes, i.tape_shapes);
return op;
}
void rotate_left(Point &a, Point &b, Point &c) {
Point tmp = a;
a = b;
b = c;
c = tmp;
}
void rotate_right(Point &a, Point &b, Point &c) {
Point tmp = c;
c = b;
b = a;
a = tmp;
}
struct ListOfRectangles {
vector<type> H, W;
ListOfRectangles() {}
int size() { return H.size(); }
};
ListOfRectangles triangulate_to_rectangles(Shape s, vector<Operation> &ops) {
Operation op;
ListOfRectangles res;
op.start_shape = s;
type cur_x = 0.0;
while (s.size() > 2) {
for (int i = 0, N = s.size(); i < N; i++) {
Point A = s[(i + N - 1) % N], B = s[i], C = s[(i + 1) % N];
if (sign(cross(B - A, C - A)) == -1) continue;
bool no_point_inside_triangle = true;
for (int j = 0; j < N; j++) {
if (i == j || ((i + N - 1) % N) == j || ((i + N + 1) % N) == j)
continue;
if (in_triangle(A, B, C, s[j])) no_point_inside_triangle = false;
}
if (!no_point_inside_triangle) continue;
type l_AB = dot(B - A, B - A), l_BC = dot(C - B, C - B),
l_AC = dot(C - A, C - A);
while (l_AB < max(l_BC, l_AC)) {
rotate_left(A, B, C);
l_AB = dot(B - A, B - A), l_BC = dot(C - B, C - B),
l_AC = dot(C - A, C - A);
}
l_AB = dot(B - A, B - A), l_BC = dot(C - B, C - B),
l_AC = dot(C - A, C - A);
Point U = A + (C - A) * 0.5;
Point V = B + (C - B) * 0.5;
Point M = ((U * dot(V - U, V - U)) + ((V - U) * dot(C - U, V - U))) /
dot(V - U, V - U);
Point shift = A;
type deg = (B - shift).rot_diff(Point(cur_x, 0));
if (get_area({A, B, V, U}) > 0) {
op.cut_shapes.push_back({A, B, V, U});
op.tape_shapes.push_back({Point(cur_x, 0) + (A - shift).rot(deg),
Point(cur_x, 0) + (B - shift).rot(deg),
Point(cur_x, 0) + (V - shift).rot(deg),
Point(cur_x, 0) + (U - shift).rot(deg)});
}
if (get_area({U, M, C}) > 0) {
op.cut_shapes.push_back({U, M, C});
op.tape_shapes.push_back(
{Point(cur_x, 0) + (U - shift).rot(deg),
Point(cur_x, 0) + (U + U - M - shift).rot(deg),
Point(cur_x, 0) + (A - shift).rot(deg)});
}
if (get_area({V, C, M}) > 0) {
op.cut_shapes.push_back({V, C, M});
op.tape_shapes.push_back(
{Point(cur_x, 0) + (V - shift).rot(deg),
Point(cur_x, 0) + (B - shift).rot(deg),
Point(cur_x, 0) + (V + V - M - shift).rot(deg)});
}
res.W.push_back(sqrtl(l_AB));
res.H.push_back(get_area({A, B, C}) / res.W.back());
op.final_shape.push_back({cur_x, res.H.back()});
op.final_shape.push_back({cur_x + res.W.back(), res.H.back()});
assert(get_area({A, B, C}) >= 0);
cur_x += sqrtl(l_AB);
s.erase(s.begin() + i);
break;
}
}
op.final_shape.emplace_back(cur_x, 0);
op.final_shape.emplace_back(0, 0);
reverse(op.final_shape.begin(), op.final_shape.end());
ops.emplace_back(op);
return res;
}
ListOfRectangles rectangles_to_ideal_rectangles(ListOfRectangles rect,
vector<Operation> &ops) {
type side = sqrtl(Area);
vector<type> &H = rect.H;
vector<type> &W = rect.W;
while (true) {
int N = rect.size();
bool stop = true;
ListOfRectangles nxt;
type cut_x = 0.0;
type tape_x = 0.0;
Operation op;
op.start_shape = ops.back().final_shape;
for (int i = 0; i < N; i++) {
if (H[i] * 2.0 < side) {
stop = false;
op.cut_shapes.push_back({{cut_x, 0},
{cut_x + W[i] / 2.0, 0},
{cut_x + W[i] / 2.0, H[i]},
{cut_x, H[i]}});
op.tape_shapes.push_back({{tape_x, 0},
{tape_x + W[i] / 2.0, 0},
{tape_x + W[i] / 2.0, H[i]},
{tape_x, H[i]}});
op.cut_shapes.push_back({{cut_x + W[i] / 2.0, 0},
{cut_x + W[i], 0},
{cut_x + W[i], H[i]},
{cut_x + W[i] / 2.0, H[i]}});
op.tape_shapes.push_back({{tape_x, H[i]},
{tape_x + W[i] / 2.0, H[i]},
{tape_x + W[i] / 2.0, H[i] * 2.0},
{tape_x, H[i] * 2.0}});
op.final_shape.emplace_back(tape_x, H[i] * 2.0);
op.final_shape.emplace_back(tape_x + W[i] / 2.0, H[i] * 2.0);
tape_x += W[i] / 2.0;
cut_x += W[i];
nxt.W.push_back(W[i] / 2.0);
nxt.H.push_back(H[i] * 2.0);
} else if (H[i] >= side) {
stop = false;
op.cut_shapes.push_back({{cut_x, 0},
{cut_x + W[i], 0},
{cut_x + W[i], H[i] / 2.0},
{cut_x, H[i] / 2.0}});
op.tape_shapes.push_back({{tape_x, 0},
{tape_x + W[i], 0},
{tape_x + W[i], H[i] / 2.0},
{tape_x, H[i] / 2.0}});
op.cut_shapes.push_back({{cut_x, H[i] / 2.0},
{cut_x + W[i], H[i] / 2.0},
{cut_x + W[i], H[i]},
{cut_x, H[i]}});
op.tape_shapes.push_back({{tape_x + W[i], 0},
{tape_x + W[i] * 2.0, 0},
{tape_x + W[i] * 2.0, H[i] / 2.0},
{tape_x + W[i], H[i] / 2.0}});
op.final_shape.emplace_back(tape_x, H[i] / 2.0);
op.final_shape.emplace_back(tape_x + W[i] * 2.0, H[i] / 2.0);
tape_x += W[i] * 2.0;
cut_x += W[i];
nxt.W.push_back(W[i] * 2.0);
nxt.H.push_back(H[i] / 2.0);
} else {
op.cut_shapes.push_back({{cut_x, 0},
{cut_x + W[i], 0},
{cut_x + W[i], H[i]},
{cut_x, H[i]}});
op.tape_shapes.push_back({{tape_x, 0},
{tape_x + W[i], 0},
{tape_x + W[i], H[i]},
{tape_x, H[i]}});
op.final_shape.emplace_back(tape_x, H[i]);
op.final_shape.emplace_back(tape_x + W[i], H[i]);
tape_x += W[i];
cut_x += W[i];
nxt.W.push_back(W[i]);
nxt.H.push_back(H[i]);
}
}
op.final_shape.emplace_back(tape_x, 0);
op.final_shape.emplace_back(0, 0);
reverse(op.final_shape.begin(), op.final_shape.end());
ops.emplace_back(op);
rect = nxt;
if (stop) break;
}
return rect;
}
void ideal_rectangles_to_square(ListOfRectangles rect,
vector<Operation> &ops) {
type cut_x = 0.0;
type tape_x = 0.0;
type side = sqrtl(Area);
Operation op;
op.start_shape = ops.back().final_shape;
int N = rect.size();
vector<type> H = rect.H;
vector<type> W = rect.W;
for (int i = 0; i < N; i++) {
type new_cut_x = cut_x + W[i];
type right_triangle = ((H[i] * W[i]) / side);
type diff_height = side - H[i];
op.cut_shapes.push_back({{right_triangle + cut_x, 0},
{new_cut_x, 0},
{right_triangle + cut_x, diff_height}});
op.tape_shapes.push_back(
{{tape_x, side - diff_height},
{W[i] - right_triangle + tape_x, side - diff_height},
{tape_x, side}});
op.cut_shapes.push_back({{new_cut_x, 0},
{new_cut_x, H[i]},
{W[i] - right_triangle + cut_x, H[i]}});
op.tape_shapes.push_back({{tape_x + right_triangle, diff_height},
{tape_x + right_triangle, side},
{tape_x, side}});
op.cut_shapes.push_back({{cut_x, 0},
{cut_x + right_triangle, 0},
{cut_x + right_triangle, diff_height},
{cut_x + W[i] - right_triangle, H[i]},
{cut_x, H[i]}});
op.tape_shapes.push_back({{tape_x, 0},
{tape_x + right_triangle, 0},
{tape_x + right_triangle, diff_height},
{tape_x + W[i] - right_triangle, H[i]},
{tape_x, H[i]}});
cut_x = new_cut_x;
tape_x = tape_x + right_triangle;
}
op.final_shape = {{0, 0}, {side, 0}, {side, side}, {0, side}};
ops.emplace_back(op);
}
vector<Operation> polygon_to_square(Shape s) {
vector<Operation> res;
ListOfRectangles rectangles = triangulate_to_rectangles(s, res);
ListOfRectangles ideal_rectangles =
rectangles_to_ideal_rectangles(rectangles, res);
ideal_rectangles_to_square(ideal_rectangles, res);
return res;
}
public:
Scissors_and_Tape(){};
Scissors_and_Tape(Shape s, Shape t) : Start(s), Target(t) {}
vector<Operation> get_solution() {
Area = get_area(Start);
vector<Operation> start_to_square = polygon_to_square(Start);
vector<Operation> target_to_square =
reverse_operations(polygon_to_square(Target));
vector<Operation> res;
res.insert(res.end(), start_to_square.begin(), start_to_square.end());
res.insert(res.end(), target_to_square.begin(), target_to_square.end());
return res;
}
};
int main() {
cout << fixed << setprecision(10);
Shape Start = read_shape();
Shape Target = read_shape();
Scissors_and_Tape solver(Start, Target);
vector<Operation> solution = solver.get_solution();
int cur_id = 0;
for (auto op : solution) {
int new_id = cur_id + op.cut_shapes.size() + 1;
cout << "scissors\n";
cout << cur_id << " " << op.cut_shapes.size() << "\n";
for (auto s : op.cut_shapes) print_shape(s);
cout << "tape\n";
cout << op.tape_shapes.size();
for (int id = cur_id + 1; id < new_id; id++) cout << " " << id;
cout << "\n";
for (auto s : op.tape_shapes) print_shape(s);
print_shape(op.final_shape);
cur_id = new_id;
}
return 0;
}
| 9 | CPP |
#include<iostream>
using namespace std;
int main(){
int A,P;
cin>>A>>P;
cout<<(3*A+P)/2;
return 0;
} | 0 | CPP |
#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
int n, m;
int nex[200000];
pair<long long, long long> a[200000];
int par[200000][20];
int depth[200000];
long long ccw(pair<long long, long long> x, pair<long long, long long> y,
pair<long long, long long> z) {
return (y.first - x.first) * (z.second - x.second) -
(y.second - x.second) * (z.first - x.first);
}
int lca(int x, int y) {
int i, j;
if (depth[x] < depth[y]) swap(x, y);
int cha = depth[x] - depth[y];
for (i = 0; i < 20; i++) {
if (cha & (1 << i)) x = par[x][i];
}
if (x == y) return x;
for (i = 19; i >= 0; i--) {
if (par[x][i] != par[y][i]) x = par[x][i], y = par[y][i];
}
return par[x][0];
}
int main() {
int i, j, k;
scanf("%d", &n);
for (i = 0; i < n; i++) scanf("%I64d%I64d", &a[i].first, &a[i].second);
nex[n - 1] = n - 1;
for (i = n - 2; i >= 0; i--) {
int dab = i + 1;
while (1) {
if (ccw(a[i], a[dab], a[nex[dab]]) > 0) {
dab = nex[dab];
} else
break;
}
nex[i] = dab;
}
depth[n - 1] = 0;
for (i = n - 2; i >= 0; i--) depth[i] = depth[nex[i]] + 1;
for (i = n - 1; i >= 0; i--) {
par[i][0] = nex[i];
for (j = 1; j < 20; j++) {
par[i][j] = par[par[i][j - 1]][j - 1];
}
}
scanf("%d", &m);
for (i = 0; i < m; i++) {
int x, y;
scanf("%d%d", &x, &y);
x--, y--;
printf("%d ", lca(x, y) + 1);
}
return 0;
}
| 10 | CPP |
#include<iostream>
using namespace std;
int main(){
int a, b; cin>>a>>b;
cout<<a*b<<" "<<(a+b)*2<<"\n";
}
| 0 | CPP |
year = int(input())
while 1:
year += 1
a=year//1000
b=(year//100)%10
c=(year//10)%10
d=year%10
if a!=b and a!=c and a!=d and b!=c and b!=d and c!=d:
break
print(year) | 7 | PYTHON3 |
n = int(input())
if n % 2 == 0:
print(n//2)
print(*['2' for i in range(n//2)])
else:
print(((n-3)//2) + 1)
print(*['2' for i in range((n-3)//2)], '3')
| 7 | PYTHON3 |
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
c = 0
t = 0
for i in range(n):
if a[i] >= t:
c += 1
t += a[i]
print(c)
| 10 | PYTHON3 |
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())
def cal(x,y,f):
return (x+y*W)*2+f
def dijkstra(lines,N,s):
weight = [INF]*N
weight[s] = 0
def search(s,w_0,q,weight):
for t,w in lines[s]:
w += w_0
if weight[t] > w:
heapq.heappush(q,[w,t])
weight[t] = w
q = [[0,s]]
heapq.heapify(q)
while q:
w,n = heapq.heappop(q)
search(n,w,q,weight)
return weight
dxr = [ 1, 1, 1, 1, 1, 2, 2, 2, 3]
dyr = [-2,-1, 0, 1, 2,-1, 0, 1, 0]
dxl = [-1,-1,-1,-1,-1,-2,-2,-2,-3]
dyl = [-2,-1, 0, 1, 2,-1, 0, 1, 0]
while True:
W,H = inpl()
if W == 0:
break
ss = [list(input().split()) for _ in range(H)]
N = W*H*2+2
S = W*H*2
T = W*H*2+1
lines = defaultdict(set)
for x in range(W):
for y in range(H):
if ss[y][x] == 'S':
lines[S].add((cal(x,y,0),0))
lines[S].add((cal(x,y,1),0))
if ss[y][x] == 'T':
lines[cal(x,y,0)].add((T,0))
lines[cal(x,y,1)].add((T,0))
continue
if ss[y][x] == 'X':
continue
else:
f = 0 # 次が右足
for i in range(9):
tx = x + dxr[i]
ty = y + dyr[i]
if (0 <= tx < W) and (0 <= ty < H):
if ss[ty][tx] == 'S' or ss[ty][tx] == 'T':
cost = 0
elif ss[ty][tx] == 'X':
continue
else:
cost = int(ss[ty][tx])
lines[cal(x,y,0)].add((cal(tx,ty,1),cost))
f = 1 # 次が左足
for i in range(9):
tx = x + dxl[i]
ty = y + dyl[i]
if (0 <= tx < W) and (0 <= ty < H):
if ss[ty][tx] == 'S' or ss[ty][tx] == 'T':
cost = 0
elif ss[ty][tx] == 'X':
continue
else:
cost = int(ss[ty][tx])
lines[cal(x,y,1)].add((cal(tx,ty,0),cost))
weights = dijkstra(lines,N,S)
if weights[T] == INF:
print(-1)
else:
print(weights[T])
| 0 | PYTHON3 |
n=eval(input())
t=n
l=[0]
for i in range(2,int(n**0.5)+1):
while n%i==0:
n/=i
l.append(int(i))
if n>1 and n!=t:
l.append(int(n))
if (len(l)!=3):
try:
print("1\n{}".format(l[1]*l[2]))
except:
print("1\n0")
else:
print(2)
| 9 | PYTHON3 |
#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("avx")
using namespace std;
template <class T>
int getbit(T s, int i) {
return (s >> i) & 1;
}
template <class T>
T onbit(T s, int i) {
return s | (T(1) << i);
}
template <class T>
T offbit(T s, int i) {
return s & (~(T(1) << i));
}
template <class T>
int cntbit(T s) {
return __builtin_popcountll(s);
}
template <class T>
T gcd(T a, T b) {
T r;
while (b != 0) {
r = a % b;
a = b;
b = r;
}
return a;
}
template <class T>
T lcm(T a, T b) {
return a / gcd(a, b) * b;
}
template <class T>
inline int minimize(T& a, const T& val) {
return val < a ? a = val, 1 : 0;
}
template <class T>
inline int maximize(T& a, const T& val) {
return a < val ? a = val, 1 : 0;
}
mt19937 RNG(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int myrand() { return abs((int)RNG()); }
const int MAXN = 1e5 + 100;
const int MOD = 1e9 + 7;
const long long MAXV = 1e9;
const double eps = 1e-12;
const int INF = 2e9 + 100;
const long long INF_LL = 1e16;
inline string toStr(long long x) {
string tmp = "";
do tmp = char(x % 10 + '0') + tmp;
while (x /= 10);
return tmp;
}
inline long long toInt(string s) {
long long res = 0;
for (auto x : s) res = res * 10 + x - '0';
return res;
}
inline string toBinStr(long long x) {
string res = "";
do res = (x % 2 ? "1" : "0") + res;
while (x >>= 1LL);
return res;
}
long long rnd(int k) {
if (!k) return myrand() % MAXV + 1;
long long t = myrand() % MAXV + 1;
return (myrand() % t) + (MAXV - t);
}
long long random_gen(int sign) {
long long x = rnd(myrand() % 2);
long long s = myrand() % 2;
s = !s ? 1 : -1;
return sign == 1 ? x : sign == -1 ? -x : s * x;
}
int n;
vector<int> g[MAXN];
vector<std::pair<int, int> > edge;
int color[MAXN];
int deg[MAXN];
void dfs(int u) {
color[u] = 1;
for (auto v : g[u])
if (!color[v]) dfs(v);
}
bool retest() {
long long a = 0, b = 0, c = 0;
for (int u = (1), _b = (n); u <= _b; u++)
if (color[u] == 1)
++a;
else if (color[u] == 2)
++b;
else if (color[u] == 3)
++c;
if (!a || !b || !c) return false;
if (a + b + c != n) return false;
if (a * (b + c) + b * c != edge.size()) return false;
for (auto E : edge) {
int u = E.first, v = E.second;
if (color[u] == color[v]) return false;
}
return true;
}
int Ares_KN() {
int m;
cin >> n >> m;
while (m--) {
int u, v;
cin >> u >> v;
edge.emplace_back(u, v);
g[u].push_back(v), g[v].push_back(u);
++deg[u], ++deg[v];
}
for (int u = (1), _b = (n); u <= _b; u++)
if (deg[u] < 2) return !puts("-1");
int component = 0;
for (int u = (1), _b = (n); u <= _b; u++)
if (!color[u]) {
dfs(u);
++component;
}
if (component > 1) return !puts("-1");
for (int u = (1), _b = (n); u <= _b; u++) sort(g[u].begin(), g[u].end());
memset(color, 0, sizeof(color));
color[1] = 1;
for (int u = (2), _b = (n); u <= _b; u++)
if (!binary_search(g[1].begin(), g[1].end(), u)) color[u] = 1;
for (int u = (2), _b = (n); u <= _b; u++)
if (!color[u]) {
color[u] = 2;
for (int v = (1), _b = (n); v <= _b; v++)
if (!color[v])
if (!binary_search(g[u].begin(), g[u].end(), v)) color[v] = 2;
break;
}
for (int u = (2), _b = (n); u <= _b; u++)
if (!color[u]) {
color[u] = 3;
for (int v = (1), _b = (n); v <= _b; v++)
if (!color[v])
if (!binary_search(g[u].begin(), g[u].end(), v)) color[v] = 3;
break;
}
bool good = retest();
if (good)
for (int u = (1), _b = (n); u <= _b; u++) printf("%d ", color[u]);
else
puts("-1");
return 0;
}
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
Ares_KN();
cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
int getint() {
unsigned int c;
int x = 0;
while (((c = getchar()) - '0') >= 10) {
if (c == '-') return -getint();
if (!~c) exit(0);
}
do {
x = (x << 3) + (x << 1) + (c - '0');
} while (((c = getchar()) - '0') < 10);
return x;
}
int n, in[1111];
int xs[1111], ys[1111];
const int base = 1111;
int grid[3333][3333];
int main() {
int i, j, tcc, tc = 1 << 28;
for (tcc = 0; tcc < tc; tcc++) {
xs[0] = ys[0] = 0;
for (n = getint(), i = 0; i < n; i++) {
in[i] = getint();
xs[i + 1] = xs[i] + in[i];
int s = (i & 1) ? -1 : 1;
ys[i + 1] = ys[i] + in[i] * s;
}
memset(grid, 0, sizeof(grid));
for (i = 1; i < n + 1; i++) {
int sx = (((xs[i] - xs[i - 1]) > 0) ? 1 : -1);
int sy = (((ys[i] - ys[i - 1]) > 0) ? 1 : -1);
char dir = '/';
if (sy < 0) dir = '\\';
for (int x = xs[i - 1], y = ys[i - 1]; x < xs[i]; x += sx, y += sy) {
if (sy > 0) grid[-y + base][x] = dir;
if (sy < 0) grid[-y + base + 1][x] = dir;
}
}
int last = 0;
for (i = 0; i < 3333; i++)
for (j = 0; j < 3333; j++) {
if (grid[i][j]) last = max(last, j);
}
for (i = 0; i < 3333; i++) {
int draw = 0;
for (j = 0; j < 3333; j++)
if (grid[i][j]) {
draw = 1;
break;
}
if (draw == 0) continue;
for (j = 0; j <= last; j++) {
if (grid[i][j])
putchar(grid[i][j]);
else
putchar(' ');
}
puts("");
}
}
return 0;
}
| 9 | CPP |
// Author: Utkarsh Pandey
#include<bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
string s;
cin>>s;
map<char,int> ma;
int flag = 1;
for(int i = 0;i<n;i++)
{
if(ma[s[i]] == 0)
{
ma[s[i]] = 1;
}
if(ma[s[i]] == -1)
{
flag = 0;
break;
}
if(i)
{
if(s[i] != s[i-1])
{
ma[s[i-1]] = -1;
}
}
}
if(flag) cout << "YES\n";
else cout << "NO\n";
}
} | 7 | CPP |
if __name__ == "__main__":
n = int(input())
for i in range(n):
tam = int(input())
numeros = list(map(int,input().split()))
glo = numeros[tam-1]
count = 0
for j in range(tam-2,-1,-1):
if numeros[j] > glo:
count += 1
glo = min(glo,numeros[j])
print(count)
| 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, b = 0;
string a[10], x[101];
cin >> n >> x[0];
for (int i = 1; i < n; i++) {
cin >> x[i];
if (x[i] == x[0]) b++;
}
b++;
if (b > n / 2) {
cout << x[0];
return 0;
}
for (int i = 0; i < n; i++) {
if (x[i] != x[0]) {
cout << x[i];
return 0;
}
}
return 0;
}
| 7 | CPP |
import math
x, y = input().split(" ")
x = int(x)
y = int(y)
x1 = y * math.log(x)
y1 = x * math.log(y)
if x1 == y1:
print("=")
elif x1 < y1:
print("<")
else:
print(">")
| 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int INF = int(1e9);
const double EPS = 1e-8;
struct debugger {
template <typename T>
debugger& operator,(const T& v) {
cerr << v << " ";
return *this;
}
} dbg;
int cols[5001], rows[5001];
int tcols[5001], trows[5001];
int main() {
std::ios_base::sync_with_stdio(false);
int n, m, k;
scanf("%d%d%d", &n, &m, &k);
vector<int> xs, ys;
vector<pair<int, pair<int, int> > > ins;
for (int it = 0; it < k; it++) {
int typ, id, col;
scanf("%d%d%d", &typ, &id, &col);
id--;
ins.emplace_back(typ, pair<int, int>(id, col));
if (typ == 1) {
xs.push_back(id);
} else {
ys.push_back(id);
}
}
sort(xs.begin(), xs.end());
xs.erase(unique(xs.begin(), xs.end()), xs.end());
sort(ys.begin(), ys.end());
ys.erase(unique(ys.begin(), ys.end()), ys.end());
int nn = (int)xs.size(), mm = (int)ys.size();
for (int it = 0; it < k; it++) {
pair<int, pair<int, int> > p = ins[it];
if (p.first == 1) {
int id = lower_bound(xs.begin(), xs.end(), p.second.first) - xs.begin();
rows[id] = p.second.second;
trows[id] = it;
} else {
int id = lower_bound(ys.begin(), ys.end(), p.second.first) - ys.begin();
cols[id] = p.second.second;
tcols[id] = it;
}
}
vector<int> revx(n, -1), revy(m, -1);
for (int id = 0; id < nn; id++) {
revx[xs[id]] = id;
}
for (int id = 0; id < mm; id++) {
revy[ys[id]] = id;
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
int c = 0;
int x = revx[i], y = revy[j];
if (x != -1 && y != -1) {
if (trows[x] > tcols[y])
c = rows[x];
else
c = cols[y];
} else if (x != -1) {
c = rows[x];
} else if (y != -1) {
c = cols[y];
}
cout << c << " ";
}
cout << "\n";
}
return 0;
}
| 8 | CPP |
#!/usr/bin/python3
import sys
def compress(l):
x = l[0]
cnt = 1
c = []
for i in range(1, len(l)):
if l[i] == x:
cnt += 1
else:
c.append((x, cnt))
x = l[i]
cnt = 1
c.append((x, cnt))
return c
if __name__ == '__main__':
n = int(sys.stdin.readline())
a = [int(x) for x in sys.stdin.readline().split()]
a.sort()
a = compress(a)
dp = [0, a[0][0] * a[0][1]]
for i in range(1, len(a)):
x, c = a[i]
px = a[i-1][0]
dp.append(max(dp[-1], x*c + (dp[-1] if x > px + 1 else dp[-2])))
print(max(dp))
| 9 | PYTHON3 |
l=input()
l=l.split()
l=[int(i) for i in l]
l1=input()
l1=l1.split()
l1=[int(i) for i in l1]
a=l1[l[1]-1]
count=0
for i in l1:
if(i>0 and i>=a):
count+=1
print(count)
| 7 | PYTHON3 |
n=int(input())
l,r,ans=[],[],0
for i in range(n):
x,y=map(int,input().split())
l.append(x)
r.append(y)
for i in range(n):
p=l[i]
ans+=r.count(p)
if(l[i]==r[i]):
ans-=1
print(ans) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int inf = (1ll << 31) - 1;
int n, m;
double logg[1005];
double sum[1005];
double c[1005][1005];
int temp[1005];
void init() {
c[0][0] = 1;
for (int i = 1; i <= 1000; ++i) {
c[i][0] = 1;
for (int j = 1; j <= i; ++j) c[i][j] = c[i - 1][j] + c[i - 1][j - 1];
}
}
vector<int> eg[1005];
int v[1005], tot;
int cmp(int a, int b) { return a > b; }
double chose[1005][1005], gl[1005][1005];
int main() {
init();
int tt, k;
tot = 0;
scanf("%d%d", &n, &m);
for (int i = 1; i <= m; ++i) {
scanf("%d", &k);
for (int j = 0; j < k; ++j) {
scanf("%d", &tt);
eg[i].push_back(tt);
v[tot++] = tt;
}
}
sort(v, v + tot, cmp);
chose[0][0] = 1;
gl[0][0] = 1;
int mo, d;
for (int i = 1; i <= m; ++i) {
mo = 0;
d = 0;
int has = eg[i].size();
for (int j = 0; j < has; ++j)
if (eg[i][j] == v[n - 1])
d++;
else if (eg[i][j] > v[n - 1])
mo++;
for (int j = n; j >= mo; --j) {
for (int k = 0; k <= d; ++k) {
chose[i][j] += chose[i - 1][j - mo - k];
gl[i][j] += gl[i - 1][j - mo - k] / c[has][mo + k];
}
}
}
printf("%.9lf\n", gl[m][n] / chose[m][n]);
return 0;
}
| 11 | CPP |
#include <cstdio>
#include <cstring>
#include <algorithm>
#define MAXN 2010
using namespace std;
int n,m;
int a[MAXN][MAXN],b[MAXN],s[MAXN];
int p[MAXN][2];
void sort(){
static int cnt[MAXN];
memset(cnt,0,sizeof cnt);
for(int i=1;i<=m;i++) cnt[b[i]]++;
for(int i=1;i<=n+1;i++) cnt[i]+=cnt[i-1];
for(int i=m;i>=1;i--) s[cnt[b[i]]--]=i;
}
int gao(int l){
for(int i=1;i<=m;i++)
if(a[l][i]) b[i]=l+1;
sort();
memset(p,0,sizeof p);
int res=0;
for(int i=1;i<=m;i++){
int x=s[i];
p[x][0]=p[x][1]=x;
if(p[x-1][0]){
p[p[x-1][0]][1]=p[x][1];
p[x][0]=p[p[x][1]][0]=p[x-1][0];
}
if(p[x+1][1]){
p[p[x+1][1]][0]=p[x][0];
p[x][1]=p[p[x][0]][1]=p[x+1][1];
}
res=max(res,(l-b[x]+2)*(p[x][1]-p[x][0]+2));
}
return res;
}
int main(){
#ifdef DEBUG
freopen("F.in","r",stdin);
#endif
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++){
static char str[MAXN];
scanf("%s",str+1);
for(int j=1;j<=m;j++)
if(str[j]=='#')
a[i][j]=1;
}
for(int i=1;i<n;i++)
for(int j=1;j<m;j++)
a[i][j]=a[i][j]^a[i+1][j]^a[i][j+1]^a[i+1][j+1];
int ans=max(n,m);
n--; m--;
for(int i=1;i<=m;i++) b[i]=1;
for(int i=1;i<=n;i++)
ans=max(ans,gao(i));
printf("%d\n",ans);
return 0;
}
| 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 508;
char d[N];
int n, m, c[N][N], a[N][N];
int b[N][N];
int out(int x, int y) {
int i, p, q;
for (p = x, q = y; p < q; p++, q--) d[q] = d[p];
for (i = x; i <= y; i++) printf("%c", d[i]);
return 0;
}
int dfs(int x, int y) {
if (y == 1) {
out(1, x);
printf("+");
return 0;
}
dfs(b[x][y], y - 1);
out(b[x][y] + 1, x);
printf("+");
return 0;
}
int main(void) {
int i, j, k, p, q;
scanf("%s%d", d + 1, &m);
n = strlen(d + 1);
for (i = 1; i <= n; i++)
for (j = i; j <= n; j++) {
k = 0;
for (p = i, q = j; p < q; p++, q--) k += (d[p] != d[q]);
c[i][j] = k;
}
for (i = 1; i <= n; i++) a[i][1] = c[1][i];
for (k = 2; k <= m; k++)
for (i = 1; i <= n; i++) {
a[i][k] = N;
for (j = 1; j < i; j++)
if (a[j][k - 1] + c[j + 1][i] < a[i][k]) {
a[i][k] = a[j][k - 1] + c[j + 1][i];
b[i][k] = j;
}
}
k = 1;
for (i = 2; i <= m; i++)
if (a[n][k] > a[n][i]) k = i;
printf("%d\n", a[n][k]);
if (k > 1) dfs(b[n][k], k - 1);
out(b[n][k] + 1, n);
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
priority_queue<int, vector<int>, greater<int> > Q;
const int INF = 1e9 + 9;
long int pow(long int a, long int b, int m) {
a %= m;
long long res = 1;
while (b > 0) {
if (b & 1) res = res * a % m;
a = a * a % m;
b >>= 1;
}
return res;
}
int main() {
int n;
cin >> n;
int ar[n + 5];
for (int i = 1; i <= n; i++) {
cin >> ar[i];
}
int ans[n + 5];
for (int i = 1; i <= n; i++) {
ans[i] = i;
}
int k = 0, c = 0;
int ind = 0;
int si = 0;
for (int i = 1; i <= n; i++) {
if (ar[i] != ans[i]) {
c++;
si = i;
for (k = i; k <= n; k++, i++) {
if (ar[k + 1] > ar[k]) {
ind = k;
break;
}
}
}
}
if (c > 1) {
cout << 0 << " " << 0 << endl;
}
bool flag = true;
for (int j = k + 1; j <= ind; j++) {
if (ar[j] != ar[j - 1] - 1) {
flag = false;
cout << 0 << " " << 0 << endl;
return 0;
}
}
if (flag and c == 1) {
cout << si << " " << ind << endl;
}
if (c == 0) {
cout << 0 << " " << 0 << endl;
}
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int n = s.length();
int ans = 0;
int m = 1;
for (int i = 1; i < n; i++) {
if (s[i] == s[i - 1])
m++;
else {
if (m % 2 == 0) ans++;
m = 1;
}
}
if (m != 1 && m % 2 == 0) ans++;
cout << ans << "\n";
return 0;
}
| 7 | CPP |
import sys
from collections import deque
def do():
a2i = lambda x: ord(x) - ord("a")
n, m = map(int, input().split())
s = input()
target = input()
posAlphas = [deque([]) for _ in range(26)]
loc = [None] * m
cur = 0
for i in range(m):
while s[cur] != target[i]:
cur += 1
loc[i] = cur
cur += 1
res = -1
for i in range(m-1):
res = max(res, loc[i+1] - loc[i])
curMax = 10 ** 9
for i in range(n):
val = a2i(s[i])
posAlphas[val].append(i)
for i in range(m-1, 0, -1):
curLoc = loc[i]
curChar = a2i(target[i])
while len(posAlphas[curChar]) > 0:
canPos = posAlphas[curChar].pop()
if curMax <= canPos:
continue
if canPos <= curLoc:
break
loc[i] = canPos
break
curMax = loc[i]
res = max(res, loc[i] - loc[i - 1])
print(res)
do()
| 9 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int M[n][2];
for (int i = 0; i < n; i++) {
cin >> M[i][1] >> M[i][2];
}
int k = 0;
vector<int> v1, v2;
for (int i = 0; i < n; i++) {
double inf = M[i][1] + 0.5, sup = M[i][2] - 0.5;
for (int j = 0; j < n; j++) {
if (((M[j][1] - inf) * (M[j][2] - inf) < 0 or
(M[j][1] - sup) * (M[j][2] - sup) < 0) and
i != j) {
v1.push_back(i);
v2.push_back(j);
k++;
}
}
}
if (k == 0) {
cout << n << endl;
for (int i = 0; i < n; i++) {
cout << i + 1 << " ";
}
} else {
int o1 = 1, o2 = 1;
int my = v1[0], mn = v2[0];
if (v1[0] < v2[0]) {
my = v2[0];
mn = v1[0];
}
for (int i = 0; i < k; i++) {
if ((v1[i] - my) * (v2[i] - my) != 0) {
o1 = 0;
}
if ((v1[i] - mn) * (v2[i] - mn) != 0) {
o2 = 0;
}
}
cout << o1 + o2 << endl;
if (o2) {
cout << mn + 1 << " ";
}
if (o1) {
cout << my + 1 << " ";
}
}
}
| 9 | CPP |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX_N = 44;
int N;
ll _F[MAX_N][MAX_N][MAX_N];
char A[MAX_N][MAX_N];
ll F(int l, int i, int r) {
ll &res = _F[l][i][r];
if (res != -1) return res;
if (l == r) return res = 1;
if (r - l & 1) return res = 0;
res = 0;
for (int j = l; j < i; j++) {
for (int k = i + 1; k <= r; k++) {
if (A[j][k] != '1') continue;
for (int p = j; p < i; p++) {
for (int q = i + 1; q <= k; q++) {
res += F(l, j, p) * F(q, k, r) * F(p + 1, i, q - 1);
}
}
}
}
return res;
}
int main() {
scanf("%d", &N);
for (int i = 1; i <= 2 * N; i++) scanf("%s", A[i] + 1);
memset(_F, -1, sizeof(_F));
ll ans = 0;
for (int i = 2; i <= 2 * N; i++) {
if (A[1][i] != '1') continue;
ans += F(2, i, 2 * N);
}
printf("%lld\n", ans);
}
| 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
for (int p = 0; p < t; p++) {
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; i++) {
int x;
cin >> x;
a[i] = x;
}
sort(a, a + n);
int i = n - 1;
int l = 0;
for (int i = 0; i < n; i++) {
if (a[i] <= i + 1 || a[i] <= i) l = i + 1;
}
cout << l + 1 << endl;
}
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
inline bool isvowel(char c) {
c = tolower(c);
if (c == 'a' || c == 'e' || c == 'i' || c == 'y' || c == 'o' || c == 'u')
return 1;
return 0;
}
const double eps = 0.000001;
const long double pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const long long MOD = 1e18 + 9;
const long long INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 1e6 + 123;
const int M = 22;
const int pri = 997;
const int Magic = 2101;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
int n, m, k;
int cnt[N];
string s;
int a[N];
vector<int> g[N];
int u[N];
long long ans, res;
void dfs(int v) {
u[v] = 1;
for (auto to : g[v]) {
if (to > v) {
res += to / v * 2;
} else {
res += v / to * 2;
}
if (!u[to]) dfs(to);
}
}
int main() {
cin >> n;
for (int i = 2; i <= n; i++) {
for (int j = i + i; j <= n; j += i) {
g[i].push_back(j);
g[j].push_back(i);
}
}
for (int i = 1; i <= n; i++) {
if (!u[i]) {
res = 0;
dfs(i);
ans = max(ans, res);
}
}
cout << ans << '\n';
return 0;
}
| 10 | CPP |
def main():
inp = input().split()
n = int(inp[0])
k = int(inp[1])
mySet = set()
for i in range(1, min(k + 1, 50)):
rem = n % i
if rem in mySet:
print("No")
exit(0)
mySet.add(rem)
print("Yes")
if __name__ == "__main__":
main()
| 9 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100100;
int n;
char s[maxn];
int ret;
int main() {
scanf("%d", &n);
scanf("%s", s);
ret = 3;
for (int i = (1); i < (n); i++) ret += (s[i] != s[i - 1]);
if (ret > n) ret = n;
printf("%d\n", ret);
return 0;
}
| 9 | CPP |
t=int(input())
for i in range(t):
n,k=map(int,input().split())
for j in range(2,n+1):
if n%j==0:
print(n+j+2*(k-1))
break
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int p[3000], v[3000];
int main(void) {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &p[i]);
if (p[i] == -1)
v[i] = 0;
else
v[i] = p[i];
}
int th = 0, max = 0;
for (int i = 1; i <= n; i++) {
th = 1;
int t = v[i];
while (t) {
t = v[t];
th++;
}
max = max > th ? max : th;
}
printf("%d\n", max);
return 0;
}
| 7 | CPP |
def main():
t = 1
for _ in range(t):
n = int(input())
tab = list(map(int,input().split()))
inc = 0
nb_dup = 0
nb_pp = 0
tab.sort()
l = -1
for x in range(n):
if tab[x] == l:
nb_dup += 1
else:
inc += 0
nb_pp += nb_dup
nb_dup = 1
if nb_pp > 0:
inc += 1
nb_pp -= 1
l = tab[x]
print(inc)
main() | 9 | PYTHON3 |
#include<bits/stdc++.h>
using namespace std;
char S[8][10][10]={
{},{},{},{},
{
"aaca",
"bbca",
"acbb",
"acaa"
},
{
"aabba",
"bcc.a",
"b..cb",
"a..cb",
"abbaa"
},
{
"aabc..",
"ddbc..",
"..aabc",
"..ddbc",
"bc..aa",
"bc..dd"
},
{
"aabbcc.",
"dd.dd.a",
"..d..da",
"..d..db",
"dd.dd.b",
"..d..dc",
"..d..dc"
}
};
char s[1005][1005];
void solve(int &x,int N){
for(int i=0;i<N;++i)
for(int j=0;j<N;++j)
s[x+i][x+j]=S[N][i][j];
x+=N;
}
int main(){
int n;
cin>>n;
if(n<=2) return puts("-1"),0;
if(n<=3) return puts("add"),puts("a.c"),puts("bbc"),0;
int tmp=1;
for(int i=1;i<=n;++i)
for(int j=1;j<=n;++j)
s[i][j]='.';
solve(tmp,n%4+4);
while(tmp<=n) solve(tmp,4);
for(int i=1;i<=n;++i,puts(""))
for(int j=1;j<=n;++j)
cout<<s[i][j];
return 0;
} | 0 | CPP |
a = list(str(input()))
b = list(str(input()))
ans = []
for x, y in zip(a,b):
if int(x)== int(y):
ans.append('0')
else:
ans.append("1")
print ("".join(ans)) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
string s;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> s;
if (s.size() > 10)
cout << s.at(0) << s.size() - 2 << s.at(s.size() - 1) << endl;
else
cout << s << endl;
}
}
| 7 | CPP |
a=int(input())
i=0
b=[]
while i in range(a):
b.append(int(input()))
i+=1
r=len(b)
o=0
u=[]
while o in range(r):
if b[o]==180:
print('NO')
else:
g=360/(180-b[o])
if int(g)==g :
print('YES')
else:
print('NO')
o+=1
| 7 | PYTHON3 |
A,B=map(int,input().split())
X=[A+B,A-B,A*B]
print(max(X)) | 0 | PYTHON3 |
s = input()
s = s.split('S')
print(max([len(i) for i in s])) | 0 | PYTHON3 |
n = int(input())
b = 0
o = 0
while b < n:
b += 1
x = input()
if "++" in x:
o += 1
elif "-" in x:
o -= 1
elif "X" in x:
o = o
else:
break
print(o) | 7 | PYTHON3 |
n,a,b = map(int,input().split())
if abs(b-a) % 2 == 0:
print('Alice')
else:
print('Borys') | 0 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
double ans = 0;
int n;
cin >> n;
int p;
cin >> p;
vector<int> L, R;
for (int i = 0 - (0 > n); i != n - (0 > n); i += 1 - 2 * (0 > n)) {
int l, r;
cin >> l >> r;
L.push_back(l);
R.push_back(r);
}
L.push_back(L[0]);
R.push_back(R[0]);
for (int i = 0 - (0 > n); i != n - (0 > n); i += 1 - 2 * (0 > n)) {
int l, r;
int ll, rr;
l = L[i];
r = R[i];
ll = L[i + 1];
rr = R[i + 1];
int u = r / p - (l - 1) / p;
int uu = rr / p - (ll - 1) / p;
ans += 2000.0 * (1.0 * u / (r - l + 1) + (1.0 - 1.0 * u / (r - l + 1)) *
(1.0 * uu / (rr - ll + 1)));
}
cout << setprecision(15) << ans << "\n";
return 0;
}
| 9 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100100;
int n, m;
char a[202][202], b[202][202], ans[202][202];
void show() {
for (int i = 0; i < m; i++) {
cout << '\n';
for (int j = 0; j < n; j++) cout << b[i][j];
}
cout << '\n';
}
int main() {
cin >> m >> n;
for (int i = 0; i < n; i++) {
string s;
cin >> s;
for (int j = 0; j < m; j++) a[i][j] = s[j];
}
for (int i = 0; i < m; i++)
for (int j = 0; j < n; j++) b[i][j] = a[n - 1 - j][i];
swap(n, m);
for (int i = 0; i < n; i++)
for (int j = 0; j < m / 2; j++) swap(b[i][j], b[i][m - 1 - j]);
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
ans[2 * i][2 * j] = ans[2 * i][2 * j + 1] = ans[2 * i + 1][2 * j] =
ans[2 * i + 1][2 * j + 1] = b[i][j];
for (int i = 0; i < 2 * n; i++) {
for (int j = 0; j < 2 * m; j++) cout << ans[i][j];
cout << '\n';
}
return 0;
}
| 7 | CPP |
R = lambda : list(map(int, input().split()))
n,a,s = R(),R(),0
for x in a:
s+=x
if s:
print("YES\n1\n1 "+str(len(a)))
else:
p,f=0,0
for i in range(len(a)):
p+=a[i]
if(p!=0 and not f):
print("YES\n2\n1 %d\n%d %d" % (i+1, i+2, len(a)))
f=1
if not f:
print("NO")
| 7 | PYTHON3 |
#include <bits/stdc++.h>
char str[1000005];
int main() {
int cntx = 0, cnty = 0;
scanf("%s", str);
int n = strlen(str);
for (int i = 0; i < n; i++) {
if (str[i] == 'x')
cntx++;
else
cnty++;
}
if (cntx < cnty) {
for (int i = 0; i < cnty - cntx; i++) printf("y");
} else {
for (int i = 0; i < cntx - cnty; i++) printf("x");
}
}
| 8 | CPP |
for i in range(int(input())):
am = int(input())
arr = list(map(int,input().split()))
print(am - (am - len(set(arr)))) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
long long mod = 998244353;
int n, m, t, k;
int a[maxn];
struct dp {
queue<long long> q;
long long sum;
int push(long long x) {
sum = (sum + x) % mod;
q.push(x);
if (q.size() >= m) {
sum = (sum - q.front() + mod) % mod;
q.pop();
}
return 0;
}
int clear() {
int i, j;
sum = 0;
queue<long long> empty;
swap(q, empty);
return 0;
}
dp() { sum = 0; }
};
dp f[5];
int read() {
int x;
scanf("%d", &x);
return x;
}
int main() {
int i, j;
long long sum;
long long ans = 0;
int x, y = -1;
queue<int> q;
n = read();
k = read();
m = read();
for (i = 1; i <= n; i++) {
a[i] = read();
if (a[i] != -1) {
q.push(a[i]);
}
}
if (a[1] == -1) {
f[0].push(k);
f[1].push(1);
} else {
f[0].push(1);
x = q.front();
q.pop();
if (q.size() >= 1) {
if (q.front() == x) {
f[1].push(1);
} else {
f[1].clear();
}
}
}
for (i = 2; i <= n; i++) {
sum = f[0].sum;
if (a[i] == -1) {
f[0].push(sum * (long long)(k - 1) % mod);
f[1].push((sum - f[1].sum + mod) % mod);
} else {
x = q.front();
q.pop();
f[1].push((sum - f[1].sum + mod) % mod);
f[0] = f[1];
if (q.size() >= 1) {
if (q.front() != x) {
f[1].clear();
}
}
}
}
ans = f[0].sum;
printf("%lld\n", ans);
return 0;
}
| 12 | CPP |
t=int(input())
for h in range(t):
n=int(input())
A=list(map(int,input().split()))
if n%2==0:
for k in range(0,n,2):
print(A[k+1],-A[k],end=' ')
print('')
else:
a=1
c=A[-1]
x=A[-2]
z=A[-3]
if A[-1]==A[-2]:
if A[-2]==A[-3]:
a=3
else:
a=2
for k in range(0,n-3,2):
print(A[k+1],-A[k],end=' ')
if a==1:
print(x-c,-z,z)
elif a==2:
print(x,c-z,-x)
elif a==3:
print(-2*x,x,x)
| 10 | PYTHON3 |
# roundoff x to the closest multiple of n
def roundoff(x, n):
remainder = x % n
roundoff_remainder = int((remainder + n/2) // n)
return x // n + roundoff_remainder
def abs(n):
if n < 0:
n = -n
return n
x = int(input())
# steps = [5, 4, 3, 2 , 1]
# count = 0
# for step in steps:
# if (x < step):
# continue
# count += roundoff(x, step)
# x = abs(x - roundoff(x, step) * step)
if x > 5:
if x % 5:
print(x//5 + 1)
else:
print(x//5)
else:
print(1)
# print(count)
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
double f[2100][2100];
bool bo[2100][2100];
int A[2100], B[2100], x, y, n, m, i;
double work(int i, int j) {
if (i > n || j > n) return 0;
if (i == n && j == n) return 0;
if (bo[i][j]) return f[i][j];
bo[i][j] = 1;
f[i][j] = ((work(i + 1, j) * (n - i) * j + work(i, j + 1) * i * (n - j) +
work(i + 1, j + 1) * (n - i) * (n - j)) /
n / n +
1) /
(1 - 1.0 * i * j / n / n);
return f[i][j];
}
int main() {
scanf("%d%d", &n, &m);
for (i = 1; i <= m; ++i) {
scanf("%d%d", &x, &y);
A[x] = 1;
B[y] = 1;
}
x = y = 0;
for (i = 1; i <= n; ++i)
if (A[i]) x++;
for (i = 1; i <= n; ++i)
if (B[i]) y++;
printf("%lf\n", work(x, y));
}
| 8 | CPP |
n = int(input())
# 7 options = 6
# 20 options != 6
mod = 1000000007
def expmod(a, b, m):
res = 1%m
a %= m
while (b):
if (b % 2 == 1):
res = (res * a) % m
a = (a*a)%m
b = b // 2
return res
result = 0
for x in range(n):
result = (20 * expmod(7, x, mod) + 27 * result) % mod
print(result)
| 8 | PYTHON3 |
if __name__ == '__main__':
a=['H','Q','9']
n=input()
for i in a:
if i in n:
print("YES")
exit()
print("NO")
| 7 | PYTHON3 |
#include<bits/stdc++.h>
using namespace std;
int cnt;
void insertionSort(int *A,int n,int g){
for(int i=g;i<n;i++){
int v=A[i];
int j=i-g;
while(j>=0&&A[j]>v){
A[j+g]=A[j];
j=j-g;
cnt++;
}
A[j+g]=v;
}
}
void shellSort(int A[],int n){
cnt=0;
int r=1;
vector<int> G;
while(r<=n){
G.push_back(r);
r=2*r+1;
}
int m=G.size();
reverse(G.begin(),G.end());
cout<<m<<endl;
for(int i=0;i<m;i++) cout<<G[i]<<" \n"[i==m-1];
for(int i=0;i<m;i++) insertionSort(A,n,G[i]);
cout<<cnt<<endl;
}
signed main(){
int n;
cin>>n;
int A[n];
for(int i=0;i<n;i++) cin>>A[i];
shellSort(A,n);
for(int k=0;k<n;k++) cout<<A[k]<<endl;
return 0;
}
| 0 | CPP |
from math import log2,ceil
for i in range(int(input())):
n=int(input())
ind=ceil(log2(n))
j=4
while(j<=n):
if(n%(j-1)==0):
break
else:
j*=2
print(n//(j-1))
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
long long int mod_expo(long long int MOD, long long int a, long long int b) {
long long int ans = 1;
while (b) {
if (b % 2) {
ans *= a;
ans %= MOD;
}
b /= 2;
a *= a;
a %= MOD;
}
return ans % MOD;
}
void display(vector<int> v1) {
for (int i = 0; i < v1.size(); i++) {
cout << v1[i] << " ";
}
cout << endl;
}
int dx[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int dy[8] = {1, 0, -1, 0, 1, -1, 1, -1};
using namespace std;
const int M = 100000 + 10;
struct EDGE {
int u, v, w, rampid;
EDGE() {}
EDGE(int u, int v, int w, int rampid) : u(u), v(v), w(w), rampid(rampid) {}
};
struct RAMP {
int x, d, t, p;
} ramp[M];
int a[3 * M];
vector<EDGE> adj[3 * M];
long long int dis[3 * M];
int visited[3 * M];
pair<int, int> par[3 * M];
struct NODE {
long long int val;
int id;
NODE() {}
NODE(long long int val, int id) : val(val), id(id) {}
bool operator<(const NODE& x) const { return val > x.val; }
};
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, L;
cin >> n >> L;
for (int i = 0; i < n; i++) {
cin >> ramp[i].x >> ramp[i].d >> ramp[i].t >> ramp[i].p;
}
a[0] = 0;
a[1] = L;
int len = 2;
for (int i = 0; i < n; i++) {
int pos1 = ramp[i].x - ramp[i].p;
int pos2 = ramp[i].x + ramp[i].d;
if (pos1 >= 0) {
a[len++] = pos1;
}
a[len++] = pos2;
}
sort(a, a + len);
int m = unique(a, a + len) - a;
for (int i = 0; i < n; i++) {
int pos1 = ramp[i].x - ramp[i].p;
int pos2 = ramp[i].x + ramp[i].d;
if (pos1 >= 0) {
int id1 = lower_bound(a, a + m, pos1) - a;
int id2 = lower_bound(a, a + m, pos2) - a;
EDGE edge(id1, id2, ramp[i].p + ramp[i].t, i + 1);
adj[id1].push_back(edge);
}
}
for (int i = 0; i < m - 1; i++) {
int id1 = i;
int id2 = i + 1;
int dis = a[id1] - a[id2];
dis = (dis < 0 ? -dis : dis);
EDGE edge1(id1, id2, dis, 0);
adj[id1].push_back(edge1);
EDGE edge2(id2, id1, dis, 0);
adj[id2].push_back(edge2);
}
for (int i = 0; i < m; i++) {
dis[i] = 1e+18;
}
dis[0] = 0;
visited[0] = 1;
par[0].first = -1;
par[0].second = 0;
priority_queue<NODE> Q;
NODE node(0, 0);
Q.push(node);
while (!Q.empty()) {
NODE node = Q.top();
Q.pop();
long long int val = node.val;
int id = node.id;
if (dis[id] == val) {
visited[id] = 1;
for (vector<EDGE>::iterator it = adj[id].begin(); it != adj[id].end();
it++) {
int nextid = (*it).v;
int nextw = (*it).w;
long long int nextdis = dis[id] + nextw;
if (nextdis < dis[nextid]) {
dis[nextid] = nextdis;
par[nextid] = make_pair(id, (*it).rampid);
NODE inode(dis[nextid], nextid);
Q.push(inode);
}
}
}
}
cout << dis[m - 1] << endl;
int id = m - 1;
int num = 0;
vector<int> ans;
while (id != 0) {
if (par[id].second != 0) {
num++;
ans.push_back(par[id].second);
}
id = par[id].first;
}
cout << num << endl;
for (int i = num - 1; i >= 0; i--) {
cout << ans[i];
if (i > 0) {
cout << " ";
} else {
cout << endl;
}
}
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int M = 1e9 + 7;
int n;
const int N = 2e5 + 5;
vector<int> adj[N];
int sz[N];
long long dp[N];
long long ans[N];
void dfs(int i, int p) {
sz[i] = 1;
for (int j : adj[i]) {
if (j != p) {
dfs(j, i);
sz[i] += sz[j];
dp[i] += dp[j];
}
}
dp[i] += sz[i];
}
long long res = 0;
void dfs2(int i, int p) {
if (p == -1) {
ans[i] = dp[i];
} else {
ans[i] = ans[p] - sz[i] - dp[i] + n;
for (int j : adj[i]) {
if (j != p) {
ans[i] += dp[j];
}
}
}
res = max(res, ans[i]);
for (int j : adj[i]) {
if (j != p) {
dfs2(j, i);
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
int u, v;
for (int i = 0; i < n - 1; ++i) {
cin >> u >> v;
--u;
--v;
adj[u].push_back(v);
adj[v].push_back(u);
}
dfs(0, -1);
dfs2(0, -1);
cout << res << "\n";
return 0;
}
| 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
int f[3];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int tt;
cin >> tt;
while (tt--) {
int n;
cin >> f[0] >> f[1] >> n;
f[2] = f[0] ^ f[1];
cout << f[n % 3] << '\n';
}
return 0;
}
| 7 | CPP |
#include <iostream>
#include <string>
using namespace std;
int main()
{
int n, ans=0, len, c;
string s, name[110], t;
cin>>n>>s;
for (int i=0; i<n; i++) cin>>name[i];
for (int i=0; i<n; i++)
{
len=name[i].size();
for (int j=1; j<51; j++)
{
for (int k=0; k<len; k++)
{
t=""; c=0;
for (int l=k; l<len && c<s.size(); l+=j)
{
if (l<len) { t+=name[i][l]; c++; }
}
if (t==s) { ans++; k=200; j=60; }
}
}
}
cout<<ans<<'\n';
return 0;
}
| 0 | CPP |
def main():
mode="filee"
if mode=="file":f=open("test.txt","r")
get = lambda :[int(x) for x in (f.readline() if mode=="file" else input()).split()]
[a,b,c]=get()
ans = min(a+b+c,2*(a+c),2*(b+c),2*(a+b))
print(ans)
if mode=="file":f.close()
if __name__=="__main__":
main()
| 7 | PYTHON3 |
#!/mnt/c/Users/moiki/bash/env/bin/python
# N,M = map(int, input().split())
w,h,nw,nh = map(int, input().split())
ans = w*2 + h*2 + 4
ans -= nw
ans += nw*2 + (nh-1) * 2 + 4
ans -= (nw+2)
print(ans)
| 7 | PYTHON3 |
a = list(input())
flag = True
i=0
if(len(a)<=2):
if(len(a)==1):
if(a[0]!='1'):
flag = False
else:
if(a[0]=='1' and (a[1]=='4' or a[1]=='1')):
flag = True
else:
flag = False
else:
while(i<len(a)):
# print(i)
if(a[i]=='1' and i<len(a)):
if(i<len(a)-1 and a[i+1]=='4'):
if(i<len(a)-2 and a[i+2]=='4'):
i=i+3
# print("1::", i)
else:
i=i+2
# print("2::", i)
else:
i=i+1
# print("3::", i)
else:
flag = False
break
if(flag == False):
print("NO")
else:
print("YES") | 7 | PYTHON3 |
def go():
n, m = map(int, input().split(' '))
half = (n + 1) // 2
if m >= half:
return n - m
if m == 0:
return 1
return m
print(go())
| 7 | PYTHON3 |
def ok(a, b):
diffs = 0
for i in range(len(a)):
if a[i] != b[i]:
diffs += 1
if diffs > 1:
return False
return True
def findInStrings(ind, ch, strs):
for s in strs:
if s[ind] == ch:
return s
for _ in range(int(input())):
n, m = map(int, input().split())
''''''
strings = []
for _ in range(n):
strings.append(input())
chars = {}
for i in range(m):
cs = set(s[i] for s in strings)
chars[i] = cs
ans = ''
done = False
for i in range(m):
ss = chars[i]
#print(ss)
if len(ss) == 1:
ans += list(ss)[0]
else:
possible = False
r = ''
o = list(ss)
for q, c in enumerate(o):
#print(q,c,o)
cand = findInStrings(i, o[int(not q)], strings)
#print(c, cand)
candd = list(cand)
candd[i] = c
cand = ''.join(candd)
#print(c, cand)
oks = [ok(cand, k) for k in strings]
#print(oks)
if False not in oks:
r = cand
possible = True
break
if possible:
print(r)
done = True
break
else:
print(-1)
done = True
break
if not done and len(ans) == m:
print(ans)
elif not done and len(ans) != m:
print(-1)
| 12 | PYTHON3 |
t=int(input())
count=0
while count<t:
count+=1
n=int(input())
l=list(map(int, input().split(' ')))
i=0
es=[]
os=[]
while i<2*n:
if l[i]%2==0:
es.append(i)
else:
os.append(i)
i+=1
left=len(es)%2
if len(es)==0:
i=0
while i<len(os)-3:
print(str(os[i]+1)+' '+str(os[i+1]+1))
i+=2
elif len(os)==0:
i=0
while i<len(es)-3:
print(str(es[i]+1)+' '+str(es[i+1]+1))
i+=2
elif left==0:
i=0
while i<len(es)-1:
print(str(es[i]+1)+' '+str(es[i+1]+1))
i+=2
i=0
while i<len(os)-3:
print(str(os[i]+1)+' '+str(os[i+1]+1))
i+=2
else:
i=0
while i<len(es)-2:
print(str(es[i]+1)+' '+str(es[i+1]+1))
i+=2
i=0
while i<len(os)-2:
print(str(os[i]+1)+' '+str(os[i+1]+1))
i+=2
| 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 6;
int Q, n;
string str;
struct Node {
int open, close, valid;
void merge(Node a, Node b) {
int t = min(a.open, b.close);
open = a.open - t + b.open;
close = a.close + b.close - t;
valid = a.valid + b.valid + t;
}
} seg[N << 2];
void build(int s = 0, int e = str.size(), int id = 1) {
if (e - s == 1) {
seg[id] = {(str[s] == '('), (str[s] == ')'), 0};
return;
}
int mid = s + e >> 1;
build(s, mid, id << 1);
build(mid, e, id << 1 | 1);
seg[id].merge(seg[id << 1], seg[id << 1 | 1]);
}
Node get(int l, int r, int s = 0, int e = str.size(), int id = 1) {
if (l <= s && e <= r) return seg[id];
if (l >= e || r <= s) return {0, 0, 0};
int mid = e + s >> 1;
Node res;
res.merge(get(l, r, s, mid, id << 1), get(l, r, mid, e, id << 1 | 1));
return res;
}
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
cin >> str >> Q;
build();
for (int q = 0, l, r; q < Q; q++) {
cin >> l >> r;
Node ans = get(--l, r);
cout << 2 * ans.valid << endl;
}
}
| 9 | CPP |
n=int(input())
l=list(map(int,input().split()))
d=[0]*n
for i in range(n):
d[l[i]-1]=i+1
print(*d)
| 7 | PYTHON3 |
#include <iostream>
#include <queue>
#include <string>
using namespace std;
int main()
{
priority_queue<int> PQ;
string com;
int n;
while(cin >> com)
{
if(com == "end")
{
break;
}
if(com[0] == 'i')
{
cin >> n;
PQ.push(n);
}
else if(com[0] == 'e')
{
cout << PQ.top() << endl;
PQ.pop();
}
}
return 0;
}
| 0 | CPP |
#include <bits/stdc++.h>
const int kN = 100000 + 5 + 12;
int n, k, q;
std::bitset<1 << 12> bs[kN];
int t[kN], x[kN], y[kN];
int a[12][kN];
int tot;
int main() {
scanf("%d%d%d", &n, &k, &q);
for (int i = 0; i < k; ++i) {
for (int j = 0; j < n; ++j) scanf("%d", &a[i][j]);
}
for (int i = 0; i < k; ++i)
for (int mask = 0; mask < 1 << k; ++mask) bs[i][mask] = mask >> i & 1;
tot = k;
for (int i = 0; i < q; ++i) {
int t, x, y;
scanf("%d%d%d", &t, &x, &y);
--x;
--y;
if (t == 1) {
bs[tot++] = bs[x] | bs[y];
} else if (t == 2) {
bs[tot++] = bs[x] & bs[y];
} else {
int result = 2e9;
for (int at = 0; at < k; ++at) {
int mask = 0;
for (int j = 0; j < k; ++j) mask |= (a[at][y] < a[j][y]) << j;
if (bs[x][mask] == 0) result = std::min(result, a[at][y]);
}
printf("%d\n", result);
}
}
}
| 10 | CPP |
a = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.sort()
b.sort()
for i in a:
if b.count(i) > 0:
print(i)
exit()
print(min(a[0], b[0]) * 10 + max(a[0], b[0])) | 7 | PYTHON3 |
[k,n,w] = list(map(int, input().split()))
val = int(w * (w + 1) / 2 * k - n)
val = val if val >= 0 else 0
print (val) | 7 | PYTHON3 |
from sys import stdin,stdout
inp = stdin.readline
out = stdout.write
s = inp().strip()
n = len(s)
s2='hello'
j=0
for i in s:
if i==s2[j]:
j+=1
if j==5:
break
if j==5:
out('YES')
else:
out('NO') | 7 | PYTHON3 |
#include<bits/stdc++.h>
using namespace std;
int a[10];
bool avai[10];
signed main(){
for(register int i=1;i<=9;++i) scanf("%d",&a[i]);
int n;
scanf("%d",&n);
while(n--){
int x;
scanf("%d",&x);
for(register int i=1;i<=9;++i) if(a[i]==x) avai[i]=true;
}
bool f=false;
if((avai[1]&&avai[2]&&avai[3])||(avai[4]&&avai[5]&&avai[6])||(avai[7]&&avai[8]&&avai[9])) f=true;
if((avai[1]&&avai[4]&&avai[7])||(avai[2]&&avai[5]&&avai[8])||(avai[3]&&avai[6]&&avai[9])) f=true;
if((avai[1]&&avai[5]&&avai[9])||(avai[3]&&avai[5]&&avai[7])) f=true;
puts(f?"Yes":"No");
return 0;
} | 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, m, g;
long long fact[200005], factinv[200005];
long long power(int n, int p) {
if (p == 0) return 1;
if (p == 1) return n;
if (p & 1) return power(n, p - 1) * n % 1000000007;
long long z = power(n, p / 2);
return z * z % 1000000007;
}
long long C(int n, int k) {
if (k == 0) return 1;
if (n < k) return 0;
long long ans = fact[n];
ans = ans * factinv[k] % 1000000007;
ans = ans * factinv[n - k] % 1000000007;
return ans;
}
long long f(int n, int m, int g) {
if (n == 1 and m == 0) return g == 0;
if (n == 0) {
if (m == 1)
return g == 1;
else
return g == 0;
}
if (g == 0) {
return (C(n + m - 1, n) + f(n - 1, m, 1)) % 1000000007;
} else {
return f(n - 1, m, 0);
}
}
int main() {
fact[0] = 1;
for (int i = 1; i < 200005; i++) fact[i] = fact[i - 1] * i % 1000000007;
factinv[0] = 1;
factinv[1] = 1;
for (int i = 2; i < 200005; i++)
factinv[i] = factinv[i - 1] * power(i, 1000000005) % 1000000007;
cin >> n >> m >> g;
cout << f(n, m, g) << endl;
return 0;
}
| 10 | CPP |
from functools import reduce
import sys
import math
class Read:
@staticmethod
def string():
return input()
@staticmethod
def int():
return int(input())
@staticmethod
def list(delimiter=' '):
return input().split(delimiter)
@staticmethod
def list_int(delimiter=' '):
return list(map(int, input().split(delimiter)))
# infilename = 'input.txt'
# sys.stdin = open(infilename, 'r')
# outfilename = 'output.txt'
# sys.stdout = open(outfilename, 'w')
def main():
t = Read.int()
for _ in range(t):
a, b, c, d = Read.list_int()
if b >= a:
print(b)
else:
if d >= c:
print(-1)
else:
print(b + math.ceil((a - b) / (c - d)) * c)
if __name__ == '__main__':
main()
| 7 | PYTHON3 |
a = input()
length = len(a)
pal = 0
counter = 0
for i in range(int(length/2)):
if a[i] == a[length - i - 1]:
pal += 1
else:
counter += 1
if counter == 1:
print("YES")
elif counter == 0:
if length % 2 == 0:
print("NO")
else:
print("YES")
else:
print("NO")
# else:
# for i in range | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long r1, c1, r2, c2;
cin >> r1 >> c1 >> r2 >> c2;
long long r = 0, c = 0;
if (r1 == r2) r++;
if (c1 == c2) c++;
cout << 2 - r - c << " ";
long long k = 0, l = 0, m = 0, n = 0;
if ((r1 + c1) % 2 == (r2 + c2) % 2) k++;
if ((r1 + c1) == (r2 + c2)) l++;
if ((r1 - c1) == (r2 - c2)) m++;
if ((r1 != r2) && (c1 != c2)) n++;
if ((m * n) == 0)
cout << (k * (2 - l)) << " ";
else
cout << min(k * (2 - l), (m * n)) << " ";
long long x = abs(r1 - r2);
long long y = abs(c1 - c2);
cout << max(x, y) << endl;
}
| 7 | CPP |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.