solution
stringlengths 10
983k
| difficulty
int64 0
25
| language
stringclasses 2
values |
---|---|---|
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while ('0' <= ch && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
return x * f;
}
int T, D, n;
long long C;
struct node {
int x, c;
} q[200009];
bool cmp(node a, node b) { return a.x < b.x; }
int main() {
T = read(), D = read(), n = read();
for (int i = 1; i <= n; i++) q[i].x = read(), q[i].c = read();
sort(q + 1, q + 1 + n, cmp);
q[n + 1].x = T;
n++;
int now = 0, nd = 0;
while (now != n) {
int g = now, mn = 0;
while (g < n && q[g + 1].x <= q[now].x + D) {
g++;
if (!mn || q[mn].c > q[g].c) mn = g;
if (q[now].c >= q[g].c) break;
}
if (g == now) {
puts("-1");
return 0;
}
if (q[now].c <= q[mn].c)
C += 1LL * (D - nd) * q[now].c, nd = D;
else
C += 1LL * (q[mn].x - q[now].x - nd) * q[now].c, nd = q[mn].x - q[now].x;
nd -= q[mn].x - q[now].x, now = mn;
}
printf("%I64d\n", C);
return 0;
}
| 10 | CPP |
t = int(input())
for case in range(t):
a, b, c, d = [int(s) for s in input().split(' ')]
print(b, c, c)
| 7 | PYTHON3 |
n = int(input())
a = []
for i in range(n):
a.append(int(input()))
b = []
for i in a:
c = (int(str(i)[0]) - 1) * 10
c += (1 + len(str(i)))*len(str(i))//2
b.append(c)
for i in b:
print(i) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main()
{
long long n, k;
cin >> n >> k;
vector<long long> v((int)1e5+1, 0);
for (int i = 0; i < n; i++)
{
int a, b;
cin >> a >> b;
v[a] += b;
}
long long i = 1, j = 0;
while (i < v.size() && j < k)
{
j += min(k-j, v[i]);
i++;
}
cout << i-1 << endl;
return 0;
}
| 0 | CPP |
n = int(input())
l = list(map(int,input().split()))
if l[0]%2:
if l[1]%2:
for i in range(2,n):
if l[i]%2==0:print(i+1)
else:
if l[2]%2:print(2)
else: print(1)
else:
if l[1]%2:
if l[2]%2:print(1)
else:print(2)
else:
if l[2]%2:print(3)
else:
for i in range(3,n):
if l[i]%2:print(i+1) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
vector<int> a, b;
int n;
cin >> n;
int tt;
for (long long i = 0; i < n; i++) {
cin >> tt;
a.push_back(tt);
}
cin >> n;
for (long long i = 0; i < n; i++) {
cin >> tt;
b.push_back(tt);
}
sort(a.rbegin(), a.rend());
sort(b.rbegin(), b.rend());
cout << a[0] << " " << b[0] << "\n";
return 0;
}
| 7 | CPP |
n = [int(i) for i in input()]
t = 0
for i in range(len(n) - 1):
if n[i] == n[i + 1]:
t += 1
if t >= 6:
print("YES")
break
else:
t = 0
else:
print("NO")
| 7 | PYTHON3 |
for _ in range(int(input())):
# n,s=map(int, input().split())
n=int(input())
a=list(map(int, input().split()))
c0=0
c1=0
for i in range(n):
if a[i]==0:
c0+=1
else:
c1+=1
if c0>=n//2:
print(n//2)
ans=[0 for i in range(n//2)]
print(*ans)
else:
if (n//2)%2:
print(n//2+1)
ans=[1 for i in range(n//2+1)]
else:
print(n//2)
ans=[1 for i in range(n//2)]
print(*ans)
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 10;
const int mod = 1e9 + 7;
int pre[N], suf[N], inv[N];
inline int power(int a, int b) {
int res = 1;
for (; b; b >>= 1, a = 1ll * a * a % mod)
if (b & 1) res = 1ll * res * a % mod;
return res;
}
int main() {
int n, m, s = 0, ans = 0;
scanf("%d%d", &n, &m);
if (m == 0) {
printf("%d\n", n);
return 0;
}
inv[1] = 1;
for (int i = 2; i <= m + 1; i++)
inv[i] = 1ll * (mod - mod / i) * inv[mod % i] % mod;
inv[0] = 1;
for (int i = 1; i <= m + 1; i++) inv[i] = 1ll * inv[i] * inv[i - 1] % mod;
pre[0] = n;
for (int i = 1; i <= m + 1; i++) pre[i] = 1ll * pre[i - 1] * (n - i) % mod;
suf[m + 1] = n - (m + 1);
for (int i = m; i >= 0; i--) suf[i] = 1ll * suf[i + 1] * (n - i) % mod;
for (int i = 0; i <= m + 1; i++) {
s = (s + power(i, m)) % mod;
int delta =
1ll * (i == 0 ? 1 : pre[i - 1]) * (i == m + 1 ? 1 : suf[i + 1]) % mod;
delta = 1ll * delta * inv[i] % mod * inv[m + 1 - i] % mod;
if ((m + 1 - i) & 1) delta = mod - delta;
ans = (ans + 1ll * s * delta % mod) % mod;
}
printf("%d\n", ans);
return 0;
}
| 12 | CPP |
#include <bits/stdc++.h>
using namespace std;
signed main() {
long long q;
cin >> q;
;
for (long long ii = 0; ii < q; ii++) {
long long n, k, sum = -1;
cin >> n;
vector<long long> a;
set<long long> s;
for (long long i = 0; i < n; i++) {
cin >> k;
s.insert(k);
}
for (auto k : s) a.push_back(k);
reverse(a.begin(), a.end());
for (long long i = 0; i < a.size(); i++) {
vector<long long> ans;
ans.push_back(a[i]);
for (long long j = i + 1; j < a.size(); j++) {
long long flag = 1;
for (int k = 0; k < ans.size(); k++) flag &= (ans[k] % a[j] != 0);
if (flag == 1) {
if (a[j] == 0) cout << j << endl << "j";
ans.push_back(a[j]);
if (ans.size() == 3) break;
}
}
sum = sum > accumulate(ans.begin(), ans.end(), 0)
? sum
: accumulate(ans.begin(), ans.end(), 0);
}
cout << sum << endl;
}
return 0;
}
| 12 | CPP |
#include <bits/stdc++.h>
using namespace std;
string BiggerLuckyNum(long long number) {
string ans, num = to_string(number);
int pos4 = -1;
for (int i = 0; i < num.size(); ++i) {
if (num[i] == '4') {
ans.append("4");
pos4 = i;
}
if (num[i] == '7') ans.append("7");
if (num[i] < '4' || num[i] == '5' || num[i] == '6') {
if (num[i] < '4') ans.append("4");
if (num[i] == '5' || num[i] == '6') ans.append("7");
++i;
for (; i < num.size(); ++i) ans.append("4");
return ans;
}
if (num[i] > '7') {
if (pos4 == -1) {
ans.clear();
for (int i = 0; i < num.size() + 1; ++i) ans.append("4");
return ans;
} else {
ans[pos4] = '7';
for (; i < num.size(); ++i) ans.append(" ");
for (i = pos4 + 1; i < num.size(); ++i) ans[i] = '4';
return ans;
}
}
}
return ans;
}
string SmallerLuckyNum(long long number) {
string ans, num = to_string(number);
int pos7 = -1;
for (int i = 0; i < num.size(); ++i) {
if (num[i] == '4') ans.append("4");
if (num[i] == '7') {
ans.append("7");
pos7 = i;
}
if (num[i] > '7' || num[i] == '5' || num[i] == '6') {
if (num[i] > '7') ans.append("7");
if (num[i] == '5' || num[i] == '6') ans.append("4");
++i;
for (i; i < num.size(); ++i) ans.append("7");
return ans;
}
if (num[i] < '4') {
if (pos7 == -1) {
ans.clear();
for (int i = 0; i < num.size() - 1; ++i) ans.append("7");
if (ans == "") return "0";
return ans;
} else {
ans[pos7] = '4';
for (i; i < num.size(); ++i) ans.append(" ");
for (i = pos7 + 1; i < num.size(); ++i) ans[i] = '7';
return ans;
}
}
}
return ans;
}
long long Min(long long a, long long b) {
if (b < 0 || a < 0) return 0;
if (a < b) return a;
return b;
}
double Probi(long long pl, long long pr, long long vl, long long vr, long k) {
long long min = pl;
if (min > pr) min = pr;
if (min > vl) min = vl;
if (min > vr) min = vr;
long long max = pl;
if (max < pr) max = pr;
if (max < vl) max = vl;
if (max < vr) max = vr;
vector<long long> luckyNum;
map<double, double> a, b;
long long i = min - 1;
if (min == 0) i = 0;
double pro = 0;
while (i <= max) {
i = stoull(BiggerLuckyNum(i + 1));
if (i <= max) luckyNum.push_back(i);
}
for (int i = 0; i < luckyNum.size(); ++i) {
long long m = luckyNum[i];
if (m < pl) {
a[m] = 0;
if (i == luckyNum.size() - 1)
a[-m] = pr - pl + 1;
else
a[-m] = Min(pr - pl + 1, luckyNum[i + 1] - pl);
}
if (m < vl) {
b[m] = 0;
if (i == luckyNum.size() - 1)
b[-m] = vr - vl + 1;
else
b[-m] = Min(vr - vl + 1, luckyNum[i + 1] - vl);
}
if (m > pr) {
a[-m] = 0;
if (i == 0)
a[m] = pr - pl + 1;
else
a[m] = Min(pr - pl + 1, pr - luckyNum[i - 1]);
}
if (m > vr) {
b[-m] = 0;
if (i == 0)
b[m] = vr - vl + 1;
else
b[m] = Min(vr - vl + 1, vr - luckyNum[i - 1]);
}
if (m >= pl && m <= pr) {
if (i == 0)
a[m] = m - pl + 1;
else
a[m] = Min(m - pl + 1, luckyNum[i] - luckyNum[i - 1]);
if (i == luckyNum.size() - 1)
a[-m] = pr - luckyNum[i] + 1;
else
a[-m] = Min(pr - m + 1, luckyNum[i + 1] - luckyNum[i]);
}
if (m >= vl && m <= vr) {
if (i == 0)
b[m] = m - vl + 1;
else
b[m] = Min(m - vl + 1, luckyNum[i] - luckyNum[i - 1]);
if (i == luckyNum.size() - 1)
b[-m] = vr - m + 1;
else
b[-m] = Min(vr - m + 1, luckyNum[i + 1] - luckyNum[i]);
}
}
for (long long i = k - 1; i < luckyNum.size(); ++i) {
long long x = luckyNum[i - k + 1];
long long y = luckyNum[i];
pro += a[x] * b[-y];
pro += a[-y] * b[x];
if (k == 1 && x >= pl && x <= pr && x >= vl && x <= vr && y >= pl &&
y <= pr && y >= vl && y <= vr)
--pro;
}
if (pro >= 0)
return pro;
else
return 0;
}
int main(int argc, const char* argv[]) {
long long pl, pr, vl, vr, k;
cin >> pl >> pr >> vl >> vr >> k;
double m = (pr - pl + 1) * (vr - vl + 1);
double ans = Probi(pl, pr, vl, vr, k) / m;
if (ans >= 1) ans = 1;
cout << fixed << setprecision(12) << ans << endl;
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, t;
cin >> n >> t;
long long a[n], i, c = 0;
for (i = 0; i < n; i++) cin >> a[i];
i = 0;
while (t) {
c++;
t -= min(t, (86400 - a[i]));
i++;
}
cout << c << endl;
}
| 7 | CPP |
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
int main() {
int n, m;
while (cin >> n >> m, n | m) {
vector<vector<int>> graph(n);
for (int i = 0; i < m; ++i) {
int a, b; cin >> a >> b; --a; --b;
graph[a].push_back(b);
graph[b].push_back(a);
}
vector<int> dist(n, 3);
queue<int> Q;
Q.push(0);
dist[0] = 0;
while (!Q.empty()) {
int v = Q.front(); Q.pop();
for (int w : graph[v]) {
if (dist[w] == 3) {
dist[w] = dist[v] + 1;
Q.push({w});
}
}
}
int ans = 0;
for (int d : dist)
if (d < 3) ++ans;
cout << ans - 1 << endl;
}
} | 0 | CPP |
#include<iostream>
#include<cstdio>
#include<cstring>
#include<climits>
#include<algorithm>
#include<cmath>
#include<queue>
using namespace std;
#define MAXN 100000
#define MAXM 100000
#define INF 1000000000000000
struct node
{
int next,to;
long long w;
}e[MAXM*2+5];
struct Qr
{
int xr,dec;
long long lim;
};
long long T;
int cnt,m,n;
int x,y,z,flag;
long long ri=INF,le=-INF;
long long vis[2][MAXN+5];
int b[MAXN+5];
void fpush(int u,int v,long long w)
{
e[++cnt].next=b[u];
e[cnt].w=w;
e[cnt].to=v;
b[u]=cnt;
}
int Ch(int x){if(x==-1)x=0;return x;}
int main()
{
fill(vis[0],vis[0]+MAXN+1,INF);
fill(vis[1],vis[1]+MAXN+1,INF);
scanf("%d%d",&n,&m);
for(int i=1;i<=m;i++)
{
scanf("%d%d%d",&x,&y,&z);
fpush(x,y,z);fpush(y,x,z);
}
queue<Qr> Q;
Q.push((Qr){1,1,0});
while(!Q.empty())
{
Qr A=Q.front();
Q.pop();
int xr=A.xr,dec=A.dec;
long long lim=A.lim;
for(int i=b[xr];i;i=e[i].next)
{
int xnext=e[i].to;
long long nlim=e[i].w-lim;
int FD=Ch(dec);
if(vis[FD][xnext]!=INF)
{
if(vis[FD][xnext]!=nlim){printf("0\n");return 0;}
else continue;
}
vis[FD][xnext]=nlim;
if(!FD)le=max(le,-vis[FD][xnext]);
else ri=min(ri,vis[FD][xnext]);
Q.push((Qr){xnext,-dec,nlim});
}
}
long long T=-1;
for(int i=1;i<=n;i++)
if(vis[0][i]!=INF&&vis[1][i]!=INF)
{
long long NT=(vis[1][i]-vis[0][i])/2;
if(NT<0){flag=1;break;}
if(T==-1)T=NT;
else if(T!=NT){flag=1;break;}
}
if(flag){printf("0\n");}
if(T!=-1)
{
if(T>le&&T<ri)printf("1\n");
else printf("0\n");
}
else printf("%lld",max((long long)0,ri-le-1));
} | 0 | CPP |
#!/usr/bin/env python3
from sys import stdin
from bisect import bisect_left, bisect_right
INF = int(1e9)
def find(par, a):
if par[a] == a:
return a
par[a] = find(par, par[a])
return par[a]
def union(par, rnk, a, b):
a = find(par,a)
b = find(par,b)
if a==b:
return
if rnk[a]<rnk[b]:
par[a] = b
else:
par[b] = a
if rnk[a]==rnk[b]:
rnk[a] += 1
def solve():
n, m, k = map(int, stdin.readline().split())
cnts = list(map(int, stdin.readline().split()))
for i in range(1,k):
cnts[i] += cnts[i-1]
group = list(range(n))
rnk = [0 for i in range(n)]
adj = [[INF for j in range(k)] for i in range(k)]
for i in range(m):
u, v, x = map(int, stdin.readline().split())
if x==0:
union(group, rnk, u-1, v-1)
tu = bisect_left(cnts, u)
tv = bisect_left(cnts, v)
adj[tu][tv] = min(adj[tu][tv], x)
adj[tv][tu] = min(adj[tv][tu], x)
p = 0
for i in range(k):
cur = group[p]
while p<cnts[i]:
if group[p]!=cur:
print("No")
return
p += 1
print("Yes")
for p in range(k):
for i in range(k):
for j in range(k):
adj[i][j] = min(adj[i][j], adj[i][p]+adj[p][j])
for i in range(k):
adj[i][i] = 0
for j in range(k):
if adj[i][j] == INF:
adj[i][j] = -1
for i in range(k):
print(' '.join(map(lambda x: str(x), adj[i])))
solve() | 10 | PYTHON3 |
vic1=input().split()
n=int(input())#list(map(int,input().split()))
for i in range(n):
print(' '.join(vic1))
t=input().split()
if vic1[0]==t[0]:
vic1[0]=t[1]
else:vic1[1]=t[1]
print(' '.join(vic1))
| 7 | PYTHON3 |
#include <bits/stdc++.h>
template <class T>
inline void read(T &x) {
int f = 1, c;
while (!isdigit(c = getchar()))
if (c == '-') f = -1;
x = c - '0';
while (isdigit(c = getchar())) {
x = x * 10 + c - '0';
}
x *= f;
}
using LL = long long;
std::vector<std::pair<int, int>> ret[2];
char s[2333];
int main() {
ret[0] = {{1, 1}, {3, 1}};
ret[1] = {{1, 3}, {2, 3}, {3, 3}, {4, 3}};
int cnt[2] = {0, 0};
scanf("%s", s);
int n = strlen(s);
for (int i = 0; i < n; ++i) {
int x = s[i] - '0';
int y = cnt[x]++ % ret[x].size();
printf("%d %d\n", ret[x][y].first, ret[x][y].second);
}
}
| 9 | CPP |
#include <bits/stdc++.h>
using namespace std;
int dx[] = {0, 0, -1, 1}, dy[] = {-1, 1, 0, 0};
int main() {
int x;
cin >> x;
vector<pair<int, int>> vp, team1, team2;
for (int i = 1; i <= x; i++) {
int t;
cin >> t;
vp.push_back(make_pair(t, i));
}
sort(vp.begin(), vp.end());
int maxx = 0, sum1 = 0, sum2 = 0;
for (int i = 0; i < x; i++) {
if (i & 1)
team1.push_back(vp[i]), maxx = max(maxx, vp[i].first),
sum1 += vp[i].first;
else
team2.push_back(vp[i]), maxx = max(maxx, vp[i].first),
sum2 += vp[i].first;
}
int in1 = 0, in2 = team2.size() - 1;
while (abs(sum1 - sum2) > maxx) {
if (in1 < team1.size() && in2 >= 0) {
sum1 -= team1[in1].first + team2[in2].first;
sum2 += team1[in1].first - team2[in2].first;
swap(team1[in1++], team2[in2--]);
} else {
break;
}
}
cout << team1.size() << endl;
for (int i = 0; i < team1.size(); i++) {
cout << team1[i].second << " ";
}
cout << endl << team2.size() << endl;
for (int i = 0; i < team2.size(); i++) {
cout << team2[i].second << " ";
}
return 0;
}
| 9 | CPP |
a=str(input())
b=str(input())
if(a[0]==b[0]):
c="0"
else:
c="1"
i=1
while(i<=len(a)-1):
if(a[i]==b[i]):
c=c+"0"
else:
c=c+"1"
i=i+1
print(c)
| 7 | PYTHON3 |
#include<iostream>
using namespace std;
int cnt, m, g[13] = {1, 4, 13, 40, 121, 364, 1093, 3280, 9841, 29524, 88573, 265720, 797161};
void insertionSort(int a[], int n, int g){
for(int i = g; i < n; i++){
int v = a[i], j = i-g;
while(j >= 0 && a[j] > v){
a[j+g] = a[j];
j = j-g;
cnt++;
}
a[j+g] = v;
}
}
void shellSort(int a[], int n){
cnt = 0;
m = 0;
for(int i = 0; i < 13; i++){
if(g[i] <= n)
m++;
}
for(int i = m-1; i >= 0; i--)
insertionSort(a, n, g[i]);
}
void print(int a[], int n){
cout << m << endl << g[m-1];
for(int i = m-2; i >= 0; i--)
cout << ' ' << g[i];
cout << endl << cnt << endl;
for(int i = 0; i < n; i++)
cout << a[i] << endl;
}
int main(){
int n, a[1000000];
cin >> n;
for(int i = 0; i < n; i++)
cin >> a[i];
shellSort(a, n);
print(a, n);
return 0;
}
| 0 | CPP |
len=int(input())
word=input()
if len<26:
print("NO")
else:
temp = word.lower()
frequencies = {}
for item in temp:
if item in frequencies:
frequencies[item] += 1
else:
frequencies[item] = 1
count = 0
for item in frequencies.keys():
count += 1
if count==26:
print("YES")
else:
print("NO") | 7 | PYTHON3 |
#include <bits/stdc++.h>
int main() {
int n, a, cnt;
scanf("%d %d", &n, &a);
if ((a % 2) == 0) a = n + 1 - a;
cnt = ((a - 1) / 2) + 1;
printf("%d\n", cnt);
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
long long mod = 1000000000 + 7;
vector<vector<int> > g;
long long pow(long long a, long long b, long long m) {
stack<int> k;
int j = 128;
int l = 1;
int an = 1;
while (b) {
if (b >= j) {
k.push(j);
b -= j;
}
j /= 2;
}
while (!k.empty()) {
if (k.top() == l) {
an = (an * a) % mod;
k.pop();
}
a = (a * a) % mod;
l *= 2;
}
return an;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
long n, k;
cin >> n >> k;
string s;
cin >> s;
int o = 0;
while (1) {
int f = 0;
for (int i = k; i > 0; --i) {
if (o + i < n && s[o + i] == '.') {
f = 1;
o += i;
break;
}
}
if (!f) {
cout << "NO" << endl;
return 0;
}
if (o == n - 1) {
break;
}
}
cout << "YES" << endl;
return 0;
}
| 8 | CPP |
def sieve(b):
a=[0]*(b+1)
p=[]
for i in range(2,b+1):
if a[i]==0:
p.append(i)
for j in range(i,b+1,i):
a[j]=1
return p
def check(t,x):
if t==1:
return 0
if int(t)-t==0:
if binarysearch(x,int(t))==1:
return 1
else:
return 0
else:
#print(t)
return 0
def binarysearch(x,a):
i=0
l=len(x)-1
while(i<=l):
mid=(i+l)//2
if x[mid]==a:
return 1
elif x[mid]>a:
l=mid-1
else:
i=mid+1
return 0
n=int(input())
a=[float(i)**0.5 for i in input().split()]
b=int(max(a))
x=sieve(b)
for i in a:
p=check(i,x)
if p==1:
print('YES')
else:
print('NO') | 8 | PYTHON3 |
def pow2(i):
ret = 1
while i!=1:
i >>= 1
ret <<= 1
return ret
m = int(input())
points = []
max2 = -1
flag = True
bias = -1
for i in range(m):
point = list(map(int,input().split()))
dis = abs(point[0])+abs(point[1])
if (dis > max2):
max2 = dis
if (bias!=-1 and dis%2 != bias%2):
flag =False
if (dis%2 == 0):
point[0] -= 1
points.append(tuple(point))
bias = dis%2
if flag == False:
print("-1")
exit(0)
bias = max2%2
max2 = pow2(max2)
diss = []
dirctions = [""]*m
while max2>0:
for i in range(m):
point = points[i]
if (point[1]>point[0] and point[1]>(-point[0])):
dirctions[i] = "U"+dirctions[i]
points[i] = (point[0],point[1]-max2)
elif(point[1]>point[0] and point[1]<(-point[0])):
dirctions[i] = "L"+dirctions[i]
points[i] = (point[0]+max2,point[1])
elif(point[1]<point[0] and point[1]>(-point[0])):
dirctions[i] = "R"+dirctions[i]
points[i] = (point[0]-max2,point[1])
else:
dirctions[i] = "D"+dirctions[i]
points[i] = (point[0],point[1]+max2)
diss = [max2] + diss
max2 >>= 1
if (bias == 0):
diss = [1] + diss
for i in range(m):
dirctions[i] = "R"+dirctions[i]
print(len(diss))
for d in diss:
print(str(d),end=" ")
print("")
for d in dirctions:
print(d)
| 0 | PYTHON3 |
// #define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream> // istringstream
using namespace std;
void Output(vector<pair<int, double> > ans){
for (int i = 0; i < ans.size(); i++){
printf("%d %.2lf\n", ans[i].first, ans[i].second);
}
}
int main(){
// 注意:it = hogehoge.erase(it) 使用時はC++11でコンパイル.
int number = 0, count = 0;
double time = 0.0;
map<double, int> time_number;
vector<pair<int, double> > ans;
map<double, int> plus2;
while (cin >> number >> time){
count++;
time_number.insert(pair<double, int>(time, number));
if (count == 8){
map<double, int>::iterator it = time_number.begin();
// 上位2人をansに格納
for (int i = 0; i < 2; i++){
ans.push_back(make_pair((*it).second, (*it).first));
it = time_number.erase(it);
}
// それ以外はplus2に格納
for (map<double, int>::iterator it = time_number.begin(); it != time_number.end(); it++){
double first = (*it).first;
int second = (*it).second;
plus2.insert(pair<double, int>(first, second));
}
count = 0;
time_number.clear();
}
}
// ここまでで6人決まった
// plus2の上位2人をansに格納
map<double, int>::iterator it = plus2.begin();
for (int i = 0; i < 2; i++){
ans.push_back(make_pair((*it).second, (*it).first));
it = plus2.erase(it);
}
Output(ans);
return 0;
} | 0 | CPP |
# ========== //\\ //|| ||====//||
# || // \\ || || // ||
# || //====\\ || || // ||
# || // \\ || || // ||
# ========== // \\ ======== ||//====||
# code
inn = lambda : int(input())
inm = lambda : map(int, input().split())
ins = lambda : str(input())
ina = lambda : list(map(int, input().split()))
import string
def solve():
n,m = inm()
s = ins()
c = {}
for i in string.ascii_lowercase:
c[i] = i
for i in range(m):
a,b = map(str, input().split())
for j in c.keys():
if c[j] == a:
c[j] = b
elif c[j] == b:
c[j] = a
t = ""
for i in s:
t += c[i]
print(t)
def main():
t = 1
# t = int(input())
for _ in range(t):
solve()
if __name__ == "__main__":
main() | 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
std::ios::sync_with_stdio(false);
cin.tie(NULL);
;
long long n;
cin >> n;
long long rem = 0;
long long ans = 0;
for (long long i = 0; i < n; i++) {
long long a;
cin >> a;
if (a >= 2 * rem) {
ans += rem;
a -= (2 * rem);
rem = 0;
} else {
long long to_use = a / 2;
rem -= (to_use);
ans += (to_use);
a -= (to_use * 2);
}
ans += (a / 3);
a = a % 3;
rem += a;
}
cout << ans;
return 0;
}
| 11 | CPP |
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long int ll;
ll X1[200005], X2[200005];
ll dp1[200005], dp2[200005];
ll Ans, L, N, A;
ll Max(ll a, ll b, ll c)
{
return max(max(a, b), c);
}
int main()
{
cin.tie(0);
ios::sync_with_stdio(false);
cin >> L >> N;
X1[N + 1] = L;
X2[N + 1] = L;
for ( int i = 1; i <= N; i++ )
{
cin >> A;
X1[i] = A;
X2[N + 1 - i] = L - A;
}
dp1[0] = X1[N + 1] - X1[N];
dp2[0] = X2[N + 1] - X2[N];
Ans = Max(Ans, L - dp1[0], L - dp2[0]);
for ( int i = 1; i < N; i++ )
{
dp1[i] = dp1[i - 1] + X1[N - ((i - 1) / 2)] + X1[N - (i / 2)] - 2 * X1[N - i];
dp2[i] = dp2[i - 1] + X2[N - ((i - 1) / 2)] + X2[N - (i / 2)] - 2 * X2[N - i];
Ans = Max(Ans, (i + 1)*L - dp1[i], (i + 1)*L - dp2[i]);
}
cout << Ans;
} | 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long int inverse(long long int i) {
if (i == 1) return 1;
return ((long long)(pow(10, 9) + 7) -
(((long long)(pow(10, 9) + 7) / i) *
inverse((long long)(pow(10, 9) + 7) % i)) %
(long long)(pow(10, 9) + 7) +
(long long)(pow(10, 9) + 7)) %
(long long)(pow(10, 9) + 7);
}
long long int nCr(long long n, long long r) {
long long product = 1;
if (n >= r && n >= 0 && r >= 0) {
for (long long i = n; i >= n - r + 1; i--) {
product = (product % (long long)(pow(10, 9) + 7) * i %
(long long)(pow(10, 9) + 7)) %
(long long)(pow(10, 9) + 7);
}
for (long long i = 1; i <= r; i++) {
product = (product % (long long)(pow(10, 9) + 7) * inverse(i) %
(long long)(pow(10, 9) + 7)) %
(long long)(pow(10, 9) + 7);
}
return product;
}
return 0;
}
int mod(int n) { return n > 0 ? n : -n; }
void Sieve(int n, vector<bool>& primes) {
for (int i = 0; i < primes.size(); i++) primes[i] = true;
for (int p = 2; p * p <= n; p++) {
if (primes[p] == true) {
for (int i = p * p; i <= n; i += p) primes[i] = false;
}
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, k;
cin >> n >> k;
int arr[n];
int H[101] = {0};
for (int i = 0; i < n; i++) {
cin >> arr[i];
H[arr[i]]++;
}
int c = 0;
while (1) {
int flag = 0;
for (int i = k - 1; i >= 1; i--) {
if (H[i] != 0) {
H[i + 1]++;
H[i]--;
flag = 1;
}
}
if (flag == 1)
c++;
else
break;
}
cout << c << endl;
return 0;
}
| 8 | CPP |
# cook your dish here
#code
import math
import collections
from sys import stdin,stdout,setrecursionlimit
from bisect import bisect_left as bsl
from bisect import bisect_right as bsr
import heapq as hq
setrecursionlimit(2**20)
t = 1
t = int(stdin.readline())
for _ in range(t):
n = int(stdin.readline())
a = list(map(int, stdin.readline().rstrip().split()))
pta = 0; ptb = n-1
cur = 0
moves = 0
prv_a = 0; prv_b = 0
aa = 0; bb = 0
while(pta<=ptb):
if(cur==0):
tm1 = 0
while(pta<=ptb and tm1<=prv_b):
tm1 += a[pta]
pta += 1
prv_a = tm1
aa += tm1
moves += 1
cur=1
else:
tm1 = 0
while(pta<=ptb and tm1<=prv_a):
tm1 += a[ptb]
ptb -= 1
prv_b = tm1
bb += tm1
moves += 1
cur=0
print(moves,end=' ')
print(aa,end=' ')
print(bb)
#print(aa,bb) | 10 | PYTHON3 |
#!/usr/bin/env python
import os
import re
import sys
from bisect import bisect, bisect_left, insort, insort_left
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from io import BytesIO, IOBase
from itertools import (
accumulate, combinations, combinations_with_replacement, groupby,
permutations, product)
from math import (
acos, asin, atan, ceil, cos, degrees, factorial, hypot, log2, pi, radians,
sin, sqrt, tan)
from operator import itemgetter, mul
from string import ascii_lowercase, ascii_uppercase, digits
def inp():
return(int(input()))
def inlist():
return(list(map(int, input().split())))
def instr():
s = input()
return(list(s[:len(s)]))
def invr():
return(map(int, input().split()))
def main():
# # For getting input from input.txt file
# sys.stdin = open('input.txt', 'r')
# # Printing the Output to output.txt file
# sys.stdout = open('output.txt', 'w')
n = inp()
up = inp()
down = 7 - up
res = 'YES'
for i in range(n):
l, r = invr()
mark = [False]*7
mark[l] = True
mark[r] = True
mark[7-l] = True
mark[7-r] = True
if mark[down] == True:
res = "NO"
print(res)
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
def input(): return sys.stdin.readline().rstrip("\r\n")
# endregion
if __name__ == "__main__":
main()
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int row, col;
int Size;
int R[110], C[110], tmp[110];
bool flag;
bool judge(int *arr) {
int sum = 0;
for (int i = 0; i < Size; i++) sum += arr[i] * arr[i];
int sq = sqrt(sum);
return (bool)(sq * sq == sum);
}
void Build(int d, int *arr) {
if (flag) return;
if (d == Size) {
if (judge(tmp)) {
flag = true;
for (int i = 0; i < Size; i++) {
arr[i] = tmp[i];
}
}
return;
}
for (int i = 1; i <= 10; i++) {
tmp[d] = i;
Build(d + 1, arr);
}
}
int main() {
cin >> row >> col;
Size = row;
flag = false;
Build(0, R);
flag = false;
Size = col;
Build(0, C);
for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++) {
cout << R[i] * C[j] << " ";
}
cout << endl;
}
return 0;
}
| 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 1 << 19;
const int LOGN = 4;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
for (int I = 0; I < t; I++) {
int c, d;
cin >> c >> d;
if ((c + d) % 2 == 1)
cout << -1 << '\n';
else if (c == d) {
if (c == 0)
cout << 0 << '\n';
else
cout << 1 << '\n';
} else
cout << 2 << '\n';
}
}
| 7 | CPP |
import re
st = [0]*128
p = 0
for i in ['a', '_']:
for j in ['b', '_']:
for k in ['a', '_']:
for l in ['c', '_']:
for m in ['a', '_']:
for n in ['b', '_']:
for o in ['a', '_']:
st[p] = i+j+k+l+m+n+o
p = p+1
#print(st)
for i in range(int(input())):
n = int(input())
s = input()
s = s.replace('?', '_')
if 'abacaba' in s:
if len(re.findall('(?=abacaba)',s)) > 1:
print('NO')
else:
print('YES')
s = s.replace('_', 'd')
print(s)
continue
else:
flag = False
for j in range(1,128):
if st[j] in s:
l = [m.start() for m in re.finditer(st[j], s)]
for k in l:
s1 = s[:k]+'abacaba'+s[k+7:]
if len(re.findall('(?=abacaba)',s1))==1:
sr = s1
sr = sr.replace('_', 'd')
print('YES')
print(sr)
flag = True
break
if flag:
break
if flag == False:
print('NO')
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int const N = 5000001;
int n, ID, tr[N][2];
long long v[N];
void ad(long long x) {
int u = 0;
for (int i = 60; i >= 0; --i) {
int cur = x >> i & 1;
if (!tr[u][cur]) tr[u][cur] = ++ID;
u = tr[u][cur];
}
}
long long Q(long long x, long long ret = 0) {
int u = 0;
for (int i = 60; i >= 0; --i) {
int cur = x >> i & 1;
if (tr[u][cur ^ 1])
u = tr[u][cur ^ 1], ret += (1ll << i);
else
u = tr[u][cur];
}
return ret;
}
int main() {
scanf("%d", &n);
long long cur = 0, suf = 0, an = 0;
for (int i = 0; i < n; ++i) {
scanf("%lld", v + i);
cur ^= v[i];
}
an = max(an, cur);
ad(0);
for (int i = n - 1; i >= 0; --i) {
cur ^= v[i];
suf ^= v[i];
ad(suf);
an = max(an, Q(cur));
}
printf("%lld\n", an);
}
| 11 | CPP |
for _ in range(int(input())):
n,k = map(int,input().split())
d = k%(n-1)
e = k//(n-1)
if d!=0:
ans = e*n+d
else:
ans = e*n-1
print(ans) | 9 | PYTHON3 |
for _ in range(int(input())):
a = list(map(int, input()))
n = len(a)
ans = n + 1
c = [0] * 4
i = 0
j = -1
while i < n:
c[a[i]] += 1
while c[a[j + 1]] > 1:
j += 1
c[a[j]] -= 1
if c[1] and c[2] and c[3]:
ans = min(ans, i - j)
i += 1
print(0 if ans > n else ans)
| 8 | PYTHON3 |
#!/usr/bin/python3.5
N, M = [*map(int, input().split())]
_L = [list() for i in range(0, M)]
for i in range(0, N):
s, r = [*map(int, input().split())]
_L[s-1].append(r)
L = []
L_sum = []
for x in _L:
if len(x) != 0:
x.sort(reverse=True)
L.append(x)
L.sort(reverse=True, key=lambda x: len(x))
for x in L:
_s = [0]*len(x)
_s[0] = x[0]
for i in range(1, len(x)):
_s[i] = _s[i-1] + x[i]
L_sum.append(_s)
ret = 0
for i in range(1, N+1):
cpt = 0
for j in range(0, len(L)):
if len(L[j]) < i:
break
if L_sum[j][i-1] > 0:
cpt += L_sum[j][i-1]
ret = max(ret, cpt)
print(max(0, ret))
| 9 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 10;
const int MAXN = 1e4 + 10;
const int MOD = 1e9 + 7;
const int inf = 1e9;
const double pi = acos(-1.0);
const double eps = 1e-6;
int dx[] = {0, -1, 0, 1};
int dy[] = {1, 0, -1, 0};
map<int, int> mymap, mymap1;
int n, m;
vector<int> Ve, Vo;
int save[200100];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
int res = 0;
for (int i = 1; i <= n; i++) {
int x;
cin >> x;
if (x % 2) {
if (!mymap[x]) {
Vo.push_back(x);
mymap[x] = 1;
mymap1[x] = i;
}
} else {
if (!mymap[x]) {
Ve.push_back(x);
mymap[x] = 1;
mymap1[x] = i;
}
}
}
int o = Vo.size();
int e = Ve.size();
int r = -1;
if (o >= n / 2 && e <= n / 2)
r = min(o - n / 2, n / 2 - e);
else if (o <= n / 2 && e >= n / 2)
r = min(n / 2 - o, e - n / 2);
if (r != -1) {
res += r;
if (o <= n / 2) {
o += r;
e -= r;
} else {
o -= r;
e += r;
}
}
res += max(n / 2 - o, 0);
res += max(n / 2 - e, 0);
for (int i = 1; i <= min(n, m); i++)
if (i % 2) {
if (!mymap[i]) {
mymap[i] = 1;
Vo.push_back(i);
}
} else {
if (!mymap[i]) {
mymap[i] = 1;
Ve.push_back(i);
}
}
o = Vo.size();
e = Ve.size();
if (o >= n / 2 && e >= n / 2) {
cout << res << endl;
vector<int> K;
K.clear();
for (int i = 0; i < n / 2; i++)
if (mymap1[Vo[i]])
save[mymap1[Vo[i]]] = Vo[i];
else
K.push_back(Vo[i]);
for (int i = 0; i < n / 2; i++)
if (mymap1[Ve[i]])
save[mymap1[Ve[i]]] = Ve[i];
else
K.push_back(Ve[i]);
int p = 1;
int q = 0;
while (p <= n && q < K.size())
if (save[p])
p++;
else {
save[p] = K[q];
p++;
q++;
}
for (int i = 1; i <= n; i++) cout << save[i] << ' ';
} else
cout << -1;
return 0;
}
| 11 | CPP |
t = int(input())
for T in range(t):
a, b, n = map(int, input().split())
kolvo = 0
while a <= n and b <= n:
if a > b:
b += a
else:
a += b
kolvo += 1
print(kolvo)
| 7 | PYTHON3 |
x,y,z=map(int,input().split());print((x-z)//(y+z)) | 0 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
class Interact {
public:
int query(int u, int v) {
cout << "? " << u << " " << v << endl;
cout.flush();
int w;
cin >> w;
return w;
}
void answer(int u) {
cout << "! " << u << endl;
cout.flush();
}
} interact;
class Solver {
Interact interact;
public:
void solve(vector<vector<int>> &e) {
queue<int> que;
vector<int> d(e.size());
for (int i = 1; i < e.size(); ++i) d[i] = e[i].size();
for (int i = 1; i < e.size(); ++i) {
if (d[i] == 1) que.push(i);
}
while (que.size() > 1) {
int u = que.front();
que.pop();
int v = que.front();
que.pop();
int w = interact.query(u, v);
if (w == u || w == v) {
interact.answer(w);
return;
} else {
for (auto ver : e[u]) {
if (--d[ver] == 1) que.push(ver);
}
for (auto ver : e[v]) {
if (--d[ver] == 1) que.push(ver);
}
}
}
int u = que.front();
que.pop();
interact.answer(u);
}
} solver;
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
std::cout.tie(0);
int n;
cin >> n;
vector<vector<int>> e(n + 1);
for (int i = 1; i < n; ++i) {
int a, b;
cin >> a >> b;
e[a].push_back(b);
e[b].push_back(a);
}
solver.solve(e);
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
cin >> n >> k;
int mini = INT_MAX;
vector<int> a(n), b(n);
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 1; i < n; i++) {
b[i] = a[i];
a[i] = ((k - a[i - 1]) > a[i]) ? (k - a[i - 1]) : a[i];
}
b[0] = a[0];
int sum = 0;
for (int i = 0; i < n; i++) sum += a[i] - b[i];
cout << sum << endl;
for (int i = 0; i < n; i++) cout << a[i] << " ";
return 0;
}
| 8 | CPP |
#include<bits/stdc++.h>
using namespace std;
int main( )
{
string a;
int v=0;
cin>>a;
for(int i=0;i<a.size();i++)
{
if(a[i]=='C')v=1;
if(a[i]=='F'&&v==1)
{
cout<<"Yes\n";
return 0;
}
}
cout<<"No\n";
return 0;
} | 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
int pd, s1, s2, n, m, a, b, x;
int main() {
cin >> n >> m >> a >> b;
pd = 1;
s1 = s2 = 1;
for (int i = 1; i <= m; i++) {
cin >> x;
if (x < a || x > b) pd = 0;
if (x == a) s1 = 0;
if (x == b) s2 = 0;
}
if (!pd || s1 + s2 > n - m)
printf("Incorrect\n");
else
printf("Correct\n");
return 0;
}
| 7 | CPP |
import sys
if __name__ == "__main__":
n = int(input())
x = (input().split())
answer = "EASY"
sum = 0
for i in x:
i = int(i)
sum = sum + i
if(sum > 0):
answer = "HARD"
# print("Die Summe ist: " + str(sum))
print(answer)
"""
Eine Zahl n einlesen
n Zahlen einlesen
Wenn eine der n Zahlen 1 ist
"HARD"
Sonst
"Easy"
"""
| 7 | PYTHON3 |
#include <bits/stdc++.h>
int main() {
int T;
scanf("%d", &T);
while (T > 0) {
long n, x, m, i, j, BI = 0, BS = 0, R, L;
scanf("%ld%ld%ld", &n, &x, &m);
j = 0;
do {
scanf("%ld%ld", &L, &R);
j++;
} while (!((x >= L) && (x <= R)) && (j < m));
if ((x >= L) && (x <= R)) {
BI = L;
BS = R;
}
for (i = j; i < m; i++) {
scanf("%ld%ld", &L, &R);
if ((L < BI) && (R >= BI)) BI = L;
if ((R > BS) && (L <= BS)) BS = R;
}
printf("%ld\n", BS - BI + 1);
T--;
}
return 0;
}
| 8 | CPP |
N, C = map(int, input().split())
P = sum(list(map(int, input().split())))
if P%(N+1)==0:
print(P//(N+1))
else:
print(P//(N+1)+1)
| 0 | PYTHON3 |
s=input()
alpha=[chr(i+97) for i in range(26)]
distinct={}
for i in s:
if i in alpha:
distinct[i]=1
print(len(distinct)) | 7 | PYTHON3 |
tt = int(input())
while tt:
tt -= 1
n = int(input())
ll = list(map(int,input().split()))
l = sorted(ll)
m = []
for i in range(len(l)):
a = l[i] - l[i-1]
m.append(a)
m.remove(m[0])
print(min(m)) | 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<long long> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
sort(a.begin(), a.end());
long long ans = 0;
for (int i = 0, j = n - 1; i < j; i++, j--) {
ans += (a[i] + a[j]) * (a[i] + a[j]);
}
cout << ans << '\n';
return 0;
}
| 9 | CPP |
#include <bits/stdc++.h>
using namespace std;
double xp, yp, vp, x, y, v, r, rp;
struct pt {
double x, y;
pt operator-(const pt& p) { return {x - p.x, y - p.y}; }
};
pt her, me;
pt rot(pt p, double rad) {
return {p.x * cos(rad) - p.y * sin(rad), p.x * sin(rad) + p.y * cos(rad)};
}
double dist(pt p1, pt p2) { return hypot(p1.x - p2.x, p1.y - p2.y); }
bool cli(pt o, pt b, double r) {
pt d = b - o;
double dr2 = d.x * d.x + d.y * d.y;
double cross = o.x * b.y - o.y * b.x;
double disc = r * r * dr2 - cross * cross;
if (disc < 1e-8) return 0;
pt i1 = {(cross * d.y + ((d.y < 0) ? -1 : 1) * d.x * sqrt(disc)) / dr2,
(-cross * d.x + abs(d.y) * sqrt(disc)) / dr2};
pt i2 = {(cross * d.y - ((d.y < 0) ? -1 : 1) * d.x * sqrt(disc)) / dr2,
(-cross * d.x - abs(d.y) * sqrt(disc)) / dr2};
if (i1.x < min(o.x, b.x) - 1e-8 || i1.x > max(o.x, b.x) + 1e-8 ||
i1.y < min(o.y, b.y) - 1e-8 || i2.y > max(o.y, b.y) + 1e-8)
return 0;
return 1;
}
bool ok(double t) {
double fspin = (2 * 3.14159265358979323846264338327950288419716939 * rp) / vp;
double ang = 2 * 3.14159265358979323846264338327950288419716939 *
((t / fspin) - floor(t / fspin));
pt herr = rot(her, ang);
if (!cli(me, herr, r)) return dist(me, herr) < t * v;
double dme = dist({0, 0}, me), dher = dist({0, 0}, herr);
double tme = sqrt(dme * dme - r * r), ther = sqrt(dher * dher - r * r);
double ttl = tme + ther;
double ame = atan2(me.y, me.x), aher = atan2(herr.y, herr.x);
if (ame < 1e-8) ame += 2 * 3.14159265358979323846264338327950288419716939;
if (aher < 1e-8) aher += 2 * 3.14159265358979323846264338327950288419716939;
double ftheta =
min(fabs(ame - aher), 2 * 3.14159265358979323846264338327950288419716939 -
fabs(ame - aher));
double theta = ftheta - acos(r / dme) - acos(r / dher);
ttl += theta * r;
return ttl < t * v;
}
double bs(double lo, double hi) {
double mid = (hi + lo) / 2;
if (fabs(lo - hi) < 1e-8) return mid;
if (ok(mid)) return bs(lo, mid);
return bs(mid, hi);
}
int main() {
cin >> xp >> yp >> vp >> x >> y >> v >> r;
her = {xp, yp};
me = {x, y};
rp = dist({0, 0}, her);
cout << setprecision(10) << fixed << bs(0, 1e9) << endl;
return 0;
}
| 9 | CPP |
index = 2
done = False
while not done:
line = input().split()
if '1' in line:
print(abs(index) + abs(2 - line.index('1')))
done = True
index -= 1
if index == -3:
done = True
| 7 | PYTHON3 |
n = int(input())
mat = list(map(int, input().split()))
sat = []
dat = []
for i in range(1,n-1):
sat.append(mat[i+1] - mat[i-1])
dat.append(mat[i] - mat[i-1])
dat.append(mat[i+1] - mat[i])
dat[sat.index(min(sat))] = min(sat)
dat[sat.index(min(sat))+1] = -1
print(max(dat))
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int s, c, a = 1;
cin >> s >> c;
for (int i = 0;; i++) {
if ((s * a) % 10 == c || (s * a) % 10 == 0) {
cout << a << endl;
break;
}
a++;
}
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
namespace patch {
template <typename T>
std::string to_string(const T& n) {
std::ostringstream stm;
stm << n;
return stm.str();
}
} // namespace patch
using namespace std;
int main() {
vector<pair<long long int, long long int> > A, B;
long long int N, M;
cin >> N;
for (int i = 0; i < N; i++) {
long long int X, Y;
cin >> X >> Y;
A.push_back({X, Y});
}
cin >> M;
for (int i = 0; i < M; i++) {
long long int X, Y;
cin >> X >> Y;
B.push_back({X, Y});
}
sort(A.begin(), A.end());
sort(B.begin(), B.end());
long long int ans = 0;
for (int i = 0; i < N; i++) {
ans = max(ans, B.back().first - A[i].second);
}
for (int i = 0; i < M; i++) {
ans = max(ans, A.back().first - B[i].second);
}
cout << ans;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
const int inf = 0x3f3f3f3f;
const long long linf = 8e18 + 9e17;
const int mod = 1e9 + 7;
const double e = exp(1.0);
const double pi = acos(-1);
int main() {
int mid, n, st;
scanf("%d", &n);
if (n == 2) {
printf("2 1\n");
return 0;
}
int block = (int)sqrt(n);
if (block * block < n) block++;
for (int i = n; i >= 1; i -= block) {
for (int j = i - block + 1, h = 1; h <= block; h++, j++) {
if (j > 0) printf("%d ", j);
}
}
return 0;
}
| 9 | CPP |
print((int(input())+1)%2) | 0 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
inline char gc() {
static char buf[100000], *p1 = buf, *p2 = buf;
return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
? EOF
: *p1++;
}
inline long long read() {
long long x = 0;
char ch = getchar();
bool positive = 1;
for (; !isdigit(ch); ch = getchar())
if (ch == '-') positive = 0;
for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
return positive ? x : -x;
}
inline void write(long long a) {
if (a < 0) {
a = -a;
putchar('-');
}
if (a >= 10) write(a / 10);
putchar('0' + a % 10);
}
inline void writeln(long long a) {
write(a);
puts("");
}
inline void wri(long long a) {
write(a);
putchar(' ');
}
long long rnd() {
unsigned long long ans = 0;
for (int i = (int)(0); i <= (int)(4); i++) ans = ans << 15 ^ rand();
return ans % ((unsigned long long)1 << 63);
}
const int B = 32000;
long long a, b, p, q, qq, mn, ans;
void solve(int i) {
long long t = abs(i * p % qq - q);
if (t < mn || t == mn && i < ans) {
mn = t;
ans = i;
}
}
pair<long long, long long> to[B];
int main() {
int T = read();
while (T--) {
a = read(), b = read() + 1, p = read() * 2, q = read(), qq = q << 1;
mn = 2e9;
if (b - a <= 2 * B) {
for (int i = (int)(a); i <= (int)(b - 1); i++) solve(i);
writeln(ans);
} else {
for (int i = (int)(a); i <= (int)(a / B * B + B - 1); i++) solve(i);
int tot = 0;
for (int i = (int)(0); i <= (int)(B - 1); i++)
to[tot++] = make_pair(i * p % qq, i);
sort(to, to + tot);
int tt = 0;
for (int i = (int)(1); i <= (int)(tot - 1); i++)
if (to[i].first != to[tt].first) to[++tt] = to[i];
tot = tt + 1;
for (int i = a / B * B + B; i < b / B * B; i += B) {
long long t = i * p % qq;
int pos = lower_bound(to, to + tot,
make_pair((q + qq - t) % qq, (long long)0)) -
to;
solve(i + to[(pos + tot - 1) % tot].second);
solve(i + to[pos % tot].second);
}
for (int i = (int)(b / B * B); i <= (int)(b - 1); i++) solve(i);
writeln(ans);
}
}
}
| 12 | CPP |
#include <bits/stdc++.h>
using namespace std;
int a[200005];
int ans[200005];
int main(void) {
int n;
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
scanf("%d", &a[i]);
}
for (int i = 0; i < n; ++i) {
ans[i] = 1000000000;
}
int j = -1000000000;
for (int i = 0; i < n; ++i) {
if (a[i] == 0) {
j = i;
}
ans[i] = min(ans[i], i - j);
}
j = 1000000000;
for (int i = n - 1; i > -1; --i) {
if (a[i] == 0) {
j = i;
}
ans[i] = min(ans[i], j - i);
}
for (int i = 0; i < n; ++i) {
cout << ans[i] << " ";
}
cout << endl;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, i, x, y, cen, j, m;
long long nr;
int t[100005], num[100005], viz[100005], nr1[100005], nr2[100005], sol[100005],
u[100005], w2[100005];
pair<int, int> w[100005];
vector<int> v[100005], p1[100005], p2[100005];
set<pair<int, int> > second;
set<pair<int, int> >::iterator it;
void dfs(int nod, int t) {
num[nod] = 1;
for (int i = 0; i < v[nod].size(); i++) {
int vecin = v[nod][i];
if (vecin != t) {
dfs(vecin, nod);
num[nod] += num[vecin];
}
}
}
void dfs2(int nod, int t, int i) {
p1[i].push_back(nod);
p2[i].push_back(nod);
for (int j = 0; j < v[nod].size(); j++) {
if (v[nod][j] != t) {
dfs2(v[nod][j], nod, i);
}
}
}
int getpoz1(int x) {
int val = p1[x][p1[x].size() - 1];
p1[x].pop_back();
return val;
}
int getpoz2(int x) {
int val = p2[x][p2[x].size() - 1];
p2[x].pop_back();
return val;
}
int findcen(int nod) {
viz[nod] = 1;
for (int i = 0; i < v[nod].size(); i++) {
int vecin = v[nod][i];
if (num[vecin] > n / 2 && viz[vecin] == 0) {
return findcen(vecin);
}
}
return nod;
}
int main() {
cin >> n;
for (i = 1; i < n; i++) {
scanf("%d%d", &x, &y);
v[x].push_back(y);
v[y].push_back(x);
}
dfs(1, 0);
for (i = 1; i <= n; i++) {
for (j = 0; j < v[i].size(); j++) {
x = v[i][j];
if (num[x] < num[i]) {
nr += min(num[x], n - num[x]);
}
}
}
nr *= 2;
if (n == 2) {
cout << nr << "\n2 1";
return 0;
}
cen = findcen(1);
dfs(cen, 0);
m = v[cen].size();
y = 0;
for (i = 0; i < v[cen].size(); i++) {
x = v[cen][i];
dfs2(x, cen, i + 1);
nr1[i + 1] = nr2[i + 1] = num[x];
second.insert(make_pair(-num[x], i + 1));
for (j = 1; j <= num[x]; j++) {
w[++y] = make_pair(j, i + 1);
}
}
w[++y] = make_pair(1, m + 1);
p1[m + 1].push_back(cen);
p2[m + 1].push_back(cen);
for (i = 1; i <= n; i++) {
w[i].second *= -1;
}
sort(w + 1, w + n + 1);
for (i = 1; i <= n; i++) {
u[i] = n;
w2[i] = -w[i].second;
}
for (i = 1; i <= n; i++) {
w[i].second *= -1;
}
sort(w + 1, w + n + 1);
for (i = n; i >= 1; i--) {
u[w[i].second] = min(i, u[w[i].second]);
while (w2[u[w[i].second]] == w[i].second) {
u[w[i].second]--;
}
swap(w2[i], w2[u[w[i].second]]);
sol[getpoz1(w[i].second)] = getpoz2(w2[i]);
}
cout << nr << "\n";
for (i = 1; i <= n; i++) {
printf("%d ", sol[i]);
}
}
| 8 | CPP |
v1, v2 = map(int, input().split())
t, d = map(int, input().split())
dist = v1
v = v1
for i in range(1, t):
v += d
if v <= v2 + d*(t-i-1):
dist += v
else:
v = v2 + d*(t-i-1)
dist += ((v + v2) * (t - i)) / 2
break
print(int(dist))
| 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int len = s.size();
double ans = 0;
double tmp = 0;
for (int i = 0; i < len; ++i) {
if (isdigit(s[i])) {
tmp = s[i] - '0';
int flag = 0;
int j;
for (j = i + 1; j < len && (isdigit(s[j]) || s[j] == '.'); ++j) {
if (isdigit(s[j])) {
if (flag) {
tmp += (s[j] - '0') * pow(10, -flag);
flag++;
} else {
tmp *= 10;
tmp += s[j] - '0';
}
} else if (s[j] == '.')
if (!flag) flag++;
}
flag--;
while (flag >= 3) {
flag -= 3;
tmp *= 1000;
}
ans = tmp + ans;
tmp = 0;
i = j;
}
}
string rans;
double tans = ans - floor(ans + 0.00001);
long long ians = floor(ans + 0.00001);
int cnt = 0;
if (!ians) rans.push_back('0');
while (ians) {
cnt++;
rans.push_back((ians % 10) + '0');
ians /= 10;
if (cnt == 3) {
rans.push_back('.');
cnt = 0;
}
}
int i = rans.size() - 1;
if (rans[i] == '.') i--;
for (; i >= 0; --i) {
cout << rans[i];
}
if (tans > 1e-3) {
int ts = (tans + 0.0001) * 100;
printf(".%02d\n", ts);
}
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int h, m;
char x;
cin >> h >> x >> m;
while (h < 24) {
if (m == 59) {
h += 1;
m = 0;
} else {
m++;
if (h / 10 == m % 10 && h % 10 == m / 10) {
if (h < 10) cout << "0";
cout << h << ":";
if (m < 10) cout << "0";
cout << m << endl;
break;
}
}
}
if (h == 24) cout << "00:00" << endl;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
int jai_shree_ram() { return 1; }
int shree_ganeshay_namah() { return 1; }
long long int power(long long int x, long long int y) {
long long int r = 1;
while (y > 0) {
if (y % 2 != 0) r = r * x;
x = x * x;
y = y / 2;
}
return r;
}
long long int ncr(long long int n, long long int k) {
long long int c[k + 1];
memset(c, 0, sizeof(c));
c[0] = 1;
for (long long int i = 1; i <= n; i++) {
for (long long int j = min(i, k); j > 0; j--) c[j] = c[j] + c[j - 1];
}
return c[k];
}
bool prime[500001];
void sieve() {
long long int i, j;
memset(prime, true, sizeof(prime));
prime[0] = false;
prime[1] = false;
for (i = 2; i <= sqrt(100001); i++) {
if (prime[i]) {
for (j = i * i; j <= 100001; j = j + i) prime[j] = false;
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long int n, a = 0, b = 0, i, j;
vector<long long int> v1;
vector<long long int> v2;
cin >> n;
long long int c;
for (i = 0; i < n; i++) {
long long int x;
cin >> x;
if (x > 0) {
a = a + x;
v1.push_back(x);
c = 1;
} else {
b = b - x;
v2.push_back(-x);
c = -1;
}
}
if (a > b) {
cout << "first";
return 0;
}
if (a < b) {
cout << "second";
return 0;
}
for (i = 0; i < min(v1.size(), v2.size()); i++) {
if (v1[i] < v2[i]) {
cout << "second";
return 0;
}
if (v1[i] > v2[i]) {
cout << "first";
return 0;
}
}
if (v1.size() < v2.size()) {
cout << "second";
return 0;
}
if (v1.size() > v2.size()) {
cout << "first";
return 0;
}
if (c == 1)
cout << "first";
else
cout << "second";
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int A, B, nA, nB;
cin >> A >> B >> nA >> nB;
vector<int> m(A), k(B);
for (int i = 0; i < A; i++) cin >> m[i];
for (int i = 0; i < B; i++) cin >> k[i];
sort(m.begin(), m.end());
sort(k.begin(), k.end());
vector<int> a(nA), b(nB);
for (int i = 0; i < nA; i++) a[i] = m[i];
int j = 0;
for (int i = B - 1; i > B - nB - 1; i--) {
b[j] = k[i];
j++;
}
int S = nA - 1;
if (a[S] >= b[nB - 1])
cout << "NO";
else
cout << "YES";
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7, Base = 998244353;
const long long N = 5000 + 7;
const long long INF = 1LL * 1000 * 1000 * 1000 * 1000 * 1000 * 1000 + 7LL;
const double pie = acos(-1.0);
const double EPS = 1e-9;
long long n, m, Memo[N][N], Max;
string A, B;
long long Calco() {
for (long long i = n; i >= 1; --i) {
for (long long j = m; j >= 1; --j) {
if (A[i] == B[j]) Memo[i][j] = 2 + Memo[i + 1][j + 1];
Memo[i][j] = max({Memo[i][j], Memo[i + 1][j] - 1, Memo[i][j + 1] - 1});
Max = max(Max, Memo[i][j]);
}
}
return Max;
}
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m >> A >> B;
A = '#' + A + '$';
B = '#' + B + '*';
cout << Calco();
return 0;
}
| 10 | CPP |
n,k = map(int,input().split())
people = [int(pep) for pep in input().split(' ', n - 1)]
team = 0
count = 0
for i in people:
if i + k <= 5:
team += 1
if team == 3:
count += 1
team = 0
print(count)
| 7 | PYTHON3 |
#https://codeforces.com/problemset/problem/977/A
n, k=input().split()
n=int(n)
k=int(k)
for i in range(k):
if n%10!=0:
n=n-1
else:
n=int(n/10)
print(n)
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
const int mod = 1e9 + 7;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--) {
long long n, m, i, j, A, B;
cin >> n >> m;
long long a[n];
for (i = 0; i < n; i++) cin >> a[i];
stack<long long> st;
long long sum = 0;
for (i = 0; i < n; i++) {
if (st.empty())
st.push(a[i]);
else {
if (a[i] > st.top()) {
st.pop();
st.push(a[i]);
} else {
sum += (st.top() - a[i]);
st.pop();
st.push(a[i]);
}
}
}
if (!st.empty()) sum += st.top();
for (i = 0; i < n; i++) {
sum = max(sum, a[i]);
}
cout << sum << endl;
}
return 0;
}
| 9 | CPP |
for _ in range(int(input())):
n, m = map(int, input().split())
if ((n <= 2 and m <= 2) or m == 1 or n == 1):
print('YES')
else:
print('NO')
| 7 | PYTHON3 |
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
using namespace std;
int main() {
int n, m; cin >> n >> m;
map<pair<int, int>, int> mp;
for (int i = 0; i < m; i++) {
int a, b; cin >> a >> b;
mp[{a, b}]++;
}
vector<long long> imos(n, m);
for (auto &p: mp) {
long long a = p.first.first, b = p.first.second, c = p.second;
imos[0] += a * c;
for (int i = b - a - 1; i < n; i += b) imos[i] -= b * c;
}
for (int i = 0; i + 1 < n; i++) imos[i + 1] += imos[i];
for (auto x: imos) cout << x << endl;
return 0;
}
| 0 | CPP |
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
int x[10][10];
int a,b,c;
int yoso[3]={5,9,13};
int tmp[3][2][13]={{{0,-1,0,1,0},{0,0,1,0,-1}},{{0,-1,-1,-1,0,1,1,1,0},{0,-1,0,1,1,1,0,-1,-1}},{{0,-1,-1,-1,0,1,1,1,0,-2,0,2,0},{0,-1,0,1,1,1,0,-1,-1,0,2,0,-2}}};
for(int i=0;i<10;i++){
for(int j=0;j<10;j++){
x[i][j]=0;
}
}
while(scanf("%d,%d,%d",&b,&a,&c)!=EOF){
c--;
for(int i=0;i<yoso[c];i++){
if(a+tmp[c][0][i]>=0&&a+tmp[c][0][i]<10&&b+tmp[c][1][i]>=0&&b+tmp[c][1][i]<10){
x[a+tmp[c][0][i]][b+tmp[c][1][i]]++;
}
}
}
int cnt=0,max=0;
for(int i=0;i<10;i++){
for(int j=0;j<10;j++){
if(x[i][j]==0)cnt++;
if(x[i][j]>max)max=x[i][j];
}
}
cout << cnt << endl << max << endl;
} | 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
const int inf = 0x3f3f3f3f;
int b[maxn];
int a[maxn];
int ma[maxn];
int pre[maxn * 10];
int _find(int x) { return x == pre[x] ? x : pre[x] = _find(pre[x]); }
void _union(int x, int y) {
x = _find(x), y = _find(y);
if (x < y)
pre[x] = y;
else
pre[y] = x;
}
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < maxn * 10; ++i) pre[i] = i;
for (int i = 1; i <= n; ++i) {
scanf("%d", &a[i]);
ma[i] = max(ma[i - 1], a[i]);
}
int x = 0;
for (int i = n; i > 0; --i) {
if (a[i] > ma[i - 1])
b[i] = ma[i - 1];
else
b[i] = a[i] + 1;
b[i] = _find(b[i]);
_union(b[i], b[i] + 1);
_union(a[i], a[i] + 1);
}
for (int i = 1; i <= n; ++i) printf("%d%c", b[i], i == n ? '\n' : ' ');
return 0;
}
| 9 | CPP |
n,m=tuple(map(int,input().split()))
l=[]
k=0
ans1=[]
ans2=[]
for i in range(n):
l.append(input())
for i in range(n):
for j in range(i+1,n):
if(l[i]==l[j][::-1]):
ans1.append(l[i])
if(m%2==0):
if(l[i][:int(len(l[i])/2)]==l[i][int(len(l[i])/2):][::-1]):
ans2.append(l[i][:int(len(l[i])/2)])
else:
if(l[i][:int(len(l[i])/2)]==l[i][int(len(l[i])/2)+1:][::-1]):
k+=1
ans2.append(l[i][:int(len(l[i])/2)+1])
if(len(ans2)!=0):
s=''.join(ans1)+ans2[0]
else:
s=''.join(ans1)
if(k==0):
print(len(s)*2)
print(s+s[::-1])
else:
print(len(s)*2 -1)
print(s+s[::-1][1:]) | 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
bool isPrime(int n) {
for (int i = 2; i * i <= n; i++) {
if (n % i == 0) return false;
}
return true;
}
int gcd(int a, int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
int main() {
int n;
cin >> n;
int l = n;
if (n % 2)
l = l / 2;
else
l = l / 2 - 1;
for (int i = l; i >= 1; i--) {
int p = n - i;
if (gcd(i, p) == 1) {
cout << i << " " << p;
break;
}
}
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int T;
cin >> T;
while (T--) {
int n;
cin >> n;
if (n == 1)
cout << "FastestFinger" << endl;
else if (n & 1 || n == 2)
cout << "Ashishgup" << endl;
else {
int cntTwo = 0;
while (n % 2 == 0) cntTwo++, n >>= 1;
int cnt = 0;
for (int i = 3; i * i <= n; i += 2) {
while (n % i == 0) cnt++, n /= i;
}
if (n != 1) cnt++;
if (cnt >= 2 || cnt == 1 && cntTwo >= 2)
cout << "Ashishgup" << endl;
else
cout << "FastestFinger" << endl;
}
}
return 0;
}
| 9 | CPP |
[t,k]=list(map(int,input().split()))
if(k==1 or k==t):
print(3*t)
else:
sum=6+(t-2)*3
m = min(t-k,k-1)
sum+=m
print(sum) | 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 55;
int main() {
int num = 0, min_ = 100;
int n, a[55];
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
min_ = min(min_, a[i]);
}
for (int i = 0; i < n; i++)
if (a[i] == min_) num++;
if (num <= n / 2)
printf("Alice\n");
else
printf("Bob\n");
return 0;
}
| 9 | CPP |
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>
using namespace std;
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());
#define PAU
typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vb> vvb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 28);
const ll LINF = 1e18;
const double PI = acos(-1);
typedef pair<ll, ll> P;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N;
cin >> N;
vector<P> V(N);
REP(i, N)cin >> V[i].first >> V[i].second;
so(V);
vll S(N);
ll sum = 0;
REP(i, N) {
sum += V[i].second;
S[i] = sum;
}
ll left = 0;
ll ans = 0;
REP(i, N) {
if (i != 0) {
left -= V[i].first;
left += V[i - 1].first;
left = max(left, -S[i - 1]);
}
ans = max(ans,S[i] + left);
}
cout << ans << endl;
PAU;
return 0;
}
| 0 | CPP |
#include <bits/stdc++.h>
using ull = unsigned long long;
using ll = long long;
using ld = long double;
using namespace std;
const ll mod = 1e9 + 7;
const int N = 2000 * 1000 * 1000;
void test_case() {
int n;
cin >> n;
for (int i = 2; i < n; i++) {
if (n % i == 0) {
cout << i << n / i;
return;
}
}
}
int main() {
test_case();
return 0;
}
| 8 | CPP |
two, three, five, six = map(int, input().split())
x = min(two, five, six)
two -= x
y = min(two, three)
print(x*256 + y*32)
| 8 | PYTHON3 |
for s in[*open(0)][1:]:
n,a,b=map(int,s.split());r=-1,
if-2<a-b<2and a+b<n-1:
*r,=range(1,n+1);j=1
if a<b:r[:2]=r[1::-1];b-=1;j=2
if a>b:r[-2:]=r[:-3:-1];a-=1
for i in range(j,a+b+1,2):r[i:i+2]=r[i+1],r[i]
print(*r) | 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
long long inf = 1e13 + 100, mod = 1e9 + 7;
long long pre[300005];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long t = 1;
cin >> t;
pre[0] = 0;
for (long long i = 1; i <= 300000; i++) pre[i] = pre[i - 1] ^ i;
while (t--) {
long long a, b;
cin >> a >> b;
long long x = pre[a - 1];
if (x == b)
cout << a;
else {
long long last = b ^ x;
if (last == a)
cout << a + 2;
else
cout << a + 1;
}
cout << "\n";
}
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
int main() {
char w[101];
scanf("%s", w);
int i, r, count, d, k;
count = 0;
d = strlen(w);
for (r = 1; r < d; r++) {
for (i = 0; i < r; i++) {
if (w[i] == w[r]) {
count += 1;
break;
}
}
}
k = d - count;
if (k % 2 == 0) {
printf("CHAT WITH HER!\n");
} else
printf("IGNORE HIM!\n");
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double PI = acos(-1.0);
const double EPS = 1e-8;
const int MOD = 1e9 + 7;
long long qpow(long long x, long long n, long long mod = MOD) {
long long res = 1;
while (n) {
if (n & 1) res = res * x % mod;
x = x * x % mod;
n >>= 1;
}
return res;
}
namespace Solver {
void InitOnce() { int t; }
int n, x, y;
const int LIMIT = 1e7;
long long dis[LIMIT + 5];
bool vis[LIMIT + 5];
priority_queue<pair<long long, int> > PQ;
void Read() {
int res = scanf("%d%d%d", &n, &x, &y);
if (res == -1) exit(0);
}
void Solve() {
memset(vis, 0, sizeof(vis));
memset(dis, LINF, sizeof(dis));
dis[n] = 0;
PQ.push({-dis[n], n});
while (!PQ.empty()) {
int u = PQ.top().second;
PQ.pop();
if (vis[u]) continue;
vis[u] = 1;
if (vis[0]) continue;
if (u % 2 == 0) {
int v = u / 2;
long long cost = min(1LL * y, 1LL * (u / 2) * x);
if (vis[v] == 0 && dis[v] > dis[u] + cost) {
dis[v] = dis[u] + cost;
PQ.push({-dis[v], v});
}
continue;
}
int v = u - 1;
if (vis[v] == 0 && dis[v] > dis[u] + x) {
dis[v] = dis[u] + x;
PQ.push({-dis[v], v});
}
v = u + 1;
if (vis[v] == 0 && dis[v] > dis[u] + x) {
dis[v] = dis[u] + x;
PQ.push({-dis[v], v});
}
}
printf("%lld\n", dis[0]);
}
} // namespace Solver
int main() {
Solver::InitOnce();
while (true) {
Solver::Read();
Solver::Solve();
}
return 0;
}
| 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
map<char, int> mp;
for (int i = 0; i < s.size(); i++) mp[s[i]]++;
if(abs(mp['a'] - mp['b']) > 1){
cout << "NO" << endl;
}else if(abs(mp['a'] - mp['c']) > 1){
cout << "NO" << endl;
}else if(abs(mp['c'] - mp['b']) > 1){
cout << "NO" << endl;
}else{
cout << "YES" << endl;
}
return 0;
} | 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define endl '\n'
using ll=long long;
const int INF=1e9+5;
const ll lim=(ll)3e16;
const int N=510000;
const int mod=1e9+7;
const ll oo=1e18+5;
int main(){
ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
int n;
cin>>n;
if(n<3) return cout<<-1,0;
if(n==3){
cout<<"aa.\n..a\n..a"<<endl;
return 0;
}
vector<string> matrixx[8];
// 4
matrixx[4].push_back("aabc");
matrixx[4].push_back("ddbc");
matrixx[4].push_back("bcaa");
matrixx[4].push_back("bcdd");
// 5
matrixx[5].push_back("aabba");
matrixx[5].push_back("bcc.a");
matrixx[5].push_back("b..cb ");
matrixx[5].push_back("a..cb");
matrixx[5].push_back("abbaa");
// 6
matrixx[6].push_back("aabc..");
matrixx[6].push_back("ddbc..");
matrixx[6].push_back("..aabc");
matrixx[6].push_back("..ddbc");
matrixx[6].push_back("bc..aa");
matrixx[6].push_back("bc..dd");
//7
matrixx[7].push_back("aabbcc.");
matrixx[7].push_back("dd.dd.a");
matrixx[7].push_back("..d..da");
matrixx[7].push_back("..d..db");
matrixx[7].push_back("dd.dd.b");
matrixx[7].push_back("..d..dc");
matrixx[7].push_back("..d..dc");
int rem=n%4;
int k=n/4;
if(rem) --k;
int times=-1;
//~ int loopp=0;
for(int i=0;i<k*4;++i)
{
if(i%4==0) ++times;
for(int j=0;j<times*4;++j) cout<<".";
cout<<matrixx[4][i%4];
for(int j=times*4+4;j<n;++j) cout<<".";
cout<<endl;
}
++times;
if(rem){
for(int i=0;i<4+rem;++i){
for(int j=0;j<times*4;++j) cout<<".";
cout<<matrixx[rem+4][i%(rem+4)];
cout<<endl;
}
}
return 0;
}
| 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
string repeat(string s, int n) {
string s1 = s;
for (int i = 1; i < n; i++) s += s1;
return s;
}
int main() {
long long int t;
cin >> t;
while (t--) {
long long int x, y, k;
cin >> x >> y >> k;
long long int td = (k * (y + 1) + x - 3) / (x - 1) + k;
cout << td << endl;
}
return 0;
}
| 7 | CPP |
k = input().split()
s = int(k[0])
k = int(k[1]) - 1
stand = input().split()
cont = 0
for pos in stand:
stand[cont] = int(pos)
cont = cont + 1
if stand[k] != 0 and k < s - 1:
score = stand[k]
flag = True
while flag:
flag = False
if k < s - 1:
if stand[k + 1] == score:
k = k + 1
flag = True
else:
score = True
while score and stand[k] == 0:
k = k - 1
score = False
if k >= 0:
if stand[k] == 0:
score = True
k = k + 1
print(k) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
int i, j, c = 0, len, end, diff = 0, deci = 0;
int t;
cin >> t;
for (j = 1; j <= t; j++) {
cin >> len;
cin >> s;
end = len - 1;
for (i = 0; i < (len / 2); i++) {
diff = int(s[i]) - int(s[end]);
end--;
if (diff == 0 || diff == 2 || diff == -2) deci++;
diff = 0;
}
if (deci == len / 2)
cout << "YES";
else
cout << "NO";
diff = 0;
deci = 0;
end = 0;
cout << endl;
}
}
| 7 | CPP |
ans = 0
for i in range(1,int(input())+1):
ans += 1/i
print(ans) | 8 | PYTHON3 |
while True:
try:
def solv():
n = int(input())
awy = [0]*(10**5+1)
aw = list()
for i in range(n):
hm, a= map(int, input().split())
aw.append(a)
awy[hm] += 1
for i in range(n):
print((n+awy[aw[i]]-1), (n-1)-(awy[aw[i]]))
if __name__=="__main__":
solv()
except EOFError:
break
| 8 | PYTHON3 |
n,m=map(int,input().split())
h=list(map(int,input().split()))
ab=[list(map(int,input().split())) for i in range(m)]
li=[1]*n
for i in ab:
if h[i[0]-1]>=h[i[1]-1]:
li[i[1]-1]-=1
if h[i[0]-1]<=h[i[1]-1]:
li[i[0]-1]-=1
print(li.count(1)) | 0 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
int n = s.size();
int cnt[26] = {};
for(int i = 0; i < n; i++) {
cnt[s[i]-'a']++;
}
int odd = 0;
for(int i = 0; i < 26; i++) {
odd += cnt[i]%2;
}
cout << odd/2 << endl;
return 0;
} | 0 | CPP |
t=int(input())
for i in range(t):
a=0
b=0
n=int(input())
if(n%4!=0):
print('NO')
else:
print("YES")
for i in range(2,n+1,2):
print(i,end=" ")
a+=i
for i in range(1,n-2,2):
print(i,end=" ")
b+=i
print(a-b)
| 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
long long cf10[20];
pair<long long, int> f[10][20][10];
pair<long long, int> dp(int x, long long n) {
if (n < 10) {
if (n >= x)
return make_pair(2, -x);
else
return make_pair(1, n - x);
}
int e = 18;
while (cf10[e] > n) e--;
pair<long long, int> ret = dp(max(x, (int)(n / cf10[e])), n % cf10[e]);
long long ans = ret.first;
int offset = ret.second;
for (int i = n / cf10[e] - 1; i >= 0; i--) {
ret = f[max(x, i)][e - 1][offset + 10];
ans += ret.first;
offset = ret.second;
}
return make_pair(ans, offset);
}
int main() {
cf10[0] = 1;
for (int i = 1; i < 19; i++) {
cf10[i] = 10 * cf10[i - 1];
}
for (int j = 0; j < 19; j++)
for (int i = 0; i < 10; i++)
for (int k = 0; k < 10; k++) f[i][j][k] = dp(i, cf10[j] * 10 - 10 + k);
long long n;
cin >> n;
if (n == 0)
cout << 0 << endl;
else
cout << dp(0, n).first - 1 << endl;
return 0;
}
| 9 | CPP |
t = int(input())
for i in range(t):
a,b,c = map(int,input().split())
print(b+(a+c-b)//2) | 7 | PYTHON3 |
n = int( input() )
Q = 0
P = 0
Df = 0
Db = 0
l=[]
for a in range(n):
x = int(input())
if a==n-1 and x!=0:
l.append(x)
if x==0 or a==n-1:
insQ=True
if l!=[]:
Q = max(l)
for i in l:
if i==Q and insQ:
print("pushQueue")
insQ=False
elif i>P and P<=Df:
print("pushStack")
P=i
elif i>Df and Df<=P:
print("pushFront")
Df=i
else:
print("pushBack")
#estrazione
if a!=n-1 or x==0:
cnt=0
s = ""
if Q!=0:
cnt+=1
s+=" popQueue"
if P!=0:
cnt+=1
s+=" popStack"
if Df!=0:
cnt+=1
s+=" popFront"
print( str(cnt) + s )
Q=0
P=0
Df=0
Db=0
l=[]
else:
l.append(x)
| 9 | PYTHON3 |
Subsets and Splits