akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;
using vll = vector<long long>;
using vpii = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvs = vector<vector<string>>;
using vvb = vector<vector<bool>>;
using vvll = vector<vector<long long>>;
using pii = pair<int, 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 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 FOR(i,a,b) for(int i = (int)(a); i <= (int)(b); i++)
#define RFOR(i,a,b) for(int i = (int)(a); i >= (int)(b); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define call(x) (x).cbegin(), (x).cend()
#define MAX(x) *max_element(all(x))
#define MIN(x) *min_element(all(x))
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 (b<a) {a=b; return 1;} return 0;}
const int INF = INT_MAX;
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};


void solve(int N, vd &p){
    vector<vector<long double>> dp(4000, vector<long double>(4000, 0));
    // dp[i+1][j] は 0indexed i枚目までで表がj枚出る確率
    dp[0][0] = 1;
    rep(i, N+1) rep(j, N+1) {
        dp[i+1][j+1] += dp[i][j] * p[i];
        dp[i+1][j] += dp[i][j] * (1-p[i]);
    }
    long double ans = 0;
    FOR(i, (N+1)/2, N) {
        ans += dp[N][i];
    }
    cout << fixed << setprecision(10);
    cout << ans << endl;
}

int main(){
    int N;
    cin >> N;
    vd p(N);
    for(int i = 0 ; i < N ; i++){
        cin >> p[i];
    }
    solve(N, p);
    return 0;
}


Measured memory_bytes: 250496
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;

int main(){
	int N,K;
	cin>>N>>K;
	int x[100];
	rep(i,N)cin>>x[i];
	
	int res=0;
	rep(i,N) res+= 2*min(x[i],K-x[i]);
	
	cout<<res;
}

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

int main(){
	int n;
	while(cin>>n){
		if(n==0)break;
		ll a[n];
		for(int i=0;i<n;i++)cin>>a[i];
		int ans = 1e9;
		int t[n];
		sort(a,a+n);
		for(int i=0;i<n;i++){
			t[i]=1e9;
		}
		for(int i=0;i<n-1;i++){
			t[i] = abs(a[i]-a[i+1]);
		}
		sort(t,t+n);
		ans=t[0];
		cout<<ans<<endl;
	}
}


Measured memory_bytes: 3076
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define PI acos(-1)
#define vi vector<int>
#define pi pair<int, int>
#define pl pair<ll, ll>
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
const int MOD = 1e9+ 7;
const int INF = numeric_limits<int>::max() - (int)1e8;
const ll INFLL = numeric_limits<ll>::max() - (ll)1e17;

int main() {
    int N, M;
    cin >> N >> M;
    int left = 1, right = M + 1;
    while (left < right) {
        cout << left << " " << right << endl;
        left++;
        right--;
    }
    left = M + 2, right =  M + M + 1;
    while (left < right) {
        cout << left << " " << right << endl;
        left++;
        right--;
    }
}

Measured memory_bytes: 3648
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>

int main() {

    int n, v, c;
    scanf("%d", &n);

    int arr01[n];
    int arr02[n];

    int mysum = 0;

    for (int i = 0; i < n; i++) {
        scanf("%d", &v);
        arr01[i] = v;

    }
    for (int j = 0; j < n; j++) {
        scanf("%d", &c);
        arr02[j] = c;
    }
    for (int k = 0; k < n; k++) {

        if (arr01[k] - arr02[k] > 0) {
            mysum += arr01[k] - arr02[k];
        }

    }

    printf("%d", mysum);


    return 0;

} 

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
using namespace std;

#ifdef DEBUG
    #define IFD if(true)
#else
    #define IFD if(false)
#endif

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

    vector<int> A(N);
    vector<int> B(N);
    rep(i, N) {
        cin >> A[i];
        B[i] = A[i];
    }
    sort(B.begin(), B.end(), greater<int>());

    rep(i, N) {
        cout << (A[i] == B[0] ? B[1] : B[0]) << endl;
    }

    return 0;
}


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

typedef long long ll;

int main() {
    int n;
    cin>>n;
    ll a[n];
    for (int i = 0; i<n; i++)
        cin>>a[i];
    
    ll sum = 0;
    ll ans = 0;

    for ( int i =0; i<n; i++ )
        sum = (sum+a[i])%1000000007;

    for ( int i=0; i<n-1; i++ )
        {
            sum -=a[i];
            if ( sum<0 )
                sum += 1000000007;
            ans = ( ans + a[i]*sum)%1000000007;
        }

    cout<<ans;
}

Measured memory_bytes: 5092
use std::io;
use std::cmp;

// read a line(without line feed)
fn read_line() -> String {
    let mut in_str = String::new();
    io::stdin().read_line(&mut in_str).unwrap();
    return in_str.trim().to_string();
}

// read wods on a line
pub fn read_words_in_line() -> Vec<String> {
    let s = read_line();
    return s.split_whitespace().map(|x| x.to_string()).collect::<Vec<String>>()
}

// read type t on a line
pub fn read_t_in_line<T : std::str::FromStr>() -> Vec<T> {
    let mut v : Vec<T> = Vec::new();
    for e in read_words_in_line().iter().map(|x| x.parse::<T>()) {
        if let Ok(r) = e {
            v.push(r);
        }
        else{
            return Vec::new();
        }
    }
    return v;
}

// sort slice
pub fn sort<T : std::cmp::Ord>(slice : &mut [T]) {
    slice.sort();
}
// sort slice by reverse order
pub fn sort_rev<T : std::cmp::Ord>(slice : &mut [T]) {
    slice.sort_by(|x, y| y.cmp(x));
}

pub fn min<T : std::cmp::Ord>(a : T, b : T) -> T{
    return cmp::min(a, b);
}

pub fn max<T : std::cmp::Ord>(a : T, b : T) -> T{
    return cmp::max(a, b);
}


fn main() {

    let h_w = read_t_in_line::<usize>();
    let (h, w) = (h_w[0], h_w[1]);
    let mut field = vec![];

    for _ in 0..h {
        let s = read_line();
        field.push(s.into_bytes());
    }
    
    for y in 0..h {
        for x in 0..w {
            if field[y][x] == '.' as u8 {
                let mut cnt = 0;
                for dy in -1..2 {
                    for dx in -1..2 {
                        let ny = y as i32 + dy;
                        let nx = x as i32 + dx;
                        if ny >= 0 && ny < h as i32 && nx >= 0 && nx < w as i32 && field[ny as usize][nx as usize] == '#' as u8 {
                            cnt += 1;
                        }
                    }
                }
                print!("{}", cnt);
            }
            else {
                print!("{}", '#');
            }
        }
        println!("");
    }
    

}


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

int main(){

    string A;
    string B;

    int count=0;
    cin >> A;
    cin >> B;

    // 桁数で比較
    if(A.size() > B.size()){
        cout << "GREATER" << endl;
    }

    if(A.size() < B.size()){
        cout << "LESS" << endl;
    }
    if(A.size() == B.size()){
        for(int i=0; i<A.size(); i++){
            if(A[i] > B[i]){
                cout << "GREATER" << endl;
                break;
            }
            if(A[i] < B[i]){
                cout << "LESS" << endl;
                break;
            }
            if(A[i] == B[i]){
                count++;
            }
        }
        if(count == A.size()){
                cout << "EQUAL" << endl;
        }
    }
    return 0;
}




Measured memory_bytes: 256
H,W=map(int,input().split())
N=int(input())
a=list(map(int,input().split()))

b=[]
for i in range(N):
  b+=[i+1]*a[i]
ans=[0]*H
for i in range(H):
  if i%2==0:
    print(" ".join(map(str,b[i*W:(i+1)*W])))
  else:
    print(" ".join(map(str,b[(i+1)*W-1:(i)*W-1:-1])))

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

using namespace std;

typedef long long int li;
typedef long double ld;
typedef vector<li> vi;
typedef pair<li,li> pi;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define B begin()
#define E end()
#define f(i,l,r) for(li i=l;i<=r;++i)
#define fr(i,l,r) for(li i=l;i>=r;--i)
#define u_map unordered_map
#define endl "\n"
#define debug(x) cerr<<#x<<" = "<<x<<endl

li fastpow(li base,li exp,li M) 
{
    li res=1;
    while(exp>0) {
        if(exp&1)
            res=(res*base)%M;

        base=(base*base)%M;
        exp>>=1;
    }
    return res;
}

void solve()
{
    li n;

    cin>>n;

    li ans=0;

    f(i,1,n)
    {
        ans+=(n-1)/i;
    }

    cout<<ans;
}

int main()
{    
    //remove this in kickstart

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    li t=1;

    // cin>>t;

    f(i,1,t)
    {
        // cout<<"Case #"<<i<<": ";

        solve();
    }

    return 0;
}

Measured memory_bytes: 3652
#include <stdio.h>

#define NUM_DATA 5

int cul_time(int time)
{
	if (time % 10 == 0)
		return time;
	else
		return (time / 10 + 1) * 10;
}

int main()
{
	int data[NUM_DATA], minpos, result, i;

    for (i = 0; i < NUM_DATA; i++)
		scanf("%d", data + i);

	for (i = 1, minpos = 0; i < NUM_DATA; i++) {
		if ((data[i] - 1) % 10 < (data[minpos] - 1) % 10)
			minpos = i;
	}

	for (i = 0, result = 0; i < NUM_DATA; i++) {
		if (i != minpos)
			result += cul_time(data[i]);
		else
			result += data[i];
	}

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

	return 0;
}
	


Measured memory_bytes: 128
/*
		Author : Kaustubh Gangwar
		||S||A||M||R||A||T||
*/
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ld long double
#define pb push_back
#define gcd __gcd
#define mp make_pair
#define vii vector<int>
#define vll vector<long long>
#define all(x) x.begin(),x.end()
#define f(i,a,b) for(int i=a;i<b;i++)
#define fe(i,a,b) for(int i=a;i<=b;i++)
typedef long long  ll;
typedef pair<int,int> pii;

ll bpow(ll a, ll b) {
	a=a;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}
int cd(int n) 
{ 
    int cnt = 0; 
    for (int i = 1; i <= sqrt(n); i++) { 
        if (n % i == 0) { 
            // If divisors are equal, 
            // count only one 
            if (n / i == i) 
                cnt++; 
  
            else // Otherwise count both 
                cnt = cnt + 2; 
        } 
    } 
    return cnt; 
} 

int main()
{	ios_base::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);
	
	ld n; cin>>n;
	ld ans=0;
	
	for(ld i=1;i<=n;i++)
	{
	ans+=(ld)(i/2)*(ld)floor(n/i)*(ld)floor(1 + n/i);
	}
	cout<<(ll)ans<<"\n";
	
	
return 0;
}


Measured memory_bytes: 3796
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include <stdio.h>
#include <ctype.h>
#include <string>
#include <iostream>
#include <vector>
#include <stack>
#include <fstream>
#include <sstream>
#include <queue>
#include <exception>
#include <cmath>
#include <numeric>
#include <map>
#include <algorithm>
#include <bitset>
#include <set>
#include <functional>

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

using namespace std;
typedef long long int lint;
typedef vector<vector<char> > matrix;

void print(matrix& mat) {
	REP(y, mat.size()) {
		REP(x, mat[0].size()) {
			cout << mat[y][x];
		}
		cout << endl;
	}
}

matrix mk_matrix(int n, int m) {
	matrix mat(n);
	REP(i, n) {
		mat[i] = vector<char>(m, 0);
	}
	return mat;
}

void rotate90(matrix& src) {
	matrix dst = mk_matrix(8, 8);
	REP(y, 8) {
		REP(x, 8) {
			dst[x][8 - y - 1] = src[y][x];
		}
	}
	src = dst;
}

bool AOJ0133()
{
	matrix mat = mk_matrix(8, 8);
	REP(i, 8) {
		REP(j, 8) {
			cin >> mat[i][j];
		}
	}
	cout << "90" << endl;
	rotate90(mat);
	print(mat);
	cout << "180" << endl;
	rotate90(mat);
	print(mat);
	cout << "270" << endl;
	rotate90(mat);
	print(mat);

	return true;
}

int main()
{
	AOJ0133();

	return 0;
}

Measured memory_bytes: 3104
#include<bits/stdc++.h>
 
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ldb;
 
#define pb push_back
#define popb pop_back
#define popf pop_front
#define pf push_front
#define si size()
#define mp make_pair 
#define mt make_tuple
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound

#define ask(i,m,n) for(lli i=m;i<n;i++)
#define anket ios::sync_with_stdio(0), cin.tie(0),cout.tie(0)
 
#define endl "\n"
#define o0(a) cout<<a<<" "
#define o1(a) cout<<a<<"\n"
#define o2(a,b) cout<<a<<" "<<b<<"\n"
#define o3(a,b,c) cout<<a<<" "<<b<<" "<<c<<"\n"
#define o4(a,b,c,d) cout<<a<<" "<<b<<" "<<c<<" "<<d<<"\n"
using namespace std;

#define prime1 1000000007
#define prime2 998244353

lli modadd(lli n,lli m , lli mod){
    lli sum = ((n+m)%mod+mod)%mod;
    return sum;
}

lli modsub(lli n,lli m,lli mod){
    lli diff = ((n-m+mod)%mod+mod)%mod;
    return diff;
}

lli modpro(lli n,lli m, lli mod){
    lli pro = ((n*m)%mod+mod)%mod;
    return pro;
}

lli powmod(lli x,lli y,lli mod){
    x %= mod;
    y %= mod;
    lli res = 1;
    while (y > 0) {
        if (y & 1)
            res = modpro(res , x,mod);
        y = y >> 1;
        x = modpro(x , x,mod);
    }
    return res;
}

lli moddiv(lli n,lli m,lli mod){
    //return n/m mod (mod) or n*(m)^-1 mod (mod)
    lli a = powmod(m,mod-2,mod);
    //this is because of fermats thm i.e. a^-1 = a^p-2 mod(p) check
    //multiplying p on both sides
    lli res = modpro(a,n,mod);
    return res;
}

vector<lli> prefix_function(string s) {
    lli n = (lli)s.length();
    vector<lli> pi(n);
    for (lli i = 1; i < n; i++) {
        lli j = pi[i-1];
        while (j > 0 && s[i] != s[j])
            j = pi[j-1];
        if (s[i] == s[j])
            j++;
        pi[i] = j;
    }
    return pi;
}


int main() {
	anket;
	lli n;
	cin>>n;
	lli s = n*(n+1)/2;
	lli a =0;
	a = 3*(n/3)*(n/3+1)/2 + 5*(n/5)*(n/5+1)/2 - 15*(n/15)*(n/15+1)/2;
	lli b = s-a;
	o1(b);
	return 0;
}




Measured memory_bytes: 3656
use std::io;


fn main() {
    let s = read_one::<String>().chars().collect::<Vec<_>>();
    let mut cnt = vec![0; 3];
    for c in s {
        match c {
            'a' => cnt[0] += 1,
            'b' => cnt[1] += 1,
            'c' => cnt[2] += 1,
            _ => unreachable!(),
        }
    }
    let max = cnt.iter().max().unwrap();
    let min = cnt.iter().min().unwrap();
    if max - min > 1 { println!("NO"); }
    else { println!("YES"); }
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

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

int main () {
  int H,W;
  string A;
  cin >> H >> W;
  
  for (int i = 0;i < W + 2;i ++) {
    cout << "#";
  }
  cout << endl;
  
  for (int i = 0;i < H;i ++) {
    cin >> A;
    cout << "#" << A << "#" << endl;
  }
   for (int i = 0;i < W + 2;i ++) {
    cout << "#";
  }
  cout << endl;
}
  
  


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <math.h>

typedef long long int ll;

#define FOR(i,n,m) for(ll i=(ll)(m);i<(ll)(n);++i)
#define REP(i,n) FOR(i,n,0)
#define IREP(i,n) for(ll i=(ll)(n);i>=0;--i)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;

using namespace std;

ll S(ll n)
{
	ll r = 0;
	while (n > 0)
	{
		r += n % 10;
		n /= 10;
	}
	return r;
}

int main()
{
	ll K;
	cin >> K;
	ll n = 1;
	ll add = 1;

	cout << 1 << endl;
	REP(i, K - 1)
	{
		ll t = n + add;
		ll s = S(t);
		ll nt = t;
		ll ns = s;

		ll nnt = t;

		while (true)
		{
			nnt = nnt + add;
			ll nns = S(nnt);
			if (nt*nns <= nnt*ns)
			{
				add = (nt - n);
				n += add;
				break;
			}
			nt = nnt;
			ns = nns;
			//add += add;
		}
		cout << n << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
const int maxn = 1e6+10;
int m,n;
int main()
{
	cin>>n;
	int ans=0;
	if(n%10!=0)
	{
		while(n)
		{
			ans+=n%10;
			n/=10;
		}
	}
	else 
	{
		n/=2;
		while(n)
		{
			ans+=n%10;
			n/=10;
		}
		ans*=2;
	}
	cout<<ans;
}

Measured memory_bytes: 888
#include <math.h>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <iomanip>
#include <iterator>
#include <algorithm>
#include <functional>
#include <typeinfo>
#include <utility>
#include <tuple>
#include <queue>
#include <deque>

using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define reprrev(i, a, b) for (int i = (int)(b) - 1; i >= (int)(a); i--)
#define reprev(i, n) reprrev(i, 0, n)
#define mp(a, b) make_pair(a, b)
#define all(vec) (vec).begin(), (vec).end()
#define yn(formula) (formula) ? (cout << "Yes" << endl) : (cout << "No" << endl)
#define YN(formula) (formula) ? (cout << "YES" << endl) : (cout << "NO" << endl)
#define MIN(a, b) ((a) < (b)) ? (a) : (b)
#define LLONG_MAX     9223372036854775807i64

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pii> vp;
typedef vector<pll> vpl;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vb> vvb;
typedef vector<vc> vvc;
typedef vector<vs> vvs;
typedef vector<vp> vvp;
typedef vector<vpl> vvpl;

constexpr double PI = 3.14159265358979323846;
constexpr ll INF = 1 << 29;
constexpr ll MOD = (ll)1e9 + 7;
constexpr double EPS = 1e-7;
constexpr int dy[4] = { 0, 1, 0, -1 };
constexpr int dx[4] = { 1, 0, -1, 0 };

struct edge { ll to; ll cost; };

ll Pow(ll a, ll b) {
	ll x = 1;
	while (b > 0) {
		if (b & 1) x = x * a;
		a = a * a;
		b = b >> 1;
	}
	return x;
}

/*<ここから>***********************************************************/


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

	if (A <= 8 && B <= 8) cout << "Yay!" << endl;
	else cout << ":(" << endl;


	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int min(int,int);
int max(int,int);

int main(void){
  int n,s,i,mini,maxi,sum;

  while(scanf("%d",&n),n){

    mini=100000;
    maxi=sum=0;

    for(i=0;i<n;i++){
    scanf("%d",&s);
    mini = min(mini,s);
    maxi = max(maxi,s);
    sum+=s;
    }
    printf("%d\n",(sum-mini-maxi)/(n-2));
}
  return 0;
}

int min(int x,int y){
  return x<y?x:y;
}

int max(int x,int y){
  return x>y?x:y;
}

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

int main() {
  ll a,b;
  int k;
  cin>>a>>b>>k;

  for (int i=0; i<k; i++) {
    if (i%2==0) {
      b+=a/2;
      a/=2;
    }
    else {
      a+=b/2;
      b/=2;
    }
  }
  cout<<a<<" "<<b<<endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        StringBuilder sb = new StringBuilder();
        sb.append(sc.next());
        String str1 = sb.substring(0,1);
        String str2 = sb.substring(1,2);
        String str3 = sb.substring(2,3);
        String str4 = sb.substring(3,4);
        if(str1.equals(str2)||str2.equals(str3)||str3.equals(str4)){
          System.out.println("Bad");
        }else{
          System.out.println("Good"); 
        }
    }
}


Measured memory_bytes: 22868
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
import numpy as np
def main():
    n, m, k = map(int, input().split())
    a = np.array(readline().split(), np.int64)
    b = np.array(readline().split(), np.int64)
    aa = a.cumsum()
    ba = b.cumsum()
    r = np.searchsorted(ba, k, side='right')    
    for i1, aae in enumerate(aa):
        if k < aae:
            break
        r = max(r, np.searchsorted(ba, k - aae, side='right') + i1 + 1)
    print(r)

if __name__ == '__main__':
    main()

Measured memory_bytes: 56376
import java.util.Scanner;

// 12
class Main{

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int K = sc.nextInt();
        int N = sc.nextInt();
        int[] a = new int[N + 1];
        for(int i = 0; i < N; ++i)
            a[i] = sc.nextInt();
        a[N] = a[0] + K;

        int t = 0;
        for(int i = 0; i < N; i++)
            t = Math.max(t, a[i + 1] - a[i]);

        System.out.println(K - t);
    }

}


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


int main() {
  int N;
  int K;
  int tmp;
  int count;

  cin >> N >> K;

  rep(i, N){
    cin >> tmp;
    if(tmp < (K - tmp)){
      count += 2 * tmp;
    }
    else{
      count += 2*(K - tmp);
    } 
  }
  cout << count << endl;
}


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



int main()
{
     int n,i,x=0,y=0,sum=0;
     cin>>n;
     int a[n];
     int b[n];
     for(i=0;i<n;i++)
     {
         cin>>a[i];
     }
   for(i=0;i<n;i++)
     {
         cin>>b[i];
     }
      for(i=0;i<n;i++)
     {
         if(a[i]-b[i]>0)
         {
             sum+=a[i]-b[i];
         }
     }
     cout<<sum;
}


Measured memory_bytes: 256
import sys
input = lambda: sys.stdin.readline().rstrip()
a=[]
for _ in range(int(input())):
    inp=[int(i) for i in input().split()]
    inp.reverse()
    a.append(inp)
a.sort()
t=0 ; flag=0
for i in a:
    t+=i[1]
    if t>i[0]:
        flag=1
        break
if flag==0: print('Yes')
else: print('No')
    

Measured memory_bytes: 74972
#include<bits/stdc++.h> 
using namespace std;
typedef long long int ll;
#define MOD 1000000007
#define fo(i,k,n) for(i=k;i<=n;i++)
#define endl '\n'
ll dp[101][100001];
//memoisation
ll knapsnack(ll* w,ll* v,ll n,ll mw){
	if(dp[n][mw]>-1) return dp[n][mw];
	if(n==0) return 0;//no item left
	if(mw==0) return 0;//no more capacity
	ll op1 = knapsnack(w,v,n-1,mw);
	ll op2 = LLONG_MIN;
	if(w[n-1]<=mw) op2 = v[n-1]+knapsnack(w,v,n-1,mw-w[n-1]);
	return dp[n][mw]=max(op1,op2);
}
//tabulation
ll knapsnacki(ll* w,ll* v,ll n,ll mw){
	ll i,j;
	fo(i,0,mw) dp[0][i]=0;
	fo(i,0,n) dp[i][0]=0;
	fo(i,1,n){
		fo(j,1,mw){
			dp[i][j] = dp[i-1][j];
			if(w[i-1]<=j) dp[i][j] = max(dp[i][j],v[i-1]+dp[i-1][j-w[i-1]]);
		}
	}
	return dp[n][mw];
}
//tabulation memory optimised
ll knapsnacki2(ll* w,ll* v,ll n,ll mw){
	ll i,j;
	ll dp2[2][mw+1];
	fo(i,0,mw) dp[0][i]=0;
	dp[1][0]=0;
	ll idx=1;
	fo(i,1,n){
		fo(j,1,mw){
			dp[idx][j] = dp[idx^1][j];
			if(w[i-1]<=j) dp[idx][j] = max(dp[idx][j],v[i-1]+dp[idx^1][j-w[i-1]]);
		}
		idx^=1;
	}
	return dp[idx^1][mw];
}
void solve(){
	ll i,j,n,mw;
	cin>>n>>mw;
	ll* w = new ll[n];
	ll* v = new ll[n];
	fo(i,0,n-1){
		cin>>w[i]>>v[i];
	}
	memset(dp,-1,sizeof(dp));
	cout<<knapsnacki2(w,v,n,mw)<<endl;
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	ll t;
	t=1;//cin>>t;
	while(t--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 79232
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewReaderSize(os.Stdin, 1024*1024*1)
var mod uint64 = 998244353

func main() {
	list := getStdinIntArr64()
	var N uint64 = uint64(list[0])
	var M uint64 = uint64(list[1])
	var K uint64 = uint64(list[2])

	initCombination()

	var ans uint64 = 0
	var k uint64 = 0
	for k = 0; k <= K; k++ {
		var tmp1 uint64 = M
		var tmp2 uint64 = combination2(N-1, k)
		var tmp3 uint64 = powMod(M-1, N-1-k)
		var tmp4 uint64 = 1
		tmp4 = (tmp4 * tmp1) % mod
		tmp4 = (tmp4 * tmp2) % mod
		tmp4 = (tmp4 * tmp3) % mod
		ans = (ans + tmp4) % mod
	}
	fmt.Printf("%d\n", ans)
}

func getStdin() string {
	return readLine()
}
func getStdinInt() int {
	str := getStdin()
	rtn, _ := strconv.Atoi(str)
	return rtn
}
func getStdinIntArr() []int {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.Atoi(val)
	}
	return rtn
}

func getStdinIntArr64() []int64 {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int64, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.ParseInt(val, 10, 64)
	}
	return rtn
}

func powMod(n, m uint64) uint64 {
	var ans uint64 = 1
	for m != 0 {
		if (m & 1) != 0 {
			ans = ans * n % mod
		}
		n = n * n % mod
		m = m >> 1
	}
	return ans
}

// 階乗
// A,B,C -> ABC, ACB, BAC, BCA, CAB, CBA
func factorial(n uint64) uint64 {
	var i uint64
	var r uint64 = 1
	if n <= 1 {
		return 1
	}
	for i = n; i > 0; i-- {
		r *= i
	}
	return r
}

// 順列(n元集合からk個の元を取り出す順番無視の組み合わせ)
// A,B,C -> 2枚 -> AB, AC, BA, BC, CA, CB = 6
func permutation(n, r uint64) uint64 {
	if r == 0 {
		return 1
	}

	var i uint64
	var rtn uint64 = 1
	for i = 0; i < (r + 1); i++ {
		rtn *= n - i
	}
	return rtn
	//return factorial(n) / factorial(n-r)
}

// 組み合わせ（n個の異なるものからr個選ぶ組み合わせ）
// A,B,C -> 2枚 -> AB, AC, BC = 3
func combination(n, r uint64) uint64 {
	return permutation(n, r) / factorial(r)
}

var maxcomb uint64 = 200001
var fac []uint64  // n! (mod M)
var ifac []uint64 // k!^(M-2) (mod M)

func initCombination() {
	fac = make([]uint64, maxcomb+1)
	ifac = make([]uint64, maxcomb+1)
	fac[0] = 1
	ifac[0] = 1
	var i uint64
	for i = 0; i < maxcomb; i++ {
		fac[i+1] = fac[i] * (i + 1) % mod
		ifac[i+1] = ifac[i] * powMod(i+1, mod-2) % mod
	}
}
func combination2(n, r uint64) uint64 {
	if n == 0 && r == 0 {
		return 1
	}
	if n < r || n < 0 {
		return 0
	}
	var rtn uint64 = ifac[n-r] * ifac[r] % mod
	return rtn * fac[n] % mod
}

func readLine() string {
	buf := make([]byte, 0, 1024*1024*10)
	for {
		l, p, e := sc.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}


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

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

    int count = 0;
    for(int i=0; i<=a; i++){
        for(int j=0; j<=b; j++){
            for(int k=0; k<=c; k++){
                if(500 * i + 100 * j + 50 * k == x) count += 1;
            }
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
 
int main() {
    long long n,k,i,ans,coleft,cof,j;
    long long mod=1000000007;
    coleft=0;
    cof=0;
    ans=0;
    cin>>n>>k;
    vector<int> vec(n);
    for(i=0;i<n;i++){
      cin>>vec[i];
    }
    for(i=0;i<n;i++){
      for(j=0;j<i;j++){
        if(vec[i]>vec[j]){
          coleft++;
        }
      }
      for(j=i+1;j<n;j++){
        if(vec[i]>vec[j]){
          cof++;
        }
      }
      ans+=coleft*((k-1)*k/2%mod)%mod;
      coleft=0;
      ans+=cof*(k*(k+1)/2%mod)%mod;
      cof=0;
    }
  ans=ans%mod;
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<vector>
#define N_ 101000
using namespace std;
int D[1010][1010], Mod = 1000000007, n, m;
char p[1010][1010];
int main() {
	int i, a, b, j;
	scanf("%d%d", &n,&m);
	for (i = 1; i <= n; i++) {
		scanf("%s", p[i] + 1);
		for (j = 1; j <= m; j++) {
			if (p[i][j] == '#') {
				D[i][j] = 0;
				continue;
			}
			if (i == 1 && j == 1) {
				D[i][j] = 1;
				continue;
			}
			D[i][j] = 0;
			if (i != 1) {
				D[i][j] = D[i - 1][j];
			}
			if (j != 1) {
				D[i][j] = (D[i][j] + D[i][j - 1]) % Mod;
			}
		}
	}
	printf("%d\n", D[n][m]);
}

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

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	int h, n; cin >> h >> n;
	while (n--) {
		int a; cin >> a;
		h -= a;
	}
	if (h > 0) cout << "No";
	else cout << "Yes";
}



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

signed main(){
  string S;
  cin>>S;
  int A[26];
  rep(i,26)A[i]=0;
  rep(i,S.size())A[S[i]-'a']+=1;
  rep(i,26){
    if(A[i]==0){
      char ans='a'+i;
      cout<<ans<<endl;
      return 0;
    }
  }
  cout<<"None"<<endl;
  return 0;
}

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

int gcd(int a,int b){ return b ? gcd(b,a%b) : a;}

int main(){
    int N,X;
    cin >> N >> X;
    int g = 0;
    for(int i=0;i<N;i++){
        int x;
        cin >> x;
        g = gcd(g,abs(x-X));
    }
    cout << g;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <cassert>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <string>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>

constexpr std::int64_t MOD = 1000000007LL;

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

    std::int64_t N;
    std::cin >> N;
    std::vector<std::int64_t> cost(N);
    for (auto& c : cost) {
        std::cin >> c;
    }
    if (N == 1) {
        std::cout << cost[0] % MOD << std::endl;
        return 0;
    }
    if (N == 2) {
        std::cout << (cost[0] + cost[1]) * 3 % MOD << std::endl;
        return 0;
    }
    {
        std::vector<std::int64_t> facto1(N);
        std::vector<std::int64_t> facto2(N + 1);
        std::vector<std::int64_t> coef(N);
        std::vector<std::int64_t> coef2(N);
        {
            facto1[0] = 1;
            for (std::int64_t i = 1; i < N; ++i) {
                facto1[i] = facto1[i - 1] * (i + 1) % MOD;
            }
            facto2[N] = 1;
            facto2[N - 1] = N;
            for (std::int64_t i = N - 2; i >= 0; --i) {
                facto2[i] = facto2[i + 1] * (i + 1) % MOD;
            }
            coef[0] = facto1[N - 1];
            coef2[0] = facto1[N - 1];
            coef[1] = facto1[N - 2];
            coef2[1] = facto1[N - 2];
            for (std::int64_t i = 2; i < N; ++i) {
                coef[i] = (facto1[N - i - 1] * facto2[N - i + 2] * 2) % MOD;
                coef2[i] = (facto1[N - i - 1] * facto2[N - i + 1]) % MOD;
            }
        }
        std::int64_t left = (N - 1) / 2;
        std::int64_t right = N / 2;
        std::int64_t sum_num = 0;
        std::int64_t sum_coef = 0;
        std::int64_t sum_cost = 0;
        if (left == right) {
            sum_num = cost[left];
            sum_coef = coef[left];
            sum_cost = sum_num * sum_coef % MOD;
        } else {
            sum_num = cost[left] + cost[right];
            sum_coef = coef[left] + coef[right];
            sum_cost = sum_num * sum_coef % MOD;
        }
        while (true) {
            if (left == 0) {
                break;
            }
            --left;
            ++right;
            sum_num = (sum_num + cost[left] + cost[right]) % MOD;
            sum_coef = (sum_coef + coef[left] + coef[right]) % MOD;
            sum_cost = (sum_cost + sum_num * sum_coef) % MOD;
        }
        {
            std::int64_t temp_sum = 0;
            for (std::int64_t i = 0; i < N - 2; ++i) {
                temp_sum = (temp_sum + cost[i]) % MOD;
                sum_cost = (sum_cost - temp_sum * coef[N - i - 1] + temp_sum * coef2[N - i - 1] + MOD * temp_sum) % MOD;
            }
        }
        {
            std::int64_t temp_sum = 0;
            for (std::int64_t i = N - 1; i > 1; --i) {
                temp_sum = (temp_sum + cost[i]) % MOD;
                sum_cost = (sum_cost - temp_sum * coef[i] + temp_sum * coef2[i] + MOD * temp_sum) % MOD;
            }
        }
        std::cout << sum_cost % (MOD) << std::endl;
    }
    return 0;
}


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

int main(){
    int n;
    cin >> n;
    vector<int> h(n);
    for(int i = 0; i < n; i++) cin >> h[i];

    string ans = "Yes";
    for(int i = 1; i < n; i++){
        if(h[i] > h[i-1]){
            h[i]--;
        }else if(h[i] < h[i-1]){
            ans = "No";
        }
    }

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

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

#define vec                vector<int>
#define vecll              vector<ll>
#define vecst              vector<string>
#define vecb               vector<bool>
#define vec2(var, n, m)    vector<vector<int>> var(n, vector<int>(m, 0))
#define vecll2(var, n, m)  vector<vector<ll>> var(n, vector<ll>(m, 0))

#define rep(i,n)         for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n)       for(ll i=(ll)m; i<(ll)n; i++)
#define arr(var, n)      vec var(n); rep(i,n){cin >> var[i];}
#define arrll(var, n)    vecll var(n); rep(i,n){cin >> var[i];}
#define arrst(var, n)    vecst var(n); rep(i,n){cin >> var[i];}
#define all(var)         (var).begin(), (var).end()
#define sortall(var)     sort(all(var))
#define uniqueall(v)     v.erase(unique(v.begin(), v.end()), v.end());
#define f_sum(var)       accumulate(all(var), 0)
#define f_sumll(var)     accumulate(all(var), 0LL)
#define chmin(v1, v2)    v1 = min(v1, v2)
#define chmax(v1, v2)    v1 = max(v1, v2)
#define mp(v1, v2)       make_pair(v1, v2)
#define pb(var)          push_back(var)
#define prt(var)         cout << (var) << "\n"
#define prtd(n, var)     cout << fixed << setprecision(n) << var << "\n"
#define prtfill(n, var)  cout << setw(n) << setfill('0') << var;
#define prt2(v1, v2)     cout << v1 << " " << v2 << "\n"
#define prt3(v1, v2, v3) cout << v1 << " " << v2 << " " << v3 << "\n"
#define prtall(v)        rep(i,v.size()){cout<<v[i]<<(i!=v.size()-1?" ":"\n");}
void prtok(bool ok){prt(ok ? "yes" : "no");}
//----------------------------------------------------------------

int main(void) {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int l=0, tmp=0;
  rep(i,n){
    if(s[i]==')'){
      if(tmp<1) l++;
      else tmp--;
    } else {
      tmp++;
    }
  }
  while(l>0){
    cout << '(';
    l--;
  }
  cout << s;
  while(tmp>0){
    cout << ')';
    tmp--;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
string s;
main()
{
    while( 1 )
    {
        cin >> s;
        if( s == "0" ) break;
        int n = s.size();
        int a = 0, b = 0;
        for( int i = 0; i < n - 1; i++ )
        {
            if( s[i]  == 'A')
            {
                if( s[i + 1] == 'A' )a++;
                else b++;
            }
            else if( s[i] == 'B' )
            {
                if( s[i + 1] == 'A' )a++;
                else b++;
            }
        }
        if( a > b ) a++;
        else b++;
        printf( "%d %d\n", a, b );
    }
    return 0;
}


Measured memory_bytes: 3144
#include<iostream>
#include<queue>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
using namespace std;
/****************************/
#define ll long long
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define qi queue<int>
#define mii map<int,int>
#define msi map<string,int>
#define vs vector<string>
#define vc vector<char>
/****************************/
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define rep3(i,a,n) for(ll i=(a);i<(n);i++)
#define rep4(i,a,n) for(ll i=(a)-1;i>=n;i--)
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define pi 3.1415926535897932384626433832795
#define zero(n) memset(n,0,sizeof(n));
#define SZ(n) n.size()
#define sn st.nd 
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};
/****************************/
ll a,b,h,m;
int main()
{
	cin>>a>>b>>h>>m;
	double x,y;
	x=h*30*1.000000000+m*0.5*1.0000000;
	y=m*6*1.00000000;
	double c=fabs(x-y);
	c=min(c,360-c);
	double ans=a*a*1.000000+b*b*1.000000-2.000000*a*b*cos(c*pi/180);
	double ans2=sqrt(ans);
	printf("%.18f",ans2);
	return 0;
}

Measured memory_bytes: 4088
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using ll = long long;
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);

  int ct = 0;
  ll a, b, c;
  cin >> a >> b >> c;
  while(1) {
    if ((a & 1) || (b & 1) || (c & 1)) {
      cout << ct << endl;
      return 0;
    }
    if (a == b && b == c) {
      cout << "-1" << endl;
      return 0;
    }

    ll na = (b + c) / 2;
    ll nb = (a + c) / 2;
    ll nc = (a + b) / 2;
    a = na;
    b = nb;
    c = nc;
    ct++;
  }
}

Measured memory_bytes: 256
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use itertools::Itertools;
use num_traits::clamp;
use ordered_float::OrderedFloat;
use proconio::{input, marker::*, fastout};
use superslice::*;

#[fastout()]
fn main() {
    input! {
        n: usize,
        a: [i64; n],
    }
    let mut sorted = a.clone();
    sorted.sort();
    
    let a = a.into_iter().zip(0..).collect::<HashMap<_,_>>();
    let mut ans = 0;
    for (i, v) in (0..).zip(sorted) {
        let i2 = *a.get(&v).unwrap();
        if (i2 - i) % 2 != 0 {
            ans += 1;
        }
    }
    ans /= 2;
    println!("{}", ans);
}


Measured memory_bytes: 6876
import math
from functools import reduce
n = int(input())
t = [int(input()) for _ in range(n)]

def lcm_base(x,y):
    return (x*y)//math.gcd(x,y)
def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

print(lcm_list(t))

Measured memory_bytes: 9560
#include<bits/stdc++.h>
using namespace std;
int main(){
    int x;
    bool a= false;
    cin>>x;
    for(int i=1;i<=9;i++)
    {
        for(int j=1;j<=i;j++)
        {
            if(i*j==x)
            a=true;
        }
    }
    if(a)
        cout<<"Yes";
    else
        cout<<"No";




return 0;}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <unordered_set>
 
using namespace std;
 
typedef long long ll;
typedef pair<ll, ll> P;
static const int INF = 1000010000;
static const int NIL = -1;
static const int MOD = 1000000007;
 
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define SORT(v) sort(v.begin(), v.end());
#define RSORT(v) sort(v.begin(), v.end(), greater<int>);
#define pb push_back
#define mp make_pair
#define np next_permutation
#define pq priority_queue
 
int gcd(int a, int b) { int c; while (b != 0) { c = a%b; a = b; b = c; }return a; }
int lcm(int a, int b) { int c = gcd(a, b); a /= c; return a*b; }
int nCr(int a, int b) { int i, r = 1; for (i = 1; i <= b; i++) { r *= (a + 1 - i); r /= i; }return r; }
int pow(int a, int b) { int i, r = 1; for (i = 1; i <= b; i++) { r *= a; }return r; }
long long llpow(long long a, long long b) { long long i, r = 1; for (i = 1; i <= b; i++) { r *= a; }return r; }
long long llgcd(long long a, long long b) { long long c; while (b != 0) { c = a%b; a = b; b = c; }return a; }
long long lllcm(long long a, long long b) { long long c = llgcd(a, b); a /= c; return a*b; }
long long llnCr(long long a, long long b) { long long i, r = 1; for (i = 1; i <= b; i++) { r *= (a + 1 - i); r /= i; }return r; }
 
//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};

struct edge{
    int to, cost;
};

struct dt{
    int t, x, y;
};

int main(){
    int n, k;
    cin >> n >> k;
    int mas[2][1002][1002]; // mas[0][x][y]は白
    int d[2][1002][1002];
    REP(s, 2) REP(i, 1002) REP(j, 1002){
        d[s][i][j] = mas[s][i][j] = 0;
    }
    REP(i, n){
        int x, y;
        char c;
        cin >> x >> y >> c;
        if(c == 'W'){
            if((x / k + y / k) % 2 == 0) mas[0][x % k + 1][y % k + 1]++;
            else mas[1][x % k + 1][y % k + 1]++;
        }else{
            if((x / k + y / k) % 2 == 0) mas[1][x % k + 1][y % k + 1]++;
            else mas[0][x % k + 1][y % k + 1]++;
        }
    }
    REP(s, 2){
        FOR(i, 1, k + 1){
            FOR(j, 1, k + 1){
                d[s][i][j] = mas[s][i][j] + d[s][i - 1][j] + d[s][i][j - 1] - d[s][i - 1][j - 1];
            }
        }
    }
    int ans = 0;
    FOR(i, 1, k + 1){
        FOR(j, 1, k + 1){
            ans = max(ans, d[0][k][k] - d[0][i][k] - d[0][k][j] + d[0][i][j] * 2 + d[1][i][k] + d[1][k][j] - d[1][i][j] * 2);
            ans = max(ans, d[1][k][k] - d[1][i][k] - d[1][k][j] + d[1][i][j] * 2 + d[0][i][k] + d[0][k][j] - d[0][i][j] * 2);            
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 15872
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#define rep(i, n) for(i = 0; i < n; i++)
#define int long long
using namespace std;

int n;
int a[200001];

signed main() {
	int i;
	
	cin >> n;
	rep(i, n) cin >> a[i + 1];
	rep(i, n) a[i + 1] += a[i];
	
	int ans = 1e+18;
	rep(i, n + 1) {
		int diff = a[i] - (a[n] - a[i]);
		int res = abs(diff);
		ans = min(ans, res);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
# -*- coding: utf-8 -*-

n,m=map(int, input().split())
ab = []
cd = []

for _ in range(n):
    ab.append(list(map(int, input().split())))
#print(ab)

for _ in range(m):
    cd.append(list(map(int, input().split())))
#print(cd)

#print("-------")
#print("n:",n,"m:",m)

#PLiがどこに行くか
for i in range(n):
    #各チェックポイントとの距離
    dis = []
    for j in range(m):
        #print("---")
        #print("i:",i,"j:",j)
        #print(ab[i][0])
        #print(ab[i][1])
        #print(cd[j][0])
        #print(cd[j][1])
        dis.append(abs(ab[i][0] - cd[j][0])+abs(ab[i][1] - cd[j][1]))
    #print(dis)


    #最寄りのチェックポイントを特定
    min_dis = min(dis)
    for idx, k in enumerate(dis):
        if min_dis == k:
            print(idx+1)
            break


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace __gnu_pbds;
using namespace std;
 
typedef unsigned long long int ull;
typedef long double ldb;
typedef long long int ll;
 
#define for01(k,n)  for (ll i=k; i<n; i++)
#define for02(k,n)  for (ll j=k; j<n; j++)
#define for03(k,n)  for (ll k=k; k<n; k++)
#define for11(k,n)  for (ll i=k; i<=n; i++)
#define for12(k,n)  for (ll j=k; j<=n; j++)
#define for13(k,n)  for (ll k=k; k<=n; k++)
 
#define pb push_back
#define mp make_pair
 
#define pf push_front
#define popf pop_front
#define popb pop_back
 
#define vll vector<ll>
#define vint vector<int>
#define mll map<ll,ll>
#define mint map<int,int>
 
#define mll_it map<ll,ll>::iterator
#define mint_it map<int,int>::iterator
 
#define f first
#define s second
#define pp pair <ll, ll>
 
#define lb lower_bound
#define ub upper_bound
 
#define emp empty()
#define beg begin()
#define en end()
#define si size()
#define bk back()
 
#define deci(n)  fixed<<setprecision(n)
 
 
#define p0(a) cout << a << " "
#define p1(a) cout << a << "\n"
 
#define mem(a,n) memset(a, n, sizeof(a)); // n = 0 OR -1 only
 
#define MAX LLONG_MAX
#define MIN LLONG_MIN
#define MOD 1000000007
#define MOD2 998244353
 
#define BOOST ios_base::sync_with_stdio(false); cin.tie(NULL)
 
 
 
// CUSTOM HASH FUNCTION - O(1)
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
 
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
 
 
//gp_hash_table - Open Address Hash Table
 
//gp_hash_table<int, int> table;
 
const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
struct chash {
    int operator()(int x) const { return x ^ RANDOM; }
};
//gp_hash_table<key, int, chash> table;
 
 
// Indexed Set
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indSet;
 
/* FUNCTIONS:
1. The function "find_by_order" returns an iterator to the element at a given position:
2. The function "order_of_key" returns the position of a given element
	-> If the element does not appear in the set, we get the position that the element
	   would have in the set
	-> O(log n)*/

bool isPrime(int n) 
{ 
    // Corner cases 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
  
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (int i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
}

ll solve(ll n)
{
  ll a = MAX;
  for11(1, (ll)sqrt(n))
  {
    ll ans = MAX;
    if(n % i == 0)
      ans = (ll)(log(n/i) / log(10))+1;
    if(ans < a)
    {
      a = ans;
      //p1(i);
    }
  }
  return a;
}
    
int main()
{
  BOOST;
  ll n;
  cin >> n;
  
  p1(solve(n));
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <functional>

template <typename T>
struct node {
    T key;
    node* left;
    node* right;
    node* parent;
    node(T key):key(key), left(nullptr), right(nullptr), parent(nullptr) {}
};

template <typename T, typename Compare = std::less<T>>
class binary_search_tree {
public:
    binary_search_tree(): root(nullptr) {}

    ~binary_search_tree() { destroy(root); }

    bool insert(node<T>* z) {
        node<T>* trailer = nullptr;
        node<T>* head = root;
        while(head != nullptr) {
            trailer = head;
            if(Compare()(z->key, head->key)) head = head->left;
            else if(Compare()(head->key, z->key)) head = head->right;
            else break;
        }

        z->parent = trailer;
        if(trailer == nullptr) root = z;
        else if(Compare()(z->key, trailer->key)) trailer->left = z;
        else if(Compare()(trailer->key, z->key)) trailer->right = z;
        else return false;

        return true;
    }

    bool remove(node<T>* z) {
        return true;
    }

    node<T>* find(T key) {
        node<T>* x = root;
        while(x != nullptr) {
            if(Compare()(key, x->key)) x = x->left;
            else if(Compare()(x->key, key)) x = x->right;
            else break; 
        }
        return x;
    }

    void print_inorder() {
        inorder_tree_walk(root);
    }

    void print_preorder() {
        preorder_tree_walk(root);
    }

private:
    node<T>* root;

    void destroy(node<T>* x) {
        if(x == nullptr) return;
        destroy(x->left);
        destroy(x->right);
        delete x;
    }

    void inorder_tree_walk(node<T>* x) {
        if(x == nullptr) return;
        inorder_tree_walk(x->left);
        std::cout << ' ' << x->key;
        inorder_tree_walk(x->right);
    }

    void preorder_tree_walk(node<T>* x) {
        if(x == nullptr) return;
        std::cout << ' ' << x->key;
        preorder_tree_walk(x->left);
        preorder_tree_walk(x->right);
    }
};


#include <string>
int main() {
    binary_search_tree<int> tree;
    int m; std::cin >> m;
    while(m--) {
        std::string query;
        std::cin >> query;
        if(query == "insert") {
            int key; std::cin >> key;
            auto z = new node<int>(key);
            tree.insert(z);
        } else if(query == "find") {
            int key; std::cin >> key;
            auto z = tree.find(key);
            std::cout << (z != nullptr ? "yes" : "no") << std::endl;
        } else {
            tree.print_inorder(); std::cout << std::endl;
            tree.print_preorder(); std::cout << std::endl;
        }
    }
}


Measured memory_bytes: 21744