solution
stringlengths 10
983k
| difficulty
int64 0
25
| language
stringclasses 2
values |
---|---|---|
#include <bits/stdc++.h>
using namespace std;
long long a[1000005], s, n, sum;
int main() {
cin >> n >> s;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
sort(a + 1, a + 1 + n);
int mid = (n + 1) / 2;
if (a[mid] > s) {
for (int i = mid; i > 0 && a[i] > s; i--) {
sum += a[i] - s;
}
cout << sum << endl;
} else if (a[mid] < s) {
for (int i = mid; i <= n && a[i] < s; i++) {
sum += s - a[i];
}
cout << sum << endl;
} else {
cout << 0 << endl;
return 0;
}
return 0;
}
| 8 | CPP |
n = input()
for i in range (len(n)):
if n[i] in ('H','Q','9'):
print("YES")
break
elif i == len(n)-1:
print("NO")
| 7 | PYTHON3 |
#include<bits/stdc++.h>
using namespace std;
int main(){
long int n,a,b;cin>>n>>a>>b;
if(n==1&&a==b)cout<<1<<endl;
else if(n==1||b<a)cout<<0<<endl;
else cout<<b*(n-2)-a*(n-2)+1<<endl;
}
| 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7, maxn = 7000000, p = 993217;
int tree[7777777], ls[7777777], rs[7777777], sz[7777777], val[7777777], all, q,
tp, x, y, mx;
bool used[7777777];
struct treenode {
int rt1, rt2;
bool bad;
treenode() { rt1 = rt2 = bad = 0; }
} t[444444];
int pw[111111], n, k, a[111111];
int Get(int x) { return ((rand() << 13) + rand()) % x + 1; }
int getnext() {
while (used[all]) all++;
used[all] = 1;
return all;
}
void pushup(int node) {
sz[node] = sz[ls[node]] + sz[rs[node]] + 1;
tree[node] = (1ll * tree[ls[node]] * pw[sz[rs[node]] + 1] +
1ll * val[node] * pw[sz[rs[node]]] + tree[rs[node]]) %
mod;
}
int merge(int x, int y) {
if (!x || !y) return x ^ y;
int pos = getnext();
if (1ll * Get(1000000) * (sz[x] + sz[y]) < 1000000ll * sz[x]) {
ls[pos] = ls[x];
val[pos] = val[x];
rs[pos] = merge(rs[x], y);
} else {
rs[pos] = rs[y];
val[pos] = val[y];
ls[pos] = merge(x, ls[y]);
}
pushup(pos);
return pos;
}
void split(int x, int &rt1, int &rt2, int y) {
if (!x) {
rt1 = rt2 = 0;
return;
}
if (y <= sz[ls[x]]) {
rt2 = getnext();
rs[rt2] = rs[x];
val[rt2] = val[x];
split(ls[x], rt1, ls[rt2], y);
pushup(rt2);
} else {
rt1 = getnext();
ls[rt1] = ls[x];
val[rt1] = val[x];
split(rs[x], rs[rt1], rt2, y - sz[ls[x]] - 1);
pushup(rt1);
}
}
void pup(treenode &a, treenode b, treenode c) {
if (b.bad || c.bad) {
a.bad = 1;
return;
}
a.rt1 = a.rt2 = a.bad = 0;
int rt, rtt;
if (sz[b.rt2] > sz[c.rt1]) {
rt = rtt = 0;
split(b.rt2, rt, rtt, sz[c.rt1]);
if (tree[rt] != tree[c.rt1]) {
a.bad = 1;
return;
}
a.rt2 = merge(c.rt2, rtt);
a.rt1 = b.rt1;
} else {
rt = rtt = 0;
split(c.rt1, rt, rtt, sz[b.rt2]);
if (tree[rt] != tree[b.rt2]) {
a.bad = 1;
return;
}
a.rt1 = merge(b.rt1, rtt);
a.rt2 = c.rt2;
}
}
void build(int l, int r, int node) {
mx = max(mx, node);
if (l == r) {
if (a[l] < 0) {
t[node].rt1 = getnext();
val[t[node].rt1] = tree[t[node].rt1] = -a[l];
sz[t[node].rt1] = 1;
} else {
t[node].rt2 = getnext();
val[t[node].rt2] = tree[t[node].rt2] = a[l];
sz[t[node].rt2] = 1;
}
return;
}
int mid = (l + r) >> 1;
build(l, mid, node << 1);
build(mid + 1, r, (node << 1) | 1);
pup(t[node], t[node << 1], t[(node << 1) | 1]);
}
void upd(int x, int l, int r, int node, int y) {
if (l == r) {
sz[t[node].rt1] = sz[t[node].rt2] = val[t[node].rt1] = val[t[node].rt2] =
tree[t[node].rt1] = tree[t[node].rt2] = 0;
ls[t[node].rt1] = rs[t[node].rt1] = ls[t[node].rt2] = rs[t[node].rt2] = 0;
t[node].rt1 = t[node].rt2 = t[node].bad = 0;
if (y < 0) {
t[node].rt1 = getnext();
val[t[node].rt1] = tree[t[node].rt1] = -y;
sz[t[node].rt1] = 1;
} else {
t[node].rt2 = getnext();
val[t[node].rt2] = tree[t[node].rt2] = y;
sz[t[node].rt2] = 1;
}
return;
}
int mid = (l + r) >> 1;
if (x > mid)
upd(x, mid + 1, r, (node << 1) | 1, y);
else
upd(x, l, mid, node << 1, y);
pup(t[node], t[node << 1], t[(node << 1) | 1]);
}
treenode query(int beg, int en, int l, int r, int node) {
if (l > en || r < beg) return treenode();
if (l >= beg && r <= en) return t[node];
int mid = (l + r) >> 1;
treenode res;
pup(res, query(beg, en, l, mid, node << 1),
query(beg, en, mid + 1, r, (node << 1) | 1));
return res;
}
void dfs(int x) {
if (!x || used[x]) return;
used[x] = 1;
dfs(ls[x]);
dfs(rs[x]);
}
void refresh() {
memset(used, 0, sizeof(used));
for (int i = 1; i <= mx; i++) {
dfs(t[i].rt1);
dfs(t[i].rt2);
}
for (int i = 1; i <= all; i++) {
if (!used[i]) {
tree[i] = val[i] = ls[i] = rs[i] = sz[i] = 0;
}
}
all = 1;
}
int main() {
scanf("%d%d", &n, &k);
pw[0] = 1;
for (int i = 1; i <= n; i++) pw[i] = 1ll * pw[i - 1] * p % mod;
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
all = 1;
build(1, n, 1);
scanf("%d", &q);
while (q--) {
scanf("%d%d%d", &tp, &x, &y);
if (tp == 1) {
upd(x, 1, n, 1, y);
} else {
treenode nw = query(x, y, 1, n, 1);
if (nw.bad || nw.rt1 || nw.rt2)
printf("No\n");
else
printf("Yes\n");
}
if (all > maxn) {
refresh();
}
}
return 0;
}
| 12 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long dif[1024], cou[1024], test[1024];
void f(int n, int k, int x, int a[]) {
if (k == 0) {
sort(a, a + n);
cout << a[n - 1] << ' ' << a[0];
} else {
for (int i = 0; i < n; i++) {
cou[a[i]]++;
}
dif[0] = 0;
for (int i = 1; i <= 1023; i++) {
dif[i] = dif[i - 1] + cou[i - 1];
}
long long int minim = 0, maxim = 0;
for (int j = 0; j < k; j++) {
for (int i = 0; i <= 1023; i++) {
long long int c = 0;
if (dif[i] % 2 == 0 and cou[i] > 0) {
c = cou[i] - cou[i] / 2;
test[i ^ x] += c;
test[i] -= c;
} else if (dif[i] % 2 == 1 and cou[i] > 0) {
c = cou[i] / 2;
test[i ^ x] += c;
test[i] -= c;
}
}
for (int i = 0; i <= 1023; i++) {
cou[i] = cou[i] + test[i];
test[i] = 0;
}
for (int i = 1; i <= 1023; i++) {
dif[i] = dif[i - 1] + cou[i - 1];
}
for (int i = 0; i <= 1023; i++) {
if (cou[i] > 0) {
minim = i;
break;
}
}
for (int i = 1023; i >= 0; i--) {
if (cou[i] > 0) {
maxim = i;
break;
}
}
}
cout << maxim << ' ' << minim;
}
}
int main() {
int n, k, x;
cin >> n >> k >> x;
int a[n];
for (int i = 0; i < n; i++) cin >> a[i];
f(n, k, x, a);
}
| 9 | CPP |
#include<bits/stdc++.h>
using namespace std;
using i64 = int64_t;
int main(){
int n, h, w;
cin >> n >> h >> w;
vector<int> v;
for(int i=0;i<n;++i){
int x;
cin >> x;
v.push_back(x);
}
int ans = 0;
for(int i=0;i<n;i+=2){
int overlapped = 0;
if(v[i]+v[i+1] <= w)overlapped = v[i] + v[i+1];
else overlapped = 2*w - (v[i] + v[i+1]);
ans += overlapped;
}
ans *= h;
cout << ans << endl;
return 0;
}
| 0 | CPP |
import sys
def equal(a):
uni = sorted(set(a))
if len(uni) == 1:
print("0")
elif len(uni) == 2:
if (uni[1]+uni[0])%2==0:
print((uni[1]+uni[0])//2 - uni[0])
else:
print(uni[1]-uni[0])
elif len(uni) == 3:
if uni[2] - uni[1] == uni[1] - uni[0]:
X = uni[2] - uni[1]
print(str(X))
else:
print(-1)
else:
print(-1)
n= int(input())
a = list(map(int,input().split()))
equal(a) | 8 | PYTHON3 |
k,r=input().split()
k=int(k)
r=int(r)
c=1
while 0!=(k*c)%10!=r:
c+=1
print(c) | 7 | PYTHON3 |
n, m = map(int, input().split())
acs = [0]*n
was = [0]*n
ac = 0
wa = 0
for i in range(m):
p, s = input().split()
p = int(p) - 1
if s == "AC" and acs[p]==0:
acs[p] += 1
ac += 1
wa += was[p]
elif s == "WA":
was[p] += 1
print(ac, wa) | 0 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
const double pi = acos(-1.0);
const int K = 1e5 + 7;
const int mod = 1e9 + 7;
int sgn(double ta, double tb);
struct Point {
double x, y, a, b;
Point(double a = 0, double b = 0) { x = a, y = b; }
bool operator<(const Point &ta) const {
return sgn(a, ta.a) < 0 || (sgn(a, ta.a) == 0 && sgn(b, ta.b) < 0);
}
};
double cross(Point ta, Point tb, Point tc);
double getdis2(const Point &ta, const Point &tb);
set<Point>::iterator L(set<Point>::iterator it);
set<Point>::iterator R(set<Point>::iterator it);
int q, n, ch;
Point o, tmp, pt[5];
set<Point> st;
int main(void) {
cin >> q;
o.x = o.y = 0;
for (int i = 1; i <= 3; i++)
scanf("%d%lf%lf", &ch, &pt[i].x, &pt[i].y), o.x += pt[i].x, o.y += pt[i].y;
o.x /= 3.0, o.y /= 3.0;
for (int i = 1; i <= 3; i++) {
pt[i].a = atan2(pt[i].y - o.y, pt[i].x - o.x);
pt[i].b = getdis2(o, pt[i]);
st.insert(pt[i]);
}
set<Point>::iterator ia, ib, ic;
for (int i = 4; i <= q; i++) {
scanf("%d%lf%lf", &ch, &tmp.x, &tmp.y);
tmp.a = atan2(tmp.y - o.y, tmp.x - o.x);
tmp.b = getdis2(tmp, o);
ia = st.lower_bound(tmp);
if (ia == st.end()) ia = st.begin();
ib = L(ia);
if (ch == 1) {
if (sgn(cross(*ib, tmp, *ia), 0) <= 0) continue;
st.insert(tmp);
ic = st.find(tmp);
ia = L(ic), ib = L(ia);
while (sgn(cross(*ib, *ia, *ic), 0) <= 0) {
st.erase(ia);
ia = ib, ib = L(ia);
}
ia = R(ic), ib = R(ia);
while (sgn(cross(*ib, *ia, *ic), 0) >= 0) {
st.erase(ia);
ia = ib, ib = R(ia);
}
} else {
if (sgn(cross(*ib, tmp, *ia), 0) <= 0)
printf("YES\n");
else
printf("NO\n");
}
}
return 0;
}
int sgn(double ta, double tb) {
if (fabs(ta - tb) < eps) return 0;
if (ta < tb) return -1;
return 1;
}
double cross(Point ta, Point tb, Point tc) {
return (tb.x - ta.x) * (tc.y - ta.y) - (tb.y - ta.y) * (tc.x - ta.x);
}
double getdis2(const Point &ta, const Point &tb) {
return (ta.x - tb.x) * (ta.x - tb.x) + (ta.y - tb.y) * (ta.y - tb.y);
}
set<Point>::iterator L(set<Point>::iterator it) {
if (it == st.begin()) it = st.end();
return --it;
}
set<Point>::iterator R(set<Point>::iterator it) {
if (++it == st.end()) it = st.begin();
return it;
}
| 10 | CPP |
import sys
t=int(input())
for _ in range(t):
N=int(input())
S=sys.stdin.readline().strip()
arr=[]
l_sum=r_sum=0
l_count=r_count=0
for i in range(N):
if S[i]=='*':
arr.append(i+1)
r_sum+=(i+1)
r_count+=1
if r_count>0:r_count-=1
if r_sum>0:r_sum-=arr[0]
cost_arr=[]
for i in range(len(arr)):
# print(r_sum,r_count)
# print(l_sum,l_count)
cost=r_sum-(r_count*arr[i])-(r_count*(r_count+1))//2
cost+=(l_count*arr[i])-l_sum-(l_count*(l_count+1))//2
cost_arr.append(cost)
l_count+=1;r_count-=1
if r_sum>0:r_sum-=arr[i+1]
l_sum+=arr[i]
print(min(cost_arr) if len(cost_arr)>0 else 0)
sys.stdout.flush() | 11 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int n, s, t;
int d[105];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> d[i];
}
cin >> s >> t;
if (s > t) {
swap(s, t);
}
int s1 = s, t1 = t;
int Ans1 = 0, Ans2 = 0;
while (s != t) {
Ans1 += d[s];
s++;
}
while (s1 != t1) {
Ans2 += d[t1];
t1++;
if (t1 == n + 1) {
t1 = 1;
}
}
cout << min(Ans1, Ans2);
return 0;
}
| 7 | CPP |
n, m = map(int, input().split())
c = list(map(int, input().split()))
s = [0] * n
p = 0
for i in c:
s[i - 1] += 1
if 0 not in s:
p += 1
for q in range(len(s)):
if s[q] > 0: s[q] -= 1
print(p)
| 7 | PYTHON3 |
from collections import Counter
if __name__ == "__main__":
n, m = map(int, input().split())
f = list(map(int, input().split()))
b = list(map(int, input().split()))
fs = set(f)
bs = set(b)
if (fs & bs) != bs:
print("Impossible")
exit(0)
ct = set(k for k, v in filter(lambda k: k[1] > 1, Counter(f).items()))
if len(bs.intersection(ct)) > 0:
print("Ambiguity")
exit(0)
h = {}
for i, x in enumerate(f):
h[x] = str(i + 1)
print("Possible")
print(" ".join(list(map(lambda xx: h[xx], b))))
| 8 | PYTHON3 |
n, m = list(map(int,input().split()))
matrix = [list(map(int,input().split())) for _ in range(n)]
ans = 0
for i in range(n):
ones = zeros = 0
for j in range(m):
if matrix[i][j] == 1:
ones += 1
else:
zeros += 1
ans += pow(2, ones) - 1
ans += pow(2, zeros) - 1
for i in range(m):
ones = zeros = 0
for j in range(n):
if matrix[j][i] == 1:
ones += 1
else:
zeros += 1
ans += pow(2, ones) - 1
ans += pow(2, zeros) - 1
print(ans - m*n)
| 8 | PYTHON3 |
from collections import defaultdict
import sys
N=int(input())
A=[int(i) for i in input().split()]
dd=defaultdict(int)
K=[0]*N
for a in A:
dd[a]+=1
K[a]+=1
L=list(dd.items())
L.sort()
if L[-1][1]<=1:
print('Impossible')
sys.exit()
m=L[-1][0]
if m%2==1:
if L[0][0]!=m//2+1 or L[0][1]!=2:
print('Impossible')
sys.exit()
if m%2==0:
if L[0][0]!=m//2 or L[0][1]!=1:
print('Impossible')
sys.exit()
s=L[0][0]
for i in range(s+1,m+1):
if K[i]<=1:
print('Impossible')
sys.exit()
print('Possible') | 0 | PYTHON3 |
n = int(input())
mat = []
mat.append(list(map(int, input().split())))
mat.append(list(map(int, input().split())))
dp = [[0 for j in range(n)] for i in range(3)]
# [skip the current element, 0th index element chosen, 1st element chosen]
dp[1][0] = mat[0][0]
dp[2][0] = mat[1][0]
for i in range(1, n):
dp[0][i] = max(dp[0][i-1], dp[1][i-1], dp[2][i-1])
dp[1][i] = max(dp[0][i-1], dp[2][i-1])+mat[0][i]
dp[2][i] = max(dp[0][i-1], dp[1][i-1])+mat[1][i]
# print(dp)
res = max(max(dp[0]), max(dp[1]), max(dp[2]))
print(res)
| 9 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int tri[50000];
void init() {
int i, j, k;
k = 1;
for (i = 1; i < 44721; i++) {
tri[i] = (i * (i + 1)) / 2;
}
tri[0] = 0;
}
bool make(int n) {
int i, j, k;
for (i = 44720; i; i--) {
if (tri[i] < n) break;
}
j = 1;
while (i && tri[j] <= tri[i]) {
if (tri[j] + tri[i] == n) {
return true;
} else if (tri[j] + tri[i] < n)
j++;
else {
i--;
while (tri[j] + tri[i] > n) j--;
}
}
return false;
}
int main() {
int i, j, k;
int n;
init();
while (cin >> n) {
if (n == 1) {
cout << "NO" << endl;
continue;
}
if (make(n)) {
cout << "YES" << endl;
} else
cout << "NO" << endl;
}
return 0;
}
| 7 | CPP |
for _ in range(int(input())):
n=int(input())
l=list(map(int,input().split()))
i=0
a=0
c,m=0,0
while i<len(l) or len(l)!=0:
m+=1
if m%2!=0:
p=0
if m==1:
p=l[i]
del l[i]
else:
if l[i]>q:
p=l[i]
del l[i]
else:
while p<=q and len(l)!=0:
p+=l[i]
del l[i]
a+=p
else:
q=0
if l[len(l)-1]>p:
q+=l[len(l)-1]
del l[len(l)-1]
else:
while q<=p and len(l)!=0:
q+=l[len(l)-1]
del l[len(l)-1]
c+=q
print(m,a,c)
| 10 | PYTHON3 |
import sys
lines = sys.stdin.read().splitlines()
lincnt = -1
def line():
global lincnt
lincnt += 1
return lines[lincnt]
nums = [6,10,14]
for _ in range(int(line())):
n = int(line())
if n > sum(nums):
d = n - sum(nums)
if d in nums:
print("YES", d-1, 6, 10, 15)
else:
print("YES", d, 6, 10, 14)
else:
print("NO")
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
map<int, int> m;
queue<int> q;
for (int i = 0; i < n; i++) {
int temp;
cin >> temp;
if (m[temp] == 0) {
if (q.size() == k) {
m[q.front()]--;
q.pop();
q.push(temp);
m[temp]++;
} else {
q.push(temp);
m[temp]++;
}
}
}
cout << q.size() << endl;
vector<int> v;
while (!q.empty()) {
v.push_back(q.front());
q.pop();
}
reverse(v.begin(), v.end());
for (int i = 0; i < v.size(); i++) {
cout << v[i] << " ";
}
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, ans = 0;
cin >> n >> m;
while (n / m > 0) {
ans += m * (n / m);
n = n % m + n / m;
}
ans += n;
cout << ans;
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
const long long MXN = 1e6 + 1;
const long long MNN = 1e3 + 1;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
using namespace std;
long long n, m, b[222222], mx = -1, mn = INF, a, ans, k, sum, x, q, c[111111],
pr[111111], n1, n2, m1, m2, nc;
char ch;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
cin >> n >> ch >> m;
nc = (n % 10) * 10;
nc += (n / 10);
m++;
for (int i = n;; i++) {
if (i == 24) {
i = 0;
}
nc = (i % 10) * 10;
nc += (i / 10);
for (int j = m; j <= 60; j++) {
m = 0;
if (j == 60) {
break;
}
if (nc == j) {
if (i < 10) {
cout << '0' << i << ':';
} else {
cout << i << ':';
}
if (j < 10) {
cout << '0' << j;
} else {
cout << j;
}
return 0;
}
}
}
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
int findlastone(string s) {
int i, k;
for (i = s.length() - 1, k = 1; i >= 0; i--, k++) {
if (s[i] == '1') break;
}
return s.length() - k;
}
int main() {
int t;
cin >> t;
while (t--) {
string s;
cin >> s;
int first;
for (int i = 0; i < s.length(); i++) {
if (s[i] == '1') {
first = i;
break;
}
}
int last = findlastone(s);
int cnt = 0;
for (int i = first; i <= last; i++) {
if (s[i] == '0') cnt++;
}
cout << cnt << endl;
}
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
template <class t>
inline void read(t &s) {
s = 0;
register long long f = 1;
register char c = getchar();
while (!isdigit(c)) {
if (c == '-') f = -1;
c = getchar();
}
while (isdigit(c)) s = (s << 3) + (s << 1) + (c ^ 48), c = getchar();
s *= f;
return;
}
template <class t, class... A>
inline void read(t &x, A &...a) {
read(x);
read(a...);
}
template <class t>
inline void write(t x) {
if (x < 0) putchar('-'), x = -x;
long long buf[21], top = 0;
while (x) buf[++top] = x % 10, x /= 10;
if (!top) buf[++top] = 0;
while (top) putchar(buf[top--] ^ '0');
return;
}
inline void setIn(std::string s) {
freopen(s.c_str(), "r", stdin);
return;
}
inline void setOut(std::string s) {
freopen(s.c_str(), "w", stdout);
return;
}
inline void setIO(std::string s = "") {
setIn(s + ".in");
setOut(s + ".out");
return;
}
template <class t>
inline bool ckmin(t &x, t y) {
if (x > y) {
x = y;
return 1;
}
return 0;
}
template <class t>
inline bool ckmax(t &x, t y) {
if (x < y) {
x = y;
return 1;
}
return 0;
}
inline long long lowbit(long long x) { return x & (-x); }
const long long MaxN = 5050;
long long a[MaxN], n, K, V;
long long f[2][MaxN], pre[MaxN][MaxN];
long long tr[MaxN], trZ[MaxN];
signed main(void) {
read(n, K, V);
for (long long i = 1; i <= n; ++i) read(a[i]);
{
register long long s = 0;
for (long long i = 1; i <= n; ++i) s += a[i];
if (s < V) return std::puts("NO"), 0;
}
if (!V) return std::puts("YES\n1000000000 1 2"), 0;
std::memset(f, 0xc0, sizeof f), f[0][0] = f[1][0] = 0;
for (long long i = 1; i <= n;
++i, std::memcpy(f[i & 1], f[(i & 1) ^ 1], sizeof(f[i & 1])))
for (long long j = 0; j < K; ++j)
if (ckmax(f[i & 1][(j + a[i]) % K], f[(i & 1) ^ 1][j] + a[i]))
pre[i][(j + a[i]) % K] = 1;
if (f[n & 1][V % K] < 0) return std::puts("NO"), 0;
if (!(V % K)) {
std::puts("YES");
for (long long i = 1; i < n; ++i)
write((long long)(1e9)), std::putchar(32), write(i), std::putchar(32),
write(n), std::puts("");
write(V / K), std::putchar(32), write(n), std::putchar(32), write(n - 1),
std::puts("");
return 0;
}
std::vector<long long> dr;
register long long y = V % K, ZZ = 0;
for (long long i = n; i; --i)
if (pre[i][y]) dr.push_back(i), y = (y - a[i] % K + K) % K;
for (long long i = 1; i < (long long)dr.size(); ++i)
a[dr[0]] += a[dr[i]], a[dr[i]] = 0, tr[dr[i]] = 1e9;
for (long long i = 1; i <= n; ++i)
if (a[i] && i != dr[0]) {
ZZ = i;
break;
}
for (long long i = 1; i <= n; ++i)
if (a[i] && i != ZZ && i != dr[0]) trZ[i] = 1e9, a[ZZ] += a[i], a[i] = 0;
register long long subZ = std::min((V - a[dr[0]]) / K, a[ZZ] / K);
ckmax(subZ, 0LL);
a[dr[0]] += subZ * K;
if (a[dr[0]] < V) return std::puts("NO"), 0;
std::puts("YES");
for (long long i = 1; i <= n; ++i)
if (trZ[i])
write(trZ[i]), std::putchar(32), write(i), std::putchar(32), write(ZZ),
std::puts("");
for (long long i = 1; i <= n; ++i)
if (tr[i])
write(tr[i]), std::putchar(32), write(i), std::putchar(32), write(dr[0]),
std::puts("");
if (subZ)
write(subZ), std::putchar(32), write(ZZ), std::putchar(32), write(dr[0]),
std::puts("");
if (a[dr[0]] - V)
write((a[dr[0]] - V) / K), std::putchar(32), write(dr[0]), std::putchar(32),
write(dr[0] == 1 ? 2 : 1), std::puts("");
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long _set(long long N, long long pos) { return N = N | (1 << pos); }
long long _reset(long long N, long long pos) { return N = N & ~(1 << pos); }
bool _check(long long N, long long pos) { return (bool)(N & (1 << pos)); }
bool _upper(char a) { return a >= 'A' && a <= 'Z'; }
bool _lower(char a) { return a >= 'a' && a <= 'z'; }
bool _digit(char a) { return a >= '0' && a <= '9'; }
long long dx[] = {1, -1, 0, 0, -1, -1, 1, 1};
long long dy[] = {0, 0, 1, -1, -1, 1, -1, 1};
int main() {
int n;
cin >> n;
if (n % 2)
cout << "black";
else
cout << "white\n1 2";
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
string str;
cin >> str;
string arr[10];
for (int i = 0; i < 10; i++) cin >> arr[i];
for (int k = 0; k < 8; k++) {
string temp = str.substr(k * 10, 10);
for (int j = 0; j < 10; j++) {
if (temp == arr[j]) cout << j;
}
}
return 0;
}
| 7 | CPP |
#include<iostream>
#include<sstream>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<algorithm>
#include<numeric>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define rp(i,c) rep(i,(c).size())
#define fr(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf=1<<28;
const double INF=1e12,EPS=1e-9;
int n,X[100],t[100];
int dp[100][4];
int main()
{
while(cin>>n,n){
rep(i,n)cin>>X[i+1]>>t[i+1];
rep(i,n+1)rep(k,4)dp[i][k]=1e9;
dp[0][0]=0;
rep(i,n)rep(k,4){
if(k<3&&abs(X[i+1]-X[i])*(k+1)<=t[i+1]-t[i])
dp[i+1][k+1]=min(dp[i+1][k+1],dp[i][k]+abs(X[i+1]-X[i]));
if(X[i]*(k+1)+X[i+1]<=t[i+1]-t[i])
dp[i+1][1]=min(dp[i+1][1],dp[i][k]+X[i]+X[i+1]);
}
int ans=1e9,mx;
rep(k,4)ans=min(ans,dp[n][k]+X[n]);
if(ans>=1e9){
rep(i,n)rep(k,4)if(dp[i][k]<1e9)mx=i;
cout<<"NG "<<mx+1<<endl;
continue;
}
cout<<"OK "<<ans<<endl;
}
return 0;
} | 0 | CPP |
#include<bits/stdc++.h>
using namespace std;
using lli = long long;
#define rep(i,n) for(int i=0;i<n;i++)
const lli m = 2e5+10;
lli n, k;
int main(void){
cin >> n >> k;
vector<lli> c(m);
rep(i, n){
lli ai;
cin >> ai;
c[ai]++;
}
sort(c.begin(), c.end(), greater<lli>());
lli ans = n;
rep(i, k) ans-=c[i];
cout << ans << endl;
return 0;
}
| 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int* a = new int[n];
for (int i = 0; i < n; i++) a[i] = 0;
int x;
int count = 0;
int max = -1;
for (int i = 0; i < (2 * n); i++) {
cin >> x;
if (a[x - 1] == 0) {
count++;
a[x - 1]++;
if (count > max) max = count;
} else
count--;
}
cout << max;
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string s1, s2;
cin >> s1 >> s2;
int p[10] = {0};
int q[10] = {0};
int len1 = s1.size();
int len2 = s2.size();
for (int i = 0; i < len1; i++) {
if (s1[i] == '9')
p[(int)s1[i] - 51]++;
else if (s1[i] == '5')
p[(int)s1[i] - 51]++;
else
p[(int)s1[i] - 48]++;
}
for (int i = 0; i < len2; i++) {
if (s2[i] == '9')
q[(int)s2[i] - 51]++;
else if (s2[i] == '5')
q[(int)s2[i] - 51]++;
else
q[(int)s2[i] - 48]++;
}
int flag = 0;
int r[10] = {0};
int count = 0;
for (int i = 0; i < 10; i++) {
if (p[i] > q[i]) {
flag++;
break;
} else if (p[i] > 0 && q[i] > 0) {
r[count++] = q[i] / p[i];
}
}
if (flag > 0)
cout << "0";
else {
sort(r, r + count);
cout << r[0];
}
}
| 8 | CPP |
def findgrid(n,m,a):
mat=[]
for i in range(n):
x=[]
for j in range(m):
if n==1 and m==1:
x.appennd(1)
elif n==1:
if j==0 or j==m-1:
x.append(1)
else:
x.append(2)
elif m==1:
if i==0 or i==n-1:
x.append(1)
else:
x.append(2)
elif (i==0 or i==n-1) and (j==0 or j==m-1):
x.append(2)
elif (i==0 or i==n-1) and (j!=0 and j!=m-1):
x.append(3)
elif (j==0 or j==m-1) and (i!=0 and i!=n-1):
x.append(3)
else:
x.append(4)
mat.append(x)
flag=0
for i in range(n):
for j in range(m):
if a[i][j]>mat[i][j]:
flag=1
return mat,flag
t=int(input())
while t>0:
nm=input().split()
n=int(nm[0])
m=int(nm[1])
a=[[int(j) for j in input().split()]for i in range(n)]
mat,f=findgrid(n,m,a)
if f==0:
print("YES")
for i in range(n):
for j in range(m):
print(mat[i][j],end=' ')
print()
else:
print("NO")
t-=1 | 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int n;
int x[110000], y[110000];
int arr[110000];
map<int, set<pair<int, int>>> M;
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++)
scanf("%d%d", &x[i], &y[i]), M[y[i] - x[i]].insert(make_pair(x[i], y[i]));
stringstream ss;
ss << "YES" << endl;
for (int i = 0; i < n; i++) scanf("%d", &arr[i]);
for (int i = 0; i < n; i++) {
pair<int, int> tmp;
if (!M[arr[i]].size()) return puts("NO"), 0;
tmp = *M[arr[i]].begin();
M[arr[i]].erase(M[arr[i]].begin());
int x = tmp.first, y = tmp.second;
if (M[arr[i] - 1].count(make_pair(x, y - 1)) ||
M[arr[i] + 1].count(make_pair(x - 1, y)))
return puts("NO"), 0;
ss << x << " " << y << endl;
}
cout << ss.str();
return 0;
}
| 9 | CPP |
import sys,io,os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
read = lambda: map(int,input().split())
N=10**5
q=[0]*N
p=[]
for i in range(2,N):
if q[i]==0:
q[i]=i
p.append(i)
j=0
while j<len(p) and p[j]<=q[i] and i*p[j]<N:
q[i*p[j]]=p[j]
j+=1
def factor(n):
i=0
r=[]
c=2
while n>1 and c*c<=n:
if n%c<1:
e=0
while n%c<1:
n//=c
e+=1
r.append((c,e))
i+=1
c=p[i]
if n>1: r.append((n,1))
return r
O = []
for _ in range(int(input())):
a,b,k = read()
if a<b: a,b = b,a
pa=pb=0
for i,j in factor(a): pa+=j
for i,j in factor(b): pb+=j
O.append(["NO","YES"][2<=k<=pa+pb or (k==1 and a!=b and a%b==0)])
print('\n'.join(O)) | 10 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
char prev = s[0];
int cnt = 1;
int ans = 0;
for (int i = 1; i < s.size(); i++) {
if (s[i] == prev)
cnt++;
else {
if (cnt % 2 == 0) ans++;
cnt = 1;
prev = s[i];
}
}
if (cnt % 2 == 0) ans++;
cout << ans << endl;
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define DEBUG(x) cerr << #x << " = " << x << endl
const int MOD = 1000000007;
int N, D, X;
int psum[2001][2001];
int tmp[2001][2001];
int extgcd(int a, int b, int &x, int &y) {
int d = a;
if (b != 0) {
d = extgcd(b, a % b, y, x);
y -= (a / b) * x;
} else {
x = 1; y = 0;
}
return d;
}
int mod_inv(int a, int m) {
int x, y;
extgcd(a, m, x, y);
return (m + x % m) % m;
}
int combination(int n, int k) {
if(n < k) return 0;
int ans = 1;
for(int i = 0; i < k; ++i) {
ans *= (n - i) % MOD;
ans %= MOD;
ans *= mod_inv(k - i, MOD);
ans %= MOD;
}
return ans;
}
signed main() {
ios::sync_with_stdio(false);
while(true) {
cin >> N >> D >> X;
if(N == 0 && D == 0 && X == 0) break;
memset(tmp, 0, sizeof(tmp));
for(int i = 1; i < X; ++i) {
tmp[1][i] = 1;
}
for(int i = 1; i < 2001; ++i) {
psum[1][i] = psum[1][i - 1] + tmp[1][i];
psum[1][i] %= MOD;
}
for(int d = 2; d < 2001; ++d) {
for(int i = 1; i < 2001; ++i) {
int add = psum[d - 1][max<int>(0, i - 1)];
int sub = psum[d - 1][max<int>(0, i - X)];
tmp[d][i] = add - sub;
tmp[d][i] = (MOD + tmp[d][i] % MOD) % MOD;
}
for(int i = 1; i < 2001; ++i) {
psum[d][i] = psum[d][i - 1] + tmp[d][i];
psum[d][i] %= MOD;
}
}
//for(int d = 1; d <= 5; ++d) {
// cerr << "d = " << d << ":";
// for(int n = 0; n <= 10; ++n) {
// cerr << " " << tmp[d][n];
// }
// cerr << endl;
//}
int ans = 0;
for(int d = 1; d <= N; ++d) {
ans += combination(D, d) * tmp[d][N];
// cerr << "comb " << D << " " << d << " = " << combination(D, d) << endl;
// cerr << "tmp[" << d << "][" << N << "] = " << tmp[d][N] << endl;
ans = (MOD + ans % MOD) % MOD;
}
cout << ans << endl;
}
} | 0 | CPP |
x=(input())
a=int(x[0:2])
b=int(x[3:])
if a>12:
a-=12
if a==12:
a=0
lol=a*30+0.5*b
yo=b*6
print(lol,yo) | 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
using ll = long long;
ll a[N], s[N];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll n, m;
cin >> n >> m;
for (int i = 1; i <= n; ++i)
cin >> a[i];
sort(a + 1, a + 1 + n);
for (int i = 1; i <= n; ++i)
s[i] = s[i - 1] + a[i];
ll l = 1, r = 1e10;
for (; l < r; )
{
ll mid = (l + r) / 2 + 1, cnt = 0;
for (int i = 1; i <= n; ++i)
cnt += n - (lower_bound(a + 1, a + 1 + n, mid - a[i]) - a) + 1;
if (cnt >= m)
l = mid;
else
r = mid - 1;
}
ll ans = 0, cnt = 0;
for (int i = 1; i <= n; ++i)
{
int pos = lower_bound(a + 1, a + 1 + n, l - a[i]) - a, tot = n - pos + 1;
cnt += tot;
ans += a[i] * tot + s[n] - s[pos - 1];
}
cout << ans - (cnt - m) * l;
}
| 0 | CPP |
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cctype>
#include<complex>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<functional>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
using namespace std;
const int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};
#define INF 1e+9
#define EPS 1e-9
#define rep(i,j) for(int i = 0; i < (j); i++)
#define reps(i,j,k) for(int i = j; i < (k); i++)
typedef long long ll;
ll mem[1000000]={0};
ll mem2[1000000]={0};
int main(){
string str="";
bool f = false;
int ma = 0;
while(getline(cin,str)){
int x;
stringstream s(str);
s >> x;
if(str == "")f = true;
else if(!f)mem[x]++;
else if(f && mem[x] > 0){
mem2[x]++;
ma = max(ma,x);
}
}
rep(i,ma+1){
if(mem2[i] > 0)printf("%d %d\n",i,mem[i]+mem2[i]);
}
return 0;
} | 0 | CPP |
import sys
input = sys.stdin.readline
def solve():
n=int(input())
ans=0
flag=0
for i in range(1,10):
total = 0
for j in range(4):
total=total*10+i
ans+=j+1
if total==n:
return ans
if __name__=="__main__":
for _ in range(int(input())):
print(solve())
| 7 | PYTHON3 |
a = [int(e) for e in input().split()]
if (a[0]*a[1])%2 == 0:
print(int(a[0]*a[1]/2))
else:
print(int((a[0]*a[1]-1)/2))
| 7 | PYTHON3 |
#include <bits/stdc++.h>
const int N = 200010, M = 20;
int w[N], s[N], f[N], best[M][1 << M], bestk = 0;
int main() {
int n, k, i, j, tmp, min;
char temp[25];
memset(w, 0, sizeof(w));
scanf("%d", &n);
scanf("%s", temp);
k = strlen(temp);
for (i = 0; i < k; i++) w[1] = w[1] * 2 + int(temp[i]) - 48;
for (i = 2; i <= n; i++) {
scanf("%s", temp);
for (j = 0; j < k; j++) w[i] = w[i] * 2 + int(temp[j]) - 48;
}
memset(s, 0, sizeof(s));
s[1] = k;
for (i = 2; i <= n; i++) {
tmp = -1;
for (j = 0; j < k; j++)
if ((w[i - 1] & ((1 << (k - j)) - 1)) == (w[i] >> j)) {
tmp = j;
break;
}
if (tmp == -1) tmp = k;
s[i] = s[i - 1] + tmp;
}
memset(best, -1, sizeof(best));
f[0] = 0;
f[1] = k;
for (i = 2; i <= n; i++) {
min = INT_MAX;
for (j = 0; j < k; j++) {
if (best[j][w[i] >> j] != -1) {
tmp = best[j][w[i] >> j];
if (min > f[tmp + 1] + j + s[i - 1] - s[tmp + 1])
min = f[tmp + 1] + j + s[i - 1] - s[tmp + 1];
}
}
if (min > f[bestk + 1] + k + s[i - 1] - s[bestk + 1])
min = f[bestk + 1] + k + s[i - 1] - s[bestk + 1];
f[i] = min;
for (j = 0; j < k; j++) {
tmp = w[i - 1] & ((1 << (k - j)) - 1);
if (best[j][tmp] == -1 ||
f[best[j][tmp] + 1] - s[best[j][tmp] + 1] > f[i] - s[i])
best[j][tmp] = i - 1;
}
if (f[bestk + 1] - s[bestk + 1] > f[i] - s[i]) bestk = i - 1;
}
min = INT_MAX;
for (i = 1; i <= n; i++)
if (min > f[i] + s[n] - s[i]) min = f[i] + s[n] - s[i];
printf("%d", min);
return (0);
}
| 11 | CPP |
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
#define EPS 1e-10
#define equals(a,b) (fabs((a)-(b)) < EPS)
//???
class Point{
public:
double x,y;
Point(double x = 0,double y = 0):x(x),y(y){}
//?????????
Point operator + (Point p) { return Point(x + p.x,y + p.y);}
Point operator - (Point p) { return Point(x - p.x,y - p.y);}
Point operator * (double a) { return Point(x*a,y*a);}
Point operator / (double a) { return Point(x/a,y/a);}
//???????????¨??§??????
double abs() {return sqrt(norm());}
double norm() {return x*x+y*y;}
bool operator < (const Point &p) const{
return x != p.x ? x < p.x : y < p.y;
}
bool operator == (const Point &p) const{
return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
}
};
//??????
struct Segment{Point p1,p2;};
//????????????
typedef Point Vector;
//??´???
typedef Segment Line;
//???
class Circle{
public:
Point c;
double r;
Circle(Point c = Point(),double r = 0.0): c(c),r(r){}
};
//????§???¢
//typedef Vector<Point> Polygon;
//????????¨??????
double dot(Vector a,Vector b){
return a.x*b.x + a.y*b.y;
}
double cross(Vector a,Vector b){
return a.x*b.y - a.y*b.x;
}
Point crosspoint(Point p0,Point p1,Point p2,Point p3){
double d1,d2;
Vector base(p1-p0);
Vector hypo1(p2-p0);
Vector hypo2(p3-p0);
d1 = abs(cross(base,hypo1));
d2 = abs(cross(base,hypo2));
double t = d1 / (d1+d2);
Vector v(p3-p2);
return p2 + v*t;
}
int main(){
int n;
cin >> n;
Point p0,p1,p2,p3;
for(int i = 0;i < n;i++){
cin >> p0.x >> p0.y >> p1.x >> p1.y >> p2.x >> p2.y >> p3.x >> p3.y;
Point p = crosspoint(p0,p1,p2,p3);
printf("%.10f %.10f",p.x,p.y);
cout << endl;
}
return 0;
} | 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
cout << n / 2 + 1 << endl;
int x = n / 2, i = 1;
while (i <= x) {
cout << "1"
<< " " << i << endl;
i++;
}
int y = i, c = 1;
while (i <= n) {
cout << y << " " << c << endl;
c++;
i++;
}
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main(){
long long int n, k;
cin>>n>>k;
cout<<min(n%k , k-(n%k));
return 0;
}
| 0 | CPP |
def c(k, n):
if 2 * k > n: k = n - k
p, q, n = 1, 1, n + 1
for i in range(1, k + 1):
p *= n - i
q *= i
return p // q
n, m, t = map(int, input().split())
print(sum(c(x, m) * c(t - x, n) for x in range(max(1, t - n), min(t - 3, m + 1))))
| 9 | PYTHON3 |
a=list(map(int,input().split()))
if(a[0]%2==0):
if(a[1]>a[0]/2):
print(2*int(a[1]-a[0]/2))
else:
print(2*a[1]-1)
else:
if(a[1]>int(a[0]/2+1)):
print(2*(a[1]-int((a[0]/2)+1)))
else:
print(2*a[1]-1)
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
char ch[10005];
int main() {
int n, start, end, ans, sum, now;
cin >> n;
getchar();
gets(ch);
sum = 0;
for (int i = 0; i < n; i++) {
if (ch[i] == 'T') sum++;
}
start = 0;
end = sum - 1;
now = 0;
for (int i = start; i <= end; i++) {
if (ch[i] == 'T') now++;
}
ans = sum - now;
for (int start = 1; start - n != 1; start++) {
end++;
int pre = (start - 1) % n;
if (ch[pre] == 'T') now--;
if (ch[end % n] == 'T') now++;
if (sum - now < ans) {
ans = sum - now;
}
}
cout << ans << endl;
}
| 9 | CPP |
t = int(input())
for i in range(t):
n = int(input())
for i in range(1,n+1):
if (i == n):
print(i)
else:
print(i,end=" ") | 7 | PYTHON3 |
def solve(given, hand):
for char in given:
for card in hand:
if char in card:
return "YES"
return "NO"
given = input()
hand = input().split()
print(solve(given, hand))
| 7 | PYTHON3 |
mod=10**9+7
def prime_factor(n):
ass=[]
for i in range(2,int(n**0.5)+1):
while n%i==0:ass.append(i);n//=i
if n!=1:ass.append(n)
return ass
f=[1]
for i in range(1,200000):f.append(f[-1]*i%mod)
def comb(a,b,m):return f[a]*pow(f[b],m-2,m)*pow(f[a-b],m-2,m)%m
n,m=map(int,input().split())
if m==1:print(1);exit()
d=prime_factor(m)
b=[1]
for i in range(1,len(d)):
if d[i-1]==d[i]:b[-1]+=1
else:b.append(1)
ans=1
for i in b:ans*=comb(i+n-1,i,mod);ans%=mod
print(ans) | 0 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
inline void rd(long long &x) {
x = 0;
char ch = 0;
long long w = 0;
while (!isdigit(ch)) ch = getchar(), w |= ch == '-';
while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
x = w ? -x : x;
}
pair<long long, long long> a[300005];
long long n, cnt, ans;
long long rt, x, y, z;
long long sz[300005], ls[300005], rs[300005], val[300005], k[300005],
add[300005];
long long New(long long v) {
sz[++cnt] = 1;
val[cnt] = v;
k[cnt] = rand();
return cnt;
}
void up(long long x) { sz[x] = sz[ls[x]] + sz[rs[x]] + 1; }
void push(long long p) {
if (!add[p]) return;
long long x = add[p];
add[p] = 0;
if (ls[p]) add[ls[p]] += x, val[ls[p]] += x;
if (rs[p]) add[rs[p]] += x, val[rs[p]] += x;
}
void split(long long p, long long k, long long &a, long long &b) {
if (!p) return a = b = 0, void();
push(p);
if (val[p] <= k)
a = p, split(rs[a], k, rs[p], b);
else
b = p, split(ls[p], k, a, ls[p]);
up(p);
}
long long merge(long long a, long long b) {
if (!a or !b) return a | b;
push(a);
push(b);
if (k[a] < k[b])
return rs[a] = merge(rs[a], b), up(a), a;
else
return ls[b] = merge(a, ls[b]), up(b), b;
}
long long pre(long long x) {
while (ls[x]) push(x), x = ls[x];
return x;
}
void dfs(long long x) {
if (!x) return;
ans++;
dfs(ls[x]);
dfs(rs[x]);
}
void work(long long l, long long r) {
split(rt, r - 1, x, y);
z = pre(y);
split(y, val[z], z, y);
split(x, l - 1, z, x);
add[x]++;
val[x]++;
z = merge(z, New(l));
rt = merge(merge(z, x), y);
}
signed main() {
rd(n);
srand(20020625);
for (long long l, r, i = 1; i <= n; i++) rd(l), rd(r), work(l, r);
dfs(rt);
cout << ans;
}
| 10 | CPP |
n=int(input())
x=n
c=1
while(x%360):
x+=n
x%=360
c+=1
print(c)
| 0 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
std::vector<int> adj[100010], level[100010];
int v[100010], par[100010], Level[100010], t = 0, dis[100010], fin[100010];
void dfs(int s, int l) {
if (v[s]) return;
v[s] = 1;
dis[s] = t++;
for (int i = 0; i < adj[s].size(); ++i) {
int t = adj[s][i];
if (!v[t]) {
par[t] = s;
dfs(t, l + 1);
}
}
level[l].push_back(t);
fin[s] = t++;
Level[s] = l;
}
int anch[100010][35];
void sparse_table(int n) {
for (int i = 0; (1 << i) <= n; ++i)
for (int j = 1; j <= n; ++j) {
if (!i)
anch[j][i] = par[j];
else if (anch[j][i - 1] != -1)
anch[j][i] = anch[anch[j][i - 1]][i - 1];
}
}
int parent(int x, int p) {
for (int i = 30; i >= 0; i--) {
if ((p >= (1 << i)) and anch[x][i] != -1) {
p -= (1 << i);
x = anch[x][i];
}
}
return x;
}
int main() {
memset(anch, -1, sizeof anch);
int n;
cin >> n;
for (int i = 1; i <= n; ++i) {
int x;
cin >> x;
if (x) adj[x].push_back(i);
}
for (int i = 1; i <= n; ++i)
if (!v[i]) par[i] = -1, dfs(i, 0);
sparse_table(n);
int q;
cin >> q;
while (q--) {
int p, x;
cin >> x >> p;
if (Level[x] < p or par[x] == -1)
printf("0 ");
else {
int l = Level[x];
int P = parent(x, p);
int up = upper_bound(level[l].begin(), level[l].end(), fin[P]) -
level[l].begin();
int lo = lower_bound(level[l].begin(), level[l].end(), dis[P]) -
level[l].begin();
printf("%d ", up - lo - 1);
}
}
}
| 11 | CPP |
#include <bits/stdc++.h>
const int imin = std::numeric_limits<int>::min();
const int imax = std::numeric_limits<int>::max();
using namespace std;
int main() {
int n;
cin >> n;
vector<int> s(n);
for (int i = 0; i < n; i++) {
cin >> s[i];
}
qsort(&s[0], s.size(), sizeof(int),
[](const void *a, const void *b) { return *((int *)a) - *((int *)b); });
int sum = 0;
int count = 0;
for (int i = 0; i < n; i++) {
if (sum <= s[i]) {
count++;
sum += s[i];
}
}
cout << count << endl;
}
| 10 | CPP |
import sys
def main():
m, n = map( int, sys.stdin.readline().strip().split())
if min(m,n)%2 == 1:
print("Akshat")
else:
print("Malvika")
if __name__ == ("__main__"):
main()
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
map<int, int> m;
int n, k, a;
cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> a;
m[a] = i + 1;
}
map<int, int>::iterator it = m.begin();
if (m.size() < k)
cout << "NO";
else {
cout << "YES\n";
for (int i = 0; i < k; i++) {
cout << it->second << " ";
it++;
}
}
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int max_n = 1e5 + 7;
const int inf = 1e9 + 7;
int a[max_n];
int n, k, c;
inline int pow(int a, int b) {
int ans = 1;
for (int i = 1; i <= b; ++i) ans *= a;
return ans;
}
int main() {
scanf("%d%d", &n, &k);
for (int i = 1; i <= n; ++i) {
int ans = 0;
for (int j = k; j >= 1; --j) {
scanf("%d", &c);
if (c == 1) ans += pow(2, j - 1);
}
a[ans] += 1;
}
for (int i = 0; i <= 15; ++i)
for (int j = 0; j <= 15; ++j)
if ((i & j) == 0 && a[i] && a[j]) {
printf("YES\n");
return 0;
}
printf("NO\n");
return 0;
}
| 9 | CPP |
n, k =[int(i) for i in input().split()]
rocket = [(ord(i)-96) for i in list(input())]
rocket.sort()
sum, i = 0, 1
prev = rocket[0]
sum += rocket[0]
k -=1
while k>0 and i<n:
if rocket[i] - prev > 1:
sum += rocket[i]
prev = rocket[i]
k -= 1
i += 1
if k == 0:
print(sum)
else:
print("-1") | 7 | PYTHON3 |
s=input().split("WUB")
for i in s:
if(len(i)!=0):
print(i," ") | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200010;
int n, a[maxn];
long long b[maxn];
vector<int> v[maxn];
long long sum[maxn << 2], rn[maxn << 2], lz[maxn << 2];
inline void pushup(int x) {
int ls = x << 1, rs = ls + 1;
sum[x] = sum[ls] + sum[rs];
rn[x] = rn[rs];
}
inline void pushdown(int x, int l, int r) {
int ls = x << 1, rs = ls + 1, mid = l + r >> 1;
if (lz[x]) {
lz[ls] = lz[rs] = lz[x];
sum[ls] = (mid - l + 1) * lz[x];
rn[ls] = lz[x];
sum[rs] = (r - mid) * lz[x];
rn[rs] = lz[x];
lz[x] = 0;
}
}
void build(int x, int l, int r) {
if (l == r) {
sum[x] = l;
rn[x] = l;
lz[x] = 0;
return;
}
int mid = l + r >> 1;
build(x << 1, l, mid);
build(x << 1 | 1, mid + 1, r);
pushup(x);
}
int getles(int x, int l, int r, int k) {
if (l == r) {
return sum[x] <= k ? l : l - 1;
}
pushdown(x, l, r);
int mid = l + r >> 1, ls = x << 1;
if (rn[ls] <= k)
return getles(x << 1 | 1, mid + 1, r, k);
else
return getles(x << 1, l, mid, k);
}
void modify(int x, int l, int r, int L, int R, int k) {
if (L <= l && r <= R) {
lz[x] = k;
sum[x] = (r - l + 1ll) * k;
rn[x] = k;
return;
}
pushdown(x, l, r);
int mid = l + r >> 1;
if (L <= mid) modify(x << 1, l, mid, L, R, k);
if (mid < R) modify(x << 1 | 1, mid + 1, r, L, R, k);
pushup(x);
}
int main() {
scanf("%d", &n);
int maxa = 0;
for (int i = (1); i <= (n); i++) {
scanf("%d", &a[i]);
maxa = max(maxa, a[i]);
for (int j = 1; j * j <= a[i]; j++) {
if (a[i] % j == 0) {
v[j].push_back(i);
if (j * j != a[i]) v[a[i] / j].push_back(i);
}
}
}
if (n <= 2) {
puts("0");
return 0;
}
for (int i = (1); i <= (maxa); i++)
if (v[i].size()) sort(v[i].begin(), v[i].end());
build(1, 1, n);
long long ans = 0;
b[maxa] = (long long)n * n + n - sum[1];
for (int i = (maxa); i >= (2); i--) {
if (v[i].size() > 1) {
int k = v[i].size();
int x = getles(1, 1, n, n + 1);
if (v[i][1] + 1 <= x) modify(1, 1, n, v[i][1] + 1, x, n + 1);
x = getles(1, 1, n, v[i][k - 1]);
int r = min(x, v[i][1]);
if (v[i][0] + 1 <= r) modify(1, 1, n, v[i][0] + 1, r, v[i][k - 1]);
x = getles(1, 1, n, v[i][k - 2]);
r = min(x, v[i][0]);
if (1 <= r) modify(1, 1, n, 1, r, v[i][k - 2]);
}
b[i - 1] = (long long)n * n + n - sum[1];
ans += (b[i] - b[i - 1]) * i;
}
ans += b[1] - 3;
cout << ans << endl;
return 0;
}
| 9 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 4e5 + 5;
const int MOD = 998244353;
int mult(long long a, long long b) { return (a * b) % MOD; }
int pot(int n, int k) {
int ret = 1, pot = n;
for (; k > 0; k >>= 1, pot = mult(pot, pot))
ret = mult(ret, (k & 1) ? pot : 1);
return ret;
}
int divide(int a, int b) { return mult(a, pot(b, MOD - 2)); }
int add(int a, int b) {
a += b;
if (a >= MOD) a -= MOD;
return a;
}
int sub(int a, int b) {
a -= b;
if (a < 0) a += MOD;
return a;
}
struct Node {
int lo, hi, LL, LR, RL, RR;
Node(int first, int second, int a, int b, int c, int d) {
lo = first, hi = second, LL = a, LR = b, RL = c, RR = d;
}
void print() {
cout << lo << ' ' << hi << " | " << LL << ' ' << LR << ' ' << RL << ' '
<< RR << "\n";
}
};
int n, POT = 1;
int X[maxn], V[maxn], P[maxn];
vector<Node> tree;
int C[maxn][4];
pair<int, int> TP[maxn][4];
Node merge(int first) {
Node L = tree[first * 2], R = tree[first * 2 + 1];
Node ret = tree[first];
ret.lo = L.lo, ret.hi = R.hi;
ret.LL = mult(mult(L.LL, R.LL), C[L.hi][0]);
ret.LL = add(ret.LL, mult(mult(L.LL, R.RL), C[L.hi][1]));
ret.LL = add(ret.LL, mult(mult(L.LR, R.LL), C[L.hi][2]));
ret.LL = add(ret.LL, mult(mult(L.LR, R.RL), C[L.hi][3]));
ret.LR = mult(mult(L.LL, R.LR), C[L.hi][0]);
ret.LR = add(ret.LR, mult(mult(L.LL, R.RR), C[L.hi][1]));
ret.LR = add(ret.LR, mult(mult(L.LR, R.LR), C[L.hi][2]));
ret.LR = add(ret.LR, mult(mult(L.LR, R.RR), C[L.hi][3]));
ret.RL = mult(mult(L.RL, R.LL), C[L.hi][0]);
ret.RL = add(ret.RL, mult(mult(L.RL, R.RL), C[L.hi][1]));
ret.RL = add(ret.RL, mult(mult(L.RR, R.LL), C[L.hi][2]));
ret.RL = add(ret.RL, mult(mult(L.RR, R.RL), C[L.hi][3]));
ret.RR = mult(mult(L.RL, R.LR), C[L.hi][0]);
ret.RR = add(ret.RR, mult(mult(L.RL, R.RR), C[L.hi][1]));
ret.RR = add(ret.RR, mult(mult(L.RR, R.LR), C[L.hi][2]));
ret.RR = add(ret.RR, mult(mult(L.RR, R.RR), C[L.hi][3]));
return ret;
}
void update(int first, int second) {
C[first][second] = 0;
first += POT;
first /= 2;
for (; first > 0; first >>= 1) tree[first] = merge(first);
}
int query() {
return add(add(tree[1].LL, tree[1].LR), add(tree[1].RL, tree[1].RR));
}
map<double, int> mapa;
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%d %d %d", X + i, V + i, P + i);
while (POT < n) POT <<= 1;
for (int i = 0; i < POT; i++)
C[i][0] = 1, C[i][1] = 1, C[i][2] = 1, C[i][3] = 1;
for (int i = 0; i < POT * 2; i++)
tree.push_back(Node(i - POT, i - POT, 0, 0, 0, 1));
for (int i = 0; i < n; i++)
tree[i + POT] =
Node(i, i, divide(sub(100, P[i]), 100), 0, 0, divide(P[i], 100));
for (int i = POT - 1; i >= 1; i--) tree[i] = merge(i);
vector<pair<double, pair<int, int>>> v;
for (int i = 0; i < n - 1; i++) {
double T1 = (double)((double)X[i + 1] - X[i]) / ((double)V[i] - V[i + 1]);
int t1 = divide(sub(X[i + 1], X[i]), sub(V[i], V[i + 1]));
int p1 = mult(divide(P[i], 100), divide(P[i + 1], 100));
double T2 = (double)((double)X[i + 1] - X[i]) / ((double)V[i + 1] - V[i]);
int t2 = divide(sub(X[i + 1], X[i]), sub(V[i + 1], V[i]));
int p2 = mult(divide(sub(100, P[i]), 100), divide(sub(100, P[i + 1]), 100));
double T3 = (double)((double)X[i + 1] - X[i]) / ((double)V[i] + V[i + 1]);
int t3 = divide(sub(X[i + 1], X[i]), add(V[i], V[i + 1]));
int p3 = mult(divide(P[i], 100), divide(sub(100, P[i + 1]), 100));
double T4 = (double)((double)X[i] - X[i + 1]) / ((double)V[i] + V[i + 1]);
int t4 = divide(sub(X[i], X[i + 1]), add(V[i], V[i + 1]));
int p4 = mult(divide(sub(100, P[i]), 100), divide(P[i + 1], 100));
TP[i][3] = {t1, p1};
TP[i][0] = {t2, p2};
TP[i][2] = {t3, p3};
TP[i][1] = {t4, p4};
if (T1 >= 0 && p1 > 0) v.push_back({T1, {i, 3}});
if (T2 >= 0 && p2 > 0) v.push_back({T2, {i, 0}});
if (T3 >= 0 && p3 > 0) v.push_back({T3, {i, 2}});
if (T4 >= 0 && p4 > 0) v.push_back({T4, {i, 1}});
}
if (v.size() == 0) {
printf("0\n");
return 0;
}
sort((v).begin(), (v).end());
int exp = 0;
for (pair<double, pair<int, int>> p : v) {
int first = query();
update(p.second.first, p.second.second);
first = sub(first, query());
exp = add(exp, mult(first, TP[p.second.first][p.second.second].first));
}
printf("%d\n", exp);
return 0;
}
| 10 | CPP |
#include <stdio.h>
int main(){
short n,a;
scanf("%hu",&n);
a=n%10;
if(a==2||a==4||a==5||a==7||a==9)printf("hon\n");
if(a==0||a==1||a==6||a==8)printf("pon\n");
if(a==3)printf("bon\n");
} | 0 | CPP |
import math
def na():
n = int(input())
b = [int(x) for x in input().split()]
return n,b
def nab():
n = int(input())
b = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]
return n,b,c
def dv():
n, m = map(int, input().split())
return n,m
def dva():
n, m = map(int, input().split())
b = [int(x) for x in input().split()]
return n,m,b
def nm():
n = int(input())
b = [int(x) for x in input().split()]
m = int(input())
c = [int(x) for x in input().split()]
return n,b,m,c
def dvs():
n = int(input())
m = int(input())
return n, m
n, a = na()
m, b = na()
a = sorted(a)
b = sorted(b)
sets = []
for i in range(n):
sets.append([])
for i in range(n):
for j in range(m):
if abs(a[i] - b[j]) < 2:
sets[i].append((b[j], j))
k = 0
f = False
used = []
usedm = []
ss = 0
while not f and k != n and k != m:
f = True
for i in range(n):
if len(sets[i]) != 0:
for j in sets[i]:
if j[1] not in used and i not in usedm:
used.append(j[1])
usedm.append(i)
k += 1
f = False
sets[i].remove(j)
for _ in range(n):
if j in sets[_]:
sets[_].remove(j)
ss += 1
print(k)
| 8 | PYTHON3 |
class CodeforcesTask798BSolution:
def __init__(self):
self.result = ''
self.n = 0
self.strings = []
def read_input(self):
self.n = int(input())
for x in range(self.n):
self.strings.append(list(input()))
def process_task(self):
states = []
for x in range(len(self.strings[0])):
states.append("".join(self.strings[0][x:] + self.strings[0][:x]))
to_be = set(states)
can = True
for string in self.strings:
if "".join(string) not in to_be:
can = False
break
if can:
costs = {}
for x in range(len(states)):
if states[x] not in costs:
costs[states[x]] = x
for string in self.strings[1:]:
lstates = []
for x in range(len(string)):
lstates.append("".join(string[x:] + string[:x]))
lcosts = {}
for x in range(len(lstates)):
if lstates[x] not in lcosts:
lcosts[lstates[x]] = x
for key, value in lcosts.items():
costs[key] += value
mn = 51 ** 2
for key, value in costs.items():
mn = min(mn, value)
self.result = str(mn)
else:
self.result = "-1"
def get_result(self):
return self.result
if __name__ == "__main__":
Solution = CodeforcesTask798BSolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())
| 8 | PYTHON3 |
# ===============================================================================================
# importing some useful libraries.
from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import *
from copy import *
from collections import deque
from collections import Counter as counter # Counter(list) return a dict with {key: count}
from itertools import combinations as comb # if a = [1,2,3] then print(list(comb(a,2))) -----> [(1, 2), (1, 3), (2, 3)]
from itertools import permutations as permutate
from bisect import bisect_left as bl
# If the element is already present in the list,
# the left most position where element has to be inserted is returned.
from bisect import bisect_right as br
from bisect import bisect
# If the element is already present in the list,
# the right most position where element has to be inserted is returned
# ==============================================================================================
# fast I/O region
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
def print(*args, **kwargs):
"""Prints the values to a stream, or to sys.stdout by default."""
sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
at_start = True
for x in args:
if not at_start:
file.write(sep)
file.write(str(x))
at_start = False
file.write(kwargs.pop("end", "\n"))
if kwargs.pop("flush", False):
file.flush()
if sys.version_info[0] < 3:
sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
# inp = lambda: sys.stdin.readline().rstrip("\r\n")
# ===============================================================================================
### START ITERATE RECURSION ###
from types import GeneratorType
def iterative(f, stack=[]):
def wrapped_func(*args, **kwargs):
if stack: return f(*args, **kwargs)
to = f(*args, **kwargs)
while True:
if type(to) is GeneratorType:
stack.append(to)
to = next(to)
continue
stack.pop()
if not stack: break
to = stack[-1].send(to)
return to
return wrapped_func
#### END ITERATE RECURSION ####
# ===============================================================================================
# some shortcuts
mod = 1000000007
def inp(): return sys.stdin.readline().rstrip("\r\n") # for fast input
def out(var): sys.stdout.write(str(var)) # for fast output, always take string
def lis(): return list(map(int, inp().split()))
def stringlis(): return list(map(str, inp().split()))
def sep(): return map(int, inp().split())
def strsep(): return map(str, inp().split())
def zerolist(n): return [0] * n
def nextline(): out("\n") # as stdout.write always print sring.
def testcase(t):
for p in range(t):
solve()
def printlist(a):
for p in range(0, len(a)):
out(str(a[p]) + ' ')
def solve():
def isvalid(i,j):
if 0<=i<n and 0<=j<n and ar[i][j]==".":
return 1
return 0
n=int(inp())
ar=[]
for _ in range(n):
temp=inp()
t=[]
for i in temp:
t.append(i)
ar.append(t)
tr=1
for i in range(n):
for j in range(n):
if ar[i][j]==".":
if isvalid(i+1,j) and isvalid(i+2,j) and isvalid(i+1,j-1) and isvalid(i+1,j+1):
ar[i][j]="#"
ar[i+1][j] = "#"
ar[i+2][j] = "#"
ar[i+1][j-1] = "#"
ar[i+1][j+1] = "#"
else:
tr=-1
print("NO")
exit()
print("YES")
solve() | 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, m, x, y;
cin >> n >> m;
for (long long i = 0; i < m; i++) cin >> x >> y;
long long ans = 1;
for (long long i = 0; i < n; i++) {
if (i % 2 == 0)
cout << "0";
else
cout << "1";
}
cout << endl;
return 0;
}
| 8 | CPP |
MAXN = 10001
z = 0
n = int(input())
a = [4,7,44,47,74,77,444,447,474,477,744,747,774,777,4444,4447,4474,4477,4744,4747,4774,4777,7444,7447,7474,7477,7744,7747,7774,7777,44444,44447,44474,44477,44744,44747,44774,44777,47444,47447,47474,47477,47744,47747,47774,47777,74444,74447,74474,74477,74744,74747,74774,74777,77444,77447,77474,77477,77744,77747,77774,77777,444444,444447,444474,444477,444744,444747,444774,444777,447444,447447,447474,447477,447744,447747,447774,447777,474444,474447,474474,474477,474744,474747,474774,474777,477444,477447,477474,477477,477744,477747,477774,477777,744444,744447,744474,744477,744744,744747,744774,744777,747444,747447,747474,747477,747744,747747,747774,747777,774444,774447,774474,774477,774744,774747,774774,774777,777444,777447,777474,777477,777744,777747,777774,777777,4444444,4444447,4444474,4444477,4444744,4444747,4444774,4444777,4447444,4447447,4447474,4447477,4447744,4447747,4447774,4447777,4474444,4474447,4474474,4474477,4474744,4474747,4474774,4474777,4477444,4477447,4477474,4477477,4477744,4477747,4477774,4477777,4744444,4744447,4744474,4744477,4744744,4744747,4744774,4744777,4747444,4747447,4747474,4747477,4747744,4747747,4747774,4747777,4774444,4774447,4774474,4774477,4774744,4774747,4774774,4774777,4777444,4777447,4777474,4777477,4777744,4777747,4777774,4777777,7444444,7444447,7444474,7444477,7444744,7444747,7444774,7444777,7447444,7447447,7447474,7447477,7447744,7447747,7447774,7447777,7474444,7474447,7474474,7474477,7474744,7474747,7474774,7474777,7477444,7477447,7477474,7477477,7477744,7477747,7477774,7477777,7744444,7744447,7744474,7744477,7744744,7744747,7744774,7744777,7747444,7747447,7747474,7747477,7747744,7747747,7747774,7747777,7774444,7774447,7774474,7774477,7774744,7774747,7774774,7774777,7777444,7777447,7777474,7777477,7777744,7777747,7777774,7777777,44444444,44444447,44444474,44444477,44444744,44444747,44444774,44444777,44447444,44447447,44447474,44447477,44447744,44447747,44447774,44447777,44474444,44474447,44474474,44474477,44474744,44474747,44474774,44474777,44477444,44477447,44477474,44477477,44477744,44477747,44477774,44477777,44744444,44744447,44744474,44744477,44744744,44744747,44744774,44744777,44747444,44747447,44747474,44747477,44747744,44747747,44747774,44747777,44774444,44774447,44774474,44774477,44774744,44774747,44774774,44774777,44777444,44777447,44777474,44777477,44777744,44777747,44777774,44777777,47444444,47444447,47444474,47444477,47444744,47444747,47444774,47444777,47447444,47447447,47447474,47447477,47447744,47447747,47447774,47447777,47474444,47474447,47474474,47474477,47474744,47474747,47474774,47474777,47477444,47477447,47477474,47477477,47477744,47477747,47477774,47477777,47744444,47744447,47744474,47744477,47744744,47744747,47744774,47744777,47747444,47747447,47747474,47747477,47747744,47747747,47747774,47747777,47774444,47774447,47774474,47774477,47774744,47774747,47774774,47774777,47777444,47777447,47777474,47777477,47777744,47777747,47777774,47777777,74444444,74444447,74444474,74444477,74444744,74444747,74444774,74444777,74447444,74447447,74447474,74447477,74447744,74447747,74447774,74447777,74474444,74474447,74474474,74474477,74474744,74474747,74474774,74474777,74477444,74477447,74477474,74477477,74477744,74477747,74477774,74477777,74744444,74744447,74744474,74744477,74744744,74744747,74744774,74744777,74747444,74747447,74747474,74747477,74747744,74747747,74747774,74747777,74774444,74774447,74774474,74774477,74774744,74774747,74774774,74774777,74777444,74777447,74777474,74777477,74777744,74777747,74777774,74777777,77444444,77444447,77444474,77444477,77444744,77444747,77444774,77444777,77447444,77447447,77447474,77447477,77447744,77447747,77447774,77447777,77474444,77474447,77474474,77474477,77474744,77474747,77474774,77474777,77477444,77477447,77477474,77477477,77477744,77477747,77477774,77477777,77744444,77744447,77744474,77744477,77744744,77744747,77744774,77744777,77747444,77747447,77747474,77747477,77747744,77747747,77747774,77747777,77774444,77774447,77774474,77774477,77774744,77774747,77774774,77774777,77777444,77777447,77777474,77777477,77777744,77777747,77777774,77777777,444444444,444444447,444444474,444444477,444444744,444444747,444444774,444444777,444447444,444447447,444447474,444447477,444447744,444447747,444447774,444447777,444474444,444474447,444474474,444474477,444474744,444474747,444474774,444474777,444477444,444477447,444477474,444477477,444477744,444477747,444477774,444477777,444744444,444744447,444744474,444744477,444744744,444744747,444744774,444744777,444747444,444747447,444747474,444747477,444747744,444747747,444747774,444747777,444774444,444774447,444774474,444774477,444774744,444774747,444774774,444774777,444777444,444777447,444777474,444777477,444777744,444777747,444777774,444777777,447444444,447444447,447444474,447444477,447444744,447444747,447444774,447444777,447447444,447447447,447447474,447447477,447447744,447447747,447447774,447447777,447474444,447474447,447474474,447474477,447474744,447474747,447474774,447474777,447477444,447477447,447477474,447477477,447477744,447477747,447477774,447477777,447744444,447744447,447744474,447744477,447744744,447744747,447744774,447744777,447747444,447747447,447747474,447747477,447747744,447747747,447747774,447747777,447774444,447774447,447774474,447774477,447774744,447774747,447774774,447774777,447777444,447777447,447777474,447777477,447777744,447777747,447777774,447777777,474444444,474444447,474444474,474444477,474444744,474444747,474444774,474444777,474447444,474447447,474447474,474447477,474447744,474447747,474447774,474447777,474474444,474474447,474474474,474474477,474474744,474474747,474474774,474474777,474477444,474477447,474477474,474477477,474477744,474477747,474477774,474477777,474744444,474744447,474744474,474744477,474744744,474744747,474744774,474744777,474747444,474747447,474747474,474747477,474747744,474747747,474747774,474747777,474774444,474774447,474774474,474774477,474774744,474774747,474774774,474774777,474777444,474777447,474777474,474777477,474777744,474777747,474777774,474777777,477444444,477444447,477444474,477444477,477444744,477444747,477444774,477444777,477447444,477447447,477447474,477447477,477447744,477447747,477447774,477447777,477474444,477474447,477474474,477474477,477474744,477474747,477474774,477474777,477477444,477477447,477477474,477477477,477477744,477477747,477477774,477477777,477744444,477744447,477744474,477744477,477744744,477744747,477744774,477744777,477747444,477747447,477747474,477747477,477747744,477747747,477747774,477747777,477774444,477774447,477774474,477774477,477774744,477774747,477774774,477774777,477777444,477777447,477777474,477777477,477777744,477777747,477777774,477777777,744444444,744444447,744444474,744444477,744444744,744444747,744444774,744444777,744447444,744447447,744447474,744447477,744447744,744447747,744447774,744447777,744474444,744474447,744474474,744474477,744474744,744474747,744474774,744474777,744477444,744477447,744477474,744477477,744477744,744477747,744477774,744477777,744744444,744744447,744744474,744744477,744744744,744744747,744744774,744744777,744747444,744747447,744747474,744747477,744747744,744747747,744747774,744747777,744774444,744774447,744774474,744774477,744774744,744774747,744774774,744774777,744777444,744777447,744777474,744777477,744777744,744777747,744777774,744777777,747444444,747444447,747444474,747444477,747444744,747444747,747444774,747444777,747447444,747447447,747447474,747447477,747447744,747447747,747447774,747447777,747474444,747474447,747474474,747474477,747474744,747474747,747474774,747474777,747477444,747477447,747477474,747477477,747477744,747477747,747477774,747477777,747744444,747744447,747744474,747744477,747744744,747744747,747744774,747744777,747747444,747747447,747747474,747747477,747747744,747747747,747747774,747747777,747774444,747774447,747774474,747774477,747774744,747774747,747774774,747774777,747777444,747777447,747777474,747777477,747777744,747777747,747777774,747777777,774444444,774444447,774444474,774444477,774444744,774444747,774444774,774444777,774447444,774447447,774447474,774447477,774447744,774447747,774447774,774447777,774474444,774474447,774474474,774474477,774474744,774474747,774474774,774474777,774477444,774477447,774477474,774477477,774477744,774477747,774477774,774477777,774744444,774744447,774744474,774744477,774744744,774744747,774744774,774744777,774747444,774747447,774747474,774747477,774747744,774747747,774747774,774747777,774774444,774774447,774774474,774774477,774774744,774774747,774774774,774774777,774777444,774777447,774777474,774777477,774777744,774777747,774777774,774777777,777444444,777444447,777444474,777444477,777444744,777444747,777444774,777444777,777447444,777447447,777447474,777447477,777447744,777447747,777447774,777447777,777474444,777474447,777474474,777474477,777474744,777474747,777474774,777474777,777477444,777477447,777477474,777477477,777477744,777477747,777477774,777477777,777744444,777744447,777744474,777744477,777744744,777744747,777744774,777744777,777747444,777747447,777747474,777747477,777747744,777747747,777747774,777747777,777774444,777774447,777774474,777774477,777774744,777774747,777774774,777774777,777777444,777777447,777777474,777777477,777777744,777777747,777777774,777777777]
for i in range (MAXN) :
if(a[i] == n) :
print(i + 1)
break;
| 8 | PYTHON3 |
#include <iostream>
#include <vector>
int main() {
int n, q;
std::cin >> n >> q;
std::vector<long long int> a(n + 1, 0);
for (auto i = 1; i <= n; ++i)
std::cin >> a[i];
for (auto i = 1; i <= n; ++i)
a[i] += a[i - 1];
for (auto i = 0; i < q; ++i) {
int left{ 0 }, right{ 0 };
long long int sum{ 0 }, x;
std::cin >> x;
while (left <= n) {
while (right <= n && a[right] - a[left] <= x) {
++right;
}
sum += right - ++left;
}
std::cout << sum << std::endl;
}
}
| 0 | CPP |
given = input()
vowels = 'AEIOUYaeiouy'
ans = []
for char in given:
if char not in vowels:
ans.append('.'+char.lower())
print(''.join(ans)) | 7 | PYTHON3 |
A = int(input())
B = int(input())
print(['LESS', 'EQUAL', 'GREATER'][(A >= B)+(A > B)])
| 0 | PYTHON3 |
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i < (int)(n);i++)
int main(){
int N;
int x = 0;
cin >> N;
vector<int>L(N);
rep(i,N)
cin >> L.at(i);
sort(L.begin(),L.end());
rep(i,N)
rep(j,i)
rep(k,j)
if(L.at(j) != L.at(k) && L.at(i) != L.at(k) && L.at(i) != L.at(j)){
if (L.at(i) < L.at(k)+L.at(j)){
x++;
}
}
cout << x;
} | 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1001 * 101, MOD = 1e9 + 7;
int a[MAXN] = {};
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i];
for (int k = 1; k < n; k++) {
int ans = 0, kj, j = 0, x = 0;
for (int i = 1; i <= k; i++) {
j = i;
kj = 20;
x = 0;
;
while (j <= k) {
if (j + (1 << kj) <= n) {
j += 1 << kj;
x++;
}
kj--;
}
ans += x * a[i - 1];
}
cout << ans << '\n';
}
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t;
cin >> t;
while (t--) {
long long n, k, flag = 1, i, j, temp;
cin >> n;
vector<long long> v[n];
long long g[n], b[n];
for (i = 0; i < n; i++) {
g[i] = -1;
b[i] = -1;
}
for (i = 0; i < n; i++) {
cin >> k;
long long f = 1;
for (j = 0; j < k; j++) {
cin >> temp;
if (g[temp - 1] == -1 && f == 1) {
b[i] = 1;
g[temp - 1] = 1;
f = 0;
}
}
}
for (i = 0; i < n; i++) {
if (b[i] == -1) {
flag = 0;
break;
}
}
for (j = 0; j < n; j++) {
if (g[j] == -1) break;
}
if (flag == 0) {
cout << "IMPROVE" << endl;
cout << i + 1 << " " << j + 1 << endl;
} else
cout << "OPTIMAL" << endl;
}
return 0;
}
| 8 | CPP |
n = int(input())
list1 = [int(i) for i in input().split()]
list2 = []
for i in range(0,len(list1) ):
list2.append([list1[i], i+1])
l2 = sorted(list2, reverse = True)
#print(l2)
count = 0
for i in range(0,len(l2)):
count = count + (l2[i][0] * (i)) + 1
print(count)
for i in range(len(l2)):
print(l2[i][1], end = ' ')
| 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
int main() {
lint x;
cin >> x;
lint cnt = x/100;
cout << (x - cnt * 100 <= 5 * cnt) << endl;
} | 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 5e4 + 10;
int n, B, K, x;
int a[N];
int cnt[1000];
long long ways[1000];
struct matrix {
long long mat[101][101];
};
matrix mul(matrix A, matrix B) {
matrix ret;
for (int i = 0; i < K; i++) {
for (int j = 0; j < K; j++) {
ret.mat[i][j] = 0;
for (int k = 0; k < K; k++) {
ret.mat[i][j] += (A.mat[i][k] * B.mat[k][j]) % 1000000007;
if (ret.mat[i][j] >= 1000000007) ret.mat[i][j] -= 1000000007;
}
}
}
return ret;
}
matrix pow(matrix A, long long p) {
if (p == 1) return A;
matrix ret = pow(A, p / 2);
ret = mul(ret, ret);
if (p & 1) ret = mul(ret, A);
return ret;
}
matrix Transition;
inline void createTransform(void) {
for (int j = 0; j < K; j++) {
for (int i = 0; i < K; i++) {
Transition.mat[i][j] = 0;
for (int k = 0; k < K; k++) {
if ((10 * i + k) % K == j) Transition.mat[i][j] = cnt[k];
}
}
}
return;
}
int main() {
cin >> n >> B >> x >> K;
for (int i = 0; i < n; i++) {
cin >> a[i];
cnt[a[i] % K]++;
}
createTransform();
matrix x1;
x1 = pow(Transition, B);
long long ans = x1.mat[0][x];
cout << ans;
return 0;
}
| 11 | CPP |
import sys,math,string,bisect
input=sys.stdin.readline
from collections import deque
L=lambda : list(map(int,input().split()))
Ls=lambda : list(input().split())
M=lambda : map(int,input().split())
I=lambda :int(input())
n=I()
l=[]
m=10**5
key=0
for i in range(n):
a,b=M()
if(a!=b):
print("Happy Alex")
exit()
print("Poor Alex")
| 7 | PYTHON3 |
def operation(string,current_value):
if (string == '+'):
current_value = current_value + 1
else:
current_value = current_value - 1
return current_value
n = int(input())
if (n>=1 and n<=150):
op = list()
res = 0
for i in range(n):
s = str(input())
op.append(s)
res = operation(op[i][1],res)
print(res)
else:
quit()
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int s = 0, t = 1;
char c = getchar();
while (!isdigit(c)) {
if (c == '-') t = -1;
c = getchar();
}
while (isdigit(c)) s = s * 10 + c - 48, c = getchar();
return s * t;
}
const int maxn = 2e5 + 5;
struct node {
int v, t;
bool operator<(const node& rhs) const { return v < rhs.v; }
} A[maxn];
int tot = 0, n, m;
int v[maxn], q[maxn];
inline int find(int val) {
if (val > A[n].v && val < A[1].v) return 0;
int l = 1, r = n, mid;
while (l < r) {
mid = (l + r) >> 1;
if (A[mid].v >= val)
r = mid;
else
l = mid + 1;
}
return A[l].v == val;
}
int main() {
n = read(), m = read();
for (register int i = 1; i <= n; i++) v[i] = A[A[i].t = i].v = read();
sort(A + 1, A + n + 1);
int add = 0, oven = 0;
if (A[1].v & 1)
add++;
else
oven++;
for (register int i = 2; i <= n; i++) {
if (A[i].v == A[i - 1].v)
v[q[++tot] = A[i].t] = -1;
else {
if (A[i].v & 1)
add++;
else
oven++;
}
}
if (add > n / 2) {
for (register int i = 1; i <= n; i++) {
if (v[i] != -1 && (v[i] & 1)) v[q[++tot] = i] = -1, add--;
if (add == n / 2) break;
}
} else if (oven > n / 2) {
for (register int i = 1; i <= n; i++) {
if (v[i] != -1 && !(v[i] & 1)) v[q[++tot] = i] = -1, oven--;
if (oven == n / 2) break;
}
}
int x = 1, ans = tot;
while (tot && x <= m) {
if ((x & 1) && add < n / 2) {
if (!find(x)) v[q[tot--]] = x, add++;
} else if (!(x & 1) && oven < n / 2) {
if (!find(x)) v[q[tot--]] = x, oven++;
}
x++;
}
if (tot)
puts("-1");
else {
printf("%d\n", ans);
for (register int i = 1; i <= n - 1; i++) printf("%d ", v[i]);
printf("%d\n", v[n]);
}
return 0;
}
| 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i, j, sum = 0, num;
cin >> n;
char a[n][n];
for (i = 0; i < n; i++) {
num = 0;
for (j = 0; j < n; j++) {
cin >> a[i][j];
if (a[i][j] == 'C') {
num++;
}
}
sum = sum + (num * (num - 1)) / 2;
}
for (i = 0; i < n; i++) {
num = 0;
for (j = 0; j < n; j++) {
if (a[j][i] == 'C') {
num++;
}
}
sum = sum + (num * (num - 1)) / 2;
}
cout << sum << endl;
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
long long binpow(long long base, long long exp, int mod) {
long long res = 1;
while (exp > 0) {
if (exp % 2 == 1) res = (res * base) % mod;
exp = exp >> 1;
base = (base * base) % mod;
}
return res;
}
long long mod(long long x) {
return ((x % 1000000007LL + 1000000007LL) % 1000000007LL);
}
long long add(long long a, long long b) { return mod(mod(a) + mod(b)); }
long long mul(long long a, long long b) { return mod(mod(a) * mod(b)); }
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
;
long long int t;
cin >> t;
while (t--) {
long long int k;
cin >> k;
long long int arr[7];
for (int i = 0; i < 7; i++) cin >> arr[i];
long long int count = 0;
for (int i = 0; i < 7; i++) {
if (arr[i] == 1) {
count++;
}
}
if (k <= count) {
long long int ans = 1e9 + 5;
for (int i = 0; i < 7; i++) {
long long int check = k, temp = 0;
for (int j = 0; j < 7; j++) {
if (arr[(i + j) % 7] == 1) {
check--;
}
temp++;
if (check == 0) {
break;
}
}
ans = min(ans, temp);
}
cout << ans << "\n";
} else {
long long int ans1, ans = 1e9 + 5;
if (k % count == 0) {
ans1 = ((k - count) / count) * 7;
k = count;
} else {
ans1 = (k / count) * 7;
k = k % count;
}
for (int i = 0; i < 7; i++) {
long long int check = k, temp = 0;
for (int j = 0; j < 7; j++) {
if (arr[(i + j) % 7] == 1) {
check--;
}
temp++;
if (check == 0) {
break;
}
}
ans = min(ans, temp);
}
cout << ans + ans1 << "\n";
}
}
return 0;
}
| 13 | CPP |
a, b, c = map(int, input().split())
if c == 0:
if a == b:
print("YES")
else:
print("NO")
else:
d, r = divmod(b - a, c)
if a == b:
print("YES")
else:
if d < 1 or r != 0:
print("NO")
else:
print("YES") | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t, a, b, c;
cin >> t;
while (t--) {
cin >> a >> b >> c;
if (a < c) {
if (b * a <= c) {
cout << 1 << " " << -1 << endl;
} else {
cout << 1 << " " << b << endl;
}
} else if (a == c) {
if (b == 1) {
cout << -1 << " " << -1 << endl;
} else {
cout << -1 << " " << b << endl;
}
} else {
cout << -1 << " " << b << endl;
}
}
}
| 7 | CPP |
import sys
import math
import collections
from collections import deque
#sys.stdin = open('input.txt', 'r')
#sys.stdout = open('output.txt', 'w')
from functools import reduce
from sys import stdin, stdout, setrecursionlimit
setrecursionlimit(2**20)
def factors(n):
return list(set(reduce(list.__add__,
([i, n // i] for i in range(1, int(n**0.5) + 1) if n % i == 0))))
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
# for _ in range(int(stdin.readline())):
n = int(stdin.readline().strip('\n'))
#b = str(stdin.readline().strip('\n'))
a = list(map(int, stdin.readline().split()))
#n, m = list(map(int, stdin.readline().split()))
#s = list(str(stdin.readline().strip('\n')))
#n = len(a)
b = a.index(max(a)) + a[::-1].index(min(a))
print(b - (b >= n))
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
vector<int> vec[1000005][10], rms[10];
int col[1000005], dist[1000005];
vector<int> getDigits(int x) {
vector<int> ans;
while (x) ans.push_back(x % 10), x /= 10;
reverse(ans.begin(), ans.end());
return ans;
}
int main() {
int n, m;
scanf("%d %d", &n, &m);
int curn = n;
for (int i = 1; i <= m; i++) {
int x, y;
scanf("%d %d", &x, &y);
vector<int> digits = getDigits(i);
if (digits.size() == 1) {
vec[x][digits[0]].push_back(y);
vec[y][digits[0]].push_back(x);
} else {
vec[x][digits[0]].push_back(++curn);
for (int i = 1; i + 1 < digits.size(); i++) {
vec[curn][digits[i]].push_back(curn + 1);
curn++;
}
vec[curn][digits[digits.size() - 1]].push_back(y);
vec[y][digits[0]].push_back(++curn);
for (int i = 1; i + 1 < digits.size(); i++) {
vec[curn][digits[i]].push_back(curn + 1);
curn++;
}
vec[curn][digits[digits.size() - 1]].push_back(x);
}
}
assert(curn < 1000005);
queue<vector<int> > qu;
col[1] = 1;
vector<int> vv;
vv.push_back(1);
qu.push(vv);
while (!qu.empty()) {
vector<int> curv = qu.front();
qu.pop();
for (int i = 0; i < 10; i++) {
for (int u : curv) {
for (int v : vec[u][i]) {
if (col[v]) continue;
dist[v] = (1LL * dist[u] * 10 + i) % 1000000007, col[v] = 1;
rms[i].push_back(v);
}
}
}
for (int i = 0; i < 10; i++) {
if (rms[i].size()) {
qu.push(rms[i]);
rms[i].clear();
}
}
}
for (int i = 2; i <= n; i++) printf("%d\n", dist[i]);
return 0;
}
| 12 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
int a[n][m], used = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> a[i][j];
if (a[i][j] == 1)
if (i == 0 or j == 0 or j == m - 1 or i == n - 1) {
used = 1;
}
}
}
if (used == 1)
cout << 2;
else
cout << 4;
}
| 7 | CPP |
def main():
n, m = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
delim = 0
for i, e in enumerate(a):
e += delim
p, delim = divmod(e, m)
print(p, end=' ')
print()
if __name__ == '__main__':
main()
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
bool sortbysec(const pair<long long, long long> &a,
const pair<long long, long long> &b) {
if (a.first > b.first) {
return true;
} else {
return false;
}
}
void solve() {
int n;
cin >> n;
vector<int> v(n), pre;
for (int i = 0; i < n; i++) cin >> v[i];
for (int i = 0; i < n; i += 2) {
pre.push_back(v[i]);
}
for (int i = 1; i < n; i += 2) {
pre.push_back(v[i]);
}
for (int i = 0; i < n; i += 2) {
pre.push_back(v[i]);
}
int j = 0;
long long ans = 0, mx = 0;
while (j < (n + 1) / 2) {
ans += pre[j];
j++;
}
for (int i = 0; i < n; i++) {
mx = max(mx, ans);
ans -= pre[i];
ans += pre[j];
j++;
}
cout << mx << "\n";
}
int main() { solve(); }
| 10 | CPP |
for i in range(int(input())):
n=int(input())
a=list(map(int,input().split()))
ans=0
a.sort()
for num in range(2,2*n+1):
b=a[:]
c=0
while len(b)>1:
x=b[0]
if num-x in b[1:]:
y=b.index(num-x,1)
c+=1
del b[0]
del b[y-1]
else:
del b[0]
ans=max(ans,c)
print(ans)
| 9 | PYTHON3 |
a,b=map(int,input().split())
c=abs(a-b)
if a >=b:
print(b, end=" ")
else:
print(a,end=" ")
if c!=0:
print(c//2)
else:
print(0) | 7 | PYTHON3 |
import sys
dr = [0, 1, 0, -1]
dc = [1, 0, -1, 0]
rows, cols = map(int, sys.stdin.readline().split())
b = ['' for row in range(rows)]
sr, sc = 0, 0
er, ec = 0, 0
for row in range (rows):
b[row] = sys.stdin.readline().strip()
if 'S' in b[row]:
sr, sc = row, b[row].index('S')
if 'E' in b[row]:
er, ec = row, b[row].index('E')
dirs = sys.stdin.readline().strip()
res = 0
for i in range (4):
for j in range (4):
for k in range (4):
if j != i and i != k and j != k:
l = (0+1+2+3) - (i+j+k)
r, c = sr, sc
p = [i, j, k, l]
ok = 0
for d in dirs:
di = int(d)
r += dr[p[di]]
c += dc[p[di]]
if r < 0 or r >= rows or c < 0 or c >= cols or b[r][c] == '#':
break
if b[r][c] == 'E':
ok = 1
res += ok
print (res) | 8 | PYTHON3 |
n,k=map(int,input().split())
l=list(map(int,input().split()))
l=list(filter(lambda a:(5-a)>=k,l))
print(len(l)//3)
| 7 | PYTHON3 |
import statistics
from statistics import mode
for t in range(int(input())):
arr=list(map(int,input().split()))
if len(arr)==len(set(arr)):
print("NO")
elif len(set(arr))==1:
print("YES")
print(*arr)
else:
number=mode(arr)
for i in range(3):
if arr[i]!=number:
n2=arr[i]
if number<n2:
print("NO")
else:
print("YES")
print(str(n2)+" "+str(n2)+" "+str(number)) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int n;
const int maxn = 100030;
int a[maxn], b[maxn];
int main() {
cin >> n;
if ((!(n & 1)))
cout << -1 << endl;
else {
for (int i = 0; i < n; i++) {
printf("%d%s", i, i == n - 1 ? "\n" : " ");
a[i] = i;
}
for (int i = 0; i < n; i++) {
printf("%d%s", (i + 1) % n, i == n - 1 ? "\n" : " ");
b[i] = (i + 1) % n;
}
for (int i = 0; i < n; i++) {
printf("%d%s", (a[i] + b[i]) % n, i == n - 1 ? "\n" : " ");
}
}
return 0;
}
| 7 | CPP |
t = int(input()) # количество наборов входных данных в тесте
lengths = []
for i_t in range(t):
n = int(input())
for i_n in range(n):
left, right = input().split()
left = int(left)
right = int(right)
if i_n == 0:
left_common = left
right_common = right
flag = True
else:
if flag:
if left_common < left < right_common:
left_common = left
if left_common < right < right_common:
right_common = right
if right == left_common:
flag = False
left_common = right_common = right
elif right < left_common:
flag = False
right_common, left_common = left_common, right
if left == right_common:
flag = False
left_common = right_common = left
elif right_common < left:
flag = False
left_common, right_common = right_common, left
else:
if left_common > right:
left_common = right
if right_common < left:
right_common = left
if flag:
lengths.append(0)
else:
lengths.append(right_common - left_common)
for length in lengths:
print(length)
| 7 | PYTHON3 |
#include "bits/stdc++.h"
using namespace std;
//#define int long long
#define DEBUG 0
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define dump(o) if(DEBUG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DEBUG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
using ll = long long; using ull = unsigned long long; using pii = pair<int, int>;
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
static const int MOD = 1e9 + 7;
signed main() {
for (int K; cin >> K&&K;) {
int sum = 0;
rep(i, 0, K*(K - 1) / 2) { int c; cin >> c; sum += c; }
cout << sum / (K - 1) << endl;
}
return 0;
} | 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
const long long N = 3e5 + 10;
const long long INF = 2e9;
long long n, k;
long long l[N], r[N];
long long delta[N];
vector<pair<long long, long long> > a[N];
struct segment {
long long l, r, val;
};
bool operator<(segment a, segment b) { return a.l < b.l; }
multiset<segment> S;
template <typename T>
inline void chkmin(T &x, T y) {
x = min(x, y);
}
template <typename T>
inline void chkmax(T &x, T y) {
x = max(x, y);
}
template <typename T>
inline void read(T &x) {
T f = 1;
x = 0;
char c = getchar();
for (; !isdigit(c); c = getchar())
if (c == '-') f = -f;
for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + c - '0';
x *= f;
}
inline long long cnt(long long mid) {
memset(delta, 0, sizeof(delta));
long long ans = 0, now = 0, l = 1;
for (long long i = 1; i <= n; ++i) {
unsigned j = 0;
while (j < a[i].size() && a[i][j].first <= l) now += a[i][j++].second;
while (l <= i && now >= mid) {
now += delta[++l];
while (j < a[i].size() && a[i][j].first <= l) now += a[i][j++].second;
}
ans += l - 1;
while (j < a[i].size()) delta[a[i][j].first] += a[i][j].second, ++j;
if (ans > INF) return INF;
}
return ans;
}
inline long long sum(long long mid) {
memset(delta, 0, sizeof(delta));
long long ans = 0, now = 0;
long long l = 1;
for (long long i = 1; i <= n; ++i) {
unsigned j = 0;
while (j < a[i].size() && a[i][j].first <= l) {
ans += 1LL * (n - i + 1) * (l - a[i][j].first) * a[i][j].second;
now += a[i][j++].second;
}
while (l <= i && now >= mid) {
ans += 1LL * (n - i + 1) * now;
now += delta[++l];
while (j < a[i].size() && a[i][j].first <= l) now += a[i][j++].second;
}
while (j < a[i].size()) delta[a[i][j].first] += a[i][j].second, ++j;
}
return ans;
}
signed main() {
read(n);
read(k);
for (long long i = 1; i <= n; ++i) {
read(l[i]);
read(r[i]);
--r[i];
}
S.insert((segment){1, INF, 0});
for (long long i = 1; i <= n; ++i) {
multiset<segment>::iterator it = S.upper_bound((segment){l[i], 0, 0});
long long ql = l[i], qr = r[i], vl = i, vr = i;
if (--it != S.end()) {
ql = (*it).l;
vl = (*it).val;
}
while (it != S.end() && (*it).l <= r[i]) {
if ((*it).r >= r[i]) {
qr = (*it).r;
vr = (*it).val;
}
multiset<segment>::iterator tmp = it;
a[i].push_back(make_pair((*tmp).val + 1, (*tmp).r - (*tmp).l + 1));
++it;
S.erase(tmp);
}
if (ql ^ l[i]) {
S.insert((segment){ql, l[i] - 1, vl});
a[i].push_back(make_pair(vl + 1, ql - l[i]));
}
if (qr ^ r[i]) {
S.insert((segment){r[i] + 1, qr, vr});
a[i].push_back(make_pair(vr + 1, r[i] - qr));
}
S.insert((segment){l[i], r[i], i});
a[i].push_back(make_pair(i + 1, -(r[i] - l[i] + 1)));
sort(a[i].begin(), a[i].end());
}
long long l = 1, r = (long long)2e9, res = 0;
while (l <= r) {
long long mid = (l + r) >> 1;
if (cnt(mid) >= k) {
res = mid;
l = mid + 1;
} else
r = mid - 1;
}
long long ans = res * (k - cnt(res + 1));
printf("%lld\n", ans + sum(res + 1));
return 0;
}
| 10 | CPP |
#include<iostream>
int main(){int t[31],w=1,n,a,b,c;for(;w<31;)t[w]=w++;for(std::cin>>w>>n;n--;){(std::cin>>a).ignore(1)>>b;c=t[a];t[a]=t[b];t[b]=c;}for(n=1;n<w+1;)std::cout<<t[n++]<<'\n';} | 0 | CPP |
for _ in range (int(input())) :
n =int(input())
l =[int(x) for x in input().split()]
for i in range (n) :
l[i] = (i+l[i])%n
if len(set(l)) == n :
print("YES")
else :
print("NO") | 7 | PYTHON3 |
Subsets and Splits