akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <queue>
#include <vector>
using namespace std;

int main() {
  int n, m;
  while (cin >> n >> m, n | m) {
    vector<vector<int>> graph(n);
    for (int i = 0; i < m; ++i) {
      int a, b; cin >> a >> b; --a; --b;
      graph[a].push_back(b);
      graph[b].push_back(a);
    }
    vector<int> dist(n, 3);
    queue<int> Q;
    Q.push(0);
    dist[0] = 0;
    while (!Q.empty()) {
      int v = Q.front(); Q.pop();
      for (int w : graph[v]) {
        if (dist[w] == 3) {
          dist[w] = dist[v] + 1;
          Q.push({w});
        }
      }
    }
    int ans = 0;
    for (int d : dist)
      if (d < 3) ++ans;
    cout << ans - 1 << endl;
  }
}

Measured memory_bytes: 1372
n, k = map(int, input().split())
a = sorted(map(int, input().split()))
f = sorted(map(int, input().split()))[::-1]

# 成績　Σ{i=1~n}a[i]*f[i]
# a[i]小さいの、f[i]でかいの組み合わせるとよい(交換しても悪化しない)
def c(x):
    need = 0
    for i in range(n):
        if a[i] * f[i] > x:
            # f[i]を何回減らしてx以下にできるか
            diff = a[i] * f[i] - x
            need += 0 - - diff // f[i]
    return need <= k


l = 0
r = 1 << 60

while r != l:
    mid = (l + r) >> 1
    if c(mid):
        r = mid
    else:
        l = mid + 1
print(l)


Measured memory_bytes: 115908
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cstdio>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int) n; i++)

int main() {
    int h,w; cin >> h >> w;
    string s;
    rep(i,h) {
        cin >> s;
        cout << s << endl << s << endl;
    }   
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  double d;
  int a, b, c;
  cin >> d;
  a = d / 100;
  b = (d / 100 - a) * 10;
  c = ((d / 100 - a) * 10 - b) * 10;   
  cout << a + b + c << endl;
}

Measured memory_bytes: 256
use std::io::*;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let mut map = std::collections::HashMap::new();
    let mut ans = 0u64;
    for _ in 0..n {
        let mut s: Vec<char> = itr.next().unwrap().chars().collect();
        s.sort();
        let s = s.into_iter().collect::<String>();
        let p = map.entry(s).or_insert(0);
        ans += *p;
        *p += 1;
    }
    println!("{}", ans);
}


Measured memory_bytes: 19664
#include<bits/stdc++.h>
using namespace std;
long long n,a[100003],c=1,s;
int main(){
cin>>n;
for(int i=1;i<=n;i++)
cin>>a[i];
sort(a+1,a+n+1);
for(int i=2;i<=n;i++){
if(a[i]==a[i-1]) c=(c+1)%2;
else s+=c,c=1;}
if(c%2==1) s++;
cout<<s;}

Measured memory_bytes: 1024
#pragma GCC optimize("Ofast", "unroll-loops")

// #define TEST

#include <bits/stdc++.h>

using namespace std;

#define ll long long

int main() {
	int N; cin >> N;
	string S; cin >> S;
	vector<int> M_cnt(N + 1, 0), C_cnt(N + 1, 0);
	vector<ll> MC_cnt(N + 1, 0);
	vector<int> D_idx;
	for (int i = 0; i < N; ++i) {
		M_cnt[i + 1] = M_cnt[i];
		C_cnt[i + 1] = C_cnt[i];
		MC_cnt[i + 1] = MC_cnt[i];
		if (S[i] == 'D')
			D_idx.push_back(i);
		else if (S[i] == 'M')
			++M_cnt[i + 1];
		else if (S[i] == 'C') {
			++C_cnt[i + 1];
			MC_cnt[i + 1] += M_cnt[i + 1];
		}
	}
#ifdef TEST
	cout << "------M_cnt-----" << endl;
	for (auto i : M_cnt) cout << i << " ";
	cout << endl;
	cout << "------C_cnt-----" << endl;
	for (auto i : C_cnt) cout << i << " ";
	cout << endl;
	cout << "------MC_cnt-----" << endl;
	for (auto i : MC_cnt) cout << i << " ";
	cout << endl;
	cout << "------D_idx-----" << endl;
	for (auto i : D_idx) cout << i << " ";
	cout << endl;
#endif
	int Q; cin >> Q;
	while (Q--) {
		int k; cin >> k;
		ll res = 0;
		for (auto d : D_idx) {
			ll tmp = MC_cnt[min(N, d + k)] - MC_cnt[d];
			tmp -= ((ll)C_cnt[min(N, d + k)] - C_cnt[d]) * M_cnt[d];
			res += tmp;
		}
		cout << res << endl;
	}
	return 0;
}

Measured memory_bytes: 22268
#!/usr/bin/env python3

def main():
    [A, B, C, D, E, F] = list(map(int, input().split()))

    A100 = A * 100
    B100 = B * 100


    d_max = 0
    d_w = A100
    d_s = 0

    i2_max = F // B100 + 1
    for i2 in range(i2_max):
        w2 = B100 * i2
        i1_max = (F - w2) // A100 + 1
        for i1 in range(i1_max):
            w = w2 + A100 * i1
            if w == 0:
                continue
            if F <= w:
                break
            target = (w // 100) * E
            if F - w < target:
                target = F - w
            if target / (w + target) < d_max:
                continue
            q = target // (C * D)
            r = target % (C * D)
            r_max = 0
            for i3 in range(D + 1):
                x3 = C * i3
                if r < x3:
                    break
                if x3 == r:
                    r_max = r
                    break
                for i4 in range(C + 1):
                    x = x3 + D * i4
                    if r < x:
                        break
                    if x == r:
                        r_max = r
                        break
                    r_max = max(r_max, x)
                if r_max == r:
                    break
            s = C * D * q + r_max
            d = s / (w + s)
            if d_max < d:
                d_max = d
                d_w = w
                d_s = s

    print('{} {}'.format(d_w + d_s, d_s))


if __name__ == '__main__':
    main()



Measured memory_bytes: 3064
#define DEB
#include<bits/stdc++.h>
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;


#ifdef DEB
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
#define dumpR(x) cerr<<"\x1b[31m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpY(x) cerr<<"\x1b[33m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpG(x) cerr<<"\x1b[32m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
#else
#define dump(x) ;
#define dumpR(x) ;
#define dumpY(x) ;
#define dumpG(x) ;
#define prl ;
template<class T> void debug(T a,T b){ ;}
#endif

template<class T> void chmin(T& a,const T& b) { if(a>b) a=b; }
template<class T> void chmax(T& a,const T& b) { if(a<b) a=b; }
typedef long long int lint;
typedef pair<int,int> pi;

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fr<<','<<a.sc<<')';
    return out;
  }
}

lint readL(){
  lint res;
#ifdef ONLINE_JUDGE
  scanf("%I64d",&res);
#else
  scanf("%lld",&res);
#endif
  return res;
}
void printL(lint res){
#ifdef ONLINE_JUDGE
  printf("%I64d",res);
#else
  printf("%lld",res);
#endif
}

//const int INF=5e8;
int n,m;
struct uf{
  static const int MAXN=200005;
  int par[MAXN];
  int size[MAXN];
  void init(){
    memset(par,-1,sizeof(par));
    REP(i,MAXN) size[i]=1;
  }
  int root(int a){
    if(par[a]==-1) return a;
    return par[a]=root(par[a]);
  }
  void unite(int a,int b){
    a=root(a);b=root(b);
    if(a==b) return;
    if(size[a]<size[b]) swap(a,b);

    par[b]=a;
    size[a]+=size[b];
  }
  bool same(int a,int b){
    return root(a)==root(b);
  }
};


uf u;


int main(){
  cin>>n>>m;
  u.init();
  REP(i,n){
    int k;scanf("%d",&k);
    REP(j,k){
      int l;scanf("%d",&l);
      --l;
      u.unite(i,l+n);
    }
  }
  int cnt=0;
  REP(i,n) if(u.root(i)==i) ++cnt;
  puts(cnt==1?"YES":"NO");

  return 0;
}





Measured memory_bytes: 1920
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define irep(i, a, n) for (int i = a; i < (int)(n); ++i)
#define rrep(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define rrep1(i, n) for (int i = (int)(n); i >= 1; --i)
#define allrep(V, v) for (auto &&V : v)
#define all(x) (x).begin(), (x).end()
const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
using lint = long long;

using namespace std;

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

  int p, q, r;
  cin >> p >> q >> r;
  cout << min({p + q, q + r, r + p}) << endl;
  return 0;
}

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

const int MAX = 2005;
int N, memo[MAX][MAX], cost[2][MAX][2*MAX], f[2][MAX];
pair<int, int> A[2*MAX];

int Solve(int a, int b) {
        if (a == N && b == N) return 0;

        int &ret = memo[a][b];
        if (ret != -1) return ret;

        ret = 1e8;
        if (a != N) ret = min(ret, Solve(a+1, b) + cost[0][a+1][f[0][a]] + cost[1][b][f[0][a]]);
        if (b != N) ret = min(ret, Solve(a, b+1) + cost[0][a][f[1][b]] + cost[1][b+1][f[1][b]]);
        return ret;
}

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

        for (int i=0; i<2*N; ++i) {
                char c;
                scanf(" %c%d", &c, &A[i].second);
                A[i].first = c == 'B';
                A[i].second -= 1;
                f[A[i].first][A[i].second] = i;
        }

        for (int t=0; t<2; ++t) for (int num=0; num<N; ++num) {
                int x = 0;
                for (int i=0; i<2*N; ++i) {
                        if (A[i].first == t && A[i].second >= num)
                                ++x;
                        cost[t][num][i] = x;
                }
        }

        memset(memo, -1, sizeof(memo));
        printf("%d\n", Solve(0, 0));
        return 0;
}


Measured memory_bytes: 79104
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b;cin>>a>>b;
    if(a==b){cout<<a+b<<endl;
            return 0;
    }
    int ra=0,rb=0;
    ra=a+a-1;
    rb=2*b-1;
    ra>rb?(cout<<ra):(cout<<rb);
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define f1(i,n) for(int i=1;i<n;i++)
#define PI 3.14159265358979323846
double tick(){static clock_t oldt,newt=clock();double diff=1.0*(newt-oldt)/CLOCKS_PER_SEC;oldt=newt;return diff;}

using namespace std;

void solve(){
  int temp;
	f(i,5){
    cin>>temp;
      if(!temp){ cout<<i+1; break;}
    }
	//cout<<tick()<<endl;	
}

int32_t main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  int t;
  // cin>>t;
  // while(t--)
    solve();
  return 0;
}

Measured memory_bytes: 3580
#include<bits/stdc++.h>
 
using namespace std;
 
int main(){
 
    int x, y;
 
    cin >> x >> y;
 
    x = y - x;
 
    int ans = 0;
 
    for(int a = 1; a <= x; a++) ans += a;
 
    cout << ans - y << endl;
 
     return 0;
 
}

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

using namespace std;
using ll=long long;

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

int main(){
  std::cin.tie(nullptr);                  // 標準入出力高速化
  std::ios_base::sync_with_stdio(false);  // SとS++の入出力出力を非同期
  string s;
  cin>>s;
  int y,m,d;
  y=stoi(s.substr(0,4));
  m=stoi(s.substr(5,2));
  d=stoi(s.substr(8,2));
  //cout<<y<<" "<<m<<" "<<d<<endl;
  y<=2019 && m<=4 && d<=30 ? cout<<"Heisei"<<endl : cout<<"TBD"<<endl;
}

Measured memory_bytes: 256
;; -*- coding: utf-8 -*-
(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter OPT
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0)))
  #+swank (ql:quickload '(:cl-debug-print :fiveam))
  #-swank (set-dispatch-macro-character #\# #\> (lambda (s c p) (declare (ignore c p)) (read s nil (values) t))))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)
#-swank (disable-debugger) ; for CS Academy

;; BEGIN_INSERTED_CONTENTS
(declaim (ftype (function * (values fixnum &optional)) read-fixnum))
(defun read-fixnum (&optional (in *standard-input*))
  (macrolet ((%read-byte ()
               `(the (unsigned-byte 8)
                     #+swank (char-code (read-char in nil #\Nul))
                     #-swank (sb-impl::ansi-stream-read-byte in nil #.(char-code #\Nul) nil))))
    (let* ((minus nil)
           (result (loop (let ((byte (%read-byte)))
                           (cond ((<= 48 byte 57)
                                  (return (- byte 48)))
                                 ((zerop byte) ; #\Nul
                                  (error "Read EOF or #\Nul."))
                                 ((= byte #.(char-code #\-))
                                  (setf minus t)))))))
      (declare ((integer 0 #.most-positive-fixnum) result))
      (loop
        (let* ((byte (%read-byte)))
          (if (<= 48 byte 57)
              (setq result (+ (- byte 48) (* 10 (the (integer 0 #.(floor most-positive-fixnum 10)) result))))
              (return (if minus (- result) result))))))))

(defmacro dbg (&rest forms)
  #+swank
  (if (= (length forms) 1)
      `(format *error-output* "~A => ~A~%" ',(car forms) ,(car forms))
      `(format *error-output* "~A => ~A~%" ',forms `(,,@forms)))
  #-swank (declare (ignore forms)))

(defmacro define-int-types (&rest bits)
  `(progn
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "UINT~A" b)) () '(unsigned-byte ,b))) bits)
     ,@(mapcar (lambda (b) `(deftype ,(intern (format nil "INT~A" b)) () '(signed-byte ,b))) bits)))
(define-int-types 2 4 7 8 15 16 31 32 62 63 64)

(declaim (inline println))
(defun println (obj &optional (stream *standard-output*))
  (let ((*read-default-float-format* 'double-float))
    (prog1 (princ obj stream) (terpri stream))))

(defconstant +mod+ 1000000007)

;; Body

(defun main ()
  (let* ((n (read))
         (as (make-array (+ 1 n) :element-type 'bit))
         (res (make-array (+ 1 n) :element-type 'bit)))
    (loop for i from 1 to n do (setf (aref as i) (read-fixnum)))
    (loop for i from n downto 1
          do (loop with xor = (aref as i)
                   for j from (* 2 i) to n by i
                   do (setf xor (logxor xor (aref res j)))
                   finally (setf (aref res i) xor)))
    (let ((count (count 1 res)))
      (println count)
      (loop for i from 1 to n
            when (= (aref res i) 1)
            do (println i)))))

#-swank (main)


Measured memory_bytes: 27496
"use strict"
function main(arg) {
    var args = arg.split("\n")
    var k = args[0].split(" ").map(Number)[1]
    var rsp = args[1].split(" ").map(Number)
    var r = rsp[0]
    var s = rsp[1]
    var p = rsp[2]
    var l = args[2].split("")
    var n = l.length
    var ans = 0
    for (var i = 0; i < n; i++) {
        // console.log([l[i] + l[i+2]])
        if (i >= k) {
            if (l[i] === l[i-k]) {
                l[i] = '-'
                // console.log("-")
                continue
            }
        }
        if (l[i] === 'r') {
            // console.log('p')
            ans += p
        }
        if (l[i] === 's') {
            // console.log('r')
            ans += r
        }
        if (l[i] === 'p') {
            // console.log('s')
            ans += s
        }
        
    }
    console.log(ans)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 12364
#include <bits/stdc++.h>
using namespace std;
 
using ll=long long;
 
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define eb emplace_back
#define a first
#define b second
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
const int MOD = 1000000007; 

ll gcd(ll a, ll b) {
    if (b==0) return a;
    return gcd(b, a%b);
}

int main() {
    ll n; ll x;
    cin >> n >> x;
    vector<ll> xs(n);
    rep(i, n) cin >> xs[i];
    ll d = abs(x-xs[0]);
    rep(i, n-1) d = gcd(d, abs(x-xs[i+1]));
    cout << d << endl;
    return 0;
}

Measured memory_bytes: 1024
var inp=(""+require("fs").readFileSync(0)).split("\n");
var n=+inp[0];
var s=inp[1];

var left=s.slice(0,n);
var right=s.slice(n).split("").reverse().join("");

var mp={};

for(var b=1<<n;b--;){
  var red="",blue="";
  for(var i=0;i<n;i++)
    if(b&(1<<i))red+=left[i];
  	else blue+=left[i];
  if(red+","+blue in mp)
    mp[red+","+blue]++;
  else
    mp[red+","+blue]=1;
}

var ans=0;

for(var b=1<<n;b--;){
  var red="",blue="";
  for(var i=0;i<n;i++)
    if(b&(1<<i))red+=right[i];
  	else blue+=right[i];
  if(red+","+blue in mp)
    ans+=mp[red+","+blue];
}

console.log(ans);


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

using namespace std;
int main(){
    int a,b,c;
    double d,S,L,h,rad;
    cin >> a >> b >> c;
    rad = c*M_PI/180;
    S=a*b*sin(rad)/2;
    d=sqrt((a*a)+(b*b)-2*a*b*cos(rad));
    L=a+b+d;
    h=b*sin(rad);
    
    printf("%lf\n",S);
    printf("%lf\n",L);
    printf("%lf\n",h);
    
    return 0;
    
}


Measured memory_bytes: 3380
using System;
using System.Collections.Generic;
using System.Linq;


namespace Library
{
    public class Miscelleneous
    {
        public static void print(object j){Console.WriteLine(j.ToString());}
        public static void print(string s){Console.WriteLine(s);}
        public static int cin(){return int.Parse(Console.ReadLine());}
        public static int[] cins(){
            string[] ss=Console.ReadLine().Split(' ');
            var res=new int[ss.Length];
            for(int i=0;i<ss.Length;i++)
                res[i]=int.Parse(ss[i]);                
            return res;            
        }
        
        public static void Main(){
            
            int[] ss;
            int[] N1=new int[1024];
            int[] S1=new int[1024];
            int c1,v;
            for(int i=0;i<1024;i++){
                c1=Enumerable.Range(0,10).Select(k=>((i>>k)&1)==1).Where(k=>k).Count();
                v=Enumerable.Range(0,10).Select(k=>((i>>k)&1)==1?k:0).Sum();
                N1[i]=c1;S1[i]=v;
            }
            int Res;
            while(true){
               ss=cins();
               Res=0;
               if(ss[0]==0&&ss[1]==0)break;
               for(int i=0;i<1024;i++){
                   if(N1[i]==ss[0]&&S1[i]==ss[1])Res++;
               }
               print(Res);
            }
        }
    }
}

Measured memory_bytes: 9476
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define repone(i,n) for(int i=1;i<(int)(n);++i)

#define Rep(j,n) for(int j=0;j<(int)(n);++j)

#define int long long

using namespace std;

signed main()
{
  double x=0,z=0;
  cin >> x;
  double y=0;
string xyx;
rep(i,x){
cin >> y>>xyx;
if(xyx=="BTC"){
  y=y*380000.0;
}
z+=y;
}
printf("%.4f\n",z);
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	vector<int> A(N);
	int a;
	int res = 0;
	for (int i = 0; i < N; i++) {
		cin >> a;
		a--;
		A[a] = i;
	}
	int t = 1;
	for (int i = 1; i < N; i++) {
		if (A[i - 1] < A[i]) {
			t++;
		}
		else {
			res = max(res, t);
			t = 1;
		}
	}
	res = max(res, t);
	cout << N -  res << endl;
}

Measured memory_bytes: 1792
#include<stdio.h>
#include<math.h>
int main(void){
   int n, count = 0, i, s, key, so;
   long a;
   scanf("%d", &n);
   while ( n ) {
   count = so = 0;
   for ( a = 1;  count < n; a++ ) {
      s = key = 2;
      if ( a == 1 ) ;
      else if ( a == 2 ) {/*printf("sosuu\n")*/;count++; so += a;}
      else {
         while ( s < sqrt(a) + 2 && key != 0) {
            if ( a % s == 0 ) key = 0;
            else key = 1;
            s++;
         }
      }
      if ( a != 1 && s > sqrt(a) + 1) {/*printf("sosuu\n")*/;count++; so += a;}
   }
   printf("%d\n", so);
   scanf("%d", &n);
   }
   return 0;
}

Measured memory_bytes: 1724
con_s = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT']
s = str(input())
total = 7
if (s in con_s):
  for i, val in enumerate(con_s):
    if (val == s):
      break
    else:
      total -= 1
print(total)
    

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

constexpr int64_t MOD = 1e9 + 7;

int64_t modpow(int64_t x, int64_t n, int64_t m = 1) {
    return n == 0 ? m : modpow(x * x % MOD, n >> 1, n & 1 ? m * x % MOD : m);
}

int main() {
    int64_t n;
    cin >> n;
    int64_t g = 1;
    vector<int64_t> a(n);
    map<int64_t, int64_t> lcmprimefactors;
    for (auto& e : a) {
        int64_t f;
        cin >> e, f = e;
        map<int64_t, int64_t> primefactors;
        for (int64_t m = 2; m <= sqrt(e) && f != 1; m++) {
            while (f % m == 0) f /= m, primefactors[m]++;
        }
        if (f != 1) primefactors[f]++;

        for (auto& f : primefactors) {
            int64_t factor, number;
            tie(factor, number) = f;
            lcmprimefactors[factor] = max(lcmprimefactors[factor], number);
        }
    }

    int64_t l = 1;
    for (auto& f : lcmprimefactors) {
        l *= modpow(f.first, f.second);
        l %= MOD;
    }

    int64_t ans = 0;
    for (auto& e : a) {
        int64_t tmp = l;
        int64_t f = e;
        map<int64_t, int64_t> primefactors;
        for (int64_t m = 2; m <= sqrt(e) && f != 1; m++) {
            while (f % m == 0) f /= m, primefactors[m]++;
        }
        if (f != 1) primefactors[f]++;
        for (auto& e : primefactors) {
            tmp *= modpow(modpow(e.first, e.second), MOD-2);
            tmp %= MOD;
        }

        ans += tmp;
        ans %= MOD;
    }

    cout << ans << endl;
}


Measured memory_bytes: 896
/*
 * wafuIroha.cpp
 *
 *  Created on: 2020/02/23
 *      Author: black
 */
#include <iostream>
using namespace std;

int selectionSort(int *a, int n){
	int tmp;
	int minj;
	int count = 0;
	for(int i=0; i< n; ++i){
		minj = i;
		for(int j=i; j<n; ++j){
			if (a[j] < a[minj]){
				minj = j;
			}
		}
		if (i != minj){
			tmp = a[i];
			a[i] = a[minj];
			a[minj] = tmp;
			++count;
		}
	}
	return count;
}

int main(){
	int n, count;
	cin >> n;
	int *a = new int[n];

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

	count = selectionSort(a, n);

	for(int i=0; i<n-1; ++i){
		cout << a[i] <<" ";
	}
	cout << a[n-1] << endl;
	cout << count << endl;

	return 0;
}




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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var xy = Console.ReadLine().Split()
                .Select(int.Parse)
                .ToArray();
            int x = xy[0];
            int y = xy[1];

            if (2 * x <= y && y <= 4 * x && y % 2 == 0)
                Console.WriteLine("Yes");
            else
                Console.WriteLine("No");
        }
    }
}


Measured memory_bytes: 28260
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (int)(n);i++)
using ll = long long;
const ll MOD=1000000007;
const long long INF = 1LL << 60;
const double pi=acos(-1.0);

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



int main()
{
  vector<int> vec(4,0); rep(i,3) vec[i+1]=1;
  ll A,B; cin>>A>>B; vec[A]=0,vec[B]=0;
  rep(i,4) if(vec[i]) cout<<i<<endl;
  return 0;
}


Measured memory_bytes: 3560
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (int i = a; i >= b; i--)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define sz(x) ((int) x.size())
#define rd(type, ...) type __VA_ARGS__; sc(__VA_ARGS__)
#define rdv(type, v, n) vector<type> v(n); rep(__ii, 0, n) cin >> v[__ii]
#define rdm(type, v, h, w) vector<vector<type>> v(h, vector<type>(w)); rep(__ii, 0, h) rep(__jj, 0, w) cin >> v[__ii][__jj]
typedef long long ll;
void solve();
signed main() {ios::sync_with_stdio(false); cin.tie(0);
  cout << fixed; cout.precision(12); solve(); return 0;}
template<typename T> void prv(vector<T> v) {rep(__ii, 0, sz(v)) {if (__ii) cout << ' '; cout << v[__ii];} cout << '\n';} 
template<typename T> void prm(vector<vector<T>> v) {rep(__ii, 0, sz(v)) {rep(__jj, 0, v[__ii].size()) {if (__jj) cout << ' '; cout << v[__ii][__jj];} cout << '\n';}}
template<typename T> void sc(T& x) {cin >> x;}
template<typename Head, typename... Tail> void sc(Head& head, Tail&... tail) {cin >> head; sc(tail...);}
template<typename T> void pr(const T& x) {cout << x << '\n';}
template<typename Head, typename... Tail> void pr(const Head& head, const Tail&... tail) {cout << head << ' '; pr(tail...);}
template<typename... T> void err(const T&... cod) {pr(cod...); exit(0);}

int f(vector<int> a, vector<int> b) {
  int sum = 0;
  rep(i, 0, sz(a)) sum += (a[i] - b[i]) * (a[i] - b[i]);
  int z = sqrt(sum);
  return (z * z == sum);
}

void solve() {
  rd(int, n, d);
  rdm(int, a, n, d);
  int ans = 0;
  rep(i, 0, n) rep(j, i + 1, n) ans += f(a[i], a[j]);
  pr(ans);
}

Measured memory_bytes: 256
from itertools import permutations

N,M = map(int,input().split())
AB = [0 for i in range(M)]

for i in range(M):
  ab = list(map(int,input().split()))
  AB[i] = ab

count = 0
nums = [i for i in range(1,N+1)]
pers =permutations(nums,N)
for i in pers:
  if i[0] == 1:
    flag1 = 0
    for j in range(N-1):
      flag2 = False
      for k in range(M):
        if (i[j] == AB[k][0] and i[j+1] == AB[k][1]) or (i[j] == AB[k][1] and i[j+1] == AB[k][0]):
          flag2 = True
          #print(i,i[j],i[j+1],AB[k])
      if flag2:
        flag1 += 1
    if flag1 == N-1:
      #print(i)
      count += 1
print(count)

Measured memory_bytes: 9168
import java.util.*;
import java.io.*;
public class Main
{
	static final int mod=(int)1e9+7;
	static final int inf=(int)1e9;
	static final long INF=(long)1e18;
	public static void main(String[] args)
	{
		FastScanner fs=new FastScanner();
		String s=fs.next();
		int sum=0;
		for(int i=0;i<s.length();i++)
		{
			sum=sum+Character.getNumericValue(s.charAt(i));
		}
		System.out.println(sum%9==0 ? "Yes":"No");	
	}
}
class FastScanner 
{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer("");
		public String next() 
		{
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
			
		}
		ArrayList<Integer> sieve(int n)
		{
			ArrayList<Integer> primes = new ArrayList<Integer>();
			boolean arr[]=new boolean[n+1];
			Arrays.fill(arr,true);
			arr[0]=arr[1]=false;
			for(int i=2;i*i<=n;i++)
			{
				if(arr[i]==true)
				{
					for(int j=i*i;j<arr.length;j+=i)
					{
						arr[j]=false;
					}
				}
			}
			for(int i=0;i<arr.length;i++)
			{
				if(arr[i]==true)primes.add(i);
			}
			return primes;
		}
		long pow(long x,long n)
		{
			long res=1;
			while(n>0)
			{
			   	if(n%2!=0)
			   	{
			   		res=(res*x);n--;
			   	}
			   	else
			   	{
			   		x=(x*x);n/=2;
			   	}
			}
			return res;
		}
		int gcd(int a,int b)
		{
			if(b==0)
			{
				return a;
			}
			return gcd(b,a%b);
		}
		long longgcd(long a,long b)
		{
			if(b==0)
			{
				return a;
			}
			return longgcd(b,a%b);
		}
		int[] sort(int arr[])
		{
			ArrayList<Integer> list = new ArrayList<Integer>();
			for(int i:arr)list.add(i);
			Collections.sort(list);
			for(int i=0;i<arr.length;i++)
			{
				arr[i]=list.get(i);
			}
			return arr;
		}
		char[] charsort(char arr[])
	        {
	    	ArrayList<Character> list = new ArrayList<>();
	    	for(char c:arr)list.add(c);
	    	Collections.sort(list);
	    	for(int i=0;i<list.size();i++)
	    	{
	    		arr[i]=list.get(i);
	    	}
	    	return arr;
	        }
		long[] longsort(long arr[])
		{
			ArrayList<Long> list = new ArrayList<Long>();
			for(long i:arr)list.add(i);
			Collections.sort(list);
			for(int i=0;i<arr.length;i++)
			{
				arr[i]=list.get(i);
			}
			return arr;
		}
		public int nextInt() 
		{
			return Integer.parseInt(next());
		}
		public int[] readArray(int n)
		{
			int[] arr=new int[n];
			for (int i=0; i<n; i++) arr[i]=nextInt();
			return arr;
		}	
		public long nextLong()
		{
			return Long.parseLong(next());
		}
		public long[] longreadArray(int n) 
		{
			long[] a=new long[n];
			for (int i=0; i<n; i++) a[i]=nextLong();
			return a;
		}
}

Measured memory_bytes: 36152
s = int(input())
l = []
stp = 0

for i in range(1000000):
    for j in l:
        if j == s:
            stp = 1
    
    if s%2 == 0:
        l.append(int(s))
        s = s/2
    else:
        l.append(int(s))
        s = s*3 + 1    
    
    if stp == 1:
        break

print(len(l))

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

typedef long long int ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
const ll mod = 1000000007;
const ll INF = 10010010010010010;

int main() {
    int n; cin >> n;
    long double a[n]; rep(i,n) cin >> a[i];
    long double ans = 0;
    rep(i,n) {
        ans += (long double) 1 / a[i];
    }
    cout << setprecision(15) << (long double) 1 / ans << endl;
    return 0;
}


Measured memory_bytes: 3780
#include<algorithm>
#include<bitset>
#include<cctype>
#include<cerrno>
#include<clocale>
#include<cmath>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<utility>
#include<vector>
#include<cwchar>
#include<cwctype>
using namespace std;
int n,m;
int h[100010],x[100010],y[100010],ans;
bool pan[100010];
int main(){
	scanf("%d %d",&n,&m);
	for(int i=1;i<=n;i++)
	    scanf("%d",&h[i]);
	for(int i=1;i<=m;i++)
	    scanf("%d %d",&x[i],&y[i]);
	for(int i=1;i<=m;i++)
	    if(h[x[i]]>h[y[i]])
	        pan[y[i]]=1;
	    else if(h[x[i]]<h[y[i]])
	        pan[x[i]]=1;
	    else
	        pan[y[i]]=1,pan[x[i]]=1;
	for(int i=1;i<=n;i++)
	    if(!pan[i]) {
	        ans++;
	        //printf("find %d\n",i);
	    }
	printf("%d\n",ans);
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main(){
    int N;
    cin >>N;
    vector<long long int> A(N);
    for(int i = 0 ;i < N;i++)cin >> A[i];
    int long long ans = 0;
    sort(A.begin(),A.end());
    cout << A[N-1] - A[0] << endl;
} 
 

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main(void)
{
    int k=0;
    char string[105]={};

    scanf("%d",&k);
    scanf("%s",string);

    if(strlen(string)<=k){
        printf("%s",string);
    } else {
        string[k]='.';
        string[k+1]='.';
        string[k+2]='.';
        string[k+3]='\0';
        printf("%s",string);
    }
    return 0;
}


Measured memory_bytes: 1708
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long h = sc.nextLong();
    long w = sc.nextLong();
    if(h==1l||w==1l){
      System.out.println(1);
      return;
    }
    long we= w/2,wo=w/2,ans=0l;
    if(w%2==1l){
      wo++;
    }
    ans = (we+wo)*(h/2l);
    if(h%2==1l){
      ans+=wo;
    }
    System.out.println(ans);

  }
}


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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  bitset<1001001001> res(0);
  int n; cin >> n;
  for (int i = 0; i < n; i++) {
    int a; cin >> a;
    res.flip(a);
  }
  cout << res.count() << '\n';
  return 0;
}

Measured memory_bytes: 122496
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    int n, m, q;
    cin >> n >> m >> q;
    VL a(n), b(m);
    REP(i,n) a[i] = lin();
    REP(i,m) b[i] = lin();

    a.push_back(-1e17);
    a.push_back(1e17);
    b.push_back(-1e17);
    b.push_back(1e17);
    sort(ALL(a));
    sort(ALL(b));

    while (q--){
        ll t = lin(), ans = 1e18;
        int i = lower_bound(ALL(a), t) - a.begin();
        int j = lower_bound(ALL(b), t) - b.begin();
        ll ra = a[i] - t;
        ll rb = b[j] - t;
        ll la = t - a[i - 1];
        ll lb = t - b[j - 1];
        ans = min(ans, max(ra, rb));
        ans = min(ans, max(la, lb));
        ans = min(ans, ra + lb + min(ra, lb));
        ans = min(ans, la + rb + min(la, rb));
        printf("%lld\n", ans);
    }

    return 0;
}


Measured memory_bytes: 2912
#include <bits/stdc++.h>
#define int long long
using namespace std;

int32_t main(){
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	ios::sync_with_stdio(0),cin.tie(0);
	int n,m;
	cin >> n >> m;
	int a[n]={0},p[n]={0};
	for(int i=0;i<m;i++){
		int x;
		string s;
		cin >> x >> s;
		x--;
		if(s=="AC"){
			a[x]=1;
		}
		else{
			if(!a[x])p[x]++;
		}
	}
	int x=0,y=0;
	for(int i=0;i<n;i++){
		if(a[i]){
			x++;
			y+=p[i];
		}
	}
	cout << x << " " << y;
}


Measured memory_bytes: 1792
#include <algorithm>
#include <assert.h>
#include <iostream>
#include <string.h>
#include <memory.h>
#include <stdio.h>
#include <complex>
#include <cstdlib>
#include <sstream>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <vector>
#include <string>
#include <bitset>
#include <cstdio>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include<deque>
typedef long long ll;
using namespace std;
const int N = 100000;
int arr[N];
int main() {
	
	//freopen("myfile.in", "r", stdin);
	for (int i = 1; i < N; ++i)
		arr[i] = arr[i - 1] + i;
	int x;
	scanf("%d", &x);
	int idx = lower_bound(arr, arr + N, x)-arr;
	printf("%d\n", idx);
	return 0;
}

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

using namespace std;

int main() {

    int A, B, C;
    cin >> A >> B >> C;


    int a = A;
    int b = B;
    int c = C;

    int count = 0;


    while (1) {
        if (a > b) {
            break;
        }
        if (b >= a) {
            b -= a;
            count++;
        }
        if (count == c) {
            break;
        }
    }

    int ans = count;
    cout << ans << endl;

}


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

int main(){
    int N, K;
    cin >> N >> K;
    vector<ll> p(N);
    for (int i=0; i<N; i++){
        int tmp;
        cin >> tmp;
        p[i] = tmp+1;
    }

    vector<ll> sum(N-K+1, 0);
    for (int i=0; i<K; i++){
        sum[0] += p[i];
    }
    for (int i=1; i<N-K+1; i++){
        sum[i] = sum[i-1] - p[i-1] + p[i+K-1];
    }

    ll max = 0;
    for (int i=0; i<N-K+1; i++){
        if (max < sum[i]){
            max = sum[i];
        }
    }
    cout << fixed << (long double)max / 2 << endl;
    return 0;
}


Measured memory_bytes: 3328
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
#include <cstdint>
using namespace std;
using LL = long long;

char three[3][4] = {
	"aab",
	"d.b",
	"dcc",
};
char four[4][5] = {
	"aacd",
	"bbcd",
	"ghee",
	"ghff",
};
char five[5][6] = {
	"aabbc",
	"h.iic",
	"hj..d",
	"gj..d",
	"gffee",
};
char six[6][7] = {
	"aab...",
	"d.b...",
	"dcc...",
	"...eef",
	"...h.f",
	"...hgg",
};
char seven[7][8] = {
	"aabb..d",
	".l..ccd",
	".l.mm.e",
	"k.n...e",
	"k.n..f.",
	"jii..f.",
	"j..hhgg",
};
char eleven[11][12] = {
	"aabb..d....",
	".l..ccd....",
	".l.mm.e....",
	"k.n...e....",
	"k.n..f.....",
	"jii..f.....",
	"j..hhgg....",
	".......aacd",
	".......bbcd",
	".......ghee",
	".......ghff",
};


int main() {
	int N;
	cin >> N;
	if (N == 2) {
		cout << -1 << endl;
		return 0;
	}
	if (N == 7) {
		for (auto s : seven) {
			cout << s << endl;
		}
		return 0;
	}
	if (N == 3) {
		for (auto s : three) {
			cout << s << endl;
		}
		return 0;
	}
	if (N == 11) {
		for (auto s : eleven) {
			cout << s << endl;
		}
		return 0;
	}
	if (N == 6) {
		for (auto s : six) {
			cout << s << endl;
		}
		return 0;
	}
	int x = 0, y = 0;
	while ((N - 5 * x) % 4 != 0) {
		++x;
	}
	y = (N - 5 * x) / 4;
	int now = 0;
	vector<string>ans(N, string(N, '.'));
	for (int i = 0; i < x; ++i) {
		for (int p = 0; p < 5; ++p) {
			for (int q = 0; q < 5; ++q) {
				ans[now + p][now + q] = five[p][q];
			}
		}
		now += 5;
	}
	for (int i = 0; i < y; ++i) {
		for (int p = 0; p < 4; ++p) {
			for (int q = 0; q < 4; ++q) {
				ans[now + p][now + q] = four[p][q];
			}
		}
		now += 4;
	}
	for (auto s : ans) {
		cout << s << endl;
	}
	return 0;
}

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

using ll = long long;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define REP(i, n) FOR(i, 0, n)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define ALL(c) (c).begin(), (c).end()
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
const int MOD = 1000000007;
const int INF = 1000000001;

int main() {
    int n;
    cin >> n;
    map<int, int> e;
    map<int, int> o;
    int v;
    REP(i, n) {
        cin >> v;
        if (i % 2 == 0) {
            e[v]++;
        } else {
            o[v]++;
        }
    }
    priority_queue<pair<int, int>> ep;
    priority_queue<pair<int, int>> op;
    for (auto x : e) {
        ep.emplace(x.second, x.first);
    }
    for (auto x : o) {
        op.emplace(x.second, x.first);
    }

    auto me = ep.top();
    ep.pop();
    auto mo = op.top();
    op.pop();
    if (me.second != mo.second) {
        cout << n - (me.first + mo.first) << endl;
    } else {
        auto se = ep.top();
        auto so = op.top();
        if (ep.size() == 0 && op.size() == 0) {
            cout << n / 2 << endl;
        } else {
            cout << n - max(me.first + so.first, se.first + mo.first) << endl;
        }
    }
}


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

int main()
{
    int N, M;
    cin >> N >> M;
    vector<int> v(N);
    for (int i = 0; i < M; i++)
    {
        int a, b;
        cin >> a >> b;
        v.at(a - 1)++;
        v.at(b - 1)++;
    }

    for (int i = 0; i < N; i++)
    {
        cout << v.at(i) << endl;
    }
    return 0;
}


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

typedef pair<int,int> pii;

priority_queue<pii> pq;

vector<int> adj[100005];
int n,m;
int par[100005];
int deg[100005];

int main(){
   cin >> n >> m;
   for(int i=1;i<n+m;i++){
      int u,v;
      cin >> u >> v;
      deg[v]++;
      adj[u].push_back(v);
   }
   for(int i=1;i<=n;i++){
      pii tmp;
      tmp.first = -deg[i];
      tmp.second = i;
      pq.push(tmp);
   }
   for(int i=1;i<=n;i++){
      pii lol = pq.top(); pq.pop();
      int cur = lol.second;
      for(int j=0;j<adj[cur].size();j++){
         int now = adj[cur][j];
         if(deg[now] == 1){
            par[now] = cur;
            pq.push({0,now});
         } else {
            deg[now]--;
         }
      }
   }
   for(int i=1;i<=n;i++) cout << par[i] << endl;
	return 0;
}


Measured memory_bytes: 8180
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)n; i++)
using ll = long long;

int main(){
    int n, c, k;
    cin >> n >> c >> k;
    int t[n];
    rep(i,n) cin >> t[i];
    sort(t,t+n);
    int ans = 0;
    int i = 0; 
    while(i < n){
        int p = t[i], b = 0;
        while(b < c && t[i] - p <= k && i < n){
            i++; b++;
        }
        ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
//#include <iomanip>
//#include <string>
//#include <vector>
//#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
//using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
//#define all(v) v.begin(),v.end()
//ll mod = 1000000007 ;
//long double pie = acos(-1) ;
//ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}]

int main(){
	ll n,a ;
	cin >> n >> a ;
	ll dp[51][51][2501] ;
	for(int i=0;i<=50;i++) for(int j=0;j<=50;j++) for(int k=0;k<=2500;k++) dp[i][j][k] = 0 ;
	dp[0][0][0] = 1 ;
	for(int i=1;i<=n;i++){
		ll x ; cin >> x ;
		for(int j=0;j<=n;j++) for(int k=0;k<=2500;k++) dp[i][j][k] += dp[i-1][j][k] ;
		for(int j=1;j<=n;j++) for(int k=x;k<=2500;k++) dp[i][j][k] += dp[i-1][j-1][k-x] ;
	}
	ll ans = 0 ;
	for(int i=1;i<=n;i++) ans += dp[n][i][i*a] ;
	cout << ans << endl ;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define Abs(x)((x) < 0 ? (x) * -1 : (x))

#define rep(x, y) for ((x) = 0; (x) < (y); (x)++)
#define repin(x, y) for ((x) = 0; (x) <= (y); (x)++)
#define nep(x, y) for ((x) = (y) - 1; 0 <= (x); (x)--)
#define nepi(x, y, z) for ((x) = (y) - 1; (z) <= (x); (x)--)
#define repi(x, y, z) for ((x) = (z); (x) < (y); (x)++)
#define repiin(x, y, z) for ((x) = (z); (x) <= (y); (x)++)
#define reps(x, y, z) for ((x) = 0; (x) < (y); (x) += (z))
#define repis(x, y, z, s) for ((x) = (z); (x) < (y); (x) += (s))
#define repit(x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define nepit(x) for (__typeof((x).rbegin()) it = (x).rbegin(); it != (x).rend(); it++)

#define All(x) (x).begin(),(x).end()

#define Mem0(x) memset(x, 0, sizeof(x))
#define Mem1(x) memset(x, -1, sizeof(x))

#define Unique(v) v.resize(unique(All(v)) - v.begin())

#define peq(p0, p1)(p0.first == p1.first && p0.second == p1.second)

#define End '\n'
#define Out(x) cout<<(x)<<End
#define OutP(p, sep, end) cout<<p.first<<sep<<p.second<<end

template<typename T> inline bool Max(T &x, const T &y) { return x < y ? x = y, 1 : 0; }
template<typename T> inline bool Min(T &x, const T &y) { return x > y ? x = y, 1 : 0; }
template<typename T> using V = vector<T>;
template<typename T> using VV = V<V<T> >;

#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define lb std::lower_bound
#define ub std::upper_bound

#define lbi(v, x) lb(All(v), (x))-v.begin()
#define ubi(v, x) ub(All(v), (x))-v.begin()

static const ll MOD = 1e9 + 7;
static const double PI = 3.141592653589793;

#define LOCAL 0

int main()
{
#if LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
#endif

    cin.tie(0);
    ios::sync_with_stdio(false);
	//std::cout.precision(18);

    int n, k;

	cin >> n >> k;

	if (n % k == 0) Out(0);
  	else Out(1);
	
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long int lint;
typedef pair<lint, lint> plint;
typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first - r.first, l.second - r.second); }
const lint MOD = 1e9 + 7, INF = 1e18;
typedef pair<plint, lint> query;

template< typename T >
struct BinaryIndexedTree {
	vector< T > data;

	BinaryIndexedTree(int sz) {
		data.assign(++sz, 0);
	}

	T sum(int k) {
		T ret = 0;
		for (++k; k > 0; k -= k & -k) ret += data[k];
		return (ret);
	}

	void add(int k, T x) {
		for (++k; k < data.size(); k += k & -k) data[k] += x;
	}
};

lint N, Q, L, R;
lint arr[500000];
vector<query> queries;
vector<plint> sec;
lint last[500000];
lint ans[500000];

int main() {
	cin >> N >> Q;
	REP(i, N) last[i] = -1;
	REP(i, N) {
		cin >> arr[i]; arr[i]--;
		if (last[arr[i]] != -1) sec.push_back({ last[arr[i]], i });
		last[arr[i]] = i;
	}
	REP(i, Q) {
		cin >> L >> R; L--; R--;
		queries.push_back({ { L, R }, i });
	}
	sort(ALL(queries), greater<query>());
	sort(ALL(sec), greater<plint>());
	BinaryIndexedTree<int> bit(N);
	lint sec_idx = 0;
	REP(i, Q) {
		while (sec_idx < SZ(sec) && queries[i].first.first <= sec[sec_idx].first) {
			bit.add(sec[sec_idx].second, 1);
			sec_idx++;
		}
		lint l = queries[i].first.first, r = queries[i].first.second;
		ans[queries[i].second] = (r - l + 1) - (bit.sum(r));
	}
	REP(i, Q) {
		cout << ans[i] << endl;
	}
}

Measured memory_bytes: 40288
import java.util.Scanner;

public class Main {
	public static void main(String[]args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt() - 1;
		String S = sc.next();
		sc.close();
		String[] s = S.split("");
		s [K] = s[K].toLowerCase();
		StringBuffer bf = new StringBuffer();
		for(int i=0;i<N;i++) {
			bf.append(s[i]);
		}
	System.out.print(bf.toString());
	}
}

Measured memory_bytes: 23124