akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;
public class Main {
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		//int a = sc.nextInt();
		// スペース区切りの整数の入力
		//int b = sc.nextInt();
		//int c = sc.nextInt();
		// 文字列の入力
		//String s = sc.next();
		//1文字ずつ
		//s.atChar(i);
		// 出力
		//System.out.println("");
		
		String S=sc.next();
		//int pointer=0;
		//int leng=S.length();
		char x=S.charAt(0);
		char y=S.charAt(1);
		char z=S.charAt(2);
		boolean t=false;
		if(x=='a' && y=='b' && z=='c')t=true;
		if(x=='a' && y=='c' && z=='b')t=true;
		if(x=='b' && y=='a' && z=='c')t=true;
		if(x=='b' && y=='c' && z=='a')t=true;
		if(x=='c' && y=='a' && z=='b')t=true;
		if(x=='c' && y=='b' && z=='a')t=true;	
		if(t){
			System.out.println("Yes");	
		}else{
			System.out.println("No");	
		}
	}
}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define pii pair<int , int>
#define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MAXX 100005

ll n , m;
ll a[MAXX];
ll b[MAXX];

int main()
{
    _FastIO;
    cin >> n >> m;
    vector<pair<ll , ll> > v;
    for(ll i = 0; i < n; i++){
        cin >> a[i] >> b[i];
        v.push_back({a[i] , b[i]});
    }
    sort(v.begin() , v.end());
    ll s = m;
    ll ans = 0;
    for(ll i = 0; i < n; i++){
        ll x = v[i].first;
        ll y = v[i].second;
        if(s >= y){
            ans += x * y;
            s -= y;
        }
        else{
            ans += x * s;
            s = 0;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3568
// Written By NewbieChd
#include <cstdio>
#include <cctype>
#include <cstring>
#include <algorithm>
using namespace std;

const int BUF = 1000000;
char buf[BUF], *p1, *p2;
inline char getChar() { return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, BUF, stdin), p1 == p2) ? EOF : *p1++; }
inline int read() {
    int f = 0;
    bool b = 1;
    char c;
    while (!isdigit(c = getChar()))
        if (c == 45)
            b = 0;
    do
        f = f * 10 + (c ^ 48);
    while (isdigit(c = getChar()));
    return b ? f : ~f + 1;
}

const int maxN = 1000003;
bool notPrime[maxN];
int prime[maxN];
inline int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }

int a[maxN], tax[maxN], p;
inline void plus(int& x, int y) { x = (x + y) % p; }

int ans[maxN];

int main() {
    int n = read(), m = 0, i, j, cnt = 0;
    for (i = n; ~i; --i) {
        a[i] = read();
        if (a[i])
            m = gcd(a[i] > 0 ? a[i] : -a[i], m);
    }
    for (i = 2; i * i <= m; ++i)
        if (m % i == 0) {
            ans[++cnt] = i;
            while (m % i == 0)
                m /= i;
        }
    if (m > 1)
        ans[++cnt] = m;
    int cntP = 0;
    for (i = 2; i <= n; ++i) {
        if (!notPrime[i])
            prime[++cntP] = i;
        for (j = 1; j <= cntP && i * prime[j] <= n; ++j) {
            notPrime[i * prime[j]] = 1;
            if (i % prime[j] == 0)
                break;
        }
    }
    for (j = 1; j <= cntP; ++j)
        if (a[0] % prime[j] == 0) {
            p = prime[j], memset(tax, 0, sizeof(int) * (p - 1));
            for (i = 0; i <= n; ++i)
                plus(tax[i % (p - 1)], a[i]);
            for (i = 0; i < p - 1; ++i)
                if (tax[i])
                    break;
            if (i == p - 1)
                ans[++cnt] = p;
        }
    sort(ans + 1, ans + cnt + 1), cnt = unique(ans + 1, ans + cnt + 1) - ans - 1;
    // printf("%d\n", cnt);
    for (i = 1; i <= cnt; ++i)
        printf("%d\n", ans[i]);
    return 0;
}


Measured memory_bytes: 8448
#include <bits/stdc++.h>
#include <cassert>
typedef long long int ll;
using namespace std;

// @@ !! LIM()

int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll N; cin >> N;
  ll sum = 0;
  for (ll i = 0; i < N; i++) {
    ll a; cin >> a;
    sum += a;
  }
  cout << sum - N << endl;

  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define MAXN 100010
#define rep(i,n) for (int i = 0; i < (n); ++i)
const ll mod = 1e9+7;


int main() {
    double W, H, x, y;
    cin >> W >> H >> x >> y;
    double ans =  W * H / 2.0;
    cout << ans << " ";
    if (x == W/2 * 1.0 && y == H/2 * 1.0) cout << 1 << endl;
    else cout << 0 << endl;
}



Measured memory_bytes: 256
from sys import stdin
s = str(stdin.readline().rstrip())

if s==s[::-1]:
    n=len(s)
    s2 = s[:int((n-1)/2)]
    if s2==s2[::-1]:
        s3 = s[int((n+3)/2)-1:]
        if s3==s3[::-1]:
            print("Yes")
            exit()

print("No")
exit()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;

int main(){
  int min=1000,max=0,N;
  cin >> N;
  int A[N];
  for(int i=0;i<N;i++){
    cin >> A[i];
    if(A[i]>max){max=A[i];}
    if(A[i]<min){min=A[i];}
  }
  cout << max-min << endl;
  return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


class Main{
	public static void main(String[] args)throws IOException{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String name;
		int num;
		double prc=100;
		long hen=0;
		while(true){

			try{
				prc=100;
				hen=0;
				num=0;

				name=br.readLine();
				num=Integer.parseInt(name);

				for(int i=0; i<num; i++){
					prc*=1.05;
					prc=Math.ceil(prc);
				}

				hen=(long) prc;
				System.out.println(hen*1000);

			}

			catch(Exception e){
				System.exit(0);
			}
		}
	}
}

Measured memory_bytes: 24060
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int main(){

    ll N;
    cin >> N;
    map<ll, ll>cnt;
    ll ans = 0;
    for(ll i = 0; i < N; i++){
        ll a;
        cin >> a;
        cnt[a]^=1;
        if(cnt[a])ans++;
        else ans--;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 6528
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<set>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,int> piii;
typedef pair<ll,ll> pll;

#define reps(i,f,n) for(int i = int(f); i <= int(n); i++)
#define rep(i,n) reps(i,0,int(n)-1)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)

#define all(x) (x).begin(),(x).end()
#define X first
#define Y second

#define sz size()
#define eb emplace_back

int cday[1024][16][32];

int main(void){
  int n, y, m, d;
  int cnt = 0;
  reps(i,1,1000){
    reps(j,1,10){
      reps(k,1,20){
        if(i%3 != 0 && j%2 == 0 && k > 19)break;
        cday[i][j][k] = ++cnt;
      }
    }
  }
  cin >> n;
  rep(l,n){
    cin >> y >> m >> d;
    cout << cday[1000][1][1] - cday[y][m][d] << endl;
  }

  return 0;
}

Measured memory_bytes: 5040
#include <cstdio>
using namespace std;

int main(){	
	for(int m,n,i,j,k,a;a=1,scanf("%d",&m),m;puts(a?"OK":"NG")){
		int d[300]={0},g[300][300]={0};
		scanf("%d",&n);
		for(i=1;i<=n;)scanf("%d",d+i++);
		for(i=0;i<=n;i++)
			for(j=1;j<=m;j++)
				k=i+j+d[i+j],(k=k<0?0:n+1<k?n+1:k),g[i][k]=1;
		for(k=0;k<n+2;k++)
			for(i=0;i<n+2;i++)
				for(j=0;j<n+2;j++)
					if(g[i][k]&&g[k][j])g[i][j]=1;
		for(i=0;i<=n;i++)
			if(g[0][i]&&!g[i][n+1])a=0;
	}
}

Measured memory_bytes: 1372
#include <iostream>
#include <vector>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <cmath>
#include <utility>
#include <bitset>
#include <queue>
#include <stack>
#include <limits>
#include <list>

using namespace std;
using ll = long long;
const ll INF = numeric_limits<ll>::max();
const int MOD = 1000000007;

void chmin(ll &a, ll b)
{
    if (a > b)
    {
        a = b;
    }
}
void chmax(ll &a, ll b)
{
    if (a < b)
    {
        a = b;
    }
}

int main()
{
    ll N;
    cin >> N;
    vector<ll> heights = vector<ll>(N);
    for (int i = 0; i < N; i++)
    {
        ll h;
        cin >> h;
        heights[i] = h;
    }

    vector<ll> dp = vector<ll>(N, INF);
    dp[0] = 0;

    for (int i = 0; i < N; i++)
    {
        chmin(dp[i], dp[i - 1] + abs(heights[i] - heights[i - 1]));
        if (i > 1)
        {
            chmin(dp[i], dp[i - 2] + abs(heights[i] - heights[i - 2]));
        }
    }
    cout << dp[N - 1] << endl;
}

Measured memory_bytes: 1792
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;

ll Sign(ll a){return (a>0?1:(a==0?0:-1));}

struct Q{
    ll up,down;
    
    Q(ll a=1):up(a),down(1){}
    
    Q(ll a,ll b):up(a),down(b){}
    
    Q(const Q &A):up(A.up),down(A.down){}
    
    ll gcd(ll a,ll b){
        if(a%b==0){return b;}
        return gcd(b,a%b);
    }
    
    Q& operator *= (const Q &A){up*=A.up; down*=A.down; return *this;}
    
    Q& operator /= (const Q &A){up*=A.down; down*=A.up; return *this;}
    
    Q& operator += (const Q &A){up*=A.down; up+=A.up*down; down*=A.down; return *this;}
    
    Q& operator -= (const Q &A){up*=A.down; up-=A.up*down; down*=A.down; return *this;}
    
    Q& normalize(){ll g=gcd(abs(up),abs(down)); up/=g; down/=g; if(down<0){down*=-1; up*=-1;} return *this;}
    
    Q operator * (const Q &A) const {Q ret(*this); ret*=A; return ret;}
    
    Q operator / (const Q &A) const {Q ret(*this); ret/=A; return ret;}
    
    Q operator + (const Q &A) const {Q ret(*this); ret+=A; return ret;}
    
    Q operator - (const Q &A) const {Q ret(*this); ret-=A; return ret;}
    
    bool operator < (const Q &A) const {return (Sign(down)*Sign(A.down)>0?up*A.down<down*A.up:up*A.down>down*A.up);}
    
    bool operator <= (const Q &A) const {return (Sign(down)*Sign(A.down)>0?up*A.down<=down*A.up:up*A.down>=down*A.up);}
    
    bool operator > (const Q &A) const {return (Sign(down)*Sign(A.down)>0?up*A.down>down*A.up:up*A.down<down*A.up);}
    
    bool operator >= (const Q &A) const {return (Sign(down)*Sign(A.down)>0?up*A.down>=down*A.up:up*A.down<=down*A.up);}
    
    bool operator == (const Q &A) const {return up*A.down==down*A.up;}
    
    bool operator != (const Q &A) const {return up*A.down!=down*A.up;}
};


ll cul(Q p,ll a,ll n,ll mi,ll k){
    if(n==0){return p==0?1:0;}
    if(p==0){return 1;}
    if(p<0){return 0;}
    ll ret=0;
    for(ll i=mi;i*k<=a && p<=Q(n,i);i++){
        ret+=cul(p-Q(1,i),a,n-1,i,k*i);
    }
    return ret;
}


int main(){
    ll p,q,a,n;
    while(cin>>p>>q>>a>>n){
        if(p==0){return 0;}
        cout<<cul(Q(p,q),a,n,1,1)<<endl;
    }
    
    return 0;
}



Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int main()
{
	long long n,a[100100],h=0,ans=0;
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>a[i];
	for(int i=0;i<n;i++)
	{
		if(a[i]>=a[i+1] &&i!=n-1)
		{
			h++;
			//cout<<h<<endl;
		}
		if(a[i]<a[i+1] ||i==n-1)
		{
			ans=max(ans,h);
			h=0; 
		}
	}
	cout<<ans<<endl;			
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 int H,W;
  cin >> H >>W;
  for (int i = 0; i < W+2; i++) {
    cout<<'#';
}
  cout<<endl;
  for (int i = 0; i < H; i++) {
    cout<<'#';
    string s;
    cin>>s;
    cout <<s;
    cout<<'#';
    cout<<endl;
}
  for (int i = 0; i < W+2; i++) {
    cout<<'#';
}
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORS(i, m, n) for (int i = m; i <= n; i++)
#define INF 2e9
#define MOD (1000000007)
#define EPS 1e-9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long long int lli;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int N = s.size();
    char d[2] = {'0', '1'};
    int count = 0;
    REP(i, N)
    {
        if (s[i] == d[i % 2])
        {
            count++;
        }
    }
    cout << min(count, N - count) << "\n";
}

Measured memory_bytes: 512
n = gets.to_i
move_maxs = readlines.map{|move_max| move_max.to_i}
move_minute = 0
move_maxs.each_with_index do |max,i|
  move_minute = [(n - 1) / max + 1 + i, move_minute + 1].max
end
puts move_minute

Measured memory_bytes: 1788
using System;
using System.Linq;
using System.IO;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using System.Text.RegularExpressions;
 
class Program
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        int[] a = Console.ReadLine().Split(' ')
                    .Select(elem => int.Parse(elem))
                    .ToArray();
        const int NumOfColors = 8;
        bool[] colors = new bool[NumOfColors];
        int NumberOfFreeColor = 0;
        for (int i = 0; i < n; i++)
        {
            if (a[i] >= 3200) 
            {
                NumberOfFreeColor++;
                continue;
            }
            for (int j = 0; j < NumOfColors; j++)
            {
                if (!colors[j] && 400 * j <= a[i] && a[i] < 400 * (j + 1))
                {
                    colors[j] = true;
                }
            }
        }
        int cnt = colors.Where(elem => elem).Count();
        int min = Math.Max(1, cnt);
        int max = cnt + NumberOfFreeColor;
        Console.WriteLine("{0} {1}", min, max);
    }
}


Measured memory_bytes: 13396
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main()
{
    int N, M, X;
    cin >> N >> M >> X;
    vector<int> A(M,0);
    for(int i=0; i<M; ++i){
        cin >> A[i];
    }

    int left = 0;
    int right = 0;
    for(int i=0; i<M; ++i){
        if( A[i] < X) 
            ++left;
        else
            ++right;
    }
    cout << min(left, right) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <stack>
#include <algorithm>
using namespace std;

typedef long long ll;
typedef pair<int,ll> pil;

const int N = 2e5 + 5;
const int LOG = 50;

int a[N];
int first[N], last[N];
pil nxt[LOG][N];
int u[N];

int main()
{
    int n;
    ll k;
    scanf("%d%lld", &n, &k);
    --k;

    for (int x = 0; x < N; ++x)
        first[x] = last[x] = -1;

    for (int i = 0; i < n; ++i)
    {
        scanf("%d", a + i);
        if (first[a[i]] == -1)
            first[a[i]] = i;
        else
            nxt[0][last[a[i]]] = {(i + 1) % n, i + 1 == n};
        last[a[i]] = i;
    }
    for (int x = 0; x < N; ++x)
        if (last[x] != -1) nxt[0][last[x]] = {(first[x] + 1) % n, 1 + (first[x] + 1 == n)};

    for (int t = 0; t < LOG - 1; ++t)
    {
        for (int i = 0; i < n; ++i)
        {
            int j = nxt[t][i].first;
            nxt[t + 1][i] = {nxt[t][j].first, nxt[t][j].second + nxt[t][i].second};
        }
    }

    int pos = 0;
    for (int t = LOG - 1; t >= 0; --t)
    {
        if (nxt[t][pos].second <= k)
        {
            k -= nxt[t][pos].second;
            pos = nxt[t][pos].first;
            t = LOG - 1;
        }
    }

    stack<int> St;
    for (int x = 0; x < N; ++x)
        u[x] = 0;
    for (int i = pos; i < n; ++i)
    {
        if (!u[a[i]])
            St.push(a[i]);
        else
        {
            while(St.top() != a[i])
            {
                u[St.top()] = 0;
                St.pop();
            }
            St.pop();
        }

        u[a[i]] ^= 1;

        if (i == n - 1 && k > 0)
        {
            i = -1;
            --k;
        }
    }

    vector<int> out;
    while(!St.empty())
    {
        out.push_back(St.top());
        St.pop();
    }

    reverse(out.begin(), out.end());
    for (int x : out)
        printf("%d ", x);
}


Measured memory_bytes: 162464
#include<stdio.h>
#include<string.h>
int main(){
    char a[10],b[10],c[10];
    scanf("%s %s %s",a,b,c);
    a[0]=a[0]-32;
    b[0]=b[0]-32;
    c[0]=c[0]-32;
    printf("%c%c%c\n",a[0],b[0],c[0]);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  double sum=0;
  for ( int i=0; i<n; i++ ) cin >> a[i];
  for ( int i=0; i<n; i++ ) sum += a[i];
  sum/=n;
  int id=0;
  double dist=100;
  for ( int i=0; i<n; i++ ) if ( fabs(sum-a[i])<dist ) { id=i; dist=fabs(sum-a[i]); }
  cout << id << '\n';
  return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;

int main(){
    int N;
    cin >> N;

    for(int i = 1; i < 10; i++){
        for(int j = 1; j < 10; j++){
            if(i * j == N){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }

    cout << "No" << endl;

}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<algorithm>

using namespace std;

int main()
{string S,T; cin >> S >> T;
 sort(S.begin(),S.end());
 sort(T.begin(),T.end());
 reverse(T.begin(),T.end());
 if( S < T){cout << "Yes" << endl;}
 else{cout << "No" << endl;}
 return 0;}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int a,b,n,c,d,i,flg;
	scanf("%d %d %d",&a,&b,&n);
	flg=0;
	for(i=0;i<n;i++){
		scanf("%d %d",&c,&d);
		if((c>=a||d>a)&&(c<b||d<=b)) flg=1;
	}
	printf("%d\n",flg);
	return 0;
}


Measured memory_bytes: 2764
#include <cmath>
#include <cstdio>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
//Quick Read
long long Read(){
	long long x=0;
	bool neg=false;
	char c=getchar();
	while(isdigit(c)==false)neg^=c=='-',c=getchar();
	while(isdigit(c)==true)x=x*10+c-'0',c=getchar();
	return neg==true?-x:x;
}
//Solve
inline long long Solve(long long a,long long b){return a==0?-b:(b/a)*(2*a)+Solve(b%a,a);}
//Main
int main(){
	// freopen("AGC001B.in","r",stdin);
	// freopen("AGC001B.out","w",stdout);
	long long n=Read(),x=Read(),a=x,b=n-x;
	if(a>b)std::swap(a,b);
	long long ans=n+Solve(a,b);
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;

bool f(void){
	int x[10], a=0, b=0;
	for (int i=0; i<10;i++)
		cin>>x[i];
	for (int i=0; i<10; i++){
		int e=x[i];
		if (e>a) a=e;
		else if (e>b) b=e;
		else return false;
	}
	return true;
}

int main(void){

	int n;
	cin>>n;
	while (n--){
		if (f()) cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
	}
	return 0;
}

Measured memory_bytes: 1152
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = (ll)1e16 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int n, a, b;
vector<ll> v;

ll comb(ll n, ll k) {
    if (n < k) return 0LL;
    if (k == 0) return 1LL;
    return n * comb(n-1, k-1) / k;
}

void solve() {
    sort(RALL(v));

    int k = 0;
    while (k < n && v[0] == v[k]) k++;
    if (k >= a) {
        cout << v[0] << endl;
        ll num = 0;
        for (int i = a; i <= b; i++) {
            num += comb(k, i);
        }
        cout << num << endl;
    } else {
        ll sum = 0;
        for (int i = 0; i < a; i++) sum += v[i];
        cout << (double)sum / a << endl;
        int same_a = 0;
        for (int i = 0; i < n; i++)
            if (v[i] == v[a-1])
                same_a++;
        int same_b = 0;
        for (int i = 0; i < a; i++)
            if (v[i] == v[a-1])
                same_b++;
        cout << comb(same_a, same_b) << endl;
    }
}

void input() {
    cin >> n >> a >> b;
    ll t;
    for (int i = 0; i < n; i++) {
        cin >> t;
        v.push_back(t);
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);

    input();
    solve();
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cctype>
#include<iostream>
#include<string>
#include<sstream>
#include<set>
#include<map>
#include<vector>
#include<algorithm>
#include<queue>
#include<utility>
using namespace std;
#define i64 long long int

struct mod_arith {
	int mod;
	mod_arith() {
		mod = 1000000007;
	}
	void set_mod(int _mod) { mod = _mod; }
	int add(int x, int y) { return (x + y) % mod; }
	int sub(int x, int y) { return (x - y + mod) % mod; }
	int mul(int x, int y) { return (int)((long long int)x*y%mod); }
	int pw(int x, i64 y) {
		int r = 1;
		while (1) {
			if (y & 1)r = mul(r, x);
			if (y >>= 1)x = mul(x, x);else
				break;
		}
		return r;
	}
};

mod_arith ma;

int dp[111],h[111];
int h2[111], m, n;
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &h[i]);
		h2[i] = h[i];
	}
	m = n + 1;
	h2[n] = 1;
	sort(h2, h2 + m);
	m = unique(h2, h2 + m) - h2;
	for (int i = 0; i < n; i++) {
		h[i] = lower_bound(h2, h2 + m, h[i])-h2;
	}
	dp[0] = 1;
	for (int i = 0; i < n; i++) {
		for (int j = 1; i + j <= n; j++) {
			i64 cur = 0;
			for (int H = 0; H < m - 1; H++) {
				int S = i, E = i + j;
				while (1) {
					for (; S < E && h[S] <= H; S++);
					if (S == E)break;
					int T = S;
					for (;T < E && h[T] > H; T++);
					bool flag = true;
					if (S == i && (i > 0 && h[i - 1] > H))flag = false;
					if (T == E && (E < n && h[E] > H))flag = false;
					if (flag) {
						cur += h2[H + 1] - h2[H];
					}
					S = T;
				}
			}
			dp[i + j] = ma.add(dp[i + j], ma.mul(dp[i], ma.pw(2, cur)));
		}
	}
	printf("%d\n", ma.mul(dp[n], 2));
	return 0;
}

Measured memory_bytes: 384
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>
#include <cassert>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using Int = long long int;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//edit
class Solve {
public:
    void solve() {
        Int N, P;
        cin >> N >> P;
        string s;
        cin >> s;

        if (P == 2 || P == 5) {
            Int ans = 0;
            for (int i = 0; i < N; ++i) {
                if ((s[i] - '0') % P == 0) {
                    ans += i + 1;
                }
            }
            cout << ans << endl;
            return;
        }


        reverse(all(s));
        vector<Int> neri(P);
        neri[0] = 1;
        Int sum = 0;
        Int base = 1;
        for (int i = 0; i < s.size(); ++i) {
//            sum *= 10;
            sum += (s[i] - '0') * base;
            sum %= P;
            neri[sum]++;

            base = base * 10 % P;
        }
        Int ans = 0;
        for (int i = 0; i < P; ++i) {
            Int tmp = neri[i] * (neri[i] - 1) / 2;
            ans += tmp;
        }
        cout << ans << endl;
    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    Solve().solve();


    return 0;
}


Measured memory_bytes: 832
#include<stdio.h>
#include<iostream>

using namespace std;

int main()
{
	int r, d, x0, x[10];
	cin >> r;
	cin >> d;
	cin >> x0;
	x[0] = r * x0 - d;
	for (int i = 0; i < 9; i++)
	{
		x[i + 1] = r * x[i] - d;
		cout << x[i] << endl;
	}
	cout << x[9] << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <limits.h>


using namespace std;

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

    int total = 0;
    int *A = new int[N];
    for (int i = 0; i < N; i++) {
        scanf("%d", &A[i]);
        total += A[i];
    }

    uint64_t *lTable = new uint64_t[N];
    uint64_t *rTable = new uint64_t[N];
    uint64_t lr[2] = {0, 0};
    for (int i = 0; i < N; i++) {
        lr[0] += A[i];
        lTable[i] = lr[0];
        lr[1] += A[N-i-1];
        rTable[N-i-1] = lr[1];
    }

    uint64_t m = UINT64_MAX;
    for (int i = 0; i < N-1; i++) {
//        if (A[i] < 2)
//            continue;
        uint64_t n = (lTable[i] > rTable[i+1] ? lTable[i] - rTable[i+1] : rTable[i+1] - lTable[i]);
        if (m > n) {
            m = n;
        } else {
            break;
        }
    }

    delete []lTable;
    delete []rTable;

    printf("%llu", m);
}


Measured memory_bytes: 4096
#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = m; i < (n); i++)
#define RFOR(i, m, n) for (int i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define print(ele) cout << ele << endl
#define print10(ele) cout << fixed << setprecision(10) << ele << endl

using namespace std;
typedef long long ll;
typedef vector<int> ivec;
typedef vector<string> svec;
typedef vector<ll> lvec;

const int mod = 1e9 + 7;
const ll INF = 1000000000000000000LL;

int main() {
  int n, m;
  cin >> n >> m;
  ivec s(m);
  vector<char> c(m);
  REP(i, m) { cin >> s[i] >> c[i]; }

  REP(i, pow(10, n)) {
    string num = to_string(i);
    if (num.size() == n) {
      bool ok = true;
      REP(j, m) {
        if (num[s[j] - 1] != c[j]) ok = false;
      }
      if (ok) {
        print(num);
        return 0;
      }
    }
  }
  print(-1);
  return 0;
}

Measured memory_bytes: 256
/* ＵＴＦ－８ */
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>
#include <limits>

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

#define USE_COLORED 1

#ifdef USE_COLORED
static const char stdout_pre[]  = "\033[1m"; // bold black
static const char stderr_pre[]  = "\033[31;1m"; // bold red
static const char stdxxx_post[] = "\033[m";

// 当然ながら GCC(g++)/libstdc++ 依存
#include <ext/stdio_filebuf.h>
using stdio_filebuf = __gnu_cxx::stdio_filebuf<char>;
class colored_stdio_filebuf : public stdio_filebuf {
private:
	const char* const pre_;
	const char* const post_;

public:
	colored_stdio_filebuf(FILE* fp, const char* pre, const char* post) : stdio_filebuf(fp, std::ios_base::out), pre_(pre), post_(post)
	{
	}

protected:
	std::streamsize xsputn(const char* s, std::streamsize count) override
	{
		stdio_filebuf::xsputn(pre_, strlen(pre_));
		auto ret = stdio_filebuf::xsputn(s, count);
		stdio_filebuf::xsputn(post_, strlen(post_));
		return ret;
	}
};
#endif

int main()
{
#ifdef USE_COLORED
	if (getenv("DEBUG")) {
		std::cout.rdbuf(new colored_stdio_filebuf(stdout, stdout_pre, stdxxx_post));
		std::cerr.rdbuf(new colored_stdio_filebuf(stderr, stderr_pre, stdxxx_post));
	} else
#endif
	{
		int fd = open("/dev/null", O_WRONLY);
		dup2(fd, 2);
		close(fd);
	}
	
	std::string S, T;
	int A, B;
	std::string U;
	
	std::cin >> S >> T >> A >> B >> U;

	if (U == S)
		--A;
	else
		--B;

	std::cout << A << " " << B << "\n";
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
int a[100010];
int main(){
    int n;
    while(cin>>n){
        ll ans=0;
        for(int i=1; i<=n; ++i){
        	if(i%3 && i%5){
        		ans+=i;
        	}
        }
        printf("%lld\n",ans);
    }
  return 0;
}




Measured memory_bytes: 3764
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
const ll MOD=1000000007;
const long double PI=3.14159265358979;
const ll MAX=0;


ll ff(ll x,ll n,ll a){
  if(x==0){
    return a;
  }
  x%=n;
  ll nx=x;
  ll nn=0;
  while(nx>0){
    if(nx%2==1){
      nn++;
    }
    nx/=2;
  }
  return ff(x,nn,a+1);
}

ll f(string x,ll n){
  ll x1=0,a=1;
  if(n==0){
    return 0;
  }
  for(int i=x.size()-1;i>=0;i--){
    if(x[i]=='1'){
      x1+=a;
    }
    a*=2;
    a%=n;
    x1%=n;
  }
  
  return x1;
}
      

int main() {
  ll N;
  string X;
  cin>>N>>X;
  ll num=0;ll a[N];
  rep(i,N){
    if(X[i]=='1'){
      num++;
    }
  }
  ll n1=f(X,num+1);
//  cout<<n1;
  ll n2=f(X,num-1);
  ll a1=1,a2=1;
  for(int i=N-1;i>=0;i--){
    string x=X;ll n=num;
    if(X[i]=='0'){
      x[i]='1';n++;ll n11=a1+n1;n11%=num+1;
      ll nx=n11;
      ll nn=0;
      while(nx>0){
        if(nx%2==1){
          nn++;
        }
        nx/=2;
      }
      a[i]=ff(n11,nn,1);
    }
    else{
      x[i]='0';n--;ll n22=n2-a2;
      if(n==0){
        a[i]=0;
        continue;
      }
      n22%=num-1;
      if(n22<0){
        n22+=num-1;
      }
      ll nx=n22;
      ll nn=0;
      while(nx>0){
        if(nx%2==1){
          nn++;
        }
        nx/=2;
      }
      a[i]=ff(n22,nn,1);
    }
    
    
    //cout<<ff(x,n,1)<<endl;
    a1*=2;
    a1%=num+1;a2*=2;
    if(num==1){
      continue;
    }
    a2%=num-1;
  }
  
      
  for(int i=0;i<N;i++){
    cout<<a[i]<<endl;//cout<<0%2;
  }
}



Measured memory_bytes: 5340
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;

int n;
ll S=0;
vector<ll> a,pos={INF},neg;

void solve(){
    cin >> n;
    a.resize(n,0);
    rep(i,n){
        cin >> a[i];
        if (a[i]>=0) pos.push_back(a[i]);
        else neg.push_back(a[i]);
    }
    rep(i,n){
        if (a[i]>=0) S+=a[i];
        else S-=a[i];
    }
    if (neg.size()%2==0) {
        cout << S << endl;
    }
    else{
        sort(neg.begin(),neg.end());
        sort(pos.begin(),pos.end());
        cout << S-2*min(pos[0],-neg.back()) << endl;
    }
    


}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    solve();
}

Measured memory_bytes: 2424
#include<bits/stdc++.h>
using namespace std;
int a[200010];
int ans[200010];
int main(){
 int n;
 scanf("%d",&n);
 for(int i=2;i<=n;i++)scanf("%d",&a[i]);
 for(int i=2;i<=n;i++)ans[a[i]]++;
 for(int i=1;i<=n;i++)printf("%d\n",ans[i]);
 }



Measured memory_bytes: 5380
#include<bits/stdc++.h>
using namespace std;

long long gcd(long long a,long long b){
  if(a%b==0)return b;
  else return gcd(b,a%b);
}
long long lcm(long long a,long long b){
  return a/gcd(a,b)*b;
}


int main(){
  int n;
  cin >> n;
  long long t[n];
  int i;
  for(i=0;i<n;i++){
    cin >> t[i];
  }
  long long tmp = t[0];
  for(i=1;i<n;i++){
    tmp = lcm(tmp,t[i]);
  }
  cout << tmp;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
l=[]
for i in range(n):
  l.append(list(map(int,input().split())))
c=0
for i in range(n-1):
  for j in range(i+1,n):
    length=0
    for k in range(m):
      length+=(l[i][k]-l[j][k])**2
    length=length**(1/2)
    if length==int(length):
      c+=1
print(c)

Measured memory_bytes: 3060
from collections import deque
n, q = map(int, input().split())
que = deque()
for _ in range(n):
    x, y = input().split()
    que.append((x, int(y)))
ans = []
time = 0
while len(que) > 0:
    x, y = que[0]
    que.popleft()
    if y > q:
        que.append((x, y - q))
        time += q
    else:
        time += y
        ans.append((x, time))
ans.sort(key = lambda x: x[1])
for i in ans:
    print(*i)



Measured memory_bytes: 14564
#include <bits/stdc++.h>
#define vsort(v) sort(v.begin(), v.end())
#define ll unsigned long long
#define rep(i, s, g) for (ll i = (s); i < (g); i++)
#define MOD 1000000007
using namespace std;
int main()
{
  ll K, x; cin >> K;
  queue<ll> Q;
  for (ll i = 1; i <= 9; i++) {
  	Q.push(i);
  }
  for (ll i = 1; i <= K; i++) {
  	x = Q.front(); Q.pop();
    if (x % 10 != 0) Q.push(10 * x + (x % 10) - 1);
    Q.push(10 * x + (x % 10));
    if (x % 10 != 9) Q.push(10 * x + (x % 10) + 1);
  }
  cout << x << endl;
}

Measured memory_bytes: 5144
#include <stdio.h>
#include<math.h>
#include <stdlib.h>

int main(){
  int i,j,k;
  int N;
  int NX=0;
  int NY=0;
  int max=0;
  scanf("%d",&N);
  char S[N];
  char X[N];
  char Y[N];

  scanf("%s",S);
  NX = 0;
  NY = 0;

  for(j=1;j<N;j++){
    if(S[j]=='W')NY++;
  }
  max = NY+NX;
  for(i=1;i<N;i++){
    if(S[i]=='W')NY--;
    if(S[i-1]=='E')NX++;
    if(NY+NX>max)max = NY+NX;
  }

  printf("%d",N-1-max);
  
  return 0;
}

Measured memory_bytes: 512
N, M = map(int, input().split())

AB_array = [list(map(int, input().split())) for _ in range(N)]

AB_array = sorted(AB_array, key=lambda x: -x[1])

# print(AB_array)

used_array = [0] * M
next_array = [i for i in range(M)]

ans = 0

for AB in AB_array:
    A, B = AB
    # print(A, B)
    ok_flag = 0
    start = M - A
    if start < 0:
        continue
    while(ok_flag == 0):
        start = next_array[start]
        if start == -1:
            next_array[M-A] = -1
            break
        if used_array[start] == 0:
            ok_flag = 1
    else:
        ans += B
        used_array[start] = 1
        next_array[start] = start - 1
        next_array[M-A] = start - 1

print(ans)


Measured memory_bytes: 72024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

int main(){
    string s;
    cin >> s;
    ll n = s.size();
    string t = "CF0";
    ll itr = 0;
    rep(i, 0, n) {
        if(s[i] == t[itr]) itr++;
    }
    cout << (itr == 2 ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 3572
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()
#define MOD 1000000007

ll fact(int n) {
    ll ret = 1;
    FOR(i, 2, n + 1) ret = (ret * i) % MOD;
    return ret;
}

int main() {
    int N, M;
    cin >> N >> M;
    if (abs(N - M) > 1) {
        cout << 0 << endl;
        return 0;
    }

    ll ans = fact(N) * fact(M) % MOD;
    if (N == M) ans = (ans * 2) % MOD;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int N_MAX = 100001;
typedef long long ll;
typedef pair<int,int> P;
int main()
{
  int n,m,i,res=0;
  P b[N_MAX]; // 枝データ
  int c[N_MAX]; // 頂点iの属する集合番号
  int nc[N_MAX]; // 集合jの要素数
  int pc[N_MAX]; // 集合jの先頭の要素番号
  int pi[N_MAX]; // 頂点iと同じ集合の要素へのポインタ
  int pp[N_MAX];
  int i1,i2,s1,s2,p,pt;
  cin >> n >> m;
  for(i=1;i<=n;i++)
    cin >> pp[i];
  for(i=0;i<m;i++)
    cin >> b[i].first >> b[i].second;
  for(i=1;i<=n;i++){
    c[i]=i;
    nc[i]=1;
    pc[i]=i;
    pi[i]=0;
  }
  for(i=0;i<m;i++){
    i1=b[i].first;
    i2=b[i].second;
    if(c[i1]!=c[i2]){
// 集合のマージここから
      s1=c[i1]; s2=c[i2];
      if(nc[s1]<nc[s2]){// 小さい方を潰す【重要】
        s1=c[i2]; s2=c[i1];
      }
      pt=pc[s1];
      p=pc[s2];
      pc[s1]=p;
      nc[s1]+=nc[s2];
      pc[s2]=0;
      nc[s2]=0;
      while(true){
        c[p]=s1;
        if(pi[p]==0) break;
        p=pi[p];
      }
      pi[p]=pt;
// 集合のマージここまで
    }
  }
  for(i=1;i<=n;i++)
    if(c[pp[i]]==c[i])
      res++;
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 6304
#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef pair<ll, ll> p_ll;
typedef vector<pair<ll, ll>> vec_p; //vector<pair<ll, ll>> pairs(n) ,pairs.at(i) = make_pair(i*i, i)

#define ture ture
#define flase false
#define falg flag

#define REP(i, x) for (ll i = 0; i < (ll)(x); i++)
#define REPS(i, x) for (ll i = 1; i <= (ll)(x); i++)
#define RREP(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (ll i = ((ll)(x)); i > 0; i--)
#define all(x) (x).begin(), (x).end()

const ll MOD = pow(10, 9) + 7;
const ll LLINF = pow(2, 61) - 1;//llの最大9*10^18
const int INF = pow(2, 30) - 1;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    ll A,V,B,W,T;
    string S;
    cin >> A>>V>>B>>W>>T;

    if(V<=W){
        cout << "NO" << endl;
    }
    else{
        if(V*T-W*T>=abs(A-B)){
            cout << "YES" << endl;
        }
        else{
            cout << "NO" << endl;
        }
    }
}


Measured memory_bytes: 3648
import re
s = input()
t = input()

s= s.replace('?','.')

n_s = len(s)
n_t = len(t)

res = []

for i in range(n_s-n_t+1):
    m = re.match(s[i:i+n_t],t)
    if not m:continue
    res.append((s[:i]+t+s[i+n_t:]).replace('.','a'))
if not res:
    print('UNRESTORABLE')
else:
    print(min(res))

Measured memory_bytes: 9828
import java.util.*

class Scanner(`in`: java.io.InputStream) {
    private val reader = java.io.BufferedReader(java.io.InputStreamReader(`in`))
    private var tokenizer: StringTokenizer? = null

    fun next(): String {
        if (tokenizer?.hasMoreTokens() != true) {
            tokenizer = StringTokenizer(reader.readLine())
        }
        return tokenizer!!.nextToken()
    }

    fun nextLine(): String {
        return if (tokenizer?.hasMoreTokens() != true) {
            reader.readLine()
        } else tokenizer!!.nextToken("\n")
    }
}

fun main(args: Array<String>) {
    val pw = java.io.PrintWriter(System.out)
    Problem.solve(Scanner(System.`in`), pw)
    pw.flush()
}

object Problem {
    fun solve(sc: Scanner, pw: java.io.PrintWriter) {
        val N = sc.next().toInt()
        val x = sc.next().toLong()
        val a = LongArray(N) { sc.next().toLong() }
        var ans = 0L
        if (a[0] > x) {
            ans += a[0] - x
            a[0] = x
        }
        for (i in 1 until N) {
            val diff = a[i - 1] + a[i] - x
            if (diff > 0) {
                ans += diff
                a[i] -= diff
            }
        }
        pw.println(ans)
    }
}


Measured memory_bytes: 45852
import sys
from heapq import heappop, heapify


def input() -> str:
    return sys.stdin.readline().rstrip("\r\n")


def main():
    x, y, a, b, c = map(int, input().split())
    red = [(-int(s), 'r') for s in input().split()]
    green = [(-int(s), 'g') for s in input().split()]
    colorless = [(-int(s), 'n') for s in input().split()]
    apples = red + green + colorless
    heapify(apples)
    cnt = {'r': x, 'g': y, 'n': -1}
    res = 0
    while sum(cnt.values()) + 1 and apples:
        num, clr = heappop(apples)
        if cnt[clr] == 0:
            continue
        cnt[clr] -= 1
        res -= num
    print(res)


if __name__ == "__main__":

    main()


Measured memory_bytes: 42844
import scala.io.StdIn._
import scala.annotation.tailrec

object Main extends App {

  @tailrec
  def gcd(a: Int, b: Int): Int = {
    if(b == 0) a else gcd(b, a % b)
  }

  val all = 1 to readInt()

  println(Seq(all.sum,
    all.combinations(2).map(combi => gcd(combi(0), combi(1))).sum*6,
    all.combinations(3).map(combi => gcd(gcd(combi(0), combi(1)), combi(2))).sum*6).foldLeft(0)(_+_))
}


Measured memory_bytes: 58108
#include <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const int INF = (1 << 30) - 1;
// const ll LL_INF = (1LL << 62) - 1;
const ll MOD = 1e9 + 7;

ll N, M;
vector<ll> a;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> N >> M;
  a.resize(M);
  for (ll i = 0; i < M; i++) {
    cin >> a[i];
  }

  for (ll i = 0; i < M - 1; i++) {
    if (a[i + 1] - a[i] == 1) {
      cout << 0 << endl;
      return 0;
    }
  }

  vector<ll> ans(N + 1, 0);
  ans[0] = 1;
  ll cur = 0;
  if (cur < M && a[cur] == 1) {
    cur++;
    ans[1] = 0;
  } else {
    ans[1] = 1;
  }

  for (ll i = 2; i <= N; i++) {
    if (cur < M && i == a[cur]) {
      ans[i] = 0;
      cur++;
    } else {
      ans[i] = (ans[i - 1] + ans[i - 2]);
      ans[i] %= MOD;
    }
  }

  cout << ans[N] << endl;
  return 0;
}

Measured memory_bytes: 1408
#include <stdio.h>
#include <math.h>

int main() {
	int N, x[8], y[8];
	double ans = 0;
	scanf("%d",&N);
	for (int i = 0; i < N; i++) {
		scanf("%d%d", &x[i], &y[i]);
	}
	for (int i = 0; i < N; i++) {
		for (int j = i + 1; j < N; j++) {
			double X = (double)x[i] - x[j];
			double Y = (double)y[i] - y[j];
			ans = ans + sqrt(pow(X , 2) + pow(Y , 2));
		}
	}
	printf("%f", ans / N * 2);
	return 0;
}

Measured memory_bytes: 128
import sys
x, n = list(map(int,input().split()))
if n>0:
    p = list(map(int,input().split()))
else:
    print(x)
    sys.exit()
p.sort()
xmin = x
while True:
    if xmin in p:
        xmin -= 1
    else:
        break
xmax = x
while True:
    if xmax in p:
        xmax += 1
    else:
        break
# print(xmin,xmax)
print(xmin if abs(x-xmin)<=abs(x-xmax) else xmax)

Measured memory_bytes: 9108
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const ll MOD = 1e9 + 7;
const ll inf = 1LL<<60;
const double eps = 1e-9;

typedef pair<ll, ll> P;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main()
{
    int N;
    ll sum = 0, tmp1=inf, tmp2 = 0;
    cin >> N;
    vector<ll> a(N);
    for (int i = 0; i < N; i++) {
        cin >> a[i];
        sum += abs(a[i]);
        if (a[i] <= 0) tmp2++;
        tmp1 = min(tmp1, abs(a[i]));
    }
    if (tmp2 % 2) sum -= 2*tmp1;
    cout << sum << endl;

    return 0;
}



Measured memory_bytes: 1024
{-# LANGUAGE PartialTypeSignatures #-}
module Main (main) where

import Control.Monad
import qualified Data.ByteString.Char8 as C8
import qualified Data.Char as C
import qualified Data.List as L

main :: IO ()
main = do
  [n] <- readInts
  replicateM n readStrings >>= output . solve . map head

solve :: [String] -> [(String, Int)]
solve = map f . L.group . L.sort
  where
    f ys = (head ys, length ys)

output :: [(String, Int)] -> IO ()
output xs = do
  putStrLn $ fmt "AC" xs
  putStrLn $ fmt "WA" xs
  putStrLn $ fmt "TLE" xs
  putStrLn $ fmt "RE" xs
  where
    fmt s xs =
      case lookup s xs of
        Nothing -> s <> " x 0"
        Just n -> s <> " x " <> show n 

-- utils
readInts :: IO [Int]
readInts = L.unfoldr (C8.readInt . C8.dropWhile C.isSpace) <$> C8.getLine

readStrings :: IO [String]
readStrings = map C8.unpack . C8.words <$> C8.getLine

Measured memory_bytes: 39704
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using Pa = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

void solve(){
    ll N,D;
    vec<ll> cost(6);
    cin >> N >> cost[2] >> cost[3] >> cost[5] >> D;
    map<ll,ll> mp;
    ll inf = 2e18;
    ll ans = inf;
    auto dfs = [&](auto&& self,ll x)->ll{
        if(!x) return 0LL;
        if(mp.count(x)) return mp[x];
        ll res = inf;
        if(x<=2e9){
            res = D*x;
        }
        for(auto d:{2,3,5}){
            ll n = x/d;
            if(n!=x) res = min(res,abs(x-n*d)*D+cost[d]+self(self,n));
            n = (x+d-1)/d;
            if(n!=x) res = min(res,abs(x-n*d)*D+cost[d]+self(self,n));
        }
        return mp[x] = res;
    };
    cout << dfs(dfs,N) << "\n";
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int T;
    cin >> T;
    while(T--){
        solve();
    }
}

Measured memory_bytes: 4452
a, b, c, d = map(int, input().split())
ans = None
for x in [max(a, b), min(a, b)]:
    for y in [max(c, d), min(c, d)]:
        if ans is None:
            ans = x*y
        else:
            ans = max(ans, x*y)
print(ans)

Measured memory_bytes: 9172
#include <stdio.h>

int main()
{
  int m, f, r;

  while (1) {
    scanf("%d %d %d", &m, &f, &r);
    if (m == -1 && f == -1 && r == -1) break;

    if (m == -1 || f == -1) {
      printf("F\n");
      continue;
    }

    if (m + f >= 80) {
      printf("A\n");
    } else if (m + f >= 65) {
      printf("B\n");
    } else if (m + f >= 50) {
      printf("C\n");
    } else if (m + f >= 30) {
      if (r >= 50) {
        printf("C\n");
      } else {
        printf("D\n");
      }
    } else {
      printf("F\n");
    }
  }
  return 0;
}



Measured memory_bytes: 2044