solution
stringlengths 10
983k
| difficulty
int64 0
25
| language
stringclasses 2
values |
---|---|---|
answer = 0
line = input()
lastCharacter = line[0]
sequence = 0
for i in range(len(line)):
if line[i] == lastCharacter:
sequence += 1
else:
sequence = 1
lastCharacter = line[i]
if(sequence >= 7):
answer = 1
break
if(answer):
print("YES")
else:
print("NO") | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int a[1005][1005], b[1005][1005], ta[1005], tb[1005];
int main() {
for (int i = 1; i <= 1000; i++) {
ta[i] = tb[i] = 0;
for (int j = 1; j <= 1000; j++) {
a[i][j] = b[i][j] = 0;
}
}
int n, m, x, y, color, d;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> color >> d;
a[color][d]++;
ta[d]++;
}
for (int i = 1; i <= m; i++) {
cin >> color >> d;
b[color][d]++;
tb[d]++;
}
int all, good;
all = good = 0;
for (int i = 1; i <= 1000; i++)
for (int j = 1; j <= 1000; j++) {
int tmp = min(a[i][j], b[i][j]);
good += tmp;
ta[j] -= tmp;
tb[j] -= tmp;
}
all = good;
for (int i = 1; i <= 1000; i++) {
int tmp = min(ta[i], tb[i]);
all += tmp;
}
cout << all << " " << good << endl;
}
| 8 | CPP |
n = int(input())
s = input()
ans = 0
w = s.count('.')
b = 0
ans = w+b
for c in s:
if c=='#':
b += 1
else:
w -= 1
ans = min(ans, w+b)
print(ans)
| 0 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
long long factorial[105];
long long rows[105];
long long columns[105];
char m[105][105];
long long fat(long long n) {
if (factorial[n] != 0) {
return factorial[n];
}
if (n <= 1) {
return factorial[n] = 1;
}
return factorial[n] = n * fat(n - 1);
}
long long perm(long long n) { return (n * (n - 1) / 2); }
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
char aux;
cin >> aux;
m[i][j] = aux;
if (m[i][j] == 'C') {
rows[i]++;
columns[j]++;
}
}
}
long long total = 0;
for (int i = 0; i < n; i++) {
if (columns[i] >= 2) {
total += perm(columns[i]);
}
if (rows[i] >= 2) {
total += perm(rows[i]);
}
}
cout << total << endl;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
//typedef tuple<int, int, int> T;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define ALL(c) c.begin(), c.end()
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = {0, 1, 0, -1};
int used[200010];
vector<int> edge[200010];
void dfs(int v) {
used[v] = 1;
for (int c : edge[v]) {
if (not used[c]) dfs(c);
}
}
int main() {
// use scanf in CodeForces!
cin.tie(0);
ios_base::sync_with_stdio(false);
int N, M; cin >> N >> M;
REP(i, N) {
int K; cin >> K;
REP(j, K) {
int l; cin >> l; l--;
edge[i].push_back(N+l);
edge[N+l].push_back(i);
}
}
dfs(0);
REP(i, N) {
if (not used[i]) {
cout << "NO" << endl;
return 0;
}
}
cout << "YES" << endl;
return 0;
}
| 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void smin(T &a, U b) {
if (a > b) a = b;
}
template <typename T, typename U>
inline void smax(T &a, U b) {
if (a < b) a = b;
}
inline void getint(int &first) {
char c;
while (c = getchar(), c > '9' || c < '0')
;
for (first = 0; c >= '0' && c <= '9'; c = getchar())
first = (first << 1) + (first << 3) + c - '0';
}
inline void print(int first) {
if (first < 10) {
putchar('0' + first);
return;
}
print(first / 10);
putchar(first % 10 + '0');
}
int power(int a, int b, int m, int ans = 1) {
for (; b; b >>= 1, a = 1LL * a * a % m)
if (b & 1) ans = 1LL * ans * a % m;
return ans;
}
vector<pair<long long, long long> > fac[5];
long long q[11111111];
int cmp(pair<long long, long long> &a, pair<long long, long long> b) {
if (a.first != b.first) return 0;
a.second += b.second;
return 1;
}
vector<pair<long long, long long> > calc1(
vector<pair<long long, long long> > &a,
vector<pair<long long, long long> > &b) {
int i = 0, n = a.size(), j = 0, m = b.size();
vector<pair<long long, long long> > tmp;
while (i < n && j < m) {
if (a[i].first == b[j].first) {
if (a[i].second < b[j].second)
tmp.push_back(pair<long long, long long>(b[j].first, a[i].second + 1));
i++, j++;
} else if (a[i].first > b[j].first)
tmp.push_back(pair<long long, long long>(b[j].first, 1)), j++;
else
i++;
}
while (j < m) tmp.push_back(pair<long long, long long>(b[j].first, 1)), j++;
return tmp;
}
vector<pair<long long, long long> > c;
long long calc(long long second, long long first) {
long long ans = 0;
for (int i = 0; i < c.size(); i++) {
if (first % c[i].first == 0) {
if (c[i].second & 1LL)
ans -= second / c[i].first;
else
ans += second / c[i].first;
}
}
return ans;
}
int main() {
int T, qb;
for (scanf("%d", &T); T--;) {
long long first = 1, second = 1, z = 2;
for (int i = 0; i < 3; i++) {
fac[i].clear();
if (i == 2) fac[i].push_back(pair<long long, long long>(2, 1));
for (int j = 0; j < 3; j++) {
int u;
scanf("%d", &u);
if (i == 0) first *= u;
if (i == 1) second *= u;
if (i == 2) z *= u;
for (int v = 2; v * v <= u; v++)
if (u % v == 0) {
int cnt = 0;
while (u % v == 0) u /= v, cnt++;
fac[i].push_back(pair<long long, long long>(v, cnt));
}
if (u > 1) fac[i].push_back(pair<long long, long long>(u, 1));
}
if (!fac[i].size()) continue;
sort(fac[i].begin(), fac[i].end());
fac[i].erase(unique(fac[i].begin(), fac[i].end(), cmp), fac[i].end());
}
qb = 0;
q[qb++] = 1;
fac[3] = calc1(fac[2], fac[0]);
long long mx = (long long)(sqrtl(z) + 1);
for (int i = 0; i < fac[2].size(); i++) {
long long u = fac[2][i].first, v = fac[2][i].second;
for (int z = qb, j = 0; j < z; j++) {
long long mid = 1;
for (int k = 0; k < v; k++) {
mid *= u;
if (mid > mx) break;
if (q[j] * mid > mx) break;
q[qb++] = q[j] * mid;
}
}
}
long long ans = 0;
for (int i = 0; i < qb; i++) {
if (z / q[i] < q[i]) continue;
if (q[i] <= first) ans++;
if (q[i] * q[i] == z) continue;
if (z / q[i] <= first) ans++;
}
qb = 0, q[qb++] = 1;
q[qb++] = 0;
for (int i = 0; i < fac[3].size(); i++) {
long long u = fac[3][i].first, v = fac[3][i].second;
for (int z = qb, j = 0; j < z; j += 2) {
long long mid = 1;
for (int k = 0; k < v; k++) mid *= u;
if (q[j] > second / mid) continue;
q[qb++] = q[j] * mid;
q[qb++] = q[j + 1] + 1;
}
}
for (int i = 0; i < qb; i += 2) {
if (q[i + 1] & 1LL)
ans -= second / q[i];
else
ans += second / q[i];
}
printf("%I64d\n", ans);
}
return 0;
}
| 9 | CPP |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void run() {
int n, m;
scanf("%d%d", &n, &m);
vector<string> v;
for (int i = 0; i < n; i++) {
string s;
cin >> s;
v.push_back(s);
}
string ans;
bool chk[11] = {};
for (int i = 0; i < m; i++) {
map<char, int> cnt;
int mx = 0;
char c;
int t;
for (int j = 0; j < n; j++) {
cnt[v[j][i]]++;
if (mx < cnt[v[j][i]]) {
mx = cnt[v[j][i]];
c = v[j][i];
t = j;
}
}
chk[t] = true;
ans.push_back(c);
}
bool gg = false;
for (int i = 0; i < n; i++) {
int diff = 0;
for (int j = 0; j < m; j++) {
if (ans[j] != v[i][j]) diff++;
}
if (diff > 1) {
gg = true;
string tmp;
for (int j = 0; j < m; j++) {
if (ans[j] != v[i][j]) {
tmp.push_back(v[i][j]);
for (int jj = j + 1; jj < m; jj++) {
tmp.push_back(ans[jj]);
}
bool pass = true;
for (int ii = 0; ii < n; ii++) {
int diff = 0;
for (int jj = 0; jj < m; jj++) {
if (tmp[jj] != v[ii][jj]) diff++;
}
if (diff > 1) {
pass = false;
}
}
if (pass) {
cout << tmp << endl;
return;
} else {
while (tmp.size() > j) tmp.pop_back();
tmp.push_back(ans[j]);
}
} else {
tmp.push_back(ans[j]);
}
}
}
}
if (!gg)
cout << ans << endl;
else
cout << "-1" << endl;
}
int main() {
int T;
scanf("%d", &T);
while (T--) {
run();
}
}
| 12 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int x, y;
cin >> x >> y;
if (min(x, y) % 2 == 0)
cout << "Malvika";
else
cout << "Akshat";
return 0;
}
| 7 | CPP |
n,x = map(int,input().split())
a = set(map(int,input().split()))
if (len(a)!=n):
print('0')
exit()
else:
for i in a:
if i&x!=i and i&x in a:
print('1')
exit()
a = set(i&x for i in a)
if len(a)!=n:
print('2')
exit()
print('-1')
| 8 | PYTHON3 |
import sys
from math import log2, floor
TEST = 0
if TEST == 1:
input_file = open("inputA.txt", "r")
input_from_file = input_file.readlines()
def read_int():
if TEST:
return int(input_from_file.pop(0))
else:
return int(sys.stdin.readline())
def read_ints():
if TEST:
return list(map(int, input_from_file.pop(0).rstrip().split()))
else:
return list(map(int, sys.stdin.readline().split()))
t = read_int()
for test in range(t):
n, m = read_ints()
open_col = [j for j in range(m)]
open_row = []
for j in range(n):
current_row = read_ints()
closed_in_row = [ind for ind, el in enumerate(current_row) if el == 1]
if len(closed_in_row) == 0:
open_row.append(j)
for ind in closed_in_row:
if ind in open_col:
open_col.remove(ind)
hodov = min(len(open_col), len(open_row))
if hodov & 1:
ans = 'Ashish'
else:
ans = 'Vivek'
print(ans)
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int n, a[maxn], b[maxn];
int vis[maxn][6];
void dfs(int i, int l) {
if (i > n) {
for (int i = 1; i <= n; i++) printf("%d ", b[i]);
exit(0);
}
if (vis[i][l]) return;
vis[i][l] = 1;
for (int f = 1; f <= 5; f++) {
if (a[i - 1] < a[i] && l < f) {
b[i] = f;
dfs(i + 1, f);
}
if (a[i - 1] > a[i] && l > f) {
b[i] = f;
dfs(i + 1, f);
}
if (a[i - 1] == a[i] && f != l) {
b[i] = f;
dfs(i + 1, f);
}
}
}
int main() {
scanf("%d", &n);
a[0] = maxn;
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
dfs(1, 5);
printf("-1\n");
}
| 9 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long n, m, t;
double second;
int main() {
cin >> m >> n;
second = 0.;
t = m;
for (double i = 1; i <= m; i++) {
second += (pow(i / t, n) - pow((i - 1) / t, n)) * i;
}
if (second > 0) {
cout << fixed << second;
} else
cout << 0.;
return 0;
}
| 9 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int m;
uint64_t n;
cin >> n >> m;
pair<int, uint64_t>* p = new pair<int, uint64_t>[m];
for (int i = 0; i < m; i++) {
cin >> p[i].second >> p[i].first;
}
if (m == 1) {
if (n > p[0].second) {
cout << p[0].second * p[0].first;
} else {
cout << n * p[0].first;
}
return 0;
}
sort(p, p + m);
uint64_t sum = 0, match = 0;
int i = m - 1;
while (sum < n && i >= 0) {
if (p[i].second <= (n - sum)) {
match += p[i].second * p[i].first;
sum += p[i].second;
i--;
} else {
match += (n - sum) * p[i].first;
break;
}
}
cout << match;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i, j, k;
cin >> n;
k = n / 2;
k = k * (n - k);
int p = n / 2;
cout << k << endl;
for (i = 1; i <= p; i++)
for (j = p + 1; j <= n; j++) cout << i << " " << j << endl;
return 0;
}
| 11 | CPP |
#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main()
{
int n,m;
cin>>n>>m;
pair<int,int> p[m];
for (int i = 0; i < m; ++i) {
cin>>p[i].second>>p[i].first;
}
sort(p,p+m);
int mx=0;
int cnt=0;
for (int i = 0; i < m; ++i) {
if(p[i].second>=mx)
{
mx=max(mx,p[i].first);
cnt++;
}
}
cout<<cnt;
} | 0 | CPP |
# bsdk idhar kya dekhne ko aaya hai, khud kr!!!
# import math
# from itertools import *
# import random
# import calendar
# import datetime
# import webbrowser
n, k = map(int, input().split())
max_ = -10000000000
for i in range(n):
f, t = map(int, input().split())
if t <= k:
if max_ < f:
max_ = f
elif t > k:
if max_ < (f - (t - k)):
max_ = (f - (t - k))
print(max_)
| 7 | PYTHON3 |
a, b = map(int, input().split())
if b-a == 1 and a > 0 and b > 0:
print(a, b)
elif a == 9 and b == 1:
print(9, 10)
elif a == b and a > 0 and b > 0:
print(a, '0', ' ', b, '1', sep = '')
else:
print(-1) | 7 | PYTHON3 |
n=int(input())
a=list(map(int,input().split()))
p=sum(a)*2//n
for i in range(n):
for j in range(n):
if i!=j and a[i]+a[j]==p:print(i+1,j+1);a[j]=a[i]=0 | 7 | PYTHON3 |
import sys
input = sys.stdin.buffer.readline
t=int(input())
for _ in range(t):
string=str(input())
p1=-1
p2=-1
p3=-1
x=2*len(string)
for i in range(len(string)):
if string[i]=="1":
p1=i
elif string[i]=="2":
p2=i
elif string[i]=="3":
p3=i
if p1!=-1 and p2!=-1 and p3!=-1:
x=min(x,max(p1,p2,p3)-min(p1,p2,p3))
if p1==-1 or p2==-1 or p3==-1:
print(0)
else:
print(x+1) | 8 | PYTHON3 |
#include<bits/stdc++.h>
using namespace std;
int main(){
string S;cin>>S;long x=0,y=0;
for(char c:S){
if(c=='A'||c=='T'||c=='C'||c=='G')x++;
else {y=max(y,x);x=0;}
}y=max(y,x);
cout<<y;
} | 0 | CPP |
#include<bits/stdc++.h>
using namespace std;
const int N=2e3+5;
const int P=1e9+7;
long long n,m,a[N],b[N],s[N][N],dp[N][N];
int main(){
scanf("%lld%lld",&n,&m);
for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
for(int i=1;i<=m;i++) scanf("%lld",&b[i]);
for(int i=0;i<=n;i++) s[i][0]=1;
for(int i=0;i<=m;i++) s[0][i]=1;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++){
s[i][j]=(s[i-1][j]+s[i][j-1]-s[i-1][j-1]+P)%P;
if(a[i]==b[j]) dp[i][j]=s[i-1][j-1];
s[i][j]=(s[i][j]+dp[i][j])%P;
}
printf("%lld\n",s[n][m]);
return 0;
} | 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long mypow(long long a, long long b) {
if (b == 0) return 1;
long long temp = mypow(a, b / 2);
temp = (temp * temp) % 1000000007LL;
if (b % 2 == 1) temp = (a * temp) % 1000000007LL;
return temp;
}
int mygcd(int a, int b) {
if (b == 0) return a;
return mygcd(b, a % b);
}
int cntBits(long long a) {
int ret = 0;
while (a > 0) {
ret++;
a /= 2;
}
return ret;
}
int points[200002][5], mxSeg[32][4 * 200002], mnSeg[32][4 * 200002];
vector<vector<int> > coeff;
vector<int> temp;
void build_coeff(int index, int k) {
if (index == k)
coeff.push_back(temp);
else {
temp.push_back(1);
build_coeff(index + 1, k);
temp.pop_back();
temp.push_back(-1);
build_coeff(index + 1, k);
temp.pop_back();
}
}
int getSum(int point_index, int coeff_index) {
int ret = 0;
for (int i = 0; i < coeff[coeff_index].size(); i++) {
ret += coeff[coeff_index][i] * points[point_index][i];
}
return ret;
}
void buildSeg1(int l, int r, int coeff, int index) {
if (l == r)
mxSeg[coeff][index] = getSum(l, coeff);
else {
int mid = l + (r - l) / 2;
buildSeg1(l, mid, coeff, 2 * index + 1);
buildSeg1(mid + 1, r, coeff, 2 * index + 2);
mxSeg[coeff][index] =
max(mxSeg[coeff][2 * index + 1], mxSeg[coeff][2 * index + 2]);
}
}
void buildSeg2(int l, int r, int coeff, int index) {
if (l == r)
mnSeg[coeff][index] = getSum(l, coeff);
else {
int mid = l + (r - l) / 2;
buildSeg2(l, mid, coeff, 2 * index + 1);
buildSeg2(mid + 1, r, coeff, 2 * index + 2);
mnSeg[coeff][index] =
min(mnSeg[coeff][2 * index + 1], mnSeg[coeff][2 * index + 2]);
}
}
void updateSeg1(int req_index, int l, int r, int coeff, int index) {
if (l == r && l == req_index)
mxSeg[coeff][index] = getSum(l, coeff);
else {
int mid = l + (r - l) / 2;
if (req_index <= mid)
updateSeg1(req_index, l, mid, coeff, 2 * index + 1);
else
updateSeg1(req_index, mid + 1, r, coeff, 2 * index + 2);
mxSeg[coeff][index] =
max(mxSeg[coeff][2 * index + 1], mxSeg[coeff][2 * index + 2]);
}
}
void updateSeg2(int req_index, int l, int r, int coeff, int index) {
if (l == r && l == req_index)
mnSeg[coeff][index] = getSum(l, coeff);
else {
int mid = l + (r - l) / 2;
if (req_index <= mid)
updateSeg2(req_index, l, mid, coeff, 2 * index + 1);
else
updateSeg2(req_index, mid + 1, r, coeff, 2 * index + 2);
mnSeg[coeff][index] =
min(mnSeg[coeff][2 * index + 1], mnSeg[coeff][2 * index + 2]);
}
}
int querySeg1(int req_l, int req_r, int l, int r, int index, int coeff) {
if (req_r < l || r < req_l) return INT_MIN;
if (l >= req_l && r <= req_r) return mxSeg[coeff][index];
int mid = l + (r - l) / 2, lef, rig;
lef = querySeg1(req_l, req_r, l, mid, 2 * index + 1, coeff);
rig = querySeg1(req_l, req_r, mid + 1, r, 2 * index + 2, coeff);
return max(lef, rig);
}
int querySeg2(int req_l, int req_r, int l, int r, int index, int coeff) {
if (req_r < l || r < req_l) return INT_MAX;
if (l >= req_l && r <= req_r) return mnSeg[coeff][index];
int mid = l + (r - l) / 2, lef, rig;
lef = querySeg2(req_l, req_r, l, mid, 2 * index + 1, coeff);
rig = querySeg2(req_l, req_r, mid + 1, r, 2 * index + 2, coeff);
return min(lef, rig);
}
int main() {
ios::sync_with_stdio(0);
int tt = 1;
for (int tcase = 1; tcase <= tt; tcase++) {
int n, k;
cin >> n >> k;
temp.push_back(1);
build_coeff(1, k);
int tot_coeffs = (1 << (k - 1));
for (int i = 0; i < n; i++)
for (int j = 0; j < k; j++) cin >> points[i][j];
for (int i = 0; i < tot_coeffs; i++) {
buildSeg1(0, n - 1, i, 0);
buildSeg2(0, n - 1, i, 0);
}
int q;
cin >> q;
while (q--) {
int type;
cin >> type;
if (type == 1) {
int i;
cin >> i;
i--;
for (int j = 0; j < k; j++) cin >> points[i][j];
for (int j = 0; j < tot_coeffs; j++) {
updateSeg1(i, 0, n - 1, j, 0);
updateSeg2(i, 0, n - 1, j, 0);
}
} else {
int l, r, ans = 0;
cin >> l >> r;
l--;
r--;
for (int i = 0; i < tot_coeffs; i++) {
ans = max(ans, abs(querySeg1(l, r, 0, n - 1, 0, i) -
querySeg2(l, r, 0, n - 1, 0, i)));
}
cout << ans << "\n";
}
}
}
return 0;
}
| 13 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
string s;
int b[N], sum[N];
char p[] = "aeiou";
bool check(char c) {
for (int i = 0; i < 5; i++) {
if (c == p[i] || c == p[i] - 32) {
return true;
}
}
return false;
}
int main() {
cin >> s;
int n = s.length();
for (int i = 0; i < n; i++) {
b[i + 1] = check(s[i]) ? -1 : 2;
}
partial_sum(b + 1, b + n + 1, b + 1);
vector<pair<int, int> > v;
for (int i = 1; i <= n; i++) {
v.push_back(make_pair(b[i], i));
}
v.push_back(make_pair(0, 0));
sort(v.begin(), v.end());
deque<pair<int, int> > Q;
int ret = 0, cnt = 0;
for (int i = 0; i <= n; i++) {
if (!Q.empty() && v[i].first - Q.front().first >= 0) {
int tmp = v[i].second - Q.front().second;
if (tmp > ret) {
ret = tmp;
cnt = 1;
} else if (ret == tmp) {
cnt++;
}
}
while (!Q.empty() && v[i].second <= Q.back().second) {
Q.pop_back();
}
Q.push_back(v[i]);
}
if (!ret) {
printf("No solution\n");
} else {
printf("%d %d\n", ret, cnt);
}
return 0;
}
| 11 | CPP |
l,r = map(int,input().split())
for i in range(l, r + 1):
st = set(list(str(i)))
if len(st) == len(str(i)):
print(i)
exit(0)
print(-1) | 7 | PYTHON3 |
import sys
def fastio():
from io import StringIO
from atexit import register
global input
sys.stdin = StringIO(sys.stdin.read())
input = lambda : sys.stdin.readline().rstrip('\r\n')
sys.stdout = StringIO()
register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()
def debug(*var, sep = ' ', end = '\n'):
print(*var, file=sys.stderr, end = end, sep = sep)
INF = 10**20
MOD = 10**9 + 7
I = lambda:list(map(int,input().split()))
from math import gcd
from math import ceil
from collections import defaultdict as dd, Counter
from bisect import bisect_left as bl, bisect_right as br
t, = I()
for test in range(t):
n = I()
arr = I()
arr = sorted(arr, reverse=True)
print(*arr) | 8 | PYTHON3 |
n=int(input())
for i in range(n):
t=int(input())
if(t==2):
print(0)
elif(t%2==0):
t=t//2
print(t-1)
else:
print(t//2) | 7 | PYTHON3 |
#in the name of god
#Mr_Rubick
n=int(input())
if n%2==0: print((n-1)//2)
else: print(n//2) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1);
const int inf = 1e9;
int n, m, x, cnt;
bool k = 0;
vector<int> a[105];
int main() {
cin >> n;
for (int i = 0; i < n; ++i) {
cin >> m;
for (int j = 0; j < m; ++j) {
cin >> x;
a[i].push_back(x);
}
sort(a[i].begin(), a[i].end());
}
for (int i = 0; i < n; ++i) {
k = 0;
for (int j = 0; j < n; j++) {
if (i == j) continue;
cnt = 0;
for (int k = 0; k < a[j].size(); ++k) {
for (int h = 0; h < a[i].size(); ++h)
if (a[j][k] == a[i][h]) cnt++;
}
if (cnt == a[j].size() && cnt <= a[i].size()) {
k = 1;
cout << "NO" << endl;
break;
}
}
if (!k) cout << "YES" << endl;
}
return 0;
}
| 8 | CPP |
T = int(input())
for t in range(T):
s = input()
l = len(s)
if s.count("0") == l or s.count("1") == l:
print(s)
else:
print("10" * l)
| 8 | PYTHON3 |
from math import ceil
m,n,a=map(int,input().split())
times=ceil(m/a)*ceil(n/a)
print(times) | 7 | PYTHON3 |
n = int(input())
mod = 10**9+7
s = [0] * (n+1)
for i in range(2, n+1):
p = 2
while i>1:
while i%p==0:
i //= p
s[p] += 1
p += 1
ans = 1
for i in s:
ans *= i+1
ans %= mod
print(ans) | 0 | PYTHON3 |
# coding: utf-8
# Your code here!
n=int(input())
def hi(n):
return len(bin(n))-2-bin(n)[2::].index('0')
def on(n):
return bin(n).count('1')==len(bin(n))-2
a=[]
cnt=0
m=1
x=n
while on(x)==False and cnt<40:
#print(x,bin(x))
cnt+=1
if m==1:
k=hi(x)
#print(k,x)
x=x^(2**k-1)
a.append(k)
else:
x+=1
m=1-m
print(cnt)
print(*a) | 8 | PYTHON3 |
q = (input())
temp = q.split()
n = int(temp[0])
m = int(temp[1])
a = int(temp[2])
import math
print ((math.ceil(n/a))*(math.ceil((m/a))))
| 7 | PYTHON3 |
t=int(input())
for _ in range(t):
n,k=map(int,input().split())
x=int(n/k)
if x*k<n:
r=n-(x*k)
if r>(int(k/2)):
print((x*k)+int(k/2))
else:
print((x*k)+r)
else:
print(x*k)
| 8 | PYTHON3 |
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <queue>
#include <map>
#include <functional>
#include <cstring>
using namespace std;
#define INF 1000000000
int main(){
int n,k;
while(scanf("%d%d",&n,&k),(n|k)){
int a;
int d[128][128];
for(int i = 0; i < 101; i++){
for(int j = 0; j < 101; j++){
d[i][j] = i == j?0:INF;
}
}
for(int l = 0; l < k; l++){
scanf("%d",&a);
if(a == 1){
int f,t,c;
scanf("%d%d%d",&f,&t,&c);
f--;
t--;
if(d[f][t] > c){
d[f][t] = d[t][f] = c;
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
d[i][j] = min(d[i][j],d[i][f] + d[f][t] + d[t][j]);
d[i][j] = min(d[i][j],d[i][t] + d[t][f] + d[f][j]);
d[j][i] = d[i][j];
}
}
}
}
else{
int f,t;
scanf("%d%d",&f,&t);
f--;
t--;
if(d[f][t] == INF)puts("-1");
else printf("%d\n",d[f][t]);
}
}
}
return 0;
} | 0 | CPP |
s = input()
h = 0
e = 0
l = 0
o = 0
for c in s:
if (c=="h") and (e==0) and (l==0) and (o==0): h+=1
if(c=="e") and (h>0) and (l==0) and (o==0): e+=1
if (c=="l") and (e>0) and (o==0): l+=1
if(c=="o") and(l>1): o+=1
if (h>0)and(e>0)and(l>1)and(o>0): print("YES")
else: print("NO") | 7 | PYTHON3 |
q=input().split()
for i in range(len(q)): q[i]=int(q[i])
q.sort()
print(q[3]-q[1], q[3]-q[2], q[3]-q[0]) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int i, j, k, l, n, m, p = 1, t, f;
string s;
long long int a[100];
memset(a, -1, sizeof(a));
cin >> s;
k = 10;
for (i = 0; i < s.size(); i++) {
if ((int)s[i] >= 65 && (int)s[i] <= 74 && a[i] == -1) {
f = 0;
for (j = i + 1; j < s.size(); j++)
if (s[i] == s[j] && a[j] == -1) {
a[j] = 0;
}
{
if (i > 0) {
p *= k;
k--;
} else {
p *= 9;
k = 9;
}
}
} else if (s[i] == '?') {
if (i == 0)
p *= 9;
else
p *= 10;
}
}
cout << p;
}
| 7 | CPP |
#!/usr/bin/python
N, K = map(int, input().split())
A = list(map(int, input().split()))
count = 0
for x in A:
if x >= A[K - 1] and x > 0 :
count += 1
print (count) | 7 | PYTHON3 |
abc = input()
q = 0
for sym in abc:
if sym in 'aueoi' or sym.isdigit() and int(sym) % 2 == 1:
q += 1
print(q) | 7 | PYTHON3 |
t_queries = int(input())
for query in range(t_queries):
_input = [int(num) for num in input().split(" ")]
num_students = _input[0]
highest_possible_score = _input[1]
scores = [int(num) for num in input().split(" ")]
prev_average_score = sum(scores) / num_students
ptr1 = num_students - 1
if ptr1 > 0:
while sum(scores) / num_students == prev_average_score and scores[0] < highest_possible_score and ptr1 > 0:
if scores[ptr1] == 0:
ptr1 -= 1
else:
grade_to_add = highest_possible_score - scores[0]
if scores[ptr1] >= grade_to_add:
scores[0] += grade_to_add
scores[ptr1] -= grade_to_add
else:
scores[0] += scores[ptr1]
scores[ptr1] = 0
print(scores[0])
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
double fRand(double fMin, double fMax) {
double f = (double)rand() / RAND_MAX;
return fMin + f * (fMax - fMin);
}
template <class T>
T min(T a, T b, T c) {
return min(a, min(b, c));
}
template <class T>
T max(T a, T b, T c) {
return max(a, max(b, c));
}
int n;
char a[15][15], b[15][15], c[15][15], d[15][15];
bool isEqual(char a[][15], char b[][15]) {
for (int i = (0); i <= (n - 1); ++i)
for (int j = (0); j <= (n - 1); ++j)
if (a[i][j] != b[i][j]) return false;
return true;
}
int main() {
scanf("%d", &n);
for (int i = (0); i <= (n - 1); ++i) scanf("%s", a[i]);
for (int i = (0); i <= (n - 1); ++i) scanf("%s", b[i]);
for (int i = (0); i <= (3); ++i) {
for (int x = (0); x <= (n - 1); ++x)
for (int y = (0); y <= (n - 1); ++y) c[n - y - 1][x] = a[x][y];
for (int x = (0); x <= (n - 1); ++x)
for (int y = (0); y <= (n - 1); ++y) d[x][n - y - 1] = c[x][y];
if (isEqual(b, c) || isEqual(b, d)) {
puts("Yes");
return 0;
}
for (int x = (0); x <= (n - 1); ++x)
for (int y = (0); y <= (n - 1); ++y) a[x][y] = c[x][y];
}
puts("No");
return 0;
}
| 7 | CPP |
for t in range(int(input())):
n=int(input())
a=list(map(int,input().split()))
res=set()
p=[]
for i in a:
if i not in res:
res.add(i)
p.append(i)
print(*p) | 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
unsigned long long int MOD = 1000000007;
unsigned long long int B = 13331;
bool cmp(const int &a, const int &b) { return a < b; }
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int lcm(int a, int b) { return a * (b / gcd(a, b)); }
unsigned long long int int_mod(unsigned long long int a) {
return (a + MOD) % MOD;
}
unsigned long long int power_expo(unsigned long long int a,
unsigned long long int b) {
unsigned long long int t;
if (b == 0) return 1;
if (b == 1) return int_mod(a);
t = power_expo(a, b / 2);
return b % 2 == 0 ? int_mod(t * t) : int_mod(int_mod(t * t) * a);
}
int main() {
int i, j, k;
int n;
cin >> n;
string s[105];
int flag = 0;
for (i = 0; i < n; i++) {
cin >> s[i];
int a, b;
cin >> a >> b;
if (a >= 2400 && b >= 2400 && b > a) flag = 1;
}
if (flag)
cout << "YES";
else
cout << "NO";
return 0;
}
| 7 | CPP |
import sys
s = input()
if len(s) == 1 and s.islower():
print(s.upper())
elif s.isupper():
print(s.lower())
elif s[0].islower() and s[1:].isupper():
print(s[0].upper() + s[1:].lower())
else:
print(s) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
template <typename Iter>
ostream& _out(ostream& s, Iter a, Iter b) {
for (auto it = a; it != b; it++) s << (it == a ? "" : " ") << *it;
return s;
}
template <typename A, typename B>
ostream& operator<<(ostream& s, pair<A, B>& p) {
return s << "(" << p.first << " , " << p.second << ")";
}
template <typename T>
ostream& operator<<(ostream& s, vector<T>& v) {
return _out(s, v.begin(), v.end());
}
inline long long rit() {
int key = 1;
char c = getchar();
while (!isdigit(c)) {
if (c == '-') key = -1;
c = getchar();
}
long long x = 0;
while (isdigit(c)) {
x = x * 10 + c - '0';
c = getchar();
}
return x * key;
}
int __ = 1;
void init() {}
void read() {}
void solve() {}
int main() {
int a, b, c, n;
vector<int> x, y, z;
cin >> a >> b >> c >> n;
for (int i = 0; i < n; i++) {
int res;
string s;
cin >> res >> s;
if (s[0] == 'U')
x.push_back(res);
else
y.push_back(res);
}
sort(x.begin(), x.end());
sort(y.begin(), y.end());
long long ans = 0;
int cnt = 0;
for (int i = 0; i < min((int)x.size(), a); i++) {
ans += x[i];
cnt++;
}
for (int i = 0; i < min((int)y.size(), b); i++) {
ans += y[i];
cnt++;
}
for (int i = a; i < x.size(); i++) {
z.push_back(x[i]);
}
for (int i = b; i < y.size(); i++) {
z.push_back(y[i]);
}
sort(z.begin(), z.end());
for (int i = 0; i < min((int)z.size(), c); i++) {
ans += z[i];
cnt++;
}
printf("%d %I64d\n", cnt, ans);
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
vector<int> v[3];
string s;
int sm;
inline bool cmp(int a, int b) { return a > b; }
bool work(int i) {
int flag = 0;
sort(v[1].begin(), v[1].end(), cmp);
sort(v[2].begin(), v[2].end(), cmp);
if (v[i].size()) {
if (v[i][0] == 0 && s[1] == '0' && v[3 - i].size() >= 2) goto E;
s.erase(v[i][0], 1);
while (s.length() > 1 && s[0] == '0') s.erase(0, 1);
flag = 1;
} else if (v[3 - i].size() >= 2) {
E:
s.erase(v[3 - i][0], 1);
s.erase(v[3 - i][1], 1);
while (s.length() > 1 && s[0] == '0') s.erase(0, 1);
flag = 1;
} else if (v[0].size()) {
s = "0";
flag = 1;
}
if (s.length() == 0 || !flag) return false;
return true;
}
int main() {
cin >> s;
for (int i = 0; i < s.length(); i++) {
int tp = s[i] - '0';
if (tp != 0 && tp % 3 == 0) continue;
v[tp % 3].push_back(i);
sm += s[i] - '0';
}
if (sm % 3 == 0) {
while (s.length() > 1 && s[0] == '0') s.erase(0, 1);
cout << s << endl;
return 0;
} else if (work(sm % 3)) {
cout << s << endl;
return 0;
} else
return 0 * puts("-1");
return 0;
}
| 9 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
string S;
cin >> S;
cout << "ABC" << S << "\n";
} | 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 3001;
vector<int> cost[N];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
int cnt = 0;
long long ans = 0;
for (int i = 0; i < n; ++i) {
int a, b;
cin >> a >> b;
if (a == 1) {
++cnt;
} else {
cost[a].push_back(b);
ans += b;
}
}
for (int i = 2; i <= m; ++i) {
sort(cost[i].begin(), cost[i].end());
}
for (int i = cnt; i <= n; ++i) {
int cur = cnt;
vector<int> ext;
long long res = 0;
for (int j = 2; j <= m; ++j) {
for (int k = 0; k < int(cost[j].size()); ++k) {
if (int(cost[j].size()) - k >= i) {
res += cost[j][k];
++cur;
} else {
ext.push_back(cost[j][k]);
}
}
}
sort(ext.begin(), ext.end());
for (int j = 0; j < i - cur; ++j) {
res += ext[j];
}
ans = min(ans, res);
}
cout << ans << "\n";
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
ll x;
cin>>x;
ll a=100;
int t=0;
while(a<x)
{
a=a+(a)*0.01;
t++;
}
cout<<t;
}
| 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int d, i, j, k = 0, t = 0, n, r = 0;
cin >> n;
int a[n];
for (i = 0; i < n; i++) {
cin >> a[i];
k++;
if (a[i] == 0) t++;
}
if (t == n) {
cout << 0;
return 0;
}
i = 0;
d = n - 1;
if (a[0] == 0) {
k--;
i++;
}
if (a[n - 1] == 0 && a[n - 2] == 1) {
k--;
}
while (i < n) {
r = 0;
if (a[i] == 0 && a[i + 1] == 0 && i + 1 < n) {
k = k - 2;
i++;
r++;
}
if (r == 0) {
if (a[i] == 0 && a[i - 1] == 0) {
k--;
}
}
i++;
}
cout << k;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, m, k, bl[12];
bool vis[12], E[12][12];
long long ans;
vector<vector<int> > V, part;
unordered_set<long long> se;
vector<int> cur;
long long H(vector<int> p) {
long long s = 0;
for (int i = (0), iend = (n - 1); i <= iend; ++i) s = s * n + p[i];
return s;
}
void dfs0(int now) {
if (now == n)
part.push_back(cur);
else
for (int i = (0), iend = (n - 1); i <= iend; ++i)
if (!vis[i] && bl[now] == bl[i] && i != now && (i > now || cur[i] == now))
cur.push_back(i), vis[i] = 1, dfs0(now + 1), vis[i] = 0, cur.pop_back();
}
void dfs(int now) {
if (now == n) {
bool zzh = 1;
for (const auto& v : V) zzh &= v.size() % 2 == 0;
if (!zzh) return;
for (const auto& v : V)
for (const auto& x : v) bl[x] = v[0];
bool asf = 0;
part.clear(), dfs0(0);
for (const auto& p : part) {
if (se.count(H(p))) {
asf = 1;
break;
}
}
if (asf) {
long long res = 1;
for (int i = (1), iend = (V.size()); i <= iend; ++i) res *= k - i + 1;
ans += res;
}
return;
}
for (int i = (0), iend = (V.size() - 1); i <= iend; ++i)
V[i].push_back(now), dfs(now + 1), V[i].pop_back();
V.push_back({now}), dfs(now + 1), V.pop_back();
}
int main() {
cin >> n >> m >> k;
while (m--) {
int u, v;
cin >> u >> v, u--, v--, E[u][v] = E[v][u] = 1;
}
dfs0(0);
for (const auto& p : part) {
bool asf = 0;
int U[6], V[6], ct = 0;
for (int i = (0), iend = (n - 1); i <= iend; ++i)
if (i < p[i]) U[ct] = i, V[ct] = p[i], ct++;
int q[6];
for (int i = (0), iend = (ct - 1); i <= iend; ++i) q[i] = i;
do {
int x = U[q[0]], y = V[q[0]];
bool flg = E[x][y];
for (int i = (1), iend = (ct - 1); i <= iend; ++i) {
int u = U[q[i]], v = V[q[i]];
flg &= (E[x][u] && E[y][v]) || (E[x][v] && E[y][u]);
x = u, y = v;
}
if (flg) {
asf = 1;
break;
}
} while (next_permutation(q, q + ct));
if (asf) se.insert(H(p));
}
dfs(0);
cout << ans << endl;
return 0;
}
| 12 | CPP |
t = int(input())
for T in range(t):
n = int(input())
n *= 2
a = [int(x) for x in input().split()]
odd = []
even = []
for i in range(n):
if a[i] % 2 == 0:
even.append(i + 1)
else:
odd.append(i + 1)
## print(odd)
## print(even)
if len(even) > 0:
for i in range(0, len(odd) - 1, 2):
print(odd[i], odd[i + 1])
for i in range(0, len(even) - 2, 2):
print(even[i], even[i + 1])
else:
for i in range(0, len(odd) - 2, 2):
print(odd[i], odd[i + 1])
| 8 | PYTHON3 |
n = int(input())
arr = [0]*n
a = list(map(int,input().split()))[::-1]
b = list(map(int,input().split()))[::-1]
for i in range(n):
arr[a[i]-1] = i
for i in range(n):
b[i] = arr[b[i]-1]
check = -1
ans = 0
for i in b:
if check > i:
ans += 1
check = max(check,i)
print(ans) | 8 | PYTHON3 |
import sys
sys.setrecursionlimit(10**6)
n,q=map(int,input().split())
pair=[i for i in range(n)]
def root(x):
if pair[x]==x:
return x
else:
pair[x]=root(pair[x])
return pair[x]
for i in range(q):
com,x,y=map(int,input().split())
if com==0:
x1=root(x-1)
y1=root(y-1)
if x1!=y1:
pair[x1]=y1
elif com==1:
if root(x-1)==root(y-1):
print(1)
else:
print(0)
| 0 | PYTHON3 |
N, L, T = map(int, input().split())
gap = 0
X = [0] * N
for i in range(N):
x, w = map(int, input().split())
x += ((w + 1) % 3 - 1) * T
gap += x // L
gap %= N
X[i] = x % L
X.sort()
for i in range(N):
print(X[(i+gap) % N]) | 0 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e2 + 6;
map<set<int>, int> memo;
int arr[MAX];
int n;
int mex(vector<int> v) {
sort(v.begin(), v.end());
v.erase(unique(v.begin(), v.end()), v.end());
for (int i = int(0); i < int(v.size()); i++) {
if (v[i] != i) {
return i;
}
}
return v.size();
}
int roll(set<int> state) {
if (state.empty()) {
return 0;
}
if (memo.count(state)) {
return memo[state];
}
int &ans = memo[state];
int maxx = *state.rbegin();
ans = 0;
vector<int> states;
for (int i = int(1); i < int(maxx + 1); i++) {
vector<int> new_vals;
for (auto &each : state) {
if (each < i) {
new_vals.push_back(each);
} else if (each > i) {
new_vals.push_back(each - i);
}
}
set<int> new_state(new_vals.begin(), new_vals.end());
states.push_back(roll(new_state));
}
ans = mex(states);
return ans;
}
int main() {
scanf("%d", &n);
map<int, set<int> > mp;
for (int i = int(1); i < int(n + 1); i++) {
scanf("%d", arr + i);
set<int> cur;
for (long long j = 2; j * j <= arr[i]; j++) {
int e = 0;
while (arr[i] % j == 0) {
arr[i] /= j;
e++;
}
if (e) {
mp[j].insert(e);
}
}
if (arr[i] != 1) {
mp[arr[i]].insert(1);
}
}
int x = 0;
for (auto &each : mp) {
x ^= roll(each.second);
}
puts(x ? "Mojtaba" : "Arpa");
return 0;
}
| 9 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long int const MAXN = 1e2 + 8;
long long int const INF = 1e18 + 8;
long long int const delta = 1000000007;
vector<long long int> fib;
long long int dp1[MAXN];
long long int dp2[MAXN];
void pre() {
fib.push_back(1);
;
fib.push_back(2);
;
for (long long int i = 2; i < 90; i++) {
fib.push_back(fib[i - 1] + fib[i - 2]);
;
}
}
long long int ans(long long int n) {
memset(dp1, 0, sizeof(dp1));
memset(dp2, 0, sizeof(dp2));
vector<long long int> temp;
for (long long int i = fib.size() - 1; i >= 0; i--) {
if (n >= fib[i]) {
n -= fib[i];
temp.push_back(i);
;
}
}
reverse(temp.begin(), temp.end());
dp1[0] = 1;
dp2[0] = temp[0] / 2;
for (long long int i = 1; i < temp.size(); i++) {
dp1[i] = dp2[i - 1] + dp1[i - 1];
dp2[i] = (dp1[i - 1] * ((temp[i] - temp[i - 1] - 1) / 2)) +
(dp2[i - 1] * ((temp[i] - temp[i - 1]) / 2));
}
return dp1[temp.size() - 1] + dp2[temp.size() - 1];
}
int main() {
std::ios::sync_with_stdio(0);
;
cin.tie(0);
cout.tie(0);
pre();
long long int n;
cin >> n;
long long int t;
for (long long int i = 0; i < n; i++) {
cin >> t;
cout << ans(t) << endl;
}
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long GCD(long long a, long long b) {
if (b == 0)
return a;
else
return GCD(b, a % b);
}
inline long long mod(long long a, long long m) { return (a % m + m) % m; }
long long modmul(long long a, long long b, long long m) {
a = mod(a, m);
b = mod(b, m);
if (b == 0) return 0;
long long res = modmul(mod(a + a, m), b >> 1, m);
if (b & 1) res = mod(res + a, m);
return res;
}
long long modinv(long long a, long long m) {
long long b = m, u = 1, v = 0;
while (b) {
long long t = a / b;
a = mod(a - modmul(t, b, m), m);
swap(a, b);
u = mod(u - modmul(t, v, m), m);
swap(u, v);
}
return mod(u, m);
}
pair<long long, long long> ChineseRem(const vector<long long> &b,
const vector<long long> &m,
long long lcm) {
long long r = 0, M = 1;
for (int i = 0; i < (int)b.size(); ++i) {
long long d = GCD(M, m[i]);
if ((b[i] - r) % d != 0) return make_pair(0, -1);
long long p = modinv(M / d, m[i] / d);
long long tmp = modmul((b[i] - r) / d, p, m[i] / d);
r += modmul(M, tmp, lcm);
M *= m[i] / d;
}
return make_pair(mod(r, M), M);
}
bool solve(long long N, long long M, long long K, vector<long long> A) {
long long lcm = 1;
for (int i = 0; i < K; ++i) {
long long g = GCD(lcm, A[i]);
lcm *= (A[i] / g);
if (lcm > N) return false;
}
vector<long long> b(K), m(K);
for (int i = 0; i < K; ++i) b[i] = mod(-i, A[i]), m[i] = A[i];
pair<long long, long long> res = ChineseRem(b, m, lcm);
if (res.second == -1) return false;
if (res.first == 0) res.first = lcm;
if (res.first > M - K + 1) return false;
for (int k = 0; k < K; ++k) {
if (GCD(lcm, res.first + k) != A[k]) return false;
}
return true;
}
int main() {
long long N, M, K;
cin >> N >> M >> K;
vector<long long> A(K);
for (int i = 0; i < K; ++i) cin >> A[i];
if (solve(N, M, K, A))
cout << "YES" << endl;
else
cout << "NO" << endl;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
int a[3][100], pr[3][100], suff[3][100], b[101], i, j, n, mn, now, pos, ans;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n;
for (i = 1; i <= 2; ++i)
for (j = 1; j < n; ++j) cin >> a[i][j], pr[i][j] = suff[i][j] = a[i][j];
for (j = 2; j < n; ++j) pr[1][j] += pr[1][j - 1];
for (j = n - 2; j > 0; --j) suff[2][j] += suff[2][j + 1];
for (i = 1; i <= n; ++i) cin >> b[i];
mn = 1e9 + 121;
for (i = 1; i <= n; ++i) {
now = pr[1][i - 1] + suff[2][i] + b[i];
if (now < mn) {
mn = now;
pos = i;
}
}
ans = mn;
mn = 1e9 + 121;
for (i = 1; i <= n; ++i) {
now = pr[1][i - 1] + suff[2][i] + b[i];
if (now < mn && i != pos) mn = now;
}
cout << ans + mn << endl;
return 0;
}
| 8 | CPP |
from sys import stdin
input = stdin.readline
mp = lambda : map(int,input().split())
it = lambda: int(input())
for _ in range(it()):
a,b = mp()
t = [list(map(int,list(input().strip()))) for i in range(a)]
# print(t)
saare =[]
for i in range(a-2):
for j in range(b):
if t[i][j]==1:
if j!=b-1:
t[i][j]=1-t[i][j]
t[i+1][j]=1-t[i+1][j]
t[i+1][j+1]=1-t[i+1][j+1]
saare.append([i,j,i+1,j,i+1,j+1])
else:
t[i][j]=1-t[i][j]
t[i+1][j]= 1- t[i+1][j]
t[i+1][j-1]=1 - t[i+1][j-1]
saare.append([i,j,i+1,j,i+1,j-1])
ls2 =a-2
ls = a-1
for k in range(b-2):
if t[ls2][k]==t[ls][k]==0:
continue
elif t[ls2][k]==t[ls][k]==1 :
if t[ls2][k+1]:
saare.append([ls,k,ls2,k,ls2,k+1])
t[ls2][k]=1-t[ls2][k]
t[ls][k]=1-t[ls][k]
t[ls2][k+1]=1-t[ls2][k+1]
else:
saare.append([ls2,k,ls,k,ls,k+1])
t[ls2][k]=1-t[ls2][k]
t[ls][k]=1-t[ls][k]
t[ls][k+1]=1-t[ls][k+1]
elif t[ls2][k]==1:
saare.append([ls2,k,ls2,k+1,ls,k+1])
t[ls2][k]=1-t[ls2][k]
t[ls2][k+1]=1-t[ls2][k+1]
t[ls][k+1]=1-t[ls][k+1]
else:
saare.append([ls,k,ls,k+1,ls2,k+1])
t[ls][k]=1-t[ls][k]
t[ls][k+1]=1-t[ls][k+1]
t[ls2][k+1]=1-t[ls2][k+1]
st = str(t[ls2][b-2]) + str(t[ls2][b-1])+str(t[ls][b-2]) + str(t[ls][b-1])
if st =="0000":
pass
elif st =="0001":
saare.append([ls,b-2,ls,b-1,ls2,b-1])
saare.append([ls,b-1,ls2,b-1,ls2,b-2])
saare.append([ls,b-1,ls,b-2,ls2,b-2])
elif st =="0010":
saare.append([ls2,b-2,ls,b-2,ls,b-1])
saare.append([ls,b-2,ls,b-1,ls2,b-1])
saare.append([ls,b-2,ls2,b-2,ls2,b-1])
elif st =="0100":
saare.append([ls2,b-2,ls2,b-1,ls,b-1])
saare.append([ls2,b-1,ls,b-1,ls,b-2])
saare.append([ls2,b-1,ls2,b-2,ls,b-2])
elif st =="1000":
saare.append([ls2,b-1,ls2,b-2,ls,b-2])
saare.append([ls2,b-2,ls,b-2,ls,b-1])
saare.append([ls2,b-2,ls2,b-1,ls,b-1])
elif st=="0011":
saare.append([ls,b-2,ls,b-1,ls2,b-1])
saare.append([ls2,b-2,ls2,b-1,ls,b-1])
saare.append([ls2,b-1,ls,b-1,ls,b-2])
saare.append([ls2,b-1,ls2,b-2,ls,b-2])
elif st=="0101":
saare.append([ls2,b-1,ls,b-1,ls,b-2])
saare.append([ls2,b-2,ls,b-2,ls,b-1])
saare.append([ls,b-2,ls,b-1,ls2,b-1])
saare.append([ls,b-2,ls2,b-2,ls2,b-1])
elif st =="0110":
saare.append([ls2,b-1,ls,b-1,ls,b-2])
saare.append([ls,b-2,ls,b-1,ls2,b-1])
saare.append([ls,b-1,ls2,b-1,ls2,b-2])
saare.append([ls,b-1,ls,b-2,ls2,b-2])
elif st=="0111":
saare.append([ls2,b-1,ls,b-1,ls,b-2])
elif st=="1001":
saare.append([ls2,b-2,ls,b-2,ls,b-1])
saare.append([ls2,b-2,ls,b-2,ls,b-1])
saare.append([ls,b-2,ls,b-1,ls2,b-1])
saare.append([ls,b-2,ls2,b-2,ls2,b-1])
elif st=="1010":
saare.append([ls2,b-2,ls,b-2,ls,b-1])
saare.append([ls,b-2,ls,b-1,ls2,b-1])
saare.append([ls,b-1,ls2,b-1,ls2,b-2])
saare.append([ls,b-1,ls,b-2,ls2,b-2])
elif st =="1011":
saare.append([ls2,b-2,ls,b-2,ls,b-1])
elif st=="1100":
saare.append([ls2,b-2,ls2,b-1,ls,b-1])
saare.append([ls,b-2,ls,b-1,ls2,b-1])
saare.append([ls,b-1,ls2,b-1,ls2,b-2])
saare.append([ls,b-1,ls,b-2,ls2,b-2])
elif st=="1101":
saare.append([ls2,b-2,ls2,b-1,ls,b-1])
elif st =="1110":
saare.append([ls,b-2,ls2,b-2,ls2,b-1])
elif st=="1111":
saare.append([ls,b-2,ls2,b-2,ls2,b-1])
saare.append([ls,b-2,ls,b-1,ls2,b-1])
saare.append([ls,b-1,ls2,b-1,ls2,b-2])
saare.append([ls,b-1,ls,b-2,ls2,b-2])
print(len(saare))
for i in saare:
print(*list(map(lambda x: x+1,i))) | 7 | PYTHON3 |
t=int(input())
i=0
while i<t:
n=int(input())
arr=list(map(int,input().split()))
if arr[0]<arr[-1]:
print("YES")
else:
print("NO")
i=i+1
| 9 | PYTHON3 |
H,W=map(int,input().split())
A=["#"*(W+2)]+["#"+input()+"#" for i in range(H)]+["#"*(W+2)]
for a in A:
print(*a,sep="") | 0 | PYTHON3 |
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define MOD 998244353
#define M 1000000
vector<ll> fact;
bool h=false;
void init(){
h=true;
fact=vector<ll>(M);
fact[0]=fact[1]=1;
loop(i,2,M)fact[i]=fact[i-1]*i%MOD;
}
// a^b mod MOD
ll powmod(ll a,ll b,ll m=MOD){
ll out=1;
ll p=a%m;
while(b){
if(b&1)out=out*p%m;
p=p*p%m;
b>>=1;
}
return out;
}
//nCr
ll nCr(ll n,ll r,ll m=MOD){
if(!h)init();
if(n<0||r<0||n<r)return 1;//??????
ll out=fact[n]*powmod(fact[r]*fact[n-r]%m,m-2,m)%m;
return out;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
int n,m;
cin>>n>>m;
vvi dp(600,vi(600));
dp[0][0]=1;
loop(x,1,m+1)for(int i=n-1;i>=0;i--)rep(j,512)if(dp[i][j]){
(dp[i+1][j^x]+=dp[i][j])%=MOD;
}
int out=0;
rep(i,n+1)if(dp[i][m]){
int a=(n-i)/2,b=dp[i][m];
(out+=b*nCr(a+m,a)%MOD)%=MOD;
}
cout<<out<<endl;
}
| 0 | CPP |
from sys import stdin, stdout
rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()
def main():
T = int(rl())
for _ in range(T):
ans = []
rows, cols = (int(x) for x in rll())
str_ans = ""
if rows > 1 and cols > 1:
for r in range(rows-1):
row = ["B" for _ in range(cols)]
ans.append("".join(row))
last = ["B" for _ in range(cols-1)]
last.append("W")
ans.append("".join(last))
str_ans = "\n".join(ans)
elif rows == 1:
row = ["B" for _ in range(cols-2)]
row.append("W")
row.append("B")
str_ans = "".join(row)
elif cols == 1:
col = ["B" for _ in range(rows-2)]
col.append("W")
col.append("B")
str_ans = "\n".join(row)
stdout.write(str_ans);stdout.write("\n")
stdout.close()
if __name__ == "__main__":
main() | 7 | PYTHON3 |
#include <bits/stdc++.h>
const int N = 260, mo = 777777777,
F[2][N] = {
{642497124, 482164403, 768209115, 462063756, 154906374, 36099042,
341766705, 678182556, 621882744, 478771358, 231881111, 175889805,
243630450, 168908523, 671961765, 55761813, 652682670, 773939082,
517628076, 756201264, 124604900, 750976272, 498253248, 676047609,
137170026, 705610017, 495032139, 561797418, 703097347, 500815609,
95984586, 739707108, 265613565, 387099846, 777331779, 594676173,
591219559, 407997044, 208947235, 93337440, 478908360, 685013007,
487033953, 671903001, 39521181, 738490312, 33785059, 465470131,
310453920, 54648783, 346831137, 427694175, 474743430, 705296781,
435828036, 429824745, 663532359, 261388683, 244690731, 533997135,
596108961, 506813013, 371892402, 590145264, 104733162, 143420103,
654339672, 700348950, 685038942, 578826927, 286484229, 501639192,
434962491, 299270097, 27702486, 335375775, 111746817, 565603164,
294926121, 676063665, 735862995, 710035809, 437011960, 668528077,
138765186, 508213986, 615036450, 353784942, 624827616, 343900011,
241289776, 52410890, 72018835, 352406796, 415705878, 4802637,
376367145, 65589678, 333633477, 341834527, 303717460, 282387700,
42951006, 254706039, 423048528, 526429710, 68131467, 669954708,
12787348, 500636381, 317959019, 479433192, 657133515, 416259390,
610216692, 340129188, 44594256, 257373347, 138718678, 530767740,
292922628, 37220268, 605295159, 480722613, 458170419, 30540300,
487159055, 232966794, 149150650},
{0, 412133651, 386543325, 139952108, 289303402, 102404925,
317067177, 396414708, 80515854, 663739304, 317300809, 228877044,
493725043, 715317967, 490300965, 315527373, 743539734, 488329191,
553627998, 533025234, 242583957, 706116537, 614109258, 645447222,
523195911, 492109128, 722623041, 111085128, 766395126, 654378921,
691964847, 496688157, 399056049, 654363234, 102052314, 191720088,
473910948, 259736526, 332840025, 388047555, 665791056, 627111387,
139696515, 441456687, 443032569, 283264821, 771641703, 452641455,
511306362, 117572859, 127701891, 721298331, 176520078, 357242229,
611296308, 696994956, 405628839, 429224274, 465336054, 695091546,
689828796, 574648641, 351220905, 507964023, 675326610, 517248963,
453528621, 220301928, 494463186, 681789969, 339589656, 44524053,
417125457, 339589404, 747135963, 341780733, 734158215, 396817281,
21997836, 5728464, 147611205, 456248898, 714128667, 377654949,
3862068, 128418948, 589390074, 304947090, 11703825, 228266073,
127304142, 429215724, 361541124, 521572968, 468358191, 341231688,
65323503, 613778508, 15985323, 291661029, 410970006, 591638112,
349541550, 89967528, 224922159, 361094166, 584206074, 640051812,
324264456, 652625388, 693768537, 11740617, 309238398, 211085469,
194905872, 639416484, 110110707, 296645895, 748118511, 131177718,
511142751, 775975599, 421403409, 475528473, 434685258, 1768977,
80301375, 708023862, 569195676, 56238084, 632887668, 88089750,
631539342, 396695565, 38780154, 695798271, 469819224, 439587099,
69045921, 682966116, 112310856, 64943298, 534475872, 40215357,
389728458, 286368453, 736006257, 501181650, 54829908, 603489402,
338032656, 512182818, 627500097, 462674016, 3103092, 157324491,
43978329, 596818971, 259025598, 9088632, 91991781, 577291428,
211245489, 429471231, 142626330, 172560633, 510907446, 444609585,
758102058, 375112647, 744786693, 276174402, 19259856, 233672418,
745389414, 225772848, 23385663, 324290610, 519804558, 120337812,
402578568, 360676008, 450089262, 551043738, 337388940, 512108856,
28879011, 690040638, 106017282, 558262341, 99972432, 608226003,
612152037, 42414435, 776201013, 39580443, 518796945, 494437752,
583194366, 723936555, 415359657, 309569589, 751104774, 166684527,
249229170, 353120823, 130668327, 753823584, 580966092, 561963717,
543672234, 393846327, 586278000, 327398400, 278403867, 156455586,
363920382, 190245195, 290039148, 547014447, 466218648, 146037150,
585462906, 666008595, 691786683, 374707494, 622498779, 231158277,
685740951, 115612245, 681825249, 545555745, 551718468, 277206615,
640171035, 757727334, 195193908, 658656684, 457760646, 225925875,
505761984, 18685233, 506832921, 112511021, 396846646, 290147622,
113924623, 669986155, 336008070, 63611061, 238586775, 119956662,
616557739, 772784623, 334527774, 410403148, 51933421}};
int n, k, f[N][N][N], C[N][N];
int main() {
scanf("%d%d", &n, &k);
if (n >= 128) return printf("%d\n", F[n == 256][k]), 0;
for (int i = 0; i <= n; i++)
for (int j = 0; j <= i; j++)
C[i][j] = j ? (C[i - 1][j] + C[i - 1][j - 1]) % mo : 1;
f[0][0][0] = 1;
for (int i = 1; i <= n; i++)
for (int j = 0; j <= n; j++)
for (int k = 0; k <= j; k++) {
int now = 0;
for (int l = 0; l <= j; l++)
if (l == i)
now = (now + 1LL * f[i - 1][j - l][k] * C[j][l]) % mo;
else if (l <= k)
now = (now + 1LL * f[i - 1][j - l][k - l] * C[j][l]) % mo;
f[i][j][k] = now;
}
printf("%d\n", f[n][n][k]);
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
int digit(int64_t x){
int ret = 0;
for(;x>0;ret++) x /= 10;
return ret;
}
void matpow(const int64_t *X, int64_t *ans, int64_t n, int64_t mod){
if(n==0){
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
ans[i*3+j] = (i==j ? 1 : 0);
}
}
}else if(n==1){
for(int i=0;i<9;i++) ans[i] = X[i] % mod;
}else if(n%2 == 0){
int64_t XX[9];
for(int i=0;i<3;i++){
for(int k=0;k<3;k++){
XX[i*3+k] = 0;
for(int j=0;j<3;j++){
XX[i*3+k] = (XX[i*3+k] + X[i*3+j] * X[j*3+k] % mod) % mod;
}
}
}
matpow(XX, ans, n/2, mod);
}else{
int64_t XX[9];
for(int i=0;i<3;i++){
for(int k=0;k<3;k++){
XX[i*3+k] = 0;
for(int j=0;j<3;j++){
XX[i*3+k] = (XX[i*3+k] + X[i*3+j] * X[j*3+k] % mod) % mod;
}
}
}
matpow(XX, ans, n/2, mod);
for(int i=0;i<9;i++){
XX[i] = ans[i];
ans[i] = 0;
}
for(int i=0;i<3;i++){
for(int k=0;k<3;k++){
for(int j=0;j<3;j++){
ans[i*3+k] = (ans[i*3+k] + XX[i*3+j] * X[j*3+k] % mod) % mod;
}
}
}
}
}
int main(){
int64_t L, A, B, M;
cin >> L >> A >> B >> M;
pair<int64_t,int64_t> pos[19];
for(int i=1;i<=18;i++){
int64_t l = -1, r = L;
while(r-l > 1){
int64_t m = (l+r) / 2;
if(digit(A + m*B) < i) l = m;
else r = m;
}
pos[i].first = r;
l = -1; r = L;
while(r-l > 1){
int64_t m = (l+r) / 2;
if(digit(A + m*B) <= i) l = m;
else r = m;
}
pos[i].second = r;
}
A %= M; B %= M;
int64_t s = 0, n = A, d = 1;
for(int i=1;i<=18;i++){
d *= 10;
int64_t X[9] = {0}, Xp[9];
X[0] = d % M;
X[1] = X[4] = X[5] = X[8] = 1;
matpow(X, Xp, pos[i].second - pos[i].first, M);
s = (Xp[0]*s%M + Xp[1]*n%M + Xp[2]*B%M) % M;
n = (Xp[3]*s%M + Xp[4]*n%M + Xp[5]*B%M) % M;
}
cout << s << endl;
return 0;
} | 0 | CPP |
n = int(input())
arr = list(map(int, input().split(' ')))
for x in arr:
if x % 2 == 0:
# replace x with x-1
for i in range(len(arr)):
if arr[i] == x:
arr[i] = x - 1
print(" ".join(map(str, arr)))
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T GCD(T a, T b) {
a = abs(a);
b = abs(b);
while (b) {
a = a % b;
swap(a, b);
}
return a;
}
template <typename T>
inline T LCM(T x, T y) {
T tp = GCD(x, y);
if ((x / tp) * 1. * y > 9e18) return 9e18;
return (x / tp) * y;
}
template <typename T>
inline T BigMod(T A, T B, T M) {
T ret = 1;
while (B) {
if (B & 1) ret = (ret * A) % M;
A = (A * A) % M;
B = B >> 1;
}
return ret;
}
template <typename T>
inline T InvMod(T A, T M) {
return BigMod(A, M - 2, M);
}
long long gcdr(long long a, long long b) {
if (a == 0) return b;
return gcdr(b % a, a);
}
long long max(long long a, long long b) {
if (a > b) return a;
return b;
}
long long min(long long a, long long b) {
if (a < b) return a;
return b;
}
void FastIO() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.precision(20);
}
const long long size3 = 300005;
const long long size2 = 200005;
const long long size1 = 100005;
int main() {
long long t, i, j, m, x, y, n;
t = 1;
while (t--) {
scanf("%lld", &n);
long long ans = 0LL;
vector<long long> V;
for (i = 0; i < n; i++) {
scanf("%lld", &x);
V.push_back(x);
}
long long current = 1LL;
for (i = 0; i < n; i++) {
if (V[i] > 0) {
ans += (V[i] - 1LL);
V[i] = 1LL;
current = current * V[i];
} else if (V[i] < 0) {
ans += (-1LL * (V[i] + 1LL));
V[i] = -1LL;
current = current * V[i];
}
}
for (i = 0; i < n; i++) {
if (V[i] == 0 && current == -1) {
current = 1;
ans++;
} else if (V[i] == 0 && current == 1) {
ans++;
}
}
if (current == -1) {
ans += 2;
}
printf("%lld", ans);
printf("\n");
}
return 0;
}
| 8 | CPP |
mod = 10**9 + 7
N = int(input())
T = list(map(int, input().split()))
A = list(map(int, input().split()))
Min = [1] * N
Max = [float("inf")] * N
tp = 0
for i, t in enumerate(T):
if t != tp:
Min[i] = max(Min[i], t)
Max[i] = min(Max[i], t)
tp = t
ap = 0
for i, a in zip(range(N-1, -1, -1), A[::-1]):
if a != ap:
Min[i] = max(Min[i], a)
Max[i] = min(Max[i], a)
ap = a
ans = 1
for mi, ma in zip(Min, Max):
ans = ans * max(ma-mi+1, 0) % mod
print(ans)
| 0 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 100001;
vector<long long int> v;
long long int ar[N];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long int n, m, k;
cin >> n >> m;
multiset<long long int> st;
for (int i = 0; i < n; i++) cin >> ar[i];
sort(ar, ar + n);
long long int ans2 = ar[n - 1] + m;
for (int i = 0; i < n; i++) st.insert(ar[i]);
while (m > 0) {
auto it = st.begin();
st.insert(*it + 1);
st.erase(it);
m--;
}
auto it = st.end();
it--;
cout << *it << " " << ans2 << endl;
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const double EPS = 1e-9;
const int R = 100001;
int n, m;
string name[100015];
vector<int> e[100015];
int in[100015], out[100015], dfs_order[100015], cnt_dfs_order, dep[100015];
int siz[100015], son[100015];
set<string> cnt[100015];
void dfs1(int u) {
dfs_order[++cnt_dfs_order] = u;
in[u] = cnt_dfs_order;
siz[u] = 1;
for (auto v : e[u]) {
dep[v] = dep[u] + 1;
dfs1(v);
if (siz[son[u]] < siz[v]) {
son[u] = v;
}
siz[u] += siz[v];
}
out[u] = cnt_dfs_order;
}
int askv[100015], askp[100015];
map<int, int> ask[100015];
int big[100015];
void add(int u, int x) {
if (1 == x)
cnt[dep[u]].insert(name[u]);
else
cnt[dep[u]].erase(name[u]);
for (auto v : e[u]) {
if (!big[v]) {
add(v, x);
}
}
}
void dfs2(int u, int keep) {
for (auto v : e[u]) {
if (v == son[u]) continue;
dfs2(v, 0);
}
if (son[u]) {
dfs2(son[u], 1);
big[son[u]] = 1;
}
add(u, 1);
for (auto &p : ask[u]) {
int d = dep[u] + p.first;
if (d >= R) d = R + 1;
p.second = cnt[d].size();
}
big[son[u]] = 0;
if (0 == keep) {
add(u, 0);
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> name[i];
int p;
cin >> p;
if (p == 0) p = R;
e[p].push_back(i);
}
dfs1(R);
cin >> m;
for (int i = 1; i <= m; ++i) {
cin >> askv[i] >> askp[i];
ask[askv[i]][askp[i]];
}
dfs2(R, 1);
for (int i = 1; i <= m; ++i) {
printf("%d\n", ask[askv[i]][askp[i]]);
}
return 0;
}
| 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
template <class C>
constexpr int sz(const C &c) {
return int(c.size());
}
using ll = long long;
using ld = long double;
constexpr const char nl = '\n', sp = ' ';
using T = double;
constexpr const T EPS = 1e-9;
bool lt(T a, T b) { return a + EPS < b; }
bool le(T a, T b) { return !lt(b, a); }
bool gt(T a, T b) { return lt(b, a); }
bool ge(T a, T b) { return !lt(a, b); }
bool eq(T a, T b) { return !lt(a, b) && !lt(b, a); }
bool ne(T a, T b) { return lt(a, b) || lt(b, a); }
int sgn(T a) { return lt(a, 0) ? -1 : lt(0, a) ? 1 : 0; }
template <class F>
struct Functor {
F f;
Functor(F f) : f(f) {}
template <class U>
bool operator()(const U &a, const U &b) const {
return f(a, b);
}
};
template <class F>
Functor<F> makeFunctor(F f) {
return Functor<F>(f);
}
using pt = complex<T>;
istream &operator>>(istream &stream, pt &p) {
T X, Y;
stream >> X >> Y;
p = pt(X, Y);
return stream;
}
ostream &operator<<(ostream &stream, const pt &p) {
return stream << p.real() << ' ' << p.imag();
}
bool operator<(const pt &a, const pt &b) {
return eq(a.real(), b.real()) ? lt(a.imag(), b.imag())
: lt(a.real(), b.real());
}
bool operator<=(const pt &a, const pt &b) { return !(b < a); }
bool operator>(const pt &a, const pt &b) { return b < a; }
bool operator>=(const pt &a, const pt &b) { return !(a < b); }
bool operator==(const pt &a, const pt &b) { return !(a < b) && !(b < a); }
bool operator!=(const pt &a, const pt &b) { return a < b || b < a; }
struct pt_lt {
bool operator()(const pt &a, const pt &b) const { return a < b; }
};
struct pt_le {
bool operator()(const pt &a, const pt &b) const { return a <= b; }
};
struct pt_gt {
bool operator()(const pt &a, const pt &b) const { return a > b; }
};
struct pt_ge {
bool operator()(const pt &a, const pt &b) const { return a >= b; }
};
struct pt_eq {
bool operator()(const pt &a, const pt &b) const { return a == b; }
};
struct pt_ne {
bool operator()(const pt &a, const pt &b) const { return a != b; }
};
T dot(const pt &a, const pt &b) {
return a.real() * b.real() + a.imag() * b.imag();
}
T cross(const pt &a, const pt &b) {
return a.real() * b.imag() - a.imag() * b.real();
}
T norm(const pt &a) { return dot(a, a); }
T distSq(const pt &a, const pt &b) { return norm(b - a); }
T dist(const pt &a, const pt &b) { return abs(b - a); }
T ang(const pt &a, const pt &b) { return arg(b - a); }
T ang(const pt &a, const pt &b, const pt &c) {
return remainder(ang(b, a) - ang(b, c), 2 * acos(T(-1)));
}
T area2(const pt &a, const pt &b, const pt &c) { return cross(b - a, c - a); }
int ccw(const pt &a, const pt &b, const pt &c) { return sgn(area2(a, b, c)); }
pt rot(const pt &a, const pt &p, const T &theta) {
return (a - p) * pt(polar(T(1), theta)) + p;
}
pt perp(const pt &a) { return pt(-a.imag(), a.real()); }
template <class It>
It sortByAng(It st, It en, const pt &pivot) {
en = partition(st, en, [&](const pt &p) { return p != pivot; });
It mid = partition(st, en, [&](const pt &p) {
return eq(p.imag(), pivot.imag()) ? lt(p.real(), pivot.real())
: lt(p.imag(), pivot.imag());
});
auto cmp = [&](const pt &p, const pt &q) { return 0 < ccw(pivot, p, q); };
sort(st, mid, cmp);
sort(mid, en, cmp);
return en;
}
struct Line {
pt v;
T c;
Line(T a = 0, T b = 0, T c = 0) : v(b, -a), c(c) {}
Line(const pt &v, T c) : v(v), c(c) {}
Line(const pt &p, const pt &q) : v(q - p), c(cross(v, p)) {}
T eval(const pt &p) const { return cross(v, p) - c; }
int onLeft(const pt &p) const { return sgn(eval(p)); }
T distSq(const pt &p) const {
T e = eval(p);
return e * e / norm(v);
}
T dist(const pt &p) const { return abs(eval(p) / abs(v)); }
Line perpThrough(const pt &p) const { return Line(p, p + perp(v)); }
Line translate(const pt &p) const { return Line(v, c + cross(v, p)); }
Line shiftLeft(T d) const { return Line(v, c + d * abs(v)); }
pt proj(const pt &p) const { return p - perp(v) * eval(p) / norm(v); }
pt refl(const pt &p) const { return p - perp(v) * T(2) * eval(p) / norm(v); }
};
int lineIntersection(const Line &l1, const Line &l2, pt &res) {
T d = cross(l1.v, l2.v);
if (eq(d, 0)) return l2.v * l1.c == l1.v * l2.c ? 2 : 0;
res = (l2.v * l1.c - l1.v * l2.c) / d;
return 1;
}
using Polygon = vector<pt>;
int mod(int i, int n) { return i < n ? i : i - n; }
int extremeVertex(const Polygon &poly, const pt &dir) {
int n = poly.size(), lo = 0, hi = n;
pt pp = perp(dir);
auto cmp = [&](int i, int j) {
return sgn(cross(pp, poly[mod(i, n)] - poly[mod(j, n)]));
};
auto extr = [&](int i) {
return cmp(i + 1, i) >= 0 && cmp(i, i + n - 1) < 0;
};
if (extr(0)) return 0;
while (lo + 1 < hi) {
int m = lo + (hi - lo) / 2;
if (extr(m)) return m;
int ls = cmp(lo + 1, lo), ms = cmp(m + 1, m);
(ls < ms || (ls == ms && ls == cmp(lo, m)) ? hi : lo) = m;
}
return lo;
}
pair<int, int> convexPolygonLineIntersection(const Polygon &poly,
const Line &line) {
int n = poly.size(), endA = extremeVertex(poly, -perp(line.v));
int endB = extremeVertex(poly, perp(line.v));
auto cmpL = [&](int i) { return line.onLeft(poly[i]); };
pair<int, int> ret(-1, -1);
if (cmpL(endA) > 0 || cmpL(endB) < 0) return ret;
for (int i = 0; i < 2; i++) {
int lo = endB, hi = endA;
while (mod(lo + 1, n) != hi) {
int m = mod((lo + hi + (lo < hi ? 0 : n)) / 2, n);
(cmpL(m) == cmpL(endB) ? lo : hi) = m;
}
(i ? ret.second : ret.first) = mod(lo + !cmpL(hi), n);
swap(endA, endB);
}
if (ret.first == ret.second) return make_pair(ret.first, -1);
if (!cmpL(ret.first) && !cmpL(ret.second)) {
switch ((ret.first - ret.second + n + 1) % n) {
case 0:
return make_pair(ret.first, ret.first);
case 2:
return make_pair(ret.second, ret.second);
}
}
return ret;
}
const pt O(0, 0);
const T PI = acos(T(-1));
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int N, Q;
cin >> N >> Q;
vector<T> A(N * 4);
Polygon poly(N);
for (auto &&p : poly) cin >> p;
reverse(poly.begin(), poly.end());
auto getA = [&](int i) { return i < 0 ? T(0) : A[i]; };
auto area2 = [&](int l, int r) {
if (l > r) r += N;
if (l == r) return T(0);
return getA(r - 1) - getA(l - 1);
};
auto getInd = [&](int i) { return i % N; };
auto getPt = [&](int i) { return poly[getInd(i)]; };
auto f = [&](pt p, T ang) {
pt q = p + polar(T(10), ang);
Line line(p, q);
int i, j;
tie(i, j) = convexPolygonLineIntersection(poly, line);
pt a, b;
lineIntersection(Line(getPt(i), getPt(i + 1)), line, a);
lineIntersection(Line(getPt(j), getPt(j + 1)), line, b);
T a1 = area2(i + 1, j) + cross(getPt(j), b) + cross(b, a) +
cross(a, getPt(i + 1));
T a2 = area2(j + 1, i) + cross(getPt(i), a) + cross(a, b) +
cross(b, getPt(j + 1));
return a1 - a2;
};
for (int i = 0; i < N * 4; i++) A[i] = cross(getPt(i), getPt(i + 1));
partial_sum(A.begin(), A.end(), A.begin());
for (int i = 0; i < Q; i++) {
pt p;
cin >> p;
T lo = 0, hi = PI;
bool s = lt(f(p, lo), f(p, hi));
for (int it = 0; it < 40; it++) {
T mid = lo + (hi - lo) / 2;
if (ge(f(p, mid), 0) == s)
hi = mid;
else
lo = mid;
}
if (eq(lo, PI)) lo = 0;
cout << fixed << setprecision(12) << lo << nl;
}
return 0;
}
| 13 | CPP |
#include <bits/stdc++.h>
int main() {
int n, m, i;
scanf("%d%d", &n, &m);
if (n < m)
printf("-1\n");
else if (m == 1) {
if (n == 1)
printf("a");
else
printf("-1");
printf("\n");
} else {
for (i = 1; i < n + 3 - m; i++) {
if (i % 2 == 1)
printf("a");
else
printf("b");
}
for (i = 2; i < m; i++) printf("%c", 'a' + i);
printf("\n");
}
}
| 9 | CPP |
import sys
input = sys.stdin.readline
t=int(input())
for _ in range(0,t):
n,k=list(map(int,input().split()))
a=list(map(int,input().split()))
f=0
for i in range(0,n):
if(a[i]==k):
f=1
break
if(f==0):
print("no")
continue
if(n==1):
print("yes")
continue
f=0
for i in range(0,n):
if(i==0):
if(a[i]>=k and a[i+1]>=k):
f=1
elif(i==n-1):
if(a[i]>=k and a[i-1]>=k):
f=1
elif(a[i]>=k):
if(a[i-1]>=k or a[i+1]>=k):
f=1
elif(a[i]<=k):
if(a[i+1]>=k and a[i-1]>=k):
f=1
if(f):
print("yes")
else:
print("no") | 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e4 + 5;
int a[maxn];
int main() {
int T;
scanf("%d", &T);
while (T--) {
int n;
scanf("%d", &n);
int sum = 0;
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
sum += a[i];
}
if (sum % n) {
puts("-1");
continue;
}
int k = sum / n;
printf("%d\n", 3 * n - 3);
for (int i = 2; i <= n; i++) {
if (a[i] % i == 0)
printf("1 %d 0\n", i);
else
printf("1 %d %d\n", i, i - a[i] % i);
printf("%d 1 %d\n", i, (a[i] + i - 1) / i);
}
for (int i = 2; i <= n; i++) printf("1 %d %d\n", i, k);
}
return 0;
}
| 8 | CPP |
from math import log,floor
n = int(input())
l = int(input())
ans = round(log(l,n),14)
f_ans = floor(ans)
if ans==f_ans:
print("YES")
print(int(ans-1))
else:
print("NO")
| 7 | PYTHON3 |
#include<bits/stdc++.h>
#define int long long
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;
int data[400000],datb[400000];
void add(int a,int b,int x,int k,int l,int r){
if(a<=l&&r<=b)data[k]+=x;
else if(l<b&&a<r){
datb[k]+=(min(b,r)-max(a,l))*x;
add(a,b,x,k*2+1,l,(l+r)/2);
add(a,b,x,k*2+2,(l+r)/2,r);
}
}
int sum(int a,int b,int k,int l,int r){
if(b<=l||r<=a)return 0;
else if(a<=l&&r<=b)return data[k]*(r-l)+datb[k];
else{
int res=(min(b,r)-max(a,l))*data[k];
res+=sum(a,b,k*2+1,l,(l+r)/2);
res+=sum(a,b,k*2+2,(l+r)/2,r);
return res;
}
}
signed main() {
int n,q;scanf("%lld%lld",&n,&q);
rep(i,q){
int k;scanf("%lld",&k);
if(k==0){
int s,t,x;scanf("%lld%lld%lld",&s,&t,&x);s--;
add(s,t,x,0,0,n);
}
else{
int s,t;scanf("%lld%lld",&s,&t);s--;
printf("%lld\n",sum(s,t,0,0,n));
}
}
} | 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int h, w, n;
cin >> h >> w >> n;
int a = max(h, w);
cout << (n+a-1)/a << endl;
} | 0 | CPP |
msg=input()
nwp=input()
aa=[0 for i in range(26)]
bb=[0 for i in range(26)]
cc=[0 for i in range(26)]
dd=[0 for i in range(26)]
for i in msg:
if(ord(i)<95):
bb[ord(i)-65]+=1
else:
aa[ord(i)-97]+=1
for i in nwp:
if(ord(i)<95):
dd[ord(i)-65]+=1
else:
cc[ord(i)-97]+=1
daba,store=0,0
vr,rb=0,0
for i in range(26):
vr=min(aa[i],cc[i])
rb=min(bb[i],dd[i])
daba+=vr
daba+=rb
store+=min(aa[i]+bb[i]-vr-rb,cc[i]+dd[i]-vr-rb)
print(daba,store) | 8 | PYTHON3 |
#include <iostream>
#include <string>
#include <algorithm>
#include <cctype>
#include <cstdlib>
using namespace std;
string S,T;
int main(){
cin >> S;
int count = 0;
while(cin >> T && T != "END_OF_TEXT"){
for(int i=0;i<T.size();i++){
T[i] = tolower(T[i]);
}
if(T == S) count++;
}
cout << count << endl;
}
| 0 | CPP |
k,r=map(int,input().split())
i=1
while 1:
a=k*i
a=str(a)
r=str(r)
if a[-1] == r or a[-1] == "0":
break
i+=1
print(i) | 7 | PYTHON3 |
n = int(input())
c = 0
for _ in range(n):
s = [int(x) for x in input().split()]
sums = sum(s)
if sums > 1:
c += 1
print(c) | 7 | PYTHON3 |
#include <bits/stdc++.h>
int main() {
char a[120][120];
int x = 0, y = 0, p = 0, q = 0;
int i, j, n, m;
scanf("%d %d", &m, &n);
for (i = 1; i <= m; i++) {
for (j = 1; j <= n; j++) {
scanf(" %c", &a[i][j]);
}
}
for (i = 1; i <= m; i++) {
for (j = 1; j <= n; j++) {
if (a[i][j] == 'B') {
x = i;
y = j;
}
}
}
for (i = m; i >= 1; i--) {
for (j = n; j >= 1; j--) {
if (a[i][j] == 'B') {
p = i;
q = j;
}
}
}
printf("%d %d", ((p + x) / 2), ((q + y) / 2));
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
const long long UNDEF = -1;
const long long INF = 2e9;
template <typename T>
inline bool chkmax(T& aa, T bb) {
return aa < bb ? aa = bb, true : false;
}
template <typename T>
inline bool chkmin(T& aa, T bb) {
return aa > bb ? aa = bb, true : false;
}
template <class T>
T extgcd(T a, T b, T& x, T& y) {
for (T u = y = 1, v = x = 0; a;) {
T q = b / a;
swap(x -= q * u, u);
swap(y -= q * v, v);
swap(b -= q * a, a);
}
return b;
}
template <class T>
T mod_inv(T a, T m) {
T x, y;
extgcd(a, m, x, y);
return (m + x % m) % m;
}
bool btw(long long a, long long b, long long c) {
return (a <= b && b <= c) || (a >= b && b >= c);
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
long long n;
string s;
cin >> n >> s;
long long px = 0, py = 0;
long long cx = 0, cy = 0;
long long ans = 0;
vector<pair<long long, long long> > st;
for (long long i = 0; i < n; i++) {
char c = s[i];
long long dx = 0, dy = 0;
if (c == 'U') dy = 1;
if (c == 'D') dy = -1;
if (c == 'L') dx = -1;
if (c == 'R') dx = 1;
long long ocx = cx, ocy = cy;
cx += dx;
cy += dy;
if (btw(px, ocx, cx) && btw(py, ocy, cy)) {
} else {
px = ocx;
py = ocy;
st.push_back(make_pair(px, py));
ans++;
}
}
if (cx != px || cy != py) st.push_back(make_pair(cx, cy));
printf("%lld\n", (long long)st.size());
}
| 9 | CPP |
#include <bits/stdc++.h>
using namespace std;
bool t[15000000];
bool used[15000000];
int p[15000000];
int get(int x) {
if (p[x] == -1) return x;
return (p[x] = get(p[x]));
}
void unite(int i1, int j1) {
int i = get(i1);
int j = get(j1);
if (i != j) {
if (i > j)
p[i] = j;
else
p[j] = i;
}
}
void add_edge(int k1, int k2) {
if (t[k1] && t[k2]) {
if (k1 < 10000010 && k2 < 10000010) unite(k1, k2);
}
}
int n;
int gcd(int a, int b) {
if (a == 0) return b;
if (b == 0) return a;
return gcd(b, a % b);
}
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
int w = 0;
scanf("%d", &w);
t[w] = 1;
}
for (int i = 0; i < 15000000; i++) p[i] = -1;
for (int i = 1; i * i < 15000000; i++)
for (int j = 1; j <= i && (j * j + i * i < 15000000); j++)
if (gcd(i, j) == 1 && (i + j) % 2 == 1) {
int k1 = i * i - j * j;
int k2 = 2 * i * j;
int k3 = i * i + j * j;
for (int k = 1;
(k * k1) < 15000000 && (k * k2) < 15000000 && (k * k3) < 15000000;
k++) {
add_edge(k1, k2);
add_edge(k2, k3);
add_edge(k3, k1);
}
}
int ans = 0;
for (int i = 0; i < 15000000; i++)
if (p[i] == -1 && t[i]) ans++;
printf("%d\n", ans);
return 0;
}
| 10 | CPP |
def func(rang):
return rang[1]
n=int(input())
l=[]
for i in range(n):
[a,b]=list(map(int,input().split()))
l.append([a,b])
l.sort(key=func)
l.sort()
ma=0
for i in range(len(l)):
if(ma==l[i][0]):
continue
elif(ma>l[i][1]):
ma=l[i][0]
else:
ma=l[i][1]
print(ma) | 7 | PYTHON3 |
string = input().lower()
print(min(len(string), 2*string.count('a')-1))
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const long long mod = 998244353;
const int N = 2e5 + 2;
int main() {
int t;
scanf("%d", &t);
while (t--) {
long long n, l, r;
scanf("%lld", &n);
scanf("%lld", &l);
scanf("%lld", &r);
long long cur = 0, val = 2 * (n - 1), ind = 1;
while (cur + val < l) {
cur += val;
val /= 2;
val--;
val *= 2;
ind++;
if (ind == n) val = 1;
}
long long total = n * (n - 1) + 1;
long long ptr = cur + 1;
long long x = ind, y = x + 1;
vector<pair<long long, long long> > v;
while (ptr <= r) {
if (ptr == total) {
v.push_back({1, ptr});
break;
}
v.push_back({x, ptr});
v.push_back({y, ptr + 1});
ptr += 2;
y++;
if (y > n) {
x++;
y = x + 1;
if (x == n) {
v.push_back({1, ptr});
break;
}
}
}
for (auto i : v)
if (i.second >= l && i.second <= r) printf("%d ", (int)i.first);
printf("\n");
}
return 0;
}
| 10 | CPP |
def is_magic_number(s):
if s[0] != '1':
return False
for x in s:
if x != '1' and x != '4':
return False
if s.find('444') != -1:
return False
return True
s = input()
if is_magic_number(s):
print('YES')
else:
print('NO')
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int mod = 1e8;
int dp[101][101][2];
int findPermute(int n1, int n2, int k1, int k2, int i) {
if (dp[n1][n2][i] == -1) {
dp[n1][n2][i] = 0;
if (i == 0) {
if (n1 == 0) {
if (!n2)
dp[n1][n2][i] = 1;
else
dp[n1][n2][i] = 0;
} else {
for (int j = 1; j <= k1; j++) {
if (n1 >= j)
dp[n1][n2][i] =
(dp[n1][n2][i] + findPermute(n1 - j, n2, k1, k2, 1 - i)) % mod;
}
}
}
if (i == 1) {
if (n2 == 0) {
if (!n1)
dp[n1][n2][i] = 1;
else
dp[n1][n2][i] = 0;
} else {
for (int j = 1; j <= k2; j++) {
if (n2 >= j)
dp[n1][n2][i] =
(dp[n1][n2][i] + findPermute(n1, n2 - j, k1, k2, 1 - i)) % mod;
}
}
}
}
return dp[n1][n2][i];
}
int main() {
int n1, n2, k1, k2;
cin >> n1 >> n2 >> k1 >> k2;
memset(dp, -1, sizeof(dp));
cout << (findPermute(n1, n2, k1, k2, 0) + findPermute(n1, n2, k1, k2, 1)) %
mod;
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int x = 0, f = 1;
char c = getchar();
while (c != '-' && (c < '0' || c > '9')) c = getchar();
if (c == '-') f = -1, c = getchar();
while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
return f * x;
}
const int maxn = 1e4 + 7;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
int n, m;
int a[maxn], d[maxn];
int vis[maxn];
int main() {
n = read(), m = read();
int cnt = 0;
for (int i = 1; i <= n; ++i) {
a[i] = i;
if (i >= 3) cnt += (i - 1) / 2;
}
if (m > cnt) return printf("-1\n"), 0;
cnt = cnt - m;
for (int i = n; i > 2 && cnt; --i) {
if (i & 1) d[i]++, cnt--;
while (cnt && a[i - 1] + a[i - 2] >= a[i] + d[i]) {
d[i] += 2, cnt--;
}
if (a[i - 1] + a[i - 2] < a[i] + d[i]) vis[i] = 1;
}
for (int i = 1; i <= n; ++i) {
a[i] = a[i] + d[i];
if (!vis[i])
printf("%d%c", a[i], " \n"[i == n]);
else
printf("%d%c", int(1e9) - 10000 * (n - i), " \n"[i == n]);
}
}
| 11 | CPP |
def ii(): return int(input())
def fi(): return float(input())
def si(): return input()
def mi(): return map(int,input().split())
def li(): return list(mi())
import math
t=ii()
for i in range(t):
l,r=mi()
print(l,l*2) | 7 | PYTHON3 |
a = list(map(int, input().split()))
a.sort()
if (a[0] == 1 or (a[0] == 2 and a[1] == 2) or (a[0] == 3 and a[1] == 3 and a[2] == 3) or (a[0] == 2 and a[1] == 4 and a[2] == 4)):
print ("YES")
else:
print ("NO") | 9 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int n, a, sum;
bool o[601];
int main() {
cin >> n;
for (int i = 1; i <= n; i++) cin >> a, o[a] = 1;
for (int i = 1; i <= 600; i++) sum += o[i];
cout << sum << endl;
return 0;
}
| 7 | CPP |
n,m=map(int,input().split())
L=[input() for i in range(n)]
k=0
deleted=set()
def chek() :
imun=set()
global deleted
global L
global m
global n
for i in range(m) :
if i not in deleted :
for j in range(1,n) :
if L[j][i]>L[j-1][i] :
imun.add(j)
if L[j][i]<L[j-1][i] and j not in imun :
deleted.add(i)
return True
return False
b=chek()
while(b) :
b=chek()
print(len(deleted))
| 9 | PYTHON3 |
import math
x,y=map(int,input().split())
if y%2==0 or y%3==0:
if y!=2 and y!=3:
print('NO')
else:
print('YES')
else:
x=x+1
for i in range(x,y+2):
c=[t for t in range(1,round(math.sqrt(i))+1) if i%t==0]
if i>y:
exit(print('NO'))
if len(c)==1 and i!=y:
exit(print('NO'))
if len(c)==1 and i==y:
exit(print('YES'))
c=c.clear() | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t;
cin >> t;
while (t--) {
long long n;
cin >> n;
cout << n << endl;
}
return 0;
}
| 7 | CPP |
x=int(input())
s=input()
a=0
for i in range(x):
if i>0 and s[i-1]==s[i]:
a+=1
print(a) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int m, n;
int main() {
int x1, x2, y1, y2;
int x3, x4, y3, y4;
cin >> x1 >> y1 >> x2 >> y2;
if (x1 == x2) {
int d = abs(y1 - y2);
x3 = x1 - d;
y3 = y1;
x4 = x3;
y4 = y2;
}
if (y1 == y2) {
int d = abs(x1 - x2);
x3 = x1;
y3 = y1 + d;
x4 = x2;
y4 = y3;
}
if (x1 != x2 && y1 != y2) {
if (abs(y1 - y2) != abs(x1 - x2)) {
cout << -1;
return 0;
}
x3 = x2;
y3 = y1;
x4 = x1;
y4 = y2;
}
cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
}
| 7 | CPP |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.