akhauriyash/Code-Regression huggingface dataset:
class UnionFind:
    def __init__(self, N: int):
        """
        N:要素数
        root:各要素の親要素の番号を格納するリスト.
             ただし, root[x] < 0 ならその頂点が根で-root[x]が木の要素数.
        rank:ランク
        """
        self.N = N
        self.root = [-1] * N
        self.rank = [0] * N

    def __repr__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

    def find(self, x: int) -> int:
        """頂点xの根を見つける"""
        if self.root[x] < 0:
            return x
        else:
            while self.root[x] >= 0:
                x = self.root[x]
            return x

    def union(self, x: int, y: int) -> int:
        """x,yが属する木をunion"""
        # 根を比較する
        # すでに同じ木に属していた場合は何もしない.
        # 違う木に属していた場合はrankを見てくっつける方を決める.
        # rankが同じ時はrankを1増やす
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        elif self.rank[x] > self.rank[y]:
            self.root[x] += self.root[y]
            self.root[y] = x
        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            if self.rank[x] == self.rank[y]:
                self.rank[y] += 1

    def same(self, x: int, y: int) -> bool:
        """xとyが同じグループに属するかどうか"""
        return self.find(x) == self.find(y)

    def count(self, x):
        """頂点xが属する木のサイズを返す"""
        return - self.root[self.find(x)]

    def members(self, x):
        """xが属する木の要素を列挙"""
        _root = self.find(x)
        return [i for i in range(self.N) if self.find == _root]

    def roots(self):
        """森の根を列挙"""
        return [i for i, x in enumerate(self.root) 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()}


import sys
input = sys.stdin.readline
n, q = map(int, input().split())
uf = UnionFind(n)
for i in range(q):
    t, u, v = map(int, input().split())
    if t:
        print(int(uf.same(u, v)))
    else:
        uf.union(u, v)


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

int main(){
    int n, m ,x;
    cin >> n >> m >> x;
    
    vector<vector<int>> a(n, vector<int>(m)); //nxmの行列みたいなイメージ
    vector<int> c(n);

    for(int i=0; i<n; i++){
        cin >> c[i];
        for(int j=0; j<m; j++) cin >> a[i][j];
    }

    int ans = 12345678;
    int all = 1<<n;
    for(int mask=0; mask < all; mask++){
        vector<int> level(m);
        int cost = 0;
        for(int i=0; i < n; i++){
            if((mask>>i)&1){
                cost += c[i];
                for(int j=0; j < m; j++){
                    level[j] += a[i][j];
                }
            }
        }
        bool ok = true;
        for(int j=0; j<m; j++){
            if(level[j] < x) ok = false;
        }
        if(ok) ans = min(ans, cost);
    }
    if(ans == 12345678) cout << -1 << endl;
    else cout << ans << endl;
}


Measured memory_bytes: 3644
/* 
   AOJ 1124
   When Can We Meet?
   2015.4.26
 */

#include<stdio.h>

int adjustment_of_schedule(int committee_num, int quorum)
{
  int i, j, target_date = 0, date, convenient_dates_num = 0, num_participant = 0, convenient_date[101] = {0};
  for(i = 0; i < committee_num; i++)
    {
      scanf("%d", &convenient_dates_num);
      for(j = 0 ; j < convenient_dates_num; j++)
	{
	  scanf("%d", &date);
	   convenient_date[date]++;
	}
    }

  for(i = 0; i < 101; i++)
    {
      if(convenient_date[i] >= quorum && convenient_date[i] > num_participant)
	{
	  target_date = i;
	  num_participant = convenient_date[i];
	}
    }

  return target_date;
}



int main(void)
{
  int n, q, date;
  while(1)
    {
      scanf("%d %d", &n, &q);
      if(n == 0 && q == 0)
	{
	  break;
	}

      date = adjustment_of_schedule(n, q);
      printf("%d\n", date);
    }
  return 0;
}

Measured memory_bytes: 600
l, r = map(int, input().split())
if l - r >= 2019:
    print(0)
else:
    n = range(l, r+1)
    min_x = 2018
    for i in range(len(n)-1):
        for j in range(i+1, len(n)):
            cur_x = ((n[i]%2019)*(n[j]%2019))%2019
            min_x = min(cur_x, min_x)
            if min_x == 0:
                break
        if min_x == 0:
                break
    print(min_x)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <deque>
#include <functional>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
    int N, A;
    cin >> N;
    vector<int> vi(N);
    REP(i, N) cin >> vi[i];
    sort(ALL(vi), greater<int>());

    ll ans = 0;
    int n1 = vi[0], n2 = vi[0], h = 1, t = N - 1, c = 0;

    while (h <= t) {
        int h_max = max(abs(n1 - vi[h]), abs(n2 - vi[h]));
        int t_max = max(abs(n1 - vi[t]), abs(n2 - vi[t]));
        if (h_max > t_max) {
            if (abs(n1 - vi[h]) > abs(n2 - vi[h])) {
                ans += abs(n1 - vi[h]);
                n1 = vi[h++];
            }
            else {
                ans += abs(n2 - vi[h]);
                n2 = vi[h++];
            }
        }
        else {
            if (abs(n1 - vi[t]) > abs(n2 - vi[t])) {
                ans += abs(n1 - vi[t]);
                n1 = vi[t--];
            }
            else {
                ans += abs(n2 - vi[t]);
                n2 = vi[t--];
            }
        }
    }

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

Measured memory_bytes: 640
n, a, b = gets.chomp.split(" ").map(&:to_i)
x = gets.chomp.split("")
limit = a + b
totalPassed = 0
overseasPassed = 0
for rank in 1..n do
    i = rank - 1
    if totalPassed < limit
        if x[i] == "a"
            puts "Yes"
            totalPassed += 1
            next
        end
        if x[i] == "b" && overseasPassed + 1 <= b
            puts "Yes"
            totalPassed += 1
            overseasPassed += 1
            next
        end
    end
    puts "No"
end


Measured memory_bytes: 22776
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

int main() {
	string s;
	rep(i,3){
		string s1; cin >> s1;
		s +=s1;
	}

	cout << s[0] << s[4] << s[8] << endl;
}




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

using i64=int64_t;

#define rep(i,x,y) for(i64 i=i64(x),i##_max_for_repmacro=i64(y); i<i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)
 
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif
 
const int inf=1.01e9;
const i64 inf64=4.01e18;
const double eps=1e-9;
 
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

void solve(){
    int A,B,C,X,Y;
    cin >> A >> B >> C >> X >> Y;

    int i=0,ans=inf;
    for(;;){
        int tmp=i*C;
        tmp+=max(0,X-i/2)*A;
        tmp+=max(0,Y-i/2)*B;
        ans=min(ans,tmp);

        if(i>=X*2 and i>=Y*2) break;
        ++i;
    }

    cout << ans << endl;
}

int main(){
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp3
{
    class Program
    {
        static void Main(string[] args)
        {
            long[] n = Console.ReadLine().Split().Select(long.Parse).ToArray();
            long N = n[0];
            long M = n[1];

            long ans = 0;
            if (N == 1 && M == 1) ans = 1;
            else if ((N == 1&&M != 1&&M != 2) ||( M == 1 &&N != 1&&N != 2)) ans = Math.Max(N - 2, M - 2);
            else if (N == 2 || M == 2) ans = 0;
            else ans = (N - 2) * (M - 2);
            Console.WriteLine(ans);
            Console.ReadLine();
        }
    }
}


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

using namespace std;

#define int long long int
#define ld long double
#define F first
#define S second
#define P pair<int,int>
#define pb push_back
#define db(x) cout <<#x<<": "<<x<<'\n';

const int N = 100005;

int32_t main()
{
	ios_base:: sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	// int t;cin>>t;while(t--)
	{
		int i, j, k, n, m;
		string s, t;
		cin >> s >> t;
		n = s.size();
		m = t.size();
		int lcs[n + 1][m + 1] = {};
		for (i = 1; i <= n; i++) {
			for (j = 1; j <= m; j++) {
				if (s[i - 1] == t[j - 1]) {
					lcs[i][j] = 1 + lcs[i - 1][j - 1];
				}
				else {
					lcs[i][j] = max(lcs[i - 1][j], lcs[i][j - 1]);
				}
			}
		}
		// for(i=0;i<=n;i++){
		//     for(j=0;j<=m;j++){
		//         cout<<lcs[i][j]<<" ";
		//     }
		//     cout<<'\n';
		// }
		i = n; j = m;
		string ans;
		while (i > 0 && j > 0) {
			if (s[i - 1] == t[j - 1]) {
				ans += s[i - 1];
				i--; j--;
			}
			else {
				if (lcs[i - 1][j] > lcs[i][j - 1]) {
					i--;
				}
				else {
					j--;
				}
			}
		}
		reverse(ans.begin(), ans.end());
		cout << ans;
	}
}

Measured memory_bytes: 70656
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define forn(i, n) for (ll i = 0; i < (n); i++)
#define fori(i, b, e) for (ll i = (b); i < (e); i++)
#define forr(i, b, e) for (ll i = (b); i >= (e); i--)
#define allele(v) v.begin(), v.end()
#define fi first
#define se second

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin >> s;
	stack<int> st;
	for (char c : s)
	{
		int i = c - '0';
		if (st.empty())
			st.push(i);
		else if (st.top() != i)
			st.pop();
		else
			st.push(i);
	}
	cout << (s.size() - st.size()) << endl;
	return 0;
}

Measured memory_bytes: 720
import java.io.IOException;
import java.io.InputStream;
import java.util.InputMismatchException;

public class Main {
	
	public static void main(String[] args) {
		Task task = new Task();
		task.solve();
	}

	public static class Task {
		static final long MOD = (long) 1e9 + 7;

		public void solve() {
			Scan sc = new Scan();
			int n = (int) sc.scanLong();
			if(n==0){
				System.out.println(0);
				return;
			}
			String got = negativeBase(n, -2);
			System.out.println(got);
		}
		
		public String negativeBase(int integer, int base) {
	        String result = "";
	        int number = integer;
	        while (number != 0) {
	            int i = number % base;
	            number /= base;
	            if (i < 0) {
	                i += Math.abs(base);
	                number++;
	            }

	            result = i + result;
	        }

	        return result;
	    }
	}

	public static class Scan {
		private byte[] buf = new byte[1024];
		private int index;
		private InputStream in;
		private int total;

		public Scan() {
			in = System.in;
		}

		public int scan() {
			if (total < 0)
				throw new InputMismatchException();
			if (index >= total) {
				index = 0;
				try {
					total = in.read(buf);
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
				if (total <= 0)
					return -1;
			}
			return buf[index++];
		}

		public long scanLong() {
			long integer = 0;
			int n = scan();
			while (isWhiteSpace(n))
				n = scan();
			int neg = 1;
			if (n == '-') {
				neg = -1;
				n = scan();
			}
			while (!isWhiteSpace(n)) {
				if (n >= '0' && n <= '9') {
					integer *= 10;
					integer += n - '0';
					n = scan();
				} else
					throw new InputMismatchException();
			}
			return neg * integer;
		}

		public double scanDouble() throws IOException {
			double doub = 0;
			int n = scan();
			while (isWhiteSpace(n))
				n = scan();
			int neg = 1;
			if (n == '-') {
				neg = -1;
				n = scan();
			}
			while (!isWhiteSpace(n) && n != '.') {
				if (n >= '0' && n <= '9') {
					doub *= 10;
					doub += n - '0';
					n = scan();
				} else
					throw new InputMismatchException();
			}
			if (n == '.') {
				n = scan();
				double temp = 1;
				while (!isWhiteSpace(n)) {
					if (n >= '0' && n <= '9') {
						temp /= 10;
						doub += (n - '0') * temp;
						n = scan();
					} else
						throw new InputMismatchException();
				}
			}
			return doub * neg;
		}

		public String scanString() {
			StringBuilder sb = new StringBuilder();
			int n = scan();
			while (isWhiteSpace(n))
				n = scan();
			while (!isWhiteSpace(n)) {
				sb.append((char) n);
				n = scan();
			}
			return sb.toString();
		}

		public char scanChar() {
			int n = scan();
			while (isWhiteSpace(n))
				n = scan();
			return (char) n;
		}

		private boolean isWhiteSpace(int n) {
			if (n == ' ' || n == '\n' || n == '\r' || n == '\t' || n == -1)
				return true;
			return false;
		}
	}
}


Measured memory_bytes: 36896
#include<iostream>

#define _USE_MATH_DEFINES
#include<math.h>

using namespace std;

int main(){

    int a,b,x, vol_half;
    double c;
    double theta;
    scanf("%d", &a);
    scanf("%d", &b);
    scanf("%d", &x);

    vol_half = a * a * b / 2;

    if(x < vol_half){
        c = (double)(2 * x)/(a * b);
        theta = atan2(b, c);
    }else{
        c = (double)((double)(2 * x)/(a * a) - b);
        theta = atan2(b - c, a);
    }

    printf("%.16f\n", theta * 360 / (2*M_PI));


    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
double calc(long long x) {
  int sum = 0;
  long long xx = x;
  while (xx) {
    sum += xx % 10;
    xx /= 10;
  }
  return 1. * x / sum;
}
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  vector<long long> a;
  for (int i = 1; i <= 9999; i++) {
    for (long long j = i; j <= 1e16; j = j * 10 + 9) {
      a.push_back(j);
    }
  }
  sort(a.begin(), a.end());
  a.erase(unique(a.begin(), a.end()), a.end());
  int n = (int) a.size();
  vector<double> b(n);
  for (int i = 0; i < n; i++) {
    b[i] = calc(a[i]);
  }
  for (int i = n - 2; i >= 0; i--) {
    b[i] = min(b[i + 1], b[i]);
  }
  vector<long long> ans;
  for (int i = 0; i < n; i++) {
    if (abs(calc(a[i]) - b[i]) <= 1e-10) ans.push_back(a[i]);
  }
  int k;
  cin >> k;
  for (int i = 0; i < k; i++) {
    cout << ans[i] << '\n';
  }
  return 0;
}

Measured memory_bytes: 2420
#include <vector>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <queue>


using namespace std;

typedef struct process {
    string name;
    int time;
} proc;



int main() {
    int n, q;
    queue<process> Q;
    cin >> n >> q;
    for (int i = 0; i < n; i++) {
        proc p;
        cin >> p.name >> p.time;
        Q.push(p);
    }
    int id = 0;
    int timeSum= 0;
    while (!Q.empty()) {
        proc p = Q.front();
        Q.pop();
        int c = min(p.time,q);
        timeSum += c;
        p.time -= c;
        if(p.time > 0) Q.push(p);
        else cout << p.name << " " << timeSum <<endl;
    }
    return 0;
}


Measured memory_bytes: 6352
#include <vector>
#include <map>
#include <set>
#include <sstream>
#include <iostream>
#include <limits>
#include <algorithm>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <cmath>


using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<pair<int, int>> vii;
typedef stringstream ss;
const int mii = numeric_limits<int>::min();
const int mai = numeric_limits<int>::max();
const ll mil = numeric_limits<long long>::min();
const ll mal = numeric_limits<long long>::max();

#define REP(i, a, b) for(long long i=a; i<=b; ++i)
#define RREP(i, a, b) for(long long i=a; i>=b; --i)
#define PB(x) push_back(x)
#define MP(x, y) make_pair(x, y)

int main(int argc, char **argv) {
    ll n, a, b;
    cin >>n>>a>>b;

    ll res = n%(a+b);

    ll o = (n/(a+b))*a;
    if(res > a) {
        o+= a;
    }
    else {
        o+=res;
    }

    cout << o << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>
#include<climits>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;


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


#define ARRAY_MAX 100005
const int INF = INT32_MAX / 3;
const ll MOD = 1e9 + 7;

int dx[4] = { 1,0,0,-1 };
int dy[4] = { 0,1,-1,0 };


/******************************************************************************************/



/*素因数分解*/
template<typename T>
map<T, T> prime_factorization(T m) {

	map<T, T> tmp;
	for (T i = 2; i * i <= m; i++) {
		while (m % i == 0) {
			tmp[i]++;
			m /= i;
		}
	}
	if (m != 1) {
		tmp[m] = 1;
	}
	return tmp;
}



int main() {

	int n;
	cin >> n;
	
	map<int, int> mp = prime_factorization(n);

	cout << n << ":";
	for (auto itr : mp) {
		for (int i = 0; i < itr.second; i++) {
			cout << " " << itr.first;
		}
	}
	cout << endl;



	return 0;
}


Measured memory_bytes: 3124
using System;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.IO;


namespace SolutionCS
{
    class Program
    {
        static void Main(string[] args)
        {
            checked
            {
                //string[] s;
#if true
                int N = int.Parse(Console.ReadLine());
#else
                s = Console.ReadLine().Split(' ');
                int A = int.Parse(s[0]);
                int B = int.Parse(s[1]);
                int C = int.Parse(s[2]);
#endif


#if true
                /*
                s = Console.ReadLine().Split(' ');
                for (int i = 0; i < N; i++)
                {
                    v[i] = int.Parse(s[i]);
                }
                */
#else
                for (int i = 0; i < N; i++)
                {
                    v[i] = int.Parse(Console.ReadLine());
                }
#endif
                int ans = 0;
                for (int i = 1; i <= N; i++)
                {
                    if ( i <= 9)
                    {
                        ans++;
                    }
                    else if( i >= 100 & i <= 999)
                    {
                        ans++;
                    }
                    else if (i >= 10000 & i <= 99999)
                    {
                        ans++;
                    }
                }


                Console.WriteLine(ans);
            }
        }
    }
}


Measured memory_bytes: 11092
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;

#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}


fn main(){
    let n: usize = read_as_vec()[0];

    let mut w: Vec<i32> = read_as_vec();

    //w.sort();

    let sum: i32 = w.iter().sum();
    let mut right = sum;
    let mut left = 0;
    let mut ans = sum;
    for elem in &w{
        right -= *elem;
        left  += *elem;
        if ans > (right - left).abs(){
            ans = (right - left).abs();
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
let to_char str =
  let len = String.length str in
  let rec inner i acc =
    match i > 0 with
    | false -> str.[0] :: acc
    | true -> inner (i - 1) (str.[i] :: acc)
  in inner (len - 1) []

let is_lower c =
  Char.compare 'a' c <= 0 && Char.compare c 'z' <= 0

let count_lower str =
  List.length (List.filter is_lower (to_char str))

let () =
  let s = read_line() in
  print_endline @@
  let ch = to_char s in
  let ch2 = List.tl (List.tl ch) in
  match (List.hd ch = 'A' &&
         List.mem 'C' ch2 &&
         not (List.nth ch2 (List.length ch2 - 1) = 'C') &&
         (String.length s) - (count_lower s) = 2) with
  | true -> "AC"
  | false -> "WA"

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

struct edge {
    int to, cost;
    edge(int to, int cost) : to(to), cost(cost){};
};

int main() {

    int w, h;
    while(cin >> w >> h, w){
        vector<vector<edge>> G(h*w*4);
        array<int, 4> di{0, 1, 0, -1}, dj{1, 0, -1, 0};
        vector<vector<int>> v(h+2, vector<int>(w+2, -1));
        for (int i = 0; i < h; ++i) {
            for (int j = 0; j < w; ++j) {
                cin >> v[i+1][j+1];
            }
        }
        array<int, 4> costs{};
        for (auto &&k : costs) cin >> k;
        for (int i = 1; i <= h; ++i) {
            for (int j = 1; j <= w; ++j) {
                for (int k = 0; k < 4; ++k) {
                    for (int un = 0; un < 4; ++un) {
                        int l = (k+un)%4;
                        if(!(~v[i+di[l]][j+dj[l]])) continue;
                        int c = (v[i][j] == un ? 0 : costs[un]);
                        i--; j--;
                        G[(i*w+j)*4+k].emplace_back(((i+di[l])*w+j+dj[l])*4+l, c);
                        i++; j++;
                    }
                }
            }
        }
        using P = pair<int, int>;
        vector<int> dist(G.size(), INF<int>);
        priority_queue<P, vector<P>, greater<>> Q;
        dist[0] = 0;
        Q.emplace(0, 0);
        while(!Q.empty()){
            int cost, i; tie(cost, i) = Q.top(); Q.pop();
            if(dist[i] < cost) continue;
            for (auto &&e : G[i]) {
                if(dist[e.to] <= cost + e.cost) continue;
                dist[e.to] = cost + e.cost;
                Q.emplace(dist[e.to], e.to);
            }
        }
        int ans = INF<int>;
        for (int i = 0; i < 4; ++i) {
            ans = min(ans, dist[(h*w-1)*4+i]);
        }
        cout << ans << "\n";
    }
    return 0;
}


Measured memory_bytes: 3312
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define INF 999999999
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;


int a[200000];
int v[200000];

int main(){
  int n,count,count2 = 0;
  cin >> n;
  REP(i,n){
    cin >> a[i];
  }
  REPR(i,n-1){
    count = 0;
    FOR(j,2,n+1){
      if((i+1)*j > n) break;
      count += v[(i+1)*j-1];
    }
    v[i] = abs(a[i] - count)%2;
    count2 += v[i];
  }
  cout << count2 << endl;
  REP(i,n){
    if(v[i]){
      cout << i+1 << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 2432
import Data.List

asciiA = fromEnum 'a'
asciiZ = fromEnum 'z'

specificWords = ["the","that","this"]
containtsWords s = any id $ map (flip isInfixOf s) specificWords

main = do
  codes <- getLines
  mapM_ putStrLn $ map composite codes
  
composite :: String -> String
composite code = plaintext
  where
    plaintextCandidate = map (flip slideString code) [0..(asciiZ - asciiA)]
    plaintext:_ = filter containtsWords plaintextCandidate
  

slideString :: Int -> String -> String
slideString n s = map (slideChar n) s

slideChar :: Int -> Char -> Char
slideChar n c 
  | 'a' <= c && c <= 'z' = slideChar' n c
  | otherwise = c
  where 
    ascii = fromEnum ascii
    slideChar' n c = toEnum $ asciiA + ((fromEnum c - asciiA + n) `mod` (asciiZ - asciiA + 1))

getLines =  do
  s <- getContents
  return $ lines s





Measured memory_bytes: 4088
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;
int a[10];
int ok;
vector <int> n;
vector <int> m;
void bfs(int cur)
{
    if(cur==10)
    {
        ok=1;
        return;
    }
    if(a[cur]>n.back())
    {
        n.push_back(a[cur]);
        bfs(cur+1);
    }
    if(a[cur]>m.back())
    {
        m.push_back(a[cur]);
        bfs(cur+1);
    }
}
int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        ok=0;
        while(!n.empty())
        {
            n.pop_back();
        }
        while(!m.empty())
        {
            m.pop_back();
        }
        n.push_back(0);
        m.push_back(0);
        for(int i=0;i<10;i++)
            scanf("%d",a+i);
            bfs(0);
        if(ok)
            printf("YES\n");
        else
            printf("NO\n");
    }
}

Measured memory_bytes: 1032
#include <string.h>
int main(void){
    char Input[201];
    char A[403];
    int Mix,Num,Sum,Answer;
    int i;
    while(1){
        for(i=0;i<200;i++){
            Input[i]='\0';
        }
        scanf("%s",Input);
        if(Input[0] == '-'){
            break;
        }
    Sum=0;
    scanf("%d",&Num);
    for(i=0;i<Num;i++){
        scanf("%d",&Mix);
        Sum += Mix;
    }
    Answer=0;
    Answer = Sum%strlen(Input);
        for(i=0;i<402;i++){
            A[i]='\0';
        }
    strcat(A, Input);
    strcat(A, Input);
    for(i=Answer;i<Answer+strlen(Input);i++){
        printf("%c",A[i]);
    }
    printf("\n");
    }
}


Measured memory_bytes: 2016
import java.util.*;
public class Main {

  public static void main(String[] args) { 
      Scanner sc = new Scanner(System.in);
      String s = sc.next();
      int q = sc.nextInt();

      int reverseCnt = 0;
      int headFlag = 1;
      int tailFlag = 2;
      StringBuilder S = new StringBuilder(s);
      StringBuilder sb = new StringBuilder();
      
      while(q-- > 0) {
        int oper = sc.nextInt();
        if(oper == 1) {
          reverseCnt++;
          headFlag = headFlag ^ tailFlag;
          tailFlag = headFlag ^ tailFlag;
          headFlag = headFlag ^ tailFlag;
        } else {
          int f = sc.nextInt();
          char c = sc.next().charAt(0);
          if(f == headFlag)
            sb.append(c);
          else
            S.append(c);
        }
      }
      StringBuilder res = new StringBuilder(sb.reverse().toString() + S.toString());
      if(reverseCnt % 2 == 1)
        res.reverse();
      System.out.println(res.toString());
  }
}

Measured memory_bytes: 127516
#include <iostream>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, s, n) for (int i = s; i < (n); i++)
using namespace std;

typedef long long ll;

int main(){
  ll n, x, y;
  cin >> n >> x >> y;
  x--; y--;
  ll ans[2020] = {};
  ll dis;
  rep(i, n-1)rep2(j, i+1, n){
    if(j-i < abs(i-x) + 1 + abs(y-j))
      dis = j-i;
    else
      dis = abs(i-x) + 1 + abs(y-j);
    ans[dis]++;
  }
  rep2(i, 1, n) cout << ans[i] << endl;
  
  return 0;
}

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

#define REP(i,a,b) for(int i=(a);i<=(b);i++)

int main()
{
	int N,ans=0;
	cin >> N; 
	int a[N+5];
	REP(i,1,N) cin >> a[i];
	REP(i,1,N){
		if(a[i] > i){
			if(a[a[i]] == i) ans++;
		}

	}
	cout << ans;
	return 0;

}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n;
    cin>>n;
    long long a[n+5];
    map<long long,long long>mp;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        mp[a[i]]++;
    }
    long long ans=0;
    for(auto itr : mp)
    ans=ans+((itr.second)*(itr.second-1))/2;
    //cout<<ans<<'\n';
    for(int i=0;i<n;i++)
    {
        long long k=mp[a[i]];
        cout<<ans-((k*(k-1))/2 - ((k-1)*(k-2))/2)<<'\n';
    }
    return 0;
}

Measured memory_bytes: 11008
X , K ,D = map(int, input().split())


if X>0:
    S = int(abs(X) / D)
    aX = X -D * S
    if S>=K:
        print(X-D*K)
    elif (K-S)%2==0:
        print(abs(aX))
    else:
        print(abs(aX-D))
else:
    S = int(abs(X) / D)
    aX = X + D * S
    if S>=K:
        print(abs(X+D*K))
    elif (K-S)%2==0:
        print(abs(aX))
    else:
        print(abs(aX+D))


Measured memory_bytes: 9132
#include <bits/stdc++.h>
#define off  exit( 0 )
#define cn   continue
#define rt   return
#define sc   scanf
#define pr   printf
#define pb   push_back
#define pf   push_front
#define p_f  pop_front
#define p_b  pop_back
#define ff   first
#define ss   second
#define ll   long long
#define ld   long double
#define N    200256
#define M    1000000007
#define I    1000000000000000000
#define pdd  pair < ld, ld >
#define pll  pair < ll, ll >
#define pii  pair < int, int >
#define sqr( a )           a * a
#define all( c )           c.begin(), c.end()
#define srt( c )           sort( all( c ) )
#define rev( c )           reverse( all( c ) )
#define srtr( c )          sort( c.rbegin(), c.rend() );
using namespace std;

ll n, k, a[N], p[N], ans, x;
map < ll, ll > c;
void solve()
{
    cin >> n >> k;
    for( int i = 1; i <= n; i ++ )
    {
        cin >> x;
        p[i] = p[i - 1] + x;
        a[i] = p[i] - i;
        if( a[i] < 0 )a[i] += k;
    }
    c[0] ++;
    for( int i = 1; i <= n; i ++ )
    {
        if( i >= k )c[a[i - k] % k] --;
        ans += c[a[i] % k];
        c[a[i] % k] ++;
    }
    cout << ans;
}
int main()
{
    ll tt = 1;
   // sc( "%d", &tt );
    for( ll i = 1; i <= tt; i ++ )
    {
        solve();
    }
}












Measured memory_bytes: 15872
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
const long long MOD = 1000000007;
using namespace std;
typedef long long ll;
map<ll, int> mp;
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, d, x[10][10], sum, r, b, ans = 0;
	cin >> n >> d;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < d; j++) {
			cin >> x[i][j];
		}
	}
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			sum = 0;
			for (int k = 0; k < d; k++) {
				b = x[i][k] - x[j][k];
				sum += b * b;
			}
			r = sqrt(sum);
			if (r * r == sum) {
				ans++;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.HashSet

fun main(args: Array<String>) {
    var (N) = readLine()!!.split(" "). map { it.toInt() }
    var A = readLine()!!.split(" "). map { it.toInt() }
    val set = HashSet<Int>()
    A.forEach { set.add(it) }
    if (N != set.size) println("NO")
    else println("YES")
}

Measured memory_bytes: 82844
import numpy as np
a,b,h,m=map(int,input().split())
pi=np.pi
h_deg=(1/6)*pi*h+(1/360)*pi*m
m_deg=(1/30)*pi*m
deg=abs(m_deg-h_deg)
if(deg>pi):
    deg=2*pi-deg
else:
    pass
c=a**2+b**2-2*a*b*np.cos(deg)
print(c**(1/2))

Measured memory_bytes: 27204
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <functional>
#include <utility>
#include <fstream>

using namespace std;

#define ll long long
#define INF 2000000000
#define LINF 2000000000000000000
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define dum(x) cout<<#x<<'='<<x<<endl
#define dum2(x,y) cout<<#x<<'='<<x<<' '<<#y<<'='<<y<<'\n'<<endl
#define dum3(x,y,z) cout<<#x<<'='<<x<<' '<<#y<<'='<<y<<' '<<#z<<'='<<z<<'\n'<<endl
#define darr(arr,n) rep(i,(n-arr)){cout<<*(arr+i)<<' ';}cout<<endl

//ifstream in("Text.txt");cin.rdbuf(in.rdbuf());

int main() {
    int a, b;
    cin >> a >> b;
    int sum = 0;
    for (int i = 1; i <= b-a; i++) {
        sum += i;
    }
    cout << sum-b << endl;
}

Measured memory_bytes: 256
N = int(input())
A = [int(a) for a in input().split()]

cnt = 0
c2 = 0
c4 = 0
for a in A:
    if a%4 == 0:
        c4 += 1
    elif a%2 == 0:
        c2 += 1
    else:
        cnt += 1

if c4 >= cnt or (c2 == 0 and c4+1 == cnt):
    ans = "Yes"
else:
    ans = "No"
print(ans)

Measured memory_bytes: 14252
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_touple<T: std::str::FromStr + Copy>() -> (T, T) {
    let v: Vec<T> = read_vec();
    assert_eq!(v.len(), 2);
    (v[0], v[1])
}
fn main() {
    let n: usize = read();
    let s: Vec<char> = read::<String>().chars().collect();
    let mut table = vec![vec![0; 10]; 10];
    let mut sum = vec![vec![0; 10]; n + 1];
    let t = s
        .iter()
        .map(|&c| c as usize - '0' as usize)
        .collect::<Vec<usize>>();
    let mut ans: usize = 0;

    for i in 0..10 {
        for j in 0..10 {
            for k in 0..10 {
                let (mut c1, mut c2, mut c3) = (false, false, false);
                for &e in &t {
                    match (c1, c2, c3) {
                        (false, _, _) if e == i => c1 = true,
                        (true, false, _) if e == j => c2 = true,
                        (true, true, false) if e == k => c3 = true,
                        _ => continue,
                    }
                }
                if c1 && c2 && c3 {
                    ans += 1;
                }
            }
        }
    }

    for i in 0..10 {
        for j in 0..10 {
            ans += table[i][j];
        }
    }
    // for i in 0..10 {
    //     println!("{:?}", table[i]);
    // }
    println!("{}", ans);
}


Measured memory_bytes: 6396
#include <bits/stdc++.h>
using namespace std;
 
#define FAST ios_base::sync_with_stdio(0); cin.tie(); cout.tie();
 
#define MAXX 100005
 
#define PI 3.14159265358979323846264338327950
 
#define F first
#define S second
 
#define ll 	 int
 
#define mod  1000000007



int main()
{
	FAST;
	ll n;
	cin >> n;
	cout << (n/2) *((n+1)/2);
	return 0;
}

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

using namespace std;

long long n;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    long long ans = (n / 500) * 1000;
    n %= 500;
    cout << ans + (n / 5) * 5;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
typedef long long lint;
const int N=1e5+5;
const int mod=1e9+7;
int n,m,fac[N<<1],ifac[N<<1];

inline int nxi(){
	int x=0;
	char c;
	while((c=getchar())>'9'||c<'0');
	while(x=x*10-48+c,(c=getchar())>='0'&&c<='9');
	return x;
}

template <class T> inline int fpow(int x,T t){
	int ans=1;
	for(; t; x=(lint)x*x%mod,t>>=1){
		if(t&1) ans=(lint)ans*x%mod;
	}
	return ans;
}

inline void init(){
	fac[0]=1;
	for(int i=1; i<=n+m; ++i){
		fac[i]=(lint)fac[i-1]*i%mod;
	}
	ifac[n+m]=fpow(fac[n+m],mod-2);
	for(int i=n+m; i>=1; --i){
		ifac[i-1]=(lint)ifac[i]*i%mod;
	}
}

inline int C(const int x,const int y){
	if(x<y) return 0;
	return (lint)fac[x]*ifac[y]%mod*ifac[x-y]%mod;
}

int main(){
	n=nxi(),m=nxi();
	int qx=nxi(),qy=nxi();
	init();
	int ans=0;
	for(int i=qy+1; i<=m; ++i){
		ans=(ans+(lint)C((n-qx-1)+i-1,i-1)*C((qx-1)+(m-i),m-i))%mod;
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 1664
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        var NL = ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        var (N, L) = (NL[0], NL[1]);

        var apples = Enumerable.Range(1, N).Select(x => L + x - 1).ToArray();
        var sum = apples.Sum();

        var min = int.MaxValue;
        var ans = 0;

        for (int i = 0; i < N; i++)
        {
            var _sum = sum - apples[i];
            var diff = Math.Abs(sum - _sum);
            if(diff < min)
            {
                min = diff;
                ans = _sum;
            }
        }

        WriteLine(ans);
    }
}


Measured memory_bytes: 28256
#include<bits/stdc++.h>
using namespace std;
#define all(c) c.begin(),c.end()
int main()
{
    double pi = 3.14159265359;
    double r, cir;
    cin >> r;
    cir = 2.0 * pi * r;
    printf("%lf\n", cir);

    return 0;
}

Measured memory_bytes: 3812
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

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

  priority_queue<int> que;
  for(int i = 0; i < N; i++){
    int a;
    cin >> a;
    que.push(a);
  }

  for(int i = 0; i < M; i++){
    int mx = que.top();
    que.pop();
    mx /= 2;
    que.push(mx);
  }

  ll ans = 0;
  while(!que.empty()){
    ans += que.top();
    que.pop();
  }

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


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

int minute[200];
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    
    for(int i = 0; i < n; ++i){
        int h_, m_;
        cin >> h_ >> m_;
        minute[i] = h_ * 60 + m_;
    }
    
    int m;
    cin >> m;
    
    for(int i = n; i < n + m; ++i){
        int h_, m_;
        cin >> h_ >> m_;
        minute[i] = h_ * 60 + m_;
    }
    
    sort(minute, minute + n + m);
    
    for(int i = 0; i < n + m; ++i){
        if(i != 0 && minute[i] == minute[i - 1]){
            continue;
        }
        if(i != 0) cout << " ";
        int h_, m_;
        h_ = minute[i] / 60;
        m_ = minute[i] % 60;
        cout << h_ << ":";
        if(m_ < 10) cout << 0;
        cout << m_;
    }
    cout << endl;
}

Measured memory_bytes: 1204
//============================================================================
// Name        : main.cpp
// Author      : nekoroko
// Version     : none
// Copyright   : Your copyright notice
// Description : AtCoder
//============================================================================
#include <iostream>
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<list>
#include<set>

using namespace std;

int main() {
	int N;
	scanf("%d", &N);
	vector<long long> A(N);
	vector<long long> rain(N);
	for(int i = 0; i < N; ++i){
		scanf("%d", &A[i]);
	}

	long long rain1 = 0;
	for(int i = 0; i < N; ++i){
		if(i % 2 == 0)rain1 += A[i];
		else rain1 -= A[i];
	}
	rain[0] = rain1;

	for(int i = 1; i < N; ++i){
		rain[i] = 2 * (A[i - 1] - rain[i - 1] / 2);
	}

	for(int i = 0; i < N; ++i){
		printf("%d ", rain[i]);
	}
	printf("\n");

	return 0;
}



Measured memory_bytes: 2816
N = int(input())
ABn = [ list(map(int,input().split(' '))) for _ in range(N) ]
ABn.sort(key=lambda x: x[1])

count_time = 0
for AB in ABn:
    count_time += AB[0]
    if count_time <= AB[1]:
        continue
    else:
        print('No')
        exit()
print('Yes')

Measured memory_bytes: 53720
#include <iostream>
#include <vector>
#include <iterator>
 
/**
 * @brief Output Sequence
 * @param [in] start  Beginning of the sequence
 * @param [in] end    Endinning of the sequence
 * @return none
 */
void outputSequence(std::vector<int>::iterator start,std::vector<int>::iterator end)
{
	using namespace std;
	
	vector<int>::iterator iter;
	for( iter = start; iter != end; iter++ )
	{
		cout << *iter;
		if( iter != (end-1) )
		{
			cout << " ";
		}
	}
	cout << endl;
	return;
}
 
/**
 * @brief Excute BubbleSort
 * @param [in]  start  Beginning of the sequence
 * @param [in]  end    Endinning of the sequence
 * @param [out] start  Beginning of the sequence
 * @param [out] end    Endinning of the sequence
 * @return swapNum     Number of swap operations
 */
int bubbleSort(std::vector<int>::iterator start,std::vector<int>::iterator end)
{
	using namespace std;
	
	int swapNum = 0;
	vector<int>::iterator count, swap_a, swap_b;
	 
	for( count = start; count != end; count++ )
	{
		for( swap_a = end-1; swap_a != count; swap_a-- )
		{
			swap_b = swap_a;
			advance( swap_b , -1 );
			if( *swap_b > *swap_a )
			{
				iter_swap( swap_a, swap_b );
				swapNum++;
			}
		}
	}
	return swapNum;
}
 
int main(void)
{
	using namespace std;

	int numData;
	cin >> numData;
	 
	/* Input Sequence */
	vector<int> vectorInt;
	vectorInt.reserve(100);
	int input;
	while( cin >> input )
	{
		vectorInt.push_back( input );
	}
	 
	/* Excute BubbleSort */
	int swapNum = bubbleSort( vectorInt.begin(), vectorInt.end() );
	outputSequence( vectorInt.begin(), vectorInt.end() );
	cout << swapNum << endl;
	 
	return 0;
}

Measured memory_bytes: 3076
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
template<class T> inline void dmin(T& x,T y){ y<x?x=y:0; }
template<class T> inline void dmax(T& x,T y){ y>x?x=y:0; }
template<class T> inline void dmin(T& x,vector<T> y){ 
	for(auto t:y) t<x?x=t:0;
}
template<class T> inline void dmax(T& x,vector<T> y){
	for(auto t:y) t>x?x=t:0;
}
ll f[20][2],c[55][55],ans=0;
int cnt[1<<25|5],a[55],n,k,S,T;
struct Initer{
	Initer(){
		cnt[0]=0;
		for(int i=1;i<1<<25;++i)
			cnt[i]=cnt[i-(i&-i)]+1;
		for(int i=0;i<=50;++i){
			c[i][0]=1;
			for(int j=1;j<=i;++j)
				c[i][j]=c[i-1][j-1]+c[i-1][j];
		}
		for(int i=0;i<=50;++i){
			for(int j=1;j<=50;++j)
				c[i][j]+=c[i][j-1];
			for(int j=0;j<=50;++j)
				c[i][j]--;
		}
	}
}__initer;
int bitcount(ll x){
	return cnt[x>>25]+cnt[x&((1<<25)-1)];
}
void dfs(int x,ll sta,int p){
//	printf("[%d %lld %d]\n",x,sta,p);
	if(x==18){
//		printf("[%lld %d %d]\n",sta,bitcount(sta),p);
//		exit(0);
		ans+=p*c[bitcount(sta)][k];
		return;
	}
	if(((S>>x)&1)==((T>>x)&1)){
		int flag=(S>>x)&1;
		dfs(x+1,sta&f[x][flag],p);
	}else{
		dfs(x+1,sta,p);
		dfs(x+1,sta&f[x][0],-p);
		dfs(x+1,sta&f[x][1],-p);
	}
}
int main(){
	scanf("%d%d%d%d",&n,&k,&S,&T);
	for(int i=0;i<n;++i){
		scanf("%d",&a[i]);
		for(int j=0;j<18;++j)
			f[j][(a[i]>>j)&1]|=1ll<<i;
	}
	dfs(0,(1ll<<n)-1,1);
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 134928
#include<iostream>

using namespace std;

int main(){
    string s; string t;
    cin >> s >> t;
    long counter = 0;
    for (int i = 0; i < t.size(); i++){
        if (s.at(i) != t.at(i)){
            counter += 1;
        }
    }
    cout << counter;
}

Measured memory_bytes: 3920
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
#define int long long
#define ll long long
//#define int  unsigned long long
#define pb push_back
//#define double long double

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int mod = 998244353;
const int N = 6555;
const int K = 700 ;
int c[N][N], dp[N][N], a[N];
int n, x, b[N], res;
void gen(int m){
    if (m == n + 1){
        int q = 1;
        for (int i = 1; q &&  i <= n; i++){
            int s = 0;
            for (int j = i;q &&  j <= n; j++){
                s += b[j];
                if (s == x) q = 0;
            }
        }
        if (q == 1){
            for (int i = 1; i <= n; i++) if (b[i] != 0) cout << b[i] << " ";
            cout << endl;
        }
        res += q;
        return;
    }
    b[m] = 0;
    gen(m + 1);
    b[m] = 1;
    gen(m + 1);
    b[m] = 2;
    gen(m + 1);
}
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    cin >> n >> x;
    //gen(1);
    c[0][0] = 1;
    for (int i = 1; i <= n; i++){
        c[i][0] = 1;
        for (int j = 1; j <= i; j++){
            c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mod;
        }
    }
    dp[0][0] = 1;
    for (int i = 1; i <= n; i++){
        for (int j = 1; j <= n + n; j++){
            dp[i][j] = dp[i - 1][j - 1];
            if (j > 1) dp[i][j] = (dp[i][j] + dp[i - 1][j - 2]) % mod;
        }
    }
    for (int i = 0; i <= n; i++){
        for (int j = 0; j < x; j++) a[i] = (a[i] + dp[i][j]) % mod;
        for (int j = 1; j <= i; j++){
            int l = j + 1;
            int r = i - j;
            if (r < l) continue;
            if (x - 1 - 2 * j >= 0 && (r - l + 1) * 2 != (x - 1 - 2 * j)) a[i] = (a[i] + dp[r - l + 1][x - 1 - 2 * j]) % mod;
        }
        if (i != 0 && 2 * i > x && x % 2 == 1) a[i] = (a[i] + 1) % mod;
    }
    int ans = 0;
    for (int i = 0; i <= n; i++){;
        ans = (ans + c[n][i] * a[i]) % mod;
    }
    cout << ans;
}


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

#define ll long long
#define ar array

int main() {

    ios::sync_with_stdio(false);
    
    int N;
    
    cin >> N;
    
    if (N%2 ==0){
    	cout << N << endl; 
	}else{
		cout << N*2 << endl;
	}
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>

using namespace std;

int main() {	
	int h,w,m, max_row_val = 0, max_col_val = 0;
	cin >> h >> w >> m;
	vector<int> rows = vector<int>(h,0);
	vector<int> cols = vector<int>(w,0);
	set<pair<int,int>> targets;

	vector<int> max_rows;
	vector<int> max_cols;

	for (int i = 0; i < m; ++i) {
		int x,y;
		cin >> x >> y;
		targets.insert({x-1,y-1});
		rows[x-1]++;
		cols[y-1]++;
		if (rows[x-1] > max_row_val) {
			max_row_val = rows[x-1];
			max_rows.clear();
			max_rows.push_back(x-1);
		} else if (rows[x-1] == max_row_val) {
			max_rows.push_back(x-1);
		}
		if (cols[y-1] > max_col_val) {
			max_col_val = cols[y-1];
			max_cols.clear();
			max_cols.push_back(y-1);
		} else if (cols[y-1] == max_col_val) {
			max_cols.push_back(y-1);
		}
	}

	for (int i: max_rows) {
		for (int j: max_cols) {
			if (targets.find({i,j}) == targets.end()) {
				cout << max_row_val + max_col_val << endl;
				return 0;
			}
		}
	}
	cout << max_row_val + max_col_val - 1 << endl;
	return 0;
}

Measured memory_bytes: 21916
//
// Created by karth on 4/28/2020.
//
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
typedef long long ll;


int main(){
    string s, t;
    cin >> s >> t;
    int ans = 0;
    for(int i = 0; i < s.length(); ++i){
        if(s[i] == t[i]){
            ans++;
        }
    }
    cout << ans << "\n";
}




Measured memory_bytes: 256
#include <iostream>//bit DP
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <string>
#include <cmath>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef pair<ll,ll>PP;
int T[55]={0};
int D[55]={0};
int main(){
  int n;cin>>n;
  for(int i=0;i<n;i++){
    cin>>D[i];
  }
  sort(D,D+n);
  T[0]=12;
  for(int i=0;i<n;i++){
    if(i%2==0)T[i+1]=12+D[i];
    else T[i+1]=12-D[i];
  }
  sort(T,T+n+1);
  int mi=min((24-T[n])+T[0],12);
  for(int i=1;i<=n;i++)mi=min(mi,abs(T[i]-T[i-1]));

cout<<mi<<endl;

}


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

int main(){
  int N;
  cin >> N;
  vector<long long> L(N + 1);
  L.at(0) = 2;
  L.at(1) = 1;
  for(int i = 2; i <= N; i++){
    L.at(i) = L.at(i - 1) + L.at(i - 2);
  }

  cout << L.at(N) << endl;
}

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

int main()
{
  string w;cin>>w;
  vector<int> alphabets(26,0);
  for(int i=0;i<w.size();i++)alphabets[w[i]-'a']++;
  for(int i=0;i<26;i++)if(alphabets[i]%2==1){printf("No\n");return 0;}
  printf("Yes\n");
}

Measured memory_bytes: 3564