akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
// ------------------------------------
int c[500005];
int d[500005];
int a[500005];
int bit[500005];
vector<pair<int, int>> v[500005];
int n, q;
// ------------------------------------
// 1 is true
// 0 is false

void update(int i, int value) {
  for (; i <= n; i += i & -i) {
    bit[i] += value;
  }
}

int sum(int i) {
  int s = 0;
  for (; i > 0; i -= i & -i) {
    s += bit[i];
  }
  return s;
}

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> q;
  for (int i = 1; i <= n; i++) {
    cin >> c[i];
  }
  for (int i = 1; i <= q; i++) {
    int l, r;
    cin >> l >> r;
    v[r].push_back({i, l});
  }

  for (int i = 1; i <= n; i++) {
    if (d[c[i]] != 0) {
      update(d[c[i]], -1);
    }
    d[c[i]] = i;
    update(i, 1);
    for (auto x : v[i]) {
      a[x.first] = sum(i) - sum(x.second - 1);
    }
    // for (int r = 1; r <= n; r++) {
    //   cout << c[r] << ' ';
    // }
    // cout << endl;
    // for (int r = 1; r <= n; r++) {
    //   cout << d[r] << ' ';
    // }
    // cout << endl;
    // for (int r = 1; r <= n; r++) {
    //   cout << e[r] << ' ';
    // }
    // cout << endl << "--------------------------------" << endl;
  }
  for (int i = 1; i <= q; i++) {
    cout << a[i] << endl;
  }
}


Measured memory_bytes: 33216
N = int(input())
AB = sorted((tuple(map(int,input().split())) for _ in [0]*N),key=lambda x:(x[0],-x[1]))
CD = sorted((tuple(map(int,input().split())) for _ in [0]*N),key=lambda x:(x[0],-x[1]))
ans = 0
for c,d in CD:
    m = max([b for a,b in AB if a<c and b<d]+[-1])
    if m==-1:continue
    for i,ab in enumerate(AB):
        a,b = ab
        if b == m:
            ans += 1
            AB[i] = (1000,1000)
            break
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define finc(i, a, b) for (int i = a, _b = (b); i <= _b; i++)
#define fdec(i, a, b) for (int i = a, _b = (b); i >= _b; i--)
#define ii pair <int, int>
#define x first
#define y second
#define db(x) cerr << #x << " = " << x << endl;

using namespace std;

inline void read(int &x){register int c = getchar();x = 0; int neg = 0;for (;((c<48 || c>57) && c != '-') ;c = getchar());if(c=='-') {neg=1;c=getchar();}for(;c>47 && c<58;c = getchar()) {x = (x<<1) + (x<<3) + c - 48;}if(neg) x=-x;}
inline void read(long long &x){register int c = getchar();x = 0; int neg = 0;for (;((c<48 || c>57) && c != '-') ;c = getchar());if(c=='-') {neg=1;c=getchar();}for(;c>47 && c<58;c = getchar()) {x = (x<<1) + (x<<3) + c - 48;}if(neg) x=-x;}
inline void writeln(long long x){char buffor[21];register int i=0;int neg=0; if (x<0) {neg=1; x= -x;}do{buffor[i++]=(x%10)+'0';x/=10;} while(x);i--;if (neg) putchar('-');while(i>=0) putchar(buffor[i--]);putchar('\n');}
inline void write(long long x){char buffor[21];register int i=0;int neg=0; if (x<0) {neg=1; x= -x;}do{buffor[i++]=(x%10)+'0';x/=10;} while(x);i--;if (neg) putchar('-');while(i>=0) putchar(buffor[i--]);putchar(' ');}

const int N = 1e5 + 7;

int n;
int a[N];

struct BIT {
	int tree[2 * N];

	void Reset(){
		for (int i = 0; i < 2 * N; i++) tree[i] = 0;
	}

	void Update(int x){
		for (int i = x; i <= 2 * n; i += i & (-i))
			tree[i]++;
	}

	int Query(int x){
		int res = 0;
		for (int i = x; i > 0; i -= i & (-i))
			res += tree[i];
		return res;
	}
}BIT;

inline bool check(int x){
	int cur = n + 1;
	long long cnt = 0;

	BIT.Reset();
	BIT.Update(cur);

	finc(i, 1, n) {
		if (a[i] >= x)
			cur++;
		else
			cur--;
		cnt += BIT.Query(cur);
		BIT.Update(cur);
	}

	return (cnt * 2 >= 1LL * n * (n + 1) / 2);
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	// freopen("test.inp", "r", stdin);
	// freopen("test.out", "w", stdout);
	read(n);
	finc(i, 1, n) read(a[i]);
	int l = 1;
	int r = (int)1e9;
	while (l <= r){
		int mid = (l + r) / 2;
		if (check(mid))
			l = mid + 1;
		else
			r = mid - 1;
	}
	writeln(r);
}

Measured memory_bytes: 1408
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int a,b;
        a = scan.nextInt(); b = scan.nextInt();
        if(b == 100) {
            b += 1;
        }
        System.out.println((int)Math.pow(100,a)*b);
    }
}


Measured memory_bytes: 21844
#include "bits/stdc++.h"
#define ed cout<<"\n";
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define All(obj) (obj).begin(),(obj).end()

using namespace std;


int main() {
	speed;
	int s;
	cin >> s;
	set <int>st;
	int x = s;
	while (st.count(x) == 0) {//ｘと同じ値が出るまで回す
		st.insert(x);
		if (x % 2 == 0)x /= 2;
		else x = x * 3 + 1;
	}
	cout << st.size() + 1;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int 
using namespace std;
int main()
{
      long double a,b,c;
       cin>>a>>b>>c;
    ll ok=0;
      long double e=1.0E-15;
       //cout<<e<<endl;
        if((sqrt(a)+sqrt(b)+e)<sqrt(c))ok=1;
    printf(ok==1? "Yes\n":"No\n");
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <map>

//#include <bits/stdc++.h>
using namespace std;
#define print(x) cout<<(x)<<endl
#define prints(x, y) cout<<(x)<<" "<<(y)<<endl
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define ll long long int
#define pb push_back

int main() {
  int h, w;
  string s;
  cin >> h >> w;
  int xy[h][w];
  rep(i, h){
    cin >> s;
    rep(j, w){
      if(s[j] == '#') xy[i][j] = -1;
      else xy[i][j] = 0;
    }
  }

  int dx[3] = {1, 0, -1}, dy[3] = {1, 0, -1};
  rep(i, h){
    rep(j, w){
      if(xy[i][j] == -1){ // mineの時
        rep(x, 3){
          rep(y, 3){
            if (x==1 && y==1) continue;
            int nx = i + dx[x];
            int ny = j + dy[y];
            if(-1 < nx && nx < h && -1 < ny && ny < w && xy[nx][ny] != -1){
              xy[nx][ny]++;
            }
          }
        }
      }
    }
  }

  // 出力
  rep(i, h){
    rep(j, w){
      if(xy[i][j] == -1 ) cout << "#";
      else cout << xy[i][j];
    }
    cout << endl;
  }
}


Measured memory_bytes: 504
mod=10**9+7
n=int(input())
s=input()
if s[0]=='W' or s[-1]=='W':
  print(0)
  exit()
arr=['']*(2*n)
arr[0]='L'
arr[-1]='R'
cnt=1
for i in range(1,n):
  if (cnt==0 and s[i]=='B') or (cnt==1 and s[i]=='W'):
    arr[i]='L'
    cnt=(cnt+1)%2
  else:
    arr[i]='R'
    cnt=(cnt+1)%2
cnt=1
for i in range(2*n-2,n-1,-1):
  if (cnt==0 and s[i]=='B') or (cnt==1 and s[i]=='W'):
    arr[i]='R'
    cnt=(cnt+1)%2
  else:
    arr[i]='L'
    cnt=(cnt+1)%2
if arr.count('L')!=n:
  print(0)
else:
  ans=1
  cnt=0
  for char in arr[::-1]:
    if char=='R':
      cnt+=1
    else:
      ans*=cnt
      ans%=mod
      cnt-=1
  for i in range(1,n+1):
    ans*=i
    ans%=mod
  print(ans)

Measured memory_bytes: 12412
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define rep(i, a, n) for (ll i = (a); i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    ll n;
    cin >> n;
    vector<double> v(n);
    rep(i, 0, n) cin >> v[i];
    sort(v.begin(), v.end());
    double ans = v[0];
    rep(i, 1, n) ans = (ans + v[i]) / 2.0;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int b;
    string a;
    cin>>b>>a;
	for(int i = 0; i < a.size(); i++){
		a[i] = 'A' + (a[i]-'A'+b)%(26);
	}
	cout<<a;
	return 0;
}


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

int main() {
 
    int a, b, c;
 
    cin >> a >> b;
 
    while(1) {
        c = a % b;
        if(c == 0) {
            cout << b << endl;
            break;
        }
        else{
            a = b;
            b = c;  
        }
    }
 
    return 0;
}

Measured memory_bytes: 3096
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String[] t = new String[s.length()];
        for (int i = 0; i < s.length(); i++) {
            t[i] = s.substring(i, i + 1);
        }

        for (int l = 0; l < s.length(); l++ ) {
            for (int r = 0 ; r < s.length(); r++) {
                StringBuilder sb = new StringBuilder();
                if (l < r) {
                    for (int i = 0 ; i <= l ; i++) {
                        sb.append(t[i]);
                    }
                    for (int i = r ; i < s.length();i++ ) {
                        sb.append(t[i]);
                    }
                }

                if (sb.toString().equals("keyence")) {
                    System.out.println("YES");
                    return;
                }
            }
        }
        System.out.println("NO");
    }

}


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

int main()
{

  int x, y;
  cin >> x >> y;

  int sum1 = 0;
  int sum2 = 0;
  if (x == 2) {
    sum1 = 2;
  } else if (x == 4 || x == 6 || x == 9 || x == 11) {
    sum1 = 1;
  }

  if (y == 2) {
    sum2= 2;
  } else if (y == 4 || y == 6 || y == 9 || y == 11) {
    sum2= 1;
  }

  if (sum1== sum2)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

	return 0 ;

	}


Measured memory_bytes: 256
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws IOException {
//		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
//		String W	 = in.readLine();
//		int num = Integer.parseInt(W.split(" ")[0]);

		Scanner sc = new Scanner(System.in);
		long A = sc.nextLong();
		long B = sc.nextLong();
		long N = sc.nextLong();

//		long modb = B%N;

		long x = B -1;
		long fb = x/B;
		if(x>N) {
			x = N;
		}

		long ans = (long)A*x/B -A*fb;


		System.out.println(ans);


	}

	//	//二分探索
	//k <= num となる最小の配列要素kのインデックスを返す
	static private int binarySearch(long num, long[] orderedArray){
		int lowerBorder = -1;
		int upperBorder = orderedArray.length;
		int mid;

		while(upperBorder - lowerBorder >1) {
			mid = (upperBorder + lowerBorder)/2;
			if(orderedArray[mid]<=num) {
				lowerBorder = mid;
			}else {
				upperBorder = mid;
			}
		}
		return lowerBorder;
	}

	//二分探索
	//k <= num となる最小のList要素kのインデックスを返す
	static private int binarySearch(long num, ArrayList<Long> orderedList){
		int lowerBorder = -1;
		int upperBorder = orderedList.size();
		int mid;

		while(upperBorder - lowerBorder >1) {
			mid = (upperBorder + lowerBorder)/2;
			if(orderedList.get(mid)<=num) {
				lowerBorder = mid;
			}else {
				upperBorder = mid;
			}
		}
		return lowerBorder;
	}

	//aとbの最小公倍数を求める
	public static int gcd(int a, int b) {
        return b == 0 ? a: gcd(b, a % b);
	}
	public static long gcd(long a, long b) {
        return b == 0 ? a: gcd(b, a % b);
	}



}


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

int N;
int p[30];

bool complete() {
  int t = p[0];
  for (int i=0; i<9; i++) {
    if (p[i] != t) return false;
  }
  if (p[ 9] != p[10] || p[ 9] != p[11] || p[10] != p[11]) return false;
  if (p[12] != p[13] || p[12] != p[14] || p[13] != p[14]) return false;
  if (p[15] != p[16] || p[15] != p[17] || p[16] != p[17]) return false;
  if (p[18] != p[19] || p[18] != p[20] || p[19] != p[20]) return false;
  return true;
}

int dfs(int i) {
  if (i == 8 || complete()) return i;
  swap(p[6], p[21]);
  swap(p[7], p[22]);
  swap(p[8], p[23]);
  swap(p[9], p[11]);
  swap(p[17], p[12]);
  int a_1 = dfs(i+1);
  swap(p[6], p[21]);
  swap(p[7], p[22]);
  swap(p[8], p[23]);
  swap(p[9], p[11]);
  swap(p[17], p[12]);

  swap(p[0], p[27]);
  swap(p[1], p[28]);
  swap(p[2], p[29]);
  swap(p[15], p[14]);
  swap(p[18], p[20]);
  int a_2 = dfs(i+1);
  swap(p[0], p[27]);
  swap(p[1], p[28]);
  swap(p[2], p[29]);
  swap(p[15], p[14]);
  swap(p[18], p[20]);

  swap(p[0], p[23]);
  swap(p[3], p[26]);
  swap(p[6], p[29]);
  swap(p[9], p[20]);
  swap(p[15], p[17]);
  int a_3 = dfs(i+1);
  swap(p[0], p[23]);
  swap(p[3], p[26]);
  swap(p[6], p[29]);
  swap(p[9], p[20]);
  swap(p[15], p[17]);

  swap(p[2], p[21]);
  swap(p[5], p[24]);
  swap(p[8], p[27]);
  swap(p[11], p[18]);
  swap(p[12], p[14]);
  int a_4 = dfs(i+1);
  swap(p[2], p[21]);
  swap(p[5], p[24]);
  swap(p[8], p[27]);
  swap(p[11], p[18]);
  swap(p[12], p[14]);
  return min(min(a_1, a_2), min(a_3, a_4));
}

int main() {
  cin >> N;
  for (int i=0; i<N; i++) {
    for (int j=0; j<30; j++) cin >> p[j];
    // 4^8
    cout << dfs(0) << "\n";
  }
  return 0;
}

Measured memory_bytes: 3100
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <set>
#include <map>
#include <algorithm>
#include <vector>
using namespace std;

const int N = 100100;
int n, m;

set<int> a[N];
vector<int> b[N];
int cnt[N];

int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	scanf("%d%d", &n, &m);
	if (m == 1)
	{
		printf("%d\n", n / 2);
		return 0;
	}
	for (int i = 0; i < n; i++)
	{
		int x;
		scanf("%d", &x);
		cnt[x]++;
		int y = x % m;
		b[y].push_back(x);
		if (cnt[x] & 1)
			a[y].insert(x);
		else
			a[y].erase(x);
	}
	for (int y = 0; y < m; y++)
	{
		int z = (m - y) % m;
		while(!a[y].empty())
		{
			int x = *a[y].begin();
			a[y].erase(a[y].begin());
			if (!a[z].empty())
			{
				int v = *a[z].begin();
				a[z].erase(a[z].begin());
				cnt[x]--;
				cnt[v]--;
				continue;
			}
			while(!b[z].empty())
			{
				int v = b[z].back();
				b[z].pop_back();
				if (v != x && cnt[v] != 0)
				{
					if (cnt[v] & 1) throw;
					a[z].insert(v);
					cnt[x]--;
					cnt[v]--;
					b[y].push_back(x);
					x = -1;
					break;
				}
			}
			if (x != -1)
			{
				a[y].insert(x);
				break;
			}
		}
	}
	int ans = n;
	for (int i = 0; i < m; i++)
		ans -= (int)a[i].size();
	if (ans & 1) throw;
	printf("%d\n", ans / 2);

	return 0;
}

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

int main() {
  
  int w,h,n;
  cin >> w >> h >> n;
  
  vector<vector<int>> s(n,vector<int>(3));
  for( int i = 0; i < n; i++){
    for( int j = 0; j < 3; j++){
      cin >> s[i][j];
    }
  }
  
  int a = 1,b = 1;
  
  vector<vector<int>> m(w*h,vector<int>(3));
  for( int i = 0; i < w*h; i++){
    if ( b == h + 1){
      a++;
      b = 1;
    }
    for( int j = 0; j < 3; j++){
      if ( j == 0 ){
        m[i][j] = a;
      }else if ( j == 1 ){
        m[i][j] = b;
        b++;
      }else{
        m[i][j] = 1;
      }
    }
  }
  
  if ( w == 0 || h == 0 ){
    cout << 0 << endl;
    return 0;
  }
  
  for ( int i = 0; i < n; i++){
    if ( s[i][2] == 1 ){
      for ( int j = 0; j < w*h; j++){
        if (m[j][0] <= s[i][0] ){
          m[j][2] = 2;
        }
      }
    }else if ( s[i][2] == 2 ){
      for ( int j = 0; j < w*h; j++){
        if (m[j][0] > s[i][0] ){
          m[j][2] = 2;
        }
      }
    }else if ( s[i][2] == 3 ){
      for ( int j = 0; j < w*h; j++){
        if (m[j][1] <= s[i][1] ){
          m[j][2] = 2;
        }
      }
    }else if ( s[i][2] == 4 ){
      for ( int j = 0; j < w*h; j++){
        if (m[j][1] > s[i][1] ){
          m[j][2] = 2;
        }
      }
    }
  }
  
  int count = 0;
  
  for ( int i = 0; i < w*h; i++){
    if ( m[i][2] == 1 ){
      count++;
    }
  }
  
  cout << count << endl;
   
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)
#define REPi(i, a, b) for(int i=int(a); i<int(b); i++)
#define MEMS(a,b) memset(a,b,sizeof(a))
#define mp make_pair
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; }
const ll MOD = 1e9+7;

const int MAX_N = 10000;

ll fact[MAX_N+100];
ll frev[MAX_N+100];

ll rev(ll a, ll p){
    if(p == 0) return 1;
    ll tmp = rev(a, p/2);
    tmp = tmp * tmp % MOD;
    if(p % 2 == 1) tmp = tmp * a % MOD;
    return tmp;
}


void calc_fact(){
    fact[0] = frev[0] = 1;
    for(int i = 1; i <= MAX_N; i++){
        fact[i] = (fact[i-1] * i) % MOD;
        frev[i] = rev(fact[i], MOD-2);
    }
}


ll comb(int n, int k){
    if(n < 0 || k < 0 || n < k) return 0;
    if(n == 0 || k == 0) return 1;
    return fact[n] * frev[k] % MOD * frev[n-k] % MOD;
}


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

    //in main function
    fact[0] = frev[0] = 1;
    for(int i = 1; i <= MAX_N; i++){
        fact[i] = (fact[i-1] * i) % MOD;
        frev[i] = rev(fact[i], MOD-2);
    }

    REPi(i,1,K+1){
        ll ans = comb(N-K+1, i) * comb(K-1, i-1);
        cout << ans % MOD << endl;
    }
    return 0;
}


Measured memory_bytes: 384
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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

const ll INF=1e15;

int main(){
    ll n;
    cin >> n;
    vector<ll> a(n),ans;
    rep(i,n){
        cin >> a[i];
    }
    ll st=-1,en=-1;
    ll money=1000;
    ll s=0;
    rep(i,n){
        if(a[i]<a[i+1]){
            ans.push_back(i);
            s=money/a[i];
            money-=s*a[i];
            st=i;
            en=i;
            for(ll j=i+1;j<n;j++){
                if(a[j]>=a[j-1]){
                    en=j;
                    continue;
                }
                else{
                    break;
                }
            }
            money+=s*a[en];
            i=en-1;
        }
    }
    cout << money << endl;
    return 0;
}

Measured memory_bytes: 3632
N=int(input())
E=[[] for i in range(N)]

for i in range(N-1):
    x,y=map(int,input().split())
    x-=1
    y-=1
    E[x].append(y)
    E[y].append(x)


from collections import deque
BACK=[-1]*N

Q=deque([0])

while Q:
    x=Q.pop()

    for to in E[x]:
        if BACK[to]==-1:
            BACK[to]=x
            Q.append(to)

ROAD=[N-1]

while ROAD[-1]!=0:
    ROAD.append(BACK[ROAD[-1]])

LEN=len(ROAD)

COLOR=[-1]*N
QW=deque()
QB=deque()

for i in range(LEN//2):
    COLOR[ROAD[i]]=1
    QB.append(ROAD[i])

for i in range(LEN//2,LEN):
    COLOR[ROAD[i]]=0
    QW.append(ROAD[i])

SW=0
if LEN%2==1:
    SW+=1
SB=0

while QW:
    x=QW.pop()

    for to in E[x]:
        if COLOR[to]==-1:
            COLOR[to]=0
            SW+=1
            QW.append(to)

while QB:
    x=QB.pop()

    for to in E[x]:
        if COLOR[to]==-1:
            COLOR[to]=1
            SB+=1
            QB.append(to)

if SW>SB:
    print("Fennec")
else:
    print("Snuke")


Measured memory_bytes: 24648
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.sql.Array;
import java.util.*;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }


    static class TaskD {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n,m;
            n=in.nextInt();
            m=in.nextInt();
            PriorityQueue<Integer> queue = new PriorityQueue<>(n ,Collections.reverseOrder());
            for (int i = 0; i <n ; i++) {
                queue.add(in.nextInt());
            }
            while (m>0){
                int v = queue.poll();
                v/=2;
                queue.add(v);
                m--;
            }
            long ans = 0;
            while (!queue.isEmpty()){
                ans+=queue.poll();
            }
            System.out.println(ans);











        }



    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
            return Long.parseLong(next());
        }

    }
}

Measured memory_bytes: 45664
n,m=gets.split.map(&:to_i)
k=m.times.map{gets.split.map(&:to_i)}
p=gets.split.map(&:to_i)

ans=0
[0,1].repeated_permutation(n).to_a.each do |bit|
    check=true
    m.times do |i|
        count=0
        k[i][0].times do |j|
            count+=bit[k[i][j+1]-1]
        end
        check=false and break if count%2!=p[i]
    end
    if check
        ans+=1
    end
end
puts ans


Measured memory_bytes: 14368
N, M = map(int, input().split())
P = list(map(int, input().split()))

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

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

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

uf = UnionFind(N)
for _ in range(M):
    x, y = map(int, input().split())
    uf.union(x-1, y-1)

ans = 0
for i in range(N):
    if uf.same(i, P[i]-1):
        ans += 1

print(ans)

Measured memory_bytes: 20428
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int[] h = new int[n];
		
		for (int i = 0; i < n; i++) {
			h[i] = sc.nextInt();
		}
		
		int[] a = new int[n];
		a[0] = 0;
		a[1] = Math.abs(h[1] - h[0]);
		
		for (int i = 2; i < n; i++) {
			a[i] = Math.min(a[i-1] + Math.abs(h[i] - h[i-1]), a[i-2] + Math.abs(h[i] - h[i-2]));
		}
		
		System.out.println(a[n-1]);
	}
}

Measured memory_bytes: 50456
s = input().split()

n = int(s[0])
m = int(s[1])

N = [[0 for j in range(n)] for i in range(n)]

M = [[0 for j in range(m)] for i in range(m)]

for num in range(n):
    p = input()
    words = list(p)
    for number in range(n):
        N[num][number] = words[number]

for num in range(m):
    p = input()
    words = list(p)
    for number in range(m):
        M[num][number] = words[number]



exist = False

for num in range(n):
    for number in range(n):
        if num + m - 1 >= n or number + m - 1 >= n:
            continue

        check = True
        for i in range(m):
            for j in range(m):
                if N[num + i][number + j] != M[i][j]:
                    check = False
        
        if check:
            exist = True

if exist:
    print('Yes')
else:
    print('No')



Measured memory_bytes: 9096
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>

using namespace std;

#define MAX(a, b)  a>b?a:b

int main()
{
	char str[8];
	cin>>str;

	if((str[2]==str[3]) && (str[4]==str[5])) {
		cout<<"Yes"<<endl;
	} else {
		cout<<"No"<<endl;
	}

	return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    var strA = readLine().orEmpty()
    var strB = readLine().orEmpty()
    var strC = readLine().orEmpty()
    val lengthAll = strA.length + strB.length + strC.length
    var player = 'a'
    var i = 0
    run loop@{
      while(i < lengthAll){
            if(player == 'a'){
                if(strA.isEmpty()){
                    return@loop
                }
                player = strA[0]
                strA = strA.drop(1)
            }else if(player == 'b'){
                if(strB.isEmpty()){
                    return@loop
                }
                player = strB[0]
                strB = strB.drop(1)
            }else if(player == 'c'){
                if(strC.isEmpty()){
                    return@loop
                }
                player = strC[0]
                strC = strC.drop(1)
            }
            i++
        }
    }


    println(player.toUpperCase())
}

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

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

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

int main(){

    ll n,k;cin >> n >> k;
    string str;cin >> str;
	vector<int> v(str.size());
	REP(i,str.size()){
		if(str[i] == 'A')v[i] = 1;
		else v[i] = 0;
	}

    int place = 0;
    int rev = 0;

    while(k){
		//cout << k << " " << place << endl;
        if(place == str.size())break;
        if((v[place] + rev) % 2){
			v[place] = 1 - v[place];
		}
		else{
			place++;
			rev = 1 - rev;
		}
		k--;
    }

	if(k == 0){
		for(int i = place;i < str.size();i++){
			if((v[i] + rev) % 2)cout << 'A';
			else cout << 'B';
		}
		for(int i = place - 1;i >= 0; i--){
			if(i % 2 == 0)cout << 'A';
			else cout << 'B';
		}
		cout << endl;
	}
	else{
		if(str.size() % 2){
			REP(i,str.size()){
				if(i == 0){
					if(k % 2 == 0)cout << 'A';
					else cout << 'B';
				}
				else if(i % 2)cout << 'B';
				else cout << 'A';
			}
		}
		else{
			REP(i,str.size()){
				if(i % 2)cout << 'A';
				else cout << 'B';
			}
		}
		cout << endl;
	}

	return 0;
}


Measured memory_bytes: 1540
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
typedef vector<int> vi;
typedef vector<ll> vl;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define IN cin >> 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (m-1); i >= (int)(n); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.end(), v.begin());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
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; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

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


int main(){
    
    int a;
    cin >> a;
    if(a == 3 || a == 5 || a== 7)YES;
    else NO;
    return  0;
}


Measured memory_bytes: 256
a, b, c, k = map(int,input().split())

count = 0

if k > a:
    count += a
    k -= a
else:
    count += k
    k = 0
    
if k > b:
    k -= b
else:
    k = 0
    
if k > c:
    count -= c
else:
    count -= k
    
print(count)

Measured memory_bytes: 9040
#include <iostream>
#include <cstdio>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <complex>
#include <map>
#include <climits>
#include <sstream>
using namespace std;

#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second
#define mkp make_pair

static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vint;
static const int INF=1<<24;

template <class T>
void initvv(vector<vector<T> > &v,int a,int b, const T  &t = T()){
	v.assign(a,vector<T>(b,t));
}

//v.erase(unique(v.begin(),v.end()),v.end());


int main(){
	int n;
	cin>>n;
	rep(i,n){
		int a,b,c;
		int ans=0;
		cin>>a>>b>>c;
		while(1){
			if(a&&b&&c){
				ans++;
				a--;
				b--;
				c--;
			}
			else{
				break;
			}
		}
		while(1){
			if(a>1&&b){
				ans++;
				a-=2;
				b--;
			}
			else{
				break;
			}
		}
		while(1){
			if(a>2){
				ans++;
				a-=3;

			}
			else{
				break;
			}
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 1164
#include<iostream>
int main(){int a,b,c,d,i;while(std::cin>>a>>b>>c){for(i=1,d=0;i<=10;++i)if(i-a&&i-b&&i-c)i<=20-a-b?++d:d;std::cout << (d > 3 ? "YES" : "NO") << std::endl;}}

Measured memory_bytes: 1148
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <random>

using namespace std;


int main()
{
	int N;
	double ans = 0;

	cin >> N;

	int n;
	for(int ni = 0; ni < N; ni++){
		cin >> n;
		ans += 1.0/n;
	}

	printf("%f\n", 1/ans);


	return 0;
}



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

int main(){
    int N; cin >> N;
    vector<int> L(N);
    for(int i = 0;i < N;++i){
        cin >> L[i];
    }
    sort(L.begin(),L.end());
    ll ans = 0;
    for(int i = 0;i < N-2;++i){
        for(int j = i+1;j < N-1;++j){
            for(int k = j+1;k < N;++k){
                int a = L[i];
                int b = L[j];
                int c = L[k];
                if(c < a + b) ans++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
#include "bits/stdc++.h"
// Custom Header {{{
#define ALL(x) x.begin(), x.end()
#define rep(i, s, n)      for(int i(s); i < int(n); ++i)
#define endl '\n'
#ifndef YDK
#define eprintf(...)
#endif
using namespace std;
using i64 = long long;
using pii = pair<i64, i64>;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr const int INF  = 0x3f3f3f3f;
constexpr const i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr const int MOD  = int(1e9) + 7;
// }}}

// Library {{{
inline vector<int> digits(unsigned long long n) {
    vector<int> ret;
    do { ret.push_back(n % 10); n /= 10; } while(n > 0);
    return ret;
}
// }}}


signed main()
{
    i64 N;
    cin >> N;

    auto d = digits(N);
    int L = d.size();

    i64 ans = 0;

    reverse(ALL(d));

    for (int b = 0; b < (1 << (L-1)); ++b) {
        bitset<16> bit = b;

        i64 tmp = d[0];
        for (int i = 0; i < L-1; ++i) {
            if (bit[i]) {
                ans += tmp;
                tmp = d[i+1];
            } else {
                tmp = tmp*10 + d[i+1];
            }
        }
        ans += tmp;
    }

    cout << (ans) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std ;
int main ()
{ int x,y;
    cin >>x>>y;
 while (x!=0||y!=0)
 {  if (x>y){
    x=x+y;
    y=x-y;
    x=x-y;
 }
 cout <<x<<" "<<y<<endl;
 cin >>x>>y;
 }
 return 0 ;
}





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

typedef long long ll;
typedef long double ld;
using namespace std;
mt19937_64 mrand(chrono::steady_clock::now().time_since_epoch().count());
//mt19937_64 mrand(42);
#define ii for(int i=1;i<=n;++i)
#define ji for(int j=1;j<=n;++j)
#define jj for(int j=1;j<=m;++j)
#define ij for(int i=1;i<=m;++i)
#define sz(x) ((ll)x.size())
#define all(x) x.begin(),x.end()
#define al(x) x+1,x+1+n
#define asd cout<<"ok"<<endl;
#define asdd cout<<"okok"<<endl;
#define pii pair<int,int>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vii vector<pair<int,int>>
#define pr(v) for(auto i:v) cout<<i<<" ";cout<<endl
#define prt(a, l, r) for(auto i=l;i<=r;++i) cout<<a[i]<<" ";cout<<endl;
#define pc(x) __builtin_popcount(x)
#define pb push_back

int main() {
    int a;
    cin>>a;
    cout<<a+a*a+a*a*a<<endl;
}

Measured memory_bytes: 3552
o = input()
e = input()
s = ""
for i in range(len(o)):
	s = s + o[i]
	if i == len(o)-1:
		if len(o) - len(e) == 1:
			break
		else:
			s = s + e[i]
	else:
		s = s + e[i]
print(s)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define T int t;cin>>t;while(t--)
#define f(i,n) for (int i=0;i<n;i++)
#define fa(i,a,b) for (int i=a;i<b;i++)
#define b(i,a,b) for (int i=a;i>=b;i--)
#define pb push_back
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mp make_pair
#define fi first    
#define se second
#define SZ(x) ((int)(x).size())
#define debug(x) cout<<'>'<<#x<<" = "<<x<<endl;
#define MOD 1000000007
#define ce cout<<"\n"
int main()
{
    int n, i, j=0;
    string s;
    cin>>n;
    cin>>s;
    for(i=0; i<n-2; i++)
    {
        if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C')
            j++;
    }
    cout<<j<<'\n';
    return 0;
}

Measured memory_bytes: 256
use proconio::input;

fn main() {
    input! { n: usize }
    let mut a = vec![0; n];
    let mut ac = vec![0; 1000_000 + 1];
    let mut ma = 0;
    for i in 0..n {
        input! { ai: usize }
        a[i] = ai;
        ac[ai] += 1;
        ma = ma.max(ai);
    }

    let mut pc = true;
    for i in 2..=ma {
        let mut c = 0;
        for j in (0..=ma).skip(i).step_by(i) {
            c += ac[j];
        }
        if c > 1 {
            pc = false;
            break;
        }
    }

    println!("{} coprime", if pc {
        "pairwise"
    } else {
        let mut v = a[0];
        for i in 1..n {
            v = num_integer::gcd(v, a[i]);
        }
        if v == 1 {
            "setwise"
        } else {
            "not"
        }
    });
}


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

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

using namespace std;

class mint{
	static const int MOD=1e9+7;
	int x;
public:
	mint():x(0){}
	mint(long long y){ x=y%MOD; if(x<0) x+=MOD; }

	mint& operator+=(const mint& m){ x+=m.x; if(x>=MOD) x-=MOD; return *this; }
	mint& operator-=(const mint& m){ x-=m.x; if(x<   0) x+=MOD; return *this; }
	mint& operator*=(const mint& m){ x=1LL*x*m.x%MOD; return *this; }
	mint& operator/=(const mint& m){ return *this*=inverse(m); }
	mint operator+(const mint& m)const{ return mint(*this)+=m; }
	mint operator-(const mint& m)const{ return mint(*this)-=m; }
	mint operator*(const mint& m)const{ return mint(*this)*=m; }
	mint operator/(const mint& m)const{ return mint(*this)/=m; }

	friend mint inverse(const mint& m){
		int a=m.x,b=MOD,u=1,v=0;
		while(b>0){ int t=a/b; a-=t*b; swap(a,b); u-=t*v; swap(u,v); }
		return u;
	}

	friend istream& operator>>(istream& is,mint& m){ long long t; is>>t; m=mint(t); return is; }
	friend ostream& operator<<(ostream& os,const mint& m){ return os<<m.x; }
	int to_int()const{ return x; }
};

mint operator*(long long y,const mint& m){ return m*y; }

mint pow(mint m,long long k){
	mint res=1;
	for(;k>0;k>>=1,m*=m) if(k&1) res*=m;
	return res;
}

mint fact(int n){
	static vector<mint> memo={1};
	if(memo.size()<=n){
		int k=memo.size();
		memo.resize(n+1);
		for(;k<=n;k++) memo[k]=memo[k-1]*k;
	}
	return memo[n];
}

mint fact_inverse(int n){
	static vector<mint> memo={1};
	if(memo.size()<=n){
		int k=memo.size();
		memo.resize(n+1);
		memo[n]=inverse(fact(n));
		for(int i=n;i>k;i--) memo[i-1]=memo[i]*i;
	}
	return memo[n];
}

mint choose(int n,int k,int type=0){
	if(k<0 || n<k) return 0;
	if(type==0){
		return fact(n)*fact_inverse(k)*fact_inverse(n-k);
	}
	else{
		if(k>n-k) k=n-k;
		mint res=fact_inverse(k);
		rep(i,k) res*=n-i;
		return res;
	}
}

mint multichoose(int n,int k,int type=0){
	return choose(n+k-1,k,type);
}

mint f(int r,int c){
	mint res=0;
	rep(i,r+1){
		res+=fact(i+c+1)*fact_inverse(i+1)*fact_inverse(c);
	}
	return res;
}

int main(){
	int r1,c1,r2,c2; scanf("%d%d%d%d",&r1,&c1,&r2,&c2);
	cout<<f(r2,c2)-f(r1-1,c2)-f(r2,c1-1)+f(r1-1,c1-1)<<'\n';
	return 0;
}


Measured memory_bytes: 20600
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
    
		// 整数の入力
		int a = sc.nextInt();
		int b = sc.nextInt();
    
		int sum = a + b;
        int sa = a - b;
        int seki = a * b;
        
        int ans = 0;
      
        if (sum > sa) {
          ans = sum > seki ? sum : seki;
        } else {
          ans = sa > seki ? sa : seki;
        }
    
		// 出力
		System.out.println(ans);
	}
}

Measured memory_bytes: 21332
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <queue>

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//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 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,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  
  int N;
  while(cin >> N, N){
	// nuse[left] = width
	map<int,int> nuse;
	nuse.insert(MP(0,1000000100));
	// use[left] = (width, id)
	map<int,PII> use;
	// idx[id] = {left_1, left_2, ...}
	map<int, VI> idx;
	REP(i,N){
	  char q; int a, b;
	  cin >> q;
	  switch(q){
	  case 'W':
		cin >> a >> b;
		while(b > 0){
		  auto it = nuse.begin();
		  int w = min(b, it->second);
		  use[it->first] = MP(w, a);
		  idx[a].PB(it->first);
		  if(it->second > b)
			nuse[it->first+b] =  it->second - b;
		  nuse.erase(it);
		  b -= w;
		}
		break;
	  case 'D':
		cin >> a;
		for(int left: idx[a]){
		  auto it = use.find(left);
		  nuse[left] = it->second.first;
		  use.erase(it);
		}
		idx[a].clear();
		break;
	  case 'R':
		cin >> a;
		auto up = use.upper_bound(a);
		if(up != use.begin()) --up;
		if(up->first <= a && a < up->first + up->second.first)
		  cout << up->second.second << endl;
		else
		  cout << -1 << endl;
		  
		break;		
	  }
	}
	cout << endl;
  }
  
  return 0;
}

Measured memory_bytes: 12948
#include <iostream>
#include <string.h>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;

void b_beautiful_words(void) {
	string w;
	int cnt[26] = { 0 };
	cin >> w;
	for (int i = 0; i < w.size(); i++) {
		//cout << i;
		int index = w[i] - 'a';
		cnt[index]++;
	}
	bool beautiful = true;
	for (int i = 0; i < 26; i++) {
		if ((cnt[i] & 0x1) == 0x1) {
			beautiful = false;
			break;
		}
	}

	if (beautiful) cout << "Yes" << endl;
	else           cout << "No" << endl;
}

int main()
{
	b_beautiful_words();
    return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n,k,t,d;
    cin>>n>>k;
    vector<pair<ll,ll> > v;
    for(int i=0;i<n;i++){
    	cin>>t>>d;
    	v.pb(make_pair(d,t-1));
    }
    sort(be(v));
    reverse(be(v));
    set<ll> s;
    vector<ll> q;
    ll num=0;
    for(int i=0;i<k;i++){
    	if(s.count(v[i].second)){
    		q.pb(v[i].first);
    	}
    	s.insert(v[i].second);
    	num+=v[i].first;
    }
    t=s.size();
    vector<ll> makichan;
    for(int i=k;i<n;i++){
    	if(s.count(v[i].second)==0){
    		makichan.pb(v[i].first);
    	}
    	s.insert(v[i].second);
    }
    sort(be(q));
    reverse(be(q));
    sort(be(makichan));
    ll ans=t*t+num;
    while(!(q.empty()||makichan.empty())){
    	num-=q.back();q.pop_back();
    	num+=makichan.back();makichan.pop_back();
    	t++;
    	ans=max(ans,t*t+num);
    }
    cout << ans<<endl;
    return 0;
}

Measured memory_bytes: 6896
#include <math.h>
#include <stdio.h>
typedef long long ll;
int a[200000];
ll aSum[200000], bSum[200000];
int main() {
	int n;
	ll sum = 0, min = 1e18;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
		sum += a[i];
	}
	aSum[0] = a[0];
	bSum[0] = sum - a[0];
	for (int i = 1; i < n; i++) {
		aSum[i] += aSum[i - 1] + a[i];
		bSum[i] = sum - aSum[i];
	}
	for (int i = 0; i < n; i++) {
		if (min > llabs(aSum[i] - bSum[i])) {
			min = llabs(aSum[i] - bSum[i]);
		}
	}
	printf("%lld\n", min);
	return 0;
}

Measured memory_bytes: 4096
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

A = list(input())
A.reverse()
B = list(input())
B.reverse()
C = list(input())
C.reverse()
player = A.pop()
while 1:
    # if len(A) == 0:
    #     print("A")
    #     exit()
    # if len(B) == 0:
    #     print("B")
    #     exit()
    # if len(C) == 0:
    #     print("C")
    #     exit()
    # print(player)
    if player == "a":
        if len(A) == 0:
            print("A")
            exit()
        else:
            player = A.pop()
    elif player == "b":
        if len(B) == 0:
            print("B")
            exit()
        else:
            player = B.pop()
    elif player == "c":
        if len(C) == 0:
            print("C")
            exit()
        else:
            player = C.pop()

    

Measured memory_bytes: 5484
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<(n);i++)
#define all(t) (t).begin(),(t).end()
#define MOD 1000000007
typedef long long ll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}else{return 0;}}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}else{return 0;}}
template <class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <class T> inline T LCM(T a,T b){return a*b/GCD(a,b);}

int main(){
	ll n;
	cin >> n;
	cout << n*(n-1)/2 << endl;
}

Measured memory_bytes: 256
N, Y = map(int, input().split())
X_yen = 10000
Y_yen = 5000
Z_yen = 1000
x = y = z = -1
for a in range(N + 1):
    for b in range(N + 1 - a):
        c = N - a - b
        total = 10000*a + 5000*b + 1000*c
        if total == Y:
            x = a
            y = b
            z = c
print(x, y, z)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

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

		int N = sc.nextInt();
		int gokei = 0;
		
		for(int i=0;i<N;i++) {
			gokei+=sc.nextInt();
		}
		System.out.println(gokei-N);
		
	}
}

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

const int MAX = (int)(300 + 5);

struct Point {int x, y;};

int h, w, d;
int a[MAX][MAX];
int q;

unordered_map<int, Point> i2p;
int scand[MAX * MAX + 5];

int main(void) {
  // Here your code !
  scanf("%d %d %d", &h, &w, &d);

  for (int x = 1; x <= h; ++x) for (int y = 1; y <= w; ++y) {
    int tmp;
    scanf("%d", &tmp);
    i2p[tmp] = {x, y};
  }

  for (int i = 1; i <= d; ++i) scand[i] = 0;

  for (int i = d + 1; i <= h * w; ++i) {
    Point cur = i2p[i];
    Point last = i2p[i - d];
    scand[i] = scand[i - d] + abs(cur.x - last.x) + abs(cur.y - last.y);
  }

  scanf("%d", &q);

  for (int i = 0; i < q; ++i) {
    int l, r;
    scanf("%d %d", &l, &r);

    int ans = scand[r] - scand[l];
    printf("%d\n", ans);
  }

	return 0;
}


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

#define rep(i, a, b) for (int i = a; i < (int)(b); i++)
#define rrep(i, a, b) for (int i = b - 1; i >= int(a); i--)

using namespace std;

using ll = long long;
using vi = vector<int>;

int main() {
    int n;
    int p;
    string s;
    cin >> n >> p >> s;

    vi si(n, 0);
    rep(i, 0, n) { si[i] = int(s[i] - '0'); }

    ll sum = 0;

    if (p == 2 || p == 5) {
        rep(i, 0, n) {
            if (si[i] % p == 0) {
                sum += i + 1;
            }
        }
    } else {
        vi counter(p, 0);
        counter[0]++;

        int num = 0;
        int power = 1;

        rrep(i, 0, n) {
            num = (num + (si[i] * power) % p) % p;
            power = power * 10 % p;
            sum += counter[num];
            counter[num]++;
        }
    }

    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 1412