solution stringlengths 10 159k | difficulty int64 0 3.5k | language stringclasses 2
values |
|---|---|---|
import sys, bisect
input = sys.stdin.readline
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
printed = False
for i in range(n - 1):
if abs(a[i + 1] - a[i]) > 1:
print('YES')
print(i + 1, i + 2)
printed = True
b... | 1,200 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int n;
int fa[100010];
vector<int> v[100010];
int dep;
int cnt[100010];
void dfs(int x, int d) {
cnt[d]++;
dep = max(d, dep);
for (auto y : v[x]) {
dfs(y, d + 1);
}
}
int main(int argc, char const *argv[]) {
scanf("%d", &n);
for (int i = 2; i <= n; i++) {
... | 1,500 | CPP |
#include <bits/stdc++.h>
#pragma warning(disable : 4996)
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout << fixed << setprecision(15);
string str;
cin >> str;
int l = 0;
for (int i = 1; i < str.length(); ++i) {
if (isupper(str[i])) l++;
}
if (l == str.length... | 1,000 | CPP |
n, m, q = map(int, input().split())
x = [0 for i in range(n+1)]
b = input()
s = input()
for i in range(n-m+1):
f = True
for j in range(i, i+m):
if b[j] != s[j-i]:
f = False
break
if f:
x[i+m] = 1
for i in range(1, n+1):
x[i] = x[i] + x[i-1]
x += [x[-1] for i in ra... | 1,300 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int NUM = 200100;
int main() {
int n;
scanf("%d", &n);
char loc[NUM];
scanf("%s", loc);
unordered_map<int, int> m;
int rooms = (n - 1) * 2;
int ans = 0;
for (int i = 0; i != rooms; i += 2) {
m[loc[i] - 'a']++;
if (m[loc[i + 1] - 'A'] == 0) {
... | 1,100 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
int equ[2 * maxn], cover[2 * maxn], a[maxn];
int main() {
int T;
cin >> T;
while (T--) {
int n, k;
scanf("%d%d", &n, &k);
for (int i = 1; i <= n; i++) scanf("%d", a + i);
fill(equ, equ + 2 * k + 5, 0);
fill(cover, cover +... | 1,700 | CPP |
n = int(input())
def binarySearch(l, b):
length = len(l)
if length == 1:
if l[0] + b > 0:
return 1
return 0
if l[length // 2] + b > 0:
return length - length // 2 + binarySearch(l[:length // 2], b)
elif length //2 + 1 < length:
return binarySearch(l[length//2 + 1 :], b)
return 0
a = list(map(int, ... | 1,400 | PYTHON3 |
n = int(input())
d = {}
for i in map(int, input().split()):
d[i] = d.get(i, 0) + 1
a = list(sorted(d.keys()))
ans = 0
s = set()
for i in sorted(d):
if d[i] == 1:
if i in s:
if i - 1 in s:
s.add(i + 1)
else:
s.add(max(i - 1, 1))
else:
... | 1,500 | PYTHON3 |
n = int(input())
coord = list(map(int,input().split()))
ans = n
for i in coord:
s = 0
for j in coord:
if abs(i-j) % 2 != 0: s += 1
if s < ans: ans = s
print(ans)
| 900 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int k, n, m;
int main() {
cin >> k;
while (k--) {
string s;
cin >> s;
int l = s.size();
bool one = false;
int ans = 0, tmp = 0;
for (int i = 0; i < l; i++) {
if (s[i] == '1' && !one) {
one = true;
} else if (s[i] == '0' && one... | 800 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 1005;
int f1[maxn][15], f2[maxn][15];
int pre[maxn], suf[maxn];
int main() {
int n, m;
scanf("%d%d", &n, &m);
f1[0][0] = 1;
for (int len = 1; len <= m; len++) {
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= i... | 1,600 | CPP |
#include <bits/stdc++.h>
using namespace std;
inline void read(int &x) {
int v = 0, f = 1;
char c = getchar();
while (!isdigit(c) && c != '-') c = getchar();
if (c == '-')
f = -1;
else
v = (c & 15);
while (isdigit(c = getchar())) v = (v << 1) + (v << 3) + (c & 15);
x = v * f;
}
inline void read(lo... | 2,900 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
;
long long int t;
cin >> t;
while (t--) {
long long int n;
cin >> n;
long long int a[2 * n], bc = 0, sc = 0, d[n], x = 0, y = 0;
long long int diffp[100005], diffn[1... | 1,700 | CPP |
from fractions import gcd
a,b,n=map(int,input().split())
s1=0
s2=0
for i in range(0,n):
n-=gcd(a,n)
s1+=1
if n==0:
break
n-=gcd(b,n)
s2+=1
if n==0:
break
if s1>s2:
print(0)
else:
print(1) | 800 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int n, cnt, a[220000];
long long sum;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
for (int l = 1; l <= n; l++) {
sum = a[l + 1];
for (int r = l + 2; r <= n; r++) {
if (a[l] < a[r]) {
sum += a[r];
if (sum... | 2,500 | CPP |
t = int(input())
for _ in range(t):
n, k, d = map(int, input().split())
a = list(map(int, input().split()))
m = dict()
for i in range(d):
if a[i] not in m:
m[a[i]] = 0
m[a[i]] += 1
ans = len(m)
for i in range(n - d):
m[a[i]] -= 1
if m[a[i]] == 0:
... | 1,000 | PYTHON3 |
from collections import deque
import math
def main():
n = int(input())
t = input().strip()
s_list = deque()
for i in range(round(math.sqrt(2 * n + 1 / 4) - (1 / 2))):
s_list.append(t[i*(i+1)//2])
print("".join(s_list))
main()
| 800 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 20, Mod = 1e9 + 7;
int pl, pr, vl, vr, k;
long double p, q;
vector<int> v;
void count(int t) {
int L, R;
L = min(v[t], pr) - max(v[t - 1] + 1, pl);
R = min(v[t + k] - 1, vr) - max(v[t + k - 1], vl);
p += max(L + 1, 0) * 1ll * max(R + 1, 0);
L = min(v... | 1,900 | CPP |
#include <bits/stdc++.h>
using namespace std;
int N, p[500001];
pair<int, int> tree1[500001], tree2[500001];
vector<pair<int, int> > g1[500001];
list<int> g2[500001];
list<int>::iterator edges[500001][2];
int parent(int x) { return (p[x] == x) ? x : (p[x] = parent(p[x])); }
void merge(int x, int y) { p[parent(x)] = par... | 3,200 | CPP |
import sys
input = sys.stdin.readline
n=int(input())
P=[1]+list(map(int,input().split()))
A=list(map(int,input().split()))
for i in range(n):
P[i]-=1
Y=[1]*n
for i in range(n):
Y[P[i]]=0
#print(Y)
for i in range(n-1,0,-1):
Y[P[i]]+=Y[i]
S=[a for a in A]
for i in range(n-1,0,-1):
S[P[i]]+=S[i]
OK=... | 1,900 | PYTHON3 |
from sys import stdin, exit
inputs = map(int, next(stdin).split())
outputs = map(int, next(stdin).split())
extras = [x - y for x, y in zip(inputs, outputs)]
for i in range(3):
if extras[i] < 0:
for x in range(3):
while extras[i] < 0 and extras[x] > 1:
extras[i] += 1
... | 1,200 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int MAXNLAY = 1000010;
const int MAXNCOL = 1000010;
const int MAXLAYL = 5010;
const int MAXSUML = 10000010;
int nLay, nCol, prm;
int layL[MAXNLAY], maxLayL, sumL[MAXNLAY];
int perm[MAXLAYL], fact[MAXLAYL];
int g[MAXLAYL][MAXLAYL];
int f[MAXSUML];
int inData() {
scan... | 2,600 | CPP |
x=sorted([int(x) for x in input().split( )])
if (x[0]+x[3]==x[1]+x[2] or x[0]+x[1]+x[2]==x[3]) :
print("YES")
else :
print("NO") | 800 | PYTHON3 |
#include <bits/stdc++.h>
int a, h, w;
int extended_euclid(int a, int b, int &x, int &y) {
if (b == 0) {
x = 1;
y = 0;
return a;
}
int ans = extended_euclid(b, a % b, x, y);
int p = y;
y = x - a / b * y;
x = p;
if (x < 0) {
y += (x / b - 1) * a;
x -= (x / b - 1) * b;
}
if (x > b) {
... | 2,700 | CPP |
for _ in range(int(input())):
n=int(input())
arr=[int(x) for x in input().split()]
arr.sort()
left=0
right=n-1
ans=1
c=0
ans=max(arr[n-1]*arr[n-2]*arr[n-3]*arr[n-4]*arr[n-5],arr[0]*arr[1]*arr[n-1]*arr[n-2]*arr[n-3],arr[0]*arr[1]*arr[2]*arr[3]*arr[-1])
print(ans) | 1,200 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 9;
int n, m, k;
vector<int> e[maxn];
int vis[maxn], ru[maxn];
queue<int> q;
vector<int> s;
bool serch(int x, int y) {
int l = 0, r = e[x].size();
while (l <= r) {
int mid = (l + r) >> 1;
if (e[x][mid] < y) {
l = mid + 1;
} else i... | 2,600 | CPP |
#include <bits/stdc++.h>
using namespace std;
const long long llINF = 9223372036854775807;
const int INF = 2147483647;
const int maxn = 2e5 + 7;
const int maxm = 1e6 + 7;
const int ALP = 26;
const long long mod = 1e9 + 7;
const double pi = acos(-1.0);
const double eps = 1e-8;
int T;
int r, c, k;
char s[107][107];
char ... | 1,700 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int TC;
cin >> TC;
while (TC--) {
int N;
cin >> N;
string s;
cin >> s;
int ans = 0;
int cnt = 0;
for (int i = N - 1; i >= 0; i--) {
if (s[i] == 'P')
cnt++;
else {
... | 800 | CPP |
n = int(input())
a = list(map(int,input().split()))
i = 0
k = 0
while i < len(a) and k <= 1:
if a[i] == 0:
k += 1
i+=1
else:
i+=1
if k == 1 and len(a) > 1:
print("YES")
elif k == 0 and len(a) == 1:
print("YES")
else:
print("NO") | 1,000 | PYTHON3 |
t = int(input())
while (t):
n = int(input())
a = [0] + list(map(int, input().split()))
b = [0] + list(map(int, input().split()))
k = 0
f = True
for i in range(1, n + 1):
if a[i] != b[i] and k == 0:
k = b[i] - a[i]
#print(k)
if k < 0:
f = False
break
elif (a[i] + k != b[i] and k != 0 and a[i] ... | 1,000 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
vector<int> div1, div2;
int main() {
int n, m, a, b, i;
cin >> n >> m;
for (i = 1; i <= m; i++) {
cin >> a >> b;
if (a > b) swap(a, b);
div2.push_back(a);
div1.push_back(b);
}
if (m == 0)
cout << n - 1;
else {
a = *max_element(div2.begin(... | 1,300 | CPP |
N = int(input())
List = [int(x) for x in input().split()]
query = []
q = int(input())
for i in range(q):
x = [int(x) for x in input().split()]
query.append(x)
second = [-1] * q
if(query[q-1][0] == 2):
second[q-1] = query[q-1][1]
for i in range(q-2,-1,-1):
if(query[i][0] == 2):
second[i] = max(se... | 1,600 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
bool desc_sort(const int& lhs, const int& rhs) { return lhs > rhs; }
bool desc_pii_sort(const pair<int, int>& lhs, const pair<int, int>& rhs) {
return lhs > rhs;
}
bool second_sort(const pair<int, int>& lhs, const pair<int, int>& rhs) {
pair<int, int> a, b;
a.first = ... | 1,700 | CPP |
#include <bits/stdc++.h>
using namespace std;
int num[10005];
int main() {
int t;
cin >> t;
while (t--) {
int n, k;
cin >> n >> k;
if (n > k) {
cout << k << endl;
} else {
int a = k / (n - 1), b = k % (n - 1);
if (k % (n - 1) == 0) {
cout << a * n - 1 << endl;
} els... | 1,200 | CPP |
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
;
long long t;
cin >> t;
while (t--) {
long long m;
cin >> m;
vector<vector<long long>> res(2, vector<long long>(m));
string str1, str2;
cin >> str1 >> str2;
... | 800 | CPP |
n=int(input())
a=[int(i) for i in input().split()]
m=int(input())
b=[int(i) for i in input().split()]
c=[0 for i in range(n)]
d=[0 for i in range(m)]
a.sort()
b.sort()
num=0
for i in range(n):
for j in range(m):
if (abs(a[i]-b[j])<=1)and(c[i]==0)and(d[j]==0):
num+=1
c[i]=1
... | 1,200 | PYTHON3 |
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
cnt = [0]*n
for i, x in enumerate(a):
while x % 2 == 0:
cnt[i] += 1
x //= 2
ok = Counter(cnt).most_common(1)[0][0]
ans = []
for i in range(n):
if cnt[i] != ok:
ans.append(a[i])
print(len(ans))
if ans:... | 1,900 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, k, x;
cin >> n >> k;
long long mn = 1000000000000000000;
long long type, ans;
for (int i = 0; i < k; i++) {
cin >> x;
long long p = n % x;
if (p < mn) {
mn = p;
type = i + 1;
ans = n / x;
}
}
cout << ... | 1,000 | CPP |
# cook your dish here
from sys import stdin, stdout
import math
from itertools import permutations, combinations
from collections import defaultdict
from bisect import bisect_left
from bisect import bisect_right
def L():
return list(map(int, stdin.readline().split()))
def In():
return map(int, stdin.readli... | 1,200 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
template <class R>
inline void Readin(R &K) {
K = 0;
bool F = false;
char C = getchar();
while (C < '0' or C > '9') {
if (C == '-') F = true;
C = getchar();
}
while (C <= '9' and C >= '0')
K = (K << 1) + (K << 3) + C - '0', C = getchar();
if (F) K ... | 1,900 | CPP |
n, x, y = map(int, input().split())
a = input()
b = str(10**x + 10**y)
count = 0
for i in range(x + 1):
if(a[-i] != b[-i]):
count += 1
print(count)
| 1,100 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int inf = (int)1e9;
const int mod = inf + 7;
const double eps = 1e-9;
const double pi = acos(-1.0);
int n, k, m, used[2020][2020];
vector<int> g[2020];
bool c[2020];
vector<int> cur;
void dfs(int v) {
c[v] = 1;
cur.push_back(v);
for (__typeof(g[v].begin()) it = ... | 1,500 | CPP |
n, k = (int(x) for x in input().split())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
cur_sum = 0
max_sum = 0
sum = 0
for i in range(n):
if b[i] == 1:
sum += a[i]
if i < k:
cur_sum += (1 - b[i]) * a[i]
else:
cur_sum += (1 - b[i]) * a[i]
c... | 1,200 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 150000;
void pls() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
int32_t main() {
pls();
long long k, b, n, t;
cin >> k >> b >> n >> t;
if (t == 1) {
cout << n << endl;
} else if (k == 1) {
long long at = max(double(0), c... | 1,700 | CPP |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
using namespace std;
const int INF = (int)1e9 + 123;
const long long LINF = (long long)1e18 + 123;
const long double EPS = (long double)1e-7;
const long long MOD = (long long)1e9 + 7;
long long power(lon... | 2,300 | CPP |
n = int(input())
string = input() + " "
xs_in_a_row = 0
x_counts = []
for i in range(n + 1):
if string[i] == 'x':
xs_in_a_row += 1
else:
x_counts.append(xs_in_a_row)
xs_in_a_row = 0
min_num_of_chars = 0
for count in x_counts:
if count >= 3:
min_num_of_chars += count - 2
... | 800 | PYTHON3 |
import sys
import bisect
from bisect import bisect_left as lb
input_=lambda: sys.stdin.readline().strip("\r\n")
from math import log
from math import gcd
from math import atan2,acos
from random import randint
sa=lambda :input_()
sb=lambda:int(input_())
sc=lambda:input_().split()
sd=lambda:list(map(int,input_().split())... | 1,500 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
double pi = 3.1415926535;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
double d, h, v, e;
cin >> d >> h >> v >> e;
if ((4 * v) / (pi * d * d) < e) {
cout << "NO\n";
return 0;
}
cout << "YES\n";
cout << h / ((4 * v) / (pi * d * d) - e) << "\n";
... | 1,100 | CPP |
n=int(input())
result = [int(item) for item in input().split()]
m=max(result);s=0
for i in result:
if i<=m:
s+=m-i
print(s) | 800 | PYTHON3 |
import math
def isPerfectSquare(x):
s = int(math.sqrt(x))
return s * s == x
def isFibonacci(n):
return isPerfectSquare(5 * n * n + 4) or isPerfectSquare(5 * n * n - 4)
n=int(input())
for i in range(n):
if (isFibonacci(i+1) == True):
print("O",end="")
else:
print("o",end="")
| 800 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
const int MAXN = 110 * 26;
const int MAXM = MAXN * 100;
int read() {
int kkk = 0, x = 1;
char c = getchar();
while ((c < '0' || c > '9') && c != '-') c = getchar();
if (c == '-') c = getchar(), x = -1;
while (c >= '0' && c <= '9') kkk = kkk * ... | 2,500 | CPP |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
const int INF = (int)1e9;
const long double EPS = 1e-9;
const long double PI = 3.1415926535897932384626433832795;
int n, m;
char a[1010][1010];
long long sI[1010], sJ[1010];
int main() {
cin >> n >> m;
memset(sI, 0, sizeof(sI)... | 1,600 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main(int argc, char **argv) {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector<int> v(n + 2), tmp;
for (int i = 1; i <= n; ++i) cin >> v[i];
vector<int> left(n + 2, 0);
for (int i = 1; i <= n; ++i) left[i] = min(left[i - 1] + 1, v[i - 1]... | 1,600 | CPP |
#include <bits/stdc++.h>
struct pt {
int x, y;
};
pt operator+(pt a, pt b) {
pt p = {std::min(a.x, b.x), std::max(a.y, b.y)};
return p;
}
int n, Q;
int head[(1 << 18)], nxt[(1 << 18)], level[(1 << 18)], tree[(1 << 18) * 2],
rev[(1 << 18)], tin[(1 << 18)];
pt pre[(1 << 18) * 2];
void dfs(int x) {
static int ... | 2,300 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
std::ios_base::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<long long> l(m), suffix(m + 1);
long long total_len = 0;
for (int i = 0; i < m; i++) {
cin >> l[i];
total_len += l[i];
}
if (total_len < n || n - l[m - ... | 1,800 | CPP |
#include <bits/stdc++.h>
using namespace std;
void add(long long &x, long long y) {
x += y;
if (x >= 1000000007) x -= 1000000007;
}
long long C[1010][1010];
long long dp[1010][1010][4];
long long F[1010];
int main() {
int N, K;
scanf("%d%d", &N, &K);
for (int i = 0; i <= N; i++)
for (int j = 0; j <= i; j+... | 2,600 | CPP |
def func(aa1, aa2, kk1, kk2, nn):
if (nn <= aa1 * (kk1 - 1) + aa2 * (kk2 - 1)):
print(0)
elif (nn < aa1 * kk1 + aa2 * kk2):
print(nn - aa1 * (kk1 - 1) - aa2 * (kk2 - 1))
else:
print(aa1 + aa2)
if (nn <= aa1 * kk1):
print(nn // kk1)
elif(nn <= aa1 * kk1 + aa2 * kk... | 1,000 | PYTHON3 |
from math import inf
t = int(input())
for q in range(t):
n = int(input())
A = [int(i) for i in input().split()]
mi = inf
ma = -1 * inf
for i in range(len(A)):
if A[i] != -1:
if i < len(A) - 1 and A[i + 1] == -1:
mi = min(A[i], mi)
ma = max(A[i], ma... | 1,500 | PYTHON3 |
n,a,b=map(int,input().split())
airport=input()
if airport[a-1]==airport[b-1]:
print(0)
else:
print(1) | 1,200 | PYTHON3 |
def solve(g, i, j):
ans = 0
for ii in range(i):
ans = max(ans, min(g[ii]))
print(ans)
i, j = tuple(map(int, input().split()))
g = []
for _ in range(i):
g.append(list(map(int, input().split())))
solve(g, i, j)
| 1,000 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 305;
map<string, int> mp;
string s;
int id[N], sum[N];
int n, cnt, ans;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
cin >> s;
if (!mp.count(s)) mp[s] = ++cnt;
id[i] = mp[s];
sum[i] = sum[i - 1] + s.size();
}
ans = sum[n... | 2,200 | CPP |
a = input()
flag = False
num0 = 0
for i in range(0,len(a)):
if a[i] == '1':
flag = True
if flag == True and a[i] == '0':
num0 = num0 + 1;
if num0 >= 6 :
print("yes")
else:
print("no")
| 1,000 | PYTHON3 |
t=int(input())
for i in range(0,t):
a=input()
b=input()
a=a.lower()
b=b.lower()
f=0
c=len(b)-len(a)
if(len(b)==len(a) and sorted(a)==sorted(b)):
print("YES")
elif(len(b)<len(a)):
print("NO")
else:
for i in range(0,c+1):
d=b[i:(i+len(a))]
... | 1,000 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
inline char read() {
static const int IN_LEN = 1000000;
static char buf[IN_LEN], *s, *t;
return (s == t ? t = (s = buf) + fread(buf, 1, IN_LEN, stdin),
(s == t ? -1 : *s++) : *s++);
}
template <class T>
inline void read(T &x) {
static bool io... | 1,600 | CPP |
#include <bits/stdc++.h>
using namespace std;
inline int getSecsInYear(int year) {
if (year % 400 == 0 || (year % 100 != 0 && year % 4 == 0))
return 60 * 60 * 24 * 366;
else
return 60 * 60 * 24 * 365;
}
int lm[12] = {31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
inline int getSecsInMonth(int year, int mon... | 2,800 | CPP |
n=int(input())
for i in range(n-1):
print(['I hate that ','I love that '][i%2],sep='',end='')
print(['I love it','I hate it'][n%2])
| 800 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
long long Solver(int h, long long n) {
if (h == 0) return 0;
if (n > (1LL << (h - 1))) {
return (1LL << h) + Solver(h - 1, n - (1LL << (h - 1)));
} else {
return (1) + Solver(h - 1, (1LL << (h - 1)) + 1 - n);
}
}
int main() {
ios_base::sync_with_stdio(0);
... | 1,700 | CPP |
import sys
def main():
n = int(sys.stdin.readline().strip())
dirs, dists = [], []
earth_circum = 40000
lat = 0
north = "North"
south = "South"
for i in range(n):
distance, direction = [s for s in sys.stdin.readline().split()]
distance = int(distance)
if dir... | 1,300 | PYTHON3 |
t_count = int(input().strip())
while t_count > 0:
n, k = list(map(int, input().strip().split(' ')))
if n % 2 == 0:
if k % 2 == 0:
if n >= 2 * k:
rem = n - 2 * (k - 1)
print('YES')
print('2 ' * (k - 1), rem, sep = '')
elif n >= k:
... | 1,200 | PYTHON3 |
n = int(input())
s = n // 2
if n % 2:
s = -s - 1
print(s)
| 800 | PYTHON3 |
t=int(input())
for i in range(t):
n=int(input())
a=list(map(int,input().split()))
c=0
for j in range(n-1):
if a.count(a[j])>2:
print('YES')
break
elif a[j]!=a[j+1] and a[j]!=a[j-1] and a.count(a[j])==2 and j>=1:
print('YES')
break ... | 1,100 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
long long n, i, ans, cnt, x;
int main() {
scanf("%I64d", &n);
cnt = 1;
x = 1;
while (i < n) {
if (i * 10 + 9 <= n)
ans += 9 * x * cnt;
else
ans += (n - i) * cnt;
x *= 10;
cnt++;
i = i * 10 + 9;
}
printf("%I64d\n", ans);
return 0... | 1,200 | CPP |
#author: raghav_0901
from math import *
mod = (10**9) + 7
def _in():
return [int(x) for x in input().split(' ')]
def main():
n = input()
ans = []
for i in range(len(n)):
if n[i] != '0':
ans.append(int(n[i]) * (10**(len(n) - i - 1)))
print(len(ans))
for i in ans:
... | 800 | PYTHON3 |
n = int(input())
a5 = n % 10;
n //= 10;
a4 = n % 10;
n //= 10;
a3 = n % 10;
n //= 10;
a2 = n % 10;
a1 = n // 10;
k = a1 * 10000 + a3 * 1000 + a5 * 100 + a4 * 10 + a2;
k = k * k * k * k * k;
x5 = k % 10
k //= 10
x4 = k % 10
k //= 10
x3 = k % 10
k //= 10
x2 = k % 10
k //= 10
x1 = k % 10
print(repr(x1) + repr(x2) + repr(... | 1,400 | PYTHON3 |
n=int(input())
k=0
while(k<n):
c=input()
if((len(c))<=10):
print(c)
else:
print(c[0]+str(len(c)-2)+c[len(c)-1])
k=k+1
| 800 | PYTHON3 |
# import sys
# sys.stdin=open("input.in","r")
s=input()
l=set()
for i in range(len(s)):
l.add(s[i:]+s[:i])
print(len(l)) | 900 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
long long sum(vector<long long> a) {
long long n = a.size(), sol = 0;
for (long long i = 1; i < n; ++i) {
if (a[i] % 2 != a[i - 1] % 2) ++sol;
}
return sol;
}
bool cmp(pair<long long, long long> a, pair<long long, long long> b) {
return ((a.second - a.first) <... | 1,800 | CPP |
def isAllOnes(st):
for ch in st:
if ch == "0":
return False
return True
# print ("Input n and d")
n,d = (int(j) for j in input().split())
currun = 0
maxrun = 0
for i in range(d):
# print("Input the next string")
nextone = input()
if isAllOnes(nextone):
currun = 0
els... | 800 | PYTHON3 |
s=input()
count=0
for i in range(len(s)):
if(s[i]=="4" or s[i]=="7"):
count=count+1
if(count==4 or count==7):
print("YES")
else:
print("NO") | 800 | PYTHON3 |
from math import *
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
s=set()
for i in range(1,len(a)):
s.add(a[i])
for i in range(1,len(b)):
s.add(b[i])
if len(s)==n:
print('I become the guy.')
else:
print('Oh, my keyboard!')
| 800 | PYTHON3 |
n = int(input())
max, curr = 0, 0
for i in range(n):
a, b = [int(elem) for elem in input().split()]
curr -=a
curr +=b
if curr > max:
max = curr
print(max) | 800 | PYTHON3 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long n;
cin >> n;
vector<long long> vis(101, 0);
long long l, r;
cin >> l >> r;
for (long long i = 2; i <= n... | 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
long long power(long long a, long long b) {
long long ans = 1;
while (b > 0) {
if (b & 1) ans *= a;
a = a * a;
b >>= 1;
}
return ans;
}
long long powm(long long a, long long b) {
a %= MOD;
long long ans = 1;
while (b > 0) {... | 800 | CPP |
#include <bits/stdc++.h>
int findmax(int p, int t);
int main() {
int a, b, c, d;
scanf("%d%d%d%d", &a, &b, &c, &d);
if (findmax(a, c) > findmax(b, d)) {
printf("Misha");
} else if (findmax(a, c) < findmax(b, d)) {
printf("Vasya");
} else {
printf("Tie");
}
return 0;
}
int findmax(int p, int t)... | 900 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 5, maxa = 1e6 + 5;
inline int gi() {
char c = getchar();
while (c < '0' || c > '9') c = getchar();
int sum = 0;
while ('0' <= c && c <= '9') sum = sum * 10 + c - 48, c = getchar();
return sum;
}
int n, q, a[maxn], A;
pair<int, int> sum[maxa ... | 3,300 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 110005;
int n, qq, fa[maxn], f[maxn], sz[maxn], up[maxn], edge[maxn], dep[maxn],
son[maxn], q[maxn];
int tot = 0, V[maxn << 1], N[maxn << 1], F[maxn], ans[maxn];
struct event {
int c, k, a, b;
} events[maxn << 1];
struct info {
int ls, rs, len, val;... | 3,100 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int INF = 2e9;
const int MOD = 1e9 + 7;
vector<long long> vector_input(long long n) {
vector<long long> v;
for (long long i = 0; i < n; i++) {
long long num;
cin >> num;
v.push_back(num);
}
return v;
}
void input() {
string s;
int q;
cin >> s... | 1,600 | CPP |
w=input()
n=w.lower()
l=len(n)
for i in range(0,l,1):
if n[i]!='a' and n[i]!='e' and n[i]!='i' and n[i]!='o' and n[i]!='u' and n[i]!='y':
print('.',n[i],sep='',end='')
| 1,000 | PYTHON3 |
nm = [int(i) for i in input().split(' ')]
n = nm[0]
m = nm[1]
lists = [int(i) for i in input().split(' ')]
lists.sort()
result = 0
for j in range(m-n+1):
if(j==0):
result = lists[j+n-1] - lists[j]
elif(lists[j+n-1] - lists[j] <= result):
result = lists[j+n-1] - lists[j]
... | 900 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int maxN = 5005;
int n, a[maxN], res, cnt;
int big[maxN][maxN], small[maxN][maxN];
int main() {
ios_base::sync_with_stdio(false);
res = 1e9;
scanf("%d", &n);
for (int i = 1; i <= n; ++i) scanf("%d", &a[i]), ++a[i];
int old = 0;
for (int i = 2; i <= n; ++i)... | 1,900 | CPP |
n=int(input())
for _ in range(n):
a=input()
a=list(a)
if len(a)>10:
b=len(a)-2
b=str(b)
a=a[0]+b+a[len(a)-1]
print(a)
else:
print("".join(a)) | 800 | PYTHON3 |
#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const long long inf = 0x3f3f3f3f3f3f3f3fll;
inline int read() {
register int x = 0, dp = 1;
register char c = getchar();
fo... | 2,700 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n, k;
vector<pair<int, int> > e[200011];
vector<int> ans;
int main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin >> n >> k;
int li, ri;
for (int i = (0); i < (n); ++i) {
cin >> li >> ri;
--li, --ri;
e[li].emplace_back(-ri, i);
}
s... | 1,800 | CPP |
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()
INF = 10**20... | 1,600 | PYTHON3 |
/*
* @Author: zhl
* @LastEditTime: 2021-02-08 21:20:19
*/
/* Author: zhl
* Time: 2021-02-07 22:35:03
**/
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
typedef long long ll;
int n, A[N], vis[N], B[N], pre[N], f[N], mx[N];
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
... | 2,100 | CPP |
#include <bits/stdc++.h>
using namespace std;
const long long N = 1e6 + 1;
const long long INF = 1e9 + 7;
const long long inf = 1e18;
vector<long long> adj[N];
long long vis[N];
long long ans[N];
long long ct;
void dfs(long long node) {
vis[node] = ct;
ans[ct]++;
for (auto it : adj[node]) {
if (!vis[it]) {
... | 1,400 | CPP |
n, m=map(int, input().split())
i=0
while n!=0 and m!=0:
n-=1
m-=1
i+=1
if i%2:
print("Akshat")
else:
print("Malvika") | 900 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
const int B = 8, M = 1 << B;
int ord[6][3] = {{0, 1, 2}, {0, 2, 1}, {1, 0, 2},
{1, 2, 0}, {2, 0, 1}, {2, 1, 0}};
struct P {
int x, y, z;
bool operator==(const P &rhs) const {
return x == rhs.x && y == rhs.y && z == rhs.z;
}
... | 2,000 | CPP |
l=input().split()
a=int(l[0])
b=int(l[1])
print(min(a,b),end=' ')
print((max(a,b)-min(a,b))//2)
| 800 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
template <class _T_>
void read(_T_& d) {
d = 0;
int f = 1;
char c = getchar();
for (; c < '0' || c > '9'; c = getchar())
if (c == '-') f *= -1;
for (; c >= '0' && c <= '9'; c = getchar()) d = d * 10 + c - '0';
d *= f;
}
const double eps = 1e-9;
struct Node {... | 2,900 | CPP |
End of preview. Expand in Data Studio
README.md exists but content is empty.
- Downloads last month
- 29