akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
class Main
{
    public static void main (String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] b = new int[m];
        Map<Integer, Integer> map = new HashMap<>();
        for(int i = 0; i < m; i++){
            int x = sc.nextInt() - 1;
            b[i] = sc.nextInt() - 1;
            if(map.containsKey(b[i])){
                x = Math.max(x, map.get(b[i]));
            }
            map.put(b[i], x);
        }
        Arrays.sort(b);
        int[] a = new int[m];
        for(int i = 0; i < m; i++){
            a[i] = map.get(b[i]);
        }
        int ans = 0;
        int index = 0, tmp;
        while(index < m){
            ans++;
            tmp = b[index];
            while(index < m && a[index] < tmp){
                index++;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 96268
#include <bits/stdc++.h>
using namespace std;
int gcd(int a,int b){
  if(b<a)
    swap(a,b);
  int r = b % a;
  while(r!=0){
  b = a;
  a = r;
  r = b % a;
  }
  return a;
}
int main() {
  int N;
  cin >> N;
  int a[N];
  cin >> a[0];
  int c = a[0];
  for(int i=1;i<N;i++){
    cin >> a[i];
    c = gcd(c,a[i]);
  }
  cout << c << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctype.h>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <queue>
#define  N  1000011 
using namespace std;

int main()
{
	int a , b; 
	while (~scanf ("%d%d",&a,&b))
	{
		int c = a + b;
		bool flag = false;
		
		if (a%3==0 && a!=0)  flag = true;
		if (b%3==0 && b!=0)  flag = true;
		if (c%3==0 && c!=0)  flag = true;
		
		if (flag)  cout << "Possible" << endl;
		else   cout << "Impossible" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <math.h>
#include <string.h>
#include <iomanip>
#include <numeric>
#include <cstdlib>
#include <cstdint>
#include <cmath>
#include <functional>
#include <limits>
#include <cassert>

using namespace std;

/* template */

using ll = long long;

void debug_out() { std::cout << std::endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cout << "debug: "; debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif

#define rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define rrep(i, a, n) for (int i = ((int)(n-1)); i >= (int)(a); i--)
#define Rep(i, a, n) for (long long i = (long long)(a); i< (long long)(n); i++)
#define RRep(i, a, n) for (long long i = ((long long)(n-1ll)); i>=(long long)(a); i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()

template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}

struct Edge{
    int to;
    ll weight;
    Edge(int t, ll w) : to(t), weight(w){ }
};

struct edge{
    int from;
    int to;
    ll weight;
    edge(int f,int t,ll w) : from(f), to(t), weight(w){ }
};


using Graph = vector<vector<Edge>>;
using graph = vector<vector<int>>;
using edges = vector<edge>;

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

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

constexpr ll LNF = 1ll<<60;

constexpr int INF = 1e9+7;

vector<int> dx = {-1,0,1,0,-1,1,-1,1};
vector<int> dy = {0,-1,0,1,1,-1,-1,1};

/* template */

int solve(){
    ll n,a,b,c,d; cin >> n >> a >> b >> c >> d;
    map<ll,ll> m;
    auto dfs = [&](ll here, auto &dfs)->ll{
        if(m[here]!=0) return m[here];
        if(here<=0) return 0;
        if(here==1){
            m[here] = d;
            return d;
        }
        ll t = LNF;
        if(here<LNF/d) t = here*d;
        chmin(t,a+d*(here%2ll)+dfs(here/2ll,dfs));
        if(here%2==1){
            chmin(t,a+d+dfs((here+1ll)/2ll,dfs));
        }
        chmin(t,b+d*(here%3ll)+dfs(here/3ll,dfs));
        if(here%3!=0){
            chmin(t,b+d*(3ll-here%3ll)+dfs((here+2ll)/3ll,dfs));
        }
        chmin(t,c+d*(here%5ll)+dfs(here/5ll,dfs));
        if(here%5!=0){
            chmin(t,c+d*(5ll-here%5ll)+dfs((here+4ll)/5ll,dfs));
        }
        m[here] = t;
        return t;
    };
    dfs(n,dfs);
    cout << m[n] << endl;
    return 0;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int t; cin >> t;
    rep(_,0,t){
        solve();
    }
}

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

int main() {
  int n,m;
  cin >> n >> m;
  if (n == m) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

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

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair
#define F first
#define S second

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 (b<a) { a=b; return 1; } return 0; }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


f64 L;


int main() {
    cin >> L;

    f64 ans = (L / 3.0) * (L / 3.0) * (L / 3.0);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
struct I{
    I(){
	ios::sync_with_stdio(false);cin.tie(0);
	cout<<fixed;
	cout<<setprecision(10);
    }
}init;

typedef long long LL;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
typedef tuple<int,int> P;
typedef vector<P> VP;
typedef vector<VP> VVP;
#define rep(i,n) for(auto i=(n)*0;i<n;i++)
#define range(i,n) for(auto &i:n)
#define OK 1
#define NG -1


int dfs(int v,V pos,VV& c,VV& dp,V& m,const int n,const int d){
    int now=pos[v];
    if(dp[v][now]!=0)return dp[v][now];
    rep(k,n){
	if(v!=k){
	    while(pos[k]+1<m[k]&&c[k][pos[k]+1]-c[v][now]<=d)
		pos[k]++;
	    if(c[v][now]>c[k][pos[k]]||c[k][pos[k]]-c[v][now]>d)
		return dp[v][now]=NG;
	}
    }
    if(now==m[v]-1){
	rep(k,n){
	    if(pos[k]!=m[k]-1)return dp[v][now]=NG;
	}
	return dp[v][now]=OK;
    }
    else{
	pos[v]++;
	int bottom=c[0][pos[0]];
	rep(k,n)bottom=min(bottom,c[k][pos[k]]);
	if(c[v][pos[v]]-bottom>d)return dp[v][now]=NG;
	rep(k,n)
	    if(c[k][pos[k]]==bottom)
		if(dfs(k,pos,c,dp,m,n,d)==OK)
		    return dp[v][now]=OK;
    }
    return dp[v][now]=NG;
}
int main(){
    for(int n,d;cin>>n>>d,n+d;){
	VV c(n),dp(n);
	V m(n);
	rep(i,n){
	    cin>>m[i];
	    m[i]++;
	    c[i].resize(m[i]);
	    dp[i].resize(m[i]);
	    c[i][0]=dp[i][0]=0;
	    rep(j,m[i]-1){
		cin>>c[i][j+1];
		c[i][j+1]+=c[i][j];
		dp[i][j+1]=0;
	    }
	}

	auto check=[&](){
	    rep(i,n){
		vector<int> pos(n,0);
		if(dfs(i,pos,c,dp,m,n,d)==OK)return true;
	    }
	    return false;
	}();
	if(check) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 5796
package main

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

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

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	s := scanString()
	t := scanString()

	n := (len(t) + len(s) - 1) / len(s)
	ss := strings.Repeat(s, n+1)

	zarr := Zalgorithm(t + "#" + ss)
	zarr = zarr[len(t)+1:][:len(s)]

	for i := 0; i < len(s); i++ {
		zarr[i] = zarr[i] / len(t)
		if zarr[i] != 0 {
			zarr[i] = 1
		}
	}

	cnt := 0
	done := make([]int, len(s))
	memo := make([]int, len(s))
	var dfs func(to int) int
	dfs = func(to int) int {
		if cnt == done[to] {
			return -1
		}

		if zarr[to] == 0 {
			return 0
		}

		done[to] = cnt
		if memo[to] == 0 {
			memo[to] = dfs((to + len(t)) % len(s))
			if memo[to] != -1 {
				memo[to]++
			}
		}
		return memo[to]
	}

	ans := 0
	for i := 0; i < len(s); i++ {
		if zarr[i] == 0 {
			continue
		}
		cnt++
		t := dfs(i)
		if t == -1 {
			fmt.Fprintln(wr, -1)
			return
		}
		ans = max(ans, t)
	}

	fmt.Fprintln(wr, ans)

}

// Zalgorithm function
func Zalgorithm(s string) []int {
	n := len(s)
	res := make([]int, n)
	i, j := 1, 0
	for i < n {
		for i+j < n && s[j] == s[i+j] {
			j++
		}
		res[i] = j
		if j == 0 {
			i++
			continue
		}
		k := 1
		for i+k < n && k+res[k] < j {
			res[i+k] = res[k]
			k++
		}
		i += k
		j -= k
	}
	return res
}


Measured memory_bytes: 137088
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <bitset>
#include <iomanip>
#include <deque>
#include <tuple>
#include <algorithm>

using namespace std;

int main()
{
    int a, b;

    cin >> a >> b;
    if (a == 1) a += 13;
    if (b == 1) b += 13;

    if (a > b) {
        cout << "Alice" << endl;
    }
    else if (a < b) {
        cout << "Bob" << endl;
    }
    else {
        cout << "Draw" << endl;
    }
}


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

using namespace std;

int main()
{
    int a,d,mp=0,mi=0;
    map<int,int> b;
    vector<int>c;

    cin>>a;
    for(int i=0;i<a;i++)
    {
        cin>>d;
        c.push_back(d);
        b[d]=i;
    }

    sort(c.begin(),c.end());
    for(int i=0;i<a;i++)
    {
        d=b[c[i]];
        if((abs(d-i))%2!=0)
        {
            if(d%2==0)mp++;
            else mi++;
        }


    }

    cout<<max(mp,mi)<<"\n";

    return 0;
}


Measured memory_bytes: 5368
#include<iostream>
using namespace std;
int main(){
  int n;cin>>n;
  int ki=0;
  for(int i=0;i<n;i++){
    int a;cin>>a;
    ki+=a%2;
  }
  if(ki%2)cout<<"NO"<<endl;
  else cout<<"YES"<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main(){
string S; 
cin >> S;
string T = S; 
string ans = "YES"; 
while(T.size() > 0){
if(S.size() > 5 && S.substr(S.size() - 5) == "dream"){
T = S.substr(0, S.size() - 5); 
}
else if(S.size() > 7 && S.substr(S.size() - 7) == "dreamer"){
T = S.substr(0, S.size() - 7); 
}
else if(S.size() > 5 && S.substr(S.size() - 5) == "erase"){
T = S.substr(0, S.size() - 5); 
}
else if(S.size() > 6 && S.substr(S.size() - 6) == "eraser"){
T = S.substr(0, S.size() - 6); 
}
else if(S == "dream" || S == "dreamer" || S == "erase" || S == "eraser"  || S == ""){
T = ""; 
}
else{
  ans = "NO"; 
  break; 
}
  S = T; 
}
cout << ans << endl;
}

Measured memory_bytes: 512
n, m = map(int , input().split())
ans  = 1
mod = 10**9+7
for i in range(1, n+1):
	ans = (ans%mod)*(i%mod)
	ans = ans%mod
for i in range(1, m+1):
	ans = (ans%mod)*(i%mod)
	ans = ans%mod
# if the difference between them is greater than 1 they can't be arranged
if abs(n-m)>1:
	print(0)
# if they have same number they can be placed in odd position or even position independently
elif abs(n-m)==0:
	ans = ans*2
	ans = ans%mod
	print(ans)
# only one way no exchange of odd and even place 
else:
	print(ans)

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

int main(){
  string S;
  cin >> S;
  int t = 0,half;
  t = S.length();
  int c = 0;
  if(t % 2 == 0){
    half = t / 2;
  }else{
    half = t / 2;
  }
  for(int i = 0;i < half;i++){
    if(S[i] != S[t-1-i]){
      c++;
    }
  }
  cout << c;
  
}


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

#define PB push_back
#define MP make_pair
#define LL long long
#define LLU usinged long long
#define SZ(a) ((int)a.size())


using namespace std;

int main() {
	
	int N;
	scanf("%d", &N);
	
	double ans = 0.5;
	
	if(N&1) ans += 0.5/N;
	
	cout << ans << endl; 
	
	return 0;
}


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

int main(void){
  int n, a = 0;		//n:正の整数の個数	a:宣言した整数が同時に2で割れる数
  cin >> n;
  
  for( int i = 0 ; i < n ; i++ ){
    int k, w = 0;		//k:宣言する整数 w:i番まで宣言した整数が同時に2で割れる数
    cin >> k;
    while(true){
      if( k % 2 == 1)  break;
      k /= 2;
      w++;
    }
    if( i == 0 || a > w )  a = w;
  }
  cout << a << endl;
}
    

Measured memory_bytes: 3572
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007; // 998244353
using ll = long long;
using namespace std;

int main(){
	int n; cin >> n;
	if( n%1000 == 0 ) cout << 0 << endl;
	else cout << 1000-n%1000 << endl;
}

Measured memory_bytes: 3632
var c = 0;

(function(input) {
    var p = input.split('\n');
    var n = Number(p.shift());
    var A = p.shift().split(' ').map(Number);

    //var count = 0;
    //var max = -Infinity;
    //for (var i = 0; i < A.length; i++) {
    //    max = Math.max(max, A[i]);
    //    if (A[i] < max) {
    //        count++;
    //    }
    //}
    mergeSort(A, 0, A.length);
    console.log(c);
    //console.log(A);
})(require('fs').readFileSync('/dev/stdin', 'utf8'));

function mergeSort(array, left, right) {
    if (left + 1 < right) {
        var mid = Math.floor((left + right) / 2);
        mergeSort(array, left, mid);
        mergeSort(array, mid, right);
        mergeSortSub(array, left, mid, right);
    }

    function mergeSortSub(array, left, mid, right) {
        var n1 = mid - left;
        var n2 = right - mid;
        var leftArray = [];
        var rightArray = [];
        for (var i = 0; i < n1; i++) {
            leftArray.push(array[left + i]);
        }
        for (var i = 0; i < n2; i++) {
            rightArray.push(array[mid + i]);
        }
        leftArray.push(Infinity);
        rightArray.push(Infinity);
        var i = j = 0;
        for (var k = left; k < right; k++) {
            if (leftArray[i] <= rightArray[j]) {
                array[k] = leftArray[i];
                i++;
            } else {
                c += (leftArray.length - 1  - i);
                array[k] = rightArray[j];
                j++;
            }
        }
        //console.log(array);
    }
}

Measured memory_bytes: 43712
N,M = map(int, input().split())
L = []
 
for i in range(1,int(M**0.5)+1):
    if M % i == 0:
        L.append(i)
        L.append(int(M / i))
L1 = [i for i in L if M / i >= N]
print(max(L1))


Measured memory_bytes: 2940
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <limits.h>
double max(double a, double b) { return a > b ? a : b; }
int main(){
    int i,k;
    double n,j,cost=0,ans=0,p[200020]={};
    scanf("%lf %d",&n,&k);
    for(i=1; i<=n; i++){
        scanf("%lf",&p[i]);
    }
    for(i=1; i<=k; i++){
        cost+=(p[i]+1)/2;
    }
    ans=cost;
    for(i=1; i<=n-k; i++){
        cost=cost-(p[i]+1)/2+(p[i+k]+1)/2;
        ans=max(cost,ans);
    }
    printf("%lf",ans);
    return 0;
}

Measured memory_bytes: 1664
h,w = gets.chomp.split(" ").map(&:to_i)

#arr = [Array.new(w+2, -1)]
arr = []
keys = []
count = 0
result = 0
h.times do |h_i|
  tmp_arr = []
  str = gets.chomp
  w.times do |w_i|
    if str[w_i] == "#" then
      keys << [h_i, w_i]
      count += 1
      tmp_arr << 1
    else
      tmp_arr << 0
    end
  end
  arr << tmp_arr
  #arr << [-1] + tmp_arr + [-1]
end
#arr << [Array.new(w+2, -1)]

while count < h * w do
  tmp_keys = keys
  keys = []
  result += 1
  tmp_keys.each do |(h_i, w_i)|
    if h_i - 1 >= 0 && arr[h_i - 1][w_i] == 0 then
      keys << [h_i - 1, w_i]
      arr[h_i - 1][w_i] = 1
      count += 1
    end
    if h_i + 1 < h && arr[h_i + 1][w_i] == 0 then
      keys << [h_i + 1, w_i]
      arr[h_i + 1][w_i] = 1
      count += 1
    end
    if w_i - 1 >= 0 && arr[h_i][w_i - 1] == 0 then
      keys << [h_i, w_i - 1]
      arr[h_i][w_i - 1] = 1
      count += 1
    end
    if w_i + 1 < w && arr[h_i][w_i + 1] == 0 then
      keys << [h_i, w_i + 1]
      arr[h_i][w_i + 1] = 1
      count += 1
    end
  end
end

puts result


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

#define int long long
#define itn int
#define For(i, a, b) for (int i = (a); i <= static_cast<int>(b); i++)
#define Forr(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) For(i, 0, n - 1)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'
#define dump2(x, y) \
    cerr << #x << " = " << (x) << " " << #y << " = " << (y) << '\n'
#define SZ(x) ((int)(x).size())
#define bit(n) (1LL << (n))
constexpr int MOD = 1e9 + 7;

template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = LLONG_MAX / 2;
using P = pair<int, int>;
using vec = vector<int>;
template <typename T>
using mat = vector<vector<T>>;

// clang-format off
template <typename T1, typename T2>
ostream& operator<<(ostream& stream, const pair<T1, T2>& p) { return stream << p.first << "," << p.second; }
template <typename T>
void print(const vector<T> vec) { rep (i, vec.size() - 1) cout << vec[i] << ' '; cout << vec[vec.size() - 1] << '\n'; }
template <typename Arg>
void print(const Arg arg) { cout << arg << '\n'; }
template <typename Head, typename... Args>
void print(const Head head, const Args... args) { cout << head << " "; print(args...); }
template <typename T, typename U>
void init(vector<T>& v, vector<U>& w) { rep (i, v.size()) cin >> v[i] >> w[i]; }
template <typename T>
void init(vector<T>& v) { rep (i, v.size()) cin >> v[i]; }
template <typename T>
T sum_(vector<T> vec, T init = 0) { return std::accumulate(all(vec), T(init)); }
template<typename T>
bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template<typename T>
bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template <typename T>
int index(const T& vec, const typename T::iterator it) { return distance(vec.begin(), it); }
template <typename T = int>
mat<T> mmat(int n, int m=0) { return mat<T>(n, vector<T>(m)); }
template <typename T = int>
vector<T> ivec(int n) { vector<T> v(n); init(v); return v; }
// clang-format on

void yn(bool tf) { print(tf ? "Yes" : "No"); }
void YN(bool tf) { print(tf ? "YES" : "NO"); }

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
// -------------------------------------------------------------------
// sort 1 2 3 4
// pqr 1 2 3 must impl >

signed main() {
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int n = s.length();

    mat<int> dp = mmat(n, 3);
    dp[0][1] = 1;
    For(i, 1, n - 1) {
        if (s[i] == s[i - 1])
            dp[i][1] = dp[i - 1][2] + 1;
        else
            dp[i][1] = max(dp[i - 1][1], dp[i - 1][2]) + 1;

        if (i == 1)
            dp[i][2] = 1;
        else if (s[i] == s[i - 2] and s[i - 1] == s[i - 3])
            dp[i][2] = dp[i - 2][1] + 1;
        else
            dp[i][2] = max(dp[i - 2][1], dp[i - 2][2]) + 1;
    }
    print(max(dp[n - 1][1], dp[n - 1][2]));

    return 0;
}


Measured memory_bytes: 11540
#include <bits/stdc++.h>
#define llint long long int
#define ldouble long double

using namespace std;

int main() {
    int N;
    cin>>N;
    vector<int> a(N+1);
    for(int i=1;i<=N;i++){
        cin>>a.at(i);
    }

    int sum=0;

    for(int i=1;i<=N;i++){
        int love=a.at(i);
            if(a.at(love)==i){
                sum++;
                a.at(love)=0;
            }
    }

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

Measured memory_bytes: 640
#include <cstdio>

int n,k,a[300005];

int main()
{
    scanf("%d%d",&k,&n);
    if(k&1)
    {
        for(int i=1;i<=n;++i)a[i]=(k+1)>>1;
        int t=n,x=n>>1;
        while(x--)
            if(a[t]==1)a[t--]=k;
            else --a[t],t=n;
        for(int i=1;i<=t;++i)printf("%d%c",a[i],i==t?'\n':' ');
    }
    else for(int i=1;i<=n;++i)printf("%d%c",i==1?k>>1:k,i==n?'\n':' ');
    return 0;
}

Measured memory_bytes: 3328
from itertools import *

h,w,k = map(int,input().split())
maps = [list(input()) for _ in range(h)]
seqw = [ i for i in range(w)]
seqh = [ i for i in range(h)]
ind = []
cnt = 0
for y in range(h):
    for x in range(w):
        if maps[y][x] == "#":
            ind.append((x,y)) 

from itertools import *

chosew = []
for i in range(2 ** w):
    bit_set = []
    for j in range(w):
        if ((i >> j) & 1):
            bit_set.append(seqw[j])
    chosew.append(bit_set)
#print(chosew)

choseh = []
for i in range(2 ** h):
    bit_set = []
    for j in range(h):
        if ((i >> j) & 1):
            bit_set.append(seqh[j])
    choseh.append(bit_set)
#print(choseh)

p = list(product(chosew, choseh))

ans = 0
for cw,ch in p:
    tmp = []
    for x,y in ind:
        if x not in cw and y not in ch:
            tmp.append((x,y))
    if len(tmp) == k:
        ans += 1
print(ans)

Measured memory_bytes: 9328
N, Q = map(int, input().split())
order_dict = {}
ans = [0]*N

for i in range(N):
    if i != 0:
        a, b = map(int, input().split())
        if not a in order_dict:
            order_dict[a] = set()
        order_dict[a].add(b)
    

for i in range(Q):
    p, x = map(int, input().split())
    ans[p-1] += x

for a in range(N+1):
    if a in order_dict:
        for b in order_dict[a]:
            ans[b-1] += ans[a-1]


print(' '.join(map(str, ans)))

Measured memory_bytes: 98264
#include <iostream>
#include <algorithm>
#include <string.h>

using namespace std;
const int maxn = 100;
const int maxm = 1e5+10;
const int INF = 0x3f3f3f3f;
typedef long long LL;
int n,W,V;
LL f[maxm];
int w[maxn];
int v[maxn];
//f[i][j] = f[i-1][j-w[i]] + v[i]
int main()
{

	memset(f, INF, sizeof(f));
	scanf("%d%d", &n, &W);
	for(int i = 0; i < n; i++)
		{
			scanf("%d%d", &w[i], &v[i]);
			V += v[i];
		}
	f[0] = 0;
	for(int i = 0; i < n; i++)
		for(int j = V; j >= v[i]; j--)
				f[j] = min(f[j], f[j-v[i]] + w[i]);
	int res = 0;
	for(int j = V; j >= 0; j--)
		if(f[j] <= W)
		{
			res = j;
			break;
		}
	printf("%d\n", res);
	return 0;
}


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

// template {{{
/* vim: set foldmethod=marker: */

// constant
const int INF = (int)1e9;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-14;

// typedef
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;

// repetition
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define RFOR(i, a, b) for (int i = (int)(b) - 1; i >= (int)(a); i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define REPit(type, i, obj) for (type::iterator i = (obj).begin(); i != (obj).end(); i++)
#define RREPit(type, i, obj) for (type::iterator i = (obj).rbegin(); i != (obj).rend(); i++)

// short
#define pb push_back
#define mp make_pair
#define fst first
#define sec second

// input
template <class T = int> inline T in(){ T x; cin >> x; return x; }
template <class T = int> inline vector<T> in(int n){ vector<T> v; v.reserve(n); REP(i, n) v.pb(in<T>()); return v; }
template <class T = int> inline void in(T* x, int n){ REP(i, n) x[i] = in<T>(); }
#define inl in<ll>
#define ind in<double>

// container util
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define sz(obj) obj.size()
#define sza(ary) (sizeof(ary) / sizeof(*ary))
#define sort(obj) sort(all(obj))
#define exist(obj, key) ((obj).find(key) != (obj).end())
#define clear(ary) memset((ary), 0, sizeof(ary))

// print util
#define print(x) cout << (x) << endl
#define printd(x, d) cout << fixed << setprecision(d) << (x) << endl
template <class T> inline void printv(vector<T>& v, int n = -1){ n = ~n ? n : sz(v); REP(i, n) cout << v[i] << "\n "[i < n - 1]; }
template <class T> inline void printa(T* ary, int n){ REP(i, n) cout << ary[i] << "\n "[i < n - 1]; }
#define dump(x) cerr << #x << ": " << (x) << endl
#define debug(x) cerr << #x << ": " << (x) << " (" << __LINE__ << ")" << endl

//template }}}

signed main()
{
    int a = in(), b = in();

    if (a <= 0 and 0 <= b) puts("Zero");
    else {
        int minus = max(0, min(b + 1, 0) - a);
        puts(minus % 2 ? "Negative" : "Positive");
    }

    return 0;
}


Measured memory_bytes: 256
package main

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

func main() {
        fmt.Println(run(os.Stdin))
}

func run(in io.Reader) int {
        sc := bufio.NewScanner(in)

        sc.Scan()
        n, err := strconv.Atoi(sc.Text())
        if err != nil {
                panic(err)
        }

        r := make([]int, n)

        for i := 0; i < n; i++ {
                sc.Scan()
                v, err := strconv.Atoi(sc.Text())
                if err != nil {
                        panic(err)
                }
                r[i] = v
        }

        return maximumProfit(n, r)
}

func maximumProfit(n int, r []int) int {
        maxProf := math.MinInt32
        minv := r[0]

        for i := 1; i < n; i++ {
                maxProf = max(maxProf, r[i]-minv)
                minv = min(minv, r[i])
        }

        return maxProf
}

func min(a, b int) int {
        if a < b {
                return a
        } else {
                return b
        }
}

func max(a, b int) int {
        if a > b {
                return a
        } else {
                return b
        }
}



Measured memory_bytes: 5364
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1 << 28;
//cout << fixed << std::setprecision(9)
//memset(a, 0, sizeof(a));
//--------------------------

const int MAX = 100;
const int WHITE = 0;
const int GRAY = 1;
const int BLACK = 2;
int n, M[MAX][MAX];

int dijkstra()
{
	int minv;
	int d[MAX];
	int color[MAX];

	for (int i = 0; i < n; i++) {
		d[i] = INF;
		color[i] = WHITE;
	}

	d[0] = 0;
	color[0] = GRAY;

	while (1) {
		minv = INF;
		int u = -1;
		for (int i = 0; i < n; i++) {
			if (minv > d[i] && color[i] != BLACK) {
				u = i;
				minv = d[i];
			}
		}

		if (u == -1) break;
		color[u] = BLACK;
		for (int v = 0; v < n; v++) {
			if (M[u][v] != INF && color[v] != BLACK) {
				if (d[v] > d[u] + M[u][v]) {
					d[v] = d[u] + M[u][v];
					color[v] = GRAY;
				}
			}
		}
	}

	for (int i = 0; i < n; i++) {
		cout << i << " " << (d[i] == INF ? -1 : d[i]) << endl;
	}

	return 0;
}

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

	int k, c, u, v;
	for (int i = 0; i < n; i++) {
		cin >> u >> k;
		for (int j = 0; j < k; j++) {
			cin >> v >> c;
			M[u][v] = c;
		}
	}

	dijkstra();

	return 0;
}

Measured memory_bytes: 1200
/******************************************
* AUTHOR : RAJAGOPALAN *
* NICK : ARNO *
* INSTITUTION : VIT *
******************************************/
#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define alli(a, n, k) (a+k),(a+n+k)
#define FP(i, a, b, k) for(__typeof(a) i = a;i < b;i += k)
#define FS(i, a, b, k) for(__typeof(a) i = a;i > b;i -= k)
#define IT(it, a) for(__typeof(a.begin()) it = a.begin();it != a.end(); ++it)
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define eps 1e-6
#define pi 3.141592653589793
using namespace std;
using namespace __gnu_pbds;

template<class T> inline T gcd(T x, T y) { if (!y) return x; return gcd(y, x%y);}
typedef vector<int> VII;
typedef vector<ll> VLL;
typedef pair<int, int> PII;
typedef vector< pair<int, int> > VPII;
typedef vector< pair<int, PII > > VPPI;
const int MOD = 1e9 + 7;
const int INF = 1e9;

inline ll modulo(ll a, ll m)
{
    return (a % m + m) % m;
}

inline ll modInverse(ll a, ll m)
{
    assert(__gcd(a, m) == 1);
    ll m0 = m;
    ll y = 0, x = 1;

    if (m == 1)
        return 0;

    while (a > 1)
    {
        ll q = a / m;
        ll t = m;

        m = a % m, a = t;
        t = y;

        y = x - q * y;
        x = t;
    }

    if (x < 0)
        x += m0;

    return x;
}

inline ll modPow(ll x, ll y, ll m)
{ //x^y % m
    if (y == 0)
        return 1LL;
    else if (y == 1)
        return x;
    else
    {
        ll ans = modPow(x, y / 2, m) % m;
        if (y & 1)
        {
            return (((ans * ans) % m) * x) % m;
        }
        else
        {
            return (ans * ans) % m;
        }
    }
}

int main(int argc, char* argv[])
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin>>s;
    bool wn=true;
    for(int i=1;i<=s.size() && wn;++i)
    {
        if(i%2==0 && s[i-1]=='R')
        wn=false;
        if(i%2!=0 && s[i-1]=='L')
        wn=false;

    }
    if(wn)
    cout<<"Yes";
    else cout<<"No";
    return 0;
}

Measured memory_bytes: 256
use proconio::input;
use proconio::fastout;

#[fastout]
fn main(){

    input!{
        n: usize,
        x: usize,
        t: usize,
    }

    let ans = if n%x == 0 {
       n/x
    }else{
         n / x + 1
    };

    println!("{}",ans*t);


}

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

struct UnionFind{
    int num;
    vector<int> par,rank;
    UnionFind(int n):num(n),par(n),rank(n,1){
        iota(par.begin(),par.end(),0);
    }
    int root(int x){
        if (par[x]==x) return x;
        return par[x]=root(par[x]);
    }
    bool merge(int x, int y){
        x=root(x),y=root(y);
        if (x==y) return false;
        if (rank[x]<rank[y]) swap(x,y);
        par[y]=x;
        rank[x]+=rank[y];
        --num;
        return true;
    }
    bool same(int x, int y){
        return root(x)==root(y);
    }
    int size(int x){
        return rank[root(x)];
    }
    int count(){
        return num;
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,H,W; cin >> N >> H >> W;
    UnionFind uf(H+W);
    struct edge{
        int r,c,a;
        edge(int r,int c,int a):r(r),c(c),a(a){}
        const bool operator<(const edge &rhs){
            return a>rhs.a;
        }
    };
    vector<edge> es;
    for (int i=0;i<N;++i){
        int R,C,A; cin >> R >> C >> A;
        es.emplace_back(--R,--C+H,A);
    }
    sort(es.begin(),es.end());
    vector<int> cycle(H+W,0);
    ll ans=0;
    for (int i=0;i<N;++i){
        int p=uf.root(es[i].r),q=uf.root(es[i].c);
        if (uf.merge(es[i].r,es[i].c)&&!(cycle[p]&&cycle[q])){
            ans+=es[i].a;
            cycle[p]|=cycle[q],cycle[q]|=cycle[p];
        } else if (!cycle[p]){
            ans+=es[i].a; cycle[p]=1;
        }
    }
    cout << ans << '\n';
}

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

a1, a2, a3 = [int(i) for i in input().split()]
if a1 + a2 + a3 >= 22:
    print('bust')
    sys.exit(0)
if a1 + a2 + a3 <= 21:
    print('win')
    sys.exit(0)


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

#define MAX_V 10000
#define INF 1e9

typedef pair<int, int> pii; // <cost, to>

int cost[MAX_V][MAX_V]; // cost[u][v]??????e=(u,v)????????????(?????¨???????????´??????INF)
bool used[MAX_V]; // ??????i???X????????????????????????
int V;

int prim() {
  for (int i = 0; i < V; ++i) {
    used[i] = false;
  }
  std::priority_queue<pii, vector<pii>, greater<pii> > que;
  que.push(pii(0, 0));
  int res = 0;

  while (!que.empty()) {
    int cst = que.top().first, v = que.top().second;
    que.pop();
    if (used[v])
      continue;
    used[v] = true;
    res += cst;
    for (int u = 0; u < V; u++)
      que.push(pii(cost[v][u], u));
  }

  return res;
}

int main(){
    cin >> V;
    for(int i=0;i<V;++i){
        for(int j=0;j<V;++j){
            int a;
            cin >> a;
            cost[i][j] = (a == -1 ? INF : a);
        }
    }
    cout << prim() << endl;

    return 0;
}


Measured memory_bytes: 3576
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}




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

int a,p;
cin >> a >> p;
cout << (a*3 + p) / 2 << endl;


return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<complex>
 
#define INF (long long)1000000000
#define MOD 1000000007
#define EPS 1e-8
 
#define REP(i, m) for(long long i = 0; i < m; ++i)
#define FOR(i, n, m) for(long long i = n; i < m; ++i)
#define ALL(v) v.begin(), v.end()
#define pb push_back
 
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;
 
int main() {
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	vector<int> im(101);
	im[a]+=1;
	im[b]-=1;
	im[c]+=1;
	im[d]-=1;
	REP(i,100) {
		im[i+1]+=im[i];
	}
	ll res = 0;
	REP(i,101) {
		if(im[i]==2) ++res;
	}
	cout<<res<<endl;
}

Measured memory_bytes: 256
class Combination:
    """
    O(n)の前計算を1回行うことで，O(1)でnCr mod mを求められる
    n_max = 10**6のとき前処理は約950ms (PyPyなら約340ms, 10**7で約1800ms)
    使用例：
    comb = Combination(1000000)
    print(comb(5, 3))  # 10
    """
    def __init__(self, n_max, mod=10**9+7):
        self.mod = mod
        self.modinv = self.make_modinv_list(n_max)
        self.fac, self.facinv = self.make_factorial_list(n_max)

    def __call__(self, n, r):
        if n < r:
            return 0
        return self.fac[n] * self.facinv[r] % self.mod * self.facinv[n-r] % self.mod

    def make_factorial_list(self, n):
        # 階乗のリストと階乗のmod逆元のリストを返す O(n)
        # self.make_modinv_list()が先に実行されている必要がある
        fac = [1]
        facinv = [1]
        for i in range(1, n+1):
            fac.append(fac[i-1] * i % self.mod)
            facinv.append(facinv[i-1] * self.modinv[i] % self.mod)
        return fac, facinv

    def make_modinv_list(self, n):
        # 0からnまでのmod逆元のリストを返す O(n)
        modinv = [0] * (n+1)
        modinv[1] = 1
        for i in range(2, n+1):
            modinv[i] = self.mod - self.mod//i * modinv[self.mod%i] % self.mod
        return modinv

def main():
    n, k = map(int,input().split())
    MOD = 10 ** 9 + 7
    comb = Combination(10 ** 6)
    ans = 0
    if n - 1 <= k:
        ans = comb(n + n - 1, n)
    else:
        ans = 1
        for i in range(1,k+1):
            ans += comb(n,i) * comb(n - 1, i)
            ans %= MOD
    
    print(ans)


    




if __name__ == "__main__":
    main()

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

int main(){

    int N;
    string S;
    string alphbt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    cin >> N;
    cin >> S;
    
    vector<string> ans(S.size());
    rep(i,S.size()){
        rep (j,26){
            if (S[i] == alphbt[j]){
                ans[i] = alphbt[(N+j)%26];
              	break;
            }
        }
    }
    
    rep (i, S.size()){
        cout << ans[i];
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 768
package main

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

var sc = bufio.NewScanner(os.Stdin)

// Road is 通路構造体
type Road struct {
	to []int
}

// Heya is 部屋構造体
type Heya struct {
	depth int
	prev  int
}

func main() {
	list := getStdinIntArr()
	N := list[0]
	M := list[1]
	road := make([]Road, N) // 通路
	heya := make([]Heya, N) // 部屋

	// 通路初期化
	for i := 0; i < N; i++ {
		road[i].to = make([]int, 0)
	}
	// 通路
	for i := 0; i < M; i++ {
		list2 := getStdinIntArr()
		A := list2[0]
		B := list2[1]
		A = A - 1 // 0スタートに直す
		B = B - 1
		road[A].to = append(road[A].to, B)
		road[B].to = append(road[B].to, A)
	}
	// 部屋初期化
	for i := 0; i < N; i++ {
		if i == 0 {
			heya[i].depth = 0
			heya[i].prev = -1
		} else {
			heya[i].depth = math.MaxInt32
			heya[i].prev = -1
		}
	}
	// 0部屋から幅優先探索する
	parent := []int{0}
	for {
		// deep copy
		parentTmp := parent[:]
		parent = parent[len(parent):]

		for _, val := range parentTmp {
			for _, to := range road[val].to {
				if heya[to].prev != -1 {
					continue
				}
				heya[to].depth = heya[val].depth + 1
				heya[to].prev = val
				parent = append(parent, to)
			}
		}

		if len(parent) == 0 {
			break
		}
	}
	// 答え出力
	fmt.Printf("Yes\n")
	for idx, val := range heya {
		if idx == 0 {
			continue
		}
		fmt.Printf("%d\n", val.prev+1) // 1スタートに戻す
	}

	fmt.Printf("\n")
}

func getStdin() string {
	sc.Scan()
	return sc.Text()
}
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
}


Measured memory_bytes: 21948
#include <stdio.h>


int main(void)
{

    int S;
    int h,m,s;
    scanf("%d",&S);

    h = S/3600;
    m = (S-h*3600)/60;
    s=S-h*3600-m*60;

    printf("%d:%d:%d\n",h,m,s);


    return 0 ;
}

Measured memory_bytes: 592
#include<stdio.h>
int main(){
  int n , i;
  scanf("%d", &n);
  for(i = 3 ; i <= n ; i++){
    if(i%3 == 0 || i%10 == 3 || i/10%10 == 3 || i/10/10%10 == 3 || i/10/10/10%10 == 3){
      printf(" %d", i);
    }
  }
  printf("\n");
  return 0;
}



Measured memory_bytes: 2052
H, W = map(int, input().split())
S = []
for _ in range(H):
    S.append(input())
cnt = [[1 for _ in range(W)] for _ in range(H)]
for h in range(H):
    ws = 0
    for w in range(W):
        if S[h][w] == "#":
            ws = 0
        else:
            cnt[h][w] += ws
            ws += 1
    ws = 0
    for w in range(W-1, -1, -1):
        if S[h][w] == "#":
            ws = 0
        else:
            cnt[h][w] += ws
            ws += 1

for w in range(W):
    hs = 0
    for h in range(H):
        if S[h][w] == "#":
            hs = 0
        else:
            cnt[h][w] += hs
            hs += 1
    hs = 0
    for h in range(H-1, -1, -1):
        if S[h][w] == "#":
            hs = 0
        else:
            cnt[h][w] += hs
            hs += 1
ans = 0
for h in range(H):
    for w in range(W):
        ans = max(ans, cnt[h][w])
print(ans)



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

typedef long long ll;
typedef pair<int, int> P;

const ll mod =  1000000007;  //出力は (ans % mod + mod) % mod  (負の剰余を正にする)
const int inf = 1e9;
const long long INF = 1LL << 60;   // INF = 1152921504606846976

int main()
{
    ll a,b; cin >> a >> b;
    ll a_sum = 0, b_sum = 0;
    a--;
    if(a % 2 == 0){
        if((a-1)/2 % 2 == 0 && a != -1){
            a_sum = 1;
        }
        a_sum ^= a;
    }else{
        if((a-1)/2 % 2 == 0){
            a_sum = 1;
        }        
    }
    if(b % 2 == 0){
        if((b-1)/2 % 2 == 0 && b != 0){
            b_sum = 1;
        }
        b_sum ^= b;
    }else{
        if((b-1)/2 % 2 == 0){
            b_sum = 1;
        }
    }
    cout << (b_sum^a_sum);
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#include <string.h>
long long int i,j;

int main(void){
    char s[10];
    scanf("%s",s);
    int a=s[0]-'0',b=s[1]-'0',c=s[2]-'0',d=s[3]-'0';
    if(a+b+c+d==7) printf("%d+%d+%d+%d=7\n",a,b,c,d);
    else if(a+b+c-d==7) printf("%d+%d+%d-%d=7\n",a,b,c,d);
    else if(a+b-c+d==7) printf("%d+%d-%d+%d=7\n",a,b,c,d);
    else if(a-b+c+d==7) printf("%d-%d+%d+%d=7\n",a,b,c,d);
    else if(a-b-c-d==7) printf("%d-%d-%d-%d=7\n",a,b,c,d);
    else if(a+b-c-d==7) printf("%d+%d-%d-%d=7\n",a,b,c,d);
    else if(a-b-c+d==7) printf("%d-%d-%d+%d=7\n",a,b,c,d);
    else if(a-b+c-d==7) printf("%d-%d+%d-%d=7\n",a,b,c,d);
    return 0;
}

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

int dp[5000][5000][2];
int main(){
	int n,m;cin>>n>>m;
	rep(i,n+1){
		if(i==0)dp[0][i][1]=1;
		else dp[0][i][0]=1;
	}
	rep(i,m)rep(j,n+1)rep(k,2){
		if(j>0){
			(dp[i+1][j-1][k||j==1]+=dp[i][j][k])%=MOD;
			(dp[i+1][j][k||j==1]+=dp[i][j][k])%=MOD;
		}
		if(j<n){
			(dp[i+1][j+1][k]+=dp[i][j][k])%=MOD;
			(dp[i+1][j][k]+=dp[i][j][k])%=MOD;
		}
	}
	int ans=0;
	rep(i,n+1)(ans+=dp[m][i][1])%=MOD;
	cout<<ans<<endl;
}

Measured memory_bytes: 118400
#include <cstdio>
#include <cstring>
#include <vector>
#include<queue>
#include <algorithm>
#define pb push_back
using namespace std;
const int P = 1000000007;
const int N = 101010;
int n,a,b,c,i;
long long jc[N],ans;
long long ksm(long long a,long long b){
	if (b==0){
		return 1;
	}
	long long ans=ksm(a,b/2);
	ans=ans*ans%P;
	if (b%2==1) ans=ans*a%P;
	return ans;
}
long long cc(int a,int b){
	return jc[b]*ksm(jc[a]*jc[b-a]%P,P-2)%P;
}
int main(){
	jc[0]=1;
	for (i=1;i<=20000;i++)
		jc[i]=(jc[i-1]*i)%P;
	scanf("%d%d%d%d",&n,&a,&b,&c);
	if (b%2==1){
		printf("0\n");
		return 0;
	}
	//printf("%lld\n",cc(2,5));
	int ds=a+b/2;
	for (i=0;i<=a;i++){
		int t=a-i;
		if (t>c) continue;
		int tt=c-t;
		for (int j=0;j*3<=tt;j++){
			long long tmp=cc(j,ds+j)*cc(i,ds)%P*cc(a-i,ds-i)%P;
			int ttt=tt-3*j;
			if ((b==0)&&(ttt)) continue;
			if (b/2-1>=0) tmp=tmp*cc(b/2-1,b/2+ttt-1)%P;
			ans=(ans+tmp)%P;
		}
	}
	printf("%lld\n",ans);
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
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 (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    string S;
    cin >>S;
    string T = S;
    ll N= S.size();
    reverse(all(T));
    if(S==T ){
       string U=S.substr(0,(N-1)/2) ;
       //cout <<U<<endl;
       T = U;
       reverse(all(T));
       if(U==T){
           U=S.substr((N+1)/2) ;
           //cout <<U<<endl;
            T = U;
            reverse(all(T));
            if(U==T){
                cout <<"Yes"<<endl;
                return 0;
            }
       }
    }
    cout << "No"<< endl;


    return 0;
    

}

Measured memory_bytes: 3588
S=input()
n=int(input())
t=0
L=""
R=""
for i in range(n):
    Q=list(input().split())
    if Q[0]=="1":
        if t==0:
            t=1
        else:
            t=0
    else:
        if int(Q[1])+t==2:
            R=R+Q[2]
        else:
            L=Q[2]+L
            
ans=L+S+R
if t==0:
    print(ans)
else:
    print(ans[::-1])

Measured memory_bytes: 4628
def func(x):
	return abs(x[0]-k[0])+abs(x[1]-k[1])


N,M=map(int,input().split())
s = []
for i in range(N):
	a,b=map(int,input().split())
	s.append((a,b))

t=[]
for i in range(M):
	a,b=map(int,input().split())
	t.append((a,b))

for k in s:
	print(1+t.index(min(t, key=func)))


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <cmath>

using namespace std;
int x, ans;
int y;
int cnt[60];

void check()
{
    if (y <= x && cnt[3] && cnt[5] && cnt[7])
    {
        ans++;
    }
}

void rec(int d)
{
    if (d == 0)
    {
        check();
        return;
    }
    cnt[3]++;
    y = 10 * y + 3;
    rec(d - 1);
    y /= 10;
    cnt[3]--;

    cnt[5]++;
    y = 10 * y + 5;
    rec(d - 1);
    y /= 10;
    cnt[5]--;

    cnt[7]++;
    y = 10 * y + 7;
    rec(d - 1);
    y /= 10;
    cnt[7]--;
}

int main()
{
    cin >> x;
    for (int i = 0; i <= 9; i++)
    {
        rec(i);
    }
    cout << ans;
}


Measured memory_bytes: 256