problem stringlengths 716 12.9k | answer stringlengths 41 999 |
|---|---|
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | //BE NAMASH
#include<iostream>
#include<stdio.h>
using namespace std;
const int MN=5100;
bool a[MN][MN];
short int A,B,C,l[MN],t[MN];
int n;
int find(int p,int q){
if(q-p<=2){
return 0;
}
int ef1=p+1,ef2=q-1;
int v=l[p];
t[p]=l[p];
for(int i=p+1;i<q;i++){
if(a[v][l[i]]){
t[ef2--]=l[i];
}else{
t[ef1+... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include <vector>
#include <stdio.h>
int main() {
int n,i;
scanf("%d",&n);
char a[n][n];
for (i = 0;i < n;i++) scanf("%s",a[i]);
std::vector<int> b(1,0);
for (i = 1;i < n;i++) {
int l=0,r=i-1;
while (l<i && a[i][b[l]]=='0') l++;
while (r>=0 && a[i][b[r]]=='1') r--;
if (l==r+1)
b.ins... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include<bits/stdc++.h>
using namespace std;
int n,m,i,j,a[1005],b[1005],a1[1005],a2[1005],a3[1005],a4[1005];
int main()
{
scanf("%d",&n);
for(i=1;i<=n;i++)scanf("%d",a+i);
for(i=1;i<=n;i++)scanf("%d",b+i);
for(i=n;i;i--)
{
if(a[i]==i&&b[i]==i)continue;
for(j=1;j<=i;j++)if(a[j]==i)a[j]=a[i];
for(j=1;j<=i;j++... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include<bits/stdc++.h>
using namespace std;
long long n;
int main(){
cin >> n;
cout << n/2+1 << "\n";
long long r=1, c=1;
for (int i=0;i<n;i++){
cout << r << " " << c << "\n";
if (i%2) r++;
else c++;
}
} |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include<iostream>
#include<math.h>
#include<stdlib.h>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
ll n;
cin>>n;
ll m=n/2+1;
ll i=1,j=1;
cout<<m<<"\n";
for(ll x=0;x<n;x++)
{
cout<<i<<" "<<j<<"\n";
if((i+j)%2==0)
i=i+1;
... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include<bits/stdc++.h>
using namespace std;
int n;
int main(){
cin>>n;
int m;
m=((n-1)+3)/2;
cout<<m<<"\n";
int cnt=0;
int k=1;
for(int i=1;i<=m;i+=(m-1)){
for(int j=k;j<=m;j++){
cout<<i<<" "<<j<<"\n";
cnt++;
if(cnt==n) break;
}
k=i+1;
if(cnt==n) break;
}
return 0;
} |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | // Author : jb
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
using namespace std;
int main()
{
IOS;
int n , m , b ;
cin>>n;
b = n ;
if(n%2==0)
n = n + 1 ;
m = (n+1)/2;
cout<<m<<endl;
for(int i = 1; i < m+1&&b!=0 ; i++,b--)
{
cou... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include<bits/stdc++.h>
using namespace std;
int main(){
long long n,p=0;
cin>>n;
long long a[2*n];
for(int i=0;i<2*n;i++)
cin>>a[i];
sort(a,a+2*n);
for(int i=0;i<2*n-1;i++)
{
if(a[i]!=a[i+1])
{p=1;break;}
}
if(!p)
cout<<-1;
else
{
... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include<bits/stdc++.h>
using namespace std;
int main(){
int n;cin>>n;
vector <int> arr(2*n);
for(auto &in:arr){
cin>>in;
}
sort(arr.begin(),arr.end());
if(arr[0]==arr[2*n-1]){
cout<<"-1"<<endl;
}else{
for(int i=0;i<2*n;i++){
cout<<arr[i]<<" ";
}
... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<vector>
#include<set>
typedef long long ll;
using namespace std;
const ll INF=1e9+7;
int a[100005];
int main()
{
int n,sum=0,s=0;
cin>>n;
for(int i=0;i<2*n;i++)
{
cin>>a[i];
sum+=a[i];
... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include <stdio.h>
#include <math.h>
int prima[10000], cnt = 0, pertama, akar;
bool isprime(int a) {
akar = sqrt(a);
for (int j = 0; j < cnt; j++) {
if (prima[j] > akar)
break;
if (a % prima[j] == 0) {
pertama = j + 1;
return false;
}
}
return true;
}
int main() {
int n;
scanf("%d", &n);
for (i... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int n,i,j,cnt,ans[100005];
int main()
{
//freopen("c.in","r",stdin);
//freopen("c.out","w",stdout);
scanf("%d",&n);
for(i=2;i<=n;++i)
if(!ans[i])
{
++cnt;
for(j=i;j<=n;j+=i)
if(!ans[j])
ans[j]=cnt;
}
fo... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include <cstdio>
#include <algorithm>
using namespace std;
int vis[100005];
int main()
{
int n,cnt=0;
scanf("%d",&n);
for(int i=2;i<=n;i++)
{
if(!vis[i])
{
vis[i]=++cnt;
for(int j=i;j<=n;j+=i)
vis[j]=cnt;
}
}
for(int i=2;i<=n;i++)
printf("%d ",vis[i]);
return 0;
} |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
#define maxn 100005
int n,k,a[maxn];
bool f[maxn];
int main()
{
//freopen("code.inp","r",stdin);
//freopen("code.out","w",stdout);
scanf("%d",&n);
memset(f,true,sizeof(f));
for(int i=2; i<=n ;i++)
{
if (!f... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include <iostream>
#include <vector>
using namespace std;
int f(int i, int avoid) {
int ans = i & -i;
if (ans >= avoid) ans <<= 1;
return ans;
}
int main() {
int n, x; cin >> n >> x;
if (x >= (1 << n)) {
cout << (1 << n) - 1 << endl << 1;
for (int i = 2; i < (1 << n); i++) cout << " " << (i & -i);
... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<ctime>
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<list>
#include<map>
#include<set>
#define MAX_V 10000
using namespace std;
typedef long long ll;
typedef pair<int,int> PI... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <set>
using namespace std;
inline int gi() {
register int data = 0, w = 1;
register char ch = 0;
while (!isdigit(ch) && ch != '-') ch = getchar();
if (ch == '-') w = -1,... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include <bits/stdc++.h>
using namespace std;
int main()
{
int n, x, s, i;
scanf("%d%d", &n, &x);
if(x >= (1 << n))
{
s = 0;
printf("%d\n", (1 << n) - 1);
for(i = 1; i < (1 << n); i++)
{
s = ((i | (i-1)) - ((i-1) & i));
printf("%d ", s);
}
}
else
{
s = 0;
printf("%d\n", ((1 << n) - 2) / 2)... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
const ll MAXN=2e5+10;
ll gcd(ll a,ll b)
{
return b?gcd(b,a%b):a;
}
ll lcm(ll a,ll b)
{
return a/gcd(a,b)*b;
}
ll lowbit(ll x)//ζε°1ηζεΌ
{
return x &... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include<bits/stdc++.h>
using namespace std;
int main()
{
int n,x=0,b,cnt=0;
vector<int>v;
cin>>n;
int a[n];
for(int i=0;i<n;i++)
{
cin>>a[i];
x+=a[i];
}
b=a[0];
if(b>x/2)
{
cout<<1<<endl<<1;
return 0;
}
else
{
for(int i=1;i<n;i... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
int main(){
ll n,al,sum=0;
cin>>n>>al;
sum=al;
ll al1=al;
vector<pair<ll,ll> > v;
vector<ll> ans;
for(int i=1;i<n;i++){
int temp;
cin>>temp;
sum+=temp;
v.pb({temp,i});
}... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
pair<int, int> a[109];
vector<int> ans;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int n; cin >> n;
int r = 0;
for (int i = 0; i < n; i++) {
cin >> a[i].first;
a[i].second = i + 1;
r += a[i].first;
}
r... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include<bits/stdc++.h>
using namespace std;
const int N = 1005;
int main() {
int n, val, tot = 0, has, ans = 0;
vector<int> res;
scanf("%d", &n);
scanf("%d", &has);
tot += has;
ans += has;
res.push_back(1);
for(int i = 2; i <= n; i++){
scanf("%d", &val);
if(has >= 2 * va... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include <bits/stdc++.h>
using namespace std;
bool prime(int n){
int s = (int)(sqrt(n) + 1);
for (int i = 2; i < s; i++){
if (n % i == 0) return 0;
}
return 1;
}
int nextP(int i){
while (!prime(i)) i++;
return i;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int N;
cin >> N;
in... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include <bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define fi first
#define se second
int N;
vector<int> prime;
vector<pii> ret;
int main(){
for(int i=2;i<=1020;i++){
bool ok = true;
for(int ver:prime){
if(i%ver==0){
ok = false;
break;
}
}
if(ok) prime.push_back(i);
}
sca... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | // qdd on Jul 21, 2019
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
bool isprime(int x) {
if (x < 2) return false;
for (int i = 2; i * i <= x; i++) {
if (x % i == 0) return false;
}
return true;
}
int get(int n) {
int rt = n;
while (!isprime(rt)) ++rt;
retu... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include <bits/stdc++.h>
using namespace std;
const int LEN = 1000000;
char s[LEN + 1], ans[(LEN >> 1) + 1];
int main() {
gets(s);
int len = strlen(s), tmp = len >> 2;
for (int i = 0; i < tmp; ++i) {
int k1 = i << 1, k2 = k1 | 1, k3 = len - ((i + 1) << 1), k4 = k3 + 1;
if (s[k1] == s[k3] ... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include <set>
#include <cmath>
#include <queue>
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
#define rep(i, x, y) for (i = x; i <= y; i++)
#define per(i, x, y) for (i = x; i >= y; i--)
char s[1100000];
vector<char> v;
int sum[1... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include <bits/stdc++.h>
using namespace std;
const int maxn=1123456;
int n,cnt[3];
char s[maxn];
vector<char> str;
int main()
{
scanf("%s",s);
n=strlen(s);
int tot=0;
for (int i=0;i+1<n-i-2;i+=2) {
cnt[0]=cnt[1]=cnt[2]=0;
++cnt[s[i]-'a'];
++cnt[s[i+1]-'a'];
++cnt[s[n-i-1... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include <bits/stdc++.h>
using namespace std;
// xx...yy
// ..x(xy)y..
char s[1000006];
char t[1000005];
int main()
{
scanf("%s", s);
int n = strlen(s);
int i = 0;
int j = n-2;
int cnt = 0;
while (i+1 < j) {
if (s[i] == s[j] || s[i] == s[j+1]) {
t[cnt++] = s[i];
} else {
t[cnt++] = s[i+1];
}
i +=... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include <iostream>
#include <vector>
#include <stack>
using namespace std;
const int nmax = 100000;
int n, m, a, b, t;
vector<int> e[nmax+1];
int num[nmax+1], low[nmax+1];
vector< pair<int, int> > ans;
bool flag;
void dfs(int u, int from) {
num[u] = low[u] = ++t;
int s = e[u].size();
for (int i = 0; i < s; i++) ... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include <cstdio>
int a[100005];
int main() {
int n, a0 = 1;
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
scanf("%d", a + i);
if (a[i] >= 0) a[i] = ~a[i];
if (~a[i]) a0 = 0;
}
if (a0) {
if (n & 1)
for (int i = 0; i < n; ++i) a[i] = 0;
} else {
... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include <bits/stdc++.h>
#define ll long long
#define M 1000000007
using namespace std;
int find(int a[], int n)
{
int maxi = -1;
int maxe = INT_MIN;
for(int i = 0; i < n; i++)
{
if(a[i] == -1)
{
continue;
}
if(abs(a[i]) > maxe)
{
maxe = a... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include<bits/stdc++.h>
char s[10],zero[]="00000";
typedef long long LL;
int val[100005],chg[100005];
LL abs(LL x){return x<0?-x:x;}
int main(){
int n;scanf("%d",&n);
LL zr=0,fr=0,sum=0;
int flag=1,l,r;
int x;
for(int i=0;i<n;i++){
scanf("%s",s);
r=strlen(s)-7;
if(s[0]=='-... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include<cstdio>
#include<algorithm>
using namespace std;
#define MAXN 100010
#define LL long long
int f[MAXN][2];
void Read(int i)
{
char c=getchar();
int flag=0,Z=1;
while(c<'0'||'9'<c)
{
if(c=='-') flag=1;
c=getchar();
}
while('0'<=c&&c<='9')
f[i][0]=f[i][0]*10+c-'0',c=getchar();
if(c=='.')
{
for(int... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include <cstdio>
using namespace std;
int a[100001],isint[100001];
struct number{
int value;
int negative;
};
number get(){
number n;
char c=getchar();
while((c<'0'||c>'9')&&c!='-')c=getchar();
if(c=='-')n.negative=1;else n.negative=0;
while(c<'0'||c>'9')c=getchar();
n.value=0;
while(c>='0'&&c<='9'){
n.valu... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include <cstdio>
#include <cstdlib>
#include <ctime>
#include <algorithm>
const int N = 1e6 + 5;
int n, m, d[N], D[N], f[N];
bool del[N];
struct Edge {
int u, v;
} e[N];
int main() {
srand(time(0) + ('Q' + 'Y' + 'A' + 'K' + 'I' + 'O' + 'I'));
scanf("%d%d", &n, &m);
for (int i = 1; i <= m; i++) {
scanf("%d%d"... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
string s;
cin>>s;
int x,y;
if(n%2)
{
cout<<1<<endl;
cout<<s<<endl;
return 0;
}
int a=0,b=0;
for(int i=0; i<n; i++)
{
if(s[i]=='0') a++;
else b++;
}
if(a!=b... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include<bits/stdc++.h>
using namespace std;
int main()
{
int n,o=0,z=0;
cin>>n;
string s;
cin>>s;
for(int i=0; i<n; i++)
{
if(s[i]=='0') z++;
else o++;
}
if(z==o)
{
cout<<2<<endl;
cout<<s[0]<<" ";
for(int i=1; i<n; i++)
{
c... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include<bits/stdc++.h>
using namespace std;
int n,o;
string s;
int main()
{
cin>>n>>s;
if(n%2==1)
{cout<<1<<endl<<s;
return 0;}
for(int i=0;i<n;i++)
{
if(s[i]=='0')
o++;
}
if(o!=n-o)
cout<<1<<endl<<s;
else
cout<<2<<endl<<s[0]<<" "<<s.... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
cin.sync_with_stdio(0);
cin.tie(0);
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
int n;
cin>>n;
string s;
cin>>s;
int count1=0;
int count2=0;
for(int i=0;i<s.size()... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include<bits/stdc++.h>
using namespace std;
int main (){
char s[200];
int i,j,n,zero=0,one=0,z1=0,on1=0;
cin>>n>>s;
for(i=0;i<n;i++){
if(s[i]=='0')
zero++;
else
one++;
}
if(zero>one||one>zero){
cout<<1<<endl<<s;
return 0;
}
cout<<2<<endl<<s[0]<<" ";
for(i=1;i<n;i++){
cout<<s[i];
}
r... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
template <class T>
inline void _read(T &x)
{
x = 0;
char t = getchar();
while (!isdigit(t)) t = getchar();
while (isdigit(t))
{
x = x * 10 + t - '0';
t = getchar();
}
}
int n;
int a[MAXN];
#define mp make_pair
#define pb push_back
int b[... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include<stdio.h>
#include<algorithm>
int n,a[100010];
int main()
{
scanf("%d",&n);
for(register int i=1;i<=n;++i) scanf("%d",&a[i]);
std::sort(a+1,a+n+1);
if(a[n]>=a[n-1]+a[n-2])
{
printf("NO\n");
return 0;
}
printf("YES\n");
for(register int i=n;i;--i)
{
if(i==n-2) continue;
printf("%d ",a[i]);
}
p... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include<cstdio>
#include<algorithm>
using namespace std;
const int N=1e5+5;
int main()
{
//freopen("test.in","r",stdin);
int n,a[N],v=-1;
scanf("%d",&n);
for (int i=1;i<=n;++i) scanf("%d",&a[i]);
sort(a+1,a+1+n);
if (a[n]>=a[1]+a[n-1])
{
for (v=n-2;v>=1;--v) if (a[v]+a[v+1]>a[n]) break;
if (a[v]+a[v+1]<=a[... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define dep(i,a,b) for(int i=(a);i>=(b);--i)
#define pb push_back
typedef long long ll;
const int maxn=(int)2e5+100;
int b,w;
void solve(){
scanf("%d%d",&b,&w);
int c=min(b,w),d=max(b,w);
if(d>3ll*c+1ll){printf("NO\n");return;}... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include <cstdio>
int T, w, b;
int main()
{
scanf("%d", &T);
while(T--)
{
scanf("%d%d", &b, &w);
if(w>=b)
{
if(w-1>3*b) puts("NO");
else
{
puts("YES");
if(w>3*b) --w, puts("1 3");
int i;
for(i=2; w-b>=2; i+=2) printf("%d %d\n%d %d\n%d %d\n%d %d\n", i, 2, i, 3, i, 4, i+1, 3), w-=3, b-=1... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include <bits/stdc++.h>
using namespace std;
int main() {
// cout<<"GfG!";
int h,l;
cin>>h>>l;
//double a=;
printf("%0.15lf",((l+h)/(2.00*h)*(l-h)));
return 0;
} |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include <bits/stdc++.h>
using namespace std;
int main()
{
int h,l;
cin>>h>>l;
long long int a = h+l;
a=a*(l-h);
h=2*h;
long long int d = a/h;
cout<<d<<".";
d = a%h;
d=d*10;
for(int i=0;i<13;i++)
{
long long int x = d/h;
cout<<x;
d = d%h;
d=d... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include<iostream>
#include<cstdio>
#define N 1010
using namespace std;
int n;
int a[N][N];
int main (){
int i,j;
scanf("%d",&n);
n--;
for(i=0;i<n;i++)
for(j=0;j<n;j++)
a[i][j]=1+(i+j)%n;
for(i=0;i<n;a[i][i]=0,i++)
a[i][n]=a[n][i]=a[i][i];
for(i=0;i<=n;i++,puts(""))
for(j=0;j<=n;j++)
... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include<cstdio>
int n;
int main() {
scanf( "%d" , &n );
for ( int i = 1 ; i <= n - 1 ; i++ ) {
for ( int j = 1 ; j <= n - 1 ; j++ )
if ( i == j ) printf( "0 " );
else printf( "%d " , 1 + ( i + j - 2 ) % ( n - 1 ) );
printf( "%d\n" , ( 2 * i - 2 ) % ( n - 1 ) + 1 );
}
for ( int i = 1 ; i <= n - 1 ; i++ )... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include <cstdio>
int a[1000][1000];
int main()
{
int n,k;
scanf("%d",&n);
for(int j=0;j<n-1;j++) {
k=j;
for(int i=0;i<j;i++) {
a[j][i]=a[i][j]=k++;
if(k==n) k=1;
}
a[n-1][j]=a[j][n-1]=k;
}
a[n-1][0]=a[0][n-1]=n-1;
for(int i=0;i<n;i++) {
for(int j=0;j<n;j++)
printf("%d ",a[i][j]);
printf("\... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include <iostream>
#include <cstdio>
using namespace std;
int m[1002][1002];
int main(int argc, char **argv) {
int n, i, j;
scanf("%d", &n); n -= 1;
for (i = 0; i < n; ++i) {
for (j = 0; j < n; ++j) {
m[i][j] = (i + j) % n + 1;
}
m[n][i] = m[i][n] = m[i][i];
m[i][i] = 0;
}
for (i = 0; i <=... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include<cstdio>
#include<cstdlib>
#include<algorithm>
using namespace std;
#define sqr(x) ((x)*(x))
struct Point
{
int x,y;
int z;
int p;
};
int n;
Point P[100005];
Point Q[100005];
bool cmp(const Point& A,const Point& B)
{
return A.x<B.x||(A.x==B.x&&A.y<B.y);
}
int main()
{
freopen("input.txt","r",stdin);
f... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include <bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int N;
cin >> N;
for (int i = 0; i < N; i++){
int a;
cin >> a;
int thou, mil, one;
mil = a/ 1122457;//1125841;
a %= 1122457;
thou = (a / 1000) ;
one = a % 1000;
//cout << mil ... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include <bits/stdc++.h>
using namespace std;
typedef long long llint;
const llint MOD = 998244353;
int main() {
int T;
cin >> T;
while(T--) {
llint N;
cin >> N;
if(N == 1) {
cout << "1337\n";
continue;
}
llint M = 0;
while((M + 2) * (M... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define rrep(i,a,b) for(int i=(a);i>=(b);--i)
#define PB push_back
#define MP make_pair
#define PII pair<int, int>
typedef long long LL;
const LL P = 998244353;
const int INF = 0x3fffffff;
const int N = 200010;
mt19937 rng(chrono:... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
int n,flag=0,t,q;cin>>n;
int a[n];
for(int i=0;i<n;i++)
cin>>a[i];
int m;cin>>m;
int b[m];
for(int i=0;i<m;i++)
cin>>b[i];
sort(a,a+n);sort(b,b+m);
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include <iostream>
#include <vector>
using namespace std;
int main() {
int n, m;
vector<int>c(401, 0);
cin >> n;
vector<int> a(n, 0);
for (int i = 0; i < n; i++) {
cin >> a[i]; c[a[i]]++;
}
cin >> m;
vector<int>b(m, 0);
for (int i = 0; i < m; i++) {
cin >> b[i]; c[b[i]]++;
}
int ans, ans2;
for (int i =... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include<bits/stdc++.h>
using namespace std;
int main()
{
int t,n,i,j,m,a[1000],b[1000],h[2000];
memset(h,0,sizeof(h));
cin>>n;
for(i=0; i<n;i++){
cin>>a[i];
h[a[i]]++;
}
cin>>m;
for(i=0; i<m; i++)
{
cin>>b[i];
h[b[i]]++;
}
int flag=0;
fo... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include <bits/stdc++.h>
using namespace std;
int main() {
int n,m;
cin>>n;
int a[n+1];
for(int i=0;i<n;i++)
{
cin>>a[i];
}
cin>>m;
int b[m+1];
for(int i=0;i<m;i++)
{
cin>>b[i];
}
sort(a,a+n);
sort(b,b+m);
cout<<a[n-1]<<" "<<b[m-1];
} |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
const int INF=0x3f3f3f3f;
const int N=200005;
char d[N];
bool vis[N];
int pos[11],st[11];
int main() {
int T,n;
scanf("%d",&T);
for(int Cas=1;Cas<=T;Cas++) {
scanf("%d",&n);
scanf("%s",d);
for(int i=0;i<=9;i++)
pos[i]=-1,st[i]=INF;... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include <bits/stdc++.h>
using namespace std;
const int MAXN = 200005;
int t, n;
char s[MAXN], d[MAXN];
int main(){
scanf("%d", &t);
while(t--){
scanf("%d %s", &n, s);
bool found = false;
for(int x = 0; x <= 10; x++){
bool ok = true;
int a = 0, b = 0;
for(int i = 0; i < n; i++){
int c = s[... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int maxn = 200002;
char a[maxn];
char ans[maxn];
int n;
int main() {
int T;
scanf("%d", &T);
while (T--) {
scanf("%d", &n);
scanf("%s", a + 1);
bool f = 0;
for (int d = 0; d <= 9; d++) {
int cur1 = '0';
int cur2 = '0' ... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include<bits/stdc++.h>
using namespace std;
bool check[3][200005];
int hello[3][200001];
vector<int> section;
char ans[200005];
int main()
{
ios_base::sync_with_stdio(0);
int N,K;cin >> N >> K;
int hold=0,mem=0;
for(int i=1;i <= 2;i++) for(int l=1;l <= N;l++) cin >> hello[i][l];
for(int i=1;i <= N;... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define ll long long
#define N 200005
int n;
char A[N], B[N];
int main()
{
scanf("%d", &n);
scanf("%s%s", A + 1, B + 1);
int s1 = 0, s2 = 0;
for (int i = 1; i <= n; i++)
{
if (A[i] == 'a' && B[i] == 'b')
s1++;
... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include <bits/stdc++.h>
#define rep(i, a, b) for(int i(a), i##_ORZ(b); i <= i##_ORZ; i++)
#define drep(i, a, b) for(int i(a), i##_ORZ(b); i >= i##_ORZ; i--)
using namespace std;
const int maxn = 200010;
char a[maxn], b[maxn];
int n, ans;
int main() {
scanf("%d", &n);
scanf("%s%s", a + 1, b + 1);
int x = 0, y = 0, p... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include <string>
#include <cstdlib>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+5;
int Pow(int a,int b)
{
int ans=1;
while(b)
{
if(b&1) ans*=a;
a*=a;
b>>=1;
}
return ans;
}
char s[maxn];
int main()
{
int n, sum1=0, sum2=0;
scanf("%d", &n);
scanf(... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
char a[N];
int main()
{
int n;int sum=0;
scanf("%d",&n);
scanf("%s",a+1);
if(n&1) n--;
for(int i=1;i<=n;i+=2){
if(a[i]==a[i+1]){
sum++;
if(a[i]=='a')
a[i+1]='b';
else a[i+1]='... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include <iostream>
using namespace std;
int main()
{
int n;
scanf("%d",&n);
char a[n];
scanf("%s",a);
int i,sum=0;
for(i=0;i<n;i=i+2)
{
if(a[i]==a[i+1])
{
sum++;
if(a[i]=='a')
a[i+1]='b';
else
a[i+1]='a';
}
}
printf("%d\n",sum);
printf("%s",... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include<bits/stdc++.h>
using namespace std;
struct Node
{
int id,val;
}a[1007];
bool cmp(Node a,Node b)
{
return a.val<b.val;
}
int main()
{
int n;cin>>n;
for(int i=1;i<=n;i++)cin>>a[i].val,a[i].id=i;
sort(a+1,a+1+n,cmp);
int ans[1007];
long long res=0;
int t=1;
for(int i=n;i>=1;i--... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include <iostream>
#include <algorithm>
using namespace std;
int n;
struct node{
int data,id;
}a[1005];
long long ans;
bool cmp(node a,node b){
return a.data>b.data;
}
int main(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i].data;
a[i].id=i;
}
sort(a+1,a+n+1,cmp);
for(int i=1;i<... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=1100;
struct node
{
int id,s;
}a[N];
int d[N];
bool cmp(node a,node b)
{
return a.s>b.s;
}
int main()
{
int n;
scanf("%d",&n);
for(int i=0;i<n;i++)
{
scanf("%d",&a[i].s);
a[i].id=i+1;
}
sort(a,a... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <inttypes.h>
using namespace std;
int main()
{
int n;
cin>>n;
int a[n];
int b[n];
long long cost =0 ;
for(int i=0;i<n;i++)
cin>>a[i];
std::copy(a, a+n, b);
sort(a, a + n, greater<int>());
cost = 1;
for (int i = 1; i < n; ++i)
{
... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include <bits/stdc++.h>
using namespace std;
typedef long long int lld;
int n, m;
pair<int, int> edge_list[5010];
vector<int> adj[5010];
int state[5010];
bool cycle;
void dfs(int node){
if(state[node]==1){
cycle = true;
return;
}
if(state[node]==2) return;
state[node] = 1;
for(int viz:adj[node]){
dfs(viz)... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include<bits/stdc++.h>
#define mxn 1000010
#define db double
#define LL long long
#define ldb long double
#define pb push_back
#define ppb pop_back
#define pf push_front
#define pii pair<int,int>
#define mp make_pair
#define fr first
#define sc second
using namespace std;
const int inf=1e9;
LL n,sl,fh,a[mxn],s[mxn],b... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include <bits/stdc++.h>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll read(){
ll ans=0;char c=getchar();
while(c<'0'||c>'9') c=getchar();
while(c>='0'&&c<='9') ans=ans*10+c-48,c=getchar();
return ans;
}
int n;
ll a[400011];
int b[400011];
int t[100];
int main(){
n=read();
for(int i=1;i<=n... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include<iostream>
using namespace std;
int main()
{
int n, i, j;
char a[100][100];
cin>>n;
for (i=0; i<n; i++)
{
for (j=0; j<n; j++)
if ((i+j)%2==0)
a[i][j]='W';
else
a[i][j]='B';
}
for (i=0; i<n; i++)
{
for (... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include<bits/stdc++.h>
using namespace std;
int main(){
int a ;
cin>>a;
string b,c,ans;
b="BWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBW";
c="WBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBWBW... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
int main()
{
int n;
cin >> n;
for(int i=0; i<n; i++){
if((i%2)==0){
for(int j=0; j<n ; j++){
if((j%2) ==0)
cout<<"W";
else cout<<"B";
}
}
else{
for(int j=0... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
for(int i=1; i<=n; i++) {
for(int j=1; j<=n; j++) {
if(i&1) {
if(j&1) cout << "W";
else cout << "B";
}
else {
if(j%2 == 0) cout << "W";
... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
int n;
cin>>n;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(i%2==0&&j%2==0)
cout<<"B";
else if(i%2==0&&j%2==1)
cout<<"W";
else if(i%2==1&&j%2==0)
cout<<"W";
else
cout<<"B";
}
cout<<endl;
}
return... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include <iostream>
using namespace std;
int main()
{
long long da,db;
cin >> da >> db;
if (db-da==1)
cout << db*10-1 << " " << db*10;
else if (da==db)
cout << da*10 << " " << db*10+1;
else if (da==9 && db==1)
cout << "99" << " " << "100";
else cout << "-1";
return 0;... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
const int N=300000;
int st[N],en[N],n,x,y,size[N];
double ans=0,sst,sen;
vector<int> v[N];
void dfs(int x,int fx){
size[x]=1;
for(int i=0;i<v[x].size();i++){
if(v[x][i]!=fx){
dfs(v[x][i],x);
size[x]+=size[v[x][... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include <bits/stdc++.h>
using namespace std;
#define ld long double
#define ll long long
#define N ((ll)101*1000)
ll n,a[N],b[N],sum1,sum2,sz[N],num[N];
ld ans;
vector <ll> e[N];
void dfs(ll x,ll par=0)
{
sz[x]=1;num[x]=a[x];
for(auto u:e[x])
if(u!=par)
{
dfs(u,x);
sz[x]+=sz[u];
num[... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include <bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false); cin.tie(NULL);
int n; cin >> n;
for(int i = 0; i < n; ++i) {
for(int j = 0; j < n; ++j) {
if(j * 2 < n) cout << j * n + i + 1 << " ";
else cout << j * n + n - i << " ";
}
cout << endl;
}
ret... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | /*
*/
#include <bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
using namespace std;
void solve(){
//solve here//
int n;
cin >> n;
int diff[2] = {0};
int x = 0;
bool indi;
int num = 1;
int temp = n-1;
i... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include<bits/stdc++.h>
using namespace std;
int main()
{
int i,j,k;
int n;
scanf("%d",&n);
if(n&1){
k=1;
for(i=1,j=n*n;i<j-n;i++,j--){
printf("%d ",i);
printf("%d ",j);
if(i%(n/2)==0 && (n*n-j+1)%(n/2)==0){
printf("%d\n",n*(n/2)+k);
... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include <iostream>
#include <vector>
#include <random>
#include <set>
#include <cmath>
#include <queue>
using namespace std;
random_device rd;
mt19937 rnd(rd());
uniform_int_distribution<int> nextRand(0, (int)1e9);
vector <int> A;
int n;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr), cout.tie(n... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=3e5+10;
int main()
{
int n,x;int sum=0;
int flag=0;
cin>>n;
for(int i=1;i<=n;i++)
{
scanf("%d",&x);
if(x%2==0)printf("%d\n",x/2),sum+=x/2;
else
{
if(flag==0)
{
... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld double
#define mx 100000
int main()
{
ll i, j, n, m, x, odp=0, odn=0;
scanf("%lld", &n);
while(n--)
{
scanf("%lld", &x);
if(abs(x)%2==0) printf("%lld\n", x/2);
else
{
if(x>0)
... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include<bits/stdc++.h>
using namespace std;
#define ll long long
#define flash ios_base::sync_with_stdio(false); cin.tie(NULL),cout.tie(NULL);
int main()
{
flash
ll n;
cin>>n;
ll i=0,j=0;
while(n--)
{
ll a,k;
cin>>a;
if(a%2==0)
k=a/2;
else
{
... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include<bits/stdc++.h>
using namespace std;
const int N = 1e4 + 10;
char s[N], t[N];
int tot[30];
struct node{
int a, b;
}p[200];
int main()
{
int T;cin>>T;
while(T--){
memset(tot, 0, sizeof tot);
int n, cnt = 0, flag = 0;
scanf("%d", &n);
scanf("%s", s + 1);
scanf("%s", t + 1);
for(int i = 1; i <= n; ... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int n,h[266];
char s[55],t[55];
vector<pair<int,int>>ans;
int main()
{
int _;
scanf("%d",&_);
while(_--)
{
for(int i='a';i<='z';i++)h[i]=0;
ans.clear();
scanf("%d%s%s",&n,s,t);
for(int i=0;i<n;i++)
h[s[i]]++,h[t[i]]++;
for(int i='a... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int main()
{
ll t;
cin >> t;
while(t--) {
ll a, b, c, d, k;
cin >> a >> b >> c >> d >> k;
ll pen = ceil((double) a/c);
ll pencil = ceil((double) b/d);
if(pen + pencil <= k) {
cout << pen <<" " << pencil << endl;
}
else cout << -... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include <bits/stdc++.h>
using namespace std;
void solve() {
int a, b, c, d, k;
cin >> a >> b >> c >> d >> k;
int x = (a / c) + (a % c != 0);
int y = (b / d) + (b % d != 0);
if (x + y <= k) {
cout << x << " " << y << '\n';
} else {
cout << "-1\n";
}
}
int main() {
ios_... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include"bits/stdc++.h"
#define ll long long int
#define mod 1e9+7
using namespace std;
#define fastio ios_base::sync_with_stdio(0); cin.tie(0);
int main()
{
fastio;
ll t = 0;
cin >> t;
while (t--)
{
ll a = 0, b = 0, c = 0, d = 0, k = 0;
cin >> a >> b >> c >> d >> k;
int x = 0, y = 0;
x = a / c;
y = b / ... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include<bits/stdc++.h>
#define bclz(x) (__builtin_clz(x))
#define x first
#define y second
using namespace std;
typedef long long INT;
typedef vector<int> VI;
typedef pair<int,int> pii;
int main(){
#ifndef ONLINE_JUDGE
freopen("in.in","r",stdin);
freopen("out.out","w",stdout);
#endif
int t;
cin>>t;
while(t--){
... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define mod 1000000007
#define M 100001
#define endl "\n"
#define all(a) (a).begin(),(a).end()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define F first
#define S second
#define pb push_back
#define m... |
You are a coding expert. Given a competition-level coding problem, you need to write a Python program to solve it. You may start by outlining your thought process. In the end, please provide the complete code in a code block enclosed with ``` ```. The code should take stdin as input and print the output. Your program s... | #include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
ll n,p,w,d;
scanf("%lld %lld %lld %lld",&n,&p,&w,&d);
ll ma=min(p/w,n);
for(int i=0;i<=min(ma,d);i++)
{
ll temp=ma-i;
if((p-temp*w)%d==0)
{
ll temp2=(p-temp*w)/d;
if(n<temp+temp2)
break;
printf("%lld %lld %lld\n",temp... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.