当前位置: 首页 > article >正文

A. Turtle and Good Strings

time limit per test

1 second

memory limit per test

256 megabytes

Turtle thinks a string ss is a good string if there exists a sequence of strings t1,t2,…,tkt1,t2,…,tk (kk is an arbitrary integer) such that:

  • k≥2k≥2.
  • s=t1+t2+…+tks=t1+t2+…+tk, where ++ represents the concatenation operation. For example, abc=a+bcabc=a+bc.
  • For all 1≤i<j≤k1≤i<j≤k, the first character of titi isn't equal to the last character of tjtj.

Turtle is given a string ss consisting of lowercase Latin letters. Please tell him whether the string ss is a good string!

Input

Each test contains multiple test cases. The first line contains the number of test cases tt (1≤t≤5001≤t≤500). The description of the test cases follows.

The first line of each test case contains a single integer nn (2≤n≤1002≤n≤100) — the length of the string.

The second line of each test case contains a string ss of length nn, consisting of lowercase Latin letters.

Output

For each test case, output "YES" if the string ss is a good string, and "NO" otherwise.

You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses.

Example

Input

Copy

 

4

2

aa

3

aba

4

abcb

12

abcabcabcabc

Output

Copy

No
nO
Yes
YES

Note

In the first test case, the sequence of strings a,aa,a satisfies the condition s=t1+t2+…+tks=t1+t2+…+tk, but the first character of t1t1 is equal to the last character of t2t2. It can be seen that there doesn't exist any sequence of strings which satisfies all of the conditions, so the answer is "NO".

In the third test case, the sequence of strings ab,cbab,cb satisfies all of the conditions.

In the fourth test case, the sequence of strings abca,bcab,cabcabca,bcab,cabc satisfies all of the conditions.

解题说明:水题,直接拆成两个字符串,然后比较首尾是否一致,如果一致就不存在了。

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

int T, n;
string s;

int main() 
{
	cin >> T;
	while (T--)
	{
		cin >> n >> s;
		if (s[0] == s[n - 1])
		{
			puts("NO");
		}
		else
		{
			puts("YES");
		}
	}
	return 0;
}


http://www.kler.cn/a/392440.html

相关文章:

  • 提取神经网络数学表达式
  • Linux kernel 堆溢出利用方法(二)
  • 大数据技术之HBase中的HRegion
  • Android 配置默认输入法
  • 《DiffusionDet: Diffusion Model for Object Detection》ICCV2023
  • 机器学习——损失函数、代价函数、KL散度
  • 富格林:可信预判交易安全契机
  • P2356 弹珠游戏
  • HarmonyOS NEXT应用元服务开发Intents Kit(意图框架服务)上架配置指导
  • STM32 4X4 键盘
  • Elasticsearch常用接口_添加数据
  • 会议直击|美格智能受邀出席第三届无锡智能网联汽车生态大会,共筑汽车产业新质生产力
  • 一生一芯 预学习阶段 NEMU代码学习(2)
  • C++总结
  • 【AI大模型】ELMo模型介绍:深度理解语言模型的嵌入艺术
  • Git - 命令杂谈 - reset、revert和clean
  • 容器docker的ulimit
  • 设备接入到NVR管理平台EasyNVR多品牌NVR管理工具/设备的音视频配置参考
  • Redis相关技术内容
  • 一条SQL查询语句的执行流程(MySQL)
  • 微信小程序进行md5加密 ,base64 转码
  • nuxt3添加wowjs动效
  • mysql 实现分库分表之 --- 基于 MyCAT 的分片策略详解
  • windows中docker安装redis和redisinsight记录
  • 什么时候用 Tailwind 什么时候用 CSS
  • 第 8 章 - Go语言 数组与切片