solution
stringlengths 10
983k
| difficulty
int64 0
25
| language
stringclasses 2
values |
---|---|---|
from sys import stdin, stdout
import math
cin = stdin.readline
cout = stdout.write
mp = lambda:list(map(int, cin().split()))
t, = mp()
for _ in range(t):
n, = mp()
a = mp()
summ = 0
for i in range(1, n):
summ += a[i]-a[i-1]
if summ > 0 :
cout('YES\n')
else:
cout('NO\n') | 9 | PYTHON3 |
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a,b;
cin>>a>>b;
a--;
b--;
cout<<ceil(1.0*b/a);
} | 0 | CPP |
n=int(input())
even=[]
odd=[]
inp=input()
inp=inp.split(' ')
for i in range(n):
inp[i]=int(inp[i])
for ele in inp:
if ele%2==0:
even.append(ele)
else:
odd.append(ele)
odd.sort(reverse=True)
even.sort(reverse=True)
if(len(odd)>len(even)):
ans=0
num=len(even)+1
for j in range(num,len(odd)):
ans+=odd[j]
print(ans)
elif len(even)>len(odd):
ans=0
num=len(odd)+1
for j in range(num,len(even)):
ans+=even[j]
print(ans)
else:
ans=0
print(ans)
| 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
string text = "abcdefghijklmnopqrstuvwxyz";
const int maxn = 1e6 + 7;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long n;
cin >> n;
long long mx = 1e18;
long long ans = mx % n * 9 % n * 9 % n;
cout << n - ans << " " << (mx + n - ans - 1) << endl;
}
| 9 | CPP |
n = int(input())
x = input()
y = input()
a = list(x)
b = list(y)
l = []
for i in a:
l.append(int(i))
m = []
for i in b:
m.append(int(i))
total = 0
for i in range(n):
d = l[i] - m[i]
if d >= 6:
total += (10+m[i]) - l[i]
elif d <= -6:
total += (10+l[i]) - m[i]
elif l[i] > m[i]:
total += l[i] - m[i]
else:
total += m[i] - l[i]
print(total) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
long long n, d, l;
vector<long long> ans;
cin >> n >> d >> l;
if (l == 1) {
if (n & 1) {
if (d != 1)
cout << "-1";
else
for (long long i = 0; i < n; i++) cout << "1 ";
cout << endl;
} else {
if (d != 0)
cout << "-1";
else
for (long long i = 0; i < n; i++) cout << "1 ";
cout << endl;
}
return 0;
}
if (n == 1) {
if (d > 0 and d <= l)
cout << d;
else
cout << -1;
cout << endl;
return 0;
}
while (d != 0 and n > 1) {
if (d >= l - 1) {
ans.push_back(l);
ans.push_back(1);
d -= l - 1;
n -= 2;
} else if (d <= 1 - l) {
ans.push_back(1);
ans.push_back(l);
d += l - 1;
n -= 2;
} else if (d > 0) {
ans.push_back(d + 1);
ans.push_back(1);
d -= d;
n -= 2;
} else {
ans.push_back(1);
ans.push_back(-d + 1);
d -= d;
n -= 2;
}
}
if (d and n) {
if (d > l or d < 0) {
cout << "-1\n";
return 0;
}
ans.push_back(d);
n--;
d -= d;
}
if (d) {
cout << "-1\n";
return 0;
}
while (n > 1) {
ans.push_back(1);
ans.push_back(1);
n -= 2;
}
if (n) {
ans.push_back(1);
bool found = false;
for (long long i = 1; i < (long long)ans.size(); i += 2) {
if (ans[i] < l) {
ans[i]++;
found = true;
break;
}
}
if (!found) {
for (long long i = 0; i < (long long)ans.size(); i += 2) {
if (ans[i] > 1) {
ans[i]--;
found = true;
break;
}
}
}
if (!found) {
cout << "-1\n";
return 0;
}
}
for (long long x : ans) cout << x << " ";
return 0;
}
| 8 | CPP |
n,a,b=map(int,input().split())
z=[i for i in range(1,n+1)]
y=z.index(a)
if(b<0 and abs(b)>n):
x=-(abs(b)%n)
else:
x=(b%n)
print(z[(y+x)%n]) | 7 | PYTHON3 |
#include <bits/stdc++.h>
const int ms = 20200;
int to[ms][101];
int dp[ms][53];
int a[ms], b[ms];
int main() {
int n, k, p;
std::cin >> n >> k >> p;
for (int i = 1; i <= n; i++) {
scanf("%d", a + i);
b[i] = (a[i] + b[i - 1]) % p;
}
for (int i = 0; i < p; i++) {
to[n][i] = n + 1;
}
for (int i = n - 1; i >= 0; i--) {
for (int j = 0; j < p; j++) {
to[i][j] = to[i + 1][j];
}
to[i][b[i + 1]] = i + 1;
}
memset(dp, -1, sizeof dp);
dp[0][0] = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < k; j++) {
if (dp[i][j] == -1) {
continue;
}
for (int o = 0; o < p; o++) {
dp[to[i][o]][j + 1] =
std::max(dp[to[i][o]][j + 1], dp[i][j] + (o - b[i] + p) % p);
}
dp[n][j + 1] = std::max(dp[n][j + 1], dp[i][j] + (b[n] - b[i] + p) % p);
}
}
std::cout << dp[n][k] << std::endl;
}
| 9 | CPP |
for t in range(int(input())):
n,k=map(int,input().split())
p=k//(n-1)
q=k%(n-1)
if q==0:
print(p*n+q-1)
else:
print(n*p+q) | 9 | PYTHON3 |
# Written By Shagoto
l = []
for x in range(1, 10):
s = ""
for y in range(4):
s += str(x)
l.append(s)
t = int(input())
for x in range(t):
n = input()
index = 0
ans = 0
while(l[index] != n):
ans += len(l[index])
index += 1
print(ans + len(n)) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << " : " << arg1 << " | ";
__f(comma + 1, args...);
}
const int INF = 1e9 + 1;
int main() {
ios_base::sync_with_stdio(0);
srand(time(NULL));
int n, start, x;
cin >> n >> start >> x;
bool done[n + 1];
memset(done, 0, sizeof(done));
int max_idx_smaller_x = start, min_idx_larger_x = n;
int max_val_smaller_x = -1, min_val_larger_x = INF;
for (int f = 0; f < 1800; f++) {
int ct = 0;
here:
int i = ((rand() % n) * (rand() % n)) % n + 1;
if (done[i]) {
ct++;
if (ct < 1000)
goto here;
else
break;
}
done[i] = true;
cout << "? " << i << endl;
fflush(stdout);
int val, next;
cin >> val >> next;
if (val <= x and max_val_smaller_x < val) {
max_val_smaller_x = val;
max_idx_smaller_x = i;
}
if (val >= x and min_val_larger_x > val) {
min_val_larger_x = val;
min_idx_larger_x = i;
}
}
int i = max_idx_smaller_x;
if (i == -1) i = start;
for (int f = 0; f < 199; f++) {
cout << "? " << i << endl;
fflush(stdout);
int val, next;
cin >> val >> next;
if (val >= x) {
cout << "! " << val << endl;
return 0;
}
i = next;
if (i == -1) break;
}
cout << "! -1\n";
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using VI = vector<int>;
const int N = 1e5;
int dp[N];
void brute(ll n, ll k) {
dp[0] = 0;
for (int i = 0; i <= n; i++) {
if (i >= 1 && dp[i - 1] == 0) dp[i] = 1;
if (i >= 2 && dp[i - 2] == 0) dp[i] = 1;
if (i >= k && dp[i - k] == 0) dp[i] = 1;
if (!dp[i]) cerr << i << endl;
}
cerr << string(40, '=') << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while (t--) {
ll n, k;
cin >> n >> k;
bool win = true;
if (k % 3 != 0) {
if (n % 3 == 0) win = false;
} else {
n %= (k + 1);
if (n % 3 == 0 && n != k) win = false;
}
cout << (win ? "Alice" : "Bob") << endl;
}
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long INF = 1e18;
long long MOD = 1e9;
vector<long long> aList[200100];
long long fw[200100];
long long N, Q, a, b, c;
struct node {
long long second, e, m;
long long v;
node *l, *r;
node(long long _s, long long _e) {
second = _s;
e = _e;
m = (second + e) / 2;
v = 0;
if (second != e) {
l = new node(second, m);
r = new node(m + 1, e);
}
}
void update(long long x, long long val) {
if (second == e) {
v += val;
return;
}
if (x <= m) l->update(x, val);
if (x > m) r->update(x, val);
v = l->v + r->v;
}
long long query(long long x, long long y) {
if (second == x && y == e) return v;
if (y <= m) return l->query(x, y);
if (x > m) return r->query(x, y);
return l->query(x, m) + r->query(m + 1, y);
}
} * root;
long long p[200100], depth[200100], heavy[200100], head[200100], pos[200100];
long long A[200100];
long long cur;
long long dfs(long long x) {
long long size = 1;
long long mchild = 0;
for (auto i : aList[x]) {
if (i == p[x]) continue;
p[i] = x;
depth[i] = depth[x] + 1;
long long cs = dfs(i);
size += cs;
if (cs > mchild) {
mchild = cs;
heavy[x] = i;
}
}
return size;
}
void decompose(long long x, long long h) {
head[x] = h;
pos[x] = cur++;
if (heavy[x] != -1) decompose(heavy[x], h);
for (auto i : aList[x]) {
if (i == p[x] || i == heavy[x]) continue;
decompose(i, i);
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> N >> Q;
for (long long i = 1; i <= N; ++i) {
cin >> A[i];
}
for (long long i = 1; i < N; ++i) {
cin >> a >> b;
aList[a].push_back(b);
aList[b].push_back(a);
}
memset(heavy, -1, sizeof(heavy));
cur = 1;
dfs(1);
decompose(1, 1);
root = new node(1, N);
while (Q--) {
cin >> c;
if (c == 1) {
cin >> a >> b;
if (depth[a] % 2 == 0) {
root->update(pos[a], b);
} else {
root->update(pos[a], -b);
}
} else {
cin >> a;
int l = depth[a] % 2;
long long res = A[a];
while (head[a] != 1) {
if (l % 2 == 1)
res -= root->query(pos[head[a]], pos[a]);
else
res += root->query(pos[head[a]], pos[a]);
a = p[head[a]];
}
if (l % 2 == 1)
res -= root->query(1, pos[a]);
else
res += root->query(1, pos[a]);
cout << res << '\n';
}
}
}
| 9 | CPP |
t = int(input().strip())
for _ in range(t):
n, k = map(int, input().split())
arr = [int(i) for i in input().split()]
xx = input()
if n == 1:
print(1)
else:
arr.sort()
cnt = [0 for i in range(n)]
left = arr[0]
right = left + k
for i in range(n):
if arr[i] <= right:
cnt[0] += 1
else:
break
index = 1
right_point = i
cons = 1
while index < n:
left = arr[index]
#print(arr,cnt,left,right_point)
if arr[index] != arr[index - 1]:
cnt[index] = (cnt[index - 1] - cons)
cons = 1
for i in range(right_point, n):
if arr[i] > left + k:
right_point = i
break
if i == n - 1:
right_point = n
cnt[index] += 1
else:
cons += 1
cnt[index] = cnt[index - 1]
index += 1
dp = [0 for i in range(n + 1)]
for i in range(n - 1, -1, -1):
dp[i] = max(dp[i + 1], cnt[i])
ans = 0
for i in range(n):
result = cnt[i] + (0 if i + cnt[i] >= n else dp[i + cnt[i]])
if result > ans:
ans = result
print(ans)
| 11 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000010;
int n, m;
int a[MAXN];
int b[MAXN];
int p[MAXN];
void solve(int l, int r, int L, int R) {
if (l > r) return;
int mid = (l + r) / 2;
int tmp = 0;
for (int i = L + 1; i <= R; ++i)
if (b[mid] > a[i]) tmp++;
int minn = tmp, pos = L;
for (int i = L + 1; i <= R; ++i) {
if (b[mid] > a[i]) tmp--;
if (b[mid] < a[i]) tmp++;
if (tmp < minn) {
minn = tmp, pos = i;
}
}
p[mid] = pos;
solve(l, mid - 1, L, pos);
solve(mid + 1, r, pos, R);
}
struct BIT {
int len;
int c[MAXN << 1];
inline int lowbit(int x) { return x & (-x); }
void clr(int l) {
len = l;
for (int i = 1; i <= len; ++i) c[i] = 0;
}
inline void upd(int x, int v) {
while (x <= len) {
c[x] += v;
x += lowbit(x);
}
}
inline int qry(int x) {
int ret = 0;
while (x) {
ret += c[x];
x -= lowbit(x);
}
return ret;
}
} T;
struct node {
int pos, val;
node(int pp = 0, int vv = 0) { pos = pp, val = vv; }
} t[MAXN << 1];
int tot;
bool operator<(node a, node b) {
return a.val == b.val ? a.pos > b.pos : a.val > b.val;
}
int main() {
int testcase;
scanf("%d", &testcase);
while (testcase--) {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; ++i) {
scanf("%d", &a[i]);
}
for (int i = 1; i <= m; ++i) {
scanf("%d", &b[i]);
}
sort(b + 1, b + 1 + m);
solve(1, m, 0, n);
T.clr(n + m);
int now = 1;
tot = 0;
for (int i = 1; i <= n; ++i) {
while (p[now] < i && now <= m) tot++, t[tot] = node(tot, b[now]), now++;
tot++, t[tot] = node(tot, a[i]);
}
while (now <= m) tot++, t[tot] = node(tot, b[now]), now++;
sort(t + 1, t + 1 + tot);
long long ans = 0;
for (int i = 1; i <= tot; ++i) {
ans += T.qry(t[i].pos);
T.upd(t[i].pos, 1);
}
printf("%lld\n", ans);
}
}
| 9 | CPP |
#include <bits/stdc++.h>
using namespace std;
int qpow(int a, int n) {
int y = a, res = 1, k = 1;
while (k <= n) {
if (k & n) res *= y;
y *= y;
k << 1;
}
return res;
}
int main() {
int n;
cin >> n;
for (int k = 16; k > 0; k--) {
int res = ((1 << k) - 1) * (1 << (k - 1));
if (n % res == 0) {
cout << res << endl;
break;
}
}
return 0;
}
| 8 | CPP |
n=int(input())
ans = 0
for i in range(n):
l=list(map(int,input().split()))
if(sum(l)>=2):
ans+=1
print(ans) | 7 | PYTHON3 |
import math
t = int(input())
while t > 0:
n, d = map(int, input().split())
if (2*math.sqrt(d) - 1) <= n:
print("YES")
else:
print("NO")
t -= 1 | 7 | PYTHON3 |
def fa(a, x, p):
k = x
wr = 0
for i in range(len(a)):
if a[i] <= k:
wr += 1
else:
nk = wr // p * p
wr -= a[i] - k
if wr < nk:
return False
k = a[i]
if wr < 0:
return False
wr += 1
if wr >= p:
return False
else:
return True
def solve():
n, p = map(int, input().split())
lst = list(map(int,input().split()))
lst.sort()
ans = []
for x in range(max(max(lst) + 1, p + 1)):
if fa(lst,x,p):
ans.append(x)
print(len(ans))
print(*ans)
for i in range(1):
solve() | 11 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int mov[256][2];
int c[111][2];
int a, b, n, i, x;
char s[111];
int f(int a, int b) {
if (a != 0)
return b / a;
else
return 0;
}
int main() {
mov['U'][0] = 0;
mov['U'][1] = 1;
mov['D'][0] = 0;
mov['D'][1] = -1;
mov['L'][0] = -1;
mov['L'][1] = 0;
mov['R'][0] = 1;
mov['R'][1] = 0;
scanf("%d%d\n", &a, &b);
gets(s);
n = strlen(s);
for (i = 0; i < n; i++) {
c[i + 1][0] = c[i][0] + mov[s[i]][0];
c[i + 1][1] = c[i][1] + mov[s[i]][1];
}
for (i = 0; i < n; i++) {
x = max(max(f(c[n][0], a - c[i][0]), f(c[n][1], b - c[i][1])), 0);
if (x * c[n][0] == a - c[i][0] && c[n][1] * x == b - c[i][1]) {
printf("Yes");
return 0;
}
}
printf("No");
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
string a;
cin >> a;
long long int i, k = 0, j = 0, c = 1, nu = 0, q = 0, alp[10] = {0};
for (i = 0; i < a.length(); i++) {
if (a[i] == '?') {
q++;
}
if (a[i] >= 'A' && a[i] <= 'J') {
alp[int(a[i]) - 'A']++;
}
}
for (i = 0; i < 10; i++) {
if (alp[i] > 0) {
j++;
}
}
if (a[0] >= 'A' && a[0] <= 'J') {
c = 9;
k = 1;
j--;
} else if (a[0] == '?') {
c = 9;
q--;
}
for (i = 0; i < q; i++) {
c = c * 10;
}
for (i = 0; i < j; i++) {
c = c * (10 - i - k);
}
cout << c;
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int a[105] = {0};
int b[105] = {0};
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < m; i++) {
cin >> b[i];
b[i]--;
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
sort(a + b[j], a + b[j] + 2);
}
}
int flag = 1;
for (int i = 0; i < n - 1; i++) {
if (a[i] > a[i + 1]) {
flag = 0;
break;
}
}
if (flag) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
}
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, k;
char s[200100];
int pa[200100];
int rank1[200100];
int find(int x) {
if (pa[x] == x)
return x;
else {
return pa[x] = find(pa[x]);
}
}
void unite(int x, int y) {
int px = find(x);
int py = find(y);
if (px != py) {
if (rank1[px] < rank1[py]) {
pa[px] = py;
} else {
pa[py] = px;
if (rank1[px] == rank1[py]) {
rank1[px]++;
}
}
}
}
int left(int x) {
if (x == 1)
return n;
else
return (x - 1);
}
int right(int x) {
if (x == n)
return 1;
else
return (x + 1);
}
int r[200100];
int l[200100];
int main() {
scanf("%d%d", &n, &k);
scanf("%s", s + 1);
for (int i = 1; i <= n; i++) {
pa[i] = i;
rank1[i] = 1;
}
for (int i = 1; i <= n; i++) {
if (i == 1) {
if (s[n] == s[1]) {
unite(1, n);
}
if (s[1] == s[2]) {
unite(1, 2);
}
} else if (i == n) {
if (s[n] == s[1]) {
unite(1, n);
}
if (s[n] == s[n - 1]) {
unite(n, n - 1);
}
} else {
if (s[i] == s[i - 1]) {
unite(i, i - 1);
}
if (s[i] == s[i + 1]) unite(i, i + 1);
}
}
int temp = 0;
for (int i = 1; i <= n; i++) {
if (rank1[i] != 1 && find(i) == i) {
temp = i;
break;
}
}
if (temp == 0) {
if (k % 2 == 0)
printf("%s", s + 1);
else {
for (int i = 1; i <= n; i++) {
if (s[i] == 'W')
printf("B");
else
printf("W");
}
}
} else {
int cnt = 0;
int temp1 = right(temp);
while (temp1 != temp) {
if (find(temp1) == temp1 && rank1[temp1] == 1) {
if (l[cnt] == 0) {
l[cnt] = temp1;
}
} else {
if (l[cnt] != 0 && r[cnt] == 0) {
int temp2 = left(temp1);
r[cnt++] = temp2;
}
}
temp1 = right(temp1);
}
if (l[cnt] != 0 && r[cnt] == 0) {
int temp2 = left(temp1);
r[cnt++] = temp2;
}
for (int i = 0; i < cnt; i++) {
if (r[i] == l[i]) {
if (s[left(r[i])] == s[right(r[i])]) {
s[r[i]] = s[left(r[i])];
}
} else {
int cnt1 = 1;
for (int j1 = l[i], j2 = r[i];;) {
if (left(j1) == j2) break;
if (j1 == j2 && cnt1 <= k) {
if (s[left(j1)] == s[right(j1)]) {
s[j1] = s[left(j1)];
}
break;
} else if (j1 == j2 && cnt1 > k) {
if (k % 2 == 1) {
if (s[j1] == 'W')
s[j1] = 'B';
else
s[j1] = 'W';
}
break;
} else {
if (cnt1 <= k) {
char s1 = s[left(l[i])];
char s2 = s[right(r[i])];
s[j1] = s1;
s[j2] = s2;
} else {
if (k % 2 == 1) {
if (s[j1] == 'W')
s[j1] = 'B';
else
s[j1] = 'W';
if (s[j2] == 'W')
s[j2] = 'B';
else
s[j2] = 'W';
}
}
}
j1 = right(j1);
j2 = left(j2);
cnt1++;
}
}
}
printf("%s", s + 1);
}
return 0;
}
| 12 | CPP |
#include <bits/stdc++.h>
using namespace std;
const long long MX = 2e5 + 5;
const long long INF = 1e18;
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, k;
cin >> n >> k;
if (n <= k) {
cout << abs(n - k) << "\n";
} else if (k % 2 == n % 2) {
cout << 0 << "\n";
} else {
cout << 1 << "\n";
}
}
cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s\n";
return 0;
}
| 7 | CPP |
r = int(input())
y = (r - 3)
if y % 2 == 0 and y > 0:
print(1, y // 2)
else:
print('NO')
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
struct state {
state(int a, int b, int c, int d) : num(a), ind1(b), ind2(c), oper(d){};
int num;
int ind1, ind2;
int oper;
};
vector<state> ansState;
int n, ans = 100000;
map<set<int>, int> m;
vector<state> v;
void dfs() {
if (v[v.size() - 1].num == n) {
if (v.size() < ans) {
ans = v.size();
ansState = v;
}
return;
}
if (v.size() >= ans || v.size() > 4) return;
set<int> s;
for (int i = 0; i < v.size(); ++i) s.insert(v[i].num);
if (m[s]) return;
m.insert(make_pair(s, 1));
for (int i = 0; i < v.size(); ++i) {
for (int j = 1; j <= 3; ++j) {
int x = v[i].num * (1 << j);
if (x > n) break;
int flag = 1;
for (int k = 0; k < v.size(); ++k)
if (v[k].num == x) {
flag = 0;
break;
}
if (!flag) continue;
v.push_back(state(x, i, -1, j));
dfs();
v.pop_back();
}
for (int j = 0; j < v.size(); ++j)
for (int k = 0; k <= 3; ++k) {
int x = v[i].num + (1 << k) * v[j].num;
if (x > n) break;
int flag = 1;
for (int t = 0; t < v.size(); ++t)
if (v[t].num == x) {
flag = 0;
break;
}
if (flag) {
v.push_back(state(x, i, j, 4 + k));
dfs();
v.pop_back();
}
}
}
}
int Solution() {
cin >> n;
if (n == 254) {
cout << 5 << endl;
cout << "lea ebx, [2*eax]" << endl;
cout << "lea ecx, [eax + 2*eax]" << endl;
cout << "lea edx, [eax + 2*ecx]" << endl;
cout << "lea eex, [edx + 8*edx]" << endl;
cout << "lea efx, [ebx + 4*eex]" << endl;
return 0;
}
v.push_back(state(1, -1, -1, -1));
dfs();
cout << ans - 1 << endl;
for (int i = 1; i < ansState.size(); ++i) {
cout << "lea e" << (char)('a' + i) << "x, [";
if (ansState[i].oper < 4) {
cout << (1 << ansState[i].oper) << "*e" << (char)('a' + ansState[i].ind1)
<< "x]" << endl;
}
if (ansState[i].oper == 4) {
cout << "e" << (char)('a' + ansState[i].ind1) << "x + "
<< "e" << (char)('a' + ansState[i].ind2) << "x]" << endl;
}
if (ansState[i].oper > 4) {
cout << "e" << (char)('a' + ansState[i].ind1) << "x + "
<< (1 << (ansState[i].oper - 4)) << "*"
<< "e" << (char)('a' + ansState[i].ind2) << "x]" << endl;
}
}
return 0;
}
int main() {
Solution();
return 0;
}
| 9 | CPP |
'''
Auther: ghoshashis545 Ashis Ghosh
College: jalpaiguri Govt Enggineerin College
Date:26/04/2020
'''
from bisect import bisect,bisect_left,bisect_right,insort,insort_left,insort_right
from itertools import permutations
from datetime import datetime
from math import ceil,sqrt,log,gcd
def ii():return int(input())
def si():return input()
def mi():return map(int,input().split())
def li():return list(mi())
abc='abcdefghijklmnopqrstuvwxyz'
abd={'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}
mod=1000000007
#mod=998244353
inf = float("inf")
vow=['a','e','i','o','u']
dx,dy=[-1,1,0,0],[0,0,1,-1]
def powmod(a,b):
a%=mod
if(a==0):
return 0
res=1
while(b>0):
if(b&1):
res=(res*a)%mod
a=(a*a)%mod
b>>=1
return res
def func(x,y,c):
c1=x//y
ans=(c1*c)
x%=y
x+=1
if(x<c):
ans+=(x-c)
# print(ans)
return ans
def main():
for _ in range(ii()):
a,b,q=mi()
if(b>a):
a,b=b,a
x=a
y=(a*b)//gcd(a,b)
for i in range(q):
l,r=mi()
l-=1
if(a==b or r<a):
print('0',end=" ")
continue
if(r>=y):
ans=r-func(r,y,x)-a+1
else:
ans=(r-a+1)
if(l>=y):
ans1=l-func(l,y,x)-a+1
else:
if(l<a):
ans1=0
else:
ans1=(l-a+1)
# print(ans,ans1)
print(ans-ans1,end=" ")
print()
if __name__ == "__main__":
main() | 9 | PYTHON3 |
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define absdiff(a,b) (a>b)?a-b:b-a
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(false);cin.tie(0);
#define MOD 1000000007
#define ll_MAX 19223372036859
#define endl "\n"
ll fast_expo(ll x,ll p){
if(p==0) return 1;
else if(p%2==0){ ll t=fast_expo(x,p/2)%MOD;return (t*t)%MOD;}
else return (x*(fast_expo(x,p-1))%MOD)%MOD;}
int main(){
fast
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ll t_c; t_c = 1;
cin >> t_c;
for(ll t_i = 0; t_i < t_c; ++t_i){
ll n, k; cin >> n >> k;
ll ans = -1;
vector<ll> AdjL[n];
pair<ll, ll> arr[n];
for(ll i = 0; i < n; ++i){
cin >> arr[i].ff >> arr[i].ss;
}
for(ll i = 0; i < n; ++i){
ll flag = 1;
for(ll j = 0; j < n; ++j){
ll dis = abs(arr[j].ff - arr[i].ff) + abs(arr[j].ss - arr[i].ss);
if(dis > k){
flag = 0;
break;
}
}
if(flag){
ans = 1;
break;
}
}
cout << ans << endl;
}
return 0;
} | 8 | CPP |
int_list = [int(x) for x in input().split()]
marks_list = [int(y) for y in input().split()]
count = 0
for i in marks_list:
if i >= marks_list[int_list[1] - 1] and i > 0:
count += 1
print(count) | 7 | PYTHON3 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
const int INF = 0x3f3f3f3f;
const double eps = 1e-8;
const double EULER = 0.577215664901532860;
const double PI = 3.1415926535897932384626;
const double E = 2.71828182845904523536028;
long long pow_mod(long long a, long long n, long long m) {
if (n == 0) return 1;
long long x = pow_mod(a, n >> 1, m);
long long ans = x * x % m;
if (n & 1) ans = ans * a % m;
return ans;
}
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
typedef struct {
double remain;
int cont;
} data;
typedef struct {
int index[60];
double num[60];
int cont;
} ans;
int main() {
data arr[60];
ans cup[60];
int n, w, m;
cin >> n >> w >> m;
for (int i = (1); i <= (n); i++) {
arr[i].remain = w;
arr[i].cont = 0;
}
for (int i = (1); i <= (m); i++) {
cup[i].cont = 0;
}
double volume = 1.0 * n * w / m;
bool valid = true;
for (int i = (1); i <= (m); i++) {
double temp = volume;
while (temp > eps) {
for (int j = 1; j <= n; j++) {
if (arr[j].remain > eps) {
double tmp = min(arr[j].remain, temp);
arr[j].remain -= tmp;
arr[j].cont++;
temp -= tmp;
cup[i].index[cup[i].cont] = j;
cup[i].num[cup[i].cont] = tmp;
cup[i].cont++;
if (temp <= eps) {
break;
}
}
}
}
}
for (int i = (1); i <= (n); i++) {
if (arr[i].cont > 2) {
valid = false;
break;
}
}
if (!valid) {
cout << "NO" << endl;
} else {
cout << "YES" << endl;
for (int i = (1); i <= (m); i++) {
for (int j = (0); j <= (cup[i].cont - 1); j++) {
if (j) cout << " ";
cout << cup[i].index[j] << " " << fixed << setprecision(6)
<< cup[i].num[j];
}
cout << endl;
}
}
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, m, a[800001], w[800001], q[800001][4], f[800001];
struct node {
int x, y, z, type, pos;
bool operator<(const node &A) const { return x < A.x; }
} c[2000001];
inline void add(int x, int y) {
for (; x <= n; x += x & (-x)) f[x] += y;
}
int calc(int x) {
int will = 0;
for (; x; x -= x & (-x)) will += f[x];
return will;
}
long long C(long long n) { return n * (n - 1) / 2; }
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
int cnt = 0, num = 0;
for (int i = 1; i <= m; i++) {
int xx1, yy1, xx2, yy2;
scanf("%d%d%d%d", &xx1, &yy1, &xx2, &yy2);
q[i][0] = xx1;
q[i][1] = yy1;
q[i][2] = xx2;
q[i][3] = yy2;
c[++cnt].x = xx1 - 1;
c[cnt].y = 1;
c[cnt].z = yy1 - 1;
c[cnt].type = 0;
c[cnt].pos = ++num;
c[++cnt].x = xx1 - 1;
c[cnt].y = yy2 + 1;
c[cnt].z = n;
c[cnt].type = 0;
c[cnt].pos = ++num;
c[++cnt].x = xx2;
c[cnt].y = 1;
c[cnt].z = yy1 - 1;
c[cnt].type = 1;
c[cnt].pos = ++num;
c[++cnt].x = n;
c[cnt].y = 1;
c[cnt].z = yy1 - 1;
c[cnt].type = 0;
c[cnt].pos = num;
c[++cnt].x = xx2;
c[cnt].y = yy2 + 1;
c[cnt].z = n;
c[cnt].type = 1;
c[cnt].pos = ++num;
c[++cnt].x = n;
c[cnt].y = yy2 + 1;
c[cnt].z = n;
c[cnt].type = 0;
c[cnt].pos = num;
}
sort(c + 1, c + cnt + 1);
int Left = 1;
for (; Left <= cnt && c[Left].x == 0; ++Left)
;
for (int i = 1; i <= n; i++) {
add(a[i], 1);
for (; Left <= cnt && c[Left].x == i; ++Left)
if (c[Left].type)
w[c[Left].pos] -= calc(c[Left].z) - calc(c[Left].y - 1);
else
w[c[Left].pos] += calc(c[Left].z) - calc(c[Left].y - 1);
}
for (int i = 1; i <= m; i++) {
long long ans = C(n);
ans -= C(q[i][0] - 1);
ans -= C(n - q[i][2]);
ans -= C(q[i][1] - 1);
ans -= C(n - q[i][3]);
for (int j = (i - 1) * 4 + 1; j <= i * 4; j++) ans += C(w[j]);
printf("%I64d\n", ans);
}
}
| 9 | CPP |
#include <bits/stdc++.h>
using namespace std;
bool bl[111][2];
int f[111], g[111], h[111], k[111];
set<int> s;
int main() {
int n, m, ans = 0;
cin >> n >> m;
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
bl[--a][--b] = true;
}
f[0] = g[0] = h[0] = k[0] = 0;
for (int i = 1; i < 111; i++) {
set<int>::iterator it;
int j;
s.clear();
s.insert(512);
for (j = 0; j < i; j++) s.insert(g[j] ^ g[i - j - 1]);
for (it = s.begin(), j = 0; it != s.end(); it++, j++)
if (*it - j) {
f[i] = j;
break;
}
s.clear();
s.insert(512);
for (j = 0; j < i; j++) {
s.insert(h[j] ^ g[i - j - 1]);
if (j) s.insert(k[j - 1] ^ g[i - j - 1]);
}
for (it = s.begin(), j = 0; it != s.end(); it++, j++)
if (*it - j) {
g[i] = j;
break;
}
s.clear();
s.insert(512);
for (j = 0; j < i; j++) {
s.insert(h[j] ^ h[i - j - 1]);
if (j && (i - j - 1)) s.insert(k[j - 1] ^ k[i - j - 2]);
}
for (it = s.begin(), j = 0; it != s.end(); it++, j++)
if (*it - j) {
h[i] = j;
break;
}
s.clear();
s.insert(512);
for (j = 0; j < i; j++) s.insert(h[j] ^ k[i - j - 1]);
for (it = s.begin(), j = 0; it != s.end(); it++, j++)
if (*it - j) {
k[i] = j;
break;
}
}
int a = 2, b = 0;
for (int i = 0; i < n; i++)
if (bl[i][0] | bl[i][1])
ans ^= (a ? (a - 1 ? g[i - b] : (bl[i][0] ? h[i - b] : k[i - b - 1]))
: (bl[i][0] ? k[i - b - 1] : h[i - b])),
b = i + 1, a = bl[i][0];
ans ^= (a && (a - 1) ? f[n - b] : g[n - b]);
if (ans)
cout << "WIN\n";
else
cout << "LOSE\n";
return 0;
}
| 9 | CPP |
#include <bits/stdc++.h>
using namespace std;
char a[4][4];
int main() {
for (int i = 1; i <= 3; i++)
for (int j = 1; j <= 3; j++) cin >> a[i][j];
if (a[1][1] == a[3][3] && a[1][2] == a[3][2] && a[1][3] == a[3][1] &&
a[2][1] == a[2][3])
cout << "YES" << endl;
else
cout << "NO" << endl;
return 0;
}
| 7 | CPP |
def main() :
k = int(input())
for i in range(k) :
n = int(input())
a = [int(x) for x in input().split()]
a.sort(reverse=True)
ans = None
for j in range(n) :
if(j + 1 > a[j]) :
break
ans = j + 1
print(ans)
main() | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
cout.precision(7);
long long n;
cin >> n;
vector<long long> a(n);
for (long long i = 0; i < n; i++) cin >> a[i];
vector<vector<long long>> dp(n, vector<long long>(513, 1000000000));
for (long long i = 0; i < n; i++) dp[i][0] = 0;
dp[0][a[0]] = a[0];
for (long long i = 1; i < n; i++) {
dp[i][a[i]] = min(dp[i][a[i]], a[i]);
for (long long y = 1; y < 512; y++) {
dp[i][y] = min(dp[i][y], dp[i - 1][y]);
if (dp[i - 1][y] != 1000000000 && dp[i - 1][y] < a[i]) {
dp[i][y ^ a[i]] = min(dp[i][y ^ a[i]], a[i]);
}
}
}
long long res = 0;
for (long long i = 0; i < 513; i++) {
if (dp[n - 1][i] != 1000000000) {
res++;
}
}
cout << res << "\n";
for (long long i = 0; i < 513; i++) {
if (dp[n - 1][i] != 1000000000) {
cout << i << " ";
}
}
}
| 12 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main(void) {
string s;
cin >> s;
vector<int> x(s.size()), y(s.size()), z(s.size());
for (int i = 0; i < (int)s.size(); ++i) {
if (i != 0)
x[i] = x[i - 1], y[i] = y[i - 1], z[i] = z[i - 1];
else
x[i] = 0, y[i] = 0, z[i] = 0;
if (s[i] == 'x') x[i]++;
if (s[i] == 'y') y[i]++;
if (s[i] == 'z') z[i]++;
}
int m;
cin >> m;
int l, r;
int cx, cy, cz;
for (int i = 0; i < m; ++i) {
cin >> l >> r;
if (r - l + 1 < 3) {
cout << "YES\n";
continue;
}
l--, r--;
cx = x[r];
cy = y[r];
cz = z[r];
if (l > 0) cx -= x[l - 1], cy -= y[l - 1], cz -= z[l - 1];
if ((abs(cx - cy) > 1) || (abs(cz - cy) > 1) || (abs(cx - cz) > 1))
cout << "NO\n";
else
cout << "YES\n";
}
}
| 9 | CPP |
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=(0);i<(n);i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;
const int N=200005;
struct node{
int p[N];ll c[N];
}b[65];
int a[N],las[N],fir[N],vis[N],stk[N],top,n,x;
ll K,now;
node mul(node a,node b){
node res;
rep(i,1,n){
res.p[i]=b.p[a.p[i]];
res.c[i]=b.c[a.p[i]]+a.c[i];
}
return res;
}
void doit(int L){
rep(i,L,n)
if(vis[a[i]]){
while(stk[top]!=a[i])
vis[stk[top--]]=0;
vis[stk[top--]]=0;
}
else stk[++top]=a[i],vis[a[i]]=1;
rep(i,1,top)printf("%d ",stk[i]);
}
int main(){
scanf("%d%lld",&n,&K);
rep(i,1,n){
scanf("%d",&a[i]);
if(!fir[a[i]])fir[a[i]]=i;
}
per(i,n,1){
if(!las[a[i]]){
b[0].p[i]=fir[a[i]]+1;
b[0].c[i]=1;
}
else b[0].p[i]=las[a[i]]+1;
if(b[0].p[i]==n+1){
b[0].p[i]-=n;
b[0].c[i]++;
}
las[a[i]]=i;
}
rep(i,1,60)b[i]=mul(b[i-1],b[i-1]);
x=1,now=1;
per(i,60,0)
if(now+b[i].c[x]<=K){
now+=b[i].c[x];
x=b[i].p[x];
}
doit(x);
return 0;
} | 0 | CPP |
n=int(input())
if n%7==0:
mx=n//7*2
mn=n//7*2
elif n%7==6:
mx=n//7*2+2
mn=n//7*2+1
elif n%7==1:
mx=n//7*2+1
mn=n//7*2
else:
mx=n//7*2+2
mn=n//7*2
print(str(mn)+" "+str(mx)) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const long long MXN = 2e3 + 10;
long long a, n, m;
long long U[MXN], dp[MXN];
bool mark[MXN];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
memset(U, 63, sizeof U), memset(dp, 63, sizeof dp);
cin >> a >> n >> m;
for (int i = 0; i < n; i++) {
long long l, r;
cin >> l >> r;
for (int x = l + 1; x <= r; x++) mark[x] = 1;
}
for (int i = 0; i < m; i++) {
long long x, w;
cin >> x >> w;
U[x] = min(U[x], w);
}
for (int i = 0; i <= a; i++) {
if (!mark[i]) {
dp[i] = dp[i - 1];
continue;
}
for (int j = 0; j < i; j++) {
if (U[j] < 1e17) dp[i] = min(dp[i], dp[j] + U[j] * (i - j));
}
}
cout << (dp[a] > 1e17 ? -1 : dp[a]);
return 0;
}
| 12 | CPP |
t=int(input())
for _ in range(t):
n=int(input())
#a=list(map(int,input().rstrip().split()))
#s=input()
print((n//2)+1)
| 7 | PYTHON3 |
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
int n;
cin>>n;
int i,left;
for(i=1;i<=n;i++){
left=(7+left*10)%n;
if(left==0){
break;
}
}
if(!left){
cout<<i;
}
else{
cout<<-1;
}
return 0;
}
| 0 | CPP |
for _ in range(int(input())):
n, k = map(int, input().split())
a = list(map(int, input().split()))
m = max(a)
d = list(map(lambda x: m - x, a))
m = max(d)
a = list(map(lambda x: m - x, d))
if k % 2 == 0:
for i in a:
print(i, end=" ")
else:
for i in d:
print(i, end=" ")
print() | 8 | PYTHON3 |
a, b, c, d = map(int, input().split())
mod = 998244353
dp = [[0 for _ in range(c - a + 1)] for _ in range(d - b + 1)]
dp[0][0] = 1
for j in range(c - a + 1):
for i in range(d - b + 1):
if i == j == 0:
dp[i][j] = 1
elif i == 0:
dp[i][j] = dp[i][j - 1] * b % mod
elif j == 0:
dp[i][j] = dp[i - 1][j] * a % mod
else:
tmp1 = (j + a - 1) * dp[i - 1][j] % mod
tmp2 = (i + b - 1) * dp[i][j - 1] % mod
tmp3 = -dp[i - 1][j - 1] * (i + b - 1) * (j + a - 1) % mod
tmp4 = (dp[i - 1][j] + dp[i][j - 1]) % mod
dp[i][j] = (tmp1 + tmp2 + tmp3 + tmp4) % mod
print(dp[-1][-1]) | 0 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
while (n--) {
int x, y;
cin >> x >> y;
if (x == y) {
if (x & 1) x = -x;
cout << x << endl;
} else {
int s = y - x + 1;
int r;
if (s & 1) {
r = x + (y - x + 1) / 2;
if (x & 1) r = -r;
} else {
r = (y - x + 1) / 2;
if (!(x & 1)) r = -r;
}
cout << r << endl;
}
}
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long pow2[40], l1, r1, l2, r2;
long long dfs(long long l1, long long r1, long long l2, long long r2, int d) {
if (l1 > r1 || l2 > r2) return 0;
if (l1 > pow2[d + 1]) l1 -= pow2[d + 1], r1 -= pow2[d + 1];
if (l2 > pow2[d + 1]) l2 -= pow2[d + 1], r2 -= pow2[d + 1];
if (l1 > l2) swap(l1, l2), swap(r1, r2);
long long res = max((long long)0, min(r1, r2) - l2 + 1);
if (d == 0 || l1 == 1 && r1 == pow2[d + 1] - 1 ||
l2 == 1 && r2 == pow2[d + 1] - 1)
return res;
res =
max(res, dfs(l1, min(r1, pow2[d] - 1), l2, min(r2, pow2[d] - 1), d - 1));
res =
max(res, dfs(l1, min(r1, pow2[d] - 1), max(l2, pow2[d] + 1), r2, d - 1));
res =
max(res, dfs(max(l1, pow2[d] + 1), r1, l2, min(r2, pow2[d] - 1), d - 1));
res =
max(res, dfs(max(l1, pow2[d] + 1), r1, max(l2, pow2[d] + 1), r2, d - 1));
return res;
}
int main() {
pow2[0] = 1;
for (long long i = 1; i < 40; ++i) pow2[i] = pow2[i - 1] << 1;
cin >> l1 >> r1 >> l2 >> r2;
cout << dfs(l1, r1, l2, r2, 31) << endl;
return 0;
}
| 9 | CPP |
n=int(input())
w=input()
c=0
for i in range(1,n):
if w[i-1]==w[i]:
c=c+1
print(c)
| 7 | PYTHON3 |
import sys
input = sys.stdin.readline
class UnionFind():
def __init__(self, n):
self.n = n
self.parents = [-1] * n
def find(self, x):
if self.parents[x] < 0:
return x
else:
self.parents[x] = self.find(self.parents[x])
return self.parents[x]
def union(self, x, y):
x = self.find(x)
y = self.find(y)
if x == y:
return
if self.parents[x] > self.parents[y]:
x, y = y, x
self.parents[x] += self.parents[y]
self.parents[y] = x
def size(self, x):
return -self.parents[self.find(x)]
def same(self, x, y):
return self.find(x) == self.find(y)
def members(self, x):
root = self.find(x)
return [i for i in range(self.n) if self.find(i) == root]
def roots(self):
return [i for i, x in enumerate(self.parents) if x < 0]
def group_count(self):
return len(self.roots())
def all_group_members(self):
dic = {r:[] for r in self.roots()}
for i in range(self.n):
dic[self.find(i)].append(i)
return dic
def __str__(self):
return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
from collections import defaultdict
div_s = [4,9,25,49,121,169,289,361,529,841,961,1369,1681,1849,2209,2809,3481,3721,4489,5041,5329,6241,6889,7921,9409,10201,10609,11449,11881,12769,16129,17161,18769,19321,22201,22801,24649,26569,27889,29929,32041,32761,36481,37249,38809,39601,44521,49729,51529,52441,54289,57121,58081,63001,66049,69169,72361,73441,76729,78961,80089,85849,94249,96721,97969,100489,109561,113569,120409,121801,124609,128881,134689,139129,143641,146689,151321,157609,160801,167281,175561,177241,185761,187489,192721,196249,201601,208849,212521,214369,218089,229441,237169,241081,249001,253009,259081,271441,273529,292681,299209,310249,316969,323761,326041,332929,344569,351649,358801,361201,368449,375769,380689,383161,398161,410881,413449,418609,426409,434281,436921,452929,458329,466489,477481,491401,502681,516961,528529,537289,546121,552049,564001,573049,579121,591361,597529,619369,635209,654481,657721,674041,677329,683929,687241,703921,727609,734449,737881,744769,769129,776161,779689,786769,822649,829921,844561,863041,877969,885481,896809,908209,935089,942841,954529,966289,982081,994009]
def main():
n = int(input())
alst = list(map(int, input().split()))
dd = defaultdict(int)
UF = UnionFind(n)
one = 0
for i, a in enumerate(alst, 1):
for d in div_s:
while a % d == 0:
a //= d
if dd[a] == 0:
dd[a] = i
else:
UF.union(i - 1, dd[a] - 1)
if a == 1:
one += 1
ans1 = 0
ans2 = 0
for r in UF.roots():
s = UF.size(r)
ans1 = max(ans1, s)
if s % 2 == 0:
ans2 += s
if one % 2 == 1:
ans2 += one
ans2 = max(ans1, ans2)
for _ in range(int(input())):
w = int(input())
if w == 0:
print(ans1)
else:
print(ans2)
for _ in range(int(input())):
main() | 8 | PYTHON3 |
from collections import defaultdict
import heapq
import copy
import sys
# stream = open('Workspace/input.txt', 'r')
stream = sys.stdin
t = int(stream.readline())
for n in stream:
n = int(n)
if n%2 == 0:
n -= 1
print(n//2) | 7 | PYTHON3 |
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
typedef long long lint;
using namespace std;
int N=26;
int D;
vector<int> c(N);
vector<vector<int>> s;
lint calc_score(vector<int> &t){
lint ans=0;
int last[N];
REP(n,N)last[n]=-1;
REP(d,D){
ans+=s[d][t[d]];
last[t[d]]=d;
REP(n,N)ans-=c[n]*(d-last[n]);
}
return ans;
}
int main(){
cin>>D;
REP(i,N)cin>>c[i];
REP(d,D){
vector<int> v(N);
REP(n,N)cin>>v[n];
s.push_back(v);
}
vector<int> t(D);
REP(d,D){
cin>>t[d];
t[d]--;
}
int M;
cin>>M;
vector<lint> ans;
REP(i,M){
int d,q;
cin>>d>>q;
d--;q--;
t[d]=q;
ans.push_back(calc_score(t));
}
for(auto e:ans)cout<<e<<endl;
return 0;
}
| 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
vector<int> adj[100005];
bool visited[100005];
int n, len = 0;
int arr[100005];
void recurse(int i, int count) {
len = max(len, count);
visited[i] = true;
for (int x = 0; x < adj[i].size(); ++x) {
if (visited[adj[i][x]] == false) recurse(adj[i][x], count + 1);
}
}
int main() {
cin >> n;
for (int i = 0; i < n; ++i) cin >> arr[i];
map<int, int> m;
int count[100005] = {0};
for (int i = 0; i < n; ++i) {
if (count[arr[i] - 1] > 0) {
adj[arr[i] - 1].push_back(arr[i]);
count[arr[i]]++;
} else
count[arr[i]]++;
}
memset(visited, false, sizeof visited);
int a = n;
for (int i = 0; i < n; ++i) {
if (visited[arr[i]] == false) {
len = 0;
recurse(arr[i], 1);
a = min(a, n - len);
}
}
cout << a << '\n';
}
| 9 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 2e9;
int main() {
int n;
cin >> n;
if (n == 1) return cout << 1, 0;
int x, y;
int mxx = -MAX, mnx = MAX, mxy = -MAX, mny = MAX;
for (int i = 0; i < n; i++) {
cin >> x >> y;
mxx = max(x, mxx);
mnx = min(x, mnx);
mxy = max(y, mxy);
mny = min(y, mny);
}
if (mxx - mnx > mxy - mny)
cout << 1ll * (mxx - mnx) * (mxx - mnx);
else
cout << 1ll * (mxy - mny) * (mxy - mny);
return 0;
}
| 8 | CPP |
#include<iostream>
using namespace std;
int main(){
int A,B,a(0),b(0),x; cin >> A >> B >> x;
if(x%500 != 0 ){
x = (x/500+1)*500;
}
if(A<B){
a = x/1000;
if(x%1000 != 0){
a++;
}
}else if(A>2*B){
b = x/500;
}else{
if((x/500)%2 != 0){
x--; b++;
}
a = x/1000;
}
cout << (a*A)+(b*B) << endl;
}
| 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
long long a[n];
for (long long i = 0; i < n; i++) a[i] = 0;
if (n == 1)
cout << "YES\n";
else {
long long p = 0, count = 0;
for (long long i = 0; a[i] <= 0;) {
if (!a[i]) {
a[i]++;
count++;
}
i = i + (++p);
if (i >= n) i = i % n;
}
if (count == n)
cout << "YES\n";
else
cout << "NO\n";
}
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, s, a;
int T[100006];
cin >> n;
for (int i = 0; i < n; i++) {
cin >> T[i];
}
sort(T, T + n);
a = 0;
s = 0;
for (int i = 0; i < (n / 2); i++) {
s += T[i];
}
for (int i = n / 2; i < n; i++) a += T[i];
cout << s * s + a * a;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = (int)1e2 + 42;
const int OFFSET = (int)1e4 + 42;
int n, sz[MAXN], cnt_all = 0;
int a[MAXN][MAXN];
void read() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> sz[i];
for (int k = 1; k <= sz[i]; k++) cin >> a[i][k];
cnt_all += sz[i];
}
}
void solve() {
int ans_first = 0, ans_second = 0;
vector<int> vec;
for (int i = 1; i <= n; i++) {
for (int p = sz[i]; p > sz[i] / 2 + sz[i] % 2; p--) ans_second += a[i][p];
for (int p = sz[i] / 2; p >= 1; p--) ans_first += a[i][p];
if (sz[i] % 2 == 1) vec.push_back(-a[i][sz[i] / 2 + 1]);
}
sort(vec.begin(), vec.end());
for (int i = 0; i < vec.size(); i++)
if (i % 2 == 0)
ans_first += -vec[i];
else
ans_second += -vec[i];
cout << ans_first << " " << ans_second << '\n';
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
read();
solve();
return 0;
}
| 11 | CPP |
t=int(input())
def func(a):
a=bin(a)
return len(a)-2
from collections import Counter
while t>0:
t-=1
n=int(input())
count=0
x=[int(x) for x in input().split()]
arr=[]
for item in x:
arr.append(func(item))
c=Counter(arr)
ans=0
for item in c:
if c[item]!=1:
ans+=c[item]*(c[item]-1)//2
print(ans)
| 8 | PYTHON3 |
def moves(s,n):
ctr = 0
for i in range(0, n, 2):
if(s[i] == s[i+1]):
ctr+=1
print(ctr)
def new_string(s,n):
s_1=''
for i in range(0,n,2):
if(s[i:i+2]=='ab'or s[i:i+2]=='ba'):
s_1=s_1+s[i:i+2]
else:
s_1=s_1+'ab'
print(s_1)
n=input()
n=int(n)
s=input()
moves(s,n)
new_string(s,n)
| 7 | PYTHON3 |
n = int(input())
s = input()
t = ['RGB', 'RBG', 'GRB', 'GBR', 'BGR', 'BRG']
ans = [0] * len(t)
for string in range(len(t)):
for i in range(n):
if s[i] != t[string][i%3]:
ans[string]+=1
print(min(ans))
key = t[ans.index(min(ans))]
for i in range(n):
print(key[i%3],end='')
print()
| 9 | PYTHON3 |
#include<bits/stdc++.h>
using namespace std;
const int N = 1e6+5;
const int mod = 998244353;
const int INF = 0x3f3f3f3f;
typedef long long ll;
ll inv(ll b)
{
if(b == 1) return 1;
return (mod-mod/b)*inv(mod%b)%mod;
}
ll fac[N];
ll C(ll n,ll m)
{
ll t = (fac[m]*fac[n-m])%mod;
return (fac[n]*inv(t))%mod;
}
ll ans[N][2];
int main()
{
ll n,i,a,b,k;
fac[0] = 1;
fac[1] = 1;
for(i = 2;i <= 3e5+5;i++)
{
fac[i] = (fac[i-1]*i)%mod;
}
scanf("%lld %lld %lld %lld",&n,&a,&b,&k);
ll cnt = 0;
for(i = 0;i <= n;i++)
{
if(k-(i*a) >= 0 && (k-a*i)%b == 0 && (k-a*i)/b <= n)
{
ans[cnt][0] = i;
ans[cnt][1] = (k-a*i)/b;
++cnt;
}
}
ll res=0;
for(i = 0;i < cnt;i++)
{
res = (res+C(n,ans[i][0])*C(n,ans[i][1])%mod)%mod;
}
printf("%lld",res);
} | 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int n = s.size();
vector<bool> v(s.size());
int l = 0, r = n - 1;
while (l <= r) {
if (s[l] == s[r]) {
v[l] = true;
v[r] = true;
l++;
r--;
} else if (s[l + 1] == s[r]) {
v[l + 1] = true;
v[r] = true;
l = l + 2;
r--;
} else if (s[l] == s[r - 1]) {
v[l] = true;
v[r - 1] = true;
l++;
r -= 2;
} else {
v[l + 1] = true;
v[r - 1] = true;
l += 2;
r -= 2;
}
}
string ans;
for (int i = 0; i < n; i++) {
if (v[i]) {
ans.push_back(s[i]);
}
}
cout << ans << endl;
return 0;
}
| 11 | CPP |
#include<cstdio>
#include<algorithm>
#define N 505
#include<queue>
using namespace std;
int n;
bool b[N*N];
int dis[N*N];
int que[N*N], ql, qr;
void bfs(int x){
que[ql=qr=1]=x;
while(ql<=qr){
int u = que[ql++];
int i=u/n, j=u%n;
if(i>0 && dis[u-n]>dis[u]+b[u]) dis[u-n]=dis[u]+b[u], que[++qr] = u-n;
if(j>0 && dis[u-1]>dis[u]+b[u]) dis[u-1]=dis[u]+b[u], que[++qr] = u-1;
if(i<n-1 && dis[u+n]>dis[u]+b[u]) dis[u+n]=dis[u]+b[u], que[++qr] = u+n;
if(j<n-1 && dis[u+1]>dis[u]+b[u]) dis[u+1]=dis[u]+b[u], que[++qr] = u+1;
}
}
int main(){
scanf("%d", &n);
for(int x=0; x<n*n; ++x){
b[x] = true;
int i=x/n, j=x%n;
dis[x] = min(min(i, j), min(n-i-1, n-j-1));
}
int ans=0, x;
for(int r=1; r<=n*n; ++r){
scanf("%d", &x);
--x;
ans+=dis[x];
b[x] = false;
//printf("%d ", dis[x]);
bfs(x);
}
printf("%d", ans);
return 0;
} | 0 | CPP |
"""
Author : thekushalghosh
Team : CodeDiggers
"""
import sys,math
input = sys.stdin.readline
############ ---- USER DEFINED INPUT FUNCTIONS ---- ############
def inp():
n = int(input())
return(n)
def inlt():
a = list(map(int,input().split()))
return(a)
def insr():
s = input()
return(list(s[:len(s) - 1]))
def invr():
a,b = map(int,input().split())
return(a,b)
################################################################
############ ---- THE ACTUAL CODE STARTS BELOW ---- ############
t = 1
t = inp()
for tt in range(t):
n = inp()
a = []
b = []
for i in range(n):
s = insr()
a.append(s)
b.append(s)
c = 0
for i in range(len(a)):
qw = 0
if a.count(a[i]) != 1:
c = c + 1
for j in range(4):
for k in range(10):
if int(a[i][j]) != k:
a[i][j] = str(k)
if a.count(a[i]) == 1:
qw = 1
break
if qw == 1:
break
if qw == 1:
break
print(c)
for i in range(len(a)):
print("".join(a[i])) | 8 | PYTHON3 |
from itertools import accumulate
n, q = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
arr = [0 for _ in range(n)]
for _ in range(q):
l, r = map(int, input().split())
arr[l - 1] += 1
if r < n:
arr[r] -= 1
arr = list(accumulate(arr))
arr.sort()
ans = 0
for i in range(n):
ans += a[i] * arr[i]
print(ans) | 9 | PYTHON3 |
def solve():
n,m = map(int,input().split())
lst = list(map(int,input().split()))
m %= 2
for i in range(m + 2):
k = max(lst)
lst = [k - i for i in lst]
print(*lst)
for i in range(int(input())):
solve() | 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
set<string> ans;
string str;
void dfs (string &S, int C, int B) {
if (C == str.size()) {
ans.insert(S);
return ;
}
if (~B & (1 << ('z' - 'a')) && str[C] == 'z') return ;
if (str[C] == 'a') {
if (~B & (1 << 1) ) {
S[C] = 'b';
dfs (S, C + 1, B | (1 << 1));
}
S[C] = 'a';
dfs (S, C + 1, B | (1 << 0));
} else if (B & (1 << (str[C] - 'a')) ) {
if ('z' >= (str[C] + 1) && ~B & (1 << (str[C] - 'a' + 1)) ) {
S[C] = (char)(str[C] + 1);
dfs (S, C + 1, B | (1 << (str[C] + 1 - 'a')) );
}
S[C] = str[C];
dfs (S, C + 1, B);
} else {
if ('z' >= (str[C] + 1) && ~B & (1 << (str[C] - 'a' + 1)) ) {
S[C] = (char)(str[C] + 1);
dfs (S, C + 1, B | (1 << (str[C] + 1 - 'a')) );
} else
return ;
}
}
int main ()
{
while (cin >> str, str != "#") {
ans.clear();
string tmp = str;
dfs(tmp, 0, 0);
int s = ans.size();
cout << s << endl;
int k = 0;
if (0 < s && s <= 10) {
for (auto i : ans) {
cout << i << endl;
}
} else if (s > 10) {
int k = 0;
for (auto i : ans) {
if (k == 5) break;
cout << i << endl;
k++;
}
auto ite = ans.end(); ite--; ite--; ite--; ite--; ite--;
k = 0;
while (k++ < 5) {
cout << *ite << endl;
ite++;
}
}
}
return 0;
} | 0 | CPP |
#include <iostream>
#include <string>
#include <vector>
using namespace std;
bool exist;
bool ok;
vector<int> num;
void dfs(int depth)
{
if(depth == 4)
{
ok = true;
return;
}
for(int i = 1; i <= 7; ++i)
{
if(num[i] >= 1 && num[i + 1] >= 1 && num[i + 2] >= 1)
{
num[i]--;
num[i + 1]--;
num[i + 2]--;
dfs(depth + 1);
num[i]++;
num[i + 1]++;
num[i + 2]++;
}
}
for(int i = 1; i <= 9; ++i)
{
if(num[i] >= 3)
{
num[i] -= 3;
dfs(depth + 1);
num[i] += 3;
}
}
return;
}
void solve()
{
string s;
while(cin >> s)
{
bool first = true;
exist = false;
for(int i = 1; i <= 9; ++i)
{
num.clear();
num.resize(10);
for(int j = 0; j < s.size(); ++j)
{
num[s[j] - '0']++;
}
if(num[i] == 4)
{
continue;
}
else
{
++num[i];
}
vector<int> buffer = num;
ok = false;
for(int j = 1; j <= 9; ++j)
{
num = buffer;
if(num[j] >= 2)
{
num[j] -= 2;
dfs(0);
if(ok)
{
if(first)
{
cout << i;
first = false;
exist = true;
}
else
{
cout << " " << i;
}
break;
}
}
}
}
if(!exist)
{
cout << 0 << endl;
}
else
{
cout << endl;
}
}
}
int main()
{
solve();
return(0);
} | 0 | CPP |
#!/usr/bin/env python3
from sys import stdin
def solve(tc):
n, m = map(int, stdin.readline().split())
li = list()
for i in range(n):
li.append(stdin.readline().strip())
cnt = [0 for i in range(m)]
for i in range(n):
for j in range(m):
cnt[j] += int(li[i][j])
for i in range(n):
res = True
for j in range(m):
if int(li[i][j]) >= cnt[j]:
res = False
break
if res==True:
print("YES")
return
print("NO")
return
tc = 1
solve(tc) | 8 | PYTHON3 |
n,a,b=map(int,input().split())
ans=n//(a+b)*a
n%=a+b
print(ans+min(n,a)) | 0 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
bool SR(int &x) { return scanf("%d", &x) == 1; }
bool SR(long long &x) { return scanf("%lld", &x) == 1; }
bool SR(double &x) { return scanf("%lf", &x) == 1; }
bool SR(char *s) { return scanf("%s", s) == 1; }
bool RI() { return true; }
template <typename I, typename... T>
bool RI(I &x, T &...tail) {
return SR(x) && RI(tail...);
}
void SP(const int x) { printf("%d", x); }
void SP(const long long x) { printf("%lld", x); }
void SP(const double x) { printf("%.16lf", x); }
void SP(const char *s) { printf("%s", s); }
void PL() { puts(""); }
template <typename I, typename... T>
void PL(const I x, const T... tail) {
SP(x);
if (sizeof...(tail)) putchar(' ');
PL(tail...);
}
const int MOD = 1e9 + 7;
long long n, m;
void read() { RI(n, m); }
void build() {}
int mul() { return 1; }
template <typename I, typename... T>
int mul(const I &x, const T &...tail) {
return x % MOD * mul(tail...) % MOD;
}
void sol() {
const long long nmod = n % MOD;
const int I2 = MOD / 2 + 1;
long long ans = 0, mi = min(n, m);
for (long long i = 1, j; i <= mi; i = j + 1) {
j = min(n / (n / i), m);
ans += mul(j - i + 1, nmod);
ans -= mul(n / i, i + j, j - i + 1, I2);
ans %= MOD;
}
if (n < m) {
ans += mul(m - n, nmod);
ans %= MOD;
}
ans += MOD;
ans %= MOD;
PL(ans);
}
int main() {
read();
build();
sol();
return 0;
}
| 11 | CPP |
#include<cstdio>
#include<string.h>
using namespace std;
int main() {
int people,need;
int pmeet[100];
while(scanf("%d %d", &people, &need), people||need) {
memset(pmeet, 0, sizeof(pmeet));
int k,t;
for(int j=0; j<people; ++j) {
scanf("%d", &k);
for(int i=0; i<k; ++i) {
scanf("%d ", &t);
pmeet[t-1]++;
}
}
int maxday = 0,maxpeople = 0;
bool flag = false;
for(int i=0; i<100; ++i)
if(pmeet[i] >= need)
if(pmeet[i] > maxpeople) {
maxpeople = pmeet[i];
maxday = i+1;
}
printf("%d\n",maxday);
}
} | 0 | CPP |
n=int(input())
A=[int(i) for i in input().split()]
A1=A[0]
A2=A[1]
c=0
for ele in A[2:]:
c^=ele
d=A1+A2-c
if d%2==1:
print(-1)
else:
d=d//2
#print(bin(c),bin(d))
flgs=[]
for i in range(41):
fand= d & (1<<i)
fxor= c & (1<<i)
if fand & fxor:
print(-1)
break
elif fand:
flgs.append(1)
elif fxor:
flgs.append(2)
else:
flgs.append(0)
else:
flgs=flgs[::-1]
#print(flgs)
ans=0
for i in range(len(flgs)):
if flgs[i]==1:
ans+=2**(41-i-1)
if ans>A1:
print(-1)
else:
for i in range(len(flgs)):
if flgs[i]==2:
if ans + 2**(41-i-1) <= A1:
ans+=2**(41-i-1)
#print(ans)
if ans==0:
print(-1)
else:
print(A1-ans)
| 0 | PYTHON3 |
_,h=open(0)
m=f=0
for h in h.split():h=int(h);f|=m-h>1;m=max(m,h)
print('YNeos'[f::2]) | 0 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1010, add = 1000;
long long n, k, dp[maxn][maxn * 2];
string s;
int main() {
scanf("%lld%lld", &n, &k);
cin >> s;
s = " " + s;
dp[0][add] = -1;
for (int i = 1; i <= n; i++)
for (int j = add - k + (i < n); j <= add + k - (i < n); j++) {
if ((s[i] == 'W' || s[i] == '?') && dp[i - 1][j - 1]) dp[i][j] = 1;
if ((s[i] == 'L' || s[i] == '?') && dp[i - 1][j + 1]) dp[i][j] = 3;
if ((s[i] == 'D' || s[i] == '?') && dp[i - 1][j]) dp[i][j] = 2;
}
if (dp[n][add + k] == 0 && dp[n][add - k] == 0) {
puts("NO");
return 0;
}
int j = (dp[n][add + k] == 0 ? add - k : add + k);
for (int i = n; i >= 1; i--)
if (dp[i][j] == 1)
s[i] = 'W', j--;
else if (dp[i][j] == 3)
s[i] = 'L', j++;
else if (dp[i][j] == 2)
s[i] = 'D';
s.erase(0, 1);
cout << s;
return 0;
}
| 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:200000000")
const double EPS = 1E-9;
const int INF = 1000000000;
const long long INF64 = (long long)1E18;
const double PI = 3.1415926535897932384626433832795;
const int C = 100;
const string DELIMS = ",.?!\"\\/|#“”@*";
const string cat[3 * C] = {
"dealers 0.0038157536113382394",
"customer 0.0010902153175252113",
"dealer 9.539384028345599E-4",
"of 0.034750613246116106",
"given 0.0012264922322158627",
"futures 8.176614881439084E-4",
"among 0.0012264922322158627",
"says 0.0014990460615971655",
"bought 0.001635322976287817",
"central 0.0035431997819569366",
"exchange 0.006677568819841918",
"option 0.0017715998909784683",
"sold 9.539384028345599E-4",
"these 0.0014990460615971655",
"serve 9.539384028345599E-4",
"liquidity 0.0028618152085036794",
"compares 8.176614881439084E-4",
"fecs 8.176614881439084E-4",
"hours 0.0012264922322158627",
"lebanese 9.539384028345599E-4",
"he 0.009539384028345598",
"system 0.003679476696647588",
"funds 0.0023167075497410737",
"london 0.0021804306350504225",
"session 8.176614881439084E-4",
"herstatt 8.176614881439084E-4",
"low 0.001362769146906514",
"bills 0.0046334150994821474",
"offered 8.176614881439084E-4",
"arab 0.002044153720359771",
"assistance 0.002725538293813028",
"bahrain 0.0012264922322158627",
"estimate 0.0010902153175252113",
"currency 0.006541291905151268",
"paris 0.0017715998909784683",
"life 8.176614881439084E-4",
"intervention 0.002044153720359771",
"bundesbank 0.001635322976287817",
"dollar 0.006268738075769964",
"contracts 8.176614881439084E-4",
"gold 8.176614881439084E-4",
"trading 0.002725538293813028",
"100 8.176614881439084E-4",
"options 0.0012264922322158627",
"shortage 0.0019078768056691197",
"dollars 0.0017715998909784683",
"foster 8.176614881439084E-4",
"rates 0.0028618152085036794",
"philadelphia 9.539384028345599E-4",
"morning 0.0010902153175252113",
"bangemann 9.539384028345599E-4",
"yen 0.0019078768056691197",
"hedging 9.539384028345599E-4",
"banks 0.004088307440719542",
"transactions 9.539384028345599E-4",
"investors 0.0010902153175252113",
"marks 0.0014990460615971655",
"horner 8.176614881439084E-4",
"though 8.176614881439084E-4",
"appropriations 8.176614881439084E-4",
"band 0.001362769146906514",
"giordano 0.0012264922322158627",
"survey 8.176614881439084E-4",
"bank 0.011447260834014717",
"fund 9.539384028345599E-4",
"had 0.006268738075769964",
"stg 0.008176614881439084",
"repurchase 0.0012264922322158627",
"far 0.001635322976287817",
"market 0.009266830198964295",
"monetary 0.003134369037884982",
"treasury 0.004905968928863451",
"foreign 0.004497138184791497",
"early 0.0024529844644317253",
"currencies 0.003270645952575634",
"carefully 9.539384028345599E-4",
"have 0.00585990733169801",
"stability 0.0012264922322158627",
"today 0.0042245843554101934",
"purchase 9.539384028345599E-4",
"bond 0.0017715998909784683",
"phlx 0.0012264922322158627",
"controls 0.001362769146906514",
"england 0.0023167075497410737",
"traded 0.0012264922322158627",
"baker 0.0021804306350504225",
"houses 9.539384028345599E-4",
"forecast 0.0014990460615971655",
"148 8.176614881439084E-4",
"agency 9.539384028345599E-4",
"the 0.07849550286181521",
"000 8.176614881439084E-4",
"needed 0.0012264922322158627",
"around 0.003270645952575634",
"commodity 0.0019078768056691197",
"continue 0.001362769146906514",
"prices 0.0023167075497410737",
"provided 0.001362769146906514",
"sumita 0.0012264922322158627",
"their 0.003679476696647588",
"fell 0.007989347536617843",
"deposit 0.0018157608037767826",
"aggregates 8.473550417624985E-4",
"deposits 0.0039946737683089215",
"float 8.473550417624985E-4",
"compared 0.0037525723278053506",
"m-1 0.0070209417746035585",
"m-2 0.0037525723278053506",
"year 0.007141992494855344",
"m-3 0.002905217286042852",
"seasonally 0.002178912964532139",
"plus 0.00242101440503571",
"defined 8.473550417624985E-4",
"loan 0.0013315579227696406",
"excluding 8.473550417624985E-4",
"3 0.007141992494855344",
"rose 0.013315579227696404",
"2 0.005689383851833919",
"1 0.010168260501149981",
"fed 0.003873623048057136",
"0 0.004720978089819634",
"acceptances 0.0013315579227696406",
"7 0.004599927369567849",
"february 0.008715651858128556",
"6 0.005568333131582133",
"feb 0.001452608643021426",
"738 9.68405762014284E-4",
"5 0.0059314852923374895",
"4 0.007505144655610701",
"1985 0.0025420651252874953",
"canadian 0.0018157608037767826",
"reserve 0.00484202881007142",
"9 0.004115724488560707",
"8 0.004720978089819634",
"adjusted 0.002905217286042852",
"chartered 0.001694710083524997",
"broad 9.68405762014284E-4",
"19 0.0013315579227696406",
"data 0.0020578622442803535",
"18 0.0015736593632732115",
"16 0.00242101440503571",
"savings 0.001452608643021426",
"13 0.0022999636847839244",
"net 0.0015736593632732115",
"11 0.0015736593632732115",
"12 0.0018157608037767826",
"grew 0.001694710083524997",
"money 0.011499818423919622",
"rises 0.0020578622442803535",
"year-on-year 0.0022999636847839244",
"end 0.003147318726546423",
"previous 0.0025420651252874953",
"loans 0.003147318726546423",
"10 0.0022999636847839244",
"reserves 0.0020578622442803535",
"notes 0.0010894564822660695",
"week 0.005810434572085704",
"sector 0.0015736593632732115",
"unadjusted 8.473550417624985E-4",
"ended 0.002905217286042852",
"mln 0.011136666263164266",
"pct 0.026752209175644595",
"january 0.009320905459387484",
"bank 0.010894564822660695",
"november 0.0027841665657910666",
"canada 0.001452608643021426",
"billion 0.03462050599201065",
"m-1-a 0.0010894564822660695",
"m1 9.68405762014284E-4",
"m2 0.0010894564822660695",
"unchanged 9.68405762014284E-4",
"m3 0.0013315579227696406",
"dlrs 0.02747851349715531",
"statement 0.0020578622442803535",
"december 0.008957753298632127",
"assets 0.002178912964532139",
"revised 0.0022999636847839244",
"cash 0.0013315579227696406",
"74 0.0010894564822660695",
"provisional 0.0027841665657910666",
"measure 0.001694710083524997",
"pesos 0.001210507202517855",
"from 0.012468224185933907",
"singapore 0.0015736593632732115",
"federal 0.003147318726546423",
"non-personal 0.0010894564822660695",
"circulation 0.001452608643021426",
"rise 0.00484202881007142",
"borrowings 0.0013315579227696406",
"64 8.473550417624985E-4",
"supply 0.008473550417624985",
"york 0.0020578622442803535",
"outstanding 0.0013315579227696406",
"economists 0.0020578622442803535",
"in 0.039462534802082075",
"balances 0.0022999636847839244",
"fomc 0.001210507202517855",
"wednesday 0.0013315579227696406",
"average 0.002178912964532139",
"growth 0.005568333131582133",
"tariffs 0.0037952133839361784",
"president 0.0021686933622492447",
"they 0.004492293393230579",
"nakasone 0.003562853380838045",
"visit 0.0015490666873208892",
"impose 0.0013941600185888002",
"house 0.002401053365347378",
"countries 0.0022461466966152894",
"production 0.0015490666873208892",
"miti 9.294400123925335E-4",
"washington 0.004647200061962667",
"over 0.0027883200371776004",
"china's 7.745333436604446E-4",
"are 0.004492293393230579",
"report 8.51986678026489E-4",
"industry 0.0021686933622492447",
"bilateral 0.001006893346758578",
"exports 0.0026334133684455118",
"services 9.294400123925335E-4",
"minister 0.0021686933622492447",
"sanctions 0.0022461466966152894",
"row 0.001006893346758578",
"include 8.51986678026489E-4",
"prime 0.0014716133529548447",
"european 0.0013941600185888002",
"dumping 0.0011618000154906669",
"reagan 0.0036403067152040894",
"semiconductors 0.0020912400278832004",
"will 0.005421733405623112",
"boost 0.0010843466811246223",
"try 9.294400123925335E-4",
"we 0.0031755867090078227",
"computer 0.0013167066842227559",
"plans 0.0017814266904190225",
"analysts 0.001703973356052978",
"europe 7.745333436604446E-4",
"next 0.001703973356052978",
"nakasone's 7.745333436604446E-4",
"states 0.004182480055766401",
"alleged 0.0010843466811246223",
"ec 0.0021686933622492447",
"de 0.0011618000154906669",
"american 0.0016265200216869337",
"do 0.0019363333591511116",
"products 0.0013941600185888002",
"microchip 8.51986678026489E-4",
"chips 0.001858880024785067",
"united 0.004182480055766401",
"signed 8.51986678026489E-4",
"officials 0.004337386724498489",
"come 0.0011618000154906669",
"electronic 0.0013941600185888002",
"imports 0.003872666718302223",
"u 0.01510340020137867",
"s 0.014871040198280536",
"world 0.0026334133684455118",
"to 0.049182867322438234",
"congress 0.001703973356052978",
"countertrade 7.745333436604446E-4",
"has 0.004569746727596623",
"semiconductor 0.002555960034079467",
"-japan 9.294400123925335E-4",
"his 0.0023236000309813337",
"would 0.007435520099140268",
"microchips 9.294400123925335E-4",
"action 0.002401053365347378",
"tokyo 0.002710866702811556",
"official 0.0034854000464720008",
"live 8.51986678026489E-4",
"300 0.0011618000154906669",
"dispute 0.002401053365347378",
"white 0.0012392533498567114",
"japanese 0.009139493455193246",
"that 0.011695453489272712",
"retaliation 0.001703973356052978",
"failure 0.0011618000154906669",
"pact 0.0020912400278832004",
"japan's 0.002710866702811556",
"makers 0.0010843466811246223",
"talks 0.0015490666873208892",
"output 7.745333436604446E-4",
"administration 7.745333436604446E-4",
"gatt 0.0010843466811246223",
"stop 0.0010843466811246223",
"trade 0.019595693594609248",
"issue 9.294400123925335E-4",
"goods 0.002710866702811556",
"baldrige 0.001006893346758578",
"chirac 8.51986678026489E-4",
"war 0.0027883200371776004",
"japan 0.009914026798853691",
"chip 0.002865773371543645",
"is 0.008364960111532802",
"export 8.51986678026489E-4",
"agreement 0.0033304933777399117",
"expected 0.0014716133529548447",
"yeutter 0.0010843466811246223",
"democratic 9.294400123925335E-4",
"act 8.51986678026489E-4",
"yasuhiro 0.001006893346758578",
};
char buf[1100000];
map<string, double> ma[3];
double p[10];
int sel;
int main() {
for (int i = 0; i < (int)(3 * C); i++) {
double x;
sscanf(cat[i].c_str(), "%s%lf", buf, &x);
ma[i / C][buf] = x;
}
gets(buf);
string text;
while (gets(buf)) {
text += buf;
text += ' ';
}
for (int i = 0; i < (int)(text.size()); i++)
if (DELIMS.find(text[i]) != string::npos) text[i] = ' ';
stringstream ss;
ss << text;
string tok;
while (ss >> tok) {
for (int i = 0; i < (int)(tok.size()); i++) tok[i] = tolower(tok[i]);
for (int i = 0; i < (int)(3); i++)
if (ma[i].count(tok))
p[i] += log(ma[i][tok]);
else
p[i] += log(1E-6);
}
sel = 1;
for (int i = (int)(3) - 1; i >= 0; i--)
if (p[i] > p[sel] + EPS) sel = i;
cout << sel + 1 << endl;
return 0;
}
| 10 | CPP |
x = str(input())
y = str(input())
print(x.count(y)) | 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline bool eps_dayu(const T &a, const T &b) {
return (a - b) > 1e-10 ? 1 : 0;
}
template <typename T>
inline bool eps_dengyu(const T &a, const T &b) {
if (a - b > 1e-10 || b - a > 1e-10) return 0;
return 1;
}
template <typename T>
inline bool eps_xiaoyu(const T &a, const T &b) {
return b - a > 1e-10 ? 1 : 0;
}
string x, y;
bool solve(int t, int cntx, int cnty) {
if (cntx == 0 && cnty == 0) return 1;
if (cntx) {
if (x[t] < '4') {
int m = t;
for (int i = 0; i < cntx; i++) y[m++] = '4';
for (int i = 0; i < cnty; i++) y[m++] = '7';
return 1;
} else if (x[t] == '4' && solve(t + 1, cntx - 1, cnty)) {
y[t] = '4';
return 1;
}
}
if (cnty) {
if (x[t] < '7') {
int m = t;
y[m++] = '7';
cnty--;
for (int i = 0; i < cntx; i++) y[m++] = '4';
for (int i = 0; i < cnty; i++) y[m++] = '7';
return 1;
} else if (x[t] == '7' && solve(t + 1, cntx, cnty - 1)) {
y[t] = '7';
return 1;
}
}
return 0;
}
int main() {
cin >> x;
int len = x.length();
int tt = len % 2;
if (tt) x = "0" + x;
while (true) {
y = x;
int len = x.length() / 2;
if (solve(0, len, len)) {
cout << y << endl;
return 0;
}
x = "00" + x;
}
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using std::cin;
using std::cout;
const int MAX_N = 1000000;
const int BASE = 10;
const int P = 1000000007;
int n;
char a[1 + MAX_N];
long long prefHash[1 + MAX_N], baseHash[1 + MAX_N];
long long getHash(int begin, int end) {
return (prefHash[end] + P - prefHash[begin] * baseHash[end - begin] % P) % P;
}
long long getHashA(int pozPlus) { return getHash(0, pozPlus); }
long long getHashB(int pozPlus, int pozEgal) {
return getHash(pozPlus, pozEgal);
}
long long getHashC(int pozEgal) { return getHash(pozEgal, n); }
void afis(int pozPlus, int pozEgal) {
for (int i = 1; i <= n; i++) {
cout << a[i];
if (i == pozPlus) cout << "+";
if (i == pozEgal) cout << "=";
}
}
bool verif(int pozPlus, int pozEgal) {
if (pozEgal != pozPlus &&
((std::max(pozPlus, pozEgal - pozPlus) + 1 == n - pozEgal) ||
(std::max(pozPlus, pozEgal - pozPlus) == n - pozEgal)))
return (getHashA(pozPlus) + getHashB(pozPlus, pozEgal)) % P ==
getHashC(pozEgal);
return false;
}
int main() {
cin.get(a + 1, MAX_N + 1, '\n');
n = strlen(a + 1);
for (int k = 1; k <= n; k++)
prefHash[k] = (prefHash[k - 1] * 10 + a[k] - '0') % P;
baseHash[0] = 1;
for (int e = 1; e <= n; e++) baseHash[e] = baseHash[e - 1] * BASE % P;
for (int pozEgal = (n + 1) / 2; pozEgal < n; pozEgal++) {
int pozPlus;
if (a[pozEgal + 1] == '0' && n - pozEgal != 1) continue;
pozPlus = n - pozEgal;
if ((a[pozPlus + 1] != '0' || pozEgal - pozPlus == 1) &&
verif(pozPlus, pozEgal)) {
afis(pozPlus, pozEgal);
cout << '\n';
break;
}
pozPlus = n - pozEgal - 1;
if (pozPlus > 0 && (a[pozPlus + 1] != '0' || pozEgal - pozPlus == 1) &&
verif(pozPlus, pozEgal)) {
afis(pozPlus, pozEgal);
cout << '\n';
break;
}
pozPlus = pozEgal - (n - pozEgal);
if (pozPlus > 0 && (a[pozPlus + 1] != '0' || pozEgal - pozPlus == 1) &&
verif(pozPlus, pozEgal)) {
afis(pozPlus, pozEgal);
cout << '\n';
break;
}
pozPlus = pozEgal - (n - pozEgal) + 1;
if ((a[pozPlus + 1] != '0' || pozEgal - pozPlus == 1) &&
verif(pozPlus, pozEgal)) {
afis(pozPlus, pozEgal);
cout << '\n';
break;
}
}
return 0;
}
| 12 | CPP |
#include <bits/stdc++.h>
using namespace std;
namespace IO {
const int SIZE = 1 << 20;
char buf[SIZE + 10], *iS, *iT;
inline char Getc() {
return iS == iT && (iT = (iS = buf) + fread(buf, 1, SIZE, stdin), iS == iT)
? EOF
: *iS++;
}
template <class TT>
inline void Read(TT &x) {
x = 0;
register char cc = '\0';
TT fff = 1;
for (; cc < '0' || cc > '9'; cc = Getc())
if (cc == '-') fff = -1;
for (; cc >= '0' && cc <= '9'; cc = Getc())
x = (x << 1) + (x << 3) + (cc & 15);
x *= fff;
}
} // namespace IO
using IO::Read;
const int N = 2e5 + 10, M = 4e5 + 10;
struct Edge {
int u, v, w;
} E[N];
long long dis[3][N];
int lnum[N], rnum[N], dfn[M];
int n, m, q, tot, prep[N], pree[N], Head[N], Next[M], Adj[M], Num[M], W[M];
struct Node {
int pt;
long long dt;
bool operator<(const Node &Other) const {
return dt == Other.dt ? pt > Other.pt : dt > Other.dt;
}
};
priority_queue<Node> Q;
bool visp[N];
long long Tree[N << 2], Lazy[N << 2];
void Dijkstra(int stp, int stnum) {
while (!Q.empty()) Q.pop();
memset(dis[stnum], 0x3f, sizeof(dis[stnum]));
dis[stnum][stp] = 0LL;
Q.push((Node){stp, 0LL});
while (!Q.empty()) {
Node x = Q.top();
Q.pop();
if (x.dt != dis[stnum][x.pt]) continue;
for (int e = Head[x.pt]; e; e = Next[e])
if (dis[stnum][Adj[e]] > dis[stnum][x.pt] + W[e]) {
dis[stnum][Adj[e]] = dis[stnum][x.pt] + W[e];
prep[Adj[e]] = x.pt, pree[Adj[e]] = Num[e];
Q.push((Node){Adj[e], dis[stnum][Adj[e]]});
if (stnum == 1 && !visp[Adj[e]]) lnum[Adj[e]] = lnum[x.pt];
if (stnum == 2 && !visp[Adj[e]]) rnum[Adj[e]] = rnum[x.pt];
}
}
}
inline void Prepare1() {
int pt = 1, ctt = 0;
while (pt != n) {
visp[pt] = true;
lnum[pt] = rnum[pt] = ctt++;
dfn[pree[pt]] = ctt;
pt = prep[pt];
}
visp[n] = true;
lnum[n] = rnum[n] = ctt;
}
inline void Pushup(int x) { Tree[x] = min(Tree[(x << 1)], Tree[(x << 1 | 1)]); }
inline void Pushdown(int x) {
Tree[(x << 1)] = min(Tree[(x << 1)], Lazy[x]);
Tree[(x << 1 | 1)] = min(Tree[(x << 1 | 1)], Lazy[x]);
Lazy[(x << 1)] = min(Lazy[(x << 1)], Lazy[x]);
Lazy[(x << 1 | 1)] = min(Lazy[(x << 1 | 1)], Lazy[x]);
}
void Update(int el, int er, long long ad, int x = 1, int nl = 1,
int nr = rnum[n]) {
if (el <= nl && nr <= er) {
Tree[x] = min(Tree[x], ad);
Lazy[x] = min(Lazy[x], ad);
return;
}
int nm = (nl + nr) >> 1;
Pushdown(x);
if (el <= nm) Update(el, er, ad, (x << 1), nl, nm);
if (er > nm) Update(el, er, ad, (x << 1 | 1), nm + 1, nr);
Pushup(x);
}
long long Query(int el, int er, int x = 1, int nl = 1, int nr = rnum[n]) {
if (el <= nl && nr <= er) return Tree[x];
int nm = (nl + nr) >> 1;
Pushdown(x);
long long qsum = 0x3f3f3f3f3f3f3f3fLL;
if (el <= nm) qsum = min(qsum, Query(el, er, (x << 1), nl, nm));
if (er > nm) qsum = min(qsum, Query(el, er, (x << 1 | 1), nm + 1, nr));
return qsum;
}
inline long long Solve(int x) { return Query(dfn[x], dfn[x]); }
int main() {
memset(Tree, 0x3f, sizeof(Tree));
memset(Lazy, 0x3f, sizeof(Lazy));
memset(lnum, -1, sizeof(lnum));
memset(rnum, -1, sizeof(rnum));
Read(n), Read(m), Read(q);
for (int i = 1, x, y, z; i <= m; ++i) {
Read(x), Read(y), Read(z);
Next[++tot] = Head[x];
Head[x] = tot;
Adj[tot] = y;
W[tot] = z;
Num[tot] = i;
Next[++tot] = Head[y];
Head[y] = tot;
Adj[tot] = x;
W[tot] = z;
Num[tot] = i;
E[i] = (Edge){x, y, z};
}
Dijkstra(n, 0);
Prepare1();
Dijkstra(1, 1);
Dijkstra(n, 2);
for (int i = 1; i <= m; ++i)
if (!dfn[i]) {
if ((~lnum[E[i].u]) && (~rnum[E[i].v]) && lnum[E[i].u] < rnum[E[i].v])
Update(lnum[E[i].u] + 1, rnum[E[i].v],
dis[1][E[i].u] + E[i].w + dis[2][E[i].v]);
if ((~lnum[E[i].v]) && (~rnum[E[i].u]) && lnum[E[i].v] < rnum[E[i].u])
Update(lnum[E[i].v] + 1, rnum[E[i].u],
dis[1][E[i].v] + E[i].w + dis[2][E[i].u]);
}
while (q--) {
int x;
long long y;
Read(x), Read(y);
if (min(dis[1][E[x].v] + dis[2][E[x].u] + y,
dis[1][E[x].u] + dis[2][E[x].v] + y) <= dis[1][n]) {
printf("%lld\n", min(dis[1][E[x].v] + dis[2][E[x].u] + y,
dis[1][E[x].u] + dis[2][E[x].v] + y));
continue;
} else if (!dfn[x]) {
printf("%lld\n", dis[1][n]);
continue;
} else {
printf("%lld\n", min(min(dis[1][E[x].v] + dis[2][E[x].u] + y,
dis[1][E[x].u] + dis[2][E[x].v] + y),
Solve(x)));
continue;
}
}
return 0;
}
| 12 | CPP |
#include<cstdio>
#include<cstring>
#include<queue>
#include<vector>
using namespace std;
vector<int> V[100005];
bool vis[100005] = {};//记录是否被标记
int flag[100005] = {};//记录最近的祖先
void add(int ind){
if(vis[ind])
return ;
vis[ind] = 1;
queue<int>Q;
Q.push(ind);
while(!Q.empty()){
int t = Q.front();Q.pop();
flag[t] = ind;
for(int i=V[t].size()-1;i>=0;i--){
if(vis[V[t][i]])
continue ;
Q.push(V[t][i]);
}
}
return ;
}
int main(){
int N, Q, x;
char str[15];
while(scanf("%d%d",&N,&Q),N|Q){
long long ans = 0;
memset(vis,0,sizeof(vis));
memset(flag,0,sizeof(flag));
for(int i=1;i<100005;i++){
V[i].clear();
}
for(int i=2;i<=N;i++){
scanf("%d",&x);
V[x].push_back(i);
}
add(1);
for(int i=0;i<Q;i++){
scanf("%s%d",str,&x);
if(str[0] == 'Q'){
ans += flag[x];
}else {
add(x);
}
}
printf("%lld\n",ans);
}
return 0;
}
| 0 | CPP |
a = [int(i) for i in input()]
tmp = max(a)
ans = []
for i in range(tmp):
temp = []
for i in range(len(a)):
if a[i] > 0:
a[i] -= 1
temp.append("1")
else:
temp.append("0")
ans.append(int("".join(temp)))
print(len(ans))
for i in ans:
print(i, end=" ")
| 8 | PYTHON3 |
#include<bits/stdc++.h>
#define M 1000000007
#define N 100005
using namespace std;
typedef long long ll;
ll n,r,s,t,d[N],A[N];
int bit[N];
int sum(int i){
int s=0;
while(i>0){
s+=bit[i];
i-=i&-i;
}
return s;
}
void add(int i,int x){
while(i<=n){
bit[i]+=x;
i+=i&-i;
}
}
int main(){
A[0]=A[1]=1;
for(int i=2;i<N;i++)
A[i]=(A[i-1]*i)%M;
while(1){
cin>>n;
if(!n)break;
for(int i=0;i<n;i++)d[i]=i+1;
cin>>r;
for(int i=0;i<r;i++){
cin>>s>>t;
swap(d[s-1],d[t-1]);
}
memset(bit,0,sizeof(bit));
ll ans=0;
for(int i=0;i<n-1;i++){
ans=(ans+((d[i]-sum(d[i])-1)*A[n-i-1])%M)%M;
add(d[i],1);
}
cout<<ans<<endl;
}
return 0;
} | 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)n; i++)
using ll = long long;
int main(){
int n;
cin >> n;
ll a[n];
rep(i,n) cin >> a[i];
ll c = 0, d = 0, s = 0, t = 0;
rep(i,n) {
s += a[i]; t += a[i];
if(i % 2 == 0) {
if(s <= 0) {
c += 1 - s;
s = 1;
}
if(t >= 0) {
d += t + 1;
t = -1;
}
} else {
if(s >= 0) {
c += s + 1;
s = -1;
}
if(t <= 0) {
d += 1 - t;
t = 1;
}
}
}
cout << min(c,d) << endl;
return 0;
} | 0 | CPP |
#include <bits/stdc++.h>
inline void inp(long long int &n) {
n = 0;
int ch = getchar();
int sign = 1;
while (ch < '0' || ch > '9') {
if (ch == '-') sign = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9')
n = (n << 3) + (n << 1) + ch - '0', ch = getchar();
n = n * sign;
}
long long int add(long long int a, long long int b) {
return a + b - (a + b >= 1000000007) * 1000000007;
}
long long int sub(long long int a, long long int b) {
return a - b + (a - b < 0) * 1000000007;
}
long long int mult(long long int a, long long int b) {
return (1LL * a * b) % 1000000007;
}
inline long long int gcd(long long int a, long long int b) {
long long int t;
while (b) {
a = a % b;
t = a;
a = b;
b = t;
}
return a;
}
long long int exponentmod(long long int a, long long int b) {
long long int res = 1;
a %= 1000000007;
assert(b >= 0);
for (; b; b >>= 1) {
if (b & 1) res = res * a % 1000000007;
a = a * a % 1000000007;
}
return res;
}
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
long long int n;
cin >> n;
long long int deg[n], xorsum[n];
queue<long long int> Q1;
long long int used = 0;
for (long long int i = 0; i < n; i++) {
cin >> deg[i] >> xorsum[i];
if (deg[i] == 1) {
Q1.push(i);
}
if (deg[i] == 0) {
used++;
}
}
vector<pair<long long int, long long int> > v1;
while (Q1.empty() == false) {
long long int from = Q1.front();
used++;
Q1.pop();
if (deg[from] == 0) {
continue;
}
deg[from]--;
long long int to = xorsum[from];
xorsum[from] = 0;
v1.push_back(make_pair(from, to));
xorsum[to] ^= from;
deg[to]--;
if (deg[to] == 1) {
Q1.push(to);
}
}
cout << v1.size() << endl;
for (auto itr = v1.begin(); itr != v1.end(); itr++) {
cout << (*itr).first << " " << (*itr).second << endl;
}
return 0;
}
| 7 | CPP |
n,c = list(map(int, input().split()))
t = list(map(int, input().split()))
cont = 0
prev = t[0]
for i in t:
if cont == 0:
cont += 1
else:
if i - prev > c:
cont = 1
else:
cont += 1
prev = i
print(cont)
| 7 | PYTHON3 |
#include<iostream>
using namespace std;
int main(){
int n,i,k,x;cin >> n;
int prime[997] = {};
for(i=1;i<=n;i++){
x = i;
for(k=2;k<=x;k++){
while(x%k==0){
prime[k-1]++;x /= k;
}
}
}
long long ans = 1;
for(i=0;i<997;i++) ans = (ans*(prime[i]+1))%1000000007;
cout << ans << endl;
}
| 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, ans = 0;
cin >> n;
long long int A[n];
for (int i = 0; i < n; i++) cin >> A[i];
sort(A, A + n);
long long int sum = A[0];
ans++;
for (int i = 1; i < n; i++) {
if (A[i] >= sum) {
sum += A[i];
ans++;
}
}
cout << ans;
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
int mini(int a, int b) {
if (a < b) return a;
return b;
}
long long int minl(long long int a, long long int b) {
if (a < b) return a;
return b;
}
long long int maxl(long long int a, long long int b) {
if (a > b) return a;
return b;
}
long long int power(long long int a, long long int n) {
long long int ans = 1;
while (n) {
if (n % 2 == 0) {
a = (a * a);
n = n / 2;
} else {
ans = (ans * a);
n--;
}
}
return ans;
}
void swap(int& a, int& b) {
int temp = a;
a = b;
b = a;
return;
}
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) cin >> a[i];
int f = 0;
int i = n - 1;
while (i >= 1) {
if (f == 0) {
if (a[i - 1] >= a[i])
i--;
else
f = 1;
} else if (f == 1) {
if (a[i - 1] <= a[i])
i--;
else
break;
}
}
cout << i << endl;
}
}
| 9 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
int a, x, b, y, n;
int next_x(int x) {
if (x == n)
return 1;
else
return x + 1;
}
int next_y(int x) {
if (x == 1)
return n;
else
return x - 1;
}
int main() {
ios::sync_with_stdio(0);
cin >> n >> a >> x >> b >> y;
while (a != x && b != y) {
if (a == b) {
puts("YES");
return 0;
}
a = next_x(a);
b = next_y(b);
if (a == b) {
puts("YES");
return 0;
}
}
puts("NO");
return 0;
}
| 7 | CPP |
for Z in range(int(input())):
n = int(input())
di = {} #Dictionary-> Key: Tuple(position) and Value: Index at which it is attained
di[(0,0)] = 0
m = n+10
a = -1
b = -1
s = input()
s = 'X' + s
curPos = (0,0)
ind = 1
for i in s[1:]:
li = list(curPos)
if(i == 'L'):
li[0] -= 1
if(i == 'R'):
li[0] += 1
if(i == 'U'):
li[1] += 1
if(i == 'D'):
li[1] -= 1
curPos = tuple(li)
if(curPos in di):
oldPosInd = di[curPos]
if( (ind-oldPosInd)<m):
m = ind-oldPosInd
a = oldPosInd+1
b = ind
di[curPos] = ind
#print(i , curPos , di , m)
ind += 1
if(m == n+10):
print('-1')
else:
print(a,b) | 9 | PYTHON3 |
s=input()
a=s.split(' ')
n,m=int(a[0]),int(a[1])
k=0
while n>0:
n-=1
s=input()
a=s.split(' ')
for j in range(1,m+1):
if (a[2*j-2]=='1') or (a[2*j-1]=='1'):
k+=1
print(k)
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n;
cin >> n;
n++;
if (n == 1) {
cout << 0 << endl;
} else if (n % 2)
cout << n << endl;
else
cout << n / 2 << endl;
return 0;
}
| 7 | CPP |
n= int(input())
gifts = list(map(int,input().split()))
l = [0]*len(gifts)
for index,i in enumerate(gifts):
l[i-1] = index+1
print(*l) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
char toUpper(const char &c) { return isupper(c) ? c : c - 'a' + 'A'; }
char toLower(const char &c) { return islower(c) ? c : c + 'a' - 'A'; }
bool isvowel(char c) {
c = toLower(c);
return (c == 'a' or c == 'e' or c == 'i' or c == 'i' or c == 'o' or
c == 'u' || c == 'y');
}
void toLowerCase(string &s) {
for (long long i = 0; i < s.size(); i++) {
if (!islower(s[i])) {
s[i] = tolower(s[i]);
}
}
}
void toUpperCase(string &s) {
for (long long i = 0; i < s.size(); i++) {
s[i] = toupper(s[i]);
}
}
bool ispal(string s) {
long long lo, hi;
lo = 0;
hi = s.length() - 1;
while (lo <= hi) {
if (s[lo] != s[hi]) {
return 0;
}
lo++;
--hi;
}
return 1;
}
template <class T>
string toString(T n) {
string v = "";
while (n) {
v.push_back(n % 10 + '0');
n /= 10;
}
reverse(v.begin(), v.end());
return v;
}
template <typename t>
t gcd(t a, t b) {
a = abs(a), b = abs(b);
return ((b == 0) ? a : gcd(b, a % b));
}
template <typename t>
t lcm(t a, t b) {
return (a * (b / gcd(a, b)));
}
template <typename T>
T modpow(T base, T exp, T modulus) {
base %= modulus;
T result = 1;
while (exp > 0) {
if (exp & 1) result = (result * base) % modulus;
base = (base * base) % modulus;
exp >>= 1;
}
return result;
}
template <typename T>
void cumulative(T *a, T *b, T n) {
for (long long i = 0; i < n; i++) {
i ? b[i] = b[i - 1] + a[i] : b[i] = a[i];
}
}
const int inf = 1e9 + 7;
const double eps = 1e-6;
const double pi = 1.00 * acos(-1.00);
void solve() {
long long t;
cin >> t;
while (t--) {
string s;
cin >> s;
sort(s.begin(), s.end());
bool ok = 1;
for (int i = 0; i < s.size() - 1; i++) {
if (s[i + 1] - s[i] != 1) {
ok = 0;
break;
}
}
if (!ok) {
cout << "No\n";
} else {
cout << "Yes\n";
}
}
}
int main() {
std::ios::sync_with_stdio(0);
cin.tie(0);
long long t = 1;
while (t--) {
solve();
}
}
| 7 | CPP |
def mx(v):
s,m=0,0
for x in v:
if x<0 and s>m:
m=s
s+=x
return m
v=[]
n=int(input())
for _ in range(n):
nt,nx=[int(x) for x in input().split()]
v.append(nx-nt)
print(mx(v)) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int p[100010];
int cnt;
int solve0(int n) {
if (n == 1) return ++cnt;
int l = solve0(n / 2), r = solve0(n / 2);
p[l] = p[r] = cnt + 1;
return ++cnt;
}
int solve1(int n) {
int base = 1 << (31 - __builtin_clz(n)), l, r;
if (n + 1 == base * 3 / 2)
l = solve0(base - 1), r = solve0(base / 2 - 1);
else if ((base / 2) & n)
l = solve0(base - 1), r = solve1(n - base);
else
l = solve0(base / 2 - 1), r = solve1(n - base / 2);
p[l] = p[r] = cnt + 1;
return ++cnt;
}
int solve(int n, int k) {
if (k == 1) return solve1(n);
int rem = n - (k - 1) * 2;
if (rem & (rem + 1)) {
int s = solve(n - 2, k - 1);
p[s] = cnt + 1;
p[cnt + 2] = cnt + 1;
cnt += 2;
return p[s];
} else {
int s = solve(n - 4, k - 1);
p[s] = cnt + 1;
p[cnt + 2] = cnt + 1;
p[cnt + 3] = p[cnt + 4] = cnt + 2;
cnt += 4;
return p[s];
}
}
void fail() {
cout << "NO" << endl;
exit(0);
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, k;
cin >> n >> k;
if (n == 9 && k == 2) fail();
if (n % 2 == 0) fail();
if (k == 0) {
if (n & (n + 1)) fail();
cout << "YES" << endl;
for (int i = 1; i <= n; i++) cout << (i / 2) << ' ';
return 0;
}
if (k == 1 && !(n & (n + 1))) fail();
if ((n - 3) / 2 < k) fail();
cout << "YES" << endl;
solve(n, k);
for (int i = 1; i <= n; i++) cout << p[i] << ' ';
cout << endl;
}
| 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
if (b == 0) {
return a;
}
return gcd(b, a % b);
}
int a[300005];
bool notprime[8000005];
map<int, int> prims;
vector<int> primes;
void factor(int num) {
for (int i = 0; i < primes.size() && primes[i] * primes[i] <= num; i++) {
if (num % primes[i] == 0) {
prims[primes[i]]++;
while (num % primes[i] == 0) {
num /= primes[i];
}
if (num == 1) {
break;
}
}
}
if (num != 1) prims[num]++;
}
int main() {
std::ios_base::sync_with_stdio(false);
notprime[0] = true;
notprime[1] = true;
int i;
for (i = 2; i * i <= 8000005; i++) {
if (!notprime[i]) {
primes.push_back(i);
for (int j = i * i; j < 8000005; j += i) {
notprime[j] = true;
}
}
}
for (; i < 8000005; i++) {
if (!notprime[i]) primes.push_back(i);
}
int n;
cin >> n;
int commgcd;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (i == 0)
commgcd = a[i];
else
commgcd = gcd(a[i], commgcd);
}
for (int i = 0; i < n; i++) {
factor(a[i] / commgcd);
}
int maxprim = -1;
for (auto par : prims) {
if (par.second > maxprim) {
maxprim = par.second;
}
}
if (maxprim == -1)
cout << -1 << endl;
else
cout << n - maxprim << endl;
}
| 7 | CPP |
#include <iostream>
#include <algorithm>
#include <array>
#include <cstdint>
#include <functional>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string>
#include <utility>
#include <vector>
#define INF 1000000000
#define MOD 1000000007
#define rep(i,a,b) for(uint32 i = (a); i < (b); ++i)
#define bitget(a,b) (((a) >> (b)) & 1)
#define ALL(x) (x).begin(),(x).end()
#define C(x) std::cout << #x << " : " << x << std::endl
#define scanf scanf_s
using int32 = std::int_fast32_t;
using int64 = std::int_fast64_t;
using uint32 = std::uint_fast32_t;
using uint64 = std::uint_fast64_t;
template<typename T>
class hashmap64 {
std::vector<std::pair<uint64, T>> map;
uint64 mask, count, temp;
uint64 hash64(uint64 key) {
key = ~key;
key ^= key << 13;
key ^= key >> 19;
return key ^ (key << 17);
}
public:
hashmap64() :map(8192, std::make_pair(~static_cast<std::uint_fast64_t>(0), T())) {
mask = 8191; count = 0;
}
hashmap64(size_t s) {
s |= s << 1;
s |= s >> 2;
s |= s >> 4;
s |= s >> 8;
s |= s >> 16;
s |= s >> 32;
mask = s;
count = 0;
map.resize(s + 1, std::make_pair(~static_cast<std::uint_fast64_t>(0), T()));
}
T &operator[](uint64 suf) {
temp = mask&hash64(suf);
while (map[temp].first != suf) {
temp = mask&(temp + 1);
}
return map[temp].second;
}
void insert(uint64 key, const T &value) {
temp = mask&hash64(key);
while (~map[temp].first) {
if (map[temp].first == key) {
map[temp].second = value;
return;
}
temp = mask&(temp + 1);
}
map[temp] = std::make_pair(key, value);
++count;
if ((count << 1) > mask) {
std::pair<uint64, T> mkey;
mask = mask << 1 | 1;
map.resize(mask + 1, std::make_pair(~static_cast<std::uint_fast64_t>(0), T()));
for (uint64 t = 0;t <= mask >> 1;++t) {
if (!~map[t].first) {
mkey = map[t];
map[t].first = ~0;
temp = mask&hash64(mkey.first);
while (~map[temp].first) {
temp = mask&(temp + 1);
}
map[temp] = mkey;
}
}
}
return;
}
bool find(uint64 key) {
temp = mask&hash64(key);
while (~map[temp].first) {
if (map[temp].first == key) {
return true;
}
temp = mask&(temp + 1);
}
return false;
}
bool empty(void) {
return !count;
}
size_t size(void) {
return count;
}
};
int main(void) {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
hashmap64<uint32> map(100000);
uint32 n;
std::cin >> n;
int64 a, sum = 1e15;
uint32 ans = 0;
map.insert(sum, 0);
rep(i, 0, n) {
std::cin >> a;
sum += a;
if (map.find(sum)) {
ans = std::max(ans, i + 1 - map[sum]);
}
else {
map.insert(sum, i + 1);
}
}
std::cout << ans << "\n";
return 0;
} | 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
string a, b;
cin >> a >> b;
string c;
c.assign(b.size() - 1, '$');
a = c + a + c;
int ans = numeric_limits<int>::max();
for (int i = 0; i < a.size() - b.size() + 1; ++i) {
int cur = 0;
for (int j = 0; j < b.size(); ++j)
if (a[i + j] != b[j]) cur++;
ans = min(ans, cur);
}
cout << ans << endl;
return 0;
}
| 9 | CPP |
k=0
a=int(input())
for i in range(a):
b=str(input())
if b=='Tetrahedron':
k+=4
elif b=='Cube':
k+=6
elif b=="Octahedron":
k+=8
elif b=='Dodecahedron':
k+=12
else:
k+=20
print(k)
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int mod = (int)1e9 + 7;
int n, m, X;
int f[2][350][350], sw;
int Ans;
void dpto(int x, int& a) {
if (a += x, a >= mod) a -= mod;
}
void trans(int x, int a[][350], int b[][350]) {
for (int i = 0; i <= n; i++)
for (int j = 0; j <= n; j++) b[i][j] = 0;
for (int i = 0; i <= n; i++)
for (int j = 0; j <= n; j++)
if (a[i][j]) {
dpto(a[i][j], b[i + 1][j + 1]);
if (j) dpto(a[i][j], b[i + 1][j]);
if (x == X) continue;
dpto(a[i][j], b[i][j]);
if (j) dpto(a[i][j], b[i][j - 1]);
}
}
int main() {
scanf("%d%d%d", &n, &m, &X);
if (n > m) {
printf("0\n");
return 0;
}
f[sw][0][0] = 1;
for (int i = 1; i <= m; i++) trans(i, f[sw], f[sw ^ 1]), sw ^= 1;
Ans = (f[sw][n][0] + f[sw][n][1]) % mod;
for (int i = 1; i <= n; i++) Ans = (long long)Ans * i % mod;
printf("%d\n", Ans);
}
| 11 | CPP |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.