akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <queue>
#include <limits>
#include <algorithm>
#include <string>
#include <set>
#include <map>
using namespace std;


int main()
{
	int64_t W, H, x, y;
	cin >> W >> H >> x >> y;

	double space = W * H / 2.0;

	int32_t way = (W % 2 == 0 && W / 2 == x && H % 2 == 0 && H / 2 == y) ? 1 : 0;

	cout << fixed << std::setprecision(std::numeric_limits<double>::max_digits10) << space << " " << way << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
const int INF=1001001000;
const int mINF=-1001001000;
int main(){
    string s,t;cin >> s >> t;
    int a,b; cin >> a >> b;
    string u;cin >> u;
    if(u==s) a--;
    else b--;
    cout << a << " " << b << endl;
}

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


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

struct edge {int to; ll cost; };

int dx[] = {-1, 1, 0,  0};
int dy[] = { 0, 0, 1, -1};
 
int main(){
  ll n;
  cin >> n;
  ll ans = 0;
  if(n%2) ans = 0;
  else{
    ll tmp = 5;
    while(n>=tmp){
      ans += n/tmp/2;
      tmp *= 5;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3616
#include <stdio.h>

int main(void)
{
  int n;
  float w,h;
  while(scanf("%d,%f,%f",&n,&w,&h)!=EOF){
    float bmi;
    bmi=w/(h*h);
    if(bmi>=25){
      printf("%d\n",n);}
  }

  return 0;
}

Measured memory_bytes: 624
#include<bits/stdc++.h>
using namespace std;
int main(){
  string S;cin>>S;
  int N=S.length();
  int l=0,r=N-1;
  int ans=0;
  while(l<r){
    if(S[l]==S[r]){l++;r--;}
    else{
      if(S[l]=='x'){ans++;l++;}
      else if(S[r]=='x'){ans++;r--;}
      else {
        cout<<-1;
        return 0;
      }
    }
  }
  cout<<ans;
}

Measured memory_bytes: 512
main = do
    _ <- getLine
    s <- getLine
    let ps = map read $ words s :: [Int]
    let ans = count ps
    print ans

count :: [Int] -> Int
count ps
    | length ps < 3 = 0
    | otherwise = do
        let countup = (p1 < p2 && p2 < p3) || (p1 > p2 && p2 > p3)
        let base = if countup then 1 else 0
        base + count (p2:p3:rest)
    where
        p1:p2:p3:rest = ps


Measured memory_bytes: 508
#include <stdio.h>

int main() {
  int H, W;
  int h, w;
  scanf("%d %d", &H, &W);
  while(H != 0 || W != 0) {
    for(h = 0; h < H; h++) {
      for(w = 0; w < W; w++) {
        if((w + h) % 2 == 0) printf("#");
        else printf(".");
      }
      printf("\n");
    }
    printf("\n");
    scanf("%d %d", &H, &W);
  }
  return 0;
}

Measured memory_bytes: 2576
# ARC090C - Candies (ABC087C)
def main():
    N = int(input())
    A = tuple(tuple(map(int, input().rstrip().split())) for _ in range(2))
    ans = {sum(A[0][: i + 1]) + sum(A[1][i:]) for i in range(N)}
    print(max(ans))


if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
n=int(input())
a=[]
ans=0
ANS=0
A=0
import itertools
for i in range(n):
    x,y=map(int,input().split())
    a.append([x,y])
for v in itertools.permutations(a, n):
    A+=1
    for i in range(n-1):
        ans+=((list(v)[i][0]-list(v)[i+1][0])**2+(list(v)[i][1]-list(v)[i+1][1])**2)**0.5
print(ans/A)

Measured memory_bytes: 3188
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


# a^n
def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a


inf = 10 ** 18
mod = 10 ** 9 + 7

n = ir()
f = [lr() for i in range(n)]
p = [lr() for i in range(n)]
ans = -inf
for i in range(1,2**10):
    pre = 0
    num = [0 for k in range(n)]
    for j in range(10):
        if (i >> j) & 1:
            for k in range(n):
                num[k] += f[k][j]
    for j in range(n):
        pre += p[j][num[j]]
    ans = max(ans, pre)
print(ans)

Measured memory_bytes: 79444
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <string.h>
#include <string>
#include <complex>
using namespace std;

#define INT_max 2147483647


typedef long long ll;
typedef long double ld;


int main(){
	int n,s;
	cin>>n;
	vector<ll> mp(n+1,0);
	vector<int> num(n);
	ll sum = 0;
	for(int i = 0;i < n;i++){
		cin>>num[i];
		sum += mp[num[i]];
		mp[num[i]]++;
	}
	for(int i = 0;i < n;i++){
		cout<<sum-mp[num[i]]+1<<endl;
	}
	return 0;
}

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

const int INF = 1 << 29;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main() {
    int N, x[200], y[200], w, h;
    while (true) {
        cin >> N;
        if (N == 0) break;
        x[0] = y[0] = 0;
        for (int i = 1; i < N; ++i) {
            int n, d;
            cin >> n >> d;
            x[i] = x[n] + dx[d];
            y[i] = y[n] + dy[d];
        }
        int min_x = INF, max_x = -INF,
            min_y = INF, max_y = -INF;
        for (int i = 0; i < N; ++i) {
            min_x = min(min_x, x[i]);
            max_x = max(max_x, x[i]);
            min_y = min(min_y, y[i]);
            max_y = max(max_y, y[i]);
        }
        cout << (max_x - min_x + 1) << " " << (max_y - min_y + 1) << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
#include "bits/stdc++.h"
using namespace std;


int main() {
    int n;
    scanf("%d", &n);
    vector<int> h(n);
    for(int& x : h) {
        scanf("%d", &x);
    }
    vector<int> dp(n, INT_MAX);
    dp[0] = 0;
    dp[1] = abs(h[1]-h[0]);
    
    for(int i=2;i<n;i++) {
        dp[i] = min((dp[i-1] + abs(h[i] - h[i-1])), 
                    (dp[i-2] + abs(h[i] - h[i-2])));
    }

    printf("%d\n", dp[n-1]);
}

Measured memory_bytes: 4064
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    s = input()
    ok = [{"N", "S"}, {"E", "W"}, {"N", "S", "E", "W"}]
    if set(s) in ok:
        print("Yes")
    else:
        print("No")


if __name__ == '__main__':
    main()


Measured memory_bytes: 61948
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#include<queue>
#include<stack>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)

using namespace std;

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

    int A, B;
    cin >> A >> B;
    cout << max(A+B, max(A-B, A*B)) << endl;
}

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

int main(void) {
  	int N, tmp;
  	cin >> N;
  	tmp = N;
  	int digits = 0;
  	while(0 < N){
    	digits += N % 10;
        N /= 10;
    }
  	if((tmp % digits) == 0){
    	cout << "Yes" << endl;
    }else{
    	cout << "No" << endl;
    }
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
 using namespace std ;
 int main()
{
short int a,b,c,d;

cin>>a;
cin>>b;
cin>>c;
cin>>d;
if((abs(c-a))<=d) cout<< "Yes";
else
 if((abs(c-b)<=d)&& ( abs(b-a)<=d) ) cout<< "Yes";
else
cout<< "No";
}

Measured memory_bytes: 3132
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;
 
public class Main {
	private static FastScanner sc = new FastScanner();
	
	public static void main(String[] args) {
		int n = sc.nextInt();
		int[] a = new int[n];
		for(int i=0; i<n; i++) {
			a[i] = sc.nextInt();
		}
		
		int[] dp = new int[n];
		for(int i=0; i<n; i++) {
			dp[i] = Integer.MAX_VALUE;
		}
		
		for(int i=0; i<n; i++) {
			int l = 0;
			int r = n-1;
			int m = 0;
			while(l <= r) {
				m = (l + r) / 2;
				if(dp[m] >= a[i]) {
					if(m-1 >= 0 && dp[m-1] < a[i]) {
						break;
					} else {
						r = m-1;
					}
				} else {
					if(m+1 <= n-1 && dp[m+1] >= a[i]) {
						m++;
						break;
					} else {
						l = m+1;
					}
				}
			}
			
//			System.out.println(m + " " + i);
			dp[m] = a[i];
		}
		
		int i=0;
		for(; i<n; i++) {
			if(dp[i] == Integer.MAX_VALUE) {
				break;
			}
		}
		System.out.println(i);
	}
	
	static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte() {
            if(ptr < buflen) {
                return true;
            } else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch(IOException e) {
                    e.printStackTrace();
                }
                if(buflen <= 0) {
                    return false;
                }
            }
            return true;
        }
        private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
        private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
        private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
        public boolean hasNext() { skipUnprintable(); return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public long nextLong() {
            return Long.parseLong(next());
        }
        public int nextInt(){
            return Integer.parseInt(next());
        }
        public double nextDouble(){
            return Double.parseDouble(next());
        }
    }
}

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

using namespace std;

#define MAX_N 100000
#define SEG_LEN 500 
#define MOD 100000

int n, m;

int dist[MAX_N] = {};
int seg[MAX_N/SEG_LEN] = {};

int dist_mod(int from, int to) {
	if (from > to) swap(from, to);

	int total_dist = 0;
	if (to - from < SEG_LEN) {
		for (int i = from; i < to; i++) {
			total_dist += dist[i];
			if (total_dist > MOD) total_dist -= MOD;
		}
		return total_dist;
	}
	int seg_from, seg_to;
	if (from % SEG_LEN == 0) seg_from = from / SEG_LEN;
	else seg_from = from / SEG_LEN + 1;
	if (to % SEG_LEN == 0) seg_to = to / SEG_LEN;
	else seg_to = to / SEG_LEN;

	for (int i = from; i < seg_from * SEG_LEN; i++) {
		total_dist += dist[i];
		if (total_dist > MOD) total_dist -= MOD;
	}
	for (int i = seg_from; i < seg_to; i++) {
		total_dist += seg[i];
		if (total_dist > MOD) total_dist -= MOD;
	}
	for (int i = seg_to * SEG_LEN; i < to; i++) {
		total_dist += dist[i];
		if (total_dist > MOD) total_dist -= MOD;
	}

	return total_dist;
}

int main() {
	int n, m;
	cin >> n >> m;
	for (int i = 0; i < n-1; i++) {
		cin >> dist[i];
		seg[i/SEG_LEN] += dist[i];
	}
	int cur = 0;
	int total_dist = 0;
	for (int i = 0; i < m; i++) {
		int q; cin >> q;
		total_dist += dist_mod(cur, cur+q);
		cur += q;
		if (total_dist > MOD) total_dist -= MOD;
	}
	cout << total_dist << endl;
	return 0;
}

Measured memory_bytes: 1232
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long 
int change[120];
string T = "MARCH";
string S[100010];
signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    
    rep(i, N) cin >> S[i];
    rep(i, 5) {
        change[T[i]] = i;
    }
    int cnt[5] = {};
    rep(i, N) {
        rep(j, 5) {
            if (T[j] == S[i][0]) cnt[change[T[j]]]++;
        }
    }
    // rep(i, 5) {
    //     cout << cnt[i] << endl;
    // }
    int ans = 0;
    rep(i, 5) {
        REP(j, i + 1, 4) {
            REP(k, j + 1, 4) {
                ans += cnt[i] * cnt[j] * cnt[k];
            }
        }
    }
    cout << ans << endl;


    return 0;
}


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

int main(){
    int a,b,c;  cin>>a>>b>>c;
    int min=a+b;
    if(min>a+c)
        min=a+c;
    if(min>b+c)
        min=b+c;
    cout<<min<<endl;
    
}

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

int	main()
{
	int	A, B, C, D;
	cin >> A >> B >> C >> D;
	while (A > 0 && C > 0) {
		C -= B;
		if (C <= 0) break;
		A -= D;
		if (A <= 0) break;
	}
	if (C <= 0)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}


Measured memory_bytes: 3636
import java.io.*;
import java.math.*;
import java.util.*;

import static java.util.Arrays.fill;
import static java.lang.Math.*;
import static java.util.Arrays.sort;
import static java.util.Collections.sort;

public class Main {
	static int mod = 1000000007;
	static InputReader in = new InputReader(System.in);
	static PrintWriter out = new PrintWriter(System.out);

	public static void main(String[] args) {

		int a=in.nextInt();
		int b=in.nextInt();
		for(int i=1;i<=3;i++)
		{
			if((a*b*i)%2==1)
			{
				System.out.println("Yes");
				return;
			}
		}
		System.out.println("No");
		out.close();

	}

	static class InputReader {
		private final InputStream stream;
		private final byte[] buf = new byte[8192];
		private int curChar, snumChars;

		public InputReader(InputStream st) {
			this.stream = st;
		}

		public int read() {
			if (snumChars == -1)
				throw new InputMismatchException();
			if (curChar >= snumChars) {
				curChar = 0;
				try {
					snumChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (snumChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public int nextInt() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public long nextLong() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public String readString() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public String nextLine() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndOfLine(c));
			return res.toString();
		}

		public boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		private boolean isEndOfLine(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}
	}

	private static void tr(Object... o) {
		if (!(System.getProperty("ONLINE_JUDGE") != null))
			System.out.println(Arrays.deepToString(o));
	}
}




Measured memory_bytes: 22612
import java.io.{BufferedOutputStream, BufferedReader, InputStreamReader, PrintWriter}

import scala.collection.mutable

object Main {
  def main(args: Array[String]): Unit = {
    val in = new BufferedReader(new InputStreamReader(System.in))
    val out = new PrintWriter(new BufferedOutputStream(System.out))
    val s = in.readLine().toList.map(_.toInt - '0').reverse
    val MOD = 2019

    val remainders = s.scanLeft((0, 1)) {
      case ((acc, base), c) =>
        ((acc + base * c) % MOD, base * 10 % MOD)
    }.map(_._1)

    val remainderMap = remainders.foldLeft(mutable.HashMap.empty[Int, Long]) {
      case (acc, remainder) =>
        acc.update(remainder, acc.getOrElse(remainder, 0L) + 1L)
        acc
    }

    out.println(
      remainderMap.foldLeft(0L) {
        case (acc, (_, count)) =>
          acc + count * (count - 1) / 2
      }
    )

    out.flush()
  }
}


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

int main() {
  int a;
  cin>>a;
  vector<int> vec(2*a);
  for(int i=0;i<2*a;i++){
    cin>>vec.at(i);
  }
  sort(vec.begin(),vec.end());
  int count=0;
  for(int i=0;i<a;i++){
    count+=vec.at(2*i);
  }
  cout<<count<<endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<vector>
#include<deque>
#include<stack>
#include<queue>
#include<string>
#include<iostream>
#include<tuple>
#include<utility>
#include<set>
#include<queue>
#include<iomanip>
#include<iterator>
#include<map>
#include<bitset>
#include<array>
#include<cmath>
//#include<chrono>
//cout<<setprecision(12)
//fixed
//#include<random>
//14348907
using namespace std;
typedef long long int llint;
typedef long double lldo;
const llint big=1e9+100000;
const llint mod=1e9+7;
const lldo eps=1e-7;
const long double pai=3.141592653589793238462643;
#define mt make_tuple
#define mp make_pair
#define fir first
#define sec second
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define res resize
#define ins insert
#define era erase
#define dme(in) cout<<in<<endl;return 0
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
int main(void){
	ios::sync_with_stdio(false);
	llint n,d;cin>>n>>d;
	llint i,j;
	static pair<llint,llint>mae[14348907];//????????¨??????
	static pair<llint,llint>ato[14348907];//????????¨?????? pair<?????´??????,??´??????>
	llint maesu=1,atosu=1;
	mae[0]=mp(0LL,0LL);
	ato[0]=mp(0LL,0LL);
	for(i=0;i<n/2;i++){
		llint x,y;
		cin>>x>>y;
		for(j=0;j<maesu;j++){
			mae[j+maesu]=mp(mae[j].fir+x,mae[j].sec+y);
			mae[j+maesu+maesu]=mp(mae[j].fir-x,mae[j].sec-y);
		}
		maesu*=3;
	}
	for(i=n/2;i<n;i++){
		llint x,y;
		cin>>x>>y;
		for(j=0;j<atosu;j++){
			ato[j+atosu]=mp(ato[j].fir+x,ato[j].sec+y);
			ato[j+atosu+atosu]=mp(ato[j].fir-x,ato[j].sec-y);
		}
		atosu*=3;
	}
	sort(mae,mae+maesu);
	sort(ato,ato+atosu);
	deque<pair<llint,llint>> que;//????????????????°?????????????,
	llint dco=0;
	llint ans=0;
	for(i=0;i<maesu;i++){
		llint ki=mae[i].fir;
		llint ka=mae[i].sec;
		//ki-d<=??????<=ki+d
		//ka-(que???????°?) ????????§???
		while(dco<atosu&&ato[dco].fir<=ki+d){
			while((!que.empty())&&que.back().sec>=ato[dco].sec){que.pob();}
			que.pub(ato[dco]);
			dco++;
		}
		while((!que.empty())&&que.front().fir<ki-d){que.pof();}
		if(!que.empty()){maxeq(ans,ka-que.front().sec);}
	}
	cout<<ans<<endl;
	return 0;
}

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

int main(){
  int n, a, b, c, d;
  string s;
  cin >> n >> a >> b >> c >> d;
  a--; b--; c--; d--;
  cin >> s;

  bool psb = true;
  for (int i = a; i < max(c, d); i++){
    if (s.at(i) == '#'){
      if (s.at(i + 1) == '#') psb = false;
    }
  }

  if (!psb){
    cout << "No" << endl;
    return 0;
  }

  if (d < c){
    psb = false;
    for (int i = b; i <= d; i++){
      if (s.at(i - 1) == '.' && s.at(i) == '.' && s.at(i + 1) == '.'){
        psb = true;
        break;
      }
    }
  }

  cout << (psb ? "Yes" : "No") << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<tuple>
#include<vector>
#include<map>
using namespace std;

static const int MAX_N = 110;

int main(void){
  long long int N, x;
  long long int a[MAX_N];
  cin >> N >> x;
  for(int i = 0; i < N; i++){
    cin >> a[i];
  }
  long long int asum = 0;
  for(int i = 0; i < N; i++){
    asum += a[i];
  }
  sort(a, a + N);
  //全員のaiのsumがxと一致する場合：全員OK
  if(asum == x){
    cout << N << endl;
  }
  //全員のaiのsum < x　の場合: N-1人
  else if(asum < x){
    cout << N - 1 << endl;
  }
  //全員のaiのsum > x　の場合：xギリギリまでとってそれ以降は捨てる。
  else if(asum > x){
    long long int tempsum = 0;
    int cnt = 0;
    for(int i = 0;tempsum <= x;i++){
      tempsum += a[i];
      cnt = i;
    }
    cout << cnt << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    
    int n,m,x,i;
    int fee[100];
    int low=0,high=0;
    
    scanf("%d %d %d",&n,&m,&x);
    
    for(i=0;i<m;i++){
        scanf("%d",&fee[i]);
        if(fee[i]<x){
            low++;
        }else{
            high++;
        }
    }
    
    if(low>high){
        printf("%d\n",high);
    }else{
        printf("%d\n",low);
    }
    
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll mod=1000000007;
int main() {
ll n,m;
cin>>n>>m;
ll aa=1;
if(abs(n-m)>=2){
cout<<0<<endl;}
else{
for(ll i=1; i<=n; i++){
aa=(aa*i)%mod;}
for(ll i=1; i<=m; i++){
aa=(aa*i)%mod;}
if(n==m)
aa=(aa*2)%mod;
cout<<aa<<endl;}}


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

typedef long long ll;

int main() {
    string S;
    cin >> S;
    int L = S.length();
    ll ans = 0;
    for (int i=0;i<(1<<(L-1));i++){
        vector<int> plus(L-1);
        for (int j=0;j<L-1;j++){
            if (i>>j & 1) plus[j] = 1;
        }
        int start = 0;
        int end = L;
        ll sum = 0;
        while (start < L){
            if (start == L-1) end = L-1;
            else {
                for (int i=start;i<L-1;i++){
                    if (plus[i] == 0 && i == L-2) {
                        end = L-1;
                        i = L-1;
                    }
                    if (plus[i] == 0) continue;
                    if (plus[i] == 1) {
                        end = i;
                        i=L-1;
                    }
                }
            }
            sum += stoll(S.substr(start,end-start+1),NULL,10);
            start = end + 1;
        }
        ans += sum;
    }
    cout << ans << endl;



    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<math.h>
#include<string>
using namespace std;

#define MAXN 100010


int main()
{
    int a,b;
    scanf("%d%d",&a,&b);
    if(a==b)
        printf("Draw\n");
    else if(b==1)
        printf("Bob\n");
    else if(a==1)
        printf("Alice\n");
    else if(a<b)
        printf("Bob\n");
    else
        printf("Alice\n");

    return 0;
}


Measured memory_bytes: 128
let split_on_char sep s =
  let open String in
  let r = ref [] in
  let j = ref (length s) in
  for i = length s - 1 downto 0 do
    if get s i = sep then begin
      r := sub s (i + 1) (!j - i - 1) :: !r;
      j := i
    end
  done;
  sub s 0 !j :: !r

let bfs vs n =
  let d = Array.make (n + 1) (-1) in
  d.(1) <- 0;
  let que = Queue.create () in
  Queue.add 1 que;
  while not (Queue.is_empty que) do
    let i = Queue.take que in
    List.iter (fun e ->
      if d.(e) = (-1) then begin
        d.(e) <- d.(i) + 1;
        Queue.add e que;
      end) vs.(i);
  done;
  d

let () =
  let n = read_int () in
  let vs = Array.make (n + 1) [] in
  for _ = 0 to n - 1 do
    match read_line () |> split_on_char ' ' |> List.map int_of_string with
    | u :: _ :: l -> vs.(u) <- l
    | _ -> assert false
  done;
  let d = bfs vs n in
  for i = 1 to n do
    Printf.printf "%d %d\n" i d.(i)
  done

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

struct query{ int v, d, c; };
vector<vector<int>> graph;
vector<vector<bool>> check;
vector<int> ans;

void DFS(int v, int d, int c){
    if(d < 0 || check[d][v] == true) return ;

    if(d == 0) ans[v] = c;
    check[d][v] = true;

    DFS(v, d-1, c);
    for(int adjacent_v : graph[v]){
        DFS(adjacent_v, d-1, c);
    }
}

int main(){
    int n, m;
    cin >> n >> m;

    graph.resize(n);
    for(int i=0; i<m; i++){
        int a, b;
        cin >> a >> b;
        a -= 1;
        b -= 1;

        graph[a].push_back(b);
        graph[b].push_back(a);
    }

    int q;
    cin >> q;

    vector<query> qs(q);
    for(int i=0; i<q; i++){
        cin >> qs[i].v >> qs[i].d >> qs[i].c;
        qs[i].v -= 1;
    }
    reverse(qs.begin(),qs.end());

    check.resize(11, vector<bool>(n));
    ans.resize(n);
    for(int i=0; i<q; i++){
        DFS(qs[i].v, qs[i].d, qs[i].c);
    }
    for(int i=0; i<n; i++){
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 10968
n = gets.chomp.to_i
values = gets.chomp.split(' ').map(&:to_i)
costs = gets.chomp.split(' ').map(&:to_i)
values_array = Array.new
costs_array = Array.new
n.times do |time|
  if values[time] > costs[time]
    values_array << values[time]
    costs_array << costs[time]
  else
    values_array << 0
    costs_array << 0
  end
end
p values_array.inject(:+) - costs_array.inject(:+)


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

using namespace std;

int N, a[309][309];

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d", &N);
for (int i=1; i<=N; i++)
    for (int j=1; j<=N; j++)
        scanf ("%d", &a[i][j]);
long long ans = 0;
for (int i=1; i<=N; i++)
    for (int j=1; j<=N; j++)
    {
        int mini = 2e9 + 1;
        for (int k=1; k<=N; k++)
        if (i != k && k != j)
        {
            if (a[i][j] > a[i][k] + a[k][j])
            {
                printf ("-1\n");
                return 0;
            }
            mini = min (mini, a[i][k] + a[k][j]);
        }
        if (mini > a[i][j])
            ans += a[i][j];
    }
printf ("%lld\n", ans / 2);
return 0;
}


Measured memory_bytes: 640
/*                        ______
 _______   /\     |``\   |        |  /
    |     /  \    |__/   |____    |/
    |    / _ _\   |  \   |        |\
    |   /      \  |   \  |______  |  \

            Dept. of CSE
        Comilla  University

*/
#include<bits/stdc++.h>
#define pi 2*acos(0.0)
#define ll long long
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Node struct node
#define spc " "
#define  E  2.71828182845904523536
#define pb push_back
#define pp pop_back
#define valid(nx,ny) nx>=0 && nx<n && ny>=0 && ny<m
#define e endl
#define pii pair<int,int>
#define infinity 10000000000000000
#define mod 1000000007
int fx[]={0,0,+1,-1};
int fy[]={+1,-1,0,0};

using namespace std;
///check n=1;
///check corner case;
map<ll,ll>check;
map<ll,ll>visit;
vector<ll>ans;

int main()
{
    ll n,i,j,cc=0;
    cin>>n;
    for(i=1;i<n;i++){
        cin>>j;
        check[j]++;
    }
    for(i=1;i<=n;i++)cout<<check[i]<<endl;

return 0;
}


Measured memory_bytes: 16148
#include <bits/stdc++.h>
#define MOD 1000000007
using ll = long long;
using namespace std;

int main()
{
	ll N, T;
	cin >> N >> T;
	vector<ll> D(N);
	for (int i = 0; i < N;i++) {
		cin >> D[i];
	}
	sort(D.begin(), D.end());
	ll res = 1;
	for (int i = 1; i < N;i++) {
		res = res * (i - (lower_bound(D.begin(), D.end(), D[i] - T) - D.begin()) + 1) % MOD;
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 3584
#include <cstdio>
int main(){
	while(1){
        int n,m;
        int num[51][51];
        int a,b;
	scanf("%d %d",&n,&m);
	if(!n) break;
	for(int i=1;i<=n;i++){
		num[i][0]=i;
	}
	for(int i=1;i<=m;i++){
		scanf("%d %d",&a,&b);
		for(int k=1;k<=b;k++){
			num[k][i]=num[a+k-1][i-1];
		}
		for(int k=b+1;k<=a+b-1;k++){
			num[k][i]=num[k-b][i-1];
		}
		for(int k=a+b;k<=n;k++){
			num[k][i]=num[k][i-1];
		}
	}
	printf("%d\n",n-num[1][m]+1);
	}
	return 0;
}

Measured memory_bytes: 1036
//Nihal Mittal - nihal_47
//Strike First , Strike Hard , No Mercy !!

/**⠀⠀⠀⠀⠀⠀⣀⣤⣤⣄⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⣠⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⣀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⣰⣿⣿⣿⣿⠿⠿⣿⣿⣿⣿⣿⣿⣿⣧⢀⠀⠀⠀⠀
⠀⠀⠀⣿⣿⣿⠋⠀⠀⠀⠀⠀⠙⠀⠙⣿⣿⣿⣷⢳⢀⠀⠀⠀
⠀⠀⣠⣿⣿⣿⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⣿⣿⣿⣿⢀
⠀⠀⣸⣿⣿⣿⠸⠀⠀⠀⠒⠒⠒⠐⠀⠀⢿⣿⣿⣿⣿⣿⠀⠀
⠀⣴⣿⣿⣿⡿⠀⠒⣋⣙⡒⢰⠀⠤⣖⠒⢾⣿⣿⣿⣿⣧⠀⠀
⢺⣿⣿⣿⣿⢀⠀⠀⠉⠉⠉⠸⠀⡇⠉⠉⠀⢿⣿⣿⣿⣄⠀⠀
⠀⠙⣿⣿⣧⢻⠀⠀⠀⠀⠀⠠⠀⠰⠀⠀⠀⣸⠸⣿⣿⠿⠰⠀
⠀⠀⠀⠹⣿⣿⣿⣷⠀⡠⠙⣲⣔⣅⢡⣰⣷⣿⣿⣿⣧⠀⠀⠀
⠀⠀⠀⣼⣿⣿⣿⣿⠀⡿⠭⠭⠭⠭⢿⠀⣿⢻⣿⣿⠃⠀⠀⠀
⠀⠀⠀⠙⠛⣿⢻⠹⣿⠐⠙⠛⠟⠉⢀⣴⡟⢿⣿⡏⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⡟⠀⠀⠻⣦⣤⣶⠾⠋⠀⠀⠁⡦⢄⢀⠀⠀⠀
⠀⠀⠀⠀⡠⠁⡇⠑⢄⠀⠀⠀⠀⠀⠀⠔⠀⠀⠁⠀⠀⠀⠉⠁
⠀⠔⠊⠁⠀⠀⣇⠀⠀⠀⠑⡤⠤⢎⠁⠀⠀⡘⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⢢⠠⠀⡠⢆⠀⠀⡠⠙⢄⠀⡸⠀
**/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define mk make_pair
#define pb push_back
#define in insert
#define se second
#define fi first
#define mod 1000000007
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define all(v) (v).begin(),(v).end()
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
#define pii pair<ll,ll>
#define vi(x) vector<x>
#define maxn 100005
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
using namespace std;
using namespace __gnu_pbds;

signed main()
{
    fast;
    
    ll n,w,i,j;
    cin>>n>>w;
    ll arr[n+2][2];
    for(i=1;i<=n;i++) cin>>arr[i][0]>>arr[i][1];
    ll dp[n+2][w+2];
    memset(dp,0,sizeof dp);
    for(i=1;i<=n;i++)
    {
    	for(j=1;j<=w;j++)
    	{
    		if(arr[i][0] <= j) dp[i][j] = max(dp[i-1][j] , dp[i-1][j - arr[i][0]] + arr[i][1]);
    		else dp[i][j] = dp[i-1][j];
    	}
    }
    cout<<dp[n][w];

}

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

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

		int n = sc.nextInt();
		int a[] = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		Arrays.sort(a);
		int ans = 1;
		for (int i = 0; i < n - 1; i++) {
			if (a[i] != a[i + 1]) {
				ans++;
			}

		}


		int x[] = new int[n];
		Renzoku(a, x);

		for (int i = 0; i < n; i++) {
			if (x[i] != 0) {
				x[i] = (x[i] + 1) % 2;
			}

		}
		if (sum(x) % 2 == 0) {

	System.out.println(ans);
		} else {
System.out.println(ans-1);
		}
	}

	public static int Renzoku(int c[], int x[]) {

		int mode = 0;
		int val = 0;

		for (int i = 0; i <= c.length - 2; i++) {
			if ((c[i] == c[i + 1]) && i != c.length - 2) {
				val++;
			} else {
				if ((c[i] == c[i + 1]) && i == c.length - 2) {
					val++;
				}
				val++;
				x[mode] = val;
				mode++;

				if ((c[i] != c[i + 1]) && i == c.length - 2) {
					x[mode] = 1;
					mode++;
				}

				val = 0;
			}

		}
		return mode;

	}

	static int sum(int a[]) {
		int n = a.length;
		int ans = 0;
		for (int i = 0; i <= n - 1; i++) {
			ans += a[i];
		}
		return ans;
	}

}

Measured memory_bytes: 49840
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
ll n;
//vector<ll> a(n,0),b(n,0),c(n,0);
 
int main(){
    cin>>n;
    vector<ll> a(n,0),b(n,0),c(n,0);
    for(int i = 0;i < n; i++){
        cin>>a[i];
    }
    //cout<<"aaa"<<endl;
    for(int i = 0;i < n; i++){
        cin>>b[i];
    }
    for(int i = 0;i < n; i++){
        cin>>c[i];
    }
    sort(a.begin(),a.end());
    //sort(b.begin(),b.end());
    sort(c.begin(),c.end());
    ll sum=0;
    for(int i = 0;i < n; i++){
        int x;
        int y;
        auto Iter = lower_bound(a.begin(),a.end(),b[i]);
        long n1=Iter-a.begin();
        auto Iter2 = upper_bound(c.begin(),c.end(),b[i]);
        long n2=c.end()-Iter2;
        sum+=n1*n2;
    }
    /*
    auto it = lower_bound(v.begin(), v.end(), 3);
    //探索したい値以上が現れる最初の位置のイテレータを取得。
    //ある値 keyより小さい配列Aの要素の個数nを求める場合
    auto Iter = lower_bound(A.begin(), A.end(), key);
    long n = Iter - A.begin();
    */
   cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 2560
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Sagor
 */

#include <fstream>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <deque>
#include <stack>
#include <vector>
#include <iomanip>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>

#define gap                        ' '
#define EPS                        1e-9
#define P_INF                      2e9+17
#define N_INF                     -2e9-17
#define MOD                        1000000007
#define PI                         2*acos(0.0)
#define All(x)                     x.begin(),x.end()
#define Mem(Name, type)            memset(Name, type, sizeof(Name))

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

template<typename T>
T LCM(T a, T b) { return (a * b) / GCD(a, b); }

template<typename T>
std::ostream &operator<<(std::ostream &os, const std::vector<T> &v) {
    for (auto ob : v) os << ob << " ";
    return os;
}

template<typename T, typename S>
std::ostream &operator<<(std::ostream &os, const std::map<T, S> &v) {
    for (auto ob : v) os << ob.first << " : " << ob.second << std::endl;
    return os;
}

using ld = double;
using ll = long long int;
using ul = unsigned long long int;
using namespace std;

class BProductMax {
public:
    void solve(std::istream &in, std::ostream &out) {
        ll a, b, c, d;
        in >> a >> b >> c >> d;
        ll ac = a * c;
        ll ad = a * d;
        ll bc = b * c;
        ll bd = b * d;
        out << max({ac, ad, bc, bd}) << endl;
    }
};


int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    BProductMax solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 3648
import java.io.*;
import java.util.*;
class Main
{
  public static void main(String[] args)
  {
    Scanner sc = new Scanner(System.in);
    int maxcount = 0;
    int count=0;
    int N = sc.nextInt();
    if(N<3 || N>100)
    {
      System.exit(0);
    }
    int arr[][] = new int[N][2];
    for(int i=0; i<N; i++)
    {
      for(int j=0; j<2; j++)
      {
        arr[i][j]=sc.nextInt();
        if(arr[i][j] < 1 || arr[i][j] > 6)
          System.exit(0);
      }
    }
    for(int i = 0; i < N ; i++)
    {
      if(arr[i][0]==arr[i][1])
      {
        count++;    
      }
      else
      {
        count = 0;
      }
      maxcount = Math.max(maxcount,count);
    }
    if(maxcount>=3)
    {
      System.out.print("Yes");
    }
    else
    {
      System.out.print("No");
    }
  }
}
                       

Measured memory_bytes: 36012
list_a = []
list_b = []

for x in range(4) :
    list_a.append(int(input()))
list_a.sort(reverse = True)

for x in range(2) :
    list_b.append(int(input()))
list_b.sort(reverse = True)

print(sum(list_a[0:3]) + list_b[0])


Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, a, b) for (int i = (a); i < (b); i++)
//#include "library/debug.cpp"

struct combination {
    ll mod;
    vector<ll> fac, finv, inv;

    combination(int n, ll m) : fac(n), finv(n), inv(n) {
        mod = m;
        fac[0] = fac[1] = 1;
        finv[0] = finv[1] = 1;
        inv[1] = 1;
        for (int i = 2; i < n; i++) {
            fac[i] = fac[i - 1] * i % mod;
            inv[i] = mod - inv[mod % i] * (mod / i) % mod;
            finv[i] = finv[i - 1] * inv[i] % mod;
        }
    }

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

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

    ll n, k, mod = 1e9 + 7;
    cin >> n >> k;
    vector<int> a(n);
    rep(i, 0, n) cin >> a[i];
    sort(a.begin(), a.end());
    combination x(200000, mod);
    ll mx = 0, mn = 0;
    rep(i, k - 1, n) {
        mx = (mx + a[i] * x.c(i, k - 1)) % mod;
    }
    rep(i, 0, n - k + 1) {
        mn = (mn + a[i] * x.c(n - i - 1, k - 1)) % mod;
    }
    ll ans = (mx - mn) % mod;
    ans = (ans + mod * 10LL) % mod;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 5376
#include <stdio.h>
int a[100000], b[100000];
int main ()
{
	int N,r=1, n=0, flag=1;
	scanf("%d", &N);
	for (int i=1; i<=N; i++)
	{
		scanf("%d", &a[i]);
		
	}
	while(n<=N)
	{
		n++;
		b[n]=a[r];
		r=b[n];
		if (r==2) break;
		if (r!=2&&n==N) 
		{
			printf("-1\n");
			flag=0;
			break;
		}
	}
	if (flag)
	{
	printf("%d\n", n);
	}
	return 0;
}

Measured memory_bytes: 896
func readInt() -> Int {
    return Int(readLine()!)!
}

func readInts(separator: String.Element = " ") -> [Int] {
    return readLine()!.split(separator: separator).map { Int($0)! }
}

func mainC() {
    let N = readInt()
    let A = readInts()

    var sums: [Int] = []
    sums.append(0)

    for i in 0..<N-1 {
        sums.append((sums.last! + A[N - 1 - i]) % (1000_000_000 + 7))
    }

    var result = 0
    for i in 0..<(N-1) {
        result += A[i] * sums[N - 1 - i]
        result = result % (1000_000_000 + 7)
    }

    print(result % (1000_000_000 + 7))
}
mainC()

Measured memory_bytes: 21292
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(ll i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    ll s = 0;
    
    rep(i, n) s ^= a[i];
    ll ans = s;
    
    ll bit = 0;
    rep(i, n) {
        ll j = 0;
        while (a[i]>>j) j++;
        j--;
        bit = max(bit, j);
    }
    rep(i, n) a[i] &= ~s;

    ll r = 0;
    //debug(ans);
    //debug(bit);
    
    
    for (ll i=bit; i>=0; i--) {
        //if (s>>i&1) continue;
        if (r==n) break;
        ll j = r;
        while (j<n && ((a[j]>>i&1)==0)) j++;
        if (j==n) continue;
        swap(a[r], a[j]);
        //debug(r);
        //debug(j);
        rep(k, n) {
            if (k==r) continue;
            if (a[k]>>i&1) a[k] ^= a[r];
        }
        r++;
        //ans += (1LL<<(i+1));
        //debug(i);
        //debug(r);
        //debug(ans);
        //rep(ii, n) debug(a[ii]);
    }
    ll x = 0;
    rep(i, r) {
        x ^= a[i];
    }
    ans += x*2;

    

    
    cout << ans << endl;
    return 0;
}


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

vector<int> G[SIZE];
vector<int> ans(SIZE), a(SIZE);
vector<int> L;
void dfs(int k = 0, int p = -1){
    int flag = -1;
    int itr = lower_bound(L.begin(), L.end(), a[k]) - L.begin();
    vector<int>::iterator it = lower_bound(L.begin(), L.end(), a[k]);
    if (it == L.end()){
        L.push_back(a[k]);
    }
    else {
        flag = *it;
        L[itr] = a[k];
    }
    ans[k] = L.size();
    for (auto &&i : G[k]){
        if (i == p)continue;
        dfs(i, k);
    }
    if (flag == -1)L.pop_back();
    else L[itr] = flag;
}
int main() {
    cin.tie(nullptr); ios::sync_with_stdio(false);
    int n; cin >> n;
    rep(i,n)cin >> a[i];
    rep(i,n-1){
        int u, v; cin >> u >> v;
        u--; v--;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    dfs();
    rep(i,n)
        cout << ans[i] << endl;
}

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

using namespace std;
typedef long long int ll;
typedef vector<ll> vll;
typedef pair<ll,ll> P;

#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define rrep(i,a) for(ll i=a-1;i>=0;i--)
#define MOD 1000000007

//debug
#define debug(arr) cerr<<#arr<<"(l"<<__LINE__<<") : ";for(auto x:arr)cerr<<x<<" ";cerr<<endl;

int main(){
  string str;
  cin >> str;
  vll N;
  for(auto c : str) N.push_back(c - '0');
  ll len = N.size();

  ll dp[len][2];
  rrep(i, len){
    if(i == len-1){
      dp[i][0] = N[len-1];
      dp[i][1] = (10 - N[len-1]) % 10;
    }
    else{
      dp[i][0] = min(N[i] + dp[i+1][0], N[i]+1 + dp[i+1][1]);
      dp[i][1] = min(9-N[i] + dp[i+1][1] + (dp[i+1][0] == 0), 10-N[i] + dp[i+1][0]);
    }
  }
  // rrep(i, len) rep(rev, 2) cout << dp[i][rev] << endl;
  ll ans = min(dp[0][0], dp[0][1] + 1);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 25460
n, k = map(int, input().split())
if k%2 == 1:
    ans = (n//k)**3
    print(ans)
else:
    c = 0
    for i in range(1, n+1):
        if i%k == k//2:
            c += 1
    ans = c**3
    ans += (n//k)**3
    print(ans)


Measured memory_bytes: 63524
#include "bits/stdc++.h"
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
//#include <boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
using namespace std;

#define all(c) (c).begin(),(c).end()
#define endl "\n"
#define ff first
#define ss second
#define allr(c) (c).rbegin(),(c).rend()
#define ifr(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define pof pop_front
#define pob pop_back
#define pb emplace_back
#define pf emplace_front
#define fstm(m,n,r) m.reserve(n);m.max_load_factor(r)
#define mp make_pair
#define mt make_tuple
#define inf LLONG_MAX
#define os tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
//order_of_key (k) : Number of items strictly smaller than k .
//find_by_order(k) : K-th element in a set (counting from zero).
const double PI = acos(-1);
typedef complex<double> cd;
typedef long long ll;
ll gcd(){return 0ll;} template<typename T,typename... Args> T gcd(T a,Args... args) { return __gcd(a,(__typeof(a))gcd(args...)); }
typedef map<ll,ll> mll;
typedef map<string,ll> msll;
typedef unordered_map<ll,ll> umap;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef long double ld;
#define mod 1000000007 

const int N = 1e5 + 2;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt","r",stdin);
    // #endif
    
    // int T;cin>>T;while(T--) 
    {
        string s, t;
        cin>>s>>t;
        int n = s.length();
        int m = t.length();
        int ans = m;
        for(int i=0; i+m-1<n; i++) {
            int c = 0;
            for(int j=0;j<m; j++)
                c+=(s[i+j]!=t[j]);
            ans = min(ans, c);
        }
        cout<<ans<<endl;
    }
    return 0;
}

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

typedef vector<int> vi;
typedef pair<int,int> ii;
typedef long long int ll;
typedef unsigned long long int ull;
#define inf INT_MAX
#define minf INT_MIN
#define watch(x)	cout<<(#x)<<"=>"<<x<<'\n';
#define sz(a) (int)(a).size()

ll ans;
vi vrr,vrc;
int R[300009];
int C[300009];
void solve()
{
				set<ii> stp;
				int h,w,m;	cin>>h>>w>>m;
				int naxr = minf;
				int naxc = minf;
				for(int i =0 ; i < m; ++i){
								int x,y;
								cin>>x>>y;
								stp.insert(make_pair(x,y));
								R[x]++;
								C[y]++;
								naxr = max(naxr,R[x]);
								naxc = max(naxc,C[y]);
				}
				for(int i = 1; i < h+1; ++i){
								if(R[i] == naxr)
												vrr.push_back(i);
				}
				for(int i = 1; i < w+1; ++i){
								if(C[i] == naxc)
												vrc.push_back(i);
				}
				for(auto r: vrr){
								for(auto cc : vrc){
												auto fh = stp.find(make_pair(r,cc));

												if(fh == stp.end()){
																cout<<R[r]+C[cc]<<'\n';
																return;
												}
																
								}
				}
				cout<<naxr+naxc-1<<'\n';

}

int main()
{
				ios_base::sync_with_stdio(false);
				cin.tie(NULL);
				int testc = 1;
				for(int t = 0; t < testc; ++t)
								solve();
				return 0;
}

		//Sat 22 Aug 2020 06:40:36 PM IST


					/***astrainL3gi0N***/


Measured memory_bytes: 23800
import os, sys, re, math

from fractions import gcd

(N, X) = [int(i) for i in input().split()]
x = [int(i) for i in input().split()]

d = []
for i in range(N):
    d.append(abs(X - x[i]))

g = d[0] if len(d) == 1 else gcd(d[0], d[1])
for i in range(len(d) - 2):
    g = gcd(g, d[i + 2])

print (g)


Measured memory_bytes: 16304
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
typedef long  l;
typedef pair<int,int> pl;
const int INF=100000001;

int main(){
  int n;cin>>n;
  bool ans=0;

  for(int i=1;i<=n/2;i++){
    if(n%i==0){
        int a=n/i;
        if(a<=9&&i<=9&&1<=a){
        ans=1;
        // cout<<i<<endl;
      }
    }
  }
  if(n==1)
  ans=1;

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


Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main(){
  int n,m;
  cin >> n >> m;
  vector<pair<int,int>> v(m);
  for (int i=0; i< m;i++){
    int a,b;
    cin >> a >> b;
    pair<int,int> p(a,b);
    v.at(i)=p;
  }
  int l=0,r=100001;
  for (int i=0; i <m; i++){
    int f1=1,f2=1;
    if (v.at(i).first > l) l=v.at(i).first;
    if (v.at(i).second < r) r=v.at(i).second;
  }
  //printf("%d,%d\n",l,r);
  if (r-l+1 > 0) cout << r-l+1 << endl;
  else cout << 0 << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
#include <math.h>

int cnt[100000];

int main(){
	int N;
	int i;

	scanf("%d",&N);
	int t;
	for(i = 0;i<N;i++){
		scanf("%d",&t);
		cnt[t]++;
	}

	if(N%2 == 1){
		if(cnt[0] != 1)goto end;
		for(i = 2;i<=N-1;i=i+2){
			if(cnt[i] != 2)goto end;
		}
		int ans = 1;
		for(i = 0;i<(N-1)/2;i++){
			ans *= 2;
			ans %= 1000000007;
		}
		printf("%d\n",ans);
		return 0;
	}else{
		for(i = 1;i<=N-1;i=i+2){
			if(cnt[i] != 2)goto end;
		}
		int ans = 1;
		for(i = 0;i<(N)/2;i++){
			ans *= 2;
			ans %= 1000000007;
		}
		printf("%d\n",ans);
		return 0;
		
	}
end:
	printf("0\n");
	return 0;
}


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

int main(){
    int n;
    cin >> n;
    double a[n], sum = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        sum += a[i];
    }
    sum /= n;
    int idx = 0;
    double mi = 10000000;
    for(int i = 0; i < n; i++){
        if(mi > fabs(sum - a[i])){
            idx = i;
            mi = fabs(sum - a[i]);
        }
    }
    cout << idx << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
#include<iomanip>
#include<math.h>
#include<vector>
#include<cctype>
#include<string>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
std::string line;

int sum(int x){
    int tmp=x;
    int res = 0;
    while(tmp>0){
        res += tmp%10;
        tmp /= 10;
    }
    return res;
}

int main(){

    int n;
    cin >> n;

    int num = 100010;
    for(int i=1;i<=n/2;i++){
        int j = n-i;

        int asum = sum(i);
        int bsum = sum(j);
        int addsum = asum + bsum;

        num = min(num,addsum);
    }

    cout << num << endl; 




   return 0;
}

Measured memory_bytes: 256
def main():
    N = int(input())
    F = [int(input().replace(' ', ''), 2) for _ in range(N)]
    P = [list(map(int, input().split())) for _ in range(N)]

    ans = -10 ** 10
    for i in range(1, 2 ** 10):
        c = 0
        for f, p in zip(F, P):
            c += p[bin(f & i).count('1')]
        ans = max(ans, c)
    print(ans)


main()


Measured memory_bytes: 3188