akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int nr1[2010][2010]; /// cate de tip 1 >= j sunt in stanga lui i de tip 2
int nr2[2010][2010];

int dp[2010][2010];

int poz1[2010];
int poz2[2010];

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

    for (int i(1); i <= 2 * n; i++) {
        char c;
        int x;
        cin >> c >> x;
        if (c == 'B')
            poz1[x] = i;
        else
            poz2[x] = i;
    }

    for (int i(1); i <= n; i++) {
        for (int j(i - 1); j >= 1; j--) {
            if (poz1[i] < poz1[j])
                nr2[j][n]++;
            if (poz2[i] < poz2[j])
                nr2[j][n]++;
        }
    }

    for (int i(1); i <= n; i++) {
        for (int j(n - 1); j >= 0; j--) {
            nr1[i][j] = nr1[i][j + 1] + (poz2[i] > poz1[j + 1]);
            nr2[i][j] = nr2[i][j + 1] + (poz1[i] > poz2[j + 1]);
        }
    }

    for (int i(0); i <= n; i++) {
        for (int j(0); j <= n; j++) {
            if (!i && !j)
                continue;
            dp[i][j] = 1e9;
            if (i) {
                int q = dp[i - 1][j];
                q += nr2[i][j];
                dp[i][j] = min(dp[i][j], q);
            }
            if (j) {
                int q = dp[i][j - 1];
                q += nr1[j][i];
                dp[i][j] = min(dp[i][j], q);
            }
        }
    }
    cout << dp[n][n] << '\n';

    return 0;
}


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ll << (b))

using namespace std;

using i32 = int;
using i64 = long long;
using u64 = unsigned long long;
using f80 = long double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vu64 = vector<u64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << '\n'; exit(0); }
inline void no() { cout << "No" << '\n'; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { return a / gcd(a, b) * b; }
inline u64 xorshift() { static u64 x = 88172645463325252ull; x = x ^ (x << 7); return x = x ^ (x >> 9); }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { if (x < y) x = y; }
template <typename T> inline void amin(T &x, T y) { if (x > y) x = y; }
template <typename T> inline T power(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
template <typename T, typename S> istream& operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
template <typename T, typename S> ostream& operator<<(ostream &os, pair<T, S> &p) { os << p.first << ' ' << p.second; return os; }

void solve() {
  int n;
  cin >> n;
  vi32 x(n), y(n);
  rep(i, n) cin >> x[i] >> y[i];
  f80 ans = 0;
  rep(i, n) rep(j, n) {
    if (i == j) continue;
    ans += sqrt(pow(x[i] - x[j], 2) + pow(y[i] - y[j], 2));
  }
  ans /= n;
  cout << ans << endl;
}


Measured memory_bytes: 256
N=int(input())
V=map(int,input().split())
C=map(int,input().split())

V = list(V)
C = list(C)

d = 0
p = 0

for i in range(N):  
  p = V[i] - C[i]
  if p > 0:
    d += p

print(d)

Measured memory_bytes: 3060
#include<iostream>

int main()
{
  int a, b, buf;
    std::cin >> a >> b;
  while(a!=0 || b!=0){
    if(a > b){
      buf=a;
      a=b;
      b=buf;
    }
    std::cout << a << ' ' << b << std::endl;
    std::cin >> a >> b;
  }
  return 0;
}



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

using namespace std;
using ll = long long;

/*
Xが1~Nあるいは1~N-1以外のカードを初手でめくったとして、もしYが「このままだと勝たれる」となったとしても、YはN-1までめくることでabs(A_N-1 - A_N)に押さえ込めるからスコアの最大値は
max(abs(w - A[N]), abs(A[N] - A[N-1]))となる。
*/

int main()
{
    int n, z, w; cin >> n >> z >> w;
    vector<int> a(n);
    for(int i = 0; i < n; i++)cin >> a[i];
    if(n == 1) {
        cout << abs(w - a.back()) << endl;
    } else {
        cout << max(abs(w - a.back()), abs(a.back() - *(a.end() - 2))) << endl;
    }

}

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

int main() {
  int N;
  string S;
  int ans = 0;

  cin >> N >> S;

  //文字列を長さの分までループして調査する
  rep(i,N-2) {
    if (S[i] =='A') {
      if (S[i+1] =='B') {
        if (S[i+2] =='C') {
          ++ans;
        }
      }
    }
  }
  cout << ans << endl;
}


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

int n, p[10], sum, Max;

int main() {
    
    cin >> n;
    rep(i, n) {
        cin >> p[i];
        sum += p[i];
        Max = max(Max, p[i]);
    }
    sum -= Max;
    sum += Max / 2;
    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 256
/******************************************
* AUTHOR : RAJAGOPALAN *
* NICK : ARNO *
* INSTITUTION : VIT *
******************************************/
#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>

#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define alli(a, n, k) (a + k), (a + n + k)
#define FP(i, a, b, k) for (__typeof(a) i = a; i < b; i += k)
#define FS(i, a, b, k) for (__typeof(a) i = a; i > b; i -= k)
#define IT(it, a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)
#define eps 1e-6
#define pi 3.141592653589793
using namespace std;
using namespace __gnu_pbds;

template <class T>
inline T gcd(T x, T y)
{
	if (!y)
		return x;
	return gcd(y, x % y);
}
typedef vector<int> VII;
typedef vector<ll> VLL;
typedef pair<int, int> PII;
typedef vector<pair<int, int>> VPII;
typedef vector<pair<int, PII>> VPPI;
const int MOD = 1e9 + 7;
const int INF = 1e9;

inline ll modulo(ll a, ll m)
{
	return (a % m + m) % m;
}

inline ll modInverse(ll a, ll m)
{
	assert(__gcd(a, m) == 1);
	ll m0 = m;
	ll y = 0, x = 1;

	if (m == 1)
		return 0;

	while (a > 1)
	{
		ll q = a / m;
		ll t = m;

		m = a % m, a = t;
		t = y;

		y = x - q * y;
		x = t;
	}

	if (x < 0)
		x += m0;

	return x;
}

inline ll modPow(ll x, ll y, ll m)
{ //x^y % m
	if (y == 0)
		return 1LL;
	else if (y == 1)
		return x;
	else
	{
		ll ans = modPow(x, y / 2, m) % m;
		if (y & 1)
		{
			return (((ans * ans) % m) * x) % m;
		}
		else
		{
			return (ans * ans) % m;
		}
	}
}

int main(int argc, char *argv[])
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	ll n,k;
	cin>>n>>k;
	 if(n<k)
	{
		cout<<min(n,abs(n-k));
	}
	else if(n==k || n%k==0)
	cout<<0;
	else{
	ll q=n/k;
	ll ma=n%k;
	
	ll aa=n-q*k;
	//cout<<aa<<' '<<q<<endl;
	cout<<min(aa,abs(aa-k));
	}

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;

int main(){
    int k;
    cin>>k;
    vector<int>a(k);
    bool flag=true;
    for(int i=0;i<=k;i++){
        if(i==0)a[i]==7%k;
        a[i]=(10*a[i-1]+7)%k;
        if(a[i]==0){
            cout<<i+1<<endl;
            flag=false;
            break;
        }
    }
    if(flag)cout<<-1<<endl;
    return 0;
}

Measured memory_bytes: 7168
h,w = map(int,input().split())
n=10
dist = [list(map(int,input().split())) for _ in range(n)]
wall = [list(map(int,input().split())) for _ in range(h)]

for k in range(n):
    for i in range(n):
        for j in range(n):
            dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])
#[print(*dist[l]) for l in range(n)]
ans = 0
for i in range(h):
    for j in range(w):
        if wall[i][j]!=-1:
            ans += dist[wall[i][j]][1]
print(ans)



Measured memory_bytes: 9372
import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
	static String[] str = {
		"eraser",
		"erase",
		"dreamer",
		"dream",
	};
	
	public static void main (String[] args) {
   	 Scanner sc = new Scanner(System.in);
   	 String S = sc.nextLine();
   	 S = S.replaceAll(str[0], "-");
   	 S = S.replaceAll(str[1], "-");
   	 S = S.replaceAll(str[2], "-");
   	 S = S.replaceAll(str[3], "-");
   	 S = S.replaceAll("-", "");
   	 if(S.length() == 0) {
   		 System.out.println("YES");
   	 } else {
   		 System.out.println("NO");   		 
   	 }
    }
}


Measured memory_bytes: 43432
import java.io.*;
import java.util.*;
import java.math.*;


public class Main {
	Scanner sc = new Scanner(System.in);

	class score implements Comparable<score>{
		int id;
		int t;
		public int compareTo(score tar){
			return t - tar.t;
		}
		
		score(Scanner sc){
			id = sc.nextInt();
			t=0;
			t += sc.nextInt()*60+sc.nextInt();
			t += sc.nextInt()*60+sc.nextInt();
			t += sc.nextInt()*60+sc.nextInt();
			t += sc.nextInt()*60+sc.nextInt();
					
		}
		
	}
	
	void run() {
		for (;;) {
			int n = sc.nextInt();
			if (n == 0) {
				break;
			}
			score s [] = new score[n];
			for (int i  = 0; i < n; i++) {
				s[i] = new score(sc);
			}
			Arrays.sort(s);
			
			System.out.println(s[0].id);
			System.out.println(s[1].id);
			System.out.println(s[n-2].id);
		}

	}

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

}

Measured memory_bytes: 13000
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
template <typename T> using ordered_set=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; //greater<T> for sorting decreasingly

#define ll         long long
#define pll        pair<ll,ll>
#define unique(a)  a.resize(unique(a.begin(), a.end()) - a.begin())
#define fill(v, p) memset(v,p,sizeof v)
#define all(x)     x.begin(), x.end()
#define at_(x,i)   x.find_by_order(i)
#define koto_(x,i) x.order_of_key(i)
#define PI         acos(-1.0)
#define EPS        0.000000001
#define INF        1LL<<62
#define MAX        300005
#define MOD        1000000007

map<ll,ll> vis, dp;

ll rec(ll h)
{
	if(h==1) return 1;
	
	if(vis[h]) return dp[h];
	
	ll p= 1+rec(h/2)+rec(h/2);
	
	vis[h]=1;
	
	return dp[h]=p;
}

signed int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(NULL); cout.tie(0);
	
	ll h;
	cin >> h;
	
	cout << rec(h) << endl;
	
	return 0;
}


Measured memory_bytes: 256
use std::collections::HashSet;
use std::io::stdin;

fn main() {
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    let mut itr = s.split_whitespace().map(|e| e.parse().unwrap());
    let n: usize = itr.next().unwrap();
    let k: usize = itr.next().unwrap();

    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    let d: HashSet<usize> = s.split_whitespace().map(|e| e.parse().unwrap()).collect();
    let mut ans = n;
    loop {
        if is_valid(ans, &d) {
            break;
        }

        ans += 1;
    }

    println!("{}", ans);
}

fn is_valid(mut ans: usize, set: &HashSet<usize>) -> bool {
    while ans > 0 {
        let t = &(ans % 10);
        if set.contains(t) {
            return false;
        }

        ans /= 10;
    }

    true
}


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

int gcd(int x, int y)
{
    if (x > y) swap(x, y);
    if (y % x == 0) return x;
    else return gcd(x, y % x);
}

int main()
{
    int n, x;
    cin >> n >> x;

    vector<int> city;
    city.push_back(0);
    rep(i, 0, n)
    {
        int c;
        cin >> c;
        city.push_back(c - x);
    }

    sort(city.begin(), city.end());

    vector<int> dis;
    rep(i, 0, city.size() - 1)
    if (city[i + 1] != city[i])
        dis.push_back(city[i + 1] - city[i]);
    
    int ans;
    if (dis.size() == 0)
        ans = 0;
    else
    {
        ans = dis[0];
        rep(i, 0, dis.size())
            ans = gcd(ans, dis[i]);
    }
    cout << ans << endl;
    return 0;
}

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

int main()
{
	int n;

	while(true){
		
		int count = 0;

		cin >> n;

		if(n==0)
			break;

		for(int i=0 ;n!=1 ;i++){

			if(n%2 == 0){
				n = n / 2;
	
				count++;
			}
			else if(n%2 != 0){
				n = n * 3 + 1;
			
				count++;
			}
		}

		cout << count << endl;

	}
	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>

#define N_MAX 10000

char is_sosuu[N_MAX+1];

void make_sosuu_list(void) {
	int i,j;
	for(i=0;i<=N_MAX;i++)is_sosuu[i]=1;
	is_sosuu[0]=is_sosuu[1]=0;
	for(i=2;i<=N_MAX;i++) {
		if(is_sosuu[i]) {
			for(j=i+i;j<=N_MAX;j+=i)is_sosuu[j]=0;
		}
	}
}

int main(void) {
	int query;
	int i;
	int result;
	make_sosuu_list();
	while(scanf("%d",&query)==1) {
		result=0;
		for(i=1;i<=query;i++) {
			if(is_sosuu[i] && is_sosuu[query-i+1])result++;
		}
		printf("%d\n",result);
	}
	return 0;
}

Measured memory_bytes: 0
#include<stdio.h>

#define N 100001
#define NIL -1


struct Node{ 
  int p,left,right,deg,dep,s,h;
};

struct Node T[N];

int depth(int );
int height(int, int);
void print(int );
void print_node(int );

int count,n;

main(){
  int i,j;
  int id=0;
  int c=0;
  int left=0,right=0;

  n =0;
  
  scanf("%d",&n);
  if(n < 1 || N < n) return 0;
  
  for (i=0;i < n;i++){
    T[i].left = NIL; 
    T[i].right = NIL;
    T[i].p = NIL;
    T[i].s = NIL;
  }
  
  for (i=0;i < n;i++){
    c=0;
    scanf("%d %d %d",&id,&left,&right);

    T[id].left = left;
    T[id].right = right;

    T[left].p = id;
    T[left].s = right;

    T[right].p = id;
    T[right].s = left;

    if(left == NIL){
      c++;
    } 
    if(right == NIL){
      c++;
    }

    if(c == 0){
      T[id].deg = 2;
    }
    else if(c == 1){
      T[id].deg = 1;
    }
    else{
      T[id].deg = 0;
    }
  }
 
  for(i=0;i < n; i++){
    count = 0;

    T[i].dep  = depth(T[i].p);
    T[i].h = height(i,0);
  }

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

  return 0;
}

int depth(int i){

  if(i == NIL){
    return count;
  }

  else{
    count++;
    return depth(T[i].p);
  }
}

int height(int h, int c){
  int a=0;
  int b=0;
  
  if(T[h].right != NIL){
    a = height(T[h].right, c+1);
  }
  
  if(T[h].left != NIL){
    b = height(T[h].left, c+1);
  } 
  
  if(T[h].left == NIL && T[h].right == NIL){
    return c;
  }
  
  if(a >= b){
    return a;
  }
  return b;  
}

void print(int i){

  printf("node %d:", i);
  printf(" parent = %d,", T[i].p);
  printf(" sibling = %d,", T[i].s);
  printf(" degree = %d,", T[i].deg);
  printf(" depth = %d,", T[i].dep);
  printf(" height = %d,", T[i].h);
  print_node(i);
  printf("\n");
}


void print_node(int i){

  if(T[i].p == NIL){
    printf(" root");
  }
  
  else if(T[i].deg == 0){
    printf(" leaf");
  }

  else{
    printf(" internal node");
  }
}

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

int main()
{
	int i, N, a[51];
	scanf("%d", &N);
	for (i = 1; i <= N; i++) scanf("%d", &(a[i]));
	
	int max = -10000000, min = 10000000, argmax, argmin;
	for (i = 1; i <= N; i++) {
		if (a[i] < min) {
			min = a[i];
			argmin = i;
		}
		if (a[i] > max) {
			max = a[i];
			argmax = i;
		}
	}
	
	if (max <= 0) {
		if (min == 0) printf("0\n");
		else {
			printf("%d\n", N);
			printf("%d %d\n", argmin, N);
			for (i = N - 1; i >= 1; i--) printf("%d %d\n", i + 1, i);
		}
	} else if (min >= 0) {
		printf("%d\n", N);
		printf("%d %d\n", argmax, 1);
		for (i = 1; i <= N - 1; i++) printf("%d %d\n", i, i + 1);
	} else if (max >= abs(min)) {
		printf("%d\n", N * 2);
		printf("%d %d\n%d %d\n", argmax, 1, argmax, 1);
		for (i = 1; i <= N - 1; i++) printf("%d %d\n%d %d\n", i, i + 1, i, i + 1);
	} else {
		printf("%d\n", N * 2);
		printf("%d %d\n%d %d\n", argmin, N, argmin, N);
		for (i = N - 1; i >= 1; i--) printf("%d %d\n%d %d\n", i + 1, i, i + 1, i);
	}	
	fflush(stdout);
	return 0;
}

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

int main () {
  int a, b, c;
  cin >> a >> b >> c;
  set<int> box;
  int now = a;
  for (int i = 1; i <= c; i++) {
    if (now > b) {
      break;
    }
    if (!box.count(now)) {
      cout << now << endl;
    }
    box.insert(now);
    now++;
  }
  now = b - c + 1;
  now = (now >= a) ? now : a;
  for (int i = 1; i <= c; i++) {
    if (now > b) {
      break;
    }
    if (!box.count(now)) {
      cout << now << endl;
    }
    box.insert(now);
    now++;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 1e5 + 10;

int main() {
    ios::sync_with_stdio(false);
    cout.tie(0), cin.tie(0);
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll x = a * c, y = a * d, p = b * c, q = b * d;
    cout << max(x, max(y, max(p, q))) << endl;
    return 0;
}


Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
#define stop exit(0)
int main(){
    vector <long long> v;
    long long a,b,c=0,d=0,e=0,f=0,g=0,i,j,k=1,l=0,r=1,n,m,z,h,p[10001];
    string s,t,x,y;
    double q,u,w;
    cin>>a>>s;
    if(s.size()>a){
        for(i=0;i<a;i++){
            cout<<s[i];
        }
        cout<<"...";
    }
    else{
        cout<<s;
    }
}

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

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

#include<algorithm>

using namespace std;
typedef long long ll;

ll kaisu(ll a){
  if(a > 1){
    return 2*kaisu(a/2)+1;
  }else{
    return 1;
  }
}

int main() {
  ll N;
  cin >> N;
  cout << kaisu(N) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include<math.h>
#include<iomanip>
#include<functional>
using namespace std;

#define ll long long
using vt = ll; //ここで数値の型を変えられる
#define rep(i, n) for (vt i = 0; i < (vt)(n); i++)
#define reps(i, s, n) for(vt i = (vt) (s); i < (vt) (n); i++) 
#define all(v) v.begin(), v.end()
#define P pair<int, int>
const ll  MOD = 1000000007;

int main() {
	ll n;
	cin >> n;
	vector<ll> a(n);
	rep(i, n) cin >> a.at(i);
	priority_queue<ll> b;
	rep(i, n) b.push(a.at(i));
	ll x, y;
	x = b.top(); b.pop();
	y = b.top(); b.pop();
	rep(i, n) {
		if (a.at(i) == x) cout << y << endl;
		else cout << x << endl;
	}
	return 0;
}

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

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

int N,K,S,T;
int A[51];

ll C[55][55];

int dp[1<<18];
ll dp2[1<<18];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	FOR(i,52) for(j=0;j<=i;j++) C[i][j]=(j==0||j==i)?1:(C[i-1][j-1]+C[i-1][j]);

	
	cin>>N>>K>>S>>T;
	
	if(S&~T) return _P("0\n");
	
	FOR(i,N) {
		cin>>A[i];
		if((A[i]&~T) ||(A[i]&S)!=S) {
			i--;
			N--;
			continue;
		}
	}
	
	int mask;
	int U=T&(~S);
	FOR(mask,1<<18) if((mask&U)==mask) {
		FOR(i,N) dp[A[i]&mask]++;
		FOR(i,N) if(dp[A[i]&mask]) {
			for(j=1;j<=min(K,dp[A[i]&mask]);j++) dp2[mask]+=C[dp[A[i]&mask]][j];
			dp[A[i]&mask]=0;
		}
	}
	
	ll ret=0;
	FOR(mask,1<<18) {
		if(__builtin_popcount(mask)%2) ret-=dp2[mask];
		else ret+=dp2[mask];
	}
	
	
	cout<<ret<<endl;
	
}


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


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

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int z = static_cast<int>('Z');
  for (char c : s) {
    cout << static_cast<char>(c + n > z ? c + n - 26 : c + n);
  }
  cout << endl;
}


Measured memory_bytes: 256
//  Author : Fuad Ashraful Mehmet ,University of Asia Pacific
// https://codeforces.com/contest/1370/problem/D
#include<bits/stdc++.h>
using namespace std;

void HalfDead()
{
    char c;
    cin>>c;
    if(isupper(c))
    {
        cout<<"A"<<endl;
    }
    else cout<<"a"<<endl;
}
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(nullptr);
    int tc=1; 
    //cin>>tc;
    while(tc--)HalfDead();
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int H,W;

int ans[111][111];

signed main(){
    cin>>H>>W;
    int N;cin>>N;

    int y=0,x=0;

    rep(k,N){
        int a;cin>>a;

        rep(beet,a){
            ans[y][x]=k+1;
            if(y%2==0){
                if(x+1!=W)x++;
                else y++;
            }
            else{
                if(x!=0)x--;
                else y++;
            }
        }
    }

    rep(i,H){
        rep(j,W){
            if(j)cout<<" ";
            cout<<ans[i][j];
        }cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
typedef long long ll;
const int maxn=2e5+9;
const int mod=1e9+7;
const double ep=1e-7;
using namespace std;
int main()
{
	ll n,k,sum[maxn]={0};
	scanf("%lld%lld",&n,&k);
	for(int i=1;i<=n;i++)sum[i+1]=sum[i]+i;
	ll ans=0;
	for(int i=k;i<=n+1;i++)
	{
		ans=(ans+(sum[n+1]-sum[n+1-i]-sum[i]+1))%mod;
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 5400
#include<bits/stdc++.h>
using namespace std;
#define _ ios::sync_with_stdio(false);cin.tie(0);
#define __ cout<<fixed;cout<<setprecision(10);
#define int long long
#define fori(a,b) for(int i = a ; i < b ; i++)
#define forj(a,b) for(int j = a ; j < b ; j++)

void solve() {
	int n, k;
	cin >> n >> k;
	int arr[n];
	fori(0, n) {
		cin >> arr[i];
	}
	fori(k, n) {
		if (arr[i] > arr[i - k]) {
			cout << "Yes\n";
		}
		else {
			cout << "No\n";
		}
	}
}

int32_t main() {
	_ __
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int t = 1;
	//cin >> t;
	while (t--) {
		solve();
	}

#ifndef ONLINE_JUDGE
	cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s.\n";
#endif

	return 0;
}

Measured memory_bytes: 5184
from itertools import permutations, combinations


def solve(string):
    n, a, b, c, *l = map(int, string.split())
    ans = 3000
    for _l in permutations(l):
        for i, j, k in combinations(range(1, len(l) + 1), 3):
            tmp = 10 * (i - 1) + abs(a - sum(_l[:i])) + 10 * (j - i - 1) + abs(
                b - sum(_l[i:j])) + 10 * (k - j - 1) + abs(c - sum(_l[j:k]))
            if tmp < ans:
                ans = tmp
    return str(ans)


if __name__ == '__main__':
    n, a, b, c = map(int, input().split())
    print(solve('{} {} {} {}\n'.format(n, a, b, c) + '\n'.join([input() for _ in range(n)])))


Measured memory_bytes: 72536
n,m=map(int,input().split())
A=[]
B=[]
for i in range(n):
    A.append(list(map(int,input().split(' '))))
for j in range(m):
    b=int(input())
    B.append(b)    
for l in A:
    a=0
    i=0
    for o in l:
        a+=o*B[i]
        i+=1
    print(a)   


Measured memory_bytes: 6016
#include<bits/stdc++.h>
using namespace std;
int div(vector<int> &cont , int x){
  
  int l = 0;
  int h = cont.size()-1;
  
  while(l < h){
    int mid = (l+h)/2;
    if(cont.at(mid) < x){
      l = mid + 1;
    }
    else{
      h = mid - 1;
    }
  }
  
  if(cont.at(l) < x){
    return h;
  }
  else if(cont.at(l) == x){
    return l-1;
  }
  else{
    if(cont.at(l-1) == x){
      int i = l;
      while(cont.at(i) >= x){
        i--;
      }
      return i;
    }
  }
}

int main(){
  int n;
  cin >> n;
  
  vector<int> cont(n);

  for(int i = 0 ; i < n ; i++){
    cin >> cont.at(i);
  }
  
  sort(cont.begin() , cont.end());
  
  int ans = 0;
  for(int i = 0 ; i < n-2 ; i++){
    int a = cont.at(i);
    for(int j = i+1 ; j < n-1 ; j++){
      int b = cont.at(j);
      
      int c = div(cont,a+b);
      ans += c - j;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<functional>
#include<vector>
typedef long long ll;
using namespace std;
int main(){
  int x,y,z,k,cnt=0;
  scanf("%d%d%d%d",&x,&y,&z,&k);
  ll a[x],b[y],c[z];
  vector<ll> ab_sum,ans;
  for(int i=0;i<x;i++){
    scanf("%lld",a+i);
  }
  for(int i=0;i<y;i++){
    scanf("%lld",b+i);
  }
  for(int i=0;i<z;i++){
    scanf("%lld",c+i);
  }
  for(int i=0;i<x;i++){
    for(int j=0;j<y;j++){
      ab_sum.push_back(a[i]+b[j]);
    }
  }
  sort(ab_sum.begin(),ab_sum.end(),greater<ll>());
  for(int i=0;i<k&&i<x*y;i++){
    for(int j=0;j<k&&j<z;j++){
      ans.push_back(ab_sum[i]+c[j]);
    }
  }
  sort(ans.begin(),ans.end(),greater<ll>());
  for(int i=0;i<k;i++){
    printf("%lld\n",ans[i]);
  }
}


Measured memory_bytes: 43236
#include<iostream>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip>//setprecision
#include<math.h>
#include <functional>
#include<climits>
using namespace std;
#define ll  long long 
#define rep(i, n)        for(ll i=0; i<(ll)(n); ++i)
#define mod 1000000007
  vector<ll>to[1000005];
   ll dp[2000000];
 int gcd(int a, int b)
{
  if (a%b == 0)
{
return(b);
}
else
{
return(gcd(b,a%b));
}
}
int main(){
  ll a,b,c;cin>>a>>b>>c;
  if(a+b+c>=22)cout<<"bust";
  else cout<<"win";
}



Measured memory_bytes: 27088
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
typedef long long int64;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
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 (a > b) { a = b; return 1; } return 0; }
int dx[] = { 0, 0, -1, 1 };
int dy[] = { 1, -1, 0, 0 };

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

	string str;
	cin >> str;
	if (str.at(2) == str.at(3) && str.at(4) == str.at(5)) {
		Yes;
	}
	No;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
 
int main(void){
    long n, count=-1, old=-1, new;
    scanf("%ld", &n);
    for(long i=0; i<n; i++){
        scanf("%ld", &new);
        long d = new-old;
        if(d>=2){
            puts("-1");
            return 0;
        }else if(d==1){
            count++;
        }else{
            count += new;
        }
        old = new;
    }
    printf("%ld\n", count);
    return 0;
}


Measured memory_bytes: 128
N,M = list(map(int, input().split()))
S,C,uniques=[],[],[]

if N==1:
    ans=['0']
elif N==2:
    ans=['1','0']
elif N==3:
    ans=['1','0','0']


for _ in range(M):
    s,c = list(map(int, input().split()))
    S.append(s)
    C.append(c)
    uniques.append(str(s)+str(c))
    ans[s-1]=str(c)

#左に同じ値が入っている
if len(S)!=len(list(set(S))):
    #組み合わせが違う値の数が左に同じ値が入ってる数と合ってない
    if len(list(set(uniques)))!=len(list(set(S))):
        ans='-1'

if ans[0]=='0' and len(ans)!=1:
    # print('a')
    ans='-1'

if type(ans)==str:
    print(int(ans))
else:
    print(int(''.join(ans)))

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　 |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/






int a, b, N;
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> a >> b >> N; b--;
    rep(i, 0, N) {
        int s, f; cin >> s >> f; f--;
        if (b < s) continue;
        if (f < a) continue;
        printf("1\n");
        return;
    }
    printf("0\n");
    return;
}


Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
int main() {
    int H, W;
    for(;;) {
        cin >> H >> W;
        if(H == 0 && W == 0) break;
        for(int i = 0; i < H; i++) {
            for(int j = 0; j < W; j++) {
                if(i == 0 || i == H-1) cout << "#";
                else {
                    if(j == 0 || j == W-1) cout << "#";
                    else cout << ".";
                }
            }
            cout << endl;
        }
        cout << endl;
    }
}


Measured memory_bytes: 3048
# Code for A - Poor
# Use input() to fetch data from STDIN
[a, b, c] = [int(x) for x in input().split()]

x = False
if a == b or b == c or c == a:
    x = True

y = False
if a != b or b != c or c != a:
    y = True

if x and y:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 2940
n, m = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]
a = sorted(a, key=lambda x: x[0])
k = 0
i = 0
ans = 0
while(True):
    if m - k > a[i][1]:
        ans += a[i][0] * a[i][1]
        k += a[i][1]
        i += 1
    else:
        ans += a[i][0] * (m - k)
        break
print(ans)


Measured memory_bytes: 29792
n = int(input())
a = list(map(int, input().split()))

ans = [0] * n
for i in range(n-1, -1, -1):
    cnt = 0
    for j in range(i, n, i+1):
        cnt += ans[j]
    if cnt % 2 != a[i]:
        ans[i] = 1

print(sum(ans))
print(' '.join(str(i+1) for i in range(n) if ans[i]))


Measured memory_bytes: 14780
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public void main() {
        Scanner sc = new Scanner(new InputStreamReader(System.in));

        char a = Character.toUpperCase(sc.next().charAt(0));
        char b = Character.toUpperCase(sc.next().charAt(0));
        char c = Character.toUpperCase(sc.next().charAt(0));

        println("" + a + b + c);
    }

    public void print(Object o) {
        System.out.print(o);
    }

    public void println(Object o) {
        System.out.println(o);
    }

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


Measured memory_bytes: 21844
(defun read-record(N ht)
  (dotimes (x N)
    (let ((str (read)))
      (let ((h (gethash str ht)))
	(setf (gethash str ht) (if h (1+ h) 1))))))


(defun ht2alist (table)
  (let ((alist nil))
    (maphash (lambda (k v) (push (cons k v) alist))
	     table)
    alist))


(let ((ht (make-hash-table :test #'equal)) alist)
  (read-record (read) ht)
  (setq alist (sort (ht2alist ht) #'> :key #'cdr))
  (setq alist (remove-if (lambda (x) (< (cdr x) (cdr (car alist)))) alist))
  (setq alist (sort (mapcar 'car alist) #'string<))
 
  (format t "~{~A~^~%~}" (mapcar 'string-downcase alist)))


Measured memory_bytes: 114660
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int k, t;
int a[110];

int solve() {
    priority_queue<int> que;
    for (int i = 0; i < t; i++) que.push(a[i]);
    int p0, q0;
    p0 = que.top(); que.pop();
    p0--;
    while (!que.empty()) {
        q0 = que.top(); que.pop();
        q0--;
        if (p0 > 0)
            que.push(p0);
        p0 = q0;
    }
    return p0;
}

void input() {
    cin >> k >> t;
    for (int i = 0; i < t; i++) cin >> a[i];
}

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

    input();
    cout << solve() << endl;
}

Measured memory_bytes: 256
from collections import deque

def dfs(r: int, c: int) -> None:
	S = deque()
	S.append(r)
	color[r] = c
	while S:
		u = S.pop()
		for v in G[u]:
			if color[v] == None:
				color[v] = c
				S.append(v)

def assignColor():
	id: int = 1
	for u in range(n):
		if color[u] == None:
			dfs(u, id)
			id += 1


if __name__ == "__main__":
	n, m = map(int, input().split())
	G = [[] for _ in range(n)]
	for _ in range(m):
		u, v = map(int, input().split())
		G[u].append(v)
		G[v].append(u)
	color = [None for _ in range(n)]
	assignColor()
	q = int(input())
	for _ in range(q):
		u, v = map(int, input().split())
		if color[u] == color[v]:
			print("yes")
		else:
			print("no")


Measured memory_bytes: 23556
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
using namespace std;
typedef long long ll;
typedef string str;

int main(){
  int n; cin >> n;
  str s; cin >> s;
  str ans = s;
  int balance = 0;
  REP(i,n){
    balance += (s[i]=='(') ? 1: -1;
    if(balance<0){
      ans = '(' + ans;
      balance++;
    }
  }
  REP(i,balance){
    ans = ans + ')';
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN=100000;
const int MOD=998244353;
const char CHARS[3]={'R','G','B'};

int n;
char s[3*MAXN+1];

int prefsum[3*MAXN+1][3];
int bal[3*MAXN+1];
char kind[3*MAXN+1];

int cnt1[3],cnt2[3];

int solve() {
	REP(j,3) prefsum[0][j]=0;
	REP(i,3*n) REP(j,3) prefsum[i+1][j]=prefsum[i][j]+(s[i]==CHARS[j]?1:0);
	REPE(i,3*n) { int mn=INT_MAX,mx=INT_MIN; REP(j,3) mn=min(mn,prefsum[i][j]),mx=max(mx,prefsum[i][j]); bal[i]=mx-mn; }
	//printf("bal:"); REPE(i,3*n) printf(" %d",bal[i]); puts("");
	REP(i,3*n) { int a=bal[i],b=bal[i+1]; assert(abs(a-b)<=1); kind[i]=a<b?'L':a>b?'R':'M'; } kind[3*n]='\0';
	//printf("kind: %s\n",kind);
	REP(j,3) cnt1[j]=cnt2[j]=0;
	int ret=1;
	REP(i,3*n) {
		int x=-1; REP(j,3) if(s[i]==CHARS[j]) x=j; assert(x!=-1); int y=0; while(y==x) ++y; int z=0; while(z==y||z==x) ++z;
		if(kind[i]=='L') ++cnt1[x];
		if(kind[i]=='M') { if(cnt1[y]==0) swap(y,z); assert(cnt1[y]>0&&cnt1[z]==0); ret=(ll)ret*cnt1[y]%MOD; --cnt1[y],++cnt2[z]; }
		if(kind[i]=='R') { assert(cnt2[x]>0); ret=(ll)ret*cnt2[x]%MOD; --cnt2[x]; }
	}
	REP(j,3) assert(cnt1[j]==0&&cnt2[j]==0);
	FORE(i,1,n) ret=(ll)ret*i%MOD;
	return ret;
}

void run() {
	scanf("%d",&n);
	scanf("%s",s); assert(strlen(s)==3*n);
	printf("%d\n",solve());
}

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


Measured memory_bytes: 5504
import java.math.BigDecimal;
import java.util.Scanner;

class Main {

	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int x = scan.nextInt();
		int y = scan.nextInt();
		double f = 1.0 * x / y;
		BigDecimal g = new BigDecimal(f);
		g = g.setScale(5,BigDecimal.ROUND_HALF_UP);
		System.out.printf(x/y + " " + x%y + " " + "%.5f",g);
	}
}

Measured memory_bytes: 26620
import java.io.*;
import java.util.*;
import java.util.function.BinaryOperator;
import java.util.function.LongBinaryOperator;

public class Main {

    public static void main(final String[] args) throws Exception {
        final Scanner sc = new Scanner(System.in);
        int N;
        N = sc.nextInt();
        int K;
        K = sc.nextInt();
        int[] V = new int[(N)];
        for(int i = 0 ; i < N ; i++){
                V[i] = sc.nextInt();
        }

        final Solver solver = new Solver();
        solver.solve(N, K, V);
    }
}

class Solver {
    public void solve(int N, int K, int[] V) {
        final int MIN = Math.min(N, K);

        int max = 0;

        for (int A = 0; A <= MIN; A++) {
            for (int B = 0; (A + B) <= MIN; B++) {
                int D = K - (A + B);

                final PriorityQueue<Integer> points = new PriorityQueue<>();
                for (int i = 0; i < A; i++) points.add(V[i]);
                for (int i = 0; i < B; i++) points.add(V[(N - 1) - i]);
                for (int i = 0; i < D; i++) {
                    if (points.peek() == null) break;
                    if (points.peek() < 0) points.poll();
                }

                max = Math.max(max, points.stream().reduce(0, Integer::sum));
            }
        }

        System.out.println(max);
    }
}



Measured memory_bytes: 30676
import java.util.*;
import java.lang.*;
import java.io.*;

class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		String nl = System.getProperty("line.separator");
		StringBuilder p = new StringBuilder(500);
		StringBuilder d = new StringBuilder(".");
		StringBuilder s = new StringBuilder("#");
		StringBuilder k = new StringBuilder(100);
		Scanner r = new Scanner(System.in);
		int h, w, i, ww;
		String u;
		for (i = 0; i < 4; ++i) {
			d.append(d);
			s.append(s);
		}
		ww = d.length();
		while ((h = r.nextInt()) + (w = r.nextInt()) != 0) {
			while (w > ww) {
				d.append(d);
				s.append(s);
				ww += ww;
			}
			p.append(u = s.substring(0,w));
			p.append(nl);
			k.setLength(0);
			k.append('#');
			k.append(d.substring(2, w));
			k.append('#');
			k.append(nl);
			for (i = h - 2; i > 0; --i) {
				p.append(k);
			}
			p.append(u);
			p.append(nl);
			p.append(nl);
		}
		System.out.print(p);
	}
}

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

#define dump(x) cout << (x) << '\n'
#define Int int64_t
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
 
Int INF = 1e18;
int inf = 1e9;
Int mod = 1e9+7;

int main() {
    Int n;
    cin >> n;
    vector<Int> c(n);
    for (Int i = 0; i < n; i++) {
        cin >> c[i];
    }
    sort(all(c));
    vector<Int> b(n + 1);
    b[0] = 1;
    for (Int i = 0; i < n; i++) {
        b[i + 1] = b[i] * 2 % mod;
    }
    Int res = 0;
    for (Int i = 0; i < n; i++) {
        Int r = n - (i + 1);
        Int cnt = b[r];
        if (r - 1 >= 0) {
            cnt += r * b[r - 1];
            cnt %= mod;
        }
        Int add = b[i] * cnt % mod;
        add = add * c[i] % mod;
        res += add;
        res %= mod;
    }
    dump(res * b[n] % mod);
    return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pi;
pi red[100], blue[100];
int table[100][100];
bool used[100];
bool custom(pi l, pi r) {
    if (l.first == r.first) return l.second > r.second;
    else return l.first < r.first;
}
int main() {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        int x, y;
        scanf("%d%d", &x, &y);
        red[i] = pi(x, y);
    }
    for (int i = 0; i < n; i++) {
        int x, y;
        scanf("%d%d", &x, &y);
        blue[i] = pi(x, y);
    }
    int res = 0;
    vector<pi> xdata, ydata;
    for (int i = 0; i < n; i++) {
        int cnt = 0;
        for (int j = 0; j < n; j++) {
            if (red[i].first < blue[j].first && red[i].second < blue[j].second) table[i][j] = 1;
            cnt += table[i][j];
        }
        xdata.push_back(pi(cnt, i));
    }
    for (int j = 0; j < n; j++) {
        int cnt = 0;
        for (int i = 0; i < n; i++) cnt += table[i][j];
        ydata.push_back(pi(cnt, j));
    }
    sort(xdata.begin(), xdata.end());
    sort(ydata.begin(), ydata.end());
    for (int i = 0; i < n; i++) {
        int xpos = xdata[i].second;
        for (int j = 0; j < n; j++) {
            int ypos = ydata[j].second;
            if (!used[ypos] && table[xpos][ypos] == 1) {
                used[ypos] = true;
                res++;
                break;
            }
        }
    }
    sort(ydata.begin(), ydata.end(), custom);
    for (int i = 0; i < n; i++) used[i] = false;
    int res2 = 0;
    for (int i = 0; i < n; i++) {
        int xpos = xdata[i].second;
        for (int j = 0; j < n; j++) {
            int ypos = ydata[j].second;
            if (!used[ypos] && table[xpos][ypos] == 1) {
                used[ypos] = true;
                res2++;
                break;
            }
        }
    }
    printf("%d\n", max(res, res2));
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <climits>
#include <bitset>
#include <list>
#include <map>
#include <set>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int num[]={0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
string s[10010];

int main(){
	int n, m;
	cin >> n >> m;
	int a[m];
	for(int i=0; i<m; i++) cin >> a[i];
	for(int i=0; i<=1010; i++) s[i]="0";
	s[0]="";

	for(int i=0; i<=n; i++){
		for(int j=0; j<m; j++){
			if(s[i]=="0") continue;

			string t=s[i]+to_string(a[j]);
			int k=i+num[a[j]];
			if(s[k]=="") s[k]=t;
			else if(s[k].length()==t.length()){
				s[k]=max(s[k], t);
			}else if(s[k].length()<t.length()){
				s[k]=t;
			}
		}
	}
	cout << s[n] << endl;
	return 0;
}

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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFやMODの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const ll MOD = 1000000007;

int main() {
  ll N, A, B;
  cin >> N >> A >> B;
  ll ans = 0;
  if ((B - A) % 2) {
    if (A - 1 < N - B) {
      ans += A - 1;
      B -= A - 1;
      A = 1;
      if ((B - A) % 2) {
        ans++;
        B--;
      }
    } else {
      ans += (N - B);
      A += (N - B);
      B = N;
      if ((B - A) % 2) {
        ans++;
        A++;
      }
    }
  }

  ans += B - (B + A) / 2;

  cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

/**
 *
 * @author lenovo
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        StringBuffer ans = new StringBuffer();
        
        
        for (int i=0;i<str.length();i++){
            if (i % 2 == 0){
                ans.append(str.substring(i, i+1));
            }
        }
        
        System.out.println(ans);
    }
    
}


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

using namespace std;

#define int long long

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

const int IINF =  0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const int INF = sizeof(int) == sizeof(long long) ? LINF : IINF;
const ll MOD = 1e9+7;

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

#define rep(i,n) for_(i,0,n)
#define rrep(i,n) rfor_(i,0,n)

#define pb push_back
//#define eb emplace_back
#define mp make_pair
#define ft first
#define sd second

#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define rev(a) reverse(all(a))

#define endl '\n'

const int limit = 100007;

int A, B, C, D, E, F;

bool w[32], s[3002];

int rw=1, rs;

signed main(){
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(false);
  
  cin>>A>>B>>C>>D>>E>>F;
	
	rep(i, 31) {
		if( A*i*100 > F )break;
		rep(j, 31) {
			if( (A*i+B*j)*100 > F )break;
			w[A*i+B*j] = true;
		}
	}
  
	
	rep(i, F+1) {
		if( C*i > F )break;
		rep(j, F+1) {
			if( C*i+D*j > F )break;
			s[C*i+D*j] = true;
		}
	}
	
	rep(i, 31) {
		if(i*100>F)break;
		if(!w[i])continue;
		
		rrep(j, F-i*100+1) {
			if( j<=i*E && s[j] ) {
				if( rs*(i+j) < j*(rs+rw) ) {
					rw = i;
					rs = j;
				}
				break;
			}
		}
		
	}
	
	if(rw==1)rw = A;
	
	cout << rw*100+rs << ' ' << rs << endl;
	
  return 0;
}


Measured memory_bytes: 256