akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define vl vaector<long>
#define vll vector<long long int>
#define vC  vector<char>
#define FastIO ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define db(...) ZZ(#__VA_ARGS__, __VA_ARGS__)
ll pow(ll x, ll y,ll m) { ll res = 1;x=x%m; while (y > 0) { if (y & 1) res = ((res%m) * (x%m))%m; y = y >> 1; x = ((x%m) * (x%m))%m; } return res%m; }
template <typename Arg1> void ZZ(const char* name, Arg1&& arg1){std::cerr << name << " = " << arg1 << endl;}
template <typename Arg1, typename... Args>void ZZ(const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr(names + 1, ',');
	std::cerr.write(names, comma - names) << " = " << arg1;
	ZZ(comma, args...);
}
const ll INF = 0xFFFFFFFFFFFFFFFL;
clock_t time_p=clock();
void abhigyan10()
{time_p=clock()-time_p;cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";}
ll seed;
mt19937 rng(seed=chrono::steady_clock::now().time_since_epoch().count());
inline ll rnd(ll l=0,ll r=INF){return uniform_int_distribution<ll>(l,r)(rng);}
#define clrbuf cin.ignore(numeric_limits<streamsize>::max(),'\n');
#define preciset(x) cout<<setprecision(x)<<fixed;
const ll mod =1000000007;
int main()
{
        FastIO

        int n,i,f=0;
        cin>>n;
        set<string> s;
        string temp;
        map<string,int> m; 
        for(i=0;i<n;i++)
        {
        	cin>>temp;
        	m[temp]++;
        	f=max(f,m[temp]);
        	s.insert(temp);
        }
        
        for(auto x:s)
        {
        	if(m[x]==f)
        		cout<<x<<"\n";
        }

        return 0;

    }

Measured memory_bytes: 33280
import fractions


def lcm(x, y):
    return int((x * y) // fractions.gcd(x, y))

n, m = [int(i) for i in input().split()]
s = input()
t = input()

span = fractions.gcd(n, m)
for i in range(span):
    if s[int(n/span)*i] != t[int(m/span)*i]:
        print("-1")
        exit()
print(lcm(n, m))


Measured memory_bytes: 5340
n = gets.to_i
b = gets.split.map{|e|e.to_i}
a = Array.new(n , 0)
r = true
n.times do |i|
    g = b[-i-1] - n + i
    if g > 0 || g < -n
        r = false
    else
        count = 0
        n.times do |j|
            if a[-j-1] == 0
                count -= 1
            end
            if g == count+1
                a[-j-1] = b[-i-1]
                break
            end
        end
    end
    if !r
        break
    end
end
if !r
    puts -1
else
    puts a.*("\n")
end
            



Measured memory_bytes: 1788
#include <iostream>

using namespace std;

int main(){
    int N;
    int B[100];
    cin >> N;
    for(int i = 0; i < N-1; i++){
        cin >> B[i];
    }
    int ans = 0;
    ans += B[0];
    for(int i = 1; i < N-1; i++){
        ans += min(B[i], B[i-1]);
       // cout << ans << endl;
    }
    ans += B[N-2];
    cout << ans << endl;
}

Measured memory_bytes: 256
package main

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

// AtCoder Functions
var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	N := nextInt()

	fmt.Println(N * N * N)
}


Measured memory_bytes: 640
# -*- 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 ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N,M=MAP()
broken=[False]*(N+1)
for i in range(M):
    a=INT()
    broken[a]=True

dp=[0]*(N+1)
dp[0]=1
for i in range(N):
    if not broken[i+1]:
        dp[i+1]+=dp[i]
        dp[i+1]%=MOD
    if i!=N-1 and not broken[i+2]:
        dp[i+2]+=dp[i]
        dp[i+2]%=MOD
print(dp[N])


Measured memory_bytes: 7796
#include<bits/stdc++.h>
using namespace std ; 
int main()
{
	long long n , a , b , c , cnt=0 ; 
	cin >> a >> b >> c >> n;
	for(int i=0 ; i<=a ; i++)
		for(int j=0 ; j<=b ; j++)
			for(int k=0 ; k<=c ; k++)
				cnt+=(i*500 + j*100 + k*50 == n) ;
	cout << cnt  << endl ; 
}

Measured memory_bytes: 256
# abc154_a.py
# https://atcoder.jp/contests/abc154/tasks/abc154_a

# A - Remaining Balls /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点 : 100点

# 問題文
# 文字列 Sの書かれたボールが A 個、文字列 T の書かれたボールが B 個あります。
# 高橋君は、文字列 U の書かれたボールを 1 個選んで捨てました。
# 文字列 S,Tの書かれたボールがそれぞれ何個残っているか求めてください。

# 制約
#     S,T,Uは英小文字のみからなる文字列
#     S,Tの長さは 1 以上 10以下
#     S≠T
#     S=Uまたは T=U
#     1≤A,B≤10
#     A,Bは整数

# 入力
# 入力は以下の形式で標準入力から与えられる。
# S T
# A B
# U

# 出力
# 答えを空白区切りで出力せよ。

# 入力例 1
# red blue
# 3 4
# red

# 出力例 1
# 2 4

# 高橋君は red が書かれたボールを 1つ選んで捨てました。
# 文字列 S,T が書かれたボールは、それぞれ 2,4個残っています。

# 入力例 2
# red blue
# 5 5
# blue

# 出力例 2
# 5 4

# 高橋君は blue が書かれたボールを 1つ選んで捨てました。
# 文字列 S,T が書かれたボールは、それぞれ 5,4 個残っています。


global FLAG_LOG
FLAG_LOG = False


def log(value):
    # FLAG_LOG = True
    # FLAG_LOG = False
    if FLAG_LOG:
        print(str(value))


def calculation(lines):
    S, T = lines[0].split()
    A, B = list(map(int, lines[1].split()))
    U = lines[2]
    # values = list(map(int, lines[1].split()))
    # values = list(map(int, lines[2].split()))
    # values = list()
    # for i in range(N):
    #     values.append(int(lines[i]))
    # valueses = list()
    # for i in range(N):
    #     valueses.append(list(map(int, lines[i+1].split())))

    if U == S:
        A -= 1
    else:
        B -= 1

    result = str(A) + ' ' + str(B)

    return [result]


# 引数を取得
def get_input_lines(lines_count):
    lines = list()
    for _ in range(lines_count):
        lines.append(input())
    return lines


# テストデータ
def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['red blue', '3 4', 'red']
        lines_export = ['2 4']
    if pattern == 2:
        lines_input = ['red blue', '5 5', 'blue']
        lines_export = ['5 4']
    return lines_input, lines_export


# 動作モード判別
def get_mode():
    import sys
    args = sys.argv
    global FLAG_LOG
    if len(args) == 1:
        mode = 0
        FLAG_LOG = False
    else:
        mode = int(args[1])
        FLAG_LOG = True
    return mode


# 主処理
def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines(3)
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    # if mode > 0:
    #     print(f'lines_input=[{lines_input}]')
    #     print(f'lines_export=[{lines_export}]')
    #     print(f'lines_result=[{lines_result}]')
    #     if lines_result == lines_export:
    #         print('OK')
    #     else:
    #         print('NG')
    # finished = time.time()
    # duration = finished - started
    # print(f'duration=[{duration}]')


# 起動処理
if __name__ == '__main__':
    main()


Measured memory_bytes: 9156
#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>;
const int MAX = 100000;
const int INF = 1e9;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};
#define PI 3.14159265358979323846264338327950L
#define MOD 1000000007
//setprecision(15)

// 素因数分解O(√n)
map<int, int> prime_factor(int n) {
	map<int, int> res;
	for (int i = 2; i*i <= n; i++) {
		while (n % i == 0) {
			++res[i];
			n /= i;
		}
	}
	if (n != 1) res[n] = 1;
	return res;
}
// ax+by=gcd(a,b)の解(x,y)を求める
ll extgcd(ll a, ll b, ll& x, ll& y) {
	ll d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a/b) * x;
	} else {
		x = 1; y = 0;
	}
	return d;
}
ll mod_inverse(ll a, ll m) {
	ll x, y;
	extgcd(a, m, x, y);
	return (m + x % m) % m;
}
#define MAX_P 200000
ll fact[MAX_P];	// n! mod p のテーブル O(p)
void make_fact(ll p) {
	ll n, wp;
	for (ll i = 0; i < MAX_P; i++) {
		if (i == 0) n = 1;
		else n = (n * i) % p;
		fact[i] = n;
	}
}
// n!=a p^eとしたときのa mod pを求める。O(log_p n)
ll mod_fact(ll n, ll p, ll& e) {
	e = 0;
	if (n == 0) return 1;

	// pの倍数の部分を計算
	ll res = mod_fact(n/p, p, e);
	e += n / p;

	// (p-1)!≡-1なので,(p-1)!^(n/p)はn/pの偶奇だけで計算できる
	if (n/p % 2 != 0) return res * (p - fact[n%p]) % p;
	return res * fact[n%p] % p;
}
// nCk mod pを求める。O(log_p n)
ll mod_comb(ll n, ll k, ll p) {
	if (n < 0 || k < 0 || n < k) return 0;
	ll e1, e2, e3;
	ll a1 = mod_fact(n, p, e1), a2 = mod_fact(k, p, e2), a3 = mod_fact(n-k, p, e3);
	if (e1 > e2 + e3) return 0;
	return a1 * mod_inverse((a2*a3)%p, p) % p;
}

int main() {
	make_fact(MOD);
	int N, M; cin >> N >> M;
	map<int, int> ma = prime_factor(M);
	ll ans = 1;
	for (auto i = ma.begin(); i != ma.end(); i++) {
		ans = ans * mod_comb(i->second+N-1, N-1, MOD) % MOD;
	}
	cout << ans << endl;
}

Measured memory_bytes: 5172
N = gets.chomp
strs = gets.chomp.split(' ').map(&:to_i)
ans = 0
strs.each_with_index do |str, idx|
  if idx == 0 || idx == strs.size-1
    next
  else
    ans += 1 if [strs[idx-1],strs[idx],strs[idx+1]].sort[1] == strs[idx]
  end
end
puts ans

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

int main() {
    int a;
    int b;
    int c;
    int counter = 0;
    cin >> a >> b >> c;
    for(a ; a <= b ; a ++){
        if(c % a == 0){
            counter ++ ;
        }
    }
    cout << counter << endl;
}


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

using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int N, M;
	cin >> N >> M;
	vector<int>a(N), b(N);
	for (int i = 0; i < M; i++){
		int c, d;
		cin >> c >> d;
		if (c == 1) {
			a[d] = 1;
		}
		if (d == N) {
			b[c] = 1;
		}
	}

	for (int i = 0; i < N; i++){
		if (a[i] == 1 && b[i] == 1) {
			cout << "POSSIBLE" << endl;
			return 0;
		}
	}
	cout << "IMPOSSIBLE" << endl;

	return 0;
}

Measured memory_bytes: 1792
line = []
while True:
    b = list(map(int, input().split()))
    if b[0] == 0 and b[1] == 0:
        break
    else:
        line.append(b)
for i in line:
    for j in range(i[0]):
        for k in range(i[1]):
            if (j + k) % 2 == 0:
                print("#", end ="")
            else:
                print(".", end = "")
        print()
    print()


Measured memory_bytes: 7004
from itertools import permutations
#N = int(input())
N,M = map(int,input().split())
ab=[[]for i in range(N)]
for i in range(M):
    a,b = list(map(int,input().split()))
    ab[a-1].append(b-1)
    ab[b-1].append(a-1)
num = [i+1 for i in range(N-1)]
count = 0
for i in permutations(num):
    flag = True
    if i[0] not in ab[0]:
        continue
    for j in range(len(i)-1):
        if i[j+1] not in ab[i[j]]:
            flag = False
    if flag:
        count += 1
print(count)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include<boost/algorithm/string/replace.hpp>
#include<boost/multiprecision/cpp_int.hpp>
using namespace std;
using namespace boost::algorithm;
using namespace boost::multiprecision;
 
#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define ALL(x) (x).begin(),(x).end()

typedef long long ll;
typedef unsigned long long ull;
 
const int INF = 1e9;
const int MOD = 1e9+7;

//C++17
template<typename Type>
Type GCD(Type a,Type b){ return b ? GCD(b,a%b) : a ;}
template<typename Type>
Type LCM(Type a,Type b){ return a*b / GCD(a,b) ;}

template<typename Type>//文字列の置換/Boost:replace_all()
Type replace_str(Type str, string target, string str_to) {
    string::size_type pos = 0;
    while (pos = str.find(target, pos), pos != string::npos) {
        str.replace(pos, target.length(), str_to);
        pos += str_to.length();
    }
    return str;
}

int main() {
  int a,b,c,d,e,f;
      cin >>a>>b>>c>>d>>e>>f;
      int water=0,sugar=0;
 
      double Max = 0;
      pair<int,int> ans;
      for(int x1=0;x1*a*100<=f;x1++){
            for(int x2=0;x2*b*100<=f;x2++){
                  water = 100*a*x1 + 100*b*x2;
                  if(water > f)continue;
                  for(int x3=0;x3*c<=f;x3++){
                        for(int x4=0;x4*d<=f;x4++){
                              if(x1+x2+x3+x4 == 0)continue;
                              sugar = c*x3 + d*x4;
                              if(water+sugar > f)continue;
                              if(sugar <= (water/100)*e){
                                    double tmp = (sugar*100*1.0) / (water+sugar);
                                    if(tmp > Max){
                                          Max = tmp;
                                          ans = make_pair(water+sugar,sugar);
                                    }
                              }
                        }
                  }
                  
            }
      }
    if(ans.second == 0)cout << a*100 << ' ' << 0 << endl;
    else cout << ans.first << ' ' << ans.second << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
	char c;int n=0,s=0,w=0,e=0;
	while(cin>>c){
		switch(c){
			case 'N':n=1;break;
			case 'S':s=1;break;
			case 'W':w=1;break;
			case 'E':e=1;break;
		}
	}
	if(n){
		if(!s){
			cout<<"No"<<endl;
		}else if(e){
			if(!w){
				cout<<"No"<<endl;
			}else{
				cout<<"Yes"<<endl;
			}
		}else if(w){
			cout<<"No"<<endl;
		}else{
			cout<<"Yes"<<endl;
		}
	}else if(e){
		if((!w)||s){
			cout<<"No"<<endl;
		}else{
			cout<<"Yes"<<endl;
		}
	}else if(s||w){
		cout<<"No"<<endl;
	}else{
		cout<<"Yes"<<endl;
	}
	return 0;
}

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

using namespace std;

int64_t solve(int64_t a, int64_t b) {
  if (a == b) {
    return a * 2;
  }
  if (a > b) {
    return a * 2 - 1;
  }
  return b * 2 - 1;
}

int main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  int64_t a;
  std::cin >> a;
  int64_t b;
  std::cin >> b;
  auto const res = solve(a, b);
  std::cout << res << std::endl;
  return 0;
}


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

const int maxn=105;

int n,x,ans;
int a[maxn];

int main()
{
	scanf("%d%d",&n,&x);
	for (int i=1; i<=n; i++)
		scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	int cur=1;
	while (x>=a[cur])
	{
		x-=a[cur];
		ans++;
		if (cur==n)
		{
			if (x>0) ans--;
			break;
		}
		cur++;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main ()
{
	int h1,h2,k1,k2,a,b,c,d;

	cin >> h1 >> h2 >> k1 >> k2;
	cin >> a >> b >> c >> d;

	int H = 0,K = 0;

	H += (a * h1) + (b * h2);
	K += (a * k1) + (b * k2);

	H += (c * (h1 / 10)) + (d * (h2 / 20));
	K += (c * (k1 / 10)) + (d * (k2 / 20));

	if (H < K)
	{
		cout << "kenjiro" << endl;
	}
	else if (H == K)
	{
		cout << "even" << endl;
	}
	else
	{
		cout << "hiroshi" << endl;
	}
}


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

#define FOR(a, b, c) for (int a = (b), _for = (c); a < _for; ++a)
#define REP(a, n) FOR(a, 0, n)
#define x first
#define y second
#define pb push_back
#define pii pair<int, int>
#define ll long long
#define lf double

using namespace std;

const int MAX = 100;
const int INF = 17000;

int x,y;

int a[MAX][MAX];
int b[MAX][MAX];

bool dp[MAX][MAX][INF+4];

void test(int i,int j,int k){
	if (i>=x || j>=y) return;
	if (k>=INF) return;
	dp[i][j][k]=1;
}

int main(){
	scanf ("%d%d",&x,&y);
	REP(i,x) REP(j,y) scanf ("%d",&a[i][j]);
	REP(i,x) REP(j,y) scanf ("%d",&b[i][j]);
	REP(i,x) REP(j,y) a[i][j]=abs(a[i][j]-b[i][j]);
	dp[0][0][a[0][0]]=1;
	REP(i,x) REP(j,y) REP(k,INF){
		if (!dp[i][j][k]) continue;
		test(i+1,j,k+a[i+1][j]);
		test(i+1,j,abs(k-a[i+1][j]));
		test(i,j+1,k+a[i][j+1]);
		test(i,j+1,abs(k-a[i][j+1]));
	}
	REP(i,INF) if (dp[x-1][y-1][i]){
		printf ("%d\n",i);
		return 0;
	}
	
	
	
	return 0;
}


Measured memory_bytes: 132096
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll inf =1LL << 62;
const ll mod=1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b,const ll &mod) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1,6);
uniform_real_distribution<double> score(0.0,10.0);

int n, K;
vi a;

bool check(int x){
    vi dp(K);
    dp[0] = true;
    rep(i, n){
        if(i == x) continue;
        vi next(K);
        rep(j, K){
            if(not dp[j]) continue;
            if(j + a[x] >= K){
                cerr << "!! " << x << " " << j << endl;
                return false;
            }
            next[j] = true;
            int nj = j + a[i];
            if(nj >= K) continue;
            next[nj] = true;
        }
        dp = next;
    }
    rep(i, K) if(dp[i] and i + a[x] >= K) return false;
    return true;
}

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

    cin >> n >> K;
    a = {0};
    rep(i, n){
        int b; cin >> b;
        if(b >= K) continue;
        a.emplace_back(b);
    }
    sort(_all(a));
    n = (int)a.size();

    vi dp(K);
    int lb = 0, ub = n;
    while(ub - lb > 1){
        int mid = (lb + ub) / 2;
        if(check(mid)){
            lb = mid;
        }
        else {
            ub = mid;
        }
    }

    cout << lb << endl;

    return 0;
}


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

using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define fin(ans) cout << (ans) << endl;
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

typedef long long ll;
typedef long long lli;
typedef unsigned long long ull;
typedef long double ld;
typedef string str;

typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<ll> vll;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<ll, str>> vpls;
typedef vector<tuple<str, ll, ll>> vtsl;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

//実行部
void Main()
{
  ll n, k; cin >> n >> k;
  if(k == 1) fin(0)
  else
  {
    n -= (k - 1);
    fin(n - 1)
  }
  
  return;
}

//前処理
int main()
{
  //ios::sync_with_stdio(false);
  //cin.tie(0);
  cout << fixed << setprecision(20); //高精度少数表示
  Main();
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
using namespace std;
 
int main(){
    while(1){
    int x,y;
    cin >> x >>y;
    if(x==0&&y==0)
    {break;} 
    int i, j;
    for ( i = 0; i < x; i++ ){
    for ( j = 0; j < y; j++ ){
        if(i%2+j%2==1){
            printf(".");
        } else {
            printf("#");
        }}
    printf("\n");
    }
	printf("\n");}
    return 0;
	}


Measured memory_bytes: 1112
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		String S = scanner.next();
		String T = scanner.next();
		int result = 0;
		for(int i = 0; i < S.length(); i++)
			if(S.charAt(i) != T.charAt(i))
				result++;
		System.out.println(result);
	}
}

Measured memory_bytes: 32160
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Main
{

	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);

		int n = Integer.parseInt(sc.next());

		List<String> cities = new ArrayList<>();
		List<Integer> points = new ArrayList<>();

		for (int i = 0; i < n; i++) {
			cities.add(sc.next());
			points.add(Integer.parseInt(sc.next()));
		}

		List<String> citiesInOrder = new ArrayList<>();

		for (int i = 0; i < n; i++) {
			if (!citiesInOrder.contains(cities.get(i))) {
				citiesInOrder.add(cities.get(i));
				Collections.sort(citiesInOrder, Comparator.naturalOrder());
			}
		}

		for (int i = 0; i < n; i++) {
			String city = cities.get(i);

			points.set(i, (citiesInOrder.size() - (IntStream.range(0, citiesInOrder.size()).map(j -> citiesInOrder.get(j).equals(city) ? j : -1).filter(j -> j >= 0).min().getAsInt())) * 1000 + points.get(i));
		}

		List<Integer> pointsInOrder = points.stream().sorted(Comparator.reverseOrder()).collect(Collectors.toList());

		List<Integer> ranks = new ArrayList<>();

		for (int i = 0; i < n; i++) {
			int point = points.get(i);

			ranks.add(IntStream.range(0, n).map(j -> pointsInOrder.get(j).equals(point) ? j : -1).filter(j -> j >= 0).min().getAsInt() + 1);
		}

		for (int i = 1; i <= n; i++) {
			int mokeke = i;

			System.out.println(IntStream.range(0, n)
										.map(j -> ranks.get(j).equals(mokeke) ? j : -1)
										.filter(j -> j >= 0).min().getAsInt() + 1);
		}



		sc.close();
	}
}

Measured memory_bytes: 28368
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < int(n); i++)
#define rep1(i,n) for (int i = 1; i <= int(n); i++)
#define repR(i,n) for (int i = int(n)-1; i >= 0; i--)
#define rep1R(i,n) for (int i = int(n); i >= 1; i--)
#define loop(i,a,B) for (int i = a; i B; i++)
#define loopR(i,a,B) for (int i = a; i B; i--)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fst first
#define snd second
#define cauto const auto
#ifdef LOCAL
#define dump(...) cerr << "[" << __LINE__ << ":" << __FUNCTION__ << "] ", my_dmp(#__VA_ARGS__, __VA_ARGS__)
void my_dmp(const char*) { cerr << endl; }
template <class T, class... U>
void my_dmp(const char *s, T const& x, U const& ...y) { const char *o = "({[", *e = "]})"; for (int i = 0; *s != '\0'; cerr << *s++) { if (count(o,o+3,*s)) i++; if (count(e,e+3,*s)) i--; if (!i && *s == ',') break; } cerr << " = " << x; if (*s == ',') cerr << ", ", s++; my_dmp(s, y...); }
#else
#define dump(...)
#endif
using ll = long long;
#define int ll
template <class T> using pque_max = priority_queue<T>;
template <class T> using pque_min = priority_queue<T, vector<T>, greater<T> >;
#define CONAINER_OUTPUT os << "{"; for (auto const& x : v) os << " " << x; return os << " }";
template <class T> ostream& operator<<(ostream& os, vector<T> const& v) { CONAINER_OUTPUT }
template <class T> ostream& operator<<(ostream& os, deque<T> const& v) { CONAINER_OUTPUT }
template <class T> ostream& operator<<(ostream& os, set<T> const& v) { CONAINER_OUTPUT }
template <class T> ostream& operator<<(ostream& os, multiset<T> const& v) { CONAINER_OUTPUT }
template <class T, class U> ostream& operator<<(ostream& os, map<T,U> const& v) { CONAINER_OUTPUT }
#undef CONAINER_OUTPUT
template <class T> istream& operator>>(istream& is, vector<T>& v) { for (auto& x : v) is >> x; return is; }
template <class T, class S> ostream& operator<<(ostream& os, pair<T,S> const& p) { return os << "(" << p.first << ", " << p.second << ")"; }
template <class T, class S> istream& operator>>(istream& is, pair<T,S>& p) { return is >> p.first >> p.second; }
struct my_Init { my_Init() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(20); } } my_init;

template <class T> void quit(T const& x) { cout << x << endl; exit(0); }
template <class T> bool chmin(T& x, T const& y) { if (x > y) { x = y; return true; } return false; }
template <class T> bool chmax(T& x, T const& y) { if (x < y) { x = y; return true; } return false; }
template <class It> auto sumof(It b, It e) { return accumulate(b,e,typename iterator_traits<It>::value_type{}); }
////////////////////////////////
const int INF = 1e10;

int32_t main() {
    int n; cin >> n;
    vector<int> h(n); cin >> h;
    vector<int> dp(n+10,INF);
    dp[0] = 0;
    rep (i,n) {
        if (i+1 < n) chmin(dp[i+1], dp[i] + abs(h[i]-h[i+1]));
        if (i+2 < n) chmin(dp[i+2], dp[i] + abs(h[i]-h[i+2]));
    }
    cout << dp[n-1] << "\n"; 
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
int dx[6]={-1,-1, 0, 0, 1, 1};
int dy[6]={-1, 0,-1, 1, 0, 1};

struct info{
    int x,y,t;
    info(int x, int y, int t):x(x),y(y),t(t){}
};

                              
int main(){
    while(1){
        int t,n;
        cin >> t >> n;
        if(t==0) break;

        vector<vector<bool> > map(121, vector<bool>(121,true));
        for(int i=0; i<n; i++){
            int x,y;
            cin >> x >> y;
            map[x+60][y+60]=false;
        }
        int sx,sy;
        cin >> sx >> sy;
        sx+=60; sy+=60;

        queue<info> q;
        q.push(info(sx,sy,t));
        map[sx][sy] = false;
        int count = 1;
        while(!q.empty()){
            info now = q.front();
            q.pop();
            if(now.t<=0) continue;
            for(int i=0; i<6; i++){
                if(map[now.x+dx[i]][now.y+dy[i]]){
                    map[now.x+dx[i]][now.y+dy[i]] = false;
                    q.push(info(now.x+dx[i], now.y+dy[i], now.t-1));
                    count++;
                }
            }       
        }
        cout << count << endl;
    }
    return 0;
}

Measured memory_bytes: 3100
// Picking_Goods 
// https://atcoder.jp/contests/abc175/tasks/abc175_e
// date: 2020-08-16T00:22:11.064770

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

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=(ll) a;i<(ll) b;i++)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _repd(i,n) repdi(i,0,n)
#define repdi(i,a,b) for(ll i=(ll) b-1;i>=(ll) a;i--)
#define repd(...) _overload3(__VA_ARGS__,repdi,_repd,)(__VA_ARGS__)

#define all(x) x.begin(),x.end()
#define SIZE(x) ((ll)(x).size())

#define PB push_back //挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素

int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev

#define bit(n) (1LL<<(n))
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

template<typename T, typename ...Args>
void CIN(T& first, Args&... args) {
    ((cin >> first), ..., (cin >> args)); //C++17
}

template<char Sep, typename T, typename ...Args>
void print_seq(const T& first, const Args&... args) {
    ((cout << first), ..., (cout << Sep << args)); //C++17
}

template<typename... Words>
void COUT_NL(Words... words) {
    print_seq<' '>(words...);
    return;
}

template<typename... Words>
void COUT(Words... words) {
    print_seq<' '>(words...);
    cout << endl;
    return;
}

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl

#define INF 1000000000000 //10^12:∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 5000 //10^5:配列の最大のrange

int solve(void) {
    static ll v[MAXR][MAXR]={0};
    ll R,C,K; //行、列、アイテム数
    CIN(R,C,K);
    rep(i,K) {
        ll row,col,val;
        CIN(row,col,val);
        v[row-1][col-1] = val;
    }
    static ll dp[MAXR][MAXR][4]={0};

    dp[0][0][1] = v[0][0];
    rep(i,R) {
        rep(j,C) {
            if (i) { //上から
                chmax(dp[i][j][0], max({dp[i-1][j][0],dp[i-1][j][1],dp[i-1][j][2],dp[i-1][j][3]}));
                chmax(dp[i][j][1], dp[i][j][0]+v[i][j]);
            }
            
            if (j) { //左から
                //拾う
                rep(k,3) chmax(dp[i][j][k+1], dp[i][j-1][k]+v[i][j]);
                //拾わない
                rep(k,4) chmax(dp[i][j][k], dp[i][j-1][k]);

            }
        }
    }
    COUT(max({dp[R-1][C-1][0],dp[R-1][C-1][1],dp[R-1][C-1][2],dp[R-1][C-1][3]}));

    return 0;
}

int main(void){
    //入力の高速化用のコード
    //ios::sync_with_stdio(false);
    //cin.tie(nullptr);

    solve();
    return 0;
}


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

int main()
{
  vector<int> v(1000);
  v[1]=1;
  for(int i=2;i<1000;i++)
    v[i]=i+v[i-1];
  int a,b;
  cin>>a>>b;
  for(int i=1;i<999;i++)
  {
    if(v[i]<a)
      continue;
    int diff = v[i]-a;
    if(b==v[i+1]-diff)
    {cout<<diff<<"\n";return 0;}
  }
  
  
  return 0;
}


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

int main(){
    string s;
    cin >> s;
    int n = s.length();
    ll ans = 0, a = 0;
    for(int i = 0; i < n; i++){
        if(s[i] == 'A'){
            a++;
        }else if(s[i] == 'B' && i+1 < n && s[i+1] == 'C'){
            ans += a;
            i++;
        }else{
            a = 0;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
// 217
// 44

using namespace std;

map <ll, int> mp;

int main() {
    //ifstream cin("A.in");
    //ofstream cout("A.out");
    int n, i, x;
    ios::sync_with_stdio(false);
    cin >> n;
    ll s = 0, ans = 0;
    mp[0] = 1;
    for(i = 1; i <= n; i++) {
        cin >> x;
        s += x;
        ans += mp[s];
        mp[s]++;
    }
    cout << ans;
    //cin.close();
    //cout.close();
    return 0;
}


Measured memory_bytes: 12800
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>

#include <algorithm>
#include <numeric>
#include <cmath>

using namespace std;
typedef long long ll;
const long double PI = (acos(-1));
#define rep(i,n) REP(i,0,n)
#define REP(i,x,n) for(int i=x;i<n;++i)

///////////////////////////////////////////////////
// -------------------- I/O -------------------- //
///////////////////////////////////////////////////
// https://stackoverflow.com/questions/610245/where-and-why-do-i-have-to-put-the-template-and-typename-keywords
template<typename T> void outputVec(const std::vector<T>& vec, const int precision = 0) {
	if (precision > 0) std::cout << std::fixed << std::setprecision(precision);
	for (auto it = vec.begin(); it != vec.end() - 1; ++it) { std::cout << *it << " "; }
	std::cout << *(vec.end() - 1) << "\n";
}
template<typename T> void outputVal(const T& res, const int precision = 0) {
	if (precision > 0) std::cout << std::fixed << std::setprecision(precision);
	std::cout << res << "\n";
}
template<typename T> T inputVal() { T a; std::cin >> a; return a; }
template<typename T> std::vector<T> inputVec(T N) {
	std::vector<T> vec(N);
	for (auto it = vec.begin(); it != vec.end(); ++it) { std::cin >> *it; }
	return vec;
}
template<typename T> void inputVec(std::vector<T>& vec) {
	for (auto it = vec.begin(); it != vec.end(); ++it) { std::cin >> *it; }
}

///////////////////////////////////////////////////
// ------------------- utils ------------------- //
///////////////////////////////////////////////////
// change min/max
template<class T> inline bool chMin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chMax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

///////////////////////////////////////////////////
// ------------------- main -------------------- //
///////////////////////////////////////////////////
void Main() {

	const int N = inputVal<int>();
	const string s = inputVal<std::string>();

	if ((N % 2) != 0) {
		std::cout << "No" << std::endl;
		return;
	}

	bool flg = true;
	for (int i = 0; i < N/2; ++i) {
		flg = flg && (s[i] == s[i+N/2]);
		if (!flg) break;
	}

	std::cout << (flg ? "Yes" : "No") << std::endl;

}

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	std::cout << std::fixed << std::setprecision(15);
	Main();

	return 0;
}


Measured memory_bytes: 256
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0].split(" ")[0]);
    let A = arg[1].split(" ").map(n=>parseInt(n)).sort((a,b)=>a-b);
    
    const list = [...Array(1e6+1)].fill(0);
    
    for(let i=0; i<N; i++) {
        list[A[i]]++;
    }
    
    let answer = 0;
    
    for(let i=1; i<=1e6; i++) {
        if(list[i] === 0) continue;
        if(list[i] === 1) answer++;
        
        for(let j=i*2; j<=1e6; j+= i) {
            list[j] = 0;
        }
    }
    
    console.log(answer);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 66300
#include <stdio.h>
#include <string.h>
int main(void){
    // Your code here!
    char day1[10];
    
    scanf("%s", day1);
    //printf("%s", day1);
    
    if(strcmp(day1,"SSR") == 0){
        printf("1");
    }else if(strcmp(day1,"SRS") == 0){
        printf("1");
    }else if(strcmp(day1,"RSR") == 0){
        printf("1");
    }else if(strcmp(day1,"RRS") == 0){
        printf("2");
    }else if(strcmp(day1,"RSS") == 0){
        printf("1");
    }else if(strcmp(day1,"SRR") == 0){
        printf("2");
    }else if(strcmp(day1,"SSS") == 0){
        printf("0");
    }else if(strcmp(day1,"RRR") == 0){
        printf("3");
    }
    
}

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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'
#define rep(i,n) for(int_fast32_t i = 0; i < ((int_fast32_t)(n)); i++)   // 0-indexed昇順
#define rep1(i,n) for(int_fast32_t i = 1; i <= ((int_fast32_t)(n)); i++) // 1-indexed昇順
#define rrep(i,n) for(int_fast32_t i = ((int_fast32_t)(n)-1); i >= 0; i--)  // 0-indexed降順
#define rrep1(i,n) for(int_fast32_t i = ((int_fast32_t)(n)); i >= 1; i--)   // 1-indexed降順
#define all(x) (x).begin(),(x).end()

using namespace std;

template<typename T>
using vec = vector<T>;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using ll = long long;
using ld = long double;
using vi = vec<int_fast32_t>;
using vl = vec<int_fast64_t>;
using vld = vec<ld>;
using vii = vec<vi>;  // 2次元配列
using PII = pair<int_fast32_t, int_fast32_t>;

template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<class T,class U> inline bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U> inline bool chmin(T &a, const U &b){if(a>b){a=b;return 1;}return 0;}

const ld Pi = std::acos(-1.0L);
constexpr ll infll = (1LL<<62)-1;
constexpr int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;


/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    int START_TIME = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
//    cout << fixed << setprecision(15);

    i32 n; cin >> n;
    vi w(n); rep(i,n) cin >> w[i];

    vi csum(n+1); rep(i,n) csum[i+1] += csum[i] + w[i];

//    rep(i,n+1) cout << csum[i] << (i == n ? '\n' : ' ');

    i32 ans = inf;
    for(i32 idx = 0; idx < n; ++idx) {
        chmin(ans, abs(csum[n] - csum[idx+1] - csum[idx+1]));
    }

    cout << ans << '\n';

    // printf("ExecutionTime: %d /ms\n",1000*(int)((clock()-START_TIME)/CLOCKS_PER_SEC));
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
const ll INF = 1LL << 60;
const ll MOD = (ll) 1e9 + 7;

int to_c(char c) {
    return c - '0';
}

int main(){
    int n;
    string s;
    cin >> n >> s;
    int ans = 0;
    for (int i = 0; i < 1000; i++) {
        int k = i;
        int idx = 0;
        for (int j = idx; j < n; j++) {
            if (to_c(s[j]) == k / 100) {
                break;
            }
            idx++;
        }
        if (idx == n) continue;
        idx++;
        k %= 100;
        for (int j = idx; j < n; j++) {
            if (to_c(s[j]) == k / 10) {
                break;
            }
            idx++;
        }
        if (idx == n) continue;
        idx++;
        k %= 10;
        for (int j = idx; j < n; j++) {
            if (to_c(s[j]) == k) {
                ans++;
                break;
            }
            idx++;
        }
    }
    cout << ans << "\n";
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;

#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define ldb ldouble

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 19;
int MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;
#define szz(x) (int)(x).size()
#define rep(i, n) for(int i=0;i<n;i++)
#define Se second
#define Fi first

const int MX = 4005;
const int MM = 998244353;

int W[MX], S[MX];

int main()
{
	int A, B, C, D, E, F;
	scanf("%d%d%d%d%d%d", &A, &B, &C, &D, &E, &F);
	for(int i = 0; i <= F; i++){
		for(int j = 0; j <= F; j++) if((i*A+j*B)*100 <= F ) W[(i*A+j*B)*100] = 1;
	}
	for(int i = 0; i <= F; i++){
		for(int j = 0; j <= F; j++) if((i*C+j*D) <= F ) S[(i*C+j*D)] = 1;
	}
	
	pii ans = pii(0, 100*A);
	for(int i = 0; i <= F; i++){
		for(int j = 0; j <= F; j++){
			if(W[i] && S[j]);
			else continue;
			if( i+j <= F && 100*j <= i * E ){
				if( ans.first * (i+j) <= ans.second * j) ans = pii(j, i+j);
			}
		}
	}
	printf("%d %d\n", ans.second, ans.first);
}


Measured memory_bytes: 256
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include<list>
#include<map>
#include<utility>
#include<tuple>
#include<numeric>
#include<set>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(a) (a).begin(),a.end()
using namespace std;

int main()
{
	int n, d, x,sum=0;
	cin >> n >> d >> x;
	rep(i, n) {
		int a;
		cin >> a;
		sum += ((d - 1) / a)+1;
	}
	cout << sum + x << endl;
}



Measured memory_bytes: 256
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val p = readLine()!!.split(" ").map(String::toInt)
    val ans = (1 until n - 1).filter { i -> (p[i - 1] < p[i] && p[i] < p[i + 1]) || (p[i + 1] < p[i] && p[i] < p[i - 1]) }.count()
    println(ans)
}

Measured memory_bytes: 37996
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=100010;
const ll mod=1e9+7;

int main(){
  int n;
  cin >> n;
  vector<int> a(n),b(n);
  vector<char> c(n*2);
  vector<vector<int>> bl(2010, vector<int>(4020,0)); //bl[i][j]:i izyo j pos num
  vector<vector<int>> wh(2010, vector<int>(4020,0));
  rep(i,2*n){
    char c; int x; cin >> c >> x; x--;
    if(c=='W'){
      a[x]=i;
      wh[x][i+1]++;
    } else {
      b[x]=i;
      bl[x][i+1]++;
    }
  }

  for(int i=n-1; i>0; i--)rep(j,2*n+1){
    wh[i-1][j] += wh[i][j];
    bl[i-1][j] += bl[i][j];
  }

  rep(i,n)rep(j,n*2){
    wh[i][j+1] += wh[i][j];
    bl[i][j+1] += bl[i][j];
  }

  vector<vector<ll>> dp(n+1, vector<ll>(n+1,longinf));
  dp[0][0]=0;
  rep(i,n+1)rep(j,n+1){
    if(i<n) dp[i+1][j] = min(dp[i+1][j], dp[i][j]+wh[i+1][a[i]]+bl[j][a[i]]);
    if(j<n) dp[i][j+1] = min(dp[i][j+1], dp[i][j]+wh[i][b[j]]+bl[j+1][b[j]]);
  }
  ll ans = dp[n][n];
  cout << ans << endl;
  return 0;  
}

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

#define rep(i, n) for(int i = 0;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)

int main(){
  int h,w;
  cin>>h>>w;
  char board[h][w];
  rep(i,h){
    rep(j,w){
      cin>>board[i][j];
    }
  }
  rep(i,h){
    rep(j,w){
      cout<<board[i][j];
    }
    cout<<endl;
    rep(j,w){
      cout<<board[i][j];
    }
    cout<<endl;
  }
}


Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int r, c, s[100+1][100+1];
    for(int i=0; i<101; i++){
        for(int j=0; j<101; j++){
            s[i][j] = 0;
        }
    }
    scanf("%d %d", &r, &c);
    for(int i=0; i<r; i++){
        for(int j=0; j<c; j++){
            scanf("%d", &s[i][j]);
            s[r][j] += s[i][j];
            s[i][c] += s[i][j];
        }
        s[r][c] += s[i][c];
    }
    for(int i=0; i<=r; i++){
        for(int j=0; j<c; j++){
            printf("%d ", s[i][j]);
        }
        printf("%d\n", s[i][c]);
    }
    return 0;
}



Measured memory_bytes: 2052
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	int n;
	cin >> n;
	vector<int> v(n);
	for (int i = 0; i < n; i++){
		int l;
		cin >> l;
		v[i] = l;
	}
	sort(ALL(v));
	
	cout << v[n-1] - v[0] <<endl;
	return 0;
}

Measured memory_bytes: 256
def find(x):
    while x!=T[x][0]:
        x = T[x][0]
    return x
def union(x,y):
    rt1 = find(x)
    rt2 = find(y)
    if T[rt1][1]>=T[rt2][1]:
        T[rt2][0] = rt1
        T[rt1][1] += T[rt2][1]
    else:
        T[rt1][0] = rt2
        T[rt2][1] += T[rt1][1]
N,M = map(int,input().split())
E = [list(map(int,input().split())) for _ in range(M)]
T = {i:[i,1] for i in range(1,N+1)}
RT = {i:1 for i in range(1,N+1)}
cnt = 0
ans = (N*(N-1))//2
A = []
A.append(ans)
for i in range(M-1,-1,-1):
    a,b = E[i]
    rt1 = find(a)
    rt2 = find(b)
    if rt1==rt2:
        A.append(ans)
    else:
        x = T[rt1][1]
        y = T[rt2][1]
        ans += (x*(x-1))//2+(y*(y-1))//2
        union(a,b)
        rt = find(a)
        z = T[rt][1]
        ans -= (z*(z-1))//2
        A.append(ans)
A = A[::-1]
for i in range(1,M+1):
    print(A[i])

Measured memory_bytes: 124092
#include<bits/stdc++.h>
using namespace std;
string s[30];
bool vis[30][30];
int n,m;
int dir[4][2]={{-1,0},{1,0},{0,1},{0,-1}};
struct node{
    int x,y,t;
    node(int x,int y,int t):x(x),y(y),t(t){}
};
int mx=0;
void bfs(int x,int y){
    memset(vis,false,sizeof(vis));
    queue<node>q;
    q.push(node(x,y,0));
    vis[x][y]=true;
    while(!q.empty()){
        node now=q.front();
        q.pop();
        for(int j=0;j<4;++j){
            int xx=now.x+dir[j][0];
            int yy=now.y+dir[j][1];
            if(xx>=0&&yy>=0&&xx<n&&yy<m&&!vis[xx][yy]&&s[xx][yy]!='#'){
                vis[xx][yy]=true;
                q.push(node(xx,yy,now.t+1));
                mx=max(mx,now.t+1);
            }
        }
    }
}
int main(){
    cin>>n>>m;
    for(int i=0;i<n;++i){
        cin>>s[i];
    }
    for(int i=0;i<n;++i){
        for(int j=0;j<m;++j){
            if(s[i][j]=='#')continue;
            bfs(i,j);
        }
    }
    cout<<mx<<endl;
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class Z { static void Main() => new K(); }
class K
{
	int F => int.Parse(Str);
	long FL => long.Parse(Str);
	int[] G => Strs.Select(int.Parse).ToArray();
	long[] GL => Strs.Select(long.Parse).ToArray();
	string Str => ReadLine();
	string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
	const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		var N = F;
		var H = F;
		var W = F;
		WriteLine((N - H + 1) * (N - W + 1));
	}
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

int main()
{
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    if(s == "abc") cout <<"Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3724
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define LB(a,x) lb(all(a),x)-a.begin()
#define UB(a,x) ub(all(a),x)-a.begin()
#define mod 1000000007
//#define mod 998244353
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline void out(T a){ cout << a << '\n'; }
void YN(bool ok){if(ok) cout << "Yes" << endl; else cout << "No" << endl;}
//void YN(bool ok){if(ok) cout << "YES" << endl; else cout << "NO" << endl;}


const ll INF=1e18;
const int mx=200005;

ll dp[1005][4100];

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int n,m;
    cin>>n>>m;
    ll a[m],b[m],c[m][n];
    rep(i,m){
        cin>>a[i]>>b[i];
        rep(j,b[i]){
            cin>>c[i][j];
            c[i][j]--;
        }
    }
    rep(i,m+1){
        rep(j,(1<<n)) dp[i][j]=INF;
    }
    dp[0][0]=0;
    rep(i,m){
        rep(j,(1<<n)){
            int to=j;
            ll cnt=a[i];
            rep(k,b[i]){
                int tmp=(1<<(c[i][k]));
                to|=tmp;
                //cnt+=a[i];
            }
            chmin(dp[i+1][j],dp[i][j]);
            chmin(dp[i+1][to],dp[i][j]+cnt);
        }
    }
    if(dp[m][(1<<n)-1]<INF) out(dp[m][(1<<n)-1]);
    else out(-1);
}

Measured memory_bytes: 35768