akhauriyash/Code-Regression huggingface dataset:
/*|In The Name Of Allah|*/

#include <bits/stdc++.h>

using namespace std;

const int N = 8e5+5;

int n;
int p;
string s;

int main(){
    cin >> n >> p >> s;
    long long ans = 0;
    if(p == 2){
        for(int i = 0; i < n; i++){
            if( (s[i] - '0') % 2 == 0 ){
                ans += i + 1;
            }
        }
    } else if(p == 5){
        for(int i = 0; i < n; i++){
            if( (s[i] - '0') % 5 == 0 ){
                ans += i + 1;
            }
        }
    } else {
        map < int , int > cnt;
        cnt[0] = 1;
        int nm = 0 , p2 = 1;
        for(int i = n - 1; ~i; i--){
            nm = (nm + (s[i] - '0') * p2) % p;
            ans += cnt[nm];
            cnt[nm]++;
            p2 = p2*10%p;
        }
    }
    printf("%lld\n" , ans);
}


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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1)
    printEoln();
  if (suc == 2)
    printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

template <class T, class U> void chmax(T &a, U b) {
  if (a < b)
    a = b;
}

template <class T, class U> void chmin(T &a, U b) {
  if (b < a)
    a = b;
}

template <class T> T Sq(const T &t) { return t * t; }

const int mod = 1e9 + 7;

signed main() {
  int n, m;
  std::cin >> n >> m;
  vector<pi> students;
  vector<pi> checkpoints;
  REP(i, n) {
    int a, b;
    std::cin >> a >> b;
    students.EB(a, b);
  }
  REP(i, m) {
    int c, d;
    std::cin >> c >> d;
    checkpoints.EB(c, d);
  }
  REP(i, n) {
    int mi = LONG_MAX, ans;
    REP(j, m) {
      int dx = abs(students[i].first - checkpoints[j].first);
      int dy = abs(students[i].second - checkpoints[j].second);
      if (mi > dx + dy)
        mi = dx + dy, ans = j;
    }
    print(ans + 1);
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll mod=1e9+7;

int main()
{
  int x,y,a,b,c;
  cin>>x>>y>>a>>b>>c;
  vector<ll> red(a),green(b),none(c);
  for(auto&& e: red) 
  {
    cin>>e;
  }
  for(auto&& e: green) 
  {
    cin>>e;
  }
  for(auto&& e: none) 
  {
    cin>>e;
  }
  sort(red.begin(), red.end(),greater<ll>());
  sort(green.begin(), green.end(),greater<ll>());
  sort(none.begin(), none.end(),greater<ll>());
  priority_queue<ll,vector<ll>,greater<ll>> RED,GREEN;
  for (int i = 0; i < x; ++i)
  {
    RED.push(red[i]);
  }
  for (int i = 0; i < y; ++i)
  {
    GREEN.push(green[i]);
  }
  for (int i = 0; i < c; ++i)
  {
    ll red_border=RED.top();
    ll green_border=GREEN.top();
    if(none[i]>red_border&&none[i]>green_border)
    {
      if(green_border>red_border)
      {
        RED.pop();
        RED.push(none[i]);
      }
      else
      {
        GREEN.pop();
        GREEN.push(none[i]);
      }
    }
    else if(none[i]>red_border)
    {
      RED.pop();
      RED.push(none[i]);
    }
    else if(none[i]>green_border)
    {
      GREEN.pop();
      GREEN.push(none[i]);
    }
    else break;
  }
  ll ans=0;
  while(!RED.empty())
  {
    ans+=RED.top();
    RED.pop();
  }
  while(!GREEN.empty())
  {
    ans+=GREEN.top();
    GREEN.pop();
  }
  cout<<ans;
}

Measured memory_bytes: 4852
#include <iostream>

int main()
{
    char s;
    std::cin >> s;
    if(s <= 'Z')
    {
        std::cout << 'A' << std::endl;
    }
    else if( s >= 'a' )
    {
        std::cout << 'a' << std::endl;
    }
    
    return 0;
}

Measured memory_bytes: 3604
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstdio>
#include <queue>
#include <deque>
#include <map>
#include <stack>
#include <set>
#include <utility>
#include <functional>
#include<cstring>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int,pii> P;
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
const int MAXN = 100000;
const int MAXE = 100000;
const int MAXV = 10000;
const int inf = 1e9;
const ll INF = 2e18;
const ll MOD = 1e9 + 7;

struct UnionFind{
    vector<int> par,rank;
    UnionFind(int n):par(n),rank(n){
        for(int i=0;i<n;++i) par[i]=i;
    }
    int root(int x){
        if(par[x]==x) return x;
        return par[x]=root(par[x]);
    }
    void unite(int x,int y){
        int rx=root(x),ry=root(y);
        if(rx==ry) return ;
        if(rank[ry]>rank[rx]) par[rx]=ry;
        else par[ry]=rx;
        if(rank[rx]==rank[ry]) rank[rx]++;
    }
    bool same(int x,int y){
        return root(x)==root(y);
    }
};

vector<ll> fac,inv,finv;

void initcom(){
    fac=inv=finv=vector<ll>(1e6);
    fac[0]=fac[1]=1;
    inv[1]=1;
    finv[0]=finv[1]=1;
    for(ll i=2;i<1e6;++i){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}

ll com(int n,int k){
    if(n<0||k<0) return 0;
    if(n<k) return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
ll gcd(ll x,ll y){
    if(y==0) return x;
    return gcd(y,x%y);
}
ll mopow(ll a,ll x,ll mod){
    ll res=1;
    while(x>0){
        if(x&1) res=res*a%mod;
        a=a*a%mod;
        x>>=1;
    }
    return res;
}

bool warp[5][5];
int maze[3010][3010];
int cnt[3010][3010];
int h,w;
vector<string> s;
int c;
void dfs(int y,int x){
    cnt[y][x]=c;
    for(int i=0;i<4;++i){
        int ny=y+dy[i],nx=x+dx[i];
        if(!(ny>=0&&ny<h&&nx>=0&&ny<w)) continue;
        if(s[ny][nx]=='#') continue;
        if(cnt[y][x]>0) continue;
        dfs(ny,nx);
    }
}
int main(){
    int n;cin>>n;
    vector<ll> a(n),sum(n+1);sum[0]=0;
    for(int i=0;i<n;++i) cin>>a[i],sum[i+1]=sum[i]+a[i];
    ll ans=INF;
    for(int i=0;i<=n;++i){
        int low=0,high=i;
        while(high-low>1){
            int mid=(low+high)/2;
            if(sum[mid]>=sum[i]-sum[mid]) high=mid;
            else low=mid;
        }
        ll P1=sum[low],Q1=sum[i]-sum[low];
        ll P2=sum[high],Q2=sum[i]-sum[high];
        ll left_min=min(P1,Q1),left_max=max(P1,Q1);
        if(abs(P1-Q1)>abs(P2-Q2)) left_min=min(P2,Q2),left_max=max(P2,Q2);

        low=i,high=n;
        while(high-low>1){
            int mid=(low+high)/2;
            if(sum[mid]-sum[i]>=sum[n]-sum[mid]) high=mid;
            else low=mid;
        }
        ll R1=sum[low]-sum[i],S1=sum[n]-sum[low];
        ll R2=sum[high]-sum[i],S2=sum[n]-sum[high];
        ll right_min=min(R1,S1),right_max=max(R1,S1);
        if(abs(R1-S1)>abs(R2-S2)) right_min=min(R2,S2),right_max=max(R2,S2);

        ll tmp=max(left_max,right_max)-min(left_min,right_min);
        ans=min(ans,tmp);
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 6400
from itertools import permutations
import math
n = int(input())
perm = permutations(range(n)) 
a = []
b = []
r = []
for i in range(n):
	x,y = map(int,input().split())
	a.append(x)
	b.append(y)
for i in perm:
	x,y = a[i[0]],b[i[0]]
	res = 0
	for j in i[1:]:
		res += math.sqrt((a[j]-x)*(a[j]-x)+(b[j]-y)*(b[j]-y))
	r.append(res)
print(sum(r)/len(r))

Measured memory_bytes: 4400
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int a[110][110];
int h,w;

int xx[]={1,-1,0,0};
int yy[]={0,0,1,-1};

int color;

void f(int x,int y){
	a[y][x]=0;
	int i;
	for(i=0;i<4;i++){
		if(x+xx[i]<0||w<=x+xx[i]||y+yy[i]<0||h<=y+yy[i])continue;
		if(a[y+yy[i]][x+xx[i]]==color)f(x+xx[i],y+yy[i]);
	}
}

int main() {
	while(h=in(),w=in()){
		int i,j;
		int chr;
		for(j=0;j<h;j++){
			for(i=0;i<w;i++){
				while(chr=getchar(),chr<32);
				//if(chr==-1)return 0;
				//cout<<chr<<" ";
				a[j][i]=chr;
			}
			//cout<<endl;
		}
		int res=0;
		for(j=0;j<h;j++){
			for(i=0;i<w;i++){
				if(a[j][i]){
					res++;
					color=a[j][i];
					f(i,j);
				}
			}
		}
		cout<<res<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
import sys

input = sys.stdin.readline


def main():
    N, A, B = map(int, input().split())
    X = tuple(map(int, input().split()))

    ans = 0
    for i in range(N - 1):
        walk = (X[i + 1] - X[i]) * A
        ans += min(walk, B)

    print(ans)


if __name__ == "__main__":
    main()


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

int main()
{
    int n, q;
    int cnt = 0;                            //カウント

    cin >> n;                               //数列sの入力処理
    int s[n];
    for( int i = 0; i < n; i++ )
        cin >> s[i];                        //ここまで

    cin >> q;                               //数列tの入力処理
    int t[q];
    for( int i = 0; i < q; i++ )
        cin >> t[i];                        //ここまで

    for( int i = 0; i < q; i++ )
    {
        int d = 0, u = n - 1;
        if( t[i] == s[d] || t[i] == s[u] )  //求める値が、一番大きい、小さい値の場合、先に処理しておく
            cnt++;                          //÷2をし続けると、一番大きい要素にたどり着かない+後の処理の都合合わせ
        else
        {
            while( true )
            {
                if( t[i] == s[(d+u)/2] )    //真ん中を両側÷2で挟み込む
                {
                    cnt++;
                    break;
                }
                else if( d + 1 == u)        //見つからなかった場合
                    break;
                else if( t[i] > s[(d+u)/2] )
                    d = (d+u) / 2;
                else
                    u = (d+u) / 2;
            }
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3580
#include<iostream>
#include<string>
#include<stack>
#include<algorithm>
#include<queue>
#include<cmath>
#include<numeric>
#include<map>
#include<set>
#include<vector>
#include<list>
#include<iomanip>
#include<functional>
#include<bitset>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;
typedef long long ll;

int main(){
    ll n,k;
    cin>>n>>k;
    int a[n+1],visited[n+1]={0};
    rep(i,n) cin>>a[i+1];
    int now = 1,flag = 0,jumped = 0;
    ll count;
    visited[1]=0;
    ll i=1;
    while(i<=k){
        // cout<<"i:"<<i<<"now:"<<now<<endl;
        now = a[now];

        if(now==1 && !jumped){
            count = i-visited[now];
            // cout<<i<<" "<<count<<endl;
            i = (k-i)/count*count + i;
            // cout<<i<<endl;
            jumped = 1;
        }
        else if(visited[now]!=0 && !jumped){
            count = i-visited[now];
            // cout<<i<<" "<<count<<endl;
            i = (k-i)/count*count + i;
            // cout<<i<<endl;
            jumped=1;
        }
        visited[now] = i;
        i++;
    }
    cout<<now<<endl;
    return 0;
}

Measured memory_bytes: 5152
x,n=map(int,input().split())
p=list(map(int,input().split()))
ans=1e9
for i in range(x+1000):
  if i in p:
    continue
  ans=min(ans,abs(x-i))

if x-ans in p:
  print(x+ans)
else:
  print(x-ans)

Measured memory_bytes: 63484
#include <iostream>
#include <stdio.h>
using namespace std;

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

int main(void)
{
	int w, n, A[31] = {};
	char op;
	cin >> w;
	for(int i = 0; i < w; i++)
		A[i] = i+1;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		int a, b;
		cin >> a >> op >> b;
		Swap(&A[a - 1], &A[b - 1]);
	}
	for (int i = 0; i < w; i++)
		cout << A[i] << endl;
	return 0;
}


Measured memory_bytes: 3008
import std.conv, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.container, std.math, std.range, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken().to!int; }
long readLong() { return readToken().to!long; }
real readReal() { return readToken().to!real; }

void chmin(T)(ref T t, in T f) { if (t > f) t = f; }
void chmax(T)(ref T t, in T f) { if (t < f) t = f; }

int binarySearch(T)(in T[] as, in bool delegate(T) test) { int low = -1, upp = cast(int)(as.length); for (; low + 1 < upp; ) { int mid = (low + upp) >> 1; (test(as[mid]) ? low : upp) = mid; } return upp; }
int lowerBound(T)(in T[] as, in T val) { return as.binarySearch((T a) => (a < val)); }
int upperBound(T)(in T[] as, in T val) { return as.binarySearch((T a) => (a <= val)); }


int N;
long[] A, B;

void main() {
  try {
    for (; ; ) {
      N = readInt();
      A = new long[N];
      B = new long[N];
      foreach (i; 0 .. N) {
        A[i] = readLong();
      }
      foreach (i; 0 .. N) {
        B[i] = readLong();
      }
      
      int needCnt;
      long need;
      long[] xs;
      foreach (i; 0 .. N) {
        if (A[i] < B[i]) {
          ++needCnt;
          need += (B[i] - A[i]);
        } else if (A[i] > B[i]) {
          xs ~= (A[i] - B[i]);
        }
      }
      xs.sort!((a, b) => (a > b));
      debug {
        writefln("need = %s", need);
        writefln("xs = %s", xs);
      }
      
      auto xsSum = new long[xs.length + 1];
      foreach (j; 0 .. xs.length) {
        xsSum[j + 1] = xsSum[j] + xs[j];
      }
      
      int ans = -1;
      foreach (j; 0 .. xs.length + 1) {
        if (need <= xsSum[j]) {
          ans = needCnt + cast(int)(j);
          break;
        }
      }
      writeln(ans);
    }
  } catch (EOFException e) {
  }
}


Measured memory_bytes: 10260
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
#define answer(x) cout << x << endl
typedef int64_t Int;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

int main() {
    string s;
    cin >> s;

    vector<string> day(vector<string>{"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"});
    reverse(day.begin(), day.end());
    for (int i = 0; i < 7; i++) {
        if (day[i] == s) {
            cout << i + 1 << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
using namespace std;
int a[210000];
int main(void){
  int n;
  scanf("%d",&n);
  for(int loop=0;loop<n;loop++){
    scanf("%d",a+loop);
  }
  sort(a,a+n);
  for(int loop=0;loop<n-1;loop++){
    if(a[loop]==a[loop+1]){
      printf("NO\n");
      return 0;
    }
  }
  printf("YES\n");
  return 0;
}

Measured memory_bytes: 896
#include<iostream>
#include<string>
using namespace std;
int main()
{
    long long i,n,ac=0,tle=0,wa=0,re=0;
    string s;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>s;
        if(s[0]=='A')
        {
            ac++;
        }
        else if(s[0]=='T')
        {
            tle++;
        }
        else if(s[0]=='W')
        {
            wa++;
        }
        else
        {
            re++;
        }
    }
    cout<<"AC x "<<ac<<endl;
    cout<<"WA x "<<wa<<endl;
    cout<<"TLE x "<<tle<<endl;
    cout<<"RE x "<<re<<endl;
    return 0;
}

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

int main(void) {
	int n,m; cin >> n >> m;
	vector<int> cnt(m, 0);
	for (int i = 0; i < n; i++) {
		int k; cin >> k;
		for (int j = 0; j < k; j++) {
			int a; cin >> a;
			cnt[a-1]++;
		}
	}
	int ans = 0;
	for (int i = 0; i < m; i++) {
		if (cnt[i] == n) {
			ans++;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;

//

#define RESIDUE(u,v) (capacity[u][v] - flow[u][v])
#define RCOST(u,v) (cost[u][v] + h[u] - h[v])
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define LL long long

string s;
bool st[100000];
bool st_dum[100000];
int l;

bool valid(int n){
  REP(i,l-1){
    st_dum[i]=st[i];
  }
  //REP(i,l-1)cerr << st_dum[i]<<endl;
  //cerr<<endl;
  REP(i,l-n){
    if(!st_dum[i]){
      st_dum[i]=!st_dum[i];
      st_dum[i+n]=!st_dum[i+n];
    }
  }
  //REP(i,l-1)cerr << st_dum[i]<<endl;
  REP(i,n-2){
    if(!st_dum[n-i-2])return false;
  }
  return true;
}

int main(){
  cin>>s;
  l=s.size();
  REP(i,l-1){
    st[i]=(s[i]==s[i+1]);
  }
  bool bl=true;
  REP(i,l-1)bl=(bl and (s[i]==s[i+1]));
  if(bl){
    cout<<l<<endl;
    return 0;
  }
  int num=max(l/2,2);
  int ret=1;
  int del=max(num/2,1);
  while(1){
    if(num<l && valid(num)){
      ret=num;
      num+=del;
    }else{
      num-=del;
    }
    if(ret>=num)break;
    del=max(del/2,1);
  }
  cout<<ret<<endl;
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<ctime>
#include<set>
#include<map>
#include<queue>
#include<stack>
#define sqr(x) ((x)*(x))
#define fz1(i,n) for ((i)=1;(i)<=(n);(i)++)
#define fd1(i,n) for ((i)=(n);(i)>=1;(i)--)
#define fz0g(i,n) for ((i)=0;(i)<=(n);(i)++)
#define fd0g(i,n) for ((i)=(n);(i)>=0;(i)--)
#define fz0k(i,n) for ((i)=0;(i)<(n);(i)++)
#define fd0k(i,n) for ((i)=(long long)((n)-1);(i)>=0;(i)--)
#define fz(i,x,y) for ((i)=(x);(i)<=(y);(i)++)
#define fd(i,y,x) for ((i)=(y);(i)>=(x);(i)--)
#define fzin fz1(i,n)
#define fzim fz1(i,m)
#define fzjn fz1(j,n)
#define fzjm fz1(j,m)
#define ff(c,itr) for (__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define rdst(st,len){static char ss[len];scanf(" %s",ss);(st)=ss;}
#define inc(x,y) {x+=(y);if(x>=mod)x-=mod;}
#define dec(x,y) {x-=(y);if(x<0)x+=mod;}
//#define T_ int
using namespace std;
//struct bit{T_ arr[1000005];int lowbit(int x){return x&(-x);}void add(int x,T_ y){for (int i=x;i<=n;i+=lowbit(i)) arr[i]+=y;}T_ query(int x){T_ s=0;for (int i=x;i>0;i-=lowbit(i)) s+=arr[i];return s;}};
//struct seg{struct treedot{int l,r;T_ sum,add;void update(T_ x){sum+=(r-l+1)*x; add+=x;}}c[800005];void pushdown(int id){if (c[id].add){c[id*2].update(c[id].add);c[id*2+1].update(c[id].add);c[id].add=0;}}void pushup(int id){c[id].sum=c[id*2].sum+c[id*2+1].sum;}void build(int id,int l,int r){if (l>r) return;c[id].l=l;c[id].r=r;c[id].sum=0;c[id].add=0;if (l==r) c[id].sum=0;else{int mid=l+(r-l)/2;build(id*2,l,mid);build(id*2+1,mid+1,r);pushup(id);}}void update(int id,int le,int ri,T_ x){if (le>c[id].r||ri<c[id].l) return;if (le<=c[id].l&&c[id].r<=ri) c[id].update(x);else{pushdown(id);update(id*2,le,ri,x);update(id*2+1,le,ri,x);pushup(id);}}T_ query(int id,int le,int ri){if (ri<c[id].l||c[id].r<le) return 0;if (le<=c[id].l&&c[id].r<=ri) return c[id].sum;T_ ans=0;pushdown(id);ans+=query(id*2,le,ri);ans+=query(id*2+1,le,ri);pushup(id);return ans;}};
//struct bit_2d{T_ a[2005][2005];int lowbit(int x){return x&(-x);}void add(int x,int y,T_ z){int i,j;for (i=x;i<=2000;i+=lowbit(i)){for (j=y;j<=2000;j+=lowbit(j)){a[i][j]+=z;}}}T_ query(int x,int y){int i,j;T_ s=0;for (i=x;i;i-=lowbit(i)){for (j=y;j;j-=lowbit(j)){s+=a[i][j];}}return s;}T_ query(int x,int y,int xx,int yy){return query(xx,yy)-query(x-1,yy)-query(xx,y-1)+query(x-1,y-1);}};
int n,m,i,j;
int main()
{
	cin>>n>>m;
	if(m==1) puts("0");else printf("%d\n",n-m);
	return 0;
}

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


int main(){
	int n,cnt=0;
	string s;
	cin >> n >> s;
s+="ZZZ";	
  
	for(int i=0;i<s.size()-2;i++){
		if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C') cnt++;
	}
	
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

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

ll f(int n)
{
    if(n<0 || 2000<n) return 0;
    return min(n+1, 2001-n);
}

int main()
{
    int n;
    while(cin >> n){
        ll ans = 0;
        rep(i, n+1){
            ans += f(i) * f(n-i);
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 1156
#include <iostream>
#include <vector>
#include <queue>
#include <stdlib.h>
#include <string.h>
#include <map> 
#include <algorithm>
#include <set>
using namespace std;
typedef vector<int> vi ;
typedef long long ll;
#define pb push_back
#define all(x) (x).begin() , (x).end() 
const double pi=3.141592653589793238462643383279502884;
int main(){	
	int r ; 
	scanf("%d" , &r ) ;
	printf("%lf\n" , pi*r*2);
	return 0 ;	
} 
 

Measured memory_bytes: 3828
N,K=list(map(int,input().strip().split(' ')))
A=[]
for _ in range(N):
    A+=[list(map(int,input().strip().split(' ')))]
dic={}
MOD=10**9+7
power=1
while 2**power<=K:
    power+=1

dp=[[[0 for j in range(N)] for i in range(N)] for p in range(power+1) ]
for p in range(0,power+1):
    
    if p==0:
        for i in range(N):
            for j in range(N):
                if A[i][j]==1:
                    dp[p][i][j]=1
    else:
        for i in range(N):
            for j in range(N):
                for k in range(N):
                    dp[p][i][j]+=(dp[p-1][i][k]*dp[p-1][k][j])%MOD
                    dp[p][i][j]%=MOD

    
rep=bin(K)[2:][::-1]
final_ans=[[0 for i in range(N)] for j in range(N)]
need=[]
for i in range(len(rep)):
    if rep[i]=="1":
        need+=[i]

final=[[dp[need[0]][i][j] for j in range(N)] for i in range(N)]
for i in range(1,len(need)):
    ##start*dp[need[i]]
    temp_ans=[[0 for i in range(N)] for j in range(N)]
    for x in range(N):
        for y in range(N):
            temp=0
            for z in range(N):
                temp+=final[x][z]*dp[need[i]][z][y]
                temp%=MOD
            temp_ans[x][y]=temp
    final=[[temp_ans[i][j] for j in range(N)] for i in range(N)]
            
ans=0
for i in range(N):
    for j in range(N):
        ans+=final[i][j]
        ans%=MOD
print(ans)


Measured memory_bytes: 48732
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String S = scan.nextLine();
        String T = scan.nextLine();

        System.out.println(S.equals(T.substring(0,S.length())) ? "Yes" : "No");
        scan.close();
    }

}

Measured memory_bytes: 35452
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define pb push_back
#define mp make_pair
#define sz(a) (ll)(a).size()
#define endl "\n"
 
const int MAXN = 500005;
const int LMAXN = 20;

inline int64_t gilbertOrder(int x, int y, int pow, int rotate) {
    if (pow == 0) {
        return 0;
    }
    int hpow = 1 << (pow-1);
    int seg = (x < hpow) ? (
        (y < hpow) ? 0 : 3
    ) : (
        (y < hpow) ? 1 : 2
    );
    seg = (seg + rotate) & 3;
    const int rotateDelta[4] = {3, 0, 0, 1};
    int nx = x & (x ^ hpow), ny = y & (y ^ hpow);
    int nrot = (rotate + rotateDelta[seg]) & 3;
    int64_t subSquareSize = int64_t(1) << (2*pow - 2);
    int64_t ans = seg * subSquareSize;
    int64_t add = gilbertOrder(nx, ny, pow-1, nrot);
    ans += (seg == 1 || seg == 2) ? add : (subSquareSize - add - 1);
    return ans;
}

struct Query {
    ll l, r, ind;
    int64_t ord;
    inline void calcOrder() {
        ord = gilbertOrder(l, r, LMAXN, 0);
    }
}; 
inline bool operator<(const Query &a, const Query &b) {
    return a.ord < b.ord;
}
   
ll n, m, a[MAXN], ans[MAXN], curr, cc[MAXN];
vector<Query>q;

inline void add(ll x)
{
	cc[x]++;
	if(cc[x] == 1) curr++;
}
 
inline void remove(ll x)
{
	if(cc[x] == 1) curr--;
	cc[x]--;
}

int main()
{
	std::ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
 
    cin >> n >> m;
    q.resize(m);
    for(int i=0;i<n;i++) cin >> a[i];
    for(int i=0;i<m;i++)
    {
    	ll l, r;
    	cin >> l >> r;
        q[i].l = l - 1;
        q[i].r = r - 1;
        q[i].ind = i;
        q[i].calcOrder();
    }
    sort(q.begin(), q.end());
    ll mo_left = 0, mo_right = -1;
    for(int i=0;i<m;i++)
    {
    	ll left = q[i].l;
    	ll right = q[i].r;
    	while(mo_right < right) add(a[++mo_right]);
    	while(mo_right > right) remove(a[mo_right--]);
    	while(mo_left < left) remove(a[mo_left++]);
    	while(mo_left > left) add(a[--mo_left]);
    	ans[q[i].ind] = curr;
    }
    for(int i=0;i<m;i++) cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 31152
#include"bits/stdc++.h"
#define int long long
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define itr(i,x) for(auto i=(x).begin();i!=(x).end();++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
using Graph=vector<vector<int>>;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
const int mod=1000000007;
int gcd(int x,int y){return y?gcd(y,x%y):x;}
int lcm(int x,int y){return x*y/gcd(x,y);}
int roundup(int a,int b){return	(a-1)/b+1;}
void YN(bool flg){cout<<(flg?"YES":"NO")<<endl;}
void Yn(bool flg){cout<<(flg?"Yes":"No")<<endl;}
void yn(bool flg){cout<<(flg?"yes":"no")<<endl;}

signed main(){
	int n,m;cin>>n>>m;
	multiset<double,greater<double>> ms;
	rep(i,n){
		double a;cin>>a;
		ms.insert(a);
	}
	rep(i,m){
		double tar=*ms.begin();
		ms.erase(ms.begin());
		tar/=2.0;
		ms.insert(tar);
	}
	int ans=0;
	for(auto c:ms) ans+=(int)c;
	cout<<ans<<endl;
}

Measured memory_bytes: 4992
// https://atcoder.jp/contests/abc124/tasks/abc124_a
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define CEIL(a, b) ((a - 1) / b + 1)

void solve() {
    int A, B;
    cin >> A >> B;
    int ans = 0;
    REP(i, 2) {
        if (A > B) {
            ans += A;
            A--;
        } else {
            ans += B;
            B--;
        }
    }
    cout << ans << endl;
}

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    solve();
}


Measured memory_bytes: 3652
#include <iostream>
#include <cstdio>
#include <cmath>

using namespace std;
typedef long long ll;

int main(){

  string s;
  char b[26]={};
  int a[26]={};
  int j;

  for(int l=0; l<26; l++){
    b[l]='a'+l;
  }
  while(getline(cin, s)){
    for(int i=0; i<s.size(); i++){
      if(s[i]>='A'&&s[i]<='Z'){
        s[i]=s[i]-'A'+'a';
      }
      j=s[i]-'a';
      a[j]++;
    }
  }

  for(int k=0; k<26; k++){
    cout<<b[k]<<" "<<':'<<" "<<a[k]<<endl;
  }
}

Measured memory_bytes: 3176
#include <bits/stdc++.h>

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    if (s[0] == s[1] || s[1] == s[2] || s[2] == s[3]) {
        cout << "Bad" << endl;
    } else {
        cout << "Good" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
const int N=1000100,P=1e9+7;
inline int read(){
	int x=0,f=0,c=getchar();
	for(;c>'9'||c<'0';f=c=='-',c=getchar());
	for(;c>='0'&&c<='9';c=getchar())
	x=(x<<1)+(x<<3)+c-'0';return f?-x:x;
}
inline void write(ll x){
	if(x<0)putchar('-'),x=-x;
	if(x>9)write(x/10);putchar(x%10+'0');
}
int n,ans;
int main(){
	//freopen("1.out","w",stdout);
	int i;
	n=read();
	for(i=1;i<=n;i++)ans+=read()%2;
	puts(ans%2?"NO":"YES");
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <numeric>
#include <functional>

using namespace std;
#define ALL(x)              (x).begin(),(x).end()
#define REP(i, n)           for (int (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n)       for (int (i) = m ; (i) < (ll)(n) ; ++(i))
#define INF                 (int)2e9
#define MOD                 (1000 * 1000 * 1000 + 7)
#define Ceil(x, n)          (((((x))+((n)-1))/n))
#define CeilN(x, n)         (((((x))+((n)-1))/n)*n)
#define FloorN(x, n)        ((x)-(x)%(n))
#define IsOdd(x)            (((x)&0x01UL) == 0x01UL)
#define IsEven(x)           (!IsOdd((x)))
#define M_PI                3.14159265358979323846
typedef long long           ll;
typedef pair<ll, ll>	    P;
#define fi                  first
#define se                  second

/*-----------------------------------------------------------------------------
　処理
 -----------------------------------------------------------------------------*/
int main()
{
	ll H, W;
	cin >> H >> W;

	if (H == 1 || W == 1) {
		cout << 1 << endl;
		return 0;
	}

	ll ans = Ceil(H * W, 2);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import sys
range = xrange
input = raw_input

N = int(input())

div = 0
i = 1
while i*i<N:
    if N%i==0:
        m = i-1 
        if m and (m+1)*(N//m) == N: 
            div += m

        m = (N//i)-1 
        if m and (m+1)*(N//m) == N: 
            div += m
    i += 1

if i*i==N:
    m = i-1 
    if m and (m+1)*(N//m) == N: 
        div += m

print div

Measured memory_bytes: 29036
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <math.h>
using namespace std;

typedef long long ll;
const int MAXN = 2000 + 10;
const int M = 1e7 + 10;
const int Mod = 1e9 + 7;
int N, K;
int fac[M], inv[M], ifc[M];
int f[MAXN];

inline void init(int n) {
	register int i;
	for( fac[0] = i = 1; i <= n; ++i ) fac[i] = 1ll * fac[i - 1] * i % Mod;
	for( inv[1] = 1, i = 2; i <= n; ++i ) inv[i] = 1ll * (Mod - Mod / i) * inv[Mod % i] % Mod;
	for( ifc[0] = ifc[1] = 1, i = 2; i <= n; ++i ) ifc[i] = 1ll * ifc[i - 1] * inv[i] % Mod;
}

inline int C(int n, int k) {
	if( n < 0 || k < 0 || n < k ) return 0;
	return 1ll * fac[n] * ifc[k] % Mod * ifc[n - k] % Mod;
}

int main() {
	register int i, j;
	scanf( "%d%d", &N, &K ); --K;
	if(!K) return 0 * puts("1");
	init(10000000); f[0] = 1;
	for( i = 1; i <= N; ++i )
		for( j = 1; j <= i; ++j )
			f[j] = (f[j] + 1ll * (N - j + 1) * C(N * K + N - i - (j - 1) * K - 1, K - 1) % Mod * f[j - 1]) % Mod;
	printf( "%d\n", f[N] );
	return 0;
}

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

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

#define fr first
#define sc second

char ret[1002][1002];
void solve(int x,int y){
	if(y == 4){
		ret[x][x] = 'a';
		ret[x+1][x] = 'a';
		ret[x][x+1] = 'b';
		ret[x+1][x+1] = 'b';
		ret[x][x+2] = 'c';
		ret[x][x+3] = 'c';
		ret[x+1][x+2] = 'd';
		ret[x+1][x+3] = 'd';
		ret[x+2][x] = 'e';
		ret[x+2][x+1] = 'e';
		ret[x+3][x] = 'f';
		ret[x+3][x+1] = 'f';
		ret[x+2][x+2] = 'g';
		ret[x+3][x+2] = 'g';
		ret[x+2][x+3] = 'h';
		ret[x+3][x+3] = 'h';
	}
	if(y == 5){
		for(int i = 0 ; i < 4 ; i ++){
			ret[x][x+i] = 'a'+(i/2);
			ret[x+i][x+4] = 'a'+(i/2);
			ret[x+4][x+4-i] = 'a'+(i/2);
			ret[x+4-i][x] = 'a'+(i/2);
		}
		ret[x+1][x+2] = 'c';
		ret[x+1][x+3] = 'c';
		ret[x+2][x+1] = 'd';
		ret[x+3][x+1] = 'd';
	}
	if(y == 7){
		for(int i = 0 ; i < 6 ; i ++){
			int t=0;
			if((i&2)==2)t = 1;
			ret[x+t][x+i] = 'a'+(i/2);
			ret[x+i][x+6-t] = 'a'+(i/2);
			ret[x+6-t][x+6-i] = 'a'+(i/2);
			ret[x+6-i][x+t] = 'a'+(i/2);
		}
		ret[x+2][x+3] = 'd';
		ret[x+2][x+4] = 'd';
		ret[x+3][x+2] = 'e';
		ret[x+4][x+2] = 'e';
	}
}

int main(){
	int n;
	cin >> n;
	if(n <= 2){
		puts("-1");
		return 0;
	}
	
	for(int i = 0 ; i < n ; i ++){
		for(int j = 0 ; j < n ; j ++){
			ret[i][j] = '.';
		}
	}
	
	if(n%3 == 0){
		for(int i = 0 ; i < n/3 ; i ++){
			ret[3*i+0][3*i+0] = 'a';
			ret[3*i+1][3*i+0] = 'a';
			ret[3*i+2][3*i+1] = 'a';
			ret[3*i+2][3*i+2] = 'a';
		}
	}
	else {
		for(int i = 0 ; i < (n-4)/9 ; i ++){
			for(int j = 0 ; j < 3 ; j ++){
				for(int k = 0 ; k < 3 ; k ++){
					ret[9*i+2*j+0][9*i+k] = 'a'+(3*j+k);
					ret[9*i+2*j+1][9*i+k] = 'a'+(3*j+k);
					ret[9*i+6+j][9*i+3+2*k+0] = 'a'+(3*j+k);
					ret[9*i+6+j][9*i+3+2*k+1] = 'a'+(3*j+k);
				}
			}
		}
		int i = (n-4)/9;
		if(n%9 == 4){
			solve(i*9,4);
		}
		else if(n%9 == 5){
			solve(i*9,5);
		}
		else if(n%9 == 7){
			solve(i*9,7);
		}
		else if(n%9 == 8){
			solve(i*9,4);
			solve(i*9+4,4);
		}
		else if(n%9 == 1){
			solve(i*9,5);
			solve(i*9+5,5);
		}
		else if(n%9 == 2){
			solve(i*9,4);
			solve(i*9+4,7);
		}
	}
	for(int i = 0 ; i < n ; i ++){
		for(int j = 0 ; j < n ; j ++){
			printf("%c",ret[i][j]);
		}
		puts("");
	}
}

Measured memory_bytes: 2176
#include<iostream>
#include<algorithm>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<math.h>
#include <string>
#define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i];
typedef long long int ll;
using namespace std;
ll mod=1e9+7;
int main(){
 	int n; cin >>n;
 	string s1,s2; cin >>s1 >> s2;
 	bool flag=false; // s1[i]== s2[i]
 	bool flag1=false; // s[i]==s[i+1]
 	ll ans=1;
 	for(int i=0;i<s1.size();i++){
 		if(s1[i]==s2[i]){
 			if(!flag&&!flag1){
 				ans=ans*3%mod;
 				flag=true;
 			}
 			else if(!flag&&flag1){
 				flag1=false;
 				flag=true;
 			}
 			else if(flag&&!flag1){
 				ans=ans*2%mod;
 			}
 		}
 		else{
 			if(!flag&&!flag1){
 				ans=ans*6%mod;
 				flag1=true;
 			}
 			else if(!flag&&flag1){
 				ans=ans*3%mod;
 			}
 			else if(flag&&!flag1){
 				flag=false;
 				flag1=true;
 				ans=ans*2%mod;
 			}
 			i++;
 		}
 	}
 	cout << ans << endl;
 }

Measured memory_bytes: 256
/*
	Problem Statement -> https://atcoder.jp/contests/abc171/tasks/abc171_e

*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

void solve(){
	int n; cin>>n;
	vi arr(n);

	int xr = 0;

	for(int i=0;i<n;i++){
		cin>>arr[i];
		xr ^= arr[i];	
	}

	for(int i=0;i<n;i++){
		int val = xr^arr[i];
		cout<<val<<' ';	
	}
	cout<<'\n';
}


int32_t main()
{
	FIO;
	solve();
	return 0;
}

Measured memory_bytes: 4832
#include <iostream>
#include <string>
#include<cmath>
#include<bits/stdc++.h>

using namespace std;
int n;
#define FOR(i,s,t) for(int i =s;i<t;i++)

long long int t[1000006];
long long int f[1000006];
long long ans=0;
bool flag =1;

int main(){
  long long int D;
  cin>>n>>D;
  FOR(i,1,n+1){
    cin>>t[i]>>f[i];
  }
  t[n+1]=1000000006;
  f[n+1]=1;
  long long int pos =1;
  long long int cnt=0;
  FOR(i,1,n+2){
    int sa =pos-f[i];
    if(abs(sa)>t[i]-t[i-1]){
      flag=0;
    }
    if(pos-1+f[i]-1<=t[i]-t[i-1]){
      ans+=cnt*(pos-1);
      cnt=1;
      pos=f[i];
    }
    else{
      ans+=cnt*(t[i]-t[i-1]);
      cnt++;
      if(cnt>D)flag=0;
      pos=f[i];
    }
  }
  if(flag==0){
    cout<<-1<<endl;
    return 0;
  }
  else cout<<ans<<endl;
  return 0;

}

Measured memory_bytes: 4680
#include<bits/stdc++.h>
using namespace std;
#define     bolt     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define     text     freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define     F        first
#define     S        second
#define     pb       push_back
#define     lb       lower_bound
#define     ub       upper_bound
#define     endl     "\n"
typedef long long ll;
typedef long double ld;
const ll mod = 1e9+7 ;
const ld pi=3.1415926535897932384626433;
const ll inf = 1e18;
ll power(ll x,ll y){ll res=1;x=x%mod;while(y>0){if(y&1)res=((res%mod)*(x%mod))%mod;y=y>>1;x=((x%mod)*(x%mod))%mod;}return res;}

int main()
{
   bolt;
   ll n;
   cin>>n;
   if (n/100==7 or (n/10)%10==7 or n%10==7)
      cout<<"Yes";
   else
      cout<<"No";
}


Measured memory_bytes: 3648
K, A, B = map(int, input().split())

if (B-A > 2):
    if (K < A+1):
        print(1+K)
    else:
        K = K - (A+1)
        bis = B
        kaisuu = int((K - K%2)/2)
        amari = int(K%2)
        bis += kaisuu * (B-A) + amari
        print(bis)
else:
    print(1+K)


Measured memory_bytes: 3060
import java.util.Scanner;

fun main (args : Array<String>) {
  val MOD = 1_000_000_007L
  val input = Scanner(System.`in`)
  
  while (input.hasNext()) {
    val N = input.nextInt()
    var power = 1L
    
    for (i in 1..N) {
      power *= i
      power %= MOD
    }
    
    println(power)
  }
}

Measured memory_bytes: 36336
#!/usr/bin/env python3
import sys
INF = float("inf")


def solve(x: int):
    if x < 1200:
        print("ABC")
    else:
        print("ARC")
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    x = int(next(tokens))  # type: int
    solve(x)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
def combination(n, r):
    com = [[0 for j in range(r+1)] for i in range(n+1)]
    for i in range(n+1):
        com[i][0] = 1

    for i in range(1, n+1):
        for j in range(1, r+1):
            com[i][j] = com[i-1][j] + com[i-1][j-1]

    return com[n][r]


def main():
    n, a, b = map(int, input().split())
    v = list(map(int, input().split()))

    v.sort(reverse=True)

    num, s, i = [], [], 0
    while i < n:
        cnt = 1
        while i < n-1 and v[i] == v[i+1]:
            cnt += 1
            i += 1
        num.append(cnt)
        s.append(v[i])
        i += 1

    if num[0] >= a:
        com = 0
        for i in range(a, min(num[0]+1, b+1)):
            com += combination(num[0], i)
        print(v[0])
    else:
        c, idx = 0, 0
        while c < a:
            c += num[idx]
            idx += 1

        w, m = 0, 0
        for i in range(idx-1):
            w += v[i] * num[i]
            m += num[i]
        w += v[idx-1] * (a-m)

        print(w/a)

        com = combination(num[idx-1], a-m)

    print(com)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.jar.Attributes.Name;
import java.util.stream.Stream;


public class Main{
    public static void main(String[] args)throws IOException{
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        String[] a1 = input.readLine().split(" ");
        String[] a2 = input.readLine().split(" ");
        String[] a3 = input.readLine().split(" ");
        boolean flag = false;

        int n = Integer.parseInt(input.readLine());

        String[] b = new String[n];
        for(int i=0; i < n; i++){
            b[i] = input.readLine();
            for(int j=0; j<3;j++){
                if(a1[j].equals(b[i])){
                    a1[j] = "0";                    
                }
                if(a2[j].equals(b[i])){
                    a2[j] = "0";
                }
                if(a3[j].equals(b[i])){
                    a3[j] = "0";
                }
            }
        }
        if(a1[0].equals("0") && a1[1].equals("0") && a1[2].equals("0")){
            flag = true;
        }
        if(a2[0].equals("0") && a2[1].equals("0") && a2[2].equals("0")){
            flag = true;
        }
        if(a3[0].equals("0") && a3[1].equals("0") && a3[2].equals("0")){
            flag = true;
        }
        if(a1[0].equals("0") && a2[0].equals("0") && a3[0].equals("0")){
            flag = true;
        }
        if(a1[1].equals("0") && a2[1].equals("0") && a3[1].equals("0")){
            flag = true;
        }
        if(a1[2].equals("0") && a2[2].equals("0") && a3[2].equals("0")){
            flag = true;
        }
        if(a1[0].equals("0") && a2[1].equals("0") && a3[2].equals("0")){
            flag = true;
        }
        if(a1[2].equals("0") && a2[1].equals("0") && a3[0].equals("0")){
            flag = true;
        }

        if(flag==true){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}



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

long long int Q,H,S,D,N,ans=0 ; 

int main() {
	scanf("%lld %lld %lld %lld %lld",&Q,&H,&S,&D,&N) ; 
	if((D <= 2*S) && (D <= 4 * H) && (D <= 8*Q) ){
		ans += D * (N/2) ; 
		N %= 2 ;  
	}
	if((S <= 2* H) && (S <= 4 * Q)){
		ans += S * N ; 
		N = 0 ; 
	}
	if((H <= 2 * Q)){
		ans += H * N * 2 ; 
		N = 0 ; 
	}
	ans += Q * N * 4 ; 
	N = 0 ; 
	printf("%lld",ans) ; 
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
  int n, a, b;
  int i, cnt;
  scanf("%d %d %d", &n, &a, &b);
  for (cnt = 0, i = 1; i <= n; i++) {
    int s = (i % 10) + ((i/10) % 10) + ((i/100) % 10) + ((i/1000) % 10) + (i/10000);
    if (a <= s && s <= b) cnt += i;
  }
  printf("%d\n", cnt);

  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  map<int,int> mp_b;
  map<int,int> mp_p;
  bool flag=false;
  for(int i=0;i<N;i++){
    cin >> mp_b[i+1];
    if(mp_b[i+1]==2){
      flag = true;
    }
    mp_p[i+1]=0;
  }
  
  if(flag==true){
    int button_on = 1;
    int count = 0;
    while(true){
      if(mp_p[button_on]>0){
        cout << "-1" <<endl;
        break;
      }
      mp_p[button_on] += 1;
      count += 1;
      button_on = mp_b[button_on];
      if(button_on==2){
        cout << count << endl;
        break;
      }
    }
  } else{
    cout << "-1" << endl;
  }
}

Measured memory_bytes: 9600
import java.io.*;
import java.util.*;

public class Main {

	final static long MOD = 1000000007;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static void main(String[] args) throws Exception {

		int N = nextInt();
		int M = nextInt();
		int Q = nextInt();

		int[][] x = new int[Q][];
		for(int i=0;i<Q;i++){
			x[i]=nextInts();
		}



		ArrayList<int[]> list = new ArrayList<>();
		test(0,0,M,new int[10],list);

		long ans = 0;
		for(int[] p:list){
			long tmp=0;
			for(int i=0;i<Q;i++){
				if(p[x[i][1]-1]-p[x[i][0]-1]==x[i][2]){
					tmp+=x[i][3];
				}
			}
			ans=Math.max(ans, tmp);
		}
		System.out.println(ans);
	}

	public static void test(int rank ,int now ,int max, int[] ans,ArrayList<int[]> list){
		if(rank == ans.length){
			list.add(Arrays.copyOf(ans, ans.length));
			return;
		}
		for(int i=0;i<max;i++){
			if(i>=now){
				ans[rank]=i;
				test(rank+1,i,max,ans,list);
			}
		}
	}

	public static String[] toStringArray(String s) {
		String[] tmp = new String[s.length()];
		char[] c = s.toCharArray();
		for (int i = 0; i < tmp.length; i++) {
			tmp[i] = String.valueOf(c[i]);
		}
		return tmp;
	}

	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}


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

int n;
int x[10], y[10];

double dist (int i, int j) {
  double dx = x[i] - x[j];
  double dy = y[i] - y[j];
  return sqrt(dx*dx + dy*dy);
}

int main () {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> x[i] >> y[i];
  }
  
  double ans = 0.0;
  for (int i = 0; i < n-1; ++i) {
    for (int j = i+1; j < n; ++j) {
      ans += dist(i, j);
    }
  }
  cout << fixed << setprecision(10) << (ans * 2 / n) << endl;
}

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

typedef long long int ll;
int main()
{
  ll a, b, c, d; cin >> a >> b >> c >> d;
  vector<ll> v{a*c, a*d, b*c, b*d};
  cout << (*max_element(v.begin(), v.end()));
  return 0;
}


Measured memory_bytes: 3588
N = int(input())
List_A = list(map(int,input().split()))
a = 0

for i in range(N-1):
    if List_A[i] <= List_A[i+1]:
        a = a + 0
    else:
        a = a + List_A[i] - List_A[i+1]
        List_A[i+1] = List_A[i]
        
print(a)

Measured memory_bytes: 32244
using System;
using System.Linq;

class Program
{
    static long mod = 1000000007;
    static void Main(string[] args) {
        int n = int.Parse(Console.ReadLine());
        Console.WriteLine(solve(n));
    }

    static long solve(int n) {
        long[,,,] dp = new long[n+1,4,4,4];
        dp[0,3,3,3] = 1;
        for(int i = 0; i < n; i ++) {
            for(int z = 0; z < 4; z ++) {
                for(int y = 0; y < 4; y ++) {
                    for(int x = 0; x < 4; x ++) {
                        for(int w = 0; w < 4; w ++) {
                            //a==0,g==1,c==2,t==3
                            if(w == 2 && x == 1 && y == 0) continue; //~AGC
                            if(w == 1 && x == 2 && y == 0) continue; //~ACG
                            if(w == 2 && x == 0 && y == 1) continue; //~GAC
                            if(w == 2 && y == 1 && z == 0) continue; //AG~C
                            if(w == 2 && x == 1 && z == 0) continue; //A~GC
                            dp[i+1,y,x,w] += dp[i,z,y,x];
                            dp[i+1,y,x,w] %= mod;
                        }
                    }
                }
            }
        }
        long ans = 0;
        for(int x = 0; x < 4; x ++) {
            for(int y = 0; y < 4; y ++) {
                for(int z = 0; z < 4; z ++) {
                    ans += dp[n,x,y,z];
                    ans %= mod;
                }
            }
        }
        return ans;
    }
}

Measured memory_bytes: 13208
#include<stdio.h>
int main(){
	int a,b;
	scanf("%d %d",&a,&b);
	if (a<=13&&a>=2&&b<=13&&b>=2&&a>b){printf("Alice\n");}
	if (a<=13&&a>=2&&b<=13&&b>=2&&b>a){printf("Bob\n");}
	if (a<=13&&a>=2&&b==1){printf("Bob\n");}
	if (b<=13&&b>=2&&a==1){printf("Alice\n");}
	if (a<=13&&a>=2&&b<=13&&b>=2&&a==b){printf("Draw\n");}
	if (a==1&&b==1){printf("Draw\n");}
	return 0;
	}

Measured memory_bytes: 128