akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

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

		String[] s = br.readLine().split(" ");
		int a = Integer.parseInt(s[0]);
		int b = Integer.parseInt(s[1]);
		int c = Integer.parseInt(s[2]);

		if(a + b + c <= 21)
			System.out.println("win");
		else
			System.out.println("bust");
	}
}


Measured memory_bytes: 21204
#include<iostream>

using namespace std;

int n, a[100009];

int Partition(int p, int r){
  int x=a[r];
  int i=p-1;
  for(int j=p;j<r;j++){
    if(a[j]<=x){
      i++;
      swap(a[i], a[j]);
    }
  }
  swap(a[i+1], a[r]);
  return i+1;
}

int main(){
  cin >> n;
  for(int i=0;i<n;i++)cin >> a[i];
  int idx = Partition(0, n-1);
  for(int i=0;i<n;i++){
    if(i==idx)cout << '[';
    cout << a[i];
    if(i==idx)cout << ']';
    cout << (i<n-1?' ': '\n');
  }
}


Measured memory_bytes: 3436
#include <bits/stdc++.h>
using namespace std;
int main(){
int  N , x;
cin >> N >> x;
vector<int> A(N);
for (int i = 0; i < N; i++) {
  cin >> A.at(i);
}
sort(A.begin(), A.end());
for (int i = 0; i < N; i++) {
x=x-A.at(i);
if (x<0) {
      cout <<i<< endl;
      break;
    }
}
if(x>0)
cout << N-1 << endl;
if(x==0)
cout << N << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
#define P pair<int,ll>
const int MOD=1e9+7;
const ll INF=2e18;



int main() {
    ios_base::sync_with_stdio(false);

    int h1,m1,h2,m2,k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    int ans=max(h2*60+m2-(h1*60+m1)-k,0);
    cout << ans << endl;
    return 0;   
}


Measured memory_bytes: 3652
#include <iostream>

int main() {
	int n;
	std::cin >> n;
	int a[1000];
	for (int i = 0; i < n; ++i) {
		std::cin >> a[i];
	}
	for (int i = n - 1; i >= 1; --i) {
		std::cout << a[i] << " ";
	}
	std::cout << a[0] << std::endl;
}


Measured memory_bytes: 3088
using System;
using System.Linq;

namespace arc063_b
{
	class Program
	{
		static void Main(string[] args)
		{
			int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
			int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
			int min = int.MaxValue;
			int maxsa = int.MinValue; int maxsacount = 1;
			for (int i = 0; i < x[0]; i++)
			{
				if (a[i] < min) min = a[i];
				if (a[i] - min > maxsa)
				{
					maxsa = a[i] - min; maxsacount = 1;
				}
				else if (a[i] - min == maxsa) maxsacount++;
			}
			Console.WriteLine(maxsacount);
		}
	}
}

Measured memory_bytes: 21728
import sys

input = sys.stdin.readline


class UnionFind:
    """Union Find class.

    "Path compression" and "Union by rank" are used.

    References:
        <https://en.wikipedia.org/wiki/Disjoint-set_data_structure>
    """

    def __init__(self, N):
        self.N = N
        self.__make_set()

    def __make_set(self):
        self._parent = list(range(self.N + 1))
        self._rank = [0] * (self.N + 1)
        self._size = [1] * (self.N + 1)

    def find(self, x):
        if self._parent[x] != x:
            self._parent[x] = self.find(self._parent[x])
        return self._parent[x]

    def union(self, x, y):
        x_root = self.find(x)
        y_root = self.find(y)

        if x_root == y_root:
            return

        x_rank = self._rank[x_root]
        y_rank = self._rank[y_root]
        if x_rank > y_rank:
            self._parent[y_root] = x_root
            self._size[x_root] += self._size[y_root]
        elif x_rank < y_rank:
            self._parent[x_root] = y_root
            self._size[y_root] += self._size[x_root]
        else:
            self._parent[y_root] = x_root
            self._rank[x_root] += 1
            self._size[x_root] += self._size[y_root]

    def same_set(self, x, y):
        return self.find(x) == self.find(y)

    def size(self, x):
        return self._size[self.find(x)]


def main():
    N, M = map(int, input().split())
    uf = UnionFind(N)
    for _ in range(M):
        X, Y, _ = map(int, input().split())
        uf.union(X, Y)

    s = set()
    for i in range(1, N + 1):
        s.add(uf.find(i))

    ans = len(s)
    print(ans)


if __name__ == "__main__":
    main()


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

using namespace std;

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

typedef long long ll;

int main() {
    ll X, Y, Z, K;
    cin >> X >> Y >> Z >> K;

    vector<ll> a(X), b(Y), c(Z);
    rep(i, X) cin >> a[i];
    rep(i, Y) cin >> b[i];
    rep(i, Z) cin >> c[i];
    sort(a.begin(), a.end(), greater<>());
    sort(b.begin(), b.end(), greater<>());
    sort(c.begin(), c.end(), greater<>());

    vector<ll> subtot;
    for (auto aa:a) {
        for (auto bb:b) {
            subtot.emplace_back(aa + bb);
        }
    }
    sort(subtot.begin(), subtot.end(), greater<>());
    subtot.resize(K);

    vector<ll> res;
    for (auto st:subtot) {
        for (auto cc:c) {
            res.emplace_back(st + cc);
        }
    }
    sort(res.begin(), res.end(), greater<>());

    for (int i = 0; i < K; ++i) {
        cout << res[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 43368
n, m = gets.split.map(&:to_i)
students = []
n.times { students << gets.split.map(&:to_i) }
checkpoints = []
m.times { checkpoints << gets.split.map(&:to_i) }
students.each do |x, y|
  puts checkpoints.index(checkpoints.min_by { |item| (item[0] - x).abs + (item[1] - y).abs }) + 1
end


Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
int main()
{
    char S[3];
    int ramen=700;
    for(int i=0;i<3;i++)
        cin>>S[i];
    for(int i=0;i<3;i++)
    {
        if(S[i]=='o')
            ramen+=100;
    }
    cout<<ramen;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 1000005
#define ll long long int 	
#define MP make_pair
#define pb push_back
#define ppb pop_back
#define sp " "
#define endl "\n"
#define fi first
#define se second
#define ii pair<int,int>
#define lli pair<ll,ll>
#define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
#define fast2 freopen ("badhair.gir","r",stdin);freopen ("badhair.cik","w",stdout);
#define mod 1000000007
#define fs(x,y) for(ll i=1;i<=y;i++) cin>>x[i]
#define fo(i,x,y) for(ll i=x;i<=y;i++)
#define INF 1000000000005
using namespace std;

ll n,m,ar[N],sum,t;



int main()
{
	fast;
	cin>>n;
	cout<<n*n;
}



/*     cd onedrive\desktop\kod
cls

Sinav:21-22 aralik
Aciklama: Muhtemelen 25 aralik
*/

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#define ft first
#define sc second
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) (a)=max(a, b)
#define chmin(a, b) (a)=min(a, b)
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;

/*
 for(i=0; i<N; i++)
   cin >> a[i];
*/

vector<ll> g[MAX];

int main(void) {
  ll i, j, k;

  ll N, M;
  cin >> N >> M;
  ll H[MAX];
  
  for(i=0; i<N; i++) {
    cin >> H[i];
  }
  
  for(i=0; i<M; i++) {
    ll a, b;
    cin >> a >> b;
    a--; b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  
  ll ans=0;
  for(i=0; i<N; i++) {
    
    ll f=1;
    for(j=0; j<g[i].size(); j++) {
      ll u=g[i][j];
      if(H[i]<=H[u]) f=0;
    }
    
    ans+=f;
  }
  
  pt(ans);
  
}
 


Measured memory_bytes: 10300
#include <stdio.h>
int main(void){
    int m , n ;
    scanf("%d %d" , &m , &n);
    int gyo_1[100][100] ;
    int gyo_2[100] ;
    int i , j ;
    int a ;
    
    //set gyo_1
    
    for(i = 0 ; i < m ; i++){
        for(j = 0 ; j < n ; j++){
            scanf("%d" , &gyo_1[i][j]);
        }
    }
    
    //set gyo_2
    for(i = 0 ; i < n ; i++){
        scanf("%d" , &gyo_2[i]);
    }
    
    for(i = 0 ; i < m ; i++){
        a = 0;
        for(j = 0 ; j < n ; j++){
            a += gyo_1[i][j] * gyo_2[j];
        }
        printf("%d\n" , a);
    }
    return 0;
}


Measured memory_bytes: 2128
while True:
	dic = {}
	n,w,d = map(int,input().split(" "))
	if n == 0 and w == 0 and d == 0:
		break
	dic[1] = (w,d)
	for i in range(n):
		p,s = map(int,input().split(" "))
		W,H = dic[p]
		for j in range(p,i+1):
			dic[j] = dic[j+1]
		cycle = 2*(H+W)
		s %= cycle
		if s < W or ((H+W) < s and s < (W+H+W)):
			if W < s:
				s -= (H+W)
			dic[i+1] = (min(s,W-s),H)
			dic[i+2] = (max(s,W-s),H)

		elif (W < s and s < (H+W)) or ((W+H+W) < s):
			if s > (H+W):
				s -= (W+H+W)
			else:
				s -= W
			dic[i+1] = (W,min(s,H-s))
			dic[i+2] = (W,max(s,H-s))

	sq = list(dic.values())
	sq.sort(key=lambda x:x[0]*x[1])
	for i in range(len(sq)-1):
		print(sq[i][0]*sq[i][1],end=" ")
	print(sq[len(sq)-1][0]*sq[len(sq)-1][1])










Measured memory_bytes: 5632
#include <iostream>
#include <cmath>
#include <vector>
#include <set>
#include <string>
#include <algorithm>

constexpr int INF = 10000001;

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    int n, u, k, vv, cc;
    std::cin >> n;
    std::vector<std::vector<int>> v(n), c(n);
    std::vector<int> d(n), p(n);
    std::set<int> v_s, s;
    for (int i=0; i<n; i++) {
        std::cin >> u >> k;
        for (int j=0; j<k; j++) {
            std::cin >> vv >> cc;
            v[u].push_back(vv);
            c[u].push_back(cc);
        }
        d[i] = INF;
        v_s.insert(i);
    }
    d[0] = 0;
    //v_s.erase(0);

    while (not v_s.empty()) {
        int mind=INF+1;
        int minnode;
        auto iter = v_s.begin();
        for (int i=0; i<v_s.size(); i++,iter++) {
            if (d[*iter] < mind) {
                mind = d[*iter];
                minnode = *iter;
            }
        }
        v_s.erase(minnode);
        s.insert(minnode);
        for (int i=0; i<v[minnode].size(); i++) {
            if (v_s.find(v[minnode][i]) != v_s.end() and mind + c[minnode][i] < d[v[minnode][i]]) {
                d[v[minnode][i]] = mind + c[minnode][i];
                p[v[minnode][i]] = minnode;
            }
        }
    }

    for (int i=0; i<n; i++) {
        std::cout << i << " " << d[i] << "\n";
    }

    return 0;
}


Measured memory_bytes: 7908
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var N = sc.ReadInt();
        var A = sc.ReadIntArray(N);
        var o = A.Distinct().Count();
        var d = N - o;

        var ans = 0;
        if (d % 2 == 0)
        {
            ans = o;
        }
        else
        {
            ans = o - 1;
        }
        Console.WriteLine(ans);
    }
    static Scanner sc = new Scanner();
}

class Scanner
{
    string[] S = new string[0];
    int Index = 0;
    char[] Separators = new char[] { ' ' };

    public string Next()
    {
        if (this.Index < this.S.Length) return this.S[this.Index++];
        var line = "";
        while (line == "") line = Console.ReadLine();
        this.S = line.Split(this.Separators, StringSplitOptions.RemoveEmptyEntries);
        if (this.S.Length == 0) return this.Next();
        this.Index = 0;
        return this.S[this.Index++];
    }
    public string ReadStr()
    {
        return this.Next();
    }
    public char ReadChar()
    {
        return this.Next()[0];
    }
    public int ReadInt()
    {
        return int.Parse(this.Next());
    }
    public uint ReadUInt()
    {
        return uint.Parse(this.Next());
    }
    public long ReadLong()
    {
        return long.Parse(this.Next());
    }
    public double ReadDouble()
    {
        return double.Parse(this.Next());
    }
    public int[] ReadIntArray(int n)
    {
        var array = new int[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadInt();
        }
        return array;
    }
    public long[] ReadLongArray(int n)
    {
        var array = new long[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadLong();
        }
        return array;
    }
    public double[] ReadDoubleArray(int n)
    {
        var array = new double[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadDouble();
        }
        return array;
    }
    public char[] ReadCharArray(int n)
    {
        var array = new char[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadChar();
        }
        return array;
    }
    public string[] ReadStrArray(int n)
    {
        var array = new string[n];
        for (int i = 0; i < array.Length; i++)
        {
            array[i] = this.ReadStr();
        }
        return array;
    }
}


Measured memory_bytes: 24160
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define int long long
#define all(a) a.begin(), a.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

map<int, int> mp;

void prime_factor(int n){
    for(int i = 2; i * i <= n; i++){
        while(n % i == 0){
            ++mp[i];
            n /= i;
        }
    }
    if(n != 1) mp[n]++;
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    for(int i = 2; i <= n; i++) prime_factor(i);
    int c[1010] = {};
    for(auto it = mp.begin(); it != mp.end(); it++){
        c[it -> second]++;
    }
    for(int i = 1000; i >= 0; i--) c[i] += c[i + 1];
    int ans = 0;
    ans += c[74] + c[24] * (c[2] - 1) + c[14] * (c[4] - 1) + c[4] * (c[4] - 1) / 2 * (c[2] - 2);
    cout << ans << endl;
}

Measured memory_bytes: 256
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")
#include<bits/stdc++.h>
#define F first
#define S second
#define vec vector
#define ms multiset
#define pb push_back
#define pf push_front
#define pll pair<ll,ll>
#define pdd pair<ld, ld>
#define pq priority_queue
#define umap unordered_map
#define uset unordered_set
#define pii pair<int, int>
#define pnn pair<Node*, Node*>
#define uid uniform_int_distribution
#define FILE ifstream in("board.in");ofstream out("board.out");
#define fast cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);cout.sync_with_stdio(0);
using namespace std;
typedef string str;
typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); //uid<int> u1(5, 10); u1(rnd);

int main() {
    fast;
    str t; cin>>t;
    if(t[0]==t[1] || t[1]==t[2] || t[2]==t[3]) cout<<"Bad";
    else cout<<"Good";
}

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

int main(){
    int A, B, C;
    cin >> A >> B >> C;
    bool ans = false;
    if(A>=C && C>=B){
	ans = true;
    }
    else if(B>=C && C>=A){
	ans = true;
    }

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




Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    S = int(rl())
    x1, y1 = 0, 0
    x2, y2 = 1000000000, 1
    x3 = (x2 - S % x2) % x2
    y3 = (S + x3) // x2
    print('{} {} {} {} {} {}'.format(x1, y1, x2, y2, x3, y3))


if __name__ == '__main__':
    solve()


Measured memory_bytes: 3060
package main

import "fmt"

func main() {
	var n int

	fmt.Scan(&n)
	fmt.Println(solve(n))
}

func solve(n int) int {
	r := 0

	for a := 1; a <= n-1; a++ {
		r += (n - 1) / a
	}

	return r
}

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

int main()
{
    int H, W;
    cin >> H >> W;
    vector<vector<char>> tate1(H, vector<char>(W));
    vector<vector<char>> tate2(H, vector<char>(W));

    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W;j++){
            cin >> tate1.at(i).at(j);
            tate2.at(i).at(j) = tate1.at(i).at(j);
        }
    }
    for (int i = 0; i < H; i++)
    {
        for (int j = 0; j < W; j++)
        {
            cout << tate1.at(i).at(j);
        }
        cout << endl;
        for (int j = 0; j < W; j++)
        {
            cout << tate2.at(i).at(j);
        }
        cout << endl;
    }
}

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

int main(void){
    vector<int> m(2), d(2);
    rep(i, 2){
        cin >> m.at(i) >> d.at(i);
    }
    
    int flag = 1;
    if(m.at(0) == m.at(1)) flag = 0;

    cout << flag << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define MAX 2000005
#define MOD 1000000007
#define MOD2 998244353
#define pb push_back
#define mp make_pair
#define pii pair<ll,ll>
#define vi vector<ll>
#define vp vector<pii>
#define all(v) v.begin(),v.end()
#define sz(x) (ll)x.size()
#define F first
#define S second
#define FOR(i,a,b) for(ll i=a;i<b;++i)
#define ROF(i,a,b) for(ll i=a;i>=b;--i)
#define trace(x) cerr<<#x<<": "<<x<<'\n';
typedef long long ll;
using namespace std;
//using namespace __gnu_pbds;
//#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>

ll mexp(ll a, ll b){
    ll ans=1;
    a%=MOD;
    while(b){
        if(b&1) ans=ans*a%MOD;
        b>>=1;
        a=a*a%MOD;
    }
    return ans;
}

int main(){
    IOS

    int n,m,x;
    cin>>n>>m>>x;
    int c=0,d=0;
    FOR(i,0,m){
        int j;
        cin>>j;
        if(j<x){
            c++;
        }
        else{
            d++;
        }
    }
    cout<<min(c,d);



    cerr<<"Time: "<<1.0/CLOCKS_PER_SEC<<" ms"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;


void solve()
{
    int a[] = { 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 };
    int n;
    scanf("%d", &n);
    printf("%d\n", a[n - 1]);
    return;
}

int main(int argc, char* argv[])
{
#if 1
    solve();
#else
    int T; scanf("%d", &T);
    while(T--) {
        solve();
    }
#endif
    return 0;
}


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

int main() {
  int k,n;cin>>k>>n;
  vector<int> a(n);
  rep(i,n)cin>>a[i];
  a.push_back(a[0]+k);
  int l=0;
  rep(i,n)l=max(l,a[i+1]-a[i]);
  int ans=k-l;
  cout<<ans<<endl;
}

Measured memory_bytes: 4824
#include <bits/stdc++.h>
 using namespace std;
 using pii = pair<int, int>;
 using ll = long long;
 #define rep(i, j, n) for(int i = j; i < (int)(n); i++)
 const ll MOD = 1000000007;
 const int INFI = 1000000000;
 const ll INFL = (1LL << 60);

 ll com(ll N, ll R) {
     if (R < 0 || R > N) return 0;
     else if (R == 1) return N;
     else if (R == 2) return N * (N - 1) / 2;
     else return N * (N - 1) * (N - 2) / 6;
 }

 ll pow(ll N, ll k) {
     ll res = 1;
     for (int i = 0; i < k; i++) res *= N;
     return res;
 }

 string S;
 int N, K;

 ll solve(int i, int k, int smaller) {
     if (i == N) {
         if (k == 0) return 1;
         else return 0;
     }
     if (k == 0) return 1;

     if (smaller) return com(N-i, k) * pow(9, k);

     else {
         if (S[i] == '0') return solve(i + 1, k, false);
         else {
             ll zero = solve(i + 1, k, true);
             ll aida = solve(i + 1, k - 1, true) * (S[i] - '1');
             ll icchi = solve(i + 1, k - 1, false);
             return zero + aida + icchi;
         }
     }
 }

 int main() {
     cin >> S >> K;
     N = S.size();
     cout << solve(0, K, false) << endl;
 }


Measured memory_bytes: 256
n_rectangles = 0
n_rhombics   = 0

$<.each_line do |line|
  a, b, c = line.split(",").map(&:to_i)
  if a == b
    n_rhombics += 1
  elsif a**2 + b**2 == c**2
    n_rectangles += 1
  end
end

puts n_rectangles
puts n_rhombics

Measured memory_bytes: 8508
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<queue>

using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int> >;
using pii = pair<int, int>;
using ppi = pair<pii, int>;

int f_dir[2][4] = {{-1, 0, 1, 0}, {0, 1, 0, -1}}; //↑→↓←
int e_dir[2][8] = {{-1, -1, -1, 0, 0, 1, 1, 1}, {-1, 0, 1, -1, 1, -1, 0, 1}};
bool is_in_field(int y, int x, int h, int w){
  return (y >= 0 && y < h && x >= 0 && x < w);
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int ti = clock();
  // start-----------------------------------------------
  char a; cin >> a;
  if(a <= 'Z') cout << 'A' << endl;
  else cout << 'a' << endl;

  // end-----------------------------------------------
  // cerr << 1.0 * (clock() - ti) / CLOCKS_PER_SEC << endl;
}


Measured memory_bytes: 3608
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int a,b;
	while(cin>>a>>b){
		if(a==0 && b==0)
		break;
		int n,p,q;
		cin>>n;
		int x[a+1][b+1],y[a+1][b+1];
		for(int i=0;i<a+1;i++){
			for(int j=0;j<b+1;j++){
				x[i][j]=0;
				y[i][j]=0;
			}
		}
		for(int i=0;i<n;i++){
			cin>>p>>q;
			y[p][q]=1;
		}
		for(int j=1;j<b+1;j++){
			for(int i=1;i<a+1;i++){
				if(i==1 && j==1)
				x[i][j]=1;
				else if(y[i][j]!=1)
				x[i][j]=x[i-1][j]+x[i][j-1];
			}
		}
		cout<<x[a][b]<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
from itertools import accumulate
n = int(input())
l = list(map(int,input().split()))
suml = sum(l)
accl = list(accumulate([0]+l))
ans = float('Inf')
for i in range(1,n):
    x = accl[i]
    j = abs(2*x - suml)
    ans = min(ans,j)
print(ans)

Measured memory_bytes: 24172
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 2 * 1e5 + 1;
vector <int> edge[MAX_N];
vector <int> ans(2 * 1e5 + 1);
vector <int> w(2 * 1e5 + 1, 0);
vector <bool> flg(2 * 1e5 + 1, false);
void dfs(int n) {
  flg[n]  = true;
  ans[n] += w[n];
  for (auto itr = edge[n].begin(); itr != edge[n].end(); itr++) {
	  if (!flg[*itr]) {
		  ans[*itr] += ans[n];
		  dfs(*itr);
		}
	}
}

int main() {
  int n, q;
  cin >> n >> q;
  for (int i = 0; i < n - 1; i++) {
	  int a, b;
	  cin >> a >> b;
	  edge[a].push_back(b);
	  edge[b].push_back(a);
	}

  for (int i = 0; i < q; i++) {
	  int p, x;
	  cin >> p >> x;
	  w[p] += x;
	}
  dfs(1);
  for (int i = 1; i < n; i++) {
	  cout << ans[i] << " ";
	}
  cout << ans[n] << endl;
  return 0;
}


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

int main() {
	string S,T;
	int c = 0;
	cin >> S >> T;

	rep(i,S.size())
		c += (S.at(i) != T.at(i));
	cout << c << endl;
}

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

set<int> U(set<int> A,set<int> B){
  set<int> S=A;
  set<int>::iterator I=B.begin();
  while(I!=B.end())S.insert(*I),I++;
  return S;
}

set<int> M(set<int> A,set<int> B){
  set<int> S;
  set<int>::iterator I=A.begin();
  while(I!=A.end()){
    if(!B.count(*I))S.insert(*I);
    I++;
  }
  return S;
}

set<int> T(set<int> A,set<int> B){
  set<int> S;
  set<int>::iterator I=B.begin();
  while(I!=B.end()){
    if(A.count(*I))S.insert(*I);
    I++;
  }
  return S;
}

string s;
set<int> V[6];

set<int> dfs(int l,int r){
  set<int> A,B;
  bool f=0,bf=0;
  char cmd=0;
  for(int j=l;j<r;j++){

    if(s[j]=='('){
      int c=1,st=j+1;
      j++;
      for(;c;j++){
	if(s[j]=='(')c++;
	if(s[j]==')')c--;
      }
      j--;
      B=dfs(st,j);
      bf=1;
    }
    
    if('a'<s[j]&&s[j]<'z'){
      if(s[j]=='c')f=1;
      else cmd=s[j];
    }
    
    if('A'<=s[j]&&s[j]<'Z'){
      int nid=s[j]-'A';
      if(s[j]=='U')nid=5;
      B=V[nid];
      bf=1;
    }

    if(bf){
      if(f){
	B=M(V[5],B);
	f=0;
      }
      if(cmd=='u')A=U(A,B);
      if(cmd=='i')A=T(A,B);
      if(cmd=='d')A=M(A,B);
      if(cmd=='s')A=U(M(A,B),M(B,A));
      if(cmd==0)A=B;
      bf=0;cmd=0;
    }
  }
  return A;
}

int main(){
  while(1){
    for(int i=0;i<=5;i++)V[i].clear();
    while(1){
      char c;
      int x;
      if(cin>>c>>x==0)return 0;
      if(c=='R')break;
      for(int i=0,a;i<x;i++)cin>>a,V[c-'A'].insert(a),V[5].insert(a);
    }

    cin>>s;
    
    set<int> res=dfs(0,s.size());
    set<int>::iterator I=res.begin();
    while(I!=res.end()){
      if(I!=res.begin())cout<<" ";
      cout<<*I;
      I++;
    }
    if(res.size()==0)cout<<"NULL";
    cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 3040
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using P   = pair<ll, ll>;
using mat = vector<vector<ll>>;
typedef string::const_iterator State;
class ParseError {};

void IOS() { ios::sync_with_stdio(false), cin.tie(0); }

constexpr ll INF = 1e16;
constexpr ll INM = 114514;
constexpr ll MOD = 1e9 + 7;
constexpr ld EPS = 1e-12;

template <typename T>
void dump(T x) { cout << x << endl; }
void dumpf(ld x, int t) { cout << setprecision(t) << fixed << x << endl; }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}
inline ll mod(ll a, ll b) {
	if (a > 0) return a % b;
	if (a % b == 0) return 0;
	ll x = -a / b + 1;
	a += x * b;
	return a % b;
}
ll powm(ll a, ll b, ll c) {
	if (b == 0)
		return 1;
	else if (b % 2 == 0) {
		ll d = powm(a, b / 2, c);
		return (d * d) % c;
	} else
		return (a * powm(a, b - 1, c)) % c;
}
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll dx[4] = {1, 0, -1, 0};
ll dy[4] = {0, 1, 0, -1};

int main() {
	IOS();
	ll n;
	cin >> n;
	ll ans = n * (n - 1) / 2;
	dump(ans);
	return 0;
}

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

using namespace std;
using ll = long long int;
using pii = pair<int, int>;
using pil = pair<int, ll>;

int H, W, N;
int sr, sc;
string S, T;

int main() {
	cin >> H >> W >> N;
	cin >> sr >> sc;
	cin >> S >> T;

	int l = 1;
	int r = W;
	int u = 1;
	int d = H;

	switch (S[N - 1])
	{
	case 'L':
		l++;
		break;
	case 'R':
		r--;
		break;
	case 'U':
		u++;
		break;
	case 'D':
		d--;
		break;
	default:
		break;
	}
	bool is_possible = true;
	for (int i = N - 2; i >= 0; i--)
	{
		switch (T[i])
		{
		case 'L':
			r = min(r + 1, W);
			break;
		case 'R':
			l = max(l - 1, 1);
			break;
		case 'U':
			d = min(d + 1, H);
			break;
		case 'D':
			u = max(u - 1, 1);
			break;
		default:
			break;
		}
		switch (S[i])
		{
		case 'L':
			l++;
			break;
		case 'R':
			r--;
			break;
		case 'U':
			u++;
			break;
		case 'D':
			d--;
			break;
		default:
			break;
		}
		if (!(l <= r and u <= d)) {
			is_possible = false;
			break;
		}
	}
	if (!(u <= sr and sr <= d and l <= sc and sc <= r)) {
		is_possible = false;
	}

	if (is_possible) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}

	return 0;
}


Measured memory_bytes: 776
eval"A,B,C,D,*X="+`tr ' ' ,`
A.upto(C){|i|s=0
X=(0..D).map{|j|s=i==A&&j==B ? 1:(X[j].to_i*j+s*i-X[j-D-2].to_i*~-i*~-j)%998244353}}
p X[D]

Measured memory_bytes: 54876
n,m = map(int, input().split())
l = [0] * n

ac = 0
wa = 0
ac_done = [False] * n

for _ in range(m):
    p, s = input().split()
    p = int(p)
    if ac_done[p-1]:
        continue
    else:
        if s == 'AC':
            ac += 1
            wa += l[p-1]
            ac_done[p-1] = True
        else:
            l[p-1] += 1 

print(ac,wa)

Measured memory_bytes: 10164
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
//自作関数
template<class T> ll llpow(T x,T n){ll ans=1;while(n--){ans*=x;}return ans;}

#define rep(i,n) for(ll i=0;i<(ll)n;i++)
#define rep2(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)

ll mod=1e9+7;
long long INF = 1LL<<60;
ll n,m;
ll fact(ll x){
    ll ans=1;
    ll temp=x;
    while(temp){
        ans*=temp;
        ans%=mod;
        temp--;
    }
    return ans;
}
int main(){
    cin>>n>>m;
    if(abs(m-n)>1){
        cout<<0<<endl;
    }else if(abs(m-n)==1){
        cout<<fact(m)*fact(n)%mod<<endl;
    }
    else if(m==n){
        cout<<(fact(m)*fact(n)%mod)*2%mod<<endl;
    }
    return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
bool AC[100005];
int WA[100005];

int main(){
	int n,m;
	cin>>n>>m;
	
	int correct=0;
	int wrong = 0;
	
	while(m--){
		int problem;
		string verdict;
		cin>>problem>>verdict;
		
		
		if(verdict[0]=='A'){
			if(AC[problem]) continue;
			else{
				AC[problem] = true;
				correct++;
              	wrong+=WA[problem];
			}	
		}
		else{
			if(AC[problem]) continue;
			else{
				WA[problem]++;
			}
		}
	}
	cout<<correct<<" "<<wrong<<'\n';
}

Measured memory_bytes: 4084
#include<bits/stdc++.h>
using namespace std;
const int N=1e3;
int main(){
	ios::sync_with_stdio(0);
	int n;
	char a[N];
	scanf("%d%s",&n,a);
	if(n%2) {puts("No");return 0;}
	int s=n/2;
	for(int i=0;i<s;i++){
        if(a[i]!=a[i+s]) {puts("No");return 0;}
	}
	puts("Yes");
	return 0;
}


Measured memory_bytes: 256
from itertools import combinations

def insert(s:str, ind:tuple):
    ind = list(ind)
    for i in range(0, len(ind)):
        ind[i] += i
        s = s[:ind[i]] + "+" + s[ind[i]:]
    else:
        return s
        
s = input()
ans = int(s)
for i in range(1, len(s)):
    for comb in combinations(range(1, len(s)), i):
        ans += eval(insert(s, comb))
else:
    print(ans)

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

// Contest: AtCoder Grand Contest 039 (https://atcoder.jp/contests/agc039)
// Problem: 

using namespace std;

using ll = int64_t;
using u64 = uint64_t;
using u32 = uint32_t;

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

    int n; cin >> n;
    vector<vector<int>> adj(n);
    for (int i = 0; i < n; ++i) {
        string s; cin >> s;
        for (int j = 0; j < n; ++j)
            if (s[j] == '1')
                adj[i].emplace_back(j);
    }

    int mx = -1;
    for (int i = 0; i < n; ++i) {
        vector<int> level(n, -1);
        level[i] = 1;
        queue<int> q;
        q.push(i);
        while (!q.empty()) {
            auto v = q.front(); q.pop();
            for (auto nei : adj[v]) {
                if (level[nei] == -1) {
                    level[nei] = level[v] + 1;
                    q.push(nei);
                }
            }
        }

        bool valid = true;
        for (int j = 0; j < n; ++j)
            for (auto nei : adj[j])
                valid &= abs(level[j] - level[nei]) == 1;
        if (valid)
            mx = max(mx, *max_element(begin(level), end(level)));
    }

    cout << mx << '\n';

    return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
using namespace std;
#define MAX 26

int hight[MAX];
int depth[MAX];

struct Node {
	int parent;
	int lchild;
	int rchild;
};

Node tree[MAX];


void getDepth(int node, int dep)
{
	depth[node] = dep;

	if (tree[node].lchild != -1)
		getDepth(tree[node].lchild, dep + 1);

	if (tree[node].rchild != -1)
		getDepth(tree[node].rchild, dep+1);

}
int getHight(int node)
{
	int height_l=-1, height_r=-1;

	if (tree[node].lchild != -1)
		height_l = getHight(tree[node].lchild);

	if (tree[node].rchild != -1)
		height_r = getHight(tree[node].rchild);

	return hight[node] = max(height_l+1,height_r+1);
}
int getSibling(int node)
{
	if (tree[node].parent == -1)
		return -1;
	if (tree[tree[node].parent].lchild == node)
		return tree[tree[node].parent].rchild;
	else
		return tree[tree[node].parent].lchild;
}

void print(int node)
{
	cout << "node " << node << ": parent = " << tree[node].parent << ", sibling = ";

	cout << getSibling(node) << ", degree = ";
	if (tree[node].lchild != -1 && tree[node].rchild != -1)
		cout << 2 << ", ";
	else if (tree[node].lchild != -1 || tree[node].rchild != -1)
		cout << 1 << ", ";
	else
		cout << 0 << ", ";

	cout << "depth = " << depth[node] << ", ";
	cout << "height = " << hight[node] << ", ";
	if (tree[node].parent == -1)
		cout << "root" << endl;
	else if (tree[node].rchild == -1&&tree[node].lchild == -1)
		cout << "leaf" << endl;
	else
		cout << "internal node" << endl;

}
int main()
{
	int n, root;
	int rchild, lchild;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		tree[i].lchild = -1;
		tree[i].parent = -1;
		tree[i].rchild = -1;
	}
	for (int i = 0; i < n; i++)
	{
		int node;
		cin >> node >>lchild >> rchild;

		tree[node].lchild = lchild;
		tree[node].rchild = rchild;

		if (lchild != -1)
			tree[lchild].parent = node;
		if (rchild != -1)
			tree[rchild].parent = node;
	}
	for (int i = 0; i < n; i++)                 //确定根节点
	{
		if (tree[i].parent == -1)
		{
			root = i;
			break;
		}
	}
	getHight(root);
	getDepth(root, 0);
	for (int i = 0; i < n; i++)                 //打印
	{
		print(i);
	}
	return 0;
}


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

int main() {
  int a;
  cin>>a;
  vector<int> vec(a);
  vector<int> vecb(a);
  
  for(int i=0;i<a;i++){
   cin>>vec.at(i);
  }
  for(int i=0;i<a;i++){
   cin>>vecb.at(i);
  }

  int answer=0;
  for(int i=0;i<a;i++){
    if(vec.at(i)>vecb.at(i)){
      answer+=vec.at(i);
      answer-=vecb.at(i);
    }
  }
  cout<<answer<<endl;  
}

Measured memory_bytes: 256
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<unordered_map>
#include<array>
#include<map>
#include<bitset>
#include<iomanip>
#include<list>
using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define RE return 0
//ios::sync_with_stdio(false);
//std::cin.tie(0);
//<< setprecision(20)
const llint mod=1e9+7;
const llint big=1e15+100;
const long double pai=3.141592653589793238462643383279502884197;
const long double ena=2.71828182845904523536;
const long double eps=1e-7;
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;}}
template <class T> void soun(T& ar)
{sort(ar.begin(),ar.end());ar.erase(unique(ar.begin(),ar.end()),ar.end());}
llint gcd(llint a,llint b){if(a%b==0){return b;}else{return gcd(b,a%b);}}
llint lcm(llint a,llint b){return a/gcd(a,b) *b;}
int main(void){
	int a,b,i;cin>>a>>b;
	string str;cin>>str;
	for(i=0;i<=(a+b);i++){
		if(('0'<=str[i]&&str[i]<='9')==(i==a)){cout<<"No"<<endl;RE;}
	}
	cout<<"Yes"<<endl;
	RE;
}

Measured memory_bytes: 888
#include <iostream>
using namespace std;
int main(void){
    int n, t, a, h, min = 1e9, palace;
    cin >> n;
    cin >> t >> a;
    for (int i = 0; i < n; i++) {
        cin >> h;
        if (min > abs(1000 * a - (1000 * t - 6 * h))) {
            min = abs(1000 * a - (1000 * t - 6 * h));
            palace = i;
        }
    }
    cout << palace + 1;
}


Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>
#include<deque>
#include<random>
#include<set>

using namespace std;
typedef long long ll;
typedef double lldo;
#define mp make_pair
#define pub push_back
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
ll gcd(ll a, ll b) { if (a % b == 0) { return b; } else  return gcd(b, a % b); }
ll lcm(ll a, ll b) { if (a == 0) { return b; }return a / gcd(a, b) * b; }
template<class T>ll LBI(vector<T>& ar, T in) { return lower_bound(ar.begin(), ar.end(), in) - ar.begin(); }
template<class T>ll UBI(vector<T>& ar, T in) { return upper_bound(ar.begin(), ar.end(), in) - ar.begin(); }

ll A, B;

int main() {
	cin >> A >> B;
	if (A <= 9 && B <= 9) {
		cout << A * B << endl;
	}
	else {
		cout << -1 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
 
using namespace std;
 
int main(){

    int n, p, fish;
    cin >> n;

    int rp = 20; 
    int max_fish = -100;

    for( int i = 0; i < n ; i++ ){
      
      cin >> p >> fish;
      
      if(max_fish < fish || max_fish == fish && rp > p){
	
        rp = p;
        max_fish = fish;
      }
    }
    cout << rp << " " << max_fish << endl;
    return 0;
}

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

int main()
{
  int A, B;
  cin >> A >> B;
  int ans = A * B - A - B + 1;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
def solve(s):
    s = set(s)
    if ("N" in s) and (not "S" in s):
        return "No"
    if ("S" in s) and (not "N" in s):
        return "No"
    if ("W" in s) and (not "E" in s):
        return "No"
    if ("E" in s) and (not "W" in s):
        return "No"
    return "Yes"

s = input()
print(solve(s))


Measured memory_bytes: 3060
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;

//ll mod = 1000000007 ;
//long double pie = acos(-1) ;

//string yorn(bool a){if(a) return"Yes" ; return "No" ;}
//string YorN(bool a){if(a) return"YES" ; return "NO" ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}

int main(){
	ll n ; cin >> n ;
	vll b(n) ;
	for(auto &i:b) cin >> i ;
	vll ans ;
	for(int i=0;i<n;i++){
		ll pos = -1 ;
		ll zero = 0 ;
		for(int j=0;j<n;j++){
			if(j+1-zero==b.at(j)) pos = j ;
			else if(b.at(j)==0) zero++ ;
		}
		if(pos==-1){
			cout << -1 << endl ;
			return 0 ;
		}
		ans.push_back(b.at(pos)) ;
		b.at(pos) = 0 ;
	}
	myrev(ans) ;
	for(int i=0;i<n;i++) cout << ans.at(i) << endl ;
}



Measured memory_bytes: 256
#ifdef FAIRLY_LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <iostream>
#include <vector>
using namespace std;

int main() {
#ifdef FAIRLY_LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    int n;
    vector<int> x;

    cin >> n;
    x.resize(n);
    for (int &elem : x) {
        cin >> elem;
    }

    int ans = 1e9;
    for (int i = 0; i <= 100; ++i) {
        int cur_ans = 0;
        for (int elem : x) {
            cur_ans += (elem - i) * (elem - i);
        }
        ans = min(ans, cur_ans);
    }

    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
#include<assert.h>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1LL << 60;
constexpr int INF = 3000000007;
const double INFD = 1e100;
const ll mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
// ----------------------------------------------------------------------------

int main(){
  int N;
  ll K;
  cin >> N >> K;
  vector<ll> A(N);
  for(int i=0; i<N; i++){
    cin >> A[i];
  }
  ll res = 0;
  for(int d=60; d>=-1; d--){
    if(d != -1 && !(K & (1LL<<d))) continue;
    ll tmp=0;
    for(int e=60; e>=0; e--){
      ll mask = (1LL<<e);
      int num=0;
      for(int i=0; i<N; i++){
        if(A[i] & mask) num++;
      }
      if(e>d){
        if(K & mask){
          tmp += mask * (N-num);
        }else{
          tmp += mask * num;
        }
      }else if(e == d){
        tmp += mask * num;
      }else{
        tmp += mask * max(N-num,num);
      }
    }
    chmax(res, tmp);
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <climits>
#include <cctype>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <utility>
#include <map>
#include <set>
#include <bitset>
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define per(i,a,b) for(int i=a;i>=b;--i)
#define rvc(i,S) for(int i=0;i<S.size();++i)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define debug(...) fprintf(stderr,__VA_ARGS__)
using namespace std;

typedef long long LL;
typedef vector<int> vi;
typedef pair<int,int> pii;

int main(){
    int A,B,C;
    cin>>A>>B>>C;
    LL ans=B;
    ans+=min(C,A+B+1);
    cout<<ans<<endl;
    return 0;
}


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

// GCD, LCM
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main()
{
    ll ans =0;
    int A,B,C,K;
    cin>>A>>B>>C>>K;

    ans=min(A,K);

    if(K>(A+B)){
        K-=A+B;
        ans-=K;
    }

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#define pb push_back
#define mpr make_pair
#define pii pair<int, int>
#define ll long long
#define ld long double
#define all(arr) arr.begin(), arr.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define fo(i, l, r) for (int i = l; i <= r; i++)
#define MOD 1000000007
#define mod 998244353
#define pie 3.14159265358979323846264338327950L
#define N 200009
#define M 2000009
#define mid(l, r) l + (r - l) / 2
#define vec vector<int>
#define umap unordered_map<int, int>
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
#define endl "\n"
#define int long long
using namespace std;
 
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};  
int ddx[8]={1,1,0,-1,-1,-1,0,1},ddy[8]={0,1,1,1,0,-1,-1,-1};
ll gcd(ll a,ll b){ if(!a)return b;return gcd(b%a,a);}
ll lcm(ll a, ll b) { return (a*b)/ gcd(a,b);}
 

bool fun(string temp, string s) {
    string ans = temp+temp;
    return ans == s;
}




void test_case() {
    int n;
    cin>>n;
    string s;
    cin>>s;
    bool check = false;

    string temp ="";

    for(int i=0; i<n-1; i++) {
        temp+=s[i];
        if(n%temp.size() == 0 && fun(temp,s)) {
            // cout<<i<<endl;
            check = true;
        }
    }
    if(check) {
        yes;
    } else {
        no;
    }
     
}
    

signed main ()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(20);
 
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
 
    int t = 1;
    // cin >> t;
    while (t--)
    {
        test_case();
    }
}

Measured memory_bytes: 3596
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define DEBUGP(val) cerr << #val << "=" << val << "\n"

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;

int s(ll n) {
  int sum = 0;
  while (n > 0) {
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

void brute(void) {
  int n = 1000000;
  vector<double> t(n);
  REP(i, 1, n) {
    t[i] = (double) i / (double) s(i);
  }
  REP(i, 1, n) {
    bool ok = true;
    REP(j, i + 1, n) {
      if (t[j] <= t[i] - 1e-11) {
        ok = false;
        if (i == 419999) {
          DEBUGP(i);
          DEBUGP(j);
          DEBUGP(t[i]);
          DEBUGP(t[j]);
        }
        break;
      }
    }
    if (ok) {
      cerr << i << " " << t[i] << endl;
    }
  }
}

typedef pair<ll, double> PLD;

int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll k;
  cin >> k;
  ll cur = 1;
  VL pool;
  REP(tap, 0, 15) {
    REP(i, 1, 1000) {
      ll v = i * cur + cur - 1;
      if (v <= 1e15)
        pool.push_back(v);
    }
    cur *= 10;
  }
  sort(pool.begin(), pool.end());
  pool.erase(unique(pool.begin(), pool.end()), pool.end());
  VL meguru(pool.size());
  REP(i, 0, pool.size()) meguru[i] = s(pool[i]);
  VL ans;
  REP(i, 0, pool.size()) {
    bool ok = 1;
    REP(j, i + 1, pool.size()) {
      if (meguru[j] * pool[i] > pool[j] * meguru[i]) {
        ok = 0;
        break;
      }
    }
    if (ok) {
      ans.push_back(pool[i]);
    }
  }
  REP(i, 0, k) cout << ans[i] << endl;
}


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

using namespace std;
typedef long long int ll;



int cost[11][11];


int dp[1200][11];

int doz[11];


int fun(int msk,int lst)
{
    if(lst==1)    return 0;

    int& ret=dp[msk][lst];

    if(ret!=-1)    return ret;

    ret=1000000009;

    for(int i=0;i<10;i++)    {
        if(!(msk&(1<<i)))    {
            ret=min(ret,cost[lst][i]+fun((msk|(1<<i)),i));
        }
    }

    return ret;

}






int main()
{
    int h,w;
    cin>>h>>w;


    for(int i=0;i<10;i++)    {
        for(int j=0;j<10;j++)    {
            cin>>cost[i][j];
        }
    }




    for(int i=0;i<10;i++)    {
        memset(dp,-1,sizeof(dp));
        int mmm=(1<<i);
        doz[i]=fun(mmm,i);
    }

    int ans=0;

    for(int i=0;i<h;i++)    {
        for(int j=0;j<w;j++)    {
            int x;
            cin>>x;
            if(x!=-1)    ans+=doz[x];

        }
    }

    cout<<ans<<endl;




    return 0;
}


Measured memory_bytes: 256