Lucky Ticket

CodeForces - 146A

Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.

Petya loves tickets very much. As we know, each ticket has a number that is a positive integer. Its length equals n (n is always even). Petya calls a ticket lucky if the ticket's number is a lucky number and the sum of digits in the first half (the sum of the first n / 2 digits) equals the sum of digits in the second half (the sum of the last n / 2 digits). Check if the given ticket is lucky.

Input

The first line contains an even integer n (2 ≤ n ≤ 50) — the length of the ticket number that needs to be checked. The second line contains an integer whose length equals exactly n — the ticket number. The number may contain leading zeros.

Output

On the first line print "YES" if the given ticket number is lucky. Otherwise, print "NO" (without the quotes).

Examples

Input
2
47
Output
NO
Input
4
4738
Output
NO
Input
4
4774
Output
YES

Note

In the first sample the sum of digits in the first half does not equal the sum of digits in the second half (4 ≠ 7).

In the second sample the ticket number is not the lucky number.

sol:按题意暴力模拟就可以了

#include <bits/stdc++.h>
using namespace std;
typedef int ll;
inline ll read()
{
ll s=;
bool f=;
char ch=' ';
while(!isdigit(ch))
{
f|=(ch=='-'); ch=getchar();
}
while(isdigit(ch))
{
s=(s<<)+(s<<)+(ch^); ch=getchar();
}
return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
if(x<)
{
putchar('-'); x=-x;
}
if(x<)
{
putchar(x+''); return;
}
write(x/);
putchar((x%)+'');
return;
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('\n')
const int N=;
int n,A[N];
int main()
{
int i,S1=,S2=;
R(n);
for(i=;i<=n;i++)
{
char ch=' ';
while(!isdigit(ch)) ch=getchar();
A[i]=ch-'';
if((A[i]!=)&&(A[i]!=)) return *puts("NO");
if(i<=(n>>)) S1+=A[i]; else S2+=A[i];
}
if(S1!=S2) puts("NO");
else puts("YES");
return ;
}
/*
input
6
477477
output
YES
*/

codeforces146A的更多相关文章

随机推荐

  1. Vue2 第二天学习

    个人小总结:1年多没有写博客,感觉很多知识点生疏了,虽然工作上能解决问题,但是当别人问到某个知识点的时候,还是迷迷糊糊的,所以坚持写博客是硬道理的,因为大脑不可能把所有的知识点记住,有可能某一天忘了, ...

  2. MySQL 基础八 用户管理

    SELECT * FROM student INSERT INTO student(NAME,sex,createuser,createtime) VALUES('jack','男','ligenyu ...

  3. 【Codeforces 464D】World of Darkraft - 2

    Codeforces 464 D 首先我们知道这K个装备是互不干扰的,就是说如果一个装备升级了或者卖掉了,不会对其它装备的挣到的钱产生任何影响.所以我们就考虑单独处理某一个装备挣到的钱. 那么就设\( ...

  4. Ubuntu 上安装QTAV第三方视频库

    安装QtAV的基本环境: sudo apt-get install build-essential sudo apt-get install libgl1-mesa-dev sudo apt-get ...

  5. 配置进程外的Session

    1.Session保存在SQLServer中配置方法 1)运行.NetFramework安装目录下对应版本的aspnet_regsql.exe 来创建相关的数据库.表和存储过程等,比如: C:\Win ...

  6. mvn打包到私服的命令

    1.mvn clean package install -Dmaven.test.skip=true deploy 2.docker清楚Nexus私服上包的命令: a) docker exec -it ...

  7. SSIS ->> Excel Destination无法接受大于255个字符长度的字符字段(转载)

    从下文的链接中找到一些背景,因为Excel会以前8行作为参考,如果某个字段前8行的最长长度没有超过255个字符,就会报错.如果知道某个字段属于描述性字段,而且字段的数据长度很可能超过255个字符长度, ...

  8. Bootstrap Search Suggest 下拉框模糊查询

    源码地址:https://github.com/lzwme/bootstrap-suggest-plugin 有时间会完善!暂时有点忙!

  9. iOS app签名原理

    基本原理: 公钥能够验证私钥的签名是否正确. Apple后台有一个私钥A,iOS内置一个公钥A,与私钥A对应.(A:代表Apple,即苹果) 本地产生一对公钥L.私钥L,(L:代表Local,即本地) ...

  10. Java 大数、高精度模板

    介绍: java中用于操作大数的类主要有两个,一个是BigInteger,代表大整数类用于对大整数进行操作,另一个是BigDecimal,代表高精度类,用于对比较大或精度比较高的浮点型数据进行操作.因 ...