Using scanf giving wrong answer

#include
#include
using namespace std;

int main()
{
int n;
scanf("%d",&n);
int64_t l;
l=int64_t(n)*int64_t(n+1);
l=(int64_t)(l)/2;
int64_t total(0);
for (int c(0);c<n;c++){
/* char r;
bool start=false,neg=false;
int64_t ret=0;
while(true){
r=getchar();
if((r-'0'<0 || r-'0'>9) && r!='-' && !start){
continue;
}
if((r-'0'<0 || r-'0'>9) && r!='-' && start){
break;
}
if(start)ret*=10;
start=true;
if(r=='-')neg=true;
else ret+=r-'0';
}
if(neg)
ret=-ret;
*/
int64_t ret;
scanf("%I64d",&ret);
total=(int64_t)total+(int64_t)ret;
 
}
 
if ((int64_t)total>=(int64_t)l){printf("YES\n");} else printf("NO\n");
return 0;
}

this gives wrong answer for http://www.codechef.com/COOK44/problems/DIVIDING
however if i replace scanf() by cin then it the answer is right please explain this thanx in advance

Try

scanf("%d\n",&n);

its not working !! but atleast thanx for replying

//