solution
stringlengths 10
159k
| difficulty
int64 0
3.5k
| language
stringclasses 2
values |
---|---|---|
#include <bits/stdc++.h>
using namespace std;
int n, x, y, x2, y2;
int main() {
cin >> n >> x >> y >> x2 >> y2;
if (abs(x - x2) == n)
cout << n + min(2 * n - (y + y2), y + y2);
else if (abs(y - y2) == n)
cout << n + min(2 * n - (x + x2), x + x2);
else
cout << abs(x - x2) + abs(y - y2);
return 0;
}
| 1,300 | CPP |
import sys
input = sys.stdin.readline
I = lambda : list(map(int,input().split()))
t,=I()
for _ in range(t):
a,b,x,y,n=I()
o=(a+b-x-y)
tt=max(0,o-n)
fx=min(x+tt,a)
tt-=(fx-x)
fb=y
if tt:
fb=min(y+tt,b)
an=fx*fb
x,y=y,x;a,b=b,a
tt=max(0,o-n)
fx=min(x+tt,a)
tt-=(fx-x)
fb=y
if tt:
fb=min(y+tt,b)
an=min(fx*fb,an)
print(an) | 1,100 | PYTHON3 |
song = str(input())
def wards_of_song(song):
song = song.split('WUB')
list_of_song = []
for i in song:
if i != '':
list_of_song += [i]
return " ".join( list_of_song)
print( wards_of_song(song)) | 900 | PYTHON3 |
'''input
aBAcAba
'''
string = input().lower()
li = []
vowels = ['a', 'e', 'i', 'o', 'u', 'y']
for i in string:
if i in vowels:
continue
else:
li.append('.')
li.append(i)
print(''.join(li)) | 1,000 | PYTHON3 |
s=input().lower()
v='aeiouy'
for i in s:
if i not in v:
print('.'+str(i),end='')
| 1,000 | PYTHON3 |
def run():
n = int(input())
nums = [int(i) for i in input().split()]
nums.sort()
for i in range(1, n):
if nums[i] > (nums[i-1] + 1):
print("NO")
return
print("YES")
return
t = int(input())
for i in range(t):
run() | 800 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
template <typename C>
void MA(C& a, C b) {
if (a < b) a = b;
}
template <typename C>
void MI(C& a, C b) {
if (a > b) a = b;
}
const int P = 1e9 + 7;
int n, k;
bool isl(int a) {
if (a == 0) return 1;
return (a % 10 == 4 || a % 10 == 7) && isl(a / 10);
}
int w[102001];
int iw = -1;
map<int, int> m;
long long pot(long long a, long long w) {
long long r = 1;
while (w) {
if (w & 1) {
r *= a;
r %= P;
}
w /= 2;
a *= a;
a %= P;
}
return r;
}
long long sil[102001], odw[102001];
long long po(int a, int b) {
if (a < b || b < 0) return 0;
return sil[a] * odw[b] % P * odw[a - b] % P;
}
int main() {
scanf("%d%d", &n, &k);
sil[0] = 1;
for (int i = 0; i < n + 1; i++) {
sil[i + 1] = sil[i] * (i + 1) % P;
}
for (int i = 0; i < n + 1; i++) {
odw[i] = pot(sil[i], P - 2);
}
for (int i = 0; i < n; i++) {
int pom;
scanf("%d", &pom);
if (isl(pom)) {
auto x = m.find(pom);
if (x != m.end()) {
w[x->second]++;
} else {
iw++;
m[pom] = iw;
w[iw] = 1;
}
} else {
iw++;
w[iw] = 1;
}
}
iw++;
vector<int> a;
a.push_back(1);
int il1 = 0;
for (int i = 0; i < iw; i++) {
if (w[i] == 1) {
il1++;
} else {
a.push_back(0);
vector<int> b;
b.push_back(1);
for (int ii = 1; ii < a.size(); ii++) {
b.push_back((a[ii] + a[ii - 1] * 1ll * w[i]) % P);
}
swap(a, b);
}
}
long long wyn = 0;
while (a.size() < k + 1) a.push_back(0);
for (int i = 0; i < k + 1; i++) {
wyn += po(il1, i) * a[k - i] % P;
}
cout << wyn % P << "\n";
}
| 2,100 | CPP |
#include <bits/stdc++.h>
using namespace std;
int T, n, nxt[102][26], lst[26], tot[26];
char s[102], t[102];
int main() {
ios::sync_with_stdio(false);
cin >> T;
while (T--) {
int ans = 0, flg = 0;
memset(tot, 0, sizeof(tot));
cin >> n >> s + 1 >> t + 1;
for (int i = 1; i <= n; ++i) {
s[i] -= 'a', t[i] -= 'a';
++tot[s[i]], --tot[t[i]];
}
for (int i = 0; i < 26; ++i) {
if (tot[i] != 0) flg = 1;
}
if (flg)
ans = n + 1;
else {
memset(lst, -1, sizeof(lst));
for (int i = n; i >= 0; --i) {
for (int j = 0; j < 26; ++j) nxt[i][j] = lst[j];
lst[s[i]] = i;
}
for (int i = 1; i <= n; ++i) {
int w = 0, cnt = 0;
for (int j = i; j <= n; ++j) {
w = nxt[w][t[j]];
if (w < 0) break;
++cnt;
}
ans = max(ans, cnt);
}
}
cout << n - ans << endl;
}
return 0;
}
| 2,200 | CPP |