solution
stringlengths 10
983k
| difficulty
int64 0
25
| language
stringclasses 2
values |
---|---|---|
n = int(input())
data = list(map(int, input().split()))
for i in range(0, n // 2, 2):
data[i], data[n - i - 1] = data[n - i - 1], data[i]
print(' '.join(map(str, data)))
| 8 | PYTHON3 |
A = [list(map(int, input().split())) for _ in range(3)]
s = sum(map(sum, A)) // 2
for i in range(3):
A[i][i] = s - sum(A[i])
print(*A[i]) | 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const double PI = 3.14159265359;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, k;
long long v;
cin >> n >> k >> v;
vector<int> a(n);
long long tot = 0;
for (int& i : a) {
cin >> i;
tot += i;
}
if (tot < v) {
cout << "NO";
return 0;
}
if (!(v % k)) {
cout << "YES" << endl;
for (int i = 1; i < n; i++) {
cout << a[i] / k + 1 << " " << i + 1 << " " << 1 << endl;
}
if (v) cout << v / k << " 1 2" << endl;
return 0;
}
vector<vector<int>> dp(k);
for (int i = 0; i < n; i++) {
vector<bool> fake(k, false);
int rem = a[i] % k;
for (int j = 0; j < k; j++) {
if (dp[j].size() && !fake[j]) {
int rem2 = (j + rem) % k;
if (!dp[rem2].size()) {
dp[rem2] = dp[j];
dp[rem2].push_back(i);
fake[rem2] = true;
}
}
}
if (!dp[rem].size()) {
dp[rem].push_back(i);
}
}
if (!dp[v % k].size()) {
cout << "NO";
return 0;
}
cout << "YES" << endl;
int gr = v % k;
int dest1 = dp[gr][0];
int dest2 = !dest1;
long long tVal = a[dp[gr][0]];
vector<bool> imp(n, false);
imp[dest1] = true;
for (int i = 1; i < dp[gr].size(); i++) {
cout << a[dp[gr][i]] / k + 1 << " " << dp[gr][i] + 1 << " " << dest1 + 1
<< endl;
imp[dp[gr][i]] = true;
tVal += a[dp[gr][i]];
}
if (tVal == v) return 0;
for (int i = 0; i < n; i++) {
if (!imp[i] && i != dest2) {
cout << a[i] / k + 1 << " " << i + 1 << " " << dest2 + 1 << endl;
}
}
if (tVal > v) {
cout << (tVal - v) / k << " " << dest1 + 1 << " " << dest2 + 1 << endl;
} else if (tVal < v) {
cout << (v - tVal) / k << " " << dest2 + 1 << " " << dest1 + 1 << endl;
}
return 0;
}
| 10 | CPP |
N=int(input())
a=[[0 for j in range(N-1)] for i in range(N)]
for i in range(N):
line=list(map(int,input().split()))
for j in range(N-1):
a[i][j]=line[j]-1
a[i]=a[i][::-1]
q=[]
#seen=[[False for j in range(N)] for i in range(N)]
# 選手nが試合できるならqueに入れる
def check(i):
if len(a[i])==0:
return False
j=a[i][-1]
if a[j][-1]==i:
q.append([i,j])
for i in range(N):
check(i)
from collections import defaultdict
day=0
while q:
day+=1
# q=sorted(q)
prevQ=q.copy()
q=[]
matched=defaultdict(list)
for p in prevQ:
i=p[0]
j=p[1]
if i>j:
i,j=j,i
if matched[i]:
continue
a[i].pop()
a[j].pop()
check(i)
check(j)
matched[i].append(j)
for i in range(N):
if len(a[i])!=0:
print(-1)
break
else:
print(day)
| 0 | PYTHON3 |
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
using namespace std;
static const int COUNTER_CLOCKWISE = 1; //??????????????¨??????
static const int CLOCKWISE = -1;
static const int ON_SEGMENT = 0;
static const int ONLINE_FRONT = 2;
static const int ONLINE_BACK = -2;
const double EPS = 1e-10;
bool equals(double a, double b) {
return fabs(a - b) < EPS;
}
class Point {
public:
double x, y;
Point(double x = 0, double y = 0): x(x), y(y) {}
Point operator + (Point p) {
return Point(x + p.x, y + p.y);
}
Point operator - (Point p) {
return Point(x - p.x, y - p.y);
}
Point operator * (double k) {
return Point(k * x, k * y);
}
Point operator / (double k) {
return Point(x / k, y / k);
}
double norm() {
return x * x + y * y;
}
double abs() {
return sqrt(norm());
}
bool operator < (const Point &p) const {
return x != p.x ? x < p.x : y < p.y;
}
bool operator == (const Point &p) const {
return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
}
};
typedef Point Vector;
double dot(Vector a, Vector b) {
return a.x * b.x + a.y * b.y;
}
double cross(Vector a, Vector b) {
return a.x * b.y - a.y * b.x;
}
class Segment {
public:
Point p1, p2;
Segment(Point p1, Point p2): p1(p1), p2(p2) {};
Point project(Point p) {
Vector a = Vector(p.x - p1.x, p.y - p1.y);
Vector b = Vector(p2.x - p1.x, p2.y - p1.y);
return p1 + p2 * (dot(a, b) / b.norm());
}
Point refrect(Point p) {
Point pro = project(p);
return pro * 2 - p;
}
double distance(Point p) {
Vector a = Vector((p - p1).x, (p - p1).y);
Vector b = Vector((p2 - p1).x, (p2 - p1).y);
Vector c = Vector((p - p2).x, (p - p2).y);
Vector d = Vector((p1 - p2).x, (p1 - p2).y);
if (dot(a, b) < 0) return (p - p1).abs();
else if (dot(c, d) < 0) return (p - p2).abs();
else return fabs(cross(a, b)) / b.abs();
}
};
int check(Vector v0, Vector v1) {
double c = cross(v0, v1);
if (equals(c, 0)) {
if (dot(v0, v1) < 0) return ONLINE_BACK;
else if (v1.norm() > v0.norm()) return ONLINE_FRONT;
else return ON_SEGMENT;
} else if (c > 0) {
return COUNTER_CLOCKWISE;
} else {
return CLOCKWISE;
}
}
int intersect(Segment s1, Segment s2) {
Point p1 = s1.p1, p2 = s1.p2, p3 = s2.p1, p4 = s2.p2;
Vector v0 = Vector((p2 - p1).x, (p2 - p1).y);
Vector v1 = Vector((p3 - p1).x, (p3 - p1).y);
Vector v2 = Vector((p4 - p1).x, (p4 - p1).y);
Vector v3 = Vector((p4 - p3).x, (p4 - p3).y);
Vector v4 = Vector((p1 - p3).x, (p1 - p3).y);
Vector v5 = Vector((p2 - p3).x, (p2 - p3).y);
if (check(v0, v1) * check(v0, v2) <= 0 && check(v3, v4) * check(v3, v5) <= 0) return 1;
return 0;
}
double sDistance(Segment s1, Segment s2) {
Point p1 = s1.p1, p2 = s1.p2, p3 = s2.p1, p4 = s2.p2;
if (intersect(s1, s2)) return 0;
double d1 = s1.distance(p3);
double d2 = s1.distance(p4);
double d3 = s2.distance(p1);
double d4 = s2.distance(p2);
return min(min(d1, d2), min(d3, d4));
}
int main() {
int q;
cin >> q;
int x0, y0, x1, y1, x2, y2, x3, y3;
for (int i = 0; i < q; i++) {
cin >> x0 >> y0 >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
Segment s1 = Segment(Point(x0, y0), Point(x1, y1));
Segment s2 = Segment(Point(x2, y2), Point(x3, y3));
cout << fixed << setprecision(10) << sDistance(s1, s2) << endl;
}
return 0;
} | 0 | CPP |
for _ in " "*int(input()):
x,y=map(int,input().split())
if x*2 <= y:
print(x,x*2)
else:
print(-1,-1) | 7 | PYTHON3 |
class BIT(object):
from operator import add
def __init__(self,A,f=add):
N=len(A)
self.__len=N
self.__f=f
# built (O(N))
self.__bit=A[:] # shallow copy
for i in range(N):
j=i+((i+1)&-(i+1))
if j<N: self.tree[j]=self.func(self.tree[i],self.tree[j])
def __repr__(self):
return str(self.tree)
@property
def func(self):
return self.__f
@property
def tree(self): # getterにしてる意味あんまない
return self.__bit
def add(self,i,w):
while(i<self.__len):
self.tree[i]=self.func(self.tree[i],w)
i+=(i+1)&-(i+1)
def sum(self,i):
res=0
while(i>-1):
res=self.func(res,self.tree[i])
i-=(i+1)&-(i+1)
return res
def bisect_left(self,w):
# sum(A)より大きければ一番右
if w>self.sum(self.__len-1): return self.__len
# 1個しかなく、右じゃないなら左
elif self.__len==1: return 0
# それ以外だと、len未満の2のべき乗からスタート
n=2**((self.__len-1).bit_length()-1)
res=0
while(n):
if res+n-1>self.__len-1: # index over(2べきじゃないときに起こる)
n//=2
continue
if w<=self.tree[res+n-1]: # 左にいく
n//=2
else: # 右にいく
w-=self.tree[res+n-1]
res+=n
n//=2
return res
def bisect_right(self,w):
if w>=self.sum(self.__len-1): return self.__len
elif self.__len==1: return 0
n=2**((self.__len-1).bit_length()-1)
res=0
while(n):
if w<self.tree[res+n-1]:
n//=2
else:
w-=self.tree[res+n-1]
res+=n
n//=2
return res
# input
n=int(input())
A=list(map(int,input().split()))
# built idx
idx=[0]*n
for i,a in enumerate(A): idx[a-1]=i
# built bit
bit=BIT([0]*n)
# calculate
score=0
for k in range(n,0,-1):
i=idx[k-1]
bit.add(i,1)
s=bit.sum(i)
# 0.5を引くことでbisect_left=bisect_right
l0=bit.bisect_left(s-1.5)-(s<=1) # 一番左を含むか含まないかで場合分け
l1=bit.bisect_left(s-2.5)-(s<=2) # 一番左を含むか含まないかで場合分け
r0=bit.bisect_left(s+0.5)
r1=bit.bisect_left(s+1.5)
score+=k*((l0-l1)*(r0-i)+(r1-r0)*(i-l0))
print(score) | 0 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
bool check(int a, int b) { return b >= a - 1 && b <= 2 * (a + 1); }
int main() {
int a, b, c, d;
scanf("%d%d%d%d", &a, &b, &c, &d);
if (check(a, d) || check(b, c))
printf("YES\n");
else
printf("NO\n");
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
int field[20][20];
int dp[20][20];
int n, m;
bool isIn(int x, int y){
return 0 <= x && x < n && 0 <= y && y < m;
}
int main(){
while(cin >> m >> n, n+m){
for(int i=0; i < n; i++) for(int j=0; j< m; j++){cin >> field[i][j];}
for(int i=0; i< 20; i++) for(int j=0; j< 20; j++) dp[i][j] = 0;
for(int i=0; i < m; i++) dp[0][i] = 1;
for(int i=0; i < n-1; i++){
for(int j=0; j < m; j++){
if(field[i][j] == 0){
for(int k=-1; k <= 1; k++){
if(isIn(i+1, j+k) && !(k != 0 && field[i+1][j+k] == 2)){
dp[i+1][j+k] += dp[i][j];
}
}
}
else if(field[i][j] == 2) dp[i+2][j] += dp[i][j];
}
}
for(int i=0; i< m; i++) if(field[n-1][i] != 1)dp[n][i] += dp[n-1][i];
long long count = 0;
for(int i=0; i< m; i++) count += dp[n][i];
cout << count << endl;
}
} | 0 | CPP |
#include<bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin>>t;
while (t--) {
int n, m, a, b;
cin>>n>>m>>a>>b;
int T;
if (a < b) T = b-1;
else T = n-b;
vector<int> aa(m);
for (int i=0; i<m; i++) cin>>aa[i];
sort(aa.begin(), aa.end());
int mx = min(m, abs(a-b)-1);
int ans = 0;
for (int t=1; t<=mx; t++) {
while (aa.size() && aa.back()+t > T) aa.pop_back();
if (aa.empty()) break;
ans++;
aa.pop_back();
}
cout<<ans<<endl;
}
}
| 10 | CPP |
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a,b;
cin>>a>>b;
cout<<ceil(((b-1)*1.0)/(a-1));
} | 0 | CPP |
import sys
from collections import Counter
input = sys.stdin.readline
for _ in range(int(input())):
n = int(input())
c01 = []
c1 = [0]*(n+1)
for x, y in (map(int, input().split()) for _ in range(n)):
c01.append(x)
if y == 1:
c1[x] += 1
f1cnt = [[] for _ in range(n+1)]
cnt01 = Counter(c01)
for k, v in cnt01.items():
f1cnt[v].append(c1[k])
ans = 0
ansf1 = 0
for i in range(n, 0, -1):
if f1cnt[i]:
ans += i
f1cnt[i].sort()
ansf1 += min(i, f1cnt[i].pop())
while f1cnt[i]:
f1cnt[i-1].append(f1cnt[i].pop())
print(ans, ansf1)
| 13 | PYTHON3 |
a=int(input())
b=input().split(" ")
l=[]
for x in range(a):
l.append([int(b[x]), x])
l.sort()
l.reverse()
total=0
count=0
for x in l:
total += x[0] * count + 1
count += 1
print(total)
out=""
for x in l:
out+=(str(x[1]+1)+" ")
print(out[:-1])
| 8 | PYTHON3 |
def solve(arr):
for i in range(1,len(arr)-1):
if arr[i]>arr[i-1] and arr[i]>arr[i+1]:
print("YES")
print(i,i+1,i+2)
return
print("NO")
t=int(input())
for i in range(t):
n=int(input())
arr=list(map(int,input().split()))
solve(arr)
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, amazing = 0;
bool less = true, greater = true;
cin >> n;
vector<int> c(n);
for (int i = 0; i < n; i++) {
cin >> c[i];
}
for (int i = 1; i < n; i++) {
less = true;
greater = true;
for (int j = i - 1; j < i && j >= 0; j--) {
if (c[i] >= c[j]) {
less = false;
break;
}
}
for (int j = i - 1; j < i && j >= 0; j--) {
if (c[i] <= c[j]) {
greater = false;
break;
}
}
if (less || greater) amazing++;
}
cout << amazing << endl;
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200005;
int lc[MAXN], rc[MAXN], top = 0, root = 0;
int sg[MAXN];
int N;
long long L;
char str[MAXN];
void push(int &nd, const char *str)
{
if (!nd) nd = ++top;
if (*str == '\0') return;
push(*str == '0' ? lc[nd] : rc[nd], str+1);
}
long long cnt = 0;
inline long long lowbit(long long i)
{ return i&(-i); }
void dfs(int nd, long long dep)
{
if (!nd) return;
dfs(lc[nd], dep-1), dfs(rc[nd], dep-1);
if ((!lc[nd] || !rc[nd]) && lc[nd]+rc[nd]) {
cnt ^= lowbit(dep);
}
}
int main()
{
scanf("%d%lld", &N, &L);
for (int i = 1; i <= N; i++) {
scanf("%s", str);
push(root, str);
}
dfs(root, L);
if (cnt != 0) cout << "Alice" << endl;
else cout << "Bob" << endl;
return 0;
}
| 0 | CPP |
q = int(input())
words = []
for i in range(q):
words.append(input())
def judge(x):
if len(x)>10:
return True
else:
return False
for i in range(q):
n = words[i]
if judge(n):
first = n[0:1]
last = n[-1:]
m = len(n)-2
print(first + str(m)+last)
else:
print(n) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int a[200005], mn[200005 * 4];
pair<int, int> lor[200005];
void build(int idx, int lo, int hi) {
if (lo == hi) {
mn[idx] = a[lo];
return;
}
int mid = (lo + hi) / 2;
build(idx * 2, lo, mid);
build(idx * 2 + 1, 1 + mid, hi);
mn[idx] = min(mn[idx * 2], mn[idx * 2 + 1]);
}
int query(int idx, int lo, int hi, int l, int r) {
if (hi < l || lo > r) return INT_MAX;
if (l <= lo && hi <= r) return mn[idx];
int mid = (lo + hi) / 2;
int x = query(idx * 2, lo, mid, l, r);
int y = query(idx * 2 + 1, 1 + mid, hi, l, r);
return min(x, y);
}
int main() {
int n, q;
scanf("%d%d", &n, &q);
int z = 0;
bool oka = false;
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
if (a[i] == q && q) oka = true;
lor[a[i]] = pair<int, int>(-1, -1);
if (a[i] == 0) z++;
}
if (!q) {
cout << "YES\n";
for (int i = 1; i <= n; i++) {
cout << a[i] << " ";
}
} else if (z == n) {
cout << "YES\n";
for (int i = 1; i <= n; i++) {
cout << q << " ";
}
} else {
for (int i = 2; i <= n; i++) {
if (a[i] == 0) {
a[i] = (oka == false ? q : a[i - 1]);
oka = true;
}
}
for (int i = n - 1; i; i--) {
if (a[i] == 0) {
a[i] = oka == false ? q : a[i + 1];
oka = true;
}
}
vector<int> v;
for (int i = 1; i <= n; i++) {
if (lor[a[i]].first == -1) {
v.push_back(a[i]);
lor[a[i]] = pair<int, int>(i, i);
} else
lor[a[i]].second = i;
}
build(1, 1, n);
for (int i = 0; i < v.size(); i++) {
if (query(1, 1, n, lor[v[i]].first, lor[v[i]].second) < v[i]) {
n = -1;
break;
}
}
if (n == -1 || oka == false)
cout << "NO";
else {
cout << "YES\n";
for (int i = 1; i <= n; i++) cout << a[i] << " ";
}
}
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (a < b) swap(a, b);
if (b == 0) return a;
while ((a = a % b) != 0) {
swap(a, b);
}
return b;
}
long long mpow(long long x, long long y, long long m) {
long long res = 1;
while (y > 0) {
if (y & 1) res = res * x % m;
y = y >> 1;
x = x * x % m;
}
return res;
}
long long ncr(long long n, long long r) {
if (r > n) return 0;
long long res = 1;
for (long long i = (1); i < (r + 1); i++) res = res * (n - r + i) / i;
return res;
}
long long *sieve(long long n) {
long long *lpf = new long long[n + 1];
for (long long i = 1; i <= n; i++) lpf[i] = i;
long long rt = (long long)floor(sqrt(n)) + 1;
for (long long i = (2); i < (rt); i++) {
if (lpf[i] != i) continue;
for (long long j = i * i; j <= n; j += i) {
if (lpf[j] == j) lpf[j] = i;
}
}
return lpf;
}
void solve() {
long long n, k;
cin >> n >> k;
long long a[n], next[n], sum = 0;
for (long long i = (0); i < (n); i++) cin >> a[i];
for (long long i = (n - 1); i > (-1); i--) {
if (a[i] == 1) {
if (i + 1 != n && a[i + 1] == 1)
next[i] = next[i + 1];
else
next[i] = i + 1;
} else
next[i] = i;
sum += a[i];
}
long long ans = 0;
for (long long i = (0); i < (n); i++) {
long long p = 1, s = 0, j = i;
while (j != n && p <= sum * k / a[j]) {
if (a[j] == 1) {
if (p % k == 0) {
long long req = p / k;
if (req > s && req <= s + next[j] - j) ans++;
}
s += next[j] - j;
j = next[j];
continue;
}
p *= a[j];
s += a[j];
if (p == s * k) ans++;
j++;
}
}
cout << ans;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long t = 1;
for (long long i = (1); i < (t + 1); i++) {
solve();
cout << "\n";
}
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
int k,q;
long long modm(int x,int m){
if(x%m == 0) return m;
return x%m;
}
void solve(){
int i,j;
string str;
cin >> k >> q;
vector<long long> d(k);
for(i = 0;i < k;i++) cin >> d[i];
for(i = 0;i < q;i++){
long long n,x,m;
cin >> n >> x >> m;
vector<long long> dm(k);
for(j = 0;j < k;j++) dm[j] = modm(d[j],m);
long long sd = 0;
for(j = 0;j < k;j++) sd += dm[j];
sd *= (n-1) / k;
sd += x%m;
for(j = 0;j < (n-1)%k;j++) sd += dm[j];
cout << n-1-sd/m << endl;
}
}
int main(){
solve();
}
| 0 | CPP |
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
int N;
cin >> N;
vector<vector<int>> Dist(N, vector<int>(N, N));
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
char c;
cin >> c;
if (c == '1') Dist[i][j] = 1;
}
}
for (int k = 0; k < N; k++) {
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
Dist[i][j] = min(Dist[i][j], Dist[i][k] + Dist[k][j]);
}
}
}
vector<int> Color(N, 0);
Color[0] = 1;
int MAX = 0;
for (int i = 0; i < N; i++) {
for (int j = i + 1; j < N; j++) {
if (Dist[i][j] == N) continue;
int c = Dist[i][j] % 2 == 0 ? Color[i] : -Color[i];
if (Color[j] == 0) Color[j] = c;
else {
if (Color[j] != c) {
cout << -1 << endl;
return 0;
}
}
MAX = max(MAX, Dist[i][j]);
}
}
cout << MAX + 1 << endl;
} | 0 | CPP |
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include <fstream>
#include <array>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcountll
#define ll long long
#define mp make_pair
#define x first
#define y second
#define Time (double)clock()/CLOCKS_PER_SEC
#define debug(x) std::cerr << #x << ": " << x << '\n';
#define FORI(i,a,b) for (int i = (a); i < (b); ++i)
#define FOR(i,a) FORI(i,0,a)
#define ROFI(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define ROF(i,a) ROFI(i,0,a)
#define rep(a) FOR(_,a)
#define each(a,x) for (auto& a: x)
#define FORN(i, n) FORI(i, 1, n + 1)
using vi = vector<int>;
template <typename T>
std::istream& operator >>(std::istream& input, std::pair <T, T> & data)
{
input >> data.x >> data.y;
return input;
}
template <typename T>
std::istream& operator >>(std::istream& input, std::vector<T>& data)
{
for (T& x : data)
input >> x;
return input;
}
template <typename T>
std::ostream& operator <<(std::ostream& output, const pair <T, T> & data)
{
output << "(" << data.x << "," << data.y << ")";
return output;
}
template <typename T>
std::ostream& operator <<(std::ostream& output, const std::vector<T>& data)
{
for (const T& x : data)
output << x << " ";
return output;
}
std::ostream& operator <<(std::ostream& output, const __int128 &x)
{
__int128 n = x;
if (n == 0) {
output << "0";
return output;
}
if (n < 0) {
n = -n;
output << "-";
}
string s;
while (n) {
s += '0' + (n%10);
n /= 10;
}
reverse(all(s));
cout << s;
return output;
}
ll div_up(ll a, ll b) { return a/b+((a^b)>0&&a%b); } // divide a by b rounded up
ll div_down(ll a, ll b) { return a/b-((a^b)<0&&a%b); } // divide a by b rounded down
ll math_mod(ll a, ll b) { return a - b * div_down(a, b); }
#define tcT template<class T
#define tcTU tcT, class U
tcT> using V = vector<T>;
tcT> bool ckmin(T& a, const T& b) {
return b < a ? a = b, 1 : 0;
} // set a = min(a,b)
tcT> bool ckmax(T& a, const T& b) {
return a < b ? a = b, 1 : 0;
}
ll gcd(ll a, ll b) {
while (b) {
tie(a, b) = mp(b, a % b);
}
return a;
}
int Bit(int mask, int bit) { return (mask >> bit) & 1; }
template<int MOD, int RT> struct mint {
static const int mod = MOD;
static constexpr mint rt() { return RT; } // primitive root for FFT
int v; explicit operator int() const { return v; } // explicit -> don't silently convert to int
mint() { v = 0; }
mint(ll _v) { v = (int)((-MOD < _v && _v < MOD) ? _v : _v % MOD);
if (v < 0) v += MOD; }
friend bool operator==(const mint& a, const mint& b) {
return a.v == b.v; }
friend bool operator!=(const mint& a, const mint& b) {
return !(a == b); }
friend bool operator<(const mint& a, const mint& b) {
return a.v < b.v; }
friend string ts(mint a) { return to_string(a.v); }
mint& operator+=(const mint& m) {
if ((v += m.v) >= MOD) v -= MOD;
return *this; }
mint& operator-=(const mint& m) {
if ((v -= m.v) < 0) v += MOD;
return *this; }
mint& operator*=(const mint& m) {
v = (int)((ll)v*m.v%MOD); return *this; }
mint& operator/=(const mint& m) { return (*this) *= inv(m); }
friend mint pow(mint a, ll p) {
mint ans = 1; assert(p >= 0);
for (; p; p /= 2, a *= a) if (p&1) ans *= a;
return ans; }
mint & operator ^=(const int &p) { return (*this) = pow(this, p); }
friend mint inv(const mint& a) { assert(a.v != 0);
return pow(a,MOD-2); }
mint operator-() const { return mint(-v); }
mint& operator++() { return *this += 1; }
mint& operator--() { return *this -= 1; }
friend mint operator+(mint a, const mint& b) { return a += b; }
friend mint operator-(mint a, const mint& b) { return a -= b; }
friend mint operator*(mint a, const mint& b) { return a *= b; }
friend mint operator/(mint a, const mint& b) { return a /= b; }
friend mint operator^(mint a, const int p) { return pow(a, p); }
};
const int MOD = 1e9+7;
typedef mint<MOD,5> mi; // 5 is primitive root for both common mods
typedef vector<mi> vmi;
std::ostream& operator << (std::ostream& o, const mi& a)
{
cout << a.v;
return o;
}
vector<vmi> scmb; // small combinations
void genComb(int SZ) {
scmb.assign(SZ,vmi(SZ)); scmb[0][0] = 1;
FORI(i,1,SZ) FOR(j,i+1)
scmb[i][j] = scmb[i-1][j]+(j?scmb[i-1][j-1]:0);
}
vmi invs, fac, ifac; // make sure to convert to LL before doing any multiplications ...
void genFac(int SZ) {
invs.resize(SZ), fac.resize(SZ), ifac.resize(SZ);
invs[1] = fac[0] = ifac[0] = 1;
FORI(i,2,SZ) invs[i] = mi(-(ll)MOD/i*(int)invs[MOD%i]);
FORI(i,1,SZ) {
fac[i] = fac[i-1]*i;
ifac[i] = ifac[i-1]*invs[i];
}
}
mi comb(int a, int b) {
if (a < b || b < 0) return 0;
assert(a < fac.size());
return fac[a]*ifac[b]*ifac[a-b];
}
const int N = 107;
int n, c[N], b[N], pb[N], ppb[N];
mi dp[N][N * N];
const int C = 2e5+7, S = 100 * 1000;
bool used[C];
mi res[C];
signed main() {
#ifdef LOCAL
#else
#define endl '\n'
ios_base::sync_with_stdio(0); cin.tie(0);
#endif
cin >> n;
FOR (i, n) {
cin >> c[i];
}
FOR (i, n - 1) {
cin >> b[i];
pb[i + 1] = pb[i] + b[i];
}
FORN (i, n - 1) {
ppb[i] = ppb[i - 1] + pb[i];
}
mi al = 1;
FOR (i, n) {
al *= c[i] + 1;
}
int q;
cin >> q;
rep (q) {
int key;
cin >> key;
if (key * n < -ppb[n - 1]) {
cout << al << endl;
continue;
}
if (key * n > 100 * n - ppb[n - 1]) {
cout << 0 << endl;
continue;
}
if (used[key + S]) {
cout << res[key + S] << endl;
continue;
}
FOR (i, N) {
FOR (j, N * N) {
dp[i][j] = 0;
}
}
dp[0][0] = 1;
FOR (i, n) {
FOR (sum, N * N) {
mi x = dp[i][sum];
if (x.v) {
FOR (add, c[i] + 1) {
if (sum+add-ppb[i] >= key*(i + 1)) {
dp[i + 1][sum + add] += dp[i][sum];
}
}
}
}
}
mi ans = 0;
FOR (i, N * N) {
ans += dp[n][i];
}
used[key + S] = 1;
res[key + S] = ans;
cout << ans << endl;
}
} | 9 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int size1 = 1e5;
const int INF = 1e9;
string s;
struct vertex {
int a = 0;
int t = 0;
int g = 0;
int c = 0;
};
vector<vector<int> > num(size1);
vector<vector<vector<vertex> > > tree(11);
vector<vector<vector<char> > > v(11);
void build_tree(int pok, int pok1, int tl, int tr, int pos) {
if (tl == tr) {
char c = v[pok][pok1][tl];
if (c == 'A') {
tree[pok][pok1][pos].a = 1;
}
if (c == 'T') {
tree[pok][pok1][pos].t = 1;
}
if (c == 'G') {
tree[pok][pok1][pos].g = 1;
}
if (c == 'C') {
tree[pok][pok1][pos].c = 1;
}
} else {
int tm = (tl + tr) / 2;
build_tree(pok, pok1, tl, tm, pos * 2);
build_tree(pok, pok1, tm + 1, tr, pos * 2 + 1);
tree[pok][pok1][pos].a =
tree[pok][pok1][pos * 2].a + tree[pok][pok1][pos * 2 + 1].a;
tree[pok][pok1][pos].t =
tree[pok][pok1][pos * 2].t + tree[pok][pok1][pos * 2 + 1].t;
tree[pok][pok1][pos].g =
tree[pok][pok1][pos * 2].g + tree[pok][pok1][pos * 2 + 1].g;
tree[pok][pok1][pos].c =
tree[pok][pok1][pos * 2].c + tree[pok][pok1][pos * 2 + 1].c;
}
}
void update1(int num1, char c, char c1, int pok, int pok1, int tl, int tr,
int pos) {
if (tl == tr) {
if (c == 'A') {
tree[pok][pok1][pos].a--;
}
if (c == 'T') {
tree[pok][pok1][pos].t--;
}
if (c == 'G') {
tree[pok][pok1][pos].g--;
}
if (c == 'C') {
tree[pok][pok1][pos].c--;
}
if (c1 == 'A') {
tree[pok][pok1][pos].a++;
}
if (c1 == 'T') {
tree[pok][pok1][pos].t++;
}
if (c1 == 'G') {
tree[pok][pok1][pos].g++;
}
if (c1 == 'C') {
tree[pok][pok1][pos].c++;
}
} else {
int tm = (tl + tr) / 2;
if (tl <= num1 && num1 <= tm) {
update1(num1, c, c1, pok, pok1, tl, tm, pos * 2);
} else {
update1(num1, c, c1, pok, pok1, tm + 1, tr, pos * 2 + 1);
}
tree[pok][pok1][pos].a =
tree[pok][pok1][pos * 2].a + tree[pok][pok1][pos * 2 + 1].a;
tree[pok][pok1][pos].t =
tree[pok][pok1][pos * 2].t + tree[pok][pok1][pos * 2 + 1].t;
tree[pok][pok1][pos].g =
tree[pok][pok1][pos * 2].g + tree[pok][pok1][pos * 2 + 1].g;
tree[pok][pok1][pos].c =
tree[pok][pok1][pos * 2].c + tree[pok][pok1][pos * 2 + 1].c;
}
}
int sum(char c, int pok, int pok1, int l, int r, int tl, int tr, int pos) {
if (l <= tl && tr <= r) {
if (c == 'A') {
return tree[pok][pok1][pos].a;
}
if (c == 'T') {
return tree[pok][pok1][pos].t;
}
if (c == 'G') {
return tree[pok][pok1][pos].g;
}
if (c == 'C') {
return tree[pok][pok1][pos].c;
}
} else {
int res = 0;
int tm = (tl + tr) / 2;
if (max(l, tl) <= min(r, tm)) {
res += sum(c, pok, pok1, l, r, tl, tm, pos * 2);
}
if (max(l, tm + 1) <= min(r, tr)) {
res += sum(c, pok, pok1, l, r, tm + 1, tr, pos * 2 + 1);
}
return res;
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int i, j, k;
cin >> s;
int n = s.size();
s = ' ' + s;
for (i = 1; i <= 10; i++) {
tree[i].resize(i);
for (j = 0; j < i; j++) {
tree[i][j].resize(4 * (n / i + 1));
}
}
for (i = 1; i <= n; i++) {
num[i].resize(11);
}
for (i = 1; i <= 10; i++) {
v[i].resize(11);
}
for (i = 1; i <= 10; i++) {
for (j = 0; j < i; j++) {
v[i][j].push_back(0);
}
}
for (i = 1; i <= n; i++) {
for (j = 1; j <= 10; j++) {
if (i > j) {
num[i][j] = num[i - j][j] + 1;
} else {
num[i][j] = 1;
}
v[j][i % j].push_back(s[i]);
}
}
for (i = 1; i <= 10; i++) {
for (j = 0; j < i; j++) {
if (v[i][j].size() > 1) {
build_tree(i, j, 1, v[i][j].size() - 1, 1);
}
}
}
int q;
cin >> q;
for (i = 1; i <= q; i++) {
int t;
cin >> t;
if (t == 1) {
int pos;
char c;
cin >> pos >> c;
for (j = 1; j <= 10; j++) {
update1(num[pos][j], s[pos], c, j, pos % j, 1, v[j][pos % j].size() - 1,
1);
}
s[pos] = c;
} else {
int l, r;
string s1;
cin >> l >> r >> s1;
int ans = 0;
int m = s1.size();
for (j = 0; j < min(int(s1.size()), r - l + 1); j++) {
int sum1 = sum(s1[j], m, (l + j) % m, num[l + j][m],
num[r - ((r - l - j) % m + m) % m][m], 1,
v[m][(l + j) % m].size() - 1, 1);
ans += sum1;
}
cout << ans << endl;
}
}
return 0;
}
| 9 | CPP |
#include<iostream>
int main(){
int q,year[100][3];
std::cin>>q;
for(int i=0;i<q;i++){
for(int j=0;j<3;j++){
std::cin>>year[i][j];
}
}
for(int i=0;i<q;i++){
int count=0;
while(year[i][0]>=1&&year[i][1]>=1&&year[i][2]>=1){
year[i][0]--,year[i][1]--,year[i][2]--;
count++;
}while(year[i][0]>=2&&year[i][1]>=1){
year[i][0]-=2,year[i][1]--;
count++;
}while(year[i][0]>=3){
year[i][0]-=3;
count++;
}
std::cout<<count<<std::endl;
}
return 0;
} | 0 | CPP |
a,b=map(int,input().split())
c=0
h=min(a,b)
h1=max(a,b)
for i in range(h,h1+1):
m=str(i)
l1=len(m)
l2=len(set(m))
if l1==l2:
c=c+1
ans=i
break
if c==1:
print(ans)
else:
print(-1)
| 7 | PYTHON3 |
#include<bits/stdc++.h>
using namespace std;
char N[3];
int main(){
cin>>N;
cout<<(N[0]==N[2]?"Yes":"No")<<endl;
}
| 0 | CPP |
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
#include <iomanip>
int main() {
cout << fixed << setprecision(12);
int W, H, w, h, x, y; cin >> W >> H >> w >> h >> x >> y;
int left = max(-W / 2, x - w / 2),
right = min( W / 2, x + w / 2),
bottom = max(-H / 2, y - h / 2),
top = min( H / 2, y + h / 2);
double cx = (left + right) / 2.0,
cy = (bottom + top) / 2.0;
cout << cy / cx << endl;
return 0;
}
| 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long sum(long long n) {
long long ans = 0;
while (n) ans += n % 10, n /= 10;
return ans;
}
long long solve(long long n, long long s) {
if (sum(n) <= s) return 0;
int add = 10 - (n % 10);
return (n % 10 ? (solve(n + add, s) + add) : (solve(n / 10, s) * 10));
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while (t--) {
long long n, s;
cin >> n >> s;
cout << solve(n, s) << '\n';
}
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM =
chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
long long power(long long x, long long y, long long p) {
long long res = 1;
x = x % p;
while (y > 0) {
if (y & 1) res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
const int N = 1e5 + 7;
int n, m, x[N + N], t[N + N], d[N + N];
int a[N + N];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n >> m;
for (int i = 0; i < n + m; i++) cin >> x[i];
for (int i = 0; i < n + m; i++) cin >> d[i];
t[0] = d[0];
for (int i = 1; i < n + m; i++) t[i] = d[i] + t[i - 1];
for (int i = 0; i < n + m; i++) {
if (d[i] == 0) {
int l = -1;
if (t[i] > 0) {
l = lower_bound(t, t + i, t[i]) - t;
}
int r = -1;
if (t[n + m - 1] > t[i]) {
r = lower_bound(t + i, t + n + m, t[i] + 1) - t;
}
if (l != -1 && r != -1) {
if (abs(x[l] - x[i]) <= abs(x[r] - x[i]))
a[l]++;
else
a[r]++;
continue;
}
if (l != -1) {
a[l]++;
continue;
}
if (r != -1) {
a[r]++;
continue;
}
}
}
for (int i = 0; i < n + m; i++)
if (d[i] == 1) cout << a[i] << " ";
cout << '\n';
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
const double eps = 1e-8;
bool hole[1000005];
bool bone[1000005];
int main() {
int n, m, k;
cin >> n >> m >> k;
memset(hole, false, sizeof(hole));
memset(bone, false, sizeof(bone));
for (int i = 0; i < m; i++) {
int x;
scanf("%d", &x);
hole[x] = true;
}
int ans = 0;
int idx = 1;
bone[1] = true;
if (hole[1]) ans = 1;
for (int i = 0; i < k; i++) {
int x, y;
scanf("%d%d", &x, &y);
if (ans) continue;
if (bone[x]) {
bone[y] = true;
bone[x] = false;
idx = y;
if (hole[y]) ans = y;
} else if (bone[y]) {
bone[x] = true;
bone[y] = false;
idx = x;
if (hole[x]) ans = x;
}
}
if (ans)
cout << ans << endl;
else
cout << idx << endl;
}
| 8 | CPP |
B=int(input())
b=sorted(list(map(int,input().split())))
G=int(input())
g=sorted(list(map(int,input().split())))
d=0
#while True:
for i in b:
for j in g:
if abs(i-j)==1 or i-j==0:
d+=1
g.remove(j)
break
print(d) | 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1);
const int N = 1e5 + 5;
int a[N];
int b[N];
int main() {
ios_base::sync_with_stdio(false);
int T;
cin >> T;
while (T--) {
int n;
cin >> n;
vector<int> ve1, ve2;
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < n; i++) cin >> b[i];
for (int i = 0; i < n; i++) ve1.push_back(a[i]);
for (int i = 0; i < n; i++) ve2.push_back(b[i]);
sort(ve1.begin(), ve1.end());
sort(ve2.begin(), ve2.end());
multiset<pair<int, long long> > mse;
bool res = true;
for (int i = 0; i < (n + 1) / 2; i++) {
int mn = min(a[i], a[n - i - 1]);
int mx = max(a[i], a[n - i - 1]);
mse.insert({mn, mx});
}
for (int i = 0; i < (n + 1) / 2; i++) {
int mn = min(b[i], b[n - i - 1]);
int mx = max(b[i], b[n - i - 1]);
pair<int, long long> x = {mn, mx};
if (mse.find(x) != mse.end()) {
mse.erase(mse.find(x));
} else {
res = false;
}
}
if (res)
cout << "YES\n";
else
cout << "NO\n";
}
return 0;
}
| 12 | CPP |
import os
import sys
from io import BytesIO, IOBase
from collections import defaultdict
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")
# n, k = map(int, input().split(" "))
# l = list(map(int, input().split(" ")))
n, m, a = map(int, input().split(" "))
l = []
t = 0
for i in range(n):
x, y = map(int, input().split(" "))
l.append([y, x])
t+=x
if t >= a*n:
print(0)
else:
l.sort()
req = a*n - t
c = 0
for i in range(n):
if l[i][1] <m:
pos = m-l[i][1]
ad = min(req, pos)
req-= ad
c+= ad*l[i][0]
if req==0:
break
print(c) | 9 | PYTHON3 |
n=int(input())
l=sorted(map(int,input().split()))
s=0
c=0
while(s<=sum(l)):
s+=l.pop()
c=c+1
print(c) | 7 | PYTHON3 |
import sys
input=sys.stdin.readline
s=list(input().rstrip())
n=len(s)
cnt=[[0]*(n+1) for i in range(26)]
for i in range(1,n+1):
cnt[ord(s[i-1])-ord("a")][i]+=1
for j in range(26):
cnt[j][i]+=cnt[j][i-1]
q=int(input())
for _ in range(q):
l,r=map(int,input().split())
if s[r-1]!=s[l-1]:
print("Yes")
continue
if r-l+1==1:
print("Yes")
continue
flag=0
for i in range(26):
flag+=(cnt[i][r]-cnt[i][l-1]>0)
if flag>=3:
print("Yes")
else:
print("No") | 8 | PYTHON3 |
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
using namespace std;
#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
typedef vector<int> vi;
typedef pair<int,int> pii;
int main(void) {
int i,j;
int a,b,c,d,e;
while(scanf("%d,%d,%d,%d,%d",&a,&b,&c,&d,&e)!=EOF){
vi v(14,0);
v[a]++;
v[b]++;
v[c]++;
v[d]++;
v[e]++;
bool ans=false;
if(v[1]&&v[10]&&v[11]&&v[12]&&v[13]){
cout<<"straight"<<endl;
ans=true;
}
rep(i,10)
if(v[i]&&v[i+1]&&v[i+2]&&v[i+3]&&v[i+4]){
cout<<"straight"<<endl;
ans=true;
}
if(ans)continue;
int na=0,nb=0,nc=0;
rep(i,14)
if(v[i]==2)na++;
else if(v[i]==3)nb++;
else if(v[i]==4)nc++;
if(nc)cout<<"four card"<<endl;
else if(na&&nb)cout<<"full house"<<endl;
else if(nb)cout<<"three card"<<endl;
else if(na==2)cout<<"two pair"<<endl;
else if(na)cout<<"one pair"<<endl;
else cout<<"null"<<endl;
END:;
}
} | 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int t;
cin >> t;
while (t--) {
long long int n, i, j, x, y, a[100005], v[100005];
map<long long int, long long int> ma;
cin >> n;
for (i = 1; i <= n; i++) {
cin >> a[i];
ma[a[i]] = i;
v[i] = 0;
}
long long int fl = 0, p = -1;
for (i = 1; i <= n; i++) {
if (!v[ma[i]]) {
for (j = ma[i]; j <= n; j++) {
if (v[j] == 1 || j == n + 1) {
break;
}
if (a[j] != j - ma[i] + i) {
fl = 1;
break;
}
v[j] = 1;
}
}
}
if (fl) {
cout << "No\n";
} else {
cout << "Yes\n";
}
}
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
long long n;
cin >> n;
vector<pair<long long, long long>> r(n);
for (long long i = 0; i < n; ++i) cin >> r[i].first >> r[i].second;
long long k;
cin >> k;
--k;
long long f = 0;
for (auto x : r) {
if ((k >= x.first) && (k >= x.second))
++f;
else
break;
}
cout << n - f;
}
| 7 | CPP |
a, b, c = map(int, input().split())
print(f"{c} {a} {b}") | 0 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
ostream& operator<<(ostream& out, vector<T> v) {
for (T t : v) out << t << ' ';
return out;
}
template <typename T>
ostream& operator<<(ostream& out, set<T> v) {
for (T t : v) out << t << ' ';
return out;
}
template <typename T>
ostream& operator<<(ostream& out, pair<T, T> v) {
out << v.first << ' ' << v.second;
return out;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin >> n;
vector<long long> a(n, 0), b(n, 0);
for (int i = 0; i < n; ++i) cin >> b[i];
int posi = -1;
for (int i = 0; i < n; ++i) {
int j = (i + n - 1) % n;
if (b[i] > b[j]) {
posi = i;
break;
}
}
if (posi == -1) {
if (b[0] == 0) {
cout << "YES\n";
for (int i = 0; i < n; ++i) cout << 1 << ' ';
return 0;
}
cout << "NO\n";
return 0;
}
cout << "YES\n";
a[posi] = b[posi];
for (int count = 1; count < n; ++count) {
int next = (posi + n - 1) % n;
int twonext = (posi + n - 2) % n;
long long k = max(0ll, (b[twonext] - b[next]) / a[posi]);
a[next] = b[next] + k * a[posi];
while (a[next] <= b[twonext]) a[next] += a[posi];
posi = next;
}
cout << a;
return 0;
}
| 11 | CPP |
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <string>
#include <fstream>
#include <vector>
#include <queue>
#include <stack>
#include <sstream>
#include <list>
#include <map>
#include <set>
#include <limits>
#include <random>
#include <functional>
#include <unordered_set>
#include <unordered_map>
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef unsigned int ui;
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
using namespace std;
const int N = 5010;
const int M = 1010;
const int MOD = 1000000007;
const int INF = 1009000999;
const ll LINF = (1ll << 60) + 1337;
const ld EPS = 0.0000000001;
int add(int x, int y)
{
x += y;
while (x >= MOD) x -= MOD;
while (x < 0) x += MOD;
return x;
}
int sub(int x, int y)
{
return add(x, -y);
}
int mul(int x, int y)
{
return (x * 1ll * y) % MOD;
}
int binpow(int x, int y)
{
int z = 1;
while (y > 0)
{
if (y % 2 == 1) z = mul(z, x);
x = mul(x, x);
y /= 2;
}
return z;
}
int inv(int x)
{
return binpow(x, MOD - 2);
}
int divide(int x, int y)
{
return mul(x, inv(y));
}
int n, x, q;
int dp[N][N];
int w[N];
int a[N];
int f(int i, int m) {
if (dp[i][m] != -1) return dp[i][m];
if (m == 0) return dp[i][m] = 1;
dp[i][m] = 0;
if (i - 1 >= 0) dp[i][m] = add(dp[i][m], f(i - 1, m - 1));
if (i + 1 < n) dp[i][m] = add(dp[i][m], f(i + 1, m - 1));
return dp[i][m];
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifdef _DEBUG
freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#endif
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
dp[i][j] = -1;
}
}
cin >> n >> x >> q;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int sum = 0;
for (int i = 0; i < n; i++) {
f(i, x);
}
for(int i = 0; i <= x; i++) {
for (int j = 0; j < n; j++) {
w[j] = add(w[j], mul(dp[j][i], dp[j][x - i]));
}
}
for (int i = 0; i < n; i++) {
sum = add(sum, mul(w[i], a[i]));
}
while (q--) {
int i, v;
cin >> i >> v;
i--;
sum = sub(sum, mul(w[i], a[i]));
a[i] = v;
sum = add(sum, mul(w[i], a[i]));
cout << sum << "\n";
}
}
/*
Important stuff
- int overflow
- array bounds
- special cases (n=1, max n) maybe adhoc problem
- doubles are read for a long time (4 * 10 ^ 5 danger GNU vs MS ICPC 2020 1/4)
- don't get stuck on one approach
- don't get stuck on one problem
- recheck submissions if near the end of the tournament and there is nothing to do
- do something instead of nothing and stay organized
*/ | 10 | CPP |
n = int(input())
a = list(map(int, input().split()))
a = list(map(lambda x: x % 2, a))
print(a.index(1 if a.count(1) == 1 else 0) + 1)
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
long long int power(long long int a, long long int b) {
if (b == 0) return 1;
long long int c = power(a, b >> 1);
c = (c * c) % 1000000007;
if (b & 1) return (a * c) % 1000000007;
return c;
}
const int N = (int)1e5 + 5;
const int Q = 301;
int dp[N][10], num[N][10];
string query[N];
string s, temp;
void solve() {
cin >> s;
int q, p;
cin >> q;
for (int i = 0; i <= q - 1; i++) {
cin >> temp;
query[i] = temp;
}
for (int i = 0; i <= 9; i++) {
dp[q][i] = i;
num[q][i] = 1;
}
for (int i = q - 1; i >= 0; i--) {
for (int j = 0; j <= 9; j++) {
dp[i][j] = dp[i + 1][j];
num[i][j] = num[i + 1][j];
}
p = query[i][0] - '0';
temp = query[i].substr(3, query[i].size() - 3);
long long int pos = 0;
dp[i][p] = 0;
for (int k = temp.size() - 1; k >= 0; k--) {
dp[i][p] += (dp[i + 1][temp[k] - '0'] * power(10, pos)) % 1000000007;
if (dp[i][p] >= 1000000007) dp[i][p] -= 1000000007;
pos += num[i][temp[k] - '0'];
pos %= (1000000007 - 1);
}
num[i][p] = pos;
}
int ans = 0;
int pos = 0;
for (int i = s.size() - 1; i >= 0; i--) {
ans += (dp[0][s[i] - '0'] * power(10, pos)) % 1000000007;
if (ans >= 1000000007) ans -= 1000000007;
pos += num[0][s[i] - '0'];
pos %= (1000000007 - 1);
}
cout << ans;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int T = 1;
for (int TC = 1; TC <= T; TC++) {
solve();
cout << "\n";
}
}
| 9 | CPP |
def inp_n():
return int(input())
def inp_list():
return list(map(int, input().split()))
def inp_mul_num():
return map(int, input().split())
def is_odd(n):
if n & 1:
return True
return False
from collections import defaultdict
import math
for _ in range(inp_n()):
a, b = inp_mul_num()
if a < b:
a, b = b, a
if a == b:
print((a+b)**2)
elif a < 2*b:
print((b*2)**2)
else:
print(a**2)
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, i, x1, x2, y1, y2;
scanf("%lld", &n);
printf("YES\n");
while (n--) {
scanf("%lld%lld", &x1, &y1);
scanf("%lld%lld", &x2, &y2);
if (x1 < 0) x1 = -(x1);
if (y1 < 0) y1 = -(y1);
if (x1 % 2 == 0 && y1 % 2 == 0)
printf("1\n");
else if (x1 % 2 == 0 && y1 % 2 == 1)
printf("2\n");
else if (x1 % 2 == 1 && y1 % 2 == 0)
printf("3\n");
else
printf("4\n");
}
return 0;
}
| 10 | CPP |
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
int t=0;
cin>>t;
while(t-->0){
int n=0,k=0,location=0,ans=0;
vector<int> dist;
cin>>n>>k>>location;
for(int i=0;i<n-1;i++){
int tmp=0;
cin>>tmp;
dist.push_back(tmp-location);
location=tmp;
}
if(k>=n){
cout<<0<<endl;
continue;
}
sort(dist.begin(),dist.end());
for(int i=0;i<dist.size()-k+1;i++){
ans+=dist[i];
}
cout<<ans<<endl;
}
return 0;
} | 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long nex[9], val[9];
long long k, a, b;
long long A[3][3], B[3][3];
signed main() {
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(false);
cin >> k >> a >> b;
for (long long i = 0; i < 3; i++) {
for (long long j = 0; j < 3; j++) {
cin >> A[i][j];
A[i][j]--;
}
}
for (long long i = 0; i < 3; i++) {
for (long long j = 0; j < 3; j++) {
cin >> B[i][j];
B[i][j]--;
}
}
for (long long i = 0; i < 9; i++) {
long long x = i / 3, y = i % 3;
if (x == y)
val[i] = -1;
else {
if ((x == 0 and y == 2) or (x == 1 and y == 0) or (x == 2 and y == 1)) {
val[i] = 0;
} else
val[i] = 1;
}
long long nx = A[x][y], ny = B[x][y];
nex[i] = nx * 3 + ny;
}
a--, b--;
vector<bool> vis(9, 0);
long long start = 3 * a + b;
long long alice = 0, bob = 0;
while (!vis[start]) {
vis[start] = 1;
if (k == 0) {
break;
}
if (val[start] == 0) alice++;
if (val[start] == 1) bob++;
start = nex[start];
k--;
}
if (k == 0) {
cout << alice << " " << bob << '\n';
return 0;
}
long long len = 0;
long long t = start;
long long a1 = 0, b1 = 0;
do {
if (val[t] == 0) a1++;
if (val[t] == 1) b1++;
len++;
t = nex[t];
} while (t != start);
t = k / len;
long long r = k % len;
alice += t * a1;
bob += t * b1;
while (r--) {
if (val[start] == 0) alice++;
if (val[start] == 1) bob++;
start = nex[start];
}
cout << alice << " " << bob << '\n';
}
| 9 | CPP |
#include <bits/stdc++.h>
using namespace std;
inline long long read() {
long long f = 1, x = 0;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
x = (x << 1) + (x << 3) + (c ^ 48);
c = getchar();
}
return f * x;
}
const int N = 2e5 + 10;
vector<int> G[N];
int dis[N], visit[N], dis1[N], dis2[N], a[N], n, m, k;
void Dijkstra(int rt) {
memset(dis, 0x3f, sizeof dis);
memset(visit, 0, sizeof visit);
priority_queue<pair<int, int>, vector<pair<int, int> >,
greater<pair<int, int> > >
q;
dis[rt] = 0;
q.push(make_pair(0, rt));
while (!q.empty()) {
int temp = q.top().second;
q.pop();
if (visit[temp]) continue;
visit[temp] = 1;
for (int i : G[temp]) {
if (dis[i] > dis[temp] + 1) {
dis[i] = dis[temp] + 1;
q.push(make_pair(dis[i], i));
}
}
}
if (rt == 1)
for (int i = 1; i <= n; i++) dis1[i] = dis[i];
else
for (int i = 1; i <= n; i++) dis2[i] = dis[i];
}
bool cmp(int x, int y) { return dis1[x] - dis2[x] < dis1[y] - dis2[y]; }
int main() {
n = read(), m = read(), k = read();
for (int i = 1; i <= k; i++) a[i] = read();
for (int i = 1; i <= m; i++) {
int x = read(), y = read();
G[x].push_back(y);
G[y].push_back(x);
}
Dijkstra(1);
Dijkstra(n);
sort(a + 1, a + k + 1, cmp);
int ans = 0, now_max = dis1[a[1]];
for (int i = 2; i <= k; i++) {
ans = max(ans, now_max + dis2[a[i]] + 1);
now_max = max(now_max, dis1[a[i]]);
}
ans = min(ans, dis1[n]);
printf("%d\n", ans);
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main(void) {
long n, m, l, r;
vector<long> a(100005);
map<long, vector<long> >::iterator mi;
vector<long>::iterator vi1, vi2;
map<long, vector<long> > hash;
scanf("%ld %ld", &n, &m);
for (long i = 0; i < n; i++) {
scanf("%ld", &a[i]);
if (hash.find(a[i]) != hash.end())
hash[a[i]].push_back(i);
else {
vector<long> v;
v.push_back(i);
hash[a[i]] = v;
}
}
mi = hash.begin();
while (mi != hash.end()) {
if (mi->first > mi->second.size()) {
long temp = mi->first;
mi++;
hash.erase(hash.find(temp));
} else
mi++;
}
for (long i = 0; i < m; i++) {
scanf("%ld %ld", &l, &r);
long diff = r - l + 1, count = 0;
mi = hash.begin();
while (mi->first <= diff && mi != hash.end()) {
vi1 = upper_bound(mi->second.begin(), mi->second.end(), r - 1);
vi2 = lower_bound(mi->second.begin(), mi->second.end() - (mi->first - 1),
l - 1);
long last = vi1 - mi->second.begin(), first = vi2 - mi->second.begin();
if (last - first == mi->first) count++;
mi++;
}
printf("%ld\n", count);
}
return 0;
}
| 8 | CPP |
def prepare(n, MOD):
f = 1
factorials = [1]
for m in range(1, n + 1):
f *= m
f %= MOD
factorials.append(f)
inv = pow(f, MOD - 2, MOD)
invs = [1] * (n + 1)
invs[n] = inv
for m in range(n, 1, -1):
inv *= m
inv %= MOD
invs[m - 1] = inv
return factorials, invs
def solve(n, k):
MOD = 998244353
if k == 0:
ans = 1
for i in range(2, n + 1):
ans = ans * i % MOD
return ans
if k > n - 1:
return 0
facts, invs = prepare(n, MOD)
use_row = n - k
t = 1
ans = 0
for r in range(use_row, 0, -1):
ans = (ans + t * facts[use_row] * invs[r] * invs[use_row - r] * pow(r, n, MOD)) % MOD
t *= -1
return ans * 2 * facts[n] * invs[use_row] * invs[n - use_row] % MOD
n, k = map(int, input().split())
print(solve(n, k))
| 11 | PYTHON3 |
n = int(input())
print(sum([1 if str(input())[1] == '+' else -1 for i in range(n)])) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
char s[1111111];
int l = 1;
long long dp[1111111][6], ans = 0;
int main(void) {
scanf("%s", s + 1);
dp[0][0] = 1;
for (int i = 1; s[i]; i++, l++) {
dp[i][0] = dp[i - 1][0];
if (s[i] >= 'a' && s[i] <= 'z')
dp[i][1] = dp[i - 1][0] + dp[i - 1][1],
dp[i][3] = dp[i - 1][2] + dp[i - 1][3],
dp[i][5] = dp[i - 1][4] + dp[i - 1][5];
else if (s[i] >= '0' && s[i] <= '9')
dp[i][1] = dp[i - 1][1], dp[i][3] = dp[i - 1][2] + dp[i - 1][3];
else if (s[i] == '_')
dp[i][1] = dp[i - 1][1];
else if (s[i] == '@')
dp[i][2] = dp[i - 1][1];
else if (s[i] == '.')
dp[i][4] = dp[i - 1][3];
ans += dp[i][5];
}
printf("%lld\n", ans);
return 0;
}
| 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pairInt;
#define FOR(i, n) for (int i = 0; i < int(n); i++)
#define FOR1(i, m, n) for (int i = int(m); i < int(n); i++)
#define MAX(a, b) ((a) >= (b) ? (a) : (b))
#define MIN(a, b) ((a) <= (b) ? (a) : (b))
int main(int argc, char *argv[]) {
int q;
array<int, 2> p1, p2, p, v1, v2;
scanf("%d%d%d%d%d", &p1[0], &p1[1], &p2[0], &p2[1], &q);
v1[0] = p2[0] - p1[0];
v1[1] = p2[1] - p1[1];
FOR(i, q) {
scanf("%d%d", &p[0], &p[1]);
v2[0] = p[0] - p1[0];
v2[1] = p[1] - p1[1];
int ip1 = inner_product(v1.begin(), v1.end(), v1.begin(), 0);
int ip2 = inner_product(v2.begin(), v2.end(), v1.begin(), 0);
array<double, 2> x = {
p1[0] + (double)ip2 / ip1 * (p2[0] - p1[0]),
p1[1] + (double)ip2 / ip1 * (p2[1] - p1[1])
};
printf("%.10lf %.10lf\n", 2 * x[0] - p[0], 2 * x[1] - p[1]);
}
return 0;
} | 0 | CPP |
n = int(input())
group = input().split()
n1 = group.count('1')
n2 = group.count('2')
n3 = group.count('3')
n4 = group.count('4')#need count
n8 = int(n2//2)#need count
n5 = min(int(n3),int(n1))#need count
if int(n3) >= int(n1):
n6 = abs(int(n3)-int(n1))#need count
import math
n11 = math.ceil(n2/2)
print (n4 + n3 + n11)
else:
n7 = abs(int(n3)-int(n1))
n9 = n7 + 2*n2
import math
n10 = math.ceil(n9/4)
print (n4 + n3 + n10)
| 8 | PYTHON3 |
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef map< string, vector< string > > Graph;
typedef long long int64;
Graph graph;
int N;
map< string, int > food;
map< string, int > dp;
map< string, bool > v;
const int INF = 1 << 30;
void solve(string S, int value) {
if(v[S]++) return;
value = min(food[S], value);
food[S] = value;
for(int i = 0; i < graph[S].size(); i++) {
solve(graph[S][i], value);
}
}
signed main() {
cin >> N;
vector< pair< int, string > > stack;
for(int i = 0; i < N; i++) {
string a;
int x;
cin >> a >> x;
food[a] = x;
stack.push_back(make_pair(x, a));
}
sort(stack.begin(), stack.end());
int M;
cin >> M;
for(int i = 0; i < M; i++){
string s, t;
cin >> s >> t;
graph[s].push_back(t);
graph[t].push_back(s);
}
int64 ret = 0LL;
for(vector< pair< int, string > >::iterator it = stack.begin(); it != stack.end(); ++it){
solve(it -> second, it -> first);
}
for(map< string, int >::iterator it = food.begin(); it != food.end(); ++it){
ret += it -> second;
}
cout << ret << endl;
} | 0 | CPP |
n=int(input())
s=list(input().split())
print("Four" if 'Y' in s else "Three") | 0 | PYTHON3 |
import datetime
import time
t = input()
M = input()
h, m = list(map(int, t.split(':')))
H,M = divmod(int(M), 60)
a = datetime.datetime(100, 1, 1, h, m, 00)
b = a + datetime.timedelta(0,0,0,0,M,H,0)
print(b.strftime('%H:%M'))
| 8 | PYTHON3 |
#include <cstdio>
const int mod = 998244353;
const int MAXN = 10005;
template<typename _T>
void read( _T &x )
{
x = 0;char s = getchar();int f = 1;
while( s > '9' || s < '0' ){if( s == '-' ) f = -1; s = getchar();}
while( s >= '0' && s <= '9' ){x = ( x << 3 ) + ( x << 1 ) + ( s - '0' ), s = getchar();}
x *= f;
}
template<typename _T>
void write( _T x )
{
if( x < 0 ){ putchar( '-' ); x = ( ~ x ) + 1; }
if( 9 < x ){ write( x / 10 ); }
putchar( x % 10 + '0' );
}
int f[MAXN][MAXN];
int fac[MAXN], ifac[MAXN];
char A[MAXN], B[MAXN];
int N;
int qkpow( int base, int indx )
{
int ret = 1;
while( indx )
{
if( indx & 1 ) ret = 1ll * ret * base % mod;
base = 1ll * base * base % mod, indx >>= 1;
}
return ret;
}
void init( const int siz )
{
fac[0] = 1;
for( int i = 1 ; i <= siz ; i ++ ) fac[i] = 1ll * fac[i - 1] * i % mod;
ifac[siz] = qkpow( fac[siz], mod - 2 );
for( int i = siz - 1 ; ~ i ; i -- ) ifac[i] = 1ll * ifac[i + 1] * ( i + 1 ) % mod;
}
int C( const int n, const int m )
{
if( n < m || n < 0 || m < 0 ) return 0;
return 1ll * fac[n] * ifac[m] % mod * ifac[n - m] % mod;
}
void add( int &x, const int v ) { x = ( x + v >= mod ? x + v - mod : x + v ); }
int main()
{
int S = 0, T = 0;
scanf( "%s%s", A + 1, B + 1 );
for( N = 1 ; A[N] ; N ++ )
{
int a = A[N] - '0', b = B[N] - '0';
if( a && b ) S ++;
if( a && ! b ) T ++;
}
init( N );
f[0][0] = 1;
for( int i = 0 ; i <= S ; i ++ )
for( int j = 0 ; j <= T ; j ++ )
{
if( i ) add( f[i][j], 1ll * f[i - 1][j] * i % mod * j % mod );
if( j ) add( f[i][j], 1ll * f[i][j - 1] * j % mod * j % mod );
}
int ans = 0;
for( int i = 0 ; i <= S ; i ++ )
add( ans, 1ll * C( S + T, i ) * C( S, i ) % mod * fac[i] % mod * fac[i] % mod * f[S - i][T] % mod );
write( ans ), putchar( '\n' );
return 0;
} | 0 | CPP |
s = str(input())
if 1<=len(s)<=100:
#print(s[0].islower())
if s[0].islower() == True and s[1:].isupper() == True:
s = s.capitalize()
print(s)
elif s == s.upper():
s = s.lower()
print(s)
elif len(s)< 2:
s = s.upper()
print(s)
else:
print(s)
| 7 | PYTHON3 |
import sys
v, e, r = map(int, input().split( ))
E = [[] for _ in range(v)]
inf = 10**12
for _ in range(e):
s,t,d = map(int, input().split( ))
E[s].append([t,d])
D = [inf for _ in range(v)]
D[r] = 0
"""
間違い
for ve in range(v):
for ed in E[ve]:
D[ed[0]] = min(D[ed[0]], D[ve] + ed[1])
print(*D)
"""
for _ in range(v):
for ve in range(v):
for ed in E[ve]:
D[ed[0]] = min(D[ed[0]], D[ve] + ed[1])
for i in range(v):
if E[i]:
for ed in E[i]:
if D[i] + ed[1] < D[ed[0]] and D[ed[0]]<inf//10:
print("NEGATIVE CYCLE")
sys.exit()
for i in range(v):
if D[i]<inf//100:
print(D[i])
else:
print("INF")
| 0 | PYTHON3 |
s=input()
u,l=0,0
for i in s:
if i.isupper()==True:
u+=1
else:
l+=1
if u<=l:
print(s.lower())
else:
print(s.upper()) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
long long dfs(int h, long long n, long long mid, bool d) {
if (h == 0) {
return 0;
}
if (n <= mid / 2 && d == false) {
return dfs((h - 1), n, mid / 2, !d) + 1;
} else if (n <= mid / 2) {
return dfs((h - 1), n, mid / 2, d) + mid;
} else if (d == false) {
return dfs((h - 1), n - mid / 2, mid / 2, d) + mid;
} else
return dfs(h - 1, n - mid / 2, mid / 2, !d) + 1;
}
int main() {
int h;
long long n;
long long ch;
cin >> h >> n;
ch = pow(2, h);
cout << dfs(h, n, ch, false);
}
| 9 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int nmax = 123456;
int n;
int a[nmax], b[nmax], c[nmax];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
for (int i = 1; i <= n; i++)
if (i == a[i]) {
printf("YES\n");
for (int j = 1; j <= n; j++)
if (j != i) printf("%d %d\n", i, j);
return 0;
}
for (int i = 1; i <= n; i++)
if (i == a[a[i]]) {
int bb = 0;
b[i] = 1;
b[a[i]] = 1;
for (int j = 1; j <= n; j++)
if (b[j] != 1) {
int dd = j;
int cc = 0;
while (b[dd] != 1) {
cc++;
b[dd] = 1;
dd = a[dd];
}
bb += cc % 2;
}
if (bb >= 1) {
printf("NO");
return 0;
} else {
printf("YES\n");
for (int j = 1; j <= n; j++) b[j] = 0;
b[i] = 1;
b[a[i]] = 1;
int y = i;
for (int j = 1; j <= n; j++)
if (b[j] != 1) {
int x = j;
while (b[x] != 1) {
printf("%d %d\n", y, x);
b[x] = 1;
x = a[x];
y = a[y];
}
}
printf("%d %d", i, a[i]);
return 0;
}
}
printf("NO\n");
return 0;
}
| 10 | CPP |
K,S =map(int, input().split())
c=0
for i in range(K+1):
for j in range(K+1):
if 0<=S-i-j<=K:
c+=1
print(c) | 0 | PYTHON3 |
a,b=map(int,input().split())
if a%2==0:
if b<=a//2:
print(2*b - 1)
else:
print((b-(a//2))*2)
else:
if b<=a//2 + 1:
print(b*2 - 1)
else:
print((b - (a //2 + 1)) * 2)
| 7 | PYTHON3 |
while True:
n = int(input())
if not n:
break
print(sum(sorted([int(input()) for _ in range(n)])[1:-1]) // (n - 2))
| 0 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5, maxm = 1e5 + 5;
const int mod = 1e9 + 7, inf = 0x7f7f7f7f;
long long n, k, b[maxn];
long long a[maxn];
long long calc(long long ai, long long x) { return ai - 3 * x * x + 3 * x - 1; }
long long check(long long d) {
long long cnt = 0;
for (int i = 1; i <= n; ++i) {
long long L = 1, R = a[i];
while (L < R) {
int mid = (L + R + 1) >> 1;
if (calc(a[i], mid) >= d)
L = mid;
else
R = mid - 1;
}
cnt += L;
b[i] = L;
}
return cnt;
}
int main() {
scanf("%lld%lld", &n, &k);
for (int i = 1; i <= n; ++i) scanf("%lld", &a[i]);
long long L = -4e18, R = 4e18;
while (L < R) {
long long mid = (L + R + 1) >> 1;
if (check(mid) >= k)
L = mid;
else
R = mid - 1;
}
long long s = check(L);
for (int i = 1; i <= n; ++i) {
if (s > k && calc(a[i], b[i]) == L) s--, b[i]--;
}
for (int i = 1; i <= n; ++i) printf("%lld%c", b[i], i == n ? '\n' : ' ');
return 0;
}
| 12 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
map<string, int> arr;
map<string, int> arr2;
vector<string> v;
for (int i = 0; i < n; i++) {
string tmp;
cin >> tmp;
v.push_back(tmp);
arr[tmp]++;
}
for (int i = 0; i < n - 1; i++) {
string tmp;
cin >> tmp;
arr2[tmp]++;
arr[tmp]--;
}
for (int i = 0; i < n - 2; i++) {
string tmp;
cin >> tmp;
arr2[tmp]--;
}
bool done1 = 0, done2 = 0;
string fst, sec;
for (int i = 0; i < n; i++) {
if (arr[v[i]]) {
fst = v[i];
done1 = 1;
}
if (arr2[v[i]]) {
sec = v[i];
done2 = 1;
}
if (done1 && done2) break;
}
cout << fst << endl << sec << endl;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
int main() {
int x, y, max, left, win = -1, turn = 0;
scanf("%d%d", &x, &y);
max = (x / 2 < y / 24) ? x / 2 : y / 24;
x -= max * 2;
y -= max * 24;
left = 100 * x + 10 * y;
while (win == -1) {
if (!(left >= 220 && y >= 2))
win = !turn;
else {
if (turn % 2 == 0) {
if (x >= 2) {
x -= 2;
y -= 2;
} else if (x == 1) {
x -= 1;
y -= 12;
} else {
y -= 22;
}
} else {
if (y >= 22)
y -= 22;
else if (y >= 12) {
x -= 1;
y -= 12;
} else {
x -= 2;
y -= 2;
}
}
turn = (turn + 1) % 2;
left -= 220;
}
}
printf("%s\n", win % 2 == 0 ? "Ciel" : "Hanako");
return 0;
}
| 7 | CPP |
n=int(input())
print(n) if n%111==0 else print((n//111+1)*111) | 0 | PYTHON3 |
#include<bits/stdc++.h>
#define N 50
#define LL long long
#define mod
#define pr pair<int,int>
#define mp(x,y) make_pair(x,y)
using namespace std;
LL read(){
char c=getchar();
LL f=1,t=0;
while(c>'9'||c<'0') f=(c=='-')?-1:1,c=getchar();
while(c>='0'&&c<='9') t=t*10+c-'0',c=getchar();
return t*f;
}
int n,m,tp[N],e[N][N][2];
int main(){
int L=read(),R=read();
if(L==R) return !printf("YES\n2 1\n1 2 %d\n",L);
puts("YES"),R-=L,n=2,m++,tp[1]++,e[1][1][0]=2,e[1][1][1]=L;
for(int i=0,nw=0;nw<=R+1;i++){
nw+=(1<<i),n++,m++,tp[1]++,e[1][tp[1]][0]=n,e[1][tp[1]][1]=L;
for(int j=2;j<n;j++) m++,tp[j]++,e[j][tp[j]][0]=n,e[j][tp[j]][1]=1<<(j-2);
}
n++,m++,tp[1]++,e[1][tp[1]][0]=n,e[1][tp[1]][1]=L;
for(int i=22,bs=0;i>=0;i--)
if(R&(1<<i)) m++,tp[i+2]++,e[i+2][tp[i+2]][0]=n,e[i+2][tp[i+2]][1]=bs+1,bs|=1<<i;
printf("%d %d\n",n,m);
for(int i=1;i<=n;i++)
for(int j=1;j<=tp[i];j++)
printf("%d %d %d\n",i,e[i][j][0],e[i][j][1]);
return 0;
}
| 9 | CPP |
#include <bits/stdc++.h>
const double eps = 1e-9;
const double pi = acos(-1);
using namespace std;
struct P {
string name;
int prio;
P() { prio = 0; }
} a[110];
map<string, int> mp;
int cnt;
int get_id(string& s) {
if (!mp.count(s)) {
mp[s] = cnt++;
a[cnt - 1].prio = 0;
a[cnt - 1].name = s;
}
return mp[s];
}
int get_op(string& s) {
if (s[0] == 'p')
return 1;
else if (s[0] == 'c')
return 2;
else if (s[0] == 'l')
return 3;
}
bool cmp(const P& a, const P& b) {
if (a.prio == b.prio)
return a.name < b.name;
else
return a.prio > b.prio;
}
int main() {
string me;
cin >> me;
int n;
cin >> n;
getchar();
cnt = 0;
string s;
for (int i = 1; i <= n; i++) {
getline(cin, s);
stringstream ss(s);
string str[5];
int tcnt = 0;
string tmp;
while (ss >> tmp) str[tcnt++] = tmp;
int op = get_op(str[1]);
if (op == 1 || op == 2) {
int id_1 = get_id(str[0]);
int j = 0;
string tmp;
while (isalpha(str[3][j])) tmp += str[3][j++];
int id_2 = get_id(tmp);
if (str[0] == me)
a[id_2].prio += (op == 1 ? 15 : 10);
else if (tmp == me)
a[id_1].prio += (op == 1 ? 15 : 10);
} else {
int id_1 = get_id(str[0]);
int j = 0;
string tmp;
while (isalpha(str[2][j])) tmp += str[2][j++];
int id_2 = get_id(tmp);
if (str[0] == me)
a[id_2].prio += 5;
else if (tmp == me)
a[id_1].prio += 5;
}
}
sort(a, a + cnt, cmp);
for (int i = 0; i < cnt; i++)
if (a[i].name != me) cout << a[i].name << endl;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main(){
int n, k; cin >> n >> k;
vector<long long> h(n);
for(int i = 0; i < n; i++){
cin >> h.at(i);
}
long long ans = 1001001001001001;
for(int i = 0; i < (1<<n); i++){
long long sum = 0, tmp = 0;
int can_see = 0;
for(int j = 0; j < n; j++){
if(tmp < h.at(j)){
tmp = h.at(j);
can_see++;
}
else{
if(i & (1 << j)){
sum += tmp - h.at(j) + 1;
tmp++;
can_see++;
}
}
if(can_see >=k) ans = min(ans, sum);
}
}
cout << ans << endl;
}
| 0 | CPP |
#include <bits/stdc++.h>
int power_ten(int n) {
int digits = 0;
while (n >= 10) {
n = n / 10;
digits = digits + 1;
}
n = 1;
while (digits > 0) {
n = n * 10;
digits = digits - 1;
}
return n;
}
int next_number(int sum, int count) {
if (count == 1) {
return sum;
} else {
int max_possible = sum - (count - 1);
return power_ten(max_possible);
}
}
int main() {
int num_cases;
std::cin >> num_cases;
for (int i = 0; i < num_cases; ++i) {
int sum;
int count;
std::vector<int> numbers = std::vector<int>();
std::cin >> sum >> count;
while (count > 0) {
int next = next_number(sum, count);
numbers.push_back(next);
sum = sum - next;
count = count - 1;
}
for (int x : numbers) {
std::cout << x << " ";
}
std::cout << "\n";
}
}
| 10 | CPP |
from collections import Counter
n=int(input())
v=list(map(int,input().split()))
v1=Counter(v[::2])
v2=Counter(v[1::2])
v1[0]=0
v2[0]=0
v1_max=v1.most_common()[0]
v2_max=v2.most_common()[0]
v1_second=v1.most_common()[1]
v2_second=v2.most_common()[1]
if v1_max[0]!=v2_max[0]:
print(n-v1_max[1]-v2_max[1])
else:
print(min(n-v1_max[1]-v2_second[1],n-v2_max[1]-v1_second[1])) | 0 | PYTHON3 |
t=int(input())
for i in range(t):
n,g,b=map(int,input().split())
answer=n
pair=g+b
need=(n+1)//2
print(max(n,(need-1)//g*pair+(need-1)%g+1))
| 8 | PYTHON3 |
n = input()
o = 0
z = 0
for i in range(0,len(n)):
if(n[i]=='1'):
o = o + 1
z = 0
if(n[i]=='0'):
z = z + 1
o = 0
if(o==7 or z==7):
break
if(o==7 or z==7):
print("YES")
else:
print("NO") | 7 | PYTHON3 |
t=int(input())
for i in range(t):
n=int(input())
if(n%2==0):
print((n//2)-1)
else:
print(n//2) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
namespace baseFastio {
template <typename Int>
inline Int read() {
Int flag = 1;
char c = getchar();
while ((!isdigit(c)) && c != '-' && c != EOF) c = getchar();
if (c == '-') flag = -1, c = getchar();
Int init = c & 15;
while (isdigit(c = getchar())) init = (init << 3) + (init << 1) + (c & 15);
return init * flag;
}
template <typename Int>
inline Int read(char& c) {
Int flag = 1;
c = getchar();
while ((!isdigit(c)) && c != '-' && c != EOF) c = getchar();
if (c == '-') flag = -1, c = getchar();
Int init = c & 15;
while (isdigit(c = getchar())) init = (init << 3) + (init << 1) + (c & 15);
return init * flag;
}
template <typename Int>
inline void write(Int x) {
if (x < 0) putchar('-'), x = ~x + 1;
if (x > 9) write(x / 10);
putchar((x % 10) | 48);
}
template <typename Int>
inline void write(Int x, char nextch) {
write(x);
putchar(nextch);
}
} // namespace baseFastio
namespace Fastio {
enum io_flags { ignore_int = 1 << 0 };
struct Reader {
char endch;
Reader() { endch = '\0'; }
template <typename Int>
Int operator()() {
return baseFastio::read<Int>(endch);
;
}
Reader& operator>>(io_flags f) {
if (f == ignore_int) baseFastio::read<int>();
return *this;
}
template <typename Int>
Reader& operator>>(Int& i) {
i = baseFastio::read<Int>(endch);
return *this;
}
template <typename Int>
inline Int get_int() {
return baseFastio::read<Int>();
}
inline char get_nxt() { return endch; }
} read;
struct Writer {
Writer& operator<<(const char* ch) {
while (*ch) putchar(*(ch++));
return *this;
}
Writer& operator<<(const char ch) {
putchar(ch);
return *this;
}
template <typename Int>
Writer& operator<<(const Int i) {
baseFastio::write(i);
return *this;
}
} write;
} // namespace Fastio
using namespace Fastio;
const int N = 1e5 + 7, Alp = 20, AlpMask = 1 << 20;
int T, n;
char a[N], b[N];
int adj[N], both_adj[N];
bitset<AlpMask> f;
bitset<Alp> vis;
int SubG_cnt, ans;
void dfs(int u) {
vis.set(u);
for (size_t i = 0; i < 20; i++)
if ((both_adj[u] & (1 << i)) && !vis.test(i)) dfs(i);
}
signed main() {
read >> T;
while (T--) {
read >> n;
scanf("%s", a + 1);
scanf("%s", b + 1);
memset(adj, 0, sizeof(adj));
memset(both_adj, 0, sizeof(both_adj));
f.reset();
vis.reset();
SubG_cnt = ans = 0;
for (int i = 1; i <= n; i++)
if (a[i] != b[i]) {
adj[a[i] - 'a'] |= (1 << (b[i] - 'a'));
both_adj[a[i] - 'a'] |= (1 << (b[i] - 'a'));
both_adj[b[i] - 'a'] |= (1 << (a[i] - 'a'));
}
for (int i = 0; i < 20; i++)
if (!vis.test(i)) dfs(i), SubG_cnt++;
f.set(0);
for (int i = 0; i < AlpMask; i++)
if (f.test(i)) {
ans = max(ans, __builtin_popcount(i));
for (int j = 0; j < 20; j++)
if (!(i & (1 << j)) && !(adj[j] & i)) f.set(i | (1 << j));
}
write << 2 * Alp - SubG_cnt - ans << '\n';
}
return 0;
}
| 7 | CPP |
def comand(l, r, a):
while True:
if a == 0:
break
if l < r:
l, a = l + 1, a - 1
else:
r, a = r + 1, a - 1
return 2 * min(l, r)
L, R, A = [int(i) for i in input().split()]
print(comand(L, R, A))
| 7 | PYTHON3 |
cases = int(input())
def get_moves_to_divisibility(a, b):
if a % b == 0:
return 0
div_value = b*(a // b + 1)
return div_value - a
for _ in range(cases):
vals = input().split(" ")
print(get_moves_to_divisibility(int(vals[0]), int(vals[1])))
| 10 | PYTHON3 |
N,M=map(int,input().split())
A=list(map(int,input().split()))
summ=sum(A)
print(max(N-summ,-1)) | 0 | PYTHON3 |
import math
N = int(input())
x = int(math.sqrt(N))
while N % x != 0:
x -= 1
print((x-1) + (N//x -1)) | 0 | PYTHON3 |
n=int(input())
if n==1:print('Hello World')
else:
a,b=int(input()),int(input())
print(a+b) | 0 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int n,a[100010],mn;
int main(){
scanf("%d",&n);
for(int i=1;i<=n;i++) scanf("%d",&a[i]);
mn=a[n];
for(int i=n;i>=1;i--){
mn=min(a[i],mn);
if(a[i]-mn>1){
printf("No\n");
return 0;
}
}
printf("Yes\n");
} | 0 | CPP |
#include <bits/stdc++.h>
int big = 1e7;
using namespace std;
int main(int argc, char *argv[]) {
ios::sync_with_stdio(0);
long long n;
cin >> n;
vector<pair<long long, long long> > vec(n);
vector<set<pair<long long, long long> > > f(3);
set<pair<long long, long long> > f3;
for (long long i = 0; i < n; i++) {
cin >> vec[i].first;
vec[i].second = i;
f[vec[i].first % 3].insert(make_pair(vec[i].first, i));
f3.insert(make_pair(vec[i].first, i));
}
long long cur = 0;
vector<long long> ans(n);
for (long long i = 0; i < n; i++) {
auto it = f3.upper_bound({cur, big});
if (it == f3.begin()) {
cout << "Impossible \n";
return 0;
}
it--;
if (it->first == cur) {
ans[i] = it->second + 1;
f[it->first % 3].erase(make_pair(it->first, it->second));
f3.erase(it);
cur++;
} else {
it = f[cur % 3].upper_bound({cur, big});
if (it == f[cur % 3].begin()) {
cout << "Impossible \n";
return 0;
}
it--;
if (it == f[cur % 3].end()) {
cout << "Impossible \n";
return 0;
}
ans[i] = it->second + 1;
cur = it->first + 1;
f3.erase(make_pair(it->first, it->second));
f[it->first % 3].erase(it);
}
}
cout << "Possible \n";
for (long long i = 0; i < n; i++) cout << ans[i] << " ";
cout << '\n';
return 0;
}
| 10 | CPP |
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
#define inf 1000000007000000007
typedef long long ll;
using namespace std;
#define N 100010
typedef pair<ll,ll> P;
typedef pair<ll,pair<ll,ll> >PP;
ll n,m,s,t;
vector<pair<ll,ll> >v[N];
priority_queue<PP,vector<PP>,greater<PP> >Q;
ll d[N][2],cnt[N][2];
void Dijkstra(ll start,ll flag){
lol(i,n)d[i][flag]=inf,cnt[i][flag]=0;
Q.push(make_pair(0,make_pair(start,-1)));
while(!Q.empty()){
ll a=Q.top().first,b=Q.top().second.first;
ll from=Q.top().second.second;
Q.pop();
if(d[b][flag]<a)continue;
if(d[b][flag]==a){
cnt[b][flag]+=cnt[from][flag];
cnt[b][flag]%=mod;
continue;
}
d[b][flag]=a;
if(from==-1)cnt[b][flag]=1;
else cnt[b][flag]=cnt[from][flag];
lol(i,v[b].size()){
Q.push(make_pair(v[b][i].first+a,make_pair(v[b][i].second,b)));
}
}
}
int main(){
cin>>n>>m>>s>>t;s--,t--;
lol(i,m){
ll a,b,c;cin>>a>>b>>c;a--,b--;
v[a].push_back(make_pair(c,b));
v[b].push_back(make_pair(c,a));
}
Dijkstra(t,1);
Dijkstra(s,0);
ll k=d[t][0];
ll sum=0;
lol(i,n){
if(d[i][0]*2>k)continue;
if(d[i][0]*2==k){
ll tmp=cnt[i][0]*cnt[i][1]%mod;
sum+=tmp*tmp;sum%=mod;
continue;
}
//d[i][0]*2<kが成り立っている
lol(j,v[i].size()){
ll to=v[i][j].second,cost=v[i][j].first;
if(cost+d[i][0]==d[to][0]&&d[to][0]*2>k&&cost+d[i][0]+d[to][1]==k){
//cout<<"#"<<i+1<<" "<<to+1<<endl;
ll tmp=cnt[i][0]*cnt[to][1]%mod;
sum+=tmp*tmp;sum%=mod;
}
}
}
ll ans=(cnt[s][1]*cnt[t][0]-sum)%mod;
cout<<ans<<endl;
return 0;
}
| 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
int n, i, x, y, w;
long long ans, dt;
int par[MAXN], sz[MAXN];
bool wk[MAXN];
bool lucky(int x) {
while (x) {
if (x % 10 != 4 && x % 10 != 7) return false;
x /= 10;
}
return true;
}
int fn(int x) { return (x == par[x] ? x : par[x] = fn(par[x])); }
void unite(int x, int y) {
x = fn(x), y = fn(y);
if (x != y) {
if (sz[x] < sz[y]) swap(x, y);
par[y] = x;
sz[x] += sz[y];
}
}
long long c2(long long a) {
if (a < 2) return 0ll;
return (a * (a - 1)) / 2ll;
}
long long c3(long long a) {
if (a < 3) return 0ll;
return (a * (a - 1) * (a - 2)) / 6ll;
}
int main() {
scanf("%d", &n);
for (i = 1; i <= n; i++) par[i] = i, sz[i] = 1;
for (i = 1; i < n; i++) {
scanf("%d%d%d", &x, &y, &w);
if (!lucky(w)) unite(x, y);
}
for (i = 1; i <= n; i++) {
if (par[i] != i) continue;
ans += 1ll * sz[i] * (n - sz[i]) * (n - sz[i] - 1);
}
cout << ans - dt << "\n";
return 0;
}
| 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
int Reg, Max;
int main() {
int n, pow, dmg;
cin >> n >> Max >> Reg;
double hp = Max;
vector<vector<int> > casts(n, vector<int>(3, 0));
vector<vector<int> > actions(n, vector<int>(2, -1));
int act_sz = 0;
for (int i = 0; i < n; i++) {
casts[i][0] = i + 1;
cin >> pow >> dmg;
casts[i][1] = pow;
casts[i][2] = dmg;
}
bool changed = true;
while (changed) {
changed = false;
for (int i = 0; i < n - 1; i++) {
if (casts[i][2] < casts[i + 1][2]) {
swap(casts[i], casts[i + 1]);
changed = true;
}
}
}
int sec;
for (sec = 0;; sec++) {
for (int i = 0; i < act_sz && actions[i][0] != -1; i++)
hp -= casts[actions[i][1]][2];
hp += Reg;
if (hp > Max) hp = Max;
if (hp <= 0) break;
int j;
for (j = 0; j < n; j++) {
if ((casts[j][0] < 0) || (casts[j][1] * Max / 100 < hp)) continue;
actions[act_sz][0] = sec;
actions[act_sz][1] = j;
casts[j][0] = -casts[j][0];
act_sz++;
break;
}
if (j == n) {
int damage = -Reg;
for (int k = 0; k < act_sz; k++) damage += casts[actions[k][1]][2];
if (damage <= 0) {
cout << "NO";
return 0;
}
}
}
cout << "YES" << endl;
cout << sec << " " << act_sz << endl;
for (int i = 0; i < act_sz; i++)
cout << actions[i][0] << " " << -casts[actions[i][1]][0] << endl;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
void solve() {
long long n, k;
cin >> n >> k;
long long x = 0, y = 0;
long long arr[n][n];
long long cur = 0;
memset(arr, 0, sizeof(arr));
while (k) {
arr[x][y] = 1;
x = x + 1;
y = (y + 1) % n;
if (x == n) {
x = 0;
cur++;
y = cur;
}
k--;
}
long long mn = (long long)1e9 + 1, mx = -(long long)1e9 + 1;
for (long long i = 0; i < n; i++) {
long long sum = 0;
for (long long j = 0; j < n; j++) {
sum += arr[i][j];
}
mn = min(mn, sum);
mx = max(mx, sum);
}
long long ans = 0;
ans += (mx - mn) * (mx - mn);
mx = -(long long)1e9 + 1, mn = (long long)1e9 + 1;
for (long long j = 0; j < n; j++) {
long long sum = 0;
for (long long i = 0; i < n; i++) sum += arr[i][j];
mn = min(mn, sum);
mx = max(mx, sum);
}
ans += (mx - mn) * (mx - mn);
cout << ans << "\n";
for (long long i = 0; i < n; i++) {
for (long long j = 0; j < n; j++) cout << arr[i][j];
cout << "\n";
}
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
;
long long t;
cin >> t;
while (t--) {
solve();
}
return 0;
}
| 10 | CPP |
lines = []
lines.append(input())
for i in range(int(lines[0])):
lines.append(input())
a, b = 0, 0
t = lines[1]
for i in range(1, len(lines), 1):
if lines[i] == t:
a += 1
else:
s = lines[i]
b += 1
print(t) if a > b else print(s)
| 7 | PYTHON3 |
i=lambda:iter(sorted(map(int,input().split())))
n=next;i();a=i();i();b=i();v=0;x,y=n(a),n(b)
try:
while 1:
if abs(x-y)<2:v+=1;x=n(a);y=n(b)
elif x<y:x=n(a)
else:y=n(b)
except:
print(v) | 8 | PYTHON3 |
n, m = map(int,input().split())
a = [0]*m
k = []
for i in range(n):
x1, x2 = map(int,input().split())
for j in range(x1-1,x2):
a[j] = 1
for i in range(m):
if a[i] == 0:
k.append(i+1)
print(len(k))
print(*k) | 7 | PYTHON3 |
import sys
input = sys.stdin.readline
inputr = lambda: sys.stdin.readline().rstrip('\n')
for _ in range(int(input())):
n = int(input())
print(max(1, (n+1)//2))
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int maxn = 1e6 + 10;
const int maxv = 1e3 + 10;
const double eps = 1e-9;
class BigNum {
private:
int a[2500];
int len;
public:
BigNum() {
len = 1;
memset(a, 0, sizeof(a));
}
BigNum(const int);
BigNum(const char *);
BigNum(const BigNum &);
BigNum &operator=(const BigNum &);
friend istream &operator>>(istream &, BigNum &);
friend ostream &operator<<(ostream &, BigNum &);
BigNum operator+(const BigNum &) const;
BigNum operator-(const BigNum &) const;
BigNum operator*(const BigNum &) const;
BigNum operator/(const int &) const;
BigNum operator^(const int &) const;
int operator%(const int &) const;
bool operator>(const BigNum &T) const;
bool operator>(const int &t) const;
void print();
};
BigNum::BigNum(const int b) {
int c, d = b;
len = 0;
memset(a, 0, sizeof(a));
while (d > 9999) {
c = d - (d / (9999 + 1)) * (9999 + 1);
d = d / (9999 + 1);
a[len++] = c;
}
a[len++] = d;
}
BigNum::BigNum(const char *s) {
int t, k, index, l, i;
memset(a, 0, sizeof(a));
l = strlen(s);
len = l / 4;
if (l % 4) len++;
index = 0;
for (i = l - 1; i >= 0; i -= 4) {
t = 0;
k = i - 4 + 1;
if (k < 0) k = 0;
for (int j = k; j <= i; j++) t = t * 10 + s[j] - '0';
a[index++] = t;
}
}
BigNum::BigNum(const BigNum &T) : len(T.len) {
int i;
memset(a, 0, sizeof(a));
for (i = 0; i < len; i++) a[i] = T.a[i];
}
BigNum &BigNum::operator=(const BigNum &n) {
int i;
len = n.len;
memset(a, 0, sizeof(a));
for (i = 0; i < len; i++) a[i] = n.a[i];
return *this;
}
istream &operator>>(istream &in, BigNum &b) {
char ch[10 * 4];
int i = -1;
in >> ch;
int l = strlen(ch);
int count = 0, sum = 0;
for (i = l - 1; i >= 0;) {
sum = 0;
int t = 1;
for (int j = 0; j < 4 && i >= 0; j++, i--, t *= 10) {
sum += (ch[i] - '0') * t;
}
b.a[count] = sum;
count++;
}
b.len = count++;
return in;
}
ostream &operator<<(ostream &out, BigNum &b) {
int i;
cout << b.a[b.len - 1];
for (i = b.len - 2; i >= 0; i--) {
cout.width(4);
cout.fill('0');
cout << b.a[i];
}
return out;
}
BigNum BigNum::operator+(const BigNum &T) const {
BigNum t(*this);
int i, big;
big = T.len > len ? T.len : len;
for (i = 0; i < big; i++) {
t.a[i] += T.a[i];
if (t.a[i] > 9999) {
t.a[i + 1]++;
t.a[i] -= 9999 + 1;
}
}
if (t.a[big] != 0)
t.len = big + 1;
else
t.len = big;
return t;
}
BigNum BigNum::operator-(const BigNum &T) const {
int i, j, big;
bool flag;
BigNum t1, t2;
if (*this > T) {
t1 = *this;
t2 = T;
flag = 0;
} else {
t1 = T;
t2 = *this;
flag = 1;
}
big = t1.len;
for (i = 0; i < big; i++) {
if (t1.a[i] < t2.a[i]) {
j = i + 1;
while (t1.a[j] == 0) j++;
t1.a[j--]--;
while (j > i) t1.a[j--] += 9999;
t1.a[i] += 9999 + 1 - t2.a[i];
} else
t1.a[i] -= t2.a[i];
}
t1.len = big;
while (t1.a[t1.len - 1] == 0 && t1.len > 1) {
t1.len--;
big--;
}
if (flag) t1.a[big - 1] = 0 - t1.a[big - 1];
return t1;
}
BigNum BigNum::operator*(const BigNum &T) const {
BigNum ret;
int i, j, up;
int temp, temp1;
for (i = 0; i < len; i++) {
up = 0;
for (j = 0; j < T.len; j++) {
temp = a[i] * T.a[j] + ret.a[i + j] + up;
if (temp > 9999) {
temp1 = temp - temp / (9999 + 1) * (9999 + 1);
up = temp / (9999 + 1);
ret.a[i + j] = temp1;
} else {
up = 0;
ret.a[i + j] = temp;
}
}
if (up != 0) ret.a[i + j] = up;
}
ret.len = i + j;
while (ret.a[ret.len - 1] == 0 && ret.len > 1) ret.len--;
return ret;
}
BigNum BigNum::operator/(const int &b) const {
BigNum ret;
int i, down = 0;
for (i = len - 1; i >= 0; i--) {
ret.a[i] = (a[i] + down * (9999 + 1)) / b;
down = a[i] + down * (9999 + 1) - ret.a[i] * b;
}
ret.len = len;
while (ret.a[ret.len - 1] == 0 && ret.len > 1) ret.len--;
return ret;
}
int BigNum::operator%(const int &b) const {
int i, d = 0;
for (i = len - 1; i >= 0; i--) {
d = ((d * (9999 + 1)) % b + a[i]) % b;
}
return d;
}
BigNum BigNum::operator^(const int &n) const {
BigNum t, ret(1);
int i;
if (n < 0) exit(-1);
if (n == 0) return 1;
if (n == 1) return *this;
int m = n;
while (m > 1) {
t = *this;
for (i = 1; i << 1 <= m; i <<= 1) {
t = t * t;
}
m -= i;
ret = ret * t;
if (m == 1) ret = ret * (*this);
}
return ret;
}
bool BigNum::operator>(const BigNum &T) const {
int ln;
if (len > T.len)
return true;
else if (len == T.len) {
ln = len - 1;
while (a[ln] == T.a[ln] && ln >= 0) ln--;
if (ln >= 0 && a[ln] > T.a[ln])
return true;
else
return false;
} else
return false;
}
bool BigNum::operator>(const int &t) const {
BigNum b(t);
return *this > b;
}
void BigNum::print() {
int i;
cout << a[len - 1];
for (i = len - 2; i >= 0; i--) {
cout.width(4);
cout.fill('0');
cout << a[i];
}
cout << endl;
}
inline int read() {
char c = getchar();
int f = 1;
while (!isdigit(c)) {
if (c == '-') f = -1;
c = getchar();
}
int x = 0;
while (isdigit(c)) {
x = x * 10 + c - '0';
c = getchar();
}
return x * f;
}
int n, k, dis;
int a[maxn];
int dp[5005][5005];
int dfs(int pos, int d1, int d0) {
if (pos > n) return 0;
int &ret = dp[d1][d0];
if (ret != -1) return ret;
ret = 2e9;
if (d1)
ret = min(ret, dfs(pos + dis + 1, d1 - 1, d0) + a[pos + dis] - a[pos]);
if (d0)
ret = min(ret, dfs(pos + dis, d1, d0 - 1) + a[pos + dis - 1] - a[pos]);
return ret;
}
int main() {
while (scanf("%d%d", &n, &k) != EOF) {
dis = n / k;
for (int i = 1; i <= n; i++) scanf("%d", a + i);
sort(a + 1, a + 1 + n);
int dlenk1 = n % k;
int dlenk0 = k - dlenk1;
memset(dp, -1, sizeof dp);
printf("%d\n", dfs(1, dlenk1, dlenk0));
}
return 0;
}
| 10 | CPP |
n=int(input())
z=input()
x=True
for i in z:
if z.count(i)>1:
x=True
break
else:
x=False
if n==1:
x=True
print("YES" if x else "NO") | 7 | PYTHON3 |
import sys
import math
#from queue import *
import random
#sys.setrecursionlimit(int(1e6))
input = sys.stdin.readline
############ ---- USER DEFINED INPUT FUNCTIONS ---- ############
def inp():
return(int(input()))
def inara():
return(list(map(int,input().split())))
def insr():
s = input()
return(list(s[:len(s) - 1]))
def invr():
return(map(int,input().split()))
################################################################
############ ---- THE ACTUAL CODE STARTS BELOW ---- ############
t=inp()
for _ in range(t):
n,m,k=invr()
ara=inara()
flag=True
for i in range(n-1):
if ara[i]>=ara[i+1]-k:
hobe=max(0,ara[i+1]-k)
m+=ara[i]-hobe
else:
lagbe=ara[i+1]-k-ara[i]
if m>=lagbe:
m-=lagbe
else:
flag=False
break
if flag:
print("YES")
else:
print("NO")
| 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
map<pair<long long, long long>, long long> A;
vector<pair<long long, long long>> B;
map<long long, long long> C;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
long long a, b;
cin >> a >> b;
for (int i = 0; i < n; i++) {
long long x, vx, vy;
cin >> x >> vx >> vy;
pair<long long, long long> p = {vx, vy};
A[p]++;
B.push_back(p);
}
for (auto it : A) {
C[it.first.second - a * it.first.first] += it.second;
}
long long ans = 0;
for (auto it : A) {
ans += (C[it.first.second - a * it.first.first] - it.second) * it.second;
}
cout << ans << endl;
return 0;
}
| 10 | CPP |
for _ in range(int(input())):
s=list(input())
c,c1,count=0,0,0
for i in range(len(s)):
if(s[i]=='+'):
c+=1
else:
c1+=1
if(c1>c):
c+=1
count=count+i+1
print(count+len(s))
| 9 | PYTHON3 |
n = int(input())
X = list(map(int,input().split()))
delta = [X[i+1] - X[i] for i in range(n-1)]
mod = 10**9 + 7
mother = 1
for i in range(1,n):
mother *= i
if mother > mod:mother %= mod
total = 0
ans = 0
for i in range(n-1):
now = (total*pow(i+1,mod-2,mod) + 1)%mod
ans += now*delta[i]%mod
if ans > mod: ans %= mod
total += now
print(ans*mother%mod)
| 0 | PYTHON3 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.