solution
stringlengths 10
983k
| difficulty
int64 0
25
| language
stringclasses 2
values |
---|---|---|
#include<stdio.h>
#include<algorithm>
int main()
{
int n,m,a,b,i,x,y;
scanf("%d",&n);
while(n--)
{
scanf("%d",&m);
for(a=b=i=0;i<m;++i)
{
scanf("%d",&x);
if(i)
{
if(x>y)a=std::max(a,x-y);
else b=std::max(b,y-x);
}
y=x;
}
printf("%d %d\n",a,b);
}
return 0;
} | 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int A, B, N, X;
bool flag;
double temp;
cin >> A >> B >> N;
flag = false;
if (A == 0 && B == 0)
printf("%d\n", N);
else if (A == 0)
printf("No solution\n");
else if (B == 0)
printf("0\n");
else {
temp = (double)B / (double)A;
if (temp < 0) {
flag = true;
}
temp = abs(temp);
temp = pow(temp, 1 / (double)N);
if (ceil(temp) - temp < 1e-6) {
if (flag) {
if (N % 2)
printf("%d\n", -(int)ceil(temp));
else
printf("No solution\n");
} else
printf("%d\n", (int)ceil(temp));
} else
printf("No solution\n");
}
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N = 2e5 + 10;
int n, m, a[N], c[N], ans;
vector<int> v[N];
int rt(int x) {
if (c[x] == x) return x;
return c[x] = rt(c[x]);
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
for (int i = 0; i < n; ++i) {
cin >> a[i];
v[--a[i]].push_back(i);
}
for (int i = 0; i < n - 1; ++i) {
if (a[i] != a[i + 1]) ++ans;
}
cout << ans << '\n';
int x, y;
iota(c, c + m, 0);
while (--m) {
cin >> x >> y;
x = rt(--x);
y = rt(--y);
if (v[x].size() < v[y].size()) swap(x, y);
for (auto i : v[y]) {
if (i > 0 && a[i - 1] == x) --ans;
if (i < n - 1 && a[i + 1] == x) --ans;
v[x].push_back(i);
}
for (auto i : v[y]) a[i] = x;
v[y].clear();
c[y] = x;
cout << ans << '\n';
}
}
| 11 | CPP |
#include <bits/stdc++.h>
int main() {
int n, m, i, j, k, x;
scanf("%d%d", &n, &m);
int a1[m], b1[m];
char a[m][11], b[m][11], c[n][11];
for (i = 0; i < m; i++) {
scanf("%s", a[i]);
a1[i] = strlen(a[i]);
scanf("%s", b[i]);
b1[i] = strlen(b[i]);
}
for (i = 0; i < n; i++) {
scanf("%s", c[i]);
for (j = 0; j < m; j++) {
x = strcmp(c[i], a[j]);
if (x == 0) {
if (a1[j] <= b1[j])
printf("%s ", a[j]);
else
printf("%s ", b[j]);
break;
}
}
}
}
| 8 | CPP |
n = int(input())
s = input() + 'a'
ans, i = 0, 0
while i < n:
if s[i] == 'x':
l, r = i, i
while s[r] == 'x': r += 1
ans += max(0, r - l - 2)
i = r
i += 1
print(ans) | 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
string s;
cin >> s;
cout << s.size() << endl;
}
} | 7 | CPP |
#include <bits/stdc++.h>
int n, g[300004];
int _max[300004], _min[300004], ct[2 * 300004] = {0};
long long ans = 0;
void solve(int l, int r) {
if (l == r) {
ans++;
return;
}
int m = (l + r) >> 1, i;
_max[m] = _min[m] = g[m];
_max[m + 1] = _min[m + 1] = g[m + 1];
for (i = m + 2; i <= r; i++) {
_max[i] = ((_max[i - 1]) > (g[i]) ? (_max[i - 1]) : (g[i]));
_min[i] = ((_min[i - 1]) < (g[i]) ? (_min[i - 1]) : (g[i]));
}
for (i = m - 1; i >= l; i--) {
_max[i] = ((_max[i + 1]) > (g[i]) ? (_max[i + 1]) : (g[i]));
_min[i] = ((_min[i + 1]) < (g[i]) ? (_min[i + 1]) : (g[i]));
}
for (i = l; i < m; i++) {
int end = i + _max[i] - _min[i];
if (end > m && end <= r && _max[end] < _max[i] && _min[end] > _min[i])
ans++;
}
for (i = r; i > m + 1; i--) {
int begin = i - _max[i] + _min[i];
if (begin <= m && begin >= l && _max[begin] < _max[i] &&
_min[begin] > _min[i])
ans++;
}
int ymax = m, ymin = m;
for (i = m + 1; i <= r; i++) {
while (ymin >= l && _min[i] < _min[ymin]) {
ct[_max[ymin] + ymin]++;
ymin--;
}
while (ymax > ymin && _max[i] > _max[ymax]) {
ct[_max[ymax] + ymax]--;
ymax--;
}
ans += ct[_min[i] + i];
}
for (i = l; i <= m; i++) ct[_max[i] + i] = 0;
ymax = ymin = m + 1;
for (i = m; i >= l; i--) {
while (ymax <= r && _min[i] < _min[ymax]) {
ct[_max[ymax] - ymax + 300004]++;
ymax++;
}
while (ymin < ymax && _max[i] > _max[ymin]) {
ct[_max[ymin] - ymin + 300004]--;
ymin++;
}
ans += ct[_min[i] - i + 300004];
}
for (i = m + 1; i <= r; i++) ct[_max[i] - i + 300004] = 0;
solve(l, m);
solve(m + 1, r);
}
int main() {
int i, r, c;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d%d", &r, &c);
g[r - 1] = c - 1;
}
solve(0, n - 1);
printf("%I64d\n", ans);
return 0;
}
| 12 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
if (n % 2 != 0)
cout << "-1" << endl;
else {
for (int i = 0; i < n; i++) {
if ((i + 1) % 2 != 0)
cout << (i + 2) << " ";
else
cout << i << " ";
}
}
return 0;
}
| 7 | CPP |
#include <iostream>
using namespace std;
long long a,n;
int main(){
cin>>n;
for(n++;n>9;n/=10)a+=9;
cout<<a+n-1<<endl;}
| 0 | CPP |
n = int(input())
#print(n)
l = [[int(x) for x in input().split()] for i in range(n)]
#print(l)
dx = (max([r[2] for r in l])-min([r[0] for r in l]))
dy = (max([r[3] for r in l])-min([r[1] for r in l]))
size = dx*dy
#print(size)
if dx == dy and sum([(r[2]-r[0])*(r[3]-r[1]) for r in l]) == size:
print("YES")
else:
print("NO") | 7 | PYTHON3 |
m,d = map(int,input().split())
cnt = 0
for i in range(m+1):
for j in range(d+1):
a = j%10
b = int(j/10)
if a >= 2 and b>=2:
if a*b == i:
cnt += 1
print(cnt) | 0 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
bool prime(long long int n) {
if (n <= 1) return false;
if (n <= 3) return true;
if (n % 2 == 0 || n % 3 == 0) return false;
for (long long int i = 5; i * i <= n; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0) return false;
return true;
}
bool subsequence_checker(string str1, string str2, long long int m,
long long int n) {
if (m == 0) return true;
if (n == 0) return false;
if (str1[m - 1] == str2[n - 1])
return subsequence_checker(str1, str2, m - 1, n - 1);
return subsequence_checker(str1, str2, m, n - 1);
}
bool cmp(const pair<int, int> &a, const pair<int, int> &b) {
if (a.first == b.first) return a.second > b.second;
return (a.first < b.first);
}
void solve() {
long long int n;
cin >> n;
string s;
cin >> s;
long long int r = n / 2;
long long int start = 0, end = n - 1;
while (start < end) {
long long int a = s[start] - 'a';
long long int b = s[end] - 'a';
if (abs(a - b) == 0 || abs(a - b) == 2) {
start++;
end--;
continue;
} else {
cout << "NO"
<< "\n";
return;
}
}
cout << "YES"
<< "\n";
return;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
long long int t;
cin >> t;
while (t--) {
solve();
}
cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1000000000 + 7;
const long long int N = 1000000 + 6;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t = 1;
cin >> t;
while (t--) {
string s;
cin >> s;
int n = s.length();
int l = -1, r = -1, c = 0;
for (int i = 0; i < n; i++) {
if (s[i] == '1' and c == 0) {
l = i;
c++;
} else if (s[i] == '1' and c != 0)
r = i;
}
int ans = 0;
if (l != -1)
for (int i = l; i <= r; i++) {
if (s[i] == '0') ans++;
}
cout << ans << '\n';
}
}
| 7 | CPP |
from sys import stdin,stdout
from math import *
# input = stdin.readline
from collections import Counter
from collections import defaultdict
def solve(l):
n = len(l)
D = Counter(l)
out = 0
pr = [0]
dd = {0:0}
for i in range(len(l)):
pr.append(pr[-1]+l[i])
dd[pr[-1]]=i+1
for k in D:
summ = 0
ans = -1
for i in range(len(pr)):
if(pr[i]>=k):
req=pr[i]-k
if(dd.get(req)!=None):
ans=dd.get(req)
if(ans!=-1 and i-ans>1):
break
ans=-1
if(ans!=-1):
out+=D[k]
return out
for __ in range(int(input())):
n=int(input())
ar=list(map(int,input().split()))
print(solve(ar))
# ans=0
# pr=[0]
# a={0:0}
# for i in range(n):
# pr.append(pr[-1]+ar[i])
# a[pr[-1]]=i+1
# d={}
# rslt=0
# for i in range(n):
# ans=-1
# if(d.get(ar[i])==-1):
# continue
# elif(d.get(ar[i])!=None):
# rslt+=1
# continue
# for j in range(2,n+1):
# c=pr[j]
# if(c>=ar[i]):
# l=0
# r=j
# req=c-ar[i]
# if(a.get(req)!=None):
# ans=a[req]
# if(ans!=-1 and j-ans>1):
# break
# ans=-1
# if(ans==-1):
# d[ar[i]]=-1
# else:
# d[ar[i]]=ans
# rslt+=1
# print(rslt)
| 11 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
long long N;
long long P[1000000];
bool visited[1000000];
long long out = 0;
void search(long long at) {
if (visited[at]) return;
visited[at] = true;
search(P[at]);
}
int main() {
cin >> N;
for (long long i = 0; i < N; i++) {
cin >> P[i];
P[i]--;
}
long long B = 0;
for (long long i = 0; i < N; i++) {
long long first;
cin >> first;
B += first;
}
out += 1 - (B % 2);
long long conn = 0;
for (long long i = 0; i < N; i++) {
if (!visited[i]) {
conn++;
search(i);
}
}
if (conn != 1) out += conn;
cout << out << endl;
return 0;
}
| 9 | CPP |
#include <bits/stdc++.h>
using namespace std;
int n;
int a[100005];
int main() {
int i, j, fl, test;
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
}
long long sum = 0;
sort(a, a + n);
for (i = n - 1; i >= 0; i--) {
if (i == n - 1)
sum += a[i];
else {
if (a[i] >= a[i + 1]) {
a[i] = a[i + 1] - 1;
if (a[i] <= 0) break;
}
sum += a[i];
}
}
printf("%lld\n", sum);
return 0;
}
| 8 | CPP |
def getLength(ambigiousStr):
#Get A Count in String first.
aCount = 0;
for i in range(0,len(ambigiousStr)):
if ambigiousStr[i] == 'a':
aCount +=1;
halfLen = int(len(ambigiousStr)/2)
if(aCount > halfLen ):
return len(ambigiousStr)
else:
return aCount + aCount - 1
def main():
ambigiousStr = input();
print(getLength(ambigiousStr));
if __name__ == "__main__":
main()
| 7 | PYTHON3 |
# #################################################################
# opgave 702A
# 18-1-2018
# #################################################################
n=int(input())
a=list(map(int,input().split()))
m=1
l=1
for i in range(1,n):
if a[i]>a[i-1]:
l+=1
else:
m=max(l,m)
l=1
m=max(l,m)
print(m)
'''
input:
5
1 7 2 11 15
output:
3
input:
6
100 100 100 100 100 100
output:
1
input:
10
802030518 598196518 640274071 983359971 71550121 96204862 799843967 446173607 796619138 402690754
output:
3
''' | 7 | PYTHON3 |
n=int(input())
print(len(set(input().split())-{'0'})) | 7 | PYTHON3 |
import math
def fact(n):
ans = 1
for i in range(2, n+1):
ans*= i
return ans
def comb(n, c):
return fact(n)//(fact(n-c)*c)
n = int(input())
a = list(map(int, input().split()))
a.sort()
if a[n-1]>=a[n-2] + a[n-3]:
print("NO")
else:
print("YES")
for i in range(n-1, -1, -2):
print(a[i], end = " ")
for i in range(n%2, n, 2):
print(a[i], end = " ")
| 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 100;
const long long LINF = 1e18 + 228;
const double DINF = 5e18 + .0;
const int ITER = 300;
const double EPS = 1e-6;
const int MOD = 1000000007;
const long long MAXN = 1e5 + 10;
int cnt[6];
string ans[MAXN];
bool was[MAXN];
pair<string, string> can[MAXN];
int n;
void solve() {
map<string, int> tosz;
tosz["S"] = 0;
tosz["M"] = 1;
tosz["L"] = 2;
tosz["XL"] = 3;
tosz["XXL"] = 4;
tosz["XXXL"] = 5;
for (int i = 0; i < 6; ++i) cin >> cnt[i];
cin >> n;
for (int i = 0; i < n; ++i) {
string in;
cin >> in;
bool df = false;
string left = "", right = "";
for (int i = 0; i < (int)in.length(); ++i) {
if (in[i] == ',') {
df = true;
continue;
}
if (!df)
left += in[i];
else
right += in[i];
}
if (!df) right = "tao";
can[i] = make_pair(left, right);
}
for (int i = 0; i < n; ++i) {
if (can[i].second == "tao") {
if (!cnt[tosz[can[i].first]]) {
cout << "NO";
return;
}
--cnt[tosz[can[i].first]];
ans[i] = can[i].first;
was[i] = true;
}
}
for (int cur = 0; cur < 5; ++cur) {
for (int i = 0; i < n; ++i) {
if (was[i]) continue;
if (tosz[can[i].first] == cur) {
if (cnt[cur]) {
ans[i] = can[i].first;
was[i] = true;
--cnt[cur];
} else if (cnt[cur + 1]) {
was[i] = true;
ans[i] = can[i].second;
--cnt[cur + 1];
} else {
cout << "NO";
return;
}
}
}
}
cout << "YES\n";
for (int i = 0; i < n; ++i) cout << ans[i] << "\n";
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
solve();
}
| 10 | CPP |
import sys
input = sys.stdin.readline
N, C = map(int, input().split())
c = [list(map(int, input().split())) for _ in range(N)]
t = [[0] * (10 ** 5 + 1) for _ in range(C + 1)]
for i in range(N):
for j in range(c[i][0], c[i][1] + 1):
t[c[i][2]][j] = 1
res = 0
for i in range(10 ** 5 + 1):
p = 0
for j in range(C + 1):
p += t[j][i]
res = max(p, res)
print(res) | 0 | PYTHON3 |
def main():
n = int(input())
s = input()
tab = [0]*10
for char in s:
if char == "L":
for x in range(10):
if tab[x] == 0:
tab[x] = 1
break
elif char == "R":
for x in range(9,-1,-1):
if tab[x] == 0:
tab[x] = 1
break
else:
tab[int(char)] = 0
s = ""
for x in range(10):
s += str(tab[x])
print(s)
main()
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long power(long long a, long long n) {
a %= 1000000007;
if (n == 1) return a;
if (n == 0) return 1;
if (n % 2)
return (a * (power((a * a) % 1000000007, n / 2) % 1000000007)) % 1000000007;
return power((a * a) % 1000000007, n / 2) % 1000000007;
}
const long long inf = (long long)1e18;
long long inverse(long long x) { return power(x, 1000000007 - 2) % 1000000007; }
long long n, dp[200005][15];
vector<long long> adj[200005][4];
long long solve2(long long pos, long long taken) {
if (pos > n) return 0;
long long &ans = dp[pos][taken];
if (ans != -1) return ans;
ans = 0;
if (!adj[pos][3].empty()) {
if (taken == 9)
ans = max(ans, 2 * adj[pos][3][0] + solve2(pos + 1, 0));
else
ans = max(ans, adj[pos][3][0] + solve2(pos + 1, taken + 1));
}
if (!adj[pos][2].empty()) {
if (taken == 9)
ans = max(ans, 2 * adj[pos][2][0] + solve2(pos + 1, 0));
else
ans = max(ans, adj[pos][2][0] + solve2(pos + 1, taken + 1));
if (!adj[pos][1].empty()) {
if (taken >= 8)
ans = max(ans, adj[pos][2][0] + adj[pos][1][0] +
max(adj[pos][2][0], adj[pos][1][0]) +
solve2(pos + 1, (taken + 2) % 10));
else
ans = max(ans,
adj[pos][2][0] + adj[pos][1][0] + solve2(pos + 1, taken + 2));
}
}
if (!adj[pos][1].empty()) {
if (taken == 9)
ans = max(ans, 2 * adj[pos][1][0] + solve2(pos + 1, 0));
else
ans = max(ans, adj[pos][1][0] + solve2(pos + 1, taken + 1));
if ((long long)adj[pos][1].size() > 1) {
if (taken >= 8)
ans = max(ans, 2 * adj[pos][1][0] + adj[pos][1][1] +
solve2(pos + 1, (taken + 2) % 10));
else
ans = max(ans,
adj[pos][1][0] + adj[pos][1][1] + solve2(pos + 1, taken + 2));
}
if ((long long)adj[pos][1].size() > 2) {
if (taken >= 7)
ans = max(ans, 2 * adj[pos][1][0] + adj[pos][1][1] + adj[pos][1][2] +
solve2(pos + 1, (taken + 3) % 10));
else
ans = max(ans, adj[pos][1][0] + adj[pos][1][1] + adj[pos][1][2] +
solve2(pos + 1, taken + 3));
}
}
ans = max(ans, solve2(pos + 1, taken));
return ans;
}
void solve() {
cin >> n;
for (long long i = 1; i < n + 1; ++i) {
long long k;
cin >> k;
for (long long j = 1; j < k + 1; ++j) {
long long c, d;
cin >> c >> d;
adj[i][c].push_back(d);
sort(adj[i][c].begin(), adj[i][c].end(), greater<long long>());
if (c == 3 || c == 2) {
while ((long long)adj[i][c].size() > 1) adj[i][c].pop_back();
} else
while ((long long)adj[i][c].size() > 3) adj[i][c].pop_back();
}
}
memset(dp, -1, sizeof dp);
cout << solve2(1, 0) << "\n";
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
;
long long T = 1;
for (long long t = 1; t < T + 1; ++t) {
solve();
}
return 0;
}
| 12 | CPP |
n=int(input())
x=list(map(int,input().split()))
if x.count(1)>=1:
print('HARD')
else:
print('EASY') | 7 | PYTHON3 |
for _ in range(int(input())):
n=int(input())
list1=list(map(int,input().split()))
if sorted(list1)==list1:
print(0)
else:
if list1[0]==1 and list1[n-1]==n:
flag=0
i=1
j=n-2
while(i<n):
if list1[i]!=i+1:
strt=i
break
i+=1
while(j>=0):
if list1[j]!=j+1:
end=j
break
j-=1
for i in range(strt,end+1):
if list1[i]==i+1:
flag=1
break
if flag==1:
print("2")
else:
print('1')
elif list1[0]==1:
flag=0
i=1
while(i<n):
if list1[i]!=i+1:
strt=i
break
i+=1
for i in range(strt,n):
if list1[i]==i+1:
flag=1
break
if flag==1:
print('2')
else:
print('1')
elif list1[n-1]==n:
flag=0
j=n-1
strt=0
while(j>=0):
if list1[j]!=j+1:
strt=j
break
j-=1
for i in range(strt,-1,-1):
if list1[i]==i+1:
flag=1
break
if flag==1:
print('2')
else:
print('1')
else:
flag=0
for i in range(len(list1)):
if list1[i]==i+1:
flag=1
if flag==0:
print('1')
else:
print('2') | 9 | PYTHON3 |
n = int(input())
t = [int(i) for i in input().split()]
s = sum(t)
ta = 0
i = 0
while ta < s / 2:
ta += t[i]
i += 1
delta_a = ta - t[i-1]
delta_b = s - ta
if delta_a <= delta_b:
pass
else:
i -= 1
print(i, n - i)
| 9 | PYTHON3 |
n=int(input())
L=list(map(int,input().split()))
print(L.count(1))
if L.count(1)==len(L):
print(*L)
else:
x=L.count(1)
c=1
x=x-1
while(x>0):
for i in range(len(L)):
if i<len(L)-1:
if L[i+1]==1:
print(L[i],end=" ")
x-=1
print(L[len(L)-1])
| 7 | PYTHON3 |
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <complex>
#include <map>
#include <climits>
#include <sstream>
using namespace std;
#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second
#define mkp make_pair
static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
static const int INF=1<<24;
template <class T>
void initvv(vector<vector<T> > &v,int a,int b, const T &t = T()){
v.assign(a,vector<T>(b,t));
}
//v.erase(unique(v.begin(),v.end()),v.end());
int main(){
vector<string> v(8);
rep(i,8){
cin>>v[i];
}
cout<<90<<endl;
rep(i,8){
rep(j,8){
cout<<v[7-j][i];
}
cout<<endl;
}
cout<<180<<endl;
rep(i,8){
rep(j,8){
cout<<v[7-i][7-j];
}
cout<<endl;
}
cout<<270<<endl;
rep(i,8){
rep(j,8){
cout<<v[j][7-i];
}
cout<<endl;
}
} | 0 | CPP |
def solve():
n = int(input())
#n,m,k = input().split()
#n = int(n)
#m = int(m)
#k = int(k)
idx1=-1
idy1=-1
idx2=-1
idy2=-1
mark = True
for i in range(n):
a = input()
for j in range(n):
if (a[j]=='*'):
if mark :
idx1= j
idy1= i
mark = False
else :
idx2= j
idy2= i
if (idx1==idx2):
if (idx1==0) :
for i in range(n):
for j in range(n):
if j==idx1 and i==idy1 : print('*',end="")
elif j==idx1+1 and i==idy1 : print('*',end="")
elif j==idx2 and i==idy2 : print('*',end="")
elif j==idx2+1 and i==idy2 : print('*',end="")
else : print('.',end="")
print('')
else :
for i in range(n):
for j in range(n):
if j==idx1 and i==idy1 : print('*',end="")
elif j==idx1-1 and i==idy1 : print('*',end="")
elif j==idx2 and i==idy2 : print('*',end="")
elif j==idx2-1 and i==idy2 : print('*',end="")
else : print('.',end="")
print('')
return 0;
if (idy1==idy2):
if (idy1==0) :
for i in range(n):
for j in range(n):
if j==idx1 and i==idy1 : print('*',end="")
elif j==idx1 and i==idy1+1 : print('*',end="")
elif j==idx2 and i==idy2 : print('*',end="")
elif j==idx2 and i==idy2+1 : print('*',end="")
else : print('.',end="")
print('')
else :
for i in range(n):
for j in range(n):
if j==idx1 and i==idy1 : print('*',end="")
elif j==idx1 and i==idy1-1 : print('*',end="")
elif j==idx2 and i==idy2 : print('*',end="")
elif j==idx2 and i==idy2-1 : print('*',end="")
else : print('.',end="")
print('')
return 0
for i in range(n):
for j in range(n):
if j==idx1 and i==idy1 : print('*',end="")
elif j==idx2 and i==idy1 : print('*',end="")
elif j==idx2 and i==idy2 : print('*',end="")
elif j==idx1 and i==idy2 : print('*',end="")
else : print('.',end="")
print('')
return 0
if __name__=="__main__":
T = int(input())
for i in range(T):
(solve()) | 8 | PYTHON3 |
from math import gcd
from bisect import bisect_left, bisect_right
from itertools import combinations
from itertools import permutations
from bisect import bisect_left
from math import ceil
from heapq import heapify, heappush, heappop, nsmallest
import bisect
from math import pi
from collections import deque
from math import factorial
from math import log, ceil
from collections import defaultdict
from math import *
from sys import stdin, stdout
import itertools
import os
import sys
import threading
from collections import deque, Counter, OrderedDict, defaultdict
from heapq import *
# from math import ceil, floor, log, sqrt, factorial, pow, pi, gcd
# from bisect import bisect_left,bisect_right
# from decimal import *,threading
from fractions import Fraction
mod = int(pow(10, 9)+7)
# mod = 998244353
def ii(): return int(input())
def si(): return str(input())
def mi(): return map(int, input().split())
def li1(): return list(mi())
def fii(): return int(stdin.readline())
def fsi(): return str(stdin.readline())
def fmi(): return map(int, stdin.readline().split())
def fli(): return list(fmi())
abd = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12,
'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24,
'z': 25}
def getKey(item): return item[0]
def sort2(l): return sorted(l, key=getKey)
def d2(n, m, num): return [[num for x in range(m)] for y in range(n)]
def isPowerOfTwo(x): return (x and (not (x & (x - 1))))
def decimalToBinary(n): return bin(n).replace("0b", "")
def ntl(n): return [int(i) for i in str(n)]
def powerMod(x, y, p):
res = 1
x %= p
while y > 0:
if y & 1:
res = (res * x) % p
y = y >> 1
x = (x * x) % p
return res
graph = defaultdict(list)
visited = [0] * 1000000
col = [-1] * 1000000
def bfs(d, v):
q = []
q.append(v)
visited[v] = 1
while len(q) != 0:
x = q[0]
q.pop(0)
for i in d[x]:
if visited[i] != 1:
visited[i] = 1
q.append(i)
print(x)
def make_graph(e):
d = {}
for i in range(e):
x, y = mi()
if x not in d:
d[x] = [y]
else:
d[x].append(y)
if y not in d:
d[y] = [x]
else:
d[y].append(x)
return d
def gr2(n):
d = defaultdict(list)
for i in range(n):
x, y = mi()
d[x].append(y)
return d
def connected_components(graph):
seen = set()
def dfs(v):
vs = set([v])
component = []
while vs:
v = vs.pop()
seen.add(v)
vs |= set(graph[v]) - seen
component.append(v)
return component
ans = []
for v in graph:
if v not in seen:
d = dfs(v)
ans.append(d)
return ans
def primeFactors(n):
s = set()
while n % 2 == 0:
s.add(2)
n = n // 2
for i in range(3, int(sqrt(n)) + 1, 2):
while n % i == 0 and i % 2 == 1:
s.add(i)
n = n // i
if n > 2 and n % 2 == 1:
s.add(n)
return s
def find_all(a_str, sub):
start = 0
while True:
start = a_str.find(sub, start)
if start == -1:
return
yield start
start += len(sub)
def SieveOfEratosthenes(n, isPrime):
isPrime[0] = isPrime[1] = False
for i in range(2, n):
isPrime[i] = True
p = 2
while (p * p <= n):
if (isPrime[p] == True):
i = p * p
while (i <= n):
isPrime[i] = False
i += p
p += 1
return isPrime
def dijkstra(edges, f, t):
g = defaultdict(list)
for l, r, c in edges:
g[l].append((c, r))
q, seen, mins = [(0, f, ())], set(), {f: 0}
while q:
(cost, v1, path) = heappop(q)
if v1 not in seen:
seen.add(v1)
path = (v1, path)
if v1 == t:
return (cost, path)
for c, v2 in g.get(v1, ()):
if v2 in seen:
continue
prev = mins.get(v2, None)
next = cost + c
if prev is None or next < prev:
mins[v2] = next
heappush(q, (next, v2, path))
return float("inf")
def binsearch(a, l, r, x):
while l <= r:
mid = l + (r-1)//2
if a[mid]:
return mid
elif a[mid] > x:
l = mid-1
else:
r = mid+1
return -1
# def input():
# return stdin.buffer.readline()
def readTree(n):
adj = [set() for _ in range(n)]
for _ in range(n-1):
u, v = map(int, input().split())
adj[u-1].add(v-1)
adj[v-1].add(u-1)
return adj
def treeOrderByDepth(n, adj, root=0):
parent = [-2] + [-1]*(n-1)
ordered = []
q = deque()
q.append(root)
depth = [0] * n
while q:
c = q.popleft()
ordered.append(c)
for a in adj[c]:
if parent[a] == -1:
parent[a] = c
depth[a] = depth[c] + 1
q.append(a)
return (ordered, parent, depth)
def isSubSequence(str1, str2):
m = len(str1)
n = len(str2)
j = 0
i = 0
while j < m and i < n:
if str1[j] == str2[i]:
j = j+1
i = i + 1
return j == m
def nextPowerOf2(n):
count = 0
if (n and not(n & (n - 1))):
return n
while(n != 0):
n >>= 1
count += 1
return 1 << count
def lastPowerOf2(n):
count = -1
if (n and not(n & (n - 1))):
return n
while(n != 0):
n >>= 1
count += 1
return 1 << count
def cou(n):
c = 0
while n > 1:
c += 1
n //= 2
return c
def sortsec(l):
return sorted(l, key=lambda x: x[1])
def BinarySearch(a, x):
i = bisect_left(a, x)
if i:
return (i-1)
else:
return - 1
def subarray(A):
r = set()
p = {0}
for x in A:
p = {x | y for y in p} | {x}
r |= p
return len(r)
def setBitNumber(n):
n |= n >> 1
n |= n >> 2
n |= n >> 4
n |= n >> 8
n |= n >> 16
n = n + 1
return (n >> 1)
def countSetBits(n):
count = 0
while (n):
count += n & 1
n >>= 1
return count
def allsub(l):
n = len(l)
a = []
for i in range(n - 1):
a.append([l[:i], l[i:]])
a.append([l[i:], l[:i]])
return a
def closestMultiple(n, x):
if x > n:
return x
z = (int)(x / 2)
n = n + z
n = n - (n % x)
return n
def block(x):
v = []
res = []
while (x > 0):
v.append(int(x % 2))
x = int(x / 2)
for i in range(0, len(v)):
if (v[i] == 1):
res.append(i)
return res
for _ in range(ii()):
n=ii()
p=0
s=si()
for i in range(1,n+1):
if s[i-1] == '0':
if i<=n//2:
print(i,i+n//2,i+1,i+n//2)
p=1
break
else:
print(i-n//2,i,i-n//2,i-1)
p=1
break
if p==0:
print(1,n-1,2,n) | 9 | PYTHON3 |
for _ in range(int(input())):
n = int(input())
s = input()
while '()' in s:
s = s.replace('()','')
print(s.count(')')) | 9 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
constexpr int MAX_V = 5252;
constexpr int INF = (1 << 29);
struct Edge {
int to, cap, rev;
Edge(int to, int cap, int rev) :
to{to}, cap{cap}, rev{rev} {}
};
vector<Edge> G[MAX_V];
int level[MAX_V], iter[MAX_V];
void add_edge(int from, int to, int cap)
{
G[from].push_back(Edge(to, cap, G[to].size()));
G[to].push_back(Edge(from, 0, G[from].size() - 1));
}
void bfs(int s)
{
memset(level, -1, sizeof(level));
queue<int> Q;
level[s] = 0;
Q.push(s);
while (!Q.empty()) {
int v = Q.front(); Q.pop();
for (int i = 0; i < (int)G[v].size(); i++) {
Edge &e = G[v][i];
if (e.cap > 0 && level[e.to] < 0) {
level[e.to] = level[v] + 1;
Q.push(e.to);
}
}
}
}
int dfs(int v, int t, int f)
{
if (v == t) return f;
for (int &i = iter[v]; i < (int)G[v].size(); i++) {
Edge &e = G[v][i];
if (e.cap > 0 && level[v] < level[e.to]) {
int d = dfs(e.to, t, min(f, e.cap));
if (d > 0) {
e.cap -= d;
G[e.to][e.rev].cap += d;
return d;
}
}
}
return 0;
}
int max_flow(int s, int t)
{
int flow = 0;
for (;;) {
bfs(s);
if (level[t] < 0) return flow;
memset(iter, 0, sizeof(iter));
int f;
while ((f = dfs(s, t, INF)) > 0) {
flow += f;
}
}
}
void init()
{
for (int i = 0; i < MAX_V; i++) {
G[i].clear();
}
}
int main()
{
int N, sum = 0;
cin >> N;
vector<int> p(N, 0);
for (int i = 0; i < N; i++) {
cin >> p[i];
sum += 2 * p[i];
}
int S = N, T = S + 1;
int m1 = p[0], m2 = p[N - 1], res = INF;
const int di[2] = {-1, 1};
for (int s = 0; s <= m1; s++) {
p[0] -= s;
for (int t = 0; t <= m2; t++) {
p[N-1] -= t;
init();
for (int i = 0; i < N; i++) {
if (i % 2 == 0) {
add_edge(S, i, p[i] * 2);
for (int j = 0; j < 2; j++) {
int ni = i + di[j];
if (0 <= ni && ni < N && p[ni] > 0) {
add_edge(i, ni, INF);
}
}
} else {
add_edge(i, T, p[i] * 2);
}
}
res = min(res, sum - max_flow(S, T) - (s + t));
p[N-1] += t;
}
p[0] += s;
}
cout << res << endl;
return 0;
} | 0 | CPP |
from collections import deque, defaultdict
from heapq import heapify, heappop, heappush
it = lambda: list(map(int, input().strip().split()))
def solve():
l, r, m = it()
for a in range(l, r + 1):
u1 = m % a
v1 = m // a
if v1 != 0 and l + u1 <= r:
print(a, l + u1, l)
return
v2 = (m // a + 1) * a
u2 = v2 - m
if v2 != 0 and l + u2 <= r:
print(a, l, l + u2)
return
if __name__ == '__main__':
T = int(input())
for _ in range(T):
solve() | 8 | PYTHON3 |
#include<bits/stdc++.h>
using namespace std;
#define fastread ios_base::sync_with_stdio(false);cin.tie(NULL);
#define fileRead freopen("input.txt","r",stdin);
#define fileWrite freopen("output.txt","w",stdout);
#define ll long long
#define mx 100009
int main()
{
int test;
cin>>test;
while(test--)
{
int n,k;
cin>>n>>k;
int from = k/2;
if(k%2)
from++;
//cout<<from<<endl;
vector<int>vec;
for(int i=from;i<=n;i++)
if(i!=k)
vec.push_back(i);
cout<<vec.size()<<endl;
for(int i=0;i<vec.size();i++)
cout<<vec[i]<<" ";
cout<<endl;
}
} | 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int N = 100 * 1000 + 85;
vector<int> s;
string o;
int n, sz;
int solve(int i) {
if (i >= n) {
cout << "Error occurred" << endl;
exit(0);
}
if (s[i] == 2) {
o += "pair";
o += "<";
int it = solve(i + 1);
o += ",";
it = solve(it);
o += ">";
return it;
} else {
o += "int";
return i + 1;
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
string t;
while (cin >> t) {
if (t == "int")
s.push_back(1);
else
s.push_back(2);
}
n = s.size();
if (solve(0) <= n - 1)
cout << "Error occurred" << endl;
else
cout << o << endl;
}
| 9 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
scanf("%i", &n);
vector<pair<int, int>> tree(n);
for (int x = 0; x < n; x++) {
scanf("%i%i", &tree[x].first, &tree[x].second);
}
sort(tree.begin(), tree.end());
int current_day = 0;
for (int i = 0; i < n; i++) {
current_day =
(tree[i].second < tree[i].first && tree[i].second >= current_day)
? tree[i].second
: tree[i].first;
}
printf("%i\n", current_day);
return 0;
}
| 7 | CPP |
p=int(input(),2)
i=0
while (4**i<p):
i+=1
print(i) | 7 | PYTHON3 |
# It's never too late to start!
from bisect import bisect_left, bisect_right
import os
import sys
from io import BytesIO, IOBase
from collections import Counter
from collections import deque, defaultdict
import math
import heapq
import re
def sin():
return input()
def ain():
return list(map(int, sin().split()))
def sain():
return input().split()
def iin():
return int(sin())
LOW = 'abcdefghijklmnopqrstuvwxyz'
UP = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
MAX = float('inf')
MIN = float('-inf')
MOD = 1000000007
def sieve(n):
prime = [True for i in range(n+1)]
p = 2
while (p * p <= n):
if (prime[p] == True):
for i in range(p * p, n+1, p):
prime[i] = False
p += 1
return prime
# Stay hungry, stay foolish!
def main():
n = iin()
l = ain()
l.sort()
ans = 0
d = deque([l[-1]])
for i in range(n-2, -1, -1):
if d[0]>l[i]:
ans += 1
d.popleft()
d.append(l[i])
else:
d.append(l[i])
# print(d)
print(ans)
# Fast IO Template starts
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
if os.getcwd() == 'D:\\code':
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')
else:
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# Fast IO Template ends
if __name__ == "__main__":
main()
# Never Give Up - John Cena | 9 | PYTHON3 |
n=int(input())
s=input()
all=list("abcdefghijklmnopqrstuvwxyz")
s=s.lower()
s=sorted(set(s))
if all==s:
print("YES")
else:
print("NO") | 7 | PYTHON3 |
#8:47
MOD=10**9+7
INT_MAX=10**18+7
def INPUT():return list(int(i) for i in input().split())
def LIST_1D_ARRAY(n):return [0 for _ in range(n)]
def LIST_2D_ARRAY(m,n):return [[0 for _ in range(n)]for _ in range(m)]
def power(a,x):
res=1
while(x>0):
if x&1:
res=(res*a)%MOD
a=(a*a)%MOD
x//=2
return res%MOD
def NCR_MOD(n,r):
num=1
for i in range(n,n-r,-1):num=(num*i)%MOD
for j in range(1,r+1):num=(num*power(j,MOD-2))%MOD
return num
#################################################################################
import math as M
def calc(n):
moves=0
i=n//2
while(n>1):
moves+=(4*n-4)*i
n-=2
i-=1
return moves
for _ in range(int(input())):
n=int(input())
print(calc(n))
| 9 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e17;
const int MOD = 1e9 + 7;
int n, t;
pair<long long, long long> figure[100];
long long p[101];
int main() {
scanf("%d", &n);
for (int(i) = 0; (i) < (n); (i)++)
scanf("%lld %lld", &figure[i].second, &figure[i].first);
sort(figure, figure + n);
scanf("%d", &t);
for (int(i) = 0; (i) < (t); (i)++) scanf("%lld", &p[i]);
p[t++] = INF;
long long an = 0, sum = 0;
for (int(i) = 0; (i) < (n); (i)++) {
long long left = figure[i].second, now = sum;
for (int(j) = 0; (j) < (t); (j)++) {
if (p[j] > now) {
long long add = min(left, p[j] - now);
an += add * figure[i].first * ((long long)j + 1ll);
left -= add;
now += add;
}
}
sum += figure[i].second;
}
printf("%lld\n", an);
return 0;
}
| 9 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int dx[] = {0, 1, 0, 1}, dy[] = {0, 0, 1, 1};
const int maxn = 105;
const int maxm = 105;
struct Ans {
int x1, y1, x2, y2, x3, y3;
Ans(int a, int b, int c, int d, int e, int f)
: x1(a), y1(b), x2(c), y2(d), x3(e), y3(f) {}
};
int n, m, a[maxn][maxm];
int main(void) {
int tc;
scanf("%d", &tc);
while (tc--) {
scanf("%d%d", &n, &m);
vector<pair<int, int> > ord;
vector<Ans> ans;
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= m; ++j) {
scanf("%1d", &a[i][j]);
ord.emplace_back(i, j);
}
sort((ord).begin(), (ord).end(), [](pair<int, int> l, pair<int, int> r) {
return pair<int, int>(l.second, l.first) <
pair<int, int>(r.second, r.first);
});
for (auto& [x, y] : ord) {
if (y > m - 2) break;
if (!a[x][y] && !a[x + dx[1]][y + dy[1]]) continue;
vector<pair<int, int> > v;
int cnt = 3;
for (int i = 0; i < 4; ++i) {
int nx = x + dx[i], ny = y + dy[i];
if (cnt == 4 - i || (cnt > 0 && a[nx][ny])) {
v.emplace_back(nx, ny);
a[nx][ny] = !a[nx][ny];
--cnt;
}
}
ans.emplace_back(v[0].first, v[0].second, v[1].first, v[1].second,
v[2].first, v[2].second);
}
int y = m - 1;
for (int x = 1; x <= n - 2; ++x) {
if (!a[x][y] && !a[x][y + 1]) continue;
vector<pair<int, int> > v;
int cnt = 3;
if (a[x][y]) {
v.emplace_back(x, y);
a[x][y] = 0;
--cnt;
}
if (a[x][y + 1]) {
v.emplace_back(x, y + 1);
a[x][y + 1] = 0;
--cnt;
}
if (cnt > 0) {
v.emplace_back(x + 1, y + 1);
a[x + 1][y + 1] = !a[x + 1][y + 1];
--cnt;
}
if (cnt > 0) {
v.emplace_back(x + 1, y);
a[x + 1][y] = !a[x + 1][y];
--cnt;
}
ans.emplace_back(v[0].first, v[0].second, v[1].first, v[1].second,
v[2].first, v[2].second);
}
int cnt = a[n - 1][m - 1] + a[n - 1][m] + a[n][m - 1] + a[n][m];
if (cnt == 4) {
ans.emplace_back(n - 1, m - 1, n - 1, m, n, m - 1);
a[n - 1][m - 1] = a[n - 1][m] = a[n][m - 1] = 0;
cnt = 1;
}
if (cnt == 1) {
if (a[n][m]) {
ans.emplace_back(n - 1, m - 1, n, m - 1, n, m);
a[n - 1][m - 1] = !a[n - 1][m - 1];
a[n][m - 1] = !a[n][m - 1];
a[n][m] = !a[n][m];
} else {
ans.emplace_back(n - 1, m - 1, n, m - 1, n - 1, m);
a[n - 1][m - 1] = !a[n - 1][m - 1];
a[n][m - 1] = !a[n][m - 1];
a[n - 1][m] = !a[n - 1][m];
}
cnt = 2;
}
if (cnt == 2) {
int x = n - 1, y = m - 1;
int j = -1;
for (int i = 0; i < 4; ++i) {
if (a[x + dx[i]][y + dy[i]]) {
j = i;
break;
}
}
vector<pair<int, int> > v;
for (int i = 0; i < 4; ++i)
if (i != j) {
int nx = x + dx[i], ny = y + dy[i];
a[nx][ny] = !a[nx][ny];
v.emplace_back(nx, ny);
}
ans.emplace_back(v[0].first, v[0].second, v[1].first, v[1].second,
v[2].first, v[2].second);
cnt = 3;
}
if (cnt == 3) {
int x = n - 1, y = m - 1;
vector<pair<int, int> > v;
for (int i = 0; i < 4; ++i) {
int nx = x + dx[i], ny = y + dy[i];
if (!a[nx][ny]) continue;
a[nx][ny] = !a[nx][ny];
v.emplace_back(nx, ny);
}
ans.emplace_back(v[0].first, v[0].second, v[1].first, v[1].second,
v[2].first, v[2].second);
cnt = 0;
}
printf("%d\n", ans.size());
for (auto& t : ans)
printf("%d %d %d %d %d %d\n", t.x1, t.y1, t.x2, t.y2, t.x3, t.y3);
}
return 0;
}
| 7 | CPP |
import math
a, b, C = map(float, input().split())
C = math.radians(C)
print(1/2 * a * b * math.sin(C))
c = (a ** 2 + b ** 2 - 2 * a * b * math.cos(C)) ** 0.5
print(a + b + c)
print(b * math.sin(C))
| 0 | PYTHON3 |
for _ in ' '*int(input()):
s = 0
for x in sorted(input().split('0'))[::-1][::2]: s+=len(x)
print(s) | 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
string to_string(pair<A, B> p);
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);
string to_string(const string &s) { return '"' + s + '"'; }
string to_string(const char *s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
string to_string(vector<bool> v) {
bool first = true;
string res = "{";
for (int i = 0; i < static_cast<int>(v.size()); i++) {
if (!first) {
res += ", ";
}
first = false;
res += to_string(v[i]);
}
res += "}";
return res;
}
template <size_t N>
string to_string(bitset<N> v) {
string res = "";
for (size_t i = 0; i < N; i++) {
res += static_cast<char>('0' + v[i]);
}
return res;
}
template <typename A>
string to_string(A v) {
bool first = true;
string res = "{";
for (const auto &x : v) {
if (!first) {
res += ", ";
}
first = false;
res += to_string(x);
}
res += "}";
return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
to_string(get<2>(p)) + ")";
}
template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
cerr << " " << to_string(H);
debug_out(T...);
}
const long double PI = -acos(-1.0);
struct Complex {
double x, y;
Complex(double _x = 0.0, double _y = 0.0) {
x = _x;
y = _y;
}
Complex operator+(const Complex &b) const {
return Complex(x + b.x, y + b.y);
}
Complex operator-(const Complex &b) const {
return Complex(x - b.x, y - b.y);
}
Complex operator*(const Complex &b) const {
return Complex(x * b.x - y * b.y, x * b.y + y * b.x);
}
};
void change(Complex y[], int len) {
int i, j, k;
for (i = 1, j = len / 2; i < len - 1; i++) {
if (i < j) swap(y[i], y[j]);
k = len / 2;
while (j >= k) {
j -= k;
k /= 2;
}
if (j < k) j += k;
}
}
void fft(Complex y[], int len, int on) {
change(y, len);
for (int h = 2; h <= len; h <<= 1) {
Complex wn(cos(-on * 2 * PI / h), sin(-on * 2 * PI / h));
for (int j = 0; j < len; j += h) {
Complex w(1, 0);
for (int k = j; k < j + h / 2; k++) {
Complex u = y[k];
Complex t = w * y[k + h / 2];
y[k] = u + t;
y[k + h / 2] = u - t;
w = w * wn;
}
}
}
if (on == -1) {
for (int i = 0; i < len; i++) {
y[i].x /= len;
}
}
}
const int MAXN = 1 << 18;
Complex A[MAXN + 10];
Complex Ai[MAXN + 10];
Complex Ax[MAXN + 10];
Complex B[MAXN + 10];
Complex Bi[MAXN + 10];
Complex Bx[MAXN + 10];
Complex z[MAXN + 10];
long long Q1[MAXN + 10];
long long Q2[MAXN + 10];
long long E11[MAXN + 10];
long long E12[MAXN + 10];
long long E21[MAXN + 10];
long long E22[MAXN + 10];
long long V[MAXN + 10];
long long W1[MAXN + 10];
long long W2[MAXN + 10];
void mul(Complex x[], Complex y[], int len, long long ans[]) {
for (int i = 0; i < len; i++) {
z[i] = x[i] * y[i];
}
fft(z, len, -1);
for (int i = 0; i < len; i++) {
ans[i] = z[i].x + 0.5;
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m, q;
cin >> n >> m >> q;
vector<int> a(n), b(m);
for (int i = 0; i < MAXN; i++) {
A[i] = {0, 0};
Ai[i] = {0, 0};
Ax[i] = {0, 0};
B[i] = {0, 0};
Bi[i] = {0, 0};
Bx[i] = {0, 0};
}
for (int i = 0; i < n; i++) {
cin >> a[i];
A[a[i]] = A[a[i]] + Complex(1, 0);
}
for (int i = 0; i < m; i++) {
cin >> b[i];
B[b[i]] = B[b[i]] + Complex(1, 0);
}
for (int i = 0; i < n - 1; i++) {
Ai[min(a[i], a[i + 1])] = Ai[min(a[i], a[i + 1])] + Complex(1, 0);
Ax[max(a[i], a[i + 1])] = Ax[max(a[i], a[i + 1])] + Complex(1, 0);
}
for (int i = 0; i < m - 1; i++) {
Bi[min(b[i], b[i + 1])] = Bi[min(b[i], b[i + 1])] + Complex(1, 0);
Bx[max(b[i], b[i + 1])] = Bx[max(b[i], b[i + 1])] + Complex(1, 0);
}
fft(A, MAXN, 1);
fft(Ai, MAXN, 1);
fft(Ax, MAXN, 1);
fft(B, MAXN, 1);
fft(Bi, MAXN, 1);
fft(Bx, MAXN, 1);
mul(A, B, MAXN, V);
mul(A, Bi, MAXN, E11);
mul(Ai, B, MAXN, E12);
mul(A, Bx, MAXN, E21);
mul(Ax, B, MAXN, E22);
mul(Ai, Bi, MAXN, Q1);
mul(Ax, Bx, MAXN, Q2);
for (int i = 0; i < MAXN; i++) {
W1[i] = -E11[i] - E12[i] + V[i] + Q1[i];
W2[i] = E21[i] + E22[i] - V[i] - Q2[i];
}
for (int i = 1; i < MAXN; i++) {
W2[i] = W2[i] + W2[i - 1];
}
for (int i = MAXN - 2; i >= 0; i--) {
W1[i] = W1[i] + W1[i + 1];
}
while (q--) {
int x;
cin >> x;
cout << W1[x] + W2[x - 1] << '\n';
}
return 0;
}
| 15 | CPP |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
int n, a[510], dp[510][510];
inline bool pali(int x, int y) {
for (int i = x, j = y; i < j; i++, j--)
if (a[i] != a[j]) return false;
return true;
}
int main() {
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < 505; i++)
for (int j = 0; j < 505; j++) dp[i][j] = 1e9;
for (int i = 0; i < n; i++) {
for (int j = i; j < n; j++)
if (pali(i, j)) dp[i][j] = 1;
}
for (int len = 2; len <= n; len++) {
for (int i = 0; i < n; i++) {
if (i + len - 1 >= n) continue;
int j = i + len - 1;
for (int k = i; k < j; k++)
dp[i][j] = min(dp[i][j], dp[i][k] + dp[k + 1][j]);
if (len > 2 && a[i] == a[j]) dp[i][j] = min(dp[i][j], dp[i + 1][j - 1]);
}
}
cout << dp[0][n - 1] << endl;
return 0;
}
| 10 | CPP |
from math import gcd
for _ in range(int(input())):
a, b, c = map(int, input().split())
x = 10 ** (a - 1)
y = 10 ** (b - 1)
if a <= b:
x += 10 ** (c - 1)
else:
y += 10 ** (c - 1)
print(x, y) | 8 | PYTHON3 |
a,b = map(int, input().split())
ans = 1
if b-a >= 10:
print(0)
else:
for x in range(b,a,-1):
ans*=x
print(str(ans)[-1]) | 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int r, c;
cin >> r >> c;
int ans = 0;
bool hole = true;
for (int i = 0; i < r; i++) {
string s;
cin >> s;
if (i + 1 == r) {
for (int j = 0; j < c; j++) {
if (s[j] == 'B') {
ans += hole;
hole = false;
} else {
hole = true;
}
}
}
}
cout << ans;
return 0;
}
| 10 | CPP |
t = int(input())
for i in range(t):
n = int(input())
lst = list(map(int, input().split()))
lst.sort()
maxi = max(lst)
mini = min(lst)
if maxi == mini:
print(n)
else:
print(1)
| 7 | PYTHON3 |
#include<bits/stdc++.h>
using namespace std;
#define F(i,a,b) for(int i=a;i<=(b);++i)
#define ll long long
int k,a[100001],vis[100001];
priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > > pq;
int c[100001];
int main(){
scanf("%d",&k);
memset(a,0x3f,sizeof a);
a[1]=1; pq.push(make_pair(1,1));
while(!pq.empty()){
pair<int,int> P=pq.top(); pq.pop();
int u=P.second, d=P.first;
if(vis[u]) continue;
int v=(u+1)%k;
if(a[v]>d+1) a[v]=d+1, pq.push(make_pair(a[v],v));
for(int i=u;;i=i*10%k){
if(c[i]||vis[i]) break;
if(a[i]>d) a[i]=d, pq.push(make_pair(a[i],i));
c[i]=1;
}
for(int i=u;;i=i*10%k){
if(!c[i]) break;
c[i]=0;
}
vis[u]=1;
} printf("%d",a[0]);
return 0;
} | 0 | CPP |
n = int(int(input()))
parent = [0,0] + list(map(int, input().split()))
color = [0] + list(map(int, input().split()))
cnt = 1
for i in range(2,n+1,1):
if color[i] != color[parent[i]]:
cnt += 1
print(cnt) | 8 | PYTHON3 |
t=int(input())
for _ in range(t):
n,m=map(int,input().split())
a=[]
for i in range(n):
b=list(input())
a.append(b)
c=0
for i in range(n):
if(a[i][m-1]=='R'):
c+=1
a[i][m-1]='D'
for i in range(m):
if(a[n-1][i]=='D'):
c+=1
a[n-1][i]='R'
print(c)
| 8 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
long long s[102];
int main() {
long long i, j, ans, n, m, maxn;
cin >> n;
for (i = 0; i < n; i++) cin >> s[i];
ans = 0;
for (i = 0; i < n; i++) {
if (s[i] == 1)
ans++;
else {
if (s[i - 1] == 1 && s[i + 1] == 1) ans++;
}
}
cout << ans << endl;
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
struct marks {
long long got;
long long essays;
};
bool compare(marks mark1, marks mark2) { return (mark1.essays < mark2.essays); }
int main() {
long long n, r, avg, i;
cin >> n >> r >> avg;
long long req = n * avg;
marks mark[n];
long long sum = 0;
for (i = 0; i < n; i++) {
cin >> mark[i].got;
cin >> mark[i].essays;
sum += mark[i].got;
}
sort(mark, mark + n, compare);
long long wrote = 0;
long long temp1 = 0, temp2 = 0;
temp1 = req - sum;
if (temp1 <= 0) {
cout << "0";
return 0;
}
long long temp3 = 0;
for (i = 0; i < n; i++) {
if (temp1 == 0) break;
temp2 = mark[i].got + temp1;
if (temp2 > r) temp2 = r;
temp3 = temp2 - mark[i].got;
wrote += temp3 * (mark[i].essays);
temp1 -= temp3;
}
cout << wrote;
}
| 9 | CPP |
q = int(input())
for i in range(q):
a = list(map(int, input().split()))
n = a[3]
max1 = max(a[0:3])
n -= 3 * max1 - a[0] - a[1] - a[2]
if n >= 0 and n % 3 == 0:
print("YES")
else:
print("NO")
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int TAM = 1e5 + 10;
struct Nodo {
int id, s, a, b;
};
inline bool byS(const Nodo& x, const Nodo& y) { return x.s < y.s; }
inline bool byID(const Nodo& x, const Nodo& y) { return x.id < y.id; }
int n;
Nodo nodo[TAM];
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) {
scanf("%d", &nodo[i].s);
nodo[i].id = i;
}
sort(nodo, nodo + n, byS);
int l = (n + 2) / 3;
for (int i = 0; i < l; i++) {
nodo[i].a = i;
nodo[i].b = nodo[i].s - nodo[i].a;
}
l = n - n / 3;
for (int i = (n + 2) / 3; i < l; i++) {
nodo[i].b = i;
nodo[i].a = nodo[i].s - nodo[i].b;
}
for (int i = n - n / 3; i < n; i++) {
nodo[i].b = n - 1 - i;
nodo[i].a = nodo[i].s - nodo[i].b;
}
sort(nodo, nodo + n, byID);
puts("YES");
for (int i = 0; i < n; i++) printf("%d ", nodo[i].a);
puts("");
for (int i = 0; i < n; i++) printf("%d ", nodo[i].b);
puts("");
return 0;
}
| 9 | CPP |
#include <iostream>
using namespace std;
int main(){
char a;
cin >> a;
char ans;
ans = (a == 'A') ? 'T' : (a == 'T') ? 'A' : (a == 'G') ? 'C' : 'G';
cout << ans << endl;
}
| 0 | CPP |
n, c = [int(i) for i in input().split()]
for _ in range(c):
if n%10==0:
n = n/10
else:
n = n-1
print(int(n)) | 7 | PYTHON3 |
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
using namespace std;
#define FOR(i,k,n) for(int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cerr<<*i<<" "; cerr<<endl; }
inline bool valid(int x, int y, int W, int H){ return (x >= 0 && y >= 0 && x < W && y < H); }
typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int popcount(int N){
return __builtin_popcount(N);
}
int main(){
int N, M;
while(cin >> N >> M && N){
vector<int> L(N);
REP(i, N) cin >> L[i];
static int dp[1000][1 << 12] = {};
memset(dp, -1, sizeof(dp));
for(int S = 0; S < 1 << M; S++){
if(popcount(S) == L[0]) dp[0][S] = 0;
}
int mask = (1 << M) - 1;
for(int i = 1; i < N; i++){
for(int S = 0; S < 1 << M; S++){
if(dp[i - 1][S] != -1){
int NS = S << 1 & mask;
if(popcount(NS) == L[i]) dp[i][NS] = S;
NS |= 1;
if(popcount(NS) == L[i]) dp[i][NS] = S;
}
}
}
int CRS = -1;
for(int S = 0; S < 1 << M; S++) if(dp[N - 1][S] != -1) CRS = S;
if(CRS == -1){
cout << "Goofy" << endl;
continue;
}
vector<int> ans;
for(int i = N - 1; i >= 0; i--){
ans.push_back(CRS & 1);
if(i != 0) CRS = dp[i][CRS];
}
for(int i = 1; i < M; i++) ans.push_back(CRS >> i & 1);
reverse(ans.begin(), ans.end());
for(int i = 0; i < ans.size(); i++) cout << ans[i];
cout << endl;
}
return 0;
} | 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
while (n--) {
int a, b;
cin >> a >> b;
int x = b / a;
int y = b % a;
long long res = 0;
for (int i = 0; i < y; i++) {
res += (x + 1) * (x + 1);
}
for (int i = 0; i < a - y; i++) {
res += x * x;
}
cout << res << endl;
}
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, m, lo, hi, mid, dist, max_dist, val;
cin >> n >> m;
int homes[n];
int towers[m];
for (int i = 0; i < n; ++i) {
cin >> homes[i];
}
for (int i = 0; i < m; ++i) {
cin >> towers[i];
}
lo = 0;
max_dist = 0;
for (int i = 0; i < n; ++i) {
hi = m;
val = homes[i];
if (val < towers[0]) {
dist = towers[0] - val;
} else if (val > towers[m - 1]) {
dist = val - towers[m - 1];
} else {
while (lo < hi - 1) {
mid = lo + (hi - lo) / 2;
if (towers[mid] <= val) {
lo = mid;
} else {
hi = mid;
}
}
dist = min(val - towers[lo], towers[hi] - val);
}
if (dist > max_dist) {
max_dist = dist;
}
}
cout << max_dist << endl;
}
| 9 | CPP |
p=input
n,m=map(int,p().split())
l=[p().split()for _ in[0]*n]
print(max([sum(sorted([sum([int(x[i])*[1,-1][k>>i&1]for i in range(3)])for x in l])[::-1][:m])for k in range(8)])) | 0 | PYTHON3 |
a, b, c, n = map(int, input().split())
s = a + b - c
p = n - s
if a >= n or b >= n or c >= n or s >= n or c > a or c > b:
print(-1)
else:
print(p)
| 7 | PYTHON3 |
#include <bits/stdc++.h>
int n, i, a[5] = {100, 20, 10, 5, 1}, ans;
int main() {
scanf("%d", &n);
for (i = ans = 0; i < 5; i++) {
ans += n / a[i];
n %= a[i];
}
printf("%d\n", ans);
return 0;
}
| 7 | CPP |
n, m, a = map (int, input().split(' ') )
if(n%a==0 and m%a==0):
k = (n//a)*(m//a)
elif(n%a!=0 and m%a==0):
k = (n//a+1)*(m//a)
elif(n%a==0 and m%a!=0):
k = (n//a)*(m//a+1)
else:
k = (n//a+1)*(m//a+1)
print (k)
| 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
int t;
cin >> t;
while (t--) {
int n, d;
cin >> n >> d;
int D = (int)(ceil(log2(n + 1))) - 1;
int minsd = (n + 1) * D - (1 << (D + 1)) + 2;
if (d < minsd || d > (n * (n - 1) / 2)) {
cout << "NO\n";
continue;
}
cout << "YES\n";
int *dep = new int[n + 1], p[n + 1], c[n + 1];
vector<int> v;
for (int i = 0; i < n + 1; i++) {
v.push_back(i);
c[i] = 0;
}
for (int i = 0; i < n + 1; i++) {
p[i] = (i >> 1);
if (2 * i <= n) c[i]++;
if (2 * i + 1 <= n) c[i]++;
dep[i] = (int)ceil(log2(i + 1)) - 1;
}
auto fun = [dep](int a, int b) { return dep[a] < dep[b]; };
for (int sd = minsd + 1; sd <= d && sd <= n * (n - 1) / 2; sd++) {
sort(v.begin(), v.end(), fun);
int a = -1, b = -1, i = 1;
while (i <= n) {
int a1 = -1, b1 = -1;
int de = dep[v[i]];
while (i <= n && dep[v[i]] == de) {
if (a1 == -1 && c[v[i]] == 0)
a1 = v[i];
else if (a1 != -1 && c[v[i]] < 2)
b1 = v[i];
if (b1 == -1 && c[v[i]] == 1) b1 = v[i];
if (a1 != -1 && b1 != -1) break;
i++;
}
if (a1 != -1 && b1 != -1) {
a = a1;
b = b1;
break;
}
}
c[p[a]]--;
p[a] = b;
c[b]++;
dep[a]++;
}
for (int i = 2; i <= n; i++) cout << p[i] << " ";
cout << endl;
}
}
| 11 | CPP |
def main():
n = int(input())
C = [25,10,5,1]
ans = 0
for i in range(4):
ans += n // C[i]
n %= C[i]
print(ans)
if __name__ == "__main__":
main()
| 0 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int MX = 2e5 + 5;
const long long INF = 1e18;
const long double PI = acos((long double)-1);
const int xd[4] = {1, 0, -1, 0}, yd[4] = {0, 1, 0, -1};
template <class T>
bool ckmin(T& a, const T& b) {
return b < a ? a = b, 1 : 0;
}
template <class T>
bool ckmax(T& a, const T& b) {
return a < b ? a = b, 1 : 0;
}
int pct(int x) { return __builtin_popcount(x); }
int bit(int x) { return 31 - __builtin_clz(x); }
int cdiv(int a, int b) { return a / b + !(a < 0 || a % b == 0); }
template <class A>
void re(complex<A>& c);
template <class A, class B>
void re(pair<A, B>& p);
template <class A>
void re(vector<A>& v);
template <class A, size_t SZ>
void re(array<A, SZ>& a);
template <class T>
void re(T& x) {
cin >> x;
}
void re(double& d) {
string t;
re(t);
d = stod(t);
}
void re(long double& d) {
string t;
re(t);
d = stold(t);
}
template <class H, class... T>
void re(H& h, T&... t) {
re(h);
re(t...);
}
template <class A>
void re(complex<A>& c) {
A a, b;
re(a, b);
c = {a, b};
}
template <class A, class B>
void re(pair<A, B>& p) {
re(p.first, p.second);
}
template <class A>
void re(vector<A>& x) {
for (auto& a : x) re(a);
}
template <class A, size_t SZ>
void re(array<A, SZ>& x) {
for (auto& a : x) re(a);
}
template <class A, class B>
string to_string(pair<A, B> p);
template <class A>
string to_string(complex<A> c) {
return to_string(make_pair(c.real(), c.imag()));
}
string to_string(bool b) { return b ? "true" : "false"; }
string to_string(char c) {
string second = "";
second += c;
return second;
}
string to_string(string second) { return second; }
string to_string(const char* second) { return (string)second; }
string to_string(vector<bool> v) {
bool fst = 1;
string res = "{";
for (int i = (0); i < ((int)v.size()); ++i) {
if (!fst) res += ", ";
fst = 0;
res += to_string(v[i]);
}
res += "}";
return res;
}
template <size_t SZ>
string to_string(bitset<SZ> b) {
string res = "";
for (int i = (0); i < (SZ); ++i) res += char('0' + b[i]);
return res;
}
template <class T>
string to_string(T v) {
bool fst = 1;
string res = "{";
for (const auto& x : v) {
if (!fst) res += ", ";
fst = 0;
res += to_string(x);
}
res += "}";
return res;
}
template <class A, class B>
string to_string(pair<A, B> p) {
return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <class A>
void pr(A x) {
cout << to_string(x);
}
template <class H, class... T>
void pr(const H& h, const T&... t) {
pr(h);
pr(t...);
}
void ps() { pr("\n"); }
template <class H, class... T>
void ps(const H& h, const T&... t) {
pr(h);
if (sizeof...(t)) pr(" ");
ps(t...);
}
void DBG() { cerr << "]" << endl; }
template <class H, class... T>
void DBG(H h, T... t) {
cerr << to_string(h);
if (sizeof...(t)) cerr << ", ";
DBG(t...);
}
void setIn(string second) { freopen(second.c_str(), "r", stdin); }
void setOut(string second) { freopen(second.c_str(), "w", stdout); }
void unsyncIO() {
ios_base::sync_with_stdio(0);
cin.tie(0);
}
void setIO(string second = "") {
unsyncIO();
if ((int)second.size()) {
setIn(second + ".in"), setOut(second + ".out");
}
}
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());
int n;
string gr[18];
vector<int> v;
vector<vector<int> > part;
map<vector<int>, int> rpart;
vector<int> cur = {1};
vector<long long> val;
long long ans[1 << 17];
void gen(int sum) {
if (sum == n) {
part.push_back(cur);
return;
}
if (sum + cur.back() <= n) {
cur.push_back(cur.back());
gen(sum + cur.back());
cur.pop_back();
}
cur.back()++;
gen(sum + 1);
cur.back()--;
}
int CNT;
vector<long long> num;
void GEN(int sum, long long prod) {
if (sum == n) {
val[CNT++] += prod * num[cur.back()];
return;
}
if (sum + cur.back() <= n) {
cur.push_back(cur.back());
GEN(sum + cur.back(), prod * num[cur.back()]);
cur.pop_back();
}
cur.back()++;
GEN(sum + 1, prod);
cur.back()--;
}
int main() {
setIO();
re(n);
for (int i = (0); i < (n); ++i) re(gr[i]);
gen(1);
val.resize((int)part.size());
for (int i = (0); i < ((int)part.size()); ++i) rpart[part[i]] = i;
for (int i = (0); i < (1 << n); ++i) {
vector<long long> cur(n);
for (int j = (0); j < (n); ++j)
if (i & (1 << j)) cur[j] = 1;
num = vector<long long>(n + 1);
for (int z = (1); z < (n + 1); ++z) {
for (auto& t : cur) num[z] += t;
vector<long long> CUR(n);
for (int j = (0); j < (n); ++j)
if (i & (1 << j))
for (int k = (0); k < (n); ++k)
if (i & (1 << k))
if (gr[j][k] == '1') CUR[k] += cur[j];
swap(cur, CUR);
}
int par = (n - pct(i)) & 1;
if (par == 0)
par = 1;
else
par = -1;
CNT = 0;
GEN(1, par);
}
for (int i = (0); i < (1 << (n - 1)); ++i) {
vector<int> len = {1};
for (int j = (0); j < (n - 1); ++j) {
if (i & (1 << j))
len.back()++;
else
len.push_back(1);
}
sort(begin(len), end(len));
ans[i] = val[rpart[len]];
}
for (int j = (0); j < (n - 1); ++j)
for (int i = (0); i < (1 << (n - 1)); ++i)
if (i & (1 << j)) ans[i ^ (1 << j)] -= ans[i];
for (int i = (0); i < (1 << (n - 1)); ++i) pr(ans[i], ' ');
ps();
}
| 12 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
float a, b, c, d;
scanf("%f %f %f %f", &a, &b, &c, &d);
if (max(3 * a / 10, a - (a * c / 250)) > max(3 * b / 10, b - (b * d / 250)))
printf("Misha");
if (max(3 * a / 10, a - (a * c / 250)) < max(3 * b / 10, b - (b * d / 250)))
printf("Vasya");
if (max(3 * a / 10, a - (a * c / 250)) == max(3 * b / 10, b - (b * d / 250)))
printf("Tie");
return 0;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
int dp[100002][7], a[100002];
int32_t main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 2; i <= n; i++) {
for (int j = 1; j <= 5; j++) {
dp[i][j] = -1;
}
}
for (int i = 2; i <= n; i++) {
for (int l = 1; l <= 5; l++) {
if (a[i] > a[i - 1]) {
for (int j = 1; j < l; j++) {
if (dp[i - 1][j] != -1) {
dp[i][l] = j;
break;
}
}
}
if (a[i] < a[i - 1]) {
for (int j = 5; j > l; j--) {
if (dp[i - 1][j] != -1) {
dp[i][l] = j;
break;
}
}
}
if (a[i] == a[i - 1]) {
for (int j = 1; j <= 5; j++) {
if (j != l && dp[i - 1][j] != -1) {
dp[i][l] = j;
break;
}
}
}
}
}
for (int i = 1; i < 6; i++) {
if (dp[n][i] != -1) {
vector<int> ans;
ans.push_back(i);
int k = i;
for (int j = n; j >= 2; j--) {
k = dp[j][k];
ans.push_back(k);
}
reverse(ans.begin(), ans.end());
for (auto j : ans) cout << j << " ";
return 0;
}
}
cout << -1;
return 0;
}
| 9 | CPP |
#include <iostream>
#include <string>
using namespace std;
int main(){
int n, h, w;
cin >> n >> h >> w;
cout << (n + 1 - h) * (n + 1 - w) << endl;
} | 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
const long long N = 2005;
long long x[N], y[N];
long long n;
long long gcd(long long a, long long b) {
if (b == 0)
return a;
else
return gcd(b, a % b);
}
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
cin >> n;
for (long long i = 1; i <= n; i++) cin >> x[i] >> y[i];
long long ans = (n * (n - 1) * (n - 2)) / 6;
long long sub = 0;
for (long long i = 1; i < n; i++) {
map<pair<long long, long long>, long long> m;
for (long long j = i + 1; j <= n; j++) {
long long xd = x[j] - x[i];
long long yd = y[j] - y[i];
if (xd == 0)
yd = 0;
else if (yd == 0)
xd = 1;
else {
long long r = gcd(xd, yd);
xd /= r;
yd /= r;
if (xd < 0 && yd > 0) {
xd *= -1;
yd *= -1;
}
}
m[{xd, yd}]++;
}
for (auto it : m) {
long long k = it.second;
sub += (k * (k - 1)) / 2;
}
}
cout << ans - sub;
return 0;
}
| 10 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
while (t--) {
int n, x, num;
cin >> n >> x;
vector<int> cnt(1000, 0);
for (__typeof(0) i = (0); i < (n); i++) {
cin >> num;
cnt[num]++;
}
int i = 1;
for (; i < 1000; i++) {
if (cnt[i] == 0) {
if (x == 0) {
i--;
break;
}
x--;
}
}
cout << i << '\n';
}
return 0;
}
| 7 | CPP |
nk=str(input()).split()
scores=str(input()).split()
i = 0
while int(scores[i]) >= int(scores[int(nk[1])-1]) and int(scores[i]) > 0:
i += 1
if i == int(nk[0]):
break
print(i) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
struct trap {
int l;
int r;
int lvl;
bool operator<(const trap& tp) const {
if (l != tp.l) return l < tp.l;
return r < tp.r;
}
};
int m, n, k, t, ma, mi, mid;
int a[(int)2e5 + 5];
trap b[(int)2e5 + 5];
bool ch(int val) {
int i = 1, ti = n + 1, l, r;
while (i <= k) {
if (b[i].lvl > val) {
l = b[i].l, r = b[i].r;
while (i <= k && b[i].l <= r) {
if (b[i].lvl > val) r = max(r, b[i].r);
i++;
}
ti += r - l + 1 << 1;
} else
i++;
}
if (ti > t) return false;
return true;
}
int bs() {
if (!ch(a[m])) return 0;
ma = m, mi = 1;
while (mi < ma) {
mid = mi + ma >> 1;
if (ch(a[mid]))
ma = mid;
else
mi = mid + 1;
}
return m - mi + 1;
}
int main() {
int x, y, z;
scanf("%d%d%d%d", &m, &n, &k, &t);
for (int i = 1; i <= m; i++) {
scanf("%d", &a[i]);
}
sort(a + 1, a + m + 1);
for (int i = 1; i <= k; i++) {
scanf("%d%d%d", &x, &y, &z);
b[i] = {x, y, z};
}
sort(b + 1, b + k + 1);
printf("%d", bs());
}
| 10 | CPP |
k,r = [int(x) for x in input().split()]
val = k
count = 1
while (k-r)%10 != 0 and k%10 != 0:
count += 1
k += val
print(count)
| 7 | PYTHON3 |
"""
Code of Ayush Tiwari
Codeforces: servermonk
Codechef: ayush572000
"""
import sys
input = sys.stdin.buffer.readline
def solution():
# This is the main code
l,r=map(int,input().split())
x=l
y=2*l
if y<=r:
print(x,y)
else:
print(-1,-1)
for _ in range(int(input())):
solution() | 7 | PYTHON3 |
#include<bits/stdc++.h>
using namespace std;
int N,K;
int dp[2][1001][1001];
int dm[2][1001][1001];
int a[1000];
int main(){
scanf("%d %d",&N,&K);
for(int i=0;i<N;i++)scanf("%d",&a[i]);
sort(a,a+N);
fill( (int*)dp[0], (int*)dp[1], 1e9);
int ans=1e9;
for(int T=1;T<=K;T++){
int t=T%2;
int u=1-t;
fill( (int*)dp[t], (int*)dp[t+1], 1e9);
for(int i=0;i<N;i++){
dp[0][i][i+1]=0;
dp[1][i][i+1]=0;
}
for(int w=2;w<=N;w++){
for(int i=0;i+w<=N;i++){
int j=i+w;
int si=i+1;
int ti=j-1;
if(w>2){
si=dm[t][i][j-1];
ti=dm[t][i+1][j];
}
for(int k=si;k<=ti;k++){
if(dp[t][i][j] > dp[u][i][k]+dp[u][k][j]+a[j-1]-a[k-1]){
dp[t][i][j]=dp[u][i][k]+dp[u][k][j]+a[j-1]-a[k-1];
dm[t][i][j]=k;
}
}
if(i==0&&j==N)ans=min(ans,dp[t][i][j]);
}
}
}
printf("%d\n",ans);
return 0;
} | 0 | CPP |
t = int(input())
for _ in range(t):
n = int(input())
xs = [int(x) for x in input().split()]
all_wrong = True
all_right = True
streak = False
streaks = 0
for i, x in enumerate(xs):
if x == i + 1:
# all_wrong = False
if streak:
streak = False
else:
# all_right = False
if not streak:
streak = True
streaks += 1
if streaks == 2:
break
else:
print(streaks)
continue
print(2)
| 9 | PYTHON3 |
a=int(input())
for n in range(a):
p,q,n=map(int,input().split())
y=min(q,n)
print(p-y+1) | 7 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
long long cp(const complex<long long>& a, const complex<long long>& b) {
return a.real() * b.imag() - b.real() * a.imag();
}
struct comp {
const bool operator()(const complex<long long>& l,
const complex<long long>& r) const {
if (l.imag() == r.imag()) return l.real() < r.real();
return l.imag() < r.imag();
}
} cmp_lex_i;
vector<complex<long long> > chull(vector<complex<long long> > p) {
sort(p.begin(), p.end(), cmp_lex_i);
int top = 0, bot = 1;
vector<complex<long long> > ch(2 * p.size());
for (int i = 0, d = 1; i < p.size() && i >= 0; i += d) {
while (top > bot && cp(ch[top - 1] - ch[top - 2], p[i] - ch[top - 2]) < 0)
top--;
ch[top++] = p[i];
if (i == p.size() - 1) d = -1, bot = top;
}
ch.resize(max(1, top - 1));
return ch;
}
int main() {
int n, m, x, y;
vector<complex<long long> > p;
p.reserve(200000);
set<complex<long long>, comp> B;
cin >> n;
while (n--) {
cin >> x >> y;
p.push_back(complex<long long>(x, y));
}
cin >> m;
while (m--) {
cin >> x >> y;
p.push_back(complex<long long>(x, y));
B.insert(complex<long long>(x, y));
}
p = chull(p);
bool yes = true;
for (int i = 0; i < p.size(); i++) {
if (B.count(p[i])) {
yes = false;
break;
}
}
if (yes)
cout << "YES";
else
cout << "NO";
cout << endl;
return 0;
}
| 8 | CPP |
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <cmath>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <complex>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(c) (c).begin(), (c).end()
#define loop(i,a,b) for(int i=a; i<int(b); i++)
#define rep(i,b) loop(i,0,b)
#define each(e,c) for(auto& e:c)
#define iter(it,c) for(auto it=c.begin(); it!=c.end(); ++it)
ll const inf = 1<<28;
double const pi = acos(-1);
typedef complex<double> P;
typedef vector<P> L;
double cross(const P& a, const P& b) {
return imag(conj(a)*b);
}
double dot(const P& a, const P& b) {
return real(conj(a)*b);
}
int ccw(P a, P b, P c) {
b -= a; c -= a;
if (cross(b, c) > 0) return +1; // counter clockwise
if (cross(b, c) < 0) return -1; // clockwise
if (dot(b, c) < 0) return +2; // c--a--b on line
if (norm(b) < norm(c)) return -2; // a--b--c on line
return 0;
}
bool intersectSS(const L &s, const L &t) {
return ccw(s[0],s[1],t[0])*ccw(s[0],s[1],t[1]) <= 0 &&
ccw(t[0],t[1],s[0])*ccw(t[0],t[1],s[1]) <= 0;
}
P ps[4];
L l;
bool solve(){
int c=0;
rep(i,3){
L m{ps[i],ps[i+1]};
if(intersectSS(l,m))c++;
}
return c==1;
}
int main(){
int n;cin>>n;
rep(_,n){
rep(i,3){
double x,y;cin>>x>>y;
ps[i]=P(x,y);
}
ps[3]=ps[0];
double a,b,c,d;
cin>>a>>b>>c>>d;
l={P(a,b),P(c,d)};
cout << (solve()?"OK":"NG")<<endl;
}
} | 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
char c[1010][1010];
bool f[1010];
int main() {
ios_base::sync_with_stdio(0);
int n, m;
cin >> n >> m;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
cin >> c[i][j];
}
}
int k = 0;
int del = 0;
for (int i = 0; i < n; i++) f[i] = true;
f[0] = false;
for (int j = 0; j < m; j++) {
bool op = true;
for (int i = 0; i < n; i++) {
if (f[i] && c[i][j] < c[i - 1][j]) op = false;
}
if (!op) {
del++;
continue;
}
for (int i = 0; i < n; i++)
if (f[i] && c[i][j] != c[i - 1][j]) f[i] = false;
}
cout << del << endl;
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T &x) {
char c;
bool nega = 0;
while ((!isdigit(c = getchar())) && (c != '-'))
;
if (c == '-') {
nega = 1;
c = getchar();
}
x = c - 48;
while (isdigit(c = getchar())) x = x * 10 + c - 48;
if (nega) x = -x;
}
template <typename T>
inline void writep(T x) {
if (x > 9) writep(x / 10);
putchar(x % 10 + 48);
}
template <typename T>
inline void write(T x) {
if (x < 0) {
putchar('-');
x = -x;
}
writep(x);
}
template <typename T>
inline void writeln(T x) {
write(x);
putchar('\n');
}
string s;
int last[256];
int k[256];
int main() {
cin >> s;
s = '0' + s;
for (int i = 0; i < s.size(); i++) {
k[s[i]] = max(k[s[i]], i - last[s[i]]);
last[s[i]] = i;
}
for (int i = 'a'; i <= 'z'; i++) k[i] = max(k[i], ((int)s.size()) - last[i]);
int ans = s.size() - 1;
for (int i = 'a'; i <= 'z'; i++)
if (k[i]) ans = min(ans, k[i]);
writeln(ans);
}
| 9 | CPP |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 10;
int n, m, comps = 0, dots = 0;
string z;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cin >> n >> m;
cin >> z;
bool indots = false;
for (int i = 0; i < n; i++) {
if (z[i] == '.')
dots++, indots = true;
else if (indots)
comps++, indots = false;
}
if (indots) comps++, indots = false;
int idx;
char c;
while (m--) {
cin >> idx >> c;
idx--;
if (z[idx] == '.' && c != '.') {
dots--;
if (idx == 0 && n > 1 && z[idx + 1] != '.') comps--;
if (idx == n - 1 && n > 1 && z[idx - 1] != '.') comps--;
if (idx < n - 1 && idx > 0 && z[idx + 1] != '.' && z[idx - 1] != '.')
comps--;
if (idx < n - 1 && idx > 0 && z[idx + 1] == '.' && z[idx - 1] == '.')
comps++;
} else if (z[idx] != '.' && c == '.') {
dots++;
if (idx == 0 && n > 1 && z[idx + 1] != '.') comps++;
if (idx == n - 1 && n > 1 && z[idx - 1] != '.') comps++;
if (idx < n - 1 && idx > 0 && z[idx + 1] != '.' && z[idx - 1] != '.')
comps++;
if (idx < n && idx > 0 && z[idx + 1] == '.' && z[idx - 1] == '.') comps--;
}
z[idx] = c;
cout << max(0, dots - comps) << '\n';
}
}
| 9 | CPP |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ll X, Y, Z, A, B, C, N;
cin >> X >> Y >> Z >> A >> B >> C >> N;
vector<ll> res(N);
const int cnt = (Z-C) / N + (C+1) / N;
for(int i=0; i<N; ++i) {
res[i] = X*Y*cnt;
}
vector<ll> rest(N);
{
const int cnt2 = (Y-B) / N + (B+1) / N;
for(int i=0; i<N; ++i) {
rest[i] = X*cnt2;
}
vector<ll> rest2(N);
for(int i=0; i<X; ++i) {
rest2[abs(i-A) % N]++;
}
for(int i=0; i<N; ++i) {
rest[i] -= rest2[i];
}
for(int i=0; i<max((Y-B)%N, (B+1)%N); ++i) {
for(int j=0; j<N; ++j) {
if(i < (Y-B) % N) {
rest[j] += rest2[j];
}
if(i < (B+1) % N) {
rest[j] += rest2[j];
}
}
auto tmp = rest2;
for(int j=0; j<N; ++j) {
tmp[(j+1)%N] = rest2[j];
}
rest2.swap(tmp);
}
}
for(int i=0; i<N; ++i) {
res[i] -= rest[i];
}
for(int i=0; i<max((Z-C)%N, (C+1)%N); ++i) {
for(int j=0; j<N; ++j) {
if(i < (C+1)%N) {
res[j] += rest[j];
}
if(i < (Z-C)%N) {
res[j] += rest[j];
}
}
auto tmp = rest;
for(int j=0; j<N; ++j) {
tmp[(j+1)%N] = rest[j];
}
rest.swap(tmp);
}
for(int i=0; i<N; ++i) {
cout << res[i] << " \n"[i == N-1] << flush;
}
}
| 0 | CPP |
#include <bits/stdc++.h>
using namespace std;
map<long long int, long long int> m;
int main() {
long long int n;
cin >> n;
m[0] = 1;
long long int minute = 0;
long long int roomNo = 1;
while (n--) {
minute += 1;
long long int x;
cin >> x;
if (m[x]) {
m.erase(x);
} else
roomNo += 1;
m[minute] = roomNo;
}
cout << roomNo;
return 0;
}
| 7 | CPP |
#160A
n=int(input())
s=[int(j) for j in input().split()]
s.sort()
v=s[::-1]
c=0
p=1
d=0
for i in range(len(s)):
c=c+s[i]
for i in range(len(v)):
d=d+v[i]
if(d<=c//2):
p+=1
print(p) | 7 | PYTHON3 |
from collections import Counter
def read_numbers():
return (int(s) for s in input().strip().split(' '))
def main():
n, k = read_numbers()
arr = list(read_numbers())
count = Counter(arr)
count = sorted(count.items(), key=lambda k: k)
# print(count)
res = 0
if k == 0:
if 1 in arr:
return -1
else:
return 1
for num, c in count:
res += c
if res == k:
return num
if res > k:
return - 1
return -1
if __name__ == '__main__':
print(main()) | 9 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
int a[n / 2];
for (int i = 0; i < n / 2; i++) cin >> a[i];
sort(a, a + n / 2);
int p = n - 1, sum = 0;
for (int i = n / 2 - 1; i >= 0; i--) {
sum += abs(p - a[i]);
p -= 2;
}
int sum1 = 0;
p = n;
for (int i = n / 2 - 1; i >= 0; i--) {
sum1 += abs(p - a[i]);
p -= 2;
}
cout << min(sum, sum1);
}
| 7 | CPP |
#include <bits/stdc++.h>
using namespace std;
int main() {
int a, b, c, d;
cin >> a >> b >> c >> d;
int maxx1 = max(((3 * a) / 10), (a - ((a / 250) * c)));
int maxx2 = max(((3 * b) / 10), (b - ((b / 250) * d)));
if (maxx1 > maxx2)
cout << "Misha" << endl;
else if (maxx1 < maxx2)
cout << "Vasya" << endl;
else
cout << "Tie" << endl;
return 0;
}
| 7 | CPP |
from math import ceil
print(ceil(int(input())/111)*111) | 0 | PYTHON3 |
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
long long n;
cin >> n;
long long p = 1;
long long c = 0;
while (1) {
p *= 2;
c++;
if (p > n) break;
}
p /= 2;
long long a[2 * c + 1][n];
for (long long i = 0; i < c; i++) {
vector<long long> v;
for (long long j = 1; j <= n; j++) {
if (j & (1 << i)) v.push_back(j);
}
cout << v.size() << endl;
for (long long j = 0; j < v.size(); j++) cout << v[j] << " ";
cout << endl;
for (long long j = 0; j < n; j++) cin >> a[i][j];
}
for (long long i = 0; i < c; i++) {
vector<long long> v;
for (long long j = 1; j <= n; j++) {
if (j & (1 << i))
continue;
else
v.push_back(j);
}
cout << v.size() << endl;
for (long long j = 0; j < v.size(); j++) cout << v[j] << " ";
cout << endl;
for (long long j = 0; j < n; j++) cin >> a[c + i][j];
}
cout << "-1" << endl;
for (long long i = 1; i <= n; i++) {
long long cur = (1e9) + 5;
for (long long j = 0; j < c; j++) {
if (i & (1 << j))
cur = min(cur, a[c + j][i - 1]);
else
cur = min(cur, a[j][i - 1]);
}
cout << cur << " ";
}
cout << endl;
return 0;
}
| 8 | CPP |
for _ in range(int(input())):
num,sticker,toy=map(int,input().split())
notoy=num-toy
nosticker=num-sticker
buy=max(notoy,nosticker)
total=buy+1
print(total) | 7 | PYTHON3 |
def lights(value):
if value == 0:
return 1
else:
return 0
matrix = []
for i in range(3):
matrix.append(list(map(int, input().split())))
ans = [[1, 1, 1], [1, 1, 1], [1, 1, 1]]
if matrix[0][0] % 2 != 0:
ans[0][0] = lights(ans[0][0])
ans[0][1] = lights(ans[0][1])
ans[1][0] = lights(ans[1][0])
if matrix[0][1] % 2 != 0:
ans[0][1] = lights(ans[0][1])
ans[0][0] = lights(ans[0][0])
ans[0][2] = lights(ans[0][2])
ans[1][1] = lights(ans[1][1])
if matrix[0][2] % 2 != 0:
ans[0][2] = lights(ans[0][2])
ans[0][1] = lights(ans[0][1])
ans[1][2] = lights(ans[1][2])
if matrix[1][0] % 2 != 0:
ans[1][0] = lights(ans[1][0])
ans[0][0] = lights(ans[0][0])
ans[2][0] = lights(ans[2][0])
ans[1][1] = lights(ans[1][1])
if matrix[1][1] % 2 != 0:
ans[1][1] = lights(ans[1][1])
ans[0][1] = lights(ans[0][1])
ans[1][0] = lights(ans[1][0])
ans[1][2] = lights(ans[1][2])
ans[2][1] = lights(ans[2][1])
if matrix[1][2] % 2 != 0:
ans[1][2] = lights(ans[1][2])
ans[0][2] = lights(ans[0][2])
ans[1][1] = lights(ans[1][1])
ans[2][2] = lights(ans[2][2])
if matrix[2][0] % 2 != 0:
ans[2][0] = lights(ans[2][0])
ans[1][0] = lights(ans[1][0])
ans[2][1] = lights(ans[2][1])
if matrix[2][1] % 2 != 0:
ans[2][1] = lights(ans[2][1])
ans[2][0] = lights(ans[2][0])
ans[2][2] = lights(ans[2][2])
ans[1][1] = lights(ans[1][1])
if matrix[2][2] % 2 != 0:
ans[2][2] = lights(ans[2][2])
ans[2][1] = lights(ans[2][1])
ans[1][2] = lights(ans[1][2])
for i in range(3):
s = ""
for j in range(3):
s += str(ans[i][j])
print(s) | 7 | PYTHON3 |
n = int(input())
minimum_capacity = 0
capacity = 0
for i in range(n) :
a, b = map(int, input().split())
capacity -= a
capacity += b
if minimum_capacity < capacity :
minimum_capacity = capacity
print(minimum_capacity) | 7 | PYTHON3 |
import sys
import math
from collections import Counter
import heapq
try:
for _ in range(int(input())):
n=int(input())
arr=[int(i) for i in input().split()]
arr.sort()
flg=0
for i in range(1,n):
if arr[i]-arr[i-1]>1:
flg=1
break
if flg==1:
print("NO")
else:
print("YES")
except EOFError as e:
print(e)
| 7 | PYTHON3 |
for _ in range(int(input())):
n=int(input())
a=list(map(int,input().split()))
p=0
m=0
b=[]
c=[]
s=0
for i in range(len(a)):
if a[i]>0:
if len(c)>0:
s+=max(c)
c=[]
b.append(a[i])
else:
if len(b)>0:
s+=max(b)
b=[]
c.append(a[i])
if len(b)>0:
s+=max(b)
if len(c)>0:
s+=max(c)
print(s)
| 9 | PYTHON3 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.