akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <map>
#include <list>
#include <climits>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>

// #define cerr if(false)cerr
#define watch(x) cerr << "> " << #x << ": " << x << "\n";

using namespace std;

template <typename T>
std::ostream &operator <<(std::ostream &out, vector<T> &v) {
	for (typename vector<T>::size_type i = 0; i < v.size(); ++i)
		out << v[i] << " ";
	out << "\n";
    return out;
}
template <typename T, typename N>
std::ostream &operator <<(std::ostream &out, vector<pair<T, N> > &v) {
	for (size_t i = 0; i < v.size(); ++i)
		out << "(" << v[i].first << ", " << v[i].second << ") ";
	out << "\n";
    return out;
}
template <typename T>
std::ostream &operator <<(std::ostream &out, vector<vector<T> > &v) {
	for (size_t i = 0; i < v.size(); ++i) {
		for (size_t j = 0; j < v[i].size(); ++j) {
			out << v[i][j] << " ";
		}
		out << "\n";
	}
   	return out;
}

int main() {

	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

	int a;
	cin >> a;

	cout << a + a * a + a * a * a << "\n";

	return 0;

}

Measured memory_bytes: 3600
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#define rep(i,n) for (int i=0; i<n;++i)
#define rep_down(i,n) for (int i=n-1; i>=0;--i)
#define ALL(a)  (a).begin(),(a).end()
typedef long long ll;
using namespace std;
const int INF = 1000000007;
string S;

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

  cin >> S;
  int ans = INF;
  rep(i, S.size()-2){
    int a = (S[i] - '0')*100+(S[i+1] - '0')*10+S[i+2] - '0';
    ans = min(ans, abs(753-a));
  }

  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    long A[] = new long[N];
    for(int i=0;i<N;i++){
      A[i]=sc.nextLong();
    }
    Arrays.sort(A);
    long P = 1000000007L;
    boolean isOdd=(N%2==1);
    long answer =1;
    if(isOdd){//奇数人の場合
      if(A[0]!=0){
        System.out.println(0);
        return;
      }else{
        for(int i=1;i<N;i++){
          if(i%2==1){
            if(A[i]!=i+1){
              System.out.println(0);
              return;
            }else{
              continue;
            }
          }else{
            if(A[i]!=i){
              System.out.println(0);
              return;
            }else{
              answer=(answer*2)%P;
            }
          }
        }
      }
    }else{//偶数人の場合
      for(int i=0;i<N;i++){
        if(i%2==0){
          if(A[i]!=i+1){
            System.out.println(0);
            return;
          }else{
            continue;
          }
        }else{
          if(A[i]!=i){
            System.out.println(0);
            return;
          }else{
            answer=(answer*2)%P;
          }
        }
      }
    }
    System.out.println(answer);
      
              
  }
  

  
}

Measured memory_bytes: 50352
n = gets.chomp.to_i
as = []
bs = []

n.times do 
  a, b = gets.chomp.split.map(&:to_i)
  as << a
  bs << b
end

as.sort!
bs.sort!

ans = if n.odd?
  bs[n / 2] - as[n / 2] + 1
else
  bs[n / 2] + bs[n / 2 - 1] - (as[n / 2] + as[n / 2 - 1]) + 1
end

puts ans

Measured memory_bytes: 20196
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

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

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

char str[500010];
char buf[500010];
int len;

bool check(int t)
{
	sprintf(buf, "%d", t * 9);
	int len2 = strlen(buf);
	for (int i = 0; i < len2; i++) buf[i] -= '0';
	reverse(buf, buf + len2);

	int sum = 0;

	for (int i = 0, up = 0; i < max(len, len2) || up; i++)
	{
		int z = buf[i] + str[i] + up;
		sum += z % 10;
		up = z / 10;
	}

	return sum <= 9 * t;
}

int main()
{
	scanf("%s", str);
	len = strlen(str);
	for (int i = 0; i < len; i++) str[i] -= '0';
	reverse(str, str + len);
	for (int i = 0, up = 0; i < len || up; i++)
	{
		if (i == len) ++len;
		int z = str[i];
		str[i] = (z * 9 + up) % 10;
		up = (z * 9 + up) / 10;
	}

	int lo = 1, hi = len - 1, ans = len;
	while (lo <= hi)
	{
		int mid = (lo + hi) / 2;
		if (check(mid))
		{
			ans = mid; hi = mid - 1;
		}
		else lo = mid + 1;
	}

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

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
//#define int long long
#define ar array<int,2>
#define inf 1000000000000000000 
int mod=1e9+7;
int min(int a,int b){return (a<b)?a:b;}
int max(int a,int b){return (a>b)?a:b;}
int fp(int a,int b){if(b==0) return 1;int x=fp(a,b/2);x=(x*x)%mod;if(b&1) x=(x*a)%mod;return x;}


const int N=1e6+5;
int mp[N]={0};


void solve()
{
  int n;
  cin>>n;
  string s,s1;
  cin>>s;
  int w=0,r=0;
  for(auto i:s)
  {
    if(i=='W')
      w++;
    else
      r++;
  }
  while(r>0){
    r--;
    s1.push_back('R');
  }
  while(w>0)
  {
    w--;
    s1.push_back('W');
  }

 // cout<<s;
  int mp[200];
  mp['W']=0;
  mp['R']=0;
  
  for(int i=0;i<s.size();i++)
    if(s[i]!=s1[i])
      mp[s[i]]++;
  int ans=min(mp['W'],mp['R'])+abs(mp['W']-mp['R']);
  cout<<ans;
}

signed main() {
 ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 
 srand(time(0));
 int t=1;
 for(int i=1;i<=t;i++)
 {
   solve();
 }


}

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

int main(){
  int N, a, max, C;
  cin >> N;
  vector<int> H(N);
  for(int i=0; i<N; i++){
    cin >> H.at(i);
  }
  
  C = 0;
  max = H.at(0);
  
  for(int i=0;i<N;i++){
    a = H.at(i)-max;
    if(a>=0){
      C++;
      max = H.at(i);
    }
  }
  cout << C << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define BUF 1e5
#define INF 1 << 30
#define vi vector<int>
#define vvi vector<vector<int>>
#define all(a) (a).begin(), (a).end()
#define bit(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
constexpr ll mod = 1e9 + 7;
ll A, B, C, D, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

signed main() {
    cin >> N;
    vi x(N), y(N), h(N);
    int ax, ay, ah;
    for (int i = 0; i < N; i++) {
        cin >> x[i] >> y[i] >> h[i];
        if (h[i] != 0) {
            ax = x[i], ay = y[i], ah = h[i];
        }
    }
    for (int i = 0; i <= 100; i++) {
        for (int j = 0; j <= 100; j++) {
            bool flag = 1;
            H = ah + abs(i - ax) + abs(j - ay);
            for (int n = 0; n < N; n++) {
                if (max(0LL, H - abs(i - x[n]) - abs(j - y[n])) != h[n]) {
                    flag = 0;
                    break;
                }
            }
            if (flag) {
                cout << i << " " << j << " " << H << endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 256
S=input()
S_=list(S)
Q=int(input())
F1=[]
F2=[]
Q_=[]
for i in range(Q):
  Q_.append(list(input().split()))
count=0  
for i in range(len(Q_)):
  if Q_[i]==['1']:
    count+=1
  elif Q_[i][0:2]==['2','1']:
    if count%2==0:
      F1.append(Q_[i][2])
    else:
      F2.append(Q_[i][2])
  else:
    if count%2==0:
      F2.append(Q_[i][2])
    else:
      F1.append(Q_[i][2])
SS=F1[::-1]+S_+F2                
if count%2==0:
  print(''.join(SS))
else:
  print(''.join(SS[::-1]))
    

Measured memory_bytes: 36724
a = input()
b = input()
c = input()
d = {
  'a':a, 
  'b':b,
  'c':c
}
n = 'a'
while(True):
  if d[n] == '':
    break
  nx = d[n][0]
  d[n] = d[n][1:]
  n = nx
 
print(n.upper())

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

int main() {
	int d[10001],i,n;
	long long s,g;
	while(cin >> n) {
		if (n==0) break;
		for (i=0;i<n;i++) cin >> d[i];
		sort(d,d+n); s=0; g=0;
		for (i=0;i<n;i++) { g=g+s; s+=d[i];}
		cout << g << endl;
	}
	return 0;
}

Measured memory_bytes: 1212
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vs = vector<string>;
using vll = vector<long long>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

int digit_sum(int n) {
    int res = 0;
    while (n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    int dsum = digit_sum(n);
    if (n % dsum == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
from operator import itemgetter
import heapq
n, m = list(map(int, input().split()))
a = sorted(list(map(int, input().split())))
heap_a = [i for i in a]
heapq.heapify(heap_a)
b = []
c = []
for i in range(m):
    bi, ci = list(map(int, input().split()))
    b.append(bi)
    c.append(ci)

bc = zip(b, c)
bc = sorted(bc, key=itemgetter(1), reverse=True)
b, c = zip(*bc)

flag = False

for i in range(m):
    if flag:
        break
    for j in range(b[i]):
        min_a = heapq.heappop(heap_a)
        if min_a < c[i]:
            heapq.heappush(heap_a, c[i])
        else:
            heapq.heappush(heap_a, min_a)
            flag = True
            break
print(sum(heap_a))


Measured memory_bytes: 33256
#include<bits/stdc++.h>
    #define ll long long int
    #define MOD 1000000007
    #define mod 998244353
    #define pi 3.1415926535
    #define fi first
    #define se second
    #define vll vector<ll>
    #define vpll vector<pair <ll,ll> >
    #define vvll vector< vll >
    #define str string
    #define umap unordered_map
    #define uset unordered_set
    #define rep(i,n) for(ll i=0;i<n;i++)
    #define repA(i,s,n) for(ll i=s;i<=n;i++)
    #define repD(i,s,n) for(ll i=s;i>=n;i--)
    #define pb push_back
    #define mp make_pair
    #define lb lower_bound
    #define ub upper_bound
    #define elif else if
    #define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    #define ALL(v) v.begin(),v.end()
    #define sortA(v) sort(ALL(v))
    #define sortD(v) sort(ALL(v),greater <ll> ())
    #define print(v) for(auto itr:v) cout<<*itr<<" ";
    #define sz size()
    #define nl cout<<"\n";
    using namespace std;
    ll factorial(ll n){return (n==1||n==0)?1:n*factorial(n-1);}
    ll power(ll x,ll y){ll res=1;while(y>0){if(y&1)res=res*x;y=y>>1;x=x*x;}return res;}
    ll powerMod(ll x,ll y,ll m){if(y==0)return 1;ll p=powerMod(x,y/2,m)%m;p=(p*p)%m;return (y%2==0)?p:(x*p)%m;}
    ll modInverse(ll a,ll m){return powerMod(a,m-2,m);}

    int main(){
        fast
        ll ans=0,x=0;
        rep(i,5){
            cin>>x;
            if(x==0) ans=i+1;
        }
        cout<<ans;
        return 0;
    }

Measured memory_bytes: 3580
#include<stdio.h>
int main(void)
{
	long long int n, k,a,b;
	scanf("%lld%lld", &n, &k);
	a = n % k;
	b = k - a;
	if (a < b)
		printf("%lld\n", a);
	else
		printf("%lld\n", b);
	return 0;
}

Measured memory_bytes: 2148
import java.lang.Math.abs
import java.util.*

fun main(args: Array<String>) {
    try {
        val sc = Scanner(System.`in`)
        val n = sc.nextInt()
        if (n < 2 || n > 200_000) {
            throw Exception("Illegal input.")
        }
        val rs = IntArray(n)
        for (i in 0 until n) {
            rs[i] = sc.nextInt()
            if (rs[i] < 0 || rs[i] > 1_000_000_000) {
                throw Exception("Illegal input.")
            }
        }
        val m = getMaximumProfitFast(rs)
        println(m)
    } catch (e: Exception) {
        println(e)
    }
}

fun getMaximumProfitFast(rs: IntArray): Int {
    var r = -1_000_000_000
    var rMin = rs[0]
    for (i in 1 until rs.size) {
        if (r < rs[i] - rMin) {
            r = rs[i] - rMin
        }
        if (rs[i] < rMin) rMin = rs[i]
    }
    return r
}

fun getMaximumProfitSlow(rs: IntArray): Int {
    var r = -1_000_000_000
    for (i in 0 until rs.size) {
        for (j in i + 1 until rs.size) {
            if (rs[j] - rs[i] > r) {
                r = rs[j] - rs[i]
            }
        }
    }
    return r
}


Measured memory_bytes: 104232
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
ans = sum(b)
for i in range(n-1):
  if a[i] + 1 == a[i + 1]:
    ans += c[a[i] - 1]
print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()

const int N = (int)3e5+3;

ll mpow(ll a, ll b){
	if(b==0) return 1;
	else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
	else return mpow(a,b-1) * a % MOD;
}
ll gcd(ll a, ll b){
	if(b==0) return a;
	else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
	if(kaijo_memo.size() > n) return kaijo_memo[n];
	if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
	while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
	return kaijo_memo[n];
}
ll nCr(ll n, ll r){
	if(n < r || r < 0) return 0;
	ll ret = 1;
	ret *= kaijo(n); ret %= MOD;
	ret *= mpow(kaijo(r), MOD-2); ret %= MOD;
	ret *= mpow(kaijo(n-r), MOD-2); ret %= MOD;
	return ret;
}

int main(void){
	int d,n;
	cin>>d>>n;

	//d -= n/100;
	if(n==100) n=101;
	cout<<n;
	rep(i,d){
		cout<<"00";
	}
	cout<<endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);


		String s = sc.next();
		char[] s_chars = s.toCharArray();
		Arrays.sort(s_chars);
		String s_asc = new String(s_chars);

		String t = sc.next();
		char[] t_chars = t.toCharArray();
		Arrays.sort(t_chars);
		String t_asc = new String(t_chars);
		String t_desc = new StringBuilder(t_asc).reverse().toString();


		if (s_asc.compareTo(t_desc) < 0){
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}


Measured memory_bytes: 23252
// https://atcoder.jp/contests/abc145/tasks/abc145_c
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define CEIL(a, b) ((a - 1) / b + 1)

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    // vector<pair<int, int>> A(N);
    vector<int> X(N), Y(N);
    REP(i, N) { cin >> X[i] >> Y[i]; }
    double sum = 0;
    REP(i, N) {
        FOR(j, i + 1, N) { sum += hypot(X[i] - X[j], Y[i] - Y[j]); }
    }
    cout << setprecision(10) << 2.0 * sum / N << endl;

    return 0;
}


Measured memory_bytes: 3712
def primeFactor(N):
    i = 2
    ret = {}
    n = N
    if n < 0:
        ret[-1] = 1
        n = -n
    if n == 0:
        ret[0] = 1
    d = 2
    sq = int(n ** (1/2))
    while i <= sq:
        k = 0
        while n % i == 0:
            n //= i
            k += 1
            ret[i] = k
        if k > 0:
            sq = int(n**(1/2))
        if i == 2:
            i = 3
        elif i == 3:
            i = 5
        elif d == 2:
            i += 2
            d = 4
        else:
            i += 4
            d = 2
        
    if n > 1:
        ret[n] = 1
    return ret

def divisors(N):
    pf = primeFactor(N)
    ret = [1]
    for p in pf:
        ret_prev = ret
        ret = []
        for i in range(pf[p]+1):
            for r in ret_prev:
                ret.append(r * (p ** i))
    return sorted(ret)

N, M = map(int, input().split(" "))
 
for i in divisors(M):
    if i >= N:
        print (M//i)
        break

Measured memory_bytes: 3188
import java.util.*;

public class Main {
    public static void main(String[] args) {
        //コード
        Scanner scanner = new Scanner(System.in);
        Integer N = Integer.parseInt(scanner.next());
        Integer K = Integer.parseInt(scanner.next());
        Integer[] H = new Integer[N];

        for (int i = 0; i < N; i++) H[i] = Integer.parseInt(scanner.next());

        Arrays.sort(H,  Collections.reverseOrder());
        Long count = 0L;
        for (Integer i = K; i < N; i++) {
            count += H[i];
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 64856
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,int> P;
#define rep(i,m,n) for(int i=m;i<n;i++)
ll mod=1e9+7;

int main(){
  int n,m;
  cin>>n>>m;
  P d[n];
  rep(i,0,n){
    ll a;
    int b;
    cin>>a>>b;
    d[i]=P(a,b);
  }
  sort(d,d+n);
  ll ans=0;
  rep(i,0,n){
    if(m>d[i].second){
      ans+=d[i].first*d[i].second;
      m-=d[i].second;
    }
    else{
      ans+=d[i].first*m;
      m=0;
      break;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 1792
#include <iostream>

using namespace std;

const long long MOD = 1000000007;
long long N, M, ans;

int main(){
	cin>>N>>M;

	if(abs(N-M) > 1){
		cout<<0<<endl;
		return 0;
	}
	
	ans = 1;
	for(long long i = 1; i <= N; i++){
		ans = (ans * i) % MOD;
	}
	for(long long i = 1; i <= M; i++){
		ans = (ans * i) % MOD;
	}
	
	if(N == M) cout<<(ans*2) % MOD<<endl;
	else cout<<ans % MOD<<endl;
	
	return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
l = len(A)
flag = 0
while flag == 0:
    flag = 1
    A.sort()
    for i in range(1, l):
        A[i] = A[i] % A[0]
        if A[i] == 0:
            A[i] = A[0]
    for i in A:
        if i != A[0]:
            flag = 0

print(A[0])

    

Measured memory_bytes: 14252
x = gets.to_i

$memo = {}

def go(a)
    return $memo[a] unless $memo[a] == nil
    $memo[a] = a ** 5
end

a = 1

loop do 
    0.upto(a-1) do |b|
        if go(a) - go(b) == x
            puts "#{a} #{b}"
            return
        elsif go(a) + go(b) == x
            puts "#{a} -#{b}"
            return
        end
    end
    a += 1
end

Measured memory_bytes: 14420
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  ll a,b,c;
  cin >> a >> b >> c;
  c %= a;
  map<ll,ll> mp;
  mp[c]++;
  while(1){
    c += b;
    c %= a;
    mp[c]++;
    if(c == 0){
      cout << "YES" << endl;
      return 0;
    }
    if(mp[c] > 1){
      cout << "NO" << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 3604
#include<iostream>
#include<fstream>
#include<math.h>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<math.h>
#define _cin ios_base::sync_with_stdio(0);  cin.tie(0);
#define PI 3.14159265358979323846
#define root2 1.4142135623
#define mod 998244353
#define ll long long
using namespace std;

int main(){
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
    #endif
    _cin;
    
    string s,t;
    cin>>s;
    cin>>t;
    int count =0;
    for(int i=0;i<s.size();i++){
        if(s[i] != t[i])count++;
    }
    cout<<count;
    
    return 0;
}

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

using namespace std;

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

using ll = long long;
using ld = long double;
using D = double;
using uint = unsigned int;
template<typename T>
using pair2 = pair<T, T>;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define pb push_back
//#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second

const int maxn = 1000006;

int curup[maxn];
pair<int, int> curdown[maxn];
char s[maxn];
int n, nn;
int godownS[maxn];

pair<string, int> add1(string ss)
{
	bool all2 = true;
	for (int j = (int)ss.length() - 1; j >= 0; j--)
	{
		if (ss[j] != '2')
		{
			ss[j]++;
			all2 = false;
			break;
		} else
		{
			ss[j] = '0';
		}
	}
	return {ss, all2};
}

string calcS(string s)
{
	for (auto &c : s) if (c != '0') c = '1' + '2' - c;
	return s;
}

int eval(string s)
{
	int v = 0;
	for (auto c : s) v = v * 3 + c - '0';
	return v;
}

int main()
{
	scanf("%d", &n);
	//n = 12;
	nn = 1;
	for (int i = 0; i < n; i++) nn *= 3;
	scanf("%s", s);
	int len = strlen(s);
	//int len = 200000;
	//for (int i = 0; i < len; i++) s[i] = 'R'; //(((int)rng() % 2) ? 'S' : 'R');
	int nhalf = (n + 1) / 2;
	int nnhalf = 1;
	for (int i = 0; i < nhalf; i++) nnhalf *= 3;
	string cur = string(nhalf, '0');
	for (int it = 0; it < nnhalf; it++)
	{
		godownS[it] = eval(calcS(cur));
		cur = add1(cur).fi;
	}
	int nntop = nn / nnhalf;


	for (int it = 0; it < nnhalf; it++)
	{
		curdown[it] = {it, 0};
	}
	for (int it = 0; it < nn; it++)
	{
		curup[it] = it / nnhalf;
	}
	for (int it = 0; it < len; it++)
	{
		//cout << "before " << it << ' ' << clock() << endl;
		//for (auto t : mp) cout << t.from << ' ' << t.to << ' ' << t.flip << endl;
		//cout << it << ' ' << mp.size() << endl;
		char op = s[it];
		if (op == 'S')
		{
			for (int i = 0; i < nnhalf; i++)
			{
				curdown[i].fi = godownS[curdown[i].fi];
				curdown[i].se ^= 1;
			}
		} else
		{
			for (int i = 0; i < nnhalf; i++)
			{
				if (curdown[i].fi != nnhalf - 1)
				{
					curdown[i].fi++;
				} else
				{
					for (int j = i; j < nn; j += nnhalf)
					{
						if (curdown[i].se)
						{
							curup[j] = godownS[curup[j]];
						}
						curup[j]++;
						if (curup[j] == nntop) curup[j] = 0;
					}
					curdown[i] = {0, 0};
				}
			}
		}
	}
	for (int i = 0; i < nn; i++)
	{
		if (curdown[i % nnhalf].se)
		{
			curup[i] = godownS[curup[i]];
		}
		int v = curup[i] * nnhalf + curdown[i % nnhalf].fi;
		printf("%d ", v);
	}
	printf("\n");
	//for (int i = 0; i < nn; i++) printf("%d%d ", curup[i], curdown[i % nnhalf].fi);
	//printf("\n");
    return 0;
}


Measured memory_bytes: 6280
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
	int n,k=111;
	cin>> n;
	if(n<=111)
	{
		cout<<"111"<<endl;
	}
	if(n>111)
	{	
		while((n/k)!=0)
		{
			k+=111;
		}
			if(n%(k-111)==0)
			{
				cout<< (k-111)<<endl;
			}
			else
				cout<<k<<endl;
	}		
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define inf 1000000000000000
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 

using namespace std;

#define N 100005

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

ll fact[N];
ll ifact[N];
ll ncr(ll n, ll r)
{
    if(r>n)
        return 0;
    ll ans = fact[n];
    ans*=ifact[r];
    ans%=mod;
    ans*=ifact[n-r];
    ans%=mod;
    return ans;
}

int main()
{
   FAST/**/
   
   fact[0] = 1;
   for(ll i=1;i<N;i++)
        fact[i] = fact[i-1]*i, fact[i]%=mod;
   for(ll i=0;i<N;i++)
        ifact[i] = powa(fact[i],mod-2,mod);
   
   ll n,k;
   cin>>n>>k;
   
   ll arr[n];
   rep(n)   
        cin>>arr[i];
   
   sort(arr,arr+n);
   
   map<ll,ll> ma;
   rep(n)
        ma[arr[i]]++;
   vector<ll> freq;
   vector<ll> no;
   autoit(ma,it)
        freq.pb(it->ss), no.pb(it->ff);
   
   ll sum = 0;
   ll ans = 0;
   rep(freq.size())
   {
       ll sum1 = sum + freq[i];
       ll temp = ncr(sum1,k) - ncr(sum,k);
       temp%=mod;
       if(temp<0)
            temp+=mod;
       ll temp1 = (no[i]*temp)%mod;
       if(temp1<0)  
            temp1+=mod;
       ans+=temp1;        
       ans%=mod;
       sum = sum1;
   }
   
   reverse(no.begin(), no.end());
   reverse(freq.begin(), freq.end());
   sum = 0;
   
   rep(freq.size())
   {
       ll sum1 = sum + freq[i];
       ll temp = ncr(sum1,k) - ncr(sum,k);
       temp%=mod;
       if(temp<0)
            temp+=mod;
       ll temp1 = (no[i]*temp)%mod;
       if(temp1<0)  
            temp1+=mod;
       ans-=temp1;        
       ans%=mod;
       if(ans<0)
            ans+=mod;
       sum = sum1;        
   }        
        
   cout<<ans;   
   
   return 0;        
}  
   

Measured memory_bytes: 10100
#include <iostream>
#include <sstream>
#include <vector>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iomanip>
#include <vector>
#include <cstdio>
#include <float.h>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <stack>
#include <functional>
 
using namespace std;
 
#define endl '\n'
#define MOD 1000000007
#define INF 1ll<<30
#define MAX 100010
#define eps 1e-11
#define bit_max 1ll<<32
#define _USE_MATH_DEFINES
 
 
 
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
  //  freopen("./input.txt","r",stdin);
 //   freopen("./output.txt","w",stdout);
    int n,l;
    cin>>n>>l;
    int total =0;
    for(int i=0;i<n;i++)
        total = total+(l+i);
    int a,b;
    a = l;
    b = l+n-1;
    int mn = min(a,b);
    int mx = max(a,b);
    if(mn==0||mx==0)
    {
        cout<<total;
    }
    else if(mn<0&&mx>0)
        cout<<total;
    else if(mn>0)
        cout<<total-mn;
    else if(mx<0)
        cout<<total-mx;

}

Measured memory_bytes: 256
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>
#include <cmath>

auto& in = std::cin;
auto& out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;

int32_t N,M;
int32_t count[40];

int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);

	in >> N>>M;
	for (size_t i = 0; i < N; i++)
	{
		int k;
		in >> k;
		for (size_t i = 0; i < k; i++)
		{
			int v;
			in >> v;
			--v;
			count[v]++;
		}
	}
	int sum = 0;
	for (size_t i = 0; i < M; i++)
	{
		if (count[i] == N) {
			++sum;
		}
	}
	out << sum << endl;

	return 0;
}
#endif


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define max0(a,b,c) max(max(a,b),c)
#define min0(a,b,c) min(min(a,b),c)
#define ft first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
using Graph = vector<vector<int>>;
typedef long long lint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldouble;
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<ull> ulvec;
typedef vector<double> dvec;
typedef vector<pair<int,int>> pvec;
typedef vector<pair<ll,ll>> plvec;
typedef vector<tuple<ll,ll,ll>> tvec;
typedef vector<string> svec;

int main(){
    ll n,m;
    cin>>n>>m;
    priority_queue<ll> que;
    set<ll> st;
    rep(i,m){
        ll a,b;
        cin>>a>>b;
        if(a==1) que.push(b);
        else if(b==n) st.insert(a);
    }
    bool flag=false;
    while(!que.empty()){
        ll k=que.top();
        que.pop();
        if(st.count(k)){
            flag=true;
            break;
        }
    }
    if(flag) cout<<"POSSIBLE";
    else cout<<"IMPOSSIBLE";
}

Measured memory_bytes: 5748
import sys
sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

def main():
	N = INT()
	A = MAP()

	i = 0
	cnt = 0
	while i < N:
		if A[i] == i+1:
			cnt += 1
			if i < N-1 and A[i+1] == i+2:
				i += 2
			else:
				i += 1
		else:
			i += 1
	
	print(cnt)

if __name__ == '__main__':
	main()

Measured memory_bytes: 13680
//#define _GLIBCXX_DEBUG
#include <iostream>
#include <bits/stdc++.h>
    
    
using namespace std;
#define ll long long
#define ld long double
#define  P pair<ll,ll>
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,m,n) for(ll i=n; i>=(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cout(n) cout<<fixed<<setprecision(n)
    
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    vector<ll> v(n);
    FOR(i,0,n)cin>>v[i];
    ll tmp = 1e9;
    FOR(i,0,100){
        ll a = 0;
        FOR(j,0,n){
            a += (v[j]-i)*(v[j]-i);
        }
        if(a<=tmp){
            tmp = a;
        }
    }
    cout<<tmp<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) REP(i,0,n)
#define int long long
#define REP(i,l,r) for(int i=l;i<r;i++)
using namespace std;
typedef pair<int,int> P;
int gcd(int a,int b){
    if(a%b==0)return b;
    else return gcd(b,a%b);
}
int lcm(int a,int b){
    return a*b/gcd(a,b);
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
struct edge{
    int to,cost;
};
class dijkstra{
    int V;
    int d[100002];
    priority_queue<P,vector<P>,greater<P>>que;
    void update(int s,vector<edge> G[]){
        fill(d,d+V+1,100000000000ll);
        d[s]=0;
        que.push(make_pair(0,s));
        while(!que.empty()){
            P p=que.top();
            que.pop();
            int v=p.second;
            if(d[v]<p.first)continue;
            rep(i,G[v].size()){
                edge e=G[v][i];
                if(d[e.to]>d[v]+e.cost){
                    d[e.to]=d[v]+e.cost;
                    que.push(make_pair(d[e.to],e.to));
                }
            }
        }
    }
public:
    dijkstra(int v,int s,vector<edge> G[]){
        V=v;
        update(s,G);
    }
    int find(int e){
        return d[e];
;    }
};
class Union_Find{
private:
    vector<int> t,s;
public:
    Union_Find(int max_length){
        rep(i,max_length+1){
            t.push_back(i);
            s.push_back(1);
        }
    }
    void Union(int x,int y){
        if(same(x,y))return;
        int tx=Find(x),ty=Find(y);
        if(s[tx]<s[ty]){
            s[ty]+=s[tx];
            t[tx]=ty;
        }
        else if(s[tx]>s[ty]){
            s[tx]+=s[ty];
            t[ty]=tx;
        }
        else if(tx>ty){
            t[tx]=ty;
            s[ty]+=s[tx];
        }
        else{
            t[ty]=tx;
            s[tx]+=s[ty];
        }
    }
    int Find(int n){
        if(t[n]==n)return n;
        else return t[n]=Find(t[n]);
    }
    bool same(int x,int y){
        return Find(x)==Find(y);
    }
    int get_Size(int a){
        return s[a];
    }
};
signed main(){
    int n,k;
    string s;
    cin>>n>>s>>k;
    rep(i,n){
        if(s[i]!=s[k-1])cout<<'*';
        else cout<<s[i];
    }
    cout<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define fs first
#define sc second
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

int main() {
	int i, n, ans=0;
	scanf("%d", &n);
	n*=2;
	vi x(n);
	for(i=0; i<n; i++) scanf("%d", &x[i]);
	sort(all(x));
	for(i=0; i<n; i+=2) ans+=x[i];
	printf("%d\n", ans);
   	return 0;
}

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

using ll = long long;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define ddrep(i, n) for (int i = n; i > 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define ssrep(i, s, t) for (int i = s; i <= t; ++i)

#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second

#define chmax(x, y) (x = max(x, y))
#define chmin(x, y) (x = min(x, y))

using pi = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "{";
    rep(i, (int)v.size()) {
        if (i)
            os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

template <typename T, size_t S> void printArray(const T (&array)[S]) {
    for (auto val : array)
        std::cout << val << ", ";
    std::cout << "\n";
}

const int mod = 1e9 + 7;
const int inf = 1e9 + 5;

struct UnionFind {
    vi parent, rank, count;
    UnionFind(const int nodeSize)
        : parent(nodeSize), rank(nodeSize, 1), count(nodeSize) {
        rep(i, nodeSize) parent[i] = i, count[i] = 1;
    }
    int find(int x) {
        if (parent[x] == x) return x;
        return parent[x] = find(parent[x]);
    }
    void unite(int x, int y) {
        int rx = find(x);
        int ry = find(y);
        if (rx == ry) return;
        if (rank[rx] < rank[ry]) swap(rx, ry);
        parent[ry] = rx;
        count[rx] += count[ry];
        if (rank[rx] == rank[ry]) ++rank[rx];
    }
    bool same(int x, int y) {
        return find(x) == find(y);
    }
    int num(int x) {
        return count[find(x)];
    }
};

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

    int n, m; std::cin >> n >> m;
    UnionFind uf(n);
    rep(i, m) {
        int x, y, z; std::cin >> x >> y >> z;
        --x, --y;
        uf.unite(x, y);
    }
    set<int> par;
    rep(i, n) {
        if (uf.find(i) == i) par.insert(i);
    }
    std::cout << par.size() << "\n";
}


Measured memory_bytes: 6144
N, D = map(int, input().split())
X = [list(map(float, input().split())) for i in range(N)]

cnt = 0
for i in range(N-1):
  for j in range(N-i-1):
    jj = j+i+1
    dis = 0.0
    for k in range(D):
      dis += (X[i][k] - X[jj][k])**2
    dis = dis**0.5
    if dis.is_integer():
      cnt += 1

print(cnt)

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

using ll = long long;
#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)

#define INF 1e9

int main(){
  int N, K;
  cin >> N >> K;
  ll t, d;
  vector<ll> A, king(N, -1);
  int cnt = 0;
  REP(i, N){
    cin >> t >> d;
    t--;
    if(king[t] == -1){
      cnt++;
    }
    if(king[t] < d){
      swap(d, king[t]);
    }
    A.push_back(d);
  }
  sort(A.rbegin(), A.rend());
  A.insert(A.begin(), 0);
  REP(i, A.size()-1){
    A[i+1] += A[i];
  }
  sort(king.rbegin(), king.rend());
  king.insert(king.begin(), 0);
  REP(i, king.size()-1){
    king[i+1] += king[i];
  }
  ll ans = 0;
  FOR(i, 1, min(cnt, K)+1){
    // cerr << "i:" << i << " king[i]:" << king[i] << " A[K-i]:" << A[K-i] << endl;
    ll pt = ll(i)*i;
    pt += king[i] + A[K-i];
    ans = max(ans, pt);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2676
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"sort"
	"strconv"
)

/*
法 1e9+7(1000000007) の下での2項係数(combination)
*/
var n int = 1e5 + 1
var mod int = 1e9 + 7
var fac = make([]int, n)
var inv = make([]int, n)
var finv = make([]int, n)

func initComb() {
	fac[0], fac[1] = 1, 1
	finv[0], finv[1] = 1, 1
	inv[1] = 1

	var i int
	for i = 2; i < n; i++ {
		fac[i] = fac[i-1] * i % mod
		inv[i] = mod - inv[mod%i]*(mod/i)%mod
		finv[i] = finv[i-1] * inv[i] % mod
	}
}

func comb(n, k int) int {
	if n < k || n < 0 || k < 0 {
		return 0
	}
	return fac[n] * (finv[k] * finv[n-k] % mod) % mod
}

func main() {
	n, k := readInt(), readInt()
	a := make([]int, n)
	for i := range a {
		a[i] = readInt()
	}
	sort.Sort(sort.Reverse(sort.IntSlice(a)))

	initComb()

	ans := 0
	for i := 0; i < n; i++ {
		reserve := n - i - 1
		cnt := comb(reserve, k-1)
		// fmt.Println(i, a[i], reserve, k-1, cnt, cnt*a[i])
		// fmt.Println(i, a[n-i-1], reserve, k-1, cnt, -cnt*a[n-i-1])
		ans = (ans + cnt*a[i]%mod) % mod
		ans = (ans + mod - cnt*a[n-i-1]%mod) % mod
	}

	fmt.Println(ans)
}

// sort ------------------------------------------------------------

type xxx struct {
	x int
}

type sortArray []xxx

func (s sortArray) Len() int           { return len(s) }
func (s sortArray) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s sortArray) Less(i, j int) bool { return s[i].x < s[j].x }

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

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcd(m, n int) int {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcm(m, n int) int {
	return m / gcd(m, n) * n
}


Measured memory_bytes: 4736
def main():
    K = int(input())
    a = list(map(int, input().split()))
    A = a[0]
    B = a[1]
    for i in range(A, B + 1, 1):
        if i % K == 0:
            print("OK")
            exit()
    print("NG")


if __name__ == '__main__':
    main()


Measured memory_bytes: 9172
import bisect
import collections
import itertools


def getint(): return int(input())
def getints(): return list(map(int, input().split()))
def getint2d(rows): return [getints() for _ in range(rows)]
def getgrid(rows): return [input() for _ in range(rows)]
def array1d(n, value): return [value for _ in range(n)]
def array2d(n, m, value): return [array1d(m, value) for _ in range(n)]

n,k=getints()
vs=getints()

cache=array2d(65, 2, -1)

def solve(pos, is_small):
    if pos < 0: return 0
    res = cache[pos][is_small]
    if res >= 0: return res
    res1, res2 = 0, 0
    val = 1 << pos
    for v in vs:
        m = v >> pos & 1
        res1 += m * val # 0
        res2 += (1 - m) * val # 1

    if is_small:
        res = max(res1, res2) + solve(pos - 1, True)
    else:
        kbit = k >> pos & 1
        if kbit == 0:
            res1 += solve(pos - 1, False)
            res2 = 0
        else:
            res1 += solve(pos - 1, True)
            res2 += solve(pos - 1, False)
        res = max(res1, res2)

    cache[pos][is_small] = res
    return res

print(solve(64, False))

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

int main() {
  int n;
  cin>>n;
  int x[n];
  for (int i=0; i<n; i++) cin>>x[i];
  sort(x, x + n);
  long long ans = 1e15;
  for (int i=x[0]; i<=x[n-1]; i++) {
    long long tmp = 0;
    for (int j=0; j<n; j++) {
      long long a = x[j] - i;
      tmp += a * a;
    }
    ans = min(tmp, ans);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
const ll mod=1000000007;
const ll INF=1e15;
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define U_ERASE(V) V.erase(unique(ALL(V)), V.end());
#define pb push_back
#define mp make_pair
typedef pair<ll,ll> P;
vec dx={1,0,-1,0};
vec dy={0,1,0,-1};

long long ruijou(ll n, ll k){
    if(k==0) return 1;
    ll x=k/2;
    long long t=ruijou(n,x);
    
    if(k%2==1) return n*t*t;
    else return t*t;
}

int main(){
  ll N,M; cin>>N>>M;
  bool OK=true;
  vec d(N+1,INF);
  rep(i,M){
    ll s,t; cin>>s>>t;
    if(d.at(s)!=INF && d.at(s)!=t) OK=false;
    d.at(s)=t;
  }
  
  if(N!=1 && d.at(1)==0) OK=false;

  ll ans=0;
  REP(i,1,N+1){
    if(d.at(i)!=INF) ans+=(d.at(i)*ruijou(10,N-i));
    else if(N!=1 && i==1) ans+=ruijou(10,N-1);
  }
  
  if(OK) cout<<ans<<endl;
  else cout<<-1<<endl;
  

 
}

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

pair<int,int> m[5][100005];
signed main() {
    int n;cin>>n;
    rep(i,2)rep(j,1e5+1)
    {
        m[i][j] = make_pair(0,j);
    }
    rep(i,n)
    {
        int v;cin>>v;
        m[i%2][v].first++;
    }

    rep(i,2)
    {
        sort(m[i],m[i]+100001);
        reverse(m[i],m[i]+100001);
    }
    int ans;
    if(m[0][0].second == m[1][0].second)
    {
        ans =min((n+1)/2-m[0][0].first + n/2 - m[1][1].first,(n+1)/2-m[0][1].first + n/2 - m[1][0].first); 
    }else{
        ans = (n+1)/2-m[0][0].first + n/2 - m[1][0].first;
    }

    cout << ans << endl;
    return 0;

}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, e) for (int i = (int)(s); i <= (int)(e); i++)
#define printYesNo(is_ok) puts(is_ok ? "Yes" : "No");
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.rbegin(), v.rend());
#define REVERSE(v) reverse(v.begin(), v.end());

template <typename T>
void printlnVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << endl;
  }
}

template <typename T>
void printVector(T v)
{
  rep(i, v.size())
  {
    cout << v[i] << " ";
  }
  cout << endl;
}

int main()
{
  int S, W;
  cin >> S >> W;
  if(S <= W)
    cout << "unsafe" << endl;
  else
    cout << "safe" << endl;
  
  return 0;
}

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

signed main() {
#ifdef LOCAL
  assert(freopen("a.in", "r", stdin));
#endif
  string s;
  cin >> s;
  if ((int) s.size() < 26) {
    vector<bool> was(26);
    for (char c : s) {
      was[c - 'a'] = true;
    }
    for (int c = 0; c < 26; ++c) {
      if (!was[c]) {
        s.push_back('a' + c);
        break;
      }
    }
    cout << s << '\n';
  } else {
    string t = s;
    if (!next_permutation(t.begin(), t.end())) {
      cout << -1 << '\n';
    } else {
      int i = 0;
      while (s[i] == t[i]) {
        ++i;
      }
      s = t.substr(0, i + 1);
      cout << s << '\n';
    }
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
int main()
{
  ll n;
  cin>>n;
  ll h[n+1];
  h[0]=INT_MAX;
  for(int i=1;i<=n;i++)
    cin>>h[i];
  
  ll dp[n+1]={0};
  for(int i=2;i<=n;i++)
  {
    dp[i]=min((labs(h[i]-h[i-1])+dp[i-1]),(labs(h[i]-h[i-2])+dp[i-2]));
  }
  cout<<dp[n];
}


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

const int N = 1e5 + 10 ;

const double INF = 1e18 ;

const pair < double, double> orginal = {INF, -INF} ;

int n ;

pair < pair < double , double >, pair < double , double > >  a[N] ;

vector < double > Candidate ;

void updateOne(pair < double, double > &foo, pair < double, double > &bar) {
	if (foo == orginal || bar == orginal) return ;
	Candidate.push_back(abs(bar.first - foo.first)) ;
	Candidate.push_back(abs(bar.second - foo.second)) ;
}

void updateTwo(pair < double, double > &foo, pair < double, double > &bar) {
	if (foo == orginal || bar == orginal) return ;
	Candidate.push_back(abs(bar.first - foo.first) / 2) ;
	Candidate.push_back(abs(bar.second - foo.second) / 2) ;
} 

int main(){

	cin >> n ;

	pair < double, double > U = {INF, -INF}, D = {INF, -INF}, L = {INF, -INF}, R = {INF, -INF}, X = {INF, -INF}, Y = {INF, -INF} ;

	for (int i = 1; i <= n; ++ i) {
		
		pair < double , double > Coordinate, Direction ;
		char c ;

		cin >> Coordinate.first >> Coordinate.second >> c ;

		if (c == 'L') Direction = {-1, 0}, L.first = min(L.first, Coordinate.first), L.second = max(L.second, Coordinate.first) ;
		else if (c == 'R') Direction = {1, 0}, R.first = min(R.first, Coordinate.first), R.second = max(R.second, Coordinate.first) ;
		else if (c == 'U') Direction = {0, 1}, U.first = min(U.first, Coordinate.second), U.second = max(U.second, Coordinate.second) ;
		else Direction = {0, -1}, D.first = min(D.first, Coordinate.second), D.second = max(D.second, Coordinate.second) ;
		a[i] = {Coordinate, Direction} ;

		if (c == 'L' || c == 'R') Y.first = min(Y.first, Coordinate.second), Y.second = max(Y.second, Coordinate.second) ;
		else X.first = min(X.first, Coordinate.first), X.second = max(X.second, Coordinate.first) ;

	}

	Candidate.push_back(0) ;

	updateOne(X, L) ; updateOne(X, R) ; updateTwo(L, R) ;
	updateOne(Y, U) ; updateOne(Y, D) ; updateTwo(U, D) ;

	double ans = INF ;

	for (auto t : Candidate) {
		
		double xmin = INF, xmax = -INF, ymin = INF, ymax = -INF ;
		
		for (int i = 1; i <= n; ++ i) {
			
			pair < double, double > Coordinate = a[i].first ;
			pair < double, double > Direction = a[i].second ;
			
			Coordinate.first += Direction.first * t ;
			Coordinate.second += Direction.second * t ;
			
			xmin = min(xmin, Coordinate.first) ;
			xmax = max(xmax, Coordinate.first) ;

			ymin = min(ymin, Coordinate.second) ;
			ymax = max(ymax, Coordinate.second) ;
		}	

		ans = min(ans, (xmax - xmin) * (ymax - ymin)) ;

	}	

	cout << setprecision(9) << fixed ;

	cout << ans << endl ;

	return 0 ;
}

Measured memory_bytes: 3328