solution
stringlengths 10
159k
| difficulty
int64 0
3.5k
| language
stringclasses 2
values |
---|---|---|
#include <bits/stdc++.h>
using namespace std;
int main() {
long int n, m, i, j;
char a[1000][1000];
cin >> n >> m;
for (i = 1; i <= n; i++) {
for (j = 1; j <= m; j++) {
cin >> a[i][j];
}
}
for (i = 1; i <= n; i++) {
for (j = 1; j <= m; j++) {
if (a[i][j] == 'C' || a[i][j] == 'M' || a[i][j] == 'Y') {
cout << "#Color";
return 0;
}
}
}
cout << "#Black&White";
}
| 800 | CPP |
mass = int(input())
num = []
def listNum(m):
a = 2
b = 0
for i in range(m):
num.append(i+1)
for j in range(len(num)):
if num[j] % a == 0:
b = num[j]
if b+a == m:
print("Yes")
break
elif j == len(num)-1:
print("No")
elif j == len(num)-1:
print("No")
listNum(mass)
| 800 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
scanf("%d", &n);
int q = int(sqrt(double(n)));
while (n % q) q--;
printf("%d %d\n", q, n / q);
}
| 800 | CPP |
import math
n,k=[int(x) for x in input().split()];
y=[int(x) for x in input().split()];
num_part=0;
for i in range(n):
if y[i]+k<=5:
num_part+=1;
print(math.floor(num_part/3)); | 800 | PYTHON3 |
import sys
input = lambda: sys.stdin.readline().rstrip()
inp = sys.stdin.buffer.readline
def I(): return list(map(int,inp().split()))
for _ in range(int(input())):
n,m,x,y=map(int,input().split())
a=[[]]
for i in range(n):
if a[-1]: a.append([])
cur=0
for j in input():
if j=='.':
cur+=1
elif j=='*':
if cur: a[-1].append(cur)
cur=0
if cur%2==0 and cur!=0:
a[-1].append(2)
cur=0
if cur: a[-1].append(cur)
if 2*x<=y:
summ=0
for i in range(len(a)):
summ+=sum(a[i])*x
print(summ)
else:
summ=0
for i in range(len(a)):
for j in range(len(a[i])):
if a[i][j]==1: summ+=x
else: summ+=y
print(summ)
| 1,000 | PYTHON3 |
abc = []
nums = [int(x) for x in input().split()]
nums.sort()
for i in range(len(nums)-1):
abc.append(nums[3]-nums[i])
print(*abc, sep = " ") | 800 | PYTHON3 |
from collections import *
from operator import *
myname, n, mem = input(), int(input()), defaultdict(int)
for i in range(n):
s, val = input().split(), 0
x, y = s[0], s[3][:-2]
if s[1] == 'posted':
val = 15
elif s[1] == 'commented':
val = 10
else:
val = 5
y = s[2][:-2]
if x == myname:
mem[y] += val
elif y == myname:
mem[x] += val
else:
if not mem[x]:
mem[x] = 0
if not mem[y]:
mem[y] = 0
ans = sorted(list(mem.items()), reverse=True, key=itemgetter(1, 0))
mem = defaultdict(list)
for i, j in ans:
mem[j].append(i)
for i, j in mem.items():
for k in j[::-1]:
print(k)
| 1,500 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
unsigned int inet4[100010];
int main(int argc, char* argv[]) {
ios_base::sync_with_stdio(false);
int n, m;
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i++) {
char* str;
int inet[4];
scanf("%d.%d.%d.%d", &inet[0], &inet[1], &inet[2], &inet[3]);
inet4[i] = 0;
for (int j = 0; j < 4; j++) inet4[i] = inet4[i] * 256 + inet[j];
}
unsigned int mask = 0x80000000;
bool flag = false;
for (int i = 1; i < 32; i++) {
set<int> hh;
for (int j = 0; j < n; j++) {
hh.insert(inet4[j] & mask);
}
if (hh.size() == m) {
int ans[4];
for (int j = 3; j >= 0; j--) {
ans[j] = mask % 256;
mask /= 256;
}
printf("%d.%d.%d.%d\n", ans[0], ans[1], ans[2], ans[3]);
flag = true;
break;
}
mask = mask | (mask >> 1);
}
if (!flag) printf("-1\n");
return 0;
}
| 1,600 | CPP |
"""
Author: Q.E.D
Time: 2020-06-13 10:45:25
"""
T = int(input())
for _ in range(T):
n = int(input())
a = list(map(int, input().split()))
d = 1 if a[1] > a[0] else -1
c = a[1]
ans = [a[0]]
for i in range(1, n):
if d == 1:
if a[i] > a[i - 1]:
c = a[i]
else:
ans.append(c)
d = -1
c = a[i]
else:
if a[i] < a[i - 1]:
c = a[i]
else:
ans.append(c)
d = 1
c = a[i]
ans.append(c)
print(len(ans))
print(' '.join(map(str, ans)))
| 1,300 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
vector<int> adj[100005];
int level[100005];
bool vis[100005];
int bfs_node(int source) {
memset(vis, 0, sizeof(vis));
;
queue<int> vc;
int a, b, mx = 0, id = 0;
level[source] = 0;
vis[source] = 1;
vc.push(source);
while (!vc.empty()) {
a = vc.front();
vc.pop();
for (int i = 0; i < adj[a].size(); i++) {
b = adj[a][i];
if (vis[b] == 0) {
level[b] = level[a] + 1;
vis[b] = 1;
vc.push(b);
if (mx <= level[b]) {
mx = level[b];
id = b;
}
}
}
}
return id;
}
int bfs(int source) {
memset(vis, 0, sizeof(vis));
;
queue<int> vc;
int a, b, mx = 0;
level[source] = 0;
vis[source] = 1;
vc.push(source);
while (!vc.empty()) {
a = vc.front();
vc.pop();
for (int i = 0; i < adj[a].size(); i++) {
b = adj[a][i];
if (vis[b] == 0) {
level[b] = level[a] + 1;
mx = max(level[b], mx);
vis[b] = 1;
vc.push(b);
}
}
}
return mx;
}
int main() {
int n, m, s;
cin >> n >> m;
for (int i = 0; i < 100005; i++) adj[i].clear();
;
memset(level, 0, sizeof(level));
;
for (int i = 1; i <= m; i++) {
int a, b;
cin >> a >> b;
adj[a].push_back(b);
adj[b].push_back(a);
}
int ans = 0;
ans = bfs(bfs_node(1));
cout << ans << endl;
return 0;
}
| 1,500 | CPP |
def solve():
n = int(input())
s = input()
bal = 0
minbal = 0
for i, e in enumerate(s):
if e == ')':
bal -= 1
else:
bal += 1
minbal = min(bal, minbal)
print(-minbal)
[solve() for i in range(int(input()))]
| 1,000 | PYTHON3 |
# AC
import sys
class Main:
def __init__(self):
self.buff = None
self.index = 0
def next(self):
if self.buff is None or self.index == len(self.buff):
self.buff = sys.stdin.readline().split()
self.index = 0
val = self.buff[self.index]
self.index += 1
return val
def next_int(self):
return int(self.next())
def solve(self):
n = self.next_int()
ss = self.next()
tt = 'ACTG'
ans = 26 * 4
for i in range(0, n - 3):
tmp = 0
for j in range(0, 4):
df = abs(ord(ss[i + j]) - ord(tt[j]))
tmp += min(df, 26 - df)
ans = min(ans, tmp)
print(ans)
if __name__ == '__main__':
Main().solve()
| 1,000 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
long long int power(long long int a, long long int b) {
if (b == 0) return 1;
long long int p = power(a, b / 2);
if (b % 2 == 0)
return p * p;
else
return a * p * p;
}
long int gcd(long int a, long int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
int main() {
std::ios_base::sync_with_stdio(false);
long long int n, s, i, ans = -1, a, c = 0, z = 0;
cin >> n >> s;
long long int st = 1, e = 1000000000000000000, mid;
while (st <= e) {
mid = (st + e) / 2;
a = mid;
c = 0;
while (a) {
c += a % 10;
a /= 10;
}
if (mid - c >= s) {
e = mid - 1;
ans = mid;
} else {
st = mid + 1;
}
}
if (ans == -1)
cout << 0;
else
cout << max(n - ans + 1, z);
return 0;
}
| 1,600 | CPP |
n = int(input())
a = list(map(int, input().split()))
a.sort()
for i in range(1, len(a)):
f, s = a[i-1], a[i]
if f == s:
continue
if f != 1:
f *= 2
if f > s:
print("YES")
exit()
print("NO")
| 1,400 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
long long int modulo = 777777777;
long long int maneras[1000000][4][4];
int valido[1000000];
int primero, tope;
int n;
int w[4][4];
void inserta(int pos, int val) {
pos += primero;
valido[pos] = 1;
if (val == 0)
for (int i = 1; i < 4; i++)
for (int j = 1; j < 4; j++)
if (i == j)
maneras[pos][i][j] = 1;
else
maneras[pos][i][j] = 0;
else
for (int i = 1; i < 4; i++)
for (int j = 1; j < 4; j++)
if (i == j and i == val)
maneras[pos][i][j] = 1;
else
maneras[pos][i][j] = 0;
while (pos > 1) {
pos /= 2;
valido[pos] = 1;
long long int(&man)[4][4] = maneras[pos];
long long int(&mana)[4][4] = maneras[2 * pos];
long long int(&manb)[4][4] = maneras[2 * pos + 1];
if (not valido[2 * pos + 1])
for (int i = 1; i < 4; i++)
for (int j = 1; j < 4; j++) man[i][j] = mana[i][j];
else {
for (int i = 1; i < 4; i++)
for (int j = 1; j < 4; j++) man[i][j] = 0;
for (int i = 1; i < 4; i++)
for (int j = 1; j < 4; j++)
for (int k = 1; k < 4; k++)
for (int t = 1; t < 4; t++)
if (w[k][t])
man[i][j] = (man[i][j] + mana[i][k] * manb[t][j]) % modulo;
}
}
}
int main() {
int m;
cin >> n >> m;
{
int nn = n;
primero = 1;
while (nn > 0) {
primero *= 2;
nn /= 2;
}
tope = 2 * primero;
for (int i = 0; i < tope; i++) valido[i] = 0;
}
for (int i = 1; i < 4; i++)
for (int j = 1; j < 4; j++) cin >> w[i][j];
for (int pos = 0; pos < n; pos++) inserta(pos, 0);
for (int cas = 0; cas < m; cas++) {
int pos, val;
cin >> pos >> val;
pos--;
inserta(pos, val);
long long int(&man)[4][4] = maneras[1];
long long int suma = 0;
for (int i = 1; i < 4; i++)
for (int j = 1; j < 4; j++) suma = (suma + man[i][j]) % modulo;
cout << suma << endl;
}
}
| 2,400 | CPP |
#include <bits/stdc++.h>
int a, b, yue[100000], l[10100], h[10100], p[10100], ans[10100], gs, c, n;
void qsort(int x, int y) {
int i, j, t, mid;
i = x;
j = y;
mid = yue[(i + j) / 2];
do {
while (yue[i] < mid) i++;
while (yue[j] > mid) j--;
if (i <= j) {
t = yue[i];
yue[i] = yue[j];
yue[j] = t;
i++;
j--;
}
} while (i <= j);
if (i < y) qsort(i, y);
if (x < j) qsort(x, j);
}
void qsort1(int x, int y) {
int i, j, t, mid;
i = x;
j = y;
mid = h[(i + j) / 2];
do {
while (h[i] > mid) i++;
while (h[j] < mid) j--;
if (i <= j) {
t = h[i];
h[i] = h[j];
h[j] = t;
t = l[i];
l[i] = l[j];
l[j] = t;
t = p[i];
p[i] = p[j];
p[j] = t;
i++;
j--;
}
} while (i <= j);
if (i < y) qsort1(i, y);
if (x < j) qsort1(x, j);
}
int gcd(int a, int b) {
if (a > b) {
int t;
t = a;
a = b;
b = t;
}
if (a == 0)
return b;
else
return gcd(b % a, a);
}
int main() {
int i, j;
while (scanf("%d %d", &a, &b) != EOF) {
c = gcd(a, b);
for (i = 1; i * i <= c; i++)
if (c % i == 0) {
gs++;
yue[gs] = i;
gs++;
yue[gs] = c / i;
}
qsort(1, gs);
scanf("%d", &n);
for (i = 0; i < n; i++) {
p[i] = i;
scanf("%d %d", &l[i], &h[i]);
}
qsort1(0, n - 1);
j = gs;
for (i = 0; i < n; i++) {
while (yue[j] > h[i]) j--;
if (yue[j] < l[i])
ans[p[i]] = -1;
else
ans[p[i]] = yue[j];
}
for (i = 0; i < n; i++) printf("%d\n", ans[i]);
}
return 0;
}
| 1,600 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, ans = 0;
long long k;
cin >> n >> k;
map<long long, int> mp;
long long arr[n];
for (int i = 0; i < n; i++) cin >> arr[i];
sort(arr, arr + n);
for (int i = 0; i < n; i++) {
if (arr[i] % k != 0)
ans++, mp[arr[i]] = 1;
else {
if (!mp[arr[i] / k]) {
ans++;
mp[arr[i]] = 1;
}
}
}
cout << ans;
return 0;
}
| 1,500 | CPP |
#include <bits/stdc++.h>
using namespace std;
char c[101];
bool check(char a, char b, char c) {
return (
a == 'A' && b == 'B' && c == 'C' || a == 'A' && b == 'C' && c == 'B' ||
a == 'B' && b == 'A' && c == 'C' || a == 'B' && b == 'C' && c == 'A' ||
a == 'C' && b == 'A' && c == 'B' || a == 'C' && b == 'B' && c == 'A');
}
int main() {
scanf("%s", &c);
for (int i = 1; i < strlen(c) - 1; i++)
if (check(c[i - 1], c[i], c[i + 1])) {
printf("Yes\n");
return 0;
}
printf("No\n");
return 0;
}
| 900 | CPP |
q = int(input())
def foo (st,it, exp):
it2 = it
if st - it >= 1:
r = st - it - 1
if r > exp:
it2 += exp
exp = 0
else:
exp -= r
it2 += r
else:
r = it - st + 1
if r > exp:
return 0
else:
exp -= r
st += r
it2 += exp//2
return (it2 - it + 1)
for i in range(q):
st, it, exp = map(int,input().split())
print(foo(st,it,exp))
| 1,300 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T abs(T t) {
return t < 0 ? -t : t;
}
const long long modn = 1000000007;
inline long long mod(long long x) { return x % modn; }
const int MAXN = 60, INF = 0x3f3f3f3f;
int n, c[MAXN][2], acu[MAXN][2], t[MAXN];
int main() {
scanf("%d", &n);
for (int b = 0; b < 2; b++) {
for (int a = 0; a < n - 1; a++) {
scanf("%d", &c[a][b]);
}
}
for (int a = 0; a < n; a++) {
scanf("%d", &t[a]);
}
for (int a = 0; a < n; a++) {
if (a != 0) {
acu[a][0] = acu[a - 1][0];
acu[a][0] += c[a - 1][0];
}
}
for (int a = n - 1; a >= 0; a--) {
acu[a][1] = acu[a + 1][1] + c[a][1];
}
int men = INF, smen = INF;
for (int a = 0; a < n; a++) {
if (acu[a][1] + acu[a][0] + t[a] < men) {
smen = men;
men = acu[a][1] + acu[a][0] + t[a];
} else if (acu[a][1] + acu[a][0] + t[a] < smen) {
smen = acu[a][1] + acu[a][0] + t[a];
}
}
printf("%d\n", smen + men);
}
| 1,300 | CPP |
#include <bits/stdc++.h>
const long long MOD = 1000 * 1000 * 1000 + 7;
const long long MOD1 = 998244353;
const long long INF = 1ll * 1000 * 1000 * 1000 * 1000 * 1000 * 1000 + 7;
using namespace std;
long long power(long long x, long long y) {
long long res = 1;
while (y > 0) {
if (y & 1) res = (long long)(res * x);
y = y >> 1;
if (x <= 100000000) x = (long long)(x * x);
}
return res;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n;
cin >> n;
long long a[2 * n];
for (int(i) = (0); (i) < (2 * n); ++(i)) cin >> a[i];
sort(a, a + 2 * n);
long long ans = INF;
for (int i = 0; i < 2 * n; i++) {
for (int j = i + 1; j < 2 * n; j++) {
long long sum = 0;
vector<long long> b;
for (int k = 0; k < 2 * n; k++) {
if (k != i && k != j) {
b.push_back(a[k]);
}
}
sort(b.begin(), b.end());
for (int p = 0; p < int((b).size()); p += 2) sum += b[p + 1] - b[p];
ans = min(sum, ans);
}
}
cout << ans;
return 0;
}
| 1,500 | CPP |
#include <bits/stdc++.h>
using namespace std;
int N, K, A[300005];
long long D[5005][5005];
int main() {
scanf("%d %d", &N, &K);
for (int i = 1; i <= N; i++) scanf("%d", &A[i]);
sort(A + 1, A + 1 + N);
int type1 = (N - 1) / K + 1;
int type2 = (N - K) / K + 1;
int cnt1 = 0, cnt2 = 0;
for (int i = 1; i <= K; i++) {
int t = (N - i) / K + 1;
if (t == type1)
cnt1++;
else
cnt2++;
}
for (int i = 1; i <= K; i++) {
for (int j = i - cnt2; j <= min(cnt1, i); j++) {
int k = i - j;
int now = j * type1 + k * type2;
if (j == 0) {
D[i][j] = D[i - 1][j] + A[now] - A[now - type2 + 1];
} else if (k == 0) {
D[i][j] = D[i - 1][j - 1] + A[now] - A[now - type1 + 1];
} else {
D[i][j] = min(D[i - 1][j] + A[now] - A[now - type2 + 1],
D[i - 1][j - 1] + A[now] - A[now - type1 + 1]);
}
}
}
cout << D[K][cnt1] << endl;
return 0;
}
| 2,000 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000000;
int du[MAXN + 10], gu[MAXN + 10];
priority_queue<int> gus;
int f[MAXN + 10];
int getFather(int x) { return f[x] = f[x] == x ? x : getFather(f[x]); }
bool been[MAXN + 10];
int main() {
int n, m;
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) f[i] = i;
for (int i = 1; i <= m; i++) {
int x, y;
scanf("%d%d", &x, &y);
du[x]++;
du[y]++;
if (rand() & 1) swap(x, y);
f[getFather(x)] = getFather(y);
}
for (int i = 1; i <= n; i++) gu[getFather(i)] += du[i] & 1;
for (int i = 1; i <= n; i++)
if (!been[getFather(i)]) {
if (getFather(1) == getFather(i) || du[getFather(i)])
gus.push(gu[getFather(i)]);
been[getFather(i)] = true;
}
int ans = 0;
while (gus.size() > 1) {
int x = gus.top();
gus.pop();
int y = gus.top();
gus.pop();
gus.push((x == 0 ? 1 : x - 1) + (y == 0 ? 1 : y - 1));
ans++;
}
ans += gus.top() / 2;
cout << ans << endl;
return 0;
}
| 2,400 | CPP |
k,n,w=map(int,input().split())
ll = list(i*k for i in range(1,w+1))
sum1=sum(ll)
if(sum1>n):
print(sum1-n)
else:
print(0) | 800 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
char s[112345];
int n, m;
long long gao() {
int ss = 0;
long long ans = 0;
for (int i = 0; i < int(n); ++i) {
ss += m - 1;
if (i + 1 < n && s[i + 1] != s[i]) {
ans += ss;
}
}
return ans;
}
int main() {
scanf("%d%d", &n, &m);
scanf("%s", s);
long long ans = n * (m - 1);
ans += gao();
reverse(s, s + n);
ans += gao();
for (int i = 0; i + 1 < n; ++i) {
char x[2] = {s[i], s[i + 1]};
if (x[0] == x[1]) continue;
int j;
for (j = i + 1; j < n && s[j] == x[(j - i) & 1]; ++j)
;
int len = j - i;
ans -= len * ((long long)len + 1) / 2 - len;
i = j - 2;
}
printf("%lld\n", ans);
}
| 2,700 | CPP |
input()
l = map(int, input().split())
#print(list(l))
l = list(l)
a, b = max(l), min(l)
count = 0
for i in l :
if i<a and i>b:
count += 1
print(count)
| 900 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const long long LINF = 1e18;
const int INF = 1000000009;
const int MOD = 1000000007;
int main() {
ios_base::sync_with_stdio(false);
int d1, d2, d3;
cin >> d1 >> d2 >> d3;
int go1 = min(d1, d2 + d3);
int go2 = min(d2, d1 + d3);
int res = go1 + min(d1 + d2, d3) + go2;
res = min(res, go1 + min(d1 + d2, d3) * 2 + go1);
res = min(res, go2 + min(d1 + d2, d3) * 2 + go2);
cout << res << endl;
return 0;
}
| 800 | CPP |
#include <bits/stdc++.h>
using namespace std;
vector<pair<long long int, long long int>> edge[5010];
long long int arr[5010];
pair<long long int, pair<long long int, long long int>> qaq[5010];
bool flag;
long long int dfs(long long int a, long long int f, long long int qwq,
long long int k) {
if (a == qwq) return 1;
long long int res = 0, orr;
for (auto x : edge[a]) {
long long int b = x.first;
long long int c = x.second;
if (b != f) {
orr = dfs(b, a, qwq, k);
res = max(res, orr);
if (orr) {
if (arr[c] <= k) {
arr[c] = k;
flag = 1;
}
}
}
}
return res;
}
inline bool cmp(pair<long long int, pair<long long int, long long int>> a,
pair<long long int, pair<long long int, long long int>> b) {
return a.first > b.first;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long int t = 1;
while (t--) {
long long int n, a, b, c, m;
cin >> n;
for (long long int i = 0; i < n - 1; i++) {
cin >> a >> b;
edge[a].emplace_back(make_pair(b, i));
edge[b].emplace_back(make_pair(a, i));
}
cin >> m;
for (long long int i = 0; i < m; i++) {
cin >> a >> b >> c;
qaq[i] = {c, {a, b}};
}
sort(qaq, qaq + m, cmp);
for (long long int i = 0; i < m; i++) {
a = qaq[i].second.first;
b = qaq[i].second.second;
c = qaq[i].first;
flag = 0;
dfs(a, -1, b, c);
if (!flag) {
cout << "-1\n";
return 0;
}
}
for (long long int i = 0; i < n - 1; i++) {
if (arr[i])
cout << arr[i] << " ";
else
cout << "1000000 ";
}
cout << "\n";
}
return 0;
}
| 2,100 | CPP |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define IOS ios::sync_with_stdio(0); cin.tie(0);
#define endl '\n'
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define sz(v) (int)(v).size()
#define mk make_pair
#define F first
#define S second
#define debug(a) cout << #a << " = " << a << endl;
const int INF = 1000000009;
const ll MOD = 1000000007LL;
int n, k;
vector<int> v[200001];
int a[200001];
int d[200001];
int d2[200001];
int ans[200001];
signed main() { IOS
cin >> n;
for (int i = 1; i <= n - 1; ++ i) {
int a, b;
cin >> a >> b;
v[a].pb(b);
v[b].pb(a);
}
cin >> k;
for (int i = 1; i <= k; ++ i) cin >> a[i];
for (int i = 1; i <= n; ++ i) d[i] = INF;
queue<int> q;
for (int i = 1; i <= k; ++ i) q.push(a[i]), d[a[i]] = 0;
while (sz(q)) {
int p = q.front(); q.pop();
for (auto i : v[p]) {
if (d[i] != INF) continue;
d[i] = d[p] + 1;
q.push(i);
}
}
vector<pii> u;
for (int i = 1; i <= n; ++ i) u.pb(mk(d[i], i));
sort(all(u), greater<pii>());
for (auto i : u) {
if (d[i.S] <= d2[i.S]) continue;
d2[i.S] = d[i.S];
ans[i.S] = max(ans[i.S], d[i.S]);
queue<pii> q;
q.push(mk(d2[i.S], i.S));
while (sz(q)) {
pii p = q.front(); q.pop();
if (p.F < d2[p.S]) continue;
for (auto j : v[p.S]) {
if (d2[p.S] - 1 <= d2[j]) continue;
d2[j] = d2[p.S] - 1;
ans[j] = max(ans[j], d[i.S]);
q.push(mk(d2[j], j));
}
}
}
for (int i = 1; i <= n; ++ i) cout << ans[i] << " ";
} | 2,700 | CPP |
#include <bits/stdc++.h>
using namespace std;
inline bool SR(int &x) { return scanf("%d", &x) == 1; }
inline bool SR(long long &x) { return scanf("%lld", &x) == 1; }
inline bool SR(double &x) { return scanf("%lf", &x) == 1; }
inline bool SR(char *s) { return scanf("%s", s) == 1; }
inline bool RI() { return true; }
template <typename I, typename... T>
inline bool RI(I &x, T &...tail) {
return SR(x) && RI(tail...);
}
inline void SP(const int x) { printf("%d", x); }
inline void SP(const long long x) { printf("%lld", x); }
inline void SP(const double x) { printf("%.16lf", x); }
inline void SP(const char *s) { printf("%s", s); }
inline void PL() { puts(""); }
template <typename I, typename... T>
inline void PL(const I x, const T... tail) {
SP(x);
if (sizeof...(tail)) putchar(' ');
PL(tail...);
}
template <typename I>
void _DOING(const char *s, I &&x) {
cerr << s << " = " << x << endl;
}
template <typename I, typename... T>
void _DOING(const char *s, I &&x, T &&...tail) {
int c = 0;
while (*s != ',' || c != 0) {
if (*s == '(' || *s == '[' || *s == '{') c++;
if (*s == ')' || *s == ']' || *s == '}') c--;
cerr << *s++;
}
cerr << " = " << x << " , ";
_DOING(s + 1, tail...);
}
inline int RAND() {
static int x = 880301;
return (x = x * 0xdefaced + 1) & 0x7fffffff;
}
struct Point {
long long x, y;
Point(long long _x = 0, long long _y = 0) : x(_x), y(_y) {}
bool operator<(const Point &rhs) const {
if (x != rhs.x)
return x < rhs.x;
else
return y < rhs.y;
}
};
inline Point operator+(const Point &p, const Point &v) {
return Point(p.x + v.x, p.y + v.y);
}
inline Point operator-(const Point &a, const Point &b) {
return Point(a.x - b.x, a.y - b.y);
}
inline Point operator*(const Point &v, const long long &p) {
return Point(v.x * p, v.y * p);
}
inline long long cross(const Point &a, const Point &b) {
return a.x * b.y - a.y * b.x;
}
inline vector<Point> convex_hull(vector<Point> ps) {
int n = ((int)ps.size());
sort((ps).begin(), (ps).end());
int m = 0;
vector<Point> ch;
for (int i = 0; i < int(n); i++) {
while (m > 1 && cross(ps[i] - ch[m - 2], ch[m - 1] - ch[m - 2]) >= 0)
ch.pop_back(), m--;
ch.push_back(ps[i]), m++;
}
int k = m;
for (int i = n - 2; i >= 0; i--) {
while (m > k && cross(ps[i] - ch[m - 2], ch[m - 1] - ch[m - 2]) >= 0)
ch.pop_back(), m--;
ch.push_back(ps[i]), m++;
}
return ch;
}
vector<Point> ps;
int main() {
int n;
long long s;
RI(n, s);
for (int i = 0; i < int(n); i++) {
long long x, y;
RI(x, y);
ps.push_back(Point(x, y));
}
ps = convex_hull(ps);
n = ((int)ps.size());
Point a = ps[0], b = ps[1], c = ps[2];
for (int i = 0; i < n - 1; i++) {
for (int j = i + 1, p = i + 1; j < n; j++) {
while (p + 1 < n && abs(cross(ps[j] - ps[i], ps[p + 1] - ps[i])) >=
abs(cross(ps[j] - ps[i], ps[p] - ps[i])))
p++;
if (abs(cross(ps[j] - ps[i], ps[p] - ps[i])) > abs(cross(b - a, c - a)))
a = ps[i], b = ps[j], c = ps[p];
}
}
Point p1 = a + (c - b), p2 = a + (b - c), p3 = b + (c - a);
PL(p1.x, p1.y);
PL(p2.x, p2.y);
PL(p3.x, p3.y);
return 0;
}
| 2,600 | CPP |
t = int(input())
while t>0:
t -= 1
n = int(input())
a = [int(x) for x in input().split()]
odd, even = [], []
for i in range(len(a)):
if a[i] % 2:
odd.append(i+1)
else:
even.append(i+1)
result = []
# print(odd)
# print(even)
for i in range(0, len(odd), 2):
if i+1 < len(odd):
result.append((odd[i], odd[i+1]))
for i in range(0, len(even), 2):
if i+1 < len(even):
result.append((even[i], even[i+1]))
for i in range(len(result)):
if n == 1:
break
x, y = result[i]
print(x,y)
n -= 1 | 1,100 | PYTHON3 |
n,m=[int(x) for x in input().split()]
re=n
c=0
rem=0
while(re):
re-=1
rem+=1
if(rem==m):
re+=1
rem=0
c+=1
print(c)
| 1,000 | PYTHON3 |
# cook your dish here
for _ in range(int(input())):
n=int(input())
temp=[]
l=[]
for _ in range(n):
temp=[i for i in map(int,input().split())]
mn=0
for i in range(1,len(temp)):
mn=max(mn,temp[i]+1-(i-1))
l.append([mn,temp[0]])
l.sort(reverse=True)
posbl=0
for i in range(len(l)):
if posbl<l[i][0]:
posbl=l[i][0]
if i+1!=len(l):
posbl-=l[i+1][1]
print(posbl)
| 1,300 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
bool comp(char a, char b) { return a > b; }
int main() {
string arr[] = {"", "", "2", "3", "322", "5", "53", "7", "7222", "7332"};
int n;
cin >> n;
string s;
cin >> s;
string w = "";
for (int i = 0; i < n; i++) {
w = w + arr[(s[i] - '0')];
}
sort(w.begin(), w.end(), comp);
cout << w << endl;
return 0;
}
| 1,400 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int L = 26;
int g[L][L], vis[L];
bool in[L];
string ans;
void dfs(int v) {
vis[v] = 1;
for (int i = 0; i < L; i++) {
if (g[i][v]) {
if (!vis[i]) {
dfs(i);
} else if (vis[i] == 1) {
cout << "IMPOSSIBLE" << endl;
exit(0);
}
}
}
vis[v] = 2;
ans.push_back('a' + v);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, k;
cin >> n >> k;
vector<vector<string>> x(n, vector<string>(k));
for (int i = 0; i < n; i++) {
int p;
cin >> p;
for (int j = 0; j < k; j++) {
cin >> x[p][j];
for (char c : x[p][j]) {
in[c - 'a'] = 1;
}
}
}
int l = n * k;
vector<string> s(l);
for (int i = 0; i < n; i++) {
for (int j = 0; j < k; j++) {
s[i * k + j] = x[i][j];
}
}
for (int i = 0; i + 1 < l; i++) {
string a = s[i], b = s[i + 1];
if (a == b) {
continue;
}
int j = 0;
while (j < a.size() && j < b.size()) {
if (a[j] == b[j]) {
j++;
continue;
}
g[a[j] - 'a'][b[j] - 'a'] = 1;
break;
}
if (j == b.size()) {
cout << "IMPOSSIBLE" << endl;
return 0;
}
}
for (int i = 0; i < L; i++) {
if (in[i] && !vis[i]) {
dfs(i);
}
}
cout << ans << endl;
return 0;
}
| 2,200 | CPP |
n=int(input())
lis=[]
for i in range(n):
a,b=map(int,input().split())
lis.append((a,b))
k=int(input())
for i in range(len(lis)):
if k<=lis[i][1]:
break
print(n-i)
| 800 | PYTHON3 |
t = int(input())
for _ in range(t):
a,b,n,s = map(int,input().split(" "))
bol = False
while a >= 0 :
if a*n > s:
a = s//n
elif a*n == s:
bol = True
print("YES")
break
else:
if (s-a*n) <= b:
bol = True
print("YES")
break
if not bol:
print("NO") | 1,000 | PYTHON3 |
s=list(input())
h=0
if 'h' not in s or 'e' not in s or 'i' not in s or 'd' not in s:
print('NO')
else:
p=[]
for i in s:
if i=='h' or i=='e' or i=='i' or i=='d' :
p.append(i)
for i in range(0,len(p)):
if p[i]=='h':
h+=1
break
for j in range(i,len(p)):
if p[j]=='e':
h+=1
break
for i in range(j,len(p)):
if p[i]=='i':
h+=1
break
for j in range(i,len(p)):
if p[j]=='d':
h+=1
break
for i in range(j,len(p)):
if p[i]=='i':
h+=1
break
if h!=5:
print('NO')
else:
print('YES')
| 800 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
long long read() {
long long x = 0, f = 0;
char ch = getchar();
while (!isdigit(ch)) f |= ch == '-', ch = getchar();
while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
return f ? -x : x;
}
const int N = 1005;
int n;
struct Point {
int x, y;
Point() {}
Point(int _x, int _y) { x = _x, y = _y; }
friend Point operator+(Point A, Point B) {
return Point(A.x + B.x, A.y + B.y);
}
friend Point operator-(Point A, Point B) {
return Point(A.x - B.x, A.y - B.y);
}
friend bool operator==(Point A, Point B) { return A.x == B.x && A.y == B.y; }
friend bool operator!=(Point A, Point B) { return A.x != B.x || A.y != B.y; }
} O;
int cross(Point A, Point B) { return A.x * B.y - B.x * A.y; }
int cross(Point A, Point B, Point C) { return cross(B - A, C - A); }
int Dot(Point A, Point B) { return A.x * B.x + A.y * B.y; }
int Dis(Point A, Point B) { return Dot(A - B, A - B); }
struct civ {
Point p;
int c, id;
civ() {}
civ(Point _p, int _c, int _id) { p = _p, c = _c, id = _id; }
};
civ Get_civ(int id) {
Point p;
p.x = read(), p.y = read();
int c = read();
return civ(p, c, id);
}
vector<civ> p, con;
bool cmpO(Point a, Point b) { return a.y != b.y ? a.y < b.y : a.x < b.x; }
bool cmpAngle_civ(civ a, civ b) {
int c = cross(O, a.p, b.p);
return c ? c > 0 : Dis(O, a.p) < Dis(O, b.p);
}
vector<civ> Get_Convex(vector<civ> p) {
vector<civ> st(0);
int n = p.size();
for (int i = 1; i < n; i++)
if (!cmpO(p[0].p, p[i].p)) swap(p[0], p[i]);
O = p[0].p;
sort(p.begin() + 1, p.end(), cmpAngle_civ);
for (int i = 0; i < n; i++) {
while (st.size() > 1 &&
cross(st[st.size() - 2].p, st.back().p, p[i].p) <= 0)
st.pop_back();
st.push_back(p[i]);
}
return st;
}
int check_same() {
for (int i = 1; i < n; i++)
if (p[i].c != p[0].c) return 0;
return 1;
}
int check_inside(Point A, Point B, Point C, Point P) {
if (P == A || P == B || P == C) return 0;
int S1 = abs(cross(A, B, C));
int S2 = abs(cross(P, A, B)) + abs(cross(P, B, C)) + abs(cross(P, C, A));
return S1 == S2;
}
vector<civ> get_inside(Point A, Point B, Point C, vector<civ> S) {
static vector<civ> res;
res.clear();
for (auto v : S)
if (check_inside(A, B, C, v.p)) res.push_back(v);
return res;
}
vector<pair<int, int> > ans;
void solve(civ A, civ B, civ C, vector<civ> S) {
int flag = 0;
civ p;
for (auto c : S)
if (c.c != A.c) {
flag = 1, p = c;
break;
}
if (!flag) {
for (auto c : S) ans.push_back(make_pair(A.id, c.id));
return;
}
ans.push_back(make_pair(C.id, p.id));
solve(A, B, p, get_inside(A.p, B.p, p.p, S));
solve(C, p, A, get_inside(C.p, p.p, A.p, S));
solve(C, p, B, get_inside(C.p, p.p, B.p, S));
}
int main() {
n = read();
for (int i = 1; i <= n; i++) p.push_back(Get_civ(i));
con = Get_Convex(p);
int cnt = con[0].c ^ con.back().c;
for (int i = 1; i < con.size(); i++) cnt += con[i - 1].c ^ con[i].c;
if (cnt > 2) return puts("Impossible"), 0;
ans.clear();
if (cnt == 0) {
if (check_same()) {
printf("%d\n", n - 1);
for (int i = 1; i < n; i++) printf("%d %d\n", 0, i);
return 0;
}
for (int i = 1; i < con.size(); i++)
ans.push_back(make_pair(con[i - 1].id, con[i].id));
civ mid;
for (auto c : p)
if (c.c != con[0].c) {
mid = c;
break;
}
solve(con[0], con.back(), mid,
get_inside(con[0].p, con.back().p, mid.p, p));
for (int i = 1; i < con.size(); i++)
solve(con[i - 1], con[i], mid,
get_inside(con[i - 1].p, con[i].p, mid.p, p));
} else {
vector<civ> _con(0);
int stco = con[0].c ^ 1, i;
int m = con.size();
for (i = 0;; i = (i + 1) % m)
if (con[i].c == stco) {
_con.push_back(con[i]);
if (con[(i + 1) % m].c != stco) break;
}
stco ^= 1;
for (i = (i + 1) % m;; i = (i + 1) % m)
if (con[i].c == stco) {
_con.push_back(con[i]);
if (con[(i + 1) % m].c != stco) break;
}
con = _con;
for (i = 0; i < m; i++)
if (con[i].c != con[(i + 1) % m].c) break;
int b = i;
for (int i = 0; i < b; i++)
ans.push_back(make_pair(con[i].id, con[i + 1].id));
for (int i = b + 1; i < m - 1; i++)
ans.push_back(make_pair(con[i].id, con[i + 1].id));
b++;
for (int i = 0; i < b - 1; i++)
solve(con[i], con[i + 1], con[b],
get_inside(con[i].p, con[i + 1].p, con[b].p, p));
for (int i = b; i < m - 1; i++)
solve(con[i], con[i + 1], con[0],
get_inside(con[i].p, con[i + 1].p, con[0].p, p));
}
printf("%d\n", (int)ans.size());
for (auto e : ans) printf("%d %d\n", e.first - 1, e.second - 1);
return 0;
}
| 3,200 | CPP |
s = input()
a_cnt = s.count('a')
print(min(2*a_cnt-1, len(s)))
| 800 | PYTHON3 |
players = input()
dangerous = False
current = players[0]
sequence_length = 1
for pos in range(len(players)):
if players[pos] == current:
sequence_length += 1
if sequence_length == 7:
dangerous = True
break
else:
current = players[pos]
sequence_length = 1
print('YES') if dangerous else print('NO')
| 900 | PYTHON3 |
import math
t = int(input())
print()
for _ in range(t):
a, b, x, y, n = map(int, input().split())
n1 = min(n, b - y)
n2 = min(n - n1, a - x)
n3 = min(n, a - x)
n4 = min(n - n3, b - y)
print(min((b - n1) * (a - n2), (a - n3) * (b - n4)))
| 1,100 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const long long N = 1e6 + 3;
const long long mod = 1e9 + 7;
const long long INF = 0x7f7f7f7f7f7f7f7f;
const int INFi = 0x7f7f7f7f;
int n, ans = -1, okk[N];
vector<int> adj[N];
map<unsigned long long, int> hm[N], okm[N];
unsigned long long hsh[N];
void dfs(int x, int p) {
hsh[x] = 1;
for (auto it : adj[x]) {
if (it == p) continue;
dfs(it, x);
hsh[x] += hsh[it] * 39;
okm[x][okk[it]]++;
hm[x][hsh[it]]++;
}
okk[x] = (hm[x].size() <= 1) & (okm[x][0] == 0);
}
void reroot(int x, int p) {
if (p) {
hsh[p] -= hsh[x] * 39;
hm[p][hsh[x]]--;
if (hm[p][hsh[x]] == 0) hm[p].erase(hsh[x]);
okm[p][okk[x]]--;
if (okm[p][okk[x]] == 0) okm[p].erase(okk[x]);
okk[p] = (hm[p].size() <= 1) & (okm[p][0] == 0);
hsh[x] += hsh[p] * 39;
hm[x][hsh[p]]++;
okm[x][okk[p]]++;
okk[x] = (hm[x].size() <= 1) & (okm[x][0] == 0);
}
if (okk[x]) ans = x;
for (auto it : adj[x]) {
if (it == p) continue;
reroot(it, x);
}
if (p) {
hsh[x] -= hsh[p] * 39;
hm[x][hsh[p]]--;
if (hm[x][hsh[p]] == 0) hm[x].erase(hsh[p]);
okm[x][okk[p]]--;
if (okm[x][okk[p]] == 0) okm[x].erase(okk[p]);
okk[x] = (hm[x].size() <= 1) & (okm[x][0] == 0);
hsh[p] += hsh[x] * 39;
hm[p][hsh[x]]++;
okm[p][okk[x]]++;
okk[p] = (hm[p].size() <= 1) & (okm[p][0] == 0);
}
}
void solve() {
cin >> n;
for (int i = 1; i < n; i++) {
int u, v;
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
dfs(1, 0);
reroot(1, 0);
cout << ans << "\n";
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cout << fixed;
cout << setprecision(15);
;
int test = 1;
for (int i = 1; i <= test; i++) {
solve();
}
}
| 2,400 | CPP |
from itertools import combinations
n = int(input())
l = []
for i in range(n):
a, b = map(int, input().split())
l.append((a, b))
c = 0
for x in combinations(l, 2):
if x[0][0] == x[1][1]:
c += 1
if x[0][1] == x[1][0]:
c += 1
print(c)
| 800 | PYTHON3 |
for i in range(int(input())):
a,b,c=sorted(map(int,input().split()))
if(a>=4):
print(7)
elif(a==0 and b==0 and c==0):
print(0)
elif(a==0 and b==0 and c>0):
print(1)
elif(a==0 and b==1):
print(2)
elif(a==0 and b>1):
print(3)
elif(a==1 and b==1):
print(3)
elif(a==1 and b!=1):
print(4)
elif(a==2 and b==2 and c==2):
print(4)
elif(a==2 and c!=a):
print(5)
elif(a==3 and b==3 and c==3):
print(6)
elif(a==3 and c!=a):
print(6) | 900 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void out(T x) {
cout << x << endl;
exit(0);
}
const int maxn = 505;
const int inf = 1e9;
int n, m, k;
int dp[maxn];
string s;
int a[maxn];
int tot;
int f[maxn];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> m >> k;
while (n--) {
cin >> s;
tot = 0;
for (int i = 0; i < m; i++) {
if (s[i] == '1') {
a[tot++] = i;
}
}
for (int rm = 0; rm < tot; rm++) {
f[rm] = inf;
for (int i = 0; i <= rm && i < tot; i++) {
int j = tot - 1 - (rm - i);
if (j < i) break;
f[rm] = min(f[rm], a[j] - a[i] + 1);
}
}
f[tot] = 0;
for (int rm = k; rm >= 0; rm--) {
dp[rm] += f[0];
for (int i = 1; i <= tot && rm - i >= 0; i++) {
dp[rm] = min(dp[rm], dp[rm - i] + f[i]);
}
}
}
cout << dp[k] << endl;
return 0;
}
| 1,800 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, i, j, ans, one, two;
int* a;
vector<int> ch;
cin >> n >> k;
a = new int[n + 1];
for (i = 1; i <= n; i++) {
cin >> a[i];
}
i = 1;
while (i <= k) {
j = i + k;
while (j <= n) {
if (a[j] != a[i]) {
ch.push_back(i);
break;
}
j = j + k;
}
i++;
}
ans = 0;
for (i = 0; i < ch.size(); i++) {
one = 0;
j = ch[i];
while (j <= n) {
if (a[j] == 2) {
one++;
}
j = j + k;
}
two = 0;
j = ch[i];
while (j <= n) {
if (a[j] == 1) {
two++;
}
j = j + k;
}
ans = ans + min(one, two);
}
cout << ans << "\n";
}
| 1,000 | CPP |
#include <bits/stdc++.h>
const int N = 5005;
int n, T, t[N];
double p[N], f[N][N], ans;
int read() {
int x = 0, f = 1;
char s;
while ((s = getchar()) < '0' || s > '9')
if (s == '-') f = -1;
while (s >= '0' && s <= '9') {
x = (x << 1) + (x << 3) + (s ^ 48);
s = getchar();
}
return x * f;
}
double qkpow(double x, int y) {
double r = 1;
while (y) {
if (y & 1) r *= x;
x *= x;
y >>= 1;
}
return r;
}
int main() {
n = read(), T = read();
for (int i = 1; i <= n; ++i) p[i] = 1.0 * read() / 100, t[i] = read();
f[0][0] = 1;
for (int i = 1; i <= n; ++i) {
double sum = 0, w = qkpow(1 - p[i], t[i] - 1);
for (int j = 1; j <= T; ++j) {
sum *= 1 - p[i];
sum += f[i - 1][j - 1] * p[i];
if (j >= t[i]) {
sum -= f[i - 1][j - t[i]] * w * p[i];
f[i][j] += f[i - 1][j - t[i]] * w;
}
f[i][j] += sum;
ans += f[i][j];
}
}
printf("%.9f\n", ans);
return 0;
}
| 2,400 | CPP |
import sys,collections,math
######################################
def in_out():
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')
#in_out()
######################################
from collections import Counter
for _ in range(int(input())):
n = int(input())
arr = list(map(int,input().split()))
greater = 0
smaller = 0
for i,ele in enumerate(arr):
if ele>1:
break
if i%2==0:
print('First')
else:
print('Second')
| 1,100 | PYTHON3 |
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Aug 17 21:41:52 2020
@author: anirudhasarmatumuluri
"""
n,k = [int(x) for x in input().split()]
print((k*n)//2) | 800 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
bool ask(long long l, long long r) {
printf("%lld %lld\n", l, r);
fflush(stdout);
char x[4];
scanf(" %s", x);
return x[0] == 'Y';
}
long long n, k;
int main() {
cin >> n >> k;
long long l = 1, r = n;
srand(time(0));
while (1) {
if (r - l + 1 <= 50) {
long long q = l + rand() % (r - l + 1);
if (ask(q, q)) return 0;
l = max(1LL, l - k);
r = min(n, r + k);
} else {
long long md = l + ((r - l) >> 1);
if (ask(l, md)) {
l = max(1LL, l - k);
r = min(n, md + k);
} else {
l = max(1LL, md + 1 - k);
r = min(n, r + k);
}
}
}
}
| 2,100 | CPP |
#include <bits/stdc++.h>
using namespace std;
int a[800][800];
int main() {
ios_base::sync_with_stdio(0);
int n, t;
cin >> n >> t;
a[200][200] = n;
queue<pair<int, int> > myqueue;
myqueue.push(make_pair(200, 200));
while (!myqueue.empty()) {
int x = myqueue.front().first;
int y = myqueue.front().second;
myqueue.pop();
if (a[x][y] / 4 > 0) {
a[x + 1][y] += a[x][y] / 4;
a[x - 1][y] += a[x][y] / 4;
a[x][y + 1] += a[x][y] / 4;
a[x][y - 1] += a[x][y] / 4;
a[x][y] = a[x][y] % 4;
myqueue.push(make_pair(x + 1, y));
myqueue.push(make_pair(x - 1, y));
myqueue.push(make_pair(x, y + 1));
myqueue.push(make_pair(x, y - 1));
}
}
while (t--) {
int xx, yy;
cin >> xx >> yy;
xx = xx + 200;
yy = yy + 200;
if (xx < 0 || xx > 400 || yy < 0 || yy > 400)
cout << 0 << endl;
else
cout << a[xx][yy] << endl;
}
}
| 2,000 | CPP |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
void go() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout << fixed;
cout << setprecision(20);
}
void solve() {
long long n;
cin >> n;
long long power = 1;
long long ans = 0;
while (n) {
long long rem = n % 10;
if (rem == 4) {
ans += 1 * power;
} else {
ans += 2 * power;
}
power *= 2;
n /= 10;
}
cout << ans;
}
signed main() {
go();
long long t = 1;
while (t--) solve();
}
| 1,100 | CPP |
s = ""
s = input()
s = list(s)
c = 0
con = False
for i in range(1, len(s)):
if s[i] == s[i - 1]:
c += 1
else:
c = 0
if c >= 6:
con = True
if con:
print("YES")
else:
print("NO")
| 900 | PYTHON3 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
using std::abs;
using std::cerr;
using std::cin;
using std::cout;
using std::map;
using std::max;
using std::min;
using std::pair;
using std::set;
using std::string;
using std::swap;
using std::vector;
using ll = long long;
using uint = unsigned int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename T>
void err(vector<string>::iterator it, T a) {
cerr << it->substr((*it)[0] == ' ') << " = " << a << '\n';
}
template <typename T, typename... Ts>
void err(vector<string>::iterator it, T a, Ts... as) {
cerr << it->substr((*it)[0] == ' ') << " = " << a << ", ";
err(++it, as...);
}
struct init {
init() {
cin.tie(0);
std::iostream::sync_with_stdio(0);
cout << std::fixed << std::setprecision(10);
cerr << std::fixed << std::setprecision(10);
srand(time(0));
}
~init() {}
} init;
const int MAXN = 2017;
string a[MAXN], b[MAXN], ans[MAXN], kek[MAXN];
vector<int> g[MAXN];
int kl[MAXN], kr[MAXN];
bool used[MAXN];
bool dfs(int v) {
if (used[v]) return false;
used[v] = true;
for (int to : g[v])
if (!kr[to]) return kl[kr[to] = v] = to;
for (int to : g[v])
if (dfs(kr[to])) return kl[kr[to] = v] = to;
return false;
}
int main() {
int n;
cin >> n;
set<string> all, bad;
for (int i = 1; i <= n; ++i) {
string x, y;
cin >> x >> y;
a[i] = {x[0], x[1], x[2]};
b[i] = {x[0], x[1], y[0]};
if (all.count(a[i])) bad.insert(a[i]);
all.insert(a[i]);
all.insert(b[i]);
}
map<string, int> num;
for (auto s : all) {
int sz = num.size() + 1;
num[s] = sz;
kek[sz] = s;
}
for (int i = 1; i <= n; ++i) {
if (!bad.count(a[i])) g[i].emplace_back(num[a[i]]);
g[i].emplace_back(num[b[i]]);
}
for (int go = 1; go--;) {
memset(used, 0, sizeof used);
for (int i = 1; i <= n; ++i)
if (!kl[i] && dfs(i)) go = 1;
}
int yay = 0;
for (int i = 1; i <= n; ++i)
if (kl[i]) {
++yay;
ans[i] = kek[kl[i]];
}
if (yay == n) {
cout << "YES\n";
for (int i = 1; i <= n; ++i) cout << ans[i] << '\n';
} else
cout << "NO\n";
return 0;
}
| 1,900 | CPP |
# n =
for t in range(int(input())):
s = input()
l = set()
n = len(s)
for i in range(n-2):
if s[i:i+3]=="one":
l.add(i+2)
if s[i:i+3]=="two":
l.add(i+2)
# print(l)
for i in range(n-4):
if s[i:i+5] == "twone":
l.remove(i+4)
l.remove(i+2)
l.add(i+3)
print(len(l))
print(" ".join(map(str, l)))
| 1,400 | PYTHON3 |
a=input()
a=a.lower()
b=input()
b=b.lower()
if a==b:
print('0')
elif a<b:
print('-1')
elif a>b:
print('1')
| 800 | PYTHON3 |
import sys
n = int(sys.stdin.readline().split()[0])
a = list(map(int, sys.stdin.readline().split()))
b = [x for x in a]
idx = -1
while max(b) != 0:
c = [x&1 for x in b]
if c.count(1) == 1:
idx = c.index(1)
b = [x>>1 for x in b]
if idx >= 0:
sys.stdout.write(str(a[idx]) + " ")
for i in range(n):
if i != idx:
sys.stdout.write(str(a[i]) + " ")
else:
for i in range(n):
sys.stdout.write(str(a[i]) + " ") | 1,500 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long s, b;
cin >> s >> b;
long long arr[s];
long long ans[s];
for (long long i = 0; i < s; i++) {
cin >> arr[i];
}
vector<pair<long long, long long>> v;
vector<long long> v1;
for (long long i = 0; i < b; i++) {
long long x, y;
cin >> x >> y;
v.push_back(make_pair(x, y));
v1.push_back(x);
}
sort(v.begin(), v.end());
sort(v1.begin(), v1.end());
long long a[b + 1];
a[0] = 0;
for (long long i = 1; i <= b; i++) {
a[i] = a[i - 1] + v[i - 1].second;
}
for (long long i = 0; i < s; i++) {
auto p = lower_bound(v1.begin(), v1.end(), arr[i]) - v1.begin();
auto it = v.begin();
it = next(it, p);
if (it == v.end()) {
ans[i] = a[p];
continue;
}
if ((*it).first > arr[i]) {
ans[i] = a[p];
continue;
} else if ((*it).first == arr[i]) {
ans[i] = a[p + 1];
continue;
}
}
for (long long i = 0; i < s; i++) {
cout << ans[i] << " ";
}
}
| 1,400 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int mod = (int)1e9 + 7, maxn = 200005, maxm = 26, ln = 17;
inline void S(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;
}
const int shift = 30, etf = mod - 1, LIM = (int)1e9;
const long long int inf = (long long int)1e18 + 1;
const double PI = (double)3.141592653589793238, EPSILON = 1e-10;
vector<pair<long long int, long long int> > va, vb;
int main() {
int n;
long long int s;
cin >> n >> s;
long long int init_ans = 0;
long long int pa = 0, pb = 0;
for (int i = 0; i < n; i++) {
long long int r, a, b;
scanf("%lld", &r);
scanf("%lld", &a);
scanf("%lld", &b);
if (a >= b) {
va.push_back(make_pair(a - b, r));
init_ans += r * a;
pa += r;
} else {
vb.push_back(make_pair(b - a, r));
init_ans += r * b;
pb += r;
}
}
sort(va.begin(), va.end());
sort(vb.begin(), vb.end());
long long int ansa = init_ans;
long long int ansb = init_ans;
long long int reqa =
((pa + s - 1) / s + (pb + s - 1) / s == (pa + pb + s - 1) / s) ? 0
: pb % s;
long long int reqb =
((pa + s - 1) / s + (pb + s - 1) / s == (pa + pb + s - 1) / s) ? 0
: pa % s;
int idx1 = 0;
while (reqa) {
long long int cnt = min(reqa, vb[idx1].second);
ansa -= cnt * vb[idx1].first;
reqa -= cnt;
idx1++;
}
int idx2 = 0;
while (reqb) {
long long int cnt = min(reqb, va[idx2].second);
ansb -= cnt * va[idx2].first;
reqb -= cnt;
idx2++;
}
cout << max(ansb, ansa) << endl;
return 0;
}
| 1,900 | CPP |
lenn = int(input())
inp = input()
box = []
strr = ""
for i in inp:
if i == " ":
box.append(int(strr))
strr = ""
else:
strr += i
box.append(int(strr))
moves = 1
while moves > 0:
moves = 0
for i in range(lenn-1, 0, -1):
summ = box[i-1]-box[i]
if summ > 0:
moves += 1
box[i] += summ
box[i-1] -= summ
for i in range(lenn-1):
print(box[i], end=" ")
print(box[lenn-1])
| 900 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
long long n, lo, hi, L, P, mem;
long long T[200005];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
hi = n - 1;
for (int i = 0; i < n; i++) cin >> T[i];
while (lo != hi) {
if (L <= P) {
L += T[lo];
if (L == P) mem = L;
lo++;
} else if (L > P) {
P += T[hi];
if (L == P) mem = L;
hi--;
}
}
if (L <= P) {
L += T[lo];
if (L == P) mem = L;
lo++;
} else if (L > P) {
P += T[hi];
if (L == P) mem = L;
hi--;
}
cout << mem;
}
| 1,200 | CPP |
n, m = map(int, input().split())
s = list(input())
for i in range(m):
l, r, c1, c2 = input().split()
for i in range(int(l) - 1, int(r)):
if s[i] == c1:
s[i] = c2
print(''.join(s)) | 800 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
inline int myrand(int l, int r) {
int ret = rand();
ret <<= 15;
ret ^= rand();
if (ret < 0) ret = -ret;
ret %= (r - l + 1);
ret += l;
return ret;
}
template <typename F, typename S>
ostream& operator<<(ostream& os, const pair<F, S>& p) {
return os << "(" << p.first << ", " << p.second << ")";
}
template <typename T>
using min_pq = priority_queue<T, vector<T>, greater<T> >;
struct solution_bag {
map<int, int> mp;
void insert(int p, int w) {
p = -p + 100002;
for (; p <= 100005; p += p & -p) mp[p] = max(mp[p], w);
}
int query(int p) {
p++;
p = -p + 100002;
int ret = -1e9;
for (; p > 0; p -= p & -p) {
if (mp.find(p) == mp.end()) continue;
ret = max(ret, mp[p]);
}
return ret;
}
};
const int maxn = 100010;
solution_bag bag[maxn];
int n, m;
vector<tuple<int, int, int> > edges;
int dp[maxn];
int32_t main() {
cin >> n >> m;
for (int i = 1; i <= m; i++) {
int u, v, w;
cin >> u >> v >> w;
edges.push_back(tuple<int, int, int>(u, v, w));
}
for (int i = m - 1; i >= 0; i--) {
int u, v, w;
tie(u, v, w) = edges[i];
dp[i] = 1;
int R = bag[v].query(w);
dp[i] = max(dp[i], R + 1);
bag[u].insert(w, max(R + 1, 1));
}
int ret = 0;
for (int i = 0; i < m; i++) {
ret = max(ret, dp[i]);
}
cout << ret << '\n';
return 0;
}
| 2,100 | CPP |
n=int(input())
a=list(map(int,input().split(" ")))
for i in range(len(a)):
if a[i]>=0:
a[i]=-a[i]-1
if (n)%2==0:
print(*a)
else:
s=a.index(min(a))
a[s]=-a[s]-1
print(*a) | 1,500 | PYTHON3 |
n,m = map(int,input().split())
arr = list(map(int,input().split()))
n //= m
bands = [n]*(m+1)
bands2 = []
for i,a in enumerate(arr):
if a <= m and bands[a]:
bands[a] -= 1
else:
bands2.append(i) #需要改动的位置
for i,s in enumerate(bands[1:],1):
for _ in range(s):
arr[bands2.pop(0)] = i
print(n,sum(bands[1:]))
print(*arr) | 1,600 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 100000;
const int MOD = 998244353;
long long a[MAX + 10], s[50], sum[50], len[MAX + 10];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
s[0] = 1;
for (int i = 1; i <= 20; ++i) {
s[i] = s[i - 1] * 10 % MOD;
}
int n;
cin >> n;
int maxlen = 0, minlen = INT_MAX;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
long long t = a[i];
int cnt = 0;
while (t) {
t /= 10;
++cnt;
}
++sum[cnt];
len[i] = cnt;
maxlen = max(maxlen, cnt);
minlen = min(minlen, cnt);
}
long long ans = 0;
for (int i = 1; i <= n; ++i) {
int leni = len[i];
for (int j = minlen; j <= maxlen; ++j) {
int cnt = 0;
long long tmp = a[i];
while (tmp) {
long long t = tmp % 10;
if (cnt < 2 * min(leni, j)) {
ans = (ans + t * s[cnt++] % MOD * sum[j]) % MOD;
ans = (ans + t * s[cnt++] % MOD * sum[j]) % MOD;
} else {
ans = (ans + t * s[cnt++] % MOD * sum[j] * 2) % MOD;
}
tmp /= 10;
}
}
}
cout << ans << endl;
return 0;
}
| 1,800 | CPP |
#include <bits/stdc++.h>
using namespace std;
class TaskA {
public:
void solve(std::istream& in, std::ostream& out) {
int n;
in >> n;
vector<int> ans;
for (int i = 0; i < n; i++) {
bool flag = false;
for (int j = 0; j < n; j++) {
int temp;
in >> temp;
if (temp == 1 || temp == 3) flag = true;
}
if (!flag) ans.push_back(i + 1);
}
out << ans.size() << endl;
for (int i = 0; i < ans.size(); i++) out << ans[i] << ' ';
}
};
int main() {
TaskA solver;
std::istream& in(std::cin);
std::ostream& out(std::cout);
solver.solve(in, out);
return 0;
}
| 900 | CPP |
totalWorkers = int(input())
counter = 0
for i in range(1, totalWorkers):
leaders = i
if (totalWorkers - leaders)%leaders == 0:
counter += 1
print(counter)
| 800 | PYTHON3 |
t=int(input())
for _ in range(t):
n=int(input())
s=str(n)
while len(s)>1:
l=len(s)
r=int(s[0])*(10**(l-1))
s=int(s)
s=s-r+r//10
n+=r//10
s=str(s)
print (n) | 900 | PYTHON3 |
N=int(input())+1
N=str(N)
while(N[0]==N[1] or N[1]==N[2] or N[2]==N[3] or N[0]==N[2] or N[0]==N[3] or N[1]==N[3]):
N=int(N)+1
N=str(N)
print(N)
| 800 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int i, j, k, l, m, n, a, b, c, d, x, y, z, tc, ans, num[1000005], w,
lastNum, v1, v2, p, t;
string inputA, inputB;
while (cin >> n) {
bool willWin = true;
if (n == 5) {
willWin = false;
long long int nums[5] = {0};
for (i = 0; i < n; i++) {
cin >> a >> b;
++nums[a - 1];
++nums[b - 1];
}
for (i = 0; i < 5; i++) {
if (nums[i] != 2) {
willWin = true;
break;
}
}
} else {
for (i = 0; i < n; i++) {
cin >> a >> b;
}
}
std::cout << (willWin ? "WIN" : "FAIL") << std::endl;
}
return 0;
}
| 1,300 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int INF = 987654321;
const int MOD = 1000000007;
int main() {
int n, m;
scanf("%d %d", &n, &m);
int arr[200001] = {};
for (int i = 0; i < n; i++) {
scanf("%d", arr + i);
}
int val = 0;
for (int i = 0; i < n; i++) {
val += arr[i];
printf("%d ", val / m);
if (val / m) val -= m * (val / m);
}
}
| 900 | CPP |
#include <bits/stdc++.h>
using namespace std;
void write(vector<int> &v) {
for (auto i : v) cout << i << " ";
cout << "\n";
}
void read(vector<int> &v) {
for (auto &i : v) cin >> i;
}
const int INF = 1e9;
const int64_t INFF = 1e18;
const int N = 1e6 + 69;
void solve() {
int n;
cin >> n;
vector<int> v(n);
read(v);
vector<vector<int>> total_cnt(202);
int ans = 0;
for (int i = 0; i < n; i++) {
total_cnt[v[i]].push_back(i);
ans = max((int)(total_cnt[v[i]]).size(), ans);
}
vector<int> run_cnt(202);
for (int i = 0; i < n; i++) {
int cnt = ++run_cnt[v[i]];
int total = total_cnt[v[i]].size();
if (total - 2 * cnt < 0) continue;
int last = total_cnt[v[i]][total - cnt];
for (int j = 1; j < 201; j++) {
if (j == v[i]) continue;
int f = lower_bound((total_cnt[j]).begin(), (total_cnt[j]).end(), i + 1) -
total_cnt[j].begin();
int l = lower_bound((total_cnt[j]).begin(), (total_cnt[j]).end(), last) -
total_cnt[j].begin();
ans = max(ans, 2 * cnt + l - f);
}
}
cout << ans << "\n";
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
cin >> t;
for (int i = 1; i <= t; i++) {
solve();
}
return 0;
}
| 1,700 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 1; i < n; i++) cout << a[i] + a[i - 1] << " ";
cout << a[n - 1];
}
| 800 | CPP |
t = int(input())
for _ in range(t):
n = int(input())
a = [int(j) for j in input().split()]
b = [int(j) for j in input().split()]
if b.count(b[0]) == len(b):
flag = 0
for i in range(n-1):
if a[i] > a[i+1]:
flag = 1
break
if flag == 1:
print("No")
else:
print("Yes")
else:
print("Yes") | 1,300 | PYTHON3 |
import math
F=lambda c:c*(c+1)//2
def find(n):
x=int(math.sqrt(2*n))
cal=F(x)
if(cal>n):
x-=1
cal=F(x)
return [n-cal,x]
for _ in range(int(input())):
n,k=map(int,input().split())
fi=find(k-1)
f3=max(fi[0],0)
f2=max(fi[1]-f3,0)
f1=max(n-2-f2-f3,0)
ans='a'*f1+'b'+'a'*f2+'b'+'a'*f3
print(ans)
#print(fi,f1,f2,f3)
| 1,300 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
const int BUFFER_SIZE = 1 << 20;
const int INF = 1 << 30;
const long long LINF = 1ll << 60;
char BUFFER[BUFFER_SIZE];
int gi() {
int x;
scanf("%d", &x);
return x;
}
double gd() {
double x;
scanf("%lf", &x);
return x;
}
vector<int> gvi(int n) {
vector<int> a;
while (n--) a.push_back(gi());
return a;
}
string gs() {
scanf("%s", BUFFER);
return string(BUFFER);
}
istringstream buff() { return istringstream(string(BUFFER)); }
template <class T>
struct forArray {
T* a;
int n;
forArray(T* a, int n) : a(a), n(n) {}
};
template <class A, class B>
ostream& operator<<(ostream& os, const pair<A, B>& d);
template <class T>
ostream& operator<<(ostream& os, const vector<T>& d);
template <class T>
ostream& operator<<(ostream& os, const queue<T>& d);
template <class T>
ostream& operator<<(ostream& os, const stack<T>& d);
template <class T>
ostream& operator<<(ostream& os, const set<T>& d);
template <class T>
ostream& operator<<(ostream& os, const multiset<T>& d);
template <class T>
ostream& operator<<(ostream& os, const unordered_set<T>& d);
template <class A, class B>
ostream& operator<<(ostream& os, const map<A, B>& d);
template <class A, class B>
ostream& operator<<(ostream& os, const multimap<A, B>& d);
template <class A, class B>
ostream& operator<<(ostream& os, const unordered_map<A, B>& d);
template <class T>
ostream& operator<<(ostream& os, const vector<T>& d) {
os << "[";
int f = 0;
for (auto x : d) {
if (f) os << ",";
f = 1;
os << x;
}
return os << "]";
};
template <class T>
ostream& operator<<(ostream& os, const queue<T>& d) {
os << "[";
int f = 0;
for (auto x : d) {
if (f) os << ",";
f = 1;
os << x;
}
return os << "]";
};
template <class T>
ostream& operator<<(ostream& os, const stack<T>& d) {
os << "[";
int f = 0;
for (auto x : d) {
if (f) os << ",";
f = 1;
os << x;
}
return os << "]";
};
template <class T>
ostream& operator<<(ostream& os, const set<T>& d) {
os << "[";
int f = 0;
for (auto x : d) {
if (f) os << ",";
f = 1;
os << x;
}
return os << "]";
};
template <class T>
ostream& operator<<(ostream& os, const multiset<T>& d) {
os << "[";
int f = 0;
for (auto x : d) {
if (f) os << ",";
f = 1;
os << x;
}
return os << "]";
};
template <class T>
ostream& operator<<(ostream& os, const unordered_set<T>& d) {
os << "[";
int f = 0;
for (auto x : d) {
if (f) os << ",";
f = 1;
os << x;
}
return os << "]";
};
template <class A, class B>
ostream& operator<<(ostream& os, const map<A, B>& d) {
os << "[";
int f = 0;
for (auto x : d) {
if (f) os << ",";
f = 1;
os << x;
}
return os << "]";
};
template <class A, class B>
ostream& operator<<(ostream& os, const multimap<A, B>& d) {
os << "[";
int f = 0;
for (auto x : d) {
if (f) os << ",";
f = 1;
os << x;
}
return os << "]";
};
template <class A, class B>
ostream& operator<<(ostream& os, const unordered_map<A, B>& d) {
os << "[";
int f = 0;
for (auto x : d) {
if (f) os << ",";
f = 1;
os << x;
}
return os << "]";
};
template <class T>
ostream& operator<<(ostream& os, const forArray<T>& d) {
os << "[";
for (int i = 0; i < d.n; ++i) {
if (i) os << ",";
os << d.a[i];
}
return os << "]";
}
template <class A, class B>
ostream& operator<<(ostream& os, const pair<A, B>& d) {
return os << "[" << d.first << ", " << d.second << "]";
}
map<vector<int>, int> ID;
vector<vector<int>> G;
vector<vector<double>> C;
vector<vector<int>> points;
int id(vector<int> p) {
if (!ID.count(p)) {
ID[p] = points.size();
points.push_back(p);
G.push_back(vector<int>());
C.push_back(vector<double>());
}
return ID[p];
}
int dist(vector<int> p1, vector<int> p2, vector<int> p3, vector<int> p4) {
int r = 1 << 30;
for (vector<int> a : {p1, p2}) {
for (vector<int> b : {p3, p4}) {
r = min(
r, ((a[0] - b[0]) * (a[0] - b[0])) + ((a[1] - b[1]) * (a[1] - b[1])));
}
}
int v1 = max(min(p3[1], p4[1]), min(p1[1], p2[1]));
int v2 = min(max(p3[1], p4[1]), max(p1[1], p2[1]));
if (v1 <= v2) {
for (int x1 : {p1[0], p2[0]}) {
for (int x2 : {p3[0], p4[0]}) {
r = min(r, ((x1 - x2) * (x1 - x2)));
}
}
}
v1 = max(min(p3[0], p4[0]), min(p1[0], p2[0]));
v2 = min(max(p3[0], p4[0]), max(p1[0], p2[0]));
if (v1 <= v2) {
for (int x1 : {p1[1], p2[1]}) {
for (int x2 : {p3[1], p4[1]}) {
r = min(r, ((x1 - x2) * (x1 - x2)));
}
}
}
return r;
}
int main() {
int A = gi();
int B = gi();
int st = id(gvi(2));
int en = id(gvi(2));
int d0 = ((points[0][0] - points[1][0]) * (points[0][0] - points[1][0])) +
((points[0][1] - points[1][1]) * (points[0][1] - points[1][1]));
if (d0 <= A * A) {
printf("%.20lf\n", sqrt(d0));
} else {
int m = gi();
for (int i = 0; i < m; ++i) {
int a = id(gvi(2));
int b = id(gvi(2));
G[a].push_back(b);
C[a].push_back(0);
G[b].push_back(a);
C[b].push_back(0);
}
for (int i = 2; i < points.size(); i += 2) {
for (int j = 2; j < points.size(); j += 2) {
if (i != j) {
int d = dist(points[i], points[i ^ 1], points[j], points[j ^ 1]);
if (d <= A * A) {
G[i].push_back(j);
C[i].push_back(A + B);
}
}
}
}
for (int i = 2; i < points.size(); i += 2) {
int d = dist(points[0], points[0], points[i], points[i ^ 1]);
if (d <= A * A) {
G[0].push_back(i);
C[0].push_back(A + B);
}
d = dist(points[1], points[1], points[i], points[i ^ 1]);
if (d <= A * A) {
G[i].push_back(1);
C[i].push_back(sqrt(d));
}
}
set<pair<int, int>> Q;
vector<double> D(points.size(), -1.0);
Q.insert({0, st});
D[st] = 0.0;
while (Q.size()) {
int x = Q.begin()->second;
Q.erase(Q.begin());
for (int i = 0; i < G[x].size(); ++i) {
if (D[G[x][i]] < 0 || D[G[x][i]] > D[x] + C[x][i]) {
Q.erase({D[G[x][i]], G[x][i]});
D[G[x][i]] = D[x] + C[x][i];
Q.insert({D[G[x][i]], G[x][i]});
}
}
}
if (D[en] < 0)
printf("-1\n");
else
printf("%.20lf\n", D[en]);
}
return 0;
}
| 2,200 | CPP |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,unroll-loops")
using namespace std;
const int maxn = 100010;
int n, K;
vector<pair<int, int>> ans;
mt19937 rnd(time(0));
struct seg {
long long a, b, c, id;
bool para(seg o) { return a * o.b == b * o.a; }
seg inter(seg o) {
return (seg){c * o.b - b * o.c, a * o.c - c * o.a, a * o.b - b * o.a};
}
bool chk(seg o) { return a * o.a + b * o.b == c * o.c; }
};
vector<seg> V;
int main() {
scanf("%d %d", &n, &K);
for (int i = 1, a, b, c; i <= n; i++) {
scanf("%d %d %d", &a, &b, &c);
V.push_back((seg){a, b, -c, i});
}
for (; !V.empty() && K; K--) {
pair<int, int> p(V[0].id, -1);
vector<seg> nV = V;
for (int $ = 0; $ < 50 && V.size() - nV.size() <= K; $++) {
int i = rnd() % V.size(), j = rnd() % V.size();
if (V[i].para(V[j])) continue;
vector<seg> T;
auto q = V[i].inter(V[j]);
for (int k = 0; k < V.size(); k++) {
if (!V[k].chk(q)) T.push_back(V[k]);
}
if (T.size() < nV.size()) nV = T, p = {V[i].id, V[j].id};
}
ans.push_back(p);
if (!~p.second)
V.erase(V.begin());
else
V = nV;
}
if (!V.empty()) puts("NO"), exit(0);
printf("YES\n%d\n", ans.size());
for (auto p : ans) printf("%d %d\n", p.first, p.second);
return 0;
}
| 2,800 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 10;
const long double eps = 1e-6;
const int INF = 1e8;
struct asd {
long double t;
int y1, y2;
};
asd a[MAXN];
int x1, x2, t1, t2, t0;
long double mod(long double x) {
if (x > 0)
return x;
else
return -x;
}
bool operator<(asd a, asd b) {
if (mod(a.t - b.t) > eps)
return a.t < b.t;
else
return (a.y1 + a.y2) > (b.y1 + b.y2);
}
long double f(long double y1, long double y2) {
if (y1 == 0 && y2 == 0) return INF;
return ((y1 * t1) + (y2 * t2)) / (y1 + y2);
}
asd tr(int k) {
int l, r;
long double x, xr;
asd z1;
l = 0;
r = x2;
z1.y1 = k;
while (l + 1 < r) {
x = f(k, (l + r) / 2) - t0;
xr = f(k, r) - t0;
if (!(mod(x - xr) < eps) && x + eps > 0)
r = (l + r) / 2;
else
l = (l + r) / 2;
}
z1.t = f(k, r) - t0;
if (z1.t < 0) z1.t = INF;
z1.y2 = r;
return z1;
}
int main() {
int i;
cin >> t1 >> t2 >> x1 >> x2 >> t0;
if (t0 == t2) {
if (t1 == t2)
cout << x1 << " " << x2;
else
cout << 0 << " " << x2;
return 0;
}
if (t0 == t1) {
cout << x1 << " " << 0;
return 0;
}
for (i = 0; i <= x1; i++) {
a[i] = tr(i);
}
sort(a, a + x1 + 1);
cout << a[0].y1 << " " << a[0].y2;
return 0;
}
| 1,900 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[3][3];
struct Node {
long long int dp[3][3];
} node[10 * 100000];
void calc(int nid) {
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
long long int ans = 0;
for (int k = 0; k < 3; k++) {
for (int l = 0; l < 3; l++) {
if (a[k][l])
ans += (node[nid * 2 + 1].dp[i][k] * node[nid * 2 + 2].dp[l][j]) %
777777777;
}
}
node[nid].dp[i][j] = ans % 777777777;
}
}
}
void initial(int nid, int st, int ed) {
Node& now = node[nid];
if (st == ed) {
for (int i = 0; i < 3; i++)
for (int j = 0; j < 3; j++) now.dp[i][j] = 0;
for (int i = 0; i < 3; i++) now.dp[i][i] = 1;
return;
}
int md = (st + ed) / 2;
initial(2 * nid + 1, st, md);
initial(2 * nid + 2, md + 1, ed);
calc(nid);
}
void dfs(int nid, int st, int ed, int v, int t) {
Node& now = node[nid];
if (st == ed) {
for (int i = 0; i < 3; i++)
for (int j = 0; j < 3; j++) now.dp[i][j] = 0;
if (t == 0)
for (int i = 0; i < 3; i++) now.dp[i][i] = 1;
else
now.dp[t - 1][t - 1] = 1;
return;
}
int md = (st + ed) / 2;
if (v <= md)
dfs(2 * nid + 1, st, md, v, t);
else
dfs(2 * nid + 2, md + 1, ed, v, t);
calc(nid);
}
void go() {
scanf("%d%d", &n, &m);
for (int i = 0; i < 3; i++)
for (int j = 0; j < 3; j++) scanf("%d", &a[i][j]);
initial(0, 1, n);
for (int i = 0; i < m; i++) {
int v, t;
scanf("%d%d", &v, &t);
dfs(0, 1, n, v, t);
long long int ans = 0;
for (int i = 0; i < 3; i++)
for (int j = 0; j < 3; j++) ans = ans + node[0].dp[i][j];
ans %= 777777777;
printf("%d\n", ans);
fflush(stdout);
}
}
int main() {
go();
return 0;
}
| 2,400 | CPP |
#include <bits/stdc++.h>
using namespace std;
pair<int, int> arr[200010];
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
int i, n, a, b, x, y;
cin >> n;
for (i = 0; i < n; i++) {
cin >> a >> b;
arr[i] = {a, b};
}
if (n & 1) {
cout << "NO\n";
return 0;
}
x = (arr[0].first + arr[n / 2].first);
y = (arr[0].second + arr[n / 2].second);
for (i = 1; i < n / 2; i++) {
a = (arr[i].first + arr[i + n / 2].first);
b = (arr[i].second + arr[i + n / 2].second);
if (a != x || b != y) {
cout << "NO\n";
return 0;
}
}
cout << "YES\n";
return 0;
}
| 1,800 | CPP |
#include <bits/stdc++.h>
using namespace std;
template <class A>
void pr(A a) {
cout << a;
cout << '\n';
}
template <class A, class B>
void pr(A a, B b) {
cout << a << ' ';
pr(b);
}
template <class A, class B, class C>
void pr(A a, B b, C c) {
cout << a << ' ';
pr(b, c);
}
template <class A, class B, class C, class D>
void pr(A a, B b, C c, D d) {
cout << a << ' ';
pr(b, c, d);
}
template <class A>
void PR(A a, long long n) {
for (long long i = (long long)(0); i < (long long)(n); i++) {
if (i) cout << ' ';
cout << a[i];
}
cout << '\n';
}
long long check(long long n, long long m, long long x, long long y) {
return x >= 0 && x < n && y >= 0 && y < m;
}
const long long MAX = 1e9 + 7, MAXL = 1LL << 61, dx[4] = {-1, 0, 1, 0},
dy[4] = {0, 1, 0, -1};
vector<long long> v[333333];
long long n, s, t;
long long dfs(long long x, long long p) {
if (x == t) return -1;
long long cnt = 0;
for (long long i = (long long)(0); i < (long long)(v[x].size()); i++) {
long long y = v[x][i];
if (y == p) continue;
long long d = dfs(y, x);
if (d == -1) {
if (x != s) return -1;
} else
cnt += d;
}
return cnt + 1;
}
void Main() {
cin >> n >> s >> t;
s--, t--;
for (long long i = (long long)(0); i < (long long)(n - 1); i++) {
long long x, y;
cin >> x >> y;
x--, y--;
v[x].push_back(y);
v[y].push_back(x);
}
long long x = dfs(s, -1);
swap(s, t);
long long y = dfs(s, -1);
pr(n * (n - 1) - x * y);
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
Main();
return 0;
}
| 1,600 | CPP |
n = int(input())
maze = [input().strip() for _ in range(n)]
def go(by_row):
global maze
maze = list(zip(*maze))
can = True
for i in range(n):
if '.' not in maze[i]:
can = False
if can:
for i in range(n):
for j in range(n):
if maze[i][j] == '.':
print(i + 1, j + 1) if by_row else print(j + 1, i + 1)
break
return can
if not go(0) and not go(1):
print(-1) | 1,500 | PYTHON3 |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:1000000000")
using namespace std;
const bool db = false;
int p[7], k, n;
int cnt = 0, tot = 0;
int inv() {
int ans = 0;
for (int i = 1; i <= n; ++i)
for (int j = i + 1; j <= n; ++j) ans += (p[i] > p[j]);
return ans;
}
void calc(int it) {
if (it == 0) {
tot += inv();
++cnt;
return;
}
for (int l = 1; l <= n; ++l) {
for (int r = l; r <= n; ++r) {
int op[7];
for (int k = 1; k <= n; ++k) op[k] = p[k];
reverse(p + l, p + r + 1);
calc(it - 1);
for (int k = 1; k <= n; ++k) p[k] = op[k];
}
}
}
int main() {
scanf("%d%d", &n, &k);
for (int i = 1; i <= n; ++i) cin >> p[i];
calc(k);
cout.precision(15);
cout << fixed << 1.0 * tot / cnt << "\n";
getchar();
getchar();
return 0;
}
| 1,800 | CPP |
#include <bits/stdc++.h>
using namespace std;
unsigned long long gcd(unsigned long long a, unsigned long long b) {
unsigned long long c;
while (a != 0) {
c = a;
a = b % a;
b = c;
}
return b;
}
string rs, rss, rsss, s[3];
int z[100010];
void fail(string s) {
memset(z, 0, (int)sizeof z);
for (int i = 1, j = 0; i < s.size(); i++) {
while (j > 0 && s[i] != s[j]) j = z[j - 1];
if (s[i] == s[j])
z[i] = ++j;
else
z[i] = j;
}
}
bool KMPfind(string &s, string &p) {
for (int i = 0, j = 0; i < s.size(); i++) {
while (j > 0 && p[j] != s[i]) j = z[j - 1];
if (p[j] == s[i]) j++;
if (j == p.size()) return 1;
}
return 0;
}
string KMPapp(string s, string p) {
int j = 0;
for (int i = 0; i < s.size(); i++) {
while (j > 0 && p[j] != s[i]) j = z[j - 1];
if (p[j] == s[i]) j++;
}
s += p.substr(j, -1);
return s;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
while (cin >> s[0] >> s[1] >> s[2]) {
int arr[3] = {0, 1, 2};
vector<string> v;
do {
string get = s[arr[0]];
fail(s[arr[1]]);
if (!KMPfind(s[arr[0]], s[arr[1]])) get = KMPapp(s[arr[0]], s[arr[1]]);
fail(s[arr[2]]);
if (!KMPfind(get, s[arr[2]])) get = KMPapp(get, s[arr[2]]);
v.push_back(get);
} while (next_permutation(arr, arr + 3));
int minn = 1000000000;
for (int i = 0; i < v.size(); i++) minn = min((int)v[i].size(), minn);
cout << minn << "\n";
}
return 0;
}
| 2,200 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int T; cin >> T;
while(T--){
int X[210] = {};
int N, M; cin >> N >> M;
for(int i = 0; i < N; i++){
for(int j = 0; j < M; j++){
int a; cin >> a;
X[i+j] ^= a;
}
}
bool ok = true;
for(int i = 0; i < N+M-1; i++){
if(X[i]) ok = false;
}
cout << (ok ? "Jeel\n" : "Ashish\n");
}
} | 2,700 | CPP |
#include <bits/stdc++.h>
const long long inf = 1e9;
const long long mod = 1e9 + 7;
const long long zero = 0;
const long long maxn = 1e6 + 5;
using namespace std;
long long n, l, r, q;
pair<long long, pair<long long, long long>> t[2 * maxn];
pair<long long, pair<long long, long long>> combine(
pair<long long, pair<long long, long long>> s1,
pair<long long, pair<long long, long long>> s2) {
long long a1 = s1.first, b1 = s1.second.first, c1 = s1.second.second,
a2 = s2.first, b2 = s2.second.first, c2 = s2.second.second;
long long a, b, c;
long long t = min(b1, c2);
a = a1 + a2 + t;
b = b1 + b2 - t;
c = c1 + c2 - t;
pair<long long, pair<long long, long long>> res = {a, {b, c}};
return res;
}
void build() {
for (int i = n - 1; i > 0; i--) t[i] = combine(t[i << 1], t[i << 1 | 1]);
}
pair<long long, pair<long long, long long>> query(int l, int r) {
pair<long long, pair<long long, long long>> resl = {0, {0, 0}},
resr = {0, {0, 0}};
for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
if (l & 1) resl = combine(resl, t[l++]);
if (r & 1) resr = combine(t[--r], resr);
}
return combine(resl, resr);
}
string s;
int main() {
cin >> s;
n = s.size();
for (int i = 0; i < n; i++) {
if (s[i] == '(')
t[i + n] = {0, {1, 0}};
else
t[i + n] = {0, {0, 1}};
}
build();
cin >> q;
for (int i = 0; i < q; i++) {
cin >> l >> r;
l--;
cout << query(l, r).first * 2 << endl;
}
}
| 2,000 | CPP |
#include <bits/stdc++.h>
using namespace std;
inline int min_index(vector<int> first, int l, int h) {
int min = 99999, res = 0;
for (int i = l; i < h; i++)
if (min > first[i]) res = i, min = first[i];
return res;
}
int main() {
ios_base::sync_with_stdio(false);
int n;
cin >> n;
vector<int> a(n), p(n);
vector<int> sums(n);
for (int i = 0; i < n; i++) cin >> a[i] >> p[i];
sums[0] = a[0];
for (int i = 1; i < n; i++) sums[i] = sums[i - 1] + a[i];
int m = n, m1;
int sum = 0;
while ((m1 = min_index(p, 0, m)) != 0)
sum += (sums[m - 1] - sums[m1] + a[m1]) * p[m1], m = m1;
sum += (sums[m - 1]) * p[0];
cout << sum << endl;
return 0;
}
| 900 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, l, r, a[105] = {0}, k[105], t[105], i, j, p = 0;
cin >> n >> m;
for (i = 1; i <= m; i++) {
cin >> l >> r >> t[i] >> k[i];
for (j = l; j <= r; j++) {
if (!a[j] || t[i] < t[a[j]]) a[j] = i;
}
}
k[0] = 0;
for (i = 1; i <= n; i++) {
p += k[a[i]];
}
cout << p;
return 0;
}
| 1,200 | CPP |
#include <bits/stdc++.h>
using namespace std;
ostream& operator<<(ostream& str, const pair<int, int>& p) {
str << p.first << " " << p.second;
return str;
}
template <typename T>
void join(T& arr, string sep) {
bool first = true;
for (auto t : arr) {
if (first) {
first = false;
cout << t;
} else {
cout << sep << t;
}
}
cout << "\n";
}
const int md = 1e9 + 7;
int MOD(int x) {
int r = x % md;
if (r < 0) {
r += md;
}
return r;
}
void solve() {
int n, m, k;
cin >> n >> m >> k;
int res = 0;
vector<vector<pair<int, int>>> g(n);
for (int i = 0; i < (int)(m); ++i) {
int u, v, w;
cin >> u >> v >> w;
u--;
v--;
g[u].push_back({w, v});
}
vector<map<pair<int, int>, int>> inn(n);
for (int u = 0; u < (int)(n); ++u) {
if (g[u].empty()) {
cout << 0 << endl;
return;
}
sort(g[u].begin(), g[u].end());
for (int i = 0; i < (int)(g[u].size()); ++i) {
g[u][i].first = i + 1;
inn[g[u][i].second][{g[u].size(), i + 1}]++;
}
}
vector<vector<vector<vector<int>>>> bad(
k + 1, vector<vector<vector<int>>>(
k + 1, vector<vector<int>>(k + 1, vector<int>(k + 1, 0))));
for (int u = 0; u < (int)(n); ++u) {
if (inn[u].empty()) {
cout << 0 << endl;
return;
}
for (auto& kv1 : inn[u]) {
if (kv1.second > 1) {
bad[kv1.first.first][kv1.first.second][kv1.first.first]
[kv1.first.second] = 1;
}
for (auto& kv2 : inn[u]) {
if (kv1.first == kv2.first && kv1.second == kv2.second) continue;
bad[kv1.first.first][kv1.first.second][kv2.first.first]
[kv2.first.second] = 1;
}
}
}
vector<int> cur(k);
function<void(int)> permute = [&](int i) {
if (i >= k) {
bool success = true;
for (int ii = 0; ii < (int)(k); ++ii) {
for (int jj = (int)(ii + 1); jj < (int)(k); ++jj) {
if (bad[ii + 1][cur[ii]][ii + 1][cur[ii]] ||
bad[jj + 1][cur[jj]][jj + 1][cur[jj]]) {
success = false;
break;
}
if (bad[ii + 1][cur[ii]][jj + 1][cur[jj]] ||
bad[jj + 1][cur[jj]][ii + 1][cur[ii]]) {
success = false;
break;
}
}
if (!success) break;
}
if (success) res++;
return;
}
for (int j = (int)(1); j < (int)(i + 2); ++j) {
cur[i] = j;
permute(i + 1);
}
};
permute(0);
cout << res << "\n";
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int tt = 1;
for (int t = 1; t <= tt; t++) {
solve();
}
return 0;
}
| 2,300 | CPP |
s=input("")
list1=[]
m=s.replace('WUB','!')
l=m.replace('!!','!')
for i in l:
list1.append(i)
if list1[0]=='!':
print(l[1:].replace('!',' '))
else:
print(l.replace('!',' '))
| 900 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
inline long long read() {
long long x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
long long n, cnt;
long long a[200010];
long long p[200010], rep[200010];
long long ans = 1;
inline long long quickpow(long long a, long long b, long long MOD) {
long long s = 1;
a %= MOD;
b = b % (MOD - 1);
while (b) {
if (b & 1) s = (s * a) % MOD;
a = (a * a) % MOD;
b >>= 1;
}
return s;
}
int main() {
n = read();
for (int i = 1; i <= n; i++) a[i] = read();
sort(a + 1, a + n + 1);
for (int i = 1; i <= n; i++)
if (i == 1 || a[i] != a[i - 1]) {
p[++cnt] = a[i];
rep[cnt] = 1;
} else
rep[cnt]++;
long long pro = 1;
for (int i = 1; i <= cnt; i++)
pro = (pro * (rep[i] + 1)) % (2 * 1000000007 - 2);
for (int i = 1; i <= cnt; i++) {
ans = ans *
quickpow(p[i], pro * rep[i] / 2 % (2 * 1000000007 - 2), 1000000007) %
1000000007;
}
printf("%lld\n", ans % 1000000007);
}
| 2,000 | CPP |
#include <bits/stdc++.h>
using namespace std;
using llint = long long;
bool solve(llint a, llint b) {
if (a > b) swap(a, b);
if (!a) return false;
if (!solve(b % a, a)) return true;
return b / a % (a + 1) % 2 == 0;
}
int main() {
int t;
scanf("%d", &t);
while (t--) {
llint a, b;
scanf("%lld%lld", &a, &b);
puts(solve(a, b) ? "First" : "Second");
}
}
| 2,300 | CPP |
# Solution for Codeforces problem 757A.
from collections import defaultdict
import time
from functools import partial
"""
We need to normalize the dictionary b/c there are repeating letters.
How can this normalization be done?
The number of letter repeatance can be found for each repeating letter.
Then that number can be used to divide total count of the repeating letter.
This means a dictionary must contain two things: count and number of repeat.
Or there must be two dictionaries.
I prefer a single dictinoary.
Another solution might be having a single dictinoary that contains the letter as the key
and a function as the value.
Can you make a function that counts on a given number?
(e.g. calling func(3) three times would result to 1, 6 times results to 2.
"""
def normalizer(num, letter):
"""Count the numbers of given letter"""
count = 0
def inner(new_letter):
nonlocal count
if new_letter is None:
return count / num
if (new_letter != letter):
raise AssertError('{} does not equal to {}'.format(new_letter, letter))
count += 1
return count / num
return inner
def get_number_of_unique_chars(text):
"""Count unique letters in given text."""
return len(set(text))
def count_keyword(text, keyword):
"""Count "{keyword}" in the given text."""
keyword_dict = {t: normalizer(keyword.count(t), t) for t in keyword}
for t in text:
if t not in keyword:
continue
keyword_dict[t](t)
if len(keyword_dict.keys()) == get_number_of_unique_chars(keyword):
return int(min([func(None) for func in keyword_dict.values()]))
return 0
def main():
keyword = 'Bulbasaur'
text = input()
print(count_keyword(text, keyword))
if __name__ == '__main__':
main()
| 1,000 | PYTHON3 |
word = input()
if len(word)>1:
if word.isupper() == True:
print(word.lower())
elif word[0].islower() == True and word[1:].isupper() == True:
print(word.title())
else:
print(word)
else:
if word.isupper() == True:
print(word.lower())
elif word.islower() == True:
print(word.upper()) | 1,000 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m, q;
while (cin >> n >> m >> q) {
struct BIT {
int n;
vector<int> tree;
function<int(int, int)> f;
BIT(int n, int val, function<int(int, int)> f)
: n(n), tree(n, val), f(f) {}
void set(int i, int val) {
for (; i < n; i |= i + 1) {
tree[i] = f(tree[i], val);
}
}
int get(int i) {
int res = tree[i];
for (; i >= 0; i = (i & (i + 1)) - 1) {
res = f(res, tree[i]);
}
return res;
}
};
const int inf = 1e9;
BIT pref(n, inf, [&](int a, int b) { return min(a, b); });
BIT suf(n, -1, [&](int a, int b) { return max(a, b); });
bool good = true;
while (q--) {
int ii, jj;
cin >> ii >> jj;
--ii, --jj;
int i = ii / 2;
int j = jj / 2;
if (ii & 1) {
auto mi = pref.get(i);
if (mi <= j) {
good = false;
}
suf.set(n - i - 1, j);
} else {
auto ma = suf.get(n - i - 1);
if (ma >= j) {
good = false;
}
pref.set(i, j);
}
cout << (good ? "YES" : "NO") << "\n";
}
}
}
| 2,700 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long GCD(long long a, long long b) { return (b == 0) ? a : GCD(b, a % b); }
long long LCM(long long a, long long b) {
long long temp = GCD(a, b);
return temp ? (a / temp * b) : 0;
}
long long oo = 1e18;
vector<int> v;
long long const M = 1e6, N = 3e5 + 7;
long long n, m, sum, c, k, ans;
long long a1, a2, a3, x, y, t[N];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n;
vector<pair<pair<int, int>, int>> v(n);
for (int i = 0; i < n; i++) {
cin >> x >> y;
v[i] = make_pair(make_pair(y, x), i + 1);
}
sort(v.rbegin(), v.rend());
cin >> m;
vector<pair<int, int>> p(m), ans;
for (int i = 0; i < m; i++) {
cin >> x;
p[i] = make_pair(x, i + 1);
}
sort(p.begin(), p.end());
int idx;
for (int i = 0; i < n; i++) {
x = v[i].first.first, y = v[i].first.second;
idx = v[i].second;
for (int i = 0; i < m; i++) {
if (!t[i + 1] && y <= p[i].first) {
sum += x;
ans.push_back(make_pair(idx, p[i].second));
t[i + 1] = 1;
break;
}
}
}
cout << ans.size() << " " << sum << '\n';
for (int i = 0; i < ans.size(); i++) {
cout << ans[i].first << " " << ans[i].second << '\n';
}
return 0;
}
| 1,600 | CPP |
import math
n=int(input())
a=[]
for i in range(n):
a.append(list(map(int,input().split())))
m=int(math.sqrt((a[0][-1]*a[-1][-2])//a[0][-2]))
for i in range(n-1):
print(a[-1][i]//m,end=' ')
print(m)
| 1,300 | PYTHON3 |
#include <bits/stdc++.h>
#pragma GCC optimize(3)
using namespace std;
const int P = 998244353;
const int INF = 0x3f3f3f3f;
const long long INFLL = 0x3f3f3f3f3f3f3f3fll;
const int N = 1e6 + 5;
inline void max24(int &x, int &y, int a, int b, int c, int d) {
if (a < c) swap(a, c);
x = a;
y = max(b, d);
if (a != c) y = max(c, y);
}
struct node {
int l, r;
int max, s_max;
int cnt_max, tag_max;
int cnt_ava, tag_add;
long long sum;
node *lson, *rson;
void mark_max(int val) {
if (val >= max) return;
sum += 1ll * cnt_max * (val - max);
tag_max = max = val;
}
void mark_add(int val) {
if (val == 0) return;
sum += val * cnt_ava;
max += val, s_max += val;
tag_add += val, tag_max += val;
}
void push_down() {
lson->mark_add(tag_add), lson->mark_max(tag_max);
rson->mark_add(tag_add), rson->mark_max(tag_max);
tag_max = INF, tag_add = 0;
}
void update() {
push_down();
sum = lson->sum + rson->sum;
cnt_ava = lson->cnt_ava + rson->cnt_ava;
max24(max, s_max, lson->max, lson->s_max, rson->max, rson->s_max);
cnt_max = 0;
if (max == lson->max) cnt_max += lson->cnt_max;
if (max == rson->max) cnt_max += rson->cnt_max;
}
} pool[2 * N], *root;
int n, m, top = -1;
int a[N];
void B_T(node *now, int l, int r) {
now->l = l, now->r = r;
now->tag_max = INF;
if (l == r) {
now->max = -INF, now->s_max = -INF - 1;
now->cnt_max = 1;
now->cnt_ava = now->sum = 0;
return;
}
B_T(now->lson = &pool[++top], l, (l + r) / 2);
B_T(now->rson = &pool[++top], (l + r) / 2 + 1, r);
now->update();
}
void setmin(node *now, int l, int r, int val) {
int lr = (now->l + now->r) >> 1, rl = lr + 1;
if (now->l == l && now->r == r) {
if (val > now->s_max)
now->mark_max(val);
else {
now->push_down();
setmin(now->lson, l, lr, val);
setmin(now->rson, rl, r, val);
now->update();
}
return;
}
now->push_down();
if (r < rl)
setmin(now->lson, l, r, val);
else if (l > lr)
setmin(now->rson, l, r, val);
else
setmin(now->lson, l, lr, val), setmin(now->rson, rl, r, val);
now->update();
}
void setval(node *now, int id, int val) {
if (now->l == now->r) {
now->sum = now->max = val;
now->cnt_ava = 1;
return;
}
now->push_down();
if (id <= (now->l + now->r) / 2)
setval(now->lson, id, val);
else
setval(now->rson, id, val);
now->update();
}
void addval(node *now, int l, int r, int val) {
int lr = (now->l + now->r) >> 1, rl = lr + 1;
if (now->l == l && now->r == r) {
now->mark_add(val);
return;
}
now->push_down();
if (r < rl)
addval(now->lson, l, r, val);
else if (l > lr)
addval(now->rson, l, r, val);
else
addval(now->lson, l, lr, val), addval(now->rson, rl, r, val);
now->update();
}
long long query_sum(node *now, int l, int r) {
int lr = (now->l + now->r) >> 1, rl = lr + 1;
if (now->l == l && now->r == r) return now->sum;
now->push_down();
if (r < rl) return query_sum(now->lson, l, r);
if (l > lr) return query_sum(now->rson, l, r);
return query_sum(now->lson, l, lr) + query_sum(now->rson, rl, r);
}
int query_max(node *now, int l, int r) {
int lr = (now->l + now->r) >> 1, rl = lr + 1;
if (now->l == l && now->r == r) return now->max;
now->push_down();
if (r < rl) return query_max(now->lson, l, r);
if (l > lr) return query_max(now->rson, l, r);
return max(query_max(now->lson, l, lr), query_max(now->rson, rl, r));
}
int pos[N], vpos[N], C[N];
long long ans[N];
inline int lowbit(int x) { return x & -x; }
inline void BIT_add(int id, int val) {
for (int i = id; i <= n; i += lowbit(i)) C[i] += val;
}
inline int BIT_query(int id) {
int res = 0;
for (int i = id; i > 0; i -= lowbit(i)) res += C[i];
return res;
}
void init() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]), pos[a[i]] = i;
for (int i = 1; i <= n; i++) {
BIT_add(pos[i], 1);
vpos[i] = BIT_query(pos[i]);
}
B_T(root = &pool[++top], 1, n);
for (int i = 1; i <= n; i++) {
setval(root, pos[i], i);
if (pos[i] - 1) setmin(root, 1, pos[i] - 1, vpos[i] - 1);
if (pos[i] + 1 <= n) addval(root, pos[i] + 1, n, 1);
ans[i] += root->sum;
}
memset(pool, 0, sizeof(pool));
B_T(root = &pool[++top], 1, n);
for (int i = 1; i <= n; i++) {
setval(root, pos[i], n);
if (pos[i] + 1 <= n) {
addval(root, pos[i] + 1, n, -1);
setmin(root, pos[i] + 1, n, n - vpos[i]);
}
ans[i] -= 1ll * n * i - root->sum;
}
for (int i = 1; i <= n; i++) printf("%lld\n", ans[i]);
}
int main() {
init();
return 0;
}
| 3,300 | CPP |