solution
stringlengths 10
983k
| difficulty
int64 0
25
| language
stringclasses 2
values |
---|---|---|
#include <bits/stdc++.h>
using namespace std;
int a[300005];
int main() {
int n, i, k, m;
scanf("%d", &n);
int max = 0;
for (i = 0; i < n; ++i) {
scanf("%d", &k);
m = 2 * k + abs(2 * i - n + 1);
a[m]++;
if (m >= (n + 1) && a[m] > max) max = a[m];
}
printf("%d", n - max);
return 0;
}
| 9 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
double p;
cin >> p;
double last = p, ans = p;
n--;
while (n--) {
cin >> p;
ans += (2 * last + 1) * p;
last = (last + 1) * p;
}
printf("%.10lf\n", ans);
return 0;
}
| 8 | CPP |
#include<iostream>
#include<queue>
#include<vector>
#include<set>
#include<cmath>
#include<algorithm>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n) REP(i,0,n)
const double eps = 1e-7;
#define MAX 250
#define INF (1<<21)
double edge[MAX][MAX];
int cap[MAX][MAX];
int tcap[MAX][MAX];
bool visited[MAX];
int parent[MAX];
int flow[MAX][MAX];
int layer[MAX];
void make_layer(int n,int s,int t){
queue<int> Q;
Q.push(s);
layer[s]=0;
while(!Q.empty()){
int now = Q.front();
Q.pop();
rep(i,n){
if ( cap[now][i]-flow[now][i] >0 && layer[i] ==-1){
layer[i]=layer[now]+1;
Q.push(i);
}
}
}
}
int augment(int now,int t,int n,int f){
if (now == t || f == 0)return f;
if ( visited[now] == true)return 0;
rep(i,n){
if (layer[now]<layer[i]){
int tmp= augment(i,t,n,min(f,cap[now][i]-flow[now][i]));
if( tmp>0){
flow[now][i]+=tmp;
flow[i][now]=-flow[now][i];
visited[now]=false;
return tmp;
}
}
}
return 0;
}
int dinic(int n,int s,int t,double time){
int ansflow=0;
bool flag=true;
rep(i,n){
rep(j,n){
if( edge[i][j]<eps+time)cap[i][j]=tcap[i][j],flow[i][j]=0;
else cap[i][j]=0,flow[i][j]=0;
}
}
while(flag){
fill(layer,layer+n,-1);
fill(visited,visited+n,false);
make_layer(n,s,t);
if ( layer[t] == -1)break;
for(int f=1;f;flag=true){
f=augment(s,t,n,INF);
if ( f == 0)break;
ansflow+=f;
}
}
return ansflow;
}
#define SUPERSOURCE 0
#define SUPERSINK 1
double solve(int n,vector<double> &v,int m){
int l=0,r=v.size()-1,ret=-1;
while(l<=r){
int mid = (r+l)/2;
if ( dinic(n,SUPERSOURCE,SUPERSINK,v[mid])==m )r=mid-1,ret=mid;
else l=mid+1;
}
return v[ret];
}
class Double{
public:
double b;
bool operator<(const Double & a)const{
if ( abs(b-a.b)<eps)return false;
else return b < a.b;
}
};
inline double calc_dist(double x,double y,double v){
return sqrt(x*x+y*y)/v;
}
int main(){
int n,m;
while(cin>>n>>m && n){
double xt[n],yt[n],v[n],xbase[n],ybase[n];
rep(i,n)cin>>xt[i]>>yt[i]>>v[i];
rep(i,m)cin>>xbase[i]>>ybase[i];
int node = 2+n+m;
rep(i,node)rep(j,node)edge[i][j]=INF,tcap[i][j]=0;
set<Double> S;
vector<double> in;
rep(i,n){
rep(j,m){
int src=2+i,dst=2+n+j;
edge[src][dst]=calc_dist(xt[i]-xbase[j],yt[i]-ybase[j],v[i]);
tcap[src][dst]=1;
Double tmp={edge[src][dst]};
if ( S.find(tmp)==S.end())in.push_back(tmp.b),S.insert(tmp);
}
}
rep(i,n){
tcap[SUPERSOURCE][2+i]=1;
edge[SUPERSOURCE][2+i]=-1;
}
rep(j,n){
tcap[2+n+j][SUPERSINK]=1;
edge[2+n+j][SUPERSINK]=-1;
}
sort(in.begin(),in.end());
printf("%.9lf\n",solve(node,in,m));
}
} | 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<pair<int, int>> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i].first;
a[i].second = i;
}
sort(a.begin(), a.end(),
[](const pair<int, int>& a, const pair<int, int>& b) {
if (a.first == b.first) return a.second < b.second;
return a.first > b.first;
});
vector<vector<pair<int, int>>> b(n);
for (int i = 0; i < n; i++) {
if (i) b[i] = b[i - 1];
b[i].push_back(a[i]);
sort(b[i].begin(), b[i].end(),
[](const pair<int, int>& a, const pair<int, int>& b) {
return a.second < b.second;
});
}
int m;
cin >> m;
for (int i = 0; i < m; i++) {
int k, pos;
cin >> k >> pos;
cout << b[k - 1][pos - 1].first << "\n";
}
return 0;
}
| 8 | CPP |
#include<bits/stdc++.h>
using namespace std;
using i64 = int64_t;
int main(){
int n, k, m;
while(cin >> n >> k >> m, n != 0){
int ans = 0;
for(int i=2;i<=n-1;++i)ans = (ans+k)%i;
ans += m;
ans %= n;
cout << ans + 1 << endl;
}
return 0;
}
| 0 | CPP |
t=int(input())
for _ in range(t):
n=int(input())
arr=list(map(int,input().split()))
freq=[[0,0] for i in range((2*n)+2)]
for i in arr:
freq[i][0]+=1
for i in range((2*n)+2):
if(freq[i][0]>1):
freq[i+1][1]+=freq[i][0]-1
freq[i][0]=1
elif(freq[i][0]>=1 and ((freq[i][0]+freq[i][1])>1)):
freq[i+1][1]+=freq[i][0]
freq[i][0]=0
ans=0
for i in freq:
if((i[0]+i[1])>0):
ans+=1
print(ans) | 8 | PYTHON3 |
#include<iostream>
#include<cstdio>
#define ll long long
#define maxn 400040
#define re register
using namespace std;
const int mo=1000000007;
int n,a[maxn],b[maxn],c[maxn];
ll f[4040][4040],ans,p[maxn];
inline int ksm(int x,int y)
{
int ans=1;
while(y)
{
if(y&1) ans=(ll)ans*x%mo;
x=(ll)x*x%mo;
y>>=1;
}
return ans;
}
int main()
{
scanf("%d",&n); int m=0;
for(re int i=1;i<=n;i++)
{
scanf("%d%d",&a[i],&b[i]);
m=max(m,max(a[i],b[i]));
}
for(re int i=1;i<=n;i++)f[m+a[i]][m+b[i]]++;
c[0]=p[0]=1;
for(re int i=1;i<=m*4;i++) c[i]=(ll)c[i-1]*i%mo,p[i]=ksm(c[i],mo-2)%mo;
for(re int i=m*2;i>=0;i--)
for(re int j=m*2;j>=0;j--)
f[i][j]=(f[i][j]+f[i+1][j]+f[i][j+1])%mo;
for(re int i=1;i<=n;i++) ans=(ans+f[m-a[i]][m-b[i]])%mo;
for(re int i=1;i<=n;i++) ans=(ans-(ll)c[a[i]*2+b[i]*2]*p[a[i]*2]%mo*p[b[i]*2]%mo)%mo;
ans=(ans*ksm(2,mo-2))%mo;
printf("%lld\n",(ans+mo)%mo);
} | 0 | CPP |
import sys
input = sys.stdin.readline
k=int(input())
A=[0]+list(input().strip())
x=k-1
B=[]
r=1
while x>=0:
B=list(range(r,r+(1<<x)))+B
r+=(1<<x)
x-=1
#print(B)
B=[-1]+B
B_INV=[-1]*(1<<k)
for i in range(1,(1<<k)):
B_INV[B[i]]=i
#print(B_INV)
C=[-1]*(1<<k)
for i in range(len(A)):
if A[B[i]]=="0":
C[i]=0
elif A[B[i]]=="1":
C[i]=1
else:
C[i]=2
q=int(input())
seg_el=1<<k
SEG=[1]*(2*seg_el)
for i in range(seg_el-1,0,-1):
if C[i]==1:
SEG[i]=SEG[i*2+1]
elif C[i]==0:
SEG[i]=SEG[2*i]
else:
SEG[i]=SEG[2*i]+SEG[2*i+1]
def update(i,s):
while i!=0:
if C[i]==1:
SEG[i]=SEG[i*2+1]
elif C[i]==0:
SEG[i]=SEG[2*i]
else:
SEG[i]=SEG[2*i]+SEG[2*i+1]
i>>=1
for queries in range(q):
x,y=input().split()
x=int(x)
if y=="0":
y=0
elif y=="1":
y=1
else:
y=2
C[B_INV[x]]=y
update(B_INV[x],y)
print(SEG[1])
| 10 | PYTHON3 |
w = int(input())
w = str(w)
def x():
if w == '2':
return 'NO'
if w[-1] in ['0', '2', '4', '6', '8']:
return 'YES'
else:
return 'NO'
print(x()) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
vector<int> adj[100000 + 5];
vector<int> av(1e5 + 5, -1);
vector<int> sv(1e5 + 5, 0);
vector<int> hv(1e5 + 5, 0);
int n;
bool bad = false;
int dfs(int start, int parent) {
hv[start] = hv[parent] + 1;
if (hv[start] % 2 == 1 && sv[start] == -1) {
bad = 1;
return -1;
}
int minsv = INT_MAX;
if (hv[start] % 2 == 0) {
for (auto v : adj[start]) {
if (v != parent) {
if (sv[v] == -1) {
bad = 1;
return -1;
}
minsv = min(sv[v], minsv);
}
}
if (minsv == INT_MAX)
sv[start] = sv[parent];
else
sv[start] = minsv;
if (minsv < sv[parent]) {
bad = 1;
return -1;
}
}
av[start] = sv[start] - sv[parent];
for (auto v : adj[start]) {
if (v != parent) dfs(v, start);
}
return 0;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cin >> n;
for (int i = 2; i <= n; ++i) {
int d;
cin >> d;
adj[d].push_back(i);
}
for (int i = 0; i < n; ++i) {
int d;
cin >> d;
sv[i + 1] = d;
}
hv[0] = 0;
sv[0] = 0;
int chk = dfs(1, 0);
if (bad) {
cout << -1 << endl;
return 0;
}
long long ans = 0;
for (int i = 0; i < n; ++i) {
ans += av[i + 1];
}
cout << ans << endl;
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-12;
const double DELTA = 1e-12;
const int INF = ~(1 << 31);
const long long LINF = ~(1LL << 63);
const int MOD = (int)998244353;
const int MAXN = 3e5 + 10;
long long sy, a, b, n, l, r, q, x, y;
long long a1, b1, c1, a2, b2, c2;
vector<long long> fence{};
vector<long long> sums{};
int main() {
cin.tie(0);
ios_base::sync_with_stdio(0);
cin >> sy >> a >> b >> n;
sums.push_back(0);
fence.push_back(0);
for (int i = 0; i < n; ++i) {
cin >> l >> r;
fence.push_back(l);
fence.push_back(r);
int len = r - l;
sums.push_back(sums[sums.size() - 1] + len);
}
fence.push_back(1e9 + 10);
cin >> q;
for (int i = 0; i < q; ++i) {
cin >> x >> y;
a1 = y - sy;
b1 = a - x;
c1 = -a1 * x - b1 * y;
double x1 = -c1 / (a1 + 0.);
long long leftFenceIdx =
lower_bound((fence).begin(), (fence).end(), x1) - fence.begin();
a2 = y - sy;
b2 = b - x;
c2 = -a2 * x - b2 * y;
double x2 = -c2 / (a2 + 0.);
long long rightFenceIdx =
prev(upper_bound((fence).begin(), (fence).end(), x2)) - fence.begin();
double coef = x != a ? (x - a) / (x - x1) : (x - b) / (x - x2);
double currSum = 0;
if (leftFenceIdx % 2 == 0) {
currSum += fence[leftFenceIdx] - x1;
}
if (rightFenceIdx % 2 == 1) {
currSum += x2 - fence[rightFenceIdx];
}
if (leftFenceIdx % 2 == 0 && leftFenceIdx - rightFenceIdx == 1) {
currSum -= (fence[leftFenceIdx] - fence[rightFenceIdx]);
}
if (rightFenceIdx - leftFenceIdx > 0) {
long long rightSumsIdx = rightFenceIdx / 2 - 1;
long long leftSumsIdx = leftFenceIdx / 2;
currSum += sums[rightSumsIdx + 1] - sums[leftSumsIdx];
}
printf("%.10f\n", currSum * coef);
}
return 0;
}
| 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
int arr[105];
int main() {
int n, x, y, ans = 0;
scanf("%d%d%d", &n, &x, &y);
for (int i = 1; i <= n; ++i) scanf("%d", &arr[i]);
if (x > y) {
printf("%d\n", n);
return 0;
} else if (x <= y) {
if (n == 1) {
if (arr[1] <= x) {
printf("1\n");
return 0;
} else {
printf("0\n");
return 0;
}
}
for (int i = 1; i <= n; ++i) {
if (arr[i] <= x) ans++;
}
printf("%d\n", ans / 2 + (ans & 1));
}
return 0;
}
| 9 | CPP |
// 基本テンプレート
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
using namespace std;
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
typedef pair<int, int> pii;
typedef long long ll;
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;
const pair<int, int> NIL(-1, -1);
double orig[110][110], mat[110][110], tmp[110][110];
signed main() {
int N, M;
while(cin >> N >> M, N) {
for(int i=0; i<N; i++) {
for(int j=0; j<N; j++) {
cin >> mat[i][j];
orig[i][j] = mat[i][j];
}
}
cout << fixed << setprecision(2);
if(M == 1) cout << 1.0 << endl;
else {
for(int k=0; k<M-2; k++) {
fill(tmp[0], tmp[N], 0);
for(int j=0; j<N; j++) {
double ma = -1;
for(int i=0; i<N; i++) {
chmax(ma, mat[i][j]);
}
for(int i=0; i<N; i++) {
chmax(tmp[j][i], orig[j][i] * ma);
}
}
swap(mat, tmp);
}
double ans = -1;
for(int i=0; i<N; i++) {
for(int j=0; j<N; j++) {
chmax(ans, mat[i][j]);
}
}
cout << ans << endl;
}
}
return 0;
}
| 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100050;
const long long INF = 1e18;
int n, q;
long long h[maxn];
int root, l[maxn] = {0}, r[maxn] = {0}, f[maxn] = {0};
long long siz[maxn] = {0}, sum[maxn] = {0};
void update(int x) {
siz[x] = siz[l[x]] + siz[r[x]] + 1;
sum[x] = sum[l[x]] + sum[r[x]] + h[x];
}
void link(int x, int y, int c) {
if (x) f[x] = y;
(c ? r[y] : l[y]) = x;
}
void rot(int x) {
int y = f[x], z = f[y];
if (!z)
root = x, f[x] = 0;
else
link(x, z, r[z] == y);
if (x == l[y])
link(r[x], y, 0), link(y, x, 1);
else
link(l[x], y, 1), link(y, x, 0);
update(x);
update(y);
}
void splay(int x, int des) {
int y, z;
while (f[x] != des) {
y = f[x], z = f[y];
if (z != des) rot((r[z] == y) == (r[y] == x) ? y : x);
rot(x);
}
}
int find(int x) {
int i = root, j;
while (h[i] != x) {
j = (h[i] < x ? r[i] : l[i]);
if (!j) break;
i = j;
}
return i;
}
int prev(int x) {
if (!l[x]) {
while (l[f[x]] == x) x = f[x];
x = f[x];
} else {
x = l[x];
while (r[x]) x = r[x];
}
return x;
}
int next(int x) {
if (!r[x]) {
while (r[f[x]] == x) x = f[x];
x = f[x];
} else {
x = r[x];
while (l[x]) x = l[x];
}
return x;
}
void del(int p) {
int d1, d2;
d1 = prev(p);
d2 = next(p);
splay(d1, 0);
splay(d2, root);
l[r[root]] = 0;
update(r[root]);
update(root);
}
void insert(int p) {
int d = find(h[p]), d0;
if (h[d] > h[p])
d0 = prev(d);
else
d0 = next(d), swap(d0, d);
splay(d0, 0);
splay(d, root);
update(p);
link(p, r[root], 0);
update(r[root]);
update(root);
}
double query(long long v) {
int i = root, j;
long long siz0 = siz[l[i]], sum0 = sum[l[i]] + h[i];
while (i == n + 2 || siz0 * h[i] - sum0 != v) {
if (siz0 * h[i] - sum0 < v) {
if (!r[i]) break;
i = r[i];
siz0 += siz[l[i]] + 1;
sum0 += sum[l[i]] + h[i];
} else {
if (!l[i]) break;
i = l[i];
siz0 -= siz[r[i]] + 1;
sum0 -= sum[r[i]] + h[f[i]];
}
}
if (i == n + 2 || siz0 * h[i] - sum0 > v) siz0--, sum0 -= h[i], i = prev(i);
return h[i] + (double)(v - siz0 * h[i] + sum0) / siz0;
}
int main() {
int i, j;
scanf("%d%d", &n, &q);
h[1] = 0, h[n + 2] = INF;
update(1);
update(n + 2);
link(n + 2, root = 1, 1);
for (i = 2; i <= n + 1; i++) {
scanf("%I64d", &h[i]);
insert(i);
}
while (q--) {
int o, x;
long long p;
scanf("%d%I64d", &o, &p);
if (o == 1) {
p++;
scanf("%d", &x);
del(p);
h[p] = x;
insert(p);
} else
printf("%lf\n", query(p));
}
return 0;
}
| 11 | CPP |
g = int(input())
for i in range(g):
a, b, n, S = map(int, input().split())
S -= n * min(a, S // n)
if S > b:
print("No")
else:
print("YEs") | 7 | PYTHON3 |
def partition(A, p, r):
x = A[r]
i = p-1
for j in range(p, r):
if A[j] <= x:
i = i+1
A[i],A[j] = A[j],A[i]
A[i+1],A[r] = A[r],A[i+1]
return i+1
r = int(input())
A = list(map(int, input().split()))
p = partition(A, 0, r-1)
A = list(map(str, A))
A[p] = "[%s]"%(A[p])
print(" ".join(A)) | 0 | PYTHON3 |
aa, bb, dp = [], [], []
def dot(i, a):
return dp[i] + a*bb[i]
def main():
n = int(input())
a = list(map(int, input().split(' ')))
b = list(map(int, input().split(' ')))
for k in range(n):
dp.append(0)
aa.append(a[k])
bb.append(b[k])
st, i, j = [0 for _ in range(n) ], 0, 0
for k in range(1,n):
while(j - i > 0 and dot(st[i],a[k]) >= dot(st[i+1],a[k])):
i+=1
dp[k] = a[k]*b[st[i]] + dp[st[i]]
while(j - i > 0 and (b[st[j]] - b[k])*(dp[st[j]] - dp[st[j-1]]) > (dp[k] - dp[st[j]])*(b[st[j-1]] - b[st[j]])):
j-=1
j+=1
st[j] = k
print(dp[-1])
if __name__ == "__main__":
main() | 9 | PYTHON3 |
n, k = [int(x) for x in input().split(' ')]
from collections import defaultdict
d = defaultdict(int)
for i in range(n):
soda = int(input())
d[soda] += 1
sorted_d = sorted(d.values())
total = 0
from math import ceil
sets = ceil(n/2)
while True:
if sets <= 0 or not sorted_d:
break
tmp = sorted_d.pop()
if tmp % 2 == 0:
total += tmp
sets -= tmp // 2
else:
if tmp == 1:
sets -= 1
total += 1
else:
sets -= tmp // 2
total += tmp - 1
sorted_d = [1] + sorted_d
print(total)
| 7 | PYTHON3 |
n,m=map(int,input().split())
import collections
c=collections.Counter()
ans=[]
for _ in range(n):
s=input()
r=s[::-1]
if c[r]!=0:
ans.append(s)
c[r]-=1
else:
c[s]+=1
mid=''
for x in c:
if c[x]!=0:
if all(x[i]==x[-i-1] for i in range(len(x))) and len(mid)<len(x):
mid=x
r=[]
for x in ans[::-1]:
r.append(x[::-1])
ans.append(mid)
ans+=r
ans=''.join(ans)
print(len(ans))
print(ans) | 8 | PYTHON3 |
nStr = input()
n = int(nStr)
inpList = ['']*n
for i in range(n):
inpList[i] = input()
hashMap = dict()
for i in range(n):
if inpList[i] in hashMap:
print(inpList[i]+str(hashMap[inpList[i]]))
hashMap[inpList[i]] = hashMap[inpList[i]] + 1
else :
print('OK')
hashMap[inpList[i]] = 1
| 9 | PYTHON3 |
#include<stdio.h>
int main (void){
int N,a,b;
scanf("%d",&N);
if(N==1){
printf("Hello World");
}
else if(N==2){
scanf("%d",&a);
scanf("%d",&b);
printf("%d",a+b);
}
return 0;
} | 0 | CPP |
print('A' if input().isupper()==True else 'a') | 0 | PYTHON3 |
#include <bits/stdc++.h>
const int M = 105;
int n, m, a[M][M];
int getcol(const int x, const int y) {
if (a[x][y]) return a[x][y];
for (int i = 1; i < 5; ++i)
if ((i ^ a[x - 1][y]) && (i ^ a[x + 1][y]) && (i ^ a[x][y - 1]) &&
(i ^ a[x][y + 1]))
return i;
}
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= m; ++j) {
if (a[i][j]) continue;
int col = getcol(i, j), k = 0;
while (getcol(i, j + k) == col && i + k <= n && j + k <= m) ++k;
for (int x = i; x < i + k; ++x)
for (int y = j; y < j + k; ++y) a[x][y] = col;
}
for (int i = 1; i <= n; ++i, putchar('\n'))
for (int j = 1; j <= m; ++j) putchar(a[i][j] - 1 + 'A');
return 0;
}
| 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
char a[100];
int main() {
cin >> a;
int p = strlen(a);
int k = 0, l = 0;
for (int i = 0; i < p; i++) {
if (a[i] == '1') {
l = 0;
k++;
if (k == 7) break;
} else if (a[i] == '0') {
k = 0;
l++;
if (l == 7) break;
}
}
if (k == 7 || l == 7)
printf("YES");
else
printf("NO");
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:20000000")
using namespace std;
int ri() {
int x;
scanf("%d", &x);
return x;
}
long long rll() {
long long x;
scanf("%lld", &x);
return x;
}
const int MAXN = 1e5 + 10;
pair<int, int> mas[MAXN];
int in[MAXN];
void solve() {
int n = ri(), k = ri();
long long b;
cin >> b;
long long sum = 0;
for (int i = (int)(1); i <= (int)(n); i++)
mas[i].first = ri(), sum += (long long)mas[i].first, mas[i].second = i,
in[i] = mas[i].first;
sum -= (long long)mas[n].first;
sort(mas + 1, mas + n);
set<pair<int, int> > st;
set<pair<int, int> >::iterator it;
long long su = 0;
for (int i = (int)(n - 1); i >= (int)(n - k + 1); i--)
st.insert(mas[i]), su += (long long)mas[i].first;
int dop = n - k;
if (dop < 0) dop = 0;
for (int i = (int)(1); i <= (int)(n - 1); i++) {
if (st.find(make_pair(in[i], i)) == st.end()) {
if (su + (long long)in[i] > b) {
cout << i << endl;
return;
}
} else {
su -= (long long)in[i];
st.erase(make_pair(in[i], i));
su += (long long)mas[dop].first;
st.insert(make_pair(mas[dop].first, mas[dop].second));
if (su + (long long)in[i] > b) {
cout << i << endl;
return;
}
st.erase(make_pair(mas[dop].first, mas[dop].second));
su -= (long long)mas[dop].first;
st.insert(make_pair(in[i], i));
su += (long long)in[i];
}
if (!st.empty() && st.begin()->first < in[i] &&
st.find(make_pair(in[i], i)) == st.end()) {
su -= (long long)st.begin()->first;
st.erase(st.begin());
su += (long long)in[i];
st.insert(make_pair(in[i], i));
}
}
cout << n << endl;
}
int main() {
solve();
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 1;
const int inf = 1e18;
signed main() {
ios_base::sync_with_stdio(0);
cout.tie(0);
cin.tie(0);
srand(time(NULL));
int n, x;
cin >> n >> x;
vector<pair<int, int>> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i].first >> a[i].second;
}
int ans = 0;
for (int i = 0; i < n; ++i) {
if (i == 0) {
ans += (a[i].first - 1) % x;
}
ans += a[i].second - a[i].first + 1;
if (i < n - 1) {
ans += (a[i + 1].first - a[i].second - 1) % x;
}
}
cout << ans;
}
| 7 | CPP |
import math
n = int(input())
a = 0
for _ in range(n):
x, y = map(int, input().split())
a = max(a, x + y)
print(a)
| 8 | PYTHON3 |
n, m = map(int, input().split())
board = [["#"] * (m + 2)] + [["#"] + list(input()) + ["#"] for i in range(n)] + [["#"] * (m + 2)]
ansr = [[0] * (m + 2) for i in range(n + 2)]
ansc = [[0] * (m + 2) for i in range(n + 2)]
for i in range(1, n + 1):
for j in range(1, m + 1):
ansr[i][j] = ansr[i - 1][j] + ansr[i][j - 1] - ansr[i - 1][j - 1] + (1 if board[i][j] == "." and board[i][j - 1] == "." else 0)
ansc[i][j] = ansc[i - 1][j] + ansc[i][j - 1] - ansc[i - 1][j - 1] + (1 if board[i][j] == "." and board[i - 1][j] == "." else 0)
q = int(input())
for i in range(q):
r1, c1, r2, c2 = map(int, input().split())
print(ansr[r2][c2] + ansc[r2][c2] - ansc[r1][c2] - ansc[r2][c1 - 1] - ansr[r1 - 1][c2] - ansr[r2][c1] + ansr[r1 - 1][c1] + ansc[r1][c1 - 1])
| 9 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n{0};
cin >> n;
int arr[n];
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
int m = sizeof(arr) / sizeof(arr[0]);
sort(arr, arr + m);
int best = 0, sum = 0;
for (int k = 0; k < m; k++) {
if (k + 1 >= arr[k]) {
sum = k + 1;
}
}
cout << sum + 1 << "\n";
}
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, ans = 1e9;
int gcd(int a, int b) {
if (b == 1) return a - 1;
if (a == b) return 1e9;
if (a == 0 || b == 0) return 1e9;
return gcd(b, a % b) + a / b;
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) ans = min(ans, gcd(i, n));
printf("%d\n", ans);
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int cmp(int x, int y) { return x > y; }
int main() {
int a[2005], b[2005], c[2005];
int n, k;
cin >> n >> k;
int i, j, m = 1;
for (i = 1; i <= n; i++) {
cin >> a[i];
b[i] = a[i];
}
sort(b + 1, b + n + 1, cmp);
int sum = 0;
for (i = 1; i <= k; i++) sum += b[i];
cout << sum << endl;
for (i = 1; i <= n; i++) {
for (j = 1; j <= k; j++) {
if (a[i] == b[j]) {
b[j] = 0;
c[m++] = i;
break;
}
}
}
sort(c + 1, c + k + 1);
c[0] = 0;
for (i = 1; i <= k - 1; i++) {
if (i == 1)
cout << c[i] - c[i - 1];
else
cout << " " << c[i] - c[i - 1];
}
if (k == 1)
cout << n - c[k - 1];
else
cout << " " << n - c[k - 1];
cout << endl;
}
| 8 | CPP |
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
int bfs(int &p, string s, vector<int> &win){
if(s[p] != '['){
return s[p++];
}
int left = bfs(++p, s, win);
int right = bfs(++p, s, win);
p++;
if(left == -1 or right == -1) return -1;
if(win[left] != 0 and win[right] != 0) return -1;
if(win[left] == 0 and win[right] == 0) return -1;
if(win[left] == 0){
win[right]--;
return right;
}else{
win[left]--;
return left;
}
}
int main(){
string s;
cin >> s;
vector<int> win(256, 0);
char ch;
int winnum;
int n=0, sum=0;
while(cin >> ch >> winnum){
win[(int)ch] = winnum;
n++;
sum += winnum;
}
int p = 0;
if(sum != n-1 or bfs(p, s, win) == -1){
cout << "No" << endl;
}else{
cout << "Yes" << endl;
}
return 0;
}
| 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
while (cin >> n) {
vector<int> v(n);
for (int i = 0; i < n; ++i) cin >> v[i];
sort(v.begin(), v.end());
int c = accumulate(v.begin(), v.end(), 0);
int b = 0;
int ans = -1e9;
for (int i = 0; i < n; ++i) {
ans = max(c - b, ans);
ans = max(b - c, ans);
b += v[i];
c -= v[i];
}
cout << ans << endl;
}
return 0;
}
| 7 | CPP |
c,d=0,0
for i in range(int(input())):
a,b=map(int,input().split())
c+=a*b
d+=b
print(d-1+(c-1)//9) | 0 | PYTHON3 |
if __name__ == '__main__':
l, r = map(int, input().split())
if l % 2 == 1:
l += 1
if l + 2 > r:
print(-1)
else:
print(str(l) + ' ' + str(l + 1) + ' ' + str(l + 2))
| 7 | PYTHON3 |
m,n=map(str,input().split())
for i in range(int(n)):
v=len(m)
t=int(m)
if(int(m[v-1])==0):
t=int(t/10)
else:
t=t-1
m=str(t)
print(m)
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
vector<vector<long long int>> adj;
long long int n, m;
void BFS() {
vector<bool> level(n + 1, false), visit(n + 1, false);
queue<long long int> Q;
Q.push(1);
visit[1] = true;
while (!Q.empty()) {
long long int P = Q.front();
Q.pop();
bool L = level[P];
L = !L;
for (int i = 0; i < adj[P].size(); i++) {
if (!visit[adj[P][i]]) {
level[adj[P][i]] = L;
visit[adj[P][i]] = true;
Q.push(adj[P][i]);
}
}
}
long long int count = 0;
for (int i = 1; i <= n; i++) {
if (level[i]) {
count++;
}
}
if (count <= n / 2) {
cout << count << endl;
for (int i = 1; i <= n; i++) {
if (level[i]) {
cout << i << " ";
}
}
} else {
cout << n - count << endl;
for (int i = 1; i <= n; i++) {
if (!level[i]) {
cout << i << " ";
}
}
}
cout << endl;
}
int main() {
long long int t;
cin >> t;
while (t--) {
cin >> n >> m;
adj.assign(n + 1, vector<long long int>());
for (int i = 0; i < m; i++) {
long long int x, y;
cin >> x >> y;
adj[x].push_back(y);
adj[y].push_back(x);
}
BFS();
}
}
| 11 | CPP |
n = input()
t = min(len(set(n[:-1])), len(set(n[1:])))
print('Yes' if t == 1 else 'No') | 0 | PYTHON3 |
#include <bits/stdc++.h>
int count = 0, len;
char a[100];
void f(int pos) {
int j;
for (j = pos; j < len; j++) {
if (a[j] == 'A') {
for (int k = j + 1; k < len; k++) {
if (a[k] == 'Q') count++;
}
}
}
}
int main() {
int j;
scanf("%s", a);
len = strlen(a);
for (int i = 0; i < len; i++) {
if (a[i] == 'Q') {
f(i);
}
}
printf("%d\n", count);
return 0;
}
| 7 | CPP |
def line(x1, y1, x2, y2):
a1 = x2 - x1
b1 = y2 - y1
a1, b1 = b1, -a1
c1 = -(a1 * x1 + b1 * y1)
return [a1, b1, c1]
def check(x, y, x1, y1, x2, y2):
if abs(((x - x1) ** 2 + (y - y1) ** 2) ** 0.5 + ((x - x2) ** 2 + (y - y2) ** 2) ** 0.5 - ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5) < 0.1 ** 10:
return True
else:
return False
n, x, y = map(int, input().split())
maxi = 0
pi = 3.1415926535897932384626433832795
s = []
for i in range(n):
a, b = map(int, input().split())
s.append([a, b])
maxi = max((x - a) ** 2 + (y - b) ** 2, maxi)
mini = 10**20
for i in range(n):
a2, b2, c2 = line(s[i][0], s[i][1], s[(i + 1) % n][0], s[(i + 1) % n][1])
a1 = -b2
b1 = a2
c1 = -(x * a1 + b1 * y)
xx, yy = (b1 * c2 - b2 * c1) / (-a2 * b1 + a1 * b2), (a1 * c2 - a2 * c1) / (a2 * b1 - a1 * b2)
if check(xx, yy, s[i][0], s[i][1], s[(i + 1) % n][0], s[(i + 1) % n][1]):
mini = min((a2 * x + b2 * y + c2) ** 2 / (a2 ** 2 + b2 ** 2), mini)
else:
mini = min((x - s[i][0]) ** 2 + (y - s[i][1]) ** 2, (x - s[(i + 1) % n][0]) ** 2 + (y - s[(i + 1) % n][1]) ** 2, mini)
print(pi * (maxi - mini)) | 9 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (b == 0)
return a;
else
return gcd(b, a % b);
}
int main() {
int q;
scanf("%d", &q);
while (q--) {
long long x, y, b;
scanf("%lld %lld %lld", &x, &y, &b);
long long fpb = gcd(x, y);
x /= fpb;
y /= fpb;
long long now = gcd(y, b);
while (now != 1) {
while (y % now == 0) y /= now;
now = gcd(b, y);
}
if (y == 1)
printf("Finite\n");
else
printf("Infinite\n");
}
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int b[maxn], cnt[maxn], pos[maxn];
vector<int> ans[maxn];
int main() {
std::ios::sync_with_stdio(false);
int t;
cin >> t;
while (t--) {
int n, x, y;
cin >> n >> x >> y;
for (int i = 1; i <= n + 1; i++) cnt[i] = 0;
for (int i = 1; i <= n; i++) {
cin >> b[i];
cnt[b[i]]++;
}
int s = 0;
for (int i = 1; i <= n + 1; i++)
if (!cnt[i]) {
s = i;
break;
}
priority_queue<pair<int, int> > q1, q2;
for (int i = 1; i <= n + 1; i++)
if (cnt[i]) q1.push(make_pair(cnt[i], i));
for (int i = 1; i <= n + 1; i++) ans[i].clear();
for (int i = 1; i <= x; i++) {
pair<int, int> now = q1.top();
q1.pop();
int t = now.first, p = now.second;
ans[p].push_back(p);
if (t > 1) q1.push(make_pair(t - 1, p));
cnt[p]--;
}
for (int i = 1; i <= n + 1; i++)
if (cnt[i]) q2.push(make_pair(cnt[i], -i));
bool boom = 0;
int last = n - y;
for (int i = 1; i <= y - x; i++) {
pair<int, int> now = q1.top();
q1.pop();
int t = now.first, p = now.second;
pair<int, int> now2 = q2.top();
q2.pop();
int t2 = now2.first, p2 = -now2.second;
if (p2 == p) {
if (q2.empty()) {
if (last) {
ans[p].push_back(s);
if (t > 1) q1.push(make_pair(t - 1, p));
q2.push(now2);
last--;
i--;
continue;
} else {
boom = 1;
break;
}
}
pair<int, int> now3 = q2.top();
q2.pop();
int t3 = now3.first, p3 = -now3.second;
ans[p].push_back(p3);
if (t > 1) q1.push(make_pair(t - 1, p));
q2.push(now2);
if (t3 > 1) q2.push(make_pair(t3 - 1, -p3));
} else {
ans[p].push_back(p2);
if (t > 1) q1.push(make_pair(t - 1, p));
if (t2 > 1) q2.push(make_pair(t2 - 1, -p2));
}
}
if (boom)
cout << "NO" << endl;
else {
while (!q1.empty()) {
pair<int, int> now = q1.top();
q1.pop();
int t = now.first, p = now.second;
for (int i = 1; i <= t; i++) ans[p].push_back(s);
}
cout << "YES" << endl;
for (int i = 1; i <= n + 1; i++) pos[i] = 0;
for (int i = 1; i <= n; i++) cout << ans[b[i]][pos[b[i]]++] << " ";
cout << endl;
}
}
return 0;
}
| 9 | CPP |
#include <cstdio>
#include <iostream>
using namespace std;
struct Node{
struct Node *p;
struct Node *cl;
struct Node *cr;
int key;
};
typedef struct Node *node;
node root;
int cnt;
void insert(int v){
node y = NULL;
node x = root;
node z;
z = (node)malloc(sizeof(Node));
z->cl= NULL;
z->cr= NULL;
z->key = v;
while(x!=NULL){
y = x;
if(z->key < x->key) x = x->cl;
else x = x->cr;
}
z->p = y;
if(y== NULL){
root = z;
}
else if(z->key < y->key) y->cl = z;
else y->cr = z;
}
void print_preorder(node x){
if(x == NULL) return;
printf(" %d", x->key);
print_preorder(x->cl);
print_preorder(x->cr);
}
void print_inorder(node x){
if(x == NULL) return;
print_inorder(x->cl);
printf(" %d", x->key);
print_inorder(x->cr);
}
int main(){
int n;
int tmp;
string t;
scanf("%d", &n);
for(int i=0; i<n;i++){
cin >> t;
if(t=="insert"){
cin >> tmp;
insert(tmp);
}else if(t=="print"){
cnt = 0;
print_inorder(root);
printf("\n");
cnt = 0;
print_preorder(root);
printf("\n");
}
}
}
| 0 | CPP |
n=int(input())
list1=[]
for i in range(n):
tmp=input().split()
list1.append(tmp)
list2=[]
list3=[['++X'],['X++']]
for value in list1:
if value in list3:
list2.append(1)
else:
list2.append(-1)
total=0
for i in range(len(list2)):
total+=list2[i]
print(total)
| 7 | PYTHON3 |
n = int(input())
s = input()
if len(set(s)) == 1:
print("NO")
else:
for i in range(n-1):
if s[i] != s[i+1]:
print("YES")
print(s[i]+s[i+1])
break
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int a[N], n, b[N];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
for (int i = 1; i <= n; ++i) cin >> a[i];
sort(a + 1, a + n + 1);
int j = 1;
for (int i = 2; i <= n; i += 2) {
b[i] = a[j++];
}
for (int i = 1; i <= n; i += 2) {
b[i] = a[j++];
}
int k = 0;
for (int i = 2; i < n; ++i)
if (b[i] < b[i - 1] && b[i] < b[i + 1]) ++k;
cout << k << endl;
for (int i = 1; i <= n; ++i) cout << b[i] << " ";
cout << endl;
}
| 10 | CPP |
#include <bits/stdc++.h>
int cnt[256];
char buf[100007];
int main() {
int N, notZero = 0, howmany = 0;
scanf("%d%s", &N, buf);
for (int i = 0; i < N; ++i) {
if (cnt[(int)buf[i]] == 0) {
++cnt[(int)buf[i]];
++howmany;
}
}
memset(cnt, 0, sizeof(cnt));
int i = 0, j = 0, ans = N;
++cnt[(int)buf[0]];
++notZero;
while (i < N && j < N) {
if (notZero == howmany) {
if (--cnt[(int)buf[i++]] == 0) --notZero;
}
while (notZero < howmany) {
if (++j == N) {
j = 0x3f3f3f3f;
break;
}
if (cnt[(int)buf[j]]++ == 0) ++notZero;
}
ans = std::min(ans, j - i + 1);
}
printf("%d\n", ans);
return 0;
}
| 9 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
set<int> s;
int a[maxn], b[maxn], num[2] = {0};
int main() {
int n, m;
cin >> n >> m;
int half = n / 2;
int cnt = 0;
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
if (s.find(a[i]) != s.end() || num[a[i] & 1] >= half)
b[cnt++] = i;
else {
s.insert(a[i]);
num[a[i] & 1]++;
}
}
int res = cnt;
for (int i = 2; i <= m && num[0] < half && cnt > 0; i += 2) {
if (s.find(i) == s.end()) {
a[b[--cnt]] = i;
s.insert(i);
num[0]++;
}
}
for (int i = 1; i <= m && num[1] < half && cnt > 0; i += 2) {
if (s.find(i) == s.end()) {
a[b[--cnt]] = i;
s.insert(i);
num[1]++;
}
}
if (num[0] == half && num[1] == half && cnt == 0) {
cout << res << endl;
for (int i = 0; i < n - 1; i++) printf("%d ", a[i]);
cout << a[n - 1] << endl;
} else
cout << -1 << endl;
return 0;
}
| 11 | CPP |
import sys
N = int(input())
if N == 1:
print(int(input()) - 1)
sys.exit()
A = [int(sys.stdin.readline()) for _ in range(N)]
ans = A[0] - 1
i = 2
for a in A[1:]:
if i == a:
i += 1
continue
ans += (a-1)//i
print(ans)
| 0 | PYTHON3 |
#include <bits/stdc++.h>
const int inf = 0x3f3f3f3f;
const int N = 400005;
using namespace std;
int a[N], b[N];
vector<int> v[N];
bool ex[N];
set<pair<int, int> > s;
int main() {
int n, k;
scanf("%d%d", &n, &k);
int i, j;
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
v[a[i]].push_back(i);
}
for (i = 1; i <= n; i++) v[i].push_back(n + 2);
memset(ex, false, sizeof(ex));
int ans = 0, sz = 0;
for (i = 0; i < n; i++) {
s.erase(make_pair(-v[a[i]][b[a[i]]], a[i]));
b[a[i]]++;
if (ex[a[i]]) {
s.insert(make_pair(-v[a[i]][b[a[i]]], a[i]));
continue;
}
if (sz == k) {
j = s.begin()->second;
s.erase(s.begin());
ex[j] = false;
} else
sz++;
ex[a[i]] = true;
s.insert(make_pair(-v[a[i]][b[a[i]]], a[i]));
ans++;
}
printf("%d", ans);
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int x0, y0, ax, ay, bx, by, xs, ys, t;
cin >> x0 >> y0 >> ax >> ay >> bx >> by >> xs >> ys >> t;
vector<pair<long long int, long long int> > v;
int cnt = 0;
long long int x = x0, y = y0;
v.push_back({x0, y0});
while (x <= xs + t * 2 && y <= ys + t * 2) {
x = x * ax + bx;
y = y * ay + by;
cnt++;
v.push_back({x, y});
}
long long int ans = 0;
for (int i = 0; i < cnt; i++) {
long long int dis = abs(xs - v[i].first) + abs(ys - v[i].second);
if (dis > t) continue;
for (int j = 0; j < cnt; j++) {
if (dis + abs(v[i].first - v[j].first) + abs(v[i].second - v[j].second) <=
t) {
ans = max(ans, (long long int)(abs(j - i) + 1));
}
}
}
cout << ans << endl;
return 0;
}
| 10 | CPP |
class Solver(object):
def __init__(self, debug=False):
self.debug = debug
def d(self, *args):
if self.debug:
import sys
print(*args, file=sys.stderr)
pass
def precalc(self):
pass
def solve(self):
a,b,c,d = map(int, input().split(" "))
return ' '.join(map(str, [b,c,c]))
# s = Solver(debug=True)
s = Solver(debug=False)
s.precalc()
NUM_CASES = int(input())
for CASE_NO in range(1, NUM_CASES + 1):
result = s.solve()
print("{}".format(result))
# print("{}".format(result))
# check out .format's specification for more formatting options
'''
inputCopy
4
1 3 5 7
1 5 5 7
100000 200000 300000 400000
1 1 977539810 977539810
outputCopy
3 4 5
5 5 5
182690 214748 300999
1 977539810 977539810
''' | 7 | PYTHON3 |
test=int(input())
for _ in range(test):
n=int(input())
n=n//2
print(n+1) | 7 | PYTHON3 |
#include<iostream>
#include<cstdio>
#define db double
using namespace std;
int n;
db x,d,ans,tmp;
int main()
{
int i,j;
cin>>n>>d>>x;
for(;n;n--)
{
ans+=(d*2.0+(db)(2*n-1)*x)/2.0;
tmp=d;
d+=d/(db)n+5.0*x/(db)(2*n);
x+=2.0*x/(db)n;
// cout<<ans<<" "<<d<<" "<<x<<endl;
}
printf("%.10f",ans);
} | 0 | CPP |
t=int(input())
while t:
t-=1
n=input()
l=len(n)
s=''
if l>10:
s=s+n[0]+str(l-2)+n[l-1]
print(s)
else:
print(n)
| 7 | PYTHON3 |
s=input()
if s.endswith('s') : n= s+'es'
else : n=s+'s'
print(n) | 0 | PYTHON3 |
import sys
import math
inp = sys.stdin.readlines()
n = int(inp[0].strip())
if n == 0:
print(0)
exit(0)
groups = [int(g) for g in inp[1].strip().split()]
l = [None, 0, 0, 0, 0]
for g in groups:
l[g] += 1
# print(l)
taxis = 0
taxis += l[4]
l[4] = 0
# print(l)
taxis += l[2]//2
l[2] %= 2
# print(l)
if l[2]:
for i in range(2):
if l[1] > 0:
l[1] -= 1
l[2] -= 1
taxis += 1
# print(l)
taxis += l[3]
l[1] -= l[3]
l[3] = 0
if l[1] > 0:
taxis += math.ceil(l[1]/4)
l[1] = 0
# print(l)
print(taxis)
| 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
inline void chmin(T &t, U f) {
if (t > f) t = f;
}
template <class T, class U>
inline void chmax(T &t, U f) {
if (t < f) t = f;
}
long long N, K;
long long x[100000], y[100000];
long long ans[111111];
void execute(vector<pair<long long, long long> > &ev, long long w) {
long long cnt = 0;
for (long long i = 0; i + 1 < ev.size(); i++) {
long long h = ev[i + 1].first - ev[i].first;
cnt += ev[i].second;
ans[cnt] += h * w;
}
}
signed main() {
scanf("%lld%lld", &N, &K);
for (long long i = 0; i < (N); i++) scanf("%lld%lld", &x[i], &y[i]);
map<long long, vector<pair<long long, long long> > > ps;
for (long long i = 0; i < (N); i++) {
ps[x[i] - K].push_back(pair<long long, long long>(y[i] - K, 1));
ps[x[i] - K].push_back(pair<long long, long long>(y[i], -1));
ps[x[i]].push_back(pair<long long, long long>(y[i] - K, -1));
ps[x[i]].push_back(pair<long long, long long>(y[i], 1));
}
map<long long, vector<pair<long long, long long> > >::iterator it, jt;
it = jt = ps.begin();
jt++;
vector<pair<long long, long long> > ev;
for (; jt != ps.end(); it++, jt++) {
long long w = jt->first - it->first;
vector<pair<long long, long long> > &v = it->second;
sort((v).begin(), (v).end());
vector<pair<long long, long long> > ev_;
long long i = 0, j = 0;
while (i < ev.size() || j < v.size()) {
if (i < ev.size() && (j == v.size() || ev[i].first <= v[j].first)) {
ev_.push_back(ev[i++]);
} else {
if (ev_.size() && ev_.back().first == v[j].first)
ev_.back().second += v[j++].second;
else
ev_.push_back(v[j++]);
}
if (ev_.back().second == 0) ev_.pop_back();
}
ev = ev_;
execute(ev, w);
}
for (long long i = 1; i <= N; i++) printf("%lld ", ans[i]);
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
signed long long tonum(string s) {
stringstream in(s);
signed long long x;
in >> x;
return x;
}
string tostr(signed long long n) {
stringstream in;
in << n;
string x;
in >> x;
return x;
}
signed long long gcd(signed long long a, signed long long b) {
while (1) {
a = a % b;
if (a == 0) return b;
b = b % a;
if (b == 0) return a;
}
}
int main() {
int N;
string s;
cin >> N;
cin >> s;
int len = (int)s.size();
map<char, int> used;
int marks = 0;
for (int i = 0; i < (int)(s.size()); ++i) {
if (s[i] == '?' && s[len - 1 - i] == '?') {
marks++;
continue;
}
if (s[i] == '?') {
s[i] = s[len - 1 - i];
continue;
}
if (s[len - 1 - i] == '?') {
s[len - 1 - i] = s[i];
continue;
}
if (s[i] != s[len - 1 - i]) {
cout << "IMPOSSIBLE" << endl;
return 0;
}
}
int mid = (s.size() % 2 == 0) ? (s.size() / 2 - 1) : (s.size() / 2);
char curr = N - 1 + 'a';
for (int i = 0; i < (int)(s.size()); ++i) used[s[i]] = 1;
for (int i = mid; i >= 0; --i) {
if (s[i] == '?') {
while (used[curr] == 1) curr--;
if (curr < 'a') break;
s[i] = s[len - 1 - i] = curr;
used[curr] = 1;
}
}
for (int i = 0; i < (int)(s.size()); ++i)
if (s[i] == '?') s[i] = s[len - 1 - i] = 'a';
for (int i = 0; i < (int)(s.size()); ++i) used[s[i]] = 1;
int req = 0, use = 0;
for (int i = 0; i < (int)(N); ++i)
if (used[char(i + 'a')] == 1) req++;
for (int i = 0; i < (int)(26); ++i)
if (used[char(i + 'a')] == 1) use++;
if (req != N || req != use) {
cout << "IMPOSSIBLE" << endl;
return 0;
}
cout << s << endl;
return 0;
}
| 9 | CPP |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
long long a[n], b[n], c = 0, ans = 0;
for (int i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
int m = a[n - 1], x = 1;
while (m / x != 1) {
x = x * 2;
}
while (x > 0) {
c = 0;
for (int i = 0; i < n; i++) {
if (a[i] / x == 1) c++;
}
ans += c * (c - 1) / 2;
x = x / 2;
}
cout << ans << '\n';
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long testCases = 1;
cin >> testCases;
while (testCases--) {
solve();
}
return 0;
}
| 8 | CPP |
k=int(input())
x=[k%4, max(-0.1,k-7)%4, max(-0.1,k-14)%4, max(-0.1,k-21)%4]
if x.count(0)==0: print("-1")
else:
y=7*x.index(0)
seven=x.index(0)
z=(k-y)//4
if z>=7:
seven+=z//7*4
z=z%7
print('4'*z+'7'*seven) | 7 | PYTHON3 |
#include <iostream>
using namespace std;
int main() {
int N, K;
string S;
cin >> N >> K >> S;
int ans = 1;
for (int l = 0, r = 1, operate = S[0] == '0' ? 1 : 0;r < N;++ r) {
if (r < N && S[r - 1] == '1' && S[r] == '0') { // rを追加したら操作回数が増えた時
++ operate;
if (operate > K) { // 反転回数がオーバーした
++ l;
while (S[l - 1] != '0' || S[l] != '1') ++ l;
-- operate;
}
}
ans = max(ans, r - l + 1);
}
cout << ans;
return 0;
} | 0 | CPP |
input()
s = input()
k = 0
c = ''
for t in s:
if t == c:
k += 1
else:
c = t
print(k) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
double sq = sqrt(3.0) / 2.0;
int ans(int r, int h) {
int n;
double q;
if (h < r / 2.0) return 0;
n = (h - r / 2.0) / r;
q = h - r / 2.0 - n * r;
if (q >= sq * r) return 2 * n + 3;
return 2 * n + 2;
}
int ansd(int r, int h) {
int n;
double q;
if (h < sq * r) return 1;
n = (h - sq * r) / r;
q = h - sq * r - n * r;
if (q >= sq * r) return 2 * n + 4;
return 2 * n + 3;
}
int main() {
int r, h, n, q, i;
while (cin >> r >> h) {
cout << max(ans(r, h), ansd(r, h)) << endl;
}
return 0;
}
| 9 | CPP |
a, b = map(int, input().split())
def sign(x):
return 1 if x >= 0 else -1
ans = abs(a) // abs(b) * sign(a) * sign(b)
print(ans)
| 0 | PYTHON3 |
a = list(map(int, input().split('+')))
a.sort()
for i in range(len(a) - 1):
print(str(a[i]) + "+", end="")
print(a[-1]) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 105;
int atk[N], atk2[N], def2[N];
bool mark[N];
int main() {
int n, len;
while (scanf("%d%d", &n, &len) != EOF) {
int lena = 0, lend = 0, i, j;
for (i = 0; i < n; i++) {
char s[5];
int v;
scanf(" %s%d", s, &v);
if (s[0] == 'A')
atk2[lena++] = v;
else
def2[lend++] = v;
}
for (int i = 0; i < len; i++) scanf("%d", &atk[i]);
sort(atk, atk + len);
sort(atk2, atk2 + lena);
sort(def2, def2 + lend);
memset(mark, false, sizeof(mark));
int ans1 = 0, ans2 = 0;
for (i = 0, j = 0; i < lend && j < len; i++) {
while (j < len && (mark[j] || atk[j] <= def2[i])) j++;
if (j == len) break;
mark[j] = true;
}
if (j < len) {
for (i = 0, j = 0; i < lena && j < len; i++) {
while (j < len && (mark[j] || atk[j] < atk2[i])) j++;
if (j == len) break;
mark[j] = true;
ans1 += atk[j] - atk2[i];
}
if (j < len) {
for (i = 0; i < len; i++)
if (!mark[i]) ans1 += atk[i];
} else
ans1 = 0;
}
for (i = len - 1, j = 0; i >= 0 && j < lena && atk[i] >= atk2[j];
i--, j++) {
ans2 += atk[i] - atk2[j];
}
printf("%d\n", max(ans1, ans2));
}
return 0;
}
| 8 | CPP |
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
string s;
cin>>n>> s;
int cnt = 0;
for(int i=0;i<n;i++)if(s[i]=='R'){
cnt++;
}
if(cnt > n-cnt){
cout<<"Yes"<<endl;
}else{
cout<<"No"<<endl;
}
return 0;
}
| 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int sz = 1e5 + 5;
int main() {
int n;
scanf("%d", &n);
;
int a[n], p1 = 0, p2 = n - 1;
long long x = 0, y = 0;
for (int i = 0; i < n; i++) scanf("%d", &a[i]);
sort(a, a + n);
while (p1 < p2) {
x += a[p1++];
y += a[p2--];
}
if (p1 == p2) y += a[p2];
cout << (x * x) + (y * y);
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int n1 = n;
bool b = 1;
int c = 0;
int odd = 1;
for (int i = 2; i * i <= n; i++) {
while (n1 % i == 0) {
n1 /= i;
if (i & 1) {
c++;
odd *= i;
}
}
}
if (n1 > 1) {
c++;
odd *= n1;
}
if (n == 1) {
cout << "FastestFinger\n";
continue;
}
if (n == 2 || n & 1) {
cout << "Ashishgup\n";
continue;
}
if (c > 1) {
cout << "Ashishgup\n";
continue;
}
if (c == 1 && n / odd > 2) {
cout << "Ashishgup\n";
continue;
} else {
cout << "FastestFinger\n";
continue;
}
}
return 0;
}
| 9 | CPP |
#include <bits/stdc++.h>
int main() {
int n;
scanf("%d", &n);
int arr[n];
int freq[1000] = {0};
for (int o = 0; o < n; o++) {
scanf("%d", &arr[o]);
freq[arr[o] - 1] += 1;
}
int count = 0;
for (int p = 0; p < n; p++) {
if (freq[arr[p] - 1] != 1) {
freq[arr[p] - 1] = freq[arr[p] - 1] - 1;
arr[p] = -1;
count += 1;
}
}
printf("%d ", n - count);
printf("\n");
for (int p = 0; p < n; p++) {
if (arr[p] != -1) {
printf("%d ", arr[p]);
}
}
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
T mod(T a, T b) {
T ans;
if (b == 0)
return -1;
else
ans = (a < 0 ? mod(((a % b) + b), b) : a % b);
return ans;
}
long long fast_exp(long long base, long long n, long long M) {
long long ans = 1;
while (n) {
if (n % 2 == 1) ans = (ans * base) % M;
base = (base * base) % M;
n = n >> 1;
}
return ans % M;
}
void solve() {
long long int l, r, x, y;
long double k, left = 0, right = 0;
cin >> l >> r >> x >> y >> k;
for (int b = x; b < y + 1; b++) {
long double a = k * b * 10;
if (int(a) % 10 == 0 and int(a / 10) > l - 1 and int(a / 10) < r + 1) {
cout << "YES" << endl;
return;
}
}
cout << "NO" << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
;
int t = 1;
while (t--) {
solve();
}
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const double eps = 1e-8;
const double PI = acos(-1.0);
const int MAXN = 2e5 + 5;
const int MAXM = 2e6 + 5;
const int MOD = 1e9 + 7;
int sgn(double x) {
if (fabs(x) < eps) return 0;
if (x < 0)
return -1;
else
return 1;
}
long long pw(long long a, long long n, long long mod) {
long long ret = 1;
while (n) {
if (n & 1) ret = ret * a % mod;
a = a * a % mod;
n >>= 1;
}
return ret;
}
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
void inc(long long &a, long long b) {
a += b;
if (a >= MOD) a -= MOD;
}
void dec(long long &a, long long b) {
a -= b;
if (a < 0) a += MOD;
}
int mul(int a, int b) {
long long c = 1ll * a * b;
return c - c / MOD * MOD;
}
int n, c;
int f[MAXN], cnt[MAXN];
bool ok(int x) {
int res = c, v = f[c];
bool has = true;
while (res && v) {
if (has && res >= x && v < x) {
has = false;
res -= x;
} else {
res -= min(cnt[v], res / v) * v;
v = min(f[v - 1], f[res]);
}
}
return res != 0;
}
int main() {
scanf("%d%d", &c, &n);
int x;
for (int i = 1; i < n + 1; i++) scanf("%d", &x), cnt[x]++;
for (int i = 1; i < c + 1; i++) f[i] = cnt[i] > 0 ? i : f[i - 1];
int ans = -1;
for (int i = 1; i < c + 1; i++) {
if (ok(i)) {
ans = i;
break;
}
}
if (ans != -1)
printf("%d\n", ans);
else
puts("Greed is good");
}
| 11 | CPP |
n=int(input())
a,b=1,1
c=list(map(int,input().split()))
for i in range(n-1):
a+=1
if c[i]>c[i+1]:
a=1
elif a>b:
b=a
print(b)
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
bool chkmax(T &a, T b) {
return a < b ? a = b, 1 : 0;
}
template <typename T>
bool chkmin(T &a, T b) {
return a > b ? a = b, 1 : 0;
}
const int maxn = 1e5 + 1e2;
struct node {
int to, nxt;
} e[maxn << 1];
int n;
int tot;
double suma, sumb, S, Ans;
int head[maxn], size[maxn];
double a[maxn], b[maxn];
inline void file() {
freopen("CF123E.in", "r", stdin);
freopen("CF123E.out", "w", stdout);
}
inline int read() {
int x = 0, p = 1;
char c = getchar();
while (!isdigit(c)) {
if (c == '-') p = -1;
c = getchar();
}
while (isdigit(c)) {
x = (x << 1) + (x << 3) + (c - '0');
c = getchar();
}
return x * p;
}
inline void add(int from, int to) {
e[++tot] = (node){to, head[from]};
head[from] = tot;
e[++tot] = (node){from, head[to]};
head[to] = tot;
}
void dfs(int u, int fa) {
size[u] = 1;
for (int i = head[u]; i != 0; i = e[i].nxt) {
int v = e[i].to;
if (v == fa) continue;
dfs(v, u);
size[u] += size[v];
a[u] += a[v];
Ans += 1.0 * size[v] * a[v] * b[u];
}
Ans += 1.0 * (n - size[u]) * (1 - a[u]) * b[u];
}
int main() {
n = read();
for (int i = (int)1; i <= (int)n - 1; ++i) {
int x = read(), y = read();
add(x, y);
}
for (int i = (int)1; i <= (int)n; ++i) {
a[i] = read();
b[i] = read();
suma += a[i];
sumb += b[i];
}
for (int i = (int)1; i <= (int)n; ++i) a[i] /= suma, b[i] /= sumb;
dfs(1, 0);
printf("%.12lf", Ans);
return 0;
}
| 11 | CPP |
t = int(input())
for i in range(t):
n, m = input().split()
n = int(n)
m = int(m)
if n == m:
print(0)
elif n < m:
if (m - n) % 2 == 1:
print(1)
else:
print(2)
else:
if (n - m) % 2 == 1:
print(2)
else:
print(1) | 7 | PYTHON3 |
//कर्मण्येवाधिकारस्ते मा फलेषु कदाचन।
//मा कर्मफलहेतुर्भूर्मा ते सङ्गोऽस्त्वकर्मणि॥
//क्रोधाद्भवति संमोह: संमोहात्स्मृतिविभ्रम:।
//स्मृतिभ्रंशाद्बुद्धिनाशो बुद्धिनाशात्प्रणश्यति॥
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>
#include<map>
#define ll long long
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll int t;
cin>>t;
for(int p = 0; p < t; p++)
{
int n;
cin>>n;
unsigned char a = n;
ll int i = 0;
while (n!=0)
{
n>>=1;
i++;
}
ll int k = pow(2,i-1)-1;
cout<<k<<endl;
}
return 0;
} | 7 | CPP |
l=[0]*1000
c=0
s=input().split()
for i in s:
if i=="+":
l[c-2]=l[c-2]+l[c-1]
c=c-1
elif i=="-":
l[c-2]=l[c-2]-l[c-1]
c=c-1
elif i=="*":
l[c-2]=l[c-2]*l[c-1]
c=c-1
else:
l[c]=int(i)
c=c+1
print(l[0])
| 0 | PYTHON3 |
n=int(input())
a=list(map(int,input().strip().split()))
count=1
l=[]
for i in range(1,len(a)):
if a[i-1]<=a[i]:
count+=1
else:
l.append(count)
count=1
l.append(count)
print(max(l)) | 7 | PYTHON3 |
#include <bits/stdc++.h>
template <class T>
bool ckmin(T& a, const T& b) {
return b < a ? a = b, 1 : 0;
}
template <class T>
bool ckmax(T& a, const T& b) {
return a < b ? a = b, 1 : 0;
}
using namespace std;
using namespace chrono;
void solve() {
long long int n;
cin >> n;
vector<long long int> arr(n);
long long int sum = 0;
long long int check[2] = {0};
for (long long int i = 0; i < n; ++i) {
cin >> arr[i];
sum += arr[i];
if (arr[i] == 0) {
check[0]++;
} else if (arr[i] == -1)
check[1]++;
}
if (check[0] == 0 && sum != 0)
cout << 0 << '\n';
else {
long long int operation = 0;
if (check[0] != 0) {
operation += check[0];
sum += operation;
if (sum == 0)
cout << operation + 1 << '\n';
else
cout << operation << '\n';
} else
cout << 1 << '\n';
}
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
auto start1 = high_resolution_clock::now();
long long int t = 1;
cin >> t;
while (t--) {
solve();
}
auto stop1 = high_resolution_clock::now();
auto duration = duration_cast<microseconds>(stop1 - start1);
return 0;
}
| 7 | CPP |
k = int(input())
a = sorted(list(map(int, input().split())), reverse = True)
if sum(a) < k:
print(-1)
elif k == 0:
print(0)
else:
cnt = 0
for i in range(12):
cnt += a[i]
if cnt >= k:
print(i + 1)
break
| 7 | PYTHON3 |
n=int(input())
ls=list()
mx=1
for i in range(n):
x=input()
ls.append(x)
for i in range(1,n):
if ls[i]!=ls[i-1]:mx+=1
print(mx) | 7 | PYTHON3 |
try:
while True:
n = int(input())
string = input()
ls = 0
rs = 0
for char in string:
if (char == "L"):
ls += 1
if (char == "R"):
rs += 1
print(ls + rs + 1)
except EOFError:
pass | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int MAXn = 21, MAXx = (1 << 20), anti = MAXx - 1;
long double sum[MAXx], dp[MAXx], prob[MAXn];
int n, k, kk;
vector<int> vec[MAXn + 2];
bool flag[MAXx];
int main() {
cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> prob[i];
if (prob[i] > 0) kk++;
}
k = min(kk, k);
for (int i = 0; i < MAXx; i++) vec[__builtin_popcount(i)].push_back(i);
for (int i = 0; i < MAXx; i++)
for (int j = 0; j < MAXn; j++)
if ((i >> j) & 1) sum[i] += prob[j];
dp[0] = 1;
for (int i = 1; i < MAXx; i++) dp[i] = 0;
for (int i = 1; i <= k; i++)
for (int j = 0; j < vec[i].size(); j++)
for (int x = 0; x < n; x++) {
int hp = vec[i][j];
if (prob[x] == (long double)0 && ((hp >> x) & 1)) {
dp[hp] = 0;
break;
}
if ((hp >> x) & 1)
dp[hp] += (long double)(prob[x] / sum[anti ^ (hp - (1 << x))]) *
dp[(hp - (1 << x))];
}
for (int i = 0; i < n; i++) {
long double ans = 0;
for (int j = 0; j < vec[k].size(); j++)
if ((vec[k][j] >> i) & 1) ans += dp[vec[k][j]];
cout << fixed << setprecision(7) << ans << ' ';
}
return 0;
}
| 11 | CPP |
n=int(input())
for i in range (n):
a,b=input().split()
b=int(b)
print(b*2)
| 7 | PYTHON3 |
import sys
def fastio():
from io import StringIO
from atexit import register
global input
sys.stdin = StringIO(sys.stdin.read())
input = lambda : sys.stdin.readline().rstrip('\r\n')
sys.stdout = StringIO()
register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()
def debug(*var, sep = ' ', end = '\n'):
print(*var, file=sys.stderr, end = end, sep = sep)
INF = 10**20
MOD = 10**9 + 7
I = lambda:list(map(int,input().split()))
from math import gcd
from math import ceil
from collections import defaultdict as dd, Counter
from bisect import bisect_left as bl, bisect_right as br
n, = I()
a = list(input())
x = a.count('x')
X = a.count('X')
ans = abs(X - x) // 2
if x > X:
for i in range(n):
if a[i] == 'x' and x != X:
a[i] = 'X'
x -= 1
X += 1
if x < X:
for i in range(n):
if a[i] == 'X' and x != X:
a[i] = 'x'
x += 1
X -= 1
print(ans)
print(''.join(a)) | 7 | PYTHON3 |
if __name__ == "__main__":
casos = int(input())
for i in range(casos):
cuadrados = int(input())
tam = cuadrados * 4
longitudes = list(map(int,input().split()))
longitudes.sort()
area = longitudes[0] * longitudes[tam - 1]
ans = True
for j in range(0, cuadrados):
if (longitudes[2*j] != longitudes[2*j+1]) or (longitudes[tam - 2*j - 1] != longitudes[tam - 2*j - 2]):
ans = False
break
elif longitudes[2*j] * longitudes[tam - 2*j - 1] != area:
ans = False
break
if ans:
print("YES")
else:
print("NO")
| 8 | PYTHON3 |
n,k=map(int,input().split())
x=list(map(int,input().split()))
l=[]
for i in range(n-k+1):
l.append(x[i+k-1]-x[i]+min(abs(x[i+k-1]),abs(x[i])))
print(min(l)) | 0 | PYTHON3 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=200010;
int n,k;
int a[maxn];
ll sum[maxn], num[maxn], ans, c[maxn];
int cnt;
int lowbit(int x){ return x&(-x); }
ll Sum(int x){
ll ret=0;
while(x){ ret+=c[x]; x-=lowbit(x); }
return ret;
}
void add(int x){ while(x<maxn){ c[x]++; x+=lowbit(x); } }
int main(){
scanf("%d%d",&n,&k);
for(int i=1;i<=n;i++) scanf("%d",&a[i]), a[i]-=k, sum[i]=sum[i-1]+a[i];
for(int i=1;i<=n;i++) num[++cnt]=sum[i];
num[++cnt]=0;
sort(num+1,num+1+cnt);
cnt=unique(num+1,num+1+cnt)-num-1;
add(lower_bound(num+1,num+1+cnt,0)-num);
for(int i=1;i<=n;i++){
ans+=Sum(lower_bound(num+1,num+1+cnt,sum[i])-num);
add(lower_bound(num+1,num+1+cnt,sum[i])-num);
}
printf("%lld\n", ans);
return 0;
} | 0 | CPP |
from sys import stdin, stdout
s = list(stdin.readline().strip())
cnt = [0, 0, 0, 0]
n = len(s)
for i in range(n):
if s[i] == 'R':
for j in range(i + 4, n, 4):
if s[j] == '!':
s[j] = 'R'
cnt[0] += 1
for j in range(i - 4, -1, -4):
if s[j] == '!':
s[j] = 'R'
cnt[0] += 1
if s[i] == 'B':
for j in range(i + 4, n, 4):
if s[j] == '!':
s[j] = 'B'
cnt[1] += 1
for j in range(i - 4, -1, -4):
if s[j] == '!':
s[j] = 'B'
cnt[1] += 1
if s[i] == 'Y':
for j in range(i + 4, n, 4):
if s[j] == '!':
s[j] = 'Y'
cnt[2] += 1
for j in range(i - 4, -1, -4):
if s[j] == '!':
s[j] = 'Y'
cnt[2] += 1
if s[i] == 'G':
for j in range(i + 4, n, 4):
if s[j] == '!':
s[j] = 'G'
cnt[3] += 1
for j in range(i - 4, -1, -4):
if s[j] == '!':
s[j] = 'G'
cnt[3] += 1
stdout.write(' '.join(list(map(str, cnt)))) | 8 | PYTHON3 |
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
int main(){
int t,a[3],k;
cin>>t;
while(t--){
cin>>a[0]>>a[1]>>a[2];
sort(a,a+3);
k=a[0]+a[2]+a[1];
if(k%9==0){
if(a[0]>=k/9){
cout<<"YES"<<endl;
}
else{
cout<<"NO"<<endl;
}
}
else{
cout<<"NO"<<endl;
}
}
return 0;
} | 7 | CPP |
def main():
n = int(input())
seq = [int(c) for c in input().split()]
alt = [[0, 0]]
prev = seq[0]
for i, e in enumerate(seq):
if e != prev:
alt[-1][1] += 1
else:
alt.append([i, i])
prev = e
alt = [e for e in alt if e[1] - e[0] + 1 > 2]
steps = 0
for a, b in alt:
length = b - a + 1
steps = max(steps, (length + 1) // 2 - 1)
if length % 2 == 1:
for i in range(a, b + 1):
seq[i] = seq[a]
else:
for i in range(a, a + length // 2):
seq[i] = seq[a]
for i in range(a + length // 2, b + 1):
seq[i] = seq[b]
print(steps)
print(*seq)
if __name__ == "__main__":
main()
| 9 | PYTHON3 |
a=int(input())
ans=[]
for i in range(a):
b=int(input())
l=list(map(int,input().split()))
ch=0
nc=0
for j in range(b):
if l[j]%2==0:
ch+=1
else:
nc+=1
if nc>0:
if ch>0:
ans.append('YES')
elif nc%2!=0:
ans.append('YES')
else:
ans.append('NO')
else:
ans.append('NO')
for i in range(a):
print(ans[i]) | 7 | PYTHON3 |
def prime():
prime = [1] * 1000001
prime[0] = prime[1] = 0
for i in range(2, 1001):
if(prime[i] == 1):
for c in range(i*i, 1000001, i):
prime[c] = 0
return prime
def root(num):
root = int(num ** 0.5) - 1
if(root * root == num):
return root
root += 1
if(root * root == num):
return root
root += 1
if(root * root == num):
return root
return -1
n = int(input())
nums = list(map(int,input().split()))
primes = prime()
for e in range(len(nums)):
croot = root(nums[e])
if(croot != -1 and primes[croot]):
print("YES")
else:
print("NO")
| 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
#define D10 fixed<<setprecision(10)
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-12;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
/*--------------------template--------------------*/
typedef int Weight;
struct Edge
{
int from, to; Weight cost;
bool operator < (const Edge& e) const { return cost < e.cost; }
bool operator > (const Edge& e) const { return cost > e.cost; }
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;
void add_edge(Graph &g, int from, int to, Weight cost)
{
g[from].push_back(Edge{ from, to, cost });
}
vs input(string& s)
{
int t = s.find('-');
string l = s.substr(0, t);
string r = s.substr(t + 1);
vs res;
res.push_back(l); res.push_back(r);
return res;
}
int main()
{
int n;
while (cin >> n, n)
{
vector<vs> v(n);
map<string, int> mp;
REP(i, n)
{
string s; cin >> s;
v[i] = input(s);
}
int p = 0;
REP(i, n)REP(j, 2)
{
string tmp = v[i][j];
if (mp.count(tmp)) continue;
mp[tmp] = p;
p++;
}
cout << p << endl;
Graph g(p);
Matrix dist(p, Array(p));
REP(i, n)
{
int l = mp[v[i][0]], r = mp[v[i][1]];
add_edge(g, l, r, 1);
add_edge(g, r, l, 1);
dist[r][l] = 1;
}
vector<pii> same;
REP(i, p)REP(j, i)
{
bool f1 = false, f2 = true;
REP(k, p)
{
if ((dist[i][k] || dist[k][i]) && (dist[j][k] || dist[k][j])) f1 = true;
if ((dist[i][k] && dist[k][j]) || (dist[k][i] && dist[j][k])) f2 = false;
}
if (f1&&f2) same.emplace_back(i, j);
}
for (auto i : same)
{
dist[i.first][i.second] = 1;
dist[i.second][i.first] = 1;
}
REP(k, p)REP(i, p)REP(j, p)
{
if (dist[i][k] && dist[k][j]) dist[i][j] = 1;
}
vi color(p);
int col = 1;
REP(i, p)
{
if (color[i]) continue;
queue<int> que;
que.push(i);
int c = col, d = -col;
color[i] = c;
while (que.size())
{
int t = que.front();
que.pop();
int nx = (color[t] == c ? d : c);
REP(j, g[t].size())
{
if (color[g[t][j].to]) continue;
color[g[t][j].to] = nx;
que.push(g[t][j].to);
}
}
col++;
}
int q;
cin >> q;
REP(i, q)
{
string s; cin >> s;
vs t = input(s);
if (!mp.count(t[0]) || !mp.count(t[1]))
{
puts("NO");
continue;
}
int l = mp[t[0]], r = mp[t[1]];
if (color[l] == -color[r] && dist[r][l])
{
puts("YES");
}
else
{
puts("NO");
}
}
}
return 0;
} | 0 | CPP |
n, d, e = [int(input()) for _ in range(3)]
DOLLAR_BILLS = [1, 2, 5, 10, 20, 50, 100]
EURO_BILLS = [5, 10, 20, 50, 100, 200]
min_rest = float('inf')
for i in range(0, n // e + 1):
if i % 5 != 0:
continue
rest = (n - (i * e)) % d
min_rest = min(min_rest, rest)
print(min_rest)
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()) {
v.assign(a, vector<T>(b, t));
}
template <class F, class T>
void convert(const F &f, T &t) {
stringstream ss;
ss << f;
ss >> t;
}
int main() {
int s = 1000000;
vector<char> rem(s + 1, 1);
int n, x;
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
scanf("%d", &x);
rem[x] = 0;
}
vector<int> ans, cand;
int cnt = 0;
for (int i = 1; i <= s; ++i) {
if (rem[i] && !rem[s - i + 1]) {
ans.push_back(i);
} else if (i * 2 <= s && rem[i] == rem[s - i + 1]) {
if (rem[i]) {
cand.push_back(i);
} else {
++cnt;
}
}
}
for (int i = 0; i < cnt; ++i) {
ans.push_back(cand[i]);
ans.push_back(s - cand[i] + 1);
}
printf("%d\n", (int)ans.size());
for (int i = ans.size(); i--;) {
printf("%d%c", ans[i], i ? ' ' : '\n');
}
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000 + 10, mod = 1e9 + 7;
int dp[maxn], a[10], fac[maxn], invfac[maxn];
int add(int a, int b) { return a + b < mod ? a + b : a + b - mod; }
int mul(int a, int b) {
return a * 1LL * b < mod ? a * 1LL * b : a * 1LL * b % mod;
}
int fpow(int a, int n) {
int ret = 1;
for (; n; n >>= 1) {
if (n & 1) ret = mul(ret, a);
a = mul(a, a);
}
return ret;
}
void init() {
fac[1] = 1;
invfac[0] = 1;
fac[0] = 1;
for (int i = 2; i < maxn; ++i) fac[i] = mul(fac[i - 1], i);
for (int i = 1; i < maxn; ++i) invfac[i] = fpow(fac[i], mod - 2);
}
int c(int n, int k) {
if (k > n) return 0;
return mul(mul(fac[n], invfac[k]), invfac[n - k]);
}
int main() {
init();
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
for (int i = 0; i < 10; ++i) cin >> a[i];
dp[0] = 1;
int cur = 0;
for (int i = 1; i <= 9; ++i) {
cur += a[i];
for (int j = n; j >= cur; --j) {
int d = 0;
for (int k = a[i]; k <= j; ++k) {
d = add(d, mul(c(j, k), dp[j - k]));
}
dp[j] = d;
}
for (int j = 0; j < cur; ++j) dp[j] = 0;
}
cur += a[0];
int ans = 0;
for (int j = n; j >= cur; --j) {
int d = 0;
for (int k = a[0]; k <= j; ++k) {
d = add(d, mul(c(j - 1, k), dp[j - k]));
}
ans = add(ans, d);
}
cout << ans << endl;
return 0;
}
| 8 | CPP |
from collections import defaultdict
import sys
input = sys.stdin.readline
'''
for CASES in range(int(input())):
n, m = map(int, input().split())
n = int(input())
A = list(map(int, input().split()))
S = input().strip()
sys.stdout.write()
'''
inf = 100000000000000000 # 1e17
mod = 998244353
for CASES in range(int(input())):
n = int(input())
if n == 2 or n == 3:
print(-1)
continue
elif n == 4:
print(3, 1, 4, 2)
continue
ANS = [i for i in range(1, n + 1, 2)]
pos = ANS[-1] - 3
ANS.append(pos)
if n % 2 == 0:
ANS.append(pos + 4)
ANS.append(pos + 2)
pos -= 2
else:
ANS.append(pos + 2)
pos -= 2
while pos > 0:
ANS.append(pos)
pos -= 2
print(*ANS)
# the end
| 13 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
scanf("%d", &n);
if (n == 1) {
printf("1\n1\n");
return 0;
}
if (n & 1) {
long long prod = 1ll * n * ((n >> 1) - 1);
long long s = sqrt(prod);
if (s * s == prod) {
printf("%d\n", n - 2);
int s1 = (n >> 1) - 2, s2 = n - 2;
for (int i = 1; i <= n; i++)
if (i != s1 && i != s2) printf("%d ", i);
putchar('\n');
return 0;
}
}
if (n & 1) n--;
int m = n >> 1;
if (m & 1) {
int x = 0, k = (m + 1) >> 1, s = sqrt(k);
if (s * s == k)
x = m + 1;
else if (m == 9)
x = 7;
if (x) {
printf("%d\n", n - 1);
for (int i = 1; i <= n; i++)
if (i != x) printf("%d ", i);
putchar('\n');
} else {
printf("%d\n", n - 2);
for (int i = 1; i <= n; i++)
if (i != 2 && i != m) printf("%d ", i);
putchar('\n');
}
} else {
printf("%d\n", n - 1);
for (int i = 1; i <= n; i++)
if (i != m) printf("%d ", i);
putchar('\n');
}
return 0;
}
| 12 | CPP |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.