akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

typedef long long ll;
ll MOD = 1000000007;

// a^p
// 2^3 = 2 * 2^2
// 2^2 = 2 * (2^1)
// 2^1 = 2
ll modpow(ll a, ll p, ll mod) {
  if (p == 0) return 1;

  if (p % 2 == 0) {
    ll half = modpow(a, p / 2, mod) % mod;
    return half * half % mod;
  } else {
    return a * modpow(a, p - 1, mod) % mod;
  }
}

// nCa を求める
ll modCombination(ll n, ll a, ll mod) {
  if (n - a < a) {
    return modCombination(n, n - a, mod);
  }

  ll denominator = 1;  // 分母
  ll numerator = 1;    // 分子

  for (ll i = 0; i < a; i++) {
    denominator *= a - i;
    numerator *= n - i;
    denominator %= mod;
    numerator %= mod;
  }

  return numerator * modpow(denominator, mod - 2, mod) % mod;
}

class UnionFind {
 private:
  vector<ll> parents;

 public:
  UnionFind(ll n) : parents(n, -1) {}

  bool issame(ll x, ll y) { return root(x) == root(y); }

  bool merge(ll x, ll y) {
    if (issame(x, y)) return false;

    ll rx = root(x);
    ll ry = root(y);
    if (parents[rx] > parents[ry]) swap(rx, ry);
    // サイズ情報を更新
    parents[rx] += parents[ry];
    // yの親を更新
    parents[ry] = rx;

    return true;
  }

  ll size(ll x) { return -parents[root(x)]; }

 private:
  ll root(ll x) {
    if (parents[x] < 0) return x;
    // 根の親の値に木の(-)サイズの情報を入れる
    return parents[x] = root(parents[x]);
  }
};

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

  ll N;
  cin >> N;
  vector<ll> X(N);
  vector<ll> Y(N);
  vector<ll> T(N);

  for (ll i = 0; i < N; i++) {
    T[i] = i;
    cin >> X[i] >> Y[i];
  }

  double ans = 0.0;
  ll count = 0;
  do {
    count++;
    for (ll i = 0; i < N - 1; i++) {
      ll s = T[i];
      ll d = T[i + 1];
      ans +=
          sqrt((X[s] - X[d]) * (X[s] - X[d]) + (Y[s] - Y[d]) * (Y[s] - Y[d]));
    }
  } while (next_permutation(T.begin(), T.end()));

  cout << ans / count << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
namespace mp = boost::multiprecision;
#define ll long long
#define cpp mp::cpp_int
#define dequeue deque
#define rep(i, n) for(int i = 0; i < n; i++)
#define rrep(i, n) for(int i = 1; i <= n; i++)
#define drep(i, n) for(int i = n-1; i >= 0; i--)
#define srep(i, s, t) for (int i = s; i < t; i++)
#define vi vector<int>
#define P pair<ll, ll>
int mod = 1'000'000'000 + 7;
struct edge {
	int to;
	ll cost;
};

void COME_LET_THE_GAMES_BEGIN() {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << setprecision(20);
}
void reverse(string* s) {
	reverse((*s).begin(), (*s).end());
}
int main() {
	COME_LET_THE_GAMES_BEGIN();
	int N, M;
	cin >> N >> M;
	vector<int> A(N);
	rep(i, N)cin >> A[i];
	vector<pair<int,int>> v;
	rep(i, M) {
		int b, c;
		cin >> b >> c;
		v.push_back(P(b, c));
	}
	sort(v.begin(), v.end(), [](auto p, auto q) {
		return p.second > q.second;
		});
	sort(A.begin(), A.end());
	int a = 0;
	for (auto x : v) {
		rep(i, x.first) {
			if (a < N && A[a] < x.second) {
				A[a] = x.second;
				a++;
			}
			else {
				break;
			}
		}
	}
	cout << accumulate(A.begin(), A.end(), 0LL) << endl;
}

Measured memory_bytes: 1784
#define F for(i=0;i<h;i++)for(j=0;j<=w;j++)if
i,j,h,w;char a[200][200];r[200],c[200];
main(){scanf("%d%d\n",&h,&w);
F((a[i][j]=getchar())==35)r[i]=c[j]=1;
c[w]=1;
F(r[i]&c[j])putchar(a[i][j]);}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
#define ALL(v) v.begin(), v.end()
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define chmax(x, a) x = max(x, a)
#define chmin(x, a) x = min(x, a)
#define MOD 998244353

const int MAX = 510000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}



int main() {
    COMinit();
    ll N, M, K;
    cin >> N >> M >> K;
    ll ans = 0;
    ll tmp = M*modpow(M-1, N-K-1, MOD) % MOD;
    for (ll i = K; i >= 0; i--) {
        ans += tmp * COM(N-1, i) % MOD;
        ans %= MOD;
        tmp = (tmp*(M-1))%MOD;
    }
    cout << ans << endl;
}


Measured memory_bytes: 15608
#include<stdio.h>
#include<stdlib.h>

typedef struct{
  char mark;
  int num;
  int in_num;
}card;

void swap (card *A,int i,int j){
  card cmp;
  cmp=A[i];
  A[i]=A[j];
  A[j]=cmp;
}



int partition(card *A,int p,int r){
  card x = A[r];
  int j,i = p-1;

  for(j=p;j<r;j++){
    if(A[j].num <= x.num){
      i++;
      swap(A,i,j);
    }
  }
  swap(A,i+1,r);

  return i+1;
}

void quicksort(card *V,int p,int r){
  int q;
  if(p<r){
    q = partition(V,p,r);
    quicksort(V,p,q-1);
    quicksort(V,q+1,r);
  }
}


int check(card *A,int N){
  int i;
  
  for(i=1;i<N;++i){
    if(A[i].num == A[i+1].num && A[i].in_num > A[i+1].in_num) return 0;
  }
  return 1; 
}



int main(){
  int n,i;
  card *A,*B;

  scanf("%d",&n);

  A = malloc(sizeof(card)*(n + 1));
 

  for(i=1;i<n+1;++i){
    scanf(" %c %d",&A[i].mark,&A[i].num);
    A[i].in_num = i;
  }

  quicksort(A,1,n);
  
  if(check(A,n))printf("Stable\n");
  else printf("Not stable\n");

  for(i=1;i<=n;++i)printf("%c %d\n",A[i].mark,A[i].num);
 
  return 0;
}




Measured memory_bytes: 2908
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
  ll n,a,b;
  cin>>n>>a>>b;
  if(n==1||a>b) {
    if(a==b){
      cout<<1;
      return 0;
    }
    cout<<0;
    return 0;
  }
  ll min=a*(n-1)+b,max=a+b*(n-1);
  cout<<max-min+1;
}

Measured memory_bytes: 256
#include <stdio.h>

void judge(int W, int H, int x, int y, int r);
int main(void)
{
    int W, H, x, y, r;
    scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
    judge(W, H, x, y, r);
    return 0;
}

void judge(int W, int H, int x, int y, int r)
{
    if (x - r >= 0 && x + r <= W && y - r >= 0 && y + r <= H) {
        printf("Yes\n");
    }else {
    printf("No\n");
    }
}

Measured memory_bytes: 1012
using System;
public class Hello{
    public static void Main(){
        long N = int.Parse(Console.ReadLine());
        long[] dp = new long[N + 1];
        
        dp[0] = 1;
        for(var i = 1;i <= N;i++){
            dp[i] = dp[i - 1] * i % 1000000007; 
        }
        Console.WriteLine(dp[N]);
    }
}


Measured memory_bytes: 11488
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>

#define INF_LL 9000000000000000000
#define INF 2000000000

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

using namespace std;

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

class Union_find{
private:
	vector<int> par;
	vector<int> rank;
	int n;

public:
	Union_find(int a){
		n = a;
		for(int i = 0;i < n;i++){
			par.push_back(i);
			rank.push_back(0);
		}
	}

	int find(int x){
		if(par[x] == x){
			return x;
		}else{
			return par[x] = find(par[x]);
		}
	}

	void unite(int x, int y){
		x = find(x);
		y = find(y);
		if(x == y) return;

		if(rank[x] < rank[y]){
			par[x] = y;
		}else{
			par[y] = x;
			if(rank[x] == rank[y]) rank[x]++;
		}
	}

	bool same(int x, int y){
		return find(x) == find(y);
	}
};

int main(void){
	int n,s,w,e;
	n = 0;
	s = 0;
	w = 0;
	e = 0;
	string d;
	cin >> d;
	REP(i, d.size()){
		switch(d[i]){
			case 'N':
				n++;
				break;
			case 'E':
				e++;
				break;
			case 'W':
				w++;
				break;
			case 'S':
				s++;
				break;
		}
	}
	if(((n > 0 && s > 0) || (n+s == 0)) && ((w > 0 && e > 0) || (w+e == 0)))
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}


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

using namespace std;
const int IINF = INT_MAX;
using ll = long long;
using P = pair<int,int>;
#define INF 1000000000000
int main(){
    int n; cin >> n;
    int x[n]; 
    rep(i,n) cin >> x[i];
    
    ll rally = INF;
 
    rep(i,101){
    	ll amount = 0;
    	rep(j,n){
    		amount+=(i-x[j])*(i-x[j]);
    	}
    	rally = min(rally,amount);
    }
    
    cout << rally << endl;
    
    return 0;	
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
typedef long long ll;
#define ALL(l)  (l).begin(),(l).end()
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
using namespace std;

//const ll mod =  1000000007;
//const ll maxn = 1000000000;

//---------------------------------------------------------------------------------------------------
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vll = vector<ll>; // intの1次元の型に vi という別名をつける
using vvll = vector<vll>; // intの2次元の型に vvi という別名をつける
using vs = vector<string>; // stringの1次元の型に vs という別名をつける
using pll = pair<ll, ll>; // これ以降 pii という型名はpair<ll, ll> と同じ意味で使える
//---------------------------------------------------------------------------------------------------


int main() {
    bool ans=false;
  int a,b,c,k;
  cin>>a>>b>>c>>k;
  
  rep(i,k){
      if(a>=b)b*=2;
      else{
          if(b>=c)c*=2;
      }
  }
  
  if(a<b&&b<c)ans=true;
  
  
  
  
   if(ans)cout<<"Yes"<<endl;
   else cout<<"No"<<endl;
   
}



Measured memory_bytes: 3620
use std::vec::Vec;
use std::cmp::*;

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

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn count_same_element<T: Eq + Copy>(v: &Vec<T>) -> Vec<usize> {

  let mut res: Vec<usize> = Vec::new();
  if v.len() == 0 {
    return res;
  }

  let mut now: T = v[0];
  let mut count: usize = 0;
  for &e in v {
    if e == now {
      count += 1;
    }
    else {
      res.push(count);
      count = 1;
      now = e;
    }
  }
  res.push(count);

  return res;
}


fn main() {
  let n: usize = read();
  let mut a: Vec<u64> = Vec::new();
  for _ in 0..n {
    let c = read();
    a.push(c);
  }

  a.sort();

  let same = count_same_element(&a);
  let ans = same.iter().fold(0, |acc, x| acc + (x % 2));
  println!("{}", ans);
}


Measured memory_bytes: 6396
// Template from https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

// input macro for competive-programming from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };

    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, bytes) => {
        read_value!($iter, String).into_bytes()
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    use std::io::Read;
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();

    println!("{}", solve(&s));
}

macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
r#"1234567876"# => r#"34"#,
r#"35753"# => r#"0"#,
r#"1111111111"# => r#"642"#,
}

fn solve(src: &str) -> String {
    input! {
        source = src,
        s: String,
    }
    let mut ans = 1000;

    for i in 0..s.len()-2 {
        let s:isize = s[i..i+3].parse::<isize>().unwrap();
        ans = std::cmp::min(ans, isize::abs(753 - s));
    }

    ans.to_string()
}

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

int main(){
  int a;
  cin>>a;
  int now;
  cin>>now;
  now--;
  for(int i=0;i<a-1;i++){
	int num;
    cin>>num;
    if(num<now){
      cout<<"No"<<endl;
      return 0;
    }
    else now=max(now,num-1);
  }
  cout<<"Yes"<<endl;
  return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define test int t;cin>>t;while(t--)
typedef long long int ll;


int main() {
    fast
    //test
    {
        int i,j,k;
        cin >> k;
      	string s;
      cin>>s;
      if(k<s.size())
      {
        for(i=0;i<k;i++)
          cout<<s[i];
        cout<<"...";
      }
      else cout<<s;
        
    }
	return 0;
}


Measured memory_bytes: 3612
const main = (input: string) => {
  let S = parseInt(input.trim())
  const A = [S];
  let isInCompleted = true;

  while (isInCompleted) {
    if(S % 2 === 0) {
      S = S / 2
    } else {
      S = (S * 3) + 1
    }
    if(A.indexOf(S) >= 0) {
      isInCompleted = false
    }
    A.push(S)
  }

  console.log(A.length)
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 7372
# -*- coding: utf-8 -*-

import sys
import os
import datetime
from itertools import combinations

for s in sys.stdin:
    n, s = map(int, s.split())
    if n == 0:
        break

    cnt = 0
    for x in combinations(range(10), n):
        if sum(x) == s:
            cnt += 1
    print(cnt)

Measured memory_bytes: 7964
n = int(input())
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())

paths = [a, b, c, d, e]
min_path = min(paths)
if n % min_path == 0:
    time = n // min_path + 4
else:
    time = n // min_path + 5

print(time)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
// #include <atcoder/all>

using namespace std;
// using namespace atcoder;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG
/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#else
#define print(...)
#endif

void solve() {
    ll K, T;
    cin >> K >> T;
    vector<ll> A(T);
    rep(i, T) cin >> A[i];
    ll m = *max_element(A.begin(), A.end());
    cout << max(0LL, m - 1 - (K - m)) << '\n';
}

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


Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1000000007;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;

int w, h, a[35][35], c[4];
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

struct state{
    int x, y, dir, dist;
    state(int x, int y, int dir, int dist): x(x), y(y), dir(dir), dist(dist){}
};

bool in(int x, int y){
    return 0<=x && x<h && 0<=y && y<w;
}

void solve(){
    rep(i, h)rep(j, w) scanf("%d", &a[i][j]);
    rep(i, 4) scanf("%d", &c[i]);
    auto cmp = [](const state &s1, const state &s2){
        return s1.dist > s2.dist;
    };
    priority_queue<state, vector<state>, decltype(cmp)> que(cmp);
    int d[h][w][4];
    rep(i, h)rep(j, w)rep(k, 4) d[i][j][k] = mod;
    d[0][0][0] = 0;
    que.emplace(0, 0, 0, 0);
    while(!que.empty()){
        auto s = que.top();
        que.pop();
        if(d[s.x][s.y][s.dir] < s.dist) continue;

        rep(i, 4){
            int nd = (s.dir + i) % 4;
            int nx = s.x + dx[nd], ny = s.y + dy[nd];
            if(in(nx, ny) && chmin(d[nx][ny][nd], s.dist + (a[s.x][s.y] != i) * c[i])){
                que.emplace(nx, ny, nd, d[nx][ny][nd]);
            }
        }
    }
    int ans = mod;
    rep(i, 4) chmin(ans, d[h-1][w-1][i]);
    printf("%d\n", ans);
}

int main(){
    while(scanf("%d%d", &w, &h) && w){
        solve();
    }
}


Measured memory_bytes: 3340
s=str(input())
n=len(s)
z=0
ans=0
i=0
while i<=n-2:
    if s[i]=='A':
        z+=1
        i+=1
        continue
    elif s[i:i+2]=='BC' and z>0:
        ans+=z
        i+=2
    else:
        z=0
        i+=1
print(ans)

Measured memory_bytes: 40688
#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

int main() {
    string S, T;
    cin >> S >> T;
    if (S.size() != T.size()) {
        cout << "No" << endl;
    } else {
        vector<set<char>> T_conpare(26), S_compare(26);
        for (ll i = 0; i < S.size(); i++) {
            S_compare[S[i] - 'a'].insert(T[i]);
            T_conpare[T[i] - 'a'].insert(S[i]);
        }

        for (ll i = 0; i < 26; i++) {
            if (S_compare[i].size() > 1 ||  T_conpare[i].size() > 1) {
                cout << "No" << endl;
                return 0;
            }
        }

        cout << "Yes" << endl;
    }
}

Measured memory_bytes: 776
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}


fn main() {
    input! {
        v: [i32; 3],
    }
    let mut v2 = v.clone();
    v2.sort();
    v2.reverse();
    let res = v2[0] * 10 + v2[1] + v2[2];
    println!("{}", res);
}


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

const int mod = 1000000007;

struct mint
{
    ll x;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint &operator+=(const mint m)
    {
        if((x += m.x) >= mod) x -= mod;
        return *this;
    }
    mint &operator-=(const mint m)
    {
        if((x += mod - m.x) >= mod) x -= mod;
        return *this;
    }
    mint &operator*=(const mint m)
    {
        (x *= m.x) %= mod;
        return *this;
    }
    mint operator+(const mint m) const
    {
        return mint(*this) += m;
    }
    mint operator-(const mint m) const
    {
        return mint(*this) -= m;
    }
    mint operator*(const mint m) const
    {
        return mint(*this) *= m;
    }
    mint pow(ll n) const
    {
        if(!n) return 1;
        mint m = pow(n>>1);
        m *= m;
        if(n & 1) m *= *this;
        return m;
    }
    mint inv() const { return pow(mod-2);}
    mint &operator/=(const mint m) { return *this *= m.inv();}
    mint operator/(const mint m) const { return mint(*this) /= m;}
};
istream &operator>>(istream &is, const mint &m) { return is >> m.x;}
ostream &operator<<(ostream &os, const mint &m) { return os << m.x;}

struct combination
{
    vector<mint> fact, ifact;
    combination(int n) : fact(n+1), ifact(n+1)
    {
        assert(n < mod);
        fact.at(0) = 1;
        for(int i=1; i<=n; i++)
        {
            fact.at(i) = fact.at(i-1) * i;
        }
        ifact.at(n) = fact.at(n).inv();
        for(int i=n; i>=1; i--)
        {
            ifact.at(i-1) = ifact.at(i) * i;
        }
    }
    mint operator()(int n, int k)
    {
        if(k < 0 || k > n) return 0;
        return fact.at(n) * ifact.at(k) * ifact.at(n-k);
    }
};

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, K;
    cin >> N >> K;
    vector<int> A(N);
    for(int i=0; i<N; i++) cin >> A.at(i);

    ll cnt_in_a_ten = 0;
    for(int i=0; i<N; i++)
    {
        for(int j=i+1; j<N; j++)
        {
            if(A[i] > A[j]) cnt_in_a_ten++;
        }
    }
    // cout << "naka:" << cnt_in_a_ten << '\n';
    
    vector<int> nums(2001, 0);
    for(auto a : A) nums[a]++;

    vector<int> cum(2001, 0);
    for(int i=2000; i>0; i--)
    {
        cum[i-1] = cum[i] + nums[i];
    }

    ll cnt_soto = 0;
    for(auto a : A) cnt_soto += cum[a];
    // cout << "soto:" << cnt_soto << '\n';

    mint ans = cnt_in_a_ten;
    ans *= K;
    mint soto = K;
    soto *= (K - 1);
    soto /= 2;
    // cout << "num soto:" << soto << '\n';
    soto *= cnt_soto;
    ans += soto;
    cout << ans << '\n';


    return 0;
}


Measured memory_bytes: 256
/*
  KUNAL ANAND
  MNNIT ALLAHABAD
*/  

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<assert.h>
using namespace std;
using namespace __gnu_pbds;
#define debug1(x) cout << # x << " " << x << endl;
#define debug2(x,y) cout << #x << " " << x << " " << #y << " " << y << endl;
#define debug3(x,y,z) cout << #x << " " << x << " " << #y << " " << y << " " << #z << " " << z << endl;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
typedef long long int ll;
const ll INF=1e16;
const ll mod=1e9+7;

ll power(ll x,ll y)
{
    if(y==0)
        return 1;
    ll a=power(x,y/2);
    a=(a*a)%mod;
    if(y%2)
        a=(a*x%mod)%mod;
    return a;
}


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

    ll t;
    ll n,q;
    ll i,j,k,a,b,m,c=1,ans1=0,ans2=0,x1,x2,y2,y1,s,mini=LLONG_MAX,idx,ans=0,l;

    string num;

    cin >> num;

    cin >> k;

    vector<ll>helper;

    n=num.length();

    for(i=0;i<n;i++)
    {
        helper.push_back(num[i]-'0');
    }

    ll dp[n+1][k];

    memset(dp,0,sizeof(dp));

    dp[0][0]=1;

    for(i=1;i<n;i++)
    {
        for(j=1;j<10;j++)
        {
            for(l=0;l<k;l++)
            {
                ll x=(j%k+l)%k;
                dp[i][x]+=dp[i-1][l];
                dp[i][x]%=mod;
            }
        }

        ans+=dp[i][0];
        ans%=mod;

        for(l=0;l<k;l++)
        {
            dp[i][l]+=dp[i-1][l];
            dp[i][l]%=mod;
        }
    }

    ll var=0;

    ll cnt=0;
    for(i=0;i<n;i++)
    {
        if(i==0)
        {    
            for(j=1;j<helper[i];j++)
            {
                for(l=0;l<k;l++)
                {
                    ll x=(j%k+l)%k;
                    x+=var;
                    x%=k;
                    dp[n][x]+=dp[n-i-1][l];
                    dp[n][x]%=mod;
                }
            }
        }
        else
        {
            for(j=0;j<helper[i];j++)
            {
                for(l=0;l<k;l++)
                {
                    ll x=(j%k+l)%k;
                    x+=var;
                    x%=k;
                    dp[n][x]+=dp[n-i-1][l];
                    dp[n][x]%=mod;
                }
            }
        }

        var+=helper[i];
        var%=k;
    }

    dp[n][var%k]++;

    ans+=dp[n][0];
    ans%=mod;

    cout << ans << endl;



    return 0;
}    

Measured memory_bytes: 8320
#include <bits/stdc++.h>
#define INF 1000000000
#define LINF 1000000000000000000
#define MOD 1000000007
#define mod 998244353
#define INF63 1061109567
#define INF127 9187201950435737471
#define UINF 18446744073709551615
#define F first
#define S second
#define ll long long
#define N 500010
using namespace std;
ll n,k[N],l[N],r[N],ans;
vector<pair<ll,ll> > lf,rg;
priority_queue<ll> pq;
int main(){
	ll T,tp,i;
	scanf("%lld",&T);
	while(T--)
	{
		scanf("%lld%",&n);
		lf.clear();
		rg.clear();
		ans=0;
		for(i=0;i<n;i++)
		{
			scanf("%lld%lld%lld",&k[i],&l[i],&r[i]);
			k[i]--;
			if(r[i]>=l[i])
			{
				rg.push_back(make_pair(k[i],l[i]-r[i]));
				ans+=r[i];
			}
			else
			{
				lf.push_back(make_pair(k[i],r[i]-l[i]));
				ans+=l[i];
			}
		}
		sort(lf.begin(),lf.end());
		sort(rg.begin(),rg.end());
		reverse(rg.begin(),rg.end());
		tp=0;
		while(!pq.empty())
		{
			pq.pop();
		}
		for(i=0;i<lf.size();i++)
		{
			pq.push(lf[i].S);
			if(tp>lf[i].F)
			{
				ans+=pq.top();
				pq.pop();
			}
			else
			{
				tp++;
			}
		}
		tp=n-1;
		while(!pq.empty())
		{
			pq.pop();
		}
		for(i=0;i<rg.size();i++)
		{
			pq.push(rg[i].S);
			if(tp<=rg[i].F)
			{
				ans+=pq.top();
				pq.pop();
			}
			else
			{
				tp--;
			}
		}
		printf("%lld\n",ans);
	}
	return 0;
}

Measured memory_bytes: 13012
unittest
{
	assert( [ "2", "1 2 1 2 2 1" ].solve == 2 );
	assert( [ "3", "1 1 2 2 3 3 3 2 1" ].solve == 1 );
	assert( [ "3", "1 1 2 2 2 3 3 3 1" ].solve == 3 );
}



import std.algorithm;
import std.container;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.solve.writeln;
}

auto solve( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.to!( long );
	input.popFront;
	auto as = input.front.split.to!( long[] );
	as[] -= 1;
	
	// インラインDP
	// dp[ (iターン目) ][ 残したカード1枚目の数字 ][ 残したカード2枚目の数字 ] = 最大得点
	auto dp = new long[][]( n, n );
	foreach( ref dpp; dp ) dpp[] = long.min;					// -2000未満にしておけば絶対0以上にならないので無視できる
	auto z = 0L;												// 全体加算値
	auto mm = 0L;												// 全体最大値
	auto ms = new long[ n ];									// 部分最大値
	ms[] = long.min;
	auto queue = DList!( Tuple!( long, long, long ) )();		// 更新キュー
	
	// 最初のカード2枚を処理
	dp[ as[ 0 ] ][ as[ 1 ] ] = 0;
	dp[ as[ 1 ] ][ as[ 0 ] ] = 0;
	ms[ as[ 0 ] ] = 0;
	ms[ as[ 1 ] ] = 0;
	as.popFrontN( 2 );
	
	// 途中のカードを3枚ずつ処理
	foreach( i; 0L .. n - 1 )
	{
		if( as[ 0 ] == as[ 1 ] && as[ 1 ] == as[ 2 ] )
		{
			// 次の3枚が全て同値の場合
			// 全てのx,yについて dp[ i+1 ][ x ][ y ] = dp[ i ][ x ][ y ] +1 が最適になるので、全体加算値に+1する
			z++;
		}
		else
		{
			foreach( j; 0 .. 3 )
			{
				auto a = as[ j ];
				auto b = as[ ( j + 1 ) % 3 ];
				auto c = as[ ( j + 2 ) % 3 ];
				
				// 前ターンのx,yを両方を残す場合
				// dp[ i+1 ][ x ][ y ] = dp[ i ][ x ][ y ] になるので、処理不要
				
				// 前ターンのx,yの片方を残す場合
				// dp[ i+1 ][ x ][ a or b or c ] = dp[ i ][ x ][ ? ].reduce!max になるので、部分最大値を使って更新する
				// また、捨て札y,b,cが全て同値の場合は+1する
				foreach( x; 0L .. n )
				{
					auto v = ms[ x ];
					if( b == c ) v = max( v, dp[ x ][ b ] + 1 );
					queue.insertBack( tuple( x, a, v ) );
				}
				
				// 前ターンのx,yのどちらも残さない場合
				// dp[ i + 1 ][ a or b or c ][ a or b or c ] = dp[ i + 1 ][ ? ][ ? ].reduce!max になるので、全体最大値を使って更新する
				// また、捨て札x,y,cが全て同値の場合は+1する
				queue.insertBack( tuple( a, b, max( mm, dp[ c ][ c ] + 1 ) ) );
			}
		}
		
		// DPテーブルと最大値を更新
		while( !queue.empty )
		{
			auto x = queue.front[ 0 ];
			auto y = queue.front[ 1 ];
			auto v = queue.front[ 2 ];
			queue.removeFront;
			
			dp[ x ][ y ] = max( dp[ x ][ y ], v );
			dp[ y ][ x ] = max( dp[ y ][ x ], v );
			ms[ x ] = max( ms[ x ], v );
			ms[ y ] = max( ms[ y ], v );
			mm = max( mm, v );
		}
		as.popFrontN( 3 );
	}
	
	// 最後のカード1枚を処理
	return max( mm, dp[ as[ 0 ] ][ as[ 0 ] ] + 1 ) + z;
}


Measured memory_bytes: 36160
import sys
def 解():
    input = sys.stdin.readline
    N,K = [int(_) for _ in input().split()]
    aP = sorted([[int(_) for _ in input().split()] for _ in range(N)],key=lambda x:x[1],reverse=True)
    dP = {}
    for t,d in aP:
        if t in dP:
            dP[t].append(d)
        else:
            dP[t] = [d]
    iSall = len(dP.keys())
    dS = set()
    aPK = aP[:K]
    for x in aPK:
        dS.add(x[0])
    iSum = sum(x[1] for x in aPK)
    i種類 = len(dS)
    iTotal = iSum + i種類**2
    if iSall == len(dS): #種類を増やす余地がない
        print(iTotal)
        exit()
    else: #種類を増やす余地があるとき
        #とりあえず地図を作る
        dPK = {}
        for t,d in aPK:
            if t in dPK :
                dPK[t].append(d)
            else:
                dPK[t] = [d]
        vT = set()
        j = K - 1
        for nt,nd in aP[K:]:
            if i種類 == iSall:
                break
            if nt not in dS:
                #for i in range(K-1,-1,-1):
                for i in range(j,-1,-1):
                    t,d = aPK[i]
                    if t not in vT:
                        dPK[t].sort()
                        vT.add(t)
                    aT = dPK[t]
                    if 1 < len(aT):
                        iNewTotal = iSum - d + nd  + (i種類+1)**2
                        if iTotal < iNewTotal:
                            iTotal = iNewTotal
                        del dPK[t][0]
                        dPK[nt]=[nd]
                        aPK[i]=[nt,nd]
                        i種類 += 1
                        iSum = iSum -d +nd
                        dS.add(nt)
                        break
                j=i-1
        print(iTotal)
解()


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

int main()
{
  int k, x, y, d, s;
  cin >> k >> x >> y;
  d = abs(x) + abs(y);
  if (k % 2 == 0 && d % 2 != 0) {
    cout << -1 << endl;
    return 0;
  }
  if (d == k) {
    cout << 1 << endl;
    cout << x << " " << y << endl;
    return 0;
  }
  if (d % 2 == 0) {
    if (k % 2 == 1) {
      s = d <= 2 * k ? 2 : 2 * ((d - 1) / (2 * k) + 1);
    } else {
      s = d <= 2 * k ? 2 : (d - 1) / k + 1;
    }
  } else {
    s = d <= 3 * k ? 3 : 2 * ((d - k - 1) / (2 * k) + 1) + 1;
  }
  cout << s << endl;
  int x0 = 0, y0 = 0, xnew, ynew;
  for (int i = 0; i < s - 2; i++) {
    if (x == x0) {
      xnew = x0;
      ynew = y > y0 ? y0 + k : y0 - k;
    } else if (abs(x - x0) >= k) {
      xnew = x > x0 ? x0 + k : x0 - k;
      ynew = y0;
    } else {
      xnew = x;
      ynew = y > y0 ? y0 + (k - abs(x - x0)) : y0 - (k - abs(x - x0));
    }
    cout << xnew << " " << ynew << endl;
    x0 = xnew;
    y0 = ynew;
  }
  if (abs(x - x0) < abs(y - y0)) {
    int k2 = k - (abs(y - y0) - abs(x - x0)) / 2;
    xnew = x > x0 ? x0 + k2 : x0 - k2;
    ynew = y > y0 ? y0 + k - k2 : y0 - (k - k2);
  } else {
    int k2 = k - (abs(x - x0) - abs(y - y0)) / 2;
    xnew = x > x0 ? x0 + k - k2 : x0 - (k - k2);
    ynew = y > y0 ? y0 + k2 : y0 - k2;
  }
  cout << xnew << " " << ynew << endl;
  cout << x << " " << y << endl;
}


Measured memory_bytes: 2304
N = int(input())
K = int(input())

# min_m = 10 ** 10
# for i in range(2 ** N):
#     m = 1
#     for n in range(N):
#         if i & (1 << n):
#             m *= 2
#         else:
#             m += K
#     min_m = min(min_m, m)

m = 1
for i in range(N):
    m = min(m * 2, m + K)

print(m)


Measured memory_bytes: 2940
from collections import deque

H = int(input())

l = [H]
q = deque(l)
ans = 0

def attack(ans,q):
    if len(q) == 0:
        print(2**ans-1)
        exit()
    else:
        a = q.popleft()
        if a == 1:
            ans += 1
        else:
            ans += 1
            q.append(a//2)
    return ans , q

while True:
    ans , q = attack(ans,q)

Measured memory_bytes: 3316
/********************************************************
  **░██████╗██╗░░░░░░█████╗░██╗░░░██╗██╗░█████╗░░██████╗░**
  **██╔════╝██║░░░░░██╔══██╗██║░░░██║██║██╔══██╗██╔════╝░**
  **╚█████╗░██║░░░░░███████║╚██╗░██╔╝██║██║░░╚═╝██║░░██╗░**
  **░╚═══██╗██║░░░░░██╔══██║░╚████╔╝░██║██║░░██╗██║░░╚██╗**
  **██████╔╝███████╗██║░░██║░░╚██╔╝░░██║╚█████╔╝╚██████╔╝**
  **╚═════╝░╚══════╝╚═╝░░╚═╝░░░╚═╝░░░╚═╝░╚════╝░░╚═════╝░**
  *********************************************************/

#include <bits/stdc++.h>
using namespace std;


#define ll                          long long
#define ld                          long double

#define forn(i,n)                   for(int i=0;i<n;++i)
#define all(v)                      v.begin(), v.end()
#define rall(v)                     v.rbegin(),v.rend();
#define isSubstring(s1,s2)          s1.find(s2) != std::string::npos
	
#define pb                          push_back
#define pf                          push_front
#define mp                          make_pair
#define fr                          first
#define sc                          second

#define vpi                         <vector<pair<int,int>>
#define vi                          vector<int>
#define sz(a)                       (int)a.size()

#define   endl                       "\n"
#define     nl                       cout<<"\n";
#define fastio                       ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

#define MN                           INT_MIN
#define MX                           INT_MAX

bool isPrime(ll n){if(n<2)return false;for(ll x = 2;x*x <=n;x++){if(n%x == 0)return false;}return true;}
bool isPerfectSquare(long double x){long double sr=sqrt(x);return((sr-floor(sr))==0);}
int gcd(int a, int b){if(a==0)return b;if(b==0) return a;if(a==b)return a;if(a>b)return gcd(a-b,b);return gcd(a,b-a);}
int lcm(int a, int b){return(a*b)/gcd(a, b);}  


int32_t main()
{
	ll a,b;
	cin >> a >> b;
	if(a < b)swap(a,b);
	for(ll i = a;i<= 1e18;i+= a)
	{
		if(i%b==0)
		{
			cout << i << endl;
			return 0;
		}
	}
}

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

using namespace std;
typedef long long ll;

#define MOD (long long)(1e9+7)
#define INF (1LL<<60)
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define rep1(i,n) for(ll i = 1; i <= (n); i++)

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;
}


// 最大公約数
ll gcd(ll a, ll b)
{
  if(b == 0) return a;
  return gcd(b, a % b);
}

// mod m におけるa の逆元
ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

// 素因数分解
vector<pair<ll, ll>> prim;
void pf(ll n)
{
  ll s = sqrt(n);
  ll r = 0;
  for(ll i = 2; i <= s; i++) {
    if((n % i) == 0) {
      r = 0;
      do {
	r++;
	n = n / i;
      } while((n % i) == 0);
      prim.push_back({i, r});
    }
  }
  if(n > s) {
    prim.push_back({n, 1});
  }
}

using Graph = vector<vector<int>>;

void solve()
{
  ll N, X, Y; cin >> N >> X >> Y;
  X--;Y--;
  
  Graph G(N);
  rep(i, N-1) {
    G[i].push_back(i+1);
    G[i+1].push_back(i);
  }
  G[X].push_back(Y);
  G[Y].push_back(X);

  vector<int> ans(N, 0);
  rep(st, N) {
    vector<int> dist(N, -1);
    queue<int> que;
    
    dist[st] = 0;
    que.push(st);
    
    while(!que.empty()) {
      int v = que.front();
      que.pop();
      
      for(int nv : G[v]) {
	if(dist[nv] != -1) continue;
	
	dist[nv] = dist[v] + 1;
	que.push(nv);
      }
    }
    for(int v = 0; v < N; v++) ans[dist[v]] ++;
  }
  
  rep1(i, N - 1) cout << (ans[i]/2) << endl;
}


int main(void)
{
  // ll t; cin >> t; REP(i, t)
  solve();
}


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

using namespace std;


typedef long long ll;
const ll MOD = 1e9 + 7;
#define cerr cout
#define sz(a) (ll)((a).size())
#define all(x) (x).begin(), (x).end()
string to_string(string s) { return '"' + s + '"';}
string to_string(char s) { return string(1, s);}
string to_string(const char* s) { return to_string((string) s);}
string to_string(bool b) { return (b ? "true" : "false");}
template <typename A> string to_string(A);
template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}
template <typename A> string to_string(A v) {bool f = 1; string r = "{"; for (const auto &x : v) {if (!f)r += ", "; f = 0; r += to_string(x);} return r + "}";}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {cerr << " " << to_string(H); debug_out(T...);}
#define pr(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
inline ll add(ll a, ll b){a += b; if(a >= MOD)a -= MOD; return a;}
inline ll sub(ll a, ll b){a -= b; if(a < 0)a += MOD; return a;}
inline ll mul(ll a, ll b){return (ll)((long long) a * b %MOD);}
inline ll binpow(ll a, ll b){ll res = 1; while(b > 0){ if(b & 1)res = mul(res, a); a = mul(a, a);b /= 2;} return res;}
inline ll inv(ll a){return binpow(a, MOD - 2);}
ll gcd(ll a, ll b, ll &x, ll &y){if(a == 0){x = 0, y = 1; return b;} ll x1, y1;  ll d = gcd(b%a, a, x1, y1); x = y1 - (b/a) * x1; y = x1; return d;}



int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

	ll q; cin>>q; 
	priority_queue<ll> left; 
	priority_queue<ll ,vector<ll>, greater<ll>> right; 

	ll constant = 0, sum_left = 0, sum_right =0; 
	while(q--){
		ll t; cin>>t;
		if(t == 1){
			ll a, b; cin>>a>>b; 
			constant += b; 
			if(right.empty() || a < right.top())left.push(a), sum_left += a; 
			else{
				ll top = right.top(); right.pop(); 
				right.push(a); sum_right += a - top; 
				left.push(top); sum_left += top; 
			}
			if((ll)left.size() - (ll)right.size() > 1){
				ll top = left.top(); left.pop(); sum_left -= top; 
				right.push(top); sum_right += top; 
			}
		}else if(t == 2){
			ll less = (ll)left.size(), great = (ll)right.size(); 
			ll val = left.top(); 
			cout<<val<<" "<<less*val - sum_left + sum_right - great*val + constant<<"\n"; 
		}
	}

    return 0;
}

Measured memory_bytes: 3828
#include<vector>
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<map>
#include<functional>
#include<queue>
#include<stack>
#include<string.h>
#include<list>
#define MOD 1000000007LL
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
int main() {
    string s;
    cin>>s;
    int n=s.length();
    ll ans=0;
    for(int i=0;i<(1<<(n-1));i++){
        ll sum=s[0]-'0';
        for(int j=1;j<n;j++){
            int b=s[j]-'0';
            if(i>>(j-1)&1){
                ans+=sum;
                sum=b;
            }else{
                sum*=10;
                sum+=b;
            }
        }
        ans+=sum;
    }
    cout<<ans<<endl;
}


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

#define debug(s) cout << s << endl
#define debug1(s, t) cout << s << " " << t << endl
#define debug2(s, t, u) cout << s << " " << t << " " << u << endl
#define printvec(v)       \
    for (auto &&i : v)    \
        cout << i << " "; \
    cout << endl

using namespace std;
using i64 = long long;

int main()
{
    int H, N;
    cin >> H >> N;
    vector<int> a(N), b(N);
    for (int i = 0; i < N; i++)
    {
        cin >> a[i] >> b[i];
    }

    int amax = 0;
    for (auto &&ai : a)
    {
        amax = max(amax, ai);
    }

    vector<int> DP(H + amax);
    DP[0] = 0;
    for (int h = 1; h < H + amax; h++)
    {
        int mn = numeric_limits<int>::max();
        for (int j = 0; j < N; j++)
        {
            if (h < a[j])
                mn = min(mn, DP[0] + b[j]);
            else
                mn = min(mn, DP[h - a[j]] + b[j]);
        }
        DP[h] = mn;
    }

    int ans = numeric_limits<int>::max();
    for (int h = H; h < H + amax; h++)
    {
        ans = min(ans, DP[h]);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 384
n = int(input())
dic = {}
List = list(map(int,input().split()))

for item in List:
  mini_list = [item-1,item,item+1]
  for value in mini_list:
    if value not in dic:
      dic[value] = 1
    else:
      dic[value] +=1

print(max(dic.values()))

Measured memory_bytes: 18796
# 入力 : 数字3つ
X, A, B = map(int, input().split())

# 出力　高橋君が食品をおいしく感じた場合 delicious を、
# おいしくは感じなかったがお腹は壊さなかった場合 safe を、
# お腹を壊した場合 dangerous を出力するプログラムを作成してください。

if A >= B :
    print("delicious")
elif (B-A) <= X :
    print("safe")
else :
    print("dangerous")


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

int main(){
    int n; cin >> n;
    map<int, int> mp;
    int ans = 0;

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

    for(auto itr=mp.begin(); itr!=mp.end(); itr++){
        if((itr->second)%2 == 1) ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 4864
N = int(input())
A = list(map(int, input().split()))

print(' '.join(map(str, A)))

for i in range(1, N):
  v = A[i]
  j = i - 1
  while j >= 0 and A[j] > v:
    A[j], A[j+1] = A[j+1], A[j]
    j -= 1
  print(' '.join(map(str, A)))



Measured memory_bytes: 5600
#include<bits/stdc++.h>
using namespace std;
#define ALL(obj) (obj).begin(), (obj).end()

#define endl "\n"
#define pb push_back
#define cout_db cout << fixed

#define MOD 1000000007LL
#define PI 3.1415926

typedef long long ll;

template <typename T>
inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <typename T>
inline T LCM(T a,T b){T c=GCD(a,b);a/=c;return a*b;}
template <typename T>
inline T nCr(T a,T b){T i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
template <typename T>
inline T nHr(T a,T b){return nCr(a+b-1,b);}
template <typename T>
inline T POW(T a,T b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}

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

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

	int cnt[45];
	memset(cnt, 0, sizeof(cnt));

	for (int i = 0; i < n; i++) {
		ll tmp = a[i]; int index = 0;
		while(tmp != 0){
			if(tmp % 2) cnt[index]++;
			tmp /= 2;
			index++;
		}
	}
	bool used[45] = {0};
	ll tmp = 1, ans = 0, MAX = 0, kk = k;
	for (int i = 0; i < 45; i++) {
		if(cnt[i] <= n/2 and kk % 2) {
			if(MAX+tmp > k) break;
			MAX += tmp;
			used[i] = 1;
		}
		kk /= 2;
		tmp *= 2;
	}
	tmp = pow(2, 44);
	for (int i = 44; i >= 0; i--) {
		if(cnt[i] <= n/2 and !used[i]){
			if(MAX+tmp <= k) MAX += tmp;
		}
		tmp /= 2;
	}
	cerr << MAX << endl;
	for (int i = 0; i < n; i++) {
		ans += MAX ^ a[i];
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1024
fun main(args : Array<String>) {
    val (n, k) = readLine()!!.split(" ").map { it.toInt() }
    val hh = IntArray(n){ readLine()!!.toInt() }
    hh.sort()

    var min = Int.MAX_VALUE

    for (i in 0..n-k) {
        val diff = hh[i+k-1] - hh[i]
        if (diff < min) min = diff
    }

    println(min)
}

Measured memory_bytes: 42768
import java.lang.Math;
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int K = sc.nextInt();

    long answer = 0;
    for (int b = K+1; b <= N; b++) {
      answer += (N/b) * (b-K) + Math.max(0, (N%b-K+1));
    }

    if (K == 0) { answer -= N; }

    System.out.println(answer);
  }
}


Measured memory_bytes: 23764
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
#include <stdio.h>
#include <stack>
#include <queue>
#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
#include <fstream>
#include <cctype>
 
using namespace std;
 
#define Int int64_t
 
void printVec(std::vector<int>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec1(std::vector<string>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
 
template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
	vector.erase(vector.begin() + index);
}
 
int vector_finder(std::vector<string> vec, string number) {
	auto itr = std::find(vec.begin(), vec.end(), number);
	size_t index = std::distance(vec.begin(), itr);
	if (index != vec.size()) { // 発見できたとき
		return 1;
	}
	else { // 発見できなかったとき
		return 0;
	}
}
 
#include <sstream> 
std::vector<std::string> StringSplit(const std::string& str, char sep)
{
	std::vector<std::string> v;
	std::stringstream ss(str);
	std::string buffer;
	while (std::getline(ss, buffer, sep)) {
		v.push_back(buffer);
	}
	return v;
}
 
 
 
int main() {
	string str; cin >> str;
 
	for (int i = 0; i < 3; i++) {
		//cout << str[i];
		if (str[i] == '1') str[i] = '9';
		else if (str[i] == '9') str[i] = '1';
	}
 
	cout << str;
 
	cout << endl;
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef long  double lb;
int mod=1e9+7;
const int N=4e6+5;
int a[100];
long  double b[100];
int main()
{
  a[1]=1;
  b[1]=1;
  for(int i=2;i<=30;i++)
    {a[i]=a[i-1]*2;
     b[i]=b[i-1]*0.5;
    }
  lb ans=0;
  int n,m;cin>>n>>m;
  for(int i=1;i<=n;i++){
      for(int j=1;j<=18;j++){
        if(i*a[j]>=m) {ans+=b[j];break;}
      }
  }
  printf("%.15llf",ans/n);
  return 0;
}


Measured memory_bytes: 256
/*
#include <vector>
#include <cstddef>

struct union_find {
    using size_type = std::size_t;
private :
    size_type _size;
    std::vector<int> node;
public :
    union_find (size_type n) : node(n, -1), _size(n) { }

    bool unite (size_type x, size_type y) {
        if ((x = root(x)) == (y = root(y))) return false;
        if (node[x] > node[y]) std::swap(x, y);
        node[x] += node[y];
        node[y] = x;
        _size--;
        return true;
    }

    bool same (size_type x, size_type y) {
        return (root(x) == root(y));
    }

    size_type root (size_type x) {
        if (node[x] < 0) return x;
        return node[x] = root(node[x]);
    }

    size_type size (size_type x) {
        return (size_type(-node[root(x)]));
    }

    const size_type &size () const noexcept {
        return _size;
    }

};
*/

#include <iostream>
#include <atcoder/dsu>

using usize = std::size_t;

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	usize n, q;
	std::cin >> n >> q;
	atcoder::dsu uf(n);
	for (usize i = 0; i < q; i++) {
		usize type, u, v;
		std::cin >> type >> u >> v;
		if (type == 0) uf.merge(u, v);
		else std::cout << uf.same(u, v) << '\n';
	}
	return 0;
}

Measured memory_bytes: 3968
N, K = map(int, input().split())
A = [i for i in range(N+1)]
S = [0] * (N+2)
mod = 10 ** 9 + 7

for right in range(1, N+2):
    S[right] = S[right-1] + A[right-1]

total = S[N+1]
ans = 0
for left in range(N+2):
    total -= A[max(left-1, 0)]
    if (N+1) - left >= K:
        ans += (total - S[(N+1)-left] + 1) % mod

print(ans % mod)

Measured memory_bytes: 27104