A :

A. Doggo Recoloring
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Panic is rising in the committee for doggo standardization — the puppies of the new brood have been born multi-colored! In total there are 26 possible colors of puppies in the nature and they are denoted by letters from 'a' to 'z' inclusive.

The committee rules strictly prohibit even the smallest diversity between doggos and hence all the puppies should be of the same color. Thus Slava, the committee employee, has been assigned the task to recolor some puppies into other colors in order to eliminate the difference and make all the puppies have one common color.

Unfortunately, due to bureaucratic reasons and restricted budget, there's only one operation Slava can perform: he can choose a color x

such that there are currently at least two puppies of color x and recolor all puppies of the color x into some arbitrary color y

. Luckily, this operation can be applied multiple times (including zero).

For example, if the number of puppies is 7

and their colors are represented as the string "abababc", then in one operation Slava can get the results "zbzbzbc", "bbbbbbc", "aaaaaac", "acacacc" and others. However, if the current color sequence is "abababc", then he can't choose x

='c' right now, because currently only one puppy has the color 'c'.

Help Slava and the committee determine whether it is possible to standardize all the puppies, i.e. after Slava's operations all the puppies should have the same color.

Input

The first line contains a single integer n

(1≤n≤105

) — the number of puppies.

The second line contains a string s

of length n consisting of lowercase Latin letters, where the i-th symbol denotes the i

-th puppy's color.

Output

If it's possible to recolor all puppies into one color, print "Yes".

Otherwise print "No".

Output the answer without quotation signs.

Examples
Input

Copy
6
aabddc
Output

Copy
Yes
Input

Copy
3
abc
Output

Copy
No
Input

Copy
3
jjj
Output

Copy
Yes
Note

In the first example Slava can perform the following steps:

  1. take all puppies of color 'a' (a total of two) and recolor them into 'b';
  2. take all puppies of color 'd' (a total of two) and recolor them into 'c';
  3. take all puppies of color 'b' (three puppies for now) and recolor them into 'c'.

In the second example it's impossible to recolor any of the puppies.

In the third example all the puppies' colors are the same; thus there's no need to recolor anything.

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
#pragma GCC diagnostic error "-std=c++11"
#pragma GCC optimize("-fdelete-null-pointer-checks,inline-functions-called-once,-funsafe-loop-optimizations,-fexpensive-optimizations,-foptimize-sibling-calls,-ftree-switch-conversion,-finline-small-functions,inline-small-functions,-frerun-cse-after-loop,-fhoist-adjacent-loads,-findirect-inlining,-freorder-functions,no-stack-protector,-fpartial-inlining,-fsched-interblock,-fcse-follow-jumps,-fcse-skip-blocks,-falign-functions,-fstrict-overflow,-fstrict-aliasing,-fschedule-insns2,-ftree-tail-merge,inline-functions,-fschedule-insns,-freorder-blocks,-fwhole-program,-funroll-loops,-fthread-jumps,-fcrossjumping,-fcaller-saves,-fdevirtualize,-falign-labels,-falign-loops,-falign-jumps,unroll-loops,-fsched-spec,-ffast-math,Ofast,inline,-fgcse,-fgcse-lm,-fipa-sra,-ftree-pre,-ftree-vrp,-fpeephole2",3)
#pragma GCC target("avx","sse2")
typedef long long ll;
const double PI = acos(-1.0);
const int INF = ;
const int maxn = ; void Debug()
{
puts("");
cout<<"+++++++++++++++++++++++++++�ֽ���++++++++++++++++++++++++++++++"<<endl;
for(int i=; i<; i++)
{
for(int j=; j<; j++)
{
cout<<<<" ";
}
cout<<endl;
}
cout<<"+++++++++++++++++++++++++++�ֽ���++++++++++++++++++++++++++++++"<<endl;
puts("");
}
int vis[]; char f[]; int flag = ; int main ()
{
int n;scanf ("%d" , &n);scanf ("%s" , &f);
if (n == ){printf ("YES\n");return ;}
for (int i = ; i < n ; i++){int h = f[i] - 'a';vis[h]++;if (vis[h] >= ){
flag++;
break;
}
}if (flag) printf ("YES\n");
else printf ("NO\n");
}

B:

B. Weakened Common Divisor
time limit per test

1.5 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

During the research on properties of the greatest common divisor (GCD) of a set of numbers, Ildar, a famous mathematician, introduced a brand new concept of the weakened common divisor (WCD) of a list of pairs of integers.

For a given list of pairs of integers (a1,b1)

, (a2,b2), ..., (an,bn) their WCD is arbitrary integer greater than 1

, such that it divides at least one element in each pair. WCD may not exist for some lists.

For example, if the list looks like [(12,15),(25,18),(10,24)]

, then their WCD can be equal to 2, 3, 5 or 6 (each of these numbers is strictly greater than 1

and divides at least one number in each pair).

You're currently pursuing your PhD degree under Ildar's mentorship, and that's why this problem was delegated to you. Your task is to calculate WCD efficiently.

Input

The first line contains a single integer n

(1≤n≤150000

) — the number of pairs.

Each of the next n

lines contains two integer values ai, bi (2≤ai,bi≤2⋅109

).

Output

Print a single integer — the WCD of the set of pairs.

If there are multiple possible answers, output any; if there is no answer, print −1

.

Examples
Input

Copy
3
17 18
15 24
12 15
Output

Copy
6
Input

Copy
2
10 16
7 17
Output

Copy
-1
Input

Copy
5
90 108
45 105
75 40
165 175
33 30
Output

Copy
5
Note

In the first example the answer is 6

from the third ones. Note that other valid answers will also be accepted.

In the second example there are no integers greater than 1

satisfying the conditions.

In the third example one of the possible answers is 5

开始想复杂勒, 其实只要求出每行两个数的最小公倍数,再求所有最小公倍数的最大公因数,判断是否为1;

#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<map>
#include<set>
#include<bitset>
#include<map>
#include<queue>
#include<cmath>
#include<stack>
#include<vector>
#define INF 0x3f3f3f3f
#define pii pair<int,int>
#define LL long long
#define mk(a,b) make_pair(a,b)
#define rep(i,n) for(int i=1;i<=n;i++)
using namespace std;
LL a[][];
inline LL gcd(LL x,LL y){
return y?gcd(y,x%y):x;
}
int main(){
int n;
scanf("%d",&n);
LL sum=,ans=;
for(int i=;i<=n;i++){
scanf("%lld%lld",&a[i][],&a[i][]);
sum=gcd(a[i][]*a[i][],sum);
}
if(sum==){
printf("-1\n");
return ;
}
for(int i=;i*i<=a[][];i++){
if(ans==&&sum%i==)ans=i;
while(a[][]%i==)a[][]/=i;
}
if(ans==&&a[][]>&&sum%a[][]==)ans=a[][];
for(int i=;i*i<=a[][];i++){
if(ans==&&sum%i==)ans=i;
while(a[][]%i==)a[][]/=i;
}
if(ans==&&a[][]>&&sum%a[][]==)ans=a[][];
printf("%lld\n",ans);
}

C,D : 不会待补。。。

EFG  : 再说吧<>

Codeforces Round #505 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final)的更多相关文章

  1. D. Recovering BST Codeforces Round #505 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final)

    http://codeforces.com/contest/1025/problem/D 树 dp 优化 f[x][y][0]=f[x][z][1] & f[z+1][y][0] ( gcd( ...

  2. Codeforces Round #505 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final) -B C(GCD,最长连续交替序列)

    B. Weakened Common Divisor time limit per test 1.5 seconds memory limit per test 256 megabytes input ...

  3. Codeforces Round #505 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final) B. Weakened Common Divis

    题目链接 让你找一个数,使得这个数,可以被每个二元组的两个数中的一个数整除. 先将第一个二元组的两个数质因数分解一下,分解的质数加入set中,然后,对剩下的n-1个二元组进行遍历,每次遍历到的二元组对 ...

  4. Codeforces Round #505 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final)-C. Plasticine zebra

    问了学长,感觉还是很迷啊,不过懂了个大概,这个翻转操作,实质不就是在序列后面加上前面部分比如 bw | wwbwwbw  操作过后 wbwbwwbww 而 bw | wwbwwbwbw 这样我们就知道 ...

  5. Codeforces Round #505 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final) 题解

    真心简单的一场比赛 就是坑比较多(自己太蠢) A是一个水题 3分钟的时候过了 B也是一个比较简单的题 类似的套路见得多了 但是我当时可能比较困 想了一会才想出来 19分钟的时候过掉了 C同样很显然 性 ...

  6. 【Codeforces Round #505 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final) C】

    [链接] 我是链接,点我呀:) [题意] 给你一个字符串s. 让你在其中的某一些位置进行操作.. 把[1..i]和[i+1..n]翻转. 使得里面01交替出现的那种子串的长度最长. [题解] 可以用a ...

  7. 【Codeforces Round #505 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final) A】 Doggo Recoloring

    [链接] 我是链接,点我呀:) [题意] 你可以把出现次数大于1的颜色换成其他颜色. 问你最后能不能全都变成同一种颜色 [题解] 判断一下有没有出现次数大于1的就好. 有的话.显然可以一直用它变颜色. ...

  8. 【Codeforces Round #505 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final) B】Weakened Common Divisor

    [链接] 我是链接,点我呀:) [题意] 给你n个数对(ai,bi). 让你求一个大于1的数字x 使得对于任意的i x|a[i] 或者 x|b[i] [题解] 求出第一个数对的两个数他们有哪些质因子. ...

  9. E - Down or Right Codeforces Round #504 (rated, Div. 1 + Div. 2, based on VK Cup 2018 Final)

    http://codeforces.com/contest/1023/problem/E 交互题 #include <cstdio> #include <cstdlib> #i ...

随机推荐

  1. Spring中@Resource与@Autowired、@Qualifier的用法与区别

    1.@Autowired与@Resource都可以用来装配bean. 都可以写在字段上,或写在setter方法上. 2.@Autowired默认按类型装配(这个注解是属业spring的),默认情况下必 ...

  2. (原)kenel开机logo的制作

    今天项目需要,需要制作一个kernel的开机logo,所以在rk3288的平台上进行测试一番. 第一步:配置kernel:选上CONFIG_LOGO_LINUX_CLUT224选项 make menu ...

  3. Linux 开机启动顺序_005

    ***了解Linux开机启动顺序之前先了解一下Linux运行级别,通过inittab配置文件查看运行级别的定义: [root@oldboy ~]# cat /etc/inittab # Default ...

  4. php7新特性总结

    PHP新功能总结 改进的性能 - 将PHPNG代码合并到PHP7中,速度是PHP 5的两倍. 降低内存消耗 - 优化的PHP 7使用较少的资源. 标量类型声明 - 现在可以强制执行参数和返回类型. 一 ...

  5. Adding ASP.NET MVC5 Identity Authentication to an existing project

    Configuring Identity to your existing project is not hard thing. You must install some NuGet package ...

  6. 转:The Difference Between a LayoutTransform and a RenderTransform

    来自:http://www.tuicool.com/articles/fIfm22 #770 – The Difference Between a LayoutTransform and a Rend ...

  7. 用scrapy框架爬取映客直播用户头像

    1. 创建项目 scrapy startproject yingke cd yingke 2. 创建爬虫  scrapy genspider live 3. 分析http://www.inke.cn/ ...

  8. 《Spring实战》学习笔记-第五章:构建Spring web应用

    之前一直在看<Spring实战>第三版,看到第五章时发现很多东西已经过时被废弃了,于是现在开始读<Spring实战>第四版了,章节安排与之前不同了,里面应用的应该是最新的技术. ...

  9. 前端上传 base64 编码图片到七牛云存储

    参考文档 如何上传base64编码图片到七牛云 调试过程 文档中分别有 java 和 html 的 demo,可以根据文档示例调试. 下面是我调试的过程,可以作为参考,特别注意的是,如果需要给文件起名 ...

  10. swust oj 1069

    图的按录入顺序广度优先搜索 5000(ms) 10000(kb) 2347 / 4868 Tags: 广度优先 图的广度优先搜索类似于树的按层次遍历,即从某个结点开始,先访问该结 点,然后访问该结点的 ...