akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair <ll, ll > pll;

bool comp(const pll &a, const pll &b) {
	return a.first < b.first;
}
std::vector<int> enum_div(int n)//nの約数を列挙
{
	std::vector<int> ret;
	for (int i = 1; i*i <= n; ++i)
	{
		if (n%i == 0)
		{
			ret.push_back(i);
			if (i != 1 && i*i != n)
			{
				ret.push_back(n / i);
			}
		}
	}
	return ret;
}


template<int N>
int factorial() {
	return factorial<N - 1>() * N;
}

template<>  /// 特殊化：factorial<N=”1”>だったら，値を返す
int factorial<1>() {
	return 1;
}
int main()
{
	priority_queue<int> q;
	string s = {};
	string s1 = {};
	ll h = 0, w = 0, k = 0, a = 0, b = 0, c = 0, d = 0, e = 0, f = 0, g = 0, ans = 0;
	ll x[300005] = {};
	ll y[300005] = {};
	ll y2[302][302] = {};
	cin >> a;
	vector<pair<ll, ll> > hoges(a);
	for (int i = 0; i < a; i++)
	{
		cin >> b;
		cin >> c;
		//x[i] = b - c;
		//y[i] = b + c;
		hoges[i] = make_pair(b - c, b + c);
	}
	//for (int i = 1; i <= a; i++)
	//{
	//	cin >> h;
	//	hoges[i - 1] = make_pair(h, i);
	//}
	sort(hoges.begin(), hoges.end(), comp);


	//for (int i = 0; i < a; i++)
	//{
	//	cout << hoges[i].first << endl;
	//	cout << hoges[i].second << endl;
	//	cout << endl;
	//}

	b = 99999999999;
	c = 99999999999;

	for (int i = 0; i < a; i++)
	{
		if (b == 99999999999)
		{
			b = hoges[i].first;
			c = hoges[i].second;
			ans++;
		}
		else
		{
			if (hoges[i].first < c)
			{
				c = min(c, hoges[i].second);
			}
			else
			{
				b = hoges[i].first;
				c = hoges[i].second;
				ans++;
			}
		}

	}




	cout << ans << endl;



	//return 0;

	/*cout << c << endl;
	cout << b << endl;*/
	//cout << fixed << setprecision(10) <<tmp << endl;
	//cout<<factorial<10><<endl;
	return 0;
}
//2つの組の数をソートしたりするやつ
//vector<pair<ll, ll> > hoges(a);
//for (int i = 1; i <= a; i++)
//{
//	cin >> h;
//	hoges[i - 1] = make_pair(h, i);
//}
//sort(hoges.begin(), hoges.end(), comp);
//for (int i = 0; i < a; i++)
//{
//	cout << hoges[i].second << endl;
//}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> V;
#define rep(cnt,e) for(ll cnt=0;cnt<e;cnt++ )
typedef pair<ll,ll> P;
const ll mod = 1e9+7;
const ll INF = INT64_MAX;
typedef tuple<ll,ll,ll,ll> T;

ll i,j,k;

int main(){
    ll A,B,N;
    cin>>A>>B>>N;
    if(B<=N){
        ll ans=A*(B-1)/B;
        cout<<ans<<endl;
    }
    else{
        ll ans=A*N/B;
        cout<<ans<<endl;
    }

}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
vector<int>vec;
const int INF=1e9+5;
int main(){
    int n;
    cin>>n;
    int a;
    for(int i=0;i<n;i++){
        scanf("%d",&a);
        vec.push_back(a);
    }
    vector<int>dp(n,INF);
    dp[0]=0;
    for(int i=0;i<n;i++){
        for(int j:{i+1,i+2}){
            if(j<n){
                dp[j]=min(dp[j],dp[i]+abs(vec[i]-vec[j]));
            }
        }
    }
    cout<<dp[n-1]<<endl;
}


Measured memory_bytes: 1144
def main():
    n, m = map(int, input().split())
    num_list = []
    for _ in range(m):
        num_list.append(list(map(int,input().split())))

    for i in range(1000):
        if len(str(i)) != n:
            continue
        for j in range(m):
            tmp = int(str(i)[num_list[j][0]-1])
            if num_list[j][1] != tmp:
                break
        else:
            print(i)
            exit()

    print(-1)

if __name__ == '__main__':
    main()

Measured memory_bytes: 38480
#define _GLIBCXX_DEBUG
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<iostream>
#include<vector>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<string>
#include<bits/stdc++.h>
#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++)
#define ll long long 
#define all(v) v.begin(),v.end()
using namespace std;
int main(){
  int n; cin  >>n;
  map<string,int> MAP;
  vector<string> s(n);
  rep(i,n) {
  string a;
  cin >>a;
  s[i]=a;
  MAP[a]++;
  }
  int count=0;
  for(string S:s)  count =max(count,MAP[S]);
  for(auto it:MAP) {
      if (it.second == count) {
      cout << it.first << endl;
      }
  }
  //for(auto it=MAP.begin();it!=MAP.end();it++) if(MAP[it]==count) cout <<it<<endl;
  }

Measured memory_bytes: 28800
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] str = in.readLine().split(" ");
    int a = Integer.parseInt(str[0]);
    int b = Integer.parseInt(str[1]);
    
    if(a>=13)
      System.out.println(b);
    else if(a>=6)
      System.out.println(b/2);
    else
      System.out.println(0);
  }
}

Measured memory_bytes: 21076
#include <iostream>
#include <algorithm>
#include <cstdio>

using namespace std;

int main(){
    int n;
    scanf("%d",&n);
    int ans[55];
    for(int i = 0;i < n; i++){
        int k;
        scanf("%d",&k);
        ans[i] = k;
    }
    sort(ans,ans+n);
    double result = ans[0];
    for (int i = 1;i < n;i++){
        result =(double)(result+ans[i])/2;
    }
    printf("%lf",result);
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
 
typedef struct zahyou{
  double x;
  double y;
} P;

void kock(int, P, P);

P p1, p2;

int main(){
  int n;

  p1.x = 0;
  p1.y = 0;

  p2.x = 100;
  p2.y = 0;

  scanf("%d",&n);

  printf("%f %f\n",p1.x,p1.y);
 
  kock(n,p1,p2);

  printf("%f %f\n",p2.x,p2.y);

  return 0;
}
void kock(int n, P p1, P p2){
  P s,t,u;

  if (n == 0) return;
  
  s.x = (2 * p1.x + p2.x) / 3;
  s.y = (2 * p1.y + p2.y) / 3;
  t.x = (p1.x + 2 * p2.x) / 3;
  t.y = (p1.y + 2 * p2.y) / 3;  

  u.x = fabs((t.x - s.x) / 2 - (t.y - s.y) * (sqrt(3)/2) + s.x);
  u.y = fabs((t.x - s.x) * (sqrt(3)/2) + (t.y - s.y) / 2 + s.y);
  
  kock(n-1, p1, s);
  printf("%f %f\n",s.x,s.y);
  kock(n-1, s, u);
  printf("%f %f\n", u.x,u.y);
  kock(n-1, u, t);
  printf("%f %f\n", t.x, t.y);
  kock(n-1, t, p2);
}

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

int main(){
  int N,K;
  string str;
  cin >> N >> K >> str;

  if(str.substr(K - 1,1) == "A")str.replace(K-1,1,"a");
  if(str.substr(K - 1,1) == "B")str.replace(K-1,1,"b");
  if(str.substr(K - 1,1) == "C")str.replace(K-1,1,"c");

  cout << str << endl;
}


Measured memory_bytes: 256
# 初期入力
import numpy as np
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
ans =1
if 0 in A:
    ans =0
else:
    for i in A:
        ans *=i
        if 10**18 < ans :
            ans = -1
            break
print(ans)

Measured memory_bytes: 40324
import java.util.*;
import java.util.stream.*;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt(), m = in.nextInt();
        int[] arr = new int[n + 1];
        for (int i = 0; i < m; i++) {
            arr[in.nextInt() - 1]++;
            arr[in.nextInt()]--;
        }
        for (int i = 1; i < n + 1; i++) {
            arr[i] += arr[i - 1];
        }
        int ans = 0;
        for(int val : arr) {
            if(val == m) {
                ans++;
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 63016
#include <iostream>
#include <iomanip>
#include <cassert>

#include <cstring>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <limits>
#include <queue>
#include <unordered_map>
#include <list>
#include <set>
#include <numeric>
using namespace std;

using ll = long long;

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

template<typename T>
constexpr T int_pow(T b, uint64_t e)
{
	if (e == 0) return 1;
	if ((e & 0x1) == 0) return int_pow(b * b, e >> 1);
	else return b * int_pow(b * b, e >> 1);
}

int main()
{
	ll N, K;
	cin >> N >> K;

	ll ans = 0;
	if (K % 2 == 0)
	{
		ll K_num = N / K;
		ll Kper2_num = (N + K / 2) / K;

		ans = int_pow(K_num, 3) + int_pow(Kper2_num, 3);
	}
	else
	{
		ll K_num = N / K;

		ans = int_pow(K_num, 3);
	}

	cout << ans << endl;
}

Measured memory_bytes: 3604
N = input()

a = 0  # not carried
b = 0  # carried
t = int(N[-1])
a, b = a + t, a + (10 - t)

for i in range(len(N) - 2, -1, -1):
    t = int(N[i])
    a, b = min(a + t, b + (t + 1)), min(a + (10 - t), b + (10 - (t + 1)))
print(min(a, b + 1))


Measured memory_bytes: 5492
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = int(A); I < int(B); ++I)
#define FORR(I,A,B) for(ll I = int((B)-1); I >= int(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;


int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	ll N,K;
	string s;
	cin >> N >> K >> s;
	if(s[K-1]=='A'){
		s[K-1] = 'a';
	}else if(s[K-1]=='B'){
		s[K-1] = 'b';
	}else{
		s[K-1] = 'c';
	}
	cout << s << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 90;
int a[MAXN][MAXN];
int b[MAXN][MAXN];
int dp[MAXN][MAXN][26010];
int main(){
    int h,w;
    cin>>h>>w;
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            cin>>a[i][j];
        }
    }
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            cin>>b[i][j];
        }
    }
    for(int i=0;i<=h;i++){
        for(int j=0;j<=w;j++){
            for(int k=0;k<=26000;k++){
                dp[i][j][k] = false;
            }
        }
    }
    int mid = 13000;
    dp[1][1][mid+abs(b[1][1]-a[1][1])] = true;
    dp[1][1][mid-abs(b[1][1]-a[1][1])] = true;
    for(int i=1;i<=h;i++){
        for(int j=1;j<=w;j++){
            for(int k=0;k<=26000;k++){
                if(dp[i][j][k]){
                    int nxt = abs(b[i][j+1]-a[i][j+1]);
                    dp[i][j+1][k+nxt] = true;
                    dp[i][j+1][k-nxt] = true;
                    nxt = abs(b[i+1][j]-a[i+1][j]);
                    dp[i+1][j][k+nxt] = true;
                    dp[i+1][j][k-nxt] = true;
                }
            }
        }
    }
    int ans = -1;
    for(int i=0;i<=13000;i++){
        if(dp[h][w][i+mid]||dp[h][w][mid-i]){
            cout<<i<<endl;
            return 0;
        }
    }
    cout<<-1<<endl;
}


Measured memory_bytes: 749824
def helper(s):
    return '0' * (6 - len(s)) + s

def main():
    n, m = map(int, input().split())
    cities = []
    counts = [1] * (n + 1)
    for i in range(m):
        a, b = input().split()
        cities.append([a, int(b), i, ''])
    cities.sort(key = lambda j: j[1])
    for i in range(m):
        temp = cities[i]
        cities[i][3] = helper(temp[0]) + helper(str(counts[int(temp[0])]))
        counts[int(temp[0])] += 1
    cities.sort(key = lambda j: j[2])
    for i in cities:
        print(i[3])
    return 0
main()


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

int main(){
  int x,y;
  while(1){
    cin >> x >> y;
    if (x == 0 and y == 0){
      break;
    }
    if (x <= y){
      cout << x << " " << y << endl;
    }
    if (x > y){
      cout << y << " " << x << endl;
    }
  }
  return 0;
}



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

using namespace std;

const int max_n = 2022, mod = 1000000007;

struct edge {
    int u, v, d;

    bool operator < (const edge &e) const {
        return d < e.d;
    }
};

int mul(int x, int y) {
    return 1LL * x * y % mod;
}

int n, m, p[max_n], pw[max_n];
edge e[max_n];
bool take[max_n];
vector<int> g[max_n], d[max_n];
long long x;

int find_set(int v) {
    if (v == p[v]) {
        return v;
    }
    return p[v] = find_set(p[v]);
}

bool union_set(int v1, int v2) {
    v1 = find_set(v1);
    v2 = find_set(v2);
    if (v1 == v2) {
        return false;
    }
    p[v1] = v2;
    return true;
}

int get_max(int v, int fin, int mx, int p) {
    if (v == fin) {
        return mx;
    }
    int res = -1;
    for (int i = 0; i < g[v].size(); ++i) {
        const int to = g[v][i], c = d[v][i];
        if (to == p) {
            continue;
        }
        res = max(res, get_max(to, fin, max(mx, c), v));
    }
    return res;
}

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    pw[0] = 1;
    for (int i = 1; i < max_n; ++i) {
        pw[i] = mul(pw[i - 1], 2);
    }
    cin >> n >> m >> x;
    if (n <= 2) {
        cout << 0 << endl;
        return 0;
    }
    for (int i = 0; i < m; ++i) {
        cin >> e[i].u >> e[i].v >> e[i].d;
        --e[i].u;
        --e[i].v;
    }
    sort(e, e + m);
    for (int i = 0; i < n; ++i) {
        p[i] = i;
    }
    long long tot = 0;
    for (int i = 0; i < m; ++i) {
        take[i] = false;
        if (union_set(e[i].u, e[i].v)) {
            take[i] = true;
            tot += e[i].d;
            g[e[i].u].push_back(e[i].v);
            d[e[i].u].push_back(e[i].d);
            g[e[i].v].push_back(e[i].u);
            d[e[i].v].push_back(e[i].d);
        }
    }
    int ans = 0;
    if (tot == x) {
        ans += mul(pw[n - 1] + mod - 2, pw[m - n + 1]);
    }
    vector<int> all;
    for (int i = 0; i < m; ++i) {
        if (!take[i]) {
            int mx = get_max(e[i].u, e[i].v, -1, -1);
            all.push_back(e[i].d - mx);
        }
    }
    sort(all.begin(), all.end());
    for (int i = 0; i < all.size(); ++i) {
        if (tot + all[i] == x) {
            ans += pw[all.size() - i];
            ans %= mod;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define pn(s) cout << (#s) << " " << (s) << endl

const ll mod = 1e9 + 7;
const ll inf = 1e18;

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

    // input
    int N;
    cin >> N;

    vector<ll> A(N);
    FOR(i, 0, N){
        cin >> A.at(i);
    }

    bool canWin = false;
    FOR(i, 0, N){
        if(A[i] % 2 == 1){
            canWin = true;
        }
    }

    if(canWin){
        p("first");
    }else{
        p("second");
    }
    
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<ll,ll> P;
#define all(v) (v).begin(),v.end()
#define fi first
#define se second
set<string> c;
map<ll,ll> mp;
const ll inf=(1e18);
const ll mod=1000000007;
const ll mod2=998244353;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
int main(){
 int n,k;
cin>>n>>k;
string s;
cin>>s;
ll resL=0,resR=0;
for(int i=0;i<n-1;i++){
   if(s.at(i)=='L'&&s.at(i+1)=='L')resL++;
   if(s.at(i)=='R'&&s.at(i+1)=='R')resR++;
}
s.erase(unique(all(s)),s.end());
int i=0;
int times=k;
ll ansL=0,ansR=0;
while(times){
     if(i>=(int)s.size()-2)break;//型変更しないとs.size()の値は無限大に行く
    if(s.at(i)=='L'&&s.at(i+1)=='R'&&s.at(i+2)=='L'){ansL+=2;times--;}
    i++;
}
if(times!=0){
     if(times>=2&&s.size()>1&&s.at(0)=='R'&&s.at(s.size()-1)=='R')ansL+=2;
    else if(times>=1&&s.size()>1&&(s.at(0)=='R'||s.at(s.size()-1)=='R'))ansL+=1;
}
i=0;
while(k){
     if(i>=(int)s.size()-2)break;
    if(s.at(i)=='R'&&s.at(i+1)=='L'&&s.at(i+2)=='R'){ansR+=2;k--;}
    i++;
}
if(k!=0){
    if(k>=2&&s.size()>1&&s.at(0)=='L'&&s.at(s.size()-1)=='L')ansR+=2;
    else if(k>=1&&s.size()>1&&(s.at(0)=='L'||s.at(s.size()-1)=='L'))ansR+=1;
}
//cout<<ansL<<" "<<ansR<<endl;
cout<<max(ansL,ansR)+resL+resR<<endl;
}





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

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;

template <uint MD> struct ModInt {
    using M = ModInt;
    const static M G;
    uint v;
    ModInt(ll _v = 0) { set_v(_v % MD + MD); }
    M& set_v(uint _v) {
        v = (_v < MD) ? _v : _v - MD;
        return *this;
    }
    explicit operator bool() const { return v != 0; }
    M operator-() const { return M() - *this; }
    M operator+(const M& r) const { return M().set_v(v + r.v); }
    M operator-(const M& r) const { return M().set_v(v + MD - r.v); }
    M operator*(const M& r) const { return M().set_v(ull(v) * r.v % MD); }
    M operator/(const M& r) const { return *this * r.inv(); }
    M& operator+=(const M& r) { return *this = *this + r; }
    M& operator-=(const M& r) { return *this = *this - r; }
    M& operator*=(const M& r) { return *this = *this * r; }
    M& operator/=(const M& r) { return *this = *this / r; }
    M pow(ll n) const {
        M x = *this, r = 1;
        while (n) {
            if (n & 1) r *= x;
            x *= x;
            n >>= 1;
        }
        return r;
    }
    M inv() const { return pow(MD - 2); }
    friend ostream& operator<<(ostream& os, const M& r) { return os << r.v; }
};
using Mint = ModInt<TEN(9) + 7>;
// template<> const Mint Mint::G = Mint(3);

const int B = 4242424;
int n, k;
Mint dp[2333][2333];
bool used[2333][2333];
Mint fac[B], ifac[B];

void first() {
    fac[0] = 1;
    for (int i = 1; i < B; i++) fac[i] = Mint(i) * fac[i - 1];
    ifac[B - 1] = fac[B - 1].inv();
    for (int i = B - 2; i >= 0; i--) ifac[i] = Mint(i + 1) * ifac[i + 1];
}

Mint C(int n, int k) {
    if (n < 0 || k < 0 || n < k) return Mint(0);
    return fac[n] * ifac[k] * ifac[n - k];
}

Mint calc(int a, int b) {
    if (a > n || b > n || a < b) return Mint(0);
    if (used[a][b]) return dp[a][b];
    used[a][b] = true;
    return dp[a][b] = 
        calc(a + 1, b) + calc(a, b + 1) * C(n * k - a - b * (k - 1) - 1, k - 2);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(20) << fixed;

    cin >> n >> k;
    if (k == 1) {
        cout << 1 << endl;
        return 0;
    }
    first();
    used[n][n] = true;
    dp[n][n] = 1;
    cout << calc(0, 0) * fac[n] << endl;
    return 0;
}

Measured memory_bytes: 60160
#include <bits/stdc++.h>
using namespace std;
#define mid ((s + e) / 2)
#define makefast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define comp(x) lower_bound(vc.begin(), vc.end(), x) - vc.begin()

const int N = 5e5 + 7;

int n, k;
int p[N], q[N];
int sg[N * 25];

void ad(int p) {
	p += (1 << 20);
	while (p) {
		sg[p]++;
		p /= 2;
	}
}
int gt(int l, int r) {
	r += (1 << 20);
	l += (1 << 20);
	int res = sg[l];
	if (l == r)
		return res;
	res += sg[r];
	while (l / 2 != r / 2) {
		if (l % 2 == 0)
			res += sg[l + 1];
		if (r % 2 == 1)
			res += sg[r - 1];
		l /= 2;
		r /= 2;
	}
	return res;
}
int seg[N * 4];
int laz[N * 4];
void spl(int v) {
	for (int u = v * 2; u <= v * 2 + 1; u++) {
		seg[u] += laz[v];
		laz[u] += laz[v];
	}	
	laz[v] = 0;
}
void add(int l, int r, int val, int v = 1, int s = 1, int e = n + 1) {
	if (r <= s || e <= l)
		return;
	if (l <= s && e <= r) {
		seg[v] += val;
		laz[v] += val;
		return;
	}
	spl(v);
	add(l, r, val, v * 2, s, mid);
	add(l, r, val, v * 2 + 1, mid, e);
	seg[v] = min(seg[v * 2], seg[v * 2 + 1]);
}
int fnd(int v = 1, int s = 1, int e = n + 1) {
	if (e - s == 1)
		return s;
	spl(v);
//	cout << "fnd : " << v << " > " << s << ' ' << e << " >>> " << seg[v * 2] << ' ' << seg[v * 2 + 1] << endl;
	if (seg[v * 2 + 1] == 0)
		return fnd(v * 2 + 1, mid, e);
	else
		return fnd(v * 2, s, mid);

}
int get(int p, int v = 1, int s = 1, int e = n + 1) {
	if (e - s == 1)
		return seg[v];
	spl(v);
	if (p < mid)
		return get(p, v * 2, s, mid);
	else
		return get(p, v * 2 + 1, mid, e);
}

int res[N];

int main() {
	 makefast;
	 cin >> n >> k;
	 for (int i = 1; i <= n; i++) {
	 	cin >> p[i];
		q[p[i]] = i;
	 }
     for (int i = n; i >= 1; i--) {
	 	int t = gt(max(1, q[i] - k + 1), min(q[i] + k - 1, n));
		add(q[i], q[i] + 1, t);
		ad(q[i]);
	 }
/*	 for (int i = 1; i <= n; i++)
		 cout << "get : " << i << " > " << get(i) << endl;*/
	 for (int i = 1; i <= n; i++) {
	 	int plc = fnd();
/*		for (int j = 1; j <= n; j++)
			cout << "get: " << j << " > " << get(j) << endl;
		cout << i << " > " << plc << endl;*/
		res[plc] = n - i + 1;
		add(max(1, plc - k + 1), min(plc + k, n + 1), -1);
		add(plc, plc + 1, 1e9);
	 }
	 for (int i = 1; i <= n; i++)
		 cout << res[i] << ' ';

	return 0;
}


Measured memory_bytes: 28800
#define _CRT_SECURE_NO_WARNINGS
#include <vector>
#include <stdio.h>
#include <math.h>

using namespace std;

struct Point {
	double x;
	double y;
};

vector<Point> Points[2];
int zeroOne;
int oneZero;
int n;

void getPoints(Point *p1, Point *p2, Point *s, Point *u, Point *t) {
	s->x = (2.0*p1->x + p2->x) / 3.0;
	s->y = (2.0*p1->y + p2->y) / 3.0;
	t->x = (2.0*p2->x + p1->x) / 3.0;
	t->y = (2.0*p2->y + p1->y) / 3.0;
	double dx = p2->x - p1->x;
	double dy = p2->y - p1->y;
	u->x = (p1->x + p2->x) / 2.0 - dy * sqrt(3.0) / 6.0;
	u->y = (p1->y + p2->y) / 2.0 + dx * sqrt(3.0) / 6.0;
}

void koch() {
	Points[oneZero].clear();
	Point p1, p2, s, u, t;
	for (int i = 0; i < Points[zeroOne].size()-1; ++i) {
		p1 = Points[zeroOne][i];
		p2 = Points[zeroOne][i+1];
		getPoints(&p1, &p2, &s, &u, &t);
		Points[oneZero].push_back(p1);
		Points[oneZero].push_back(s);
		Points[oneZero].push_back(u);
		Points[oneZero].push_back(t);
	}
	Points[oneZero].push_back(Points[zeroOne][Points[zeroOne].size()-1]);
}

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

	Point p1, p2;
	p1.x = 0.0;
	p1.y = 0.0;
	p2.x = 100.0;
	p2.y = 0.0;
	zeroOne = 0;
	oneZero = 1;
	Points[zeroOne].push_back(p1);
	Points[zeroOne].push_back(p2);
	for (int i = 0; i < n; ++i) {
		koch();
		int temp = zeroOne;
		zeroOne = oneZero;
		oneZero = temp;
	}
	for (int i = 0; i < Points[zeroOne].size(); ++i) {
		printf("%.8f %.8f\n", Points[zeroOne][i].x, Points[zeroOne][i].y);
	}

	return 0;
}

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

struct card{
    char suit;
    int value;
};

void BubbleSort(vector<card> &x, int n){
    int flag = 1;


    for(int i = 0; i < n; i++){
        for(int j = n-1; j > i; j--){
            if(x.at(j).value < x.at(j - 1).value){
                card tmp = x.at(j);
                x.at(j) = x.at(j - 1);
                x.at(j - 1) = tmp;
            }
        }
    }
}

void SelectionSort(vector<card> &x, int n){
    for(int i = 0; i < n; i++){
        int minj = i;

        for(int j = i; j < n; j++){
            if(x.at(j).value < x.at(minj).value){
                minj = j;
            }
        }

        card tmp = x.at(minj);
        x.at(minj) = x.at(i);
        x.at(i) = tmp;
    }
}

int checkStable(vector<card> before_sort, vector<card> after_sort, int n){
    vector<queue<int>> vec_q(10);

    for(int i = 0; i < n; i++){
        int value = before_sort.at(i).value - 1;
        char suit = before_sort.at(i).suit;
        vec_q.at(value).push(suit);
    }

    // ソート後の配列を見てゆき、queueと一致した場合、除去
    for(int i = 0; i < n; i++){
        int value = after_sort.at(i).value - 1;
        char suit = after_sort.at(i).suit;

        if(suit == vec_q.at(value).front()){
            vec_q.at(value).pop();
        }
    }

    // queueの中身が0であるか確認
    for(int i = 0; i < 10; i++){
        if(vec_q.at(i).size() != 0){
            cout << "Not stable" << endl;
            return 0;

        }
    }
    cout << "Stable" << endl;
    return 1;
}

void printVec(vector<card> x, int n){
    rep(i, n-1){
        cout << x.at(i).suit << x.at(i).value << " ";
    }
    cout << x.at(n-1).suit << x.at(n-1).value << endl;
}

int main(){
    int n; cin >> n;
    vector<card> x(n);
    vector<card> bx(n);
    vector<card> sx(n);


    rep(i, n){
        cin >> x.at(i).suit >> x.at(i).value;
    }

    bx = x;
    sx = x;

    BubbleSort(bx, n);
    SelectionSort(sx, n);

    printVec(bx, n);
    checkStable(x, bx, n);

    printVec(sx, n);
    checkStable(x, sx, n);


}


Measured memory_bytes: 3164
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 1e9;
// const int MOD = 1e9 + 7;

int main() {
    int X;
    cin >> X;
    int ans = 1;
    for (int i = 2; i <= 1000; i++) {
        int n = i * i;
        while (n <= X) {
            chmax(ans, n);
            n *= i;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3592
#include <stdio.h>
int main(){    
int h, w;    
int i, j;    while(1){       
scanf("%d %d ", &h, &w);        
if(h==0&&w==0)break;       
 for(i=0;i<h;i++){           
 for(j=0;j<w;j++){               
 printf("#");            
}            
printf("\n");        
}        
printf("\n");    
}    
return 0;
}


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

#define SORT(c) sort((c).begin(), (c).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
#define ANS(ans) cout << (ans) << endl;
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
typedef vector<int> VI;
typedef pair<int, int> P;

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

int main() {
  int a,b;
  cin >> a >> b;
  if(a>b){
    swap(a, b);
  }

  if(a==1 &&b==2){
    ANS(3);
  }
  else if(a==1 && b==3){
    ANS(2);
  }
  else if(a==2 && b==3){
    ANS(1);
  }
  return 0;
}


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

int main()
{
  int N;
  int A[1000];
  int v;
  int j;

  cin >> N;

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

  for (int i = 0; i < N; i++)
   { v = A[i];
     j = i - 1;
     
     while(j >= 0 && A[j] > v){
       A[j + 1] = A[j];
       j--;
      }
     
     A[j + 1] = v;

     for (int k = 0; k < N; k++)
      { cout << A[k];
        if( k < N - 1) cout << " ";
      }
   cout << endl;
   } 
}

Measured memory_bytes: 1164
namespace System
{
    class Program
    {
        static void Main(string[] args)
        {

            var inputted = Console.ReadLine();

            int a = int.Parse(inputted.Split(' ')[0]);
            int b = int.Parse(inputted.Split(' ')[1]);

            int area = a * b;
            int zhou = (a + b) * 2;

            Console.WriteLine(area + " " + zhou);
            Console.ReadKey();
            

        }
    }
}

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

    int a, b, c;


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

    bool ans = false;
    if((a == b) && (a != c)){
        ans = true;
    }
    else if((a == c) && (a != b)){
        ans = true;
    }
    else if((b == c) && (a != b)){
        ans = true;
    }
    else{
        ans = false;
    }

    cout << ((ans)? "Yes" : "No");

}

Measured memory_bytes: 384
import java.util.Scanner;

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

        int n = sc.nextInt();
        int[] s = new int[n];
        for (int i = 0; i < n; i++) {
            s[i] = sc.nextInt();
        }

        int q = sc.nextInt();
        int count = 0;
        for (int i = 0; i < q; i++) {
            int ti = sc.nextInt();
            for (int si : s) {
                if (ti == si) {
                    count++;
                    break;
                }
            }
        }

        System.out.println(count);
    }
}


Measured memory_bytes: 40068
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, m, d[2019][2019] = {}, z = 0;
    string s[2019] = {};
    cin >> n >> m;
    for (int i = 0; i < n; i++) cin >> s[i];
    for (int i = 1; i < m; i++) d[n - 1][i] = 1;
    for (int i = n - 2; i >= 0; i--) {
        for (int j = 1; j < m; j++) {
            if ((s[i][j] == s[i][j - 1]) == (s[i + 1][j] == s[i + 1][j - 1])) d[i][j] = d[i + 1][j] + 1;
            else d[i][j] = 1;
            //cout << d[i][j] << " \n"[j == m - 1];
        }
    }
    z = max(n, m);
    for (int i = 0; i < n; i++) {
        int l[2019] = {}, r[2019] = {};
        vector<int> a = {0};
        for (int j = 1; j < m; j++) {
            while (d[i][a.back()] >= d[i][j]) a.pop_back();
            l[j] = a.back();
            a.push_back(j);
        }
        a = {m};
        for (int j = m - 1; j; j--) {
            while (d[i][a.back()] >= d[i][j]) a.pop_back();
            r[j] = a.back();
            a.push_back(j);
        }
        //for (int j = 1; j < m; j++) cout << l[j] << ' ' << r[j] << '\n';
        for (int j = 1; j < m; j++) z = max(z, (r[j] - l[j]) * d[i][j]);
    }
    cout << z;
}


Measured memory_bytes: 20480
/// meowa 

#pragma GCC optimize("O3")

#include<bits/stdc++.h>

#define x first
#define y second
#define pb push_back
#define sz(x) (int) x.size()
 
using namespace std;

using ll = long long;
using pii = pair<int, int>;                                   

const int MOD = 1e9 + 7;
const int INF = 1e9 + 1e2;

void stndrtn() {
#ifdef AM
    freopen(".in", "r", stdin);
#endif        
}                   

const bool flag = 0;

void ma1n() {
    int a;
    cin >> a;
    cout << a + a*a + a*a*a;        
} 

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr), stndrtn();
    int ts = 1;
    if (flag) {
        cin >> ts;
    }
    while (ts--) {
        ma1n(); 
    }
    return 0;
}

Measured memory_bytes: 3608
#include <iostream>
using namespace std;
const int maxn = 1000 + 5;
const int model = 1000000000 + 7;

int r, c;
char mem[maxn][maxn];
int f[maxn][maxn];

int main(int argc, char *argv[])
{
    cin >> r >> c;
    for (int i = 0; i < r; ++i)
    {
        for (int j = 0; j < c; ++j)
        {
            cin >> mem[i][j];
        }
    }
    
    f[0][0] = 1;
    for (int i = 0; i < r; ++i)
    {
        for (int j = 0; j < c; ++j)
        {
            if (i >= 1 && mem[i - 1][j] == '.')
            {
                f[i][j] += f[i - 1][j] % model;
            }
            if (j >= 1 && mem[i][j - 1] == '.')
            {
                f[i][j] += f[i][j - 1] % model;
            }
        }
    }
    cout << f[r - 1][c - 1] % model << endl;
    return 0;
}

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

using namespace std;

#define LOG(...) fprintf(stderr,__VA_ARGS__)
//#define LOG(...)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int main() {
    string s;
    cin >> s;
    int n = s.length();
    int ans = 0;
    if (n % 2 == 0) {
        REP(i, n/2) {
            if (s[n/2+i] == '(' && s[n/2-1-i] == ')') {
            } else if (s[n/2+i] == ')' && s[n/2-1-i] == '(') {
            } else if (isalpha(s[n/2+i]) && isalpha(s[n/2-1-i]) && s[n/2+i] == s[n/2-1-i]) {
            } else {
                ans++;
            }
        }
    } else {
        if (s[n/2] == '(' || s[n/2] == ')') ans++;
        FOR(i, 1, n/2+1) {
            if (s[n/2+i] == '(' && s[n/2-i] == ')') {
            } else if (s[n/2+i] == ')' && s[n/2-i] == '(') {
            } else if (isalpha(s[n/2+i]) && isalpha(s[n/2-i]) && s[n/2+i] == s[n/2-i]) {
            } else {
                ans++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define debug(x) cerr << #x << " " << x << "\n"

using namespace std;
typedef long long ll;
typedef pair <int,pair <int,int > > pii;

const int MOD = 1000000007;
map <int,int> mp;
int main()
{
    ll a,b,c,ok = 0;
    cin >> a ;
    while(a--){
        cin >> b;
        if(b % 2 == 0){
            if(b % 3 != 0 && b % 5 != 0){
                ok = 1;
            }
        }
    }
    if(ok)
        cout << "DENIED";
    else
        cout << "APPROVED";
    return 0;
}


Measured memory_bytes: 256
# 4種類の塩基 A,C,G,T が存在し、 A と T 、 C と G がそれぞれ対
# A,C,T,G いずれかの文字 b が入力される
# 塩基 b と対になる塩基をあらわす文字を出力

b = input()

if b == 'A':
    print('T')
elif b == 'C':
    print('G')
elif b == 'G':
    print('C')
else:
    print('A')

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

int main(){
	string s;
	cin >> s;
	int p = 0;
	string ans = "Yes";

	for(char c: s) {
		if (p == 0) {
			if (c != 'R' && c != 'U' && c != 'D') {
				ans = "No";
				break;
			}
		} else {
			if (c != 'L' && c != 'U' && c != 'D') {
				ans = "No";
				break;
			}
		}
		p = 1 - p;
	}


	cout << ans << endl;
	cin >> ans;
	return 0;
}

Measured memory_bytes: 256
#pragma warning(disable:4996)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <float.h>

#pragma region 定義
#define i_cin(X) scanf("%d", &X)
#define i_cin2(X,Y) scanf("%d %d",&X,&Y)
#define i_cin4(X,Y,Z,W) scanf("%d %d %d %d",&X,&Y,&Z,&W)
#define i_cin3(X,Y,Z) scanf("%d %d %d",&X,&Y,&Z)
#define l_cin(X) scanf("%ld",&X)
#define f_cin(X) scanf("%f",&X)
#define l_cin2(X,Y) scanf("%ld %ld",&X,&Y)
#define s_cin(X) scanf("%s",&X)
#define ll_cin(X) scanf("%lld", &X)

#define  i_cout(X) printf("%d\n",X)
#define  f_cout(X) printf("%g\n",X)
#define  i_cout2(X,Y) printf("%d %d\n",X,Y)
#define  l_cout(X) printf("%ld\n",X)
#define  s_cout(X) printf("%s\n",X)
#define  ll_cout(X) printf("%lld\n",X)

typedef long long  ll;
#define rept(x, s, n) for (int x = s; x < n; x++)

#define S_RTN(S)  s_cout(S);return 0


#define _itoa(A,N) sprintf(A, "%d", N);

int i_cins(int n, int* A);
int l_cins2(int n, long* A, long* B);
int s_dsort(const void* a, const void* b);
int s_asort(const void* a, const void* b);

int  _gcd(int a, int b);
int  _swp(int* a, int* b);
int _cknum(char* a, int n);
int _atoi(char* s, int len);


int s_asorts(const void* a, const void* b);

//昇順
int s_asorts(const void* a, const void* b) {
	return(strcmp((char*)a, (char*)b));
}
int s_dsort(const void* a, const void* b) {
	return(*(int*)b - *(int*)a);
}
int s_asort(const void* a, const void* b) {
	return(*(int*)a - *(int*)b);
}
int l_cins2(int n, long* a, long* b) {
	int i;
	rept(i, 0, n) {
		l_cin2(*(a + i), *(b + i));
	}
	return 0;
}
int i_cins(int n, int* a) {
	int i;
	for (i = 0; i < n; i++) {
		i_cin(*(a + i));
	}

	return 0;
}
int _gcd(int a, int b) {
	int r, tmp;
	if (a < b) { tmp = a; a = b; b = tmp; }
	r = a % b;
	while (r) {
		if (!r) break;
		a = b; b = r;
		r = a % b;
	}
	return(b);
}

long _max(long a, long b) {
	return a > b ? a : b;
}
long _min(long a, long b) {
	return a < b ? a : b;
}
int _swp(int* a, int* b)
{
	int tmp;
	tmp = *b; *b = *a; *a = tmp;
	return 0;
}

int _cknum(char* a, int n) {
	int i;
	char t = '0';

	for (i = 0; i < n; i++) {
		if (a[i] < '0' || a[i]>'9') return 1;
	}
	return 0;
}


int _atoi(char* s, int len) {
	char tmp[20];
	memcpy(tmp, s, len);
	tmp[len] = 0x00;
	return (atoi(tmp));
}
#pragma endregion

static int x[100001][2];
//static char a[100001];

int main(void)
{

	int  n,m;
	int  i, j,wa=0, ac=0;
	char a[3];

	i_cin2(n,m);
	for (i = 0; i < m; i++) {
		i_cin(j); j--;
		s_cin(a);
		if (x[j][0]) continue;
		if (a[0] == 'A') x[j][0] = 1;
		else             x[j][1]++;
	}
	for(i=0;i<n;i++) {
		if (!x[i][0]) continue;
		ac++;
		wa += x[i][1];
	}
	
	i_cout(ac);
	i_cout(wa);
	return 0;
}



Measured memory_bytes: 896
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<stdbool.h>
typedef long long ll;
typedef long double ld;
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define rrep(i,l,r)for(ll i=(l);i>=(r);i--)
#define INF (1LL<<60)
#define MOD1 1000000007
#define MOD2 998244353
#define MAX_N (1 << 17)
#define YES printf("Yes\n")
#define NO printf("No\n")
#define PN printf("\n")

void swap(ll *a, ll *b){ll c;c=*b;*b=*a;*a=c;}
ll max2(ll a,ll b){return a>=b?a:b;}
ll min2(ll a,ll b){return a>=b?b:a;}
ll min3(ll a, ll b, ll c){return (a<=b && a<=c) ? a : b<=c ? b : c;}
ll max3(ll a, ll b, ll c){return (a>=b && a>=c) ? a : b>=c ? b : c;}
ll minn(ll n, ll a[n]){ll b=INF;rep(i,0,n) b=min2(b,a[i]);return b;}
ll maxn(ll n, ll a[n]){ll b=-INF;rep(i,0,n) b=max2(b,a[i]);return b;}
ll ABS(ll a){return a>=0?a:(-a);}
ll POW(ll a, ll b){ll c=1;rep(i,0,b) c*=a;return c;}
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;}
ll mod(ll n){return n%=MOD1;}
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

typedef struct{ ll aa , bb;}fr;
int cmp1( const void *p, const void *q ) { return ((fr*)p) ->aa - ((fr*)q)->aa;}

/*----------------------priorityqueue(max)-----------------------------------------------------------*/
// top:min popHeap heap[0]=INF;
// kind = max?1:0
ll HeapValue(ll a){
    return a?-1:INF;
}
ll Heapcmp(ll a, ll b, ll kind){
    return kind ? (a<b?1:0) : (a>b?1:0);
}
ll heap[MAX_N];
void pushHeap(ll val, ll len , ll kind){
    ll i=len; heap[i]=val;
    while(i!=0){
        if( Heapcmp( heap[i], heap[(i-1)/2] , ABS(kind-1) )  ) swap(&heap[i],&heap[(i-1)/2]);
        i--;i/=2;
    }
}
void popHeap(ll *val, ll len, ll kind){
    ll i=0; *val=heap[0]; heap[0]=HeapValue(kind);
    swap(&heap[0],&heap[len-1]);
    while(len>i*2+1){
        if(i*2+2<len && Heapcmp(heap[i],heap[i*2+2],kind) && Heapcmp(heap[i*2+1],heap[i*2+2],kind) ){
            swap(&heap[i],&heap[i*2+2]);
            i*=2;i+=2;
        }else{
            if( Heapcmp(heap[i],heap[i*2+1],kind) ){
                swap(&heap[i],&heap[i*2+1]);
                i*=2;i++;
            }else break;
        }
    }
}
/*---------------------------------------------------------------------------------*/

int main(void){
    // char ;
    ll n,m,ans=0;
    scanf("%lld%lld",&n,&m);
    ll a[n];
    rep(i,0,n){
        scanf("%lld",&a[i]);
    }
    
    rep(i,0,n){
        pushHeap(a[i],i,1);
    }
    rep(i,0,m){
        ll val;
        popHeap(&val,n,1);
        val/=2;
        pushHeap(val,n-1,1);
    }
    rep(i,0,n){
        // printf("%lld ",heap[i]);
        ans+=heap[i];
    }
    
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 1664
N = int(input())
A = [list(map(int, input().split())) for i in range(2)]

def dfs(r, i, j, total):
  if i == 1 and j == N-1:
    r.append(total)
  
  if i < 1 and j < N-1:
    dfs(r, i+1, j, total+A[i+1][j])
    dfs(r, i, j+1, total+A[i][j+1])
  elif i < 1 and j == N-1:
    dfs(r, i+1, j, total+A[i+1][j])
  elif i == 1 and j < N-1:
    dfs(r, i, j+1, total+A[i][j+1])

i, j = [0]*2

r=[]
dfs(r, i, j, A[0][0])
print(max(r))


Measured memory_bytes: 9072
a, b, c, d = map(int, input().split())
 
def gcd(x, y):
    if x % y == 0:
        return y
    return gcd(y, x%y)
 
cd = c // gcd(c,d) * d

a -= 1
a_ = a - a//c - a//d + a//cd
b_ = b - b//c - b//d + b//cd
 
print(b_ - a_)

Measured memory_bytes: 3060
from itertools import accumulate
n,k,*a=map(int,open(0).read().split())
p=[x if x>0 else 0 for x in a]
acc=[0]+list(accumulate(a))
p_acc=[0]+list(accumulate(p))
rev_p_acc=[0]+list(accumulate(p[::-1]))
print(max(max(0,acc[k+i]-acc[i])+p_acc[i]+rev_p_acc[n-k-i] for i in range(n-k+1)))

Measured memory_bytes: 23308
#include <bits/stdc++.h>
 
const double pi = 3.141592653589793238462643383279;
using namespace std;
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
 
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
 
//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007
 
 
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
 
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
 
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)

//ここから編集 

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

    int x; cin >> x;
    if(x >= 400 && x < 600) cout << 8 << endl;
    if(x >= 600 && x < 800) cout << 7 << endl;
    if(x >= 800 && x < 1000) cout << 6 << endl;
    if(x >= 1000 && x < 1200) cout << 5 << endl;
    if(x >= 1200 && x < 1400) cout << 4 << endl;
    if(x >= 1400 && x < 1600) cout << 3 << endl;
    if(x >= 1600 && x < 1800) cout << 2 << endl;
    if(x >= 1800 && x < 2000) cout << 1 << endl;

    return 0;
}


Measured memory_bytes: 3688
#include <stdio.h>

int main(void)
{
  int a,b,c,d;
  int s1,s2,max;

  scanf("%d %d %d %d",&a,&b,&c,&d);

  s1=a*b;
  s2=c*d;

  max=s1;

  if(s2>max)max=s2;

  printf("%d\n",max);

  return 0;
}


Measured memory_bytes: 128
import heapq

N, M = map(int, input().split())
AB_list = []
[heapq.heappush(AB_list, list(map(int, input().split()))) for _ in range(N)]
ans = 0
kouho = []

for day in range(1, M + 1):
    if len(AB_list) != 0:
        while AB_list[0][0] <= day:           
            heapq.heappush(kouho, heapq.heappop(AB_list)[1]*(-1))
            if len(AB_list) == 0:
                break
    if len(kouho) != 0:
        ans += heapq.heappop(kouho)

print(ans * (-1))

Measured memory_bytes: 28176
#include<bits/stdc++.h>
using namespace std;
int main() {
  int k, a, b;
  cin >> k;
  cin >> a >> b;
  
  int largest = (b/k) * k;
  if( a <= largest ) {
    cout << "OK" << "\n";
  } else {
    cout << "NG" << "\n";
  }
  return 0;
}

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

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

using namespace std;

int main(void) {
    int N;

    cin >> N;

    vector<string> S(N);

    rep(i, N) {
        cin >> S.at(i);
    }

    sort(S.begin(), S.end());
    S.erase(unique(S.begin(), S.end()), S.end());

    cout << S.size() << endl;

    return 0;
}


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

typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FOR1(i, n) for(int (i)=1; (i)<=(n); (i)++)
#define FORI(i, n) for(int (i)=n-1; (i)>=0; (i)--)

int n, m;
vector<vector<int>> edge;
vector<int> h;
vector<bool> good;

int main(int argc, char** argv) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << setprecision(15);
    if (argc == 2 && atoi(argv[1]) == 123456789) freopen("d:\\code\\cpp\\contests\\stdin", "r", stdin);

    cin >> n >> m;
    h = vector<int>(n+1);
    good = vector<bool>(n+1, 1);
    FOR1(i, n) cin >> h[i];
    FOR(i, m){
        int u, v;
        cin >> u >> v;
        if (h[u] >= h[v])
            good[v] = 0;
        if (h[v] >= h[u])
            good[u] = 0;
    }

    int sol = 0;
    FOR1(i, n) sol += good[i];
    cout << sol << endl;

    if (argc == 2 && atoi(argv[1]) == 123456789) cout << clock()*1.0/CLOCKS_PER_SEC << " sec\n";
    return 0;
}

Measured memory_bytes: 3728
#include "bits/stdc++.h"

using namespace std;

//using Matrix = vector< vector<int> >;
typedef long long ll;
typedef pair<int, int> P;
#define fir first
#define sec second

const int INF = 1e9 + 10;
//const ll INF = 1e18 + 10LL;
int dx[5] = {0, 0, 1, -1, 0}, dy[5] = {1, -1, 0, 0, 0};
const double EPS = 1e-10;
bool cmp(P a, P b) { return a.second < b.second; } //End sort (Interval scheduling problem)
ll MOD = 1e9 + 7;

int H, W;
char field[20][21];

int ans;

int bfs(int sx, int sy, int gx, int gy) {
	int d[20][20];
	for (int i = 0; i < H; i++)
		for (int j = 0; j < W; j++) d[i][j] = INF;


	d[sy][sx] = 0;
	queue<P> que;
	que.push({sx, sy});
	while (!que.empty()) {
		P p = que.front(); que.pop();

		if (p.fir == gx && p.sec == gy) break;

		for (int i = 0; i < 4; i++) {
			int nx = p.fir + dx[i], ny = p.sec + dy[i];

			if (nx < 0 || nx >= W || ny < 0 || ny >= H || field[ny][nx] == '#' || d[ny][nx] != INF) continue;

			d[ny][nx] = d[p.sec][p.fir] + 1;
			que.push({nx, ny});
		}
	}

	return d[gy][gx];
}

int main(void){
	cin>>H>>W;
	for (int i = 0; i < H; i++)
		for (int j = 0; j < W; j++) cin>>field[i][j];


	
	for (int sx = 0; sx < W; sx++) {
		for (int sy = 0; sy < H; sy++) {
			for (int gx = 0; gx < W; gx++) {
				for (int gy = 0; gy < H; gy++) {
					if ((field[sy][sx] != '#') && (field[gy][gx] != '#')) {
						ans = max(ans, bfs(sx, sy, gx, gy));
					}
				}
			}
		}
	}

	printf("%d\n", ans);
	
	return 0;
}

Measured memory_bytes: 384
import collections
import itertools
import numpy as np
import sys
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()


a,b = IL()
cnt = 0
for i in range(a,b+1):
    if str(i) == str(i)[::-1]:
        cnt += 1

print(cnt)

Measured memory_bytes: 20232
//
// Created by myabu on 2020/02/02.
//

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <math.h>
#include <stack>
#include <queue>
#include <cstdio>
#include <numeric>
#include <iomanip>

using namespace std;


int main(void){
    int  a,b,c,d;

    cin>>a>>b>>c>>d;

    if(abs(a-c)<=d){
        cout<<"Yes"<<endl;
    }else if(abs(a-b) <= d && abs(b-c) <= d){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }

    return 0;
}

Measured memory_bytes: 888