solution
stringlengths 10
159k
| difficulty
int64 0
3.5k
| language
stringclasses 2
values |
---|---|---|
for _ in range(int(input())):
lst = [int(i) for i in input().split()]
if lst[2] == lst[0]+lst[1]:
print(lst[0], lst[1], lst[3])
else:
print(lst[0], lst[1], lst[2])
| 800 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int h, g, c, n, m, k, l, a[140] = {};
string s;
cin >> s;
n = s.length();
for (int i = 0; i < s.length(); i++) a[s[i]]++;
int res = 0;
for (int i = 0; i <= 139; i++)
if (a[i] > 0) {
res++;
}
if ((res < 2) || (n < 4) || (res > 4)) {
printf("No");
return 0;
}
int kol = res;
if (res == 4) {
printf("Yes");
return 0;
}
res = 0;
for (int i = 0; i <= 139; i++)
if (a[i] > 1) {
res++;
}
if ((kol == 3) && (res > 0)) {
printf("Yes");
return 0;
}
if ((kol == 2) && (res > 1)) {
printf("Yes");
return 0;
}
printf("No");
}
| 1,400 | CPP |
x=int(input())
ans=0
i=0
while ans<x:
ans+=5
i+=1
print(i)
| 800 | PYTHON3 |
R = lambda: map(int, input().split())
for _ in range(int(input())):
n = int(input())
L = list(R())
k = n-1
i = 1
v = [0]*(n-1)
while k and i < n:
ind = L.index(i)
for j in reversed(range(ind)):
if k > 0:
if v[j] == 0 and L[j] > i:
v[j] = 1
L[j],L[j+1] = L[j+1],L[j]
k -= 1
else:break
i += 1
print(*L) | 1,400 | PYTHON3 |
cases = int(input())
for t in range(cases):
n,x = list(map(int,input().split()))
a = list(map(int,input().split()))
s = 0
f = 0
for i in a:
s+=i
f += i%x==0
# s = sum(a)
# f = sum([i%x==0 for i in a])
if f==n:
print(-1)
else:
if s%x != 0:
print(n)
else:
l = n+1
r = -1
for i in range(n//2+1):
low = i
high = n-i-1
if low <= high:
if a[low]%x != 0:
l = min(l,low)
if a[high]%x != 0:
r = max(r,n-i-1)
print(max(n-l-1,r))
| 1,200 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
inline bool iseq(double x, double y) {
if (fabs(x - y) < 1e-8) return true;
return false;
}
template <typename T>
inline T hpt(T x1, T y1, T x2, T y2) {
return hypot(x1 - x2, y1 - y2);
}
template <typename T>
inline T gcd(T a, T b) {
if (!b)
return a;
else
return gcd(b, a % b);
}
template <typename T>
inline void extended_euclid(T a, T b, T &x, T &y) {
if (a % b == 0)
x = 0, y = 1;
else {
extended_euclid(b, a % b, x, y);
T temp = x;
x = y;
y = -y * (a / b) + temp;
}
}
template <typename T>
inline T bigmod(T b, T p, T m) {
if (!p)
return 1;
else if (!(p % 2)) {
T x = bigmod(b, p / 2, m);
return x * x;
} else
return ((b % m) * bigmod(b, p - 1, m)) % m;
}
int prime[105 / 32 + 1];
void setbit(int i) {
int p = i >> 5, q = i & 31;
prime[p] |= (1 << q);
}
bool checkbit(int i) {
int p = i >> 5, q = i & 31;
return prime[p] & (1 << q) ? true : false;
}
void buildprime(int n) {
int i, j, k = sqrt(double(n));
prime[0] = 3;
for (i = 4; i < n; i += 2) setbit(i);
for (i = 3; i <= k; i += 2) {
if (!checkbit(i)) {
int ii = i + i;
for (j = i * i; j < n; j += ii) setbit(j);
}
}
}
int sum, r, n, N, R, C, t, txt, m;
int main() {
int i, j, k;
buildprime(105 - 1);
while (scanf("%d%d", &n, &m) == 2) {
for (j = n + 1;; j++)
if (!checkbit(j)) break;
if (j != m)
printf("NO\n");
else
printf("YES\n");
}
return 0;
}
| 800 | CPP |
t = int(input())
for _ in range(t):
n = int(input())
prev_p = 0
prev_c = 0
invalid = False
for _ in range(n):
p,c = map(int,input().split())
if p<prev_p or c<prev_c or c>p or (p-prev_p)<(c-prev_c):
invalid = True
prev_p = p
prev_c = c
if invalid:
print ("NO")
else:
print ("YES") | 1,200 | PYTHON3 |
t = int(input())
for _ in range(t):
x = int(input())
q, r = divmod(x, 7)
if r == 1:
print(q + 2)
else:
print(q + 1) | 800 | PYTHON3 |
from sys import stdin, stdout
import math,sys,heapq
from itertools import permutations, combinations
from collections import defaultdict,deque,OrderedDict
from os import path
import random
import bisect as bi
def yes():print('YES')
def no():print('NO')
if (path.exists('input.txt')):
#------------------Sublime--------------------------------------#
sys.stdin=open('input.txt','r');sys.stdout=open('output.txt','w');
def I():return (int(input()))
def In():return(map(int,input().split()))
else:
#------------------PYPY FAst I/o--------------------------------#
def I():return (int(stdin.readline()))
def In():return(map(int,stdin.readline().split()))
#sys.setrecursionlimit(1500)
def dict(a):
d={}
for x in a:
if d.get(x,-1)!=-1:
d[x]+=1
else:
d[x]=1
return d
def find_gt(a, x):
'Find leftmost value greater than x'
i = bi.bisect_left(a, x)
if i != len(a):
return i
else:
return -1
def main():
try:
dp=1
n=I()
ans=1
for i in range(1,n):
ans+=(dp+2)
dp+=2
print(ans*2-((n*2)-1))
except:
pass
M = 998244353
P = 1000000007
if __name__ == '__main__':
#for _ in range(I()):main()
for _ in range(1):main() | 800 | PYTHON3 |
print('+'.join([str(x) for x in sorted(list(map(int, input().split('+'))))])) | 800 | PYTHON3 |
def gcd(a,b):
if a>b:
return gcd(b,a)
if a == 0:
return b
return gcd(b%a,a)
q = int(input())
for i in range(q):
n = int(input())
lol = list(map(int,input().split()))
lol.sort(reverse = True)
x,a = map(int,input().split())
y,b = map(int,input().split())
if x<y:
x,y = y,x
a,b = b,a
k = int(input())
ans = 0
l,r = 0,n
baaa = a*b//gcd(a,b)
m = n
kol = 0
for i in range(m // baaa):
ans += lol[i] * (x + y) // 100
for j in range(m // baaa, m // a):
ans += lol[j] * x // 100
kol += 1
for j in range(m // baaa+kol, m // b+kol):
ans += lol[j] * y // 100
if k > ans:
print(-1)
else:
l, r = 0, n
while r-l>1:
kol = 0
m = (l+r)//2
ans = 0
for i in range(m//baaa):
ans+=lol[i]*(x+y)//100
for j in range(m//baaa,m//a):
ans+=lol[j]*x//100
kol += 1
for p in range(m//baaa+kol,m//b+kol):
ans+=lol[p]*y//100
#print(m,ans,baaa)
if k>ans:
l = m
else:
r = m
print(r)
| 1,600 | PYTHON3 |
if __name__ == '__main__':
t = int(input())
for i in range(t):
n = int(input())
arr = list(map(int, input().split()))
height = 1
previous = None
for i in arr:
if previous is not None:
if previous and i==1:
height+=5
elif previous and i==0:
height+=0
elif not previous and i==1:
height+=1
elif not previous and i==0:
height=-1
break
else:
if i==1:
height+=1
else:
height+=0
previous=i
print(height)
| 800 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
int n, k, cnt[N], mn = INT_MAX;
int main() {
cin.tie(0), ios::sync_with_stdio(0);
cin >> n >> k;
for (int i = 1; i <= n; i++) {
int u;
cin >> u;
mn = min(mn, u);
cnt[max(1, u - k)]++;
cnt[u + 1]--;
}
for (int i = 1; i <= N - 5; i++) cnt[i] += cnt[i - 1];
for (int i = mn; i > k; i--) {
int sum = 0;
for (int j = i; j <= N - 5; j += i) sum += cnt[j];
if (sum == n) {
cout << i << "\n";
exit(0);
}
}
cout << mn << "\n";
}
| 2,100 | CPP |
n = int(input())
downs = []
ups = []
for i in range(n):
a, b = map(int, input().split())
if a < b:
ups.append([a, b, i + 1])
else:
downs.append([a, b, i + 1])
if len(ups) >= len(downs):
ups.sort(key=lambda x: x[0], reverse=True)
ans = []
for a, b, i in ups:
ans.append(i)
print(len(ans))
print(*ans)
else:
downs.sort(key=lambda x: x[1])
ans = []
for a, b, i in downs:
ans.append(i)
print(len(ans))
print(*ans) | 1,800 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int ans = 0;
int n, k;
cin >> n >> k;
for (int i = 0; i < n; i++) {
string s;
cin >> s;
set<int> R;
for (int j = 0; j < s.size(); j++) {
if ((int)(s[j] - '0') <= k) R.insert((int)(s[j] - '0'));
}
if (R.size() == k + 1) ans++;
}
cout << ans << endl;
;
}
| 1,100 | CPP |
n,k=map(int,input().split())
a=list(map(int,input().split()))
d=sum(a[0:k])
r=[d]
for i in range(n-k):
d=d-a[i]+a[i+k]
r.append(d)
print(r.index(min(r))+1) | 1,100 | PYTHON3 |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const int MAX = 2e5 + 5;
const long long MAX2 = 11;
const long long MOD = 1000000007;
const long long MOD2 = 1000000006;
const long long INF = 2e18;
const int dr[] = {1, 0, -1, 0, 1, 1, -1, -1, 0};
const int dc[] = {0, 1, 0, -1, 1, -1, 1, -1, 0};
const double pi = acos(-1);
const double EPS = 1e-9;
const int block = 2000;
int n, x[MAX], cnt;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
for (int i = 1; i <= n; ++i) cin >> x[i], cnt += x[i] & 1;
if (cnt && cnt != n) sort(x + 1, x + 1 + n);
for (int i = 1; i <= n; ++i) cout << x[i] << ' ';
return 0;
}
| 1,200 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<pair<int, int>> fragments(n);
for (int i = 0; i < n; i++) {
fragments[i].first = i;
cin >> fragments[i].second;
}
sort(fragments.begin(), fragments.end(),
[](pair<int, int> p1, pair<int, int> p2) {
return p1.second < p2.second;
});
long long cost = 0;
for (int i = 1; i < n; i++) {
cost += abs(fragments[i].first - fragments[i - 1].first);
}
cout << cost << endl;
return 0;
}
| 1,200 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long int const delta = 1000000007;
long long int dphigh[(long long int)1e5 + 8];
long long int dplow[(long long int)1e5 + 8];
long long int high[(long long int)1e5 + 8];
long long int low[(long long int)1e5 + 8];
long long int anss[(long long int)1e5 + 8];
int main() {
std::ios::sync_with_stdio(0);
;
cin.tie(0);
cout.tie(0);
long long int n;
cin >> n;
long long int a[n];
for (long long int i = 0; i < n; i++) {
cin >> a[i];
high[i] = a[i];
low[i] = a[i];
}
dphigh[0] = 0;
for (long long int i = 1; i < n; i++) {
if (a[i] > high[i - 1]) {
dphigh[i] = dphigh[i - 1];
} else {
dphigh[i] = dphigh[i - 1] + (high[i - 1] - a[i] + 1);
high[i] += (high[i - 1] - a[i] + 1);
}
}
dplow[n - 1] = 0;
anss[n - 1] = dphigh[n - 1];
if (n > 1) {
dplow[n - 2] = max((long long int)0, a[n - 1] - a[n - 2] + 1);
anss[n - 2] = dphigh[n - 2];
}
for (long long int i = n - 3; i >= 0; i--) {
long long int a1 = a[i + 1];
long long int a2 = low[i + 2];
long long int a3 = high[i];
if (a[i + 1] > low[i + 2]) {
dplow[i + 1] = dplow[i + 2];
} else {
dplow[i + 1] = dplow[i + 2] + low[i + 2] - a[i + 1] + 1;
low[i + 1] += (low[i + 2] - a[i + 1] + 1);
}
anss[i] = dphigh[i] + dplow[i + 1];
if (high[i] == low[i + 1]) {
anss[i]++;
}
}
long long int ans = (long long int)1e18 + 8;
for (long long int i = 0; i < n; i++) {
ans = min(ans, anss[i]);
}
cout << ans;
return 0;
}
| 1,600 | CPP |
n,m = map(int, input().split())
a = [int(s) for s in input().split()]
a = sorted(a)
current = a[n-1]
k = 0
if n==1:
print(0)
exit()
for i in range(n-1,-1,-1):
if i>0 and a[i-1]<current-1:
a[i]-=(current-1)-a[i-1]
k+=a[i]-1
current = a[i-1]
else:
if a[i]>=current:
k+=a[i]-current
if i!=0:
k+=max(current-1,0)
current-=1
current = max(current,1)
print(k)
| 1,400 | PYTHON3 |
length=int(input())
digits=input()
zeros=0
ones=0
for i in range(0,length,1):
if digits[i] =="0":
zeros+=1
elif digits[i] == "1":
ones+=1
if zeros > ones:
zeros=ones
count=length-(zeros+ones)
print (count)
else:
ones=zeros
count=length-(zeros+ones)
print (count)
| 900 | PYTHON3 |
n, k=map(int, input().split())
l=input()
a=[int(i) for i in l.split()]
m=list(range(1,n+1))
l=""
b=0
d=len(m)
for i in a:
if m[(i+b)%d]==m[len(m)-1]:
l+="{} ".format(m[(i+b)%d])
m.remove(m[(i+b)%d])
b=0
else:
l+="{} ".format(m[(i+b)%d])
m.remove(m[(i+b)%d])
b=m.index(m[(i+b)%d])
d=len(m)
print(l)
| 1,300 | PYTHON3 |
#include <bits/stdc++.h>
int F, R, C, K, RR[101], CC[101];
int main() {
scanf("%d%d%d", &R, &C, &K);
F = 0;
for (int(x) = (1); (x) <= (K); (x) += (1)) scanf("%d%d", &RR[x], &CC[x]);
for (int(x) = (1); (x) <= (K); (x) += (1))
if (RR[x] - 4 <= 1 || RR[x] + 4 >= R || CC[x] - 4 <= 1 || CC[x] + 4 >= C)
F = 1;
if (F == 0)
printf("NO");
else
printf("YES");
}
| 1,900 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int MAXL = 3e5 + 50;
int fail[MAXL], nxt[MAXL][26];
void findFailure(const string &P) {
fail[1] = 0;
int k = 0;
for (int i = 1; i < (int)P.size(); i++) {
while (k && P[i] != P[k]) k = fail[k];
if (P[i] == P[k]) k++;
fail[i + 1] = k;
}
for (int i = 0; i < (int)P.size(); i++)
for (int x = 0; x < 26; x++)
nxt[i][x] = (P[i] - 'a' == x) ? i + 1 : (i ? nxt[fail[i]][x] : 0);
}
const int MAXN = 1e5 + 50;
vector<int> adj[MAXN];
int p[MAXN], n;
string s[MAXN], t;
void readInput() {
cin >> n;
for (int i = 2; i <= n; i++) {
cin >> p[i] >> s[i];
adj[p[i]].push_back(i);
}
cin >> t;
}
int cnt = 0;
void dfs(int v, int pos = 0) {
for (auto c : adj[v]) {
int k = pos;
for (char x : s[c]) {
k = nxt[k][x - 'a'];
if (k == (int)t.size()) cnt++, k = fail[k];
}
dfs(c, k);
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
readInput();
findFailure(t);
dfs(1);
cout << cnt << endl;
}
| 2,000 | CPP |
for _ in range(int(input())):
n=int(input())
s=map(int,input().split())
s=list(s)
#for i,x in enumerate(s):
i=0
while i!=n:
if s[i]<i:
break
i+=1
#for j in range(n-1,-1,-1):
j=n-1
while j!=-1:
if s[j]<n-1-j:
break
j-=1
i-=1
j+=1
#print(i,j)
if i<j:
print('No')
else:
print('Yes') | 1,300 | PYTHON3 |
a=int(input())
b=list(input())
c=0
for j in b:
if j=='+':
c+=1
elif j=='-' and c>0:
c-=1
print(c) | 800 | PYTHON3 |
n = int(input())
x = 0
for i in range(0, n):
z = input()
if z[1] == "+":
x += 1
else:
x -= 1
print(x)
| 800 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1 << 28;
const double INF = 1e12, EPS = 1e-9;
void run() {
string s;
cin >> s;
int ans = 0;
while (!s.empty()) {
int p = 0;
for (; p < 5 && p < (int)s.size() && s[p] == s[0]; p++)
;
ans++;
s = s.substr(p);
}
cout << ans << endl;
}
int main() { run(); }
| 900 | CPP |
#include <bits/stdc++.h>
using namespace std;
struct ele {
int to, val;
};
ele a[100001];
int cmp(ele a, ele b) { return a.val < b.val; }
int n;
int sum = 0;
vector<int> voter[100001], v;
int len = 0;
int jundge(int x) {
int total = 0;
int need = x - sum;
v.clear();
for (int i = 1; i <= len; i++) {
for (int j = 0; j < voter[i].size(); j++) {
if (voter[i].size() - j >= x) {
total += voter[i][j];
need--;
} else {
v.push_back(voter[i][j]);
}
}
}
sort(v.begin(), v.end());
for (int i = 0; i < need; i++) {
total += v[i];
}
return total;
}
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
int to, val;
cin >> to >> val;
if (to == 0) {
sum++;
} else {
voter[to].push_back(val);
len = max(len, to);
}
}
for (int i = 1; i <= len; i++) {
sort(voter[i].begin(), voter[i].end());
}
int l = 0, r = n;
while (r - l > 1) {
int mid = (l + r) >> 1;
int mmid = (mid + r) >> 1;
int sum1 = jundge(mid);
int sum2 = jundge(mmid);
if (sum1 >= sum2) {
l = mid;
} else {
r = mmid;
}
}
int Min = jundge(l);
cout << Min << endl;
return 0;
}
| 2,100 | CPP |
#include <bits/stdc++.h>
using namespace std;
const long long int N = 1e5;
long long int i, j, k;
int main() {
long long int p, k, a, b, c;
cin >> a >> b >> c;
k = (a - b) * c;
p = ceil((float)k / b);
cout << p;
}
| 1,000 | CPP |
#include <bits/stdc++.h>
using namespace std;
vector<string> split(string s, string border);
struct node {
vector<node*> links;
long long id;
bool was = false;
};
void solve() {
long long n;
cin >> n;
vector<vector<long long>> c(3, vector<long long>(n));
for (long long color = 0; color < (3); color++) {
for (long long i = 0; i < (n); i++) {
cin >> c[color][i];
}
}
vector<node*> tree(n);
for (long long i = 0; i < (n); i++) tree[i] = new node;
for (long long i = 0; i < (n); i++) tree[i]->id = i;
for (long long i = 0; i < (n - 1); i++) {
long long v;
cin >> v;
long long u;
cin >> u;
tree[--v]->links.push_back(tree[--u]);
tree[u]->links.push_back(tree[v]);
}
for (long long i = 0; i < (n); i++) {
if (tree[i]->links.size() >= 3) {
cout << -1;
return;
}
}
node* start;
for (long long i = 0; i < (n); i++) {
if (tree[i]->links.size() == 1) {
start = tree[i];
break;
}
}
long long ans = -1;
vector<long long> ans_v(n);
for (long long c1 = 0; c1 < (3); c1++) {
for (long long c2 = 0; c2 < (3); c2++) {
if (c1 == c2) continue;
long long c3 = 3 - c1 - c2;
vector<long long> colors = {c1, c2, c3};
for (long long i = 0; i < (n); i++) tree[i]->was = false;
vector<long long> ans_now_v(n);
long long sum = 0, pos = 0;
node* next = start;
while (1) {
next->was = true;
sum += c[colors[pos % 3]][next->id];
ans_now_v[next->id] = colors[pos % 3];
pos++;
bool find = false;
for (long long i = 0; i < (next->links.size()); i++) {
if (next->links[i]->was == false) {
next = next->links[i];
find = true;
break;
}
}
if (!find) {
break;
}
}
if (ans == -1 || sum < ans) {
ans = sum;
ans_v = ans_now_v;
}
}
}
cout << ans << '\n';
for (long long i = 0; i < (n); i++) {
cout << ans_v[i] + 1 << " ";
}
}
signed main(signed argc, char* argv[]) {
ios_base::sync_with_stdio(0);
cin.tie();
cout.setf(cout.fixed);
cout.precision(10);
if (argc > 1 && (string)argv[1] == "file") {
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
long long number_sample = 1;
do {
cout << "Sample #" << number_sample << ":" << '\n';
cerr << "Sample #" << number_sample << ":" << '\n';
solve();
number_sample++;
cout << '\n';
cerr << '\n';
} while (!cin.eof());
} else {
cerr.clear(ios_base::badbit);
solve();
}
}
vector<string> split(string s, string border) {
vector<string> ans;
long long pos_end;
while ((pos_end = s.find(border)) != string::npos) {
if (pos_end) ans.push_back(s.substr(0, pos_end));
s = s.substr(pos_end + border.size());
}
return ans;
}
| 1,800 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long max(long long a, long long b) { return a > b ? a : b; }
long long min(long long a, long long b) { return a < b ? a : b; }
double max(double a, double b) { return a > b ? a : b; }
double min(double a, double b) { return a < b ? a : b; }
long long modd(long long a) {
if (a < 0LL) return a * -1LL;
return a;
}
double modd(double a) {
if (a < 0.0) return a * -1.0;
return a;
}
long long modulo(long long a) { return a % 1000000007LL; }
long long power(long long k, long long p) {
if (p == 0) return 1LL;
long long P = power(k, p / 2LL);
P = (P * P) % 1000000007LL;
if (p % 2 == 1) P = (P * k) % 1000000007LL;
return P;
}
struct p_str {
long long val, idx;
char ch;
};
bool comp(p_str& a, p_str& b) { return a.val < b.val; }
void solve() {
string s;
cin >> s;
long long m;
cin >> m;
long long b[m];
for (long long i = 0; i < m; i++) {
cin >> b[i];
}
long long cnt[26];
memset(cnt, 0, sizeof(cnt));
for (long long i = 0; i < s.length(); i++) {
cnt[s[i] - 'a']++;
}
char t[m];
long long i_cnt = 26;
while (1) {
bool f = 1;
long long mn_i = -1;
for (long long i = 0; i < m; i++) {
if (b[i] == 0) {
mn_i = i;
f = 0;
break;
}
}
if (f) {
break;
}
vector<long long> zero_pos;
for (long long i = 0; i < m; i++) {
if (b[i] == 0) {
zero_pos.push_back(i);
}
}
long long c = zero_pos.size();
i_cnt--;
while (i_cnt >= 0 && cnt[i_cnt] < c) {
i_cnt--;
}
for (long long i = 0; i < zero_pos.size(); i++) {
t[zero_pos[i]] = (char)(i_cnt + 'a');
}
for (long long j = 0; j < zero_pos.size(); j++) {
long long pos = zero_pos[j];
for (long long i = 0; i < m; i++) {
if (b[i] > 0) {
b[i] -= modd(i - pos);
}
}
b[pos] = -1;
}
}
for (long long i = 0; i < m; i++) {
cout << t[i];
}
cout << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}
| 1,800 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
string n;
cin >> n;
cout << (n[n.length() - 1] - '0') % 2;
return 0;
}
| 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
char g[20][20];
int main() {
int n, m;
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i++) scanf("%s", g[i]);
int count = 0;
for (int i = 0; i < n; i++) {
bool can = 1;
for (int j = 0; j < m; j++)
if (g[i][j] == 'S') can = 0;
if (can)
for (int j = 0; j < m; j++) g[i][j] = '*', count++;
}
for (int j = 0; j < m; j++) {
bool can = 1;
for (int i = 0; i < n; i++)
if (g[i][j] == 'S') can = 0;
if (can)
for (int i = 0; i < n; i++)
if (g[i][j] != '*') count++;
}
printf("%d\n", count);
return 0;
}
| 800 | CPP |
#include <bits/stdc++.h>
using namespace std;
map<int, int> a, b;
int main() {
int n, m, k, v;
scanf("%d %d %d", &n, &m, &k);
for (int i = 0; i < n; i++) {
scanf("%d", &v);
if (a.count(v) == 0) a[v] = 0;
a[v]++;
}
for (int i = 0; i < m; i++) {
scanf("%d", &v);
if (b.count(v) == 0) b[v] = 0;
b[v]++;
}
map<int, int>::reverse_iterator ait;
map<int, int>::iterator it, it1;
bool ok = false;
for (ait = a.rbegin(); ait != a.rend() && !ok; ait++) {
it = b.lower_bound(ait->first);
int sum = 0;
for (; it != b.end();) {
sum += it->second;
it1 = it;
it1++;
b.erase(it);
it = it1;
}
if (sum < ait->second) {
ok = true;
} else if (sum > ait->second) {
b[ait->first] = sum - ait->second;
}
}
if (ok)
printf("YES\n");
else
printf("NO\n");
}
| 1,600 | CPP |
t=int(input())
for _ in range(t):
x=list(map(int,input().split()))
a=x[0]
b=x[1]
X=x[2]
Y=x[3]
y=[(a-X-1)*b,X*b,(b-Y-1)*a,Y*a]
print(max(y)) | 800 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e10;
const int N = 2e5 + 77;
long long tree[4 * N];
string type[N];
vector<long long> v;
map<long long, long long> assign, rev_assign;
multiset<long long> store[N];
struct point {
long long x, y;
point() {
x = 0;
y = 0;
}
} query[N];
void build(long long node, long long a, long long b) {
if (a == b) {
tree[node] = -inf;
return;
}
long long mid = (a + b) / 2;
build(2 * node, a, mid);
build(2 * node + 1, mid + 1, b);
tree[node] = max(tree[2 * node], tree[2 * node + 1]);
}
void update(long long node, long long a, long long b, long long ind,
long long val) {
if (a > b || a > ind || b < ind) return;
if (a == b) {
tree[node] = val;
return;
}
long long mid = (a + b) / 2;
update(2 * node, a, mid, ind, val);
update(2 * node + 1, mid + 1, b, ind, val);
tree[node] = max(tree[2 * node], tree[2 * node + 1]);
}
long long get(long long node, long long a, long long b, long long l,
long long r, long long val) {
if (a > b || a > r || b < l || tree[node] <= val) return -1;
if (a == b) return a;
long long mid = (a + b) / 2;
long long ans = get(2 * node, a, mid, l, r, val);
if (ans != -1) return ans;
return get(2 * node + 1, mid + 1, b, l, r, val);
}
int main() {
long long i, j, n, x, y, ctr = 0, hi, lo, mid;
scanf("%I64d", &n);
for (i = 1; i <= n; i++) {
cin >> type[i];
scanf("%I64d%I64d", &query[i].x, &query[i].y);
v.push_back(query[i].x);
}
ctr = 0;
sort(v.begin(), v.end());
for (i = 0; i < v.size(); i++) {
if (!assign[v[i]]) {
ctr++;
assign[v[i]] = ctr;
rev_assign[ctr] = v[i];
}
}
for (i = 1; i <= n; i++) query[i].x = assign[query[i].x];
build(1, 1, ctr);
for (i = 1; i <= n; i++) {
if (type[i] == "add") {
x = query[i].x;
y = query[i].y;
store[x].insert(y);
update(1, 1, ctr, x, *store[x].rbegin());
} else if (type[i] == "remove") {
x = query[i].x;
y = query[i].y;
store[x].erase(store[x].find(y));
if (!store[x].size())
update(1, 1, ctr, x, -inf);
else
update(1, 1, ctr, x, *store[x].rbegin());
} else {
x = query[i].x;
y = query[i].y;
hi = get(1, 1, ctr, x + 1, ctr, y);
if (hi == -1) {
cout << "-1" << endl;
continue;
}
printf("%I64d %I64d\n", rev_assign[hi], (*store[hi].upper_bound(y)));
}
}
return 0;
}
| 2,800 | CPP |
lista = list(map(int, input().split(" ")))
base = lista.pop(0)
lista.sort(key=int)
def cortes(lista,base):
if base%lista[0]==0:
return base//lista[0]
resp=0
respF=0
a=lista[0]
b=lista[1]
c=lista[2]
aCabe=(base//a)*a
bCabe=(base//b)*b
cCabe=(base//c)*c
aCabeR=0
bCabeR=b
cCabeR=0
i=0
while i<2000000:
i+=1
if aCabeR + bCabeR + cCabeR==base:
resp=aCabeR//a + bCabeR//b + cCabeR//c
if resp>respF:
respF=resp
aCabeR+=a
if aCabeR>aCabe:
aCabeR=0
bCabeR+=b
if a==b:
bCabeR=0
cCabeR+=c
if bCabeR>bCabe:
if b==c:
break
bCabeR=0
cCabeR+=c
return respF
print(cortes(lista,base)) | 1,300 | PYTHON3 |
a=int(input())
if(a%2==0):
print(a//2)
else:
d=(a//2)+1
print(-d) | 800 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i, ma = 0, indx1 = -1, indx2 = -1, sum = 0;
cin >> n;
map<pair<int, int>, vector<pair<int, int> > > map;
int arr[n][3];
for (i = 0; i < n; i++) {
cin >> arr[i][0] >> arr[i][1] >> arr[i][2];
sort(arr[i], arr[i] + 3);
map[make_pair(arr[i][1], arr[i][2])].push_back(make_pair(arr[i][0], i));
}
for (auto it = map.begin(); it != map.end(); it++) {
if ((it->second).size() == 1) {
if ((it->second)[0].first > ma) {
indx1 = (it->second)[0].second;
indx2 = -1;
ma = (it->second)[0].first;
}
} else {
int num = (it->first).first;
if (num > ma) {
sort((it->second).rbegin(), (it->second).rend());
int sum = (it->second)[0].first + (it->second)[1].first;
if (sum > num) {
ma = num;
indx1 = (it->second)[0].second;
indx2 = (it->second)[1].second;
} else {
if (sum > ma) {
ma = sum;
indx1 = (it->second)[0].second;
indx2 = (it->second)[1].second;
}
}
}
}
}
if (indx2 == -1) {
cout << "1"
<< "\n";
cout << indx1 + 1 << "\n";
} else {
cout << "2"
<< "\n";
cout << indx1 + 1 << " " << indx2 + 1 << "\n";
}
return 0;
}
| 1,600 | CPP |
# HEY STALKER
n = int(input())
l = list(map(int, input().split()))
k = list(map(int, input().split()))
ans = 0
for t in range(n):
z = 0
w = 0
for j in range(t, n):
z = z | l[j]
w = w | k[j]
ans = max(ans, z+w)
print(ans)
| 900 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int lg(long long n) {
assert(n > 0);
int ans = -1;
while (n) {
ans++;
n >>= 1;
}
return ans;
}
void solve() {
int n, m, k;
cin >> n >> m >> k;
vector<vector<int>> grid(n, vector<int>(m));
vector<vector<pair<int, int>>> pos(k);
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> grid[i][j];
grid[i][j]--;
pos[grid[i][j]].emplace_back(i, j);
}
}
auto inrange = [&](const pair<int, int> &p) {
return 0 <= p.first && p.first < n && 0 <= p.second && p.second < m;
};
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
vector<vector<vector<int>>> dist(k,
vector<vector<int>>(n, vector<int>(m, -1)));
auto bfs = [&](int col) {
vector<int> jump(k, 0);
queue<pair<int, int>> q;
for (auto p : pos[col]) {
q.push(p);
dist[col][p.first][p.second] = 0;
}
jump[col] = 1;
while (!q.empty()) {
auto [x, y] = q.front();
q.pop();
int cur = grid[x][y];
if (!jump[cur]) {
jump[cur] = true;
for (auto [i, j] : pos[cur]) {
if (dist[col][i][j] == -1) {
dist[col][i][j] = dist[col][x][y] + 1;
q.push(make_pair(i, j));
}
}
}
for (int i = 0; i < 4; i++) {
int nxtx = x + dx[i], nxty = y + dy[i];
if (inrange(make_pair(nxtx, nxty)) && dist[col][nxtx][nxty] == -1) {
dist[col][nxtx][nxty] = dist[col][x][y] + 1;
q.push(make_pair(nxtx, nxty));
}
}
}
};
for (int i = 0; i < k; i++) {
bfs(i);
}
int q;
cin >> q;
while (q--) {
int r1, c1, r2, c2;
cin >> r1 >> c1 >> r2 >> c2;
r1--, c1--, r2--, c2--;
int ans = abs(r1 - r2) + abs(c1 - c2);
for (int i = 0; i < k; i++) {
ans = min(ans, dist[i][r1][c1] + 1 + dist[i][r2][c2]);
}
cout << ans << '\n';
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
while (t--) solve();
return 0;
}
| 2,600 | CPP |
#include <bits/stdc++.h>
using namespace std;
unsigned long long gcd(unsigned long long a, unsigned long long b) {
while (b) {
a %= b;
swap(a, b);
}
return a;
}
unsigned long long lcm(unsigned long long a, unsigned long long b,
unsigned long long t) {
unsigned long long tmp = (a / gcd(a, b));
if (t / tmp >= b)
return tmp * b;
else
return 0;
}
int main() {
unsigned long long t, w, b;
cin >> t >> w >> b;
unsigned long long up;
unsigned long long min1 = min(w, b) - 1;
if (lcm(w, b, t) == 0) {
up = min(min1, t);
} else {
up = (t / lcm(w, b, t)) + min1 * ((t / lcm(w, b, t))) +
min(min1, t % lcm(w, b, t));
}
unsigned long long a = gcd(up, t);
while (gcd(up, t) > 1) {
a = gcd(up, t);
up /= a;
t /= a;
}
cout << up << "/" << t;
return 0;
}
| 1,800 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long T;
cin >> T;
while (T--) {
long long n, flag = 0;
cin >> n;
string s;
cin >> s;
for (int i = 0; i < n / 2; i++) {
int p = s[i];
int r = s[n - i - 1];
int dif = abs(p - r);
if (p == r || dif == 2) {
flag = 1;
} else {
flag = 0;
break;
}
}
if (flag == 0)
cout << "NO" << endl;
else
cout << "YES" << endl;
}
return (0);
}
| 1,000 | CPP |
import math
t = int(input())
def split(d,x):
if (d <= 3*x):
return [0,d-2*x]
else:
return [x//2,d-3*x]
while (t):
n = int(input())
x = 1
while (x <= n):
x = x*2 + 1
x = (x-1)//2
d = n-x
if (d == 0):
ans = []
elif (d >= (x+1)//2):
ans = [d-(x+1)//2]
else:
d += (x+1)//2
x = (x-1)//2
ans = split(d,(x+1)//2)
#print(ans)
k = 1
tmp = []
while (k < x):
tmp.append((k+1)//2)
k = k * 2 + 1
tmp.extend(ans)
print(len(tmp))
for x in tmp:
print(x,end=' ')
print()
t -= 1
| 1,900 | PYTHON3 |
n=int(input())
for i in range(n):
t=int(input())
l=[]
x=1
for j in range(t):
l.append(x)
print(*l) | 800 | PYTHON3 |
y = int(input())
for i in range(y+1 , 90000) :
if len(set(str(i))) == 4 :
print(i)
break | 800 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1e5 + 1;
struct point {
long long x, y;
point() {}
point(long long x, long long y) {}
};
point v[maxn];
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n;
cin >> n;
for (long long i = 0; i < n; i++) cin >> v[i].x >> v[i].y;
if (n % 2) {
cout << "no";
return 0;
}
map<pair<long long, long long>, long long> mp;
for (long long i = 0; i < n; i++) {
long long cdx = (v[(i + 1) % n].x > v[i].x || v[(i + 1) % n].x == v[i].x &&
v[(i + 1) % n].y >= v[i].y
? 1
: -1);
mp[{cdx * (v[(i + 1) % n].x - v[i].x),
cdx * (v[(i + 1) % n].y - v[i].y)}]++;
}
for (auto gg : mp) {
if (gg.second % 2) {
cout << "no";
return 0;
}
}
cout << "yes";
return 0;
}
| 1,800 | CPP |
def getSum(n):
total = 0
while (n != 0):
total = total + int(n % 10)
n = int(n / 10)
return total
a=int(input())
l=[]
for i in range(a,100000):
ans=getSum(i)
if(ans%4==0):
l.append(i)
break
print(*l)
| 800 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, h, data[100][100], i, r[100], c[100], b[100][100], j, t;
scanf("%d %d %d", &n, &m, &h);
for (i = 0; i < m; i++) {
scanf("%d", &r[i]);
}
for (i = 0; i < n; i++) {
scanf("%d", &c[i]);
}
for (j = 0; j < m; j++) {
for (i = 0; i < n; i++) {
data[i][j] = r[j];
}
}
for (i = 0; i < n; i++) {
for (j = 0; j < m; j++) {
scanf("%d", &t);
if (t == 0) {
data[i][j] = 0;
} else {
data[i][j] = min(data[i][j], c[i]);
}
printf("%d ", data[i][j]);
}
printf("\n");
}
return 0;
}
| 1,200 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
for (int x = 0; x < s.length() - 1;) {
if (s[x] == s[x + 1]) {
s.erase(x, 2);
if (x != 0) {
x--;
}
} else {
x++;
}
}
cout << s;
return 0;
}
| 1,400 | CPP |
def solve(L):
for i in range(n):
L[i] = ord(L[i]) - ord('0')
return L
n = int(input())
L1 = list(input())
L2 = list(input())
L1 = solve(L1)
L2 = solve(L2)
ans = 0
for i in range(n):
temp = min(abs(L1[i] - L2[i]),min(10 - L1[i] + L2[i],10 - L2[i] + L1[i]))
ans += temp
print(ans)
| 800 | PYTHON3 |
a=input()
b=input()
c=input()
res1=[int(x) for x in str(b)]
res2=[int(x) for x in str(c)]
s=0
for i in range(len(res1)):
x=abs(res1[i]-res2[i])
s=s+min(x,10-x)
print(s) | 800 | PYTHON3 |
import sys
readline = sys.stdin.readline
T = int(readline())
Ans = [1]*T
for qu in range(T):
N = int(readline())
A = list(map(int, readline().strip()))
Aodd = [A[i]%2 for i in range(N) if not i&1]
Aeven = [A[i]%2 for i in range(N) if i&1]
if len(Aodd) == len(Aeven):
if all(a == 1 for a in Aeven):
continue
else:
Ans[qu] = 2
else:
if all(a == 0 for a in Aodd):
Ans[qu] = 2
print('\n'.join(map(str, Ans))) | 900 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
inline int ADD(int a, int b) {
a += b;
if (a >= 1000000007) a -= 1000000007;
return (int)a;
}
inline void ADDTO(int &a, int b) {
a += b;
if (a >= 1000000007) a -= 1000000007;
}
inline void SUBTO(int &a, int b) {
a -= b;
if (a < 0) a += 1000000007;
}
inline int MUL(int a, int b) { return (int)((long long)a * b % 1000000007); }
const double PI = acos(-1.);
struct point {
double x, y;
point() {}
point(double xx, double yy) : x(xx), y(yy) {}
point rotate(double a) {
double xx = x * cos(a) - y * sin(a);
double yy = x * sin(a) + y * cos(a);
return point(xx, yy);
}
void output() { printf("%.12lf %.12lf\n", x, y); }
};
point operator+(point a, point b) { return point(a.x + b.x, a.y + b.y); }
point operator-(point a, point b) { return point(a.x - b.x, a.y - b.y); }
int main() {
int n;
while (scanf("%d", &n) == 1) {
point A(0, 0);
point B(cos(36. / 180 * PI) * 2 * 10, 0);
point C = point(10, 0).rotate(-72. / 180 * PI);
point D = point(10, 0).rotate(36. / 180 * PI);
point E = B.rotate(-36. / 180 * PI);
printf("%d\n", 4 * n + 1);
A.output();
for (int i = 0; i < (n); ++i) {
A = A + B;
A.output();
}
for (int i = 0; i < (n); ++i) {
A = A - B;
(A + C).output();
(A + D).output();
(A + E).output();
}
for (int i = 0; i < (n); ++i) {
printf("%d %d %d %d %d\n", i + 1, 4 * n - 3 * i, i + 2, 4 * n - 3 * i + 1,
4 * n - 3 * i - 1);
}
for (int i = (0); i <= (n); ++i) {
if (i) printf(" ");
printf("%d", i + 1);
}
for (int i = 0; i < (n); ++i)
printf(" %d %d %d %d", n + i * 3 + 2, n + i * 3 + 3, n + i * 3 + 4,
n - i);
puts("");
}
}
| 2,300 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
long long C(long long m, long long n) {
if (n > m) return 0;
if (n > m / 2) return C(m, m - n);
long long ret = 1;
for (int i = 1; i <= n; i++) {
ret = ret * (m - i + 1) / i;
}
return ret;
}
int main() {
long long n, m, t;
cin >> n >> m >> t;
long long ans = C(n + m, t);
for (long long i = 0; i < 4; i++) {
ans -= C(n, i) * C(m, t - i);
}
ans -= C(n, t);
cout << ans << endl;
return 0;
}
| 1,400 | CPP |
#include <bits/stdc++.h>
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
using namespace std;
using llong = long long;
using ld = long double;
using itn = int;
using ii = pair<int, int>;
using ull = unsigned long long;
using pll = pair<llong, llong>;
using psi = pair<string, int>;
using ll = pair<llong, llong>;
const llong over999 = 1e9;
const ld over999ld = 1e18 + 1;
const llong md = 1e9 + 7;
const ld EPS = 1e-15;
const ld Pi = acos(-1);
const ld nich = 0;
const llong mnogo = 300;
long long n, x[100100], pr[100010];
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
cin >> n;
long long now = 1;
for (long long i = 1; i <= n; i++) {
cin >> x[i];
if (x[i] >= now) {
now = x[i] + 1;
}
pr[i] = max(pr[i - 1], now);
}
long long all = 0;
for (long long i = n; i >= 1; i--) {
if (pr[i] < now) {
now--;
}
all += now;
}
for (long long i = 1; i <= n; i++) {
all -= x[i] + 1;
}
cout << all;
return 0;
}
| 1,700 | CPP |
#include <bits/stdc++.h>
using namespace std;
inline long long read() {
long long Hashimoto = 0;
bool Kanna = 1;
char I_Love = getchar();
while (I_Love < '0' || I_Love > '9') {
if (I_Love == '-') Kanna = 0;
I_Love = getchar();
}
while (I_Love >= '0' && I_Love <= '9') {
Hashimoto = Hashimoto * 10 + I_Love - '0';
I_Love = getchar();
}
return (Kanna ? Hashimoto : -Hashimoto);
}
template <typename T1, typename T2>
inline void Umax(T1 &a, T2 b) {
if (a < b) a = b;
}
template <typename T1, typename T2>
inline void Umin(T1 &a, T2 b) {
if (a > b) a = b;
}
int n, m, k, q;
int a[555][555], b[555][555];
multiset<int> s;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
;
memset(a, 0x3f, sizeof(a));
memset(b, 0x3f, sizeof(b));
cin >> n >> m >> k >> q;
while (q--) {
int x, y, z;
cin >> x >> y >> z;
a[x - 1][y - 1] = z;
}
for (int i = 0; i < (n); ++i) {
s.clear();
for (int j = 0; j < (m); ++j) {
s.insert(-a[i][j]);
if (s.size() > k) {
s.erase(s.find(-a[i][j - k]));
}
if (s.size() == k) {
b[i][j - k + 1] = -*(s.begin());
}
}
}
memset(a, 0x3f, sizeof(a));
for (int j = 0; j < (m); ++j) {
s.clear();
for (int i = 0; i < (n); ++i) {
s.insert(-b[i][j]);
if (s.size() > k) {
s.erase(s.find(-b[i - k][j]));
}
if (s.size() == k) {
a[i - k + 1][j] = -*(s.begin());
}
}
}
int ans = (1000000000) + 2;
for (int i = 0; i < (n); ++i)
for (int j = 0; j < (m); ++j) Umin(ans, a[i][j]);
if (ans == (1000000000) + 2)
cout << -1 << endl;
else
cout << ans << endl;
return 0;
}
| 1,900 | CPP |
#include <bits/stdc++.h>
using namespace std;
vector<long long> works;
int main() {
int N;
cin >> N;
int a = 1;
while (a < 210000 * 10) {
if (a == N || a + 1 == N) {
cout << 1;
return 0;
}
if (a % 2 == 1) {
++a;
a *= 2;
} else {
a *= 2;
++a;
}
}
cout << 0;
}
| 2,400 | CPP |
#include <bits/stdc++.h>
using namespace std;
string a, b;
const int maxn = 100005;
int sufa1[maxn], sufb1[maxn], sufa2[maxn], sufb2[maxn];
int main() {
cin >> a >> b;
int m;
for (int i = 0; a[i] != '\0'; i++) {
if (a[i] == 'A') {
sufa1[i + 1] = sufa1[i] + 1;
sufb1[i + 1] = sufb1[i];
} else {
sufa1[i + 1] = 0;
sufb1[i + 1] = sufb1[i] + 1;
}
}
for (int i = 0; b[i] != '\0'; i++) {
if (b[i] == 'A') {
sufa2[i + 1] = sufa2[i] + 1;
sufb2[i + 1] = sufb2[i];
} else {
sufa2[i + 1] = 0;
sufb2[i + 1] = sufb2[i] + 1;
}
}
scanf("%d", &m);
while (m--) {
int l, r, l2, r2;
scanf("%d%d%d%d", &l, &r, &l2, &r2);
int a1, b1, a2, b2;
if (r - l + 1 < sufa1[r])
a1 = r - l + 1;
else
a1 = sufa1[r];
b1 = sufb1[r] - sufb1[l - 1];
if (r2 - l2 + 1 < sufa2[r2])
a2 = r2 - l2 + 1;
else
a2 = sufa2[r2];
b2 = sufb2[r2] - sufb2[l2 - 1];
if (a1 < a2) {
printf("0");
continue;
}
if ((a1 % 3) != (a2 % 3)) b1 += 2;
if (b1 == 0 && b2 > 0 && a1 > a2) {
b1 += 2;
}
if (b1 == 0 && b2 > 0) {
printf("0");
continue;
}
if (b1 <= b2 && (b2 - b1) % 2 == 0) {
printf("1");
} else {
printf("0");
}
}
return 0;
}
| 2,500 | CPP |
#include <bits/stdc++.h>
using namespace std;
int dx[1000010];
int dxx(int a) {
if (a <= 9) return a;
int res = 0;
while (a > 0) {
res += a % 10;
a /= 10;
}
return dx[res];
}
int ilosc_dx_rowne[11];
long long DP[10][1000010];
int main() {
int N;
scanf("%d", &N);
long long res = 0;
for (int(i) = (1); (i) <= (1000001); (i)++) dx[i] = dxx(i);
for (int(i) = (1); (i) <= (10); (i)++) ilosc_dx_rowne[i] = 0;
for (int(i) = (1); (i) <= (N); (i)++) ilosc_dx_rowne[dx[i]]++;
for (int(i) = (1); (i) <= (9); (i)++) {
DP[i][N + 1] = 0;
for (int j = N; j >= 1; j--)
DP[i][j] = DP[i][j + 1] + ilosc_dx_rowne[dx[i * dx[j]]];
}
for (int(i) = (1); (i) <= (N); (i)++) {
for (int(j) = (1); (j) <= (N / i); (j)++) {
if (dx[i * j] == dx[dx[i] * dx[j]]) res--;
res += ilosc_dx_rowne[dx[dx[i] * dx[j]]];
}
res += DP[dx[i]][N / i + 1];
}
cout << res << endl;
return 0;
}
| 2,000 | CPP |
t = int(input())
for _ in range(t):
n = int(input())
arr = [1]*n
print(*arr) | 800 | PYTHON3 |
N = int(input())
S = input()
sum = 0
for i in range(0, N):
if int(S[i]) % 2 == 0: sum += i+1
print(sum) | 800 | PYTHON3 |
input()
v = sum(map(int, input().split(' ')))
c = list(map(int, input().split(' ')))
s = max(c)
c.remove(s)
s += max(c)
print('YES' if s - v >= 0 else 'NO')
| 900 | PYTHON3 |
arr=[];estan=0
for i in range(int(input())):
salen,entran=map(int,input().split())
estan+=entran-salen;arr.append(estan)
arr.sort();print(arr[len(arr)-1]) | 800 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int s, n, res = 1;
scanf("%d %d", &s, &n);
int arr[n][2];
for (int i = 0; i < n; i++) {
for (int j = 0; j < 2; j++) {
scanf("%d", &arr[i][j]);
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n - i - 1; j++) {
if (arr[j][0] > arr[j + 1][0]) {
swap(arr[j][0], arr[j + 1][0]);
swap(arr[j][1], arr[j + 1][1]);
}
}
}
for (int i = 0; i < n; i++) {
if (s > arr[i][0]) {
s = s + arr[i][1];
} else {
res = 0;
break;
}
}
if (res == 0) {
printf("NO\n");
} else if (res == 1) {
printf("YES\n");
}
return 0;
}
| 1,000 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int Maxn = 1e5;
struct NonRotateTreap {
struct TreapNode {
int key, siz, fix;
TreapNode *lch, *rch;
};
TreapNode pool[Maxn * 25 + 5];
TreapNode *NIL, *ncnt;
typedef pair<TreapNode *, TreapNode *> Droot;
void init() {
ncnt = NIL = &pool[0];
NIL->lch = NIL->rch = NIL;
NIL->siz = 0, NIL->fix = 0, NIL->key = 0;
}
void pushup(TreapNode *rt) { rt->siz = rt->lch->siz + rt->rch->siz + 1; }
TreapNode *newnode(TreapNode *rt) {
TreapNode *p = ++ncnt;
(*p) = (*rt);
return p;
}
TreapNode *newnode(int val) {
TreapNode *p = ++ncnt;
p->key = val, p->siz = 1, p->fix = rand();
p->lch = p->rch = NIL;
return p;
}
TreapNode *merge(TreapNode *rt1, TreapNode *rt2) {
if (rt1 == NIL) return rt2;
if (rt2 == NIL) return rt1;
TreapNode *t;
if (rt1->fix <= rt2->fix) {
t = newnode(rt1);
t->rch = merge(rt1->rch, rt2);
pushup(t);
} else {
t = newnode(rt2);
t->lch = merge(rt1, rt2->lch);
pushup(t);
}
return t;
}
Droot split_rnk(TreapNode *rt, int k) {
Droot d(NIL, NIL);
if (rt == NIL) return d;
TreapNode *p = newnode(rt);
if (k <= rt->lch->siz) {
d = split_rnk(rt->lch, k);
p->lch = d.second;
d.second = p;
} else {
d = split_rnk(rt->rch, k - rt->lch->siz - 1);
p->rch = d.first;
d.first = p;
}
pushup(p);
return d;
}
TreapNode *build(int *f, int l, int r) {
if (l > r) return NIL;
int mid = (l + r) >> 1;
TreapNode *p = newnode(f[mid]);
p->lch = build(f, l, mid - 1);
p->rch = build(f, mid + 1, r);
pushup(p);
return p;
}
void trans(TreapNode *rt, int *f, int k) {
if (rt == NIL) return;
f[rt->lch->siz + 1 + k] = rt->key;
trans(rt->lch, f, k);
trans(rt->rch, f, k + rt->lch->siz + 1);
}
TreapNode *rebuild(int *f, int n, TreapNode *root) {
trans(root, f, 0);
ncnt = &pool[0];
return build(f, 1, n);
}
};
NonRotateTreap::TreapNode *root;
NonRotateTreap tree;
int f[Maxn + 5];
int nxt[42][Maxn + 5];
int main() {
srand(20192813);
int N, M, S;
long long T;
scanf("%d %d %d %lld", &N, &M, &S, &T);
for (int i = 1; i <= N; i++) f[i] = i;
tree.init();
root = tree.build(f, 1, N);
for (int i = 1; i <= N; i++) {
if (i % 150 == 0) root = tree.rebuild(f, N, root);
NonRotateTreap::TreapNode *p, *q, *tmp;
tmp = tree.split_rnk(root, i).second;
if (tmp->siz >= M)
p = tree.split_rnk(tmp, M).first;
else
p = tree.merge(tmp, tree.split_rnk(root, M - tmp->siz).first);
tmp = tree.split_rnk(root, N - i).first;
if (tmp->siz >= N - M)
q = tree.split_rnk(tmp, tmp->siz - (N - M)).second;
else
q = tree.merge(tree.split_rnk(root, N - ((N - M) - tmp->siz)).second,
tmp);
root = tree.merge(p, q);
}
tree.trans(root, f, 0);
while (T % N) {
if (S <= M)
S = (S - 1 + T) % N + 1;
else
S = ((S - 1 - T) % N + N) % N + 1;
T--;
}
for (int i = 1; i <= N; i++) nxt[0][i] = f[i];
for (int j = 1; j <= 41; j++)
for (int k = 1; k <= N; k++) nxt[j][k] = nxt[j - 1][nxt[j - 1][k]];
long long tmp = T / N;
for (int i = 41; i >= 0; i--)
if ((1LL << i) & tmp) S = nxt[i][S];
printf("%d\n", S);
return 0;
}
| 2,900 | CPP |
#include <bits/stdc++.h>
using namespace std;
char ans[110][110], s[110][110];
char nextt(char ch) {
if (ch == 'z')
return 'A';
else if (ch == 'Z')
return '0';
else
return ch + 1;
}
int main() {
int t, n, m, k;
scanf("%d", &t);
while (t--) {
scanf("\n%d%d%d", &n, &m, &k);
int nr = 0;
for (int i = 1; i <= n; i++) {
scanf("\n%s", s[i] + 1);
for (int j = 1; j <= m; j++)
if (s[i][j] == 'R') nr++;
}
int a = nr / k;
int b = nr % k;
int p = 1;
int cnt = 1;
char ch = 'a';
nr = 0;
if (b == 0) p = 0;
for (int i = 1; i <= n; i++) {
if (i % 2 == 1) {
for (int j = 1; j <= m; j++) {
if (s[i][j] == 'R') nr++;
ans[i][j] = ch;
if (nr == a + p && cnt < k) {
ch = nextt(ch);
nr = 0;
b--;
if (b == 0) p = 0;
cnt++;
}
}
} else {
for (int j = m; j >= 1; j--) {
if (s[i][j] == 'R') nr++;
ans[i][j] = ch;
if (nr == a + p && cnt < k) {
ch = nextt(ch);
nr = 0;
b--;
if (b == 0) p = 0;
cnt++;
}
}
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) printf("%c", ans[i][j]);
printf("\n");
}
}
return 0;
}
| 1,700 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 100;
int t, n, a[N], b[N];
bool solve() {
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
b[i] = a[i];
}
sort(b + 1, b + n + 1);
int mn = b[1];
for (int i = 1; i <= n; i++) {
if (a[i] == b[i]) continue;
if (a[i] % mn) {
return false;
}
}
return true;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> t;
while (t--) {
if (solve()) {
cout << "YES\n";
} else {
cout << "NO\n";
}
}
return 0;
}
| 1,300 | CPP |
from sys import stdin
from collections import deque
input = stdin.readline
def bfs():
ans = [0]*(n+1)
marked = set()
r = [-1]*(n+1)
for i in range(n+1):
if r[i] != -1:
ans[i] = ans[r[i]]
continue
queue = deque()
queue.append((i, 0))
size = 0
while queue:
v = queue.popleft()
marked.add(v)
size += 1
if v[1] == 0:
r[v[0]] = i
for c in g[v[0]][v[1]]:
if not(c in marked):
queue.append(c)
ans[i] = size
return ans
t = int(input())
for _ in range(t):
n = int(input())
s = input().rstrip()
g = [[[] for _ in range(2)] for _ in range(n+1)]
for i in range(n):
a = int(s[i] == "R")
g[i][1 - a].append((i + 1, a))
g[i + 1][a].append((i, 1 - a))
ans = bfs()
print(*ans) | 1,700 | PYTHON3 |
#include <bits/stdc++.h>
long long zero[] = {0, 1, 2, 3};
long long two[] = {0, 2, 3, 1};
long long three[] = {0, 3, 1, 2};
long long perfect_triple_element(long long index) {
long long q = (index - 1) % 3;
index = (index - 1) / 3;
long long* iter_array;
if (index == 0) return q + 1;
if (q == 0)
iter_array = zero;
else if (q == 1)
iter_array = two;
else if (q == 2)
iter_array = three;
long long triple = 0;
long long count = 0;
do {
long long q = (index - 1) % 4;
triple += (iter_array[q] << count);
count += 2;
index = (index - 1) / 4;
} while (index > 0);
triple += ((q + 1) << count);
return triple;
}
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long t, index;
std::cin >> t;
while (t--) {
std::cin >> index;
std::cout << perfect_triple_element(index) << "\n";
}
return 0;
}
| 2,200 | CPP |
from collections import deque
def solve(n,k,arr):
count = 0
screen = deque([])
dict = {}
for i in arr:
if dict.get(i,0)==0:
if count == k:
dict[screen.pop()] = 0
count-=1
screen.appendleft(i)
dict[i]=1
count += 1
return str(len(screen))+'\n'+' '.join(str(x) for x in list(screen))
if __name__ == "__main__":
output = ''
n,k = map(int,input().split(' '))
arr = [int(x) for x in input().split(' ')]
output += solve(n,k,arr)
print(output)
| 1,300 | PYTHON3 |
s=input()
k=len(s)-1
ans=0
for i in range(0,len(s)):
ans=ans+(int(s[i])*pow(2,k))
k=k-1
sum=0
n=0
while(1):
if(sum>=ans):
break
else:
sum=pow(4,n)
n=n+1
if(n==0):
print(0)
else:
print(n-1)
| 1,000 | PYTHON3 |
c=input()
s=input()
k="qwertyuiopasdfghjkl;zxcvbnm,./"
m=[]
for i in s:
j=k.find(i)
if(c=='R'):
m.append(k[j-1])
else:
m.append(k[j+1])
mes=''.join(m)
print(mes) | 900 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
template <typename S, typename T>
ostream& operator<<(ostream& out, pair<S, T> const& p) {
out << '(' << p.first << ", " << p.second << ')';
return out;
}
template <typename T>
ostream& operator<<(ostream& out, vector<T> const& v) {
long long l = v.size();
for (long long i = 0; i < l - 1; i++) out << v[i] << ' ';
if (l > 0) out << v[l - 1];
return out;
}
template <typename T>
void trace(const char* name, T&& arg1) {
cout << name << " : " << arg1 << "\n";
}
template <typename T, typename... Args>
void trace(const char* names, T&& arg1, Args&&... args) {
const char* comma = strchr(names + 1, ',');
cout.write(names, comma - names) << " : " << arg1 << " | ";
trace(comma + 1, args...);
}
long long n, m, k, p;
long long arr[2000][2000];
multiset<long long> r, c;
long long s;
long long off_r, off_c;
int main() {
cin >> n >> m >> k >> p;
for (long long i = 0; i < n; i++) {
for (long long j = 0; j < m; j++) {
cin >> arr[i][j];
}
}
for (long long i = 0; i < n; i++) {
s = 0;
for (long long j = 0; j < m; j++) {
s += arr[i][j];
}
r.insert(s);
}
for (long long j = 0; j < m; j++) {
s = 0;
for (long long i = 0; i < n; i++) {
s += arr[i][j];
}
c.insert(s);
}
long long tr, tc;
long long tot_ans = -100000000;
tot_ans *= -tot_ans;
vector<long long> vc, vr;
vc.push_back(0LL);
vr.push_back(0LL);
for (long long i = 0; i <= k; i++) {
tr = *r.rbegin();
tc = *c.rbegin();
r.erase(r.find(tr));
vr.push_back(tr);
r.insert(tr - p * m);
c.erase(c.find(tc));
vc.push_back(tc);
c.insert(tc - p * n);
}
for (int i = 1; i <= k; i++) {
vr[i] += vr[i - 1];
vc[i] += vc[i - 1];
}
for (int i = 0; i <= k; i++) {
tot_ans = max(tot_ans, vr[i] + vc[k - i] - ((i) * (k - i) * p));
}
cout << tot_ans << "\n";
return 0;
}
| 2,000 | CPP |
def solve_b(n=None, m=None, sign=None):
if n is None or m is None or sign is None:
n, m = (int(x) for x in input().split())
sign = [input() for _ in range(n)]
sheet = [list('.' * m) for _ in range(n)]
def can_write(r, c):
for i in range(r - 1, r + 2):
for j in range(c - 1, c + 2):
if (i, j) == (r, c):
continue
if sign[i][j] != '#':
return False
return True
def write(r, c):
for i in range(r - 1, r + 2):
for j in range(c - 1, c + 2):
if (i, j) == (r, c):
pass
else:
sheet[i][j] = '#'
for r in range(1, n - 1):
for c in range(1, m - 1):
if can_write(r, c):
write(r, c)
for r in range(n):
sheet[r] = ''.join(sheet[r])
if sheet[r] != sign[r]:
print('NO')
return 'NO'
print('YES')
return 'YES'
if __name__ == '__main__':
solve_b()
| 1,300 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
bool comp(pair<int, int> a, pair<int, int> b) { return a.second != b.second; }
int main() {
int x;
cin >> x;
while (x--) {
int q;
cin >> q;
vector<int> vec;
for (int i = 1; i <= q; i++) {
int r;
cin >> r;
vec.push_back(r);
}
sort(vec.begin(), vec.end(), greater<int>());
for (int i = 0; i < vec.size(); i++) {
cout << vec[i] << " ";
}
cout << endl;
}
}
| 1,000 | CPP |
s = input()
k = int(input())
w = list(map(int, input().split()))
mp = dict()
x = 'a'
for i in range(len(w)):
mp[chr(i+ord('a'))] = w[i]
ans = 0
ln = len(s)
for i in range(ln):
ans += mp[s[i]]*(i+1)
# print(ans)
mx = max(w)
ml = ln + k
mul = (ml*(ml+1))//2 - (ln*(ln+1))//2
ans += mul*mx
print(ans)
| 1,000 | PYTHON3 |
#include <bits/stdc++.h>
const double PI = 3.141592653589793238460;
using namespace std;
long long pows(long long a, long long n, long long m) {
long long res = 1;
while (n) {
if (n % 2 != 0) {
res = (res * a) % m;
n--;
} else {
a = (a * a) % m;
n = n / 2;
}
}
return res % m;
}
long long gcd(long long a, long long b) {
if (b == 0)
return a;
else
return gcd(b, a % b);
}
bool isprime(long long n) {
if (n == 1) {
return false;
}
for (long long i = 2; i * i <= n; i++) {
if (n % i == 0) {
return false;
}
}
return true;
}
bool istrue(string s) {
int i = 0;
int j = s.size() - 1;
while (i < j) {
if (s[i] == s[j]) {
i++;
j--;
} else {
return false;
}
}
return true;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long l, r;
cin >> l >> r;
long long ans = 0;
for (long long i = 1; i <= r; i = i * 2) {
for (long long j = 1; j <= r; j = j * 3) {
if (i * j >= l && i * j <= r) {
ans++;
}
}
}
cout << ans << endl;
}
| 1,300 | CPP |
def game(n, m, moves):
if n == 0 or m == 0:
if moves%2 == 0:
return "Malvika"
else:
return "Akshat"
else:
moves += 1
return game(n-1, m-1, moves)
x, y = list(map(int, input().split(' ')))
print(game(x,y,0)) | 900 | PYTHON3 |
n, db = input().split()
n, db = int(n), int(db)
exists = False
for i in range(10**(n-1), 10**(n)):
if i%db == 0:
print(i)
exists = True
break
if exists==False:
print(-1) | 1,000 | PYTHON3 |
n,x,y=map(int,input().split())
c1=n*y/100
c2=n*y//100
if c1==c2 :
c2=int(c1)
else:
c2=int(c1)+1
if c2-x>=0:
print(c2-x)
else:
print(0)
| 900 | PYTHON3 |
#
# ------------------------------------------------
# Fast Tests Competitive Python Template
# ------------------------------------------------
# Author: prophet "神"
# Version: 1V3uJkowFG
# License: GNU Affero General Public License v3.0
# Location: 218.92.0.135
# ------------------------------------------------
#
testing_mode = True
import sys, traceback
test_data = ""
final_output = ""
def input(input_format = 0, multi = 0):
if multi > 0: return [input(input_format) for x in range(multi)]
else:
next_line = next(test_data, None).strip() if test_data else sys.stdin.readline()
if input_format == 0: formatted_input = [next_line]
elif input_format == 1: formatted_input = list(map(int, next_line.split()))
elif input_format == 2: formatted_input = list(map(float, next_line.split()))
elif input_format == 3: formatted_input = next_line.split()
elif input_format == 4: formatted_input = (lambda x: [x[0], list(map(int, x[1:]))])(next_line.split())
elif input_format == 5: formatted_input = (lambda x: [x[0], list(map(float, x[1:]))])(next_line.split())
else: formatted_input = [next_line]
return formatted_input
def log(*args):
if testing_mode: print(*args)
def out(output_line, output_format = 0, newline = True):
global final_output
formatted_output = ""
if output_format == 0: formatted_output = str(output_line)
elif output_format == 1: formatted_output = " ".join(map(str, output_line))
elif output_format == 1: formatted_output = "\n".join(map(str, output_line))
if testing_mode: final_output += formatted_output + "\n" * newline
else: print(formatted_output, end = "\n" if newline else "")
test_inputs = [
# Input 1
"""
3
6 4 3
1 6
2 3
5 5
4 1 2
2 4
1 2
3 3 2
2 3
1 2
""",
# Input 2
"""
$$$
""",
# Input 3
"""
$$$
""",
# Input 4
"""
$$$
"""
]
test_outputs = [
# Output 1
"""
6
2
3
""",
# Output 2
"""
$$$
""",
# Output 3
"""
$$$
""",
# Output 4
"""
$$$
"""
]
#
# >>>>>>>>>>>>>>> START OF SOLUTION <<<<<<<<<<<<<<
#
def solve():
for z in range(input(1)[0]):
n, x, m = input(1)
vl = x
vr = x
for i in range(m):
l, r = input(1)
if r >= vl and l <= vr:
vl = min(vl, l)
vr = max(vr, r)
s = vr - vl + 1
out(s)
return
#
# >>>>>>>>>>>>>>>> END OF SOLUTION <<<<<<<<<<<<<<<
#
def run_all(overwrite_testing = False):
global testing_mode, final_output, test_data
testing_mode = overwrite_testing and testing_mode
if testing_mode:
tests_failed = 0
for test_number, (test_in, test_out) in enumerate(zip(test_inputs, test_outputs)):
final_output = ""
if test_in.lstrip()[:3] == "$$$": continue
test_data = iter([i for i in test_in.split("\n") if i])
print(f"Test Case #{test_number + 1}:")
print("<" * 20)
fail = False
verdict = "\033[92m\033[1mPASS\033[0m"
try:
solve()
final = final_output.rstrip("\n")
raw_out = iter(map(str, final.split("\n"))) if final else iter(())
except Exception:
raw_out = ""
fail = True
print("\033[95m")
traceback.print_exc()
print("\033[0m")
if raw_out:
if test_out.lstrip()[:3] == "$$$":
verdict = "\033[94m\033[1mSKIP\033[0m"
print("\033[94m" + '\n'.join(list(raw_out)) + "\033[0m")
else:
for line_out in [i for i in test_out.split("\n") if i]:
line_raw = next(raw_out, "% None %")
if line_raw == line_out.strip():
print(f"\033[92m{line_raw}\033[0m")
else:
print(f"\033[91m{line_raw}\033[0m")
fail = True
line_raw = next(raw_out, None)
while line_raw:
print(f"\033[91m{line_raw}\033[0m")
line_raw = next(raw_out, None)
fail = True
print(">" * 20)
if fail:
verdict = "\033[91m\033[1mFAIL\033[0m"
tests_failed += 1
print(verdict + "\n")
if tests_failed: print(f"\033[91m\033[1m{tests_failed} TEST{'S' if tests_failed > 1 else ''} FAILED!\033[0m")
else: print(f"\033[92m\033[1mALL TESTS PASSED!\033[0m")
else:
test_data = False
solve()
run_all(False)
| 1,300 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const double epsilon = 1e-7;
void solve() {
int n;
cin >> n;
vector<int> v(n);
for (int i = 0; i < n; ++i) cin >> v[i];
int res = -1;
int mx = *max_element(v.begin(), v.end());
for (int i = 0; i < n; ++i) {
if (v[i] != mx) continue;
if (i and v[i - 1] != mx) {
res = i + 1;
break;
}
if (i < n - 1 and v[i + 1] != mx) {
res = i + 1;
break;
}
}
cout << res << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while (t--) {
solve();
}
return 0;
}
| 900 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n = 0, k = 0, ci = 0, re = 0;
cin >> n >> k;
for (int i = 0; i < n; i++) {
cin >> ci;
if (ci + k <= 5) {
re++;
}
}
cout << re / 3;
return 0;
}
| 800 | CPP |
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main()
{
int t;
cin >> t;
for (int i = 0; i < t; i++) {
int n; cin >> n;
vector <int> a(n);
vector<int> b(n);
vector<int> add (n);
vector <int> subtract (n);
vector<int> addindex;
vector <int> subtractindex;
int count = 0;
int asum = 0;
int bsum = 0;
for (int j = 0; j < n; j++) {
cin >> a[j];
asum += a[j];
}
for (int j = 0; j < n; j++) {
cin >> b[j];
bsum += b[j];
}
if (asum != bsum) {
cout << -1 << endl;
continue;
}
for (int j = 0; j < n; j++) {
if (b[j] - a[j] > 0) {
add[j] = b[j] - a[j];
addindex.push_back(j+1);
}
else if (b[j] - a[j] < 0) {
subtract[j] = b[j] - a[j];
subtractindex.push_back(j + 1);
}
}
for (int j = 0; j < n; j++) {
count += add[j];
}
cout << count << endl;
if (count == 0) {
continue;
}
for (int j = 0; j < count; j++) {
cout << subtractindex[0] << " " << addindex[0] << endl;
subtract[subtractindex[0] - 1]++;
add[addindex[0] - 1]--;
if (add[addindex[0] - 1] == 0) {
addindex.erase(addindex.begin());
}
if (subtract[subtractindex[0] - 1] == 0) {
subtractindex.erase(subtractindex.begin());
}
}
}
}
| 800 | CPP |
#include <bits/stdc++.h>
using namespace std;
inline long long readLL() {
long long n = 0;
int ch = getchar();
while (!isdigit(ch)) ch = getchar();
while (isdigit(ch)) n = n * 10 + ch - '0', ch = getchar();
return n;
}
const int MAX_N = 500000 + 3, MAX_LOG_V = 61;
int n;
long long a[MAX_N], b[MAX_LOG_V];
int main() {
n = readLL();
long long v = 0;
for (int i = 0; i < n; ++i) {
a[i] = readLL(), v ^= a[i];
a[i] ^= readLL();
}
int cnt = 0;
for (int i = 0; i < n; ++i)
for (int j = MAX_LOG_V - 1; j >= 0; --j)
if (a[i] >> j & 1) {
if (b[j])
a[i] ^= b[j];
else {
b[j] = a[i];
for (int k = j - 1; k >= 0; --k)
if (b[k] && (b[j] >> k & 1)) b[j] ^= b[k];
for (int k = j + 1; k < MAX_LOG_V; ++k)
if (b[k] >> j & 1) b[k] ^= b[j];
++cnt;
break;
}
}
long long nowV = 0;
for (int i = MAX_LOG_V - 1; i >= 0; --i)
if ((v >> i & 1) && !(nowV >> i & 1)) nowV ^= b[i];
if (nowV != v)
puts("1/1");
else
printf("%lld/%lld", (1LL << cnt) - 1, 1LL << cnt);
return 0;
}
| 2,400 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int q;
cin >> q;
while (q--) {
long long int A[3], ans = 0;
cin >> A[0] >> A[1] >> A[2];
sort(A, A + 3);
if (A[0] == A[1] && A[1] == A[2]) {
ans = A[1] - A[0] + A[2] - A[1] + A[2] - A[0];
} else {
if (A[0] == A[1]) {
if (A[1] + 1 == A[2]) {
A[2]--;
} else {
A[0]++;
A[1]++;
A[2]--;
}
ans = A[1] - A[0] + A[2] - A[1] + A[2] - A[0];
} else if (A[1] == A[2]) {
if (A[0] + 1 == A[1]) {
A[0]++;
} else {
A[0]++;
A[1]--;
A[2]--;
}
ans = A[1] - A[0] + A[2] - A[1] + A[2] - A[0];
} else {
A[0]++;
A[1]--;
A[2]--;
ans = A[1] - A[0] + A[2] - A[1] + A[2] - A[0];
}
}
cout << ans << endl;
}
}
| 900 | CPP |
#include <bits/stdc++.h>
using namespace std;
class Debugger {
public:
Debugger(const std::string& _separator = " | ")
: first(true), separator(_separator) {}
template <typename ObjectType>
Debugger& operator,(const ObjectType& v) {
if (!first) std::cerr << separator;
std::cerr << v;
first = false;
return *this;
}
~Debugger() { std::cerr << std::endl; }
private:
bool first;
std::string separator;
};
long long int n, m, x, y;
vector<long long int> black, white;
long long int dp[1005][1005][2];
long long int fun(long long int pos, long long int cou, long long int color) {
if (pos >= m and (cou < x or cou > y)) {
return INT_MAX;
}
if (pos >= m) {
return 0;
}
if (dp[pos][cou][color] != -1) return dp[pos][cou][color];
if (cou < x) {
return dp[pos][cou][color] =
fun(pos + 1, cou + 1, color) + (color ? black[pos] : white[pos]);
} else if (cou >= y) {
return dp[pos][cou][color] =
fun(pos + 1, 1, color ^ 1) + (color ? white[pos] : black[pos]);
} else {
return dp[pos][cou][color] = min(
fun(pos + 1, cou + 1, color) + (color ? black[pos] : white[pos]),
fun(pos + 1, 1, color ^ 1) + (color ? white[pos] : black[pos]));
}
}
void solve() {
cin >> n >> m >> x >> y;
black.resize(m, 0), white.resize(m, 0);
memset(dp, (-1), sizeof(dp));
for (long long int i = 0; i < n; ++i) {
for (long long int j = 0; j < m; ++j) {
char x;
cin >> x;
if (x == '.') {
black[j]++;
} else {
white[j]++;
}
}
}
cout << min(fun(1, 1, 0) + white[0], fun(1, 1, 1) + black[0]) << "\n";
}
int32_t main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0),
cout << fixed << setprecision(10);
;
long long int T;
T = 1;
while (T--) {
solve();
}
}
| 1,700 | CPP |
from functools import reduce as rdc
from operator import mul
n = int(input())
print(1 if n == 1 else rdc(mul, range(2*n-2, n-1, -1))//rdc(mul, range(1, n))) | 800 | PYTHON3 |
n,a,x,b,y = map(int,input().split())
join = False
#print(min((x-a)%n, (b-y)%n))
for k in range(min((x-a)%n, (b-y)%n)+1):
if a==b:
join = True
a+=1
a%=n
b-=1
b%=n
if join:
print('YES')
else:
print('NO')
| 900 | PYTHON3 |
t = int(input())
res = ''
for _ in range(t):
n = int(input())
a = list(map(int, input().split()))
max_l = max(a)
second_l = n - max_l
k = 0
sub_res = ''
if max_l * second_l != 0:
left = set(a[:max_l])
right = set(a[max_l:])
if len(left) == max_l and max(left) == max_l and max(right) == second_l and len(right) == second_l:
k = 1
sub_res = str(max_l) + ' ' + str (second_l) + '\n'
left = set(a[:second_l])
right = set(a[second_l:])
if max_l != second_l and len(right) == max_l and len(left) == second_l and max(left) == second_l and max(right) == max_l:
k += 1
sub_res += str(second_l) + ' ' + str (max_l) + '\n'
res += str(k) + '\n' + sub_res
print(res)
| 1,400 | PYTHON3 |
s=input()
flag=True
for i in range(len(s)):
if s[i]=='4' and i==0:
flag=False
break
elif i<len(s)-2 and s[i:i+3]=='444':
flag=False
break
elif s[i]!='1' and s[i]!='4':
flag=False
break
print("YES" if flag else "NO")
| 900 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
long long Set(long long N, long long pos) { return N = N | (1 << pos); }
long long reset(long long N, long long pos) { return N = N & ~(1 << pos); }
bool check(long long N, long long pos) { return (bool)(N & (1 << pos)); }
void CI(long long &_x) { scanf("%I64d", &_x); }
void CO(long long &_x) { cout << _x; }
template <typename T>
void getarray(T a[], long long n) {
for (long long i = 0; i < n; i++) cin >> a[i];
}
template <typename T>
void prLLIarray(T a[], long long n) {
for (long long i = 0; i < n - 1; i++) cout << a[i] << " ";
cout << a[n - 1] << endl;
}
const double EPS = 1e-9;
const long long INF = 0x7f7f7f7f;
long long dr8[8] = {1, -1, 0, 0, 1, -1, -1, 1};
long long dc8[8] = {0, 0, -1, 1, 1, 1, -1, -1};
long long dr4[4] = {0, 0, 1, -1};
long long dc4[4] = {-1, 1, 0, 0};
long long kn8r[8] = {1, 2, 2, 1, -1, -2, -2, -1};
long long kn8c[8] = {2, 1, -1, -2, -2, -1, 1, 2};
map<long long, long long> MP;
map<int, int> dp;
long long rec(long long num) {
if (num == 1) return 0;
long long ans = 0;
if (dp.find(num) != dp.end()) return dp[num];
long long sq = sqrt(num);
bool enter = 0;
for (long long i = 2; i <= sq; i++)
if (num % i == 0) {
enter = 1;
ans = rec(num / i);
if (MP.find(i) == MP.end())
ans += 1;
else
ans += -1;
break;
}
if (enter == 0) {
if (MP.find(num) == MP.end())
ans += 1;
else
ans += -1;
}
return dp[num] = ans;
}
long long gcd(long long a, long long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
int ar[5005];
int main() {
long long n, m;
cin >> n >> m;
int gc = 0;
vector<long long> A, B;
for (long long i = 0; i < n; i++) {
long long temp;
CI(temp);
A.push_back(temp);
gc = gcd(gc, temp);
ar[i] = gc;
}
for (long long i = 0; i < m; i++) {
long long temp;
CI(temp);
B.push_back(temp);
MP[temp] = 1;
}
int v = 1;
for (int i = n - 1; i >= 0; i--) {
int temp = ar[i] / v;
int t = rec(temp);
if (t < 0) v = v * temp;
A[i] /= v;
}
int ans = 0;
for (int i = 0; i < n; i++) ans += rec(A[i]);
cout << ans << "\n";
}
| 1,800 | CPP |
for _ in range(int(input())):
x,y,a,b=map(int,input().split());x,y=min(x,y), max(x,y);a,b=min(a,b), max(a,b)
if a==b:print(x//a)
else:
c=b-a;z=y-x;ans=0;k=min(z//c, x//a);ans+=k;x-=a*k;y-=b*k;k=min(x,y)//(a+b);ans+=2*k;x-=(a+b)*k;y-=(b+a)*k
if(max(x,y)>=b and min(x,y)>=a):ans+=1
print(ans) | 0 | PYTHON3 |
##codeforces
def findMinInValue(arr):
mxcnt = 0
cnt = 0
for i in arr:
if i == '-':
cnt += 1
else:
cnt -= 1
if cnt > mxcnt:
mxcnt = cnt
val = mxcnt
for i in arr:
if i == '-':
val -= 1
else:
val += 1
return val
n = int(input())
arr = input()
print(findMinInValue(arr)) | 800 | PYTHON3 |
n,t=map(int,input().split())
s=input()
l=[]
for i in range(n):
if s[i]=='G':
l.append(1)
else:
l.append(0)
while(t):
t-=1
i=0
while(i<n-1):
if(l[i]<l[i+1]):
l[i],l[i+1]=l[i+1],l[i]
i+=2
else:
i+=1
for i in range(n):
if l[i]==1:
print("G",end="")
else:
print("B",end="")
| 800 | PYTHON3 |
l,b = input().split(" ")
limak = int(l)
bob = int(b)
year = 1
while True:
limak*=3
bob*=2
if (limak > bob):
break
year+=1
print(year) | 800 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
long long n;
cin >> n;
long long k;
cin >> k;
map<long long, long long> m;
for (long long i = 0; i < n; i++) {
long long a;
cin >> a;
m[a]++;
}
vector<pair<long long, long long>> v;
for (auto& it : m) {
v.push_back({it.first, it.second});
}
if (v.size() == 1) {
cout << 0;
return 0;
}
long long l = 0;
long long r = (long long)(v.size()) - 1;
while (k and l < r) {
long long m1 = v[l].second;
long long m2 = v[r].second;
if (m2 < m1) {
long long mvs = v[r].first - v[r - 1].first;
if (mvs * v[r].second <= k) {
k -= mvs * v[r].second;
v[r - 1].second += v[r].second;
r--;
} else {
long long z = k / v[r].second;
v[r].first -= z;
break;
}
} else {
long long mvs = v[l + 1].first - v[l].first;
if (mvs * v[l].second <= k) {
k -= mvs * v[l].second;
v[l + 1].second += v[l].second;
l++;
} else {
long long z = k / v[l].second;
v[l].first += z;
break;
}
}
}
cout << v[r].first - v[l].first;
return 0;
}
| 2,000 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> deg, s;
deg = s = vector<int>(n);
for (int i = 0; i < n; i++) cin >> deg[i] >> s[i];
int m = 0;
for (int i = 0; i < n; i++) m += deg[i];
cout << m / 2 << endl;
queue<int> q;
for (int i = 0; i < n; i++)
if (deg[i] == 1) q.push(i);
while (not q.empty()) {
int a = q.front();
q.pop();
if (deg[a] == 0) continue;
int b = s[a];
cout << a << " " << b << endl;
s[b] ^= a;
if (--deg[b] == 1) q.push(b);
}
}
| 1,500 | CPP |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.