solution
stringlengths 10
983k
| difficulty
int64 0
25
| language
stringclasses 2
values |
---|---|---|
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a,b,c,d,n,k;
cin>>n>>k;
int ara[n];
for(int i=0;i<n;i++) cin>>ara[i];
sort(ara,ara+n);
n-=k;
long long sum=0;
for(int i=0;i<n;i++) sum+=ara[i];
cout<<sum<<endl;
}
| 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long num[15] = {9, 18, 27, 36, 45, 54, 63, 72, 81, 90};
char N[15];
long long n, cnt;
long long output[10005];
long long cal(long long n) {
long long sum = 0;
while (n) {
sum += n % 10;
n /= 10;
}
return sum;
}
int main() {
while (cin >> n) {
sprintf(N, "%I64d", n);
long long len = strlen(N);
cnt = 0;
for (long long i = num[len - 1]; i >= 0; i--) {
if (cal(n - i) == i) {
output[cnt++] = n - i;
}
}
if (!cnt)
printf("0\n");
else {
printf("%I64d\n", cnt);
for (long long i = 0; i < cnt; i++) {
printf("%I64d\n", output[i]);
}
}
}
return 0;
}
| 9 | CPP |
n = int(input())
x = int(input())
y = int(input())
m = n
if n % x == 0:
print("YES")
print(n // x, 0)
exit()
if n % y == 0:
print("YES")
print(0, n // y)
exit()
while n > 0:
if n % y == 0 and (m - n) % x == 0:
print("YES")
print((m - n) // x, n // y)
exit()
n -= x
print("NO") | 8 | PYTHON3 |
a,b,c,n=map(int,input().split())
if n<=a+b:
print(min(a,n))
else:
print(a-(n-a-b)) | 0 | PYTHON3 |
n = int(input())
w = []
for _ in range(n):
s = input()
if len(set(s)) <= 2:
w.append(s)
d = set()
for s in w:
d |= set(s)
d = list(d)
m = 0
for i in range(0, len(d)):
for j in range(i, len(d)):
total = 0
s = set([d[i], d[j]])
for x in w:
if set(x) <= s:
total += len(x)
m = max(m, total)
print(m)
| 7 | PYTHON3 |
while(True):
n = int(input())
if n == 0:
break
arr = []
for i in range(n):
arr.append(list(map(int, input().split())))
arr = [ l+[sum(l)] for l in arr]
brr = [0]*(n+1)
for i in range(n):
for j in range(n+1):
brr[j] += arr[i][j]
crr = arr+[brr]
for c in crr:
for d in c:
print("%5d"%d,end="")
print()
| 0 | PYTHON3 |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2010,M=30005,inf=0x3f3f3f3f;
int read(){
int f=1,g=0;
char ch=getchar();
for (;!isdigit(ch);ch=getchar()) if (ch=='-') f=-1;
for (;isdigit(ch);ch=getchar()) g=g*10+ch-'0';
return f*g;
}
int cnt,n,m,S,T;
ll cost;
int fir[N],siz;
struct edge{int v,w,fl,re;};
vector<edge> e[N];
void add(int u,int v,int w,int fl){
e[u].push_back((edge){v,w,fl,(int)e[v].size()});
e[v].push_back((edge){u,-w,0,(int)e[u].size()-1});
}
ll dist[N];
int dis[N];
vector<int> que;
bool inq[N];
bool spfa(){
memset(dist,0xA0,8*(cnt+1));
memset(inq,0,cnt+1);
dist[S]=0;inq[S]=1;
que.clear();que.push_back(S);
for (unsigned i=0;i<que.size();i++){
int x=que[i];
for (auto cur : e[x])
if (cur.fl&&(dist[cur.v]<dist[x]+cur.w)){
if (!inq[cur.v]) {que.push_back(cur.v);inq[cur.v]=1;}
dist[cur.v]=dist[x]+cur.w;
}
inq[x]=0;
}
return dist[T]>=0;
}
void bfs(){
memset(dis,0x3f,4*(cnt+1));
dis[S]=0;
que.clear();que.push_back(S);
for (unsigned i=0;i<que.size();i++){
int x=que[i];
for (auto cur : e[x])
if ((dist[cur.v]==dist[x]+cur.w)&&cur.fl&&(dis[cur.v]>dis[x]+1)){
que.push_back(cur.v);
dis[cur.v]=dis[x]+1;
}
}
return;
}
int dfs(int x,int flow){
if (x==T) return flow;
int fl=0,t=0;
for (unsigned i=fir[x];i<e[x].size();i++){
edge &cur=e[x][i];
if ((dist[cur.v]==dist[x]+cur.w)&&cur.fl&&(dis[cur.v]>dis[x])){
t=dfs(cur.v,min(flow-fl,cur.fl));
fl+=t;cur.fl-=t;e[cur.v][cur.re].fl+=t;
if (fl==flow) {fir[x]=i;return fl;}
}
}
fir[x]=e[x].size();
return fl;
}
int dinic(){
int flow=0;
while (spfa()){
bfs();
for (int i=0;i<=cnt;i++) fir[i]=0;
int cur=dfs(S,inf);
flow+=cur;
cost+=(ll)dist[T]*cur;
}
return flow;
}
int main(){
n=read();
S=0;T=cnt=n*2+5;
for (int i=1;i<=n;i++){
int x=read(),y=read(),c=read();
add(S,i,0,c);
add(i,n*2+1,x+y,c);
add(i,n*2+2,x-y,c);
add(i,n*2+3,-x+y,c);
add(i,n*2+4,-x-y,c);
}
for (int i=n+1;i<=n+n;i++){
int x=read(),y=read(),c=read();
add(i,T,0,c);
add(n*2+1,i,-x-y,c);
add(n*2+2,i,-x+y,c);
add(n*2+3,i,x-y,c);
add(n*2+4,i,x+y,c);
}
dinic();
printf("%lld\n",cost);
return 0;
} | 0 | CPP |
for _ in range(int(input())):
t=int(input())
n=2
while(1):
if t%(2**n-1)==0:
break
n=n+1
print(t//(2**n-1))
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while (t--) {
long int n;
cin >> n;
bool ones = true;
int count = 0;
vector<long long int> a(n);
for (long int i = 0; i < n; i++) {
cin >> a[i];
if (a[i] != 1) ones = false;
count++;
}
if (ones) {
if (count % 2 != 0)
cout << "First" << endl;
else
cout << "Second" << endl;
continue;
}
bool hand = false;
for (long int i = 0; i < n; i++) {
if (a[i] == 1)
hand = !hand;
else
break;
}
if (!hand)
cout << "First" << endl;
else
cout << "Second" << endl;
}
return 0;
}
| 8 | CPP |
num_of_word =int( input() )
L=['0']*100
for i in range(num_of_word) :
L[i]=input()
for j in range(num_of_word) :
if len(L[j])>10 :
print(L[j][0]+str((len(L[j])-2))+L[j][-1])
else:
print(L[j])
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
long long i, j, k, m, n, t, u[10005], v[10005], w[10005], x[10005], y[10005],
z[10005];
string s[105];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
for (cin >> t; t--;) {
cin >> n >> m;
for (i = k = 0; i < n; i++) cin >> s[i];
for (i = 0; i < n - 2; i++) {
for (j = 0; j < m; j++) {
if (s[i][j] & 1) {
if (j) {
u[++k] = i;
v[k] = j;
w[k] = i + 1;
x[k] = j;
y[k] = i + 1;
z[k] = j - 1;
s[i][j] ^= 1;
s[i + 1][j] ^= 1;
s[i + 1][j - 1] ^= 1;
} else {
u[++k] = i;
v[k] = j;
w[k] = i + 1;
x[k] = j;
y[k] = i + 1;
z[k] = j + 1;
s[i][j] ^= 1;
s[i + 1][j] ^= 1;
s[i + 1][j + 1] ^= 1;
}
}
}
}
for (j = 0; j < m - 1; j++) {
if (s[n - 2][j] == 49 && s[n - 1][j] == 49) {
u[++k] = n - 2;
v[k] = j;
w[k] = n - 1;
x[k] = j;
y[k] = n - 1;
z[k] = j + 1;
s[n - 2][j] ^= 1;
s[n - 1][j] ^= 1;
s[n - 1][j + 1] ^= 1;
} else if (s[n - 2][j] == 49 && s[n - 1][j] == 48) {
u[++k] = n - 2;
v[k] = j;
w[k] = n - 2;
x[k] = j + 1;
y[k] = n - 1;
z[k] = j + 1;
s[n - 2][j] ^= 1;
s[n - 2][j + 1] ^= 1;
s[n - 1][j + 1] ^= 1;
} else if (s[n - 2][j] == 48 && s[n - 1][j] == 49) {
u[++k] = n - 1;
v[k] = j;
w[k] = n - 1;
x[k] = j + 1;
y[k] = n - 2;
z[k] = j + 1;
s[n - 1][j] ^= 1;
s[n - 1][j + 1] ^= 1;
s[n - 2][j + 1] ^= 1;
}
}
if (s[n - 2][m - 1] == 49 && s[n - 1][m - 1] == 49) {
u[++k] = n - 2;
v[k] = m - 1;
w[k] = n - 2;
x[k] = m - 2;
y[k] = n - 1;
z[k] = m - 2;
u[++k] = n - 1;
v[k] = m - 1;
w[k] = n - 2;
x[k] = m - 2;
y[k] = n - 1;
z[k] = m - 2;
} else if (s[n - 2][m - 1] == 49 && s[n - 1][m - 1] == 48) {
u[++k] = n - 2;
v[k] = m - 1;
w[k] = n - 2;
x[k] = m - 2;
y[k] = n - 1;
z[k] = m - 2;
u[++k] = n - 1;
v[k] = m - 1;
w[k] = n - 2;
x[k] = m - 2;
y[k] = n - 2;
z[k] = m - 1;
u[++k] = n - 1;
v[k] = m - 1;
w[k] = n - 1;
x[k] = m - 2;
y[k] = n - 2;
z[k] = m - 1;
} else if (s[n - 2][m - 1] == 48 && s[n - 1][m - 1] == 49) {
u[++k] = n - 1;
v[k] = m - 1;
w[k] = n - 2;
x[k] = m - 2;
y[k] = n - 1;
z[k] = m - 2;
u[++k] = n - 1;
v[k] = m - 1;
w[k] = n - 2;
x[k] = m - 2;
y[k] = n - 2;
z[k] = m - 1;
u[++k] = n - 1;
v[k] = m - 1;
w[k] = n - 1;
x[k] = m - 2;
y[k] = n - 2;
z[k] = m - 1;
}
cout << k << '\n';
for (i = 0; i++ < k;) {
cout << u[i] + 1 << ' ' << v[i] + 1 << ' ' << w[i] + 1 << ' ' << x[i] + 1
<< ' ' << y[i] + 1 << ' ' << z[i] + 1 << '\n';
}
}
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 5005;
long long f[2][N];
int q[N], a[N];
int main() {
for (int i = 0; i < N; i++) f[0][i] = -1e18;
int n, k, m;
scanf("%d%d%d", &n, &k, &m);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
f[0][0] = 0;
for (int i = 1; i <= m; i++) {
int front = 0, tail = -1;
for (int j = 0; j <= n; j++) {
if (front <= tail && q[front] < j - k) front++;
if (front <= tail) f[i & 1][j] = f[i - 1 & 1][q[front]] + a[j];
while (front <= tail && f[i - 1 & 1][j] >= f[i - 1 & 1][q[tail]]) tail--;
q[++tail] = j;
}
}
long long ans = -1;
for (int i = n - k + 1; i <= n; i++) ans = max(ans, f[m & 1][i]);
printf("%lld", ans);
}
| 12 | CPP |
for _ in range(int(input())):
s=input("")
ans=""
i=0
ok=False
while(i<len(s)):
if i==len(s)-2:
ok=True
ans+=s[i]+s[i+1]
i+=4
if ok==False:
ans+=s[-1]
print(ans)
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int t, n;
cin >> t;
while (t--) {
cin >> n;
if (n % 2)
cout << (n + 1) / 2 << endl;
else
cout << n / 2 << endl;
}
}
| 7 | CPP |
t = int(input())
if t == 1:
print(1)
print(1)
else:
i = 9
while i >= 1:
if t % i == 0:
print(int(t/i))
for j in range(int(t/i)):
print(i, end=" ")
break
i = i - 1
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int arr[100005];
bool ck(int n) {
for (int i = n; i > 0; i--) {
if (!arr[i]) return 0;
}
for (int i = 1; i <= n; i++) {
arr[i]--;
}
return 1;
}
int main() {
int n, i, m, k, j, cnt = 0;
scanf("%d%d", &n, &m);
for (i = 1; i <= m; i++) {
scanf("%d", &k);
if (!arr[k]) cnt++;
arr[k]++;
if (cnt == n) {
printf("1");
for (j = 1; j <= n; j++) {
arr[j]--;
if (!arr[j]) cnt--;
}
} else
printf("0");
}
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
const int N = 645, M = N * N, u[] = {1, 0, -1, 0}, v[4] = {0, 1, 0, -1};
bool b[N];
int n, m, S, T, l = 1, ans, a[85][85], d[N], f[M], ed[M], st[M], next[M],
cost[M], data[M], son[N], pre[N];
void add(int x, int y, int z) {
st[++l] = x, ed[l] = y, data[l] = 1, cost[l] = z, next[l] = son[x],
son[x] = l;
st[++l] = y, ed[l] = x, data[l] = 0, cost[l] = -z, next[l] = son[y],
son[y] = l;
}
int main() {
scanf("%d%d", &n, &m), S = n * m, T = S + 1;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++) {
scanf("%d", a[i] + j);
if (i + j & 1)
add(S, i * m + j, 0);
else
add(i * m + j, T, 0);
}
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
if (i + j & 1)
for (int k = 0; k < 4; k++) {
int x = i + u[k], y = j + v[k];
if (x >= 0 && x < n && y >= 0 && y < m)
add(i * m + j, x * m + y, a[i][j] != a[x][y]);
}
for (;;) {
int h = 0, t = 1;
f[1] = S;
memset(d, 6, sizeof(d)), d[S] = 0;
while (h < t) {
int x = f[++h];
b[x] = 0;
for (int p = son[x]; p; p = next[p])
if (data[p]) {
int y = ed[p];
if (d[x] + cost[p] < d[y]) {
d[y] = d[x] + cost[p], pre[y] = p;
if (!b[y]) b[y] = 1, f[++t] = y;
}
}
}
if (d[T] >= 1 << 20) break;
ans += d[T];
for (int p = T; p != S; p = st[p]) p = pre[p], data[p]--, data[p ^ 1]++;
}
printf("%d\n", ans);
return 0;
}
| 9 | CPP |
n=int(input())
arr=input()
l=list(map(int,arr.split()))
n==int(len(arr))
i=int(sum(l))
if i== 0:
print('EASY')
else:
print('HARD')
| 7 | PYTHON3 |
n,k=map(int,input().split())
a=list(map(int,input().split()))
s=input()
i,j,dmg=0,1,0
while j<n:
if(s[j]==s[i]):
j+=1
else:
dmg+=sum(sorted(a[i:j])[-k:])
i,j=j,j+1
dmg+=sum(sorted(a[i:])[-k:])
print(dmg) | 9 | PYTHON3 |
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
typedef long long lint;
const int N=5e5+5;
int n,q;
struct data{
int w;
double t;
};
namespace utils{
inline int nxi(FILE *fd=stdin){
int x=0;
char c;
while(((c=fgetc(fd))>'9'||c<'0')&&c!='-');
const bool f=(c=='-')&&(c=fgetc(fd));
while(x=x*10-48+c,(c=fgetc(fd))>='0'&&c<='9');
return f?-x:x;
}
template <class T>
inline void apx(T &x,const T y){
x<y?x=y:0;
}
template <class T>
inline void apn(T &x,const T y){
x>y?x=y:0;
}
}
using namespace utils;
int main(){
static data dq[N];
double sumt=0;
int hd=0,tl=0,sumw=0;
n=nxi(),q=nxi();
for(int i=1; i<=n; ++i){
int t=nxi(),w=nxi();
dq[tl++]=(data){w,(double)t};
sumw+=w;
sumt+=(lint)t*w;
for(; tl-1>hd&&dq[tl-1].t<dq[tl-2].t; --tl){
int oflow=std::max(0,dq[tl-2].w+dq[tl-1].w-q);
sumw-=oflow;
sumt-=dq[tl-2].t*oflow;
assert(oflow<=dq[tl-2].w);
int w0=dq[tl-2].w-oflow,w1=dq[tl-1].w;
dq[tl-2].t=(dq[tl-2].t*w0+dq[tl-1].t*w1)/(w0+w1);
dq[tl-2].w+=dq[tl-1].w-oflow;
}
for(; sumw>q&&hd<tl; ++hd){
int wgt=std::min(sumw-q,dq[hd].w);
dq[hd].w-=wgt;
sumw-=wgt;
sumt-=wgt*dq[hd].t;
if(sumw==q) break;
}
assert(hd<tl);
printf("%.8lf\n",sumt/sumw);
}
return 0;
}
| 0 | CPP |
def case():
n = int(input())
a = list(map(int, input().split()))
ans = []
if n % 2 == 0: # easy
for i in range(0, n, 2):
ans.append(a[i+1])
ans.append(-a[i])
else: # harder
if a[0] + a[1] != 0:
ans = [a[2], a[2], -(a[0] + a[1])]
elif a[0] + a[2] != 0:
ans = [a[1], -(a[0] + a[2]), a[1]]
else: # a[1] + a[2] != 0
ans = [-(a[1] + a[2]), a[0], a[0]]
for i in range(3, n, 2):
ans.append(a[i+1])
ans.append(-a[i])
print(' '.join(map(str, ans)))
def main():
T = int(input())
for _ in range(T):
case()
if __name__ == '__main__':
main() | 10 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
set<vector<bool>> ch;
int dfs(vector<bool> arr, int i) {
int res = 0;
if (!(i < arr.size())) {
return (int)(ch.count(arr));
} else {
if (!arr[i]) {
res += dfs(arr, i + 1);
arr[i] = 1;
res += dfs(arr, i + 1);
} else
res += dfs(arr, i + 1);
}
return res;
}
int main() {
int n;
cin >> n;
vector<vector<bool>> seg(10, vector<bool>(7, 0));
seg[0] = {1, 1, 1, 1, 1, 1, 0};
seg[1] = {0, 1, 1, 0, 0, 0, 0};
seg[2] = {1, 1, 0, 1, 1, 0, 1};
seg[3] = {1, 1, 1, 1, 0, 0, 1};
seg[4] = {0, 1, 1, 0, 0, 1, 1};
seg[5] = {1, 0, 1, 1, 0, 1, 1};
seg[6] = {1, 0, 1, 1, 1, 1, 1};
seg[7] = {1, 1, 1, 0, 0, 0, 0};
seg[8] = {1, 1, 1, 1, 1, 1, 1};
seg[9] = {1, 1, 1, 1, 0, 1, 1};
for (auto i : seg) ch.insert(i);
cout << dfs(seg[n / 10], 0) * dfs(seg[n % 10], 0) << endl;
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
long n,m,ans=1;
cin >> n >> m;
map<long,long> pf;
for(long i=2;true;i++) {
while(m%i==0) pf[i]++,m/=i;
if(m<i*i) {
if(m!=1) pf[m]++;
break;
}
}
for(auto itr=pf.begin();itr!=pf.end();itr++) {
long a=1,b=1;
for(long i=1;i<=(*itr).second;i++) {
a=a*((*itr).second+n-1-i+1)%1000000007;
b=b*i%1000000007;
}
long c=1;
for(long j=1;j<=1000000005;j=j*2) {
if(1000000005/j%2==1) c=c*b%1000000007;
b=b*b%1000000007;
}
ans=a*c%1000000007*ans%1000000007;
}
cout << ans << endl;
} | 0 | CPP |
N, x = map(int, input().split())
A = list(map(int, input().split()))
ans = 0
pre_ai = A[0]
for i in range(1, N):
ai = A[i]
over = max(pre_ai + ai - x, 0)
ans += over
pre_ai = max(ai - over, 0)
print(ans) | 0 | PYTHON3 |
x, y = input().split()
print(1 if x != y else x) | 7 | PYTHON3 |
import sys
from collections import defaultdict
from heapq import nlargest
Input=lambda:map(int,input().split())
n = int(input())
s = input()
a = s.count('x')
b = n//2
print(abs(b-a))
if b < a:
a-=b
s = s.replace('x','X',a)
elif b > a:
b-=a
s = s.replace('X','x',b)
print(s) | 7 | PYTHON3 |
import sys
input = sys.stdin.readline
I = lambda : list(map(int,input().split()))
n,=I()
l=sorted(I())
an=1;c=1;cr=l[0]
i=1
while i<n:
if l[i]>l[i-1]:
an=max(an,(c+cr)//(cr+1))
cr=l[i]
c+=1;i+=1
an=max(an,((c+cr)//(cr+1)))
print(an)
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
int arr[n];
int ans = 0;
for (int i = 0; i < n; i++) {
scanf("%d", &arr[i]);
}
for (int i = 0; i < n - 1; i++) {
int t = arr[i] + arr[i + 1];
if (t < k) {
arr[i + 1] += k - t;
ans += (k - t);
}
}
printf("%d\n", ans);
for (int i = 0; i < n; i++) {
printf("%d ", arr[i]);
}
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, i;
cin >> n;
long long c1 = 0, c2 = 0;
string s, p, r;
cin >> s;
for (i = 0; i < n; i++) p.push_back(s[i]);
sort(p.begin(), p.end());
for (i = n; i < 2 * n; i++) r.push_back(s[i]);
sort(r.begin(), r.end());
for (i = 0; i < p.size(); i++) {
if (p[i] < r[i]) c1++;
}
for (i = 0; i < p.size(); i++) {
if (p[i] > r[i]) c2++;
}
if (c1 == n || c2 == n)
cout << "YES\n";
else
cout << "NO\n";
}
| 8 | CPP |
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#define COUNT(i, n) for(int i = 1; i <= n; i ++)
#define rep(i, n) for(int i = 0; i < n; i ++)
#define ITER(c) __typeof((c).begin())
#define each(c, it) for(ITER(c) it =(c).begin(); it!=(c).end(); it++)
#define ALL(c) c.begin(), c.end()
#define mp make_pair
#define pb push_back
#define MEMSET(v, h) memset((v), h, sizeof(v))
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;
const int INF = 1 << 24;
const int N = 10000;
int main(void){
vs t(N + 1);
COUNT(i, N){
stringstream ss;
if(!(i % 5) || !(i % 3)){
if(!(i % 3)) ss << "Fizz";
if(!(i % 5)) ss << "Buzz";
}
else ss << i;
t[i] = ss.str();
}
for(int m, n; cin >> m >> n, m; cout << endl){
queue<int> rest;
COUNT(i, m) rest.push(i);
COUNT(i, n){
int cur = rest.front(); rest.pop();
string s; cin >> s;
if(t[i] == s || rest.empty()) rest.push(cur);
}
vi res;
while(!rest.empty()) res.pb(rest.front()), rest.pop();
sort(ALL(res));
rep(i, res.size()) cout << (i ? " ":"") << res[i];
}
return 0;
} | 0 | CPP |
#include <iostream>
#include <cmath>
using namespace std;
int main() {
double x_a, y_a, x_b, y_b, x_c, y_c, x_d, y_d;
while (cin >> x_a >> y_a >> x_b >> y_b >> x_c >> y_c >> x_d >> y_d) {
double dx1 = x_b - x_a;
double dy1 = y_b - y_a;
double dx2 = x_c - x_d;
double dy2 = y_c - y_d;
double det = dx1 * dx2 + dy1 * dy2;
cout << ((abs(det) < 1e-10) ? "YES" : "NO") << endl;
}
}
| 0 | CPP |
#bubais code
T=int(input())
for z in range(T):
n=int(input())
s=input()
add=0
neg=list()
pos=list()
for e in s.split():
e=int(e)
add+=e
if e<0:
neg.append(e)
else:
pos.append(e)
if add==0:
print("NO")
elif add>0:
print("YES")
pos.sort(reverse=True)
for e in pos:
print(e,end=" ")
for e in neg:
print(e,end=" ")
print("")
else:
print("YES")
for e in neg:
print(e,end=" ")
for e in pos:
print(e,end=" ")
print("")
#bubaiscode
| 7 | PYTHON3 |
arr = list(input())
cap = 0
lit = 0
for i in arr:
if 64 < ord(i) < 91:
cap += 1
if 96 < ord(i) < 123:
lit += 1
for i in range(len(arr)):
if lit >= cap:
if 64 < ord(arr[i]) < 91:
arr[i] = chr(ord(arr[i])+32)
else:
if 96 < ord(arr[i]) < 123:
arr[i] = chr(ord(arr[i])-32)
print(''.join(arr))
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int a[n];
long long int diff = INT_MAX, d;
memset(a, -1, n * sizeof(int));
for (long long int i = 0; i < n; i++) {
cin >> d;
d--;
if (a[d] == -1) {
a[d] = i;
} else {
if (i - a[d] <= diff) {
diff = i - a[d];
}
a[d] = i;
}
}
if (diff == INT_MAX || n == 1) {
cout << "-1"
<< "\n";
} else
cout << ++diff << "\n";
}
return 0;
}
| 9 | CPP |
na = sum(map(int, input().split()))
nb = sum(map(int, input().split()))
n = int(input())
if na:
n1 = (na - 1) // 5 + 1
else:
n1 = 0
if nb:
n2 = (nb - 1) // 10 + 1
else:
n2 = 0
print(('NO', 'YES')[n1 + n2 <= n])
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
void InitializeStartIndexIfHasNot(int& startIndex, const int& value,
bool& isInitializedStartIndex) {
if (!isInitializedStartIndex) {
startIndex = value;
isInitializedStartIndex = true;
}
}
void UpdateBadSubstringsCount(
const int& currentIndex, const int& startIndex, int& badSubstringsCount,
const function<int(const int&)>& GetEndIndexFunc,
const function<int(const int&, const int&)> GetLengthFunc) {
int endIndex = GetEndIndexFunc(currentIndex);
int length = GetLengthFunc(startIndex, endIndex);
if (length == 0) {
return;
}
badSubstringsCount += length - 1;
}
int GetBadSubstringsCount(
const int& n, string& s, const char& startChar,
const function<void(int&)>& SetBeginIndexFunc,
const function<bool(const int&)>& IsOverFlowFunc,
const function<void(int&)>& IterateFunc,
const function<int(const int&)>& GetEndIndexFunc,
const function<int(const int&, const int&)> GetLengthFunc) {
int badSubstringsCount = 0;
int startIndex;
int i;
bool isInitializedStartIndex = false;
SetBeginIndexFunc(i);
while (true) {
if (IsOverFlowFunc(i)) {
if (isInitializedStartIndex) {
UpdateBadSubstringsCount(i, startIndex, badSubstringsCount,
GetEndIndexFunc, GetLengthFunc);
}
break;
}
if (s[i] == startChar) {
InitializeStartIndexIfHasNot(startIndex, i, isInitializedStartIndex);
UpdateBadSubstringsCount(i, startIndex, badSubstringsCount,
GetEndIndexFunc, GetLengthFunc);
startIndex = i;
}
IterateFunc(i);
}
return badSubstringsCount;
}
int GetBadSubstringsCountLeftToRight(const int& n, string& s,
const char& startChar) {
auto SetBeginIndex = [](int& i) { i = 0; };
auto IsOverFlow = [&](const int& i) { return i > n - 1; };
auto Iterate = [](int& i) { i++; };
auto GetEndIndex = [](const int& currentIndex) { return currentIndex - 1; };
auto GetLength = [](const int& startIndex, const int& endIndex) {
return endIndex - startIndex + 1;
};
return GetBadSubstringsCount(n, s, startChar, SetBeginIndex, IsOverFlow,
Iterate, GetEndIndex, GetLength);
}
int GetBadSubstringsCountRightToLeft(const int& n, string& s,
const char& startChar) {
auto SetBeginIndex = [&](int& i) { i = n - 1; };
auto IsOverFlow = [](const int& i) { return i < 0; };
auto Iterate = [](int& i) { i--; };
auto GetEndIndex = [](const int& currentIndex) { return currentIndex + 1; };
auto GetLength = [](const int& startIndex, const int& endIndex) {
return startIndex - endIndex + 1;
};
return GetBadSubstringsCount(n, s, startChar, SetBeginIndex, IsOverFlow,
Iterate, GetEndIndex, GetLength);
}
int GetDuplicatedBadSubstrings(const int& n, string& s,
const string& badSubstring) {
int count = 0;
for (int i = 0; i < n - 1; i++) {
if (s[i] == badSubstring[0] && s[i + 1] == badSubstring[1]) {
count++;
}
}
return count;
}
void DoSomething(const int& n, string& s) {
int badSubstringsCount = 0;
badSubstringsCount += GetBadSubstringsCountLeftToRight(n, s, 'A');
badSubstringsCount += GetBadSubstringsCountLeftToRight(n, s, 'B');
badSubstringsCount += GetBadSubstringsCountRightToLeft(n, s, 'A');
badSubstringsCount += GetBadSubstringsCountRightToLeft(n, s, 'B');
badSubstringsCount -= GetDuplicatedBadSubstrings(n, s, "AB");
badSubstringsCount -= GetDuplicatedBadSubstrings(n, s, "BA");
long long int totalSubstringsCount =
(long long int)n * ((long long int)n - 1) / 2;
long long int goodSubstringsCount =
totalSubstringsCount - (long long int)badSubstringsCount;
cout << goodSubstringsCount << endl;
}
int main() {
int n;
cin >> n;
string s;
cin >> s;
DoSomething(n, s);
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
scanf("%d%d", &n, &k);
if (n == k && n == 1) {
puts("a");
return 0;
}
if (n < k || k == 1) {
puts("-1");
return 0;
}
if (k == 1) {
for (int i = 0; i < n; i++) printf("a");
return 0;
}
int fl = 0;
for (int i = 0; i < n - k + 2; i++, fl ^= 1) printf("%c", fl ? 'b' : 'a');
char c = 'c';
for (int i = 0; i < k - 2; i++) printf("%c", c++);
}
| 9 | CPP |
# DFS(再帰) v:頂点
def DFS(v,dis,fin):
global time
# 訪問したので発見時刻を記入
dis[v] = time
time += 1
# vに隣接している頂点をみる
for u in V[v]:
if dis[u] is None:
DFS(u,dis,fin)
# 処理が完了したので完了時刻を記入
fin[v] = time
time += 1
n = int(input())
# 0番目を始点として初期化
V = [[i for i in range(n)]]
for i in range(n):
_, __, *a = map(int, input().split())
V.append(a)
dis = [None]*(n+1)# 頂点を発見した時刻
fin = [None]*(n+1)# 頂点の完了時刻
time = 0
DFS(0,dis,fin)
for i in range(1,n+1):
print(i, dis[i], fin[i])
| 0 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
while (true) {
int b, r, g, c, s, t;
cin >> b >> r >> g >> c >> s >> t;
if (b==0 && r==0 && g==0 && c==0 && s==0 && t==0) {
break;
}
int free_game = s;
int bonus_game = 5*b+3*r;
int normal_game = t-free_game-bonus_game;
int sub = 2*bonus_game+3*normal_game;
int add = 15*(bonus_game+b+r)+7*g+2*c;
cout << 100-sub+add << endl;
}
}
| 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
int IN() {
int c, f, x;
while (!isdigit(c = getchar()) && c != '-')
;
c == '-' ? (f = 1, x = 0) : (f = 0, x = c - '0');
while (isdigit(c = getchar())) x = (x << 1) + (x << 3) + c - '0';
return !f ? x : -x;
}
const int N = 500000 + 19;
struct node {
int a, b, c;
bool operator<(const node &B) const { return a < B.a; }
} A[N];
int mxb[N], mxc[N];
int n, p, q, r, c;
long long res;
int mn[N * 4], cov[N * 4];
long long sum[N * 4];
int Ql, Qr, Qv, pos;
void Cov(int x, int L, int R, int v) {
mn[x] = v;
cov[x] = v;
sum[x] = 1ll * v * (R - L + 1);
}
void Down(int x, int L, int R) {
if (cov[x]) {
Cov((x << 1), L, ((L + R) >> 1), cov[x]);
Cov((x << 1 | 1), ((L + R) >> 1) + 1, R, cov[x]);
cov[x] = 0;
}
}
void Build(int x, int L, int R) {
if (L == R) {
mn[x] = sum[x] = 1;
return;
}
Build((x << 1), L, ((L + R) >> 1));
Build((x << 1 | 1), ((L + R) >> 1) + 1, R);
mn[x] = min(mn[(x << 1)], mn[(x << 1 | 1)]);
sum[x] = sum[(x << 1)] + sum[(x << 1 | 1)];
}
void Modify(int x, int L, int R) {
if (Ql <= L && R <= Qr) {
Cov(x, L, R, Qv);
return;
}
Down(x, L, R);
if (Ql <= ((L + R) >> 1)) Modify((x << 1), L, ((L + R) >> 1));
if (Qr > ((L + R) >> 1)) Modify((x << 1 | 1), ((L + R) >> 1) + 1, R);
mn[x] = min(mn[(x << 1)], mn[(x << 1 | 1)]);
sum[x] = sum[(x << 1)] + sum[(x << 1 | 1)];
}
long long Qsum(int x, int L, int R) {
if (Ql <= L && R <= Qr) return sum[x];
Down(x, L, R);
long long res = 0;
if (Ql <= ((L + R) >> 1)) res += Qsum((x << 1), L, ((L + R) >> 1));
if (Qr > ((L + R) >> 1)) res += Qsum((x << 1 | 1), ((L + R) >> 1) + 1, R);
return res;
}
int Qmin2(int x, int L, int R) {
if (L == R) return L;
Down(x, L, R);
if (mn[(x << 1)] <= Qv) return Qmin2((x << 1), L, ((L + R) >> 1));
return Qmin2((x << 1 | 1), ((L + R) >> 1) + 1, R);
}
void Qmin(int x, int L, int R) {
if (~pos) return;
if (Ql <= L && R <= Qr) {
if (mn[x] <= Qv) pos = Qmin2(x, L, R);
return;
}
Down(x, L, R);
if (Ql <= ((L + R) >> 1)) Qmin((x << 1), L, ((L + R) >> 1));
if (Qr > ((L + R) >> 1)) Qmin((x << 1 | 1), ((L + R) >> 1) + 1, R);
}
void gao(int x, int y) {
pos = -1;
Ql = 1, Qr = x, Qv = y;
Qmin(1, 1, q);
if (pos == -1) return;
Ql = pos, Qr = x, Qv = y;
Modify(1, 1, q);
}
long long qry(int x, int y) {
if (x > q || y > r) return 0;
pos = -1;
Ql = x, Qr = q, Qv = y;
Qmin(1, 1, q);
if (pos == -1) pos = q + 1;
long long res = 0;
res += 1ll * (r - y + 1) * (q - pos + 1);
Ql = x, Qr = pos - 1;
if (Ql <= Qr) {
res += 1ll * (r + 1) * (Qr - Ql + 1);
res -= Qsum(1, 1, q);
}
return res;
}
int main() {
n = IN(), p = IN(), q = IN(), r = IN();
for (int i = 1; i < n + 1; i++) {
A[i] = (node){IN(), IN(), IN()};
}
sort(A + 1, A + n + 1);
for (int i = n; i; i--) {
mxb[i] = max(mxb[i + 1], A[i].b);
mxc[i] = max(mxc[i + 1], A[i].c);
}
Build(1, 1, q);
c = 1;
for (int u = 1; u <= p; u++) {
for (; c <= n && A[c].a < u; c++) {
gao(A[c].b, A[c].c + 1);
}
res += qry(mxb[c] + 1, mxc[c] + 1);
}
cout << res << endl;
}
| 10 | CPP |
t=int(input())
for i in range(t):
str=""
n,m,b=[int(a) for a in input().split()]
for j in range(n):
str+=chr(j%b + ord('a'))
print(str) | 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
long long power(long long base, long long pow, long long mo) {
long long res = 1;
while (pow) {
if (pow & 1) res = (res * base) % mo;
base = (base * base) % mo;
pow /= 2;
}
return res;
}
long long Mul(long long a, long long b, long long mo) {
long long res = 0;
a %= mo;
while (b) {
if (b & 1) res = (res + a) % mo;
a = (2 * a) % mo;
b >>= 1;
}
return res;
}
bool comp_functor(const pair<int, int> &a, const pair<int, int> &b) {
if (a.second == b.second) {
return a.first < b.first;
}
return a.second > b.second;
}
void Prime(long long n) {
while (n % 2 == 0) {
cout << 2 << " ";
n = n / 2;
}
for (int i = 3; i <= sqrt(n); i = i + 2) {
while (n % i == 0) {
cout << i << " ";
n = n / i;
}
}
if (n > 2) cout << n << " ";
}
void Divisors(int n) {
for (int i = 1; i <= sqrt(n); i++) {
if (n % i == 0) {
if (n / i == i)
printf("%d ", i);
else
printf("%d %d ", i, n / i);
}
}
}
long long gcd(long long a, long long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }
long long min(long long a, long long b) {
if (a < b) {
return a;
} else {
return b;
}
}
long long max(long long a, long long b) {
if (a > b) {
return a;
} else {
return b;
}
}
void NcR(long long n, long long r) {
long long p = 1, k = 1;
if (n - r < r) r = n - r;
if (r != 0) {
while (r) {
p *= n;
k *= r;
long long m = gcd(p, k);
p /= m;
k /= m;
n--;
r--;
}
} else
p = 1;
cout << p << "\n";
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long t, n, i, j, k, mini, l1, l2, l3, r1, r2, c, d, maxi, x, y, l, m, r,
ans, last, flag, lastind, q;
t = 1;
cin >> t;
while (t--) {
cin >> n >> m;
int a[n + 1][m + 1];
c = 0;
flag = 200;
for (i = 0; i < n; i++) {
for (j = 0; j < m; j++) {
cin >> a[i][j];
}
}
ans = 0;
for (i = 0; i < n; i++) {
for (j = 0; j < m; j++) {
if (a[i][j] < 0) {
c++;
}
ans += abs(a[i][j]);
flag = min(flag, abs(a[i][j]));
}
}
if (c % 2 == 0) {
cout << ans << "\n";
} else {
ans -= 2 * flag;
cout << ans << "\n";
}
}
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long arr[1000005];
long long cnt[1000005];
long long mat[1000005];
bool check(long long n, long long m, long long posx, long long posy) {
if (posx <= 0 || posx > n || posy <= 0 || posy > m) return false;
memset(mat, 0, sizeof mat);
for (long long i = 1; i <= n; i++) {
for (long long j = 1; j <= m; j++) {
long long dis = abs(posx - i) + abs(posy - j);
mat[dis]++;
}
}
for (long long i = 1; i <= n * m; i++) {
if (cnt[i] != mat[i]) return false;
}
return true;
}
int main() {
long long i, j, k, l, m, n, o;
long long testcase;
long long input, flag, tag, ans;
long long t;
scanf("%lld", &t);
long long b = 0;
for (i = 1; i <= t; i++) {
scanf("%lld", &arr[i]);
cnt[arr[i]]++;
b = max(b, arr[i]);
}
if (cnt[0] != 1) {
cout << -1 << endl;
return 0;
}
long long posx = -1, posy = -1;
for (i = 1; i <= t; i++) {
if (cnt[i] != (4 * i)) {
posx = i;
break;
}
}
if (posx == -1) {
cout << -1 << endl;
return 0;
}
for (n = 1; n <= t; n++) {
if (t % n) continue;
m = t / n;
posy = n + m - b - posx;
if (check(n, m, posx, posy)) {
cout << n << " " << m << endl << posx << " " << posy << endl;
return 0;
}
}
cout << -1 << endl;
}
| 10 | CPP |
n, k = map(int, input().split())
for i in range(k):
if str(n)[-1] == "0":
n //= 10
else:
n -= 1
print(n)
| 7 | PYTHON3 |
T=int(input())
for i in range(T):
s=input()
l=[0]*len(s)
d=-1
g=1
m=0
c=0
for j in range(len(s)):
if s[j]=='L':
c=c+1
else:
if m<c:
m=c
c=0
if c!=0:
if c>m:
m=c
print(m+1)
| 9 | PYTHON3 |
#include <bits/stdc++.h>
int main() {
int t;
scanf("%d", &t);
label:
while (t--) {
int n, m;
scanf("%d%d", &n, &m);
int arr[n][m];
int i, j;
for (i = 0; i < n; i++) {
for (j = 0; j < m; j++) {
scanf("%d", &arr[i][j]);
if (arr[i][j] == 0) arr[i][j] = 1;
}
}
for (i = 0; i < n; i++) {
for (j = 0; j < m; j++) {
if (arr[i][j] > 4) {
printf("NO\n");
goto label;
} else if (arr[i][j] == 3) {
if (i == 0 && j == 0 || i == n - 1 && j == 0 ||
i == 0 && j == m - 1 || i == n - 1 && j == m - 1) {
printf("NO\n");
goto label;
}
} else if (arr[i][j] == 4) {
if (i == 0 || j == 0 || i == n - 1 || j == m - 1) {
printf("NO\n");
goto label;
}
}
}
}
printf("YES\n");
for (i = 0; i < n; i++) {
for (j = 0; j < m; j++) {
if (i == 0 && j == 0 || i == n - 1 && j == 0 || i == 0 && j == m - 1 ||
i == n - 1 && j == m - 1) {
printf("2 ");
if (j == m - 1) printf("\n");
} else if (i == 0 || j == 0 || i == n - 1 || j == m - 1) {
printf("3 ");
if (j == m - 1) printf("\n");
} else {
printf("4 ");
if (j == m - 1) printf("\n");
}
}
}
}
return 0;
}
| 8 | CPP |
def calc(s,x,y):
ps=s[x:y:1]
ss=s[0:x:1]
# print(x,ps,ss)
# t=ss
if((y-x)%2!=0):
ss=ss[::-1]
sf=ps+ss
#print(x,ps,t,ss,sf)
return(sf)
for _ in range(int(input())):
n=int(input())
s=str(input())
s1=s
k=1
for i in range(1,n+1):
ts=calc(s,i,n)
#print(ts)
if(ts<s1):
s1=ts
k=i+1
print(s1)
print(k) | 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int x, y, x1, y1;
cin >> x >> y >> x1 >> y1;
if (x - x1 != 0 && y - y1 != 0) {
if (abs(x - x1) == abs(y - y1)) {
cout << x1 << " " << y << " " << x << " " << y1 << endl;
} else {
cout << -1 << endl;
}
} else if (x - x1 == 0 && y - y1 != 0) {
cout << x1 + abs(y - y1) << " " << y1 << " " << x1 + abs(y - y1) << " " << y
<< endl;
} else if (y - y1 == 0 && x - x1 != 0) {
cout << x1 << " " << y1 + abs(x - x1) << " " << x << " " << y1 + abs(x - x1)
<< endl;
}
}
| 7 | CPP |
#include <bits/stdc++.h>
char s[1111111];
int f[1111111];
int c[1111111];
int d[1111111];
int main() {
int i, j, n, m, l;
scanf("%d%d%s", &n, &m, s);
if (m == 0) {
j = 1;
for (i = 0; i < n; i++) j = 26LL * j % 1000000007;
printf("%d", j);
return 0;
}
f[0] = -1;
for (i = 1; s[i]; i++) {
for (j = f[i - 1];; j = f[j]) {
if (s[j + 1] == s[i]) break;
if (j == -1) break;
}
if (s[j + 1] == s[i])
f[i] = j + 1;
else
f[i] = -1;
}
l = i;
for (j = f[l - 1]; j >= 0; j = f[j]) c[l - j - 1] = 1;
scanf("%d", &i);
d[i - 1] = l;
while (--m) {
scanf("%d", &j);
if (j - i < l && !c[j - i]) {
puts("0");
return 0;
}
d[j - 1] = l;
i = j;
}
j = 1;
for (i = 0; i < n; i++) {
if (i) d[i] = std::max(d[i - 1] - 1, d[i]);
if (d[i] == 0) j = 26LL * j % 1000000007;
}
printf("%d", j);
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long a, b, T, q, w, e, d[100001], v[100001], t[100001], B = 140;
int main() {
scanf("%lld%lld", &a, &b);
for (int i = 1; i <= a; i++) scanf("%lld", &d[i]), v[d[i]] = i, t[i] = i;
for (int i = 1; i <= a; i++)
for (int j = 1; j <= B; j++) t[i] = d[t[i]];
for (int ii = 1; ii <= b; ii++) {
scanf("%lld%lld%lld", &q, &w, &e);
if (q == 1) {
swap(d[w], d[e]);
swap(v[d[w]], v[d[e]]);
long long tt = e, yy = e;
for (int i = 1; i <= B; i++) yy = d[yy];
for (int i = 1; i <= B + 1; i++) t[tt] = yy, tt = v[tt], yy = v[yy];
tt = w, yy = w;
for (int i = 1; i <= B; i++) yy = d[yy];
for (int i = 1; i <= B + 1; i++) t[tt] = yy, tt = v[tt], yy = v[yy];
} else {
long long ff = w;
for (int i = 1; i <= e / B; i++) ff = t[ff];
e %= B;
for (int i = 1; i <= e; i++) ff = d[ff];
printf("%lld\n", ff);
}
}
return 0;
}
| 14 | CPP |
#include <bits/stdc++.h>
using namespace std;
int a[5050], f[5050] = {0}, c[5050] = {0};
int main() {
int i, j, m, n, k, t;
scanf("%d", &n);
a[0] = 0;
for (i = 1; i <= n; i++) scanf("%d", &a[i]);
for (i = 1; i <= n; i++) {
memset(c, 0, sizeof(c));
int ma = a[i];
for (j = i; j <= n; j++) {
c[a[j]]++;
if (c[a[j]] > c[ma] || (c[a[j]] == c[ma] && ma > a[j])) ma = a[j];
f[ma]++;
}
}
for (i = 1; i <= n; i++) printf("%d ", f[i]);
return 0;
}
| 9 | CPP |
#include <cstdio>
#include <algorithm>
#define N 100010
#define inf 2000000000
#define ll long long
#define mem(x, a) memset(x, a, sizeof x)
#define fo(x, a, b) for (int x = (a); x <= (b); x++)
#define fd(x, a, b) for (int x = (a); x >= (b); x--)
#define go(x) for (int p = tail[x], v; p; p = e[p].fr)
using namespace std;
struct node{int v, fr, flow, c;}e[N << 3];
const int zf[4][2] = {{1, 1}, {1, -1}, {-1, 1}, {-1, -1}};
int n, S, T, cp[4], tail[N << 2], cnt = 1, f[N << 4], tot_node;
bool tag[N << 2], vis[N << 2];
ll dis[N << 2], ans = 0;
inline int read() {
int x = 0, f = 0; char c = getchar();
while (c < '0' || c > '9') f = (c == '-') ? 1 : f, c = getchar();
while (c >= '0' && c <= '9') x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
return f ? -x : x;
}
inline void add(int u, int v, int flow, int c) {
// printf("%d %d %d\n", u, v, c);
e[++cnt] = (node){v, tail[u], flow, c}, tail[u] = cnt;
e[++cnt] = (node){u, tail[v], 0, -c}, tail[v] = cnt;
}
bool spfa() {
fo(i, 1, tot_node) dis[i] = -inf;
int l = 0, r = 1; f[1] = S;
dis[S] = 0, tag[S] = 1;
while (l++ < r) {
int x = f[l];
go(x) {
if (! e[p].flow) continue;
if (dis[x] + e[p].c > dis[v = e[p].v]) {
dis[v] = dis[x] + e[p].c;
if (! tag[v]) f[++r] = v, tag[v] = 1;
}
}
tag[x] = 0;
}
return dis[T] > 0;
}
int dfs(int x, int hav) {
if (x == T) return hav;
int gone = 0, can = 0; vis[x] = 1;
go(x) {
v = e[p].v;
if (dis[x] + e[p].c != dis[v] || ! e[p].flow || vis[v]) continue;
can = dfs(v, min(e[p].flow, hav - gone));
if (! can) {dis[v] = -inf; continue;}
gone += can, e[p].flow -= can, e[p ^ 1].flow += can;
if (gone == hav) {vis[x] = 0; return gone;}
}
vis[x] = 0; return gone;
}
int main()
{
n = read();
fo(i, 0, 3) cp[i] = (n << 1) + i + 1;
S = (n << 1) + 5, tot_node = T = (n << 1) + 6;
fo(i, 1, n) {
int x = read(), y = read(), c = read(); add(S, i, c, 0);
fo(j, 0, 3) add(i, cp[j], c, zf[j][0] * x + zf[j][1] * y);
}
fo(i, n + 1, (n << 1)) {
int x = read(), y = read(), c = read(); add(i, T, c, 0);
fo(j, 0, 3) add(cp[j], i, c, -zf[j][0] * x + -zf[j][1] * y);
}
while (spfa()) {
ll flow = dfs(S, inf);
ans += flow * dis[T];
}
printf("%lld\n", ans);
return 0;
} | 0 | CPP |
# interesting_subarray.py
for _ in range(int(input())):
n = int(input())
a = list(map(int,input().split()))
ok = False
for i in range(1,n):
# print(a[i],a[i-1])
if abs(a[i]-a[i-1])>1:
ok = True
print('YES')
print(i,i+1)
break
if not ok:
print('NO')
# i = 2
# j = 0
# k = 0
# while i<=n:
# k = 0
# while k<=n-i:
# j = k
# max_ = -10e7
# min_ = 10e7
# # print(k,j,j+i)
# while j<k+i:
# # print(a[j])
# if a[j]>max_:
# max_ = a[j]
# if a[j]<min_:
# min_ = a[j]
# j+=1
# # print(max_,min_)
# if max_-min_>=i:
# ok = True
# # print(max_-min_,i)
# break
# k+=1
# if ok:
# break
# i+=1 | 8 | PYTHON3 |
n = int(input())
s = input()
q = int(input())
d = dict()
for j in range(len(s)):
try:
d[s[j]].append(j)
except KeyError:
d[s[j]] = [j]
for i in range(q):
request = input()
counter = 0
ind = dict()
for r in request:
try:
ind[r] += 1
except KeyError:
ind[r] = 0
counter = max(counter, d[r][ind[r]])
print(counter + 1)
| 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
long long INF = (1LL << 62);
const int inf = (1LL << 30);
const int maxn = (int)1e9 + 5;
const int MOD = 1000000007;
vector<string> V;
bool isOn(int mask, int b) { return (mask & (1 << b)) != 0; }
bool func(set<char> const &clues) {
int sz = V.size();
int f = 1;
for (int i = 0; i < sz; ++i)
for (int j = i + 1; j < sz; ++j) {
if (V[i] != V[j]) {
if (V[i][0] == V[j][0] && (clues.count(V[i][1]) == 0) &&
(clues.count(V[j][1]) == 0))
f = 0;
else if (V[i][1] == V[j][1] && (clues.count(V[i][0]) == 0) &&
(clues.count(V[j][0]) == 0))
f = 0;
else {
if ((clues.count(V[i][1]) == 0) && (clues.count(V[j][1]) == 0) &&
(clues.count(V[i][0]) == 0) && (clues.count(V[j][0]) == 0))
f = 0;
}
}
}
return f;
}
int main() {
int n;
cin >> n;
for (int i = 0; i < n; ++i) {
string S;
cin >> S;
V.push_back(S);
}
int mi = inf;
for (int maskl = 0; maskl < (1 << 5); ++maskl) {
for (int maskn = 0; maskn < (1 << 5); ++maskn) {
set<char> clues;
if (isOn(maskl, 0)) clues.insert('R');
if (isOn(maskl, 1)) clues.insert('G');
if (isOn(maskl, 2)) clues.insert('B');
if (isOn(maskl, 3)) clues.insert('Y');
if (isOn(maskl, 4)) clues.insert('W');
if (isOn(maskn, 0)) clues.insert('1');
if (isOn(maskn, 1)) clues.insert('2');
if (isOn(maskn, 2)) clues.insert('3');
if (isOn(maskn, 3)) clues.insert('4');
if (isOn(maskn, 4)) clues.insert('5');
if (func(clues))
mi = min(mi, __builtin_popcount(maskl) + __builtin_popcount(maskn));
}
}
cout << mi << endl;
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 500050;
inline int gi() {
register char ch = getchar();
register int x = 0, q = 0;
while (ch < '0' || ch > '9') ch == '-' ? q = 1 : 0, ch = getchar();
while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
return q ? (-x) : x;
}
int f[N], a[N], b[N], n, num;
inline void ins(int x, int s) {
while (x <= n) f[x] += s, x += x & (-x);
return;
}
inline int query(int x) {
int s = 0;
while (x) s += f[x], x -= x & (-x);
return s;
}
int main() {
n = gi();
for (int i = 1; i <= n; ++i) a[i] = gi();
printf("1");
for (int i = 1; i <= n; ++i) ins(n - i + 1, 1);
for (int i = 1; i <= n; ++i) {
ins(n - a[i] + 1, -1);
b[a[i]] = 1;
if (query(n - a[i] + 1) > 0)
++num;
else {
for (int j = a[i] - 1; j; --j)
if (b[j] && query(n - j + 1) == 0)
--num;
else
break;
}
printf(" %d", num + 1);
}
return 0;
}
| 10 | CPP |
t = int(input())
for i in range(t):
word = input()
wlen = len(word)
if wlen > 10:
print(word[0] + str(wlen-2) + word[-1])
else:
print(word) | 7 | PYTHON3 |
t = int(input())
for i in range(t):
x =input()
s = len(x)
count = int(((int(x[0])-1)*10) + (s*(s+1))/2)
print(count) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 2222 * 40 + 5;
const int INF = 1e9 + 7;
int a[1555];
long long fact[N], inv[N];
long long pw(long long x, long long exp1) {
if (exp1 == 0) return 1;
long long y = pw(x, exp1 / 2);
y = (y * y) % 1000000007;
if (exp1 & 1) y = (y * x) % 1000000007;
return y;
}
void pre() {
fact[0] = 1;
inv[0] = 1;
for (int i = (1); i < (N); i++) fact[i] = (fact[i - 1] * i) % 1000000007;
for (int i = (1); i < (N); i++) inv[i] = pw(fact[i], 1000000007 - 2);
return;
}
long long ncr(int n, int r) {
if (n < r) return 0;
if (n == r) return 1;
long long tmp = fact[n];
tmp = (tmp * inv[r]) % 1000000007;
tmp = (tmp * inv[n - r]) % 1000000007;
return tmp;
}
long long begger(int n, int r) {
long long res = ncr(n + r - 1, r - 1);
return res;
}
int p[333333];
vector<int> prime;
void sieve() {
for (int i = 2; i < 333333; i++) {
if (p[i]) continue;
prime.push_back(i);
for (int j = 2 * i; j < 333333; j += i) {
p[j] = 1;
}
}
return;
}
map<int, int> cntp;
int main() {
pre();
int n;
scanf("%d", &n);
for (int i = (0); i < (n); i++) {
scanf("%d", &a[i]);
}
sieve();
for (int i = (0); i < (n); i++) {
long long x = a[i];
for (int j = (0); j < (prime.size()); j++) {
long long y = prime[j];
if (y * y > x) break;
int cnt = 0;
while (x % y == 0) {
x /= y;
cnt++;
}
if (cnt > 0) cntp[y] += cnt;
}
if (x > 1) cntp[x]++;
}
long long ans = 1;
for (map<int, int>::iterator it = cntp.begin(); it != cntp.end(); it++) {
ans = (ans * begger(it->second, n)) % 1000000007;
}
cout << ans;
return 0;
}
| 9 | CPP |
def pairss(n):
res = [];i = 1
while i < n:
for k in range(0,n,i*2):
for j in range(i):res.append((j+k,j+i+k))
i *= 2
return res
n = int(input());z = 1
while z * 2 < n:z *= 2
q = pairss(z);res = []
for a, b in q:res.append((a+1, b+1))
for a, b in q:res.append((n-a, n-b))
print(len(res))
for a, b in res:print(a,b) | 12 | PYTHON3 |
from sys import stdin, stdout
import sys
INF=1e11
import bisect
def get_int(): return int(stdin.readline().strip())
def get_ints(): return map(int,stdin.readline().strip().split())
def get_array(): return list(map(int,stdin.readline().strip().split()))
def get_string(): return stdin.readline().strip()
def op(c): return stdout.write(c)
from collections import defaultdict
import math
def lcm(a,b):
return (a*b)/gcd(a,b)
def gcd(x,y):
while y:
x,y=y,x%y
return x
for _ in range(int(stdin.readline())):
n=get_int()
v=set()
for i in range(1,int(math.sqrt(n))+1):
if n%i==0:
v.add(i)
v.add(n//i)
a,b=1,n
mx=INF
v=list(v)
v.sort()
for i in v:
if i>=n:
break
lc=lcm(i,n-i)
if lc<mx:
mx=lc
a,b=i,n-i
print(a,b) | 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i, a, b, x;
cin >> n;
for (i = 0; i < n; i++) {
cin >> x;
if (x == 1) a = i;
if (x == n) b = i;
}
cout << max(max(a, n - a - 1), max(b, n - b - 1)) << endl;
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
int N, M, fa[200000];
char s[200000], input[200000];
std::vector<int> E[200000];
int left[200000], right[200000];
int q[200001];
std::vector<int>::iterator ue[200001];
std::vector<std::pair<int, int> > VA[200002], VD[200002];
inline int g1(int x) {
if (x == -1) return -1;
if (s[x] == 'U')
return x >= M ? x - M : -1;
else if (s[x] == 'D')
return x < (N - 1) * M ? x + M : -1;
else if (s[x] == 'L')
return x % M ? x - 1 : -1;
else
return (x + 1) % M ? x + 1 : -1;
}
inline int g2(int x) {
if (x == -1) return -1;
if (s[x] == 'D')
return x >= M ? x - M : -1;
else if (s[x] == 'U')
return x < (N - 1) * M ? x + M : -1;
else if (s[x] == 'R')
return x % M ? x - 1 : -1;
else
return (x + 1) % M ? x + 1 : -1;
}
void pair(int u, int v) {
if (left[u] > left[v]) std::swap(u, v);
VA[left[u]].push_back({left[v], right[v]});
VD[right[u] + 1].push_back({left[v], right[v]});
}
struct node {
int min, num, tag;
} T[524288];
long long O;
void build(int p, int l, int r) {
T[p].num = r - l + 1;
if (l < r) {
int m = l + r >> 1;
build(p << 1, l, m);
build(p << 1 | 1, m + 1, r);
}
}
void P(int p, int l, int r, int L, int R, int w) {
if (L <= l && r <= R) {
T[p].min += w;
T[p].tag += w;
return;
}
int m = l + r >> 1;
if (T[p].tag) {
T[p << 1].min += T[p].tag;
T[p << 1].tag += T[p].tag;
T[p << 1 | 1].min += T[p].tag;
T[p << 1 | 1].tag += T[p].tag;
T[p].tag = 0;
}
if (L <= m) P(p << 1, l, m, L, R, w);
if (R > m) P(p << 1 | 1, m + 1, r, L, R, w);
T[p].min = std::min(T[p << 1].min, T[p << 1 | 1].min);
T[p].num = (T[p].min == T[p << 1].min ? T[p << 1].num : 0) +
(T[p].min == T[p << 1 | 1].min ? T[p << 1 | 1].num : 0);
}
int main() {
scanf("%d%d", &N, &M);
for (int i = 0; i < N; i++) {
scanf("%s", input);
std::copy(input, input + M, s + i * M);
}
for (int i = 0; i < N * M; i++) {
fa[i] = g2(g1(i));
if (fa[i] != -1) E[fa[i]].push_back(i);
}
int D = 0, TIME = 0;
for (int i = 0; i < N * M; i++)
if (fa[i] == -1) {
left[i] = ++TIME;
q[++D] = i;
ue[D] = E[i].begin();
while (D) {
if (ue[D] == E[q[D]].end())
right[q[D--]] = TIME;
else {
int To = *ue[D]++;
left[To] = ++TIME;
q[++D] = To;
ue[D] = E[To].begin();
}
}
}
for (int i = 0; i < N * M; i++)
if (s[i] == 'U')
pair(i, i + M);
else if (s[i] == 'L')
pair(i, i + 1);
build(1, 1, N * M);
for (int i = 1; i <= N * M; i++) {
for (auto j : VA[i]) P(1, 1, N * M, j.first, j.second, 1);
for (auto j : VD[i]) P(1, 1, N * M, j.first, j.second, -1);
O += N * M - (T[1].min ? 0 : T[1].num);
}
printf("%lld\n", O);
return 0;
}
| 13 | CPP |
#include <bits/stdc++.h>
using namespace std;
char s[105];
int n, t0[200005], t1[200005], res[205][105];
inline int gcd(int a, int b) {
for (; b; b ^= a ^= b ^= a %= b)
;
return a;
}
int main() {
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
int a, b, c;
scanf("%s", s);
sscanf(s, "(%d+%d)/%d\n", &a, &b, &c);
a += b;
if (a) {
int g = gcd(a, c);
++res[t0[i] = a / g][t1[i] = c / g];
} else
++res[t0[i] = 0][t1[i] = 0];
}
for (int i = 0; i < n; ++i) printf("%d ", res[t0[i]][t1[i]]);
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long i, s, r, t, a[1000000], na, nb, m, k, c, e, b[1000000];
int main() {
cin >> na >> nb;
cin >> k >> m;
for (i = 0; i < na; i++) cin >> a[i];
for (i = 0; i < nb; i++) cin >> b[i];
sort(a, a + na);
sort(b, b + nb);
if (a[k - 1] < b[nb - m])
cout << "YES";
else
cout << "NO";
}
| 7 | CPP |
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
b.sort(reverse=True)
print(['YES', 'NO'][int(sum(a) > b[0] + b[1])])
| 7 | PYTHON3 |
HQ=['H','Q','9']
s=input()
x=0
y=0
for i in s:
if i in HQ:
y=y+1
else:
x=x+1
if(x==len(s)):
print('NO')
if(y >= 1):
print('YES') | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
int t[MAXN];
int main() {
int n, a, b, c, d, e, f;
scanf("%d%d%d%d", &a, &b, &c, &n);
for (d = 0; d < n; d++) scanf("%d", &t[d]);
sort(t, t + n);
e = 0;
for (d = 0; d < n && t[d] <= b; d++)
;
for (; d < n && t[d] < c; d++) e++;
printf("%d", e);
return 0;
}
| 7 | CPP |
tests = int(input())
for t in range(tests):
n, k = list(map(int, input().split()))
if k<=n:
if (n-k)%2 == 0:
print(0)
else:
print(1)
else:
print(k-n) | 7 | PYTHON3 |
for _ in range(int(input())):
n,m=map(int,input().split())
if (n*m)<=(n+m):
print("YES")
else:
print("NO") | 7 | PYTHON3 |
#include <iostream>
using namespace std;
int n, a[10];
bool dfs(int b, int c, int cnt) {
bool ans = false;
if (cnt == 10) {
return true;
}
if (b < a[cnt]) {
ans = dfs(a[cnt], c, cnt + 1);
}
if (c < a[cnt]) {
ans = dfs(b, a[cnt], cnt + 1);
}
return ans;
}
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
for (int j = 0; j < 10; j++) cin >> a[j];
if (dfs(0, 0, 0)) cout << "YES" << endl;
else cout << "NO" << endl;
}
} | 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1001;
int arr[maxn];
int n;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
for (int i = 0; i < n - 1; i++) {
int u, v;
cin >> u >> v;
arr[u]++;
arr[v]++;
}
int ans = 0;
for (int i = 1; i <= n; i++) {
if (arr[i] == 1) ans++;
}
cout << ans << '\n';
return 0;
}
| 8 | CPP |
#include <cstdio>
#include <algorithm>
using namespace std;
int main()
{
int z;
while (scanf("%d", &z), z) {
int m = -1;
for (int x = 1; x < z; ++x) {
int lo = 1, hi = z;
while (lo < hi) {
int y = (lo + hi + 1) / 2;
if (x*x*x + y*y*y <= z*z*z)
lo = y;
else
hi = y-1;
}
m = max(m, x*x*x + lo*lo*lo);
}
printf("%d\n", z*z*z - m);
}
} | 0 | CPP |
from math import *
from copy import *
from string import * # alpha = ascii_lowercase
from random import *
from sys import stdin
from sys import maxsize
from operator import * # d = sorted(d.items(), key=itemgetter(1))
from itertools import *
from collections import Counter # d = dict(Counter(l))
import math
def bin1(l,r,k,t,b,val,ans):
if(l>r):
return ans
else:
mid=(l+r)//2
v=k**mid
if(v==val):
return v
elif(v>val):
ans=mid
return bin1(mid+1,r,k,t,b,val,ans)
else:
return bin1(l,mid-1,k,t,b,val,ans)
def bin2(l,r,k,t,b,val,ans):
if(l>r):
return ans
else:
mid=(l+r)//2
v=t*(k**mid)+b*(mid)
if(v==val):
return v
elif(v>val):
ans=mid
return bin2(l,mid-1,k,t,b,val,ans)
else:
return bin2(mid+1,r,k,t,b,val,ans)
def SieveOfEratosthenes(n):
# Create a boolean array "prime[0..n]" and initialize
# all entries it as true. A value in prime[i] will
# finally be false if i is Not a prime, else true.
prime = [True for i in range(n+1)]
p = 2
while (p * p <= n):
# If prime[p] is not changed, then it is a prime
if (prime[p] == True):
# Update all multiples of p
for i in range(p * p, n+1, p):
prime[i] = False
p += 1
l=[]
for i in range(2,n+1):
if(prime[i]):
l.append(i)
return l
def bin(l,r,ll,val):
if(l>r):
return -1
else:
mid=(l+r)//2
if(val>=ll[mid][0] and val<=ll[mid][1]):
return mid
elif(val<ll[mid][0]):
return bin(l,mid-1,ll,val)
else:
return bin(mid+1,r,ll,val)
def deci(n):
s=""
while(n!=0):
if(n%2==0):
n=n//2
s="0"+s
else:
n=n//2
s="1"+s
return s
def diff(s1,s2):
if(len(s1)<len(s2)):
v=len(s1)
while(v!=len(s2)):
s1="0"+s1
v=v+1
else:
v=len(s2)
while(v!=len(s1)):
s2="0"+s2
v=v+1
c=0
for i in range(len(s1)):
if(s1[i:i+1]!=s2[i:i+1]):
c=c+1
return c
from sys import stdin, stdout
def fac(a,b):
v=a
while(a!=b):
v*=a-1
a=a-1
return v
def bino(l,r,n):
if(l>r):
return -1
else:
mid=(l+r)//2
val1=math.log((n/mid)+1,2)
val2=int(val1)
if(val1==val2):
return val1
elif(val1<1.0):
return bino(l,mid-1,n)
else:
return bino(mid+1,r,n)
def binary(l,r,ll,val,ans):
if(l>r):
return ans
else:
mid=(l+r)//2
if(ll[mid]<=val):
ans=mid
return binary(mid+1,r,ll,val,ans)
else:
return binary(l,mid-1,ll,val,ans)
if __name__ == '__main__':
n=int(stdin.readline())
l=list(map(int,stdin.readline().split(" ")))
l.sort()
print(*l) | 7 | PYTHON3 |
for _ in range(int(input())):
a,b=map(int,input().split())
if a-b>1:
print("Yes")
else:print("No")
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
bool first = true;
string res = "{";
for (const auto& x : v) {
if (!first) {
res += ", ";
}
first = false;
res += to_string(x);
}
res += "}";
return res;
}
void debug_out() { cerr << '\n'; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
cerr << " " << to_string(H);
debug_out(T...);
}
bool expo(long long a, long long b, long long c) {
double d = 1.0l;
long long e = 1;
for (int i = 0; i < b; i++) {
d *= a;
if (d > c + 100) return false;
e *= a;
if (e > c) return false;
}
return true;
}
long long root(long long n, long long p, long long r) {
long long l = 0;
r++;
while (r - l > 1) {
long long mid = (l + r) / 2;
if (expo(mid, p, n))
l = mid;
else
r = mid;
}
return l;
}
void solve() {
long long n;
cin >> n;
vector<long long> v(60);
for (int i = 2; i < 60; i++) {
v[i] = root(n, i, i == 2 ? n : v[i - 1] + 1) - 1;
}
long long ans = n;
for (int i = 59; i >= 2; i--) {
for (int j = i * 2; j < 60; j += i) v[i] -= v[j];
ans -= v[i];
}
cout << ans - 1 << '\n';
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}
| 12 | CPP |
def inv(a):
return str(9 - int(a))
def alter(x, i):
return x[:i] + inv(x[i]) + x[i + 1 :]
x = input()
if x[0] != '9' and x[0] > inv(x[0]): x = alter(x, 0)
for i in range(1, len(x)):
if x[i] > inv(x[i]):
x = alter(x, i)
print (x) | 7 | PYTHON3 |
t=int(input())
for i in range(t):
a,b,c=map(int,input().split())
d,e,f=map(int,input().split())
print(min(c,e)*2-max(0,min(f-a-(c-min(c,e)),b))*2) | 8 | PYTHON3 |
import math
t=int(input())
for _ in range(t):
a,b,c,d=map(int,input().split())
if b>=a:
print(b)
else:
x=a-b
if c<=d:
print(-1)
else:
y=math.ceil((a-b)/(c-d))
print(b+y*c) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
while (cin >> n) {
deque<int> v(n);
for (int i = 0; i < n; i++) v[i] = i + 1;
long long int answer = 0;
for (int i = 0; i < n - 1; i++) {
answer += (v.front() + v.back()) % (n + 1);
if (i % 2)
v.pop_back();
else
v.pop_front();
}
cout << answer << endl;
}
}
| 9 | CPP |
#include <bits/stdc++.h>
void ps() { system("pause"); }
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m, d, t, playerPos = 0;
vector<pair<int, int>> wood;
vector<int> index;
cin >> n >> m >> d;
for (int i = 0; i < n; i++) index.push_back(0);
for (int i = 0; i < m; i++) {
cin >> t;
wood.push_back(make_pair(0, t));
}
int c = 0;
for (int i = m - 1; i >= 0; i--) {
c += wood[i].second;
wood[i].first = n + 1 - c;
}
for (int i = 0; i < m; i++) {
while (1) {
if (playerPos + d >= wood[i].first) {
playerPos = wood[i].first + wood[i].second - 1;
break;
} else
wood[i].first--;
}
}
for (int i = 0; i < m; i++)
for (int j = 0; j < wood[i].second; j++)
index[wood[i].first + j - 1] = i + 1;
if (playerPos + d >= n + 1) {
cout << "YES\n";
for (int i = 0; i < n; i++) cout << index[i] << " ";
} else
cout << "NO";
return 0;
}
| 9 | CPP |
n = int(input())
o = 0
for i in range(n):
k = 0
for l in input().split():
k = k + int(l)
if k>=2: o=o+1
print(o) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
long long cnts[26], cntt[26];
signed main() {
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(false);
long long q;
cin >> q;
while (q--) {
for (long long i = 0; i < 26; i++) cnts[i] = cntt[i] = 0;
long long n;
cin >> n;
string s, t;
cin >> s >> t;
for (long long i = 0; i < n; i++) cnts[s[i] - 'a']++, cntt[t[i] - 'a']++;
bool ok = 1;
for (long long i = 0; i < 26; i++) {
if (cnts[i] != cntt[i]) ok = 0;
}
if (!ok)
cout << "-1\n";
else {
long long ans = -1;
for (long long l = 0; l < n; l++) {
for (long long i = 0; i < l + 1; i++) {
vector<long long> rem(26, 0), req(26, 0);
long long j = n - 1 + i - l;
assert(i + (n - 1 - j) == l);
long long pts = 0, ptt = i;
while (ptt <= j and pts < n) {
if (s[pts] == t[ptt]) {
pts++;
ptt++;
} else {
rem[s[pts] - 'a']++;
pts++;
}
}
while (pts < n) rem[s[pts++] - 'a']++;
for (long long k = 0; k < i; k++) req[t[k] - 'a']++;
for (long long k = j + 1; k < n; k++) req[t[k] - 'a']++;
bool ok = 1;
for (long long k = 0; k < 26; k++)
if (rem[k] != req[k]) {
ok = 0;
break;
}
if (ok) {
ans = l;
break;
}
}
if (ans != -1) break;
}
cout << ans << '\n';
}
}
}
| 11 | CPP |
#include <iostream>
#include <algorithm>
using namespace std;
int n, a[1009];
int main() {
while (cin >> n, n) {
for (int i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
int ret = 1999999999;
for (int i = 1; i < n; i++) ret = min(ret, a[i] - a[i - 1]);
cout << ret << endl;
}
return 0;
} | 0 | CPP |
n=int(input())
a=list(map(int,input().strip().split(' ')))
s=sum(a[:])
m=max(a)
print(m*n-s) | 7 | PYTHON3 |
import sys
from fractions import gcd
f = sys.stdin
# f = open("input.txt", "r")
x, y, a, b = map(int, f.readline().strip().split())
def lcm(x, y):
return x * y // gcd(x, y)
l = lcm(x, y)
print(b//l - (a-1)//l) | 7 | PYTHON3 |
s = input()
n = len(s)
cu = sum(1 for x in s if x.isupper())
print(s.lower()) if (2 * cu <= n) else print(s.upper()) | 7 | PYTHON3 |
'''
n = int(input())
list = []
for i in range(n):
leaf = input()
if leaf in list:
continue
else:
list.append(leaf)
print(list)
'''
n = int(input())
cont = set()
for i in range(n):
cont.add(input())
print(len(cont))
| 7 | PYTHON3 |
#include<bits/stdc++.h>
using namespace std;
int main(){
int a,b,c,d,e,f,g,h,i;
cin>>a>>b>>e;
c=e*3-a-b;
g=e*3-e-c;
d=e*3-a-g;
f=e*3-d-e;
h=e*3-b-e;
i=e*3-g-h;
cout<<a<<" "<<b<<" "<<c<<endl;
cout<<d<<" "<<e<<" "<<f<<endl;
cout<<g<<" "<<h<<" "<<i;
return 0;
} | 0 | CPP |
def main():
number, of, quantifier = input().split()
number = int(number)
months = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
weeks = {
'mon': 1,
'tue': 2,
'wed': 3,
'thu': 4,
'fri': 5,
'sat': 6,
'sun': 7
}
if quantifier == 'month':
total = sum(1 for month in months if number <= month)
elif quantifier == 'week':
total = 53 if number == weeks['fri'] or number == weeks['sat'] else 52
print(total)
if __name__ == '__main__':
main()
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int n, m, a[1000010], mid;
long long ans;
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
mid = (1 + n) >> 1;
for (int i = 1; i <= mid; i += m) ans += a[mid] - a[i];
for (int i = n; i >= mid; i -= m) ans += a[i] - a[mid];
printf("%I64d\n", ans << 1);
}
| 11 | CPP |
x=list(map(int,input().split()))
s=0
while(x[0]<=x[1]):
x[0]=3*x[0]
x[1]=2*x[1]
s=s+1
print(s)
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using std::cin;
using std::cout;
const int maxn = 10100;
int n, ans;
int sum = 0;
struct edge {
int u, v, w;
} a[maxn];
int fa[maxn], size[maxn], can[maxn];
inline int find(int x) { return fa[x] == x ? fa[x] : fa[x] = find(fa[x]); }
inline int cmp0(const edge& x, const edge& y) { return x.w < y.w; }
inline int check(int x) { return size[find(x)] > sum - can[find(x)]; }
int main() {
std::ios::sync_with_stdio(false), cin.tie(0);
cin >> n;
for (int i = 1; i < n; ++i) {
cin >> a[i].u >> a[i].v >> a[i].w;
}
for (int i = 1; i <= n; ++i) {
cin >> can[i];
sum += can[i];
fa[i] = i;
size[i] = 1;
}
std::sort(a + 1, a + n, cmp0);
for (int i = 1; i <= n; ++i) {
ans += check(i);
}
for (int i = 1; i < n; ++i) {
int x = find(a[i].u), y = find(a[i].v);
ans -= check(x) + check(y);
fa[x] = y;
size[y] += size[x];
can[y] += can[x];
ans += check(x);
if (ans) {
cout << a[i].w << '\n';
return 0;
}
}
cout << a[n - 1].w << '\n';
}
| 11 | CPP |
print("Yes" if("7"in input())else"No") | 0 | PYTHON3 |
######################################################
# ps template
def mi(): return map(int, input().split())
def ii(): return int(input())
def li(): return list(map(int, input().split()))
def si(): return input().split()
#######################################################
t = ii()
for _ in range(t):
n = ii()
print(n//2+1)
| 7 | PYTHON3 |
s = input()
res = -float('inf')
mul = 1
for i in range(len(s)):
if s[i] == '0':
break
part = 9 ** (len(s) - i - 1)
res = max(res, (int(s[i]) - 1) * mul * (part if part > 0 else 1))
mul *= int(s[i])
kek = 1
for x in s:
kek *= int(x)
print(max([res, kek, 9 ** (len(s) - 1)]))
| 8 | PYTHON3 |
x, y = map(int, input().split())
u, v = abs(x), abs(y)
a = max(u, v)
s = 4 * (a - 1)
if u >= v and x > 0 and y > 1 - a: s += 1
elif v >= u and y > 0: s += 2
elif u >= v and x < 0: s += 3
elif v >= u and y < 0: s += 4
print(s if a > 0 else 0) | 7 | PYTHON3 |
n = int(input())
p = [int(input()) for i in range(n-1)]
ver = [i for i in range(1, n+1) if i in p]
lis = [j for i, j in enumerate(p, start=2) if i not in ver]
b = []
for i in ver:
if i in lis:
b.append(lis.count(i))
else:
b.append(0)
b = min(b)
print("Yes" if b >= 3 else "No") | 8 | PYTHON3 |
n = int(input())
if (n - 2) % 3 == 0:
print(n - 3, 2, 1)
else:
print(n - 2, 1, 1)
| 7 | PYTHON3 |
def main():
t, k = map(int, input().split())
max_n = 100003
mod = 1000000007
d = [1] * max_n
for i in range(k, max_n):
d[i] = (d[i - 1] + d[i - k]) % mod
for i in range(1, max_n):
d[i] = (d[i] + d[i - 1]) % mod
for i in range(t):
a, b = map(int, input().split())
print((d[b] - d[a - 1]) % mod)
if __name__ == '__main__':
main()
| 10 | PYTHON3 |