akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<string.h>
#include<set>
#define MAX_N 50
#define INF 10000
using namespace std;
int d[MAX_N][MAX_N];
int N;
void floyed(int  X) {
	for (int k = 0; k<X; k++) {
		for (int i = 0; i<X; i++) {
			for (int j = 0; j<X; j++) {
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
			}
		}
	}
}
int main() {
	while (true) {
		set<int> s;
		cin >> N;
		if (N <= 0)
			break;
		for (int i = 0; i<MAX_N; i++) {
			for (int j = 0; j<MAX_N; j++) {
				d[i][j] = INF;
				if (i == j)
					d[i][j] = 0;
			}
		}
		
		for (int i = 0; i<N; i++) {
			int from, to, costs;
			cin >> from >> to >> costs;
			d[from][to] = costs;
			d[to][from] = costs;
			s.insert(to);
			s.insert(from);
		}
		floyed(s.size());
		int misum = INF;
		int no;
		for (int i = 0; i<s.size(); i++) {
			int sum = 0;
			for (int j = 0; j<s.size(); j++) {
				if (i != j&&d[i][j]!=INF)
					sum += d[i][j];
			}
			if (sum < misum) {
				misum = sum;
				no = i;
			}
		}
	
		cout << no<<" "<<misum << endl;
		
	}
	
}


Measured memory_bytes: 3064
n = int(input())

strings = ["a"]

for i in range(n-1):
    newstrings = []
    for s in strings:
        mx = ord('a')
        for char in s:
            mx = max(mx, ord(char))
        
        for c in range(ord('a'),mx+2):
            newstrings.append(s+chr(c))
    
    strings = newstrings

for s in strings:
    print(s)

Measured memory_bytes: 57000
N, K = map(int, input().split())

lst = []
for i in range(N):
    lst += [list(map(int, input().split()))]

lst.sort()


for i in range(N):
    if K <= lst[i][1]:
        print (lst[i][0])
        exit()
    else:
        K -= lst[i][1]

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

#define all(x) begin(x), end(x)

using i64 = int_fast64_t;
using u64 = uint_fast64_t;
using f64 = double;
using p64 = pair<i64, i64>;

constexpr i64 INF = INT_FAST64_MAX / 2;

template<typename T>
struct binary_indexed_tree {
    vector<T> t_;
    i64 n_;

    binary_indexed_tree(size_t n): t_(n + 1), n_(n + 1) {}

    void add(i64 i, T x) {
        for (; i <= n_; i += i & -i) t_[i] += x;
    }

    T sum(i64 i) {
        T res = 0;
        for (; i > 0; i -= i & -i) res += t_[i];
        return res;
    }
};

struct query { i64 idx, l, r; };

void solve() {
    i64 n, q;
    cin >> n >> q;
    vector<i64> c(n);
    for (auto& e : c) cin >> e;
    vector<query> qs(q);
    for (i64 i = 0; i < q; i++) {
        auto& [ idx, l, r ] = qs[i];
        idx = i;
        cin >> l >> r;
    }
    sort(all(qs), [](query x, query y) { return x.r < y.r; });

    vector<i64> right(n), ans(q);
    binary_indexed_tree<i64> cnt(n);
    i64 i = 0;
    for (auto& [ idx, l, r ] : qs) {
        while (i < r) {
            if (right[c[i]]) cnt.add(right[c[i]], -1);
            right[c[i]] = i + 1;
            cnt.add(right[c[i]], 1);
            i++;
        }
        ans[idx] = cnt.sum(r) - cnt.sum(l - 1);
    }
    for (auto& e : ans) cout << e << endl;
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}


Measured memory_bytes: 31080
//
// Created by Tzyark on 2018/9/18.
//
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
int H, W, N, a, b;
ll ans[10];
vector<pair<int, int>> vec;
int main() {
    cin >> H >> W >> N;
    for (int n = 0; n < N; n++) {
        cin >> a >> b;
        for (int i = 0; i < 3; i++) {
            for (int j = 0; j < 3; j++) {
                if (1 <= a-i && a-i <= H-2 && 1 <= b-j && b-j <= W-2) {
                    vec.push_back(make_pair(a-i, b-j));
                }
            }
        }
    }
    sort(vec.begin(), vec.end());
    int cnt = 1;
    for (int i = 0; i < vec.size(); i++) {
        if (vec[i] == vec[i + 1]) cnt++;
        else ans[cnt]++, cnt = 1;
    }
    ans[0] = 1ll * (H-2) * (W-2);
    for (int i = 1; i <= 9; i++) {
        ans[0] -= ans[i];
    }
    for (int i = 0; i <= 9; i++) {
        cout << ans[i] << endl;
    }
    return 0;
}

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

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

const int N = 105;
int n, k, d, id;
int nums[N];

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

  cin >> n >> k;
  for (int i = 0; i < k; ++i) {
    cin >> d;
    for (int j = 0; j < d; ++j) {
      cin >> id;
      ++nums[id];
    }
  }
  int res = 0;
  for (int i = 1; i <= n; ++i) {
    if (nums[i] == 0)
      ++res;
  }
  cout << res << endl;
  
  return 0;
}


Measured memory_bytes: 3668
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: u64,
        m: u64,
        stores: [(u64, u64); n]
    };
    let mut stores = stores;
    stores.sort_by(|f1, f2| f1.0.cmp(&f2.0));

    let mut ans = 0;
    let mut drink_count = 0;
    for store in stores {
        if drink_count + store.1 > m {
            ans += store.0 * (m - drink_count);
            break;
        } else {
            ans += store.0 * store.1;
            drink_count += store.1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 6396
#include<bits/stdc++.h>
using namespace std;
#define RI register int
typedef double db;
int n;db d,x,ans;
int main()
{
    scanf("%d%lf%lf",&n,&d,&x);
    db nn=n+n;
    for(RI i=n;i>=1;--i) {
        ans+=d+(nn-1)/2*x;
        db dd=d+(2*d+5*x)/nn;
        db xx=x+4*x/nn;
        x=xx,d=dd,nn-=2;
    }
    printf("%.10lf\n",ans);
    return 0;
}

Measured memory_bytes: 256
D=int(input())
C=list(map(int,input().split()))
import sys
S=sys.stdin.readlines()
A=[0]*26
B=[0]*D
k=0
for i in range(26):
  if C[i]!=0:
    k+=C[i]
for i in range(26):
  if i<25:
    A[i]=int(C[i]/k*D)
  else:
    A[i]=D-sum(A[:25])

for i in range(25):
  for j in range(A[i]):
    B[D//A[i]*j]=i+1

for i in range(D):
  if B[i]==0:
    B[i]=26


for i in range(D):
  print(B[i])

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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define ALL(v) (v).begin(), (v).end()
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO  cout << "NO"  << endl
#define No  cout << "No"  << endl

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;


void solve()
{
    string s; cin >> s;
    int K; cin >> K;
    set<string> ss;
    vs ans;
    REP1(l, 5)
    {
        REP(i, s.length())
        {
            if(i + l > s.length()) break;
            if(ss.find(s.substr(i, l)) == ss.end()) ans.push_back(s.substr(i, l));
            ss.insert(s.substr(i, l));
        }
    }
    sort(ALL(ans));
    cout << ans[K-1] << endl;
}
    
int main() 
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <sstream>
#include <stdio.h>
#include <algorithm>
#include <string>
#include <bitset>
#include <vector>
using namespace std;
int N,M;
int n[100000];
bool m[100000] = {1};
int main()
{
	int ans = 0;
	cin >> N;
	cin >> M;
	int x, y;
	for (int i = 0; i < M; i++) {
		cin >> x; cin >> y;
		n[x-1]--; n[y-1]++;
		if (m[x - 1] == true)m[y - 1] = true;
		if (n[x - 1] < 0)m[x - 1] = 0;
	}
	for (int i = 0; i < N; i++) {
		if (m[i]==true)ans++;
	}
	cout << ans << endl;
}


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

int main() {
  int A,N,a;
  
  cin >> N >> A;
  a=N%500;
  
  if(a<=A){
    cout << "Yes" << endl;
  }
  
  else{
    cout << "No" << endl;
  }
}

  

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

public class Main {
    public static void main(String[] args) {
        FastReader s = new FastReader();
        int T = s.nextInt();
        Set<String> hash_Set = new HashSet<String>();
        while (T-- > 0) {
            hash_Set.add(s.next());
        }
        System.out.println(hash_Set.size());
    }

    private static boolean isPrime(int n) {
        if (n == 2)
            return true;
        else if ((n % 2 == 0 && n > 2) || n < 2)
            return false;
        else {
            for (int i = 3; i <= (int) Math.sqrt(n); i += 2) {
                if (n % i == 0)
                    return false;
            }
            return true;
        }


    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

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

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

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

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

}

Measured memory_bytes: 66232
import java.util.Scanner;

class Main
{
	public static void main(String[] args)
	{
		Scanner scanner = new Scanner(System.in);
		int a = scanner.nextInt();
		int b = scanner.nextInt();
		int c = scanner.nextInt();
                if(a < b && b < c)
		{
  			System.out.println("Yes");
		}
		else
		{
			System.out.println("No");
		}
	}
}
		


Measured memory_bytes: 26312
package main

import (
	"fmt"
)

func main() {
	arr := []int{1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51}
	var K int
	fmt.Scanf("%d\n", &K)
	fmt.Println(arr[K-1])
}


Measured memory_bytes: 512
def solve():
    x, y = map(int, input().split())
    a = [0 , 1 , 3 , 1 , 2 , 1 , 2 , 1 , 1 , 2 , 1 , 2 , 1]
    if a[x] == a[y]:
        ans = "Yes"
    else:
        ans = "No"
    print(ans)

if __name__ == '__main__':
    solve()  

Measured memory_bytes: 2940
// abc099_b
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(i,v.size())cout<<" "<<v[i];cout<<endl<<endl;
#define show2d(v) rep(i,v.size()){rep(j,v[i].size())cout<<" "<<v[i][j];cout<<endl;}cout<<endl;
using namespace std;
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(int argc, char *argv[])
{
  int a,b,tower=0;
  cin>>a>>b;
  for (int i=1; i<b-a; ++i) {
    tower+=i;
  }
  cout<<tower-a<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#define REP(i, n) for(i=0; i<n; i++)
#define REPR(i, n) for(i=n; i>=0; i--)
#define FOR(i, m, n) for(i=m; i<n; i++)
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define INF 1<<30
#define MOD 1000000007LL
#define MAX 100005
#define NIL -1
#define WHITE 0
#define GRAY 1
#define BLACK 2
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PA;
typedef priority_queue<ll> PQ;
typedef pair<double, double> doup;
typedef vector<ll> vec;
typedef vector<vec> mat;

int main() {
    ll N, K;
    cin >> N >> K;
    ll x[51], y[51], i, j, k, l, p;
    ll num;
    for(i=0; i<N; i++) {
        cin >> x[i] >> y[i];
    }
    
    ll ans=-1;
    for(i=0; i<N; i++) {
        for(j=0; j<N; j++) {
            for(k=0; k<N; k++) {
                for(l=0; l<N; l++) {
                    num=0;
                    for(p=0; p<N; p++) {
                        if(x[i]<=x[p] && x[p]<=x[j] && y[k]<=y[p] && y[p]<=y[l])
                            num++;
                    }
                    if(num>=K) {
                        if(ans<0) {
                            ans=(x[j]-x[i])*(y[l]-y[k]);
                        }else
                            ans=min(ans, (x[j]-x[i])*(y[l]-y[k]));
                    }
                }
            }
        }
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 384
import java.util.Scanner;
public class Main {
	public static void main(String args[]) {
		Scanner scan = new Scanner(System.in);
		String str = scan.nextLine();
		
		String[] strAry = str.split(" ");
		int int1 = Integer.parseInt(strAry[0]);
		int int2 = Integer.valueOf(strAry[1]).intValue();
		
		int rate;
		
		if(int1 >=10) {
		    rate = int2;
		}else {
			rate = int2 + 100*(10-int1);
			
		}
		System.out.println(String.valueOf(rate));

		
		
	}

}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, K; cin >> N >> K;
  vector<long long> pos;
  vector<long long> neg;
  for(int i = 0; i < N; i++) {
    long long x; cin >> x;
    if(x < 0) neg.push_back(x);
    else if(x > 0) pos.push_back(x);
    else K--;
  }
  reverse(neg.begin(), neg.end());
  long long ans = -1;
  if(K == 0) {
    cout << 0 << endl;
    return 0;
  }
  for(int p = 0; p <= K; p++) {
    if(p > pos.size()) continue;
    if(K - p > neg.size()) continue;
    long long upd = 0;
    if(p == 0) upd = -neg[K - p - 1];
    else if(K - p == 0) upd = pos[p - 1];
    else upd = 2 * min(pos[p - 1], -neg[K - p - 1]) + max(pos[p - 1], -neg[K - p - 1]);
    if(ans == -1) ans = upd;
    else ans = min(ans, upd);
  }
  cout << ans << endl;
}

Measured memory_bytes: 1656
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int N, Q;
    cin >> N >> Q;
    string S;
    cin >> S;
    int l[100000], r[100000];
    for(int i=0;i<Q;i++)
        cin >> l[i] >> r[i];
    
    // 累積和
    int AC[100000]; // AC[i]:S[0]~S[i]までに含まれる"AC"の数
    AC[0] = 0;
    int count = 0;
    for(int i=1;i<N;i++){
        if(S[i-1] == 'A' && S[i] == 'C')
            count++;
        AC[i] = count;
    }
    // Q個のクエリの処理
    int ans;
    for(int i=0;i<Q;i++){
        ans = AC[r[i]-1] - AC[l[i]-1];
        cout << ans << endl; 
    }
        
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
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 ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (a < b) {
    ll tmp = a;
    a = b;
    b = tmp;
  }
  ll r = a%b;
  while(r != 0) {
    a = b;
    b = r;
    r = a%b;
  }
  return b;
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}

int main() {
  ll n;
  cin >> n;
  set <ll> s;
  rep(i, n) {
    ll a;
    cin >> a;
    s.insert(a);
  }
  cout << s.size() << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include <sstream>
#include<map>
#include<cmath>
#include<queue>

using namespace std;

int main() {

	int N, L;
	cin >> N >> L;

	int total = 0;
	bool isZero = false;
	for (int i = 0; i < N; i++)
	{
		int add = L + i;
		total += add;
		if (add == 0)
		{
			isZero = true;
		}
	}

	if (!isZero)
	{
		if (L < 0)
		{
			total -= N + L - 1;
		}
		else
		{
			total -= L;
		}
	}




	cout << total << endl;
	
	return 0;
}

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

int main() {
  int64_t n,k;
  cin >> n >> k;
  
  int count = 0;
  
  while (n / k > 0) {
  n = n / k;
    count++;
  }
  
  cout << count + 1;
   
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/priority_queue.hpp> //__gnu_pbds::priority_queue
 
using std::pair;
using std::vector;
using std::string;

typedef long long ll;
typedef pair<int, int> pii;
 
#define fst first
#define snd second
#define pb(a) push_back(a)
#define mp(a, b) std::make_pair(a, b)
#define debug(...) fprintf(stderr, __VA_ARGS__)
 
template <typename T> bool chkmax(T& a, T b) { return a < b ? a = b, 1 : 0; }
template <typename T> bool chkmin(T& a, T b) { return a > b ? a = b, 1 : 0; }
 
const int N = 400;
const int mo = 1e9 + 7;
const int oo = 0x3f3f3f3f;
 
template<typename T> T read(T& x) {
    int f = 1; x = 0;
    char ch = getchar();
    for(;!isdigit(ch); ch = getchar()) if(ch == '-') f = -1;
    for(; isdigit(ch); ch = getchar()) x = x * 10 + ch - 48; 
    return x *= f;
}

int n, m;
int a[N + 5], b[N + 5];
int p0[N + 5], p1[N + 5];
int s[N + 5][N + 5], f[N + 5][N + 5], g[N + 5][N + 5];

inline void add(int &x, int y) {
    if((x += y) >= mo) x -= mo;
}

int main() {
#ifdef Wearry
    freopen("data.txt", "r", stdin);
    freopen("ans.txt", "w", stdout);
#endif

    m = read(n) / 3;
    for(int i = 1; i <= n; ++i) p0[read(a[i])] = i;
    for(int i = 1; i <= n; ++i) p1[read(b[i])] = i;

    for(int i = 1; i <= n; ++i) {
        s[i][n + 1] = 0;
        for(int j = n; j >= 1; --j) {
            s[i][j] = s[i][j + 1] + (p0[b[j]] >= i);
        }
    }

    for(int i = 0; i <= n; ++i) std::fill(g[i], g[i] + N + 1, 1);
    for(int k = 1; k <= m; ++k) {
        for(int i = n; i >= 1; --i)
            for(int j = n; j >= 1; --j)
                if(a[i] ^ b[j] && p0[b[j]] > i && p1[a[i]] > j) {
                    f[i][j] = g[i + 1][j + 1];
                    int res = s[i][j] - 2 * k;
                    if(res >= k) f[i][j] = 1ll * f[i][j] * (res - k + 1) % mo; else f[i][j] = 0;
                    f[i][j] = 1ll * f[i][j] * (3 * (k - 1) + 1) % mo * (3 * (k - 1) + 2) % mo;
                } else f[i][j] = 0;

        memset(g, 0, sizeof g);
        for(int i = n; i >= 1; --i) {
            for(int j = n; j >= 1; --j) {
                g[i][j] = (g[i][j + 1] + f[i][j]) % mo;
            }
            for(int j = n; j >= 1; --j) {
                g[i][j] = (g[i + 1][j] + g[i][j]) % mo;
            }
        }
    }
    printf("%d\n", f[1][1]);

    return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
//typedef long double ld;

typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<double,double> pdd;
typedef set<int> si;
typedef set<ll> sll;
typedef vector<int> vi;
typedef vector<pair<int, int > > vii;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef vector<vll> vvll;

constexpr ll MOD = 1e9+7;
constexpr int INF = 1<<30;
constexpr ll  LINF = 1LL<<60;

#define Sort(x) sort(x.begin(),x.end())
#define Reverse(x) reverse(x.begin(),x.end())
#define ABS(a,b) ((a)<(b)?(b)-(a):(a)-(b))
#define nbit(n) (1ll<<(n))

// sort(begin(x), end(x), greater<ll>());
// lower_bound(a.begin(), a.end(), val): a[i] ≥ valである最左の位置
// upper_bound(a.begin(), a.end(), val): a[i] > valである最左の位置

// Returns minimum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmin(T& a, T b) {
  if (a > b) {
    a = b;
  }
  return a;
}

// Returns maximum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmax(T& a, T b) {
  if (a < b) {
    a = b;
  }
  return a;
}

// a = (a+b)%MOD;
void addmod(ll& a, ll b) {
  a = (a+b)%MOD;
}

template <typename T>
void dumpContents(const T& v, const string& msg)
{
  cerr << "### " << msg << " ###\n";
  for (const auto& x : v) {
    cerr << x << " ";
  }
  cerr << endl;
}

struct before_main_function {
  before_main_function() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<setprecision(20)<<fixed;
    #define endl "\n"
  }
} before_main_function;

// ========== end of template ==========

int main(int argc, char** argv) {
  ll W, H, x, y;
  cin >> W >> H >> x >> y;

  double S = double(W)*double(H)/2.0;

  int flag = 0;
  if (x*2 == W && y*2 == H) {
    flag = 1;
  }

  cout << S << " " << flag << endl;

  return 0;
}


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

#define ll long long
#define ull unsigned long long

bool isPalindrome(string s) {
    string t(s.rbegin(), s.rend());
    return s == t;
}

int main(void) {
    ll N;
    ll count = 0;
    vector<string> ss;
    vector<ll> com{1};
    cin >> N;
    for(ll i = 0;i < N;i++) {
        string temp;
        cin >> temp;
        sort(temp.begin(), temp.end());
        ss.push_back(temp);
    }
    sort(ss.begin(), ss.end());
    for(ll i = 1;i < N;i++) {
        if(ss[i - 1] == ss[i]) {
            com.back() += 1;
        } else {
            com.push_back(1);
        }
    }
    for(auto &i: com) count += i * (i - 1) / 2;
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 7284
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod = 1e9 + 7;
int main() {
    int h, w;
    cin >> h >> w;
    vector< vector< char > > grid(h, vector< char > (w));
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) cin >> grid[i][j];
    }
    vector< vector< ll > > dp(h, vector< ll >(w));
    for (int i = 0; i < w; i++) {
        if (grid[0][i] == '.') dp[0][i] = 1;
        else break;
    }
    for (int i = 0; i < h; i++) {
        if (grid[i][0] == '.') dp[i][0] = 1;
        else break;
    }
    for (int i = 1; i < h; i++) {
        for (int j = 1; j < w; j++) {
            if (grid[i][j] == '.') dp[i][j] = (dp[i][j - 1] + dp[i - 1][j]) % mod;
            else dp[i][j] = 0;
        }
    }
    
    cout << dp[h - 1][w - 1];
}

Measured memory_bytes: 12076
S = input()
S1 = [s for s in S if s != 'x']
# print(S, S1)

ans = 0
ls = len(S)
l = 0
r = ls - 1
while l < r:
    if S[l] == S[r]:
        l += 1
        r -= 1
        continue
    if S[l] == 'x':
        l += 1
        ans += 1
    elif S[r] == 'x':
        r -= 1
        ans += 1
    else:
        ans = -1
        break
print(ans)


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

#define INF 1LL << 60
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPP(i, n) for (int i = 1; i <= n; i++)

const int maxV = 100005;
const int maxE = 100005;
vector<int> G[maxV];

int N, M;
int x[maxE], y[maxE];

int memo[maxV];
int dfs(int i) {
    if (memo[i] != -1) return memo[i];
    if (G[i].empty()) return memo[i] = 0;

    int M = 0;
    REP(j, G[i].size()) {
        M = max(M, dfs(G[i][j]));
    }
    return memo[i] = M + 1;
}

int solve() {
    REP(i, M) G[x[i]].push_back(y[i]);
    REP(i, maxV) memo[i] = -1;

    int M = 0;
    REPP(i, N) M = max(M, dfs(i));
    return M;
}

int main() {
    cin >> N >> M;
    REP(i, M) cin >> x[i] >> y[i];

    cout << solve() << endl;
    return 0;
}

Measured memory_bytes: 8960
#include <stdio.h>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <algorithm>
#include <vector>
#include <math.h>
#define MOD (long long)1000000007
#define INF (long long)998244353
using namespace std;

int main(void){
    int n;
    cin >> n;
    string s;
    cin >> s;
    int count=1;
    for(int i=1; i<n; i++){
        if(s[i-1]!=s[i])count++;
    }
    cout << count << endl;
}

Measured memory_bytes: 512
import java.util.*;
import java.math.RoundingMode;
import java.math.BigDecimal;
 
 
 
public class Main{
	 public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		int h[] = new int[n];
		for(int i = 0; i < n; i++) {
		h[i] = sc.nextInt();	
		}
		int ans = 0; 
		for(int i = 0; i < n; i++) {
			if(h[i]>=k) ans++;
		}
		System.out.println(ans);
	 }
}

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

int main() {
    int n, k;
    cin >> n >> k;
    map<int, int> p;
    rep(i, n) {
        int tmp;
        cin >> tmp;
        if (p.count(tmp)) {
            p[tmp]++;
        } else {
            p[tmp] = 1;
        }
    }

    int m = 0;
    vector<int> cnts = {};
    for (auto q : p) {
        m++;
        cnts.push_back(q.second);
    }

    if (m <= k) {
        cout << 0 << endl;
    } else {
        sort(cnts.begin(), cnts.end());
        int replace_cnt = 0;
        rep(i, m - k) {
            replace_cnt += cnts[i];
        }

        cout << replace_cnt << endl;
    }
}

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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	string s, t;
	cin >> n >> s >> t;
	for (int i = 0; i < n; i++) {
		cout << s[i] << t[i];
	}
	cout << '\n';
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<string>
#include<bits/stdc++.h>
#include<algorithm>
#include<stdio.h>
#include<bits/stdc++.h>
#define ll  long long
#define ff first
#define ss second
#define pb push_back
#define mp make_pair

using namespace std;

/*ll ma=998244353;
ll power(ll v,ll ti){
if(ti==1)
    return v;
ll x=power(v,ti/2);
x=(x*x)%ma;
if(ti%2==1)
    x=(x*v)%ma;
return x;

}
struct t{
int a,b;
};
vector<vector<t > >g;
vector<int> v;


ll n;


void dfs(int i,int sum){
v[i]=1;


for(int j=0;j<go[i].size();j++){
    int x=go[i][j].a;
    int y=go[i][j].b;
    if(v[x]==0){
        dfs(x,min(y,sum));

    }

}

}*/



 int main(){
int r,g,b,n;
cin>>r>>g>>b>>n;
int x=n/r;
int y=n/g;
int ans=0;
for(int i=0;i<=x;i++){
    for(int j=0;j<=y;j++){
        int z=n-(i*r+j*g);
        if(z>=0 && z%b==0)
            ans++;
    }
}
cout<<ans<<endl;
 }


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define N 100
typedef long long int ll;
ll a[N];
ll b[N];
ll c[N];
ll d[N];
ll q;
ll cal1(vector<ll> v)
{
	ll ans=0;
	for(ll i=0;i<q;i++)
	{
		ll x=b[i];
		ll y=a[i];
		if(v[x]-v[y]==c[i])ans+=d[i];
	}
	return ans;
}
ll cal(vector<ll> v,ll i,ll j,ll n,ll m)
{
	if(i==n)return cal1(v);
	ll ans=0;
	for(ll k=j;k<=m;k++)
	{
		v.push_back(k);
		ans=max(ans,cal(v,i+1,k,n,m));
		v.pop_back();
	}
	return ans;
}
int main()
{
	ll n,m;
	cin>>n>>m>>q;
	for(ll i=0;i<q;i++)cin>>a[i]>>b[i]>>c[i]>>d[i],a[i]--,b[i]--;
	vector<ll> v;
	cout<<cal(v,0,1,n,m)<<endl;
}

Measured memory_bytes: 3632
#include<stdio.h>

int A[100000], n;

int binarySearch(key)
{
    int left = 0, right = n;
    int mid;
    
    while( left < right ) {
        mid = (left + right) / 2;
        if ( A[mid] == key) {
            return 1;
        } else if ( A[mid] > key ){
            right = mid;
            
        } else if ( A[mid] < key ){
            left = mid + 1;
        }
    }
    return 0;
}

int main()
{
    int i, q, key, sum = 0;
    scanf("%d", &n);
    for ( i = 0; i < n; i++){
        scanf("%d", &A[i]);
    }
    scanf("%d", &q);
    for ( i = 0; i < q; i++){
        scanf("%d", &key);
        if (binarySearch(key) == 1) {
            sum++;
        }
    }
    printf("%d\n", sum);
    return 0;
}

Measured memory_bytes: 988
from heapq import heapify
from heapq import heappop
from heapq import heappush
class UnionFind():
    def __init__(self, n):  #初期化　最初はみんなばらばら
        self.n = n
        self.parents = [-1] * n
    def find(self, x):  #xの根を見つける　たどった経路全ての根を更新
        if self.parents[x] < 0:
            return x   #根の番号を返す
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)  #x,yの木の根
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x  #xをでかい木にする

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):  #xの含まれる木の要素数を返す
        return -self.parents[self.find(x)]

    def same(self, x, y):  #x,yが同じ気に属するか判定
        return self.find(x) == self.find(y)

    def members(self, x):  #xの含まれる木の要素を配列で返す
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):  #根をすべて返す
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self): #木の個数
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
V,E = map(int,input().split())
uf = UnionFind(V)
hq = []
heapify(hq)
for i in range(E):
    s,t,w = map(int,input().split())
    heappush(hq,(w,s,t))
ans = 0 #最小全域木の辺の重みの総和
while len(hq) != 0:
    w,s,t = heappop(hq)
    if not uf.same(s,t):
        ans += w
        uf.union(s,t)
    else:
        continue
print(ans)


Measured memory_bytes: 22960
#include <stdio.h>

int main() {
    int n;
    scanf("%d", &n);
    int F[50];
    F[0] = 1;
    F[1] = 1;
    for(int i=2; i<50; i++) F[i] = F[i-2] + F[i-1];
    
    printf("%d\n", F[n]);
    return 0;
}


Measured memory_bytes: 2700
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >>N;
  char c='s';
  vector<int> vec(N);
  for(int i=0;i<N;i++){
    cin >>vec.at(i);
  }
  int a=1;
  for(int i=0;i<N;i++){
    a=vec.at(a-1);
    if(a==2){
      cout <<i+1<<endl;
      c='n';
      break;
    }
    else{}
  }
  if(c=='s')
    cout << -1 <<endl;
}
      

Measured memory_bytes: 640
import Data.List

countDiff :: String -> String -> Int
countDiff s t 
  | s == "" || t == "" = 0
  | head s == head t = countDiff (tail s) (tail t)
  | otherwise = 1 + countDiff (tail s) (tail t)

main = do
  s <- getLine
  putStrLn $ show $ countDiff s "CODEFESTIVAL2016"


Measured memory_bytes: 380
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
long long dp[100005],h[100005];
int n,k;
int main()
{
	memset(dp,0x3f,sizeof(dp));dp[1]=0;
	scanf("%d%d",&n,&k);for(int i=1;i<=n;++i) scanf("%lld",&h[i]);
	for(int i=2;i<=n;++i) for(int j=max(1,i-k);j<i;++j) dp[i]=min(dp[i],dp[j]+abs(h[i]-h[j]));
	printf("%lld",dp[n]);
	return 0;
}

Measured memory_bytes: 1664
import math
import collections


def kumiawase(n):
    if n == 0 or n == 1:
        return 0
    return (n**2 - n) // 2


n = int(input())
aL = list(map(int, input().split(" ")))

d = collections.Counter(aL)

s = 0
for i in d.values():
    s += kumiawase(i)

for a in aL:
    print(s - kumiawase(d[a]) + kumiawase(d[a] - 1))


Measured memory_bytes: 26780
import sys
def input():
    return sys.stdin.readline()[:-1]


N = int(input())

head_b_count = 0
tail_a_count = 0

head_b_tail_a_count = 0

total = 0

for _ in range(N):

    s = input()

    if s[0] == 'B':
        head_b_count += 1
    if s[-1] == 'A':
        tail_a_count += 1
    if s[0] == 'B' and s[-1] == 'A':
        head_b_tail_a_count += 1

    total += s.count('AB')

additional = min(head_b_count, tail_a_count)

if head_b_count == tail_a_count == head_b_tail_a_count != 0:
    additional -= 1

total += additional

print(total)


Measured memory_bytes: 40048
# include <iostream>
# include <string>
# include <algorithm>
# include <vector>
# include <cstring>
# include <stdio.h>
# include <map>
# include <queue>

# define ll long long
# define pii pair<int,int>
# define FOR(a,b) for(int a=1; a<=b; a++)
# define REP(a,b) for(int a=0; a<b; a++)
# define FORU(a,b,c) for(int a=b; a<=c; a++)
# define FORD(a,b,c) for(int a=b; a>=c; a--)

using namespace std;

char grid[2005][2005];
int tok[2005][2005];
int h[2005], w[2005];

int R, C;

int main(){

    ios :: sync_with_stdio(false);
    cin >> R >> C;
    FOR(i,R) FOR(j,C){
        cin >> grid[i][j];
    }

    int ans = max(R,C);
    FOR(i,R-1){
        FOR(j,C-1){
            int black = (grid[i][j] == '#') + (grid[i][j+1] == '#') + (grid[i+1][j] == '#') + (grid[i+1][j+1] == '#');
            tok[i][j] = black&1;
        }
    }

    FOR(i,R){
        FOR(j,C-1){
            if(tok[i-1][j]) h[j] = 1;
            else h[j]++;
        }

        int k = 0;
        FOR(j,C-1){
            while(h[j] <= h[w[k]]){
                ans = max(ans, h[w[k]]*(j - w[k-1]));
                k--;
            }
            w[++k] = j;
        }

        while(k > 0){
            ans = max(ans, h[w[k]] * (C - w[k-1]));
            k--;
        }
    }

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

Measured memory_bytes: 19840
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[n];
    map<int,int> m;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        m[a[i]]++;
    }
    long long int sum=0;
    for(auto i:m)
    {
        long long int x=i.second;
        sum=sum+(x*(x-1))/2;
    }
    for(int i=0;i<n;i++)
    {
        cout<<sum-m[a[i]]+1<<"\n";
    }

}

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

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

//マクロ
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define FORD(i, a, b) for (ll i = (a); i >= (b); i--)
#define ALL(x) (x).begin(), (x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007      //10^9+7
#define PB push_back
#define MP make_pair
#define F first
#define S second

int main(int argc, char const *argv[])
{
    int a,b;
    cin >> a >> b;
    cout << a * b << endl;
    return 0;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define ll long long int
const ll M = 1e9+7;
const ll inf = 1e18+5;
using namespace std;
#define debug() for(ll l=0;l<50;l++){}
#define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
ll power(ll x,ll y,ll p){
	ll res = 1;
	x = x % p;
	if(x == 0) return 0;
	while (y > 0){
		if (y & 1) res = (res*x) % p;
		y = y>>1;
		x = (x*x) % p;
		}
	return res;
}

void solve(){
	ll n;
	cin>>n;
	cout<<((power(10,n,M)-(2*power(9,n,M))%M+power(8,n,M))%M+M)%M;
}

int main(){
	fast;
	ll t=1;
	//cin>>t;
	while(t--) solve();
	return 0;
}


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

int main(){
  int N,L;
  cin >> N >> L;
  vector<string> S(N);
  for(int i=0;i<N;i++){
    cin >> S.at(i);
  }
  sort(S.begin(),S.end());
  for(int i=0;i<N;i++){
    cout << S.at(i);
  }
  cout << endl;
} 

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
    int n;
    cin >> n;
    int t[2], x[2], y[2];
    t[0] = x[0] = y[0] = 0;
    for (int i = 1; i <= n; i++) {
        if (i >= 2) {
            t[0] = t[1]; x[0] = x[1]; y[0] = y[1];
        }
        cin >> t[1] >> x[1] >> y[1];
        if (abs(t[1] - t[0]) < abs(x[1] - x[0]) + abs(y[1] - y[0])) { //t[i]とt[i+1]の関係 戻れることも注意
            cout << "No" << endl;
            return 0;
        } else {
            if (abs(t[1] - t[0]) % 2 != (abs(x[1] - x[0]) + abs(y[1] - y[0])) % 2) { //戻れる条件
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl; //生き残ったら
    return 0;
}


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

// macro
#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
int main()
{
	int n,m;cin>>n>>m;
	vector<int> a(m);
	vector<int> b(m);
	int i;
	rep(i,m)cin>>a[i]>>b[i];
	vector<pair<int,int>> p(m);
	rep(i,m)p[i]=make_pair(b[i],a[i]);
	sort(all(p));
	int last=-1;
	int ans=0;
	rep(i,m)
	{
		if(last>=p[i].first||last<p[i].second)
		{
			last=p[i].first-1;
			ans++;
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};

int cnt[50];//各桁、つまり2^iの桁の1の数
long long diff[50];//xの各ビットに1を立たせた時のfの増減
long long greedy[50];//xの上限を気にしない時に2^iの桁のビットまで決めた時のfの最大値を持つ配列

//dfs(0,k,0,base_sum)で呼ぶ
long long dfs(int depth, long long k, long long now_x, long long now_f){
  if(depth==50){
    return now_f;
  }
  //int undecided = 50 - depth;
  long long x,f;
  long long res=-1;
  if((k>>(49-depth)) & 1){
    //2^49-depth桁目にビットを立てる時
    f = now_f + diff[49-depth];
    x = now_x + 1<<(49-depth);
    
    res = dfs(depth+1,k,x,f);
    
    //2^49-depth桁目にビットを立てない時
    if(depth==49){
      f = now_f;
    }else{
      f = now_f + greedy[48-depth];
    }
    res = max(res,f);
  }else{
    res = dfs(depth+1,k,now_x,now_f);
  }
  return res;
}

      
int main(){
  
  int n;
  cin>>n;
  long long k;
  cin>>k;
  long long a[n];
  REP(i,n){
    cin>>a[i];
  }
  int temp;
  REP(j,50){
    temp = 0;
    REP(i,n){
      temp += (a[i]>>j)%2;
    }
    cnt[j] = temp;
  }
  REP(j,50){
    temp = n- 2*cnt[j];
    diff[j] = (long long)temp<<j;
  }
  
  long long base_sum=0;//xが0の時のfの値
  REP(i,n){
    base_sum += a[i];
  }
  
  REP(j,50){
    if(diff[j]<=0){
      if(j==0){
        greedy[j] = 0;
      }else{
        greedy[j] = greedy[j-1];
      }
    }else{
      if(j==0){
        greedy[j] = diff[j];
      }else{
        greedy[j] = greedy[j-1]+diff[j];
      }
    }
  }
  
  long long ans;
  ans = dfs(0,k,0,base_sum);
  
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<stdio.h>
#include<vector>
using namespace std;
#define rep(s,i,n) for(int i=s;i<n;i++)
#define c(n) cout<<n<<endl;
#define ic(n) int n;cin>>n;
#define sc(s) string s;cin>>s;
#define mod 1000000007
#define f first
#define s second
int a[114514];
signed main(){
	ic(n)	
	rep(0,i,n)cin>>a[i];
	int ans=0;
	rep(0,i,n)rep(0,j,n)if(i!=j)ans+=a[i]*a[j];
	c(ans/2)
}	

Measured memory_bytes: 256
using System;

namespace atcoderA
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            int[] line = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            int X = line[0];
            int A = line[1];
            Console.WriteLine(X < A ? 0 : 10);
        }
    }
}

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

using namespace std;

const int mod = (int)1e9 + 7;

int n,m,dp[1005][1005];

char a[1005][1005];

int solve(int i,int j){
	if(i == n && j == m) return 1;
	if(dp[i][j] != -1) return dp[i][j];
	int cur = 0;
	if(i + 1 <= n && a[i + 1][j] == '.'){
		dp[i + 1][j] = solve(i + 1,j);
		if(dp[i + 1][j] >= mod) dp[i + 1][j] -= mod;
		cur += dp[i + 1][j];
	}
	if(j + 1 <= m && a[i][j + 1] == '.'){
		dp[i][j + 1] = solve(i,j + 1);
		if(dp[i][j + 1] >= mod) dp[i][j + 1] -= mod;
		cur += dp[i][j + 1];
	}
	if(cur >= mod) cur -= mod;
	return cur;
}                 

int main(){
    cin >> n >> m;
    memset(dp,-1,sizeof(dp));
    for(int i = 1; i <= n; i++){
    	for(int j = 1; j <= m; j++){
    		cin >> a[i][j];
    	}
    }
    cout << solve(1,1);
	return 0;
}

Measured memory_bytes: 5376
#include"bits/stdc++.h"
using namespace std;
string st;
int main(){
	cin>>st;
	int ans=114514;
	for(char c='a';c<='z';c++){
		string t=st;
		for(int j=0;;j++){
			bool f=true;
			string next;
			for(int i=0;i<t.length()-1;i++){
				if(t[i]==c){
					next+=t[i];
				}
				else if(t[i+1]==c){
					next+=t[i+1];
				}
				else{
					next+=t[i];
					f=false;
				}
			}
			if(f==true||next.length()==0){
				if(j!=0)ans=min(ans,j+1);
				else ans=0;
				break;
			}
			else t=next;
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

int64_t luca(vector<int64_t>& ans,int n) {
	if (ans.at(n)) return ans.at(n);
	return ans.at(n) = luca(ans, n - 1) + luca(ans, n - 2);
}

int main() {
	int N; cin >> N;
	
	vector<int64_t> ans(N+1, 0);
	ans.at(0) = 2;
	ans.at(1) = 1;
	cout << luca(ans, N) << endl;
}

Measured memory_bytes: 3604
n = int(input())
jobs = []
for i in range(n):
    s = list(map(int,input().split()))
    jobs.append(s)
    

end_jobs = sorted(jobs,key=lambda x:x[1])

cnt = 0
for i in end_jobs:
    cnt += i[0]
    if cnt > i[1]:
        print("No")
        break
else:
    print("Yes")

Measured memory_bytes: 55316
import java.util.Scanner;

/**
 * @author ??\???
 *
 */
public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int s = scanner.nextInt();
		scanner.close();
		
		int h = s / 60 / 60;
		s = s - h * 60 * 60;
		int m = s / 60;
		s = s- m * 60;
		
		System.out.println(h + ":" + m + ":" + s);
	}

}

Measured memory_bytes: 26148
N=input()
L=[0]*(N+1)
for i in range(N*(N-1)/2):
    A,B,C,D=map(int,raw_input().split())
    if C>D:
        L[A]+=3
    elif C<D:
        L[B]+=3
    else:
        L[A]+=1
        L[B]+=1
for i in range(1,N+1):
    cnt=0
    for j in range(1,N+1):
        if L[i]<L[j]:
            cnt+=1
    print cnt+1

Measured memory_bytes: 4368
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main()
{
	int A, B;
	string op;
	cin >> A >> op >> B;

		if (op == "+") {
			cout << A + B << endl;
}
		else if (op == "-") {
			cout << A - B << endl;
		}
}


Measured memory_bytes: 3608
// A

#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll mod=1e9+7;
#define pa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};

int main(){
  string s;
  cin>>s;
  int N = s.size();
  ll cnta(0);
  ll ans(0);
  for (int i(0);i<N;i++){
    if (s[i] == 'A') cnta++;
    else cnta = 0;
    //cout << i << " " << cnta << endl;
    if (s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C'){
      ll cntbc = 0;
      while (s[i+2+cntbc*2 + 1] == 'B' && s[i+2 + cntbc*2 + 2] == 'C'){
        cntbc++;
      }
      //cout <<i <<" " <<  cnta  << " " << cntbc << endl;
      //ans += cnta;
      //ans += cntbc;
      ans += cnta*(cntbc+1);
      i += 2*(cntbc+1);
      //cnta = 1;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        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();
        }
        
        int count = 0;
        boolean flg = true;
        while(flg){
            for(int i = 0; i < n;i++){
                if(a[i]%2 == 0){
                    a[i] /=2;
                    if(i==n-1) count++;
                }else{
                    flg = false;
                    break;
                }
            }
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 22740
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<stdio.h>
#include<stack>
#include<stdlib.h>
using namespace std;
//stacklibrary

int main(){
    stack<int> s;
    string ss;
    int a,b;
    while(cin>>ss){
        if(ss[0]=='+'){
            a=s.top();s.pop();
            b=s.top();s.pop();
            s.push(a+b);
        }else if(ss[0]=='*'){
            a=s.top();s.pop();
            b=s.top();s.pop();
            s.push(a*b);
        }else if(ss[0]=='-'){
            a=s.top();s.pop();
            b=s.top();s.pop();
            s.push(b-a);
        }else{
            s.push(atoi(ss.c_str()));
        }
        
        
    }
    cout<<s.top()<<endl;

return 0;
}



Measured memory_bytes: 3156
N = int(input())
A = [0] * 101010
for i in range(N):
    a, b = map(int, input().split())
    A[a] += 1
    A[b+1] -= 1
ans = 1
cuma = A[0]
for i, a in enumerate(A[1:], 1):
    cuma += a
    if cuma >= i-1:
        ans = i
print(ans-1)



Measured memory_bytes: 7040
#include <iostream>
#include <queue>
#include <string>
using namespace std;

int main(void){
    queue<string> N;
    queue<int> T;
    int n,q,now=0;
    cin>>n>>q;
    for(int i=0;i<n;i++){
        string na;int ti;
        cin>>na>>ti;
        N.push(na);T.push(ti);
    }
    while(!T.empty()){
        string fn=N.front();
        int ft=T.front();
        N.pop();T.pop();
        if(ft-q<=0){
            now+=ft;
            cout<<fn<<" "<<now<<endl;
        }else{
            now+=q;
            ft-=q;
            N.push(fn);T.push(ft);
        }
        
    }
    return 0;
    
}



Measured memory_bytes: 5684