akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define FOR(i,a,b) for(int i=(a);i<(int)(b);i++)
#define rep(i,n) FOR(i,0,n)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SZ(x) (int)(x).size()
#define mset(a,x) memset(a,x,sizeof(a))
#define dbg(x) cout<<#x<<": "<<(x)<<"\n"
#define pb push_back
#define mp make_pair

int w,h,n;
int d[120][120];

void solve(){
    rep(i,n){
        int x,y,a; cin>>x>>y>>a;
        if(a == 1){
            rep(j,h) rep(i,x) d[j][i] = 0;
        } else if(a == 2){
            rep(j,h) FOR(i,x,w) d[j][i] = 0;
        } else if(a == 3){
            rep(i,w) rep(j,y) d[j][i] = 0;
        } else {
            rep(i,w) FOR(j,y,h) d[j][i] = 0;
        }
    }

    int res = 0;
    rep(y,h) rep(x,w) res += d[y][x];
    cout << res << "\n";
}

int main() {
    while(cin>>w>>h>>n){
        mset(d,0);
        rep(y,h) rep(x,w) d[y][x] = 1;
        solve();
    }


    return 0;
}


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

int main() {
  int n;
  string x;
  cin >> n >> x;

  vector<int> r(2), p(2);
  for (auto e : x) p[0] += e == '1';
  p[0]++;
  p[1] = p[0] - 2;
  for (auto e : x) {
    for (int i = 0; i < 2; i++) {
      if (p[i] == 0) continue;
      r[i] <<= 1;
      r[i] += e == '1';
      r[i] %= p[i];
    }
  }

  vector<vector<int>> br(2, vector<int>(n));
  for (int i = 0; i < 2; i++) {
    if (p[i] == 0) continue;
    br[i][0] = 1 % p[i];
    for (int j = 1; j < n; j++) br[i][j] = (br[i][j - 1] << 1) % p[i];
  }
  if (p[1] != 0) {
    for (int j = 0; j < n; j++) br[1][j] = (p[1] - br[1][j]) % p[1];
  }

  vector<int> m(n + 1);
  for (int i = 1; i <= n; i++) {
    int b = bitset<30>(i).count();
    m[i] = m[i % b] + 1;
  }

  for (int i = 0; i < n; i++) {
    int e = x[i] == '1';
    // cerr << r[e] << ' ' << br[e][n - 1 - i] << ' ' << (r[e] + br[e][n - 1 - i]) % p[e] << endl;
    cout << (p[e] == 0 ? 0 : m[(r[e] + br[e][n - 1 - i]) % p[e]] + 1) << endl;
  }
}


Measured memory_bytes: 6032
#include <iostream>
#include <vector>
#include <cstdio>
#include <queue>
#include <map>
#include<numeric>
using namespace std;
#define rep(i,n) for(int i=0; i<(n);i++)
typedef long long ll;


vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0;

        while (N % a == 0) {
            ++ex;
            N /= a;
        }

        res.push_back({a, ex});
    }

    if (N != 1) res.push_back({N, 1});
    return res;
}

int main() {
    long long N;
    cin >> N;
    const auto &res = prime_factorize(N);
    cout << N << ":";
    for (auto p : res) {
        for (int i = 0; i < p.second; ++i) cout << " " << p.first;
    }
    cout << endl;
}



Measured memory_bytes: 3096
IDENTIFICATION                   DIVISION.
PROGRAM-ID.                      ABC_081_B.
ENVIRONMENT                      DIVISION.
DATA                             DIVISION.
WORKING-STORAGE                  SECTION.
    01 N      PIC 9(3).
    01 INP    PIC X(2200).
    01 maxlen PIC 9(3).
    01 cur    PIC 9(4)  VALUE 1.
    01 i      PIC 9(18) VALUE 1.
    01 j      PIC 9(18).

    01 k      PIC 9(18).

    01 D      PIC 9(10).
    01 R      PIC 9(1).

    01 len    PIC 9(4).
    01 ans    PIC X(3).

    01 mn     PIC 9(2).

    01 cnt    PIC 9(2).

    01 A      PIC 9(10).

    01 ZS     PIC Z(2)9.
    01 DUMMY  PIC X(1).

PROCEDURE                        DIVISION.
MAIN.
    ACCEPT N.
    ACCEPT INP.

    MOVE N TO maxlen.

    MOVE 99 TO mn.

    PERFORM maxlen TIMES

        PERFORM VARYING j FROM cur BY 1
            UNTIL INP(j:1) = SPACE
        END-PERFORM

        COMPUTE len = j - cur

        MOVE INP(cur:len) TO A

        MOVE A TO D

        MOVE 0 TO R

        MOVE 0 TO cnt

        PERFORM UNTIL D = 0 OR R = 1
            DIVIDE 2 INTO D GIVING D REMAINDER R
            IF R = 0 THEN
                ADD 1 TO cnt
            END-IF
        END-PERFORM

        COMPUTE mn = FUNCTION MIN(mn, cnt)

        COMPUTE cur = j + 1

        ADD 1 TO i

    END-PERFORM.

    MOVE mn TO ZS.

    PERFORM UNANS.

    DISPLAY ans(1:FUNCTION STORED-CHAR-LENGTH(ans)).
    STOP RUN.

UNANS                            SECTION.
    UNSTRING
        ZS DELIMITED BY ALL SPACE
        INTO DUMMY ans
    END-UNSTRING.


Measured memory_bytes: 636
function myout(text){console.log(text);}//standard output
function Main(input) {
	input = input.trim();
	//input = input.trim().split(" ");
	//input = input.trim().split("\n");
	//input = input.trim().split(" ").map((a)=>Number(a));
	//input = input.trim().split("\n").map((a)=>Number(a));
  input = parseInt(input);
  var list = [input];
  while(true){
    var next = F(list[list.length - 1]);
    if(list.indexOf(next) != -1){
      //myout(list);
       myout(list.length + 1);
      return;
    }else{
      list.push(next);
    }
  }
}

function F(val){
 if(val % 2 == 0){
    return val / 2;
    }else{
      return 3 * val + 1;
    }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
#include <stdio.h>

typedef long long int lli;

int main()
{
	lli a, b, c, count = 0;

	scanf("%lld%lld%lld", &a, &b, &c);

	if (c <= a + b)
	{
		count = b + c;
	}

	else if (c > a + b)
	{
		count = 2 * b + a + 1;
	}

	printf("%lld\n", count);

	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cstring>
#include <ctype.h>
#include <algorithm>
#include <fstream>
#define mp make_pair
#define x first
#define y second
#define Debug(...) fprintf(stdout, __VA_ARGS__)

using namespace std;

typedef long long LL;
typedef pair<int, int> pii;
typedef pair<int, LL> pil;

const int MAXN = 1e5 + 7;
const int MOD = 1e9 + 7;

inline void proc_status() {
	ifstream t("/proc/self/status");
	cerr << string(istreambuf_iterator<char>(t), istreambuf_iterator<char>()) << endl;
}

template<typename T> inline T read() {
	T res = 0, flag = 1; char in = getchar();
	while(!isdigit(in)) { if(in == '-') flag = -1; in = getchar(); }
	while(isdigit(in)) { res = (res << 1) + (res << 3) + in - '0'; in = getchar(); }
	return res * flag;
}

template<typename T> inline void chkmax(T &a, T b) { if(a < b) a = b; }
template<typename T> inline void chkmin(T &a, T b) { if(a > b) a = b; }

inline void Add(int &x, int y) { x += y; if(x >= MOD) x -= MOD; }

namespace BIT {
	int tr[MAXN];
	inline int lowbit(int x) { return x & (-x); }
	inline void update(int x, int val) { for(; x < MAXN; x += lowbit(x)) Add(tr[x], val); }
	inline int query(int x) { int res = 0; for(; x > 0; x -= lowbit(x)) Add(res, tr[x]); return res; }
}

int n, m;
int tx[MAXN], ty[MAXN];
pii p[MAXN];
int f[MAXN];
int vis[MAXN];

inline void init() {
	n = read<int>(); m = read<int>();
	for(int i = 1; i <= n; ++i) tx[i] = read<int>();
	for(int i = 1; i <= m; ++i) ty[i] = read<int>();
	int pos = 1;
	for(int i = 1; i <= m; ++i) {
		while(pos <= n && tx[pos] < ty[i]) {
			p[pos].y = ty[i] - tx[pos]; ++pos;
		}
//		printf("FF %d\n", pos);
		if(i == 1) for(int j = 1; j < pos; ++j) vis[j] = 1;
		while(pos <= n && tx[pos] <= ty[i]) vis[pos++] = 1;
	}

	pos = n;
	for(int i = m; i >= 1; --i) {
		while(pos >= 1 && tx[pos] > ty[i]) {
			p[pos].x = tx[pos] - ty[i]; --pos;
		}
		if(i == m) for(int j = n; j > pos; --j) vis[j] = 1;
		while(pos >= 1 && tx[pos] >= ty[i]) vis[pos--] = 1;
	}

	int tot = 0;
	for(int i = 1; i <= n; ++i)
		if(!vis[i]) p[++tot] = p[i];
	n = tot;

//	for(int i = 1; i <= n; ++i) {
//		printf("(%d, %d)\n", p[i].x, p[i].y);
//	}
	sort(p + 1, p + n + 1);
	n = unique(p + 1, p + n + 1) - p - 1;

	for(int i = 1; i <= n; ++i) ty[i] = p[i].y;
	sort(ty + 1, ty + n + 1);
	tot = unique(ty + 1, ty + n + 1) - ty - 1;

	for(int i = 1; i <= n; ++i)
		p[i].y = lower_bound(ty + 1, ty + tot + 1, p[i].y) - ty;
//	exit(0);
}

inline void solve() {
	int pos = 1;
	for(int i = 1; i <= n; ++i) {
		while(p[pos].x == p[i].x) {
			f[pos] = BIT::query(p[pos].y - 1) + 1;
			++pos;
		}
		for(int j = i; j < pos; ++j) BIT::update(p[j].y, f[j]);
		i = pos - 1;
//		printf("In Pos(%d, %d) V = %d\n", p[i].x, p[i].y, BIT::query(p[i].y - 1) + 1);
	}
//	exit(0);
	int ans = 1;
	for(int i = 1; i <= n; ++i) {
		Add(ans, f[i]);
//		printf("FF %d\n", f[i]);
	}

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

int main() {
	init();
	solve();

	return 0;
}



Measured memory_bytes: 2560
package main

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

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	/*/TODO:!!!!!!!テスト用!!!!!!!!!
	sc = bufio.NewScanner(strings.NewReader(`
					`))
	//TODO:!!!!!!!テスト用!!!!!!!!!*/

	buf := make([]byte, 1024*1024)
	sc.Buffer(buf, bufio.MaxScanTokenSize)
	sc.Split(bufio.ScanWords)
	defer out.Flush() // !!!!caution!!!! you must use Fprint(out, ) not Print()
	/* --- code --- */

	//fmt.Fprintln(out, "[DEBUG]", time.Now())

	a := nextInt()
	b := nextInt()

	ans := a * b

	//fmt.Fprintln(out, "[DEBUG]]", a)
	fmt.Fprintln(out, ans)
}

//------------------------------------------------------------------------------

// -*-*-*-*-*-*-*-*-
// * I/O utilities *
// -*-*-*-*-*-*-*-*-

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func chars(s string) []string {
	ret := make([]string, len([]rune(s)))
	for i, v := range []rune(s) {
		ret[i] = string(v)
	}
	return ret
}

func absInt(x int) int {
	return int(math.Abs(float64(x)))
}
func minInt(x, y int) int {
	if x < y {
		return x
	}
	return y
}
func maxInt(x, y int) int {
	if x > y {
		return x
	}
	return y
}


Measured memory_bytes: 1796
#include <iostream>
#include <string>
#include <set>

using namespace std;

void dfs() {

}

int main() {
    string str;
    cin >> str;
    int K;
    cin >> K;
    
    set<string> st;
    set<char> st_1;
    for(int i=0; i<str.size(); i++) {
        st.insert(str.substr(i, 1));
        st_1.insert(str[i]);
    }
    
    for(auto itr=st_1.begin(); itr!=st_1.end(); itr++) {
        // for(int j=1; j<str.size(); j++) {
        //     for(int i=0; i+j<str.size(); i++) {
        //         if(str[i]==*itr) {
        //             st.insert(str.substr(i, j+1));
        //         }
        //     }
        //     if(st.size()-st_1.size()>=K) break;
        // }
        
        for(int i=0; i<str.size(); i++) {
            if(str[i]==*itr) {
                for(int j=1; j<K; j++) {
                    st.insert(str.substr(i, j+1));
                }
            }
        }
        if(st.size()>=K) break;
        
    }
    
    int count=0;
    for(auto itr=st.begin(); itr!=st.end(); itr++) {
        // cout << *itr << endl;
        if(count==K-1) {
            cout << *itr << endl;
            return 0;
        }

        count++;
    }
    
    return 0;
    
}

Measured memory_bytes: 256
import logging

logging.basicConfig(level=logging.INFO, format="%(message)s")
logging.disable(logging.CRITICAL)


def gcd(m, n):
    x = max(m, n)
    y = min(m, n)
    if x % y == 0:
        return y
    else:
        while x % y != 0:
            z = x % y
            x = y
            y = z
        else:
            return z

def main():
    A, B, C_, D_ = (int(x) for x in input().split())

    if C_ > D_:
        C, D = D_, C_
    else:
        C, D = C_, D_
        

    lcm_CD = int(C * D / gcd(C, D))
    
    div_C = int(B // C) - int((A - 1) // C)
    div_D = int(B // D) - int((A - 1) // D)
    div_lcm_CD = int(B // lcm_CD) - int((A - 1) // lcm_CD)
    
    answer = B - A + 1 - div_C - div_D + div_lcm_CD

    if A == 0:
        print(answer - 1)
    else:
        print(answer)

if __name__ == "__main__":
    main()


Measured memory_bytes: 4964
h, w = gets.split.map(&:to_i)
s = Array.new(h) { gets.chomp.chars }

s.each { |e| e << '.' }
s << '.' * w

1.upto(h) do |i|
  1.upto(w) do |j|
    next if s[i][j] == '.'

    if s[i][j - 1] == '.' && s[i][j + 1] == '.' &&
       s[i - 1][j] == '.' && s[i + 1][j] == '.'
      puts :No
      exit
    end
  end
end

puts :Yes

Measured memory_bytes: 1916
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
  
using namespace std;
using namespace __gnu_pbds;
 
#define ll long long
#define uint unsigned int
#define ull  unsigned long long
#define pb push_back
#define mk make_pair
#define ins insert
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define X first
#define Y second
#define umap unordered_map
#define speed() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define setvalue(d,s,e,n) for(int qwe = s; qwe < e; ++qwe) d[qwe] = n
#define mset multiset
#define pqueue priority_queue
   
template<class T> using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
        
const int  N = 2e5 + 314;
const int INF = 1e9;
const double PI = acos(-1);
const int MOD = 1e9 + 7;
const double eps = 1e-9;
const long long LINF = 1e18 + 3141;
ll a[N], b[N];
ll sum[N];
void solve(){
    // 
    ll n, m, k;
    cin >> n >> m >> k;
    for(int i = 1; i <= n; ++i)
        cin >> a[i];
    for(int j = 1; j <= m; ++j) 
        cin >> b[j],
        sum[j] = sum[j - 1] + b[j];

    ll mx = 0;
    ll pfsum = 0;
    for(int i = 0; i <= n; ++i){
        pfsum += a[i];
        ll rem = k - pfsum;
        if(rem < 0)
            break; 
        ll l = 0, r = m, f = 0;
        while(l <= r) {
            ll md = (l + r) / 2;
            if(sum[md] <= rem) {
                f = md;
                l = md + 1;
            }else {
                r = md - 1;
            }
            
        }
        mx = max(mx, i + f);
    }
    cout << mx << '\n';
}
 
int main(){
    speed();
    int t = 1;
    // cin >> t;
    while(t--)solve();
}

Measured memory_bytes: 8340
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 30;
const int MOD = 1e9 + 7;

const int N = 1e5 + 10;
int a[N];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
  }
  int g = a[0];
  for (int i = 1; i < n; ++i) {
    g = __gcd(g, a[i]);
  }
  int maxv = *max_element(a, a + n);
  puts(m % g == 0 && maxv >= m ? "POSSIBLE" : "IMPOSSIBLE");
  return 0;
}


Measured memory_bytes: 764
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
#include<cmath>
using namespace std;

int main(){
    int a,b;
    cin>>a>>b;
    if((b/100)!=0){
        a*=1000;
    }
    else if((b/10)!=0){
        a*=100;
    }
    else{
        a*=10;
    }
    int c=a+b;
    int f=sqrt(c);
    if(f*f==c){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <stdio.h>
using namespace std;
int a[1000000];

int main() {
  int n, k; cin >> n >> k;
  int g, mx;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (!i) mx = g = a[0];
    else {
      g = __gcd(g,a[i]);
      mx = max(mx, a[i]);
    }
  }
  string str[2] = {"IMPOSSIBLE","POSSIBLE"};
  cout << str[!(k%g) && k <= mx] << endl;

  return 0;
}

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

int main()
{
  //入力
  long int s,w;
  cin>> s>> w;

  //操作
  if(s<=w)
  {
    cout<<"unsafe"<<endl;
  }
  else
  {
    cout<<"safe"<<endl;
  }
  //出力
  
}

Measured memory_bytes: 3024
/**Which of the favors of your Lord will you deny ?**/

#include<bits/stdc++.h>
using namespace std;

#define LL long long
#define PII pair<int,int>
#define PLL pair<LL,LL>
#define MP make_pair
#define F first
#define S second
#define INF INT_MAX

#define ALL(x) (x).begin(), (x).end()
#define DBG(x) cerr << __LINE__ << " says: " << #x << " = " << (x) << endl

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

template<class TIn>
using indexed_set = tree<
                    TIn, null_type, less<TIn>,
                    rb_tree_tag, tree_order_statistics_node_update>;

/*
PBDS
-------------------------------------------------
1) insert(value)
2) erase(value)
3) order_of_key(value) // 0 based indexing
4) *find_by_order(position) // 0 based indexing

*/

inline void optimizeIO()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

const int nmax = 2e5+7;
const LL LINF = 1e17;

string to_str(LL x)
{
    stringstream ss;
    ss<<x;
    return ss.str();
}

//bool cmp(const PII &A,const PII &B)
//{
//
//}

int main()
{
    optimizeIO();


    int n,m;
    cin>>n>>m;

    vector<int>v(m);


    for(int i=0;i<m;i++)
        cin>>v[i];

    int s = 0;
    for(int i=0;i<m;i++)
    {
        s+=v[i];
    }

    if(s>n)
        cout<<-1<<endl;
    else
        cout<<n-s<<endl;


    return 0;
}




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

typedef uint64_t u64;
typedef int64_t i64;
typedef uint32_t u32;
typedef int32_t i32;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

using namespace std;

#define rep(idx, N) for (u64 idx = 0; idx < N; idx++)

u64 dp[100 + 10][100000 + 10] = {{0}};

int main() {
  u64 n, wmax;
  cin >> n >> wmax;

  vector<i64> w, v;

  rep(i, n) {
    i64 wi, vi;
    cin >> wi >> vi;
    w.push_back(wi);
    v.push_back(vi);
  }

  u64 ans = 0;

  for (int i = 0; i < n; i++) {
    rep(j, wmax + 1) {
      dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]);
      if (j >= w[i]) {
        dp[i + 1][j] = max(dp[i + 1][j], dp[i][j - w[i]] + v[i]);
      }
    }
  }

  cout << dp[n][wmax];

  return 0;
}


Measured memory_bytes: 81664
#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
const int N = 100005;

int n, m;
pair<int, int> a[N];
vector<int> g[N];

bool c[N];
bool dfs(int x)
{
    c[x] = true;
    for (int i = 0; i < g[x].size(); ++i)
    {
        int h = g[x][i];
        if (h == a[n - 1].second)
            return true;
        if (c[h])
            continue;
        if (dfs(h))
            return true;
    }
    return false;
}

int main()
{
    cin >> n >> m;
    for (int i = 1; i <= n; ++i)
        a[i].second = i;
    for (int i = 0; i < m; ++i)
    {
        int x, y;
        cin >> x >> y;
        a[x].first++;
        a[y].first++;
        g[x].push_back(y);
        g[y].push_back(x);
    }
    sort(a + 1, a + n + 1);
    for (int i = 1; i <= n; ++i)
    {
        if (a[i].first % 2 == 1)
        {
            cout << "No" << endl;
            return 0;
        }
    }
    if (a[n].first == 2)
    {
        cout << "No" << endl;
        return 0;
    }
    if (a[n].first == 4 && a[n - 1].first == 2)
    {
        cout << "No" << endl;
        return 0;
    }
    if (a[n].first == 4 && a[n - 1].first == 4 && a[n - 2].first == 2)
    {
        c[a[n].second] = true;
        for (int i = 0; i < 4; ++i)
        {
            int h = g[a[n].second][i];
            if (!dfs(h))
            {
                cout << "Yes" << endl;
                return 0;
            }
        }
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 7424
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
const long long INFLL = 1LL << 60;
const int INFINT = 1 << 30;
const long long MOD = 1e9 + 7;

template <class T> void vecout(T V) {
    auto t = V.begin();
    while(t != V.end()) {
        cout << *t++;
        if(t != V.end()) cout << " ";
    }
    cout << endl;
};

int main() {
    int n, pk, lk, rk;
    cin >> n;
    vector<int> Heap(n + 1);
    rep(i, 1, n + 1) cin >> Heap[i];

    rep(i, 1, n + 1) {
        pk = i / 2, lk = 2 * i, rk = 2 * i + 1;

        cout << "node " << i << ": key = " << Heap.at(i);
        if(pk) cout << ", parent key = " << Heap.at(pk);
        if(lk <= n) cout << ", left key = " << Heap.at(lk);
        if(rk <= n) cout << ", right key = " << Heap.at(rk);
        cout << ", \n";
    }
}



Measured memory_bytes: 3104
#include<stdio.h>

int main(void){
  float i = 0;
  int a=0;
  int b=0;
  int c=0;
  int d=0;
  scanf("%d",&a);
  scanf("%d",&b);
  for(i=1; i<=1000; i=i+1.0){
    if ( 0.5 <= (i*0.08 - (int)i*0.08)){
      c = (int)i*0.08+1;
    }else{
      c = (int)i*0.08;
    }
    if ( 0.5 <= (i*0.10 - (int)i*0.10)){
      d = (int)i*0.10+1;
    }else{
      d = (int)i*0.10;
    }
    if (a == c && b == d){
      printf("%d", (int)i);
      return 0;
    }
  }
  printf("-1");
}

Measured memory_bytes: 128
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	i, _ := strconv.Atoi(next())
	return i
}

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func min(nums ...int) int {
	ret := nums[0]
	for _, v := range nums {
		if v < ret {
			ret = v
		}
	}
	return ret
}

func max(nums ...int) int {
	ret := nums[0]
	for _, v := range nums {
		if v > ret {
			ret = v
		}
	}
	return ret
}

func divFloor(a, b int) int {
	return (a + (b - 1)) / b
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	h, w := nextInt(), nextInt()

	// 縦に3分割
	ans := (divFloor(w, 3) - w/3) * h
	// 横に3分割
	ans = min(ans, (divFloor(h, 3)-h/3)*w)
	// 先に横に分割してから縦に分割
	for x := 1; x <= h-1; x++ {
		a, b, c := w*x, (w/2)*(h-x), divFloor(w, 2)*(h-x)
		ans = min(ans, max(a, b, c)-min(a, b, c))
	}
	// 逆バージョン
	for x := 1; x <= w-1; x++ {
		a, b, c := h*x, (h/2)*(w-x), divFloor(h, 2)*(w-x)
		ans = min(ans, max(a, b, c)-min(a, b, c))
	}

	puts(ans)
}


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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define fst first
#define snd second
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define EPS (1e-9)
#define equals(a,b) (fabs((a)-(b))<EPS)

using namespace std;

bool LT(double a,double b) { return !equals(a,b) && a < b; }
bool LTE(double a,double b) { return equals(a,b) || a < b; }

const string YES = "";
const string NO  = "";

typedef long long ll;

int n;
vector<int> a;

bool check(vector<int> &vec) {
  rep(i,n) {
    int sum = 0;
    for(int j=(i+1);j<=n;j+=(i+1)) {
      sum += vec[j-1];
    }
    if( sum % 2 != a[i] ) {
      return false;
    }
  }
  return true;
}

void bf() {
  int cnt = 0;
  rep(i,(1<<n)) {
    vector<int> vec(n,0);
    rep(j,n) if( (i>>j) & 1 ) vec[j] = 1;
    if( check(vec) ) {
      ++cnt;
      cout << "* " << cnt << "-th: (" << vec.size() << ")" << endl;
      cout << "  ";
      rep(j,(int)vec.size()) {
	cout << vec[j] << " ";
      } puts("");
    }
  }
  cout << "Found: " << cnt << " patterns" << endl;
}

void solve() {
  //bf();
  vector<int> ans;
  vector<int> vec(n,0);
  int m = n / 2;
  for(int i=m;i<n;++i) {
    if( a[i] == 1 ) { vec[i] = 1; ans.pb(i); }
  }
  for(int i=m-1;i>=0;--i) {
    int sum = 0;
    for(int j=i;j<n;j+=(i+1)) {
      sum += vec[j];
    }
    if( sum%2 != a[i] ) {
      vec[i] = 1;
      ans.pb(i);
    }
  }
  sort(ALL(ans));
  cout << ans.size() << endl;
  rep(i,(int)ans.size()) {
    if( i ) cout << " ";
    cout << ans[i]+1;
  } puts("");
}

int main() {
  cin >> n;
  a.resize(n);
  rep(i,n) cin >> a[i];
  solve();
  return 0;
}


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

using namespace std;

#define intt long long
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const int N = 100005;

int n, a, b;

int x[N];

int main() {

	FAST;

	cin >> n >> a >> b;
	for (int i = 0; i < n; i ++) {
		cin >> x[i];
	}
	intt ans = 0;
	for (int i = 1; i < n; i ++) {
		ans += min(1LL * (x[i] - x[i - 1]) * a, 1LL * b);
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 640
#include <vector>
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <numeric>
using namespace std;

typedef long long ll;

#define REP(var,n) for(int var=0;var<(n);var++)
#define REPP(var,n) for(int var=1;var<(n);var++)
#define ALL(c) (c).begin(),(c).end()

int euclid( int a, int b )
{
    int temp;

    if( a < b ) { return euclid(b,a); }

    if( a % b == 0 ) return b;
    return euclid( b, a % b );
}

int abs(int x){
    if(x < 0) { return -x;}
    else { return x;}
}


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

    ll x[N];

    REP(i,N){
        cin >> x[i];
        x[i] -= X;
        x[i] = abs(x[i]);
    }
    
    ll tmp=0; 

    REP(i,N){
        if(x[i] != 0) { tmp = x[i]; break;}
    }

    REP(i,N){
        if(x[i] !=0){
            tmp = euclid(tmp, x[i]);
        }
    }

    cout << tmp << endl;
}



Measured memory_bytes: 1024
#include <stdio.h>

int main() {

char ch[2000] = {0};
char W[15] = {0};
int i,j,k,l,m,n,o,p; 

m=0; /* ??????W?????\??? */
while(1) {

scanf("%c" , &W[m]);
/* printf("W[%d]???%c ",m,W[m]); /*W[m]????¢????*/
if(W[m] == '\n') {
break;
}
m = m+1;
}

n=0; /* ?????????T?????\??? */
while(1) {

scanf("%c",&ch[n]);

 /*printf("ch[%d]???%c ",n ,ch[n]); /*  ch[n]????¢???? */
 

if(ch[n] =='T' && ch[n-1] == 'X' && ch[n-2] == 'E' && ch[n-3] == 'T' && ch[n-4] == '_' && ch [n-5] == 'F' && ch[n-6] == 'O' && ch[n-7] == '_' && ch[n-8] == 'D' && ch[n-9] == 'N' && ch[n-10] == 'E') {
/* printf("break??????\n"); */
break;
}
n +=1;
} /*while??\????????????*/


/*??????????????¨?????????????¢????*/
p=0;
for(i=0; i<n; i++){
if(W[0] == ch[i] || W[0] == ch[i]+32 || W[0] == ch[i]-32) {
/* printf("????????????????¢????ch[%d]\n",i); /**/
if(ch[i+m] == ' ' || ch[i+m] == '\n' || W[0] == ch[0]  ) { 
if(ch[i-1] == ' ' || ch[i-1] == '\n' ||  W[0] == ch[0]+32 || W[0] == ch[0]-32){
o=o+1;
/*printf("ch[%d]???%c?????????\n",i,ch[i]); /*??????????¢????*/

for(j=0;j<m; j++) {
if(W[j] == ch[i+j] || W[j] == ch[i+j]+32 || W[j] == ch[i+j]-32){
/*printf("W[%d]???%c ch[%d]???%c\n",j,W[j],i+j,ch[i+j]); /*???= ????¢???????*/
o=o+1;
}
}
}
}

if(o==m+1){
p=p+1;
}
o=0;
}
}

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

return 0;

}

Measured memory_bytes: 540
#define ll long long

#include <bits/stdc++.h>
using namespace std;

int main(){
  int n, i, m = 0;
  ll sp = 0, sm = 0;
  cin >> n;
  vector<int> dif(n);
  
  for(i = 0; i < n; i++) cin >> dif.at(i);
  for(i = 0; i < n; i++){
    int b;
    cin >> b;
    dif.at(i) -= b;
    
    if( dif.at(i) < 0 ){
      m++;
      sm += dif.at(i);
    } else {
      sp += dif.at(i);
    }
  }
  
  if( sm + sp < 0 ){
    cout << -1 << endl;
    return 0;
  }
  
  sort(dif.begin(), dif.end(), [](int a, int b){return a>b;});
  
  for(i = 0; sm < 0; i++) sm += dif.at(i);
  
  cout << m + i << endl;
}

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

int main(){
  int x,y;
  cin>>x>>y;
  bool b=true;
  if(y%2!=0) b=false;
  if(y<2*x||y>4*x) b=false;
  if(b) cout<<"Yes";
  else cout<<"No";
}

Measured memory_bytes: 3632
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll MOD = (1e+9)+7;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
//x,yがax+by=gcd(a,b)の解になる
ll extgcd(ll a, ll b, ll& x, ll& y) {
	ll d = a;
	if (b != 0) {
		d = extgcd(b, a%b, y, x);
		y -= (a / b)*x;
	}
	else {
		x = 1; y = 0;
	}
	return d;
}
//aのmod mでの逆元を求める
ll mod_inverse(ll a, ll m) {
	ll x, y;
	extgcd(a, m, x, y);
	return (m + x % m) % m;
}
ll p[200001];
void init() {
	p[0] = 1;
	for (ll i = 1; i < 200001; i++) {
		p[i] = p[i - 1] * i%MOD;
	}
}
ll pas(ll x,ll y){
	ll res = p[x+y];
	(res *= mod_inverse(p[x], MOD)) %= MOD;
	(res *= mod_inverse(p[y], MOD)) %= MOD;
	return res;
}
int main() {
	init();
	ll h, w, a, b; cin >> h >> w >> a >> b;
	ll out = 0;
	LP s = { h - a-1,b };
	while (s.first >= 0 && s.second <= w-1) {
		(out += pas(h-s.first-1,w-s.second-1)*pas(s.first, s.second)%MOD) %= MOD;
		s.first--; s.second++;
	}
	cout << out << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <numeric>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)






int main() {
		string s,t;
		cin >> s>>t;
		sort(s.begin(), s.end());

		
		sort(t.begin(), t.end());
		reverse(t.begin(), t.end());

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

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

int main() {
  uint32_t N = 0, M = 0;
  std::cin >> N >> M;
  std::vector<std::vector<uint32_t>> data(N + 1);
  std::vector<std::pair<uint32_t, uint32_t>> PY(M);
  for (size_t m = 0; m < M; m++) {
    std::cin >> PY[m].first >> PY[m].second;
    data[PY[m].first].push_back(PY[m].second);
  }

  for (size_t n = 0; n < data.size(); n++) {
    std::sort(data[n].begin(), data[n].end());
  }

  for (size_t i = 0; i < M; i++) {
    uint32_t id = std::lower_bound(data[PY[i].first].begin(),
                                   data[PY[i].first].end(), PY[i].second) -
                  data[PY[i].first].begin();
    std::cout << std::setw(6) << std::setfill('0') << PY[i].first
              << std::setw(6) << std::setfill('0') << id + 1 << std::endl;
  }

  return 0;
}

Measured memory_bytes: 7808
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
using ll = long long;
 
int main(){
  int n;
  cin >> n;
  ll mult=1;
  vector<ll> a(n);
  rep(i,n){
    cin >> a[i];
  }
  rep(i,n){
    if(a[i]==0){
      cout << 0 << endl;
      return 0;
    }
  }
 
  rep(i,n){
    if(a[i]<=1000000000000000000/mult){
    mult *=a[i];
    }
    else{
      cout << -1 << endl;
      return 0;
    }
  }
 
  cout << mult << endl;
  return 0;
}

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

int main() {
	int n,c,m;
	cin>>n>>m;
	for(int a=0;a<=n;a++){
		for(int b=0;b<=n;b++){
		c=n-a-b;
		if(c<0)break;
		if(m==a*10000+b*5000+c*1000){
			cout<<a<<' '<<b<<' '<<c;
			return 0;
		}
		}
	}
	cout<<-1<<' '<<-1<<' '<<-1;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <stack>
#include <deque>
#include <cmath>
#include <map>
using ll = long long;
using namespace std;

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  cout << max(a*b, c*d) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (int i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=1e18;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

int main(){
  int cnt=0;
  int n,h;
  cin>>n>>h;
  vector<P> ab(n);
  rep(i,0,n){
    int a,b;
    cin>>a>>b;
    ab[i]=mp(a,b);
  }
  //////////////
  sort(all(ab));
  reverse(all(ab));
  ll amax=ab[0].first;
  ////////////////////////////
  rep(i,0,n){
    swap(ab[i].first,ab[i].second);
  } 
  P mx;
  mx=ab[0];
      int a=mx.second,b=mx.first;
  sort(all(ab));
  reverse(all(ab));
  /////////////////////////////
  int v=0;
  rep(i,0,n){
   if(ab[i]==mx&&v==0){
     
     v++;
     continue;
   }
    if(ab[i].first<amax) break;
    if(ab[i].first<b&&h-b<=0) break;
    cnt++;
    h-=ab[i].first;
    
    if(h<=0) break;
   
  }
 
    ////int a=mx.second,b=mx.first;
    while(h>b){
      cnt++;
      h-=a;
    }
  if(h>0) cnt++;
  
  
  
  cout<<cnt<<endl;
}
/*
a(n)の最大値　amax 以下のbを持つ剣は使わない
amax 以外の剣で使うものを投げる
amax の剣のb の値以下になるまでa減らす
b減らして倒す。
*/




Measured memory_bytes: 4032
"use strict";
const input = require('fs').readFileSync('/dev/stdin', 'utf8').split(" ");
const s = parseInt(input[0]);

let list = [];
let t = s;
for(let i = 2; ; i++){
  list.push(t);
  if(t % 2 === 0){
    t = t / 2;
  }else{
    t = 3 * t + 1;
  }
  if(list.indexOf(t) >= 0) {
    console.log(i);
    break;
  }
}




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

namespace ARC80_C
{
    class Program
    {
        static void Main(string[] args)
        {

            var n = int.Parse(Console.ReadLine());

            var a = Console.ReadLine().Split().Select(long.Parse).ToArray();

            int co = 0;
            int c4 = 0;

            for (int i = 0; i < n; i++)
            {
                if (a[i] % 2 == 1) co++;
                if (a[i] % 4 == 0) c4++;

            }
            if (c4 >= co || (co + c4 == n && co - c4 == 1))
            {

                Console.WriteLine("Yes");
            }
            else
            {

                Console.WriteLine("No");
            }
        }
    }
}


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

int main(){
  int N;
  cin>>N;
  vector<int> A (N);
  rep(i,N)cin>>A[i];
  int h=0;
  ll ans=0;
  rep(i,N){
    h=max(h,A[i]);
    ans+=h-A[i];
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 4024
#include <iostream>
#include <string>
#include <map>

using namespace std;

int main()	{
  	string s;
  	cin >> s;
  	map<char, int> freq;
  	for (auto x : s)	{
    	freq[x]++;
    }
  	for (auto x : freq)	{
    	if (x.second % 2)	{
        	cout << "No" << endl;
          	return 0;
        }
    }
  	cout << "Yes" << endl;
 	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int N,K;
int INF = INT_MAX;
int h[100105];
long cost[100105];

int main(){
    cin >> N >> K;
    for(int i = 1; i <= N; ++i){
        cin >> h[i];
        cost[i] = INF;
    }
    
    cost[1] = 0;
    
    for(int i = 1; i <= N; ++i){   
        for(int j = 1; j <= K; ++j){
            cost[i + j] = min(cost[i + j],cost[i] + abs(h[i+j]-h[i]));
        }
    }
    
    cout << cost[N] << endl;
    
}

Measured memory_bytes: 1408
using System;

class Program
{
    static void Main(string[] args)
    {
        var n = int.Parse(Console.ReadLine());
        var k = int.Parse(Console.ReadLine());
        var x = int.Parse(Console.ReadLine());
        var y = int.Parse(Console.ReadLine());

        var a = Math.Min(n, k);
        Console.WriteLine(a * x + (n - a) * y);
    }
}


Measured memory_bytes: 11220
#include <stdio.h>
#include <iostream>

int main(){
	int a, b, c;
   	scanf("%d %d %d", &a, &b, &c);
   	if( a < b && b < c )
   	{
   	printf("Yes\n");
	}else
	{
	 printf("No\n");
		}
}


Measured memory_bytes: 3172
#include <iostream>
#include <vector>
using namespace std;
 
int main() {
    int N;
    cin >> N;
    long long ketasuu = 0, sum = 0;
    for (int i = 0; i < N; ++i) {
        long long d, c;
        cin >> d >> c;
        ketasuu += c;
        sum += d * c;
    }
    cout << (sum - 1) / 9 + (ketasuu - 1) << endl;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> s(n);
    int sum = 0;
    rep(i, n) {
        cin >> s.at(i);
        sum += s.at(i);
    }

    if(sum % 10 != 0) {
        cout << sum << endl;
        return 0;
    }
    int ans = 0;
    rep(i, n) {
        int p = sum - s.at(i);
        if(p % 10 != 0) ans = max(ans, p);
    }
    cout << ans << endl;
    return 0;
}

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

int n, A[20], M[200];
int memo[21][2001];

void init() {
	for (int i = 0; i < 21; i++) {
		for (int j = 0; j < 2001; j++) {
			memo[i][j] = -1; // Not fixed
		}
	}
	for (int i = 0; i < 21; i++) memo[i][0] = 1;
	for (int i = 0; i < 2001; i++) memo[n][i] = 0;
	memo[n][0] = 1;
}

bool solve(int i, int m) {
	if (m < 0)
		return false;
	if (memo[i][m] == 0)
		return false;
	if (memo[i][m] == 1)
		return true;
	bool res = solve(i+1, m) || solve(i+1, m-A[i]);
	if (res)
		memo[i][m] = 1;
	else
		memo[i][m] = 0;
	return res;
}

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

	init();
	for (int i = 0; i < q; i++) {
		if (solve(0, M[i]))
			cout << "yes" << endl;
		else
			cout << "no" << endl;
	}
}



Measured memory_bytes: 3288
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部定数
#define D_ON			1										// 汎用フラグ - ON
#define D_OFF			0										// 汎用フラグ - OFF

// 内部変数
static FILE *szpFpI;											// 入力

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpA;
#endif

// 改行カット
// 戻り値：文字数
int
fCutCrLf(
	char *pcpStr				// <I> 文字列
)
{
	int i;

	for (i = 0; pcpStr[i] != '\0'; i++) {
		if (pcpStr[i] == '\n') {
			pcpStr[i] = '\0';
			break;
		}
	}

	return i;
}

// 判定 - １文字
int
fJudgeOne(
	char *pcpStr				// <I> 文字列
	, char pcChar				// <I> 指定文字
	, int *pipPos				// <IO> 位置
	, int piA					// <I> Aの可・不可
)
{
	// 指定文字チェック
	if (pcpStr[*pipPos] == pcChar) {
		(*pipPos)++;
		return 0;
	}

	// Aの可
	if (piA == D_ON) {
		if (pcpStr[*pipPos] == 'A') {
			(*pipPos)++;
			return fJudgeOne(pcpStr, pcChar, pipPos, D_OFF);
		}
	}

	return -1;
}

// 判定
int
fJudge(
	char *pcpStr				// <I> 文字列
)
{
	int liRet;

	// 改行カット
	fCutCrLf(pcpStr);

	// 各文字チェック
	int liPos = 0;
	liRet = fJudgeOne(pcpStr, 'K', &liPos, D_ON);
	if (liRet != 0) {
		return -1;
	}
	liRet = fJudgeOne(pcpStr, 'I', &liPos, D_OFF);
	if (liRet != 0) {
		return -1;
	}
	liRet = fJudgeOne(pcpStr, 'H', &liPos, D_OFF);
	if (liRet != 0) {
		return -1;
	}
	liRet = fJudgeOne(pcpStr, 'B', &liPos, D_ON);
	if (liRet != 0) {
		return -1;
	}
	liRet = fJudgeOne(pcpStr, 'R', &liPos, D_ON);
	if (liRet != 0) {
		return -1;
	}
	liRet = fJudgeOne(pcpStr, '\0', &liPos, D_ON);
	if (liRet != 0) {
		return -1;
	}

	return 0;
}

// 実行メイン
int
fMain(
	int piTNo					// <I> テスト番号 1～
)
{
	char lc1Buf[1024], lc1Out[1024];

	// データ - 初期化

	// 入力 - セット
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", piTNo);
	szpFpI = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", piTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#else
	szpFpI = stdin;
#endif

	// 文字列 - 取得
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);

	// 判定
	int liRet = fJudge(lc1Buf);

	// 結果 - セット
	if (liRet == 0) {
		sprintf(lc1Out, "YES\n");
	}
	else {
		sprintf(lc1Out, "NO\n");
	}

	// 結果 - 表示
#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, lc1Out)) {
		siRes = -1;
	}
#else
	printf("%s", lc1Out);
#endif

	// 残データ有無
#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, "")) {
		siRes = -1;
	}
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpI);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", piTNo);
	}
	else {
		printf("NG %d\n", piTNo);
	}
#endif

	return 0;
}

int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		fMain(i);
	}
#else
	fMain(0);
#endif

	return 0;
}



Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const signed INF_=1001001001; const ll INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct{template<class T> operator T(){T x;cin>>x;return x;}} IN;
struct before_main_function {
    before_main_function() {
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
        #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

int cnt[1001][1001][2];
signed main() {
    int N=IN,K=IN;
    vector<int> x(N),y(N);
    vector<char> c(N);
    REP(i,N) {
        cin>>x[i]>>y[i]>>c[i];
        int X=x[i]/K;
        int Y=y[i]/K;
        int col=(c[i]=='B');
        if((X+Y)%2==1) {  // 逆
            cnt[y[i]%K][x[i]%K][col^1]++;
        } else {
            cnt[y[i]%K][x[i]%K][col]++;
        }
    }
    REP(i,K) {
        REPF(j,1,K) {
            cnt[i][j][0]+=cnt[i][j-1][0];
            cnt[i][j][1]+=cnt[i][j-1][1];
        }
    }
    REP(i,K) {
        REPF(j,1,K) {
            cnt[j][i][0]+=cnt[j-1][i][0];
            cnt[j][i][1]+=cnt[j-1][i][1];
        }
    }

    int ans=0;
    REP(i,K) {
        REP(j,K) {
            REP(k,2) {
                int b=cnt[K-1][K-1][k];
                if(i>0) b-=cnt[i-1][K-1][k];
                if(j>0) b-=cnt[K-1][j-1][k];
                if(i>0 && j>0) b+=cnt[i-1][j-1][k]*2;
                int w=0;
                if(i>0) w+=cnt[i-1][K-1][k^1];
                if(j>0) w+=cnt[K-1][j-1][k^1];
                if(i>0 && j>0) w-=cnt[i-1][j-1][k^1]*2;
                chmax(ans,b+w);
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}


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

typedef long long ll;

const int N = 13;
int n, m, x;
int C[N];
int A[N][N];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n >> m >> x;
    for (int i = 0; i < n; ++i) {
        cin >> C[i];
        for (int j = 0; j < m; ++j) {
            cin >> A[i][j];
        }
    }
    int res = INT_MAX;
    for (int i = 0; i < (1 << n); ++i) {
        int l[m];
        memset(l, 0, sizeof l);
        int sum = 0;
        for (int j = 0; j < n; ++j) {
            if (i & (1 << j)) {
                sum += C[j];
                for (int k = 0; k < m; ++k) {
                    l[k] += A[j][k];
                }
            }
        }
        bool ok = true;
        for (int j = 0; j < m; ++j) {
            if (l[j] < x) {
                ok = false;
                break;
            }
        }
        if (ok)
            res = min(res, sum);
    }
    if (res == INT_MAX) {
        cout << -1 << endl;
    } else {
        cout << res << endl;
    }

    return 0;
}



Measured memory_bytes: 3624
n,d=map(int,input().split())
x=[0 for i in range(n)]
y=[0 for i in range(n)]
count=0
for i in range(n):
  x[i],y[i]=map(int,input().split())
  if x[i]**2+y[i]**2<=d**2:
    count+=1
print(count)

Measured memory_bytes: 24616
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using static Scanner;
using static System.Math;

class Program
{
    static void Main(string[] args) {
        var writer = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
        Console.SetOut(writer);
        Solve();
        Console.Out.Flush();
    }
    static void Solve() {
        var S = Scan().AsSpan();
        var list = new List<string>();
        while (S.IndexOf("><", StringComparison.Ordinal) != -1) {
            list.Add(S.Slice(0, S.IndexOf("><") + 1).ToString());
            S = S[(S.IndexOf("><") + 1)..];
        }
        list.Add(S.ToString());
        long answer = 0;
        foreach (var str in list) {
            long lt = str.Length - str.Replace("<", "").Length;
            long gt = str.Length - str.Replace(">", "").Length;
            var max = Max(lt, gt);
            answer += max + lt * (lt - 1) / 2 + gt * (gt - 1) / 2;
        }
        Console.WriteLine(answer);
    }
}

public static class Scanner
{
    static readonly Stream stdin = Console.OpenStandardInput();
    static readonly byte[] buffer = new byte[1024];
    static int length, p;
    static bool isEof;
    private static byte StdIn() {
        if (isEof) return 0;
        if (p < length) return buffer[p++];
        p = 0;
        if ((length = stdin.Read(buffer, 0, 1024)) > 0) return buffer[p++];
        isEof = true;
        return 0;
    }
    public static char GetChar() {
        var by = StdIn();
        while ((by < '!' || '~' < by) && !isEof) by = StdIn();
        return (char) by;
    }
    public static string Scan() {
        var sb = new StringBuilder();
        for (var ch = GetChar(); '!' <= ch && ch <= '~'; ch = (char) StdIn()) {
            sb.Append(ch);
        }
        return sb.ToString();
    }
}

Measured memory_bytes: 38944
def resolve():
    '''
    code here
    '''
    N = int(input())
    chp = [[int(item) for item in input().split()] for _ in range(N)]

    def root_chk(a, b):

        delta_t = b[0] - a[0]
        shortest_path = abs(a[1] - b[1]) + abs(a[2] - b[2])

        if shortest_path > delta_t:
            return False

        elif (delta_t - shortest_path) % 2 == 1:
            return False
        else:
            return True
    


    for i in range(N):

        if i == 0:
            # print(root_chk([0,0,0], chp[0]))
            if root_chk([0,0,0], chp[0]):
                pass
            else:
                print('No')
                break
        else:
            # print(root_chk(chp[i-1], chp[i]))
            if root_chk(chp[i-1], chp[i]):
                pass
            else:
                print('No')
                break
    else:
        print('Yes')


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 21108