akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <queue>
#include <string>
using namespace std;
int main()
{
	int h,w,n;
	int sx,sy;
	int dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};
	string map[1001];
	int d[1001][1001];
	int x = 0;
	cin >> h >> w >> n;
	for(int i=0;i < h;i++)
	{
		cin >> map[i];
	}
	for(int i=0;i < h;i++)
	{
		for(int j=0;j < w;j++)
		{
			d[j][i] = -1;
			if(map[i][j] == 'S')
			{
				sx = j;
				sy = i;
			}
		}
	}
	d[sx][sy] = 0;
	for(int i=0;i<9;i++)
	{
		queue< pair<int, int> > que;
		for(int j=0;j < h;j++)
		{
			for(int k=0;k < w;k++)
			{
				d[k][j] = -1;
			}
		}
		d[sx][sy] = 0;
		que.push(make_pair(sx,sy));
		while(que.size())
		{
			pair<int, int> p = que.front();
			que.pop();
			if((map[p.second][p.first] - '0') == (i+1))
			{
				sx = p.first;
				sy = p.second;
				x+=d[sx][sy];
				break;
			}
			for(int j=0;j < 4;j++)
			{
				int nx = p.first + dx[j];
				int ny = p.second + dy[j];
				if(0 <= nx && nx < w && 0 <= ny && ny < h && map[ny][nx] != 'X' && d[nx][ny] == -1)
				{
					que.push(make_pair(nx,ny));
					d[nx][ny] = d[p.first][p.second] + 1;
				}
			}
		}
	}
	cout << x << endl;
}

Measured memory_bytes: 7956
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	vector<int> vi;
	for(int i=0;i<n;i++)
	{
		int a;
		cin>>a;
		vi.push_back(a);
	}long long sum = 0;
	for(int i=0;i<n;i++)
	{
		for(int j=i+1;j<n;j++)
		{
			sum+=vi[i]*vi[j];
		}
	}
	cout<<sum<<endl;
 } 

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val s = readLine()!!
    val s1 = s.substring(0, (s.length-1)/2)
    val s2 = s.substring((s.length+1)/2, s.length)
    println(if (solve(s) && solve(s1) && solve(s2)) "Yes" else "No")
}

fun solve(s: String): Boolean {
    return s == s.reversed()
}


Measured memory_bytes: 31848
#include<bits/stdc++.h>
#pragma GCC target ("avx2")
#pragma GCC optimization ("03")
#pragma GCC optimization ("unroll-loops")
using namespace std;

const int maxn = 200001;
const int maxe = 20;
int a[maxn],b[maxn],c,k,pa[maxn],x,y,q,sol,d,d2,mod=1000000007,j;
long long m,n;
char h;
set<int>se;
string s;
pair<int,int>p[maxn+1];
int rmq[maxn][maxe];
int st[4*maxn],la[4*maxn],ft[maxn],dt[maxn],dt2[maxn];

void build(int n){
    for(int j=1;(1<<j)<=n;j++){
        for(int i=1;i+(1<<j)-1<=n;i++){
            rmq[i][j] = min(rmq[i][j-1], rmq[i+(1<<(j-1))][j-1]);
        }
    }
}

int query(int a, int b){
    int k = 31- __builtin_clz(b-a+1);
    return min(rmq[a][k], rmq[b-(1<<k)+1][k]);
}

int fin(int i)
{
    if(pa[i]==i)return i;
    return pa[i]=fin(pa[i]);
}

int bs(int l,int r)
{

    while(l!=r)
    {
        int mi=(l+r)/2;
        if(a[mi]==x)return mi;
        if(a[mi]>x)r=mi;
        else l=mi+1;
    }
    return l;
}
void crear(int l,int r,int nod){
if(l==r)st[nod]=a[l];
else{
int mi=(l+r)/2;
crear(l,mi,2*nod);
crear(mi+1,r,2*nod+1);
st[nod]=min(st[2*nod],st[2*nod+1]);
}
}

void upd(int l,int r,int nod){
if(l>x || r<x)return;
if(la[nod]!=0){
st[nod]+=la[nod];
la[2*nod]+=la[nod];
la[2*nod+1]+=la[nod];
la[nod]=0;
}
if(l==r)st[nod]+=y;
else{
int mi=(l+r)/2;
upd(l,mi,2*nod);
upd(mi+1,r,2*nod+1);
st[nod]=min(st[2*nod],st[2*nod+1]);
}
}

int qu(int l,int r,int nod){
if(l>y || r<x)return 100001;
if(la[nod]!=0){
st[nod]+=la[nod];
la[2*nod]+=la[nod];
la[2*nod+1]+=la[nod];
la[nod]=0;
}
if(l>=x && r<=y)return st[nod];
else {
int mi=(l+r)/2;
return min(qu(l,mi,2*nod),qu(mi+1,r,2*nod+1));
}
}

void lazy(int l,int r,int nod){
if(l>y || r<x)return;
if(la[nod]!=0){
st[nod]+=la[nod];
la[2*nod]+=la[nod];
la[2*nod+1]+=la[nod];
la[nod]=0;
}
if(l>=x && r<=y){
st[nod]+=q;
if(l!=r){
la[nod*2]+=q;
la[2*nod+1]+=q;
}
}
else {
int mi=(l+r)/2;
lazy(l,mi,2*nod);
lazy(mi+1,r,2*nod+1);
st[nod]=min(st[2*nod],st[2*nod+1]);
}
}

int ftq(int n){
int c=0;
while(n){
c+=ft[n];
n-=(n&-n);
}
return c;
}

void ftupd(int x){
for(int i=x;i<=n;i+=(i&-i))
ft[i]+=y;
}

void abi(int x){
for(int i=x;i<=n;i+=(i&-i))
dt[i]+=y;
}

void abi2(int x){
for(int i=x;i<=n;i+=(i&-i))
dt2[i]+=y;
}

int q1(int n){
int c=0;
while(n){
c+=dt[n];
n-=(n&-n);
}
return c;
}

int q2(int n){
int c=0;
while(n){
c+=dt[n];
n-=(n&-n);
}
return c;
}
void ini(){
for(int i=1;i<=n;i++){
		cin>>a[i];
		y=a[i]-a[i-1];
		abi(i);
		y=a[i]-a[i-1]*i;
		abi2(i);
	}
}

/*
printf("%.2f",x);


Range Update
Update(BITree1, l, val)
Update(BITree1, r+1, -val)
UpdateBIT2(BITree2, l, val*(l-1))
UpdateBIT2(BITree2, r+1, -val*r)

Range Sum
getSum(BITTree1, k) *k) - getSum(BITTree2, k)

*/
int main(){
	ios_base::sync_with_stdio();
	cin.tie(0);
	cout.tie(0);

	cin>>n>>m;
	if(n<4)c+=4-n;
	if(m<4)c+=4-m;
	if(n==1 && m==1)c+=4;
	c*=100000;
	cout<<c;
}


Measured memory_bytes: 2304
import Data.List as L
import qualified Data.ByteString.Char8 as BC
import Data.Maybe (fromJust)

readInts2 :: IO [[Int]]
readInts2 = map (map (fst . fromJust . BC.readInt) . BC.words) . BC.lines <$> BC.getContents

isInt :: (RealFrac a) => a -> Bool
isInt x = x == fromInteger (round x)

main :: IO ()
main = do
  getLine
  xss <- readInts2
  let combi = [sqrt . fromIntegral . sum $ zipWith (\a b -> (a - b) ^ 2) x y | (x:rest) <- L.tails xss, y <- rest]
  print . length $ filter (== True) $ map isInt combi

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

constexpr int MAX_N = 8;

int N, A[3];
int l[MAX_N];

int dfs(int n, array<int, 3> a) {
  if (n == N) {
    int mp{};
    for (int i{}; i < 3; ++i) {
      if (a[i] == 0) {
        return 10000;
      }
      mp += abs(A[i] - a[i]);
    }
    mp -= 30;
    return mp;
  }

  int ret[4];
  for (int i{}; i < 3; ++i) {
    array<int, 3> na = a;
    na[i] += l[n];
    ret[i] = dfs(n + 1, na) + 10;
  }
  ret[3] = dfs(n + 1, a);
  sort(ret, ret + 4);

  return ret[0];
}

int main() {
  cin >> N;
  for (int i{}; i < 3; ++i)
    cin >> A[i];
  for (int i{}; i < N; ++i)
    cin >> l[i];

  array<int, 3> a{};
  cout << dfs(0, a) << endl;
  return 0;
}


Measured memory_bytes: 256
N = gets.chomp.to_i
A = gets.chomp.split(' ').map(&:to_i)
m = 1

if A.include?(0)
  m = 0
else
  for i in 0..N-1 do
    if m > 10**18
      break
    end
    m *= A[i]
  end
  if m > 10**18
    m = -1
  end
end
p m


Measured memory_bytes: 23468
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y) {
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
int dp[2000][2000] = {};
int dh[2000][2000] = {};
int dw[2000][2000] = {};
int ds[2000][2000] = {};
int main() {
	long long int n;
	long long int k;
	cin >> n >> k;
	double ans = 0;
	for (int i = 1; i <= n; i++) {
		double s = i;
		double sum = 1;
		while (s < k) {
			s = s * 2;
			sum = sum * 0.5;
		}
		double t = n;
		ans = ans + 1 / t * sum;
	}
	cout << fixed << setprecision(120) << ans;
}

Measured memory_bytes: 256
#include <stdio.h>
#define N 100

int main(){

	int H[N],W[N];
	int i,j,k,l;
	
	for(i=0;i<N;i++){
	
		scanf("%d %d",&H[i],&W[i]);
	
		if((H[i]==0)&&(W[i]==0)){break;}
	
	}
	
	for(j=0;j<i;j++){
		for(k=0;k<H[j];k++){
			for(l=0;l<W[j];l++){
				printf("#");
			}
			printf("\n");
		}
		printf("\n");	
	}
	
	return 0;
}

Measured memory_bytes: 572
R=range
I=input
p=print
l=[[[0 for i in R(10)]for j in R(3)]for s in R(4)]
for i in R(int(I())):b,f,r,v=map(int,I().split());l[b-1][f-1][r-1]+=v
for i in R(4):
 for k in l[i]:p("",*k)
 if i!=3:p("#"*20)

Measured memory_bytes: 7772
import scala.io.StdIn._

object Main extends App{
	val (a,b,h,m) = {
		val arr = readLine().split(" ", 4).map{_.toInt}
		(arr(0), arr(1), arr(2), arr(3))
	}
	
	val funshin = 6 * m
	val jishin = 30 * h + 0.5 * m
	
	val diff = math.abs(funshin - jishin)
	
	val angle = math.min(diff, 360 - diff)
	
	val result : Double = math.sqrt(a*a + b*b - 2*a*b*math.cos(2 * math.Pi * angle / 360))
	println(result)
}

Measured memory_bytes: 54740
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
//#define ll long long
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; }
#define rep(i, n) REP(i, 0, n)
#define rep_rev(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
ll t1,t2,t3;
const ll mod = 1000000007;
const int INF = 1e9;
const ll INFLONG = 1e18;

vector<ll> vec;

int main(){
  ll t;
  cin >> t;
  string str;
  ll n;
  rep(_,t){
    vec.clear();
    cin >> n;
    rep(i,n){
      cin >> t1;
      vec.push_back(t1);
    }
    cin >> str;
    vector<ll> arr;
    bool can = true;
    rep_rev(i,n){
      if(vec[i] == 0){
        continue;
      }
      t1 = vec[i];
      ull len = arr.size();
      rep(j,len){
        chmin(t1,t1^arr[j]);
      }
      if(t1 != 0){
        //cout << t1 << " ";
        if(str[i] == '1'){
          can = false;
        }else{
          arr.push_back(t1);
        }
      }
    }
    if(can){
      cout << 0 << endl;
    }else{
      cout << 1 << endl;
    }
  }
}


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

int main() {
    ll n;
    cin >> n;
    vector<ll> w(n);
    for(ll i = 0; i < n; i++) cin >> w[i];
    ll ans = LLONG_MAX;
    for(ll t = 0; t < n - 1; t++){
        ll s1 = 0, s2 = 0;
        for(ll i = 0; i <= t; i++){
            s1 += w[i];
        }
        for(ll i = t + 1; i < n; i++) s2 += w[i];
        ans = min(ans, abs(s1 - s2));
    }
    cout << ans << endl;
}


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

using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int cnt[110] = {}, a;
  while (cin >> a) {
    cnt[a]++;
  }
  int M = *max_element(cnt, cnt + 110);
  for (int i = 1; i <= 100; i++) {
    if (cnt[i] == M) cout << i << endl;
  }

  return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

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

ll fac[200010],finv[200010];

ll comb(ll n,ll r){
  if(n<0||r<0||n<r)return 0;
  else return (fac[n]*finv[n-r]%mod)*finv[r]%mod;
}

ll N,M,K;

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

  fac[0]=1;
  rep(i,200000)fac[i+1]=fac[i]*(i+1)%mod;
  rep(i,200001)finv[i]=mod_pow(fac[i],mod-2);

  cin>>N>>M>>K;

  ll suma=0,sumb=0;
  repl(i,1,N){
    ll cnt=N-i;
    suma+=cnt*i;
    suma%=mod;
  }
  suma*=M; suma%=mod;
  suma*=M; suma%=mod;

  repl(i,1,M){
    ll cnt=M-i;
    sumb+=cnt*i;
    sumb%=mod;
  }
  sumb*=N; sumb%=mod;
  sumb*=N; sumb%=mod;

  cout<<(suma+sumb)*comb(N*M-2,K-2)%mod<<endl;

  return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <iomanip>
#include <map>
using namespace std;


int main()
{
   string s, t;
   cin >> s >> t;

   int ans = 0;
   for (int i = 0; i < (int) s.length(); i++)
   {
      ans += (s[i] != t[i]);
   }

   cout << ans;

   return 0;
}

Measured memory_bytes: 3748
#include <iostream>

const int MAXN = (int)1e3 + 1;
const int MAXH = (int)2e4 + 1;
const int INF = (int)2e8 + 1;

int f[MAXN][MAXH];
int profit[MAXN], cost[MAXN];

int solve(int h, int n) {
  int max_h = h + (int)1e4;
  for (int j = 0; j < max_h; ++j) {
    f[0][j] = INF;
  }
  f[0][0] = 0;
  
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j < max_h; ++j) {
      f[i][j] = f[i - 1][j];
      if (j >= profit[i] && f[i][j] > f[i][j- profit[i]] + cost[i]) {
        f[i][j] = f[i][j - profit[i]] + cost[i];
      }
    }
  }
  int ans = f[n][h];
  for (int j = h + 1; j < max_h; ++j) {
    if (f[n][j] < ans)
      ans = f[n][j];
  }
  return ans;
}

int main() {
  int h, n;
  std::cin >> h >> n;
  for (int i = 1; i <= n; ++i) {
    std::cin >> profit[i] >> cost[i];
  }
  std::cout << solve(h, n) << std::endl;
  return 0;
}


Measured memory_bytes: 78464
from collections import defaultdict

n = int(input())
s = [input() for _ in range(n)]

d = defaultdict(int)
for i in range(n):
    d["".join(sorted(s[i]))] += 1

ans = 0
for k in d.keys():
    ans += d[k] * (d[k]-1) // 2
print(ans)


Measured memory_bytes: 25328
import sys
from collections import Counter

h, w, m, *bomb = map(int, sys.stdin.buffer.read().split())
biii = bomb[0::2]
bjjj = bomb[1::2]
h_cnt = Counter(biii).most_common()
w_cnt = Counter(bjjj).most_common()

mi, mh = h_cnt[0]
h_idx = {mi}
for i, c in h_cnt[1:]:
    if c < mh:
        break
    h_idx.add(i)

mi, mw = w_cnt[0]
w_idx = {mi}
for i, c in w_cnt[1:]:
    if c < mw:
        break
    w_idx.add(i)

ans = mh + mw
cross_bomb = 0

for bi, bj in zip(biii, bjjj):
    if bi in h_idx and bj in w_idx:
        cross_bomb += 1

if len(h_idx) * len(w_idx) == cross_bomb:
    ans -= 1

print(ans)


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

int main() {
	int N;
	cin >> N;
	for (int i = 1; i < 10; i++) {
		for (int j = 1; j < 10; j++) {
			if (N == i * j) {
				cout << "Yes" << endl;
				exit(0);
			}
			else if (N != i * j && i == 9 && j == 9) {
				cout << "No" << endl;
			}
		}
	}
}

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

int main()
{
    int N, K;
    cin >> N >> K;
    vector<int> v(N);
    for (int i = 0; i < N; i++)
    {
        cin >> v.at(i);
    }

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

    int ans = 0;
    for (int i = 0; i < K; i++)
    {
        ans += v.at(i);
    }

    cout << ans;
}


Measured memory_bytes: 3612
n = int(input())
dp = [0]*(n+1)
dp[0] = 0
dp[1] = 1
for i in range(2,n+1):
    c = float("inf")
    j = 1
    while j <= i:
        c = min(c,dp[i-j]+1)
        j *= 6
    k = 1
    while k <= i:
        c = min(c,dp[i-k]+1)
        k *= 9
    dp[i] = c

print(dp[n])

Measured memory_bytes: 42732
# スペース区切りの整数入力
h,n = map(int, input().split())

#指定数分の2つの整数を順番に受けてリストに入力
a = [0]*n
b = [0]*n
for i in range(n):
    a[i],b[i] = map(int, input().split())

#下から順に最小の積み上げを作る
bsum=[0]
for i in range(1,h+1):
    min_bsum = 9999999999999
    for atk in range(n):
        if bsum[max(0,i-a[atk])]+b[atk] < min_bsum:
            min_bsum = bsum[max(0,i-a[atk])]+b[atk]
    bsum.append(min_bsum)

#指定のHのコストを表示
print(bsum[h])


Measured memory_bytes: 42476
#include <cstddef>
#include <complex>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <array>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <limits>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <bitset>
#include <valarray>
#include <utility>
#include <tuple>
#include <cmath>
#include <memory>
#include <random>
#include <fstream>
#include <locale>

using ll = long long;
using ull = unsigned long long;

//vector
template <class T>
using vec = std::vector<T>;

template <class T>
using vvec = vec<vec<T>>;

constexpr std::size_t operator""_sz(ull n) { return std::size_t(n); }

int main()
{
	using namespace std;

	ll n;
	cin >> n;

	auto ans = (n - 1) * (n) / 2;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 2e9
#define MOD 1000000007
#define MOD9 998244353
#define intMAX 51000;
#define PI 3.14159265359
using namespace std;
typedef long long llong;
typedef long double ldouble;

using Graph = vector<vector<int>>;

int main(){
	string S, T;
	cin >> S >> T;
	int count = 0;
	for(int i=0; i<S.length(); ++i){
		if(S[i]!=T[i]) ++count;
	}
	cout << count << endl;
}


Measured memory_bytes: 3924
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#define sqr(x) (x)*(x)
using namespace std;
string st;
int main()
{
	cin>>st;
	cout<<st.substr(0,st.length()-8);
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	int k;
	scanf("%d",&k);
	if(k==4||k==6||k==9||k==10||k==14||k==21||k==22||k==25||k==26){
		printf("2");
	}else if(k==8||k==12||k==18||k==20||k==27){
		printf("5");
	}else if(k==28||k==30){
		printf("4");
	}else if(k==16){
		printf("14");
	}else if(k==24){
		printf("15 ");
	}else if(k==32){
		printf("51");
	}else{
		printf("1");
	}
	return 0;
}



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

typedef struct Node {
  int key;
  struct Node *next,*prev;
}Node;

Node *nil;

Node *listSearch(int);
void init(void);
void printList(void);
void deleteNode(Node *);
void deleteFirst(void);
void deleteLast(void);
void deleteKey(int);
void insert(int);

int main() {
  int key,n,i;
  int size = 0;
  char com[20];
  int np = 0,nd = 0;

  scanf("%d",&n);
  init();

  for(i=0;i<n;i++) {
    scanf("%s %d",com,&key);

    if(com[0] == 'i') {
      insert(key);
      np++;
      size++;
    } else if(com[0] == 'd') {
      if(strlen(com) > 6) {
	if(com[6] == 'F') deleteFirst();
	else if(com[6] == 'L') deleteLast();
      } else {
	deleteKey(key);
	nd++;
      }
      size--;
    }
  }

  printList();

  return 0;

}

Node *listSearch(int key) {
  Node *cur = nil->next;
  while(cur != nil && cur->key != key) cur = cur->next;
  return cur;
}

void init() {
  nil = malloc(sizeof(Node));
  nil->next = nil;
  nil->prev = nil;
}

void printList() {
  Node *cur = nil->next;
  int isf = 0;
  while(1) {
    if(cur == nil) break;
    if(isf++ > 0) printf(" ");
    printf("%d",cur->key);
    cur = cur->next;
  }
  printf("\n");
}

void deleteNode(Node *t) {
  if(t == nil) return;
  t->prev->next = t->next;
  t->next->prev = t->prev;
  free(t);
}

void deleteFirst() {
  deleteNode(nil->next);
}

void deleteLast() {
  deleteNode(nil->prev);
}

void deleteKey(int key) {
  deleteNode(listSearch(key));
}

void insert(int key) {
  Node *x = malloc(sizeof(Node));
  x->key = key;
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
}


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

using namespace std;

int main() {
  int n, t, l, b;
  while(cin >> n >> t >> l >> b, n+t+l+b) {
    int mas[101] = {};
    for(int i = 0; i < l; i++) {
      int x;
      cin >> x;
      mas[x] = 1;
    }
    for(int i = 0; i < b; i++) {
      int x;
      cin >> x;
      mas[x] = 2;
    }
    double dp[111][111];
    fill(dp[0], dp[101], 0);
    dp[0][0] = 1;
    for(int i = 0; i < t; i++) {
      for(int j = 0; j < n; j++) {
	for(int k = 1; k <= 6; k++) {
	  int pos = j + k;
	  double tmp = dp[i][j]/6;
	  if(pos > n) pos = n - pos + n;
	  if(mas[pos] == 1) dp[i+2][pos] += tmp;
	  else if(mas[pos] == 2) dp[i+1][0] += tmp;
	  else dp[i+1][pos] += tmp;
	}
      }
    }
    double ans = 0;
    for(int i = 0; i <= t; i++) ans += dp[i][n];
    printf("%.10f\n", ans);
  }
  return 0;
}

Measured memory_bytes: 3140
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define gc getchar
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define x1 uvuvwevwevwe
#define y1 onyetenyevwe
#define x2 ugwemubwem
#define y2 ossas
typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
template <typename T> void scan(T &angka){
	angka=0;char input=gc();T kali=1;
	while(!(48<=input&&input<=57)){	if(input=='-')	kali=-1;input=gc();}
	while(48<=input&&input<=57)	angka=(angka<<3)+(angka<<1)+input-48,input=gc();angka*=kali;
}
template <typename T1,typename T2> void scan(T1 &angka1,T2 &angka2){
	scan(angka1);scan(angka2);
}
int best=-1,arr[55],n,posbest;
bool pos=true;
int main()
{
	scan(n);
	for(int i=1;i<=n;i++)
	{
		scan(arr[i]);
		if(abs(arr[i])>best)
		{
			posbest=i;
			best=abs(arr[i]);
			pos=(arr[i]>=0);
		}
	}
	cout<<n+n-1<<endl;
	for(int i=1;i<=n;i++)
		cout<<posbest<<" "<<i<<endl;
	if(pos)
	{
		for(int i=2;i<=n;i++)
			cout<<i-1<<" "<<i<<endl;
	}
	else
	{
		for(int i=n-1;i>=1;i--)
			cout<<i+1<<" "<<i<<endl;
	}
}

Measured memory_bytes: 256
import sys
s=input()
if s[0]=="R":
    if s[1]=="R":
        if s[2]=="R":
            print(3)
        else:
            print(2)
    else:
        print(1)
else:
    if s[1]=="R":
        if s[2]=="R":
            print(2)
        else:
            print(1)
    elif s[2]=="R":
        print(1)
    else:
        print(0)

Measured memory_bytes: 9112
#include <iostream>
#include <vector>

using namespace std;

int n, a, b;

int pop(int x)
{
	int ret = 0;
	for(;x;x/=2) ret += x%2;
	return ret;
}

int ins(int x, int i, int v)
{
	int m = 1<<i;
	int ret = x / m * m * 2 + x % m + v * m;
	return ret;
}

int del(int x, int i)
{
	int m = 1<<i;
	int ret = x / (m*2) * m + x % m;
	return ret;
}

vector<int> calc(int n, int a, int b)
{
	vector<int> ret;
	if(n == 1){
		ret.push_back(a);
		ret.push_back(b);
		return ret;
	}
	
	int p;
	vector<int> res1, res2;
	for(int i = 0; i < n; i++){
		if( (a^b) & (1<<i) ){
			p = i;
			int na = del(a, p), nb = del(b, p), m = na^1;
			res1 = calc(n-1, na, m);
			res2 = calc(n-1, m, nb);
			break;
		}
	}
	for(int i = 0; i < res1.size(); i++) ret.push_back(res1[i]);
	for(int i = 0; i < res2.size(); i++) ret.push_back(res2[i]);
	
	for(int i = 0; i < ret.size()/2; i++) ret[i] = ins(ret[i], p, (a>>p)&1);
	for(int i = ret.size()/2; i < ret.size(); i++) ret[i] = ins(ret[i], p, 1 - ((a>>p)&1));
	return ret;
}

int main(void)
{
	cin >> n >> a >> b;
	
	if(pop(a)%2 == pop(b)%2){
		cout << "NO" << endl;
		return 0;
	}
	
	vector<int> ans = calc(n, a, b);
	cout << "YES" << endl;
	for(int i = 0; i < ans.size(); i++) cout << ans[i] << " "; cout << endl;
	
	return 0;
}

Measured memory_bytes: 1628
#include <stdio.h>
#include<stdlib.h>
#define N 10000

int isprime(int);

int main(void){
  int n[N],count=0,i,a,j,flag=0;
  scanf("%d",&a);
  for(i=0;i<a;i++){
    scanf("%d",&n[i]);
  }
  for(i=0;i<a;i++){
    if(isprime(n[i])==1) count++;
  }
  printf("%d\n",count);
  return 0;
}

int isprime(int x){
  int i;
  if(x<2)return 0;
  else if(x==2) return 1;
  else{
    if(x%2==0) return 0;
    for(i=3;i<=x/i;i+=2){
      if(x%i==0) return 0;
    }
  }
  return 1;
}

Measured memory_bytes: 628
#include <iostream>
int main(){
  int n;
  std::cin>>n;
  int a[100];
  for(int i=0;i < n;i++){
 std::cin>>a[i];
  }

 for(int k=0;k<n;k++){
   if(k<n-1){
   std::cout<<a[k]<<" ";
   }
   else std::cout<<a[k]<<"\n";
    } 
    
  int j,v;
  for(int i=1;i<n;i++){
    v = a[i];
    j = i-1;
    while(j>=0 && a[j] > v){
      a[j+1] = a[j];
      j--;
    }
    a[j+1] = v;
 for(int k=0;k<n;k++){
  if(k<n-1){
   std::cout<<a[k]<<" ";
  }
else std::cout<<a[k]<<"\n";
    }
  }
 return 0;
}


Measured memory_bytes: 3088
#include<bits/stdc++.h>
using namespace std;
namespace FAST_IO
{
	template<typename T> void read(T &a)
	{
		a=0;
		int f=1;
		char c=getchar();
		while(!isdigit(c))
		{
			if(c=='-')
			{
				f=-1;
			}
			c=getchar();
		}
		while(isdigit(c))
		{
			a=a*10+c-'0';
			c=getchar();
		}
		a=a*f;
	}
	template <typename T> void write(T a)
	{
		if(a<0)
		{
			a=-a;
			putchar('-');
		}
		if(a>9)
		{
			write(a/10);
		}
		putchar(a%10+'0');
	}
	template <typename T> void writeln(T a)
	{
		write(a);
		puts("");
	}
}
int n,q[101],tot,tt=1;
double mins=190000;
double avg;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>q[i];
		tot+=q[i];
	}
	avg=tot*1.0/n;
	for(int i=1;i<=n;i++)
	{
		if(abs(q[i]-avg)<mins)
		{
			mins=abs(q[i]-avg);
			tt=i;
		}
	}
	cout<<tt-1;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {
	static PrintWriter out;
	static StringBuilder sb;
	static int n, m, k;
	static long mod = 998244353;
	static Boolean[][][] memo;
	static String s;
	static HashMap<Integer, Integer> nums;
	static ArrayList<Integer>[] ad;
	static int inf = 1000000;

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		out = new PrintWriter(System.out);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] a = sc.nextArrInt(n);
		ad = new ArrayList[n];
		for (int i = 0; i < n; i++)
			ad[i] = new ArrayList<>();
		for (int i = 0; i < m; i++) {
			int ak = sc.nextInt() - 1;
			int b = sc.nextInt() - 1;
			ad[ak].add(b);
			ad[b].add(ak);
		}
		int ans=0;
		for(int i=0;i<n;i++) {
			boolean f=true;
			for(int v:ad[i])
				if(a[v]>=a[i])
					f=false;
			if(f)
				ans++;
		}
		System.out.println(ans);
		out.flush();
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream system) {
			br = new BufferedReader(new InputStreamReader(system));
		}

		public Scanner(String file) throws Exception {
			br = new BufferedReader(new FileReader(file));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public char nextChar() throws IOException {
			return next().charAt(0);
		}

		public Long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public int[] nextArrInt(int n) throws IOException {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		public long[] nextArrLong(int n) throws IOException {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextLong();
			return a;
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

		public void waitForInput() throws InterruptedException {
			Thread.sleep(3000);
		}
	}
}

Measured memory_bytes: 64128
#include <stdio.h>

int main(void)
{
    int x;
	int y = 1;
	scanf("%d", &x);
	while(x != 0){
	   printf("Case %d: %d\n", y, x);
	   y++;
 	   scanf("%d", &x);
	}

	return 0;
}

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

int main() {
  int n;
  string s;

  cin >> n >> s;

  if (n % 2 == 0) {
    string left, right;
    for (int i = 0; i < n / 2; i++) {
      left.push_back(s[i]);
      right.push_back(s[i+n/2]);
    }
    if (left == right) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define po pop_back
#define fi first
#define se second
#define hello ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define MOD 998244353  
using namespace std;
bool comp(ll a,ll b){if(a>b)return true;else return false;}
int isP(ll n){if(n==1)return 0;if(n==2 || n==3)return 1;for(ll i=2;i<=sqrt(n);i++){if(n%i==0)return 0;}return 1;}
ll power(ll a,ll b){if(b==0)return 1;if(b==1) return a;ll t=power(a,b/2);if(b%2==1) return t*t*a;else return t*t;}
ll powMOD(ll x,ll y){if(y==0)return 1;if(y==1)return x;ll t=powMOD(x,y/2);if(y%2==1)return t*t%MOD*x%MOD;else return t*t%MOD;}
bool cmp(pair<ll,ll> p1,pair<ll,ll> p2){if(p1.fi>p2.fi) return true;if(p1.fi==p2.fi && p1.se>p2.se) return true;return false;}

int main()
{
    hello;
    
    ll t; 
//    cin>>t;
	t=1;
	
	while(t--){
		ll n;
		cin>>n;
		ll ans=0;
		for(ll i=1;i<=n;i++){
			ll l=1,r=n;
			ll an=0;
			while(l<=r){
				ll mid=l+(r-l)/2;
				if(n-i*mid>0){
					an=mid;
					l=mid+1;
				}
				else{
					r=mid-1;
				}
			}
			ans+=an;
		}
		cout<<ans<<"\n";
	}
    
    return 0;  
}

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


#define DEBUG(x) 			   cout << '>' << #x << ':' << x << endl;
#define D(x)        		   cerr << __LINE__ << ": " << #x << " = " << (x) << '\n'
#define DD(x,y)     		   cerr << __LINE__ << ": " << #x << " = " << x << "   " << #y << " = " << y << '\n'
#define DDD(x,y,z)  		   cerr << __LINE__ << ": " << #x << " = " << x << "   " << #y << " = " << y << "   " << #z << " = " << z << '\n'
#define DBG         		   cerr << __LINE__ << ": Hi" << '\n'
#define fresh                  {ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);}
#define read                   freopen("in.txt","rt",stdin)
#define write                  freopen("out.txt","wt",stdout)
#define PI                     3.1415926535897932384626433832795
#define mems(ds_name,val)      memset(ds_name,val,sizeof(ds_name))


int main()
{
    fresh;
#ifndef ONLINE_JUDGE
//    read;
#endif
//	write;

    int t;
    cin>>t;
    int divs = t/2;
    int mods=t%2;
    if(!mods){
        cout<<divs*divs<<endl;
    }
    else{
        cout<<divs*(divs+1)<<endl;
    }



}


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

#include<boost/multiprecision/cpp_int.hpp>

template<typename T>
T euclidean_gcd(T a, T b){
    if(a == 0)return b;
    while(a){
        swap(a, b);
        a %= b;
    }
    return b;
}

int main(){
    using namespace std;
    using bigint = boost::multiprecision::cpp_int;
    constexpr unsigned long MOD = 1000000007;
    unsigned long b{0};
    bigint lcm{1};
    unsigned long N;
    cin >> N;
    for(unsigned long i{0}, A; i < N; ++i){
        cin >> A;
        auto t = euclidean_gcd<bigint>(lcm, A);
        ((b *= ::boost::multiprecision::integer_modulus(A / t, MOD)) += ::boost::multiprecision::integer_modulus(lcm / t, MOD)) %= MOD;
        (lcm /= t) *= A;
    }
    cout << b << endl;
    return 0;
}

Measured memory_bytes: 384
s = input().split()
r,g,b,n=int(s[0]),int(s[1]),int(s[2]),int(s[3])
k = [r,g,b]
k.sort()
a,b,c=k[0],k[1],k[2]
co = 0
for i in range(n//c+1):
    p = n-i*c
    for j in range(p//b+1):
        q = p-j*b
        if q>=0 and q%a==0:
            co+=1
print(co)

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

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N, A, B, C, D = MAP()
B -= A

l = D - C + 1
b = C * 2 - 1
mx = D
l += (D-C) * (N-2)
b = max(b - (D-C) * (N-2), 0)
mx *= N - 1

B += mx
mod = l + b
if B < 0 or B > mx*2:
    NO()
    exit()
if B % mod < l:
    YES()
else:
    NO()


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

using namespace std;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int N, M;
	cin >> N >> M;
	vector<pair<int, int>> S(N), C(M);
	for (auto &p : S) {
		cin >> p.first >> p.second;
	}
	for (auto &p : C) {
		cin >> p.first >> p.second;
	}
	for (auto s : S) {
		int d = 1e9, ans;
		for (int i = 0; i < M; ++i) {
			int dd = abs(s.first-C[i].first) + abs(s.second-C[i].second);
			if (dd < d) {
				d = dd;
				ans = i;
			}
		}
		cout << ans+1 << "\n";
	}
}

Measured memory_bytes: 256
#include <stdio.h>

int A[1000000], n;

int binarySearch(int key) {
	int left = 0;
	int right = n;
	int mid;
	while (left < right) {
		mid = (left + right) / 2;
		if (key == A[mid]) {
			return 1;
		}
		if (key > A[mid])
			left = mid + 1;
		else if (key < A[mid])
			right = mid;
	}
	return 0;
}

int main(int argc, char **argv) {
	int i, q, k, sum = 0;
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
			scanf("%d",&A[i]);
	}
	scanf("%d", &q);
	for (i = 0; i < q; i++) {
		scanf("%d", &k);
		if (binarySearch(k))
			sum++;
	}
	printf("%d\n", sum);
	return 0;
}


Measured memory_bytes: 2188
n=int(input())
ans=0

g=[[-1 for i in range(n)] for j in range(n)]
for i in range(n):
  a=int(input())
  for j in range(a):
    x,y=map(int,input().split())
    g[i][x-1]=y

for i in range(2**n):# iは正直な人間の数
  ok=True
  for j in range(n):
    if (i>>j)&1: #iのjビット目が1のなのか確認
      for k in range(n):
        if g[j][k]==-1: # 証言がなければパス
          continue
        if (i>>k)&1!=g[j][k]: # 証言があればあっているか確認
          ok=False
  if ok:
    d=i
    t=str(bin(d)).count('1') #立っている1の個数
    ans=max(t,ans)
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int n,head[100005],cnt,in[100005],flag,vis[100005];
struct edge{int to,next;
}e[200005];
void add(int x,int y)
{
	e[cnt].to=y;
	e[cnt].next=head[x];
	head[x]=cnt++;
}
void dfs(int u,int pre)
{
	int tot=0;
	for(int i=head[u];i;i=e[i].next)
	{
		if(e[i].to==pre)continue;
		dfs(e[i].to,u);
	}
	if(u==1&&!vis[u])flag=1;
	if(!vis[u])
	{
		vis[u]++;vis[pre]++;
	}
	if(vis[u]!=1)flag=1;
}
int main()
{
	flag=0;cnt=1;
	scanf("%d",&n);
	for(int i=1;i<n;++i)
	{
		int x,y;scanf("%d%d",&x,&y);add(x,y);add(y,x);
	}
	dfs(1,0);

	if(flag)puts("First");
	else puts("Second");
  return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
 
using namespace std;
 
pair <long long, long long> a[200005];
 
int main() {
    int n, d, aa;
    scanf("%d%d%d", &n, &d, &aa);
 
    for (int i = 0; i < n; i++) scanf("%lld%lld", &a[i].first, &a[i].second);
 
    sort(a, a + n);
 
    queue <pair<long long, long long>> que;
    long long sum = 0;
    long long res = 0;
 
    for (int i = 0; i < n; i++) {
        while (que.size() && que.front().first < a[i].first) {
            sum -= que.front().second;
            que.pop();
        }
 
        if (a[i].second - sum <= 0) continue;
 
        long long need = (a[i].second - sum + aa - 1) / aa;
        res += need;
        que.push(make_pair(a[i].first + 2 * d, need * aa));
        sum += need * aa;
    }
 
    printf("%lld\n", res);
}

Measured memory_bytes: 8428
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {
   /* #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif*/
        /* 
        Ofcourse it's Hard.
        It's supposed to be Hard.
        If it's easy everyone would do it.
        HARD IS WHAT MAKES IT GREAT

        YESTERDAY U SAID TOMORROW

        SLOWLY BECOMING THE PERSON I 
        SHOULD HAVE BEEN A LONG TIME AGO

        SAME TASK CAN'T BE FOUND DIFFICULT TWICE

        BTBHWSITW

        SPRH TU KAB P

        CP IS ALL ABOUT THINKING 
        YOU HAVE MUCH MORE POTENTIAL THAN U THINK

        AJIT SHIDDAT 10

        UR DAILY ROUTINE 


        */

fast();
//ll t;cin>>t;while(t--)
{
    ll n,m;
    cin>>n>>m;
    if(n<=m)
        Yes
    else
        No
}
return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import itertools
import math
from collections import deque
from collections import defaultdict
from itertools import permutations
import heapq
import bisect
from scipy.sparse.csgraph import floyd_warshall as wf
INF = float("inf")

H,W = map(int,input().split())
ans = INF

for i in range(1,H):
    SA = i * W
    h = (H-i)//2
    w = W//2
    SB2 = (H-i)*w
    SC2 = H*W-(SA+SB2)
    SB1 = h * W
    SC1 = H*W-(SA+SB1)
    S1 = max(SA,SB1,SC1)-min(SA,SB1,SC1)
    S2 = max(SA,SB2,SC2)-min(SA,SB2,SC2)
    ans = min(ans,S1,S2)

for i in range(1,W):
    SA = H * i
    #横半分に分割するケース
    h = H//2
    w = (W-i)//2
    SB1 = h * (W-i)
    SC1 = H*W-(SA+SB1)
    S1 = max(SA,SB1,SC1)-min(SA,SB1,SC1)
    #縦半分に分割するケース
    SB2 = H*w
    SC2 = H*W -(SA+SB2)
    S2 = max(SA,SB2,SC2)-min(SA,SB2,SC2)
    ans = min(ans,S1,S2)

print(ans)


Measured memory_bytes: 17152
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Map = map<string,ll>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
ll INF=1LL<<60;
ll MOD=1000000007;

int main(){
    ll N;
    cin >> N;
    vector<ll> H(N+1,0);
    ll ans=0;
    for(ll i=0;i<N;i++){
        cin>>H[i+1];
        bool check=0;
        for(ll j=0;j<i+1;j++){
            if(H[j]>H[i+1])check=1;
        ;}
        if(!check)ans++;
    ;}
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[]args){
		Scanner sc=new Scanner(System.in);
		int k=1;
		while(k==1){
			int H=sc.nextInt();
			int W=sc.nextInt();
			if(H==0 && W==0)
				break;
			for ( int i = 0; i < H; i++ ){
				for ( int j = 0; j < W; j++ )
					System.out.print("#");
				System.out.println("");
			}
			System.out.println();
		}
	}
}



Measured memory_bytes: 33116
#include<iostream>
#include<deque>
#include<queue>
#include<math.h>
#include<string>
#include<string.h>
#include<stdio.h>
#include<set>
#include<vector>
#include<iomanip>
#include<map>
#include<bitset>
#include<algorithm>
#include<stack>
#include<unordered_map>
#include<cstdlib>
#include<unordered_set>
#include<algorithm>
#include<chrono>

#define inf 0x3f3f3f3f
#define sup_inf 2e18
#define pb push_back
		
#define ii pair	<int, int>
#define i64ii pair< long long, pair<int,int> >
#define i64i pair<long long , int >
#define f first
#define s second
#define fast_io ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define iii pair<int, ii >	
#define in freopen("entrada","r",stdin);
#define out freopen("myfile.txt", "w", stdout);
#define eps 1e-9
#define id pair<int ,double > 
#define di pair<double, int>
 
#define pi 3.14159265359
#define nl (no<<1)
#define nr ( (no<<1)|1)
#define mid l + ( (r-l)>>1)
 
using namespace std;
 
typedef long long ll;	
typedef vector< int> vi;
typedef long double ld;
typedef  pair <ii, ii > iiii;
typedef vector < ii > vii;
 
const int MAX = 2e5;
const int maxn = 1e6 + 200;

typedef unsigned long long ull;
using namespace std;
 


int an[maxn], n, m , k, ans[maxn], _size[maxn];


int findc(int x ){
 while (x != an[x] ){
  x = an[x] = an[an[x]];
 }
 return x;
}

void une ( int a, int b ){
 int x = findc(a);
 int y = findc(b);
 if ( x == y) return;
 an[x] = y;
 _size[y]+=_size[x];
}


int main (){
 //~ in
 cin >> n >> m >> k ;
 
 for(int i = 0 ;i < n + 1 ;i++) { 
  an[i] = i;
  _size[i] = 1;
 }
 
 for(int i = 0 ;i < m;i++) {
  int a, b; cin >> a >> b;
  ans[a]++;
  ans[b]++;
  une ( a, b );
 }
 
 for(int i = 0 ;i < k; i++) {
  int a, b;
  cin >> a >> b;
  if ( findc(a) == findc(b)) {
   ans[a]++;
   ans[b]++;
  }
 }
 
 
 
 for(int i = 0 ;i < n;i++) {
  cout << _size[findc(i+1)] - ans[i+1] - 1<< ' ';
 }
 cout << '\n';
 
 return 0;
}


 


Measured memory_bytes: 9472
#include <iostream>
#include <stack>
#include <sstream>
#include <stdlib.h>
#include <cstdio>
#include <typeinfo>

typedef long long int ll;
using namespace std;

int main()
{
    stack<int> S;
    string word;

    while (cin >> word)
    {
        int front, back, num;
        string result;

        if (word == "+")
        {
            back = S.top();
            S.pop();
            front = S.top();
            S.pop();
            S.push(front + back);
        }
        else if (word == "-")
        {
            back = S.top();
            S.pop();
            front = S.top();
            S.pop();
            S.push(front - back);
        }
        else if (word == "*")
        {
            back = S.top();
            S.pop();
            front = S.top();
            S.pop();
            S.push(front * back);
        }
        else
        {
            num = atoi(word.c_str());
            S.push(num);
        }
    }
    cout << S.top() << endl;
}


Measured memory_bytes: 3180
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <list>
#include <iomanip>
#include <queue>
#include <functional>
#include <cassert>
#include <cmath>
#include <set>

#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define NL << endl

using namespace std;
using ll = long long;


int main() {

	string s;

	cin >> s;

	bool found = false;

	if (s[0] == 'A') {
		FOR(i, 2, s.size() - 1) {
			if (s[i] == 'C') {
				if (found) {
					cout << "WA" NL;
					return 0;
				} else {
					found = true;
				}
			} else if ('a' > s[i] || 'z' < s[i]) {
				cout << "WA" NL;
				return 0;
			}
		}
		if (!found) {
			cout << "WA" NL;
			return 0;
		}
	} else {
		cout << "WA" NL;
		return 0;
	}
	if (s[1] < 'a' || s[1] > 'z' || s.back() < 'a' || s.back() > 'z') {
		cout << "WA" NL;
		return 0;
	}

	cout << "AC" NL;


	return 0;

}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  int n,i=0;
  scanf("%d",&n);
  //int arr[100]={0};
  double tmp;
  double sum=0;
  for(i=0;i<n;i++){
    scanf("%lf",&tmp);
    sum += 1/tmp;
  }
  printf("%f",1/sum);
  return 0;
}



Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	// memset(dp,-1,sizeof(dp));
	int a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
	}

	int dp[n];
	dp[0] = 0;
	dp[1] = abs(a[0] - a[1]);

	for(int i=2;i<n;i++){
		dp[i] = min(dp[i-1] + abs(a[i] - a[i-1]) , dp[i-2]+abs(a[i]-a[i-2]));
	}
	cout<<dp[n-1]<<endl;


}

Measured memory_bytes: 1024
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>
#include <boost/math/common_factor_rt.hpp>

using namespace std;

int main()
{
    std::string S;
    std::cin >> S;

    auto SS = S;
    if (S.size() == 26) {
        bool result = std::next_permutation(SS.begin(), SS.end());
        if (!result) {
            std::cout << -1 << std::endl;
            return 0;
        }
        else {
            for (int i = 0; i < 26; ++i) {
                if (S[i] == SS[i]) {
                    std::cout << S[i];
                }
                else {
                    std::cout << SS[i] << std::endl;
                    return 0;
                }
            }
        }
    }

    std::vector<bool> used(26);

    for (auto c: S) {
        int o = c - 'a';
        used[o] = true;
    }


    std::cout << S;
    for (int i = 0; i < 26; ++i) {
        if (!used[i]) {
            char c = i + 'a';
            std::cout << c << std::endl;
            return 0;
        }
    }

    return 0;
}


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

constexpr int inf = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3fLL;

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

    string w; cin >> w;
    vector<int> cnt(26);
    for (auto &c: w) cnt[c - 'a']++;
    for (auto &e: cnt) {
        if (e & 1) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


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

signed main()
{
  int N; cin>>N;
  vector<int> a(N);
  for(int i=0;i<N;i++){
    cin>>a[i];
  }

  multiset<int> st;
  for(int x:a){
    auto itr=st.lower_bound(x);
    if(itr==st.begin()){
      st.insert(x);
    }else{
      itr--;
      st.erase(itr);
      st.insert(x);
    }
  }
  cout<<st.size()<<endl;

  return 0;
}


Measured memory_bytes: 5760
def getInput():
    n = int(input())
    a = [int(i) for i in input().split(" ")]
    return n, a

def swap(x, y):
    v = x
    x = y
    y = v
    return x, y

def bubbleSort(n, a):
    cnt = 0
    for j in range(n):
        init = True
        for i in range(n-1, -1, -1):
            if init:
                init = False
                continue
            if a[i] > a[i+1]:
                a[i], a[i+1] = swap(a[i], a[i+1])
                cnt += 1
    print(" ".join([str(i) for i in a]))
    print(cnt)
    return

n, a = getInput()
bubbleSort(n, a)



Measured memory_bytes: 5608
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MAX =510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

void COMinit(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  for(int i=2; i<MAX; i++){
    fac[i]=fac[i-1]*i%MOD;
    inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
    finv[i]=finv[i-1]*inv[i]%MOD;
  }
}

ll COM(int n, int k){
  if(n<k)
    return 0;
  if(n<0 || k<0)
    return 0;
  return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}

int main(){
  COMinit();
  ll N,M;
  cin>>N>>M;
  ll ans=0;
  ans+=COM(N,2);
  ans+=COM(M,2);
  cout<<ans<<endl;
}

Measured memory_bytes: 12160
from bisect import bisect

def sieve(n):
  prime = [True] * n
  prime[0] = prime[1] = False
  for i in xrange(2, int(n ** 0.5) + 1):
    if prime[i]:
      for j in range(i ** 2, n, i):
        prime[j] = False
  return [i for i in xrange(2, n) if prime[i]]

primes = sieve(999999)
while True:
  try:
    print bisect(primes, input())
  except:
    break

Measured memory_bytes: 29912
n = int(input())
l = []
for i in range(n):
  s,p = input().split()
  l.append((s,int(p),i+1))
l.sort(key = lambda x : x[1],reverse=True)
l.sort(key = lambda x : x[0])
for i in range(n):
  print(l[i][2])

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
long long a[100010];
int main() {
	long long q=1;
	int k;
	cin>>k;
	int r=1,l=9;
	for(int i=1;i<=9;i++){
		a[i]=i;
	}
	while(l<=k){
		if(a[r]%10==0){
			l++;
			a[l]=a[r]*10;
			l++;
			a[l]=a[r]*10+1;
		}
		else if(a[r]%10==9){
			l++;
			a[l]=a[r]*10+8;
			l++;
			a[l]=a[r]*10+9;
		} 
		else{
			l++;
			a[l]=a[r]*10+a[r]%10-1;
			l++;
			a[l]=a[r]*10+a[r]%10;
			l++;
			a[l]=a[r]*10+a[r]%10+1;
		}
		r++;
	}
	cout<<a[k];
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
using namespace std;
int main(){
        int N;
        cin >> N;
        char s;int x;
        bool missing[100][14];
        string str="SHCD";
        for(int i=0 ; i<str.size() ; i++ )
                for(int l=0 ; l<14 ; l++ )
                        missing[str[i]-'A'][l]=false;
        for(int i=0 ; i<N ; i++ ){
                cin >> s >> x;
                missing[s-'A'][x]=true;
        }
        for(int i=0 ; i<str.size() ; i++ ){
                for(int l=1 ; l<14 ; l++ ){
                        if(missing[str[i]-'A'][l]==false)
                                cout<<str[i]<<" "<<l<<endl;
                }
        }
        return 0;
}


Measured memory_bytes: 3188