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

using namespace std;
 
#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

typedef int64_t ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = 1e9+7; typedef vector<ll> VL;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }


int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n, k;
	cin >>n >>k;
	VL v(n);
	rep(i, n) cin >>v[i];
	ll ans = 0;
	rep(lf, k+1) rep(rg, k-lf+1){
		if(lf + rg > n) continue;
		int d = k-lf-rg;
		VL sv;
		ll su = 0;
		rep(i, lf){
			su += v[i];
			sv.push_back(v[i]);
		}
		rep2(i ,n-rg, n){
			su += v[i];
			sv.push_back(v[i]);
		}
		sort(all(sv));
		rep(i, d){
			if(sz(sv)==0 || i >= sz(sv)) break;
			if(sv[i] >0) break;
			su -= sv[i];
		}
		//dbg(lf, rg, su, d,sz(sv));
		ans = max(ans, su);
	}
	
	cout << ans <<"\n";
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define N 200000


int main(){
	long long a[N];
	long long b[N];
	vector<pair<long long, int> >c;
	f(i, N){
		a[i] = 0;
		b[i] = 0;
	}
	int n, k;
	int x, y, z;
	long long s, ans;
	bool v = true;
	ans = 0;
	scanf("%d", &n);
	f(i, n){
		scanf("%lld %lld", &a[i], &b[i]);
		c.push_back(make_pair((a[i] + b[i]), i));
	}
	sort(c.begin(), c.end(),greater<pair<long long,int> >());
	ans = 0;
	f(i, n){
		if (i % 2 == 0)ans += a[c[i].second];
		else ans -= b[c[i].second];
	}

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


	return 0;
}

Measured memory_bytes: 5492
s=input()
for i in range(1,len(s),1):
	if s[i]==s[i-1]:
		print(str(i)+" "+str(i+1))
		break
	try:
		if s[i-1]==s[i+1]:
			print(str(i)+" "+str(i+2))
			break
	except:
		pass
else :
	print(str(-1)+" "+str(-1))

Measured memory_bytes: 3188
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, S):
    c = Counter(S)
    if c['R'] > c['B']:
        return 'Yes'
    return 'No'


def main():
    N = read_int()
    S = read_str()
    print(slv(N, S))


if __name__ == '__main__':
    main()


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

int memo[100005];

int main(){

    int n,k;
    cin>>n >> k;

    vector<int> heights(n);

    for(int i = 0; i<n; i++){
        cin>>heights[i];
    }

    memo[0] = 0;

    for(int i = 1; i<n; i++){
        memo[i] = memo[i-1] + abs(heights[i] - heights[i-1]);
        if(i>1){
            int l = min(i,k);
            if(k >= 2 && l >= 2){
            int m = memo[i-2] + abs(heights[i] - heights[i-2]);
            for(int j = 3; j <= l;j++){
                int o = memo[i-j] + abs(heights[i] - heights[i-j]);
                m = min(m,o);
            }
            memo[i] = min(memo[i],m);
            }
        }
        //cout << memo[i] << endl;
    }
    
    cout<<memo[n-1];

}

Measured memory_bytes: 4036
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll cnt[200010],a[200010];

int main () {
    int n,c=0;
    ll ans=0;
    cin>>n;
    for(int i=0;i<n;i++){
        int k;
        cin>>a[i];
        //if(cnt[a[i]]==0)c++;
        cnt[a[i]]++;
    }
    for(int i=1;i<=n;i++){
        if(cnt[i]){
            ans+=cnt[i]*(cnt[i]-1)/2;
        }
    }
    for(int i=0;i<n;i++){
        ans-=cnt[a[i]]*(cnt[a[i]]-1)/2;
        cnt[a[i]]--;
        //ans+=cnt[a[i]]*(cnt[a[i]]-1)/2;

        cout<<ans+cnt[a[i]]*(cnt[a[i]]-1)/2<<'\n';
        cnt[a[i]]++;
        ans+=cnt[a[i]]*(cnt[a[i]]-1)/2;
    }
}

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

using namespace std;

int k, s;

int main()
{
	int ymin, ymax;
	int zmin, zmax;
	int cnt;
	
	cin >> k >> s;
	
	ymin = 0;
	ymax = k;
	
	cnt = 0;
	for (int x = 0; x <= k; x++)
	{
		zmin = s - x - ymax;
		zmax = s - x - ymin;
		
		if (zmin > k || zmax < 0) {continue;}
		
		if (zmin < 0) {zmin = 0;}
		if (zmax > k) {zmax = k;}
		cnt += zmax - zmin + 1;
	}
	
	cout << cnt << endl;;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <stdio.h>
#include <vector>
#include <map>

using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

int main() {

    string S;
    cin >> S;
    ll N = S.length();
    ll B[N];
    ll W[N];
    rep(i,N){
        if(S[i]=='B'){
            if(i==0){
                B[0] = 1;
                W[0] = 0;
            }else{
                B[i] = B[i-1]+1;
                W[i] = W[i-1];
            }
        }else{
            if(i==0){
                B[0] = 0;
                W[0] = 1;
            }else{
                B[i] = B[i-1];
                W[i] = W[i-1]+1;
            }
        }
    }
    ll out = 0;
    rep(i,N){
        if(S[i]=='W') out += B[i];
    }
    cout << out << endl;
    return 0;
}


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

ll max1(ll a,ll b){
    if(a>b) return a;
    return b;
}
int main(void){
    ll n;
    cin>>n;
    ll a[200010],b[200010]={};
    for(int i=1;i<=n;i++){
        cin>>a[i];
        b[a[i]]++;
    }
    ll sum=0;
    ll s1[200010]={},s2[200010]={};
    for(int i=1;i<=n;i++){
        s1[i]=b[i]*(b[i]-1)/2;
        s2[i]=max1(0,(b[i]-1)*(b[i]-2)/2);
        sum+=s1[i];
    }
    for(int i=1;i<=n;i++){
        cout<<sum-s1[a[i]]+s2[a[i]]<<endl;
    }
}

Measured memory_bytes: 8832
def resolve():
    n = int(input())
    a = list(map(int, input().split()))
    ans = 0
    for i in range(1, n):
        if a[i] == a[i - 1]:
            ans += 1
            a[i] = -1
    print(ans)
            

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 3060
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <string.h>
#include <tuple>
#include <vector>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i >= 0; i--)
#define REP1O(i,x) for(int i{ 1 }; i < (int)(x); i++)
#define REP1C(i,x) for(int i{ 1 }; i <= (int)(x); i++)

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

using namespace std;

typedef int64_t ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef pair<int, int> pii;
typedef tuple<int, int, int> tupiii;
typedef tuple<ll, ll, ll> tuplll;

const int INTMAX = 2147483647;
const ll LLMAX = 9223372036854775807;
const int MOD = 1000000007;

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

const int MAX = 100000;
ll cnt[MAX + 1];
int n; ll k;

void init()
{
	memset(cnt, 0LL, sizeof cnt);
	cin >> n >> k;
}

int main()
{
	init();

	REP(i, n)
	{
		int a;
		ll b;
		cin >> a >> b;
		cnt[a] += b;
	}

	ll tot = 0;
	int i = 0;
	while (tot < k)
	{
		tot += cnt[i++];
	}

	cout << i - 1 << endl;

}


Measured memory_bytes: 1024
a = ("a".."z").to_a
b = Array.new(26, 0)

while x = gets
  x.downcase.chars { |i|
    for j in 0..25
      i == a[j] && b[j] += 1
    end
  }
end

a.size.times { |c|
  puts "#{a[c]} : #{b[c]}"
}

Measured memory_bytes: 8620
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        // 整数の入力
        int a = sc.nextInt();
        // スペース区切りの整数の入力
        int b = sc.nextInt();
        int c = sc.nextInt();
        int k = sc.nextInt();
        int[] array = {a,b,c};
        int max = array[0];
        int result;
        if (1<=a && a<=50 && 1<=b && b<=50 && 1<=c && c<=50 && 1<=k && k<=10) {
            for (int j = 0; j < array.length; j++) {
                if(array[j]>max){
                    max=array[j];
                }
            }
        }
            result = (int) (a+b+c-max+(Math.pow(2,k)*max));
        System.out.println(result);
    }
}


Measured memory_bytes: 19796
import sys
import bisect
sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

N, K = MAP()
A = MAP()

if min(A) > 0:
	print(A[K-1])
	sys.exit()
elif max(A) < 0:
	print(abs(list(reversed(A))[K-1]))
	sys.exit()

# print(A)
o = bisect.bisect_left(A, 0)
# print(o)

ans = float('INF')
for i in range(K+1):
	j = K - i
	# print('=====', i, j)
	if j==0 and o+K <= N-1:
		# print('zenbu migi',abs(A[o+K-1]))
		ans = min(ans, abs(A[o+K]))
	elif i==0 and o-K >= 0:
		# print('zenbu hidari', abs(A[o-K]))
		ans = min(ans, abs(A[o-K]))
	elif o+i-1 <= N-1 and o-j >=0:
		if i<j:
			# print('migi itte hidari', abs(A[o+i-1]*2) + abs(A[o-j]))
			ans = min(ans, abs(A[o+i-1]*2) + abs(A[o-j]))
		elif i>j:
			# print('hidari itte migi', abs(A[o+i-1]) + abs(A[o-j]*2))
			ans = min(ans, abs(A[o+i-1]) + abs(A[o-j]*2))
		else:
			ans = min(ans, abs(A[o+i-1])+abs(A[o-j])*2, abs(A[o+i-1])*2+abs(A[o-j]))

print(ans)

Measured memory_bytes: 58736
require 'pp'

def gets; ARGF.gets; end

class Solver

  def initialize
  end

  def main
    s = gets.chomp

    h_len = s.length / 2
    if h_len == 0
      puts 0
      return
    end

    ans = 0
    0.upto(h_len-1) do |i|
      if s[i] != s[s.length-i-1]
        ans += 1
      end
    end

    puts ans
  end
end

if __FILE__ == $0
  Solver.new.main
end


Measured memory_bytes: 2172
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll MOD = pow(10, 9) + 7; //10e9 + 7


int main() {
  string S, ans;
  cin >> S;
  //for(int i=0; i<S.size(); i++) cout << S.at(i)<<endl;

  ans = "Yes";

  for(int i=0; i<S.size(); i += 2){//奇数番目確認
    if(S.at(i) == 'L'){//奇数番目にLがあるなら
      ans = "No";
      break;
    }
  }
  for(int i=1; i<S.size(); i += 2){//偶数番目確認
    if(S.at(i) == 'R'){//偶数番目にRがあるなら
      ans = "No";
      break;
    }
  }
  
  cout << ans << endl;
  
}


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

int		main(void)
{
	vector<string>	letter(3);
	for (int i = 0; i < 3; i++)
		cin >> letter.at(i);
	for (auto &i : letter)
		cout << char(i.at(0) - 32);
	cout << endl;
}

Measured memory_bytes: 256
K = int(input())
A, B = map(int, input().split())
sa = B - A

if sa == 0:
  if B % K == 0:
    print("OK")
    exit()

for i in range (A - 1, B):
  if (i + 1) % K == 0:
    print("OK")
    exit()
    
print("NG")

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

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

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

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

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

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
/*逆元計算*/
long long int  modinv(long long a, long long m) {
	long long int b = m, u = 1, v = 0;
	while (b) {
		long long int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
// index が条件を満たすかどうか
vector<long long int >meguru;
bool isOK(int index, int key) {
	if (meguru[index] <= key) return true;
	else return false;
}
// 汎用的な二分探索のテンプレ
int binary_search(int key) {
	int left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	int right = (int)meguru.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()
	/* どんな二分探索でもここの書き方を変えずにできる！ */
	while (right - left > 1) {
		int mid = left + (right - left) / 2;

		if (isOK(mid, key)) left = mid;
		else right = mid;
	}
	/* left は条件を満たす最大の値、right は条件を満たさない最小の値になっている */
	return left;
}
long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
int main() {
	long long int n;
	cin >> n;
	string ans;
	while (n > 0) {
		long long int a = n % 26;
		int b = a;
		if (a == 0) {
			n = n - 26;
		}
		else {
			n = n - a;
		}
		n = n / 26;
		if (a == 0) {
			ans = ans + 'z';
		}
		else {
			char c = 'a' + (b - 1);
			ans = ans + c;
		}
	}
	reverse(ans.begin(), ans.end());
	cout << ans;
}

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

namespace Question3
{
    class Program
    {
        static void Main(string[] args)
        {
            string line = Console.ReadLine();
            int a = Int32.Parse(line.Split(' ')[0]);
            int b = Int32.Parse(line.Split(' ')[1]);
            Console.WriteLine((a + b) % 24);
        }
    }
}


Measured memory_bytes: 11092
#include "bits/stdc++.h"
// Custom Header {{{
#define ALL(x) x.begin(), x.end()
using namespace std;
using i64 = long long;
using pii = pair<i64, i64>;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
// }}}

signed main()
{
    // ios::sync_with_stdio(false); cin.tie(nullptr);
    int N;
    cin >> N;
    for (int i = 0; i < N; ++i) {
        int x, y, b, p;
        cin >> x >> y >> b >> p;

        int ans = x * b + y * p;
        chmin(ans, int(x * 0.8) * max(5, b) + int(y * 0.8) * max(2, p));

        cout << ans << endl;
    }

    return 0;
}

// vim: set foldmethod=marker :



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

using ll = long long;

const int mod = 1000000007;
const int INF = 1000000000;
const double EPS = 1e-9;

ll gcd(ll a, ll b) {
    if (b == 0ll) return a;
    return gcd(b, a % b);
}

ll lcm(ll a, ll b) {
    ll g = gcd(a, b);
    return a / g * b;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, M;
    cin >> N >> M;
    vector<ll> A(N);
    for (int i = 0; i < N; ++i) cin >> A[i];
    ll l = 1;
    for (int i = 0; i < N; ++i) l = lcm(l, A[i] / 2);
    bool ok = true;
    for (int i = 0; i < N; ++i) {
        if ((l / (A[i] / 2)) % 2 == 0) ok = false;
    }
    ll ans = (M - l) / 2 / l;
    if (M >= l) ++ans;
    else ans = 0;
    if (!ok) ans = 0;
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <map>

using namespace std;

int main() {

	int N;
	cin >> N;

	map<long long , long long> work;

	long long A, B;

	for (int i = 0; i < N; i++) {
		cin >> A >> B;
		work[B] += A;
	}

	bool ans = false;

	long long sum = 0;

	for (auto i : work) {
		sum += work[i.first];
		if (sum > i.first) {
		ans = true;
		break;
		}
	}


	cout << ((ans) ? "No" : "Yes") << endl;


	return 0;
}

Measured memory_bytes: 12800
package main

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

func solution(s string) int {
        n := len(s) + 1
        a := make([]int, n)
        for i := 0; i < n-1; i++ {
                if s[i] == '<' {
                        a[i+1] = max(a[i+1], a[i]+1)
                }
        }

        for i := n - 2; i >= 0; i-- {
                if s[i] == '>' {
                        a[i] = max(a[i], a[i+1]+1)
                }
        }
        out := 0
        for i := 0; i < n; i++ {
                out += a[i]
        }
        return out
}

func max(x, y int) int {
        if x > y {
                return x
        }
        return y
}

func main() {
        var fp *os.File = os.Stdin
        reader := bufio.NewReaderSize(fp, 1024)
        s := readLine(reader)
        fmt.Println(solution(s))
}

func readLine(reader *bufio.Reader) string {
        buf := make([]byte, 0, 1024)

        for {
                l, p, _ := reader.ReadLine()

                buf = append(buf, l...)

                if !p {
                        break
                }
        }
        return string(buf)
}

Measured memory_bytes: 8192
N, M = map(int, input().split())
a = []
b = []
c = []

MY_INF = 1000000007

for _ in range(M):
    a_tmp, b_tmp = map(int, input().split())
    a.append(a_tmp)
    b.append(b_tmp)
    c.append(list(map(int, input().split())))

c_bin = []
for i in range(M):
    c_bin.append(sum([1 << (cij - 1) for cij in c[i]]))
    
memo = [None] * (1 << N)

def dp(state):
    global MY_INF
    if state == (1 << N) - 1: return 0
    if memo[state] != None: return memo[state]
    #
    rets = [MY_INF]
    for i in range(M):
        if (state | c_bin[i]) > state:
            rets.append(a[i] + dp((state | c_bin[i])))
    ret = min(rets)
    #
    memo[state] = ret
    return ret

ans = dp(0)
if ans != MY_INF:
    print(ans)
else:
    print(-1)

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

using namespace std;
using ll = long long;
#define int ll

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)

const int INF = (1LL<<30);

char col[] = {'R', 'G', 'B'};
string board[4];
int n, d[1<<16], h[20], w[20];
signed main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n;
  REP(i, n) cin >> h[i] >> w[i];
  REP(i, 4) cin >> board[i];

  REP(i, 1<<16) d[i] = INF;
  d[0] = 0;
  queue<int> que;
  que.push(0);

  while(que.size()) {
    int bit = que.front(); que.pop();
    if(bit == (1LL<<16)-1) break;
    // i番目のはんこで左上を(y,x)で色をcとして押す
    REP(i, n) FOR(y, -h[i]+1, 4) FOR(x, -w[i]+1, 4) REP(c, 3) {
      int n_bit = bit;
      FOR(ny, max(0LL, y), min(y+h[i],4LL)) FOR(nx, max(0LL, x), min(x+w[i],4LL)) {
        // 押した結果同じ色なら1に、違う色なら0に
        if(board[ny][nx] == col[c]) n_bit |= 1<<(ny*4+nx);
        else n_bit &= ~(1<<(ny*4+nx));
      }
      if(d[n_bit] == INF) {
        d[n_bit] = d[bit] + 1;
        que.push(n_bit);
      }
    }
  }

  cout << d[(1LL<<16)-1] << endl;

  return 0;
}



Measured memory_bytes: 3884
n,k = map(int,input().split())

def ans(n,k):  
  ans = (n-1) + ((n-1)*(n-2)//2 - k)
  print(ans)
  c = 0
  for i in range(n):
    for j in range(i+1,n):
      if c >= ans:
        return 
      print(i+1,j+1)
      c += 1

if k > (n-1)*(n-2)//2:
  print(-1)
else:  
  ans(n,k)

Measured memory_bytes: 3608
#include <iostream>
#include <string>
#include <map>
using namespace std;

int main(){
    string S[3];
    cin >> S[0] >> S[1] >> S[2];
    int next=0;
    while(1){
        int n = S[next][0]-'a';
        S[next].erase(S[next].begin());
        next = n;
        if(S[next][0]=='\0') break;
    }
    char win = next+'A';
    cout << win << endl;
    return 0;
}

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

#define pb push_back
#define fastIO ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define endl '\n'
#define deb(x) cout << #x << " "<< x << endl;
#define fo(i, n) for(int i=0; i<n; i++)
#define Fo(i, k, n) for(int i=k; i<n; i++)

struct greaterr
{
    template<class T>
    bool operator()(T const &a, T const &b) const { return a > b; }
};

vector<bool> sieve(1000007,true);

void help(){
     sieve[0] = false;
     sieve[1] = false;

     for(int i=2;i*i<=1000000;++i){
        if(sieve[i]){
            for(int j=i*i;j<=1000000;j+=i)
                sieve[j] = false;

        }
     }


}

int main() {
   fastIO


    int n;
    cin>>n;

    int arr[n];

    fo(i,n)
        cin>>arr[i];
    int maxx = arr[0];
    for(int i=1;i<n;++i){
        if(maxx-arr[i]>=2){
            cout<<"No";
            return 0;
        }
        maxx = max(maxx,arr[i]);
    }
  cout<<"Yes";




   return 0 ;
      }


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

int main(){
	string row;
	int i = 0;
	int cnt = 0;

	cin >> row;

	for(i=0;i<row.size();i++){
		if(row.at(i) == '1'){
			cnt++;
		}
	}

	cout << cnt << endl;
}

Measured memory_bytes: 3612
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
typedef long long ll;
typedef unsigned long long ull;

int x[100002];

int main()
{
	int N, K;
	ll ans = 10000000000000;

	cin >> N >> K;
	x[0] = -1;
	repc(i, 1, N) cin >> x[i];
	x[N + 1] = 0;

	repc(i, 1, N - K + 1) {
		ll tmp;

		if (x[i + K] < 0 || x[i - 1] > 0) continue;

		if (x[i + K - 1] < 0) tmp = abs(x[i]);
		else if (x[i] > 0) tmp = x[i + K - 1];
		else {
			tmp = (ll)abs(x[i]) * 2 + (ll)x[i + K - 1];
			tmp = min(tmp, (ll)abs(x[i]) + (ll)x[i + K - 1] * 2);
		}

		ans = min(ans, tmp);
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <sstream>
#include <stdio.h>
#include<vector>
#include<climits>
#include<algorithm>
#include<bitset>
#include<cmath>
#include<functional>
#include <numeric>
#include <map>
#define FORi(N) for(int i=0;i<N;++i)
#define FORj(N) for(int j=0;j<N;++j)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
ll gcd(ll m,ll n){
  if(n==0)return abs(m);
  return(gcd(n,m%n));
}
void putYN(bool b){
  if(b){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
}
int main(){
  string S;
  cin >> S;
  bool flag=false;
  ll num=0;
  FORi(S.size()){
    bool b = S[i]=='0';
    if(flag)b=!b;
    if(b)num++;
    flag=!flag;
  }
  if(num>S.size()-num)num = S.size()-num;
  cout<<num<<endl;
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n, m, x, y;
    cin >> n >> m >> x >> y;
    int X[10000], Y[10000];
    for(int i=0; i<n; i++){
        cin >> X[i];
    }
    for(int i=0; i<m; i++){
        cin >> Y[i];
    }
    sort(X, X+n);
    sort(Y, Y+m);
    bool war=true;
    for(int i=x+1; i<=y; i++){
        if(X[n-1]<i && i<=Y[0]){
            war = false;
        }
    }
    if(war){
        cout << "War" << endl;
    }else{
        cout << "No War" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
// vvvvvvvvvvvv TEMPLATE vvvvvvvvvvvv
#include <bits/stdc++.h>
using namespace std; using ll = long long; using P = pair<ll, ll>;
const ll linf = 1e18; const double eps = 1e-12, pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define each(i,a) for (auto&& i : a)
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define eb emplace_back
#define all(a) begin(a),end(a)
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)
#define min(x,y) (x < y ? x : y)
#define max(x,y) (x < y ? y : x)
template<typename Head> void out(Head h) { cout << h << endl; } template<typename Head, typename... Tail>void out(Head h, Tail... t) { cout << h << " "; out(t...); }
template<typename T> istream& operator>>(istream& is, vector<T>& v) { each(x,v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) { rep(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
ostream& operator<<(ostream& os, const vector<string>& v) { rep(i,v.size()) { if (i) os << endl; os << v[i]; } return os; }
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) { rep(i,v.size()) { if (i) os << endl; os << v[i]; } return os; }
template<typename T1, typename T2> ostream& operator<<(ostream& os, const pair<T1, T2>& p) { return os << "(" << p.first << ", " << p.second << ")"; }
struct yes_no : std::numpunct<char> { string_type do_truename() const { return "Yes"; } string_type do_falsename() const { return "No"; } };
void solve(); int main() {
  ios::sync_with_stdio(false); cin.tie(0); locale loc(locale(), new yes_no); cout.imbue(loc); cout << fixed << setprecision(10) << boolalpha;
  solve();
}
// ^^^^^^^^^^^^ TEMPLATE ^^^^^^^^^^^^

double dp[301][301][301];

void solve() {
  ll n; cin >> n;
  vector<ll> a(n); cin >> a;
  dp[0][0][0] = 0;
  rep(c, n+1) rep(b, n-c+1) rep(a, n-b-c+1) {
    ll sum = a + b + c;
    if (sum == 0) continue;
    ll zero = n - sum;
    double num = 0;
    if (a > 0) {
      num += double(a) / n * (dp[a-1][b][c] + 1);
    }
    if (b > 0) {
      num += double(b) / n * (dp[a+1][b-1][c] + 1);
    }
    if (c > 0) {
      num += double(c) / n * (dp[a][b+1][c-1] + 1);
    }
    num += double(zero) / n;
    double dia = 1 - double(zero) / n;
    dp[a][b][c] = num / dia;
    // cout << a << " " << b << " " << c << " " << dp[a][b][c] << endl;
  }
  vector<ll> cnt(3, 0);
  rep(i, n) cnt[a[i]-1]++;
  cout << dp[cnt[0]][cnt[1]][cnt[2]] << endl;
}


Measured memory_bytes: 213248
#include <iostream>
#include <cmath>
#include <stdio.h>
using namespace std;
int main(){

double a,b,C,S,L,h;
cin>>a>>b>>C;

S=a*b*sin((C/180)*M_PI)/2;
L=a+b+sqrt(a*a+b*b-2*a*b*cos((C/180)*M_PI));
h=S*(double)2/a;

printf("%.8f\n%.8f\n%.8f\n",S,L,h);

}

Measured memory_bytes: 1240
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
const lint MOD =1000000007;
const lint MAX = 10000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;

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

void COMinit() // 二項係数を求める時は前処理としてCOMinit()をする
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
// 二項係数計算
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0; // 偶数はあらかじめ除く

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

    // 素数である
    return 1;
}
   long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

 
  int main(){
      lint h,w;
      cin>>h>>w;
      lint N;
      cin >>N; lint A[N];
      vector<lint>x;
      rep(i,N)cin >> A[i];
      rep(i,N){
          rep(j,A[i]){
              x.push_back(i+1);
          }
      }
     vector<vector<lint>> ans(100000);
     lint t=0;
      rep(i,h){
          rep(j,w){
              ans[i].push_back(x[t]);
              t++;
          }
          if(i%2==1)reverse(all(ans[i]));
          rep(k,w){
              cout<<ans[i][k]<<" ";
          }
          cout<<endl;
      }
    }
     
  


Measured memory_bytes: 2944
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <iomanip>
using namespace std;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
typedef vector <int> vi;
typedef pair<int,int> ii;
typedef long long ll;
typedef long double ld;
const int mod = 998244353;
const ll inf = 3e18 + 5;
int add(int a, int b) { return (a += b) < mod ? a : a - mod; }
int mul(int a, int b) { return 1LL * a * b % mod; }  

int main(){
    int n, m;
    cin >> n >> m;
    priority_queue<int> A;

    for(int i=0; i<n; i++){
        int tmp;
        cin >> tmp;
        A.push(tmp);
    }

    while(m){
        int tmp = A.top();
        tmp/=2;
        A.push(tmp);
        A.pop();
        m--;
    }
    ll sol=0;

    while(A.size()){
        sol+=A.top();
        A.pop();
    }
    cout << sol;
}

Measured memory_bytes: 892
n = int(input())
A = sorted(map(int, input().split()))

U = A[-1]
line = [1]*(U+1)
ans = set()
depricated = set()
cnt = [0]*(U+1)
for a in A:
    cnt[a] += 1
    if cnt[a] == 2 and line[a]:
        depricated.add(a)
    if line[a]:
        ans.add(a)
        for p in range(2*a, U+1, a):
            line[p] = 0
print(len(ans-depricated))


Measured memory_bytes: 134444
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define sz(x) int(x.size())
#define all(x) (x).begin(), (x).end()
#define INF 1e9
typedef long long ll;
typedef pair<int, int> P;

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> a(n), b(n);
    vector<P> p(n);
    priority_queue<P> que;
    rep(i, n) {
        cin >> a[i] >> b[i];
        p[i] = P(a[i], b[i]);
    }
    sort(all(p));
    int ans = 0;
    int j = 0;
    rep(i, m) {
        while (j < n && p[j].first == i+1) {
            que.push(P(p[j].second, p[j].first));
            j++;
        }
        if (!que.empty()) {
            P tmp = que.top(); que.pop();
            ans += tmp.first;
        }
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 2936
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdlib>
#include <string>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>
#define endl '\n'
#define ll long long
#define mod 1000000007
#define NCONS 1000000000
//#define NCONS 100001
//#define NCONS 1001
//#define NCONS 101
#define MCONS 2001
#define LIMIT 1000000000
#define TRUE 1
#define FALSE 0
#define toRadian(degree) ((degree) * (M_PI / 180.))
#define toDegree(radian) ((radian) * (180. / M_PI))
using namespace std;
struct Point{int x; int y;};

int main(void)
{
    cin.tie(NULL); ios_base::sync_with_stdio(false);
    
    int M; cin >> M;
    cout << 48 - M;
    
    return 0;
}


Measured memory_bytes: 256
#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++)
#define fi first
#define se second
#define mp make_pair
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int(2 * 1e5 +5)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong
#define INF llong(1e17)
void myprint(int* A,int A_num){
   REP(i,A_num) cout << A[i] << " ";
   cout << endl;
}

signed main(){
    int a,b;
    cin >> a >> b;
    b --;
    a--;
    int ans = b / a;
    if(b %a != 0) ans ++;
    cout << ans << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef set<int> si;
typedef map<string, int> msi;
typedef greater<int> gt;
typedef priority_queue<int, vector<int>, gt> minq;
typedef long long ll;
const ll INF = 1e18L + 1;
//clang++ -std=c++11 -stdlib=libc++ 

int main() {
  int N; cin>>N;
  vi a(N);
  rep(i,N) cin >> a[i];
  double avg = 0;
  rep(i,N) avg+=a[i];
  avg = avg/(double)N;
  avg = round(avg);
  ll sum =0;
  rep(i,N) {
    sum += pow(a[i]-avg, 2);
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 256
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

//

fn run() {
    input! {
        n: usize,
        m: usize,
        a: [usize; n],
    }
    let mut a = a;
    a.sort();
    let a = a;
    let mut ok = 2;//cnt >= m
    let mut ng = 200_000 + 1;//cnt < m
    while ng - ok > 1 {
        let mid = (ok + ng) / 2;
        let mut cnt = 0;
        let mut j = 0;
        for i in (0..n).rev() {
            while j < n && a[i] + a[j] < mid {
                j += 1;
            }
            cnt += n - j;
        }
        if cnt >= m {
            ok = mid;
        } else {
            ng = mid;
        }
    }
    let mut ans = 0;
    let mut sum = a.iter().fold(0, |s, a| s + *a);
    let mut cnt = 0;
    let mut j = 0;
    for i in (0..n).rev() {
        while j < n && a[i] + a[j] < ok {
            sum -= a[j];
            j += 1;
        }
        let c = n - j;
        cnt += c;
        ans += sum + c * a[i];
    }
    ans -= (cnt - m) * ok;
    println!("{}", ans);
}

fn main() {
    run();
}


Measured memory_bytes: 6396
// ProblemURL : https://atcoder.jp/contests/agc005/tasks/agc005_a
// ---------------------------------------------
package main

import "fmt"

func main() {
	var x string
	fmt.Scan(&x)

	ct := 0
	sta := 0
	for i := range x {
		switch x[i] {
		case 'S':
			sta++
		case 'T':
			if sta > 0 {
				sta--
				ct++
			}
		}
	}
	fmt.Println(len(x) - ct*2)
}


Measured memory_bytes: 1920
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    int n,r=0,p;
    cin>>n;
    p=n;
    while (p)
    {
        r=r*10+p%10;
        p/=10;
    }
    if (n==r)
        cout<<"Yes\n";
    else
        cout<<"No\n";
}

Measured memory_bytes: 256
<?php
// $n = (int)trim(fgets(STDIN));
$input = explode(' ', trim(fgets(STDIN)));

$n = (int)$input[0];
$m = (int)$input[1];

$input = explode(' ', trim(fgets(STDIN)));
$pq = new PriorityQueue();
for ($i=0; $i < $n; $i++) { 
	$pq->insert((int)$input[$i]);
}

for ($j=0; $j < $m; $j++) { 
	$tmp = $pq->pop();
	$pq->insert((int)floor($tmp/2));
}

$sum = 0;
for ($i=0; $i < $n; $i++) { 
	$sum += $pq->pop();
}

echo $sum;

/**
 * priority queue
 * 優先度設定を変更するときは、compareメソッドを変更する
 */
class PriorityQueue
{
	// 1-idxedな配列
	private $data = [];

	// データを追加する
	public function insert($d){
		$size = count($this->data);
		$this->increaseKey($size+1, $d);
	}

	// $this->data[$idx]に値$dを追加し、priorityを満たす位置まで上昇させる
	private function increaseKey($idx, $d){
		$this->data[$idx] = $d;
		$parent_idx = (int)floor($idx/2);
		while ($idx > 1 && $this->compare($this->data[$idx], $this->data[$parent_idx])) {
			$tmp = $this->data[$idx];
			$this->data[$idx] = $this->data[$parent_idx];
			$this->data[$parent_idx] = $tmp;
			$idx = $parent_idx;
			$parent_idx = (int)floor($idx/2);
		}
	}

	// priorityが最大のデータを取り出す
	public function pop(){
		$result = null;
		$size = count($this->data);
		if ($size > 0) {
			$result = $this->data[1];
			$this->data[1] = $this->data[$size];
			unset($this->data[$size]);
			if ($size !== 1) {
				$this->heapify(1);
			}
		}
		return $result;
	}

	// $this->data[$idx]を、priorityを満たす位置まで降下させる
	private function heapify($idx){
		$size = count($this->data);
		$l_idx = 2 * $idx;
		$r_idx = $l_idx + 1;
		$heighest_priority_idx = $idx;
		if ($l_idx <= $size && $this->compare($this->data[$l_idx], $this->data[$idx])) {
			$heighest_priority_idx = $l_idx;
		}
		if ($r_idx <= $size && $this->compare($this->data[$r_idx], $this->data[$heighest_priority_idx])) {
			$heighest_priority_idx = $r_idx;
		}

		if ($heighest_priority_idx !== $idx) {
			$tmp = $this->data[$heighest_priority_idx];
			$this->data[$heighest_priority_idx] = $this->data[$idx];
			$this->data[$idx] = $tmp;
			$this->heapify($heighest_priority_idx);
		}
	}

	// targetのpriorityがfromより真に高い場合にtrueを返す
	private function compare($target, $from){
		return ($target > $from);
	}

}

Measured memory_bytes: 18932
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // uint64_t

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))
#define BUF_SIZE 20

int get_int2(int *a1, int *a2) {
#ifdef BUF_SIZE
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, stdin)) return -1;
  sscanf(line, "%d %d", a1, a2);
#else
#error
#endif
  return 0;
}

#define ITEMS 3

#define K_MAX 2500
#define SUM_MAX (K_MAX*ITEMS)

void calc_cum(int *cum, int *dp, int limit) {
    int i;
    for(i = 1; i <= limit; i++) {
        cum[i] = cum[i-1] + dp[i-1];
    }
}

int main(void) {
    static int dp[ITEMS+1][SUM_MAX+1];
    static int cum[SUM_MAX+2];
    int limit, sum;
    get_int2(&limit, &sum);
    int i, j;
    for(i = 0; i <= min(limit, sum); i++) dp[1][i] = 1;
    calc_cum(cum, dp[1], sum+1);
    for(i = 2; i <= ITEMS; i++) {
        for(j = 0; j <= sum; j++) {
            // [j-2499, j]
            dp[i][j] = cum[j+1] - cum[max(0, j-limit)];
#ifdef DEBUG
            printf("dp[%d][%d] = %d\n", i, j, dp[i][j]);
#endif
        }
        calc_cum(cum, dp[i], sum+1);
    }

    printf("%d\n", dp[ITEMS][sum]);
    return 0;

}

Measured memory_bytes: 256
a,b,c,d,n,*A=`dd`.split.map &:to_i;e=f=1;a>c&&(a,c,e=c,a,-1);b>d&&(b,d,f=d,b,-1);V=A.each_slice(2).select{|x,y|a<=x&&x<=c&&b<=y&&y<=d}.map{|x,y|[x*e,y*f]}.sort;D=[F=1e9]*-~V.size;V.map{|x,y|D[D.bsearch_index{|e|e>y}]=y};N=D.index{|e|e>=F};p 1e2*(c-a+d-b)-20*N+5*(N+(N>[c-a,d-b].min ? 1:0))*Math::PI

Measured memory_bytes: 40984
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<int (n); i++)
/*
bool kougo(string s){
    int j=0;
    for(int i=0; i+1<s.size(); i++){
        if (s[i]==s[i+1]) ++j;
    }
    if(!j) return true;
    else return false;
}

int main(){

string s;
cin >> s;
int ans=0;
string t;

while(!kougo(s)){
    for (int i=0; i+1<s.size(); i++){
        if(s[i]==s[i+1]){
        ans+=2;
        s[i]=100; s[i+1]=100;
        }
    }
    rep(i,s.size()) if(s[i]!=100) t[i]=s[i];

}
*/

//問題文をよく読もう！

int main(){

string s;
cin >> s;
int count0=0, count1=0;
for(int i=0; i<s.size(); i++){
    if (s[i]=='0') count0++;
    else count1++;
}
int a=min(count0, count1);
cout << 2*a << endl;


}


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

using namespace std;

#define REP1(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pow(x) x*x
#define ll long long
static const ll MAX = 1000000;
static const ll INFTY = 1e12;
static const ll MOD = 1000000007;

template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };

struct edge {
    ll to, cost;
};

using Graph = vector<vector<int>>;
using _Graph = vector<vector<edge>>;


const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

// 深さ優先探索
vector<bool> seen;
vector<int> colors;

int H, W, N;
int sx, sy, gx, gy; 
vector<vector<char>> field;
vector<vector<int>> dist;
//vector<pair<int, int>> gx, gy;
deque<pair<int, int>> que;

typedef vector<vector<int> > Matrix;

const int INF = 100000000;


int main() {

    ll N;
    string S;
    cin >> N;
    cin >> S;
    ll R=0, G=0, B=0;
    ll all = 0;
    
    REP(i, S.length()){
        if(S[i] == 'R')R++;
        if(S[i] == 'G')G++;
        if(S[i] == 'B')B++;
    }
    all = R*G*B;

    ll j_i;
    ll sub = 0;

    for(int i = 0; i < N; i++){
        for(int j = i+1; j < N; j++){
            if (S[i] == S[j]) continue;
            j_i = j-i;
            ll k = j + j_i;
            if(k>=N || (S[i] == S[k] || S[j] == S[k]))continue;
            sub++;
        }
    }

    cout << all-sub << endl;

    
    

}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/


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

int main()
{
    for(int i=1; i<=9; i++)
    {
        for(int j=1; j<=9; j++)
        {
            int sum=i*j;
            cout<<i<<"x"<<j<<"="<<sum<<endl;
        }
    }
    return 0;
}



Measured memory_bytes: 3080
#include<iostream>
#include<cassert>
#include<stdexcept>
#include<utility>
#include<functional>
#include<numeric>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<array>
#include<stack>
#include<queue>
#include<deque>
#include<vector>
#include<complex>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<string>
#include<bitset>
#include<memory>
using namespace std;
using ll=long long;

int main(){
    string s;
    cin>>s;
    ll k;    
    cin>>k;
    if(s.size()==1){
        cout<<k/2<<endl;
        return 0;
    }
    string s1=s.substr(1,s.size()-1);

    ll c1=0;

    bool b1=false;
    for(int i=0;i<s.size();i++){
        if(s[i]==s[(i+1)%s.size()]){
            if(i+1==s.size()){
               b1=true; 
            }
            c1++;
            i++;
        }
    }

    ll c2=0;
    bool b2=false;
    for(int i=0;i<s1.size();i++){
        if(i+1!=s1.size() && s1[i]==s1[i+1]){
            c2++;
            i++;
        }
        else{
            if(s1[i]==s[0]){
                b2=true;
                i++;
                c2++;
            }
        }
    }

    

    if(!b1){
        cout<<c1*k<<endl;
    }
    else if(b2){
        cout<<c1+c2*(k-1)-1<<endl;
    }
    else{
        if(k%2==1) cout<<c1*((k+1)/2)+c2*(k/2)-1<<endl;
        else cout<<c1*((k+1)/2)+c2*(k/2)<<endl;
    }

    return 0;
}


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

using namespace std;

#define PI 3.1415926535897932

int main(){
    int n,k,x,y;
    scanf("%d",&n);
    scanf("%d",&k);
    scanf("%d",&x);
    scanf("%d",&y);
    printf("%d\n",x*min(n,k)+max(y*(n-k),0));

    return 0;
}


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

int n, k;
set<string> po;
string s[10];

int main()
{
  while (cin >> n >> k, n) {
    po.clear();
    for (int i = 0; i < n; i++){
      cin >> s[i];
    }
    sort(s, s + n);
    do {
      string uyu = "";
      for (int i = 0; i < k; i++){
        uyu += s[i];
      }
      po.insert(uyu);
    } while (next_permutation(s, s + n));

    cout << po.size() << endl;
  }
}

Measured memory_bytes: 3440
#define _USE_MATH_DEFINES
#include <iostream>
#include <complex>
#include <algorithm>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <cmath>
#include <math.h>
#include <numeric>
#include <list>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <climits>
#include <set>
#include <memory.h>
#include <memory>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cassert>
#include <map>
#include <cassert>
#include <time.h>

using namespace std;

typedef complex<double> xy_t;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int , P> PP;
typedef pair<int, string> Ps;
typedef vector<int> vec;
typedef vector<vec> mat;
const int INF= 1 << 30;
const double EPS = 1e-9;
const double PI = 3.1415926535897932384626433832795;

#define rep(i, n) for(int i = 0; i < n; i++)
string data = "afkpuzbglqv.chmrw?dinsx!ejoty ";

int main(){
	string s;
	while(cin >> s){
		if(s.size() % 2 != 0){
			cout << "NA" << endl;
			continue;
		}
		bool ok = true;
		string res(s.size()/2,' ');
		rep(i, (int)s.size()/2){
			int a = s[i*2] - '1';
			int b = s[i*2+1] - '1';
			if(a < 0 || 5 < a || b < 0 || 4 < b) {
				ok = false;
				break;
			}
			res[i] = data[b*6+a];
		}
		if(ok) cout << res << endl;
		else cout << "NA" << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector <int> lista;
  int aux;
  bool cont=false;
  for(int i=0; i<n; i++){
    cin>>aux;
    if(aux==1) cont=true;
    lista.push_back(aux);
  }
  if(cont){
    int breaks=0;
    aux=1;
    for(int i=0; i<n; i++){
      if(lista[i]==aux) aux++;
      else breaks++;
    }
    cout<<breaks;
  } else cout << -1;
}

Measured memory_bytes: 1400