304 North Cardinal St.
Dorchester Center, MA 02124

# Copy and Push Back CodeChef Solution

## Copy and Push Back CodeChef Solution in C++17

``````

#include <bits/stdc++.h>
using namespace std;

bool manoj(string s){
if(s.size() == 0 || s.size() == 1) return true;
if(s.size()%2 != 0){
int n=s.size();
return manoj(s.substr(0,n -1));
}
int n=s.size();
if(s.substr(0,n/2) == s.substr(n/2,n)){
return manoj(s.substr(0,n/2));
}
return false;
}

int main() {
int t;cin>>t;
while(t--){
int n;int f=0;
cin>>n;string s;cin>>s;
if(manoj(s))
cout<<"YES";
else cout<<"NO";cout<<"\n";
}
return 0;
}``````

## Copy and Push Back CodeChef Solution in C++14

``````#include <iostream>
using namespace std;

int main() {

int t;
cin>>t;

while(t--){

int n;
cin>>n;
string s;
cin>>s;

if(n==1)cout<<"YES\n";
else if (n==2){

if(s[0]==s[1])cout<<"YES\n";
else cout<<"NO\n";
}else{

bool q=true;
int cnt=0;

if(s[0]!=s[1])cout<<"NO\n";

else
{
int idx=n-1;

while(idx>1){

if(idx%2==0){
idx-=1;
}else{
int len=(idx+1)/2;
if ((idx-2*len+1)>=0 &&  s.substr(idx-len+1,len)==s.substr(idx-2*len+1,len)){
idx-=(len);
}else{
q=false;
break;
}

}

}

if(q)cout<<"YES\n";
else cout<<"NO\n";

}

}

}
return 0;
}``````

## Copy and Push Back CodeChef Solution in PYTH 3

``````# cook your dish here
t=int(input())
for i in range(t):
n=int(input())
s=input()
while(len(s)>0):
if len(s)&1!=0:
s=s[:-1]
else:
m=len(s)//2
if s[:m]==s[m:]:
s=s[:m]
else:
break
if len(s)==0:
print("YES")
else:
print("NO")``````

## Copy and Push Back CodeChef Solution in C

``````#include <stdio.h>

int main (void)
{
int t;
scanf("%d", &t);

while (t--) {
int n, len, i, c;
char arr[1000001];
scanf("%d", &n);
scanf("%s", arr);
len =n;
c= 1;

while (len && c) {
if (len % 2) {
len--;
}

for (i = 0; i < (len/2); i++) {
if (arr[i] != arr[(len/2) + i]) {
c = 0;
break;
}
}
len = len/2;
}

if (c) {
printf("YES\n");
} else {
printf("NO\n");
}
}

return 0;
}``````

## Copy and Push Back CodeChef Solution in JAVA

``````import java.util.*;
import java.io.*;

class A {
StringTokenizer st;

}
String next() {
while(st == null || !st.hasMoreElements()) {
try {
}
catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}

int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine () {
String str = "";
try {
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
static class Pair {
int first;
int second;
}
public static void main(String args[]) {
StringBuilder ans = new StringBuilder();
int t = fs.nextInt();
while(t-- > 0) {
int n = fs.nextInt();
String a = fs.next();
boolean possible = true;
while(n > 0) {
if(n % 2 == 1) {
n--;
}
else {
int mid = n / 2 - 1;
int i = 0, j = mid + 1;
while(i <= mid) {
if(a.charAt(i) != a.charAt(j)) {
possible = false;
break;
}
i++;
j++;
}
if(possible) {
n /= 2;
}
else {
break;
}
}
}
if(possible) {
ans.append("YES\n");
}
else {
ans.append("NO\n");
}
}

// abababab

System.out.print(ans);
}
}``````

## Copy and Push Back CodeChef Solution in PYPY 3

``````t=int(input())
while t!=0:
n=int(input())
s=input()
while len(s):
if len(s)%2==0:
if s[:len(s)//2]==s[len(s)//2:]:
s=s[:len(s)//2]
else:
break
else:
s = s[:-1]
if len(s)==0:
print("yes")
else:
print("no")
t-=1

``````

## Copy and Push Back CodeChef Solution in PYTH

``````from collections import defaultdict
import sys

def rec(s):
if not s:
return True
if len(s)==1:
return True
if len(s)%2:
return rec(s[:-1])
if s[:len(s)//2] == s[len(s)//2:]:
return rec(s[:len(s)//2])
return False

def solve():
n = int(input())
s = list(input().strip())
if rec(s):
print("YES")
else:
print("NO")

for _ in range(int(input())):
solve()``````

## Copy and Push Back CodeChef Solution in C#

``````using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class Test
{
//private static int limit = 65536;//(int)Math.Pow(2, 14);
//Console.WriteLine(limit);
//private static int[,] xors = new int[limit, limit];
public static void Main()
{
var inputStr = string.Empty;
//for(int i = 0; i < noOfTestCases; i++)
while(noOfTestCases-- > 0)
{
//var inputData = inputStr.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList().Select(x => int.Parse(x)).ToArray();

Copy(N, inputStr);
}
}

private static void Copy(int N, string s)
{
if(IsCopy(s))
Console.WriteLine("Yes");
else
Console.WriteLine("No");
}

private static bool IsCopy(string s)
{
int l = s.Length;

string s1 = s.Substring(0, l / 2);
string s2 = s.Substring(l / 2, l / 2);
if(s1 != s2)
return false;
if(l <= 2)
return true;

if(!IsCopy(s1))
return false;

if(!IsCopy(s2))
return false;

return true;
}

private static int[] GetInputLineValues(int N)
{
Console.WriteLine(N);
var inputData = new List<int>();
var stringInp = string.Empty;
for(int i = 0; i < N; i++)
{
if(stringInp != string.Empty)
{
}
stringInp = string.Empty;
}

return inputData.ToArray();
}

private static string[] GetInputLineValuesAsStrings(int N)
{
//Console.WriteLine(N);
var inputData = new List<string>();
var stringInp = string.Empty;
for(int i = 0; i < N; i++)
{
if(stringInp != string.Empty)
{
}
stringInp = string.Empty;
}

return inputData.ToArray();
}
}``````

## Copy and Push Back CodeChef Solution in NODEJS

``````process.stdin.resume();
process.stdin.setEncoding('utf8');
let arr = "";
process.stdin.on('data', function (chunks) {
arr += chunks;
});
process.stdin.on('end', function () {
arr = arr.split("\n");
let testcases = parseInt(arr.shift());
for (let i = 0; i < testcases*2; i=i+2) {
let n=parseInt(arr[i]);
let arry=arr[i+1];
console.log(COPYPUSH(n,arry))
}
});
function COPYPUSH(n,arry){
if(n==1){
return 'YES'
}
let m=n;
let flag=true;
while(m>0){
if(m%2==0){
let mid=m/2;
let i=0;
let j=mid;
while(i!=mid){
if(arry[i]!=arry[j]){
flag=false;
break;
}
i++;
j++;
}
if(!flag){
break;
}
m=m/2;
}else{
m--;
}
}
// console.log(count,i,j)
if(flag){
return 'YES'
}else{
return 'NO'
}
}
function prefix_suffix(n,arry){
let lps=Array(n);
lps[0]=0;
let len=0;
let i=1;
while(i<n){
if(arry[i]==arry[len]){
len++;
lps[i]=len;
i++;
}else{
if(len==0){
lps[i]=0;
i++;
}else{
len--
}
}
}
// console.log(lps)
if(n%2==0&& lps[n-1]==n/2){
return 'YES'
}else if(n%2!=0&&(lps[n-2]==Math.ceil(n/2) ||
lps[n-2]==Math.floor(n/2))){
return 'YES'
}else{
return 'NO'
}
}``````

## Copy and Push Back CodeChef Solution in GO

``````package main

import (
"bufio"
"bytes"
"fmt"
"os"
)

func main() {

var buf bytes.Buffer
for tc > 0 {
tc--
res := solve(s)
if res {
buf.WriteString("YES\n")
} else {
buf.WriteString("NO\n")
}
}
fmt.Print(buf.String())
}

func readUint64(bytes []byte, from int, val *uint64) int {
i := from

var tmp uint64
for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
tmp = tmp*10 + uint64(bytes[i]-'0')
i++
}
*val = tmp

return i
}

func readInt(bytes []byte, from int, val *int) int {
i := from
sign := 1
if bytes[i] == '-' {
sign = -1
i++
}
tmp := 0
for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
tmp = tmp*10 + int(bytes[i]-'0')
i++
}
*val = tmp * sign
return i
}

for i := 0; i < len(s); i++ {
if s[i] == '\n' {
return s[:i]
}
}
return s
}

return
}

a, b = res[0], res[1]
return
}

a, b, c = res[0], res[1], res[2]
return
}

res := make([]int, n)
x := 0
for i := 0; i < n; i++ {
for x < len(bs) && (bs[x] < '0' || bs[x] > '9') && bs[x] != '-' {
x++
}
}
return res
}

func solve(s string) bool {
n := len(s)

for n > 1 {
if n&1 == 1 {
// odd length
n--
}
for i, j := 0, n/2; j < n; i, j = i+1, j+1 {
if s[i] != s[j] {
return false
}
}
n /= 2
}
return n == 1
}``````
##### Copy and Push Back CodeChef Solution Review:

In our experience, we suggest you solve this Copy and Push Back CodeChef Solution and gain some new skills from Professionals completely free and we assure you will be worth it.

If you are stuck anywhere between any coding problem, just visit Queslers to get the Copy and Push Back CodeChef Solution.

Find on CodeChef

##### Conclusion:

I hope this Copy and Push Back CodeChef Solution would be useful for you to learn something new from this problem. If it helped you then don’t forget to bookmark our site for more Coding Solutions.

This Problem is intended for audiences of all experiences who are interested in learning about Programming Language in a business context; there are no prerequisites.

Keep Learning!