akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define t(w) int w; cin>>w; while(w--) 
typedef long long int ll; 
using namespace std;

void solve(){
	ll n;
	vector<ll> o,e;
	cin>>n;
	for(ll i=0;i<2*n;i++){
		ll a;
		cin>>a;
		if(a%2==0)
		e.push_back(i);
		else
		o.push_back(i);
	}
	if(e.size()%2!=0){
		e.pop_back();
		o.pop_back();
	}
	else if(o.size()%2==0){
		e.pop_back();
		e.pop_back();
	}
	
	for(ll i=0;i<e.size();i=i+2)
	cout<<e[i]+1<<" "<<e[i+1]+1<<endl;
	for(ll i=0;i<o.size();i=i+2)
	cout<<o[i]+1<<" "<<o[i+1]+1<<endl;
}
void solve1(){
	ll n,sum=0;
	vector<ll> v(1000000,0);
	cin>>n;
	for(ll i=0;i<n;i++){
		ll a;
		cin>>a;
		sum+=a;
		v[a]++;
	}
	ll q;
	cin>>q;
	for(ll i=0;i<q;i++){
		ll x,y;
		cin>>x>>y;
		if(v[x]>0){
			sum-=x*v[x];
			sum+=y*v[x];
			v[y]+=v[x];
			v[x]=0;
		}
		cout<<sum<<endl;
	}
}
int main(){
	solve1();
	return 0;
}

Measured memory_bytes: 10972
#include <iostream>
#include <string>
using namespace std;
int main(){

int x,y,sum=0;
cin>>x>>y;
int z[x];
for(int i=0;i<x;i++){
    cin>>z[i];
    if(z[i]>=y)
        sum+=1;
}
    cout<<sum;
   return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s=sc.next();
		if(s.length()>=4&&s.substring(0, 4).equals("YAKI")) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}
}



Measured memory_bytes: 22996
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <bitset>
#include <fstream>
#include <cmath>
#include <ctime>
using namespace std;
typedef long long ll;

int main()
{
	for(int i = 0; i < 3; i++){

		int h1, h2, m1, m2, s1, s2;
		cin >> h1 >> m1 >> s1 >> h2 >> m2 >> s2;
		
		int time1 = h1 * 3600 + m1 * 60 + s1;
		int time2 = h2 * 3600 + m2 * 60 + s2;

		int res = time2 - time1;

		cout << res / 3600 << " " << res / 60 % 60 << " " << res % 60 << endl;
	}
}

Measured memory_bytes: 0
#include<iostream>
#include<algorithm>
using namespace std;
struct node{
	int dur,dea;
	};
node* func(node *a,int n)
{
	if(n==1)
		return a;
	node *b=new node[n/2],*c=new node[n/2+n%2];
	for(int i=0;i<n/2;i++)
		{b[i].dur=a[i].dur;
		b[i].dea=a[i].dea;}
	for(int i=0;i<n/2+n%2;i++)
		{c[i].dur=a[i+n/2].dur;
		c[i].dea=a[i+n/2].dea;}
	b=func(b,n/2);
	c=func(c,n/2+n%2);
	int k=0,t1=0,t2=0;
	while(t1<n/2 and t2<n/2+n%2)
	{
		if(b[t1].dea>c[t2].dea)
			{a[k].dur=c[t2].dur;
			a[k].dea=c[t2].dea;
			k++;t2++;}
		else{a[k].dur=b[t1].dur;
			a[k].dea=b[t1].dea;
			k++;t1++;}
	}
	while(t1<n/2)
		{a[k].dur=b[t1].dur;
			a[k].dea=b[t1].dea;
			k++;t1++;}
	while(t2<n/2+n%2)
		{a[k].dur=c[t2].dur;
			a[k].dea=c[t2].dea;
			k++;t2++;}
	return a;
}
	
int main()
{
int n;cin>>n;
node *a=new node[n];
for(int i=0;i<n;i++)
	cin>>a[i].dur>>a[i].dea;
a=func(a,n);
int check=0;
long long int sum=0;
for(int i=0;i<n;i++)
{
	sum+=a[i].dur;
	if(sum>a[i].dea)
		check=1;
}
if(check==1)
	cout<<"No";
else cout<<"Yes";
	
return 0;
}


Measured memory_bytes: 36608
n,m = map(int,input().split())
a = [int(input()) for i in range(m)]
a = set(a)
mod = 10**9+7
dp = [0] * (n+1)
dp[0] = 1
if not 1 in a:
    dp[1] = 1

for i in range(2,n+1):
    if i in a:
        continue
    dp[i] = dp[i-1] + dp[i-2]

print(dp[n] % mod)


Measured memory_bytes: 460020
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using VS = vector<string>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int i=(a);i<(n);++i)
#define eFOR(i,a,n) for(int i=(a);i<=(n);++i)
#define rFOR(i,a,n) for(int i=(n)-1;i>=(a);--i)
#define erFOR(i,a,n) for(int i=(n);i>=(a);--i)
#define each(i, a) for(auto &i : a)
#define SORT(a) sort(a.begin(),a.end())
#define rSORT(a) sort(a.rbegin(),a.rend())
#define fSORT(a,f) sort(a.begin(),a.end(),f)
#define all(a) a.begin(),a.end()
#define out(y,x) ((y)<0||h<=(y)||(x)<0||w<=(x))
#define tp(a,i) get<i>(a)
#define line cout << "-----------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause")
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T>inline istream& operator>>(istream& is, deque<T>& v) { for (auto& a : v)is >> a; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }
template<class T>inline void print(const T& a) { cout << a << "\n"; }
template<class T, class... Ts>inline void print(const T& a, const Ts&... ts) { cout << a << " "; print(ts...); }
template<class T>inline void print(const vector<T>& v) { for (int i = 0; i < v.size(); ++i)cout << v[i] << (i == v.size() - 1 ? "\n" : " "); }
template<class T>inline void print(const vector<vector<T>>& v) { for (auto& a : v)print(a); }
inline string reversed(const string& s) { string t = s; reverse(all(t)); return t; }

int main() {
    init();

    int n, k; cin >> n >> k;
    VI a(n); cin >> a;
    FOR(i, k, n) {
        print(a[i] > a[i - k] ? "Yes" : "No");
    }

    return 0;
}

Measured memory_bytes: 3992
import Control.Applicative
import Data.List

main :: IO ()
main = solve <$> f >>= print
  where
    f = map read <$> words <$> getLine

solve :: [Int] -> Int
solve [a, b] = maybe (-1) id . find f $ [1 .. 1009]
  where
    f x = x * 8 `div` 100 == a && x `div` 10 == b


Measured memory_bytes: 508
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.HashSet;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author AnandOza
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CDistinctOrNot solver = new CDistinctOrNot();
        solver.solve(1, in, out);
        out.close();
    }

    static class CDistinctOrNot {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            HashSet<Integer> set = new HashSet<>();
            for (int i = 0; i < n; i++) {
                set.add(in.nextInt());
            }

            out.println(n == set.size() ? "YES" : "NO");
        }

    }

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

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

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

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

    }
}



Measured memory_bytes: 56496
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#define fi first
#define sc second
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

vector <ll> div_n;
vector <ll> div_n_1;

int main()
{
	ll n; scanf("%lld", &n);
	ll ans = 0;
	
	if(n == 2){
		printf("1\n");
		return 0;
	}
	for(ll i = 2; i * i <= n; i++){
		if(n % i == 0){
			div_n.pb(i);
			if(i * i != n) div_n.pb(n / i);
		}
		if((n - 1) % i == 0){
			div_n_1.pb(i);
			if(i * i != n - 1) div_n_1.pb((n - 1) / i);
		}
	}
	for(int i = 0; i < div_n.size(); i++){
		ll temp = n;
		while(temp % div_n[i] == 0) temp /= div_n[i];
		if(temp % div_n[i] == 1) ans++;
	}
	ans += 2 + div_n_1.size();
	
	printf("%lld\n", ans);
}

Measured memory_bytes: 3832
K=int(input())

ini=(K//50)*50+49
A=[ini]*50
for i in range(K%50):
    A[i]+=50
add=K%50
for i in range(50):
    a=A[i]
    if a>ini:
        A[i]-=(K//50+1)*(add-1)+(K//50)*(50-add)
    else:
        A[i]-=(K//50+1)*(add)+(K//50)*(50-add-1)
print(50)
print(*A)

Measured memory_bytes: 62060
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()

class modfact(object):
    def __init__(self,n):
        fact=[1]*(n+1); invfact=[1]*(n+1)
        for i in range(1,n+1): fact[i]=i*fact[i-1]%MOD
        invfact[n]=pow(fact[n],MOD-2,MOD)
        for i in range(n-1,-1,-1): invfact[i]=invfact[i+1]*(i+1)%MOD
        self.__fact=fact; self.__invfact=invfact

    def inv(self,n):
        assert(n>0)
        return self.__fact[n-1]*self.__invfact[n]%MOD

    def fact(self,n):
        return self.__fact[n]

    def invfact(self,n):
        return self.__invfact[n]

    def comb(self,n,k):
        if(k<0 or n<k): return 0
        return self.__fact[n]*self.__invfact[k]*self.__invfact[n-k]%MOD

    def perm(self,n,k):
        if(k<0 or n<k): return 0
        return self.__fact[n]*self.__invfact[n-k]%MOD

def resolve():
    n,k=map(int,input().split())
    E=[[] for _ in range(n)]
    for _ in range(n-1):
        a,b=map(int,input().split())
        a-=1; b-=1
        E[a].append(b)
        E[b].append(a)

    ans=[k]
    mf=modfact(k)
    Q=[(0,-1)]
    while(Q):
        v,p=Q.pop()
        if(p==-1):
            ans[0]*=mf.perm(k-1,len(E[v]))
            ans[0]%=MOD
        else:
            ans[0]*=mf.perm(k-2,len(E[v])-1)
            ans[0]%=MOD
        for nv in E[v]:
            if(nv==p): continue
            Q.append((nv,v))

    print(ans[0])
resolve()

Measured memory_bytes: 67760
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define all(x) x.begin(), x.end()
#define int long long
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int MX = 1e5 + 5, INF = 5 << 28, MOD = 1e9 + 7;

int a, b, c, d, e, f;
void input() {
  cin >> a >> b >> c >> d >> e >> f;
  ;
}

int dp[3003];  // goukei
// dp[i]
pii ans;
double maxdens = -INF;
bool findd = false;
bool mem[3003][3003] = {};
void dfs(int wa, int sugar, int water) {
  if (findd) return;
  if (wa > f) return;
  if (sugar > water) return;
  if (mem[sugar][water] == 1) return;
  mem[sugar][water] = 1;

  double dens = (water == 0 ? -1 : (sugar * 100.0) / water);
  // printf("%f\n", dens);
  if (dens > e) return;
  if (maxdens < dens) {
    maxdens = dens;
    ans = pii(wa, sugar);
    if (dens == e) {
      findd = true;
      return;
    }
  }

  if (not findd) {
    dfs(wa + 100 * a, sugar, water + 100 * a);
    dfs(wa + 100 * b, sugar, water + 100 * b);
    dfs(wa + c, sugar + c, water);
    dfs(wa + d, sugar + d, water);
  }
}
void solve() {
  if (!(e == 0)) {
    dfs(0, 0, 0);
    cout << ans.first << " " << ans.second << endl;
  } else {
    cout << a * 100 << " " << 0 << endl;
  };
}
signed main() {
  input();
  solve();
  return 0;
}

Measured memory_bytes: 4224
#include <stdio.h>
int main()
{
	int a;
	int b;
	int c;
	int sumnum = 0;
	int totalnum = 0;
	int tmpnum = 0;
	int i;
	scanf("%d %d %d", &a, &b, &c);
	for (i = 0; i <= a; i++) {
		sumnum = 0;
		tmpnum = i;
		sumnum += tmpnum / 10000;
		tmpnum = tmpnum % 10000;
		sumnum += tmpnum / 1000;
		tmpnum = tmpnum % 1000;
		sumnum += tmpnum / 100;
		tmpnum = tmpnum % 100;
		sumnum += tmpnum / 10;
		tmpnum = tmpnum % 10;
		sumnum += tmpnum;

		if ((sumnum >= b) && (sumnum <= c)) {
			totalnum += i;
		}
	}
	printf("%d\n", totalnum);
    return 0;
}

Measured memory_bytes: 128
import bisect
import copy
import heapq
import math
import sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
sys.setrecursionlimit(5000000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

n=int(input())
s=input()

cnt=Counter(s)
ans=1
for i in al:
    ans*=cnt[i]+1
    ans%=mod
ans-=1
print(ans%mod)

Measured memory_bytes: 74320
a=int(input())
b=int(input())
c=int(input())
x=int(input())
A=x//500
ans=0
for i in range(A+1):
  if(i>a):
    break
  B=(x-i*500)//100
  for j in range(B+1):
    if(j>b):
      break
    elif(0<=(x-i*500-j*100)<=50*c):
      ans += 1
print(ans)

Measured memory_bytes: 3064
import time
n=int(input())
al=[list(map(int,input().split())) for _ in range(n)]
m=n*(n-1)//2
tn=[n-1]*n
start=time.time()
for i in range(m+1):
    flg=True
    s=0
    ts=set()
    for j in range(n):
        if tn[j]>0 and j not in ts:
            t=al[j][0]-1
            if t not in ts:
                if al[t][0]==j+1:
                    al[t].pop(0)
                    tn[t]-=1
                    ts.add(t)
                    al[j].pop(0)
                    tn[j]-=1
                    flg=False
        ts.add(j)
        s+=tn[j]
    if s==0:
        print(i+1)
        exit()
    if flg:
        print(-1)
        exit()
    now=time.time()
    if (now-start)>1.6:
        print(m)
        exit()

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

int main()
{
    int A, B;
    cin >> A >> B;
    if( (B!=1 and B < A) or (A==1 and B==13)){
        cout << "Alice" << endl;
    }
    else if (A!=1 and A < B or (B == 1 and A == 13))
    {
        cout << "Bob" << endl;
    }else if ( A==B ){
        cout << "Draw" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
N,X = map(int, input().split())
A = list(map(int, input().split()))

ans = 0
prev = A[0]
if prev > X:
  ans = prev - X
  prev = X
  
for i in range(1,N):
  now = A[i]
  eat = max(0, prev + now - X)
  ans += eat
  prev = now - eat
  
print(ans)

Measured memory_bytes: 14252
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cfloat>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define int long long
#define ll long long
#define eps DBL_EPSILON
#define mod (ll)1000000007
#define INF LLONG_MAX/10
#define P pair<int,int>
#define prique priority_queue
using namespace std;
int n, s[100010];
map<P, int> dp;
signed main() {
	cin >> n;
	rep(i, n)cin >> s[i];
	rep(i, n) {//2i+1回でゴール
		REP(j, n - 1) {//a-b=j
			if (n - 1 <= i * j + j)break;
			if ((n - 1 - i * j) % j == 0 && (n - 1 - i * j) / j * 2 <= 2 * i)continue;
			//2i回目の後いるのはi*j番
			if (i)dp[make_pair(i, j)] = dp[make_pair(i - 1, j)] + s[n - 1 - i * j] + s[i * j];
			else dp[make_pair(i, j)] = s[n - 1 - i * j] + s[i * j];
		}
	}
	int ans = 0;
	for (pair<P, int> p : dp) {
		ans = max(ans, p.second);
	}
	cout << ans << endl;
}

Measured memory_bytes: 71296
#include <iostream>
#include <vector>
#include <string.h>
#include <set>
#include <map>
#include <unordered_map>
#include <assert.h>
#include <algorithm>
#include <queue>
#include <bitset>
#include <stack>
#include <chrono>
#include <random>
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define ll long long
#define INF 1000000000000000000
#define MOD 1000000007
#define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define uid uniform_int_distribution <int>
using namespace std;
// Read the question carefully and see all the given sample tests
// Think about the correctness before implementing

/*
 * 4 6 3 2 8 5 7 1
 * 
 * 
 * */
using tii = tuple<int, int, int, int>;
using PII = pair<int, int>;
const int N = 200 * 1000 + 5;
vector <int> A(N);
vector <PII> tree(4 * N, {MOD, MOD});
void build(int l, int r, int i) {
	if (l == r) {
		if (l % 2 == 1) {
			tree[i].ff = A[l];
		}
		else {
			tree[i].ss = A[l];
		}
		return;
	}
	int mid = (l + r) / 2;
	build(l, mid, 2 * i);
	build(mid + 1, r, 2 * i + 1);
	tree[i].ff = min(tree[2 * i].ff, tree[2 * i + 1].ff);
	tree[i].ss = min(tree[2 * i].ss, tree[2 * i + 1].ss);
}
PII query(int ql, int qr, int l, int r, int i) {
	if (ql > r || qr < l)
		return {MOD, MOD};
	if (ql <= l && r <= qr)
		return tree[i];
	int mid = (l + r) / 2;
	PII a = query(ql, qr, l, mid, 2 * i);
	PII b = query(ql, qr, mid + 1, r, 2 * i + 1);
	return {min(a.ff, b.ff), min(a.ss, b.ss)};
}
int main() {
	int n;
	cin >> n;
	vector <int> rm(n + 1);
	for (int i = 1; i <= n; i++) {
		cin >> A[i];
		rm[A[i]] = i;
	}
	build(1, n, 1);
	priority_queue<tii, vector<tii>, greater<tii>> pq;
	//pq.push(make_tuple(1, 1, 1, 1));
	auto ins = [&] (int l, int r) {
		if (l % 2 == 1) {
			int val1 = query(l, r, 1, n, 1).ff;
			int val2 = query(rm[val1], r, 1, n, 1).ss;
			pq.push(make_tuple(val1, val2, l, r));
		}
		else {
			int val1 = query(l, r, 1, n, 1).ss;
			int val2 = query(rm[val1], r, 1, n, 1).ff;
			pq.push(make_tuple(val1, val2, l, r));
		}
	};
	auto decompose = [&] (int l, int p1, int p2, int r) {
		if (l <= p1 - 1) {
			ins(l, p1 - 1);
		}
		if (p1 + 1 <= p2 - 1) {
			ins(p1 + 1, p2 - 1);
		}
		if (p2 + 1 <= r) {
			ins(p2 + 1, r);
		}
	};
	ins(1, n);
	vector <int> ans;
	while(!pq.empty()) {
		int val1, val2, l, r;
		tie(val1, val2, l, r) = pq.top();
		pq.pop();
		ans.push_back(val1);
		ans.push_back(val2);
		decompose(l, rm[val1], rm[val2], r);
	}
	for (auto g : ans)
		cout << g << " ";
}


Measured memory_bytes: 10868
#include <iostream>
#include <vector>
#include <queue>
#include <utility>

std::vector<int> dx = { 1, 0, -1,  0 };
std::vector<int> dy = { 0, 1,  0, -1 };

int BFS(std::vector<std::vector<char>> s, int H, int W, int sharpCnt) {
	std::queue<std::pair<int, int>> candidatePntQueue;
	std::vector<std::vector<int>> dist(H, std::vector<int>(W, -1));
	int x, y, nx, ny;

	candidatePntQueue.emplace(0, 0);
	dist[0][0] = 1;

	while (!candidatePntQueue.empty()) {
		x = candidatePntQueue.front().first;
		y = candidatePntQueue.front().second;
		candidatePntQueue.pop();

		for (int i = 0; i < 4; i++) {
			nx = x + dx[i];
			ny = y + dy[i];

			if (nx < 0 || nx >= H) {//マップの範囲外
				continue;
			}
			if (ny < 0 || ny >= W) {//マップの範囲外
				continue;
			}
			if (s[nx][ny] == '#') {//障害物アリ
				continue;
			}
			if (dist[nx][ny] != -1) {//探索済み
				continue;
			}

			dist[nx][ny] = dist[x][y] + 1; 
			candidatePntQueue.emplace(nx, ny);
		}
	}

	if (dist[H - 1][W - 1] == -1) {
		return -1;
	}
	return H*W - sharpCnt - dist[H-1][W-1];
}

int main() {
	int H = 0, W = 0;
	int sharpCnt = 0;
	std::cin >> H >> W;

	std::vector<std::vector<char>> s( H, std::vector<char>(W, 0) );
	char tmp;

	for(int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			std::cin >> s[i][j];

			if (s[i][j] == '.') {
				continue;
			}
			sharpCnt++;
		}
	}

	std::cout << BFS(s, H, W, sharpCnt) << std::endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

template <typename Monoid> struct SegmentTree {
    using F = function<Monoid(Monoid, Monoid)>;

  private:
    int n;
    vector<Monoid> node;
    Monoid E;
    F f;

  public:
    SegmentTree(vector<Monoid> &v, Monoid e, const F func) : f(func), E(e) {
        int sz = v.size();
        n = 1;
        while(n < sz) {
            n *= 2;
        }
        node.resize(2 * n - 1, E);
        for(int i = 0; i < sz; i++) {
            node[i + n - 1] = v[i];
        }
        for(int i = n - 2; i >= 0; i--) {
            node[i] = f(node[2 * i + 1], node[2 * i + 2]);
        }
    }

    void update(int i, Monoid val) {
        i += (n - 1);
        node[i] = val;
        while(i > 0) {
            i = (i - 1) / 2;
            node[i] = f(node[2 * i + 1], node[2 * i + 2]);
        }
    }

    Monoid query(int a, int b, int i = 0, int l = 0, int r = -1) {
        if(r < 0) {
            r = n;
        }
        if(r <= a || b <= l) {
            return E;
        }
        if(a <= l && r <= b) {
            return node[i];
        }
        Monoid vl = query(a, b, 2 * i + 1, l, (l + r) / 2);
        Monoid vr = query(a, b, 2 * i + 2, (l + r) / 2, r);
        return f(vl, vr);
    }

    Monoid operator[](const int &i) const { return node[i + n - 1]; }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, t;
    cin >> n >> t;
    vector<int> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    SegmentTree<int> segmax(a, -INF, [](int p, int q) { return max(p, q); });
    // SegmentTree<int> segmin(a, INF, [](int p, int q) { return min(p, q); });
    map<int, int> mp;
    for(int i = 0; i < n - 1; i++) {
        int mx = segmax.query(i + 1, n);
        // int mn = segmin.query(i + 1, n);
        if(mx > a[i]) {
            mp[mx - a[i]]++;
        }
    }
    auto it = mp.rbegin();
    cout << it->second << endl;
}


Measured memory_bytes: 6400
#include<stdio.h>
#define MAX 100000
#define SENTINEL 2000000000
struct A{
  char m;
  int value;
};
struct A L[MAX/2+2],R[MAX/2+2];
void merge(struct A a[],int n,int left,int mid,int right){
  int i,j,k;
  int n1=mid-left;
  int n2=right-mid;
  for(i=0;i<n1;i++)L[i]=a[left+i];
  for(i=0;i<n2;i++)R[i]=a[mid+i];
  L[n1].value=R[n2].value=SENTINEL;
  i=j=0;
  for(k=left;k<right;k++){
    if(L[i].value<=R[j].value)a[k]=L[i++];
    else a[k]=R[j++];
  }

}
void mergeSort(struct A a[],int n,int left,int right){
  int mid;
  if(left+1<right){
    mid=(left+right)/2;
    mergeSort(a,n,left,mid);
    mergeSort(a,n,mid,right);
    merge(a,n,left,mid,right);
  }
}int partition(struct A a[],int n,int p,int r){
  struct A x,y;
  int i,j;
  x=a[r];
  i=p-1;
  for(j=p;j<r;j++){
    if(a[j].value<=x.value){
      i++;
      y=a[i];
      a[i]=a[j];
      a[j]=y;
    }
  }
  y=a[i+1];
  a[i+1]=a[r];
  a[r]=y;
  return i+1;
}
void quickSort(struct A a[],int n,int p,int r){
  int q;
  if(p<r){
    q=partition(a,n,p,r);
    quickSort(a,n,p,q-1);
    quickSort(a,n,q+1,r);
  }
}
int main(){
  int n,i,v;
  struct A a[MAX],b[MAX];
  char S[10];
  int stable=1;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s %d",S,&v);
    a[i].m=b[i].m=S[0];
    a[i].value=b[i].value=v;
  }
  mergeSort(a,n,0,n);
  quickSort(b,n,0,n-1);
  for(i=0;i<n;i++){
    if(a[i].m!=b[i].m)stable=0;  
  }
  if(stable==1)printf("Stable\n");
  else printf("Not stable\n");
  for(i=0;i<n;i++){
    printf("%c %d\n",b[i].m,b[i].value);
  }
  return 0;
}

Measured memory_bytes: 2952
#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
vector<int> edge[600005];
int ans[600005];
int main(){
    int N,M;
    cin>>N>>M;

    for(int i=0;i<M;i++){
        int a,b;
        cin>>a>>b;
        edge[a].push_back(b+150000);
        edge[a+150000].push_back(b+300000);
        edge[a+300000].push_back(b);
    }
    int S,T;
    cin>>S>>T;

    for(int i=0;i<600005;i++)ans[i]=2100000000;
    queue<int> Qx,Qte;
    Qx.push(S);
    Qte.push(0);
    while(!Qx.empty()){
        int a,b;
        a=Qx.front();
        b=Qte.front();
        Qx.pop();
        Qte.pop();
        for(int i=0;i<edge[a].size();i++){
            if(ans[edge[a][i]]>b+1){
                ans[edge[a][i]]=b+1;
                Qx.push(edge[a][i]);
                Qte.push(b+1);
            }
        }
    }
    if(ans[T]==2100000000){
        cout<<-1<<endl;
        return 0;
    }
    cout<<ans[T]/3<<endl;
    return 0;
}


Measured memory_bytes: 25984
n = int(input())

a = list(map(int, input().split()))

b = list(map(int, input().split()))

c = [0] + list(map(int, input().split()))

ans = 0
tmp = 0
for i in a:
    ans += b[i-1]
    if tmp + 1 == i:
        ans += c[i-1]

    tmp = i

print(ans)


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

int main(){
  int N, K, X, Y;
  cin >> N >> K >> X >> Y;
  
  int sum = 0;
  for (int i = 1; i <= N; i++){
    if (i <= K){
      sum += X;
    }
    else{
      sum += Y;
    }
  }
  cout << sum << endl;


}


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

int main(){
  int flag;
  vector<vector<int>>a(3,vector<int>(3));
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      cin >>a.at(i).at(j);
    }
  }
  vector<vector<int>>tmp(3,vector<int>(3,0));
  int n;cin>>n;
  vector<int>b(n);
  for(int i=0;i<n;i++){
    cin >>b.at(i);
    for(int j=0;j<3;j++){
      for(int k=0;k<3;k++){
        if(a.at(j).at(k)==b.at(i)){
          tmp.at(j).at(k)=1;
        }
      }
    }
  }
  //tate
  for(int i=0;i<3;i++){
    if(tmp.at(i).at(0)!=1)
      continue;
    if(tmp.at(i).at(0)==tmp.at(i).at(1)&&tmp.at(i).at(0)==tmp.at(i).at(2)){
      cout <<"Yes"<<endl;
      return 0;
    }
  }
  //yoko
  for(int i=0;i<3;i++){
    if(tmp.at(0).at(i)!=1)
      continue;
    if(tmp.at(0).at(i)==tmp.at(1).at(i)&&tmp.at(0).at(i)==tmp.at(2).at(i)){
      cout <<"Yes"<<endl;
      return 0;
    }
  }
  //naname1
  if(tmp.at(0).at(0)==1){
    if(tmp.at(0).at(0)==tmp.at(1).at(1)&&tmp.at(0).at(0)==tmp.at(2).at(2)){
      cout <<"Yes"<<endl;
      return 0;
    }
  }
  //naname2
  if(tmp.at(2).at(0)==1){
    if(tmp.at(2).at(0)==tmp.at(1).at(1)&&tmp.at(2).at(0)==tmp.at(0).at(2)){
      cout <<"Yes"<<endl;
      return 0;
    }
  }
  //bingonasi
  cout <<"No"<<endl;
  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

string s[404]; /* NOT FOUND */

int h,w,ufp[160410];
ll ufr[160410];

int pos(int i, int j){
	return i*w+j;
}

void ufinit(){
	int i,j,p;
	for(i=0; i<h; ++i){
		for(j=0; j<w; ++j){
			p = pos(i,j);
			ufp[p] = p;
			if(s[i][j]=='.'){
				ufr[p] = 1ll;
			}else{
				ufr[p] = 0ll;
			}
		}
	}
}

int ufind(int x){
	if(ufp[x] != x){
		ufp[x] = ufind(ufp[x]);
	}
	return ufp[x];
}

void unionf(int x, int y){
	x = ufind(x);
	y = ufind(y);
	if(x==y){
		return;
	}
	if(ufr[x] > ufr[y]){
		ufp[y] = x;
		ufr[x] += ufr[y];
	}else{
		ufp[x] = y;
		ufr[y] += ufr[x];
	}
}

int main(void){
	int i,j,p,q,d[4][2]={{-1,0},{0,-1},{0,1},{1,0}},k;
	ll ans=0ll;
	cin >> h >> w;
	for(i=0; i<h; ++i){
		cin >> s[i];
	}
	ufinit();
	for(i=0; i<h; ++i){
		for(j=0; j<w; ++j){
			for(k=0; k<4; ++k){
				p = i+d[k][0];
				q = j+d[k][1];
				if(!(p>=0 && p<h && q>=0 && q<w)){
					continue;
				}
				if(s[i][j]!=s[p][q]){
					unionf(pos(i,j),pos(p,q));
				}
			}
		}
	}
	for(i=0; i<h; ++i){
		for(j=0; j<w; ++j){
			if(s[i][j]=='#'){
				ans += ufr[ufind(pos(i,j))];
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
const int N = 100001;
typedef unsigned long long ll;
int n,k;
int a[N];
int main() {
    int n;
    cin >> n;
    for(int i = 0; i < n; i++)
        for (int j = 0; j < n; ++j) {
            if (i * 4 + 7 * j == n){
                cout << "Yes" << endl;
                return 0;
            }
        }
     cout << "No" << endl;
    return 0;
}

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

typedef long long            ll;
typedef unsigned long long   ull;
typedef vector<int>          vi;
typedef vector<ll>           vl;
typedef pair<int, int>       pi;
typedef pair<ll, ll>         pl;
typedef vector<pi>           vpi;
typedef vector<pl>           vpl;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

#define read        freopen("in.c", "r", stdin)
#define write       freopen("out.c", "w", stdout)
#define all(a)      a.begin(), a.end()
#define bye         exit(0)
#define mp          make_pair
#define ff          first
#define ss          second
#define L(x)        ((x) << 1)
#define R(x)        ((x) << 1 | 1)
#define SZ(a)       (ll)(a).size()
#define pb          push_back
#define eb          emplace_back
#define eps         1e-9
#define inf         (1000000000)
#define infl        (1000000000000000000LL)
#define cs(p)       printf("Case %d:", (p)++)
#define ptc(c)      putchar(c)
#define gtc()       getchar()
#define nl          puts("")
#define sp          printf(" ")
#define out(a)      printf("%lld", (ll)(a))
#define SET(a, x)   memset((a), x, sizeof(a))
#define dbg(x)      cout << "--- " << #x << " = " << (x) << '\n'

ll bgm(ll a, ll b, ll m) {
    b = (b == -1) ? (m - 2) : b;
    a %= m;
    ll rem = 1;
    while(b != 0) {
        if(b&1)
            rem = (rem * a) % m;
        a = (a * a) % m;
        b >>= 1;
    }
    return rem;
}

inline ll in() {
    ll a;
    assert(scanf("%lld", &a) != EOF);
    return a;
}

const int MAX = 1000000 + 5;
const int LEN = 50;
const ll MOD = 1000000007;


int n,m,sum;
int ara[105][105];

void reset(){
    for(int i=0;i<=105;i++){
        for(int j=0;j<=105;j++) ara[i][j]=0;
    }
}

int main() {
    //read,write;
    cin >> n >> m;
    int j=0;
    for(int i=0;i<n;i++){
        sum=0;
        for(j=0;j<m;j++){
            cin >> ara[i][j];
            sum+=ara[i][j];
            if(j==m-1) ara[i][j+1]=sum;
        }
    }
    sum=0;
    for(j=0;j<=m;j++){
        sum=0;
        for(int i=0;i<=n;i++){
            sum+=ara[i][j];
            if(i==n) ara[i][j]=sum;
        }
    }
    for(int i=0;i<=n;i++){
        for(j=0;j<m;j++){
            cout << ara[i][j] << " ";
        }
        cout << ara[i][j] << endl;
    }

    return 0;
}



Measured memory_bytes: 3112
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>
const int inf = 1 << 30;
const ll linf = 1e18;
template<class T> void chmin(T& x, T y){if(x > y) x = y;}
template<class T> void chmax(T& x, T y){if(x < y) x = y;}

int N;
ll A[2010];
ll dp[2010][2010];
vector<pll> as;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> N;
    for(int i = 0; i < N; i++){
        ll A;
        cin >> A;
        as.push_back(pll{A, i});
    }
    sort(as.rbegin(), as.rend());
    set<pll> st;
    queue<pll> q;
    q.push({0, N - 1});
    st.insert({0, N - 1});
    ll ans = 0;
    int cnt = 0;
    while(!q.empty()){
        pii p = q.front();
        q.pop();
        ll l = p.first;
        ll r = p.second;
        chmax(ans, dp[l][r]);
        if(l > r) continue;
        ll val = as[N - 1 - r + l].first;
        ll idx = as[N - 1 - r + l].second;
        chmax(dp[l + 1][r], dp[l][r] + val * abs(l - idx));
        if(st.find({l + 1, r}) == st.end()) st.insert({l + 1, r}), q.push({l + 1, r});
        chmax(dp[l][r - 1], dp[l][r] + val * abs(r - idx));
        if(st.find({l, r - 1}) == st.end()) st.insert({l, r - 1}), q.push({l, r - 1});
    }
    cout << ans << endl;
}

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

int main()
{
    int n;
    cin>>n;
    int i,j=0,ar[n],pr[n];
    for(i = 0; i< n; i++)
    {
        cin>>ar[i];
        pr[i] = ar[i];
    }
    sort(ar, ar+n);
    for(i = 0; i< n; i++)
    {
        if(ar[i] != pr[i])
            j++;
    }
    if(j==0 || j==2)
        cout<<"YES";
    else
        cout<<"NO";

    return 0;
}


Measured memory_bytes: 256
#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;
    cin >> s;
    int ans=700;
    rep(i,3){
        if(s[i]=='o')ans+=100;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3612
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <stdio.h>

using namespace std;

//typedefリスト
typedef vector<long long int> vint;
typedef vector<string> vstr;
typedef long long int llint;



int main(void) {
	int N,M,ans;
	cin >> N;
	vint T(N),Y(N);
	for (int i = 0; i < N; i++){
	    cin >> T[i];
	    Y[i]=T[i];
	}
	cin >> M;
	vint P(M), X(M);
	for (int i = 0; i < M; i++)cin >> P[i] >> X[i];

	for (int i = 0; i < M; i++){
		ans = 0;
		T[P[i]-1] = X[i];
		for (int j = 0; j < N; j++){
			ans += T[j];
		}
		T[P[i]-1]=Y[P[i]-1];
		cout << ans << endl;
	}
	
}

Measured memory_bytes: 256
n, m, x, y = map(int, input().split())
x_l = list(map(int, input().split()))
y_l = list(map(int, input().split()))
x_max = max(x_l)
y_min = min(y_l)

def f():

  if x <= x_max <= y and x <= y_min <= y:

    if x_max < y_min:
      return 'No War'
  
  return 'War'


print(f())

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

int main (){
    int x,a,b;
    cin >> x ;
    a=x/100;
    b=x%100;
    double c=(double)b/a;
    if(c>5){
        cout << 0 << endl;
    }else {
        cout << 1 << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>

using namespace std;

int main() {
  map<string, int> s;
  s["SUN"] = 7;
  s["MON"] = 6;
  s["TUE"] = 5;
  s["WED"] = 4;
  s["THU"] = 3;
  s["FRI"] = 2;
  s["SAT"] = 1;
  string in; cin>>in;
  cout << s[in] << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
template<class T> bool max(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

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

int main(void){
    int N;
    cin >> N;
    long long h[100010], dp[100010];
    
    for (int i = 0; i < 100010; i++) dp[i] = 1000100;
    for (int i = 0; i < N; i++) cin >> h[i];
    
    dp[0] = 0;
    
    for (int i = 1; i < N; i++) {
    
        dp[i] = abs(h[i] - h[i-1]) + dp[i-1];
        
        if (i > 1) {
            min(dp[i], abs(h[i] - h[i-2]) + dp[i-2]);
        }
    }
    
    cout << dp[N-1] << endl;
}


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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
#define DEBUG freopen("in.txt", "r", stdin);

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

string s;
int ans;
int main() {
    cin >> s;
    for (int i = 0; i < s.length(); ++i) {
        if (s[i] == '+')
            ++ans;
        else
            --ans;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3612
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

k = int(input())

ans = 0
for x in range(1, k+1):
    for y in range(1, k+1):
        for z in range(1, k+1):
            ans += gcd(x, y, z)

print(ans)


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

#define SZ(v) ((int)(v).size())
using ll = long long;

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

	int nb_livres, nb_algos, target;
	cin >> nb_livres >> nb_algos >> target;
	vector<int> cost(nb_livres);
	vector<vector<int> > inc(nb_livres);
	for (int i(0); i < nb_livres; ++i)
	{
		cin >> cost[i];
		inc[i].resize(nb_algos);
		for (int j(0); j < nb_algos; ++j)
			cin >> inc[i][j];
	}

	int best(1e9);
	for (int mask(0); mask < (1<<nb_livres); ++mask)
	{
		vector<int> mastery(nb_algos);
		int c(0);
		for (int i(0); i < nb_livres; ++i)
			if ((1<<i) & mask)
			{
				c += cost[i];
				for (int j(0); j < nb_algos; ++j)
					mastery[j] += inc[i][j];
			}
		bool ok(true);
		for (int i(0); i < nb_algos; ++i)
			if (mastery[i] < target)
				ok = false;
		if (ok)
			best = min(best, c);
	}
	if (best == 1e9)
		best = -1;
	cout << best << endl;
}


Measured memory_bytes: 3664
from functools import reduce
from operator import mul
def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    elif r<0: return 0
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under

n = int(input())
s = [''.join(sorted(input())) for _ in range(n)]


ans = 0
d = {}
for i in s:
    d[i] = d.get(i, 0) + 1

for i in d.values():
    ans += cmb(i, 2)

print(ans)

Measured memory_bytes: 20012
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <math.h>
#include <numeric>
#include <set>
#include <list>
#include <bitset>
using namespace std;

int main()
{
    int N, T;
    cin >> N >> T;
    vector<pair<int, int>> X(N);
    for (int i = 0; i < N; i++)
    {
        pair<int, int> tmp;
        cin >> tmp.first >> tmp.second;
        X[i] = tmp;
    }
    sort(X.begin(), X.end());
    bool flag = false;
    for (int i = 0; i < N; i++)
    {
        if (X[i].second <= T)
        {
            flag = true;
            cout << X[i].first << endl;
            break;
        }
    }
    if (!flag)
    {
        cout << "TLE" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
using ll = long long;
using ld = long double;
 
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;
 
typedef pair<ll, ll> P;
 
#define bit(n) (1LL << (n))
 
//#define int long long
 
#define all(v) v.begin(), v.end()
#define sortAl(v) sort(all(v))
#define sortAlr(v)          \
  sort(v.begin(), v.end()); \
  reverse(v.begin(), v.end())
 
#define rep(i, n) for (ll i = 0; i < n; i++)
#define REP(i, n) for (ll i = 1; i < n; i++)
 
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)
 
template <class T>
inline void chmax(T &a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T &a, T b) {
  a = std::min(a, b);
}
 
#define mod (ll)(1e9 + 7)
#define INF LLONG_MAX
 
#define MAX_DIGIT 45
 
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
 
  ll n, k;
  cin >> n >> k;
 
  vll a(n);
  vector<bitset<MAX_DIGIT>> bs(n);
  rep(i, n) {
    cin >> a[i];
    bs[i] = a[i];
  }
 
  if (k == 0) {
    cout << a[0] << endl;
    return 0;
  }
 
  vvll memo(MAX_DIGIT, vll(2));
 
  rep(d, MAX_DIGIT) {
    ll cnt = 0;
    rep(i, n) {
      if (bs[i][d]) {
        cnt++;
      }
    }
    memo[d][0] = cnt << d;
    memo[d][1] = (n - cnt) << d;
  }
 
  bitset<MAX_DIGIT> m;
  m = k;
 
  vvll dp(MAX_DIGIT+1, vll(2));
  ll d = MAX_DIGIT-1;
 
  while (m[d] == 0) {
    dp[d][0] = dp[d + 1][0] + memo[d][0];
    d--;
  }
  
  dp[d][0] = dp[d + 1][0] + max(memo[d][0], memo[d][1]);
  dp[d][1] = dp[d + 1][0] + memo[d][0];
  d--;
 
  for (; d >= 0; d--) {
    dp[d][1] = dp[d + 1][1] + max(memo[d][0], memo[d][1]);
 
    if (m[d]) {
      dp[d][0] = dp[d + 1][0] + memo[d][1];
      chmax(dp[d][1], dp[d + 1][0] + memo[d][0]);
    } else {
      dp[d][0] = dp[d + 1][0] + memo[d][0];
    }
  }
 
  cout << max(dp[0][0],dp[0][1]) << endl;
 
  return 0;
}

Measured memory_bytes: 1792
x=input()
A = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
a = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
if x in A:
	print('A')
if x in a:
	print('a')

Measured memory_bytes: 61792
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,m;
  cin>>n>>m;
  int arr[m];
  for(int i=0; i<m; ++i)
    cin>>arr[i];
  int uw[m-1];
  int sum(0);
  for(int i=0; i<=m-2; ++i)
  {
      if(arr[i]<=arr[i+1])
    uw[i]=abs(arr[i]-arr[i+1]);
    else
        uw[i]=abs(n-arr[i])+arr[i+1];
  sum+=uw[i];
}
  int ansi(sum);
int mn(sum);
  for(int i=0; i<m-1; ++i)
  {

  sum-=uw[i];
   sum+=abs(arr[m-1]-n)+arr[0];
    ansi=min(ansi,sum);
     sum=mn;
  }
  cout<<ansi;
}


Measured memory_bytes: 1792
#include <cstdio>
#include <algorithm>
#include <functional>

using namespace std;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define DUMP(a, n) REP(i, n) printf("%d%c", a[i], i + 1 == n ? '\n' : ' ')

typedef long long ll;

const int N_MAX = 100000;
const int A_I_MAX = 1000000000;

int N;
int a[N_MAX * 3];

void solve() {
  sort(a, a + 3 * N, greater<int>());
  ll ans = 0;
  REP(i, N) {
    ans += a[i * 2 + 1];
  }
  printf("%lld\n", ans);
}

void input() {
  scanf("%d", &N);
  REP(i, 3 * N) scanf("%d", a + i);
}

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


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

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

    for(int i=0;i<s.length()/2;i++){
    if(s[i*2]=='L'){
        ans="No";
      //cout<<i<<"even"<<endl;
        break;
        }
    else if(s[i*2+1]=='R'){
        ans="No";
      //cout<<i<<"odd"<<endl;
        break;
        }
    }
    if(s.length()%2==1){
        if(s[s.length()-1]=='L'){
          ans="No";
          //cout<<"last"<<endl;
        }
    }
	
	cout << ans<< endl;

}


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

using namespace std;

int main()
{
  string order;
  int topping = 0;
  int fee = 700;
  
  cin >> order;
  
  if (order[0] == 'o') {
    topping++;
  }
  if (order[1] == 'o') {
    topping++;
  }
  if (order[2] == 'o') {
    topping++;
  }
  fee = fee + topping * 100;
  cout << fee << endl;
  return 0;
}

Measured memory_bytes: 256
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
def resolve():
    stack = []
    for c in input():
        if c != 'B':
            stack.append(c)
        else:
            if stack:
                stack.pop()
    print(''.join(stack))
resolve()

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

int main(){
    int a,b,c,buf;
    cin >> a >> b >> c;
    if (a>b){
        buf=a;
        a=b;
        b=buf;
    }
    if (b>c){
        buf=b;
        b=c;
        c=buf;
    }
    if (a>b){
        buf=a;
        a=b;
        b=buf;
    }
    cout << a << " " << b << " " << c << endl;
    return 0;
}


Measured memory_bytes: 3060
#include <stdio.h>

int main() {
	int sx, sy, tx, ty, a, b, h;

	scanf("%d%d%d%d", &sx, &sy, &tx, &ty);
	a = tx - sx;
	b = ty - sy;
	for (h = 1; h <= b; h++)
		printf("U");
	for (h = 1; h <= a; h++)
		printf("R");
	for (h = 1; h <= b; h++)
		printf("D");
	for (h = 1; h <= a; h++)
		printf("L");
	printf("L");
	for (h = 1; h <= b; h++)
		printf("U");
	printf("U");
	for (h = 1; h <= a; h++)
		printf("R");
	printf("RDR");
	for (h = 1; h <= b; h++)
		printf("D");
	printf("D");
	for (h = 1; h <= a; h++)
		printf("L");
	printf("LU\n");
	return 0;
}


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

bool solve(const vector<string>& board, char c)
{
  if (board[0][0] == c && board[0][1] == c && board[0][2] == c ||
      board[1][0] == c && board[1][1] == c && board[1][2] == c ||
      board[2][0] == c && board[2][1] == c && board[2][2] == c ||
      board[0][0] == c && board[1][0] == c && board[2][0] == c ||
      board[0][1] == c && board[1][1] == c && board[2][1] == c ||
      board[0][2] == c && board[1][2] == c && board[2][2] == c ||
      board[0][0] == c && board[1][1] == c && board[2][2] == c ||
      board[2][0] == c && board[1][1] == c && board[0][2] == c)
    return true;
  return false;
}

int main()
{
  vector<string> board(3);
  while (cin >> board[0] >> board[1] >> board[2]) {
    if (board[0] == "0")
      break;

    if (solve(board, 'b'))
      cout << "b" << endl;
    else if (solve(board, 'w'))
      cout << "w" << endl;
    else
      cout << "NA" << endl;
  }
  return 0;
}

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

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define rep(i, n) repd(i, 0, n)

using namespace std;

using ll = long long;
using ul = unsigned long long;
ll mod = 1000000007;

int main() {
source:
    ll n, k;
    cin >> n >> k;
    ll ans = 0;
    while (n > 0) {
        ans++;
        n /= k;
    }
    cout << ans << endl;
    return 0;
}



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

int main() {
  int N, K;
  cin >> N >> K;
  int goukei=0;
 for (int i = 0; i < N; i++) {
   int x;
   cin >> x;
   if ( K < x)
     goukei += (x-K)*2;
   else if ((K-x) < x)
     goukei += (K-x)*2;
   else
     goukei += x*2;
 }
  cout << goukei << endl;
}

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

using namespace std;
typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REP(a, b, m) for (ll a = (ll)(b); a < (ll)(m); a++)

int main()
{
    ll n;
    cin >> n;
    if (n / 100000 > 0)
    {
        ll sum = n - 1 - 9000 - 90;
        cout << sum << endl;
    }
    else if (n / 10000 > 0)
    {
        int sum = n - 9000 - 90;
        cout << sum << endl;
    }
    else if (n / 1000 > 0)
    {
        cout << 999 - 90 << endl;
    }
    else if (n / 100 > 0)
    {
        cout << n - 90 << endl;
    }
    else if (n / 10 > 0)
    {
        cout << 9 << endl;
    }
    else
    {
        cout << n  << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    int a;
    int i;
    map<int,int>mp;
    for(i=0;i<N;i++){
        cin>>a;
        mp[a]=i+1;
    }
    for(i=1;i<N+1;i++)cout << mp[i] << endl;
}

Measured memory_bytes: 5504
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
constexpr char ln =  '\n';

const int mx=100010;
const ll mod=1e9+7;

int main(){
  ll n,k;
  cin >> n >> k;
  ll ans = 1;
  while(n--){
    if(ans>k){
      ans += k;
    } else {
      ans *= 2;
    }
  }
  cout << ans << ln;
  return 0;
}

Measured memory_bytes: 256