solution
stringlengths 10
983k
| difficulty
int64 0
25
| language
stringclasses 2
values |
---|---|---|
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int s = 0, w = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') w = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
s = (s << 3) + (s << 1) + (ch ^ 48);
ch = getchar();
}
return s * w;
}
const long long mod = 998244353;
const int N = 1001000;
int n, m;
int a[N];
vector<int> Q[N];
long long result[N];
int id[N];
int now;
int pos(int x) {
if (x == now) return 1;
if (x < now) return x + 1;
return x;
}
int main() {
n = read();
m = read();
for (int i = 1; i <= n; i++) id[i] = i;
long long s = 0;
for (int i = 1; i <= m; i++) {
a[i] = read();
Q[a[i]].push_back(i);
if (i != 1) s += abs(a[i] - a[i - 1]);
}
result[1] = s;
for (int i = 2; i <= n; i++) {
for (int j = 0; j < Q[i].size(); j++) {
int x = Q[i][j];
if (x > 1) s -= abs(pos(a[x]) - pos(a[x - 1]));
if (x < m) s -= abs(pos(a[x + 1]) - pos(a[x]));
}
for (int j = 0; j < Q[i - 1].size(); j++) {
int x = Q[i - 1][j];
if (x > 1) s -= abs(pos(a[x]) - pos(a[x - 1]));
if (x < m) s -= abs(pos(a[x + 1]) - pos(a[x]));
}
now = i;
for (int j = 0; j < Q[i].size(); j++) {
int x = Q[i][j];
if (x > 1) s += abs(pos(a[x]) - pos(a[x - 1]));
if (x < m) s += abs(pos(a[x + 1]) - pos(a[x]));
}
for (int j = 0; j < Q[i - 1].size(); j++) {
int x = Q[i - 1][j];
if (x > 1) s += abs(pos(a[x]) - pos(a[x - 1]));
if (x < m) s += abs(pos(a[x + 1]) - pos(a[x]));
}
result[i] = s;
}
for (int i = 1; i <= n; i++) printf("%lld ", result[i]);
printf("\n");
}
| 11 | CPP |
z = int(input())
n = 1000
a = [1] * n
a[1] = 0
i = 2
while i < n:
if a[i] != 0:
j = i + i
while j < n:
a[j] = 0
j = j + i
i += 1
b = ""
for i in range(1, n):
x1 = z // i
if z / i == x1 and a[x1] == 1:
b += str(min(i, x1))
b += str(max(i, x1))
break
print(b)
| 8 | PYTHON3 |
n, m = map(int, input().split())
l = [int(i) for i in input().split()]
m = [i for i in range(1, n+1)]
for i in l:
for j in range(i-1, n):
m[j] = i
n = i-1
print(*m) | 7 | PYTHON3 |
a = input()
b = input()
print("YES" if a[:] == b[::-1] else "NO") | 0 | PYTHON3 |
i=int(input())
w=input()
w=w.upper()
flag=1
for i in range(65,91):
if chr(i) not in w:
flag=0
break
if flag==1:
print("YES")
else:
print("NO") | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 123;
const int inf = 1e9 + 123;
const long long INF = 1e18 + 123;
const long long MAXN = 1e10 + 123;
const long long MOD = 1e9 + 7;
const long long mod = 555557;
const double pi = acos(-1.0);
vector<int> ans;
long long a, b;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> a >> b;
int m = b;
while (b != a) {
int k = b;
if (b % 10 == 1)
b /= 10;
else if (b % 2 == 0)
b /= 2;
if (k == b) cout << "NO", exit(0);
ans.push_back(b);
}
cout << "YES\n" << ans.size() + 1 << endl;
reverse(ans.begin(), ans.end());
for (int i : ans) cout << i << " ";
cout << m;
}
| 7 | CPP |
x = input().strip()
if len(x) % 2 == 1 and x.count('1') > 1:
print(len(x)//2+1)
else:
print(len(x)//2)
| 7 | PYTHON3 |
A,B,C,D,E,F = map(int,input().split())
ws = set()
for i in range(F+1):
if 100*A*i > F: break
for j in range(F+1):
if 100*A*i + 100*B*j > F: break
ws.add(100*A*i + 100*B*j)
ws.remove(0)
ss = set()
for i in range(F+1):
if C*i > F: break
for j in range(F+1):
if C*i + D*j > F: break
ss.add(C*i + D*j)
opt_w = 1
opt_s = -1
for w in ws:
for s in ss:
if w+s > F: continue
if s*100 > w*E: continue
if opt_s * (w+s) < s * (opt_w+opt_s):
opt_w,opt_s = w,s
print(opt_w+opt_s, opt_s) | 0 | PYTHON3 |
a=b=ans=cnt=-1
for i in range(int(input())):
x,y=map(int,input().split())
if x==a and y==b:
cnt+=1
else:
if ans<cnt:ans=cnt
cnt=1
a,b=x,y
print(cnt if ans<cnt else ans) | 7 | PYTHON3 |
n = int(input())
a = [int(i) - 1 for i in input().split()]
s = input().split()
ans = dict()
b = [0 for i in range(n)]
for i in range(n):
b[int(s[i]) - 1] = i
ans[i] = 0
for i in range(n):
if i >= b[a[i]]:
ans[i - b[a[i]]] += 1
else:
ans[n - b[a[i]] + i] += 1
m = 0
for i in ans.keys():
if ans[i] > ans[m]:
m = i
print(ans[m]) | 9 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long t, n, i, j, a[1000];
string s[1000];
char ch, nch;
cin >> t;
while (t--) {
cin >> n;
nch = 'y';
for (i = 0; i <= n; i++) s[i] = "";
for (i = 0; i < n; i++) {
cin >> a[i];
}
if (a[0] == 0) {
s[0] += nch;
nch = nch == 'y' ? 'z' : 'y';
s[1] += nch;
nch = nch == 'y' ? 'z' : 'y';
a[0] = 1;
} else {
for (i = 0; i < a[0]; i++) s[0] += "a";
s[1] = s[0];
}
ch = 'b';
for (i = 1; i < n; i++) {
if (a[i] == 0) {
s[i + 1] += nch;
nch = nch == 'y' ? 'z' : 'y';
a[i] = 1;
} else {
if (a[i] <= a[i - 1])
s[i + 1] = s[i].substr(0, a[i]);
else {
for (j = 0; j < a[i] - a[i - 1]; j++) s[i] += ch;
ch++;
if (ch > 'x') ch = 'a';
s[i + 1] = s[i];
}
}
}
for (i = 0; i <= n; i++) cout << s[i] << "\n";
}
}
| 7 | CPP |
#include <bits/stdc++.h>
int rever[10] = {8, -1, -1, 3, 6, 9, 4, 7, 0, 5};
int main() {
char in[15] = {};
scanf("%s", in);
int p = strlen(in);
int t = p / 2;
for (int i = 0; i <= t; i++) {
if (rever[in[i] - '0'] != in[p - i - 1] - '0') {
printf("No");
return 0;
}
}
printf("Yes");
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, m, k, d[110];
char s[110];
int main() {
scanf("%d%d%d\n", &n, &m, &k);
bool gen = false, cheb = false;
for (int i = 0; i < (n); i++) {
int x = -1, y;
d[i] = -1;
gets(s);
bool ok = false;
for (int j = 0; j < (m); j++)
if (s[j] != '-') {
if (x == -1)
x = j;
else if (s[x] != s[j])
d[i] = j - x - 1;
} else
ok = true;
if (d[i] == -1) {
if (x == -1 || !ok)
d[i] = 0;
else {
if (s[x] == 'G')
gen = true;
else
cheb = true;
}
}
}
if (gen && cheb) {
puts("Draw");
return 0;
}
if (gen) {
puts("First");
return 0;
}
if (cheb) {
puts("Second");
return 0;
}
bool ok = false;
for (int i = 0; i < (7); i++) {
int x = 0;
for (int j = 0; j < (n); j++) {
x += d[j] & 1;
d[j] >>= 1;
}
ok |= x % (k + 1);
}
puts(ok ? "First" : "Second");
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
struct room {
int a, b, c;
};
struct rul {
int a, b, dollars;
};
int main() {
int n, res = 0, m;
room kom[500];
rul rulon[500];
cin >> n;
for (int i = 0; i < n; i++) cin >> kom[i].a >> kom[i].b >> kom[i].c;
cin >> m;
for (int i = 0; i < m; i++)
cin >> rulon[i].a >> rulon[i].b >> rulon[i].dollars;
for (int i = 0; i < n; i++) {
int minmoney = 1000000, P = 2 * (kom[i].a + kom[i].b);
for (int j = 0; j < m; j++) {
int lol = rulon[j].a / kom[i].c;
if (lol == 0) continue;
int numpol = P % rulon[j].b == 0 ? P / rulon[j].b : P / rulon[j].b + 1;
int numrul = numpol % lol == 0 ? numpol / lol : numpol / lol + 1;
int money = numrul * rulon[j].dollars;
if (money < minmoney) minmoney = money;
}
res += minmoney;
}
cout << res;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int cnt, prime[100005];
set<int> pp[100005];
bool in_p[100005];
int l[1005], t;
int aa[100005][30];
int main() {
cnt = 0;
for (int i = 2; i <= 100000; i++) {
bool flag = true;
for (int j = 0; j < cnt && prime[j] * prime[j] <= i; j++)
if (i % prime[j] == 0) {
flag = false;
break;
}
if (flag) prime[cnt++] = i;
}
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) {
for (int j = 0; j < cnt && prime[j] <= i; j++)
if (i % prime[j] == 0) {
memcpy(aa[i], aa[i / prime[j]], sizeof(aa[i]));
bool flag = true;
for (int k = 1; k <= aa[i][0]; k++)
if (aa[i][k] == j) {
flag = false;
break;
}
if (flag) aa[i][++aa[i][0]] = j;
break;
}
}
memset(in_p, false, sizeof(in_p));
for (int i = 0; i < m; i++) {
char s[10];
int x;
scanf("%s%d", s, &x);
if (s[0] == '+') {
if (in_p[x])
printf("Already on\n");
else {
int conf = -1;
int k = x;
t = 0;
for (int k = 1; k <= aa[x][0]; k++) {
int i = aa[x][k];
l[t++] = i;
if (!pp[i].empty()) {
conf = *pp[i].begin();
break;
}
}
if (conf != -1)
printf("Conflict with %d\n", conf);
else {
for (int k = 0; k < t; k++) pp[l[k]].insert(x);
in_p[x] = true;
printf("Success\n", x);
}
}
} else {
if (!in_p[x])
printf("Already off\n");
else {
for (int k = 1; k <= aa[x][0]; k++) {
int i = aa[x][k];
pp[i].erase(x);
}
in_p[x] = false;
printf("Success\n", x);
}
}
}
return 0;
}
| 8 | CPP |
intp=list(map(int,input().split()))
a=list(map(int,input().split()))
b=[]
for i in range(len(a)):
c=[str(i+1),a[i]]
b.append(c)
i=0
while(len(b)!=1):
if(len(b)==1):
print(b[i][1])
else:
choc=intp[1]
n=b[i][1]
total=n-choc
if(total<=0):
b.pop(i)
else:
b[i][1]=total
shift=b[i]
b.pop(i)
b.append(shift)
print(b[0][0]) | 7 | PYTHON3 |
n = int(input())
for y in range(n):
dy = abs(y - n//2)
for x in range(n):
dx = abs(x - n//2)
print('*' if dx + dy > n//2 else 'D', end = '')
print()
| 7 | PYTHON3 |
//#pragma once
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <sstream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cctype>
#include <cstdlib> // srand,rand
using namespace std;
#define modd 1000000007
typedef pair<long long, long long> pl;
typedef string::const_iterator State;
class ParseError {};
#define ll long long
class UnionFind {
public:
vector <ll> par;
vector <ll> siz;
// Constructor
UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL){
for (ll i = 0; i < sz_; ++i) par[i] = i;
}
void init(ll sz_) {
par.resize(sz_);
siz.assign(sz_, 1LL); // resize だとなぜか初期化されなかった
for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
}
// Member Function
// Find
ll root(ll x) { // 根の検索
while (par[x] != x) {
x = par[x] = par[par[x]]; // x の親の親を x の親とする
}
return x;
}
// Union(Unite, Merge)
bool merge(ll x, ll y) {
x = root(x);
y = root(y);
if (x == y) return false;
// merge technique(データ構造をマージするテク.小を大にくっつける)
if (siz[x] < siz[y]) swap(x, y);
siz[x] += siz[y];
par[y] = x;
return true;
}
bool issame(ll x, ll y) { // 連結判定
return root(x) == root(y);
}
ll size(ll x) { // 素集合のサイズ
return siz[root(x)];
}
};
class SegmentTree {
private:
int n;
vector <ll> node;
public:
// 元の配列 v をセグメントツリーで表現する。
SegmentTree(vector<ll> v) {
//最下段のノード数は元配列のサイズ以上になる最小の2冪->これをnとおく。
//セグ木全体で必要なノード数は2n-1個である。
int sz = v.size();
n = 1;
while (n < sz)n *= 2;
}
};
long long N, M, K, a, b, c, d, e, H, W, L,T;
ll A[300005] = {};
ll B[300005] = {};
ll C[100][3005] = {};
bool f, ff;
string S,SS;
set <long long>sll;
pl bufpl;
vector <long long>vl[100005];
vector <long long>vll;
vector <pl>vpl;
vector <string> vs;
set<ll> llset[50];
multiset<ll> llmset;
queue<ll> ql;
struct ST
{
ll first;
ll second;
ll kaisuu;
bool operator<(const ST& another) const
{
return first < another.first;//比較
};
};
/*vector <ST> vst;
ST st[200005];
ST bufst;
bitset<5000> bits;*/
long long modinv(long long aa, long long mm) {
long long bb = mm, uu = 1, vv = 0;
while (bb) {
long long tt = aa / bb;
aa -= tt * bb; swap(aa, bb);
uu -= tt * vv; swap(uu, vv);
}
uu %= mm;
if (uu < 0) uu += mm;
return uu;
}
ll minn, maxx;
double ansa;
ll zettai(ll aa) {
if (aa < 0) {
aa *= -1;
}
return aa;
}
bool itta[300000];
int main() {
cin >> N;
for (int i = 2; i <= 100000; i++) {
for (int j = i; j <= 100000; j+=i) {
A[j]++;
}
}
c = 0;
for (int i = 1; i <=100000; i++) {
if (A[i] - 1 >= 3) {
c++;
}
B[i] = c;
}
for (int i = 0; i < N; i++) {
cin >> d;
cout << B[d] << endl;
}
//cout << fixed << setprecision(10) << ansa << endl;
return 0;
}
| 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using pi = pair<int, int>;
const int maxn = 100005;
void solve() {
priority_queue<pi> q;
int n;
cin >> n;
vi ne(n + 1), t(n + 1, 1);
for (int i = 0; i < (n + 1); ++i) ne[i] = i + 1;
for (int i = (1); i <= (n); ++i) q.push(make_pair(t[i], i));
bool ok = true;
for (int i = 0; i < (n); ++i) {
int p;
cin >> p;
if (!ok) continue;
while (q.size() && t[q.top().second] != q.top().first) q.pop();
assert(!q.empty());
if (t[p] != q.top().first) {
ok = 0;
continue;
}
if (ne[p] != n + 1 && t[ne[p]] != -1) {
t[ne[p]] += 1 + t[p];
q.push(make_pair(t[ne[p]], ne[p]));
}
t[p] = -1;
}
if (ok)
cout << "Yes\n";
else
cout << "No\n";
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int t = 1;
cin >> t;
while (t--) solve();
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
int OO = 1e9 + 10;
int n, k[3], a[3][N];
int id[N];
int pre[3][N], suf[3][N];
int suf1[N];
int main() {
for (int i = 0; i < 3; i++) cin >> k[i], n += k[i];
for (int i = 0; i < 3; i++) {
for (int j = 0; j < k[i]; j++) {
scanf("%d", &a[i][j]);
id[a[i][j]] = i;
}
}
int ans = min({n - k[0], n - k[1], n - k[2]});
for (int i = 0; i < 3; i++) {
for (int j = 1; j <= n; j++) {
pre[i][j] = pre[i][j - 1];
if (id[j] == i) pre[i][j]++;
}
for (int j = n; j >= 0; j--) {
suf[i][j] = suf[i][j + 1];
if (id[j] == i) suf[i][j]++;
}
}
for (int i = 1; i + 1 <= n; i++) {
for (int j = 0; j < 3; j++) {
for (int d = j + 1; d < 3; d++) {
ans = min(ans, n - (pre[j][i] + suf[d][i + 1]));
}
}
}
for (int i = n; i >= 0; i--) {
suf1[i] = suf[2][i] - suf[1][i];
suf1[i] = max(suf1[i], suf1[i + 1]);
}
for (int i = 1; i + 2 <= n; i++) {
ans = min(ans, n - (pre[0][i] + suf[1][i + 1] + suf1[i + 2]));
}
cout << ans << endl;
}
| 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long mp[200][200];
int main() {
memset(mp, 0, sizeof(mp));
int n, m;
int aa = 0, bb = 0;
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i++) {
scanf("%lld", &mp[i][m - 1]);
aa ^= mp[i][m - 1];
}
for (int i = 0; i < m; i++) {
scanf("%lld", &mp[n - 1][i]);
bb ^= mp[n - 1][i];
}
if (aa == bb) {
bb = mp[n - 1][m - 1];
mp[n - 1][m - 1] = 0;
aa = 0;
for (int i = 0; i < n - 1; i++) aa ^= mp[i][m - 1];
for (int i = 0; i < 30; i++) {
if (((bb ^ (1 << i)) > bb && (aa ^ (1 << i)) > aa) ||
((bb ^ (1 << i)) < bb && (aa ^ (1 << i)) < aa))
continue;
else
mp[n - 1][m - 1] += (1 << i);
}
printf("YES\n");
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++)
printf("%I64d%c", mp[i][j], " \n"[j == m - 1]);
} else
printf("NO\n");
return 0;
}
| 10 | CPP |
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
using namespace std;
void print(const vector<int>& res) {
for (int i = 0; i < res.size(); i++)
cout << (i == 0 ? "" : " ") << res[i];
cout << endl;
}
bool check(const vector<int>& res, const vector<int>& G){
for (int i = 0; i < res.size()-1; i++)
if (res[i+1] == G[res[i]]) return false;
return true;
}
int main(){
int N; cin >> N;
vector<int> G(N+1), in(N+1, 0);
set<int> av;
for (int i = 1; i <= N; i++) {
cin >> G[i];
av.insert(i);
in[G[i]]++;
}
if (N == 2) {
cout << -1 << endl;
exit(0);
}
int u = -1;
vector<int> res;
while (not av.empty()) {
auto it = av.begin();
if (u != -1 and *it == G[u]) ++it;
if (it == av.end()) --it;
u = *it;
auto it2 = av.find(G[u]);
if (it2 != av.end() and in[G[u]] == av.size()-1) u = G[u];
res.push_back(u);
av.erase(u);
in[G[u]]--;
}
int& a = res[N-1];
int& b = res[N-2];
int& c = res[N-3];
int sum = a+b+c;
c = min(a, min(b, c));
a = max(a, max(b, c));
b = sum - c - a;
do {
if (check(res, G)) {
print(res);
exit(0);
}
} while (next_permutation(res.begin(), res.end()));
}
| 0 | CPP |
A,B,K = map(int,input().split())
if A > K:
print(A-K,B)
else:
print(0,max(B-(K-A), 0)) | 0 | PYTHON3 |
n,x=[int(x) for x in input().split(' ')]
s=sum([int(x) for x in input().split(' ')])
if s==0:
print(0)
else:
z=abs(s)
ans=z//x
if z%x!=0:
ans+=1
print(ans)
| 7 | PYTHON3 |
i=int(input())
for x in range(i):
a=input()
b=len(a)
if b>10:
print(a[0],end="")
print(b-2,end="")
print(a[-1])
else:
print(a) | 7 | PYTHON3 |
def main():
v = -1 if input() == 'R' else 1
table = 'qwertyuiopasdfghjkl;zxcvbnm,./'
s = input()
t = ''.join([table[table.find(x) + v] for x in s])
print ( t )
main()
| 7 | PYTHON3 |
#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <sstream>
#include <climits>
#include <cmath>
#include <map>
#include <stack>
using namespace std;
#define M_PI 3.141592
#define toRad 2.0*M_PI/360.0
#define inin(x) int x;cin>>x;
#define all(x) x.begin(),x.end()
#define debug(x) cout<<#x<<" "<<x<<endl;
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define EPS 1e-12
#define pri_max 60000
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
/*
bool memo[pri_max] = {};
vector<int> pri;
void calc()
{
for (int i = 2; i < pri_max; i++)
{
if (memo[i] == false)
{
pri.push_back(i);
for (int l = i; l < pri_max; l += i)
{
memo[l] = true;
}
}
}
}*/
int convex_hull(vector<pdd> a)
{
vector<pdd> u, d;
sort(all(a));
for (int i = 0; i < a.size(); i++)
{
for (int l = u.size() - 1; l >= 1; l--)
{
double v1, v2;
v1 = atan2(u[l].first - u[l - 1].first, u[l].second - u[l - 1].second);
v2 = atan2(a[i].first - u[l - 1].first, a[i].second - u[l - 1].second);
if (v2 < v1)u.pop_back();
}
u.push_back(a[i]);
}
for (int i = 0; i < a.size(); i++)
{
for (int l = d.size() - 1; l >= 1; l--)
{
double v1, v2;
v1 = atan2(d[l].first - d[l - 1].first, d[l].second - d[l - 1].second);
v2 = atan2(a[i].first - d[l - 1].first, a[i].second - d[l - 1].second);
if (v2 > v1)d.pop_back();
}
d.push_back(a[i]);
}
for (int i = 0; i < u.size(); i++)
{
//cout << u[i].first << " " << u[i].second << endl;
}
return u.size()+d.size()-2;
}
int main()
{
int n;
while (cin >> n&&n)
{
vector<pdd> v;
for (int i = 0; i < n; i++)
{
double x, y;
scanf("%lf,%lf", &x, &y);
v.push_back(pdd(x, y));
}
cout << n - convex_hull(v) << endl;
}
} | 0 | CPP |
a, b, c = map(int, input().split())
for i in range(b):
if i * a % b == c:
print("YES")
exit()
print("NO") | 0 | PYTHON3 |
a,b,c,n=map(int,input().split())
d = (a-c) + (b)
e = n - d
if c>a or c>b:
print(-1)
elif e>=1:
print(e)
else:
print(-1) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int PUT = 34;
long long two[PUT];
long long three[PUT];
unordered_map<long long, int> H;
long long v[100999];
inline long long cmmdc(long long a, long long b) {
long long r;
while (r = a % b) {
a = b;
b = r;
}
return b;
}
int main() {
ios ::sync_with_stdio(false);
two[0] = 1;
three[0] = 1;
for (register int i = 1; i <= 32; ++i) {
two[i] = two[i - 1] * 2LL;
three[i] = three[i - 1] * 3LL;
}
int n;
cin >> n;
cin >> v[1];
cin >> v[2];
long long w = cmmdc(v[1], v[2]);
for (register int i = 3; i <= n; ++i) {
cin >> v[i];
w = cmmdc(w, v[i]);
}
for (register int i = 1; i <= n; ++i) {
long long x = v[i];
x /= w;
for (register int i = 30; i >= 0; --i) {
if (x % two[i] == 0) {
x /= two[i];
}
if (x % three[i] == 0) {
x /= three[i];
}
}
if (x != 1) {
cout << "No\n";
exit(0);
}
}
cout << "Yes\n";
return 0;
}
| 9 | CPP |
#include <bits/stdc++.h>
using namespace std;
int a[55];
int main() {
int i, j, k, l, r, n;
long long m;
scanf("%d", &n);
cin >> m;
long long x = 1LL << (n - 2);
l = 1;
r = n;
for (i = (1); i <= (n); i++) {
if (m > x) {
a[r] = i;
r--;
m -= x;
} else {
a[l] = i;
l++;
}
x >>= 1;
}
for (i = (1); i <= (n); i++) printf("%d%c", a[i], " \n"[i == n]);
}
| 8 | CPP |
# Enter your code here. Read input from STDIN. Print output to STDOUT# ===============================================================================================
# importing some useful libraries.
from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import ceil, floor
from copy import *
from collections import deque, defaultdict
from collections import Counter as counter # Counter(list) return a dict with {key: count}
from itertools import combinations # if a = [1,2,3] then print(list(comb(a,2))) -----> [(1, 2), (1, 3), (2, 3)]
from itertools import permutations as permutate
from bisect import bisect_left as bl
from operator import *
# If the element is already present in the list,
# the left most position where element has to be inserted is returned.
from bisect import bisect_right as br
from bisect import bisect
# If the element is already present in the list,
# the right most position where element has to be inserted is returned
# ==============================================================================================
# fast I/O region
BUFSIZE = 8192
from sys import stderr
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
def print(*args, **kwargs):
"""Prints the values to a stream, or to sys.stdout by default."""
sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
at_start = True
for x in args:
if not at_start:
file.write(sep)
file.write(str(x))
at_start = False
file.write(kwargs.pop("end", "\n"))
if kwargs.pop("flush", False):
file.flush()
if sys.version_info[0] < 3:
sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
# inp = lambda: sys.stdin.readline().rstrip("\r\n")
# ===============================================================================================
### START ITERATE RECURSION ###
from types import GeneratorType
def iterative(f, stack=[]):
def wrapped_func(*args, **kwargs):
if stack: return f(*args, **kwargs)
to = f(*args, **kwargs)
while True:
if type(to) is GeneratorType:
stack.append(to)
to = next(to)
continue
stack.pop()
if not stack: break
to = stack[-1].send(to)
return to
return wrapped_func
#### END ITERATE RECURSION ####
###########################
# Sorted list
class SortedList:
def __init__(self, iterable=[], _load=200):
"""Initialize sorted list instance."""
values = sorted(iterable)
self._len = _len = len(values)
self._load = _load
self._lists = _lists = [values[i:i + _load] for i in range(0, _len, _load)]
self._list_lens = [len(_list) for _list in _lists]
self._mins = [_list[0] for _list in _lists]
self._fen_tree = []
self._rebuild = True
def _fen_build(self):
"""Build a fenwick tree instance."""
self._fen_tree[:] = self._list_lens
_fen_tree = self._fen_tree
for i in range(len(_fen_tree)):
if i | i + 1 < len(_fen_tree):
_fen_tree[i | i + 1] += _fen_tree[i]
self._rebuild = False
def _fen_update(self, index, value):
"""Update `fen_tree[index] += value`."""
if not self._rebuild:
_fen_tree = self._fen_tree
while index < len(_fen_tree):
_fen_tree[index] += value
index |= index + 1
def _fen_query(self, end):
"""Return `sum(_fen_tree[:end])`."""
if self._rebuild:
self._fen_build()
_fen_tree = self._fen_tree
x = 0
while end:
x += _fen_tree[end - 1]
end &= end - 1
return x
def _fen_findkth(self, k):
"""Return a pair of (the largest `idx` such that `sum(_fen_tree[:idx]) <= k`, `k - sum(_fen_tree[:idx])`)."""
_list_lens = self._list_lens
if k < _list_lens[0]:
return 0, k
if k >= self._len - _list_lens[-1]:
return len(_list_lens) - 1, k + _list_lens[-1] - self._len
if self._rebuild:
self._fen_build()
_fen_tree = self._fen_tree
idx = -1
for d in reversed(range(len(_fen_tree).bit_length())):
right_idx = idx + (1 << d)
if right_idx < len(_fen_tree) and k >= _fen_tree[right_idx]:
idx = right_idx
k -= _fen_tree[idx]
return idx + 1, k
def _delete(self, pos, idx):
"""Delete value at the given `(pos, idx)`."""
_lists = self._lists
_mins = self._mins
_list_lens = self._list_lens
self._len -= 1
self._fen_update(pos, -1)
del _lists[pos][idx]
_list_lens[pos] -= 1
if _list_lens[pos]:
_mins[pos] = _lists[pos][0]
else:
del _lists[pos]
del _list_lens[pos]
del _mins[pos]
self._rebuild = True
def _loc_left(self, value):
"""Return an index pair that corresponds to the first position of `value` in the sorted list."""
if not self._len:
return 0, 0
_lists = self._lists
_mins = self._mins
lo, pos = -1, len(_lists) - 1
while lo + 1 < pos:
mi = (lo + pos) >> 1
if value <= _mins[mi]:
pos = mi
else:
lo = mi
if pos and value <= _lists[pos - 1][-1]:
pos -= 1
_list = _lists[pos]
lo, idx = -1, len(_list)
while lo + 1 < idx:
mi = (lo + idx) >> 1
if value <= _list[mi]:
idx = mi
else:
lo = mi
return pos, idx
def _loc_right(self, value):
"""Return an index pair that corresponds to the last position of `value` in the sorted list."""
if not self._len:
return 0, 0
_lists = self._lists
_mins = self._mins
pos, hi = 0, len(_lists)
while pos + 1 < hi:
mi = (pos + hi) >> 1
if value < _mins[mi]:
hi = mi
else:
pos = mi
_list = _lists[pos]
lo, idx = -1, len(_list)
while lo + 1 < idx:
mi = (lo + idx) >> 1
if value < _list[mi]:
idx = mi
else:
lo = mi
return pos, idx
def add(self, value):
"""Add `value` to sorted list."""
_load = self._load
_lists = self._lists
_mins = self._mins
_list_lens = self._list_lens
self._len += 1
if _lists:
pos, idx = self._loc_right(value)
self._fen_update(pos, 1)
_list = _lists[pos]
_list.insert(idx, value)
_list_lens[pos] += 1
_mins[pos] = _list[0]
if _load + _load < len(_list):
_lists.insert(pos + 1, _list[_load:])
_list_lens.insert(pos + 1, len(_list) - _load)
_mins.insert(pos + 1, _list[_load])
_list_lens[pos] = _load
del _list[_load:]
self._rebuild = True
else:
_lists.append([value])
_mins.append(value)
_list_lens.append(1)
self._rebuild = True
def discard(self, value):
"""Remove `value` from sorted list if it is a member."""
_lists = self._lists
if _lists:
pos, idx = self._loc_right(value)
if idx and _lists[pos][idx - 1] == value:
self._delete(pos, idx - 1)
def remove(self, value):
"""Remove `value` from sorted list; `value` must be a member."""
_len = self._len
self.discard(value)
if _len == self._len:
raise ValueError('{0!r} not in list'.format(value))
def pop(self, index=-1):
"""Remove and return value at `index` in sorted list."""
pos, idx = self._fen_findkth(self._len + index if index < 0 else index)
value = self._lists[pos][idx]
self._delete(pos, idx)
return value
def bisect_left(self, value):
"""Return the first index to insert `value` in the sorted list."""
pos, idx = self._loc_left(value)
return self._fen_query(pos) + idx
def bisect_right(self, value):
"""Return the last index to insert `value` in the sorted list."""
pos, idx = self._loc_right(value)
return self._fen_query(pos) + idx
def count(self, value):
"""Return number of occurrences of `value` in the sorted list."""
return self.bisect_right(value) - self.bisect_left(value)
def __len__(self):
"""Return the size of the sorted list."""
return self._len
def __getitem__(self, index):
"""Lookup value at `index` in sorted list."""
pos, idx = self._fen_findkth(self._len + index if index < 0 else index)
return self._lists[pos][idx]
def __delitem__(self, index):
"""Remove value at `index` from sorted list."""
pos, idx = self._fen_findkth(self._len + index if index < 0 else index)
self._delete(pos, idx)
def __contains__(self, value):
"""Return true if `value` is an element of the sorted list."""
_lists = self._lists
if _lists:
pos, idx = self._loc_left(value)
return idx < len(_lists[pos]) and _lists[pos][idx] == value
return False
def __iter__(self):
"""Return an iterator over the sorted list."""
return (value for _list in self._lists for value in _list)
def __reversed__(self):
"""Return a reverse iterator over the sorted list."""
return (value for _list in reversed(self._lists) for value in reversed(_list))
def __repr__(self):
"""Return string representation of sorted list."""
return 'SortedList({0})'.format(list(self))
# ===============================================================================================
# some shortcuts
mod = 1000000007
def inp(): return sys.stdin.readline().rstrip("\r\n") # for fast input
def out(var): sys.stdout.write(str(var)) # for fast output, always take string
def lis(): return list(map(int, inp().split()))
def stringlis(): return list(map(str, inp().split()))
def sep(): return map(int, inp().split())
def strsep(): return map(str, inp().split())
def fsep(): return map(float, inp().split())
def nextline(): out("\n") # as stdout.write always print sring.
def testcase(t):
for p in range(t):
solve()
def pow(x, y, p):
res = 1 # Initialize result
x = x % p # Update x if it is more , than or equal to p
if (x == 0):
return 0
while (y > 0):
if ((y & 1) == 1): # If y is odd, multiply, x with result
res = (res * x) % p
y = y >> 1 # y = y/2
x = (x * x) % p
return res
from functools import reduce
def factors(n):
return set(reduce(list.__add__,
([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))
def gcd(a, b):
if a == b: return a
while b > 0: a, b = b, a % b
return a
# discrete binary search
# minimise:
# def search():
# l = 0
# r = 10 ** 15
#
# for i in range(200):
# if isvalid(l):
# return l
# if l == r:
# return l
# m = (l + r) // 2
# if isvalid(m) and not isvalid(m - 1):
# return m
# if isvalid(m):
# r = m + 1
# else:
# l = m
# return m
# maximise:
# def search():
# l = 0
# r = 10 ** 15
#
# for i in range(200):
# # print(l,r)
# if isvalid(r):
# return r
# if l == r:
# return l
# m = (l + r) // 2
# if isvalid(m) and not isvalid(m + 1):
# return m
# if isvalid(m):
# l = m
# else:
# r = m - 1
# return m
##############Find sum of product of subsets of size k in a array
# ar=[0,1,2,3]
# k=3
# n=len(ar)-1
# dp=[0]*(n+1)
# dp[0]=1
# for pos in range(1,n+1):
# dp[pos]=0
# l=max(1,k+pos-n-1)
# for j in range(min(pos,k),l-1,-1):
# dp[j]=dp[j]+ar[pos]*dp[j-1]
# print(dp[k])
def prefix_sum(ar): # [1,2,3,4]->[1,3,6,10]
return list(accumulate(ar))
def suffix_sum(ar): # [1,2,3,4]->[10,9,7,4]
return list(accumulate(ar[::-1]))[::-1]
def N():
return int(inp())
dx = [0, 0, 1, -1]
dy = [1, -1, 0, 0]
def YES():
print("YES")
def NO():
print("NO")
def Yes():
print("Yes")
def No():
print("No")
# =========================================================================================
from collections import defaultdict
def numberOfSetBits(i):
i = i - ((i >> 1) & 0x55555555)
i = (i & 0x33333333) + ((i >> 2) & 0x33333333)
return (((i + (i >> 4) & 0xF0F0F0F) * 0x1010101) & 0xffffffff) >> 24
class MergeFind:
def __init__(self, n):
self.parent = list(range(n))
self.size = [1] * n
self.num_sets = n
# self.lista = [[_] for _ in range(n)]
def find(self, a):
to_update = []
while a != self.parent[a]:
to_update.append(a)
a = self.parent[a]
for b in to_update:
self.parent[b] = a
return self.parent[a]
def merge(self, a, b):
a = self.find(a)
b = self.find(b)
if a == b:
return
self.num_sets -= 1
self.parent[a] = b
self.size[b] += self.size[a]
# self.lista[a] += self.lista[b]
# self.lista[b] = []
def set_size(self, a):
return self.size[self.find(a)]
def __len__(self):
return self.num_sets
def lcm(a, b):
return abs((a // gcd(a, b)) * b)
#
# # to find factorial and ncr
# tot = 400005
# mod = 10 ** 9 + 7
# fac = [1, 1]
# finv = [1, 1]
# inv = [0, 1]
#
# for i in range(2, tot + 1):
# fac.append((fac[-1] * i) % mod)
# inv.append(mod - (inv[mod % i] * (mod // i) % mod))
# finv.append(finv[-1] * inv[-1] % mod)
#
#
# def comb(n, r):
# if n < r:
# return 0
# else:
# return fac[n] * (finv[r] * finv[n - r] % mod) % mod
def solve():
n,w=sep()
l=(w+1)//2
tr=0
brr=[]
crr=[]
su=0
t_ar=lis()
for i in range(n):
k=t_ar[i]
if tr:
continue
if k>=l and k<=w :
tr=1
print(1)
print(i+1)
return
if k<l:
brr.append(k)
crr.append(i+1)
su+=k
if tr:
return
if su<l:
print(-1)
return
n=len(brr)
arr=[]
ts=0
for i in range(n):
ts+=brr[i]
arr.append(crr[i])
if ts>=l:
break
arr.sort()
print(len(arr))
print(*arr)
#solve()
testcase(int(inp()))
| 7 | PYTHON3 |
n = input()
nn = len(n)
if(int(n)>0):
print(n)
else:
x = list(n)
x = list(map(int,x[1:]))
#case1 : removing last
val = x[nn-2]
x = x[::-1]
x.remove(val)
x = x[::-1]
val_1 = int(''.join(str(e) for e in x))
val2=x[nn-3]
x = x[::-1]
x.remove(val2)
x = x[::-1]
x.append(val)
val_2 = int(''.join(str(e) for e in x))
if(val_2>val_1):
print("-"+str(val_1))
else:
if(val_2!=0):
print("-"+str(val_2))
else:
print(0)
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
vector<long long int> v(n);
vector<bool> vec(n, true);
for (long long int i = 0; i < n; i++) cin >> v[i];
;
sort(v.begin(), v.end());
for (int i = 0; i < n; i += 2) {
cout << v[i] << " ";
vec[i] = false;
}
for (int i = n - 1; i >= 0; i--) {
if (vec[i] == true) cout << v[i] << " ";
}
return 0;
}
| 9 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int NUM = 1 << 16;
const int mod = 998244353;
long long qpow(long long x, long long k) {
long long res = 1;
for (; k; k >>= 1) {
if (k & 1) res = res * x % mod;
x = x * x % mod;
}
return res;
}
class NTT {
public:
NTT() {
N = 1 << 16;
wi[0] = 1, wi[1] = qpow(wroot, (mod - 1) / N);
for (int i = 2; i < N; ++i) wi[i] = 1ll * wi[i - 1] * wi[1] % mod;
}
int N, wi[1 << 16];
int wroot = 3;
void operator()(int a[], int n, int op) {
for (int i = 0, j = 0; i < n; ++i) {
if (i < j) swap(a[i], a[j]);
for (int l = n >> 1; (j ^= l) < l; l >>= 1)
;
}
for (int h = 2, hf = 1; h <= n; hf = h, h <<= 1) {
int unit = op < 0 ? N - N / h : N / h;
for (int i = 0; i < n; i += h) {
for (int j = i, w = 0; j < i + hf; ++j) {
int u = a[j], t = 1ll * wi[w] * a[j + hf] % mod;
if ((a[j] = u + t) >= mod) a[j] -= mod;
if ((a[j + hf] = u - t) < 0) a[j + hf] += mod;
if ((w += unit) >= N) w -= N;
}
}
}
if (op > 0) return;
long long inv = qpow(n, mod - 2);
for (int i = 0; i < n; ++i) a[i] = a[i] * inv % mod;
}
} ntt;
int n, m;
const int N = 1 << 16;
int tmp[2][N], dp[2][3][N];
inline void ADD(int &x, int &y) {
if ((x += y) >= mod) x -= mod;
}
void work(int n, int now[3][N], int nxt[3][N]) {
if (n == 0) {
memset(now[0], 0, sizeof(now[0]));
memset(now[1], 0, sizeof(now[1]));
memset(now[2], 0, sizeof(now[2]));
now[1][0] = 1;
now[2][0] = now[2][1] = 1;
}
if (n == 1) {
memset(now[0], 0, sizeof(now[0]));
memset(now[1], 0, sizeof(now[1]));
memset(now[2], 0, sizeof(now[2]));
now[0][0] = 1;
now[1][0] = now[1][1] = 1;
now[2][0] = now[2][2] = 1, now[2][1] = 3;
return;
}
if (n & 1) {
work(n >> 1, nxt, now);
for (int i = m + 1; i < N; ++i) {
nxt[0][i] = nxt[1][i] = nxt[2][i] = 0;
}
ntt(nxt[0], N, 1);
ntt(nxt[1], N, 1);
ntt(nxt[2], N, 1);
for (int i = 0; i < N; ++i) {
tmp[0][i] = 1ll * nxt[0][i] * nxt[0][i] % mod;
tmp[1][i] = 1ll * nxt[0][i] * nxt[1][i] % mod;
now[0][i] = 1ll * nxt[1][i] * nxt[1][i] % mod;
now[1][i] = 1ll * nxt[1][i] * nxt[2][i] % mod;
now[2][i] = 1ll * nxt[2][i] * nxt[2][i] % mod;
}
ntt(tmp[0], N, -1);
ntt(tmp[1], N, -1);
ntt(now[0], N, -1);
ntt(now[1], N, -1);
ntt(now[2], N, -1);
for (int i = m; i >= 1; --i) {
ADD(now[2][i], now[0][i - 1]);
ADD(now[1][i], tmp[1][i - 1]);
ADD(now[0][i], tmp[0][i - 1]);
}
} else {
work(n - 1, nxt, now);
now[2][0] = 1;
for (int i = 0; i <= m; ++i) {
now[0][i] = nxt[1][i];
now[1][i] = nxt[2][i];
now[2][i + 1] = nxt[2][i + 1];
ADD(now[2][i + 1], nxt[2][i]);
ADD(now[2][i + 1], nxt[1][i]);
}
}
}
int main() {
scanf("%d%d", &n, &m);
work(n, dp[0], dp[1]);
for (int i = 1; i <= m; ++i) printf("%d ", dp[0][1][i]);
puts("");
return 0;
}
| 13 | CPP |
n = int(input())
g = str(input())
if (g.count("A") > g.count("D")): print("Anton")
elif (g.count("A") < g.count("D")): print("Danik")
else: print("Friendship") | 7 | PYTHON3 |
import math
def prime(n):
for i in range(2,int(math.sqrt(n))+1):
if n%i==0:
return False
return True
for _ in range(int(input())):
n=int(input())
l=[101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199]
for i in l:
if prime(i+1-n)==False:
e=i+1
break
a=[[1 for i in range(n)]for j in range(n)]
for i in range(n):
a[i][i]=e-n
print(*a[i]) | 8 | PYTHON3 |
while True:
w = input()
if w == '-':
break
n = int(input())
for i in range(n):
h = int(input())
w = w[h:] + w[:h]
print(w) | 0 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 9;
long long binpow(long long n, int x) {
if (x == 0) return 1;
if (x & 1) return binpow(n, x - 1) * n % MOD;
long long b = binpow(n, x >> 1);
return b * b % MOD;
}
int main() {
int n, m;
cin >> n >> m;
long long k = binpow(2, m);
if (k <= n) return (cout << 0), 0;
long long ans = 1;
for (int i = k - n; i < k; ++i) ans *= i, ans %= MOD;
return (cout << ans), 0;
}
| 9 | CPP |
#include <bits/stdc++.h>
using namespace std;
inline int gi() {
register int data = 0, w = 1;
register char ch = 0;
while (!isdigit(ch) && ch != '-') ch = getchar();
if (ch == '-') w = -1, ch = getchar();
while (isdigit(ch)) data = 10 * data + ch - '0', ch = getchar();
return w * data;
}
const int MAX_N = 2e5 + 5;
vector<int> G[MAX_N];
int N, color[MAX_N];
int prevx[MAX_N], prevy[MAX_N];
void dfs(int x, int col) {
color[x] = col;
for (auto v : G[x])
if (color[v] == -1) dfs(v, col ^ 1);
}
int main() {
N = gi();
for (int i = 1; i <= N; i++) {
int x = gi(), y = gi();
if (prevx[x])
G[i].push_back(prevx[x]), G[prevx[x]].push_back(i), prevx[x] = 0;
else
prevx[x] = i;
if (prevy[y])
G[i].push_back(prevy[y]), G[prevy[y]].push_back(i), prevy[y] = 0;
else
prevy[y] = i;
}
memset(color, -1, sizeof(color));
for (int i = 1; i <= N; i++)
if (color[i] == -1) dfs(i, 0);
for (int i = 1; i <= N; i++)
if (color[i])
putchar('b');
else
putchar('r');
putchar('\n');
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long n;
long long a[50004], temp[50004];
long long merge(int left, int mid, int right) {
long long invcount = 0;
long long i = left, j = mid, k = left;
while ((i < mid) && (j <= right)) {
if (a[i] <= a[j]) {
temp[k++] = a[i++];
} else {
temp[k++] = a[j++];
invcount += mid - i;
}
}
while (i < mid) temp[k++] = a[i++];
while (j <= right) temp[k++] = a[j++];
i = left;
while (i <= right) {
a[i] = temp[i];
i++;
}
return invcount;
}
long long meergesort(int left, int right) {
long long invcount = 0;
if (left < right) {
long long mid = (left + right) / 2;
invcount = meergesort(left, mid);
invcount += meergesort(mid + 1, right);
invcount += merge(left, mid + 1, right);
}
return invcount;
}
int main() {
long long t, i, n;
cin >> t;
while (t--) {
cin >> n;
for (i = 0; i < n; i++) cin >> a[i];
if (meergesort(0, n - 1) <= (n * (n - 1)) / 2 - 1)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int TESTS = 1;
while (TESTS--) {
int pres[1000005] = {0}, a, n, i, j, ans = 1, count = 0;
cin >> n;
vector<vector<int>> p(1000005);
vector<int> arr;
for (long long int i = 0; i < n; i++) {
cin >> a;
p[a].push_back(i);
if (!pres[a]) {
arr.push_back(a);
pres[a] = 1;
}
}
for (i = 0; i < arr.size(); i++) {
ans = max(ans, (int)p[arr[i]].size());
for (j = 0; j < arr.size(); j++) {
if (i == j) continue;
auto it1 = p[arr[i]].begin(), it2 = p[arr[j]].begin();
while (true) {
if (count & 1) {
while (it1 != p[arr[i]].end() && *it1 <= *it2) it1++;
} else {
while (it2 != p[arr[j]].end() && *it2 <= *it1) it2++;
}
count++;
if (it1 == p[arr[i]].end() || it2 == p[arr[j]].end()) break;
}
ans = max(ans, count);
count = 0;
}
}
cout << ans << '\n';
}
return 0;
}
| 9 | CPP |
n = int(input())
*a, = map(int, input().split())
b = []
i = 0
while i < n:
if i > 0 and a[i] == a[i-1]:
i += 1
continue
b.append(a[i])
i += 1
print(*b)
| 0 | 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**13
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 distance(x1, y1, x2, y2):
return math.sqrt((x1-x2)**2 + (y1-y2)**2)
def intersection(a1, a2, b1, b2):
x1,y1 = a1
x2,y2 = a2
x3,y3 = b1
x4,y4 = b2
ksi = (y4 - y3) * (x4 - x1) - (x4 - x3) * (y4 - y1)
eta = (x2 - x1) * (y4 - y1) - (y2 - y1) * (x4 - x1)
delta = (x2 - x1) * (y4 - y3) - (y2 - y1) * (x4 - x3)
if delta == 0:
return None
ramda = ksi / delta;
mu = eta / delta;
if ramda >= 0 and ramda <= 1 and mu >= 0 and mu <= 1:
return (x1 + ramda * (x2 - x1), y1 + ramda * (y2 - y1))
return None
def circumcenters(a,b,c):
t1 = [(a[0]+b[0])/2, (a[1]+b[1])/2]
s1 = [t1[1]-a[1], a[0]-t1[0]]
t2 = [(a[0]+c[0])/2, (a[1]+c[1])/2]
s2 = [t2[1]-a[1], a[0]-t2[0]]
p1 = [t1[0]+s1[0]*1e7, t1[1]+s1[1]*1e7]
p2 = [t1[0]-s1[0]*1e7, t1[1]-s1[1]*1e7]
p3 = [t2[0]+s2[0]*1e7, t2[1]+s2[1]*1e7]
p4 = [t2[0]-s2[0]*1e7, t2[1]-s2[1]*1e7]
return intersection(p1,p2,p3,p4)
def main():
n = I()
rr = []
for _ in range(n):
x1,y1,x2,y2,x3,y3 = LF()
a = [x1,y1]
b = [x2,y2]
c = [x3,y3]
t = circumcenters(a,b,c)
rr.append('{:0.3f} {:0.3f} {:0.3f}'.format(t[0], t[1], distance(t[0],t[1],x1,y1)))
return '\n'.join(rr)
print(main())
| 0 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 100;
int b[maxn];
int g[maxn];
int n;
int m;
int main() {
cin >> n >> m;
int b_max = -1;
long long b_tot = 0;
for (int i = 0; i < n; i++) {
cin >> b[i];
b_tot += b[i];
b_max = max(b_max, b[i]);
}
sort(b, b + n);
int min_g = INT_MAX;
for (int i = 0; i < m; i++) {
cin >> g[i];
min_g = min(min_g, g[i]);
}
cerr << b_max << " " << min_g << endl;
if (b_max > min_g) {
return puts("-1"), 0;
}
long long ans = b_tot * m;
int cnt = 0;
for (int i = 0; i < m; i++) {
if (g[i] == b_max) continue;
cnt++;
ans += max(0, g[i] - b_max);
}
if (cnt == m) {
ans += b[n - 1] - b[n - 2];
}
cout << ans << endl;
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
int cmp_str(string &a, string &b) {
int s = 0;
for (int i = 0; i < a.size(); i++) s += (a[i] == b[i]);
return s;
}
string gen_str(int s, char a, char b) {
string res = "";
for (int i = 0; i < s; i++)
if (i % 2 == 1)
res += b;
else
res += a;
return res;
}
int solve(vector<string> &src, string pat, vector<string> &ans) {
ans.clear();
int res = 0;
string a1 = gen_str(src[0].size(), pat[0], pat[1]);
string a2 = gen_str(src[0].size(), pat[1], pat[0]);
string b1 = gen_str(src[0].size(), pat[2], pat[3]);
string b2 = gen_str(src[0].size(), pat[3], pat[2]);
for (int i = 0; i < src.size(); i++) {
if (i % 2 == 0) {
int x1 = cmp_str(src[i], a1);
int x2 = cmp_str(src[i], a2);
if (x1 > x2)
ans.push_back(a1);
else
ans.push_back(a2);
res += max(x1, x2);
} else {
int x1 = cmp_str(src[i], b1);
int x2 = cmp_str(src[i], b2);
if (x1 > x2)
ans.push_back(b1);
else
ans.push_back(b2);
res += max(x1, x2);
}
}
return res;
}
void trans(vector<string> &A, vector<string> &B) {
B.clear();
B.resize(A[0].size(), "");
for (int i = 0; i < A.size(); i++)
for (int j = 0; j < A[i].size(); j++) B[j] += A[i][j];
}
int main() {
int n, m;
cin >> n >> m;
vector<string> A(n), B, C, D;
for (int i = 0; i < n; i++) cin >> A[i];
trans(A, D);
vector<string> st = {"AGCT", "ACGT", "ATCG", "GCAT", "GTAC", "CTAG"};
int best = 0;
for (int i = 0; i < 6; i++) {
int r = solve(A, st[i], B);
if (r > best) {
best = r;
swap(C, B);
}
r = solve(D, st[i], B);
if (r > best) {
best = r;
trans(B, C);
}
}
for (int i = 0; i < n; i++) cout << C[i] << '\n';
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const long long N = 1e18;
long long n, k;
int main() {
cin >> n >> k;
n++;
for (long long i = 1; i <= k; i++) {
if (n % i) {
cout << "No" << endl;
return 0;
}
}
cout << "Yes" << endl;
return 0;
}
| 9 | CPP |
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <climits>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <random>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#ifndef ONLINE_JUDGE
#include "prettyprint.h"
#endif
using namespace std;
#define int long long
#define deb(...) cerr << "[" << #__VA_ARGS__ << "] : [", DBG(__VA_ARGS__)
void DBG() { cerr << "]\n"; }
template <typename T, typename... Args> void DBG(T first, Args... args) {
cerr << first;
if (sizeof...(args))
cerr << ", ";
DBG(args...);
}
void solve() {
int x1, y1;
int x2, y2;
int x3, y3;
cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
if(y1 == y2){
if(y2 == y3 && min(x1, x2) <= x3 && x3 <= max(x1, x2)){
cout << abs(x2-x1) + 2 << "\n";
}
else{
cout << abs(x2-x1) << "\n";
}
}
else if(x1 == x2){
if(x3 == x1 && min(y1, y2) <= y3 && y3 <= max(y1, y2)){
cout << abs(y1-y2) + 2<< "\n";
}
else{
cout << abs(y1-y2) << "\n";
}
}
else{
cout << abs(y1-y2) + abs(x1-x2) << "\n";
}
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int t = 1;
cin >> t;
for (int tt = 1; tt <= t; tt++) {
solve();
}
}
| 7 | CPP |
#include<bits/stdc++.h>
using namespace std;
void __print(int x){cout<<x;}void __print(long x){cout<<x;}
void __print(long long x){cout<<x;}void __print(unsigned x){cout<<x;}
void __print(unsigned long x){cout<<x;}void __print(unsigned long long x){cout<<x;}
void __print(float x){cout<<x;}void __print(double x){cout<<x;}
void __print(long double x){cout<<x;}void __print(char x){cout<<'\''<<x<<'\'';}
void __print(const char *x){cout<<'\"'<<x<<'\"';}void __print(const string &x){cout<<'\"'<<x<<'\"';}
void __print(bool x) {cout<<(x?"true":"false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cout << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define lp(i,a,b) for (int i=a;i<=b;i++)
#define rp(i,a,b) for (int i=a;i>=b;i--)
#define ms(a,x) memset(a,x,sizeof a)
#define ll long long
#define ff first
#define ss second
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define nl cout<<"\n"
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/(gcd(a,b))
#define sq(a) ((a)*(a))
#define sz(a) (int) a.size()
#define mod 1000000007
#define PI (2*acos(0.0))
bool check(string s)
{
int cnt=0;
for(auto i:s)
{
if(i=='(') cnt++;
else cnt--;
if(cnt<0) return false;
}
if(cnt==0)
return true;
return false;
}
void solve()
{
string s;
cin>>s;
char c=s[0];
map<char,int>m;
for(auto i:s)
{
if(i!=c) m[i]++;
}
if(sz(m)==0)
{
cout<<"NO";
nl;
return;
}
if(sz(m)==1)
{
for(auto &i:s)
{
if(i!=c) i=')';
else i='(';
}
debug(s);
if(check(s)) cout<<"YES";
else cout<<"NO";
nl;
return;
}
for(auto &i:s)
{
if(i==c) i='(';
}
vector<char> v;
for(auto i: m) v.pb(i.ff);
string w,x,y,z;
w=s,x=s,y=s,z=s;
lp(i,0,sz(s)-1)
{
if(s[i]==v[0]) w[i]=')',x[i]=')';
else if(s[i]==v[1]) w[i]=')',x[i]='(';
}
lp(i,0,sz(s)-1)
{
if(s[i]==v[0]) y[i]='(',z[i]=')';
else if(s[i]==v[1]) y[i]=')',z[i]=')';
}
debug(w);
debug(x);
debug(y);
debug(z);
if(check(w) or check(x) or check(y) or check(z)) cout<<"YES";
else cout<<"NO";
nl;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
int T=1;
cin>>T;
while(T--) solve();
return 0;
}
| 7 | CPP |
t=int(input())
# a=(input())
# b=(input())
i=0
summer=0
maxi=0
while(i<t):
n,k=list(map(int,input().split()))
# print("okokok")
summer+=(k-n)
maxi=max(summer,maxi)
i+=1
print(maxi)
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, k;
cin >> n >> k;
int cnt2 = 0, cnt5 = 0, temp = 2;
while (1) {
if (n % temp == 0) {
temp *= 2;
++cnt2;
} else
break;
}
temp = 5;
while (1) {
if (n % temp == 0) {
temp *= 5;
++cnt5;
} else
break;
}
long long int zero = 0;
int cnt1 = max(zero, k - cnt2);
while (cnt1--) {
n *= 2;
}
int cnt = max(zero, k - cnt5);
while (cnt--) {
n *= 5;
}
cout << n;
return 0;
}
| 7 | CPP |
def main():
s = input()
c_o = 0
c_z = 0
flag = False
for c in s:
if c == '1':
c_o += 1
c_z = 0
else:
c_z += 1
c_o = 0
if c_o >= 7 or c_z >= 7:
flag = True
break
if flag:
print("YES")
else:
print("NO")
if __name__ == "__main__":
main() | 7 | PYTHON3 |
import math
from collections import Counter, defaultdict, deque
# from bisect import bisect_left as bl, bisect_right as br
# from itertools import accumulate,permutations,combinations
# import heapq
# from functools import reduce
# from fractions import Fraction
from io import BytesIO, IOBase
import sys
import os
# IO region
def Iint(): return int(input())
def Ilist(): return list(map(int, input().split())) # int list
def Imap(): return map(int, input().split()) # int map
def Plist(li, s=' '): print(s.join(map(str, li))) # non string list
# /IO region
def main():
t = Iint()
for _ in range(t):
s = input()
sl = len(s)
s = deque(sorted(Counter(s).most_common(), reverse=True))
m = Iint()
b = Ilist()
new_string = [0]*m
Q = [i for i, bi in enumerate(b) if bi == 0]
while len(Q):
if len(Q) <= s[0][1]:
alp = s[0][0]
newQ = []
for qi in Q:
new_string[qi] = alp
for i in range(m):
if b[i] != 0:
b[i] -= abs(i-qi)
if b[i] == 0:
newQ.append(i)
s.popleft()
Q = newQ
else:
s.popleft()
Plist(new_string, '')
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
def input(): return sys.stdin.readline().rstrip("\r\n")
# endregion
if __name__ == '__main__':
main()
| 10 | PYTHON3 |
#include<iostream>
using namespace std;
int main(){
int An,a,b,c[101]={0};
cin>>a;
for(int i=0;i<a;i++){
cin>>b;
for(int j=b;j>=0;j--){
c[j]++;
}
}
for(int i=0;i<101;i++){
if(c[i]>=i)
An=i;
}
cout<<An<<'\n';
return 0;
} | 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int maxM = 20005, maxN = 505;
const int maxQ = 500;
const int oo = 100000000;
struct Te {
int u, v;
} e[maxM];
struct Tedge {
int v, c, w, next;
} edge[maxM];
int dad[maxN], edges;
int n, m, k, s, t, tot, c[maxM];
int dis[maxN], que[maxN];
int degree[maxN];
int fa[maxN];
void insertedge(int u, int v, int c, int w) {
edges++;
edge[edges].v = v;
edge[edges].c = c;
edge[edges].w = w;
edge[edges].next = dad[u];
dad[u] = edges;
}
void Readln() {
scanf("%d%d%d%d\n", &n, &m, &k, &tot);
for (int i = 1; i <= k; i++) {
scanf("%d%d\n", &e[i].u, &e[i].v);
degree[e[i].u]++;
degree[n + e[i].v]++;
}
int ans = 0;
for (int i = 1; i <= n + m; i++)
if (degree[i] % tot != 0) ans++;
printf("%d\n", ans);
}
bool SPFA() {
for (int i = s; i <= t; i++) dis[i] = oo;
dis[s] = 0;
int head = 1, tail = 1;
que[1] = s;
while (head <= tail) {
int now = que[head % maxQ];
head++;
for (int i = dad[now]; i != 0; i = edge[i].next)
if (edge[i].c > 0 && dis[now] + edge[i].w < dis[edge[i].v]) {
fa[edge[i].v] = i;
dis[edge[i].v] = dis[now] + edge[i].w;
tail++;
que[tail % maxQ] = edge[i].v;
}
}
return dis[t] != oo;
}
void Solve() {
for (int i = tot; i; i--) {
s = 0;
t = n + m + 1;
edges = 0;
for (int j = s; j <= t; j++) dad[j] = 0;
for (int j = 1; j <= k; j++)
if (!c[j]) {
insertedge(e[j].u, e[j].v + n, 1, 0);
insertedge(e[j].v + n, e[j].u, 0, 0);
}
for (int j = 1; j <= n; j++) {
insertedge(s, j, degree[j] / i, 0);
insertedge(j, s, 0, 0);
if (degree[j] % i != 0) {
insertedge(s, j, 1, 1);
insertedge(j, s, 0, -1);
}
}
for (int j = 1; j <= m; j++) {
insertedge(n + j, t, degree[n + j] / i, 0);
insertedge(t, n + j, 0, 0);
if (degree[n + j] % i != 0) {
insertedge(n + j, t, 1, 1);
insertedge(t, n + j, 0, -1);
}
}
while (SPFA()) {
for (int L = t; L != s; L = edge[((fa[L] - 1) ^ 1) + 1].v) {
edge[fa[L]].c--;
edge[((fa[L] - 1) ^ 1) + 1].c++;
}
}
int now = 0;
for (int j = 1; j <= k; j++)
if (!c[j]) {
now += 2;
if (edge[now].c) {
c[j] = i;
degree[e[j].u]--;
degree[e[j].v + n]--;
}
}
}
for (int i = 1; i <= k; i++) printf("%d ", c[i]);
}
int main() {
Readln();
Solve();
return 0;
}
| 7 | CPP |
for i in range(int(input())):
n,a,b=map(int,input().split())
an=''
p=['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
s=''.join(p[:b])+''.join(['a']*(a-b))
for i in range (n//a):
an+=s
temp=n%a
an+=s[:temp]
print(an)
| 8 | PYTHON3 |
#!/usr/bin/env python
import os
import sys
from io import BytesIO, IOBase
import threading
from math import floor,ceil
from heapq import heappop,heappush,heapify
mod=10**9+7
def main():
for _ in range(int(input())):
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
l=0
h=min(a[0],b[n-1])
while l<=h:
mid=l+(h-l)//2
# print(mid)
prev=mid
bol=True
for i in range(n-1):
# print(mid,prev)
if b[i]+prev<a[i]:
bol=False
break
prev=b[i]-max(0,a[i]-prev)
# print('-->',bol,prev)
if bol and prev+b[n-1]-mid>=a[n-1] :
print('YES')
break
# h=mid-1
elif not bol:
l=mid+1
elif prev+b[n-1]-mid<a[n-1]:
#
# print('NO',prev+b[n-1]-mid)
h=mid-1
if l>h:
print('NO')
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# endregion
if __name__ == "__main__":
main()
| 12 | PYTHON3 |
// D - Moving Piece
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
int main(){
int N, K; cin>>N>>K;
vi P(N); rep(i, N) cin>>P[i], P[i]--;
vi C(N); rep(i, N) cin>>C[i];
ll INF = 1e18;
ll score = -INF;
rep(st, N){
ll lap_sc = 0;
int lap_cn = 0;
int nx = st;
while(true){
lap_cn++;
lap_sc += C[nx];
if(st == (nx = P[nx])) break;
}
lap_sc = max(0LL, lap_sc);
ll sum_sc = 0;
for(int k_cn=1; k_cn<=K; k_cn++){
sum_sc += C[nx];
score = max(score, sum_sc + lap_sc * ((K - k_cn) / lap_cn));
if(st == (nx = P[nx])) break;
}
}
cout<< score <<endl;
}
| 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
struct debugger {
template <typename T>
debugger& operator,(const T& v) {
cerr << v << " ";
return *this;
}
} dbg;
int n;
int check(int a[]) {
sort(a, a + 4);
int x, y, z;
x = (a[0] + a[1] + a[2] + a[3]);
y = (a[1] + a[2]);
z = (a[3] - a[0]);
if ((x == 2 * y) && (y == 2 * z)) {
return 1;
}
return 0;
}
int main() {
cin >> n;
int a[4], x, y, z;
if (n == 4) {
for (int i = (0), _n = (n); i < _n; i++) cin >> a[i];
if (check(a)) {
cout << "YES";
} else
cout << "NO";
return 0;
} else if (n == 3) {
cin >> x >> y >> z;
for (int i = 1; i <= 1500; i++) {
a[0] = x;
a[1] = y;
a[2] = z;
a[3] = i;
if (check(a)) {
cout << "YES\n" << i;
return 0;
}
}
cout << "NO";
} else if (n == 2) {
cin >> x >> y;
for (int i = 1; i <= 1500; i++) {
for (int j = 1; j <= 1500; j++) {
a[0] = x;
a[1] = y;
a[2] = i;
a[3] = j;
if (check(a)) {
cout << "YES\n" << min(i, j) << endl;
cout << max(i, j);
return 0;
}
}
}
cout << "NO\n";
} else if (n == 1) {
cin >> x;
a[0] = x;
cout << "YES\n";
cout << a[0] << "\n" << a[0] * 3 << "\n" << a[0] * 3;
return 0;
} else {
cout << "YES\n1\n1\n3\n3";
}
return 0;
}
| 8 | CPP |
n,k,l,c,d,p,nl,np = map(int, input() .split())
Milli_litres = (k * l) // nl
Slices = c * d
Salt = p // np
Litres = Milli_litres // n
slices = Slices // n
salt = Salt // n
x = min(Litres,slices,salt)
print(x) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
string row[100];
char ans[100][100];
string alpha = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
int main() {
assert(alpha.size() == 62);
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while (t--) {
int h, w, k;
cin >> h >> w >> k;
int rice = 0;
for (int i = 0; i < h; i++) {
cin >> row[i];
for (int j = 0; j < w; j++) rice += (row[i][j] == 'R');
}
vector<int> order;
for (int j = 0; j < w; j++) order.push_back(j);
int acc = 0;
for (int i = 0; i < h; i++) {
for (int j : order) {
ans[i][j] = alpha[min(acc * k / rice, k - 1)];
acc += (row[i][j] == 'R');
}
reverse(order.begin(), order.end());
}
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
cout << ans[i][j];
}
cout << '\n';
}
}
}
| 10 | CPP |
N = int(input())
A = [int(input()) for _ in range(N)]
x = set(A[::2])
y = set(sorted(A)[::2])
print(len(x)-len(x&y))
| 0 | PYTHON3 |
a, b = map(int, input().split())
print(a) if(a <= b) else print(a - 1)
| 0 | PYTHON3 |
t = int(input())
for _ in range(t):
n = int(input())
s = str(input())
w = ''
for i in range(n):
w += s[2*i]
print(w) | 7 | PYTHON3 |
line = input().strip('\n\r\t ')
s = set()
for c in line:
s.add(c)
print('CHAT WITH HER!' if len(s) % 2 == 0 else 'IGNORE HIM!') | 7 | PYTHON3 |
m,n=[int(x) for x in input().split()]
r=[int(x) for x in input().split()]
cost=[int(x) for x in input().split()]
costa=[]
i=1
for item in cost:
a=[item,i,r[i-1]]
costa.append(a)
i+=1
counter=0
costa.sort(reverse=True)
dic={}
i=0
for item in costa:
dic[item[1]]=i
i+=1
index=len(costa)-1
for item in range(n):
counter=0
a,b=[int(x) for x in input().split()]
if r[a-1]>=b:
counter+=cost[a-1]*b
r[a-1]-=b
costa[dic[a]][2]-=b
else:
i=index
counter+=cost[a-1]*r[a-1]
costa[dic[a]][2]=0
b-=r[a-1]
r[a-1]=0
while i>=0:
if costa[i][2]>=b:
counter+=costa[i][0]*b
r[costa[i][1]-1]-=b
costa[i][2]-=b
break
else:
counter+=costa[i][0]*costa[i][2]
r[costa[i][1]-1]=0
index-=1
b-=costa[i][2]
costa[i][2]=0
i-=1
else:
counter=0
print(counter)
| 8 | PYTHON3 |
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
long long gcd(long long m, long long n)
{
if (n == 0) return m;
return gcd(n,m%n);
}
int main()
{
int a1, a2, a3, m1, m2, m3, x, y, z;
while (1)
{
cin >> a1 >> m1 >> a2 >> m2 >> a3 >> m3;
if ((a1 | m1 | a2 | m2 | a3 | m3) == 0) { break; }
long long cntx = 1, cnty = 1, cntz = 1, ans;
x = a1 % m1;
y = a2 % m2;
z = a3 % m3;
while (x != 1)
{
x = (a1 * x) % m1;
cntx++;
}
while (y != 1)
{
y = (a2 * y) % m2;
cnty++;
}
while (z != 1)
{
z = (a3 * z) % m3;
cntz++;
}
ans = cntx * cnty / gcd(cntx, cnty); //????????????????????°???????°???¬?????°????±???????
ans = ans * cntz / gcd(ans, cntz);
cout << ans << endl;
}
return 0;
} | 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
int A[100005];
int X[100005];
int Y[100005];
set<int> Q[2 * 100005];
int main() {
ios::sync_with_stdio(false);
int n, a, b;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a >> b;
Q[b - a + 100005].insert(a);
}
for (int i = 1; i <= n; i++) {
cin >> a;
if (!Q[a + 100005].size()) {
cout << "NO";
return 0;
}
X[i] = *Q[a + 100005].begin();
Y[i] = X[i] + a;
Q[a + 100005].erase(Q[a + 100005].begin());
if (i > 1 && X[i] <= X[i - 1] && Y[i] <= Y[i - 1]) {
cout << "NO";
return 0;
}
}
cout << "YES" << endl;
for (int i = 1; i <= n; i++) cout << X[i] << " " << Y[i] << endl;
return 0;
}
| 9 | CPP |
import sys
def main():
x,y=map(int,input().split())
s=2*x+y
t=2*y+x
if s//3-(s%3==0)==t//3-(t%3==0):
print('Brown')
else:
print('Alice')
if __name__=='__main__':
main()
| 0 | PYTHON3 |
__author__ = 'Rakshak.R.Hegde'
def AP(a, n, d):
return (n * (2 * a + (n - 1) * d)) >> 1
n = int(input())
ans = AP(2, n >> 1, 2) - AP(1, (n + 1) >> 1, 2)
print(ans) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
for (int i = 0; i < t; i++) {
int n, k;
cin >> n >> k;
long long int arr[n];
for (int j = 0; j < n; j++) {
cin >> arr[j];
}
long long int peaks[n];
peaks[0] = 0;
peaks[1] = 0;
for (int j = 2; j < n; j++) {
if (arr[j - 1] > arr[j - 2] && arr[j - 1] > arr[j]) {
peaks[j] = peaks[j - 1] + 1;
} else {
peaks[j] = peaks[j - 1];
}
}
int l = 0;
int p = 0, q;
for (int j = 0; j <= (n - k); j++) {
q = peaks[j + k - 1] - peaks[j + 1];
if (q > p) {
l = j;
p = q;
}
}
cout << p + 1 << " " << l + 1 << endl;
}
}
| 8 | CPP |
x = input()
if len(x) == 2:
print(0)
else:
print(len(set(x[1:-1].split(', ')))) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, n, m;
cin >> t;
while (t--) {
cin >> n >> m;
string s;
cin >> s;
vector<int> pos(m);
for (int i = 0; i < m; i++) cin >> pos[i];
long long dp[n + 1][26];
for (int i = 0; i < 26; i++) dp[0][i] = 0;
for (int i = 1; i < n + 1; i++) {
for (int j = 0; j < 26; j++) dp[i][j] = dp[i - 1][j];
dp[i][s[i - 1] - 'a']++;
}
vector<long long> ans(26);
for (int i = 0; i < m; i++) {
int x = pos[i];
for (int j = 0; j < 26; j++) {
ans[j] += dp[x][j];
}
}
for (int i = 0; i < 26; i++) ans[i] += dp[n][i];
for (int i = 0; i < 26; i++) cout << ans[i] << " ";
}
return 0;
}
| 9 | CPP |
n = int(input())
a = [int(i) for i in input().split()]
d = {}
for i in a:
d[i] = 0
for i in a:
d[i] += 1
ans = n - max(d.values())
print(ans)
| 9 | PYTHON3 |
n = int(input())
a = [int(x) for x in input().split(' ')]
if len(a) == 1:
print(0)
else:
a.sort()
in1 = a[len(a)-2] - a[0]
in2 = a[len(a)-1] - a[1]
print(min(in1, in2))
| 8 | PYTHON3 |
#include<iostream>
using namespace std;
int main()
{
int t,sum=0;
int n,m;
cin>>t;
for(int i=1;i<=t;i++)
{
cin>>n>>m;
sum=sum+(m-n+1);
}
cout<<sum<<endl;
} | 0 | CPP |
//In the name of God
//SMani24
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 100;
int n, a[N], r0, r1;
int h[2][N], ans;
vector<int> adj[N];
void dfs(int v = 0, int par = -1, int f = 0) {
for (int u : adj[v])
if (u != par) {
h[f][u] = h[f][v] + 1;
dfs(u, v, f);
}
}
int main() {
cin >> n >> r0 >> r1;
r0--, r1--;
for (int i = 0; i < n - 1; i++) {
int u, v;
cin >> u >> v;
u--, v--;
adj[u].push_back(v);
adj[v].push_back(u);
}
dfs(r0, -1, 0);
dfs(r1, -1, 1);
for (int i = 0; i < n; i++)
if (h[1][i] < h[0][i])
continue;
else {
int t = h[1][i] - h[0][i];
ans = max(ans, h[1][i] - 1);
}
cout << ans << endl;
return 0;
}
| 0 | CPP |
a = str(input())
alist = list(map(str,a))
alist.sort()
a2 = list(set(alist))
ans = []
for s in a2:
if s.isalpha() is True:
ans += s
print(len(ans))
| 7 | PYTHON3 |
T = int(input())
for t in range(T):
n, k = [int(i) for i in input().split()]
A = sorted([int(i) for i in input().split()])
if len(A) == 1:
print(0)
else:
ans = 0
for i in range(1, n):
ans += (k-A[i]) // A[0]
print(ans)
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long t;
cin >> t;
while (t--) {
long long n;
cin >> n;
long long arr[n];
for (long long i = 0; i < n; i++) {
cin >> arr[i];
}
sort(arr, arr + n);
multiset<long long> extras;
for (long long i = 0; i < n;) {
long long var = arr[i];
i++;
while (i < n && arr[i] == var) {
extras.insert(var);
i++;
}
}
long long pre[n + 1];
memset(pre, 0, sizeof(pre));
bool first = 1;
for (long long i = 0; i <= n; i++) {
if (binary_search(arr, arr + n, i)) {
if (i == 0)
pre[i] = 0;
else
pre[i] = pre[i - 1];
} else {
auto indi = extras.lower_bound(i);
if (extras.empty() || indi == extras.begin()) {
for (long long j = i; j <= n; j++) {
pre[j] = -1;
}
i = n;
} else {
advance(indi, -1);
pre[i] = pre[i - 1] + i - *indi;
extras.erase(indi);
}
}
}
long long freqs[n + 1];
memset(freqs, 0, sizeof(freqs));
for (long long i = 0; i < n; i++) freqs[arr[i]]++;
bool flag = 1;
for (long long i = 0; i <= n; i++) {
long long ans = freqs[i];
if (i > 0 && pre[i - 1] == -1) {
cout << -1 << " ";
} else {
if (i > 0)
cout << ans + pre[i - 1] << " ";
else
cout << ans << " ";
}
}
cout << '\n';
}
}
| 11 | CPP |
import io, os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
n = int(input())
p = list(map(int, input().split()))
a = list(map(int, input().split()))
b = list(map(int, input().split()))
col = {(i, j) : [] for i in range(1,4) for j in range(1,4)}
for i in range(n):
x, y = a[i], b[i]
if x > y : y,x = x,y
col[(x, y)].append(p[i])
for i in col.values():
i.sort(reverse = True)
m = int(input())
c = list(map(int, input().split()))
ans = []
for i in c:
cost = -1
for j, k in col.items():
if i in j and k and (cost==-1 or col[cost][-1] > k[-1]): cost = j
if cost == -1: ans.append(-1)
else: ans.append(col[cost].pop())
print(*ans) | 8 | PYTHON3 |
def main():
n,t1,t2,p=map(int,input().split())
p=1-(p/100)
a=[0]*n
for i in range(n):
x,y=map(int,input().split())
z=max(((x*t1*p)+(y*t2)),((y*t1*p)+(x*t2)))
a[i]=[i+1,z]
a.sort(key=lambda x:x[1],reverse=True)
for i in a:
print(i[0],'%.2f'%i[1])
main() | 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int a[2000010];
int b[1000010];
int pos[1000010];
int f[1000010];
long long q[2000100];
int main() {
int res = 0;
int n, m;
memset(pos, -1, sizeof(pos));
scanf("%d%d", &n, &m);
for (int i = (0); i < (n); ++i) {
scanf("%d", &a[i]);
a[n + i] = a[i];
}
for (int i = (0); i < (m); ++i) {
scanf("%d", &b[i]);
pos[b[i]] = i;
}
int l = 0, r = -1;
for (int i = (0); i < (n + n); ++i) {
res = ((res < r - l + 1) ? (r - l + 1) : (res));
if (pos[a[i]] == -1)
l = r + 1;
else {
long long v = pos[a[i]];
if (r - l + 1 == 0) {
r++;
q[r] = v;
continue;
}
long long last = q[r];
if (v < last) {
long long k = (last - v) / m;
v += (k + 1) * m;
}
while ((r - l + 1) && (v - q[l] >= m)) l++;
q[++r] = v;
}
if (r - l + 1 > n) l++;
}
res = ((res < r - l + 1) ? (r - l + 1) : (res));
cout << res << endl;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pi = pair<int, int>;
const int INF = 1e9 + 10;
const ld EPS = 1e-9;
const ll MOD = 1e9 + 7;
const int M = 1e3 + 10;
const int N = 1e6 + 10;
int a[N];
void solve() {
int t;
cin >> t;
while (t--) {
int l1, r1, l2, r2;
cin >> l1 >> r1 >> l2 >> r2;
int a = l1;
int b = l2;
if (a == b) b = r2;
cout << a << " " << b << "\n";
}
}
int main() {
ios_base::sync_with_stdio(false);
FILE* stream;
cin.tie();
solve();
}
| 7 | CPP |
def read():
s = input()
s = s.split(' ')
s = [int(x) for x in s]
return s
def write(data):
print(data)
def calc(n, a):
if n % a == 0:
return n // a
else:
return n // a + 1
def solve(n, m, a):
return calc(n, a) * calc(m, a)
data = read()
data = solve(data[0], data[1], data[2])
write(data) | 7 | PYTHON3 |
X, D = map(int, input().split())
cn = 1
add0 = 1 if (X&1) else 0
ans = []
for i in range(30,0,-1):
if not (X & (1<<i)): continue
ans += [cn]*i
add0 += 1
cn += D
for i in range(add0):
ans.append(cn)
cn += D
print(len(ans))
print(' '.join(map(str, ans)))
| 9 | PYTHON3 |
from sys import stdin
import math
inp = lambda : stdin.readline().strip()
n, m, a, b = [int(x) for x in inp().split()]
if a * m <= b:
print(a*n)
else:
ans = (n//m)*b
r = n%m
ans+=min(a*r, b)
print(ans) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
void chmin(int& x, int y)
{
x = min(x, y);
}
void chmax(int& x, int y)
{
x = max(x, y);
}
int main()
{
int Q, H, W;
string S[50];
int proc = 1;
int used[50][50] = {{}};
cin >> Q;
while(Q--) {
cin >> H >> W;
string chars = "";
for(int i = 0; i < H; i++) {
cin >> S[i];
chars += S[i];
}
sort(chars.begin(), chars.end());
chars.erase(unique(chars.begin(), chars.end()), chars.end());
vector< int > x1(chars.size(), W), x2(chars.size(), 0);
vector< int > y1(chars.size(), H), y2(chars.size(), 0);
for(int i = 0; i < H; i++) {
for(int j = 0; j < W; j++) {
int pos = chars.find(S[i][j]);
chmin(x1[pos], j);
chmax(x2[pos], j);
chmin(y1[pos], i);
chmax(y2[pos], i);
}
}
map< char, int > xx1, xx2, yy1, yy2;
for(int i = 0; i < chars.size(); i++) {
xx1[chars[i]] = x1[i];
xx2[chars[i]] = x2[i];
yy1[chars[i]] = y1[i];
yy2[chars[i]] = y2[i];
}
bool Judge = false;
do {
Judge = true;
for(int i = 0; i < chars.size(); i++) {
for(int j = xx1[chars[i]]; j <= xx2[chars[i]]; j++) {
for(int k = yy1[chars[i]]; k <= yy2[chars[i]]; k++) {
if(used[j][k] == proc) continue;
used[j][k] = proc;
if(S[k][j] != chars[i]) {
Judge = false;
goto myon;
}
}
}
}
myon: ;
++proc;
} while(!Judge && next_permutation(chars.begin(), chars.end()));
if(Judge) cout << "SAFE" << endl;
else cout << "SUSPICIOUS" << endl;
}
} | 0 | CPP |
n = int(input())
if n==1:
print('1')
exit()
s = [[0 for i in range(n)] for j in range(n)]
for i in range(n):
s[i][0]=1
for j in range(n):
s[0][j]=1
for i in range(1,n):
for j in range(1,n):
s[i][j]=s[i-1][j]+s[i][j-1]
print(s[n-1][n-1])
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
void fun() {}
int flag = 0;
void dfs(int par, int pare, int vis[], vector<int> g[], long long int sumarr[],
long long int a[]) {
if (sumarr[par] == -1) {
long long int minval = -1;
for (int i = 0; i < g[par].size(); i++) {
int child = g[par][i];
if (!vis[child]) {
if (minval == -1) minval = sumarr[child];
minval = min(minval, sumarr[child]);
vis[child] = 1;
dfs(child, par, vis, g, sumarr, a);
}
}
a[par] = minval - sumarr[pare];
if (minval == -1) {
a[par] = 0;
}
if (minval != -1 && a[par] < 0) {
flag = 1;
return;
}
for (int i = 0; i < g[par].size(); i++) {
int child = g[par][i];
a[child] = sumarr[child] - minval;
}
} else {
for (int i = 0; i < g[par].size(); i++) {
int child = g[par][i];
if (!vis[child]) {
vis[child] = 1;
dfs(child, par, vis, g, sumarr, a);
}
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
fun();
int n;
cin >> n;
long long int par[n + 1];
par[1] = 0;
par[0] = 0;
for (int i = 2; i <= n; i++) {
cin >> par[i];
}
long long int s[n + 1];
s[0] = 0;
for (int i = 1; i <= n; i++) {
cin >> s[i];
if (s[i] == -1) {
s[i] = LLONG_MAX;
}
}
for (int i = 2; i <= n; i++) {
s[par[i]] = min(s[par[i]], s[i]);
}
long long int ans = 0;
for (int i = 1; i <= n; i++) {
if (s[i] < s[par[i]]) {
cout << "-1\n";
return 0;
}
if (s[i] == LLONG_MAX) {
s[i] = s[par[i]];
}
ans += s[i] - s[par[i]];
}
cout << ans << "\n";
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, m, k, a[1001][1001], b[11][11][11], res[11][11], p[11], md = 1e9 + 7,
ans = 0;
void dfs(int row, int col, int mc) {
if (row == n) {
for (int c = (int)1; c < (int)mc + 1; c++)
for (int qc = (int)c + 1; qc < (int)mc + 1; qc++)
if (p[c] != 0 && p[c] == p[qc]) return;
int fr = 0, cs = k;
for (int c = (int)1; c < (int)mc + 1; c++)
if (p[c] == 0)
fr++;
else
cs--;
int cur = 1;
for (int c = (int)0; c < (int)fr; c++) cur *= cs--;
ans += cur;
if (ans >= md) ans -= md;
return;
}
for (int c = (int)1; c < (int)min(k + 1, mc + 2); c++) {
if (b[row][col][c]) continue;
for (int x = (int)row; x < (int)n; x++)
for (int y = (int)col; y < (int)m; y++) b[x][y][c]++;
res[row][col] = c;
int ok = 1;
if (a[row][col] != 0 && p[c] != 0 && p[c] != a[row][col]) ok = 0;
if (ok) {
bool flag = 0;
if (p[c] == 0) {
p[c] = a[row][col];
flag = 1;
}
int cmc = max(c, mc);
if (col < m - 1)
dfs(row, col + 1, cmc);
else
dfs(row + 1, 0, cmc);
if (flag) p[c] = 0;
}
for (int x = (int)row; x < (int)n; x++)
for (int y = (int)col; y < (int)m; y++) b[x][y][c]--;
}
}
int main() {
cin >> n >> m >> k;
if (n + m - 1 > k) {
cout << 0 << endl;
return 0;
}
for (int i = (int)0; i < (int)n; i++)
for (int j = (int)0; j < (int)m; j++) cin >> a[i][j];
for (int i = (int)0; i < (int)n; i++)
for (int j = (int)0; j < (int)m; j++)
for (int l = (int)1; l < (int)k + 1; l++) b[i][j][l] = 0;
for (int i = (int)1; i < (int)k + 1; i++) p[i] = 0;
dfs(0, 0, 0);
cout << ans << endl;
return 0;
}
| 8 | CPP |
a=input()
lista=[]
for i in range(0,len(a)):
if a[i]=='@':
lista.append(i)
d=0
cadena=""
contador=0
boleano=True
if len(lista)>=1:
b=int(lista[contador])+2
if int(lista[0])==0 or len(a)==2 or a[-1]=='@':
print("No solution")
else:
if len(lista)%2==0:
n=2
m=1
else:
n=1
m=1
for j in range(0,len(lista)-m):
if int(lista[j])-int(lista[j+1])==-1 or int(lista[j])-int(lista[j+1])==-2:
print("No solution")
boleano=(1==2)
break
if boleano:
for t in range(0,len(lista)):
if t==len(lista)-1:
b=len(a)
for k in range(d,b):
cadena+=a[k]
if len(lista)-1!=t:
cadena=cadena+','
d=int(lista[t])+2
if t==len(lista)-1:
t=t-1
b=b+2
b=int(lista[t+1])+2
#contador+=1
print(cadena)
contador=0
elif len(lista)==len(a) or len(lista)==0:
print("No solution")
| 8 | PYTHON3 |
#include<bits/stdc++.h>
using namespace std;
const int N=3010;
typedef long long ll;
int mod,n,jc[N],jc2[N],inv[N],pww[N],pw[N*N],dp[N][N],ans;
int ksm(ll a,int b,int c=1){
for(;b;b/=2,a=a*a%mod)
if(b&1)c=c*a%mod;
return c;
}
void init(){
jc[0]=jc2[0]=pww[0]=1;
for(int i=1;i<=n;++i){
jc[i]=(ll)jc[i-1]*i%mod;
inv[i]=ksm(i,mod-2);
jc2[i]=(ll)jc2[i-1]*inv[i]%mod;
pww[i]=pww[i-1]*2%(mod-1);
}
pw[0]=1;
for(int i=1;i<=n*n;++i)pw[i]=pw[i-1]*2%mod;
}
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>n>>mod;init();
for(int j=0;j<=n;++j)dp[0][j]=jc2[j];
for(int i=1;i<=n;++i)
for(int j=i;j<=n;++j)
dp[i][j]=((ll)(dp[i][j-1]+dp[i-1][j-1])*i+dp[i][j-1])%mod*inv[j]%mod;
for(int i=0;i<=n;++i){
int sum=0;
for(int j=0;j<=i;++j)
sum=(sum+(ll)dp[j][i]*pw[j*(n-i)]%mod*jc2[j])%mod;
sum=ksm(2,pww[n-i],sum);sum=(ll)sum*jc[n]%mod*jc2[n-i]%mod;
if(i&1)ans=(ans-sum+mod)%mod;
else ans=(ans+sum)%mod;
}
cout<<ans<<'\n';
return 0;
}
| 0 | CPP |
n = int(input())
*a, = map(int, input().split())
odd = 2**sum(i%2==0 for i in a)
print(3**n - odd) | 0 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
char s[1000000];
string answer, temp1 = "", temp2;
cin >> s;
int i, j, k;
k = strlen(s);
for (i = 0; i < k; i++)
if (s[i] == '.') break;
j = i;
string t1, t2;
stringstream ss1, ss2;
ss1 << s[j + 1];
ss1 >> t1;
ss2 << s[j + 2];
ss2 >> t2;
if (k >= j + 3)
temp2 = t1 + t2;
else if (k == j + 2)
temp2 = t1 + "0";
else
temp2 = "00";
for (i = 1; i <= j; i++)
if (s[j - i] != '-') {
temp1 = s[j - i] + temp1;
if (i % 3 == 0) {
if (s[0] == '-' && j != i + 1) temp1 = "," + temp1;
if (s[0] != '-' && j != i) temp1 = "," + temp1;
}
}
answer = "$" + temp1 + "." + temp2;
if (s[0] == '-') answer = "(" + answer + ")";
cout << answer;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
#define PII pair<int, int>
#define LL long long
using namespace std;
const int MAXN = 200005;
const LL MOD = 1000000007;
const LL INF = (LL) 1e9 + 5;
struct DSU {
int pa[MAXN];
bool fix[MAXN];
int find(int x) {
return pa[x] == 0 ? x : pa[x] = find(pa[x]);
}
void merge(int x, int y) {
x = find(x);
y = find(y);
pa[y] = x;
}
} dsu;
struct Coin {
int r, c, v;
bool operator < (const Coin &c) const {
return v > c.v;
}
};
int R, C, N;
Coin coin[MAXN];
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> N >> R >> C;
for (int i = 0; i < N; i++) {
int r, c, v;
cin >> r >> c >> v;
coin[i] = {r, c, v};
}
LL ans = 0;
sort(coin, coin + N);
for (int i = 0; i < N; i++) {
int x = dsu.find(coin[i].r), y = dsu.find(coin[i].c + R), v = coin[i].v;
bool *fix = dsu.fix;
if ((int) fix[x] + (int) fix[y] == 1) {
ans += v;
dsu.merge(x, y);
fix[x] = true;
}
else if (!fix[x] && !fix[y]) {
ans += v;
if (x == y) {
fix[x] = true;
}
else {
dsu.merge(x, y);
}
}
}
cout << ans << '\n';
return 0;
} | 0 | CPP |
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<cmath>
#include<bitset>
#include<map>
#include<vector>
using namespace std;
typedef long long ll;
const int N=3010,mod=998244353;
int A,B,C,D;
ll f[N][N],sum;
ll ksm(ll x,ll k){ll re=1;for(;k;k>>=1,x=x*x%mod)if(k&1)re=re*x%mod;return re;}
int main(){
//freopen("a.in","r",stdin);
scanf("%d%d%d%d",&A,&C,&B,&D);
f[A][C]=1;
for(int i=A+1;i<=B;i++){sum=0;
for(int j=C;j<=D;j++){
f[i][j]=(f[i-1][j]*j+sum*(i-1))%mod;
sum=(sum*(i-1)+f[i-1][j])%mod;
}
}sum=0;
for(int i=C;i<=D;i++)sum=(sum+f[B][i]*ksm(B,D-i))%mod;
cout<<sum;
} | 0 | CPP |
for _ in range(int(input())):
a,b,c = map(int,input().split())
abc = [a,b,c]
abc.sort()
orders = list()
if "c" not in orders and c != 0:
orders.append("c")
abc[abc.index(c)] -= 1
if "b" not in orders and b != 0:
orders.append("b")
abc[abc.index(b)] -= 1
if "a" not in orders and a != 0:
orders.append("a")
abc[abc.index(a)] -= 1
if str(abc[2])+str(abc[1]) not in orders and abc[2] != 0 and abc[1] != 0:
orders.append(str(abc[2])+str(abc[1]))
abc[2] -= 1
abc[1] -= 1
if str(abc[1])+str(abc[0]) not in orders and abc[1] != 0 and abc[0] != 0:
orders.append(str(abc[1])+str(abc[0]))
abc[1] -= 1
abc[0] -= 1
if str(abc[2])+str(abc[0]) not in orders and abc[2] != 0 and abc[0] != 0:
orders.append(str(abc[2])+str(abc[0]))
abc[2] -= 1
abc[0] -= 1
if str(abc[2])+str(abc[1])+str(abc[0]) not in orders and abc[2] != 0 and abc[1] != 0 and abc[0] != 0:
orders.append(str(abc[2])+str(abc[0]))
abc[2] -= 1
abc[1] -= 1
abc[0] -= 1
print(len(orders))
| 7 | PYTHON3 |
import math
n=input().split()
a=int(n[0])*int(n[1])
m=math.floor(a/2)
print(m)
| 7 | PYTHON3 |
n = int(input())
if n % 2 == 0:
print ((n // 2 + 1) ** 2)
else:
print ((n // 2 + 1) * (n + 3)) | 8 | PYTHON3 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.