solution
stringlengths 10
159k
| difficulty
int64 0
3.5k
| language
stringclasses 2
values |
---|---|---|
#n = int(input())
a,b = map(int,input().split())
while(a>0 and b > 0):
if a >= 2*b:
a %= 2*b
elif b >= 2*a:
b %= 2*a
else : break
print(a,b)
| 1,100 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t, a, b, count;
cin >> t;
while (t--) {
count = 0;
cin >> a >> b;
int dif = abs(a - b);
int _five = dif / 5;
dif %= 5;
int _two = dif / 2;
dif %= 2;
int _one = dif / 1;
cout << _five + _two + _one << endl;
}
}
| 800 | CPP |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long int t, z = 1;
cin >> t;
cin.ignore();
while (t--) {
long long int n, m;
cin >> n >> m;
if (n == 1) {
cout << "0\n";
continue;
} else if (n == 2) {
cout << m << "\n";
continue;
} else {
long long int p = (n - 2) / 2;
if ((n - 2) % 2 != 0) p++;
if (m % p == 0)
cout << ((m / p) * 2 * p) << "\n";
else {
p--;
long long int ans = ((m / p) * 2 * p);
ans += (2 * (m - (m / p) * p));
cout << ans << "\n";
}
continue;
}
}
}
| 800 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int Case;
int n, m, a[N];
struct nd {
int p, s;
nd(int _p = 0, int _s = 0) {
p = _p;
s = _s;
}
friend bool operator<(nd a, nd b) {
return a.p < b.p || (a.p == b.p && a.s < b.s);
}
} b[N];
struct ST {
int tot;
int ls[N << 1], rs[N << 1], mx[N << 1];
int build(int l, int r) {
int x = ++tot;
if (l == r) {
mx[x] = a[l];
return x;
}
int mid = l + r >> 1;
ls[x] = build(l, mid);
rs[x] = build(mid + 1, r);
mx[x] = max(mx[ls[x]], mx[rs[x]]);
return x;
}
int getmx(int x, int l, int r, int L, int R) {
if (L <= l && r <= R) return mx[x];
int mid = l + r >> 1, ret = 0;
if (L <= mid) ret = getmx(ls[x], l, mid, L, R);
if (R > mid) ret = max(ret, getmx(rs[x], mid + 1, r, L, R));
return ret;
}
void rebuild() {
for (int i = 1; i <= tot; ++i) ls[i] = rs[i] = mx[i] = 0;
tot = 0;
build(1, n);
}
} T;
void Solve() {
static int mx[N];
mx[m + 1] = 0;
for (int i = m; i >= 1; --i) mx[i] = max(mx[i + 1], b[i].s);
int ans = 0;
if (*max_element(a + 1, a + n + 1) > b[m].p) {
cout << -1 << endl;
return;
}
for (int R = 1, l = 1; R <= n; R = l) {
int px = 0;
while (l <= n) {
px = max((int)(lower_bound(b + 1, b + m + 1, nd(a[l], 0)) - b), px);
if (mx[px] >= l - R + 1)
l++;
else
break;
}
ans++;
}
cout << ans << endl;
}
int main() {
cin >> Case;
while (Case--) {
cin >> n;
for (int i = 1; i <= n; ++i) cin >> a[i];
cin >> m;
for (int i = 1; i <= m; ++i) cin >> b[i].p >> b[i].s;
sort(b + 1, b + m + 1);
T.rebuild();
Solve();
}
}
| 1,700 | CPP |
N = int(input())
X = input().split()
Y = input().split()
X, Y = list(map(int, X)), list(map(int, Y))
if len(set(X[1:]) | set(Y[1:])) == N:
print('I become the guy.')
else:
print('Oh, my keyboard!')
| 800 | PYTHON3 |
n=int(input())
bi=[int(x) for x in input().split()]
m=int(input())
p=list()
for i in range(m):
x=[int(x) for x in input().split()]
p.append(x)
for i in p:
k=i[1]
w=i[0]-1
if w-1>=0:
bi[w-1]=bi[w-1]+(k-1)
if w+1<n:
bi[w+1]=bi[w+1]+(bi[w]-k)
bi[w]=0
for i in bi:
print(i) | 800 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int n, a[101], b[101], c, d;
string s, t;
char x, y;
int main() {
ios_base::sync_with_stdio(false);
cin >> s >> t >> n;
for (int i = 0; i < n; i++) {
cin >> c >> x >> d >> y;
if (y == 'r') {
if (x == 'h' && a[d] != 3) {
cout << s << " " << d << " " << c << endl;
a[d] = 3;
}
if (x == 'a' && b[d] != 3) {
cout << t << " " << d << " " << c << endl;
b[d] = 3;
}
} else {
if (x == 'h' && a[d] != 3) a[d]++;
if (x == 'a' && b[d] != 3) b[d]++;
if (a[d] == 2) {
cout << s << " " << d << " " << c << endl;
a[d] = 3;
}
if (b[d] == 2) {
cout << t << " " << d << " " << c << endl;
b[d] = 3;
}
}
}
return 0;
}
| 1,300 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
char c = s[0], d = s[1];
int x = (int)c - 48, y = (int)d - 48;
int h = 10 * x + y;
c = s[3], d = s[4];
x = (int)c - 48, y = (int)d - 48;
int m = 10 * x + y;
long int a;
cin >> a;
int ah = 0;
while (a >= 60) {
a -= 60;
ah++;
}
h += ah;
m += a;
ah = 0;
while (m >= 60) {
m -= 60;
ah++;
}
h += ah;
while (h >= 24) h -= 24;
if (h < 10) cout << "0";
cout << h << ":";
if (m < 10) cout << "0";
cout << m;
return 0;
}
| 900 | CPP |
t = int(input())
while(t):
t-=1;
n,k = map(int,input().split())
end = n;
while(1):
k-=1
if k == 0:
break
n+=int(min(str(n)))*int(max(str(n)))
if n==end:
break
end = n
print(n)
| 1,200 | PYTHON3 |
#include <bits/stdc++.h>
long long mod = 1e9 + 7;
using namespace std;
long long maxm = 1500000;
int main() {
int n, m, id;
long long i;
long long x;
cin >> x;
int ff = 0;
long long eq;
vector<pair<long long, long long> > ans;
ans.clear();
for (i = 1; i <= maxm; ++i) {
long long num = 6 * x + i * (i - 1) * (i + 1);
long long den = 3 * i * (i + 1);
if (num % den == 0) {
long long xx = num / den;
if (xx == i) {
ff = 1;
eq = xx;
} else if (xx > i) {
ans.push_back(make_pair(i, xx));
}
}
}
if (ff) {
int vvv = ans.size();
cout << vvv * 2 + 1 << endl;
for (i = 0; i < vvv; ++i)
cout << ans[i].first << " " << ans[i].second << endl;
cout << eq << " " << eq << endl;
for (i = vvv - 1; i >= 0; --i) {
cout << ans[i].second << " " << ans[i].first << endl;
}
} else {
int vvv = ans.size();
if (vvv > 0) cout << vvv * 2 << endl;
for (i = 0; i < vvv; ++i)
cout << ans[i].first << " " << ans[i].second << endl;
for (i = vvv - 1; i >= 0; --i) {
cout << ans[i].second << " " << ans[i].first << endl;
}
}
}
| 1,900 | CPP |
from bisect import bisect
def main():
N, K = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
ans = N
for i in range(N):
j = bisect(A, A[i] + K)
if A[i] < A[j-1]:
ans -= 1
print(ans)
main()
| 1,200 | PYTHON3 |
n=int(input())
hours = [int(i) for i in input().split()]
state=0
first=0
maxim=0
current=0
for i,v in enumerate(hours):
if state==0 and v==0:
state=1
maxim=current
current=0
elif state==0 and v==1:
current += 1
first += 1
elif state==1 and v==0:
maxim = max(maxim, current)
current = 0
else:
current += 1
if(i==n-1):
maxim = max(maxim, current+first)
print(maxim)
| 900 | PYTHON3 |
import sys
import math
from collections import defaultdict,deque
input = sys.stdin.readline
def inar():
return [int(el) for el in input().split()]
def main():
t=int(input())
for _ in range(t):
n=int(input())
st=input().strip()
ans=-1
result=[]
for i in range(n):
if i==0:
result.append(1)
ans=int(st[i])+1
continue
if ans==2:
if st[i]=="1":
result.append(0)
else:
result.append(1)
ans=1
else:
if ans==1:
if st[i]=="1":
result.append(1)
else:
result.append(0)
else:
result.append(1)
ans=int(st[i])+result[-1]
print("".join(map(str,result)))
if __name__ == '__main__':
main()
| 800 | PYTHON3 |
n, a, b = map(int, input().split())
if n > a * b:
print(-1)
else:
c = [[0 for j in range(b)] for i in range(a)]
p = 1
i = 0
j = 0
while p <= n:
if i % 2 == 0:
for j in range(b):
if p > n:
break
c[i][j] = p
p += 1
else:
for j in reversed(range(b)):
if p > n:
break
c[i][j] = p
p += 1
i += 1
for i in range(a):
print(*c[i])
| 1,000 | PYTHON3 |
n = int(input())
x = 0
while n:
str = input()
if str.find('++') >= 0:
x += 1
else:
x -= 1
n -= 1
print(x) | 800 | PYTHON3 |
import collections
n,l=map(int, input().split())
array = list(map(int, input().split()))
c=collections.Counter(array).values()
cur=1
while sum(x//cur for x in c)>=n:cur+=1
print(cur-1)
| 1,200 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
vector<long long> G[800000];
bool visited[800000], pp[800000];
string a;
string s[300];
void dfs(int u) {
visited[u] = pp[u] = true;
for (long long i : G[u]) {
if (!visited[i])
dfs(i);
else if (pp[i]) {
cout << "Impossible";
exit(0);
}
}
pp[u] = false;
char l = u + 97;
a += l;
}
int main() {
long long n;
cin >> n;
for (int i = 0; i < n; i++) cin >> s[i];
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
int k = 0;
while (s[i][k] == s[j][k]) {
if (k < s[i].size() && k < s[j].size())
k++;
else
break;
}
if (k == s[j].size()) return cout << "Impossible", 0;
G[s[i][k] - 'a'].push_back(s[j][k] - 'a');
}
}
for (int i = 25; i >= 0; i--) {
if (!visited[i]) dfs(i);
}
reverse(a.begin(), a.end());
cout << a;
}
| 1,600 | CPP |
def query(n,PC):
p_prev=0
c_prev=0
for p,c in PC:
play=p-p_prev
clear=c-c_prev
if play<0 or clear<0:
return 'NO'
if play<clear:
return 'NO'
p_prev=p
c_prev=c
return 'YES'
def main():
t=int(input())
for _ in range(t):
n=int(input())
PC=[tuple(map(int,input().split())) for _ in range(n)]
print(query(n,PC))
if __name__=='__main__':
main() | 1,200 | PYTHON3 |
a,b,c = sorted(list(map(int,input().split())))
if a+b>c: print(0)
else: print(c-(a+b)+1) | 800 | PYTHON3 |
#include <bits/stdc++.h>
struct node {
int x, y;
};
char s[100][100];
int map[100][100], num, n, m;
bool col[100][100];
node nodes[100 * 100];
void flood(int i, int j);
int main() {
int i, j, k, l;
scanf("%d %d", &n, &m);
for (i = 0; i < n; i++) {
scanf("%s", s[i]);
}
int tot = 0;
for (i = 0; i < n; i++) {
for (j = 0; j < m; j++) {
if (s[i][j] == '#') {
nodes[tot].x = i;
nodes[tot].y = j;
map[i][j] = tot;
tot++;
}
}
}
if (tot <= 2) {
printf("-1\n");
return 0;
}
int fl = 0;
for (i = 0; i < tot; i++) {
memset(col, 0, sizeof(col));
col[nodes[i].x][nodes[i].y] = 1;
num = 0;
k = i + 1;
if (k == tot) k = 0;
flood(nodes[k].x, nodes[k].y);
if (num == tot - 1) continue;
fl = 1;
break;
}
if (fl)
printf("1\n");
else if (tot == 3)
printf("-1\n");
else
printf("2\n");
return 0;
}
void flood(int i, int j) {
if (i < 0 || j < 0 || i >= n || j >= m) return;
if (s[i][j] == '.' || col[i][j]) return;
num++;
col[i][j] = 1;
flood(i - 1, j);
flood(i + 1, j);
flood(i, j - 1);
flood(i, j + 1);
}
| 1,700 | CPP |
def solve(arr,n,k,ans):
final = [0]*(10**4)
index = 0
visited = set()
for i in arr:
if final[index] == 0:
if i not in visited:
visited.add(i)
temp = index
while temp < len(final):
final[temp] = i
temp += k
index += 1
while index < len(final) and final[index] == 0:
temp = index
while temp < len(final):
final[temp] = 1
temp += k
index += 1
i = 0
j = 0
while i < len(arr) and j < len(final):
if arr[i] == final[j]:
i += 1
j += 1
if i == len(arr):
ans.append(final)
else:
ans.append([-1])
def main():
t = int(input())
ans = []
for i in range(t):
n,k = map(int,input().split())
arr = list(map(int,input().split()))
solve(arr,n,k,ans)
for i in ans:
if len(i) == 1:
print(-1)
else:
print(len(i))
for j in i:
print(j,end = ' ')
print()
main()
| 1,400 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
vector<int> g[N];
int deg[N];
bool check(int u, int p, int k);
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, k;
cin >> n >> k;
for (int i = 1; i <= n - 1; ++i) {
int u, v;
cin >> u >> v;
g[u].push_back(v);
g[v].push_back(u);
++deg[u];
++deg[v];
}
vector<int> cur, nxt;
for (int i = 1; i <= n; ++i) {
if (deg[i] == 1) {
cur.push_back(i);
}
}
while (!cur.empty()) {
nxt.clear();
for (auto &u : cur) {
for (auto &v : g[u]) {
--deg[v];
if (deg[v] == 1) {
nxt.push_back(v);
}
}
}
swap(cur, nxt);
}
int root = (nxt.empty() ? 1 : nxt[0]);
if (check(root, 0, k)) {
cout << "Yes\n";
} else {
cout << "No\n";
}
}
bool check(int u, int p, int k) {
int ch = (g[u].size() - (p != 0));
if (k == 0) {
return ch == 0;
} else if (ch < 3) {
return false;
} else {
for (auto &v : g[u]) {
if (v != p and !check(v, u, k - 1)) {
return false;
}
}
return true;
}
}
| 1,800 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
long long x[300010];
int n;
long long qpow(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 get(int x) { return qpow(2LL, 1LL * x) - 1; }
void upd(long long a, long long val) {
a += val;
if (a >= mod) a -= mod;
}
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) scanf("%lld", &x[i]);
sort(x + 1, x + 1 + n);
long long ans = 0;
for (int i = 1; i < n; ++i) {
ans = (ans + (x[i + 1] - x[i]) * (get(i) * get(n - i) % mod)) % mod;
}
printf("%lld\n", ans);
}
| 1,500 | CPP |
instructions=list(map(int,input().split()))
ovan1=int(instructions[3]/instructions[1])*instructions[2]
ovan2=instructions[0]-instructions[2]
if ovan1<ovan2:
print("YES")
else:
print("NO") | 1,100 | PYTHON3 |
import sys, os, io
def rs(): return sys.stdin.readline().rstrip()
def ri(): return int(sys.stdin.readline())
def ria(): return list(map(int, sys.stdin.readline().split()))
def ws(s): sys.stdout.write(s + '\n')
def wi(n): sys.stdout.write(str(n) + '\n')
def wia(a): sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math,datetime,functools,itertools,operator,bisect,fractions,statistics
from collections import deque,defaultdict,OrderedDict,Counter
from fractions import Fraction
from decimal import Decimal
from sys import stdout
def main():
starttime=datetime.datetime.now()
if(os.path.exists('input.txt')):
sys.stdin = open("input.txt","r")
sys.stdout = open("output.txt","w")
for _ in range(1):
n,a,b,k=ria()
h=ria()
neededkhi=[]
pt=0
for i in h:
e=i//(a+b)
if i%(a+b)==0:e-=1
dest=e*(a+b)
if dest+a>=i: pt+=1
else: neededkhi.append(math.ceil((i-dest-a)/a))
neededkhi=sorted(neededkhi)
for i in neededkhi:
if k-i>=0:
pt+=1
k-=i
else:
break
print(pt)
#<--Solving Area Ends
endtime=datetime.datetime.now()
time=(endtime-starttime).total_seconds()*1000
if(os.path.exists('input.txt')):
print("Time:",time,"ms")
class FastReader(io.IOBase):
newlines = 0
def __init__(self, fd, chunk_size=1024 * 8):
self._fd = fd
self._chunk_size = chunk_size
self.buffer = io.BytesIO()
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
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, size=-1):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
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()
class FastWriter(io.IOBase):
def __init__(self, fd):
self._fd = fd
self.buffer = io.BytesIO()
self.write = self.buffer.write
def flush(self):
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class FastStdin(io.IOBase):
def __init__(self, fd=0):
self.buffer = FastReader(fd)
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
class FastStdout(io.IOBase):
def __init__(self, fd=1):
self.buffer = FastWriter(fd)
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.flush = self.buffer.flush
if __name__ == '__main__':
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()
| 1,500 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k, g{}, i, j;
cin >> n >> k;
int c;
cin >> c;
vector<int> h(c);
for (auto& i : h) cin >> i;
for (i = 0, j = -1;; i + k < h[j + 1] ? i = i + k : i = h[++j]) {
++g;
if (j == c - 1) break;
}
for (i += k; i <= n; i += k) ++g;
cout << g - 1 << endl;
}
| 1,300 | CPP |
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using PII = pair<int, int>;
int main() {
auto get_factors = [](int n) {
vector<int> ret;
for (int i = 1; i * i <= n; i++) {
if (n % i == 0) {
ret.push_back(i);
if (i * i != n) ret.push_back(n / i);
}
}
sort(ret.begin(), ret.end());
return ret;
};
vector<vector<int>> factors(1e5 + 1);
for (int i = (1); i <= (1e5); ++i) factors[i] = get_factors(i);
ios::sync_with_stdio(false);
int tc;
cin >> tc;
while (tc--) {
int x[3], cnt[8] = {0};
cin >> x[0] >> x[1] >> x[2];
vector<int> v;
for (int i = 0; i < 3; i++) {
for (auto val : factors[x[i]]) v.push_back(val);
}
sort(v.begin(), v.end());
v.erase(unique(v.begin(), v.end()), v.end());
for (auto val : v) {
int mask = 0;
for (int i = 0; i < 3; i++) {
if (x[i] % val == 0) mask |= 1 << i;
}
cnt[mask]++;
}
int ans = 0;
for (int a = 1; a < 8; a++) {
for (int b = a; b < 8; b++) {
int t1 = a | b;
if (t1 == (t1 & -t1)) continue;
for (int c = b; c < 8; c++) {
int t2 = a | c, t3 = b | c;
if (t2 == (t2 & -t2)) continue;
if (t3 == (t3 & -t3)) continue;
if ((a | b | c) != 7) continue;
if (a != b && a != c && b != c) {
ans += cnt[a] * cnt[b] * cnt[c];
} else if (a == b && b == c) {
int n = cnt[a] + 2;
ans += n * (n - 1) * (n - 2) / 6;
} else if (a == b) {
ans += cnt[a] * (cnt[a] + 1) / 2 * cnt[c];
} else if (a == c) {
ans += cnt[a] * (cnt[a] + 1) / 2 * cnt[b];
} else if (b == c) {
ans += cnt[b] * (cnt[b] + 1) / 2 * cnt[a];
}
}
}
}
cout << ans << endl;
}
}
| 2,400 | CPP |
#include <bits/stdc++.h>
using namespace std;
void input() {
int i, n;
long long x27, x7;
scanf("%d", &n);
x27 = x7 = 1;
for ((i) = 0; (i) < (n); (i)++) {
x27 = (x27 * 27) % 1000000007;
x7 = (x7 * 7) % 1000000007;
}
long long res = (x27 - x7 + 1000000007) % 1000000007;
printf("%I64d\n", res);
}
int main() {
input();
return 0;
}
| 1,500 | CPP |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
struct Point {
double x, y;
Point(double x, double y) : x(x), y(y) {}
Point() : x(0), y(0) {}
Point operator+(const Point &o) { return Point(x + o.x, y + o.y); }
Point operator-(const Point &o) { return Point(x - o.x, y - o.y); }
Point operator*(double k) { return Point(x * k, y * k); }
Point operator/(double k) { return Point(x / k, y / k); }
};
inline double dot(const Point &a, const Point &b) {
return a.x * b.x + a.y * b.y;
}
inline double det(const Point &a, const Point &b) {
return a.x * b.y - a.y * b.x;
}
inline int sign(double a) { return a < -eps ? -1 : a > eps; }
bool left(Point a, Point b, vector<Point> poly) {
int np = poly.size();
for (int i = 0; i < np; ++i) {
if (sign(det(b - a, poly[i] - a)) > 0) {
return 0;
}
}
return 1;
}
bool right(Point a, Point b, vector<Point> poly) {
int np = poly.size();
for (int i = 0; i < np; ++i) {
if (sign(det(b - a, poly[i] - a)) < 0) {
return 0;
}
}
return 1;
}
int main() {
int n;
double w, v, u;
cin >> n >> w >> v >> u;
vector<Point> poly(n);
for (int i = 0; i < n; ++i) {
cin >> poly[i].x >> poly[i].y;
poly[i].x /= v;
}
double res = 1e100;
if (left(Point(0, 0), Point(w / u, w), poly)) {
res = min(res, w / u);
}
if (right(Point(0, 0), Point(w / u, w), poly)) {
res = min(res, w / u);
}
for (int i = 0; i < n; ++i) {
double x = poly[i].x - poly[i].y / u;
if (x < 0) {
continue;
}
Point a(x, 0), b(x + w / u, w);
if (sign(det(b - a, poly[(i + 1) % n] - poly[i])) >= 0 &&
sign(det(a - b, poly[(i + n - 1) % n] - poly[i])) <= 0) {
res = min(res, b.x);
}
if (sign(det(b - a, poly[(i + 1) % n] - poly[i])) <= 0 &&
sign(det(a - b, poly[(i + n - 1) % n] - poly[i])) >= 0) {
res = min(res, b.x);
}
}
printf("%.15f\n", res);
}
| 2,100 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
vector<int> price_vector;
int price_fruit;
for (int i = 0; i < n; ++i) {
cin >> price_fruit;
price_vector.push_back(price_fruit);
}
string fruit;
map<string, int> fruit_map;
for (int i = 0; i < m; ++i) {
cin >> fruit;
fruit_map[fruit]++;
}
vector<int> fruit_vector;
for (const auto& m : fruit_map) fruit_vector.push_back(m.second);
size_t count_min = 0;
sort(fruit_vector.rbegin(), fruit_vector.rend());
sort(price_vector.begin(), price_vector.end());
for (size_t i = 0; i < fruit_vector.size(); ++i) {
count_min += fruit_vector[i] * price_vector[i];
}
cout << count_min << ' ';
size_t count_max = 0;
sort(price_vector.rbegin(), price_vector.rend());
for (size_t i = 0; i < fruit_vector.size(); ++i) {
count_max += fruit_vector[i] * price_vector[i];
}
cout << count_max;
}
| 1,100 | CPP |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<int, int>;
template <typename T>
inline void _read(T arr, int n) {
for (int i = 0; i < n; i++) cin >> arr[i];
}
template <typename T>
inline void _write(T arr, int n, bool _space = true, bool _endl = true) {
if (_space)
for (int i = 0; i < n; i++) cout << arr[i] << " ";
else
for (int i = 0; i < n; i++) cout << arr[i];
if (_endl) cout << endl;
}
int cnt = 0;
bool isInRange(ll l, ll r) {
if (++cnt > 4500) {
exit(0);
}
if (l > r) swap(l, r);
cout << l << " " << r << endl;
string t;
cin >> t;
if (t[0] == 'B') {
exit(0);
}
if (t[0] == 'Y') {
if (l == r) exit(0);
return true;
} else {
return false;
}
}
ll n, k;
ll L, R;
inline ll Random(ll l, ll r) {
if (l > r) swap(l, r);
ll mod = (r - l) + 1;
return (rand() << 15 | rand()) % mod + l;
}
void __Main__() {
cin >> n >> k;
L = 1, R = n;
srand(time(NULL));
while (cnt < 4500) {
while (R - L + 1 > 6 * k) {
ll mid = (L + R) / 2;
if (isInRange(L, mid)) {
R = mid;
} else {
L = mid + 1;
}
R = min(n, R + k);
L = max(1ll, L - k);
}
ll pos = Random(L, R);
if (isInRange(pos, pos)) return;
R = min(n, R + k);
L = max(1ll, L - k);
}
}
signed main() {
ios ::sync_with_stdio(false);
cin.tie(nullptr);
__Main__();
return 0;
}
| 2,100 | CPP |
from sys import stdin
def input():
return stdin.readline()[:-1]
def intput():
return int(input())
def sinput():
return input().split()
def intsput():
return map(int, sinput())
q = intput()
for _ in range(q):
n = intput()
s = []
evens = []
odds = []
onecount = 0
for i in range(n):
s.append(input())
if len(s[-1]) % 2 == 0:
evens.append(len(s[-1]))
else:
odds.append(len(s[-1]))
for x in s[-1]:
if x == '1':
onecount += 1
for x in evens:
while onecount - x < 0:
x -= 2
onecount -= x
if onecount == 0:
break
if n - len(evens) == 0:
print(n - onecount)
else:
if onecount <= sum(odds):
print(n)
else:
print(n - 1)
| 1,400 | PYTHON3 |
import sys
input = sys.stdin.readline
t=int(input())
for _ in range(t):
n=int(input())
A=[int(i) for i in input().split()]
A.sort()
print(0 if n==2 else min(n-2,A[-2]-1)) | 900 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll LINF = 1001002003004005006ll;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
template <class T>
bool chmax(T &a, const T &b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <class T>
bool chmin(T &a, const T &b) {
if (b < a) {
a = b;
return true;
}
return false;
}
template <ll Mod>
struct ModInt {
long long x;
ModInt() : x(0) {}
ModInt(long long y) : x(y >= 0 ? y % Mod : (Mod - (-y) % Mod) % Mod) {}
ModInt &operator+=(const ModInt &p) {
if ((x += p.x) >= Mod) x -= Mod;
return *this;
}
ModInt &operator-=(const ModInt &p) {
if ((x += Mod - p.x) >= Mod) x -= Mod;
return *this;
}
ModInt &operator*=(const ModInt &p) {
x = (int)(1ll * x * p.x % Mod);
return *this;
}
ModInt &operator/=(const ModInt &p) {
(*this) *= p.inverse();
return *this;
}
ModInt operator-() const { return ModInt(x); }
ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
ModInt operator==(const ModInt &p) const { return x == p.x; }
ModInt operator!=(const ModInt &p) const { return x != p.x; }
ModInt inverse() const {
int a = x, b = Mod, u = 1, v = 0, t;
while (b > 0) {
t = a / b;
swap(a -= t * b, b);
swap(u -= t * v, v);
}
return ModInt(u);
}
ModInt pow(long long n) const {
ModInt ret(1), mul(x);
while (n > 0) {
if (n & 1) ret *= mul;
mul *= mul;
n >>= 1;
}
return ret;
}
friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; }
friend istream &operator>>(istream &is, ModInt &a) {
long long t;
is >> t;
a = ModInt<Mod>(t);
return (is);
}
static int get_mod() { return Mod; }
};
using mint = ModInt<998244353>;
int n;
vector<vector<int>> g;
struct node {
mint ha, nuru, nuranai;
node(mint ha, mint nuru, mint nuranai)
: ha(ha), nuru(nuru), nuranai(nuranai) {}
node() {}
};
void o(node &p) {
cout << "ha : " << p.ha << " , nuru : " << p.nuru
<< " , nuranai : " << p.nuranai << endl;
}
node dfs(int pre, int now) {
if (pre >= 0 and g[now].size() == 1) {
return node(mint(0), mint(0), mint(0));
}
node ret(mint(1), mint(1), mint(1));
for (auto to : g[now])
if (pre != to) {
auto ch = dfs(now, to);
ret.ha *= ch.nuru + ch.nuranai + ch.ha + 1;
ret.nuru *=
ch.nuranai + 1 + ch.ha + (ch.ha + ch.nuranai + ch.nuru + mint(1));
ret.nuranai *= ch.nuru + ch.nuranai + ch.ha + ch.ha +
(ch.nuru + ch.ha + ch.nuranai) + mint(3);
}
ret.nuru -= ret.ha;
ret.nuranai -= ret.ha;
ret.ha -= 1;
return ret;
}
signed main() {
cin.tie(0);
ios::sync_with_stdio(0);
cin >> n;
g.resize(n);
for (int i = 0; i < (n - 1); i++) {
int u, v;
cin >> u >> v;
u--, v--;
g[u].push_back(v);
g[v].push_back(u);
}
auto res = dfs(-1, 0);
mint ans = res.ha + res.nuranai + res.nuru;
cout << ans << endl;
return 0;
}
| 2,500 | CPP |
#include <bits/stdc++.h>
using namespace std;
template <class T>
bool setmin(T &a, T b) {
if (b < a) {
a = b;
return true;
} else
return false;
}
template <class T>
bool setmax(T &a, T b) {
if (b > a) {
a = b;
return true;
} else
return false;
}
bool g[99][99];
int n, p;
int main() {
int cs;
cin >> cs;
while (cs--) {
cin >> n >> p;
memset(g, false, sizeof(g));
for (int i = (int)(1); i <= (int)(n); ++i) {
int j = i;
(j %= n) += 1;
g[i][j] = g[j][i] = true;
(j %= n) += 1;
g[i][j] = g[j][i] = true;
}
for (int i = (int)(1); i <= (int)(n); ++i)
for (int j = (int)(1); j <= (int)(n); ++j)
if (i != j && !g[i][j] && p > 0) {
--p;
g[i][j] = g[j][i] = true;
}
for (int i = (int)(1); i <= (int)(n); ++i)
for (int j = (int)(i); j <= (int)(n); ++j)
if (g[i][j]) cout << i << " " << j << endl;
}
return 0;
}
| 1,500 | CPP |
n, k = map(int, input().split())
arr = sorted(list(map(int, input().split())))
s = 0
for i in range(k):
s += arr[i]
print(s)
| 1,200 | PYTHON3 |
n = int(input())
print(3*n+4)
print(0,0)
print(0,1)
for i in range(1,n+1):
print(i,i-1)
print(i,i)
print(i,i+1)
print(n+1,n)
print(n+1,n+1) | 1,500 | PYTHON3 |
nb = int(input())
for k in range(nb):
n = int(input())
A = list(map(int, input().split(" ")))
B = list(map(int, input().split(" ")))
sol = 0
ma = min(A)
mb = min(B)
for k in range(n):
na = A[k] - ma
nb = B[k] - mb
nmove = max([na,nb])
sol += nmove
print(sol) | 800 | PYTHON3 |
n = int(input())
str = input()
count=0
i=1
while i<n:
j=i+1
if str[i-1]==str[i]:
count+=1
while(j<n and str[j]==str[j-1]):
count+=1
j+=1
i = j
print(count)
| 800 | PYTHON3 |
m,n=map(int,input().split());p=0
while(m<=n):m=m*3;n=n*2;p+=1
print(p)
| 800 | PYTHON3 |
from math import sqrt
def distance(x, y, x_ex, y_ex):
return sqrt((x_ex - x)**2 + (y_ex - y)**2)
_, v_vehicle, v_student = map(int, input().split())
x = list(map(int, input().split()))
y = 0
x_exam, y_exam = map(int, input().split())
min_time = float('inf')
min_distance = float('inf')
min_index = 0
index = 1
del x[0]
for xi in x:
dist = distance(xi, y, x_exam, y_exam)
time_sum = xi/v_vehicle + dist / v_student
index += 1
if min_time > time_sum:
min_time = time_sum
min_distance = dist
min_index = index
else:
if min_time == time_sum and dist < min_distance:
min_time = time_sum
min_distance = dist
min_index = index
print(min_index)
| 1,200 | PYTHON3 |
def GP(n):
if n == 0:
return 0
else:
k = 2 *(2**n -1)
# print(k)
return k
p=input()
count=GP(int(len(p)-1))
#count=GP(int(len(p)-(int(i)+1)))
for i in range(0,len(p)):
if p[i] == '7' :
count=count + 2**(len(p)-(i+1))
print(count+1) | 1,100 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100000;
vector<int> g[N];
int par[N];
int w[N];
int vis[N];
int h[N];
int dfs(int r, int dep = 0) {
vis[r] = 1;
for (auto c : g[r])
if (!vis[c]) dfs(c, dep + 1);
return h[r] = dep;
}
int clans[N];
int n, m;
int d2fs(int r, int anc) {
vis[r] = 1;
clans[r] = anc;
;
for (auto c : g[r]) {
;
if (!vis[c]) {
d2fs(c, anc);
}
}
return 0;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
memset(par, -1, sizeof(par));
cin >> n >> m;
for (int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
a--;
b--;
par[b] = a;
g[a].push_back(b);
}
for (int i = 0; i < n; i++) {
cin >> w[i];
w[i]--;
}
for (int i = 0; i < n; i++)
if (!vis[i]) {
int r = i;
while (par[r] != -1) r = par[r];
dfs(r, 0);
}
vector<pair<pair<int, int>, int> > order;
for (int i = 0; i < n; i++) order.push_back({make_pair(-h[w[i]], h[i]), i});
sort(order.begin(), order.end());
memset(vis, 0, sizeof(vis));
int i, a;
for (i = 0; i < n; i++)
if (!vis[order[i].second]) d2fs(order[i].second, order[i].second);
for (i = 0; i < n; i++)
if (clans[i] != w[i]) break;
if (i != n) {
cout << -1 << '\n';
return 0;
}
cout << n << '\n';
for (int i = 0; i < n; i++) cout << ++order[i].second << '\n';
return 0;
}
| 2,000 | CPP |
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-9;
const int mof = 1000000007;
const int inf = 1000000010;
const long long llinf = 1000000007000000007;
const double pi = 3.14159265359;
int a[211111];
int b[211111];
int A[211111];
int B[211111];
int main() {
int n;
cin >> n;
int sz = 0;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
if (x != 0) {
a[sz] = x;
sz++;
}
}
sz = 0;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
if (x != 0) {
b[sz] = x;
sz++;
}
}
int first = a[0];
int ind = 0;
for (int i = 0; i < n - 1; i++) {
if (b[i] == first) {
ind = i;
break;
}
}
bool ok = true;
for (int i = 0; i < n - 1; i++) {
if (b[(i + ind) % (n - 1)] != a[i]) {
ok = false;
}
}
if (ok)
cout << "YES";
else
cout << "NO";
return 0;
}
| 1,300 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
string a, b;
int c, d;
cin >> a >> b;
c = a.size();
d = b.size();
if (a == b && c == d)
cout << "-1";
else if (c == d)
cout << c;
else
cout << max(c, d);
}
| 1,000 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, x, y, c;
int u, d, l, r;
int ur, rd, dl, lu;
int cnt, step;
int main() {
cin >> n >> x >> y >> c;
cnt = 1;
u = d = x;
l = r = y;
while (cnt < c) {
step++;
if (u != 0) u--;
if (d != n + 1) d++;
if (l != 0) l--;
if (r != n + 1) r++;
if (u != 0) cnt++;
if (d != n + 1) cnt++;
if (l != 0) cnt++;
if (r != n + 1) cnt++;
cnt += ur;
cnt += rd;
cnt += dl;
cnt += lu;
ur++;
rd++;
dl++;
lu++;
if (u == 0) lu--;
if (u == 0) ur--;
if (d == n + 1) rd--;
if (d == n + 1) dl--;
if (l == 0) dl--;
if (l == 0) lu--;
if (r == n + 1) ur--;
if (r == n + 1) rd--;
if (ur < 0) ur = 0;
if (rd < 0) rd = 0;
if (dl < 0) dl = 0;
if (lu < 0) lu = 0;
}
cout << step << '\n';
return 0;
}
| 1,800 | CPP |
#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
using namespace std;
template <class T>
using vec = std::vector<T>;
bool __hack = std::ios::sync_with_stdio(false);
auto __hack1 = cin.tie(nullptr);
struct Input {
Input(istream &in) : in(&in) {}
template <class T>
T next() const {
T x;
*in >> x;
return x;
}
int ni() const { return next<int>(); }
int64_t ni64() const { return next<int64_t>(); }
istream *in;
};
Input in(cin);
class Output {
private:
ostream *out;
template <typename T>
void printSingle(const T &value) {
*out << value;
}
public:
Output(ostream &out) : out(&out) {}
inline void print() {}
template <typename T, typename... Ts>
inline void print(const T &f, const Ts &...args) {
printSingle(f);
if (sizeof...(args) != 0) {
*out << ' ';
print(args...);
}
}
template <typename... Ts>
inline void println(const Ts &...args) {
print(args...);
*out << '\n';
}
template <typename... Ts>
inline void operator()(const Ts &...args) {
println(args...);
}
};
Output out(cout);
namespace template_util {
constexpr int bytecount(uint64_t x) { return x ? 1 + bytecount(x >> 8) : 0; }
template <int N>
struct bytetype {};
template <uint64_t N>
struct minimal_uint : bytetype<bytecount(N)> {};
} // namespace template_util
namespace dsu {
struct DSU {
vector<int> parent;
vector<int> rank;
vector<int> size;
DSU(int n) {
parent = vector<int>(n, 0);
rank = vector<int>(n, 0);
size = vector<int>(n, 1);
for (int i = 0; i < (n); ++i) {
parent[i] = i;
}
}
bool unite(int a, int b) {
a = findSet(a);
b = findSet(b);
if (a == b) {
return false;
}
int size_a = size[a];
int size_b = size[b];
if (rank[a] >= rank[b]) {
++rank[b];
parent[b] = a;
} else {
parent[a] = b;
}
size[findSet(a)] = size_a + size_b;
return true;
}
int findSet(int v) {
return (v == parent[v]) ? v : (parent[v] = findSet(parent[v]));
}
};
} // namespace dsu
namespace hash_util_detail {
template <class T>
inline void hash_combine(size_t &seed, T const &v) {
static std::hash<T> h;
seed ^= h(v) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
}
} // namespace hash_util_detail
namespace std {
template <class U, class V>
struct hash<pair<U, V>> {
std::size_t operator()(pair<U, V> const &p) const {
size_t seed = 0;
hash_util_detail::hash_combine(seed, p.first);
hash_util_detail::hash_combine(seed, p.second);
return seed;
}
};
} // namespace std
template <typename T>
class Compress {
public:
Compress(const vec<T> &o) : mapping(o), compressedOriginal(o) {
sort(mapping.begin(), mapping.end());
mapping.resize(unique(mapping.begin(), mapping.end()) - mapping.begin());
for (int i = 0; i < (compressedOriginal.size()); ++i) {
compressedOriginal[i] = int(
lower_bound(mapping.begin(), mapping.end(), compressedOriginal[i]) -
mapping.begin());
}
}
vec<int> compressed() const { return compressedOriginal; }
private:
vec<int> mapping;
vec<int> compressedOriginal;
};
template <class T>
inline int bitCnt(T mask);
template <>
inline int bitCnt(int32_t mask) {
return __builtin_popcount(mask);
}
void solve(istream &inStream, ostream &outStream) {
in = Input(inStream);
out = Output(outStream);
auto n = in.ni();
vec<pair<int64_t, int64_t>> ps(n);
for (int i = 0; i < (n); ++i) {
auto xx = in.ni64();
auto yy = in.ni64();
ps[i] = {xx, yy};
}
auto check = [&](int t) -> bool {
dsu::DSU dsu(n);
int countConnectedComponents = n;
for (int i = 0; i < (n); ++i) {
for (int j = 0; j < (i); ++j) {
if (abs(ps[i].first - ps[j].first) <= t &&
ps[i].second == ps[j].second) {
if (dsu.unite(i, j)) {
--countConnectedComponents;
}
}
if (abs(ps[i].second - ps[j].second) <= t &&
ps[i].first == ps[j].first) {
if (dsu.unite(i, j)) {
--countConnectedComponents;
}
}
}
}
if (countConnectedComponents >= 5) {
return false;
}
if (countConnectedComponents == 1) return true;
if (countConnectedComponents == 2) {
for (int i = 0; i < (n); ++i) {
for (int j = 0; j < (i); ++j) {
if (dsu.findSet(i) != dsu.findSet(j)) {
if (abs(ps[i].second - ps[j].second) <= t &&
abs(ps[i].first - ps[j].first) <= t) {
return true;
}
if (abs(ps[i].second - ps[j].second) <= 2 * t &&
ps[i].first == ps[j].first) {
return true;
}
if (abs(ps[i].first - ps[j].first) <= 2 * t &&
ps[i].second == ps[j].second) {
return true;
}
}
}
}
return false;
}
unordered_map<pair<int, int>, int> counts;
vec<int> leadSet(n);
for (int i = 0; i < (n); ++i) {
leadSet[i] = dsu.findSet(i);
}
Compress<int> compress(leadSet);
leadSet = compress.compressed();
for (int i = 0; i < (n); ++i) {
for (int j = 0; j < (i); ++j) {
if (leadSet[i] != leadSet[j]) {
if (abs(ps[i].second - ps[j].second) <= t &&
abs(ps[i].first - ps[j].first) <= t) {
int a = leadSet[i], b = leadSet[j];
if (a > b) {
swap(a, b);
}
a <<= 2;
a |= b;
counts[{ps[i].first, ps[j].second}] |= (1 << a);
counts[{ps[j].first, ps[i].second}] |= (1 << a);
}
}
}
}
int needCount = 2;
if (countConnectedComponents == 4) {
needCount = 4;
}
for (const auto &countItem : counts) {
if (bitCnt(countItem.second) >= needCount) {
return true;
}
}
return false;
};
check(1000000000);
int64_t le = 1, ri = int64_t(2e9), res = -1;
while (le <= ri) {
int64_t e = (le + ri) / 2;
if (check(e)) {
res = e;
ri = e - 1;
} else {
le = e + 1;
}
}
out(res);
}
int main() {
solve(cin, cout);
return 0;
}
| 2,800 | CPP |
t = int(input())
for i in range(t):
a = str(input())
s = []
for i in range(len(a)):
if a[i] != '0':
apend_s = a[i] + '0'*(len(a)-i-1)
s.append(apend_s)
print(len(s))
print(*s) | 800 | PYTHON3 |
def test(w):
if w<=2:
return 'NO'
elif w%2==0:
return 'YES'
else:return 'NO'
w=int(input())
print(test(w)) | 800 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int n, v[300002];
int p2[300002];
int ans;
int main() {
scanf("%d", &n);
p2[0] = 1;
for (int i = 1; i <= n; ++i) {
scanf("%d", &v[i]);
p2[i] = (p2[i - 1] * 2) % 1000000007;
}
sort(v + 1, v + n + 1);
for (int i = 2; i <= n; ++i) {
int val = p2[i - 1] - p2[n - i];
if (val < 0) val += 1000000007;
ans = (ans + 1LL * (v[i] - v[1]) * val) % 1000000007;
}
printf("%d\n", ans);
return 0;
}
| 1,500 | CPP |
# cook your code here
for _ in range(int(input())):
s=input()
a=""
x=0
y=0
for i in range(len(s)-1):
if s[i]==s[i+1] and s[i]!="?":
print(-1)
x=1
break
for i in s:
if i!="?":
y=1
break
if x==1:
continue
if y==0:
a="a"
for i in range(len(s)):
if a=="a":
print("b",end="")
a="b"
else:
print("a",end="")
a="a"
print()
continue
j=0
a=""
b="l"
k=["a","b","c"]
for i in range(len(s)):
if s[i]=="?":
j=j+1
else:
if b=="l":
b=s[i]
if j==0:
b=s[i]
elif b==s[i]:
k.remove(b)
m=k[0]
n=k[1]
for l in range(j):
if a=="":
a=a+n
elif a[-1]==m:
a=a+n
else:
a=a+m
k=["a","b","c"]
j=0
else:
k.remove(b)
k.remove(s[i])
m=k[0]
for l in range(j):
if a[-1]==b:
a=a+m
else:
a=a+b
k=["a","b","c"]
j=0
a=a+s[i]
if j!=0:
k.remove(b)
m=k[0]
n=k[1]
for l in range(j):
if a=="":
a=a+n
elif a[-1]==m:
a=a+n
else:
a=a+m
print(a) | 1,000 | PYTHON3 |
def go():
n, k = map(int, input().split(' '))
a = [int(i) for i in input().split(' ')]
minimum = min(a)
maximum = max(a)
if maximum - minimum > 2 * k:
return -1
return minimum + k
Q = int(input())
for q in range(Q):
print(go())
| 900 | PYTHON3 |
# from debug import debug
import math
t = int(input())
for i in range(t):
s = input()
print(s[::2]+s[-1])
| 800 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const long long _ = 1 << 18, MOD = 998244353, G = 3;
long long dir[_], need, invnd, N, K, P[_], F[_], jc[_], inv[_];
long long poww(long long a, long long b) {
long long tms = 1;
while (b) {
if (b & 1) tms = tms * a % MOD;
a = a * a % MOD;
b >>= 1;
}
return tms;
}
void init(long long len) {
need = 1;
while (need < len) need <<= 1;
invnd = poww(need, MOD - 2);
for (long long i = 1; i < need; ++i)
dir[i] = (dir[i >> 1] >> 1) | (i & 1 ? need >> 1 : 0);
}
void NTT(long long *arr, long long tp) {
for (long long i = 1; i < need; ++i)
if (i < dir[i]) swap(arr[i], arr[dir[i]]);
for (long long i = 1; i < need; i <<= 1)
for (long long j = 0, wn = poww(G, MOD / 2 / i); j < need; j += i << 1) {
for (long long k = 0, w = 1; k < i; ++k, w = w * wn % MOD) {
long long x = arr[j + k], y = w * arr[i + j + k] % MOD;
arr[j + k] = (x + y) % MOD;
arr[i + j + k] = (x - y + MOD) % MOD;
}
}
if (tp == -1) {
reverse(arr + 1, arr + need);
for (long long i = 0; i < need; ++i) arr[i] = arr[i] * invnd % MOD;
}
}
signed main() {
cin >> N >> K;
for (long long i = 0; i <= N; ++i) cin >> P[i];
jc[0] = 1;
for (long long i = 1; i <= N; ++i) jc[i] = jc[i - 1] * i % MOD;
inv[N] = poww(jc[N], MOD - 2);
for (long long i = N - 1; ~i; --i) inv[i] = inv[i + 1] * (i + 1) % MOD;
for (long long i = 0; i <= N; ++i) {
P[i] = P[i] * jc[i] % MOD;
F[i] = inv[i];
}
init(2 * N + 1);
reverse(F, F + N + 1);
NTT(P, 1);
NTT(F, 1);
for (long long i = 0; i < need; ++i) F[i] = F[i] * P[i] % MOD;
NTT(F, -1);
memset(P, 0, sizeof(P));
for (long long i = N; i < need; ++i) {
if (i - N <= N) F[i - N] = F[i];
F[i] = 0;
}
for (long long i = 0; i <= N; ++i) {
F[i] = F[i] * poww(poww(i + 1, MOD - 2), K) % MOD;
P[i] = (i & 1 ? MOD - 1 : 1) * inv[i] % MOD;
}
reverse(P, P + N + 1);
NTT(F, 1);
NTT(P, 1);
for (long long i = 0; i < need; ++i) F[i] = F[i] * P[i] % MOD;
NTT(F, -1);
for (long long i = N; i <= 2 * N; ++i)
printf("%lld\n", F[i] * inv[i - N] % MOD);
return 0;
}
| 3,100 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long n, nr, i;
int main() {
cin >> n;
nr = n / 210;
nr *= 48;
n = n % 210;
for (i = 1; i <= n; i++)
if (i % 3 != 0 && i % 5 != 0 && i % 7 != 0 && i % 2 != 0) nr++;
cout << nr;
return 0;
}
| 1,500 | CPP |
n = int(input())
l = []
for _ in range(n):
l.append(list(input()))
co = 0
for i in range(1, n - 1):
for j in range(1, n - 1):
if l[i][j] == 'X':
if l[i - 1] [j - 1] == 'X' and l[i + 1][ j + 1] == 'X' and l[i - 1] [j + 1] == 'X' and l[ i + 1] [j - 1] == 'X':
co += 1
print(co) | 800 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int n, x, y, i, j, t, s, sum, k, f;
int a[100010], b[300], c[100010], d[300][2];
int main() {
scanf("%d%d", &n, &k);
for (i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
for (i = 0; i <= 255; i++) b[i] = -1;
for (i = 0; i < 256; i++) d[i][0] = d[i][1] = -1;
b[0] = 0;
d[0][0] = 0;
d[0][1] = 0;
for (i = 1; i <= n; i++) {
if (b[a[i]] >= 0)
c[i] = b[a[i]];
else {
for (j = max(0, a[i] - k + 1); j <= a[i]; j++) {
if (b[j] >= 0 && b[j] != j) continue;
f = 0;
for (int v = j - 1; v >= 0; v--)
if (d[v][0] != -1) {
if (d[v][1] > j) f = 1;
break;
}
for (int v = j + 1; v <= 255; v++)
if (d[v][0] != -1) {
if (d[v][0] <= a[i]) f = 1;
break;
}
if (f == 0) {
c[i] = j;
d[j][0] = j;
if (d[j][1] < 0 || d[j][1] < a[i]) {
d[j][1] = a[i];
for (int v = d[j][0]; v <= d[j][1]; v++) {
b[v] = j;
}
}
break;
}
}
}
}
for (i = 1; i < n; i++) printf("%d ", c[i]);
printf("%d\n", c[n]);
}
| 1,700 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10, MAXL = 40;
const long long INF = 4e18;
int n;
long long m;
int maxl;
int pai[MAXN][MAXL];
long long lessy[MAXN][MAXL];
long long sum[MAXN][MAXL];
void build() {
maxl = log2(m) + 1;
for (int l = 1; l <= maxl; l++) {
for (int i = 0; i < n; i++) {
pai[i][l] = pai[pai[i][l - 1]][l - 1];
sum[i][l] = sum[pai[i][l - 1]][l - 1] + sum[i][l - 1];
lessy[i][l] = min(lessy[pai[i][l - 1]][l - 1], lessy[i][l - 1]);
}
}
}
int main() {
scanf("%d %lld", &n, &m);
for (int i = 0, a; i < n; i++) scanf("%d", &a), pai[i][0] = a;
long long b;
for (int i = 0, b; i < n; i++) scanf("%lld", &b), lessy[i][0] = sum[i][0] = b;
build();
for (int i = 0; i < n; i++) {
long long jump = m;
int cur = i;
long long lessy0 = INF, sum0 = 0;
for (int l = maxl; jump && l >= 0; l--) {
if ((1LL << l) <= jump) {
lessy0 = min(lessy0, lessy[cur][l]);
sum0 += sum[cur][l];
cur = pai[cur][l];
jump -= (1LL << l);
}
}
printf("%lld %lld\n", sum0, lessy0);
}
}
| 2,100 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, a[1100000], pos;
int zh, fu;
vector<int> f[1100000];
long long ans;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
if (a[i] > i)
f[a[i] - i].push_back(i);
else if (a[i] < i)
f[n - i + a[i]].push_back(i);
else
f[0].push_back(i);
}
for (int i = 1; i <= n; i++) {
ans += (long long)abs(a[i] - i);
if (a[i] - i < 0)
fu++;
else if (a[i] - i > 0)
zh++;
}
long long now = ans;
for (int i = 1; i < n; i++) {
int last = n - i + 1;
if (a[last] < n) fu--;
now -= (long long)zh;
now += (long long)fu;
now += (long long)f[i - 1].size();
if (a[n - i + 1] == n) now--;
now -= (long long)abs(a[last] - n);
now += (long long)(a[last] - 1);
if (a[last] > 1) zh++;
for (int j = 0; j < f[i - 1].size(); j++) {
int x = a[f[i - 1][j]];
int y = f[i - 1][j] + i;
if (y == n + 1) continue;
if (y > n) y -= n;
if (x > y)
zh++;
else
fu++;
}
for (int j = 0; j < f[i].size(); j++) {
int x = a[f[i][j]];
int y = f[i][j] + i - 1;
if (y == n) continue;
if (y > n) y -= n;
if (x > y)
zh--;
else
fu--;
}
if (now < ans) ans = now, pos = i;
}
cout << ans << " " << pos << endl;
return 0;
}
| 1,900 | CPP |
t = int(input())
while t:
n = list(input())
l = len(n)
num = []
c = 0
for i in range(l):
if int(n[i]) != 0:
c += 1
num.append(int(n[i])*(10**(l-i-1)))
print(c)
for i in range(len(num)):
print(num[i],end=" ")
print(end="\n")
t = t-1
| 800 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(12);
int tcase;
cin >> tcase;
while (tcase--) {
int n;
cin >> n;
int k1, k2;
cin >> k1 >> k2;
int max1 = INT_MIN, max2 = INT_MIN;
for (int i = 0; i < k1; i++) {
int x;
cin >> x;
max1 = max(x, max1);
}
for (int i = 0; i < k2; i++) {
int x;
cin >> x;
max2 = max(x, max2);
}
if (max1 > max2)
cout << "YES";
else
cout << "NO";
cout << "\n";
}
return 0;
}
| 800 | CPP |
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
cout << (n - 1) / 2 + 1 << endl;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int t = 1, i = 0;
cin >> t;
while (t--) {
solve();
}
return 0;
}
| 800 | CPP |
import sys
input=sys.stdin.readline
T=int(input())
for _ in range(T):
a,k=map(int,input().split())
for i in range(k-1):
v=str(a)
mv=min(v)
vx=max(v)
if (mv=='0'):
break
a=a+int(mv)*int(vx)
print(a)
| 1,200 | PYTHON3 |
"""
___. .__ .__ .__ __ __ _________
_____ \_ |__ | |__ |__| _____| |__ ____ | | _| | __ \______ \
\__ \ | __ \| | \| |/ ___/ | \_/ __ \| |/ / |/ / / /
/ __ \| \_\ \ Y \ |\___ \| Y \ ___/| <| < / /
(____ /___ /___| /__/____ >___| /\___ >__|_ \__|_ \_____/____/
\/ \/ \/ \/ \/ \/ \/ \/_____/
"""
import sys, io, os
BUFSIZE = 8192
class FastIO(io.IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = io.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(io.IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
def print(*args, **kwargs):
"""Prints the values to a stream, or to sys.stdout by default."""
sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
at_start = True
for x in args:
if not at_start:
file.write(sep)
file.write(str(x))
at_start = False
file.write(kwargs.pop("end", "\n"))
if kwargs.pop("flush", False):
file.flush()
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# endregion
MOD = 1000000007
# from collections import defaultdict as dd,Counter,deque
def si(): return input()
def ii(): return int(input())
def li(): return list(map(int, input().split()))
def mi(): return map(int, input().split())
def sout(v): print(v, end=' ')
def d2b(n): return bin(n).replace("0b", "")
def twod(n, m, num): return [[num for x in range(m)] for y in range(n)]
def vow(): return ['a', 'e', 'i', 'o', 'u']
def let(): return [chr(i) for i in range(97, 123)]
def gcd(x, y):
while y:
x, y = y, x % y
return x
def ispow2(x):
return (x and (not (x & (x - 1))))
def prime_factors(n):
i = 2
factors = []
while i * i <= n:
if n % i:
i += 1
else:
n //= i
factors.append(i)
if n > 1: factors.append(n)
return (list(factors))
def binary_search(arr, low, high, x):
if high >= low:
mid = (high + low) // 2
if arr[mid] == x:
return mid
elif arr[mid] > x:
return binary_search(arr, low, mid - 1, x)
else:
return binary_search(arr, mid + 1, high, x)
else:
return -1
def linear_sieve(n):
primes = []
least_prime_divs = [0] * (n + 1)
for i in range(2, n + 1):
if not least_prime_divs[i]:
least_prime_divs[i] = i
primes.append(i)
for p in primes:
if i * p > n or p > least_prime_divs[i]: break
least_prime_divs[i * p] = p
return primes, least_prime_divs
def helper(l,r,p,b):
if p==-1: return 9999999999
ans=0
for i in range(p-1,-1,-1):
if b[i]=='*':
ans+=p-i-(r[i]-r[p])
for i in range(p+1,len(b)):
if b[i]=='*':
ans+=i-p+(l[p]-l[i])
# print(ans,p,b)
return ans
t = ii()
while t:
t -= 1
n=ii()
b=si()
ans=0
left=[0 for _ in range(n+1)]
for i in range(1,n+1):
if b[i-1]=='*':
left[i]=left[i-1]+1
else:
left[i]=left[i-1]
for i in range(n):
if b[i]=='.':
ans+=min(left[i],left[n]-left[i])
print(ans) | 1,400 | PYTHON3 |
a = int(input(''))
mozno = 0
for i in range(a):
p, q = map(int, input().split())
if q - p >= 2:
mozno += 1
print(mozno) | 800 | PYTHON3 |
n = int(input())
ls = [list(map(int, input().split())) for _ in range(n)]
ans = 0
for lsi in ls:
if sum(lsi) >= 2:
ans += 1
print(ans) | 800 | PYTHON3 |
n,m = input().split()
n = int(n)
m = int(m)
a = list(map(int,input().split()))
b = list(map(int,input().split()))
k = set(a)
l = set(b)
j = k & l
for x in a:
if x in j:
print(x,end=" ")
| 800 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
bool p[31624];
vector<int> pr;
int gcd(int a, int b) { return a % b == 0 ? b : gcd(b, a % b); }
void pre() {
for (int i = 2; i <= 31623; i++) {
if (!p[i]) {
for (int j = i * 2; j <= 31623; j += i) p[j] = 1;
pr.push_back(i);
}
}
return;
}
bool chk(int x) {
if (x == 2) return 1;
for (int i = 0; i < pr.size() && pr[i] < x; i++) {
if (x % pr[i] == 0) {
while (x % pr[i] == 0) x /= pr[i];
if (x > 1) return 0;
return 1;
}
}
return 1;
}
vector<int> ans;
int lf(int x) {
for (int i = 0; i < pr.size(); i++) {
if (x % pr[i] == 0) return pr[i];
}
return x;
}
int n;
bool work(int x) {
for (int i = 2; i <= sqrt(x); i++) {
if (x % i) continue;
for (int j = 1; j < i; j++) {
int c = j * (x / i);
if (gcd(c, n) != 1 && gcd((n - 1) - c, n) != 1) {
ans.push_back(c);
ans.push_back(n - 1 - c);
printf("YES\n%d\n", ans.size());
for (int i = 0; i < ans.size(); i++) {
int g = gcd(n, ans[i]);
printf("%d %d\n", ans[i] / g, n / g);
}
return 1;
;
}
}
}
return 0;
}
int main() {
cin >> n;
pre();
if (chk(n)) {
puts("NO");
return 0;
}
int np = n - 1, lst = n - 1;
if (work(n)) return 0;
while (np) {
if (gcd(np, n) == 1 || gcd(lst % np, n) == 1)
np--;
else {
int ned = lst / np;
lst %= np;
for (int i = 1; i <= ned; i++) ans.push_back(np);
np = lst;
}
}
if (lst) {
puts("NO");
return 0;
}
printf("YES\n%d\n", ans.size());
for (int i = 0; i < ans.size(); i++) {
int g = gcd(n, ans[i]);
printf("%d %d\n", ans[i] / g, n / g);
}
return 0;
}
| 1,900 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a[n], b[n];
for (int i = 0; i < n; i++) cin >> a[i];
int mx = a[n - 1];
for (int i = n - 2; i >= 0; i--) {
if (a[i] <= mx)
b[i] = mx + 1 - a[i];
else
mx = a[i], b[i] = 0;
}
b[n - 1] = 0;
for (int i = 0; i < n; i++) cout << b[i] << " ";
return 0;
}
| 1,100 | CPP |
import os
import sys
from io import BytesIO, IOBase
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# ------------------------------
from math import factorial
from collections import Counter, defaultdict
from heapq import heapify, heappop, heappush
def RL(): return map(int, sys.stdin.readline().rstrip().split())
def N(): return int(input())
def comb(n, m): return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0
def perm(n, m): return factorial(n) // (factorial(n - m)) if n >= m else 0
def mdis(x1, y1, x2, y2): return abs(x1 - x2) + abs(y1 - y2)
mod = 1000000007
INF = float('inf')
# ------------------------------
def main():
for _ in range(N()):
x, n, m = RL()
while n>0 and x>20:
x = x//2+10
n-=1
print("YES" if x<=m*10 else "NO")
if __name__ == "__main__":
main()
| 900 | PYTHON3 |
t=int(input())
l1=[]
for i in range(t):
n=int(input())
s=input()
l2=[]
for j in range(len(s)):
if(s[j]=='A'):
l2.append(j)
l2.append(n)
max1=0
for k in range(1,len(l2)):
if(max1<l2[k]-l2[k-1]-1):
max1=l2[k]-l2[k-1]-1
l1.append(max1)
for i in range(t):
print(l1[i])
| 800 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
long long n, k;
long long a[55];
int main() {
long long i, j;
a[0] = a[1] = 1;
for (i = 2; i <= 50; i++) {
a[i] = a[i - 1] + a[i - 2];
}
cin >> n >> k;
long long c1 = 1, c2 = 2;
while (n > 0) {
if (k > a[n - 1]) {
cout << c2 << ' ' << c1 << ' ';
k -= a[n - 1];
n -= 2;
c2 += 2;
c1 += 2;
} else {
cout << c1 << ' ';
n--;
c1++;
c2++;
}
}
printf("\n");
return 0;
}
| 1,900 | CPP |
value = int(input())
if value%2==0:
print(value//2)
for i in range(value//2):
print(2,end = ' ')
else:
print(value//2)
for i in range(value//2-1):
print(2,end = ' ')
print(3)
| 800 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> vec[105];
int arr[102];
int fre[1002];
int n, one = 0, more = 0;
cin >> n;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
arr[i] = x;
vec[x].push_back(i);
}
for (int i = 0; i <= 100; i++) {
if (vec[i].size() == 1) one++;
if (vec[i].size() > 2) more++;
}
int now = 0;
if (one % 2 == 1 && more == 0) {
cout << "NO" << endl;
return 0;
}
for (int i = 0; i <= 100; i++) {
if (vec[i].size() == 1) {
if (now == 0) {
now = 1;
fre[vec[i][0]] = 0;
} else if (now == 1) {
now = 0;
fre[vec[i][0]] = 1;
}
vec[i].clear();
}
}
if (one % 2 == 1) {
for (int i = 0; i <= 100; i++) {
if (vec[i].size() > 2) {
if (now == 0) {
fre[vec[i][0]] = 0;
now = 1;
} else if (now == 1) {
fre[vec[i][0]] = 1;
now = 0;
}
vec[i][0] = n + 1;
break;
}
}
}
for (int i = 0; i <= 100; i++) {
for (int j = 0; j < vec[i].size(); j++) fre[vec[i][j]] = now;
}
cout << "YES" << endl;
for (int i = 0; i < n; i++) cout << (char)(fre[i] + 'A');
}
| 1,500 | CPP |
#include <bits/stdc++.h>
using namespace std;
int a[300000], dp[300000];
int main() {
int n, a;
cin >> n;
set<int> q;
q.insert(0);
for (int i = 0; i < n; i++) {
cin >> a;
if (q.find(a) != q.end()) {
q.erase(a);
}
q.insert(i + 1);
}
cout << q.size();
return 0;
}
| 1,300 | CPP |
#include <bits/stdc++.h>
using namespace std;
char a[1000005];
void f() {
long long i, j;
long long l = 0;
long long x;
cin >> x;
cin >> a + 1;
const long long D = 1e9 + 7;
long long n = strlen(a + 1);
for (i = 1; i <= n; i++) a[i] -= '0';
long long m = n;
int isok = 1;
while (1) {
l++;
if (isok) {
for (i = m + 1; i <= x && i <= m + (m - l) * (a[l] - 1); i++)
a[i] = a[i - m + l];
}
if (isok == 0) {
m += (m - l + D) % D * (a[l] - 1) % D;
m %= D;
} else {
m += (m - l) * (a[l] - 1);
if (m > x) isok = 0;
m %= D;
}
if (l == x) {
cout << m << "\n";
return;
}
}
}
int main() {
cin.tie(0);
ios_base::sync_with_stdio(0);
int t;
cin >> t;
for (int i = 0; i < t; i++) f();
return 0;
}
| 1,700 | CPP |
#include <bits/stdc++.h>
using namespace std;
int f[502][25060];
int ans[2000], n;
int main() {
ios_base::sync_with_stdio(0);
f[0][0] = 1;
cin >> n;
ans[0] = 0;
for (int i = 0; i <= 100; i++)
for (int j = 0; j <= 5000; j++)
if (f[i][j] != 0) {
ans[i]++;
f[i + 1][j + 1] = 1;
f[i + 1][j + 5] = 1;
f[i + 1][j + 10] = 1;
f[i + 1][j + 50] = 1;
}
if (n <= 100)
cout << ans[n] << "\n";
else {
long long d = ans[100] - ans[100 - 1];
long long t = n - 100;
cout << ans[100] + 49 * t << "\n";
}
return 0;
}
| 2,000 | CPP |
from math import ceil
def main():
params = [ int(x) for x in input().split(" ") ]
#n, m, a, b
spent = []
spent.append( params[0] * params[2] )
spent.append( ceil(params[0]/params[1]) * params[3] )
b_rides = params[0]//params[1]
a_rides = params[0]%params[1]
spent.append( ( b_rides * params[3] ) + ( a_rides * params[2] ) )
print( min( spent ) )
main()
| 1,200 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int n;
struct node {
int a[5];
} p[1005];
inline bool check(int i, int j, int k) {
int ret = 0;
for (int o = 0; o < 5; ++o)
ret += (p[j].a[o] - p[i].a[o]) * (p[k].a[o] - p[i].a[o]);
return ret <= 0;
}
int main() {
scanf("%d", &n);
if (n > 50) return 0 * puts("0");
for (int i = 1; i <= n; ++i)
for (int j = 0; j < 5; ++j) scanf("%d", &p[i].a[j]);
vector<int> res;
for (int i = 1; i <= n; ++i) {
bool flag = true;
for (int j = 1; j <= n; ++j)
if (i != j)
for (int k = j + 1; k <= n; ++k)
if (i != k) flag &= check(i, j, k);
if (flag) res.push_back(i);
}
printf("%d\n", res.size());
for (auto x : res) printf("%d\n", x);
return 0;
}
| 1,700 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int i = 1;
int j = n;
int counter = 0;
while (counter < n) {
if (counter % 2 == 0) {
cout << i << " ";
i++;
} else {
cout << j << " ";
j--;
}
counter++;
}
}
| 1,200 | CPP |
t = int(input());
for test in range(t):
n = int(input());
arr = list(map(int,input().split()));
p = arr.count(0);
s = sum(arr);
if(s==0 and p==0):
print(1);
if(s!=0 and p==0):
print(0);
if(s==0 and p!=0):
print(p)
if(s!=0 and p!=0):
if(p+s)==0:
print(p+1);
else:
print(p);
| 800 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false), cout.tie(0), cin.tie(0);
int n = 100000;
vector<bool> P(n + 1);
vector<long long> A, B;
for (long long i = 2; i <= n; ++i)
if (!P[i]) {
if (i * i > n)
B.push_back(i);
else
A.push_back(i);
for (long long j = i * i; j <= n; j += i) P[j] = 1;
}
cin >> n;
int res = 1;
auto aksA = [&](int x) {
cout << "A " << x << endl;
cout.flush();
int t;
cin >> t;
return t;
};
auto askB = [&](int x) {
cout << "B " << x << endl;
cout.flush();
int t;
cin >> t;
return t;
};
for (int i = 0; i < ((int)(A).size()); ++i) {
if (A[i] > n) continue;
int t = askB(A[i]);
t = aksA(A[i]);
if (t == 1) {
while (res * A[i] <= n && aksA(res * A[i])) res *= A[i];
}
}
int a = 0, cur = aksA(1);
for (int i = 0; i < 98; ++i) {
int tmp = cur;
for (int j = 0; j < 97; ++j, ++a) {
if (B[a] > n) continue;
int t = askB(B[a]);
tmp -= t;
}
cur = aksA(1);
if (tmp != cur) {
for (int j = 0; j < 97; --j) {
if (B[--a] > n) continue;
int t = aksA(B[a]);
if (t == 1) {
res *= B[a];
cout << "C " << res << endl;
cout.flush();
return 0;
}
}
}
}
for (; a < ((int)(B).size()); ++a) {
if (B[a] > n) continue;
int t = askB(B[a]);
t = aksA(B[a]);
if (t == 1) {
res *= B[a];
break;
}
}
cout << "C " << res << endl;
cout.flush();
return 0;
}
| 2,600 | CPP |
# 注意array cache順序 QQ
from math import log, floor
class RMQ:
'''
maximum version rmq
query: max([l, r])
'''
def __init__(self, nums):
size = floor(log(len(nums)) // log(2)) + 1
self.nums = [nums]
for i in range(1, size):
last = self.nums[-1]
delta = 1 << (i-1)
self.nums.append([max(last[j], last[j + delta])
for j in range(len(nums) - 2 * delta + 1)])
def query(self, l, r):
delta = floor(log(r - l + 1) // log(2))
return max(self.nums[delta][l], self.nums[delta][r-2**delta+1])
n, m, q = map(int, input().split())
perms = list(map(int, input().split()))
nums = list(map(int, input().split()))
logit = floor(log(n) // log(2)) + 1
current_max_index = [-1]*(n+1)
prevs = [[-1]*m for i in range(logit)]
prev_map = [-2]*(n+1)
for i, j in zip(perms[1:]+[perms[0]], perms):
prev_map[i] = j
# Update the one step case
for idx, ele in enumerate(nums):
prevs[0][idx] = current_max_index[prev_map[ele]]
current_max_index[ele] = idx
# Update the n_step table
for i in range(1, logit):
for idx, ele in enumerate(nums):
if prevs[i-1][idx] != -1:
prevs[i][idx] = prevs[i-1][prevs[i-1][idx]]
prev_n = []
# Create the update sequence
use = [i for i in range(n.bit_length()) if 1 & (n - 1) >> i]
max_pre = -1
ran = [-1] * (m+2)
for i in range(m):
t = i
for dim in use:
t = prevs[dim][t]
if t == -1:
break
max_pre = max(t, max_pre)
ran[i] = max_pre
"""
for i in range(m):
remain = n - 1
idx = i
while remain and idx != -1:
ma = floor(log(remain) // log(2))
idx = prevs[ma][idx]
remain -= 2**ma
prev_n.append(idx)
"""
#rmq = RMQ(prev_n)
ans = []
for i in range(q):
l, r = map(int, input().split())
if ran[r-1] >= l - 1:
ans.append("1")
else:
ans.append("0")
print("".join(ans))
| 2,000 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int in() {
int x;
scanf("%d", &x);
return x;
}
long long lin() {
long long x;
scanf("%lld", &x);
return x;
}
long long MOD = 1e9 + 7;
template <typename Monoid>
struct SegmentTree {
using F = function<Monoid(Monoid, Monoid)>;
int sz;
vector<Monoid> seg;
const F f;
const Monoid M1;
SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1) {
sz = 1;
while (sz < n) sz <<= 1;
seg.assign(2 * sz, M1);
}
void set(int k, const Monoid &x) { seg[k + sz] = x; }
void build() {
for (int k = sz - 1; k > 0; k--) {
seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
}
}
void update(int k, const Monoid &x) {
k += sz;
seg[k] = x;
while (k >>= 1) {
seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
}
}
Monoid query(int a, int b) {
Monoid L = M1, R = M1;
for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
if (a & 1) L = f(L, seg[a++]);
if (b & 1) R = f(seg[--b], R);
}
return f(L, R);
}
Monoid operator[](const int &k) const { return seg[k + sz]; }
};
int n;
int p[310000], pos[310000];
int main() {
n = in();
SegmentTree<int> seg(
n + 1, [](int a, int b) { return a + b; }, 0);
for (long long i = 0; i < n; i++) {
p[i] = in();
pos[p[i]] = i;
}
long long ans = 0;
for (long long i = n; i >= 1; i--) {
int s = pos[i];
bool f;
for (long long j = 0; j < n; j++) {
if (s - j < 0 || p[s - j] > i) {
f = true;
break;
}
if (s + j >= n || p[s + j] > i) {
f = false;
break;
}
}
if (f) {
int t = s - 1;
while (t >= 0 && p[t] < i) {
if (pos[i - p[t]] > s && !seg.query(s, pos[i - p[t]] + 1)) ans++;
t--;
}
} else {
int t = s + 1;
while (t < n && p[t] < i) {
if (pos[i - p[t]] < s && !seg.query(pos[i - p[t]], s)) ans++;
t++;
}
}
seg.update(s, 1);
}
cout << ans;
}
| 2,200 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long int pmod(long long int x, long long int y) {
long long int res = 1;
x = x % 1000000007;
while (y > 0) {
if (y & 1) res = (res * x) % 1000000007;
y = y >> 1;
x = (x * x) % 1000000007;
}
return res;
}
long long int dp1[1002][1002], dp2[1003][1003];
int main() {
int n;
cin >> n;
long long int arr[n + 2];
long long int brr[n + 2];
for (int i = 0; i < n; i++) cin >> arr[i];
for (int i = 0; i < n; i++) cin >> brr[i];
long long int ans1 = -1, ans2 = -1;
for (int i = 0; i < n; i++) {
for (int j = i; j < n; j++) {
if (i == j) {
dp1[i][j] = arr[i];
dp2[i][j] = brr[i];
ans1 = max(ans1, dp1[i][j]);
ans2 = max(ans2, dp2[i][j]);
} else {
dp1[i][j] = dp1[i][j - 1] | arr[j];
dp2[i][j] = dp2[i][j - 1] | brr[j];
ans1 = max(ans1, dp1[i][j]);
ans2 = max(ans2, dp2[i][j]);
}
}
}
cout << ans1 + ans2;
return 0;
}
| 900 | CPP |
t = int(input())
v = 1
b = ""
va_a_decir = []
def mayor(elem):
return int(elem.split(" ")[0]) + int(elem.split(" ")[1])
while v <= t:
b = ""
robotito = [0, 0]
ord = []
estado = "idle"
c = int(input())
for i in range(0, c):
a = input()
ord.append(a)
ord.sort(key=mayor)
for i in range(0, len(ord)):
if robotito[0] > int(ord[i].split(" ")[0]) or robotito[1] > int(ord[i].split(" ")[1]) < 0:
estado = "NO"
if estado != "NO":
while robotito[0] < int(ord[i].split(" ")[0]):
robotito[0] += 1
b += "R"
while robotito[1] < int(ord[i].split(" ")[1]):
robotito[1] += 1
b += "U"
if robotito[0] > int(ord[i].split(" ")[0]) or robotito[1] > int(ord[i].split(" ")[1]):
b = ""
estado = "NO"
if estado != "NO":
va_a_decir.append("YES")
va_a_decir.append(b)
if estado == "NO":
va_a_decir.append("NO")
estado = "idle"
robotito = [0, 0]
v += 1
for i in range(0, len(va_a_decir)):
print(va_a_decir[i]) | 1,200 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
long long MOD = 1000000007LL;
long long eleva(long long a, long long b) {
if (b == 0) return 1;
long long aux = eleva(a, b / 2);
aux *= aux;
aux %= MOD;
if (b & 1) aux *= a;
aux %= MOD;
return aux;
}
vector<vector<long long> > B;
long long calcula(long long num, long long n) {
if (n > num) return 0LL;
long long lol = 1;
for (long long i = num - n + 1; i <= num; ++i) {
lol *= i;
lol %= MOD;
}
for (long long i = 1; i <= n; ++i) {
lol *= eleva(i, MOD - 2);
lol %= MOD;
}
return lol;
}
int main() {
long long NN = 505;
B = vector<vector<long long> >(NN, vector<long long>(NN));
B[0][0] = 1;
for (long long i = 1; i < NN; ++i) {
for (int j = 0; j < NN; j++) {
B[i][j] += B[i - 1][j];
B[i][j] %= MOD;
if (j) {
B[i][j] += B[i - 1][j - 1];
B[i][j] %= MOD;
}
}
}
long long n, aux;
cin >> n;
map<long long, long long> M;
for (int i = 0; i < n; i++) {
cin >> aux;
for (long long i = 2; i * i <= aux; ++i) {
while (aux % i == 0) {
M[i]++;
aux /= i;
}
}
if (aux > 1) M[aux]++;
}
long long res = 1;
for (map<long long, long long>::iterator it = M.begin(); it != M.end();
++it) {
long long num = it->second + n - 1;
if (num < NN)
res *= B[(it->second) + n - 1][n - 1];
else {
long long lol = calcula(num, n - 1);
res *= lol;
res %= MOD;
}
res %= MOD;
}
cout << res << endl;
}
| 0 | CPP |
n=int(input())
if n==2:
print ('NO')
else:
if n%2==1:
print ('NO')
else:
print ('YES') | 800 | PYTHON3 |
k=int(input())
s='codeforces'
a=[1]*10
ans=1
pointer=0
while ans<k:
ans=ans//a[pointer]
a[pointer]+=1
ans=ans*a[pointer]
pointer=(pointer+1)%10
ans1=[]
for i in range(10):
for j in range(a[i]):
ans1.append(s[i])
print(''.join(ans1))
| 1,500 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
cin >> n >> m;
int a[n];
int sum = 0;
int maxi = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
sum = sum + a[i];
if (a[i] > maxi) {
maxi = a[i];
}
}
int ans = sum - maxi;
if (ans <= m) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
}
| 800 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s, val = "><+-.,[]";
cin >> s;
long long int size = 0;
for (int i = 0; i < s.size(); i++) {
size = (size * 16 + val.find(s[i]) + 8) % 1000003;
}
cout << size;
}
| 1,200 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c;
cin >> a >> b >> c;
if (a != 1 && b != 1 && c != 1) {
cout << a * b * c << endl;
return 0;
} else if (a > c) {
cout << a * (b + c) << endl;
} else if (a < c) {
cout << (a + b) * c << endl;
} else if (a > 1) {
cout << a * (b + c) << endl;
} else {
cout << a + b + c << endl;
}
return 0;
}
| 1,000 | CPP |
l=list(map(int,input().split()))
if sum(l)%5!=0 or sum(l)==0:
print("-1")
else:
print(sum(l)//5)
| 1,100 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 500005;
int stot, stop, sstk[MAXN], n, root1, root2, root3, root, l1, r1, m, pos, x;
const long long mod = 1e9 + 7;
const long long inv2 = 500000004;
int id[MAXN];
long long pw2[MAXN];
struct arrnode {
long long val;
int id;
} arr[MAXN];
bool cmp(const arrnode &A, const arrnode &B) { return A.val < B.val; }
long long quickpow(long long x, long long y) {
long long ans = 1;
while (y) {
if (y & 1) {
ans = (x * ans) % mod;
}
x = (x * x) % mod;
y >>= 1;
}
return ans;
}
struct tree {
int ch[2];
int fa;
long long size;
long long num;
long long pre, suf, sum, ans;
} t[MAXN];
tree operator+(const tree &a, const tree &b) {
tree c;
c.ans = (a.ans * pw2[b.size] % mod + b.suf * a.pre % mod +
b.ans * pw2[a.size] % mod) %
mod;
c.pre = (a.pre + b.pre * pw2[a.size] % mod) % mod;
c.size = a.size + b.size;
c.suf = (b.suf + a.suf * pw2[b.size] % mod) % mod;
return c;
}
void update(int root) {
tree temp;
temp.size = 1;
temp.suf = t[root].num;
temp.ans = 0;
temp.pre = t[root].num;
if (t[root].ch[0]) {
temp = t[t[root].ch[0]] + temp;
}
if (t[root].ch[1]) {
temp = temp + t[t[root].ch[1]];
}
t[root].ans = temp.ans;
t[root].size = temp.size;
t[root].pre = temp.pre;
t[root].suf = temp.suf;
}
void rot(int root) {
int fa = t[root].fa;
int gfa = t[fa].fa;
int t1 = (root != t[fa].ch[0]);
int t2 = (fa != t[gfa].ch[0]);
int ch = t[root].ch[1 ^ t1];
t[root].fa = gfa;
t[root].ch[1 ^ t1] = fa;
t[fa].ch[0 ^ t1] = ch;
t[fa].fa = root;
t[ch].fa = fa;
t[gfa].ch[0 ^ t2] = root;
update(fa);
return;
}
int splay(int root) {
while (t[root].fa) {
int fa = t[root].fa, gfa = t[fa].fa;
if (gfa) {
(t[fa].ch[0] == root) ^ (t[gfa].ch[0] == fa) ? rot(root) : rot(fa);
}
rot(root);
}
update(root);
return root;
}
int kth(int root, int k) {
for (;;) {
if (k <= t[t[root].ch[0]].size) {
root = t[root].ch[0];
} else if (k > t[t[root].ch[0]].size + 1) {
k -= t[t[root].ch[0]].size + 1;
root = t[root].ch[1];
} else {
return splay(root);
}
}
}
int findnum(int root, int num) {
while (root && t[root].num != num && t[root].ch[num > t[root].num])
root = t[root].ch[num > t[root].num];
return splay(root);
}
int findpre(int root) {
root = t[root].ch[0];
while (t[root].ch[1]) root = t[root].ch[1];
return splay(root);
}
int findnex(int root) {
root = t[root].ch[1];
while (t[root].ch[0]) root = t[root].ch[0];
return splay(root);
}
int links(int root1, int root2) {
if (!root1 || !root2) return root1 | root2;
root1 = kth(root1, t[root1].size);
t[root1].ch[1] = root2;
t[root2].fa = root1;
update(root1);
return root1;
}
void cuts(int root, int k, int &root1, int &root2) {
if (k == 0) {
root1 = 0;
root2 = root;
return;
}
root1 = kth(root, k);
root2 = t[root1].ch[1];
t[root1].ch[1] = t[root2].fa = 0;
update(root1);
return;
}
int build(int l, int r) {
if (r < l) return 0;
int mid = (l + r) >> 1;
int new_node = ++stot;
t[new_node].size = 1;
t[new_node].num = arr[mid].val;
id[arr[mid].id] = new_node;
t[new_node].fa = 0;
t[new_node].ch[0] = build(l, mid - 1);
t[new_node].ch[1] = build(mid + 1, r);
t[t[new_node].ch[0]].fa = new_node;
t[t[new_node].ch[1]].fa = new_node;
update(new_node);
return new_node;
}
void dfs(int root) {
if (t[root].ch[0]) {
dfs(t[root].ch[0]);
}
cout << "root " << root << ":" << t[root].num << " " << t[root].size << endl;
if (t[root].ch[1]) {
dfs(t[root].ch[1]);
}
return;
}
int main() {
pw2[0] = 1;
for (int i = 1; i <= 300000; ++i) {
pw2[i] = pw2[i - 1] * 2 % mod;
}
scanf("%d", &n);
if (n == 1) {
scanf("%*d");
scanf("%d", &m);
for (int i = 0; i <= m; ++i) {
printf("0\n");
}
return 0;
}
for (int i = 1; i <= n; ++i) {
scanf("%lld", &arr[i].val);
arr[i].id = i;
}
sort(arr + 1, arr + 1 + n, cmp);
root = build(1, n);
printf("%lld\n", t[root].ans * quickpow(inv2, n) % mod);
scanf("%d", &m);
while (m--) {
scanf("%d %d", &pos, &x);
root = splay(id[pos]);
root1 = t[root].ch[0];
t[root1].fa = t[root].ch[0] = 0;
root2 = t[root].ch[1];
t[root2].fa = t[root].ch[1] = 0;
root3 = root;
t[root3].num = x;
update(root3);
root = links(root1, root2);
root = findnum(root, x);
if (t[root].num > x) {
if (t[root].ch[0] == 0) {
root = links(root3, root);
} else {
root = findpre(root);
root2 = t[root].ch[1];
t[root2].fa = t[root].ch[1] = 0;
update(root);
root = links(root, root3);
root = links(root, root2);
}
} else {
if (t[root].ch[1] == 0) {
root = links(root, root3);
} else {
root = findnex(root);
root2 = t[root].ch[0];
t[root2].fa = t[root].ch[0] = 0;
update(root);
root1 = root;
root = links(root2, root3);
root = links(root, root1);
}
}
printf("%lld\n", t[root].ans * quickpow(inv2, n) % mod);
}
return 0;
}
| 2,800 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
std::ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, i;
cin >> n;
vector<int> a(n);
for (i = 0; 0 < n ? i < n : i > n; 0 < n ? i += 1 : i -= 1) {
cin >> a[i];
}
map<int, vector<pair<int, int> > > segs;
for (int r = 0; r < n; r++) {
int sum = 0;
for (int l = r; l >= 0; l--) {
sum += a[l];
segs[sum].push_back(make_pair(l, r));
}
}
vector<pair<int, int> > best;
int result = 0;
for (auto to : segs) {
vector<pair<int, int> > temp = to.second;
int cur = 0;
int r = -1;
vector<pair<int, int> > now;
for (auto seg : temp) {
if (seg.first > r) {
cur++;
now.push_back(seg);
r = seg.second;
}
}
if (cur > result) {
result = cur;
best = now;
}
}
cout << result << endl;
for (auto to : best) {
cout << to.first + 1 << " " << to.second + 1 << endl;
}
return 0;
}
| 1,900 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 10000001;
bool prime[MAX];
int primeCount = 0;
void buildSimple() {
for (int i = 0; i < MAX; i++) {
prime[i] = true;
}
prime[0] = prime[1] = false;
for (int i = 2; i < MAX; i++) {
if (!prime[i]) {
continue;
}
primeCount++;
for (int j = 2; j < MAX / i + 1; j++) {
if (i * j < MAX) {
prime[i * j] = false;
}
}
}
}
int main() {
int n;
buildSimple();
while (cin >> n) {
for (int i = 0; n > 0; i++) {
if (prime[i]) {
cout << i << ' ';
n--;
}
}
cout << endl;
}
return 0;
}
| 1,200 | CPP |
#include <bits/stdc++.h>
using namespace std;
int k;
int p;
int calc(const int v, const int k) {
int c = v;
int k_p = k;
if (p >= 1) c += v / k_p;
for (int i = 2; i <= p; ++i) {
k_p *= k;
c += v / k_p;
}
return c;
}
int main() {
int n;
cin >> n;
cin >> k;
if (k > n) {
cout << n << endl;
return 0;
}
p = log(n) / log(k);
int l = k;
int h = n;
while (l != h) {
int v = (l + h) / 2;
int c = calc(v, k);
if (c > n) {
h = v;
} else if (c < n) {
l = v + 1;
} else {
cout << v << endl;
return 0;
}
}
cout << h << endl;
return 0;
}
| 1,500 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int MaxN = (int)1e6 + 100;
long long tree[MaxN][2];
long long sum(int x, int y) {
long long ans = 0;
for (; x >= 0; x = (x & (x + 1)) - 1) ans += tree[x][y];
return ans;
}
void update(int x, int val, int y) {
for (; x <= MaxN; x |= (x + 1)) tree[x][y] += val;
}
int main() {
if (1) {
ios_base::sync_with_stdio(0);
cin.tie(0);
}
if (0) {
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
}
int n;
vector<int> v, s;
map<int, int> mp;
cin >> n;
v.resize(n);
s.resize(n);
for (int i = 0; i < n; i++) {
cin >> v[i];
s[i] = v[i];
}
sort(s.begin(), s.end());
for (int i = 0; i < n; i++) mp[s[i]] = i;
for (int i = 0; i < n; i++) v[i] = mp[v[i]];
reverse(v.begin(), v.end());
long long ans = 0;
for (auto i : v)
if (0) cerr << i << ' ';
if (0) cerr << '\n';
for (int i = 0; i < n; i++) {
long long tm = sum(v[i], 0);
update(v[i], 1, 0);
update(v[i], tm, 1);
ans += sum(v[i] - 1, 1);
if (0) cerr << tm << ' ' << ans << '\n';
}
cout << ans;
return 0;
}
| 1,900 | CPP |
l=int(input())
l1=str(l)
w=1
ma=-1
while w*w<=l :
s=str(w*w)
i=0
k=0
for x in s :
for j in range(i,len(l1)) :
if x==l1[j] :
k+=1
break
i=j+1
if k==len(s) :
ma=len(l1)-len(s)
w+=1
print(ma)
| 1,400 | PYTHON3 |
#include <bits/stdc++.h>
const char nl = '\n';
const int mod = (int)1e9 + 7;
int main() {
std::cin.tie(0)->std::ios::sync_with_stdio(0);
std::cin.exceptions(std::cin.failbit);
int t;
std::cin >> t;
while (t--) {
int n;
std::string s;
std::cin >> n >> s;
int l = -1, r = -1;
for (int i = 0; i < n - 1; i++) {
if ((s[i] == 'a' && s[i + 1] == 'b') ||
(s[i] == 'b' && s[i + 1] == 'a')) {
l = i + 1;
r = i + 2;
break;
}
}
std::cout << l << ' ' << r << nl;
}
}
| 800 | CPP |