akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <assert.h>
#include <numeric>
#include <iomanip>

using ll = long long;
using P = std::pair<ll, ll>;

#define rep(i, a, b) for (ll(i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cout << i << "\n"

const int INF = 100000000;
const ll MOD = 1000000007;

ll pow_mod(ll x, ll y, ll mod)
{
    if (y == 0)
        return 1;
    if (y % 2)
    {
        return (x * pow_mod(x, y - 1, mod)) % mod;
    }
    else
    {
        return pow_mod(x * x, y / 2, mod);
    }
}

int main()
{
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    //問題文中の添え字が0-indexか1-indexか確認!
    ll n;
    std::cin >> n;
    std::vector<ll> a(n), seq;
    rep(i, 0, n)
    {
        std::cin >> a[i];
    }
    seq.push_back(a[0]);
    rep(i, 1, n)
    {
        if (a[i] <= seq[0])
        {
            seq.insert(seq.begin(), a[i]);
        }
        else
        {
            auto itr = std::lower_bound(all(seq), a[i]);
            itr--;
            *itr = a[i];
        }
    }
    std::cout << seq.size();
    return 0;
}

Measured memory_bytes: 2168
#include <iostream>
#include <string> 
#include <vector> 
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include <math.h>
using namespace std;

//#define int long long
#define endl "\n"
#define all(v)  v.begin(),v.end()
#define fir first
#define sec second
#define fro front
#define m_p make_pair
#define mod 1000000007
#define INF 2000000000
#define rep(i,n)  for(int i=0; i<(int) (n); i++)
#define vecin(v) for(int i=0; i<(int)v.size(); i++)cin>>v[i];
using namespace std;

const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
int jousu(int x00, int y00) {
	int z00 = 1;
	for (int i = 0; i < y00; i++) {
		z00 *= x00;
	}
	return z00;
}
int keta(int x00) {
	int z00 = x00;
	int w00 = 0;
	while (z00 != 0) {
		z00 /= 10;
		w00++;
	}
	return w00;
}
int krag(double xx) {
	return INF - (int)(INF - xx);
}


int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int modpow(int a, int n) {
	int res = 1;
	while (n > 0) {
		if (n & 1) res* a% mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
int com(int xx, int yy) {
	int zz = 1;
	for (int i = xx; i > xx - yy; i--) {
		zz *= i;
		zz %= mod;
	}
	for (int i = 1; i <= yy; i++) {
		zz *= modinv(i, mod);
		zz %= mod;
	}
	return zz;
}
int gcd(int xx, int yy) {
	int p = xx;
	int q = yy;
	if (q > p)swap(p, q);
	while (p % q != 0) {
		p %= q;
		swap(p, q);
	}
	return q;
}
int lcm(int xx, int yy) {
	return xx * yy / gcd(xx, yy);
}
bool prime(int xx) {
	int a = xx;
	for (int i = 2; i * i <= xx; i++) {
		if (xx % i == 0) {
			return 0;
		}
	}
	return 1;
}



int main() {
	int a=0;
	string s;
	cin >> s;
	rep(i, s.size()) {
		if (s[i] == '0') {
			a++;
		}
	}
	cout << min(a, (int)s.size() - a) * 2 << endl;
}



Measured memory_bytes: 512
import java.util.*;

public class Main {
    static TreeSet<Integer> all = new TreeSet<>();
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] arr = new int[n];
		for (int i = 0; i < n; i++) {
		    arr[i] = sc.nextInt();
		}
		int q = sc.nextInt();
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < q; i++) {
		    int x = sc.nextInt();
		    int left = 0;
		    int right = n;
		    while (right - left > 1) {
		        int m = (left + right) / 2;
		        if (arr[m] <= x) {
		            left = m;
		        } else {
		            right = m;
		        }
		    }
		    if (arr[left] == x) {
		        sb.append("1");
		    } else {
		        sb.append("0");
		    }
		    sb.append("\n");
		}
		System.out.print(sb);
	}
}



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

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	double T, X;
	cin >> T >> X;

	cout << T / X << endl;


}


Measured memory_bytes: 256
a = [0]* 1000001
m = 0
input()
for x in map(int, input().split()):
  m = max(m, x)
  a[x] += 1
m += 1
for i in range(1, m):
  if a[i]:
    for j in range(i + i, m, i):
      a[j] = 0
print(a.count(1))


Measured memory_bytes: 32352
#include <iostream>
#include <algorithm>

template <class T>
T gcd(T n, T m) {
    while (m != 0) {
        n %= m;
        std::swap(n, m);
    }
    return n;
}

int main() {
    int x, y;
    std::cin >> x >> y;
    std::cout << gcd(x, y) << std::endl;
}



Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
#define F(i,L,R) for(int i=L;i<R;i++)
#define FE(i,L,R) for(int i=L;i<=R;i++)
#define RF(i,l,r) for(int i=r;i>l;i--)
#define RFE(i,l,r) for(int i=r;i>=l;i--)
#define getI(i) scanf("%d",&i)
#define getII(i,j) scanf("%d%d",&i,&j)
#define getIII(i,j,k) scanf("%d%d%d",&i,&j,&k)
#define VgetI(i) int (i);scanf("%d",&(i));
#define VgetII(i,j) int (i),(j);scanf("%d%d",&(i),&(j));
#define VgetIII(i,j,k) int (i),(j),(k);scanf("%d",&(i),&(j),&(k));
#define EoF(n) int(n);while(~getI(n))
#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define abs(n) (n>0?n:(-n))
#define INF 2147483647
#define nINF -2147483648
int main(){
	int a,b;
	while(~getII(a,b)){
		char in[100];
		int cnt=0;
		scanf("%s",in);
		int l=strlen(in);
		if(in[a]!='-'){
			puts("No");
			continue;
		}
		F(i,0,l) if(in[i]=='-') cnt++;
		if(cnt!=1) puts("No");
		else puts("Yes");
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int h, w, n; cin >> h >> w >> n;
	auto valid = [&](int x, int y){
		if(x < 1 || y < 1) return false;
		if(x + 2 > h || y + 2 > w) return false;
		return true;
	};
	map<pair<int,int>, int > good;
	for(int i = 0; i < n; i++){
		int x, y; cin >> x >> y;
		for(int j = -2; j <= 0; j++) for(int k = -2; k <= 0; k++) if(valid(x + j, y + k)) {
			good[{x+j,y+k}]++;
		}
	}
	vector<long long> res(10, 0);
	for(auto e : good) res[e.second]++;
	res[0] = 1ll * (h - 2) * (w - 2);
	for(int i = 1; i < 10; i++) res[0] -= res[i];
	for(auto v : res) cout << v << endl;
	return 0;
}


Measured memory_bytes: 56448
class SegTree
    def update(k); @d[k] = @op.call(@d[2 * k], @d[2 * k + 1]); end

    def initialize(v, e, &op)
        @n = v.size
        @log = (@n - 1).bit_length
        @size = 1 << @log
        @op = op

        @d = Array.new(2 * @size, e) # vector

        @n.times{|i| @d[@size + i] = v[i]}
        (@size - 1).downto(1) {|i| update(i)}
    end

    def set(pos, x)
        pos += @size
        @d[pos] = x
        1.upto(@log) {|i| update(pos >> i)}
    end

    def get(pos); @d[pos + @size]; end

    def prod(l, r)
        sml = smr = @d[0]
        l += @size
        r += @size

        while l < r
            (sml = @op.call(sml, @d[l]); l += 1) if l[0] == 1
            smr = @op.call(@d[r -= 1], smr) if r[0] == 1
            l >>= 1
            r >>= 1
        end
        @op.call(sml, smr)
    end

    def all_prod; @d[1]; end

    def max_right(l, &f)
        return @n if l == @n
        l += @size
        sm = @d[0]

        loop do
            l >>= 1 while l[0] == 0
            if !f.call(@op.call(sm, @d[l]))
                while l < @size
                    l <<= 1
                    x = @op.call(sm, @d[l])
                    if f.call(x)
                        sm = x
                        l += 1
                    end
                end
                return l - @size
            end
            
            sm = @op.call(sm, @d[l])
            l += 1
            break if (l & -l) == l
        end

        @n
    end
    
    def min_left(r, &f)
        return 0 if r == 0
        r += @size
        sm = @d[0]

        loop do
            r -= 1
            r >>= 1 while r > 1 && r[0] == 1
            if !f.call(@op.call(@d[r], sm))
                while r < @size
                    r = 2 * r + 1
                    x = @op.call(@d[r], sm)
                    if f.call(x)
                        sm = x
                        r -= 1
                    end
                end
                return r + 1 - @size
            end
            sm = @op.call(@d[r], sm)
            break if (r & -r) == r
        end

        0
    end
end

n, q = gets.split.map(&:to_i)
st = SegTree.new(gets.split.map(&:to_i), -1) {|ch1, ch2| ch1 > ch2 ? ch1 : ch2}

q.times do
    t, x, y = gets.split.map(&:to_i)
    
    if t == 1
        st.set(x-1, y)
    elsif t == 2
        puts st.prod(x-1, y)
    else
        puts st.max_right(x-1){|v| v < y} + 1
    end
end

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

int digitcheck(long long x) {
  int cnt = 0;
  while(x > 0) {
    x /= 10;
    cnt++;
  }
  return cnt;
}

int main(){
  long long n;
  cin >> n;
  int tmp, ans = INT_MAX;
  for(long long i = 1; i*i <= n; i++) {
    if(n%i != 0) continue;
    int digitA = digitcheck(i);
    int digitB = digitcheck(n/i);
    tmp = max(digitA, digitB);
    ans = min(tmp, ans);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
char s1[11], s2[11], s3[11];
scanf("%s %s %s", s1, s2, s3);
printf("%c%c%c\n", s1[0] + 'A' - 'a', s2[0] + 'A' - 'a', s3[0] + 'A' - 'a');
return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;


public class Main {
  private static class Tuple {
    public final int a;
    public final long b;
    public Tuple(int a, long b) {
      this.a = a;
      this.b = b;
    }
  }
  public static void main(String[] args) throws Throwable {
    Scanner scanner = new Scanner(System.in);
    int N = scanner.nextInt();
    long K = scanner.nextLong();
    Tuple[] ab = new Tuple[N];
    for (int i = 0; i < N; i++) {
      int a = scanner.nextInt();
      int b = scanner.nextInt();
      ab[i] = new Tuple(a, b);
    }
    Arrays.sort(ab, (x, y) -> Integer.compare(x.a, y.a));

    int lastA = -1;
    long k = 0;
    for (int i = 0; k < K && i < N; i++) {
      k += ab[i].b;
      lastA = ab[i].a;
    }

    System.out.println(lastA);
  }
}

Measured memory_bytes: 89064
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  string s;
  set<string> ss;
  while (n--) {
    cin >> s;
    ss.insert(s);
  }
  cout << ss.size() << "\n";
  return 0;
}

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

int main(){
    int l;
    cin >> l;
    int n;
    cin >> n;
    int M = 0;
    for(int i=0; i<n; i++){
        int x, w;
        cin >> x >> w;
        M += x*w;
    }
    int W = abs(M);
    int X = 0;
    if( M > 0 ) X = -1;
    else if( M < 0 ) X = 1;
    cout << abs(X) << endl;
    if( X != 0 ){
        cout << X << " " << W << endl;
    }
}



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

int main()
{
    long long int a,b,c,x,y,ans=0,max,temp;
    cin>>a>>b>>c>>x>>y;
    max=x*a+y*b; //x个a元的，y个b元的，这个应该是最大的，再看后面的咯
    ans=max;
    temp=max;
    while(x>0&&y>0)
    {
        temp=temp-a-b+2*c;
        //cout<<temp<<endl;
        if(temp<max)
        {
            max=temp;
            ans=temp;
        }
        else
            break;
        x--;
        y--;
    }
    while(x>0)
    {
        temp=temp-a+2*c;
        //cout<<temp<<endl;
        if(temp<max)
            {
                max=temp;
                ans=temp;
            }
        else
            break;
        x--;
    }
    while(y>0)
    {
        temp=temp-b+2*c;
        //cout<<temp<<endl;
        if(temp<max)
            {
                max=temp;
                ans=temp;
            }
        else
            break;
        y--;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

class A {
	int a, b, c, d;
public:
	void solve()
	{
		int ans{ a };
		if (b < a) ans = b;
		if (c < d) ans += c;
		else ans += d;

		cout << ans << endl;
	}
	A() { cin >> a >> b >> c >> d; }
};


int main()
{
	A solution;
	solution.solve();

	return 0;
}

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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)

typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<int,P> PP;

struct edge {
	int to,cost;
	edge(int t,ll c):to(t),cost(c) {}
};

int dx[]={1,-1,0,0},dy[]={0,0,1,-1};
int ddx[]={1,1,1,0,-1,-1,-1,0},ddy[]={1,0,-1,-1,-1,0,1,1};

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

string a,b,c,d,s;

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

	cin>>s;
	if((s[0]==s[1]&&s[1]==s[2])||(s[1]==s[2]&&s[2]==s[3])) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int arr[10][10];
int chk[30010], c[10], cn = 1;
char s[30010];

int main() {
	
	int n, i, j, k, l, cnt = 0, sub;
	
	scanf("%d", &n);
	scanf("%s", s);
	
	c[s[n - 1] - '0'] = 1;
	
	for (i = n - 2; i >= 0; i--)
	{
		chk[i] = cn;
		
		if (c[s[i] - '0'] == 0)
		{
			c[s[i] - '0']++;
			cn++;
		}
	}

	for (i = 0; i < n - 1; i++)
	{
		for (j = i + 1; j < n; j++)
		{
			if (arr[s[i] - '0'][s[j] - '0'] == 1)
				continue;
			
			arr[s[i] - '0'][s[j] - '0']++;
			cnt += chk[j];
		}
	}
	
	printf("%d", cnt);
	
	return 0;
}

Measured memory_bytes: 256
import sys

def inp():
    for line in sys.stdin:
        i = 1
        while True:
            if is_prime(int(line[:-1]) - i) == True:
                print (int(line[:-1]) - i),
                break
            else:
                i += 1
        i = 1
        while True:
            if is_prime(int(line[:-1]) + i) == True:
                print (int(line[:-1]) + i)
                break
            else:
                i += 1

def is_prime(q):
    q = abs(q)
    if q == 2: return True
    if q < 2 or q&1 == 0: return False
    return pow(2, q-1, q) == 1
             
if __name__ == "__main__":
    inp()

Measured memory_bytes: 6344
#include<iostream>
#include<algorithm>
using namespace std;
long long xor1_a(long long a){
    if(a%4==1)
        return 1ll;
	if(a%4==2)
        return a+1;
    if(a%4==3 || a==0)
        return 0ll;
    return a;
}
int main(){
    long long n,m;
    cin>>n>>m;
    if(n==0) cout<<(xor1_a(m))<<endl;
    else cout<<((xor1_a(n-1))^(xor1_a(m)))<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define min(x,y) ((x<y)?(x):(y))
int main(){
	int n,m,d[105][105],f[105],u[105],i,j,x,y,ans;
	while(scanf("%d",&n)!=EOF){
		if(n==0)break;
		scanf("%d",&m);
		for(i=0;i<n;i++){
			f[i]=1000000;
			u[i]=0;
			for(j=0;j<n;j++){
				d[i][j]=1000000;
			}
		}
		for(i=0;i<m;i++){
			scanf("%d,%d,",&x,&y);
			scanf("%d",&d[x][y]);
			d[y][x]=d[x][y];
		}
		ans=1;f[0]=0;
		while(1){
			x=-1;
			for(i=0;i<n;i++){
				if(u[i]==0 && (x==-1 || f[i]<f[x]))x=i;
			}
			if(x==-1)break;
			u[x]=1;
			ans+=f[x]/100-1;
			for(i=0;i<n;i++){
				f[i]=min(f[i],d[x][i]);
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}

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

int main(){
    int a, b, c, d, x, y;
    cin >> a >> b >> c >> d;
    x = a + b;
    y = c + d;
    if (x - y > 0) {
        cout << "Left" << endl;
    }
    else if (x - y == 0) {
        cout << "Balanced" << endl;
    }
    else {
        cout << "Right" << endl;
    }
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());

		String str[] = br.readLine().split(" ");

		int rate[] = new int[9];
		for (int i = 0; i < n; i++) {
			int a = Integer.parseInt(str[i]);

			if (a < 400) {
				rate[0]++;
			} else if (a < 800) {
				rate[1]++;
			} else if (a < 1200) {
				rate[2]++;
			} else if (a < 1600) {
				rate[3]++;
			} else if (a < 2000) {
				rate[4]++;
			} else if (a < 2400) {
				rate[5]++;
			} else if (a < 2800) {
				rate[6]++;
			} else if (a < 3200) {
				rate[7]++;
			} else {
				rate[8]++;
			}
		}

		int count = 0;
		for (int i = 0; i < 8; i++) {
			if (rate[i] != 0) {
				count++;
			}
		}

		int max = 0;
		int min = 0;
		if (rate[8] != 0) {
			max = count + rate[8];
			min = (count == 0) ? 1 : count;
		} else {
			max = count;
			min = count;
		}

		System.out.println(min + " " + max);
	}
}


Measured memory_bytes: 21076
n,m=map(int, input().split())
shop=sorted([list(map(int, input().split())) for _ in range(n)], key=lambda x: x[0])

ans = 0
for (val,amo) in shop:
	if amo > m:
		ans += m * val
		break
	else:
		m -= amo
		ans += amo * val

print(ans)


Measured memory_bytes: 29788
import std.stdio, std.range;
void main() {
	string s;
	int n, l;
	for(;;) {
		"%s\n".readf(&s);
		if (s == "-") break;
		"%d\n".readf(&n);
		foreach (i; 0..n) {
			"%d\n".readf(&l);
			s = s.drop(l) ~ s.dropBack(s.length - l);
		}
		s.writeln;
	}
}

Measured memory_bytes: 2488
#include <iostream>

using namespace std;

int table[501][501];
int C[501][501];

int main() {
  int N, M, Q;
  cin >> N >> M >> Q;
  for (int i = 0; i < M; i++) {
    int l, r;
    cin >> l >> r;
    table[l][r]++;
  }
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= N; j++) {
      C[i][j] = C[i][j - 1] + table[i][j];
    }
  }
  for (int i = 0; i < Q; i++) {
    int p, q;
    cin >> p >> q;
    int ans = 0;
    for (int j = p; j <= q; j++) {
      ans += C[j][q] - C[j][p - 1];
    }
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 5580
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cassert>
#define ll long long
using namespace std;
inline int read(){
	int re=0,flag=1;char ch=getchar();
	while(!isdigit(ch)){
		if(ch=='-') flag=-1;
		ch=getchar();
	}
	while(isdigit(ch)) re=(re<<1)+(re<<3)+ch-'0',ch=getchar();
	return re*flag;
}
int n,ch[100010];ll a[100010];
ll dp0,dp1,dp2;
int main(){
	n=read();int i;char c;
	for(i=1;i<=n;i++){
		a[i]=read();
		if(i==n) break;
		c=getchar();
		while(c!='+'&&c!='-') c=getchar();
		ch[i+1]=(c=='-');
//		cout<<"finish readin "<<i<<' '<<a[i]<<' '<<ch[i+1]<<'\n';
	}
	dp0=0;dp1=dp2=-1e15;
	for(i=1;i<=n;i++){
		if(ch[i]){
			dp0-=a[i];
			dp1+=a[i];
			dp2-=a[i];
			dp2=max(dp2,dp1);
			dp1=max(dp1,dp0);
		}
		else{
			dp0+=a[i];
			dp1-=a[i];
			dp2+=a[i];
		}
		dp1=max(dp2,dp1);
		dp0=max(dp1,dp0);
	}
	cout<<dp0<<'\n';
}

Measured memory_bytes: 1536
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <climits>
#include <set>
#include <map>
#include <iomanip>
#include <cassert>
#include <functional>
#include <cstring>

using namespace std;

#define mp make_pair
#define FOR(i, a, b) for(int (i)=a;(i)<(b);++(i))
#define rep(i, n)  FOR(i,0,n)
#define FFOR(i, a, b) for(int (i)=a;(i)>(b);--(i))
#define rrep(i,n) FFOR(i,0,n)
#define vsort(v) sort((v).begin(), (v).end());					//小さい順
#define rvsort(v) sort(v.begin(), v.end(),greater<>());		//大きい順
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define all(c) (c).begin(),(c).end()
#define ll long long
#define lb long double
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define Print(p) cout<<(p)<<endl
#define F first
#define S second
#define pb push_back
#define mod 1000000007LL
#define INF 1234567890123456
typedef pair<int, int> P;
typedef pair<int, P> PP;

const int maxn =1e5 + 10;

//initialization here
//
char field[105][105];
//
//initialization finish


// your function is here
//

//
// your function finished

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	// your code is here
	//
	int a,b; cin >> a >> b;
	a--,b--;
	rep(i,21)rep(j,100) field[i][j] = '#';
	rep(i,21)rep(j,100) field[i+21][j] = '.';

	// うえはんぶんにしろプロット
	
	rep(i,20)
	{
		int nowh=0,noww=0;
		while(a)
		{
			a--;
			field[nowh][noww] = '.';
			noww+=2;
			if(noww >=100)
			{
				// 100 ->1 101 -> 0
				noww = 1-noww%2;
				nowh +=2;
			}
		}
	}

	// したからくろプロット
	rep(i,20)
	{
		int nowh=41,noww=0;
		while(b)
		{
			b--;
			field[nowh][noww] = '#';
			noww+=2;
			if(noww >=100)
			{
				// 100 ->1 101 -> 0
				noww = 1-noww%2;
				nowh -=2;
			}
		}
	}
	cout << 42 <<" "<< 100<<endl;
	rep(i,42)
	{
		rep(j,100) cout << field[i][j];
		cout << endl;
	}


	//
	// your code finished


	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cmath>
#define NMax 200000
#define ll long long
using namespace std;

ll sum[NMax+1];
int v[NMax+1];

int main(){

    int i,N;
    ll res;

    scanf("%d",&N);
    for(i = 1; i <= N; ++i) scanf("%d",&v[i]);
    for(i = 1; i <= N; ++i) sum[i] = sum[i-1] + v[i];

    res = abs(sum[1] - (sum[N] - sum[1]));
    for(i = 2; i < N; ++i) res = min(res, abs(sum[i] - (sum[N] - sum[i])));

    printf("%lld\n",res);


return 0;
}


Measured memory_bytes: 2560
#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <iterator>
#include <set>
#include <cmath>
#include <queue>
#include <vector>
#include <algorithm>
using namespace std;

typedef long long LL;
const int maxn = 2020;
const LL INF = 100000000000000LL;
const LL mod = 1e9 + 9;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define For(i,a,b) for(int i=a;i<=b;++i)


void solve() {
	int a, b;
	cin >> a >> b;
	cout << max(a + b, max(a - b, a * b)) << endl;
}

int main() {
	int t = 1;
	while(t--) {
		solve();
	}
	int mark_EOF;
	if(scanf("%d", &mark_EOF) == EOF) return 0;
    return 0;
}


Measured memory_bytes: 256
#include <cassert>
#include <algorithm>
#include <array>
#include <bitset>
#include <cctype>
#include <cstdint>
#include <cmath>
#include <complex>
#include <chrono>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
#include <memory>
#include <utility>
#include <limits>
#include "limits.h"
 
#define rep(i, a, b) for (long long (i) = (a); (i) < (b); (i)++)
#define all(i) i.begin(), i.end()
#define debug(...) std::cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

void debug_out(){std::cerr<<std::endl;}

template<typename Head,typename... Tail>
void debug_out(Head h,Tail... t){
  std::cerr<<" "<<h;
  debug_out(t...);
}
 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (int i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}
 
long long pow_mod(long long a, long long b, long long mod=-1) {
  if(b==0)return 1;
  if ((a == 0)||(mod!=-1&&(a+mod)%mod==0)) {
    return 0;
  }
  long long x = 1;
  while (b > 0) {
    if (b & 1) {
      x = (mod!=-1)?(x * a) % mod:x*a;
    }
    a = (mod!=-1)?(a * a) % mod:a*a;
    b >>= 1;
  }
  return x;
}

// const long long MOD = 998244353;
const long long MOD = 1e9 + 7;

using ll = long long;
using P=std::pair<long long,long long>;

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

  ll n;
  std::cin>>n;

  rep(i,0,n){
    ll a;
    std::cin>>a;

    if(a%2==0){
      if(a%3!=0&&a%5!=0){
        std::cout<<"DENIED\n";
        return 0;
      }
    }
  }

  std::cout<<"APPROVED\n";

  return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

int main() {
  int n, a, b; cin >> n >> a >> b;
  vector<int> ans(n);
  iota(ALL(ans), 0);
  REP(i, b) ans[i] = b - 1 - i;
  int inc = n - b + 1;
  if (b > 1) {
    for (int i = n - 1; i >= b;) {
      if (inc <= a) break;
      int j = max({b, i - b + 1, i - (inc - a)});
      FOR(k, j, i + 1) ans[k] = i - (k - j);
      inc -= i - j;
      i = j - 1;
    }
  }
  if (inc != a) {
    cout << "-1\n";
  } else {
    REP(i, n) cout << ans[i] + 1 << " \n"[i + 1 == n];
  }
  return 0;
}


Measured memory_bytes: 4460
#include<bits/stdc++.h>
using namespace std;
#define h first
#define w second
vector<pair<bool,pair<int,int> > >v;
int n,m,p,q,r,i;
void Vp(bool a,int b,int c){v.push_back(make_pair(a,make_pair(b,c)));}
int main(){
	while(cin>>n&&n){
	cin>>m>>p>>q>>r;v.clear();
	Vp(1,1,r);Vp(0,r+1,n);
	while(m--){
		int x,y;scanf("%d%d",&x,&y);
		for(i=0;i<v.size();i++){
			int a=v[i].w.h,b=v[i].w.w;bool c=v[i].h;
			if(a<=x&&x<b){Vp(c,x+1,b);b=x;}
			if(a<=y&&y<b){Vp(c,y+1,b);b=y;}
			if(0<a&&b<=x)a+=n-x,b+=n-x;
			else if(x<a&&b<=y)a+=n-x-y,b+=n-x-y;
			else if(y<a&&b<=n)a-=y,b-=y;
			v[i].w.h=a,v[i].w.w=b;
		}
	}n=0;
	for(i=0;i<v.size();i++)if(v[i].h)n+=max(0,1+min(v[i].w.w,q)-max(v[i].w.h,p));
	cout<<n<<endl;
	}
	return 0;
}

Measured memory_bytes: 3300
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.StringTokenizer;

public class Main{
	
	public static long left_to_right(char[] inputs, int start, int end){
		int ops_pos = end - 1;
		while(ops_pos >= start && ('0' <= inputs[ops_pos] && inputs[ops_pos] <= '9')){
			ops_pos--;
		}
		
		long fst_number = 0;
		for(int pos = end - 1, keta = 1; pos > ops_pos; pos--, keta *= 10){
			fst_number += keta * (inputs[pos] - '0');
		}
		
		//System.out.println(start + " " + ops_pos + " " + end + " " + (ops_pos < start ? "" : inputs[ops_pos]) + " " + fst_number);
		
		if(ops_pos < start){
			return fst_number;
		}else if(inputs[ops_pos] == '+'){
			return fst_number + left_to_right(inputs, start, ops_pos);
		}else{
			return fst_number * left_to_right(inputs, start, ops_pos);
		}
	}
	
	public static long multi(String input){
		String[] inputs = input.split("\\+");
		
		long ret = 0;
		for(String in : inputs){
			String[] multi = in.split("\\*");
			long ret_m = 1;
			for(String mul : multi){
				ret_m *= Long.parseLong(mul);
			}
			
			ret += ret_m;
		}
		
		return ret;
	}
	
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		
		String input = sc.next();
		final long answer = sc.nextInt();
		
		final long left  = left_to_right(input.toCharArray(), 0, input.length());
		final long multi = multi(input);
		
		//System.out.println(left + " " + multi);
		
		if(left == answer && multi == answer){
			System.out.println("U");
		}else if(left == answer){
			System.out.println("L");
		}else if(multi == answer){
			System.out.println("M");
		}else{
			System.out.println("I");
		}
		
		sc.close();
	}

	public static class Scanner {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while (!hasNext()) {
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
		
		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		// 他のnextXXXもXXX.parseXXX()メソッドを使って作れるので省略

		public void close() throws IOException {
			br.close();
		}
	}
}

Measured memory_bytes: 17104
def solve(string):
    import heapq
    x, y, z, k, *abc = map(int, string.split())
    a, b, c = map(lambda x: sorted(x, reverse=True), [abc[:x], abc[x:x + y], abc[x + y:]])
    hq = []
    heapq.heappush(hq, (-(a[0] + b[0] + c[0]), 0, 0, 0))
    ans = []
    check = set([(0, 0, 0)])
    for _ in range(k):
        m, i, j, k = heapq.heappop(hq)
        ans.append(str(-m))
        if i + 1 < x and (i + 1, j, k) not in check:
            heapq.heappush(hq, (-(a[i + 1] + b[j] + c[k]), i + 1, j, k))
            check.add((i + 1, j, k))
        if j + 1 < y and (i, j + 1, k) not in check:
            heapq.heappush(hq, (-(a[i] + b[j + 1] + c[k]), i, j + 1, k))
            check.add((i, j + 1, k))
        if k + 1 < z and (i, j, k + 1) not in check:
            heapq.heappush(hq, (-(a[i] + b[j] + c[k + 1]), i, j, k + 1))
            check.add((i, j, k + 1))
    return "\n".join(ans)


if __name__ == '__main__':
    print(solve('\n'.join([input() for _ in range(4)])))


Measured memory_bytes: 51548
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <iostream>
#include <vector>
#include <list>
#include <map>
#include<string>
#include <algorithm>
#include <functional>
#include <cmath>
using namespace std;
typedef vector <int> ivector;


int main(){
	int a, b;
	while (scanf("%d %d", &a, &b) != EOF){
		int dat=log10(a + b);
		cout << dat+1 << endl;
	}
	

	return 0;
}

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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
typedef double DOUBLE;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

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

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const ll LL_INF = 1e17 + 10;
const int INF = 1e9 + 10;
const ll MOD = 1e9 + 7;

const int MAXN = 1 << 10;

int g[MAXN][MAXN];

void rec_build(int t, int l, int r) {
	if (t == 1) {
		g[l][r] = 1;
		return;
	}
	int t1 = t / 2;
	rec_build(t1, l, r);
	rec_build(t1, l + t1 + 1, r);
	rec_build(t1, l, r + t1 + 1);
	rec_build(t1, l + t1 + 1, r + t1 + 1);
	g[l + t1][r + t1] = 1;
}

void solve(){
	int n, m;
	scanf("%d%d", &n, &m);
	n = (1 << n) - 1, m = (1 << m) - 1;
	int t = min(n, m);
	rec_build(t, 0, 0);
	
	if (t < n) {
		for(int i = t + 1; i < n; i += t + 1) {
			rec_build(t, i, 0);
		}
	}
	
	if (t < m) {
		for(int i = t + 1; i < m; i += t + 1) {
			rec_build(t, 0, i);
		}
	}
	
	int LIMI = n, LIMJ = m;
	/*int mx = -1;

	//g[3][3] = 0;
	int cur = 0;
	REP(i1, 0, LIMI) {
		REP(i2, i1, LIMI) {
			REP(j1, 0, LIMJ) {
				REP(j2, j1, LIMJ) {
					int cnt = 0;
					REPN(i, i1, i2) {
						REPN(j, j1, j2) {
							cnt += g[i][j];
						}
					}
					if (cnt & 1) {
						cur++;
					}
				}
			}
		}
	}

	printf("%d\n", cur);*/
	
	REP(i, 0, LIMI) {
		REP(j, 0, LIMJ) {
			printf("%d", g[i][j]);
		}
		putchar('\n');
	}
}

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


Measured memory_bytes: 5376
/*
 * atcoder/abc124/d.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> ostream & operator << (ostream & out, vector<T> const & v) {
  for (auto &&a: v) out << a << " "; out << endl; return out;
}
template <class T> void dump(T &a) { cout << a << endl; }
template <class T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }

int N, K;
string S;
vector<ll> M, acc;
void solve() {
  cin >> N >> K >> S;
  if (S[0] == '0') M.push_back(0);
  int i = 0;
  while (i < N) {
    int j=i;
    while (j < N and S[i] == S[j]) j++;
    M.push_back(j-i);
    i=j;
  }
  if (S[N-1] == '0') M.push_back(0);
  acc.resize(M.size()+1);
  acc[0] = 0;
  loop(m,0,M.size()) acc[m+1] = acc[m] + M[m];
  // dump(M);
  // dump(acc);

  ll max_ = 0;
  K = 2 * K + 1;
  for (int l=0; l<acc.size(); l+=2) {
    int r = min(l+K, (int)(acc.size()-1));
    if (chmax(max_, acc[r] - acc[l])) {
      // cout << "l = " << l << " r = " << (l+K) << endl;
    }
  }
  cout << max_ << endl;
}
int main() {
  // cout.precision(15); cout << fixed;

  solve();

  return 0;
}


Measured memory_bytes: 2164
#include <bits/stdc++.h>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> void pr_vec(vector<T> &v, char ep=' '){int n=v.size();REP(ni,n){cout<<v[ni];if(ni!=n-1)cout<<ep;}cout<<endl;};
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int main(void)
{
    ll a;
    cin >> a;
    pr(a+a*a+a*a*a);
}

Measured memory_bytes: 3568
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here! 
        Scanner sc = new Scanner(System.in);
        int r = sc.nextInt();
        int c = sc.nextInt();
        int n = sc.nextInt();
        
        int[][] array = new int[r+1][c+1];
        for (int i = 0; i < n; i++) {
            int row = sc.nextInt() - 1;
            int col = sc.nextInt() - 1;
            int val = sc.nextInt();
            array[row][col] = val;
        }
        // for (int[] a : array) {
        //     System.out.println(Arrays.toString(a));
        // }
        
        long[][][] dp = new long[r+1][c+1][4];
        for (int i = 0; i <= r; i++) {
            for (int j = 0; j <= c; j++) {
                for (int k = 0; k < 4; k++) {
                    // 取って右に行く
                    if (j+1 <= c && k != 3) {
                        dp[i][j+1][k+1] = Math.max(dp[i][j+1][k+1], dp[i][j][k] + array[i][j]);
                    }
                    // 取らずに右に行く
                    if (j+1 <= c) {
                        dp[i][j+1][k] = Math.max(dp[i][j+1][k], dp[i][j][k]);
                    }
                    // 取って下に行く
                    if (i+1 <= r && k != 3) {
                        dp[i+1][j][0] = Math.max(dp[i+1][j][0], dp[i][j][k] + array[i][j]);
                    }
                    // 取らずに下に行く
                    if (i+1 <= r) {
                        dp[i+1][j][0] = Math.max(dp[i+1][j][0], dp[i][j][k]);
                    }
                }
            }
        }
        // for (long[][] a : dp) {
        //     for (long[] b : a) {
        //         System.out.println(Arrays.toString(b));
        //     }
        // }
        // System.out.println(dp[1][5][3]);
        
        long ans = 0;
        for (int i = 0; i < 4; i++) {
            // System.out.println(dp[r][c][i]);
            ans = Math.max(ans, dp[r][c][i]);
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 703244
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <string>
#include <stack>
#include <bitset>
#define INF 0x3f3f3f3f
#define eps 1e-8
#define FI first
#define SE second
using namespace std;
typedef long long LL;
int col[20], row[20];
bool use[20];

int main() {
    int n, m;
    while(scanf("%d%d", &n, &m)) {
        if(n + m == 0) break;
        for(int i = 0; i < n; ++i) scanf("%d", col + i);
        for(int i = 0; i < m; ++i) scanf("%d", row + i);
        int ans = 0;
        for(int i = 0; i < n; ++i) ans += col[i];
        memset(use, 0, sizeof(use));
        for(int i = 0; i < m; ++i) {
            bool Find = 0;
            for(int j = 0; j < n; ++j) {
                if(use[j]) continue;
                if(col[j] == row[i]) {
                    use[j] = Find = 1;
                    break;
                }
            }
            if(!Find) ans += row[i];
        }
        printf("%d\n", ans);
    }
    return 0;
}

Measured memory_bytes: 1188
fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.read();
    let a: Vec<usize> = (0..n).map(|_| sc.read()).collect();
    let mut b: Vec<usize> = (0..n).map(|_| sc.read()).collect();

    let mut ans = 0;
    for k in (0..30).rev() {
        ans *= 2;
        let t = 1 << k;
        let t2 = t * 2;
        let t2m = t2 - 1;
        b.sort_by_key(|&bi| bi & t2m);

        let mut ans_i = 0;
        for &a in &a {
            let a = a & t2m;
            let s1 = b.binary_search_by_key(&(1 * t * 2 - 1), |&b| ((b & t2m) + a) * 2);
            let s2 = b.binary_search_by_key(&(2 * t * 2 - 1), |&b| ((b & t2m) + a) * 2);
            let s3 = b.binary_search_by_key(&(3 * t * 2 - 1), |&b| ((b & t2m) + a) * 2);
            let s1 = s1.err().unwrap();
            let s2 = s2.err().unwrap();
            let s3 = s3.err().unwrap();

            let q = n - s3 + s2 - s1;
            ans_i = ans_i ^ (q % 2);
        }
        ans += ans_i;
    }

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

struct Scanner {
    ptr: usize,
    length: usize,
    buf: Vec<u8>,
    small_cache: Vec<u8>,
}

impl Scanner {
    fn new() -> Scanner {
        Scanner {
            ptr: 0,
            length: 0,
            buf: vec![0; 1024],
            small_cache: vec![0; 1024],
        }
    }

    fn load(&mut self) {
        use std::io::Read;
        let mut s = std::io::stdin();
        self.length = s.read(&mut self.buf).unwrap();
    }

    fn byte(&mut self) -> u8 {
        if self.ptr >= self.length {
            self.ptr = 0;
            self.load();
            if self.length == 0 {
                self.buf[0] = b'\n';
                self.length = 1;
            }
        }

        self.ptr += 1;
        return self.buf[self.ptr - 1];
    }

    fn is_space(b: u8) -> bool {
        b == b'\n' || b == b'\r' || b == b'\t' || b == b' '
    }

    fn read<T>(&mut self) -> T
        where
            T: std::str::FromStr,
            T::Err: std::fmt::Debug,
    {
        let mut b = self.byte();
        while Scanner::is_space(b) {
            b = self.byte();
        }

        for pos in 0..self.small_cache.len() {
            self.small_cache[pos] = b;
            b = self.byte();
            if Scanner::is_space(b) {
                return String::from_utf8_lossy(&self.small_cache[0..(pos + 1)])
                    .parse()
                    .unwrap();
            }
        }

        let mut v = self.small_cache.clone();
        while !Scanner::is_space(b) {
            v.push(b);
            b = self.byte();
        }
        return String::from_utf8_lossy(&v).parse().unwrap();
    }
}


Measured memory_bytes: 10492
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] a = new int[n];
    
    for(int i=0;i<n;i++){
      a[i] = sc.nextInt();
    }
    
    for(int i=0;i<n;i++){
      if(a[i]%2==0){
        if(a[i]%3!=0 && a[i]%5!=0){
          System.out.println("DENIED");
          return;
        }
      }
    }
    System.out.println("APPROVED");
  }
}

Measured memory_bytes: 23892
e_list = ['A', 'C', 'G', 'T']
b = str(input())
if b == e_list[0]:
    print(e_list[3])
elif b == e_list[1]:
    print(e_list[2])
elif b == e_list[2]:
    print(e_list[1])
elif b == e_list[3]:
    print(e_list[0])

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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;

template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	os << v[0];
	for (int i = 1; i < v.size(); i++) os << " " << v[i];
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u; return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}

bool match(char x, char y) {
	return (x == '?' || y == '?' || x == y);
}


void Main() {
	string A, B, C; cin >> A >> B >> C;
	int off = 50000;
	vector<bool> ab(100000, true);
	vector<bool> ac(100000, true);
	vector<bool> bc(100000, true);

	for (int i = 0; i < A.size(); i++) {
		for (int j = 0; j < B.size(); j++) {
			if (!match(A[i], B[j])) ab[i-j+off] = false;
		}
	}
	for (int i = 0; i < A.size(); i++) {
		for (int j = 0; j < C.size(); j++) {
			if (!match(A[i], C[j])) ac[i-j+off] = false;
		}
	}
	for (int i = 0; i < B.size(); i++) {
		for (int j = 0; j < C.size(); j++) {
			if (!match(B[i], C[j])) bc[i-j+off] = false;
		}
	}
	
	int ans = 6000;
	for (int i = -4000; i <= 4000; i++) {
		for (int j = -4000; j <= 4000; j++) {
			if (ab[i+off] && ac[j+off] && bc[j-i+off]) {
				int L = min({0, i, j});
				int R = max({(int)A.size(), i + (int)B.size(), j + (int)C.size()});
				chmin(ans, R - L);
			}
		}
	}
	cout << ans << endl;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(20);
	Main();
	return (0);
}


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

using namespace std;

#define int long long

int D;
vector<int> v(6);
unordered_map<int,int> m;

int solve(int N) {
    if (N < 0) return 1e12;
    if (N == 0) return 0;
    if (N == 1) return D;
    if (m.count(N) > 0) return m[N];
    if ((int)(1e12)/N < D) m[N] = 1e12;
    else m[N] = N*D;
    int u = N;
    for (auto r: {2,3,5}) {
        if (u%r == 0) m[N] = min(m[N], solve(u/r) + v[r]);
        else {
            m[N] = min(m[N], solve((u-(u%r))/ r) + (u%r)*D + v[r]);
            m[N] = min(m[N], solve((u + r -(u%r))/ r) + (r - u%r)*D + v[r]);
        }
    }
    return m[N];
}

main() {

    int T; 
    cin >> T;

    while (T--) {
        int N;
        m.clear();
        cin >> N >> v[2] >> v[3] >> v[5] >> D;
        cout << solve(N) << "\n";

        //queue<int> q;
        
        // q.push(make_pair(0,N));

        // while (!q.empty()) {
        //     int d,u;
        //     tie(d,u) = q.top(); 
        //     q.pop();        

        //     if (u == 1) {
        //         cout << d+D << "\n";
        //         break;
        //     }


        
        // }

    }

    return 0;
}

Measured memory_bytes: 4076
from sys import stdin 
hi = 10**5 + 105 
mod = 10**9 + 7 
fa = [1] * hi 
for i in xrange(1,hi):
    fa[i] = (i * fa[i-1])%mod 
def ncr(n,r):
    num = fa[n]
    den = (fa[r] * fa[n-r])%mod 
    den = pow(den, mod-2, mod)
    return (num * den)%mod 

n,m = map(int,stdin.readline().split())
di = {} 
x = 2 
ans = 1 
while True:
    if x * x > m:
        break 
    if m%x==0:
        cnt = 0 
        while m%x==0:
            m/=x 
            cnt+= 1 
        ans = (ans * ncr(n-1+cnt,cnt))%mod 
    x+=1 
if m!=1:
    ans = (ans * n)%mod 
print ans

Measured memory_bytes: 5764