solution
stringlengths 10
983k
| difficulty
int64 0
25
| language
stringclasses 2
values |
---|---|---|
__author__ = 'ysyh'
numberBlocks = 0
lenBlocks = 0
heiBlocks = 0
line = input()
x = line.split(' ')
length = int(x[0])
height = int(x[1])
blockParameters = int(x[2])
# length = int(input())
# height = int(input())
# blockParameters = int(input())
# length, height, blockParameters = int(input(" "))
lenBlocks = length / blockParameters
if lenBlocks - int(lenBlocks) > 0:
lenBlocks = int(lenBlocks + 1)
heiBlocks = height / blockParameters
if heiBlocks - int(heiBlocks) > 0:
heiBlocks = int(heiBlocks + 1)
numberBlocks = int(heiBlocks * lenBlocks)
print(numberBlocks)
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, i, co = 0, j, ma = 1, g, k;
cin >> n;
long long s[n], d[100004];
memset(d, 0, sizeof(d));
for (i = 0; i < n; i++) {
cin >> s[i];
d[s[i]]++;
}
for (i = 2; i <= 100000; i++) {
co = 0;
for (j = i; j <= 100000; j += i) {
co += d[j];
}
ma = max(ma, co);
}
cout << ma;
return 0;
}
| 8 | CPP |
def get_int(string, n):
i = j = k = 0
for s in string:
k += 1
for s in string:
if i == n - 1:
break
if s == ' ':
i += 1
j += 1
i = 0
while j < k:
if string[j] == ' ':
break
i = 10 * i + int(string[j])
j += 1
return i
x = input()
a = get_int(x, 1)
b = get_int(x, 2)
c = get_int(x, 3)
n = -1
for i in range(1, 10000):
a *= 10
if (a // b) % 10 == c:
n = i
break
print(n) | 8 | PYTHON3 |
n=int(input(''))
a=list(map(int, input().split()))
b=[]
ce=0
co=0
cnt=0
if n==1:
print('1')
elif (n>2):
for i in range(1,n+1):
if i%2==0:
ce=ce+a[i-1]
b.append([ce,co])
else:
co=co+a[i-1]
b.append([ce,co])
for i in range(1,n-1):
if b[-1][0]-b[i][0]+b[i-1][1] == b[-1][1]-b[i][1]+b[i-1][0]:
cnt+=1
if b[-1][0]-b[0][0]==b[-1][1]-b[0][1]:
cnt+=1
if b[-2][0]==b[-2][1]:
cnt+=1
print(cnt)
else:
print('0')
| 8 | PYTHON3 |
e, p, q = {}, {}, {}
def upd(x, y):
e[x] = e.get(x, 0) + 1
if y < p.get(x, 100):
q[x] = p.get(x, 100)
p[x] = y
elif y < q.get(x, 100):
q[x] = y
n = int(input())
for x in map(int, input().split()):
d = 2
while d * d <= x:
if 0 == x % d:
c = 0
while 0 == x % d:
x //= d
c += 1
upd(d, c)
d += 1
if x > 1:
upd(x, 1)
ans = 1
for k, v in e.items():
if v == n:
for _ in range(q[k]):
ans *= k
elif v == n - 1:
for _ in range(p[k]):
ans *= k
print(ans)
| 7 | PYTHON3 |
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
mark=[0]*(n+1)
cnt1=0
cnt2=0
while cnt2<n:
if mark[b[cnt2]]==1:
print(0,end=" ")
else:
count=1
while True :
if a[cnt1]==b[cnt2]:
mark[b[cnt2]]=1
cnt1+=1
print(count,end=" ")
break
else:
mark[a[cnt1]]=1
count+=1
cnt1+=1
cnt2+=1
| 8 | PYTHON3 |
import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int, input().split()))
prev = a[n-1]
idx = n-1
flag = False
for i in range(n-2, -1, -1):
if a[i] > prev:
if flag:
break
else:
idx = i
elif a[i] == prev:
idx = i
elif a[i] < prev:
flag = True
idx = i
prev = a[i]
print(idx) | 9 | PYTHON3 |
#include <vector>
#include <utility>
#include <stdio.h>
#include <string.h>
using namespace std;
typedef pair<int,int> pi;
#define F first
#define S second
#define MP make_pair
#define PB push_back
const int N=1e3+10;
int a[N*4],flag[N*4];
void add(int n,int x,int l,int r,int L,int R){
if(L<=l&&r<=R){
a[n]+=x;
flag[n]+=x;
}
else if(!(L>r||l>R)){
int mid=(l+r)>>1;
if(flag[n]!=0){
flag[n*2+2]+=flag[n];
flag[n*2+1]+=flag[n];
a[n*2+2]+=flag[n];
a[n*2+1]+=flag[n];
flag[n]=0;
}
add(n*2+1,x,l,mid,L,R);
add(n*2+2,x,mid+1,r,L,R);
a[n]=max(a[n*2+1],a[n*2+2]);
}
return ;
}
int main(){
int n,x1,x2,y1,y2,ans=0;
vector<pi> l[N],r[N];
scanf("%d",&n);
memset(a,0,sizeof(a));
memset(flag,0,sizeof(flag));
for(int i=0;i<n;i++){
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
l[y1].PB({x1+1,x2});
r[y2].PB({x1+1,x2});
}
for(int i=0;i<N;i++){
for(auto u:l[i])add(0,1,0,N-1,u.F,u.S);
for(auto u:r[i])add(0,-1,0,N-1,u.F,u.S);
ans=max(ans,a[0]);
}
printf("%d\n",ans);
}
| 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
int a[maxn], f[maxn];
bool vis[10000005];
int main() {
int n;
while (~scanf("%d", &n)) {
int ans = 0;
for (int i = 0; i < (n); i++) {
scanf("%d", a + i);
if (!vis[a[i]]) vis[a[i]] = 1, ans++;
for (int j = 0; j < (21); j++) {
if (a[i] & (1 << j)) {
int tmp = a[i];
for (int k = i - 1; k >= 0 && !(a[k] & (1 << j)); k--) {
tmp |= a[k];
if (!vis[tmp]) {
vis[tmp] = 1;
ans++;
}
}
}
}
}
printf("%d\n", ans);
}
return 0;
}
| 7 | CPP |
//27
#include<iostream>
#include<algorithm>
#include<cstdlib>
using namespace std;
int main(){
int n,m,k;
cin>>n>>m>>k;
int t[3001];
fill(t,t+3001,1<<29);
int a[100000][2],l[100000];
for(int i=0;i<m;i++){
cin>>a[i][0]>>a[i][1]>>l[i];
}
for(int i=0;i<k;i++){
int s;
cin>>s;
t[s]=0;
}
for(int o=0;o<n;o++){
for(int i=0;i<m;i++){
for(int j=0;j<2;j++){
t[a[i][j]]=min(t[a[i][j]],t[a[i][!j]]+l[i]);
}
}
}
int ll=0;
for(int i=0;i<m;i++){
ll=max(ll,(l[i]-abs(t[a[i][0]]-t[a[i][1]])+1)/2+max(t[a[i][0]],t[a[i][1]]));
}
cout<<ll<<endl;
return 0;
} | 0 | CPP |
#include<iostream>
#include<string>
using namespace std;
int main(){
string s;
cin>>s;
long long cnt=0;
long long sum=0;
for(int i=0;i<s.length();i++){
if(s[i]=='W')
sum+=(i-cnt),cnt++;
}
cout<<sum<<endl;
} | 0 | CPP |
t = int(input())
while(t):
n,x = [int(a) for a in input().split()]
l = [int(b) for b in input().split()]
v = 0
i =1
while True:
if(not i in l):
l.append(i)
v+=1
if(v==x):
break
i += 1
i = 0
l = set(l)
m = max(l)+1
for j in range(1,m):
if(j in l):
i += 1
else:
break
print(i)
t -=1 | 7 | PYTHON3 |
#include <bits/stdc++.h>
int main() {
int n;
scanf("%d", &n);
int m;
printf("%d\n", m = (int)(sqrt(8 * n + 1) - 1) / 2);
int s = 0;
for (int i = 1; i < m; ++i) {
s += i;
printf("%d ", i);
}
if (n = n - s) printf("%d", n);
}
| 7 | CPP |
n, c = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
limak = 0
radewoosh = 0
d = b[-1]
for i in range(n):
limak += max(0, a[i] - c * sum(b[0:i + 1]))
for j in range(1, i + 1):
d += b[n - 1 - i]
radewoosh += max(0, a[n - 1 - i] - c * d)
if limak > radewoosh:
print("Limak")
elif limak < radewoosh:
print("Radewoosh")
else:
print("Tie")
| 7 | PYTHON3 |
#1005B
s = list(input())
t = list(input())
s = s[::-1]
t = t[::-1]
a = len(s)
b = len(t)
count = 0
if a >= b:
for i in range(b):
if s[i] == t[i]:
count +=1
else:
break
else:
for i in range(a):
if s[i] == t[i]:
count += 1
else:
break
print(a + b - 2*count) | 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int N = 500005;
const int MAX = (int)1e7 + 5;
int n;
bitset<MAX> isPrime;
vector<int> primeList;
int ans1[N], ans2[N];
inline void Sieve() {
isPrime.set();
isPrime[0] = isPrime[1] = 0;
for (int i = 2; i < MAX; i++) {
if (isPrime[i]) {
primeList.push_back(i);
for (long long j = 1ll * i * i; j < MAX; j += i) {
isPrime[j] = 0;
}
}
}
}
int main() {
Sieve();
scanf("%d", &n);
for (int i = 0; i < n; i++) {
ans1[i] = ans2[i] = -1;
int x;
scanf("%d", &x);
if (!isPrime[x]) {
int root = (int)sqrt(x);
for (int j = 0; primeList[j] <= root; j++) {
int p = primeList[j];
if (x % p == 0) {
ans1[i] = 1;
while (x % p == 0) {
ans1[i] *= p;
x /= p;
}
if (x == 1) {
ans1[i] = ans2[i] = -1;
} else {
ans2[i] = x;
}
break;
}
}
}
}
for (int i = 0; i < n; i++) printf("%d%c", ans1[i], i == n - 1 ? '\n' : ' ');
for (int i = 0; i < n; i++) printf("%d%c", ans2[i], i == n - 1 ? '\n' : ' ');
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int Maxn = 55;
char s[Maxn][Maxn];
int n, m;
char ned[5] = "face";
bool check(int x, int y) {
vector<int> rep;
for (int i = 0; i < 2; i++)
for (int j = 0; j < 2; j++) rep.push_back(s[i + x][j + y]);
sort(rep.begin(), rep.end());
for (int i = 0; i < 4; i++)
if (rep[i] != ned[i]) return 0;
return 1;
}
int main() {
sort(ned, ned + 4);
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i++) scanf("%s", s[i]);
int ans = 0;
for (int i = 0; i < n - 1; i++)
for (int j = 0; j < m - 1; j++)
if (check(i, j)) ans++;
printf("%d\n", ans);
}
| 7 | CPP |
#include <bits/stdc++.h>
const long long inf = 1e18;
const int32_t M = 1e9 + 7;
const int32_t mxn = 1e6 + 1;
using namespace std;
template <typename T>
istream& operator>>(istream& in, vector<T>& a) {
for (auto& i : a) in >> i;
return in;
}
template <typename T>
ostream& operator<<(ostream& out, vector<T>& a) {
for (auto& i : a) out << i << "";
return out;
}
void solve() {
long long n;
cin >> n;
string s;
cin >> s;
long long i;
for (i = 0; i <= n * 9; ++i) {
long long c = 0;
long long it = 0;
for (auto ch : s) {
c += ch - '0';
if (c == i) {
it++;
c = 0;
}
}
if (c == 0 && it > 1) {
cout << "YES\n";
return;
}
}
cout << "NO\n";
}
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long t = 1;
while (t--) solve();
return 0;
}
| 9 | CPP |
c=0
z=0
n,k=map(int,input().split())
a=[int(i) for i in input().split()]
for g in range(n):
if a[g]>=a[k-1] and a[g]!=0:
c=c+1
elif a[g]>=a[k-1] and a[k-1]==0:
z+=1
if z==n:
print(0)
else:
print(c) | 7 | PYTHON3 |
l=input().split()
n=int(l[0])
m=int(l[1])
l=input().split()
li=[int(i) for i in l]
li.sort()
li.reverse()
if(sum(li)<m):
print(-1)
else:
ans=0
for i in range(1,n+1):
arr=list(li)
sumi=0
for j in range(n):
sumi+=max(arr[j]-(j//i),0)
if(sumi>=m):
ans=i
break
print(ans)
| 10 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int MOD = 1000000007;
int main() {
string str;
cin >> str;
int l = str.length();
int dp[l + 1];
dp[0] = 1;
dp[1] = 1;
if (str.find('w') != -1 || str.find('m') != -1) {
cout << 0 << endl;
return 0;
}
for (int i = 2; i <= l; i++) {
if (str[i - 1] == str[i - 2] && (str[i - 1] == 'u' || str[i - 1] == 'n'))
dp[i] = (dp[i - 1] + dp[i - 2]) % MOD;
else
dp[i] = dp[i - 1];
}
cout << dp[l] << endl;
return 0;
}
| 9 | CPP |
N=int(input())
S=[input() for i in range(N)]
judge=["AC","WA","TLE","RE"]
for j in judge:
print("{0} x {1}".format(j,S.count(j))) | 0 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200000 + 5;
const int sz = 26;
struct suffix_automaton {
int tot, last, ch[2 * maxn][sz], fa[2 * maxn], len[2 * maxn];
int sum[2 * maxn], tp[2 * maxn], cnt[2 * maxn];
void init() {
last = tot = 1;
len[1] = 0;
memset(ch[1], 0, sizeof ch[1]);
memset(cnt, 0, sizeof cnt);
}
void add(int x, int fg) {
int p = last, np = last = ++tot;
len[np] = len[p] + 1;
if (fg)
cnt[last] = 0;
else
cnt[last] = 1;
memset(ch[np], 0, sizeof ch[np]);
while (p && !ch[p][x]) ch[p][x] = np, p = fa[p];
if (p == 0)
fa[np] = 1;
else {
int q = ch[p][x];
if (len[q] == len[p] + 1)
fa[np] = q;
else {
int nq = ++tot;
memcpy(ch[nq], ch[q], sizeof ch[q]);
len[nq] = len[p] + 1, fa[nq] = fa[q], fa[q] = fa[np] = nq;
while (p && ch[p][x] == q) ch[p][x] = nq, p = fa[p];
}
}
}
void toposort() {
for (int i = 1; i <= len[last]; i++) sum[i] = 0;
for (int i = 1; i <= tot; i++) sum[len[i]]++;
for (int i = 1; i <= len[last]; i++) sum[i] += sum[i - 1];
for (int i = 1; i <= tot; i++) tp[sum[len[i]]--] = i;
for (int i = tot; i; i--) cnt[fa[tp[i]]] += cnt[tp[i]];
}
};
suffix_automaton sam;
int n;
char s[maxn], t[maxn];
int main() {
scanf("%d", &n);
scanf("%s%s", s, t);
sam.init();
for (int i = 0; i < n; i++) sam.add(s[i] - 'a', t[i] - '0');
sam.toposort();
long long ans = 0;
for (int i = sam.tot; i; i--)
ans = max(ans, (long long)sam.len[i] * sam.cnt[i]);
printf("%lld\n", ans);
return 0;
}
| 12 | CPP |
#include<iostream>
#include<string>
using namespace std;
int main(void)
{
string set;
int joi=0;
int ioi=0;
for (int a=0;a<5;a++)
{
cin>>set;
int b=set.size();
for (int c=0;c<b-2;c++)
{
if (set.substr(c,3)=="JOI") joi++;
if (set.substr(c,3)=="IOI") ioi++;
}
cout<<joi<<endl<<ioi<<endl;
joi=0;
ioi=0;
}
return 0;
} | 0 | CPP |
n, x = map(int, input().split())
v = [int(i) for i in input().split()]
cont = [0] * 200
for i in v:
cont[i] += 1
res = 0
for i in range(x):
if cont[i] == 0:
res += 1
if cont[x] == 1:
res += 1
print(res) | 7 | PYTHON3 |
# http://codeforces.com/problemset/problem/735/C
def main():
num = int(input())
num1 = 1
num2 = 2
tmp = 0
cont = 0
while tmp <= num:
tmp = num1 + num2
num1 = num2
num2 = tmp
cont += 1
print(cont)
main() | 9 | PYTHON3 |
def num(n):
resultado="";
x=0
for i in range(n):
x=input()
if x is "1":
resultado="-1"
print(resultado)
elif x in nums:
resultado=nums[x]
print(resultado)
else:
resultado="2"+"3"*(int(x)-1)
print(resultado)
nums[x]=resultado
nums={}
num(int(input())) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
long K;
cin>>s>>K;
long n=s.size();
string ans="";
for(int i=0;i<n;i++){
if(K>=('z'-s[i]+1)&&s[i]!='a'){
K-=int('z'-s[i]+1);
s[i]='a';
}
}
s[n-1]+=K%26;
//cout<<K<<endl;
cout<<s<<endl;
}
| 0 | CPP |
k2,k3,k5,k6 = map(int,input().split())
s = 0
m1 = min(k2,k5,k6)
s += 256*m1
k2,k5,k6 = k2-m1,k5-m1,k6-m1
m1 = min(k2,k3)
s += 32*m1
k2,k3 = k2-m1,k3-m1
print(s) | 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
double pi = 3.14159265359;
bool isPrime(int i) {
if (i == 2) {
return true;
}
if (i % 2 == 0) {
return false;
}
for (int j = 3; j < sqrt(i) + 1; j += 2) {
if (i % j == 0) {
return false;
}
}
return true;
}
int main() {
cin.tie(0);
ios_base::sync_with_stdio(0);
int n, k;
cin >> n >> k;
string s;
cin >> s;
vector<pair<int, int>> t;
for (int i = 1; i < n; ++i) {
if (s[i - 1] == '4' && s[i] == '7' && k > 0) {
if (i % 2 == 1) {
s[i] = '4';
} else {
s[i - 1] = '7';
}
if (s[i] == '4' && s[i + 1] == '7') {
if (k % 2 == 0 && k != 1) {
s[i] = '7';
}
break;
}
if (s[i - 1] == '7' && s[i - 2] == '4') {
if (k % 2 == 0 && k != 1) {
s[i - 1] = '4';
}
break;
}
k--;
}
}
for (int i = 0; i < n; ++i) {
cout << s[i];
}
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1000000000000000000;
int per[6][3] = {{0, 1, 2}, {0, 2, 1}, {1, 0, 2},
{1, 2, 0}, {2, 0, 1}, {2, 1, 0}};
vector<vector<int> > P(8, vector<int>(3));
vector<vector<int> > p(8, vector<int>(3));
bool Orto(vector<int>& a, vector<int>& b, vector<int>& c) {
long long ska = 0;
for (int i = 0; i < 3; ++i)
ska += (long long)(b[i] - a[i]) * (long long)(c[i] - a[i]);
return (ska == 0);
}
long long Dl(vector<int>& a, vector<int>& b) {
long long d = 0;
for (int i = 0; i < 3; ++i)
d += (long long)(a[i] - b[i]) * (long long)(a[i] - b[i]);
return d;
}
void Spr() {
long long D = INF;
for (int i = 0; i < 8; ++i)
for (int j = i + 1; j < 8; ++j) D = min(D, Dl(p[i], p[j]));
for (int i = 0; i < 8; ++i) {
vector<int> nr;
for (int j = 0; j < 8; ++j)
if (Dl(p[i], p[j]) == D) nr.push_back(j);
if (!(nr.size() == 3 && Orto(p[i], p[nr[0]], p[nr[1]]) &&
Orto(p[i], p[nr[0]], p[nr[2]]) && Orto(p[i], p[nr[1]], p[nr[2]])))
return;
}
cout << "YES" << endl;
for (int i = 0; i < 8; ++i) {
for (int j = 0; j < 3; ++j) cout << p[i][j] << " ";
cout << endl;
}
exit(0);
}
void gen(int nr, int x) {
for (int i = 0; i < 3; ++i) p[nr][i] = P[nr][per[x][i]];
if (nr == 7) {
Spr();
return;
}
for (int i = 0; i < 6; ++i) gen(nr + 1, i);
}
int main() {
ios_base::sync_with_stdio(0);
for (int i = 0; i < 8; ++i)
for (int j = 0; j < 3; ++j) cin >> P[i][j];
for (int i = 0; i < 6; ++i) gen(0, i);
cout << "NO";
return 0;
}
| 8 | CPP |
n=int(input())
sa=set()
sb=set()
l=[]
for i in range(n*n):
a,b=map(int,input().split())
if not(a in sa) and not(b in sb):
l+=[str(i+1)]
sa.add(a)
sb.add(b)
print(' '.join(l))
| 7 | PYTHON3 |
def warshall_floyd():
inf=float("inf")
v,e=map(int,input().split())
#頂点集合、始点、終点
dp=[[[inf]*v for i in range(v)] for j in range(v+1)]
#initialize
for i in range(v):
dp[0][i][i]=0
for _ in range(e):
s,t,d=map(int,input().split())
dp[0][s][t]=d
for i in range(1,v+1):
for j in range(v):
for k in range(v):
dp[i][j][k]=min(dp[i-1][j][k],dp[i-1][j][i-1]+dp[i-1][i-1][k])
#負閉路判定
for i in range(v):
if dp[v][i][i]<0 :
print("NEGATIVE CYCLE")
return None
for i in range(v):
print(" ".join(["INF" if x ==inf else str(x) for x in dp[v][i]]))
warshall_floyd()
| 0 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int N = (int)1e5 + 10;
int a[N];
vector<int> v[N];
long long all;
void update(long long &best, int pos) {
if ((int)v[pos].size() == 0) return;
long long temp = all;
int i, j;
for (i = 0; i < (int)v[pos].size(); i++) temp -= abs(pos - v[pos][i]);
int l = (int)v[pos].size();
int cur = v[pos][l / 2];
for (i = 0; i < (int)v[pos].size(); i++) temp += abs(cur - v[pos][i]);
if (temp < best) best = temp;
}
int main() {
int i, j;
int n, m;
cin >> n >> m;
for (i = 1; i <= m; i++) scanf(" %d", a + i);
long long best = 0;
for (i = 1; i < m; i++) best += (long long)abs(a[i + 1] - a[i]);
for (i = 1; i < m; i++)
if (a[i] != a[i + 1]) {
v[a[i + 1]].push_back(a[i]);
v[a[i]].push_back(a[i + 1]);
}
all = best;
for (i = 1; i <= n; i++) sort(v[i].begin(), v[i].end());
for (i = 1; i <= n; i++) update(best, i);
cout << best << endl;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m;
string first[3000], second[3000], temp;
cin >> n >> m;
for (int i = 0; i < m; i++) {
cin >> first[i] >> second[i];
if (first[i].size() > second[i].size()) {
temp = second[i];
second[i] = first[i];
first[i] = temp;
}
}
for (int i = 0; i < n; i++) {
cin >> temp;
for (int j = 0; j < m; j++)
if (temp == second[j]) temp = first[j];
cout << temp << ' ';
}
return 0;
}
| 8 | CPP |
import sys
import math
from collections import defaultdict,deque
input = sys.stdin.readline
def inar():
return [int(el) for el in input().split()]
def main():
t=int(input())
for _ in range(t):
n,k=inar()
arr=list(input().strip())
ans=0
ind=[]
for i in range(n):
if arr[i]=="W":
ind.append(i)
tup=[]
for i in range(1,len(ind)):
el1=ind[i-1]
el2=ind[i]
t=el2-el1-1
tup.append([t,el1,el2])
tup.sort()
# print(tup)
for i in range(len(tup)):
start=tup[i][1]
end=tup[i][2]
for j in range(start+1,end):
if k==0:
break
if arr[j]=="L":
k-=1
arr[j]="W"
if k==0:
break
if k>0:
if len(ind)==0:
for i in range(n):
if k == 0:
break
if arr[i] == "L":
k -= 1
arr[i] = "W"
else:
for i in range(ind[0]-1,-1,-1):
if k==0:
break
if arr[i]=="L":
k-=1
arr[i]="W"
for i in range(ind[-1]+1,n):
if k==0:
break
if arr[i]=="L":
k-=1
arr[i]="W"
temp=0
for i in range(n):
if arr[i]=="W":
ans+=temp+1
if temp==0:
temp=1
else:
temp=0
print(ans)
if __name__ == '__main__':
main()
| 8 | PYTHON3 |
import sys
n, k = sys.stdin.readline().split()
n = int(n)
k = int(k)
l = 0
r = n
while l < r:
m = int((l + r)/2)
if ((n - m)*(n - m + 1)/2 - m == k):
print(m)
break
if (n - m)*(n - m + 1)/2 - m > k:
l = m
else:
r = m
| 8 | PYTHON3 |
S = input()
ans = 0
for c in S:
if c == '1':
ans += 1
print(ans) | 0 | PYTHON3 |
s = input()
x = "hello"
j = 0
i = 0
p = len(s)
result = 0
while True:
if i ==p or j==len(x):
break
if s[i]==x[j]:
j+=1
result+=1
i+=1
if result==5:
print("YES")
else:
print("NO") | 7 | PYTHON3 |
import math
q=int(input())
for _ in range(q):
n=int(input())
l=list(map(int,input().split()))
l.sort()
l=list(set(l))
#print(l)
team=1
for i in range(len(l)-1):
if (abs(l[i]-l[i+1])==1):
team=team+1
break
print(team) | 7 | PYTHON3 |
import string
pattern=string.ascii_letters+'0123456789'
t=int(input())
for _ in range(t):
r,c,k=map(int,input().split())
grid=[]
for i in range(r):
grid+=[list(map(str,input().strip()))]
l=[]
countr=0
#print(grid)
for strip in grid:
for element in strip:
if(element=='R'):
#print(element)
countr+=1
for i in range(k):
if(countr%k>i):
l+=[countr//k+1]
else:
l+=[countr//k]
ans=[[0 for i in range(c)] for j in range(r)]
now=0
for i in range(r):
if(i%2==0):
for j in range(c-1,-1,-1):
if(grid[i][j]=='R'):
if(l[now]==0):
now+=1
l[now]-=1
ans[i][j]=pattern[now]
else:
for j in range(c):
if(grid[i][j]=='R'):
if(l[now]==0):
now+=1
l[now]-=1
ans[i][j]=pattern[now]
#print(countr)
#print(l)
for i in ans:
print(''.join(i)) | 10 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int n, m, dx, dy, yVal[1000100], ans[1000100];
vector<pair<int, int> > apples;
int main() {
ios::sync_with_stdio(false);
cin >> n >> m >> dx >> dy;
for (int i = 0; i < m; i++) {
int t1, t2;
cin >> t1 >> t2;
apples.push_back({t1, t2});
}
memset(yVal, 0, sizeof yVal);
memset(ans, 0, sizeof ans);
int x = 0, y = 0;
for (int i = 0; i < n; i++) {
x += dx;
x %= n;
y += dy;
y %= n;
yVal[x] = y;
}
for (auto pt : apples) {
x = pt.first, y = pt.second;
ans[(y - yVal[x] + n) % n]++;
}
int mx = 0, mxi = 0;
for (int i = 0; i < n; i++) {
if (ans[i] >= mx) {
mx = ans[i];
mxi = i;
}
}
cout << 0 << " " << mxi << "\n";
}
| 11 | CPP |
import sys
import math
n,k=map(int,input().split())
smra=[int(x) for x in input().strip().split()]
ones=smra.count(1)
minsu=n-ones
op=0
maxd=-1e9
for op in range(k):
a, s = 0,0
#print("op=",op)
for i in range(op,n,k):
#print("i=",i)
if(smra[i]==1):
a+=1
else:
s+=1
maxd=max((abs((ones-a)-(minsu-s)),maxd))
print(maxd) | 7 | PYTHON3 |
sx,sy,tx,ty = map(int, input().split())
dx = tx-sx
dy = ty-sy
a = dx*'R'+dy*'U'+dx*'L'+dy*'D'
b = 'D'+(dx+1)*'R'+(dy+1)*'U'+'L'+'U'+(dx+1)*'L'+(dy+1)*'D'+'R'
print(a+b)
| 0 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 2;
const int maxx = 1e13;
const int mod1 = 1000000007;
const int mod = 998244353;
const int base = 31;
template <class T>
void read(T& x) {
register int c;
T neg = 1;
x = (T)0;
while ((c = getchar()) <= 47 || c >= 58)
if (c == '-') neg = -1;
for (; (c > 47 && c < 58); c = getchar()) {
x = (x << 3) + (x << 1) + (T)(c - 48);
}
x *= neg;
}
struct tk {
int u;
int v;
int w;
};
bool lf(tk& a, tk& b) { return a.w <= b.w; }
int dp[maxn];
int n, m;
tk a[maxn];
vector<pair<int, int> > vt;
int mx = 0;
vector<pair<int, int> > wt[maxn];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
read(n);
read(m);
for (int i = 1; i <= m; i++) {
read(a[i].u);
read(a[i].v);
read(a[i].w);
wt[a[i].w].push_back(make_pair(a[i].u, a[i].v));
}
for (int i = 1; i <= n; i++) dp[i] = 0;
for (int i = 0; i < maxn; i++) {
vt.clear();
for (int j = 0; j < wt[i].size(); j++) {
auto p = wt[i][j];
vt.push_back(make_pair(p.second, dp[p.first] + 1));
}
for (auto p : vt) {
dp[p.first] = max(dp[p.first], p.second);
}
}
for (int i = 1; i <= n; i++) {
mx = max(mx, dp[i]);
}
cout << mx;
return 0;
}
| 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
vector<int> X[100005];
int main() {
ios::sync_with_stdio(0);
cin.tie(NULL), cout.tie(NULL);
int N;
cin >> N;
for (int i = 1; i <= N - 1; i++) {
int u, v;
cin >> u >> v;
X[u].push_back(v);
X[v].push_back(u);
}
int leaves = 0, connectors = 0;
for (int i = 1; i <= N; i++) connectors += (X[i].size() == 2);
if (connectors == 0)
cout << "YES\n";
else
cout << "NO\n";
return 0;
}
| 7 | CPP |
I=lambda:map(int,input().split())
H,W=I()
h,w=I()
print(H*W-h*W-H*w+h*w) | 0 | PYTHON3 |
if __name__ == '__main__':
numbers = list(map(int, input().split()))
n = numbers[0]
m = numbers[1]
s = input()
t = input()
if n > m + 1:
print("NO")
elif n == 1 and n == m and s != "*" and s != t:
print("NO")
elif n == m and s == "*":
print("YES")
elif n == m and s == t:
print("YES")
else:
newS = s.split('*')
if len(newS) == 1:
if newS[0] == t:
print("YES")
elif n == m and t[0: len(newS[0])] == newS[0]:
print("YES")
else:
print("NO")
else:
lenSt = len(newS[0])
lenDr = len(newS[1])
# print(lenDr)
# print(lenSt)
# print(newS[0])
# print(newS[1])
if t[0:lenSt] == newS[0] and t[-lenDr:] == newS[1]:
print("YES")
elif t[0:lenSt] == newS[0] and lenDr == 0:
print("YES")
elif n == m and lenDr == 0 and t[0:lenSt - 1] == newS[0]:
print("YES")
else:
print("NO")
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int dp[510][510];
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;
}
int main() {
int n, k;
scanf("%d%d", &n, &k);
for (int i = 0; i <= n; i++) {
for (int j = 1; j <= n; j++) {
if (i == 0) {
dp[i][j] = 2;
continue;
}
for (int t = 1; t <= min(i, j); t++) {
dp[i][j] += dp[i - t][j];
if (dp[i][j] >= 998244353) dp[i][j] -= 998244353;
}
}
}
int ans = 0;
for (int i = 1; i <= n; i++) {
ans += (long long)(dp[n][i] - dp[n][i - 1]) * dp[n][min(n, (k - 1) / i)] %
998244353;
ans = (ans % 998244353 + 998244353) % 998244353;
}
ans = (long long)ans * power(2, 998244353 - 2, 998244353) % 998244353;
printf("%d\n", ans);
return 0;
}
| 11 | CPP |
x,y= map(int,input().split())
if(x<len(str(y))):
print("-1")
else:
print("{}{}".format(y,"0"*(x-len(str(y))))) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
struct M {
unsigned long long int s[35][35], n;
friend M operator*(M a, M b) {
M c;
c.n = a.n;
int i, j, k;
for (i = 0; i < a.n; i++) {
for (j = 0; j < a.n; j++) {
c.s[i][j] = 0;
for (k = 0; k < a.n; k++) {
c.s[i][j] += a.s[i][k] * b.s[k][j];
c.s[i][j] %= 1000000007;
}
}
}
return c;
}
} bi[65][65], I;
int main() {
unsigned long long int n, m, t, x, y, z, add;
int i, j, k;
scanf("%llu%llu", &n, &m);
bi[0][0].n = m + 1;
for (i = 0; i <= m; i++) {
bi[0][0].s[i][i] = 1;
bi[0][0].s[0][i] = 1;
}
x = 0, y = 1, z = 0, add = 0;
while (y * m <= n) {
y *= m;
x++;
}
for (t = 0; t <= x; t++) {
if (t) {
bi[t][0] = bi[t - 1][0];
for (i = 1; i < m; i++) {
bi[t][0] = bi[t][0] * bi[t - 1][i];
}
}
for (i = 1; i < m; i++) {
bi[t][i] = bi[t][i - 1];
for (j = m - 2; j >= 0; j--) {
for (k = 0; k <= m; k++) {
swap(bi[t][i].s[j][k], bi[t][i].s[j + 1][k]);
}
}
for (j = m - 2; j >= 0; j--) {
for (k = 0; k <= m; k++) {
swap(bi[t][i].s[k][j], bi[t][i].s[k][j + 1]);
}
}
}
}
for (i = 0; i <= m; i++) {
I.n = m + 1;
I.s[i][i] = 1;
}
while (add < n) {
if (add <= n - y) {
add += y;
I = I * bi[x][z];
z = (z + 1) % m;
} else {
y /= m;
x--;
}
}
unsigned long long int ans = 0;
for (i = 0; i <= m; i++) {
ans = (ans + I.s[i][m]) % 1000000007;
}
printf("%llu\n", ans);
}
| 11 | CPP |
n = input()
a = []
for i in range(len(n)):
if n[i] not in a:
a.append(n[i])
if len(a)%2 == 0:
print('CHAT WITH HER!')
else:
print('IGNORE HIM!') | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
int *arr = new int[n];
for (int i = 0; i < n; i++) cin >> arr[i];
int j, k;
for (int i = 0; i < n; i++) {
if (arr[i] == 1) {
j = i;
break;
}
}
for (int i = n - 1; i >= 0; i--) {
if (arr[i] == 1) {
k = i;
break;
}
}
int ans = 0;
for (int i = j; i <= k; i++) {
if (arr[i] == 0) ans++;
}
cout << ans << endl;
}
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
void swap(long long &x, long long &y) {
long long temp = x;
x = y;
y = temp;
}
void google(long long t) { cout << "Case #" << t << ": "; }
long long mod_add(long long a, long long b, long long m) {
a = a % m;
b = b % m;
return (((a + b) % m) + m) % m;
}
long long mod_mul(long long a, long long b, long long m) {
a = a % m;
b = b % m;
return (((a * b) % m) + m) % m;
}
long long mod_sub(long long a, long long b, long long m) {
a = a % m;
b = b % m;
return (((a - b) % m) + m) % m;
}
long long expom(long long x, long long y, long long m) {
if (y == 0) return 1;
x = x % m;
if (y % 2 == 0) return expom(x * x, y / 2, m) % m;
return (x * expom(x * x, y / 2, m)) % m;
}
inline long long gcd(long long a, long long b) {
return b == 0 ? a : gcd(b, a % b);
}
inline long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
inline long long ceil(long long a, long long b) {
return (a % b == 0) ? a / b : a / b + 1;
}
long long dx[] = {1, 0, -1, 0};
long long dy[] = {0, 1, 0, -1};
vector<long long> pri(200000 + 6);
void prime_factorization_sieve() {
pri[1] = 1;
for (long long i = 2; i <= 200000 + 5; i++) {
pri[i] = -1;
}
for (long long i = 2; i <= 200000 + 5; i++) {
if (pri[i] == -1) {
for (long long j = i; j <= 200000 + 5; j += i) {
if (pri[j] == -1) pri[j] = i;
}
}
}
}
vector<long long> get_factors(long long n) {
vector<long long> res;
while (pri[n] != 1) {
res.push_back(pri[n]);
n = n / pri[n];
}
return res;
}
void solve() {
long long n, k;
cin >> n >> k;
vector<long long> arr(n + 1);
for (long long i = 1; i <= n; i++) cin >> arr[i];
long long ans = INT_MIN;
long long x = (n >= 300) ? n - 300 : n;
if (n >= 300) {
for (long long i = x + 1; i <= n; i++) {
for (long long j = 1; j <= n; j++) {
if (i != j) {
ans = ((ans) < (i * j - k * (arr[i] | arr[j]))
? (i * j - k * (arr[i] | arr[j]))
: (ans));
}
}
}
} else {
for (long long i = 1; i <= x; i++) {
for (long long j = 1; j <= n; j++) {
if (i != j) {
ans = ((ans) < (i * j - k * (arr[i] | arr[j]))
? (i * j - k * (arr[i] | arr[j]))
: (ans));
}
}
}
}
cout << ans << "\n";
}
signed main() {
ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
long long t = 1;
cin >> t;
while (t--) {
solve();
}
return 0;
}
| 8 | CPP |
for _ in range(int(input())):
a,b,n = map(int,input().split())
s = [0]*200
s[0] = min(a,b)
s[1] = max(b,a)
for i in range(2,101):
s[i] = s[i-1]+s[i-2]
for i in range(len(s)):
if s[i] > n:
j = i
break
print(j-1) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int CheckSingle(int num[], int n, int start, int k) {
int sum[3] = {0};
for (int i = start; i < n; i += k) sum[num[i]]++;
return min(sum[1], sum[2]);
}
int Check(int num[], int n, int k) {
int lmin = 0;
for (int i = 0; i < k; i++) lmin += CheckSingle(num, n, i, k);
return lmin;
}
int main() {
int num[101], n, k;
while (~scanf("%d %d", &n, &k)) {
for (int i = 0; i < n; i++) scanf("%d", &num[i]);
printf("%d\n", Check(num, n, k));
}
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main(){
string s;
cin >> s;
int maxs=753;
for(int i=0; i<s.size()-2; i++){
maxs=min(abs(753-(100*(s[i]-48)+10*(s[i+1]-48)+(s[i+2]-48))),maxs);
}
cout << maxs << endl;
} | 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
const int M = 1e9 + 7;
const int inf = 1e9 + 7;
const long long INF = 1e18;
int n, m;
vector<int> g[N];
int a[N], b[N], c[N];
int vis[N], h[N];
int pre[N];
int sz = 0;
int isCyc[N];
int p[N];
int R[N];
vector<pair<int, int>> Edge;
void add_Edge(int u, int v) { Edge.push_back({u, v}); }
void dfs(int u, int p) {
vis[u] = 1;
for (auto idx : g[u]) {
int v = a[idx] ^ b[idx] ^ u;
if (v == p) continue;
if (!vis[v]) {
h[v] = h[u] + 1;
pre[v] = idx;
dfs(v, u);
} else if (h[v] < h[u]) {
++sz;
add_Edge(sz, c[idx] + n);
isCyc[idx] = 1;
int cur = u;
while (cur != v) {
int idx = pre[cur];
add_Edge(sz, c[idx] + n);
isCyc[idx] = 1;
cur = a[idx] ^ b[idx] ^ cur;
}
}
}
}
int find(int x) { return x == p[x] ? x : p[x] = find(p[x]); }
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> n >> m;
for (int i = 1; i <= m; i++) {
cin >> a[i] >> b[i] >> c[i];
g[a[i]].push_back(i);
g[b[i]].push_back(i);
}
dfs(1, 0);
for (int i = 1; i <= m; i++)
if (!isCyc[i]) {
add_Edge(0, c[i] + n);
add_Edge(0, c[i] + n);
}
for (int i = 0; i <= n + m; i++) {
p[i] = i;
R[i] = 0;
isCyc[i] = 0;
}
for (int i = n + 1; i <= n + m; i++) {
R[i] = 1;
}
for (auto e : Edge) {
int u = e.first, v = e.second;
u = find(u), v = find(v);
if (u == v) {
isCyc[v] = 1;
} else {
p[u] = v;
R[v] += R[u];
R[u] = 0;
isCyc[v] |= isCyc[u];
}
}
int ans = 0;
for (int i = 0; i <= n + m; i++) {
if (R[i] && find(i) == i) {
ans += R[i];
if (!isCyc[i]) ans--;
}
}
cout << ans << endl;
}
| 8 | CPP |
matrix=[]
r=5
c=5
for i in range(r):
a=[]
a=list(map(int,(input().split())))
matrix.append(a)
r1=int(r/2)
c1=int(c/2)
for i in range(r):
for j in range(c):
if matrix[i][j]==1:
g=abs(r1-i)
f=abs(c1-j)
d=g+f
print(d)
| 7 | PYTHON3 |
for i in range(int(input())):
n = int(input())
d = [0]*n
for i in map(int,input().split()):
d[i-1] += 1
s=sorted(d)
s.reverse()
for i in range(1,n):
if(s[i]>=s[i-1]):
s[i]=max(s[i-1]-1,0)
print(sum(s)) | 10 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int N, D;
vector<int> nums;
int main() {
scanf("%d%d", &D, &N);
int ans = 0, prev;
scanf("%d", &prev);
for (int i = 1; i < N; i++) {
int val;
scanf("%d", &val);
if (prev == D) {
} else {
ans += D - prev;
}
prev = val;
}
cout << ans;
return 0;
}
| 8 | CPP |
s,n=list(map(int,input().split()))
dragon={}
ts=0
for i in range (n):
x,y=list(map(int,input().split()))
while (x,ts) in dragon:
ts+=1
dragon[(x,ts)]=y
playorder=sorted(dragon)
for x in playorder:
hp=s-x[0]
if hp<=0:
print('NO')
break
s+=dragon[x]
else:
print('YES')
| 7 | PYTHON3 |
def main():
n = int(input())
top = int(input())
for _ in range(n):
a, b = map(int, input().split())
if top == a or top == 7 - a or top == b or top == 7 - b:
print("NO")
return
print("YES")
if __name__ == '__main__':
main()
| 7 | PYTHON3 |
s = list(map(int, input().split()))
cl = list(map(int, input().split()))
n, b = s[0], s[1]
dic = {}
nw = []
for x in cl:
nw.append(x%2)
count0 = 0
count1 = 0
count0 = nw.count(0)
count1 = nw.count(1)
if count0!=count1 or n%2!=0:
print(0)
else:
res = []
for i in range(2, n):
x = nw[:i]
k0 = x.count(0)
k1 = x.count(1)
if count0 - k0 == count1 - k1:
res.append(abs(cl[i]-cl[i-1]))
counter = 0
sm = 0
res = sorted(res)
i = 0
while(sm<=b and i<len(res)):
sm+=res[i]
counter+=1
i+=1
if sm>b:
counter-=1
print(counter) | 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
long long int N = 1e6;
long long int dp[11][1000001];
int main() {
ios::sync_with_stdio(false);
cin.tie();
cout.tie();
long long int i, j, k, x;
cin >> x;
for (i = 0; i <= 10; i++) {
for (j = 0; j <= N; j++) {
dp[i][j] = 0;
}
}
for (i = 0; i <= N; i++) {
dp[1][i] = 1;
}
for (i = 2; i <= 10; i++) {
for (j = 0; j <= N; j++) {
if (j >= i) {
dp[i][j] = dp[i][j - i] + dp[i - 1][j];
} else {
dp[i][j] = dp[i - 1][j];
}
}
}
for (i = 1; i <= 10; i++) {
for (j = 1; j <= N; j++) {
if (dp[i][j] == x) {
cout << j << " " << i << endl;
for (k = 1; k <= i; k++) cout << k << " ";
return 0;
}
}
}
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
const long long PI = 3.1415926535897932384626;
const long long mod = 1000000007;
const long long FMOD = 998244353;
const long long N = 100005;
const double eps = 1e-9;
long long check(double n) {
double x = n * n;
if ((x - (int)x) == 0)
return 1;
else
return 0;
}
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {
return (a.second < b.second);
}
int main() {
long long n, l = 0, r = 9, cnt = 0, x;
cin >> n;
string s;
cin >> s;
vector<long long> v(10);
for (long long i = 0; i < 10; i++) v[i] = 0;
for (long long i = 0; i < n; i++) {
if (s[i] == 'L' && cnt != 10) {
cnt++;
v[l] = 1;
while (v[l] != 0 && cnt < 10) {
l++;
}
} else if (s[i] == 'R' && cnt != 10) {
v[r] = 1;
while (v[r] != 0 && cnt < 10) {
r--;
}
cnt++;
} else {
char a = s[i];
int x = a - 48;
v[x] = 0;
if (l > x) {
l = x;
}
if (x > r) {
r = x;
}
if (cnt == 10) {
l = x;
r = x;
}
cnt--;
}
}
for (long long i = 0; i < 10; i++) cout << v[i];
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
class A301 {
public:
void solve(istream& in, ostream& out) {
int n;
in >> n;
vector<int> v(2 * n - 1);
for (int i = 0; i < 2 * n - 1; ++i) {
in >> v[i];
}
sort(v.begin(), v.end());
vector<int> v2 = v;
for (int i = 0; i + 1 < 2 * n - 1; i += 2) {
if (v[i] + v[i + 1] < 0) {
v[i] = -v[i];
v[i + 1] = -v[i + 1];
}
}
int sum = accumulate(v.begin(), v.end(), 0);
if (n % 2 == 0) {
out << sum << "\n";
} else {
for (int i = 0; i < 2 * n - 1; ++i) {
v[i] = max(v[i], -v[i]);
}
out << max(sum, accumulate(v.begin(), v.end(), 0)) << "\n";
}
}
};
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
A301 solver;
std::istream& in(std::cin);
std::ostream& out(std::cout);
solver.solve(in, out);
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int out[] = {15, 14, 12, 13, 8, 9, 10, 11, 0, 1, 2, 3, 4, 5, 6, 7};
cout << out[n];
return 0;
}
| 7 | CPP |
n=list(map(int,input().split()))
t=list(map(int,input().split()))
tx=set(t)
def check(x):
z=0
w=0
for p in range(1,x+1):
for i in tx:
z+=int(t.count(i)/p)
if z>=n[0]:w=p
z=0
return w
maxi=[]
for i in tx:
a=check(t.count(i))
maxi.append(a)
maxi.sort()
if len(maxi)==0:print(0)
else: print(maxi[len(maxi)-1])
| 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
void File() {
freopen("name", "r", stdin);
freopen("name", "r", stdout);
}
void fast() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
bool isPrime(long long n) {
if (n == 2) return true;
if (n % 2 == 0 || n < 2) return false;
for (long long i = 3; i * i <= n; i += 2) {
if (n % i == 0) return false;
}
return true;
}
bool binarySearch(vector<int> &arr, int target, int size1) {
int f = 0, l = size1 - 1;
int mid = 0;
while (f <= l) {
mid = (f + (l - f) / 2);
if (arr[mid] == target) return true;
if (arr[mid] > target)
l = mid - 1;
else if (arr[mid] < target)
f = mid + 1;
}
return false;
}
long long factorial(long long n) {
if (n == 0) return 1;
return n * factorial(n - 1);
}
void Divisors(long long n) {
for (int i = 1; i <= sqrt(n); i++) {
if (n % i == 0) {
if (n / i == i)
cout << i << " ";
else
cout << i << " " << n / i << " ";
}
}
cout << endl;
}
void printChars(char s) {
char arr[] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
int pos = 0;
while (arr[pos] != s) {
cout << arr[pos];
pos++;
}
cout << arr[pos];
for (int i = pos - 1; i >= 0; i--) cout << arr[i];
cout << endl;
}
bool isEqual2(vector<int> &arr, int target, int sz) {
int f = 0, l = sz - 1;
while (f < l) {
if (arr[f] + arr[l] == target)
return true;
else if (arr[f] + arr[l] > target)
l--;
else
f++;
}
return false;
}
long long sum_range2(int s, int e, vector<long long> &arr3) {
return arr3[e] - arr3[s - 1];
}
long long sum_range(int s, int e, vector<long long> &arr2) {
return arr2[e] - arr2[s];
}
int main() {
fast();
string s;
int n, m;
cin >> n >> m >> s;
int gpos = s.find('G');
int tpos = s.find('T');
if (gpos > tpos) {
swap(s[gpos], s[tpos]);
swap(gpos, tpos);
}
string tmp = "";
for (int i = gpos; i <= tpos; i++) tmp += s[i];
int c = 0;
for (int i = 0; i < ((int)((tmp).size())); i += m) {
if (tmp[i + m] == '.')
continue;
else if (tmp[i + m] == 'T') {
cout << "YES\n";
return 0;
} else {
cout << "NO\n";
return 0;
}
}
cout << "NO\n";
return 0;
}
| 7 | CPP |
n,m,d=map(int,input().split())
p = ((n - d) * 2) / (n * n);
if d == 0: p /= 2
ans = p * (m - 1)
print(ans)
| 0 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
#define NMAX 100004
int n,m,i,j,x,y,lg[NMAX],k[NMAX],a[NMAX][2],b[NMAX][2],pr[NMAX][2],rmqa[NMAX][20][2],rmqb[NMAX][20][2],ok[NMAX][2];
void solution (int pos)
{
cout<<"Yes"<<'\n';
x=n+1;
int sol[NMAX];
while (x>0)
{
y=pr[x][pos];
for (i=y;i<x;i++)
sol[i]=1-pos;
x=y;
pos=1-pos;
}
for (i=1;i<=n;i++)
cout<<sol[i]<<' ';
cout<<'\n';
return;
}
bool isInInterval (int val, int left, int right, int pos)
{
int sz=lg[right-left+1];
int Min=max(rmqa[left][sz][pos],rmqa[right-(1<<sz)+1][sz][pos]);
int Max=min(rmqb[left][sz][pos],rmqb[right-(1<<sz)+1][sz][pos]);
return ((Min<=val) && (val<=Max));
}
void solve (int step, int pos)
{
if (pr[step][pos]==-1)
return;
int left=step;
int right=n;
int mid;
while (left<=right)
{
mid=(left+right)/2;
if (ok[mid][pos]!=(ok[step-1][pos]+mid-step+1))
{
right = mid - 1;
continue;
}
if (isInInterval(k[step-1], step, mid, 1-pos))
left = mid + 1;
else
right = mid - 1;
}
for (int i = left; i > step; i--)
{
if (pr[i][1-pos]==-1)
{
pr[i][1-pos]=step;
}
else
break;
}
return;
}
int main()
{
cin>>n>>m;
ok[0][0]=0;
ok[0][1]=0;
for (i=1;i<=n;i++)
{
cin>>k[i];
cin>>a[i][0]>>b[i][0];
cin>>a[i][1]>>b[i][1];
ok[i][0]=ok[i-1][0];
ok[i][1]=ok[i-1][1];
if ((k[i]>=a[i][0]) && (k[i]<=b[i][0]))
ok[i][0]++;
if ((k[i]>=a[i][1]) && (k[i]<=b[i][1]))
ok[i][1]++;
}
for (i=1;i<=n;i++)
{
rmqa[i][0][0]=a[i][0];
rmqb[i][0][0]=b[i][0];
rmqa[i][0][1]=a[i][1];
rmqb[i][0][1]=b[i][1];
}
lg[0]=0;
lg[1]=0;
for (i=2;i<=n;i++)
lg[i]=lg[i/2]+1;
for (i=1;(1<<i)<=n;i++)
{
for (j=1;j<=(n-(1<<i)+1);j++)
{
rmqa[j][i][0]=max(rmqa[j][i-1][0],rmqa[j+(1<<(i-1))][i-1][0]);
rmqb[j][i][0]=min(rmqb[j][i-1][0],rmqb[j+(1<<(i-1))][i-1][0]);
rmqa[j][i][1]=max(rmqa[j][i-1][1],rmqa[j+(1<<(i-1))][i-1][1]);
rmqb[j][i][1]=min(rmqb[j][i-1][1],rmqb[j+(1<<(i-1))][i-1][1]);
}
}
for (i=1;i<=(n+1);i++)
{
pr[i][0]=-1;
pr[i][1]=-1;
}
pr[1][0]=0;
pr[1][1]=0;
k[0]=0;
for (i=1;i<=n;i++)
{
solve(i,0);
solve(i,1);
}
if (pr[n+1][0]!=-1)
solution(0);
else if (pr[n+1][1]!=-1)
solution(1);
else
cout<<"No"<<'\n';
return 0;
}
| 11 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
const int inf = 0x3f3f3f3f;
int a[N], b[N];
int nex[N];
int main() {
int n, m;
int t, l, r;
int x;
while (cin >> n >> m) {
memset(b, 0, sizeof(b));
memset(a, 0, sizeof(a));
memset(nex, 0, sizeof(nex));
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
cin >> x;
if (a[j] <= x) {
b[j] += 1;
a[j] = x;
if (nex[i] < b[j]) nex[i] = b[j];
} else {
a[j] = x;
b[j] = 1;
if (nex[i] == 0) nex[i] = 1;
}
}
}
cin >> t;
while (t--) {
cin >> l >> r;
if (nex[r] > r - l)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
}
return 0;
}
| 9 | CPP |
a,b = [int(i) for i in input().split()]
list = [int(i) for i in input().split()]
t = []
def f(list):
t = [i-b for i in list]
t1 = [i+b for i in t]
y = []
for i in range(0,len(t)):
if t[i] >0:
y.append(t[i])
if y == []:
list2 = t1
l = 0
i = 0
s = len(list2)
while i <=0:
i = t1.pop()
l = l+1
print(s-l+1)
else:
list = t
return f(list)
f(list)
| 7 | PYTHON3 |
#include <bits/stdc++.h>
int main() {
int n = 9, i, x, y, z;
int *m = new int[n];
for (i = 1; i < n + 1; i++) {
scanf("%d", &m[i]);
}
z = (m[4] + m[6] - m[7] - m[8] + m[2] + m[3]) / 2;
x = m[4] + m[6] - z;
y = m[2] + m[3] - z;
m[1] = x;
m[5] = y;
m[9] = z;
for (i = 1; i < n + 1; i++) {
printf("%d ", m[i]);
}
return 0;
}
| 8 | CPP |
def fixing_typos(s):
if len(s)==1:
print(s)
else:
count=0
array=[]
values=""
for i in range(1,len(s)):
if s[i-1]==s[i]:
count+=1
else:
values+=s[i-1]
if count+1>=3:
array.append(2)
else:
array.append(count+1)
count=0
if count+1>=3:
array.append(2)
else:
array.append(count+1)
values+=s[i]
for i in range(1,len(array)):
if array[i-1]==2 and array[i-1]==array[i]:
array[i]=1
new_array=[values[i]*array[i] for i in range(len(array))]
print("".join(new_array))
s=input()
fixing_typos(s)
| 9 | PYTHON3 |
#include<bits/stdc++.h>
using namespace std;
const int N=1000005,mod=998244353;
int n,m,q,ans,k,v=1,f[N],c[N],a[N],s[N][2],t[N];
vector<int>x;
int fa(int x)
{
if(x==f[x])
return x;
int y=f[x],t=fa(y);
c[x]^=c[y];
return f[x]=t;
}
void mg(int x,int y)
{
v=v*2%mod,k++,f[k]=k;
if(a[x]<a[y])
swap(x,y);
if(!a[x])
{
a[x]^=1,a[y]^=1;
t[x]=t[y]=k;
s[k][0]=v;
return;
}
if(!a[y])
{
a[x]^=1,a[y]^=1;
int z=t[x],r=fa(z);
t[x]=0,t[y]=k;
c[k]=c[z]^1,f[k]=r;
s[r][c[k]]=(s[r][c[k]]+v)%mod;
if(c[k])
ans=(ans+v)%mod;
return;
}
a[x]^=1,a[y]^=1;
int z1=t[x],z2=t[y],r1=fa(z1),r2=fa(z2);
c[k]=c[z1]^1,f[k]=r1;
s[r1][c[k]]=(s[r1][c[k]]+v)%mod;
if(c[k])
ans=(ans+v)%mod;
if(r1==r2)
return;
c[r2]=c[z1]^c[z2],f[r2]=r1;
s[r1][0]=(s[r1][0]+s[r2][c[r2]])%mod;
s[r1][1]=(s[r1][1]+s[r2][c[r2]^1])%mod;
if(c[r2])
ans=(ans+s[r2][0])%mod,ans=(ans+mod-s[r2][1])%mod;
}
int main()
{
scanf("%d%d%d",&n,&m,&q);
while(q--)
{
int u,v;
scanf("%d%d",&u,&v);
mg(u,v+n);
}
scanf("%d",&q);
while(q--)
{
int ty,u,v;
scanf("%d",&ty);
if(ty==1)
{
int u,v;
scanf("%d%d",&u,&v);
mg(u,v+n);
printf("%d\n",ans);
}
else
{
x.clear();
for(int i=1;i<=k;i++)
{
fa(i);
if(c[i])
x.push_back(i);
}
printf("%d ",x.size());
for(auto i:x)
printf("%d ",i);
puts("");
}
fflush(stdout);
}
return 0;
}
| 13 | CPP |
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
ll qmin(ll a, ll b){
return (a < b) ? a : b;
}
int n, m;
int par[777];
ll dist[777][777];
vector< pair<int, ll> > v[200200];
pair< ll, pair<int, int> > e[200200];
int getpar(int now){
return par[now] = ((par[now] == now) ? now : getpar(par[now]));
}
int cnt_edge[200200];
priority_queue< pair<ll, int> > ne;
bool in[200200];
int tot = 0;
queue<int> q;
ll solve_700(){
q.push(0);
in[0] = 1;
ll ans = 0;
while(tot < n){
while(!q.empty()){
int now = q.front(); q.pop();
rep(i, (int)v[now].size()){
cnt_edge[v[now][i].first]++;
ne.push(make_pair(-v[now][i].second, v[now][i].first));
}
tot++;
}
rep(i, n) if(!in[i] && cnt_edge[i] < tot) q.push(i), in[i] = 1;
if(q.empty()){
while(!ne.empty()){
int now = ne.top().second;
ll nowval = -ne.top().first;
ne.pop();
if(in[now]) continue;
ans += nowval;
in[now] = 1;
q.push(now);
break;
}
}
}
return ans;
}
int main(){
ios::sync_with_stdio(false);
cin >> n >> m;
rep(i, m){
int a, b; ll c;
cin >> a >> b >> c;
a--, b--;
e[i] = make_pair(c, make_pair(a, b));
v[a].push_back(make_pair(b, c));
v[b].push_back(make_pair(a, c));
}
if(n > 700){
cout << solve_700() << endl;
} else {
memset(dist, 0x3f, sizeof(dist));
ll val = 0;
rep(i, m){
int a = e[i].second.first, b = e[i].second.second;
ll c = e[i].first;
val ^= c;
dist[a][b] = qmin(c, dist[a][b]);
dist[b][a] = qmin(c, dist[b][a]);
}
e[m] = (make_pair(val, make_pair(-1, -1)));
sort(e, e + m + 1);
rep(i, n) par[i] = i;
ll INF = 0x3f3f3f3f3f3f3f3f;
bool found_ok = 0;
vector< pair<int, int> > edge0;
rep(i, n){
rep(j, i){
if(i == j || dist[i][j] < INF) continue;
if(getpar(i) == getpar(j)) found_ok = 1;
par[getpar(i)] = getpar(j);
edge0.push_back(make_pair(i, j));
}
}
if(found_ok){
ll ans = 0;
rep(i, m + 1){
if(e[i].second == make_pair(-1, -1)) continue;
if(getpar(e[i].second.first) != getpar(e[i].second.second)){
ans += e[i].first;
par[getpar(e[i].second.first)] = getpar(e[i].second.second);
}
}
cout << ans << endl;
} else {
ll res = 0x3f3f3f3f3f3f3f3f;
rep(e1, (int)edge0.size()){
rep(k, n) par[k] = k;
rep(e2, (int)edge0.size()) if(e1 != e2 && getpar(edge0[e2].first) != getpar(edge0[e2].second)) par[getpar(edge0[e2].first)] = getpar(edge0[e2].second);
ll ans = 0;
rep(ei, m + 1){
if(e[ei].second == make_pair(-1, -1)) e[ei].second = edge0[e1];
if(getpar(e[ei].second.first) != getpar(e[ei].second.second)){
ans += e[ei].first;
par[getpar(e[ei].second.first)] = getpar(e[ei].second.second);
}
}
res = qmin(res, ans);
}
cout << res << endl;
}
}
return 0;
}
| 9 | CPP |
#include <bits/stdc++.h>
using namespace std;
map<char, int> mp;
char s[10][10];
int main() {
mp['Q'] = 9;
mp['q'] = 9;
mp['K'] = 0;
mp['k'] = 0;
mp['R'] = 5;
mp['r'] = 5;
mp['B'] = 3;
mp['b'] = 3;
mp['n'] = 3;
mp['N'] = 3;
mp['P'] = 1;
mp['p'] = 1;
int i, j, w = 0, b = 0;
for (i = 0; i < 8; i++) scanf("%s", s[i]);
for (i = 0; i < 8; i++) {
for (j = 0; j < 8; j++) {
if (s[i][j] == '.') continue;
if (s[i][j] >= 65 && s[i][j] <= 90)
w += mp[s[i][j]];
else
b += mp[s[i][j]];
}
}
if (w > b)
printf("White\n");
else if (b > w)
printf("Black\n");
else
printf("Draw\n");
return 0;
}
| 7 | CPP |
n = int(input())
t = str(input())
s = ''
i = 0
num = 0
a = []
while i <= 10:
num += i
a.append(num)
i += 1
index = 0
for i in range(a.index(n)):
try:
letter = t[index]
except IndexError:
print('error')
# print(letter)
s += letter
index = index + i + 1
print(s) | 7 | PYTHON3 |
a1,a2,a3,a4=list(map(int,input().split()))
if (a1+a2==a3+a4) or (a1+a3==a2+a4) or (a1+a4==a2+a3) or (a1+a2+a3==a4) or (a4+a3+a2==a1) or (a1+a2+a4==a3) or (a2==a1+a3+a4):
print ("YES")
else: print ("NO") | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int H,W,w,h;
const int INF =2333;
int main()
{
scanf("%d%d%d%d",&H,&W,&h,&w);
if (H%h==0&&W%w==0) return printf("No"),0;
printf("Yes\n");
for (int i=1;i<=H;++i)
for (int j=1;j<=W;++j)
printf("%d%c",(i%h==0&&j%w==0?(1-h*w)*INF-1:INF),j==W?'\n':' ');
return 0;
} | 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
int a[1501], N;
unordered_map<int, vector<pair<int, int> > > Unordered_map;
void build_unordered_map() {
for (int r = 1; r <= N; r++) {
int sum = 0;
for (int l = r; l >= 1; l--) {
sum += a[l];
Unordered_map[sum].push_back(make_pair(l, r));
}
}
}
void find_max() {
int res = 1, mark = a[1];
for (auto it = Unordered_map.begin(); it != Unordered_map.end(); it++) {
int r = -1, sum = 0;
for (int j = 0; j < it->second.size(); j++) {
if (it->second[j].first > r) sum++, r = it->second[j].second;
}
if (sum > res) res = sum, mark = it->first;
}
cout << res << '\n';
int r = -1;
for (int j = 0; j < Unordered_map[mark].size(); j++)
if (Unordered_map[mark][j].first > r)
cout << Unordered_map[mark][j].first << " "
<< Unordered_map[mark][j].second << '\n',
r = Unordered_map[mark][j].second;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> N;
for (int i = 1; i <= N; i++) cin >> a[i];
build_unordered_map();
find_max();
return 0;
}
| 12 | CPP |
#include<bits/stdc++.h>
using namespace std;
#define pi acos(-1)
#define printfl printf("%f\n",f)
#define printd printf("%lf\n",d)
#define printi printf("%d\n",p)
#define printl printf("%ld\n",l)
#define printll printf("%lld\n",ll)
#define case cout<<"Case "<<TEST<<": "
#define forcase for(int TEST=1;TEST<=test;TEST++)
#define max3(a,b,c) max((a,b),c)
#define min3(a,b,c) min((a,b),c)
#define newl printf("\n")
#define printd1d2 printf("%lf %lf\n",d1, d2)
#define ll long long int
void solve()
{
ll n;cin>>n;
ll a[n],b[n];
for (ll i = 0; i < n; i++)
{
cin>>a[i];
}
for (ll i = 0; i < n; i++)
{
cin>>b[i];
}
vector < pair <ll,ll> >dec,inc;
ll sum1=0,sum2=0;
for (ll i = 0; i < n; i++)
{
if (a[i]>b[i])
{
dec.push_back(make_pair(a[i]-b[i],i+1));
sum1+=a[i]-b[i];
}
if (a[i]<b[i])
{
inc.push_back(make_pair(b[i]-a[i],i+1));
sum2+=b[i]-a[i];
}
}
if (sum1!=sum2)
{
cout<<-1<<endl;
return;
}
if (dec.size()==0 && inc.size()==0)
{
cout<<0<<endl;
return;
}
vector < pair <ll,ll> >v1;
ll indx1=0,indx2=0;
while (dec[indx1].first>0 && inc[indx2].first>0 && indx1<dec.size() && indx2<inc.size())
{
dec[indx1].first-=1;
inc[indx2].first-=1;
v1.push_back(make_pair(dec[indx1].second,inc[indx2].second));
if (dec[indx1].first==0)
{
indx1+=1;
}
if (inc[indx2].first==0)
{
indx2+=1;
}
}
cout<<v1.size()<<endl;
for (ll i = 0; i < v1.size(); i++)
{
cout<<v1[i].first<<" "<<v1[i].second<<endl;
}
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int test;
cin>>test;
forcase
solve();
return 0;
}
| 7 | CPP |
n=int(input())
for i in range(n):
n1=int(input())
n2=list(map(int,input().split()[:n1]))
s=set(n2)
print(len(s)) | 7 | PYTHON3 |
n = int(input())
for i in range(n):
m = int(input())
s = []
for j in range(m):
a, b = input().split(' ')
a, b = int(a), int(b)
s.append([a,b])
s.sort(key=lambda c: (c[0], c[1]))
flag = True
for e in range(len(s) - 1):
if s[e][1] <= s[e+1][1]:
pass
else:
flag = False
break
if flag:
print('YES')
x_tek = 0
y_tek = 0
rez = ''
for xt, yt in s:
r_time = xt - x_tek
up_time = yt - y_tek
rez += 'R' * r_time + 'U' * up_time
x_tek = xt
y_tek = yt
print(rez)
else:
print('NO')
| 8 | PYTHON3 |
n,m = map(int,input().split())
x = list(map(int,input().split()))
x.sort()
result=0
count=0
for i in x:
if i<0 and count<m:
result+=abs(i)
count+=1
print(result)
| 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
long long t, s, q, kq;
int main() {
cin >> t >> s >> q;
kq = 0;
while (s < t) {
s = s * q;
kq++;
}
cout << kq;
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
struct node {
int num;
int pos;
const bool operator<(const node &a) const { return num < a.num; }
};
int o[200010];
int ans[200010];
node u[200010];
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%d", &o[i]);
sort(o, o + n, greater<int>());
for (int i = 0; i < n; i++) {
scanf("%d", &u[i].num);
u[i].pos = i;
}
sort(u, u + n);
for (int i = 0; i < n; i++) ans[u[i].pos] = o[i];
for (int i = 0; i < n; i++) printf("%d ", ans[i]);
printf("\n");
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void amin(T &x, U y) {
if (y < x) x = y;
}
template <typename T, typename U>
inline void amax(T &x, U y) {
if (x < y) x = y;
}
long long powmod(long long a, long long b) {
long long res = 1;
a %= 1000000007;
assert(b >= 0);
for (; b; b >>= 1) {
if (b & 1) res = res * a % 1000000007;
a = a * a % 1000000007;
}
return res;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(NULL);
long long i, j, n, m;
string s;
cin >> s;
n = ((s).size());
cin >> m;
string b[m];
for (int i = 0; i < m; i++) cin >> b[i];
long long dp[n][m];
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (((b[j]).size()) > i + 1) {
if (i > 0)
dp[i][j] = dp[i - 1][j];
else
dp[i][j] = -1;
}
long long pos = 1;
for (int k = 0; k < ((b[j]).size()); k++) {
if (s[i - k] != b[j][((b[j]).size()) - k - 1]) pos = 0;
}
if (pos)
dp[i][j] = i;
else if (i > 0)
dp[i][j] = dp[i - 1][j];
else
dp[i][j] = -1;
}
}
long long fmaxi = 0;
long long ind = 0;
for (int i = 0; i < n; i++) {
long long maxi = -1;
for (int j = 0; j < m; j++) {
if (dp[i][j] == -1) continue;
long long st = dp[i][j] - ((b[j]).size()) + 1;
maxi = max(maxi, st);
}
if (i - maxi > fmaxi) {
fmaxi = i - maxi;
ind = maxi + 1;
}
}
swap(ind, fmaxi);
cout << ind << " " << fmaxi;
return 0;
}
| 9 | CPP |
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <map>
#include <set>
#include <bitset>
#include <vector>
#include <complex>
#include <queue>
#include <stack>
#include <sstream>
#define mp(a, b) make_pair(a, b)
using namespace std;
typedef pair<long long, int> pp;
const int maxn = 1e5 + 5;
const long long oo = 1e16;
long long b[maxn], l[maxn], u[maxn];
pp a[maxn];
long long n, x;
long long gao(const int &id, const long long &v)
{
if(v < 0)
return 0;
if(l[id] * b[id] >= v)
return v == 0 ? 0 : (v - 1) / l[id] + 1;
long long nv = v + b[id] * u[id] - b[id] * l[id];
if(u[id] * x >= nv)
return nv == 0 ? 0 : (nv - 1) / u[id] + 1;
return oo;
}
int main()
{
std::ios::sync_with_stdio(false);
cin >> n >> x;
long long tot = 0;
for(int i = 1; i <= n; i ++)
{
cin >> b[i] >> l[i] >> u[i];
a[i].first = x * u[i] - b[i] * u[i] + b[i] * l[i];
a[i].second = i;
tot -= b[i] * l[i];
}
sort(a + 1, a + n + 1);
reverse(a + 1, a + n + 1);
for(int i = 1; i <= n; i ++)
{
if(tot + a[i].first >= 0)
{
long long ans = oo;
for(int j = i; j <= n; j ++)
ans = min(ans, (i - 1) * x + gao(a[j].second, -tot));
for(int j = 1; j < i; j ++)
ans = min(ans, (i - 1) * x + gao(a[j].second, -(tot + a[i].first - a[j].first)));
cout << ans << endl;
break;
}
tot += a[i].first;
}
return 0;
}
| 0 | CPP |
#include <bits/stdc++.h>
int main() {
int TUX, FOO = 0, BAR = 0, BAZ = 0, QUZ = 1;
double result;
scanf("%d", &TUX);
while (TUX--) {
int PUR;
scanf("%d", &PUR);
FOO += PUR;
BAR += 1;
if (FOO * QUZ >= BAR * BAZ) {
BAZ = FOO;
QUZ = BAR;
}
}
result = 1. * BAZ / QUZ;
printf("%lf", result);
return 0;
}
| 9 | CPP |
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
using namespace std;
int main(){
string a;
getline(cin,a);
for(int i=0;i<a.size();i++)a[i]=toupper(a[i]);
cout<<a<<endl;
} | 0 | CPP |
import sys
from functools import reduce
from collections import Counter
import time
import datetime
from math import sqrt,gcd
# def time_t():
# print("Current date and time: " , datetime.datetime.now())
# print("Current year: ", datetime.date.today().strftime("%Y"))
# print("Month of year: ", datetime.date.today().strftime("%B"))
# print("Week number of the year: ", datetime.date.today().strftime("%W"))
# print("Weekday of the week: ", datetime.date.today().strftime("%w"))
# print("Day of year: ", datetime.date.today().strftime("%j"))
# print("Day of the month : ", datetime.date.today().strftime("%d"))
# print("Day of week: ", datetime.date.today().strftime("%A"))
def ip(): return int(sys.stdin.readline())
def sip(): return sys.stdin.readline()
def mip(): return map(int,sys.stdin.readline().split())
def mips(): return map(str,sys.stdin.readline().split())
def lip(): return list(map(int,sys.stdin.readline().split()))
def matip(n,m):
lst=[]
for i in range(n):
arr = lip()
lst.insert(i,arr)
return lst
def factors(n): # find the factors of a number
return list(set(reduce(list.__add__, ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0))))
def minJumps(arr, n): #to reach from 0 to n-1 in the array in minimum steps
jumps = [0 for i in range(n)]
if (n == 0) or (arr[0] == 0):
return float('inf')
jumps[0] = 0
for i in range(1, n):
jumps[i] = float('inf')
for j in range(i):
if (i <= j + arr[j]) and (jumps[j] != float('inf')):
jumps[i] = min(jumps[i], jumps[j] + 1)
break
return jumps[n-1]
def dic(arr): # converting list into dict of count
return Counter(arr)
def check_prime(n):
if n<2:
return False
for i in range(2,int(n**(0.5))+1,2):
if n%i==0:
return False
return True
# --------------------------------------------------------- #
# sys.stdin = open('input.txt','r')
# sys.stdout = open('output.txt','w')
# --------------------------------------------------------- #
n = ip()
cur = sip()
fin = sip()
p = 0
for i in range(n):
x = min(int(cur[i]),int(fin[i]))
y = max(int(cur[i]),int(fin[i]))
p += min(abs(int(fin[i])-int(cur[i])),abs(10-y+x))
# print(p)
print(p) | 7 | PYTHON3 |
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;
vector<int> v(n,0);
for(int i=0;i<n;i++){
cin>>v[i];
}
sort(v.begin(),v.end());
cout<<v[n-1]-v[0]<<endl;
return 0;
} | 0 | CPP |
# -*- coding: utf-8 -*-
n, m, a = list(map(int, input().split(' ')))
def pave(n, m):
inLine = int(n / a) if n % a == 0 else int((n - (n % a))/a) + 1
if m <= a:
return inLine
if m % a == 0:
return int(m / a) * inLine
if m % a != 0:
return (int((m - (m % a))/a) + 1) * inLine
if n >= m:
print(pave(n, m))
elif n < m:
print(pave(m, n))
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false), cin.tie(0);
int n;
cin >> n;
int ar[n + 1];
for (int i = 1; i <= n; i++) cin >> ar[i];
long long eng = 0, ans = 0;
for (int i = 0; i < n; i++) {
if (!i) {
ans += ar[i + 1];
continue;
}
if (ar[i] >= ar[i + 1]) {
eng += ar[i] - ar[i + 1];
} else {
if (eng >= (ar[i + 1] - ar[i]))
eng -= ar[i + 1] - ar[i];
else {
ans += (ar[i + 1] - ar[i]) - eng;
eng = 0;
}
}
}
cout << ans;
return 0;
}
| 8 | CPP |
#include <bits/stdc++.h>
using namespace std;
template <class T>
void pv(T a, T b) {
for (T i = a; i != b; ++i) cout << *i << " ";
cout << endl;
}
template <class T>
void pvp(T a, T b) {
for (T i = a; i != b; ++i)
cout << "(" << i->first << ", " << i->second << ") ";
cout << endl;
}
template <class T>
void chmin(T &t, T f) {
if (t > f) t = f;
}
template <class T>
void chmax(T &t, T f) {
if (t < f) t = f;
}
int in_c() {
int c;
for (; (c = getchar()) <= ' ';) {
if (!~c) throw ~0;
}
return c;
}
int in() {
int x = 0, c;
for (; (unsigned)((c = getchar()) - '0') >= 10;) {
if (c == '-') return -in();
if (!~c) throw ~0;
}
do {
x = (x << 3) + (x << 1) + (c - '0');
} while ((unsigned)((c = getchar()) - '0') < 10);
return x;
}
long long In() {
long long x = 0, c;
for (; (unsigned)((c = getchar()) - '0') >= 10;) {
if (c == '-') return -In();
if (!~c) throw ~0;
}
do {
x = (x << 3) + (x << 1) + (c - '0');
} while ((unsigned)((c = getchar()) - '0') < 10);
return x;
}
int N, L;
string S[110];
string T;
char C;
int is[1010];
string TOLOWER(string s) {
string ret = "";
for (unsigned i = 0; i < s.size(); ++i) ret += tolower(s[i]);
return ret;
}
int main() {
int i, j;
for (; cin >> N;) {
for (i = 0; i < N; ++i) {
cin >> S[i];
}
cin >> T;
cin >> C;
L = T.size();
memset(is, 0, sizeof(is));
for (i = 0; i < N; ++i)
for (j = 0; j + (int)S[i].size() <= L; ++j) {
if (TOLOWER(S[i]) == TOLOWER(T.substr(j, S[i].size()))) {
++is[j];
--is[j + S[i].size()];
}
}
for (j = 0; j < L; ++j) {
is[j + 1] += is[j];
}
string ans = T;
for (j = 0; j < L; ++j)
if (is[j]) {
bool up = isupper(T[j]);
char c = tolower(C);
char d = tolower(T[j]);
char e;
if (d != c) {
e = c;
} else if (d != 'a') {
e = 'a';
} else {
e = 'b';
}
if (up) e = toupper(e);
ans[j] = e;
}
cout << ans << endl;
}
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
vector<int> tree[300001];
vector<int> color[300001];
vector<int> present[300001];
vector<int> val(300001, -1);
vector<bool> vis(300001, 0);
long long mod = 1000000007;
void dfs(int x) {
int mx = 1;
int lim = present[x].size();
for (int i = 0; i < color[x].size(); i++) {
int j = color[x][i];
if (val[j] == -1) continue;
if (val[j] >= lim) continue;
present[x][val[j]] = 1;
}
for (int i = 1; i < lim; i++) {
if (!present[x][i]) {
mx = i;
break;
}
}
for (int i = 0; i < color[x].size(); i++) {
int j = color[x][i];
if (val[j] == -1) {
val[j] = mx;
present[x][mx] = 1;
while (mx < lim && present[x][mx]) mx++;
}
}
for (int i = 0; i < tree[x].size(); i++) {
int j = tree[x][i];
if (vis[j]) continue;
vis[j] = 1;
dfs(j);
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
int s;
cin >> s;
for (int j = 0; j < s; j++) {
int c;
cin >> c;
color[i].push_back(c);
present[i].push_back(0);
}
present[i].push_back(0);
}
for (int i = 0; i < n - 1; i++) {
int x, y;
cin >> x >> y;
tree[x].push_back(y);
tree[y].push_back(x);
}
vis[1] = 1;
dfs(1);
int ans = 0;
for (int i = 1; i <= m; i++) {
if (val[i] == -1) val[i] = 1;
ans = max(ans, val[i]);
}
cout << ans << endl;
for (int i = 1; i <= m; i++) {
cout << val[i] << " ";
}
cout << endl;
}
| 9 | CPP |
t = int(input())
while t > 0:
n = int(input())
a = list(map(int, input().split(" ")))
b = [x % 3 for x in a]
answer = [0, 0, 0]
for bn in b:
answer[bn] += 1
couple = min(answer[1], answer[2])
extra = (max(answer[1], answer[2]) - couple) // 3
print(answer[0] + couple + extra)
t -= 1
| 8 | PYTHON3 |
Subsets and Splits