solution
stringlengths 10
983k
| difficulty
int64 0
25
| language
stringclasses 2
values |
---|---|---|
a = input().strip()
b = input().strip()
print(6-int(a)-int(b))
| 0 | PYTHON3 |
#include <bits/stdc++.h>
char ans[200][200];
int main() {
int a, b, c, d, n, s[30];
scanf("%d%d%d%d%d", &a, &b, &c, &d, &n);
for (int i = 1; i <= n; i++) scanf("%d", &s[i]);
printf("YES\n");
if (b > d) {
int l = 1, r = 1, dir = 1;
if (d % 2 == 1) {
r = a + c;
dir = -1;
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= s[i]; j++) {
ans[l][r] = 'a' + i - 1;
if (l <= d) {
if (r == 1 && dir == -1) {
l++;
dir = 1;
} else if (r == a + c && dir == 1) {
l++;
dir = -1;
} else {
r += dir;
}
} else {
if (r == 1 && dir == -1) {
l++;
dir = 1;
} else if (r == a && dir == 1) {
l++;
dir = -1;
} else {
r += dir;
}
}
}
}
for (int i = 1; i <= b; i++) {
for (int j = 1; j <= a + c; j++)
if (ans[i][j] >= 'a' && ans[i][j] <= 'z')
printf("%c", ans[i][j]);
else
printf(".");
printf("\n");
}
} else {
int l = 1, r = a + c, dir = -1;
if (b % 2 == 1) {
r = 1;
dir = 1;
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= s[i]; j++) {
ans[l][r] = 'a' + i - 1;
if (l <= b) {
if (r == 1 && dir == -1) {
l++;
dir = 1;
} else if (r == a + c && dir == 1) {
l++;
dir = -1;
} else {
r += dir;
}
} else {
if (r == a + 1 && dir == -1) {
l++;
dir = 1;
} else if (r == a + c && dir == 1) {
l++;
dir = -1;
} else {
r += dir;
}
}
}
}
for (int i = 1; i <= d; i++) {
for (int j = 1; j <= a + c; j++)
if (ans[i][j] >= 'a' && ans[i][j] <= 'z')
printf("%c", ans[i][j]);
else
printf(".");
printf("\n");
}
}
}
| 10 | CPP |
/*
[dwacon5th-prelims] D - Square Rotation
*/
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
const int MAX_N = 1e5;
const int MAX_D = 1000;
int N, D;
int x[MAX_N], y[MAX_N];
int c[MAX_D][MAX_D];
int s[3][MAX_D * 2 + 1][MAX_D * 2 + 1];
bool can(int q) {
for (int a = 0; a < D; a++) {
for (int b = 0; b < D; b++) {
bool is_ok = true;
is_ok = is_ok && (s[2][a + q + 1][b + q + 1] - s[2][a + q + 1][b] -
s[2][a][b + q + 1] + s[2][a][b] ==
0);
is_ok =
is_ok && (s[1][a + q + 1][b + D] - s[1][a + q + 1][b + q + 1] -
s[1][a][b + D] + s[1][a][b + q + 1] ==
0);
is_ok =
is_ok && (s[1][a + D][b + q + 1] - s[1][a + D][b] -
s[1][a + q + 1][b + q + 1] + s[1][a + q + 1][b] ==
0);
is_ok = is_ok &&
(s[0][a + D][b + D] - s[0][a + D][b + q + 1] -
s[0][a + q + 1][b + D] + s[0][a + q + 1][b + q + 1] ==
0);
if (is_ok) {
return true;
}
}
}
return false;
}
ll solve() {
int p = 0;
for (int i = 0; i < N; i++) {
c[x[i] % D][y[i] % D]++;
}
for (int i = 0; i < D; i++) {
for (int j = 0; j < D; j++) {
while ((p + 1) * (p + 1) < c[i][j]) {
p++;
}
}
}
int thresh[3] = {p * p, p * (p + 1), (p + 1) * (p + 1)};
for (int k = 0; k < 3; k++) {
for (int i = 0; i < D; i++) {
for (int j = 0; j < D; j++) {
if (c[i][j] > thresh[k]) {
s[k][1 + i][1 + j]++;
s[k][1 + i + D][1 + j]++;
s[k][1 + i][1 + j + D]++;
s[k][1 + i + D][1 + j + D]++;
}
}
}
}
for (int k = 0; k < 3; k++) {
for (int i = 1; i <= 2 * D; i++) {
for (int j = 0; j <= 2 * D; j++) {
s[k][i + 1][j] += s[k][i][j];
}
}
for (int i = 0; i <= 2 * D; i++) {
for (int j = 1; j <= 2 * D; j++) {
s[k][i][j + 1] += s[k][i][j];
}
}
}
int ng = -1, ok = D - 1;
while (ok - ng > 1) {
int m = (ok + ng) / 2;
if (can(m)) {
ok = m;
} else {
ng = m;
}
}
ll ans = p * D + ok;
return ans;
}
int main() {
cin >> N >> D;
for (int i = 0; i < N; i++) {
cin >> x[i] >> y[i];
}
cout << solve() << endl;
return 0;
}
| 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
void task() {
long long t, s;
cin >> t;
while (t--) {
cin >> s;
long long ans = 0, mid;
while (1) {
if (s < 10) {
ans += s;
break;
}
ans += (s - s % 10);
s = s / 10 + s % 10;
}
cout << ans << "\n";
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
task();
return 0;
}
| 8 | CPP |
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
#######################################
t=int(input())
for i in range(t):
n,m=map(int,input().split())
l1=list(map(int,input().split()))
l2=list(map(int,input().split()))
ans="NO"
a=0
for j in l1:
if j in l2:
a=j
ans="YES"
break
print(ans)
if ans=="YES":
print(1,a)
| 7 | PYTHON3 |
def main():
t = int(input())
for k in range(t):
line = input().split()
n, s = int(line[0]), int(line[1])
nums = list(map(int, input().split()))
max_pos = -1
total = 0
i = 0
while i < n:
total += nums[i]
if total > s:
if max_pos == -1:
print(1)
else:
if nums[i] > nums[max_pos]:
print(i + 1)
else:
print(max_pos + 1)
break
if max_pos == -1 or nums[i] > nums[max_pos]:
max_pos = i
i += 1
if total <= s and i == n:
print(0)
if __name__ == "__main__":
main()
| 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
long long fpow(long long a, long long b) {
long long ret = 1;
while (b) {
if (b & 1) ret = ret * a % mod;
a = a * a % mod;
b >>= 1;
}
return ret;
}
long long n, q, a[200005], qzh[200005], qzh2[200005];
long long bas, iv2, iv6;
int main() {
iv2 = fpow(2, mod - 2), iv6 = fpow(6, mod - 2);
scanf("%lld%lld", &n, &q);
for (int i = 1; i <= n; i++) {
scanf("%lld", &a[i]);
qzh[i] = (qzh[i - 1] + fpow(a[i], 2)) % mod;
qzh2[i] = (qzh2[i - 1] + a[i]) % mod;
}
for (int i = 1, l, r; i <= q; i++) {
long long d, st, m, sum;
scanf("%d%d%lld", &l, &r, &d);
m = r - l + 1;
st = ((qzh2[r] - qzh2[l - 1] + mod) % mod -
(m - 1) * m % mod * d % mod * iv2 % mod + mod) *
fpow(m, mod - 2) % mod;
sum =
(st * st % mod * m % mod +
d * d % mod * (m - 1) % mod * m % mod * (2 * m - 1) % mod * iv6 % mod +
st * d % mod * m % mod * (m - 1) % mod) %
mod;
if (sum == (qzh[r] - qzh[l - 1] + mod) % mod)
printf("Yes\n");
else
printf("No\n");
}
}
| 12 | CPP |
#include <bits/stdc++.h>
long long ans, n;
int main() {
scanf("%d", &n);
char c[110];
scanf("%s", c);
for (int i = 0; i < n; i++)
if (c[i] == 'B') ans += 1ll << i;
printf("%lld", ans);
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
int x = min(n, m);
if (x % 2 != 0)
cout << "Akshat\n";
else
cout << "Malvika\n";
}
| 7 | CPP |
#include <bits/stdc++.h>
#pragma comment(linker, "/stack:640000000")
using namespace std;
const double EPS = 1e-9;
const int INF = 0x7f7f7f7f;
const double PI = acos(-1.0);
template <class T>
inline T _abs(T n) {
return ((n) < 0 ? -(n) : (n));
}
template <class T>
inline T _max(T a, T b) {
return (!((a) < (b)) ? (a) : (b));
}
template <class T>
inline T _min(T a, T b) {
return (((a) < (b)) ? (a) : (b));
}
template <class T>
inline T _swap(T &a, T &b) {
a = a ^ b;
b = a ^ b;
a = a ^ b;
}
template <class T>
inline T gcd(T a, T b) {
return (b) == 0 ? (a) : gcd((b), ((a) % (b)));
}
template <class T>
inline T lcm(T a, T b) {
return ((a) / gcd((a), (b)) * (b));
}
struct debugger {
template <typename T>
debugger &operator,(const T &v) {
cerr << v << " ";
return *this;
}
} dbg;
template <typename F, typename S>
ostream &operator<<(ostream &os, const pair<F, S> &p) {
return os << "(" << p.first << ", " << p.second << ")";
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
os << "{";
typename vector<T>::const_iterator it;
for (it = v.begin(); it != v.end(); it++) {
if (it != v.begin()) os << ", ";
os << *it;
}
return os << "}";
}
template <typename T>
ostream &operator<<(ostream &os, const set<T> &v) {
os << "[";
typename set<T>::const_iterator it;
for (it = v.begin(); it != v.end(); it++) {
if (it != v.begin()) os << ", ";
os << *it;
}
return os << "]";
}
template <typename F, typename S>
ostream &operator<<(ostream &os, const map<F, S> &v) {
os << "[";
typename map<F, S>::const_iterator it;
for (it = v.begin(); it != v.end(); it++) {
if (it != v.begin()) os << ", ";
os << it->first << " = " << it->second;
}
return os << "]";
}
int Set(int N, int pos) { return N = N | (1 << pos); }
int reset(int N, int pos) { return N = N & ~(1 << pos); }
bool check(int N, int pos) { return (bool)(N & (1 << pos)); }
const int MX = 500004;
int a[MX], b[MX], mark[MX];
int call(int f, int l) {
int z = 0, o = 0;
for (int i = f; i <= l; i++) {
if (mark[i] == 1) {
if (a[i] == 0)
z++;
else
o++;
}
}
int res = max(z, o);
int x = f, y = l;
f = a[f], l = a[l];
if (f == 0 && l == 0) {
for (int i = x; i <= y; i++) {
if (mark[i]) a[i] = 0;
}
} else if (f == 1 && l == 1) {
for (int i = x; i <= y; i++) {
if (mark[i]) a[i] = 1;
}
} else if (f == 0 && l == 1) {
for (int i = x; i <= y; i++) {
if (mark[i]) {
if (z > 0) {
a[i] = 0;
z--;
} else {
a[i] = 1;
o--;
}
}
}
} else if (f == 1 && l == 0) {
for (int i = x; i <= y; i++) {
if (mark[i]) {
if (o > 0) {
a[i] = 1;
o--;
} else {
a[i] = 0;
z--;
}
}
}
}
return res;
}
int main() {
int n;
while (~scanf("%d", &n)) {
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
memset(mark, 0, sizeof(mark));
int z = 0, o = 0;
for (int i = 1; i < n - 1; i++) {
if (a[i - 1] != a[i] && a[i] != a[i + 1]) {
mark[i] = 1;
if (a[i] == 0)
z++;
else
o++;
}
}
int f = -1, l = -1;
int res = -INF;
for (int i = 0; i < n; i++) {
if (f == -1 && mark[i] == 0 && mark[i + 1] == 1) {
f = i;
} else if (l == -1 && mark[i] == 0 && mark[i - 1] == 1) {
l = i;
}
if (f != -1 && l != -1) {
res = max(res, call(f, l));
f = -1, l = -1;
}
}
if (res == -INF) res = 0;
printf("%d\n", res);
for (int i = 0; i < n; i++) {
if (i) printf(" ");
printf("%d", a[i]);
}
printf("\n");
}
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, k, t;
cin >> n >> k;
t = n;
multiset<long long> a;
multiset<long long>::iterator it, tempi;
for (long long i = 30; i >= 0; i--) {
if (n >= (1 << i)) {
a.insert(1 << i);
n %= (1 << i);
}
}
if (k > t || k < a.size())
cout << "NO";
else {
it = a.begin();
cout << "YES \n";
k -= a.size();
while (k) {
if (*it != 1) {
k--;
if (it != a.begin()) {
it--;
tempi = it;
tempi++;
a.insert(*(tempi) / 2);
a.insert(*(tempi) / 2);
a.erase(tempi);
} else {
tempi = it;
a.insert(*(tempi) / 2);
a.insert(*(tempi) / 2);
a.erase(tempi);
it = a.begin();
}
} else
it++;
}
for (tempi = a.begin(); tempi != a.end(); tempi++) cout << *tempi << " ";
}
}
| 9 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
long long n, k;
cin >> n >> k;
if (sqrt(n) < k) {
cout << "NO" << endl;
} else if (n % 2 == 0 && k % 2 != 0) {
cout << "NO" << endl;
} else if (n % 2 != 0 && k % 2 == 0) {
cout << "NO" << endl;
} else {
cout << "YES" << endl;
}
}
}
| 7 | CPP |
s1 = input()
s2 = input()
s3 = input()
mat=[]
sat=[]
buka=2
for i in s1:
mat.append(i)
for i in s2:
mat.append(i)
for i in s3:
sat.append(i)
if len(sat)==len(mat):
for i in sat:
if i in mat:
del mat[mat.index(i)]
else:
print('NO')
buka=int(0)
break
if len(mat)==0:
print('YES')
else:
if buka==2:
print('NO')
else:
print('NO')
| 7 | PYTHON3 |
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct data{
int t;
int s;
int d;
};
bool operation(const data &l,const data&r){
return l.t < r.t;
}
int main(){
bool b[20001];
int N,M;
vector<data> v;
data da;
int res;
while(1){
cin >> N >> M;
if(N == 0)break;
v.clear();
for(int i = 1;i <= N;i++){
b[i] = false;
}
for(int i = 0;i < M;i++){
cin >> da.t >> da.s >> da.d;
v.push_back(da);
}
sort(v.begin(),v.end(),operation);
b[1] = true;
res = 1;
for(int i = 0;i < v.size();i++){
if(b[v[i].s] && !b[v[i].d]){
b[v[i].d] = true;
res++;
//cout << v[i].s << " : " << v[i].d <<endl;
}
}
cout << res <<endl;
}
return 0;
} | 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
bool round(long long n) {
long long cnt = 0;
while (n != 0) {
long long temp = n % 10;
if (temp == 0) cnt++;
n = n / 10;
}
if (cnt == 1)
return true;
else
return false;
}
void minround(long long n) {
long long i = 0;
vector<long long> v;
while (n != 0) {
long long temp = n % 10;
if (temp != 0) {
v.push_back(temp * pow(10, i));
i++;
n = n / 10;
} else {
i++;
n = n / 10;
}
}
cout << v.size() << endl;
for (int i = 0; i < v.size(); i++) cout << v[i] << " ";
cout << endl;
}
int main() {
long long t;
cin >> t;
while (t--) {
long long n;
cin >> n;
minround(n);
}
return 0;
}
| 7 | CPP |
t=int(input())
for i in range(t):
b=[]
a=list(map(int,input()))
b=a[1:]
if list(set(b))==[0]:
print(1)
print("".join(list(map(str,a))))
continue
elif len(a)==1:
print(1)
print("".join(list(map(str,a))))
continue
for i in range(0,len(a),1):
if a[i]!=0:
a[i]=a[i]*(10**(len(a)-1-i))
a = [i for i in a if i!=0]
print(len(a))
for i in a:
print(i,end=" ")
print()
continue
| 7 | PYTHON3 |
N,K=map(int,input().split())
L=list(map(int,input().split()))
ans=1000000010
for i in range(N-K+1):
ans=min(ans,(min(abs(L[i]),abs(L[i+K-1]))+L[i+K-1]-L[i]))
print(ans) | 0 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
map<long long, long long> dd;
map<long long, long long> tong;
int main() {
long long n;
cin >> n;
string s;
cin >> s;
long long sum = 0;
for (long long i = 0; i < s.size(); i++) {
sum += (s[i] - '0');
}
for (long long i = 2; i <= s.size(); i++) {
if (sum % i == 0) {
long long tmp = sum / i, dem = 0;
long long sum1 = 0;
for (long long j = 0; j < s.size(); j++) {
sum1 += (s[j] - '0');
if (sum1 == tmp) {
sum1 = 0;
dem++;
}
}
if (dem == i) {
cout << "YES";
return 0;
}
}
}
cout << "NO";
}
| 9 | CPP |
n=int(input())
a=input()
c=0
d=0
for i in range(n):
if a[i]=="A":
c+=1
else:
d+=1
if c>d:
print ("Anton")
elif d>c:
print ("Danik")
else:
print ("Friendship") | 7 | PYTHON3 |
a=input()
c=0
b=0
for i in a:
if i.isupper():
b+=1
else:
c+=1
if b>c:
print(a.upper())
else:
print(a.lower())
| 7 | PYTHON3 |
di = {'A':'T','T':'A','G':'C','C':'G'}
print(di[input()]) | 0 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
struct edge {
int u, v, c, p;
} s[501000];
int n, m;
int f[501000], ff[501000];
void Union(int a, int b) {
int t = f[a] + f[b];
if (f[a] > f[b]) swap(a, b);
f[a] = t;
f[b] = a;
}
int root(int u) {
if (f[u] < 0) return u;
return f[u] = root(f[u]);
}
int tcase, now[501000];
int root2(int u) {
if (now[u] != tcase) now[u] = tcase, ff[u] = f[u];
if (ff[u] < 0) return u;
return ff[u] = root2(ff[u]);
}
void Union2(int a, int b) {
int t = ff[a] + ff[b];
if (ff[a] > ff[b]) swap(a, b);
ff[a] = t;
ff[b] = a;
}
vector<pair<int, int> > qc[501000];
vector<int> e[501000];
int q;
bool query[501000];
void init() {
int k, id;
cin >> q;
for (int i = 0; i < q; ++i) {
cin >> k;
query[i] = true;
while (k--) {
cin >> id;
qc[s[id].c].push_back(pair<int, int>(i, id));
}
}
}
void solve() {
tcase = 0;
for (int i = 1; i <= n; ++i) f[i] = -1;
for (int cost = 1; cost <= 5e5; ++cost) {
sort(qc[cost].begin(), qc[cost].end());
for (int i = 0; i < qc[cost].size(); ++i) {
if (!i || qc[cost][i].first != qc[cost][i - 1].first) tcase++;
int id = qc[cost][i].second;
int a = root2(s[id].u);
int b = root2(s[id].v);
if (a == b) {
query[qc[cost][i].first] = false;
} else
Union2(a, b);
}
for (int id : e[cost]) {
int a = root(s[id].u);
int b = root(s[id].v);
if (a != b) Union(a, b);
}
}
for (int i = 0; i < q; ++i) {
if (query[i])
cout << "YES\n";
else
cout << "NO\n";
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
;
cin >> n >> m;
for (int i = 1; i <= m; ++i) {
cin >> s[i].u >> s[i].v >> s[i].c;
e[s[i].c].push_back(i);
}
init();
solve();
}
| 9 | CPP |
# a=[3, -1, 7]
# b=[-5, 2, -4]
# c=[2, -1, -3]
b=[]
n=int(input())
for x in range(n):
b.append(list(map(int, input().split())))
# my_zip=list(zip(*b))
summ=list(map(sum, list(zip(*b))))
# print(summ)
if summ[0]==summ[1]==summ[2]==0:
print("YES")
else:
print("NO")
# my_zip=list(zip(a,b,c))
# print(my_zip)
# my_map=sum(list(map(sum,my_zip)))
# print(my_map) | 7 | PYTHON3 |
# sys.setrecursionlimit(300000)
import sys
def main():
pass
def binary(n):
# decimal to binary
return (bin(n).replace("0b", ""))
def decimal(s):
# binary to decimal
return (int(s, 2))
def pow2(n):
# power of a number base 2
p = 0
while n > 1:
n //= 2
p += 1
return (p)
def isPrime(n):
# if number is prime in √n time
if (n == 1):
return (False)
else:
root = int(n ** 0.5)
root += 1
for i in range(2, root):
if (n % i == 0):
return (False)
return (True)
def lts(l):
# list to string ,no spaces
s = ''.join(map(str, l))
return s
def stl(s):
# for each character in string to list with no spaces -->
l = list(s)
# for space in string -->
# l=list(s.split(" "))
return l
# Returns list of numbers with a particular sum
def sq(a, target, arr=[]):
s = sum(arr)
if (s == target):
return arr
if (s >= target):
return
for i in range(len(a)):
n = a[i]
remaining = a[i + 1:]
ans = sq(remaining, target, arr + [n])
if (ans):
return ans
# 1000000007
mod = int(1e9) + 7
def sinp(): return sys.stdin.readline().strip()
def iinp(): return int(input())
def ninp(): return map(int, sys.stdin.readline().strip().split())
def llinp(): return list(map(int, sys.stdin.readline().strip().split()))
def p(xyz): print(xyz)
def p2(a, b): print(a, b)
import math as m
#for _ in range(iinp()):
n,m=ninp()
l=[]
for i in range(n):
s=sinp()
s1=list(s)
l.append(s1)
ms=set()
for i in range(m):
ma=0
l1=[]
for j in range(len(l)):
if(int(l[j][i])<ma):
pass
elif(int(l[j][i])==ma):
l1.append(j)
elif(int(l[j][i])>ma):
l1=[]
ma=int(l[j][i])
l1.append(j)
for x in l1:
ms.add(x)
p(len(ms))
| 7 | PYTHON3 |
import math
m = []
i = 0
while i < 5:
m.append(input().split())
i += 1
i = 0
while i < 5:
j = 0
while j < 5:
if m[i][j] == '1':
print(abs(i-2)+abs(j-2))
break
j += 1
if j < 5:
break
i += 1
| 7 | PYTHON3 |
#include <bits/stdc++.h>
int main() {
int n, i;
double b;
while (scanf("%d", &n) != EOF) {
double a[101] = {0}, sum, ave, res[101];
int flag = 1;
scanf("%lf", &b);
sum = b;
for (i = 0; i < n; i++) {
scanf("%lf", a + i);
sum += a[i];
}
ave = sum / n;
for (i = 0; i < n; i++) {
if (a[i] > ave) {
flag = 0;
break;
}
res[i] = ave - a[i];
}
if (flag)
for (i = 0; i < n; i++) printf("%lf\n", res[i]);
else
printf("-1\n");
}
return 0;
}
| 7 | CPP |
a, b = map(int, input().split())
p = list(map(int, input().split()))
for i in range(b):
l, r, x = map(int, input().split())
l -= 1
r -= 1
x -= 1
ans = 0
for i in range(l, r+1):
if p[i] <= p[x]:
ans+=1
if ans == x-l+1:
print("Yes")
else:
print("No")
| 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll ans;
ll cal(ll x)
{
return (1+x)*x/2;
}
int main()
{
int n;
cin>>n;
for(int i=1;i<=n;i++) ans+=i*cal(n/i);
cout<<ans;
} | 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
int par[1005], in[1005], dp[1005][1005];
vector<int> v;
int main() {
int n, x, k, len, pos, offset;
scanf("%d", &n);
scanf("%d", &k);
for (int i = int(1); i <= int(n); i++) {
scanf("%d", &x);
if (x) {
par[i] = x;
in[x]++;
}
}
for (int i = int(1); i <= int(n); i++) {
assert(in[i] <= 1);
if (!in[i]) {
x = i;
len = 0;
pos = -1;
while (x) {
len++;
if (x == k) pos = len;
x = par[x];
}
if (pos != -1)
offset = len - pos + 1;
else
v.push_back(len);
}
}
n = v.size();
dp[0][0] = 1;
for (int i = int(1); i <= int(n); i++) {
for (int j = int(0); j <= int(1000); j++) {
if (dp[i - 1][j]) dp[i][j] = dp[i][j + v[i - 1]] = 1;
}
}
for (int j = int(0); j <= int(1000); j++) {
if (dp[n][j]) cout << j + offset << endl;
}
return 0;
}
| 8 | CPP |
problems,times=map(int,input().split())
lefttime=240-int(times)
needtimes=0
for i in range(problems):
needtimes+=(i+1)*5
if needtimes>lefttime:
print(i)
break
elif needtimes==lefttime:
print(i+1)
break
elif i+1==problems and needtimes<=lefttime:
print(problems)
break
| 7 | PYTHON3 |
a = int(input())
if a == 5 or a == 4 or a == 3 or a==2 or a==1:
print("1")
elif a == 0:
print("0")
elif a > 5:
print((a//5)+1 if a%5 != 0 else a//5) | 7 | PYTHON3 |
while True:
w,h=map(int, input().split())
if w==h==0:
break
xs,ys=map(int, input().split())
xg,yg=map(int, input().split())
xs-=1
ys-=1
xg-=1
yg-=1
n=int(input())
dataset=[]
for _ in range(n):
dataset.append(list(map(int,input().split())))
maze=[ [0 for i in range(w) ] for j in range(h)]
for data in dataset:
color=data[0]
drc=data[1]
x=data[2]-1
y=data[3]-1
x_list=[x,x+1] if drc==1 else [x,x+1,x+2,x+3]
y_list=[y,y+1,y+2,y+3] if drc==1 else [y,y+1]
for dy in y_list:
for dx in x_list:
maze[dy][dx]=color
history=[[-1 for i in range(w)] for j in range(h)]
ws=[]
dx_list=[0,0,1,-1]
dy_list=[1,-1,0,0]
flag=False
if maze[ys][xs]!=0:
ws.append([xs,ys])
while len(ws)!=0:
current=ws.pop(0)
current_color=maze[current[1]][current[0]]
if current[0]==xg and current[1]==yg:
flag=True
break
for dx,dy in zip(dx_list,dy_list):
next_x=current[0]+dx
next_y=current[1]+dy
if next_x>=0 and next_x<w and next_y>=0 and next_y<h and maze[next_y][next_x]==current_color and history[next_y][next_x]==-1:
history[next_y][next_x]=0
ws.append([next_x,next_y])
if flag:
print('OK')
else:
print('NG')
| 0 | PYTHON3 |
from sys import stdin,stdout
input = stdin.readline
print = stdout.write
def gt(n):
l = list(map(int,[i for i in str(n)]))
return max(l)*min(l)
for _ in range(int(input())):
a,k=map(int,input().split())
for _ in range(1,k):
p=gt(a)
if p==0:
break
else:
a+=p
print(str(a)+'\n') | 7 | PYTHON3 |
n, m = map(int, input().split())
w = list(map(int, input().split()))
ans = 0
for i in range(m):
x, y = map(int, input().split())
ans += min(w[x-1], w[y-1])
print(ans)
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
bool b = false;
int c0 = 0, c1 = 0;
string arr;
cin >> arr;
int k = arr.length();
for (int i = 0; i < k; i++) {
if (arr[i] == '0') {
c0++;
c1 = 0;
} else {
c1++;
c0 = 0;
}
if (c1 > 6 || c0 > 6) b = true;
}
if (b == true)
cout << "YES";
else
cout << "NO";
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
const long long int inf = 1e9 + 9;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long int t;
cin >> t;
while (t--) {
long long int n;
cin >> n;
vector<pair<long long int, long long int>> even, odd;
for (long long int i = 0; i < 2 * n; ++i) {
long long int x;
cin >> x;
if (x & 1)
odd.push_back({x, i + 1});
else
even.push_back({x, i + 1});
}
long long int odd_sz = odd.size();
long long int even_sz = even.size();
if (odd_sz & 1) {
odd.pop_back();
even.pop_back();
} else if (odd_sz) {
odd.pop_back();
odd.pop_back();
} else {
even.pop_back();
even.pop_back();
}
while (odd.size()) {
cout << odd.back().second << " ";
odd.pop_back();
cout << odd.back().second << " ";
cout << "\n";
odd.pop_back();
}
while (even.size()) {
cout << even.back().second << " ";
even.pop_back();
cout << even.back().second << " ";
cout << "\n";
even.pop_back();
}
}
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
int x[100005], a, b;
int main() {
int n;
while (scanf("%d", &n) != EOF) {
for (int i = 0; i < n; i++) {
scanf("%d", &x[i]);
}
scanf("%d%d", &a, &b);
sort(x, x + n);
n = unique(x, x + n) - x;
int step = 0;
while (a > b) {
int mix = a - 1;
for (int i = 0; i < n; i++)
if (a - a % x[i] >= b) mix = min(mix, a - (a % x[i]));
a = mix;
step++;
while (n > 0 && a - (a % x[n - 1]) < b) n--;
}
printf("%d\n", step);
}
return 0;
}
| 9 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
set<string> st;
string sp;
for (int i = 0; i < N; i++) {
string sn;
cin >> sn;
if (st.count(sn) || (i > 0 && sn[0] != sp[sp.size()-1]) ) {
cout << "No" << endl;
return 0;
}
st.insert(sn);
sp = sn;
}
cout << "Yes" << endl;
} | 0 | CPP |
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
cout<<n*2*3.14;
return 0;
} | 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
long double const pi = 3.141592653589793238462;
long long int const mod = 998244353;
long long int power(long long int a, long long int b) {
long long int f = 1;
while (b > 0) {
if (b & 1) {
f = f * a;
}
a = a * a;
b = b / 2;
}
return f;
}
bool rev(pair<long long int, pair<long long int, long long int> > a,
pair<long long int, pair<long long int, long long int> > b) {
return a.first <= b.first;
}
long long int const N = 105;
int32_t main() {
std::ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
;
long long int n;
cin >> n;
long long int i, j, l;
vector<long double> p(n);
for (i = 0; i < n; i++) {
cin >> p[i];
}
sort(p.begin(), p.end());
long double ans = p[n - 1];
long double z = 1.0 - p[n - 1];
for (i = n - 2; i >= 0; i--) {
long double x = ans * (1.0 - p[i]);
long double y = p[i] * z;
x = x + y;
if (ans < x) {
ans = x;
z = z * (1.0 - p[i]);
} else {
break;
}
}
cout << fixed << setprecision(20) << ans << endl;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n;
cin >> n;
long long a[n], b[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
long long mx = 0;
for (int j = 0; j < a[i]; j++) {
long long k;
cin >> k;
b[i] = max(mx, k);
mx = b[i];
}
}
long long mx = *max_element(b, b + n);
long long res = 0;
for (int i = 0; i < n; i++) {
res = res + a[i] * (mx - b[i]);
}
cout << res << endl;
}
| 7 | CPP |
#include <bits/stdc++.h>
const int N = 500;
bool a[N + 5][N + 5], b[N + 5][N + 5], d[N + 5][N + 5];
bool f(int x, int y) {
return (0 <= x && x < N && 0 <= y && y < N) ? a[x][y] : false;
}
void dfs(int x, int y) {
if (b[x][y]) return;
b[x][y] = true;
if (f(x - 1, y)) dfs(x - 1, y);
if (f(x + 1, y)) dfs(x + 1, y);
if (x & 1) {
if (f(x - 1, y + 1)) dfs(x - 1, y + 1);
} else {
if (f(x + 1, y - 1)) dfs(x + 1, y - 1);
}
}
struct node {
int x, y;
};
std::queue<node> que;
void try_add(int i, int j, bool k) {
if (f(i, j) == k) return;
int c = (f(i + 1, j) == k) + (f(i - 1, j) == k);
if (i & 1)
c += (f(i - 1, j + 1) == k);
else
c += (f(i + 1, j - 1) == k);
if (c >= 2) que.push((node){i, j});
}
int main() {
int n;
scanf("%d", &n);
for (int i = 1, x, y; i <= n; i++) scanf("%d%d", &x, &y), a[x][y] = true;
int ans = 0;
for (int i = -1; i <= N; i++)
for (int j = -1; j <= N; j++) {
ans += (f(i, j) != f(i + 1, j));
if (i & 1) ans += (f(i, j) != f(i - 1, j + 1));
}
for (int i = 0; i < N; i++)
for (int j = 0; j < N; j++) {
if (!f(i, j) && f(i + 1, j) && f(i - 1, j)) {
if (i & 1) {
if (f(i - 1, j + 1)) d[i][j] = true;
} else {
if (f(i + 1, j - 1)) d[i][j] = true;
}
}
}
for (int i = -1; i < N; i++)
for (int j = -1; j <= N; j++) try_add(i, j, true);
while (!que.empty()) {
node x = que.front();
que.pop();
a[x.x][x.y] = true, try_add(x.x - 1, x.y, true),
try_add(x.x + 1, x.y, true);
if (x.x & 1)
try_add(x.x - 1, x.y + 1, true);
else
try_add(x.x + 1, x.y - 1, true);
}
for (int i = 0; i < N; i++)
for (int j = 0; j < N; j++)
if (d[i][j]) {
if (i & 1) {
if (!f(i + 2, j) && !f(i - 2, j) && !f(i, j + 1) &&
!f(i - 2, j + 1) && !f(i, j - 1) && !f(i + 2, j - 1))
ans -= 2;
} else {
if (!f(i + 2, j) && !f(i - 2, j) && !f(i, j - 1) &&
!f(i + 2, j - 1) && !f(i, j + 1) && !f(i - 2, j + 1))
ans -= 2;
}
}
for (int i = 0; i < N; i++)
for (int j = 0; j < N; j++)
if (a[i][j] && !b[i][j]) ans -= 2, dfs(i, j);
for (int i = 0; i < N; i++)
for (int j = 0; j < N; j++) try_add(i, j, false);
while (!que.empty()) {
node x = que.front();
que.pop();
a[x.x][x.y] = false, try_add(x.x - 1, x.y, false),
try_add(x.x + 1, x.y, false);
if (x.x & 1)
try_add(x.x - 1, x.y + 1, false);
else
try_add(x.x + 1, x.y - 1, false);
}
for (int i = 0; i < N; i++)
for (int j = 0; j < N; j++)
if (a[i][j]) {
puts("SICK");
return 0;
}
printf("RECOVERED\n%d\n", ans);
}
| 11 | CPP |
from itertools import product
n = int(input())
l = []
for i in range(2, 11, 2):
l = l + [int(''.join([str(y) for y in x])) for x in list(product([4,7], repeat=i)) if x.count(4) == i/2]
for x in sorted(l):
if x == n or x > n:
print(x)
exit(0)
# Made By Mostafa_Khaled | 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
struct node {
long long sum, mx;
node() {}
node(long long v) : sum(v), mx(v) {}
node(long long sum, long long mx) : sum(sum), mx(mx) {}
};
node NEUT(0);
node oper(node x, node y) { return node(x.sum + y.sum, max(x.mx, y.mx)); }
struct STree {
vector<node> st;
int n;
STree(int n) : st(4 * n + 5, NEUT), n(n) {}
void upd(int k, int s, int e, int p, int v) {
if (s + 1 == e) {
st[k] = node(v);
return;
}
int m = (s + e) / 2;
if (p < m)
upd(2 * k, s, m, p, v);
else
upd(2 * k + 1, m, e, p, v);
st[k] = oper(st[2 * k], st[2 * k + 1]);
}
node query(int k, int s, int e, int a, int b) {
if (s >= b || e <= a) return NEUT;
if (s >= a && e <= b) return st[k];
int m = (s + e) / 2;
return oper(query(2 * k, s, m, a, b), query(2 * k + 1, m, e, a, b));
}
int get(int k, int s, int e, int pos, int v) {
if (e <= pos) return n;
if (s >= pos) {
if (st[k].mx < v) return n;
if (s + 1 == e) return s;
}
int m = (s + e) / 2;
int ans = get(2 * k, s, m, pos, v);
if (ans == n) ans = get(2 * k + 1, m, e, pos, v);
return ans;
}
void upd(int p, int v) { upd(1, 0, n, p, v); }
int get(int pos, int v) { return get(1, 0, n, pos, v); }
node query(int a, int b) { return query(1, 0, n, a, b); }
};
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, q;
cin >> n >> q;
STree st(n);
vector<int> a(n);
for (long long i = 0; i < n; i++) cin >> a[i], st.upd(i, a[i]);
while (q--) {
int t;
cin >> t;
if (t == 1) {
int l, r;
cin >> l >> r;
cout << st.query(l - 1, r).sum << "\n";
}
if (t == 2) {
int l, r, x;
cin >> l >> r >> x;
l--;
r--;
while (l <= r) {
st.upd(l, a[l] % x);
a[l] %= x;
l = st.get(l + 1, x);
}
}
if (t == 3) {
int k, x;
cin >> k >> x;
k--;
a[k] = x;
st.upd(k, x);
}
}
return 0;
}
| 10 | CPP |
n = int(input())
l = [list(map(int,input().split())) for _ in range(n)]
s=0
flag=False
for i in range(3):
for j in range(n):
s+=l[j][i]
if s==0:
s=0
else:
flag=True
break
if flag:
print("NO")
else:
print("YES") | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
bool compar(const pair<int, int> &a, const pair<int, int> &b) {
return a.first < b.first;
}
bool compar_arr(const int &a, const int &b) { return a > b; }
int main(void) {
int n;
cin >> n;
int a[n];
vector<pair<int, int> > b;
for (int i = (0); i < (n); i++) cin >> a[i];
int temp;
for (int i = (0); i < (n); i++) {
cin >> temp;
b.push_back(make_pair(temp, i));
}
sort(a, a + n, compar_arr);
int k = 0;
sort(b.begin(), b.end(), compar);
int x[n];
for (int i = (0); i < (n); i++) {
x[b[i].second] = a[k++];
}
for (int i = (0); i < (n); i++) cout << x[i] << " ";
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n,m;
cin>>n>>m;
vector<int> v[m];
for(int i=0;i<m;i++){
int k;
cin>>k;
for(int j=0;j<k;j++){
int z;
cin>>z;
v[i].push_back(z);
}
}
int p[m];
for(int i=0;i<m;i++) cin>>p[i];
int ans2=0;
for(int i=0;i<(1<<n);i++){
int big=0;
for(int j=0;j<m;j++){
int ans=0;
for(int z=0;z<v[j].size();z++){
if((1<<(v[j][z]-1))&i) ++ans;
}
if(ans%2==p[j]) ++big;
}
if(big==m) ++ans2;
}
cout<<ans2;
} | 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7, LINF = 1e16 + 1;
const int INF = 1e9 + 1;
const double EPS = 1e-10;
const int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};
const ll P1 = 31, P2 = 37, M1 = 1e9 + 7, M2 = 1e9 + 9;
const int N = 5002, Q = 1e5 + 1;
int n, q, a[N], s[N], f[N][N], mx[N], res[Q];
vector<pair<int, int>> queries[N];
void computef() {
for (int i = (int)1; i <= (int)n; ++i) f[i][i] = a[i];
for (int len = (int)2; len <= (int)n; ++len) {
for (int i = (int)1; i <= (int)n - len + 1; ++i) {
int j = i + len - 1;
f[i][j] = f[i][j - 1] ^ f[i + 1][j];
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
;
cin >> n;
for (int i = (int)1; i <= (int)n; ++i) {
cin >> a[i];
s[i] = s[i - 1] ^ a[i];
}
cin >> q;
for (int i = (int)0; i <= (int)q - 1; ++i) {
int l, r;
cin >> l >> r;
queries[r].emplace_back(l, i);
}
computef();
for (int i = (int)1; i <= (int)n; ++i) {
for (int j = (int)i; j >= (int)1; --j) {
mx[j] = max(mx[j + 1], mx[j]);
mx[j] = max(f[j][i], mx[j]);
}
for (auto &p : queries[i]) {
res[p.second] = max(mx[p.first], res[p.second]);
}
}
for (int i = (int)0; i <= (int)q - 1; ++i) cout << res[i] << '\n';
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, m, ans = 0, ff[666666], fa[666666], dep[666666];
int M = 0, fst[666666], vb[666666], nxt[666666];
void ad_de(int a, int b) {
++M;
nxt[M] = fst[a];
fst[a] = M;
vb[M] = b;
}
void adde(int a, int b) {
ad_de(a, b);
ad_de(b, a);
}
bool vis[666666], te[666666];
vector<int> cx;
int gf(int x) { return ff[x] ? ff[x] = gf(ff[x]) : x; }
void dfs(int x) {
vis[x] = 1;
cx.push_back(x);
for (int e = fst[x], b = vb[e]; e; e = nxt[e], b = vb[e])
if (!vis[b]) te[e] = te[e ^ 1] = 1, dep[b] = dep[x] + 1, fa[b] = x, dfs(b);
}
namespace Tr2 {
int M = 0, fst[666666], vb[666666], nxt[666666];
void ad_de(int a, int b) {
++M;
nxt[M] = fst[a];
fst[a] = M;
vb[M] = b;
}
void adde(int a, int b) {
ad_de(a, b);
ad_de(b, a);
}
bool big[666666];
int dis[666666], dis2[666666];
pair<int, int> mx;
void dfs(int* d, int x) {
mx = max(mx, pair<int, int>(d[x], x));
for (int e = fst[x], b = vb[e]; e; e = nxt[e], b = vb[e])
if (d[b] == -1) d[b] = d[x] + 1, dfs(d, b);
}
void doit() {
for (int i = 1; i <= n; ++i) dis[i] = dis2[i] = -1;
for (int i = 1; i <= n; ++i)
if (big[i] && dis[i] == -1) {
mx = pair<int, int>(-1, -1);
dis[i] = 1;
dfs(dis, i);
int g = mx.second;
mx = pair<int, int>(-1, -1);
dis2[g] = 1;
dfs(dis2, g);
ans -= mx.first;
}
}
} // namespace Tr2
namespace Tr {
int M = 0, fst[666666], vb[666666], nxt[666666];
void ad_de(int a, int b) {
++M;
nxt[M] = fst[a];
fst[a] = M;
vb[M] = b;
}
void adde(int a, int b) {
ad_de(a, b);
ad_de(b, a);
}
int du[666666];
void doit() {
for (int i = 1; i <= n; ++i)
if (du[i] >= 2) {
++ans;
Tr2::big[i] = 1;
for (int e = fst[i], b = vb[e]; e; e = nxt[e], b = vb[e])
if (b > i && du[b] >= 2) Tr2::adde(i, b);
}
}
} // namespace Tr
void work(int r) {
cx.clear();
dep[r] = 1;
dfs(r);
for (unsigned _ = 0; _ < cx.size(); ++_) {
int x = cx[_];
for (int e = fst[x], b = vb[e]; e; e = nxt[e], b = vb[e])
if (!te[e] && dep[x] < dep[b]) {
for (int g = gf(b); dep[g] > dep[x]; g = gf(g)) ff[g] = fa[g], ++ans;
}
}
for (unsigned _ = 0; _ < cx.size(); ++_) {
int x = cx[_];
for (int e = fst[x], b = vb[e]; e; e = nxt[e], b = vb[e])
if (b > x && gf(x) != gf(b))
Tr::adde(gf(x), gf(b)), ++Tr::du[gf(x)], ++Tr::du[gf(b)];
}
}
int main() {
scanf("%d%d", &n, &m);
M = 1;
for (int i = 1, a, b; i <= m; ++i) scanf("%d%d", &a, &b), adde(a, b);
for (int i = 1; i <= n; ++i)
if (!vis[i]) ++ans, work(i);
--ans;
Tr::doit();
Tr2::doit();
printf("%d\n", ans);
}
| 12 | CPP |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n = 0;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
vector<vector<int> > freq(n + 1, vector<int>(n));
for (int i = 0; i < n; i++) {
freq[i + 1] = freq[i];
freq[i + 1][a[i] - 1]++;
}
vector<vector<long long int> > dp(n, vector<long long int>(n));
for (int i = 0; i < n; i++) {
for (int j = i + 2; j < n; j++) {
dp[i][j] = dp[i][j - 1] - (freq[j - 1][a[j] - 1] - freq[i + 1][a[j] - 1]);
dp[i][j] += (freq[n][a[j - 1] - 1] - freq[j + 1][a[j - 1] - 1]);
}
}
long long int ans = 0;
for (int i = 0; i < n; i++) {
for (int j = i + 2; j < n; j++) {
if (a[i] == a[j]) {
ans += dp[i][j];
}
}
}
cout << ans << endl;
return;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}
| 10 | CPP |
#include <iostream>
#include <algorithm>
using namespace std;
pair <int,int> a[1000005];
inline bool cmp(pair <int,int> x,pair <int,int> y)
{
if(x.second-x.first>=0&&y.second-y.first<0) return 1;
if(x.second-x.first<0&&y.second-y.first>=0) return 0;
if(x.second-x.first>=0) return x.first<y.first;
else return -x.first+x.second-y.first>-y.first+y.second-x.first;
}
int main(int argc, char** argv) {
int n;
cin >> n;
for(int i=1;i<=n;i++)
{
string s;
cin >> s;
int l=0,r=0;
for(auto x:s)
{
if(x=='(') ++l;
else if(l) --l;
else ++r;
}
a[i]={r,l};
// cout << a[i].first << " " << a[i].second << "\n";
}
sort(a+1,a+n+1,cmp);
int now=0;
for(int i=1;i<=n;i++)
{
now-=a[i].first;
if(now<0)
{
puts("No");
return 0;
}
now+=a[i].second;
}
if(now) puts("No");
else puts("Yes");
return 0;
} | 0 | CPP |
/*input
4 4
2 4
1 1
2 3
2 4
*/
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
int main() {
int h, w;
cin >> h >> w;
map<int, int> s;
multiset<int> vals;
rep(i, w) s[i] = i;
rep(i, w) vals.insert(0);
rep(i, h) {
int l, r;
cin >> l >> r;
--l;
auto it = s.lower_bound(l);
int mr = -1;
while (it != s.end() && it->first <= r) {
mr = max(mr, it->second);
int x = it->first-it->second;
vals.erase(vals.find(x));
s.erase(it++);
}
if (mr != -1 && r < w) {
vals.insert(r-mr);
s[r] = mr;
}
int ans = -1;
if (vals.size() > 0) {
ans = *vals.begin()+(i+1);
}
cout << ans << endl;
}
} | 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
const long long md = 1e9 + 7;
const int maxn = 107;
vector<vector<long long> > matexpo(vector<vector<long long> > A, long long ex) {
vector<vector<long long> > B, C, D;
int n = A.size();
C = *new vector<vector<long long> >(n);
B = *new vector<vector<long long> >(n);
D = *new vector<vector<long long> >(n);
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
C[i].push_back(i == j);
B[i].push_back(A[i][j]);
D[i].push_back(0);
}
}
while (ex > 0) {
if (ex & 1ll) {
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
D[i][j] = 0;
for (int k = 0; k < n; k++) {
D[i][j] = (D[i][j] + C[i][k] * B[k][j]) % md;
}
}
}
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++) C[i][j] = D[i][j];
}
ex >>= 1;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
D[i][j] = 0;
for (int k = 0; k < n; k++) {
D[i][j] = (D[i][j] + B[i][k] * B[k][j]) % md;
}
}
}
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++) B[i][j] = D[i][j];
}
return C;
}
long long a[maxn];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
long long k;
cin >> n >> k;
vector<vector<long long> > M, A;
M.resize(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
M[i].push_back(__builtin_popcountll(a[i] ^ a[j]) % 3 == 0);
}
}
A = matexpo(M, k - 1);
long long res = 0;
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++) res = (res + A[i][j]) % md;
cout << res << endl;
}
| 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
class point {
public:
int x, y;
point() {}
point( int x_, int y_ ) :x(x_), y(y_) {}
point operator -( point p ) { return point( x - p.x, y - p.y ); }
};
int main()
{
point vp[2];
cin >> vp[0].x >> vp[0].y >> vp[1].x >> vp[1].y;
point base = vp[1] - vp[0];
double norm = base.x * base.x + base.y * base.y;
int q;
cin >> q;
for( int i = 0; i < q; i++ ) {
point p;
cin >> p.x >> p.y;
p = p - vp[0];
double dot = p.x * base.x + p.y * base.y;
double x = vp[0].x + base.x * dot / norm;
double y = vp[0].y + base.y * dot / norm;
cout << fixed << setprecision(10) << x << " " << y << endl;
}
}
| 0 | CPP |
#include <bits/stdc++.h>
int main() {
using namespace std;
ios_base::sync_with_stdio(false), cin.tie(nullptr);
int t; cin >> t;
while (t--) {
long long n; cin >> n;
vector<long long> h(n);
for (long long i = 0; i < n; ++i) {
cin >> h[i];
}
auto solve = [&]() {
for (int i = 1; i < n; ++i) {
h[i] += h[i - 1] - (i - 1);
if (h[i] < i) {
cout << "NO\n";
return;
}
}
cout << "YES\n";
};
solve();
}
}
| 7 | CPP |
H, W, A, B = map(int, input().split())
for i in range(H):
if i <= B-1:
s = '1'*A + '0'*(W-A)
else:
s = '0'*A + '1'*(W-A)
print(s) | 0 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
struct edge {
int u, v;
} ed[100105];
int n, cnt;
int par[100105];
vector<int> adj[100105];
int sz[100105];
void sizeDfs(int nd) {
sz[nd] = 1;
for (auto v : adj[nd]) {
if (v != par[nd]) {
par[v] = nd;
sizeDfs(v);
sz[nd] += sz[v];
}
}
}
int main() {
scanf("%d", &n);
int u, v;
for (int i = 1; i < n; i++) {
scanf("%d %d", &u, &v);
adj[u].push_back(v);
adj[v].push_back(u);
ed[i] = {u, v};
}
if (n & 1) {
puts("-1");
return 0;
}
par[1] = -1;
sizeDfs(1);
for (int i = 1; i < n; i++) {
u = ed[i].u;
v = ed[i].v;
if (par[u] == v) swap(u, v);
if (!(sz[v] & 1)) cnt++;
}
cout << cnt << endl;
return 0;
}
| 9 | CPP |
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
const int N = 3e3 + 10;
long long a[N], b[N];
long long dp[N][N];
long long cost(int x, int y) {
return (a[x] - b[y] > 0) ? a[x] - b[y] : b[y] - a[x];
}
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]), a[i] -= i, b[i] = a[i];
sort(b + 1, b + 1 + n);
for (int i = 0; i <= n; i++)
for (int j = 0; j <= n; j++) dp[i][j] = inf;
for (int i = 1; i <= n; i++) dp[1][i] = cost(1, i);
for (int i = 2; i <= n; i++) {
long long m = inf;
for (int j = 1; j <= n; j++) {
m = min(m, dp[i - 1][j]);
dp[i][j] = m + cost(i, j);
}
}
long long ans = inf;
for (int i = 1; i <= n; i++) ans = min(ans, dp[n][i]);
printf("%lld\n", ans);
return 0;
}
| 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
struct op {
int x, r, ans = -1, index;
} e[maxn];
bool cmp(op x, op y) { return x.x < y.x; }
bool cmp1(op x, op y) { return x.index < y.index; }
bool judge(int x, int y, int x1, int r) {
if ((x - x1) * (x - x1) + y * y > r * r)
return 0;
else
return 1;
}
int judge1(int x, int x1) {
if (x > x1)
return 0;
else if (x < x1)
return 1;
else
return -1;
}
int main() {
int n;
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
scanf("%d %d", &e[i].x, &e[i].r);
e[i].index = i;
}
sort(e + 1, e + 1 + n, cmp);
int m;
scanf("%d", &m);
for (int i = 1; i <= m; ++i) {
int x, y;
scanf("%d %d", &x, &y);
int l = 1, r = n, cnt = 0;
while (l <= r) {
cnt++;
int mid = (l + r) / 2;
if (judge(x, y, e[mid].x, e[mid].r) == 1) {
if (e[mid].ans == -1) e[mid].ans = i;
if (judge1(x, e[mid].x) == 1)
r = mid - 1;
else
l = mid + 1;
} else {
if (judge(x, y, e[mid].x, e[mid].r) == 0 && judge1(x, e[mid].x) == -1)
break;
else if (judge(x, y, e[mid].x, e[mid].r) == 0 &&
judge1(x, e[mid].x) == 1)
r = mid - 1;
else if (judge(x, y, e[mid].x, e[mid].r) == 0 &&
judge1(x, e[mid].x) == 0)
l = mid + 1;
}
if (cnt > log(n) + 100) break;
}
}
sort(e + 1, e + 1 + n, cmp1);
int ans = 0;
for (int i = 1; i <= n; ++i) {
if (e[i].ans != -1) ans++;
}
printf("%d\n", ans);
for (int i = 1; i <= n; ++i) {
printf("%d ", e[i].ans);
}
return 0;
}
| 9 | CPP |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V> &x) {
cerr << '{';
__print(x.first);
cerr << ',';
__print(x.second);
cerr << '}';
}
template <typename T>
void __print(const T &x) {
int f = 0;
cerr << '{';
for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
__print(t);
if (sizeof...(v)) cerr << ", ";
_print(v...);
}
long long int pow1(long long int a, long long int b,
long long int m = 1000000007) {
if (b == 0)
return 1ll;
else if (b == 1)
return a;
else {
long long int x = pow1(a, b / 2, m);
x *= x;
x %= m;
if (b % 2) {
x *= a;
x %= m;
}
return x;
}
}
template <class avgType>
avgType avg(avgType a, avgType b) {
return (a + b) / 2;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng64(chrono::steady_clock::now().time_since_epoch().count());
int randInt() { return rng() % INT_MAX; }
long long int randLL() { return rng64() % LLONG_MAX; }
vector<int> hashmods = {1000000007, 1000000009, 1000000021,
1000000033, 1000000087, 1000000093};
int t, n, u, v, node, dist, par[1100], reqanc[1100], maxlev = 1;
vector<vector<int> > tree(1100);
vector<vector<int> > levels(1100);
string resp;
void dfs(int index, int l) {
levels[l].push_back(index);
maxlev = max(maxlev, l);
if (l >= 2)
reqanc[index] = reqanc[par[index]];
else if (l == 1)
reqanc[index] = index;
for (int neigh : tree[index]) {
if (neigh == par[index]) continue;
par[neigh] = index;
dfs(neigh, l + 1);
}
}
int main() {
cin >> t;
while (t--) {
cin >> n;
maxlev = 1;
for (int i = 0; i <= n; i++) {
tree[i].clear();
levels[i].clear();
par[i] = 0;
reqanc[i] = 0;
}
for (int i = 0; i < n - 1; i++) {
cin >> u >> v;
tree[u].push_back(v);
tree[v].push_back(u);
}
cout << "? " << n << " ";
for (int i = 1; i <= n; i++) cout << i << " ";
cout << "\n";
fflush(stdout);
cin >> node >> dist;
int root = node;
int mindist = dist;
dfs(root, 0);
int beg = max(1, mindist / 2), end = min(mindist, maxlev), ans = -1,
ansnode = -1;
while (beg <= end) {
int mid = avg(beg, end);
cout << "? " << (levels[mid].size()) << " ";
for (int i = 0; i < levels[mid].size(); i++) {
cout << levels[mid][i] << " ";
}
cout << "\n";
fflush(stdout);
cin >> node >> dist;
assert(node != -1);
if (dist == mindist) {
ans = mid;
ansnode = node;
beg = mid + 1;
} else {
end = mid - 1;
}
}
int distlef = mindist - ans, ansothernode = -1;
if (distlef == 0) {
ansothernode = root;
} else {
int cnt = 0;
for (int i = 0; i < levels[distlef].size(); i++) {
if (reqanc[levels[distlef][i]] != reqanc[ansnode]) cnt++;
}
cout << "? " << cnt << "\n";
for (int i = 0; i < levels[distlef].size(); i++) {
if (reqanc[levels[distlef][i]] != reqanc[ansnode]) {
cout << levels[distlef][i] << " ";
}
}
fflush(stdout);
cin >> ansothernode >> dist;
}
cout << "! " << ansnode << " " << ansothernode << "\n";
fflush(stdout);
cin >> resp;
if (resp == "Incorrect") return 0;
}
return 0;
}
| 12 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int inf = (int)1e9 + 7;
const int N = (int)2e5 + 7;
int t;
int n, k;
int used[N];
int main() {
scanf("%d", &t);
while (t--) {
scanf("%d %d", &n, &k);
for (int i = 1; i <= n; ++i) {
used[i] = 0;
}
for (int i = 1; i <= k; ++i) {
int x;
scanf("%d", &x);
used[x] = 1;
}
int ans = 0;
for (int i = 1; i <= n; ++i) {
int to = inf;
for (int j = 1; j <= n; ++j) {
if (used[j]) {
to = min(to, abs(i - j) + 1);
}
}
ans = max(ans, to);
}
printf("%d\n", ans);
}
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
int read() {
int x = 0;
char ch = getchar();
for (; !isdigit(ch); ch = getchar())
;
for (; isdigit(ch); ch = getchar()) x = (x << 3) + (x << 1) + (ch ^ 48);
return x;
}
const double eps = 1e-9;
int n, m;
struct Edge {
int to, nxt;
} edge[200010];
int cnt = 1, last[100010];
inline void addedge(int x, int y) {
edge[++cnt] = (Edge){y, last[x]}, last[x] = cnt;
edge[++cnt] = (Edge){x, last[y]}, last[y] = cnt;
}
int fat[100010], dep[100010], son[100010], siz[100010];
int top[100010], id[100010], od[100010];
void dfs1(int cur, int fat, int dep) {
::fat[cur] = fat;
::dep[cur] = dep;
siz[cur] = 1;
for (int i = last[cur], v; i; i = edge[i].nxt)
if ((v = edge[i].to) ^ fat) {
dfs1(v, cur, dep + 1);
siz[cur] += siz[v];
if (!son[cur] || siz[v] > siz[son[cur]]) son[cur] = v;
}
}
void dfs2(int cur, int top) {
::top[cur] = top;
od[id[cur] = ++*id] = cur;
if (siz[cur] == 1) return;
dfs2(son[cur], top);
for (int i = last[cur], v; i; i = edge[i].nxt)
if (v = edge[i].to, (v ^ fat[cur]) && (v ^ son[cur])) dfs2(v, v);
}
struct Node {
double st, et;
int sp, ep;
bool x, y;
} node[2500000];
int nodetot;
struct Rec {
double tim1;
bool tim2, opt;
int val;
} rec[5000000];
int rectop;
bool operator<(const Rec x, const Rec y) {
if (fabs(x.tim1 - y.tim1) > eps) return x.tim1 < y.tim1;
if (x.tim2 ^ y.tim2) return x.tim2 < y.tim2;
return x.opt > y.opt;
}
void work(double t, double c, int u, int v) {
static pair<int, int> A[100], B[100];
int Atot = 0, Btot = 0;
while (top[u] ^ top[v]) {
if (dep[top[u]] < dep[top[v]])
B[++Btot] = (pair<int, int>){id[top[v]] - 1, id[v]}, v = fat[top[v]];
else
A[++Atot] = (pair<int, int>){id[top[u]] - 1, id[u]}, u = fat[top[u]];
}
if (dep[u] < dep[v])
B[++Btot] = (pair<int, int>){id[u], id[v]};
else if (dep[u] > dep[v])
A[++Atot] = (pair<int, int>){id[v], id[u]};
int s = (dep[u] < dep[v] ? id[u] : id[v]);
for (int i = 1; i <= Atot; i++) {
double tt = t + (A[i].second - A[i].first) / c;
node[++nodetot] = (Node){t, tt, A[i].second, A[i].first, 0, 1};
rec[++rectop] = (Rec){t, 0, 0, nodetot};
rec[++rectop] = (Rec){tt, 0, 1, nodetot};
t = tt;
}
node[++nodetot] = (Node){t, t, s, s, 0, 0};
rec[++rectop] = (Rec){t, 0, 0, nodetot};
rec[++rectop] = (Rec){t, 1, 1, nodetot};
for (int i = Btot; i; i--) {
double tt = t + (B[i].second - B[i].first) / c;
node[++nodetot] = (Node){t, tt, B[i].first, B[i].second, 1, 0};
rec[++rectop] = (Rec){t, 1, 0, nodetot};
rec[++rectop] = (Rec){tt, 1, 1, nodetot};
t = tt;
}
}
namespace T {
double tim;
bool cmp(int x, int y) {
double s = (node[x].ep ^ node[x].sp
? (node[x].ep - node[x].sp) / (node[x].et - node[x].st)
: 0),
t = (node[y].ep ^ node[y].sp
? (node[y].ep - node[y].sp) / (node[y].et - node[y].st)
: 0);
double a = node[x].sp + s * (tim - node[x].st),
b = node[y].sp + t * (tim - node[y].st);
if (fabs(a - b) > eps) return a < b;
if (fabs(s - t) > eps) return s < t;
return x < y;
}
unsigned rnd() {
static unsigned sd = 1756984316U;
return sd ^= sd << 23, sd ^= sd >> 5, sd ^= sd << 11, sd ^= sd >> 26;
}
struct Node {
int lson, rson, siz;
} node[2500000];
int rt;
inline void pushup(int cur) {
node[cur].siz = node[(node[cur].lson)].siz + 1 + node[(node[cur].rson)].siz;
}
void split(int cur, int siz, int &x, int &y) {
if (!cur) return x = y = 0, void();
if (siz <= node[(node[cur].lson)].siz)
y = cur, split((node[cur].lson), siz, x, node[y].lson), pushup(y);
else
x = cur,
split((node[cur].rson), siz - node[cur].siz + node[(node[cur].rson)].siz,
node[x].rson, y),
pushup(x);
}
int getrk(int cur, int id) {
if (!cur) return 0;
if (cmp(id, cur)) return getrk((node[cur].lson), id);
return node[cur].siz - node[(node[cur].rson)].siz +
getrk((node[cur].rson), id);
}
int merge(int x, int y) {
if (!x || !y) return x | y;
if (rnd() % (node[x].siz + node[y].siz) < node[x].siz)
return node[x].rson = merge(node[x].rson, y), pushup(x), x;
return node[y].lson = merge(x, node[y].lson), pushup(y), y;
}
} // namespace T
void checkans(double &ans, int x, int y) {
double myk1, myk2, myb1, myb2;
if (node[x].sp ^ node[x].ep)
myk1 = (node[x].sp - node[x].ep) / (node[x].st - node[x].et),
myb1 = node[x].sp - myk1 * node[x].st;
else
myk1 = 0, myb1 = node[x].sp;
if (node[y].sp ^ node[y].ep)
myk2 = (node[y].sp - node[y].ep) / (node[y].st - node[y].et),
myb2 = node[y].sp - myk2 * node[y].st;
else
myk2 = 0, myb2 = node[y].sp;
double a;
bool b;
if (fabs(node[x].st - node[y].st) > eps)
if (node[x].st < node[y].st)
a = node[y].st, b = node[y].x;
else
a = node[x].st, b = node[x].x;
else
a = node[x].st, b = node[x].x | node[y].x;
double c;
bool d;
if (fabs(node[x].et - node[y].et) > eps)
if (node[x].et < node[y].et)
c = node[x].et, d = node[x].y;
else
c = node[y].et, d = node[y].y;
else
c = node[x].et, d = node[x].y | node[y].y;
if (fabs(myk1 - myk2) < eps) {
if (fabs(myb1 - myb2) < eps)
if (a + eps < c || fabs(a - c) < eps && !b && !d) ans = min(ans, a);
return;
}
double e = (myb2 - myb1) / (myk1 - myk2);
if ((b ? a + eps < e : a < e + eps) && (d ? e + eps < c : e < c + eps))
ans = min(ans, e);
}
int main() {
n = read(), m = read();
for (int i = 1; i < n; i++) addedge(read(), read());
dfs1(1, 0, 1);
dfs2(1, 1);
for (int i = 1, t, c, u, v; i <= m; i++) {
t = read(), c = read(), u = read(), v = read();
work(t, c, u, v);
}
double ans = 1e18;
sort(rec + 1, rec + rectop + 1);
for (int i = 1, t, x, y, z, a, b, c; i <= rectop; i++) {
if (ans < rec[i].tim1 + eps) break;
if (rec[i].opt) {
T::split(T::rt, t = T::getrk(T::rt, rec[i].val), y, z);
T::split(y, t - 1, x, y);
T::rt = T::merge(x, z);
if (t > 1 && t <= T::node[T::rt].siz) {
T::split(T::rt, t - 2, y, z);
T::split(z, 1, a, z);
T::split(z, 1, b, z);
checkans(ans, a, b);
T::rt = T::merge(y, T::merge(a, T::merge(b, z)));
}
continue;
}
T::tim = rec[i].tim1;
T::split(T::rt, t = T::getrk(T::rt, rec[i].val), x, z);
if (x)
T::split(x, T::node[x].siz - 1, x, a), checkans(ans, a, rec[i].val),
x = T::merge(x, a);
if (z)
T::split(z, 1, b, z), checkans(ans, rec[i].val, b), z = T::merge(b, z);
if (ans < rec[i].tim1 + eps) break;
T::node[t = rec[i].val] = (T::Node){0, 0, 1};
T::rt = T::merge(x, T::merge(t, z));
}
if (ans == 1e18)
puts("-1");
else
printf("%.10lf\n", fabs(ans) < eps ? 0.0 : ans);
return 0;
}
| 11 | CPP |
n=int(input())
for i in range(n):
s,a,b,c=map(int,input().split())
print(int(int(s/c)+int(int(s/c)/a)*b))
| 7 | PYTHON3 |
a, b, n = map(int, input().split())
a1=a
b1=b
n1=n
while n1>=0:
while n>0:
a,n=n,a%n
if n1-a<0:
print('1')
break
n1=n1-a
n=n1
a=a1
while n>0:
b,n=n,b%n
if n1-b<0:
print('0')
break
n1=n1-b
n=n1
b=b1
| 7 | PYTHON3 |
#include <cstdio>
#include <vector>
using namespace std;
typedef long long int lli;
vector<int> a;
int find(int m){
if(a[m] == m)
return m;
return find(a[m]);
}
int main(void){
int n, q, p, v, i;
lli ans;
char c;
while(1){
scanf("%d%d",&n,&q);
if(n == 0 && q == 0)
break;
ans = 0;
a.push_back(0);
a.push_back(1);
for(i = 2;i <= n;i++){
scanf("%d%*c",&p);
a.push_back(p);
}
for(i = 0;i < q;i++){
scanf("%c%d%*c",&c,&v);
if(c == 'Q'){
ans += (lli)find(v);
}
else if(c == 'M'){
a[v] = v;
}
}
printf("%lld\n",ans);
a.clear();
}
return 0;
} | 0 | CPP |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ppll pair<ll,pair<ll,ll>>
#define pll pair<ll,ll>
#define rep(i,x,y) for(ll i=x;i<=y;i++)
#define inf 1e16
#define imin INT_MIN
#define imax INT_MAX
#define pb push_back
#define pf push_front
#define vll vector<ll>
#define vvll vector<vector<ll>>
#define vvb vector<vector<bool>>
#define vb vector<bool>
int mod =1e9+7;
bool comp(pair<int,int> a,pair<int,int> b)
{
if(a.second == b.second) return a.first<b.first;
return a.second<b.second;
}
void display(vll a)
{
for(auto& val: a) cout<<val<<' ';
}
ll power(ll a, ll b)
{
ll ans = 1;
while(b)
{
if (b & 1) ans = (ans * a)%mod;
a = (a * a) % mod;
b >>= 1;
}
return ans;
}
const int N = 40000;
bool prime[N + 1];
vll primes;
void setup()
{
for(ll i = 2;i <= N;i++) {
if(prime[i]) {
primes.pb(i);
for(ll j = i*i;j <= N;j+= i)
prime[j] = false;
}
}
}
ll cntPF(ll x)
{
ll cnt = 0;
for(auto i: primes)
{
while(x % i == 0)
x /= i, cnt++;
}
if(x > 1) cnt++;
return cnt;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
rep(i,1,N) prime[i] = true;
setup();
ll t;
cin>>t;
while(t--)
{
ll a, b, k;
cin>>a>>b>>k;
if(k == 1)
{
if((a%b == 0 || b % a == 0) && (a != b)) cout<<"YES\n";
else cout<<"NO\n";
continue;
}
ll total = cntPF(a) + cntPF(b);
cout<< ((total >= k) ? "YES\n" : "NO\n");
}
return 0;
}
| 10 | CPP |
t=int(input())
for you in range(t):
l=input().split()
n=int(l[0])
x=int(l[1])
l=input().split()
li=[int(i)-x for i in l]
li.sort()
suma=0
j=n-1
count=0
while(j>=0):
if(suma+li[j]>=0):
count+=1
suma+=li[j]
j-=1
else:
break
print(count)
| 8 | PYTHON3 |
for _ in [0]*int(input()):
n = int(input())
a = list(map(int, input().split()))
cnt = [0,0]
for i in range(n):
if i%2 != a[i]%2:
cnt[i%2] += 1
print(cnt[0] if cnt[0] == cnt[1] else -1)
| 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int w, l;
int main() {
scanf("%d %d", &w, &l);
int a[w];
for (int i = 1; i < w; i++) {
scanf("%d", &a[i]);
a[i] = a[i] + a[i - 1];
}
int res = a[w - 1];
for (int i = l; i < w; i++) res = min(a[i] - a[i - l], res);
printf("%d\n", res);
return 0;
}
| 10 | CPP |
[n,m]=[int(x) for x in input().split()]
a=[n//5 for i in range(0,5)]
b=[m//5 for i in range(0,5)]
for i in range(1,n%5+1):
a[i]+=1
for i in range(1,m%5+1):
b[i]+=1
c=a[0]*b[0]
for i in range(1,5):
c+=a[i]*b[5-i]
print(c)
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
void func(void) {
freopen("input.c", "r", stdin);
freopen("output.c", "w", stdout);
}
int main() {
long long n, q, i, j = 0, temp, t, k, ans = 0, sum = 0, x, y, z, cnt = 0, m,
fg = 0, mx = 0, mx1 = 0, mn = 8000000000000000000,
mn1 = 8000000000000000000;
cin >> n >> x >> y;
for (i = 0; i <= 10000000; i++) {
temp = n - i * x;
if (temp >= 0 and temp % y == 0) {
cout << "YES" << endl;
cout << i << " " << temp / y << endl;
return 0;
}
}
cout << "NO\n";
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int N, K;
cin >> N >> K;
for (int i = 0; i < N; i++)
for (int j = 0; j < N; j++)
cout << ((i == j) ? K - N + 1 : 1) << ((j == N - 1) ? "\n" : " ");
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, a[500], s[500], Q, f[500][60][500];
int main() {
cin >> n >> Q;
for (int i = 1; i <= n; i++) {
cin >> a[i];
s[i] = s[i - 1] + a[i];
}
int ans = 0;
for (int i = 1; i <= n; i++) {
for (int j = 2; j <= min(i, Q); j++) {
for (int k = 1; k <= i - j + 1; k++) {
for (int t = 1; t <= i - k - j + 2; t++)
f[i][j][k] = max(f[i][j][k],
f[i - k][j - 1][t] +
abs(s[i] - s[i - k] - s[i - k] + s[i - k - t]));
if (j == Q) ans = max(ans, f[i][j][k]);
}
}
}
cout << ans << '\n';
}
| 11 | CPP |
#include <iostream>
using namespace std;
int main() {
char n;
cin>>n;
if(isupper(n))cout<<'A';
else
cout<<'a';
return 0;
} | 0 | CPP |
n=int(input())
for i in range(n+1,100000):
num=i
a=[0]*10
while(num):
if(a[num%10]==1):
break
a[num%10]=1
num=int(num/10)
if(num==0):
print(i)
break | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int ans = 1;
for (int i = 1; i <= n; i++) {
char tmp;
cin >> tmp;
if (tmp == '1')
ans++;
else
break;
}
cout << min(n, ans) << endl;
return 0;
}
| 7 | CPP |
import os
import sys
from io import BytesIO, IOBase
nmbr = lambda: int(input())
lst = lambda: list(map(int, input().split()))
def main():
for _ in range(nmbr()):
n = nmbr()
s1 = input()
s2 = input()
p = ans = 0
while p < n:
this = s1[p] + s2[p]
if p < n - 1 and ((this == '00' and (s1[p + 1] + s2[p + 1]) == '11') or (
this == '11' and (s1[p + 1] + s2[p + 1]) == '00')):
ans += 2
p += 2
elif s1[p] + s2[p] in ['01', '10']:
ans += 2
p += 1
elif s1[p] + s2[p] == '00':
ans += 1
p += 1
else:
p += 1
# print(ans)
sys.stdout.write(str(ans)+'\n')
# sys.stdout.flush()
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
if __name__ == "__main__":
for t in range(1):main()#int(input())): | 9 | PYTHON3 |
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
template<class T> bool chmin (T &a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1LL<<60;
using node = pair<string, bool>; // left : true right : false
map<node, ll> dp;
using P = pair<ll, node>;
priority_queue<P, vector<P>, greater<P>> que;
ll ans = INF;
void calcu (const string &left, const string &right, ll cost) {
int l = (int)left.size(), r = (int)right.size();
int i = l - 1, j = 0;
while ( i >= 0 && j < r ) if ( left[i--] != right[j++] ) return;
if (l == r) { chmin(ans,cost); return; }
node save;
if (l > r) save = node(left.substr(0, l-r), true);
else save = node(right.substr(l), false);
if ( dp.count(save) ) { if ( chmin(dp[save], cost) ) que.push(P(cost, save)); }
else { dp[save] = cost; que.push(P(cost, save)); }
return;
}
int main() {
int n; cin >> n;
vector<string> s(n);
vector<ll> c(n);
for (int i = 0; i < n; i++) cin >> s[i] >> c[i];
for (int i = 0; i < n; i++) {
for (int j = 0; j <= (int)s[i].size(); j++) {
string left = s[i].substr(0,j), right = s[i].substr(j);
calcu(left, right, c[i]);
}
for (int j = 0; j < (int)s[i].size(); j++) {
string left = s[i].substr(0,j), right = s[i].substr(j+1);
calcu(left, right, c[i]);
}
}
while (!que.empty()) {
auto p = que.top(); que.pop();
ll dist = p.first;
string ns = p.second.first;
if ( dist > dp[p.second] ) continue;
for (int i = 0; i < n; i++) {
if (p.second.second) calcu(ns, s[i], dist + c[i]);
else calcu(s[i], ns, dist + c[i]);
}
}
cout << (ans == INF ? -1 : ans) << endl;
return 0;
} | 0 | CPP |
n = int(input())
size = len(str(n))
rem = 0
cont = 0
i = 1
while i <= size:
rem = n % 10
if rem == 4 or rem == 7:
n = n // 10
cont += 1
else:
n = n // 10
cont = cont
i += 1
if cont == 4 or cont == 7:
print("YES")
else:
print("NO") | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll gcd(ll a, ll b) {
if (b == 0) {
return a;
} else {
return gcd(b, a % b);
}
}
void solve(ll l, ll n, ll k, ll &x, ll &y) {
ll max_gcd = std::numeric_limits<ll>::min();
ll min_gcd = std::numeric_limits<ll>::max();
for (ll i = 0; i <= n; ++i) {
max_gcd = max(max_gcd, gcd(l + i * k, n * k));
min_gcd = min(min_gcd, gcd(l + i * k, n * k));
}
x = (n * k) / max_gcd;
y = (n * k) / min_gcd;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
ll n, k;
cin >> n >> k;
ll a, b;
cin >> a >> b;
ll x, y, x_cur, y_cur;
solve((b - a + k) % k, n, k, x, y);
solve((b + a + k) % k, n, k, x_cur, y_cur);
x = min(x, x_cur);
y = max(y, y_cur);
solve((-b - a + k) % k, n, k, x_cur, y_cur);
x = min(x, x_cur);
y = max(y, y_cur);
solve((-b + a + k) % k, n, k, x_cur, y_cur);
x = min(x, x_cur);
y = max(y, y_cur);
cout << x << ' ' << y << endl;
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
FILE *oku, *yaz;
int dizi[2500] = {
1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1, 0,
0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1, 0, 1, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 0, 1, 0, 0,
1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 1, 1,
0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 0, 1, 0, 0,
1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0,
1, 1, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0,
1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 1, 1,
1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1,
1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1,
0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 1, 1, 0,
0, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0,
1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1,
0, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0,
0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0,
0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1,
1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0,
0, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1,
1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 0,
0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1,
1, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 0,
1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 1, 1, 0, 1, 0, 1, 1, 0, 1,
1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 1, 0,
0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1,
1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1,
1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0,
1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1,
0, 1, 1, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1,
0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1,
1, 1, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1,
1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 0, 1, 0, 1,
0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 1, 1, 1,
1, 0, 0, 0, 1, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0,
1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 1, 1,
0, 1, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1,
1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0,
0, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 1,
0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0,
0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1,
1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0,
0, 1, 1, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1};
int a, b;
int main() {
scanf("%d %d", &a, &b);
printf("%d", dizi[33 * a + b]);
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e3 + 5;
const int INF = 0x3f3f3f3f;
struct triple {
int a, b, c;
bool operator<(const triple &rhs) const {
if (a != rhs.a) return a < rhs.a;
if (b != rhs.b) return b < rhs.b;
return c < rhs.c;
}
};
int N;
unordered_map<int, vector<int> > hor, ver;
vector<triple> H, V;
map<triple, int> idHor, idVer;
int match[MAXN], dist[MAXN];
vector<int> adj[MAXN];
vector<triple> ansHor, ansVer;
bool coverHor[MAXN], coverVer[MAXN];
bool bio[MAXN];
void load() {
scanf("%d", &N);
while (N--) {
int x, y;
scanf("%d%d", &x, &y);
ver[x].push_back(y);
hor[y].push_back(x);
}
}
bool bfs() {
queue<int> Q;
for (int i = 1; i <= H.size(); i++)
if (!match[i]) {
dist[i] = 0;
Q.push(i);
} else
dist[i] = INF;
dist[0] = INF;
while (!Q.empty()) {
int x = Q.front();
Q.pop();
if (!x) continue;
for (auto it : adj[x])
if (dist[match[it]] == INF) {
dist[match[it]] = dist[x] + 1;
Q.push(match[it]);
}
}
return dist[0] != INF;
}
bool dfs(int x) {
if (!x) return true;
for (auto it : adj[x])
if (dist[match[it]] == dist[x] + 1 && dfs(match[it])) {
match[it] = x;
match[x] = it;
return true;
}
dist[x] = INF;
return false;
}
int hopcroft_karp() {
int matching = 0;
while (bfs())
for (int i = 1; i <= H.size(); i++) matching += !match[i] && dfs(i);
return matching;
}
void work(int lvl, vector<int> c, vector<triple> &where, map<triple, int> &id) {
sort(c.begin(), c.end());
for (int i = 1; i < c.size(); i++) {
id[{lvl, c[i - 1], c[i]}] = where.size();
where.push_back({lvl, c[i - 1], c[i]});
}
}
bool range(int x, int y, int z) { return x > y && x < z; }
bool intersect(triple h, triple v) {
return range(h.a, v.b, v.c) && range(v.a, h.b, h.c);
}
void go(int x) {
bio[x] = true;
coverHor[x - 1] = false;
for (auto it : adj[x])
if (it != match[x]) {
coverVer[it - (int)H.size() - 1] = true;
assert(match[it]);
if (!bio[match[it]]) go(match[it]);
}
}
void construct(int lvl, vector<int> c, vector<triple> &ans, bool *cover,
map<triple, int> &id) {
sort(c.begin(), c.end());
int lst = c[0];
for (int i = 1; i < c.size(); i++)
if (cover[id[{lvl, c[i - 1], c[i]}]]) {
ans.push_back({lvl, lst, c[i - 1]});
lst = c[i];
}
ans.push_back({lvl, lst, c.back()});
}
void solve() {
for (auto it : hor) work(it.first, it.second, H, idHor);
for (auto it : ver) work(it.first, it.second, V, idVer);
for (int i = 0; i < H.size(); i++)
for (int j = 0; j < V.size(); j++)
if (intersect(H[i], V[j])) adj[i + 1].push_back(H.size() + j + 1);
hopcroft_karp();
memset(coverHor, true, sizeof coverHor);
for (int i = 1; i <= H.size(); i++)
if (!match[i] && !bio[i]) go(i);
for (auto it : hor) construct(it.first, it.second, ansHor, coverHor, idHor);
for (auto it : ver) construct(it.first, it.second, ansVer, coverVer, idVer);
printf("%d\n", ansHor.size());
for (auto it : ansHor) printf("%d %d %d %d\n", it.b, it.a, it.c, it.a);
printf("%d\n", ansVer.size());
for (auto it : ansVer) printf("%d %d %d %d\n", it.a, it.b, it.a, it.c);
}
int main() {
load();
solve();
return 0;
}
| 12 | CPP |
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdlib>
using namespace std;
#define ALL(c) c.begin(),c.end()
#define RALL(c) c.rbegin(),c.rend()
#define SORT(x) sort((x).begin(),(x).end())
#define REP(i,x,y) for(int i=(x);i<(y);++i)
#define MP(a,b) make_pair((a),(b))
#define debug(x) #x << "=" << (x)
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif
typedef long long int ll;
typedef pair<int,int> pii;
//template<typename T> using vec=std::vector<T>;
const int INF=1<<30;
const long long int INF_=1LL<<58;
const double EPS=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
os << "[";
for (const auto &v : vec) {
os << v << ",";
}
os << "]";
return os;
}
int N;
pii w[100000],s[100000];
bool Check(int d){
int a[100000],b[100000];
fill_n((int*)a,100000,0);
fill_n((int*)b,100000,0);
int mi=w[0].first,mx=w[N-1].first;
REP(i,0,N){
if(abs(mi-w[i].first)>d&&abs(mx-w[i].first)>d) return false;
if(abs(mi-w[i].first)>d) a[w[i].second]=2;
if(abs(mx-w[i].first)>d) a[w[i].second]=1;
}
mi=s[0].first;
mx=s[N-1].first;
REP(i,0,N){
if(abs(mi-s[i].first)>d&&abs(mx-s[i].first)>d) return false;
if(abs(mi-s[i].first)>d) b[s[i].second]=2;
if(abs(mx-s[i].first)>d) b[s[i].second]=1;
}
int both=0,either=0;
REP(i,0,N){
if(a[i]==0||b[i]==0) ++both;
else if(a[i]!=b[i]) ++either;
}
return either==0||both+either==N;
}
void Solve(){
cin >> N;
REP(i,0,N){
int x,y;
cin >> x >> y;
w[i]=MP(x+y,i);
s[i]=MP(x-y,i);
}
sort(s,s+N);
sort(w,w+N);
int lb=0,ub=600000;
while(true){
if(ub-lb<=1){
if(Check(lb)) ub=lb;
break;
}
int mid=(lb+ub)/2;
if(Check(mid)) ub=mid;
else lb=mid;
}
cout << ub << endl;
}
int main(){
std::ios::sync_with_stdio(false);
std::cin.tie(0);
Solve();
return 0;
} | 0 | CPP |
#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using namespace std;
const int N = 2502;
int n;
ll operator^(const pair<int, int> &A, const pair<int, int> &B) {
return A.first * 1LL * B.second - A.second * 1LL * B.first;
}
pair<int, int> operator-(const pair<int, int> &A, const pair<int, int> &B) {
return pair<int, int>(A.first - B.first, A.second - B.second);
}
bool ccw(const pair<int, int> &A, const pair<int, int> &B,
const pair<int, int> &C) {
return ((B - A) ^ (C - A)) > 0;
}
pair<int, int> p[N << 1];
ll res = 0;
void solve(const pair<int, int> &O) {
sort(p + 1, p + n, [&](const pair<int, int> &A, const pair<int, int> &B) {
if (A.second >= O.second && B.second < O.second) return 1;
if (B.second >= O.second && A.second < O.second) return 0;
return (ccw(O, A, B) ? 1 : 0);
});
for (int i = (n); i <= (2 * n - 2); ++i) p[i] = p[i - n + 1];
ll num = 0;
for (int i = 1, j = 1; i < n; i++) {
if (j < i) j = i;
while (j < 2 * n - 2 && ccw(O, p[i], p[j + 1])) j++;
num += (j - i) * (j - i - 1) / 2;
}
res += (n - 1) * 1LL * (n - 2) * (n - 3) / 6 - num;
}
pair<int, int> po[N];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n;
for (int i = (1); i <= (n); ++i) cin >> po[i].first >> po[i].second;
for (int i = (1); i <= (n); ++i) {
int np = 0;
for (int j = (1); j <= (n); ++j)
if (i != j) p[++np] = po[j];
solve(po[i]);
}
cout << res * (n - 4) / 2;
return 0;
}
| 11 | CPP |
def li ():
return list (map (int, input ().split ()))
def num ():
return map (int, input ().split ())
def nu ():
return int (input ())
def find_gcd ( x, y ):
while (y):
x, y = y, x % y
return x
mm = 1000000007
def solve ():
t = 1
for tt in range (t):
n,l,r=num()
mn=[0]*n
cc=0
pp=1
while(cc<l):
mn[cc]=pp
pp*=2
cc+=1
ox=0
for i in range(cc,n):
mn[i]=1
mx=[0]*n
cc=0
pp=1
while(cc<r):
mx[cc]=pp
cc+=1
pp*=2
for i in range(cc,n):
mx[i]=pp//2
print(sum (mn),sum(mx))
if __name__ == "__main__":
solve () | 8 | PYTHON3 |
def check(n, p, m):
a = n - p*m
if a<=0:
return False
b = bin(a)[2:][:: -1]
l = len(b)
c = 0
res = 0
q = []
for i in range(l):
if b[i] == '1':
q += [2**i]
c += 1
res += max(0, 2**(i - 1))
d = c - m
if d > 0:
return False
if d == 0:
return True
if res + d > 0:
return True
def main():
n, p = [int(i) for i in input().split()]
ans = 10**4
for i in range(1, 10**4 + 1):
if(check(n, p, i)):
ans = i
break
if(ans == 10**4):
print(-1)
else:
print(ans)
main()
| 9 | PYTHON3 |
import sys
input=sys.stdin.readline
for _ in range(int(input())):
n=int(input())
a=[]
for i in range(n):
a.append(input())
flag=0
for i in range(n-1):
for j in range(n-1):
if a[i+1][j]=="0" and a[i][j+1]=="0" and a[i][j]=="1":
flag=1
print("YES" if flag==0 else "NO") | 11 | PYTHON3 |
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int f[11][11],b[11];
int main()
{
int n,m,i,j,k,ans=0;cin>>n>>m;int lim=(1<<n);
for (i=1;i<=m;i++)
{
cin>>k;
for (j=1;j<=k;j++) cin>>f[i][j];
}
for (i=1;i<=m;i++) cin>>b[i];
for (i=0;i<lim;i++)
{
int flg=1;
for (j=1;j<=m;j++)
{
int t=b[j];
for (k=1;k<=n;k++)
{
t^=((i>>(f[j][k]-1))&1);
}
if (t) {flg=0;break;}
}
if (flg) ans++;
}
cout<<ans;
}
| 0 | CPP |
rw = int(input())
for reqw in range(rw):
n = int(input())
for i in range(n):
print(i + 1, end = ' ')
print('')
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char *s) { return to_string(string(s)); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
bool first = true;
string res = "{";
for (const auto &x : v) {
if (!first) {
res += ", ";
}
first = false;
res += to_string(x);
}
res += "}";
return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
cerr << " " << to_string(H);
debug_out(T...);
}
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int> >;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using ld = long double;
mt19937_64 rnd((unsigned long)chrono::high_resolution_clock::now()
.time_since_epoch()
.count());
const int MOD = 1e9 + 7;
const int MAXN = 1e5 + 9;
int n;
vvi gg;
vi sSize;
void dfs(int v, int p = -1) {
if (p != -1 && (gg[v]).size() == 1) sSize[v] = 1;
for (auto to : gg[v]) {
if (to == p) continue;
dfs(to, v);
sSize[v] += sSize[to];
}
}
void input() {
cin >> n;
if (n == 1) {
cout << 1 << endl;
exit(0);
}
gg.resize(n);
sSize.resize(n);
for (int i = 1; i < n; i++) {
int x;
cin >> x;
x--;
gg[i].push_back(x);
gg[x].push_back(i);
}
}
void solve() {
dfs(0);
sort((sSize).begin(), (sSize).end());
for (int i = 0; i < n; i++) cout << sSize[i] << ' ';
cout << endl;
}
int main() {
input();
solve();
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
string s;
int main() {
cin >> s;
for (int i = 0; i < s.length() - 1; i++) {
if (s[i] == 'b' && s[i + 1] == 'a')
cout << "1 ";
else if (s[i] == 'a' && s[i + 1] == 'b')
cout << "1 ";
else
cout << "0 ";
}
if (s[s.length() - 1] == 'a')
cout << "1";
else
cout << "0";
}
| 9 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int lim = 2e5 + 10;
int n;
int ft[lim] = {};
int A[lim] = {};
int B[lim] = {};
int C[lim] = {};
int rmq(int pos) {
int ans = 0;
for (; pos; pos -= (pos & (-pos))) {
ans += ft[pos];
}
return ans;
}
void update(int pos, int val) {
for (; pos <= n; pos += (pos & (-pos))) {
ft[pos] += val;
}
}
int find(int pos) {
int ans;
int l = 1, r = n + 1;
int m;
while (l < r) {
m = (l + r) / 2;
if (rmq(m) >= pos) {
r = m;
} else {
l = m + 1;
}
}
return l;
}
void init() {
for (int i = 1; i <= n; ++i) {
update(i, 1);
}
}
int main() {
scanf("%d", &n);
init();
for (int i = n - 1; i >= 0; --i) {
int X;
scanf("%d", &X);
int ans = rmq(X + 1);
A[i] = ans - 1;
update(X + 1, -1);
}
init();
for (int i = n - 1; i >= 0; --i) {
int X;
scanf("%d", &X);
int ans = rmq(X + 1);
B[i] = ans - 1;
update(X + 1, -1);
}
for (int i = 0; i < n; ++i) {
int X = A[i] + B[i];
C[i] = X % (i + 1);
A[i + 1] += X / (i + 1);
}
init();
for (int i = n - 1; i >= 0; --i) {
int pos = find(C[i] + 1);
printf("%d ", pos - 1);
update(pos, -1);
}
}
| 10 | CPP |
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <queue>
#include <vector>
using namespace std;
constexpr static int MAXN = 100 + 10;
constexpr static int MAXC = 100 * 100 + 10;
int n;
int a[MAXN], b[MAXN];
bool valid[MAXN][MAXC];
int dp[MAXN][MAXC];
void solve() {
cin >> n;
valid[0][0] = true;
for (int i = 0; i < n; i++) {
cin >> a[i] >> b[i];
for (int k = i; k >= 0; k--) {
for (int j = MAXC - a[i] - 1; j >= 0; j--) {
if (valid[k][j]) {
dp[k + 1][j + a[i]] = max(dp[k + 1][j + a[i]], dp[k][j] + b[i]);
valid[k + 1][j + a[i]] = true;
}
}
}
}
int total = 0;
for (int i = 0; i < n; i++)
total += b[i];
vector <double> res(n);
for (int k = 1; k <= n; k++) {
for (int j = 0; j < MAXC; j++) {
if (valid[k][j]) {
double val = dp[k][j] + 0.5 * (total - dp[k][j]);
res[k - 1] = max(res[k - 1], min(val, 1.0 * j));
}
}
}
cout << fixed << setprecision(10);
for (int i = 0; i < n; i++)
cout << res[i] << (i + 1 == n ? '\n' : ' ');
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
}
| 8 | CPP |
n,m=map(int,input().split())
k=n%m
j=(n-k)//m
total=0
actual=0
for i in range(1,m+1):
for l in range(1,m+1):
if (i**2+l**2)%m==0:
total+=1
if 0<i<=k and 0<l<=k:
actual+=(j+1)**2
elif 0<i<=k or 0<l<=k:
actual+=j*(j+1)
else:
actual+=j**2
if k==0:
print(j**2*total)
else:
print(actual) | 8 | PYTHON3 |
#include<bits/stdc++.h>
using namespace std;
int main(){
int h,w; cin >>h >>w;
char s[h][w];
for(int i=0;i<h;i++){
for(int j=0;j<w;j++){
cin>>s[i][j];
}
}
for(int i=0;i<h;i++){
for(int j=0;j<w;j++){
if(s[i][j]=='#'){
if(s[i-1][j]!='#'&&s[i+1][j]!='#'&&s[i][j-1]!='#'&&s[i][j+1]!='#'){
cout<<"No"<<endl;
return 0;
}
}
}
}
cout<<"Yes"<<endl;
} | 0 | CPP |
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
//#include <unordered_set>
#include <set>
using namespace std;
char field[1001][1001];
bool used[1001][1001];
int main(){
int H,W;
while(cin>>H>>W&&(H|W)){
for(int i=0;i<H;i++)
for(int j=0;j<W;j++)
cin>>field[i][j];
vector<string> vs;
for(int dy=-1;dy<=1;dy++){
for(int dx=-1;dx<=1;dx++){
if(dy==0&&dx==0)continue;
memset(used,0,sizeof(used));
for(int i=0;i<H;i++){
for(int j=0;j<W;j++){
if(!(i==0||j==0||i==H-1||j==W-1))continue;
int cx=j;
int cy=i;
string s;
if(used[cy][cx])continue;
while(1){
used[cy][cx]=true;
s+=field[cy][cx];
cy+=dy;cx+=dx;
cy=(cy+H)%H;
cx=(cx+W)%W;
if(used[cy][cx])break;
}
vs.push_back(s);
//cout<<s<<endl;
}
}
}
}
//unordered_set<string> us;
set<string> us;
string cand;
for(int i=0;i<(int)vs.size();i++){
for(int j=0;j<(int)vs[i].size();j++){
for(int k=1;k<=(int)vs[i].size();k++){
string s;
for(int l=0;l<k;l++){
s+=vs[i][(j+l)%vs[i].size()];
}
if(us.count(s)==1){
if(cand==""||cand.size()<s.size())
cand=s;
else if(cand.size()==s.size()&&cand>s)
cand=s;
}
else if(us.count(s)==0)
us.insert(s);
}
}
}
if(cand.size()>1)cout<<cand<<endl;
else cout<<0<<endl;
}
return 0;
} | 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
char VOWELS[6] = {'A', 'E', 'I', 'Y', 'O', 'U'};
int diff = 'a' - 'A';
bool isVowel(char c) {
for (int i = 0; i < 6; i++) {
if (c == VOWELS[i] || c == (VOWELS[i] + diff)) {
return true;
}
}
return false;
}
char toLower(char c) { return (c >= 'A' && c <= 'Z') ? (c + diff) : c; }
int main(int argc, char const *argv[]) {
char c;
while ((c = getchar()) != '\n') {
if (!isVowel(c)) {
cout << "." << toLower(c);
}
}
cout << endl;
return 0;
}
| 7 | CPP |
s = input()
counter = 0
counter1 = 0
for i in s:
if i.isupper() == True :
counter += 1
else:
counter1 += 1
if counter > counter1:
print(s.upper())
else:
print(s.lower())
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n,k,sum=0;
cin>>n>>k;
int a[n];
for(int i=0;i<n;i++) cin>>a[i];
sort(a,a+n);
for(int i=0;i<k;i++) sum+=a[i];
cout<<sum;
return 0;
}
| 0 | CPP |
number_of_rocks = int(input())
rocks = str(input())
number_of_deletion = 0
for i in range(number_of_rocks):
if i == number_of_rocks - 1:
break
elif rocks[i] == rocks[i + 1]:
number_of_deletion += 1
print(number_of_deletion)
| 7 | PYTHON3 |
Subsets and Splits