akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
class Main
{
    static long MOD = (long) Math.pow(10, 9) + 7;
    public static void main (String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(), m = sc.nextInt();
        int[] p = fact(m);
        long ans = 1;
        for(int i = 0; i < p.length; i++){
            ans *= aHb(p[i], n);
            ans %= MOD;
        }
        System.out.println(ans);
    }
    static int[] fact (int M)
    {
        int[] res = new int[30];
        int index = 0;
        for(int i = 2; i <= M; i++){
            boolean flag = true;
            while(flag){
                if(M % i == 0){
                    res[index]++;
                    M /= i;
                }
                else{
                    flag = false;
                }
            }
            if(res[index] > 0) index++;
        }
        int[] ans = new int[index];
        for(int i = 0; i < index; i++) ans[i] = res[i];
        return ans;
    }
    static long aHb (long a, long b)
    {
        long x = a + b - 1;
        long y = b - 1;
        long MulSum = 1, DivSum = 1;
        for(int i = 1; i <= y; i++){
            MulSum *= x - i + 1;
            MulSum %= MOD;
            DivSum *= i;
            DivSum %= MOD;
        }
        return MulSum * pow(DivSum, MOD - 2) % MOD;
    }
   static long pow(long a, long b)
    {
        if(b == 0) return 1;
        if(b % 2 == 0){
            long d = pow(a, b / 2);
            return d * d % MOD;
        }
        else return  a *  pow(a, b - 1) % MOD;
    }
 }




Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define foi(i,k,n) for(int i = (int)k; i < (int)n; ++i)

using namespace std;
using ii = pair<int,int>;
using ll = long long;

int main() {
  ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
  int k; cin >> k;
  string s; cin >> s;
  if ((int) s.size() > k) {
    while (s.size() > k) s.pop_back();
    s += "...";
  }
  cout << s << '\n';
  return 0;
}


Measured memory_bytes: 3652
#include <vector>
#include <iostream>

using namespace std;

int main()
{
	vector<bool> S(31, false);

	int A;

	for (int i = 0; i < 28; i++)
	{
		cin >> A;

		S[A] = true;
	}

	for (int i = 1; i < 31; i++)
	{
		if (S[i] == false)
		{
			cout << i << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 3104
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using ld = long double;
int main() {
  ll N, A, B;
  cin >> N >> A >> B;
  ll ans = (N / (A + B)) * A;
  if (N % (A + B) >= A)
    cout << ans + A << endl;
  else
    cout << ans + (N % (A + B)) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=3e5+10;
map<int,int> ss;
int n,x;

int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
       scanf("%d",&x);
       ss[x]++;
    }
    if(ss[0]==n)return !printf("Yes\n");
    if(n%3){
        return !printf("No\n");
    }
    else{
        vector<int> a;
        for(auto i:ss){
            for(int j=0;j<i.second/(n/3);j++)
                a.push_back(i.first);
        }
        if(a.size()==3&&(a[0]^a[1]^a[2])==0)
            printf("Yes\n");
        else 
            printf("No\n");
    }
}


Measured memory_bytes: 3840
a = int(input())
b = int(input())
c = int(input())
x = int(input())
ans = 0
for i in range(a + 1):
    for j in range(b + 1):
        for k in range(c + 1):
            if i * 500 + j * 100 + k * 50 == x:
                ans += 1
print(ans)


Measured memory_bytes: 9180
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        Map<Integer, Integer> resultMap = new HashMap<>();
        for (int i = 1; i < N; i++) {
            int boss = sc.nextInt();
            Integer count = resultMap.get(boss);
            if (Objects.isNull(count)) {
                count = 1;
            } else {
                count += 1;
            }
            resultMap.put(boss, count);
        }

        for (int i = 1; i <= N; i++) {
            Integer val = resultMap.get(i);
            if (Objects.isNull(val)) {
                System.out.println(0);
            } else {
                System.out.println(val);
            }
        }
    }
}


Measured memory_bytes: 73056
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

//ITP1_11-A

namespace ConsoleApplication24
{
    class Dice
    {
        string[] D;

        public Dice(string[] DArray)
        {
            D = DArray;
        }

        public string DiceRoll(string roll)
        {
            for (int i = 0; i < roll.Length; ++i)
            {
                string D0 = D[0];
                string D1 = D[1];
                string D2 = D[2];
                string D3 = D[3];
                string D4 = D[4];
                string D5 = D[5];

                switch (roll[i])
                {
                    case 'E':
                        D[0] = D3;
                        D[2] = D0;
                        D[3] = D5;
                        D[5] = D2;

                        break;

                    case 'N':
                        D[0] = D1;
                        D[1] = D5;
                        D[4] = D0;
                        D[5] = D4;

                        break;

                    case 'S':
                        D[0] = D4;
                        D[1] = D0;
                        D[4] = D5;
                        D[5] = D1;
                        break;

                    case 'W':
                        D[0] = D2;
                        D[2] = D5;
                        D[3] = D0;
                        D[5] = D3;
                        break;
                }
            }
            return D[0];
        }
    }


    class Program
    {
        static void Main()
        {
            string[] DiceArray = Console.ReadLine().Split(' ');
            string str = Console.ReadLine();

            Dice DClass = new Dice(DiceArray);

            string top = DClass.DiceRoll(str);

            Console.WriteLine(top);
        }
    }
}

Measured memory_bytes: 5296
#include<cstdio>

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

using namespace std;

double dp[10001][20];
double dfs(int t,int cont){
	if(t==0) return 0;
	if(cont>=20) return dfs(t-1,0);

	if(dp[t][cont]!=-1) return dp[t][cont];
	double p=1./(1<<cont);
	return dp[t][cont]=p*(1+dfs(t-1,cont+1))+(1-p)*dfs(t-1,0);
}

int main(){
	rep(t,10001) rep(c,20) dp[t][c]=-1;
	for(int n;scanf("%d",&n),n;){
		double res;
		if(n<10000) res=dfs(n,0);
		else        res=dfs(10000,0)+(n-10000)*0.62144621667;
		printf("%.9f\n",res);
	}

	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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

using namespace std;
#define int long long
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
#define pb push_back

const long long MOD = 1000000007;
//const long long MOD = 998244353;
const long long INF = 1LL << 60;


long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	unsigned r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a * g / b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}




const long double PI = 3.14159265359;
const int MAX_N = 100010;



signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int a, b, c, d, e, f; cin >> a >> b >> c >> d >> e >> f;
	P ans;
	double now = -1.0;
	for (int i = 0; i * a * 100 <= f; i++) {
		for (int j = 0; (i + a + j * b) * 100 <= f; j++) {
			if (i + j == 0)continue;
			int w = (i*a + j * b) * 100;
			int ms = min(f - w, e*w / 100);
			for (int k = 0; k * c <= ms; k++) {
				int l = (ms - k * c) / d;
				int s = k * c + l * d;
				if (now < 100.0 * s / (s + w)) {
					now = 100.0*s / (s + w);
					ans = P(s + w, s);
				}
				
			}
		}
	}
	cout << ans.first<<" "<<ans.second << endl;
	return 0;
}

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

#define M1 1000000007
#define M2 1000000009
#define ll long long 
#define ull unsigned long long
#define ui unsigned int
#define us unsigned short
#define INF 1001001001
#define PI 3.1415926535897932384626
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define f0(i, n) for (int i = 0; i < (int)(n); ++i)
#define f1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define fc0(i,l,r) for(int i = (int)(l); i<(int)(r); ++i)
#define fc1(i, l, r) for (int i = (int)(l); i <= (int)(r); ++i)
#define fr0(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
#define sz(a) int((a).size())
#define tr(c,i) for(typeof((c)).begin() i = (c).begin(); i != (c).end(); i++)
typedef vector<int> vi; 
typedef vector<vi> vvi; 
typedef pair<int,int> ii; 
 
void init()
{
  #ifndef ONLINE_JUDGE
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
      freopen("error.txt", "w", stderr);
    #endif

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;
}
 
signed main()
{
    init();

    int n;
    cin>>n;
    if(n%1000==0){cout<<0<<endl;}
    else{cout<<((n/1000)+1)*1000-n<<endl;}

    cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" secs"<<endl;
    return 0;
}

Measured memory_bytes: 3808
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
using namespace std;
int main(void){
    float n;
    cin >> n;
    float ans = 0;
    for(int i = 1; i < n + 1; i++){
        if(i % 2 != 0) ans++;
    }
    float x = ans / n;
    cout << x << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using namespace std;
int main() {
	int n, m, a[55], b[55], c[55], d[55], i, j, minv = 1e9, minn;
	cin >> n >> m;
	for (i = 1; i <= n; i++)
		cin >> a[i] >> b[i];
	for (i = 1; i <= m; i++)
		cin >> c[i] >> d[i];
	for (i = 1; i <= n; i++) {
		minv = 1e9;
		for (j = 1; j <= m; j++)
			if (abs(c[j] - a[i]) + abs(d[j] - b[i]) < minv) {
				minv = abs(c[j] - a[i]) + abs(d[j] - b[i]);
				minn = j;
			}
		cout << minn << endl;
	}
	return 0;
}

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

template<typename T> T gcdraw(T a, T b)
{
    return a ? gcdraw(b%a, a) : b;
}

template<typename T> T gcd(T a, T b)
{
    const auto aa = abs(a), bb = abs(b);
    return aa > bb ? gcdraw(aa, bb) : gcdraw(bb, aa);
}

const int MAXN = 1000001;
int P[MAXN + 1];
bool B[MAXN + 1];

void makeLowestPrimeTable()
{
    for (int i=2;i*i<=MAXN;++i)
    {
        if (P[i]) { continue; }
        for (int j=i*2;j<=MAXN;j+=i) if(!P[j]) { P[j] = i; }
    }
}

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

    vector<int> A(N);
    for (auto& a : A) { cin >> a; }

    makeLowestPrimeTable();

    const auto calcPairwise = [](int x)
    {
        while (x != 1)
        {
            const auto p = P[x] ? P[x] : x;

            if (B[p]) { return false; }
            B[p] = true;

            while ((x % p) == 0) { x /= p; }
        }

        return true;
    };

    bool isPairwise = true;
    int setwiseValue = A[0];

    for (int i=0;i<N;++i)
    {
        isPairwise &= calcPairwise(A[i]);
        setwiseValue = gcd(setwiseValue, A[i]);
    }

    if (isPairwise)             { cout << "pairwise coprime" << endl; }
    else if (setwiseValue == 1) { cout << "setwise coprime" << endl; }
    else                        { cout << "not coprime" << endl; }

    return 0;
}


Measured memory_bytes: 12012
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)

using namespace std;
const ll MAX_N=2e5;
ll N,X[MAX_N],S[MAX_N],psm[MAX_N+1];
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>N;
	REP(i,N)cin>>X[i]>>S[i];
	REP(i,N)psm[i+1]=psm[i]+S[i];
	priority_queue<ll> pque;
	ll ans=0;
	REP(i,N){
		pque.push(X[i]-psm[i]);
		ans=max(ans,psm[i+1]-X[i]+pque.top());
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 7156
#include <stdio.h>

int main(void){

    int n,alice=0,bob=0,a[120];
    scanf ("%d",&n) ;
    
    for (int i=0; i<n; i++ ){
        
        scanf("%d",&a[i]) ;
    }
    
    for (int i=0; i<n; i++ ){
        
        for (int j=0; j<n; j++ ){
            
            int tmp = 0 ;
            if ( a[i]>a[j] ){
                tmp = a[i] ;
                a[i] = a[j] ; 
                a[j] = tmp ;
            }    
        }
    }
    
    for (int i=0; i<n; i++ ){
        
        if ( i%2==0 ){
            alice += a[i] ;
            
        } else {
            bob += a[i] ;
            
        }
    }
    
    printf ("%d\n",alice-bob) ;

    return 0 ;
}

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

int A[100000];

int partition(int *A,int p,int r) {
    int x = A[r];
    int i = p - 1;
    int temp;
    for ( int j = p; j < r; ++j ) {
        if ( A[j] <= x ) {
            i++;
            temp = A[i];
            A[i] = A[j];
            A[j] = temp;
        }
    }
    temp = A[i+1];
    A[i+1] = A[r];
    A[r] = temp;
    return i+1;
}

int main() {
    int n;
    int num;
    cin >> n;
    for ( int i = 0; i < n; ++i ) {
        cin >> A[i];
    }
    num = partition(A,0,n-1);
    for ( int i = 0; i < n; ++i ) {
        if ( i ) cout << " ";
        if ( i == num ) {
            cout << "[" << A[i] << "]";
        }
        else {
            cout << A[i];
        }
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 3432
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int W,H,x,y,r;
    cin >> W >> H >> x >> y >> r;

    if (x >= r && y >= r && x+r <= W && y+r <= H){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }

} 


Measured memory_bytes: 3084
#include<iostream>
using namespace std;
int main()
{
int n;
int x=0;
int mx=0;
cin>>n;
char s[n];
cin>>s;
for(int i=0;i<n;i++)
{
	if(s[i]=='I')
	x++;
	mx=max(x,mx);
	if(s[i]=='D')
int abs(x--);
	}	
	cout<<mx;
	return 0;
}

Measured memory_bytes: 256
import java.math.*

fun main(args: Array<String>) {
    val N = readInputLine().toInt()
    val AArr = readInputLine().split(" ").map { it.toLong() }.toLongArray()
    
    var lIndex = 1
    var rIndex = N - 2
    var lSum = AArr[0]
    var rSum = AArr[N - 1]
    
    while (rIndex >= lIndex) {
        if (rSum > lSum) {
            lSum += AArr[lIndex]
            lIndex++
        } else {
            rSum += AArr[rIndex]
            rIndex--
        }
    }

    println(Math.abs(rSum - lSum))
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 80840
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <map> 
#include<set>
#include<queue>

typedef long long ll;


#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;

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

const long long INF = 1000000000000000;
typedef pair<int, int> P;
ll ma = 1000000000 + 7;
ll h, w, n,k; string s;
char maze[60][60];
int dis[101][101];
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };

int gcd(int x, int y) {
	if (x % y == 0) return y;
	return gcd(y, x % y);

}
int main() {
	cin >> n;
	vector<ll> a(n); vector<ll> l(n); vector<ll> r(n); vector<ll> m(n);
	rep(i, n) {
		cin >> a[i];
	}
	l[0] = a[0];
	r[n-1] = a[n-1];
	for (ll i = 1; i < n; i++) {
		l[i] = gcd(l[i - 1], a[i]);
		r[n - i - 1] = gcd(r[n - i], a[n - i - 1]);
	}
	rep(i, n) {
		if (i == 0) {
			m[i] = r[i + 1];
		}
		else if (i == n - 1) {
			m[i] = l[i - 1];
		}
		else {
			m[i] = gcd(l[i - 1], r[i + 1]);
		}
	}
	sort(m.begin(), m.end(), greater<int>());
	cout << m[0] << endl;
}




Measured memory_bytes: 3328
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<numeric>
#include<limits>
#include<iterator>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rep(i,n) for(int i=0; i<n; i++)
#define INF (1<<20)

using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ll, char> plc;

int L[1010][1010];

int main() {
	string s1, s2;
	cin >> s1 >> s2;

	for (int i = 0; i <= s1.size(); i++)
		L[i][0] = i;
	for (int i = 0; i <= s2.size(); i++)
		L[0][i] = i;

	for (int i = 1; i <= s1.size(); i++) {
		for (int j = 1; j <= s2.size(); j++) {
			int diff = (s1[i - 1] == s2[j - 1]) ? 0 : 1;
			L[i][j] = min(L[i-1][j-1]+diff,min(L[i-1][j]+1,L[i][j-1]+1));
		}
	}
	cout << L[s1.size()][s2.size()] << endl;
}

Measured memory_bytes: 7160
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);
//cin.tie(0);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
ll mod=1000000007;
ll mod2=998244353;
ll inf=1000000000000000000;
double pi=2*acos(0);
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll lmax(ll a,ll b){
    if(a<b)return b;
    else return a;
}
ll lmin(ll a,ll b){
    if(a<b)return a;
    else return b;
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll gya[200010];
ll kai[200010];
ll beki(ll n,ll k){
  ll ret=1;
  ll now=n;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=mod;
    }
    now*=now;
    now%=mod;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n){
  return beki(n,mod-2);
}
void nckinit(ll n){
  kai[0]=1;
  kai[1]=1;
  for(int i=2;i<=n;i++){
    kai[i]=kai[i-1]*i;
    kai[i]%=mod;
  }
  gya[n]=gyaku(kai[n]);
  for(int i=n-1;i>=1;i--){
    gya[i]=gya[i+1]*(i+1);
    gya[i]%=mod;
  }
  gya[0]=1;
}    
ll nck(ll n,ll k){
  if(k<0)return 0;
  if(k==0||n==k)return 1;
  ll ret=kai[n];
  ret*=gya[n-k];
  ret%=mod;
  ret*=gya[k];
  ret%=mod;
  return ret;
}
ll npk(ll n,ll k){
  if(k<0)return 0;
  if(k==0)return 1;
  ll ret=kai[n];
  ret*=gya[n-k];
  ret%=mod;
  return ret;
}

int main(){
  ll n,k;cin>>n>>k;
  ll a[n];rep(i,0,n)cin>>a[i];
  if(k==0){
    ll sum=0;
    rep(i,0,n)sum+=a[i];
    cout<<sum<<endl;
    return 0;
  }
  ll now=1;
  ll cnt=0;
  for(;;){
    if(now>k)break;
    now*=2;
    cnt++;
  }
  ll dp[cnt+1][2];
  rep(i,0,cnt+1){
    rep(j,0,2){
      dp[i][j]=-inf;
    }
  }
  dp[0][1]=0;
  rep(i,0,cnt){
    ll u=Pow(2,cnt-1-i);
    ll t=k/u;
    t%=2;
    ll c[2];
    c[0]=0,c[1]=0;
    rep(j,0,n){
      ll tt=a[j]/u;
      tt%=2;c[tt]++;
    }
    if(t==0){
      dp[i+1][0]=max(c[0],c[1])*u+dp[i][0];
      dp[i+1][1]=dp[i][1]+c[1]*u;
    }
    else{
      dp[i+1][0]=max(max(c[0],c[1])*u+dp[i][0],dp[i][1]+c[1]*u);
      dp[i+1][1]=dp[i][1]+c[0]*u;
    }
  }
  ll ans=max(dp[cnt][0],dp[cnt][1]);
  rep(i,0,n){
    ll y=Pow(2,cnt);
    ll yy=a[i]/y;
    yy*=y;
    ans+=yy;
  }
  cout<<ans<<endl;
  rep(i,0,cnt+1){
    //rep(j,0,2)cout<<dp[i][j]<<" ";
    //cout<<endl;
  }
}
      





Measured memory_bytes: 1024
import java.util.Scanner;

class Main{
    public static void main(String args[]){
        Scanner scan=new Scanner(System.in);
        int w=scan.nextInt();
        int h=scan.nextInt();
        int x=scan.nextInt();
        int y=scan.nextInt();
        int r=scan.nextInt();
        if(x+r>w||x-r<0||y+r>h||y-r<0)System.out.println("No");
        else System.out.println("Yes");
   }
}


Measured memory_bytes: 26188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define pll pair<ll,ll>
#define rep(i,n) for(int i=0;i<n;i++) 
const ll INF = 1LL<<60;
const ll mod = (int)1e9 + 7;

int gcd_euclid(ll u, ll v) {
  ll r;
  while (0 != v) {
    r = u % v; u = v; v = r; /* swap */
  }
  return u;
}

int main() {
    ll N; cin >> N;
    //ll N,M; cin >> N >> M;
    //string S; cin >> S;
    //ll H,W; cin >> H >> W;
    ll A[N];
    rep(i,N){
        cin >> A[i];
    }
    int L[N+1];
    int R[N+1];
    L[0]=0;
    R[N]=0;
    rep(i,N){
        L[i+1]=gcd_euclid(L[i],A[i]);
    }
    for(int i=N-1;i>=0;i--){
        R[i]=gcd_euclid(R[i+1],A[i]);
    }
    int mx=0;
    rep(i,N){
        chmax(mx,gcd_euclid(L[i],R[i+1]));
    }
    cout << mx;
}

/*



 */



Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,k,n) for(int i=k;i<n;++i)
#define repe(i,k,n) for(int i=k;i<=n;++i)

using namespace std;

int main()
{
    cin.tie(0);cout.tie(0);
    ios::sync_with_stdio(false);
    string a,b;
    cin >> a >> b;
    int aa = a.size(),bb = b.size();

    for (int i=0;i<bb;++i){
        putchar(a[i]);
        putchar(b[i]);
    }

    if (aa != bb){
        putchar(a[bb]);
    }

    return 0;
}


Measured memory_bytes: 3640
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<functional>
#include<queue>
#include<vector>
#include<map>
#include<cmath>
using namespace std;
int n,dx,dy,hx,hy;
int cx[21],cy[21];
bool used[21];
bool flag;
void dfs(int v,int cnt,double cost){
	if(cnt==n)flag=true;
	if(flag)return;
	for(int i=0;i<n;i++){
		if(!used[i]){
			double move=sqrt(pow(cx[v]-cx[i],2)+pow(cy[v]-cy[i],2));
			double ng=sqrt(pow(dx-cx[i],2)+pow(dy-cy[i],2));
			if(cost+move>=ng)return;
		}
	}
	for(int i=0;i<n;i++){
		if(!used[i]){
			double move=sqrt(pow(cx[v]-cx[i],2)+pow(cy[v]-cy[i],2));
			used[i]=true;
			dfs(i,cnt+1,cost+move);
			used[i]=false;
		}
	}
}

int main(void){
	while(1){
		scanf("%d %d %d %d %d",&n,&hx,&hy,&dx,&dy);
		if(n+hx+hy+dx+dy==0)break;
		for(int i=0;i<n;i++){
			scanf("%d %d",&cx[i],&cy[i]);
		}
		cx[n]=hx,cy[n]=hy;
		flag=false;
		dfs(n,0,0);
		printf("%s\n",flag?"YES":"NO");
	}
	return 0;
}

Measured memory_bytes: 1012
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<int> A;
vector<int> B;

bool check(int len){
  for(int begin = 0; begin < B.size() - len + 1; begin++){
    int bidx = begin;
    for(int j = 0; j < A.size(); j++){
      if(A[j] == B[bidx]) bidx++;
      if(bidx - begin >= len) return true;
    }
  }
  return false;
}

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

  int a, b; cin >> a >> b;
  A = vector<int>(a);
  B = vector<int>(b);
  for(int i = 0; i < a; i++){
    cin >> A[i];
  }
  for(int i = 0; i < b; i++){
    cin >> B[i];
  }

  int l = 0, r = b;
  while(l+1 < r){
    int mid = (l+r)/2;
    if(check(mid)){
      l = mid;
    }else{
      r = mid;
    }
  }

  cout << l << endl;

  return 0;
}

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

public class Main {

	public static String Y = "Yes";
	public static String N = "No";
	public static long MOD = (long) (Math.pow(10, 9) + 7);
	public static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {
		long n = nl();
		long ans = 0;

		for (int i = 1; i <= n; i++) {
			long x = i;
			long y = n / x; // 末項
			ans += y * (y + 1) * x / 2;
		}
		out(ans);
	}

	/*
	 * 以下メソッド集
	 */
	static int[] sort(int[] n) {
		Arrays.sort(n);
		return n;
	}

	static void debug() {
		out("---");
	}

	static void debug(long a) {
		out("-------");
		out(a);
		out("-------");
	}

	static void debug(String a) {
		out("-------");
		out(a);
		out("-------");
	}

	static long[] sort(long[] n) {
		Arrays.sort(n);
		return n;
	}

	static int ketasuu(int n) {
		String str = "" + n;
		return str.length();
	}

	static int account(String str) {
		String target = "AC";
		int count = 0;
		int len = str.length();
		for (int i = 0; i < len - 1; i++) {
			if (target.equals(str.substring(i, i + target.length()))) {
				count++;
			}
		}
		return count;
	}

	static int ni() {
		return sc.nextInt();
	}

	static long nl() {
		return sc.nextLong();
	}

	static double nd() {
		return sc.nextDouble();
	}

	static String n() {
		return sc.next();
	}

	static char[] nc() {
		return sc.next().toCharArray();
	}

	static int kaijo(int n) {
		if (n == 0 || n == 1) {
			return 1;
		} else {
			return n * kaijo(n - 1);
		}
	}

	static int fib(int n) {
		return (n == 1 || n == 0) ? n : fib(n - 2) + fib(n - 1);
	}

	static long lcm(long m, long n) {

		return m * n / gcd(m, n);
	}

	static int lcm(int m, int n) {

		return m * n / gcd(m, n);
	}

	static long gcd(long a, long b) {
		return (b == 0) ? a : gcd(b, a % b);
	}

	static int gcd(int a, int b) {
		return (b == 0) ? a : gcd(b, a % b);
	}

	static void out(String info) {
		System.out.println(info);
	}

	static void out(int info) {
		System.out.println(info);
	}

	static void out(double info) {
		System.out.println(info);
	}

	static void out(long info) {
		System.out.println(info);
	}

	static void out(char info) {
		System.out.println(info);
	}

	static void out(Object obj) {
		System.out.println(obj.toString());
	}

	static void outn(String info) {
		System.out.print(info);
	}

	static void outn(int info) {
		System.out.print(info);
	}

	static void outn(double info) {
		System.out.print(info);
	}

	static void outn(long info) {
		System.out.print(info);
	}

	static void outn(char info) {
		System.out.print(info);
	}

	static double max(double d, double e) {
		return Math.max(d, e);
	}

	static long max(long a, long b) {
		return Math.max(a, b);
	}

	static long min(long d, long e) {
		return Math.min(d, e);
	}

	static int min(int a, int b) {
		return (int) Math.min(a, b);
	}
}

class XY {
	int h;
	int c;

	XY(int h, int c) {
		this.h = h;
		this.c = c;
	}
}


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

int main() {
  int64_t n, s = 1, mod = 1000000007;
  cin >> n;
  rep(i, n){
    s *= (i+1);
    s %= mod;
  }
  cout << s << endl;
  return 0;
}

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

using namespace std;

int main() {
    int N; cin>>N;
    
    vector<int> pn(N), qn(N);
    for (int i=0;i<N;i++) {
        int p; cin>>p;
        pn[i] = p;
        qn[i] = p;
    }

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

    int diff=0;
    for (int i=0;i<N;i++) {
        if (pn[i] != qn[i]) {
            diff++;
        }
    }

    if (diff <= 2) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }


    return 0;
}

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

#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
ll MOD = 1e9+7;

ll dp[104][100009];
ll a[104],pre[104][100009];
inline int add(int a, int b){
    a += b;
    if(a >= MOD)a -= MOD;
    return a;
}
 
inline int sub(int a, int b){
    a -= b;
    if(a < 0)a += MOD;
    return a;
}
int main(){
    fast;
    ll n,k;cin>>n>>k;

    for(ll i=0;i<n;++i){
        cin>>a[i];
    }

    for(ll i=0;i<n;++i)
        pre[i][0] = dp[i][0] = 1;
    
    
    for(ll i=0;i<=k;++i){
        dp[0][i] = 1*(i<=a[0]);
        if(i>0)
            pre[0][i] = pre[0][i-1] + dp[0][i];
        else
            pre[0][0] = 1;
        
    }
    for(ll i=1;i<n;++i){
        for(ll j=1;j<=k;++j){//sum to make
/*            if(j-a[i]-1<0){
                dp[i][j] = pre[i-1][j]%MOD;
            }
            else{
                dp[i][j] = pre[i-1][j] - pre[i-1][j-a[i]-1];
            }
            pre[i][j] = pre[i][j-1] + dp[i][j];
*/
            
            int first = (j - a[i] - 1 >= 0)? pre[i - 1][j - a[i] - 1] : 0;
            int last = pre[i - 1][j];
            dp[i][j] = add(dp[i][j], sub(last, first));
            pre[i][j] = add(pre[i][j - 1], dp[i][j]);
            
            /*  precalculate the sum from dp[i-1][max(0,j-a[i])] to dp[i-1][j].
                which is equal to dp[i-1][j] - dp[i-1][max(0,j-a[i])-1]
            */
            /*for(ll l=max(0ll,j-a[i]);l<=j;++l){//
                dp[i][j] = (dp[i][j]%mod + dp[i-1][l]%mod)%mod;
                
            }*/
        }
    }
    /*cout<<endl<<"prefix\n";
    for(ll x=0;x<n;++x){ 
        cout<<"\n->"<<x+1<<endl; 
        for(ll i=0;i<=k;++i){
            cout<<"\t"<<pre[x][i]<<" ";
        }
    }
    cout<<"\ndp\n";
    for(ll x=0;x<n;++x){
        cout<<"\n->"<<x+1<<endl;
        for(ll i=0;i<=k;++i){
            cout<<"\t"<<dp[x][i]<<" ";
        }
    }*/

    cout<<dp[n-1][k];

    return 0;
}

Measured memory_bytes: 80128
// In the name of GOD
#include<bits/stdc++.h>
using namespace std;

#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";

#define     IOS         ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define 	setprecn(x) cout<<fixed<<setprecision(x);
#define 	ll          long long int
#define 	pb          push_back
#define 	pll         pair<ll,ll>
#define 	vll         vector<ll>
#define 	ff          first
#define 	ss          second
#define 	all(a)      (a).begin(),(a).end()
#define 	sz(x)       (ll)x.size()
#define 	mod         1000000007
#define 	inf         10000000000000007
#define 	rep(i,n)    for(ll i=0;i<n;i++)
#define 	repe(i,a,b) for(ll i=a;i<b;i++)
#define 	lbnd        lower_bound
#define 	ubnd        upper_bound
#define 	bs          binary_search

ll power(ll a,ll b,ll m=mod)
{
	if(b==0)
		return 1;
	if(b==1)
		return a;
	ll c=power(a,b/2,m);
	if(b%2==0)
		return((c%m)*(c%m))%m;
	return ((((c%m)*(c%m))%m)*(a%m))%m;
}
/********************************************************/
//	d.erase(unique(all(d)), d.end());



int main()
{
	IOS;
	ll n,k,m,i,j,c=0,cs=0,t;
	t=1;

	// cin>>t;
	string s;
	while(t--)
	{
		cin>>n>>m;
		// n=s.length();
		// ll a[n];
		if(m>=n) cout<<"unsafe";
		else cout<<"safe";

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


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

using namespace std;

int n, m;
int lft, rit;
int arr[100005];
int curC, res;

int main()
{
    while(cin >> n >> m)
    {
        memset(arr, 0, sizeof(arr));
        for(int i = 1; i <= m; i++)
        {
            cin >> lft >> rit;
            arr[lft]++;
            arr[rit + 1]--;
        }

        curC = 0;
        res = 0;
        for(int i = 1; i <= n; i++)
        {
            curC += arr[i];
            if(curC == m)
                res++;
        }

        cout << res << endl;
    }

    return 0;
}


Measured memory_bytes: 768
import java.util.*;

class Main
{
	static Scanner in = new Scanner(System.in);
	public static void main(String[]args)
	{
		while(in.hasNext())
		{
			String[] A = in.nextLine().split(" ");
			String[] B = in.nextLine().split(" ");
			int hit = 0, blow = 0;
			for(int i = 0; i < A.length;i++)
			{
				for(int j = 0; j < B.length;j++)
				{
					if(A[i].equals(B[j]))
					{
						if(i==j) hit++;
						else blow++;
					}
				}
			
			}
		System.out.printf("%d %d\n",hit,blow);
		}
	
	}
}

Measured memory_bytes: 17360
#include <iostream>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <cstring>

uint64_t dp[101][100001];

uint64_t knapsack1_recur(const std::vector<int> &v,
                         const std::vector<int> &w,
                         int capacity, int x) {
  if (x >= 0) {
    if (dp[x][capacity]) return dp[x][capacity];

    uint64_t a = 0;
    if (capacity >= w[x]) {
      a =
        std::max(knapsack1_recur(v, w, capacity - w[x], x - 1) + v[x],
                 knapsack1_recur(v, w, capacity, x - 1));
    }
    else {
      a = knapsack1_recur(v, w, capacity, x - 1);
    }
/*
    std::cout
      << "capacity=" << capacity
      << " x=" << x
      << " --> " << a
      << std::endl;
*/
    dp[x][capacity] = a;
    return a;
  }
  return 0;
}

int main() {
  int n, capacity;
  std::cin >> n >> capacity;
  std::vector<int> v(n), w(n);
  memset(dp, 0, sizeof(dp));
  for (int i = 0; i < n; ++i) {
    std::cin >> w[i] >> v[i];
  }
  std::cout
    << knapsack1_recur(v, w, capacity, n - 1)
    << std::endl;
  return 0;
}

Measured memory_bytes: 79232
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<int> B(N - 1);
  int ans = 0;
  for(int i = 0; i < N - 1; i++) {
    cin >> B.at(i);
  }
  ans += B.at(0) + B.at(N - 2);
  for(int i = 1; i < N - 1; i++) {
    if(B.at(i - 1) > B.at(i)) {
      ans += B.at(i);
    }
    else {
      ans += B.at(i - 1);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False


n,k = m()

a = l()

a.sort()

po = bs.bisect(a,0)

a,b = a[po:],a[po-1::-1]

n,m = len(a),len(b)

ok = 10 ** 18

bad = - ok

while ok - bad > 1:
    x = (ok + bad)//2
    s = 0
    if x >= 0:
        s += n*m
        t = 0
        i = n
        for y in a:
            while i and a[i-1] * y > x:
                i -= 1
            t+= i
            if y*y <= x:
                t-=1
        s += t // 2
        t = 0
        i = m
        for y in b:
            while i and b[i-1] * y> x:
                i -= 1
            t += i
            if y * y <= x:
                t -= 1
        s += t//2
    else:
        i = m
        for y in a:
            while i and b[i-1] * y <= x:
                i -= 1
            s += m-i
    if s >= k:
        ok = x
    else:
        bad = x
print(ok)





Measured memory_bytes: 84884
#include <stdio.h>

int main()
{
  int i,j,n,k,o,minj,count=0;
  scanf("%d",&n);
  int A[100];
  for(k=0;k<n;k++)
    {
      scanf("%d",&A[k]);
    }

  for(i=0;i<=n-1;i++)
    {
      minj=i;
      for(j=i;j<=n-1;j++)
	{
          if(A[j]<A[minj])
	    {
	      minj=j;
	    }
	}
      if(i!=minj)
	{
	  count++;
	  o=A[i];
	  A[i]=A[minj];
	  A[minj]=o;
	}
    }

  for(k=0;k<n-1;k++)
    {
      printf("%d ",A[k]);
    }
  printf("%d\n",A[n-1]);
  
  printf("%d\n",count);
  return 0;
}
	  



Measured memory_bytes: 2104
use std::io::prelude::*;
use std::io::stdin;
use std::str::FromStr;

fn main() {
    let a: i32 = read();
    let b: i32 = read();
    let x: i32 = read();
    println!("{}", if a + b >= x && x >= a { "YES" } else { "NO" });
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
using lint = long long;
int main(){
    lint count = 1;
    lint attack = 0;
    lint H;
    cin >> H;
    while(H != 0){
        H = lint(H / 2);
        attack += count;
        count*=2;
    }
    cout << attack << endl;
    return 0;
}

Measured memory_bytes: 256
/*   LazyBones
*
*/

#include <bits/stdc++.h>
#include<cctype>
#include <sstream>
#include<ctime>
using namespace std;
#define rep(i,b) for(int i=0;i<b;i++)
#define getarr(a,n) for(int i=0;i<n;i++){cin>>a[i];}
#define disparr(a,n) for(int i=0;i<n;i++){cout<<a[i];}cout<<"\n";
#define disparrs(a,n) for(int i=0;i<n;i++){cout<<a[i]<<" ";}cout<<"\n";
#define disparrl(a,n) for(int i=0;i<n;i++){cout<<a[i]<<"\n";}cout<<"\n";
#define mem0(a) memset(a,0,sizeof(a));
#define ull unsigned long long int
#define ll long long int
#define ld long double
#define key pair<ld,ld>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define si set<int>
#define vii vector<pair<int,int> >
#define vi vector<int>
#define vll vector<ll>
#define vb vector<bool>
#define vvi vector<vector<int>>
#define vs vector<string>
#define all(v) v.begin(),v.end()
#define pb push_back
#define pob pop_back
#define pof pop_front
#define pf push_front
#define mp make_pair
#define F first
#define S second
//#define nu 100001
#define M 1000000007
#define mul(x,y) ((ll)(x)*(y))%M
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++)
#define fastio  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define INF 0x3f3f3f3f
#define MOD 998244353

int MODU(int a, int b)
{
    if(a>b)
    return a-b;
    else
    return b-a;
}
ll max3(ll a,ll b,ll c)
{
    return max(c,max(a,b));
}
ll power(ll x,ll y, ll p)
{
    ll res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
ll max(ll a,ll b)
{
    return (a>b)?a:b;
}
ll min(ll a,ll b)
{
    return (a<b)?a:b;
}
ld min(ld a,ld b)
{
    return (a<b)?a:b;
}
ll gcd(ll a,ll b)
{
    if(b==1)
    return 1;
    else if(a%b==0)
    return b;
    else
    return gcd(b,a%b);
}
ll mod(ll x){
    if(x>=0)
    return x;
    else
    return -x;
}
ll lcm(ll a,ll b){
    return (a*b)/gcd(a,b);
}

void cycle(vll c,vi& v,int u, ll& val,vi& len,int ini){
    //cout<<u<<endl;
    v[u]=1;
    if(c[u]==u){
        v[u]=2;
        val=1;
        return;
    }
    if(v[c[u]]==2){
        return;
    }
    if (v[c[u]]==1){
        if(v[c[u]]!=ini)
            return;
        val=len[u]+1-len[c[u]];
        //cout<<val<<" hf"<<endl;
        v[u]=2;
        return;
    }
    len[c[u]]=len[u]+1;
    //cout<<u<<endl;
    cycle(c,v,c[u],val,len,ini);
    v[u]=2;
    return;

}



int main()
{
    fastio;
    ll n,m;
    cin>>n>>m;
    ll a1,a2;
    if(m%4==0)a1=m;
    if(m%4==1)a1=1;
    if(m%4==2)a1=m+1;
    if(m%4==3)a1=0;
    m=n-1;
    a2=a1;
    if(n==0){
        cout<<a1;
        return 0 ;
    }
    if(m%4==0)a1=m;
    if(m%4==1)a1=1;
    if(m%4==2)a1=m+1;
    if(m%4==3)a1=0;
    cout<<(a2 ^ a1);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef pair<long long,int>P;
const int maxn=1e6+5;
long long n,x[maxn],s[maxn],m;
int main(void){
    priority_queue<P>q;
    scanf("%lld",&n);
    for(int i=1;i<=n;i++){
        scanf("%lld%lld",&x[i],&s[i]);
        s[i]+=s[i-1];q.push(P(s[i]-x[i],i));}
    for(int i=1,flag;i<=n;i++){
        flag=1;while(flag){
            P p=q.top();
            if(p.second<i)q.pop();
            else{m=max(m,p.first-s[i-1]+x[i]);flag=0;}
        }
    }
    printf("%lld\n\r",m);
}

Measured memory_bytes: 11632
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <sstream>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <functional>
#include <cmath>
#include <array>

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI;
typedef pair<int,int> pii;
const int md = (int)1e9+7;
const int MX = 200120;
ll  fct[MX], inv[MX];

ll bin_pow(ll x, ll n, ll mod){
	ll res = 1LL;
	for(; n > 0; n >>=1, x = x*x %mod) if(n & 1) res = res * x %mod;
	return res;
}

void init(int cmx){

	fct[0]=fct[1]=1;
	rep2(i,2,cmx+10) fct[i] = fct[i-1] * i % md;
	inv[cmx] = bin_pow(fct[cmx], md-2, md);
	repr(i,cmx,1) inv[i-1] = inv[i] * i % md;
}

ll nCk_mod(ll n, ll k, ll mod=md) {
	ll ret =fct[n] * inv[k] % mod * inv[n-k] % mod;
	return ret;
}

int main()
{
	int h,w,a,b;
	cin >>h >>w >>a >>b;
	
	init(h+w+5);
	ll ans =0;
	rep(i, h-a){
		(ans += nCk_mod(i+b-1,b-1) * nCk_mod(w-b-1+h-i-1,h-i-1)) %=md;
	}
	
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3328
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
ll solve1(ll n){
  vector<ll> yaku;
  for(ll i=2;i*i<=n;i++){
    if(n%i==0){
      yaku.push_back(i);
      if(i*i!=n) yaku.push_back(n/i);
    }
  }
  ll ans=1; //k=n
  for(int i=0;i<yaku.size();i++){
    ll k=yaku[i];
    ll N=n;
    while(N>=k){
      if(N%k==0) N/=k;
      else N%=k;
    }
    if(N==1) ans++;
  }
  return ans;
}
ll solve2(ll n){
  vector<ll> yaku;
  for(ll i=2;i*i<=n;i++){
    if(n%i==0){
      yaku.push_back(i);
      if(i*i!=n) yaku.push_back(n/i);
    }
  }
  ll res=yaku.size()+1;
  return res;
}
int main(){
  ll n;
  cin>>n;
  if(n==1||n==2){
    cout<<1<<endl;
    return 0;
  }
  cout<<solve1(n)+solve2(n-1)<<endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>

using namespace std;

int main() {
	int h, w;
	cin >> h >> w;
	
	vector<string> g(h);
	vector<int> hUse(h);
	vector<int> wUse(w);
	
	for (auto &&e : g) {
		cin >> e;
	}
	
	for (int i = 0; i < h; ++i) {
		for (int j = 0; j < w; ++j) {
			if (g[i][j] == '#') {
				hUse[i] = 1;
				wUse[j] = 1;
			}
		}
	}
	
	for (int i = 0; i < h; ++i) {
		if (hUse[i] == 0)
			continue;
		
		for (int j = 0; j < w; ++j) {
			if (wUse[j] == 0)
				continue;
			
			if (g[i][j] == '#') {
				cout << "#";
			} else {
				cout << ".";
			}
		}
		
		cout << endl;
	}
}

Measured memory_bytes: 256
S = input()
N = len(S)
dp = [[0 for _ in range(4)] for _ in range(N+1)]
dp[0][0] = 1
MOD = 10 ** 9 + 7

for i in range(N):
    if S[i] == 'A':
        dp[i+1][0] = dp[i][0] % MOD
        dp[i+1][1] = (dp[i][0] + dp[i][1]) % MOD
        dp[i+1][2] = dp[i][2] % MOD
        dp[i+1][3] = dp[i][3] % MOD
     
    if S[i] == 'B':
        dp[i+1][0] = dp[i][0] % MOD
        dp[i+1][1] = dp[i][1] % MOD
        dp[i+1][2] = (dp[i][1] + dp[i][2]) % MOD
        dp[i+1][3] = dp[i][3] % MOD
    
    if S[i] == 'C':
        dp[i+1][0] = dp[i][0] % MOD
        dp[i+1][1] = dp[i][1] % MOD
        dp[i+1][2] = dp[i][2] % MOD
        dp[i+1][3] = (dp[i][2] + dp[i][3]) % MOD
    
    if S[i] == '?':
        dp[i+1][0] = 3 * dp[i][0] % MOD
        dp[i+1][1] = (dp[i][0] + 3 * dp[i][1]) % MOD
        dp[i+1][2] = (dp[i][1] + 3 * dp[i][2]) % MOD
        dp[i+1][3] = (dp[i][2] + 3 * dp[i][3]) % MOD

print(dp[N][3] % MOD)

Measured memory_bytes: 27636
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <cctype>
#include <cmath>
#include <cstring>
#include <string>
#include <vector>
#define LL long long
#define MAXN 100010
#define debug(x) cerr << #x << " " << x << endl
using namespace std;

inline int read() { int x = 0, f = 1; char ch = getchar();
    for(; !isdigit(ch); ch = getchar()) f = ch == '-' ? -1 : 1;
    for(; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0'; return x * f;
}

const int inf = 1e9 + 7;

int n, m;
struct Note {
    int p, y, idx;
//    bool operator < (const Note &cmp) const {
//        if(p == cmp.p) return y < cmp.y;
//        return p < cmp.p;
//    }
} c[MAXN];

bool cmp1(Note a, Note b) {
    if(a.p == b.p) return a.y < b.y;
    return a.p < b.p;
}
bool cmp2(Note a, Note b) {
    return a.idx < b.idx;
}

int main() {
    m = read(); n = read();
    for(int i = 1; i <= n; ++i) {
        c[i].p = read();
        c[i].y = read();
        c[i].idx = i;
    }
    sort(c + 1, c + n + 1, cmp1);
    int cnt = 1;
    for(int i = 1; i <= n; ++i) {
        c[i].y = cnt;
        ++cnt;
        if(c[i].p ^ c[i + 1].p)
            cnt = 1;
    }
    sort(c + 1, c + n + 1, cmp2);
    for(int i = 1; i <= n; ++i) {

        printf("%06d%06d\n", c[i].p, c[i].y);
    }
    return 0;
}

Measured memory_bytes: 2688
'use strict'
const main = arg => {
	const input = arg.trim().split("\n");
	let a = input[0].split('')
	let b = input[1].split('')
	let c = input[2].split('')
	
	function shiftCard(man) {
		let out = eval(man).shift()
		if(out === undefined) {
			console.log(man.toUpperCase())
			return
		}
		shiftCard(out)
	}
	shiftCard('a')

}   
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
<?php
  
list($n, $k) = explode(' ', trim(fgets(STDIN)));

$nums = [];
for($i=0; $i<$n; $i++){
  $nums[$i] = trim(fgets(STDIN));
}
sort($nums);

$min = $nums[$n-1];
for($i=0; $i<=$n-$k; $i++){
  $m = $nums[$i+$k-1] - $nums[$i];
  if ($m < $min) $min = $m;
}

echo $min;

?>

Measured memory_bytes: 12792
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        if (k % 2 == 0) {
            long b = 0;
            long c = 0;
            for (int i = 1; i <= n ; i++) {
                if (i % k == k/2) {
                    b++;
                } else if (i%k == 0) {
                    c++;
                }
            }
            long ans = b* b * b + c * c * c;
            System.out.println(ans);
        } else {
            long c = 0;
            for (int i = 1; i <= n ; i++) {
                if (i%k == 0) {
                    c++;
                }
            }
            long ans =  c * c * c;
            System.out.println(ans);
        }
    }

}

Measured memory_bytes: 23764
N, K = map(int, input().split())
a = list(map(int, input().split()))
sa = [0]
for i in range(N):
    sa.append(sa[-1] + a[i])

sb = [0]
for i in range(N):
    sb.append(sb[-1] + max(0, a[i]))


num = 0
for i in range(N - K + 1):
    num = max(num, sb[i] + max(0, sa[i + K] - sa[i]) + sb[N] - sb[i + K])

print(num)



Measured memory_bytes: 16776
S = input()
T = input()

width = len(T)
predict_word = []
for s_index in range(len(S)):
    if(len(S) < s_index + width):
        break
    predict_word.append(S[s_index:s_index+width])


count_list, ans = [], []
for p_word in predict_word:
    tmp = []
    for count, word in enumerate(p_word):
        if(T[count] == word):
            tmp.append(word)
    count_list.append(tmp)

for count in count_list:
    ans.append(len(count))

print(len(T)-max(ans))


Measured memory_bytes: 10792