akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp43 {
    class Program {
        static void Main(string[] args) {
            var st = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

            int A = st[0];
            int B = st[1];

            var hairetsu = new int[13] { 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 1 };

            if (Array.IndexOf(hairetsu, A) < Array.IndexOf(hairetsu, B)) {
                Console.WriteLine("Bob");
            } else if (Array.IndexOf(hairetsu, A) == Array.IndexOf(hairetsu, B)) {
                Console.WriteLine("Draw");
            } else {
                Console.WriteLine("Alice");
            }

        }

    }
}


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

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

using namespace std;

const int INF=1<<29;

string s;
int dp[1000002][2];

int dfs(int i,int carry){
	if(i==s.length()) return carry;

	if(dp[i][carry]!=-1) return dp[i][carry];

	int res=INF,a=s[i]-'0';
	rep(d,10){
		res=min(res,dfs(i+1,(a+d+carry)/10)+(a+d+carry)%10+d);
	}
	return dp[i][carry]=res;
}

int main(){
	memset(dp,-1,sizeof dp);

	cin>>s;
	reverse(s.begin(),s.end());
	s+="0";

	printf("%d\n",dfs(0,0));

	return 0;
}


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

int main(void){
     int n,i=0;

     while(cin >> n,!cin.eof()){
	  for(int a=0;a<10;a++){
	       for(int b=0;b<10;b++){
		    for(int c=0;c<10;c++){
			 for(int d=0;d<10;d++){
			      if(n == a+b+c+d){
				   i = i+1;
			      }
			 }
		    }
	       }
	  }
	  cout << i << endl;
	  i=0;
     }


     return 0;
}

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

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define FOR(i, n) for (int i = 0; i < int(n); i++)
#define FOR1(i, m, n) for (int i = int(m); i < int(n); i++)
#define MAX(a, b) ((a) >= (b) ? (a) : (b))
#define MIN(a, b) ((a) <= (b) ? (a) : (b))

int main() {
  int N;

  scanf("%d", &N);

  FOR1(h, 1, 3501) {
    FOR1(n, h, 3501) {
      ll a = (ll)N * h * n;
      ll b = (ll)4 * h * n - N * n - N * h;
      if (b > 0 && a % b == 0) {
        ll w = a / b;
        printf("%d %d %lld\n", h, n, w);
        goto LOOP_END;
      }
    }
  }
LOOP_END:
  
  return 0;
}


Measured memory_bytes: 256
var
	s:String;
	a:Array[1..4]of Longint;
	i,j,k,now:Longint;
begin
	readln(s);
	for i:=1 to 4 do a[i]:=ord(s[i])-48;
	for i:=0 to 1 do for j:=0 to 1 do for k:=0 to 1 do begin
		now:=a[1];
		if i=0 then inc(now,a[2])else dec(now,a[2]);
		if j=0 then inc(now,a[3])else dec(now,a[3]);
		if k=0 then inc(now,a[4])else dec(now,a[4]);
		if now=7 then begin
			write(a[1]);
			if i=0 then write('+')else write('-');
			write(a[2]);
			if j=0 then write('+')else write('-');
			write(a[3]);
			if k=0 then write('+')else write('-');
			write(a[4]);
			writeln('=7');
			exit;
		end;
	end;
end.


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=((n)-1);(i)>=0;(i)--)
#define itn int
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
const long long INF = 1LL << 60;
const int MOD = 1000000007;
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; }
//https://www.creativ.xyz/dump-cpp-652/
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
 
// vector
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec) is >> x;
    return is;
}
// pair
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &pair_var) {
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}
// vector
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
// map
template <typename T, typename U>
ostream &operator<<(ostream &os, map<T, U> &map_var) {
    os << "{";
    repi(itr, map_var) {
        os << *itr;
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// set
template <typename T>
ostream &operator<<(ostream &os, set<T> &set_var) {
    os << "{";
    repi(itr, set_var) {
        os << *itr;
        itr++;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
 
#define DUMPOUT cerr
 
void dump_func() {
    DUMPOUT << endl;
}
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&... tail) {
    DUMPOUT << head;
    if (sizeof...(Tail) > 0) {
        DUMPOUT << ", ";
    }
    dump_func(std::move(tail)...);
}

#ifdef DEBUG_
#define DEB
#define dump(...)                                                              \
    DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
            << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
            << endl                                                            \
            << "    ",                                                         \
        dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif

signed main(void) { cin.tie(0); ios::sync_with_stdio(false);
    int a,b; cin>>a>>b;
    vector <int> data(3);
    data[a-1] = data[b-1] = true;
    if(!data[0]) cout<<1<<endl;
    else if(!data[1]) cout<<2<<endl;
    else cout<<3<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define mrep(i,j,n) for(int i = j; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)
#define rreps(i,n) for(int i = n; i >= 1; i--)
#define co(x) cout << x <<endl
#define cs(x) cout << x <<" "
#define el cout<<endl
#define cer(x) cerr << x <<endl
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(ALL(x), val), x.end())

typedef long long ll;
typedef unsigned long long ull;
using namespace std;
ll mod = 1e9 + 7;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }

ll gcd(ll a, ll b)
{
	return b == 0 ? a : gcd(b, a % b);
}

ll lcm(ll a, ll b)
{
	ll g = gcd(a, b);
	return a * b / g;
}

int main()
{
	int a, b; cin >> a >> b;
	co(lcm(a, b));
	return 0;
}


Measured memory_bytes: 256
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <ctype.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>
#include <math.h>

#define N_MAX (100)
#define P_MAX (100)
#define DP_ARRAY_SIZE (N_MAX * P_MAX / 32 + 1)

#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? -(a) : (a))
#define ABSS(a, b) ((a) > (b) ? (a) - (b) : (b) - (a))

int compare_sz_asc(const void* a, const void* b) {
    return *((size_t*)a) < *((size_t*)b) ? -1 : 1;
}

int compare_sz_desc(const void* a, const void* b) {
    return *((size_t*)a) > * ((size_t*)b) ? -1 : 1;
}

int compare_i64_asc(const void* a, const void* b) {
    return *((int64_t*)a) < *((int64_t*)b) ? -1 : 1;
}

int compare_i64_desc(const void* a, const void* b) {
    return *((int64_t*)a) > * ((int64_t*)b) ? -1 : 1;
}

int compare_c_asc(const void* a, const void* b) {
    return *((char*)a) < *((char*)b) ? -1 : 1;
}

int compare_c_desc(const void* a, const void* b) {
    return *((char*)a) > * ((char*)b) ? -1 : 1;
}

static size_t powSz(const size_t base, const size_t exp) {
    if (exp == 0) {
        return 1;
    }

    if (exp == 1) {
        return base;
    }

    if (exp % 2 == 0) {
        return powSz(base * base, exp / 2);
    }
    else {
        return base * powSz(base, exp - 1);
    }
}

static size_t comb(const size_t n, const size_t r) {
    size_t result = 1;

    for (size_t i = 0; i < r; i++) {
        result *= n - i;
        result /= i + 1;
    }

    return result;
}

static uint64_t combU64(const uint64_t n, const uint64_t r) {
    uint64_t result = 1;

    for (uint64_t i = 0; i < r; i++) {
        result *= n - i;
        result /= i + 1;
    }

    return result;
}

static size_t gcdZu(size_t m, size_t n) {
    size_t temp;

    while (m % n != 0) {
        temp = n;
        n = m % n;
        m = temp;
    }

    return n;
}

static uint64_t gcdU64(uint64_t m, uint64_t n)
{
    uint64_t temp;

    while (m % n != 0) {
        temp = n;
        n = m % n;
        m = temp;
    }

    return n;
}

int main(void) {
    int64_t A, B;

    scanf("%"PRId64" %"PRId64, &A, &B);

    if ((A + B) % 2 == 0) {
        printf("%"PRId64"\n", (A + B) / 2);
    }
    else {
        puts("IMPOSSIBLE");
    }

    return 0;
}


Measured memory_bytes: 128
package main

import (
	"fmt"
)

func main() {
	numbers := []int8{0, 0, 0}
	for i := 0; i < 3; i++ {
		fmt.Scan(&numbers[i])
	}

	unique_numbers := []bool{true, true, true}
	for i := 0; i < 3; i++ {
		for j := i + 1; j < 3; j++ {
			if i != j && numbers[i] == numbers[j] {
				unique_numbers[j] = false
			}
		}
	}

	answer := 0
	for i := 0; i < 3; i++ {
		if unique_numbers[i] {
			answer++
		}
	}

	fmt.Println(answer)
}


Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
#include <queue>
#include <set>

using namespace std;

typedef unsigned long long int ULL;
typedef long long LL;
typedef long double LD;


int main()
{
	
	LL N, W;
	cin >> N >> W;

	vector<LL> w(N), v(N);

	for (LL i = 0; i < N; ++i) {
		cin >> w[i] >> v[i];
	}

	vector<LL> d[2];

	for (int i = 0; i < W+1; ++i) {
		d[0].push_back(0);
		d[1].push_back(0);
	}

	for (int i = w[0]; i < W+1; ++i) {
		d[0][i] = v[0];
	}

	for (int i = 1; i < N; ++i) {
		for (int j = 0; j <= W; ++j) {
			d[1][j] = max(d[0][j], (j - w[i] >= 0 ? d[0][j-w[i]]+v[i] : 0));
		}

		for (int j = 0; j <= W; ++j) {
			d[0][j] = d[1][j];
		}
	}

	cout << d[0][W] << endl;


	 
}

Measured memory_bytes: 2036
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int m, n, i, cnt = 0, sum = 0;
    float x;
    cin>>n>>m;
    int a[n];
    for(i = 0; i<n; i++)
    {
        cin>>a[i];
    }
    for(i = 0; i<n; i++)
    {
        sum += a[i];
    }
    x = (1.0/(4.0*m))*sum;

    for(i = 0; i<n; i++)
    {
        if(a[i]>=x)
        {
            cnt++;
        }
    }
    if(cnt>=m) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

    return 0;
}


Measured memory_bytes: 3552
#include <stdio.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define min(p,q)((p)<(q)?(p):(q))

int main(){
	ll n;
	while(scanf("%lld",&n),n){
		ll ans=1e9;
		rep(z,0,ans){
			if(z*z*z>n)break;
			rep(y,0,ans-z){
				if(z*z*z+y*y>n)break;
				ans=min(ans,z+y+n-z*z*z-y*y);
			}
		}
		printf("%lld\n",ans);
	}
}


Measured memory_bytes: 2100
#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 = 1e9 + 7;
const int N = 100100;
const int K = 250;
vector < pair < int, int > > g[N];
int d[N], was[N];
map < pair < int, int >, int > used;
map < pair < int, int >, vector < int > > g2;
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= m; i++){
        int u, v, c;
        cin >> u >> v >> c;
        g[u].pb({v, c});
        g[v].pb({u, c});
        g2[{v, c}].pb(u);
        g2[{u, c}].pb(v);
    }
    for (int i = 2; i <= n; i++) d[i] = 1e9;
    deque < pair < int, int > > q;
    set < pair < pair < int, int >, int > > s;
    q.push_front({1, -1});
    while(!q.empty() || !s.empty()){
        int v, col, co;
        if (!q.empty()){
            auto z = q.front();
            q.pop_front();
            v = z.F;
            col = z.S;
            co = d[v];
        } else{
            auto z = *s.begin();
            s.erase(s.begin());
            v = z.F.S;
            col = z.S;
            co = z.F.F;
        }
        used[{v, col}] = 1;
        if (co > d[v]) continue;
        int z = 1;
        for (auto u: g2[{v, col}])
            if (d[u] >= co && !used[{u, col}]){
                d[u] = d[v];
                q.push_front({u, col});
                used[{u, col}] = 1;
                z = 0;
        }
        if (!z) q.push_back({v, col}); else
        if (!was[v]){
            was[v] = 1;
            for (auto u: g[v]){
                if (d[u.F] >= co + 1 && u.S != col && !used[{u.F, u.S}]){
                    d[u.F] = co + 1;
                    s.insert({{d[u.F], u.F}, u.S});
                }
            }
        }
    }
    if (d[n] == 1e9) cout << -1; else
    cout << d[n];
}


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

int main() {
    string g;
    while (cin >> g, g != "#") {
        int y, m, d;
        cin >> y >> m >> d;

        if (g == "HEISEI" && y > 31) {
            cout << "? " << y - 30 << " " << m << " " << d << endl;
        } else if (g == "HEISEI" && y == 31 && m >= 5) {
            cout << "? 1 " << m << " " << d << endl;
        } else {
            cout << g << " " << y << " " << m << " " << d << endl;
        }
    }

    return 0;
}


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

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

using namespace std;
using lint = long long;

int main(void)
{
    int A, B;
    cin >> A >> B;
    cout << max(0, A-B*2) << endl;
    return 0;
}


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

int main() {
  int n;
  cin >> n;
  
  int count = 0;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    if (i % 2 == 0 && a % 2 == 1)
      count++;
  }
  
  cout << count << endl;
}

Measured memory_bytes: 3588
# stack
class stack(object):
    def __init__(self):
        self.container = [] # Empty Stack
        self.topIndex = -1
    def push(self, elem):
        self.container.append(elem)
        self.topIndex += 1
    def pop(self):
        if self.topIndex > -1:
            elem = self.container[self.topIndex]
            del self.container[self.topIndex]
            self.topIndex -= 1
            return elem
        else:
            return None

def calc(ins):
    stk = stack()
    try:
        for sin in ins:
            if sin == '+':
                stk.push(stk.pop() + stk.pop())
            elif sin == '-':
                a, b = stk.pop(), stk.pop()
                stk.push(b - a)
            elif sin == '*':
                stk.push(stk.pop() * stk.pop())
            elif sin == '/':
                a, b = stk.pop(), stk.pop()
                stk.push(b / a)
            else:
                stk.push(int(sin))
        return stk.pop()
    except:
        print 'Bad Expr'

print calc(raw_input().split(' '))

Measured memory_bytes: 6360
#include <bits/stdc++.h>
using namespace std;
int main()
{
	long long int n,a,b;
	cin>>n;
	if(n%1000==0)
	{
	a=n/1000;
	}
	else
	{
		a=(n/1000)+1;
	}
	b=(a*1000)-n;
	cout<<b<<endl;
}

Measured memory_bytes: 3628
import sys
import numpy as np
from numba import njit

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

INF = 10**9 + 1

N, M = map(int, readline().split())
data = np.int64(read().split()).reshape(-1, 3)

A = data[:N, 0]
B = data[:N, 1]
C = data[:N, 2]
D = data[N:, 0]
E = data[N:, 1]
F = data[N:, 2]

X = np.unique(np.concatenate([A, B, D, [0, -INF, INF]]))
Y = np.unique(np.concatenate([C, E, F, [0, -INF, INF]]))
DX = X[1:] - X[:-1]
DY = Y[1:] - Y[:-1]

A, B, D = map(lambda x: np.searchsorted(X, x), (A, B, D))
C, E, F = map(lambda x: np.searchsorted(Y, x), (C, E, F))

H, W = len(X), len(Y)
N = H * W

@njit
def set_ng(A, B, C, D, E, F):
    ng = np.zeros((N, 4), np.bool_)

    for i in range(len(A)):
        for x in range(A[i], B[i]):
            v = x * W + C[i]
            ng[v][1] = 1
            ng[v - 1][0] = 1

    for i in range(len(D)):
        for y in range(E[i], F[i]):
            v = D[i] * W + y
            ng[v][3] = 1
            ng[v - W][2] = 1
    return ng

@njit
def solve():
    ng = set_ng(A, B, C, D, E, F)
    x0, y0 = np.searchsorted(X, 0), np.searchsorted(Y, 0)
    v0 = x0 * W + y0
    visited = np.zeros(N, np.bool_)
    visited[v0] = 1
    stack = [v0]
    ret = 0

    def area(x):
        x, y = divmod(x, W)
        return DX[x] * DY[y]

    def push(x):
        nonlocal ret
        stack.append(x)
        visited[x] = 1
        ret += area(x)

    push(v0)
    move = (1, -1, W, -W)
    while stack:
        v = stack.pop()
        for i in range(4):
            if ng[v][i]:
                continue
            w = v + move[i]
            if visited[w]:
                continue
            x, y = divmod(w, W)
            if x == 0 or x == H - 1 or y == 0 or y == W - 1:
                return 0
            push(w)
    return ret

x = solve()
if x == 0:
    print('INF')
else:
    print(x)

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

int main(){
  int n;
  cin >> n;
  int order = to_string(n).size();//桁数
  vector<int>select(3);
  select = {3,5,7};
  int ans = 0;
  int s = 0;
  for (int i = 3; i <= order; i++){
    
    int ways = pow(3, i);
    for (int j = 0; j < ways; j++){
      int real = 0;
      int newj = j;
      vector<int>micro(i);
      for (int k = 0; k < i; k++){
       
        micro.at(k) = newj % 3;
        real = 10 * real + select.at(micro.at(k));
        newj /= 3;
      }
      
      vector<int>var(3);
      for (int k = 0; k < i; k++){
        if (micro.at(k) == 0)
          var.at(0)++;
        if (micro.at(k) == 1)
          var.at(1)++;
        if (micro.at(k) == 2)
          var.at(2)++;
      }
      if (real <= n && var.at(0) > 0 && var.at(1) > 0&& var.at(2) >0 && var.at(0)+ var.at(1) + var.at(2) ==i ){
        ans++;
      }
    }
  }
  cout << ans << endl;
}
        
      
    
  
                       
                    

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template<class T> inline bool chmax(T&a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T&a,T b){if(a>b){a=b;return 1;}return 0;}
typedef long long ll;

int n,m,k;
string s,t;
vector<pair<int,int>> g[100005];
int ans[100005];

void dfs(int v, int p, int c){
  ans[v]=c;
  for(auto e : g[v]){
    if(e.first==p) continue;
    if(e.second & 1) dfs(e.first,v,1-c);
    else dfs(e.first,v,c);
  }
}

int main() {
  cin >> n;
  int a,b,c;
  rep(i,n-1){
    cin >> a >> b >> c; a--,b--;
    g[a].push_back({b,c});
    g[b].push_back({a,c});
  }
  dfs(0,-1,0);
  rep(i,n) cout << ans[i] << endl;
}

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

int main() {
	int N, M, A[100001], B[100001];
	cin >> N >> M;
	repeat(i, M) {
		cin >> A[i] >> B[i];
	}

	map<int, string> Amap, Bmap;

	repeat(i, M) {
		Amap[A[i]] += to_string(i);
		Amap[A[i]] += ",";
		Bmap[B[i]] += to_string(i);
		Bmap[B[i]] += ",";
	}

	int kikenline[100001] = {};
	int setudankaisuu = 0;

	repeat(i, N) {
		while (Amap[i].length() != 0) {
			int num = stoi(Amap[i].substr(0, Amap[i].find(",")));
			kikenline[num] = setudankaisuu + 1;
			Amap[i].erase(0, Amap[i].find(",") + 1);
		}
		int setudanflag = 0;
		while (Bmap[i + 1].length() != 0) {
			int num = stoi(Bmap[i + 1].substr(0, Bmap[i + 1].find(",")));
			if (kikenline[num] == setudankaisuu + 1) setudanflag = 1;
			kikenline[num] = 0;
			Bmap[i + 1].erase(0, Bmap[i + 1].find(",") + 1);
		}
		if (setudanflag == 1) setudankaisuu++;
	}

	cout << setudankaisuu << endl;
	return 0;
}

Measured memory_bytes: 21888
package main

import (
	"fmt"
)

func main() {
	var s string
	fmt.Scan(&s)

	for i, v := range s {
		if i == len(s)-1 {
			break
		}
		if string(s[i+1]) == string(v) {
			fmt.Println("Bad")
			return
		}
	}
	fmt.Println("Good")
}


Measured memory_bytes: 512
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)

thd = sum(A) / (M*4)

flag = 'Yes'
for i in range(M):
    if A[i] < thd:
        flag = 'No'
        break

print(flag)




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

bool all_same(string S){
	char prev = S[0];
  	for (const auto &s: S)
      if (prev != s) return false;
  	return true;
}

int cnt_front(string S){
    char prev = S[0];
    int i = 0;
  	for (i = 0; i < S.length(); i++)
      if (prev != S[i]) return i;
    return i;
}

int main(void){
    // Your code here!
    string S;
    int64_t k;
    cin >> S >> k;
  	
  	if (all_same(S)){
  		cout << S.size() * k / 2 << endl;
  		return 0;
	}
  
    string T = S + S;
    int n = S.length();
    int64_t ans = 0;
    int cnt = 1;
    char prev = 'A';
    for (int i = 0; i < 2 * n; i++){
        if (prev == T[i])
            cnt++;
        else{
            if (i >= n + 1)
                ans += cnt / 2;
            cnt = 1;
        }
      	prev = T[i];
    }
    int b = 0;
  	if (S[0] != S[n - 1])
    	ans += cnt / 2;
    	
    	
    else if (cnt_front(S) % 2 == 1){
        reverse(S.begin(), S.end());
        if (cnt_front(S) % 2 == 1)
            b = 1;
    }    
    cout << ans * k - b << endl;
}


Measured memory_bytes: 256
import std.stdio,std.string,std.conv;

double isCross(double p1_x,double p1_y,double p2_x,double p2_y,double p3_x,double p3_y,double p4_x,double p4_y)
{  
	return ( (p1_x-p2_x)*(p3_y-p1_y) + (p1_y-p2_y)*(p1_x-p3_x)) * ((p1_x-p2_x)*(p4_y-p1_y) + (p1_y-p2_y)*(p1_x-p4_x));  
}

int main()
{
	string s;
	while((s = readln.chomp).length != 0)
	{
		string[] _s = s.split(",");
		double a[8];
		foreach(i;0..8)
		{
			a[i] = _s[i].to!double;
		}

		if(isCross(a[0],a[1],a[4],a[5],a[2],a[3],a[6],a[7]) > 0.0 || isCross(a[2],a[3],a[6],a[7],a[0],a[1],a[4],a[5]) > 0.0)
		{
			writeln("NO");
		}
		else
		{
			writeln("YES");
		}
	}
	return 0;
}

Measured memory_bytes: 1080
#include <bits/stdc++.h>
using namespace std;
int main(){
   int n,x=0,g=0;
   string s;
   cin >> n >> s;
   for(int i=0;i<n;i++){
       if(s[i]=='I'){
           x++;
       }
       else if(s[i]=='D'){
           x--;
       }
       if(g<=x){
           g=x;
       }
   }
   cout << g << endl;
   
    return 0;
    
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
class node
{
public:
	int key;
	node *p;
	node *l;
	node *r;
};

node *NIL,*root;

void insert(int v)
{
	node *y=NIL,*x=root,*z=new node;
	z->key=v;z->l=z->r=NIL;
	while(x!=NIL)
	{
		y=x;
		if(z->key<x->key)x=x->l;
		else x=x->r;
	}
	z->p=y;
	if(y==NIL)root=z;
	else if(z->key<y->key)y->l=z;
	else y->r=z;
	return;
}

node* find(int k)
{
	node *x=root;
	while(x!=NIL&&k!=x->key)
	{
		if(k<x->key)x=x->l;
		else x=x->r;
	}
	return x;
}

node* next(node *z)
{
	node *x,*y;
	if(z->r!=NIL)
	{
		x=z->r;
		while(x->l!=NIL)x=x->l;
		return x;
	}
	
	y=z->p;
	while(y!=NIL&&x==y->r)
	{
		x=y;
		y=y->p;
	}
	return y;
}

void del(node *z)
{
	node *y,*x;
	if(z->l==NIL||z->r==NIL)y=z;
	else y=next(z);
	
	if(y->l!=NIL)x=y->l;
	else x=y->r;
	
	if(x!=NIL)x->p=y->p;
	
	if(y->p==NIL)root=x;
	else if(y==y->p->l)y->p->l=x;
	else y->p->r=x;
	
	if(y!=z)z->key=y->key;
	delete(y);
	return;
}

void ino(node *u)
{
	if(u==NIL)return;
	ino(u->l);
	cout<<" "<<u->key;
	ino(u->r);
	return;
}

void preo(node *u)
{
	if(u==NIL)return;
	cout<<" "<<u->key;
	preo(u->l);
	preo(u->r);
	return;
}

void print()
{
	ino(root);
	cout<<endl;
	preo(root);
	cout<<endl;
	return;
}

int main() {
	int n;cin>>n;
	string s;node *a;
	while(cin>>s)
	{
		if(s=="insert")
		{
			cin>>n;
			insert(n);
		}
		else if(s=="find")
		{
			cin>>n;
			a=find(n);
			if(a!=NIL)cout<<"yes"<<endl;
			else cout<<"no"<<endl;
		}
		else if(s=="delete")
		{
			cin>>n;
			del(find(n));
		}
		else if(s=="print")print();
	}
	return 0;
}

Measured memory_bytes: 21912
use proconio::input;

fn main() {
    input! {
        n: usize,
        mut d: [u64; n + 1],
    }
    let depth = n + 1;

    let mut lim = vec![0 as u64; n + 1];
    for i in (1..depth).rev() {
        lim[i - 1] = lim[i] + d[i];
    }

    let r = match calc(depth, &d, &lim) {
        Ok(r) => r.to_string(),
        Err(r) => r.to_string(),
    };
    println!("{}", r);
}

fn calc(depth: usize, d: &Vec<u64>, lim: &Vec<u64>) -> Result<u64, i32> {
    let mut node = 1;
    let mut r = 1;
    for i in 0..depth {
        if d[i] > node {
            return Err(-1);
        }

        node = std::cmp::min((node - d[i]) * 2, lim[i]);
        r += node;
    }
    Ok(r)
}

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

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

    vector<int> B(M);
    for(int i=0; i<M; i++){
        cin>>B[i];
    }

    vector<vector<int>> A(N,vector<int>(M));
    for(int i=0; i<N; i++){
        for(int j=0; j<M; j++){
            cin>>A[i][j];
        }
    }

    int ans = 0;
    for(int i=0; i<N; i++){
        int sum = 0;
        for(int j=0; j<M; j++){
            sum += A[i][j]*B[j];
        }
        if(sum + C > 0){
            ans++;
        }
    }    

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

Measured memory_bytes: 3600
n,m = map(int, input().split())
b1 = []
b2 = []
for i in range(m):
    a,b = map(int, input().split())
    if a == 1:
        b1.append(b)
    if b == n:
        b2.append(a)
if len(b1) + len(b2) == len(list(set(b1+b2))):
    print('IMPOSSIBLE')
else:
    print('POSSIBLE')

Measured memory_bytes: 30740
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <numeric>
#include <functional>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <memory>
#include <thread>
#include <tuple>
#include <limits>
#include <iostream> 

using namespace std;

int dp[100001][26];

int main() {
  ios_base::sync_with_stdio(false);
  string s, t;
  cin >> s >> t;
  long long n = s.length(), m = t.length();
  for (int j = 0; j < 26; j++) { dp[n][j] = -1; }
  for (int i = n - 1; i >= 0; i--) {
    memcpy(dp[i], dp[i + 1], sizeof(dp[i]));
    dp[i][s[i] - 'a'] = i;
  }
  long long ans = 0;
  int sind = 0;
  for (int i = 0; i < m; i++) {
    int c = t[i] - 'a';
    if (dp[sind][c] != -1) {
      int jump = dp[sind][c] + 1 - sind;
      sind += jump;
      ans += jump;
    } else if (dp[0][c] != -1) {
      int jump = (n - sind) + dp[0][c] + 1;
      sind = dp[0][c] + 1;
      ans += jump;
    } else {
      printf("-1\n");
      return 0;
    }
  }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 10832
#include <stdio.h>
int main(void)
{
int n, no, a, i, j;
char m;
int x[4][13] ={{0}};

scanf("%d",&n);

while(n > 0){
scanf(" %c",&m);
scanf("%d",&no);

if(m == 'S')
   a = 0;
if(m == 'H')
   a = 1;
if(m == 'C')
   a = 2;
if(m == 'D')
   a = 3;

x[a][no - 1] = 1;
n--;
}

for(i = 0; i < 4; i++){
   for(j = 0; j < 13; j++){
if(x[i][j] == 0){

if(i == 0)
m = 'S';
if(i == 1)
m = 'H';
if(i == 2)
m = 'C';
if(i == 3)
m = 'D';

printf("%c %d\n",m,j + 1);
}
}
}

return 0;
}

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

int main(){
  int a, b;
  scanf("%d %d", &a, &b);
  int count = 0;
  for (int i = a; i <= b; i++){
    int l, m, n, o, p;
    p = i % 10;
    o = (i % 100) / 10;
    n = (i % 1000) / 100;
    m = (i % 10000) / 1000;
    l = i / 10000;
    if (l == p && m == o) count++;
  }
  printf("%d\n", count);
}

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

int main()
{
  int n, m;
  cin >> n >> m;
  vector<vector<int>> s(m, vector<int>(n, 0));
  vector<int> p(m);
  for (int i = 0; i < m; i++)
  {
    int k;
    cin >> k;
    for (int j = 0; j < k; j++)
    {
      int connect;
      cin >> connect;
      connect--;
      s[i][connect]++;
    }
  }
  for (int i = 0; i < m; i++)
  {
    cin >> p[i];
  }
  int ans = 0;
  for (int bit = 0; bit < (1 << n); bit++)
  {
    vector<int> sw(n, 0);
    for (int i = 0; i < n; i++)
    {
      if (bit & (1 << i))
      {
        sw[i]++;
      }
    }
    bool ok = true;
    for (int i = 0; i < m; i++)
    {
      int cnt = 0;
      for (int j = 0; j < n; j++)
      {
        if (s[i][j] + sw[j] == 2)
        {
          cnt++;
        }
      }
      if (cnt % 2 != p[i])
      {
        ok = false;
      }
    }
    if (ok)
    {
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3580
n = int(input())
a = list(map(int, input().split()))

ans = 217937901270479417
_sum = sum(a)
sum_1 = 0
for i in range(0,len(a)):
    sum_1 += a[i]
    sum_2 = _sum - sum_1
    ans = min(ans, abs(sum_1 - sum_2))
print(ans)


Measured memory_bytes: 26892
#include <iostream>
#include <sstream>
#include <cstdio>
#include <stdlib.h>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
#define max 2001
#define INF 200000000
int color[max],p[max],n;
int m[max][max],d[max];
void prim(){
  int mincost,u,i;
  p[0]=-1;
  for(i=1;i<n;i++)d[i]=INF;
  while(1){
    mincost = INF;
    for(i=0;i<n;i++){
      if(color[i]!=1&&d[i]<mincost){
	mincost=d[i];
	u=i;
      }
    }
    if(mincost==INF)break;
    color[u]=1;
    for(int j=0;j<n;j++){
      if(color[j]!=1&&m[u][j]!=-1)
	if(m[u][j]<d[j]){
	  d[j]=m[u][j];
	  p[j]=u;
	  color[j]=-1;
	}
    }
  }
}
int main(){
  int sum=0;
  cin>>n;
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)
      cin>>m[i][j];
  prim();
  for(int i=0;i<n;i++)
    sum+=d[i];

  cout<<sum<<endl;
  return 0;
}



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

int n,m,q;
vector<int> a,b,c,d;
int ans;

void dfs(vector<int> A){
  if(A.size() == n + 1){
    int now = 0;
    for(int i=0; i<q; ++i){
      if(A[b[i]] - A[a[i]] == c[i]){now += d[i];}
    }
    ans = max(ans, now);
    return;
  }
  A.push_back(A.back());
  while(A.back() <= m){
    dfs(A);
    A.back()++;
  }
}

int main(){
  cin >> n >> m >> q;
  a = b = c = d = vector<int>(q);
  for(int i=0; i<q; ++i){
    cin >> a[i] >> b[i] >> c[i] >> d[i];
  }
  dfs(vector<int>(1,1));
  cout << ans << endl;
}


Measured memory_bytes: 3604
export class Main {
  main(input: string) {
    const tmp: string[] = input.split("\n");
    const s: string = tmp.shift();

    switch (s) {
      case 'SUN':
        return 7;
      case 'MON':
        return 6;
      case 'TUE':
        return 5;
      case 'WED':
        return 4;
      case 'THU':
        return 3;
      case 'FRI':
        return 2;
      case 'SAT':
        return 1;
    }
  }
}

console.log(new Main().main(require("fs").readFileSync("/dev/stdin", "utf8")));

Measured memory_bytes: 7820
#include<stdio.h>

static const int MAX = 500;
static const int INFTY = (1<<21);

main(){
    int n, i, j, e, sum = 0;
    int M[MAX][MAX];
    int d[MAX];         // 最小コスト
    int p[MAX], v[MAX];
    int x[MAX];         // visited-boolean
    int min = INFTY, k, u;

    scanf("%d", &n);

    for ( i = 0; i< n; i++ ){
        for ( j = 0; j < n; j++ ){
            scanf("%d", &e);
            M[i][j] = (e==-1)?INFTY:e;
        }
    }

    // 初期化
    for (i = 0; i < n; i++) {
        d[i] = INFTY;
        x[i] = 0;
        p[i] = -1;
    }
    d[0] = 0;   // aからaの距離は0

    while(1) {
        u = -1;
        min = INFTY;

        // d[u]が最小になるuを求める
        for(i = 0; i < n; i++){
            if(d[i] < min && x[i] == 0) {       // 最小コスト && 未訪
                u = i;      // 最小コストx[i]保存
                min = d[i];     //最小コスト保存
            }
        }
        if(u == -1) break;      //all訪問
        x[u] = 1;       // 訪問済

        for(i = 0; i < n; i++){
            if(d[i] >= M[u][i] && x[i] == 0){
                d[i] = M[u][i];
                p[i] = u;   // 最短経路v保持
            }
        }
    }

    for(i = 0; i < n; i++){
        if(p[i] != -1)
            sum += M[i][p[i]];
    }
    printf("%d\n", sum);
    return 0;
}

Measured memory_bytes: 804
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1000000010
#define EPS 1e-9
#define F first
#define S second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"

typedef pair<int,int> PII;
typedef pair<int,string> PIS;
typedef pair<string,int> PSI;


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int s,w;
  cin>>s>>w;
  if(s>w) cout<<"safe"<<endl;
  else cout<<"unsafe"<<endl;

  return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<algorithm>
#include<functional>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<tuple>
#include<stack>
#include<queue>
#include<deque>
#include<sstream>
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<bitset>
#include<time.h>
#include<cstdlib>
#include<cassert>
#define ll long long
#define fi first
#define se second
using namespace std;

int a,b,c;
                   
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout<<fixed;
#ifdef LOCAL_DEFINE
    freopen("in", "r", stdin); 
    freopen("out","w",stdout);
#endif
  cin>>a>>b>>c;
  if(abs(b-a)>abs(c-a))cout<<"B"<<endl;
  else cout<<"A"<<endl;
#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}

Measured memory_bytes: 256
A = int(input())

B = input()
w = B.split(' ')

C = input()
x = C.split(' ')

q1 = 0
q2 = 0

for p1, p2 in zip(w, x):
    if int(p1) > int(p2):
        q1 += int(p1)
        q2 += int(p2)
    
print(q1 - q2)


Measured memory_bytes: 3060
# -*- coding: utf-8 -*-
"""
A - Dodecagon
https://atcoder.jp/contests/abc134/tasks/abc134_a

"""
import sys


def solve(r):
    return 3 * r**2


def main(args):
    r = int(input())
    ans = solve(r)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 2940
#include <stdio.h>

int main()
{
  int n, S[100000], q, T[50000], left, right, mid, i, count = 0;

  scanf("%d",&n);
  for (i = 0; i < n; i++)
    scanf("%d",&S[i]);
  scanf("%d",&q);
  for (i = 0; i < q; i++){
    scanf("%d",&T[i]);
    left = 0;
    right = n;
    while (left < right){
      mid = (left+right)/2;
      if (S[mid] == T[i]){
	count++;
	break;
      }
      else if (T[i] < S[mid])
	right = mid;
      else
	left = mid + 1;
    }
  }
  printf("%d\n",count);
    
  return 0;
}



Measured memory_bytes: 2288
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <vector>

#define REP(i,n) for(int i=0;i<(int)n;i++)
#define REP1(j,n) for(int j=0;j<(int)n;j++)
#define REPD(i,n) for(int i=n;i>=0;i--)
#define REPD1(j,n) for(int j=n;j=>0;j--)
#define REPS(i,n) for(int i=1;i<=(int)n;i++)
#define REPS1(j,n) for(int j=1;j<=(int)n;j++)
#define rep(i,a,n) for(int i=a;i<=(int)n;i++)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;

int main(void) {
	int a;
	cin >> a;
	cout << 24 + (24 - a) << endl;
	return 0;
}



Measured memory_bytes: 256
program sample
    implicit none  !二分探索
    integer(8) ::c,i,j,m(12),n,k,a1,b1,c1
    character::a(2)
    character(len=1),allocatable::s(:)
    character(len=1)::t(1:26)
    t=(/'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'/)
    read(*,*) n

    do i=1,12
        m(i)=0
    end do
    j=0
    do while (n>0)
        j=j+1
        m(j)=mod(n,26)
        if (m(j)==0)then
            m(j)=26
            n=n/26-1
        else
            n=n/26
        end if
        
    end do
    allocate(s(j))
    do i=1,j
        s(j+1-i)=t(m(i))
    end do
    write(*,'(a,a,a,a,a,a,a,a,a,a,a,a,a)')s
    

    deallocate(s)
    stop

end program sample
  



Measured memory_bytes: 2948
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);

		String yohou  = scanner.nextLine();
		String zissai = scanner.nextLine();

		int count = 0;

		scanner.close();

		for(int i=0; i<3; i++) {

			if(yohou.charAt(i) == zissai.charAt(i)){

				count++;

			}else {

				continue;

			}

		}

		System.out.println(count);

	}

}

Measured memory_bytes: 21972
import sys
from bisect import bisect_right

def solve():
    def getINearests(ss, ts):
        iNearests = [-1] * len(ss)
        for iS, s in enumerate(ss):
            iT = bisect_right(ts, s)
            if iT == len(ts):
                iNearests[iS] = iT-1
            elif iT == 0:
                iNearests[iS] = 0
            else:
                d1 = abs(s - ts[iT-1])
                d2 = abs(s - ts[iT])
                if d1 <= d2:
                    iNearests[iS] = iT-1
                else:
                    iNearests[iS] = iT
        return iNearests


    A, B, Q = map(int, input().split())
    ss = [int(sys.stdin.readline()) for _ in range(A)]
    ts = [int(sys.stdin.readline()) for _ in range(B)]
    xs = [int(sys.stdin.readline()) for _ in range(Q)]

    iTNearests = getINearests(ss, ts)
    iSNearests = getINearests(ts, ss)

    anss = [0] * Q
    for iX, x in enumerate(xs):
        ans = float('inf')

        # 初手: 神社
        iS = bisect_right(ss, x)
        if iS > 0:
            cost = abs(x - ss[iS-1])
            cost += abs(ss[iS-1] - ts[iTNearests[iS-1]])
            if cost < ans: ans = cost
        if iS < A:
            cost = abs(x - ss[iS])
            cost += abs(ss[iS] - ts[iTNearests[iS]])
            if cost < ans: ans = cost

        # 初手: 寺
        iT = bisect_right(ts, x)
        if iT > 0:
            cost = abs(x - ts[iT-1])
            cost += abs(ts[iT-1] - ss[iSNearests[iT-1]])
            if cost < ans: ans = cost
        if iT < B:
            cost = abs(x - ts[iT])
            cost += abs(ts[iT] - ss[iSNearests[iT]])
            if cost < ans: ans = cost

        anss[iX] = ans

    print('\n'.join(map(str, anss)))

solve()


Measured memory_bytes: 34972
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;

typedef pair<long long int, long long int> P;
long long int INF = 1e18;
#define MAX_V 200

long long int cost[MAX_V][MAX_V]; // cost[u][v] は頂点uからvへのコスト
long long int mincost[MAX_V];
bool used[MAX_V];
int V;// Vは頂点数

// 最小全域木であり、O(V^2)

// 最初にすべての頂点に対するcostを計算しておくこと

long long int prim(){
	
	for(int i = 0; i < V; i++){
		mincost[i] = INF;
		used[i] = false;
	}
	
	mincost[0] = 0;
	
	long long int total = 0;
	
	while(true){
		
		int add_v = -1;
		
		for(int u = 0; u < V; u++){
			if(!used[u] && (add_v == -1 || mincost[u] < mincost[add_v])){
				add_v = u;
			}
		} // 追加する頂点を決定
		
		if(add_v == -1){
			break;
		} // 更新する頂点がない場合、終了
		used[add_v] = true;
		total += mincost[add_v];
		
		for(int u = 0; u < V; u++){
			mincost[u] = min(mincost[u], cost[add_v][u]);
		} // 集合の外の頂点への最小コストを更新
	}
	return total;
}

int main(){
	
	long long int ans;
	
	cin >> V;
	
	for(int i = 0; i < V; i++){
		for(int j = 0; j < V; j++){
			cin >> cost[i][j];
			if(cost[i][j] == -1){
				cost[i][j] = INF;
			}
		}
	}
	
	ans = prim();
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 3176
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cassert>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;


typedef long long i64;
const int inf = (int)1.05e9;

pair<int,int> comp(vector<vector<pair<int,int>>>& imos, int sx, int sy, int tx, int ty)
{
	auto v = imos[tx][ty];

	v.first -= imos[sx][ty].first;
	v.first -= imos[tx][sy].first;
	v.first += imos[sx][sy].first;
	v.second -= imos[sx][ty].second;
	v.second -= imos[tx][sy].second;
	v.second += imos[sx][sy].second;

	return v;
}

int main()
{
	int n, k;
	vector<pair<bool,pair<int,int>>> ps;

	scanf("%d%d", &n, &k);
	ps.resize(n);

	int w_sum = 0;

	for(int i = 0; i < n; ++i) {

		int x, y;
		char buf[10];

		scanf("%d%d%s", &x, &y, buf);

		bool b = (buf[0] == 'B');
		int px = x / k, qx = x % k;
		int py = y / k, qy = y % k;

		b = b ^ ((px + py) % 2);
		x = qx;
		y = qy;

		ps[i] = {b, {x, y}};
		if(!b)
			w_sum += 1;
	}

	vector<vector<pair<int,int>>> imos;

	imos.resize(k + 1);
	for(auto& v : imos) v.resize(k + 1);

	for(int i = 0; i < n; ++i) {
		bool b = ps[i].first;
		int x = ps[i].second.first;
		int y = ps[i].second.second;
		if(!b)
			imos[x + 1][y + 1].first += 1;
		else
			imos[x + 1][y + 1].second += 1;
	}

	for(int i = 0; i < k + 1; ++i) {
		for(int j = 0; j < k; ++j) {
			imos[i][j + 1].first += imos[i][j].first;
			imos[i][j + 1].second += imos[i][j].second;
		}
	}
	for(int i = 0; i < k + 1; ++i) {
		for(int j = 0; j < k; ++j) {
			imos[j + 1][i].first += imos[j][i].first;
			imos[j + 1][i].second += imos[j][i].second;
		}
	}

	int ans = 0;

	for(int sx = 0; sx < k; ++sx) {
		for(int sy = 0; sy < k; ++sy) {

			auto ur = comp(imos, sx, sy, k, k);
			auto dl = comp(imos, 0, 0, sx, sy);

			int ws = ur.first + dl.first;
			int bs = ur.second + dl.second;

			int a1 = bs + (w_sum - ws);
			int a2 = n - a1;

			ans = max(ans, max(a1, a2));
		}
	}

	printf("%d\n", ans);

	return 0;
}

/* waffle */


Measured memory_bytes: 9216
import sys
import itertools
# import numpy as np
import time
import math
import heapq
from collections import defaultdict
from collections import Counter
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())

N = int(input())
A = Counter(list(map(int, input().split())))
ans = 0
for k, v in A.items():
    if k < v:
        ans += v - k
    elif k > v:
        ans += v
print(ans)



Measured memory_bytes: 22352
def main():
  N = int(input())
  flag = False
  for i in range(1, 3501):
    for j in range(1, 3501):
      if 4*i*j-N*i-N*j > 0 and N*i*j % (4*i*j-N*i-N*j) == 0:
        print(i, j, int(N*i*j/(4*i*j-N*i-N*j)))
        flag = True
        break
    if flag:
      break
        
if __name__ == "__main__":
  main()
  

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

int main(){
    int N,X,wa=0;
    cin >> N >> X;
    vector<int> m(N);

    for(int i = 0;i < N;i++){
        cin >> m.at(i);
    }

    for(int i = 0;i < N;i++){
        X -= m.at(i);
        wa++;
    }

    sort(m.begin(),m.end());

    while(X - m.at(0) >= 0){
        X -= m.at(0);
        wa++;
    }

    cout << wa << endl;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
	val (n, l) = readLine()!!.split(' ').map { it.toInt() }
	val s = mutableListOf<String>()

	for (i in 0 until n){
		s.add(readLine()!!)
	}
	s.sort()
	println(s.joinToString(""))
}


Measured memory_bytes: 37916
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>
#include <cstdlib>
#include <string>

using namespace std;

int int_max = numeric_limits<int>::max();

void c(){

    int N; cin >> N;
    string S; cin >> S;

    vector<int> bw = {1};//初期化はあと
    int bwIdx = 0;

    for(int i = 1; i < N; i++){
        if (S[i - 1] != S[i]) {
            bw.push_back(1);
            bwIdx++;
        }else{
            bw[bwIdx]++;
        }
    }

    if(bw.size() == 1){
        cout << 0;
        return;
    }
    int firstBlack =  (S[0] == '#')?0:1;
    int wToB = 0;
    for (int j = firstBlack + 1; j < bw.size(); j += 2){
        wToB += bw[j];
    }


    int minChange = wToB ;
    int change = minChange;

    for(int i = firstBlack;  i < bw.size(); i += 2){
        if (i == bw.size() -1){
            change = change + bw[i];
        }else {
            change = change + bw[i] - bw[i + 1];
        }
        minChange = min(change, minChange);
    }

    int toAll = 0;
    for(int i = 0; i <  bw.size(); i += 2){
        toAll += bw[i];
    }
    minChange = min(toAll, minChange);
    toAll = 0;
    for(int i = 1; i < bw.size(); i += 2){
        toAll += bw[i];
    }
    minChange = min(toAll, minChange);

    cout << minChange;


}

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

Measured memory_bytes: 1532
#include "bits/stdc++.h"
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(s) s.begin(), s.end()
using namespace std;
typedef long long int ll;
// typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
// typedef vector<P> vp;
typedef vector<string> vs;
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;
const int DIV = 1e9+7;

int n;
vs s;

int main()
{
    cin >> n;
    s.resize(n); rep(i, n) cin >> s[i];

    rep(i, n){ if(s[i] == "Y"){ puts("Four"); return 0; } }
    puts("Three");
  
    return 0;
}

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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

long long modpow(long long a, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    (a *= a) %= mod;
    n >>= 1;
  }
  return res;
}

const int maxf = 10000000;
long long fact[maxf+5];

void fact_init(int n, long long mod){
  fact[0] = 1;
  for(int i=1; i<=n; i++){
    fact[i] = (fact[i-1] * i) % mod;
  }
}

long long comb(long long a, long long b, long long mod){
  if(a<b || a<0 || b<0) return 0;
  if(fact[0] == 0) fact_init(maxf, mod);
  return (fact[a] * modpow((fact[a-b]*fact[b])%mod, mod-2, mod)) % mod;
}

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n; cin>>n;
  vll a(n);
  vll s(n+1);
  rep(i,n){
    cin>>a[i];
    s[i+1]=s[i]+a[i];
  }
  map<ll,ll> m;
  rep(i,n+1){
    m[s[i]]++;
  }
  ll ans=0;
  for(auto e: m){
    ans+=(e.second*(e.second-1))/2;
  }
  cout<<ans<<endl;
}

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

int main()
{
    int n, d;
    cin >> n >> d;
    int ans = 0;
    if(n % (2*d+1) != 0){
        ans = n/(2*d+1) + 1;
    }
    else{
        ans = n/(2*d+1);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256