akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
using namespace std;

int main(){
int n;cin>>n;
vector<long long> v(n);
for(int i=0;i<n;i++)cin>>v[i];
map<long long ,long long> m;
for(int i=0;i<n;i++)m[v[i]]++;
long long ans=0;
for(auto it=m.begin();it!=m.end();it++){
    if(it->second<it->first)ans+=it->second;
    else ans+=it->second-it->first;
}
cout<<ans;
    
}

Measured memory_bytes: 7040
#include <iostream>      // cout, endl, cin
#include <vector>
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound


using namespace std;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

int main()
{
    int N;
    cin >> N;
    vector<int> vec(N);
    rep(i, N) cin >> vec[i];
    int ans = -1000000010;
    int minv = vec[0];

    rep2(i, 1, N)
    {
        ans = max(vec[i] - minv, ans);
        minv = min(minv, vec[i]);
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 3608
#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++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef pair<int, int> p;
typedef priority_queue<p> pq;
typedef priority_queue<p, vector<p>, greater<p>> gpq;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int a, b;
    cin >> a >> b;

    cout << ((b - a - 1) * (1 + (b - a - 1)) / 2) - a << endl;
}

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

const long long MOD = 1000000007;
const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

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

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int A, B, X;
  cin >> A >> B >> X;
  if (A <= X && X <= A + B)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}


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

long long ans;
int main()
{
	int n;
	cin >> n;
	for( int i = 0; i < n; i++ ) {
		int a;
		cin >> a;
		ans += a;
	}
	ans -= n;
	cout << ans << endl;
}

Measured memory_bytes: 256
def main():
    a, b, c, k = map(int, input().split())
    answer = min(a, k)
    k -= min(a, k)
    if k > 0:
        k -= min(b, k)
    if k > 0:
        answer -= min(k, c)
    print(answer)


if __name__ == '__main__':
    main()



Measured memory_bytes: 9176
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		String s = stdIn.next();
		char[] S = s.toCharArray();
		Arrays.sort(S);
		String s1 = new String(S);
		String t = stdIn.next();
		char[] T = t.toCharArray();
		Arrays.sort(T);
		String t1 = new String(T);
		String t2 = new StringBuilder(t1).reverse().toString();
		if(s1.compareTo(t2) < 0) {
			System.out.println("Yes");
		}
		else {
			System.out.println("No");
		}
	}

}

Measured memory_bytes: 23124
let (n1, n2) = (3, 9)
(* let (n1, n2) = (4, 16) *)

let n_limit = 100
let mdt = Array.make_matrix n2 n2 0
let path = Array.make n_limit 0
let dx = [| 0; -1; 0; 1 |]
let dy = [| 1; 0; -1; 0 |]
let dir = [| "r"; "u"; "l"; "d" |]

type puzzle = { f : int array; space : int; md : int }

let initialize_mdt () =
  for i = 0 to n2 - 1 do
    for j = 0 to n2 - 1 do
      mdt.(i).(j) <- abs (i / n1 - j / n1) + abs (i mod n1 - j mod n1)
    done
  done

let get_all_md f =
  Array.fold_left (fun (i, sum) e ->
    (i + 1, if e = n2 then sum else sum + mdt.(i).(e-1)))
    (0, 0) f
  |> snd

let dfs pzl limit =
  let rec doit depth prev pzl =
    if pzl.md = 0 then true
    else if depth + pzl.md > limit then false
    else begin
      let sx = pzl.space / n1 in
      let sy = pzl.space mod n1 in
      let rec move r =
        if r = 4 then false
        else begin
          let tx = sx + dx.(r) in
          let ty = sy + dy.(r) in
          if tx < 0 || ty < 0 || tx >= n1 || ty >= n1 then move (r + 1)
          else if max prev r - min prev r = 2 then move (r + 1)
          else begin
            let { f; space; md } = pzl in
            let a = tx*n1 + ty in
            let b = sx*n1 + sy in
            let md = md - mdt.(a).(f.(a) - 1) in
            let md = md + mdt.(b).(f.(a) - 1) in
            let newf = Array.init n2 (fun i -> f.(i)) in
            let t = newf.(a) in
            newf.(a) <- newf.(b);
            newf.(b) <- t;
            if doit (depth + 1) r { f = newf; space = a; md } then begin
              path.(depth) <- r;
              true
            end else move (r + 1)
          end
        end in
      move 0
    end in
  doit 0 (-n_limit) pzl

let idastar f space =
  let pzl = { f; space; md = get_all_md f } in
  let rec doit limit =
    if limit > n_limit then assert false
    else if dfs pzl limit then begin
      let str = ref "" in
      for i = 0 to limit - 1 do
        str := !str ^ dir.(path.(i));
      done;
      !str
    end else doit (limit + 1) in
  doit pzl.md

let () =
  initialize_mdt ();
  let f = Array.make n2 0 in
  let space = ref 0 in
  for i = 0 to n2 - 1 do
    f.(i) <- Scanf.scanf "%d " (fun i -> i);
    if f.(i) = 0 then begin
      f.(i) <- n2;
      space := i;
    end
  done;
  idastar f !space |> String.length |> Printf.printf "%d\n"

Measured memory_bytes: 4448
/*
 * @Author: Kaizyn
 * @Date: 2020-08-27 16:16:35
 * @LastEditTime: 2020-08-27 17:08:14
 */
#include <bits/stdc++.h>

// #define DEBUG

using namespace std;

const long long INF = 1e18;
const int N = 53;
const int L = 23;

int n;
int c[N];
long long dp[2][N][L];
string s[2][N];

template <typename T, typename U>
inline void update(T &x, const U &y) {
  if (x == -1 || y < x) x = y;
}

inline bool is_palindrome(const string &str) {
  for (int i = 0, j = str.size()-1; i < j; ++i, --j)
    if (str[i] != str[j]) return false;
  return true;
}

long long dfs(int rev, int id, int pos) {
  if (~dp[rev][id][pos]) return dp[rev][id][pos];
  if (is_palindrome(s[rev][id].substr(pos))) return dp[rev][id][pos] = 0;
  dp[rev][id][pos] = INF; // dead for loop
  long long res = -1;
  int lk = s[rev][id].size();
  for (int i = 1, j, k, lj; i <= n; ++i) {
    lj = s[rev^1][i].size();
    for (j = 0, k = pos; j < lj && k < lk; ++j, ++k) {
      if (s[rev^1][i][j] != s[rev][id][k]) break;
    }
    if (j == lj && k == lk) {
      update(res, c[i]);
    } else if (j == lj) {
      if (~dfs(rev, id, k)) update(res, c[i]+dp[rev][id][k]);
    } else if (k == lk) {
      if (~dfs(rev^1, i, j)) update(res, c[i]+dp[rev^1][i][j]);
    }
  }
  return dp[rev][id][pos] = res;
}

inline void solve() {
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> s[0][i] >> c[i];
    s[1][i] = s[0][i];
    reverse(s[1][i].begin(), s[1][i].end());
  }
  long long res = -1;
  memset(dp, -1, sizeof dp);
  for (int i = 1; i <= n; ++i) {
    // if (is_palindrome(s[0][i])) update(res, c[i]);
    if (~dfs(0, i, 0)) update(res, c[i]+dp[0][i][0]);
  }
  cout << res << endl;
}

signed main() {
  ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
  int T = 1;
  // cin >> T;
  for (int t = 1; t <= T; ++t) {
    solve();
  }
  return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<n;++i)
#define rep2(i,a,b) for (ll i=a;i<b;++i)
const ll MOD=1e9+7;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

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

int main(){
    string A;
    cin >> A;
    int s=A.size();
    vector<vector<int>> pos(26);
    rep(i,s) pos[A[i]-'a'].push_back(i);
    string ans="";
    queue<pair<int,string>> que;
    que.push(make_pair(-1,""));
    vector<bool> used(s,false);
    bool finished=false;
    while(!finished){
        pair<int,string> p=que.front();
        que.pop();
        int now=p.first;
        string S=p.second;
        rep(i,26){
            if (upper_bound(pos[i].begin(),pos[i].end(),now)==pos[i].end()){
                if (ans==""||ans.size()>(int)S.size()+1) ans=S+char('a'+i);
                finished=true;
            }
            else {
                int next=*upper_bound(pos[i].begin(),pos[i].end(),now);
                if (!used[next]){
                    que.push(make_pair(next,S+char('a'+i)));
                    used[next]=true;
                }
            }
        }
    }
    cout << ans << endl;
}

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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

int main()
{
    int a, b;
    cin >> a >> b;

    cout << ((a == b) ? a + b : 2 * max(a, b) - 1) << '\n';
    return 0;
}


Measured memory_bytes: 3640
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
using namespace std;
long long  mod = 1000000007;
int main()
{
	long long A, B;
	cin >> A >> B;
	if ((A - B) % 2 != 0) {
		cout << "IMPOSSIBLE";
	}
	else {
		cout << (A + B) / 2;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <array>
#include <cstdint>
#include <climits>
#include <functional>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <string>
#include <time.h>
#include <utility>
#include <vector>

using int32 = std::int_fast32_t;
using int64 = std::int_fast64_t;
using uint32 = std::uint_fast32_t;
using uint64 = std::uint_fast64_t;



class UnionFindTree {
	using int32 = std::int_fast32_t;
	using uint32 = std::uint_fast32_t;
	std::vector<int32> tree;

public:
	UnionFindTree(uint32 size) : tree(size, -1) {}
	uint32 find(const uint32 x) {
		if (tree[x] < 0)
			return x;
		return tree[x] = (int32)find((uint32)tree[x]);
	}
	bool unite(uint32 x, uint32 y) {
		x = find(x);
		y = find(y);
		if (x == y)
			return false;
		if (tree[x] > tree[y])
			std::swap(x, y);
		tree[x] += tree[y];
		tree[y] = (int32)x;
		return true;
	}
	uint32 size(const uint32 x) { return (uint32)(-tree[find(x)]); }
	bool same(const uint32 x, const uint32 y) { return find(x) == find(y); }
};
namespace n91 {
	template <typename T>
	auto scan(T &d) ->
		typename std::enable_if<std::is_same<T, std::string>::value>::type {
		d = std::string();
		int c = 0;
		while (c < 'a' || 'z' < c)
			c = fgetc(stdin);
		while ('a' <= c && c <= 'z') {
			d.push_back(c);
			c = fgetc(stdin);
		}
	}
	template <typename T>
	auto scan(T &d) ->
		typename std::enable_if<std::is_same<T, double>::value>::type {
		scanf("%lf", &d);
	}
	template <typename T>
	auto scan(T &d) ->
		typename std::enable_if<std::is_signed<T>::value ==
		std::is_same<T, std::string>::value>::type {
		d = 0;
		int c = 0;
		while (c < '0' || '9' < c)
			c = fgetc(stdin);
		while ('0' <= c && c <= '9') {
			d = d * 10 + c - '0';
			c = fgetc(stdin);
		}
	}
	template <typename T>
	auto scan(T &d) ->
		typename std::enable_if<std::is_signed<T>::value !=
		std::is_same<T, double>::value>::type {
		d = 0;
		int c = 0;
		bool f = 0;
		while (c < '0' || '9' < c) {
			if (c == '-')
				f = 1;
			c = fgetc(stdin);
		}
		while ('0' <= c && c <= '9') {
			d = d * 10 + c - '0';
			c = fgetc(stdin);
		}
		if (f)
			d = -d;
	}
} // namespace n91
int main(void) {
	uint32 n, m;
	n91::scan(n);n91::scan(m);
#define SIZ 100001
	std::priority_queue<uint32, std::vector<uint32>, std::greater<uint32>> Q[SIZ], P;
	std::vector<uint32> r(n, 0), c(n);
	UnionFindTree U(n);
	for (uint32 i = 0;i < n;++i) {
		n91::scan(c[i]);
	}
	uint32 x, y;
	for (uint32 i = 0;i < m;++i) {
		n91::scan(x);n91::scan(y);
		U.unite(x, y);
	}
	for (uint32 i = 0;i < n;++i) {
		Q[U.find(i)].push(c[i]);
	}
	uint64 cost = 0, node = 0;
	for (uint32 i = 0;i < n;++i) {
		if (r[U.find(i)]) continue;
		r[U.find(i)] = 1;
		++node;
		cost += Q[U.find(i)].top();
		Q[U.find(i)].pop();
		while (!Q[U.find(i)].empty()) {
			P.push(Q[U.find(i)].top());
			Q[U.find(i)].pop();
		}
	}
	if (node == 1) {
		std::cout << "0\n";
		return 0;
	}
	if (P.size() + 2 < node) {
		std::cout << "Impossible\n";
		return 0;
	}
	for (uint32 i = 2;i < node;++i) {
		cost += P.top();
		P.pop();
	}
	std::cout << cost << "\n";
	return 0;
}

Measured memory_bytes: 8832
H, W = map(int, input().split())

S = H * W
ans = 0
if H * W % 3 != 0:
    ans = 10 ** 11
    for a, b in zip((H, W), (W, H)):
        for i in range(1, a):
            S1 = i * b
            S2 = (a - i) * (b // 2)
            S3 = S - S1 - S2
            S4 = ((a - i) // 2) * b
            S5 = S - S1 - S4

            ans = min(ans,
                      max(S1, S2, S3) - min(S1, S2, S3),
                      max(S1, S4, S5) - min(S1, S4, S5))

print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>

using namespace std;

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


int main(){
    int a, b, c;    cin >> a >> b >> c;
    int x, y;   cin >> x >> y;

    int plan_a = x * a + y * b;
    int plan_b = min(x, y) * 2 * c + max((x - y)*a, (y - x)*b);
    int plan_c = max(x, y) * 2 * c;

    cout << min(plan_a, min(plan_b, plan_c)) << endl;


    return 0;

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
void func(int i,int x,vector<int> &num,string s,vector<string> &answer){
  if(i == num.size()){
    if(x == 0){
      answer.push_back(s);
      return;
    }
    else{
      return;
    }
  }
  
  for(int k=0;k<2;k++){
    if(k == 0){
      s.at(2*i-2) = '+';
      s.at(2*i-1) = '0' + num.at(i);
      func(i+1,x-(num.at(i)),num,s,answer);
    }
    else{
      s.at(2*i-2) = '-';
      s.at(2*i-1) = '0' + num.at(i);
      func(i+1,x+(num.at(i)),num,s,answer);
    }
  }
}

int main(){
  vector<int> num(4);
  int input;
  cin >> input;
  for(int i=0;i<4;i++){
    num.at(3-i) = input % 10;
    input /= 10;
  }
  int x = 7 - num.at(0);
  string s = "aaaaaa";
  vector<string> answer;
  func(1,x,num,s,answer);
  cout << num.at(0) << answer.at(0) << "=7" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

ll lcm(ll a, ll b) {
	return a / gcd(a, b) *b;
}

struct edge {
	ll ind;
	ll to;
	ll d;
};


///////////////////////////





int main() {

	ll N;
	cin >> N;
	vector<ll> A(N + 1);
	repn(i, N) cin >> A[i];

	sort(++A.begin(), A.end());

	ll d = 0;
	repn(i, N - 1) { if (A[i] == A[i + 1]) { d++; } }

	cout << N-2*((d + 1) / 2);

	system("PAUSE");
}


Measured memory_bytes: 1272
i = 1
while i <= 4:
    s_i,n_i = map(int,input().split())
    if s_i == 1:
        x = n_i * 6000
    elif s_i == 2:
        x = n_i * 4000
    elif s_i == 3:
        x = n_i * 3000
    else:
        x = n_i * 2000
    print(x)
    i += 1




Measured memory_bytes: 5596
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000000;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

///////////////////////////





int main() {

	ll N;
	cin >> N;

	ll A[MAX];
	repn(i, N) { cin >> A[i]; }

	sort(A + 1, A + N + 1);

	ll ans = 0;

	repn(i, N / 2) {
		ans += abs(A[2 * i - 1] + A[2 * i]);
	}

	if (N % 2 == 1) { ans += A[N]; }

	cout << ans;

	system("PAUSE");
}

Measured memory_bytes: 3200
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <functional>
#include <vector>
#include <queue>
#include <map>
#include <stack>
#include <string>

using namespace std;

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

#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 FORR(i, m, n) for (int i = m; i >= n; i--)

ll const INF = 1000000000000000000;
int const I_MAX = 2147483647;
ll const MOD = 1e9 + 7;
int const POW_MAX = 1e5;
int const N_MAX = 1e5;

// nCr
ll po[POW_MAX + 2];
ll mod_pow(ll x, ll n) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * x % MOD;
    x = x * x % MOD;
    n >>= 1;
  }
  return res;
}
ll mod_inv (ll x) {
  return mod_pow(x, MOD - 2) % MOD;
}
ll comb(int n, int r) {
  if (!po[n]) {
    po[0] = 1;
    FOR(i, 1, n + 1) po[i] = po[i - 1] * i % MOD;
  }
  return (((po[n] * mod_inv(po[r])) % MOD) * mod_inv(po[n - r])) % MOD;
}
// greatest common divisor
ll gcd(ll a, ll b) {
  while (a % b != 0) {
    ll tmp = a;
    a = b;
    b = tmp % b;
  }
  return b;
}

int N, M;
int us[N_MAX + 1], vs[N_MAX + 1];
int S, T;

map<int, vector<int>> G;
map<int, int> steps;
map<int, int> f_steps;
map<int, int> s_steps;

int main() {
  scanf("%d %d", &N, &M);
  rep(i, M) scanf("%d %d", &us[i], &vs[i]);
  scanf("%d %d", &S, &T);

  rep(i, M) {
    int u = us[i];
    int v = vs[i];
    G[u].push_back(v);
  }

  queue<int> Q;
  Q.push(S);
  while (!Q.empty()) {
    int q = Q.front();
    Q.pop();
    int current = steps[q];
    int n_step = current + 1;

    for (int a : G[q]) {
      if (n_step < f_steps[a] || f_steps[a] == 0) {
        f_steps[a] = n_step;
      } else {
        continue;
      }
      for (int b : G[a]) {
        if (n_step < s_steps[b] || s_steps[b] == 0) {
          s_steps[b] = n_step;
        } else {
          continue;
        }
        for (int c : G[b]) {
          if (n_step < steps[c] || steps[c] == 0) {
            steps[c] = n_step;
            Q.push(c);
          }
        }
      }
    }
  }
  int t = steps[T];
  if (t == 0) {
    printf("%d\n", -1);
  } else {
    printf("%d\n", t);
  }
}


Measured memory_bytes: 25984
import numpy as np

N=int(input())
s_arr=np.zeros(N, dtype=np.int8)
for i in range(N):
    s_arr[i]=int(input())

total=np.sum(s_arr)
if total%10!=0:
    print(total)
else:
    msk=(s_arr%10!=0)
    if np.sum(msk)==0:
        print(0)
    else:
        print(total-np.min(s_arr[msk]))

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

using namespace std;

#define lp(i,n) for(int i = 0; i <n;i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define MP make_pair
#define SZ(v) ((int)((v).size()))
typedef long long ll;

const ll MOD = 1e9 + 7;
const int OO = (int)1e6;
const int N = (int)1e7;

void init(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}

int main() {
    priority_queue<ll>q;
    int n,m;
    scanf("%d%d",&n,&m);
    ll x;
    for(int i=0;i<n;i++){
        scanf("%lld",&x);
        q.push(x);
    }
    while(m&&!q.empty()){
        ll temp =q.top();
        temp/=2;
        q.pop();
        q.push(temp);
        m--;
    }
    ll sum =0;
    while(!q.empty()){
        sum+=q.top();
        q.pop();
    }
    printf("%lld",sum);
    return 0;
}


Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
typedef long long int LL;
typedef pair<int, int> par;
typedef pair<par, int> prr;
#define x first
#define y second
int main(){
    LL n;
    scanf("%lld", &n);
    LL tmp = 0, add = 0, now = 0;
    while (n >= 10) {
        now += n % 10;
        add += 9;
        n /= 10;
    }
    now += n;
    add += n - 1;
    printf("%lld\n", max(add, now));
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int A, B, Q;
ll s[100002], t[100002];

int low_s(ll x){
	int i = -1, j = A+1;
	while(j-i > 1){
		int m = (i+j)/2;
		if(s[m] >= x) j = m;
		else i = m;
	}
	return j;
}

int low_t(ll x){
	int i = -1, j = B+1;
	while(j-i > 1){
		int m = (i+j)/2;
		if(t[m] >= x) j = m;
		else i = m;
	}
	return j;
}

int main(){
	scanf("%d%d%d", &A, &B, &Q);
	s[0] = -1e18, s[A+1] = 1e18;
	t[0] = s[0], t[B+1] = s[A+1];
	for(int i=1; i<A+1; i++) scanf("%lld", s+i); 
	for(int i=1; i<B+1; i++) scanf("%lld", t+i); 
	sort(s, s+A+2);
	sort(t, t+B+2);
	for(int i=0; i<Q; i++){
		ll x;
		scanf("%lld", &x);
		int sR = low_s(x);
		int tR = low_t(x);
		ll ans = 1e18;
		for(int j=sR-1; j<sR+1; j++){
			for(int k=tR-1; k<tR+1; k++){
				ans = min(ans, min(abs(x-s[j]), abs(x-t[k])) + abs(s[j]-t[k]));
			}
		}
		printf("%lld\n", ans);
	}
	return 0;
}


Measured memory_bytes: 2816
N = int(input())
ans = 90909
if 0 <= N <= 9:
    ans = N
elif 10 <= N <= 99:
    ans = 9
elif 100 <= N <= 999:
    ans = 9 + N - 100+1
elif 1000 <= N <= 9999:
    ans = 909
elif 10000 <= N <= 99999:
    ans = 909 + N - 10000 + 1

print(ans)


Measured memory_bytes: 2940
import Control.Applicative
import qualified Data.Map as M
import Data.Char
main = do
    lowerStr <- toLowerStr <$> getContents
    let regiMap = registerChar lowerStr
    mapM_ (\x -> putStrLn $ formatMap x regiMap) (M.keys regiMap)

initMap :: M.Map Char Integer
initMap = let a = map (\x -> (x, 0)) ['a'..'z']
          in M.fromList a

toLowerStr :: String -> String
toLowerStr = map (\x -> toLower x)

registerChar :: String -> M.Map Char Integer
registerChar = foldl (\acc x -> M.adjust (+1) x acc) initMap

formatMap :: Char -> M.Map Char Integer -> String
formatMap a mapp = [a] ++ " : " ++ show ((M.!) mapp a)

Measured memory_bytes: 4212
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    ll n; cin>>n;
    string x; cin>>x;
    vector<ll> f(200001,-1);
    f[0]=0;
    for(ll i=1;i<=200000;i++){
        ll cnt=0;
        rep(j,20){
            if(i&(1<<j)) cnt++;
        }
        f[i]=f[i%cnt]+1;
    }
    ll cnt=0;
    rep(i,n){
        if(x[i]=='1') cnt++;
    }
    vector<ll> mmod(n,0),pmod(n,0);
    ll c=1;
    if(cnt>1){
        rep(i,n){
            mmod[i]=c;
            c=c*2%(cnt-1);
        }
    }
    c=1;
    rep(i,n){
        pmod[i]=c;
        c=c*2%(cnt+1);
    }
    ll mnum=0,pnum=0;
    rep(i,n){
        if(x[n-1-i]=='1'){
            mnum+=mmod[i];
            pnum+=pmod[i];
        }
    }
    rep(i,n){
        ll d,ans;
        if(x[i]=='1'){
            if(cnt==1) ans=0;
            else{
                d=(mnum-mmod[n-1-i]+(cnt-1))%(cnt-1);
                ans=f[d]+1;
            }

        }
        else{
            d=(pnum+pmod[n-1-i])%(cnt+1);
            ans=f[d]+1;
        }
        cout<<ans<<endl;
    }
}

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

#define M 1000000007
#define MM 998244353 
#define ll long long 
#define pb push_back
#define mem0(a) memset(a,0,sizeof(a))
#define mem1(a) memset(a,-1,sizeof(a))
#define memf(a) memset(a,false,sizeof(a))
#define all(v) v.begin(),v.end()
#define sz(a) (ll)a.size()
#define F first
#define S second
#define PI 3.1415926536
#define INF 2e18
#define endl "\n"
#define llevel 20
ll power(ll b,ll e,ll m)
{
	if(e==0) return 1;
	if(e&1) return b*power(b*b%m,e/2,m)%m;
	return power(b*b%m,e/2,m);
}
ll power( ll b, ll e)
{
	if(e==0) return 1;
	if(e&1) return b*power(b*b,e/2);
	return power(b*b,e/2);
}

int _runtimeTerror_()
{
	int h,w,k,i,j,var,xx;
	cin>>h>>w>>k;
	char a[h+2][w+2];
	int ans=1e9;
	for(i=0;i<h;++i)
	{
		for(j=0;j<w;++j)
			cin>>a[i][j];
	}
	int sub=(1<<(h-1));
	for(i=0;i<sub;++i)
	{
		int call=0;
		vector<int> v;
		v.pb(0);
		for(j=0;j<h-1;++j)
		{
			if(i&(1<<j))
				v.pb(j+1);
		}
		v.pb(h);
		int ss=sz(v)-1;
		vector<int> val(ss,0);
		for(xx=0;xx<w;++xx)
		{
			vector<int> temp(ss,0);
			for(var=0;var<ss;++var)
			{
				for(j=v[var]+1;j<=v[var+1];++j)
				{
					temp[var]+=(a[j-1][xx]=='1');
				}
				val[var]+=temp[var];
			}
			for(int lll=0;lll<ss;++lll)
			{
				if(val[lll]>k)
				{
					if(xx==0)call=1e9;
					else
					{
						val=temp;++call;
					}
					break;
				}
			}
			for(int lll=0;lll<ss;++lll)
			{
				if(val[lll]>k)
				{
					call=1e9;
					break;
				}
			}
			if(call==1e9)
				break;
		}
		ans=min(ans,call+__builtin_popcount(i));
	}
	cout<<ans<<endl;
	return 0;
}

int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	#ifdef runSieve
		sieve();
	#endif
	#ifdef NCR
		initialize();
	#endif
	int TESTS=1;
	//cin>>TESTS;
	while(TESTS--)
		_runtimeTerror_();
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
  int x, y;

  while(scanf("%d %d", &x, &y))
    {
      if(!x && !y)
	{
	  break;
	}
      x < y ? printf("%d %d\n", x, y) : printf("%d %d\n", y, x);
    }

  return 0;
}

Measured memory_bytes: 0
use std::cmp::*;
use std::io::*;
use std::num::*;
use std::str::*;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let s = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok().unwrap()
}

fn string() -> String {
    read()
}

fn int() -> i64 {
    read()
}

fn char() -> char {
    read::<String>().pop().unwrap()
}

fn vecchar() -> Vec<char> {
    string().chars().collect()
}

fn vecint(n: i64) -> Vec<i64> {
    let mut vec = Vec::new();
    for i in 0..n {
        vec.push(int())
    }
    vec
}

fn main() {
    let (n, k, s) = (int() as usize, int() as usize, vecchar());
    let mut now = 0;
    for i in 1..n {
        if s[i] == s[i - 1] {
            now += 1
        }
    }
    println!("{}", min(n - 1, now + 2 * k))
}


Measured memory_bytes: 4352
n,k = map(int,input().split())
r,s,p = map(int,input().split())
t = list(input())

d = {'r':p,'s':r,'p':s}
c = 0

for i in range(k):
    c += d[t[i]]
for i in range(k,n):
    if(t[i] == t[i-k]):
        t[i] = 'x'
    else:
        c += d[t[i]]
print(c)

Measured memory_bytes: 4084
#include <cstdio> 
#include <cstring>
#include <algorithm>
using namespace std;
#define LL long long
int n, num[100005], opt[100005];
LL sum[100005], now[100005], ans;
int main()
{
	char ch[2];
	scanf("%d%d", &n, &num[1]); opt[1] = 1;
	now[1] = sum[1] = num[1];
	for(int i = 2; i <= n; i++)
	{
		scanf("%s%d", ch, &num[i]); opt[i] = (ch[0] == '+') ? 1 : -1;
		now[i] = now[i-1] + opt[i] * num[i];
		sum[i] = sum[i-1] + num[i];
	}
	ans = now[n];
	int last = -1;
	for(int i = 1; i <= n; i++) if(opt[i] == -1)
	{
		if(last != -1)
			ans = max(ans, now[last-1] - (sum[i-1] - sum[last-1]) + (sum[n] - sum[i-1]));
		last = i;
	}
	printf("%lld\n", ans);
}
 



Measured memory_bytes: 2560
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import permutations,combinations
from collections import defaultdict,Counter
from pprint import pprint

def myinput():
    return map(int,input().split())

def mylistinput(n):
    return [ list(myinput()) for _ in range(n) ]

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col):
    data.sort(key=lambda x:x[col],reverse=False)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

class Kruskal_UnionFind():
    # 無向グラフであるという前提に注意
    def __init__(self, N):
        self.edges = []
        self.rank = [0] * N
        self.par = [i for i in range(N)]
        self.counter = [1] * N

    def add(self, u, v, d):
        """
        u = from, v = to, d = cost
        """
        self.edges.append([u, v, d])

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x != y:
            z = self.counter[x] + self.counter[y]
            self.counter[x], self.counter[y] = z, z
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def size(self, x):
        x = self.find(x)
        return self.counter[x]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def Kruskal(self):
        """
        return: 最小全域木のコストの和
        """
        edges = sorted(self.edges, key=lambda x: x[2])  # costでself.edgesをソートする
        res = 0
        for e in edges:
            if not self.same(e[0], e[1]):
                self.unite(e[0], e[1])
                res += e[2]
        return res

n = int(input())
xy = mylistinput(n)

G = Kruskal_UnionFind(n)

xy0 = []
for i in range(n):
    x = xy[i][0]
    y = xy[i][1]
    xy0.append([i,x,y])

xy1 = mysort(xy0,1)
for i in range(n-1):
    No1 = xy1[i][0]
    a = xy1[i][1]
    b = xy1[i][2]
    No2 = xy1[i+1][0]
    c = xy1[i+1][1]
    d = xy1[i+1][2]
    cost = min(abs(c-a),abs(d-b))
    G.add(No1,No2,cost)

xy2 = mysort(xy0,2)
for i in range(n-1):
    No1 = xy2[i][0]
    a = xy2[i][1]
    b = xy2[i][2]
    No2 = xy2[i+1][0]
    c = xy2[i+1][1]
    d = xy2[i+1][2]
    cost = min(abs(c-a),abs(d-b))
    G.add(No1,No2,cost)

ans = G.Kruskal()
print(ans)

Measured memory_bytes: 125404
def d_init(n):
  c = 0
  A = D.items()[:]
  for i, e in A:
    c += 1
    for j, f in A[c:]:
      a = abs(e-f)
      D[(i, j)] = a
      D[(j, i)] = a
  return

def solve(p, v, w):
  if v == (1<<n)-1: return 0, N[p]
  a, b = dp[p][v]
  if a >= 0: return a, b

  T = 1e10
  for i in range(n):
    i1 = 1<<i
    if (v & i1) == 0:
      a, b = solve(i, v|i1, w + W[i])
      a += D[(i, p)] * w
      if T > a:
        T = a
        R = b
  R = N[p] + R
  dp[p][v] = [T, R]
  return T, R

N = {}
D = {}
W = {}
n = input()
dp = [[[-1, []] for _ in [0]*(1<<n)] for _ in [0]*n]
for i in range(n):
  a, b, c = map(int, raw_input().split())
  N[i] = [a]
  D[i] = b/2000.0
  W[i] = c*20
d_init(n)

minT = 1e10
R = []
for i, e in W.items():
  a, b = solve(i, 1<<i, e+70.0)
  if minT > a:
    minT = a
    R = b

for e in R:
  print str(e),

Measured memory_bytes: 118884
#include<stdio.h>
int main()
{
    int n,k,x,y,bank;
    scanf("%d%d%d%d",&n,&k,&x,&y);
    if(n-k<=0)
        bank=n*x;
    else
        bank=k*x+(n-k)*y;
    printf("%d",bank);
    return 0;
        
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <string.h>
#include <numeric>
using namespace std;

#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(i,v) for(auto &(i):(v))
#define eachr(i,v) for(auto &(i)=(v).rbegin();(i)!=(v).rend();(i)++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())
#define endl "\n"

//typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a/gcd(a,b)*b;}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;



int n, a, g;

signed main() {
	cin >> n;
	cin >> g;
	rep(i,n-1) {
		cin >> a;
		g = gcd(a,g);
	}
	cout << g << endl;
}

Measured memory_bytes: 256
from sys import stdin
h,w = [int(x) for x in stdin.readline().rstrip().split()]
data = [stdin.readline().rstrip() for _ in range(h)]
row=[False]*h
col=[False]*w
for i,r in enumerate(data):
    for j,c in enumerate(r):
        if c=='#':
            row[i]=True
            col[j]=True
for i in range(h):
    if row[i]:
        for j in range(w):
            if col[j]:
                print(data[i][j],end='')
        print()

Measured memory_bytes: 4468
S = str(input())
T = str(input())

Ans=1000
for i in range(0, len(S)):
    Tmp=0
    if i + len(T) <= len(S):
      for j in range(0, len(T)):
          if S[i+j] != T[j]:
              Tmp += 1
      Ans = min(Ans, Tmp)
print(Ans)

Measured memory_bytes: 9120
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>

using namespace std;

int main() {
	int n, k;
	int m, i, j, start = -1, time, min_time = -1;
	vector<int>sum_x;

	cin >> n >> k;

	for (i = 0; i < n; i++) {
		cin >> m;
		if (m >= 0 && start == -1)
			start = i;
		sum_x.push_back(abs(m));
	}
	if (start == -1)
		start = n;
	if (start - k >= 0) {
		min_time = sum_x[start - k];
	}
	for (i = start - k + 1; i < start; i++) {
		if (i < 0)
			i = 0;
		if (k + i - 1 > n - 1)
			break;
		time = sum_x[i] * 2 + sum_x[k + i - 1];
		if (min_time > time || min_time == -1)
			min_time = time;
	}
	for (i = start + k - 2; i > start - 1; i--) {
		if (i > n - 1)
			i = n - 1;
		if (i - k + 1 < 0)
			break;
		time = sum_x[i] * 2 + sum_x[i - k + 1];
		if (min_time > time || min_time == -1)
			min_time = time;
	}
	if ((start + k - 1 )< n) {
		if (min_time > sum_x[start + k - 1]) {
			min_time = sum_x[start + k - 1];
		}
	}

	if (min_time == -1) {
		min_time = 0;
	}

	cout << min_time;

	return 0;
}

Measured memory_bytes: 892
import sys
import numpy as np

# N お札の枚数 Y お年玉の金額
n, y = map(int, input().split())

ok = False
for i in range(n+1):
    for j in range(n-i+1):
        k = n - i - j
        money = (10000 * i) + (5000 * j) + (1000 * k)
        if (money == y) and (i + j + k == n):
            ok = True
            break
    if  ok:
        break

if ok:
    print(i, j, k)
else:
    print("-1 -1 -1")   

Measured memory_bytes: 14460
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int main(){
    string s,t;
    R(s,t);
    int AA=0;
    REP(i,3)AA+=(s[i]==t[i]);
    W(AA);
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
int main()
{
long long n, i, factorial=1;

scanf("%lld",&n);

if(n<=20){
    for(i=1;i<=n;i++){
    factorial=factorial*i;
    }
    printf("%lld\n",factorial);
}
return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
using V = vector<ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;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--)
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define INF 1000000000

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
	ll x; // typedef long long ll;
	mint(ll x = 0) :x((x% mod + mod) % mod) {}
	mint operator-() const { return mint(-x); }
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint a) const {
		mint res(*this);
		return res *= a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime mod
	mint inv() const {
		return pow(mod - 2);
	}
	mint& operator/=(const mint a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint a) const {
		mint res(*this);
		return res /= a;
	}
};

void solve_abc_d() {
	ll n, k;
	mint ans = 0;

	cin >> n >> k;

	mint v1, v2;
	rep2(i, k, n+2) {
		v1 = (i - 1) * (i) / 2;

		v2 = (n) * (n + 1) / 2;
		v2 -= (n - i) * (n + 1 - i) / 2;
		ans += v2 - v1 + 1;
	}

	cout << ans.x << "\n";
}

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

	solve_abc_d();

	return 0;
}


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

int main()
{
	int N, Y, x, y, z;
	cin >> N >> Y;
	
	for(x=0; x<=Y/10000; x++)
	   for(y=0; y<=Y/5000; y++)
       {
           z = N - x - y;
           if(z>=0 && x*10000+y*5000+z*1000==Y)
           {
               cout << x << " " << y << " " << z;
               return 0;
           }
       }
	
	cout << "-1 -1 -1";
	return 0;
}

Measured memory_bytes: 256
N,M = map(int, input().split())
L = [0]*M
R = [0]*M
D = [0]*M
for i in range(M):
    L[i], R[i], D[i] = map(int, input().split())
    
G = [[] for _ in range(N)]
for i in range(M):
    G[L[i]-1].append([R[i]-1, D[i]])
    G[R[i]-1].append([L[i]-1, -D[i]])
    
ans = "Yes"
visited = ["?"]*N
for i in range(N):
    if visited[i] == "?":
        q = [[i, 0]]
        visited[i] = 0
        while len(q) > 0:
            temp = q.pop(-1)
            pos = temp[0]
            d = temp[1]
            for j in range(len(G[pos])):
                if visited[G[pos][j][0]] == "?":
                    q.append([G[pos][j][0], d+G[pos][j][1]])
                    visited[G[pos][j][0]] = d+G[pos][j][1]
                elif visited[G[pos][j][0]] != d+G[pos][j][1]:
                    ans = "No"
                    break

print(ans)

Measured memory_bytes: 104424
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int dp[200010][2];

int main(void)
{
    string S;
    cin >> S;
    int n = S.size();

    int ans = 0;
    string prev = "", cur = "";

    Rep(i, 0, n){
        cur += S[i];
        if(prev != cur){
            ans++;
            prev = cur;
            cur = "";
        }
    }

    pr(ans);
}

Measured memory_bytes: 640
L = "1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51"
L = L.split(", ")
k = int(input())
print(L[k-1])

Measured memory_bytes: 9156
#include <iostream>

using namespace std;

long long lpow(long long a, long long b) {
    long long res = 1;
    for(long long i = 0; i < b; i++) {
        res *= a;
    }
    return res;
}

int main() {
    int h, w, k;
    cin >> h >> w >> k;

    char note[h][w];
    int total_black = 0;
    for(int y=0; y < h; y++) {
        for(int x = 0; x < w; x++) {
            cin >> note[y][x];
            if(note[y][x] == '#') total_black++;
        }
    }

    int ymax = lpow(2, h);
    int xmax = lpow(2, w);
    int black;
    int count = 0;
    for(int y_val = 0; y_val < ymax; y_val++) {
        for(int x_val = 0; x_val < xmax; x_val++) {
            black = total_black;
            for(int y = 0; y < h; y++) {
                for(int x = 0; x < w; x++) {
                    if(((y_val & (1 << y)) != 0) && note[y][x] == '#') {
                        black--;
                    }else if(((x_val & (1 << x)) != 0) && note[y][x] == '#') {
                        black--;
                    }
                }
            }
            if(black == k) {
                count++;
            }
        }
    }

    cout << count << endl;
}

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

#define for_(i,a,b) for(int i=(a);i<(b);++i)

int main() {
	int N, M;
	
	while (cin >> N >> M, N) {
		vector< int > P;
		for_(i,0,N) {
			int x;
			cin >> x;
			if (x <= M) P.push_back(x);
		}
		
		P.push_back(0);
		for_(i,0,N) for_(j,0,N) if (P[i] + P[j] <= M) P.push_back(P[i] + P[j]);
		sort(P.begin(), P.end());
		
		int m = P.size(), ans = 0;
		for_(i,0,m) ans = max(ans, *(upper_bound(P.begin(), P.end(), M - P[i]) - 1) + P[i]);
		cout << ans << endl;
	}
}

Measured memory_bytes: 10732
while True:
    m,f,r = map(int, input().split())
    if m==f==r==-1:
        break
    if m == -1 or f == -1:
        print("F")
    elif m+f >= 80:
        print("A")
    elif m+f >= 65:
        print("B")
    elif m+f >= 50 or r >= 50:
        print("C")
    elif m+f >= 30:
        print("D")
    else:
        print("F")


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

int main() {
  ll A, B;
  int K;
  cin >> A >> B >> K;
  set<ll> N;
  for (int i = 0; i < K; i++) {
    if (A + i > B) {
      break;
    }
    else {
      N.insert(A+i);
    }
  }
  for (int i = 0; i < K; i++) {
    if (B - i < A) {
      break;
    }
    else {
      N.insert(B-i);
    }
  }
  for (auto value : N) {
    cout << value << endl;
  }
}

 

Measured memory_bytes: 256
num, poi, ans = [int(x) for x in input().split()]

list01 = [poi for x in range(num)]
list02 = [0 for x in range(num)]

for i in range(ans):
  j = int(input())
  list02[j-1] += 1

for i in range(num):
  list02[i] = list02[i] + list01[i] - ans

for k in list02:
  if k <= 0:
    print("No")
  else:
    print("Yes")

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

int GCD(int m,int n){
    int big,small;
    int p=-1;
    big=max(m,n);
    small=min(m,n);

    while(1){
        p=big%small;
        if(p==0)break;
        big=small;
        small=p;
    }
    
    return small;
}


int main(){
    int ans=0;
    int x,y;
    cin >> x>>y;

    //cout <<fixed<<setprecision(16)<< << endl;
    cout << GCD(x,y) << endl;

    //if(flag==1)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}



Measured memory_bytes: 3096
import heapq

def solve():
    N = int(input())
    que = []
    for i in range(N):
        a, b = map(int, input().split())
        heapq.heappush(que, (b, a))
    now = 0
    while que:
        b, a = heapq.heappop(que)
        now += a
        if now > b:
            return False
    return True

if solve():
    print("Yes")
else:
    print("No")


Measured memory_bytes: 34392
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;
ll MOD=1000000007;
 
int main() {
    ll n;
    cin >> n;
    ll ans=0;
    for (ll i=1;i<=n;i++){
        if (i%3!=0 && i%5!=0) ans+=i;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3636
/**
 * Sergey Kopeliovich (burunduk30@gmail.com)
 */

#include <bits/stdc++.h>

using namespace std;

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

int main() {
	int n, m, k;
	cin >> n >> m >> k;
	forn(i, n + 1)
		forn(j, m + 1)
			if (i * j + (n - i) * (m - j) == k) {
				puts("Yes");
				return 0;
			}
	puts("No");
}

Measured memory_bytes: 256