akhauriyash/Code-Regression huggingface dataset:
T = int(input())
for i in range(T):
    n, A, B, C, D = map(int, input().split())
    memo = {}
 
    def herasu(N):
        if N == 0:
            return 0
        if N == 1:
            return D
        if N in memo:
            return memo[N]
        m = 100000000000000000000000
        if N % 2 == 0:
            m = min([m, A + herasu(N//2)])
        else:
            m = min([m, A + herasu(N//2) + D])
            m = min([m, A + herasu(N//2 + 1) + D])
        if N % 3 == 0:
            m = min(m, B + herasu(N//3))
        else:
            m = min([m, B + herasu(N//3) + (N%3) * D])
            m = min([m, B + herasu(N//3 + 1) + (3-(N%3)) * D])
        if N % 5 == 0:
            m = min(m, C + herasu(N // 5))
        else:
            m = min([m, C + herasu(N//5) + (N%5) * D])
            m = min([m, C + herasu(N//5 + 1) + (5-(N%5)) * D])
        m = min([m, D * N])
        memo[N] = m
        return m
 
    print(herasu(n))

Measured memory_bytes: 11012
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

const int N = 1005 * 3;

int n;

char map[3][N];

pair<int, bool> getVar(char ch) {
	if (ch >= 'A' && ch <= 'Z') {
		return make_pair(ch - 'A', false);
	} else {
		return make_pair(ch - 'a', true);
	}
}

struct SAT3 {
	pair<int, bool> v[3];
	
	SAT3(char a, char b, char c) {
		v[0] = getVar(a), v[1] = getVar(b), v[2] = getVar(c);
		sort(v, v + 3);
	}

	bool operator < (const SAT3 &b) const {
		for (int i = 0; i < 3; ++i) {
			if (v[i] != b.v[i]) {
				return v[i] < b.v[i];
			}
		}
		return false;
	}

	bool operator == (const SAT3 &b) const {
		for (int i = 0; i < 3; ++i) {
			if (v[i] != b.v[i]) {
				return false;
			}
		}
		return true;
	}
};

const int C = 26;

int val[C];

vector<SAT3> cl;

bool go(int d) {
	if (d == cl.size()) {
		vector<char> ans;
		for (int i = 0; i < C; ++i) {
			if (val[i] == 1) {
				ans.push_back('A' + i);
			}
		}
		printf("%d", (int)ans.size());
		for (int i = 0; i < (int)ans.size(); ++i) {
			printf(" %c", ans[i]);
		}
		printf("\n");
		return true;
	}
	SAT3 &cur = cl[d];
	bool good = false;
	int bad = 0;
	for (int i = 0; i < 3 && !good; ++i) {
		int v = cur.v[i].first;
		if (val[v] == -1) {
			continue;
		}
		if (val[v] == cur.v[i].second) {
			good = true;
		} else {
			++bad;
		}
	}
	if (good) {
		return go(d + 1);
	}
	if (bad == 3) {
		return false;
	}
	bool vis[3] = {0, 0, 0};
	for (int i = 0; i < 3; ++i) {
		int v = cur.v[i].first, c = cur.v[i].second;
		if (val[v] != -1) {
			continue;
		}
		vis[i] = true;
		val[v] = c;
		if (go(d + 1)) {
			return true;
		}
		val[v] = !c;
	}
	for (int i = 0; i < 3; ++i) {
		if (vis[i]) {
			val[cur.v[i].first] = -1;
		}
	}
	return false;
}

int main() {
	while (scanf("%d", &n) == 1 && n) {
		for (int i = 0; i < 3; ++i) {
			scanf("%s", map[i]);
		}
		cl.clear();
		for (int i = 0; i < n; ++i) {
			int d = i * 3 + 1;
			for (int a = 0; a < 2; ++a) {
				for (int b = 0; b < 2; ++b) {
					for (int c = 0; c < 2; ++c) {
						cl.push_back(SAT3(map[0][d + a], map[1][d + b], map[2][d + c]));
					}
				}
			}
		}
		sort(cl.begin(), cl.end());
		cl.erase(unique(cl.begin(), cl.end()), cl.end());
		vector<SAT3> clt;
		for (int i = 0; i < (int)cl.size(); ++i) {
			bool flag = false;
			for (int j = 0; j < 2; ++j) {
				if (cl[i].v[j].first == cl[i].v[j + 1].first && cl[i].v[j].second != cl[i].v[j + 1].second) {
					flag = true;
					break;
				}
			}
			if (!flag) {
				clt.push_back(cl[i]);
			}
		}
		cl = clt;
		memset(val, -1, sizeof(val));
		if (!go(0)) {
			printf("-1\n");
		}
	}
	return 0;
}

Measured memory_bytes: 2276
#include <iostream>
using namespace std;
int main()
{
  int N,s;
  cin>>N;
  s=0;
  for(int i=0;i<N;i++)
  {
    int l,r;
    cin>>l>>r;
    s+=r-l+1;
  }
  cout<<s<<endl;
  return 0;
}

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

void solve() {
    bool vis[105] = {};

    int x, n;
    scanf("%d%d", &x, &n);

    for (int i = 1, x; i <= n; i++) scanf("%d", &x), vis[x] = 1;

    for (int i = 0; ; i++) {
        if (x>=i && !vis[x-i]) {
            printf("%d\n", x-i);
            return ;
        }
        if (!vis[x+i]) {
            printf("%d\n", x+i);
            return ;
        }
    }

}

int main(){

    solve();
	return 0;
}


Measured memory_bytes: 3716
# Author: cr4zjh0bp
# Created: Sat Mar 28 11:53:27 UTC 2020
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

x = ni()
ans = 0

while x:
    if x // 500 == 0:
        ans += x // 5 * 5
        break
    else:
        ans += x // 500 * 1000
        x %= 500

print(ans)

Measured memory_bytes: 3064
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll N;
  cin >> N;
  vector<ll> A(N), B(N);
  vector<ll> C(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i] >> B[i];
  }
  ll ans = 0;
  ll accum = 0;
  for (int i = N - 1; i >= 0; i--) {
    if ((A[i] + accum) % B[i] != 0) {
      ll new_cnt = (B[i] - (A[i] + accum) % B[i]);
      ans += new_cnt;
      accum += new_cnt;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 2560
n = int(input())
a = list(map(int,input().split()))
q = int(input())

bu = [0] * (10**5+10)

for i in range(n):
    bu[a[i]] += 1
s = 0
for i in range(10**5+10):
    s += bu[i]*i

for i in range(q):
    b,c = map(int,input().split())
    if bu[b] == 0:
        pass
    else:
        bu[c] += bu[b]
        s += (c-b)*bu[b]
        bu[b] = 0
    print(s)

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

#define rep(i, N) for (int i = 0; i < (N); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back

using ll = long long;
using i_i = tuple<int, int>;

int main() {
    int N, Q;
    cin >> N >> Q;
    vector<ll> a(N);
    rep(i, N) scanf("%lld", &a[i]);
    rep(i, N) a[i] *= 4;
    vector<ll> sum(N + 1);
    rep(i, N) sum[i + 1] = sum[i] + a[i];
    vector<ll> unko(N + 1);
    unko[1] = a[0];
    for (int i = 2; i <= N; i++)
        unko[i] = unko[i - 2] + a[i - 1];
    while (Q--) {
        ll x; scanf("%lld", &x);
        x = x * 4 - 1;
        ll lb = 0, ub = 10LL * INT_MAX;
        int l0 = N, r0 = N;
        while (ub - lb > 1) {
            ll mid = (lb + ub) / 2;
            ll xl = x - mid, xr = x + mid;
            int l = lower_bound(all(a), xl) - a.begin();
            int r = upper_bound(all(a), xr) - a.begin();
            int d = r - l;
            if (r <= N - d) {
                lb = mid;
                l0 = l;
                r0 = r;
            }
            else ub = mid;
        }
        ll ans = sum[N] - sum[r0];
        if ((N - l0) % 2) l0--;
        if (l0 >= 0) ans += unko[l0];
        printf("%lld\n", ans / 4);
    }
}


Measured memory_bytes: 4096
#include <iostream>
#include <cstring>
#include <queue>
#include <algorithm>
#include <string>
#include <cstdio>

using namespace std;

int f[1001][1001];
bool checked[1001][1001];
int gx,gy,n;
int dx[4] = {1,0,-1,0};
int dy[4] = {0,-1,0,1};
int w,h;
bool solve(int hour){
    memset(checked, false,sizeof(checked));
    deque<pair<int,int> > q;
    pair<int,int> tmp;
    int nx,ny;
    q.push_back(make_pair(0,0));
    checked[0][0] = true;
    while(!q.empty()){
        tmp = q.front();
        q.pop_front();
        if(tmp.first == gx && tmp.second == gy){
            return true;
        }

        for(int i=0;i<4;i++){
            nx = tmp.first + dx[i];
            ny = tmp.second + dy[i];
            if(0 <= nx && nx < w &&
               0 <= ny && ny < h &&
               f[ny][nx] != -1 &&
               f[ny][nx] <= hour &&
               !checked[ny][nx]){
                q.push_back(make_pair(nx,ny));
                checked[ny][nx] = true;
            }
        }
    }
    return false;
}

int main(){
    int x,y;
    char c;

    cin >> w >> h;

    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin >> c;
            if(c == '.'){
                f[i][j] = 0;
            }else if(c == '#'){
                f[i][j] = -1;
            }else if(c == 't'){
                gx = j;
                gy = i;
                f[i][j] = 0;
            }
        }
    }
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> x >> y;
        f[y][x] = i+1;
    }

    int lb = 0, ub = 2000,mid;
    if(solve(0)) ub = 0;
    while(ub - lb > 1){
        mid = (lb+ub)/2;
        if(solve(mid)){
            ub = mid;
        }else{
            lb = mid;
        }
    }

    if(ub > n){
        cout << -1 << endl;
    }else{
        cout << ub << endl;
    }
}

Measured memory_bytes: 5776
n,k = map(int, input().split())

ans = 0
for i in range(k,n+2):
    if n != 1:
        if i > 2:
            ans += n*(n+1)//2 - (n-i)*(n-i+1)//2 - (i-1)*i//2 + 1
        elif i == 2:
            ans += 2 * n - 1
        elif i == 1:
            ans += n+1
    else:
        if i == 2:
            ans += 1
        elif i == 1:
            ans += 2

print(ans%(10**9+7))

Measured memory_bytes: 63620
import java.util.Scanner;
public class Main {
	static void output(int[][] card,int N){
		boolean judge=true;
		System.out.printf("%c%d",card[0][2],card[0][0]);
		for(int i=1;i<N;i++){
			System.out.printf(" %c%d",card[i][2],card[i][0]);
			if((card[i][0]==card[i-1][0])&&!(card[i-1][1]<card[i][1])){
				judge=false;
			}
		}
		System.out.println();
		if(judge) System.out.println("Stable");
		else System.out.println("Not stable");
	}
	static void BubbleSort(int[][] card,int N){
		int t;
		for(int i=0;i<N;i++){
			for(int j=N-1;i<j;j--){
				if(card[j][0]<card[j-1][0]){
					t=card[j][0];
					card[j][0]=card[j-1][0];
					card[j-1][0]=t;
					t=card[j][1];
					card[j][1]=card[j-1][1];
					card[j-1][1]=t;
					t=card[j][2];
					card[j][2]=card[j-1][2];
					card[j-1][2]=t;
				}
			}
		}
		output(card,N);
	}
	static void SelectionSort(int[][] card,int N){
		int min,t;
		for(int i=0;i<N;i++){
			min=i;
			for(int j=i;j<N;j++){
				if(card[j][0]<card[min][0]){
					min=j;
				}
			}
			t=card[i][0];
			card[i][0]=card[min][0];
			card[min][0]=t;
			t=card[i][1];
			card[i][1]=card[min][1];
			card[min][1]=t;
			t=card[i][2];
			card[i][2]=card[min][2];
			card[min][2]=t;
		}
		output(card,N);
	}
	static void cardcopy(int[][] card,int[][] copy,int N){
		for(int i=0;i<N;i++){
			copy[i][0]=card[i][0];
			copy[i][1]=card[i][1];
			copy[i][2]=card[i][2];
		}
	}
	public static void main(String[] args){
		Scanner scan=new Scanner(System.in);
		String s;
		int[] counter=new int[9];
		int N=scan.nextInt();
		int[][] card=new int[N][3];
		int[][] copy=new int[N][3];
		for(int i=0;i<N;i++){
			s=scan.next();
			card[i][0]=s.charAt(1)-'0';
			card[i][1]=counter[card[i][0]-1];
			card[i][2]=s.charAt(0);
			counter[card[i][0]-1]++;
		}
		cardcopy(card,copy,N);//一回目のコピーの作成
		BubbleSort(copy,N);
		cardcopy(card,copy,N);
		SelectionSort(copy,N);
		scan.close();
	}
}

Measured memory_bytes: 17420
#include <iostream>

int f(int a) {
	a = (a % 2) ? (3*a+1):(a / 2);
	return a;
}
int main()
{
	int N = 0;
	std::cin >> N;
	int v[25];
	int c[25];
	int X = 0;
	int Y = 0;
	for (int i = 0; i < N; i++) { std::cin >> v[i]; }
	for (int i = 0; i < N; i++) { std::cin >> c[i]; }
	for (int i = 0; i < N; i++) {
		if (v[i] > c[i]) {
			X += v[i]; Y += c[i];
		}
	}

	std::cout<<(X-Y);
    return 0;
}

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

#define LL long long



int main(){
	int n, m;
	scanf("%d %d\n", &n, &m);
	int sum=0,a[n];

	for(int i=n; i--; ){
		scanf(" %d", &a[i]);
		sum+=a[i];
	}
	
	double minl=sum/(4.0*m);
	sort(a, a+n);
	while(m--){
		if(a[n-1-m]<minl){
			printf("No");
			return 0;
		}
	}
	printf("Yes");

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int n;
  scanf("%d", &n);
  
  int i;
  int min=11;
  for(i=11; i>0; i--){
    if(1000*i>=n){
      min=i;
    }
  }
  
  printf("%d\n", min*1000-n);
  
  return 0;
}

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

#define ll long long int
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define all(A) A.begin(), A.end()
#define sz(A) (int)A.size()
typedef vector <int> vi;
typedef vector <ll> vl;
typedef pair <int, int> pii;
const ll mod = 1e9 + 7;
//const ll mod = 998244353;
const int inf = 1e9;
//const ll inf = 1e18;
const int N = 2e5;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, k, c;
	string s;
	cin >> n >> k >> c;
	cin >> s;
	if (n == 1) {
		cout << 1 << "\n";
		return 0;
	}
	int dp1[n], dp2[n];
	dp1[0] = (s[0] == 'x' ? 0 : 1);
	for (int i = 1; i < n; i++) {
		if (s[i] == 'o') {
			if (i > c) 
				dp1[i] = max(dp1[i - 1], 1 + dp1[i - c - 1]);
			else 
				dp1[i] = 1;
		}
		else
			dp1[i] = dp1[i - 1];
	}
	dp2[n - 1] = (s[n - 1] == 'x' ? 0 : 1);
	for (int i = n - 2; i >= 0; i--) {
		if (s[i] == 'o') {
			if (i < n - 1 - c) 
				dp2[i] = max(1 + dp2[i + c + 1], dp2[i + 1]);
			else 
				dp2[i] = 1;
		}
		else 
			dp2[i] = dp2[i + 1];
	}
	for (int i = 0; i < n; i++) {
		if (i == 0) {
			if (dp2[i + 1] < k) cout << i + 1 << "\n";
		}
		else if (i == n - 1) {
			if (dp1[i - 1] < k) cout << i + 1 << "\n";
		}
		else {
			if (dp1[i - 1] + dp2[i + 1] < k) {
				cout << i + 1 << "\n";
			}
		}
	}
 	return 0;
}

Measured memory_bytes: 3348
h,w=map(int,input().split())
first=h*w
if first%3==0:
    print(0)
    exit()

h,w=min(h,w),max(h,w)
ans=float('inf')
for i in range(1,w):
    s1=h*i
    neww=w-i
    newh,neww=min(h,neww),max(h,neww)
    if newh%2==0 or neww%2==0:
        s2=(newh*neww)//2
        s3=first-(s1+s2)
        s4=(newh*neww)//2
        s5=first-(s1+s2)
    else:
        s2=newh*(neww//2)
        s3=first-(s1+s2)
        s4=(newh//2)*neww
        s5=first-(s1+s4)
    #print(s1,s2,s3)
    ans=min(ans,max([s1,s2,s3])-min([s1,s2,s3]), max([s1,s4,s5])-min([s1,s4,s5]))

for i in range(1,h):
    s1=w*i
    newh=h-i
    newh,neww=min(newh,w),max(newh,w)
    if newh%2==0 or neww%2==0:
        s2=(newh*neww)//2
        s3=first-(s1+s2)
        s4=(newh*neww)//2
        s5=first-(s1+s2)
    else:
        s2=newh*(neww//2)
        s3=first-(s1+s2)
        s4=(newh//2)*neww
        s5=first-(s1+s4)
    #print(s1,s2,s3)
    ans=min(ans,max([s1,s2,s3])-min([s1,s2,s3]), max([s1,s4,s5])-min([s1,s4,s5]))

print(ans)

Measured memory_bytes: 46296
#include <bits/stdc++.h>
#define INF 5000000000000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

int main() {
  ll N;
  cin >> N;
  ll ans = 0;
  for (ll i = 1; i <= N; ++i) {
    ll largest = N / i * i;
    ans += (largest + i) * (N / i) / 2;
  }
  cout << ans << "\n";
}


Measured memory_bytes: 3592
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
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;}

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

ll n, k;
vll a;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> k;
  a.resize(n); REP(i, n) cin >> a[i];
  ll ans = 0;
  REP(i, n) {
    ll ls = 0;
    ll rs = 0;
    REP(j, n) {
      if (a[i] > a[j]) {
        ls++;
        if (i<j) rs++;
      }
    }
    ans = (ans + (rs*k)%MOD + ((k*(k-1)/2)%MOD)*ls%MOD) % MOD;
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;

namespace atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var k = int.Parse(Console.ReadLine());
            var result = 0L;

            for (var i = 1; i <= k; i++)
            {
                result += i;
                if (k > 1)
                {
                    for (var j = i + 1; j <= k; j++)
                    {
                        var ijGcd = GCD(i, j);
                        result += 6 * ijGcd;
                        if (k > 2)
                        {
                            for (var l = j + 1; l <= k; l++)
                            {
                                result += 6 * GCD(ijGcd, l);
                            }
                        }
                    }
                }
            }

            Console.WriteLine(result);

            int GCD(int x, int y)
            {
                if (x >= y)
                {
                    var rm = x % y;
                    if (rm == 0)
                    {
                        return y;
                    }
                    else
                    {
                        return GCD(y, rm);
                    }
                }
                else
                {
                    var rm = y % x;
                    if (rm == 0)
                    {
                        return x;
                    }
                    else
                    {
                        return GCD(x, rm);
                    }
                }
            }
        }
    }
}

Measured memory_bytes: 27484
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using db = double;
using ld = long double;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define all(v) (v).begin(),(v).end()
#define siz(v) (ll)(v).size()
#define rep(i,a,n) for(int i=a;i<(ll)(n);++i)
#define repr(i,a,n) for(ll i=n-1;(ll)a<=i;--i)
#define lb lower_bound
#define ub upper_bound
#define ENDL '\n'
typedef pair<int,int> Pi;
typedef pair<ll,ll> PL;
const ll mod = 1000000007;
const ll INF = 1000000099;
const ll LINF = (ll)(1e18 +99);
const vector<ll> dx={-1,1,0,0},dy={0,0,-1,1};
template<typename T,typename U> inline bool chmin(T& t, const U& u){if(t>u){t=u;return 1;}return 0;}
template<typename T,typename U> inline bool chmax(T& t, const U& u){if(t<u){t=u;return 1;}return 0;}
template<typename T> inline T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T,typename Y> inline T mpow(T a, Y n) {
  T res = 1;
  for(;n;n>>=1) {
    if (n & 1) res = res * a;
    a = a * a;
  }
  return res;
}



signed main(){
  cin.tie(0);ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);
  ll n,ans=LINF;cin>>n;
  V<int> a(n),b(n);
  rep(i,0,n)cin>>a[i];
  rep(i,0,n)cin>>b[i];

  rep(i,0,(1<<n)){
    V<Pi> od(0),ev(0),v(n);

    rep(j,0,n){
      if(i&(1<<j)){
        v[j]={b[j],j};
        if(j%2)ev.pb(v[j]);
        else od.pb(v[j]);
      }else{
        v[j]={a[j],j};
        if(j%2)od.pb(v[j]);
        else ev.pb(v[j]);
      }
    }

    if(siz(ev)-siz(od)!=0 && siz(ev)-siz(od)!=1)continue;

    sort(all(v));
    sort(all(ev));
    sort(all(od));
    bool ok=true;
    rep(j,0,n){
      if(j%2 && v[j].fs!=od[j/2].fs)ok=false;
      if(j%2==0 && v[j].fs!=ev[j/2].fs)ok=false;
      
      if(j%2)v[j]=od[j/2];
      else v[j]=ev[j/2];
    }

    ll cnt=0;
    rep(j,0,n-1){
      rep(k,0,n-1-j){
        if(v[k].sc>v[k+1].sc){
          swap(v[k],v[k+1]);
          ++cnt;
        }
      }
    }
    if(ok)chmin(ans,cnt);
  }


  if(ans==LINF)cout<<-1<<ENDL;
  else cout<<ans<<ENDL;
}
//( ・ __ ・ ) KEEP BEING ORGANIZED 
//CHECK overflow,vector_size,what to output?


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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;
using std::bitset;

#define rep(i,n)    for(int i=0; i<(int)(n); i++)
#define reps(i,s,e) for(int i=s; i<(int)(e); i++)
#define coutd(i) cout << std::fixed << std::setprecision(i)
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, ll> pll;

template<class T>
using Set = std::set<T>;
template<class T, class U>
using Map = std::map<T, U>;

template<class T>
using Graph = vector<vector<T>>;

const int INT_BIG = 1<<28;

int main() {
    int H, W, M;
    cin >> H >> W >> M;
    Set<pii> bombs;

    vector<pll> hdir(H, pll(0, 0));
    vector<pll> wdir(W, pll(0, 0));
    rep(h, H) {
        hdir[h].second = h;
    }
    rep(w, W) {
        wdir[w].second = w;
    }

    rep(i, M) {
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        bombs.insert(pii(x, y));
        hdir[x].first++;
        wdir[y].first++;
    }

    std::sort(hdir.begin(), hdir.end(), std::greater<pll>() );
    std::sort(wdir.begin(), wdir.end(), std::greater<pll>() );

    ll maxH = hdir[0].first;
    ll maxW = wdir[0].first;
    rep(h, H) {
        if (hdir[h].first < maxH) {
            break;
        }
        rep(w, W) {
            if (wdir[w].first < maxW) {
                break;
            }
            pii searchp((int)hdir[h].second, (int)wdir[w].second);

            if(bombs.find(searchp) == bombs.end()) {
                // cout << searchp.first << "x" << searchp.second << endl;
                cout << maxH + maxW << endl;
                return 0;
            }
        }
    }
    cout << maxH + maxW - 1 << endl;
}

Measured memory_bytes: 26740
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<N;i++)
#define INF 1e9
typedef long long LL;
const LL MOD = 1e9+7;

int main() {
  string S;
  cin >> S;
  LL N = S.size();
  
  vector<LL> result(N);
  
  LL odd = 0, even = 0;
  for (int i = 0; i < N; i++) {
    if(S[i] == 'R') {
      if (i % 2 == 1) odd++;
      else even++;
    } else {
      if (i % 2 == 1) {
        result[i] += odd; 
	    result[i-1] += even;
      } else {
        result[i] += even;
	    result[i-1] += odd;
      }
      odd = 0;
      even = 0;
    }
  }
  
  odd = 0;
  even = 0;
  for (int i = N-1; i >= 0; i--) {
    if(S[i] == 'L') {
      if (i % 2 == 1) odd++;
      else even++;
    } else {
      if (i % 2 == 1) {
        result[i] += odd; 
	    result[i+1] += even;
      } else {
        result[i] += even;
	    result[i+1] += odd;
      }
      odd = 0;
      even = 0;
    }
  }
  
  rep(i,N) cout << result[i] << ' ';
  
  return 0;
}


Measured memory_bytes: 1408
#include "bits/stdc++.h"

using namespace std;

#define sp(x) cout<<setprecision(x);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define all(a) (a).begin(), (a).end()
#define inf 10000000
#define linf INT64_MAX*0.99
#define print(s) cout<<(s)<<endl
#define lint long long
#define yes "Yes"
#define no "No"

typedef pair<int, int> P;
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s; cin>>s;
    int now = 0;
    int ans = 0;
    REP(i,s.length()){
        if(s[i]=='A'||s[i]=='C'||s[i]=='G'||s[i]=='T') now++;
        else {
            ans = max(ans,now);
            now = 0;
        }
    }
    ans = max(ans,now);
    print(ans);
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main
{
  public static void main(String args[])
  {
    Scanner sc=new Scanner(System.in);
    int a=sc.nextInt();
    int b=sc.nextInt();
    if(b%a==0)
      System.out.println(a+b);
    else
      System.out.println(b-a);
  }
}

Measured memory_bytes: 23636
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int a = x/1000;
		int b = x/100 -a*10;
		int c = x/10 -a*100 - b*10;
		int d = x-a*1000-b*100-c*10;


		if(a==b&&b==c||b==c&&c==d) {
			System.out.print("Yes");
		}
		else {
			System.out.print("No");
		}
	}

}

Measured memory_bytes: 23892
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>
#include<queue>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	Int a, b;
	cin >> a >> b;

	cout << (a-1)*(b-1) << "\n";

}


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

using namespace std;

int main(){
	int n,m;
	cin >> n >> m;
	vector<vector<int> > v(n+1);
	for(int i=0;i<m;i++){
		int a,b;
		cin >> a >> b;
		v[a].push_back(b);
		v[b].push_back(a);
	}
	int c[200001]={};
	int d[200001]={};
	for(int i=0;i<v[1].size();i++){
		c[v[1][i]]=1;
	}
	for(int i=0;i<v[n].size();i++){
		d[v[n][i]]=1;
	}
	for(int i=1;i<n;i++){
		if(c[i]==1&&d[i]==1){
			cout << "POSSIBLE" << endl;
			return 0;
		}
	}
	cout << "IMPOSSIBLE" << endl;
	return 0;
}

Measured memory_bytes: 13552
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <iomanip>

using namespace std;
#define LOCAL  1
#define UPLOAD 2
#define ll long long
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
template <class T = long long> T input(){T x;cin >> x;return x;}
template <class T> void output(T x){cout << x << endl;}
#define debug(x) cerr << #x<< ": " << x<< '\n';
#define debugBit(x,n) cerr << #x<< ": " << std::bitset<n>(x) << '\n';

int main()
{
#if ENVIRONMENT == LOCAL
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
  string S = input<string>();
  string T = input<string>();

  output(T+S);

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    int r;
    int c;
    scanf("%d%d",&r,&c);
    int exc[r+1][c+1];
    int i;
    int j;
    for(i=0;i<=r;i++){
        for(j=0;j<=c;j++){
            exc[i][j]=0;
        }
    }
    for(i=0;i<r;i++){
        for(j=0;j<c;j++){
            scanf("%d",&exc[i][j]);
        }
    }
    for(i=0;i<r;i++){
        for(j=0;j<c;j++){
            exc[i][c]=exc[i][c]+exc[i][j];
        }
    }
    for(i=0;i<=c;i++){
        for(j=0;j<r;j++){
            exc[r][i]=exc[r][i]+exc[j][i];
        }
    }
    for(i=0;i<=r;i++){
        for(j=0;j<=c;j++){
            printf("%d",exc[i][j]);
            if(j!=c){
                printf(" ");
            }
        }
        printf("\n");
    }
    return 0;
}

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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, m;
	cin >> n >> m;
	vector<int> l(m);
	vector<int> r(m);
	rep(i, m) {
		cin >> l[i]; cin >> r[i];
	}
	int res1 = 0;
	int res2 = 1000000;
	rep(i, m) {
		res1 = max(res1, l[i]);
		res2 = min(res2, r[i]);
	}
	cout << max(0, res2 - res1 + 1) << endl;
}

Measured memory_bytes: 1024
while True:
    a, op, b = map(str, input().split())
    a = int(a)
    b = int(b)
    if op=='?': break
    else:
        if op=='+': print(a+b)
        elif op=='-': print(a-b)
        elif op=='*': print(a*b)
        elif op=='/': print(a//b)


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

bool p[300000];

void prime() {
  fill(p, p+300000, true);
  p[0] = false, p[1] = false;
  for(int i = 2; i < 300000; i++) {
    if(p[i]) {
      for(int j = 2; i*j < 300000; j++) {
	p[i*j] = false;
      }
    }
  }
}

int main() {
  int n;
  prime();

  while(cin >> n, n) {
    int ans = 0;
    for(int i = n+1; i <= 2*n; i++) {
      if(p[i]) ans++;
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 1452
import sys


stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))


def main():
    a, b, k = nm()

    for i in range(a, min(a + k, b + 1)):
        print(i)
    for i in range(max(a + k, b - k + 1), b + 1):
        print(i)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9144
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
  	Scanner input = new Scanner(System.in);
    String str = input.nextLine();

    if (str.charAt(2) == str.charAt(3) && str.charAt(4) == str.charAt(5)) {
      System.out.println("Yes");
    }
    else {
      System.out.println("No");
    }
  }
}

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

bool binary_search(int a[],int n,int x){
    int l=0,r=n;
        int mid;
    while(r-l>0){
        mid=(l + r) / 2;
        if(a[mid]==x)return true;
        else if(x<a[mid])r=mid;
        else l =mid+1;
    }
    return false;
}

int main(){
    int n;
    int q;
    int ans=0;
    int t;
    int A[100005]={};

    cin>>n;

    for(int i=0;i<n;i++){
        cin>>A[i];
    }
    cin>>q;

    for(int i=0;i<q;i++){
        cin>>t;
        if(binary_search(A,n,t)) ans++;
    }
    cout<<ans<<endl;
    return 0;
}


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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pb(n) push_back(n)
#define mp make_pair
#define INF LONG_LONG_MAX
#define yn(f) cout << (f ? "Yes" : "No") << endl;

int n,ans=2;

signed main() {
    cin >> n;
    if (n == 2) {
        cout << 1 << endl;
        return 0;
    }
    int tmpn = n-1;
    int b = sqrt(tmpn);
    for(int i=2; i<=b; ++i) {
        if (tmpn%i == 0) ans+=2;
        if (i*i == tmpn) --ans;
    }
    b = sqrt(n);
    for(int i=2; i<=b; ++i) {
        if (n%i == 0) {
            int tmp = n;
            while(tmp%i == 0) tmp /= i;
            if (tmp%i == 1) ans++;
            int I = n/i;
            tmp = n;
            while(tmp%I == 0) tmp /= I;
            if (tmp%I == 1 && i!=I) ans++;
        }
    }
    cout << ans << endl;
}





Measured memory_bytes: 256
N,K = gets.chomp.split(" ").map(&:to_i)
if K%2 == 1
  L = N/K
  print(L*L*L)
else
  L = N/K
  M = (N/K) + (N%K)/(K/2)
  print(L*L*L+M*M*M)
end
  

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
const ll inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

int R, G, B, N;
ll ans;

int main()
{
    cin >> R >> G >> B >> N;
    for (int i = 0; R * i <= N; i++)
    {
        for (int j = 0; G * j <= N; j++)
        {
            if (R * i + G * j > N)
                continue;
            int res = N - i * R - G * j;
            if (res % B == 0)
                ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
using System;

using System.Collections.Generic;

class Program {
    static void Main(string[] args) {

        long N = long.Parse(Console.ReadLine());

        long result = N;

        for(long a = 1; a <= Math.Sqrt(N); a++) {
            if (N % a == 0) {
                long b = N / a;
                if (a + b - 2 < result) {
                    result = a+b-2;
                }
            }
        }

        Console.WriteLine(result);
        
    }
}

Measured memory_bytes: 13140
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
using namespace std;

int N, A, B, C, D;
string S;

bool solve(int t, int s){
    if(t == s) return true;
    if(t > s) return false;
    if(S[t] == '#' || S[s] == '#') return false;
    for(int i=t; i<s; i++){
        if(S[i] == '#' && S[i+1] == '#') return false;
    }
    return true;
}
int main(){
    cin >> N >> A >> B >> C >> D;
    cin >> S;
    A--; B--; C--; D--;
    if(C < D){
        if(solve(A, C) && solve(B, D)) cout << "Yes" << endl;
        else cout << "No" << endl;
    }else{
        int pos = -1;
        for(int i=B; i<N-1; i++){
            if(S[i-1] == '.' && S[i] == '.' && S[i+1] == '.'){
                pos = i;
                break;
            }
        }
        if(pos == -1){
            cout << "No" << endl;
            return 0;
        }
        if(!solve(B, pos) || !solve(A, pos-1)){
            cout << "No" << endl;
            return 0;
        }
        if(solve(pos+1, C) && solve(pos, D)) cout << "Yes" << endl;
        else cout << "No" << endl;
    }


    return 0;
}

Measured memory_bytes: 640
#include <cstdlib>
#include <iostream>
#include <queue>
#include <vector>
#include <cmath>
#include <string>
using namespace std;
typedef unsigned long long u64;
typedef signed long long l64;
u64 over = 1000000007;

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  cout << "ABC" << n << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define all(x) x.begin(), x.end()

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
typedef long long ll;

template <typename T> void max_self(T& a, T b){
  a = max(a,b);
}

template <typename T> void min_self(T& a, T b){
  a = min(a,b);
}

void solve(){	
  int n; cin>>n;
  vpi v(n);
  for(int i=0;i<n;i++){
    cin>>v[i].F>>v[i].S;
  }
  int c = 0;
  for(int i=0;i<n;i++){
    if(v[i].F != v[i].S) c = 0;
    if(v[i].F == v[i].S) c++;

    if(c == 3){
      cout<<"Yes\n";
      return;
    }
  }
  cout<<"No\n";
}

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  //int t; cin >> t;
  //while(t--) solve();
  //
  solve();
  return 0;
}


Measured memory_bytes: 3656
n, x, y = map(int, input().split())
g = [[] for _ in range(n)]
for i in range(n-1):
    g[i].append(i+1)
    g[i+1].append(i)
x -= 1
y -= 1
g[x].append(y)
g[y].append(x)

d = {}
for i in range(n):
    d[i] = 0

from collections import deque
for i in range(n):
    q = deque()
    q.append(i)
    visit = [-1]*n
    visit[i] = 0
    while q:
        x = q.popleft()
        for nx in g[x]:
            if visit[nx] == -1:
                visit[nx] = visit[x]+1
                q.append(nx)
    for i in range(n):
        d[visit[i]] += 1
#print(d)
for k in range(1, n):
    print(d[k]//2)

Measured memory_bytes: 49456
#include <bits/stdc++.h>
using namespace std;
#define rep(i, s, n) for (int i = (s); i < (n); ++i)
#define rem(i, s, n) for (int i = (s); i >= (n); --i)
using ll = long long;

int main() {
	ll n; cin >> n;
	vector<ll> a(n); rep(i, 0, n) cin >> a[i];

	ll c = 1, ans = 0;
	rep(i, 0, n) {
		if (a[i] != c) ans++;
		else c++;
	}

	if (ans == n) cout << -1 << endl;
	else cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1920
#include <stdio.h>

long int gcd(long int x, long int y);

int main(void)
{
    long int a, b, c;

    while(scanf("%ld %ld", &a, &b) != EOF) {
       c = gcd(a,b);
       printf("%ld %ld\n", c, a/c*b); // a*b/cだと long int では扱えないので NG
    }

    return (0);
}


long int gcd(long int x, long int y)
{
    long int r = 0;
    
    if(x < y) {
        r = x;
        x = y;
        y = r;
    }

    while(y > 0) {
        r = x%y;
        x = y;
        y = r;
    }

    return (x);
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;

int main() {
    int n;
    cin >> n;
    int to_add = 0;
    VVI dp(n+2, VI(n+2, -1));
    int a1, a2;
    cin >> a1 >> a2;
    if (a1 > a2) swap(a1, a2);
    dp[0][0] = 0;
    dp[0][a1] = 0;
    dp[0][a2] = 0;
    dp[a1][a2] = 0;
    rep(i, n) {
        int x, y, z;
        if (i == n-1) {
            cin >> x;
            y = z = n+1;
        } else {
            cin >> x >> y >> z;
        }
        if (y < x) swap(x, y);
        if (z < x) swap(x, z);
        if (z < y) swap(y, z);
        if (x == y && y == z) {
            to_add += 1;
            continue;
        }
        vector<tuple<int, int, int>> to_update;
        if (x == y) {
            // [*][x] -> [*][0] / [*][z]
            rep(w, n+1) {
                int s = min(x, w), t = max(x, w);
                if (dp[s][t] < 0) continue;
                int nsc = dp[s][t] + 1;
                to_update.emplace_back(w, 0, nsc);
                to_update.emplace_back(w, z, nsc);
            }
        }
        if (y == z) {
            rep(w, n+1) {
                int s = min(y, w), t = max(y, w);
                if (dp[s][t] < 0) continue;
                int nsc = dp[s][t] + 1;
                to_update.emplace_back(w, 0, nsc);
                to_update.emplace_back(w, x, nsc);
            }
        }
        for(auto p: {tuple<int, int, int>{x, y, z}, {y, z, x}, {z, x, y}}) {
            int s, t, u;
            tie(s, t, u) = p;
            // [s][s] -> [0][0] / [0][t] / [0][u] / [t][u]
            if (dp[s][s] < 0) continue;
            int nsc = dp[s][s] + 1;
            to_update.emplace_back(0, 0, nsc);
            to_update.emplace_back(t, 0, nsc);
            to_update.emplace_back(u, 0, nsc);
            to_update.emplace_back(t, u, nsc);
        }
        for(int s: {x, y, z}) {
            // [0][*] -> [x][*]
            rep(w, n+1) {
                if (dp[0][w] < 0) continue;
                to_update.emplace_back(s, w, dp[0][w]);
            }
        }
        if (dp[0][0] >= 0) for(auto p: {P{x, y}, {y, z}, {z, x}}) {
            // [0][0] -> [x][y]
            int s, t;
            tie(s, t) = p;
            to_update.emplace_back(s, t, dp[0][0]);
        }
        for(auto p: to_update) {
            int s, t, score;
            tie(s, t, score) = p;
            if (s > t) swap(s, t);
            chmax(dp[s][t], score);
        }
    }
    int ans = 0;
    rep(i, n+1) rep(j, n+1) chmax(ans, dp[i][j]);
    ans += to_add;
    cout << ans << endl;
}


Measured memory_bytes: 19316
danmen = input()
down = []
edge = []
pool = []

for (i, line) in enumerate(danmen):
    if line == "\\":
        down.append(i)
    elif down and line == "/":
        left = down.pop()
        area = i - left

        while edge:
            if edge[-1] > left:
                edge.pop()
                area += pool.pop()
            else:
                break

        edge.append(left)
        pool.append(area)

print(sum(pool))
print(len(pool), *pool)

Measured memory_bytes: 8032
package main 

 import(
     "bufio"
     "fmt"
     "os"
     
     )
var r = bufio.NewReader(os.Stdin)

func main(){
     var a int
     var b int
     fmt.Fscan(r,&a,&b)
     
     
     x := a*b
     y := a*2+b*2
     fmt.Println(x,y)
}


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

int main() {
  int N;
  cin >> N;
  
  if(N < 10) {
    cout << N << endl;
  } else if(10 <= N && N < 100) {
    cout << 9 << endl;
  } else if(100 <= N && N < 1000) {
    cout << N - 90 << endl;
  } else if(1000 <= N && N < 10000) {
    cout << 909 << endl;
  } else if(10000 <= N && N < 100000) {
    cout << N - 9090 << endl;
  } else {
    cout << 90909 << endl;
  }
}


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <climits> // INT_MAX, LONG_MAX, LLONG_MAX, UINT_MAX, ULONG_MAX, ULLONG_MAX
#include <cmath>
#include <cstdint>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

#define ALL(x) (x).begin(), (x).end()
#define INF 1e9
#define LOG(x) cout << #x << " = " << (x) << endl
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)

using namespace std;

int main() {
    int N, K;
    vector<pair<int, int>> ab;

    cin >> N >> K;
    for (int i = 0; i < N; ++i) {
        int ai, bi;
        cin >> ai >> bi;
        ab.push_back({ai, bi});
    }

    // sort(ALL(ab), [&] (const pair<int, int>&a, const pair<int, int>& b) -> bool { return a.first < b.first; });

    // int msb = 0;
    // for (long long i = 1; i <= INT_MAX; i <<= 1) {
    //     if (i > K)
    //         break;
    //     msb++;
    // }

    unsigned int mask_seed = 1;
    long long maxValue = 0;
    for (int i = 1; i <= 30; i++, mask_seed <<= 1) {
        int mask = K;
        if (i > 1) {
            if ((K & mask_seed) == 0)
                continue;
            mask = K & ~mask_seed; // i-th bit = 0
            mask |= (mask_seed - 1); // 0 to (i - 1)-th bit = 1
        }
        long long value = 0;
        for (auto j : ab) {
            if ((j.first & ~mask) == 0) {
                value += j.second;
            }
        }
        maxValue = max(maxValue, value);
    }

    cout << maxValue << endl;
    
    return 0;
}


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

public class Main {
    FastScanner in;
    PrintWriter out;


    void solve() {
        int h = in.nextInt();
        int w = in.nextInt();
        int b = in.nextInt();
        int a = in.nextInt();
        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                int x = ((i < a) ? 1 : 0) ^ ((j < b) ? 1 : 0);
                out.print(x);
            }
            out.println();
        }
    }

    void run() {
        try {
            in = new FastScanner(new File("Main.in"));
            out = new PrintWriter(new File("Main.out"));

            solve();

            out.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }

    void runIO() {

        in = new FastScanner(System.in);
        out = new PrintWriter(System.out);

        solve();

        out.close();
    }

    class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(File f) {
            try {
                br = new BufferedReader(new FileReader(f));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        public FastScanner(InputStream f) {
            br = new BufferedReader(new InputStreamReader(f));
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return null;
                st = new StringTokenizer(s);
            }
            return st.nextToken();
        }

        boolean hasMoreTokens() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return false;
                st = new StringTokenizer(s);
            }
            return true;
        }

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

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

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

    public static void main(String[] args) {
        new Main().runIO();
    }
}


Measured memory_bytes: 43732
import sys
def input():
    return sys.stdin.readline()[:-1]
a=input()
li=[0]*26
for i in range(len(a)):
    li[ord(a[i])-ord("a")]+=1
ans=len(a)*(len(a)-1)//2+1
for i in li:
    ans-=i*(i-1)//2
print(ans)

Measured memory_bytes: 40176
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define SaveTime ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back 
#define eb emplace_back
#define mx *max_element
#define mi *min_element
#define fn for(int i =0 ;i <n;i++)
#define fn1 for( int i =1;i<=n;i++)
#define fm for(int j =0 ;j <m;j++)
#define fm1 for(int j =1;j<=m;j++)
#define fi first
#define se second
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
const int N = 1e6+5;
const int INF = 1e18L;
int ncr(int n,int r){if(n<r)return 0;int p=1,k=1;if(n-r<r)r=n-r;if(r!=0){while(r){p*=n;k*=r;int g=__gcd(p, k);p/=g;k/=g;n--;r--;}}else p=1;return p;}
#define pi acos(-1)
int ar[N];
int tree[2*N];
int dp[N];
int bit[N];
signed main(){
 	
	SaveTime;
	int T=1;
	// cin >> T;
	while(T--){
		int n;
		cin >>n;
		vector<int>v;
		fn{
			int x;cin >> x;
			v.pb(x);
		}
		int ans =0 ;
		// int cur = v[0] , nxt , s=0;
		for(int i =0 ;i < n -1 ;){
			int st = i;
			if(v[i] < v[i+1]){
				i++;
				continue;
			}
			while(i < n-1 && v[i] >= v[i+1]){
				i++;
			}
			ans = max(ans , i-st);
		}
		cout << ans <<  endl;
	
	}
	
	return 0;
}


Measured memory_bytes: 1400
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(ll i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind 
#define Pint pair<llint,llint>
#define keta(a)  fixed << setprecision(a)
constexpr auto INF = 100000000000;
constexpr auto mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！
struct edge { int to, cost; };

ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0)return a;
	return gcd(b, a % b);
}

long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

// mod. m での a の逆元 a^{-1} を計算するよ！
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;
}


//aCbをmod.mで割った余りを求める
ll int c(ll int a, ll int b, ll int m) {
	ll int ans = 1;
	for (ll int i = 0; i < b; i++) {
		ans *= a - i;
		ans %= m;
	}
	for (ll int i = 1; i <= b; i++) {
		ans *= modinv(i, m);
		ans %= m;
	}
	return ans;
}
struct UnionFind {
	vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

	UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
		for (int i = 0; i < N; i++) par[i] = i;
	}
	int size(int a) {
		return par[root(a)];
	}

	int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
		if (par[x] == x) return x;
		return par[x] = root(par[x]);
	}

	void unite(int x, int y) { // xとyの木を併合
		int rx = root(x); //xの根をrx
		int ry = root(y); //yの根をry
		if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
		par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
	}

	bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};
int max(int a, int b) {
	if (a < b)return b;
	return a;
}
int min(int b, int a) {
	if (a > b)return b;
	return a;
}
int f(llint a) {
	int ans = 0;
	while (a) {
		a /= 2;
		ans++;
	}
	return ans;
}

int main() {
	int n, m;
	cin >> n >> m;
	hei(int) a(m), b(m);
	whei(int) G(n);
	rep(i, 0, m) {
		cin >> a[i] >> b[i];
		a[i]--;
		b[i]--;
		G[a[i]].push_back(b[i]);
		G[b[i]].push_back(a[i]);
	}
	hei(int) s(n, -1);
	queue<int> que;
	que.push(0);
	while (!que.empty()) {
		int x = que.front(); que.pop();
		for (auto z : G[x]) {
			if (s[z] != -1)continue;
			s[z] = x+1;
			que.push(z);
		}
	}
	rep(i, 1, n) {
		if (s[i] == -1) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	rep(i, 1, n) {
		cout << s[i] << endl;
	}
	return 0;
}



Measured memory_bytes: 11784