akhauriyash/Code-Regression huggingface dataset:
#include <string>
#include <iostream>

using namespace std;

int main()
{
    cin.tie(0);

    int N;

    double BTC = 380000;

    cin >> N;

    double ans = 0;

    double x = 0.0;
    string u;

    for (int i = 0; i < N; i++) {
        cin >> x;
        cin >> u;
        if (u == "JPY") {
            ans += x;
        }
        else {
            ans += x * 380000;
        }
    }

    cout << ans << "\n";

}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <bitset>
#include <map>
#include <queue>
#include <stack>
#define speed ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define eps 1e-8
#define inf 0x3f3f3f3f
#define mod 1000000009
using namespace std;

int main() {
	speed;
	int n, k;
	cin >> n >> k;
	vector<int>v(n);
	for (int i = 0; i < n; ++i)
		cin >> v[i];
	ll ans = 0, suml = 0;
	multiset<int>sub;
	for (int i = -1; i < n && i < k; ++i) {
		if (i != -1) {
			suml += v[i];
			if (v[i] < 0)
				sub.insert(v[i]);
		}
		ll sum = suml, ktmp = k - (i + 1);
		multiset<int>st = sub;
		for (int j = n - 1; j > i && ktmp; --j) {
			ll kk = ktmp, stmp = sum;
			for (auto l : st) {
				if (!kk)
					break;
				stmp -= l;
				--kk;
			}
			ans = max(ans, stmp);

			sum += v[j];
			if (v[j] < 0)
				st.insert(v[j]);
			--ktmp;
		}
		ll kk = ktmp, stmp = sum;
		for (auto l : st) {
			if (!kk)
				break;
			stmp -= l;
			--kk;
		}
		ans = max(ans, stmp);
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 256
//Binary Search
#include <iostream>

using namespace std;

bool search(int S[], int n, int key) {
    int left = 0, right = n;
    int mid;

    while(left < right) {
        mid = (left + right) / 2;
        if(S[mid] == key) return true;
        else if(S[mid] > key) right = mid;
        else left = mid+1;
    }
    return false;
}

int main() {
    int n, q;
    cin >> n;
    int S[n];
    for(int i=0; i<n; i++) cin >> S[i];
    cin >> q;

    int cnt = 0;
    for(int i=0; i<q; i++) {
        int t;
        cin >> t;
        if(search(S, n, t)) cnt++;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 3476
macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); let mut next = || { iter.next().unwrap() }; input_inner!{next, $($r)*} }; ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes .by_ref() .map(|r|r.unwrap() as char) .skip_while(|c|c.is_whitespace()) .take_while(|c|!c.is_whitespace()) .collect() }; input_inner!{next, $($r)*} }; }
macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let mut $var = read_value!($next, $t); input_inner!{$next $($r)*} }; }
macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

fn main() {
    input!(n: chars,);

    for i in 0..n.len() {
        if n[i] == '1' {
            n[i] = '9'
        } else {
            n[i] = '1'
        }
    }
    println!("{}{}{}", n[0], n[1], n[2]);
}

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define ALL(a) (a).begin(),(a).end()

using namespace std;
using ll = long long;

const double PI = 3.14159265358979;

void solve()
{
  ll n;
  cin >> n;
  char c;
  for(int i = 0; i < n; ++i)
  {
    cin >> c;
    if (c == 'Y')
    {
      cout << "Four";
      return;
    }
  }
  cout << "Three";
}

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? 1e9:1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T a){int b=0;for(auto itr :a){if(b++!=0)cout << " "; cout << itr;} }
using ll  = long long;
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
string alpha = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
#define int ll
signed main(){
    int n;
    map<char,int>key;
    rep(i,alpha.size())key[alpha[i]] = i;
    while(cin >> n,n){
        vector<int>v(n);
        rep(i,n)cin >> v[i];
        int num = 0;
        string s; cin >> s;
        rep(i,s.size()){
            int base = key[s[i]];
            rep(j,v[num]){
                base --;
                if(base == -1)base = alpha.size()-1;
            }
            cout << alpha[base];
            num ++;
            if(num  == n) num = 0;
        }
        cout << endl;
    }
}







Measured memory_bytes: 3164
#include <iostream>

using namespace std;

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    if (a + b + 1 >= c)
    {
        cout << b + c << endl;
    }
    else
    {
        cout << a + 2*b + 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
	int n;
	string h;
	cin >> n;
	vector<int>v(26, 0);
	for (int i = 0; i < n; ++i) {
		cin >> h;
		vector<int>mon(26, 0);
		for (char H : h) {
			++mon[H - 'a'];
		}
		for (int j = 0; j < 26; ++j) {
			if (i == 0) v[j] = mon[j];
			else v[j] = min(v[j], mon[j]);
		}
	}

	for (int i = 0; i < 26; ++i) {
		for (int j = 0; j < v[i]; ++j) {
			cout << (char)('a' + i);
		}
	}
	cout << endl;
}

Measured memory_bytes: 256
#define rep(i, a, b) for(int i = a; i < (int)(b); i++)
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
template<class T> inline void chmax(T &a, const T &b) {if(a < b) a = b;}
template<class T> inline void chmin(T &a, const T &b) {if(a > b) a = b;}
const long long INF = 1LL<<60;
const long long MOD = (ll)1e9+7;
const long long MAX = (ll)420;

int main(void) {
   ll N;
   cin>>N;
   vector<ll> d(N);
   rep(i,0,N) cin>>d[i];

   ll ans = 0;
   rep(i,0,N) rep(j,i+1,N) {
      ans += d[i]*d[j];
   }
   cout<<ans<<endl;


   return 0;
}

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

int main() {
    string s;cin>>s;
    int ans[s.size()]{};
    for (int i=1;i<s.size();i++)
        if (s.substr(i-1,2)=="RL") {
            int j=i-1;
            while (0<=j&&s[j]=='R') {
                ans[i-1+(i-1-j)%2]++;
                j--;
            }
            j=i;
            while (j<s.size()&&s[j]=='L') {
                ans[i-(j-i)%2]++;
                j++;
            }
            i=j;
        }
    for (int i=0;i<s.size();i++) {
        if (i!=0)
            cout<<' ';
        cout<<ans[i];
    }
    return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <queue>
#include <list>
#include <stack>
#include <math.h>
#include <map>
#include <unordered_map>
#include <set>
using namespace std;

#define ll long long
#define ull unsigned long long

#define	max	1000000007

ll gcd(ll a, ll b) {
	if (a < b)
		swap(a, b);
	while (ll r = a % b)
		a = b, b = r;
	return b;
}

class mod
{
public:
	ll val;

	mod(ll v)
	{
		val = v % max;
	}

	mod()
	{
		val = 0;
	}

	void operator -=(const mod &v)
	{
		val -= v.val;

		if (val < 0)
			val += max;
	}

	void operator +=(const mod &v)
	{
		if (val + v.val >= max)
			val -= max;
		val += v.val;
	}

	void operator +=(ll &v)
	{
		if (val + v >= max)
			val -= max;
		val += v;
	}

	void operator *=(const mod &v)
	{
		val *= v.val;
		val %= max;
	}

	void operator *=(ll &v)
	{
		val *= v;
		val %= max;
	}

	ll modinv(ll a)
	{
		ll b = max, u = 1, v = 0;
		while (b)
		{
			ll t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		u %= max;
		if (u < 0)
			u += max;
		return u;
	}

	void operator /=(const mod &v)
	{
		val *= modinv(v.val);
		val %= max;
	}

	void operator /=(ll &v)
	{
		val *= modinv(v);
		val %= max;
	}
};

int main()
{
	int a, b, c;
	cin >> a >> b >> c;

	bool y = false;

	if (a == b && b == c)
		y = true;
	else if (a == b || b == c || c == a)
		y = false;
	else
		y = true;
	if(y)
	printf("No");
	else
		printf("Yes");

	return 0;
}


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

using namespace std;

using ll = long long;
using ld = long double;
using D = double;
using uint = unsigned int;

#ifdef WIN32
    #define LLD "%I64d"
#else
    #define LLD "%lld"
#endif

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second

const int maxn = 100005;

int a[maxn];
int n, k;
vector<int> gr[maxn];
int answer;

int go(int cur)
{
	int curd = 0;
	for (auto t : gr[cur]) curd = max(curd, go(t) + 1);
	if (curd + 2 > k)
	{
		if (a[cur] != 0) answer++;
		return -1;
	}
	return curd;
}

int main()
{
	scanf("%d%d", &n, &k);
	for (int i = 0; i < n; i++)
	{
		scanf("%d", &a[i]);
		a[i]--;
	}
	if (a[0] != 0)
	{
		answer++;
		a[0] = 0;
	}
	for (int i = 1; i < n; i++) gr[a[i]].pb(i);
	go(0);
	cout << answer << endl;
    return 0;
}

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

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

    vector<int> A, B, C; 
    priority_queue<pair<int, int>> q;
    for(int i = 0; i < N; i++){ 
         int a;
         cin >> a;
         A.push_back(a);
         q.push(make_pair(A.at(i),1));
    }

    for(int i = 0; i < M; i++){ 
         int b, c;
         cin >> b >> c;
         B.push_back(b);
         C.push_back(c);
         q.push(make_pair(C.at(i), B.at(i)));
    }

    long long ans = 0;
    for(int i = 0; i < N; i++){ 
         
         pair<int, int> P = q.top();
         q.pop();
         ans += P.first;
         if(P.second > 1){
             P.second--;
             q.push(P);
         }

    }
    cout << ans << endl; 

}

Measured memory_bytes: 3700
S = input()
C = list(set(S))

if len(C)==2:
    counter = {c:0 for c in C}
    for s in S:
        counter[s]+=1
    if counter[C[0]]==2 and counter[C[1]]==2:
        print('Yes')
    else:
        print('No')
else:
    print('No')

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

res = 0

if N == 2:
    res += 1
else:
    res += 2

for i in range(2, int((N - 1)**0.5 + 0.5) + 1):
    if (N - 1) % i != 0:
        continue
    if (N - 1) % i == 0:
        res += 1
    if i ** 2 == N - 1:
        continue
    if (N - 1) % ((N - 1) // i) == 0:
        res += 1

for i in range(2, int(N**0.5 + 0.5) + 1):
    if N % i != 0:
        continue
    tmp = N
    while tmp % i == 0:
        tmp //= i
    if (tmp - 1) % i == 0:
        res += 1
    if i ** 2 == N:
        continue
    tmp = N
    while tmp % (N // i) == 0:
        tmp //= (N // i)
    if (tmp - 1) % (N // i) == 0:
        res += 1

print(res)


Measured memory_bytes: 41520
#include <stdio.h>

int main()
{
    int inputN, inputB, firstRow[3], secondRow[3], thirdRow[3];

    // Create a array for every row in a bingo and fill it with values
    scanf("%d %d %d", &firstRow[0], &firstRow[1], &firstRow[2]);

    scanf("%d %d %d", &secondRow[0], &secondRow[1], &secondRow[2]);

    scanf("%d %d %d", &thirdRow[0], &thirdRow[1], &thirdRow[2]);

    // Check if values in bingo are the same with the input
    // If input value and value in the bingo is the same, then makes it '-1'
    scanf("%d", &inputN);

    for (int i = 0; i < inputN; i++)
    {
        scanf("%d", &inputB);

        for (int j = 0; j < 3; j++)
        {
            if (firstRow[j] == inputB)
            {
                firstRow[j] = -1;
            }
            if (secondRow[j] == inputB)
            {
                secondRow[j] = -1;
            }
            if (thirdRow[j] == inputB)
            {
                thirdRow[j] = -1;
            }
        }

    }

    // Print 'Yes' if you have bingo in rows
    if ((firstRow[0] == -1 && firstRow[1] == -1 && firstRow[2] == -1) || (secondRow[0] == -1 && secondRow[1] == -1 && secondRow[2] == -1) || (thirdRow[0] == -1 && thirdRow[1] == -1 && thirdRow[2] == -1))
    {
        printf("Yes\n");
    }
    // Print 'Yes' if you have bingo in columns
    else if ((firstRow[0] == -1 && secondRow[0] == -1 && thirdRow[0] == -1) || (firstRow[1] == -1 && secondRow[1] == -1 && thirdRow[1] == -1) || (firstRow[2] == -1 && secondRow[2] == -1 && thirdRow[2] == -1))
    {
        printf("Yes\n");
    }
    // Print 'Yes' if you have bingo in diagonall
    else if ((firstRow[0] == -1 && secondRow[1] == -1 && thirdRow[2] == -1) || (firstRow[2] == -1 && secondRow[1] == -1 && thirdRow[0] == -1))
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

constexpr int P = 1000000007;

ll powmod(ll n, ll k) {
    ll r = 1, t = n % P;
    for (; k != 0; k /= 2) {
        if (k & 1) r = r * t % P;
        t = t * t % P;
    }
    return r;
}

struct Sieve {
    Sieve(int n) : l(n + 1, 0) {
        for (int i = 2; i <= n; i++) {
            if (!l[i]) p.push_back(l[i] = i);
            for (int q : p) {
                if (q > l[i]) break;
                if (int j = i * q; j <= n) l[j] = q; else break;
            }
        }
    }
    bool is_prime(int i) {
        return l[i] == i;
    }
    vector<int> l, p;
};

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

    vector<int> a(k + 1);
    for (int i = 1; i <= k; i++) {
        a[i] = powmod(k / i, n);
    }

    Sieve si(k);
    for (int p : si.p) {
        for (int i = 1; i * p <= k; i++) {
            a[i] -= a[i * p];
            if (a[i] < 0) a[i] += P;
        }
    }

    ll r = 0;
    for (int i = 1; i <= k; i++) {
        r += (ll)a[i] * i % P;
    }
    r %= P;

    cout << r << endl;

    return 0;
}

Measured memory_bytes: 4276
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <tuple>
#include <algorithm>
#include <array>
using namespace std;
using ll = long long;
#define rep(i,n) for(decltype(n) i=0; i<n; ++i)
inline constexpr ll Inf = (1ULL << 62) -1;

template <class T>
void updatemax(T& a, T b) { if (b > a) a = b; }

int main() {
    ll N, K;
    cin >> N >> K;
    vector<ll> A(N);
    rep(i,N) cin >> A[i];
    ll l = 0;
    ll r = 1e9+1;
    auto f = [&](auto len) {
        ll cut = 0;
        rep(i,N) {
            cut += (A[i]-1) / len;
        }
        return cut <= K;
    };
    while (r-l > 1) {
        ll m = (r + l)/2;
        if (f(m)) r = m;
        else l = m;
    }
    ll ans=r;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4356
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph= vector<vector<int>>; 
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define mpa make_pair
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}

int main(){
  ll a ;cin>>a;
  ll ans= a+ a*a+ a*a*a ;
  cout<<ans<<endl ;
     return 0;
  }
  

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

using namespace std;

#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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

int main() { 
    int x;
    cin >> x;
    if (x < 1200) cout << "ABC" << endl;
    else cout << "ARC" << endl;
    
    return 0; 
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

	static int MOD = 1_000_000_007;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		boolean[] broken = new boolean[N + 10];
		Arrays.fill(broken, false);
		for (int i = 0; i < M; i++) {
			broken[sc.nextInt()] = true;
		}
		sc.close();

		long[] dp = new long[N + 10];
		dp[0] = 0;
		dp[1] = broken[1] ? 0 : 1;
		if (broken[2]) {
			dp[2] = 0;
		} else if (broken[1]) {
			dp[2] = 1;
		} else {
			dp[2] = 2;
		}
		for (int i = 3; i <= N; i++) {
			if (broken[i]) {
				dp[i] = 0;
			} else {
				dp[i] = (dp[i - 2] + dp[i - 1]) % MOD;
			}
		}

		System.out.println(dp[N]);
	}
}


Measured memory_bytes: 51892
N, A, B, C = map(int, input().split())
L = [int(input()) for _ in range(N)]

ans = 10 ** 10
for i in range(4**N):
    a = 0
    l = [0, 0, 0]
    for n in range(N):
        x = i % 4
        i //= 4
        if x == 3:
            continue
        if l[x] > 0:
            a += 10
        l[x] += L[n]

    if l[0] == 0 or l[1] == 0 or l[2] == 0:
        continue

    a += abs(l[0]-A) + abs(l[1]-B) + abs(l[2]-C)
    ans = min(a, ans)

print(ans)



Measured memory_bytes: 3064
// すぬけ君の塗り絵2イージー
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
using namespace std;

int main () {
    int W, H, N;
    cin >> W >> H >> N;
    vector<vector<int>> nurie(W, vector<int>(H));
    for (int i = 0; i < N; i++) {
        int x, y, a;
        cin >> x >> y >> a;
        if (a == 1) {
            for (int j = 0; j < x; j++) {
                for (int k = 0; k < H; k++) {
                    nurie[j][k] = 1;
                }
            }
        }
        if (a == 2) {
            for (int j = x; j < W; j++) {
                for (int k = 0; k < H; k++) {
                    nurie[j][k] = 1;
                }
            }
        }
        if (a == 3) {
            for (int j = 0; j < W; j++) {
                for (int k = 0; k < y; k++) {
                    nurie[j][k] = 1;
                }
            }
        }
        if (a == 4) {
            for (int j = 0; j < W; j++) {
                for (int k = y; k < H; k++) {
                    nurie[j][k] = 1;
                }
            }
        }
        // 出力確認
        // cout << endl;
        // for (int i = 0; i < W; i++) {
        //     for (int j = 0; j < H; j++) {
        //         cout << nurie[i][j] << ' ';
        //     }
        //     cout << endl;
        // }
    }
    int count = 0;
    for (int i = 0; i < W; i++) {
        for (int j = 0; j < H; j++) {
            if (nurie[i][j] == 1) count++;
        }
    }
    cout << W*H-count << endl;
}

Measured memory_bytes: 256
#include <iostream>

int main(void) {
  int A = 0;
  int B = 0;
  int T = 0;
  
  std::cin >> A;
  std::cin >> B;
  std::cin >> T;
  
  int kakeru = 0;
  kakeru = (double)(T + 0.5) / A;
  
  int num = 0;
  num = B * kakeru;
  
  std::cout << num;  
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define bit_cnt(n) (__builtin_popcountll(n))
#define substr(s,f,t) (s.substr(f-1,t-f+1))
#define ALL(a) (a).begin(),(a).end()
#define Yes(hoge) cout<<((hoge)?"Yes":"No")<<endl;
#define YES(hoge) cout<<((hoge)?"YES":"NO")<<endl;
using namespace std;
struct Grid{ll x,y,t;};
struct Edge{ll to,cost;};
struct Graph{vector<vector<Edge>>E;int V;
  const ll Inf = llINF;const int MAX_V=201010;vector<ll>d;
  Graph(int n):E(n){d.resize(MAX_V);E.resize(n);V=n;}
  void init(){for(int i=0;i<MAX_V;i++)d[i]=Inf;}
  void add_edge(ll from,ll to,ll cost){E[from].pb({to,cost});}
};
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n,k;
  cin>>n>>k;
  vi num(n);
  vi bits(100);
  for(int i=0;i<n;i++){
    cin>>num[i];
    ll numm=num[i];
    ll cnt=0LL;
    while(numm>0LL){if(numm&1)bits[cnt]++;numm/=2;cnt++;}
  }
  ll keta=0;
  ll numm=k;
  ll test=0;
  while(numm>0){numm/=2;keta++;}
  ll sum=0;
  ll ans=0;
  for(ll i=63;i>=keta;i--){
    //sum+=(ll)(1LL<<i)*(n-bits[i]);
    sum+=(ll)(1LL<<i)*(bits[i]);
  }
  ans=max(ans,sum);
  if(k==0){
    cout<<ans<<endl;
    return 0;
  }
  for(ll i=keta-1;i>=0LL;i--){
    ll nu=0;
    // cout<<k<<" "<<(1LL<<i)<<" "<<(k&(1LL<<i))<<endl;
    if(((k)&(1LL<<i))==0){
      sum+=(bits[i])*(1LL<<i);
      ans=max(sum,ans);
      continue;
    }
    nu+=(bits[i])*(1LL<<i);
    nu+=sum;
    //cout<<nu<<endl;
    for(ll j=i-1;j>=0LL;j--){
      nu+=max(bits[j]*(1LL<<j),((n-bits[j])*(1LL<<j)));
    }
    test+=(1LL<<i);
   
    ans=max(nu,ans);
    sum+=(n-bits[i])*(1LL<<i);
    ans=max(sum,ans);
  }
  cout<<ans<<endl;
  return 0;
}


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

using namespace std;

#define N 50005
#define M 120000

int n,m,op,a[M],b[M];
char ans[M];

namespace sub1{
	bitset<N> f[N];
	bool c[N];
	void solve(){
		for (int i=1;i<=n;++i) f[i][i]=1;
		for (int i=1;i<=m;++i){
			f[a[i]]|=f[b[i]];
			f[b[i]]|=f[a[i]];
		}
		for (int i=1;i<=n;++i)
			if ((int)f[i].count()==n){
				c[i]=1;
				for (int j=m;j;--j){
					if (c[a[j]]){
						ans[j]='^';
						c[b[j]]=1;
					}
					else{
						ans[j]='v';
						c[a[j]]=c[b[j]];
					}
				}
				puts(ans+1);
				exit(0);
			}
		puts("-1");
	}
}

namespace sub2{
	int f[N],cnt[N];
	void solve(){
		if (n>=3){
			for (int i=1;i<=n;++i){f[i]=i; ++cnt[i];}
			for (int i=m;i;--i){
				if (cnt[f[a[i]]]>1){
					ans[i]='v';
					--cnt[f[a[i]]];
					f[a[i]]=f[b[i]];
					++cnt[f[b[i]]];
				}
				else{
					ans[i]='^';
					--cnt[f[b[i]]];
					f[b[i]]=f[a[i]];
					++cnt[f[a[i]]];
				}
			}
			puts(ans+1);
		}
		else puts("-1");
	}
}

int main(){
	scanf("%d%d%d",&n,&m,&op);
	for (int i=1;i<=m;++i) scanf("%d%d",a+i,b+i);
	if (op==1) sub1::solve(); else sub2::solve();
	
	return 0;
}
			

Measured memory_bytes: 306816
r, c = map(int, input().split())

spreadSheet = [list(map(int, input().split())) for x in range(r)]
for row in range(r):
    spreadSheet[row].append(sum(spreadSheet[row]))

finalRow = []

for col in range(c + 1):
    sumCol = 0
    for row in range(r):
        sumCol += spreadSheet[row][col]
    finalRow.append(sumCol)

spreadSheet.append(finalRow)

for row in range(r + 1):
    print(*spreadSheet[row])



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

namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			long[] hwd = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
			long h = hwd[0];
			long w = hwd[1];
			long d = hwd[2];

			Tuple<long, long>[] a = new Tuple<long, long>[h * w];
			for (int i = 0; i < h; i++) {
				long[] aa = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
				for (int j = 0; j < w; j++) {
					a[aa[j] - 1] = new Tuple<long, long>(i + 1, j + 1);
				}

			}

			long[] p = new long[h * w];
			for (int i = 0; i < h * w; i++) {
				if (i / d == 0) {
					p[i] = 0;
				} else {
					var dst = a[i];
					var src = a[i - d];
					p[i] = Math.Abs(src.Item2 - dst.Item2) + Math.Abs(src.Item1 - dst.Item1)
						+ p[i - d];
				}
			}

			long q = long.Parse(Console.ReadLine());
			for (int i = 0; i < q; i++) {
				long[] lr = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
				Console.WriteLine(p[lr[1] - 1] - p[lr[0] - 1]); 
			}
		}
	}
}


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

int main()
{
  int a, b;
  cin >> a >> b;
  int p = 1; bool f = 0;
  while(floor(p * 0.08) < (a+1) && floor(p * 0.1)< (b+1)){
    if(floor(p * 0.08) == a && floor(p * 0.1) == b){
      f = 1;
      break;
    }
    p++;
  }
  if(!f) p = -1;
  cout << p << endl;
  return 0;
}


Measured memory_bytes: 256
n, x = map(int, input().split())
s = list(map(int, input().split()))
MOD = 10 ** 9 + 7

s = sorted(s, reverse=True)
max_ = max(s[0], x)
dp = [[0] * (max_ + 1) for i in range(n + 1)]
dp[0][x] = 1

for i in range(n):
    for val in range(max_ + 1):
        dp[i + 1][val % s[i]] += dp[i][val]
        dp[i + 1][val % s[i]] %= MOD
        dp[i + 1][val] += dp[i][val] * (n - i - 1)
        dp[i + 1][val] %= MOD

ans = 0
for i, num in enumerate(dp[-1]):
    ans += num * i
    ans %= MOD
print(ans)

Measured memory_bytes: 192152
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    
    int N   = sc.nextInt();
    int ans = 0;
    
    for (int i = 0; i < N; i++) {
      int a_i = sc.nextInt();
      
      while (a_i % 2 == 0) {
        a_i = a_i >> 1;
        ans++;
      }
    }
    
    System.out.println(ans);
  }
}

Measured memory_bytes: 33900
#include<bits/stdc++.h>
using namespace std;
int h,w;
char c[105][105];
int main()
{
	cin>>h>>w;
	for(int i=0;i<h;i++)
        for(int j=0;j<w;j++)
            cin>>c[i][j];
    for(int i=0;i<h;i++)
        for(int k=0;k<2;k++)
        {
            for(int j=0;j<w;j++)
                cout<<c[i][j];
            cout<<endl;
        }
	return 0;
}


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

int main(){
  int a, b, c; cin >> a >> b >> c;
  if(a==5){
    if((b==7&&c==5)||(b==5&&c==7)){
      cout << "YES" << endl;
    }else{
      cout << "NO" << endl;
    }
  }else{
    if(b==5&&c==5){
      cout << "YES" << endl;
    }else{
      cout << "NO" << endl;
    }
  }
}

Measured memory_bytes: 256
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

N = int(input())
A = []
for i in range(N):
    a = [i , int(input())]
    A.append(a)
    
A.sort(key = lambda x : x[1])

ans = [0]*N

for i in A:
    index = i[0]
    if i[1] == A[-1][1]:
        ans[index] = A[-2][1]
    else:
        ans[index] = A[-1][1]

for i in ans:
    print(i)

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

template<typename T, typename U>
struct segtree {
	ll n, H;
	
	vector<T> value;
	vector<U> prop;
	vector<bool> dirty;

	segtree<T,U>(vector<T> leaves): n(sz(leaves)) {
		H = 32 - __builtin_clz(2*n-1);

		value.resize(2*n);
		copy(all(leaves),begin(value)+n);
		FORD(i,1,n) value[i] = value[2*i] + value[2*i+1];
		
		dirty.resize(n,false);
		prop.resize(n);
	}

	void apply(ll i, U &upd) {
		value[i] = upd(value[i]);
		if (i < n) prop[i] = prop[i] + upd, dirty[i] = true;
	}

	void rebuild(ll i) {
		for (i /= 2; i; i /= 2) value[i] = prop[i](value[2*i] + value[2*i+1]);
	}

	void propagate(ll i) {
		FORD(h,1,H+1) if (dirty[i >> h]) {
			ll j = i >> h;
			apply(2*j,prop[j]), apply(2*j+1,prop[j]);
			prop[j] = U(), dirty[j] = false;
		}
	}

	void update(ll i, ll j, U upd) {
		i += n, j += n;
		propagate(i), propagate(j-1);
		for (ll l = i, r = j; l < r; l /= 2, r /= 2) {
			if (l & 1) apply(l++,upd);
			if (r & 1) apply(--r,upd);
		}
		rebuild(i), rebuild(j-1);
	}
	
	T query(ll i, ll j) {
		i += n, j += n;
		propagate(i), propagate(j-1);
		T resl, resr;
		for (; i < j; i /= 2, j /= 2) {
			if (i & 1) resl = resl + value[i++];
			if (j & 1) resr = value[--j] + resr;
		}
		return resl + resr;
	}
};

struct node {
	ll x = oo;
	node operator+(node n) { return {min(x,n.x)}; }
};

struct update {
	ll y = 0;
	node operator()(node n) { return {n.x+y}; }
	update operator+(update u) { return {y+u.y}; }
};

struct interval {
	ll l, r, v;
	bool operator<(interval i) { return r < i.r; }
};

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll n, m;
	cin >> n >> m;
	
	vector<interval> a(m);
	for (auto &i: a) cin >> i.l >> i.r >> i.v;
	sort(all(a));
	
	segtree<node,update> S(vector<node>(n+1,{0}));
	
	ll j = 0;
	FOR(x,1,n+1) {
		ll value = S.query(0,x).x;
		S.update(x,x+1,{value});
		
		for (; j < m && a[j].r == x; j++) {
			S.update(0,a[j].l,{a[j].v});
		}
	}
	ll res = -S.query(0,n+1).x;
	FOR(i,0,m) res += a[i].v;
	cout << res << endl;
}



Measured memory_bytes: 11264
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>

using namespace std;

#define INF 1e9

const int maxN=110;
int N;
vector<int> X;

void solve(){
    cin >> N;
    X.resize(N);
    for(int i=0;i<N;i++){
        cin >> X[i];
    }
    sort(X.begin(), X.end());

    int min=INF;
    for(int x=X[0];x<=X[N-1];x++){
        long long sum=0;
        for(int i=0;i<N;i++){
            sum+=pow(x-X[i],2);
        }
        if(sum<min) min=sum;
    }
    cout << min << endl;
}


int main(){
    solve();
    return 0;
}

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

int main(void)
{
    int r,g,b,n;
    cin >> r >> g >> b >> n;

    int count =0;
    for(int i = 0; n >= r*i; i++) {
        if (r*i == n) {
            count++;
            continue;
        }
        for (int j = 0; n >= r*i + g*j; j++) {
                if (r*i + g*j == n) {
                    count++;
                } else {
                    int m = n - (r*i + g*j);
                    if (m % b == 0) count++;
                }
        }
    }

    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

#define rep(i, x, n) for(int i = x; i < n; i++)
using namespace std;
const long long INF = 1LL << 60;

long long GCD(long long a, long long b) {
    if(b == 0)
        return a;
    else
        return GCD(b, a % b);
}
long long LCM(long long a, long long b) {
    long long g = GCD(a, b);
    return a / g * b;
}
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 n;
vector<string> res;
char al[] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j'};
void solve(string tmp, int shiyou) {
    if(tmp.size() == n) {
        res.push_back(tmp);
    } else {
        rep(i, 0, shiyou + 2) {

            if(i != shiyou + 1) {
                solve(tmp + al[i], shiyou);
            } else {
                solve(tmp + al[i], shiyou + 1);
            }
        }
    }
}
int main() {

    cin >> n;
    solve("a", 0);
    for(string t : res) {
        cout << t << endl;
    }
}


Measured memory_bytes: 7796
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);i++)
#define REP2(i,m,n) for (int i=m;i<(n);i++)
typedef long long ll;
typedef long double ld;
#define fst first
#define snd second
#define all(c) ((c).begin()), ((c).end())


struct graph {
    int n;
    vector<vector<int>> adj, rdj;
    vector<int> group;
    graph(int n) : n(n), adj(n), rdj(n), group(n) { }
    void add_edge(int src, int dst) {
        adj[src].push_back(dst);
        rdj[dst].push_back(src);
    }

    vector<vector<int>> strongly_connected_components() { // kosaraju
        vector<int> ord, visited(n);
        vector<vector<int>> scc;
        function<void(int,vector<vector<int>>&, vector<int>&)> dfs
            = [&](int u, vector<vector<int>> &adj, vector<int> &out) {
            visited[u] = true;
            for (int v: adj[u])
        if (!visited[v]) dfs(v, adj, out);
            out.push_back(u);
        };
        for (int u = 0; u < n; ++u)
            if (!visited[u]) dfs(u, adj, ord);
        fill(all(visited), false);
        for (int i = n-1; i >= 0; --i)
            if (!visited[ord[i]])
                scc.push_back({}), dfs(ord[i], rdj, scc.back());
        for (int i = 0; i < (int)scc.size(); ++i)
            for (int j = 0; j < (int)scc[i].size(); ++j)
                group[scc[i][j]] = scc[i][0];
        return scc;
    }
};

int N;
int G[26][26];
bool used[26];

void solve() {
    cin >> N;
    graph g(26);

    REP(i, N) {
        string s;
        cin >> s;
        G[s.front()-'a'][s.back()-'a'] += 1;
        used[s.front()-'a'] = true;
        used[s.back()-'a']  = true;
    }

    REP(i, 26) REP2(j, i+1, 26) {
        int m = min(G[i][j], G[j][i]);
        G[i][j] -= m;
        G[j][i] -= m;
        while (G[i][j]--) g.add_edge(i, j);
        while (G[j][i]--) g.add_edge(j, i);
    }

    vector<vector<int>> scc = g.strongly_connected_components();

    REP(i, 26) if (used[i]) {
        bool ok = (int)g.rdj[i].size() - (int)g.adj[i].size() >= 0;
        for (auto j: g.adj[i]) if (g.group[i] != g.group[j]) ok = false;
        if (ok) cout << (char)('a' + i) << endl;
    }
}

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



Measured memory_bytes: 3248
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef tuple<ll,ll,ll> T;
int main(){
  ll n,x=0,y=0;
  cin>>n;
  ll a[n],b[n];
  vector<T> p(n);
  for(ll i=0;i<n;i++){
    cin>>a[i]>>b[i];
    p.push_back(T(a[i]+b[i],a[i],i));
  }
  sort(p.begin(),p.end());
  reverse(p.begin(),p.end());
  for(int i=0;i<n;i++){
    if(i%2==0){
      x+=a[get<2>(p[i])];
    }else{
      y+=b[get<2>(p[i])];
    }
  }
  cout<<x-y;
}


Measured memory_bytes: 6528
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <cstring>

using namespace std;

bool includes_keyword(const char *str) {
  const static char *keywords[] = { "the", "this", "that" };
  for (const auto keyword : keywords) {
    const char *pos = strstr(str, keyword);
    if (pos == NULL) { continue; }
    if (pos != str && isalpha(pos[-1])) { continue; }
    if (isalpha(pos[strlen(keyword)])) { continue; }
    return true;
  }
  return false;
}

int main() {
  char *cipher = NULL;
  size_t buffer_size = 0;
  ssize_t len;
  while ((len = getline(&cipher, &buffer_size, stdin)) > 0) {
    if (cipher[len - 1] == '\n') {
      cipher[len - 1] = '\0';
      len -= 1;
    }

    char decoded[81];
    for (int i = 0; i < 26; ++i) {
      strcpy(decoded, cipher);
      for (int j = 0; j < len; ++j) {
        if (islower(decoded[j])) {
          decoded[j] += i;
          if (!islower(decoded[j])) { decoded[j] -= 26; }
        }
      }
      if (includes_keyword(decoded)) { break; }
    }
    puts(decoded);
  }

  free(cipher);

  return 0;
}

Measured memory_bytes: 980
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
  vector<int> a(5);
  for(int i=0; i<5; i++) cin >>a[i];
  sort(a.begin(), a.end());
  cout <<a[4]<<" "<<a[3]<<" "<<a[2]<<" "<<a[1]<<" "<<a[0]<<endl;
  return 0;
}

Measured memory_bytes: 1212
S = input()
if 1 <= int(S[:2]) <=12 and 1 <= int(S[2:]) <=12:
    ans = 'AMBIGUOUS'
elif 1 <= int(S[:2]) <=12:
    ans = 'MMYY'
elif 1 <= int(S[2:]) <=12:
    ans = 'YYMM'
else:
    ans = 'NA'

print(ans)

Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>

int main() {
    int h, w;
    char *s = NULL;

    scanf("%d %d", &h, &w);
    s = (char *)malloc(sizeof(char) * h * w);

    for (int i = 0; i < h; i++) {
        scanf("%s", s+(i*w));
    }

    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            printf("%c", *(s + (i * w) + j));
            if (j % w == w - 1) {
                printf("\n");
            }
        }
        for (int j = 0; j < w; j++) {
            printf("%c", *(s + (i * w) + j));
            if (j % w == w - 1) {
                printf("\n");
            }
        }
    }

    if (s != NULL) {
        free(s);
        s = NULL;
    }
    return 0;
}


Measured memory_bytes: 128
import math
a, b, x = list(map(int,input().split()))
if x >= ((a**2)*b)/2:
    x = (x * 2)/(a**2) #台形の面積
    tan_theta = (2*b - x)/a
    theta = math.atan(tan_theta)
    ans = math.degrees(theta)
else:
    tan_theta = (a*(b**2))/(2*x)
    theta = math.atan(tan_theta)
    ans = math.degrees(theta)

print(ans)

Measured memory_bytes: 3060
import sys
range = xrange
input = sys.stdin.readline

h,w,n = [int(x) for x in input().split()]

sy,sx = [int(x) for x in input().split()]

S = input().rstrip()
T = input().rstrip()

smallx = bigx = sx
smally = bigy = sy

dx = 0
dy = 0

for i in range(n):
    c = S[i]
    if c=='R':
        bigx += 1
    elif c=='L':
        smallx -= 1
    elif c=='U':
        smally -= 1
    elif c=='D':
        bigy += 1

    if smallx<1:
        tmp = min(1 - smallx, dx)
        dx -= tmp
        smallx += tmp
        bigx += tmp
    
    if smally<1:
        tmp = min(1 - smally, dy)
        dy -= tmp
        smally += tmp
        bigy += tmp
    

    if smallx < 1 or bigx > w or smally < 1 or bigy > h:
        print 'NO'
        sys.exit()


    c = T[i]
    if c=='R':
        smallx += 1
    elif c=='L':
        bigx -= 1
    elif c=='U':
        bigy -= 1
    elif c=='D':
        smally += 1

    # default to left
    if smallx>bigx:
        smallx = bigx
        dx += 1
    if smally>bigy:
        smally = bigy
        dy += 1

    if smallx<1:
        tmp = min(1 - smallx, dx)
        dx -= tmp
        smallx += tmp
        bigx += tmp
    
    if smally<1:
        tmp = min(1 - smally, dy)
        dy -= tmp
        smally += tmp
        bigy += tmp


    if smallx < 1 or bigx > w or smally < 1 or bigy > h:
        print 'NO'
        sys.exit()
print 'YES'
sys.exit()


Measured memory_bytes: 34664
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#define LL long long
#define M 702
using namespace std;
namespace IO{
	const int BS=(1<<20)+5; int Top=0;
	char Buffer[BS],OT[BS],*OS=OT,*HD,*TL,SS[20]; const char *fin=OT+BS-1;
	char Getchar(){if(HD==TL){TL=(HD=Buffer)+fread(Buffer,1,BS,stdin);} return (HD==TL)?EOF:*HD++;}
	void flush(){fwrite(OT,1,OS-OT,stdout);}
	void Putchar(char c){*OS++ =c;if(OS==fin)flush(),OS=OT;}
	void write(int x){
		if(!x){Putchar('0');return;} if(x<0) x=-x,Putchar('-');
		while(x) SS[++Top]=x%10,x/=10;
		while(Top) Putchar(SS[Top]+'0'),--Top;
	}
	int read(){
		int nm=0,fh=1; char cw=getchar();
		for(;!isdigit(cw);cw=getchar()) if(cw=='-') fh=-fh;
		for(;isdigit(cw);cw=getchar()) nm=nm*10+(cw-'0');
		return nm*fh;
	}
}
using namespace IO;
int n,m,p[M][M],g[M][M],f[M][M],ans;
char ch[M];
#define S(a,b,c,d) (f[c][d]-f[a-1][d]-f[c][b-1]+f[a-1][b-1])
int main(){
	//freopen(".in","r",stdin);
//	freopen("map.out","w",stdout);
	n=read(),m=read();
	for(int i=1;i<=n;i++){
		scanf("%s",ch+1);
		for(int j=1;j<=m;j++) if(ch[j]=='#') g[i+j][i-j+m+1]=1;
	}
	n=n+m,m=n;
	for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) f[i][j]=f[i][j-1]+f[i-1][j]-f[i-1][j-1]+g[i][j];
//	for(int i=1;i<=n;i++,puts("")) for(int j=1;j<=n;j++) printf("%d ",g[i][j]);
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			if(!g[i][j]) continue;
			for(int d=2;j+d<=n;d++){
				if(!g[i][j+d]) continue;
				if(i>d) ans+=S(i-d,j+1,i-d,j+d-1);
				if(i+d<=n) ans+=S(i+d,j+1,i+d,j+d-1);
			}
			for(int d=2;i+d<=n;d++){
				if(!g[i+d][j]) continue;
				if(j>d) ans+=S(i+1,j-d,i+d-1,j-d);
				if(j+d<=n) ans+=S(i+1,j+d,i+d-1,j+d);
			}
			for(int d=1;d<=n;d++){
				if(i>d&&j>d) ans+=(g[i-d][j]&g[i][j-d]);
				if(i>d&&j+d<=n) ans+=(g[i-d][j]&g[i][j+d]);
				if(i+d<=n&&j>d) ans+=(g[i+d][j]&g[i][j-d]);
				if(i+d<=n&&j+d<=n) ans+=(g[i+d][j]&g[i][j+d]);
			} 
		}
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 6144
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

string s, t;
int ss[110000], st[110000];

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	cin >> s >> t;
	rep(i, s.size()) ss[i + 1] = (ss[i] + (s[i] == 'A' ? 1 : 2)) % 3;
	rep(i, t.size()) st[i + 1] = (st[i] + (t[i] == 'A' ? 1 : 2)) % 3;
	
	int n; cin >> n;
	while(n--){
		int a, b, c, d; cin >> a >> b >> c >> d; a--; c--;
		int x = (st[d] - st[c] + 3) % 3;
		int y = (ss[b] - ss[a] + 3) % 3;
		cout << (x == y ? "YES" : "NO") << endl;
	}
	return 0;
}

Measured memory_bytes: 1744
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()



int main(void){
	int X,A;
    cin >> X >> A;
    int p;
    if(X<A){
        p = 0;
    }else{
        p = 10;
    }
    cout << p << endl;

    return 0;
}


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

int main(){
  ll i,j,k,n,m,t;
  cin>>n>>m;
  ll cn=0;
  for(i=22;i<=m;i++){
     ll d1=i%10;
    ll d2=i/10;
    if(d1>=2 && d2>=2 && d1*d2<=n) cn+=1;
  }
  cout<<cn<<"\n";
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <ctime>
#include <unordered_map>
#include <stdlib.h>
using namespace std;
#define ll  long long int
#define mod 1000000007
#define modd 998244353
#define com(a,n) for(ll i=0;i<n;i++) cin>>a[i];
#define pri(a,n) for(ll i=0;i<n;i++) cout<<a[i]<<endl;
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
 ll gcdExtended(ll a, ll b, ll *x, ll *y) ;
    ll modInverse(ll a, ll m) 
    { 
        ll x, y; 
        ll g = gcdExtended(a, m, &x, &y); 
        // if (g != 1) 
        //     cout << "Inverse doesn't exist"; 
        // else
        // { 
            // m is added to handle negative x 
            ll res = (x%m + m) % m; 
            return res; 
        // } 
    } 
      
    // // C function for extended Euclidean Algorithm 
    ll gcdExtended(ll a, ll b, ll *x, ll *y) 
    { 
        // Base Case 
        if (a == 0) 
        { 
            *x = 0, *y = 1; 
            return b; 
        } 
      
        ll x1, y1; // To store results of recursive call 
        ll gcd = gcdExtended(b%a, a, &x1, &y1); 
      
        // Update x and y using results of recursive 
        // call 
        *x = y1 - (b/a) * x1; 
        *y = x1; 
      
        return gcd; 
    }
ll modu(ll n)
{
    if(n < 0)
    n+=mod;
    else 
    n = n%mod;
    return n;
}
ll power(ll x, unsigned ll y, ll p)  
{  
    ll res = 1;     // Initialize result  
  
    x = x % p; // Update x if it is more than or  
                // equal to p 
   
    if (x == 0) return 0; // In case x is divisible by p; 
  
    while (y > 0)  
    {  
        // If y is odd, multiply x with result  
        if (y & 1)  
            res = (res*x) % p;  
  
        // y must be even now  
        y = y>>1; // y = y/2  
        x = (x*x) % p;  
    }  
    return res;  
}
int main()
{
    boost;
    ll n;
    cin>>n;
    ll k = power(10,n,mod);
    ll ans = k;
    k = power(9,n,mod);
    ll z= power(8,n,mod);
    ans = modu(ans -modu(2*k) + z);
    cout<<ans<<"\n"; 
}

Measured memory_bytes: 3608
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


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

	int M;
	scanf("%d",&M);

	int Q[M];
	for(int i = 0; i < M; i++)scanf("%d",&Q[i]);
	sort(Q,Q+M);

	int left = 0,right,m,count = 0;

	for(int i = 0; i < M; i++){
		right = N-1;
		m = (left+right)/2;

		while(left <= right){
			if(S[m] == Q[i]){
				count++;
				left= m+1;
				break;
			}else if(S[m] > Q[i]){
				right = m-1;
			}else{ //S[m] < Q[i]
				left = m+1;
			}
			m = (left+right)/2;
		}
	}
	printf("%d\n",count);
}



Measured memory_bytes: 3776
/*input
2 6
*/

#include <bits/stdc++.h>
#define ll long long

using namespace std;

void run() {
	ll n, k;
	cin >> n >> k;
	n %= k;
	cout << min(n, k-n) << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);		
	int t = 1;
	while(t--) {
		run();
	}
}


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

int num[300010], mx[300010], frac[300010]; 
int ok[300010], ans[300010];
int n;

int main() {
    cin >> n;
    for (int i = 1; i <= n; i++) {
        int x;
        cin >> x;
        num[x]++;
    }
    for (int i = 1; i <= n; i++) {
        mx[0]++;
        mx[num[i] + 1]--;
        frac[num[i] + 1] += num[i];
    }
    for (int i = 1; i <= n; i++) {
        mx[i] += mx[i - 1];
        frac[i] += frac[i - 1];
    }
    for (int i = 1; i <= n; i++) {
        int j = mx[i] * i + frac[i];
        ok[j / i] = i;
    }
    for (int i = n; i >= 1; i--) {
        ans[i] = max(ans[i + 1], ok[i]);
    }
    for (int i = 1; i <= n; i++) cout << ans[i] << '\n';
}

Measured memory_bytes: 6016
#include <bits/stdc++.h>
using namespace std;
 
int row[300010], col[300010];	// マップ 
int X[300010], Y[300010];		// 爆弾リスト  
int vr[300010], vc[300010];
vector <int> R, C;				// 一番爆弾があるX座標、Y座標(複数個) 
int maxr = -1, maxc = -1;
 
int main () {
	// 入力を受け取る 
	int n, m, k; scanf("%d%d%d", &n, &m, &k);
	for (int i = 0; i < k; i++) {
		int x, y; scanf("%d%d", &x, &y);
		row[x]++, col[y]++;	// マップに記録 
		X[i] = x, Y[i] = y;	// 爆弾リストに記録 
	}

	// X軸の最大値を集める(最大値だけ全て持っておく) 
	                	// ^^^^^^^^^^^^^^^^^^^^^^^
	for (int i = 1; i <= n; i++) {
		if (row[i] > maxr) maxr = row[i], R.clear(), R.push_back(i);
		else if (row[i] == maxr) R.push_back(i);
	}
	// Y軸の最大値を集める(最大値だけ全て持っておく) 
	                	// ^^^^^^^^^^^^^^^^^^^^^^^ 
	for (int i = 1; i <= m; i++) {
		if (col[i] > maxc) maxc = col[i], C.clear(), C.push_back(i);
		else if (col[i] == maxc) C.push_back(i);
	}

	// 爆破地点に破壊対象が置いてあるか?
	for (int i = 0; i < R.size(); i++) {
		vr[R[i]] = 1;	// 一番多いX座標にフラグを立てる 
	}
	for (int i = 0; i < C.size(); i++) {
		vc[C[i]] = 1;	// 一番多いY座標にフラグを立てる 
	}
	int cnt = 0;
	for (int i = 0; i < k; i++) {
		if (vr[X[i]] && vc[Y[i]]) cnt++;	// ある爆弾が一番多いX,Y座標の交点とかぶっている 
	}
	if (cnt == R.size() * C.size()) printf("%d\n", maxr + maxc - 1);	// 交点の数と爆弾がかぶっている数が同じ 
	else printf("%d\n", maxr + maxc);	// 交点の数と爆弾がかぶっている数が違う = かぶっていない交点がある 

	return 0;
}

Measured memory_bytes: 12808