solution
stringlengths 10
159k
| difficulty
int64 0
3.5k
| language
stringclasses 2
values |
---|---|---|
minutes = 240
prob, time = map(int, input().split())
minutes-=time
t = c = 0
for i in range(1, prob+1):
t+=(5*i)
if t<=minutes:
c+=1
else:
break
print(c) | 800 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const long long maxn = 3e4 + 1;
const long long k = sqrt(1e9) + 1;
long long n;
long long GTN(long long x, long long y) {
if (y == 0) {
return 1;
} else {
long long tmp = GTN(x, y / 2);
if (y % 2 == 0) {
return tmp * tmp;
} else {
return tmp * tmp * x;
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n;
cout << 2 * 4 * 3 * GTN(4, n - 3) + 4 * (n - 3) * 9 * GTN(4, n - 4);
}
| 1,700 | CPP |
n,m = map(int,input().split())
tasks = [int(x) for x in input().split()]
ans = tasks[0]-1
for i in range(1,m):
if tasks[i]>=tasks[i-1]:
ans += (tasks[i]-tasks[i-1])
else:
ans += (n-tasks[i-1]+tasks[i])
print(ans)
| 1,000 | PYTHON3 |
for _ in range(int(input())):
n,s=input().split()
n=int(n)
mn=[0]*n
mx=[0]*n
s_i=[0]*(n)
if s[-1]=='>':
s_i[-2]=1
else:
s_i[-2]=-1
for i in range(len(s)-2,-1,-1):
if s[i]=='>':
if i+1<len(s) and s_i[i+1]>0:
s_i[i]=s_i[i+1]+1
else:
s_i[i]=1
else:
if i+1<len(s) and s_i[i+1]<0:
s_i[i]=s_i[i+1]-1
else:
s_i[i]=-1
#print(s_i)
mxm=n
i=0
while i<n:
if s_i[i]>0:
ei=i+s_i[i]+1
if ei==n:
while i<n:
mx[i]=mxm
i+=1
mxm-=1
else:
mx[ei]=mxm
mxm-=1
while i<ei:
mx[i]=mxm
i+=1
mxm-=1
i+=1
else:
ei=i+abs(s_i[i])
j=ei
while j>=i:
mx[j]=mxm
mxm-=1
j-=1
i=ei+1
i=0
mnm=1
while i<n:
if s_i[i]>0:
ei=i+abs(s_i[i])
j=ei
while j>=i:
mn[j]=mnm
mnm+=1
j-=1
i=ei+1
else:
ei=i+abs(s_i[i])
while i<=ei:
mn[i]=mnm
mnm+=1
i+=1
i=0
while i<len(s):
if s[i]=='>' and mx[i]<mx[i+1]:
mx[i],mx[i+1]=mx[i+1],mx[i]
i-=1
continue
elif s[i]=='<' and mx[i]>mx[i+1]:
mx[i],mx[i+1]=mx[i+1],mx[i]
i-=1
continue
i+=1
print(*mx)
i=0
while i<len(s):
if s[i]=='>' and mn[i]<mn[i+1]:
mn[i],mn[i+1]=mn[i+1],mn[i]
i-=1
continue
elif s[i]=='<' and mn[i]>mn[i+1]:
mn[i],mn[i+1]=mn[i+1],mn[i]
i-=1
continue
i+=1
print(*mn)
| 1,800 | PYTHON3 |
import sys; read = lambda : sys.stdin.readline()
for _ in range(int(read())):
a = read()
if int(a)<10: print(int(a)-1); continue
num1 = int("".join([a[i] for i in range(0, len(a), 2)]))
num2 = int("".join([a[i] for i in range(1, len(a), 2)]))
print((num1+1)*(num2+1) - 2) | 1,600 | PYTHON3 |
def prime_list(n):
a = list(range(n + 1))
a[1] = 0
lst = []
i = 2
while i <= n:
if a[i] != 0:
lst.append(a[i])
for j in range(i, n+1, i):
a[j] = 0
i += 1
del(a)
return lst
def isdiv(a, b):
c = a
d = b
res = 0
while (c % d == 0):
c = c // d
res += 1
return res
n = int(input())
a = [int(i) for i in input().split()]
lst = prime_list(int(max(a)))
div = 1
for prime in lst:
isdiv_min = 10 ** 7
isdiv_min2 = 10 ** 7
count = 0
res = 0
for i in range(n):
res = isdiv(a[i], prime)
if res == 0:
count += 1
if count > 1:
break
if res < isdiv_min:
isdiv_min2 = isdiv_min
isdiv_min = res
elif res >= isdiv_min and res < isdiv_min2:
isdiv_min2 = res
if count <= 1:
div = div * (prime ** isdiv_min2)
print(div)
| 1,600 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int M = 1e2 * 2 + 5;
int n, m, a[M];
double C[M][M], dp[M][M][M], ans, T;
void pre() {
C[0][0] = 1;
for (int i = 1; i <= 50; ++i) {
C[i][0] = 1;
for (int j = 1; j <= i; ++j) C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
}
}
int main() {
scanf("%d %d", &n, &m);
for (int i = 1; i <= m; i++) {
scanf("%d", &a[i]);
}
pre();
dp[0][0][0] = 1;
for (int i = 1; i <= m; i++) {
for (int j = 0; j <= n; j++) {
for (int k = 0; k <= j; k++) {
for (int l = 0; l <= n - j; l++) {
dp[i][j + l][max((l + a[i] - 1) / a[i], k)] +=
dp[i - 1][j][k] * C[n - j][l];
}
}
}
}
for (int i = 0; i <= n; ++i) T += dp[m][n][i];
for (int i = 1; i <= n; ++i) ans += i * dp[m][n][i] / T;
printf("%.20lf", ans);
return 0;
}
| 2,200 | CPP |
#include <bits/stdc++.h>
using namespace std;
inline long long read() {
long long sum = 0, ff = 1;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-') ff = -1;
ch = getchar();
}
while (isdigit(ch)) sum = sum * 10 + (ch ^ 48), ch = getchar();
return sum * ff;
}
const long long N = 3e5 + 5;
long long n, m, s, ans = -1e12, a[N], f[N][11];
signed main() {
n = read();
m = read();
s = read();
for (long long i = 1; i <= n; i++) a[i] = read();
if (m == 1) {
long long tot = 0;
for (long long i = 1; i <= n; i++) {
tot += a[i] - s;
ans = max(ans, tot);
tot = max(tot, 0ll);
}
printf("%lld\n", max(0ll, ans));
return 0;
}
memset(f, 128, sizeof f);
for (long long i = 0; i <= n; i++) f[i][0] = 0;
for (long long i = 1; i <= n; i++)
for (long long j = 0; j <= min(i, m - 1); j++) {
if (j == 1)
f[i][j] = f[i - 1][0] + a[i] - s;
else if (!j)
f[i][j] = max(0ll, f[i - 1][m - 1] + a[i]);
else
f[i][j] = max(f[i][j], f[i - 1][j - 1] + a[i]);
ans = max(ans, f[i][j]);
}
printf("%lld\n", ans);
return 0;
}
| 1,900 | CPP |
X = list(map(int,input().split(" ")))
M = -9999999
for i in X:
if M > i:
M = M
else:
M = i
arr = []
for i in X:
if M - i != 0:
arr.append(M - i)
for i in arr:
print(i, end = " ")
| 800 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int Mod = 1e9 + 7;
int n;
int a[30], p[10], k;
int dp[1 << 24], cnt[1 << 24];
long long sum[1 << 24];
int main() {
cin >> n;
for (int i = 0; i < n; i++) scanf("%d", &a[i]), sum[1 << i] = a[i];
cin >> k;
dp[0] = 1;
for (int i = 0; i < k; i++) scanf("%d", &p[i]);
for (int i = 0; i < 24; i++) cnt[1 << i] = i;
int all = (1 << n) - 1;
for (int i = 0; i <= all; i++) {
int now = i, lowbit = i & (-i), j;
for (; now; now -= now & (-now)) {
lowbit = (now & (-now));
j = cnt[lowbit];
if (now == i) sum[i] = sum[i ^ lowbit] + a[j];
if (sum[i] != p[0] && sum[i] != p[1])
dp[i] = (dp[i] + dp[i ^ lowbit]) % Mod;
}
}
printf("%d\n", dp[all]);
return 0;
}
| 2,300 | CPP |
a = int(input())
if a > 2:
if a % 2 == 0:
print('YES')
else:
print('NO')
else:
print('NO') | 800 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int iinf = 1e9 + 7;
const long long linf = 1ll << 62;
const double dinf = 1e10;
inline long long read() {
bool f = 0;
long long x = 0;
char c = getchar();
while ((c < '0' || c > '9') && c != '-') c = getchar();
if (c == '-') {
f = 1;
c = getchar();
}
while (c >= '0' && c <= '9') {
x = x * 10 + c - '0';
c = getchar();
}
if (f) x = -x;
return x;
}
inline void scf(int &x) {
bool f = 0;
x = 0;
char c = getchar();
while ((c < '0' || c > '9') && c != '-') c = getchar();
if (c == '-') {
f = 1;
c = getchar();
}
while (c >= '0' && c <= '9') {
x = x * 10 + c - '0';
c = getchar();
}
if (f) x = -x;
return;
}
void scf(int &x, int &y) {
scf(x);
return scf(y);
}
void scf(int &x, int &y, int &z) {
scf(x);
scf(y);
return scf(z);
}
const int N = 233;
const int M = 50055;
int n, m;
long long G, S;
struct edge {
int u, v;
long long g, s;
void in() {
scf(u, v);
g = read();
s = read();
return;
}
} e[M];
int id[M];
int rar, rare;
int par[N];
int q[N], que[N];
inline int find(int u) { return par[u] == u ? u : par[u] = find(par[u]); }
inline bool cmp_g(int u, int v) { return e[u].g < e[v].g; }
inline bool cmp_s(int u, int v) { return e[u].s < e[v].s; }
int main() {
scf(n, m);
G = read();
S = read();
for (int i = 0; i < (m); i++) e[i].in(), id[i] = i;
sort(id, id + m, cmp_g);
long long ans = linf;
for (int i = 0; i < (m); i++) {
rare = 0;
q[rar++] = id[i];
sort(q, q + rar, cmp_s);
for (int u = (1); u <= (n); u++) par[u] = u;
long long mx = 0;
for (int j = 0; j < (rar); j++) {
const edge &E = e[q[j]];
if (find(E.u) == find(E.v)) continue;
mx = E.s;
que[rare++] = q[j];
par[find(E.u)] = find(E.v);
}
memcpy(q, que, sizeof(que));
rar = rare;
if (rar < n - 1) continue;
long long calc = e[id[i]].g * G + mx * S;
(calc < ans) && (ans = calc);
}
printf("%I64d\n", ans == linf ? -1 : ans);
return 0;
}
| 2,200 | CPP |
v = [int(x) for x in input().split(' ')]
a = v[0]
b = v[1]
timeLimit = 240 - b
def sumTime(x):
s = 0
for i in range(x + 1):
s = s + (i * 5)
return s
while sumTime(a) > timeLimit:
a -= 1
print(a)
| 800 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int n_max = 1001;
int dig[n_max][n_max][2], way[n_max][n_max][2], i, j, k, x = -1, n, cur;
void print(int ii, int jj) {
if (ii == 1 && jj == 1) return;
if (way[ii][jj][k]) {
print(ii - 1, jj);
cout << "D";
} else {
print(ii, jj - 1);
cout << "R";
}
}
int main() {
cin >> n;
for (i = 2; i <= n; i++) {
dig[0][i][0] = dig[0][i][1] = dig[i][0][0] = dig[i][0][1] = 2147483647;
;
}
for (i = 1; i <= n; i++) {
for (j = 1; j <= n; j++) {
cin >> cur;
if (!cur) {
x = i;
} else {
for (; !(cur & 1); cur >>= 1) {
dig[i][j][0]++;
}
for (; !(cur % 5); cur /= 5) {
dig[i][j][1]++;
}
}
for (k = 0; k < 2; k++) {
if (way[i][j][k] = (dig[i - 1][j][k] < dig[i][j - 1][k])) {
dig[i][j][k] += dig[i - 1][j][k];
} else {
dig[i][j][k] += dig[i][j - 1][k];
}
}
}
}
k = dig[n][n][0] > dig[n][n][1];
if (x != -1 && dig[n][n][k] > 1) {
cout << 1 << endl;
for (i = 1; i < x; i++) cout << "D";
for (i = 1; i < n; i++) cout << "R";
for (i = x; i < n; i++) cout << "D";
} else {
cout << dig[n][n][k] << endl;
print(n, n);
}
return 0;
}
| 2,000 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
string s = {
"123456789101112131415161718192021222324252627282930313233343536373839404"
"142434445464748495051525354555657585960616263646566676869707172737475767"
"778798081828384858687888990919293949596979899100101102103104105106107108"
"109110111112113114115116117118119120121122123124125126127128129130131132"
"133134135136137138139140141142143144145146147148149150151152153154155156"
"157158159160161162163164165166167168169170171172173174175176177178179180"
"181182183184185186187188189190191192193194195196197198199200201202203204"
"205206207208209210211212213214215216217218219220221222223224225226227228"
"229230231232233234235236237238239240241242243244245246247248249250251252"
"253254255256257258259260261262263264265266267268269270271272273274275276"
"277278279280281282283284285286287288289290291292293294295296297298299300"
"301302303304305306307308309310311312313314315316317318319320321322323324"
"325326327328329330331332333334335336337338339340341342343344345346347348"
"349350351352353354355356357358359360361362363364365366367368369370371372"
"373374375376377378379380381382383384385386387388389390391392393394395396"
"397398399400"};
cout << s[n - 1] << endl;
return 0;
}
| 800 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, c = 0;
cin >> n;
int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
cin >> m;
int b[m];
for (int i = 0; i < m; i++) {
cin >> b[i];
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
for (int g = 0; g < n; g++) {
if (a[i] + b[j] != a[g]) {
c++;
}
}
for (int h = 0; h < m; h++) {
if (a[i] + b[j] != b[h]) {
c++;
}
}
if (c == n + m) {
cout << a[i] << " " << b[j];
return 0;
} else {
c = 0;
}
}
}
return 0;
}
| 800 | CPP |
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
const int MAX = 2e9 + 7;
const long long MOD = 1e18 + 7;
void solve() {
int m, n;
cin >> m;
vector<int> dis;
for (int i = 0; i < m; i++) {
int x;
cin >> x;
dis.push_back(x);
}
cin >> n;
sort((dis).begin(), (dis).end());
vector<int> b;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
b.push_back(x);
}
long long cnt = 0;
sort((b).begin(), (b).end());
int mn = dis[0];
int l = 0;
reverse((b).begin(), (b).end());
while (l < n) {
int k = l;
for (int i = l; i < (min(n, l + mn)); i++) {
cnt += b[i];
k = i;
}
l = k + 3;
}
cout << cnt << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
solve();
return 0;
}
| 1,400 | CPP |
#include <bits/stdc++.h>
int n;
int main() {
int t;
scanf("%d", &t);
while (t--) {
scanf("%d", &n);
if (n % 2 == 1) {
printf("7");
n = n - 3;
}
while (n) {
printf("1");
n = n - 2;
}
printf("\n");
}
return 0;
}
| 900 | CPP |
s = input()
upper_len = len(list(filter(lambda c: ord('A') <= ord(c) <= ord('Z'), s)))
print(s.upper() if upper_len > len(s) - upper_len else s.lower())
| 800 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int n, m;
char temp[30];
string str[10];
vector<string> ivan[20];
int arr[10];
int inversion() {
int ret = 0;
for (int(i) = (0), _n = (n - 1); (i) <= _n; (i)++) {
for (int(j) = (i + 1), _n = (n - 1); (j) <= _n; (j)++) {
if (arr[i] > arr[j]) ret++;
}
}
return ret;
}
bool isSubsequence(int ind) {
int pos = 0;
for (int(i) = (0), _n = (ivan[ind].size() - 1); (i) <= _n; (i)++) {
if (pos >= n) break;
if (str[arr[pos]] == ivan[ind][i]) pos++;
}
return pos >= n;
}
int main() {
scanf("%d", &n);
for (int(i) = (0), _n = (n - 1); (i) <= _n; (i)++) {
scanf("%s", temp);
str[i] = temp;
}
scanf("%d", &m);
for (int(i) = (0), _n = (m - 1); (i) <= _n; (i)++) {
int x;
scanf("%d", &x);
while (x--) {
scanf("%s", temp);
ivan[i].push_back(temp);
}
}
int ans = 200000000, ans2 = -1;
for (int(ind) = (0), _n = (m - 1); (ind) <= _n; (ind)++) {
for (int(i) = (0), _n = (n - 1); (i) <= _n; (i)++) arr[i] = i;
int cnt = 200000000;
bool _b = false;
do {
if (isSubsequence(ind)) cnt = min(inversion(), cnt);
} while (next_permutation(arr, arr + n));
if (cnt != 200000000) {
if (ans > cnt) {
ans = cnt;
ans2 = ind;
}
}
}
if (ans2 == -1)
puts("Brand new problem!");
else {
printf("%d\n", ans2 + 1);
ans = n * (n - 1) / 2 - ans + 1;
printf("[:");
for (int(i) = (1), _n = (ans); (i) <= _n; (i)++) printf("|");
puts(":]");
}
for (int(i) = (1), _n = (2); (i) <= _n; (i)++) getchar();
return 0;
}
| 2,600 | CPP |
import sys
#sys.stdin = open('in', 'r')
q = int(input())
for _ in range(q):
n = int(input())
l = []
while n > 0:
l.append(n % 3)
n = n // 3
ind = -1
for i in range(len(l)):
if l[i] == 2:
ind = i
if ind != -1:
ind += 1
while ind < len(l) and l[ind] == 1:
ind += 1
for j in range(ind):
l[j] = 0
if ind >= len(l):
l.append(1)
else:
l[ind] = 1
res = 0
p3 = 1
for i in range(len(l)):
res += p3 if l[i] == 1 else 0
p3 *= 3
print(res)
#l = [2 1 0 1 1]
#sys.stdout.write('YES\n')
#sys.stdout.write(f'{res}\n')
#sys.stdout.write(f'{y1} {x1} {y2} {x2}\n')
| 1,300 | PYTHON3 |
# -*- coding: utf-8 -*-
"""
Created on Tue Nov 3 14:35:56 2020
@author: 86183
"""
n,M=[int(x) for x in input().split()]
a=[int(x) for x in input().split()]
if n>3:
on=[a[0]]
off=[]
b=a[0]
c=0
for i in range(0,n-2,2):
b+=a[i+2]-a[i+1]
c+=a[i+1]-a[i]
on.append(b)
off.append(c)
if n%2==1:
c+=M-a[-1]
off.append(c)
else:
b+=M-a[-1]
c+=a[-1]-a[-2]
on.append(b)
off.append(c)
s=int()
t=on[-1]
for i in range(2,n-1,2):
if a[i+1]-a[i]>1:
s=on[int(i/2)]+off[-1]-off[int(i/2)]+a[i+1]-a[i]-1
t=max(s,t)
for i in range(3,n-1,2):
if a[i+1]-a[i]>1:
s=on[int((i-1)/2)]+M-on[-1]-off[int((i-1)/2)]+a[i+1]-a[i]-1
t=max(s,t)
if a[0]>1:
s=off[-1]+a[0]-1
t=max(s,t)
if a[1]-a[0]>1:
s=a[0]-1+off[-1]
t=max(s,t)
if a[2]-a[1]>1:
s=a[0]+off[-1]-1
t=max(s,t)
if n%2==1 and M-a[-1]>1:
s=on[-1]+M-a[-1]-1
t=max(s,t)
print(t)
elif n==1:
print(M-1)
else:
s=0
for i in range(n):
s+=a[i]*((-1)**i)
if n%2==0:
s+=M
if M-a[-1]>3:
for i in range(min(M-2,a[-1]+1)):
if i+1 not in a:
a.append(i+1)
b=sorted(a)
si=0
for j in range(n+1):
si+=b[j]*((-1)**j)
if n%2==1:
si+=M
if si>s:
s=si
a.remove(i+1)
else:
for i in range(a[-1]+1):
if i+1 not in a:
a.append(i+1)
b=sorted(a)
si=0
for j in range(n+1):
si+=b[j]*((-1)**j)
if n%2==1:
si+=M
if si>s:
s=si
a.remove(i+1)
print(s) | 1,500 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
os << '{';
string sep;
for (const auto &x : v) os << sep << x, sep = ", ";
return os << '}';
}
template <typename T, size_t size>
ostream &operator<<(ostream &os, const array<T, size> &arr) {
os << '{';
string sep;
for (const auto &x : arr) os << sep << x, sep = ", ";
return os << '}';
}
template <typename A, typename B>
ostream &operator<<(ostream &os, const pair<A, B> &p) {
return os << '(' << p.first << ", " << p.second << ')';
}
vector<string> vec_splitter(string s) {
s += ',';
vector<string> res;
while (!s.empty()) {
res.push_back(s.substr(0, s.find(',')));
s = s.substr(s.find(',') + 1);
}
return res;
}
void debug_out(vector<string> __attribute__((unused)) args,
__attribute__((unused)) int idx,
__attribute__((unused)) int LINE_NUM) {
cerr << endl;
}
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
if (idx > 0)
cerr << ", ";
else
cerr << "+ Line(" << LINE_NUM << ") ";
stringstream ss;
ss << H;
cerr << args[idx] << " = " << ss.str();
debug_out(args, idx + 1, LINE_NUM, T...);
}
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
long long n, k;
cin >> n >> k;
vector<long long> v;
long long ans = 2147483647;
for (long long i = 0; i < n; i++) {
long long x;
cin >> x;
v.push_back(x);
}
sort(v.begin(), v.end());
for (long long x = 0; x <= 200000; x++) {
long long c = 0;
long long r = 0;
for (long long u : v) {
if (u < x) continue;
if (u == x)
c++;
else {
long long t = u;
while (t > x) t /= 2;
if (t == x) {
t = u;
while (t > x) {
t /= 2;
r++;
}
c++;
}
}
if (c == k) {
ans = min(ans, r);
break;
}
}
}
cout << ans << '\n';
}
| 1,500 | CPP |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
int n;
double l, wmax;
vector<double> base, x;
void solve() {
int r = 0;
int l = 0;
ll ans = 0;
for (double b : base) {
while (l < x.size() &&
(x[l] < b + 1e-8 || abs((x[l] + b) / (x[l] - b)) > wmax - 1e-8))
l++;
ans += x.size() - l;
}
cout << ans << endl;
}
void load() {
cin >> n >> l >> wmax;
for (int i = 0; i < n; i++) {
int xx, v;
cin >> xx >> v;
if (v > 0)
base.push_back(xx);
else
x.push_back(xx + l);
}
sort(base.begin(), base.end());
sort(x.begin(), x.end());
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
load();
solve();
return 0;
}
| 2,500 | CPP |
n = int(input())
s1 = input()
zero = s1.count('z');
one = s1.count('n');
for i in range(0,one):
print("1 ", end = " ")
for i in range(0,zero):
print("0 ", end = " ")
| 800 | PYTHON3 |
from collections import deque
n, k = map(int, input().split(" "))
lis = [int(k) for k in input().split(" ")]
tot=deque([])
sto=set()
ltot=0
for i in range(n):
next = lis[i]
if next in sto:
continue
elif ltot < k:
tot.appendleft(next)
sto.add(next)
ltot += 1
else:
tot.appendleft(next)
last = tot.pop()
sto.remove(last)
sto.add(next)
print(ltot)
print(" ".join(str(k) for k in tot)) | 1,000 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int n, a[10], b[100005], ans = 1e9, tot;
vector<pair<int, int>> v;
multiset<int> s;
int m[100005], pre[600005], suf[600005];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
for (int i = 1; i <= 6; i++) cin >> a[i];
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> b[i];
for (int bs = 1; bs <= 6; bs++) v.emplace_back(make_pair(b[i] - a[bs], i));
}
sort(v.begin(), v.end());
memset(m, -1, sizeof(m));
tot = n;
for (int i = 0; i < v.size(); i++) {
const pair<int, int> &p = v[i];
if (m[p.second] != -1) {
s.erase(s.find(m[p.second]));
} else
tot--;
s.insert(m[p.second] = p.first);
if (tot == 0) ans = min(ans, p.first - *s.begin());
}
cout << ans << endl;
return 0;
}
| 1,900 | CPP |
#include <bits/stdc++.h>
using namespace std;
void _fill_int(int* p, int val, int rep) {
int i;
for (i = 0; i < rep; i++) p[i] = val;
}
signed long long GETi() {
signed long long i;
scanf("%lld", &i);
return i;
}
int N;
map<vector<int>, double> M[64];
int st[64], num[64];
double dodo(int top, vector<int> V) {
int otop, i, x, y, z, ng = 0;
otop = top = st[top];
sort(V.begin(), V.end());
vector<int> VV = V;
if (M[top].find(V) != M[top].end()) return M[top][V];
if (num[top] == 3) V.push_back(top), top = 0, ng = 1;
double ma[4] = {0, 1e15, 1e15, 1e15};
int pre = -1;
for (i = 0; i < V.size() - ng; i++) {
if (pre == V[i]) continue;
pre = V[i];
x = V[i] % 4;
y = V[i] / 4 % 4;
z = V[i] / 16;
vector<int> V2 = V;
V2.erase(V2.begin() + i);
if (x && y && z) {
if (top % 4 == 0) ma[y] = min(ma[y], dodo(top + y * 1, V2));
if (top / 4 % 4 == 0) ma[y] = min(ma[y], dodo(top + y * 4, V2));
if (top / 16 == 0 && top % 4) ma[y] = min(ma[y], dodo(top + y * 16, V2));
}
if (z && y) {
if (x) {
V[i] = 4 + x;
if (top % 4 == 0) ma[z] = min(ma[z], dodo(top + z * 1, V));
if (top / 4 % 4 == 0) ma[z] = min(ma[z], dodo(top + z * 4, V));
if (top / 16 == 0 && top % 4) ma[z] = min(ma[z], dodo(top + z * 16, V));
} else {
if (top % 4 == 0) ma[z] = min(ma[z], dodo(top + z * 1, V2));
if (top / 4 % 4 == 0) ma[z] = min(ma[z], dodo(top + z * 4, V2));
if (top / 16 == 0 && top % 4)
ma[z] = min(ma[z], dodo(top + z * 16, V2));
}
}
if (y && x) {
if (z) {
V[i] = z + 4;
if (top % 4 == 0) ma[x] = min(ma[x], dodo(top + x * 1, V));
if (top / 4 % 4 == 0) ma[x] = min(ma[x], dodo(top + x * 4, V));
if (top / 16 == 0 && top % 4) ma[x] = min(ma[x], dodo(top + x * 16, V));
} else {
if (top % 4 == 0) ma[x] = min(ma[x], dodo(top + x * 1, V2));
if (top / 4 % 4 == 0) ma[x] = min(ma[x], dodo(top + x * 4, V2));
if (top / 16 == 0 && top % 4)
ma[x] = min(ma[x], dodo(top + x * 16, V2));
}
}
V[i] = pre;
}
int sum = 1;
if (ma[1] >= 1e15) ma[1] = 0, sum += 1;
if (ma[2] >= 1e15) ma[2] = 0, sum += 2;
if (ma[3] >= 1e15) ma[3] = 0, sum += 2;
if (sum == 6) return M[otop][VV] = 0;
M[otop][VV] = (1 + ma[1] / 6 + ma[2] / 3 + ma[3] / 3) / (1 - sum / 6.0);
return M[otop][VV] =
(1 + ma[1] / 6 + ma[2] / 3 + ma[3] / 3) / (1 - sum / 6.0);
}
void solve() {
int f, i, j, k, l, x, y, x2, y2, z;
cin >> N;
string S;
for (i = 0; i < 64; i++) {
x = i % 4;
y = i / 4 % 4;
z = i / 16;
st[i] = (z > x) ? (x * 16 + y * 4 + z) : i;
num[i] = (x > 0) + (y > 0) + (z > 0);
}
vector<int> V;
for (i = 0; i < N; i++) {
cin >> S;
x = 0;
for (y = 0; y < 3; y++) {
if (S[y] == 'R') x += 1 << (y * 2);
if (S[y] == 'G') x += 2 << (y * 2);
if (S[y] == 'B') x += 3 << (y * 2);
}
if (i < N - 1) V.push_back(st[x]);
}
(void)printf("%.12lf\n", dodo(st[x], V));
}
int main(int argc, char** argv) {
string s;
if (argc == 1) ios::sync_with_stdio(false);
for (int i = 1; i < argc; i++) s += argv[i], s += '\n';
for (int i = s.size() - 1; i >= 0; i--) ungetc(s[i], stdin);
solve();
return 0;
}
| 2,500 | CPP |
#include <bits/stdc++.h>
using namespace std;
int a, d, f, g, h, j, k, l, i, n, m, res;
string s;
int main() {
cin >> s;
n = s.size();
g = s.find("bear", 0);
while (g < n) {
k = min(s.find("bear", g + 1), s.size());
if (k == n)
i = k - 3;
else
i = k;
res += (g + 1) * (i - g);
m = g;
g = k;
k = m;
}
cout << res;
}
| 1,200 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 79, logn = 18;
vector<vector<int> > l, p(maxn), son(maxn);
vector<int> depth(maxn, 0), val(maxn, 0);
int lca(int u, int v) {
if (depth[u] < depth[v]) swap(u, v);
for (int i = logn - 1; i >= 0; i--)
if (depth[l[i][u]] >= depth[v]) u = l[i][u];
if (u == v) return u;
for (int i = logn - 1; i >= 0; i--) {
if (l[i][u] != l[i][v]) {
u = l[i][u];
v = l[i][v];
}
}
return l[0][u];
}
void dfs(int v) {
for (int i : son[v]) {
dfs(i);
val[v] += val[i];
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m, s;
cin >> n >> m >> s;
s--;
l.assign(logn, vector<int>(maxn, s));
vector<vector<pair<int, long long> > > g(n);
for (int i = 0, u, v, w; i < m; i++) {
cin >> u >> v >> w;
g[--u].push_back({--v, w});
g[v].push_back({u, w});
}
vector<long long> d(n, 1e18);
set<pair<long long, int> > q{{0, s}};
while (!q.empty()) {
auto v = *q.begin();
q.erase(q.begin());
int vr = v.second;
if (d[vr] <= v.first) continue;
d[vr] = v.first;
for (pair<int, long long> i : g[vr]) {
if (d[i.first] > d[vr] + i.second) q.insert({d[vr] + i.second, i.first});
}
}
vector<pair<long long, int> > v;
for (int i = 0; i < n; i++) v.push_back({d[i], i});
sort(v.begin(), v.end());
for (int i = 1; i < n; i++) {
if (d[v[i].second] > 1e17) break;
val[v[i].second] = 1;
int lcaa = -1;
for (pair<int, long long> j : g[v[i].second]) {
if (d[v[i].second] == d[j.first] + j.second) {
if (lcaa != -1)
lcaa = lca(lcaa, j.first);
else
lcaa = j.first;
}
}
l[0][v[i].second] = lcaa;
depth[v[i].second] = depth[lcaa] + 1;
for (int j = 1; j < logn; j++)
l[j][v[i].second] = l[j - 1][l[j - 1][v[i].second]];
son[lcaa].push_back(v[i].second);
}
dfs(s);
val[s] = 0;
cout << *max_element(val.begin(), val.end()) << "\n";
return 0;
}
| 2,800 | CPP |
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using llf = long double;
using pi = pair<int, int>;
const int MAXN = 200005;
struct edg {
int s, e, x;
bool operator<(const edg &e) const { return x > e.x; }
};
struct qry {
int lim, vtx, idx;
bool operator<(const qry &q) const { return lim > q.lim; }
};
struct node {
int maxE, maxT;
set<int> cands;
} fuck[MAXN];
int pa[MAXN];
int find(int x) { return pa[x] = (pa[x] == x ? x : find(pa[x])); }
int n, q, a[MAXN];
int par[18][MAXN], pae[18][MAXN], din[MAXN], dep[MAXN], rev[MAXN], piv;
vector<pi> gph[MAXN];
pi lca(int x, int y) {
if (dep[x] > dep[y]) swap(x, y);
int dx = dep[y] - dep[x];
int ret = 0;
for (int i = 0; dx; i++) {
if (dx & 1) {
ret = max(ret, pae[i][y]);
y = par[i][y];
}
dx >>= 1;
}
for (int i = 17; i >= 0; i--) {
if (par[i][y] != par[i][x]) {
ret = max({ret, pae[i][x], pae[i][y]});
x = par[i][x];
y = par[i][y];
}
}
if (x != y) ret = max({ret, pae[0][x], pae[0][y]}), x = par[0][x];
return pi(x, ret);
}
void dfs(int x, int p) {
din[x] = ++piv;
rev[din[x]] = x;
for (auto &[w, y] : gph[x]) {
if (y == p) continue;
par[0][y] = x;
pae[0][y] = w;
dep[y] = dep[x] + 1;
dfs(y, x);
}
}
void sex(int p, int q) {
p = find(p);
q = find(q);
if (((int)(fuck[p].cands).size()) > ((int)(fuck[q].cands).size())) swap(p, q);
pa[p] = q;
if (fuck[q].maxE > fuck[p].maxE) {
return;
}
if (fuck[q].maxE < fuck[p].maxE) {
fuck[q].maxE = fuck[p].maxE;
fuck[q].maxT = fuck[p].maxT;
fuck[q].cands = fuck[p].cands;
return;
}
fuck[q].maxT = max(fuck[q].maxT, fuck[p].maxT);
for (auto &z : fuck[p].cands) {
auto l = fuck[q].cands.lower_bound(z);
if (l != fuck[q].cands.end()) {
fuck[q].maxT = max(fuck[q].maxT, lca(rev[*l], rev[z]).second);
}
if (l != fuck[q].cands.begin()) {
l--;
fuck[q].maxT = max(fuck[q].maxT, lca(rev[*l], rev[z]).second);
}
fuck[q].cands.insert(z);
}
}
pi QQuery(int z) {
int q = find(z);
z = din[z];
int ret = fuck[q].maxT;
auto l = fuck[q].cands.lower_bound(z);
if (l != fuck[q].cands.end()) {
ret = max(ret, lca(rev[*l], rev[z]).second);
}
if (l != fuck[q].cands.begin()) {
l--;
ret = max(ret, lca(rev[*l], rev[z]).second);
}
return pi(fuck[q].maxE, ret);
}
int main() {
scanf("%d %d", &n, &q);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
vector<edg> merge_ord;
vector<qry> query;
for (int i = 0; i < n - 1; i++) {
int s, e, x, y;
scanf("%d %d %d %d", &s, &e, &x, &y);
gph[s].emplace_back(y, e);
gph[e].emplace_back(y, s);
merge_ord.push_back({s, e, x});
}
sort((merge_ord).begin(), (merge_ord).end());
for (int i = 0; i < q; i++) {
int v, x;
;
scanf("%d %d", &v, &x);
query.push_back({v, x, i});
}
sort((query).begin(), (query).end());
{
dfs(1, 0);
for (int i = 1; i < 18; i++) {
for (int j = 1; j <= n; j++) {
par[i][j] = par[i - 1][par[i - 1][j]];
pae[i][j] = max(pae[i - 1][j], pae[i - 1][par[i - 1][j]]);
}
}
for (int i = 1; i <= n; i++) {
fuck[i].maxE = a[i];
fuck[i].cands.insert(din[i]);
pa[i] = i;
}
}
int j = 0;
vector<pi> dap(q);
for (auto &i : query) {
while (j < ((int)(merge_ord).size()) && i.lim <= merge_ord[j].x) {
sex(merge_ord[j].s, merge_ord[j].e);
j++;
}
dap[i.idx] = QQuery(i.vtx);
}
for (auto &[x, y] : dap) printf("%d %d\n", x, y);
}
| 3,300 | CPP |
from collections import defaultdict
def fun():
return 0
n=int(input())
arr=[int(x) for x in input().split()]
arr=sorted(arr)
d=defaultdict(fun)
flag=True
for i in arr:
d[i]+=1
if d[i]>2:
flag=False
break
if not flag:
print("NO")
else:
print("YES")
dec=[]
dd=0
arr=sorted((set(arr)))
for i in arr:
if d[i]==2:
dd+=1
dec.append(i)
print(dd)
if dd==0:
print()
else:
for i in dec:
print(i,end=" ")
print()
a=len(arr)
print(a)
if a==0:
print()
else:
for i in arr[::-1]:
print(i,end=" ")
print()
| 1,000 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T>
int complete_unique(T& v) {
sort(v.begin(), v.end());
v.resize(unique(v.begin(), v.end()) - v.begin());
return v.size();
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
vector<int> one, two;
vector<pair<int, int> > ans;
for (int i = n - 1; i >= 0; i--) {
if (a[i] == 0) {
continue;
} else if (a[i] == 1) {
one.emplace_back(i);
} else if (a[i] == 2) {
if (one.empty()) {
cout << "-1\n";
return 0;
}
ans.emplace_back(i, i);
ans.emplace_back(i, one.back());
one.pop_back();
two.push_back(i);
} else {
if (two.empty()) {
if (one.empty()) {
cout << "-1\n";
return 0;
}
ans.emplace_back(i, i);
ans.emplace_back(i, one.back());
ans.emplace_back(one.back(), one.back());
one.pop_back();
two.push_back(i);
} else {
ans.emplace_back(i, i);
ans.emplace_back(i, two.back());
ans.emplace_back(two.back(), two.back());
two.pop_back();
two.push_back(i);
}
}
}
for (int x : one) {
ans.emplace_back(x, x);
}
complete_unique(ans);
cout << ans.size() << '\n';
for (pair<int, int>& p : ans) {
cout << p.first + 1 << ' ' << p.second + 1 << '\n';
}
return 0;
}
| 1,900 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, n;
cin >> t;
while (t--) {
cin >> n;
char a[n][n];
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> a[i][j];
}
}
int chk = 1;
for (int i = 0; i < n - 1; i++) {
for (int j = 0; j < n - 1; j++) {
if (a[i][j] == '0') continue;
if (a[i + 1][j] == '0' && a[i][j + 1] == '0') {
chk = 0;
}
}
}
if (chk)
cout << "YES\n";
else
cout << "NO\n";
}
}
| 1,300 | CPP |
#include <bits/stdc++.h>
using namespace std;
unsigned long long dp[100002];
unsigned long long dp2[100002];
unsigned long long N;
unsigned long long T[100002];
unsigned long long n = 0, d = 1;
unsigned long long gcd(unsigned long long a, unsigned long long b) {
if (b > a) return gcd(b, a);
return (b > 0) ? (gcd(b, a % b)) : a;
}
void sup() {
unsigned long long k;
while ((k = gcd(n, d)) > 1) {
n /= k;
d /= k;
}
}
int main() {
memset(dp, 0, sizeof(dp));
memset(dp2, 0, sizeof(dp2));
cin >> N;
for (unsigned long long i = 1; i <= N; i++) cin >> T[i];
T[0] = 0;
sort(T, T + N + 1);
for (unsigned long long i = 1; i <= N; i++)
dp[i] = dp[i - 1] + i * (T[i] - T[i - 1]);
for (unsigned long long i = N - 1; i > 0; i--)
dp2[i] = dp2[i + 1] + (N - i) * (T[i + 1] - T[i]);
for (unsigned long long i = 1; i <= N; i++) n += dp[i];
for (unsigned long long i = N - 1; i > 0; i--) n += dp2[i];
d = N;
sup();
cout << n << " " << d << endl;
}
| 1,600 | CPP |
import math
def lcm(x, y):
return (x * y)//math.gcd(x,y)
q = int(input())
for i in range(q):
n = int(input())
p = list(map(lambda x: int(x)//100,input().split()))
p = sorted(p)
x, a = map(int,input().split())
y, b = map(int,input().split())
k = int(input())
if y > x:
x, y = y, x
a, b = b, a
lo = 0 #Impossible
hi = n + 1 #Possible (with fake large ticket)
while hi - lo > 1:
test = (lo + hi)//2
best = p[::]
both = test//lcm(a,b)
anum = (test//a) - both
bnum = (test//b) - both
out = 0
while best:
if both > 0:
out += (x + y) * best.pop()
both -= 1
elif anum > 0:
out += (x) * best.pop()
anum -= 1
elif bnum > 0:
out += (y) * best.pop()
bnum -= 1
else:
break
if out >= k:
hi = test
else:
lo = test
if hi == n+1:
print(-1)
else:
print(hi)
| 1,600 | PYTHON3 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")
#pragma GCC target("avx2,tune=native")
using namespace std;
bool lucky(int x) {
while (x > 0) {
if (x % 10 != 7 && x % 10 != 4) return false;
x /= 10;
}
return true;
}
vector<pair<int, int> > a, ans;
vector<int> cur;
void add_ans(int x, int y) {
if (x == y) return;
ans.emplace_back(x, y);
swap(cur[x], cur[y]);
a[cur[x]].second = x;
a[cur[y]].second = y;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
a.resize(n);
cur.resize(n);
for (int i = 0; i < n; i++) {
cin >> a[i].first;
a[i].second = i;
}
sort(a.begin(), a.end());
bool need = false;
int x = -1;
for (int i = 0; i < n; i++) {
if (lucky(a[i].first)) x = i;
need = need || a[i].second != i;
cur[a[i].second] = i;
}
if (need && x == -1) {
cout << "-1";
return 0;
} else if (x == -1) {
cout << "0";
return 0;
}
if (cur[x] + 1 != n) {
if (x != a[x].second) add_ans(x, a[x].second);
if (x != n - 1) add_ans(x, n - 1);
}
for (int i = 0; i < n; i++) {
if (i == x || a[i].second == i) continue;
add_ans(i, a[x].second);
add_ans(a[i].second, a[x].second);
}
cout << ans.size() << "\n";
for (pair<int, int> it : ans)
cout << it.first + 1 << " " << it.second + 1 << "\n";
return 0;
}
| 2,000 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;
int main() {
int n, m, k;
cin >> n >> m >> k;
vector<int> tooth(m, INF);
for (int i = 0; i < n; ++i) {
int r, c;
cin >> r >> c;
r--;
tooth[r] = min(tooth[r], c);
}
for (int i = 0; i < m; ++i) {
if (tooth[i] == INF) {
tooth[i] = 0;
}
}
sort(tooth.begin(), tooth.end(), greater<int>());
int i = 0;
int res = 0;
while (tooth[i] != 0 && i < m) {
int prev = k;
k -= tooth[i];
if (k >= 0) {
res += tooth[i];
} else {
res += prev;
break;
}
++i;
}
cout << res << endl;
return 0;
}
| 1,200 | CPP |
#include <bits/stdc++.h>
using namespace std;
struct el {
int x;
int idx;
};
int n, k;
el vec[300300];
long long sum[300300];
void read() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &vec[i].x);
vec[i].idx = i;
}
scanf("%d", &k);
}
bool cmp(el a, el b) { return a.x < b.x; }
void solve() {
sort(vec + 1, vec + n + 1, cmp);
for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + vec[i].x;
long long opt = 0;
int start = 1;
for (int i = 1; i < k; i++)
opt += (sum[k] - sum[i]) - (k - i) * (long long)vec[i].x;
long long tmp = opt;
for (int i = 2; i + k - 1 <= n; i++) {
tmp = tmp - (sum[i + k - 2] - sum[i - 1] -
(long long)(k - 1) * (long long)vec[i - 1].x);
tmp = tmp + (long long)(k - 1) * (long long)vec[i + k - 1].x -
(sum[i + k - 2] - sum[i - 1]);
if (tmp < opt) {
opt = tmp;
start = i;
}
}
for (int i = start; i < start + k; i++) printf("%d ", vec[i].idx);
printf("\n");
}
int main() {
read();
solve();
return 0;
}
| 2,000 | CPP |
n=int(input())
a=[int(x) for x in input().split()]
ans=0
i=0
j=n-1
p,q=0,0
while(i<=j):
if p==q and i+1<=j:
p+=a[i]
q+=a[j]
i+=1
j-=1
elif p==q :
i+=1
elif p>q:
q+=a[j]
j-=1
elif p<q:
p+=a[i]
i+=1
if p==q:
ans=max(ans,p)
print(ans)
| 1,200 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
long long modpow(long long a, long long b) {
long long ans = 1;
while (b) {
if (b & 1) {
ans = (ans * a) % 1000000007;
}
a = (a * a) % 1000000007;
b = b / 2;
}
return ans;
}
int main() {
int n, k;
cin >> n >> k;
if (n == 2) {
cout << 2 << " " << 1 << " " << 2 << endl;
fflush(stdout);
return 0;
}
int lo = 1, hi = n, md1, md2;
int ans = -1;
int anss = -1;
while (lo < hi) {
md1 = (lo + hi) / 2;
md2 = md1 + 1;
cout << 1 << " " << md1 << " " << md2 << endl;
fflush(stdout);
string s;
cin >> s;
if (hi - lo == 1) {
if (s[0] == 'T') {
ans = md1;
} else
ans = md2;
break;
} else {
if (s[0] == 'T') {
hi = md1;
} else {
lo = md2;
}
}
if (lo == hi) {
ans = lo;
break;
}
}
if (ans == 1) {
lo = 2;
hi = n;
while (lo < hi) {
md1 = (lo + hi) / 2;
md2 = md1 + 1;
cout << 1 << " " << md1 << " " << md2 << endl;
fflush(stdout);
string s;
cin >> s;
if (hi - lo == 1) {
if (s[0] == 'T') {
anss = md1;
} else
anss = md2;
break;
} else {
if (s[0] == 'T') {
hi = md1;
} else {
lo = md2;
}
}
if (lo == hi) {
anss = lo;
break;
}
}
} else if (ans == n) {
lo = 1;
hi = n - 1;
while (lo < hi) {
md1 = (lo + hi) / 2;
md2 = md1 + 1;
cout << 1 << " " << md1 << " " << md2 << endl;
fflush(stdout);
string s;
cin >> s;
if (hi - lo == 1) {
if (s[0] == 'T') {
anss = md1;
} else
anss = md2;
break;
} else {
if (s[0] == 'T') {
hi = md1;
} else {
lo = md2;
}
}
if (lo == hi) {
anss = lo;
break;
}
}
} else {
int lo1 = 1, hi1 = ans - 1;
int lo2 = ans + 1, hi2 = n;
if (lo1 == hi1) {
cout << 1 << " " << lo1 << " " << ans << endl;
fflush(stdout);
string s;
cin >> s;
if (s[0] == 'T') {
anss = lo1;
goto xx;
}
}
if (lo2 == hi2) {
cout << 1 << " " << lo2 << " " << ans << endl;
fflush(stdout);
string s;
cin >> s;
if (s[0] == 'T') {
anss = lo2;
goto xx;
}
}
while (lo1 < hi1) {
md1 = (lo1 + hi1) / 2;
md2 = md1 + 1;
cout << 1 << " " << md1 << " " << md2 << endl;
fflush(stdout);
string s;
cin >> s;
if (hi1 - lo1 == 1) {
if (s[0] == 'T') {
anss = md1;
} else
anss = md2;
break;
} else {
if (s[0] == 'T') {
hi1 = md1;
} else {
lo1 = md2;
}
}
if (lo1 == hi1) {
anss = lo1;
break;
}
}
if (anss == ans - 1) {
cout << 1 << " " << anss << " " << ans << endl;
fflush(stdout);
string s;
cin >> s;
if (s[0] == 'T') {
goto xx;
}
} else if (anss != -1) {
goto xx;
}
while (lo2 < hi2) {
md1 = (lo2 + hi2) / 2;
md2 = md1 + 1;
cout << 1 << " " << md1 << " " << md2 << endl;
fflush(stdout);
string s;
cin >> s;
if (hi2 - lo2 == 1) {
if (s[0] == 'T') {
anss = md1;
} else
anss = md2;
break;
} else {
if (s[0] == 'T') {
hi2 = md1;
} else {
lo2 = md2;
}
}
if (lo2 == hi2) {
anss = lo2;
break;
}
}
}
xx:
cout << 2 << " " << ans << " " << anss << endl;
fflush(stdout);
return 0;
}
| 2,200 | CPP |
"""
Author: Q.E.D
Time: 2020-03-31 08:38:46
"""
T = int(input())
for _ in range(T):
a, b, c, d= list(map(int, input().split()))
x, y, x1, y1, x2, y2 = list(map(int, input().split()))
ans = True
d_x = b - a
d_y = d - c
ans = ans & ((x + min(b, 1) <= x2) or (x - min(a, 1) >= x1))
ans = ans & ((y + min(d, 1) <= y2) or (y - min(c, 1) >= y1))
ans = ans & (x + d_x >= x1) & (x + d_x <= x2) & (y + d_y >= y1) & (y + d_y <= y2)
print('Yes' if ans else 'No') | 1,100 | PYTHON3 |
import math
import sys
input = sys.stdin.readline
n = int(input())
def isPrime(n):
for i in range(2, n):
if n % i == 0:
return False
return True
if isPrime(n):
print('YES')
print('\n'.join(list(map(str, [1] + [i * pow(i - 1, n - 2, n) % n for i in range(2, n)] + [n]))[:n]))
elif n == 4:
print('YES')
print('\n'.join(map(str, [1, 3, 2, 4])))
else:
print('NO')
| 2,300 | PYTHON3 |
def Input():
tem = input().split()
ans = []
for it in tem:
ans.append(int(it))
return ans
T = Input()[0]
for t in range(T):
n = Input()[0]
s = input()
i = 0
while i<n and s[i]=='P':
i+=1
if i==n:
print(0)
continue
MAX = 0
tem = 0
while i<n:
if s[i]=='A':
MAX = max(MAX,tem)
tem = 0
else:
tem+=1
i+=1
MAX = max(MAX, tem)
print(MAX) | 800 | PYTHON3 |
n = int(input())
a = list(map(int, list(input())))
ans = []
prime = [2, 3, 5, 7]
for i in range(n):
if a[i] in prime:
ans.append(a[i])
else:
if a[i] == 9:
ans.extend([7, 3, 3, 2])
elif a[i] == 8:
ans.extend([7, 2, 2, 2])
elif a[i] == 6:
ans.extend([5, 3])
elif a[i] == 4:
ans.extend([3, 2, 2])
ans.sort(reverse=True)
for i in ans:
print(i, end='')
print('') | 1,400 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int l, b, k, ans = 0, m, n, i;
cin >> l >> b >> k;
for (i = 0; i < k; i++) {
n = l - (i * 2) * 2;
m = b - (i * 2) * 2;
ans += 2 * (m + n - 2);
}
cout << ans << endl;
}
| 800 | CPP |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
long long POW(long long a, long long b, long long MMM = MOD) {
long long ret = 1;
for (; b; b >>= 1, a = (a * a) % MMM)
if (b & 1) ret = (ret * a) % MMM;
return ret;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) {
if (a == 0 || b == 0) return a + b;
return a * (b / gcd(a, b));
}
int dx[] = {0, 1, 0, -1, 1, 1, -1, -1}, dy[] = {1, 0, -1, 0, 1, -1, 1, -1};
map<int, int> M;
int go(int k) {
if (k == 0) return 0;
if (M.find(k) != M.end()) return M[k];
vector<int> v;
for (int(i) = (1); (i) <= (29); (i) += (1)) {
if (k >> (i - 1)) {
int nk = (k & ((1 << (i - 1)) - 1)) | (k >> i);
v.push_back(go(nk));
} else
break;
}
sort(v.begin(), v.end());
v.resize(unique(v.begin(), v.end()) - v.begin());
for (int(i) = (0); (i) <= ((int)v.size() - 1); (i) += (1))
if (v[i] != i) return M[k] = i;
return M[k] = v.size();
}
int n;
map<int, vector<int> > m;
int main() {
scanf("%d", &n);
for (int(i) = (1); (i) <= (n); (i) += (1)) {
int x;
scanf("%d", &x);
for (int j = 2; j * j <= x; j++) {
if (x % j == 0) {
int c = 0;
while (x % j == 0) {
c++;
x /= j;
}
m[j].push_back(c);
}
}
if (x > 1) m[x].push_back(1);
}
int res = 0;
for (auto it = m.begin(); it != m.end(); it++) {
auto &v = it->second;
int t = 0;
for (auto y : v) t |= (1 << y);
res ^= go(t >> 1);
}
puts(res ? "Mojtaba" : "Arpa");
}
| 2,200 | CPP |
n=input()
count=0
for i in range(len(n)):
if n[i].islower():
count=count+1
y=len(n)-count
if y>count:
print(n.upper())
else:
print(n.lower()) | 800 | PYTHON3 |
l1=list(map(int, input().split()))
l1.sort()
print(l1[-1]-l1[0], l1[-1]-l1[1], l1[-1]-l1[2],) | 800 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, x, y;
cin >> a >> x >> y;
int boxH = y / a, boxNum;
if (y % a == 0)
cout << "-1\n";
else if (boxH == 0) {
if (((x == 0) && (y == 0)) || (abs(2 * x) >= a))
cout << "-1\n";
else
cout << "1\n";
} else {
if (boxH % 2 == 0) {
boxNum = (boxH / 2) * 3;
if ((x == 0) || (x >= a) || (x <= -a))
cout << "-1\n";
else if (x > 0)
cout << boxNum + 1;
else
cout << boxNum;
} else {
boxNum = ((boxH + 1) / 2) * 3 - 1;
if ((2 * x >= a) || (2 * x <= -a))
cout << "-1\n";
else
cout << boxNum;
}
}
return 0;
}
| 1,400 | CPP |
#------------------------template--------------------------#
import os
import sys
from math import *
from collections import *
# from fractions import *
# from heapq import*
from bisect import *
from io import BytesIO, IOBase
def vsInput():
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
ALPHA='abcdefghijklmnopqrstuvwxyz'
M=998244353
EPS=1e-6
def Ceil(a,b): return a//b+int(a%b>0)
def value():return tuple(map(int,input().split()))
def array():return [int(i) for i in input().split()]
def Int():return int(input())
def Str():return input()
def arrayS():return [i for i in input().split()]
#-------------------------code---------------------------#
# vsInput()
s = [int(i) for i in input()]
n = len(s)
ans = [0]*n
have = 0
for i in range(n-1,-1,-1):
if(not s[i]): have += 1
else:
if(have):
have -= 1
ans[i] = 1
print(*ans,sep="")
| 2,000 | PYTHON3 |
p=int(input())
n=input()
k=[]
for i in range(2,int(p**0.5)+1):
if p%i==0:
if p//i==i:
k.append(i)
else:
k.append(i)
k.append(p//i)
k.sort()
for i in k:
n=n[:i][::-1]+n[i:]
print(n[::-1])
| 900 | PYTHON3 |
x=[i for i in map(int,input().split())]
q=sorted(x)
a=q[0]
b=q[1]
c=q[2]
d=q[3]
s=[]
s.append(d-a)
s.append(d-b)
s.append(d-c)
print(*s,sep=' ')
| 800 | PYTHON3 |
from collections import deque
from collections import Counter
n = int(input())
a = list(map(int,input().split()))
mycounter = Counter(a).most_common()
ans = []
OO = mycounter[0][0]
MIN_index = a.index(OO)
for i in range(MIN_index-1,-1,-1):
if a[i] > OO:
ans.append([2,i,i+1])
elif a[i] < OO:
ans.append([1,i,i+1])
for i in range(MIN_index+1,n):
if a[i] > OO:
ans.append([2,i,i-1])
elif a[i] < OO:
ans.append([1,i,i-1])
print(len(ans))
for i,j,k in ans:
print(i,j+1,k+1) | 1,400 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int in(int &a, int &b, int &c, int &d) {
return scanf("%d%d%d%d", &a, &b, &c, &d);
}
int in(int &a, int &b, int &c) { return scanf("%d%d%d", &a, &b, &c); }
int in(int &a, int &b) { return scanf("%d%d", &a, &b); }
int in(long long &a) { return scanf("%lld", &a); }
int in(int &a) { return scanf("%d", &a); }
int in(char *s) { return scanf("%s", s); }
int in(char &s) { return scanf("%c", &s); }
int in(long double &a) { return scanf("%Lf", &a); }
const long double pi = acos((long double)-1);
const long long inf = 0x3f3f3f3f;
const long double eps = 1e-8;
const int N = 3.1e5;
const long long mod = 1e9 + 7;
int sign(long double a) { return a < -eps ? -1 : a > eps; }
int db_cmp(long double a, long double b) { return sign(a - b); }
int a[N], n, k, dp[N];
bool check(int x) {
int last = 0;
for (int i = k; i <= n; i++) {
int j = dp[i - k];
if (a[i] - a[j + 1] <= x) last = i;
dp[i] = last;
}
return dp[n] == n;
}
int main() {
in(n, k);
for (int i = 1; i <= n; i++) in(a[i]);
sort(a + 1, a + 1 + n);
int l = 0, r = 1e9, mid;
while (l <= r) {
mid = (l + r) / 2;
if (check(mid))
r = mid - 1;
else
l = mid + 1;
}
printf("%d\n", l);
return 0;
}
| 1,900 | CPP |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
template <typename T>
vector<T>& operator--(vector<T>& v) {
for (auto& i : v) --i;
return v;
}
template <typename T>
vector<T>& operator++(vector<T>& v) {
for (auto& i : v) ++i;
return v;
}
template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
for (auto& i : v) is >> i;
return is;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
for (auto& i : v) os << i << ' ';
return os;
}
template <typename T, typename U>
pair<T, U>& operator--(pair<T, U>& p) {
--p.first;
--p.second;
return p;
}
template <typename T, typename U>
pair<T, U>& operator++(pair<T, U>& p) {
++p.first;
++p.second;
return p;
}
template <typename T, typename U>
istream& operator>>(istream& is, pair<T, U>& p) {
is >> p.first >> p.second;
return is;
}
template <typename T, typename U>
ostream& operator<<(ostream& os, pair<T, U> p) {
os << p.first << ' ' << p.second;
return os;
}
template <typename T, typename U>
pair<T, U> operator-(pair<T, U> a, pair<T, U> b) {
return make_pair(a.first - b.first, a.second - b.second);
}
template <typename T, typename U>
pair<T, U> operator+(pair<T, U> a, pair<T, U> b) {
return make_pair(a.first + b.first, a.second + b.second);
}
template <typename T, typename U>
void umin(T& a, U b) {
if (a > b) a = b;
}
template <typename T, typename U>
void umax(T& a, U b) {
if (a < b) a = b;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin >> n;
vector<ll> a(n);
cin >> a;
vector<ll> dp(n + 1, 1e18);
dp[0] = 0;
dp[1] = a[0];
for (int i = 2; i <= n; ++i) {
dp[i] = min(dp[i], dp[i - 2] + a[i - 1]);
if (i >= 3) dp[i] = min(dp[i], dp[i - 3] + max(a[i - 1], a[i - 2]));
}
int x = n;
if (dp[n - 1] < dp[n]) x = n - 1;
vector<int> ans;
while (x > 0) {
if (x == 1 || dp[x] == dp[x - 2] + a[x - 1]) {
ans.push_back(x - 1);
ans.push_back(x - 2);
x -= 2;
} else {
ans.push_back(x - 2);
ans.push_back(x - 1);
ans.push_back(x - 3);
x -= 3;
}
}
ll s = min(dp[n - 1], dp[n]);
ll tot = 0;
vector<int> real_ans;
for (int k : ans) {
if (k < 0 || k + 1 >= n) continue;
ll m = min(a[k], a[k + 1]);
if (m) real_ans.push_back(k);
tot += m;
a[k] -= m;
a[k + 1] -= m;
}
assert(s == tot);
cout << real_ans.size() << '\n';
for (int k : real_ans) {
cout << k + 1 << '\n';
}
return 0;
}
| 3,200 | CPP |
#include <bits/stdc++.h>
using namespace std;
double p[210];
int a[210];
double d[210][210][410];
int main() {
int n, l, k;
cin >> n >> l >> k;
for (int i = 1; i <= n; i++) {
cin >> p[i];
p[i] /= 100;
}
int sum = 0;
for (int i = 1; i <= n; i++) {
cin >> a[i];
a[i]++;
sum += a[i];
}
d[1][1][a[1]] = p[1];
d[1][0][0] = 1 - p[1];
for (int i = 1; i < n; i++) {
for (int j = 0; j <= i; j++) {
for (int s = 0; s <= 201; s++) {
d[i + 1][j][s] += d[i][j][s] * (1 - p[i + 1]);
int ss = s + a[i + 1];
if (ss > 200) ss = 200;
d[i + 1][j + 1][ss] += d[i][j][s] * p[i + 1];
}
}
}
double ans = 0;
for (int j = 0; j <= n; j++) {
for (int s = 0; s <= 200; s++) {
if (j >= l && j <= k + s) ans += d[n][j][s];
}
}
printf("%.8lf\n", ans);
return 0;
}
| 1,800 | CPP |
#include <bits/stdc++.h>
using namespace std;
char c[181][181];
int n, m, i, j, ans;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
for (i = 1; i <= n; i++)
for (j = 1; j <= m; j++) cin >> c[i][j];
c[n][m + 1] = '.';
for (i = 1; i <= m; i++)
if ((c[n][i] == 'B') && (c[n][i + 1] == '.')) ans++;
cout << ans << '\n';
return 0;
}
| 1,200 | CPP |
#include <bits/stdc++.h>
using namespace std;
map<int, int> memo;
map<int, int> knd;
vector<int> v;
inline bool myf(pair<int, int> x, pair<int, int> y) { return x > y; }
void print_arr(int n, int m) {
vector<vector<int>> arr(n, vector<int>(m, 0));
vector<pair<int, int>> t1;
vector<int> t2;
int idx = 0;
for (auto xx : memo) t1.push_back({xx.second, xx.first});
sort(t1.begin(), t1.end(), myf);
for (auto xx : t1) {
for (int i = 0; i < min(xx.first, n); i++) t2.push_back(xx.second);
}
int x = 0, y = 0;
for (int i = 0; i < n * m; i++) {
if (arr[x][y]) x = (x + 1) % n;
arr[x][y] = t2[i];
x = (x + 1) % n;
y = (y + 1) % m;
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) cout << arr[i][j] << " ";
cout << '\n';
}
}
const int SZ = 400005;
int pre[SZ];
int main(void) {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
v.push_back(x);
memo[x]++;
}
int kmx = 0;
for (auto xx : memo) {
knd[xx.second]++;
kmx = max(kmx, xx.second);
}
for (int i = 1; i <= kmx; i++) {
if (knd.find(i) != knd.end())
pre[i] = pre[i - 1] + knd[i];
else
pre[i] = pre[i - 1];
}
for (int i = n; i > 0; i--) {
int stt = (int)sqrt(i);
int sz = memo.size();
int xx = 0;
for (int j = 1; j * j <= i; j++) {
xx += sz - pre[j - 1];
if (i % j) continue;
if (xx >= i) {
cout << i << '\n';
cout << j << " " << i / j << '\n';
print_arr(j, i / j);
return 0;
}
}
}
return 0;
}
| 2,300 | CPP |
import sys
import math
#to read string
get_string = lambda: sys.stdin.readline().strip()
#to read list of integers
get_int_list = lambda: list( map(int,sys.stdin.readline().strip().split()) )
#to read non spaced string and elements are integers to list of int
get_intList_from_str = lambda: list(map(int,list(sys.stdin.readline().strip())))
#to read non spaced string and elements are character to list of character
get_charList_from_str = lambda: list(sys.stdin.readline().strip())
#get word sepetared list of character
get_char_list = lambda: sys.stdin.readline().strip().split()
#to read integers
get_int = lambda: int(sys.stdin.readline())
#to print faster
pt = lambda x: sys.stdout.write(str(x))
#--------------------------------WhiteHat010--------------------------------#
n,k,x = get_int_list()
lst = sorted(get_int_list())
for i in range(k):
lst[~i] = x
print(sum(lst)) | 800 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int nmax = 500 + 18;
char mat[nmax][nmax];
int f[2][nmax][nmax];
int c[nmax][nmax];
int n, m, mod;
void add(int &a, int b) { a = ((long long)a + b) % mod; }
int main() {
scanf("%d%d%d", &n, &m, &mod);
for (int i = 0; i <= n; ++i) c[i][0] = 1;
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= i; ++j) {
c[i][j] = ((long long)c[i - 1][j - 1] + c[i - 1][j]) % mod;
}
for (int i = 1; i <= m; ++i) scanf("%s", mat[i] + 1);
bool suc = 0;
int rest1 = 0, rest2 = 0;
for (int i = 1; i <= n; ++i) {
int k = 0;
for (int j = 1; j <= m; ++j)
if (mat[j][i] == '1') ++k;
if (k > 2)
suc = 1;
else if (k == 0)
++rest2;
else if (k == 1)
++rest1;
}
f[m & 1][rest1][rest2] = 1;
for (int i = m; i < n; ++i) {
int nf = i & 1, pf = 1 - nf;
memset(f[pf], 0, sizeof(f[pf]));
for (int j = 0; j <= rest1 + rest2; ++j)
for (int k = 0; k <= rest2; ++k)
if (f[nf][j][k]) {
if (j >= 2) {
add(f[pf][j - 2][k], f[nf][j][k] * 1LL * c[j][2] % mod);
}
if (j >= 1 && k >= 1) {
add(f[pf][j][k - 1], f[nf][j][k] * 1LL * j % mod * k % mod);
}
if (k >= 2) {
add(f[pf][j + 2][k - 2], f[nf][j][k] * 1LL * c[k][2] % mod);
}
}
}
printf("%d\n", f[n & 1][0][0]);
return 0;
}
| 2,100 | CPP |
#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 1e6;
const long long MOD = 1e9 + 7;
bool tree = true;
set<long long> xs, ys;
long long binpow(long long a, long long p) {
if (p == 1) return a % MOD;
if (!p) return 1;
if (p & 1)
return (binpow(a, p - 1) * a) % MOD;
else
return (binpow(a, p / 2) * binpow(a, p / 2)) % MOD;
}
vector<char> used(MAXN, false);
map<long long, set<pair<long long, long long>>> x, y;
map<long long, pair<long long, long long>> cbyid;
vector<vector<long long>> g(MAXN);
void dfs(long long v, long long p = -1) {
if (used[v]) {
if (used[v] == 1) {
tree = false;
}
used[v] = 2;
return;
}
used[v] = true;
auto coords = cbyid[v];
xs.insert(coords.first);
ys.insert(coords.second);
for (auto i : g[v])
if (i != p) dfs(i, v);
used[v] = 2;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long n, id = 0;
cin >> n;
for (long long i = 0; i < n; ++i) {
long long xx, yy;
cin >> xx >> yy;
cbyid[id] = {xx, yy};
x[xx].insert({yy, id});
y[yy].insert({xx, id++});
}
for (auto i : y)
for (set<pair<long long, long long>>::iterator j = i.second.begin();
j != (i.second.end()); ++j)
if (next(j) != i.second.end())
g[j->second].push_back(next(j)->second),
g[next(j)->second].push_back(j->second);
for (auto i : x)
for (set<pair<long long, long long>>::iterator j = i.second.begin();
j != (i.second.end()); ++j)
if (next(j) != i.second.end())
g[j->second].push_back(next(j)->second),
g[next(j)->second].push_back(j->second);
long long ans = 1;
for (long long i = 0; i <= id - 1; ++i) {
dfs(i);
ans *= max(1ll,
(binpow(2, max(static_cast<size_t>(0), xs.size() + ys.size())) -
tree)) %
MOD;
ans %= MOD;
tree = true;
xs.clear(), ys.clear();
}
cout << ans;
return 0;
}
| 2,300 | CPP |
import sys
t = int(sys.stdin.readline().rstrip())
for _ in range(t):
a, b, c, d = list(map(int, sys.stdin.readline().strip().split(' ')))
if a + b > c + d:
print(a+b)
else:
print(c+d)
| 900 | PYTHON3 |
import math
def Origami():
n,k = map(int,input().split())
books = 0
books += math.ceil(2*n/k)+math.ceil(5*n/k)+math.ceil(8*n/k)
print (books)
Origami() | 800 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
struct rect {
long long x1, y1, x2, y2;
long long area() { return (x2 - x1) * (y2 - y1); };
};
rect c, a, b, d;
void enter() {
cin >> a.x1 >> a.y1 >> a.x2 >> a.y2;
cin >> b.x1 >> b.y1 >> b.x2 >> b.y2;
cin >> c.x1 >> c.y1 >> c.x2 >> c.y2;
}
void createD() {
d.x1 = max(b.x1, c.x1);
d.y1 = max(b.y1, c.y1);
d.x2 = min(b.x2, c.x2);
d.y2 = min(b.y2, c.y2);
}
long long overlap(rect ra, rect rb) {
long long x = max((long long)0, min(ra.x2, rb.x2) - max(ra.x1, rb.x1));
long long y = max((long long)0, min(ra.y2, rb.y2) - max(ra.y1, rb.y1));
return x * y;
}
void solve() {
long long res = a.area() - overlap(a, b) - overlap(a, c);
createD();
if (d.area() > 0) res += overlap(d, a);
if (res > 0)
cout << "YES";
else
cout << "NO";
}
int main() {
ios ::sync_with_stdio(0);
cin.tie(0);
cout << (fixed) << setprecision(9);
enter();
solve();
}
| 1,700 | CPP |
n, m=map(int,input().split())
l=[]
for i in range(m):
temp=list(map(int,input().split()))
a=temp[0]
b=1
for j in range(n):
if temp[j]>a:
a=temp[j]
b=j+1
l.append(b)
c=l.count(1)
d=1
for i in range(n):
if l.count(i+1)>c:
c=l.count(i+1)
d=i+1
print(d)
| 1,100 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int n, k;
vector<long long> dp, tmp;
vector<vector<long long> > a, sum;
long long ans;
void update(int l, int r) {
for (int i = l; i <= r; ++i) {
int sz = a[i].size();
for (int j = k; j >= sz; --j) dp[j] = max(dp[j], dp[j - sz] + sum[i][sz]);
}
}
void solve(int l, int r) {
if (l == r) {
int sz = a[l].size();
for (int i = 0; i <= min(k, sz); ++i) ans = max(ans, sum[l][i] + dp[k - i]);
return;
}
int mid = l + r >> 1;
vector<long long> tmp = dp;
update(l, mid);
solve(mid + 1, r);
dp = tmp;
update(mid + 1, r);
solve(l, mid);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> k;
dp.resize(k + 1), tmp.resize(k + 1);
a.resize(n), sum.resize(n);
for (int i = 0, m; i < n; ++i) {
cin >> m;
a[i].resize(m), sum[i].resize(m + 1);
for (int j = 0; j < m; ++j) {
cin >> a[i][j];
sum[i][j + 1] = sum[i][j] + a[i][j];
}
}
ans = 0;
solve(0, n - 1);
cout << ans << '\n';
return 0;
}
| 2,800 | CPP |
import math
def ri():
return map(int,input().split())
def li():
return list(map(int,input().split()))
def inp():
return int(input())
def si():
return input()
def pYes():
print("YES")
def pNo():
print("NO")
def plist(l):
print("".join(l))
t=int(input())
for t1 in range(t):
a,b= ri()
if a%2==0:
a+=2*b
print(a)
else:
for i in range(2,a+1):
if a%i==0:
break
print(a+i+(b-1)*2) | 900 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
const int mod = 10007;
long long a[maxn], b[maxn];
int main() {
long long n, m, ta, tb, k;
cin >> n >> m >> ta >> tb >> k;
for (int i = 0; i < n; i++) scanf("%lld", &a[i]), a[i] = a[i] + ta;
for (int i = 0; i < m; i++) scanf("%lld", &b[i]);
int p = 0;
int flag1 = 0;
long long ans = 0;
if (k >= n || k >= m) flag1 = 1;
for (int i = 0; i < n && k >= 0; i++, k--) {
int idx = m - (lower_bound(b, b + m, a[i]) - b);
if (idx <= k) {
flag1 = 1;
break;
} else {
int s = lower_bound(b, b + m, a[i]) - b;
ans = max(b[s + k] + tb, ans);
}
}
if (flag1)
cout << -1 << endl;
else
cout << ans << endl;
}
| 1,600 | CPP |
#include <bits/stdc++.h>
int a[21], n;
int main() {
int i;
scanf("%d%d%d", &a[0], &a[1], &n);
for (i = 2; i <= n; i++) a[i] = a[i - 2] + a[i - 1];
printf("%d\n", a[n]);
}
| 1,600 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, m;
char str[6000000];
int f[20] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int que[6000000];
int head = 0;
int tail = 0;
void init() {
for (int i = 1; i <= 12; i++) f[i] += f[i - 1];
}
int main() {
init();
int year, month, day, hh, mm, ss;
int ayear, amonth, aday, ahh, amm, ass;
scanf("%d%d\n", &n, &m);
bool flag = true;
while (gets(str)) {
sscanf(str, "%d-%d-%d %d:%d:%d", &year, &month, &day, &hh, &mm, &ss);
int tim = ss + mm * 60 + hh * 3600 + (day - 1) * 3600 * 24 +
f[month - 1] * 3600 * 24;
que[tail++] = tim;
while (tim - que[head] >= n) head++;
if (flag && tail - head >= m) {
flag = false;
ayear = year;
amonth = month;
aday = day;
ahh = hh;
amm = mm;
ass = ss;
}
}
if (flag)
printf("-1\n");
else
printf("%04d-%02d-%02d %02d:%02d:%02d\n", ayear, amonth, aday, ahh, amm,
ass);
}
| 2,000 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
int n, ans, sum, a, b, arr[100005];
string str;
int main() {
ios::sync_with_stdio(false);
{
for (int i = 0; i < 3; i++) {
cin >> arr[i];
}
cin >> n;
sort(arr, arr + 3);
if (arr[1] - arr[0] < n) {
ans += (n - (arr[1] - arr[0]));
}
if (arr[2] - arr[1] < n) {
ans += (n - (arr[2] - arr[1]));
}
cout << ans;
}
return 0;
}
| 800 | CPP |
GL = 'aoyeui'
stroke = str(input()).lower()
for i in GL:
stroke = stroke.replace(i, '')
print('.' + '.'.join(list(stroke))) | 1,000 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T abs(T a) {
return ((a < 0) ? -a : a);
}
template <typename T>
inline T sqr(T a) {
return a * a;
}
const int INF = (int)1E9 + 7;
const long double EPS = 1E-9;
const long double PI = 3.1415926535897932384626433832795;
const int NMAX = 2010;
int n;
char s[NMAX][NMAX], ts[NMAX][NMAX];
int a[NMAX], r[NMAX], c[NMAX], tr[NMAX], tc[NMAX];
void rot(char s[NMAX][NMAX]) {
for (int i = 0; i < int(n); ++i)
for (int j = 0; j < int(n); ++j) ts[n - 1 - j][i] = s[i][j];
for (int i = 0; i < int(n); ++i)
for (int j = 0; j < int(n); ++j) s[i][j] = ts[i][j];
}
int solve(char s[NMAX][NMAX], int r[NMAX], int c[NMAX]) {
memset(r, 0, sizeof(int) * NMAX);
memset(c, 0, sizeof(int) * NMAX);
vector<pair<int, int> > q;
int ans = 0;
for (int j = int(n) - 1; j >= 0; --j) {
if (j == 0) break;
int ci = 0, cj = j;
vector<pair<int, int> > q;
while (cj < n) {
int col = s[ci][cj] ^ r[ci] ^ c[cj];
if (col == 1) {
ans++;
q.push_back(make_pair(ci, cj));
}
cj++, ci++;
}
for (int i = 0; i < int(int((q).size())); ++i)
r[q[i].first] ^= 1, c[q[i].second] ^= 1;
}
return ans;
}
int main() {
scanf("%d", &n);
gets(s[0]);
for (int i = 0; i < int(n); ++i) {
gets(s[i]);
for (int j = 0; j < int(n); ++j) s[i][j] -= '0';
}
int ans = solve(s, r, c);
rot(s), rot(s);
ans += solve(s, tr, tc);
rot(s), rot(s);
for (int i = 0; i < int(n); ++i)
ans += int((s[i][i] ^ tr[n - i - 1] ^ tc[n - i - 1] ^ r[i] ^ c[i]) == 1);
cout << ans << endl;
return 0;
}
| 2,000 | CPP |
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
const long long mod = 1e9 + 7;
const long long INF = 1e18;
const int MAX = 1e5 + 10, N = 10005;
const int lim = 1 << 18;
int main() {
ios_base::sync_with_stdio(0);
int n;
while (cin >> n) {
set<int> s;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
if (x) s.insert(x);
}
cout << s.size() << "\n";
}
return 0;
}
| 800 | CPP |
from collections import defaultdict
def findLen(s):
N = len(s)
def checkFor(size):
left, right = 0, size-1
c = defaultdict(int)
for i in range(left, right+1):
c[s[i]] += 1
while right < N-1:
if c["1"]>0 and c["2"]>0 and c["3"]>0: return True
c[s[left]] -= 1
left += 1
right += 1
c[s[right]] += 1
if c["1"]>0 and c["2"]>0 and c["3"]>0: return True
else: return False
left, right = 0, N
while left < right:
mid = (left+right)//2
if checkFor(mid):
right = mid
else:
left = mid + 1
if left <N or left==N and checkFor(N): return left
else: return 0
t = int(input())
for i in range(t):
s = input()
print(findLen(s)) | 1,200 | PYTHON3 |
from sys import stdin
inp = lambda : stdin.readline().strip()
t = int(inp())
for _ in range(t):
n = int(inp())
a = [int(x) for x in inp().split()]
a.sort()
print(max(a[0]*a[1]*a[2]*a[3]*a[-1],a[0]*a[1]*a[-1]*a[-2]*a[-3],a[-1]*a[-2]*a[-3]*a[-4]*a[-5])) | 1,200 | PYTHON3 |
n = int(input())
mi1, ma1 = map(int, input().split())
mi2, ma2 = map(int, input().split())
mi3, ma3 = map(int, input().split())
ma = [ma1, ma2, ma3]
res = [mi1, mi2, mi3]
n -= sum(res)
for i in range(3):
if ma[i] - res[i] > n:
res[i] += n
break
n -= ma[i] - res[i]
res[i] = ma[i]
print(*res)
| 1,100 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
const int M = 10000005;
const int mo = 1000000007;
int pri[M / 10], mn[M], id[M];
vector<int> e[N];
int n, T, Q, dfn[N], ed[N];
int fa[N][20], dep[N];
int qx[N], qy[N], qL[N], qv[N];
int t[N * 2], vis[N], A[N], ans[N];
vector<int> vec[M / 10];
pair<int, int> q1[N], q2[N];
int power(int x, int y) {
int s = 1;
for (; y; y /= 2, x = 1ll * x * x % mo)
if (y & 1) s = 1ll * s * x % mo;
return s;
}
void change(int x, int v) {
for (; x <= 2 * n; x += x & (-x)) t[x] += v;
}
int ask(int x) {
int ans = 0;
for (; x; x -= x & (-x)) ans += t[x];
return ans;
}
void init() {
for (int i = (int)(2); i <= (int)(M - 1); i++) {
if (!mn[i]) mn[i] = i, pri[++*pri] = i;
for (int j = 1; j <= *pri && i * pri[j] < M; ++j) {
mn[i * pri[j]] = pri[j];
if (i % pri[j] == 0) break;
}
}
for (int i = (int)(1); i <= (int)(*pri); i++) id[pri[i]] = i;
}
void insert(int x, int id) {
for (; x != 1;) {
int v = mn[x];
for (; x % v == 0; x /= v)
;
vec[::id[v]].push_back(id);
}
}
void dfs(int x) {
dfn[x] = ++*dfn;
for (auto i : e[x])
if (i != fa[x][0]) {
fa[i][0] = x;
dep[i] = dep[x] + 1;
dfs(i);
}
ed[x] = ++*dfn;
}
int LCA(int x, int y) {
if (dep[x] < dep[y]) swap(x, y);
int tmp = dep[x] - dep[y];
for (int i = (int)(0); i <= (int)(18); i++)
if (tmp & (1 << i)) x = fa[x][i];
for (int i = (int)(18); i >= (int)(0); i--)
if (fa[x][i] != fa[y][i]) x = fa[x][i], y = fa[y][i];
return x == y ? x : fa[x][0];
}
void solve(int id) {
int top1 = 0, top2 = 0;
for (auto i : vec[id])
if (i < 0)
q2[++top2] = pair<int, int>(-i, qv[-i]);
else
q1[++top1] = pair<int, int>(i, A[i]);
for (; top1 && top2;) {
int tmp1 = 0, tmp2 = 0;
for (int i = (int)(1); i <= (int)(top1); i++) {
change(dfn[q1[i].first], -1);
change(ed[q1[i].first], 1);
}
for (int i = (int)(1); i <= (int)(top2); i++) {
int at = q2[i].first;
int val1 = ask(ed[qL[at]] - 1) - ask(ed[qx[at]] - 1);
int val2 = ask(ed[qL[at]]) - ask(ed[qy[at]] - 1);
ans[at] = 1ll * ans[at] * power(pri[id], val1 + val2) % mo;
}
for (int i = (int)(1); i <= (int)(top1); i++) {
change(dfn[q1[i].first], 1);
change(ed[q1[i].first], -1);
}
for (int i = (int)(1); i <= (int)(top1); i++) q1[i].second /= pri[id];
for (int i = (int)(1); i <= (int)(top2); i++) q2[i].second /= pri[id];
for (int i = (int)(1); i <= (int)(top1); i++)
if (q1[i].second % pri[id] == 0) q1[++tmp1] = q1[i];
for (int i = (int)(1); i <= (int)(top2); i++)
if (q2[i].second % pri[id] == 0) q2[++tmp2] = q2[i];
top1 = tmp1;
top2 = tmp2;
}
}
int main() {
init();
scanf("%d", &n);
for (int i = (int)(1); i <= (int)(n - 1); i++) {
int x, y;
scanf("%d%d", &x, &y);
e[x].push_back(y);
e[y].push_back(x);
}
dfs(1);
for (int i = (int)(1); i <= (int)(18); i++)
for (int j = (int)(1); j <= (int)(n); j++)
fa[j][i] = fa[fa[j][i - 1]][i - 1];
for (int i = (int)(1); i <= (int)(n); i++) {
scanf("%d", &A[i]);
insert(A[i], i);
}
scanf("%d", &Q);
for (int i = (int)(1); i <= (int)(Q); i++) {
scanf("%d%d%d", &qx[i], &qy[i], &qv[i]);
qL[i] = LCA(qx[i], qy[i]);
insert(qv[i], -i);
ans[i] = 1;
}
for (int i = (int)(1); i <= (int)(*pri); i++) solve(i);
for (int i = (int)(1); i <= (int)(Q); i++) printf("%d\n", ans[i]);
}
| 2,800 | CPP |
#include <bits/stdc++.h>
int main() {
int n, flag = 0;
scanf("%d", &n);
int arr[n];
for (int i = 0; i < n; i++) {
scanf("%d", &arr[i]);
}
if (n == 1) {
if (arr[0] == 1) {
printf("HARD");
flag = 2;
} else {
printf("EASY");
flag = 2;
}
}
if (n == 2) {
if (arr[0] == 1 && arr[1] == 1) {
printf("HARD");
flag = 2;
} else {
printf("EASY");
flag = 2;
}
}
if (n > 2) {
for (int i = 0; i < n; i++) {
if (arr[i] == 1) {
printf("HARD");
flag = 1;
break;
}
}
}
if (flag == 0) {
printf("EASY");
}
return 0;
}
| 800 | CPP |
L1 = [int(x) for x in input().split() ]
L2 = [int(x) for x in input().split() ]
L3 = [int(x) for x in input().split() ]
A, B = [int(x) for x in input().split() ]
r = max(L1[1:])
p1 = max(L2[1:])
p2 = min(L3[1:])
r2 =r *( ( p1 * B ) / ( p1*B + p2*A) )**0.5
print(f'{r2:.12f}') | 1,300 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, i, j, k = 1;
cin >> n;
if (n % 2 == 0)
k = 2;
else
k = 1;
cout << k;
}
| 1,200 | CPP |
import math
t=int(input())
for i in range(t):
n=int(input())
cal=n*n-4*n
if cal>=0:
cal=math.sqrt(cal)
b=(n+cal)/2
a=n-b
print('Y',a,b)
else:
print('N')
| 1,300 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int a[300100];
int b[300100];
vector<int> used;
int cnt[1000010];
int k;
long long rec(int l, int r) {
if (l >= r) return 0;
int m = (l + r) / 2;
long long res = rec(l, m) + rec(m + 1, r);
int sum1 = 0;
int sum2 = 0;
int max1 = 0;
int p = m + 1;
used.clear();
int maxMod = 0;
for (int i = m; i >= l; --i) {
sum1 += b[i];
if (sum1 >= k) sum1 -= k;
if (a[i] > max1) {
max1 = a[i];
maxMod = b[i];
}
while ((p <= r) && (a[p] <= max1)) {
sum2 += b[p];
if (sum2 >= k) sum2 -= k;
cnt[sum2]++;
used.push_back(sum2);
p++;
}
int c = maxMod;
c -= sum1;
if (c < 0) c += k;
res += cnt[c];
}
for (int i = (0); i < (used.size()); ++i) cnt[used[i]] = 0;
sum1 = 0;
sum2 = 0;
max1 = 0;
p = m;
maxMod = 0;
used.clear();
for (int i = m + 1; i <= r; ++i) {
sum2 += b[i];
if (sum2 >= k) sum2 -= k;
if (a[i] > max1) {
max1 = a[i];
maxMod = b[i];
}
while ((p >= l) && (a[p] < max1)) {
sum1 += b[p];
if (sum1 >= k) sum1 -= k;
cnt[sum1]++;
used.push_back(sum1);
p--;
}
int c = maxMod;
c -= sum2;
if (c < 0) c += k;
res += cnt[c];
}
for (int i = (0); i < (used.size()); ++i) cnt[used[i]] = 0;
return res;
}
int main() {
int n;
cin >> n >> k;
for (int i = (0); i < (n); ++i) scanf("%d", &a[i]);
for (int i = (0); i < (n); ++i) b[i] = a[i] % k;
long long res = rec(0, n - 1);
cout << res << endl;
return 0;
}
| 2,800 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long r, k, binom[300][300];
const long long MOD = 1e9 + 7;
long long mpow(long long b, long long e) {
long long res = 1;
for (long long k = 1; k <= e; k *= 2) {
if (k & e) res = (res * b) % MOD;
b = (b * b) % MOD;
}
return res;
}
long long count(long long t) {
long long res = 0;
for (int br = 0; br <= t; br++) {
int bc = t - br;
if (br > r || bc > r) continue;
long long cells = (r * br + r * bc - br * bc);
long long ways = (mpow(k - 1, cells) * mpow(k, r * r - cells)) % MOD;
ways = (ways * binom[r][br]) % MOD;
ways = (ways * binom[r][bc]) % MOD;
res = (res + ways) % MOD;
}
return res;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
for (int i = 0; i < 300; i++) binom[i][0] = 1;
for (int i = 1; i < 300; i++)
for (int j = 1; j <= i; j++)
binom[i][j] = (binom[i - 1][j - 1] + binom[i - 1][j]) % MOD;
cin >> r >> k;
long long tot = 0;
for (int i = 1; i <= r + r; i++) {
long long amt = count(i);
if (i % 2)
tot = (tot + amt) % MOD;
else
tot = (tot - amt) % MOD;
}
long long res = (mpow(k, r * r) - tot) % MOD;
cout << (res + MOD) % MOD << '\n';
}
| 2,300 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int i, j, k;
int count, sum;
int n, m, p, t;
vector<int> v;
int maxi, mini;
int tc, ora, orb;
string s, r;
int lens, lenr;
cin >> n;
int a[n], b[n];
for (i = 0; i < n; i++) {
cin >> a[i];
}
for (i = 0; i < n; i++) {
cin >> b[i];
}
maxi = INT_MIN;
for (i = 0; i < n; i++) {
ora = a[i];
orb = b[i];
maxi = max(maxi, ora + orb);
for (j = i + 1; j < n; j++) {
ora |= a[j];
orb |= b[j];
maxi = max(maxi, ora + orb);
}
}
cout << maxi << endl;
return 0;
}
| 900 | CPP |
r = int(input())
for x in range(r):
r1 = input()
if(len(r1)>10):
print(r1[0] + str(len(r1)-2) + r1[-1])
else:
print(r1) | 800 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int n;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
int x = n / 3;
x *= 2;
if (n % 3) x++;
cout << x << "\n";
return 0;
}
| 800 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const int N = 200000;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int a, b;
cin >> a >> b;
int c = 1;
while (1) {
if (a < c) {
cout << "Vladik\n";
return 0;
}
a -= c++;
if (b < c) {
cout << "Valera\n";
return 0;
}
b -= c++;
}
return 0;
}
| 800 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
long long int n, s;
cin >> n >> s;
long long int a[n + 1];
for (int i = 1; i <= n; i++) cin >> a[i];
long long int x = 1;
int i = 1;
while (i <= n) {
if (a[i] > a[x]) x = i;
s -= a[i];
if (s < 0) break;
i++;
}
if (s >= 0)
cout << 0 << endl;
else
cout << x << endl;
}
}
| 1,300 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
string s;
cin >> s;
int n = int((s).size()), u = 0;
for (int i = 0; i < int(n); i++)
if (s[i] == '1') u++;
int k = 0;
while (k < n && s[k] != '2') {
if (s[k] == '0') cout << 0;
k++;
}
for (int _ = 0; _ < int(u); _++) cout << 1;
for (int i = (int)(k); i < (int)(n); i++)
if (s[i] != '1') cout << s[i];
cout << '\n';
return 0;
}
| 1,400 | CPP |
for _ in range(int(input())):
n = int(input())
p = list(map(int, input().split()))
s = input()
liked = []
disliked = []
for i in range(n):
if s[i]=="1":
liked.append([p[i],i])
else:
disliked.append([p[i],i])
liked.sort()
disliked.sort()
perm = 1
final = [0]*n
for _ in disliked:
final[_[1]] = perm
perm+=1
for _ in liked:
final[_[1]] = perm
perm+=1
print(*final) | 1,000 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
scanf("%d", &n);
int sum = 0;
int par[110];
for (int i = 0; i < n; i++) {
scanf("%d", &par[i]);
sum += par[i];
}
if (par[0] * 2 - sum > 0) {
printf("1\n1\n");
return 0;
}
int ret = par[0];
int index[110];
int pos = 0, mark = 0, cnt = 1, flag = 0;
for (int i = 1; i < n; i++) {
if (par[0] >= par[i] * 2) {
mark = 1;
ret += par[i];
index[pos++] = i + 1;
cnt++;
if (ret * 2 > sum) {
flag = 1;
break;
}
}
}
if (mark == 0 || flag == 0) {
printf("0\n");
return 0;
}
printf("%d\n1", cnt);
for (int i = 0; i < pos; i++) printf(" %d", index[i]);
printf("\n");
return 0;
}
| 800 | CPP |
#include <bits/stdc++.h>
using namespace std;
struct store {
long long k, p, c;
store() {}
store(long long k, long long p, long long c) : k(k), p(p), c(c) {}
};
bool operator<(const store& a, const store& b) { return a.p < b.p; }
bool is_fit(vector<store>& stores,
vector<pair<long long, long long>>& distances, long long ind,
long long r, long long a, vector<long long>& distC) {
int i;
for (i = 0; i < stores.size() && r > 0 && a >= 0; ++i) {
if (distC[stores[i].c] <= distances[ind].first) {
r -= stores[i].k;
a -= stores[i].p * stores[i].k;
}
}
--i;
if (r <= 0)
if ((a += abs(r) * stores[i].p) >= 0) return true;
return false;
}
int main() {
long long n, m;
cin >> n >> m;
vector<vector<long long>> cities(n);
for (int i = 0; i < m; ++i) {
int e, v;
cin >> e >> v;
--e;
--v;
cities[e].push_back(v);
cities[v].push_back(e);
}
long long w;
cin >> w;
vector<store> stores(w);
for (int i = 0; i < w; ++i) {
int c, k, p;
cin >> c >> k >> p;
--c;
stores[i] = store(k, p, c);
}
sort(stores.begin(), stores.end());
int q;
cin >> q;
for (int i = 0; i < q; ++i) {
long long g, r, a;
cin >> g >> r >> a;
--g;
vector<char> visited(n);
vector<pair<long long, long long>> distances;
vector<long long> distC(n, 999999999);
queue<pair<long long, long long>> que;
que.push(make_pair(g, 0));
int max_dist = 0;
while (!que.empty()) {
auto ind = que.front();
max_dist = max_dist < ind.second ? ind.second : max_dist;
distances.emplace_back(ind.second, ind.first);
distC[ind.first] = ind.second;
que.pop();
visited[ind.first] = 1;
for (int j = 0; j < cities[ind.first].size(); ++j) {
if (!visited[cities[ind.first][j]]) {
que.push(make_pair(cities[ind.first][j], ind.second + 1));
visited[cities[ind.first][j]] = 1;
}
}
}
long long l = 0, right = distances.size();
while (l < right) {
long long mid = l + (right - l) / 2;
if (is_fit(stores, distances, mid, r, a, distC)) {
right = mid;
} else {
l = mid + 1;
}
}
if (l == right) {
if (l == distances.size()) {
cout << -1 << endl;
} else {
cout << distances[l].first << endl;
}
} else {
cout << -1 << endl;
}
}
return 0;
}
| 2,100 | CPP |
n,d=map(int,input().split())
a=list(map(int,input().split()))
m=int(input())
a.sort()
x=sum(a)
if m>n:
print(x-(m-n)*d)
elif m==n:
print(x)
else:
print(sum(a[:m])) | 1,000 | PYTHON3 |
st1 = input()
word = st1[0].upper()
print(word + st1[1:])
| 800 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int A[1020304];
int n;
int MAP[333][333];
void ADD(int b, int e, int wei) {
if (b > e) swap(b, e);
printf("%d %d %d\n", b, e, wei);
}
pair<int, int> ans[1020304];
int main() {
cin >> n;
if (n == 5) {
ADD(3, 2, 3);
ADD(2, 1, 5);
ADD(1, 4, 2);
ADD(4, 5, 3);
puts("3 4");
puts("3 5");
return 0;
}
memset(MAP, (0x3f3f3f3f), sizeof(MAP));
int ansn = 0;
int MOD = n % 6;
int i = 1;
if (MOD > 3) {
ADD(3, 4, 3);
ADD(4, 5, 7);
ADD(5, 2, 2);
ADD(2, 1, 5);
ans[++ansn] = make_pair(1, 3);
ans[++ansn] = make_pair(2, 3);
for (i = 4; i < MOD + 1; ++i) {
ADD(i + 1, i + 2, 7);
}
} else if (MOD > 1) {
ADD(1, 4, 7);
ADD(3, 4, 7);
ADD(2, 3, 1);
ans[++ansn] = make_pair(1, 2);
for (i = 3; i < MOD + 1; ++i) {
ADD(i + 1, i + 2, 7);
}
} else if (MOD) {
ADD(1, 2, 1);
i = 2;
}
for (; i + 5 <= n; i += 6) {
ADD(i + 4, i, 2);
ADD(i + 3, i + 1, 3);
if (i <= 2) ADD(i, i + 1, 7);
ADD(i, i + 2, 1);
ans[++ansn] = make_pair(i + 2, i + 3);
ans[++ansn] = make_pair(i + 3, i + 4);
if (i + 11 <= n) {
ADD(i + 4, i + 7, 5);
ADD(i + 6, i + 7, 7);
ADD(i + 5, i + 6, 1);
ans[++ansn] = make_pair(i + 4, i + 5);
} else {
ADD(i + 4, i + 5, 5);
ans[++ansn] = make_pair(i + 3, i + 5);
}
}
for (long long i = 1; i <= ansn; ++i) {
int b = ans[i].first, e = ans[i].second;
printf("%d %d\n", ans[i].first, ans[i].second);
}
return 0;
}
| 0 | CPP |
iniStr = input()
strLen = len(iniStr)
ans=str()
index = 0
while index<strLen :
theLower = iniStr[index].lower()
if theLower=='a' \
or theLower=='e' \
or theLower=='i' \
or theLower=='o' \
or theLower=='u' \
or theLower=='y':
index = index+1
continue
else :
ans = ans +'.'+theLower
index = index+1
print(ans) | 1,000 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, k, l, ans = INT_MAX;
map<int, pair<int, int> > m;
cin >> n >> k;
int a[n];
for (int i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
for (int i = 0; i < n; i++) {
l = 0;
while (a[i]) {
if (m[a[i]].first < k) m[a[i]].first++, m[a[i]].second += l;
a[i] /= 2, l++;
}
}
for (auto i : m) {
if ((i.second).first == k) ans = min((i.second).second, ans);
}
cout << ans;
return 0;
}
| 2,200 | CPP |
n=int(input())
c=list(map(int,input().split()))
pre=[0 for _ in range(n)]
pre[0]=c[0]
for i in range(1,n):
pre[i]=c[i]
pre[i]+=pre[i-1]
#print(pre)
if pre[-1]%3!=0:
print(0)
exit(0)
u,v=0,0
a=pre[-1]//3
for i in range(n):
if pre[i]==2*a and i!=n-1:
v+=u
if pre[i]==a:
u+=1
print(v) | 1,700 | PYTHON3 |
Subsets and Splits