akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.io.*;

public class Main{
	public static void main(String[] args)  throws IOException,NumberFormatException{
		try {
		FastScanner sc=new FastScanner();
		int n=sc.nextInt(),m=sc.nextInt();
		char a[][]=new char[n][m];
		for(int i=0;i<m+2;i++) {
			System.out.print("#");
		}
		System.out.println();
		for(int i=0;i<n;i++) {
			char s[]=sc.next().toCharArray();
			for(int j=0;j<m;j++) {
				a[i][j]=s[j];
			}
		}
		for(int i=0;i<n;i++) {
			System.out.print("#");
			for(int j=0;j<m;j++) {
				System.out.print(a[i][j]);
			}
			System.out.println("#");
		}
		for(int i=0;i<m+2;i++) {
			System.out.print("#");
		}
		}
		catch(Exception e) {
			return ;
		}
		
	}
	static final Random random=new Random();
	
	static void ruffleSort(int[] a) {
		int n=a.length;
		for(int i=0;i<n;i++) {
			int oi=random.nextInt(n),temp=a[oi];
			a[oi]=a[i]; a[i]=temp;
		}
		Arrays.sort(a);
	}
	
	public static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try { 
                                      st=new StringTokenizer(br.readLine());				               
                              } catch (IOException e) {}
			return st.nextToken();
		}
		
		int nextInt() {
			return Integer.parseInt(next());
		}
		
		long nextLong() {
			return Long.parseLong(next());
		}
		
		int[] readArray(int n) {
			int[] a=new int[n];
			for (int i=0; i<n; i++) a[i]=nextInt();
			return a;
		}
		
		long[] readLongArray(int n) {
			long[] a=new long[n];
			for(int i=0; i<n ; i++) a[i]=nextLong();
			return a;
		}
		
		String nextLine() 
        { 
            String str = ""; 
            try
            { 
                str = br.readLine(); 
            } 
            catch (IOException e) 
            { 
                e.printStackTrace(); 
            } 
            return str; 
        } 
	}

}


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

using namespace std;

#define endl '\n'

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
  cout << fixed << setprecision(10);
  int n;
  cin >> n;
  vector<double> p(n);
  for (int i = 0; i < n; i++) {
    cin >> p[i];
  }
  double dp[n + 1][n + 1];
  dp[0][0] = 1;
  for (int i = 1; i <= n; i++)
    dp[0][i] = dp[0][i - 1]*(1 - p[i - 1]);
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= n; j++) {
      if (i > j) dp[i][j] = 0;
      else dp[i][j] = dp[i - 1][j - 1]*p[j - 1] + dp[i][j - 1]*(1 - p[j - 1]);
    }
  }
  double ans = 0.0;
  for (int i = n/2 + 1; i <= n; i++) {
    ans += dp[i][n];
  }
  cout << ans << endl;

	return 0;
}


Measured memory_bytes: 74160
mod = 1000000007
eps = 10**-9


def main():
    import sys
    from collections import defaultdict
    input = sys.stdin.readline

    N = int(input())
    A = list(map(int, input().split()))

    AA = [0] * N
    for i, a in enumerate(A):
        AA[i] = -a + i + 1
    ans = 0
    C = defaultdict(int)
    for i in range(N-2, -1, -1):
        C[AA[i+1]] += 1
        ans += C[A[i] + i + 1]
    print(ans)


if __name__ == '__main__':
    main()


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

using namespace std;

using int64 = long long;

const int mod = 1e9 + 7;

template< class T >
struct BinaryIndexedTree {
  vector< T > data;

  BinaryIndexedTree(int sz) {
    data.assign(++sz, 0);
  }

  T sum(int k) {
    T ret = 0;
    for(++k; k > 0; k -= k & -k) ret = max(ret, data[k]);
    return (ret);
  }

  void add(int k, T x) {
    for(++k; k < data.size(); k += k & -k) data[k] = max(data[k], x);
  }
};

int main() {
  int N, H[200000];
  cin >> N;
  vector< int > ex;
  for(int i = 0; i < N; i++) {
    cin >> H[i];
    ex.emplace_back(H[i]);
  }
  sort(begin(ex), end(ex));
  ex.erase(unique(begin(ex), end(ex)), end(ex));
  BinaryIndexedTree< int64 > bit(ex.size());
  int64 latte = 0;
  for(int i = 0; i < N; i++) {
    int c;
    cin >> c;
    H[i] = lower_bound(begin(ex), end(ex), H[i]) - begin(ex);
    auto ret = bit.sum(H[i] - 1) + c;
    latte = max(latte, ret);
    bit.add(H[i], ret);
  }
  cout << latte << endl;
}



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

using namespace std;

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

typedef long long ll;
ll mod=998244353;

int bc[200010];

int main()
{
	string s;
	cin >> s;
	int n=s.size();
	string t="Z";
	int pt=0;
	while(pt<n)
	{
		if(pt==n-1)
		{
			t+=s[n-1];
			pt++;
		}
		else
		{
			if(s[pt]=='B' && s[pt+1]=='C')
			{
				t+="D";
				pt+=2;
			}
			else
			{
				t+=s[pt];
				pt++;
			}
		}
	}
	t+="Z";
	//cout << t << endl;
	n=t.size();
	ll ans=0;
	pt=0;
	rep(i, n)
	{
		if(t[i]=='B' || t[i]=='C' || t[i]=='Z')
		{
			bc[pt]=i;
			pt++;
		}
	}
	rep(i, pt-1)
	{
		if(bc[i+1]>bc[i]+1)
		{
			ll sum=0, kosu=0;
			for(int j=bc[i]+1; j<bc[i+1]; j++)
			{
				if(t[j]=='D')
				{
					sum+=(ll)(j-bc[i]);
					kosu++;
				}
			}
			ans+=(sum-kosu*(kosu+1)/2);
		}
	}
	cout << ans << endl;
	//cout << t << endl;
	return 0;
}

Measured memory_bytes: 1544
import sys

def selection_sort(size, numbers):
    swap_count = 0

    for i in range(size):
        minindex = i
        for j in range(i + 1, size):
            if numbers[j] < numbers[minindex]:
                minindex = j

        if i != minindex:
            swap_count += 1
            numbers[i], numbers[minindex] = numbers[minindex], numbers[i]

    return swap_count

def main(stdin=None, stdout=None):
    if stdin is None:
        stdin = sys.stdin
    if stdout is None:
        stdout = sys.stdout

    size = int(stdin.readline().strip())
    numbers = [int(x) for x in stdin.readline().strip().split(" ")]

    swap_count = selection_sort(size, numbers)
    stdout.write(" ".join([str(x) for x in numbers]) + "\n")
    stdout.write(str(swap_count) + "\n")

main()


Measured memory_bytes: 5616
import qualified Data.Vector.Unboxed as VU
import qualified Data.ByteString.Char8 as B
import Data.Char

set :: VU.Vector Int -> Int -> Int
set vec acc
  | VU.length vec == 1 = acc + 1
  | otherwise = 
    case compare a b of
      LT -> trav vec 1 acc
      EQ -> set ts acc
      GT -> trav vec 0 acc
  where
    a = VU.head vec
    b = vec VU.! 1
    ts = VU.tail vec

trav :: VU.Vector Int -> Int -> Int -> Int 
trav vec mode acc 
  | VU.length vec == 1 = acc + 1
  | (mode == 1) && (a <= b) = trav ts mode acc
  | (mode == 0) && (a >= b) = trav ts mode acc
  | otherwise = set ts (acc + 1)
  where
    a = VU.head vec
    b = vec VU.! 1
    ts = VU.tail vec

main = do
  n <- readLn :: IO Int
  vec <- VU.unfoldrN n (B.readInt . B.dropWhile isSpace) <$> B.getLine
  print $ set vec 0



Measured memory_bytes: 3836
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long LL;
typedef vector<ll>VI;
typedef pair<ll,ll>P;
typedef pair<double,double>P_D;
#define VV(T) vector<vector<T>>
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define reprev(i, n) for (ll i = (ll)n - 1; i >= 0; i--)
#define ALL(a)  (a).begin(),(a).end()
#define c_max(a, b) (((ll)a)>((ll)b)?(a):(b))
#define c_min(a,b) (((ll)a)<((ll)b)?(a):(b))
#define chmax(x,a) x=max(x,a)
#define chmin(x,a) x=min(x,a)
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define $(x) {cout<<#x<<" = " <<(x)<<endl;}
#define fi first
#define se second
#define MAX 100100//5
#define MAX2 200100
#define MAX_6 1001001//6
#define MAX_7 10010010//7
#define SENTINEL 2000000000//9
#define NIL -1
const int MOD = 1000000007;
#define INF 1<<30
#define INFTY 1LL<<61
#define MAX_INT INT_MAX
#define Endl '\n'
inline ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}
inline ll lcm(ll a,ll b){return a*b/GCD(a,b);}
using Edge=pair<int,ll>;
using Graph=vector<vector<int> >;//ll or Edge
using Edge=pair<int,ll>;
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
// sort_reverse...greater<ll>()
// g++ -o a a.cpp -Wall -lm -std=c++17

int main(){
    LL n,p;cin>>n>>p;
    int m=0;
    rep(i,n){
        int a;cin>>a;
        if(a%2)m++;
    }
    if(m==0)cout<<(p==0?((LL)1LL<<n):0)<<endl;
    else cout<<((LL)1LL<<(n-1))<<endl;
}

Measured memory_bytes: 3676
#include<iostream>
#include <stdlib.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <vector>
#include <numeric>
typedef long long int ll;
using namespace std;
int main(){
	vector<ll> X;
	ll k,x;
	cin>> k;
	for(int i=0; i<k;i++){
		cin>>x;
		X.push_back(x);
	}
	sort(X.begin(),X.end());
	if(accumulate(X.begin(),--X.end(),0)>X[k-1]){
		cout << "Yes"<< endl;
	}else{
		cout << "No"<<endl;
	}
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int x = scan.nextInt();
		int a = scan.nextInt();
		int b = scan.nextInt();
		int a_x = a - x;
		int b_x = b - x;
		if(a_x < 0) {
			a_x = a_x * (-1);
		}
		if(b_x < 0) {
			b_x = b_x * (-1);
		}
		if(a_x < b_x) {
			System.out.println("A");
		} else {
			System.out.println("B");
		}
	}
}

Measured memory_bytes: 21844
N = int(input())
X = [int(x) for x in input().split()]
X.sort()
P = [[0 for i in range(N)] for _ in range(101)]
for p in range(101):
  for i, x in enumerate(X):
    P[p][i] = (x - p) ** 2
print(min([sum(p) for p in P[1:]]))

Measured memory_bytes: 3316
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)
#define LL long long

int main(){
  int N;
  cin>>N;
  int c[N], s[N], f[N];
  REP(i, N-1) cin>>c[i]>>s[i]>>f[i];
  c[N-1]=0;
  s[N-1]=0;
  f[N-1]=0;

  int ans[N];
  ans[N-1]=0;
  for(int i=N-2; i>-1; --i){
    ans[i] = s[i]+c[i];
    for(int j=i+1; j<N-1; ++j){
      if(ans[i]<s[j]) ans[i] = s[j]+c[j];
      else if(ans[i]%f[j]==0) ans[i]+=c[j];
      else ans[i] = ans[i] -ans[i]%f[j] +f[j]+c[j];
    }
  }

  REP(i, N) cout<<ans[i]<<endl;


  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,c,d,e;
  cin >> a >> b >> c >> d >> e;
  int last = 10,ans = 0;
  int i;
  if(a%10 < last && a%10 != 0){
    last = a%10;
  }
  ans += ((a+9)/10)*10;
  
  if(b%10 < last && b%10 != 0){
    last = b%10;
  }
  ans += ((b+9)/10)*10;
  
  if(c%10 < last&& c%10 != 0){
    last = c%10;
  }
  ans += ((c+9)/10)*10;
  
  if(d%10 < last&& d%10 != 0){
    last = d%10;
  }
  ans += ((d+9)/10)*10;
  
  if(e%10 < last&& e%10 != 0){
    last = e%10;
  }
  ans += ((e+9)/10)*10;
  
 ans = ans -10 + last;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define mp make_pair
#define fast ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
#define ff first
#define ss second
#define INF (ll) (1e9)
#define mod (ll) (1e9 + 7)
#define endl "\n"
#define tt ll testcase; cin>>testcase; while(testcase--)
 
const int mxn = 1*(1e5) + 5;
ll n, m;
 
void solve(){
    cin >> n;
    ll h[n];
    for(int i=0; i<n; i++) {
        cin >> h[i];
    }
    ll dp[n+1];
    dp[1] = 0;
    dp[2] = abs(h[1] - h[0]);
    for(int i=3; i<=n; i++) {
        dp[i] = min(dp[i-1] + abs(h[i-1] - h[i-2]), dp[i-2] + abs(h[i-1] - h[i-3]));
    }
    cout<<dp[n];
}
 
int main(){
    fast;
    //  tt
        solve();
}

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

using namespace std;

#define  input freopen("in.txt","r",stdin)
#define  output freopen("out.txt","w",stdout)
const int mxn = 1e5+5;

int cnt1[mxn];
int cnt2[mxn];

int main()
{
	//input;
	//output;

	int n;
	cin >> n;
	int mx = 0, t;
	for(int i = 1; i <= n; i++)
	{
		cin >> t;
		if(i&1) cnt2[t]++;
		else cnt1[t]++;
		mx = max(mx, t);
	}
	int mx11 = 0, mx12 = 0, mx21 = 0, mx22 = 0;
	int v11 = 0, v12 = 0, v21 = 0, v22 = 0;

	for(int i = 1; i <= mx; i++)
	{
		if(cnt1[i]>mx11)
		{
			mx12 = mx11;
			mx11 = cnt1[i];
			v12 = v11;
			v11 = i;
		}
		else if(cnt1[i]>mx12)
		{
			mx12 = cnt1[i];
			v12 = i;
		}
		if(cnt2[i]>mx21)
		{
			mx22 = mx21;
			mx21 = cnt2[i];
			v22 = v21;
			v21 = i;
		}
		else if(cnt2[i]>mx22)
		{
			mx22 = cnt2[i];
			v22 = i;
		}
	}	
	int ans = -1;
	if(v11 == v21) 
	{
		if(v11!=v22) ans = max(ans, mx11+mx22);
		if(v12!=v21) ans = max(ans, mx12+mx21);
	}
	else ans = mx11+mx21;
	ans = n-ans;
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 1024
tmp = input().split()
Lt = int(tmp[0])
At = int(tmp[1])
La = int(tmp[2])
Aa = int(tmp[3])

while True:
    La = La - At
    if La <= 0:
        print('Yes')
        break
    Lt = Lt - Aa
    if Lt <= 0:
        print('No')
        break


Measured memory_bytes: 9204
// G - Longest Path
// O(V)
 
#include <bits/stdc++.h>
 
using namespace std;
 
#define fi first
#define se second
#define pb push_back
 
typedef long long ll;
typedef pair<int, int> pii;
 
const ll inf = 1e15L;
const int maxn = 3010;
double p[maxn];
double dp[maxn][maxn];
 
int main(){
    // freopen("input.txt", "r", stdin);
    // ios_base::sync_with_stdio(0);
    // cin.tie(0); 
    int n;
    scanf("%d", &n);
    memset(p, 0, sizeof(p));
    memset(dp, 0, sizeof(dp));
    dp[0][0] = 1.;
    for (int i = 1; i <= n; ++i)
    {
         scanf("%lf", &p[i]);
         dp[i][0] = dp[i-1][0] * (1-p[i]);
         dp[i][i] = dp[i-1][i-1] * p[i];
    }
    
    //dp[i][j] - i is the number of current coins, j is the number fo heads
    for(int i = 1; i <= n; ++i){
        for(int j = 1; j <= i; ++j){
            dp[i][j] = p[i] * dp[i-1][j-1] + (1 - p[i]) * dp[i-1][j];
        }
    }
    // for(int i = 0; i <= n; ++i){
    //     for(int j = 0; j <= n; ++j)cout << dp[i][j] << " ";
    //         cout << endl;
    // }
    double res = 0.;
    for (int head = 1; head <= n; ++head)
    {
        int tail = n - head;
        if(head > tail)res = res + dp[n][head];
    }
    printf("%.10lf\n", res);
    return 0;
}

Measured memory_bytes: 71168
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#define rep(i, n)   for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

const int INF = 1001001001;

int main(){
    int n;  cin >> n;
    vector<int>p(n);
    rep(i, n)   cin >> p[i];
    int ans = 0;
    int Min = INF;
    rep(i, n){
        if(p[i] <= Min){
            ans++;
            Min = min(Min, p[i]);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxx = 1e5 + 7;
const int Inf = 1 << 30;
const ll INF = 1ll << 60;
int n;
int a[maxx];
int ans;

void Init() {
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
	a[n + 1] = Inf;
}

int main() {
	Init();
	int minT = a[1], tmp = 0;
	for(int i = 2; i <= n + 1; i++) {
		if(a[i] <= minT) tmp++;
		else {
			ans = max(ans, tmp);
			tmp = 0;
		}
		minT = a[i];
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 640
fun main(args: Array<String>) {
    val (r, c) = readLine()?.split(" ")?.map { it.toInt() } ?: return
    val matrix = Array(r, { intArrayOf() })
    val rowList = arrayListOf<Int>()
    for (i in 0 until r) {
        val elements = readLine()?.split(" ")?.map { it.toInt() }?.toMutableList() ?: return
        rowList.add(elements.sum())
        matrix[i] = elements.toIntArray()
    }
    val builder = StringBuilder()
    val colSumList = arrayListOf<Int>()
    for ((i, row) in matrix.withIndex()) {
        row.forEachIndexed { j, element ->
            if (colSumList.size < c) {
                colSumList.add(element)
            } else {
                colSumList[j] += element
            }
        }
        builder.append(row.joinToString(" "))
                .append(" ${rowList.get(i)}")
                .appendln()
    }
    builder.append(colSumList.joinToString(" "))
            .append(" ${colSumList.filterNotNull().sum()}")
            .appendln()
    print(builder.toString())

}


Measured memory_bytes: 36516
import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7

def calc_comb(zeros, ones, length):
    return (pow(2,ones,MOD) * pow(3,(length - ones - zeros),MOD)) % MOD

def main():
    # L = int('0b'+SI(), 0)
    L = SI()

    count_one = 0
    count_zero = 0
    comb = 0
    for char in L:
        if char == '0':
            count_zero += 1
        elif char == '1':
            count_one += 1
            comb += calc_comb(count_zero + 1, count_one -1, len(L))
            comb %= MOD

    comb += calc_comb(count_zero, count_one, len(L))  # Lの最後が0だったとしても1だったとしても、a+b = L の場合が計算されていない。
    comb %= MOD

    print(comb)

main()

Measured memory_bytes: 40560
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using st=string;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
#define pb push_back
#define mp make_pair
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
st abc="abcdefghijklmnopqrstuvwxyz";
st ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct edge{ll to,cost;};

int main() {
    ll n;
    cin >> n;
    st t;
    while(n!=0){
        ll x=n%26;
        if(x==0){
            x=26;
        }
        t=abc[x-1]+t;
        n-=x;
        n/=26;
    }
    cout << t << endl;
}

Measured memory_bytes: 3620
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <list>
#include <set>
#include <stack>
#include <cctype>
#include <cmath>
#include <bitset>

using namespace std;
/* typedef */
typedef long long ll;
/* constant */
const int INF = 1 << 30;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int N;
    cin >> N;
    cout << (N + (2 - 1)) / 2 << '\n';
}


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

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

    static class BEcho {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            String x = in.next();
            if (n % 2 != 0) {
                out.println("No");
                return;
            }
            if (x.substring(0, n / 2).equals(x.substring(n / 2))) {
                out.println("Yes");
            } else {
                out.println("No");
            }
        }

    }

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

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

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

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

    }
}



Measured memory_bytes: 21716
#include<iostream>
#include<algorithm>
#include<cassert>

using namespace std;

const int MAX = 24*60+1;
int n,p,q;
int CM[MAX];

int tomin(int n){
  int h = n/100,m = n%100;
  return h*60+m;
}
void make(int f, int t){
  for(int i = f; i < t; i++)
    CM[i]++;
}

int main(){
  while(cin >> n >> p >> q && n+p+q){
    fill(CM,CM+MAX,0);
    for(int i = 0; i < n; i++){
      int k;
      cin >> k;
      for(int j = 0; j < k; j++){
	int f,t;
	cin >> f >> t;
	make(tomin(f),tomin(t));
      }
    }
    int sum = 0;
    int ans = 0;
    for(int i = tomin(p); i < tomin(q); i++)
      if(CM[i] < n) sum++;
      else{
	ans = max(ans,sum);
	sum = 0;
      }

    cout << max(ans,sum) << endl;
  }
  return 0;
}

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

using namespace std;

int main() {
  int N, K;
  cin >> N >> K;
  vector<int64_t> H(N);
  for (int i = 0; i < N; i++) cin >> H[i];
  sort(H.rbegin(), H.rend());
  for (int i = 0; i < min(K, N); i++) H[i] = 0;

  cout << accumulate(H.begin(), H.end(), 0LL) << endl;
  return 0;
}


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

fn main() {
    let n: i32 = read();
    let x: i32 = read();

    println!("{}", (n + x * 2) / (x * 2 + 1));
}

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


Measured memory_bytes: 4352
#include <iostream>
#include<cstdio>
#include<algorithm>
const long long mod=1e9+7;
typedef long long ll;
using namespace std;

ll f[1000010],revf[1000010];//????????1e5*2

ll qpow(ll a,ll b){
  ll ret=1;
  while(b){
    if(b&1) ret=(ret*a)%mod;
    a=(a*a)%mod;
    b>>=1;
  }
  return ret;
}

void init(){
  f[0]=1; revf[0]=qpow(f[0],mod-2);
  for(ll i=1;i<1000010;i++){
    f[i]=i*f[i-1]%mod;
    revf[i]=qpow(f[i],mod-2);
  }
}

ll C(ll n,ll m){
  return (f[n]*revf[m])%mod*revf[n-m]%mod;
}

ll count_ways(ll a,ll b,ll c,ll d){
  ll tot=(c-a)+(d-b);
  ll down=(c-a);
  ll ret=C(tot,down);
  return ret;
}

int main()
{
    init();
    ll h,w,a,b;
    cin>>h>>w>>a>>b;
    ll tot=count_ways(1,1,h,w);
    for(ll i=1;i<=b;i++){
        ll tmp=count_ways(1,1,h-a,i)*count_ways(h-a+1,i,h,w)%mod;
        while(tot<tmp) tot+=mod;//??????
        tot=(tot-tmp)%mod;
    }
    cout<<tot<<endl;
    return 0;
}

Measured memory_bytes: 15872
n = int(input())
a = input().split(" ")

num = []
for b in a:
    num.append(int(b))

entry = 'APPROVED'
for i in range(0, n):
    if num[i] % 2 == 0:
        if num[i] % 3 == 0:
            continue
        if num[i] % 5 == 0:
            continue

        entry = 'DENIED'
        break

print(entry)

Measured memory_bytes: 3060
X = int(input())

lut = [i**5 for i in range(200)]

a = 0
b = 0

for a, a5 in enumerate(lut):
    for b, b5 in enumerate(lut):
        if a5 + b5 == X:
            print(a,-b)
            exit()
        elif a5 -b5 == X:
            print(a, b)
            exit()


Measured memory_bytes: 9172
import collections

N = int(raw_input())
moji = []
moji.append(raw_input())
moji.append(raw_input())
moji.append(raw_input())

count = 0


for i in range(N):
	row = [moji[0][i],moji[1][i],moji[2][i]]
	count += 3 - collections.Counter(row).most_common()[0][1]

print count

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

int main() {
    long N;
    cin >> N;
    bool ans = true;
    bool b = false;
    if (N % 3 != 0) {
        for (int i = 0; i < N; i++) {
            long a;
            cin >> a;
            if (a != 0) {
                ans = false;
            }
        }
    }
    else {
        map<long, long> data;
        priority_queue<long> keep;
        for (int i = 0; i < N; i++) {
            long a;
            cin >> a;
            if (!data.count(a)) {
                data[a] = 1;
                keep.push(a);
            }
            else {
                data[a] = data.at(a) + 1;
            }
        }
        if (data.size() >= 4) {
            ans = false;
        }
        else if (data.size() == 1) {
            if (keep.top() != 0) {
                ans = false;
            }
        }
        else if (data.size() == 2) {
            if (data.at(keep.top()) != N * 2 / 3) {
                ans = false;
            }
            keep.pop();
            if (keep.top() != 0) {
                ans = false;
            }
            if (data.at(keep.top()) != N / 3) {
                ans = false;
            }
        }
        else if (data.size() == 3) {
            long x, y, z;
            x = keep.top();
            keep.pop();
            y = keep.top();
            keep.pop();
            z = keep.top();
            keep.pop();
            if (data.at(x) != N / 3 || data.at(y) != N / 3 || data.at(z) != N / 3) {
                ans = false;
            }
            if ((x ^ y ^ z) != 0) {
                ans = false;
            }
        }
    }

    if (ans) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

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

using namespace std;

int main()
{
    string s;
    cin>>s;
    int l=s.length();
    for(int i=0;i<l;i++)
    {
        if(s[i]==',')
        {
            s[i]=' ';
        }
    }
    cout<<s;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include<math.h>
#include<numeric>
#include<iomanip>
#define rep(i, n) rep2(i,0,n)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define PI acos(-1);
typedef long long ll;
using namespace std;
const int MOD=1000000007;
//scanf("%d", &a); '\n';
bool s[200050]={};
bool t[200050]={};
 
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, m;
	cin >> n >> m;
	rep(i,m)
	{
		int a, b;
		cin >> a >> b;
 
		if (a == 1) {
			t[b] = true;
		}
 
		if (b == n) {
			s[a] = true;
		}
	}
 
	rep(i,200050)
	{
		if (s[i] && t[i]) {
			cout << "POSSIBLE";
			return 0;
		}
	}
 
	cout << "IMPOSSIBLE";
	return 0;
	}
 
	

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <vector>
#include <stack>
#include <math.h>
#include <queue>

using namespace std;

typedef long long int ll;
typedef long double ld;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define vsort(a) sort(a.begin(), a.end())
#define rev(a) reverse(a.begin(), a.end())

const int MOD = 1000000007;
const int INF = INT_MAX;


// a,bの最小公倍数
ll LCM(ll a, ll b){ll lcm = a * b; ll r = a % b;while(r != 0){a = b; b = r; r = a % b;}return lcm /= b;}
// a,bの最大公約数
ll GCD(ll a, ll b){ll r = a % b;while(r != 0){a = b; b = r; r = a % b;}return b;}
// MOD
ll modadd(ll a, ll b){return (a%MOD+b%MOD+MOD)%MOD;}
ll modmul(ll a, ll b){return a%MOD*b%MOD%MOD;}
ll modexp(ll a, ll n){if(n==0)return 1; if(n%2==0){ll e=modexp(a,n/2); return modmul(e,e);} return modexp(a,n-1)*a%MOD;}
ll modinv(ll n){return modexp(n%MOD,MOD-2);}
ll modfact(ll n){ll res=1; for (int i=1; i <= n; ++i){res *= i; res %= MOD;} return res;}
ll modncr(ll n, ll r){ll numer=1;ll denom=1;for(int i=1;i<=r;++i){numer=modmul(numer,n-r+i);denom=modmul(denom,i);}return modmul(numer, modinv(denom));}


int main(){
    
    int h, w;
    cin >> h >> w;
    char cell[h][w];
    rep(i,h) {
        rep(j,w) {
            cin >> cell[i][j];
        }
    }

    bool flag_h[h];
    rep(i,h) flag_h[i] = true;
    bool flag_w[w];
    rep(i,w) flag_w[i] = true;

    rep(i,h) {
        bool line = true;
        rep(j,w) {
            if (cell[i][j] != '.') line = false;
        }
        if (line) flag_h[i] = false;
    }

    rep(j,w) {
        bool line = true;
        rep(i,h) {
            if (cell[i][j] != '.') line = false;
        }
        if (line) flag_w[j] = false;
    }

    rep(i,h) {
        if(flag_h[i]) {
            rep(j,w) {
                if (flag_w[j]) cout << cell[i][j];
            }
            cout << endl;
        }
    }


}





//              g++ -std=c++1z


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 30;
 
int main() {
	int n;
	cin >> n;
	int m = 0;
	rep(i, n) {
		int h; cin >> h;
		if (h < m) {
			cout << "No" << endl;
			return 0;
		}
		m = max(m, h-1);
	}
	cout << "Yes" << endl;
	return 0;
	
	return 0;
}

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

int main(){
	int n; cin>>n;
	if(n % 4 == 0 || n % 7 == 0){
		cout<<"Yes\n";
	}
	else{
		for(int i = 1; i <= n; i++){
		if(n - i * 4 >= 0 && (n - i * 4 ) % 7 == 0){
			puts("Yes");
			return 0;
		}
	}
	puts("No");
}
}


Measured memory_bytes: 256
/*BISMILLAH
THE WHITE WOLF
NO DREAM IS TOO BIG AND NO DREAMER IS TOO SMALL*/

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<long long> vll;
typedef vector<int> vi;

#define io ios_base::sync_with_stdio(false)
#define pb push_back
#define eb emplace_back
#define mod  1000000007
#define PI 2*acos(0.0)
#define maxn 10000005

int main()
{
    io;
    int n, m, k;
    cin>>n>>m>>k;
    vi a(n), b(m);
    for(auto& x: a)cin>>x;
    for(auto& x: b)cin>>x;
    ll sum = 0;
    for(auto x: a)
        sum += x;
    int atak = n, btak = 0, ans = 0;
    while(77)
    {
        if(sum <= k)
        {
            ans = max(ans, atak + btak);
            if(btak< m)
            {
                sum += b[btak];
                btak++;
            }
            else
                break;
        }
        else
        {
            if(atak == 0)
                break;
            atak--;
            sum -= a[atak];
        }
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 4800
#include <vector>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;



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

  vector<int> H(N);
  for (int i = 0; i < N; i++)
    cin >> H[i];

  int highest = H[0];
  for (int i = 1; i < N; i++){
    if (highest < H[i]) {
      highest = H[i];
      continue;
    }

    if ((highest - H[i]) >= 2){
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;
}


Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<climits>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<iomanip>
using namespace std;

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define rep2(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()
#define INF 1e9

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<int, int> pi;
typedef long long i64;

int main() {
	string ans;
	rep(i, 0, 3) {
		string s;
		cin >> s;
		transform(all(s), s.begin(), ::toupper);
		ans += s[0];
	}
	cout << ans << endl;
}

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

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        for (;;) {
            String[] s = sc.nextLine().split(" ");
            int n = s.length;
            int[] l = new int[n];
            for (int i = 0; i < n; i++) {
                l[i] = Integer.parseInt(s[i]);
            }
            if (l[0] ==0)
                break;
            Arrays.sort(l);
            int sum = 0;
            for (int i = n - 1; i >= 0; i--) {
                if (l[i] > 10) {
                    sum += 10;
                } else if (l[i] == 1) {
                    if (i == 0 && sum <= 10) {
                        sum += 11;
                    } else {
                        sum += 1;
                    }
                } else {
                    sum += l[i];
                }
                if (sum > 21) {
                    sum = 0;
                    break;
                }
            }
            System.out.println(sum);
        }
    }
}


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

const int INF = 1000000007;
const int MOD = 1000000007;

typedef long long ll;
typedef pair<int, int> pr;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    while(true){
        int x, y, s;
        cin >> x >> y >> s;
        if((x|y|s) == 0) break;
        int ans = -1;
        for(int i = 1; i < s; i++){
            int p1 = i;
            int tp1 = p1 * (100 + x) / 100;
            int p2 = ceil((s - tp1) * 100.0 / (100 + x));
            if(p2 <= 0) continue;
            if(tp1 + p2 * (100 + x) / 100 != s) continue;
            ans = max(ans, p1 * (100 + y) / 100 + p2 * (100 + y) / 100);
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1196
#include<bits/stdc++.h>
using namespace std;
const int N=200005;
int n,a[N];
long long ans;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		if(a[i]<a[i-1])
		{
			ans+=a[i-1]-a[i];
			a[i]=a[i-1];
		}
	}
	printf("%lld\n",ans);
	return 0;
}

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

using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()

template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) {
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }

template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
  for(T& x: vec) {is >> x;} return is;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'['; for(T i: a) {out<<i<<',';} out<<']'; return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;

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

  ll n;
  cin >> n;
  vector<ll> a(n);
  map<ll,ll> mp, cnt;
  REP(i, n) {
    cin >> a[i];
    mp[a[i]]++;
    cnt[a[i]]++;
  }

  vector<ll> pow2(31);
  pow2[0] = 1;
  FOR(i, 1, 31) pow2[i] = pow2[i-1] * 2;

  sort(ALL(a));
  a.erase(unique(ALL(a)), a.end());
  reverse(ALL(a));

  ll ret = 0;
  REP(i, n) {
    REP(j, 31) {
      if(pow2[j] < a[i]) continue;
      if(a[i]*2 == pow2[j]) {
        ll tmp = mp[a[i]] / 2;
        mp[a[i]] -= tmp * 2;
        ret += tmp;
        continue;
      }
      if(mp.find(pow2[j] - a[i]) != mp.end()) {
        ll tmp = min(mp[pow2[j] - a[i]], mp[a[i]]);
        mp[pow2[j] - a[i]] -= tmp;
        mp[a[i]] -= tmp;
        ret += tmp;
      }
    }
//    cout << "i=" << i << " " << ret << endl;
  }

  cout << ret << endl;

  return 0;
}


Measured memory_bytes: 26880
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<ll, ll> P;
 
const ll MOD = 1e9 + 7;
const ll inf = 1LL<<60;
const int int_inf = 100000000;
const double eps = 1e-9;
 
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
 
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
 
int score[50][50] = {};
bool visited[50][50] = {false};
 
int main()
{
    int h, w, cnt = 0;
    cin >> h >> w;
 
    char grid[h][w];
 
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cin >> grid[i][j];
            if (grid[i][j] == '#') cnt++;
        }
    }
    
    score[0][0] = 1;
 
    queue< pair<int, int> > que;
    que.push(make_pair(0, 0));
 
    while (!que.empty()) {
        auto now = que.front();
        que.pop();
 
        int now_x = now.first;
        int now_y = now.second;
 
        for (int i = 0; i < 4; i++) {
            int nx = now_x + dx[i];
            int ny = now_y + dy[i];
 
            if (nx < 0 or nx >= h or ny < 0 or ny >= w) continue;
            if (grid[nx][ny] == '#') continue;
            if (!visited[nx][ny]) {
                score[nx][ny] = score[now_x][now_y] + 1;
                que.push(make_pair(nx, ny));
                visited[nx][ny] = true;
            }
        }
    }
 
    if (!visited[h-1][w-1]) cout << -1 << endl;
    else cout << h * w - cnt - score[h-1][w-1] << endl;
 
    return 0;
}
 

Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd, log
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

N = INT()
A = [LIST() for _ in range(N)]

match = defaultdict(int)
cnt = 0
for i, j in combinations(range(N), 2):
	match[(i, j)] = cnt
	match[(j, i)] = cnt
	cnt += 1

V = N*(N-1)//2
graph = [[] for _ in range(V)]
dag = [0]*V
for i in range(N):
	for j in range(N-2):
		graph[match[(i, A[i][j]-1)]].append(match[(i, A[i][j+1]-1)])
		dag[match[(i, A[i][j+1]-1)]] += 1

q = deque([i for i in range(V) if dag[i]==0])
day = [1]*V
ans = 1

while q:
	p = q.popleft()
	for v in graph[p]:
		dag[v] -= 1
		if dag[v] == 0:
			day[v] = day[p]+1
			ans = day[v]
			q.append(v)


if any(dag):
	print(-1)
else:
	print(ans)




Measured memory_bytes: 282124
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0].split(" ")[0]);
    const M = parseInt(arg[0].split(" ")[1]);
    
    const ab = arg.slice(1, M + 1).map(n=>n.split(" ").map(l=>parseInt(l)));
    
    // グラフ用の2次元配列を作る
    const mx = [...Array(N)].map(n=>[...Array(N)].fill(0));
    
    for(let i in ab) {
        const from = ab[i][0] - 1;
        const to   = ab[i][1] - 1;
        
        mx[from][to] = 1;
        mx[to][from] = 1;
    }
    
    let sum = 0;

    const dfs = (v, visited) => {
        if (visited.every(v=>v===true)) sum++;
        
        for (let i=0; i<N; i++) {
          if (mx[v][i] === 0) continue;
          if (visited[i]) continue;
        
          visited[i] = true;
          dfs(i, visited);
          visited[i] = false;
        }
        
        return;
    }
    
    const visited = [true, ...[...Array(N - 1)].map(n=>false)];
    dfs(0, visited);
    
    console.log(sum);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7988
#include<cstdio>
#include<bits/stdc++.h>
typedef long long int ll;
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOR_IN(i, a, b) for(int i = (a); i < (b); i++)
#define BETWEEN(x, a, b) ((x) >= (a) && (x) <= (b))
#define BIT(b, i) (((b) >> (i)) & 1)
#define LOG_F 1
#define LOG(...) if(LOG_F) fprintf(stderr, __VA_ARGS__)

using namespace std;

ll pow(int x, int n){
  return n == 0 ? 1 : x * pow(x, n - 1);
}


/*
n k
a1 ... an

n 10^5
k 10^12
ai 10^12
 */
int n;
ll k,a[100000];

int main(){
  cin>>n>>k;
  REP(i,n)
    cin>>a[i];

  sort(a, a+n);
  int la = floor(log(a[n-1])/log(2));
  LOG("a[n-1]=%lld, log = %f\n", a[n-1], floor(log(a[n-1])/log(2)));
  int lk = floor(log(k)/log(2));
  int l = max(la,lk);

  unsigned long long ans=0;
  ll x=0;
  for(int i = l; i>=0; i--){
    sort(a, a+n);
    int j = a+n - lower_bound(a, a+n, pow(2,i));
    if(2*j <= n && x + (pow(2,i)) <= k){
      x += pow(2,i);
      ans += (n-j) * (pow(2,i));
      LOG("i = %d, j = %d, x = %lld, ans = %lld\n",i, j, x, ans);
    } else {
      ans += j * (pow(2,i));
      LOG("i = %d, j = %d, x = %lld, ans = %lld\n",i, j, x, ans);
    }
    FOR_IN(cnt,n-j,n){
      a[cnt] -= (pow(2,i));
    }
  }
  
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline int rd(){
    int x=0,fl=1;char ch=gc();
    for (;ch<48||ch>57;ch=gc())if(ch=='-')fl=-1;
    for (;48<=ch&&ch<=57;ch=gc())x=(x<<3)+(x<<1)+(ch^48);
    return x*fl;
}
inline void wri(int a){if(a<0)a=-a,putchar('-');if(a>=10)wri(a/10);putchar(a%10|48);}
inline void wln(int a){wri(a);puts("");}
const int N=200002;
int h,w,n,sx,sy,x,y,i;
char s1[N],s2[N];
int main(){
	scanf("%d%d%d%d%d%s%s",&h,&w,&n,&sx,&sy,s1+1,s2+1);
	x=sx,y=sy;
	for (i=1;i<=n;i++){
		if (s1[i]=='L'){
			y--;
			if (!y) return puts("NO"),0;
		}
		if (s2[i]=='R') y++,y=min(y,w);
	}
	x=sx,y=sy;
	for (i=1;i<=n;i++){
		if (s1[i]=='R'){
			y++;
			if (y>w) return puts("NO"),0;
		}
		if (s2[i]=='L') y--,y=max(y,1);
	}
	x=sx,y=sy;
	for (i=1;i<=n;i++){
		if (s1[i]=='U'){
			x--;
			if (!x) return puts("NO"),0;
		}
		if (s2[i]=='D') x++,x=min(x,h);
	}
	x=sx,y=sy;
	for (i=1;i<=n;i++){
		if (s1[i]=='D'){
			x++;
			if (x>h) return puts("NO"),0;
		}
		if (s2[i]=='U') x--,x=max(x,1);
	}
	puts("YES");
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <ctype.h>
#include <ios> 
#include <iomanip>
using namespace std;

#define N_MAX   (100000)
#define LL_MAX_NUM (1LL<<60)
#define INF 1e7

typedef long long ll;
typedef long long int lli;

int main() {
    int H, W; cin >> H >> W;
    int Hp = H + 2;
    int Wp = W + 2;
    char frame = '#';
    for (int i = 0; i < Hp; i++)
    {
        for (int j = 0; j < Wp; j++)
        {
            if (i==0 || i== Hp-1 || j==0 || j== Wp-1)
            {
                cout << frame;
            }
            else
            {
                char a; cin >> a;
                cout << a;
            }
        }
        cout << endl;
    }
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;
#define int long long
#define pb push_back
#define fi first
#define se second
#define fr(i, a, b) for(int i = a; i <= b; i++)
#define all(x) x.begin(), x.end()
#define IO ios :: sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define pii pair<int,int>
#define sz(x) (int)x.size()
const int mod = 1e9 + 7;
const int mod1 = 998244353;
typedef long double f80;

#ifndef LOCAL
#pragma GCC optimize ("O2")
#define endl '\n'
#endif

template<typename T>
using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rand(int l, int r){
    uniform_int_distribution<int> uid(l, r);
    return uid(rng);
}

ll pwr(ll a,ll b, ll mod){
    a %= mod;
    int ans = 1;
    while(b){
        if(b & 1) ans = (ans * a) % mod;
        a = (a * a) % mod;
        b >>= 1;
    }
    return ans;
}

string to_string(string s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

const int N = 5e5 + 5;
int a[N], pre[N];
int dp[N];
map<int,int> m, m1;
void solve(){
	int n;
	cin >> n;
	fr(i, 1, n){
		cin >> a[i];
		pre[i] = pre[i - 1] ^ a[i];
	}
	int ans = 0;
	if(pre[n] != 0){ // xor != 0 and odd partitions ...
		int s0 = 1, s1 = 0;
		int val = pre[n];
		fr(i, 1, n){
			if(pre[i] == val){
				dp[i] = s0;
				s1 += dp[i];
				s1 %= mod;
			}
			else if(pre[i] == 0){
				dp[i] = s1;
				s0 += dp[i];
				s0 %= mod;
			}
		}
		cout << dp[n] << endl;
		return;
	}
	// xor = 0
	int c = 0;
	fr(i, 1, n - 1){
		if(pre[i] == 0)
			c++;
	}
	ans = pwr(2, c, mod);
	// xor != 0
	int c0 = 1;
	m[0] = 1;
	dp[0] = 1;
	fr(i, 1, n){
		if(pre[i] == 0){
			c0++;
		}
		else{
			dp[i] = (m1[pre[i]] * c0 - m[pre[i]] + mod + 1) % mod;
			ans += dp[i];
			ans %= mod;
			m[pre[i]] += c0 * dp[i];
			m[pre[i]] %= mod;
			m1[pre[i]] += dp[i];
			m1[pre[i]] %= mod;
		}
	}
	cout << ans;
}
signed main(){
    IO;
    #ifdef LOCAL
        freopen("inp.txt","r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
    cout << setprecision(10) << fixed;
    int t = 1;
    // cin >> t;
    fr(tt, 1, t){
        solve();
    }
    return 0;
}

Measured memory_bytes: 47872
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REPR(i, n) for(int i = (n); i >= 0; i--)
#define FOR(i, m, n) for(int i = (m); i < (n); i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << ": " << x << endl;

using namespace std;
typedef long long ll;

signed main() {
  char b;
  cin >> b;
  if(b == 'A') {
    cout << 'T' << endl;
  } else if(b == 'T') {
    cout << 'A' << endl;
  } else if(b == 'C') {
    cout << 'G' << endl;
  } else {
    cout << 'C' << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict
inf=float('inf')
mod = 10**9+7
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N = I()
    A = set()
    for _ in range(N):
        a = I()
        if a in A:
            A.remove(a)
        else:
            A.add(a)
    print(len(A))
if __name__ == '__main__':
    main()

Measured memory_bytes: 46556