solution
stringlengths 10
159k
| difficulty
int64 0
3.5k
| language
stringclasses 2
values |
---|---|---|
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7, K = 150, INF = 1e9;
int dp[K][N];
long long a[N];
long long get(long long x, int i) {
if (i >= 60) return x;
return x & ((1LL << (i - 1)) - 1);
}
long long geti(long long x, int i) {
if (i >= 60) return 0;
return x & (1LL << (i - 1));
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
for (int k = 0; k < K; k++)
for (int i = 0; i < N; i++) dp[k][i] = INF;
dp[0][0] = 0;
int n;
cin >> n;
long long mx = 0;
for (int i = 1; i <= n; i++) {
cin >> a[i];
mx = max(mx, a[i]);
}
for (int i = 1; i <= n; i++) a[i] = mx - a[i];
for (int k = 1; k < K; k++) {
vector<int> order;
for (int i = 1; i <= n; i++) order.push_back(i);
sort(order.begin(), order.end(),
[&k](int i, int j) { return get(a[i], k) > get(a[j], k); });
for (int b = 0; b <= 1; b++) {
int cnt = 0, carry = 0;
for (int i = 1; i <= n; i++) {
bool bi = geti(a[i], k);
if (bi + b >= 2) carry++;
if (bi ^ b) cnt++;
}
dp[k][carry] = min(dp[k][carry], dp[k - 1][0] + cnt);
for (int pc = 1; pc <= n; pc++) {
int id = order[pc - 1];
bool bi = geti(a[id], k);
if (bi + b >= 2) carry--;
if (bi ^ b) cnt--;
if (bi ^ b ^ 1) cnt++;
if (b + bi + 1 >= 2) carry++;
dp[k][carry] = min(dp[k][carry], dp[k - 1][pc] + cnt);
}
}
}
int ans = INF;
for (int i = 0; i <= n; i++) {
ans = min(ans, dp[K - 1][i]);
}
cout << ans << endl;
}
| 3,100 | CPP |
import random
import sys
import os
import math
n = int (input())
arr = []
num = input()
arr = list(map(int, num.split(' ')))
maxnum = float('-inf')
for x in range(0, len(arr)):
if (arr[x] >= 0 and (not math.sqrt(arr[x]).is_integer()) and maxnum < arr[x]):
maxnum = arr[x]
elif (arr[x] < 0 and maxnum < arr[x]):
maxnum = arr[x]
print (int(maxnum)) | 900 | PYTHON3 |
from sys import stdin, stdout
cin = stdin.readline
cout = stdout.write
mp = lambda:list(map(int, cin().split()))
t, = mp()
for _ in range(t):
a, b, c = mp()
x = y = -1
if c > a:
x = 1
y = (a*b-c > 0)*b + (a*b-c <= 0) * -1
cout(str(x) + ' ' + str(y) + '\n')
| 1,000 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e9;
int32_t main() {
cin.tie(0);
ios::sync_with_stdio(0);
long long n;
cin >> n;
vector<long long> used(n + 1), a(n);
long long mx = n;
for (long long i = 0; i < n - 1; i++) {
cin >> a[i];
}
cout << a[0] << endl;
for (long long i = 0; i < n - 1; i++) {
used[a[i]] = 1;
if (i < n - 2 && !used[a[i + 1]]) {
cout << a[i] << " " << a[i + 1] << endl;
} else {
while (used[mx]) mx--;
cout << a[i] << " " << mx << endl;
used[mx] = 1;
}
}
}
| 2,200 | CPP |
t=int(input())
for i in range(t):
a,b,n=map(int,input().split())
z=n%3
if(z==0):
print(a)
elif(z==1):
print(b)
else:
print(a^b)
| 900 | PYTHON3 |
n = int(input())
numbers = []
for i in range(n):
numbers.append(int(input()))
for num in numbers:
if num == 1:
print(-1)
elif num == 2:
print(57)
else:
print("2" + "3" * (num - 2) + "9")
| 1,000 | PYTHON3 |
# import sys
# sys.stdin=open("input.in","r")
# sys.stdout=open("output.out","w")
x=int(input())
s=input()
p=0
for i in range(x):
if int(s[i])%2==0:
p=p+i+1
print(p) | 800 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
bool A[1000005];
int T[1000005];
int main() {
cin.sync_with_stdio(false);
int n;
cin >> n;
for (int i = 0; i < n; ++i) {
int a;
cin >> a;
A[a] = true;
}
int ret = 0;
for (int i = 1000002; i >= 1; --i) {
if (!A[i]) continue;
T[i] = 1;
for (int j = i + i; j <= 1000002; j += i) {
T[i] = max(T[i], 1 + T[j]);
}
ret = max(ret, T[i]);
}
cout << ret << '\n';
return 0;
}
| 1,500 | CPP |
n,a,b=map(int,input().split())
x=input()
x=x.split(' ')
cost=0
flag=-1
for i in range(n):
if x[i]=='2':
if x[n-1-i]=='2':
if a<b:
x[i]='0'
cost+=a
else:
x[i]='1'
cost+=b
else:
x[i]=x[n-1-i]
if x[i]=='0':
cost+=a
else:
cost+=b
for j in range(n):
if x[j]!=x[n-1-j]:
flag=0
if flag==-1:
print(cost)
else:
print('-1') | 1,000 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int n;
long long k;
long long k2;
long long a[1001];
long long gcd(long long a, long long b) {
if (a < b) swap(a, b);
if (b == 0) return a;
return gcd(b, a % b);
}
void read() {
cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
k2 = k;
}
vector<long long> factor;
vector<long long> mply;
void add_factor(long long p) {
if (factor.size() == 0 || factor[factor.size() - 1] != p) {
factor.push_back(p);
mply.push_back(1);
} else {
mply[mply.size() - 1]++;
}
}
void factor_k() {
while (k > 1) {
bool prime = true;
for (int i = 2; i < pow(k, 0.5) + 2; i++) {
if (k % i == 0) {
k /= i;
add_factor(i);
prime = false;
break;
}
}
if (prime == true) {
add_factor(k);
return;
}
}
}
long long ddd[10000];
long long small[1001001];
long long big[1001001];
long long index_to_div1(int index) {
long long ans = 1;
long long s = 1;
for (int i = 0; i < factor.size(); i++) {
s = (mply[i] + 1);
int w = index % s;
for (int j = 0; j < w; j++) ans *= factor[i];
index /= s;
}
return ans;
}
long long index_to_div(int index) { return ddd[index]; }
int div_to_index(long long div) {
if (div <= 1000000)
return small[div];
else
return big[k2 / div];
}
pair<long long, long long> dp[1001][10001];
int main() {
read();
if (k == 1) {
int ans = 0;
for (int i = 0; i < n; i++) {
if (a[i] < a[ans]) ans = i;
}
cout << 1 << endl << ans + 1;
return 0;
}
factor_k();
int max_div = 1;
for (int i = 0; i < mply.size(); i++) max_div *= (mply[i] + 1);
for (int i = 0; i < max_div; i++) {
ddd[i] = index_to_div1(i);
if (ddd[i] <= 1000000)
small[ddd[i]] = i;
else {
big[k2 / ddd[i]] = i;
}
}
dp[0][0].first = 0;
dp[0][0].second = 0;
for (int i = 1; i < max_div; i++) dp[0][i] = make_pair(999999, 999999);
long long f;
for (int i = 1; i <= n; i++) {
for (int d = 0; d < max_div; d++) {
f = index_to_div(d);
f = div_to_index(f / gcd(f, a[i - 1]));
dp[i][d] = min(dp[i - 1][d], make_pair(dp[i - 1][f].first + 1,
dp[i - 1][f].second + a[i - 1]));
}
}
if (dp[n][max_div - 1].first > 5000) {
cout << "-1";
return 0;
}
cout << dp[n][max_div - 1].first << endl;
int i = n + 1;
int d = max_div - 1;
while (i >= 0) {
i--;
if (d == 0) break;
if (dp[i][d] == dp[i - 1][d]) continue;
cout << i << " ";
d = div_to_index(index_to_div(d) / gcd(a[i - 1], index_to_div(d)));
}
}
| 2,600 | CPP |
# import sys,os
# sys.stdin = open('input.txt', 'r')
# sys.stdout = open('output.txt', 'w')
test=int(input())
def solve():
n=int(input())
arr=[int(i) for i in input().split()]
arr.sort()
for i in range(len(arr)-1):
if(arr[i+1]-arr[i]>=2):
print("NO")
return
print("YES")
while test:
solve()
test-=1 | 800 | PYTHON3 |
a,c=map(int,input().split())
def tern(a):
s,i='',0
while True:
if pow(3,i)>=a:
break
i+=1
if pow(3,i)>a:i-=1
for j in range(i,-1,-1):
t1=pow(3,j)
t2=a//t1
a-=t1*t2
s+=str(t2)
return s
t1,t2=tern(a),tern(c)
if len(t1)>len(t2):t2=(len(t1)-len(t2))*'0'+t2
elif len(t1)<len(t2):t1=(len(t2)-len(t1))*'0'+t1
s=''
for i in range(len(t1)):
t3=int(t2[i])-int(t1[i])
if t3==-1:t4='2'
elif t3==-2:t4='1'
else:t4=str(t3)
s+=t4
def tern1(a):
t1=len(a)
ans=0
for i in range(t1):
t2=int(a[-i-1])
t3=pow(3,i)
ans+=t2*t3
return ans
print(tern1(s))
| 1,100 | PYTHON3 |
w1, w2 = list(map(int, input().split()))
count = 0
while w1 <= w2:
w1 = w1*3
w2 = w2*2
count +=1
print(count) | 800 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
inline double D(const double &x, const double &y) {
return sqrt(x * x + y * y);
}
int main() {
double _x1, _y1, _x2, _y2;
long long A, B, C, x1, y1, x2, y2;
int i, n;
bool flag;
scanf("%lld%lld%lld", &A, &B, &C);
if (A < 0) {
A = -A;
B = -B;
C = -C;
}
if (B < 0) {
B = -B;
C = -C;
flag = true;
} else
flag = false;
scanf("%lld%lld%lld%lld", &x1, &y1, &x2, &y2);
if (flag) x1 = -x1, x2 = -x2;
if (x1 > x2) swap(x1, x2), swap(y1, y2);
if ((x1 == x2) || (y1 <= y2))
printf("%lld.000\n", x2 - x1 + ((long long)abs(y2 - y1)));
else {
_x1 = -((double)C + B * y1) / A;
_x2 = -((double)C + B * y2) / A;
_y1 = -((double)C + A * x1) / B;
_y2 = -((double)C + A * x2) / B;
if ((_x1 >= x1) && (_x1 <= x2))
if ((_x2 >= x1) && (_x2 <= x2))
printf("%.10lf\n", _x1 - x1 + x2 - _x2 + D(_x2 - _x1, y1 - y2));
else
printf("%.10lf\n", _x1 - x1 + _y2 - y2 + D(x2 - _x1, y1 - _y2));
else if ((_y1 >= y2) && (_y1 <= y1))
if ((_y2 >= y2) && (_y2 <= y1))
printf("%.10lf\n", y1 - _y1 + _y2 - y2 + D(x2 - x1, _y1 - _y2));
else
printf("%.10lf\n", y1 - _y1 + x2 - _x2 + D(_x2 - x1, _y1 - y2));
else
printf("%lld.000000\n", x2 - x1 + y1 - y2);
}
return 0;
}
| 1,900 | CPP |
p,q = list(map(int,input().split()))
a = []
if p==1 and q==1:
print(0)
elif p==1:
for i in range(q):
print(2+i,end= " ")
elif q==1:
for i in range(p):
print(2+i)
else:
for i in range(q):
a.append(2+i)
b = []
k = 2+q
b.append(a)
for i in range(p-1):
c = []
for j in range(q):
c.append(a[j]*k)
k+=1
b.append(c)
for i in b:
print(*i) | 1,400 | PYTHON3 |
"""
βββ βββββββ βββ βββββββ βββββββ βββ ββββββ
βββββββββββββββ βββββββββββββββββββββββββββββ
ββββββ ββββββ ββββββββββββββββββββββββββββ
ββββββ ββββββ βββββββ βββββββββ βββ βββββββ
βββββββββββββββ βββββββββββββββββ βββ βββββββ
βββ βββββββ βββ ββββββββ βββββββ βββ ββββββ
__ __ _
| \/ (_)_ __ ___ _ __
| |\/| | | '__/ _ \| '_ \
| | | | | | | (_) | | | |
|_| |_|_|_| \___/|_| |_|
"""
"""
ΠΡΠ°ΡΠΈΠ²ΠΎΠ΅ Π»ΡΡΡΠ΅, ΡΠ΅ΠΌ ΡΡΠΎΠ΄Π»ΠΈΠ²ΠΎΠ΅.
Π―Π²Π½ΠΎΠ΅ Π»ΡΡΡΠ΅, ΡΠ΅ΠΌ Π½Π΅ΡΠ²Π½ΠΎΠ΅.
ΠΡΠΎΡΡΠΎΠ΅ Π»ΡΡΡΠ΅, ΡΠ΅ΠΌ ΡΠ»ΠΎΠΆΠ½ΠΎΠ΅.
Π‘Π»ΠΎΠΆΠ½ΠΎΠ΅ Π»ΡΡΡΠ΅, ΡΠ΅ΠΌ Π·Π°ΠΏΡΡΠ°Π½Π½ΠΎΠ΅.
ΠΠ»ΠΎΡΠΊΠΎΠ΅ Π»ΡΡΡΠ΅, ΡΠ΅ΠΌ Π²Π»ΠΎΠΆΠ΅Π½Π½ΠΎΠ΅.
Π Π°Π·ΡΠ΅ΠΆΠ΅Π½Π½ΠΎΠ΅ Π»ΡΡΡΠ΅, ΡΠ΅ΠΌ ΠΏΠ»ΠΎΡΠ½ΠΎΠ΅.
Π§ΠΈΡΠ°Π΅ΠΌΠΎΡΡΡ ΠΈΠΌΠ΅Π΅Ρ Π·Π½Π°ΡΠ΅Π½ΠΈΠ΅.
ΠΡΠΎΠ±ΡΠ΅ ΡΠ»ΡΡΠ°ΠΈ Π½Π΅ Π½Π°ΡΡΠΎΠ»ΡΠΊΠΎ ΠΎΡΠΎΠ±ΡΠ΅, ΡΡΠΎΠ±Ρ Π½Π°ΡΡΡΠ°ΡΡ ΠΏΡΠ°Π²ΠΈΠ»Π°.
ΠΡΠΈ ΡΡΠΎΠΌ ΠΏΡΠ°ΠΊΡΠΈΡΠ½ΠΎΡΡΡ Π²Π°ΠΆΠ½Π΅Π΅ Π±Π΅Π·ΡΠΏΡΠ΅ΡΠ½ΠΎΡΡΠΈ.
ΠΡΠΈΠ±ΠΊΠΈ Π½ΠΈΠΊΠΎΠ³Π΄Π° Π½Π΅ Π΄ΠΎΠ»ΠΆΠ½Ρ Π·Π°ΠΌΠ°Π»ΡΠΈΠ²Π°ΡΡΡΡ.
ΠΡΠ»ΠΈ ΠΎΠ½ΠΈ Π½Π΅ Π·Π°ΠΌΠ°Π»ΡΠΈΠ²Π°ΡΡΡΡ ΡΠ²Π½ΠΎ.
ΠΡΡΡΠ΅ΡΠΈΠ² Π΄Π²ΡΡΠΌΡΡΠ»Π΅Π½Π½ΠΎΡΡΡ, ΠΎΡΠ±ΡΠΎΡΡ ΠΈΡΠΊΡΡΠ΅Π½ΠΈΠ΅ ΡΠ³Π°Π΄Π°ΡΡ.
ΠΠΎΠ»ΠΆΠ΅Π½ ΡΡΡΠ΅ΡΡΠ²ΠΎΠ²Π°ΡΡ ΠΎΠ΄ΠΈΠ½ ΠΈ, ΠΆΠ΅Π»Π°ΡΠ΅Π»ΡΠ½ΠΎ, ΡΠΎΠ»ΡΠΊΠΎ ΠΎΠ΄ΠΈΠ½ ΠΎΡΠ΅Π²ΠΈΠ΄Π½ΡΠΉ ΡΠΏΠΎΡΠΎΠ± ΡΠ΄Π΅Π»Π°ΡΡ ΡΡΠΎ.
Π₯ΠΎΡΡ ΠΎΠ½ ΠΏΠΎΠ½Π°ΡΠ°Π»Ρ ΠΌΠΎΠΆΠ΅Ρ Π±ΡΡΡ ΠΈ Π½Π΅ ΠΎΡΠ΅Π²ΠΈΠ΄Π΅Π½, Π΅ΡΠ»ΠΈ Π²Ρ Π½Π΅ Π³ΠΎΠ»Π»Π°Π½Π΄Π΅Ρ [^1].
Π‘Π΅ΠΉΡΠ°Ρ Π»ΡΡΡΠ΅, ΡΠ΅ΠΌ Π½ΠΈΠΊΠΎΠ³Π΄Π°.
Π₯ΠΎΡΡ Π½ΠΈΠΊΠΎΠ³Π΄Π° Π·Π°ΡΠ°ΡΡΡΡ Π»ΡΡΡΠ΅, ΡΠ΅ΠΌ ΠΏΡΡΠΌΠΎ ΡΠ΅ΠΉΡΠ°Ρ.
ΠΡΠ»ΠΈ ΡΠ΅Π°Π»ΠΈΠ·Π°ΡΠΈΡ ΡΠ»ΠΎΠΆΠ½ΠΎ ΠΎΠ±ΡΡΡΠ½ΠΈΡΡ β ΠΈΠ΄Π΅Ρ ΠΏΠ»ΠΎΡ
Π°.
ΠΡΠ»ΠΈ ΡΠ΅Π°Π»ΠΈΠ·Π°ΡΠΈΡ Π»Π΅Π³ΠΊΠΎ ΠΎΠ±ΡΡΡΠ½ΠΈΡΡ β ΠΈΠ΄Π΅Ρ, Π²ΠΎΠ·ΠΌΠΎΠΆΠ½ΠΎ, Ρ
ΠΎΡΠΎΡΠ°.
ΠΡΠΎΡΡΡΠ°Π½ΡΡΠ²Π° ΠΈΠΌΡΠ½ β ΠΎΡΠ»ΠΈΡΠ½Π°Ρ ΡΡΡΠΊΠ°! ΠΡΠ΄Π΅ΠΌ Π΄Π΅Π»Π°ΡΡ ΠΈΡ
Π±ΠΎΠ»ΡΡΠ΅!
"""
"""
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
"""
"""
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
ββββββββββββββββββββββββββββββββββββββββββ ββ ββ ββ ββ ββ ββ ββ ββ ββ ββ ββ ββ ββββββ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
"""
"""
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#@#@@#@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@##@M@M # #@@@M@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#@@@@#@@ @@@@@@M@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#@@### #@@B@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#@@B@@#@@@@@#M@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#@##@@M@#@@##@##@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#@@#M@@@@@##@M@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@##@@@@@@#@##@#@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#@@# @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@M@@ #
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#@@#@@#@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @# @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @# @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#@@#@@#@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@M@@ #
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#@@# @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ @@#@@#@@@@@@@@@@@@@@@@@#@@#@#@@@@@@@@@@@@@@@@@@@@@#@#@@@@@@@@@@@@@@@@@@@@@@@@@
@ #@@@@@@@@@@@@@@@@@@@@#@@@@@@#@@@@@@@@@@@@@@@@@#@#@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ @@#@#@@@@@@@@@@@@@@@@@@#@####@@@@@@@@@@@@@@@@@M@#@@#@#@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@#@#M@@@M@@@@@@@@@@@@@@@@@@@M@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#@M@#@#@@@@@@@@@@@@@@@@@@#@@@@@@@@@@@@@@@@@@@@@@@@M@@M@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@#@@#@@@@@@@@@@@@@@@@@@@@M@M@#@@@@@@@@@@@@@@@@@@@@@@@#@@@@@@@@@@@@@@@@@@@@@@@@
@@#@@#@@@@@@@@@@@@@@@@@@@@@@@M@ @M@@#@@@@@@@@@@@@@@@@@@@@@@@@@
@#@@@@@#@@@@@@@@@@@@@@@@@@@#@@ @@@@M@@@@@@@@@@@@@@@@@@@@@@@@
@@@#@@@##@@@#@@@@@#@@@@@##@@@@ #@#@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@####@@####@@@@#@@@@M@@@#@@# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@#@ @#@@#@@@ #@ @ #@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@# @@#@@ #@@#@@@@@@@@@@@@@@@@@@@@@@@@@
##@#@@ #M @# @@ @@M @@@@@@@@@@@@@@@@@@@@@@@@
@#@@@M #@ #@ # @@ @@@@@@@@@@@@@@@@@@@@@@@@
@@ @@#@@ ## @##@@ @@@@@@@@@@@@@@@@@@@@@@@@
@# @@M@ @@ @@@@@@@@@@@@@@@@@@@@@@@@
@@@##@@@ @@@@ @@@ @@ #@#@@#@@@@@@@@@@@@@@@@@
@@@@###@@###@@@@#@#@@@@#@@@ M@ #@ @ B @@@#@@@@@@@@@@@@@@@@@@@
@M@@@@@MM@@@@@M@@#@##@@@#@@M@B @# M@ @# #@ #@@#@@@@@@@@@@@@@@@@@@@
@#@#@@M@@M@@#@#@#@#@@#@#@#@@@@ @# @@ # @M @#@@@@@@@@@@@@@@@@@@@@@
@@@ @@@@#@##@ #@# @M # @ @ @@@@@#@@@@@@@@@@@@@@@@@
@@ @@ @#@@#@@#M #@@@@#@@@@@@@@@@@@@@@@@
M@# #@ @@@@##@@ @M@#M@@@#@@@@@@@@@@@@@@@@
@@@@ @@ @@@#@@@#@#@@@@@@@@@@@@@@@@
@# @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@M@H@@ @# @#@@@@#@@@#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@#@#@##@M@@@M@ @M#@@@@@#@@#@@#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
#M@@@##@@@@@@@@M@@@@#@@#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@#@@@@@M@#@M@@B#M@@M@###@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
###@@@@@@@@@# @#@@@@@@@#@@@#@##@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@#@@M@@@#@@#@#@@@@@@#@@@#@#@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#@M@#@#
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@M@@@@#
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#@@@@@#@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@M@@##
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#@@#@M
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@###@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@#@@@@@#@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@# #@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@# #@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
"""
"""
/ \ //\
|\___/| / \// \\
/0 0 \__ / // | \ \
/ / \/_/ // | \ \
@_^_@'/ \/_ // | \ \
//_^_/ \/_ // | \ \
( //) | \/// | \ \
( / /) _|_ / ) // | \ _\
( // /) '/,_ _ _/ ( ; -. | _ _\.-~ .-~~~^-.
(( / / )) ,-{ _ `-.|.-~-. .~ `.
(( // / )) '/\ / ~-. _ .-~ .-~^-. \
(( /// )) `. { } / \ \
(( / )) .----~-.\ \-' .~ \ `. \^-.
///.----..> \ _ -~ `. ^-` ^-_
///-._ _ _ _ _ _ _}^ - - - - ~ ~-- ,.-~
/.-~
"""
"""
____ _ _____
/ ___|___ __| | ___| ___|__ _ __ ___ ___ ___
| | / _ \ / _` |/ _ \ |_ / _ \| '__/ __/ _ \/ __|
| |__| (_) | (_| | __/ _| (_) | | | (_| __/\__ \
\____\___/ \__,_|\___|_| \___/|_| \___\___||___/
"""
"""
βββββββββββββββββββ
ββββββββββββββββββββ
ββββββββββββββββββββ
ββββββββββββββββββββ
ββββββββββββββββββββ
ββββββββββββββββββββ
ββββββββββββββββββββ
ββββββββββββββββββββ
ββββββββββββββββββββ
ββββββββββββββββββββ
ββββββββββββββββββββ
ββββββββββββββββββββ
ββββββββββββββββββββ
"""
"""
n = int(input())
os=0
ch=[]
for i in range(n):
m = int(input())
ch.append(m)
if ch[0]==10:
if 1 in ch:
print((len( ch[:ch.index(1)])))
break
else:
if 10 in ch:
print((len( ch[:ch.index(10)])))
break
"""
"""
n,m = map(int,input().split())
m = float(m)
mi = []
for i in range(n):
a,b = map(float,input().split())
mi.append((a*m)/b)
print(round(min(mi),6))
"""
"""
l = input().split()
l = set(l)
print(len(l))
"""
"""
x = input()
y = x[1:-1]
z = set(y.split(', '))
if x == "{}":
print(0)
else:
print(len(z))
"""
"""
n,k = map(int,input().split())
L = sorted(map(int, input().split()))
res = [L[0]]
for i in range(1,n):
if L[i] != L[i-1]:
res.append(L[i]-L[i-1])
l = len(res)
if k > l:
res += [0]*(k-l)
for i in range(k):
print(res[i])
"""
"""
from math import*
s,k = map(int,input().split(" "))
sq = input().split()
score = 0
pol = ""
for i in range(len(sq)):
if sq[i]>=sq[i-1]:
score+=1
print(ceil(score/len(sq))+ceil(score/len(sq)))
"""
"""
from math import*
s,k = map(int,input().split(" "))
sq = input().split()
score = 0
pol = ""
for i in range(len(sq)):
if sq[i]>=sq[i-1]:
score+=1
print(ceil(score/len(sq))+ceil(score/len(sq)))
"""
"""
st=list(input().split('+'))
st.sort()
for i in range(len(st)):
if i!=len(st)-1:
print(str(st[i])+'+',end='')
else:
print(str(st[i]))
"""
"""
a = input()
up = a.upper()
abc = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
print(abc[abc.find(up[0])]+a[1::])
"""
"""
n= int(input())
k = 0
for i in range(n):
p = input()
if p == "++X" or p == "X++":
k+=1
elif p == "--X" or p == "X--":
k-=1
print(k)
"""
"""
import math
c = 1
l = int(input())
g = ""
for i in range(l):
for s in range(1,l - i + 1):
g = g + " "
for j in range(0,i + 1):
if(i == 0 or j == 0):
c = 1
else:
c = c * (i - j + 1)/j
t = c
T=0
while(t != 0):
T = T + 1
t = int(math.floor(t/10))
p=0
while((p+T)!=4):
g = g + " "
p=p+1
g = g + str(int(math.floor(c)))
g = g + "\n"
print(g)
"""
"""
___ __ _ _
|_ _|_ __ / _| ___ _ __ _ __ ___ __ _| |_(_) ___ ___
| || '_ \| |_ / _ \| '__| '_ ` _ \ / _` | __| |/ __/ __|
| || | | | _| (_) | | | | | | | | (_| | |_| | (__\__ \
|___|_| |_|_| \___/|_| |_| |_| |_|\__,_|\__|_|\___|___/
"""
"""
from math import*
a1 = float(input())
a2 = float(input())
b = sqrt(a1**2 + a2**2)
print(b)
"""
"""
a1 = float(input())
a2 = float(input())
b = (a1**2 + a2**2)
import math
l = math.sqrt(b)
print(l)
"""
"""
n = int(input())
a=list(map(int,input().split(" ")))
b = []
for i in range(len(a)):
if i%2==0:
print(a[i],end=' ')
"""
"""
n = int(input())
a=list(map(int,input().split(" ")))
b = []
for i in range(len(a)):
if a[i]%2==0:
print(a[i],end=' ')
"""
"""
n = int(input())
a=list(map(int,input().split(" ")))
b = []
for i in range(len(a)):
if a[i]>0:
b.append(a[i])
print(len(b))
"""
"""
n = int(input())
a=list(map(int,input().split(" ")))
b = 0
for i in range(1,n):
if a[i]>a[i-1]:
b+=1
print(b)
"""
"""
n = int(input())
a=list(map(int,input().split(" ")))
b = 0
for i in range(1,n):
if a[i]>a[i-1]:
b+=1
print(b)
"""
"""
n = int(input())
a=list(map(int,input().split(" ")))
b = 0
for i in range(n-1):
if i == 0:
pass
elif a[i]>a[i-1]and a[i+1]< a[i]:
b+=1
print(b)
"""
"""
n = int(input())
a=list(map(int,input().split(" ")))
a.reverse()
for i in a:
print(i,end = " ")
"""
"""
n = int(input())
a=list(map(int,input().split(" ")))
print(max(a))
"""
"""
n = int(input())
a = list(map(int,input().split(" ")))
l = 0
q = []
for i in range(len(a)):
if a[i] in q:
pass
else:
l +=1
q.append(a[i])
print(l)
"""
"""
n = int(input())
a = list(map(int,input().split()))
x = int(input())
k =1
for i in range(len(a)):
k+=1
if x > a[i]:
print(i+1)
exit()
print(k)
"""
"""
a=list(map(int,input().split(" ")))
b = []
for i in range(len(a)):
if i%2==0:
print(a[i],end=' ')
"""
"""
a=list(map(int,input().split(" ")))
b = 0
for i in range(len(a)-1):
if i == 0:
pass
elif a[i]>a[i-1]and a[i+1]< a[i]:
b+=1
print(b)
"""
"""
a = list(map(int,input().split()))
print(max(a),a.index(max(a)))
"""
"""
ch = list(input())
if ch.count("h")>=1 and ch.count("e")>=1 and ch.count("l")>=2 and ch.count("o")>=1 and len(ch)!=53:
print("YES")
else:
print("NO")
"""
"""
from decimal import Decimal
x,y = map(Decimal,input().split(" "))
d = 1
while x < y and x - y < 0.000001 :
x += x * 70 / 100
d += 1
print(d)
"""
"""
n = int(input())
abc = "abcdefghijklmnopqrstuvwxyz"
s =""
for i in range(n):
k,v = map(int,input().split())
for i in range(k):
while len(s) <= k:
s += abc[:v]
if len(s)>k:
s = s[:-(len(s)-k)]
print(s,end="\n")
s=""
"""
"""
k = int(input())
l = int(input())
m = int(input())
n = int(input())
d = int(input())
lst = []
lst.append(k)
lst.append(l)
lst.append(m)
lst.append(n)
uron = 0
for i in range(len(lst)):
if d % lst[i] == 0:
uron+=lst[i]
print(uron)
"""
"""
n = int(input())
a = list(map(int,input().split()))
ch = 0
nch = 0
for i in range(len(a)):
if a[i] % 2 == 0:
ch+=1
else:
nch+=1
if ch > nch:
for i in range(len(a)):
if a[i] % 2 == 1:
print(a.index(a[i])+1)
else:
for i in range(len(a)):
if a[i]%2==0:
print(a.index(a[i])+1)
"""
"""
n,t = map(int,input().split())
oc = input()
for i in range (1,n):
if oc[i]=="B":
oc[i]=oc[i-1]
print(oc)
"""
"""
n = int(input())
o = 0
for i in range(n):
o += ((n-2) - (n % 2))//2
print(o)
"""
"""
sl = input()
abc = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
m=0
b=0
big = ""
for i in range(len(sl)):
if sl[i]== abc[abc.find(sl[i])]:
b+=1
else:
m +=1
if m>b:
big += sl.lower()
print(big)
elif b>m:
big += sl.upper()
print(big)
elif b==m:
big += sl.lower()
print(big)
"""
"""
n = int(input())
a = list(map(int,input().split()))
for i in range(n):
print(a.index(i+1)+1, end=' ')
"""
"""
n = int(input())
if n % 2 == 0 and n != 2 :
print("YES")
else:
print("NO")
"""
"""
a = input().replace("WUB"," ")
print(a)
"""
"""
a = int(input())
b = list(map(int,input().split()))
b.sort()
for i in b:
print(i,end=" ")
"""
"""
a,b = map(int,input().split())
o = 0
if a % 2 == 0:
o = a//2
else:
o = (a//2)+1
if b <= o:
print((1+((o-1)*2)))
else:
print(((o-1)*2))
"""
"""
a,b = map(int,input().split())
year = 0
while b>=a:
a*=3
b*=2
year+=1
print(year)
"""
"""
n,m = map(int,input().split())
m = float(m)
mi = []
for i in range(n):
a,b = map(float,input().split())
mi.append((a*m)/b)
print(min(mi))
"""
"""
n = int(input())
x = 0
for i in range(n):
a = input()
if a == "Tetrahedron":
x+=4
elif a == "Cube":
x+=6
elif a == "Octahedron":
x+=8
elif a == "Dodecahedron":
x+=12
elif a == "Icosahedron":
x+=20
print(x)
"""
"""
n= int(input())
a = list(map(int,input().split()))
for i in a:
if sum(a)>0:
print("HARD")
break
else:
print("EASY")
break
"""
"""
a,b = map(int,input().split())
c = list(map(int,input().split()))
bal = 0
for i in range(1,len(c)+1):
if b == len(c):
if c[i]>=c[b-1]:
bal +=1
else:
if c[i]>=c[b] and c[i]!= 0:
bal+=1
print(bal)
"""
"""
a,b =map(int, input().split())
y=list(map(int,input().split()))
for i in y:
if i<y[b-1] or i==0:
a-=1
print(a)
"""
"""
a,b=map(int,input().split())
c=b-(a+1)//2
if c > 0:
print(2*c)
else:
print(2*b-1)
"""
"""
a = input()
b = input()
a1 = a.lower()
b1 = b.lower()
o = 0
k = 0
if a1>b1:
o+=1
if b1>a1:
k+=1
print(o-k)
"""
"""
n=int(input())
p=input().split()
q=input().split()
m = p[1:]
j = q[1:]
if len(set(m+j))==n:
print("I become the guy.")
else:
print("Oh, my keyboard!")
"""
"""
a = set(input())
for i in range(len(a)):
a.remove()
if a == "hello":
print("YES")
else:
print("NO")
"""
"""
n = list(map(int,input()))
a = n.count(4)+n.count(7)
if a == 7 or a == 4:
print("YES")
else:
print("NO")
"""
"""
n = int(input())
b = input()
b = b.upper
abc = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
for i in range(len(b)):
if abc[i] in b:
print("YES")
else:
print("NO")
"""
"""
from math import*
n,a,b = list(map(int,input().split()))
pos = 0
for i in range(n):
if (a + b) % 2 == 0:
print(a+b)
break
else:
print(ceil((a+b)/2))
break
"""
"""
n = int(input())
ans = 0
for i in range(n):
a,b,c = map(str,input().split())
b = int(b)
for i in range(n):
if b == -b and c == "YES":
print("Impossible")
elif ans > b and c == "Y":
ans += 1
elif ans < b and c == "Y":
ans+=1
elif ans >= b and c == "Y":
ans+=1
elif ans <= b and c == "Y":
ans+=1
elif ans > b and c == "N":
break
elif ans < b and c == "N":
break
elif ans >= b and c == "N":
break
elif ans <= b and c == "N":
break
print(ans)
"""
"""
from math import*
n,k = map(int,input().split())
a = list(map(int,input().split()))
com = 0
for i in range(len(a)):
if a[i]+2 <= 5:
com += 0.333
print(ceil(com))
"""
"""
n,a,b = map(int,input().split())
d = []
s = 0
k = 1
for i in range(n-1):
if a == 0 and b == 0:
print(n)
exit()
d.append("*"*((a+i)) +"+"+"*"*(((b-i)-k)))
if len(d[i])<=n:
s+=1
print(s)
"""
"""
n,h =map(int, input().split())
for i in map(int, input().split()):
if i > h:
n+=1
print(n)
"""
"""
n = input()
a = input()
if a.count('A')> a.count('D'):
print('Anton')
elif a.count('A')<a.count('D'):
print('Danik')
else:
print('Friendship')
"""
"""
n = int(input())
a=[]
for i in range(n):
a.append(list(map(int,input().split())))
g = list(map(sum,a))
count=0
i=0
for j in g:
if j >=2:
count+=1
print(count)
"""
"""
n=int(input())
x=input()
c=0
for i in range(n-1):
if x[i] == x[i+1]:
c+=1
print(c)
"""
"""
k = list(map(int,input().split()))
t = input()
kal = 0
for i in range(len(t)):
if t[i]=="1":kal += k[0]
elif t[i]=="2":kal += k[1]
elif t[i]=="3":kal += k[2]
elif t[i] == "4":kal += k[3]
print(kal)
"""
"""
orient = input()
key = input()
keyboard = "poiuytrewq;lkjhgfdsa/.,mnbvcxz"
ans = ""
for i in range(len(key)):
if orient == "R":
ans += keyboard[keyboard.find(key[i])+1]
elif orient == "L":
ans += keyboard[keyboard.find(key[i])-1]
print(ans)
"""
"""
n,k = map(int, input().split())
abc = "abcdefghijklmnopqrstuvwxyz"
f = abc[:k]
s = f
while len(s) < n:
s += f
s = s[:n]
print(s)
"""
"""
n = int(input())
if n %2 == 0 or n == 2:
print("YES")
else:
print("NO")
"""
"""
mas = 0
while 1:
try:
a = input()
if ":" in a:
mas += len(a[a.find(":"):])
except EOFError:
print(mas)
"""
"""
a = input()
b = input()
c = str(int(a)+int(b))
if int(a.replace("0",""))+int(b.replace("0",""))== int(c.replace("0","")):
print("YES")
else:
print("NO")
"""
"""
s = input()
w = len(s)
n=int(input())
b=[]
for i in range(n):
wd=input()
if wd[:w]==s:
b.append(wd)
b.sort()
if len(b)==0:
print(s)
else:
print(min(b))
"""
"""
n = int(input())
ans = 0
for i in range(n):
x,a = map(int,input().split())
if x == -x and a:
ans += a
else:
ans+=a
print(ans)
"""
"""
from decimal import Decimal
n,m = map(int,input().split())
fst = []
scd = []
a=0
for i in range(1,n+1):
for j in range(1,m+1):
if (i+j)%5==0:
a+=1
print(a)
"""
"""
n,a = map(int,input().split())
ans = ""
for i in range(n):
b = list(map(str,input().split()))
for j in range(a):
if b[j] != "B" or b[j]!="W"or b[j]!="G":
ans += "#Color"
break
else:
ans += "#Black&White"
break
print(ans)
"""
"""
n=int(input())
num=0
a , b =[],[]
for i in range(n):
c=input().split()
a.append(c[0])
b.append(c[1])
for i in a:
num+=b.count(i)
print(num)
"""
"""
n = int(input())
b = input()
a = b.lower()
if a.count("a")>=1 and a.count("b")>=1 and a.count("c")>=1 and a.count("d")>=1 and a.count("e")>=1 and a.count("f")>=1 and a.count("g")>=1 and a.count("h")>=1 and a.count("i")>=1 and a.count("j")>=1 and a.count("k")>=1 and a.count("l")>=1 and a.count("m")>=1 and a.count("n")>=1 and a.count("o")>=1 and a.count("p")>=1 and a.count("q")>=1 and a.count("r")>=1 and a.count("s")>=1 and a.count("t")>=1 and a.count("u")>=1 and a.count("v")>=1 and a.count("w")>=1 and a.count("x")>=1 and a.count("y")>=1 and a.count("z")>=1:
print("YES")
else:
print("NO")
"""
"""
from math import*
n = int(input())
dig = []
for i in range(1,n+1):
if factorial(i-1) % i != i-1:
dig.append(i)
for j in range(1,len(dig)+1):
if dig[j] + dig[j-n%2-4] == n or dig[j] + dig[j-n%2-9] == n:
print(dig[j],dig[j-n%2-4])
"""
"""
a=input()
b=input()
s=input()
c=a+b
d=list(s)
e=list(c)
d.sort()
e.sort()
if d==e:
print('YES')
else:
print('NO')
"""
"""
def nextmiron(s):
s += '#'
cnt = 1
ret = ""
for i in range(1, len(s)):
if s[i] == s[i - 1]:
cnt += 1
else:
ret += str(cnt) + s[i - 1];
cnt = 1
return ret
"""
"""
n = list(map(int,input()))
for i in range(len(n)):
if n[i] > 0:
print(n[i],end="")
exit()
elif n[i]>n[i-1]:
n.remove(n[i])
for i in n:
print(n[i],end="")
"""
"""
n = list(map(int,input()))
a = 0
ans = 0
for i in range(len(n)):
a += n[i]+n[i-1]
ans += 1
if a in n:
break
print(ans+1)
"""
"""
from math import factorial as fal
a,b = map(int,input().split())
ans = 0
p = []
prime = []
for i in range(a,b+1):
if fal(i-1) % i == i-1:
p.append(i)
for i in range(len(p)):
if fal((int(str(p[i])[::-1]))-1)% int(str(p[i])[::-1]) == int(str(p[i])[::-1])-1:
ans += 1
print(ans)
"""
"""
a,b,c = map(int,input().split())
d = str(a/b)
if len(d)==3:
print(d+"0"*(c-1))
else:
print(round((a/b),c))
"""
"""
a = list(input())
n = 0
h = 'hello'
for i in range(len(a)):
if a[i] == h[n]:
n += 1
if n >= 5:
break
if n >= 5:
print('YES')
else:
print('NO')
"""
"""
from math import factorial as fal
a,b = map(int,input().split())
ans = 0
for i in range(a,b+1):
if fal(i-1) % i == i-1 and fal((int(str(i)[::-1]))-1) % int(str(i)[::-1]) == int(str(i)[::-1])-1:
ans += 1
if a == 1:
print(ans - 1)
exit()
print(ans)
"""
"""
l=list(map(int,input().split(' ')))
n,v=l[0],l[1:]
dp=[1]*(n+1)
inf=2**64
for i in range(n+1):
if i not in v: dp[i]=-inf
for i in range(n+1):
for j in v:
if i>j:
dp[i]=max(dp[i],dp[j]+dp[i-j])
print(dp[n])
"""
"""
p = list(map(int,input().split()))
q = set(p)
s = 0
for i in q:
s += p.count(i)-1
print(s)
"""
"""
a,b = map(int,input().split())
h = []
l = []
for i in range(b):
c = list(map(int,input().split()))
h.append(c)
h.sort()
for i in h:
if a > i[0]:
l.append(1)
a += i[1]
if len(l) == b:
print("YES")
else:
print("NO")
"""
"""
n,m=map(int,input().split())
ans=0
for i in range(1,n+1):
ans += int((i+m)/5)-int(i/5)
print(ans)
"""
"""
a = input()
if a[0]=="-":
print((a[0])+a[1],a[2])
else:
print(int(a[0]),int(a[1]))
"""
"""
from math import factorial as myfunct
a,b = map(int,input().split())
c = min(a,b)
print(myfunct(c))
"""
"""
a,b,c = map(int,input().split())
d = []
d.append(a)
d.append(b)
d.append(c)
d.sort()
print(d[2]-d[0])
"""
"""
n=int(input())
a=list(map(int,input().split()))
b = a[:]
b.reverse()
u = a.index(max(a))
l = n-1-b.index(min(a))
if u > l:
print(u+(n-1-l)-1)
else:
print(u+(n-1-l))
"""
"""
s=input().lower()
for i in "aeiouy":
s = s.replace(i,"")
print("."+".".join(s))
"""
"""
n = int(input())
maxi = 0
mini = 0
for i in range(n):
a,b = map(int,input().split())
maxi += a+b
mini += a//i
print(mini,maxi)
"""
"""
n = int(input())
last_zero = []
for i in range(n):
a = input()
if a[-1]=="0":
last_zero.append(a)
for i in range(len(last_zero)):
if last_zero[i].count("0")>last_zero[i-1].count("0"):
print(last_zero[i])
break
"""
"""
n = int(input())
for i in range(n):
a,b = map(int,input().split())
d = len(str(a+b))
if int(str(a)[-i])+int(str(b)[-i]) >= 10 and int(str(a)[-i])+int(str(b)[-i]) >= 10:
print(a+b-(10**(d-1)))
"""
"""
fcoin,coins = map(int,input().split())
l = fcoin
pirates = 0
while l <= coins:
l += fcoin +1
pirates+=1
print(pirates)
"""
"""
a,b = map(str,input().split("+"))
roman = ["I","II","III","IV","V","VI","VII","VIII","IX","X","XI","XII","XIII","XIV","XV","XVI","XVII","XVIII","XIX","XX"]
f = roman.index(a)+1
s = roman.index(b)+1
d = f+s
print(roman[d-1])
"""
"""
x = int(input())
j = 0
r =[]
l = []
for i in range(x):
y = [int(i) for i in list(input().split())]
if y[0]<0:
l.append(y)
else:
r.append(y)
r = sorted(r)
l = sorted(l, reverse = True)
j = 0
d =1 if len(r)>=len(l) else -1
while((d == 1 and len(r)>0) or (d==-1 and len(l)>0)):
if d ==1:
j += r[0][1]
r = r[1:]
d = -1
else:
j += l[0][1]
l = l[1:]
d = 1
print(j)
"""
"""
a=int(input())
b=int(input())
c=int(input())
d=int(input())
n=int(input())
ans=0
for i in range(1,n+1):
if i%a==0 or i%b==0 or i%c==0 or i%d==0:
ans+=1
print(ans)
"""
"""
n,m = map(int,input().split( ))
for i in range(n):
if i%2==0:
print('#'*m)
elif i%4==1:
print('.'*(m-1)+'#')
else:
print('#'+'.'*(m-1))
"""
"""
n = int(input())
a = list(map(int, input().split()))
print(sum(a)/n)
"""
"""
a,b = map(int, input().split())
r1 = min(a,b)
r2 = (max(a,b) - min(a,b)) // 2
print(r1,r2)
"""
"""
a = input()
b1,b2,b3,b4,b5 = map(str,input().split())
if a[-1] == b1[-1] or a[-1] == b2[-1] or a[-1] == b3[-1] or a[-1] == b4[-1] or a[-1] == b5[-1] or a[0] == b1[0] or a[0] == b2[0] or a[0] == b3[0] or a[0] == b4[0] or a[0] == b5[0]:
print("YES")
else:
print("NO")
"""
"""
n = int(input())
lo = []
for i in range(n):
a = int(input())
lo.append(a)
if sum(lo)-lo[-1] == lo[-1] or sum(lo) == 360:
print("YES")
else:
print("NO")
"""
"""
from math import*
n = int(input())
a = list(map(int,input().split()))
for i in range(len(a)):
if factorial(a[i]-1) % a[i] == a[i]-1:
print("YES")
else:
print("NO")
"""
"""
a,b = map(int,input().split())
ans = a
if a % b == 0:
ans += a//b
if (a//b) % 2 == 0:
ans += ans % b
print(ans)
"""
"""
a,b = map(int,input().split())
print(a+b)
"""
"""
a = input()
if set(a) == "ABC" or set(a) == ".ABC" or set(a) == "ABC.":
print(1)
else:
print(2)
print(set(a))
"""
"""
n = int(input())
a = list(map(int,input().split()))
ans = 0
for i in range(len(a)):
if a[i] >= a[-1]:
ans += 1
print(ans)
"""
"""
n,k = map(int,input().split())
i = 0
while 1:
i+=1
if (i // k)*(i % k) == n:
print(i)
break
"""
"""
a = input()
if "ABC" in a or "ACB" in a or "BAC" in a or "BCA" in a or "CAB" in a or "CBA" in a:
print('Yes')
else:
print('No')
"""
"""
s=''
for i in range(int(input())):
s=s+input()
print(s.count('11')+s.count('00')+1)
"""
"""
a = int(input())
b = [[0] * a for i in range(a)]
c = []
for i in range(a):
for j in range(a):
if i == 0 :
b[i][j] = 1
else:
b[i][j] = b[i - 1][j] + b[i][j -1]
for i in b:
c.append(max(i))
print(max(c))
"""
"""
a,b = map(int,input().split())
for i in range(b):
if a % 10 != 0:
a -= 1
elif a % 10 == 0:
a //= 10
print(a)
"""
"""
n = int(input())
ans = []
for i in range(100):
if int(str(i[0]))+ int(str(i[1]))== 10:
ans.append(i)
print(ans[n])
"""
"""
n=int(input())
a=input()
c=0
for i in range(n-2):
if a[i]+a[i+1]+a[i+2]=="xxx":
c+=1
print(c)
"""
"""
a = input()
b = input()
op = a.find("1")
op1 = b.find("1")
op2 = min(op,op1)
if a[0] == "0" and b[0] == "0":
print("0"*len(a[:op2])+str((int(a)+int(b))).replace("2","0"))
else:
print(str((int(a)+int(b))).replace("2","0"))
"""
"""
n = int(input())
if n % 2 != 0:
print(n//2)
print('2 '*(n//2-1)+'3')
else:
print(n//2)
print('2 '*(n//2))
"""
"""
a=int(input())
for i in range(a):
b,c,d = map(int,input().split())
if d >= min(b,c):
print(max(b,c)+(d-max(b,c)%d))
else:
print(d)
"""
"""
n = int(input().strip())
kras = input().strip()+'W'
k = []
l = 0
for i in range(n+1):
if kras[i] == 'B':
l += 1
elif l != 0:
k.append(str(l))
l = 0
print(len(k))
print(' '.join(k))
"""
"""
n = int(input())
a = list(map(int, input().split()))
for i in range(n):
if a[i] % 2 == 0:
a[i] = a[i] - 1
for i in a:
print(i, end = " ")
"""
"""
n,k = map(int, input().split())
s=1
d = n
while (n%10!=k and n%10!=0):
n+=d
s+=1
print(s)
"""
"""
n = int(input())
a = input()
b = []
can = 1
for i in range(n):
b.append(int(a[i]))
if a[i] != '4' and a[i] != '7':
can = 0
suma = 0
for i in range(n):
if i < n / 2:
suma += b[i]
else:
suma -= b[i]
if suma != 0 or can == 0:
print("NO")
else:
print("YES")
"""
"""
n,k = map(int,input().split())
if (n // k) % 2 == 1:
print("YES")
else:
print("NO")
"""
"""
n = int(input())
var = []
for i in range(10000):
if str(i) == str(i)[::-1] and len(str(i)) % 2 == 0 or len(str(i)) == 2:
var.append(i)
print(var[n])
"""
"""
a,b = map(int,input().split())
ans = []
tot=0
for i in range(999):
while i>0:
dig=i%10
tot+=dig
i //=10
if tot == b:
ans.append(i)
if len(ans)==0:
print(-1,-1)
exit()
print(min(ans),max(ans))
"""
"""
n = int(input())
seq = []
for i in range(1,10000):
seq.append(i*(-1)**i)
for i in range(n):
l,r = map(int,input().split())
print(sum(seq[l-1:r]))
"""
"""
from math import*
n = int(input())
a = list(map(int,input().split()))
for i in range(len(a)):
g = sqrt(a[i])
point = str(g).find(".")
if len(str(g)[point:])>2:
g = 100
if factorial(g-1) % g == g-1 and g != 1:
print("YES")
else:
print("NO")
"""
"""
n = int(input())
mishka = 0
Chris = 0
Friend = 0
for i in range(n):
a,b = map(int,input().split())
if a > b:
mishka += 1
elif b > a:
Chris += 1
elif a == b:
Friend += 1
if mishka > Chris:
print("Mishka")
elif Chris > mishka:
print("Chris")
elif Chris == mishka:
print("Friendship is magic!^^")
"""
"""
n = int(input())
ans = ["purple","green","blue","orange","red","yellow"]
ans1 = []
for i in range(n):
a = input()
ans1.append(a)
del(ans[ans.index(a)])
print(len(ans))
for i in range(len(ans)):
if ans[i] == "purple":
print("Power")
elif ans[i] == "green":
print("Time")
elif ans[i] == "blue":
print("Space")
elif ans[i] == "orange":
print("Soul")
elif ans[i] == "red":
print("Reality")
elif ans[i] == "yellow":
print("Mind")
"""
"""
a = input()
ans = 0
b = a
for i in range(len(a)):
if a == a[::-1]:
b = a[i:]
if b != b[::-1]:
ans = len(a)-i
break
elif a != a[::-1]:
ans = len(a)
elif a[i]==a[i-1]:
ans = 0
print(ans)
"""
"""
from math import*
d,h,v,e = map(int,input().split())
vol = (pi*(d/2)**2)
vol1= (pi/vol - pi)
if vol < vol1:
print("NO")
else:
print("YES")
print(pi/(vol-pi))
print(vol,vol1)
"""
"""
n = int(input())
if n == 1 or n == 2 or n == 3:
print(-1)
exit()
ans = [1,5,7,8,3,5,8,7]
for i in range(1,n-1):
for j in range(i,n-1):
if ans[j]>ans[j-1]:
ans[j-1],ans[j]=ans[j-1],ans[j]
"""
"""
a,b = map(int,input().split())
past = ""
ans =""
for i in range(a):
kl = input()
past += kl
if "W" in past:
l = past.replace(".","D")
for i in range(len(l)):
if i %b==0:
print(l[i])
else:
print(l[i],end='')
"""
"""
n = int(input())
code1 = input()
code2 = input()
password = "1234567890"
ans = 0
for i in range(len(code1)):
ans += len(password[password.find(code1[i]):password.find(code2[i])])
print(ans)
"""
"""
n = int(input())
a = input()
one = a.count("1")
zero = a.count("0")
print(abs(one-zero))
"""
"""
n = int(input())
a = input()
lol = ""
ans = ""
YN = ""
if a == "abb":
print("YES")
print("ab")
exit()
for i in a:
lol += i
if a[:] == a[0]*len(a):
YN += "NO"
else:
YN += "YES"
ans += lol[-(len(set(a))):]
print(YN)
print(ans)
"""
"""
n = int(input())
a = set(map(int,input().split()))
a = list
print(len(a))
lol = ""
for i in a:
lol += str(i)
lol += " "
for i in range(len(lol)):
kek = a.count(lol[i])
print(kek)
"""
"""
w,h,k = map(int,input().split())
ans = 0
for i in range(k):
if k == 1:
ans +=(((h*2)+(w-2)*2))
else:
ans +=(((h*2)+(w-2)*2)+((h-4*(k-1))*2)+((w-4*(k-1)-2)*2)) // 2
print(ans)
"""
"""
n = int(input())
mark = input().split()))
mark.sort()
ans = 0
if round((sum(mark)/n)+0.00001)==5:
print(0)
exit()
else:
for i in range(n):
mark[i] = 5
ans += 1
if round((sum(mark)/n)+0.000001) == 5:
print(ans)
break
"""
"""
n,m = map(int,input().split())
a = list(map(int,input().split()))
seta = list(set(a))
if len(set(a)) >= m:
print("YES")
for i in range(m):
print(a.index(seta[i])+1,end = " ")
else:
print("NO")
"""
"""
a=int(input())
b=int(input())
c=int(input())
b=b//2
c=c//4
if a<=b:
d=a
else
d=b
if d>c
d=c
d*=7
print(d)
"""
"""
a,b = list(map(int,input().split()))
print((a*b)//2)
"""
"""
n = int(input())
for i in range(n):
a,b = map(int,input().split())
print(a,a*2)
"""
"""
n,a=map(int,input().split())
m=list(map(int,input().split()))
ans=0
for i in range(6-a):
ans+=m.count(i)
ans//=3
print(ans)
"""
"""
n = int(input())
a = list(map(int, input().split()))
ans = []
ans1 = 1
for i in range(1, n):
if a[i] > a[i - 1]:
ans1 += 1
else:
ans.append(ans1)
ans1 = 1
ans.append(ans1)
print(max(ans))
"""
"""
n = int(input())
s = input()
decode = "*"*len(s)
k = ""
for i in range(len(s)):
if len(decode) %2== 0:
k += decode.replace(decode[(len(s)//2)-1],s[i])
else:
k += decode.replace(decode[(len(s)//2)],s[i])
print(k)
"""
"""
n=int(input())
s=input()
ans=""
if n%2==0:
for i in range(n):
if i%2==1:
ans+=s[i]
else:
ans=s[i]+ans
else:
for i in range(n):
if i%2==0:
ans+=s[i]
else:
ans=s[i]+ans
print(ans)
"""
"""
s = input()
srev = s[::-1]
print(srev+s)
"""
"""
n = int(input())
sumA = 0
sumB = 0
ans = ""
for i in range(n):
t,x,y = map(int,input().split())
if t == 1:
sumA += (x+y)
else:
sumB += (x+y)
if x >= sumA//2:
ans += "LIVE"
else:
ans += "DEAD"
if x >= sumB // 2:
ans += "LIVE"
else:
ans += "DEAD"
print(ans[:4*n])
"""
"""
n,c = map(int,input().split())
ques = list(map(int,input().split()))
time = list(map(int,input().split()))
radewoosh = 0
limak = 0
timecode = 0
for i in range(n):
timecode += time[i]
limak += max(0,ques[i]-c*timecode)
radewoosh = 0
timecode = 0
for i in range(n):
timecode += time[n-1-i]
radewoosh += max(0,ques[n-1-i]-c*timecode)
if radewoosh > limak:
print("Radewoosh")
elif radewoosh < limak:
print("Limak")
elif radewoosh == limak:
print("Tie")
"""
"""
s1 = input()
s2 = input()
s3 = input()
s3 = s3.lower()
kek = ""
ans = ""
for i in range(len(s3)):
if s3[i] == "1" or s3[i] == "2" or s3[i] == "3" or s3[i] == "4" or s3[i] == "5" or s3[i] == "6" or s3[i] == "7" or s3[i] == "8" or s3[i] == "9" or s3[i] == "0":
kek += s3[i]
for i in range(len(s3)-len(kek)):
ans += s2[s1.find(s3[i])]
print(ans+kek)
"""
"""
from math import*
n = int(input())
a = list(map(int,input().split()))
for i in range(len(a)):
g = sqrt(a[i])
point = str(g).find(".")
if len(str(g)[point:])>2:
g = 100
if factorial(g-1) % g == g-1 and g != 1:
print("YES")
else:
print("NO")
"""
n = int(input())
mina = n
maxi = n
while str(mina)[-1] != "0":
mina -= 1
while str(maxi)[-1] != "0":
maxi += 1
if max(maxi,mina) - n > n - min(maxi,mina):
print(mina)
else:
print(maxi)
| 800 | PYTHON3 |
"""""""""""""""""""""""""""""""""""""""""""""
| author: mr.math - Hakimov Rahimjon |
| e-mail: [email protected] |
"""""""""""""""""""""""""""""""""""""""""""""
#inp = open("lepus.in", "r"); input = inp.readline; out = open("lepus.out", "w"); print = out.write
TN = 1
# ===========================================
def solution():
n = int(input())
a = sorted(list(map(int, input().split())), reverse=True)
ans = 0
frst = 0
scnd = sum(a)
for i in range(n):
frst += a[i]
scnd -= a[i]
if frst > scnd:
print(i+1)
break
# ===========================================
while TN != 0:
solution()
TN -= 1
# ===========================================
#inp.close()
#out.close() | 900 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const double eps = 1e-6;
const int mod = 1000000007;
inline string getstr(string &s, int l, int r) {
string ret = "";
for (int i = l; i <= r; i++) ret.push_back(s[i]);
return ret;
}
int modpow(int x, int y, int md = mod) {
if (y == 0) return 1;
int ret = modpow(x, y >> 1, md);
ret = (long long)ret * ret % md;
if (y & 1) ret = (long long)ret * x % md;
return ret;
}
int n;
int a[1005];
int dp[1005][1 << 8];
int nxt[1005][205];
void init() {
memset(nxt, -1, sizeof nxt);
for (int i = 1; i <= n; i++) {
int cnt = 0;
for (int j = i; j <= n; j++) {
if (a[i] == a[j]) {
nxt[i][++cnt] = j;
}
}
}
}
inline void upd(int &x, int y) { x = max(x, y); }
int check(int low) {
memset(dp, -1, sizeof dp);
dp[1][0] = 0;
for (int i = 1; i <= n; i++) {
for (int mask = 0; mask < (1 << 8); mask++) {
if (dp[i][mask] == -1) continue;
upd(dp[i + 1][mask], dp[i][mask]);
if (mask & (1 << a[i])) continue;
if (~nxt[i][low])
upd(dp[nxt[i][low] + 1][mask | (1 << a[i])], dp[i][mask] + low);
if (~nxt[i][low + 1])
upd(dp[nxt[i][low + 1] + 1][mask | (1 << a[i])], dp[i][mask] + low + 1);
}
}
return dp[n + 1][(1 << 8) - 1];
}
int main() {
cin >> n;
set<int> s;
for (int i = 1; i <= n; i++) cin >> a[i], a[i]--, s.insert(a[i]);
init();
int l = 0, r = 200;
while (r - l > 1) {
int mid = l + r >> 1;
if (~check(mid))
l = mid;
else
r = mid;
}
if (l == 0) {
cout << s.size() << endl;
return 0;
}
cout << check(l) << endl;
return 0;
}
| 2,200 | CPP |
import sys
#sys.stdin = open('in', 'r')
q = int(input())
for _ in range(q):
n = int(input())
a = sorted([int(x) for x in input().split()])
r = 1
for i in range(1, n):
if a[i] - a[i-1] == 1:
r = 2
break
print(r)
#sys.stdout.write('YES\n')
#sys.stdout.write(f'{res}\n')
#sys.stdout.write(f'{y1} {x1} {y2} {x2}\n')
| 800 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, l, c, d, p, nl, np, an;
cin >> n >> k >> l >> c >> d >> p >> nl >> np;
an = min(l * k / nl, c * d);
an = min(an, p / np);
cout << an / n << endl;
return 0;
}
| 800 | CPP |
n, m = map(int, input().split())
grades = [[int(x) for x in input()] for _ in range(n)]
res = set()
subjects = [[grades[j][i] for j in range(n)] for i in range(m)]
for grades in subjects:
_max = max(grades)
for student, grade in enumerate(grades):
if grade == _max:
res.add(student)
print(len(res)) | 900 | PYTHON3 |
n = int(input())
maxn = 0
minn = 10e10
dicta = {}
for i in range(n):
a, b = list(map(int, input().split()))
if(b > maxn):
maxn = b
if(a < minn):
minn = a
dicta[str(a)+str(b)] = i + 1
ires = dicta.get(str(minn) + str(maxn))
if(ires != None):
print(ires)
else:
print(-1) | 1,100 | PYTHON3 |
import math
from collections import defaultdict
from sys import stdin
input=stdin.readline
T=int(input())
for _ in range(T):
n=int(input())
arr=list(map(int,input().split()))
arr.sort()
f=0
for i in range(n-1):
if arr[i]==arr[i+1]:
f=1
break
if f:
print('YES')
else:
print('NO')
| 1,000 | PYTHON3 |
def test(r, g, b):
if r + g >= b-1 and r + b >= g-1 and g + b >= r-1:
print('Yes')
else:
print('No')
for i in range(int(input())):
r, g, b = map(int, input().split())
test(r, g, b) | 900 | PYTHON3 |
n,a,b,k = map(int, input().split())
open = 0
must = 0
must_arr = []
for i,c in enumerate(input()):
if c == '1':
open = 0
else:
open += 1
if open == b:
open = 0
must += 1
if must >= a:
must_arr.append(i+1)
must -= a - 1
print(must)
print(*must_arr) | 1,700 | PYTHON3 |
n=int(input())
s=input()
l=[0]*10
i=0
while(i<len(s)):
if(ord(s[i])>=48 and ord(s[i])<=57):
l[ord(s[i])-48]=0
elif(s[i]=='L'):
for j in range(0,10):
if(l[j]==0):
l[j]=1
break
else:
for j in range(9,-1,-1):
if(l[j]==0):
l[j]=1
break
i+=1
q=""
for i in l:
q=q+str(i)
print(q)
| 800 | PYTHON3 |
arr = list(map(int,input().split()))
arr.sort()
if(arr[-1] > 2*arr[0]+2*arr[1]):
print(arr[0]+arr[1])
else:
print(sum(arr)//3) | 1,800 | PYTHON3 |
for i in range(int(input())):
h,m = map(int, input().split())
k = h*60 + m
print(24*60-k) | 800 | PYTHON3 |
def move(a, b, d):
if abs(a) == 10000 and d[0] not in 'SN':
return -10001
if d[0] == 'S':
return a - b
if d[0] == 'N':
return a + b
return a
bo = True
r = 10000
for _ in range(int(input())):
a, b = input().split()
r = move(r, int(a), b)
if abs(r) > 10000: bo = False; break
if r != 10000: bo = False
print('NO YES'.split()[bo]) | 1,300 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i;
scanf("%d", &n);
if (n == 2) {
puts("3");
return 0;
}
if (n == 3) {
puts("5");
return 0;
}
if (n % 4 == 0 || n % 4 == 1) {
for (i = 1;; i += 2) {
if ((i * i + 1) / 2 >= n) {
printf("%d\n", i);
return 0;
}
}
} else {
for (i = 1;; i += 2) {
if ((i * i + 1) / 2 >= n) {
printf("%d\n", i);
return 0;
}
}
}
return 0;
}
| 1,700 | CPP |
#include <bits/stdc++.h>
using namespace std;
const char nl = '\n';
const long long INF = 0x3f3f3f3f;
const long long INFLL = 0x3f3f3f3f3f3f3f3f;
const long long MOD = 1e9 + 7;
const long double EPS = 1e-10;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
struct Node {
int id, len;
Node() {}
Node(int i, int l) : id(i), len(l) {}
bool operator<(const Node& n) const { return len > n.len; }
};
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cout << fixed << setprecision(10);
int n;
cin >> n;
vector<int> deg(n + 1, 0);
unordered_set<int> adj[n + 1];
int a, b;
for (int i = 1; i < n; i++) {
cin >> a >> b;
deg[a]++;
deg[b]++;
adj[a].insert(b);
adj[b].insert(a);
}
vector<int> leaves;
for (int i = 1; i <= n; i++) {
if (deg[i] == 1) leaves.push_back(i);
}
vector<int> dist(n + 1, -1);
vector<int> jump(n + 1, -1);
vector<int> child(n + 1, -1);
vector<int> revr(n + 1, -1);
priority_queue<Node> least;
for (int leaf : leaves) {
int pre = leaf;
int v = *adj[leaf].begin();
int len = 1;
while (deg[v] == 2) {
len++;
for (int it : adj[v]) {
if (it != pre) {
pre = v;
v = it;
break;
}
}
}
least.push(Node(leaf, len));
dist[leaf] = len;
jump[leaf] = v;
child[leaf] = pre;
revr[pre] = leaf;
}
vector<int> ans(n + 1);
int pos = leaves.size();
for (int i = pos; i <= n; i++) {
ans[i] = n;
}
while (--pos > 1) {
Node cur = least.top();
least.pop();
if (dist[cur.id] != cur.len) {
++pos;
continue;
}
adj[jump[cur.id]].erase(child[cur.id]);
deg[jump[cur.id]]--;
ans[pos] = ans[pos + 1] - cur.len;
if (adj[jump[cur.id]].size() == 2) {
int connect = -1;
for (int v : adj[jump[cur.id]]) {
if (revr[v] != -1) {
connect = v;
break;
}
}
if (connect != -1) {
int leaf = revr[connect];
int pre = connect;
int v = jump[cur.id];
int len = dist[leaf];
while (deg[v] == 2) {
len++;
for (int it : adj[v]) {
if (it != pre) {
pre = v;
v = it;
break;
}
}
}
least.push(Node(leaf, len));
dist[leaf] = len;
jump[leaf] = v;
child[leaf] = pre;
revr[pre] = leaf;
}
}
}
ans[1] = 1;
for (int i = 1; i <= n; i++) {
cout << ans[i] << " ";
}
cout << nl;
return 0;
}
| 2,200 | CPP |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
long long t;
cin >> t;
while (t--) {
long long n;
cin >> n;
long long arr[n];
for (long long i = 0; i < n; i++) {
cin >> arr[i];
}
long long sign = 1, idx = 0;
long long sm = 0, vl = arr[0];
if (arr[0] < 0) sign = -1;
while (idx < n) {
sign = arr[idx] / abs(arr[idx]);
vl = arr[idx];
while (idx < n && sign == arr[idx] / abs(arr[idx])) {
vl = max(vl, arr[idx]);
idx++;
}
sm = sm + vl;
}
cout << sm << "\n";
}
return 0;
}
| 1,200 | CPP |
#include <bits/stdc++.h>
long long n, s;
long long mabs(long long t) { return t >= 0 ? t : -t; }
bool meet(long long t) {
int sum = 0;
long long tt = t;
while (t != 0) {
sum += t % 10;
t /= 10;
}
if (mabs(tt - sum) >= s) return 1;
return 0;
}
int main() {
scanf("%I64d %I64d", &n, &s);
long long l = 1, r = n;
while (l <= r) {
long long mid = (l + r) >> 1;
if (meet(mid))
r = mid - 1;
else
l = mid + 1;
}
while (!meet(r)) r++;
while (meet(r - 1)) r--;
printf("%I64d\n", n - r + 1 > 0 ? n - r + 1 : 0);
return 0;
}
| 1,600 | CPP |
## 432 A
[n , k] = [int(x) for x in input().split(' ')]
y = [int(x) for x in input().split(' ')]
people = sum(1 for x in y if x + k <= 5)
print(people // 3) | 800 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
scanf("%d", &n);
vector<int> vc;
int cnt = 0;
for (int i = 0; i < 2 * n - 1; i++) {
int x;
scanf("%d", &x);
if (x < 0) cnt++, x *= -1;
vc.push_back(x);
}
sort(vc.begin(), vc.end());
if (cnt % 2 && n % 2 == 0) vc[0] *= -1;
cout << accumulate(vc.begin(), vc.end(), 0) << endl;
return 0;
}
| 1,800 | CPP |
#include <bits/stdc++.h>
using namespace std;
const long long N = 1e6 + 5;
const long long mod = 998244353;
const long long INF = 0x7f7f7f7f7f7f7f7f;
const int INFi = 0x7f7f7f7f;
int test = 1;
int push_back[N], pr[N], n, m, q, dp[N][2];
char L[N], R[N], U[N], D[N];
int solve(char *L, char *R, char *U, char *D, int n, int m, char r, char b) {
dp[0][0] = dp[0][1] = 0;
for (int i = 0; i < n; i++) {
dp[0][0] += (L[i] == b);
dp[0][1] += (L[i] == r);
}
dp[0][0] += (U[0] == b) + (D[0] == b);
dp[0][1] += (U[0] == r) + (D[0] == r);
for (int i = 1; i < m; i++) {
dp[i][0] = min(dp[i - 1][0], dp[i - 1][1] + n) + (U[i] == b) + (D[i] == b);
dp[i][1] = min(dp[i - 1][1], dp[i - 1][0] + n) + (U[i] == r) + (D[i] == r);
}
for (int i = 0; i < n; i++) {
dp[m - 1][0] += (R[i] == b);
dp[m - 1][1] += (R[i] == r);
}
return min(dp[m - 1][0], dp[m - 1][1]);
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cout << fixed;
cout << setprecision(15);
;
cin >> n >> m >> q;
cin >> L >> R >> U >> D;
int pR = 0;
for (int i = 0; i < n; i++) pR += (L[i] == 'R') + (R[i] == 'R');
for (int i = 0; i < m; i++) pR += (U[i] == 'R') + (D[i] == 'R');
int ans = min(pR, 2 * (n + m) - pR);
ans = min(ans, solve(L, R, U, D, n, m, 'R', 'B'));
ans = min(ans, solve(U, D, L, R, m, n, 'R', 'B'));
cout << ans << "\n";
}
| 3,300 | CPP |
#include <bits/stdc++.h>
using namespace std;
vector<vector<long long> > MATT(vector<vector<long long> > b,
vector<vector<long long> > a) {
vector<vector<long long> > sol;
for (int i = 0; i < a.size(); i++) {
vector<long long> t;
for (int j = 0; j < b[0].size(); j++) {
t.push_back(0);
}
sol.push_back(t);
}
for (int i = 0; i < b[0].size(); i++) {
for (int j = 0; j < a.size(); j++) {
long long x = 0;
for (int k = 0; k < b.size(); k++) {
x += (a[j][k] * b[k][i]) % 1000000007;
}
sol[j][i] = x % 1000000007;
}
}
return sol;
}
vector<vector<long long> > power(vector<vector<long long> > a, int b) {
if (b == 1) return a;
vector<vector<long long> > x;
x = power(a, b / 2);
if (b % 2 == 0)
return MATT(x, x);
else
return MATT(a, MATT(x, x));
}
int main() {
vector<vector<long long> > matrix;
vector<vector<long long> > sol;
for (int i = 0; i < 4; i++) {
vector<long long> temp;
for (int j = 0; j < 4; j++) {
temp.push_back(1);
}
matrix.push_back(temp);
temp.clear();
if (i == 0)
temp.push_back(1);
else
temp.push_back(0);
sol.push_back(temp);
matrix[i][i] = 0;
}
int n;
cin >> n;
matrix = power(matrix, n);
sol = MATT(sol, matrix);
cout << sol[0][0] << endl;
}
| 1,500 | CPP |
import math
def solve(n, m, k):
first_pick = n / k
# number of jokers first guy gets
x = min(m, first_pick)
if x == m:
return x
# number of jokers left after turn
left = m - x
y = math.ceil(left / (k - 1))
return abs(x - y)
def main():
t = int(input())
i = 1
while i <= t:
n, m, k = map(int, input().split())
ans = solve(n, m, k)
print(int(ans))
i += 1
main()
| 1,000 | PYTHON3 |
value = sum(map(int, input().split()))/5
if value.is_integer() and value != 0:
print(int(value))
else:
print("-1") | 1,100 | PYTHON3 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:100000000")
using namespace std;
const int N = 100100;
vector<int> m[N];
int d[N], a[N];
void dfs(int i, int p) {
a[i] = p;
for (int j : m[i])
if (j != p) {
d[j] = d[i] + 1;
dfs(j, i);
}
}
bool dfs2(int i, int p, int k) {
int c = 0;
for (int j : m[i])
if (j != p) c++;
if (k == 0)
return c == 0;
else {
if (c < 3) return 0;
for (int j : m[i])
if (j != p && !dfs2(j, i, k - 1)) return 0;
return 1;
}
}
int main() {
int n, k;
scanf("%d%d", &n, &k);
int i, j;
for (int l = n - 1; l--;
scanf("%d%d", &i, &j), i--, j--, m[i].push_back(j), m[j].push_back(i))
;
i = 0;
d[0] = 0;
dfs(i, -1);
for (int j = 0; j < n; j++)
if (d[j] > d[i]) i = j;
d[i] = 0;
dfs(i, -1);
for (int j = 0; j < n; j++)
if (d[j] > d[i]) i = j;
for (j = d[i] / 2; j > 0; i = a[i], j--)
;
if (dfs2(i, -1, k))
printf("Yes\n");
else
printf("No\n");
return 0;
}
| 1,800 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1012345678;
const double PI = acos(-1.0);
const double EPS = 0.0000000304;
const int MAX = 123231;
int N, K;
char ip[MAX];
int main() {
scanf("%d %d", &N, &K);
scanf("%s", ip);
int id = 0;
int len = strlen(ip);
while (K) {
if (id == len - 1) {
puts(ip);
return 0;
}
if (ip[id] == '4' && ip[id + 1] == '7') {
K--;
if (id & 1) {
ip[id] = '7';
if (id) {
id--;
}
if (ip[id] == '4') {
K %= 2;
}
} else {
ip[id + 1] = '4';
id++;
}
} else {
id++;
}
}
puts(ip);
}
| 1,500 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, m, y, z, w;
int A[1000005], B[1000005], C[1000005];
int x, k;
bool ok;
int main() {
scanf("%d %d", &n, &k);
w = k;
if (k == 1) {
printf("Yes\n");
return 0;
}
for (int i = (0); i < (n); i++) {
scanf("%d", &y);
A[y] = 1;
}
for (int j = 2; j * j <= k; j++) {
while (w % j == 0) {
C[j]++;
w /= j;
}
}
if (w != 1) C[w]++;
for (int i = (1); i <= (1000000); i++) {
if (C[i] == 0) continue;
x = 1;
for (int j = (0); j < (C[i]); j++) x *= i;
ok = 0;
for (int j = x; j <= 1000000; j += x)
if (A[j] != 0) ok = 1;
if (ok == 0) {
printf("No\n");
return 0;
}
}
printf("Yes\n");
return 0;
}
| 1,800 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int inf_int = 1e9 + 100;
const long long inf_ll = 1e18;
const double pi = 3.1415926535898;
template <class T1, class T2>
std::ostream &operator<<(std::ostream &out, const std::pair<T1, T2> &rhs) {
out << "( " << rhs.first << " , " << rhs.second << " )";
return out;
}
template <typename A, typename B>
string to_string(pair<A, B> p);
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
string to_string(const string &s) { return '"' + s + '"'; }
string to_string(const char *s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
string to_string(vector<bool> v) {
bool first = true;
string res = "{";
for (int i = 0; i < static_cast<int>(v.size()); i++) {
if (!first) {
res += ", ";
}
first = false;
res += to_string(v[i]);
}
res += "}";
return res;
}
template <size_t N>
string to_string(bitset<N> v) {
string res = "";
for (size_t i = 0; i < N; i++) {
res += static_cast<char>('0' + v[i]);
}
return res;
}
template <typename A>
string to_string(A v) {
bool first = true;
string res = "{";
for (const auto &x : v) {
if (!first) {
res += ", ";
}
first = false;
res += to_string(x);
}
res += "}";
return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
to_string(get<2>(p)) + ")";
}
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
cerr << " " << to_string(H);
debug_out(T...);
}
bool debug = 0;
const int MAXN = 5000 + 100;
const int LOG = 21;
const int mod = 1e9 + 7;
const int MX = (2e7 + 100);
struct Edge {
int a, b, c, flow, cost;
};
vector<pair<long long, long long> > spec;
struct MIN_FLOW {
vector<Edge> e;
vector<int> g[MAXN];
int n, s, t;
int id[MAXN];
long long dis[MAXN];
int from[MAXN];
void init(int N, int S, int T) {
n = N;
s = S;
t = T;
}
void add_edge(int a, int b, int c, int cost) {
Edge e1 = {a, b, c, 0, cost};
Edge e2 = {b, a, 0, 0, -cost};
g[a].push_back(e.size());
e.push_back(e1);
g[b].push_back(e.size());
;
e.push_back(e2);
}
long long get_val(int k) {
int flow = 0;
long long cost = 0;
while (1) {
queue<int> q;
fill(id, id + n, 0);
fill(dis, dis + n, inf_ll);
dis[s] = 0;
id[s] = 1;
q.push(s);
while (!q.empty()) {
int v = q.front();
q.pop();
id[v] = 0;
for (int ind : g[v]) {
Edge &edge = e[ind];
int to = edge.b;
if (edge.c > edge.flow && dis[edge.b] > dis[v] + edge.cost) {
if (id[to] == 0) {
q.push(to);
id[to] = 1;
}
dis[to] = dis[v] + edge.cost;
from[to] = ind;
}
}
}
spec.push_back({dis[t], flow + 1});
if (dis[t] == inf_ll) break;
int addflow = 1;
int v = t;
while (v != s) {
int ind = from[v];
cost += 1ll * e[ind].cost * addflow;
e[ind].flow += addflow;
e[ind ^ 1].flow -= addflow;
v = e[ind].a;
}
flow += addflow;
if (flow == k) break;
}
return cost;
}
} flow;
void solve() {
int n, m;
cin >> n >> m;
int s = 1, t = n;
for (int i = 1; i <= m; ++i) {
int a, b, c;
cin >> a >> b >> c;
flow.add_edge(a, b, 1, c);
}
flow.init(n + 5, s, t);
flow.get_val(inf_int);
int q;
cin >> q;
while (q--) {
int x;
cin >> x;
long double ans = spec[0].first;
long double total_cost = 0;
for (int i = 0; i + 1 < (int(spec.size())); ++i) {
total_cost += spec[i].first;
long double need = spec[i].first * spec[i].second;
if (total_cost + x >= need) {
ans = min<long double>(
spec[i].first + (total_cost + x - need) / spec[i].second,
spec[i + 1].first);
} else {
break;
}
}
cout << ans << "\n";
}
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cout.setf(ios::fixed);
cout.precision(15);
int t = 1;
while (t--) solve();
42;
}
| 3,100 | CPP |
s = input()
h = int(s[0:2])
m = int(s[3:5])
abs_time = h*60 + m
palins = []
for i in range(0, 351, 70):
palins.append(i)
for i in range(601, 70*5+601+1, 70):
palins.append(i)
for i in range(1202, 70*4+1202, 70):
palins.append(i)
palins.append(1440)
for i in range(len(palins)):
if abs_time <= palins[i]:
print(palins[i] - abs_time)
break
| 1,000 | PYTHON3 |
#include <bits/stdc++.h>
const int N = 500 + 10;
const int MOD = 1e9 + 7;
int n, m, q;
int prod = 1;
char b[N][N];
char s[N];
void ins() {
int i, j;
for (i = 1; i <= int(m); i++) s[i] -= 'a';
for (i = int(m); i; i--) {
if (s[i]) {
if (!b[i][i]) {
memcpy(b[i], s, sizeof(s));
return;
}
while (s[i])
for (j = 1; j <= int(i); j++) s[j] = (s[j] + 5 - b[i][j]) % 5;
}
}
prod = prod * 5LL % MOD;
}
int query() {
int i, j;
for (i = 1; i <= int(m); i++) s[i] -= 'a';
for (i = int(m); i; i--) {
if (s[i]) {
if (!b[i][i]) return 0;
while (s[i])
for (j = 1; j <= int(i); j++) s[j] = (s[j] + 5 - b[i][j]) % 5;
}
}
return prod;
}
int main() {
int i;
scanf("%d %d", &n, &m);
for (i = 1; i <= int(n); i++) {
scanf("%s", s + 1);
ins();
}
scanf("%d", &q);
for (i = 1; i <= int(q); i++) {
scanf("%s", s + 1);
printf("%d\n", query());
}
return 0;
}
| 2,600 | CPP |
#include <bits/stdc++.h>
using namespace std;
typedef struct NODE {
NODE* prev = nullptr;
unsigned numv = 1;
unsigned ans = 0;
bool chosen = false;
} NODE;
NODE a[2 * 400005];
NODE* get(NODE* x) {
return (x->prev == nullptr) ? x : (x->prev = get(x->prev));
}
void merge(NODE* x, NODE* y) {
x = get(x);
y = get(y);
if (x == y) return;
if (x->numv < y->numv) {
x->prev = y;
y->numv += x->numv;
y->ans += x->ans;
} else {
y->prev = x;
x->numv += y->numv;
x->ans += y->ans;
}
}
void solve() {
int n, m, i, j;
int ans = 0;
string s;
bool flag = false;
cin >> n >> m;
for (int k = 1; k <= 2 * n; k++) a[k] = NODE();
for (int k = n + 1; k <= 2 * n; k++) a[k].ans = 1;
for (int k = 0; k < m; k++) {
cin >> i >> j >> s;
if (s == "imposter") {
merge(a + i, a + j + n);
merge(a + i + n, a + j);
} else {
merge(a + i, a + j);
merge(a + i + n, a + j + n);
}
}
for (int k = 1; k <= n; k++) {
if (get(a + k) == get(a + k + n)) {
flag = true;
cout << "-1\n";
break;
}
}
if (flag) return;
for (int k = 1; k <= n; k++) {
NODE* crewi = get(a + k);
NODE* impi = get(a + (k + n));
if (crewi->chosen || impi->chosen) continue;
if (crewi->ans > impi->ans) {
ans += crewi->ans;
crewi->chosen = true;
} else {
ans += impi->ans;
impi->chosen = true;
}
}
cout << ans << "\n";
}
int main() {
ios::sync_with_stdio(false);
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}
| 1,700 | CPP |
def solve():
d = { "purple": "Power" ,
"green" : "Time" ,
"blue" : "Space" ,
"orange": "Soul" ,
"red" : "Reality",
"yellow": "Mind" }
ins = set()
for _ in range(int(input())):
ins.add(input())
res = []
for x,y in d.items():
if x not in ins:
res.append(y)
print(len(res))
for x in res:
print(x)
solve() | 800 | PYTHON3 |
for i in range(0,int(input())):
c,s=map(int,input().split())
sph=s//c
oh=s-(sph*c)
s=0
#print(c,s,sph,oh)
if oh>0:
for j in range(0,oh):
s+=(sph+1)**2
for j in range(0,c-oh):
s+=sph**2
print(s) | 1,000 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i, j, k = 0, l = 0, a[8];
for (i = 0; i < 6; i++) cin >> a[i];
k = a[0] + a[1] + a[2];
l = a[0] * a[0] + a[2] * a[2] + a[4] * a[4];
cout << (k * k) - l;
}
| 1,600 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 200;
int a[N];
vector<char> v;
int main() {
string s;
cin >> s;
int n = s.size();
for (int i = 0; i < n; i++) {
if (s[i] != s[n - i - 1] or
(s[i] != 'A' and s[i] != 'H' and s[i] != 'I' and s[i] != 'M' and
s[i] != 'O' and s[i] != 'T' and s[i] != 'U' and s[i] != 'V' and
s[i] != 'W' and s[i] != 'X' and s[i] != 'Y')) {
cout << "NO";
return 0;
}
}
cout << "YES";
return 0;
}
| 1,000 | CPP |
s = input()
x = ord(s[0]) - ord('A')
if len(s)>1:
y = ord(s[1]) - ord('A')
ch = True
for i in range(2,len(s)):
z = ord(s[i]) - ord('A')
if (x+y)%26 != z:
ch = False
break
x = y
y = z
if ch:
print("YES")
else:
print("NO")
| 0 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
long long q;
cin >> q;
while (q--) {
long long n, k;
cin >> n >> k;
vector<long long> a(n);
for (auto &x : a) cin >> x;
long long sum = 0;
vector<long long> m;
long long cnt = 0;
for (long long i = 0; i < n; ++i) {
sum += a[i];
if ((sum & 1) && cnt < k - 1) {
sum = 0;
cnt++;
m.push_back(i + 1);
}
}
if (sum & 1) {
m.push_back(n);
cout << "YES\n";
for (auto x : m) cout << x << " ";
cout << "\n";
} else
cout << "NO\n";
}
}
| 1,200 | CPP |
import sys
import math
import itertools
import functools
import collections
import operator
import fileinput
import copy
ORDA = 97 # a
def ii(): return int(input())
def mi(): return map(int, input().split())
def li(): return [int(i) for i in input().split()]
def lcm(a, b): return abs(a * b) // math.gcd(a, b)
def revn(n): return str(n)[::-1]
def dd(): return collections.defaultdict(int)
def ddl(): return collections.defaultdict(list)
def sieve(n):
if n < 2: return list()
prime = [True for _ in range(n + 1)]
p = 3
while p * p <= n:
if prime[p]:
for i in range(p * 2, n + 1, p):
prime[i] = False
p += 2
r = [2]
for p in range(3, n + 1, 2):
if prime[p]:
r.append(p)
return r
def divs(n, start=2):
r = []
for i in range(start, int(math.sqrt(n) + 1)):
if (n % i == 0):
if (n / i == i):
r.append(i)
else:
r.extend([i, n // i])
return r
def divn(n, primes):
divs_number = 1
for i in primes:
if n == 1:
return divs_number
t = 1
while n % i == 0:
t += 1
n //= i
divs_number *= t
def prime(n):
if n == 2: return True
if n % 2 == 0 or n <= 1: return False
sqr = int(math.sqrt(n)) + 1
for d in range(3, sqr, 2):
if n % d == 0: return False
return True
def convn(number, base):
newnumber = 0
while number > 0:
newnumber += number % base
number //= base
return newnumber
def cdiv(n, k): return n // k + (n % k != 0)
def ispal(s):
for i in range(len(s) // 2 + 1):
if s[i] != s[-i - 1]:
return False
return True
for _ in range(ii()):
n = ii()
p = li()
for i in range(1, n - 1):
if p[i-1] < p[i] > p[i+1]:
print('YES')
print(i, i+1, i+2)
break
else:
print('NO')
| 900 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
/*<DEBUG>*/
#define tem template <typename
#define can_shift(_X_, ...) enable_if_t<sizeof test<_X_>(0) __VA_ARGS__ 8, debug&> operator<<(T i)
#define _op debug& operator<<
tem C > auto test(C *x) -> decltype(cerr << *x, 0LL);
tem C > char test(...);
tem C > struct itr{C begin, end; };
tem C > itr<C> get_range(C b, C e) { return itr<C>{b, e}; }
struct debug{
#ifdef _LOCAL
~debug(){ cerr << endl; }
tem T > can_shift(T, ==){ cerr << boolalpha << i; return *this; }
tem T> can_shift(T, !=){ return *this << get_range(begin(i), end(i)); }
tem T, typename U > _op (pair<T, U> i){
return *this << "< " << i.first << " , " << i.second << " >"; }
tem T> _op (itr<T> i){
*this << "{ ";
for(auto it = i.begin; it != i.end; it++){
*this << " , " + (it==i.begin?2:0) << *it;
}
return *this << " }";
}
#else
tem T> _op (const T&) { return *this; }
#endif
};
string _ARR_(int* arr, int sz){
string ret = "{ " + to_string(arr[0]);
for(int i = 1; i < sz; i++) ret += " , " + to_string(arr[i]);
ret += " }"; return ret;
}
#define exp(...) " [ " << #__VA_ARGS__ << " : " << (__VA_ARGS__) << " ]"
/*</DEBUG>*/
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<int, int> pii;
//mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
#define pb push_back
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define TC int __TC__; cin >> __TC__; while(__TC__--)
#define ar array
const int INF = 1e9 + 7, N = 500;
int dp[N][N], g[N][N];
// dp[i][j] : 1 if a there is a spruce of size j with base y = i
int main(void)
{
FAST;
TC{
memset(dp, 0, sizeof dp);
int n, m; cin >> n >> m;
for(int i = 0; i < n; ++i){
string s; cin >> s;
for(int j = 0; j < m; ++j){
g[i][j] = (s[j] == '*');
}
}
ll ans = 0;
for(int j = 0; j < m; ++j){
memset(dp, 0, sizeof dp);
for(int i = 0; i < n; ++i){
if(g[i][j]){
++ans;
dp[i][0] = 1;
for(int sz = 1; i-sz>=0&&j-sz>=0&&j+sz<m; ++sz){
if(g[i][j+sz] && g[i][j-sz]){
if(dp[i-1][sz-1]){
++ans;
dp[i][sz] = 1;
}
}else{
break;
}
}
}
}
}
cout << ans << '\n';
}
return 0;
}
| 1,400 | CPP |
#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
int n;
double x[200005], y[200005];
inline bool judge(int a, int b, int c) {
double k1 = (y[a] - y[b]) * (x[b] - x[c]);
double k2 = (y[b] - y[c]) * (x[a] - x[b]);
return fabs(k1 - k2) <= 1e-5;
}
inline bool check(int a, int b) {
std::vector<int> V;
for (int i = 1; i <= n; i++)
if (i != a && i != b && !judge(a, b, i)) V.push_back(i);
if (V.size() <= 2) return 1;
int c = V[0], d = V[1];
for (int i = 2; i < (int)V.size(); i++) {
if (!judge(c, d, V[i])) return 0;
}
return 1;
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%lf%lf", x + i, y + i);
if (n < 5 || check(1, 2) || check(2, 3) || check(1, 3))
return 0 * printf("YES\n");
printf("NO\n");
return 0;
}
| 2,000 | CPP |
a = input()
al = list(a)
if 'h' in al:
b = al.index('h')
a = a[b+1:]
al = list(a)
if 'e' in al:
c = al.index('e')
a = a[c+1:]
al = list(a)
if 'l' in al:
d = al.index('l')
a = a[d+1:]
al = list(a)
if 'l' in al:
e = al.index('l')
a = a[e+1:]
al = list(a)
if 'o' in al:
print('YES')
else:
print('NO')
else:
print('NO')
else:
print('NO')
else:
print('NO')
else:
print('NO')
| 1,000 | PYTHON3 |
n,m = map(int,input().split())
a = list(map(int,input().split()))
sumi =0
for i in range(m):
u,v = map(int,input().split())
sumi += min(a[u-1],a[v-1])
print(sumi)
| 1,400 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int a[301];
int main() {
int p, x, n, ans, i;
int flag = 1, c = -1;
cin >> p >> n;
for (i = 0; i < n; i++) {
cin >> x;
ans = x % p;
if (a[ans] != 0 && flag == 1) {
c = i + 1;
flag = 0;
}
a[ans] = 1;
}
cout << c << endl;
return 0;
}
| 800 | CPP |
def factorize(n):
L=[]
for i in range(1,int(n**0.5)+1):
if(n%i==0):
L.append(i)
if(i*i!=n):
L.append(n//i)
return L
n=int(input())
print(len(factorize(n))-1) | 800 | PYTHON3 |
names=[]
names_2=[]
ips=[]
n, m=list(map(int, input().split()))
for i in range(n):
name, ip=input().split()
names+=[name]
ips+=[ip]
commands_ips=[]
for i in range(m):
command_ip, name=input().split(';')
commands_ips+=[command_ip]
names_2+=name
for i in range(m):
print(commands_ips[i]+'; #'+names[ips.index(commands_ips[i].split()[1])]) | 900 | PYTHON3 |
f = [0, 1, 2, 0, 2, 1, 0]
l = [int(i) for i in input().split()]
mn = min([l[i] // f.count(i) for i in range(3)])
l = [l[i] - mn * f.count(i) for i in range(3)]
mx = 0
for i in range(7):
tmp = l.copy()
j = 0
while tmp[f[(i + j) % 7]] > 0:
tmp[f[(i + j) % 7]] -= 1
j += 1
if j > mx:
mx = j
print(mn * 7 + mx)
| 1,400 | PYTHON3 |
#include <bits/stdc++.h>
long long min(long long a, long long b) { return a < b ? a : b; }
int main() {
static long long tt1[1000000], tt2[1000000], dp[1000000], dq[1000000];
int n, r1, r2, r3, d, i;
long long ans;
scanf("%d%d%d%d%d", &n, &r1, &r2, &r3, &d);
for (i = 0; i < n; i++) {
int a;
scanf("%d", &a);
tt1[i] = (long long)a * r1 + r3;
tt2[i] = min(tt1[i], min(r2 + r1, (long long)(a + 2) * r1));
}
dp[0] = min(tt1[0], tt2[0] + d * 2);
for (i = 1; i < n; i++)
dp[i] = min(dp[i - 1] + tt1[i],
(i < 2 ? 0 : dp[i - 2]) + tt2[i - 1] + tt2[i] + d * 2);
dq[n - 1] = min(tt1[n - 1], tt2[n - 1] + d * 2);
for (i = n - 2; i >= 0; i--) dq[i] = dq[i + 1] + tt2[i] + d;
ans = dp[n - 1];
for (i = 0; i < n; i++) ans = min(ans, (i == 0 ? 0 : dp[i - 1]) + dq[i]);
ans += (long long)(n - 1) * d;
printf("%lld\n", ans);
return 0;
}
| 2,300 | CPP |
import os,sys
if(os.path.exists('input.txt')):
sys.stdin = open("input.txt","r") ; sys.stdout = open("output.txt","w")
from math import log2 as l2
t = int(input())
for _ in range(t):
d,m = [int(x) for x in input().split()]
bit = l2(d)
bit = int(bit)+1
ans = 1
# print("bit",bit)
p = 0
for i in range(0,bit+1):
if (1<<(i))>d:
break
ans = ans * (min(2**(i+1) -1 , d) - 2**(i) + 2)
ans-=1
print(ans%m)
| 1,700 | PYTHON3 |
#include <bits/stdc++.h>
struct point {
int x, y;
point *read() {
scanf("%d%d", &x, &y);
return this;
}
inline bool operator<(const point &B) const {
return x < B.x || (x == B.x && y < B.y);
}
inline bool operator==(const point &B) const { return x == B.x && y == B.y; }
} p[100054], q[100054];
int n;
int col[100054];
long long aX = 0, aY = 0;
inline int min(const int x, const int y) { return x < y ? x : y; }
inline int max(const int x, const int y) { return x < y ? y : x; }
inline void up(long long &x, const long long y) { x < y ? x = y : 0; }
long long solve() {
int i, h = n / 2, cur;
if (n & 1) {
for (i = 0; i < n; ++i)
col[i] = (q[i].x < p[h].x ? 0 : q[i].x > p[h].x ? 1 : -1);
for (cur = -1;;) {
for (i = 0; i < h; ++i)
if (~col[i]) {
if (~cur && cur != col[i]) break;
cur = col[i];
}
if (i < h) break;
for (++i; i < n; ++i)
if (~col[i]) {
if (~cur && cur == col[i]) break;
cur = !col[i];
}
break;
}
bool flag = col[h] == -1 && !(q[h] == q[h - 1] || q[h] == q[h + 1]);
return aY + (i == n || !flag
? 0
: 2ll * max(q[h - 1].y - q[h].y, q[h].y - q[h + 1].y));
} else {
for (i = 0; i < n; ++i)
col[i] = (q[i].x < p[h].x ? 0 : q[i].x > p[h - 1].x ? 1 : -1);
for (cur = -1;;) {
for (i = 0; i < h; ++i)
if (~col[i]) {
if (~cur && cur != col[i]) break;
cur = col[i];
}
if (i < h) break;
for (; i < n; ++i)
if (~col[i]) {
if (~cur && cur == col[i]) break;
cur = !col[i];
}
break;
}
return aY + (i == n ? 0 : 2ll * (q[h - 1].y - q[h].y));
}
}
int main() {
int i;
long long ans;
scanf("%d", &n);
for (i = 0; i < n; ++i) q[i] = *p[i].read();
std::sort(p, p + n);
std::sort(q, q + n, [](const point &A, const point &B) {
return A.y < B.y || (A.y == B.y && A.x < B.x);
});
for (i = 1; i < n; ++i) aX += 2ll * min(i, n - i) * (p[i].x - p[i - 1].x);
for (i = 1; i < n; ++i) aY += 2ll * min(i, n - i) * (q[i].y - q[i - 1].y);
ans = aX + solve();
for (i = 0; i < n; ++i) std::swap(p[i].x, q[i].y), std::swap(p[i].y, q[i].x);
std::swap(aX, aY);
ans = std::max(ans, aX + solve());
printf("%lld\n", ans);
return 0;
}
| 3,100 | CPP |
from sys import stdin
n=int(stdin.readline().rstrip())
l=list(map(int,stdin.readline().split()))
d={200:0,100:0}
for i in l:
d[i]+=1
p=0
if d[200]%2==0 and d[100]%2==0:
p=1
if d[200]%2!=0:
if d[100]>=2 and d[100]%2==0:
p=1
if p==0:
print("NO")
else:
print("YES") | 1,100 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, x = 1000000009, ans = 1;
cin >> n;
for (int i = 1; i <= n; i++) {
int t;
cin >> t;
if (x > (t - i + n) / n) {
x = (t - i + n) / n;
ans = i;
}
}
cout << ans << endl;
return 0;
}
| 1,300 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long int mod1 = 1000000007;
long long int mod2 = 67280421310721;
long long int mod3 = 998244353;
long long int INF = 1e18;
long long int pow1(long long int a, long long int b) {
long long int res = 1;
while (b > 0) {
if (b & 1) res = res * a;
a = a * a;
b >>= 1;
}
return res;
}
void sieve() {
long long int n;
bool prime[n + 1];
memset(prime, true, sizeof(prime));
for (int p = 2; p * p <= n; p++) {
if (prime[p] == true) {
for (int i = p * p; i <= n; i += p) prime[i] = false;
}
}
}
long long int pow2(long long int a, long long int b, long long int m) {
a %= m;
long long int res = 1;
while (b > 0) {
if (b & 1) res = res * a % m;
a = a * a % m;
b >>= 1;
}
return res;
}
long long int setbit(long long int n) { return __builtin_popcount(n); }
void solve() {
long long int n, k;
cin >> n >> k;
string s;
cin >> s;
vector<int> v;
int win = 0;
int W = 0;
int loss = 0;
int ans = 0;
for (char a : s) {
if (a == 'W') {
if (loss) {
v.push_back(loss);
loss = 0;
}
ans++;
if (W) ans++;
W = 1;
win++;
} else {
W = 0;
if (win) loss++;
}
}
if (win == 0) {
cout << max(2 * k - 1, 0LL) << endl;
} else if (win + k >= n)
cout << 2 * n - 1 << endl;
else {
sort(v.begin(), v.end());
ans += 2 * k;
for (auto x : v) {
if (x <= k) ans++;
k -= x;
}
cout << ans << endl;
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}
| 1,400 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e6 + 3;
struct milk {
int l, r;
};
milk x[MAX];
int a[MAX];
int b[MAX];
int n;
inline int cheak(int x) {
int l, r;
r = x;
for (int i = 2; i <= n; i++) {
l = min(a[i], b[i - 1] - r);
r = a[i] - l;
if (r > b[i]) return 3;
}
if (r + (a[1] - x) <= b[n])
return 1;
else
return 2;
}
long long rin() {
long long s = 0;
char c = getchar();
bool bj = 0;
for (; (c > '9' || c < '0') && c != '-'; c = getchar())
;
if (c == '-') bj = 1, c = getchar();
for (; c >= '0' && c <= '9'; c = getchar())
s = (s << 1) + (s << 3) + (c ^ '0');
if (bj)
return -s;
else
return s;
}
int main() {
int i, j;
for (int t = rin(); t > 0; t--) {
n = rin();
int minx, maxx;
int ans;
for (i = 1; i <= n; i++) a[i] = rin();
for (i = 1; i <= n; i++) b[i] = rin();
int l = max(0, a[1] - b[n]), r = min(a[1], b[1]);
ans = 0;
for (; l <= r;) {
int mid = (l + r) >> 1;
ans = cheak(mid);
if (ans == 1) break;
if (ans == 2) l = mid + 1;
if (ans == 3) r = mid - 1;
}
if (ans == 1)
printf("YES\n");
else
printf("NO\n");
}
return 0;
}
| 2,400 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 1000010;
vector<long long> is_prime(N + 1, true);
long long to_int(string s) {
stringstream geek(s);
long long x = 0;
geek >> x;
return x;
}
string to_string(long long n) {
ostringstream str1;
str1 << n;
string geek = str1.str();
return geek;
}
bool sortinrev(const pair<int, int> &a, const pair<int, int> &b) {
return (a.first > b.first);
}
bool sortbysecdesc(const pair<int, int> &a, const pair<int, int> &b) {
return a.second > b.second;
}
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {
return (a.second < b.second);
}
long long ncr(long long n, long long r) {
if (r > n - r) r = n - r;
long long ans = 1, i;
for (i = 1; i <= r; i++) {
ans *= n - r + i;
ans /= i;
}
return ans;
}
long long powerm(long long a, long long k) {
if (!k) {
return 1;
}
long long b = powerm(a, k / 2);
b = b * b % (1000000000 + 7);
if (k % 2) {
return a * b % (1000000000 + 7);
} else {
return b;
}
}
long long power(long long a, long long b) {
if (b == 1) return a;
if (b == 0) return 1;
long long m1 = power(a, b / 2);
if (b % 2) return m1 * m1 * a;
return m1 * m1;
}
void seive_of_eras(long long n) {
is_prime[0] = 0;
is_prime[1] = 0;
for (long long i = 2; i * i <= n; i++) {
if (is_prime[i]) {
for (long long j = i * i; j <= n; j += i) {
is_prime[j] = false;
}
}
}
}
bool isprime(long long a) {
if (a <= 1) return false;
if (a == 2 || a == 3) return true;
if (a % 2 == 0 || a % 3 == 0) return false;
for (long long i = 5; i * i <= a; i = i + 6) {
if (a % i == 0 || a % (i + 2) == 0) return false;
}
return true;
}
void codeit() {
long long l, r;
cin >> l >> r;
if (l <= r / 2) {
cout << r % (r / 2 + 1) << '\n';
} else {
cout << r % l << '\n';
}
return;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(0);
long long tt;
tt = 1;
cin >> tt;
for (long long i = 0; i < tt; i++) {
codeit();
}
}
| 800 | CPP |
n,s=int(input()),input()
c0=s.count('0')
if c0==n:
print(0)
else:
print('1'+'0'*c0)
| 800 | PYTHON3 |
import sys
from collections import deque
class Group(object):
def __init__(self, ids, height):
self.ids = ids
self.height = height
def __repr__(self):
return "[h={} ids={}]".format(self.height, self.ids)
t = int(sys.stdin.readline())
for _ in range(t):
n, k = map(int, sys.stdin.readline().split())
H = deque(enumerate(map(int, sys.stdin.readline().split())))
groups = list()
groups.append(Group([1], H.popleft()[1]))
while True:
if not len(H):
print("-1")
break
mountain_id, forward_height = H[0]
mountain_id += 1
if forward_height == groups[-1].height:
# same height as previous
groups[-1].ids.append(mountain_id)
H.popleft()
elif forward_height < groups[-1].height:
# lower than previous
groups.append((Group([mountain_id], forward_height)))
H.popleft()
else:
# too tall, ball stops
group_size = len(groups[-1].ids)
if len(groups) > 1:
next_height = min(groups[-2].height, forward_height)
else:
next_height = forward_height
cost = group_size * (next_height - groups[-1].height)
if k > cost:
k -= cost
else:
num_in_group = len(groups[-1].ids)
print(groups[-1].ids[-(k % num_in_group)])
break
groups[-1].height = next_height
if forward_height == groups[-1].height:
H.popleft()
groups[-1].ids.append(mountain_id)
if len(groups) > 1:
if groups[-1].height == groups[-2].height:
groups[-2].ids.extend(groups[-1].ids)
del groups[-1]
# print("k={} g={}".format(k, groups)) | 1,100 | PYTHON3 |
#include <bits/stdc++.h>
template <class T>
inline void read(T &x) {
x = 0;
register char c = getchar();
register bool f = 0;
while (!isdigit(c)) f ^= c == '-', c = getchar();
while (isdigit(c)) x = x * 10 + c - '0', c = getchar();
if (f) x = -x;
}
using namespace std;
int n, m, ans;
string s, t, c, w;
struct node {
int next, val;
} e[2000006];
int a[1000006];
int main() {
cin >> n;
cin >> s;
cin >> t;
int rs = 0, rt = 0, flag = 1;
for (int i = 0; i < n; i++) {
if (s[i] != t[i]) {
flag = 0;
break;
}
}
if (flag) {
cout << "0" << endl;
return 0;
}
for (int i = 0; i < n; i++) {
if (s[i] == '1') {
rs++;
}
if (t[i] == '1') {
rt++;
}
}
if (rs != rt) {
cout << "-1" << endl;
return 0;
}
for (int i = 0; i < n; i++) {
if (s[i] != t[i]) {
c += s[i];
m++;
}
}
while (m > 0) {
w = "";
int len = m;
int i;
if (c[c.size() - 1] == '1' && c[0] == '0') {
i = 1;
m -= 2;
while (i < c.size() - 1) {
if (i + 1 >= c.size() - 1) {
w += c[i];
break;
}
if (c[i] == '1' && c[i + 1] == '0') {
i += 2;
m -= 2;
} else {
w += c[i];
i++;
}
}
} else {
i = 0;
while (i < c.size()) {
if (i + 1 >= c.size()) {
w += c[i];
break;
}
if (c[i] == '1' && c[i + 1] == '0') {
i += 2;
m -= 2;
} else {
w += c[i];
i++;
}
}
}
c = w;
ans++;
if (len - 2 == m) {
ans += m / 2;
break;
}
}
cout << ans << endl;
return 0;
}
| 2,100 | CPP |
t=0
a=int(input())
for i in range(a):
z=input()
if (z=="X++") or (z=="++X"):
t=t+1
elif (z=="X--") or (z=="--X"):
t=t-1
print(t) | 800 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
long long x, i, j, k, p, b, n;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
if (n % 4 == 1) {
cout << 0 << " "
<< "A" << endl;
} else {
if (n % 4 == 3) {
cout << 2 << " "
<< "A" << endl;
} else {
if (n % 4 == 2)
cout << 1 << " "
<< "B" << endl;
else
cout << 1 << " "
<< "A" << endl;
}
}
return 0;
}
| 800 | CPP |
#include <bits/stdc++.h>
using namespace std;
struct hash_pair {
template <class T1, class T2>
size_t operator()(const pair<T1, T2> &p) const {
auto hash1 = hash<T1>{}(p.first);
auto hash2 = hash<T2>{}(p.second);
return hash1 ^ hash2;
}
};
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long n;
cin >> n;
long long A[n];
for (long long i = 0; i < n; i++) {
cin >> A[i];
}
pair<long long, long long> DP[n + 10];
DP[n] = {(long long)0, (long long)0};
DP[n - 1].first = A[n - 1];
DP[n - 1].second = 0;
for (long long i = n - 2; i >= 0; i--) {
long long x = 0;
long long y = 0;
long long c = 0;
for (long long j = i; j < n; j++) {
long long temp = A[j] + DP[j + 1].second;
if (x < temp) {
x = temp;
y = c + DP[j + 1].first;
}
c += A[j];
}
DP[i] = {x, y};
}
cout << DP[0].second << " " << DP[0].first << endl;
}
| 1,500 | CPP |
n, k = map(int, input().split())
def get(x):
if x <= k:
return x * (x + 1) // 2
res = k * x - k * (k - 1) // 2
sz = x - k - 1
if sz % 2 == 0:
cnt = sz // 2
res += (2 + sz) * cnt // 2
else:
cnt = sz // 2 + 1
res += (1 + sz) * cnt // 2
return res
l = 0
r = 10 ** 18
while r - l > 1:
m = l + (r - l) // 2
if get(m) >= n:
r = m
else:
l = m
print(r)
| 2,100 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
int N;
char col[40][10];
int v(int x) { return col[x][0] == 'b'; }
void rd(int x) { scanf("%s", col[x]); }
void print(int x) {
printf("%d %d\n", x, x);
fflush(stdout);
}
int main() {
scanf("%d", &N);
if (N == 1) {
puts("0 0");
puts("0 1 1 0");
fflush(stdout);
return 0;
}
print(INF / 3);
rd(1);
print(INF * 2 / 3);
rd(2);
int col1, col2, L, R;
col1 = v(1);
col2 = col1 ^ 1;
if (v(1) == v(2)) {
L = INF * 2 / 3;
R = INF;
} else {
L = INF / 3;
R = INF * 2 / 3;
}
for (int i = 3; i <= N; i++) {
int mid = (L + R) / 2;
print(mid);
rd(i);
if (v(i) == col1)
L = mid;
else
R = mid;
}
printf("%d %d %d %d\n", L, L + 1, L + 1, L);
fflush(stdout);
}
| 1,900 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> hm;
vector<int> to;
vector<int> visited;
int hotel;
int main(int argc, char **argv) {
scanf("%d", &n);
for (int i = 0; i < 100000; i++) {
to.push_back(0);
visited.push_back(0);
}
for (int i = 0; i < n; i++) {
int temp;
scanf("%d", &temp);
if (temp == 1) hotel = i + 1;
hm.push_back(temp);
}
for (int i = 0; i < n; i++) {
int temp;
scanf("%d", &temp);
if (temp != 0) {
if (to[temp - 1] == 0)
to[temp - 1] = i + 1;
else
to[temp - 1] = -1;
}
}
vector<int> pathF;
for (int i = 0; i < n; i++) {
if (hm[i] == 0 && to[i] > 0 && visited[i] == 0) {
vector<int> path;
path.push_back(i + 1);
int cycle = i;
int t1 = i;
int d = -1;
visited[i] = 1;
int found = 0;
while (1) {
d = to[t1] - 1;
if (d == cycle) break;
if (to[d] > 0) {
path.push_back(d + 1);
t1 = d;
visited[d] = 1;
} else {
if (hm[d] == 1) {
path.push_back(d + 1);
found = 1;
}
break;
}
}
if (found == 1 && path.size() > pathF.size()) pathF = path;
}
}
if (pathF.size() > 1) {
printf("%d\n", pathF.size());
for (int i = 0; i < pathF.size(); i++) printf("%d ", pathF[i]);
} else {
printf("1\n%d", hotel);
}
return 0;
}
| 1,500 | CPP |
#include <bits/stdc++.h>
using namespace std;
string rooms;
vector<int> rm;
int n, k;
bool bs(int mid) {
int l = 0;
int r = k;
while (r < rm.size()) {
vector<int>::iterator re;
if (r == rm.size() - 1) {
re = rm.end();
} else {
re = rm.begin() + r + 1;
}
vector<int>::iterator a1 = upper_bound(rm.begin() + l, re, rm[l] + mid);
a1--;
vector<int>::iterator a2 = lower_bound(rm.begin() + l, re, rm[r] - mid);
if (a1 - a2 >= 0) {
return true;
}
l++;
r++;
}
return false;
}
int main() {
cin >> n >> k;
cin >> rooms;
rm.clear();
int r = 100000;
for (int i = 0; i < n; i++) {
if (rooms[i] == '0') {
rm.push_back(i);
}
}
int l = 0;
while (l + 1 < r) {
int mid = (l + r) / 2;
if (bs(mid)) {
r = mid;
} else {
l = mid;
}
}
cout << r << "\n";
}
| 1,600 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n;
int a[100000];
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%d", &a[i]);
set<int> ret, s1, s2;
for (int i = 0; i < n; i++) {
for (set<int>::iterator it = s1.begin(); it != s1.end(); it++) {
int y = (*it) | a[i];
ret.insert(y);
s2.insert(y);
}
ret.insert(a[i]);
s2.insert(a[i]);
s1 = s2;
s2.clear();
}
printf("%d\n", (int)ret.size());
return 0;
}
| 1,600 | CPP |
a,b,c,d=map(int,input().split())
if a==(b+c+d):
print("YES")
elif b==(a+c+d):
print("YES")
elif c==(a+b+d):
print("YES")
elif d==(a+c+b):
print("YES")
elif (a+b)==(c+d):
print("YES")
elif (a+c)==(b+d):
print("YES")
elif (a+d)==(b+c):
print("YES")
else:
print("NO") | 800 | PYTHON3 |
import re
s = input()
if re.match(".*h.*e.*l.*l.*o",s):
print("YES")
else:
print("NO")
| 1,000 | PYTHON3 |
n,h=map(int,input().split())
a=list(map(int,input().split()))
b=0
for i in a:
if i>h:
b+=1
c=len(a)-b
c=c+b*2
print(c)
| 800 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
srand(time(NULL));
long long n;
int k;
cin >> n >> k;
long long l = 1, r = n;
while (true) {
if (r - l >= 50) {
long long m = (l + r) >> 1;
cout << l << ' ' << m << endl;
string s;
cin >> s;
if (s[0] == 'Y') {
r = m;
} else if (s[0] == 'N') {
l = m + 1;
} else {
throw 1;
}
l = max((long long)1, l - k);
r = min(n, r + k);
} else {
long long x = rand() % (r - l + 1);
x += l;
cout << x << ' ' << x << endl;
string s;
cin >> s;
if (s[0] == 'Y') {
return 0;
} else if (s[0] != 'N') {
throw 1;
}
l = max((long long)1, l - k);
r = min(n, r + k);
}
}
return 0;
}
| 2,100 | CPP |
#include <bits/stdc++.h>
using namespace std;
bool u[123456];
int main() {
int n;
cin >> n;
string s;
cin >> s;
vector<int> v(n);
for (int i = 0; i < n; i++) cin >> v[i];
int cur = 0;
for (int i = 0; i <= n; i++) {
if (cur < 0 || cur >= n) {
cout << "FINITE";
return 0;
}
if (u[cur]) {
cout << "INFINITE";
return 0;
}
u[cur] = true;
if (s[cur] == '>')
cur += v[cur];
else
cur -= v[cur];
}
cout << "INFINITE";
return 0;
}
| 1,000 | CPP |
from sys import stdin,stdout
# from collections import deque,Counter,defaultdict
# from itertools import permutations,combinations,combinations_with_replacement
# from operator import itemgetter
# import heapq
# from functools import reduce
def ii():return int(stdin.readline())
def mi():return map(int,stdin.readline().split())
def li():return list(mi())
def si():return stdin.readline()
for _ in range(ii()):
l = ii()
pre = [0]*(l+1)
l1 = li()
last = 0
for i in range(len(l1)):
if pre[l1[i]] == 0:
print(l1[i],end = ' ')
pre[l1[i]] = 1
print('')
| 800 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 123456;
typedef struct Point {
int x, y, id;
Point() {}
Point(int id1, int x1, int y1) {
x = x1;
y = y1;
id = id1;
}
bool operator<(const Point &t) const { return y > t.y; }
} Point;
bool cmp(const Point &t1, const Point &t2) { return t1.x < t2.x; }
Point arr[maxn];
int ans[maxn];
int cnt;
int main() {
int n, m;
scanf("%d%d", &n, &m);
for (int i = 0; i < m; i++) {
int tp1, tp2;
scanf("%d%d", &tp1, &tp2);
arr[i] = Point(i + 1, n + 1 - tp1, tp2);
}
priority_queue<Point> Q;
cnt = 0;
while (!Q.empty()) {
Q.pop();
}
sort(arr, arr + m, cmp);
int i, j;
for (i = 1, j = 0; i <= n; ++i) {
for (; j < m && arr[j].x <= i; ++j) {
if (arr[j].y >= i) Q.push(arr[j]);
}
while (!Q.empty()) {
if (Q.top().y < i) {
Q.pop();
} else {
ans[cnt++] = Q.top().id;
Q.pop();
break;
}
}
}
printf("%d\n", cnt);
printf("%d", ans[0]);
for (int i = 1; i < cnt; i++) {
printf(" %d", ans[i]);
}
printf("\n");
return 0;
}
| 2,200 | CPP |
#include <bits/stdc++.h>
using namespace std;
constexpr int N = 3e3;
uint16_t a[N], lst[N], nxt[N], cnxt[19], dp[N][N];
int main() {
cin.tie(0), ios::sync_with_stdio(0);
int t, n;
cin >> t;
while (t--) {
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> a[i], --a[i];
}
memset(lst, 0, n * sizeof *lst);
for (int i = 0; i < n; ++i) {
++lst[a[i]];
}
int w = -1, r = 0, purged = 0;
while (r < n) {
if (w >= 0 && a[w] == a[r]) {
if (--lst[a[r++]] == 1) {
--w;
++purged;
}
} else if (lst[a[r]] == 1) {
++r;
++purged;
} else {
a[++w] = a[r++];
}
}
memset(lst, -1, n * sizeof *lst);
n = w + 1;
memset(nxt, 127, n * sizeof *nxt);
for (int i = 0; i < n; ++i) {
if (lst[a[i]] != (uint16_t)-1) {
nxt[lst[a[i]]] = i;
}
lst[a[i]] = i;
}
for (int i = n - 1; i > -1; --i) {
auto* cnxte = cnxt;
for (int z = nxt[i]; z < n; z = nxt[z]) {
*cnxte++ = z;
}
cnxte = cnxt;
for (int j = i + 1; j < n; ++j) {
if (a[j] == a[i]) {
++cnxte;
}
int t = dp[i + 1][j] - 1;
#pragma GCC unroll 2
for (const auto* z = cnxt; z != cnxte; ++z) {
t = max(t, dp[i + 1][*z - 1] + dp[*z][j]);
}
dp[i][j] = t + 1;
}
}
cout << (n ? n - dp[0][n - 1] : 0) - 1 + purged << '\n';
}
}
| 2,700 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long n, a, flag = 0;
cin >> n;
std::vector<long long> v(n + 1, -1);
for (long long i = 0; i < n + 1; i++) {
if (i == 0) continue;
cin >> a;
cin >> v[a];
}
long long index = lower_bound(v.begin(), v.end(), 1) - v.begin();
for (long long i = 0; i < n + 1; i++) {
long long change = (int)1e9;
if (i == 0) continue;
if (v[i] == -1) continue;
if (v[i] != -1) {
change = v[index] - v[i];
index = i;
}
if (change > 0) {
cout << "Happy Alex"
<< "\n";
return 0;
}
}
cout << "Poor Alex"
<< "\n";
return 0;
}
| 1,100 | CPP |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
int du[100100], xx[100100];
int main() {
int n;
while (cin >> n) {
for (int i = 0; i < n; i++) cin >> du[i] >> xx[i];
vector<pair<int, int> > pp;
queue<int> Q;
for (int i = 0; i < n - 1; i++)
if (du[i] == 1) Q.push(i);
while (!Q.empty()) {
int u = Q.front();
Q.pop();
if (du[u] == 0) continue;
pp.push_back(make_pair(u, xx[u]));
int t = xx[u];
xx[t] ^= u;
xx[u] = 0;
du[t]--;
du[u]--;
if (du[t] == 1) Q.push(t);
}
cout << pp.size() << endl;
int sz = pp.size();
for (int i = 0; i < sz; i++)
cout << pp[i].first << " " << pp[i].second << endl;
}
return 0;
}
| 1,500 | CPP |
rows = int(input())
sits = []
for i in range(rows) :
sits.append(input())
out = 'NO'
for i in range(len(sits)) :
if sits[i].find('OO') != -1 :
if sits[i][:2] == 'OO' :
sits[i] = '++' + sits[i][2:]
else:
sits[i] = sits[i][:3] + '++'
out = 'YES'
break
print(out)
if out == 'YES' :
for i in sits :
print(i) | 800 | PYTHON3 |
graph = input()
graph = graph.split(' ')
n = int(graph[0])
p = int(graph[1])
matrix =[[0] * n for i in range(n)]
conn = dict()
for i in range(p):
line = input()
line = line.split(' ')
matrix[int(line[0])-1][int(line[1])-1] = int(line[2])
conn[int(line[0])-1]=int(line[1])-1
iniciales = [i for i in conn.keys() if i not in conn.values()]
finales = [i for i in conn.values() if i not in conn.keys()]
iniciales.sort()
resultados = dict()
c = 0
for i in iniciales:
resultados[c]=[]
nodo = i
minimo = 10**6
while nodo not in finales:
resultados[c].append(nodo)
if matrix[nodo][conn[nodo]] < minimo:
minimo = matrix[nodo][conn[nodo]]
nodo = conn[nodo]
resultados[c].append(nodo)
resultados[c].append(minimo)
c += 1
print(len(resultados.keys()))
for element in resultados.values():
print(element[0]+1,element[-2]+1, element[-1]) | 1,400 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
long long int logy(long long int x, long long int y) {
return ceil((long double)(log(x) / log(y)));
}
long long int powe(long long int a, long long int b) {
long long int re = 1;
while (b) {
if (b & 1) re = (re * a);
a = (a * a);
b = b >> 1;
}
return re;
}
bool flag = 0, flag1 = 0, flag2 = 0;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long int n;
cin >> n;
vector<pair<pair<long long, long long>, pair<long long, long long>>> v(n);
multiset<long long int, greater<long long int>> x, y;
multiset<long long int> p, q;
for (long long int i = 0; i < n; i++) {
long long int x1, y1, p1, q1;
cin >> x1 >> y1 >> p1 >> q1;
v[i] = {{x1, y1}, {p1, q1}};
x.insert(x1);
y.insert(y1);
p.insert(p1);
q.insert(q1);
}
if (n == 1) {
cout << v[0].first.first << " " << v[0].first.second;
return 0;
}
for (long long int i = 0; i < n; i++) {
long long int x1 = v[i].first.first, y1 = v[i].first.second,
p1 = v[i].second.first, q1 = v[i].second.second;
x.erase(x.find(x1));
y.erase(y.find(y1));
p.erase(p.find(p1));
q.erase(q.find(q1));
long long int tx = *x.begin(), ty = *y.begin(), tp = *p.begin(),
tq = *q.begin();
if (tx <= tp && ty <= tq) {
cout << tx << " " << ty;
return 0;
}
x.insert(x1);
y.insert(y1);
p.insert(p1);
q.insert(q1);
}
return 0;
}
| 1,600 | CPP |
n, k = map(int, input().split())
s = input()
l = list(s)
m = list(s)
for _ in range(k):
for i in range(n - 1):
if m[i] == 'B' and m[i + 1] == 'G':
l[i] = 'G'
l[i + 1] = 'B'
m = l[:]
print("".join(l))
| 800 | PYTHON3 |
for _ in range(int(input())):
s=input();l=len(s)-2;print([s,s[0]+str(l)+s[l+1]][l>8])
| 800 | PYTHON3 |
# http://codeforces.com/problemset/problem/961/A
n, m = input().split()
n = int(n)
m = int(m)
indexes = input().split()
index_dict = {str(i):0 for i in range(1, n+1)}
for i in indexes:
index_dict[i] += 1
# index_dict = {i:indexes.count(i) for i in indexes}
min_col = min(index_dict[key] for key in index_dict)
print(min_col) | 900 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 5005;
long long par[2 * MAXN], dist[2 * MAXN], bit[MAXN], n, tot[2 * MAXN],
w[2 * MAXN], ans[2 * MAXN];
vector<long long> adj[2 * MAXN];
void update(long long now) {
for (long long i = now; i <= 5000; i += (i & (-i))) bit[i]++;
}
long long query(long long now) {
long long ret = 0;
for (long long i = now; i > 0; i -= (i & (-i))) ret += bit[i];
return ret;
}
void build() {
vector<long long> V;
dist[1] = 1;
n = 5000;
for (long long i = 2; i <= 5000; i++) {
V.clear();
long long tmp = i;
for (long long j = 2; j * j <= tmp; j++) {
if (tmp % j != 0) continue;
long long pangkat = 0;
while (tmp % j == 0) {
pangkat++;
tmp /= j;
}
for (long long k = 0; k < pangkat; k++) V.push_back(j);
}
if (tmp != 1) V.push_back(tmp);
long long que = query(V.back() - 1);
dist[i] = que + V.size();
long long last = i - 1;
while (dist[last] <= que) {
que -= dist[last];
last = par[last];
}
if (que == 0)
par[i] = last;
else {
n++;
par[i] = n;
par[n] = par[last];
par[last] = n;
dist[n] = dist[last] - que;
dist[last] = que;
}
for (auto isi : V) update(isi);
}
for (long long i = 2; i <= n; i++) {
adj[par[i]].push_back(i);
}
}
void dfs(long long now) {
tot[now] = w[now];
for (auto nxt : adj[now]) {
dfs(nxt);
tot[now] += tot[nxt];
ans[now] += (tot[nxt] * dist[nxt]);
ans[now] += ans[nxt];
}
}
void dfs2(long long now) {
for (auto nxt : adj[now]) {
ans[nxt] += (ans[now] - (ans[nxt] + tot[nxt] * dist[nxt]));
ans[nxt] += (dist[nxt] * (tot[1] - tot[nxt]));
dfs2(nxt);
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
build();
long long x, a;
cin >> x;
for (long long i = 1; i <= x; i++) {
cin >> a;
if (a == 0) a = 1;
w[a]++;
}
dfs(1);
dfs2(1);
long long jwb = 1e18;
for (long long i = 1; i <= n; i++) jwb = min(jwb, ans[i]);
cout << jwb << '\n';
return 0;
}
| 2,700 | CPP |
#include <bits/stdc++.h>
int main() {
unsigned long long n;
scanf("%I64d", &n);
printf("%I64d", n * (n + 1) / 2 * (n + 2) / 3 * (n + 3) / 4 * (n + 4) / 5 *
n * (n + 1) / 2 * (n + 2) / 3);
return 0;
}
| 1,600 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t;
cin >> t;
while (t--) {
long long n;
cin >> n;
vector<long long> a(n + 1), b(n + 1), min1(n + 1), max1(n + 1);
max1[0] = -10;
min1[0] = 10;
for (int i = 1; i <= n; i++) {
cin >> a[i];
min1[i] = min(min1[i - 1], a[i]);
max1[i] = max(max1[i - 1], a[i]);
}
for (int i = 1; i <= n; i++) cin >> b[i];
if (a[1] != b[1]) {
cout << "NO\n";
continue;
} else {
long long flag = 0;
for (int i = n; i > 1; i--) {
if (b[i] < a[i] && min1[i - 1] != -1) {
flag = 1;
break;
} else if (b[i] > a[i] && max1[i - 1] != 1) {
flag = 1;
break;
}
}
if (flag == 1) {
cout << "NO\n";
} else
cout << "YES\n";
}
}
return 0;
}
| 1,100 | CPP |
from collections import defaultdict
for _ in range(int(input())):
N = int(input())
A = input()
B = input()
flag = 0
for i in range(N):
if(ord(A[i])>ord(B[i])):
flag = 1
break
if(flag):
print(-1)
continue
else:
A = [i for i in A]
B = [i for i in B]
X = 97
Ans = 0
for x in range(20):
pos = []
current_character = chr(X + x)
Min = 198
for i in range(N):
if(A[i] == current_character and A[i]<B[i]):
Min = min(Min, ord(B[i]) - ord(A[i]))
pos.append(i)
if(pos):
for i in pos:
A[i] = chr(X + x + Min)
Ans+=1
print(Ans) | 1,700 | PYTHON3 |
Subsets and Splits