akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>
#define MAX 10001
#define NIL -1

struct Node { int parent, left, right; };

struct Node T[MAX];
int n, D[MAX], H[MAX];

void setDepth(int u, int d) {
  if(u == NIL ) return;
  D[u] = d;
  setDepth(T[u].left, d + 1);
  setDepth(T[u].right, d + 1);
}

int setHeight(int u) {
  int h1 = 0, h2 = 0;
  if(T[u].left != NIL ) {
    h1 = setHeight(T[u].left) +1;
      }
  if(T[u].right != NIL ) {
    h2 = setHeight(T[u].right) +1;
  }
  return H[u] = ( h1 > h2 ? h1 : h2 );
  //h1 > h2 真ならh1を返し、偽ならh2を返す
}

//節点 u の兄弟を返す
int getSibling(int u) {
  if(T[u].parent == NIL) {
    return NIL;
  }
  else if(T[T[u].parent].left != u && T[T[u].parent].left != NIL) {
    return T[T[u].parent].left;
  }
  else if(T[T[u].parent].right != u && T[T[u].parent].right != NIL) {
    return T[T[u].parent].right;
  }
  else return NIL;
}

void print(int u) {
  printf("node %d: ", u);
  printf("parent = %d, ", T[u].parent);
  printf("sibling = %d, ", getSibling(u));
  int deg = 0;
  if( T[u].left != NIL ) deg++;
  
  if( T[u].right != NIL ) deg++;
	
  printf("degree = %d, ", deg);
  printf("depth = %d, ",D[u]);
  printf("height = %d, ", H[u]);

  if ( T[u].parent == NIL ) {
    printf("root\n");
  } else if ( T[u].left == NIL & T[u].right == NIL ) {
    printf("leaf\n");
  } else {
    printf("internal node\n");
  }
}

int main() {
  int i;
  int v,l,r,root = 0;
  scanf("%d",&n);

  for(i = 0; i < n; i++ ) T[i].parent = NIL;

  for(i = 0; i < n; i++ ) {
    scanf("%d %d %d",&v,&l,&r);
    T[v].left = l;
    T[v].right = r;
    if( l != NIL ) T[l].parent = v;
    if( r != NIL ) T[r].parent = v;
  }

  for (i = 0; i < n; i++ ) if (T[i].parent == NIL ) root = i;

  setDepth(root, 0);
  setHeight(root);

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

  return 0;
}
  

Measured memory_bytes: 624
use std::collections::HashSet;

fn read1<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

pub fn readn<T: std::str::FromStr>(delimiter: &str) -> Vec<T> {
    let s = read1::<String>();
    s.split(delimiter).map(|e| e.parse().ok().unwrap()).collect::<Vec<T>>()
}

fn main() {
    let n = read1::<usize>();
    let a = readn::<usize>(" ");
    let mut set = HashSet::new();
    let mut v = Vec::new();

    for i in 0..n {
        if set.contains(&a[i]) {
            v.push(a[i]);
            set.remove(&a[i]);
        } else {
            set.insert(a[i]);
        }
    }

    v.sort();
    let l = v.len();
    if l < 2 {
        println!("0");
    } else {
        println!("{}", v[l-1] * v[l-2]);
    }
}

Measured memory_bytes: 10484
import java.util.Scanner;

public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int X=sc.nextInt();
    int a=X%500;
    int Y=X-a;
    int N=Y/500;
    int b=a%5;
    int Z=a-b;
    int M=Z/5;
    System.out.println((1000*N)+(5*M));
  }
}

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

using namespace std;

int main() {
    cin.tie(nullptr); ios::sync_with_stdio(false);
	
	int K, X; cin>>K>>X;
	for (int i = X-K+1; i <= X+K-1; i++)
	    cout << i << ' ';
	cout << endl;
	
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int s=0,n,k,a,b,i,j,m[101],x,y;
	scanf("%d%d%d%d",&n,&a,&b,&k);
	for(i=0;i<n;i++)scanf("%d",&m[i]);
	for(i=0;i<n;i++){
		for(j=i+1;j<n;j++){
			if(m[i]<m[j]){
				x=m[i];
				m[i]=m[j];
				m[j]=x;
			}
		}
	}
	for(i=1;i<=n;i++){
		x=0;
		for(j=0;j<i;j++)x+=m[j];
		y=(k+x)/(a+b*i);
		if(s<y)s=y;
	}
	printf("%d\n",s);
	return 0;
}


Measured memory_bytes: 2048
S = list(input())

if "N" in S and "W" not in S and "S" in S and "E" not in S:
    print("Yes")
elif "N" not in S and "W" in S and "S" not in S and "E" in S:
    print("Yes")
elif "N" in S and "W" in S and "S" in S and "E" in S:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
using namespace std;
int dp[10000];
int solve(int num){
    if(num==6174){
        return 0;
    }else if(dp[num]){
        return dp[num];
    }else{
        int x[4];
        x[0]=num%10;
        x[1]=(num%100-num%10)/10;
        x[2]=(num%1000-num%100)/100;
        x[3]=(num%10000-num%1000)/1000;
        sort(x,x+4);
        dp[num]=solve(x[3]*999+x[2]*90-x[0]*999-x[1]*90)+1;
        return dp[num];
    }
    
}
int main(void){
   
 
   int N;
   while(1){
       cin>>N;
        
       if(N==0)break;
       
       if(N==1111||N==2222||N==3333||N==4444||N==5555||N==6666||N==7777||N==8888||N==9999){
           cout<<"NA"<<endl;
       }else{
           cout<<solve(N)<<endl;
       }
       
      
   }

}

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

int main() {
  int N, K, h = 0;
  cin >> N >> K;
  string S;
  cin >> S;
  for (int i = 0; i < N - 1; i++) {
    if (S.at(i) == S.at(i + 1)) h++;
  }
  cout << min(h + K * 2, N - 1) << endl;
}

Measured memory_bytes: 512
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	Scanner sc = new Scanner(System.in);

	final int MAX = 1000 * 1000;
	final int INF = 1 << 29;
	int dp[];
	int dp2[];

	void init() {
		dp = new int[MAX + 1];
		dp2 = new int[MAX + 1];
		Arrays.fill(dp, INF);
		Arrays.fill(dp2, INF);
		// dp[i][j] i番目までのtetraの和でjを作る時の最小個数
		// dp[i+1][j] = Math.min(dp[i][j],dp[i][j-tetra[i+1]]+1);
		dp[0] = 0;
		dp2[0] = 0;
		for (int i = 1;; i++) {
			int tetra = i * (i + 1) * (i + 2) / 6;
			if (tetra > MAX)
				break;
			for (int j = 1; j <= MAX; j++) {
				if (j - tetra < 0)
					continue;
				dp[j] = Math.min(dp[j], dp[j - tetra] + 1);
				if (tetra % 2 != 0) {
					dp2[j] = Math.min(dp2[j], dp2[j - tetra] + 1);
				}
			}
		}
	}

	void run() {
		init();

		while (true) {
			int n = sc.nextInt();
			if (n == 0)
				break;
			System.out.println(dp[n] + " " + dp2[n]);
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}

}

Measured memory_bytes: 29284
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main() {
  int m,n;
  vector<float> a;
  float votes = 0;
  cin >> n >> m;
  REP(i,n) {
    float tmp;
    cin >> tmp;
    votes += tmp;
    a.push_back(tmp);
  }
  stable_sort(ALL(a),greater<int>());
  REP(j,m) {
    if(a[j] < votes/(4*m)){
      cout << "No";
      return 0;
    }
  }
  cout << "Yes";
  return 0;
}

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

using namespace std;

int main() {
	int h, w; cin >> h >> w;
	vector<vector<pair<int, int> > > lcnt(h + 2, vector<pair<int, int> >(w + 2, make_pair(0, 0)));
	vector<vector<pair<int, int> > > rcnt(h + 2, vector<pair<int, int> >(w + 2, make_pair(0, 0)));
	vector<string> s(h);
	for (int i = 0; i < h; ++i) cin >> s[i];
	for (int i = 1; i <= h; ++i) {
		for (int j = 1; j <= w; ++j) {
			if (s[i - 1][j - 1] == '.') {
				lcnt[i][j].first += lcnt[i][j - 1].first + 1;
				lcnt[i][j].second += lcnt[i - 1][j].second + 1;
			}
		}
	}
	for (int i = h; i > 0; --i) {
		for (int j = w; j > 0; --j) {
			if (s[i - 1][j - 1] == '.') {
				rcnt[i][j].first += rcnt[i][j + 1].first + 1;
				rcnt[i][j].second += rcnt[i + 1][j].second + 1;
			}
		}
	}
	int ans = 0;
	for (int i = 1; i <= h; ++i) {
		for (int j = 1; j <= w; ++j) {
			int tmp = 0;
			if (lcnt[i][j].first != 0) tmp++;
			if (lcnt[i][j].second != 0) tmp++;
			if (rcnt[i][j].first != 0) tmp++;
			if (rcnt[i][j].second != 0) tmp++;
			ans = max(ans, lcnt[i][j].first + lcnt[i][j].second + rcnt[i][j].first + rcnt[i][j].second - tmp + 1);
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 67200
#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

class Solution {
private:
public:
	/* time: O(1), space: O(1) */
	long double maximumVolume(int L) {
		long double r = L;
		r /= 3;
		return r * r * r;
	}
};

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

	Solution sol;
	const long double ans = sol.maximumVolume(L);
	cout << fixed << setprecision(12) << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()

const int N = (int)3e5;

ll mpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
  else return mpow(a,b-1) * a % MOD;
}
ll lpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = lpow(a,b/2); return memo*memo;}
  else return lpow(a,b-1) * a;
}
ll gcd(ll a, ll b){
  if(b==0) return a;
  else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
  if(kaijo_memo.size() > n) return kaijo_memo[n];
  if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
  while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
  return kaijo_memo[n];
}
vector<ll> gyaku_kaijo_memo;
ll gyaku_kaijo(ll n){
  if(gyaku_kaijo_memo.size() > n) return gyaku_kaijo_memo[n];
  if(gyaku_kaijo_memo.size() == 0) gyaku_kaijo_memo.push_back(1);
  while(gyaku_kaijo_memo.size() <= n) gyaku_kaijo_memo.push_back(gyaku_kaijo_memo[gyaku_kaijo_memo.size()-1] * mpow(gyaku_kaijo_memo.size(), MOD-2) % MOD);
  return gyaku_kaijo_memo[n];
}

ll nCr(ll n, ll r){
  if(n == r) return 1;//0個の丸と-1個の棒みたいな時に時に効く？不安.
  if(n < r || r < 0) return 0;
  ll ret = 1;
  ret *= kaijo(n); ret %= MOD;
  ret *= gyaku_kaijo(r); ret %= MOD;
  ret *= gyaku_kaijo(n-r); ret %= MOD;
  return ret;
}


int main(void){
  int n;
  cin>>n;
  vector<int> A;
  rep(i,n){
    A.push_back(0);
  }
  rep(i,n){
    int a;
    cin>>a;a--;
    A[a] = i+1;
  }
  rep(i,n){
    cout<<A[i]<<" ";
  }
  cout<<endl;
  return 0;
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,j) FOR(i,0,j)

const int INF = 1 << 24;

typedef unsigned long long ull;

int main(){
    int N, A, B, C, D[110];
    std::cin >> N;
    std::cin >> A >> B;
    std::cin >> C;

    REP(i, N){
        std::cin >> D[i];
    }

    
    int dp[110][110];// トッピング, 値段 => 最大カロリー
    
    REP(i, N){
        REP(j, N){
            dp[i][j] = 0;
        }
    }

    dp[0][1] = D[0];

    FOR(i, 1, N){
        REP(j, N){
            dp[i][j] = dp[i-1][j];
            if(j-1 >= 0){
                dp[i][j] = std::max(dp[i][j], dp[i-1][j-1] + D[i]);
            }
        }
    }
    
    int res = 0;
    REP(i, N){
        res = std::max(res, (C+dp[N-1][i]) / (A+B*i));
    }

    std::cout << res << std::endl;
}

Measured memory_bytes: 1208
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, f, n) for (ll i = (f); i < (n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define INIT    \
    cin.tie(0); \
    ios::sync_with_stdio(false);

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

ll const INF = 1LL << 60;
ll const MOD = 1000000007;
ll const MAX_N = 3234566670;
// ll const MAX_N = 1000;
vector<ll> nums;

void dfs(ll n) {
    if (n > MAX_N) return;

    nums.pb(n);
    ll r = n % 10;

    for (ll i = -1; i <= 1; i++) {
        if (r + i >= 0 && r + i <= 9) {
            dfs(n * 10 + r + i);
        }
    }
}

int main() {
    INIT;
    ll K;
    cin >> K;

    reps(i, 1, 10) { dfs(i); }
    sort(ALL(nums));
    // repv(nums) cout << *it << " ";
    // cout << endl;

    cout << nums[K - 1] << endl;

    return 0;
}

Measured memory_bytes: 4240
//的場梨沙★担当
//結城晴★副担当
//日野茜★副担当
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string.h>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <cctype>
#include <complex>
#include <regex>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <stdio.h>


using namespace std;

int main(void) {
   int A,B,C;
   cin>>A>>B>>C;

   cout<<(A*B)/2<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a) 
#define dumparr(a,n) 
#endif
#define FOR(i, a, b) for(ll i = a;i < b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = b-1;i >= a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;

const ll INF=(1LL<<50);
#if __cplusplus>=201700L
ll gcd(ll a, ll b) {
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
#endif

template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}


void solve(long long N){
  if(N%2==0){
    cout<<N/2-1<<endl;
  }else{
    cout<<N/2<<endl;
  }
}

int main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define rrep(i, n) for (ll i = n - 1; i >= 0; i--)
#define Rep(i, r, n) for (ll i = r; i < n; i++)
#define RRep(i, r, n) for (ll i = n - 1; i <= r; i--)
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define int long long
#define pb push_back
#define mp make_pair
const int dx[] = {0, -1, 0, 1};
const int dy[] = {1, 0, -1, 0};
const int MOD = (1000000007);
//const int MOD = (998244353);
//const int INF = (1 << 30)-1;
const int INF = (1LL << 60) - 1;
const double EPS = (1 >> 30);

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

using Graph = vector<vector<pair<int, int>>>;

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

    int n, k;
    cin >> n >> k;
    if ((n - 1) * (n - 2) / 2 < k)
    {
        cout << -1 << endl;
    }
    else
    {
        int l=0;
        cout << n - 1 + (n - 1) * (n - 2) / 2 - k << endl;
        rep(i, n - 1)
        {
            cout << 1 << " " << i + 1+1 << endl;
        }
        int memo = (n - 1) * (n - 2) / 2 - k;
        for (int i = 1; i < n - 1; i++)
        {
            for (int j = i + 1; j < n; j++)
            {
                if (memo == 0)
                {
                    l++;
                    break;
                }
                memo--;
                cout << i+1 << " " << j+1 << endl;
            }
            if(l==1){
                break;
            }
        }
    }
}

Measured memory_bytes: 256
def binarySearch(arr,key)
  left=0
  right=@n
  while left<right
    mid=(left+right)/2
    if arr[mid]==key
      return mid
    elsif key<arr[mid]
      right=mid
    else
      left=mid+1
    end
  end
  return FALSE
end
cnt=0
@n=gets.to_i
s=gets.split.map(&:to_i)
q=gets.to_i
t=gets.split.map(&:to_i)
t.each do |key|
  if binarySearch(s,key)
    cnt+=1
  end
end
puts cnt

Measured memory_bytes: 17312
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <time.h>
#include <list>

using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define reps(x,c) for(auto x:c)
#define all(x) begin(x), end(x)
#define pb(a) emplace_back(a) 
#define mp(a,b) make_pair((a),(b))
#define pl pair<ll,ll>
#define INF 2147483600
#define MOD 1000000007
#define fi first
#define se second
#define dbg(x) cout << #x"="<< (x) << endl
#define dbgv(x) cout<<#x<<endl;reps(y,x){cout<<y<<" ";}cout<<endl

int main(){
  ll n;cin>>n;
  vector<ll> v(n);rep(i,n)cin>>v[i];
  map<int,int> even,odd;
  rep(i,n){
    if(i%2==0){
      even[v[i]]++;
    }else{
      odd[v[i]]++;
    }
  }

  vector<pl> even_v,odd_v;
  reps(x,even){
    even_v.pb(mp(x.se,x.fi));
  }
  reps(x,odd){
    odd_v.pb(mp(x.se,x.fi));
  }

  even_v.pb(mp(0,0));
  odd_v.pb(mp(0,0));

  sort(all(even_v),greater<pl>());
  sort(all(odd_v),greater<pl>());

  if(even_v[0].se!=odd_v[0].se){ 
    cout<<n-even_v[0].fi-odd_v[0].fi<<endl;
  }else{
    cout<<n-max(even_v[0].fi+odd_v[1].fi,even_v[1].fi+odd_v[0].fi)<<endl;
  }

  return 0;
}

Measured memory_bytes: 8052
// デバッグ実行：Ctrl+F5

using System;

class Program
{
    static void Main(string[] args)
    {
        String line;
        line = Console.ReadLine();
        String[] words = line.Split(' ');
        
        if (line.Length == 3)
        {
            Console.Write(line[2]);
            Console.Write(line[1]);
            Console.WriteLine(line[0]);
        }
        else
        Console.WriteLine(line);
    }
}

Measured memory_bytes: 11092
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=1e9+7;
ll gcd(ll a,ll b){
    if(a>b)swap(a,b);
    if(a==0)return b;
    else return gcd(b%a,a);
}
signed main(){
    ll n,k;cin>>n>>k;
    vector<ll>a(n);
    ll now=0;
    rep(i,n){
        cin>>a[i];
        now=gcd(now,a[i]);
    }
    bool f=0;
    rep(i,n){
        if(a[i]>=k){
            if((a[i]-k)%now==0)f=1;
        }
    }
    cout<<(f?"POSSIBLE":"IMPOSSIBLE")<<endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <unordered_map>

using namespace std;

long long n, a[100000 + 10], result = 0;
unordered_map<long long, long long> u;

void read() {
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        result = result ^ a[i];
        u[a[i] ^ (a[i] - 1)] = 1;
    }
}

long long solve() {
    long long x  = 0;
    for(int i = 30; i >= 0; i--) {
        if(result & (1LL << i)) {
            if(u.find((1LL << (i + 1)) - 1LL) != u.end()) {
                x++;
                result = result ^ ((1LL << (i + 1)) - 1LL);
            } else {
                return -1;
            }
        }
    }
    return x;
}

int main()
{
    read();
    cout << solve();
    return 0;
}

Measured memory_bytes: 1152
import std.stdio;
import std.conv;
import std.string;
import std.array;
import std.algorithm;

void main() {
	auto n = readln.chomp.to!int;
	auto a = readln.chomp.split(" ").map!(to!long).array;
	long[long] table;
	
	foreach (e;a) {
		++table[e];
	}

	table.rehash;

	long patterns = 0;
	foreach (value;table.values) {
		patterns += value * (value - 1) / 2;
	}

	foreach (e;a) {
		auto v = table[e];
		if (v < 2) {
			writeln(patterns);
		} else {
			writeln(patterns - (v * (v - 1) / 2) + ((v - 1) * (v - 2) / 2));
		}
	}
}


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

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

int main(){
    double L;
    cin >> L;
    double x, y, z;
    x = L/3, y = L/3, z = L/3;
    double ans = x * y * z;
    printf("%.7f\n", ans);
    return 0;
}


Measured memory_bytes: 3748
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>

#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <queue>
#include <unordered_map>
#include <unordered_set>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

class A {
public:
    static constexpr int kStressIterations = 0;

    static void generateTest(std::ostream& test) {
    }

    void solve(std::istream& cin, std::ostream& cout) {
        string s;
        cin >> s;

        int N = s.size() + 1;

        vector<int> A(N);
        vector<int> pos;
        if (s.front() == '<') pos.push_back(0);
        if (s.back() == '>') pos.push_back(N - 1);

        REP(i, s.size() - 1) {
            if (s[i] == '>' && s[i + 1] == '<') {
                pos.push_back(i + 1);
            }
        }

        for (auto i : pos) {
            A[i] = 0;
            int l = i;
            while (l - 1 >= 0 && s[l - 1] == '>') {
                l--;
                A[l] = max(A[l], A[l + 1] + 1);
            }
            int r = i;
            while (r + 1 <= N - 1 && s[r] == '<') {
                r++;
                A[r] = max(A[r], A[r - 1] + 1);
            }
        }

        int res = 0;
        REP(i, N) res += A[i];
        cout << res << endl;

    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    A solver;
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 6172
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    string x, y;
    cin >> x >> y;
    if(x > y) cout << '>' << endl;
    else if(x == y) cout << '=' << endl;
    else cout << '<' << endl;
    
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<set>
using namespace std;
long long int mod = 1e9 + 7;
template <class T>
void inputV(vector<T> &x, int n){
  for(int i=0; i<n; i++) cin >> x[i];
}

int dx[4] = {0, 0, 1, -1};
int dy[4] = {-1, 1, 0, 0};

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  for(int i=0; i<h; i++) cin >> s[i];

  vector< vector<int> > cost(h, vector<int>(w, 1e9));
  cost[0][0] = 1;
  queue< pair<int, int> > q;
  q.push({0, 0});
  while(!q.empty()){
    pair<int, int> p = q.front();
    q.pop();
    int x = p.first;
    int y = p.second;
    for(int d=0; d<4; d++){
      int nx = x + dx[d];
      int ny = y + dy[d];
      if(nx < 0 || ny < 0 || nx >= w || ny >= h) continue;
      if( s[ny][nx] == '#' ) continue;
      if(cost[ny][nx] != 1e9) continue;
      cost[ny][nx] = cost[y][x] + 1;
      q.push({nx, ny});
    }
  }
  int sp = 0;
  for(int i=0; i<h; i++){
    for(int j=0; j<w; j++){
      if( s[i][j] == '#' ) sp++;
    }
  }
  if(cost[h-1][w-1] == 1e9) {
    cout << -1 << endl;
    return 0;
  }

  cout << (h*w) - sp - cost[h-1][w-1] << endl;

  return 0;
}




//


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args) {	
	Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int[] list=new int[n];
		long[][] result =new long[n][21];
		for(int i=0;i<n;i++)list[i]=sc.nextInt();
		result[0][list[0]]=1;
		for(int i=0;i<n-2;i++){
			for(int j=0;j<21;j++){
				if(result[i][j]!=0&&j+list[i+1]<=20)result[i+1][j+list[i+1]]+=result[i][j];
				if(result[i][j]!=0&&j-list[i+1]>=0)result[i+1][j-list[i+1]]+=result[i][j];
			}
		}
		System.out.println(result[n-2][list[n-1]]);

	}

}

Measured memory_bytes: 18104
#include<iostream>
#include<string>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;
const long long INF=4000000000000000000LL;
typedef pair<long long,int> P;
int main(){
	int N,M,a=1;
	cin>>N>>M;
	for(int i=0;i<M;++i)a*=2;
	cout<<((N-M)*100+M*1900)*a<<endl;
	return 0;
}


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

using namespace std;

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

    int a, b, c, d;
    cin >> a >> b >> c >> d;

    cout << max(max(1ll * a * c, 1ll * a * d), max(1ll * b * c, 1ll * b * d)) << endl;

    return 0;
}


Measured memory_bytes: 3644
s=input()
o=["R","U","D"]
e=["L","U","D"]
for i in range(len(s)):
  if i%2==0:
    if s[i] in o:
      pass
    else:
      print("No")
      break
  else:
    if s[i] in e:
      pass
    else:
      print("No")
      break
else:
  print("Yes")

Measured memory_bytes: 9052
#include<iostream>
#include<vector>
#include<set>
#include<algorithm>


using ll =  long long;

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

using namespace std;

int main(){

    int n;
    cin >> n;
    set<int> d;
    
    rep(i,n) {
        int t;
        cin >> t;
        d.insert(t);
    }

    cout << d.size() << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
#include <map>
#include <stack>
#include <queue>
//#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define urept(soeji, start, n) for (int soeji = start; soeji < n; soeji++)
#define drept(soeji, start, n) for (int soeji = start; soeji > n; soeji--)
//input
int main(void)
{
    string s;
    cin >> s;
    int cnt = 0;
    for (int i = 0; i < s.length() - 1; i++)
    {
        if (s[i] == s[i + 1] && s[i] == '0')
        {
            s[i + 1] = '1';
            cnt++;
        }
        else if (s[i] == s[i + 1] && s[i] == '1')
        {
            s[i + 1] = '0';
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3728
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 100005;

int main() {
    int n, k; cin >> n >> k;
    ll sum = 0;
    for (int i = 1; i <= n; i++) {
        int ct = (n-n%i)/i;
        sum += (i-min(k,i))*ct;
        sum += n%i+1-min(k,n%i+1);
        if (k == 0) sum--;
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	static int maxn = 300 + 10;

	public static void main(String[] args) 
	{
		Scanner cin = new Scanner(System.in);
		int a[]=new int [200000+100];
		int n=cin.nextInt();
		for(int i=0;i<n;i++)
			{a[i]=cin.nextInt();}
		Arrays.sort(a,0,n);
		boolean flag=true;
		for(int i=1;i<n;i++)
		{
			//System.out.print(a[i]+" ");
			if(a[i]==a[i-1])
				flag=false;
		}
		if(flag)
			System.out.println("YES");
		else 
			System.out.println("NO");
	}

}

Measured memory_bytes: 64424
#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<stdlib.h>
#include<queue>
#include<map>
#include<vector>
#include<cmath>
#include<fstream>
#include <set>
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
const int  MAXN =2e5+10;
const int mod = 1e9 + 7;
const long long INF = 0x7f7f7f7f7f7f7f7f;
const int inf= 0x3f3f3f3f;
#define eps 1e-8
#define PI 3.1415926535898
#define lowbit(x) (x&(-x))
using namespace std ;
//getline(cin,s);
//set<ll>::iterator it;
//map<int,int>::iterator it;
typedef long long ll;
int need[MAXN][64];
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		ll a;
		scanf("%lld",&a);
		int to=0;
		while(a)
		{
			need[i][to++]=a%2;
			a/=2;
		}
	}
	for(int i=63;i>=0;i--)
	{
		int num1=0,num2=0;
		for(int j=1;j<=n;j++)
		{
			if(need[j][i]) num1++;
			else num2++;
		}
		if(num1%2)// 奇数 
		{
			for(int j=1;j<=n;j++)
			{
				need[j][i]^=1;
			}
		}
	} 
	for(int i=1;i<=n;i++)
	{
		ll sum=0,num=1;
		for(int j=0;j<64;j++)
		{
			if(need[i][j]) sum+=num;
			num*=2;
		}
		if(i==1) printf("%lld",sum);
		else printf(" %lld",sum);
	}
}

Measured memory_bytes: 53756
#ifndef VS
#include<bits/stdc++.h>
#endif

using namespace std;
typedef long long LL;

#ifdef BTK
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww {cww() {CIN_ONLY{ios::sync_with_stdio(false); cin.tie(0);}}
}star;
#define DEBUG if(0)
#endif

#define ALL(v) (v).begin(),(v).end()
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l, T r){bool a = l>r; if (a)l = r; return a;}
template <typename T>inline bool chmax(T &l, T r){bool a = l<r; if (a)l = r; return a;}
template <typename T>istream& operator>>(istream &is, vector<T> &v){for (auto &it : v)is >> it;return is;}

class range {private: struct I { int x; int operator*() { return x; }bool operator!=(I& lhs) { return x<lhs.x; }void operator++() { ++x; } }; I i, n;public:range(int n) :i({ 0 }), n({ n }) {}range(int i, int n) :i({ i }), n({ n }) {}I& begin() { return i; }I& end() { return n; }};

int x[1123456];
int y[1123456];
LL d[1123456];
int E=0;
typedef vector<int> V;
typedef vector<V> VV;
constexpr LL INF = 1e18;
int main() {
	int N, M;
	cin >> N >> M;
	int s, t;
	cin >> s >> t;
	s--;
	t--;
	VV g(N);
	for (int i : range(M)) {
		int a, b, c, cost;
		cin >> a >> b >> c >> cost;
		a--;
		b--;
		c--;
		x[E] = a; y[E] = b; d[E] = cost;
		g[a].push_back(E); g[b].push_back(E); E++;
		x[E] = b; y[E] = c; d[E] = cost;
		g[b].push_back(E); g[c].push_back(E); E++;
		x[E] = c; y[E] = a; d[E] = cost;
		g[c].push_back(E); g[a].push_back(E); E++;
	}
	vector<LL> p(N, INF);
	p[s] = 0;
	priority_queue<pair<LL, int>> que;
	que.push({ 0ll,s });
	while (que.size()) {
		int v; LL q;
		tie(q, v) = que.top(); q = -q; que.pop();
		if (p[v] < q)continue;
		for (int e : g[v]) {
			int u = v ^ x[e] ^ y[e];
			LL nq = q + d[e];
			if (chmin(p[u], nq)) {
				que.push({ -nq,u });
			}
		}
	}
	cout << p[t] << endl;
	return 0;
}



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

int main() {
  string str;
  cin >> str;
  bool n = false, w = false, s = false, e = false;

  int i;
  for (i = 0; i < str.length(); i++) {
    if (str.at(i) == 'N') {
      n = true;
    } else if (str.at(i) == 'W') {
      w = true;
    } else if (str.at(i) == 'S') {
      s = true;
    } else {
      e = true;
    }
  }
  cout << (!(n ^ s) && !(w ^ e) ? "Yes" : "No") << endl;

  return 0;
}


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

using ll = long long;
//print(fixed << setprecision(10));
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define repk(i,n,k) for(ll i = k; i < (n); i++)
#define all(n) n.begin(), n.end()
#define print(n) cout << n << endl
double PI = acos(-1.0);
int INF = 1e9;
ll LINF = 1e18;
ll MOD = 1e9+7;


int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    
    int n;
    cin >> n;
    print((1000-n%1000)%1000);
}

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

int main() {
    int n, y; cin >> n >> y;
    
    for (int i = 0; i <= n; i++)
    {
        for (int j = 0; j <= n - i; j++)
        {
            if ((10000 * i + 5000 * j + 1000 * (n - i - j)) == y) {
                cout << i << " " << j << " " << n - i - j << endl;
                return 0;
            }
        }
        
    }
    
    cout << "-1 -1 -1" << endl;
    return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
typedef int64_t llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define ld PRId64



int main(){
    int n;
    cin >> n;
    int sum=0;
    int mi=1000;
    int tmp;
    REP(i,n){
        cin >> tmp;
        sum+=tmp;
        if(tmp%10!=0) if(tmp < mi) mi=tmp;
    }
    if(sum%10!=0) cout << sum << endl;
    else if( mi == 1000) cout << 0 << endl;
    else cout << sum - mi << endl;
}

Measured memory_bytes: 256
#define DEBUG(...)
/*                        Strip me down and go to town                        */
/*                          Lick me over upside down                          */
/*                     Pound and pound and pound and pound                    */
/*                        Baby make me make that sound                        */
/*                Aaah, aaah, aaah, aaah, aaaaaaaaaaaaaaaaaah!                */
#include<stdio.h>
#include<vector>

using namespace std;

typedef long long int LL;

const LL MOD = 1000000007;
const int maxN = 100005;

vector<int>lis[maxN];
int n, k;

LL serc(int x, int p) {
  LL way = k - (p!=x);
  LL ret = 1;
  for (int i = 0, j = 1; i < lis[x].size(); i++) {
    if (lis[x][i] != p) {
      ret = ret * ((way - j++) * serc(lis[x][i], x) % MOD) % MOD;
    }
  }
  return ret;
}

int main() {
  scanf("%d %d", &n, &k);
  for (int i = 1; i < n; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    lis[a-1].push_back(b-1);
    lis[b-1].push_back(a-1);
  }
  printf("%lld\n", k * serc(0, 0) % MOD);
  return 0;
}

Measured memory_bytes: 11520
#include <stdio.h>

int main()
{
    long inputN;
    int inputK, printOutput = 0;
    
    scanf("%ld %d", &inputN, &inputK);
    
    while(1)
    {
        inputN /= inputK;
        printOutput += 1;
        
        if(inputN == 0)
        {
            break;
        }
    }
    
    printf("%d\n", printOutput);
}


Measured memory_bytes: 128
// She is Pretty pretty!
#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define ff first
#define ss second
#define mp make_pair
#define pb push_back

const int N = 1e6+100;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n ;
    cin >> n;
    vector<int > a(n+1);
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }
    int cnt = 0, mx = n+1;
    for(int i = 1; i <= n; i++){
        if(a[i] < mx){
            mx = a[i];
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define maxn 300005
#define ll long long

ll a,b,c,d,k1,k2;
ll s1[maxn],s2[maxn];

int main()
{
    cin>>a>>b>>c>>d;
    ll lcm=c*d/__gcd(c,d);
    ll s1=a/c,s2=b/c,s=0;
    if(a%c==0)s1--;
    s=s2-s1;
    s1=a/d,s2=b/d;
    if(a%d==0)s1--;
    s+=s2-s1;
    s1=a/lcm,s2=b/lcm;
    if(a%lcm==0)s1--;
    s2=s2-s1;
    s-=s2;
    cout<<b-a-s+1;
    return 0;
}

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

#define FOR(i,l,r) for(int i = (l);i < (r);i++)
#define ALL(x) (x).begin(),(x).end()
template<typename T> bool chmax(T& a,const T& b){return a < b ? (a = b,true) : false;}
template<typename T> bool chmin(T& a,const T& b){return b < a ? (a = b,true) : false;}
typedef long long ll;

int N;
ll dp [100001] [3];
const ll INF = 1e17;

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

	cin >> N;

	fill(dp [0],dp [N + 1],-INF);
	dp [0] [0] = 0;
	FOR(i,0,N){
		ll A;
		char C;
		if(i == 0){
			cin >> A;
			chmax(dp [i + 1] [0],dp [i] [0] + A);
		}
		else{
			cin >> C >> A;
			for(int j = 0;j <= 2;j++){
				for(int k = C == '-';k <= min(j + (C == '-'),2);k++){
					chmax(dp [i + 1] [k],dp [i] [j] + (k % 2 == 0 ? A : -A));
				}
			}
		}
	}

	cout << *max_element(dp [N],dp [N + 1]) << endl;

	return 0;
}


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

using namespace std;
using LL = long long;
using P = pair<LL,LL>;
const LL INF=1e11;

LL N, M;
vector<LL> A, A_rev, sum;

LL count(LL mid){
	int i=0, num=0;
	LL res=0;
	while(i<N){
		LL a=A_rev[i];
		for(int j=num; j<N; j++){
			LL b=A[j];
			if(a+b>=mid){
				res+=N-j;
				i++, num=j;
				break;
			}
			if(j==N-1) i=N;
		}
	}
	return res;
}

P calc(LL p){
	LL num=0, res=0;
	rep(i,N){
		LL a=A_rev[i];
		int k=upper_bound(A.begin(),A.end(),p-a)-A.begin();
		num+=N-k, res+=(sum[N]-sum[k])+a*(N-k);
	}
	return {res,num};
}

bool is_over(LL mid, LL key){
	LL res=count(mid);
	if(res<key) return true;
	else return false;
}

LL binary_search(LL key){
	LL left=0, right=INF;
	while(right-left > 1){
		LL mid=left+(right-left)/2;
		if(is_over(mid,key)) right=mid;
		else left=mid;
	}
	return left;
}

int main(){
	cin >> N >> M;
	A=vector<LL>(N), A_rev=vector<LL>(N);
	rep(i,N) cin >> A[i];
	sort(A.begin(),A.end());
	rep(i,N) A_rev[i]=A[N-1-i];
	LL p=binary_search(M);
	sum=vector<LL>(N+1);
	rep(i,N) sum[i+1]=sum[i]+A[i];
	P c=calc(p);
	LL ans=c.first+p*(M-c.second);
	cout << ans << endl;

	return 0;
}

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

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

    ll x, y;
    cin >> x >> y;

    ll mul = x;
    int count = 0;
    while (mul <= y) {
        mul *= 2;
        ++count;
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
int main() {
	int a,b,c;
  	scanf("%d/%d/%d",&a,&b,&c);
  	if (b <= 4 && a <= 2019 && c <= 30) printf("Heisei");
  	else printf("TBD");
  	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#define endl '\n'
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int N, K, d, a;
    map<int, bool> stable;
    cin >> N >> K;
    for(int i=0; i<K; i++){
        cin >> d;
        for(int j=0; j<d; j++){
            cin >> a;
            if(stable[a]!=1){
                stable[a] = 1;
                N--;
            }
        }
    }
    cout << N;


    return 0;
}



Measured memory_bytes: 3664
#define _USE_MATH_DEFINES
#include<iostream>
#include<math.h>
#include <iomanip>

using namespace std;

int main(void){
	double r;
	cin >> r;

	cout << fixed << setprecision(20) << r*r*M_PI <<" "<< fixed << setprecision(20) << 2.0*r*M_PI << endl;
	return 0;
}

Measured memory_bytes: 1288
#include<iostream>
#include<cstdio>
using namespace std;
long long n,a[111111],b[111111],cnt,cur;
int main()
{
	scanf("%lld",&n);
	for (int i=1;i<=n;i++)
	scanf("%lld%lld",&a[i],&b[i]);
	for (int i=n;i>=1;i--)
	{
		cur=(a[i]+cnt)%b[i];
		if (cur) cur=b[i]-cur;
		cnt+=cur;
	}
	printf("%lld\n",cnt);
	return 0;
 } 

Measured memory_bytes: 1792
#include<iostream>
using namespace std;
int main()
{
    // 整数の入力
    char a[200000];
    char b[200000];
    uint32_t count = 0;
    cin >> a;
    cin >> b;
  
    for (uint32_t i = 0; a[i] != '\0' && b[i] != '\0' && i < 200000; ++i) {
       if (a[i] != b[i]) {
         ++count;
       }
    }

    // 出力
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 3536
#include <bits/stdc++.h>
#include <stdio.h>
#include <algorithm>
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)
#define rn(i,n) for(int i=1;i<=n;i++)

int main(void){
  int n;
  cin>>n;
  vector<double> a(n);
  double sum;

  r(i,n){cin>>a.at(i);}
  r(i,n){sum+=1/a.at(i);}

  if(sum!=0)cout<<1/sum<<endl;
  else cout<<"error"<<endl;



  return 0;
}


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

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

using namespace std;
using ll = long long;

const int MOD = 1000000007;

struct mint { int n; mint(int n_ = 0) : n(n_) {} };
mint operator-(mint a) { return -a.n + MOD * (a.n != 0); }
mint operator+(mint a, mint b) { int x = a.n + b.n; return x - (x >= MOD) * MOD; }
mint operator-(mint a, mint b) { int x = a.n - b.n; return x + (x < 0) * MOD; }
mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }
istream &operator>>(istream &i, mint &a) { return i >> a.n; }
ostream &operator<<(ostream &o, mint a) { return o << a.n; }

vector<mint> F_{1, 1}, R_{1, 1}, I_{0, 1};

void check_fact(int n) {
  for (int i = I_.size(); i <= n; i++) {
    I_.push_back(I_[MOD % i] * (MOD - MOD / i));
    F_.push_back(F_[i - 1] * i);
    R_.push_back(R_[i - 1] * I_[i]);
  }
}

mint I(int n) { check_fact(abs(n)); return n >= 0 ? I_[n] : -I_[n]; }
mint F(int n) { check_fact(n); return n < 0 ? 0 : F_[n]; }
mint R(int n) { check_fact(n); return n < 0 ? 0 : R_[n]; }
mint C(int n, int r) { return F(n) * R(n - r) * R(r); }
mint P(int n, int r) { return F(n) * R(n - r); }
mint H(int n, int r) { return n == 0 ? (r == 0) : C(n + r - 1, r); }

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  // xoxoxoxoxox
  int N, K;
  cin >> N >> K;
  for (int i = 1; i <= K; i++) {
    cout << H(i, K-i) * H(i+1,N-K-(i-1)) << '\n';
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
  int N, M, ans=0;
  cin >> N >> M;
  int C[M], D[M-1];
  rep(i, M){
    cin >> C[i];
  }
  if(N<M){
   sort(C, C+M);
   rep(i, M-1){
     D[i] = C[i+1]-C[i];
   }
   sort(D, D+M-1);
   rep(i, M-N){
     ans += D[i];
  }
  }
  cout << ans << endl;
}


Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class MainClass
{
	public const long Giri = 1000000007;

	public static void Main(string[] args)
	{
		var p = Input().ToInt();
		int five = 0;
		int seven = 0;
		foreach(var i in p)
		{
			if(i == 5) five++;
			else if(i == 7) seven++;
			else
			{
				Console.WriteLine("NO");
				return;
			}
		}
		if(five == 2 && seven == 1)
			Console.WriteLine("YES");
		else
			Console.WriteLine("NO");
		

	}
	
	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(' '); }
	public static int Clamp(int val, int max, int min = 0) { return Math.Min(max, Math.Max(min, val)); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt();
		return r;
	 }
}


Measured memory_bytes: 11092
s = int(input())
a = [0]*1000010

i = 1
a[s] = 1
while True:
	i += 1
	s = s//2 if s%2 == 0 else 3*s+1
	if a[s] == 0:
		a[s] = i
	else:
		print(i)
		break

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

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

using namespace std;

int main() {
  int n;
  cin >> n;
  int cnt = 0;
  bool succ = true;
  rep(i,n) {
    string s;
    cin >> s;
    if( s == "A" ) ++cnt;
    else           --cnt;
    if( cnt < 0 ) succ = false;
  }
  if( cnt != 0 ) succ = false;
  puts(succ?"YES":"NO");
  return 0;
}

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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int A[10101];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	
	int X,Y;
	for(i=1;i<=999;i++) {
		A[i]=A[i-1]+i;
	}
	cin>>X>>Y;
	for(i=1;i<=998;i++) {
		if(A[i+1]-A[i]==Y-X) {
			cout<<A[i+1]-Y<<endl;
			return;
		}
	}
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){

	int n;
	long long int tmp=0;
	vector<int> v;

	cin>> n;
	v.resize(n);
	for(int i=0;i<n;i++) cin>> v[i];

	for(int i=0;i<n;i++){
		if(i%2==0) tmp+=v[i];
		else tmp-=v[i];
	}
	cout<< tmp <<endl;

	for(int i=0;i<n-1;i++){
		tmp=2*v[i]-tmp;
		cout<< tmp <<endl;
	}

}

Measured memory_bytes: 1664