solution stringlengths 10 983k | difficulty int64 0 25 | language stringclasses 2
values |
|---|---|---|
import math
data=input().split()
n=int(data[0])
m=int(data[1])
a=int(data[2])
k=math.ceil(n/a)
l=math.ceil(m/a)
print(k*l)
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int MaxN = 100010;
int solve(int n, int m) {
int x[] = {n, m};
int s = n + m;
--x[0];
int a = 0, p = 0;
for (int i = 2; i <= s; ++i) {
if (i & 1) {
if (x[p]) {
--x[p];
++a;
} else {
p ^= 1;
--x[p];
--a;... | 8 | CPP |
k=int(input())
l=list(map(int,input().split()))
l.sort(reverse=True)
i=0
s=0
flag=0
if(k==0):
print(0)
flag=1
while i<12 and flag==0:
s+=l[i]
if(s>=k):
print(i+1)
flag=1
break
i+=1
if flag==0:
print(-1)
| 7 | PYTHON3 |
n=int(input())
c=list(map(int,input().split()))
t=list(map(int,input().split()))
cdiffs=[c[i+1]-c[i] for i in range(n-1)]
tdiffs=[t[i+1]-t[i] for i in range(n-1)]
if sorted(cdiffs)==sorted(tdiffs) and t[0]==c[0]:
print("Yes")
else:
print("No") | 11 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int cost[200000 + 5], jump[200000 + 5], mark[200000 + 5];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, i, j, k, temp, ticks = 0, ans = 0;
cin >> n;
for (i = 1; i <= n; ++i) cin >> cost[i];
for (i = 1; i <= n; ++i) cin >> jump[i];
for (i... | 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
long long powmod(long long a, long long b) {
long long tmp = 1;
a %= (1000000007);
for (; b; b >>= 1) {
if (b & 1) tmp = tmp * a % (1000000007);
a = a * a % (1000000007);
}
return tmp;
}
long long gcd(l... | 11 | CPP |
#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:128000000")
using namespace std;
mt19937 ggen;
int n;
long long A, cf, cm, m;
pair<long long, int> a[100010];
long long aval[100010];
long long ps[100010];
long long rps[100010];
long long mps[100010];
void solve() {
cin >> n >> A >> cf >> cm >> m;
for (int i... | 8 | CPP |
from math import gcd
K=int(input())
S=0
for a in range(1,K+1):
for b in range(1,K+1):
for c in range(1,K+1):
S+=gcd(a,gcd(b,c))
print(S)
| 0 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int a[n], b[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
b[i] = a[i];
}
string s;
cin >> s;
int cnt = 0;
vector<int> big, small, old1, old0;
for (int i =... | 8 | CPP |
n = input()
m = input()
q =""
for i in range(len(n)):
if n[i]!=m[i]:
q+="1"
else:
q+="0"
print(q)
| 7 | PYTHON3 |
n = int(input())
s = [x for x in input()]
v = ['a', 'e', 'i', 'o', 'u','y']
ans = ''
i = 0
while i<(len(s)):
if(s[i] not in v):
ans+=s[i]
else:
ans+=s[i]
while(i<len(s) and s[i] in v):
i+=1
i-=1
i+=1
print(ans)
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100 * 1000 + 1000;
int arr[MAXN];
int mrk[MAXN];
int n;
int32_t main() {
int cur = 0, max_so = 0;
cin >> n;
for (int i = 0; i < 2 * n; i++) {
int num;
cin >> num;
if (!mrk[num]) {
mrk[num] = 1;
cur++;
} else {
mrk[num... | 7 | CPP |
#include <bits/stdc++.h>
const char EMPTY = '.';
static void setComponent(int rows, int cols,
const std::vector<std::string>& input, int row,
int col, std::deque<std::pair<int, int>>& toVisit,
std::vector<std::vector<int>>& components,
... | 9 | CPP |
M,D=map(int,input().split())
ans = 0
for m in range(1,M+1):
for d in range(22,D+1):
d1 = d%10
d10 = d//10
if d1 >=2 and d10 >=2 and m == d1*d10: ans += 1
print(ans) | 0 | PYTHON3 |
n = int(input())
ai = input().replace(" ","")
num = ai.count("1")
print(num + ai.replace("101","11011").count("101"))
| 7 | PYTHON3 |
import sys
def main():
s = input()
n = len(s)
lim = 243
ar = [int(c) for c in s]
dp = [0] * (n + lim + 3)
for i in range(n - 1, -1, -1):
x = 0
k = 1 if ar[i] == 0 else lim
for j in range(k):
if (i + j) == n:
break
... | 10 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
template <class A, class B>
ostream& operator<<(ostream& o, pair<A, B>& p) {
return o << "(" << p.first << ", " << p.second << ")";
}
template <class T>
ostream& operator<<(ostream& o, const vector<T>& v) {
o << "{";
for (typeof((v).begin()) it = (v).begin(); it != (v... | 7 | CPP |
#include<bits/stdc++.h>
using namespace std;
int main()
{long long n;cin>>n;
cout<<(n/2)+(n%2);
return 0;
}
| 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
set<long long> s;
long long n, k;
cin >> n >> k;
for (int i = 1; i <= k; i++) {
if (s.find(n % i) != s.end()) break;
s.insert(n % i);
}
if (s.size() == k)
cout << "YES";
else
cout << "NO";
}
| 9 | CPP |
t=int(input())
for i in range(t):
n=int(input())
a=input()
b=""
for j in range(0,len(a),2):
b+=a[j]
print(b) | 7 | PYTHON3 |
N,A,B=map(int,input().split())
x=min([N*A,B])
print(x)
| 0 | PYTHON3 |
# https://codeforces.com/contest/1358/problem/D
import sys
import os
import heapq
import math
try:
path = "./file/input.txt"
if os.path.exists(path):
sys.stdin = open(path, 'r')
# sys.stdout = open(r"./file/output.txt", 'w')
except:
pass
t = 1
def printd(value):
# print(value)
pa... | 10 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int NUM_ROW = 15;
const int NUM_COL = 15;
int mod(int a) {
if (a < 0) {
return -a;
}
return a;
}
int cmp(const void *a, const void *b) { return -(*(int *)a - *(int *)b); }
void FV(int grid[NUM_ROW][NUM_COL], int length) {
for (int k = 0; k < length; k++) {... | 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
unsigned long long int a;
unsigned long long int temp;
unsigned long long int temp2;
unsigned long long int count = 0;
for (int i = 0; i < n; i++) {
cin >> a;
if (a == 1) {
cout << "NO\n";
} else {
temp = (... | 8 | CPP |
import math as m
n=int(input())
arr=[]
c=1
for i in range(n):
t=int(input())
if t/2==m.ceil(t/2):
arr.append(t//2)
elif c%2!=0:
arr.append(m.ceil(t/2))
c+=1
else:
arr.append(m.floor(t/2))
c+=1
for i in arr:
print(i) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 2e5 + 5;
pair<long long, long long> a[MAXN];
long long s;
long long n;
bool check(long long x) {
long long sum = 0, cnt = 0;
vector<long long> nums;
for (long long i = 0; i < n; i++) {
if (a[i].first >= x) {
sum += a[i].first;
cn... | 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
const int MAXM = 60;
int sum[MAXN << 2][MAXM];
void push_up(int rt) {
for (int i = 0; i < MAXM; ++i)
sum[rt][i] =
sum[rt << 1][i] + sum[rt << 1 | 1][(i + sum[rt << 1][i]) % MAXM];
}
void build(int l, int r, int rt) {
if (l == r) {
... | 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long int gcd(long long int a, long long int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long int tc = 1;
cin >> tc;
while (tc--) {
long long int m, d, w;
cin >> m >>... | 11 | CPP |
n=int(input())
a=list(input())
l=[0,0,0,0,0]
for i in a:
if i=='A':
l[0]+=1
elif i=='C':
l[1]+=1
elif i=='G':
l[2]+=1
elif i=='T':
l[3]+=1
else:
l[4]+=1
max1=max(l[:-1])
req=0
for i in l[:-1]:
req=req+(max1-i)
if ((req!=l[-1] and l[-1]!=n) and ((l[-1]-req)... | 8 | PYTHON3 |
n=[]
x=str(input())
d=x.replace('WUB',' ')
c=d.replace(' ',' ')
for v in c:
n.append(v)
if n[0]==' ':
n.remove(n[0])
for m in n:
print(m,end='')
| 7 | PYTHON3 |
l,r=map(int,input().split())
mini=2019
L=l
R=r+1 if r-l<2019*2 else l+2019+1
for i in range(L,R):
for j in range(i+1,R):
mini=min(mini,i*j%2019)
print(mini) | 0 | PYTHON3 |
n = int(input())
array = list(map(int, input().split()))
i = 0
j = len(array)-1
soma = 0
soma1 = array[i]
soma2 = array[j]
while i < j:
if soma1 < soma2:
i += 1
soma1 += array[i]
elif soma1 > soma2:
j -= 1
soma2 += array[j]
else:
if soma1 > soma:
soma = ... | 9 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll inf = 1e9 + 7;
const double PI = 3.141592653589793;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll n, sumq = 0, mini = 0;
cin >> n;
ll q[n - 1];
for (ll i = 0; i < (ll)(n - 1); ++i) {
cin >> q[i];
... | 9 | CPP |
#include<bits/stdc++.h>
using namespace std;
int main(){
int N,M;
cin>>N>>M;
int ans=pow(2,M)*(100*N+1800*M);
cout<<ans<<endl;
} | 0 | CPP |
x1, y1 = map(int, input().split())
x2, y2 = map(int, input().split())
n = int(input())
num_sign_diff = 0
for road in range(n):
a, b, c = map(int, input().split())
pos1 = (a * x1 + b * y1 + c) > 0
pos2 = (a * x2 + b * y2 + c) > 0
if pos1 + pos2 == 1: #exactly one of them is on positive side of line
num_sign_diff +... | 7 | PYTHON3 |
l = list(map(int,input().split()))
coins = 0
login_times = 0
while True:
coins += l[0]
login_times += 1
if login_times%7==0:
coins += l[1]
if coins>=l[2]:
print(login_times)
break
| 0 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, s, sum1 = 0, sum2 = 0, c = 0, f;
vector<long long> v;
cin >> n;
for (size_t i = 0; i < n; i++) {
cin >> s;
v.push_back(s);
if (v[i] % 2 != 0) {
if (c % 2 == 0) {
v[i] = ceil(v[i] / 2.0);
c++;
} else {... | 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long mod = 1e9 + 7;
long long dp[25][25];
int a[30];
int dfs(int pos, int sta, bool lead, bool limit) {
if (pos == -1) return 1;
if (!limit && !lead && dp[pos][sta] != -1) return dp[pos][sta];
int up = limit ? a[pos] : 9;
long ... | 9 | CPP |
def optimal(num):
int_num = int(num)
if int_num >= 0:
return num
elif int_num >= -10:
return 0
else:
if num[-2] > num[-1]:
res = num[0:-2] + num[-1]
else:
res = num[0:-1]
if res == '-0':
return 0
return res
def main():
n = inpu... | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int constexpr nax = 3e5 + 5;
using ll = int64_t;
const int INF = 1e9;
template <typename T>
struct fenwick {
T bit[nax];
fenwick() { memset(bit, 0, sizeof(bit)); }
void update(int x, T val) {
for (; x < nax; x += x & -x) bit[x] += val;
}
T get(int x) {
int... | 9 | CPP |
# -*- coding: utf-8 -*-
"""
Created on Wed Aug 12 18:22:02 2020
@author: The Wonder Land
"""
"""
A. Watermelon
time limit per test: 1 second
memory limit per test: 64 megabytes
input: standard input
output: standard output
One hot summer day Pete and his friend Billy decided to buy a watermelon. They chose the biggest... | 7 | PYTHON3 |
#include <bits/stdc++.h>
int main() {
long long int a, b, s;
scanf("%lld%lld%lld", &a, &b, &s);
if (s >= abs(a) + abs(b)) {
if ((s - (abs(a) + abs(b))) % 2 == 0) {
printf("Yes\n");
} else {
printf("No\n");
}
} else {
printf("No\n");
}
return 0;
}
| 7 | CPP |
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
# from math import gcd
# from itertools import combinations,permutations,accumulate, product # (string,3) 3回
# #from collections import deque
# from collections import deque,defaultdict,... | 9 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
long long int A[1005], B[1005];
long long int V[1005];
int main() {
int n, k1, k2;
scanf("%d%d%d", &(n), &(k1), &(k2));
for (int i = 1; i <= n; i++) scanf("%lld", &(A[i]));
for (int i = 1; i <= n; i++) scanf("%lld", &(B[i]));
for (int i = 1; i <= n; i++) {
lon... | 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
char arr[1000][1000];
int main() {
int n;
cin >> n;
int ans = 0;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (i % 2 == 0 && j % 2 == 0)
arr[i][j] = 'C';
else if (i % 2 == 0 && j % 2 != 0)
arr[i][j] = '.';
else... | 7 | CPP |
# Legends Always Come Up with Solution
# Author: Manvir Singh
import os
import sys
from io import BytesIO, IOBase
def solve():
n = int(input())
a = [list(map(int,input().split())) for _ in range(n)]
for i in range(5):
for j in range(i + 1, 5):
x,y,f=0,0,1
for k in range(n):... | 8 | PYTHON3 |
def fonct():
n=int(input())
s=set()
nb=0;
for i in map(int,input().split()):
s.add(i);
t=len(s)
l=list()
if(t<=1):
print("NO");
else:
for i in s:
l.append(i);
l.sort()
print (l[1])
fonct()
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const long long maxN = 1e18;
const long long minN = -1e18;
const int INF = 2e9;
const long long MOD = 1e9 + 7;
const long long MOD1 = 998244353;
const int baseHash = 331;
const int bigNumLength = 5000;
const long double PI = acos(-1);
const long long limit = 3e5 + 5;
const ... | 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int N;
cin >> N;
int ans{};
for (int i{1}; N >= i; i *= 100) {
ans += min(i*10-1, N) - (i - 1);
}
cout << ans << endl;
return 0;
}
| 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int x, o = 0, l = 0;
string str;
cin >> str;
for (x = 0; x < str.length(); x++) {
if (str[x] == 'o')
o++;
else
l++;
}
if (l == 0 || o == 0)
cout << "YES" << endl;
else {
if (l % o)
cout << "NO" << endl;
else
... | 7 | CPP |
ip = str(input()).split(' ')
m = int(ip[0])
n = int(ip[1])
num_of_dominos_placed = 0
def print_board():
global board
for row in board:
print(''.join(row))
def place_domino(row, col):
global board, num_of_dominos_placed, m, n
if board[row][col] == '*':
if col + 1 < n and board[row][col + 1] == '*':
board[ro... | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int t;
cin >> t;
while (t--) {
long long int a, b, n, p;
cin >> a >> b >> n;
p = a ^ b;
if (n % 3 == 0)
cout << a << endl;
else if ((n - 1) % 3 == 0)
cout << b << endl;
else
cout << p << endl;
}
retu... | 7 | CPP |
arr=input()
arr=arr.lower()
new=""
ch=['a','e','i','o','u','y']
for i in range(len(arr)):
if arr[i] not in ch:
new+='.'
new+=arr[i]
print(new) | 7 | PYTHON3 |
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse2")
using namespace std;
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
std::cerr << name << " : " << arg1 << '\n';
}
template <typename Arg1, typename... Args>
void __f(const char* n... | 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 510000;
int n, k;
char s1[N], s2[N];
int main() {
scanf("%d%d", &n, &k);
scanf("%s%s", s1 + 1, s2 + 1);
long long ans = 0, now = 0, last = 0;
for (int i = 1; i <= n; i++) {
now = (now << 1) + s2[i] - s1[i];
long long tmp = min((long long)k, now... | 11 | CPP |
#include <bits/stdc++.h>
int main(void) {
int n, a[1000000], i = 0, b = 0, j;
char s[1000000];
scanf("%s", s);
n = strlen(s);
j = n - 1;
for (b = 0; b < n; b++) {
if (s[b] == 'r') {
a[i] = b + 1;
i++;
} else if (s[b] == 'l') {
a[j] = b + 1;
j--;
}
}
for (i = 0; i < n;... | 7 | CPP |
n = int(input())
d = list(map(int,input().split()))[:n]
dp = [[int(101) for i in range(100)] for j in range(3)]
dp[0][0] = 1
if d[0]==1 or d[0]==3:
dp[1][0] = 0
if d[0]==2 or d[0]==3:
dp[2][0] = 0
for i in range(1,n):
dp[0][i] = 1+min(dp[0][i-1],dp[1][i-1],dp[2][i-1])
if d[i]==1 or d[i]==3:
... | 7 | PYTHON3 |
if __name__ == '__main__':
n = int(input())
if n in (1, 2):
print(1)
elif n == 3:
print(0)
elif n % 4 == 0 or (n-3) % 4 == 0:
print(0)
else:
print(1) | 7 | PYTHON3 |
import math as mt
import sys,string,bisect
input=sys.stdin.readline
import random
from collections import deque,defaultdict
L=lambda : list(map(int,input().split()))
Ls=lambda : list(input().split())
M=lambda : map(int,input().split())
I=lambda :int(input())
n,s=M()
a=L()
def check(k,s):
l=a[::]
for i in range... | 9 | PYTHON3 |
n, m, q= map(int,input().split())
s,t = input(), input()
ans = ""
for i in range(n-m+1):
if s[i:i+m] == t:
ans += "1"
else:ans += "0"
for i in range(0,q):
l, r = map(int,input().split())
if r-l+1 >= m:
print(ans[l-1 : r-m+1].count("1"))
else:print("0") | 8 | PYTHON3 |
nm = list(map(int, input().split()))
n, m = nm[0], nm[1]
pol = set()
vrag = set()
for i in range(0, n):
pol.add(input())
for i in range(0, m):
vrag.add(input())
vrf = 0
while len(pol) > 0 and len(vrag) > 0:
vrf = 0
pol_flag = 0
for w in pol:
if w in vrag:
pol.remove(w)
... | 8 | PYTHON3 |
a = input().lstrip("0")
b = input().lstrip("0")
if a == "":
a = "0"
if b == "":
b = "0"
if len(a) > len(b):
print(">")
elif len(a) < len(b):
print("<")
else:
equal = True
for i in range(0,len(a)):
if int(a[i]) > int(b[i]):
equal = False
print(">")
br... | 7 | PYTHON3 |
import sys
def input():
return sys.stdin.readline().strip()
def ints():
return map(int, input().split())
def solve():
input()
k, n, m = ints()
a = list(ints())
b = list(ints())
i = j = 0
res = []
while i < len(a) or j < len(b):
if i < len(a) and a[i] == 0:
res.... | 9 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int T, n;
int num;
int main() {
ios_base::sync_with_stdio(0);
cout.tie(0);
cin.tie(0);
cin >> T;
while (T--) {
cin >> n;
deque<int> deq;
for (int i = 0; i < n; ++i) {
cin >> num;
deq.push_back(num);
}
int prev = -1, cnt = 0, a = 0, ... | 10 | CPP |
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
int n, cnt = 0, p[1000][1000];
bool check[1000];
cin >> n;
for (int i = 0; i < n; i++){
for(int j = 0; j < 3; j++){
cin >> p[i][j];
}
sort(p[i], p[i] + 3);... | 0 | CPP |
#include<bits/stdc++.h>
using namespace std;
struct RMQ{
static const int MAX_N = 1 << 17;
int n,dat[2*MAX_N-1];
RMQ(){}
RMQ(int n_){init(n_);}
void init(int n_){
n=1;
while(n<n_) n*=2;
for(int i=0;i<2*n-1;i++) dat[i]=INT_MAX;
}
void update(int k,int a){
k+=n-1;
dat[k]=a;
while(k>0... | 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
void solve() {}
long long findNumberOfDigits(long n, long long base) {
if (n == 0) return 1;
long long dig = (long long)(floor(log(n) / log(base)) + 1);
return dig;
}
void no() {
cout << 0 << '\n';
exit(0);
}
long long pows[50];
signed main() {
ios::sync_with_st... | 7 | CPP |
for _ in range(int(input())):
n=int(input())
d={}
for i in range(n):
a=input()
for j in a:
try:
d[j]+=1
except:
d[j]=1
k=0
for i in d.keys():
if d[i]%n==0:
pass
else:
k=1
break... | 7 | PYTHON3 |
import collections, heapq, bisect, math
def gcd(a, b):
if b == 0: return a
return gcd(b, a%b)
def solve(s, n):
count = 0
out = []
for i in range(0,len(s),2):
if s[i:i+2] == 'aa':
out.append('ab')
count += 1
elif s[i:i+2] == 'bb':
out.append('ab'... | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
constexpr long long INF = 1999999999999999997;
int main() {
ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
char a[n][n];
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++)... | 11 | CPP |
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<map>
#include<deque>
#include<cstring>
#include<climits>
#include<cassert>
#include<cctype>
#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
using namespace std;
int dx[] = {0,1};
int dy[] = {1,0};
struct Data {
i... | 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c;
int n;
cin >> n >> a >> b >> c;
if (n == 1) {
cout << "0" << endl;
} else if (n == 2) {
cout << min(a, b) << endl;
} else {
if (c >= a || c >= b) {
printf("%d\n", (n - 1) * min(a, b));
} else if (a >= c && b >= c) ... | 7 | CPP |
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())
f=e-a*(c-1)-b*(d-1)
if f<0:
f=0
if c>d:
g=d
h=b
j=c
else:
g=c
h=a
j=d
if e<g*h:
i=int(e/g)
else:
i=h+int((e-h*g)/j)
print(f)
print(i)
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
long long mod_plus(long long a, long long b) { return (a + b) % 1000000007; }
long long mod_mul(long long a, long long b) { return (a * b) % 1000000007; }
long long m[10], g[10];
long long go(char *second, int now) {
if (now < 0) return 0;
return mod_plus(m[second[now] ... | 9 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
for (int i = 0; i < s.size(); i++) {
if (s[i] == '9' || s[i] == 'H' || s[i] == 'Q') {
cout << "YES";
return 0;
}
}
cout << "NO";
}
| 7 | CPP |
def maximize_items_count(p, f, cnt_s, cnt_w, s, w):
if s > w or (s == w and cnt_s < cnt_w):
cnt_s, cnt_w = cnt_w, cnt_s
s, w = w, s
max_sum = 0
max_cnt_s = min(cnt_s, p // s + f // s)
p_cnt_s = 0
while p_cnt_s <= max_cnt_s:
p_cnt_w = (p - s * p_cnt_s) // w
f_cnt_w =... | 8 | PYTHON3 |
// -----Joy Baba Lokenath, Joy Maa Lokenath ,Joy Guru Lokenath, Joy Shiva Lokenath, Joy Brahma Lokenath----- //
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
#define ll long long int
#define vv vector
#define desc greater<int>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pb push_back
#defi... | 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long mult(long long a, long long b, long long p = 1000000007) {
return ((a % p) * (b % p)) % p;
}
long long add(long long a, long long b, long long p = 1000000007) {
return (a % p + b % p) % p;
}
long long fpow(long long n, long long k, long long p = 1000000007) {
... | 8 | CPP |
#include<iostream>
using namespace std;
int main()
{
int r,g,b,n,i,j;
long long dem=0;
cin >> r >> g >> b >> n;
for (i=0; i<=n/r; i++)
for (j=0; j<=(n-i*r)/g; j++)
if ((n-i*r-j*g)%b==0) dem++;
cout << dem;
return 0;
} | 0 | CPP |
n=int(input())
space=0
for i in range(n):
p,q=map(int,input().split())
if q-p >= 2:
space= space+1
print(space)
| 7 | PYTHON3 |
#include <bits/stdc++.h>
#pragma GCC target("avx")
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
using namespace std;
template <class code>
inline code read(const code &a) {
code x = 0;
short w = 0;
char ch = 0;
while (!isdigit(ch)) {
w |= ch == '-';
ch = getchar();
}
while (isdigit(ch)) {
... | 10 | CPP |
n=int(input())
a=[int(x) for x in input().split()]
pref=[0]
for item in a:
if item<0:
pref.append(pref[-1]+1)
else:
pref.append(pref[-1])
non=0
on=0
arr=0
for item in pref:
if item%2==0:
arr+=non
on+=1
else:
arr+=on
non+=1
print(arr,n*(n+1)//2-arr)
| 8 | PYTHON3 |
import io,os
from collections import deque
dev=0
if dev:
def read():
return input().strip()
else:
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
def read():
return input().decode()
t = int(read())
def solve():
n,m = map(int,read().split())
initial = list(map(int, read... | 9 | PYTHON3 |
def solve(l):
n = int(input())
#print(l[:n])
if n == 2:
print(2)
else:
#print(l[:n+1])
sum1, sum2 = l[n], 0
for i in range(1, n//2):
sum1 += l[i]
i = n // 2
while i < n:
sum2 += l[i]
i += 1
print(abs(sum1... | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
struct SegmentTree {
int data[maxn << 2], lz[maxn << 2];
int L[maxn << 2], R[maxn << 2];
void build(int l, int r, int k) {
L[k] = l;
R[k] = r;
lz[k] = 0;
if (l == r) {
... | 11 | CPP |
import sys
t = int(sys.stdin.readline())
while t:
s = sys.stdin.readline()
stack = []
count = 0
for e in s:
if e=='1':
if stack and stack[-1]=='0':
stack.pop()
count+=1
else:
stack.append(e)
elif e=='0':
... | 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, x, k, ans = 0;
cin >> n >> k;
if (n < 3) {
cout << 0;
return 0;
}
for (int i = 0; i < n; ++i) {
cin >> x;
if (5 - x >= k) ans++;
}
cout << ans / 3;
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
template <ostream& out = cout, class... T>
void prints(T&&...) {}
template <ostream& out = cout, class... T>
void printe(T&&...) {}
template <ostream& out = cout, class... T>
void printw(T&&...) {}
template <ostream& out = cout, class... T>
void printew(T&&...) {}
template ... | 7 | CPP |
#define _USE_MATH_DEFINES
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
using namespace std;
//typedef pair<long long int, long long int> P;
long long int INF = 1e18;
long long int MOD = 1e9 + 7;
i... | 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long bigmod(long long a, long long b, long long M) {
if (b == 0) return 1 % M;
long long x = bigmod(a, b / 2, M);
x = (x * x) % M;
if (b % 2 == 1) x = (x * a) % M;
return x;
}
int main() {
long long n, m;
cin >> n >> m;
if (n == 0)
cout << "0" << en... | 9 | CPP |
"""
Author: Sagar Pandey
"""
# ---------------------------------------------------Import Libraries---------------------------------------------------
import sys
import time
import os
from math import sqrt, log, log2, ceil, log10, gcd, floor, pow, sin, cos, tan, pi, inf, factorial
from copy import copy, deepcopy
fr... | 7 | PYTHON3 |
I = lambda: [int(i) for i in input().split()]
n,t = I()
a = []
a = I()
c=0
while c<(t-1):
c = c+a[c]
if(c>=t):
print("NO")
else:
print("YES") | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, c = 0, i, ans = 0;
scanf("%d", &n);
int a[n];
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
for (i = 0; i < n; i++) {
if (i == 0) {
if (a[1] == 2) {
c++;
}
} else if (i == n - 1 && a[n - 2] == 999) {
c+... | 7 | CPP |
n,m=map(int,input().split())
b=list(map(int,input().split()))
g=list(map(int,input().split()))
if(min(g)<max(b)):
print(-1)
exit(0)
from collections import *
from heapq import *
ans=[]
al=defaultdict(int)
for i in range(len(g)):
heappush(ans,-g[i])
al[g[i]]+=1
total=sum(b)*len(g)
b.sort(reverse... | 9 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
long long int dp[4011][4011];
long long int b[2000000];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long int n;
cin >> n;
long long int a[n];
set<long long int> st;
for (int i = 0; i < n; i++) {
cin >> a[i];
st.insert(a[i]);
}
... | 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
void solve() {
int n;
string s;
cin >> n >> s;
vector<int> last[2];
vector<int> ans(n);
int now = 0;
for (int i = 0; i < n; i++) {
int cur = s[i] - '0';
if (last[cur ^ 1].empty()) {
ans[i] = ++now;
... | 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
long long l[100005], le[100005];
vector<int> Div[100005];
long long tedad[100005], contain[100005];
long long t(long long a, int b) {
if (b == 0) return 1;
long long ans = t(a, b / 2);
ans = (ans * ans) % 1000000007;
if (b % 2 == 1) ans = (ans * a) % 1000000007;
r... | 11 | CPP |
#include<iostream>
#include<algorithm>
#define int long long
using namespace std;
int n, a[1010], q, b, e, k;
signed main() {
cin >> n; for (int i = 0; i < n; i++)cin >> a[i];
cin >> q;
for (int i = 0; i < q; i++) {
cin >> k >> b >> e;
int ans = a[b];
for (int j = b + 1; j < e; j++)if (!k)ans = min(ans, a[j]);... | 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int maxn=1e5+5;
const int N = 1e3+5;
int n,d,a[maxn];
double lg[N],nw[11],go[11];
pair<int,int>to[maxn][11];
double dp[maxn][11];
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
for(int i = 1;i <= 1000;i++) lg[i] = log10(i);
cin >> ... | 10 | CPP |
"""
Author : co_devil Chirag Garg
Institute : JIIT
"""
from __future__ import division, print_function
from sys import stdin, stdout
import itertools, os, sys, threading
from collections import deque, Counter, OrderedDict, defaultdict
import heapq
from math import ceil, floor, log, sqrt, factorial, pow, pi, gcd
# fr... | 8 | PYTHON3 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.