solution
stringlengths 10
983k
| difficulty
int64 0
25
| language
stringclasses 2
values |
---|---|---|
n = int(input())
sum = 0
d = {'Tetrahedron' : 4, 'Cube' : 6, 'Octahedron' : 8, 'Dodecahedron' : 12, 'Icosahedron' : 20}
for i in range(n):
sum += d[input()]
print(sum) | 7 | PYTHON3 |
#include <bits/stdc++.h>
// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#include <time.h>
#define dibs reserve
#define OVER9000 1234567890
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) ((x < 0)?-(x):x)
#define uint unsigned int
#define dbl long double
#define pi 3.14159265358979323846
using namespace std;
// mylittledoge
typedef long long cat;
#ifdef DONLINE_JUDGE
// palindromic tree is better than splay tree!
#define lld I64d
#endif
int main() {
cin.sync_with_stdio(0);
cin.tie(0);
cout << fixed << setprecision(10);
int A,B;
cin >> A >> B;
vector< vector<int> > d(A,vector<int>(B));
for(int i =0; i < A*B; i++) cin >> d[i/B][i%B];
vector< vector<int> > mincost(101,vector<int>(101,0));
for(int i =1; i <= A; i++) for(int j =1; j <= B; j++)
for(int k =0; k <= 100; k++) for(int l =0; l <= 100; l++)
mincost[k][l] =max(d[i-1][j-1]-k*i-l*j,mincost[k][l]);
for(int i =1; i <= A; i++) for(int j =1; j <= B; j++) {
int m =101;
for(int k =0; k <= 100; k++) for(int l =0; l <= 100; l++)
m =min(m,mincost[k][l]+k*i+l*j);
if(m != d[i-1][j-1]) {
cout << "Impossible\n";
return 0;
}
}
cout << "Possible\n";
int N =2*(100+1), M =(N/2)*(N/2)+2*(N/2-1);
cout << N << " " << M << "\n";
for(int i =0; i < N/2-1; i++) cout << i+1 << " " << i+2 << " X\n";
for(int i =0; i <= N/2-1; i++) for(int j =0; j <= N/2-1; j++)
cout << i+1 << " " << N-j << " " << mincost[i][j] << "\n";
for(int i =0; i < N/2-1; i++) cout << i+N/2+1 << " " << i+N/2+2 << " Y\n";
cout << "1 " << N << "\n";
return 0;}
// look at my code
// my code is amazing
| 0 | CPP |
n=int(input())
list_of_divisors=[]
for i in range(1,n+1):
if n%i==0:
list_of_divisors.append(i)
c='47'
Result=False
for i in list_of_divisors:
Result1=True
for j in str(i):
if not(j in c):
Result1=False
if Result1:
Result=True
break
if Result:
print('YES')
else:
print('NO')
| 7 | PYTHON3 |
#include <iostream>
using namespace std;
int n;
int main(){
scanf("%d",&n);
bool ok=0;
for(int i=1;i<=n;i++){
int x;scanf("%d",&x);
if(x&1)ok=1;
}
printf("%s\n", ok?"first":"second");
} | 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<long long> v;
for (int i = 0; i < n; i++) {
long long temp;
cin >> temp;
v.push_back(temp);
}
if (v.size() == 1) {
cout << v[0] << endl;
return 0;
}
sort(v.begin(), v.end());
long long ans = 0;
for (long long i = 0; i < v.size(); i++) ans += v[i] * (i + 2);
cout << ans - v[n - 1] << endl;
}
| 7 | CPP |
def gcd(a,b):
large=1
for i in range(1,min(a,b)+1):
if(a%i==0 and b%i==0):
large=i
return large
a,b,n=map(int,input().split())
while(True):
if(gcd(a,n)<=n):
n-=gcd(a,n)
else:
print("1")
exit()
if(gcd(b,n)<=n):
n-=gcd(b,n)
else:
print("0")
exit()
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
long long m, n;
string s;
int CapsLock(string s) {
for (int i = 0; i < s.size(); i++) {
if (s[i] > 92) {
s[i] -= 32;
} else if (s[i] < 92) {
s[i] += 32;
}
}
cout << s;
return 0;
}
int main() {
cin >> s;
if (s.size() == 1) {
CapsLock(s);
return 0;
}
for (int i = 0; i < s.size(); i++) {
if (s[i] < 92) {
m++;
if (m == s.size()) {
CapsLock(s);
return 0;
}
}
if (s[0] > 92 && s[i] < 92 && i != 0) {
n++;
if (n + 1 == s.size()) {
CapsLock(s);
return 0;
}
}
}
cout << s;
}
| 7 | CPP |
n, x0 = list(map(int, input().rstrip().split()))
x = [0] * 1002
for _ in range(n):
a, b = list(map(int, input().rstrip().split()))
x[min(a,b)] += 1
x[max(a,b) + 1] += -1
minD = 1002
arr = [0] * 1001
arr[0] = x[0]
if arr[0] == n:
minD = abs(0 - x0)
for i in range(1, len(arr)):
arr[i] += arr[i - 1] + x[i]
if arr[i] == n:
if abs(i - x0) < minD:
minD = abs(i - x0)
if minD == 1002:
print(-1)
else:
print(minD)
| 8 | PYTHON3 |
def sieve(n):
prime = [-1]*(n+1)
for i in range(2,n+1):
if prime[i]==-1:
for j in range(i,n+1,i):
prime[j] = i
return prime
prime = sieve(100010)
for nt in range(int(input())):
p,q = map(int,input().split())
if p>q:
if p%q!=0:
print (p)
else:
primes = []
for i in range(2,int(q**0.5)+2):
if q%i==0:
primes.append(i)
if q//i!=1:
primes.append(q//i)
ans = 1
if not primes:
primes.append(q)
# print (primes)
for i in primes:
k = 1
while p%(i**k)==0:
# print (p//(i**k))
if (p//(i**k))%q!=0:
ans = max(ans, p//(i**k))
break
k += 1
print (ans)
elif p==q:
num = -1
for i in range(2,int(p**0.5)+1):
if p%i==0:
num = i
break
if num==-1:
print (1)
else:
print (p//num)
else:
print (p) | 7 | PYTHON3 |
t=int(input())
s=[]
for i in range(t):
input()
q=sorted(list(map(int,input().split())))
n=max(q)
while len([i for i in q if i>=n])<n:
n-=1
s.append(n)
[print(i) for i in s] | 7 | PYTHON3 |
n = int(input())
x = 0
for i in range(0, n):
s = input()
if "++" in s:
x += 1
else:
x -= 1
print(x)
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int N, M, A, B, i, z = INT_MAX;
int main() {
for (cin >> N >> M; i < M; i++) {
cin >> A >> B;
z = min(z, B - A + 1);
}
cout << z;
while (N) {
cout << '\n' << N-- % z;
}
}
| 7 | CPP |
#include <bits/stdc++.h>
#define gc getchar()
using namespace std;
typedef long long ll;
const int N=200009;
int n,fa[N],a[N],f[N],c[N][2];
ll Ans;
struct cmp
{
bool operator() (const int &x,const int &y)
{
if ((ll)c[x][0]*c[y][1]==(ll)c[x][1]*c[y][0]) return x<y;
return (ll)c[x][0]*c[y][1]>(ll)c[x][1]*c[y][0];
}
};
multiset<int,cmp> st;
int read()
{
int x=1;
char ch;
while (ch=gc,ch<'0'||ch>'9') if (ch=='-') x=-1;
int s=ch-'0';
while (ch=gc,ch>='0'&&ch<='9') s=s*10+ch-'0';
return s*x;
}
int find(int x)
{
return f[x]==x?x:f[x]=find(f[x]);
}
int main()
{
n=read();
for (int i=2;i<=n;i++) fa[i]=read();
for (int i=1;i<=n;i++) f[i]=i,a[i]=read(),c[i][a[i]]++;
for (int i=2;i<=n;i++) st.insert(i);
for (int i=1;i<n;i++)
{
int x=(*st.begin());
int y=find(fa[x]);
st.erase(x);
if (y!=1) st.erase(y);
Ans+=(ll)c[y][1]*c[x][0];
c[y][0]+=c[x][0],c[y][1]+=c[x][1];
f[x]=y;
if (y!=1) st.insert(y);
}
printf("%lld\n",Ans);
return 0;
}
| 0 | CPP |
import sys
input = sys.stdin.readline
def main():
t = int(input())
for _ in range(t):
N = int(input())
if (N // 2) % 2 == 1:
print("NO")
else:
print("YES")
A = [2 * i for i in range(1, N // 2 + 1)]
sa = sum(A)
sb = 0
for i in range(N // 2 - 1):
sb += i * 2 + 1
A.append(i * 2 + 1)
A.append(sa - sb)
print(*A)
if __name__ == '__main__':
main()
| 8 | PYTHON3 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast, unroll-loops")
using namespace std;
const int N = 50000;
vector<vector<int> > adj(N);
vector<int> start(N);
vector<int> ending(N);
vector<int> order(N);
vector<int> depth(N);
int counter = 0;
void dfs(int v, int d) {
depth[counter] = d;
order[counter] = v;
start[v] = counter;
counter++;
for (auto &u : adj[v]) {
dfs(u, d + 1);
}
ending[v] = counter - 1;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int n, q;
cin >> n >> q;
vector<int> A(n);
for (int i = 0; i < n; i++) cin >> A[i];
for (int i = 0; i < n - 1; i++) {
int a;
cin >> a;
a--;
adj[a].push_back(i + 1);
}
dfs(0, 0);
vector<int> last(n);
vector<int> dur(n);
for (int i = 0; i < n; i++) {
last[i] = -A[order[i]];
dur[i] = A[order[i]];
}
for (int i = 0; i < q; i++) {
int x;
cin >> x;
int count = 0;
int sum = 0;
int second = start[x - 1];
int e = ending[x - 1];
for (int j = second; j <= e; j++) {
int cond = (last[j] + dur[j] <= i);
last[j] += cond * (i - last[j]);
sum += cond * (depth[j] - depth[second]);
count += cond;
}
cout << sum << " " << count << endl;
}
}
| 15 | CPP |
#include <bits/stdc++.h>
using namespace std;
void qmax(int &x, int y) {
if (x < y) x = y;
}
void qmin(int &x, int y) {
if (x > y) x = y;
}
long long read() {
char s;
long long k = 0, base = 1;
while ((s = getchar()) != '-' && s != EOF && !(isdigit(s)))
;
if (s == EOF) exit(0);
if (s == '-') base = -1, s = getchar();
while (isdigit(s)) {
k = k * 10 + (s ^ '0');
s = getchar();
}
return k * base;
}
void write(int x) {
if (x < 0) {
putchar('-');
write(-x);
} else {
if (x / 10) write(x / 10);
putchar(x % 10 + '0');
}
}
const int maxn = 1e5 + 100;
char a[maxn];
char b[maxn];
int T, n, m;
int A, B, C, D;
int sa[maxn][4];
int sb[maxn][4];
int ne[maxn];
int n1[maxn];
int main() {
scanf("%s", a + 1);
scanf("%s", b + 1);
n = strlen(a + 1);
m = strlen(b + 1);
T = read();
for (int i = 1; i <= n; i++) sa[i][a[i] - 'A']++;
for (int i = 1; i <= m; i++) sb[i][b[i] - 'A']++;
for (int i = 1; i <= n; i++) {
if (a[i - 1] == 'A')
ne[i] = ne[i - 1];
else
ne[i] = i - 1;
if (a[i] != 'A') ne[i] = i;
sa[i][1] += sa[i - 1][1];
sa[i][2] += sa[i - 1][2];
sa[i][0] = sa[i][1] + sa[i][2];
}
for (int i = 1; i <= m; i++) {
if (b[i - 1] == 'A')
n1[i] = n1[i - 1];
else
n1[i] = i - 1;
if (b[i] != 'A') n1[i] = i;
sb[i][1] += sb[i - 1][1];
sb[i][2] += sb[i - 1][2];
sb[i][0] = sb[i][1] + sb[i][2];
}
while (T--) {
A = read();
B = read();
C = read();
D = read();
int s1, s2, Y;
s1 = sa[B][0] - sa[A - 1][0];
s2 = sb[D][0] - sb[C - 1][0];
if (s1 > s2 || s1 % 2 != s2 % 2) {
printf("0");
continue;
}
if (s1 % 2 == s2 % 2) {
int X = (B - ne[B]);
X = min(X, B - A + 1);
Y = min(D - n1[D], D - C + 1);
if (s1 == 0 && X == Y && s2 != 0) {
printf("0");
continue;
}
if (X < Y) {
printf("0");
continue;
}
if (((X - Y) % 3 == 0) || s1 + 2 <= s2) {
printf("1");
continue;
}
printf("0");
} else
printf("0");
}
return 0;
}
| 10 | CPP |
n=input()
b=int(n,2)
count=0
i=1
while i<b:
i=i*4
count+=1
print(count)
| 7 | PYTHON3 |
for _ in range(int(input())):
n=int(input())
k=2
while True:
if n%(pow(2,k)-1)==0:
print(n//(pow(2,k)-1))
break
k+=1 | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
long long n;
string s;
int seat[7] = {4, 5, 6, 3, 2, 1};
int main() {
cin >> s;
n = 0;
for (int i = 0; i < s.size() - 1; i++) {
n *= 10;
n += s[i] - '0';
}
char ch = s[s.size() - 1];
long long rs = 0;
rs += (n - 1) / 4 * 2 * 6 + (n - 1) / 4 * 4;
n = (n - 1) % 4 + 1;
if (n == 1 || n == 3) {
rs += seat[ch - 'a'];
} else if (n == 2 || n == 4) {
rs += 1;
rs += 6;
rs += seat[ch - 'a'];
}
cout << rs;
return 0;
}
| 8 | CPP |
n=int(input())
b=list(map(int,input().split()))
ope=[[] for i in range(n)]
Q=int(input())
for i in range(Q):
l,r=map(int,input().split())
ope[r-1].append(l-1)
res=b.count(0)
Data=[(-1)**((b[i]==1)+1) for i in range(n)]
for i in range(1,n):
Data[i]+=Data[i-1]
Data=[0]+Data
for i in range(n):
ope[i].sort(reverse=True)
# N: 処理する区間の長さ
N=n+1
N0 = 2**(N-1).bit_length()
data = [None]*(2*N0)
INF = (-2**31, -2**31)
# 区間[l, r+1)の値をvに書き換える
# vは(t, value)という値にする (新しい値ほどtは大きくなる)
def update(l, r, v):
L = l + N0; R = r + N0
while L < R:
if R & 1:
R -= 1
if data[R-1]:
data[R-1] = max(v,data[R-1])
else:
data[R-1]=v
if L & 1:
if data[L-1]:
data[L-1] = max(v,data[L-1])
else:
data[L-1]=v
L += 1
L >>= 1; R >>= 1
# a_iの現在の値を取得
def _query(k):
k += N0-1
s = INF
while k >= 0:
if data[k]:
s = max(s, data[k])
k = (k - 1) // 2
return s
# これを呼び出す
def query(k):
return _query(k)[1]
for i in range(n+1):
update(i,i+1,(-Data[i],-Data[i]))
if ope[0]:
update(1,2,(0,0))
for i in range(1,n):
val=query(i)
update(i+1,i+2,(val+Data[i]-Data[i+1],val+Data[i]-Data[i+1]))
for l in ope[i]:
val=query(l)
update(l+1,i+2,(val,val))
print(n-(res+query(n)+Data[n])) | 0 | PYTHON3 |
for _ in range(int(input())):
n, x, y, d = map(int, input().split())
tt = abs(x - y)
if tt % d != 0:
ans = -1
if (y - 1) % d == 0:
ans = (x - 1) // d + (1 if (x-1) % d > 0 else 0) + (y - 1) // d
if (n - y) % d == 0:
cc = (n - x + d - 1) // d + (n - y) // d
if ans == -1 or cc < ans:
ans = cc
print(ans)
else:
print(tt // d) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
os << '{';
string sep;
for (const auto &x : v) os << sep << x, sep = ", ";
return os << '}';
}
template <typename T, size_t size>
ostream &operator<<(ostream &os, const array<T, size> &arr) {
os << '{';
string sep;
for (const auto &x : arr) os << sep << x, sep = ", ";
return os << '}';
}
template <typename A, typename B>
ostream &operator<<(ostream &os, const pair<A, B> &p) {
return os << '(' << p.first << ", " << p.second << ')';
}
void dbg_out() { cerr << endl; }
template <typename Head, typename... Tail>
void dbg_out(Head H, Tail... T) {
cerr << ' ' << H;
dbg_out(T...);
}
using T_tree = int;
const T_tree T_INF = numeric_limits<T_tree>::max() / 2;
struct segment_change {
T_tree to_add;
segment_change(T_tree _to_add = 0) : to_add(_to_add) {}
};
struct segment {
T_tree max_prefix, sum;
segment(T_tree _max_prefix = -T_INF, T_tree _sum = 0)
: max_prefix(_max_prefix), sum(_sum) {}
void apply(const segment_change &change) {
max_prefix += change.to_add;
sum += change.to_add;
}
void join(const segment &other) {
max_prefix = max(max_prefix, sum + other.max_prefix);
sum += other.sum;
}
void join(const segment &a, const segment &b) {
*this = a;
join(b);
}
};
int right_half[32];
struct max_prefix_sum_tree {
static const bool POWER_OF_TWO_MODE = true;
int tree_n = 0;
vector<segment> tree;
max_prefix_sum_tree(int n = -1) {
if (n >= 0) init(n);
}
void init(int n) {
if (POWER_OF_TWO_MODE) {
tree_n = 1;
while (tree_n < n) tree_n *= 2;
} else {
tree_n = n;
}
tree.assign(2 * tree_n, segment());
}
void build(const vector<segment> &initial) {
int n = int(initial.size());
init(n);
assert(n <= tree_n);
for (int i = 0; i < n; i++) tree[tree_n + i] = initial[i];
for (int position = tree_n - 1; position > 0; position--)
tree[position].join(tree[2 * position], tree[2 * position + 1]);
}
segment query(int a, int b) const {
assert(0 <= a && a <= b && b <= tree_n);
segment answer;
int r_size = 0;
for (a += tree_n, b += tree_n; a < b; a /= 2, b /= 2) {
if (a & 1) answer.join(tree[a++]);
if (b & 1) right_half[r_size++] = --b;
}
for (int i = r_size - 1; i >= 0; i--) answer.join(tree[right_half[i]]);
return answer;
}
segment query_single(int index) const {
assert(0 <= index && index < tree_n);
return tree[tree_n + index];
}
void join_up(int position) {
while (position > 1) {
position /= 2;
tree[position].join(tree[2 * position], tree[2 * position + 1]);
}
}
void update(int index, const segment_change &change) {
assert(0 <= index && index < tree_n);
int position = tree_n + index;
tree[position].apply(change);
join_up(position);
}
void update(int index, const segment &seg) {
assert(0 <= index && index < tree_n);
int position = tree_n + index;
tree[position] = seg;
join_up(position);
}
};
struct add_max_seg_tree {
max_prefix_sum_tree tree;
add_max_seg_tree(int n = -1) {
if (n >= 0) init(n);
}
void init(int n) { tree.init(n); }
void build(const vector<T_tree> &initial) {
vector<segment> segment_initial(initial.size());
T_tree previous = 0;
for (int i = 0; i < int(initial.size()); i++) {
T_tree value = initial[i] - previous;
previous = initial[i];
segment_initial[i] = segment(value, value);
}
tree.build(segment_initial);
}
T_tree query(int a, int b) const {
return tree.query(0, a).sum + tree.query(a, b).max_prefix;
}
T_tree query_full() const { return tree.tree[1].max_prefix; }
void update(int a, int b, segment_change change) {
if (a < tree.tree_n) tree.update(a, change);
if (b < tree.tree_n) {
change.to_add *= -1;
tree.update(b, change);
}
}
void set_value(int index, T_tree value) {
T_tree current = query(index, index + 1);
update(index, index + 1, segment_change(value - current));
}
};
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N, K, M;
cin >> N >> K >> M;
K--;
add_max_seg_tree tree(2 * N);
vector<int> initial(2 * N);
for (int i = 0; i < 2 * N; i++) initial[i] = i;
tree.build(initial);
map<array<int, 2>, int> pawns;
multiset<int> coords;
for (int i = 0; i < M; i++) {
int x, y;
cin >> x >> y;
x--;
y--;
int status = pawns[{x, y}]++ % 2;
status = status == 0 ? +1 : -1;
int coordinate = y + abs(x - K);
if (status > 0)
coords.insert(coordinate);
else
coords.erase(coords.find(coordinate));
tree.update(0, coordinate + 1, segment_change(status));
int answer = 0;
if (!coords.empty())
answer = max(tree.query(0, *coords.rbegin() + 1) - N, 0);
cout << answer << '\n';
}
}
| 13 | CPP |
a, b = [input().lower() for _ in range(2)]
if a == b:
print(0)
elif a < b:
print(-1)
else:
print(1)
| 7 | PYTHON3 |
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <sstream>
#include <functional>
#include <numeric>
#include <cmath>
#include <cstring>
#include <cstdio>
#include <queue>
#include <stack>
#include <set>
using namespace std;
#define ALL(co) co.begin(), co.end()
#define tpl(...) make_tuple(__VA_ARGS__)
typedef long long LL;
typedef pair<int, int> P; typedef pair<int, P> IP; typedef pair<P, P> PP;
typedef vector<int> Array; typedef vector<vector<int> > Array2;
typedef vector<LL> LArray; typedef vector<P> PArray; typedef vector<string> SArray;
const int INF = 1 << 29;
const LL LINF = 1LL << 60;
inline int getInt() { int itiv; return (cin >> itiv, itiv); }
template <typename T> void readAll(vector<T>& vec) { for (int i = 0, size = vec.size(); i < size; i++) cin >> vec[i]; }
template <typename T, typename U> void readAll(vector<pair<T, U> >& vec) { for (int i = 0, size = vec.size(); i < size; i++) cin >> vec[i].first >> vec[i].second; }
template < typename T > inline string toString( const T &a ){ ostringstream oss; oss << a; return oss.str(); };
inline bool between(int min, int max, int n) { return min <= n && n <= max; }
inline bool inRange(int begin, int end, int n) { return begin <= n && n < end; }
inline bool inRange(int size, int n) { return 0 <= n && n < size; }
int dx[] = { -1, 0, 1, 0 }, dy[] = { 0, -1, 0, 1 };
int dr[] = { 0, -1, 0, 1 }, dc[] = { -1, 0, 1, 0 };
//turn, mass, money -> e;
double dp[51][5010];
int x, y, z;
int main(void)
{
while(cin >> x >> y >> z && x)
{
memset(dp, 0, sizeof(dp));
vector<P> events(y + 1);
vector<int> roulette(x);
readAll(roulette);
int maxmoney = 0;
for (int i = 0; i < z; i++)
{
int n, e, a;
cin >> n >> e >> a;
events[n] = P(e, a);
if(e == 2)
maxmoney += a;
}
dp[0][0] = 1.;
double mag = 1.0 / (double)x;
for (int i = 0; i <= y; i++)
{
for (int j = i; j < y; j++)
{
for (int k = 0; k <= maxmoney; k++)
{
double exp = dp[j][k] * mag;
for (int l = 0; l < x; l++)
{
int next = min(j + roulette[l], y);
int money = k;
int ev = events[next].first;
int value = events[next].second;
if(ev != 0)
{
if(ev == 1)
{
next = min(next + value, y);
}
if(ev == 2)
{
money += value;
}
if(ev == 3)
{
money = max(0, money - value);
}
}
dp[next][money] += exp;
dp[j][k] = 0;
}
}
}
}
double result = 0;
for (int k = 0; k <= 5000; k++)
{
result += dp[y][k] * k;
}
cout << (int)result << endl;
}
return 0;
} | 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void printArr(T* arr, int size) {
for (int i = 0; i < size; i++) cout << arr[i] << " ";
cout << endl;
}
long long fast_exp(long long x, long long y) {
if (y == 1) return x;
if (y == 0) return 1;
if (y & 1)
return x * fast_exp(x, y - 1);
else {
long long re = fast_exp(x, y / 2);
return re * re;
}
}
int main() {
ios_base::sync_with_stdio(0);
long long a = 0;
string s;
cin >> a >> s;
unordered_map<int, int> ht;
for (int i = 0; i < s.size(); i++) {
int interv = 0;
for (int j = i; j < s.size(); j++) {
interv += s[j] - '0';
unordered_map<int, int>::iterator it = ht.find(interv);
if (it == ht.end()) {
ht.insert(make_pair(interv, 1));
} else {
++it->second;
}
}
}
long long ans = 0;
for (int i = 0; i < s.size(); i++) {
int interv = 0;
for (int j = i; j < s.size(); j++) {
interv += s[j] - '0';
if (a == 0 && interv == 0) {
long long siz = s.size() * 1LL;
ans += ((siz) * (siz - 1) / 2) + siz;
} else {
if (interv != 0 && a % interv == 0) {
long long other = a / interv;
unordered_map<int, int>::iterator it = ht.find(other);
if (it != ht.end()) {
ans += it->second;
}
}
}
}
}
cout << ans << endl;
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
int cnt[4], ans[4], c = 1;
char S[10000], T[10000];
int n;
int main() {
scanf("%d%s%s", &n, S, T);
for (int i = 0; i < n; i++) cnt[(S[i] & 1) << 1 | (T[i] & 1)]++;
for (int d = 0; d <= cnt[3]; d++) {
int a = (n >> 1) + d - cnt[1] - cnt[3];
if (0 <= a && a <= cnt[0]) {
int Sbc = cnt[1] + cnt[3] - 2 * d;
if (0 <= Sbc && Sbc <= cnt[1] + cnt[2]) {
ans[0] = a, ans[3] = d, ans[1] = std::min(Sbc, cnt[1]),
ans[2] = Sbc - ans[1], c = 0;
}
}
}
if (c)
puts("-1");
else {
for (int i = 0; i < n; i++) {
int v = (S[i] & 1) << 1 | (T[i] & 1);
if (ans[v]) printf("%d ", i + 1), ans[v]--;
}
}
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 998244353;
const int oo = (int)1e9;
const long long OO = (long long)1e18;
const double PI = acos(-1.0);
const int N = (int)1e5 + 9;
bool isprime(long long n) {
if (n <= 1) return 0;
for (long long i = 2; i * i <= n; i++)
if (n % i == 0) return false;
return 1;
}
long long intlog(long long base, long long x) { return (log(x) / log(base)); }
bool prime[N];
void primee() {
for (int p = 2; p * p <= N; p++) {
if (prime[p] == true) {
for (int i = p * 2; i < N; i += p) prime[i] = false;
}
}
}
string decToBinary(long long n) {
string z = "";
int i = 0;
while (n > 0) {
z += (n % 2) + 48;
n = n / 2;
i++;
}
reverse(((z).begin()), ((z).end()));
return z;
}
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long power(long long x, int y) {
long long temp;
if (y == 0) return 1;
temp = power(x, y / 2);
if (y % 2 == 0)
return temp * temp;
else
return x * temp * temp;
}
int main() {
int n;
scanf("%d", &n);
printf("%d\n", n == 2 ? 2 : 1);
return 0;
}
| 7 | CPP |
n = int(input())
a = list(map(int,input().split()))
for i in range(n): a[i] -= 1
ans = sum([i == a[a[i]] for i in range(n)])
print(ans//2) | 0 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN=(3e5+10)*3,MOD=1e9+7;
ll res=0,cur=1;
int n,m,k,fac[MAXN],inv[MAXN];
ll quick_pow(ll a,ll b)
{
ll ret=1;
for(;b;b>>=1,a=a*a%MOD)
if(b&1) ret=ret*a%MOD;
return ret;
}
int C(int a,int b)
{if(a<b||b<0) return 0;return 1ll*fac[a]*inv[b]%MOD*inv[a-b]%MOD;}
int main()
{
scanf("%d%d%d",&n,&m,&k);
fac[0]=1;
for(int i=1;i<MAXN;i++)
fac[i]=1ll*fac[i-1]*i%MOD;
inv[MAXN-1]=quick_pow(fac[MAXN-1],MOD-2);
for(int i=MAXN-2;i>=0;i--)
inv[i]=1ll*inv[i+1]*(i+1)%MOD;
for(int i=n;i<=n+m+k;i++)
(res+=C(i-1,n-1)*cur%MOD*quick_pow(3,n+m+k-i)%MOD)%=MOD,
cur=(2*cur-C(i-n,m)+MOD-C(i-n,i-n-k)+MOD)%MOD;
printf("%lld",res);
return 0;
} | 0 | CPP |
inp = input().split()
k = int(inp[0])
n = int(inp[1])
w = int(inp[2])
mn = 0
for i in range(w+1):
mn = mn + (i*k)
x = mn-n
if x > 0:
print(x)
else:
print(0) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
long double eps = 1e-8;
long double D(pair<long double, long double> a,
pair<long double, long double> b = {0, 0}) {
return sqrtl((a.first - b.first) * (a.first - b.first) +
(a.second - b.second) * (a.second - b.second));
}
long double eq(pair<long double, long double> a,
pair<long double, long double> b) {
return (abs(a.first - b.first) + abs(a.second - b.second) < eps);
}
pair<long double, long double> sub(pair<long double, long double> a,
pair<long double, long double> b) {
return {a.first - b.first, a.second - b.second};
}
long double cross(pair<long double, long double> a,
pair<long double, long double> b) {
long double den = D(sub(a, b));
long double num = a.first * b.second - a.second * b.first;
return abs(num / den);
}
long double D1, D2;
long double sq(long double a) { return a * a; }
vector<long double> ds(pair<long double, long double> a,
pair<long double, long double> b) {
pair<long double, long double> from = a, to = b;
long double da = D(a), db = D(b);
if (eq(from, {0, 0}) || eq(to, {0, 0}) || eq(from, to)) {
return {da, db};
}
long double perp = cross(from, to);
long double dis = sqrt(sq(da) - sq(perp)) + sqrt(sq(db) - sq(perp));
if (dis - eps > D(a, b)) {
return {da, db};
} else {
return {da, perp, db};
}
}
void modify(pair<long double, long double> las,
pair<long double, long double> final, bool &f, int &ans) {
auto vv = ds(las, final);
for (int i = 0; i < vv.size(); i++) {
if (f) {
if (vv[i] < D1 + eps) {
ans++;
f = 0;
}
} else {
if (vv[i] > D2 + eps) {
f = 1;
}
}
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int N;
cin >> N >> D1 >> D2;
long double ox, oy;
pair<long double, long double> las = {0, 0};
int ans = 0;
bool fdone = 1;
for (int i = 0; i < N; i++) {
pair<long double, long double> cur;
cin >> ox >> oy >> cur.first >> cur.second;
cur.first -= ox;
cur.second -= oy;
if (i == 0) {
if (D(cur) < D1 + eps) {
ans++;
fdone = 0;
}
} else {
modify(las, cur, fdone, ans);
}
las = cur;
}
cout << ans;
return 0;
}
| 15 | CPP |
keyboard = int(input())
number_Keyboard=[]
number_Keyboard = [int(s) for s in input().split()]
number_Keyboard.sort()
current = number_Keyboard[keyboard - 1] - number_Keyboard[0]
print(current - keyboard + 1)
| 7 | PYTHON3 |
print("+".join(sorted(input()[::2])))
# nothing
| 7 | PYTHON3 |
x, n = map(int, input().split())
p = set(map(int, input().split()))
ans = min(abs(x - i) for i in range(102) if i not in p)
print(x + ans if x - ans in p else x - ans)
| 0 | PYTHON3 |
#include <bits/stdc++.h>
const int N = (int)1e6 + 5;
const int M = (int)1e9 + 5;
const int mod = (int)1000000007;
const int max_prime = (int)1e6 + 3;
const int BLK = (int)700;
int main() {
int t;
scanf("%d", &t);
while (t--) {
long long int n, m, k;
scanf("%lld %lld %lld", &n, &m, &k);
if (m < n - 1 || m > n * (n - 1) / 2) {
printf("NO\n");
continue;
}
if (n == 1) {
if (k > 1) {
printf("YES\n");
} else {
printf("NO\n");
}
continue;
}
if (m == n * (n - 1) / 2) {
if (k > 2) {
printf("YES\n");
} else {
printf("NO\n");
}
continue;
}
if (m == n - 1) {
if (k > 3) {
printf("YES\n");
} else {
printf("NO\n");
}
continue;
}
if (k > 3) {
printf("YES\n");
} else {
printf("NO\n");
}
}
return 0;
}
| 8 | CPP |
n, m = [int(x) for x in input().split()]
ma = [[int(x) for x in input().split()]for q in range(n)]
z=0
for x in range(n):
for y in range(0,m*2,2):
if ma[x][y] + ma[x][y+1]>=1:
z+=1
print(z)
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
long long int binomialCoeff(long long int n, long long int k) {
long long int res = 1;
if (k > n - k) k = n - k;
for (int i = 0; i < k; ++i) {
res *= (n - i);
res /= (i + 1);
}
return res;
}
long long int power(long long int x, long long int y) {
long long int temp;
if (y == 0) return 1;
temp = power(x, y / 2);
if (y % 2 == 0)
return temp * temp;
else
return x * temp * temp;
}
vector<long long int> primes;
void Sieve(int n) {
vector<bool> prime(n + 1, true);
for (int p = 2; p * p <= n; p++) {
if (prime[p] == true) {
for (int i = p * p; i <= n; i += p) prime[i] = false;
}
}
for (int p = 2; p <= n; p++)
if (prime[p]) primes.push_back(p);
}
const int Nmax = 1e6 + 6;
long long int modInverse(long long int a, long long int m = 998244353) {
long long int m0 = m;
long long int y = 0, x = 1;
if (m == 1) return 0;
while (a > 1) {
long long int q = a / m;
long long int t = m;
m = a % m, a = t;
t = y;
y = x - q * y;
x = t;
}
if (x < 0) x += m0;
return x;
}
long long int row[Nmax];
long long int col[Nmax];
long long int rr[Nmax];
long long int cc[Nmax];
long long int ans;
long long int val[Nmax] = {0};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long int mod = 998244353;
int n, m;
cin >> n >> m;
long long int arr[n + 1][m + 1];
vector<tuple<long long int, long long int, long long int> > v;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cin >> arr[i][j];
v.push_back(make_tuple(arr[i][j], i, j));
}
}
sort(v.begin(), v.end());
pair<long long int, long long int> end;
cin >> end.first >> end.second;
long long int q = 0;
vector<long long int> v2;
for (int i = 0; i < v.size(); i++) {
long long int a, r, c;
tie(a, r, c) = v[i];
if (i == 0) {
v2.push_back(a);
val[i] = 0;
col[i] = c;
row[i] = r;
cc[i] = c * c;
rr[i] = r * r;
if (end.first == r && end.second == c) {
ans = 0;
break;
}
continue;
}
long long int q = lower_bound(v2.begin(), v2.end(), a) - v2.begin();
v2.push_back(a);
if (q == 0) {
val[i] = (val[i] + val[i - 1]) % mod;
row[i] = row[i - 1] + r;
row[i] %= mod;
col[i] = col[i - 1] + c;
col[i] %= mod;
rr[i] = rr[i - 1] + r * r;
rr[i] %= mod;
cc[i] = cc[i - 1] + c * c;
cc[i] %= mod;
if (end.first == r && end.second == c) {
ans = 0;
break;
}
continue;
}
long long int inv = modInverse(q);
long long int res = (r * r % mod + c * c % mod) % mod;
res += val[q - 1] * (inv) % mod;
res %= mod;
res += cc[q - 1] * (inv) % mod + rr[q - 1] * (inv) % mod;
res %= mod;
long long int t = ((2 * (r * row[q - 1]) % mod) % mod * (inv)) % mod +
((2 * (c * col[q - 1]) % mod) % mod * (inv)) % mod;
t %= mod;
res -= t;
if (res < 0) res += mod;
if (end.first == r && end.second == c) {
ans = res;
break;
}
val[i] = (val[i - 1] + res) % mod;
col[i] = (col[i - 1] + c) % mod;
row[i] = (row[i - 1] + r) % mod;
cc[i] = (cc[i - 1] + c * c) % mod;
rr[i] = (rr[i - 1] + r * r) % mod;
}
cout << ans % mod;
}
| 11 | CPP |
#accumulate and count function from itertools module are very slow
n = int(input())
data = list(map(int,input().split()))
M = max(data)
count = [0]*(M+1)
for i in data:
count[i]+=1
nc = [0]*(M+1)
for k in range(1,M+1):
nc[k] = nc[k-1]+count[k]
for j in range(int(input())):
m = int(input())
if m>=M:
print(nc[-1])
else:
print(nc[m])
| 8 | PYTHON3 |
number = eval(input())
x = 0
for i in range(number):
string = input()
if string[0] == 'X':
if string[1:] == '++':
x += 1
else:
x -= 1
else:
if string[:2] == '++':
x += 1
else:
x -= 1
print(x) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int a[105];
int main() {
int n;
int x, y;
while (cin >> n) {
x = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
if (a[i]) x++;
}
y = n - x;
int ans = 0;
for (int i = 0; i < n; i++) {
for (int j = i; j < n; j++) {
int t = 0;
for (int k = i; k <= j; k++) {
if (a[k]) t++;
}
if (ans < j - i + 1 - t + x - t) ans = j - i + 1 - t + x - t;
}
}
cout << ans << endl;
}
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 100;
const int maxm = 1e6 + 100;
const int INF = 1 << 30;
const long long mod = 1e9 + 7;
const int N = 500005;
int n, q, k, t[N], x[N], y[N], a[N], pre[N], sz[N], st[N], tp, d, m;
vector<int> tr[N << 2];
int fa(int x) {
while (pre[x] != x) x = pre[x];
return x;
}
void undo(int u) {
while (tp > u) {
int x = st[tp];
sz[pre[x]] -= sz[x];
pre[x] = x;
tp--;
}
}
void merge(int x, int y) {
x = fa(x), y = fa(y);
if (x == y) return;
tp++;
if (sz[x] < sz[y]) {
pre[x] = y;
st[tp] = x;
sz[y] += sz[x];
} else {
pre[y] = x;
st[tp] = y;
sz[x] += sz[y];
}
}
void update(int a, int b, int v, int l, int r, int rt) {
if (l == a && r == b) {
tr[rt].push_back(v);
return;
}
int mid = (l + r) >> 1;
if (b <= mid)
update(a, b, v, l, mid, rt << 1);
else if (a > mid)
update(a, b, v, mid + 1, r, rt << 1 | 1);
else
update(a, mid, v, l, mid, rt << 1),
update(mid + 1, b, v, mid + 1, r, rt << 1 | 1);
}
void sol(int l, int r, int rt) {
int u = tp;
for (auto i : tr[rt]) merge(x[i], y[i]);
if (l == r) {
if (t[l] == 2) printf("%d\n", sz[fa(x[l])]);
undo(u);
return;
}
int mid = l + r >> 1;
sol(l, mid, rt << 1);
sol(mid + 1, r, rt << 1 | 1);
undo(u);
}
int main() {
scanf("%d%d%d", &n, &q, &k);
for (int i = 1; i <= n; i++) pre[i] = i, sz[i] = 1;
d = 1;
for (int i = 1; i <= q; i++) {
scanf("%d", &t[i]);
if (t[i] == 1) scanf("%d%d", &x[i], &y[i]);
if (t[i] == 2) scanf("%d", &x[i]);
if (t[i] == 3) a[d++] = i - 1;
}
a[d] = q, m = d, d = 1;
for (int i = 1; i <= q; i++) {
if (t[i] == 1) update(i, a[min(d + k - 1, m)], i, 1, q, 1);
if (t[i] == 3) d++;
}
sol(1, q, 1);
return 0;
}
| 14 | CPP |
n, k = map(int, input().split())
a = list(map(int, input().split()))
answer = 0
for x in a:
if x >= a[k - 1] and x > 0:
answer += 1
print(answer) | 7 | PYTHON3 |
def order(str1):
counts = [0]*26
for x in str1:
counts[ord(x) - ord('A')]+=1
return counts
str1 = input()
str1 += input()
str2 = input()
if(order(str1) == order(str2)):
print("YES")
else:
print("NO") | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0; (i)<(n); (i)++)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define ll long long
#define pii pair<int,int>
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
const int INF = 1001001001;
//int 2×10の9乗
//vector<vector<int>> a(n, vector<int>(m));
//rep(i,n) rep(j,m) cin >> a[i][j];
//cout << fixed << setprecision(10);
//int gcd(int x, int y){
//if(y==0) return x;
//return gcd(y, x%y);
//}
//sort小さい順(昇順)
//g++ code.cpp ./a.out
int main(){
while(true){
int n; cin >> n;
if(n==0) break;
map<char,int> m;
int s1=0, s2=0;
char u;
bool h=false;
rep(i,n){
char s; cin >> s; m[s]++;
if(m[s]>s1) {
if (u!=s) s2=s1;
u=s;
s1=m[s];}
else s2=max(s2,m[s]);
if(s1 > s2+n-i-1 && !h){
cout << u << " " << i+1 << endl;
h=true;
}
}
if (!h) cout << "TIE" << endl;
}
}
| 0 | CPP |
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int cost[1000]={300000,200000,100000};
int main(){
int x,y;
cin>>x>>y;
if(x==1&&y==1)
cout<<"1000000";
else
cout<<cost[x-1]+cost[y-1];
} | 0 | CPP |
import sys
import math
import bisect
def solve(a, b):
if b == a:
return 0
if b > a:
if (b - a) % 2 == 1:
return 1
else:
return 2
else:
if (a - b) % 2 == 0:
return 1
else:
return 2
def main():
for _ in range(int(input())):
a, b = map(int, input().split())
print(solve(a, b))
if __name__ == "__main__":
main()
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
long double a, b, c, d, aad = 1e300, bad = -1e300, abc = 1e300, bbc = -1e300;
bool solve(long double x) {
aad = min(min(min((a - x) * (d - x), (a + x) * (d + x)), (a + x) * (d - x)),
(a - x) * (d + x));
bad = max(max(max((a - x) * (d - x), (a + x) * (d + x)), (a + x) * (d - x)),
(a - x) * (d + x));
abc = min(min(min((b - x) * (c - x), (b + x) * (c + x)), (b + x) * (c - x)),
(b - x) * (c + x));
bbc = max(max(max((b - x) * (c - x), (b + x) * (c + x)), (b + x) * (c - x)),
(b - x) * (c + x));
return (aad <= abc && abc <= bad) || (aad <= bbc && bbc <= bad) ||
(abc <= aad && aad <= bbc) || (abc <= bad && bad <= bbc);
}
int main() {
scanf("%Lf%Lf%Lf%Lf", &a, &b, &c, &d);
long double cur = 0;
for (long double i = 1e20; i >= 1e-20; i /= 2) {
if (!solve(cur + i)) cur += i;
}
printf("%.15Lf", cur);
}
| 14 | CPP |
if __name__ == '__main__':
n, t = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
if n == 1 and a[0] <= t:
print(1)
exit()
result = 0
buf = 0
for i in range(n):
if buf + a[i] > t:
break
buf += a[i]
result += 1
for i in range(n):
if i + result >= n:
break
buf = buf - a[i] + a[i + result]
while True:
if i + result + 1 >= n:
break
if buf + a[i + result + 1] > t:
break
buf += a[i + result + 1]
result += 1
print(result)
| 8 | PYTHON3 |
s = input()
s = s.replace('hi','')
if len(s):
print('No')
else:
print('Yes') | 0 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int i, j, n, m, a, b, c, d, op, mini, mij, ls, ld, ul, timp, k, maxl, rasp;
long long dp[1000005], flower[1000005], viz[1000005];
vector<int> v[1000005];
long long rez;
void go(int nod, int p) {
if (viz[nod]) return;
viz[nod] = 1;
for (int i = 0; i < v[nod].size(); i++) {
int nxt = v[nod][i];
if (nxt == p) continue;
go(nxt, nod);
dp[nod] += dp[nxt];
flower[nod] += flower[nxt];
}
long long total = dp[nod] + flower[nod];
if (nod == b)
rez += total + dp[nod];
else
rez += total * 2;
for (int i = 0; i < v[nod].size(); i++) {
int nxt = v[nod][i];
if (nxt == p) continue;
if (nod == b)
rez += (total - dp[nxt] - flower[nxt]) * dp[nxt];
else
rez += (total - dp[nxt] - flower[nxt]) * (dp[nxt] + flower[nxt]);
}
dp[nod]++;
if (nod == a) flower[nod] += dp[nod], dp[nod] = 0;
}
int main() {
ios_base::sync_with_stdio(false), cin.tie(NULL);
cin >> n >> a >> b;
for (int i = 1; i < n; i++)
cin >> c >> d, v[c].push_back(d), v[d].push_back(c);
go(b, -1);
cout << rez;
return 0;
}
| 9 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 10007;
int n, m, k, dist[N], ok;
pair<int, int> vertice[N];
int calc(int i, int j) {
if (i > j) swap(i, j);
if (j == k && !ok) {
if (abs(vertice[i].first - vertice[j].first) < 2 ||
abs(vertice[i].second - vertice[j].second) < 2)
return 1;
return 100000;
}
if (abs(vertice[i].first - vertice[j].first) +
abs(vertice[i].second - vertice[j].second) <
2)
return 0;
if (abs(vertice[i].first - vertice[j].first) <= 2 ||
abs(vertice[i].second - vertice[j].second) <= 2)
return 1;
return 100000;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m >> k;
for (int i = 1; i <= k; ++i)
cin >> vertice[i].first >> vertice[i].second,
ok |= (vertice[i].first == n && vertice[i].second == m);
if (!ok) ++k, vertice[k].first = n, vertice[k].second = m;
sort(vertice + 1, vertice + k + 1);
for (int i = 2; i <= k; ++i) dist[i] = 100000;
priority_queue<pair<int, int>, vector<pair<int, int> >,
greater<pair<int, int> > >
q;
q.push(make_pair(0, 1));
while (!q.empty()) {
pair<int, int> u = q.top();
q.pop();
if (dist[u.second] != u.first) continue;
for (int i = 2; i <= k; ++i)
if (dist[i] > dist[u.second] + calc(i, u.second))
dist[i] = dist[u.second] + calc(i, u.second),
q.push(make_pair(dist[i], i));
}
cout << (dist[k] == 100000 ? -1 : dist[k]) << endl;
return 0;
}
| 10 | CPP |
def fill(ind, y):
global pole
ind1 = ind - y + 1
ind2 = ind + t - 1
k = 1
for i in range(ind1, ind):
pole[i] += k
k += 1
k = t
for i in range(ind, ind2 + 1):
if k<y:
pole[i] += k
else:
pole[i] += y
k -= 1
m, t, r = map(int, input().split())
mas = list(map(int, input().split()))
if t < r:
print(-1)
else:
pole = [0] * 1000
answer = 0
for i in range(m):
answer += (r - pole[mas[i]])
fill(mas[i], r - pole[mas[i]])
print(answer) | 9 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
struct point {
long long x, y;
point(long long x = 0, long long y = 0) : x(x), y(y) {}
long long operator*(point p) { return x * p.x + y * p.y; }
long long operator^(point p) { return x * p.y - y * p.x; }
point operator-(point p) { return point(x - p.x, y - p.y); }
};
long long INF = 1e9;
struct line {
long long a, b, c;
line(point p, point q) {
a = p.y - q.y;
b = q.x - p.x;
c = -(p.x * a + p.y * b);
}
point operator*(line l) {
long long d = a * l.b - b * l.a;
if (d == 0) {
return point(INF, INF);
}
long long d1 = (-c) * l.b - b * (-l.c);
long long d2 = a * (-l.c) - (-c) * l.a;
if (d1 % d != 0 || d2 % d != 0) {
return point(INF, INF);
}
return point(d1 / d, d2 / d);
}
};
vector<pair<point, point> > v;
long long gcd(long long a, long long b) {
if (b == 0) {
return a;
}
return gcd(b, a % b);
}
set<long long> st;
bool in(point a, point b, point c) {
if (((a - b) * (c - b)) >= 0 && ((a - c) * (b - c)) >= 0 &&
((c - a) ^ (b - a)) == 0) {
return 1;
} else {
return 0;
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
v.resize(n);
long long ans = 0;
for (int i = 0; i < v.size(); ++i) {
cin >> v[i].first.x >> v[i].first.y >> v[i].second.x >> v[i].second.y;
long long c = gcd(abs(v[i].first.x - v[i].second.x),
abs(v[i].first.y - v[i].second.y)) +
1;
ans += c;
}
for (int i = 0; i < n; ++i) {
set<long long> st1;
for (int j = 0; j < n; ++j) {
if (i == j) {
continue;
}
point p = line(v[i].first, v[i].second) * line(v[j].first, v[j].second);
if (in(p, v[i].first, v[i].second) && in(p, v[j].first, v[j].second)) {
st.insert(p.x * INF + p.y);
st1.insert(p.x * INF + p.y);
}
}
ans -= st1.size();
}
cout << ans + st.size() << endl;
;
return 0;
}
| 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
int l[100], r[100], n, m;
map<int, int> id;
vector<int> sum;
map<int, long long> sl, sr;
int getans(long long a, long long b) {
int res = 0, cnt = 0;
while (a) {
res += (a & 1);
cnt++;
a >>= 1;
}
cnt = 0;
while (b) {
res += (b & 1);
cnt++;
b >>= 1;
}
return res;
}
int main() {
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i++) scanf("%d", &l[i]);
for (int i = 0; i < m; i++) scanf("%d", &r[i]);
int cnt = 0;
for (int i = 0; i < n; i++)
for (int j = 0; j < m; j++) {
if (!id.count(l[i] + r[j])) {
id[l[i] + r[j]] = cnt++;
sl[l[i] + r[j]] = sr[l[i] + r[j]] = 0;
sum.push_back(l[i] + r[j]);
}
sl[l[i] + r[j]] |= (1ll << i);
sr[l[i] + r[j]] |= (1ll << j);
}
int ans = -1;
if (sum.size() == 1) ans = n + m;
for (int i = 0; i < sum.size(); i++)
for (int j = i + 1; j < sum.size(); j++)
ans = max(ans, getans(sl[sum[i]] | sl[sum[j]], sr[sum[i]] | sr[sum[j]]));
printf("%d\n", ans);
}
| 9 | CPP |
#include <iostream>
using namespace std;
int main() {
int n,x;
cin>>n>>x;
if(x%2==0&&x>=2*n&&x<=4*n)
cout<<"Yes";
else
cout<<"No";
return 0;
}
| 0 | CPP |
if __name__ == "__main__":
n = int(input().strip())
ip = []
for i in range(n):
ip.append(tuple(map(int,input().strip().split())))
ip.sort()
i = 0
for l,f in ip:
if f >= i:
i = f
else :
i = l
print(i)
| 7 | PYTHON3 |
n,k=input().split(' ')
n=int(n)
k=int(k)
a=input().split(' ')
a=list(map(int,a))
s=[]
for id in a:
if id not in s:
s.insert(0,id)
if len(s)==k+1:
del s[k]
print(len(s))
for i in range(len(s)):
print('{} '.format(s[i]),end=' ') | 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int s, t, p;
string r1, r2;
int main() {
cin >> r2 >> r1;
s = 600 * (r1[0] - 48) + 60 * (r1[1] - 48) + 10 * (r1[3] - 48) + r1[4] - 48;
t = 600 * (r2[0] - 48) + 60 * (r2[1] - 48) + 10 * (r2[3] - 48) + r2[4] - 48;
p = t - s;
if (p < 0) p += 1440;
cout << p / 600;
p %= 600;
cout << p / 60;
p %= 60;
cout << ":";
cout << p / 10;
p %= 10;
cout << p;
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long t;
long long c[300005];
long long sol;
long long a[300005];
long long n, q;
void check(long long i) {
if (i == 0 || i == n + 1 || c[i]) return;
if (a[i - 1] < a[i] && a[i + 1] < a[i])
sol += a[i], c[i] = 1;
else if (a[i - 1] > a[i] && a[i + 1] > a[i])
sol -= a[i], c[i] = -1;
}
int32_t main() {
cin.tie(0);
ios_base::sync_with_stdio(0);
cin >> t;
while (t--) {
cin >> n >> q;
a[0] = -(1 << 30), a[n + 1] = -(1 << 30);
for (long long i = 1; i <= n; ++i) {
cin >> a[i];
c[i] = 0;
}
c[0] = c[n + 1] = 0;
sol = 0;
for (long long i = 1; i <= n; ++i) check(i);
cout << sol << "\n";
while (q--) {
long long i, j;
cin >> i >> j;
sol -= c[i - 1] * a[i - 1], c[i - 1] = 0, sol -= c[i] * a[i], c[i] = 0,
sol -= c[i + 1] * a[i + 1],
c[i + 1] = 0;
sol -= c[j - 1] * a[j - 1], c[j - 1] = 0, sol -= c[j] * a[j], c[j] = 0,
sol -= c[j + 1] * a[j + 1],
c[j + 1] = 0;
swap(a[i], a[j]);
check(i - 1), check(i), check(i + 1), check(j - 1), check(j),
check(j + 1);
cout << sol << "\n";
}
}
return 0;
}
| 9 | CPP |
"""
Satwik_Tiwari ;) .
5th AUGUST , 2020 - WEDNESDAY
"""
#===============================================================================================
#importing some useful libraries.
from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import *
from copy import *
from collections import deque
from collections import Counter as counter # Counter(list) return a dict with {key: count}
from itertools import combinations as comb # if a = [1,2,3] then print(list(comb(a,2))) -----> [(1, 2), (1, 3), (2, 3)]
from itertools import permutations as permutate
from bisect import bisect_left as bl
#If the element is already present in the list,
# the left most position where element has to be inserted is returned.
from bisect import bisect_right as br
from bisect import bisect
#If the element is already present in the list,
# the right most position where element has to be inserted is returned
#==============================================================================================
#fast I/O region
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
def print(*args, **kwargs):
"""Prints the values to a stream, or to sys.stdout by default."""
sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
at_start = True
for x in args:
if not at_start:
file.write(sep)
file.write(str(x))
at_start = False
file.write(kwargs.pop("end", "\n"))
if kwargs.pop("flush", False):
file.flush()
if sys.version_info[0] < 3:
sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
# inp = lambda: sys.stdin.readline().rstrip("\r\n")
#===============================================================================================
### START ITERATE RECURSION ###
from types import GeneratorType
def iterative(f, stack=[]):
def wrapped_func(*args, **kwargs):
if stack: return f(*args, **kwargs)
to = f(*args, **kwargs)
while True:
if type(to) is GeneratorType:
stack.append(to)
to = next(to)
continue
stack.pop()
if not stack: break
to = stack[-1].send(to)
return to
return wrapped_func
#### END ITERATE RECURSION ####
#===============================================================================================
#some shortcuts
mod = 1000000007
def inp(): return sys.stdin.readline().rstrip("\r\n") #for fast input
def out(var): sys.stdout.write(str(var)) #for fast output, always take string
def lis(): return list(map(int, inp().split()))
def stringlis(): return list(map(str, inp().split()))
def sep(): return map(int, inp().split())
def strsep(): return map(str, inp().split())
# def graph(vertex): return [[] for i in range(0,vertex+1)]
def zerolist(n): return [0]*n
def nextline(): out("\n") #as stdout.write always print sring.
def testcase(t):
for p in range(t):
solve()
def printlist(a) :
for p in range(0,len(a)):
out(str(a[p]) + ' ')
def lcm(a,b): return (a*b)//gcd(a,b)
def power(a,b):
ans = 1
while(b>0):
if(b%2==1):
ans*=a
a*=a
b//=2
return ans
def ncr(n,r): return factorial(n)//(factorial(r)*factorial(max(n-r,1)))
def isPrime(n) :
if (n <= 1) : return False
if (n <= 3) : return True
if (n % 2 == 0 or n % 3 == 0) : return False
i = 5
while(i * i <= n) :
if (n % i == 0 or n % (i + 2) == 0) :
return False
i = i + 6
return True
#===============================================================================================
# code here ;))
def solve():
n = int(inp())
a = lis()
b = lis()
a1 = min(a)
b1 = min(b)
cnt = 0
for i in range(n):
tempa = a[i]-a1
tempb = b[i]-b1
cnt+=max(tempa,tempb)
print(cnt)
# testcase(1)
testcase(int(inp()))
| 8 | PYTHON3 |
import sys
input = sys.stdin.buffer.readline
n,q=map(int,input().split())
a=list(map(int,input().split()))
queries=[[]for _ in[0]*n]
for i in range(q):
l,r=map(int,input().split())
l-=1
r-=1
queries[r].append((l,i))
lastAppeared=[0]*n
bit=[0]*(n+1)
ans=[0]*q
for i in range(n):
x=lastAppeared[a[i]-1]+1
while x<=n+1:
bit[x-1]-=1
x+=x&-x
x=i+2
while x<=n+1:
bit[x-1]+=1
x+=x&-x
lastAppeared[a[i]-1]=i+1
for l,ind in queries[i]:
x=i+2
while x:
ans[ind]+=bit[x-1]
x-=x&-x
x=l+1
while x:
ans[ind]-=bit[x-1]
x-=x&-x
print(*ans)
| 0 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
inline long long gcd(long long x, long long y) { return x ? gcd(y % x, x) : y; }
const long long mod = 1e9 + 7;
inline signed rd() {
signed ans = 0;
char last = ' ', ch = getchar();
while (!(ch >= '0' && ch <= '9')) last = ch, ch = getchar();
while (ch >= '0' && ch <= '9') ans = ans * 10 + ch - '0', ch = getchar();
if (last == '-') ans = -ans;
return ans;
}
inline long long QPow(long long a, long long b) {
long long ans = 1;
while (b) {
if (b & 1) ans = ans * a % mod;
a = a * a % mod;
b >>= 1;
}
return ans;
}
long long exgcd(long long a, long long b, long long &x, long long &y) {
long long d = a;
if (b == 0)
x = 1, y = 0;
else {
d = exgcd(b, a % b, y, x), y -= a / b * x;
}
return d;
}
const long double PI = 3.141592653589793115997963468544185161590576171875;
signed bits[50];
bool g[1010][1010];
long long pos[50];
signed main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
long long t;
long long n, m, A, cf, cm, pl, pr, vl, vr, k, x, y, px, py;
cin >> k;
signed top = 0;
m = k;
while (m) bits[top++] = m & 1, m >>= 1;
signed cur = 3;
pos[0] = 3;
g[1][cur++] = 1;
for (long long i = 0; i < top - 1; i++) {
g[cur - 1][cur] = g[cur - 1][cur + 1] = 1;
g[cur][cur + 2] = g[cur + 1][cur + 2] = 1;
cur += 3;
pos[i + 1] = cur - 1;
}
g[cur - 1][2] = 1;
for (long long i = top - 2; i >= 0; i--) {
if (bits[i] == 0) continue;
long long last = pos[i];
for (long long j = i; j < top - 1; j++) {
g[last][cur++] = 1;
g[cur - 1][cur++] = 1;
last = cur - 1;
}
g[cur - 1][2] = 1;
}
cout << --cur << endl;
for (long long i = 1; i <= cur; i++) {
for (long long j = 1; j <= cur; j++) {
if (i == j)
cout << 'N';
else
cout << (g[i][j] || g[j][i] ? 'Y' : 'N');
}
cout << '\n';
}
return 0;
}
| 10 | CPP |
#include <iostream>
using namespace std;
int main(){
while(true){
int n, m;
cin >> m >> n;
if(n == 0 && m == 0){ break; }
int iw[100];
cin >> iw[0];
for(int i = 1; i < n; i++){
cin >> iw[i];
iw[i] += iw[i - 1];
}
int left = 0, right = 1500000, answer = 0;
while(left < right){
int center = (left + right) / 2;
bool flag = false;
for(int i = 0, f = 0, p = 0; i < m; i++){
for(; f < n; f++){
if(iw[f] - p > center){ break; }
}
if(f == n){ flag = true; break; }
if(f == 0 || iw[f] == p){ break; }
p = iw[f - 1];
}
if(flag){
answer = center;
right = center;
}else{
left = center + 1;
}
}
cout << answer << endl;
}
return 0;
} | 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
const long long M = 1e9 + 7;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
;
int t;
cin >> t;
while (t--) {
string s, t;
cin >> s >> t;
int flag = 0;
for (int i = 0; i < s.size(); i++) {
for (int j = 0; j < s.size() - i; j++) {
if (i + j < t.size() - j - 1) continue;
string a = s.substr(i, j),
b = s.substr(i + 2 * j - t.size() + 1, t.size() - j);
reverse(b.begin(), b.end());
if (a + b == t) {
flag = 1;
break;
}
}
}
cout << (flag ? "YES\n" : "NO\n");
}
return 0;
}
| 8 | CPP |
n = int(input())
a = input();a = a.split(' ')
b = input();b = b.split(' ')
for i in range(n):
a[i] =int(a[i])
for i in range(n):
b[i] = int(b[i])
sum =0;
for i in range(n):
sum =sum + a[i]
b.sort();
b.reverse();
if(sum<=b[0]+b[1]):
print("YES")
else:
print("NO") | 7 | PYTHON3 |
# -*- coding: utf-8 -*-
"""
Created on Tue Oct 22 16:44:30 2019
@author: LV
"""
n, t = map(int, input().split())
p = [int(x) for x in input().split()]
c, acc = 0, []
while c < len(p):
c += p[c]
acc.append(c + 1)
print(['NO', 'YES'][t in acc]) | 7 | PYTHON3 |
#include <bits/stdc++.h>
#pragma GCC optimize("O2,Ofast,inline,unroll-all-loops,-ffast-math")
#pragma GCC target("avx,sse2,sse3,sse4,popcnt")
using namespace std;
template <class T>
inline void in(T &x) {
x = 0;
char c = getchar();
bool f = 0;
while (!isdigit(c)) f |= (c == '-'), c = getchar();
while (isdigit(c)) x = x * 10 + (c ^ '0'), c = getchar();
f ? x = -x : 0;
}
template <class T>
inline void out(T x, const char c = '\n') {
static short st[30];
short m = 0;
if (x < 0) putchar('-'), x = -x;
do st[++m] = x % 10, x /= 10;
while (x);
while (m) putchar(st[m--] | '0');
putchar(c);
}
template <class T>
inline void err(const T &x, const char c = '\n') {
cerr << x << c;
}
template <class T, class... Args>
inline void in(T &x, Args &...args) {
in(x);
in(args...);
}
template <class T, class... Args>
inline void out(const T &x, const Args &...args) {
out(x, ' ');
out(args...);
}
template <class T, class... Args>
inline void err(const T &x, const Args &...args) {
err(x, ' ');
err(args...);
}
template <class T>
inline void prt(T a[], int n) {
for (register int i = 0; i < n; ++i) out(a[i], i == n - 1 ? '\n' : ' ');
}
template <class T>
inline void clr(T a[], int n) {
memset(a, 0, sizeof(T) * n);
}
template <class T>
inline void clr(T *a, T *b) {
memset(a, 0, sizeof(T) * (b - a));
}
template <class T>
inline bool ckmax(T &a, const T &b) {
return a < b ? a = b, 1 : 0;
}
template <class T>
inline bool ckmin(T &a, const T &b) {
return a > b ? a = b, 1 : 0;
}
namespace MOD_CALC {
const int md = 1e9 + 7, inv2 = (md + 1) / 2;
inline int add(const int a, const int b) {
return a + b >= md ? a + b - md : a + b;
}
inline int sub(const int a, const int b) {
return a - b < 0 ? a - b + md : a - b;
}
inline int mul(const int a, const int b) { return (long long)a * b % md; }
inline void inc(int &a, const int b) { (a += b) >= md ? a -= md : 0; }
inline void dec(int &a, const int b) { (a -= b) < 0 ? a += md : 0; }
inline int qpow(int a, int b) {
int r = 1;
for (; b; b >>= 1, a = mul(a, a))
if (b & 1) r = mul(r, a);
return r;
}
inline int qpow(int a, int b, const int p) {
int r = 1;
for (; b; b >>= 1, a = (long long)a * a % p)
if (b & 1) r = (long long)r * a % p;
return r;
}
inline int mdinv(const int a) { return qpow(a, md - 2); }
template <class... Args>
inline int add(const int a, const int b, const Args &...args) {
return add(add(a, b), args...);
}
template <class... Args>
inline int mul(const int a, const int b, const Args &...args) {
return mul(mul(a, b), args...);
}
} // namespace MOD_CALC
using namespace MOD_CALC;
namespace i207M {
const int inf = 1e9;
int ch[2005][3];
bool del[2005];
int all, mnsz, pot;
int sz[2005];
void getrt(int x, int _fa) {
sz[x] = 1;
int t = 0;
for (register int i = 0; i < 3; ++i)
if (ch[x][i] && ch[x][i] != _fa && !del[ch[x][i]]) {
getrt(ch[x][i], x);
sz[x] += sz[ch[x][i]];
ckmax(t, sz[ch[x][i]]);
}
ckmax(t, all - sz[x]);
if (ckmin(mnsz, t)) pot = x;
}
int getsz(int x, int _fa) {
int t = 1;
for (register int i = 0; i < 3; ++i)
if (ch[x][i] && ch[x][i] != _fa && !del[ch[x][i]]) t += getsz(ch[x][i], x);
return t;
}
inline int query(int x, int y, int z) {
cout << x << ' ' << y << ' ' << z << endl;
string s;
cin >> s;
return s == "X" ? 1 : (s == "Y" ? 2 : 3);
}
int rt, tot;
inline void newnode(int x, int id) {
int y = ch[x][2];
if (!y) {
ch[x][2] = ch[id][2] = ++tot, ch[tot][0] = x, ch[tot][1] = id;
rt = tot;
} else {
ch[y][ch[y][1] == x] = ++tot, ch[tot][2] = y;
ch[x][2] = ch[id][2] = tot, ch[tot][0] = x, ch[tot][1] = id;
}
}
inline int getid(int x) {
while (ch[x][0]) x = ch[x][0];
return x;
}
void solve(int x, int id) {
all = getsz(x, 0);
if (del[x] || !ch[x][0]) return newnode(x, id);
mnsz = inf;
getrt(x, 0);
x = pot;
if (!ch[x][0]) x = ch[x][2];
del[x] = 1;
int t = query(getid(ch[x][0]), getid(ch[x][1]), id);
if (t == 1)
return (!ch[x][2] || del[ch[x][2]]) ? newnode(x, id) : solve(ch[x][2], id);
if (t == 2) return solve(ch[x][1], id);
return solve(ch[x][0], id);
}
int n;
signed main() {
cin >> n;
tot = n;
ch[1][2] = ch[2][2] = ++tot, ch[tot][0] = 1, ch[tot][1] = 2;
rt = tot;
for (register int i = 3; i <= n; ++i) {
memset(del, 0, sizeof(del));
solve(rt, i);
}
cout << -1 << endl;
for (register int i = 1; i <= tot; ++i)
cout << (ch[i][2] ? ch[i][2] : -1) << ' ';
cout << endl;
return 0;
}
} // namespace i207M
signed main() {
i207M::main();
return 0;
}
| 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
bool if_prime(int a) {
for (int i = 2; i * i <= a; i++) {
if (a % i == 0) return false;
}
return true;
}
int main() {
int N;
cin >> N;
for (int i = 4; i <= N; i++) {
if (!if_prime(i) && !if_prime(N - i)) {
cout << i << " " << N - i << endl;
return 0;
}
}
}
| 7 | CPP |
#include <bits/stdc++.h>
int main() {
int n, ans = 0, a, b = 1;
scanf("%d", &n);
while (n) {
a = n % 10;
ans += (b * ((a == 4) ? 1 : 2));
n /= 10;
b *= 2;
}
printf("%d\n", ans);
return 0;
}
| 8 | CPP |
for _ in range(int(input())):
a, b, c = map(int, input().split())
if a <= c/b:
op1 = 1
else:
if a < c:
op1 = 1
else:
op1 = -1
if a*b > c:
op2 = b
else:
op2 = -1
print(op1,op2) | 7 | PYTHON3 |
#include <cstdio>
#include <algorithm>
using namespace std;
int main(){
int a, b, c, d, h1, h2, k1, k2, ph, pk;
scanf("%d %d", &h1, &h2);
scanf("%d %d", &k1, &k2);
scanf("%d %d %d %d", &a, &b, &c, &d);
ph = (h1/10) * c + h1 * a + (h2/20) * d + h2 * b;
pk = (k1/10) * c + k1 * a + (k2/20) * d + k2 * b;
if (ph == pk) printf("even\n");
else if (ph > pk) printf("hiroshi\n");
else printf("kenjiro\n");
return 0;
}
| 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
void fast() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
long long int maximum(long long int a, long long int b) {
if (a > b)
return a;
else
return b;
}
long long int power(long long int a, long long int n) {
long long int result = 1;
while (n > 0) {
if (n & 1) {
result = result * a;
}
a = a * a;
n = n >> 1;
}
return result;
}
long long int a[1000009], b[1000009];
long long int n;
int check(int m) {
int cur = 0;
int l = m;
int r = n - 1;
while (l < r) {
if (min(a[l], a[r]) < cur) {
return 0;
}
if (a[l] < a[r]) {
cur = a[l];
l++;
} else {
cur = a[r];
r--;
}
}
return 1;
}
int main() {
fast();
long long int t;
cin >> t;
while (t--) {
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i];
int low = 0, high = n - 1;
while (low < high) {
int mid = (low + high) / 2;
if (check(mid)) {
high = mid;
} else
low = mid + 1;
}
cout << low << endl;
}
}
| 9 | CPP |
#include <bits/stdc++.h>
int main() {
static char s[128];
static long long dp[128][128];
int n, h, i, j, l;
long long min;
scanf("%d", &n);
scanf("%s", s);
l = strlen(s);
for (i = 0; i <= l; i++)
for (j = 0; j <= l; j++) dp[i][j] = ((long long)1e18);
dp[0][0] = 0;
for (i = 0; i < l; i++)
for (j = 0; j < l; j++)
if (dp[i][j] < ((long long)1e18)) {
long long x = dp[i][j];
if (s[i] == '0') {
if ((double)x * n <= ((long long)1e18))
if (dp[i + 1][j + 1] > x * n) dp[i + 1][j + 1] = x * n;
} else {
long long y = 0;
for (h = i; h < l; h++) {
y = y * 10 + (s[h] - '0');
if (y >= n) break;
if ((double)x * n + y <= ((long long)1e18))
if (dp[h + 1][j + 1] > x * n + y) dp[h + 1][j + 1] = x * n + y;
}
}
}
min = ((long long)1e18);
for (j = 0; j <= l; j++)
if (min > dp[l][j]) min = dp[l][j];
printf("%lld\n", min);
return 0;
}
| 10 | CPP |
t=int(input())
for _ in range(t):
n,k=map(int,input().split())
ans=0
a=max(n,k)
b=min(n,k)
if(a>=2*b):
ans=b
else:
ans=a-b+((2*b-a)*2)//3
print(ans)
| 7 | PYTHON3 |
def change_char(s, p, r):
return s[:p]+r+s[p+1:]
n=int(input())
while n!=0:
flag=0
inp_string=input()
len1=len(inp_string)
ans=0
q_count=inp_string.count('?')
final_string1=''
final_string=inp_string
if len1==1:
final_string=change_char(final_string,0,'a')
else:
for i in range(0,len1-1):
if final_string[i]=='?':
if final_string[i+1]=='a':
if i==0:
final_string=change_char(final_string,i,'b')
else:
if final_string[i-1]=='a':
final_string=change_char(final_string,i,'b')
elif final_string[i-1]=='c':
final_string=change_char(final_string,i,'b')
elif final_string[i-1]=='b':
final_string=change_char(final_string,i,'c')
elif final_string[i+1]=='b':
if i==0:
final_string=change_char(final_string,i,'c')
else:
if final_string[i-1]=='a':
final_string=change_char(final_string,i,'c')
elif final_string[i-1]=='c':
final_string=change_char(final_string,i,'a')
elif final_string[i-1]=='b':
final_string=change_char(final_string,i,'c')
elif final_string[i+1]=='c':
if i==0:
final_string=change_char(final_string,i,'b')
else:
if final_string[i-1]=='a':
final_string=change_char(final_string,i,'b')
elif final_string[i-1]=='c':
final_string=change_char(final_string,i,'b')
elif final_string[i-1]=='b':
final_string=change_char(final_string,i,'a')
elif final_string[i+1]=='?':
if i==0:
final_string=change_char(final_string,i,'a')
else:
if final_string[i-1]=='a':
final_string=change_char(final_string,i,'b')
elif final_string[i-1]=='c':
final_string=change_char(final_string,i,'b')
elif final_string[i-1]=='b':
final_string=change_char(final_string,i,'a')
else:
if (final_string[i+1]==final_string[i]):
ans=-1
flag=1
break
if final_string[len1-1]=='?':
if final_string[len1-2]=='a':
final_string=change_char(final_string,len1-1,'b')
elif final_string[len1-2]=='c':
final_string=change_char(final_string,len1-1,'b')
elif final_string[len1-2]=='b':
final_string=change_char(final_string,len1-1,'a')
if flag==1:
print(ans)
else:
print(final_string)
n-=1
| 7 | PYTHON3 |
n, t = map(int, input().split())
st = '';
if (n == 1 and t == 10):
print(-1)
else:
for i in range (n - 1):
st += '1';
st += '0';
k = int(st);
for i in range(k, k + 10):
if i % t == 0:
ans = i
print(ans);
| 7 | PYTHON3 |
for _ in range(int(input())):
n,k=map(int,input().split())
l1=list(map(int,input().split()))
l2=list(map(int,input().split()))
for i,x in enumerate(l1):
if x in l2:
print('YES')
print(1,x)
break
else:
print('NO')
| 7 | PYTHON3 |
//#line 2 "SubstringQueries.cpp"
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <random>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
#include <cstdint>
using namespace std;
using LL = long long;
int N;
int main() {
cin >> N;
if (N == 1) {
cout << 1 << endl << 0 << endl;
return 0;
}
if (N == 2) {
cout << 2 << endl << 0 << endl << 11 << endl;
return 0;
}
cout << N - 1 << endl;
for (int i = 2; i <= N; ++i) {
for (int j = 0; j < i; ++j) {
if (j == 0 || j == i - 1) {
cout << 0;
}
else {
cout << 1;
}
}
cout << endl;
}
return 0;
}
| 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200010;
int n, a[maxn];
unordered_map<int, int> mp;
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i]; mp[a[i]]++;
}
sort(a + 1, a + n + 1);
int ans = 0;
for (int i = n; i; i--) if (mp[a[i]]) {
mp[a[i]]--;
for (long long j = 1; j <= 2e9; j *= 2) {
if (j > a[i] && mp[j - a[i]]) {
mp[j - a[i]]--, ans++; break;
}
}
}
cout << ans << endl;
return 0;
} | 0 | CPP |
n,t=map(int,input().split())
s=input()
for i in range(t):
a=list(s)
for i in range(n-1):
if s[i:i+2]=='BG':
a[i:i+2]=['G','B']
s=''.join(a)
print(s) | 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int64_t arr[10][10];
int64_t temp = 1;
for (int j = 0; j < 10; j++) {
for (int i = 0; i < 9; i++) {
if (j == 0) {
arr[j][i] = i + 1;
} else {
arr[j][i] = temp * (i + 1) + arr[j - 1][i];
}
}
temp = temp * 10;
}
int t;
cin >> t;
int64_t n;
while (t--) {
bool flag = 0;
cin >> n;
int count = 0;
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 9; j++) {
if (arr[i][j] <= n) {
count++;
} else {
cout << count << "\n";
flag = 1;
}
if (flag) {
break;
}
}
if (flag) {
break;
}
}
}
}
| 7 | CPP |
x,p=map(int,input().split())
for _ in range(p):
if(x%10==0):
x=x//10
else:
x=x-1
print(x)
#d | 7 | PYTHON3 |
t=int(input())
for r in range(t):
n=int(input())
if n==1:
print(-1)
else:
s="9"*(n-1)
s=s+"8"
print(s) | 7 | PYTHON3 |
#include <algorithm>
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#include <queue>
#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }
#include <set>
using namespace std;
int main(){
const int n = getInt();
const int k = getInt();
const int t = 'z' - 'a' + 1;
vector<int> v(t);
REP(i,n) {
char buff[16];
scanf("%s", buff);
v[buff[0] - 'A']++;
}
int ans = 0;
while (true) {
sort(v.rbegin(), v.rend());
if(v[k - 1] == 0) break;
ans++;
REP(i,k) v[i]--;
}
printf("%d\n", ans);
return 0;
}
| 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n;
long long p;
map<int, int> fact;
map<int, int>::iterator it;
vector<long long> ans;
void search() {
it++;
if (it == fact.end()) {
ans.push_back((n - n / p + 2) * p / 2);
it--;
return;
}
search();
for (int i = 1; i <= it->second; ++i) {
p *= it->first;
search();
}
for (int i = 1; i <= it->second; ++i) p /= it->first;
it--;
}
bool myfunction(int i, int j) { return (i < j); }
int main() {
ans.clear();
cin >> n;
int t = n;
fact.clear();
for (int i = 2; i <= sqrt((float)t); ++i) {
while (t % i == 0) {
fact[i]++;
t /= i;
}
}
fact[t]++;
fact[1] = 1;
p = 1;
int siz = fact.size();
it = fact.begin();
search();
sort(ans.begin(), ans.end());
for (vector<long long>::iterator it = ans.begin(); it != ans.end(); ++it)
cout << *it << ' ';
}
| 9 | CPP |
def merge_sort(x):
if len(x) == 1:
return x
left = []
right = []
for i in range(0, len(x)):
if i < len(x)/2:
left.append(x[i])
else:
right.append(x[i])
left = merge_sort(left)
right = merge_sort(right)
return merge(left, right)
def merge(left, right):
sol = []
while len(left) > 0 and len(right) > 0:
if left[0] <= right[0]:
sol.append(left[0])
left = left[1:]
else:
sol.append(right[0])
right = right[1:]
while len(left) > 0:
sol.append(left[0])
left = left[1:]
while len(right) > 0:
sol.append(right[0])
right = right[1:]
return sol
n = int(input())
sol = ''
string = list(map(int, input().strip().split()))
sort = merge_sort(string)
for i in range(0,len(sort)):
sol = sol + '{} '.format(sort[i])
print(sol) | 7 | PYTHON3 |
#include <iostream>
#include <string>
using namespace std;int main(){string s;cin>>s;for(int i=0;i<12;i++){cout<<s.at(i);if(i==3)cout<<" ";}cout<<endl;return 0;}
| 0 | CPP |
n = int(input())
r = list(range(1, n + 1))
x = list(map(int, input().split()))
y = list(map(int, input().split()))
c = []
for i in range(1, len(x)):
c.append(x[i])
for i in range(1, len(y)):
c.append(y[i])
c = list(set(c))
if c == r:
print("I become the guy.")
else:
print("Oh, my keyboard!") | 7 | PYTHON3 |
s = input()
print(s.swapcase() if s == s.upper() or len(s) == 1 and s.islower() or s[0].islower and s[1:].isupper() else s) | 7 | PYTHON3 |
N,M,K=map(int,input().split())
par=[-1]*N
num=[0]*N
def find(x):
if par[x-1]<0:
return x
else:
par[x-1]=find(par[x-1])
return par[x-1]
def union(x,y):
p,q=find(x),find(y)
if p==q:
return
if p>q:
p,q=q,p
par[p-1]+=par[q-1]
par[q-1]=p
def size(x):
return -par[find(x)-1]
def same(x,y):
return find(x)==find(y)
for _ in range(M):
a,b=map(int,input().split())
union(a,b)
num[a-1]+=1
num[b-1]+=1
for _ in range(K):
c,d=map(int,input().split())
if same(c,d):
num[c-1]+=1
num[d-1]+=1
for i in range(N):
print(size(i+1)-1-num[i],end=" ") | 0 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int mmmm = 1111;
int n;
char s[mmmm];
int a[mmmm], f[mmmm];
void qwe() {
a[0] = 1989;
f[0] = 1;
for (int i = 1; i <= 9; i++) {
f[i] = f[i - 1] * 10;
a[i] = a[i - 1] + f[i];
}
}
int main() {
qwe();
while (scanf("%d", &n) != EOF) {
for (int i = 1; i <= n; i++) {
scanf("%s", s);
int l = strlen(s) - 4;
int c = 0;
for (int i = 4; i < l + 4; i++) {
c = c * 10 + s[i] - '0';
}
int asd = a[l - 1];
int zxc = a[l];
int t1 = asd / f[l] * f[l] + c;
int t2 = zxc / f[l] * f[l] + c;
if (t1 >= asd && t1 < zxc) {
printf("%d\n", t1);
} else {
printf("%d\n", t2);
}
}
}
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
long long aa[300000];
int arr[2000][2];
int l = 0;
int mark[100000];
int main() {
queue<int> black, white;
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; i++) cin >> a[i];
long long ans = 0;
set<int> w;
for (int i = n - 1; i >= 0; i--) {
aa[i] = w.size();
w.insert(a[i]);
}
for (int i = 0; i < n; i++) {
if (!mark[a[i]]) {
ans += aa[i];
mark[a[i]] = 1;
}
}
cout << ans;
}
| 9 | CPP |
print("Yes" if sorted(input()) == list("abc") else "No") | 0 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
string s, t;
int n, m, l[200009], r[200009], a[30][200009];
bool ans = true;
int main() {
cin >> s >> t;
n = s.length();
m = t.length();
s = ' ' + s + ' ';
t = ' ' + t + ' ';
l[0] = 0;
for (int i = 1; i <= n; ++i) l[i] = l[i - 1] + int(t[l[i - 1] + 1] == s[i]);
r[n + 1] = m + 1;
for (int i = n; i >= 1; --i) r[i] = r[i + 1] - int(t[r[i + 1] - 1] == s[i]);
for (int i = 0; i < 26; ++i)
for (int j = 1; j <= m + 1; ++j)
a[i][j] = a[i][j - 1] + int(t[j] - 'a' == i);
for (int i = 1; i <= n; ++i)
if (a[s[i] - 'a'][l[i - 1] + 1] -
a[s[i] - 'a'][r[i + 1] - 2 < 0 ? 0 : r[i + 1] - 2] <=
0) {
ans = false;
break;
}
if (ans)
cout << "Yes";
else
cout << "No";
cout << endl;
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3f;
const int MOD = (int)1e9 + 7;
const int N = (int)1e6 + 7;
int n, k;
int a[N], bit[N];
map<int, int> cnt[11];
long long dp[N][11];
void Init() {
for (int i = (1); i < (11); ++i) cnt[i].clear();
for (int i = (0); i < (n); ++i) scanf("%d", a + i);
for (int i = (0); i < (n); ++i) {
int x = a[i];
bit[i] = 0;
while (x) {
bit[i]++;
x /= 10;
}
}
}
int Solve() {
for (int i = (0); i < (n); ++i) {
cnt[bit[i]][a[i] % k]++;
dp[i][0] = a[i] % k;
for (int j = (1); j < (11); ++j) dp[i][j] = dp[i][j - 1] * 10 % k;
}
long long ans = 0;
for (int i = (0); i < (n); ++i) {
for (int j = (1); j < (11); ++j) {
if (bit[i] == j && (dp[i][j] + a[i]) % k == 0) --ans;
int t = k - dp[i][j] != k ? k - dp[i][j] : 0;
if (cnt[j].count(t)) ans += cnt[j][t];
}
}
return !printf("%lld\n", ans);
}
int main() {
while (~scanf("%d%d", &n, &k)) {
Init();
Solve();
}
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long a, b, c, d, e, f, l;
cin >> a >> b >> c >> d >> e >> f;
l = a + b + c;
cout << l * l - a * a - c * c - e * e;
}
| 7 | CPP |
n=int(input())
a=[5]+list(map(int,input().split()))
dp=[[[i,0] for i in range(n+1)] for j in range(4)]
end=n
indx_a,indx_b,indx_c=0,0,0
for i in range(1,n+1):
dp[0][i][1]=dp[0][i-1][1]+a[i]
dp[1][i][1]=max(dp[0][i-1][1],dp[1][i-1][1])-a[i]
dp[2][i][1]=max(dp[1][i-1][1],dp[2][i-1][1])+a[i]
dp[3][i][1]=max(dp[2][i-1][1],dp[3][i-1][1])-a[i]
dp_indx=[0,0,0,0]
indx=0
pt=3
for i in range(n,0,-1):
if dp[pt][i][1] < dp[pt-1][i][1] :
pt-=1
dp_indx[pt]=i
if pt==0:
break
print(dp_indx[0],dp_indx[1],dp_indx[2]) | 9 | PYTHON3 |
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld =long double;
const ld eps = 1e-9;
struct edge {
int from;
int to;
int c1;
int c2;
};
int main()
{
int N,M;cin>>N>>M;
vector<vector<edge>>graph(N);
vector<int>comes(N);
for (int i = 0; i < M; ++i) {
int a,b,t1,t2;cin>>a>>b>>t1>>t2;
a--;b--;
graph[a].push_back(edge{ a,b,t1,t2 });
comes[b]++;
}
vector<int>v;
vector<int>nums(N);
{
queue<int>que;
for (int i = 0; i < N; ++i) {
if (!comes[i])que.push(i);
}
while (!que.empty()) {
int now(que.front());
que.pop();
v.push_back(now);
for (auto e : graph[now]) {
comes[e.to]--;
if (!comes[e.to]) {
que.push(e.to);
}
}
}
for (int i = 0; i < N; ++i) {
nums[v[i]]=i;
}
}
vector<vector<vector<int>>>memo(N,vector<vector<int>>(N,vector<int>(2,1e9)));
memo[0][0][0]=0;
for (int i = 0; i < N; ++i) {
for (int j = 0; j <= i; ++j) {
for (int k = 0; k < 2; ++k) {
int now_u = v[j];
int now_d = v[i];
for (auto e : graph[now_u]) {
if (k&&e.to == now_d)continue;
else {
int next_u = e.to;
int next_d = now_d;
if (nums[next_u]>nums[next_d])swap(next_u, next_d);
int next_i = nums[next_d];
int next_j = nums[next_u];
memo[next_i][next_j][i==j] = min(memo[next_i][next_j][i==j], memo[i][j][k] + e.c1);
}
}
if (now_u == now_d) {
for (auto e : graph[now_u]) {
int next_u = e.to;
int next_d = e.to;
int next_i = nums[next_d];
int next_j = nums[next_u];
memo[next_i][next_j][0] = min(memo[next_i][next_j][0], memo[i][j][k] + e.c1 + e.c2);
}
}
}
}
}
int ans=memo[N-1][N-1][0];
ans=min(ans,memo[N-1][N-1][1]);
cout<<ans<<endl;
return 0;
}
| 0 | CPP |
from math import ceil, log, floor, sqrt
import math
def mod_expo(n, p, m):
"""find (n^p)%m"""
result = 1
while p != 0:
if p%2 == 1:
result = (result * n)%m
p //= 2
n = (n * n)%m
return result
def get_string(n):
s = "codeforces"
l = []
res = ""
flag = True
if n == 1:
return s
for i in range(10):
l.append(1)
m = 1
while flag:
for i in range(10):
m = (m*(l[i]+1))//l[i]
l[i] += 1
if m >= n:
flag = False
break
for i in range(10):
for j in range(l[i]):
res += s[i]
return res
def nc2(n):
return n*(n+1)/2
def get_grain_count(n, l, m):
print(l, n - nc2(l) - (m+l+1))
return n - nc2(l) - (m+l+1)
def count_days(n, m):
if n == 1:
return 1
value = 2*(n-m-1)
l = ceil((-3 + sqrt(9 + 4*value))/2)
while get_grain_count(n, l, m) > 0:
l += 1
return m + l + 1
def get_count(k, r):
for i in range(1, 10):
if (k*i - r) % 10 == 0 or k*i % 10 == 0:
return i
return 10
t = 1
#t = int(input())
while t:
t = t - 1
#k = int(input())
#a, b, n = map(int, input().split())
k, r = map(int, input().split())
#l = list(map(int, input().strip().split()))[:n]
#str1 = input()
#if no_vacancy(n, l):
# print("Yes")
#else:
# print("No")
print(get_count(k, r))
#print(count_moves(a, b, n))
| 7 | PYTHON3 |
q=lambda:map(int,input().split())
qi=lambda:int(input())
qs=lambda:input().split()
n=qi()
m=qi()
a=[]
for _ in range(n):
a.append(qi())
k=1
while sum(sorted(a)[::-1][:k])<m:k+=1
print(k) | 7 | PYTHON3 |
Subsets and Splits