solution
stringlengths 10
983k
| difficulty
int64 0
25
| language
stringclasses 2
values |
---|---|---|
t = int(input())
while t:
t-=1
n = int(input())
a = list(map(int, input().split()))
freq = {}
maxi = float("-inf")
for x in a:
freq[x] = freq.get(x, 0) + 1
maxi = max(maxi, freq[x])
uniq = len(freq)
if n == 1:
print(0)
continue
if uniq == n:
print(1)
continue
print(max(min(uniq-1, maxi), min(uniq, maxi-1)))
| 9 | PYTHON3 |
'''input
6
5 6 2
2 4 3 5 7
5 11 2
2 4 3 5 7
2 10000 2
10000 10000
2 9999 2
10000 10000
5 13 2
8 2 8 2 5
3 18 2
1 2 3
'''
# A coding delight
from sys import stdin
import sys
sys.setrecursionlimit(10 ** 5)
def check(index):
aux = p
for i in range(index, -1, -2):
aux -= arr[i]
return aux >= 0
def binary_search(start, end):
while start < end:
# print(start, end)
mid = (start + end + 1) // 2
if check(mid):
start = mid
else:
end = mid - 1
if check(start):
return start + 1
else:
return start
# main starts
t = int(stdin.readline().strip())
for _ in range(t):
n, p, k = list(map(int, stdin.readline().split()))
arr = list(map(int, stdin.readline().split()))
arr.sort()
ans = 0
ans = binary_search(0, n - 1)
print(ans)
| 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
vector<pair<long long int, pair<long long int, long long int>>> v;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n, mark[1005] = {0};
long long int x, y, r, area = 0;
cin >> n;
for (int i = 0; i < int(n); ++i)
cin >> x >> y >> r, v.push_back(make_pair(r, make_pair(x, y)));
sort(v.begin(), v.end());
reverse(v.begin(), v.end());
for (int i = 0; i < int(n - 1); ++i) {
r = (v[i].first) * (v[i].first);
for (int j = i + 1; j < n; j++) {
x = (v[i].second.first - v[j].second.first) *
(v[i].second.first - v[j].second.first);
y = (v[i].second.second - v[j].second.second) *
(v[i].second.second - v[j].second.second);
if (x + y <= r) mark[j] = max(mark[j], i + 1);
}
}
list<pair<int, int>> q;
q.push_back(make_pair(0, 1));
while (!q.empty()) {
pair<int, int> m = q.front();
for (int i = 0; i < int(n); ++i)
if (m.first == mark[i]) {
q.push_back(make_pair(i + 1, m.second + 1));
r = (v[i].first) * (v[i].first);
if (m.second % 2 == 0 || m.second == 1)
area += r;
else
area -= r;
}
q.pop_front();
}
double arr = acos(-1) * (double)area;
cout << setprecision(10) << fixed << arr;
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const long long INF = 1e7;
long long p(long long n, long long k) {
if (k == 0) return 1;
if (k % 2 == 1)
return min(INF, n * p(min(INF, n * n), k / 2));
else
return p(min(INF, n * n), k / 2);
}
int main() {
ios_base::sync_with_stdio(false);
long long n, k;
cin >> n >> k;
long long a[n];
for (long long i = 0; i < n; i++) {
cin >> a[i];
for (long long x = 2; p(x, k) <= a[i]; x++) {
while ((a[i] % p(x, k)) == 0) a[i] /= p(x, k);
}
}
long long ans = 0;
map<long long, long long> K;
for (long long i = 0; i < n; i++) {
long long x = a[i];
long long y = 1;
for (long long p_ = 2; p_ <= 320; p_++) {
long long alfa = 0;
while (x % p_ == 0) {
x /= p_;
alfa++;
}
if (alfa > 0) y *= p(p_, k - alfa);
y = min(y, INF);
}
if (x != 1) y *= p(x, k - 1);
y = min(y, INF);
ans += K[y];
K[a[i]]++;
}
cout << ans << "\n";
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 121;
using ll = long long;
ll a[N];
ll f(ll n, ll k) { return (n + k - 1) / k; }
ll now[N];
int main() {
ios ::sync_with_stdio(0);
int n;
ll k;
cin >> n >> k;
vector<pair<int, int>> v;
ll all = 0;
for (int i = 1; i <= n; i++) {
ll j = 1;
cin >> a[i];
all += a[i];
v.push_back({1, i});
for (int j = 1; j <= a[i]; j = a[i] / (a[i] / (j + 1))) {
if (j == a[i]) break;
v.push_back({j + 1, i});
}
for (int j = 1; j * j <= a[i]; j++)
if (a[i] % j == 0) {
v.push_back({j, i});
v.push_back({a[i] / j, i});
}
}
sort(v.begin(), v.end());
ll ans = 0, sum = 0;
for (int i = 0; i < v.size(); i++) {
sum -= now[v[i].second];
sum += f(a[v[i].second], v[i].first);
now[v[i].second] = f(a[v[i].second], v[i].first);
ll l = v[i].first, r = (i + 1 == v.size()) ? 2e11L : v[i + 1].first - 1;
r = min(r, (k + all) / sum);
if (l <= r) ans = max(ans, r);
}
cout << ans << '\n';
}
| 9 | CPP |
#include <bits/stdc++.h>
using namespace std;
struct Tpt {
long long p, q;
};
bool ByPQ(const Tpt& a, const Tpt& b) {
return a.p < b.p || (a.p == b.p && a.q < b.q);
}
const int MAX_PN = 100010;
Tpt P[MAX_PN];
int Pn, Dn, V;
int X[MAX_PN], T[MAX_PN];
long long D[MAX_PN];
const int MAX_ARR = MAX_PN << 2;
int Tmax[MAX_ARR];
int Ql, Qr, Qw, Qp, Ans;
void QueryUtil(int p = 1, int l = 1, int r = Dn) {
if ((r < Ql || Qr < l)) return;
if ((Ql <= l && r <= Qr)) {
((Ans) < (Tmax[p]) ? (Ans) = (Tmax[p]) : 1);
return;
}
QueryUtil((p << 1), l, ((l + r) >> 1)),
QueryUtil((p << 1 | 1), ((l + r) >> 1) + 1, r);
}
int Query(int l, int r) {
Ql = l, Qr = r, Ans = -(INT_MAX >> 1);
QueryUtil();
return Ans;
}
void PushUp(int p) {
Tmax[p] = ((Tmax[(p << 1)]) > (Tmax[(p << 1 | 1)]) ? (Tmax[(p << 1)])
: (Tmax[(p << 1 | 1)]));
}
void ModifyUtil(int p = 1, int l = 1, int r = Dn) {
if ((r < Qp || Qp < l)) return;
if (l == r) {
Tmax[p] = Qw;
return;
}
ModifyUtil((p << 1), l, ((l + r) >> 1)),
ModifyUtil((p << 1 | 1), ((l + r) >> 1) + 1, r);
PushUp(p);
}
void Modify(int p, int w) {
Qp = p, Qw = w;
ModifyUtil();
}
int DP() {
int ret = 0;
for (int i = 1, f; i <= Pn; i++) {
int p = (lower_bound(D + 1, D + 1 + Dn, (P[i].q)) - D);
if (P[i].p == 0 && P[i].q == 0) {
f = 0;
} else {
f = 1 + Query(1, p);
}
Modify(p, f);
((ret) < (f) ? (ret) = (f) : 1);
}
return ret;
}
inline void Main() {
scanf("%d", &Pn);
for (int i = 1; i <= Pn; i++) {
scanf("%d%d", X + i, T + i);
}
scanf("%d", &V);
for (int i = 1; i <= Pn; i++) {
P[i] = (Tpt){(long long)X[i] + T[i] * V, (long long)-X[i] + T[i] * V};
D[++Dn] = P[i].q;
}
P[++Pn] = (Tpt){0, 0}, D[++Dn] = 0;
sort(P + 1, P + 1 + Pn, ByPQ);
sort(D + 1, D + 1 + Dn);
Dn = unique(D + 1, D + 1 + Dn) - D - 1;
memset(Tmax, -60, sizeof(Tmax));
int ans1 = DP();
memset(Tmax, 0, sizeof(Tmax));
int ans2 = DP();
printf("%d %d\n", ans1, ans2);
}
int main() {
Main();
return 0;
}
| 12 | CPP |
n,k = map(int,input().split())
a = list(map(int,input().split()))
p = a[k-1]
count= 0
for i in range(len(a)):
if a[i]>=p and a[i]!=0:
count = count+1
print(count)
| 7 | PYTHON3 |
#!/usr/bin/python
import sys
import math
def gcd(a, b):
if a == 0:
return b
return gcd(b % a, a)
N = int(input())
x, y = map(int, input().split(' '))
divisor = 2
result = []
while divisor <= math.sqrt(max(x,y)):
if (x % divisor == 0) or (y % divisor == 0):
result.append(divisor)
while x % divisor == 0:
x /= divisor
while y % divisor == 0:
y /= divisor
divisor += 1
if (x > 1):
result.append(x)
if (y > 1):
result.append(y)
for i in range(1, N):
x, y = map(int, input().split(' '))
new_result = [i for i in result if ((x % i == 0) or (y % i == 0))]
result = new_result
if len(result) < 1:
print(-1)
else:
print(int(result[0]))
| 8 | PYTHON3 |
#include <algorithm>
#include <cstdio>
#include <vector>
using namespace std;
int v[100];
vector<int> g[100];
inline int dfs(int x){
int ans = 0;
for(int i = 0,l = g[x].size(); i < l; i++){
int y = g[x][i];
v[x]++;
if(!v[y]){
ans = max(ans,dfs(y)+1);
}
v[x]--;
}
return ans;
}
int main(){
int n;
while(scanf("%d",&n),n){
int M = 0;
for(int i = 0; i < n; i++){
int a,b;
scanf("%d%d",&a,&b);
M = max(M,b);
a--;b--;
g[a].push_back(b);
g[b].push_back(a);
}
int ans = 0,size = 100;//sizeは嘘枝刈り用
for(int i = 0; i < M; i++){
size = min((int)g[i].size(),size);
}
size += 3;//2だとWAすることを確認済み
for(int i = 0; i < M; i++){
if(g[i].size()<=size)ans = max(ans,dfs(i)+1);
}
printf("%d\n",ans);
for(int i = 0; i < M; i++){
g[i].clear();
}
}
return 0;
}
| 0 | CPP |
x = 0
n = int(input())
for i in range(n):
statement = input()
if statement == '++X' or statement == 'X++':
x += 1
if statement == '--X' or statement == 'X--':
x -= 1
print(x)
| 7 | PYTHON3 |
#include <bits/stdc++.h>
int main() {
long long int n, i, sum = 0;
scanf("%lld", &n);
if (n <= 9)
sum = n;
else if (n <= 99)
sum = n + (n - 9);
else if (n <= 999)
sum = n + (n - 9) + (n - 99);
else if (n <= 9999)
sum = 4 * n - 9 - 99 - 999;
else if (n <= 99999)
sum = 5 * n - 9 - 99 - 999 - 9999;
else if (n <= 999999)
sum = 6 * n - 9 - 99 - 999 - 9999 - 99999;
else if (n <= 9999999)
sum = 7 * n - 9 - 99 - 999 - 9999 - 99999 - 999999;
else if (n <= 99999999)
sum = 8 * n - 9 - 99 - 999 - 9999 - 99999 - 999999 - 9999999;
else if (n <= 999999999)
sum = 9 * n - 9 - 99 - 999 - 9999 - 99999 - 999999 - 9999999 - 99999999;
else if (n <= 9999999999)
sum = 10 * n - 9 - 99 - 999 - 9999 - 99999 - 999999 - 9999999 - 99999999 -
999999999;
printf("%lld\n", sum);
return 0;
}
| 8 | CPP |
#include<bits/stdc++.h>
using namespace std;
long long k;
int n;
long long dp[100001];
long long mod=1000000007;
int main()
{
ios_base::sync_with_stdio(false);
memset(dp,0,sizeof(dp));
cin>>n>>k;
int i,j;
long long a;
dp[0]=1;
for(i=0;i<n;i++)
{
cin>>a;
for(j=1;j<=k;j++)
dp[j]=(dp[j-1]%mod+dp[j]%mod)%mod;
for(j=k;j>=a+1;j--)
dp[j]=(dp[j]%mod-dp[j-a-1]%mod+mod)%mod;
}
cout<<dp[k];
return 0;
}
| 0 | CPP |
s = input()
if (s[6] == '0' or s[6] == '2' or s[6] == '4' or s[6] == '6' or s[6] == '8' or s[6] == 'A' or s[6] == 'C' or s[6] == 'E'):
print(0)
else:
print(1) | 10 | PYTHON3 |
'''from sys import stdin, stdout
in1 = int(stdin.readline())
for i in range(in1):
in2 = stdin.readline()
in3 = stdin.readline()
in3 = in3.split()
l = len(set(in3))
stdout.write(l)
'''
'''
in1 = int(input())
for i in range(in1):
in2 = input()
in3 = input().split()
l = len(set(in3))
print(l)
'''
from collections import Counter
in1 = int(input())
for i in range(in1):
in2 = input()
in3 = input().split()
print(len(Counter(in3).keys())) | 7 | PYTHON3 |
#include <bits/stdc++.h>
int main() {
unsigned long int num0;
int len = 1, num2 = 1, newNum, i, num3;
scanf("%d", &num0);
int num1 = num0;
if (num0 > 0) {
for (len = 0; num0 > 0; len++) {
num0 = num0 / 10;
}
for (i = 0; i < len - 1; i++) {
num2 *= 10;
}
num3 = num2;
num2 = num1 / num2;
newNum = ((num2 + 1) * num3) - num1;
printf("%d\n", newNum);
} else {
printf("10\n");
}
return 0;
}
| 7 | CPP |
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
LL a[100010],b[100010];
int n,ans;
map<LL,int>mp;
LL sqr(LL x){return x*x;}
int main(){
scanf("%d",&n);
for(int i=1; i<=n; i++){
LL x;
scanf("%lld",&x);
for(LL j=2;j*j*j<=x;j++) for(;x%(j*j*j)==0;x/=j*j*j);
mp[x]++;
a[i]=x;
LL y=1;
for(LL j=2;j*j*j<=x;j++) if(x%j==0){
y*=(x%(j*j)==0)?j:j*j;
for(;x%j==0;x/=j);
}
if(sqr((LL)sqrt(x))==x) y*=(LL)sqrt(x);
else y*=x*x;
b[i]=y;
}
if(mp[1]) ans++,mp[1]=0;
for(int i=1;i<=n;i++){
ans+=max(mp[a[i]],mp[b[i]]);
mp[a[i]]=mp[b[i]]=0;
}
printf("%d",ans);
return 0;
}
/*
8
1
2
3
4
5
6
7
8
*/ | 0 | CPP |
number = int(input())
first = [[0 for i in range(number)] for i in range(number)]
for i in range(number):
first[0][i] = 1
for i in range(number):
for j in range(number):
first[i][j] = first[i - 1][j] + first[i][j - 1]
print(1 if number==1 else first[number-1][number-1]) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int h[100002];
int n, a, b;
bool ok(int t){
long long q = 0;
for(int i = 1; i <= n; ++i){
if (1ll * a * t < h[i]) return false;
long long x = h[i] - 1ll * b * t;
if (x > 0) q += (x - 1) / (a - b) + 1;
if (q > t) return false;
}
return true;
}
int main(){
scanf("%d%d%d",&n,&a,&b);
for(int i = 1; i <= n; ++i) scanf("%d",&h[i]);
int l = 1, r = 1e9;
while (l <= r){
int md = (l + r) >> 1;
if (ok(md)) r = md - 1;
else l = md + 1;
}
printf("%d",l);
return 0;
} | 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll get_val(ll a, char op, ll b)
{
switch (op) {
case '*':
return a * b;
case '+':
return a + b;
case '-':
return a - b;
}
assert(0);
}
class Calc {
string str;
vector<char> p;
string::iterator it;
public:
Calc(const string &str, vector<char> p){
this->str = str;
this->p = p;
it = this->str.begin();
}
ll f0()
{
ll res = 0;
if (*it == '(') {
++it;
res = f3();
++it;
} else {
while (isdigit(*it)) {
res *= 10LL;
res += (ll)(*it - '0');
++it;
}
}
return res;
}
ll f1()
{
ll res = f0();
while (*it == p[0]) {
++it;
res = get_val(res, p[0], f0());
}
return res;
}
ll f2()
{
ll res = f1();
while (*it == p[1]) {
++it;
res = get_val(res, p[1], f1());
}
return res;
}
ll f3()
{
ll res = f2();
while (*it == p[2]) {
++it;
res = get_val(res, p[2], f2());
}
return res;
}
};
class Calc2 {
string str;
vector<char> p;
string::iterator it;
public:
Calc2(const string &str, vector<char> p){
this->str = str;
this->p = p;
it = this->str.begin();
}
ll f0()
{
ll res = 0;
if (*it == '(') {
++it;
res = f2();
++it;
} else {
while (isdigit(*it)) {
res *= 10LL;
res += (ll)(*it - '0');
++it;
}
}
return res;
}
ll f1()
{
ll res = f0();
while (*it == p[0]) {
++it;
res = get_val(res, p[0], f0());
}
return res;
}
ll f2()
{
ll res = f1();
while (*it == p[1] || *it == p[2]) {
if (*it == p[1]) {
++it;
res = get_val(res, p[1], f1());
} else {
++it;
res = get_val(res, p[2], f1());
}
}
return res;
}
};
class Calc22 {
string str;
vector<char> p;
string::iterator it;
public:
Calc22(const string &str, vector<char> p){
this->str = str;
this->p = p;
it = this->str.begin();
}
ll f0()
{
ll res = 0;
if (*it == '(') {
++it;
res = f2();
++it;
} else {
while (isdigit(*it)) {
res *= 10LL;
res += (ll)(*it - '0');
++it;
}
}
return res;
}
ll f1()
{
ll res = f0();
while (*it == p[0] || *it == p[1]) {
if (*it == p[0]) {
++it;
res = get_val(res, p[0], f0());
} else {
++it;
res = get_val(res, p[1], f0());
}
}
return res;
}
ll f2()
{
ll res = f1();
while (*it == p[2]) {
++it;
res = get_val(res, p[2], f1());
}
return res;
}
};
class Calc3 {
string str;
vector<char> p;
string::iterator it;
public:
Calc3(const string &str, vector<char> p){
this->str = str;
this->p = p;
it = this->str.begin();
}
ll f0()
{
ll res = 0;
if (*it == '(') {
++it;
res = f1();
++it;
} else {
while (isdigit(*it)) {
res *= 10LL;
res += (ll)(*it - '0');
++it;
}
}
return res;
}
ll f1()
{
ll res = f0();
while (*it == p[0] || *it == p[1] || *it == p[2]) {
if (*it == p[0]) {
++it;
res = get_val(res, p[0], f0());
} else if (*it == p[1]) {
++it;
res = get_val(res, p[1], f0());
} else {
++it;
res = get_val(res, p[2], f0());
}
}
return res;
}
};
int main()
{
string str;
cin >> str;
vector<char> p = {'*', '+', '-'};
ll res = LLONG_MIN;
do {
Calc c(str, p);
Calc2 c2(str, p);
Calc22 c22(str, p);
Calc3 c3(str, p);
res = max(res, max(max(c.f3(), c2.f2()), max(c22.f2(), c3.f1())));
} while (next_permutation(p.begin(), p.end()));
cout << res << endl;
return 0;
} | 0 | CPP |
n = int(input())
for i in map(int, input().split()):
print('YNEOS'[not 0 < i % 14 < 7 < i::2])
| 8 | PYTHON3 |
print(''.join('.'+ i for i in input().lower() if i not in 'aeuiyo')) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, a, b, c;
cin >> n >> a >> b >> c;
if (n < a && n < b) {
cout << 0 << endl;
return 0;
}
if (a <= b - c) {
cout << n / a << endl;
} else {
long long ans = (n - c) / (b - c);
long long rm = n - ans * b + ans * c;
long long ans2 = rm / a;
cout << max(n / a, ans + ans2) << endl;
}
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
string s;
cin >> s;
int co = 0;
for (int i = 0; i < s.size(); i++) {
bool c = 0;
for (int j = i + 3; j < s.size(); j++) {
if (c || (s[j - 3] == 'b' && s[j - 2] == 'e' && s[j - 1] == 'a' &&
s[j] == 'r'))
c = 1, co++;
}
}
cout << co;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long int powmod(long long int a, long long int k, long long int m) {
if (a == 0) {
return 0;
}
long long int apow[60], c[60];
for (int i = 0; i < 60; i++) {
if (i == 0) {
apow[i] = a;
c[i] = 1;
} else {
apow[i] = apow[i - 1] * apow[i - 1] % m;
c[i] = c[i - 1] * 2;
}
}
long long int ans = 1;
for (int i = 59; i >= 0; i--) {
if (k >= c[i]) {
ans = ans * apow[i] % m;
}
k = k % c[i];
}
return ans;
}
int main() {
long long int x, k;
scanf("%lld %lld", &x, &k);
if (x == 0) {
printf("%d\n", 0);
return 0;
}
x = x % 1000000007LL;
if (k == 0) {
printf("%lld\n", x * 2 % 1000000007LL);
return 0;
}
long long int ans =
(1 + (powmod(2, k, 1000000007LL) *
((2 * x + 1000000007LL - 1) % 1000000007LL) % 1000000007LL)) %
1000000007LL;
printf("%lld\n", ans);
return 0;
}
| 9 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
const int MOD = 998244353;
struct node {
long long a, b;
node() {}
node(long long a, long long b) {
this->a = a;
this->b = b;
}
node operator+(const node& rhs) const {
return node((a + rhs.a) % MOD, (b + rhs.b) % MOD);
}
node operator*(const node& rhs) const {
return node(a * rhs.a % MOD, b * rhs.b % MOD);
}
bool operator==(const node& rhs) const { return a == rhs.a && b == rhs.b; }
};
node BASE(2333, 233333);
node h[maxn];
node ALL(0, 0);
node s[maxn][15];
vector<pair<int, int> > vec[maxn];
int n, m, k, ans;
void dfs(int u, node hh) {
if (u > k) {
ans += (hh == ALL ? 1 : 0);
return;
}
for (int i = 0; i < u; i++) {
node v = hh + s[u][i];
dfs(u + 1, v);
}
return;
}
int main() {
scanf("%d%d%d", &n, &m, &k);
h[0] = node(1, 1);
for (int i = 1; i <= n; i++) {
h[i] = h[i - 1] * BASE;
ALL = ALL + h[i];
}
for (int i = 1; i <= m; i++) {
int u, v, w;
scanf("%d%d%d", &u, &v, &w);
vec[u].emplace_back(make_pair(v, w));
}
for (int i = 1; i <= n; i++) {
sort(vec[i].begin(), vec[i].end(), [](pair<int, int> a, pair<int, int> b) {
return a.second < b.second;
});
int lens = vec[i].size();
for (int j = 0; j < lens; j++) s[lens][j] = s[lens][j] + h[vec[i][j].first];
}
dfs(1, node(0, 0));
printf("%d\n", ans);
return 0;
}
| 8 | CPP |
#include <iostream>
using namespace std;
int main(void) {
long long I, O, T, J, L, S, Z;
cin >> I >> O >> T >> J >> L >> S >> Z;
long long ans = O;
int n = I%2 + J%2 + L%2;
if (n>=2 && I>0 && J>0 && L>0) {
ans+=3;
I--, J--, L--;
}
ans = ans + I/2*2 + J/2*2 + L/2*2;
cout << ans << endl;
return 0;
}
| 0 | CPP |
t = int(input())
for _ in range(t):
n = int(input())
res = 0
while n > 1:
res += (n * 4 - 4) * (n // 2)
n -= 2
print(res)
| 9 | PYTHON3 |
l, r = map(int, input().split())
output = -1
for i in range(l, r+1):
if len(set(str(i))) == len(str(i)):
output = i
break
print(output) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
long double x = 1.000000011;
int main() {
long double n;
int t;
cin >> n >> t;
while (t > 0) {
if (t % 2 == 1) n *= x;
x *= x;
t /= 2;
}
cout.precision(10);
cout << n;
return 0;
}
| 8 | CPP |
input()
print(len({tuple(sorted(set(w))) for w in input().split()}))
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main()
{
string s;
long long k;
cin>>s>>k;
for(int i=0;i<k;i++)if(s[i]!='1')cout<<s[i]<<endl,exit(0);
cout<<"1\n";
return 0;
}
| 0 | CPP |
c,*s=input();n=len(s);print(sum(eval(c+''.join('+'*(b>>i&1)+s[i]for i in range(n)))for b in range(2**n))) | 0 | PYTHON3 |
while 1:
put=input()
if(put=="END OF INPUT"):
break
print(''.join(map(str,map(len,put.split(' ')))))
| 0 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5;
int X1[MAXN], Y1[MAXN], X2[MAXN], Y2[MAXN];
pair<int, int> yV[10], xV[10];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> X1[i] >> Y1[i] >> X2[i] >> Y2[i];
X1[i] = 2 * X1[i];
Y1[i] = 2 * Y1[i];
X2[i] = 2 * X2[i];
Y2[i] = 2 * Y2[i];
}
int minX = X1[0], maxX = X2[0];
int minY = Y1[0], maxY = Y2[0];
for (int i = 1; i < n; i++) {
minX = min(X1[i], minX);
maxX = max(X2[i], maxX);
minY = min(Y1[i], minY);
maxY = max(Y2[i], maxY);
}
if (maxX - minX + 1 != maxY - minY + 1) {
cout << "NO" << endl;
return 0;
}
int ok = 1;
for (int x = minX; x <= maxX && ok; x++) {
int m = 0;
for (int i = 0; i < n; i++) {
if (x >= X1[i] && x <= X2[i]) {
yV[m++] = pair<int, int>(Y1[i], Y2[i]);
}
}
if (m == 0) {
ok = 0;
continue;
}
sort(yV, yV + m);
int start = yV[0].first, end = yV[0].second;
for (int i = 1; i < m; i++) {
int left = yV[i].first, right = yV[i].second;
if (left > end) {
ok = 0;
break;
}
end = max(end, right);
}
if (ok) {
if (end != maxY || start != minY) ok = 0;
}
}
for (int y = minY; y <= maxY && ok; y++) {
int m = 0;
for (int i = 0; i < n; i++) {
if (y >= Y1[i] && y <= Y2[i]) {
xV[m++] = pair<int, int>(X1[i], X2[i]);
}
}
if (m == 0) {
ok = 0;
continue;
}
sort(xV, xV + m);
int start = xV[0].first, end = xV[0].second;
for (int i = 1; i < m; i++) {
int left = xV[i].first, right = xV[i].second;
if (left > end) {
ok = 0;
break;
}
end = max(end, right);
}
if (ok) {
if (end != maxX || start != minX) ok = 0;
}
}
if (ok)
cout << "YES" << endl;
else
cout << "NO" << endl;
return 0;
}
| 7 | CPP |
import math, sys
ax,ay,bx,by,tx,ty = list(map(float, input().split()))
n = int(input())
def dist(x1,y1,x2,y2):
return math.sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2))
cost = 0
bottleCoord = []
for i in range(0,n):
x,y = list(map(float, input().split()))
cost += 2*dist(tx,ty,x,y)
bottleCoord.append((x,y))
asCost = [(0,-1)]
bsCost = [(0,-1)]
for i in range(0,n):
asCost.append((dist(ax,ay,bottleCoord[i][0],bottleCoord[i][1]) - dist(bottleCoord[i][0],bottleCoord[i][1],tx,ty),i))
bsCost.append((dist(bx,by,bottleCoord[i][0],bottleCoord[i][1]) - dist(bottleCoord[i][0],bottleCoord[i][1],tx,ty),i))
asCost.sort()
bsCost.sort()
costTmpIndiv = sys.maxsize
for i in range(0,min(len(asCost),5)):
for j in range(0, min(len(bsCost),5)):
if (asCost[i][1] != bsCost[j][1]):
costTmpIndiv = min(costTmpIndiv, asCost[i][0]+bsCost[j][0])
print(cost + costTmpIndiv)
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
void Main();
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
Main();
return 0;
}
void Main() {
long long int m, n;
cin >> m >> n;
vector<vector<long long int>> B(m, vector<long long int>(n));
for (long long int i = 0; i < m; i++)
for (long long int j = 0; j < n; j++) cin >> B[i][j];
vector<vector<long long int>> A(m, vector<long long int>(n, 1));
for (long long int i = 0; i < m; i++) {
for (long long int j = 0; j < n; j++)
if (B[i][j] == 0) {
for (long long int k = 0; k < n; k++) A[i][k] = 0;
for (long long int k = 0; k < m; k++) A[k][j] = 0;
}
}
for (long long int i = 0; i < m; i++) {
for (long long int j = 0; j < n; j++) {
long long int OR = 0;
for (long long int k = 0; k < m; k++) OR |= A[k][j];
for (long long int k = 0; k < n; k++) OR |= A[i][k];
if (OR != B[i][j]) {
cout << "NO\n";
return;
}
}
}
cout << "YES\n";
for (long long int i = 0; i < m; i++, cout << "\n")
for (long long int j = 0; j < n; j++) cout << A[i][j] << " ";
}
| 8 | CPP |
from itertools import product
x, t,a,b,da,db = map(int, input().split())
ans=0
la,lb = [0],[0]
for i in range(t):
la +=[a-i*da]
lb +=[b-i*db]
for sx in product(la,lb):
if sx[0]+sx[1]==x:
ans=1
break
print(['NO','YES'][ans]) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, x;
cin >> n >> x;
vector<int> a(n);
vector<int> b(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n; i++) {
cin >> b[i];
}
sort(a.rbegin(), a.rend());
sort(b.begin(), b.end());
bool flag = true;
for (int i = 0; i < n; i++) {
if (a[i] + b[i] > x) {
flag = false;
break;
}
}
if (flag) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i;
cin >> n;
vector<int> v;
while (n != 0) {
v.push_back(n % 2);
n /= 2;
}
for (i = v.size() - 1; i >= 0; i--) {
if (v[i] == 1) cout << i + 1 << " ";
}
return 0;
}
| 7 | CPP |
s = input()
t = input()
l = list(s)
l.sort()
c=0
for i in range(len(l)):
if l[i]!='0':
c = i
break
x = ['0']*c
#print(x)
l = [l[c]] + x + l[c+1:]
l = ''.join(l)
if l == t:
print('OK')
else:
print('WRONG_ANSWER')
| 8 | PYTHON3 |
/*
author: Kamal Shakhdullaev
*/
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:512000000")
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <string>
#include <cmath>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <sstream>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <cstdlib>
#include <cstdio>
#include <iterator>
#include <functional>
#include <bitset>
#include <iomanip>
#include <float.h>
#include <math.h>
#include <random>
#include <chrono>
using namespace std;
//mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());
using ll = long long;
using db = double;
using ldb = long double;
using str = string;
using pi = pair <int, int>;
using pl = pair <ll, ll>;
using pd = pair <db, db>;
using vi = vector <int>;
using vl = vector <ll>;
using vb = vector <bool>;
using vd = vector <db>;
using vs = vector <str>;
using vpi = vector <pi>;
using vpl = vector <pl>;
using vpd = vector <pd>;
#define mp make_pair
#define X first
#define Y second
#define sz(x) int((x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
//#define sor(x) sort(all(x))
#define rsz resize
#define ins insert
#define pb push_back
#define pf push_front
#define eb emplace_back
#define bk back()
#define ft front()
#define lb lower_bound
#define ub upper_bound
int dx[4] = { 0, 0, 1, -1 };
int dy[4] = { 1, -1, 0, 0 };
const int MOD = 1000000000 + 7; // 998244353
const int MAXN = (int)1e5 + 5;
const ll INFint = 1000000000;
const ll INF = 1000000000000000000;
const db PI = acos((db)-1);
int nxt() {
int x;
cin >> x;
return x;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int t; cin >> t;
while (t--) {
int n, m, k;
cin >> n >> m >> k;
vi c0(n, 0), c1(m, 0);
for (int i = 0; i < k; ++i) {
int a;
cin >> a;
++c0[a - 1];
}
for (int i = 0; i < k; ++i) {
int b;
cin >> b;
++c1[b - 1];
}
ll res = (ll)k * (k - 1) / 2;
for (auto v : c0) res -= (ll)v * (v - 1) / 2;
for (auto v : c1) res -= (ll)v * (v - 1) / 2;
cout << res << '\n';
}
return 0;
}
/*
*/ | 9 | CPP |
s=input().split(' ')
n=int(s[0])
if s[2]=='month':
if n>=1 and n<=29:
print(12)
elif n==30:
print(11)
elif n==31:
print(7)
elif s[2]=='week':
if n==5 or n==6:
print(53)
else:
print(52)
| 7 | PYTHON3 |
input()
a = list(map(int,input().split()))
b = list(map(int,input().split()))
a1 = len([x for x in a if x % 2 == 0])
a2 = len(a)-a1
b1 = len([x for x in b if x % 2 == 0])
b2 = len(b)-b1
sol = 0
x = min(a2,b1)
sol += x
a2 -= x
b1 -= x
x = min(a1,b2)
sol += x
a1 -= x
b2 -= x
print(sol) | 7 | PYTHON3 |
import sys
input=sys.stdin.readline
n=int(input())
a=list(map(int,input().split()))
b={}
c={}
d=[]
for i in range(n):
b[a[i]]=b.get(a[i],0)+1
c[b[a[i]]]=c.get(b[a[i]],0)+1
if c[b[a[i]]]*b[a[i]]==i+1:
if i+2<=n:
d.append(i+2)
if c[b[a[i]]]*b[a[i]]==i:
if i+1<=n:
d.append(i+1)
if len(d)==0:
print(1)
exit()
print(max(d))
| 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100000 + 5;
int n;
char ch[1000004];
long long num;
map<long long, long long> mp;
long long now;
int cnt[28];
long long ans;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%s", ch + 1);
int len = strlen(ch + 1);
memset(cnt, 0, sizeof cnt);
for (int j = 1; j <= len; j++) {
cnt[ch[j] - 'a']++;
}
num = 0;
for (int j = 0; j < 26; j++) {
if (cnt[j] & 1) {
num |= (1 << j);
}
}
ans += mp[num];
for (int j = 0; j < 26; j++) {
now = num ^ (1 << j);
ans += mp[now];
}
mp[num]++;
}
cout << ans;
return 0;
}
| 14 | CPP |
n = int(input())
mod = 10**9 + 7
d = {}
for i in range(2,n+1):
x = i
for j in range(2,x+1):
while x % j == 0:
x = x // j
d[j] = d.get(j, 0) + 1
ret = 1
for v in d.values():
ret *= v+1
print(ret % mod)
| 0 | PYTHON3 |
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
int rect=0,dia=0;
int a[3]{};
while(scanf("%d,%d,%d",&a[0],&a[1],&a[2])>0){
if(a[0]==a[1]) dia++;
if(a[0]*a[0]+a[1]*a[1]==a[2]*a[2]) rect++;
}
printf("%d\n%d\n",rect,dia);
} | 0 | CPP |
#include<bits/stdc++.h>
using namespace std;
int main(){
int score[2];
int h[2],k[2],a,b,c,d;
cin >> h[0] >> h[1];
cin >> k[0] >> k[1];
cin >> a >> b >> c >>d;
score[0] = h[0]*a + h[1]*b + h[0] / 10 * c + h[1] / 20 * d;
score[1] = k[0]*a + k[1]*b + k[0] / 10 * c + k[1] / 20 * d;
if(score[0] > score[1]){
cout << "hiroshi" << endl;
}else if(score[0] < score[1]){
cout << "kenjiro" << endl;
}else{
cout << "even" << endl;
}
return 0;
}
| 0 | CPP |
from collections import Counter
import string
import math
import sys
from fractions import Fraction
def array_int():
return [int(i) for i in sys.stdin.readline().split()]
def vary(arrber_of_variables):
if arrber_of_variables==1:
return int(sys.stdin.readline())
if arrber_of_variables>=2:
return map(int,sys.stdin.readline().split())
def makedict(var):
return dict(Counter(var))
# i am noob wanted to be better and trying hard for that
def printDivisors(n):
divisors=[]
# Note that this loop runs till square root
i = 1
while i <= math.sqrt(n):
if (n % i == 0) :
# If divisors are equal, print only one
if (n//i == i) :
divisors.append(i)
else :
# Otherwise print both
divisors.extend((i,n//i))
i = i + 1
return divisors
def countTotalBits(num):
# convert number into it's binary and
# remove first two characters 0b.
binary = bin(num)[2:]
return(len(binary))
def isPrime(n) :
# Corner cases
if (n <= 1) :
return False
if (n <= 3) :
return True
# This is checked so that we can skip
# middle five numbers in below loop
if (n % 2 == 0 or n % 3 == 0) :
return False
i = 5
while(i * i <= n) :
if (n % i == 0 or n % (i + 2) == 0) :
return False
i = i + 6
return True
""" def dfs(node,val):
global tree,visited
visited[node]=1
ans[node]=val
val^=1
for i in tree[node]:
if visited[i]==-1:
dfs(i,val) """
for _ in range(vary(1)):
a,b=vary(2)
pt=abs(a-b)
ans=0
for i in range(10,0,-1):
ans+=pt//i
pt=pt%i
print(ans)
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
long long fac[300002], inv[300002];
int arr[300002], cnt[300002], f[12][300001];
long long qpow(long long base, long long k) {
long long tmp = 1;
for (; k; base = base * base % 998244353, k >>= 1)
tmp = tmp * base % 998244353;
return tmp;
}
long long C(int n, int m) {
if (n < m) return 0;
return fac[n] * inv[m] % 998244353 * inv[n - m] % 998244353;
}
int main() {
int i, j, n, M = 0;
scanf("%d", &n);
for (i = 1; i <= n; ++i) {
scanf("%d", &arr[i]), cnt[arr[i]]++, f[1][arr[i]]++;
M = max(M, arr[i]);
if (arr[i] == 1) {
printf("1\n");
return 0;
}
}
fac[0] = 1;
for (i = 1; i < 300002; ++i) fac[i] = 1ll * fac[i - 1] * i % 998244353;
inv[300002 - 1] = qpow(fac[300002 - 1], 998244353 - 2);
for (i = 300002 - 1; i >= 1; --i) inv[i - 1] = i * inv[i] % 998244353;
for (i = 1; i <= M; ++i)
for (j = i + i; j <= M; j += i) cnt[i] += cnt[j];
for (i = 2; i <= 11; ++i) {
for (j = M; j >= 1; --j) {
f[i][j] = C(cnt[j], i);
for (int k = j + j; k <= M; k += j)
f[i][j] = (f[i][j] - f[i][k] + 998244353) % 998244353;
}
if (f[i][1] > 0) {
printf("%d\n", i);
return 0;
}
}
printf("-1\n");
return 0;
}
| 12 | CPP |
import sys
from math import ceil,sqrt
read=sys.stdin.buffer.readline
mi=lambda:map(int,read().split())
li=lambda:list(mi())
cin=lambda:int(read())
def isp(n):
i=2
while i*i<=n:
if n%i==0:
return False
i+=1
return True
primes=[]
for _ in range(cin()):
n,k=mi()
a=li()
b=li()
a.sort()
b.sort()
for i in range(n):
if a[i]<b[n-i-1] and k>0:
a[i]=b[n-i-1]
k-=1
print(sum(a)) | 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
std::ios::sync_with_stdio(false);
long long n, d;
cin >> n >> d;
vector<long long> v;
long long x = 1;
for (long long i = 1; i <= n; i <<= 1) {
if (n & i) {
long long no = n & i;
int bits = log2(no);
for (int j = 0; j < bits; j++) v.push_back(x);
x += d;
v.push_back(x);
x += d;
}
}
cout << v.size() << endl;
for (int i = 0; i < v.size(); i++) cout << v[i] << " ";
}
| 9 | CPP |
#include<stdio.h>
int main(){
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
if(a-b==b-c) printf("YES\n");
else printf("NO\n");
return 0;
} | 0 | CPP |
n = int(input())
string = input().lower()
string = set(string)
if len(string) == 26:
print("YES")
else:
print("NO") | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
char p[80];
int D[80][80][80][3];
int A[80], CA, B[80], CB, C[80], CC;
int Calc(int a, int b, int c, int pv) {
int i, cc = 0;
for (i = 1; i <= a; i++)
if (pv < A[i]) cc++;
for (i = 1; i <= b; i++)
if (pv < B[i]) cc++;
for (i = 1; i <= c; i++)
if (pv < C[i]) cc++;
return cc;
}
int main() {
int i, j, k, l, n;
scanf("%d", &n);
scanf("%s", p);
for (i = 0; p[i]; i++) {
if (p[i] == 'V')
A[++CA] = i;
else if (p[i] == 'K')
B[++CB] = i;
else
C[++CC] = i;
}
for (i = 0; i <= CA; i++)
for (j = 0; j <= CB; j++)
for (k = 0; k <= CC; k++)
for (l = 0; l < 3; l++) D[i][j][k][l] = 1e9;
D[0][0][0][2] = 0;
for (i = 0; i <= CA; i++) {
for (j = 0; j <= CB; j++) {
for (k = 0; k <= CC; k++) {
for (l = 0; l < 3; l++) {
if (i != CA) {
D[i + 1][j][k][0] =
min(D[i + 1][j][k][0], D[i][j][k][l] + Calc(i, j, k, A[i + 1]));
}
if (j != CB && l) {
D[i][j + 1][k][1] =
min(D[i][j + 1][k][1], D[i][j][k][l] + Calc(i, j, k, B[j + 1]));
}
if (k != CC) {
D[i][j][k + 1][2] =
min(D[i][j][k + 1][2], D[i][j][k][l] + Calc(i, j, k, C[k + 1]));
}
}
}
}
}
int res = 1e9;
for (i = 0; i < 3; i++) res = min(res, D[CA][CB][CC][i]);
printf("%d\n", res);
}
| 11 | CPP |
def loc(x, y):
for k in range(len(y)):
if x == b[k]:
return k + 1
a = int(input())
b = input().split()
c = []
for i in range(1,a+1):
c += [str(loc(str(i),b))]
print(" ".join(c)) | 7 | PYTHON3 |
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define ll long long
using namespace std;
ll A,B,ans;
ll read()
{
ll x=0,f=1;char ch=getchar();
for (;ch<'0'||ch>'9';ch=getchar()) if (ch=='-') f=-1;
for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
return x*f;
}
int main()
{
A=read(),B=read();
if (A==B)
{
puts("1");
return 0;
}
int k=0,m=0;
while((A>>k)^(B>>k)) k++;
A=A&((1ll<<k)-1),B=B&((1ll<<k)-1);
ans=((1ll<<(k-1))-1)-A+1;
ans+=((1ll<<k)-1)-((1ll<<(k-1))+A)+1;
while((B&((1ll<<(k-1))-1))>>m) m++;
ans+=min((1ll<<(k-1))+A-1,(1ll<<(k-1))+(1ll<<m)-1)-(1ll<<(k-1))+1;
printf("%lld\n",ans);
return 0;
}
| 0 | CPP |
#include <bits/stdc++.h>
const int MAXN = 1e5 + 10;
const int MOD = 1e9 + 7;
int n, q;
struct Edge {
int v, w, next;
} edge[MAXN << 1];
int head[MAXN], tail;
void insert(int u, int v, int w) {
edge[++tail] = (Edge){v, w, head[u]};
head[u] = tail;
}
namespace {
inline int add(int x) { return x >= MOD ? x - MOD : x; }
inline int sub(int x) { return x < 0 ? x + MOD : x; }
inline int mul(int x, int y) { return (long long)x * y % MOD; }
} // namespace
namespace solver1 {
int son_w2[MAXN], son_w[MAXN], up_w2[MAXN], up_w[MAXN], sz[MAXN];
int anc[MAXN][21], len[MAXN], dep[MAXN];
void dfs(int u, int fa) {
dep[u] = dep[fa] + 1;
sz[u] = 1;
anc[u][0] = fa;
for (int i = 1; i <= 20; i++) anc[u][i] = anc[anc[u][i - 1]][i - 1];
for (int i = head[u]; i; i = edge[i].next) {
int v = edge[i].v;
if (v == fa) continue;
len[v] = add(len[u] + edge[i].w);
dfs(v, u);
sz[u] += sz[v];
son_w2[u] =
add(son_w2[u] +
add(son_w2[v] + add(mul(edge[i].w * 2, son_w[v]) +
mul(mul(edge[i].w, edge[i].w), sz[v]))));
son_w[u] = add(son_w[u] + add(son_w[v] + mul(edge[i].w, sz[v])));
}
}
void dfs2(int u, int fa, int w2, int w) {
up_w2[u] = w2;
up_w[u] = w;
for (int i = head[u]; i; i = edge[i].next) {
int v = edge[i].v;
if (v == fa) continue;
int ww2 = add(
w2 + sub(son_w2[u] -
add(son_w2[v] + add(mul(edge[i].w * 2, son_w[v]) +
mul(mul(edge[i].w, edge[i].w), sz[v])))));
int ww = add(w + sub(son_w[u] - add(son_w[v] + mul(edge[i].w, sz[v]))));
dfs2(v, u,
add(ww2 + add(mul(edge[i].w * 2, ww) +
mul(mul(edge[i].w, edge[i].w), n - sz[v]))),
add(ww + mul(edge[i].w, n - sz[v])));
}
}
int lca(int x, int y) {
if (dep[x] < dep[y]) std::swap(x, y);
int k = dep[x] - dep[y];
for (int i = 20; i >= 0; i--) {
if (k & (1 << i)) {
x = anc[x][i];
}
}
if (x == y) return x;
for (int i = 20; i >= 0; i--) {
if (anc[x][i] != anc[y][i]) {
x = anc[x][i];
y = anc[y][i];
}
}
return anc[x][0];
}
void main() {
dfs(1, 0);
dfs2(1, 0, 0, 0);
while (q--) {
int u, v;
scanf("%d%d", &u, &v);
int l = lca(u, v);
int w = sub(add(len[u] + len[v]) - add(len[l] + len[l]));
int part2 = add(son_w2[u] + up_w2[u]), part1;
if (l != v) {
part1 =
add(son_w2[v] + add(mul(w * 2, son_w[v]) + mul(mul(w, w), sz[v])));
} else {
part1 = sub(
add(son_w2[u] + up_w2[u]) -
add(add(mul(mul(w, w), n - sz[v]) + up_w2[v]) + mul(w * 2, up_w[v])));
}
printf("%d\n", sub(add(part1 * 2) - part2));
}
}
} // namespace solver1
int main() {
scanf("%d", &n);
for (int i = 1; i < n; i++) {
int u, v, w;
scanf("%d%d%d", &u, &v, &w);
insert(u, v, w);
insert(v, u, w);
}
scanf("%d", &q);
solver1::main();
}
| 10 | CPP |
tests = int(input())
mass = [0]*tests
for i in range(tests):
mass[i] = int(input())
for i in range(tests):
if mass[i] % 2 == 1:
mass[i] = mass[i] // 2
else:
mass[i] = mass[i] // 2 - 1
print(mass[i]) | 7 | PYTHON3 |
mex=0
def shit(a, n):
if(n==1):
global mex
mex=max(mex, 1)
return
if(a[:n//2]==sorted(a[:n//2]) or a[n//2:]==sorted(a[n//2:])):
mex
mex=max(mex, n//2)
shit(a[:n//2], n//2)
shit(a[n//2:], n//2)
n=int(input())
a=[int(x) for x in input().split()]
if(a==sorted(a)):
print(n)
exit()
shit(a, n)
print(mex)
| 7 | PYTHON3 |
a=input()
b=input()
ans=''
for i in range(len(a)):
if a[i]!=b[i]:
ans+='1'
else:
ans+='0'
print(ans) | 7 | PYTHON3 |
import math
def tr(s):
x = list(s.split('.'))
if len(x) > 1:
if len(x[-1]) == 2:
a = ''
for i in range(len(x) - 1):
a += x[i]
a = int(a) + int(x[-1]) * 0.01
else:
a = ''
for i in range(len(x)):
a += x[i]
a = int(a)
else:
a = int(s)
return a
def out(a):
a = str(a)
y = a.rfind('.')
z = a[y + 1:]
#print(z)
if int(z) == 0:
z = ''
else:
if len(str(z)) == 2:
z = '.' + str(z)
else:
z = '.' + str(z) + '0'
b = [str(z)]
i = y - 1
c = -1
while i > -1:
c += 1
if c == 3:
c = 0
b.append('.')
b.append(a[i])
i -= 1
b = reversed(b)
x = ''
for elem in b:
x += elem
return x
s = input()
num = ''
a = []
i = 0
while i < len(s):
if s[i].isdigit() or s[i] == '.':
num += s[i]
else:
if num != '':
a.append(num)
num = ''
i += 1
if num != '':
a.append(num)
num = ''
ans = 0
for elem in a:
ans += tr(elem)
#print(ans)
ans = round(ans * 100) / 100
#print(ans)
if ans < 1000:
ans = str(ans)
print(out(ans))
else:
print(out(ans)) | 8 | PYTHON3 |
n = int(input())
s = list(input())
print(min(s.count('8'), n // 11)) | 7 | PYTHON3 |
#include"bits/stdc++.h"
using namespace std;
int main(){
string s;
cin>>s;
int c=0;
for(auto i:s){
if(i=='o')
++c;
}
cout<<700+c*100;
} | 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 10;
const long long inf = 1e17;
const long long M = 998244353;
int n;
int a[N];
vector<int> B;
int cal(vector<int> &b, int bit) {
if (bit < 0) return 0;
int key = 1 << bit;
vector<int> v[2];
for (int i : b) {
v[(i & key) > 0].push_back(i);
}
if (v[0].size() == 0) return cal(v[1], bit - 1);
if (v[1].size() == 0) return cal(v[0], bit - 1);
return min(cal(v[1], bit - 1), cal(v[0], bit - 1)) + key;
}
int main() {
scanf("%d", &n);
B.resize(n);
for (auto &i : B) scanf("%d", &i);
int ans = cal(B, 30);
printf("%d", ans);
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
bool not_prime[100010];
int n;
inline void sieve() {
not_prime[1] = true;
for (int i = 2; i < 100001; ++i) {
if (not_prime[i]) continue;
int x = i + i;
while (x < 100001) {
not_prime[x] = true;
x += i;
}
}
}
bool is_prime(int x) {
if (x == 1) return false;
for (int i = 2; i * i <= x; ++i)
if (x % i == 0) return false;
return true;
}
int main(void) {
sieve();
scanf("%d", &n);
if (n <= 7) {
printf("1\n%d\n", n);
return 0;
}
n -= 3;
int a, b;
for (int i = 3; i < 100001; ++i) {
if (!not_prime[i] && is_prime(n - i)) {
a = i;
b = n - i;
break;
}
}
printf("3\n");
printf("3 %d %d\n", a, b);
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
int n;
int a[10000];
int b[10000];
long mpow(long b, long e) {
if (e == 0) return 1;
if (e % 2 == 1) return b * mpow(b, e - 1) % mod;
long t = mpow(b, e / 2);
return t * t % mod;
}
long inv(long n) {
return mpow(n, mod - 2);
}
int main() {
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> a[i];
b[i] = a[i];
}
long lcm = 1;
for (int d = 2; d < 1000; ++d) {
int mx = 0;
for (int i = 0; i < n; ++i) {
int cnt = 0;
while (b[i] % d == 0) {
b[i] /= d;
++cnt;
}
mx = max(mx, cnt);
}
for (int i = 0; i < mx; ++i) {
lcm = (lcm * d) % mod;
}
}
set<int> divs;
for (int i = 0; i < n; ++i) {
divs.insert(b[i]);
}
for (int div : divs) {
lcm = (lcm * div) % mod;
}
long ans = 0;
for (int i = 0; i < n; ++i) {
ans = (ans + lcm * inv(a[i])) % mod;
}
cout << ans << endl;
} | 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
cout << n << ' ';
for (int i = 1; i < n; i++) cout << i << ' ';
cout << endl;
cin >> n;
}
| 9 | CPP |
#include <bits/stdc++.h>
std::vector<std::vector<std::string>> n;
int maxd, l;
char s[1000001], *c;
std::string S() {
std::string ret("");
char c;
while ((c = getchar()) != ',') {
if (c == '\n' || c == EOF) break;
ret += c;
}
if (c == EOF || c == '\n') throw 1;
return ret;
}
int I() { return std::atoi(S().c_str()); }
int readnode(int dpt) {
if (dpt > maxd) maxd = dpt;
std::string ss;
try {
ss = S();
} catch (int) {
return 0;
}
if (n.size() < dpt) n.push_back(std::vector<std::string>(0));
n[dpt - 1].push_back(ss);
int cnt;
try {
cnt = I();
} catch (int) {
return 0;
}
for (int i = 0; i < cnt; ++i) readnode(dpt + 1);
return 1;
}
int main() {
while (readnode(1))
;
printf("%d\n", maxd);
for (int i = 0; i < n.size(); ++i) {
printf("%s", n[i][0].c_str());
for (int j = 1; j < n[i].size(); ++j) printf(" %s", n[i][j].c_str());
puts("");
}
return 0;
}
| 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 5;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int T;
cin >> T;
for (int t = 0; t < T; t++) {
string s;
cin >> s;
string ans;
ans += s[0];
for (int i = 1; i < (int)s.size(); i += 2) {
ans += s[i];
}
cout << ans << '\n';
}
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
int GCD(int a, int b) {
if (!a) return b;
return GCD(b % a, a);
}
void init() {}
struct ss {
int go;
int rest;
};
vector<ss> V;
int main() {
clock_t startTime = clock();
init();
int n;
cin >> n;
if (n == 0) {
cout << "O-|-OOOO";
return 0;
}
while (n > 0) {
int x = n % 10;
n /= 10;
ss tmp;
if (x >= 5) {
tmp.go = 1;
x -= 5;
} else
tmp.go = 0;
tmp.rest = x;
V.push_back(tmp);
}
for (int i = 0; i < V.size(); i++) {
if (V[i].go == 1) {
cout << "-O|";
} else
cout << "O-|";
for (int j = 0; j < V[i].rest; j++) {
cout << "O";
}
cout << "-";
for (int j = 0; j < 4 - V[i].rest; j++) {
cout << "O";
}
cout << "\n";
}
clock_t endTime = clock();
fprintf(stderr, "\nTime: %.5f seconds\n",
double(endTime - startTime) / CLOCKS_PER_SEC);
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
struct edges {
int to, next;
} edge[202020];
int first[101010], now;
void adde(int x, int y) {
now++;
edge[now].to = y;
edge[now].next = first[x];
first[x] = now;
}
double v[101010], sum[101010];
int fa[101010];
void work(int p) {
for (int e = first[p]; e; e = edge[e].next)
if (edge[e].to != fa[p]) {
fa[edge[e].to] = p;
work(edge[e].to);
}
}
int main() {
int n, x, y, q;
double nv, ans = 0.0;
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%lf", &v[i]);
memset(first, 0, sizeof(first));
now = 0;
for (int i = 1; i < n; i++) {
scanf("%d%d", &x, &y);
adde(x, y);
adde(y, x);
}
v[n] = 1.0;
fa[0] = n;
work(0);
for (int i = 0; i < n; i++) {
ans += (1.0 - v[i]) * v[fa[i]];
sum[fa[i]] += 1.0 - v[i];
}
scanf("%d", &q);
for (int i = 1; i <= q; i++) {
scanf("%d%lf", &x, &nv);
ans += sum[x] * (nv - v[x]);
ans -= (nv - v[x]) * v[fa[x]];
sum[fa[x]] -= nv - v[x];
v[x] = nv;
printf("%.5lf\n", ans);
}
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
struct node {
int x, y, next;
} road[100005 * 2];
struct nodd {
int max1, max2, num;
} msg[100005];
int m, n, d, start[100005], tot = 0, f[100005];
bool mark[100005];
void build(int x, int y) {
tot++, road[tot].x = x, road[tot].y = y, road[tot].next = start[x];
start[x] = tot;
}
void init() {
scanf("%d%d%d", &n, &m, &d);
for (int i = 1; i <= m; i++) {
int p;
scanf("%d", &p);
mark[p] = true;
}
for (int i = 1; i <= n - 1; i++) {
int p, q;
scanf("%d%d", &p, &q);
build(p, q), build(q, p);
}
}
void df_1(int x, int fa) {
if (mark[x] == true) msg[x].max1 = 0, f[x] = 0;
for (int i = start[x]; i; i = road[i].next)
if (road[i].y != fa) {
df_1(road[i].y, x);
int q = road[i].y;
f[x] = max(f[x], f[q] + 1);
if (msg[q].max1 >= 0 && msg[x].max1 <= msg[q].max1 + 1)
msg[x].max2 = msg[x].max1, msg[x].max1 = msg[q].max1 + 1,
msg[x].num = q;
else if (msg[q].max1 >= 0 && msg[x].max2 <= msg[q].max1 + 1)
msg[x].max2 = msg[q].max1 + 1;
}
}
void df_2(int x, int fa, int deep, int Max) {
for (int i = start[x]; i; i = road[i].next)
if (road[i].y != fa) {
int q = road[i].y;
if (msg[x].num == q) {
int t = max(Max, msg[x].max2 - deep);
f[q] = max(f[q], t + deep + 1);
df_2(q, x, deep + 1, t);
} else {
int t = max(Max, msg[x].max1 - deep);
f[q] = max(f[q], t + deep + 1);
df_2(q, x, deep + 1, t);
}
}
}
void work() {
for (int i = 1; i <= n; i++)
msg[i].max1 = msg[i].max2 = -0x3f3f3f3f, msg[i].num = 0;
for (int i = 1; i <= n; i++) f[i] = -0x3f3f3f3f;
df_1(1, 0);
df_2(1, 0, 0, -0x3f3f3f3f);
int ans = 0;
for (int i = 1; i <= n; i++)
if (f[i] <= d) ans++;
printf("%d\n", ans);
}
int main() {
init();
work();
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(0);
int n;
cin >> n;
vector<pair<int, int> > vec;
int fe = 0, fo = 0, se = 0, so = 0;
int s = 0;
for (int i = 0; i < n; i++) {
pair<int, int> temp;
cin >> temp.first >> temp.second;
if (((temp.first - temp.second) & 1)) {
s++;
}
if (temp.first & 1) {
fo++;
} else {
fe++;
}
if (temp.second & 1) {
so++;
} else {
se++;
}
}
if (fo & 1 && so & 1 && s) {
cout << 1 << '\n';
} else if (!(fo & 1) && !(so & 1)) {
cout << 0 << '\n';
} else {
cout << -1 << '\n';
}
}
| 7 | CPP |
#include <iostream>
#include <cstring>
#include <limits.h>
#include <algorithm>
#include <math.h>
#include <vector>
using namespace std;
typedef long long ll;
int main(void){
int l, b = 1, cnt = 0;
vector<int> u, v, w;
cin >> l;
while (b <= l) {
b *= 2; cnt++;
}
for (int i = 1; i <= cnt - 1; i++) {
u.push_back(i); v.push_back(i + 1); w.push_back(pow(2, i - 1));
u.push_back(i); v.push_back(i + 1); w.push_back(0);
}
l -= b / 2;
int n = cnt, k = b / 2;
while (l != 0) {
cnt = 0;
b = 1;
while (b <= l) {
b *= 2; cnt++;
}
u.push_back(cnt); v.push_back(n); w.push_back(k);
k += b / 2;
l -= b / 2;
}
cout << n << " " << u.size() << endl;
for (int i = 0; i < u.size(); i++) cout << u[i] << " " << v[i] << " " << w[i] << endl;
}
| 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
int a, n;
char str[100100], co[20];
pair<int, bool> C[1010];
int main() {
scanf("%d\n%s", &a, str + 1);
str[0] = '+';
int len = strlen(str), p, cur = 0;
if (str[1] == '-') cur++;
for (; cur < len;) {
char *p1 = strstr(str + cur, "a++"), *p2 = strstr(str + cur, "++a");
if (p1 == NULL && p2 == NULL) break;
if ((p1 < p2 && p1 != NULL) || p2 == NULL)
p = p1 - str, C[n].second = false;
else
p = p2 - str, C[n].second = true;
if (p - 1 == cur) {
if (str[cur] == '+')
C[n++].first = 1;
else
C[n++].first = -1;
cur += 4;
} else {
int pc = strstr(str + cur, "*") - str;
str[pc] = '\0';
C[n++].first = atoi(str + cur);
cur = pc + 4;
}
}
sort(C, C + n);
long long ans = 0;
for (int i = 0; i < n; i++) {
ans += C[i].first * a;
if (C[i].second) ans += C[i].first;
a++;
}
printf("%I64d\n", ans);
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
int a, b;
int main() {
cin >> a >> b;
for (int i = 0; i <= b; ++i) {
if (a % b == 0) {
cout << "Yes";
return 0;
}
a += (a % b);
a %= b;
}
cout << "No";
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long int n, m;
vector<long long int> a[105];
long long int dist[105][105];
long long int vis[105];
void bfs(long long int src) {
memset(vis, 0, sizeof(vis));
for (long long int i = 1; i <= n; i++) dist[src][i] = 1000000007;
dist[src][src] = 0;
vis[src] = 1;
queue<long long int> q;
q.push(src);
while (!q.empty()) {
long long int node = q.front();
q.pop();
for (auto it : a[node]) {
if (!vis[it]) {
vis[it] = 1;
dist[src][it] = 1 + dist[src][node];
q.push(it);
}
}
}
}
struct Hopcroft_Karp {
static const int inf = 1e9;
int n;
vector<int> matchL, matchR, dist;
vector<vector<int> > g;
Hopcroft_Karp(int n)
: n(n), matchL(n + 1), matchR(n + 1), dist(n + 1), g(n + 1) {}
void addEdge(int u, int v) { g[u].push_back(v); }
bool bfs() {
queue<int> q;
for (int u = 1; u <= n; u++) {
if (!matchL[u]) {
dist[u] = 0;
q.push(u);
} else
dist[u] = inf;
}
dist[0] = inf;
while (!q.empty()) {
int u = q.front();
q.pop();
for (auto v : g[u]) {
if (dist[matchR[v]] == inf) {
dist[matchR[v]] = dist[u] + 1;
q.push(matchR[v]);
}
}
}
return (dist[0] != inf);
}
bool dfs(int u) {
if (!u) return true;
for (auto v : g[u]) {
if (dist[matchR[v]] == dist[u] + 1 && dfs(matchR[v])) {
matchL[u] = v;
matchR[v] = u;
return true;
}
}
dist[u] = inf;
return false;
}
int max_matching() {
int matching = 0;
while (bfs()) {
for (int u = 1; u <= n; u++) {
if (!matchL[u])
if (dfs(u)) matching++;
}
}
return matching;
}
};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int TESTS = 1;
while (TESTS--) {
cin >> n >> m;
while (m--) {
long long int u, v;
cin >> u >> v;
a[u].push_back(v);
a[v].push_back(u);
}
for (long long int i = 1; i <= n; i++) bfs(i);
long long int s, b, k, h;
cin >> s >> b >> k >> h;
long long int xs[s + 1], as[s + 1], f[s + 1];
for (long long int i = 1; i <= s; i++) cin >> xs[i] >> as[i] >> f[i];
long long int xb[b + 1], ab[b + 1];
for (long long int i = 1; i <= b; i++) cin >> xb[i] >> ab[i];
Hopcroft_Karp graf(s + b);
for (long long int i = 1; i <= s; i++) {
for (long long int j = 1; j <= b; j++) {
if (dist[xs[i]][xb[j]] <= f[i] && as[i] >= ab[j]) {
graf.addEdge(i, s + j);
}
}
}
cout << min(k * graf.max_matching(), s * h) << '\n';
}
return 0;
}
| 8 | CPP |
a = int(input())
s = [[] for k in range(a)]
for k in range(a):
s[k] = str(input())
fil = 'po'
jap = 'desu'
jap2 = 'masu'
kor = 'mnida'
def suffchang(x):
x = list(x)
x.reverse()
return x
fil = suffchang(fil)
jap = suffchang(jap)
jap2 = suffchang(jap2)
kor = suffchang(kor)
for k in range (0,len(s)):
b = suffchang(s[k])
if b[0] == fil[0] and b[1] == fil[1]:
print('FILIPINO')
elif b[0] == jap[0] and b[1] == jap[1] and b[2] == jap[2] and b[3] == jap[3]:
print('JAPANESE')
elif b[0] == jap2[0] and b[1] == jap2[1] and b[2] == jap2[2] and b[3] == jap2[3]:
print('JAPANESE')
elif b[0] == kor[0] and b[1] == kor[1] and b[2] == kor[2] and b[3] == kor[3] and b[4] == kor[4]:
print('KOREAN')
| 7 | PYTHON3 |
import sys
# input = sys.stdin.readline
ll = lambda: list(map(int, input().split()))
lls = lambda: list(map(str, input().split()))
fin = lambda: list(map(float, input().split()))
st = lambda: input()
v = lambda: map(int, input().split())
ii = lambda: int(input())
mod = (10 ** 9) + 7
from math import *
# from fractions import *
from datetime import datetime
from collections import *
import math
# print(log(8,3))
x=ii()
l=ll()
if(x<3):
if(x==1):
print(1,1)
l[0]+=1
print(1)
print(1,1)
l[0]+=1
print(1)
print(1,1)
print(-l[0])
else:
print(1, 1)
print(-l[0])
if(l[1]%2):
print(2,2)
print(1)
l[1]+=1
print(2,2)
print(-l[1])
else:
print(2,2)
print(0)
print(2,2)
print(-l[1])
elif(x==3):
print(1,1)
print(-l[0])
print(2,2)
print(-l[1])
print(3,3)
print(-l[2])
else:
#print(l)
print(x,x)
print(-l[-1])
l[-1]=0
print(1,x-1)
sol=[]
for i in range(x-1):
sol.append((x-1)*(((l[i]%x)+x)%x))
l[i]+=sol[i]
print(*sol)
print(1,x)
ans=[]
#print(l)
for i in range(x):
ans.append(-l[i])
print(*ans)
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main(void) {
int vp, vd, t, f, c;
scanf("%d%d%d%d%d", &vp, &vd, &t, &f, &c);
if (vd <= vp) {
puts("0");
return 0;
}
double p = 0;
int k = 0;
p += t * vp;
while (p < c - 1e-9) {
p = (vd / (double)(vd - vp)) * p;
if (p < c - 1e-9) {
++k;
p += (p / vd + f) * vp;
}
}
printf("%d\n", k);
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
const int MAX = 1e3 + 7;
const int MOD = 998244353;
using namespace std;
int n, m;
int c[MAX], a[MAX];
int main() {
ios::sync_with_stdio(false), cout.tie(NULL);
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> c[i];
for (int i = 1; i <= m; i++) cin >> a[i];
int lt = 1, pos = 1;
while (pos <= n && lt <= m) {
if (c[pos] <= a[lt])
lt++, pos++;
else
pos++;
}
cout << lt - 1 << '\n';
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
long long ans = 0;
long long qpow(long long a, long long p) {
long long ans = 1;
while (p) {
if (p & 1) ans = ans * a % mod;
a = a * a % mod;
p >>= 1;
}
return ans;
}
int main() {
long long x, k;
cin >> x >> k;
long long ans1 = qpow(2, k + 1);
long long ans2 = qpow(2, k);
x ? cout << (x % mod * ans1 % mod - ans2 + 1 + mod) % mod << endl
: cout << 0 << endl;
return 0;
}
| 9 | CPP |
n,m,s=map(int,input().split())
s = s - (abs(n)+abs(m))
if s<0:
s=1
if s%2==0:
print('Yes')
else:
print('No')
| 7 | PYTHON3 |
import itertools
def calc(s1, s2):
val = 0
for z in range(len(s1)):
if s1[z] != s2[z]:
diff = ord(s1[z])-ord(s2[z])
if (diff < 0): diff = -diff
if (diff > 13): diff = 26-diff
val += diff
return val
n = int(input())
s = input()
ans = 300
for i in range(0, len(s)-3):
ans = min(ans, calc(s, s[:i] + "ACTG" + s[i+4:]))
print(ans) | 7 | PYTHON3 |
class BinaryIndexedTree:
def __init__(self, n):
self.bit = [0] * n
def add(self, i, x):
i += 1
while i <= len(self.bit):
self.bit[i-1] += x
i += i & -i
def sum_sub(self, i):
a = 0
i += 1
while i:
a += self.bit[i-1]
i -= i & -i
return a
def sum(self, i, j):
a = 0
if j != 0:
a += self.sum_sub(j-1)
if i != 0:
a -= self.sum_sub(i-1)
return a
def f(m):
ans=0
bit=BinaryIndexedTree(2*n+7)
f=0
for i in range(n):
bit.add(n+f,1)
if a[i]>m:f-=1
else:f+=1
ans+=bit.sum_sub(n+f)
return ans
n,m=map(int,input().split())
a=list(map(int,input().split()))
print(f(m)-f(m-1)) | 11 | PYTHON3 |
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
#include <ctime>
using namespace std;
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define mp make_pair
#define all(r) r.begin(),r.end()
#define fi first
#define se second
#define println(X) cout<<X<<endl;
#define DBG(X) cout<<#X<<" : "<<X<<endl;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-3;
const double PI = acos(-1);
int dx[]={-1,0,1,0};
int dy[]={0,-1,0,1};
int ans[110], d[18];
int calc(int t, int m){
vi v(18, 0);
for(int i = 16; i >= 0; i--){
if(d[i] <= t) v[i] = v[i+1]+1;
}
for(int i = 0; i < 17; i++){
if(v[i] >= m) return i;
}
return -1;
}
int main(){
int n, t=0, idx;
for(int i = 0; i < 100; i++){
n = i%5==1?5:2;
t = max(t,i*5);
while(1){
idx = calc(t, n);
if(idx < 0) {
t++;
continue;
}
ans[i] = t - i*5;
for(int j = 0; j < n; j++) d[idx+j] = t + 17*(i%2)+3*(i%3)+19;
break;
}
}
while(cin>>n){
printf("%d\n", ans[n]);
}
} | 0 | CPP |
def put(): return map(int, input().split())
t = int(input())
for _ in range(t):
n,k = put()
l = list(put())
m = min(l)
ind = l.index(m)
l.pop(ind)
ans = 0
for i in l:
if k-i>0:
ans+= (k-i)//m
print(ans)
| 7 | PYTHON3 |
for _ in range(int(input())):
n=int(input())
a=list(map(int,input().split()))
s=max(a)
f=0
for i in range(n):
if(a[i]==s):
if(i==0):
if(a[i]>a[i+1]):
print(i+1)
f=1
break
elif(i>0 and i<(n-1)):
if((a[i]>a[i+1])or (a[i]>a[i-1])):
print(i+1)
f=1
break
else:
if((a[i]>a[i-1])):
print(i+1)
f=1
break
if(f==0):
print(-1)
| 9 | PYTHON3 |
def solve(l1,l2):
for j in range(m):
if(l1[j] in l2):
return 1,l1[j]
break
return 0,0
t=int(input())
for i in range(t):
m,n=map(int,input().split())
l1=list(map(int,input().split()))
l2=list(map(int,input().split()))
res,val=solve(l1,l2)
if(res==1):
print("YES")
print(res,val)
else:
print("NO")
| 7 | PYTHON3 |
n= int(input())
a=[]
for i in range(n):
a.append([int(x) for x in input().split()])
an=0
for i in range(n):
an+=a[n//2][i]
an+=a[i][n//2]
an+=a[i][i]
an+=a[n-1-i][i]
print(an-3*(a[n//2][n//2])) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int power(int a) {
int k = 1;
for (int i = 0; i < a; i++) k *= 10;
return k;
}
int main() {
long long int n;
cin >> n;
long long int temp = n, sum = n, m = n, cnt = 0;
while (temp > 0) cnt++, temp /= 10;
temp = power(cnt - 1);
cout << temp - (n % temp) << endl;
return 0;
}
| 7 | CPP |
#include<bits/stdc++.h>
using namespace std;
int main(){
int N,A[105],B[105],max=0,sum=0;
cin>>N;
for(int i = 0;i < N;i++){
cin>>A[i];
sum += A[i];
}
for(int i = 0;i < N;i++)
cin>>B[i];
sum += B[N-1];
max = sum;
for(int i = N-2;i>=0;i--){
sum += B[i];
sum -= A[i+1];
if(sum>max) max = sum;
}
cout<<max<<endl;
return 0;
} | 0 | CPP |
#include <iostream>
using namespace std;
int main(){
string s;
int i,j;
cin >> s;
i = 0;
j = s.size()-1;
while(s[i]!='A') i++;
while(s[j]!='Z') j--;
cout << j - i + 1;
} | 0 | CPP |
# Bismillah
# In the name of GOD
n = int(input())
a = [0] * n
p = [0] * n
for i in range(n):
a[i], p[i] = map(int, input().split())
price = 0
for i in range(n):
j = i + 1
price += a[i] * p[i]
while j < n:
if p[i] < p[j]:
price += a[j] * p[i]
a[j] = 0
j += 1
else:
break
print(price)
| 7 | PYTHON3 |
t=int(input())
for k in range(t):
a,b,n=list(map(int,input().split(" ")))
c=0
while a<=n and b<=n:
c+=1
if a>b:
b+=a
else:
a+=b
print(c)
| 7 | PYTHON3 |
# python3
#===============================================================================
from collections import defaultdict, Counter
from functools import lru_cache
from heapq import heappush, heappop
from math import gcd, floor, ceil
from sys import stdin, stdout
def ilist():
return [int(x) for x in stdin.readline().strip().split(" ")]
def iint():
return int(stdin.readline().strip())
def istr():
return stdin.readline().strip()
#===============================================================================
def solve(n):
return (1 << (n//2 + 1)) - 2
if __name__ == '__main__':
t = iint()
for _ in range(t):
n = iint()
print(solve(n))
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int test,n,a[55];
int main() {
cin>>test;
while(test--){
cin>>n;
n*=2;
for(int i=1;i<=n;i++){
cin>>a[i];
}
sort(a+1,a+n+1);
for(int i=2;i<=n/2;i+=2){
swap(a[i],a[n+1-i]);
}
for(int i=1;i<=n;i++){
cout<<a[i]<<" ";
}
cout<<endl;
}
}
//return 0;
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
void no() {
cout << "-1" << endl;
}
void solve() {
int n;
cin >> n;
vector<int> b(n + 2);
for (int &x : b) {
cin >> x;
}
multiset<int> have(b.begin(), b.end());
long long sum = accumulate(b.begin(), b.end(), 0LL);
for (int x : b) {
have.erase(have.find(x));
sum -= x;
if (sum % 2 == 0 && sum <= 2000000000 && have.find(sum / 2) != have.end()) {
have.erase(have.find(sum / 2));
for (int y : have) {
cout << y << " ";
}
cout << endl;
return;
}
sum += x;
have.insert(x);
}
no();
}
int main() {
int tests;
cin >> tests;
while (tests-- > 0) {
solve();
}
return 0;
} | 10 | CPP |
for _ in range(int(input())):
n,m=map(int,input().split())
t='NO'
for __ in range(n):
a,b=map(int,input().split())
c,d=map(int,input().split())
if b==c and m%2==0:
t='YES'
print(t)
| 8 | PYTHON3 |