akhauriyash/Code-Regression huggingface dataset:
H, W, D = map(int, input().split())
Aindex = [0] * (H*W)
for h in range(H):
    w = 0
    for A in input().split():
        Aindex[int(A)-1] = (h,w)
        w += 1 

import numpy as np
v, h = int(np.ceil(H*W/D)), D
Mp = np.zeros((v, h)) #MpをMod D別に計算する予定
mp = lambda X, Y: abs(X[0]-Y[0]) + abs(X[1]-Y[1]) #魔力計算する関数
for x in range(D,H*W):
    i, j = divmod(x, D)
    Mp[i,j] = mp(Aindex[x], Aindex[x-D])
#縦軸方向に累積和を取っておき、後のクエリにO(1)で対応
Mp = Mp.cumsum(axis=0)

#クエリ処理
Q = int(input())
Query = [(int(x) for x in input().split()) for _ in range(Q)]
for l, r in Query:
    ans = Mp[divmod(r-1, D)] - Mp[divmod(l-1,D)]
    print(int(ans))

Measured memory_bytes: 129316
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet, BinaryHeap, VecDeque, BTreeSet, BTreeMap};
#[allow(unused_imports)]
use std::iter::FromIterator;
#[allow(unused_imports)]
use std::io::stdin;

mod util {
    use std::io::stdin;
    use std::str::FromStr;
    use std::fmt::Debug;

    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }
}

#[allow(unused_macros)]
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    get!($t)
                   ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    get!($($t),*)
                   ).collect::<Vec<_>>()
    };
    ($t:ty ;;) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    let s: Vec<usize> = util::line()
        .chars()
        .map(|c| c as usize - '0' as usize)
        .collect();

    let mut ans = 0;

    for i in 0..s.len() {
        for k in i..s.len() {
            let b = s[i..k + 1]
                .iter()
                .rev()
                .zip(0..)
                .map(|(&d, a)| d * 10usize.pow(a as u32))
                .sum::<usize>();

            let mut n = s.len() - 1;

            if i != 0 {
                n -= 1;
            }

            if k != s.len() - 1 {
                n -= 1;
            }

            n -= k - i;

            ans += b * 2usize.pow(n as u32);
        }
    }

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


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long int
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);
#define inf 922337203685477580
#define mini 9223372036854775807
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
pair<ll,ll>s4[4]={{-1,0},{1,0},{0,-1},{0,1}};
pair<ll,ll>s8[8]={{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,1},{1,0},{1,-1}};
ll power(ll a,ll b)
{
	if(b==0)
		return 1;
	ll c=power(a,b/2);
	if(b%2==0)
		return ((c%mod)*(c%mod))%mod;
	else
		return ((((c%mod)*(c%mod))%mod)*a)%mod;
}
string s,t;
ll dp[3005][3005];
int main()
{
	boost
	cin>>s;
	cin>>t;
	ll n,m;
	n=s.size();
	m=t.size();
	ll i,j;
	for(i=1; i<=n; i++)
	{
		for(j=1; j<=m; j++)
		{
			if(s[i-1]==t[j-1])
				dp[i][j]=dp[i-1][j-1]+1;
			else
				dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
		}
	}
/*	for(i=0; i<=n; i++)
	{
		for(j=0; j<=m; j++)
			cout<<dp[i][j]<<" ";
		cout<<endl;
	}*/
	i=n;
	j=m;
	vector<char>v;
	while(i>0 && j>0)
	{
		if(s[i-1]==t[j-1])
		{
			v.push_back(s[i-1]);
			i--;
			j--;
		}
		else if(dp[i-1][j]>dp[i][j-1])
			i--;
		else
			j--;
	}
	for(i=v.size()-1; i>=0; i--)
		cout<<v[i];
	return 0;
}

Measured memory_bytes: 70784
xor(a,b)=a$b
N=parse(Int,readline())
A=zeros(Int,N)
B=zeros(Int,N)
for i=1:N
	a=parse(Int,readline())
	for _=1:a
		x,y=map(x->parse(Int,x),split(readline()))
		if y==1
			A[i]=xor(A[i],2^(x-1))
		else
			B[i]=xor(B[i],2^(x-1))
		end
	end
end
ans=0
for m=0:2^N-1
	t=m
	f=(2^N-1)&~m
	cnt=0
	for i=1:N
		if (m>>(i-1))%2==1
			t=t|A[i]
			f=f|B[i]
			cnt+=1
		end
	end
	if (t&f)==0
		ans=max(ans,cnt)
	end
end
println(ans)


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

int a, b;

int main() {
  cin >> a >> b;
  cout << a*b << endl;
  return 0;
}


Measured memory_bytes: 3636
my $a = <>;
my $b = <>;
my $count = 0;

if(substr($a,0,1) eq substr($b,0,1)){
	$count++;
}
if(substr($a,1,1) eq substr($b,1,1)){
	$count++;
}
if(substr($a,2,1) eq substr($b,2,1)){
	$count++;
}
print $count;

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

using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using vs = vector<string>;
using pll = pair<ll, ll>;
const ll oo = 0x3f3f3f3f3f3f3f3fLL;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define FOR(i, a, b) for(ll i=(a); i<(b); i++)
#define FORD(i, a, b) for(ll i=ll(b)-1;i>=(a);i--)
#define TR(X) ({if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

int main() {
    cin.sync_with_stdio(0);

    ll mod = pow(10, 9) + 7;

    ll n;
    cin >> n;
    vl a(n);
    ll sum = 0;
    FOR(i, 0, n) {
        ll tmp;
        cin >> tmp;
        tmp %= mod;
        a[i] = tmp;
        sum += tmp;
        sum %= mod;
    }
    ll end = 0;
    FOR(i, 0, n) {
        end += (a[i] * ((sum + mod - a[i]) % mod)) % mod;
        end %= mod;
    }
    if (end % 2 == 0) {
        cout << end / 2 << endl;
    } else {
        cout << ((end + mod) / 2) % mod << endl;
    }
}

Measured memory_bytes: 4764
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <deque>
#include <queue>

#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, m, n) for(int i = m; i < n; ++i)
#define rrep(i,n) for(int i = n; i >= 0; --i)
#define RREP(i, m, n) for(int i = n; i >= m; --i)

using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int, int>;
using pll = std::pair<long long, long long>;

using namespace std;


const long long MOD = 1000000007;

template<typename T>
constexpr std::pair<T, T> eea(T a, T b) noexcept {
	T x = 1, y = 0, p = 0, q = 1;
	while (b != 0) {
		T s = a;
		a = b;
		T t = s / b;
		b = s % b;

		T i = x, j = y;
		x = p;
		y = q;
		p = i - t * p;
		q = j - t * q;
	}

	return pair<T, T>(x, y);
}

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

	ll n, k;
	cin >> n >> k;
	ll ans = 1;
	
	ll c = 1, h = 1;
	rep(i, min(k, n - 1)) {
		c *= n - i;
		c %= MOD;
		h *= n - 1 - i;
		h %= MOD;
		ll inv = eea((ll)i + 1, MOD).first;
		if (inv < 0) inv += MOD;
		c *= inv;
		c %= MOD;
		h *= inv;
		h %= MOD;

		ans += c * h;
		ans %= MOD;
	}

	cout << ans << "\n";

	return 0;
}
 

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

int main(){
    int n;
    vector<int> v;
    
    cin >> n;
    v.reserve(n);
    for(int i = 0 ; i < n ; i++) cin >> v[i];
    for(int i = n-1 ; i >= 0 ; i--){
        if(i == 0) cout << v[i] << endl;
        else cout << v[i] << ' ';
    }

    return 0;
}


Measured memory_bytes: 3084
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <unistd.h>
#include <math.h>
long long int ans=0;
#define  ll long long
//最大公約数
long long int getgcd(long long n, long long m)
{
  int r;
  if (n > m) {
    long long t = m;
    m = n;
    n = t;
  }
  while ((r = m % n) != 0) {
    m = n;
    n = r;
  }
return n;
}

//nの階乗を計算
long long factorial(long long n){
    long long int answer = 1;
while(n > 1){
  answer *= n;
  n--;
}
    return answer;
}

//組み合わせの数nCrを計算
long long calcNumOfCombination(long long  n, long long r){
    return factorial(n) / (factorial(r) * factorial(n-r));
}
 void yes(){
   printf("Yes\n");
 }

 void no(){
   printf("No\n");
 }

int main(int argc, char* argv[]){
	ll a = 0, b = 0,c=0,e=0;
  scanf("%lld %lld",&a,&b);
  ll g[a],h[a];
  for (int i = 0; i < a; i++) {
    g[i]=0;
    scanf("%lld",&h[i]);
  }
  for (int i = 0; i < b; i++) {
    scanf("%lld %lld",&c,&e);
    c--;e--;
    if (h[c]>h[e]) {
      g[e]=1;
    }else if(h[c]==h[e]){
      g[c]=1;
      g[e]=1;
    }else{
      g[c]=1;
    }
  }
  for (int i = 0; i < a; i++) {
    if (g[i]==0) {
      ans++;
    }
  }
  printf("%lld",ans);
  return 0;
}


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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;


#ifdef LOCAL
#include "pretty_debug.h"
#else
#define debug(...) //ignore
#endif

bool smin(auto &a, auto&& b) { return (b < a) ? (a = b, 1) : 0; } 
bool smax(auto &a, auto&& b) { return (b > a) ? (a = b, 1) : 0; } 

int main() {
  cin.sync_with_stdio(0); cin.tie(0);
  cin.exceptions(cin.failbit);
  int n;
  cin>>n;
  vector<pii> v(n);
  trav(x,v) cin >> x.first >> x.second;
  vector<pii> pre(n+1, pii(-5,1e9+5)), suf(n+1, pii(-5,1e9+5));
  rep(i,0,n) {
    pre[i+1].first = max(pre[i].first, v[i].first);
    pre[i+1].second = min(pre[i].second, v[i].second);
  }
  for(int i = n; i--;) {
    suf[i].first = max(suf[i+1].first, v[i].first);
    suf[i].second = min(suf[i+1].second, v[i].second);
  }
  ll ans = 0;
  rep(i,0,n) {
    int left = max(pre[i].first, suf[i+1].first);
    int right = min(pre[i].second, suf[i+1].second);
    int cur = max(0,right-left+1) + v[i].second-v[i].first+1;
    smax(ans,cur);
  }

  sort(all(v));
  vector<pii> nv;
  pii lst = {0,1e9+5};
  rep(i,0,n) {
    if(i > 0 && v[i].first == v[i-1].first) continue;
    while(!nv.empty() && nv.back().second >= v[i].second)
      nv.pop_back();
    lst = v[i];
    nv.push_back(v[i]);
  }

  ll ans2 = 0;
  rep(i,0,sz(nv)-1) {
    int cur = 0;
    cur += max(0, nv.front().second - nv[i].first + 1);
    cur += max(0, nv[i+1].second - nv.back().first + 1);
    debug(cur);
    smax(ans2, cur);
  }
  debug(ans, ans2);
  debug(pre);
  debug(suf);
  debug(nv);
  cout << max(ans, ans2) << endl;
}


Measured memory_bytes: 3832
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 5;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); } 
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
template <typename T> void write(T x) {
	if (x < 0) x = -x, putchar('-');
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
char s[MAXN], t[MAXN];
int main() {
	int lx = 1, rx, ly = 1, ry, n, x, y, X, Y;
	read(X), read(Y), read(n), read(x), read(y);
	rx = X, ry = Y;
	scanf("\n%s", s + 1);
	scanf("\n%s", t + 1);
	for (int i = n; i >= 1; i--) {
		if (t[i] == 'L') ry = min(ry + 1, Y);
		if (t[i] == 'R') ly = max(ly - 1, 1);
		if (t[i] == 'U') rx = min(rx + 1, X);
		if (t[i] == 'D') lx = max(lx - 1, 1);
		if (s[i] == 'L') ly++;
		if (s[i] == 'R') ry--;
		if (s[i] == 'U') lx++;
		if (s[i] == 'D') rx--;
		if (ly > ry || lx > rx) {
			puts("NO");
			return 0;
		}
	}
	if (x >= lx && x <= rx && y >= ly && y <= ry) puts("YES");
	else puts("NO");
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <math.h>
#define uint unsigned long long
#define ll long long
#define db double
#define ls rt << 1
#define rs rt << 1 | 1
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define X first
#define Y second
#define pcc pair<char, char>
#define vi vector<int>
#define vl vector<ll>
#define rep(i, x, y) for(int i = x; i <= y; i ++)
#define rrep(i, x, y) for(int i = x; i >= y; i --)
#define ept 1e-9

using namespace std;
inline int read()
{
    int x = 0, f = 1; char ch = getchar();
    while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
    while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
    return x * f;
}
const int mod = 1e9 + 7;
ll N;
map<ll,ll> DP;
ll dp(ll x)
{
    if(DP[x]) return DP[x];
    return DP[x] = ( dp(x / 2) + dp((x - 1) / 2) + dp((x - 2) / 2) )%mod;
}
int main()
{
    DP[0] = 1;
    DP[1] = 2;
    cin >> N;
    cout << dp(N) << endl;
    return 0;;
}


Measured memory_bytes: 256
import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
sys.setrecursionlimit(10**7)

def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

def main():
    K,X = LI()
    print("Yes" if 500*K>=X else "No")

main()



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

using namespace std;

using ll = long long;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    string s;
    cin >> s;

    vector<int> v(n);
    for (int i = 0; i < n; ++i) {
        if (s[i] == 'R') v[i] = 0;
        else if (s[i] == 'G') v[i] = 1;
        else v[i] = 2;


    }

    vector< vector<int> > cnt(3, vector<int>(n + 1, 0));
    for (int i = 0; i < n; ++i) {
        cnt[v[i]][i + 1]++;
        for (int j = 0; j < 3; ++j) {
            cnt[j][i + 1] += cnt[j][i];
        }
    }

    ll ans = 0;
    for (int j = 0; j < n; ++j) {
        int c1 = (v[j] + 1) % 3;
        int c2 = (v[j] + 2) % 3;
        ans += cnt[c1][j] * (cnt[c2][n] - cnt[c2][j + 1]);
        ans += cnt[c2][j] * (cnt[c1][n] - cnt[c1][j + 1]);
        for (int i = 0; i < j; ++i) {
            int k = 2 * j - i;
            if (k < 0 || k >= n) continue;
            if (v[i] != v[j] && v[j] != v[k] && v[k] != v[i]) --ans;
        }
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3700
import java.io.*;

public class Main{
    public static void main(String args[]) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String line1 = br.readLine();
        String line2 = br.readLine();

        String[] array = line1.split(" ");

        int n = Integer.parseInt(array[0]);
        int x = Integer.parseInt(array[1]);

        array = line2.split(" ");
        int l[]  = new int[n];

        for(int i = 0;i < n;i++){
            l[i] = Integer.parseInt(array[i]);
        }

        int kaisuu = 1;
        int length = 0;
        for(int i = 0;i < n;i++){
            length = length + l[i];
            if(length > x ){
                break;
            }
            kaisuu++;
        }
        System.out.println(kaisuu);
    }
}

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



int main() {
    ll k,s;
    cin >> k >> s;
    if(k==1 || s==1) cout << 1 << endl;
    else {
        cout << (k*s+1)/2 << endl;
    }
}

Measured memory_bytes: 256
import java.util.*;
import java.util.Collections;
import java.util.stream.Collectors;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int totalDiff = 0;
    int maxDiff = 0;
    ArrayList<Integer> list = new ArrayList<Integer>();
    for (int i = 0; i < 5; i++) {
      list.add(sc.nextInt());
      if (list.get(i) % 10 <= 9 && list.get(i) % 10 != 0) {
        totalDiff += 10 - list.get(i) % 10;
        maxDiff = Math.max(maxDiff, 10 - list.get(i) % 10);
      }
    }
    System.out.println(list.stream().mapToInt(x -> x).sum() + totalDiff - maxDiff);
  }
}


Measured memory_bytes: 26708
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (int i = (a); i <= (b); ++ i)
#define rrp(i,a,b) for (int i = (a); i >= (b); -- i)
#define gc() getchar()
#define fir first
#define sec second
typedef pair<int,int> pii;
typedef long double db;
typedef long long ll;
template <typename tp>
inline void read(tp& x) {
  x = 0; char tmp; bool key = 0;
  for (tmp = gc(); !isdigit(tmp); tmp = gc())
    key = (tmp == '-');
  for (; isdigit(tmp); tmp = gc())
    x = (x << 3) + (x << 1) + (tmp ^ '0');
  if (key) x = -x;
}
template <typename tp>
inline void ckmn(tp& x,tp y) {
  x = x < y ? x : y;
}
template <typename tp>
inline void ckmx(tp& x,tp y) {
  x = x < y ? y : x;
}

const int N = 6, M = 55;
db dp[N * M][1 << (N-1)][N * M];
db ans;
db mn = 1;
int n, c, len[N], per[N];
db solve() {
  memset(dp, 0, sizeof dp);
  dp[0][0][len[0] * n] = 1;
  rep (i, 0, c * n) {
    rep (s, 0, (1 << (n-1))-1) {
      rep (j, i, c * n) {
	if (i < c * n) dp[i+1][s][j] += dp[i][s][j];
	int k = i % n;
	if (k > 0 && ((s >> (k-1))&1) == 0)
	  dp[i+1][s | (1 << k >> 1)][min(c * n, max(j, i + len[per[k]] * n))] += dp[i][s][j] / (c + 0.0);
	if (dp[i][s][j] > 0) ckmn(mn, dp[i][s][j]);
      }
    }
  }
  return dp[c * n][(1 << (n-1)) - 1][c * n];
}
int main() {
  read(n), read(c);
  rep (i, 0, n-1) read(len[i]);
  sort(len, len + n, greater<int>());
  rep (i, 1, n-1) per[i] = i;
  do {
    db tmp = solve();
    rep (i, 1, n-1) tmp /= (i + 0.0);
    ans += tmp;
  } while (next_permutation(per+1, per+n));
  printf("%.12Lf\n", ans);
  return 0;
}


Measured memory_bytes: 54784
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace AtCoder
{
    class ABC168C
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            int n = int.Parse(str[0]);
            int x = int.Parse(str[1]);
            int t = int.Parse(str[2]);
            int a = n%x;
            int ans = 0;
            if(a == 0)
            {
                ans = n/x;
            }
            else
            {
                ans = n/x+1;
            }
            Console.WriteLine(ans*t);
        }
    }
}

Measured memory_bytes: 27460
import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    x = int(input().rstrip('\n'))
    d, m = divmod(x, 100)
    print(1 if 0 <= m <= d * 5 else 0)


if __name__ == '__main__':
    solve()


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

namespace Atc_0031
{
    class Program
    {
        static void Main(string[] args)
        {
            var str = Console.ReadLine();

            int H = int.Parse(str.Split(' ')[0]);
            int W = int.Parse(str.Split(' ')[1]);

            str = Console.ReadLine();

            int h = int.Parse(str.Split(' ')[0]);
            int w = int.Parse(str.Split(' ')[1]);

            Console.WriteLine((H - h) * (W - w));
        }
    }
}


Measured memory_bytes: 17712
n = int(input())
h = list(map(int, input().split()))

x = 0
y = 0
z = 0
for i in h:
  if x < i:
    x = i
    y = 0
    continue
    
  y += 1
  x = i
  if z < y:
    z = y
print(z)

Measured memory_bytes: 14252
class Dice
	def initialize(n=Array.new(6,0))
		@num = n
		@LRRoll = [:u, :b, :d, :f]
		@FBRoll = [:u, :l, :d, :r]
		@UDRoll = [:r, :b, :l, :f]
		reset
	end

	def reset
		@position = { u: @num[0],
									d: @num[5],
									r: @num[2],
									l: @num[3],
									f: @num[4],
									b: @num[1]
		}
	end

	def move(v)
		case v
		when "N"
			Roll(@LRRoll)
		when "S"
			Roll(@LRRoll, -1)
		when "E"
			Roll(@FBRoll)
		when "W"
			Roll(@FBRoll, -1)
		end
	end

	def move_roll(n)
		n.times { Roll(@UDRoll) }
	end

	def Roll(roll, v=1)
		v = -1 if v != 1
		t = @position[roll[0]]
		@position[roll[  0]] = @position[roll[1*v]]
		@position[roll[1*v]] = @position[roll[2*v]]
		@position[roll[2*v]] = @position[roll[3*v]]
		@position[roll[3*v]] = t
	end

	def v_up
		@position[:u]
	end

	def v_down
		@position[:d]
	end

	def v_foward
		@position[:f]
	end

	def v_back
		@position[:b]
	end

	def v_right
		@position[:r]
	end

	def v_left
		@position[:l]
	end

end

n1 = gets.chomp.split(" ").map &:to_i
d1 = Dice.new(n1)
n2 = gets.chomp.split(" ").map &:to_i
d2 = Dice.new(n2)

same = false
n = 0

3.times {
	break if d1.v_up == d2.v_up and d1.v_down == d2.v_down
	d2.move("E")

	break if d1.v_up == d2.v_up and d1.v_down == d2.v_down
	d2.move("N")
}

same = true if d1.v_up == d2.v_up and d1.v_down == d2.v_down

if same
	case d1.v_back
	when d2.v_left
		d2.move_roll(1)
	when d2.v_foward
		d2.move_roll(2)
	when d2.v_right
		d2.move_roll(3)
	when d2.v_back
		same = true
	else
		same = false
	end
end

if same
	same = false if not  (d1.v_foward == d2.v_foward and
												d1.v_right  == d2.v_right  and
										 		d1.v_left   == d2.v_left)
end

if same
	print("Yes\n")
else
	print("No\n")
end

Measured memory_bytes: 8760
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
const double eps = 1e-9;

int32_t main()
{
	int a,b,c;
	cin >> a >> b >> c;
	
	int k = (c - a - b)*(c - a - b);
	if(a+b > c)
		cout << "No\n";
	else
	{
		if(k > 4*a*b)
			cout << "Yes\n";
		else
			cout << "No\n";
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    int64_t x,k,d,answer,a,b,c;
    cin >> x >> k >> d;
    if (x == 0){
        if (k % 2 == 0){
            answer = 0;
        }
        else {
            answer = d;
        }
    }
    if (x > 0){
        if (x/d >= k){
            answer = x - k * d;
        }
        else if ((k - x/d) % 2 == 0){
            answer = x % d;
        }    
        else {
            answer = d - (x % d);
        }
    }
        
    if (x < 0){
        x = -1 * x;
        if (x/d >= k){
            answer = x - k * d;
        }
        else if ((k - x/d) % 2 == 0){
            answer = x % d;
        }
        else {
            answer = d - x % d;
        }
    }
    
    cout << answer << endl;
}

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

long long N, A, B;
vector<long long> V;


vector<vector<long long> > comb;

void combination(int n)
{
	comb.assign(n+1, vector<long long>(n+1, 0));
	for(int i=0; i<=n; ++i){
		comb[i][0] = 1;
		for(int j=1; j<=i; ++j){
			comb[i][j] = comb[i-1][j-1] + comb[i-1][j];
		}
	}
}

int main(){
	combination(100);
	cin >> N >> A >> B;
	for(long long i = 0; i < N; i++){
		long long tmp;
		cin >> tmp;
		V.push_back(tmp);
	}

	sort(V.begin(), V.end(), greater<long long>());

	long long Asum = 0;
	long long Anum = 0;
	long long Aallnum = 0;
	long long Extranum = 0;
	for(long long i = 0; i < A; i++){
		//cout << "Add asum " << V[i] << endl;
		Asum += V[i];
		if(V[i] == V[A-1]){
			Anum++;
		}
	}

	for(long long i = A; i < B; i++){
		if(Asum == V[i] * A){
			Extranum++;
		}
	}

	for(long long i = 0; i < N; i++){
		//cout << V[i] << endl;
		if(V[i] == V[A-1]){
			Aallnum++;
		}
	}
	//cout << "ASUM = " << Asum << endl;
	//cout << "A = " << A << endl;

	printf("%.10f\n", (double)Asum/(double)A);
	
	long long ans = 0;
	for(long long i = 0; i <= Extranum; i++){
		ans += comb[Aallnum][Anum + i];
	}

	cout << ans << endl;



	

}

Measured memory_bytes: 384
#!/mnt/c/Users/moiki/bash/env/bin/python
N,M = map(int, input().split())
if N >= M:
    print(0)
    exit(0)

X = list(map(int, input().split()))
X = sorted(X)
X = [x-X[0] for x in X]
diff = [x-y for x,y in zip(X[1:], X)]
# print(X)
# print(diff)
diff = sorted(diff)
sum  = sum(diff[:M-1-(N-1)])
# print("diff: ", diff,"M: ", M, ", N-1: ",  N-1)

print(sum)

        


Measured memory_bytes: 60072
///Astalavista Code........~boy_with_no_gf
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define Br cout<<endl
#define int long long
#define double long double
#define all(v) v.begin(),v.end()
#define pb push_back
#define mk make_pair
#define allr(v) v.rbegin(),v.rend()
#define PT(x) cout << (x) << endl
#define PTT(x) cout << (#x) << " is " << (x) << endl; 
#define lets_go ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
const int M = 1e9 + 7;
const int N = 2e6 + 10;
const int IM = 1e15 + 37;
const double PI = 3.1415926535897932384;
inline void PP(int n) { cout << n << " ";}
void PV(vi v) { for (int i = 0 ; i < v.size() ; i++) cout << v[i] << " " ; cout << endl;}
void PVV(vii v) {for (int i = 0 ; i < v.size() ; i++) cout << v[i].first << " " << v[i].second << endl;}
void PA(int v[], int n, int x = 0) { for (int i = x ; i < n + x; i++)cout << v[i] << " " ; cout << endl;}
void IN(int a[], int n, int x = 0) {for (int i = x; i < n + x; i++)cin >> a[i];}
// <=================================================================================================================================
// <=================================================================================================================================

void fu(vi &arr){
    int n=arr.size();
    for(int i=2;i<n;i++){
        int j=1;
        while(i*j<n){
            arr[i*j]++;
            j++;
        }
    }
}

void fun(){
    int n;cin>>n;
    int ans=0;
    vi arr(n,1);
    arr[0]=0;
    // arr[1]=1;
    fu(arr);
    for(int i:arr){
        ans+=i;
    }
    cout<<ans;    
}

signed  main() {
    lets_go

    int t;
    t=1;
    //cin >> t;
    while (t--) {            
         fun();             
    }                        
                            
                            
    return 0;

}

Measured memory_bytes: 11044
a, b = map(int, input().split())
s = input()
check = True
if len(s) == a + b + 1:
    for i in range(len(s)):
        if i == a:
            if not (s[i] == '-'):
                check = False
        else:
            if not (s[i] in '0123456789'):
                check = False
else:
    check = False
if check:
    print("Yes")
else:
    print("No")

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

int main()
{
    // input
    int N, K;
    std::cin >> N >> K;

    std::vector<int> v;
    for (int i = 0; i < N; i++)
    {
        int input_v;
        std::cin >> input_v;
        v.push_back(input_v);
    }

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

    // make diff vector
    std::vector<int> v_headless, v_diff;
    v_headless = v;
    v_headless.erase(v_headless.begin());

    for (int i = 0; i < v.size() - 1; i++)
    {
        v_diff.push_back(v_headless[i] - v[i]);
    }

    // find answer
    int ans = 1000000000;
    int h_diff = 0;
    for (int i = 0; i < v_diff.size() - (K-2); i++)
    {
        h_diff = 0;
        for (int j = i; j < i + (K-1); j++)
        {
            h_diff += v_diff[j];
        }
        ans = std::min(ans, h_diff);
    }

    std::cout << ans << std::endl;

    return 0;
}

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

int main()
{
    int N;
	cin>>N;
	int A[N],S[N];
	int i,j;
	A[0]=0;	S[0]=0;
	for(i=1;i<N;i++){
	cin>>A[i];
	S[i]=0;	
	}
	for(i=N-1;i>=0;i--){
		S[A[i]-1]++;
	}
	for(i=0;i<N;i++){
		cout<<S[i]<<" ";
	}
   return 0;
}

Measured memory_bytes: 5196
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <algorithm>   
static int N;

static int matrix[100004][3];
static int h[100004][3];
using namespace std;


int solotion(int i, int last) {
	if (i >= N) {
		return 0;
	}
	int b = 0;
	for (int x = 1; x <= 3; x++) {
		if (x != last) {
			int a = matrix[i][x-1];
			if (h[i][x-1] == -1) {
				int y = solotion(i + 1, x) + a;
				if (y > b) {
					h[i][x-1] = y;
					b = y;
				}
			}
			else {
				int y = h[i][x - 1];
				if (y > b) {
					b = y;
				}
			}
		}
	}
	return b;
}

int main() {
	cin >> N;

	for (int i = 0; i < N; i++) {
		for (int j = 0; j < 3; j++) {
			cin >> matrix[i][j];
			h[i][j] = -1;
		}
	}

	printf("%d", solotion(0,0));
}



Measured memory_bytes: 10368
#include<iostream>
#include<cstdio>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<unordered_map>
#include<map>
#include<string>
#include<cstring>
#include<stack>
#include<cmath>

#define vint vector<int>
#define vstr vector<string>
#define vll vector<long long>
#define ll long long
#define pf printf
#define sf scanf
#define sfd(n) scanf("%d", &n)
#define sflf(n) scanf("%lf", &n)
#define sfll(n) scanf("%lld", &n)
#define pfd(n) printf("%d", n)
#define pflf(n) printf("%lf", n)
#define pfll(n) printf("%lld", n)
#define pft	printf("\t")
#define pfn printf("\n")
#define pfk printf(" ")
#define PI 3.1415926
#define MAX 100000
#define M 1e18

using namespace std;

int main() {
	ll w, h, x, y;
	sfll(w);
	sfll(h);
	sfll(x);
	sfll(y);
	int cnt = 0;
	if( x==w-x&&y==h-y ) {
		cnt++;
	}
	pf("%.6lf", double(w*h/2.0));
	pfk;
	if( cnt ) {
		pfd(1);
	}else {
		pfd(0);
	}

	return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var A, B int
	fmt.Scanf("%d %d", &A, &B)
	for i := 1; i < 10*(B+1); i++ {
		if 100*A <= 8*i && 8*i < 100*(A+1) && 100*B <= 10*i && 10*i < 100*(B+1) {
			fmt.Println(i)
			return
		}
	}
	fmt.Println(-1)
}


Measured memory_bytes: 512
import sys

N, M = map(int, input().split())
canMove = [[] for _ in range(N+1)]
for m in range(M):
  a, b = map(int, input().split())
  canMove[a].append(b)

for key in canMove[1]:
  if N in canMove[key]:
    print('POSSIBLE')
    sys.exit()

print('IMPOSSIBLE')


Measured memory_bytes: 29076
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;

int main() {

    int n, k; cin >> n >> k;
    vector<int> l(n);
    for (int i = 0; i < n; i++) {
        cin >> l[i];
    }
    sort(l.begin(), l.end(), greater<int>());

    int ans = 0;
    for (int i = 0; i < k; i++) {
        ans += l[i];
    }

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

Measured memory_bytes: 256
N,M,P = map(int, input().split())

es = []

for i in range(M):
    a,b,c = map(int, input().split())
    es.append((a-1, b-1, c))

INF = float("inf")

d = [INF for _ in range(N)] 
d[0] = 0
"""
頂点Nに向かうまでに関係ない閉路に注意する

無限にコインを拾える場合、
・ある閉路を一周したときの得点と支払いの収支がプラス
・その閉路からゴールまで行ける
である。これがない場合、全てのノードを経由してゴールまで行く（N-1回移動）までにコインの枚数が最大になる
なので、一回ベルマンフォード法をやった後もう一回行って一回目と２回目でゴールまでのコイン枚数に変化があればゴ、
ールに行くまでの道に無限にコインをとれる閉路があるといえる

"""

def solve(start, f):
    for i in range(N):
        for a,b,c, in es:
            if d[a] != INF and d[a] + (-c) + P < d[b]:
                # ２週目と区別する。２週目で更新される部分は-INFとか適当に置いておくと、ゴールまでの影響がわかる
                if f == 0:
                    d[b] = d[a] + (-c) + P
                else:
                    d[b] = -INF


    return d[-1]


first=solve(0,0)
second=solve(0, 1)
if first != second:
    print(-1)
else:
    print(max(-first, 0))



Measured memory_bytes: 50284
n = int(input())
a = list(map(int, input().split()))
flag = 0

for i in a:
    if i % 2 == 0:
        if i % 3 == 0 or i % 5 == 0:
            flag = 0
        else:
            flag = 1
            break

if flag == 0:
    print('APPROVED')
else:
    print('DENIED')


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rrep(i,a,b) for(int i=(int)(a);i>=(int)(b);--i)
#define fore(i,a) for(auto &i:a)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define isin(i,a,b) ((a) <= (i) && (i) < (b))
#define uni(a) (a).erase(unique(all(a)),(a).end())
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)(a).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll  = long long;
using unit= unsigned;
using ull = unsigned long long;
using P   = pair<int,int>;
using vi  = vector<int>;
using vl  = vector<ll>;
using vvi = vector<vi>;
using vp  = vector<P>;
void _main(); int main(){ cin.tie(0); ios::sync_with_stdio(false); _main(); }
template<class T>void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T>void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T>void POSS(T condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class T>void Poss(T condition){ if(condition) cout << "Possible" << endl; else cout << "Impossible" << endl; }
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<class T>T gcd(T a, T b){ if (b==0){ return a; }else{ return gcd(b, a%b); }}
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
constexpr double eps = 1e-10;
constexpr int inf = INT_MAX / 2;
constexpr ll infl = 1LL << 60;

void _main() {
  int N, M;
  cin >> N >> M;
  vi L(M), R(M);
  rep(i, 0, M) cin >> L[i] >> R[i];
  int l = 1;
  int r = N;

  rep(i, 0, M) {
    chmax(l, L[i]);
    chmin(r, R[i]);
  }

  int ans = max(0, r - l + 1);
  cout << ans << endl;
}

Measured memory_bytes: 1024
#C問題
import heapq
N = int(input())
A = list(map(int,input().split()))

a = []
for i in range(N):
    heapq.heappush(a,A[i])
B = []
for i in range(3*N):
    B.append(-A[3*N-1-i])
b = []
for i in range(N):
    heapq.heappush(b,B[i])

Red = [sum(a)]
Blue = [sum(b)]
inf = float("inf")
MAX = -inf
AR = []
BB = []
for i in range(N):
    AR.append(A[N+i])
    BB.append(B[N+i])
for i,(ar,r) in enumerate(zip(AR,Red)):
    l = heapq.heappushpop(a,ar)
    Red.append(r+(ar-l))
for i,(bb,bl) in enumerate(zip(BB,Blue)):
    m = heapq.heappushpop(b,bb)
    Blue.append(bl+(bb-m))
    
for i in range(N+1):
    #print(Red[i],Blue[N-i])
    MAX = max(MAX,Red[i]+Blue[N-i])

#print(A,B)
print(MAX)


Measured memory_bytes: 40268
#include <stdio.h>

int main(){
    int a = 0;
    int b = 0;
    scanf("%d %d", &a, &b);
    int sum = a + b;
    if(sum >= 10){
        printf("error\n");
    }else{
        printf("%d\n", sum);
    }
    return 0;
}


Measured memory_bytes: 128
N=int(input())
*A,=map(int,input().split())

mx=max(A)
mn=min(A)


if len(set(A))==1:
    print(0)
else:
    ans=float('inf')
    for i in range(mn,mx):
        ans=min(ans, sum([(k-i)**2 for k in A]))
    print(ans)


Measured memory_bytes: 9184
def decide(a, b):
    a_is_month = False
    b_is_month = False

    if a >= 1 and a <= 12:
        a_is_month = True

    if b >= 1 and b <= 12:
        b_is_month = True

    if a_is_month and b_is_month:
        print("AMBIGUOUS")
    elif a_is_month and not b_is_month:
        print("MMYY")
    elif b_is_month and not a_is_month:
        print("YYMM")
    else:
        print("NA")

s = input()

f, e = s[:2], s[2:]

decide(int(f), int(e))

Measured memory_bytes: 3064
//14
#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>

using namespace std;

typedef pair<int,int> P;

int nr,nc,m;
char g[50][51];
int ut[50][50];
int on[50][50];
int off[50][50];
int u[50][50];
vector<P> v(1);

bool dfs(P c,P d){
  if(g[c.second][c.first]=='#'||u[c.second][c.first])return false;
  u[c.second][c.first]=1;
  if(c==d)return true;
  for(int i=0;i<4;i++){
    int dr[]={0,-1,0,1,0};
    int nx=c.first+dr[i];
    int ny=c.second+dr[i+1];
    if(ny<0||nr<=ny||nx<0||nc<=nx)continue;
    if(dfs(P(nx,ny),d)){
      v.push_back(c);
      return true;
    }
  }
  u[c.second][c.first]=0;
  return false;
}

int main(){
  cin>>nr>>nc>>m;
  for(int i=0;i<nr;i++){
    cin>>g[i];
  }
  for(int i=0;i<nr;i++){
    for(int j=0;j<nc;j++){
      cin>>ut[i][j];
    }
  }
  for(int i=0;i<nr;i++){
    for(int j=0;j<nc;j++){
      cin>>on[i][j];
    }
  }
  for(int i=0;i<nr;i++){
    for(int j=0;j<nc;j++){
      cin>>off[i][j];
    }
  }
  cin>>v[0].second>>v[0].first;
  for(int i=0;i<m-1;i++){
    P p;
    cin>>p.second>>p.first;
    fill(u[0],u[nr],0);
    dfs(p,v.back());
  }
  bool l[50][50]={};
  int p=0;
  for(int i=0;i<v.size();i++){
    int y=v[i].second;
    int x=v[i].first;
    if(!l[y][x]){
      p+=on[y][x];
    }
    int nx=find(v.begin()+i+1,v.end(),v[i])-v.begin();
    if(nx==v.size()||on[y][x]+off[y][x]<ut[y][x]*(nx-i)){
      p+=off[y][x];
      l[y][x]=false;
    }else{
      p+=ut[y][x]*(nx-i);
      l[y][x]=true;
    }
  }
  cout<<p<<endl;
  return 0;
}

Measured memory_bytes: 19428
# -*- coding: utf-8 -*-
N,T=map(int,raw_input().split())
t=map(int,raw_input().split())

sum=0
for i,v in enumerate(t):
	if i==0:pass
	elif (v-t[i-1])>=T:sum+=T
	else:sum+=v-t[i-1]

print sum+T

Measured memory_bytes: 20060
import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    K, T = map(int, readline().split())
    A = list(map(int, readline().split()))
    if sum(A)-max(A)+1 <max(A):
        print(max(A)*2-sum(A)-1)
    else:
        print(0)



if __name__ == '__main__':
    main()


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

using namespace std ;

const int MAX = 5 ;

int arr[MAX][MAX] , mark[MAX][MAX] ;
int n ;

int main()
{
	ios_base::sync_with_stdio(0) ;
	cin.tie(0) ;
	for(int i = 0 ; i < 3 ; ++i)
	{
		for(int j = 0 ; j < 3 ; ++j)
			cin>>arr[i][j] ;
	}
	cin>>n ;
	while(n--)
	{
		int x  ;
		cin>>x ;
		for(int i = 0 ; i < 3 ; ++i)
		{
			for(int j = 0 ; j < 3 ; ++j)
			{
				if(arr[i][j] == x)
					mark[i][j] = 1; 
			}
		}
	}
	if(mark[0][0] && mark[1][1] && mark[2][2])
		return cout<<"Yes\n" , 0 ;
	if(mark[0][2] && mark[1][1] && mark[2][0])
		return cout<<"Yes\n" , 0 ;
	if(mark[0][0] && mark[0][1] && mark[0][2])
		return cout<<"Yes\n" , 0 ;
	if(mark[1][0] && mark[1][1] && mark[1][2])
		return cout<<"Yes\n" , 0 ;
	if(mark[2][0] && mark[2][1] && mark[2][2])
		return cout<<"Yes\n" , 0 ;
	for(int j = 0 ; j < 3 ; ++j)
	{
		bool flag = true ;
		for(int i = 0 ; i < 3 ; ++i)
			flag &= (mark[i][j]) ;
		if(flag)
			return cout<<"Yes\n" , 0 ;
	}
	return cout<<"No\n" , 0  ;
}		

Measured memory_bytes: 256
#prag\
ma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;

int n;
int a[4005];
char col[4005];
int cw[2005][2005];
int cb[2005][2005];
int b[2005];
int w[2005];
int counts_b[2005];
int counts_w[2005];
int dp[2005][2005];

int main() {
  cin >> n;
  for (int i = 0; i < 2 * n; i++) {
    cin >> col[i] >> a[i];
    a[i]--;
    if (col[i] == 'W') w[a[i]] = i;
    else b[a[i]] = i;
  }

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < i; j++) {
      if (b[i] < b[j]) counts_b[i]++;
      if (w[i] < w[j]) counts_w[i]++;
    }
  }

  cb[0][0] = 0;
  cw[0][0] = 0;
  for (int i = 0; i < n; i++) {
    cb[i][0] = counts_b[i];
    cw[i][0] = counts_w[i];
    int count_b = counts_b[i];
    int count_w = counts_w[i];
    for (int j = 0; j < n; j++) {
      if (b[i] < w[j]) count_b++;
      if (w[i] < b[j]) count_w++;
      cb[i][j + 1] = count_b;
      cw[i][j + 1] = count_w;
    }
  }

  dp[0][0] = 0;
  for (int i = 1; i <= n; i++) {
    dp[i][0] = dp[i - 1][0] + cb[i - 1][0];
    dp[0][i] = dp[0][i - 1] + cw[i - 1][0];
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      dp[i][j] = min(dp[i - 1][j] + cb[i - 1][j], dp[i][j - 1] + cw[j - 1][i]);
    }
  }
  cout << dp[n][n];
}


Measured memory_bytes: 47360
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mp make_pair
#define pb push_back
#define x first
#define y second
#define pii pair<int, int>
#define p3i pair<pii, int>
#define pll pair<ll, ll>
#define p3l pair<pll, ll>
#define lseg L, (L+R)/2, N*2+1
#define rseg (L+R)/2+1, R, N*2+2
#define ub upper_bound
#define lb lower_bound
#define pq priority_queue
#define MN 1000000007
#define fox(k, x) for (int k=0; k<x; ++k)
#define fox1(k, x) for (int k=1; k<=x; ++k)
#define foxr(k, x) for (int k=x-1; k>=0; --k)
#define fox1r(k, x) for (int k=x; k>0; --k)
#define ms multiset
#define flood(x) memset(x, 0x3f3f3f3f, sizeof x)
#define drain(x) memset(x, 0, sizeof x)
#define rng() (rand() >> 3)*rand()
#define scan(X) do{while((X=getchar())<'0'); for(X-='0'; '0'<=(_=getchar()); X=(X<<3)+(X<<1)+_-'0');}while(0)
char _;
#define pi 3.14159265358979323846

ll n, m;
int main(){
    cin >> n >> m;
    if (n==1 && m==1) cout << 1;
    else if (n==1) cout << m-2;
    else if (m==1) cout << n-2;
    else cout << n*m-2*n-2*m+4;
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace C
{
    class Program
    {
        static void Main(string[] args)
        {
            var k = IOUtils.ReadNums().First();
            long sum = 0;
            for (int a = 1; a <= k; a++)
            {
                for (int b = 1; b <= k; b++)
                {
                    for (int c = 1; c <= k; c++)
                    {
                        sum += Gcd(a, b, c);
                    }
                }
            }

            Console.WriteLine(sum);

        }

        private static long Gcd(long a, long b, long c)
        {
            var ab = Gcd(a, b);
            return Gcd(ab, c);
        }

        private static long Gcd(long a, long b)
        {
            if (a < b)
            {
                return Gcd(b, a);
            }
            while (b != 0)
            {
                var remainder = a % b;
                a = b;
                b = remainder;
            }
            return a;
        }
    }

    static class IOUtils
    {
        public static IEnumerable<int> ReadNums()
        {
            return Console.ReadLine().Split(' ').Select(v => int.Parse(v));
        }

        public static void WriteNums(params int[] nums)
        {
            Console.WriteLine(string.Join(" ", nums));
        }
    }
}


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

bool IsPrime(long long num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}

int main() {
    long long X;
    cin >> X;
    while(true) {
        if(IsPrime(X) == true) {
            cout << X << endl;
            exit(0);
        }
        X++;
    }

}

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

int main() {
  int n;
  cin >> n;
  if (n == 1) {
    puts("! 1");
    return 0;
  }

  int last_num;
  int distance = 0;
  for (int i = 2; i <= n; i++) {
    cout << "? 1 " << i << endl;
    cout.flush();
    int temp;
    cin >> temp;
    if (distance < temp) {
      last_num = i;
      // cout << "last_num : " << last_num << endl;
      distance = temp;
    }
  }

  int distance_list[10000];
  distance_list[0] = last_num;
  for (int i = 1; i <= n; i++) {
    cout << "? " << last_num << " " << i << endl;
    cout.flush();
    int temp;
    cin >> temp;
    distance_list[temp] = i;
  }

  cout << "!";
  for (int i = 0; i < n; i++) {
    cout << " " << distance_list[i];
  }
  puts("");
}

Measured memory_bytes: 3608
#include <stdio.h>

static int N;
static int B[100];

int search(int i, int *data) {
  if(i == 0) {
    return 1;
  }

  int idx = 0;
  for(int j = i - 1; j >= 0; j--) {
    if(data[j] == (j+1)) {
      idx = j+1;
      break;
    }
  }
  if(idx == 0)
    return 0;

  int newdata[100];
  int dst = 0;
  for(int k = 0; k < i; k++) {
    if(k != (idx-1))
       newdata[dst++] = data[k];
  }
  if(search(i-1, newdata) == 1) {
    printf("%d\n", idx);
    return 1;
  }
  return 0;
}

int main(void) {
  scanf("%d", &N);
  for(int i = 0; i < N; i++) {
    scanf("%d", &B[i]);
  }
  if(search(N, B) == 0) {
    printf("-1\n");
  }
  return 0;
}


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

using namespace std;

int main()
{
	string s, ans;
	
	cin >> s;
	
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'B') {
			if (ans.empty() != 1) {
				ans.erase(ans.size() - 1);
			}
		}
		else {
			ans += s[i];
		}
	}
	
	cout << ans << endl;
	
	return (0);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  
  int A;
  int B;
  cin >> A >> B;
  
  int num;
  int num2 = 1;
  
  if(B == 1){
    cout << "0" << endl;
    
  }
  else{
  while(true){
    if(num2 == 1){
      num = A;
    }
    else{
      num = num + (A - 1);
    }
    if(num >= B){
      cout << num2 << endl;
      break;
    }
    num2++;
  }
  }
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int x;
    cin >> x;
    cout << ((x / 100)*5 >= (x % 100) ? 1 : 0) << '\n';
}


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

bool isPalindrome( string s, int l )
{
    for ( int i = 0; i < l / 2; i++ )
        if ( s[i] != s[l-i-1] )
            return false;
    
    return true;
}

int main( void )
{
    string s;
    cin >> s;
    int l = s.length();
    string half = s.substr(0,l/2);
    
    bool kaibun = isPalindrome(s,l);
    bool tsuyoi = isPalindrome(half,l/2);
    
    if ( kaibun && tsuyoi )
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int main(){
	int n;
	while(cin>>n,n){
		vector<int>in(n);
		rep(i,n)cin>>in[i];
		int co=0;
		while(1){
			co++;
			map<int,int>a;
			rep(i,n)a[in[i]]++;
			bool h=true;
			rep(i,n){
				if(in[i]!=a[in[i]])h=false;
				in[i]=a[in[i]];
			}
			if(h)break;
		}
		cout<<co-1<<endl;
		rep(i,n-1)cout<<in[i]<<" ";
		cout<<in[n-1]<<endl;
	}
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N, num, count;
    cin >> N;
    vector<int> a(N);
    for(int i=0;i<N;i++){
        cin >> a[i];
    }
    sort(a.begin(),a.end());
    int i=1;
    count = 0;
    num = 1;
    int tmp = a[0];
    while(i<N){
        if(a[i] == tmp){
            num++;
            i++;
        }else{
            if(num%2 == 1) count++;
            num = 1;
            tmp = a[i];
            i++;
        }
    }
    if(num%2 == 1) count++;
    cout << count << endl;
}


Measured memory_bytes: 640
n = int(input())
otoshidama = []
for i in range(n):
    x, u = input().split()
    x = float(x)
    if u == "JPY":
        otoshidama.append(x)
    else:
        otoshidama.append(x*380000)
ans = sum(otoshidama)
print(f"{ans:.5f}")


Measured memory_bytes: 61780
#include <stdio.h>

int main(void){
  int n;
  int a[100005],b[100005];
  
  scanf("%d", &n);
  int i=0;
  for(i=0;i<n;i++){
    scanf("%d", &a[i]);
    b[a[i]-1]=i+1;
  }
  for(int i=0;i<n;i++){
    printf("%d ", b[i]);
   }

    
    return 0;
  }
  

Measured memory_bytes: 2476