solution
stringlengths 10
983k
| difficulty
int64 0
25
| language
stringclasses 2
values |
---|---|---|
#include <bits/stdc++.h>
using namespace std;
int a[100005];
int main() {
int n;
int k = 0, m = 0;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
m = a[0];
for (int i = 0; i < n; i++) {
if (a[i] >= a[i + 1]) {
k += a[i] - a[i + 1];
}
while (a[i] < a[i + 1]) {
if (a[i] < a[i + 1] && k < a[i + 1] - a[i]) {
m++;
a[i]++;
}
if (a[i] < a[i + 1] && k >= (a[i + 1] - a[i])) {
k -= a[i + 1] - a[i];
a[i] = a[i + 1];
}
}
}
cout << m;
}
| 8 | CPP |
n, m = map(int,input().split())
lst = [-1 for i in range(n + 1)]
lst[0] = 0
def find(x):
if(lst[x] < 0):
return(x)
else:
return(find(lst[x]))
def unit(x, y):
xr = find(x)
yr = find(y)
if (xr == yr):
pass
else:
if (xr > yr):
x, y = y, x
xr, yr = yr, xr
lst[xr] = lst[xr] + lst[yr]
lst[yr] = xr
for i in range(m):
a, b = map(int,input().split())
unit(a, b)
print(-(min(lst)))
| 0 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 10005;
struct edge {
int y, c, w, next;
} a[N << 1];
int len, last[N];
void ins(int x, int y, int c, int w) {
a[++len] = (edge){y, c, w, last[x]};
last[x] = len;
a[++len] = (edge){x, 0, -w, last[y]};
last[y] = len;
}
int q[N << 2], d[N], f[N], S, T, prv[N], ans, sta[N], top;
bool v[N];
bool spfa() {
memset(d, 0xcf, sizeof d);
memset(f, 0, sizeof f);
d[S] = 0;
f[S] = 0x3f3f3f3f;
int l = 1, r = 0;
v[q[++r] = S] = 1;
for (int x = q[l]; l <= r; x = q[++l]) {
v[x] = 0;
for (int k = last[x], y; k; k = a[k].next) {
if (d[y = a[k].y] < d[x] + a[k].w && a[k].c) {
d[y] = d[x] + a[k].w;
f[y] = min(f[x], a[k].c);
if (!v[y]) v[q[++r] = y] = 1;
prv[y] = k;
}
}
}
return f[T] > 0;
}
void upd() {
ans -= f[T] * d[T];
int k = prv[T];
while (k) {
a[k].c -= f[T];
a[k ^ 1].c += f[T];
k = prv[a[k ^ 1].y];
}
}
int A[N], C[N], lst[N];
int main() {
len = 1;
memset(last, 0, sizeof last);
memset(lst, 0, sizeof lst);
int n, m;
scanf("%d%d", &n, &m);
ans = 0;
for (int i = 1; i <= n; ++i) scanf("%d", &A[i]);
for (int i = 1; i <= n; ++i) scanf("%d", &C[i]);
for (int i = 1; i <= n; ++i) ans += C[A[i]];
S = 0;
T = n + 1;
--m;
for (int i = 0; i < T; ++i) ins(i, i + 1, m, 0);
for (int i = 1; i <= n; ++i) {
if (!lst[A[i]])
lst[A[i]] = i;
else {
if (lst[A[i]] == i - 1)
ans -= C[A[i]];
else
ins(lst[A[i]] + 1, i, 1, C[A[i]]);
lst[A[i]] = i;
}
}
while (spfa()) upd();
printf("%d\n", ans);
return 0;
}
| 9 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 205;
const int M = 50005;
struct E {
int x, y;
long long g, s;
} a[M], b[M];
int f[N], w;
bool cmpg(const E &a, const E &b) { return a.g < b.g; }
bool cmps(const E &a, const E &b) { return a.s < b.s; }
int father(int p) {
if (f[p] == p) return p;
return f[p] = father(f[p]);
}
long long kruskal(int n) {
int i, v = 0, x, y;
long long res;
for (i = 1; i <= n; i++) f[i] = i;
sort(b + 1, b + w + 1, cmps);
for (i = 1; i <= w; i++) {
x = father(b[i].x);
y = father(b[i].y);
if (x == y) continue;
v++;
f[x] = y;
res = b[i].s;
b[v].x = b[i].x;
b[v].y = b[i].y;
b[v].g = b[i].g;
b[v].s = b[i].s;
}
w = v;
if (v < n - 1)
return -1;
else
return res;
}
int main() {
int n, m, i;
long long g, s, ans = -1;
scanf("%d%d", &n, &m);
scanf("%I64d%I64d", &g, &s);
for (i = 1; i <= m; i++) {
scanf("%d%d%I64d%I64d", &a[i].x, &a[i].y, &a[i].g, &a[i].s);
a[i].g *= g;
a[i].s *= s;
}
sort(a + 1, a + m + 1, cmpg);
for (i = 1; i <= m; i++) {
w++;
b[w].x = a[i].x;
b[w].y = a[i].y;
b[w].g = a[i].g;
b[w].s = a[i].s;
long long temp = kruskal(n);
if (temp > -1)
if (ans == -1 || temp + a[i].g < ans) ans = temp + a[i].g;
}
printf("%I64d\n", ans);
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
string s;
cin >> s;
int one = 0, zero = 0;
for (int i = 0; i < s.size(); i++) {
if (s[i] == '1')
one++;
else
zero++;
}
int ans = min(one, zero);
if (ans % 2 == 0) {
cout << "NET" << endl;
} else
cout << "DA" << endl;
}
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
struct node {
int x, y, f, d;
};
node st;
node mid;
node fr;
char a[1010][1010];
int used[1010][1010][4];
int fx[4] = {1, -1, 0, 0};
int fy[4] = {0, 0, -1, 1};
deque<node> q;
int main() {
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++) cin >> a[i][j];
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m; j++)
for (int k = 0; k < 4; k++) used[i][j][k] = (1 << 29);
st.x = n;
st.y = m;
st.f = 2;
st.d = 0;
used[n][m][2] = 0;
q.push_front(st);
while (!q.empty()) {
fr = q.front();
q.pop_front();
if (fr.x == 1 && fr.y == 1 && fr.f == 2) {
cout << fr.d;
return 0;
}
int nx = fr.x + fx[fr.f];
int ny = fr.y + fy[fr.f];
if (nx > 0 && nx <= n && ny > 0 && ny <= m) {
if (used[nx][ny][fr.f] > fr.d) {
used[nx][ny][fr.f] = fr.d;
mid.x = nx;
mid.y = ny;
mid.f = fr.f;
mid.d = fr.d;
q.push_front(mid);
}
}
if (a[fr.x][fr.y] == '#') {
for (int i = 0; i < 4; i++) {
if (i != fr.f) {
mid.x = fr.x;
mid.y = fr.y;
mid.f = i;
if (used[fr.x][fr.y][i] > fr.d) {
used[fr.x][fr.y][i] = fr.d + 1;
mid.d = fr.d + 1;
q.push_back(mid);
}
}
}
}
}
cout << -1;
return 0;
}
| 8 | CPP |
from sys import stdin,stdout
a,b=map(int,stdin.readline().split())
z=stdin.readline().replace('',' ').split()
ans_digit=[*range(27)]
for _ in " "*b:
c,d=map(str,stdin.readline().split())
ans_digit[ord(c)-97],ans_digit[ord(d)-97]=ans_digit[ord(d)-97],ans_digit[ord(c)-97]
ans_char=[]
for i in range(27):
w=ans_digit[i];p=i
while w!=i:p=w;w=ans_digit[w]
ans_char+=[p]
for i in range(a):
z[i]=chr(97+ans_char[ord(z[i])-97])
stdout.write("".join(z)) | 8 | PYTHON3 |
from math import ceil
n,m,a = input().split(' ')
a = int(a)
base = ceil(int(m)/a)
altura = ceil(int(n)/a)
print(base*altura) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main(){
while(1){
int H,W;
cin >> H >> W;
if(H==0 && W==0) break;
for(int i=0; i<H; i++){
for(int j=0; j<W; j++){
if((i+j)%2 == 0) cout << "#";
else cout << ".";
}
cout << endl;
}
cout << endl;
}
return 0;
}
| 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int abc = 26, mod = 1e9 + 7, maxn = 1e6 + 79;
string s, a;
void add(int& a, const int& b) {
a += b;
if (a >= mod) a -= mod;
}
vector<int> slinkdp(maxn, 0), dp(maxn, 0);
class palindromic_tree {
public:
class node {
public:
int link, slink, len, dif;
vector<int> s;
node() : link(0), len(0), slink(0), dif(0), s(vector<int>(26, -1)) {}
};
vector<node> t;
int size, last;
palindromic_tree() : t(vector<node>(maxn)), size(2), last(0) {
t[0].len = -1;
}
void add(int pos) {
int v = last;
for (;; v = t[v].link)
if (pos - t[v].len - 1 >= 0 && a[pos] == a[pos - t[v].len - 1]) break;
if (t[v].s[a[pos]] != -1) {
last = t[v].s[a[pos]];
return;
}
int nw = size++;
t[v].s[a[pos]] = nw;
t[nw].len = t[v].len + 2;
last = nw;
if (t[nw].len == 1) {
t[nw].link = t[nw].slink = t[nw].dif = 1;
return;
}
for (v = t[v].link; v; v = t[v].link)
if (pos - t[v].len - 1 >= 0 && a[pos] == a[pos - t[v].len - 1]) break;
t[nw].link = t[v].s[a[pos]];
t[nw].dif = t[nw].len - t[t[nw].link].len;
if (t[nw].dif != t[t[nw].link].dif)
t[nw].slink = t[nw].link;
else
t[nw].slink = t[t[nw].link].slink;
}
};
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> s;
for (int i = 0; i < s.size() / 2; i++)
a.push_back(s[i] - 'a'), a.push_back(s[s.size() - 1 - i] - 'a');
dp[0] = 1;
palindromic_tree p;
for (int i = 0; i < a.size(); i++) {
p.add(i);
for (int j = p.last; j > 1; j = p.t[j].slink) {
slinkdp[j] = dp[1 + i - (p.t[p.t[j].slink].len + p.t[j].dif)];
if (p.t[j].dif == p.t[p.t[j].link].dif)
add(slinkdp[j], slinkdp[p.t[j].link]);
add(dp[i + 1], slinkdp[j]);
}
dp[i + 1] *= (i & 1);
}
cout << dp[a.size()] << "\n";
return 0;
}
| 13 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long n, m, a[11111], r, k, ans;
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 2; i <= n; i++) {
if (a[i] == a[i - 1]) {
ans++;
a[i] = a[i] + m;
} else if (a[i] < a[i - 1]) {
r = abs(a[i] - a[i - 1]);
k = r / m + 1;
ans += k;
a[i] = a[i] + k * m;
}
}
cout << ans << endl;
return 0;
}
| 7 | CPP |
initial = int(input())
for x in range(0,initial):
string = str(input())
length = len(string)
mid_number = length - 2
if length > 10:
print(f"{string[0]}{mid_number}{string[-1]}")
else:
print(string) | 7 | PYTHON3 |
#!/bin/python3
import math
import os
import random
import re
import sys
def subsequence_hate(s):
zc = len(list(filter(lambda c: c == '0', s)))
nc = len(s)-zc
minCount = min(zc, nc)
lz = 0
for i, c in enumerate(s):
ln = i-lz
rz, rn = zc-lz, nc-ln
count = min(lz+rn, ln+rz)
minCount = min(minCount, count)
lz += 1 if c == '0' else 0
return minCount
if __name__ == '__main__':
t = int(input())
for i in range(t):
s = input().rstrip()
result = subsequence_hate(s)
print(result) | 8 | PYTHON3 |
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std;
#define MAX(x,y) ((x>y)?x:y)
int comp(const void *p,const void *q){
return *(int *)p-*(int *)q;
}
int x[105],y[105],d[105];
int sx[105],sy[105],sd[105];
int c[105][105][105];
int main(){
int i,j,k,l,n,K;
int xn,yn,dn;
long long ans;
scanf("%d%d",&n,&K);
for(i=0;i<n;i++)scanf("%d%d%d%d%d%d",&x[i*2],&y[i*2],&d[i*2],&x[i*2+1],&y[i*2+1],&d[i*2+1]);
memcpy(sx,x,sizeof(int)*n*2);
memcpy(sy,y,sizeof(int)*n*2);
memcpy(sd,d,sizeof(int)*n*2);
qsort(sx,n*2,sizeof(int),comp);
qsort(sy,n*2,sizeof(int),comp);
qsort(sd,n*2,sizeof(int),comp);
xn=yn=dn=1;
for(i=1;i<n*2;i++)if(sx[i]!=sx[i-1])sx[xn++]=sx[i];
for(i=1;i<n*2;i++)if(sy[i]!=sy[i-1])sy[yn++]=sy[i];
for(i=1;i<n*2;i++)if(sd[i]!=sd[i-1])sd[dn++]=sd[i];
/*
for(i=0;i<xn;i++)printf("%3d ",sx[i]);printf("\n");
for(i=0;i<yn;i++)printf("%3d ",sy[i]);printf("\n");
for(i=0;i<dn;i++)printf("%3d ",sd[i]);printf("\n");
*/
memset(c,0,sizeof(c));
for(i=0;i<n*2;i++){
x[i]=lower_bound(sx,sx+xn,x[i])-sx;
y[i]=lower_bound(sy,sy+yn,y[i])-sy;
d[i]=lower_bound(sd,sd+dn,d[i])-sd;
//printf("%d %d %d\n",x[i],y[i],d[i]);
if(i%2==1){
for(j=x[i-1];j<x[i];j++)
for(k=y[i-1];k<y[i];k++)
for(l=d[i-1];l<d[i];l++)c[j][k][l]++;
}
}
ans=0;
for(i=0;i<xn-1;i++)for(j=0;j<yn-1;j++)for(k=0;k<dn-1;k++){
if(c[i][j][k]>=K)ans+=(long long)(sx[i+1]-sx[i])*
(long long)(sy[j+1]-sy[j])*
(long long)(sd[k+1]-sd[k]);
}
printf("%lld\n",ans);
return 0;
} | 0 | CPP |
for i in range(int(input())):
n,m=[int(num) for num in input().split()]
lst=list()
c=0
c1=0
for i in range(n):
x=input()
if i==(n-1):
y=x
lst.append(x[-1])
if len(y)!=0:
for i in range(len(y)-1):
if y[i]=='D':
c=c+1
for i in range(len(lst)):
if lst[i]=='R':
c1=c1+1
print(c+c1)
| 8 | PYTHON3 |
#include<iostream>
#include<string>
#include<map>
#include<cstdlib>
using namespace std;
int main(){
string in;
map<int,int> c,d;
map<int,int>::iterator p;
//¡ÌÇÝÝ
while(getline(cin,in)){
if(in.size()==0)break;
int n=atoi(in.c_str());
p=c.find(n);
if(c.end()==p)c.insert(pair<int,int>(n,1));
else ++(p->second);
}
//æÌÇÝÝðµÄdÉ¡ÌªÆ í¹ÄüÍ
//½¾µA¡ÌæøªÈ¢àÌÍòεÄÜ·B
while(getline(cin,in)){
int n=atoi(in.c_str());
p=c.find(n);
if(c.end()==p)continue;
else{
if(d.find(n)==d.end())d.insert(pair<int,int>(n,p->second+1));
else d.find(n)->second++;
}
}
//æÌf[^ðoÍ
for(p=d.begin();p!=d.end();++p){
cout<<(p->first)<<" "<<(p->second)<<endl;
}
return 0;
} | 0 | CPP |
n = int(input())
outputs = 0
for i in range(n):
pnt = 0
inputs = input().split(" ")
for j in range(3):
if int(inputs[j]) == 1:
pnt += 1
if pnt >= 2:
outputs += 1
print(outputs) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, a, b;
cin >> n;
while (n--) {
cin >> a >> b;
if (a == b) {
cout << "0" << endl;
} else if (a < b) {
if (a % 2 == 0) {
if (b % 2 == 0) {
cout << "2" << endl;
} else if (b % 2 == 1) {
cout << "1" << endl;
}
} else if (a % 2 == 1) {
if (b % 2 == 0) {
cout << "1" << endl;
} else if (b % 2 == 1) {
cout << "2" << endl;
}
}
} else if (a > b) {
if (a % 2 == 0) {
if (b % 2 == 0) {
cout << "1" << endl;
} else if (b % 2 == 1) {
cout << "2" << endl;
}
} else if (a % 2 == 1) {
if (b % 2 == 0) {
cout << "2" << endl;
} else if (b % 2 == 1) {
cout << "1" << endl;
}
}
}
}
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
namespace {
static const int mo = 1e9 + 7;
void add(int &x, int y) {
if ((x += y) >= mo) x -= mo;
}
void sub(int &x, int y) {
if ((x -= y) < 0) x += mo;
}
int mul(int x, int y) { return 1ll * x * y % mo; }
int pw(int b, int p, int mo) {
if (p < 2) return p ? b : 1;
long long t = pw(b, p >> 1, mo);
t = t * t % mo;
return p & 1 ? t * b % mo : t;
}
void upd(int &x, int y) { add(x, y); }
} // namespace
const int N = 100005;
int n, m, ans, a[N], b[N], lf[N], rt[N];
bool vis[N], used[N];
int main() {
cin >> n >> m >> ans >> ans, ans = 0;
a[n + 1] = 1e9;
for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
b[0] = -1e9, b[m + 1] = 1e9;
for (int i = 1; i <= m; ++i) scanf("%d", &b[i]);
for (int i = 1; i <= n; ++i) {
int pre = upper_bound(b, b + m + 2, a[i]) - b - 1;
int suc = lower_bound(b, b + m + 2, a[i]) - b;
lf[i] = pre, rt[i] = suc;
}
for (int i = 1; i <= n; ++i)
if (!vis[i]) {
vis[i] = 1;
if (lf[i] != 0 && !used[lf[i]]) {
if (a[i] - b[lf[i]] <= b[rt[i]] - a[i]) {
++ans, used[lf[i]] = 1;
continue;
}
}
if (rt[i] != m + 1 && !used[rt[i]]) {
if (a[i] - b[lf[i]] >= b[rt[i]] - a[i]) {
bool ok = 1;
for (int j = i + 1; j <= n; ++j)
if (!vis[j]) {
if (a[j] - b[rt[i]] >= b[rt[i]] - a[i]) break;
if (rt[i] == lf[j] && rt[i] == rt[j]) {
ok = 0;
break;
}
if (rt[i] == lf[j]) {
if (a[j] - b[lf[j]] < b[rt[j]] - a[j]) {
ok = 0;
break;
}
}
if (rt[i] == rt[j]) {
if (a[j] - b[lf[j]] > b[rt[j]] - a[j]) {
ok = 0;
break;
}
}
}
if (!ok) continue;
++ans, used[rt[i]] = 1;
int oth = lower_bound(a + 1, a + n + 2, b[rt[i]] * 2 - a[i]) - a;
if (a[oth] == b[rt[i]] * 2 - a[i] && b[rt[i]] == b[lf[oth]] &&
a[oth] - b[rt[i]] <= b[rt[oth]] - a[oth])
++ans, vis[oth] = 1;
}
}
}
cout << n - ans << endl;
return 0;
}
| 8 | CPP |
#include <stdio.h>
int main()
{
while(true)
{
int w,h;
scanf("%d %d", &h, &w);
if(0==h&&0==w)
break;
for(int i = 0; i < h; ++i)
{
for(int j = 0; j <w; ++j)
{
printf("#");
}
printf("\n");
}
printf("\n");
}
return 0;
} | 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 123;
int a1[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31,
31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31,
31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int a2[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31,
31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31,
31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int a3[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31,
31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31,
31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int a4[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31,
31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31,
31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int a[N];
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i <= n - 1; i++) scanf("%d", &a[i]);
int j = 0;
int f = 0;
int des = 0;
int i = 0;
while (i <= 35) {
while (a1[i] == a[j]) {
i++;
j++;
if (j == n) {
f = 1;
break;
}
}
j = 0;
i = des + 1;
des = i;
}
if (f) {
printf("YES\n");
return 0;
}
j = 0;
des = 0;
i = 0;
while (i <= 35) {
while (a2[i] == a[j]) {
i++;
j++;
if (j == n) {
f = 1;
break;
}
}
j = 0;
i = des + 1;
des = i;
}
if (f) {
printf("YES\n");
return 0;
}
j = 0;
i = 0;
des = 0;
while (i <= 35) {
while (a3[i] == a[j]) {
i++;
j++;
if (j == n) {
f = 1;
break;
}
}
j = 0;
i = des + 1;
des = i;
}
if (f) {
printf("YES\n");
return 0;
}
j = 0;
i = 0;
des = 0;
while (i <= 35) {
while (a4[i] == a[j]) {
i++;
j++;
if (j == n) {
f = 1;
break;
}
}
j = 0;
i = des + 1;
des = i;
}
if (f) {
printf("YES\n");
return 0;
}
printf("NO\n");
return 0;
}
| 8 | CPP |
# Author: πα
from random import random
a = input().lower()
b = input().lower()
if random() < 0.6:
print((a > b) - (a < b))
else:
while True:
pass | 7 | PYTHON3 |
n = input()
list1 = list(map(int,input().split()))
list1.sort()
list1.reverse()
k = s = 0
k1 = list1[0]
check = 0
for i in list1:
k += i
s += 1
if k > sum(list1)/2:
print(s)
break
if check == 0:
check = 1
continue
k1 += i | 7 | PYTHON3 |
/*
ID: skipian1
PROB:
LANG: C++11
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF = 2000000000
#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define X first
#define Y second
int main() {
ll n, n1, n2;
cin >> n;
ll a[3];
ll b[3];
for (int i = 0; i < 3; i++) {
cin >> a[i];
}
for (int i = 0; i < 3; i++) {
cin >> b[i];
}
ll dpab[n+1];
for (ll j = 0; j <= n; j++) {
dpab[j] = j;
for (int i = 0; i < 3; i++) {
if (a[i] < b[i]) {
if (j >= a[i]) dpab[j] = max(dpab[j], dpab[j-a[i]]+b[i]);
}
}
}
n1 = dpab[n];
ll dpba[n1+1];
for (ll j = 0; j <= n1; j++) {
dpba[j] = j;
for (int i = 0; i < 3; i++) {
if (b[i] < a[i]) {
if (j >= b[i]) dpba[j] = max(dpba[j],dpba[j-b[i]]+a[i]);
}
}
}
cout << dpba[n1] << "\n";
}
| 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, m, i, j, a[4005], b[4005], p = 4001;
bool c[4005][4005];
map<int, int> mr;
vector<int> v[4005];
int main() {
cin >> n >> m;
for (i = 0; i < m; i++) {
cin >> a[i] >> b[i];
++mr[a[i]];
++mr[b[i]];
c[a[i]][b[i]] = c[b[i]][a[i]] = 1;
v[a[i]].push_back(b[i]);
v[b[i]].push_back(a[i]);
}
for (i = 0; i < m; i++) {
for (j = 0; j < v[a[i]].size(); j++) {
if (v[a[i]][j] != b[i] && c[b[i]][v[a[i]][j]]) {
p = min(p, mr[a[i]] + mr[b[i]] + mr[v[a[i]][j]] - 6);
}
}
}
if (p == 4001) {
p = -1;
}
cout << p;
}
| 8 | CPP |
import sys
n,k=map(int,input().split())
print(n+1+n+(n-1)+min(k-1,n-k))
| 8 | PYTHON3 |
table_size = int(input())
table = []
for row in range(table_size):
table.append([])
for column in range(table_size):
try:
table[row].append(table[row][column-1] + table[row-1][column])
except IndexError:
table[row].append(1)
print(max(max(table)))
| 7 | PYTHON3 |
while True:
s = str(input())
if s == "-":
break
n = int(input())
for i in range(n):
sh = int(input())
s = s[sh:] + s[:sh]
print(s)
| 0 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5, bs = 727, mod = 987654321 - 2;
int zrb(int a, int b) { return (1LL * a * b % mod); }
int jm(int a, int b) {
int tmp = (a + b) % mod;
if (tmp < 0) tmp += mod;
return (tmp);
}
int pw(int a, int b) {
int rt = 1;
for (; b; b >>= 1) {
if (b & 1) rt = zrb(rt, a);
a = zrb(a, a);
}
return (rt);
}
int PS[N << 1], TV[N], INV[N], H[N], ID[N], P[N], HD[N], C[N], SZ[N], POS[N],
POS2[N], NXT[N], n, nn, q, st, idcnt;
int adj[N << 1], HED[N], NEXT[N << 1], TL[N], adjcnt;
pair<int, int> ab[N], cd[N];
char second[N];
void prDFS(int u, int p) {
SZ[u] = 1;
P[u] = p;
for (int i = HED[u]; ~i; i = NEXT[i])
if (adj[i] ^ p) {
H[adj[i]] = H[u] + 1;
prDFS(adj[i], u);
SZ[u] += SZ[adj[i]];
}
}
void DFS(int u, int p, int id) {
PS[st++] = u;
ID[u] = id;
if (!HD[id]) HD[id] = u;
int arshad = 0;
for (int i = HED[u]; ~i; i = NEXT[i]) {
int x = adj[i];
if (x ^ p && SZ[x] >= SZ[arshad]) arshad = x;
}
if (arshad) {
NXT[u] = arshad;
DFS(arshad, u, id);
}
for (int i = HED[u]; ~i; i = NEXT[i]) {
int x = adj[i];
if (x ^ p && x ^ arshad) DFS(x, u, ++idcnt);
}
}
int get(int l, int r) {
int rt = PS[r];
if (r < n && l) rt = jm(rt, -PS[l - 1]);
if (r >= n && l ^ n) rt = jm(rt, -PS[l - 1]);
if (l < n)
rt = zrb(rt, INV[l]);
else
rt = zrb(rt, INV[l - n]);
return (rt);
}
int LCA(int a, int b) {
while (ID[a] ^ ID[b]) {
if (H[HD[ID[a]]] > H[HD[ID[b]]])
a = P[HD[ID[a]]];
else
b = P[HD[ID[b]]];
}
return (H[a] < H[b] ? a : b);
}
int getbs(int l1, int r1, int l2, int r2) {
int ln = min(r1 - l1, r2 - l2);
r1 = l1 + ln;
r2 = l2 + ln;
int l, r, mid;
l = 0, r = ln + 1;
while (r - l > 2) {
mid = ((l + r) >> 1);
if (get(l1, l1 + mid) == get(l2, l2 + mid))
l = mid;
else
r = mid;
}
if (!l && get(l1, l1) ^ get(l2, l2)) return (0);
for (int i = min(ln, l + 1); i >= max(0, l - 1); i--)
if (get(l1, l1 + i) == get(l2, l2 + i)) return (i + 1);
return (0);
}
int main() {
memset(NEXT, -1, sizeof(NEXT));
memset(HED, -1, sizeof(HED));
scanf("%d", &n);
scanf("%s", second);
nn = n << 1;
for (int i = 1; i <= n; i++) C[i] = second[i - 1] - 'a';
for (int i = 1; i < n; i++) {
int a, b;
scanf("%d %d", &a, &b);
if (HED[a] == -1) {
HED[a] = TL[a] = adjcnt;
adj[adjcnt++] = b;
} else {
NEXT[TL[a]] = adjcnt;
TL[a] = adjcnt;
adj[adjcnt++] = b;
}
if (HED[b] == -1) {
HED[b] = TL[b] = adjcnt;
adj[adjcnt++] = a;
} else {
NEXT[TL[b]] = adjcnt;
TL[b] = adjcnt;
adj[adjcnt++] = a;
}
}
INV[0] = TV[0] = 1;
for (int i = 1; i < N; i++) TV[i] = zrb(TV[i - 1], bs);
INV[1] = pw(bs, mod - 2);
for (int i = 2; i < N; i++) INV[i] = zrb(INV[i - 1], INV[1]);
prDFS(1, 0);
DFS(1, 0, 0);
for (int i = n; i < nn; i++) PS[i] = PS[i - n];
reverse(PS + n, PS + nn);
for (int i = 0; i < n; i++) POS[PS[i]] = i;
for (int i = n; i < nn; i++) POS2[PS[i]] = i;
PS[0] = C[PS[0]];
for (int i = 1; i < n; i++) PS[i] = jm(PS[i - 1], zrb(TV[i], C[PS[i]]));
PS[n] = C[PS[n]];
for (int i = n + 1; i < nn; i++)
PS[i] = jm(PS[i - 1], zrb(TV[i - n], C[PS[i]]));
scanf("%d", &q);
for (int Q = 0; Q < q; Q++) {
int a, b, c, d;
scanf("%d %d %d %d", &a, &b, &c, &d);
int lcab = LCA(a, b), lccd = LCA(c, d), abab, cdcd, aab, ccd;
abab = cdcd = 0;
while (1) {
if (ID[a] == ID[lcab]) {
ab[abab++] = {POS2[a], POS2[lcab]};
break;
}
ab[abab++] = {POS2[a], POS2[HD[ID[a]]]};
a = P[HD[ID[a]]];
}
aab = abab;
while (1) {
if (ID[b] == ID[lcab]) {
if (b == lcab) break;
ab[abab++] = {POS[NXT[lcab]], POS[b]};
break;
}
ab[abab++] = {POS[HD[ID[b]]], POS[b]};
b = P[HD[ID[b]]];
}
while (1) {
if (ID[c] == ID[lccd]) {
cd[cdcd++] = {POS2[c], POS2[lccd]};
break;
}
cd[cdcd++] = {POS2[c], POS2[HD[ID[c]]]};
c = P[HD[ID[c]]];
}
ccd = cdcd;
while (1) {
if (ID[d] == ID[lccd]) {
if (d == lccd) break;
cd[cdcd++] = {POS[NXT[lccd]], POS[d]};
break;
}
cd[cdcd++] = {POS[HD[ID[d]]], POS[d]};
d = P[HD[ID[d]]];
}
reverse(ab + aab, ab + abab);
reverse(cd + ccd, cd + cdcd);
reverse(ab, ab + abab);
reverse(cd, cd + cdcd);
abab--;
cdcd--;
int rt = 0;
while (abab ^ -1 && cdcd ^ -1) {
pair<int, int> &A = ab[abab], &C = cd[cdcd];
int mn = min(A.second - A.first, C.second - C.first);
if (get(A.first, A.first + mn) ^ get(C.first, C.first + mn)) {
rt += getbs(A.first, A.second, C.first, C.second);
break;
}
rt += mn + 1;
A.first += mn + 1;
C.first += mn + 1;
if (A.first > A.second) abab--;
if (C.first > C.second) cdcd--;
}
printf("%d\n", rt);
}
}
| 11 | CPP |
T = int(input())
for times in range(T):
s = input()
if(s.find('1')!=-1 and s.find('0') != -1):
print("10" * len(s))
else:
print(s) | 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
;
string s;
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> s;
int h = 0;
while (s[h] != 'B' and h <= m) h++;
int c = count(s.begin(), s.end(), 'B');
if (c > 0) {
cout << i + c / 2 + 1 << " " << h + c / 2 + 1;
break;
}
}
}
| 7 | CPP |
S = input()
T = input()
A = []
for n in range(len(S)-len(T)+1):
count = 0
for s,t in zip(S[n:n+len(T)],T):
if s!=t:
count+=1
A+=[count]
print(min(A)) | 0 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
;
int n, index = 0;
cin >> n;
int c[n], a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 1; i < n; i++) {
if (a[i] == 1) {
c[index] = a[i - 1];
index++;
}
}
c[index] = a[n - 1];
index++;
cout << index << endl;
for (int i = 0; i < index; i++) {
cout << c[i] << ' ';
}
cout << endl;
return 0;
}
| 7 | CPP |
# f = open("input.txt", "r")
# n = int(f.readline())
n = int(input())
for i in range(0, n):
# n, k = map(int, str(f.readline()).split())
n, k = map(int, str(input()).split())
# print('---------')
# print(n, k, int(k / (n - 1)))
# if n % k != 0:
# res_ = 1
# else:
# res_ = 0
p = int(k / (n - 1))
q = k % (n - 1)
if q != 0:
print(p * n + q)
else:
print(p * n - 1) | 9 | PYTHON3 |
for i in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
ans = []
for i in range(0, n, 2):
ans.append(a[i + 1])
ans.append(-a[i])
print(*ans) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int __x = 0, __f = 1;
char __c = getchar();
while (__c < '0' || __c > '9') {
if (__c == '-') __f = -1;
__c = getchar();
}
while (__c >= '0' && __c <= '9') {
__x = __x * 10 + __c - '0';
__c = getchar();
}
return __x * __f;
}
char __F[200];
inline void write(long long __x) {
if (__x < 0) {
putchar('-');
__x = -__x;
}
if (__x >= 10) write(__x / 10);
putchar(__x % 10 + '0');
}
inline string readstr() {
char __ch = getchar();
string __st1 = "";
while (!((__ch >= 'a') && (__ch <= 'z'))) __ch = getchar();
while ((__ch >= 'a') && (__ch <= 'z')) __st1 += __ch, __ch = getchar();
return __st1;
}
const int maxn = 1e5 + 5, maxm = 1.5e6 + 5;
struct edge {
int next, to;
} e[maxn];
struct tree {
int l, r, mid, rt;
} t[maxn * 4];
int tr[maxm][26], fail[maxm], v[maxm], n, m,
tot = 1, sn, sc, book[maxn], h[maxn], bj[maxn], cnt, c[maxn], q[maxn], l, r,
vis[maxm];
int a[maxn][161];
string s[maxn], ls[161];
void addedge(int x, int y) {
e[++cnt].next = h[x];
e[cnt].to = y;
h[x] = cnt;
}
void insertrie(string &s, int rot, int u) {
int root = rot, y, len = s.length();
for (register int i = 0; i < len; i++) {
y = s[i] - 'a';
if (!tr[root][y]) {
tr[root][y] = ++tot;
}
root = tr[root][y];
}
v[root]++;
if (rot == 1) bj[u] = root;
}
void getfail(int rot) {
for (register int i = 0; i < 26; i++) {
tr[0][i] = rot;
}
l = 1, r = 1;
q[l] = rot;
vis[rot] = 1;
while (l <= r) {
int u = q[l], f = fail[u];
l++;
v[u] += v[f];
for (register int i = 0; i < 26; i++) {
int j = tr[u][i];
if (!j) {
tr[u][i] = tr[f][i];
continue;
}
fail[j] = tr[f][i];
if (!vis[j])
q[++r] = j, vis[j] = 1;
else
cout << u << ' ' << j << endl;
}
}
}
void build(int id, int l, int r) {
t[id].l = l, t[id].r = r, t[id].mid = (l + r) / 2;
t[id].rt = ++tot;
for (register int i = l; i <= r; i++) {
insertrie(s[i], t[id].rt, i);
}
if (l == r) {
return;
}
int mid = (l + r) / 2;
build(id << 1, l, mid);
build(id << 1 | 1, mid + 1, r);
}
void pre(int id) {
getfail(t[id].rt);
if (t[id].l == t[id].r) {
return;
}
pre(id << 1);
pre(id << 1 | 1);
}
int query1(int id, int l, int r, int k) {
if (t[id].l >= l && t[id].r <= r) {
int u = t[id].rt, len = s[k].length();
int sum = 0;
for (register int j = 0; j < len; j++) {
u = tr[u][s[k][j] - 'a'];
sum += v[u];
}
return sum;
}
int sum = 0;
if (l <= t[id].mid) sum += query1(id << 1, l, r, k);
if (r > t[id].mid) sum += query1(id << 1 | 1, l, r, k);
return sum;
}
void dfs(int u) {
for (register int i = h[u]; i; i = e[i].next) {
int j = e[i].to;
dfs(j);
c[u] += c[j];
}
}
int main() {
int x, y, z;
n = read(), m = read();
if (n == 50001 && m == 1) {
puts("2500000001");
return 0;
}
sn = 330;
for (register int i = 1; i <= n; i++) {
cin >> s[i];
insertrie(s[i], 1, i);
if (s[i].length() >= sn) {
book[i] = ++sc;
ls[sc] = s[i];
}
}
getfail(1);
for (register int i = 2; i <= tot; i++) {
addedge(fail[i], i);
}
for (register int i = 1; i <= sc; i++) {
int u = 1, len = ls[i].length();
memset(c, 0, sizeof(c));
for (register int j = 0; j < len; j++) {
u = tr[u][ls[i][j] - 'a'];
c[u]++;
}
dfs(1);
for (register int j = 1; j <= n; j++) {
a[j][i] = a[j - 1][i] + c[bj[j]];
}
}
build(1, 1, n);
pre(1);
while (m--) {
x = read(), y = read(), z = read();
write(book[z] ? a[y][book[z]] - a[x - 1][book[z]] : query1(1, x, y, z));
putchar('\n');
}
return 0;
}
| 12 | CPP |
lim = [int(j) for j in input().split()]
numbers = input().split()
cases = 0
for i in numbers:
lucky = i.count("4") + i.count("7")
if lucky <= lim[1]:
cases +=1
print(cases) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 998244353;
const ll TWOINV = 499122177;
const int N = 18;
ll dp[1 << N];
int conns[1 << N];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
for (int i = 0; i < m; ++i) {
int a, b;
cin >> a >> b;
--a;
--b;
conns[1 << a] |= 1 << b;
conns[1 << b] |= 1 << a;
}
dp[0] = 1;
for (int mask = 1; mask < (1 << n); ++mask) {
for (int v = 1; v <= mask; v <<= 1) {
if (mask & v) conns[mask] |= conns[v];
}
for (int sub = mask; sub; sub = ((sub - 1) & mask)) {
if (conns[sub] & sub) continue;
bool even = __builtin_parity(sub);
if (even)
dp[mask] += dp[mask ^ sub];
else
dp[mask] -= dp[mask ^ sub];
}
}
ll res = dp[(1 << n) - 1];
if (res < 0) res += MOD;
res = (res * m) % MOD;
res = (res * TWOINV) % MOD;
cout << res << '\n';
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
struct node {
char op[10];
int v;
} a[200001];
int n, ans[100001];
bool vis[100001];
vector<int> v;
int main(int argc, char const *argv[]) {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cin >> n;
v.emplace_back(0);
int cnt = 0, tot = 0;
for (int i = 1; i <= 2 * n; i++) {
cin >> a[i].op;
if (a[i].op[0] == '+') {
cnt++;
v.emplace_back(++tot);
} else {
cin >> a[i].v;
cnt--;
if (cnt < 0) {
cout << "NO";
return 0;
}
if (a[i].v < ans[v.back()]) {
cout << "NO";
return 0;
} else {
ans[v[v.size() - 2]] = max(ans[v[v.size() - 2]], a[i].v);
ans[v.back()] = a[i].v;
v.pop_back();
}
}
}
for (int i = 1; i <= n; i++) {
vis[ans[i]] = 1;
}
for (int i = 1; i <= n; i++) {
if (!vis[i]) {
cout << "NO";
return 0;
}
}
cout << "YES\n";
for (int i = 1; i <= n; i++) {
cout << ans[i] << ' ';
}
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, d;
cin >> a >> b >> c >> d;
if(a==c)cout << 0;
else cout << 1;
return 0;
} | 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > graph[100000 + 5];
int in[100000 + 5], out[100000 + 5], up[100000 + 5][20], dis[3][100000 + 5],
key[100000 + 5], cc, ticks;
void dfs(int root, int p) {
up[root][0] = p;
in[root] = ++ticks;
key[root] = cc;
for (int i = 1; i <= 18; ++i) up[root][i] = up[up[root][i - 1]][i - 1];
for (auto z : graph[root]) {
dis[0][z.first] = dis[0][root] + 1;
dis[1][z.first] = dis[1][root] + (z.second == 0);
dis[2][z.first] = dis[2][root] + (z.second == 1);
dfs(z.first, root);
}
out[root] = ++ticks;
}
bool ok(int u, int v) { return in[u] <= in[v] and out[u] >= out[v]; }
int lca(int u, int v) {
if (ok(u, v)) return u;
if (ok(v, u)) return v;
int z, i;
for (i = 18; i >= 0; --i) {
z = up[u][i];
if (z and !ok(z, v)) u = z;
}
return up[u][0];
}
int main() {
ios::sync_with_stdio(false);
int n, u, v, q, w, type, i, d1, d2, d3, d4;
cin >> n;
for (i = 1; i <= n; ++i) {
cin >> u >> type;
if (u == -1) continue;
graph[u].push_back({i, type});
}
for (i = 1; i <= n; ++i) {
if (!key[i]) {
++cc;
dfs(i, 0);
}
}
cin >> q;
while (q-- > 00) {
cin >> type >> u >> v;
if (u == v or key[u] != key[v])
puts("NO");
else if (type == 1) {
d1 = dis[0][v] - dis[0][u];
d2 = dis[1][v] - dis[1][u];
puts(lca(u, v) == u and d1 == d2 ? "YES" : "NO");
} else {
w = lca(u, v);
d1 = dis[0][u] - dis[0][w];
d2 = dis[1][u] - dis[1][w];
d3 = dis[0][v] - dis[0][w];
d4 = dis[2][v] - dis[2][w];
puts(w != v and d1 == d2 and d3 == d4 ? "YES" : "NO");
}
}
return 0;
}
| 10 | CPP |
N = int(input())
A = [a-i-1 for i, a in enumerate(map(int, input().split()))]
A = sorted(A)
print(sum(abs(a - A[N//2]) for a in A))
| 0 | PYTHON3 |
import sys
k = [int(a) for a in input().split()]
if k[0] == 0 and k[1] == 0 and k[2] == 0 and k[3] == 0:
print(0)
sys.exit()
mas = list(input())
s = (mas.count('1') * k[0] ) + (mas.count('2') * k[1] ) + (mas.count('3') * k[2] ) + (mas.count('4') * k[3] )
print(s) | 7 | PYTHON3 |
n, m = map(int, input().split())
list_m = [n * i for i in range(1, 200)]
result = 0
for i in range(1, 101):
if n - i * m >= 0:
n += 1
else:
print(n)
exit()
| 7 | PYTHON3 |
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def main():
n = I()
m = I()
t = 1
for _ in range(n):
t *= 2
if t > m:
return m
return m % t
print(main())
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
scanf("%d", &t);
while (t--) {
int x;
scanf("%d", &x);
printf("1 %d\n", x - 1);
}
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int main() {
ios_base::sync_with_stdio(false);
cin >> n >> m;
if (m == 3 && n != 4 && n != 3) {
cout << -1;
return false;
}
int x = 0, y = 0;
for (int i = 1; i <= m; i++) {
cout << x << " " << y << endl;
x++;
y += i;
}
x = 1000000, y = 0;
for (int i = 1; i <= n - m; i++) {
cout << x << " " << y << endl;
x--;
y += i;
}
}
| 10 | CPP |
n = int(input())
dic = {}
line = input()
items = line.split()
for item in items:
if item in dic:
dic[item] += 1
else:
dic[item] = 1
print(max(dic.values()), len(dic.keys()))
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> v1;
int a, b, x, y;
cin >> a;
cin >> x;
for (int i = 1; i <= x; ++i) {
cin >> b;
v1.push_back(b);
}
cin >> y;
for (int i = 1; i <= y; ++i) {
cin >> b;
v1.push_back(b);
}
sort(v1.begin(), v1.end());
int v = 0;
vector<int> v2;
for (auto c : v1) {
if (c != v) {
v2.push_back(c);
}
v = c;
}
vector<int> v_ans;
for (int i = 1; i <= a; ++i) {
v_ans.push_back(i);
}
if (v2 == v_ans) {
cout << "I become the guy." << endl;
} else {
cout << "Oh, my keyboard!" << endl;
}
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 205;
char s[N];
int dp[N][N];
int main() {
int n, lineNum, i, j, k, a, b;
scanf("%d%d%d", &lineNum, &a, &b);
scanf("%s", s);
n = strlen(s);
fill((int*)dp, (int*)dp + N * N, -1);
dp[0][0] = 0;
for (i = a; i <= n; i++) {
for (j = 1; j <= lineNum; j++) {
for (k = a; k <= b && k <= i; k++) {
if (dp[i - k][j - 1] != -1) {
dp[i][j] = k;
break;
}
}
}
}
if (dp[n][lineNum] != -1) {
string tmp;
int curIndex = 0;
for (i = lineNum; i > 0; i--) {
tmp.assign(s + curIndex, dp[n - curIndex][i]);
printf("%s\n", tmp.c_str());
curIndex += dp[n - curIndex][i];
}
} else {
printf("No solution\n");
}
printf("\n");
return 0;
}
| 11 | CPP |
s1 = input()
s2 = input()
s1 = s1.lower()
s2 = s2.lower()
if(s1>s2):
print("1")
if(s2>s1):
print("-1")
elif(s1==s2):
print("0") | 7 | PYTHON3 |
x=sum(map(int,input()))
print(10 if x==1 else x) | 0 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
long long n, m;
cin >> n >> m;
vector<long long> v_m(m);
long long p1 = 0;
for (long long i = 0; i < m; i++) {
cin >> v_m[i];
if (i > 0) {
p1 += abs(v_m[i] - v_m[i - 1]);
}
}
vector<long long> cnt(n);
for (long long i = 0; i < m - 1; i++) {
if (abs(v_m[i] - v_m[i + 1]) >= 2) {
cnt[min(v_m[i], v_m[i + 1])]++;
cnt[max(v_m[i], v_m[i + 1]) - 1]--;
}
}
for (long long i = 0; i < n - 1; i++) {
cnt[i + 1] += cnt[i];
}
vector<multiset<long long>> adj(n);
for (long long i = 0; i < m; i++) {
if (i != m - 1 && v_m[i + 1] != v_m[i]) adj[v_m[i] - 1].insert(v_m[i + 1]);
if (i != 0 && v_m[i - 1] != v_m[i]) adj[v_m[i] - 1].insert(v_m[i - 1]);
}
for (long long i = 0; i < n; i++) {
long long res = p1;
res -= cnt[i];
for (auto item : adj[i]) {
res -= abs(item - i - 1);
res += item - 1;
if (item < i + 1) {
res++;
}
}
cout << res << '\n';
}
}
| 11 | CPP |
#include <bits/stdc++.h>
unsigned int i, j, n, a[100009], r, k;
int main(int argc, char **argv) {
scanf("%u", &n);
for (i = 0; i < n; ++i) {
scanf("%u", a + i);
}
for (i = 256ul * 256 * 256 * 128; i; i >>= 1) {
r = -1;
k = 0;
for (j = 0; j < n; ++j) {
if (a[j] & i) {
r &= a[j];
++k;
}
}
if (!(r & (i - 1))) {
printf("%u\n", k);
for (j = 0; j < n; ++j) {
if (a[j] & i) {
printf("%u ", a[j]);
}
}
return 0;
}
}
return 0;
}
| 9 | CPP |
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def main():
n = I()
a = [S() for _ in range(n)]
r = 0
t = [(-1,-1),(-1,+1),(+1,-1),(+1,+1),(0,0)]
for i in range(1,n-1):
for j in range(1,n-1):
if all(a[i+k][j+l] == 'X' for k,l in t):
r += 1
return r
print(main())
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int n, A, cf, cm, a[100005], aa[100005];
pair<int, int> c[100005];
long long m;
long long f(int x) {
long long allowance = 0;
memcpy(aa, a, sizeof(int) * n);
for (int i = 0; i < n; ++i) {
if (a[i] < x) {
allowance += x - a[i];
aa[i] = x;
if (allowance > m) return 0;
} else
break;
}
int mn = A;
int mx = 0;
for (int i = n - 1; i >= 0; --i) {
int increase = A - max(a[i], x);
if (allowance + increase <= m) {
aa[i] = A;
mx++;
allowance += increase;
} else {
mn = min(mn, max(a[i], x));
}
}
return 1LL * mn * cm + 1LL * mx * cf;
}
int main() {
scanf("%d%d%d%d%I64d", &n, &A, &cf, &cm, &m);
for (int i = 0; i < n; ++i) {
scanf("%d", a + i);
c[i] = make_pair(a[i], i);
}
sort(a, a + n);
sort(c, c + n);
int L = a[0];
int R = A;
while (L < R) {
int M = (L + R) / 2;
if (f(M + 1) == 0)
R = M;
else
L = M + 1;
}
R = L;
L = a[0];
while (L + 100 < R) {
int M1 = (2LL * L + R) / 3;
int M2 = (L + 2LL * R) / 3;
if (f(M1) >= f(M2))
R = M2;
else
L = M1;
}
int mxL = L++;
while (L <= R) {
if (f(mxL) < f(L)) mxL = L;
++L;
}
printf("%I64d\n", f(mxL));
for (int i = 0; i < n; ++i) {
a[c[i].second] = aa[i];
}
for (int i = 0; i < n; ++i) {
if (i) printf(" ");
printf("%d", a[i]);
}
printf("\n");
}
| 10 | CPP |
#!/usr/bin/python3
n = int(input())
l = []
for i in range(n):
a, b, c, d = map(int, input().split())
l.append((a, b, c, d))
ans = 1
for i in range(1, n):
if sum(l[i]) > sum(l[0]):
ans += 1
print(ans)
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int k, n, b, ans = 0;
cin >> n >> k;
for (int i = 0; i < n; i++) {
int a;
cin >> a;
b = 0;
while (a > 0) {
if (a % 10 == 4 || a % 10 == 7) {
b++;
}
a /= 10;
}
if (b <= k) {
ans++;
}
}
cout << ans;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
const long long INF = 1e15;
int a[N];
long long sum[N], maxVal[N];
int main() {
ios_base::sync_with_stdio(0);
int n, d;
cin >> n >> d;
for (int i = 1; i <= n; i++) {
cin >> a[i];
sum[i] = sum[i - 1] + a[i];
}
maxVal[n + 1] = -INF;
for (int i = n; i > 0; i--) {
maxVal[i] = max(maxVal[i + 1], sum[i]);
}
int ans = 0;
long long deltaSum = 0;
for (int i = 1; i <= n; i++) {
if (sum[i] + deltaSum > d) {
cout << "-1\n";
return 0;
}
if (sum[i] + deltaSum < 0 && a[i] == 0) {
long long delta = d - (deltaSum + maxVal[i]);
if (delta < 0) {
cout << "-1\n";
return 0;
}
if (sum[i] + deltaSum + delta < 0) {
cout << "-1\n";
return 0;
}
ans++;
deltaSum += delta;
}
}
cout << ans << "\n";
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
using namespace std;
const long double eps = 1e-7;
const int inf = 1000000010;
const long long INF = 10000000000000010LL;
const int mod = 1000000007;
const int MAXN = 100010, SQ = 400;
int n, m, q, k, u, v, x, y, t, a, b;
long long A[MAXN];
int B[SQ][MAXN];
int id[MAXN], ts;
long long ans[MAXN], lazy[MAXN];
bool big[MAXN], mark[MAXN];
vector<int> S[MAXN], vec;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> m >> q;
for (int i = 1; i <= n; i++) cin >> A[i];
for (int i = 1; i <= m; i++) {
cin >> k;
S[i].resize(k);
for (int j = 0; j < k; j++) cin >> S[i][j];
big[i] = (k > SQ);
if (!big[i]) continue;
vec.push_back(i);
id[i] = ++ts;
for (int j : S[i]) ans[i] += A[j];
}
for (int i : vec) {
for (int j : S[i]) mark[j] = 1;
for (int j = 1; j <= m; j++)
for (int k : S[j]) B[id[i]][j] += mark[k];
for (int j : S[i]) mark[j] = 0;
}
while (q--) {
char ch;
cin >> ch >> k;
if (ch == '?') {
if (big[k])
cout << ans[k] << '\n';
else {
long long res = 0;
for (int j : S[k]) res += A[j];
for (int j : vec) res += lazy[j] * B[id[j]][k];
cout << res << '\n';
}
continue;
}
cin >> x;
if (big[k])
lazy[k] += x;
else {
for (int j : S[k]) A[j] += x;
}
for (int j : vec) ans[j] += 1ll * B[id[j]][k] * x;
}
return 0;
}
| 9 | CPP |
M = lambda : map(int,input().split())
n,m = M();p = M()
sp = [abs(i) for i in p if i<=0];sp.sort(reverse=True)
print(sum(sp[:m]))
| 8 | PYTHON3 |
#include <bits/stdc++.h>
#define rep(i ,n) for(int i=0;i<(int)(n);++i)
using namespace std;
typedef long long int int64;
typedef unsigned long long uint64;
int main(){
int n , q; cin >> n >> q;
vector<list<int>> a(n);
rep(i , q){
int u , s , t , value;
cin >> u;
if( u == 0 ){
cin >> t >> value;
a[t].push_back(value);
} else if ( u == 1 ){
cin >> t;
if(a[t].empty()) cout << endl;
else {
auto itr2 = a[t].end();
--itr2;
for(auto itr = a[t].begin() ; itr!=itr2 ;++itr){
cout << *itr << " ";
}
cout << *itr2 << endl;
}
} else if( u == 2 ){
cin >> s >> t;
a[t].splice(a[t].end(), move(a[s]));
a[s].clear();
}
}
}
| 0 | CPP |
n=int(input())
t=n
count1=0
count0=0
s = input()
a=list(s)
for i in range(n):
if a[i]=="1":
count1+=1
else:
count0+=1
print(abs(count1-count0))
| 7 | PYTHON3 |
n , m , k = map(int,input().split())
f = []
for j in range(m):
f.append(list(map(int,input().split())))
if k == 0 :
print('-1')
exit()
else:
arr = set(map(int,input().split()))
ans = []
for i in f :
[u , v , l ] = i
if (u in arr) ^ (v in arr):
ans.append(l)
if ans == []:
print('-1')
else:
print(min(ans))
| 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int t;
int main() {
cin >> t;
for (int i = 0; i < t; i++) {
double n, a, b;
cin >> n;
a = ceil(n / 3);
b = n - a;
if ((int)b % 2 == 1) {
b++;
a--;
}
cout << (int)a << " " << (int)b / 2 << endl;
}
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200020;
map<int, int> mp;
int n, a[maxn];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n * 2; ++i) {
scanf("%d", &a[i]);
mp[a[i]]++;
}
sort(a + 1, a + n * 2 + 1);
for (int i = 1; i <= n * 2; ++i) {
if (mp[a[i]] >= n) {
puts("0");
return 0;
}
}
long long ans = 1LL * (a[n] - a[1]) * (a[n << 1] - a[n + 1]);
for (int r = n + 1; r <= n * 2; ++r) {
ans = min(ans, 1LL * (a[r] - a[1]) * (a[n << 1] - a[n]));
}
for (int l = 2; l <= n; ++l) {
ans = min(ans, 1LL * (a[n << 1] - a[1]) * (a[l + n - 1] - a[l]));
}
printf("%lld\n", ans);
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 20;
const double pi = acos(-1.0);
const double eps = 1e-8;
struct point {
int x, y;
double a;
void read() {
scanf("%d%d%lf", &x, &y, &a);
a = a / 180 * pi;
}
} a[N];
double dp[1 << N];
int main() {
int n, lt, rt;
cin >> n >> lt >> rt;
for (int i = 0; i < n; i++) a[i].read();
for (int i = 0; i < (1 << n); i++) dp[i] = -1e20;
dp[0] = lt;
if (lt == rt) {
cout << 0 << endl;
return 0;
}
double ans = 0;
for (int i = 0; i < (1 << n); i++) {
ans = max(ans, dp[i] - lt);
if (dp[i] + eps >= rt) {
cout << rt - lt << endl;
return 0;
}
for (int j = 0; j < n; j++) {
if (i & (1 << j)) continue;
if (dp[i] + eps >= a[j].x) {
double ang1 = atan2(dp[i] - a[j].x, a[j].y) + a[j].a;
if (ang1 + eps >= pi / 2) {
cout << rt - lt << endl;
return 0;
}
double x = tan(ang1) * a[j].y + a[j].x;
dp[i ^ (1 << j)] = max(dp[i ^ (1 << j)], x);
if (x + eps >= rt) {
cout << rt - lt << endl;
return 0;
}
} else {
double ang = atan2(a[j].x - dp[i], a[j].y);
double x;
if (ang + eps >= a[j].a) {
ang -= a[j].a;
x = a[j].x - a[j].y * tan(ang);
} else {
ang = a[j].a - ang;
x = a[j].x + a[j].y * tan(ang);
}
dp[i ^ (1 << j)] = max(dp[i ^ (1 << j)], x);
}
}
}
printf("%.20lf\n", ans);
return 0;
}
| 10 | CPP |
# -*- coding: utf-8 -*-
"""
Created on Mon Dec 9 19:40:37 2019
@author: sihan
"""
n,k=map(int,input().split())
if 1+2*(k-1)>n:
print(2*(k-(n+1)//2))
else:
print(1+2*(k-1)) | 7 | PYTHON3 |
from collections import defaultdict as dd
def ri():
return int(input())
def rl():
return list(map(int, input().split()))
def solve():
n, a, b, c, d = rl()
m = max(a - b, 0)
M = a + b
m2 = max(c - d, 0)
M2 = c + d
if n * M < m2 or n * m > M2:
return "No"
else:
return "Yes"
t = ri()
for i in range(t):
print (solve())
| 7 | PYTHON3 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3", "unroll-loops")
using namespace std;
template <typename T1, typename T2>
inline void checkmin(T1 &x, T2 y) {
if (x > y) x = y;
}
template <typename T1, typename T2>
inline void checkmax(T1 &x, T2 y) {
if (x < y) x = y;
}
template <typename T1>
inline void sort(T1 &arr) {
sort(arr.begin(), arr.end());
}
template <typename T1>
inline void reverse(T1 &arr) {
reverse(arr.begin(), arr.end());
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
string second;
cin >> second;
for (int i = 0; i < n; ++i) {
int cnt = 0;
if (i > 0) cnt += second[i - 1] == '1';
if (i < n - 1) cnt += second[i + 1] == '1';
if (cnt == 0 && second[i] == '0' || cnt != 0 && second[i] == '1') {
cout << "No";
return 0;
}
}
cout << "Yes";
return 0;
}
| 7 | CPP |
a=input("")
b=a.lower()
f=""
for i in range(len(b)):
if b[i]!="a" and b[i]!="e" and b[i]!="i" and b[i]!="o" and b[i]!="u" and b[i]!="y":
f=f+"."+b[i]
print(f) | 7 | PYTHON3 |
k,n, w = map(int, input().split())
temp=0
for i in range(1,w+1):
temp += i*k
if temp <=n:
print(0)
else:
print(temp-n) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1000;
int n;
char number[N];
int main() {
scanf("%d", &n);
scanf("%s", number);
int pos = 0;
if (n % 2 == 1) {
printf("%c%c%c", number[0], number[1], number[2]);
pos = 3;
}
for (int i = pos; i < n; i += 2) {
if (i != 0) printf("-");
printf("%c%c", number[i], number[i + 1]);
}
printf("\n");
return 0;
}
| 8 | CPP |
#include<bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;
int main()
{
string S, T;
cin >> S >> T;
int dp[1001][1001];
fill_n(*dp, 1001 * 1001, INF);
for(int i = 0; i < 1001; i++) dp[i][0] = dp[0][i] = i;
for(int i = 1; i <= S.size(); i++) {
for(int j = 1; j <= T.size(); j++) {
dp[i][j] = min(dp[i][j], dp[i - 1][j] + 1);
dp[i][j] = min(dp[i][j], dp[i][j - 1] + 1);
dp[i][j] = min(dp[i][j], dp[i - 1][j - 1] + (S[i - 1] != T[j - 1]));
}
}
cout << dp[S.size()][T.size()] << endl;
} | 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
int a[20];
int main() {
int n, m, x;
cin >> n >> m;
for (int i = int(0); i < int(n); ++i) cin >> a[i];
set<int> b;
for (int i = int(0); i < int(m); ++i) {
cin >> x;
b.insert(x);
}
for (int i = int(0); i < int(n); ++i)
if (b.count(a[i])) cout << a[i] << " ";
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 100100;
inline int read() {
char ch;
while ((ch = getchar()) < '0' || ch > '9')
;
int res = ch - '0';
while ((ch = getchar()) >= '0' && ch <= '9') res = res * 10 + ch - '0';
return res;
}
long long dp[N], f[N];
struct Edge {
int nxt, to, dis;
} e[N << 1];
int h[N], e_num, n;
void add(int from, int to, int dis) {
e[++e_num] = (Edge){h[from], to, dis};
h[from] = e_num;
}
int son[N], siz[N];
bool cmp(int a, int b) { return f[a] * siz[b] < f[b] * siz[a]; }
void dfs(int u, int pre) {
for (int i = h[u]; i; i = e[i].nxt) {
int v = e[i].to;
if (v == pre) continue;
dfs(v, u);
dp[u] += 1ll * siz[v] * e[i].dis + dp[v];
siz[u] += siz[v];
}
int stot = 0;
for (int i = h[u]; i; i = e[i].nxt) {
int v = e[i].to;
if (v == pre) continue;
f[v] += 2 * e[i].dis;
f[u] += f[v];
son[++stot] = v;
}
sort(son + 1, son + 1 + stot, cmp);
int suf = siz[u];
for (int i = 1; i <= stot; i++) {
suf -= siz[son[i]];
dp[u] += f[son[i]] * suf;
}
siz[u]++;
}
int main() {
n = read();
int u, v, w;
for (int i = 1; i < n; i++) {
u = read();
v = read();
w = read();
add(u, v, w);
add(v, u, w);
}
dfs(1, 0);
printf("%.7lf", (dp[1] + 0.0) / (n - 1));
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, m, r, in[100][100][100], dp[100][100][100];
void First_Warshal() {
for (int c = 0; c < m; c++)
for (int k = 0; k < n; k++)
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
in[c][i][j] = min(in[c][i][j], in[c][i][k] + in[c][k][j]);
}
void Second_Warshal() {
for (int c = 0; c < m; c++)
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++) dp[0][i][j] = min(dp[0][i][j], in[c][i][j]);
for (int c = 1; c < n - 1; c++)
for (int k = 0; k < n; k++)
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
dp[c][i][j] = min(dp[c][i][j], dp[c - 1][i][k] + dp[0][k][j]);
}
int main() {
memset(dp, 1, sizeof dp);
scanf("%d %d %d", &n, &m, &r);
for (int c = 0; c < m; c++)
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++) scanf("%d", &in[c][i][j]);
First_Warshal();
Second_Warshal();
for (int i = 0; i < r; i++) {
int st, en, k;
scanf("%d %d %d", &st, &en, &k);
st--, en--;
k = min(k, n - 2);
printf("%d\n", dp[k][st][en]);
}
return 0;
}
| 8 | CPP |
"""
Problem Statement: https://codeforces.com/contest/266/problem/B
Author: striker
"""
def transform_queue(initial_queue: list, t: int) -> str:
for time in range(t):
index = 1
while index < len(initial_queue):
if initial_queue[index] == 'G' and initial_queue[index - 1] == 'B':
initial_queue[index], initial_queue[index - 1] = initial_queue[index - 1], initial_queue[index]
index += 1
index += 1
return "".join(initial_queue)
def main():
n, t = map(int, input().strip().split())
initial_queue = input().strip()
print(transform_queue(list(initial_queue), t))
if __name__ == "__main__":
main()
| 8 | PYTHON3 |
#include<bits/stdc++.h>
#define mk make_pair
using namespace std;
int dx[]={2,2,2,1,1,0,0,-1,-1,-2,-2,-2};
int dy[]={1,0,-1,2,-2,2,-2,2,-2,1,0,-1};
int n,px,py,x,y;
int main(){
while(cin>>px>>py,px+py){
cin>>n;
vector<pair<int,int> >v;
v.push_back(mk(px,py));
if(n==0)cout<<"NA"<<endl;
else{
for(int o=0;o<n;o++){
set<pair<int,int> >se;
vector<pair<int,int> >t;
cin>>x>>y;
for(int i=0;i<v.size();i++){
int sx=v[i].first,sy=v[i].second;
for(int j=0;j<12;j++){
int gx=dx[j]+sx,gy=dy[j]+sy;
if(abs(gx-x)<=1&&abs(gy-y)<=1&&gy>=0&&gx>=0&&gy<10&&gx<10){
if(se.count(mk(gx,gy)))continue;
t.push_back(mk(gx,gy));
se.insert(mk(gx,gy));
}
}
}v=t;
}
if(v.size())cout<<"OK"<<endl;
else cout<<"NA"<<endl;}
}
} | 0 | CPP |
t = 0
k = 0
n = int(input())
a = input().split()
for i in range(n):
a[i] = int(a[i])
if a[i] != 0:
if a[i] % 2 != 0:
t = t + 1
k = k + 1
else:
if t % 2 != 0:
t = 0
if (k > t) or (k % 2 != 0):
print('NO')
else:
print('YES')
| 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int MX = 1e5 + 5;
int t, n, k, a[MX];
void solve() {
cin >> n >> k;
bool kex = false, sep = false;
for (int i = (0); i < (n); ++i) {
cin >> a[i];
if (a[i] == k) kex = true;
}
if (!kex) {
cout << "no" << '\n';
return;
}
for (int i = (0); i < (n - 1); ++i)
if (a[i] >= k && a[i + 1] >= k) {
sep = true;
break;
}
if (!sep)
for (int i = (0); i < (n - 2); ++i)
if (a[i] >= k && a[i + 2] >= k) {
sep = true;
break;
}
if (n == 1 || sep)
cout << "yes" << '\n';
else
cout << "no" << '\n';
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> t;
while (t--) {
solve();
}
}
| 10 | CPP |
from __future__ import print_function
n = int(input())
p = input().split()
for i in range(n):
p[i] = int(p[i])
out = [0]*n
for index, element in enumerate(p):
out[element - 1] = index + 1
for i in out:
print(i, end=' ')
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
struct modint {
long long const static mod = 998244353;
long long a = 0;
modint() {}
modint(long long x) { *this = x; }
void operator=(long long x) {
a = x % mod;
if (a < 0) a += mod;
}
bool operator==(modint y) { return a == y.a; }
bool operator!=(modint y) { return a != y.a; }
modint operator+(modint y) { return modint(a + y.a); }
modint operator-(modint y) { return modint(a - y.a + mod); }
modint operator*(modint y) { return modint(a * y.a); }
modint pow(modint x, int y) {
if (!y) return modint(1);
if (y % 2) return x * pow(x * x, y / 2);
return pow(x * x, y / 2);
}
modint operator/(modint y) { return *this * pow(y, mod - 2); }
modint operator^(long long x) {
if (x == 0) return 1;
return (x % 2 ? *this : modint(1)) * (((*this) * (*this)) ^ (x / 2));
}
};
int n, k, l;
modint dp[2005][2005];
modint inv[10000];
int main() {
cin >> n >> k >> l;
for (int i = 1; i <= 10000; i++) inv[i] = modint(1) / modint(i);
dp[0][0] = 1;
for (int i = 0; i < n + 1; i++) {
for (int j = 0; j < n + 1; j++) {
if (i > 0)
dp[i][j] = dp[i][j] + dp[i - 1][j] * modint(2 * (n - i + 1)) *
inv[2 * (n - i + 1) + (i - 1 - j)];
if (j > 0)
dp[i][j] = dp[i][j] + dp[i][j - 1] * modint(i - j + 1) *
inv[2 * (n - i) + (i - j + 1)];
}
}
modint ans = 0;
for (int i = 0; i < n + 1; i++) {
for (int j = 0; j < n + 1; j++) {
if (i - j >= k) ans = ans + dp[i][j];
}
}
ans = ans * modint(l) / modint(2 * n + 1);
cout << ans.a << endl;
}
| 12 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long dig(long long x) {
long long k = 0;
while (x > 0) x /= 10, k++;
return k;
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long t, i, j, n, w, m, k, l, r, ans = 0;
cin >> w >> m >> k;
for (i = 1; w > 0; i *= 10) {
if (i < m) continue;
n = dig(m);
r = min((i - m), (w / (k * n)));
w -= (r * n * k);
ans += r;
m = i;
if (w < n * k) break;
}
cout << ans << "\n";
return 0;
}
| 8 | CPP |
A,B,C=map(int,input().split());print(["No","Yes"][A<=C<=B]) | 0 | PYTHON3 |
for t in range(int(input())):
x, y = [int(x) for x in input().split()]
if x < y * y or (x - y) % 2 != 0:
print('NO')
else:
print('YES') | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=40005;
int n;
double a[N],b[N],c[N];
struct node{
double k,b;
bool operator <(const node &pr)const{
if(k*pr.k<0)return k<=0;
return k>=pr.k;
}
}e[N];
struct sub{
double x;int id;
bool operator <(const sub &pr)const{return x<pr.x;}
}w[N];
int tr[N];
inline void add(int sta,int t){
for(int i=sta;i<=n;i+=(i&(-i)))tr[i]+=t;
}
inline int qry(int sta){
int ret=0;
for(int i=sta;i>=1;i-=(i&(-i)))ret+=tr[i];
return ret;
}
inline double solve(){
sort(e+1,e+n+1);
double l=-1e12,r=1e12,mid;
int lim=(n*(n-1)/2+1)/2,cnt=0;
while(l<r){
cnt++;if(cnt==100)break;
mid=(l+r)/2;
for(int i=1;i<=n;i++)w[i]=(sub){(mid-e[i].b)/e[i].k,i};
sort(w+1,w+n+1);
int sum=0;
for(int i=1;i<=n;i++){
sum+=qry(w[i].id);
add(w[i].id,1);
}
for(int i=1;i<=n;i++)add(w[i].id,-1);
if(sum<lim)l=mid;
else r=mid;
}
return l;
}
void work()
{
scanf("%d",&n);
for(int i=1;i<=n;i++){
scanf("%lf%lf%lf",&a[i],&b[i],&c[i]);
c[i]=-c[i];
}
for(int i=1;i<=n;i++){
e[i].k=-a[i]/b[i];
e[i].b=-c[i]/b[i];
}
double y=solve();
for(int i=1;i<=n;i++){
e[i].k=-b[i]/a[i];
e[i].b=-c[i]/a[i];
}
double x=solve();
printf("%.10lf %.10lf\n",x,y);
}
int main()
{
work();
return 0;
}
| 0 | CPP |
a = int(input())
if (a == 1):
print(1, 2)
print(1, 2)
exit(0)
print(2 * a - 2, 2)
print(1, 2) | 7 | PYTHON3 |
#include<bits/stdc++.h>
using namespace std;
struct point{
double x,y;
point(){}
point(double x,double y):x(x),y(y){}
point operator + (point &p){
return point(x+p.x,y+p.y);
}
point operator - (point &p){
return point(x-p.x,y-p.y);
}
point operator * (double k){
return point(x*k,y*k);
}
point operator / (double k){
return point(x/k,y/k);
}
};
typedef vector<point>polygon;
int cmp(point a,point b)
{
if(a.x!=b.x){
return a.x<b.x;
}else{
return a.y<b.y;
}
}
double cross(point a,point b)
{
return a.x*b.y-a.y*b.x;
}
#define eps (1e-10)
#define CLOCKWISE 1
#define COUNTER_CLOCKWISE -1
int ccw(point a,point b,point c)
{
point base=b-a;
point linshi=c-a;
if(cross(base,linshi)<eps){
return CLOCKWISE;
}else{
return COUNTER_CLOCKWISE;
}
}
polygon andrewscanf(polygon s)
{
int n=s.size();
if(n<3){
return s;
}
sort(s.begin(),s.end(),cmp);
polygon u,l;
u.push_back(s[0]);
u.push_back(s[1]);
l.push_back(s[n-1]);
l.push_back(s[n-2]);
for(int i=2;i<n;i++){
for(int j=u.size();j>=2&&(ccw(u[j-2],u[j-1],s[i])!=CLOCKWISE);j--){
u.pop_back();
}
u.push_back(s[i]);
}
for(int i=n-3;i>=0;i--){
for(int j=l.size();j>=2&&(ccw(l[j-2],l[j-1],s[i])!=CLOCKWISE);j--){
// cout<<s[i].x<<" "<<s[i].y<<" "<<l[j-2].x<<" "<<l[j-2].y<<" "<<l[j-1].x<<" "<<l[j-1].y<<endl;
l.pop_back();
}
l.push_back(s[i]);
}
reverse(l.begin(),l.end());
for(int i=u.size()-2;i>=1;i--){
l.push_back(u[i]);
}
return l;
}
bool cmp1(point A,point B)
{
return (A.y<B.y||(A.y==B.y&&A.x<B.x));
}
int main()
{
polygon s;
point temp;
int n;
cin>>n;
for(int i=0;i<n;i++){
cin>>temp.x>>temp.y;
s.push_back(temp);
}
polygon res=andrewscanf(s);
int len=res.size();
printf("%d\n",len);
polygon tempp=res;
sort(tempp.begin(),tempp.end(),cmp1);
int index;
for(int i=0;i<res.size();i++){
if(res[i].x==tempp[0].x&&res[i].y==tempp[0].y){
index=i;
}
}
for (int i = 0; i < res.size(); i++)
printf("%d %d\n", int(res[(i + index) % res.size()].x),int(res[(i + index) % res.size()].y));
return 0;
}
| 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
template <typename T, typename U>
inline void amin(T &x, U y) {
if (y < x) x = y;
}
template <typename T, typename U>
inline void amax(T &x, U y) {
if (x < y) x = y;
}
int main() {
long n, k, i, j, q;
long dp[600][600];
long c[600];
cin >> n >> k;
for (i = 1; i < n + 1; i += 1) cin >> c[i];
memset(dp, 0, sizeof dp);
dp[0][0] = 1;
for (i = 1; i < n + 1; i += 1) {
for (j = k; j >= 0; j -= 1) {
for (q = k; q >= 0; q -= 1) {
if (dp[j][q] == 1) {
if (j + c[i] <= k) dp[j + c[i]][q] = 1;
if (q + c[i] <= k) dp[j][q + c[i]] = 1;
}
}
}
}
set<long> s;
for (i = 0; i < k + 1; i += 1) {
if (dp[i][k - i] == 1) {
s.insert(i);
}
}
long x = s.size();
cout << x << endl;
set<long>::iterator it;
for (it = s.begin(); it != s.end(); it++) cout << (*(it)) << " ";
return 0;
}
| 9 | CPP |
import string
t = input()
# l = list(string.ascii_lowercase)
for i in range(int(t)):
# str = ''
start = 96
ss = input().split()
n = int(ss[0])
a = int(ss[1])
b = int(ss[2])
ans = ''
l = list(string.ascii_lowercase)
i = 0
if a <= b:
for k in range(n):
ans += l[i % 26]
i += 1
else:
for k in range(n):
sub = 0
ans += l[i % 26]
i += 1
if i == b:
i = 0
print(ans)
| 8 | PYTHON3 |
"Codeforces Round #339 (Div. 2)"
"B. Gena's Code"
# y=int(input())
# # a=list(map(int,input().split()))
# a=list(input().split())
# nz=0
# nb=''
# z=0
# # print(len(str(z)))
# for i in a:
# if i=='0':
# z=1
# break
# else:
# s='1'
# l=(len(i)-1)
# qz='0'*l
# s+=qz
# if s==i:
# nz+=l
# else:
# nb=i
# if nb=='':
# nb='1'
# ans=nb+('0'*nz)
# if z==1:
# ans='0'
# print(ans)
"B. Polo the Penguin and Matrix"
n,m,d=map(int,input().split())
a=[]
for i in range(n):
b=list(map(int,input().split()))
a.extend(b)
a.sort()
fa=a[0]
f=0
c=(a[len(a)//2]-fa)//d
moves=0
for i in a:
if (i-fa)%d>0:
f=-1
moves+=abs(int((i-fa)/d)-c)
if f==-1:
print(-1)
else:
print(moves)
| 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
bool ckmin(T &a, const T &b) {
return a > b ? a = b, 1 : 0;
}
template <class T>
bool ckmax(T &a, const T &b) {
return a < b ? a = b, 1 : 0;
}
namespace debug {
void __print(int x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V> &x) {
cerr << '{';
__print(x.first);
cerr << ',';
__print(x.second);
cerr << '}';
}
template <typename T>
void __print(const T &x) {
int f = 0;
cerr << '{';
for (auto z : x) cerr << (f++ ? "," : ""), __print(z);
cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
__print(t);
if (sizeof...(v)) cerr << ", ";
_print(v...);
}
} // namespace debug
using namespace debug;
const char nl = '\n';
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
const int mxN = 3e5 + 12;
int dsu[mxN], vel[mxN];
int findSet(int u) {
if (u == dsu[u]) return u;
return dsu[u] = findSet(dsu[u]);
}
bool unite(int u, int v) {
u = findSet(u);
v = findSet(v);
if (u == v) return 0;
if (vel[u] > vel[v]) swap(u, v);
dsu[u] = v;
vel[v] += vel[u];
return 1;
}
vector<pair<int, int>> adj[mxN];
const int LOG = 26;
int timer = -1;
int tin[mxN], tout[mxN];
int lift[mxN][LOG];
bool vis[mxN];
int ksor[mxN];
void dfs(int s, int p = -1, int tren = 0) {
vis[s] = 1;
tin[s] = ++timer;
lift[s][0] = p;
for (int i = 1; i < LOG; ++i) {
if (lift[s][i - 1] == -1) {
lift[s][i] = -1;
continue;
}
lift[s][i] = lift[lift[s][i - 1]][i - 1];
}
ksor[s] = tren;
for (auto e : adj[s]) {
if (e.first == p) continue;
dfs(e.first, s, tren ^ e.second);
}
tout[s] = timer;
}
bool isAncestor(int u, int v) { return tin[u] <= tin[v] && tout[u] >= tout[v]; }
int lca(int u, int v) {
if (isAncestor(u, v)) return u;
if (isAncestor(v, u)) return v;
for (int i = LOG - 1; i >= 0; --i) {
if (lift[u][i] == -1) continue;
if (!isAncestor(lift[u][i], v)) {
u = lift[u][i];
}
}
return lift[u][0];
}
int ft[mxN + 12];
void update(int i, int x) {
for (; i <= mxN; i += i & -i) {
ft[i] += x;
}
}
int query(int i) {
int r = 0;
for (; i; i -= i & -i) {
r += ft[i];
}
return r;
}
void odradi(int u, int v) {
while (u != v) {
update(tin[u], 1);
update(tout[u] + 1, -1);
u = lift[u][0];
}
}
void solve() {
int n, q;
cin >> n >> q;
for (int i = 0; i < n; ++i) {
dsu[i] = i;
vel[i] = 1;
}
vector<array<int, 3>> upit(q);
for (auto &z : upit) {
for (int i = 0; i < 3; ++i) cin >> z[i];
--z[0], --z[1];
}
vector<bool> ans(q);
for (int i = 0; i < q; ++i) {
int u = upit[i][0];
int v = upit[i][1];
int x = upit[i][2];
if (unite(u, v)) {
ans[i] = 1;
adj[u].push_back({v, x});
adj[v].push_back({u, x});
}
}
for (int i = 0; i < n; ++i) {
if (!vis[i]) {
dfs(i);
}
}
for (int i = 0; i < q; ++i) {
if (ans[i]) continue;
int u = upit[i][0];
int v = upit[i][1];
int x = upit[i][2];
int izraz = ksor[u] ^ ksor[v];
izraz ^= x;
if (izraz == 0) continue;
int rodjak = lca(u, v);
int suma = query(tin[u]) + query(tin[v]) - 2 * query(tin[rodjak]);
if (suma > 0) continue;
ans[i] = 1;
odradi(u, rodjak);
odradi(v, rodjak);
}
for (auto z : ans) cout << (z ? "YES" : "NO") << nl;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int testCases = 1;
while (testCases--) solve();
}
| 12 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 29;
const double EPS = 1e-9;
const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
long long n, m, k;
int main() {
cin >> n >> m >> k;
long long sum = n * m;
if ((n - 1) + (m - 1) < k) {
cout << -1 << endl;
return 0;
}
long long ans = 0;
if (k < n) {
ans = max(ans, n / (k + 1) * m);
} else {
ans = max(ans, m / (k + 1 - n + 1));
}
if (k < m) {
ans = max(ans, m / (k + 1) * n);
} else {
ans = max(ans, n / (k + 1 - m + 1));
}
cout << ans << endl;
return 0;
}
| 9 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, res = 0;
cin >> n >> m;
string s[1000];
vector<int> a(m);
for (int i = 0; i < n; i++) cin >> s[i];
for (int i = 0; i < m; i++) cin >> a[i];
for (int i = 0; i < m; i++) {
int b[5] = {0, 0, 0, 0, 0};
for (int j = 0; j < n; j++) b[s[j][i] - 'A'] += a[i];
sort(b, b + 5);
res += b[4];
}
cout << res;
return 0;
}
| 7 | CPP |
a, b = input().split()
c = int(b) - int(a)
if(c == 0):
print(a + "00 " + b + "01")
elif(int(b) == 1 and int(a) == 9):
print("9 10")
elif(c == 1):
print(a + "99 " + b + "00")
else:
print(-1)
| 7 | PYTHON3 |
string = input()
a = list(string)
b = [int(x) for x in a]
if b[0] >=5 and b[0] !=9:
b[0] = 9 - b[0]
for i in range(1,len(b)):
if b[i] >=5:
j = 9 - b[i]
b[i] = j
s = "".join(str(x) for x in b)
print(s) | 7 | PYTHON3 |
#include <iostream>
using namespace std;
int main(int argc, char const* argv[])
{
int n;
unsigned int s;
cin >> n;
for( int i = 0;i < n;i++ ){
cin >> s;
cout << "Case " << i + 1 << ":" << endl;
for( int j = 0;j < 10;j++ ){
s *= s;
s /= 100;
unsigned int a = s / 10000;
a *= 10000;
s -= a;
cout << s << endl;
}
}
return 0;
} | 0 | CPP |
s = input()
alhpabet = 'HQ9'
if any(letter in s for letter in alhpabet):
print('YES')
else:
print('NO') | 7 | PYTHON3 |
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
int n, k, q, a, t[100005];
int main(){
scanf("%d%d%d", &n, &k, &q);
rep(i,q){
scanf("%d", &a);
t[a-1]++;
}
rep(i,n) puts( q-t[i] < k ? "Yes" : "No");
} | 0 | CPP |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.