#include <stdio.h>

int main(){
    int n;
    int qdade;

    scanf("%d",&n);

    if(n%1000==0){
        printf("0\n");
    }else{
        n = (1000 - n%1000);
        printf("%d\n",n);
    }

    return 0;
}


#include<stdio.h>
#include<stdlib.h>

int main()
{
	int N,change;
	scanf("%d",&N);

	if(N>=1 && N<=10000)
	{
		change=(N%1000);
		printf("%d", change);
	}
	return 0;
}

Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.

Score : 100 points

Problem Statement

We will buy a product for N yen (the currency of Japan) at a shop.

If we use only 1000-yen bills to pay the price, how much change will we receive?

Assume we use the minimum number of bills required.

Constraints

1 \leq N \leq 10000

N is an integer.

Input

Input is given from Standard Input in the following format:

N

Output

Print the amount of change as an integer.

Sample Input 1

1900

Sample Output 1

100

We will use two 1000-yen bills to pay the price and receive 100 yen in change.

Sample Input 2

3000

Sample Output 2

0

We can pay the exact price.

Submitted source-code file size, in bytes.

Execution CPU time reported by official Project CodeNet metadata, in milliseconds.

Peak memory usage reported by official Project CodeNet metadata, in kilobytes.


#include <stdio.h>

int main(void){
int N;
int result;
scanf("%d",&N);

  if(N%1000 == 0){
   result = 0;
  }else{
   result = 1000-(N%1000);
  }
   printf("%d\n", result);
}


/*  AUTHOR: AKASH JAIN
*   EMAIL:  akash19jain@gmail.com
*   ID:     akash19jain
*   DATE:   13-07-2020 17:46:27
*/

// #include<algorithm>
// #include <bits/stdc++.h>
// using namespace std;

#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<ctype.h>
#define SC1(x)          scanf("%lld",&x)
#define SC2(x,y)        scanf("%lld%lld",&x,&y)
#define SC3(x,y,z)      scanf("%lld%lld%lld",&x,&y,&z)
#define SCS(x)          scanf("\n%s", x)
#define SCA(a,n)        for(long long i=0;i<n;i++)    scanf("%lld",&a[i]);
#define PF1(x)          printf("%lld\n",x)
#define PF2(x,y)        printf("%lld %lld\n",x,y)
#define PF3(x,y,z)      printf("%lld %lld %lld\n",x,y,z)
#define PFA(a,n)        for(long long i=0;i<n;i++)    printf("%lld ",a[i]); printf("\n");
#define PFN             printf("\n")
#define PFS(x)          printf("%s\n",x)
#define REP(i,n)        for(long long i=0;i<(n);++i)
#define FOR(i,a,b)      for(long long i=(a);i<=(b);++i)
#define FORD(i,a,b)     for(long long i=(a);i>=(b);--i)
#define WHILE(n)        while(n--)
#define MEM(a, b)       memset(a, (b), sizeof(a))
#define ITOC(c)         ((char)(((ll)'0')+c))
#define MID(s,e)        (s+(e-s)/2)
#define SZ(a)           strlen(a)
#define PI              3.1415926535897932384626433832795
#define DEB(x)          printf("The value of \"%s\" is: %d\n",#x,x)
#define CASES           ll t;SC1(t);while(t--)
#define ABS(a)          ((a>0)?a:-(a))
#define SWAP(a,b)       ll z=a;a=b;b=z
#define SWAPC(a,b)      char z=a;a=b;b=z
#define FLSH            fflush(stdout)
#define faster          ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef unsigned long long ull;
const ll INF = 1 << 29;
const ll MOD = 1000000007;
const ll FMOD = 998244353;
const ll MAX = 10000000005;
const ll MIN = -10000000005;
#define FILEIO(name) \  freopen(name".in", "r", stdin); \   freopen(name".out", "w", stdout);
int cmp(const void * a, const void * b);
long long maxv(long long a, long long b);
long long minv(long long a, long long b);
long long gcd(long long u, long long v);
long long digits(long long n);
bool ispoweroftwo(long long n);
bool isvowel(char x);
ll chartoint(char ch);
ll CEIL(ll x, ll y);
ll FLOOR(ll x, ll y);

int main()
{
#ifndef ONLINE_JUDGE
	freopen("F:\\COMPETITIVE-PROGRAMMING\\inp.txt", "r", stdin);
	freopen("F:\\COMPETITIVE-PROGRAMMING\\out.txt", "w", stdout);
#endif

	ll n;
	SC1(n);
	n = n % 1000;
	ll ans = 1000 - n;
	ans = ans % 1000;
	PF1(ans);
	return 0;
}

//qsort(arr,n,sizeof(arr[0]),cmp);
int cmp (const void * a, const void * b)
{
	if ( *(ll*)a - * (ll*)b < 0 ) return -1;
	if ( *(ll*)a - * (ll*)b > 0 ) return 1;
	return 0;
}
long long maxv(long long a, long long b)
{
	if (a > b) return a;
	return b;
}
long long minv(long long a, long long b)
{
	if (a < b) return a;
	return b;
}
long long gcd(long long u, long long v)
{
	if (v == 0) return u;
	return gcd(v, u % v);
}
long long digits(long long n)    //to calculate no of digits in a number
{
	return floor(log10(n)) + 1;
}
bool ispoweroftwo(long long x)
{
	return x && (!(x & (x - 1)));
}
bool isvowel(char x)
{
	return (x == 'a' || x == 'e' || x == 'i' || x == 'o' || x == 'u' );
}
ll chartoint(char ch)
{
	if (ch >= 'A' && ch <= 'Z') return (ch - 'A');
	else if (ch >= '0' && ch <= '9') return (ch - '0');
	else if (ch >= 'a' && ch <= 'z') return (ch - 'a');
	else return 0;
}
ll CEIL(ll x, ll y)
{
	if (x % y == 0) return (x / y);
	else return (x / y + 1);
}

ll FLOOR(ll x, ll y)
{
	if (x % y == 0) return (x / y);
	else return (x / y - 1);
}


#include <stdio.h>
#include <string.h>

int main(void){
  int N;
  int i1 = 0;
  int i2 = 0;
  int i3 = 0;
  int i4 = 0;
  scanf("%d",&N);
  for(int i = 0; i < N; i++){
    char str[3];
    scanf("%s", str);
    if(strcmp("AC", str) == 0){
      i1++;
    }else if(strcmp("WA", str) == 0){
      i2++;
    }else if(strcmp("TLE", str) == 0){
      i3++;
    }else if(strcmp("RE", str) == 0){
      i4++;
    }
  }
  printf("AC x %d\n",i1);
  printf("WA x %d\n",i2);
  printf("TLE x %d\n",i3);
  printf("RE x %d\n",i4);
  return 0;
}


//AtCoder Biginner Contest 173 A問題

#include <stdio.h>

int main(void) {
    int n, m;

    scanf("%d", &n);

    m = n % 1000;

    if (m == 0) {
        printf("%d", 0);
    } else {
        m = 1000 - m;
        printf("%s", m);
    }

    return 0;
}


# include <stdio.h>

int main (void)
{
  int a;
  int b;

  printf("input manny>>>");
  scanf("%d", &a);

  b -= a;
  printf("%d\n", b);

  return 0;
}


#include <stdio.h>
int main(void){
	int N,i,q;
scanf("%d",&N);
q=N%1000;
if(q!=0){
N=1000-q;
}
N=q;
printf("%d",N);
	return 0;
}


#include <stdio.h>

int main(void) {
  char input[5];
  int n, m;
  fgets(input, 4, stdin);
  sscanf(input, "%d", &n);
  while(n > 1000) n = n-1000;
  m = 1000-n;
  printf("%d", m);
  return 0;
}


#include <stdio.h>

int main(void){
  int charge,a;
  char line[5];

  fgets(line,4,stdin);
  sscanf(line,"%d",&a);

  while(a>=0){
    a = a - 1000;
  }
  charge = a * -1;
  printf("%d\n",charge);
}


#include <stdio.h>

int main()
{

printf("購入した商品の値段を入力してください\n");
int N;
scanf("%d",&N);
 for (int i = 1; i < 11; i++){
 int u = i*1000;
 if(N <= u){
 int x;
 x = u - N;
// if(N == u){
  printf("%d\n",x);break;
  // printf("円ちょうどですね。ありがとうございました。");break;
// }
 //printf("
 //1000円札%d枚でお支払ですね。お釣りは%d円になりますn", i,x);break;
 }
}
}


#include <stdio.h>
int main(){
  int n, ans=0;
  scanf("%d", &n);
  if(n%1000){ ans = 1000-(n%1000); }
  printf("%d", ans);
  return 0;
}


#include<stdio.h>
#include<string.h>

int main(void) {
	int N, i;
	char judge[100000][4];
	char* s1 = "AC", * s2 = "WA", * s3 = "TLE", * s4 = "RE";
	int a = 0, w = 0, t = 0, r = 0;

	scanf("%d", &N);

	for (i = 0; i < N; i++) {
		scanf("%s", judge[i]);
	}

	for (i = 0; i < N; i++) {
		if (strcmp(judge[i], s1) == 0) {
			a += 1;
		}
	}
	for (i = 0; i < N; i++) {
		if (strcmp(judge[i], s2) == 0) {
			w += 1;
		}
	}
	for (i = 0; i < N; i++) {
		if (strcmp(judge[i], s3) == 0) {
			t += 1;
		}
	}
	for (i = 0; i < N; i++) {
		if (strcmp(judge[i], s4) == 0) {
			r += 1;
		}
	}
	printf("AC x %d\n", a);
	printf("WA x %d\n", w);
	printf("TLE x %d\n", t);
	printf("RE x %d\n", r);

	return 0;
}


#include<stdio.h>
void main()
{
int n,r;
  scanf("%d",&n);
  r=n%1000;
   if(r==0)
   {
    printf("0");
   }
  else
  {
   r=1000-r;
    printf("%d",r);
  }
  return 0;
}


#include<stdio.h>

int main()
{
    int n, cng;
    scanf("%d", &n);
    if(n % 1000 == 0){
        cng = 0;
    }
    else{
        cng = 1000 - (n % 1000);
    }
    printf("%d", cng);

    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main()
{
    int n,a;
    scanf("%d",&n);
    a=n%1000;
    if(a==0)
        printf("0");
    else
        printf("%d",1000-a);
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
int main(){
    int N,x,y;
    scanf("%d",&N);
    x = N/1000;
    if(N%1000==0){
        y = 0;
        printf("%d",y);
    }
    else{
        y = (x+1)*1000 - N;
        printf("%d",y);
    }
    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main(void) {

  int input = 0;
  scanf("%d", &input);
  int change = input % 1000;
  if (change > 0) {
    change = 1000 - change;
    printf("%d\n", change);
  } else {
      printf("%d\n", change);
  }

  return 0;
}


#include<stdio.h>
int main()
{
    int x,y;
    scanf("%d",&x);
    if(x%1000==0)printf("0\n");
    else {
            printf("%d\n",1000-(x%1000));
    }
    return 0;

}


#include <stdio.h>

int main() {
    int N;
    scanf("%d", &N);

    while(N > 0) {
        N = N - 1000;
    }

    printf("%d\n", -N);
    return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define type 26

int constant(int day)//1~26 順番
{
  return day%type+1;
}
int get_random()//1~26 ランダム
{
  return rand()%type+1;
}
int max(int s[][type+1],int day)//その日の最大の満足度選ぶ
{
  int m,max_score=0,i;
  for(i=1;i<=type;i++)
  {
    if(s[day][i]>max_score){
      max_score=s[day][i];
      m=i;
    }
  }
  return m;
}
void cal(int select,int c[type+1],int last[type+1],int s[][type+1],int day,int sum[])
{
  int i;
  sum[day]=sum[day-1]+s[day][select];
  for(i=1;i<=type;i++){
    sum[day]-=c[i]*(day-last[i]);
  }
}
void change(int c[type+1],int last[type+1],int s[][type+1],int sum[],int schedul[],int D)
//ランダムに変更
{
  int d,t,old,total=0,i,j;
  d=rand()%D+1;
  t=rand()%type+1;
  old=schedul[d];
  schedul[d]=t;
  for(i=1;i<=type;i++) last[i]=0;
  for(i=1;i<=D;i++){
    total+=s[i][schedul[i]];
    last[schedul[i]]=i;
    for(j=1;j<=type;j++){
     total-=c[j]*(i-last[j]);
   }
  }
  if(total>sum[D]){
  //  printf("change\n");
    sum[D]=total;
  }
  else{
    schedul[d]=old;
  }
}
void cross(int c[type+1],int last[type+1],int s[][type+1],int sum[],int schedul[],int D)
//ランダムな２つ交換
{
  int a,b,old_a,old_b,flag=0,i,j,total=0;
  flag=rand()%2;
  a=rand()%D+1;
  if(flag==0){
    b=a+rand()%16+1;
    if(b>D) b=a-(rand()%16+1);
  }
  else{
    b=a-(rand()%16+1);
    if(b<1)   b=a+rand()%16+1;
  }
  old_a=schedul[a];
  old_b=schedul[b];
  schedul[a]=old_b;
  schedul[b]=old_a;
  for(i=1;i<=type;i++) last[i]=0;
  for(i=1;i<=D;i++){
    total+=s[i][schedul[i]];
    last[schedul[i]]=i;
    for(j=1;j<=type;j++){
     total-=c[j]*(i-last[j]);
   }
  }
  if(total>sum[D]){
    sum[D]=total;
  }
  else
  {
    schedul[a]=old_a;
    schedul[b]=old_b;
  }
}
int main(void)
{
  int D,c[type+1],i,j;
  clock_t start,stop;
  start=clock();
  srand((unsigned int)time(NULL));
  scanf("%d",&D);//D=365
  int s[D+1][type+1],last[type+1],sum[D+1],schedul[D+1];
  for(i=0;i<=D;i++) sum[i]=0;
  for(i=1;i<=type;i++) last[i]=0;
  for(i=1;i<=type;i++) scanf("%d",&c[i]);
  for(i=1;i<D+1;i++){
    for(j=1;j<=type;j++) scanf("%d",&s[i][j]);
  }
  for(i=1;i<D+1;i++){
    int select;
    select=max(s,i);
    last[select]=i;
    schedul[i]=select;
    cal(select,c,last,s,i,sum);
    //printf("%d\n",sum[i]);
  }
  int count=0;
  stop=start;
  while((double)(stop - start) / CLOCKS_PER_SEC<1.988){
    int flag=rand()%2;
    if(flag==0) cross(c,last,s,sum,schedul,D);
    else change(c,last,s,sum,schedul,D);
    count++;
    stop=clock();
  }
/*
  printf("count:%d\n",count);
  printf("time:%f\n",(double)(stop - start) / CLOCKS_PER_SEC);
  printf("%d\n",sum[D]);
  printf("確認\n");
  int total=0;
  for(i=1;i<=type;i++) last[i]=0;
  for(i=1;i<=D;i++){
    total+=s[i][schedul[i]];
    last[schedul[i]]=i;
    for(j=1;j<=type;j++){
     total-=c[j]*(i-last[j]);
   }
  }
  printf("%d\n",total);
*/
  for(i=1;i<=D;i++) printf("%d\n",schedul[i]);
  return 0;
}

Problem Statement

AtCoder currently hosts three types of contests: ABC, ARC, and AGC. As the number of users has grown, in order to meet the needs of more users, AtCoder has decided to increase the number of contests to 26 types, from AAC to AZC. For convenience, we number these 26 types as type 1 through type 26. AtCoder wants to schedule contests for D days so that user satisfaction is as high as possible. For every day, AtCoder will hold exactly one contest, and each contest will end on that day. The satisfaction is calculated as follows.

The satisfaction at the beginning of day 1 is 0. Satisfaction can be negative.

Holding contests increases satisfaction. The amount of increase will vary depending on a variety of factors. Specifically, we know in advance that holding a contest of type i on day d will increase the satisfaction by s_{d,i}.

If a particular type of contest is not held for a while, the satisfaction decreases. Each contest type i has an integer c_i, and at the end of each day d=1,2,...,D, the satisfaction decreases as follows. Let \mathrm{last}(d,i) be the last day before day d (including d) on which a contest of type i was held. If contests of type i have never been held yet, we define \mathrm{last}(d,i)=0. At the end of day d, the satisfaction decreases by \sum _{i=1}^{26}c_i \times (d-\mathrm{last}(d,i)).

Please schedule contests on behalf of AtCoder.
If the satisfaction at the end of day D is S, you will get a score of \max(10^6 + S, 0).
There are 50 test cases, and the score of a submission is the total scores for each test case.
You can make submissions multiple times, and the highest score among your submissions will be your score.

Constraints

D = 365

Each c_i is an integer satisfying 0\leq c_i \leq 100.

Each s_{d,i} is an integer satisfying 0\leq s_{d,i} \leq 20000.

Input

Input is given from Standard Input in the following format:

D
c_1 c_2 \cdots c_{26}
s_{1,1} s_{1,2} \cdots s_{1,26}
\vdots
s_{D,1} s_{D,2} \cdots s_{D,26}

Output

Let t_d (1\leq t_d \leq 26) be the type of the contest that will be held at day d.
Print D integers t_d to Standard Output in the following format:

t_1
t_2
\vdots
t_D

Any output that does not follow the above format may result in 0 pointsWA for that test case.

Input Generation

Each integer c_i and s_{d,i} is generated independently and uniformly at random from the integers in the range described in the problem statement.

Sample Input 1

5
86 90 69 51 2 96 71 47 88 34 45 46 89 34 31 38 97 84 41 80 14 4 50 83 7 82
19771 12979 18912 10432 10544 12928 13403 3047 10527 9740 8100 92 2856 14730 1396 15905 6534 4650 11469 3628 8433 2994 10899 16396 18355 11424
6674 17707 13855 16407 12232 2886 11908 1705 5000 1537 10440 10711 4917 10770 17272 15364 19277 18094 3929 3705 7169 6159 18683 15410 9092 4570
6878 4239 19925 1799 375 9563 3445 5658 19857 11401 6997 6498 19933 3848 2426 2146 19745 16880 17773 18359 3921 14172 16730 11157 5439 256
8633 15862 15303 10749 18499 7792 10317 5901 9395 11433 3514 3959 5202 19850 19469 9790 5653 784 18500 10552 17975 16615 7852 197 8471 7452
19855 17918 7990 10572 4333 438 9140 9104 12622 4985 12319 4028 19922 12132 16259 17476 2976 547 19195 19830 16285 4806 4471 9457 2864 2192

Sample Output 1

1
17
13
14
13

Note that this example is a small one for checking the problem specification. It does not satisfy the constraint D=365 and is never actually given as a test case. The final satisfaction with this output is 79325, so the score is 1079325.

Input generator, score calculator, and visualizer

Beginner's Guide

If you don't know what to do, proceed to problem B or C.


#include <stdio.h>
#include <limits.h>

#ifndef KOTAISUU
#define KOTAISUU 12
#endif
#ifndef SEDAISUU
#define SEDAISUU 17000
#endif
#ifndef KAKURITU
#define KAKURITU 30 /* * 0.01 % */
#endif

#ifndef NO_ENABLE_REVERSE
#define ENABLE_REVERSE
#endif

static unsigned int x=123456789;
static unsigned int y=362436069;
static unsigned int z=521288629;
static unsigned int w=88675123;

void seed(unsigned int a,unsigned int b,unsigned int c,unsigned int d) {
	if((a|b|c|d)==0)return;
	x=a;y=b;z=c;w=d;
}

unsigned int randint(void) {
	unsigned int t;
	t=(x^(x<<11));
	x=y;y=z;z=w;
	w=(w^(w>>19))^(t^(t>>8));
	return w;
}

unsigned int randint2(unsigned int max) {
	unsigned int amari = ((UINT_MAX % max) + 1) % max;
	unsigned int ret;
	do {
		ret = randint();
	} while (ret < amari);
	return ret % max;
}

#define KIND 26
#define MAX 365

struct horieyui {
	int mamegu[MAX];
};

int D;
int c[KIND];
int s[MAX][KIND];

int mizuhasu(const struct horieyui* kitaeri) {
	int sumipe = 0;
	int i, j;
	int last[KIND] = {0};
	for (i = 0; i < D; i++) {
		sumipe += s[i][kitaeri->mamegu[i]];
		last[kitaeri->mamegu[i]] = i + 1;
		for (j = 0; j < KIND; j++) {
			sumipe -= c[j] * ((i + 1) - last[j]);
		}
	}
	return sumipe;
}

int main(void) {
	int i, j;
	struct horieyui otehon;
	struct horieyui saikyou;
	int saikyou_score = 0;
	if (scanf("%d", &D) != 1) return 1;
	for (i = 0; i < KIND; i++) {
		if (scanf("%d", &c[i]) != 1) return 1;
	}
	for (i = 0; i < D; i++) {
		for (j = 0; j < KIND; j++) {
			if (scanf("%d", &s[i][j]) != 1) return 1;
		}
	}

	for (i = 0; i < KIND; i++) {
		int score;
		for (j = 0; j < D; j++) otehon.mamegu[j] = (i + j) % KIND;
		score = mizuhasu(&otehon);
		if (i == 0 || score > saikyou_score) {
			saikyou = otehon;
			saikyou_score = score;
		}
	}
#ifdef ENABLE_REVERSE
	for (i = 0; i < KIND; i++) {
		int score;
		for (j = 0; j < D; j++) otehon.mamegu[j] = (i - (j % KIND) + KIND) % KIND;
		score = mizuhasu(&otehon);
		if (score > saikyou_score) {
			saikyou = otehon;
			saikyou_score = score;
		}
	}
#endif
	otehon = saikyou;

	for (i = 0; i < SEDAISUU; i++) {
		struct horieyui saituyo;
		int saituyo_score = 0;
		for (j = 0; j < KOTAISUU; j++) {
			struct horieyui kore = otehon;
			int k;
			int score;
			for(k = 0; k < D; k++) {
				if (randint2(10000) < KAKURITU) {
					kore.mamegu[k] = randint2(KIND - 1);
					if (kore.mamegu[k] >= otehon.mamegu[k]) kore.mamegu[k]++;
				}
			}
			score = mizuhasu(&kore);
			if (j == 0 || score > saituyo_score) {
				saituyo = kore;
				saituyo_score = score;
			}
		}
#ifdef NO_FORCE_UPDATE
		if (saituyo_score > saikyou_score)
#endif
		otehon = saituyo;
		if (saituyo_score > saikyou_score) {
#ifdef PRINT_UPDATE
			fprintf(stderr, "update at generation %d : %d -> %d\n", i + 1, saikyou_score, saituyo_score);
#endif
			saikyou = saituyo;
			saikyou_score = saituyo_score;
		}
	}
	for (i = 0; i < D; i++) {
		printf("%d\n", saikyou.mamegu[i] + 1);
	}
#ifdef PRINT_SCORE
	printf("score = %d\n", saikyou_score < -1000000 ? 0 : 1000000 + saikyou_score);
#endif
	return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>

int main(){
  srand((unsigned int)time(NULL));
  int D,M=365*500;
  int c[30];
  int s[370][30];
  int t[370];
  int last[30];
  int ans_max=0,ans=0;
  int old_t,old_d;

  scanf("%d",&D);
  for(int i=1;i<=26;i++)
    scanf("%d",c+i);
  for(int i=1;i<=D;i++)
   for(int j=1;j<=26;j++)
     scanf("%d",&s[i][j]);

  for(int i=1;i<=D;i++)
    t[i]=rand()%26+1;

  ans_max=0;
  for(int k=1;k<=26;k++)
    last[k]=0;
  for(int d=1;d<=D;d++){
    ans_max+=s[d][t[d]];
    last[t[d]]=d;
    for(int j=1;j<=26;j++){
      ans_max-=c[j]*(d-last[j]);
    }
  }

  for(int i=1;i<=M;i++){
    ans=0;
    old_d=i%D+1;
    old_t=t[old_d];
    t[old_d]=rand()%26+1;
    for(int k=1;k<=26;k++)
      last[k]=0;
    for(int d=1;d<=D;d++){
      ans+=s[d][t[d]];
      last[t[d]]=d;
      for(int j=1;j<=26;j++){
        ans-=c[j]*(d-last[j]);
      }
    }
    if(ans<ans_max){
      t[old_d]=old_t;
    }else{
      ans_max=ans;
    }
  }
  printf("ans_max:%d\n",ans_max);
  for(int i=1;i<=D;i++)
    printf("%d\n",t[i]);
  return 0;
}


Score : 300 points

Problem Statement

We have two desks: A and B. Desk A has a vertical stack of N books on it, and Desk B similarly has M books on it.

It takes us A_i minutes to read the i-th book from the top on Desk A (1 \leq i \leq N), and B_i minutes to read the i-th book from the top on Desk B (1 \leq i \leq M).

Consider the following action:

Choose a desk with a book remaining, read the topmost book on that desk, and remove it from the desk.

How many books can we read at most by repeating this action so that it takes us at most K minutes in total? We ignore the time it takes to do anything other than reading.

Constraints

1 \leq N, M \leq 200000

1 \leq K \leq 10^9

1 \leq A_i, B_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M K
A_1 A_2 \ldots A_N
B_1 B_2 \ldots B_M

Output

Print an integer representing the maximum number of books that can be read.

Sample Input 1

3 4 240
60 90 120
80 150 80 150

Sample Output 1

3

In this case, it takes us 60, 90, 120 minutes to read the 1-st, 2-nd, 3-rd books from the top on Desk A, and 80, 150, 80, 150 minutes to read the 1-st, 2-nd, 3-rd, 4-th books from the top on Desk B, respectively.

We can read three books in 230 minutes, as shown below, and this is the maximum number of books we can read within 240 minutes.

Read the topmost book on Desk A in 60 minutes, and remove that book from the desk.

Read the topmost book on Desk B in 80 minutes, and remove that book from the desk.

Read the topmost book on Desk A in 90 minutes, and remove that book from the desk.

Sample Input 2

3 4 730
60 90 120
80 150 80 150

Sample Output 2

7

Sample Input 3

5 4 1
1000000000 1000000000 1000000000 1000000000 1000000000
1000000000 1000000000 1000000000 1000000000

Sample Output 3

0

Watch out for integer overflows.


#include <stdio.h>

int max(int a, int b) {
    if (a > b)
        return a;
    return b;
}

int bs(long long *arr, int n, long long val) {
    int l = 0, r = n-1, mid;

    while (r - l > 1) {
        mid = (r + l) >> 1;

        if (arr[mid] > val)
            r = mid;
        else
            l = mid;
    }
    if (arr[r] <= val)
        return r;
    if (arr[mid] <= val)
        return mid;
    if (arr[l] <= val)
        return l;
    return -1;
}

int main() {
    int n, m;
    long long k;
    long long aprefix[200000+7];
    long long bprefix[200000+7];

    scanf("%d %d %lld", &n, &m, &k);

    long long prev = 0, temp;
    for (int i=0; i < n; i++) {
        scanf("%lld", &temp);
        aprefix[i] = prev + temp;
        prev = aprefix[i];
    }
    prev = 0;
    for (int i=0; i < m; i++) {
        scanf("%lld", &temp);
        bprefix[i] = prev + temp;
        prev = bprefix[i];
    }
    int ans = 0;
    temp = bs(bprefix, m, k);
    if (temp != -1)
        ans = temp + 1;
    temp = bs(aprefix, n, k);
    if (temp != -1)
        ans = max(ans, temp + 1);

    for (int a=0; a < n; a++) {
        long long rem = k - aprefix[a];
        if (rem < 0)
            break;
        int b = bs(bprefix, m, rem);
        if (b != -1)
            ans = max(ans, a + 1 + b + 1);
    }

    printf("%d\n", ans);

    return 0;
}


#include<stdio.h>
int main()
{
      long long int n,m,k;
      scanf("%lld%lld%lld",&n,&m,&k);
      long long int a[n],b[m],i,d[3]={0},x=0;
      for(i=0;i<n;i++){
            scanf("%lld",&a[i]);
      }
      for(i=0;i<m;i++){
            scanf("%lld",&b[i]);
      }
      for(i=0;i<n;i++){
            x+=a[i];
            if(x<=k) d[0]++;
            else break;
      }
      if(x<k){
            for(i=0;i<m;i++){
                  x+=b[i];
                  if(x<=k) d[0]++;
                  else break;
            }
      }
      x=0;
      for(i=0;i<m;i++){
            x+=b[i];
          ///  printf("%lld ",x);
            if(x<=k) d[1]++;
            else break;
      }
      ///printf("\n");
      if(x<k){
            for(i=0;i<n;i++){
                  x+=a[i];
                  ///printf("%lld ",x);
                  if(x<=k) d[1]++;
                  else break;
            }
      }
      ///printf("\n");
      long long int sum=0;
      long long int  j,c;
      for(i=0,j=0,c=1;c<=(n+m);c++){
            if(j==m){
                  if(k>=a[i]) k=k-a[i];
                  else break;
                  i++;
                  sum++;
            }
            else if(i==n){
                  if(k>=b[j]) k=k-b[j];
                  else break;
                  j++;
                  sum++;
            }
            else if(a[i]<b[j]){
                  if(k>=a[i]) k=k-a[i];
                  else break;
                  i++;
                  sum++;
            }
            else if(a[i]==b[j]){
                  if(a[i+1]<b[j+1]){
                        if(k>=a[i]) k=k-a[i];
                        else break;
                        i++;
                        sum++;
                  }
                  else{
                        if(k>=b[j]) k=k-b[j];
                        else break;
                        j++;
                        sum++;
                  }
            }
            else{
                  if(k>=b[j]) k=k-b[j];
                  else break;
                  j++;
                  sum++;
            }
            ///printf("%d %d %d %d\n",i,j,sum,k);
      }
      d[2]=sum;
      long long int min=d[0];
     /* for(i=0;i<3;i++){
            printf("%lld ",d[i]);
      }
      printf("\n");*/
      for(i=1;i<3;i++){
            if(d[i]>min) min=d[i];
      }

      printf("%lld\n",min);

      return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main(void)
{
    int n;
    int m;
    int k;
    scanf("%d", &n);
    scanf("%d", &m);
    scanf("%d", &k);

    long long int *a;
    long long int *b;
    long long int temp;
    int i;
    a = (long long int *)malloc(sizeof(long long int) * n + 1);
    a[0] = 0;
    for (i = 1; i < n + 1; i++)
    {
        scanf("%lld", &temp);
        a[i] = a[i - 1] + temp;
    }
    b = (long long int *)malloc(sizeof(long long int) * m + 1);
    b[0] = 0;
    for (i = 1; i < m + 1; i++)
    {
        scanf("%lld", &temp);
        b[i] = b[i - 1] + temp;
    }

    int answer = 0;
    int j = m;
    for (i = 0; i < n + 1; i++)
    {
        if (a[i] > k)
        {
            break;
        }
        while (b[j] > k - a[i])
        {
            j -= 1;
        }
        answer = answer > (i + j) ? answer : (i + j);
    }

    printf("%d\n", answer);

    free(a);
    free(b);
    return 0;
}


#include <stdio.h>
int main(void) {
	int n,m,k = 0;
	int a = 0;
	int b = 0;
	unsigned long aSum[200010];
	unsigned long bSum[200010];
	int ai,bi = 0;
	int count = 0;

	//For binary search
	int mid = 0;
	int left = 0;
	int right = 0;

	aSum[0] = 0;
	bSum[0] = 0;

	scanf("%d%d%d",&n,&m,&k);
	for(ai=1;ai<n+1;ai++){
		scanf("%d",&a);
		aSum[ai] = aSum[ai-1] + a;
		//printf("aSum = %d\n",aSum[ai]);
		}
	for(bi=1;bi<m+1;bi++){
		scanf("%d",&b);
		bSum[bi] = bSum[bi-1] + b;
	}

	for(ai=1;ai<n+1;ai++){
		left = 1;
		right = m;
		//binary search
		while(left <= right){
			mid = (left + right)/2;
			if((aSum[ai]+bSum[mid]) <= k){
				left = mid + 1;
				//読んだ冊数を更新
				if(count < (ai + mid)){
					count = ai + mid;
				}
			}else{
				right = mid - 1;
			}
		}
	}

	printf("%d",count);
	return 0;
}


#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>

//using ll = long long int;
#define PI 3.141592653589793
//141167095653376;

int main(void) {

	int n, m;
	long long int k;
	long long int aa , bb;
	long long int a[20010], b[20010];
	int i;
	int x;
	int sum = 0;
	int cnt = 0;
	int max = 0;
	int j;
	a[0] = 0;
	b[0] = 0;
	scanf("%d%d%d", &n, &m, &k);
	for (i = 1; i <= n; i++)
	{
		scanf("%d", &aa);
		a[i] = a[i - 1] + aa;
	}
	for (i = 1; i <= m; i++)
	{
		scanf("%d", &bb);
		b[i] = b[i - 1] + bb;
	}
	j = m;
	for (i = 0; i <= n; i++)
	{
		if (a[i] > k)
			break;
		while (b[j] > k - a[i])
			j -= 1;
		//printf("%lld>%d - %lld\n", b[j], k, a[i]);
		if (max < i + j)
		{
			max = i + j;
			//printf("%d %d\n", i, j);
		}
	}
	printf("%d\n", max);
	return 0;
}


#include<stdio.h>
int main() {
	int n, m, k;
	int a[200001] = { 0 }, b[200001] = { 0 };

	scanf("%d%d%d", &n, &m, &k);

	for (int i = 0; i < n; i++) {
		int tmp;
		scanf("%d", &tmp);
		a[i + 1] = tmp + a[i];
	}
	for (int i = 0; i < m; i++) {
		int tmp;
		scanf("%d", &tmp);
		b[i + 1] = tmp + b[i];
	}

	int result = 0;
	int tmp = 0;
	for (int i = 0; i <= n; i++) {
		while (a[i] + b[m - tmp] > k) {
			tmp++;
		}
		result = (i + m - tmp) > result ? (i + m - tmp) : result;
	}

	printf("%d", result);
	return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>

typedef long long ll;

int max(int a, int b){
  if(a > b) return a;
  else return b;
}
int min(int a, int b){
  if(a < b) return a;
  else return b;
}

int sort(const void *a ,const void *b){
  return *(int*)a - *(int*)b;
}

int main(){

  int n,m;
  int k;
  ll a[200001],b[200001];

  scanf("%d%d%lld",&n,&m,&k);
  for(int i = 0; i < n; ++i){
    scanf("%d",a+i);
  }
  for(int i = 0; i < m; ++i){
    scanf("%d",b+i);
  }

  a[n] = 111111111111;
  b[m] = 111111111111;

  int a_count = 0;
  int b_count = 0;
  int book = 0;
  ll sum = 0;
  while(sum <= k){
    if(a_count == n && b_count == m) break;
    if(a[a_count] < b[b_count]){
      sum += a[a_count];
      a_count ++;
      book ++;
    }else{
      sum += b[b_count];
      b_count ++;
      book ++;
    }
  }

  printf("%d",book);

  return 0;
}


#include <stdio.h>

int main() {
  long int n, m, k;
  long int i, a[200000], b[200000], cnt, ans;
  scanf("%ld %ld %ld", &n, &m, &k);

  for (i = 0; i < n; i++) {
    scanf("%ld", &a[i]);
//  	printf("%ld\n", a[i]);
  }

  for (i = 0; i < m; i++) {
    scanf("%ld", &b[i]);
//  	printf("%ld\n", b[i]);
  }

  cnt = 0;
  ans = 0;
  for (i = 0; cnt < k; i++) {
    cnt += a[i];
//    printf("%ld\n", cnt);
    if (cnt > k)
      break;
    else {
      ans++;
      cnt += b[i];
      ans++;
    }
  }

  if (i <= 1)
    printf("0");
  else
    printf("%ld", ans - 1);
  return (0);
}


#include<stdio.h>

int max1(int a, int b) {
	if (a > b)
		return a;
	else
		return b;
}
int main(void)
{
	int i,j, ans = 0;
	long long int te=0,sum = 0;
	long long int  n, k, m;
	int A[200001], B[200001];

	scanf("%lld %lld %lld", &n, &m, &k);
	A[0] = 0;B[0] = 0;
	for (i = 1;i <= n;i++)
		scanf("%d", &A[i]);
	for (i = 1;i <= m;i++)
		scanf("%d", &B[i]);

	for (i = 0;i <=n;i++) {
		te += A[i];
		sum = te;
		if (sum > k)
			break;
		for (j = 0;j <= m;j++) {
			sum += B[j];
			if (sum <= k)
				ans = max1(ans, i + j);
			else
				break;
		}
	}

	printf("%d", ans);

	return 0;
}


#include <stdio.h>
#include <string.h>

int main(){
  long n,m,k,i,hon_a,hon_b,time=0,result=0;
  long a[200001],b[200001];

  scanf("%ld %ld %ld",&n,&m,&k);
  for(i=0;i<n;i++){
    scanf("%ld",&a[i]);
  }
  a[i]=1000000001;
  for(i=0;i<m;i++){
    scanf("%ld",&b[i]);
  }
  b[i]=1000000001;

  hon_a=hon_b=0;
  for(i=0;i<(m+n);i++){
    if(time+a[hon_a]>k && time+b[hon_b]>k){
      break;
    } else {
      if(a[hon_a]<=b[hon_b]){
        time+=a[hon_a];
        result++;
        hon_a++;
      } else {
        time+=b[hon_b];
        result++;
        hon_b++;
      }
    }
  }

  printf("%ld",result);
}


#include<stdio.h>

int main(){
    int n,m,i,a[200001],b[200001],acount=0,bcount=0,count=0,over=0;
    long int k;

    scanf("%d %d %ld",&n,&m,&k);

    for(i=0;i<n;i++){
        scanf("%d",&a[i]);

    }
    for(i=0;i<m;i++){
        scanf("%d",&b[i]);

    }
    a[n]=1000000000;
    b[m]=1000000000;

    while(k>=a[acount]||k>=b[bcount]){

        if(acount+1==n&&bcount+1==m)
            break;

        count++;
    if(a[acount]<=b[bcount]){
        k=k-a[acount];
        acount++;

    }else{
        k=k-b[bcount];
        bcount++;
    }

    printf("%d %d %ld\n",acount,bcount,k);
    printf("%d\n",count);

    }
    printf("%d",count);

    return 0;
}


#include<stdio.h>

int main(void){
    int N,M,K,n=0,time=0;
    scanf("%d %d %d", &N, &M, &K);

    int A[N],B[M];
    for(int i=0;i<N;i++){
        scanf("%d", &A[i]);
    }
    for(int j=0;j<M;j++){
        scanf("%d", &B[j]);
    }

    int a=0;
    int b=0;
    for(;;){
        if(A[a]-B[b]>0){
            if(time + B[b]> K){
                break;
            }
            time += B[b];
            b++;
            n++;
        }
        else{
            if(time + A[a]> K){
                break;
            }
            time += A[a];
            a++;
            n++;
        }

        if(a==N){
            if(b==M)
                break;
            for(;;){
                if(b==M)
                    break;
                if(time + B[b]> K){
                    break;
                }
                time += B[b];
                b++;
                n++;
            }

        }
        else if(b==M){
            if(a==N)
                break;
                for(;;){
                    if(a==N)
                        break;
                    if(time + A[a]> K){
                       break;
                    }
                    time += A[a];
                    a++;
                    n++;
                }
        }

    }

    printf("%d", n);
}


#include <stdio.h>

int main(void){

    long long int n,m,k;
    unsigned long int a[200010]={0},b[2000010]={0};
    unsigned long int ans=0;
    unsigned long int cnta=0,cntb=0;
    scanf("%ld %ld %ld",&n,&m,&k);
    for(unsigned long int i = 0;i<n;i++)scanf("%ld",&a[i]);
    for(unsigned long int i = 0;i<m;i++)scanf("%ld",&b[i]);

    a[n] = k+1;
    b[m] = k+1;
    while(1){
        if(a[cnta] <= k || b[cntb] <= k){
            ans ++;
            if(a[cnta] < b[cntb]){
                k -= a[cnta];
                cnta ++;
            }else{
                k -= b[cntb];
                cntb ++;
            }
        }else break;
    }

    printf("%ld",ans);

    return 0;
}


#include <stdio.h>

int main(void){
    // Your code here!
long long int a[200001];
long long int b[200001];
int n,m,k;

    scanf("%d %d %d",&n,&m,&k);
    for(int i=0;i<n;i++){
        scanf("%lld",&a[i]);
        if(i!=0){
            a[i]+=a[i-1];
        }
    }
     for(int i=0;i<m;i++){
        scanf("%lld",&b[i]);
         if(i!=0){
            b[i]+=b[i-1];
        }
    }
    int max=0;

for(int i=0;i<n;i++){
    if(a[i]>k){break;}
    for(int j=0;j<m;j++){
        if(a[i]+b[j]>k){break;}
        if(a[i]+b[j]<=k){
            if(i+j+2>max){
            max=i+j+2;
            }
        }
    }
}

    /*
    for(int i=0;i<n;i++){
        printf("%lld ",a[i]);
    }
     for(int i=0;i<m;i++){
        printf("%lld ",b[i]);
    }*/

   printf("%d",max);
}


#include<stdio.h>
int r=1e10;
int main()
{
  int N,M,K;
  int a[r],b[r],i;
  int sum=0;
  int count=0;
  scanf("%d %d %d",&N,&M,&K);
  for(i=0;i<N;i++)
  {
    scanf("%d",&a[i]);
  }
  for(i=0;i<M;i++)
  {
    scanf("%d",&b[i]);
  }
  for(i=0;(i<N)||(i<M);i++)
  {
   if(a[i]<K)
   {
     if((sum+a[i])<K)
     {
     sum=sum+a[i];
       count++;
     }
   }
     if(b[i]<K)
   {
     if((sum+b[i])<K)
     {
     sum=sum+b[i];
       count++;
     }
   }
  }
  printf("%d",count);
  return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define ll long long

ll n,m,k;
ll a[212345],b[212345];

int main(){
  scanf("%lld%lld%lld",&n,&m,&k);

  a[0]=0;
  b[0]=0;
  for(ll i=1;i<=n;i++){
    scanf("%lld",&a[i]);
    a[i] = a[i]+a[i-1];}
  for(ll i=1;i<=m;i++){
    scanf("%lld",&b[i]);
    b[i] = b[i]+b[i-1];}

  ll ans=0;
  ll indb=m;
  for(ll i=1;i<=n;i++){
    if(a[i]>k){
      while(b[indb]>k && indb>0){
	indb--;}
      if(indb>ans) ans=indb;
      break;}
    while(a[i]+b[indb]>k && indb>0){
      indb--;}
    if(i+indb>ans) ans=i+indb;
  }

  printf("%lld\n",ans);

  return 0;
}


#include <stdio.h>
#include <string.h>

int main() {
  int n,m;
  long long k;
  scanf("%d %d %lld", &n, &m, &k);
  long long a[n], b[m];
  for(int i=0;i<n;i++){
    scanf("%lld", &a[i]);
  }
  for(int i=0;i<m;i++){
    scanf("%lld", &b[i]);
  }

  int i=0,j=0,c=0;
  for(;;){
    if(k<0 || (i==n&&j==m)){
      if(k<0){
        c--;
      }
      break;
    }

    if(i==n || j==m){
      if(j<m){
        k-=b[j];
        j++;
        c++;
      }else if(i<n){
        k-=a[i];
        i++;
        c++;
      }
    }
    else if(a[i]>=b[j]){
      k-=b[j];
      j++;
      c++;
    }
    else{
      k-=a[i];
      i++;
      c++;
    }

  }
  printf("%d", c);
  return 0;
}


#include<stdio.h>
#include<stdlib.h>

long int g(long int x);

int main(void)
{
  long int n;
  scanf("%ld", &n);

  long int ans=0;
  long int x;
  for(int i=1;i<=n;i++){
    x = n/i;
    ans += i*g(x);
  }

  printf("%ld\n", ans);

  return 0;
}

long int g(long int x)
{
  return x*(x+1)/2;
}

Score : 400 points

Problem Statement

For a positive integer X, let f(X) be the number of positive divisors of X.

Given a positive integer N, find \sum_{K=1}^N K\times f(K).

Constraints

1 \leq N \leq 10^7

Input

Input is given from Standard Input in the following format:

N

Output

Print the value \sum_{K=1}^N K\times f(K).

Sample Input 1

4

Sample Output 1

23

We have f(1)=1, f(2)=2, f(3)=2, and f(4)=3, so the answer is 1\times 1 + 2\times 2 + 3\times 2 + 4\times 3 =23.

Sample Input 2

100

Sample Output 2

26879

Sample Input 3

10000000

Sample Output 3

838627288460105

Watch out for overflows.


#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部定数
#define D_VAL_MAX		10000005								// 最大値

// 内部変数
static FILE *szpFpI;											// 入力
static int si1DCnt[D_VAL_MAX];									// 約数数

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpA;
	static int siTNo;
#endif

// １行出力
int
fOutLine(
	char *pcpLine				// <I> １行
)
{
	char lc1Buf[1024];

#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, pcpLine)) {
		siRes = -1;
	}
#else
	printf("%s", pcpLine);
#endif

	return 0;
}

// 実行メイン
int
fMain(
)
{
	int i, j;
	char lc1Buf[1024];

	// データ - 初期化
	memset(si1DCnt, 0, sizeof(si1DCnt));

	// N - 取得
	int liN;
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
	sscanf(lc1Buf, "%d", &liN);

	// 約数数 - セット
	for (i = 1; i <= liN; i++) {
		for (j = i; j <= liN; j += i) {
			si1DCnt[j]++;
		}
	}
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);

	// 合計 - 取得
	long long llSum = 0;
	for (i = 1; i <= liN; i++) {
		llSum += (long long)i * (long long)si1DCnt[i];
	}

	// 出力
	sprintf(lc1Buf, "%lld\n", llSum);
	fOutLine(lc1Buf);

	return 0;
}

// １回実行
int
fOne(
)
{
	int liRet;
	char lc1Buf[1024];

	// 入力 - セット
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", siTNo);
	szpFpI = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", siTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#else
	szpFpI = stdin;
#endif

	// 実行メイン
	liRet = fMain();

	// 残データ有無
#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, "")) {
		siRes = -1;
	}
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpI);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", siTNo);
	}
	else {
		printf("NG %d\n", siTNo);
	}
#endif

	return 0;
}

// プログラム開始
int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		siTNo = i;
		fOne();
	}
#else
	fOne();
#endif

	return 0;
}


#include <math.h>
#include <stdio.h>
int n, sqrtN;
long long ans, d;
char buf[8],out[20];
char k;
s;
size_t i;
int main() {
    s = read(0, buf, 8);
    for(;;) {
        k = buf[i++];
        if(k < '0') break;
        n = n * 10 + k - '0';
    }
    if(n == 1) {
        putchar(49);
    } else {
        const int sqrtN = sqrt(n);
        ans = -(long long)(sqrtN) * (sqrtN + 1) * (2 * sqrtN + 1) / 6;
        for(int i = 1; i <= sqrtN; ++i) {
            const int a = n / i;
            ans += ((long long)i * (i + a) * (a + 1 - i));
        }
        i = 20;
        do{
            out[--i]=ans%10+'0';
            ans/=10;
        }while(ans);
        write(1,out+i,20-i);
    }
}


#include <stdio.h>
#include <math.h>
// using namespace std;
int N;
int i = 2;
long long num;
char buf[8], out[20];
char k;
s;
size_t ii;
int main()
{
  s = read(0, buf, 8);
  for (;;)

  {
    k = buf[ii++];
    if (k < '0')
      break;
    N = N * 10 + k - '0';
  }
  // printf("%d\n", N);
  long long ans = (long long)N * (N + 1) - 1;

  for (; i * i <= N; i++)
  {
    num = N / i;
    // ans += (long long)(num - i + 1) * i * (i + num) - i * i;
    ans += (num * num - i * i + num) * i;
  }
  printf("%lld\n", ans);
}


#include <stdio.h>
#include <math.h>
// using namespace std;
int N;
int i = 2;
int num;
char buf[8], out[20];
char k;
s;
size_t ii;
int main()
{
  s = read(0, buf, 8);
  for (;;)

  {
    k = buf[ii++];
    if (k < '0')
      break;
    N = N * 10 + k - '0';
  }
  // printf("%d\n", N);
  long long ans = (long long)N * (N + 1) - 1;

  for (; i * i <= N; i++)
  {
    num = N / i;
    ans += (long long)(num - i + 1) * i * (i + num) - i * i;
  }
  printf("%lld\n", ans);
}


#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

//gcdやり直す

void swap (int *x, int *y) {
  int temp;

  temp = *x;
  *x = *y;
  *y = temp;
}

/***
* pivotを決め、
* 全データをpivotを境目に振り分け、
* pivotの添え字を返す
***/
int partition (int array[], int left, int right) {
  int i, j, pivot;
  i = left;
  j = right + 1;
  pivot = left;   // 先頭要素をpivotとする

  do {
    do { i++; } while (array[i] < array[pivot]);
    do { j--; } while (array[pivot] < array[j]);
    // pivotより小さいものを左へ、大きいものを右へ
    if (i < j) { swap(&array[i], &array[j]); }
  } while (i < j);

  swap(&array[pivot], &array[j]);   //pivotを更新

  return j;
}

/* クイックソート */
void quick_sort (int array[], int left, int right) {
  int pivot;

  if (left < right) {
    pivot = partition(array, left, right);
    quick_sort(array, left, pivot-1);   // pivotを境に再帰的にクイックソート
    quick_sort(array, pivot+1, right);
  }
}

/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  |
\****************************************/

int main(void){
  long int n;
  scanf("%ld",&n);
  long int ans=0;
  for(int i=1;i<=n;i++){
    long int now=n/i;
    ans+=now*(now+1)/2*i;
  }

  printf("%ld\n",ans);
  return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>

long long cnt_divisors(long long num){
  long long cnt = 0;
  for(long long i = 1; i*i <= num ; i++){
    if(num%i==0){
      cnt += 2;
    }
    if(i*i==num){
      cnt --;
    }
  }
  return cnt;
}

int main(void){
  long long n;
  long long sum = 0;
  scanf("%lld",&n);
  for(long long k = 1; k <= n ; k++ ){
    sum += k*cnt_divisors(k);
  }
  printf("%lld",sum);
  return 0;
}


#include <stdio.h>
#include <string.h>

long go(int);

int main(){
    long i, j, total=0;
    scanf("%ld",&i);
    for(j=0;j<i;j++){
        total += (j+1)*go(j+1);
    }
    printf("%ld",total);
    return 0;
}

long go(int n){
    int i, s=0;
    for(i=1;i<=n;i++){
        if(n % i==0){
            s++;
        }
    }
    return s;
}


#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<stdbool.h>
#include<assert.h>
#include<ctype.h>
typedef long long ll;
typedef long double ld;
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define rrep(i,l,r)for(ll i=(l);i>=(r);i--)
#define INF (1LL<<60)
#define MOD1 1000000007
#define MOD2 998244353
#define MAX_N (1 << 20)
#define YES printf("Yes\n")
#define NO printf("No\n")
#define PN printf("\n")
#define charsize 100005 //10^5+5
#define PI 3.141592653589793238

void swap(ll *a, ll *b){ll c;c=*b;*b=*a;*a= c;}
void cin(ll *n){ scanf("%lld",&(*n)); }
ll max2(ll a,ll b){return a>=b?a:b;}
ll min2(ll a,ll b){return a>=b?b:a;}
ll min3(ll a, ll b, ll c){return (a<=b && a<=c) ? a : b<=c ? b : c;}
ll max3(ll a, ll b, ll c){return (a>=b && a>=c) ? a : b>=c ? b : c;}
ll minn(ll n, ll a[]){ll b=INF;rep(i,0,n) b=min2(b,a[i]);return b;}
ll maxn(ll n, ll a[]){ll b=-INF;rep(i,0,n) b=max2(b,a[i]);return b;}
ll POW(ll a, ll b){ll c=1;rep(i,0,b) c*=a;return c;}
double POW_d(double a, double b){double c=1;rep(i,0,b) c*=a;return c;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll mod_MOD1(ll n){n+= n<0?((-n)/MOD1+1)*MOD1:0; return n%=MOD1;}
ll mod_p(ll n ,ll p){n+= n<0?((-n)/p+1)*p:0; return n%=p;}
ll change_into_num(char s[] , ll len, ll p){ return !p ? 0 : POW(10,p-1)*(s[len-p]-'0') + change_into_num(s,len,p-1); }
ll digits(ll a, ll b){return a/b?1+digits(a/b,b):1;}
ll base(ll n, ll a, ll i){return i==1?n%a:base(n/a,a,i-1);}

void lr_lower( int *l, int *r, ll am, ll val , int type ){ (type<3) ? ( am < val ?  ( *l = (*l+*r)/2 ) : ( *r= (*l+*r)/2 ) ) : ( am <= val ? ( *l = (*l+*r)/2 ) : ( *r= (*l+*r)/2 ) ); }
void lr_upper( int *l, int *r, ll am, ll val , int type ){ (type<3) ? ( am <= val ?  ( *l = (*l+*r)/2 ) : ( *r= (*l+*r)/2 ) ) : ( am < val ? ( *l = (*l+*r)/2 ) : ( *r= (*l+*r)/2 ) ); }
int cmp_lower( ll a, ll b, int type ){ return (type==1) ? ( a==b ? 1 : 0 ) : (type==2) ? ( a>=b ? 1 : 0 ) : ( a>b ? 1 : 0 ) ; }
int cmp_upper( ll a, ll b, int type ){ return (type==1) ? ( a==b ? 1 : 0 ) : (type==2) ? ( a<=b ? 1 : 0 ) : ( a<b ? 1 : 0 ) ; }
// return smallest p  which meets  a[p]==val :1  >=:2   >:3
ll lower_bound( ll a[], int l, int r, ll val , int type ){  while(r-l>1) lr_lower(&l,&r,a[ (l+r)/2 ],val,type);  return cmp_lower(a[l],val,type) ? l : cmp_lower(a[r],val,type) ? r : -1;  }
// return biggest p  which meets   a[p]==val :1  <=:2   <:3
ll upper_bound( ll a[], int l, int r, ll val , int type ){  while(r-l>1) lr_upper(&l,&r,a[ (l+r)/2 ],val,type); return cmp_upper(a[r],val,type) ? r : cmp_upper(a[l],val,type) ? l : -1; }
// count i  which meets ai==x
ll count(ll a[], int l, int r, ll x){  int p = lower_bound(a,l,r,x,1);  return p==-1 ? 0 : upper_bound(a,p,r,x,1)-p+1; }

ll *factors[2] , fac_cnt=0 , is_factor_prepared=0;
ll factor_pre(){  rep(i,0,1){ if(is_factor_prepared++) return 0; }  ll tmp=(1e5)/2+1, fac_tmp[tmp];  rep(i,0,tmp){fac_tmp[i]=i?2*i+1:2;}  rep(i,1,tmp){if(fac_tmp[i]){  repp(j,3,tmp/(2*i+1)+1,2 ){  if( j*(2*i+1)<tmp ) fac_tmp[ (j*(2*i+1)-1)/2 ]=0;  }  }else continue;}  rep(i,0,tmp){if(fac_tmp[i]){  rep(j,0,2){ factors[j] = realloc( factors[j] , sizeof(ll)*( fac_cnt +1 ) );  factors[j][j?fac_cnt++:fac_cnt]=j?0:fac_tmp[i];  }  } }  return 0;  }
ll factor(ll n, ll new_common_plus){ factor_pre();  rep(i,0,fac_cnt){ ll cnt=0; rep(j,0,1){ while( ( cnt+= n %factors[0][i]==0 ? 1 : 0 )  && (n/=factors[0][i]) %factors[0][i]==0 ) continue; } factors[1][i]= new_common_plus==1 ? cnt :  new_common_plus==2 ? max2(factors[1][i],cnt) : factors[1][i]+cnt ;  if( factors[0][i]> n ) break; } return n; }
ll judge_prime(ll n){ factor_pre(); rep(i,0,fac_cnt){ if(n<factors[0][i]*factors[0][i] || n==factors[0][i]) break; else if(n%factors[0][i]==0) n/=n; }  return n==1?0:1; }

ll *mf_arr,*inv_arr,*finv_arr,is_minv_made=0,is_mf_made=0;
ll makeinv(ll n , ll mod){  rep(i,0,1){if(is_minv_made++) return 0;}  inv_arr = realloc(inv_arr, sizeof(ll)*2 );  finv_arr = realloc(finv_arr, sizeof(ll)*2 );  inv_arr[1]=1;finv_arr[0]=finv_arr[1]=1;  rep(i,2,n+1){  inv_arr = realloc(inv_arr, sizeof(ll)*(i+1) );  finv_arr = realloc(finv_arr, sizeof(ll)*(i+1) );  inv_arr[i]= mod - inv_arr[mod%i] * (mod / i) % mod;  finv_arr[i] = finv_arr[i - 1] * inv_arr[i] % mod;  }  return 0; }
ll make_mf(ll n, ll mod){  rep(i,0,1){ if(is_mf_made++) return 0; }  mf_arr = realloc(mf_arr, sizeof(ll)*2 );  ll x=1;  mf_arr[0]=mf_arr[1]=x;  rep(i,2,n+1){   x=x*i%mod;  mf_arr = realloc(mf_arr, sizeof(ll)*(i+1) );  mf_arr[i]=x; }  return 0;  }
ll m_inv(ll x, ll mod, ll is_fac ){ makeinv(2*1e6+10,mod);  return is_fac?finv_arr[x]:inv_arr[x]; }
ll m_f(ll x, ll mod){  make_mf(2*1e6+10,mod);  return mf_arr[x];  }
// ll mod_nck(ll n, ll k, ll mod){ return m_f[n]*finv_arr[k]%mod*finv_arr[n-k]%mod; }
ll m_p(ll r,ll n,ll mod){  ll t=1,s=r;  while(n>0){ t = (n&1) ? t*s%mod : t;  s=s*s%mod; n>>=1; }  return r?t:0;  }
ll m_mul2(ll a, ll b, ll mod){ return a*b%mod; }
ll m_mul3(ll a, ll b, ll c, ll mod){ return m_mul2(a*b%mod,c,mod); }
ll m_mul4(ll a, ll b, ll c, ll d, ll mod){ return m_mul3(a*b%mod,c,d,mod); }
ll m_mul5(ll a, ll b, ll c, ll d, ll e, ll mod){ return m_mul4(a*b%mod,c,d,e,mod); }

int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
int cmp_string( const void * a , const void * b ) {  return strcmp( (char *)a , (char *)b ); }  // qsort((void*)s,n,sizeof(s[0]),int_sort );
int cmp_char(const void * a, const void * b) { return *(char *)a - *(char *)b;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
void sort_string(int n,int size,char s[][size]){ qsort( (void*)s , n , sizeof(s[0]) , cmp_string ); }
void sort_char(char *s){ qsort( (void *)s , strlen(s) , sizeof(char) , cmp_char ); }
ll unique_string(ll n ,ll size, char s[][size]){ ll ans=1; rep(i,1,n) if( strcmp(s[i],s[i-1]) ) ans++; return ans; }
ll unique_num(ll n , ll a[]){ ll ans=1; rep(i,1,n) if( a[i]!=a[i-1] ) ans++; return ans; }

typedef struct{ ll a , b;}fr;
int cmp1( const void *p, const void *q ) { return ((fr*)p) ->a - ((fr*)q)->a;}
int cmp2( const void *p, const void *q ) { return ((fr*)q) ->a - ((fr*)p)->a;}
void strsortup(fr*a,int n){qsort(a,n,sizeof(fr),cmp1);}
void strsortdown(fr*a,int n){qsort(a,n,sizeof(fr),cmp2);}

// char s[1151154];
ll ppp[10010005];
int main(void){
    // fgets(s,sizeof(s),stdin);
    ll n;
    ll ans=0;
    cin(&n);
    // ll a++
    // scanf("%s",s);
    rep(i,0,1e7+3) ppp[i]=1;
    // ll [n];
    factor_pre();
    rep(i,0,fac_cnt){
        if(factors[0][i]>1e4) break;
        repp(j,factors[0][i],1e7+3,factors[0][i]){
            ll t=j,p=0;
            while(t%factors[0][i]==0){
                t/=factors[0][i]; p++;
            }
            ppp[j]*=p+1;
        }
    }
    rep(i,1,n+1){
        ans+=i*ppp[i];
    }

    printf("%lld\n",ans);
    return 0;
}


#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<ctype.h>
typedef long long LL;
#define rep(i,n) for(LL i=0; i<(LL)(n); i++)

//qsort
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}

//比較
int max(int a, int b){
	if (a>b) return a;
	else return b;
}

int min(int a,int b) {
	if(a>b) return b;
	else return a;
}

//main関数
int main(){
	int N;
	scanf("%d",&N);

	int A[N];
	int flag[1000010] = {0};
	rep( i , N ){
		scanf("%d",&A[i]);
		flag[ A[i] ] = 1;
	}
	qsort( A, N , sizeof(int), compare_int );
	rep(i,N-1){
		if( A[i] == A[i+1] ) {
			flag[A[i]] = 0;
		}
	}
	int ans = 0;
	for( int i=0; i<N; i++ ){
		if( flag[A[i]] == 1 ){
			ans++;
		}
		int j=2;
		while( A[i]*j <= A[N-1] ){
			flag[ A[i] * j ] = 0;
			j++;
		}
	}

	printf("%d",ans);
}

Score : 400 points

Problem Statement

Given is a number sequence A of length N.

Find the number of integers i \left(1 \leq i \leq N\right) with the following property:

For every integer j \left(1 \leq j \leq N\right) such that i \neq j , A_j does not divide A_i.

Constraints

All values in input are integers.

1 \leq N \leq 2 \times 10^5

1 \leq A_i \leq 10^6

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 \cdots A_N

Output

Print the answer.

Sample Input 1

5
24 11 8 3 16

Sample Output 1

3

The integers with the property are 2, 3, and 4.

Sample Input 2

4
5 5 5 5

Sample Output 2

0

Note that there can be multiple equal numbers.

Sample Input 3

10
33 18 45 28 8 19 89 86 2 4

Sample Output 3

5


#include<stdio.h>
#include<stdlib.h>
int main(void){

  int i,j,flag = 0,count = 0;
  int n,*a;
  scanf("%d",&n);
  a = (int*)malloc(sizeof(int)*n);

  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }

  for(i=0;i<n;i++){
   for(j=0;j<n;j++){

     if(i != j){
       if(a[i] >= a[j] && a[i] % a[j] == 0){
         flag = 1;
         break;
       }
     }
   }

     if(flag==0){
      count++;
     }
    flag = 0;

  }

       printf("%d",count);

 free(a);
 return 0;
}


#include<stdio.h>
int main()
{
    int n,a[200000],i,j,count=0;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    for(i=0;i<n;i++)
    {
        int flag=1;
        for(j=0;j<n;j++)
        {
            if(i!=j)
            {
                if(a[i]%a[j]==0)
                {
                    flag=0;
                    break;
                }
            }
        }
        if(flag==1)
        {
            count++;
        }
    }
    printf("%d",count);
}


#include <stdio.h>
#include <stdlib.h>

int comparador(const void *a, const void *b)
{
   return ( *(int*)a - *(int*)b );
}

int main()
{
   int n;
   scanf("%d", &n);
   int a[n];
   int marcador[1000000] = {0};
   int result = 0, valor, igual = 0;

   for(int i=0; i<n; i++)
   {
      scanf(" %d", &a[i]);
   }
   qsort(a,n,sizeof(int),comparador);

   for(int i=0; i<n; i++)
   {
      if(marcador[a[i]] == 0)
      {
         result++;
         for(int j=2;; j++)
         {
            valor = a[i]*j;
            if(valor > 1000000)
               break;
            marcador[valor] = 1;
         }
      }
      if(a[i] == a[0])
         igual++;
   }
   if(igual == n)
   {
      printf("%d\n", 0);
      return 0;
   }

   printf("%d\n", result);
   return 0;
}


#include<stdio.h>
#include <assert.h>
#include <stdio.h>
#include <string.h>

/*
	入力例：
	3
	1 1 3
*/
int main(){
	int iDataNum,st,sx,sy,i;
	int ct,cx,cy;
	int strInput[1];
	for(int i=0;i<1;i++){
	 scanf("%d", &strInput[i]);
	}

	int strInput2[strInput[0]];
	for(int i=0;i<strInput[0];i++){
	 scanf("%d", &strInput2[i]);
	}

	int cnt[1000001]={0};
	int iRetCnt;
	iRetCnt=0;
	for(int i=0;i<strInput[0];i++){

		for(int j=strInput2[i];j<1000001;j+=strInput2[i]){
			if(cnt[j]>=1){
				cnt[j]=2;
				continue;
			}
			cnt[j]=1;
		}
	}
	for(int i=0;i<strInput[0];i++){
		if(cnt[strInput2[i]]==1){
			iRetCnt++;
		}
	}
	printf("%d\n",iRetCnt);

  return 0;
}


#include <math.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define PI acos(-1)
typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;

int main(void) {
  /* 標準入力フラグ */
  int   scan;

  /* 数入力 */
  int    answer;
  int    n;
  int    *a;
  answer = 0;
  scan = scanf("%d", &n);
  a = (int *)malloc(sizeof(int) * n);
  for (int i = 0; i < n; i++) {
    scan = scanf("%d", &a[i]);
  }

  int   *result;
  result = (int *)malloc(sizeof(int) * n);
  /* プログラムを書く */
  for (int i = 0; i < n; i++) {
    result[i] = 1;
    for (int j = 0; j < n; j++) {
      if (i != j && a[i] % a[j] == 0) {
        result[i] = 0;
      }
    }
  }

  for (int i = 0; i < n; i++) {
    answer += result[i];
  }
  printf("%d", answer);

  return (0);
}


#include <stdio.h>

#define rep(i, n) for (int i = 0; i < n; i = i + 1)
#define MAX 10010
#define MAX_INT 9223372036854775807

/**
 * target について、割り切れるものが無いか探す
 * 割り切れるものがあったら 1 を返す
 * なければ 0 を返す
 * @param target: long long int
 *        割られる対象
 * @param A[]: long long int
 *        これを用いて target を割っていく
 * @param N: long long int
 *        配列Aの要素数
 * @param variable_i: long long int
 *        i !== j という条件を満たすために、呼び出し側の iteration_count をもらいたかった
 * @return short int 0 | 1
 */
short find_div(long long target, long long A[], long long N, long long variable_i) {
  short ret_val = 0; // 見つからなかった
  rep(i, N) {
    if (variable_i == i) {
      continue;
    }
    //    printf("target: %lld\n", target);
    //    printf("i: %d\n", i);
    //    printf("A[i]: %lld\n", A[i]);
    //    printf("target / A[i]: %lld\n\n", target / A[i]);
    // 余りが0ということは割り切れた
    if (target % A[i] == 0) {
      ret_val = 1;
    }
  }
  return ret_val;
}

int main() {
  long long N; // <= 2 * 10^5
  scanf("%lld", &N);

  long long A[N]; // <= 10^6
  rep(i, N) {
    scanf("%lld", A + i);
  }

  long long output = 0;
  short div_ans[1000000];
  // 2で初期化
  rep(i, N) {
    div_ans[A[i]] = 2;
  }
  // 入力の1つ目から順に見ていく
  rep(i, N) {
    // 2だったら初期値
    // なのでfind_divの結果を入れる
    if (div_ans[A[i]] == 2) {
      //      printf("A[i]: %lld\n", A[i]);
      div_ans[A[i]] = find_div(A[i], A, N, i);
    }
    if (div_ans[A[i]] == 0) {
      //      printf("A[i]: %lld\n", A[i]);
      output += 1;
    }
  }

  printf("%lld\n", output);

  return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<stdbool.h>
#include<assert.h>
typedef long long ll;
typedef long double ld;
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define rrep(i,l,r)for(ll i=(l);i>=(r);i--)
#define INF (1LL<<60)
#define MOD1 1000000007
#define MOD2 998244353
#define MAX_N (1 << 17)
#define YES printf("Yes\n")
#define NO printf("No\n")
#define PN printf("\n")
#define charsize 100005 //10^5+5
#define PI 3.141592653589793238

void swap(ll *a, ll *b){ll c;c=*b;*b=*a;*a= c;}
void cin(ll *n){ scanf("%lld",&(*n)); }
ll max2(ll a,ll b){return a>=b?a:b;}
ll min2(ll a,ll b){return a>=b?b:a;}
ll min3(ll a, ll b, ll c){return (a<=b && a<=c) ? a : b<=c ? b : c;}
ll max3(ll a, ll b, ll c){return (a>=b && a>=c) ? a : b>=c ? b : c;}
ll minn(ll n, ll a[]){ll b=INF;rep(i,0,n) b=min2(b,a[i]);return b;}
ll maxn(ll n, ll a[]){ll b=-INF;rep(i,0,n) b=max2(b,a[i]);return b;}
ll POW(ll a, ll b){ll c=1;rep(i,0,b) c*=a;return c;}
double POW_d(double a, double b){double c=1;rep(i,0,b) c*=a;return c;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll mod_MOD1(ll n){n+= n<0?((-n)/MOD1+1)*MOD1:0; return n%=MOD1;}
ll mod_p(ll n ,ll p){n+= n<0?((-n)/p+1)*p:0; return n%=p;}
ll change_into_num(char s[] , ll len, ll p){ return !p ? 0 : POW(10,p-1)*(s[len-p]-'0') + change_into_num(s,len,p-1); }

void lr_lower( int *l, int *r, ll am, ll val , int type ){ (type<3) ? ( am < val ?  ( *l = (*l+*r)/2 ) : ( *r= (*l+*r)/2 ) ) : ( am <= val ? ( *l = (*l+*r)/2 ) : ( *r= (*l+*r)/2 ) ); }
void lr_upper( int *l, int *r, ll am, ll val , int type ){ (type<3) ? ( am <= val ?  ( *l = (*l+*r)/2 ) : ( *r= (*l+*r)/2 ) ) : ( am < val ? ( *l = (*l+*r)/2 ) : ( *r= (*l+*r)/2 ) ); }
int cmp_lower( ll a, ll b, int type ){ return (type==1) ? ( a==b ? 1 : 0 ) : (type==2) ? ( a>=b ? 1 : 0 ) : ( a>b ? 1 : 0 ) ; }
int cmp_upper( ll a, ll b, int type ){ return (type==1) ? ( a==b ? 1 : 0 ) : (type==2) ? ( a<=b ? 1 : 0 ) : ( a<b ? 1 : 0 ) ; }
// return smallest p  which meets  a[p]==val :1  >=:2   >:3
ll lower_bound( ll a[], int l, int r, ll val , int type ){  while(r-l>1) lr_lower(&l,&r,a[ (l+r)/2 ],val,type);  return cmp_lower(a[l],val,type) ? l : cmp_lower(a[r],val,type) ? r : -1;  }
// return biggest p  which meets   a[p]==val :1  <=:2   <:3
ll upper_bound( ll a[], int l, int r, ll val , int type ){  while(r-l>1) lr_upper(&l,&r,a[ (l+r)/2 ],val,type); return cmp_upper(a[r],val,type) ? r : cmp_upper(a[l],val,type) ? l : -1; }
// count i  which meets ai==x
ll count(ll a[], int l, int r, ll x){  int p = lower_bound(a,l,r,x,1);  return p==-1 ? 0 : upper_bound(a,p,r,x,1)-p+1; }

ll *factors[2] , fac_cnt=0 , is_factor_prepared=0;
ll factor_pre(){  rep(i,0,1){ if(is_factor_prepared++) return 0; }  ll tmp=(1e3)/2+1, fac_tmp[tmp];  rep(i,0,tmp){fac_tmp[i]=i?2*i+1:2;}  rep(i,1,tmp){if(fac_tmp[i]){  repp(j,3,tmp/(2*i+1)+1,2 ){  if( j*(2*i+1)<tmp ) fac_tmp[ (j*(2*i+1)-1)/2 ]=0;  }  }else continue;}  rep(i,0,tmp){if(fac_tmp[i]){  rep(j,0,2){ factors[j] = realloc( factors[j] , sizeof(ll)*( fac_cnt +1 ) );  factors[j][j?fac_cnt++:fac_cnt]=j?0:fac_tmp[i];  }  } }  return 0;  }
ll factor(ll n, ll new_common_plus){ factor_pre();  rep(i,0,fac_cnt){ ll cnt=0; rep(j,0,1){ while( ( cnt+= n %factors[0][i]==0 ? 1 : 0 )  && (n/=factors[0][i]) %factors[0][i]==0 ) continue; } factors[1][i]= new_common_plus==1 ? cnt :  new_common_plus==2 ? max2(factors[1][i],cnt) : factors[1][i]+cnt ;  if( factors[0][i]> n ) break; } return n; }
ll judge_prime(ll n){ factor_pre(); rep(i,0,fac_cnt){ if(n<factors[0][i]*factors[0][i] || n==factors[0][i]) break; else if(n%factors[0][i]==0) n/=n; }  return n==1?0:1; }

ll *mod_fac_arr,*inv_arr,*finv_arr,is_modinv_made=0,is_modfac_made=0;
ll makeinv(ll n , ll mod){  rep(i,0,1){if(is_modinv_made++) return 0;}  inv_arr = realloc(inv_arr, sizeof(ll)*2 );  finv_arr = realloc(finv_arr, sizeof(ll)*2 );  inv_arr[1]=1;finv_arr[0]=finv_arr[1]=1;  rep(i,2,n+1){  inv_arr = realloc(inv_arr, sizeof(ll)*(i+1) );  finv_arr = realloc(finv_arr, sizeof(ll)*(i+1) );  inv_arr[i]= mod - inv_arr[mod%i] * (mod / i) % mod;  finv_arr[i] = finv_arr[i - 1] * inv_arr[i] % mod;  }  return 0; }
ll make_mod_fac(ll n, ll mod){  rep(i,0,1){ if(is_modfac_made++) return 0; }  mod_fac_arr = realloc(mod_fac_arr, sizeof(ll)*2 );  ll x=1;  mod_fac_arr[0]=mod_fac_arr[1]=x;  rep(i,2,n+1){   x=x*i%mod;  mod_fac_arr = realloc(mod_fac_arr, sizeof(ll)*(i+1) );  mod_fac_arr[i]=x; }  return 0;  }
ll mod_inv(ll x, ll mod, ll is_fac ){ makeinv(2*1e5,mod);  return is_fac?finv_arr[x]:inv_arr[x]; }
ll mod_fac(ll x, ll mod){  make_mod_fac(2*1e5,mod);  return mod_fac_arr[x];  }
// ll mod_nck(ll n, ll k, ll mod){ return mod_fac[n]*finv_arr[k]%mod*finv_arr[n-k]%mod; }
ll modpow(ll r,ll n,ll mod){  ll t=1,s=r;  while(n>0){ t = (n&1) ? t*s%mod : t;  s=s*s%mod; n>>=1; }  return r?t:0;  }

int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
int cmp_string( const void * a , const void * b ) {  return strcmp( (char *)a , (char *)b ); }  // qsort((void*)s,n,sizeof(s[0]),int_sort );
int cmp_char(const void * a, const void * b) { return *(char *)a - *(char *)b;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
void sort_string(int n,int size,char s[][size]){ qsort( (void*)s , n , sizeof(s[0]) , cmp_string ); }
void sort_char(char *s){ qsort( (void *)s , strlen(s) , sizeof(char) , cmp_char ); }
ll unique_string(ll n ,ll size, char s[][size]){ ll ans=1; rep(i,1,n) if( strcmp(s[i],s[i-1]) ) ans++; return ans; }
ll unique_num(ll n , ll a[]){ ll ans=1; rep(i,1,n) if( a[i]!=a[i-1] ) ans++; return ans; }

typedef struct{ ll a , b;}fr;
int cmp1( const void *p, const void *q ) { return ((fr*)p) ->a - ((fr*)q)->a;}
int cmp2( const void *p, const void *q ) { return ((fr*)q) ->a - ((fr*)p)->a;}
void strsortup(fr*a,int n){qsort(a,n,sizeof(fr),cmp1);}
void strsortdown(fr*a,int n){qsort(a,n,sizeof(fr),cmp2);}

// /*----------------------priorityqueue-----------------------------------------------------------*/
// // kind = max?1:0
// ll HeapValue(ll a){ return a?-INF:INF; }
// ll Heapcmp(ll a, ll b, ll kind){ return kind ? (a<b?1:0) : (a>b?1:0); }
// ll heap[MAX_N];

// void pushHeap(ll val, ll len , ll kind){
//     ll i=len; heap[i]=val;
//     while(i!=0){
//         if( Heapcmp( heap[i], heap[(i-1)/2] , llabs(kind-1) )  ) swap(&heap[i],&heap[(i-1)/2]);
//         i--;i/=2;
//     }
// }
// void popHeap(ll *val, ll len, ll kind){
//     ll i=0; *val=heap[0]; heap[0]=HeapValue(kind);
//     swap(&heap[0],&heap[len-1]);
//     while(len>i*2+1){
//         if(i*2+2<len && Heapcmp(heap[i],heap[i*2+2],kind) && Heapcmp(heap[i*2+1],heap[i*2+2],kind) ){
//             swap(&heap[i],&heap[i*2+2]);
//             i*=2;i+=2;
//         }else{
//             if( Heapcmp(heap[i],heap[i*2+1],kind) ){
//                 swap(&heap[i],&heap[i*2+1]);
//                 i*=2;i++;
//             }else break;
//         }
//     }
// }
// void deleteHeap( ll len, ll kind , ll piv){
//     ll i=piv; heap[piv]=HeapValue(kind);
//     swap(&heap[piv],&heap[len-1]);
//     while(len>i*2+1){
//         if(i*2+2<len && Heapcmp(heap[i],heap[i*2+2],kind) && Heapcmp(heap[i*2+1],heap[i*2+2],kind) ){
//             swap(&heap[i],&heap[i*2+2]);
//             i*=2;i+=2;
//         }else{
//             if( Heapcmp(heap[i],heap[i*2+1],kind) ){
//                 swap(&heap[i],&heap[i*2+1]);
//                 i*=2;i++;
//             }else break;
//         }
//     }
// }
// /*---------------------------------------------------------------------------------*/
// ll f[100000*2][346];
// ll irr[200000];

int main(void){
    // fgets(s,sizeof(s),stdin);
    // char ;
    ll n;
    ll ans=0;
    cin(&n);
    // scanf("%s",);
    ll a[n];
    rep(i,0,n){
        cin(&a[i]);
        // ll t=
        // pushHeap(a,i,0);
    }
    // factor_pre();
    // printf("%lld\n",fac_cnt);
    // ll cnt=n;
    sortup(a,n);
    // while(cnt){
    //     // printf("%lld\n",heap[0]);
    //     ll jud=1;
    //     rep(i,1,n){
    //         if(i>=cnt) break;
    //         if(heap[i]==heap[0]) jud=0;
    //         if(heap[i]%heap[0]==0){
    //             // printf("%lld\n",i);
    //             // rep(j,0,n){
    //             //     printf("%lld ",heap[j]);
    //             // }
    //             // PN;
    //             deleteHeap(cnt--,0,i);
    //             // rep(j,0,n){
    //             //     printf("%lld ",heap[j]);
    //             // }
    //             // PN;
    //             i--;
    //         }
    //     }
    //     ans+=jud;
    //     deleteHeap(cnt--,0,0);
    //     // ll tmp;
    //     // popHeap(&tmp,cnt--,0);
    // }
    // rep(i,0,n) printf("%lld ",a[i]);
    // PN;
    rrep(i,n-1,1){
        // printf("%lld\n",a[i]);
        if(a[i]==a[i-1]) continue;
        rep(j,0,i){
            if(a[j]>a[i]/2){
                break;
            }
            if(a[i]%a[j]==0){
                goto NEXT;
            }
        }
        ans++;
        NEXT:;
    // printf("%lld\n",ans);
    }
    if(n>1){
        if(a[0]!=a[1]) ans++;
    }

    printf("%lld\n",ans);
    return 0;
}


#include <stdio.h>
#include <math.h>

int main() {
  int hoge = 2 * pow(10, 5);
  int n, a[hoge], c=0, flg=0;
  scanf("%d\n", &n);
  for (int i=0; i<n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i=0; i<n; i++) {
    flg = 0;
    for (int j=0; j<n; j++) {
      if (a[i] != a[j]) {
        if (a[i] % a[j] != 0) {
          flg++;
        }
      }
    }
    if (flg == n-1) {
      c++;
    }
  }
  printf("%d\n", c);
}


#include <stdlib.h>

int compare_int(const void *a, const void *b)
{
  return *(int*)a - *(int*)b;
}

int main()
{
  int n;
  scanf("%d", &n);
  int a[n], i, j;
  for (i = 0; i < n; i++)
    scanf("%d", &a[i]);
  qsort(a, n, sizeof(int), compare_int);
  int cnt = 0;
  int flg;
  for (i = 0; i < n; i++)
  {
    flg = 0;
    if (a[i] == a[i + 1] || a[i] == a[i - 1])
      flg = 1;
    if (flg == 0)
    {
      for (j = 0; j < i; j++)
      {
        if (a[i] % a[j] == 0)
        {
          flg = 1;
          break;
        }
      }
    }
    if (flg == 0)
      cnt++;
  }
  printf("%d", cnt);
}


#include<stdio.h>
#include<math.h>
int main ()
{
    int n;
    scanf("%d",&n);

    long long int i,ar[n];
    for(i = 0;i<n;i++)
    {
        scanf("%lld",&ar[i]);
    }
    long long int product = 1 ;
    for(i = 0;i<n;i++)

    {

      product *= ar[i];
    }
      if(product>= 0 && product <= (1000000000000000000))
      {

       printf("%lld\n",product);
      }
      else if(product>= 0 && product > (1000000000000000000))
      {

          printf("%lld\n",product = -1);
      }

    return 0;
}

Score : 200 points

Problem Statement

Given N integers A_1, ..., A_N, compute A_1 \times ... \times A_N.

However, if the result exceeds 10^{18}, print -1 instead.

Constraints

2 \leq N \leq 10^5

0 \leq A_i \leq 10^{18}

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N
A_1 ... A_N

Output

Print the value A_1 \times ... \times A_N as an integer, or -1 if the value exceeds 10^{18}.

Sample Input 1

2
1000000000 1000000000

Sample Output 1

1000000000000000000

We have 1000000000 \times 1000000000 = 1000000000000000000.

Sample Input 2

3
101 9901 999999000001

Sample Output 2

-1

We have 101 \times 9901 \times 999999000001 = 1000000000000000001, which exceeds 10^{18}, so we should print -1 instead.

Sample Input 3

31
4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 5 0

Sample Output 3

0


#include<stdio.h>

int main(){
	unsigned long long int batas,sum;
	sum=1;
	batas= 10000000000000000000;
	long int i,n;
	scanf("%d", &n);
	for(i=1;i<=n;i++){
		unsigned long long int angka;
		scanf("%d", &angka);
		if(angka==0){
			sum=0;
		}
		else{
			sum*=angka;
			//printf("jumlah sum ke %d adalah %lld\n", i, sum);
		}
	}
	if(sum>batas){
		printf("-1\n");
		//printf("Batas adalah %lld", batas);
	}
	else{
		printf("%lld\n", sum);
		//printf("Batas adalah %lld", batas);
	}
	return 0;
}


#include <stdio.h>

int main () {
	int n;
	scanf("%d", &n);
	long long int a[n];
	unsigned long long sum = 1;
	for (int i = 0; i < n; i++){
		scanf("%lld", &a[i]);
		sum *= a[i];
	}
	if (sum > 1000000000000000000 / a[0]){
		printf("-1");
	}
	else {
		printf("%llu\n", sum);
	}

	return 0;
}


#include<stdio.h>
int main()
{
	long long sum = 1,ans;
	int flagO = 1,flag = 1;
	long long tc;
	scanf("%lld",&tc);
	long long input[tc+1];
	for(int i = 0;i<tc;i++)
	{
		scanf("%lld",&input[i]);
		if(input[i] == 0)
		{
			flagO = 0;
		}
	}
	for(int i = 0;i<tc;i++)
	{
		if(sum *input[i] > 1000000000000000000 || sum * input[i] < 0 || input[i] > 1000000000000000000)
		{
			flag = 0;
			break;
		}
		sum *= input[i];
	}
	if(flagO == 0) printf("0\n");
	else if(flag == 0) printf("-1\n");
	else printf("%lld",sum);

}


#include <stdio.h>

int main () {
	long long n, sum = 1;
	scanf("%lld", &n);
	for (int i = 0; i < n; i++){
		long long int a;
		scanf("%lld", &a);
		sum *= a;
	}

	if (sum > 1000000000000000000){
		printf("-1");
	}
	else {
		printf("%lld\n", sum);
	}
	return 0;
}


#include<stdio.h>
int main()
{
	long long tc;
	scanf("%lld",&tc);
	long long input[tc+1];
	long long total = 1;
	int flag = 1;
	for(int i = 0;i<tc;i++)
	{
		scanf("%lld",&input[i]);
		total *= input[i];
	}
	for(int i = 0;i<tc-1;i++)
	{
		if(input[i] >= 1000000000000000000 && input[i+1] > 1)
		{
			flag = 0;
		}
	}
	if(flag == 0) printf("-1\n");
	else if(total > 1000000000000000000) printf("-1\n");
	else printf("%lld\n",total);
	return 0;
}


#include <stdio.h>
int main()
{
  int n, flag = 0;
  long long arr[100000];
  long long temp = 1;
  scanf("%d",&n);
  for(int i = 0; i < n ;i++)
  {
     scanf("%lld", &arr[i]);
  }

  for(int i = 0; i < n;i++)
  {
     if(arr[i] == 0)
     {
     	flag = 1;
     	break;
	 }
	 if(flag == 0)
	 {
	 	printf("0\n");
	 	return 0;
	 }
  }

  for(int i = 0; i < n;i++)
  {
    if(arr[i]<=1000000000000000000/temp)
	{
      temp = temp * arr[i];
    }
    else
	{
      printf("-1\n");
      return 0;
    }
  }
  printf("%lld", temp);
  return 0;
}


#include <stdio.h>

int main()
{
  int n,i;
  long long a,ans=1,t=1000000000000000000;
  scanf("%d",&n);

  for(i=0; i<n; i++){
    scanf("%lld", &a);

    if(a == 0){
      puts("0");
      return 0;}

    if(ans > t/a)
      {
        printf("-1");
        return 0;
      }
    ans = ans * a;
  }

  if(ans > t)
    printf("-1");
  else
    printf("%lld",ans);
  return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main(void){
    int i,n;
    long ans=1;

    scanf("%d",&n);

    long a[n];

    for(i=0;i<n;i++){
        scanf("%ld",&a[i]);
    }

    for(i=0;i<n;i++){
        if(ans * a[i] > 1000000000000000000){
            printf("-1\n");
            return 0;
        }
        ans *= a[i];
    }
    printf("%ld",ans);
    return 0;
}


#include <stdio.h>

int main (void) {
    int n;
    long long a[100010];
    long long result = 1;
    scanf("%d", &n);
    for (int i=0; i<n; i++) {
        long long input;
        scanf("%lld", &input);
        a[i] = input;
        if (input == 0) {
            result = 0;
        }
    }

    if (result == 0) {
        printf("%d\n", 0);
        return 0;
    }

    for (int i=0; i<n; i++) {
        if (a[i] <= 1000000000000000000/result) {
            result *= a[i];
        } else {
            printf("-1\n");
            return 0;
        }
    }

    printf("%lld\n", result);
    return 0;
}


#include<stdio.h>
int main (void){
    int N,i;
    long long int result;
    long long int A[100000];
    result = 1;
    scanf("%d",&N);
    for(i=0;i<N;i++){
        scanf("%lld",&A[i]);
        result = result * A[i];
    }
    if(result>=1000000000000000000 || result < 0){
        printf("-1");
    }else{
        printf("%lld\n",result);
    }
    return 0;
}


#include<stdio.h>
signed main(){

long long i,n,answer=1;

scanf("%lld",&n);
long long a[n];

for(i=0;i<n;i++){

scanf("%lld",&a[i]);
answer*=a[i];
}
if(answer<=1000000000000000000){
printf("%lld\n",answer);
}else{
printf("-1\n");
}

return(0);
}


#include<stdio.h>
signed main(){
  long long N,A[100000],res=1;
  scanf("%lld",&N);
  int i;
  for(i=0;i<N;i++){
    scanf("%lld",&A[i]);
  }
  for(i=0;i<N;i++){
    res*=A[i];
  }
  if(res>1000000000000000000){
    printf("-1\n");
  }else{
    printf("%lld\n",res);
  }
  return(0);
}


#include <stdio.h>

int main(void){
  int n;
  scanf("%d",&n);

  long int a[n];
  int i, j=0;
  long int ans=1;
  for(i=0; i<n; i++){
    scanf("%ld", &a[i]);
    ans*=a[i];
    if(a[i]==0){
      ans=0;
    }
  }

  for(i=0; i<n; i++){
    if(a[i]==0){
      ans=0;
      printf("%ld\n", ans);
      j++;
      break;
    }else if(ans>1000000000000000000){
      printf("-1");
      j++;
      break;
    }
  }
  if(j==0){
    printf("%ld\n", ans);
  }

  return 0;
}


#include<stdio.h>

int main(void)
{
	long long a[100000] = { 0 };
	int i;
	long long N,ans=1;

	scanf("%lld", &N);

	for (i = 0; i < N; i++)
	{
		scanf("%lld", &a[i]);

		ans = a[i] * ans;
		if (a[i] == 0)
		{
			ans = 0;
			break;
		}
		else if(ans>1000000000000000000)
		{
			ans = -1;
			break;
		}
	}
	printf("%lld", ans);
	return 0;
}


#include<stdio.h>

int main(void)
{
	long long a[100000] = { 0 };
	int N,i;
	long long ans=1;

	scanf("%d", &N);

	for (i = 0; i < N; i++)
	{
		scanf("%lld", &a[i]);

		ans = a[i] * ans;
		if (a[i] == 0)
		{
			ans = 0;
			break;
		}
		else if(ans>1000000000000000000)
		{
			ans = -1;
			break;
		}
	}
	printf("%lld", ans);
	return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void)
{
    int N;
    unsigned long long int *A;
    unsigned long long int ans = 1;
    int c;
    scanf("%d", &N);
    A = (unsigned long long int *)malloc(sizeof(unsigned long long int) * N);
    for (c = 0; c < N; ++c)
    {
        scanf("%llu", A + c);
        if (A[c] == 0)
        {
            printf("0");
            return 0;
        }
    }
    for (c = 0; c < N; ++c)
    {
        if (A[c] > (unsigned long long)1e+18)
        {
            printf("-1");
            return 0;
        }
        ans *= A[c];
        if (ans > (unsigned long long)1e+18)
        {
            printf("-1");
            return 0;
        }
    }
    printf("%llu", ans);
    return 0;
}


#include <stdio.h>
#include <math.h>

int main()
{
    long long t,s=1,n,i;
    scanf("%lld",&t);
    for(i=0;i<t;i++)
    {
        scanf("%lld",&n);
        s*=n;
    }
    if(s>pow(10,17)) s=-1;

    printf("%lld\n",s);

    return 0;
}


#include<stdio.h>
#include<string.h>

int main(){

	long long int mul=1,i,a[100000],n;

	scanf("%lld",&n);
	for(i=0 ; i<n ; i++)
		scanf("%lld",&a[i]);

	for(i=0 ; i<n ; i++){
		mul*=a[i];
	}

	if(mul>1000000000000000000)
		printf("%d",-1);
	else
		printf("%lld\n",mul);

	return 0;
}


#include <stdio.h>
#include <math.h>
#define LIMIT 100000
int main(void){
  int N,A[LIMIT]={0},multiple,i;
  scanf("%d",&N);
  for(i=0; i<N; i++){
    scanf("%d",&A[i]);
  }
  multiple=A[0];
  for(i=1; i<N; i++){
    multiple *= A[i];
  }

  if(multiple > pow(10.0,18.0)){
    printf("%d\n",-1);
  }else{
    printf("%d\n",multiple);
  }
  return 0;
}


#include <stdio.h>

int main(void)
{
	int unsigned long long a = 1;
	int n;
	int unsigned long long array[100000] = {};

	scanf("%d", &n);

	for (int i = 0; i < n; i++)
	{
		scanf("%llu", &array[i]);
	}

	for (int i = 0; i < n; i++)
	{
		a = a * array[i];
		if (a <= 1000000000000000000)
		{
			printf("%lld", a);
		}
		else
		{
			printf("-1");
		}
	}
	return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main() {
    long long A[100000],answer = 1,max = 1000000000000000000;
    int n,i;
    scanf("%d",&n);

    for (i = 0;i < n;i++){
        scanf("%lld",&A[i]);
    }

    for (i = 0;i < n;i++){
        if (A[i] == 0){
            printf("0");
            return 0;
        }else if(max / A[i] > answer){
            answer = -1;
            return 0;
        }else{
            answer *= A[i];
        }
    }

    printf("%lld\n",answer);

    return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define giga 1e9
#define exa 1e18

int main() {
	int  n;
	long long ans = 1, a;
	scanf("%d\n", &n);
	for (int i = 0; i < n; i++) {
		scanf("%lld", &a);
		if (a == 0) {
			printf("0");
			return 0;
		}
		if (ans >= exa / a) {
			printf("-1");
			return 0;
		}
		ans *= a;
	}

	printf("%lld", ans);

	return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
	int k,i,flag=1;
	long long int data,res=1;
	long long pow1=pow(10,18);
	scanf("%d",&k);
	for(i=0;i<k;++i)
	{
		scanf("%lld",&data);
		res=res*data;
		if(pow1-res<0)
			flag=0;
	}
	if(flag)
		printf("%lld\n",res);
	else
		printf("-1\n");
	return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

#define SIZE 100005
#define PI acosl(-1) //3.14159265358979323846264338327950L
#define rep(i, N) for (i = 0; i < N; i++) //制御変数iを用いてN回転
#define array(N, t) (t*)calloc(N, sizeof(t)) //t型N要素の1次元配列を動的確保後0クリア(freeを忘れずに)
#define zero(a); {int iter; rep(iter, sizeof(a)/sizeof((a)[0])) (a)[iter]=0;} //1次元配列aのゼロ初期化?

typedef long long ll; typedef long double ld;
typedef struct node { int data; struct node *next; } Node;

Node *list[SIZE];
int queue[SIZE]; int q_head = 0, q_tail = 0;

void print_log(); //とりあえず文字を出力してどこまで実行できているか確認(for debug)
void printa_int(int *a, int size); //int型の1次元配列aを出力(for debug)
void printl_int(int size); //リンクリストを出力(for debug)
Node* add_node(int i, int data); void free_list(Node* head);
int queue_empty(); int queue_full();
void enqueue(int data); int dequeue();

int main() {
    int i, N;
    scanf("%d", &N);
    ll *A = array(N, ll);
    rep(i, N) {
        scanf("%lld", A + i);
        if (!A[i]) {
            printf("0\n");
            return 0;
        }
    }
    ll ans = 1, temp = 1;
    rep(i, N) {
        if (ans > 1000000000000000000LL / A[i]) {
            printf("-1\n");
            return 0;
        }
        ans *= A[i];
        temp = ans;
    }
    printf("%lld\n", ans);
    return 0;
}

void print_log() {
    printf("=== print log ===\n");
}
void printa_int(int *a, int size) {
    int i;
    printf("[");
    for (i = 0; i < size; i++)
        printf("%d, ", a[i]);
    printf("]\n");
}
void printl_int(int size) {
    int i;
    Node *t;
    rep(i, size) {
        printf("[%d] ", i);
        for (t = list[i]; t; t = t->next) printf("%d, ", t->data);
        printf("\n");
    }
}
Node* add_node(int i, int data) {
    if (!list[i]) {
        list[i] = (Node*)malloc(sizeof(Node*));
        list[i]->data = data;
    } else {
        Node *t;
        t = list[i];
        list[i] = (Node*)malloc(sizeof(Node*));
        list[i]->data = data;
        list[i]->next = t;
    }
    return list[i];
}
void free_list(Node* head) {
    Node *prev = NULL, *t = head;
    while (t) {
        prev = t;
        t = t->next;
        free(prev);
    }
}
int queue_empty() {
    return q_head == q_tail;
}
int queue_full() {
    return (q_head - 1) % SIZE == q_tail % SIZE;
}
void enqueue(int data) {
    if (queue_full()) {
        printf("full!\n");
        return;
    }
    queue[q_tail++] = data;
    q_tail %= SIZE;
}
int dequeue() {
    if (queue_empty()) {
        printf("empty!\n");
        return -444444;
    }
    int data = queue[q_head++];
    q_head %= SIZE;
    return data;
}


#include <stdio.h>

int main()
{
	int n;
	scanf("%d", &n);

	register long long unsigned int a= 1;
	long long unsigned int b;
	int i;
	for (i = 0; i < n; i++) {
		scanf("%llu", &b);
		a *= b;
		if (a > 1E18) {
			printf("-1\n");
			return 0;
		}
	}
	printf("%llu", a);
	return 0;
}


#include <stdio.h>

int main(void){
    long long int n;
    scanf("%lld",&n);
    long long int a;
    scanf("%llu",&a);
    long long int ans = a;
    long long int ai[n-1];
    long long int i=0;
    if(ans == 0) {
        printf("0\n");
        return 0;
    }
    for(i = 0;i<n-1;i++){
        scanf("%llu",&ai[i]);
        if(ai[i] == 0) {
            printf("0\n");
            return 0;
        }
        if(ai[i] > 1000000000000000000){
            printf("-1\n");
            return 0;
        }
    }

    for(i = 0;i<n-1;i++){
        if(ans>(ans*ai[i])){
            printf("-1\n");
            return 0;
        }
        ans *= ai[i];
        if(ans>1000000000000000000) {
            printf("-1\n");
            return 0;
        }
    }

    printf("%lld\n",ans);
    return 0;
}


#include <stdio.h>

int main()
{
  long long int i,n,a,ans;

  scanf("%lld", &n);

  ans = 1;
  for (i = 0; i < n; i++) {
    scanf("%lld", &a);
    ans *= a;
  }

  if (ans > 1000000000000000000 || ans < 0)
    printf("-1");
  else
    printf("%lld", ans);
  return(0);
}


#include<stdio.h>
#include<stdlib.h>
int main(){
	int n;
	scanf("%d",&n);
	unsigned long long a[n];
	for(int i = 0; i < n; i++){
		scanf("%llu", &a[i]);
		if(a[i] == 0){
			printf("%llu\n", a[i]);
			return 0;
		}
	}
	unsigned long long sum = 1LL;
	for(int i = 0; i < n; i++){
		sum *= a[i];
		if(sum > 1000000000000000000){
			puts("-1");
			return 0;
		}
	}
	printf("%llu\n", sum);

	return 0;
}


#include<stdio.h>
int main(void)
{
    int N,i,tmp,A[100000];
    long long int sum;
    sum=1;
    tmp=scanf("%d",&N);
    for(i=0;i<N;i++)
    {
        tmp=scanf("%lld",&A[i]);
             sum=sum*A[i];

    }

     if(sum>=0 && sum<=1000000000000000000)
    {
        printf("%lld\n",sum);

    }
    else
    {
        {
            printf("-1\n");
        }
    }
    return 0;
}


int main()
{
  int n, i;
  scanf("%d", &n);
  unsigned long a[n];
  unsigned long tmp = pow(10, 18);
  unsigned long sum = 1;
  for (i = 0; i < n; i++)
  {
    scanf("%lu", &a[i]);
    sum = sum * a[i];
  }
  if (sum > tmp)
  {
    printf("-1\n");
    return 0;
  }
  printf("%lu", sum);
}


#include<stdio.h>
#include<stdlib.h>
int main(void){
int N;
scanf("%d",&N);
unsigned long long m=1,A[N+1];
  for(int i=0;i<N;i++){
  scanf("%ld",&A[i]);
  m=m*A[i];
  if(m>1000000000000000000||m<0) break;
  }
if(m>1000000000000000000||m<0) printf("-1");
else printf("%ld",m);
return 0;
}


#include <stdio.h>
#include <math.h>

int main(){
    int data[100000];
    int N,num,i,n,sum;
    //char s[20];
    num = 0;
    sum = 1;

    scanf("%d",&N);
    for(i=0;i<N;i++){
        scanf("%d", &data[i]);
    }

    for(num=0;num<N;num++){
        sum = sum * data[num];
    }

    //sprintf(s,"%d",sum);

   // for(n =0;s[n] != '\0' ; n++)

    if(sum <= pow(10,18)){
        printf("%d",sum);
    }else{
        printf("%d",-1);
    }

    return 0;

}


#include<stdio.h>
#include<math.h>
#include<string.h>

int keta(long long int xx)
{
	int yy = 0;
	while (1) {
		xx = xx / 10;
		yy++;
		if (xx < 10) {
			break;
		}
	}
	return yy;
}

int ke(long long int xx, long long int yy) {
	int xxx = 0;
	while (1) {
		xx = xx / 10;
		xxx++;
		if (xx < 10) {
			break;
		}
	}
	int yyy = 0;
	while (1) {
		yy = yy / 10;
		yyy++;
		if (yy < 10) {
			break;
		}
	}
	if (xx*yy > 11) {
		return 1;
	}
	return 0;
}

int main() {
	int i, j, k;
	int  n;
	long long int f = 1, m = 0;
	int g = 0;
	int x[110] = {0};
	int a, b, c, d;

	scanf("%d", &n);

	for (i = 0;i < n;i++) {
		scanf("%lld", &m);

		if (keta(f) + keta(m) > 18) {
			f = -1;
			break;
		}

		f = f * m;

		if (keta(f) > 18) {
			f = -1;
			break;
		}
	}

	printf("%lld", f);

	return 0;
}


#include<stdio.h>
#include<limits.h>

int main(void)
{
  long n;
  long long  sum=1LL;
  scanf("%ld",&n);
  long long  a[n];
  for(long i=0L;i<n;i++){
    scanf("%lld",&a[i]);
  }

  for(long i=0L;i<n;i++){
    sum=sum*a[i];
  }

  if(sum>=1000000000000000000LL){
    printf("%d\n",-1);
  }else{
    printf("%lld\n",sum);
  }
  return 0;
}


#include<stdio.h>
int main()
{
    int n;

    if(scanf("%d", &n)<1){
       return 0;
    }

    long long u,a[n],r;
    for(long long i=0;i<n;i++){
        if(scanf("%llu", &u)<1){
            return 0;
        }
        a[i]=u;
    }

    for(long long j=0;j<n;j++){
        if(j==0){
            r=a[0];
        }else{
            if(a[j]==0){
                printf("0");
                return 0;
            }else{
                r=r*a[j];
            }
        }
    }

    if(r > 1000000000000000000){
        r = -1;
    }
    printf("%llu",r);

    return 0;
}


#include<stdio.h>
int main()
{
    unsigned long n;
    int loop;
    unsigned long long ans=1;
    // 整数の入力
    scanf("%d", &loop);
    while (loop >= 1)
    {
        scanf("%lu", &n);
        ans = ans * n;
        if (n == 0)
        {
            break;
        }

        loop--;
    }
    // 出力
    if (ans > 1000000000000000000)
    {
        printf("-1");
    }
    else
    {
        printf("%llu",ans);
    }
    return 0;
}


#include <stdio.h>
#include <math.h>

int main(void){

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

    int i;
    long a[100000],ans=1;
    long max = pow(10, 18);

    for(i=0;i<n;i++){
        scanf("%ld",&a[i]);
        if(a[i]>max){
            ans=-1;
        }
        if(a[i]==0){
            printf("0\n");
            return 0;
        }
        ans*=a[i];
    }

    if (ans > max){
        printf("-1\n");
        return 0;
    }

    printf("%ld\n",ans);
    return 0;
}


#include<stdio.h>
#include<math.h>
int main()
{
    long long int i,a, b,sum=1;
   long long int result;
    result = pow(10,18);
scanf("%lld",&a);
if(a>=2)
 {while(a--)
 {
  scanf("%lld",&b);
    sum=sum*b;

 }
 if(sum>=result)
    printf("-1");
 else
 printf("%lld\n",sum);

}}


#include<stdio.h>
int main()
{
    int n;

    if(scanf("%d", &n)<1){
       return 0;
    }

    long long u,a[n],r=1;
    for(long i=0;i<n;i++){
        if(scanf("%llu", &u)<1){
            return 0;
        }
        a[i]=u;
//        r=r*a;
    }
    for(long j=0;j<n;j++){
        r*=a[j];
    }

    if(r > 1000000000000000000){
        r = -1;
    }
    printf("%llu",r);

    return 0;
}


#include<stdio.h>
int main()
{
    long long int i,a, b,sum=1;
scanf("%lld",&a);
if(a>=2)
 {while(a--)
 {
  scanf("%lld",&b);
    sum=sum*b;

 }
 if(sum>=1000000000000000000)
    printf("-1");
 else
 printf("%lld\n",sum);

}}


#include<stdio.h>
#include<math.h>
#include<string.h>

int keta(long long int xx)
{
	int yy = 0;
	while (1) {
		xx = xx / 10;
		yy++;
		if (xx < 10) {
			break;
		}
	}
	return yy;
}

int ke(long long int xx, long long int yy) {
	int xxx = 0;
	while (1) {
		xx = xx / 10;
		xxx++;
		if (xx < 10) {
			break;
		}
	}
	int yyy = 0;
	while (1) {
		yy = yy / 10;
		yyy++;
		if (yy < 10) {
			break;
		}
	}
	if (xx*yy > 10) {
		return 1;
	}
	return 0;
}

int main() {
	int i, j, k;
	int  n;
	long long int f = 1, m = 0;
	int g = 0;
	int x[110] = {0};
	int a, b, c, d;

	scanf("%d", &n);

	for (i = 0;i < n;i++) {
		scanf("%lld", &m);

		if (keta(f) + keta(m)+ke(f,m) > 18) {
			f = -1;
			break;
		}

		f = f * m;

		if (keta(f) > 18) {
			f = -1;
			break;
		}
	}

	printf("%lld", f);

	return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<math.h>

int main(){
    int N,hant=1;
    unsigned long long int  a;
    unsigned long long int kekka=1;
        scanf("%d",&N);
    int i;
    for(i=0;i<N-1;i++){
        scanf("%llu ",&a);
        kekka *=a;
        if(kekka>1000000000000000000){
            hant=-1;
        }
    }
        scanf("%llu",&a);
        kekka *=a;

        //   1000000000000000000
        /////9223372036854775807
    if(kekka<=1000000000000000000||hant==1)
        printf("%llu\n",kekka);
    else
        printf("-1");

    return 0;
}


#include<stdio.h>
int main()
{
    int n;

    if(scanf("%d", &n)<1){
       return 0;
    }

    long long a[n],r=1;
    for(long i=0;i<n;i++){
        if(scanf("%llu", &a[i])<1){
            return 0;
        }
        if(a[i]==0){
             printf("0");
        }
//        r=r*a;
    }
    for(long j=0;j<n;j++){
        r*=a[j];
    }
    if(r>1000000000000000000){
           printf("-1");
           return 0;
    }else{
        printf("%llu",r);
    }
    return 0;
}


#include <stdio.h>
#include <math.h>

int main(void)
{
  long n,p = 1,max = pow(10,18);

  scanf("%ld",&n);

  long a[n];

  for(long i=0; i<n; i++){
    scanf("%ld",&a[i]);
    p *= a[i];

    if(a[i] == 0){
      puts("0");
      return 0;
    }
  }

  if(p > max)
    puts("-1");

  else
  	printf("%l\n",p);

  return 0;
}


#include <stdio.h>

int main(void) {
	int N = 0;
	unsigned long int a[100000] = { 0 };
	unsigned long int ans = 1;

	scanf("%d", &N);

	for (int i = 0; i < N; i++) {
		scanf("%lu", &a[i]);
		if (a[i] == 0) {
			printf("0");
			return 0;
		}
	}

	for (int i = 0; i < N; i++) {
		ans = ans * a[i];
		if (ans > 1000000000000000000) {
			printf("-1");
			return 0;
		}
	}
	printf("%lu", &ans);

	return 0;
}


#include <stdio.h>
int main(){
  unsigned long long int a,n,ans=1,ans1=1;
  scanf("%lld", &n);
  for(int i=0;i<18;i++){
    ans1 = ans1*10;
  }
  for(int i=0;i<n;i++){
    scanf("%lld", &a);
    ans = ans * a;
  }
    if(ans>ans1||ans<0){
      ans=-1;
      printf("%lld", ans);
    }else{
  printf("%llu", ans);
}
  return 0;
}


#include <stdio.h>
#include <math.h>

int main(void){

    int n;
    scanf("%d",&n);
    int i;
    long a,ans=1;
    for(i=0;i<n;i++){
        scanf("%ld",&a);
        ans*=a;
    }
    long max=pow(10,18);
    if (ans > max){
        printf("-1\n");
        return 0;
    }
    printf("%ld\n",ans);
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main() {
  int n;
  scanf("%d", &n);
  long long a[n];
  for(int i=0;i<n;i++) {
    scanf("%lld", &a[i]);
    if(a[i]==0){
      printf("0");
      return 0;
    }
  }
  long long ans=1;
  for(int i=0;i<n;i++){
    ans *= a[i];
    if(ans > 1000000000000000000L){
      printf("-1");
      return 0;
    }
  }
  printf("%lld", ans);
  return 0;
}


#include <stdio.h>

int main(){

    int N;
    scanf("%d", &N);

    int i;
    long long int A, ans=1;
    long long int THR = 1000000000000000000;
    for(i=1;i<=N;i++){
        scanf("%lld", &A);
        ans *= A;
        if( A == 0 ){
            printf("0");
            return 0;
        }
    }

    if( ans > THR ){
        ans = -1;
    }

    printf("%lld\n", ans);

    return 0;
}


#include <stdio.h>

int main(){
  int N;
  scanf("%d",&N);
  int a[N];
  scanf("%d",&a[0]);
  int sum = a[0];
  int i;
  for(i=1;i<N;i++){
    scanf("%d",&a[i]);
    sum = sum * a[i];
    if(sum > 10e8){
      printf("-1");
    }
  }
  if(sum < 10e8){
    printf("%d",sum);
  }
  return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */
#define MAXSIZE 20
int main(int argc, char *argv[]) {
//

	char A[MAXSIZE], B[5];
	scanf("%s %s", A, B);
	int i;
	int j;
	int lenA = strlen(A);
	int lenB = strlen(B);
	char temp;
	for (i = 0; i < lenA/2; ++i)
	{
		temp = A[i];
		A[i] = A[lenA-1-i];
		A[lenA - 1 - i] = temp;

	}
//	printf("%s\n", A);

	for ( i = 1; i < 3; i++)
	{
		B[i] = B[i + 1];
	}
	B[3] = '\0';

	temp = B[0];
	B[0] = B[2];
	B[2] = temp;
//	printf("%s", B);
	lenB = strlen(B);
	int *res = (int *)calloc(lenA + lenB - 2, sizeof(int));
//	int res[lenA + 2] = 0;

	for ( i = 0; i < lenB - 1; ++i)
	{
		for (j = 0; j < lenA - 1; ++j)
		{
			res[i + j] += (A[j] - '0') * (B[i] - '0');
//			printf("%d", res[i + j]);
			if (res[i + j] >= 10)
			{
				res[i + j + 1] += 1;
				res[i + j] %= 10;
			}
		}
	}

	i =  i + j;

	while (res[i] == 0)
	{
		i--;
	}
//	printf("%d\n", i);
	if (i < 2)
	{
		printf("%d", 0);

	}
	else
	{
//		printf("%d\n", res[i]);

		while (i >=  2)
		{
			printf("%d", res[i--]);
		}

	}
//1000 0000  0000 0000
//9990 0000  0000 0000

	return 0;
}

Score : 300 points

Problem Statement

Compute A \times B, truncate its fractional part, and print the result as an integer.

Constraints

0 \leq A \leq 10^{15}

0 \leq B < 10

A is an integer.

B is a number with two digits after the decimal point.

Input

Input is given from Standard Input in the following format:

A B

Output

Print the answer as an integer.

Sample Input 1

198 1.10

Sample Output 1

217

We have 198 \times 1.10 = 217.8. After truncating the fractional part, we have the answer: 217.

Sample Input 2

1 0.01

Sample Output 2

0

Sample Input 3

1000000000000000 9.99

Sample Output 3

9990000000000000


#include <stdio.h>

int main(){
  long long x;
  int y, z;
  scanf("%lld %d.%d", &x, &y, &z);
  printf("%lld\n",x*(y*100+z)/100);
}


#include <stdio.h>
#include<math.h>

int main()
{
    long long a;
    double b;

    scanf("%lld %lf", &a, &b);
    printf("%lld", (a*(long long)(b*100))/100);

    return 0;
}


#include <stdio.h>

int main(void) {
    long int A, b2;
    double B, C;
    long int result;

    scanf("%ld", &A);
    scanf("%lf", &B);
    b2 = B * 100;
    C = A * b2;
    result = C/100;
    printf("%ld\n", result);
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main(void)
{
	long A;
	double  B;

	scanf("%ld %lf", &A, &B);

    B *= 100;

	printf("%ld", (long)(A*B/100));
}


#include<stdio.h>
int main(){
  long long int a;
  float b;
  scanf("%lld%f",&a ,&b);
  long long int z;
  z=a*b;
  printf("%d",z);
}


#include<stdio.h>
int main()
{
    long int n1;
    double n2,pro=1.0;
    scanf("%ld %lf",&n1,&n2);
    pro=(n1*(n2*100))/100;
    printf("%ld",pro);
    return 0;
}


#include<stdio.h>
#include<stdlib.h>
typedef long long ll;
int main(void)
{
  ll n,cn,ans=0,a;
  double b;
  scanf("%lld %lf",&a,&b);
  cn=(ll)(100.0*b);
  ans=a*cn/100;
  printf("%lld\n",ans);
  return 0;

}


#include <stdio.h>

int main(void) {
    unsigned long long A;
    double B;
    unsigned long long result;

    scanf("%lld %lf", &A, &B);

    unsigned long long BLL = (unsigned long long)(B * 100);

    result = A * BLL / 100ULL;

    printf("%lld\n", result);
    return 0;
}


#include<stdio.h>
int main(void)
{
  long long a;
  double b;
  scanf("%lld %lf",&a,&b);
  int c=b*100+0.5;
  // printf("%d\n",c);
  // printf("%lld\n",(a*c/100));
  printf("%lld\n",(long long)(a*c/100));
  return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>

int main()
{
    long int a,c=0;
    double b;

    scanf("%ld %lf",&a,&b);
    b *= a;
    c = b;
    printf("%ld",c);
    return 0;
}


#include <stdio.h>

int main(void)
{
        int a;
        double b,s;

        scanf("%d%lf",&a,&b);

        s=a*(b*100)/100;

        printf("%d\n",(int)s);
        return 0;
}


#include <stdio.h>
int main(void){
	long a;
	// long double b;
	// scanf("%ld", &a);
	// scanf("%Lf", &b);
	// printf("%ld\n", (long)(a*b));
	char b[5];
	scanf("%ld", &a);
	scanf("%s", b);
	long long_b = (b[0]-'0')*100 + (b[2]-'0')*10 + (b[3]-'0');
	printf("%ld\n", long_b);
	printf("%ld\n", a*long_b/100);
	return 0;
}


#include <malloc.h>
#include <math.h>
#include <stdio.h>
#include <string.h>

//ABC169C
int main(){
    long long a;
    long double  b;
    scanf("%lld %Lf",&a,&b);
    printf("%.0lf",a*b);
    return 0;
}


#include <stdio.h>
#include <math.h>
int main()
{
    long double A;
    long double B;
    scanf("%Le %LF",&A,&B);
    long double result;
    modfl(A*B,&result);
    printf("%.0Lf",result);
    return 0;
}


#include<stdio.h>
#include<math.h>
int main(void){
    long long int a;
    float b;
    scanf("%lld %f",&a,&b);
    long long int ans = floor(a*b);
    printf("%lld",ans);
    return 0;
}


#include <stdio.h>
typedef long long ll;

int main(void)
{
    ll a, ans;
    double b;
    scanf("%lld%lf", &a, &b);

    ans = a * b;
    printf("%lld\n", ans);
    return 0;
}


#include <stdio.h>
int main() {
    double a, b, ans;
    scanf("%lf %lf", &a, &b);
    ans = a*b;
    printf("%.0lf", ans);
}


#include<stdio.h>

int main(void){
  long a=0,d=0;
  double b=0,c=0;
  scanf("%ld",&a);
  scanf("%lf",&b);
  c=a*b;
  d=(long) c;
  printf("%ld",d);
  return 0;
}


#include<stdio.h>

int main(void){
	long long int a,c;
	double b;
	scanf("%lld %lf",&a,&b);
	c=(long long int)(b*100);
	printf("%lld",(long long int)((a*c-(a*c)%100)/100));
}


#include <stdio.h>

int main(void){
  long long int a;
  float b;
  long long int ans;
  scanf("%lld%f",&a,&b);
  ans = a*b;
  printf("%lld",ans);
  return 0;
}


#include<stdio.h>

int main()
{
   long long int a, d;
   double c;
   scanf("%lld %lf", &a, &c);
   d = a*c;
   printf("%lld\n",d);
    return 0;
}


/*
 * FileName:     C
 * CreatedDate:  2020-05-31 20:58:51 +0900
 * LastModified: 2020-05-31 21:55:06 +0900
 */

#include <stdio.h>

int main(void){
    long long int a;
    float b;
    scanf("%lld%f",&a,&b);
    printf("%lld\n",(long long int)(a*b));
    return 0;
}


#include <stdio.h>

int main(){
    double A,B;
    int C;
    scanf("%f",&A);
    scanf("%f",&B);
    C =A*B;

    printf("%d", C);

}


#include <stdio.h>

int main()
{

    long long  a;
    double b;

    scanf("%lld", &a);
    scanf("%lf", &b);
    double c =( b * 100.0);
    int z = c / 100;//1のくらいのみ
   // printf("1けため%d\n",z);
    int q = ((int)c - z*100) / 10;
    int r = ((int)c - z * 100-q*10);
  //  printf("2けため%d\n",q);
    //printf("2けため%d\n", r);

    printf("%lld", a * (long long)z + a * (long long)(q) / 10l + a * (long long)(r) / 100l);

    printf("\n");
}


#include<stdio.h>
int main(void){
  long long int A,B1;
  double B,B2;
  scanf("%d" ,&A);
  scanf("%lf",&B);
  B1=(long long int)B;
  B2=B-(double)B1;
  printf("%d",A*B1+(int)(A*(int)(B2*100))/100);
  return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MOD 1000000007
#define INF 1000000000000000000
#define PI 3.14159265359
#define ull unsigned long long
#define MYPOW_t int

int main(){
    ull a,B,hyaku,juu,iti,ans=0;
    float b;
    scanf("%lld%f",&a,&b);
    b*=100;
    B=(ull)b;
    hyaku=B/100;
    B-=hyaku*100;
    juu=B/10;
    B-=juu*10;
    iti=B;
    ans=hyaku*a+(juu*a)/10+(iti*a)/100;
    printf("%lld",ans);
    return 0;
}


#include <stdio.h>
#include <math.h>

#define MAXLEN 1000000000000000000

int main(){
    double  a,b;
    unsigned long long int ans;

    scanf("%le%le",&a,&b);

    ans=floor(a*b);
    printf("%lo",ans);
    return 0;
}


#include<stdio.h>

int main(void){
  long long  a;
  long double b;
  scanf("%lld %llf",&a,&b);

  long long  ans = a * b;

  printf("%lld\n",ans);

  return 0;
}


#include <stdio.h>
int main()
{
	long long a;
	float b;
	long long c;
	scanf("%lld %f",&a,&b);
	c=a*b;
	printf("%lld\n",c);
	return 0;
}


#include <stdio.h>
#include <malloc.h>
#include <stdlib.h>
typedef char Bool;
#define true 39
#define false 0
typedef long long int64;
typedef unsigned long long uint64;
typedef int int32;
typedef unsigned int uint32;
typedef unsigned char byte;

int main()
{

	uint64 a , b;
	double f;

	scanf("%llu %lf", &a, &f);

	uint64 c = (uint64)((double)a * f);

	printf("%llu", c);

	return 0;
}


#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main(){
    long int a;
    double b;
    scanf("%ld%lf",&a,&b);

    printf("int:%ld\n",a);
    long long int ans = 0;
    ans = (long long int)(a*b);

    printf("%lld",ans);
}


#include <stdio.h>
int main(void)
{

  long a, ans;
  double b;

  scanf("%ld%lf", &a, &b);

  ans = a * b;

  printf("%ld\n", ans);

  return 0;

}


#include <stdio.h>
int main()
{
  long long int a;
  double b;
  scanf("%d",&a);
  scanf("%lf",&b);

  printf("%d",(int)a*b);
  return 0;

}