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

int main(){
    int K, even, odd;
    cin >> K;

    if (K % 2 == 0){
        even = int(K / 2);
        odd  = int(K / 2);
    }
    else if(K % 2 == 1){
        even = int(K / 2);
        odd  = int(K / 2) + 1;
    }
    cout << even * odd << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define y0    lol
#define y1    lool
#define yn    loool
#define prev  looool
#define next  loooool
#define read  looooool
#define tm    loooooool
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define rrep(i,a,b) for(int i = (b); i >= (a); i--)
#ifdef LOCAL
#define rall(x,a) for(x : a)
#define LL "%lld"
#else
#define rall(x,a) for(auto x : a)
#define LL "%I64d"
#endif
#define rng(a) a.begin(), a.end()
#define PI 3.14159265358979323846
#define MOD 1000000007
#define endl "\n"
typedef long long ll;
using namespace std;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int a, b, t;
    cin >> a >> b >> t;
    int ans = 0;
    rep(i, 1, t) {
        if(i % a == 0) {
            ans += b;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S, T;
  cin >> S >> T;
  if (S.size() < T.size()) {
    cout << "UNRESTORABLE" << endl;
  }
  else {
    int F = S.size();
    int D = T.size();
    vector<char> ans(F);
    for (int j = 0; j < F; j++) {
        ans.at(j) = 'z';
      }
    bool ok = false;
    int K = (S.size() - T.size());
    for (int i = 0; i <= K; i++) {
      vector<char> B(F);
      for (int j = 0; j < F; j++) {
        if (S.at(j) == '?') {
          B.at(j) = 'a';
        }
        else {
          B.at(j) = S.at(j);
        }
      }
      int k = 0;
      bool good = true;
      for (int j = i; j < i + D; j++) {
        if (S.at(j) == '?') {
          B.at(j) = T.at(k);
        }
        else if (S.at(j) != T.at(k)) {
          good = false;
          break;
        }
        else {
          B.at(j) = S.at(j);
        }
        k++;
      }
      if (good) {
        ok = true;
        if (ans > B) {
          for (int j = 0; j < F; j++) {
             ans.at(j) = B.at(j);
          }
        }
      }
    }
    if (ok) {
      for (int j = 0; j < F; j++) {
        cout << ans.at(j);
      }
      cout << endl;
    }
    else {
      cout << "UNRESTORABLE" << endl;
    }
  }
}

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

int main() {
  int H, W;
  cin >> H >> W;
  string a, edge;
  for ( int i = 0; i < W + 2; i++ )
      edge += '#';
  cout << edge << endl;
  string picture;
  for ( int i = 0; i < H; i++ ) {
    cin >> picture;
    cout << '#' + picture + '#' << endl;
  }
  cout << edge << endl;
}


Measured memory_bytes: 256
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
    let nx:Vec<usize> = read_vec::<usize>();
    let l:Vec<usize> = read_vec::<usize>();

    let n = nx[0];
    let x = nx[1];

    let count = process(n, x, &l);
    println!("{}", count);
    return;
}

fn process(n:usize, x:usize, l:&Vec<usize>) ->  usize {
    let mut p = 0;
    for i in 0..n {
        if p > x {
           return i;
        }
        p = p + l[i];
    }
    if p > x {
        return n;
    }
    return n + 1;
}

Measured memory_bytes: 4352
import sys


class UnionFind():
    def __init__(self, n):
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x


N, M = map(int, input().split())
uf = UnionFind(N)
for _ in range(M):
    a, b = map(lambda x: int(x) - 1, sys.stdin.readline().split())
    uf.union(a, b)

print(sum(p < 0 for p in uf.parents) - 1)


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

int tot;
int N, A[1<<17];

int main() {
	scanf("%d", &N);
	for (int i = 0; i < N; ++i) scanf("%d", A+i);

	tot += abs(A[0]);
	for (int i = 0; i < N; ++i) tot += abs(A[i] - A[i+1]);
	
	printf("%d\n", tot - abs(A[0]) - abs(A[1] - A[0]) + abs(A[1]));
	for (int i = 1; i < N; ++i) printf("%d\n", tot - abs(A[i] - A[i-1]) - abs(A[i+1] - A[i]) + abs(A[i+1] - A[i-1]));
}

Measured memory_bytes: 1664
n=int(input())
XYH=[list(map(int,input().split())) for _ in range(n)]

XYH.sort(key=lambda x:x[2],reverse=True)
x0,y0,h0=XYH[0]
for i in range(101):
  for j in range(101):
    H = h0+abs(i-x0)+abs(j-y0)
    for x,y,h in XYH:
      if h>0:
        if H != h+abs(i-x)+abs(j-y):
          break
      else:
        if H-abs(i-x)-abs(j-y)>0:
          break
    else:
      print(i,j,H)
      exit()


Measured memory_bytes: 3064
#include <stdio.h>

int calc_digits(int num)
{
    int digits = 1;

    while (1)
    {
        num /= 10;
        if (num != 0)
        {
            digits++;
        }
        else
        {
            break;
        }
    }

    return digits;
}

int main()
{
    int x, y;
    while (EOF != scanf("%d %d", &x, &y))
    {
        printf("%d\n", calc_digits(x + y));
    }

    return 0;
}

Measured memory_bytes: 1676
n,t = gets.split.map(&:to_i)
list = (1..n).map{gets.split.map(&:to_i)}.sort
dp = [0]*(t+3001)

p list.map{|a,b|
  predp = dp.dup
  (0..t-1).each{|ti|
    if dp[tia=ti+a] < predpb=predp[ti]+b
      dp[tia] = predpb
    end
  }
  predp[t-1]+b
}.max

Measured memory_bytes: 60024
#include <bits/stdc++.h>
std::map<char, int> m;
int main()
{
    m.insert({'K', 0});
    m.insert({'U', 0});
    m.insert({'P', 0});
    m.insert({'C', 0});
    std::string str;
    std::cin >> str;
    for (int i = 0; i < str.size(); i++) {
        if (str[i] == 'K' || str[i] == 'U' || str[i] == 'P' || str[i] == 'C') m[str[i]]++;
    }
    std::cout << std::min(std::min(std::min(m['K'], m['U']), m['P']), m['C']) << std::endl;
    return 0;
}


Measured memory_bytes: 3220
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }

        static void Solve()
        {
            var ABC = Sarray();
            var K = Sarray()[0];
            var m = ABC.Max();
            WriteLine(ABC.Sum() - m + (long)Pow(2, K) * m);
            
        }

        static long Mod = 998244353;
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
    }
}

Measured memory_bytes: 28360
program Battle;
var
	A, B, C, D : integer;
begin
	readln(A, B, C, D);
	repeat 
		A := A - D;
		C := C - B;
	until (A <= 0) or (C <=0);
	if C <= 0 
		then writeln('Yes')
		else writeln('No');
end.	

Measured memory_bytes: 1368
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    n,b,r=INTM()
    s=r+b
    print(n//s*b+min(b,(n%s)))
if __name__ == '__main__':
    do()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define pi 3.14159
using namespace std;
typedef long long LL;
const LL MOD = 1e9 + 7;
const int N = 1e5 + 7, M = 1e7, OO = 0x3f3f3f3f;
#define AC ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin.sync_with_stdio(0);
int main()
{
string s;
cin>>s;
for(int i=0;i<s.size();i++){
    if(s[i]==','){
        cout<<" ";
        continue;
    }
    cout<<s[i];
}



    return 0;
}


Measured memory_bytes: 3600
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
using namespace std;



int main(){
		
		int caseNum;
		cin>>caseNum;
		int arr [200001];
		int base [200001];
		long long outp [200001];
		long long tt=0;
		
		for(int i=1;i<=caseNum;i++){
			arr[i]=0;
			outp[i]=0;
		}
		for(int i=1;i<=caseNum;i++){
			cin>>base[i];
			arr[base[i]]++;
		}
		
		for(int i=1;i<=caseNum;i++){
			if(arr[i]>1){
				for(int j=arr[i]-1;j>0;j--){
				tt=tt+j;
				}
			}
		}
		
		for(int i=1;i<=caseNum;i++){
			if(arr[base[i]]>1){
				outp[i]=tt-arr[base[i]]+1;	
			}else outp[i]=tt;
			cout<<outp[i]<<endl;
		}	
		return 0;
}



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

int main() {
    int n, q;
    string str;
    cin >> n >> q >> str;
    vector<pair<int, int>> query(q);
    vector<int> cnt(n);
    cnt.at(0) = 0;
    rep(i, q) {
        int l, r;
        cin >> l >> r;
        query.at(i) = make_pair(l, r);
    }
    rep(i, n - 1) {
        if(str.at(i) == 'A' && str.at(i + 1) == 'C') cnt.at(i + 1) = cnt.at(i) + 1;
        else cnt.at(i + 1) = cnt.at(i);
    }
    for(pair<int, int> p : query) {
        int ans = cnt.at(p.second - 1) - cnt.at(p.first - 1);
        cout << ans << endl;
    }
}

Measured memory_bytes: 2176
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using std::cerr;
using std::cin;
using std::cout;
using std::endl;

using namespace std;

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

  int n;
  cin>>n;
  vector<int64_t> a(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  int64_t result=0;
  int64_t price=2;
  for(int i=0;i<n;i++){
    if(i==0){
      result+=a[i]-1;
    }else{
      if(price==a[i]){
        price++;
      }else{
        result+=(a[i]-1)/price;
      }
    }
  }

  cout<<result<<endl;

  return 0;
}


Measured memory_bytes: 1024
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        String s = sc.next();
        long ans=0;

        for(int i=0;i<Math.pow(2,s.length()-1);i++){
            int shift =i;
            int n=0;
            boolean[] bit = new boolean[s.length()];
            for(int j=0;j<s.length();j++){
                bit[j]=shift%2==1;
                shift = shift>>1;
                if(bit[j])n++;
            }

            int nk=0;
            for(int j=0;j<n+1;j++){

                String temp = "";
                for(int k=nk;k<s.length();k++){
                    temp += s.charAt(k);
                    if(bit[k]){
                        nk=k+1;
                        break;
                    }
                }

                ans+=Long.parseLong(temp);
                //System.out.println(Integer.parseInt(temp));

            }
        }

        System.out.println(ans);
    }
}


Measured memory_bytes: 21844
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<cctype>
#include<string.h>

#define PI 3.1415926

int main(){
	int a, b,c;
	double	C, S, L, h;
	scanf("%d %d %d", &a, &b, &c);

	C =c *PI / 180;

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

	printf("%f\n%f\n%f\n", S, L, h);
	
	return 0;
}

Measured memory_bytes: 2928
#include <bits/stdc++.h>
using namespace std;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a) 
#define dumparr(a,n) 
#endif
#define FOR(i, a, b) for(ll i = a;i < b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = b-1;i >= a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;

const ll INF=(1LL<<50);

template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}


void solve(long long N){
  cout<<N*N*N<<endl;
  return;
}

int main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}


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

#ifdef DEBUG
#define PRINT(x)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#x<<" = "<<(x)<<endl;
#define PRINTA(a,first,last)\
    cout<<"func "<<__func__<<": line "<<__LINE__<<": "<<#a<<"["<<(first)<<", "<<(last)<<")"<<endl;\
    for (int i=(first);i<(last);++i){cout<<#a<<"["<<i<<"] = "<<(a)[i]<<endl;}
#else
#define PRINT(x)
#define PRINTA(a,first,last)
#endif

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007

using namespace std;

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

template <class T, class U> void amax(T& x, U y) {if (x < y) x = y;}
template <class T, class U> void amin(T& x, U y) {if (x > y) x = y;}

int gcd(int x, int y) {
    while (y != 0) {
        int r = x % y;
        x = y;
        y = r;
    }
    return x;
}

int solve(int N, vector<int> &A) {
    // l[i] == gcd(A[0],A[1],...,A[i]) (0 <= i < N),
    // r[i] == gcd(A[N-1],A[N-2],...,A[N-i-1]) (0 <= i < N).
    vector<int> l(N), r(N);
    l[0] = A[0];
    r[0] = A[N - 1];
    FOR (i, 1, N) {
        l[i] = gcd(l[i - 1], A[i]);
        r[i] = gcd(r[i - 1], A[N - i - 1]);
        //printf("l[%d] = %d\n", i, l[i]);
        //printf("r[%d] = %d\n", i, r[i]);
    }
    int result = max(l[N - 2], r[N - 2]);
    FOR(i, 1, N - 2 + 1) {
        //printf("gcd([0, %d]) = %d, gcd([%d, N - 1]) = %d\n", i - 1, l[i - 1], i + 1, r[N - i - 2]);
        amax(result, gcd(l[i - 1], r[N - i - 2]));
    }
    return result;
}

int main(void) {
    int N;
    cin >> N;
    vector<int> A(N);
    REP(i, N) cin >> A[i];

    cout << solve(N, A) << endl;

    return 0;
}

Measured memory_bytes: 1408
#include <iostream>
using namespace std;
int main()
{
    int n,k;
    cin >> n >> k;
    int b[n];
    int sum=0;
    int s,t;
    for(int i=0;i<n;i++){
        cin >> b[i];
        if(b[i]>k-b[i]){
            sum += (k-b[i])*2;
        }
        else{
            sum += b[i]*2;
        }
    }
    cout << sum << "\n";
    return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9) + 7;

int main(void) {
	vector<int> x(5), v(5);
	
	for(int i = 0; i < 5; ++i) {
		cin >> x[i];
		
		if( x[i] % 10 > 0 ) v[i] = x[i] + 10 - (x[i] % 10);
		else v[i] = x[i];
	}
	
	int ans = MOD;
	for(int i = 0; i < 5; ++i) {
		int sum = 0;
		
		for(int j = 0; j < 5; ++j) {
			if( i != j ) sum += v[j];
		}
		
		sum += x[i];
		ans = min(ans, sum);
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int n, a[maxn], b[maxn];
signed main() {
    ios::sync_with_stdio(false); cin.tie(0);
    cin >> n;
    for (int i = 1; i <= n; ++i) cin >> a[i] >> b[i];
    if (n % 2) {
        sort(a + 1, a + n + 1);
        sort(b + 1, b + n + 1);
        int mid = (n + 1) >> 1;
        cout << b[mid] - a[mid] + 1;
    }
    else {
        sort(a + 1, a + n + 1);
        sort(b + 1, b + n + 1);
        int t1 = a[n / 2] + a[n / 2 + 1];
        int t2 = b[n / 2] + b[n / 2 + 1];
        cout << t2 - t1 + 1 << endl;
    }
    return 0;
}

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

using namespace std;
typedef long long ll;
typedef long double ld;
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }


const int q = 1e9+7;
int a,b,ans=0;


int main()
{
    cin>>a>>b;
    ans=a+(b/2);
    cout<<ans<<endl;


    return 0;
}
// gotcha;


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cmath>
#define ll long long
using namespace std;

ll fmx(ll x, ll y, ll z) {
	if(x >= y && x >= z) return x;
	if(y >= z && y >= x) return y;
	if(z >= x && z >= y) return z;
}
ll fmn(ll x, ll y, ll z) {
	if(x <= y && x <= z) return x;
	if(y <= z && y <= x) return y;
	if(z <= x && z <= y) return z;
}
int main() {
	ll h, w, ans = 1e18, x, y, z;
	scanf("%lld%lld", &h, &w);
	if(h%3==0 || w%3==0) 
		ans = 0;
	else {
		ans = min((int)(ceil(h/3.0) - floor(h/3.0))*w, (int)(ceil(w/3.0) - floor(w/3.0))*h);
		for(int i = 1; i <= h / 2; i++) {
			x = i * w;
			y = (h-i) * (w/2);
			z = h * w - x - y;
			ans = min(ans, fmx(x, y, z) - fmn(x, y, z));
		}
		for(int i = 1; i <= w / 2; i++) {
			x = i * h;
			y = (w-i) * (h/2);
			z = h * w - x - y;
			ans = min(ans, fmx(x, y, z) - fmn(x, y, z));
		}
	}
	printf("%lld\n", ans);
	return 0;
}


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

int main() {
  	int w, a, b;
  	cin >> w >> a >> b;
  	if(abs(a-b) <= w) {
    	cout << 0 << endl;
    }else {
    	cout << abs(a-b) - w << endl;
    }
    return 0;
}

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

int main(){
  int N;
  cin >> N;

  int cnt=0;
  for (int i = 0; i < N; i++) {
    int l, r;
    cin >> l >> r;
    cnt += r-l+1;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
	int a, b, c, count =0;
	scanf("%d %d %d", &a, &b, &c);
	for (int temp =b; temp >= a; temp -= a) {
		count++;
		if (count >= c) break;
	}
	printf("%d", count);
	return 0;
}

Measured memory_bytes: 128
// ConsoleApplication50.cpp : コンソール アプリケーションのエントリ ポイントを定義します。
//

//#include "stdafx.h"
#include <iostream>

using namespace std;

#define int long long

signed main()
{
	int n, m;
	cin >> n >> m;
	if (n * 2 <= m) {
		int count = n + ((m - (2 * n)) / 4);
		cout << count << endl;
	}
	else {
		int count = (m / 2);
		cout << count << endl;
	}
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())
#define fi first
#define se second

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<endl;
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;
const ll inf=1e15;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin>>s;
  int n=s.size();
  vector<vector<ll>> dp(n+1,vector<ll>(4,0));
  dp[0][0]=1;
  rep(i,n)rep(j,4){
    if(j==3){
      if(s[i]=='?'){
        (dp[i+1][j]+=(3*dp[i][j])%mod)%=mod;
      }else{
        (dp[i+1][j]+=dp[i][j])%=mod;
      }
    }else if(j==2){
      if(s[i]=='?'){
        (dp[i+1][j+1]+=dp[i][j])%=mod;
        (dp[i+1][j]+=(3*dp[i][j])%mod)%=mod;
      }else if(s[i]=='C'){
        (dp[i+1][j+1]+=dp[i][j])%=mod;
        (dp[i+1][j]+=dp[i][j])%=mod;
      }else{
        (dp[i+1][j]+=dp[i][j])%=mod;
      }
    }else if(j==1){
      if(s[i]=='?'){
        (dp[i+1][j+1]+=dp[i][j])%=mod;
        (dp[i+1][j]+=(3*dp[i][j])%mod)%=mod;
      }else if(s[i]=='B'){
        (dp[i+1][j+1]+=dp[i][j])%=mod;
        (dp[i+1][j]+=dp[i][j])%=mod;
      }else{
        (dp[i+1][j]+=dp[i][j])%=mod;
      }
    }else{
      if(s[i]=='?'){
        (dp[i+1][j+1]+=dp[i][j])%=mod;
        (dp[i+1][j]+=(3*dp[i][j])%mod)%=mod;
      }else if(s[i]=='A'){
        (dp[i+1][j+1]+=dp[i][j])%=mod;
        (dp[i+1][j]+=dp[i][j])%=mod;
      }else{
        (dp[i+1][j]+=dp[i][j])%=mod;
      }
    }
  }
  cout<<dp[n][3]<<endl;
}

Measured memory_bytes: 7376
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string a,b;
	cin>>b>>a;
	cout<<a<<b<<endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;

main() {
  int64_t n;
  cin >> n;
  
  vector<int64_t> a(n);
  for (auto&& aa : a) {
    cin >> aa;
  }

  int64_t r = 0;
  int64_t s = 0;
  int64_t ans = 0;
  for (auto l : irange(0L, n)) {
    while (r < n && (s ^ a[r]) == (s + a[r])) {
      s += a[r];
      ++r;
    }
    
    ans += r - l;
    s -= a[l];    
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 1792
import sys
def input():
	return sys.stdin.readline()[:-1]

H, W, k = map(int, input().split())
s = [input() for _ in range(H)]

ans = (H-1) * (W-1)
for bit in range(1<<(H-1)):
	hs = []
	cur = [0]
	res = 0
	for i in range(1, H):
		if bit & (1 << (i-1)) == 0:
			cur.append(i)
		else:
			res += 1
			hs.append(cur)
			cur = [i]
	hs.append(cur)
	#print(hs)
	ng = False
	whites = [0 for _ in range(len(hs))]
	for c, d in enumerate(hs):
		for h in d:
			if s[h][0] == "1":
				whites[c] += 1
		if whites[c] > k:
			ng = True
	

	for w in range(1, W):
		tmp = [0 for _ in range(len(hs))]
		for c, d in enumerate(hs):
			for h in d:
				if s[h][w] == "1":
					tmp[c] += 1
			if tmp[c] > k:
				ng = True

		over = False
		for c in range(len(hs)):
			if whites[c] + tmp[c] > k:
				over = True

		if over:
			res += 1
			whites = tmp
		else:
			whites = [wh + t for wh, t in zip(whites, tmp)]
		#print(whites)

	if not ng:
		ans = min(ans, res)

print(ans)

Measured memory_bytes: 50652
#include <bits/stdc++.h>
using namespace std;
#define int           long long
#define pb            push_back
#define mp            make_pair
#define PI            3.14159265
#define M             1000000007
#define MM            998244353
#define fr            first
#define sc            second
#define all(v)        (v).begin(),(v).end()
#define rall(v)       (v).rbegin(),v.rend()
#define vc            vector
#define vi            vector<int>
#define pii           pair<int,int>
#define psi           pair<string,int>
#define pis           pair<int,string>
#define mii           map<int,int>
#define msi           map<string,int>

int solve(){
    int a,b,t; cin>>a>>b>>t;
    t/=a;
    cout<<b*t;
}

signed main() {
    ios::sync_with_stdio(false);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int t=1;
    //cin>>t;
    while(t--) solve();
    return 0;
}

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

int n, m, q, l, r;

int dp[N][N];

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
    cin >> n >> m >> q;
    for (int i = 0; i < m; i++) {
		cin >> l >> r;
		dp[l][r]++;
	}
		
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			dp[i][j] = dp[i][j] + dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - 1];
		}
	}
	
	while (q--) {
		cin >> l >> r;
		cout << dp[r][r] - dp[l - 1][r] << "\n";
	}
	
    return 0;
}


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

const int INF = 1e9;
const int maxn = 2e5 + 5;
int minv[maxn << 2];
#define lson o*2,l,mid
#define rson o*2+1,mid+1,r
 
void pushup(int o){
    minv[o] = min(minv[o*2],minv[o*2+1]);
}
 
void build(int o, int l, int r){
    minv[o] = INF;
    if(l == r)
        return;
    int mid = (l + r) / 2;
    build(lson);
    build(rson);
}
 
void update(int o, int l, int r, int p, int v){
    if(l == r){
        minv[o] = v;
        return;
    }
    int mid = (l + r) / 2;
    if(p <= mid)
        update(lson, p, v);
    if(p > mid)
        update(rson, p, v);
    pushup(o);
}
 
int query(int o, int l, int r, int ql, int qr){
    if(ql <= l && r <= qr){
        return minv[o];
    }
    int mid = (l + r) / 2;
    if(qr <= mid)
        return query(lson, ql, qr);
    if(ql > mid)
        return query(rson, ql, qr);
    return min(query(lson, ql, qr), query(rson, ql, qr));
}

int n, q;
int b[maxn];
vector<int> G[maxn];

int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n;
    int delta = 0;
    for(int i = 1;i <= n;i++){
        cin >> b[i];
        delta += (b[i] == 0);
    }
    cin >> q;
    for(int i = 1;i <= q;i++){
        int l, r;
        cin >> l >> r;
        G[l].push_back(r);
    }
    build(1, 1, n + 1);
    update(1, 1, n + 1, 1, 0);
    for(int i = 1;i <= n;i++){
        //vector<pair<int, int> > tmp;
        for(auto r : G[i]){
            int val = query(1, 1, n + 1, i, r + 1);
            update(1, 1, n + 1, r + 1, val);
        }
        int cost = (b[i] == 1) - (b[i] == 0);
        int val = query(1, 1, n + 1, i, i);
        int val1 = query(1, 1, n + 1, i + 1, i + 1); 
        if(val + cost < val1)
            update(1, 1, n + 1, i + 1, val + cost);
    }
    int ans = query(1, 1, n + 1, n + 1, n + 1);
    cout << ans + delta << endl;
    return 0;
}



Measured memory_bytes: 12416
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <climits>
#include <set>
#include <map>
#include <iomanip>
#include <cassert>
#include <functional>
#include <cstring>

using namespace std;

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

typedef pair<int, int> P;
#define mp make_pair
#define FOR(i, a, b) for(int (i)=a;(i)<(b);++(i))
#define rep(i, n)  FOR(i,0,n)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort((v).begin(), (v).end());					//小さい順
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());		//大きい順
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define all(c) (c).begin(),(c).end()
#define ll long long
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define Print(p) cout<<(p)<<endl
#define F first
#define S second
#define pb push_back
#define mod 1000000007LL
#define INF 12345678901234567

const int maxn = 1e5 + 10;

ll dp[1005] = { -INF };
vector<pair<ll, ll>> g[5000];
bool mugen = false;

void dfs(ll to, ll from, ll cost, vb check)
{
	if (check[to])
	{
		mugen = true;
	}
	else {
		dp[to] = max(dp[to], cost);
		//cout << to << " " << dp[to] << endl;
		check[to] = true;
		for (auto i : g[to])
		{
			dfs(i.first, to, cost + i.second, check);
		}
	}
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	// your code is here

	ll n, T; cin >> n >> T;

	vi t(200005);

	rep(i, n) cin >> t[i];

	ll sum = T;
	FOR(i, 1, n)
	{
		if (-t[i - 1] + t[i] < T) sum += t[i] - t[i - 1];
		else sum += T;
	}

	Print(sum);
	return 0;

}

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

double pwd( int tei,int n ){
	int i;
	double ans = 1;
	if( n >= 0 ){	
		for( i = 0;i < n;i++ ){
			ans *= tei;
		}
	}
	else{
		for(i = 0;i < -n;i++ ){
			ans /= tei;
		}
	}
	return ans;
}

int main(){
	double n;
	int ans[12];

	while( cin >> n ){
		if( n < 0 )
			break;
		for(int i = 7; i >= -4; i--)
		{
			if( n >= pwd( 2,i ) ){
				ans[i+4] = 1;
				n -= pwd( 2,i );
			}
			else{
				ans[i+4] = 0;
			}
		}
		if( n != 0 ){
			cout << "NA" << endl;
			continue;
		}
		for( int i = 11;i >= 0;i-- ){
			cout << ans[i];
			if( i == 4 ){
				cout << ".";
			}
			if( i == 0){
				cout << endl;
			}
		}
			
	}
	return 0;
}

Measured memory_bytes: 1224
def main():
    import sys
    input = sys.stdin.readline
    H, W = [int(x) for x in input().strip().split()]
    Ch, Cw = [int(x)-1 for x in input().strip().split()]
    Dh, Dw = [int(x)-1 for x in input().strip().split()]
    M = [W for _ in range(H)]
    for h in range(H):
        M[h] = list(input().strip())
        # print(M[h])
    ans = 0
    q = set([(Dh, Dw)])
    while True:
        nq = set()
        while q:
            q_ = set()
            for h, w in q:
                # print('({}, {}) = {}'.format(h, w, ans))
                if h == Ch and w == Cw:
                    print(ans)
                    return True
                M[h][w] = '#'
                nq.add((h, w))
                for dh, dw in [(1, 0), (0, 1), (-1, 0), (0, -1)]:
                    if 0 <= h+dh < H and 0 <= w+dw < W:
                        if M[h+dh][w+dw] == '.':
                            q_.add((h+dh, w+dw))
                            M[h+dh][w+dw] = '#'
            q = q_

        if nq:
            for h, w in nq:
                for dh in range(-2, 3):
                    for dw in range(-2, 3):
                        if 0 <= h+dh < H and 0 <= w+dw < W:
                            if M[h+dh][w+dw] == '.':
                                q.add((h+dh, w+dw))
        # for h in range(H):
        #     print(M[h])
        if len(q):
            ans += 1
        else:
            print(-1)
            return True

if __name__ == '__main__':
    main()

Measured memory_bytes: 131468
// ----- In the name of ALLAH, the Most Gracious, the Most Merciful -----

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

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define deb(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define memo(a,val) memset(a,val,sizeof(a))
#define NINJA ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define all(a) a.begin(),a.end()
#define fo(i,n) for(int i=0;i<n;i++)
#define Fo(i,k,n) for(int i=k;i<n;i++)
#define for1(i,n) for(int i=1;i<=n;i++)
#define dloop(i,n) for(int i=n-1;i>=0;i--)
#define iii tuple<int,int,int>
#define vi vector<int>
#define ii pair<int,int>
#define vii vector<ii>
#define int long long
#define ld long double
#define pb push_back
#define endl "\n"
#define setbits __builtin_popcountll
#define mp map<int,int>
#define F first
#define S second
#define sz(v) (int)v.size()
#define mod 1000000007
#define inf (int)1e18

int32_t main(){
	NINJA;

	string s; cin >> s;
	int sum =0;
	for(char c : s){
		sum += c-'0';
	}
	cout << (sum%9==0 ? "Yes" : "No" ) << endl;
	
	return 0;
}

Measured memory_bytes: 3728
import java.util.Scanner;

class Main {
    public static void main(String[] args) {

        try (Scanner sc = new Scanner(System.in)) {
            int N = Integer.parseInt(sc.nextLine());
            String S = sc.next();
            StringBuilder result = new StringBuilder();

            for (int i = 0; i < S.length(); i++){
                int ascii = (int)S.charAt(i);
                ascii = ascii + N;
                if (ascii > (int)'Z') {
                    ascii = ascii % (int)'Z' + (int)'A' -1;
                }
                result.append((char)ascii);
            }
            System.out.println(result.toString());
        }
    }
}

Measured memory_bytes: 23892
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <fstream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

string foo(string s, string t) {
	int ls = s.length(), lt = t.length();
	if (ls < lt) return s;
	if (ls > lt) return t;
	return min(s, t);
}

int main() {
	for (;;) {
		int N; cin >> N;
		if (N == 0) break;
		vector<string> s(N);
		for (int i = 0; i < N; i++)
			cin >> s[i];
		sort(s.begin(), s.end());
		s.erase(unique(s.begin(), s.end()), s.end());
		N = s.size();
		vector<bool> a(N, true);
		for (int i = 0; i < N; i++) {
			int l = s[i].length();
			for (int j = 0; j < N; j++) {
				if (j == i) continue;
				for (int k = 0; k + l <= s[j].length(); k++)
					if (s[j].substr(k, l) == s[i])
						a[i] = false;
			}
		}
		vector<string> _s;
		_s.push_back("");
		for (int i = 0; i < N; i++)
			if (a[i]) _s.push_back(s[i]);
		s = _s;
		N = s.size();
		vector< vector<string> > t(N, vector<string>(N));
		for (int i = 0; i < N; i++)
			for (int j = 0; j < N; j++) {
				int l = min(s[i].length(), s[j].length());
				for (;;) {
					if (s[i].substr(s[i].length() - l) == s[j].substr(0, l))
						break;
					l--;
				}
				t[i][j] = s[j].substr(l);
			}
		vector< vector<string> > dp(1 << N, vector<string>(N, string(101, 'z')));
		dp[1][0] = "";
		for (int S = 1; S < (1 << N); S++)
			for (int i = 0; i < N; i++) {
				if (!(S & (1 << i))) continue;
				int T = S - (1 << i);
				for (int j = 0; j < N; j++) {
					if (!(T & (1 << j))) continue;
					dp[S][i] = foo(dp[S][i], dp[T][j] + t[j][i]);
				}
			}
		string sss(101, 'z');
		for (int i = 0; i < N; i++)
			sss = foo(sss, dp[(1 << N) - 1][i]);
		cout << sss << endl;
	}
}

Measured memory_bytes: 1880
s = list(map(int, input().split()))
s = list(map(int, input().split()))
ans = 1
if 0 in s:
    print(0)
else:
    for i in s:
        ans *= i
        if ans > 10**18:
            break
    if ans > 10**18:
        print(-1)
    else:
        print(ans)


Measured memory_bytes: 21700
INF = 10 ** 9

def main():
    N, K = map(int, input().split())
    H = list(map(int, input().split()))

    dp = [INF] * N
    dp[0] = 0
    for i in range(1, N):
        ks = max(0, i-K)
        hi = H[i]
        for j in range(ks, i):
            dp[i] = min(dp[i], dp[j] + abs(hi - H[j]))
    
    print(dp[N-1])


if __name__ == "__main__":
    main()

Measured memory_bytes: 52448
#include<bits/stdc++.h>
#define ll long long
const ll inf=1e18L+5;
using namespace std;


int main()
{
	int n;
	cin>>n;
	vector<ll>a(n);
	vector<ll>s(n,0);
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		if(i!=0)
			s[i]+=s[i-1]+a[i];
		else
			s[i]=a[i];
	}

	ll dp[405][405];
	// memset(dp,inf,sizeof(dp));
	for(int l=n-1;l>=0;l--)
	{
		for(int r=l;r<n;r++)
		{
			if(l==r)
			{
				dp[l][r]=0;
				continue;
			}
			dp[l][r]=inf;
			ll range=0;
			if(l-1>=0)
				range=s[r]-s[l-1];
			else
				range=s[r];
			for(int i=l;i<r;i++)
				dp[l][r]=min(dp[l][r],dp[l][i]+dp[i+1][r]+range);
		}
	}
	cout<<dp[0][n-1];
}


Measured memory_bytes: 4920
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    cout << fixed << setprecision(10);
    int n;
    cin >> n;
    vector<int> v(n);
    rep(i,n) cin >> v[i];
    map<int,int> mii1,mii2;
    rep(i,n){
        if(i%2 == 0) mii1[v[i]]++;
        else mii2[v[i]]++;
    }
    auto itr1 = mii1.begin();
    auto itr2 = mii2.begin();
    vector<pair<int,int>> v1,v2;
    for(auto u : mii1){
        v1.push_back({u.second,u.first});
    }
    for(auto u : mii2){
        v2.push_back({u.second,u.first});
    }
    sort(v1.rbegin(), v1.rend());
    sort(v2.rbegin(), v2.rend());
    if(v1[0].second == v2[0].second){
        if(v1.size() == 1){
            if(v2.size() != 1)cout << n/2 - v2[1].first << endl;
            else cout << n/2 << endl;
            return 0;
        }
        if(v2.size() == 1){
            if(v1.size() != 1)cout << n/2 - v1[1].first << endl;
            else cout << n/2 << endl;
            return 0;
        }
        //cout << "yes" << endl;
        cout << min(n - v1[0].first - v2[1].first, n - v1[1].first - v2[0].first) << endl;
        return 0;
    }
    cout << n - v1[0].first - v2[0].first << endl;
    return 0;
}

Measured memory_bytes: 9224
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
int main(){
string S;
cin>>S;
int ans=0,czero=0,cone=0,count=0;
for(int i=0;i<S.size();i++){
      if(S.at(i)=='0')czero++;
      else cone++;
}   
ans=2*min(czero,cone);
cout<<ans<<endl;
}


Measured memory_bytes: 512
class struct:
  def __init__(self,a,b):
    self.a=a
    self.b=b

n=int(input())
l=list(map(int,input().split()))

l2=[struct(0,0) for _ in range(n)]
l2[0].a=l[0]
l2[1].a=l[1]
l2[1].b=abs(l[0]-l[1])

i=2
for x in l[2:]:
  l2[i].a=x
  l2[i].b=min(abs(l2[i-2].a-x)+l2[i-2].b,
    abs(l2[i-1].a-x)+l2[i-1].b)
  i+=1

print(l2[-1].b)

Measured memory_bytes: 28180
/*   _/                _/                 _/_/_/   _/
  _/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
   _/     _/    _/   _/     _/    _/  _/_/_/     _/
  _/     _/    _/   _/     _/    _/  _/    _/   _/
   _/_/   _/_/       _/_/   _/_/      _/_/     _/ */
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
using ll=long long;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=1e18;
using P=pair<int,int>;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  ll n,a[200005]={},ans=0,cnt[200005]={};
  cin >> n;
  map<ll,ll> m;
  for(int i=0; i<n; i++) {
    cin >> a[i];
    m[a[i]]++;
    if(m[a[i]]>1) {
      ans+=m[a[i]]-1;
      cnt[a[i]]+=m[a[i]];
    }
  }
  for(int i=0; i<n; i++) {
    cout << ans-m[a[i]]+1 << "\n";
  }
}

Measured memory_bytes: 11136
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
using namespace std;
using ll = int64_t;
using vi = vector<int>;
using vvi = vector<vi>;


//auto mod int
//https://github.com/atcoder-live/library/blob/master/mint.cpp

const int mod = 1000000007;
//const int mod = 998244353;

struct mint {
    int64_t x;
    mint(int64_t x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(int64_t t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    //for prime mod
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) {return mint(*this) /= a;}
};

istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

struct Sieve {
    int n;
    vector<int> f, primes;
    Sieve(int n=1):n(n), f(n+1) {
        f[0] = f[1] = -1;
        for(int64_t i=2; i<=n; ++i) {
            if(f[i]) continue;
            primes.push_back(i);
            f[i] = i;
            for(int64_t j = i*i; j <= n; j += i) {
                if(!f[j]) f[j] = i;
            }
        }
    }
    bool isPrime(int x) {return f[x] == x;}
    vector<int > factorList(int x) {
        assert(x <= n);
        vector<int> res;
        while(x != 1) {
            res.emplace_back(f[x]);
            x /= f[x];
        }
        return res;
    }
    vector<pair<int, int> > factor(int x) {
        vector<int> fl = factorList(x);
        if(fl.size() == 0) return {};
        vector<pair<int, int> > res(1, pair<int, int>(fl[0], 0));
        for(int p : fl) {
            if(res.back().first == p) {
                ++res.back().second;
            } else {
                res.emplace_back(p, 1);
            }
        }
        return res;
    }
} s(1000000);

int main() {
    int n;
    cin >> n;
    vi a(n);
    rep(i, n) {
        cin >> a[i];
    }

    map<int, int> mp;
    rep(i, n) {
        for(auto x:s.factor(a[i])) {
            if(mp[x.first] < x.second) {
                mp[x.first] = x.second;
            }
        }
    }

    mint lcm=1;
    for(auto x:mp) {
        mint b = x.first;
        lcm *= b.pow(x.second);
    }

    mint ans=0;
    rep(i, n) {
        ans += lcm / a[i];
    }

    cout << ans << endl;
}


Measured memory_bytes: 4984
W,H,N=[int(i) for i in input().split()]
l,r,u,d = 0,W,0,H

for i in range(N):
	x,y,a=[int(i) for i in input().split()]
	if a==1:
		l=max(l,x)
	if a==2:
		r=min(r,x)
	if a==3:
		u=max(u,y)
	if a==4:
		d=min(d,y)
h=max(0,d-u)
w=max(0,r-l)

print(h*w)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // std::ifstream in("input.txt");
    // std::cin.rdbuf(in.rdbuf());
    ll x, y;
    cin >> x >> y;
    if (abs(x - y) <= 1) {
        cout << "Brown" << endl;
    }
    else {
        cout << "Alice" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

def s(generator, splitter, mapper):
    return [ mapper(s) for s in generator().split(splitter) ]

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

a,b,c = get_nums_l()
print(max(0,c-(a-b)))

Measured memory_bytes: 38256
using System.Collections.Generic;
using static System.Console;

class Program {
    static void Main() {
        var s = NextString();
        var t = new char[s.Length];
        for (var i = 0; i < s.Length; i++) {
            t[i] = s[i];
        }

        for (var v = 'a'; v <= 'z'; v++) {
            if (!s.Contains(v.ToString())) {
                WriteLine(s + v);
                return;
            }
        }
        if (!NextPermutation(t)) {
            WriteLine(-1);
        } else {
            var i = 0;
            while (s[i] == t[i]) {
                Write(s[i]);
                i++;
            }
            WriteLine(t[i]);
        }
    }

    static bool NextPermutation(char[] t) {
        var n = t.Length;
        var i = n - 2;
        while (i >= 0 && t[i] >= t[i + 1]) {
            i--;
        }
        if (i < 0) {
            return false;
        }
        var j = i + 1;
        while (j < n && t[j] > t[i]) {
            j++;
        }
        j--;
        var tmp = t[i];
        t[i] = t[j];
        t[j] = tmp;

        var left = i + 1;
        var right = n - 1;

        while (left < right) {
            tmp = t[left];
            t[left] = t[right];
            t[right] = tmp;

            left++;
            right--;
        }
        return true;
    }

    static string NextString() {
        var result = new List<char>();
        while (true) {
            int next = Read();
            if (next < 0)
                break;
            var nextChar = (char)next;
            if (!char.IsWhiteSpace(nextChar))
                result.Add(nextChar);
            else if (nextChar != '\r')
                break;
        }
        return string.Join("", result);
    }
}

Measured memory_bytes: 13268
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
using namespace std;

int main(){

  int a,b,d,r;
  double f;

  cin >>a >>b;

  d=a/b;
  r=a%b;
  f=(double)a/(double)b;
  printf("%d %d %f\n",d,r,f);

  return 0;
}

Measured memory_bytes: 1188
#include <iostream>

int main()
{
  std::string s, t;
  bool flag = true;
  int i;

  std::cin >> s >> t;

  for (i = 0; i < s.length(); i++)
  {
    if (s[i] != t[i])
    {
      flag = false;
      break;
    }
  }
  if (flag == true)
  {
    std::cout << "Yes" << std::endl;
  }
  else
  {
    std::cout << "No" << std::endl;
  }

  return 0;
}

Measured memory_bytes: 3596