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

using namespace std;

int main() {
    string s;

    cin >> s;

    if (s.size() == 1) {
        cout << 0 << endl;
        return 0;
    }

    int a = 0, b = 0;

    for (int i = 0; i < s.size(); i++) {
        if (s[i] - '0' == i % 2)
            a++;
        else
            b++;
    }

    if (a < b)
        cout << a << endl;
    else
        cout << b << endl;

    return 0;
}



Measured memory_bytes: 512
#include <stdio.h>
#include <iostream>
using namespace std;

int N,M,X,A, sum1,sum2;
int toll [101];
int main (){
cin >> N >> M >>X;
	for (int i=1; i<=M; i++){
		cin>>A;	
		toll[A]=1;
	}
	for (int i=0; i<=X; i++){
		sum1= sum1 + toll[i];
	}for (int j=X+1; j<=N; j++){
		sum2= sum2 + toll[j];
	}
	if (sum2>sum1){
		cout <<sum1;
	}else {
		cout<<sum2;
	}
}

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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,a;cin >> n >> a;
	vector<ll> x(n);
	rep(i,n) cin >> x.at(i);
	ll dp[51][51][3000];
	dp[0][0][0]=1;
	for(int i=0;i<n;++i){
		for(int j=0;j<=i;++j){
			for(int k=0;k<=2500;++k){
				dp[i+1][j+1][k+x.at(i)]+=dp[i][j][k];
				dp[i+1][j][k]+=dp[i][j][k];
			}
		}
	}
	ll ans=0;
	for(int i=1;i<=n;++i){
		ans+=dp[n][i][a*i];
	}
	cout << ans << endl;
}

Measured memory_bytes: 60800
#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

#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define repk(i,k,n) for (ll i = k; i <= (int)(n); i++)
#define MAX 10000
typedef long long ll;

using namespace std;


int main(){
    int a,b;
    cin >> a >> b ;
    int ans =a*b;
    if(ans<a*b) ans = a*b;
    if(ans<=a+b) ans = a+b;
    if(ans<=a-b) ans = a-b;
  
    cout<< ans << endl;
        
    return 0;
}

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

int main() {
    while(cin){
        int r, c;
        cin >> r >> c;
        if (r == 0 && c == 0) break;
        vector<vector<int> > grid(r, vector<int>(c, 0));
        rep(i, r) {
            rep(j, c) {
                cin >> grid[i][j];
            }
        }
        int ans = 0;
        for (int bit = 0; bit < (1 << r); bit++) {
            vector<vector<int> > temp = grid;
            for (int i = 0; i < r; i++) {
                if ((bit >> i) & 1) {
                    for (int j = 0; j < c; j++) {
                        temp[i][j] ^= 1;
                    }
                }
            }
            for (int j = 0; j < c; j++) {
                int count = 0;
                for (int i = 0; i < r; i++) {
                    count += temp[i][j];
                }
                if (count > r / 2) {
                    for (int i = 0; i < r; i++) {
                        temp[i][j] ^= 1;
                    }
                }
            }
            int score = 0;
            rep(i, r) {
                rep(j, c) {
                    // cout << temp[i][j] << " ";
                    score += temp[i][j];
                }
                // cout << endl;
            }
            ans = max(ans, r * c - score);
            // cout << endl;
        }
        cout << ans << endl;
    }
}


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

void trace(int a[], int N) {
  for (int i = 0; i < N; i++) {
    if (i > 0) cout << " ";
    cout << a[i];
  }
  cout << endl;
}

void insertionSort(int a[], int N) {
  for (int i = 1; i < N; i++) {
    int v = a[i];
    int j = i-1;
    while (j >= 0 && a[j] > v) {
      a[j+1] = a[j];
      j--;
    }
    a[j+1] = v;
    trace(a, N);
  }
}

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



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

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

    string s; cin >> s;
    reverse(s.begin(), s.end());
    
    int pos = 0;
    while (pos < s.size()) {
        if (s.substr(pos, 5) == "maerd" || s.substr(pos, 5) == "esare") {
            pos += 5;
            continue;
        }
        if (s.substr(pos, 6) == "resare") {
            pos += 6;
            continue;
        }
        if (s.substr(pos, 7) == "remaerd") {
            pos += 7;
            continue;
        }
        cout << "NO" << endl;
        return 0;
    }

    cout << "YES" << endl;
    return 0;
}

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

struct point{
	char c;
	int count;
};

void move(point area[100][100], int &i, int &j){
	area[i][j].count = 0;
	if(area[i][j].c == '>'){
		j++;
	}else if(area[i][j].c == '<'){
		j--;
	}else if(area[i][j].c == 'v'){
		i++;
	}else if(area[i][j].c == '^'){
		i--;
	}
}

int main(){
	int h, w;
	string s;
	point area[100][100];
	while(cin >> h >> w){
		if(h == 0 && w == 0) break;
		for(int i = 0; i < h; i++){
			cin >> s;
			for(int j = 0; j < s.size(); j++){
				area[i][j].c = s[j];
				area[i][j].count = 1;
			}
		}
		int i = 0, j = 0;
		while((area[i][j].c != '.') && (area[i][j].count == 1)){
			move(area, i, j);
		}
		if(area[i][j].c == '.') cout << j << " " << i << endl;
		else cout << "LOOP" << endl;
	}
	return 0;
}

Measured memory_bytes: 0
A,B,Q=map(int,input().split())

# 左右の神社両方に行ってから最短の寺に行くパターンと、
# 左右の寺両方に行ってから最短の神社に行くパターン
# 両方を試して最小値を取る

S=[None] * A
T=[None] * B

for i in range(A):
  S[i] = int(input())
for i in range(B):
  T[i] = int(input())

# print("S",S)
# print("T",T)
import bisect

INF = 10**11
def getshortest(x,A,B):
  # xの両端のAをまず求める
  ind = bisect.bisect_right(A,x)
  dist_left = 0
  # 左に進む場合
  if ind == 0:
    dist_left = INF
  else:
    x2 = A[ind-1]
    dist_left = abs(x - A[ind-1])
    
    ind2 = bisect.bisect_right(B,x2)
    if ind2 == 0:
      dist_left += abs(B[0] - x2)
    elif ind2 == len(B):
      dist_left += abs(x2 - B[-1])
    else:
      dist_left += min(abs(x2 - B[ind2-1]),abs(B[ind2] - x2))
  
  dist_right = 0
  # 右に進む場合
  if ind == len(A):
    dist_right = INF
  else:
    x2 = A[ind]
    dist_right = abs(x - A[ind])
    
    ind2 = bisect.bisect_right(B,x2)
    if ind2 == 0:
      dist_right += abs(B[0] - x2)
    elif ind2 == len(B):
      dist_right += abs(x2 - B[-1])
    else:
      dist_right += min(abs(x2 - B[ind2-1]),abs(B[ind2] - x2))
  return (dist_left,dist_right)[dist_left > dist_right]
  
for i in range(Q):
  x = int(input())
#  print("x",x)
  s = getshortest(x,S,T)
  t = getshortest(x,T,S)
  print((s,t)[t<s])
  

Measured memory_bytes: 12020
import Data.List

main = getLine >> getContents >>= print . solve 0 . lines

solve :: Int -> [String] -> Int
solve n [xxs@(_ : xs), ys]
    | xxs `isPrefixOf` ys = n + length ys
    | otherwise = solve (n + 1) [xs, ys]
solve n [_, ys] = n + length ys


Measured memory_bytes: 508
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int x,a,b;
	cin>>x>>a>>b;
	int ans1=abs(x-a);
	int ans2=abs(x-b);
	if(ans1>ans2)
	cout<<"B"<<endl;
	else cout<<"A"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 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; }
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;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    ll N;
    string S;
    cin >>S;
    N=S.size();
    

    rep3(i,2,N){
        if(i%2==0){
            string s1,s2;
            s1 =S.substr(0,(N-i)/2);
            s2=S.substr((N-i)/2,(N-i)/2);
            if(s1==s2){
                cout<<N-i<<endl;
                return 0;
            }
        }
    }
   


    return 0;
    

}

Measured memory_bytes: 3540
#include<stdio.h>
int main(void){
  long long int a,b,c,x;
  scanf("%d %d %d %d",&a,&b,&c,&x);
  long long ans=a-b;
  if(x&1){
    ans=-1*ans;
  }
  printf("%lld\n",ans);
  return 0;
}

Measured memory_bytes: 128
#include<iostream>

using namespace std;

int main() {
	int w, n;
	cin >> w;
	cin >> n;
	int *array = new int[w + 1];
	for (int i = 1; i < w + 1; i++) {
		array[i] = i;
	}
	for (int i = 1; i < n+1; i++) {
		int a, b;
		char c;
		cin >> a >> c >> b;
		int tmp;
		tmp = array[a];
		array[a] = array[b];
		array[b] = tmp;
	}
	for (int i = 1; i < w + 1; i++) {
		cout << array[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 3072
n=int(input())
aa=list(map(int,input().split()))
aa=sorted(aa,reverse=True)
ans=0
if (n-1)%2==1:
  ans+=aa[0]
  for i in range(int((n-2)/2)+1):
    if i!=0:
      ans+=(aa[i]*2)
else:
  ans+=aa[0]
  for i in range(int((n-3)/2)+1):
    if i!=0:
      ans+=(aa[i]*2)
  ans+=aa[int((n-3)/2)+1]
print(ans)

Measured memory_bytes: 31468
n,k = map(int,input().split())
m = (n-1)*(n-2)//2
if( m<k ):
    print(-1)
    exit(0)

ans = []
buf = []
sub = m-k
for i in range(2,n+1):
    ans.append((1,i))

for i in range(3,n+1):
    for j in range(2,i):
        buf.append((j,i))

ans.extend(buf[:sub])

print(len(ans))
for x,y in ans:
    print('{0} {1}'.format(x,y))

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

int main(){
  int a,b,c; cin >> a >> b >> c;
  
  int d1 = abs(a-b);
  int d2 = abs(b-c);
  int d3 = abs(c-a);
  
  int dmin = min({d1,d2,d3});
  int dmax = max({d1,d2,d3});
  
  int cost = 0;
  
  if(d1 == dmin){
    cost += d1;
    if(d2 == dmax){
      cost+= d3;
    }
    else{
      cost+= d2;
    }
  }
  
  if(d2 == dmin){
    cost += d2;
    if(d3 == dmax){
      cost+= d1;
    }
    else{
      cost+= d3;
    }
  }
    
    if(d3 == dmin){
    cost += d3;
    if(d1 == dmax){
      cost+= d2;
    }
    else{
      cost+= d1;
    }
  }
    
    cout << cost << endl;
    
    return 0;
    
}
  
  
  
  

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin>>s;
	int mon=0;
	for(int i=s.length()/2-1;i>=0;i--){
		for(int k=0;k<i;k++){
			if(s[k]==s[k+i]){
				++mon;
			}
		}
		if(mon==i){
			cout<<i*2<<endl;
			break;
		}
		mon=0;
	}
}

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

void selectionSort(int[],int,int*);
static int n;
int a[100];

int main(){
	cin>>n;
	for (int i = 0; i < n; ++i)
	{
		cin>>a[i];
	}
	int sum=0;
	selectionSort(a,n,&sum);
	for (int i = 0; i < n-1; ++i)
	{
		cout<<a[i]<<" ";
	}
	cout<<a[n-1]<<endl;
	cout<<sum<<endl;


	
return 0;
}

void selectionSort(int a[], int n,int* sum){
	for (int i = 0; i < n; ++i)
	{
		int minj=i;
		for (int j = i; j < n; ++j)
		{
			if(a[j]<a[minj]) {
				minj=j;				
			}
		}
		if (a[i]!=a[minj]){
		swap(a[i],a[minj]);
		*sum= *sum+1;
		}
	}
}

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

int main()
{
    string s, t;
    cin >> s >> t;
    cout << t+s << endl; 
}

Measured memory_bytes: 3604
import sys
s=list(input())

a=s[0]
f=0
for x in range(1,4):
  if a!=s[x]:
    b=s[x]
    f=1
    break

if f==0:
    print("No")
    sys.exit()

for y in range(1,4):
    if y!=x:
        if a!=s[y] and b!=s[y]:
            print("No")
            sys.exit()
print("Yes")
        

Measured memory_bytes: 3060
n = gets.to_i
f = Array.new(n+1, 10000000)
f[0] = 0
(1..n).each{|i|
    f[i] = ([1] + (1..6).map{|x| 6**x} + (1..5).map{|x| 9**x}).select{|x| x<=i}.map{|x| f[i-x]}.min + 1
}
p f[n]



Measured memory_bytes: 2940
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <functional>
#include <map>
#include <set>
#define REP(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=1;i<=n;++i)
#define INF 10000000
#define ll long long

using namespace std;

typedef pair<int, int> P;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

int N;
ll int a[10010];

int f(ll int d, int k){
    if(d % 2 == 1) return k;
    else return f(d / 2, k+1);
}

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

    REP(i, N){
        scanf("%lld", &a[i]);
    }

    int ans = 0;

    REP(i, N){
        ans += f(a[i], 0);
    }

    printf("%d", ans);

	return 0;
}


Measured memory_bytes: 384
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::f64::consts::*;

#[allow(unused)]
const INF: usize = std::usize::MAX / 4;
#[allow(unused)]
const M: usize = 1000000007;

fn main() {
    input! {
        n: usize,
        k: usize,
        mut a: [usize; n],
    }
    a.sort();
    println!("{}", (0..k).map(|i| a[i]).sum::<usize>());
}


Measured memory_bytes: 2164
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);
		long n = sc.nextLong(), a = sc.nextLong(), b = sc.nextLong();
		long ans = n/(a+b);
		long mod = n%(a+b);
		long plus = 0;
		if(mod <= a) {
			plus = mod;
		}else {
			plus = a;
		}
		System.out.println((a*ans)+plus);

	}

	static class FastScanner {
		private BufferedReader reader = null;
	    private StringTokenizer tokenizer = null;
	    public FastScanner(InputStream in) {
	        reader = new BufferedReader(new InputStreamReader(in));
	        tokenizer = null;
	    }

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

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

	        return tokenizer.nextToken("\n");
	    }

	    public long nextLong() {
	        return Long.parseLong(next());
	    }

	    public int nextInt() {
	        return Integer.parseInt(next());
	    }

	    public double nextDouble() {
	         return Double.parseDouble(next());
	     }

	    public int[] nextIntArray(int n) {
	        int[] a = new int[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextInt();
	        return a;
	    }

	    public long[] nextLongArray(int n) {
	        long[] a = new long[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextLong();
	        return a;
	    }
	}
}

Measured memory_bytes: 22612
N = int(input())
As = list(map(int, input().split()))

pair =[(a,i) for i,a in enumerate(As)]
pair.sort()
min_info = pair[0]
max_info = pair[-1]
# maxとminの大小関係からせめて見る
# minの絶対値が大きい->負で構成
# それ以外 -> 正で構成
print(2*N-1)
if abs(min_info[0]) > abs(max_info[0]):
    ind = pair[0][1]
    for i in range(N):
        print(ind+1, i+1)
    for i in range(N-1,0,-1):
        print(i+1,i)
else:
    ind = pair[-1][1]
    for i in range(N):
        print(ind+1, i+1)
    for i in range(1,N):
        print(i,i+1)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
    
#define int long long int
#define vi vector<int>
#define vvi vector<vi>
#define read(a)  for(int i = 0; i < n; i++) cin >> a[i];
#define print(a)  for(int i = 0; i < n; i++) cout << a[i] << " ";
#define pb push_back
#define pql priority_queue<int>
#define pqs priority_queue<int, vi, greater<int>>
#define pqlv priority_queue<vi>
#define pqsv priority_queue<vi, vvi, greater<vi>>
#define endl '\n'
#define N 10000002
#define MOD 1000000007

int f(int a) {
    int ans = 0;
    int c = (a + 1) / 2;
    ans = c % 2;
    if(a % 2 == 1) {
        return ans;    
    }
    return a ^ ans;
}
    
signed main() {
    int a, b;
    cin >> a >> b;
    if(a > b)   swap(a, b);
    if(a == 0)  
        cout << f(b);
    else
        cout << (f(b) ^ f(a - 1));
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>


typedef long double ld;
typedef long long ll;

using namespace std;

int main() {
	int n, k;
	vector<ll> a;
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		ll t;
		cin >> t;
		a.push_back(t);
	}
	sort(a.begin(), a.end());
	reverse(a.begin(), a.end());
	ll ret = 0;
	for (int i = min(k, n); i < n; i++) {
		ret += a[i];
	}
	cout << ret << endl;

	return 0;
}


Measured memory_bytes: 4868
#include<bits/stdc++.h>
#include <time.h> 
#define ll long long int
#define F first
#define S second
#define pb push_back
#define sd(x) scanf("%d",&x)
#define sd2(x,y) scanf("%d%d",&x,&y);
#define sdl(x) scanf("%lld",&x)
#define sd2l(x,y) scanf("%lld%lld",&x,&y);
#define sz(x) (int)(x.size())
#define nax 100010
#define inf 1001000100
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MOD 1000000007
#define mp make_pair
#define pc pair<char ,int>
#define pi pair<int ,int>
#define pii pair <pi,pi>
using namespace std;
const int V_MAX = 100001; 
ll dp[105][100010]; // min weight to reach here.
int wt[105];
int val[105];
int main(int argc, char const *argv[])
{
  //freopen("input.txt","r",stdin);
  //freopen("output.txt","w",stdout);
  int n,w;
  sd2(n, w);
  int fans = 0;
  for(int i = 1; i <= n; i++)
    sd2(wt[i], val[i]);
  for(int i = 1; i < V_MAX; i++)
    dp[0][i] = inf * 1ll * inf;
  for(int i = 1; i <= n; i++)
  {
      int cwt = wt[i];
      int cval = val[i];
      for(int j = 1; j < V_MAX; j++)
      {
          dp[i][j] = dp[i - 1][j];
          if(j - cval >= 0)
            dp[i][j] = min(dp[i][j] , dp[i - 1][j - cval] + cwt);
          if(i == n && dp[i][j] <= w)
            fans = max(fans, j);
      }
  }
  printf("%d\n", fans);
  return 0;
}

Measured memory_bytes: 80128
#include <stdio.h>

int main () {
	int N, y = 0;
	scanf ("%d", &N);
	for (int i=0; i<N; i++) {
		char tmp;
		scanf ("%c", &tmp);
		if (tmp=='Y')
			y++;
	}
	printf ("%s\n",y?"Four":"Three");
	return 0;
}


Measured memory_bytes: 128
// I make this just for fun because i'm done
// Aimi Haraguni >> Konomi Suzuki >> Yui >>  Ikimono Gakari >> Garnidelia >> Kalafina >> Eir Aoi.   .. dude? 
// problems that involves any kind of persistent data structures are the best of the best, are not them?
 
// #pragma GCC optimize ("Ofast,unroll-loops")
// #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
 
#define pb push_back
#define ff  first
#define ss second
#define tm1 first
#define tm2 second.first
#define tm3 second.second
#define sz(x) ll(x.size())
#define all(v) (v).begin(), (v).end()
#define FER(i,a,b) for(ll i=ll(a); i< ll(b); ++i)
#define IFR(i,a,b) for(ll i=ll(a); i>=ll(b); --i )
#define fastio ios_base::sync_with_stdio(0); cin.tie(0)
 
#define N 2005
// #define M 19
 
#define mod  998244353
#define mod1 1000000007
#define mod2 1000000009
#define bas 987625403
#define sqr(x) (x)*(x)  
#define INF 2000000000000000000
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef pair<ll, ll> ii;
typedef pair<ll, ii > tri;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef tree<pair<ll, ll>, null_type, less<pair<ll, ll>>, rb_tree_tag, tree_order_statistics_node_update> S_t;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
 
#define trace(...) fff(#__VA_ARGS__, __VA_ARGS__)
template<typename t> void fff(const char* x, t&& val1) { cout<<x<< " : "<<val1<<"\n";}
template<typename t1, typename... t2> void fff(const char* x, t1&& val1, t2&&... val2){
    const char* xd=strchr(x+1, ',');
    cout.write(x, xd-x)<<" : "<<val1<<" | ";
    fff(xd+1, val2...);
}

ll dist[1<<13][1<<13];

int main(){
    fastio;
    ll x, y, a, b, c; cin>>x>>y>>a>>b>>c;
    
    vi tnt1, tnt2, tnt3;
    FER(i, 0, a) {
        ll x; cin>>x;
        tnt1.pb(x);
    }
    FER(i, 0, b){
        ll x; cin>>x;
        tnt2.pb(x);
    }
    FER(i, 0, c){
        ll x; cin>>x;
        tnt3.pb(x);
    }
    sort(all(tnt1)), reverse(all(tnt1));
    sort(all(tnt2)), reverse(all(tnt2));
    FER(i, 0, x) tnt3.pb(tnt1[i]);
    FER(i, 0, y) tnt3.pb(tnt2[i]);
    sort(all(tnt3)), reverse(all(tnt3));
    ll ans = 0;
    FER(i, 0, x+y) ans+=tnt3[i];
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 7792
import java.util.Scanner;

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

		for (int i = 0; i < N.length(); i++) {
			char c = N.charAt(i);
			if (i % 2 == 0) {
				if (c =='L') {
					System.out.println("No");
					break;
				}
			}else {
				if (c =='R') {
					System.out.println("No");
					break;
				}
			}
			if (i == N.length() - 1) {
				System.out.println("Yes");
			}
		}
	}

}

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

int n;
string s, t;

int main()
{
    cin >> n;
    cin >> s;
    cin >> t;
    int res = 0;
    for (int i = 1; i <= n; i++)
        if (s.substr(int(s.length()) - i) == t.substr(0, i))
            res = i;
    cout << 2 * n - res << endl;
    return 0;
}


Measured memory_bytes: 256
### constant

DIV = 1000

PI2 = 2 * Math::PI

### classes

class Pt
  attr_accessor :x, :y

  def initialize() end
  def initialize(x, y) @x = x; @y = y end

  def ==(pt) @x == pt.x && @y == pt.y end
  def +(pt) Pt.new(@x + pt.x, @y + pt.y) end
  def -(pt) Pt.new(@x - pt.x, @y - pt.y) end
  def -@() Pt.new(-@x, -@y) end
  def *(t) Pt.new(@x * t, @y * t) end
  def /(t) Pt.new(@x / t, @y / t) end
  def dot(v) @x * v.x + @y * v.y end
  def cross(v) @x * v.y - @y * v.x end
  def d2() @x * @x + @y * @y end
  def d() Math.sqrt(d2()) end
  def normalize() self / d() end
  def to_s() "(#{@x},#{@y})" end
end

### subroutines

def gcenter(pts)
  npts = pts.length
  gp = Pt.new(0.0, 0.0)
  ar = 0.0
  
  for i in (0...npts)
    j = (i + 1) % npts
    ari = pts[i].cross(pts[j]) / 2
    gpi = (pts[i] + pts[j]) / 3

    gp += gpi * ari
    ar += ari
  end

  gp / ar
end

def contains?(pts, gcp)
  npts = pts.length
  cn = 0
  
  for i in (0...npts)
    pt0 = pts[i]
    pt1 = pts[(i + 1) % npts]

    if pt0.y == gcp.y && pt1.y < gcp.y
      cn += 1 if pt0.x >= gcp.x
    elsif pt1.y == gcp.y && pt0.y < gcp.y
      cn += 1 if pt1.x >= gcp.x
    elsif (pt0.y - gcp.y) * (pt1.y - gcp.y) < 0.0
      t = (gcp.y - pt0.y) / (pt1.y - pt0.y) 
      x = (pt1.x - pt0.x) * t + pt0.x
      cn += 1 if x >= gcp.x
    end
  end

  (cn & 1) == 1
end

### main

loop do
  line = gets.strip
  break if line == 'end'

  cmd, x, y = line.split
  spt = Pt.new(x.to_f, y.to_f)
  #p spt.to_s

  pts = [spt]
  pt0 = spt
  
  loop do
    cmds = gets.strip.split
    case cmds[0]
    when 'close'
      pts.pop if pts.last == spt
      break
    when 'line'
      pt1 = Pt.new(cmds[1].to_f, cmds[2].to_f)
      pts << pt1
      pt0 = pt1
    when 'arc'
      pt1 = Pt.new(cmds[1].to_f, cmds[2].to_f)
      r = cmds[3].to_f

      v = pt1 - pt0
      pt2 = v / 2 + pt0
      vd2 = v.d2
      cd = Math.sqrt(r * r - vd2 / 4)

      nv = ((r < 0.0) ? Pt.new(-v.y, v.x) : Pt.new(v.y, -v.x)).normalize
      cp = nv * cd + pt2

      v0 = pt0 - cp
      v1 = pt1 - cp
      th0 = Math.atan2(v0.y, v0.x)
      th1 = Math.atan2(v1.y, v1.x)
      th = th1 - th0
      while th < 0.0
        th += 2 * PI2
      end
      while th > PI2
        th -= PI2
      end
      th = PI2 - th if r > 0.0
      dth = (r < 0.0) ? th / DIV : -th / DIV
      ra = r.abs
      
      for k in (1...DIV)
        thk = th0 + dth * k
        pts << Pt.new(ra * Math.cos(thk) + cp.x, ra * Math.sin(thk) + cp.y)
      end
      pts << pt1
      
      pt0 = pt1
    end
  end
  npts = pts.length
  #p pts.map{|pt| pt.to_s}
  #p arcs

  gcp = gcenter(pts)
  cnt = contains?(pts, gcp)

  puts ([gcp.x, gcp.y].map{|f| "%.5f" % f} + [cnt ? '+' : '-']).join(' ')
end

Measured memory_bytes: 7132
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define bFOR(i,n1,n2) for(ll i=n1;i>=n2;i--)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
typedef tuple<ll,ll,ll> Tu;
const int INF=(ll)(1LL<<30)-1;
const double INFd=100000000000.0;
const double PI=3.14151926535;
const ll INFl=(ll)9223372036854775807/2;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
const ll tMOD=(ll)998244353;
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;}
int dx[4]={0,-1,0,1},dy[4]={-1,0,1,0};
int mdx[8]={0,1,0,-1,1,1,-1,-1},mdy[8]={-1,0,1,0,1,-1,1,-1};


template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

ll n;
int main(){
	cin>>n;
	if(n%2==1){
		cout<<0<<endl;
		return 0;
	}
	ll ans=0;
	ll t=10;
	for(;t<=1e18;t*=5){
		ans+=(n/t);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>
#include<cstring>
#include<bitset>
#include<cassert>

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

using namespace std;
using ll = long long int;

const int inf = 1001001000;
const long long int Inf = 1001001001001001000;



void print(vector<vector<int>> a){
	for (int i = 0; i < a.size(); i++)
	{
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<vector<long long int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(vector<long long int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(set<int> a){
	for (auto x:a)
		cout << x << " ";
	cout << endl;
}

//幅優先探索のテンプレ.デフォルトではstartからの距離を返す.
//graphは隣接リスト.startは探索開始地点
vector<vector<int>> bfs(vector<vector<int>> &graph, int start){
	vector<vector<int>> dist(graph.size(), vector<int>(3, -1));
	queue<pair<int,int>> todo;
	dist[start][0] = 0;
	todo.push(make_pair(start,0));
	while(!todo.empty()){
		int now = todo.front().first;
		int l = todo.front().second;
		todo.pop();
		for (int i=0;i<graph[now].size();i++){
			int nxt = graph[now][i];
			if (dist[nxt][(l+1)%3] != -1) continue;
			dist[nxt][(l+1)%3] = dist[now][l] + 1;
			todo.push(make_pair(nxt,(l+1)%3));
		}
	}
	return dist;
}

int main(){
	int n, m;
	cin >> n >> m;
	vector<vector<int>> graph(n);
	rep(i, m)
	{
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		graph[a].push_back(b);
	}
	int s, t;
	cin >> s >> t;
	s--;
	t--;
	vector<vector<int>> dist = bfs(graph, s);
	if(dist[t][0] != -1)
		dist[t][0] /= 3;
	cout << dist[t][0] << endl;

	return 0;
}

Measured memory_bytes: 11136
def f():
    res = []
    for i in range(n):
        pivot = -1
        for j in range(len(LIST)-1,-1,-1):
            if LIST[j] == j:
                pivot = j
                break
        if pivot == -1:
            print(-1)
            exit()
        res.append(pivot+1)
        LIST.pop(pivot)
    res = res[::-1]
    #print(res)
    for v in res:
        print(v)



n = int(input())
LIST = list(map(lambda x:int(x)-1,input().split()))
f()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main()
{
    int n;
    cin >> n;
    int s[n];
    rep(i, 0, n) cin >> s[i];
    int q;
    cin >> q;
    int t[q];
    rep(i, 0, q) cin >> t[i];

    int ans = 0;
    rep(i, 0, q) {
        rep(j, 0, n) {
            if (t[i] == s[j]) {
                ans ++;
                break;
            }
        }
    }

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



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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define VIN(v) for(auto&elem_: (v) )cin>>elem_
#define VOUT(v, sep) for(_loop_int idx=0; idx<(_loop_int)v.size(); idx++) {cout<<v[idx]; if(idx<(_loop_int)v.size()-1) cout<<sep;} cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(debugidx,v.size())cout<<" "<<v[debugidx];cout<<endl
#define DEBUG_ARR(v,n) cout<<#v<<":";REP(debugidx,n)cout<<" "<<v[debugidx];cout<<endl

const ll MOD = 1000000007ll;
const int IINF = numeric_limits<int>::max()/2-1;
const ll LINF = numeric_limits<ll>::max()/2-1;

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



int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    vi a(3);
    cin>>a[0]>>a[1]>>a[2];
    sort(ALL(a), greater<int>());

    int ans = a[0]*10+a[1]+a[2];

    cerr<<"errhoge"<<endl;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
#define pb push_back
#define int long long
//#define M 998244353
#define M 1000000007
using namespace std;
const int inf=4e18;
const int MX=100;
const int MN=-100;
const double pi=3.14159265358979;
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	int a,b;cin>>a>>b;
	int g=__gcd(a,b);
	cout<<(a*b)/g<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define sz size()
#define pb push_back
#define mp make_pair
#define ALL(X) (X).begin(),(X).end()

using namespace std;

const int INF = 1000000000;
const double eps = 1e-8;

struct pos{
  pos(int _f,int _s):first(_f),second(_s){}
  int first;int second;
};

int union_t(vector<vector<int> > & table,int clr,int h,int w)
{
  vector<vector<int> > vis(h,vector<int>(w,0));
  queue<pos> q;
  q.push(pos(0,0));
  vis[0][0]=1;
  while(!q.empty())
  {
    int dx[]={1,0,-1,0};
    int dy[]={0,1,0,-1};
    pos p = q.front();
    q.pop();
    int x,y;
    x=p.first;
    y=p.second;
    vis[y][x]=1;
    REP(i,4)
    {
      int nx=x+dx[i];
      int ny=y+dy[i];
      if(nx<0||nx>=w||ny<0||ny>=h)
        continue;
      if(vis[ny][nx]==1)
        continue;
      if(table[ny][nx] == clr || (table[y][x] == table[0][0] && table[ny][nx] == table[0][0]))
      {
        q.push(pos(nx,ny));
      }
    }
  }
  int c = 0;
  REP(i,h)
    REP(j,w)
      if(vis[i][j]==1)
      {
        table[i][j] = clr;
        c++;
      }
  return c;
}

int search(vector<vector<int> > & table,int depth,int clr,int h,int w)
{
  if(depth > 1)
  {
    int m = 0;
    FOR(i,1,7)
    {
      vector<vector<int> > cp(h);
      REP(j,h)
        cp[j] = vector<int>(table[j]);
      union_t(cp,i,h,w);
      m = max(m,search(cp,depth-1,clr,h,w));
    }
    return m;
  }
  else
  {
    vector<vector<int> > cp(h);
    REP(j,h)
      cp[j] = vector<int>(table[j]);
    return union_t(cp,clr,h,w);
  }
}

int main(void) {
  while(1)
  {
    int h,w,c;
    cin>>h>>w>>c;
    if(!(h||w||c))break;
    vector<vector<int> > table(h,vector<int>(w,0));
    REP(i,h)
      REP(j,w)
        cin>>table[i][j];
    cout<<search(table,5,c,h,w)<<endl;
  }
  return 0;
}

Measured memory_bytes: 1260
#include <bits/stdc++.h>
 
#define f(i,a,b) for( ll i = a; i < b ; i++ )
#define af(i,a,b) for( ll i = a; i >= b ; i--)
#define rep(i,a,b,k) for(ll i = a; i < b ; i+= k )
#define arep(i,a,b,k) for( ll i = a; i >= b ; i-= k)
#define ones(x) (ll) __builtin_popcount(x)
#define fs first
#define sc second
#define pb push_back
#define po pop_back
#define mp make_pair 
#define sz(a) (ll) a.size()
#define all(a) a.begin(), a.end()
#define sor(a) sort( a.begin(), a.end() )
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define ller ios::sync_with_stdio(false);cin.tsie(nullptr);cout.tie(nullptr)
#define watch(x) cout << (#x) << " is " << (x) <<"\n"
#define PI 3.1415926535
using namespace std;
typedef long long ll;
typedef long double ld; 
typedef pair<ll,ll> ii ;
typedef vector<ll>  vi ;
typedef vector<ii> vii ;
const ll mod = 1e9+7;
const ll MAX = 1e5+10;
const ll inf = 1e18+7;

ll binpow(ll a,ll b){
	a%=mod;
	ll res= 1;
	while(b>0){
		if(b&1) res = res*a%mod;
		a = a*a%mod;
		b>>=1;
	}
	return res%mod;
}

int main(){
	fastio;
	ll n;
	cin>>n;
	ll ans = (binpow(10,n)- (2*binpow(9,n))%mod + mod)%mod;
	ans = (ans+binpow(8,n))%mod;
	cout<<ans<<"\n";
    return 0; 
}

Measured memory_bytes: 3652
#include<cstdio>
#include <algorithm>
#include <iostream>
#include <functional>

using namespace std;

int main(){
	int a[500000],min;
	char s[500000];
	long int sum;
	scanf("%s",s);
	a[0]=0;
	for(int i=0;s[i]!='\0';i++){
		if(s[i]=='<') a[i+1]=a[i]+1;
		else a[i+1]=a[i]-1;
	}
	/*
	printf("%d",a[0]);
	for(int i=0;s[i]!='\0';i++) printf(",%d",a[i+1]);
	printf("\n");
	*/
	for(int i=0;;i++){
		if(i>0&&s[i-1]=='\0') break;
		if(s[i-1]=='>' && ( s[i]=='<' || s[i]=='\0') ){
			min = -1*a[i];
			a[i]=0;
			for(int j=1;s[i-j]=='>'&&i-j>=0;j++){
				a[i-j]+=min;
			}
			for(int j=0;s[i+j]=='<'&&s[i]!='\0';j++){
				a[i+j+1]+=min;
			}
		}
	}
	/*
	printf("%d",a[0]);
	for(int i=0;s[i]!='\0';i++)
		if(s[i]=='<'&&s[i+1]=='>'){
			if(a[i]>a[i+2])  printf(",%d",a[i]+1);
			else   printf(",%d",a[i+2]+1);
		}
		else  printf(",%d",a[i+1]);
	printf("\n");
	*/
	sum = a[0];
	for(int i=0;s[i]!='\0';i++){
		if(s[i]=='<'&&s[i+1]=='>'){
			if(a[i]>a[i+2])sum += a[i]+1;
			else sum += a[i+2]+1;
		}
		else sum += a[i+1];
	}
	printf("%ld\n",sum);
	
	return 0;
}

Measured memory_bytes: 2688
#include <stdio.h>
#include <map>

std::map<int,bool> mp;

int x,n;
int p[200];

int main()
{
    scanf("%d%d",&x,&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&p[i]);
        mp[p[i]]=1;
    }
    for(int i=0;;i++)
    {
        if(mp[x-i]!=1)
        {
            printf("%d\n",x-i);
            return 0;
        }
        if(mp[x+i]!=1)
        {
            printf("%d\n",x+i);
            return 0;
        }
    }

}

Measured memory_bytes: 3324
using System;
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        var input = new InputB();
        var cities = new Cities(input.N);
        foreach (var abTuple in input.abTuples)
        {
            cities.AddLoad(abTuple.a, abTuple.b);
        }

        cities.PrintConnectedCities();
    }

    class Cities
    {
        public City[] cities;

        public void AddLoad(int a_i, int b_i)
        {
            this.cities[a_i].connectedCity.Add(b_i);
            this.cities[b_i].connectedCity.Add(a_i);
        }

        public void PrintConnectedCities()
        {
            foreach (var city in this.cities)
            {
                Console.WriteLine(city.connectedCity.Count);
            }
        }
        
        public class City
        {
            public IList<int> connectedCity;

            public City()
            {
                this.connectedCity = new List<int>();
            }
        }

        public Cities(int numberOfCity)
        {
            this.cities = new City[numberOfCity];
            for(var i = 0; i < numberOfCity; i++)
            {
                this.cities[i] = new City();
            }
        }
    }
    class InputB
    {
        public int N {get; set;}
        public int M {get; set;}
        public List<ABTuple> abTuples {get; set;}

        public class ABTuple
        {
            public int a {get; set;}
            public int b {get; set;}
        }

        public InputB()
        {
            var line0 = Console.ReadLine().Split(" ");
            this.N = int.Parse(line0[0]);
            this.M = int.Parse(line0[1]);

            this.abTuples = new List<ABTuple>();

            for(var i = 0; i < M; i++)
            {
                var line_i = Console.ReadLine().Split(" ");
                var a_i = int.Parse(line_i[0]) - 1;
                var b_i = int.Parse(line_i[1]) - 1;
                this.abTuples.Add(new ABTuple()
                {
                    a = a_i,
                    b = b_i,
                });
            }
        }
    }

}


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

using ll = long long;
#define repi(n) for (int i = 0; i < (n); i++)
#define repj(n) for (int j = 0; j < (n); j++)
#define repk(n) for (int k = 0; j < (n); k++)
#define rep(i, n) for (int i = 0; (i) < (n); i++)
#define repr(i, a, b) for (auto i = (a); i < (b); i++)
#define repv(itr) for (auto&& v : (itr))
#define updatemax(t, v) (t = max((t), (v)))
#define updatemin(t, v) (t = min((t), (v)))
const int dx[] = {-1, 0, 0, 1, -1, -1, 1, 1};
const int dy[] = {0, -1, 1, 0, -1, 1, -1, 1};
template <typename T>
T minptr(T begin, T end) {
  T re = begin;
  for (T i = begin + 1; i != end; i++) {
    if (*i < *re) re = i;
  }
  return re;
}
template <typename T>
T maxptr(T begin, T end) {
  T re = begin;
  for (T i = begin + 1; i != end; i++) {
    if (*i > *re) re = i;
  }
  return re;
}
int __vmax(int x) {
  return INT_MAX;
}
double __vmax(double x) {
  return 1e+300;
}
ll __vmax(ll x) {
  return LLONG_MAX;
}
int __vmin(int x) {
  return INT_MIN;
}
double __vmin(double x) {
  return -1e+300;
}
ll __vmin(ll x) {
  return LLONG_MIN;
}
template <typename T>
vector<T> lis(T begin, T end, bool allowequal = false, bool lds = false) {
  using V = typename iterator_traits<T>::value_type;
  int n = end - begin;
  vector<V> a(n, lds ? __vmin(*begin) : __vmax(*begin));
  vector<int> id(n);
  if (lds && allowequal) {
    for (int i = 0; i < n; i++) {
      id[i] = n - 1 -
              (lower_bound(a.rbegin(), a.rend(), begin[i]) - 1 - a.rbegin());
      a[id[i]] = begin[i];
    }
  } else if (lds) {
    for (int i = 0; i < n; i++) {
      id[i] = n - 1 -
              (upper_bound(a.rbegin(), a.rend(), begin[i]) - 1 - a.rbegin());
      a[id[i]] = begin[i];
    }
  } else if (allowequal) {
    for (int i = 0; i < n; i++) {
      id[i] = upper_bound(a.begin(), a.end(), begin[i]) - a.begin();
      a[id[i]] = begin[i];
    }
  } else {
    for (int i = 0; i < n; i++) {
      id[i] = lower_bound(a.begin(), a.end(), begin[i]) - a.begin();
      a[id[i]] = begin[i];
    }
  }
  int m = *maxptr(id.begin(), id.end());
  vector<T> re(m + 1);
  for (int i = n - 1; i >= 0; i--) {
    if (id[i] == m) re[m--] = begin + i;
  }
  return re;
}

ll a[100100];
int main() {
  ll n, k;
  cin >> n >> k;
  repi(n) cin >> a[i];

  // Xの各bitを立てるとどれだけ得をするか
  ll toku[42] = {};
  repi(n) repj(42) {
    if (a[i] & (1ll << j)) toku[j]++;
  }
  repi(42) toku[i] = ((n - toku[i]) - toku[i]) << i;

  ll sum = 0;
  repi(n) sum += a[i];
  // ll dp[43][2] = {};
  // ll klen = k ? log2(k) + 1 : 0;
  // repi(klen) {
  //   ll tk = klen - i - 1, kbit = (k >> tk) & 1;
  //   repj(2) rep(t, j ? kbit + 1 : 2)
  //       updatemax(dp[i + 1][j && t == kbit], dp[i][j] + max(0ll, toku[tk] *
  //       t));
  // }
  // cout << sum + max(dp[klen][0], dp[klen][1]) << endl;
  ll re = LLONG_MIN;
  repi(42) {
    if ((((k + 1) >> i) & 1) == 0) continue;
    ll xx = sum;
    repj(i) if (toku[j] > 0) xx += toku[j];
    repr(j, i + 1, 42) if (((k + 1) >> j) & 1) xx += toku[j];
    updatemax(re, xx);
  }
  cout << re << endl;
}


Measured memory_bytes: 1024
//参考：https://qiita.com/DaikiSuyama/items/9dba963ba74396b9b7fd
//インクルード(アルファベット順)
#include <algorithm>     //sort,二分探索,など
#include <bitset>        //固定長bit集合
#include <cmath>         //pow,logなど
#include <complex>       //複素数
#include <deque>         //両端アクセスのキュー
#include <functional>    //sortのgreater
#include <iomanip>       //setprecision(浮動小数点の出力の誤差)
#include <iostream>      //入出力
#include <iterator>      //集合演算(積集合,和集合,差集合など)
#include <map>           //map(辞書)
#include <numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include <queue>         //キュー
#include <set>           //集合
#include <stack>         //スタック
#include <string>        //文字列
#include <unordered_map> //イテレータあるけど順序保持しないmap
#include <unordered_set> //イテレータあるけど順序保持しないset
#include <utility>       //pair
#include <vector>        //可変長配列

using namespace std;
typedef long long ll;

//マクロ
//forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
//Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはループ変数は1ずつデクリメントされる
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      //sizeをsize_tからllに直しておく
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007    //10^9+7:合同式の法
#define MAXR 100000       //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define FIR first    //pairの一つ目の要素
#define SEC second   //pairの二つ目の要素

signed main()
{
    //入力の高速化用のコード
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    ll N, X, T;
    cin >> N >> X >> T;

    ll Q = N / X;
    ll R = N % X;

    if (R != 0)
        Q++;

    cout << Q * T << endl;

    return 0;
}


Measured memory_bytes: 3160
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author YahiaAshraf74
 */

#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <stack>
#include <complex>
#include <string>
#include <bitset>
#include <stdio.h>
#include <string.h>
#include <fstream>
#include <iomanip>
#include <assert.h>

using namespace std;
#define el  '\n'
#define ll long long
#define clr(a, b)memset(a,b,sizeof(a))
#define sz(a) (int)(a).size()
const long long N = (int) 2e5 + 74, OO = 0x3f3f3f3f, MOD = (int) 1e9 + 7;

int n;
int a[N][3];
int mem[N][4];

class CVacation {
public:
    void init() {
        clr(mem, -1);
    }

    int solve(int i, int last) {
        if (i == n)
            return 0;
        int &ret = mem[i][last];
        if (~ret)
            return ret;
        ret = 0;
        for (int j = 0; j < 3; j++) {
            if (last != j)
                ret = max(ret, solve(i + 1, j) + a[i][j]);
        }
        return ret;
    }

    void solve(istream &cin, ostream &cout) {
        init();
        cin >> n;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < 3; j++)
                cin >> a[i][j];
        }
        cout << solve(0, 3);
    }
};
int main() {
	ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
	CVacation solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 8960
//------------------------------>> tsukasa_diary's template <<------------------------------//
#include <bits/stdc++.h>
using namespace std;

#define for_(i,a,b) for(int i=(a);i<(b);++i)
#define allof(a) (a).begin(),(a).end()
using lint = long long;
template< typename T > using Vec = vector< T >;

template< typename T > bool inRange(T x, T lb, T ub) { return lb <= x && x < ub; }
template< typename T > bool inRange(T x, T y, T lb, T ub) { return in_range(x, lb, ub) && in_range(y, lb, ub); }
template< typename T > void modAdd(T& a, T b, T mod) { a = (a + b + mod) % mod; }
template< typename T > void modMul(T& a, T b, T mod) { a = (a * b) % mod; }
template< typename T > void minUpdate(T& a, T b) { a = min(a, b); }
template< typename T > void maxUpdate(T& a, T b) { a = max(a, b); }
inline int bitCount(int x) { return __builtin_popcount(x); }
inline int bitCount(lint x) { return __builtin_popcountll(x); }

const int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};
const int Dx[8] = {0,1,1,1,0,-1,-1,-1}, Dy[8] = {-1,-1,0,1,1,1,0,-1};
const double PI = acos(-1);

//--------------8---------------->> coding space <<-----------------8-------------//



int main() {
	int N, A, B;
	cin >> N >> A >> B;
	cout << min(N * A, B) << endl;
}
//--------------8---------------->> coding space <<-----------------8-------------//

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int INF = 1 << 30;

bool fail() {
    cout << "none" << endl;
    return true;
}

bool solve() {
    int N;
    cin >> N;
    if (N == 0) return false;

    vector<string> S(N + 2);
    for (int i = 1; i <= N; ++i) cin >> S[i];
    S[0] = to_string(INF), S[N + 1] = to_string(N % 2 == 0 ? -INF : INF);

    int low = -(1 << 30), high = 1 << 30;
    for (int i = 1; i <= N; ++i) {
        if (S[i] == "x") {
            if (S[i - 1] == "x" || S[i + 1] == "x") return fail();

            if (i % 2 == 0) {
                low = max({low, stoi(S[i - 1]) + 1, stoi(S[i + 1]) + 1});
            } else {
                high = min({high, stoi(S[i - 1]) - 1, stoi(S[i + 1]) - 1});
            }
        } else {
            if (S[i + 1] == "x") continue;
            if (i % 2 == 0) {
                if (stoi(S[i]) <= stoi(S[i + 1])) return fail();
            } else {
                if (stoi(S[i]) >= stoi(S[i + 1])) return fail();
            }
        }
    }

    if (low > high) return fail();
    if (low < high) {
        cout << "ambiguous" << endl;
    } else {
        cout << low << endl;
    }
    return true;
}

int main() {
    while (solve()) {}
    return 0;
}



Measured memory_bytes: 3188
fun main(args: Array<String>) {
    while (true) {
        val (n, x) = readLine()!!.split(" ").map(String::toInt)

        if (n == 0 && x == 0) break

        var cnt = 0
        (1..n).forEach { i ->
            (i..n).forEach { j ->
                (j..n).forEach { k ->
                    if (i != j && j != k && i+j+k == x) cnt++
                }
            }
        }
        println(cnt)
    }
}


Measured memory_bytes: 37372