Score: 400 points

Problem Statement

The Kingdom of Takahashi has N towns, numbered 1 through N.

There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i.

Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there.

Help the king by writing a program that answers this question.

Constraints

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

1 \leq A_i \leq N

1 \leq K \leq 10^{18}

Input

Input is given from Standard Input in the following format:

N K
A_1 A_2 \dots A_N

Output

Print the integer representing the town the king will be in if he starts at Town 1 and uses a teleporter exactly K times from there.

Sample Input 1

4 5
3 2 4 1

Sample Output 1

4

If we start at Town 1 and use the teleporter 5 times, our travel will be as follows: 1 \to 3 \to 4 \to 1 \to 3 \to 4.

Sample Input 2

6 727202214173249351
6 5 2 5 3 2

Sample Output 2

2


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdbool.h>
#include<math.h>
#include<limits.h>
#define MAX 200010
typedef long long ll;
ll N,K;
ll A[MAX];
ll loop_start=0;
ll loop_end=0;
bool bit[MAX]={false};
ll memo[MAX];

void solve(ll town){
    bit[town] = true;
    memo[++loop_end] = town;
    if(bit[A[town]] == true){
        for(ll i=1;i<loop_end;i++){
            if(memo[i] == A[town]){
                loop_start = i;
            }
        }
    }
    else solve(A[town]);
}
int main(){
    scanf("%lld %lld",&N,&K);
    for(ll i=1;i<=N;i++)
        scanf("%lld",A+i);
    solve(1);
    if(K <= loop_start) printf("%lld",memo[K]);
    else
        printf("%lld",memo[loop_start + (K-loop_start+1)%(loop_end-loop_start+1)]);
    return 0;
}

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

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>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#define ull unsigned long long int
#define ll long long
#define l long
#define sd(x) scanf("%d",x)
#define sld(x) scanf("%ld",x)
#define slld(x) scanf("%lld",x)
#define sllu(x) scanf("%llu",x)
#define ss(x) scanf("%s",x)
#define rep(x) for(book[x].onoff=0;book[x].onoff<2;book[x].onoff++)
#define min(x,y) x<y?x:y

int main(){
  int N,pos;
  sd(&N);
  ull K,v,c;
  sllu(&K);
  int A[N+1],B[200001]={};
  for(int i=1;i<=N;i++)
    sd(&A[i]);
  pos=1;
  B[pos]=1;
  for(ull u=2;u<=K+1;u++){
    pos=A[pos];
    if(u==K){
      printf("%d",pos);
      return 0;
    };
    if(B[pos]!=0){
      v=u-B[pos];
      c=B[pos]-1;
      break;
    };
    B[pos]=u;
  };
  v=((K-c)%v)+c;
  pos=1;
  for(int i=1;i<=v;i++){
    pos=A[pos];
  };
  printf("%d",pos);
};


#include<stdio.h>

int main(){
  long long n,k,point,loop,time1,time2;
  scanf("%lld%lld",&n,&k);
  long long a[n+1],b[n+1];
  for(long long i=1;i<=n;i++){
    scanf("%lld",&a[i]);
    b[i]=0;
  }

  point=1;
  b[1]=1;

  for(long long i=1;i<=n;i++){
    point=a[point];
    if(b[point]==2){
      loop=point;
      time2=i;
      break;
    }
  }

  point=1;

  if(loop==1){
    k=k%time2;
    point=1;
    for(int i=1;i<=k;i++){
      point=a[point];
    }
    printf("%lld",point);
    return 0;
  }

  for(long long i=1;i<=n;i++){
    point=a[point];
    if(point==loop){
      time1=i;
    }
  }

  k=(k-time1+1)%(time2-time1);
  point=loop;

  for(long long i=1;i<=k;i++){
    point=a[point];
  }

  printf("%lld",point);
  return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main(){
  long long N, A[200010], ans = 1;
  long long num[200010] = { 0 };
  long long K, i;
  scanf("%lld %lld", &N, &K);
  for (i = 0; i < N; i++) scanf("%lld", A + i);
  for (i = 0; i <= K; i++) {
    ans = A[ans - 1];
    if (num[ans - 1] == 0) {
      num[ans - 1] = i;
    }
    else {
      K = K % (num[ans - 1] - i) + num[ans - 1];
      break;
    }
  }
  ans = 1;
  for (i = 0; i < K; i++) {
    ans = A[ans - 1];
  }
  printf("%lld", ans);
  return 0;
}


#include <stdio.h>
#include <string.h>
int main()
{
  int n,t;
  long long int i,k;
  int a[200000];
  scanf("%d %lld",&n,&k);
  for(i=1;i<=n;i++)
  {
      scanf("%d",&a[i]);
  }
  t=a[1];
  i=1;
  while(i<k)
  {
      t=a[t];
      i++;
  }
  printf("%d",t);
}


#include <stdio.h>

int main() {
  int a, b, c, d;

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

  while (a > 0 && c > 0) {
    c = c - b;
    if (c > 0) a = a - d;
  }

  if (c <= 0)
    printf("Yes\n");
  else
    printf("No\n");

  return 0;
}

Score : 200 points

Problem Statement

Takahashi and Aoki will have a battle using their monsters.

The health and strength of Takahashi's monster are A and B, respectively, and those of Aoki's monster are C and D, respectively.

The two monsters will take turns attacking, in the order Takahashi's, Aoki's, Takahashi's, Aoki's, ...
Here, an attack decreases the opponent's health by the value equal to the attacker's strength.
The monsters keep attacking until the health of one monster becomes 0 or below. The person with the monster whose health becomes 0 or below loses, and the other person wins.

If Takahashi will win, print Yes; if he will lose, print No.

Constraints

1 \leq A,B,C,D \leq 100

All values in input are integers.

Input

Input is given from Standard Input in the following format:

A B C D

Output

If Takahashi will win, print Yes; if he will lose, print No.

Sample Input 1

10 9 10 10

Sample Output 1

No

First, Takahashi's monster attacks Aoki's monster, whose health is now 10-9=1.

Next, Aoki's monster attacks Takahashi's monster, whose health is now 10-10=0.

Takahashi's monster is the first to have 0 or less health, so Takahashi loses.

Sample Input 2

46 4 40 5

Sample Output 2

Yes


#include<stdio.h>

int main(void)
{
  int a,b,c,d;
  int s=0;

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

  while(a>0&&c>0)
  {
    if(s==0){
      a=a-d;
      s=1;
    }
    else if(s==1){
      c=c-b;
      s=0;
    }
  }
  if(s==1)
    puts("No");
  else if(s==0)
    puts("Yes");

  return 0;
}


#include<stdio.h>

int main(void){
    int Thp,Tat,Ahp,Aat;

    scanf("%d%d%d%d",&Thp,&Tat,&Ahp,&Aat);
    while((Thp>0)||(Ahp>0)){
        Ahp=Ahp-Tat;
        if(Ahp>0){
            Thp=Thp-Aat;
        }
    }
    if(Ahp<=0){
        printf("Yes\n");
    }
    else if(Ahp>0){
        printf("No\n");
    }
    return 0;
}


#include<stdio.h>

int main(void){
  int a,b,c,d;
  scanf("%d %d %d %d",&a,&b,&c,&d);
  while(1){
    if( (c=c-b) <= 0 ){
       printf("Yes");
      return 0;
    }
    else if( (a=a-d) <=0){
      printf("No");
      return 0;
    }
  }
}


#include <stdio.h>
int main()
{
    int a,b,c,d,i=0;
    scanf("%d %d %d %d",&a,&b,&c,&d);
    while(a>0&&c>0)
    {
        if(i%2==0)
        c-=b;
        else
        a-=d;
        i++;
    }
    if((i-1)%2==0)
    printf("no");
    else
    printf("yes");
}


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

#define MAXNUM 32

void save_str(int array_num, char **str) {
    int i = 0, j = 0, count = 0;
    char temp[MAXNUM];

    if(scanf("%[^\n]", temp));
    while (temp[++i] != '\0') {
      if (temp[i] == ' ') {
        count++;
        temp[i] = '\0';
      }
    }
    if (count + 1 != array_num) return;

    str[0] = &temp[0];
    for (i = 1; i < array_num; i++) {
      while (temp[++j] != '\0');
      str[i] = &temp[++j];
    }

    return;
}

int main(void) {
  int i, k, num[4];
  char **val;

  val = (char **)malloc(MAXNUM * sizeof(char *));
  for (k = 0; k < 4; k++) {
    val[k] = (char *)malloc(MAXNUM * sizeof(char));
  }
  save_str(4, val);

  for (i = 0; i < 4; i++) {
    num[i] = atoi(val[i]);
  }

  while (1) {
    if((num[0] -= num[3]) <= 0) {
      printf("No");
      break;
    } else if((num[2] -= num[1]) <= 0) {
      printf("Yes");
      break;
    }

  }

  return 0;

}


#include<stdio.h>
int main()
{
    long long int a,b,c,d;
    scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
    while(a>=0 && c>=0)
    {
        c = c - b;
        if(c<=0)
        {
            printf("Yes");break;
        }
        a = a - d;
        if(a<=0)
        {
            printf("No");break;
        }

    }
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
int main()
{
	int A,C;
	int B,D;
	scanf("%d %d %d %d",&A,&B,&C,&D);
	while(1)
	{
		C = C - B;
		if(C<=0)
		{
			printf("yes");
			break;
		}
		A = A - D;
	        if(A<=0)
	       {
			printf("no");
			break;
		}
	}

	return 0;
}


#include <stdio.h>

int main(void)
{
    int C, D;
    int TAKA, AOKI;

    scanf("%d %d %d %d", &TAKA, &AOKI, &C, &D);

    while(TAKA >= 0 && AOKI >= 0){
        AOKI -= C;
        TAKA -= D;
    }
    if (TAKA <= 0)
    {
        printf("No\n");
    }else
    {
        printf("Yes\n");
    }

    return 0;
}


#include<stdio.h>
int main(void){
  int A,B,C,D;
  scanf("%d %d %d %d",&A,&B,&C,&D);
  if(1>A || 100<A || 1>B || 100<B || 1>C || 100<C || 1>D|| 100<D){
    printf("input error");
    return 0;
  }
  do{
    C = C-B;
    A = A-D;
  }while(C<=0 || A<=0);
  if(C<=0){
    printf("Yes");
  }
  else{
    printf("No");
  }
  return 0;
}


#include <stdio.h>
int main(void){
  int A, B, C, D, e = 0;
  scanf("%d", &A);
  scanf("%d", &B);
  scanf("%d", &C);
  scanf("%d", &D);

  while(A > 0 && C > 0){
    C -= B;
    if(C <= 0) e += 1;
    A -= D;
  }
  if(e > 0) printf("Yes\n");
  else printf("No\n");
}


#include<stdio.h>
int main()
{
     long long a,b,c,d;
while(scanf("%lld %lld %lld %lld",&a,&b,&c,&d)!=EOF)
    {
        if(a+b>c+d)
        {
            printf("yes\n");
            }
        else if(a+b<c+d)
        {
            printf("no\n");
            }
        }
    return 0;
    }


#include <stdio.h>
#include<string.h>
int main (void){
int A,B,C,D;
scanf("%d%d%d%d",&A,&B,&C,&D);
if(A/D>C/B){
    printf("Yes");
}
else if(A/D==C/B){
    if(A%D!=0){
        printf("Yes");
    }else{
    printf("No");
}
}
        else if(A/D+1==C/B){
    if(C%B==0){
    printf("Yes");
    }else{
    printf("No");
}
}else{
    printf("No");
}
}


#include <stdio.h>

int main(){
	int tt, tk, at, ak;

	scanf("%d %d %d %d", &tt, &tk, &at, &ak);

	while(1){
		at=at-tk;
		if(at<=0);{
			break;
		}
		tt=tt-ak;
		if(tt<=0){
			break;
		}
	}
	if(at<=0){
		printf("Yes");
	}else{
		printf("No");
	}

	return 0;
}


#include <stdio.h>
int main()
{
   int n=0,i,j,k,l;
 scanf("%d %d %d %d",&i,&j,&k,&l);
 if(i-l<=0||l-i<=0||j-k<=0||k-j<=0)
    printf("No");
 else
    printf("Yes");
           return 0;
}


#include <stdio.h>
int main()
{
   int n=0,i,j,k,l;
 scanf("%d %d %d %d",&i,&j,&k,&l);
 if(k-i==0||j-i==0)
    printf("No");
 else
    printf("Yes");
           return 0;
}


	#include<stdio.h>

	int main(){
		int a,b,c,d;
		scanf("%d %d %d %d",&a,&b,&c,&d);
		while(a > 0 && b > 0){
			a = a - d;
			c = c - b;
			if(c <= 0){
				printf("Yes");
				break;
			}
			else{
				printf("No");
			}
		}

	}


#include<stdio.h>

int main(){

  int a,b,c,d;

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

while(a > 0){
  c-=b;
  if(c <= 0) break;
  a-=d;
}
if(a > 0) printf("Yes\n");
else printf("No\n");

  return 0;
}


#include<stdio.h>
int main()
{
	int A,B,C,D,X,Y;
	scanf("%d %d %d %d",&A,&B,&C,&D);
	X=A-B;
	Y=C-D;
	if(Y<=0){
		printf("NO\n");
	}
	else{
		printf("YES\n");
	}
	return 0;
}


#include <stdio.h>

int main(void){
  int A,B,C,D;
  scanf("%d",&A);
  scanf("%d",&B);
  scanf("%d",&C);
  scanf("%d",&D);
  while(1){
    C-=B;
    if(C<=0){
      printf("Yes");
      return 0;
    }
    A-=D;
    if(A<=0){
      printf("No");
      return 0;
    }
  }
  return 0;
}


#include<stdio.h>
int main(){
  int t_a,t_h,a_a,a_h;
  int win;
  while(1){
    a_h=a_h-t_a;
    if(a_h<=0){
      win=1;
      break;
    }
    t_h=t_h-a_a;
    if(t_h<=0){
      win=0;
      break;
    }
  }
  if(win){
    printf("Yes");
  }else{
    printf("No");
  }
  return 0;
}


#include<stdio.h>

int main(){
  int t_tairyoku,t_kougeki,a_tairyoku,a_kougeki;
  int i,k;
  scanf("%d %d %d %d",&t_tairyoku,&t_kougeki,&a_tairyoku,&a_kougeki);

  for(i=0;i<100;i++){
    a_tairyoku=a_tairyoku-t_kougeki;
    if(a_tairyoku<=0){
      k=1;
      break;
    }
    t_tairyoku=t_tairyoku-a_kougeki;
    if(t_tairyoku<=0){
      k=2;
      break;
    }
  }
  if(k==1)
    printf("Yes");
  else
    printf("No");
}


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

int ASC(const void *a, const void *b) {
	return *(int *)b - *(int *)a;//降順
}
int GCD(int a, int b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

int main(void)
{
	int a,b,c,d;
	scanf("%d%d%d%d",&a,&b,&c,&d);
	int ahp = a / d;
	int chp = c / b;
	if (a%d > 0)	ahp++;
	if (c%b > 0)	chp++;
	if (ahp < chp)
		printf("No");
	else
		printf("Yes");
	return 0;
}


#include <stdio.h>

#define NUM (2019)
#define SIZE (200000)

int count[NUM];

main()
{
        int n;
        int c;
        int buf[SIZE];
        int md[SIZE + 1];
        int tmp;
        int tens;
        int i, j;
        int res;

        n = 0;
        while((c = getchar()) != EOF) {
                buf[n] = c - '0';
                ++n;
        }

        tmp = 0;
        tens = 1;
        for(i = n - 1; i >= 0; --i) {
                tmp = (buf[i] * tens + tmp) % NUM;
                md[i] = tmp;
                tens = (tens * 10) % NUM;
        }
        md[n] = 0;

        for(i = 0; i <= n; ++i) {
                count[md[i]]++;
        }
        res = 0;
        for(i = 0; i < NUM; ++i) {
                if(count[i] > 0) {
                        res += count[i] - 1;
                }
        }
#if 0
        for(i = 0; i < n; ++i) {
                for(j = i + 1; j <= n; ++j) {
                        if(md[i] == md[j]) {
                                res++;
                        }
                }
//              count[md[i]]++;
        }
        res = count[0];
        for(i = 1; i < NUM; ++i) {
                if(count[i] > 0) {
                        res += count[i] - 1;
                }
        }
#endif
        printf("%d", res);
}

Score : 400 points

Problem Statement

Given is a string S consisting of digits from 1 through 9.

Find the number of pairs of integers (i,j) (1 ≤ i ≤ j ≤ |S|) that satisfy the following condition:

Condition: In base ten, the i-th through j-th characters of S form an integer that is a multiple of 2019.

Constraints

1 ≤ |S| ≤ 200000

S is a string consisting of digits from 1 through 9.

Input

Input is given from Standard Input in the following format:

S

Output

Print the number of pairs of integers (i,j) (1 ≤ i ≤ j ≤ |S|) that satisfy the condition.

Sample Input 1

1817181712114

Sample Output 1

3

Three pairs - (1,5), (5,9), and (9,13) - satisfy the condition.

Sample Input 2

14282668646

Sample Output 2

2

Sample Input 3

2119

Sample Output 3

0

No pairs satisfy the condition.


#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#define F(i,a,n) for(int i=a; i<n; i++)

int compare(const void *b1, const void *b2){ // 昇順
  if(*(int*)b1 > *(int*)b2) return 1;
  else if(*(int*)b1 < *(int*)b2) return -1;
  else return 0;
}

int main(){
  char cs[20010];
  scanf("%s",cs);
  int n=strlen(cs);
  int a[n];
  F(i,0,n){
    char ss[2];
    strncpy(ss,cs+i,1);
    a[i]=atoi(ss);
  }
  int tmod[n+1];
  int t10[n+1];
  tmod[n]=0;
  t10[n]=1;
  for(int i=n-1; i>=0; i--){
    if(i==n-1) t10[i]=1;
    else t10[i]=(t10[i+1]*10)%2019;
    tmod[i]=(tmod[i+1]+t10[i]*a[i])%2019;
  }
  int count[n+1];
  F(i,0,n+1){
    count[i]=0;
  }
  int iter=0;
  qsort(tmod,n+1,sizeof(int),compare);
  F(i,0,n){
    if(tmod[i]==tmod[i+1]){
      count[iter]++;
    }else{
      iter++;
    }
  }
  int ans=0;
  F(j,0,n){
    ans+=(count[j]*(count[j]+1))/2;
  }
  printf("%d\n",ans);
  return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define N 200000

int main(){
    char S[N+1];
    scanf("%s",S);

    long long count = 0;
    long long Slen = strlen(S);
    long long T[Slen+1];
    long long C[2019];
    for(int i = 0;i<2019;i++) C[i]=0;
    T[Slen]=0;

    for(int i = Slen-1;i>-1;i--) T[i] = (T[i+1] + (long long)pow(10,Slen-1-i)*(S[i]-'0')) % 2019;
    for(int i = 0;i<Slen+1;i++) C[T[i]]++;
    for(int i = 0;i<2019;i++) count+=(C[i]-1)*(C[i])/2.0;
    printf("%lld\n",count);
    return 0;
}


#include<stdio.h>
#include<string.h>
#include<math.h>
int main(){
  long long s;
  scanf("%lld",&s);

  long long x=1,y=1;
  while(s/x>=10){
    x*=10;y++;}

  long long i,j,ans=0,t;
  for(i=pow(10,y);i>=1;i/=10)
    for(j=1;j<=i;j*=10){
     t=(s%i)/j;
     if(t%2019==0&&t!=0)ans++;
    }
  printf("%lld\n",ans);
return 0;}


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

char buff[200000+1];
int ans = 0;

int num(char c) { return c-'0'; }
int main() {
    scanf("%s", buff);
    //for (int i=4; i<200000; i++) buff[i]='0';
    //buff[200000]=0;
    int len = strlen(buff);

    for (int i=0; i+4<=len; i++) {
        int rest = num(buff[i])*100
            + num(buff[i+1])*10
            + num(buff[i+2]);
        printf("i=%d\n", i);
        for (int pos=i+3; pos<len; pos++) {
            //printf("rest=%d\n", rest);
            rest = rest*10+num(buff[pos]);
            rest %= 2019;
            if (rest==0) ans++;
        }
    }
    printf("%d\n", ans);

}


#include<stdio.h>
#include<math.h>
int main(){
    int k=0,count=0;
    long long S;
    scanf("%lld",&S);
    while(pow(10,k)<=S){
        k++;
    }
    for(int i=1;i<k;i++){
        for(int j=i+3;j<=k;j++){
            long long s=S;
            long long sj=S/pow(10,j);
            s-=sj*pow(10,j);
            s/=pow(10,i-1);
            if(s%2019==0){
                count++;
            }
        }
    }
    printf("%d",count);
    return 0;
}


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

int main (void) {
    char s[200001];
    scanf("%s", s);

    long long ans = 0;
    long long s_num;
    int s_len = strlen(s);

    for ( int i=0; i<s_len; i++ ) {
        s_num = strtol(&s[i], NULL, 10);
        while ( s_num > 0 && s_num >= 2019 ) {
            if ( s_num % 2019 == 0 )
                ans++;
            s_num /= 10;
        }
    }

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


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

int main(int argc, char const *argv[])
{
    int i, j, k, len, count;
    char s[200001], tmp[200001];

    scanf("%s", s);
    len = strlen(s);
    count = 0;
    for(i = len-1; i >= 0; i--) {
        for(j = len-1; j > i; j--) {
            for(k = 0; k < j-i+1; k++) {
                tmp[k] = s[i+k];
            }
            tmp[k] = '\0';
            if(!(atoi(tmp) % 2019)) count++;
        }
    }
    printf("%d\n", count);
    return 0;
}


#include<stdio.h>
#include<stdlib.h>
#define inf 100000000000
#define max (N-1)*50
#define mi(x,v) x<v?x:v
#define ll long long int
long N,M,S;
int T_n[55] = {};
int Used[55][2510];
ll city[55][2510];
ll ans[55];
int a=1;

typedef struct {
	int to,cost;
    ll time;
}train;
train* T[55];

int dijkstra() {
	for (int i = 0; i < N; i++) {
		ans[i] = -1;
		for (int j = 0; j <= max; j++) {
			city[i][j] = inf;
			Used[i][j] = 1;
		};
	};
	ans[0] = 0;
	city[0][S] = 0;
	ll min;
	int  mati=0, money=0, co=1;
	while (1) {
		min = inf;
		for (int i = 0; i < N; i++) {
			for (int j = 0; j <= max; j++) {
				if (min > city[i][j] && Used[i][j]==1) {
						min = city[i][j];
						mati = i;
						money = j;
				};
			};
		};
		if (ans[mati]==-1) {
			ans[mati] = min;
			co++;
			if (co == N) {
				return 0;
			};
		};
		for (int i = 0; i <= money; i++) {
			Used[mati][i] = 0;
		};
		for (int i = 0; i < T_n[mati]; i++) {

			if (money >= T[mati][i].cost
				 && T[mati][i].time + min <city[T[mati][i].to][mi(money - T[mati][i].cost,max)] )
            {
					city[T[mati][i].to][mi(money - T[mati][i].cost,max)] = T[mati][i].time + min;

			};
		};
	};
};

int main() {
	scanf("%ld %ld %ld", &N, &M, &S);
  if(S>=a)return  0;
	S = mi(S, max);
	int u, v, a, b,c,d;
	for (int i = 0; i < M; i++) {
		scanf("%d %d %d %d", &u, &v, &a, &b);
		u--; v--;
		T[u] = (train *)realloc(T[u], sizeof(train) * (T_n[u] + 1));
		T[v] = (train *)realloc(T[v], sizeof(train) * (T_n[v] + 1));
		T[u][T_n[u]] =(train){ v,a,b };
		T[v][T_n[v]] = (train){ u,a,b };
		T_n[u]++;
		T_n[v]++;
	};
	for (int i = 0; i < N; i++) {
		scanf("%d %d", &c, &d);
		T[i] = (train *)realloc(T[i], sizeof(train) * (T_n[i] + 1));
		T[i][T_n[i]] = (train){ i,-1*c,d };
		T_n[i]++;
	};
	if(dijkstra()!=0)return 2;
	for (int i = 1; i < N; i++) {
		printf("%lld\n", ans[i]);
	};
};

Score : 500 points

Problem Statement

There are N cities numbered 1 to N, connected by M railroads.

You are now at City 1, with 10^{100} gold coins and S silver coins in your pocket.

The i-th railroad connects City U_i and City V_i bidirectionally, and a one-way trip costs A_i silver coins and takes B_i minutes.
You cannot use gold coins to pay the fare.

There is an exchange counter in each city. At the exchange counter in City i, you can get C_i silver coins for 1 gold coin.
The transaction takes D_i minutes for each gold coin you give.
You can exchange any number of gold coins at each exchange counter.

For each t=2, ..., N, find the minimum time needed to travel from City 1 to City t. You can ignore the time spent waiting for trains.

Constraints

2 \leq N \leq 50

N-1 \leq M \leq 100

0 \leq S \leq 10^9

1 \leq A_i \leq 50

1 \leq B_i,C_i,D_i \leq 10^9

1 \leq U_i < V_i \leq N

There is no pair i, j(i \neq j) such that (U_i,V_i)=(U_j,V_j).

Each city t=2,...,N can be reached from City 1 with some number of railroads.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M S
U_1 V_1 A_1 B_1
:
U_M V_M A_M B_M
C_1 D_1
:
C_N D_N

Output

For each t=2, ..., N in this order, print a line containing the minimum time needed to travel from City 1 to City t.

Sample Input 1

3 2 1
1 2 1 2
1 3 2 4
1 11
1 2
2 5

Sample Output 1

2
14

The railway network in this input is shown in the figure below.

In this figure, each city is labeled as follows:

The first line: the ID number i of the city (i for City i)

The second line: C_i / D_i

Similarly, each railroad is labeled as follows:

The first line: the ID number i of the railroad (i for the i-th railroad in input)

The second line: A_i / B_i

You can travel from City 1 to City 2 in 2 minutes, as follows:

Use the 1-st railroad to move from City 1 to City 2 in 2 minutes.

You can travel from City 1 to City 3 in 14 minutes, as follows:

Use the 1-st railroad to move from City 1 to City 2 in 2 minutes.

At the exchange counter in City 2, exchange 3 gold coins for 3 silver coins in 6 minutes.

Use the 1-st railroad to move from City 2 to City 1 in 2 minutes.

Use the 2-nd railroad to move from City 1 to City 3 in 4 minutes.

Sample Input 2

4 4 1
1 2 1 5
1 3 4 4
2 4 2 2
3 4 1 1
3 1
3 1
5 2
6 4

Sample Output 2

5
5
7

The railway network in this input is shown in the figure below:

You can travel from City 1 to City 4 in 7 minutes, as follows:

At the exchange counter in City 1, exchange 2 gold coins for 6 silver coins in 2 minutes.

Use the 2-nd railroad to move from City 1 to City 3 in 4 minutes.

Use the 4-th railroad to move from City 3 to City 4 in 1 minutes.

Sample Input 3

6 5 1
1 2 1 1
1 3 2 1
2 4 5 1
3 5 11 1
1 6 50 1
1 10000
1 3000
1 700
1 100
1 1
100 1

Sample Output 3

1
9003
14606
16510
16576

The railway network in this input is shown in the figure below:

You can travel from City 1 to City 6 in 16576 minutes, as follows:

Use the 1-st railroad to move from City 1 to City 2 in 1 minute.

At the exchange counter in City 2, exchange 3 gold coins for 3 silver coins in 9000 minutes.

Use the 1-st railroad to move from City 2 to City 1 in 1 minute.

Use the 2-nd railroad to move from City 1 to City 3 in 1 minute.

At the exchange counter in City 3, exchange 8 gold coins for 8 silver coins in 5600 minutes.

Use the 2-nd railroad to move from City 3 to City 1 in 1 minute.

Use the 1-st railroad to move from City 1 to City 2 in 1 minute.

Use the 3-rd railroad to move from City 2 to City 4 in 1 minute.

At the exchange counter in City 4, exchange 19 gold coins for 19 silver coins in 1900 minutes.

Use the 3-rd railroad to move from City 4 to City 2 in 1 minute.

Use the 1-st railroad to move from City 2 to City 1 in 1 minute.

Use the 2-nd railroad to move from City 1 to City 3 in 1 minute.

Use the 4-th railroad to move from City 3 to City 5 in 1 minute.

At the exchange counter in City 5, exchange 63 gold coins for 63 silver coins in 63 minutes.

Use the 4-th railroad to move from City 5 to City 3 in 1 minute.

Use the 2-nd railroad to move from City 3 to City 1 in 1 minute.

Use the 5-th railroad to move from City 1 to City 6 in 1 minute.

Sample Input 4

4 6 1000000000
1 2 50 1
1 3 50 5
1 4 50 7
2 3 50 2
2 4 50 4
3 4 50 3
10 2
4 4
5 5
7 7

Sample Output 4

1
3
5

The railway network in this input is shown in the figure below:

Sample Input 5

2 1 0
1 2 1 1
1 1000000000
1 1

Sample Output 5

1000000001

The railway network in this input is shown in the figure below:

You can travel from City 1 to City 2 in 1000000001 minutes, as follows:

At the exchange counter in City 1, exchange 1 gold coin for 1 silver coin in 1000000000 minutes.

Use the 1-st railroad to move from City 1 to City 2 in 1 minute.


Score : 100 points

Problem Statement

Print the circumference of a circle of radius R.

Constraints

1 \leq R \leq 100

All values in input are integers.

Input

Input is given from Standard Input in the following format:

R

Output

Print the circumference of the circle.
Your output is considered correct if and only if its absolute or relative error from our answer is at most 10^{-2}.

Sample Input 1

1

Sample Output 1

6.28318530717958623200

Since we accept an absolute or relative error of at most 10^{-2}, 6.28 is also an acceptable output, but 6 is not.

Sample Input 2

73

Sample Output 2

458.67252742410977361942


#include<stdio.h>
int main(void){
  int X,Y,Z,T;
  scanf("%d",&X);
  scanf("%d",&Y);
  scanf("%d",&Z);
  T = X;
  X = Y;
  Y = T;
  T = Z;
  Z = X;
  X = T;
  printf("%d",X);
  printf("%d",Y);
  printf("%d",Z);
  return 0;
}


#include<stdio.h>
#include<math.h>
int main()
{
	double r;
	scanf("%lf",&r);
	printf("%lf\n",2*r*M_PI);
	return 0;
}


#include<stdio.h>
int main()
{
    int R;
    double circumference;
    scanf("%d",&R);
    if(1<= R && R<=100){
            circumference=2*3.1416*R;
            printf("%.2lf ",circumference);
    }
    return 0;
}


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

int main(void) {
    int R;
    double cirLong;
    scanf("%d", &R);

    cirLong = 2 * R * M_PI;

    printf("%.15f", cirLong);
    return 0;

}


#include <stdio.h>

int main(){
double a,p=3.14159;
scanf("%lf",&a);
printf("%f",a*p*2);
}


#include<stdio.h>
int main()
{
	int r;
	float f;
	f=(22.0/7)*2;
	scanf("%d",&r);
	printf("%f",f*r);
	return 0;
}


#include <stdio.h>

int main(void){
  int N, M, i;
  scanf("%d %d\n",&N,&M);
  int A[M];
  for(i=1;i<=M;i++){
    scanf("%d,",&A[i]);
  }

  for(i=1;i<=M;i++){
    N=N-A[i];
  }

  if(N<0){
    printf("-1\n");
  }else{
    printf("%d\n",N);
  }
}


#include <stdio.h>

int main()
{
  int iR;
  float fAns;

  scanf("%d", &iR);

  fAns = iR * 2 * 3.1412;

  printf("%.3f\n", fAns);
}


#include <stdio.h>

double main(){
 double aaa;
 int R;
 scanf("%d",&R);
 aaa = 2.0 * 3.14 * R;
 printf("%f¥n",aaa);
 return 0;
}


#include<stdio.h>

int main(void){
  int r;
  scanf("%d",&r);
  printf("%lf\n", 2*3.14159265*r);
}


#include<stdio.h>
int main()
{
    int vacation,assignment,i,arr[20],sum=0,ans;
    scanf("%d %d",&vacation,&assignment);
    for(i=0;i<assignment;i++)
    {
        scanf("%d",&arr[i]);
        sum=sum+arr[i];
    }
    ans=vacation-sum;
    if(ans<0)
    {
        printf("%d",-1);
    }
    else
    {
        printf("%d",ans);
    }
return 0;
}


#include<stdio.h>

int main()
{
  int a;
  float b;
  a=2;
  b=a*a*3.1415;
  return 0;
}


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

  b = 2 * a * 3.14;

  printf("%4.2f\n",b);

  return 0;
}


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

int main()
{
    double r;
    scanf("%lf", &r);
    r = 2 * M_PI * r;
    printf("%lf", r);
    return 0;
}


#include<stdio.h>

int main(void) {
	int n, m, i;
	int a[1000000];

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

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

	for (i = 0; i < m; i++) {
		n -= a[i];
		if (n < 0) {
			printf("-1\n");
			return 0;
		}
	}

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

	return 0;
}


#include<stdio.h>
int main()
{
    int R;
    scanf("%d",&R);
    double C;
    C = 2*3.14159*R;
    printf("%.2lf\n",C);
}


#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<math.h>
#define PI 3.141592653589793238462
int main() {
	int r;
	scanf("%d", &r);
	printf("%.20f", 2 * PI * r);

	return 0;

}


//set many funcs template
//Ver.20190820
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<time.h>
#include<assert.h>
#define inf 1072114514
#define llinf 4154118101919364364
#define mod 1000000007
#define pi 3.1415926535897932384

int max(int a,int b){if(a>b){return a;}return b;}
int min(int a,int b){if(a<b){return a;}return b;}
int zt(int a,int b){return max(a,b)-min(a,b);}
int round(int a,int b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
int ceil(int a,int b){if(a%b==0){return a/b;}return (a/b)+1;}
int gcd(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;}
int lcm(int a,int b){int c=gcd(a,b);a/=c;return a*b;}
int nCr(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
int nHr(int a,int b){return nCr(a+b-1,b);}
int fact(int a){int i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
int pow(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
int dsum(int x){int r=0;while(x){r+=(x%10);x/=10;}return r;}
int dsumb(int x,int b){int r=0;while(x){r+=(x%b);x/=b;}return r;}
int sankaku(int x){return ((1+x)*x)/2;}
void swap(int *a,int *b){int c;c=(*a);(*a)=(*b);(*b)=c;}
long long llmax(long long a,long long b){if(a>b){return a;}return b;}
long long llmin(long long a,long long b){if(a<b){return a;}return b;}
long long llzt(long long a,long long b){return llmax(a,b)-llmin(a,b);}
long long llround(long long a,long long b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
long long llceil(long long a,long long b){if(a%b==0){return a/b;}return (a/b)+1;}
long long llgcd(long long a,long long b){long long c;while(b!=0){c=a%b;a=b;b=c;}return a;}
long long lllcm(long long a,long long b){long long c=llgcd(a,b);a/=c;return a*b;}
long long llnCr(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
long long llnHr(long long a,long long b){return llnCr(a+b-1,b);}
long long llfact(long long a){long long i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
long long llpow(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
long long lldsum(long long x){long long r=0;while(x){r+=(x%10);x/=10;}return r;}
long long lldsumb(long long x,long long b){long long r=0;while(x){r+=(x%b);x/=b;}return r;}
long long llsankaku(long long x){return ((1+x)*x)/2;}
void llswap(long long *a,long long *b){long long c;c=(*a);(*a)=(*b);(*b)=c;}
double dbmax(double a,double b){if(a>b){return a;}return b;}
double dbmin(double a,double b){if(a<b){return a;}return b;}
double dbzt(double a,double b){return dbmax(a,b)-dbmin(a,b);}
void dbswap(double *a,double *b){double c;c=(*a);(*a)=(*b);(*b)=c;}
void chswap(char *a,char *b){char c;c=(*a);(*a)=(*b);(*b)=c;}
int sortfncsj(const void *a,const void *b){if(*(int *)a>*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int sortfnckj(const void *a,const void *b){if(*(int *)a<*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int llsortfncsj(const void *a,const void *b){if(*(long long *)a>*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int llsortfnckj(const void *a,const void *b){if(*(long long *)a<*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int dbsortfncsj(const void *a,const void *b){if(*(double *)a>*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}
int dbsortfnckj(const void *a,const void *b){if(*(double *)a<*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}
int strsortfncsj(const void *a,const void *b){return strcmp((char *)a,(char *)b);}
int strsortfnckj(const void *a,const void *b){return strcmp((char *)b,(char *)a);}
int chsortfncsj(const void *a,const void *b){if(*(char *)a>*(char *)b){return 1;}if(*(char *)a==*(char *)b){return 0;}return -1;}
int chsortfnckj(const void *a,const void *b){if(*(char *)a<*(char *)b){return 1;}if(*(char *)a==*(char *)b){return 0;}return -1;}

void shuffledget(int x[],int n){
    int i,b[524288],p,c;
    for(i=0;i<n;i++){
        b[i]=i;
    }
    for(i=n;i>=1;i--){
        p=rand()%i;
        c=b[i-1];b[i-1]=b[p];b[p]=c;
    }
    for(i=0;i<n;i++){
        scanf("%d",&x[b[i]]);
    }
}

int dx4[4]={1,-1,0,0};
int dy4[4]={0,0,1,-1};
int dx8[8]={-1,-1,-1,0,0,1,1,1};
int dy8[8]={-1,0,1,-1,1,-1,0,1};

int search(int x,int a[],int n){
    int st=0,fi=n-1,te;
    while(st<=fi){
        te=(st+fi)/2;
        if(a[te]<x){st=te+1;}else{fi=te-1;}
    }
    return st;
}

void prarr(int arr[],int n){
  int i;
  for(i=0;i<n;i++){
    if(i){printf(" ");}
    printf("%d",arr[i]);
  }
  printf("\n");
  return;
}

void getperm(int a[],int n){
  int i,p;
  for(i=0;i<n;i++){
    a[i]=i;
  }
  for(i=n-1;i>=1;i--){
    p=rand()%(i+1);
    swap(&a[p],&a[i]);
  }
}

typedef struct{
int val;
int node;
}sd;

int sdsortfnc(const void *a,const void *b){
if(((sd*)a)->val < ((sd*)b)->val){return -1;}
if(((sd*)a)->val > ((sd*)b)->val){return 1;}
return 0;
}

void coordinate_comp(int a[],int n){
  int i,c=0;
  sd dat[524288];
  for(i=0;i<n;i++){
    dat[i].val=a[i];
    dat[i].node=i;
  }
  qsort(dat,n,sizeof(dat[0]),sdsortfnc);
  a[dat[0].node]=c;
  for(i=1;i<n;i++){
    if(dat[i-1].val!=dat[i].val){c++;}
    a[dat[i].node]=c;
  }
}

int main(void){
  double r;
  scanf("%lf",&r);
  printf("%.12lf\n",r*2.0*pi);
  return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#define pi 3.1415926535897932384626433832795

int main(){

 long long int N;
  scanf("%lld",&N);

/*
  char A[];
  scanf("%s",A);
  */

  /*
  int A[N];
  int i;
  for(i=0;i<N;i++){
   scanf("%d",&A[i]);
   }
  */
printf("%lf",(double)(N)*2.0*pi);

 return(0);
 }


#include<stdio.h>

int main(void)
{
    int r;
    double ans=0;

    scanf("%d",&r);
    ans=r*2*3.1415926535897;

    printf("%.2f\n",ans);

    return 0;

}


#include "stdio.h"
int main()
{
  int r;
  scanf ("%d",&r);
  float c = (2*r*3.14159);
  printf ("%f\n", c);
  return 0;
}


#include <stdio.h>

int main(){
	double R;
	scanf("%lf",&R);

	double L=R*3.14;
	printf("%lf",L);
	return 0;
}


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

int main(void) {
	//printf("hello\n");
	int x;
	double a;

	scanf("%d", &x);
	a = (double)x;
	printf("%lf", a * 2 * 3.141592);
	return 0;
}


#include "stdio.h"

int main(){
  int a;
  double pi = 3.1415;
  scanf("%d", &a);
  printf("%lf", 2 * pi * a);
  return 0;
}


#include<stdio.h>
#include<math.h>
double k=atan(1)*4;
int main()
{
	int r;
	scanf("%d", &r);
	double x=2*k*r;
	printf("%.10f", x);
}


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

int main(){

  int R;
  scanf("%d",&R);
  printf("%f",M_PI*2*R);

  return 0;

}


#include<stdio.h>
#include<math.h>
int main(){
  int R;
  scanf("%d",&R);
  printf("%f",2*R*M_PI);
  return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define yes "Yes\n"
#define no "No\n"
int r;
//int m,n;
//int i,j,k,l;
//int a,b,c,d,e,f,g;
//int sum,total;
//long long int ;
//float ;
//double ;
//char a[101],b[101],s[101],t[101],u[101];
int main(void){
    scanf("%d",&r);
    printf("%f",2*r*M_PI);
    return 0;
}


#include <stdio.h>

int main(){
  int r;
  scanf("%d",&r);
  printf("%d\n",6.283*r);
  return 0;
}


#include <stdio.h>

int main(void)
{
	double r;

	scanf("%lf", &r);

	printf("%.2lf", r * 3.141592 * 2.0);
	return 0;
}


#include<stdio.h>

int main(void){
	int r;

	scanf("%d",&r);

	printf("%lf\n",r*3.1415*2);

	return 0;

}


#include <stdio.h>
int main(void)
{
  int N;
  scanf ("%d",&N);
  if (N/100||N%100-N%10||N%10==0) printf ("Yes");
  else printf ("No");

}

Score : 100 points

Problem Statement

Given is a three-digit integer N. Does N contain the digit 7?

If so, print Yes; otherwise, print No.

Constraints

100 \leq N \leq 999

Input

Input is given from Standard Input in the following format:

N

Output

If N contains the digit 7, print Yes; otherwise, print No.

Sample Input 1

117

Sample Output 1

Yes

117 contains 7 as its last digit.

Sample Input 2

123

Sample Output 2

No

123 does not contain the digit 7.

Sample Input 3

777

Sample Output 3

Yes


#include <stdio.h>

int main()
{
  int n;

  scanf("%d",&n );
  if(n/100 == 7)
    printf("Yes");
  else if( (n%100)/10 == 7)
    printf("Yes");
  else if( (n%100)%10 == 7)
    printf("Yes");
  else
    printf("No");

  return 0;
}


#include<stdio.h>
int main(void){
  long n,k,s;
  scanf("%ld",&n);
  k=(n-n%15)/15;
  s=(k*(k+1))/2;
  k=60*k*s;
  switch(n%k){
    case 0:k=k;break;
    case 1:k=k+1;break;
    case 2:
    case 3:k=k+3;break;
    case 4:
    case 5:
    case 6:k=k+7;break;
    case 7:k=k+14;break;
    case 8:
    case 9:
    case 10:k=k+22;break;
    case 11:
    case 12:k=k+33;break;
    case 13:k=k+46;break;
    case 14:k=k+60;break;
  }
  printf("%ld",k);
 return 0;
}


#include <stdio.h>

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

    if (n % 10 == 7) printf("Yes\n");
    else printf("No\n");

    return 0;
}


#include <stdio.h>
#define N 6
int main(void)
{
    int n,i;
    scanf("%d",&n);
    for(i=0;i<3;i++){
        if(n%10 == 7){
            printf("Yes");
            return 0;
        }
        n=n/10;
    }
    printf("No");
}


#include <stdio.h>

int main(void) {
  int N;
  scanf("%d", &N);
  int shou1;
  int amari;
  int shou2;
  shou1 = N / 100;
  amari = N % 100;
  shou2 = amari / 10;
  amari = amari % 10;
  if (shou1 == 7 || shou2 == 7 || amari == 7) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }
  return 0;
}


#include <stdio.h>

int main(void){
  int n;
  int a;
  scanf("%d",&n);
  for(int i=0;i<3;i++){
    if(n%10==7){
      printf("Yes\n");
      return 0;
    }
    else n /=10;
  }
  printf("No\n");
  return 0;
}


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

int main(void)
{
  int n, n3, n2, n1;
  scanf("%d", &n);
  n3 = n / 100;
  n2 = (n - n3*100) / 10;
  n1 = n - n3*100 - n2*10;

  if(n1 == 7 || n2 == 7 || n3 == 7){
    printf("Yes\n");
  }
  else{
    printf("No\n");
  }

  return 0;
  }


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

int main() {
	int N;
	scanf("%d", &N);
	int t;
	while (1) {
		if (N / 100 == 7) {
			printf("Yes");

			break;
		}
		else {
			t = N / 100;
			N = N - 100 * t;
		}
		if (N / 10 == 7) {
			printf("Yes");
			break;
		}
		else {
			t = N / 10;
			N = N - 10 * t;
		}
		if (N == 7) {
			printf("Yes");
			break;
		}
		else {
			printf("No");
			break;
		}
	}
	return 0;
}


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

    if(100<=a && a<=999)
    {
        b=a%10;
        if(b==7)
        {
            printf("Yes\n%d contains 7 as its last digit.\n", a);
        }

        else
        printf("No\n%d does not contain the digit 7.\n", a);
    }

    return 0;
}


#include<stdio.h>

main()
{
    int n,flag=0,res;
    scanf("%d",&n);

    while(n!=0)
    {
        res = n%10;
        n/=10;
        if(res==7)
        {
            flag=1;
            break;
        }
    }
    if(flag)
        printf("Yes");
    else
        printf("No");
}


#include <stdio.h>
int main(void) {
	char s[4];
	scanf("%s", s);
	if (s[0] == '7' || s[1] ==' 7' || s[2] == '7') puts("Yes");
	else puts("No");
	return 0;
}


#include<stdio.h>
int main(void) {
	char s[3];
	scanf("%s", s);
	if (s[0] =='7' || s[1] =='7' || s[2] == '7') printf("Yes");
	else { printf("No");
	}

	return 0;
}


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

int main()
{
    int i,flag=0;
    char digit[4];
    scanf("%s",digit);
    for(i=0;i<3;i++)
    {
        if(digit[i]=='7')flag++;
    }
    if(flag==0)printf("No");
    else printf("Yes");
    return 0;
}


/*
* @Author: Kabid
* @Date:   2020-04-16 00:45:39
*/

#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#define in(x)  scanf("%d", &x);
#define ins(x) scanf("%s", &x);
#define out(x) printf("%d", x);
#define outs(x) printf("%s", x);
#define _ putchar(' ');
#define lin puts("");

int t,i,j=0,k,l,x=0,r,la,lb;
int c=0,m=1,ci=0,ca=0,cb=0;
char s[100001];
char sa[501],sb[501];
int a[1001],b[1001]={0},e[101]={0},g[101]={0},d;
int main(){
	in(x)
	sprintf(s,"%d",x);
	l=strlen(s);
	for(i=0;i<l;i++){
		if(s[i]=='7'){
			j=1;
			//puts("dkfjuds");
		}
	}
	if(j)puts("Yes");
	else puts("No");
	//puts(s);
	//putchar(s[2]);lin
	//out(s[2]-'7')

    return 0;
 }


#include <stdio.h>

int main(void) {
  int n,d,check;
  scanf("%d",&n);
  while(d!=7&&n>0){
    d=n%10;
    n=n/10;
  }
  if(d==7)
    printf("Yes");
  if(d!=7)
    printf("No");
}


#include <stdio.h>

int main(void) {
  int N, o, t, s;
  scanf("%d", &N);
  for (int i=0;i<4; i++){
    o = N%10;
    t = N/10%10;
    s = N/100%10;
  }
  if (o == 7 || t == 7 || s == 7)
    printf("Yes");
  else
    printf("No");
  return 0;
}


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

int main()
{
    char s[4];
    gets(s);
    if(s[0]=='7'||s[1]=='7'||s[2]=='7')
       puts("Yes");
    else
        puts("No");

    return 0;
}


#include <stdio.h>
int main(){
	long long int n,threes,fives,fifteens,sum=0;
	scanf("%lld",&n);
	threes=(long long int)(n/3);
	threes=3*(threes)*(threes+1)/2;
	fives=(long long int)(n/5);
	fives=5*(fives)*(fives+1)/2;
	fifteens=(long long int)(n/15);
	fifteens=15*fifteens*(fifteens+1)/2;
	sum=(n*(n+1)/2)+fifteens-fives-threes;
	printf("%lld\n",sum);
	return 0;
}


#include<stdio.h>
int main()
{
    int a,A,b,B,c;
    scanf("%d",&a);
    A=a%10;
    b=a/10;
    B=b%10;
    c=b/10;
    if(A==7||B==7||c==7)
        printf("Yes\n");
    else
        printf("No\n");
    return 0;

}


#include<stdio.h>

int main(void){
  char str[3];
  int i;
  scanf("%s",str);
  for(i = 0;i < 3;i++){
    if(str[i] == "7"){
      printf("Yes");
      break;
    }
  }
  if(i == 3){
    printf("No");
  }
  return 0;
}


#include<stdio.h>

int main() {
    int a,t,rem;
    scanf("%d",&t);
    if(t>=100 && t<1000){
        while(t>0){
            rem = t%10;
            t = t/10;
            if(rem==7){
                a = 2;
            }
        }
        if(a==2){
            printf("Yes\n");
        }
        else
            printf("No\n");
    }

    return 0;
}


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

int main(void){
  int a =0;
  scanf("%d\n",&a );
  for(int i =0;i<3;i++){
    if(a % 10 == 7){
      printf("Yes");
      exit(0);
    }
    a /= 10;
  }
  printf("No");
  return 0;
}


#include<stdio.h>

int main() {
	int N;
	int x = scanf("%d", &N);
	while (N) {
		if (N%10 == 7) {
			printf("Yes\n");
			return 0;
		}

		N /= 10;
	}

	printf("No\n");
	return 0;
}


#include <stdio.h>

int main(){
	int n,x,x1,x2,x3,flag=0;

	scanf("%d",&n);

	//10で割った余りがx桁目
	x1 = n % 10;
	if(x1 == 7)	flag =1;

		x = n / 10;
//		printf("%d\t",x);

	x2 = x % 10;
	if(x2 == 7)	flag =1;

		x = x / 10;
//		printf("%d\t",x);

	x3 = x %10;
	if(x3 == 7)	flag =1;

	if(flag==1){
		printf("Yes");
	}
	else printf("No");

	return 0;
}


#include <stdio.h>

int main() {
	int N;
	scanf("%d", &N);
	int j = 100;
	for (int i = 0; i < 3; i++) {
		int t = N / j;
		if (t == 7) {
			printf("Yes");
			return 0;
		}
		N = N - j * t;
		j = j / 10;
		//printf("%d %d %d\n",N, t, j);
	}
	printf("No");
	return 0;
}


#include <stdio.h>
int main () {
int x;
scanf ("%d",&x);
while (x>0) {
if (x%10==7) {puts ("Yes");return 0;}
x/=10;
}
puts ("No");
}


#include<stdio.h>
int main()
{
  int N;
  scanf("%d",&N);
  int flag=0;
  if(N%10==7){
    flag=1;
  }
  else{
    N=N/10;
    if(N%10==7){
      flag=1;
    }
    else{
      N=N/10;
      if(N%10==7){
        flag=1;
      }
    }
  }
  if(flag==1){
    printf("Yes");
  }
  else{
    printf("No");
  }
  return 0;
}


#include <stdio.h>

int main(void)
{
  int n;

  scanf("%d", &n);

  if (n / 100 == 7)
    printf("Yes");
  else if ((n % 100) / 10 == 7)
    printf("Yes");
  else if (n % 10 == 7)
    printf("Yes");
  else
    printf("No");

  return 0;
}


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

typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;

int main(void) {
  int scan; // scanf result
  char *n; // to input

  n = (char *)malloc(sizeof(char) *4);
  scan = scanf("%s", n);
  if (n[0] != '7') {
    if (n[1] != '7') {
      if (n[2] != '7') {
        printf("No");
        return (0);
      }
      printf("Yes");
      return (0);
    }
    printf("Yes");
    return (0);
  }
  printf("Yes");
  return (0);
}


#include <stdio.h>

int main(void) {
    char N[4];
    scanf("%s", N);

    int i = 0;
    for (i = 0; i < 3; i++) {
        if (N[i] == '7') {
            printf("Yes\n");
            return 0;
        }
    }
    printf("No\n");
    return 0;
}


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

#define BUF 4
int main(void) {
  char num[BUF];
  scanf("%s", num);
  if (num[0] == '7' || num[1] == '7' || num[2] == '7') {
    printf("Yes\n");
  } else {
    printf("No\n");
  }

  return 0;
}


#include <stdio.h>
int GCD(int a,int b)
{
  int r=1;
  while(r!=0){
    r=a%b;
    a=b;
    b=r;
  }
  return a;
}
int main()
{
  int k;
  scanf("%d",&k);
  int gcdsum=0;
  for(int i=1;i<=k;i++){
    for(int j=1;j<=k;j++){
      for(int m=1;m<=k;m++){
            gcdsum+=GCD(GCD(i,j),m);
      }
    }
  }
  printf("%d",gcdsum);
  return 0;
}

Score : 300 points

Problem Statement

Find \displaystyle{\sum_{a=1}^{K}\sum_{b=1}^{K}\sum_{c=1}^{K} \gcd(a,b,c)}.

Here \gcd(a,b,c) denotes the greatest common divisor of a, b, and c.

Constraints

1 \leq K \leq 200

K is an integer.

Input

Input is given from Standard Input in the following format:

K

Output

Print the value of \displaystyle{\sum_{a=1}^{K}\sum_{b=1}^{K}\sum_{c=1}^{K} \gcd(a,b,c)}.

Sample Input 1

2

Sample Output 1

9

\gcd(1,1,1)+\gcd(1,1,2)+\gcd(1,2,1)+\gcd(1,2,2)
+\gcd(2,1,1)+\gcd(2,1,2)+\gcd(2,2,1)+\gcd(2,2,2)
=1+1+1+1+1+1+1+2=9

Thus, the answer is 9.

Sample Input 2

200

Sample Output 2

10813692


#include <stdio.h>

int main(void)
{
  int n,i,j,k,wari;
  int kys = 0;
  int goukei = 0;

  scanf("%d",&n);

  for(i=1; i<=n; i++){
    for(j=1; j<=n; j++){
      for(k=1; k<=n; k++){
        for(wari=1; wari<=n; wari++){
          if(i%wari==0 && j%wari==0 && k%wari==0)
            kys = wari;
        }
        goukei += kys;
      }
    }
  }
  printf("%d",goukei);
  return 0;
}


#include <stdio.h>

int gcd(int a, int b) {
  while (b != 0) {
    int r = a % b;
    a = b;
    b = r;
  }
  return a;
}

int gcd3(int a, int b, int c) {
  return gcd(gcd(a, b), c);
}

int main(void) {
  int input;
  int sum = 0;
  scanf("%d", &input);
  for(int i = 1; i <= input; i++) {
    for(int j = 1; j <= input; j++) {
      for(int k = 1; k <= input; k++) {
        sum += gcd3(i, j, k);
      }
    }
  }
  printf("%d\n", sum);

  return 0;
}


#include <stdio.h>
#include <math.h>
int main(){
	int k, ans=0, r1, r2, l, m, n, a=1, b=1, c=1;
	scanf("%d", &k);

	while(a <= k){
		while(b <= k){
			while(c <= k){
				if(a==c){
					ans += a;
				}
				else{
					l = a, m = b, n = c;//aとcの最大公約数r1
					r1 = n % l;
					while(r1!=0){
						n = l;
						l = r1;
						r1 = n % l;
					}
					if(a==b || b==c){
						ans = ans + l*3;
					}
					else{
						r2 = m % l;
						while(r2!=0){//r1とbの最大公約数r2
							m = l;
							l = r2;
							r2 = m % l;
						}
						ans = ans + l*6;
					}
				}

				//printf("(%d,%d,%d), l = %d, ans = %d\n", a, b, c, l, ans);
				c++;
			}
			b++;
			c = b;
		}
		a++;
		b = a;
		c = a;
	}
	printf("%d", ans);
	return 0;
}


#include <stdio.h>
#include <time.h>
int main(){
  int i,j,k,t=1;
  int N;
int ans=0;
  scanf("%d",&N);
  clock_t start,end;
  start = clock();
  for(i=1;i<=N;i++){
    t=i;
    for(j=1;j<=N;j++){
      for(k=1;k<=N;k++){
        if(k%t == 0 && j%t == 0 && i%t == 0){
          ans+=t;
        }else{
          t--;
        }
      }
    }
  }
  end = clock();
  printf("%f秒かかりました\n",(double)(end-start)/CLOCKS_PER_SEC);

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


#include<stdio.h>
#include<math.h>
int gcd(long long int a,long long int b,long long int c)
{
   long long int n,m,t,j,k,h;
   if(a>b)
   {
       t=a;a=b;b=t;
   }
   if(a<=b)
   {
       m=b%a;
       if(m==0) n=a;
       while(m!=0)
       {
           b=a;
           a=m;
           m=b%a;
       }
       n=a;
   }

   if(n>c)
   {
       j=n;n=c;c=j;    //j×÷½»»»
   }
   if(n<=c)
   {
       k=c%n;
       if(k==0) h=n;
       while(k!=0)
       {
           c=n;
           n=k;
           k=c%n;
       }
       h=n;
   }
   return h;
}

int main()
{
    long long int n,i,j,k,sum=0;
    scanf("%lld",&n);
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=n;j++)
        {
            for(k=1;k<=n;k++)
            {
                sum=sum+gcd(i,j,k);
            }
        }
    }
    printf("%lld",sum);
}


#include<stdio.h>
int gcd(int a,int b){
    int r,tmp;
    if(a<b){
        tmp = a;
        a = b;
        b = tmp;
    }
    r = a % b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}
int main(void)
{
    int n,i,j,k,b,c,total=0;
    scanf("%d",&n);

    for(i=1;i<n+1;i++){
        for(j=1;j<n+1;j++){
            for(k=1;k<n+1;k++){
                b=gcd(i,j);
                c=gcd(k,b);
                total = total +c;
            }
        }
    }
    printf("%d\n",total);
    return 0;
}


#include <stdio.h>

int gcd(int i,int j,int k)
{
  int min;

  if(i<j)
    min=i;
  else
    min=j;
  if(k<min)
    min=k;
  for(int cnt=min;cnt>0;cnt--)
  {
    if (i%cnt==0 && j%cnt==0 && k%cnt==0)
      return (cnt);
  }
  return(0);
}

int main()
{
  int num;
  long ans=0;

  scanf("%d",&num);
  for(int i=1;i<=num;i++)
  {
    for(int j=1;j<=num;j++)
    {
      for(int k=1;k<=num;k++)
      {
        ans+=gcd(i,j,k);
      }
    }
  }
  printf("%lu",ans);
}


#include <stdio.h>
typedef long long int lld;

int gcd(int a, int b) {
  int r;
  while (1) {
    if (b == 0) {
      return a;
    }
    r = a % b;
    a = b;
    b = r;
  }
}

int main(void) {
  lld s = 0;
  int k, t;
  scanf("%d", &k);
  for (int a = 1; a <= k; a++) {
    if (a == 1) {
      s += k * k;
      continue;
    }
    for (int b = 1; b <= k; b++) {
      if (b == 1) {
        s += k;
        continue;
      }
      t = gcd(a, b);
      if (t == 1) {
        s += k;
        continue;
      }
      for (int c = 1; c <= k; c++) {
        if (c == 1) {
          s++;
          continue;
        }
        s += gcd(t, c);
      }
    }
  }
  printf("%lld\n", s);
}


#include<stdio.h>
int gcd(int a, int b)
{
    // Everything divides 0
    if (a == 0)
       return b;
    if (b == 0)
       return a;

    // base case
    if (a == b)
        return a;

    // a is greater
    if (a > b)
        return gcd(a-b, b);
    return gcd(a, b-a);
}
int main()
{
	int a;
    scanf("%d", &a);
    int b = a;
    int c = a;
    long long int sum = 0;
    for(int i=1;i<=a;i++)
    {
        for(int j=1;j<=b;j++)
        {
            for(int k=1;k<=c;k++)
            {
              int x = gcd(j,k);
                x = gcd(x, i);
                sum += x;
            }
        }
    }
    printf("%lld", sum);
	return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int cmp(const void *a,const void *b){
    if(*(int*)a>*(int*)b){return 1;}
    else if(*(int*)a<*(int*)b){return -1;}
    else {return 0;}
}

int gcd(int a,int b){
    int aa=a;
    int bb=b;
    int cc;
for(;;){
    if(aa%bb==0){return bb;}
    else{cc=aa%bb;aa=bb;bb=cc;}
}

}

int main(void){
int k;
int sum=0;
scanf("%d",&k);
for(int i=1;i<=k;i++){
    for(int j=1;j<=k;j++){
        for(int m=1;m<=k;m++){
            sum=sum+gcd(gcd(i,j),m);
        }
    }
}
printf("%d\n",sum);
}


#include <stdio.h>

int main(){
  int n;  scanf("%d", &n);
  char s[4010];  scanf("%s", s);
  int n_r = 0, n_g = 0, n_b = 0;
  for(int i=0; i<n; i++)
    if(s[i] == 'R')  n_r++;
    else if(s[i] == 'G')  n_g++;
    else if(s[i] == 'B')  n_b++;

  int ans = n_r * n_g * n_b;

  for(int i=0; i<n-2; i++){
    for(int j=i+1; j<n-1; j++){
      if(s[i] == s[j])  continue;
      int k = j*2-i;
      if(k >= n)  continue;
      if(s[k] != s[i] && s[k] != s[j])
	ans--;
    }
  }

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

  return 0;
}

Score : 400 points

Problem Statement

We have a string S of length N consisting of R, G, and B.

Find the number of triples (i,~j,~k)~(1 \leq i < j < k \leq N) that satisfy both of the following conditions:

S_i \neq S_j, S_i \neq S_k, and S_j \neq S_k.

j - i \neq k - j.

Constraints

1 \leq N \leq 4000

S is a string of length N consisting of R, G, and B.

Input

Input is given from Standard Input in the following format:

N
S

Output

Print the number of triplets in question.

Sample Input 1

4
RRGB

Sample Output 1

1

Only the triplet (1,~3,~4) satisfies both conditions. The triplet (2,~3,~4) satisfies the first condition but not the second, so it does not count.

Sample Input 2

39
RBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBB

Sample Output 2

1800


#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int int_min(int a,int b)
{
  if(a>=b){
    return b;
  }else{
    return a;
  }
}
void main(void)
{
  int N,r=0,g=0,b=0;
  //char *str;
  scanf("%d",&N);
  //str=(char*)malloc(sizeof(char)*N);
  char str[N+1];
  scanf("%s",str);
  for(int i=0;i<N;i++){
    //scanf("%c",&str[i]);
    if(str[i]=='R'){
      r++;
    }else if(str[i]=='G'){
      g++;
    }else if(str[i]=='B'){
      b++;
    }
  }
  int tmp=0;
  for(int i=1;i<=(N-2);i++){
    for(int j=1;j<=int_min(i,N-1-i);j++){
      if((str[i-j]!=str[i])&&(str[i-j]!=str[i+j])&&(str[i]!=str[i+j])){
        tmp++;
      }
    }
   }

   printf("%d",r*g*b-tmp);

}


#include <stdio.h>

int main(){
  long int num,sum;
  scanf("%ld",&num);
  char s[4000]={};
  scanf("%s",s,num);
  long int count_r=0,count_g=0,count_b=0;
  for(int a=0;a<=num-1;a++){
    if(s[a]=='R')count_r++;
    else if(s[a]=='G')count_g++;
    else count_b++;
  };
  sum=count_r*count_g*count_b;
  long int i,j,k;
  for(j=0;j<=num-2;j++){
    for(i=j+1;2*i-j<=num-1;i++){
      k=2*i-j;
      if(s[j]!=s[i]&&s[k]!=s[i]&&s[k]!=s[j])
        sum--;
    };
  };
   printf("%ld",sum);
};


#include <stdio.h>

#define SIZE 4500

int main(){
    int N;
    char S[SIZE] = {};
    scanf("%d%s", &N, S);
    int r, g, b;
    r = g = b = 0;
    for(int i=0; i<N; i++){
        switch(S[i]){
            case 'R': r++; break;
            case 'G': g++; break;
            case 'B': b++; break;
        }
    }
    long long ans = r*g*b;

    int i, p;
    for(i=0; i<N-2; i++){
        for(p=1; i+p+p<N; p++){
            if(S[i]!=S[i+p] && S[i]!=S[i+p+p] && S[i+p]!=S[i+p+p]){
                ans--;
            }
        }
    }

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


#include <stdio.h>

int check(char a, char b, char c)
{
    if (a != b && a != c && b != c) {
        return 1;
    }
    return 0;
}

int main(void)
{
    int N;
    char S[4001];
    scanf("%d", &N);
    scanf("%s", S);

    // 全てのRGBの順列
    int i;
    int r = 0, g = 0, b = 0;
    for (i = 0; i < N; i++) {
        if (S[i] == 'R') r++;
        if (S[i] == 'G') g++;
        if (S[i] == 'B') b++;
    }
    long long result = r * g * b;

    // 距離が同じでRGBなら除外
    // long long exc = 0;
    // int head, center, tail;
    // for (head = 0; head < N - 2; head++) {
    //     for (center = head + 1; center < N - 1; center++) {
    //         tail = center * 2 - head;
    //         if (tail > N - 1) break;
    //         if (check(S[head], S[center], S[tail])) {
    //             exc++;
    //         }
    //     }
    // }
    int head = 0;
    int center = 1;
    int tail = 2;
    while (head < N - 2) {
        if (check(S[head], S[center], S[tail])) {
            // exc++;
            result--;
        }
        center += 1;
        tail += 2;
        if (tail > N - 1) {
            head++;
            center = head + 1;
            tail = head + 2;
        }
    }

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


#include<stdio.h>

int main(void){

    int N,i,j,R_num = 0,G_num = 0,B_num = 0;
    long int ans;
    char S[4001];

    scanf("%d",&N);
    scanf("%s",S);

    for(i = 0;i < N;i++){
        if(S[i] == 'R') R_num++;
        else if(S[i] == 'G') G_num++;
        else if(S[i] == 'B') B_num++;
    }

    ans = R_num * G_num * B_num;

    for(i = 0;i < N;i++){
        for(j = 1;(i+j+j) < N;j++){
            if(S[i] != S[i+j] && S[i+j] != S[i+j+j] && S[i+j+j] != S[i]) ans--;
        }
    }

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


#include <stdio.h>

int main(void)
{
	int i,x,y,N,r[4001],g[4001],b[4001],rc=0,gc=0,bc=0,rp[4001],gp[4001],bp[4001];
	char S[4001];
	long long total=0;
	scanf("%d",&N);
	scanf("%s",S);
	for(i=0;i<N;i++){
		if(S[i]=='R'){
			rp[rc]=i;
			rc++;
		}else if(S[i]=='G'){
			gp[gc]=i;
			gc++;
		}else if(S[i]=='B'){
			bp[bc]=i;
			bc++;
		}
		r[i]=rc;
		g[i]=gc;
		b[i]=bc;
	}
	if(rc==0||gc==0||bc==0){}
	else{
	for(x=0;x<rc;x++){
		for(y=0;y<gc;y++){
			if(rp[x]<gp[y]){
				if(S[gp[y]*2-rp[x]]=='B')total+=(long long)bc-b[gp[y]]-1;
				else total+=(long long)bc-b[gp[y]];
			}
		}
	}
	for(x=0;x<gc;x++){
		for(y=0;y<bc;y++){
			if(gp[x]<bp[y]){
				if(S[bp[y]*2-gp[x]]=='R')total+=(long long)rc-r[bp[y]]-1;
				else total+=(long long)rc-r[bp[y]];
			}
		}
	}
	for(x=0;x<bc;x++){
		for(y=0;y<rc;y++){
			if(bp[x]<rp[y]){
				if(S[rp[y]*2-bp[x]]=='G')total+=(long long)gc-g[rp[y]]-1;
				else total+=(long long)gc-g[rp[y]];
			}
		}
	}
	for(x=0;x<rc;x++){
		for(y=0;y<bc;y++){
			if(rp[x]<bp[y]){
				if(S[bp[y]*2-rp[x]]=='G')total+=(long long)gc-g[bp[y]]-1;
				else total+=(long long)gc-g[bp[y]];
			}
		}
	}
	for(x=0;x<gc;x++){
		for(y=0;y<rc;y++){
			if(gp[x]<rp[y]){
				if(S[rp[y]*2-gp[x]]=='B')total+=(long long)bc-b[rp[y]]-1;
				else total+=(long long)bc-b[rp[y]];
			}
		}
	}
	for(x=0;x<bc;x++){
		for(y=0;y<gc;y++){
			if(bp[x]<gp[y]){
				if(S[gp[y]*2-bp[x]]=='R')total+=(long long)rc-r[gp[y]]-1;
				else total+=(long long)rc-r[gp[y]];
			}
		}
	}
	}
	printf("%lld",total);
	return 0;
}


#include <stdio.h>

int main()
{
  int num;
  scanf("%d\n",&num);
  if(num<3)
    return(0);
  char a[num];
  int ans=0;
  for(int cnt=0;cnt<num;cnt++)
    scanf("%c",&a[cnt]);

  for(int i=0;i<num-2;i++)
  {
    for(int j=i+1;j<num-1;j++)
    {
      for(int k=j+1;k<num;k++)
      {
        if(a[i]!=a[j] && a[j]!=a[k] && a[i]!=a[k])
        {
          if(j-i != k-j)
          {
            ans++;
          }
        }
      }
    }
  }
  printf("%d",ans);
}


#include<stdio.h>
#include<string.h>
#include <stdlib.h>
int main(void){
    int N;
    char S[4001];
    scanf("%d",&N);
    scanf("%s",S);
    int SUM=0;
    for (int i=0; i<N-2; i++) {
        for (int j=i+1; j<N-1; j++) {
            for (int l=j+1; l<N; l++) {
                if (S[i]!=S[j] && S[i]!=S[l] && S[j]!=S[l]) {
                    if (j-i!=l-j) {
                        SUM++;
                    }
                }
            }
        }
    }
    printf("%d\n",SUM);
    return 0;
}


#include<stdio.h>
#include<stdlib.h>
int main()
{
	char a[4010];
	int i, j, k,n;
	long long int num = 0;
	scanf("%d%s", &n, a);
	for (i = 0; i < n-2; i++)
	{
		for (j = i + 1; j < n-1; j++)
		{
			for (k = j + 1; k < n; k++)
			{
				if (a[i] != a[j] && a[i] != a[k] && a[j] != a[k] && i + k != j + j)
				{
					num++;
				}
			}
		}
	}
	printf("%lld", num);
	return 0;
}


#include <stdio.h>

int main(){

    int x, y, z;
    int a;

    scanf("%d %d %d", &x, &y, &z);

    a = z;
    z = y;
    y = x;
    x = a;

    printf("%d %d %d", x, y, z);

    return 0;

}

Score : 100 points

Problem Statement

We have three boxes A, B, and C, each of which contains an integer.

Currently, the boxes A, B, and C contain the integers X, Y, and Z, respectively.

We will now do the operations below in order. Find the content of each box afterward.

Swap the contents of the boxes A and B

Swap the contents of the boxes A and C

Constraints

1 \leq X,Y,Z \leq 100

All values in input are integers.

Input

Input is given from Standard Input in the following format:

X Y Z

Output

Print the integers contained in the boxes A, B, and C, in this order, with space in between.

Sample Input 1

1 2 3

Sample Output 1

3 1 2

After the contents of the boxes A and B are swapped, A, B, and C contain 2, 1, and 3, respectively.

Then, after the contents of A and C are swapped, A, B, and C contain 3, 1, and 2, respectively.

Sample Input 2

100 100 100

Sample Output 2

100 100 100

Sample Input 3

41 59 31

Sample Output 3

31 41 59


#include <stdio.h>
int main(void){
  int x,y,z;
  int a,b;
  scanf("%d",&x);
  scanf("%d",&y);
  scanf("%d",&z);
  a=x;
  x=y;
  y=a;
  b=x;
  x=z;
  z=b;
  printf("%d %d %d\n",x,y,z);
  return 0;
}


#include<stdio.h>

int main(){
  int a,b,c,t;
  scanf("%d",&a);
  scanf("%d",&b);
  scanf("%d",&c);

  t=a; a=b; b=t;
  t=a; a=c; c=t;

  printf("%d %d %d",a,b,c);

  return 0;
}


#include<stdio.h>
int main(void)
{int a,b,c;scanf("%d %d %d",&a,&b,&c);printf("%d %d %d\n",c,a,b);return 0;}


#include<stdio.h>

int main(){
  int X,Y,Z;
  scanf("%d %d %d",&X,&Y,&Z);
  printf("%d %d %d\n",Z,X,Y);
  return 0;
}


#include<stdio.h>
int main(void) {
  int X, Y, Z;
  int store;
  scanf("%d %d %d", &X, &Y, &Z);
  store = X;
  X = Y;
  Y = store;
  store = X;
  X = Z;
  Z = store;
  printf("%d %d %d", X, Y, Z);
  return 0;
}


#include <stdio.h>
#include <stdlib.h>
int main(){
    unsigned long long n,k,x,y;
    scanf("%llu %llu", &n,&k);
    x = n%k; y = abs(x-k);
    if (x>y)
    printf("%llu\n",y);
    else
    printf("%llu\n",x );
}


#include<stdio.h>
int main()
{
	int A,B,C;
        int temp,temp1;
	scanf("%d %d %d",&A,&B,&C);
	temp=A;
	A=B;
	B=temp;
	temp1=A;
	A=C;
	C=temp1;
	printf("%d %d %d\n",A,B,C);
	return 0;
}


#include<stdio.h>

int main()
{
    int X, Y, Z;
    scanf("%d%d%d",&X,&Y,&Z);
    printf("%d %d %d\n",Z,X,Y);
    return 0;
}


#include <stdio.h>

int main(void){

	int a;
	int b;
	int c;
	int num;

	scanf("%d %d %d",&a,&b,&c);
	num = a;
	a = b;
	b = num;

	num = a;
	a = c;
	c = num;

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

	return 0;
}


#include <stdio.h>

int main()
{
  int a,b,c,temp;
  scanf("%d %d %d",&a,&b,&c);
  temp = a;
  a = b;
  b = temp;

  temp = a;
  a = c;
  c = temp;

  printf("%d %d %d\n",a,b,c);
}


#include "stdio.h"
int main()
{
  int X,Y,Z;
  scanf ("%d",&X);
  scanf ("%d",&Y);
  scanf ("%d",&Z);
  printf ("%d %d %d",Z,X,Y);
  return 0;
}


#include<stdio.h>

void Exchange(int *a, int *b);

int main(void){
	int A, B, C;
	scanf("%d %d %d", &A, &B, &C);

    Exchange(&A, &B);
    Exchange(&A, &C);

	printf("%d %d %d", A, B, C);
	return 0;
}

// 2つの数字を入れ替える
void Exchange(int *a, int *b){
	int box;
	box = *a;
	*a = *b;
	*b = box;
}


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


#include <stdio.h>

void swap(int *a,int *b){
  int temp;
  temp=*a;
  *a=*b;
  *b=temp;
}

int main(){
  	int x,y,z;
  	if(scanf("%d %d %d",&x,&y,&z)==1);

  	swap(&x,&y);
    printf("箱Aと箱Bの中身を入れ替えた後、箱A,B,Cに入っている整数はそれぞれ%d,%d,%dです。\n",x,y,z);
  	swap(&x,&z);
  	printf("箱Aと箱Bの中身を入れ替えた後、箱A,B,Cに入っている整数はそれぞれ%d,%d,%dです。\n",x,y,z);

  	return 0;
}


#include<stdio.h>
int main(void){
  int x,y,z;
  scanf("%d %d %d", &x, &y, &z);
  printf("%d %d %d", z, x, y);
  return 0;
}


#include <stdio.h>

int main (void) {
  int a, b, c;
  int a1, b1, c1;
  int a2, b2, c2;

  scanf("%d %d %d", &a, &b, &c);
  a1 = b;
  b1 = a;
  c1 = c;
  a2 = c1;
  b2 = b1;
  c2 = a1;

  printf("%d %d %d\n", a2, b2, c2);

  return 0;
}


#include<stdio.h>
int main()
{
    int X;
    int Y;
    int Z;
    scanf("%d",&X);
    scanf("%d",&Y);
    scanf("%d",&Z);
    printf("%d¥n",&Z,&X,&Y);
    return 0;
}


#include <stdio.h>
int main()
{
  int X,Y,Z;
  int i=0;
  int j=0;
  scanf ("%d %d %d", &X, &Y, &Z);
  i=X;
  X=Y;
  Y=i;
  j=X;
  X=Z;
  Z=j;
  printf("%d %d %d", X, Y, Z);
  return 0;
}


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


#include <stdio.h>

void main(){
  long a,b,c;

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

  printf("%ld %ld %ld",&c,&a,&b);
}


/*
 * main.c
 *
 *  Created on: 2020/03/28
 *      Author: family
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define MAX(a,b) (a > b ? a : b)
#define MIN(a,b) (a > b ? b : a)
typedef long long int ll;
typedef unsigned long long int ull;

int sort_inc(const void *a, const void *b) { return (*(int*)a - *(int*)b);}
int sort_dec(const void* a, const void* b) { return (*(int*)b - *(int*)a);}
int sort_dec_ll(const void *a, const void *b) {
    ll da = *(ll*)a, db = *(ll*)b;    int val = 0;
    if(da > db) { val = -1; }
    else if (da == db) { val = 0; }
    else { val = 1; }
    return val;
}
int sort_inc_ll(const void *a, const void *b) {
    ll da = *(ll*)a, db = *(ll*)b;    int val = 0;
    if(da > db) { val = 1; }
    else if (da == db) { val = 0; }
    else { val = -1; }
    return val;
}
int sort_dic(const void *a, const void *b) {
    char *pa = (char *)a;    char *pb = (char *)b;    int i = 0, val = 0, N = 10;
    for (i = 0; i < N; i++) {
    	char da = pa[i], db = pb[i];
    	if (da == db) continue;
  		if (da > db) val = 1; else val = -1;
        break;
    }
    return val;
}

int main()
{
	int A = 0, B = 0, C = 0, tmp = 0;
	scanf("%d %d %d", &A, &B, &C);
	tmp = A;
	A = B;
	B = tmp;
	tmp = A;
	A = C;
	C = tmp;
	printf("%d %d %d\n", A, B, C);
    return 0;
}


#include<stdio.h>
int main()
{
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    printf("%d\t%d\t%d\t",c,a,b);
    return 0;
}


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

typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;

int main(void) {
  int scan; // scanf result
  int x; // to input
  int y; // to input
  int z; // to input
  int temp;

  scan = scanf("%d", &x);
  scan = scanf("%d", &y);
  scan = scanf("%d", &z);

  temp = 0;
  temp = x;
  x = y;
  y = temp;

  temp = 0;
  temp = x;
  x = z;
  z = temp;

  printf("%d", x);
  printf(" ");
  printf("%d", y);
  printf(" ");
  printf("%d", z);
  return (0);
}


#include <stdio.h>

int main(int argc, char *argv[]){
    int a,b,c,temp;
    scanf("%d %d %d",&a,&b,&c);

    temp = a;
    a = b;
    b = temp;

    temp = a;
    a = c;
    c = temp;

    printf("%d %d %d\n", a,b,c);
    return 0;
}


#include<stdio.h>
int main()
{
int n,m,i,sum,sw;
  sw=0;
  sum=0;
scanf("%d %d",&n,&m);
int a[n];
double bo;

  for(i=0;i<n;++i)
  {
  scanf("%d",&a[i]);
  sum=sum+a[i];
  }
  bo=sum/(4*m);

  for(i=0;i<n;++i)
  {
  if(a[i]>=bo) sw++;
  }

  if(sw>m) printf("Yes");
  else printf("No");
return 0;
}

Score : 200 points

Problem Statement

We have held a popularity poll for N items on sale. Item i received A_i votes.

From these N items, we will select M as popular items. However, we cannot select an item with less than \dfrac{1}{4M} of the total number of votes.

If M popular items can be selected, print Yes; otherwise, print No.

Constraints

1 \leq M \leq N \leq 100

1 \leq A_i \leq 1000

A_i are distinct.

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M
A_1 ... A_N

Output

If M popular items can be selected, print Yes; otherwise, print No.

Sample Input 1

4 1
5 4 2 1

Sample Output 1

Yes

There were 12 votes in total. The most popular item received 5 votes, and we can select it.

Sample Input 2

3 2
380 19 1

Sample Output 2

No

There were 400 votes in total. The second and third most popular items received less than \dfrac{1}{4\times 2} of the total number of votes, so we cannot select them. Thus, we cannot select two popular items.

Sample Input 3

12 3
4 56 78 901 2 345 67 890 123 45 6 789

Sample Output 3

Yes


#include<stdio.h>
void main(){
   int n,m;
   scanf("%d%d",&n,&m);
   int a[n];
   int i;
   int count=0;
   double sum=0;;
   for(i=0;i<n;i++){
      scanf("%d",&a[i]);
      sum=sum+a[i];
   }
   for(i=0;i<m;i++){
      if(a[i]<sum/(4*m)){
         count++;
      }
   }
   if(count>= m){
      printf("Yes");
   }else{
      printf("No");
   }
}


#include <stdio.h>
int main(void){
int x,y,z;
int i,n=0;
int count=0;
scanf("%d",&x); //商品の種類
scanf("%d",&y); //人気商品の個数
 int hyou[x];
for(i=0;i<x;i++){
scanf("%d",&z); //票数
  count+=z;
  hyou[i]=z;
}
  for(i=0;i<x;i++){
   if(hyou[i]>=count/(4*y)) n++;
  }
if(n>=y) printf("Yes");
else printf("No");
return 0;
}


#include <stdio.h>

int main(void){
  int m,n,i,j,tmp;
  int a[100];
  int all_vote=0;

  do{
    scanf("%d %d",&n,&m);
  }while(m<1 || n<m || 100<n);

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

  for(i=0;i<n;i++){
    for(j=i+1;j<n;i++){
      if(a[i]<a[j]){
        tmp = a[i];
        a[i] = a[j];
        a[j] = tmp;
      }
    }
  }

  if(4*m*a[n-m] >= all_vote){
    printf("Yes");
  }

  return 0;
}


#include <stdio.h>
int main(void){
 int n,m,sum=0,i,max=0;
 int num[256];
 for(i=0;i<n;i++){
    num[i]=0;
 }
 scanf("%d %d",&n,&m);
 scanf("%d",&num);
 for(i=0;i<n;i++){
    sum+=num[i];
 }
 for(i=0;i<n;i++){
    if(num[i]>=sum*(1/4*m)){
       max+=1;
    }
 }
}


#include <stdio.h>
void swap(int *a,int *b)
{
  int temp=*a;
  *a=*b;
  *b=temp;
}
int main(void)
{
  int n,m,i,s,max=0,a[100];
  scanf("%d%d",&n,&m);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  for(s=0;s<n;s++){
    for(i=0;i<n-1;i++){
      if(a[i]<a[i+1])
        swap(&a[i],&a[i+1]);
    }
  }
  if(a[m-1]<1/(4*m)){
    printf("No");
  }else{
    printf("Yes");
  }
  return 0;
}


#include<stdio.h>

int main(void)
{
  int n,m,s,t=0;
  int total=0;
  int a[1000];
  double u;

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

  u=1/(4*m);

  for(s=0;s<n;s++){
    if(a[n]>=total*u){
      t++;
    }
  }

  if(t>=m)
    puts("Yes");
  else
    puts("No");

  return 0;
}


#include <stdio.h>

int main(void){
  int n,m,i,l,sum;
  int a[n];
  scanf("%d",&n);
  scanf("%d",&m);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
    sum+=a[i];
  }
  for(l=0;l<n;l++){
    if(a[l]>sum*(1/4*m)){
      puts("Yes");
      break;
    }
    else{
      puts("No");
      break;
    }
  }
  return 0;
    }


#include <stdio.h>
int main(void)
{
int N,M,A[200],i,count=0,sum=0;
double line;
scanf("%d",&N);
scanf("%d",&M);
for(i=0;i<N;i++){
scanf("%d",&A[i]);
sum=sum+A[i];
}
line=sum/(4*M);
for(i=0;i<N;i++){
if(A[i]>line+0.8)
count++;
}

if(count>=M)
printf("Yes");
else
printf("No");

return 0;
}


#include<stdio.h>

int main(void)
{
  int A[1000]={0};
  int n,m,i;
  int low;
  int gou=0;
  int count=0;

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

  for(i=0;i<n;i++){
    scanf("%d", &A[i]);
    gou=gou+A[i];
  }
  low=gou/(4*m);
  for(i=0;i<n;i++){
    if(A[i]>=low)
      count+=1;
  }
  if(count>=m)
    puts("Yes");
  else puts("No");

  return 0;
}


#include <stdio.h>
int main(void)
{
  int i,n,m,cnt,total;
  total=0;
  scanf("%d",&n);
  scanf("%d",&m);
  int a[n];
  for(i=0;i<n;i++)
    scanf("%d",&a[i]);
  for(i=0;i<n;i++)
  {
    total=total+a[i];
  }
  for(i=0;i<n;i++)
  {
  if(a[i]>total/(4*m))
    cnt++;
  }
  if(cnt>=m)
    printf("Yes");
  else
    printf("No");
return 0;
}


#include<stdio.h>
int main(void)
{
  int N,M;
  int A[1000]={0};
  scanf("%d %d",&N,&M);
  int i;
  double sum=0;
  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
    sum+=A[i];
  }
  int num=0,flag=0;
  double n;
  n=sum/(4*M);
  for(i=0;i<N;i++){
  	if(A[i]>=n){
      num++;
      if(num>=M){
        flag=1;
      }
  	}
  }
  if(flag==1)
    printf("Yes");
  else
    printf("No");
  return 0;
}


#include <stdio.h>
int main(void){
int N,M,i;
int sum=0;
scanf("%d",&N);
scanf("%d",&M);

int a[100];
int b=0;

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

for(i=0;i<=N-1;i++){
if(a[i]*4*M>sum){
	b++;
}
}

if(b>M)
	printf("Yes");
else
    printf("No");

return 0;
}


#include <stdio.h>
int main(void)
{
  int n,m,i,sum=0;
  scanf("%d",&n);
  scanf("%d",&m);
  int a[n],b=0;
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
    sum+=a[i];
  }
  for(i=0;i<n;i++)
    if(a[i]*4*m>=sum)
      b++;
  if(b>=m)
    printf("Yes");
  else
    printf("No");

  return 0;
}


#include<stdio.h>

int main(void)
{
  int N, M, i;
  int A[100];
  int cnt = 0;
  int sum = 0;

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

    sum += A[i];
  }

  for(i = 0; i < N; i++)
  {
     if(A[i] >= sum / (4 * M))
    {
      cnt++;
    }
  }

  if(cnt >= M)
    printf("Yes\n");

  else
    printf("No\n");

  return 0;
}


#include <stdio.h>

int main(){
  int N,M,canSelect=0;
  scanf("%d %d",&N,&M);

  int syohin[N];
  double sotokuhyo=0.0;
  for(int i=0;i<N;i++){
    sotokuhyo += syohin[i];
  }

  for(int j=0;j<N;j++){
     if(syohin[j] >= (sotokuhyo/(4*M))) canSelect++;
  }

  if(canSelect>=M){
    printf("Yes");
  }else{
    printf("No");
  }
}


#include<stdio.h>

int main(void)
{
   int n,m,a[100],x,y,i,b,c;
   b=0; c=0;
   scanf("%d%d",&n,&m);
   x=4*m;
   for(i=0; i<n; i++){
      scanf("%d",&a[i]);
      b+=a[i];
   }
   y=b/x;
   for(i=0; i<n; i++){
      if(a[i]>=y)
        c=c+1;
   }

   if(c<m)
      printf("No\n");
   else
      printf("Yes\n");
   return 0;
}


#include<stdio.h>
int main(void)
{
    int n,m,a[100],i,s=0,j=0;
    scanf("%d%d",&n,&m);
    for(i=0;i<n;i++){
        scanf("%d",&a[i]);
        s+=a[i];
    }
    for(i=0;i<n;i++)
        if(a[i]>=(s*(1.0/(4.0*(double)m))))
            j++;
    if(j>=m) printf("Yes\n");
    else     printf("No\n");
    return 0;
}


/* B - Popular Vote */

#include <stdio.h>

int main(void){
  int N, M, i, A[100], sum = 0, count = 0;
  scanf("%d %d", &N, &M);
  for(i = 0; i < N; i++){
    scanf("%d", &A[i]);
    sum += A[i];
  }
  for(i = 0; i < N; i++){
    if(sum % (4 * M) == 0){
      if(A[i] >= sum / (4 * M)){
        count++;
      }
    }else{
      if(A[i] >= sum / (4 * M) + 1){
        count++;
      }
    }
  }
  if(count >= M){
    printf("Yes\n");
  }else{
    printf("No\n");
  }
}


#include<stdio.h>

int main(){
  int n,m;
  scanf("%d %d",&n,&m);
  int a[n],all=0,count=0;
  for(int i=0;i<n;i++){
    scanf("%d",&a[i]);
    all=all+a[i];
  }
  for(int i=0;i<n;i++){
    if(all/(4*m)<a[i]){
      count++;
      if(count==2){
        printf("Yes");
        break;
      }
    }
    else if(i==n-1)
      printf("No");
  }
}


#include<stdio.h>
int main()
{
    int n,m,x,i,sum=0,c;
    scanf("%d %d",&n,&m);
    int a[101];
    for(i=0; i<n; i++)
    {
        scanf("%d",&a[i]);
        sum=sum+a[i];
    }
    c=0;
    x=sum/(4*m);
    for( i=0; i<n; i++)
    {
        if(x<=a[i])
        {
            c++;
        }
    }
    if(c>=m)
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }
    return 0;
}


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

int main()
{
    int i,n,m,a[101],sum=0,count=0;
    scanf("%d %d",&n,&m);
    for(i=0;i<n;i++){
        scanf("%d",a[i]);
        sum=sum+a[i];
    }
    double x=sum/(4*m);
        for(i=0;i<n;i++){
        if(a[i]>=x){
            count++;
        }
    }
    if(count>=m){
        printf("YES\n");
    }

    else{
        printf("NO\n");
    }

    return 0;
}


#include<stdio.h>

int main(void)
{
	int N, M;
	scanf("%d%d", &N, &M);
	int A[N], i;
	double sum = 0;
	for (i = 0; i < N; i++) {
		scanf("%d",& A[i]);
		sum += A[i];
	}
	int flag = 0;
	for (i = 0; i < N; i++) {
		if (A[i] >= sum/4/M) flag++;
	}
	if (flag >= M) printf("Yes");
	else printf("No");

	return 0;
}


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

int i,n,m;

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

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

for(i=0;i<n;i++){
    if(s[i]>=(sum/(4*m)))
        c++;

}

if(c>=m)
    printf("Yes");
else
    printf("No");

}


#include <stdio.h>

int partition(int a[], int p, int r){
  int x, i, j, t;
  x = a[r];
  i = p - 1;
  for(j=p; j<r; j++){
    if(a[j] <= x){
      i++;
      t = a[i];
      a[i] = a[j];
      a[j] = t;
    }
  }
  t = a[i+1];
  a[i+1] = a[r];
  a[r] = t;
  return i+1;
}

void quickSort(int a[],int p, int r){
  int q;
  if(p < r){
    q = partition(a, p, r);
    quickSort(a, p, q-1);
    quickSort(a, q+1, r);
  }
}

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

  if (a[n - 1 - m] < (sum / (4 * m)))
    printf("No\n");
  else
    printf("Yes\n");
}


#include<stdio.h>

int main(void){
  int m,n;

  scanf("%d %d",&n,&m);
  int a[n];
  int i;
  int sum = 0;
  for(i = 0;i < n;i++){
    scanf("%d",&a[i]);
    sum+=a[i];
  }
  float th = (float)sum/(4.0*(float)m);
  int cnt=0;
  for(i=0;i < n;i++){
    if(th < a[i]){
      cnt++;
    }
  }
  if(cnt >= m){
    printf("Yes");
  }
  else{
    printf("No");
  }
  return 0;
}


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

int main(void);
char* func(int n, int m, int a[]);

char* func(int n, int m, int a[]){
     int ii1, line, count, sum=0;
  	 char *s;
     count = 0;
     for(ii1=0; ii1<n; ii1++) sum+=a[ii1];
     line = sum/(4.0*m);
     for(ii1=0; ii1<n; ii1++){
        if(a[ii1] >= line) count++;
     }

     if(count >= m) s="Yes";
  	 else s="No";

     return s;
}

int main(void){
    int n, m, ii1;
    scanf("%d %d", &n, &m);
    int a[n];
    char *s;
    for(ii1=0; ii1<n; ii1++){
        scanf("%d", &a[ii1]);
    }
    s = func(n, m, a);

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

    return 0;
}


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

int main(void);
char* func(int n, int m, int a[]);

char* func(int n, int m, int a[]){
     int ii1, line, count, sum=0;
  	 char *s;
     count = 0;
     for(ii1=0; ii1<n; ii1++) sum+=a[ii1];
     line = sum/(4*m);
     for(ii1=0; ii1<n; ii1++){
        if(a[ii1] >= line) count++;
     }

     if(count >= m) s="Yes";
  	 else s="No";

     return s;
}

int main(void){
    int n, m, ii1;
    scanf("%d %d", &n, &m);
    int a[n];
    char *s;
    for(ii1=0; ii1<n; ii1++){
        scanf("%d", &a[ii1]);
    }
    s = func(n, m, a);

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

    return 0;
}


#include<stdio.h>
int main(void){
	int t,n,m,e,ask,vot=0,sum=0;
	int a[10000];
	scanf("%d%d",&n,&m);
	for(t=0;t<n;t++){
		scanf("%d",&a[t]);
		sum=sum+a[t];
	}
	ask=sum/(4*m);
	if(sum%(4*m)!=0){
		ask=ask+1;
	}
	for(e=0;e<n;e++){
		if(a[e]>=ask){
			vot=vot+1;
		}
	}
	if(vot>=m){
		printf("Yes");
	}else{
		printf("No");
	}
	return 0;
}


#include <stdio.h>

int main(void){
    int N, M;
    int votes[100], sum_votes, count, i;
    sum_votes = 0;
    count = 0;

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

    for(i = 0; i < N; i++){
        if(votes[i] >= (sum_votes/(4.0*M)))
            count++;
    }

    if(count >= M)
        printf("Yes\n");
    else
        printf("No\n");

    return 0;
}


#include <stdio.h>

int main(){
  int n, m;
  scanf("%d %d", &n, &m);
  int a[n];
  int i;
  int sum;
  sum = 0;
  for(i = 0; i < n; i++){
    scanf("%d", &a[n]);
    sum += a[n];
  }
  int number;
  for(i = 0; i < n; i++){
    if (a[i] >= (sum / (4 * m))){
      number++;
    }
  }
  if (number >= m)
    printf("Yes");
  else
    printf("No");
}


#include <stdio.h>

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

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

        int select = 0, cnt = 0;

        for (i=0;i<n;i++) {
                if(A[i] * 4 * m >= sum) cnt++;
                if(cnt == m) {
                        select = 1;
                        break;
                }
        }
        if(select) printf("Yes\n");
        else printf("No\n");
        return 0;
}


int main(){
	long n,m,i;
  	long *data,total=0,count=0,try;
 	double cutOff;
  	scanf("%ld%ld",&n,&m);
  	data=(long int*)malloc(sizeof(long int)*n);

  	for(i=0;i<n;i++){
    	scanf("%ld",&data[i]);
      	total+=data[i];
    }
  	cutOff=total/(4*m);

  	for(i=0;i<n;i++){
    	if(data[i]>=cutOff)
          	count+=1;
    }

  	if(count>=m)
      	printf("Yes");
  	else
      	printf("No");

}


#include<stdio.h>

int main(){

  int N , M , M_max = 0; /*商品数N、人気商品数M、選べる人気商品数の最大M_max*/
  int A[101]; /*得票数*/
  int sum =0; /*総得票数*/
  int judge =0; /*人気商品の判定*/

  scanf("%d %d",&N,&M); /*商品数、人気商品数取得*/

  for(int i=0 ;i < N ; i++){
    scanf("%d",&A[i]);/*得票数取得*/
    sum = sum +A[i]; /*総得票数を計算する*/
  }

  judge = sum/(4*M);

   for(int i=0 ;i < N ; i++){
     if(A[i] % 4 == 0){
       if(A[i]<judge){
       /*何もしない*/
     	}else{
       M_max ++;
    	}
     }else{
      if(A[i]<=judge){
       /*何もしない*/
     	}else{
      M_max ++;
    	}
     }
   }

  if(M <= M_max){
    printf("Yes");
  }else{
    printf("No");
  }

  return 0;

  }


#include<stdio.h>
int main(void){
    int n,m,sum=0,tmp,i,j,ans=0;
    scanf("%d%d",&n,&m);
    int a[n];
    /*入力*/
    for(i=0;n>i;++i){
        scanf("%d",&a[i]);
    }
    /*総投票数*/
    for(i=0;n>i;++i){
        sum+=a[i];
    }
    /*降順ソート*/
    for (i=0; i<n; ++i) {
        for (j=i+1; j<n; ++j) {
            if (a[i] < a[j]) {
        tmp =  a[i];
        a[i] = a[j];
        a[j] = tmp;
      }
    }
  }
  /*判定*/
  for(i=0;m>i;++i){
      if(a[i]>=(double)sum/(4*m))
      ++ans;
  }
  if(ans==m)
  printf("Yes");
  else
  printf("No");
  return 0;
}


#include <stdio.h>
int main()
{
 int lineup[100];
 int M=0;
 int N=0;
 int i=0;
 int j=0;
 int k=0;
 int add=0;

 scanf("%d %d",&N,&M);
  for(i=0;i<N;i++)
  {
    scanf("%d",&lineup[i]);
    add+=lineup[i];
  }
  for(j=0;j<N;j++){
    if(lineup[j]*4*M>=add){
      k++;
    }
  }
          if(k>=M)
            printf("yes");

          else
            printf("No");

          return 0;
          }


#include<stdio.h>
#include<math.h>
#include<stdlib.h>
int main()
{
  int n,m,a[100];
  scanf("%d %d",&n,&m);
  int i;
  for(i=0;i<n;i++)
  {
    scanf("%d ",&a[i]);
  }
  int s=0;
  for(i=0;i<n;i++)
  {
    s=s+a[i];
  }
  int c=0;
  for(int i=1;i<=n;i++) if(a[i]*4*m>=s) ++c;
    if(c>m)
    printf("Yes");
  else
    printf("No");

}


#include <stdio.h>
int main()
{
 int lineup[100];
 int M=0;
 int N=0;
 int i=0;
 int j=0;
 int k=0;
 int add=0;

 scanf("%d %d",&N,&M);
  for(i=0;i<N;i++)
  {
    scanf("%d",&lineup[i]);
    add+=lineup[i];
  }
  for(j=0;j<N;j++){
    if(lineup[j]*4*M>=add){
      k++;
    }
  }
          if(k>=M){
            printf("yes");
          }
          else{
            printf("No");
          }
          return 0;
          }


#include <stdio.h>

int main()
{
    int n,m,a[100],i,j,sum = 0;

    scanf("%d %d",&n,&m);
    for (i = 0; i < n; i++)
    {
        scanf("%d",&a[i]);
        sum += a[i];
    }
    int ans = 0;
    for (i = 0; i < n; i++)
    {
        if(a[i] * 4 * m >= sum)
        {
            ans++;
        }
    }

    if(m <= ans)printf("Yes");
    else printf("No");
}


#include <stdio.h>

int main() {
  int n, m, number, is_false;
  scanf("%d %d", &n, &m);
  int a[n];

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

  is_false = 0;
  for (int i = 0; i < n; i++) {
    if ( a[i] < (number / (double)(4 * m)) ) {
      is_false++;
    }
  }

  if (n - is_false >= m) {
    printf("Yes");
  } else {
    printf("No");
  }
  return 0;
}


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

int main(){

    int N, M;

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

    int A[N], escolido, maior=0, resul;

    for(int cont=0; cont<N;++cont){

        scanf("%d", &A[cont]);
    }

    escolido= A[M-1];

    for(int cont=0; cont<N;++cont){

        if(maior<A[cont]){
            maior=A[cont];
        }
    }

    resul=maior/(4*M);

    if(escolido==maior){

        printf("yes");

    }else if(escolido >resul){

         printf("yes");
    }else{

     printf("no");

    }

    return 0;
}


#include<stdio.h>
int main(){
    int n,m,ans=0,a[256],cnt=0;
    scanf("%d %d",&n,&m);
    if(n<=m){
      printf("No\n");
    return 0;
  }
      for(int i=0;i<n;i++){
          	scanf("%d",&a[i]);
        if(a[i]<1||a[i]>1000){
                printf("No\n");
    		return 0;
        }

      }
  for(int i=0;i<n;i++){
    cnt+=a[i];
  }
 cnt=cnt/(m*4);
    for(int i=0;i<n;i++){
  if(a[i]>=cnt){
          ans++;
        }
  }
        if(ans>=m){
          printf("Yes\n");
      }
  else
    printf("No\n");

}


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

int main (void) {
    int all;
    int pickup;

    scanf("%d %d", &all, &pickup);

    int value[all];
    int all_value = 0;

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

    float judge = (float)all_value / (4 * pickup);
    int cnt = 0;

    for (int i = 0; i < all; i++) {
        //printf("value:%d, judge:%f\n", value[i], judge);
        if (judge <= value[i]) {
            cnt++;
        }
    }
    if (cnt >= pickup) {
        printf("Yes\n");
    } else {
        printf("No\n");
    }

    return 0;
}


#include<stdio.h>
#include<math.h>
#include<stdlib.h>
int main()
{
  long int n,m,a[100];
  scanf("%ld %ld",&n,&m);
  long int i;
  for(i=0;i<n;i++)
  {
    scanf("%ld ",&a[i]);
  }
  long int s=0;
  for(i=0;i<n;i++)
  {
    s=s+a[i];
  }
  long int p,s1=0;
  p=ceil(s/(4*m));
  for(i=0;i<n;i++)
  {
    if(a[i]>p)
      s1=s1+1;
  }
  if(s1>=m)
    printf("Yes");
  else
    printf("No");

}


#include<stdio.h>

int main(){
  int M,N,n[99],i,j;
  int count=0;
  int sum=0;
  scanf("%d ",&N);
  scanf("%d\n",&M);
  for(i=0;i<=N-1;i++){
    scanf("%d",&n[i]);
    sum=sum+n[i];
    if(i==N-1)
      printf("\n");
  }
  for(j=0;j<=N-1;j++){
    if(n[j]>=sum/(4*M))
      count++;
  }
  if(count>=M){
    printf("Yes\n");
  }else{
    printf("No\n");
  }
  return 0;
}


#include <stdio.h>
#include <string.h>
#define lop(i, n) for(i=0; i<n; i++)

int main()
{
	int N, M, i, sum=0, cnt=0;
	int A[1000];

	scanf("%d %d", &N, &M);
	lop(i, N){
		scanf("%d", &A[i]);
		sum+=A[i];
	}

	float rin=sum/(4*M);

	lop(i, N){
		if(rin<(float)A[i])cnt++;
	}

	if(cnt>=M){ printf("Yes"); }
	else { printf("No"); }

return 0;
}


#include<stdio.h>

int main(){

  int N , M , M_max = 0; /*商品数N、人気商品数M、選べる人気商品数の最大M_max*/
  int A[99]; /*得票数*/
  int sum =0; /*総得票数*/

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

  for(int i=0 ;i < N ; i++){
    scanf("%d",&A[i]);
    sum = sum +A[i]; /*総得票数を計算する*/
  }

   for(int i=0 ;i < N ; i++){
     if(A[i]>=( sum/(4*M))){
       M_max ++;
     }else{
       /*何もしない*/
     }
   }

  if(M <= M_max){
    printf("Yes");
  }else{
    printf("No");
  }

  return 0;

  }


#include<stdio.h>
int main(void){
  int all_num=0;
  int select_num=0;
  scanf("%d %d",&all_num, &select_num);
  int point[1000];
  for(int i=0;i<all_num;i++){
    scanf("%d",&point[i]);
  }
  int point_sum = 0;
  for (int j=0;j<all_num;j++){
    point_sum += point[j];
  }
  int select_ok = 0;
  int judgement = point_sum /(4*select_num);
  for (int k=0;k<all_num;k++){
    if(point[k] >= judgement){
      select_ok += 1;
    }
  }
  if(select_ok < select_num){
    printf("no");
  } else {
    printf("yes");
  }
  return 0;
}


#include <stdio.h>
int main(void){
  int i, n, m, a[100], sum, tmp, counter;

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

  sum = 0;
  for(i=0;i<n;i++) sum += a[i];

  tmp = sum / ( 4 * m );

  counter = 0;
  for(i=0;i<n;i++)
    if(a[i] >= tmp)
      counter++;

  if(counter >= m)
    printf("Yes");
  else
    printf("No");

  return 0;
}


#include<stdio.h>

int main(){
  int M,N,n[100],i,j;
  int count=0;
  scanf("%d %d\n",&N,&M);
  for(i=0;i<=N-1;i++){
    scanf("%d",&n[i]);
    if(i==N-1){
      printf("\n");
    }else{
      printf(" ");
    }
  }
  for(j=0;j<=N-1;j++){
    if(n[j]>=1/(4*M))
      count++;
  }
  if(count>=M){
    printf("Yes\n");
  }else{
    printf("No\n");
  }
  return 0;
}


#include<stdio.h>

int main(void){

  int n,m,sum=0,i,count=0;
  int a[1000];
  scanf("%d %d",&n,&m);

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

  for(i=0;i<n;i++){
    if(a[i]>=sum/(4*m))count++;
    }

  if(m<=count)printf("Yes");
  else printf("No");

  return 0;
}


#include<stdio.h>

int int_sort( const void * a , const void * b ) {
  /* 引数はvoid*型と規定されているのでint型にcastする */
  if( *( int * )a < *( int * )b ) {
    return -1;
  }
  else
  if( *( int * )a == *( int * )b ) {
    return 0;
  }
  return 1;
}

int main(void) {
  int n, m, i, sum=0;
  int* a;
  scanf("%d %d", &n, &m);
  a = (int*)malloc(sizeof(int)*n);
  for(i=0; i<n; i++) {
    scanf("%d", &a[i]);
    sum += a[i];
  }
  qsort((void*)a, n, sizeof(int), int_sort);
  if(a[n-m] < sum/(4*m)) {
    printf("No\n");
  }
  else {
    printf("Yes\n");
  }
  return 0;
}


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

#define ll long long
#define INF 1<<31-1
#define LNF 9223372036854775807
#define PI 3.14159265358979
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)<(y)?(y):(x))
#define FOR(i,a,n) for(i=a;i<n;i++)
#define MOD 1000000007
//#define MOD 998244353
#define NUM 200010

void swap(int* a,int* b){int tmp=*a;*a=*b;*b=tmp;}
int abs(int a){if(a<0)return -a;return a;}
int dup(int a,int d){if(a%d==0)return a/d;else return a/d+1;}
int mod(int a,int m){if(a<0)return a%m+m;else return a%m;}

void swapl(ll* a,ll* b){ll tmp=*a;*a=*b;*b=tmp;}
ll absl(ll a){if(a<0)return -a;return a;}
ll dupl(ll a,ll d){if(a%d==0)return a/d;else return a/d+1;}
ll modl(ll a,ll m){if(a<0)return a%m+m;else return a%m;}

ll GCD(ll a,ll b){ll c=1,tmp=MAX(a,b);b=MIN(a,b);a=tmp;while(c!=0){c=a%b;a=b;b=c;}return a;}
ll LCM(ll a,ll b){return a*b/GCD(a,b);}

ll factorial(ll n, ll m) {return n < m ? 1 : n*factorial(n-1, m);}

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;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

int main(){
  ll N, M;
  ll A[1000];
  ll sum=0, cnt;

  scanf("%lld%lld", &N, &M);

  for (int i = 0; i < N; i++)
  {
      scanf("%lld", A + i);
      sum += A[i];
  }

  for (int i = 0; i < N; i++)
  {
      if(A[i] * 4 * M >= sum) cnt++;
  }

  if (cnt < M)
  {
      printf("No\n");
  }
  else
  {
      printf("Yes\n");
  }

  return 0;
}


#include<stdio.h>
#include<stdlib.h>
#define ll long long
int asc(const void *a,const void *b){
    long long *A=(long long*)a,*B=(long long*)b;
    if(*A<*B) return 1;
    if(*A>*B) return -1;
    return 0;
}
int main(){
    ll x,y,a,b,c,i;
    scanf("%lld%lld%lld%lld%lld",&x,&y,&a,&b,&c);
    ll p[a],q[b],r[c];
    for(i=0;i<a;i++) scanf("%lld",&p[i]);
    for(i=0;i<b;i++) scanf("%lld",&q[i]);
    for(i=0;i<c;i++) scanf("%lld",&r[i]);
    qsort(p,a,sizeof(long long),asc);
    qsort(q,b,sizeof(long long),asc);
    qsort(r,c,sizeof(long long),asc);
    ll max=r[0],ans=0,countp=0,countq=0,countr=0;
    ll count=0,all=x+y;
    for(;countp<x&&p[countp]>=max,count<all;countp++){
        ans+=p[countp];
        count++;
    }
    for(;count<all,countq<y&&q[countq]>=max;countq++){
        ans+=q[countq];
        count++;
    }
    ll z=countp,w=countq;
    for(;countp<x&&count<all;countp++){
        if(max>p[z]&&countr<c){
            ans+=max;
            countr++;
            count++;
            max=r[countr];
        }
        else{
            count++;
            ans+=p[z];
            z++;
        }
    }
    for(;countq<y&&count<all;countq++){
        if(max>q[w]&&countr<c){
            ans+=max;
            countr++;
            count++;
            max=r[countr];
        }
        else{
            count++;
            ans+=q[w];
            w++;
        }
    }
    printf("%lld\n",ans);
    return 0;
}

Score : 500 points

Problem Statement

You are going to eat X red apples and Y green apples.

You have A red apples of deliciousness p_1,p_2, \dots, p_A, B green apples of deliciousness q_1,q_2, \dots, q_B, and C colorless apples of deliciousness r_1,r_2, \dots, r_C.

Before eating a colorless apple, you can paint it red or green, and it will count as a red or green apple, respectively.

From the apples above, you will choose the apples to eat while making the sum of the deliciousness of the eaten apples as large as possible.

Find the maximum possible sum of the deliciousness of the eaten apples that can be achieved when optimally coloring zero or more colorless apples.

Constraints

1 \leq X \leq A \leq 10^5

1 \leq Y \leq B \leq 10^5

1 \leq C \leq 10^5

1 \leq p_i \leq 10^9

1 \leq q_i \leq 10^9

1 \leq r_i \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

X Y A B C
p_1 p_2 ... p_A
q_1 q_2 ... q_B
r_1 r_2 ... r_C

Output

Print the maximum possible sum of the deliciousness of the eaten apples.

Sample Input 1

1 2 2 2 1
2 4
5 1
3

Sample Output 1

12

The maximum possible sum of the deliciousness of the eaten apples can be achieved as follows:

Eat the 2-nd red apple.

Eat the 1-st green apple.

Paint the 1-st colorless apple green and eat it.

Sample Input 2

2 2 2 2 2
8 6
9 1
2 1

Sample Output 2

25

Sample Input 3

2 2 4 4 4
11 12 13 14
21 22 23 24
1 2 3 4

Sample Output 3

74


#include<stdio.h>

/* 値を入れ替える関数 */
void swap (int *x, int *y) {
  int temp;    // 値を一時保存する変数

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

/* バブルソート */
void bubble_sort (int array[], int array_size) {
  int i, j;

  for (i = 0; i < array_size - 1; i++){
    for (j = array_size - 1; j >= i + 1; j--){   //　右から左に操作
      if (array[j] < array[j-1]) { swap(&array[j], &array[j-1]); }
    }
  }
}

int main(){
    int x, y, a,b,c;
    int p[100000], q[100000], r[100000];
    long res;
    int i ;
    int xIndex, yIndex;
    int n, sum = 0;
    // char s[6] = {};
    int flag = 0;

    scanf("%d %d %d %d %d ", &x, &y, &a,&b,&c);
    // scanf("%s", s);

    for(i = 0; a > i; i++){
        scanf("%d", &p[i]);
    }
    for(i = 0; b > i; i++){
        scanf("%d", &q[i]);
    }
    for(i = 0; c > i; i++){
        scanf("%d", &r[i]);
    }

    bubble_sort(p, a);
    bubble_sort(q,b);
    bubble_sort(r, c);

    xIndex = 0;
    yIndex = 0;

    if(x>y){
        for(i=0;i<x;i++){
            if(p[i-xIndex] < r[xIndex]){
                res += r[xIndex];
                xIndex++;
            } else {
                res += p[i - xIndex];
            }
        }

        for(i=0;i<y;i++){
            if(q[i-yIndex] < r[xIndex+yIndex]){
                res += r[xIndex+yIndex];
                yIndex++;
            } else {
                res += p[i - yIndex];
            }
        }
    } else {
        for(i=0;i<y;i++){
            if(q[i-yIndex] < r[yIndex]){
                res += r[yIndex];
                yIndex++;
            } else {
                res += p[i - yIndex];
            }
        }

        for(i=0;i<x;i++){
            if(p[i-xIndex] < r[xIndex+yIndex]){
                res += r[xIndex+yIndex];
                xIndex++;
            } else {
                res += p[i - xIndex];
            }
        }
    }

    for(i=0;i<x;i++){
        printf("%d ",res);
    }
    return 0;

}


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

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

int main(void)
{
    ll p[120000] = {0};
    ll q[120000] = {0};
    ll r[120000] = {0};
    int X, Y, A, B, C;
    int n, m, i;
    ll max = 0, t;
    scanf("%d%d%d%d%d", &X, &Y, &A, &B, &C);
    for (i = 0; i < A; i++)
    {
        scanf("%lld", &t);
        p[i] = t;
    }
    for (i = 0; i < B; i++)
    {
        scanf("%lld", &t);
        q[i] = t;
    }
    for (i = 0; i < C; i++)
    {
        scanf("%lld", &t);
        r[i] = t;
    }

    qsort(p, A, sizeof(ll), compare_int);
    qsort(q, B, sizeof(ll), compare_int);
    qsort(r, B, sizeof(ll), compare_int);

    int x = X - 1;
    int y = Y - 1;
    int j = 0;

    while (1)
    {
        if ((p[x] < q[y]) && (p[x] < r[j]))
        {
            p[x] = r[j];
            x--;
            j++;
        }
        else if ((p[x] > q[y]) && (q[y] < r[j]))
        {
            q[y] = r[j];
            y--;
            j++;
        }
        else
        {
            break;
        }
    }
    for (i = 0; i < X; i++)
    {
        max += p[i];
    }
    for (i = 0; i < Y; i++)
    {
        max += q[i];
    }
    printf("%lld\n", max);
    return 0;
}


#include <stdio.h>

int main(){
  long long int a,b,c;
  scanf("%lld,%lld,%lld",&a,&b,&c);
  long long int d=c-a-b;
  if(4LL*a*b<d*d) printf("Yes\n");
  else printf("No\n");
  return 0;
}

Score : 300 points

Problem Statement

Does \sqrt{a} + \sqrt{b} < \sqrt{c} hold?

Constraints

1 \leq a, b, c \leq 10^9

All values in input are integers.

Input

Input is given from Standard Input in the following format:

a \ b \ c

Output

If \sqrt{a} + \sqrt{b} < \sqrt{c}, print Yes; otherwise, print No.

Sample Input 1

2 3 9

Sample Output 1

No

\sqrt{2} + \sqrt{3} < \sqrt{9} does not hold.

Sample Input 2

2 3 10

Sample Output 2

Yes

\sqrt{2} + \sqrt{3} < \sqrt{10} holds.


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

int main(void){
	long long int a, b, c;
	long double A, B, C;
	scanf("%lld %lld %lld", &a, &b, &c);
	A = sqrt(a); B = sqrt(b); C = sqrt(c);
	if (A + B < C) {
		printf("Yes");
	}
	else
	{
		printf("No");
	}
	return 0;
}


#include<stdio.h>
int main()
{
    int a,b,c;
    float d,e;
    scanf("%d%d%d",&a,&b,&c);
    d=sqrt(a)+sqrt(b);
    e=sqrt(c);
    if(d<e)
        printf("Yes");
    else
        printf("No");
}


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

int main(){
    char token[1000]={};
    unsigned long long a=0,b=0,c=0;
    unsigned long long left=0,right=0;
    while(fgets(token, sizeof(token), stdin)!=NULL){
        a=atoi(strtok(token, " "));b=atoi(strtok(NULL, " "));c=atoi(strtok(NULL, " "));
        right=c-a-b;right*=right;
        left=4*a*b;
        if(right>left) printf("Yes");
        else printf("No");
    }
    return 0;
}


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

int main(){
   long double a,b,c;scanf("%lf %lf %lf",&a,&b,&c);
   if((sqrtl(a)+sqrtl(b))<sqrtl(c))printf("Yes\n");
   else printf("No\n");
   return 0;
}