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;
scanf("%d %d %d %d", &a, &b, &c, &d);
int M, M1, M2, V, V1, V2;
M1 = (3 * a) / 10;
M2 = (a - (a / 250) * c);
if (M1 > M2) {
M = M1;
} else {
M = M2;
}
V1 = (3 * b) / 10;
V2 = (b - (b / 250) * d);
if (V1 > V2) {
V = V1;
} else {
V = V2;
}
if (M > V) {
printf("Misha\n");
} else {
if (V > M) {
printf("Vasya");
} else {
printf("Tie");
}
}
return 0;
}
| 7 | CPP |
k=int(input())
arr=list(map(int, input().split()))
arr.sort(reverse=True)
count=0
Sum=0
for x in arr:
if Sum>=k:
break
Sum+=x
count+=1
if Sum<k and count==12:
print(-1)
exit()
print(count) | 7 | PYTHON3 |
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,m;
cin>>n>>m;
int k[20],s[20][20],p[20];
for(int i=0;i<m;i++){
cin>>k[i];
for(int j=0;j<k[i];j++){
cin>>s[i][j];
}
}
for(int i=0;i<m;i++) cin>>p[i];
int ans=0;
for(int bit=0;bit<(1<<n);bit++){
int light=0;
for(int i=0;i<m;i++){
int cnt=0;
for(int j=0;j<k[i];j++){
if(bit&(1<<s[i][j]-1)) cnt++;
}
if(p[i]==0&&(cnt%2==0)) light++;
if(p[i]==1&&(cnt%2!=0)) light++;
}
if(light==m) ans++;
}
cout<<ans<<endl;
return 0;
}
| 0 | CPP |
n=int(input())
ar=[]
for i in range(9,0,-1):
if (n%i==0):
d=i
break
while (n>0):
n=n-d
ar.append(d)
print(len(ar))
print(*ar)
| 7 | PYTHON3 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:200000000")
using namespace std;
const int INF = (int)1E9;
const long long INF64 = (long long)2E18;
const double EPS = 1E-9;
const double PI = acos((double)0) * 2;
const int MAXN = 210;
int n, m, p[MAXN][MAXN];
long long k;
bool read() {
if (!(cin >> n >> m >> k)) return false;
for (int i = 0; i < int(n); ++i)
for (int j = 0; j < int(m); ++j) scanf("%d", &p[i][j]);
return true;
}
int prior[MAXN];
pair<int, int> vec[MAXN];
string pat;
int cu, u[MAXN][MAXN];
long long d[MAXN][MAXN];
long long get_d(int pos, int bal) {
if (pos == (int)pat.length()) return bal == 0;
int& myu = u[pos][bal];
long long& my = d[pos][bal];
if (myu == cu) return my;
my = 0;
myu = cu;
if (pat[pos] != ')') my += get_d(pos + 1, bal + 1);
if (bal && pat[pos] != '(') my += get_d(pos + 1, bal - 1);
my = min(my, INF64);
return my;
}
long long calc() {
++cu;
return get_d(0, 0);
}
void rec(int pos1, long long k) {
if (pos1 == n + m - 1) {
for (int i = 0; i < int(n); ++i) {
for (int j = 0; j < int(m); ++j) printf("%c", pat[i + j]);
puts("");
}
return;
}
int pos = vec[pos1].second;
pat[pos] = '(';
long long cur = calc();
if (cur >= k) return rec(pos1 + 1, k);
k -= cur;
pat[pos] = ')';
if (calc() < k) throw;
return rec(pos1 + 1, k);
}
void solve() {
for (int i = 0; i < int(n + m - 1); ++i) prior[i] = INF;
for (int i = 0; i < int(n); ++i)
for (int j = 0; j < int(m); ++j) prior[i + j] = min(prior[i + j], p[i][j]);
for (int i = 0; i < int(n + m - 1); ++i) vec[i] = make_pair(prior[i], i);
sort(vec, vec + n + m - 1);
pat = string(n + m - 1, '?');
rec(0, k);
}
int main() {
if (!read()) throw;
solve();
}
| 9 | CPP |
n=int(input())
f=list(map(int,input().split()))
arr=[0]*n
for i in range(n):
arr[f[i]-1]=i+1
for i in range(n):
print(arr[i],end=' ') | 7 | PYTHON3 |
for _ in range(int(input())):
n = int(input())
l = list(map(int,input().split(' ')))
pos = 0
for i in range(n):
if(l[i] > 0):
pos += l[i]
l[i] = 0
elif(l[i] < 0):
if(pos > abs(l[i])):
pos -= abs(l[i])
l[i] = 0
else:
l[i] = l[i] + pos
pos = 0
ans = 0
neg = 0
for i in l:
if(i < 0):
neg += abs(i)
else:
pos += i
ans = min(neg,pos)
neg -= ans
pos -= ans
print(ans+neg+pos) | 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
scanf("%lld", &n);
n += 1;
if (n == 1) {
puts("0");
return 0;
} else if (n == 2) {
puts("1");
return 0;
}
long long N = n;
if (N % 2 == 0) {
printf("%lld\n", N / 2);
} else {
printf("%lld\n", N);
}
return 0;
}
| 7 | CPP |
n, k = input().split()
n = int(n) # no. of problems
k = int(k) # no. of teams
inputList = [] # input
twoPkList = [] # array to save status for each 2 pow k values
kList = [] # array to save status for each k values in every (2 pow k) row
result = 'NO'
for j in range(k + 1):
kList.append(0)# initialize elements = FALSE + another column to check the whole number
# case k = 3 :
# 0 0 1 (1)
# 0 1 0 (2)
# 0 1 1 (3)
# 1 0 0 (4)
# ........
#for every value btn. parentheses we put a boolean value indicating whether it's already found (TRUE) or not (FALSE)
for i in range(2**k - 2): # all cases except when all 0's and all 1's
twoPkList.append(list(kList))#initialize elements = FALSE
for i in range(n):
onesList = [] # to save the positions of 1's in the input string
inputList = input().split()# split the input string
summation = 0 #initialize summation
for j in range(k):
#convert to binary
inputList[j] = int(inputList[j])# a list of ones and zeros
if (inputList[j]):# if it is a 1
onesList.append(j)# keep the position of that 1
summation += inputList[j] * (2**(k-1-j))
if (summation == 0): # input is all 0's
result = "YES"
break
if (summation == (2**k - 1)): # all ones, no need to check
continue
if (twoPkList[2**k - 2 - summation][k]): # if the complement exists
result = "YES"
break
for index, row in enumerate(twoPkList):# for every row in twoPkList
adjacentZeros = 0
if ( row[k] and (not( index == (summation - 1) )) ):# if the row is already set and it isn't the same element #### to not pointlessly check a row
for position in onesList:# for every position of 1
if (row[position] == 0):# if the position of a 1 in the input has an adjacent 0
adjacentZeros += 1 # increase number of adjacent zeros by 1
if (adjacentZeros == len(onesList)):# if number of zeros in the row == number of ones in the input in the same positions
# we can form an interesting problemset
result = "YES"
break
if (result == "YES"):
break
if (not twoPkList[summation - 1][k]):#if it is not set
twoPkList[summation - 1] = list(inputList)
twoPkList[summation - 1].append(1)
print(result)
| 9 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
pair<int, int> tab[100002];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
for (int i = 0; i < n; ++i) cin >> tab[i].first >> tab[i].second;
sort(tab, tab + n);
int maxi = tab[0].second, ans = 0;
for (int i = 1; i < n; ++i) {
if (tab[i].second < maxi)
ans++;
else
maxi = tab[i].second;
}
cout << ans;
return 0;
}
| 9 | CPP |
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;struct edge{int to,next;}e[4005];
int tot=0,sz[2005],sm[2005],f[2005],last[2005];char str[2005];
inline void adde(int u,int v) {e[++tot]=(edge){v,last[u]},last[u]=tot;return;}
inline void inse(int u,int v) {return adde(u,v),adde(v,u);}
void dfs(int root,int fa) {
int wson=0;if (str[root]^48) sz[root]=1;
for (int i=last[root];i;i=e[i].next) {
int ot=e[i].to;if(ot==fa) continue;
dfs(ot,root),sz[root]+=sz[ot],sm[ot]+=sz[ot];
sm[root]+=sm[ot];if (sm[wson]<sm[ot]) wson=ot;
}if (!wson) return f[root]=0,void();if (sm[root]>=(sm[wson]<<1)) f[root]=sm[root]>>1;
else f[root]=sm[root]-sm[wson]+min(f[wson],(sm[wson]+sm[wson]-sm[root])>>1);return;
}int main() {int n,ans=0x3f3f3f3f,u,v;scanf("%d%s",&n,str+1);
for (int i=1;i<n;++i) scanf("%d%d",&u,&v),inse(u,v);
for (int i=1;i<=n;++i) {memset(sz,0,sizeof sz);
memset(sm,0,sizeof sm),dfs(i,0);
if ((~sm[i]&1)&&f[i]>=(sm[i]>>1)) ans=min(ans,sm[i]);
}printf("%d",ans==0x3f3f3f3f?-1:ans>>1);return 0;
} | 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
deque<int> v;
for(int i = 0; i < n; i++) {
int a;
cin >> a;
if(i % 2 == 0) v.push_back(a);
else v.push_front(a);
}
if(n % 2) {
reverse(v.begin(), v.end());
}
for(int i = 0; i < n; i++) {
cout << v[i] << " ";
}
cout << endl;
}
| 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, n) for (int i = (a); i <= (int)(n); ++i)
#define per(i, n, a) for (int i = (n); i >= (int)(a); --i)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
mt19937 rnd(time(0));
#ifdef LOCAL_DEBUG
#define Log(format, ...) \
printf("\33[1;34m[%s,%d,%s] " format "\33[0m\n", __FILE__, __LINE__, \
__func__, ##__VA_ARGS__)
#define Log2(format, ...) \
printf("\33[1;35m[%s,%d,%s] " format "\33[0m\n", __FILE__, __LINE__, \
__func__, ##__VA_ARGS__)
#define Assert(cond, ...) \
do { \
if (!(cond)) { \
fflush(stdout); \
fprintf(stderr, "\33[1;31m"); \
fprintf(stderr, __VA_ARGS__); \
fprintf(stderr, "\33[0m\n"); \
assert(cond); \
} \
} while (0)
#define panic(...) Assert(0, __VA_ARGS__)
#else
#define Log(format, ...)
#define Log2(format, ...)
#define Assert(cond, ...)
#define panic(...)
#endif
inline int in() {
char ch = getchar();
int f = 1, x = 0;
while (ch < '0' || ch > '9') {
if (ch == '-')
f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9')
x = (x << 1) + (x << 3) + ch - '0', ch = getchar();
return f * x;
}
namespace Flow {
using cap_t = int;
const cap_t cap_inf = 0x3f3f3f3f;
// using cap_t = long long;
// const cap_t cap_inf = 1ll << 60;
struct Edge {
int to, rev;
cap_t cap;
Edge(int v, int r, cap_t c) {
to = v;
rev = r;
cap = c;
}
};
vector<int> cur, d;
vector<vector<Edge>> e;
int n, s, t;
void init(int size, int src, int dst) {
s = src;
t = dst;
n = size;
e.resize(n);
d.resize(n);
cur.resize(n);
}
void add_edge(int u, int v, cap_t c) {
// Log("add_edge: (%d %d) %d", u, v, c);
assert(u < n && v < n);
e[u].emplace_back(v, e[v].size(), c);
e[v].emplace_back(u, e[u].size() - 1, 0);
}
bool bfs() {
queue<int> q;
for (int i = 0; i < n; ++i) {
d[i] = 0x3f3f3f3f;
cur[i] = 0;
}
q.push(s);
d[s] = 0;
while (!q.empty()) {
int u = q.front();
q.pop();
for (const auto &v : e[u]) {
if (v.cap && d[v.to] == 0x3f3f3f3f) {
d[v.to] = d[u] + 1;
q.push(v.to);
}
}
}
return d[t] != 0x3f3f3f3f;
}
cap_t dfs(int u, cap_t F) {
if (u == t || !F)
return F;
cap_t res = 0;
for (int &i = cur[u]; i < (int)e[u].size(); ++i) {
auto &v = e[u][i];
if (v.cap && d[v.to] == d[u] + 1) {
cap_t w = dfs(v.to, min(v.cap, F - res));
res += w;
F -= w;
v.cap -= w;
e[v.to][v.rev].cap += w;
if (F == 0)
return res;
}
}
return res;
}
cap_t Dinic() {
cap_t flow = 0;
while (bfs()) {
flow += dfs(s, cap_inf);
}
return flow;
}
} // namespace Flow
const int N = 110;
void Initialization() {
// Remember to modify [inf, N, mod, ...]
}
int n, m, k;
ll dp[N][N], x[N], y[N];
int pre[N][N];
int match[N], o[N];
void dfs(int u) {
for (auto &ed : Flow::e[u]) {
int v = ed.to;
// Log("%d->%d", u, v);
if (v >= n || o[v])
continue;
o[v] = 1;
o[match[v]] = 1;
dfs(match[v]);
}
}
void solve(int CaseNum) {
n = in(), m = in(), k = in();
int s = 2 * n;
int t = 2 * n + 1;
Flow::init(2 * n + 2, s, t);
rep(i, 1, m) {
int u = in() - 1, v = in() - 1;
Flow::add_edge(u, v + n, 1);
}
for (int i = 1; i <= k; ++i) {
x[i] = in();
y[i] = in();
}
rep(i, 0, n - 1) {
Flow::add_edge(s, i, 1);
Flow::add_edge(i + n, t, 1);
}
int ans = Flow::Dinic();
memset(match, -1, sizeof(match));
rep(i, 0, n - 1) {
for (auto &ed : Flow::e[i]) {
if (ed.cap == 0 && ed.to < 2 * n) {
match[i] = ed.to;
match[ed.to] = i;
}
}
}
// for (int i = 0; i < 2 * n; ++i) {
// cout << match[i] << " ";
// }
// cout << endl;
rep(i, n, 2 * n - 1) {
if (match[i] == -1)
dfs(i);
}
// for (int i = 0; i < 2 * n; ++i)
// cout << o[i] << " ";
// cout << endl;
vector<int> del;
for (int i = 0; i < n; ++i) {
if (o[i] && match[i] != -1)
del.push_back(i);
}
for (int i = n; i < 2 * n; ++i) {
if (!o[i] && match[i] != -1)
del.push_back(i);
}
// for (auto v : del)
// printf("%d ", v);
// printf("\n");
// dp[i][j] in the i-th wave, max-matching = j, the maximum score
for (int i = 0; i <= k; ++i)
for (int j = 0; j <= n; ++j)
dp[i][j] = -(1ll << 60), pre[i][j] = -1;
dp[0][ans] = 0;
for (int i = 1; i <= k; ++i) {
for (int j = 0; j < n - i; ++j) {
for (int t = j; t <= n; ++t)
if (dp[i - 1][t] >= 0) {
if (dp[i - 1][t] + max(0ll, x[i] - (t - j) * y[i]) > dp[i][j]) {
dp[i][j] = dp[i - 1][t] + max(0ll, x[i] - (t - j) * y[i]);
pre[i][j] = t;
}
}
}
}
// for (int i = 0; i <= k; ++i) {
// for (int j = 0; j < n - i; ++j) {
// if (dp[i][j] < 0)
// cout << "-1"
// << " ";
// else
// cout << dp[i][j] << " ";
// }
// cout << endl;
// }
int cur = n - k - 1, pos = k;
for (int i = n - k - 1; i >= 0; i--) {
if(dp[k][cur] < dp[k][i])
cur = i;
}
Log("%lld", dp[pos][cur]);
vector<int> act;
while (pos > 0) {
// Log("%d %d", pos, cur);
act.push_back(0);
int prev = pre[pos][cur];
assert(prev != -1);
// Log("%d %d", prev, cur);
int delta = prev - cur;
while (delta > 0) {
assert(!del.empty());
int x = del.back();
del.pop_back();
if (x >= n)
act.push_back(-(x - n + 1));
else
act.push_back(x + 1);
delta--;
}
cur = prev;
pos--;
}
reverse(all(act));
printf("%d\n", (int)act.size());
for (auto v : act)
printf("%d ", v);
// printf("Case #%d: ", CaseNum);
}
int main() {
#ifdef LOCAL_DEBUG
freopen("in.in", "r", stdin);
// freopen("out.out", "w", stdout);
clock_t _start_time = clock();
#endif
int T = 1;
// T = in();
Initialization();
rep(_, 1, T) solve(_);
#ifdef LOCAL_DEBUG
Log2("Running Time: %.3lfs",
((double)clock() - _start_time) / CLOCKS_PER_SEC);
#endif
return 0;
}
| 12 | CPP |
#include <bits/stdc++.h>
using namespace std;
inline long long read() {
long long sum = 0, ff = 1;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-') ff = -1;
ch = getchar();
}
while (isdigit(ch)) sum = sum * 10 + (ch ^ 48), ch = getchar();
return sum * ff;
}
const long long N = 2005;
const long long mo = 1e9 + 7;
const long long base = 131;
char ch[3][N], t[N];
long long Hash1[3][N], Hash2[3][N], Hasht[N], bin[N];
long long n, m, f[3][N][N], g[3][N][N], ans, gs;
inline long long get1(long long l, long long r, long long id) {
return Hash1[id][r] - Hash1[id][l - 1] * bin[r - l + 1];
}
inline long long get2(long long l, long long r, long long id) {
return Hash2[id][l] - Hash2[id][r + 1] * bin[r - l + 1];
}
inline void Add(long long &x, long long y) {
x += y;
if (x >= mo) x -= mo;
}
inline long long merge(long long H1, long long H2, long long len) {
return H2 + H1 * bin[len];
}
inline void dp() {
memset(f, 0, sizeof(f));
memset(g, 0, sizeof(g));
for (long long i = 1; i <= m; i++)
Hasht[i] = Hasht[i - 1] * base + (t[i] - 'a' + 1);
for (long long i = 1; i <= 2; i++)
for (long long j = 1; j <= n; j++)
for (long long k = j; k >= 1; k--) {
long long len = 2 * (j - k + 1);
if (len > m) continue;
long long HA = get1(k, j, i);
long long HB = get2(k, j, 3 - i);
long long HH = Hasht[len];
if (merge(HB, HA, j - k + 1) == HH) {
if (len == m)
gs++;
else
g[i][j][len] = 1;
}
}
for (long long i = 1; i <= 2; i++)
for (long long j = 1; j <= n; j++)
if (ch[i][j] == t[1]) g[i][j][1] = 1;
for (long long i = m; i >= 1; i--)
Hasht[i] = Hasht[i + 1] * base + (t[i] - 'a' + 1);
for (long long k = 1; k < m; k++)
for (long long j = 1; j <= n; j++)
for (long long i = 1; i <= 2; i++) {
if (g[i][j][k])
if (j < n && ch[i][j + 1] == t[k + 1])
Add(f[i][j + 1][k + 1], g[i][j][k]);
if (f[i][j][k]) {
if (j < n && ch[i][j + 1] == t[k + 1])
Add(f[i][j + 1][k + 1], f[i][j][k]);
if (ch[3 - i][j] == t[k + 1]) Add(g[3 - i][j][k + 1], f[i][j][k]);
}
}
for (long long i = 1; i <= 2; i++)
for (long long j = 1; j <= n; j++) {
if (ch[i][j] == t[m]) {
if (m == 1) Add(ans, 1);
Add(ans, f[i][j - 1][m - 1]);
Add(ans, g[i][j - 1][m - 1]);
}
for (long long k = j; k <= n; k++) {
long long len = (k - j + 1) * 2;
if (len > m) continue;
long long HA = get1(j, k, 3 - i);
long long HB = get2(j, k, i);
long long HH = Hasht[m - len + 1];
if (merge(HA, HB, k - j + 1) == HH) {
if (len == m && m != 2)
gs++;
else {
Add(ans, f[i][j - 1][m - len]);
Add(ans, g[i][j - 1][m - len]);
}
}
}
}
}
signed main() {
scanf("%s", ch[1] + 1);
scanf("%s", ch[2] + 1);
n = strlen(ch[1] + 1);
scanf("%s", t + 1);
m = strlen(t + 1);
bin[0] = 1;
long long Lim = max(n, m);
for (long long i = 1; i <= Lim; i++) bin[i] = bin[i - 1] * base;
for (long long i = 1; i <= 2; i++)
for (long long j = 1; j <= n; j++)
Hash1[i][j] = Hash1[i][j - 1] * base + (ch[i][j] - 'a' + 1);
for (long long i = 1; i <= 2; i++)
for (long long j = n; j >= 1; j--)
Hash2[i][j] = Hash2[i][j + 1] * base + (ch[i][j] - 'a' + 1);
dp();
reverse(t + 1, t + m + 1);
dp();
Add(ans, gs / 2);
if (m == 1) ans /= 2;
printf("%lld\n", ans);
return 0;
}
| 11 | CPP |
for _ in range(int(input())):
n = int(input())
print((n - n % 2) // 2) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int IN() {
int x = 0, f = 0, ch;
for (; (ch = getchar()) < '0' || ch > '9';) f = (ch == '-');
for (; ch >= '0' && ch <= '9'; (ch = getchar())) x = x * 10 + ch - '0';
return f ? -x : x;
}
int N, M, D, st[105];
int F[105][25 << 1], G[2][25 << 1][25 << 1];
struct Lin {
int v, next;
} E[105 << 1];
void Link(int u, int v) {
E[++D] = (Lin){v, st[u]};
st[u] = D;
E[++D] = (Lin){u, st[v]};
st[v] = D;
}
void Plu(int& a, int b) {
a += b;
if (a >= 1000000007) a -= 1000000007;
}
void DFS(int u, int f) {
int tot = 0;
for (int i = st[u], v; i; i = E[i].next)
if ((v = E[i].v) != f) DFS(v, u), tot++;
if (!tot) {
F[u][M + M] = 1;
F[u][M - 1] = 1;
}
for (int p = 0, lim = 1; p <= lim; p++)
for (int a = 0, lim = M * 2; a <= lim; a++)
for (int b = 0, lim = M * 2; b <= lim; b++) G[p][a][b] = 0;
G[0][2 * M][0] = 1;
int p = 0, q = 1;
for (int i = st[u], v; i; i = E[i].next)
if ((v = E[i].v) != f) {
p ^= 1;
q ^= 1;
for (int a = 0, lim = M * 2; a <= lim; a++)
for (int b = 0, lim = M * 2; b <= lim; b++) G[p][a][b] = 0;
for (int a = 0, lim = M * 2; a <= lim; a++)
for (int b = 0, lim = M * 2; b <= lim; b++)
if (G[q][a][b])
for (int c = 0, lim = M * 2; c <= lim; c++)
Plu(G[p][min(a, c)][max(b, c)],
1ll * G[q][a][b] * F[v][c] % 1000000007);
}
for (int a = 0, lim = M * 2; a <= lim; a++)
for (int b = a, lim = M * 2; b <= lim; b++) {
if (a - M + b - M >= 1) {
Plu(F[u][M + M], G[p][a][b]);
Plu(F[u][b - 1], G[p][a][b]);
} else if (a == 0) {
Plu(F[u][M + M], G[p][a][b]);
} else {
Plu(F[u][M + M], G[p][a][b]);
Plu(F[u][a - 1], G[p][a][b]);
}
}
}
int main(int argc, char* argv[]) {
N = IN();
M = IN();
for (int i = 2, lim = N; i <= lim; i++) Link(IN(), IN());
if (M == 0) return puts("1"), 0;
DFS(1, 0);
int Ans = 0;
for (int c = M, lim = 2 * M; c <= lim; c++) Plu(Ans, F[1][c]);
printf("%d\n", Ans);
return 0;
}
| 9 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int h, m, s, a, b, c, d;
cin >> h >> m >> s;
cin >> a >> b;
m = m / 5;
s = s / 5;
int w1, w2;
w1 = w2 = 0;
if (b > a) {
if (h >= a && h < b)
w2 = 1;
else
w1 = 1;
if (m >= a && m < b)
w2 = 1;
else
w1 = 1;
if (s >= a && s < b)
w2 = 1;
else
w1 = 1;
} else {
if (h < a && h >= b)
w2 = 1;
else
w1 = 1;
if (m < a && m >= b)
w2 = 1;
else
w1 = 1;
if (s < a && s >= b)
w2 = 1;
else
w1 = 1;
}
if (w1 == 0 || w2 == 0)
cout << "YES";
else
cout << "NO";
cout << endl;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
template <class T>
void dbg(const char* xn, T x) {
if (0) cout << xn << ": " << x << "\n";
}
template <class T, class... TA>
void dbg(const char* xn, T x, TA... t) {
while (*xn != ',')
if (0) cout << *xn++;
if (0) cout << ": " << x << ",";
dbg(xn + 1, t...);
}
template <class T>
inline bool upd_max(T& x, T y) {
return y > x ? x = y, true : false;
}
template <class T>
inline bool upd_min(T& x, T y) {
return y < x ? x = y, true : false;
}
const int N = 1000007;
long long n, P[N];
vector<long long> G[N];
bitset<N> vis;
void DFS(long long v) {
vis[v] = 1;
for (auto u : G[v]) {
if (vis[u]) continue;
DFS(u);
}
}
void solve() {
cin >> n;
for (long long i = 1; i <= (n); ++i) cin >> P[i], G[i].push_back(P[i]);
if (n < 100) cout << "Petr", exit(0);
long long rst = 0;
for (long long i = 1; i <= n; ++i) {
if (vis[i]) continue;
++rst;
DFS(i);
}
if (rst % 2)
cout << "Um_nik";
else
cout << "Petr";
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout << fixed << setprecision(10);
solve();
return 0;
}
| 8 | CPP |
a=int(input())
if a>5:
k=1
while True:
b=a//(5*((2**k)-1))
if b==0:
break
else:
k+=1
continue
c=a-5*((2**(k-1)-1))
d=c//(2**(k-1))
if d==0:
print('Sheldon')
if d==1:
print("Leonard")
if d==2:
print("Penny")
if d==3:
print("Rajesh")
if d==4:
print("Howard")
else:
if a==1:
print('Sheldon')
elif a==2:
print("Leonard")
elif a==3:
print("Penny")
elif a==5:
print("Howard")
elif a==4:
print("Rajesh")
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const long long ool = (long long)1e18;
const int oo = (int)1e9 + 7;
const int N = (int)1e5 + 1;
const int N6 = (int)1e6 + 1;
const int N3 = (int)1e3 + 1;
const int N4 = (int)1e4 + 1;
const long double EPS = 1e-6;
int cntbit(int s) { return __builtin_popcount(s); }
int getbit(int s, int i) { return (s >> i) & 1; }
int gcd(int a, int b) {
if (b == 0)
return a;
else
return gcd(b, a % b);
}
int lcm(int a, int b) { return a / (gcd(a, b) * b); }
bool used[N + 5];
string s;
long long ans, cnt;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> s;
for (int i = s.size() - 1; i >= (int)0; --i) {
if (s[i] == 'b')
cnt++;
else {
ans = (ans + cnt) % oo;
cnt = cnt * 2 % oo;
}
}
cout << ans << "\n";
return 0;
}
| 8 | CPP |
import math
r=math.pi
for _ in range(int(input())):
N=int(input())
if(N==199):
print(126.687663595)
else:
w=2*N
t=(math.cos(r/(2*w)))/(math.sin(r/w))
print(t) | 9 | PYTHON3 |
n = int(input())
seq = list(map(int, input().split()))
dp = [0 for i in range(n+1)]
dp[seq[0]] = 1
for i in range(1, len(seq)):
if dp[seq[i]-1] > 0:
dp[seq[i]] = dp[seq[i]-1] + 1
else:
dp[seq[i]] = 1
print(n - max(dp)) | 9 | PYTHON3 |
'''
自宅用PCでの解答
'''
import math
#import numpy as np
import itertools
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)
mod = 10**9+7
# mod = 998244353
dir = [(-1,0),(0,-1),(1,0),(0,1)]
alp = "abcdefghijklmnopqrstuvwxyz"
INF = 1<<32-1
# INF = 10**18
def main():
n = int(ipt())
wrds = []
hq = []
usd = set()
for i in range(n):
s,c = input().split()
c = int(c)
wrds.append((s,c))
hpq.heappush(hq,(c,s,1))
while hq:
hc,hs,hp = hpq.heappop(hq)
usd.add((hs,hp))
ls = len(hs)
if hs == hs[::-1]:
print(hc)
exit()
for si,ci in wrds:
lsi = len(si)
if lsi > ls:
if hp == 1:
wt = si[::-1]
# print(wt)
if hs == wt[:ls:] and not (wt[ls::],-1) in usd:
hpq.heappush(hq,(hc+ci,wt[ls::],-1))
else:
if hs == si[:ls:] and not (si[ls::],1) in usd:
hpq.heappush(hq,(hc+ci,si[ls::],1))
else:
if hp == 1:
wt = si[::-1]
if wt == hs[:lsi:] and not (hs[lsi::],1) in usd:
hpq.heappush(hq,(hc+ci,hs[lsi::],1))
else:
if si == hs[:lsi:] and not (hs[lsi::],-1) in usd:
hpq.heappush(hq,(hc+ci,hs[lsi::],-1))
# print(hq)
print(-1)
return None
if __name__ == '__main__':
main()
| 0 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
template <class T>
T cross(complex<T> a, complex<T> b) {
return imag(a * conj(b));
}
template <class T>
T min(T a, T b, T c) {
return min(a, min(b, c));
}
template <class T>
T max(T a, T b, T c) {
return max(a, max(b, c));
}
template <class T>
void setmin(T &a, T b) {
if (b < a) a = b;
}
template <class T>
void setmax(T &a, T b) {
if (b > a) a = b;
}
const int MAXN = 200000;
int N;
long long W[MAXN];
long long l, r, ql, qr;
long long minWt() {
long long ls = 0, rs = 0;
for (int i = 0; i < N; i++) rs += W[i];
long long ans = r * rs + (N - 1) * qr;
for (int i = 0; i < N; i++) {
ls += W[i], rs -= W[i];
long long nl = i + 1, nr = N - nl;
long long val = ls * l + rs * r;
if (nl > nr)
val += (nl - nr - 1) * ql;
else if (nr > nl)
val += (nr - nl - 1) * qr;
if (val < ans) {
ans = val;
}
}
return ans;
}
void io(istream &in, ostream &out) {
in >> N >> l >> r >> ql >> qr;
for (int i = 0; i < N; i++) in >> W[i];
out << minWt() << '\n';
}
int main() {
ifstream fin("354A.in");
if (fin.good()) {
ofstream fout("354A.out");
io(fin, fout);
fin.close();
fout.close();
} else
io(cin, cout);
return 0;
}
| 7 | CPP |
######################################################################
# Write your code here
import sys
input = sys.stdin.readline
#import resource
#resource.setrlimit(resource.RLIMIT_STACK, [0x10000000, resource.RLIM_INFINITY])
#sys.setrecursionlimit(0x100000)
# Write your code here
RI = lambda : [int(x) for x in sys.stdin.readline().strip().split()]
rw = lambda : input().strip().split()
from collections import defaultdict as df
#import heapq
#heapq.heapify(li) heappush(li,4) heappop(li)
#import random
#random.shuffle(list)
#infinite = float('inf')
#######################################################################)
n=int(input())
#0 4 8 12 .... +1
#n/2(2*0 + (n-1)*4) + 1
ans=n*((n-1)*4)//2
ans+=1
print(ans)
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int t,n;
string s;
int main()
{
scanf("%d",&t);
while(t--)
{
int flag=0;
scanf("%d",&n);
cin>>s;
if(s.substr(0,4)=="2020") flag=1;
else if(s.substr(n-4,4)=="2020") flag=1;
else if(s.substr(0,1)=="2" && s.substr(n-3,3)=="020") flag=1;
else if(s.substr(0,2)=="20" && s.substr(n-2,2)=="20") flag=1;
else if(s.substr(0,3)=="202" && s.substr(n-1,1)=="0") flag=1;
if(flag) printf("YES\n");
else printf("NO\n");
}
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 150000 + 1;
const int maxm = 10000;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
int a[maxn];
int vis[maxn];
int n;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
a[n + 1] = 1001;
n++;
int ans = 0;
for (int i = 0; i <= n; i++) {
for (int j = i + 1; j <= n; j++) {
if (j - i + 1 == a[j] - a[i] + 1)
for (int k = i + 1; k <= j - 1; k++) ans = max(ans, j - i - 1);
}
}
printf("%d\n", ans);
return 0;
}
| 7 | CPP |
n, m = map(int, input().split(" "))
for i in range(m):
if n % 10 == 0:
n /= 10
else:
n -= 1
print(int(n))
| 7 | PYTHON3 |
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <sstream>
#include <cmath>
#include <climits>
#include <map>
using namespace std;
#define reep(i,f,n) for(int i=f; i<int(n); ++i)
#define rep(i,n) reep(i,0,n)
typedef vector<int> vi;
int main()
{
double x[4], y[4];
while(1){
rep(i, 4){
if(scanf("%lf,%lf,", &x[i], &y[i]) == EOF)
return 0;
}
bool ok = true;
bool turn = true;
rep(i, 4){
bool b = (x[(i+1)%4]-x[i])*(y[(i+2)%4]-y[i])-(y[(i+1)%4]-y[i])*(x[(i+2)%4]-x[i]) < 0.0;
if(!i) turn = b;
else if(turn^b){
ok = false;
break;
}
}
puts(ok ? "YES" : "NO");
}
} | 0 | CPP |
n = int(input())
a = list(map(int, input().split()))
n += 1
f = [0] * (10 ** 5 + 10)
x = 0
mx = 0
cnt = [0] * (10 ** 5 + 10)
i = 1
ans = 0
for c in a:
cnt[f[c]] -= 1
f[c] += 1
cnt[f[c]] += 1
mx = max(mx, f[c])
ok = False
if cnt[1] == i:
ok = True
elif cnt[1] == 1 and cnt[mx] * mx == i - 1:
ok = True
elif cnt[mx - 1] * (mx - 1) == i - mx and cnt[mx] == 1:
ok = True
if ok:ans = i
i += 1
print(ans)
| 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
inline int _Int() {
char Syed_Zafrul_Lipu[1000];
scanf("%s", Syed_Zafrul_Lipu);
return atoi(Syed_Zafrul_Lipu);
}
inline string _String() {
char Syed_Zafrul_Lipu[100001];
scanf("%s", Syed_Zafrul_Lipu);
string s(Syed_Zafrul_Lipu);
return s;
}
const int M = 2000 + 10;
char ch[M][M];
int main() {
int n = _Int(), a, b, c;
int m = _Int();
int pre = _Int();
for (int i = 0; i < n; i++) scanf("%s", ch[i]);
for (int j = 0; j < m; j++) {
int ans = 0;
for (int i = 0, mv = 0; i < n; i++, mv++) {
if ((i + mv) >= 0 && (i + mv < n) && ch[i + mv][j] == 'U') ans++;
if ((j + mv) >= 0 && (j + mv < m) && ch[i][j + mv] == 'L') ans++;
if ((i - mv) >= 0 && (i - mv < n) && ch[i - mv][j] == 'D') ans++;
if ((j - mv) >= 0 && (j - mv < m) && ch[i][j - mv] == 'R') ans++;
}
printf("%d ", ans);
}
puts("");
return 0;
}
| 8 | CPP |
import math
def read():
return map(int, input().split())
def solve(x, b, lcm):
d, r = divmod(x, lcm)
return d*(lcm-b) + max(0, r-b+1)
for _ in range(int(input())):
A, B, q = read()
a = min(A, B)
b = max(A, B)
g = math.gcd(a, b)
lcm = a*b//g
for i in range(q):
l, r = read()
print(solve(r, b, lcm) - solve(l-1, b, lcm), end=' ')
print() | 9 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int hh, mm, a;
scanf("%d:%d\n%d", &hh, &mm, &a);
int t = mm + hh * 60 + a;
t %= 24 * 60;
mm = t % 60;
hh = t / 60;
printf("%02d:%02d\n", hh, mm);
return 0;
}
| 8 | CPP |
n, m = map(int, input().split())
a = list(map(int, input().split()))
n_name = 0
pages = []
for x in a:
page, n_name = divmod(x + n_name, m)
pages.append(page)
print(*pages) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9;
const long long N = 1e5 + 2;
const long long mod = 1e9 + 7;
const long double eps = 1E-7;
int k, p[N];
bool used[N];
int n, m, x, y;
vector<pair<int, int> > D[N];
vector<int> f, V[N];
void dfs(int v) {
used[v] = 1;
for (auto to : D[v]) {
int x = to.first;
int y = to.second;
int r = V[x][y];
if (x == n) continue;
int l = V[x + 1][y];
if (p[x + 1] == y) {
if (used[l]) l += m;
if (used[r]) r += m;
if (l < r) {
if (l > m) {
cout << "No";
exit(0);
}
if (!used[l]) dfs(l);
}
}
}
}
int main() {
ios_base::sync_with_stdio(0);
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> k;
p[i] = -1;
for (int j = 0; j < k; j++) {
cin >> x;
V[i].push_back(x);
D[x].push_back({i, j});
}
if (i != 1) {
x = V[i].size();
y = V[i - 1].size();
for (int j = 0; j < min(x, y); j++) {
if (V[i][j] != V[i - 1][j]) {
p[i] = j;
break;
}
}
if (x < y && p[i] == -1) {
cout << "No";
return 0;
}
}
}
for (int i = n; i > 1; i--) {
x = p[i];
if (x == -1) continue;
int l = V[i][x];
int r = V[i - 1][x];
if (used[l]) l += m;
if (used[r]) l += m;
if (l < r) {
if (l > m) {
cout << "No";
return 0;
}
if (!used[l]) dfs(l);
}
}
for (int i = 1; i <= m; i++)
if (!used[i]) f.push_back(i);
cout << "Yes\n" << f.size() << endl;
for (auto to : f) cout << to << " ";
}
| 11 | CPP |
n,t=map(int,input().split())
glass=[[0 for i in range(0,n+1)] for j in range(0,n+1)]
ans=0
glass[0][0]=t
for i in range(0,n):
for j in range(0,i+1):
if(glass[i][j]>=1.0):
t=glass[i][j]-1
glass[i+1][j]+=(t/2)
glass[i+1][j+1]+=(t/2)
ans+=1
print(ans) | 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
long long i, i1, j, k, t, n, m, res, x[200010], a[200010], b[200010], c[200010];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for (i = 0; i < n; i++) {
cin >> x[i];
}
sort(x, x + n);
a[0] = 1;
b[0] = 1;
c[0] = 1;
for (i = 1; i < n; i++) {
if (x[i] == x[i - 1]) {
a[i] = a[i - 1];
b[i] = b[i - 1];
c[i] = c[i - 1];
} else if (x[i] == x[i - 1] + 1) {
a[i] = min(a[i - 1] + 1, b[i - 1]);
b[i] = min(min(a[i - 1] + 1, b[i - 1] + 1), c[i - 1]);
c[i] = min(min(a[i - 1] + 1, b[i - 1] + 1), c[i - 1] + 1);
} else if (x[i] == x[i - 1] + 2) {
a[i] = min(min(a[i - 1] + 1, b[i - 1] + 1), c[i - 1]);
b[i] = min(min(a[i - 1] + 1, b[i - 1] + 1), c[i - 1] + 1);
c[i] = min(min(a[i - 1] + 1, b[i - 1] + 1), c[i - 1] + 1);
} else {
a[i] = min(min(a[i - 1] + 1, b[i - 1] + 1), c[i - 1] + 1);
b[i] = min(min(a[i - 1] + 1, b[i - 1] + 1), c[i - 1] + 1);
c[i] = min(min(a[i - 1] + 1, b[i - 1] + 1), c[i - 1] + 1);
}
}
cout << min(min(a[n - 1], b[n - 1]), c[n - 1]) << ' ';
for (i = 1; i < n; i++) {
if (x[i] == x[i - 1]) {
a[i] = a[i - 1];
b[i] = max(a[i - 1] + 1, b[i - 1]);
c[i] = max(max(a[i - 1] + 1, b[i - 1] + 1), c[i - 1]);
} else if (x[i] == x[i - 1] + 1) {
a[i] = max(a[i - 1] + 1, b[i - 1]);
b[i] = max(max(a[i - 1] + 1, b[i - 1] + 1), c[i - 1]);
c[i] = max(max(a[i - 1] + 1, b[i - 1] + 1), c[i - 1] + 1);
} else if (x[i] == x[i - 1] + 2) {
a[i] = max(max(a[i - 1] + 1, b[i - 1] + 1), c[i - 1]);
b[i] = max(max(a[i - 1] + 1, b[i - 1] + 1), c[i - 1] + 1);
c[i] = max(max(a[i - 1] + 1, b[i - 1] + 1), c[i - 1] + 1);
} else {
a[i] = max(max(a[i - 1] + 1, b[i - 1] + 1), c[i - 1] + 1);
b[i] = max(max(a[i - 1] + 1, b[i - 1] + 1), c[i - 1] + 1);
c[i] = max(max(a[i - 1] + 1, b[i - 1] + 1), c[i - 1] + 1);
}
}
cout << max(max(a[n - 1], b[n - 1]), c[n - 1]);
return 0;
}
| 11 | CPP |
#include <bits/stdc++.h>
#pragma gcc optimize("Ofast")
using namespace std;
template <typename T>
using maxHeap = priority_queue<T, vector<T>, less<T>>;
template <typename T>
using minHeap = priority_queue<T, vector<T>, greater<T>>;
inline void input(int& _x) {
_x = 0;
int _tmp = 1;
char _tc = getchar();
while ((_tc < '0' || _tc > '9') && _tc != '-') _tc = getchar();
if (_tc == '-') _tc = getchar(), _tmp = -1;
while (_tc >= '0' && _tc <= '9') _x = _x * 10 + (_tc - 48), _tc = getchar();
_x *= _tmp;
}
inline void output(int _x) {
char _buff[20];
int _f = 0;
if (_x == 0) putchar('0');
while (_x > 0) {
_buff[_f++] = _x % 10 + '0';
_x /= 10;
}
for (_f -= 1; _f >= 0; _f--) putchar(_buff[_f]);
putchar('\n');
}
template <typename Iter>
ostream& _out(ostream& s, Iter b, Iter e) {
s << "[";
for (auto it = b; it != e; it++) s << (it == b ? "" : " ") << *it;
s << "]";
return s;
}
template <class T1, class T2>
ostream& operator<<(ostream& out, pair<T1, T2> p) {
return out << '(' << p.first << ", " << p.second << ')';
}
template <typename T>
ostream& operator<<(ostream& s, const vector<T>& c) {
return _out(s, c.begin(), c.end());
}
vector<int> xx, yy;
signed main() {
int n;
cin >> n;
xx.push_back(0);
for (int i = 0; i < n; i++) {
int x;
cin >> x;
xx.push_back(x + xx.back());
}
int ans = 0;
for (int i = 0; i < n; i++)
for (int j = i + 1; j <= n; j++)
if (xx[j] - xx[i] > 100 * (j - i)) ans = max(ans, j - i);
cout << ans << '\n';
}
| 8 | CPP |
#include <bits/stdc++.h>
#define N 14
using namespace std;
int n;
typedef pair<double,double> P;
typedef pair<P,P> PP;
double X[N],Y[N],X2[N],Y2[N];
double dis(double x,double y,double x2,double y2){
return sqrt((x-x2)*(x-x2)+(y-y2)*(y-y2));
}
map<P,double> mem[1<<N];
double dfs(double x,double y,int bit){
if(bit==(1<<n)-1) return 0;
P sta = P(x,y);
if(mem[bit].count(sta)) return mem[bit][sta];
double res=1e9;
for(int i=0;i<n;i++){
if(bit&(1<<i))continue;
int nbit = bit|1<<i;
double a = dis(x,y,X[i],Y[i]) + dfs(X2[i],Y2[i],nbit);
double b = dis(x,y,X2[i],Y2[i]) + dfs(X[i],Y[i],nbit);
res = min(res,min(a,b));
}
return mem[bit][sta]=res;
}
int main(){
int Case=0;
while(1){
cin>>n;
if(n==0) break;
double sum =0;
for(int i=0;i<n;i++) cin>>X[i]>>Y[i]>>X2[i]>>Y2[i],sum+=dis(X[i],Y[i],X2[i],Y2[i]);
for(int i=0;i<(1<<N);i++) mem[i].clear();
double ans = 1e9;
for(int i=0;i<n;i++)
ans = min(ans, min(dfs(X2[i],Y2[i],1<<i),dfs(X[i],Y[i],1<<i)));
printf("Case %d: %.10f\n",++Case,ans+sum);
}
return 0;
} | 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 85;
int n, V, now;
int sl[N], sr[N], lens[N], h[N * 2];
double ans[N][N];
void add(int x, int l, int r, double y) {
ans[x][l] += y;
ans[x][r + 1] -= y;
}
void trans(int x, int c, double F[N][N]) {
double g0 =
sr[x] > now + 1 ? 1.0 * (h[sr[x]] - h[max(now + 1, sl[x])]) / lens[x] : 0;
double g1 = sl[x] < now ? 1.0 * (h[min(now, sr[x])] - h[sl[x]]) / lens[x] : 0;
double g2 =
sl[x] <= now && sr[x] > now ? 1.0 * (h[now + 1] - h[now]) / lens[x] : 0;
for (int k = c + 1; k >= 1; k--) {
for (int t = c + 1 - k; t >= 1; t--)
F[k][t] = F[k][t] * g0 + F[k - 1][t] * g1 + F[k][t - 1] * g2;
F[k][0] = F[k][0] * g0 + F[k - 1][0] * g1;
}
for (int t = c + 1; t >= 1; t--) F[0][t] = F[0][t] * g0 + F[0][t - 1] * g2;
F[0][0] *= g0;
}
void solve(int l, int r, double F[N][N]) {
if (l == r) {
if (sl[l] > now || sr[l] <= now) return;
double pn = 1.0 * (h[now + 1] - h[now]) / lens[l];
for (int k = 0; k < n; k++)
for (int t = 0; k + t < n; t++)
add(l, k + 1, k + t + 1, F[k][t] * pn / (t + 1));
return;
}
int mid = (l + r) >> 1;
double FH[N][N];
memcpy(FH, F, sizeof(FH));
for (int i = r; i > mid; i--) trans(i, n - (i - l + 1), F);
solve(l, mid, F);
for (int i = l; i <= mid; i++) trans(i, n - (r - i + 1), FH);
solve(mid + 1, r, FH);
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d%d", sl + i, sr + i);
for (int i = 1; i <= n; i++)
lens[i] = sr[i] - sl[i], h[++V] = sl[i], h[++V] = sr[i];
sort(h + 1, h + V + 1);
V = unique(h + 1, h + V + 1) - (h + 1);
for (int i = 1; i <= n; i++)
sl[i] = lower_bound(h + 1, h + V + 1, sl[i]) - h,
sr[i] = lower_bound(h + 1, h + V + 1, sr[i]) - h;
for (now = 1; now < V; now++) {
double tmpf[N][N];
memset(tmpf, 0, sizeof(tmpf));
tmpf[0][0] = 1;
solve(1, n, tmpf);
}
for (int i = 1; i <= n; i++, puts(""))
for (int j = 1; j <= n; j++) printf("%.12lf ", ans[i][j] += ans[i][j - 1]);
return 0;
}
| 11 | CPP |
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
using namespace std;
typedef long long LL;
char g[1005][1005] = {0};
string c[10][10];
LL n;
void init(){
c[3][0] = "aa.";
c[3][1] = "..b";
c[3][2] = "..b";
c[4][0] = "aabc";
c[4][1] = "ddbc";
c[4][2] = "efgg";
c[4][3] = "efhh";
c[5][0] = "aabbc";
c[5][1] = "dee.c";
c[5][2] = "d..fg";
c[5][3] = "h..fg";
c[5][4] = "hiijj";
c[7][0] = "aabbcc.";
c[7][1] = "gg.gg.d";
c[7][2] = "..g..gd";
c[7][3] = "..g..ge";
c[7][4] = "gg.gg.e";
c[7][5] = "..g..gf";
c[7][6] = "..g..gf";
}
LL cov(LL x,LL y,LL id){
for(LL i = 0;i < id;i ++){
for(LL j = 0;j < id;j ++){
g[x + i][y + j] = c[id][i][j];
}
}
}
void solve(LL x,LL y){
if(x == -1){
if(y == 2){ cout << -1 << endl; return; }
if(y == 3) cov(1,1,3);
if(y == 6){ cov(1,1,3); cov(4,4,3); }
if(y == 5) cov(1,1,5);
if(y == 7) cov(1,1,7);
if(y == 11){ cov(1,1,4); cov(5,5,7); }
}
else{
LL tx = 1;
for(LL i = 1;i <= x;i ++){
cov(tx,tx,4);
tx += 4;
}
for(LL i = 1;i <= y;i ++){
cov(tx,tx,5);
tx += 5;
}
}
for(LL i = 1;i <= n;i ++){
for(LL j = 1;j <= n;j ++){
if(!g[i][j]) g[i][j] = '.';
cout << g[i][j];
}
cout << endl;
}
}
int main(){
cin >> n;
init();
if(n <= 2) solve(-1,2);
if(n == 3) solve(-1,3);
if(n == 4) solve(1,0);
if(n == 5) solve(0,1);
if(n == 6) solve(-1,6);
if(n == 7) solve(-1,7);
if(n == 11) solve(-1,11);
if(n < 8 || n == 11) return 0;
for(LL i = 0;i <= 1000;i ++){
if((n - i * 4) % 5 == 0){
solve(i,(n - i * 4) / 5);
break;
}
}
return 0;
} | 0 | CPP |
q = int(input())
for _ in range(q):
c, m, x = map(int, input().split())
ms = min(c, m)
if 3 * ms <= c + m + x:
ans = ms
else:
ans = (c+m+x) // 3
print (ans)
| 9 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int N = 1e5 + 5;
void ggg() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
string s, a[N];
int n;
int main() {
ggg();
cin >> s >> n;
for (int i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
for (int i = 0; i < n; i++) {
long long int k = 0, j = 0;
while (k < s.size() && j < a[i].size()) {
if (s[k] == a[i][j])
k++, j++;
else
break;
}
if (k == s.size()) return cout << a[i] << '\n', 0;
}
cout << s << '\n';
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, k, a, b, h;
int xx[10005], yy[10005], aa[10005], bb[10005];
inline int read() {
char c = getchar();
int x = 0;
while (c < '0' || c > '9') c = getchar();
while (c >= '0' && c <= '9') x = (x << 3) + (x << 1) + c - 48, c = getchar();
return x;
}
int main() {
n = read();
h = read();
a = read();
b = read();
k = read();
for (register int i = 1; i <= k; i++) {
xx[i] = read();
yy[i] = read();
aa[i] = read();
bb[i] = read();
long long ans = 0;
ans = abs(xx[i] - aa[i]);
if (xx[i] == aa[i]) {
cout << abs(yy[i] - bb[i]) << endl;
continue;
}
if (yy[i] > b)
ans += yy[i] - b;
else if (yy[i] < a)
ans += a - yy[i];
if (yy[i] >= a && yy[i] <= b)
ans += abs(yy[i] - bb[i]);
else if (yy[i] > b)
ans += abs(b - bb[i]);
else if (yy[i] < a)
ans += abs(a - bb[i]);
cout << ans << endl;
}
return 0;
}
| 7 | CPP |
x = input()
x = x.lower()
x = x.replace('a','')
x = x.replace('e','')
x = x.replace('i','')
x = x.replace('o','')
x = x.replace('u','')
x = x.replace('y','')
final_string = ""
i = 0
length = len(x)
while length!=0:
temp = "." + x[i]
final_string = final_string + temp
i+=1
length-=1
print (final_string) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int a[105][105][4], s[100000];
int main() {
int w, h, n, x1, y1, x2, y2, cnt = 0;
cin >> w >> h >> n;
for (int i = 0; i <= w; i++) {
a[i][0][1] = 1, a[i][h][1] = 1;
a[i][0][3] = 1, a[i][h][3] = 1;
}
for (int j = 0; j <= h; j++) {
a[0][j][0] = 1, a[w][j][0] = 1;
a[0][j][2] = 1, a[w][j][2] = 1;
}
for (int i = 1; i <= n; i++) {
cin >> x1 >> y1 >> x2 >> y2;
if (x1 == x2) {
if (y1 > y2) swap(y1, y2);
a[x1][y1][0] = 1;
a[x2][y2][2] = 1;
for (int j = y1 + 1; j < y2; j++) {
a[x1][j][0] = 1;
a[x1][j][2] = 1;
}
}
if (y1 == y2) {
if (x1 > x2) swap(x1, x2);
a[x1][y1][1] = 1;
a[x2][y2][3] = 1;
for (int j = x1 + 1; j < x2; j++) {
a[j][y1][1] = 1;
a[j][y2][3] = 1;
}
}
}
for (int i = 0; i <= w; i++)
for (int j = 0; j <= h; j++)
if (a[i][j][0] + a[i][j][1] == 2) {
int f = 0;
for (int k = i + 1; k <= w; k++) {
for (int l = j + 1; l <= h; l++) {
if (a[k][l][2] == 0 && a[k][l][3] == 1) break;
if (a[k][l][2] + a[k][l][3] == 2) {
s[++cnt] = (k - i) * (l - j);
f = 1;
break;
}
}
if (f) break;
}
}
sort(s + 1, s + cnt + 1);
for (int i = 1; i <= cnt; i++) cout << s[i] << " ";
return 0;
}
| 10 | CPP |
n = int(input())
test = 2
out = 1
while test * test <= n:
p = 0
while n % test == 0:
n //= test
p += 1
if p >= 1:
out = test
break
test += 1
if out == 1 and n > 1:
print(n)
elif out > 1 and n == 1:
print(out)
else:
print(1)
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e6 + 9;
set<int> ist;
map<string, int> msi;
map<string, string> mss;
map<int, string> mis;
map<int, int> mii;
pair<int, int> pii;
vector<int> v;
vector<pair<int, int> > vv;
int cc[] = {1, -1, 0, 0};
int rr[] = {0, 0, 1, -1};
void BIRTH_MONTH() {
int t;
int n;
cin >> n;
int ahm[n];
set<int> st;
int mn = 1000000;
int ans = 0;
for (int i = 0; i < n; i++) {
cin >> ahm[i];
if (ahm[i] < mn) {
mn = ahm[i];
ans = i + 1;
}
st.insert(ahm[i]);
}
if (st.size() == 1) {
if (n > 2) {
cout << 1 << endl;
cout << ans << endl;
} else {
cout << -1 << endl;
}
} else {
cout << 1 << endl;
cout << ans << endl;
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
BIRTH_MONTH();
return 0;
}
| 7 | CPP |
#include <iostream>
#include <string>
using namespace std;
int main(void){
string res;
int n,cnt=0,cntH=0,point=0;
cin >> n;
for( int i = 0 ; i < n ;){
cin >> res;
if( res == "OUT" ){
cnt++;
if( cnt == 3 ){
i++;
cnt = 0;
cout << point << endl;
point = 0;
cntH = 0;
}
}
else if( res == "HIT" ){
cntH++;
if( cntH == 4 ){
point++; cntH--;
}
}
else{
point += cntH+1;
cntH = 0;
}
}
return 0;
} | 0 | CPP |
D={'A':0,'B':0,'C':0}
lt=[]
for i in range(3):
str=input()
if str[1]=='>':
D[str[0]]+=1
else:
D[str[2]]+=1
lt.append(str)
win=True
for i in lt:
if i[1]=='>':
if D[i[0]]<=D[i[2]]:
win=False
else:
if D[i[0]]>=D[i[2]]:
win=False
if not win:
print("Impossible")
else:
lt=list(D.values())
lt.sort()
finalPrint = ""
for i in lt:
for j in D.keys():
if D[j] == i:
finalPrint+=j
break
print(finalPrint)
| 8 | PYTHON3 |
#include <bits/stdc++.h>
int d[1111];
int s[1111];
int main() {
int m, k;
int ans;
int temp;
while (scanf("%d %d", &m, &k) == 2) {
for (int i = 0; i < m; i++) scanf("%d", &d[i]);
for (int i = 0; i < m; i++) scanf("%d", &s[i]);
ans = 0;
temp = 0;
int max = -1;
for (int i = 0; i < m; i++) {
if (max < s[i]) max = s[i];
temp += s[i];
temp -= d[i];
ans += d[i];
if (temp < 0) {
int dd = -1 * temp / max;
temp += dd * max;
if (temp < 0) {
temp += max;
dd++;
}
ans += dd * k;
}
}
printf("%d\n", ans);
}
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, k, a[1010], f[1000010];
int main() {
scanf("%d%d", &n, &k);
int m = 1000000;
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
sort(a + 1, a + n + 1);
for (int i = 2; i <= n; i++) {
a[i] -= a[1];
}
for (int i = 1; i <= m; i++) {
f[i] = 1e9;
}
for (int i = 0; i + k * a[1] < m; i++) {
if (f[i] >= k) {
continue;
}
for (int j = 2; j <= n; j++) {
if (i + a[j] <= m) {
f[i + a[j]] = min(f[i + a[j]], f[i] + 1);
}
}
}
for (int i = 0; i + k * a[1] <= m; i++) {
if (f[i] <= k) {
printf("%d ", i + k * a[1]);
}
}
return 0;
}
| 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
using DO = long double;
using LL = long long;
const DO pi = acosl(-1);
const DO eps = 1e-15;
const DO EPS = 1e-7;
int sgn(const DO& a) { return a < -eps ? -1 : a > eps; }
int SGN(const DO& a) { return a < -EPS ? -1 : a > EPS; }
struct point {
DO x, y;
point(DO x = 0, DO y = 0) : x(x), y(y) {}
point operator+(const point& a) const { return {x + a.x, y + a.y}; }
point operator-(const point& a) const { return {x - a.x, y - a.y}; }
LL operator&(const point& a) const {
return (LL)x * (LL)a.y - (LL)y * (LL)a.x;
}
point operator*(const DO& a) const { return {x * a, y * a}; }
DO operator^(const point& a) const { return x * a.y - y * a.x; }
void eat() { cin >> x >> y; }
};
point get(const DO& alp) { return point(cosl(alp), sinl(alp)); }
const int N = 1e4 + 10;
int n;
DO area;
LL dp[N * 4];
point p[N * 4], a;
int id(const point& b) {
if (SGN(p[0] - a ^ b) > 0) return 0;
if (SGN(p[0] - a ^ b) == 0) {
if (SGN(p[1] - a ^ b) > 0)
return 1;
else
return n - 1;
}
int st = 0, ed = n, i;
while (true) {
i = st + ed >> 1;
int sg = SGN(p[i] - a ^ b);
if (sg > 0) return i;
if (sg == 0) {
if (SGN(p[i - 1] - a ^ b) > 0)
return i - 1;
else
return (i + 1) % n;
}
if (SGN(p[0] - a ^ p[i] - a) > 0)
st = i;
else
ed = i;
}
}
int get(int L, int R, const point& b) {
if (R < L) R += n;
while (L + 1 < R) {
int md = L + R >> 1;
if (SGN(p[md] - a ^ b) > 0)
L = md;
else
R = md;
}
return L % n;
}
point inter(const point& a, const point& b, const point& c, const point& d) {
return a + b * ((c - a ^ d) / (b ^ d));
}
LL seg(int L, int R) {
while (L > R) R += n;
return dp[R] - dp[L] + (p[R] & p[L]);
}
DO calc(const DO& alp) {
point b = get(alp), c;
c = b * -1;
int L, R;
do {
L = rand() % n;
} while (SGN(b ^ p[L] - a) >= 0);
do {
R = rand() % n;
} while (SGN(b ^ p[R] - a) <= 0);
int j = get(L, R, b);
int i = get(R, L, c);
point F = inter(a, c, p[i], p[i + 1] - p[i]);
point G = inter(a, b, p[j], p[j + 1] - p[j]);
return fabsl(G - F ^ p[j] - F) + fabsl(p[j] - F ^ p[i + 1] - F) +
seg((i + 1) % n, j);
}
DO solve() {
a.eat();
DO st = 0, ed = pi, md;
DO sub = calc(st);
int t = SGN((area - sub) / area);
if (!t) return 0;
int step = 50;
while (step--) {
md = (st + ed) / 2;
sub = calc(md);
int f = SGN((area - sub) / area);
if (!f) return md;
if (f == t)
st = md;
else
ed = md;
}
return st;
}
int main() {
srand(time(0));
int q;
scanf("%d %d", &n, &q);
for (int i = 0; i < n; i++)
p[i].eat(), p[n + i] = p[n + n + i] = p[n + n + n + i] = p[i];
reverse(p, p + n * 4);
for (int i = 1; i < n * 4; i++) dp[i] = dp[i - 1] + (p[i - 1] & p[i]);
area = dp[n];
area /= 2;
cout << fixed << setprecision(12);
while (q--) cout << solve() << endl;
return 0;
}
| 13 | CPP |
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const int MAXN = 200005;
int n, T, a[MAXN], m, p[MAXN];
double c;
long long sum[MAXN];
void solve() {
for (int i = 1; i <= n; i++) {
sum[i] = a[i] + sum[i - 1];
}
double approx = 0;
double qt = 1. / T;
double qc = 1. / c;
int ptr = 0;
for (int t = 1; t <= n; t++) {
approx = (approx + a[t] * qt) * qc;
if (ptr < m && t == p[ptr]) {
double real = (sum[t] - sum[t - T]) * qt;
double error = fabs(real - approx) / real;
printf("%.8f %.8f %.8f\n", real, approx, error);
ptr++;
}
}
}
int main() {
while (scanf("%d %d %lf", &n, &T, &c) == 3) {
for (int i = 1; i <= n; i++) {
scanf("%d", a + i);
}
scanf("%d", &m);
for (int i = 0; i < m; i++) {
scanf("%d", p + i);
}
solve();
}
}
| 8 | CPP |
a = input()
b = len(set(map(str, (a[1:-1]).split(", "))))
if len(a) == 2:
print('0')
else:
print(b) | 7 | PYTHON3 |
#include<iostream>
using namespace std;
int s[5] = { 0,6000,4000,3000,2000 };
int a, b;
int main() {
for (int i = 0; i < 4; i++) {
cin >> a >> b;
cout << s[a] * b << endl;
}
} | 0 | CPP |
#include <bits/stdc++.h>
#pragma GCC optimize("-O3")
using namespace std;
long long MOD = 1e9 + 7;
long long exp(long long n, long long e) {
if (e == 0) return 1;
long long temp = exp((n * n) % MOD, e / 2);
return e % 2 == 0 ? temp : (temp * n) % MOD;
}
int cnt = 0;
long long n, d, k;
void extend(int n, int N, vector<vector<long long> > &adj, int depth,
int branch) {
if (depth == 0) return;
for (int i = 1; i <= branch; i++) {
if (cnt >= N) return;
cnt++;
adj[n].push_back(cnt);
extend(cnt, N, adj, depth - 1, k - 1);
}
}
void solve() {
cin >> n >> d >> k;
if (k == 1) {
if (n > 2) {
cout << "NO" << endl;
} else if (n == 2) {
if (d == 1) {
cout << "YES" << endl;
cout << 1 << " " << 2 << endl;
} else {
cout << "NO" << endl;
}
} else if (n == 1) {
if (d == 0)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
return;
}
if (d >= n) {
cout << "NO" << endl;
return;
}
vector<vector<long long> > adj(n + 1);
for (int i = 2; i <= d + 1; i++) adj[i].push_back(i - 1);
cnt = d + 1;
int N = n;
int mid = (d + 1) / 2;
for (int i = 2; i <= mid; i++) {
extend(i, N, adj, i - 1, k - 2);
}
for (int i = mid + 1; i <= d; i++) {
extend(i, N, adj, d + 1 - i, k - 2);
}
if (cnt == N) {
cout << "YES" << endl;
for (int i = 1; i <= n; i++) {
for (int j = 0; j < adj[i].size(); j++)
cout << i << " " << adj[i][j] << endl;
}
} else {
cout << "NO" << endl;
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t = 1;
while (t--) {
solve();
}
return 0;
}
| 11 | CPP |
N,M=map(int, input().split())
inlist=[list(map(int, input().split())) for _ in range(N)]
res=0
for i in [1, -1]:
for j in [1, -1]:
for k in [1, -1]:
res = max(res, sum(list(reversed(sorted(map(lambda x: i*x[0] + j*x[1] + k*x[2], inlist))))[:M]))
print(res)
| 0 | PYTHON3 |
#include<cstdio>
#include<iostream>
#include<vector>
#include<complex>
#include<algorithm>
#include<cmath>
using namespace std;
#define reps(i,f,n) for(int i=f;i<int(n);i++)
#define rep(i,n) reps(i,0,n)
typedef complex<double> Point;
const double EPS = 0.000001;
int main(){
A:;
int n;
cin>>n;
if(n==0)return 0;
vector<Point> point;
rep(i,n){
double a,b;
cin>>a>>b;
point.push_back(Point(a,b));
}
int ans = 1;
rep(i,n){
rep(j,n){
if(i==j)continue;
Point p1 = point[j];
Point p0 = point[i];
Point diff = p1-p0;
Point d2 = diff/Point(2,0);
double dlen = abs(d2);
if(dlen>1.0)continue;
double clen = sqrt(1-dlen*dlen);
Point e = d2*Point(0,1);
e = e/Point(abs(e),0)*Point(clen,0);
Point t = p0 + d2 + e;
int count = 0;
rep(k,n){
if(abs(t-point[k])<=1.0+EPS)count++;
}
ans = max(ans,count);
}
}
printf("%d\n",ans);
goto A;
}
/*
3
6.47634 7.69628
5.16828 4.79915
6.69533 6.20378
2
0 0
0.8 0
2
0 0
0.5 0.5
2
0 0
0 2
6
7.15296 4.08328
6.50827 2.69466
5.91219 3.86661
5.29853 4.16097
6.10838 3.46039
6.34060 2.41599
*/ | 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, m, id, ans;
int main() {
char x;
string s;
s = 'a' + s;
s += 'a';
cin >> n >> m >> s;
for (int i = 0; i < s.size(); i++)
if (s[i] == '.' && s[i + 1] == '.') ans++;
while (m--) {
cin >> id >> x;
if (s[id - 1] != '.') {
if (x == '.') {
if (s[id - 2] == '.') ans++;
if (s[id] == '.') ans++;
}
} else {
if (x != '.') {
if (s[id - 2] == '.') ans--;
if (s[id] == '.') ans--;
}
}
s[id - 1] = x;
cout << ans << endl;
}
}
| 9 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
string a, b;
int n;
cin >> n >> a;
for (int j = 1; j < n; j++) {
cin >> b;
for (int i = 0; i < a.size(); i++) {
if (a[i] == '?') {
a[i] = b[i];
}
if (a[i] == '.') {
continue;
} else {
if (a[i] != b[i] && b[i] != '?') {
a[i] = '.';
}
}
}
}
for (int i = 0; i < a.size(); i++) {
if (a[i] == '.') {
cout << '?';
} else {
if (a[i] == '?') {
cout << 'a';
} else {
cout << a[i];
}
}
}
cout << endl;
return 0;
}
| 9 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int x1, x2, y1, y2;
scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
int n, ans = 0;
scanf("%d", &n);
while (n--) {
int a, b, c;
scanf("%d%d%d", &a, &b, &c);
long long p1 = 0, p2 = 0;
p1 = 1ll * (1ll * a * x1 + 1ll * b * y1 + 1ll * c);
p2 = 1ll * (1ll * a * x2 + 1ll * b * y2 + 1ll * c);
if ((p1 > 0 && p2 < 0) || (p1 < 0 && p2 > 0)) ans++;
}
printf("%d\n", ans);
return 0;
}
| 7 | CPP |
def main():
t = int(input())
for _ in range(t):
n = int(input())
if (n % 4) == 0:
print("YES")
init = 2
a = [0] * n
for i in range(0, n // 2, 2):
a[i] = init
a[i + 1] = init + 2
rev_index = (n - i) - 1
a[rev_index] = init - 1
a[rev_index - 1] = init + 3
init += 6
print(*a)
else:
print("NO")
if __name__ == '__main__':
main()
| 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long double n, m, a[5005], b[5005], min = 1000000;
cin >> n >> m;
for (int i = 0; i < n; ++i) {
cin >> a[i] >> b[i];
long double f = a[i] / b[i];
if (f < min) {
min = f;
}
}
long double s = min * m;
cout << fixed << setprecision(8) << s << endl;
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main()
{
int n,m;
cin>>n>>m;
if (n==1 && m==0)
{
cout<<0;
return 0;
}
vector<int>a(n,-1);
while(m--)
{
int s,c;
cin>>s>>c;s--;
if (a[s]!=-1 && a[s]!=c || (s==0 && c==0 && n!=1))
{
cout<<-1;
return 0;
}
a[s]=c;
}
if (a[0]==-1)
a[0]=1;
for (int i=0;i<n;i++)
if (a[i]!=-1)
cout<<a[i];
else
cout<<0;
return 0;
} | 0 | CPP |
def f():
n = int(input())
arr = list(map(int, input().split(' ')))
arr.sort()
#print(arr)
# runs in O(n), O(1) space
def comp(arr, c):
ans = 0
for i in range(len(arr)):
ans += abs(arr[i] - c**i)
return ans
# try to O(logn) this part
if comp(arr,1) <= comp(arr,2):
print(comp(arr,1))
#print('early end')
return
rbound = 1
while rbound**(n-1) < arr[-1]:
rbound += 1
lo, hi = 1, rbound
#print(f'hi:{hi}')
while lo <= hi:
mid = (lo + hi)//2
l, m, r = comp(arr,mid-1), comp(arr,mid), comp(arr,mid+1)
#print(l, m, r, mid, arr)
# claim: answer should always end early
if l > m < r or l == m or r == m:
print(m)
#print('end')
return
elif l > m > r:
lo = mid+1
elif l < m < r:
hi = mid-1
#print('bad end case')
f()
'''
3
1 3 2
3
1000000000 1000000000 1000000000
7
1 3 4 8 16 33 65
3 2 4
(2)
3 2 5
(3)
6 2 4
(5)
(3)
10 2 100
(1)
sort and then reduce?
''' | 8 | PYTHON3 |
n = int(input())
b = int(input())
i,w=0,-1
while True:
q = n**i
if q>b:break
elif q==b:w =i;break
i+=1
if w>=1:print("YES");print(w-1)
else:print("NO") | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100000;
int kk[N], bb[N], ii[N];
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int main() {
int n;
cin >> n;
int cnt = 0;
while (n--) {
int k, b;
cin >> k >> b;
if (k == 0) continue;
int d = gcd(k, b);
k /= d, b /= d;
kk[cnt] = k, bb[cnt] = b, ii[cnt] = cnt, cnt++;
}
if (cnt == 0) {
cout << "0\n";
return 0;
}
n = cnt;
sort(ii, ii + n, [](int i, int j) {
return kk[i] < kk[j] || kk[i] == kk[j] && bb[i] < bb[j];
});
for (int i = 1; i < n; i++)
if (kk[ii[i - 1]] == kk[ii[i]] && bb[ii[i - 1]] == bb[ii[i]]) cnt--;
cout << cnt << '\n';
return 0;
}
| 10 | CPP |
#include <iostream>
using namespace std;
int main(){
int T[5];
for(int i = 0; i < 5; ++i) cin >> T[i];
int N = 5, r = 0, ans = 0;
for(int i = 0; i < N; ++i){
ans += (T[i]+9)/10*10;
r = max(r,((10-T[i]%10)%10+10)%10);
}
ans -= r;
cout << ans << endl;
}
| 0 | CPP |
for i in range(int(input())):
x,y,n=map(int,input().split())
theta=(n-y)//x
k=theta*x+y
print(k)
| 7 | PYTHON3 |
n=int(input())
students=list(map(int,input().split()))
students.insert(0,0)
teams=list()
while True:
if 1 not in students or 2 not in students or 3 not in students:
break
else:
x=students.index(1)
students.pop(x)
students.insert(x,0)
y=students.index(2)
students.pop(y)
students.insert(y,0)
z=students.index(3)
students.pop(z)
students.insert(z,0)
teams.append([x,y,z])
print(len(teams))
for i in range(len(teams)):
print(teams[i][0],teams[i][1],teams[i][2])
| 7 | PYTHON3 |
from collections import deque
n, k = map(int, input().split())
l = 0
ids = list(map(int, input().split()))
q = deque()
val = set()
for i in ids:
if not (i in val):
l += 1
val.add(i)
q.appendleft(i)
if len(q) > k:
l -= 1
t = q.pop()
val.discard(t)
print(l)
print(*q)
| 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
double mx[100005], mn[100005], ans1[100005], ans2[100005];
void calc(double a, double b, double c, double &x, double &y) {
x = (-b - sqrt(fabs(b * b - 4 * a * c))) / (2 * a);
y = (-b + sqrt(fabs(b * b - 4 * a * c))) / (2 * a);
if (x > y) swap(x, y);
}
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%lf", &mx[i]);
for (int i = 1; i <= n; i++) mx[i] += mx[i - 1];
for (int i = 1; i <= n; i++) scanf("%lf", &mn[i]);
for (int i = 1; i <= n; i++) mn[i] += mn[i - 1];
for (int i = 1; i <= n; i++)
calc(1.0, -(mx[i] + mn[i]), mx[i], ans1[i], ans2[i]);
for (int i = 1; i <= n; i++) printf("%.8lf ", ans1[i] - ans1[i - 1]);
puts("");
for (int i = 1; i <= n; i++) printf("%.8lf ", ans2[i] - ans2[i - 1]);
puts("");
return 0;
}
| 10 | CPP |
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,a;
cin>>n>>a;
n%=500;
cout<<((n>a)?"No":"Yes")<<endl;
} | 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n;
string s;
int main() {
int t;
cin >> t;
while (t--) {
cin >> n >> s;
bool ok = 0;
string a, b;
for (int i = 0; i < n; i++) {
if (s[i] == '0') {
a += '0';
b += '0';
} else if (s[i] == '1') {
if (!ok) {
a += '0';
b += '1';
ok = 1;
} else {
a += '1';
b += '0';
}
} else {
if (!ok) {
a += '1';
b += '1';
} else {
a += '2';
b += '0';
}
}
}
cout << a << endl << b << endl;
}
return 0;
}
| 9 | CPP |
#include <bits/stdc++.h>
using namespace std;
const long long maxn = 3e5 + 10;
long long n, m, a[maxn], d[1000010];
struct seg_tree {
struct nodes {
long long l, r, sum, max_num;
} node[maxn << 2];
void up(long long now) {
return (
void)(node[now].sum = node[(now << 1)].sum + node[(now << 1 | 1)].sum,
node[now].max_num =
max(node[(now << 1)].max_num, node[(now << 1 | 1)].max_num));
}
void build(long long l, long long r, long long now) {
node[now].l = l, node[now].r = r;
if (l == r) return (void)(node[now].sum = a[l], node[now].max_num = a[l]);
build(l, ((l + r) >> 1), (now << 1)),
build(((l + r) >> 1) + 1, r, (now << 1 | 1));
return up(now);
}
void chenge(long long l, long long r, long long now) {
if (r < node[now].l or node[now].r < l or node[now].max_num <= 2) return;
if (node[now].l == node[now].r)
return (void)(node[now].max_num = node[now].sum = d[node[now].sum]);
chenge(l, r, (now << 1)), chenge(l, r, (now << 1 | 1));
return up(now);
}
void quary(long long l, long long r, long long now, long long &ans) {
if (r < node[now].l or node[now].r < l) return;
if (l <= node[now].l and node[now].r <= r)
return (void)(ans += node[now].sum);
quary(l, r, (now << 1), ans), quary(l, r, (now << 1 | 1), ans);
return up(now);
}
} tree;
signed main() {
for (long long i = 1; i <= 1000000; i++) {
for (long long j = i; j <= 1000000; j += i) {
d[j]++;
}
}
scanf("%lld%lld", &n, &m);
for (long long i = 1; i <= n; i++) scanf("%lld", &a[i]);
tree.build(1, n, 1);
for (long long i = 1, x, y, z; i <= m; i++) {
scanf("%lld%lld%lld", &x, &y, &z);
if (x & 1)
tree.chenge(y, z, 1);
else {
long long ans = 0;
tree.quary(y, z, 1, ans);
printf("%lld\n", ans);
}
}
return 0;
}
| 12 | CPP |
n,h=[int(i) for i in input().split()]
a=[int(i) for i in input().split()]
ans=0
for i in range(len(a)):
arr = a[:i+1]
arr.sort()
#print(*arr)
ht=0
for j in range(len(arr)-1,-1,-2):
ht+=max(arr[j],arr[max(0,j-1)])
#print('ht',ht)
if(ht<=h):
ans = max(ans,i+1)
print(ans)
| 8 | PYTHON3 |
s = input()
m = chr(ord('z') + 1)
ans = []
f = 0
for i in s:
if i > m:
ans.append('Ann')
else:
ans.append('Mike')
m = min(m, i)
print('\n'.join(ans)) | 9 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
char dich(char a) {
if (a == '1')
return '0';
else
return '1';
}
int main() {
string s, ss, res;
cin >> s >> ss;
int i, j = 0;
res = s;
for (i = 0; i < s.size(); i++) {
if (s[i] != ss[i]) j++;
}
if (j % 2 != 0)
cout << "impossible";
else {
j = j / 2;
for (i = 0; i < s.size(); i++) {
if (s[i] != ss[i]) {
res[i] = dich(s[i]);
j--;
if (j == 0) break;
}
}
cout << res << endl;
}
}
| 8 | CPP |
for I in range(int(input())):
n = int(input())
s = input()
one = -1
zero = -1
for i in range(n):
if s[i]=='1' and one==-1:
one=i
if s[i]=='0':
zero=i
if one<0 or zero<0 or one>zero:
print(s)
elif one==0 and zero==n-1:
print('0')
else:
string = s[:one]+s[zero:]
print(string)
| 8 | PYTHON3 |
#input(): n cantidad de monedas, y en la segunda linea, el valor de cada una
#output: tengo que devolver la minima cantidad de monedas para que sea mi parte mayor que la de mi hermano
n=int(input())
s=input().split()
sumTotal=0
s2=[]
for i in s:
s2.append(int(i))
for i in s2:
sumTotal+=i
x=0
sum=0
s2.sort(reverse=True)
while x < len(s2) and sum<=(sumTotal/2):
sum+=int(s2[x])
x+=1
print(x)
| 7 | PYTHON3 |
def print_round(s):
s = list(str(s))
s = [int(i) for i in s]
r = [10**i for i in range(len(s))]
r = r[::-1]
ans = [r[i]*s[i] for i in range(len(s))]
ans = [i for i in ans if i != 0]
print(len(ans))
for i in ans:
print(i,end=' ')
print()
t = int(input())
for i in range(t):
n = int(input())
print_round(n) | 7 | PYTHON3 |
#include<bits/stdc++.h>
using namespace std;
void solve(){
long long int n;
cin >> n;
int moves = 0;
while(n >= 2050*1LL){
long long int mul = 1LL;
while(n >= 2050*mul){
mul *= 10;
}
if(2050*mul > n){
mul /= 10;
}
moves++;
n -= 2050*mul;
}
if(n == 0LL){
cout << moves << endl;
}
else{
cout << "-1\n";
}
return;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while(t--){
solve();
}
} | 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x7f7f7f7f;
int dx[] = {-1, -1, -1, 0, 0, 1, 1, 1};
int dy[] = {-1, 0, 1, -1, 1, -1, 0, 1};
vector<int> arr;
int main() {
int n;
string st;
int x;
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &x);
arr.push_back(x);
}
cin >> st;
int beg = 0;
int flag = 0;
for (int i = 0; i < st.size(); i++) {
if (st[i] == '1' && flag == 0) {
beg = i;
flag = 1;
} else if (st[i] == '0') {
if (flag) {
sort(arr.begin() + beg, arr.begin() + i + 1);
flag = 0;
beg = -1;
}
}
}
if (flag == 1) sort(arr.begin() + beg, arr.end());
bool f = 0;
for (int i = 0; i < n; i++) {
if (arr[i] != i + 1) {
f = 1;
break;
}
}
if (f == 1)
cout << "NO" << endl;
else
cout << "YES" << endl;
return 0;
}
| 9 | CPP |
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
d = 0
for i in range(n):
c= b[i]-a[i]
if c<0:
d+=-c
else:
d-=c//2
print('Yes' if d<1 else 'No')
| 0 | PYTHON3 |
k=int(input())*2
l=[0]*10
for i in range(4):
s=input()
for j in s:
if j!='.':
l[int(j)]+=1
print('NO' if max(l)>k else 'YES')
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int n;
int arr[5050], *A = &arr[1];
int memo[5005][5005][2];
int dp(int id, int rem, int f) {
if (rem == 0) return 0;
if (id >= n) return 2e9;
if (memo[id][rem][f] != -1) return memo[id][rem][f];
int org1 = A[id - 1];
int org2 = A[id + 1];
int cost = 0;
if (A[id - 1] - A[id] >= 0)
cost += A[id - 1] - A[id] + 1, A[id - 1] = A[id] - 1;
if (A[id + 1] - A[id] >= 0)
cost += A[id + 1] - A[id] + 1, A[id + 1] = A[id] - 1;
int ans = dp(id + 2, rem - 1, 1) + cost;
A[id - 1] = org1;
A[id + 1] = org2;
ans = min(ans, dp(id + 1, rem, 0));
return memo[id][rem][f] = ans;
}
int main() {
scanf("%i", &n);
for (int i = 0; i < n; i++) scanf("%i", &A[i]);
A[-1] = A[n] = -2e9;
memset(memo, -1, sizeof memo);
for (int k = 1; k <= (1 + n) / 2; k++)
printf("%i", dp(0, k, 0)), putc(' ', stdout);
putc('\n', stdout);
}
| 9 | CPP |
#include <bits/stdc++.h>
const int maxn = 100005;
using namespace std;
int n, a[maxn], b[maxn];
char s[maxn];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
scanf("%s", s + 1);
for (int i = 1; i <= n; i++) {
b[i] = s[i] - '0';
}
int ur = 1e9, ul = -1e9, dr = -1e9, dl = 1e9;
for (int i = 5; i <= n; i++) {
if (b[i] != b[i - 1]) {
if (b[i] == 0) {
for (int ii = 0; ii <= 4; ii++) ur = min(ur, a[i - ii] - 1);
} else {
for (int ii = 0; ii <= 4; ii++) ul = max(ul, a[i - ii] + 1);
}
}
}
for (int i = 5; i <= n; i++) {
if (b[i] == b[i - 1] && b[i - 1] == b[i - 2] && b[i - 2] == b[i - 3] &&
b[i - 3] == b[i - 4]) {
if (b[i] == 1) {
int minv = b[i];
for (int ii = 0; ii <= 4; ii++) minv = min(minv, a[i - ii]);
dr = max(dr, minv);
} else {
int maxv = b[i];
for (int ii = 0; ii <= 4; ii++) maxv = max(maxv, a[i - ii]);
dl = min(dl, maxv);
}
}
}
printf("%d %d\n", ul, ur);
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int l[n + 5], r[n + 5];
for (int i = 1; i <= n; i++) cin >> l[i] >> r[i];
int k;
cin >> k;
int ans = n;
for (int i = 1; i <= n; i++)
if (r[i] < k) ans--;
cout << ans << "\n";
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while (t--) {
double a, b;
cin >> a >> b;
double total = 2.0 * a * b, fav = a * b;
if (b == 0) {
cout << 1.0 << '\n';
continue;
} else if (a == 0) {
cout << 0.5 << '\n';
continue;
}
double inter, temp;
inter = 4.0 * b;
if (inter < a) {
temp = (0.5 * (a * (a / (4.0)))) -
(0.5 * (a - (4.0) * b) * ((a / (4.0)) - b));
} else {
temp = (0.5 * a * (a / (4.0)));
}
fav += temp;
double ans;
ans = fav / total;
cout.precision(12);
cout << ans << '\n';
}
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
int n = 0;
cin >> n;
vector<int> a(n);
vector<int> b(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
for (int i = 0; i < n; ++i) {
cin >> b[i];
}
int cur = 0;
for (int i = 0; i < n; ++i) {
if (b[i] == a[cur]) ++cur;
}
cout << n - cur << endl;
return 0;
}
| 7 | CPP |
for i in range(int(input())):
n = int(input())
ans = 0
for j in range(n // 2):
ans += (n - 2 * j + n - 2 * j + n - 2 * j - 2 + n - 2 * j - 2) * (n // 2 - j)
print(ans) | 9 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
string n;
cin >> n;
int dig = n.length();
int arr[9][dig];
for (int i = 0; i <= 8; i++)
for (int j = 0; j <= dig - 1; j++) arr[i][j] = 0;
for (int i = 0; i <= dig - 1; i++) {
int k = n.at(i) - '0';
for (int j = 0; j <= k - 1; j++) {
arr[j][i] = 1;
}
}
vector<long long> quas;
for (int i = 0; i <= 8; i++) {
long long num = 0;
for (int j = 0; j <= dig - 1; j++) {
num *= 10;
num += arr[i][j];
}
if (num != 0) quas.push_back(num);
}
cout << quas.size() << endl;
for (int i = 0; i <= quas.size() - 1; i++) {
cout << quas[i] << " ";
}
cout << endl;
return 0;
}
| 8 | CPP |
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<bitset>
using namespace std;
typedef long long LL;
const int N=1<<18;
int gi() {
int w=0;bool q=1;char c=getchar();
while ((c<'0'||c>'9') && c!='-') c=getchar();
if (c=='-') q=0,c=getchar();
while (c>='0'&&c <= '9') w=w*10+c-'0',c=getchar();
return q? w:-w;
}
int L[N],R[N],x[N];
int p[18][N],q[N];
int ans[N];
inline void umin(int &x,int y) { y<x?x=y:0; }
inline void umax(int &x,int y) { x<y?x=y:0; }
int main()
{
int n=gi()-1,v=gi(),i,j,k=v,m=0,u[20]={},s;
while (k) u[m++]=k>>=1;
for (i=0;i<=n;i++) x[i]=gi();
for (i=n;i;i--) x[i]-=x[i-1];
for (i=0;i<m;i++) {
p[i][n+1]=n+1;
for (j=n;j;j--)
p[i][j]=x[j]<=u[i]?p[i][j+1]:j;
}
for (s=0;s<1<<m;s++)
for (i=0;i<m;i++)
if (!(s>>i&1))
umax(L[s|1<<i],p[i][L[s]+1]);
for (i=0;i<m;i++)
for (j=1;j<=n;j++)
p[i][j]=x[j]<=u[i]?p[i][j-1]:j;
for (s=0;s<1<<m;s++) R[s]=n+1;
for (s=0;s<1<<m;s++)
for (i=0;i<m;i++)
if (!(s>>i&1))
umin(R[s|1<<i],R[s|1<<i]?p[i][R[s]-1]:0);
memset(ans,0x3f,sizeof(ans));
for (s=0;s<1<<m;s++)
umin(ans[L[s]],R[((1<<m)-1)^s]);
for (i=1;i<=n;i++) umin(ans[i-1],ans[i]);
for (i=n,q[n+1]=n+1;i;i--)
q[i]=x[i]>v?i:q[i+1];
for (i=0;i<=n;i++) {
if (!i||x[i]>v) k=i;
puts(ans[k]<=q[i+1]?"Possible":"Impossible");
}
return 0;
}
| 0 | CPP |
import sys
def solve(n, m, x):
if(n == m):
return x[n-1]
pares = 0
while((pares*2)+(m-pares) < n):
pares += 1
maxi = x[n-1]
j = pares*2 - 1
for i in range(pares):
maxi = max(maxi, x[i]+x[j-i])
return maxi
x = [int(x) for x in input().split()]
n = x[0]
m = x[1]
x = [int(x) for x in input().split()]
print(solve(n, m, x)) | 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int M = 6e6+10;
const int N = 3e5+10;
struct AA{
int val,id;
const bool operator < (const AA &b) const {
return val<b.val;
}
const bool operator == (const AA &b) const {
return (val==b.val);
}
};
vector <AA> a;
int mp[M][2];
int main(){
int n;
cin>>n;
a.push_back({0,0});
for (int i=1;i<=n;i++){
int p;
cin>>p;
a.push_back({p,i});
}
sort(a.begin(),a.end());
n=a.size()-1;
for (int i=1;i<n;i++){
for (int j=i+1;j<=n;j++){
int sum=a[i].val+a[j].val;
if (mp[sum][0]==0){
mp[sum][0]=a[i].id; mp[sum][1]=a[j].id;
}
else if (mp[sum][0]!=a[i].id && mp[sum][1]!=a[j].id && mp[sum][1]!=a[i].id && mp[sum][0]!=a[j].id) {
cout<<"YES\n"<<mp[sum][0]<<" "<<mp[sum][1]<<" "<<a[i].id<<" "<<a[j].id<<"\n";
return 0;
}
}
}
cout<<"NO\n";
return 0;
} | 7 | CPP |
n = int(input(""))
list = []
for i in range(n):
list.append(int(input("")))
for i in range(n):
if ((list[i]>3) and ((list[i])%4==0)):
print("YES")
else:
print("NO")
| 7 | PYTHON3 |
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
wynik = 0
lista = []
for x in range(n):
wynik = wynik + b[x]
roznica = a[x] - b[x]
if roznica < 0:
wynik = wynik + roznica
k = k - 1
else:
lista.append(roznica)
lista.sort()
for x in range(len(lista)):
if k > 0:
wynik = wynik + lista[x]
k = k - 1
print(wynik) | 9 | PYTHON3 |
n,b,d=map(int,input().split())
Orng=list(map(int,input().split()))
size,times=0,0
for i in Orng:
if i<=b :
size+=i
if size>d:
times+=1
size=0
print(times) | 7 | PYTHON3 |
#include<bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
using namespace std;
int main(){
int n,k;
cin>>n>>k;
cout<<(n-1)/(k-1)+((n-1)%(k-1)+k-2)/(k-1)<<endl;
}
| 0 | CPP |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.