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. python基础学习第二天

    读文件 r 要以读文件的模式打开一个文件对象,使用Python内置的open()函数,传入文件名和标示符 写文件 w 写文件和读文件是一样的,唯一区别是调用open()函数时,传入标识符’w’或者’w ...

  2. C++ new/malloc、delete/free

    1.new和delete是运算符,可以被重载:malloc和free是库函数,不能被重载. 2.new会调用对象的构造函数,delete会调用对象的析构函数:malloc和free不会.

  3. ubuntu开机自动运行用Qt写的程序

    这里介绍一种在ubuntu系统开机自动运行使用Qt编写的程序的方法.首先要注意要自动运行Qt编的程序,不需要先打开Qt,而是直接运行编译好的与工程名同名的可执行文件即可,比如我要运行的工程为QRDec ...

  4. Android应用更新-自动检测版本及自动升级

    原文 http://www.cnblogs.com/keyindex/articles/1819504.html 注:实质,把自己新版的APK放在可以下载的地方,先自己设置个通信,检查版本,我是直接放 ...

  5. 通过重建清理SVN服务器无用目录,不丢失其他目录修改记录

    1.主要时有时间希望调整一些文件的目录结构,或者移除一个大量占用空间的文件节省服务器磁盘,但是又不希望调整后,对应的修改记录丢失.这时可以通过服务器目录重建实现. 2.重建后只是被排除掉的目录的修改记 ...

  6. React-简书视频学习总结

    react的基础语法 redux这个数据层框架 react-redux如何方便我们在react中使用redux react-router 4.0 这样的非常实用的相关的第三方模块儿 immutable ...

  7. [转][南京米联ZYNQ深入浅出]第二季更新完毕课程共计16节课

    [南京米联]ZYNQ第二季更新完毕课程共计16节课 [第二季ZYNQ]                                                                  ...

  8. (译)理解 LSTM 网络 (Understanding LSTM Networks by colah)

    @翻译:huangyongye 原文链接: Understanding LSTM Networks 前言:其实之前就已经用过 LSTM 了,是在深度学习框架 keras 上直接用的,但是到现在对LST ...

  9. GBDT和随机森林的区别

    GBDT和随机森林的相同点: 1.都是由多棵树组成 2.最终的结果都是由多棵树一起决定 GBDT和随机森林的不同点: 1.组成随机森林的树可以是分类树,也可以是回归树:而GBDT只由回归树组成 2.组 ...

  10. A2dp连接流程源码分析

    在上一篇文章中,我们已经分析了:a2dp初始化流程 这篇文章主要分析a2dp的连接流程,其中还是涉及到一些底层的profile以及protocol,SDP.AVDTP以及L2CAP等. 当蓝牙设备与主 ...