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

int main() {
    int x; cin >> x;
    int c = x / 100;
    int a = x % 100;

    int cnt = 0;
    auto calc = [](int &cnt, int &a, int d){
        cnt += a / d;
        a    = a % d;
    };
    calc(cnt, a, 5);    
    calc(cnt, a, 4);    
    calc(cnt, a, 3);    
    calc(cnt, a, 2);    
    calc(cnt, a, 1);
    if(cnt <= c) cout << 1 << endl;
    else cout << 0 << endl;
}

Measured memory_bytes: 384
import math

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


a, b = map(int, input().split())
g = gcd(a, b)


s = int(math.sqrt(g))

f = {}
for i in range(2, s+1):  
    while g % i == 0:  
        f[i] = f.get(i, 0) + 1  
        g = g/i  
if g != 1:
    f[g] = f.get(g, 0) + 1

print(len(f)+1)

Measured memory_bytes: 3064
N=int(input())
S=[]
for _ in range(N):
    S.append(list(input()))
# print(S)

count = {
    'M': 0,
    'A': 0,
    'R': 0,
    'C': 0,
    'H': 0
}

for s in S:
    if s[0] in ['M','A','R','C','H']:
        count[s[0]] += 1

# print(count)

H=['M','A','R','C','H']
res = 0
for i in range(0,5):
    for j in range(i+1,5):
        for k in range(j+1,5):
            cnt = count[H[i]] * count[H[j]] * count[H[k]]
            # print(i,j,k,cnt)
            res += cnt

print(res)

Measured memory_bytes: 85720
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
using namespace std;

typedef long long ll;
#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1;} return 0;}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////


int main() {
    int x, n;
    cin >> x >> n;
    if (n == 0) {
        cout << x << endl;
        return 0;
    }
    map<int, bool> a;
    rep(i,n) {
        int p;
        cin >> p;
        a[p] = true;
    }
    int ans = 105;
    for (int i = 101; i >= -1; i--) {
        if (!a[i] && abs(ans-x) >= abs(i-x)) {
            ans = i;
        }
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

#define PI 3.14159265358979323846264338327950L

int main(void){

    int N,ans;
    cin>>N;

    if(N%1000 == 0){
        ans=0;
    }else{
        ans=N;
        while(ans>=0){
            ans=ans-1000;
        }
        ans=ans*(-1);
    }

    cout<< ans <<endl;

    return 0;
}



Measured memory_bytes: 3632
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
#define int long long
#define ll long long
//#define int  unsigned long long
#define pb push_back
//#define double long double

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int mod = 998244353;
const int N = 300000;
int d, used[N], ans, sz[N], p[N], deg[N];
set < int > g[N];
vector < pair < pair < int, int >, int > > a;
int gt(int x){
    if (x == p[x]) return x;
    return p[x] = gt(p[x]);
}
void unite(int x, int y){
    x = gt(x);
    y = gt(y);
    if (x == y) return;
    if (sz[x] < sz[y]) swap(x, y);
    p[y] = x;
    sz[x] += sz[y];
}
void build(int l, int r){
    if (r - l + 1 <= 1) return;
    int mid = (r + l) / 2;
    build(l, mid);
    build(mid + 1, r);
    int x = a[mid].F.F;
    for (int j = 0; j < 2; j++){
        int c = 1;
        if (j == 1) c = -1;
        vector < pair < pair < int, int >, pair < int, int > > > b;
        for (int i = l; i <= mid; i++){
            if (abs(a[i].F.F - x) > d) continue;
            b.pb({{a[i].F.S, 1},{a[i].S, abs(x - a[i].F.F) - c * a[i].F.S}});
        }
        for (int i = mid + 1; i <= r; i++){
            if (abs(a[i].F.F - x) > d) continue;
            b.pb({{a[i].F.S, 2},{a[i].S, abs(x - a[i].F.F) + c * a[i].F.S}});
        }
        sort(b.begin(), b.end());
        set < pair < int, int > > s;
        map < int, int > m;
        vector < pair < int, pair < int, int > > > v;
        int z = 0;
        for (auto i: b){
            if ((i.F.S == 2 && j == 0) || (i.F.S == 1 && j == 1)){
                while(z < v.size() && v[z].F + j <= i.F.F){
                    if (s.find({v[z].S.F,v[z].S.S}) == s.end())
                    s.insert({v[z].S.F, v[z].S.S});
                    m[v[z].S.F]++;
                    z++;
                }
                auto it = s.lower_bound({d - i.S.S, -1});
                auto x = *it;
                deg[i.S.F] += m[d - i.S.S];
                while (it != s.end() && x.F + i.S.S == d){
                    unite(x.S, i.S.F);
                    it++;
                    if (it != s.end()) x = *it;
                }
            } else{
                v.pb({i.F.F,{i.S.S, gt(i.S.F)}});
            }
        }
    }
}
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    int n, p1, p2;
    cin >> n >> p1 >> p2;
    for (int i = 1; i <= n; i++){
        int x, y;
        cin >> x >> y;
        a.pb({{x, y}, i});
    }
    d = abs(a[p1 - 1].F.F - a[p2 - 1].F.F) + abs(a[p1 - 1].F.S - a[p2 - 1].F.S);
    for (int i = 1; i <= n; i++){
        p[i] = i;
        sz[i] = 1;
    }
    sort(a.begin(), a.end());
    build(0, n - 1);
    int x = gt(p1);
    for (int i = 1; i <= n; i++){
        if (gt(i) == x) ans += deg[i];
    }
    cout << ans;
}


Measured memory_bytes: 37560
import java.sql.ResultSet;
import java.util.Scanner;
import java.util.stream.Stream;

class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        String n = sc.next();
        sc.close();

        int sum = Stream.of(n.split("", 0)).mapToInt(e -> Integer.parseInt(e)).sum();
        String result = "No";
        if(sum % 9 == 0){
            result = "Yes";
        }
        System.out.println(result);
    }
}

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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int k, n, a[200000];
    cin >> k >> n;
    for (int i = 0; i < n; ++i) cin >> a[i];
    int m = 0;
    for (int i = 0; i < n - 1; ++i) {
        m = max(m, a[i + 1] - a[i]);
    }
    m = max(m, k - a[n - 1] + a[0]);
    cout << k - m << '\n';
    return 0;
}


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

#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,n) for(int i = 1; i < n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
using vb = vector<bool>;
using vc = vector<char>;
using vcc = vector<vc>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }



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

  string s, t;
  cin >> s >> t;
  sort(all(s));
  sort(rall(t));
  YesorNo(s < t);
}

Measured memory_bytes: 256
N,T = map(int, input().split())
data = [list(map(int, input().split())) for i in range(N)]
dp1 = [[0]*(N+1) for _ in range(T+1)]
dp2 = [[0]*(N+1) for _ in range(T+1)]

for t in range(T):
    for n in range(N):
        if t+1-data[n][0]>=0:
            dp1[t+1][n+1] = max(dp1[t+1][n],dp1[t+1-data[n][0]][n]+data[n][1])
            dp2[t+1][n+1] = max(dp2[t+1][n],dp2[t+1-data[n][0]][n]+data[n][1],
                                dp1[t][n]+data[n][1])
        else:
            dp1[t+1][n+1] = dp1[t+1][n]
            dp2[t+1][n+1] = max(dp2[t+1][n],dp1[t][n]+data[n][1])

print(dp2[T][N])


Measured memory_bytes: 178692
def main():
    N = int(input())
    money = 0
    for i in range(N):
        x, u = map(str, input().split())
        x = float(x)
        if u == 'JPY':
            money += x
        elif u == 'BTC':
            money += x * 380000

    print(money)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
use superslice::Ext;
fn main() {
    proconio::input! {
        n: usize,
        m: usize,
        k: usize,
        mut a: [usize;n],
        mut b: [usize;m],
    }
    a.reverse();
    a.push(0);
    a.reverse();
    for i in 1..=n {
        a[i]+=a[i-1];
    }
    for i in 1..m {
        b[i]+=b[i-1];
    }
    let mut t=0;
    for (i,a) in a.into_iter().enumerate() {
        if a>k {
            break;
        }
        let j=b.upper_bound(&(k-a));
        t=std::cmp::max(t,i+j);
    }
    println!("{}",t);
}

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

  int main() {
    string a;
    int b,c,d,count = 0;
    cin >> a;
    
    b = atoi(a.substr(0, 1).c_str());
    c = atoi(a.substr(1, 1).c_str());
    d = atoi(a.substr(2, 1).c_str());

    if (b == 1) {
      count += 1;
    }
    if (c == 1) {
      count += 1;
    }
    if (d == 1) {
      count += 1;
    }
    
    cout << count << endl;
  }

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Scanner;

public class Main 
{

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

		while(true)
		{
			String in = scan.next();
			int d = scan.nextInt();
			
			if(in.equals("0") && d == 0)break;
			
			LinkedList<Integer> l = new LinkedList<Integer>();
			
			for(int i = 0; i < d; i++)
			{
				if(i < in.length())
				{
					l.add(Integer.parseInt(in.substring(i, i+1)));
				}
				else
				{
					l.add(0);
				}
			}
			
			l.sort(null);
//			System.out.println(l);
			
			int curnum;
			int iter = 0;
			int a1 = -1;
			ArrayList<Integer> log = new ArrayList<Integer>();
			
			while(true)
			{
				iter += 1;
				String bigs = "";
				String smalls = "";
				
				for(int i = 0; i < l.size(); i++)
				{
					smalls += l.get(i);
					bigs += l.get(l.size()-1-i);
				}
				
				int big = Integer.parseInt(bigs);
				int small = Integer.parseInt(smalls);
				
				curnum = big - small;
//				if(iter<= 5)
//				System.out.println(iter + " CURNUM " + curnum);
				
				if(log.contains(curnum) || curnum == Integer.parseInt(in))
				{
					int index1;
					if(curnum == Integer.parseInt(in))
					{
						index1 = 0;
					}
					else
					{
						index1 = log.indexOf(curnum);
						index1 += 1;
					}
					System.out.println((index1) + " " + curnum + " " + (iter-index1));
					break;
				}
				else
				{
					log.add(curnum);
				}
				/*
				if(iter == 1)
				{
					a1 = curnum;
				}
				else
				{
					if(curnum == a1)
					{
						System.out.println(iter + " " + curnum);
						break;
					}
				}
				*/
				
				//
				l = new LinkedList<Integer>();
				
				for(int i = 0; i < d; i++)
				{
					if(i < Integer.toString(curnum).length())
					{
						l.add(Integer.parseInt(Integer.toString(curnum).substring(i, i+1)));
					}
					else
					{
						l.add(0);
					}
				}				
				l.sort(null);
				//
			}
		}
	}

}



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

using namespace std;

int main(){
        int n, a;
        cin >> n;
        map<int, int> mp;
        for(int i = 1; i <= n; i++){
                mp[i] = 0;
        }
        while(cin >> a){
                mp[a]++;
        }
        for(auto it: mp){
                cout << it.second << '\n';
        }
}

Measured memory_bytes: 13004
#ifndef CLASS_MODINT
#define CLASS_MODINT

#include <cstdint>

template <std::uint32_t mod>
class modint {
private:
	std::uint32_t n;
public:
	modint() : n(0) {};
	modint(std::int64_t n_) : n((n_ >= 0 ? n_ : mod - (-n_) % mod) % mod) {};
	static constexpr std::uint32_t get_mod() { return mod; }
	std::uint32_t get() const { return n; }
	bool operator==(const modint& m) const { return n == m.n; }
	bool operator!=(const modint& m) const { return n != m.n; }
	modint& operator+=(const modint& m) { n += m.n; n = (n < mod ? n : n - mod); return *this; }
	modint& operator-=(const modint& m) { n += mod - m.n; n = (n < mod ? n : n - mod); return *this; }
	modint& operator*=(const modint& m) { n = std::uint64_t(n) * m.n % mod; return *this; }
	modint operator+(const modint& m) const { return modint(*this) += m; }
	modint operator-(const modint& m) const { return modint(*this) -= m; }
	modint operator*(const modint& m) const { return modint(*this) *= m; }
	modint inv() const { return (*this).pow(mod - 2); }
	modint pow(std::uint64_t b) const {
		modint ans = 1, m = modint(*this);
		while (b) {
			if (b & 1) ans *= m;
			m *= m;
			b >>= 1;
		}
		return ans;
	}
};

#endif // CLASS_MODINT

#include <vector>
#include <iostream>
#include <functional>
using namespace std;
using mint = modint<998244353>;
const int limit = 3000000;
int main() {
	vector<mint> fact(limit + 1), inv(limit + 1), factinv(limit + 1);
	fact[0] = 1; inv[1] = 1; factinv[0] = 1;
	for (int i = 1; i <= limit; ++i) fact[i] = fact[i - 1] * i;
	for (int i = 2; i <= limit; ++i) inv[i] = inv[mint::get_mod() % i] * mint(-int(mint::get_mod() / i));
	for (int i = 1; i <= limit; ++i) factinv[i] = factinv[i - 1] * inv[i];
	function<mint(int, int)> comb = [&](int x, int y) {
		if (y < 0 || x < y) return mint(0);
		return fact[x] * factinv[y] * factinv[x - y];
	};
	int N, M;
	cin >> N >> M;
	mint ans = 0;
	for (int i = M % 2; i <= M && i <= N; i += 2) {
		int rem = M + (M - i) / 2;
		mint sub1 = comb(N + rem - 1, rem);
		mint sub2 = comb(N + rem - M - 1, rem - M) * i;
		mint sub3 = comb(N + rem - M - 2, rem - M - 1) * (N - i);
		ans += (sub1 - sub2 - sub3) * comb(N, i);
	}
	cout << ans.get() << endl;
	return 0;
}

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

#define lp_i(k,n)  for(int i = (k); i < (n); i++)
#define lp_j(k,n)  for(int j = (k); j < (n); j++)
#define lp_ui(k,n) for(uint32_t i = (k); i < (n); i++)
#define lp_uj(k,n) for(uint32_t j = (k); j < (n); j++)

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

using namespace std;

constexpr auto MOD = 2019;

ul calculation(ul L, ul R);

int main(void)
{
	ul L, R;
	cin >> L >> R;
	
	auto ans = calculation(L, R);

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

ul calculation(ul L, ul R)
{
	if ((R - L) >= MOD - 1)
		return 0;
	if (L % MOD == 0
		|| R % MOD == 0)
		return 0;

	ul ans = MOD;
	for (auto i = L; i < R; i++)
	{
		for (auto j = L + 1; j <= R; j++)
		{
			ans = min(ans, (i * j) % MOD);
			if (ans == 0)
				break;
		}
	}

	return ans;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=5005;
int n,k,p[N],c[N],cir[N];
int cal(int st)
{
	int now=p[st],j=0;
	while(now!=st)
	{
		cir[++j]=c[now];
		now=p[now];
	}
	cir[++j]=c[now];
	for(int i=1;i<=j;i++) 
		cir[i]+=cir[i-1];
	if(k<=j)
	{
		int ans=cir[1];
		for(int i=1;i<=k;i++) 
			ans=max(ans,cir[i]);
		return ans;
	}
	else
	{
		int ans=cir[1];
		for(int i=1;i<=j;i++) 
			ans=max(ans,cir[i]);
		int macir=ans,qu=k%j,maqu=0;
		for(int i=1;i<=qu;i++) 
			maqu=max(maqu,cir[i]);
		ans=max(ans,k/j*cir[j]+maqu);
		if(k/j>0)
			ans=max(ans,(k/j-1)*cir[j]+macir);
		return ans;
	}
}
signed main()
{
	scanf("%lld%lld",&n,&k);
	for(int i=1;i<=n;i++) 
		scanf("%lld",&p[i]);
	for(int i=1;i<=n;i++) 
		scanf("%lld",&c[i]);
	int ans=-1e17;
	for(int i=1;i<=n;i++)
		ans=max(cal(i),ans);
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 3904
#include<bits/stdc++.h>
#define LIM 1+2+4+8+16+32+64+128
using namespace std;
typedef long long int ll;
int main(){
  ll n;
  cin>>n;
  ll a[n];
  ll ans=0;
  for(int i=0;i<n;i++){
    cin>>a[i];
    if(i%2==0){
      ans+=a[i];
    }else{
      ans-=a[i];
    }
  }
  ll ac[n];
  ac[0]=ans;
  for(int i=1;i<n;i++){
    ac[i]=(a[i-1]-ac[i-1]/2)*2;
  }
  for(int i=0;i<n-1;i++){
    cout<<ac[i]<<' ';
  }
  cout<<ac[n-1]<<endl;
  return(0);
}


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

using namespace std;

#define all(x) (x).begin(), (x).end()
typedef long double ld;
typedef long long ll;

const int mod = 1e9 + 7;

int add(int x) {  
  return x;
}

template<typename... T>
int add(int x, T... y) {  
  x += add(y...);
  if (x >= mod)
        x -= mod;
  return x;
}

template<typename... T>
int udd(int &x, T... y) { 
  return x = add(x, y...);
}

template<typename... T>
int sub(int x, T... y) { 
  return add(x, mod - add(y...));
}

int mul(int x) { 
  return x;
}

template<typename... T>
int mul(int x, T... y) { 
  return 1ll * x * mul(y...) % mod;
}

int bin(int x, int to) { 
  int y = 1;
  while (to) { 
        if (to & 1)
                  y = mul(x, y);
            x = mul(x, x);
                to >>= 1;
  }
  return y;
}

int inv(int x) { 
  assert(x != 0);
  return bin(x, mod - 2);
}
 


int main() {
#ifdef LOCAL
  assert(freopen("a.in", "r", stdin));
#endif

  ios_base::sync_with_stdio(false);

  int n;
  string s;
  cin >> n;
  cin >> s;
  map<char, int> cnt;

  for (char c : s)
    cnt[c]++;

  int ans = 1;
  for (auto e : cnt)
    ans = mul(ans, e.second + 1);

  ans = sub(ans, 1);
  cout << ans << "\n";
}



Measured memory_bytes: 512
"""
    こんにちは。これはクシャルです
    
    Author : thekushalghosh (クシャル)
    Team   : CodeDiggers
 
    I prefer Python language over the C++ language :p :D
        
    Visit my website : thekushalghosh.github.io
"""
import sys,math,cmath,time
start_time = time.time()
##########################################################################
################# ---- THE ACTUAL CODE STARTS BELOW ---- #################
    

    
def solve():
    n = inp()
    a = inlt()
    q = 0
    w = 0
    for i in range(len(a)):
        if a[i] < q:
            w = w + q - a[i]
        else:
            q = a[i]
    print(w)
    
################## ---- THE ACTUAL CODE ENDS ABOVE ---- ##################
##########################################################################
 
def main():
    global tt
    if not ONLINE_JUDGE:
        sys.stdin = open("input.txt","r")
        sys.stdout = open("output.txt","w")
    t = 1
    for tt in range(t):
        solve()
    if not ONLINE_JUDGE:
        print("Time Elapsed :",time.time() - start_time,"seconds")
        sys.stdout.close()
    
#---------------------- USER DEFINED INPUT FUNCTIONS ----------------------#
def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    return(input().strip())
def invr():
    return(map(int,input().split()))
 
#------------------ USER DEFINED PROGRAMMING FUNCTIONS ------------------#
def counter(a):
    q = [0] * max(a)
    for i in range(len(a)):
        q[a[i] - 1] = q[a[i] - 1] + 1
    return(q)

def counter_elements(a):
    q = dict()
    for i in range(len(a)):
        if a[i] not in q:
            q[a[i]] = 0
        q[a[i]] = q[a[i]] + 1
    return(q)

def string_counter(a):
    q = [0] * 26
    for i in range(len(a)):
        q[ord(a[i]) - 97] = q[ord(a[i]) - 97],1
    return(q)
 
def factors(n):
    q = []
    for i in range(1,int(n ** 0.5) + 1):
        if n % i == 0: q.append(i); q.append(n // i)
    return(list(sorted(list(set(q)))))
 
def prime_factors(n):
    q = []
    while n % 2 == 0: q.append(2); n = n // 2
    for i in range(3,int(n ** 0.5) + 1,2):
        while n % i == 0: q.append(i); n = n // i
    if n > 2: q.append(n)
    return(list(sorted(q)))

def transpose(a):
    n,m = len(a),len(a[0])
    b = [[0] * n for i in range(m)]
    for i in range(m): 
        for j in range(n): 
            b[i][j] = a[j][i]
    return(b)

#-----------------------------------------------------------------------#
ONLINE_JUDGE = __debug__
if ONLINE_JUDGE:
    input = sys.stdin.readline
main()

Measured memory_bytes: 91404
#include<iostream>
#include<cmath>
#include<string>
#include<map>
#include<queue>

using namespace std;

#define N 4
#define N2 16
#define LIMIT 100

static const int dx[4] = {0, -1, 0, 1};
static const int dy[4] = {1, 0, -1, 0};
static const char dir[4] = {'r', 'u', 'l', 'd'};
int MDT[N2][N2];

struct Puzzle {
  int f[N2];
  int space;
  int MD;
};

Puzzle state;
int limit;
int path[LIMIT];

int getAllMD(Puzzle pz) {
  int sum = 0;
  for (int i = 0; i < N2; i++) {
    if (pz.f[i] == N2) {
      continue;
    }
    sum += MDT[i][pz.f[i] - 1];
  }
  return sum;
}

bool isSolved() {
  for (int i = 0; i < N2; i++) {
    if (state.f[i] != i + 1) {
      return false;
    }
  }
  return true;
}

bool dfs(int depth, int prev) {
  if (state.MD == 0) {
    return true;
  }
  if (depth + state.MD > limit) {
    return false;
  }

  int sx = state.space / N;
  int sy = state.space % N;
  Puzzle tmp;

  for (int r = 0; r < 4; r++) {
    int tx = sx + dx[r];
    int ty = sy + dy[r];
    if (tx < 0 || ty < 0 || tx >= N || ty >= N) {
      continue;
    }
    if (max(prev, r) - min(prev, r) == 2) {
      continue;
    }
    tmp = state;
    state.MD -= MDT[tx * N + ty][state.f[tx * N + ty] - 1];
    state.MD += MDT[sx * N + sy][state.f[tx * N + ty] - 1];
    swap(state.f[tx * N + ty], state.f[sx * N + sy]);
    state.space = tx * N + ty;
    if (dfs(depth + 1, r)) {
      path[depth] = r;
      return true;
    }
    state = tmp;
  }
  return false;
}

string iterative_deepening(Puzzle in) {
  in.MD = getAllMD(in);

  for (limit = in.MD; limit <= LIMIT; limit++) {
    state = in;
    if (dfs(0, -100)) {
      string ans = "";
      for (int i = 0; i < limit; i++) {
        ans += dir[path[i]];
      }
      return ans;
    }
  }
  return "unsolvable";
}

int main(){
  for (int i = 0; i < N2; i++) {
    for (int j = 0; j < N2; j++) {
      MDT[i][j] = abs(i / N - j / N) + abs(i % N - j % N);
    }
  }

  Puzzle in;

  for (int i = 0; i < N2; i++) {
    cin >> in.f[i];
    if (in.f[i] == 0) {
      in.f[i] = N2;
      in.space = i;
    }
  }
  string ans = iterative_deepening(in);
  cout << ans.size() << endl;

  return 0;
}



Measured memory_bytes: 3228
#include <cstdio>
using namespace std;
int main(){
	register int n, m;
	scanf("%d %d", &n, &m);
	if (n == 1 && m == 1) puts("1");
	else if (n == 1) printf("%d", m - 2);
	else if (m == 1) printf("%d", n - 2);
	else printf("%lld", 1ll * (n - 2) * (m - 2));
	return 0;
}

Measured memory_bytes: 128
import math
r = int(input())
ints = [int(input()) for _ in range(r)]

ans = 0

for i in ints:
    if i == 2:
        ans += 1
        continue

    if i < 2 or i % 2 == 0:
        continue
    
    j = 3
    flag = True
    while j <= math.sqrt(i):
        if i % j == 0:
            flag = False
            break
        j += 1
    if flag: ans += 1

print(ans)
    


Measured memory_bytes: 6012
#include <bits/stdc++.h>
    using namespace std;
     
    int main() {
      int a, b;
      cin >> a >> b ;
      
      if((a*b) % 2 == 0){
        cout << "Even" << endl;
      }
      if((a*b) % 2 ==1){
        cout << "Odd" << endl;
      }
    }
        

Measured memory_bytes: 256
// AtCoder Regular Contest 070
// D - No Need

#include <cstdio>
#include <cstring>
#include <algorithm>
#define MAX_N 5000
#define MAX_K 5000
using namespace std;
typedef long long int ll;


int N, K;
ll A[MAX_N + 2];
bool dp[2][MAX_N + 2][MAX_K + 1];
int ans;

int main() {

  scanf("%d%d", &N, &K);
  for (int i = 1; i <= N; i++) {
    scanf("%lld", &A[i]);
  }
  memset(dp, 0, sizeof(dp));

  for (int z = 0; z < 2; z++) {
    dp[z][(z ? N + 1 : 0)][0] = true;
    for (int i = (z ? N : 1); (z ? (i >= 1) : (i <= N)); i += -2 * z + 1) {
      for (int j = 0; j <= K; j++) {
        dp[z][i][j] = dp[z][i + 2 * z - 1][j];
        if (j - A[i] >= 0) {
          dp[z][i][j] = dp[z][i][j] || dp[z][i + 2 * z - 1][j - A[i]];
        }
      }
    }
  }

  ans = 0;
  for (int i = 1; i <= N; i++) {
    int j0, j1, tmp_k;
    j1 = K;
    tmp_k = 0;
    for (j0 = 0; j0 <= K; j0++) {
      if (!dp[0][i - 1][j0]) {
        continue;
      }
      for (; j1 >= 0; j1--) {
        if (!dp[1][i + 1][j1]) {
          continue;
        }
        if (j0 + j1 < K) {
          tmp_k = max(tmp_k, j0 + j1);
          break;
        }
      }
    }
    if (tmp_k < K - A[i]) {
      ans++;
    }
  }

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

  return 0;

}




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

#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;

const uint64_t M = 109;
const uint64_t iM = UINT64_C(12015769075535579493);

int main() {
  int n,m;
  cin>>n>>m;
  vector<uint64_t> pm(n+1,1);
  REP(i,n) pm[i+1] = pm[i] * M;
  set<uint64_t> st;
  string s;
  cin>>s;
  int l=0, r=0;
  uint64_t h = s[0];
  REP(i,m) {
    string cmd;
    cin>>cmd;
    if (cmd[0] == 'L') {
      if (cmd[1] == '+') {
        h -= s[l];
        h *= iM;
        ++l;
      } else {
        --l;
        h *= M;
        h += s[l];
      }
    } else {
      if (cmd[1] == '+') {
        ++r;
        h += s[r] * pm[r - l];
      } else {
        h -= s[r] * pm[r - l];
        --r;
      }
    }
    st.insert(h);
  }
  cout << st.size() << endl;
  return 0;
}

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

using namespace std;

int main(void)
{
    int N;
    vector<int> v;

    cin >> N;
    int vi;
    for(int i;i<N;i++){
        cin >> vi;
        v.push_back(vi);
    }

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

    double result = v.at(0);

    for(int i=1;i<N;i++){
        result += v.at(i);
        result /= 2;
    }

    cout << result <<endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define req(i,n) for(int i = 1;i <=n;i++)
#define pai 3.14159265358979323846
const int INF = 1001001001;
typedef long long ll;
int A[3][3], N;
bool punched[3][3];
bool ok[3][3];
using Graph = vector<vector<int>>;
vector<vector<int>> field;
vector<bool> seen;

const int MOD = 1000000007;
typedef pair<int,int> P;

//最大公約数
int gcd(int a,int b){
	if (a%b == 0){
		return b;
	}
	else{
		return gcd(b,a%b);
	}

}

//最小公倍数
int lcm(int a,int b){
	return a /gcd(a,b) * b;
}

//素数判定
bool is_prime(long long N) {
    if (N == 1) return false;
    for (long long i = 2; i * i <= N; ++i) {
        if (N % i == 0) return false;
    }
    return true;
}

// 素因数分解
vector<pair<long long, long long> > prime_factorize(long long n) {
    vector<pair<long long, long long> > res;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) { ++num; n /= p; }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

// 10進数から2進数
int binary(int bina){
    int ans = 0;
    for (int i = 0; bina>0 ; i++)
    {
        ans = ans+(bina%2)*pow(10,i);
        bina = bina/2;
    }
    return ans;
}




int main() {
  string s,t; cin >> s >> t;
    vector<string> ans;
    int l = s.size()-t.size()+1;
    for(int i = 0; i < max(0, l); i ++) {
        string tmp = s;
        for(int j = 0; j < t.length(); j ++) {
            if(i+j>s.size()-1) break;
            if(tmp[i+j]=='?' || tmp[i+j]==t[j]) tmp[i+j] = t[j];
            else break;
            if(j==t.length()-1) {
                for(int k = 0; k < tmp.length(); k ++) {
                    if(tmp[k]=='?') tmp[k] = 'a';
                }
                ans.push_back(tmp);
            }
        }
    }
    //cout << ans[1] << endl;
    sort(ans.begin(), ans.end());
    cout << (ans.size() > 0 ? ans[0] : "UNRESTORABLE") << endl;
    //cout << t.size() << " " << t.length() << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cmath>

using namespace std;

#define ll long long
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
int main() {
	string S;
	cin >> S;
	string ans = "Yes";

	if (S == "AAA" || S == "BBB") {
		ans = "No";
	}
	cout << ans << endl;
}

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

using namespace std;
using ll = long long;
using P = pair<ll, ll>;

int main() {
	int N;
	cin >> N;
	vector<ll> a(N);
	for (int i = 0; i < N; ++i) { cin >> a[i]; }
	sort(a.begin(), a.end());

	vector<P> op;
	ll res = 0;
	if (a[0] <= 0 && a[N-1] >= 0) {
		for (int i = 1; i < N - 1; ++i) {
			if (a[i] <= 0) {
				op.push_back(P(a[N-1], a[i]));
				a[N-1] -= a[i];
			} else {
				op.push_back(P(a[0], a[i]));
				a[0] -= a[i];
			}
		}
		op.push_back(P(a[N-1], a[0]));
		a[N-1] -= a[0];
		res = a[N-1];
	} else if (a[0] >= 0) {
		for (int i = 1; i < N - 1; ++i) {
			op.push_back(P(a[0], a[i]));
			a[0] -= a[i];
		}
		op.push_back(P(a[N-1], a[0]));
		a[N-1] -= a[0];
		res = a[N-1];
	} else {
		for (int i = N - 2; i >= 0; --i) {
			op.push_back(P(a[N-1], a[i]));
			a[N-1] -= a[i];
		}
		res = a[N-1];
	}

	cout << res << endl;
	for (int i = 0; i < N - 1; ++i) {
		cout << op[i].first << " " << op[i].second << endl;
	}

	return 0;
}


Measured memory_bytes: 4336
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define INF 0x3f3f3f3f
#define maxn 200009
inline ll read()
{
	ll x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ll)(ch-'0');ch=getchar();}
	return x*f;
}
ll n,m,k,ans,tot,l;
ll d[maxn],sum[maxn],x[maxn];
int main()
{
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	n=read();
	for(int i=1;i<=n;i++)
		d[i]=read(),x[i]=x[i-1]^d[i],sum[i]=sum[i-1]+d[i];
	l=1,ans=0;	
	for(ll r=1;r<=n;r++)
	{
		while(sum[r]-sum[l-1]!=(x[r]^x[l-1]))
			l++;
		ans+=(r-l+1);
	//	cout<<l<<" "<<r<<" "<<ans<<endl;
	}
	printf("%lld\n",ans);
//	fclose(stdin);
//	fclose(stdout);
	return 0;
}


Measured memory_bytes: 4992
package main

import (
	"fmt"
	"sort"
)

// ロボットが動く範囲の構造体
// t: max, s: min
type p struct {
	t, s int
}

type Ps []p

func (p Ps) Len() int {
	return len(p)
}

func (p Ps) Less(i, j int) bool {
	return p[i].t < p[j].t
}

func (p Ps) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func solution(n int, matrix [][]int) int {
	ps := make(Ps, n)

	for i := 0; i < n; i++ {
		t := matrix[i][0] + matrix[i][1]
		s := matrix[i][0] - matrix[i][1]
		ps[i] = p{s: s, t: t}
	}

	// ロボットを $$T_i$$ が小さい順にソート
	sort.Sort(ps)

	// ロボット$$p_i$$の腕が既に残すと決めたロボットの腕と重ならないならば、ロボット $$p_i$$ を残すと決める。そうでないなら残さないと決める。
	var ans int
	var cur int = -1 << 31
	for i := 0; i < n; i++ {
		if cur <= ps[i].s {
			ans++
			cur = ps[i].t
		}
	}
	return ans
}

func main() {
	var n, x, l int
	fmt.Scan(&n)
	matrix := make([][]int, n)
	for i := range matrix {
		matrix[i] = make([]int, 2)
	}
	for i := 0; i < n; i++ {
		fmt.Scan(&x, &l)
		matrix[i][0] = x
		matrix[i][1] = l
	}
	fmt.Println(solution(n, matrix))
}


Measured memory_bytes: 10624
n = int(input())
a = list(map(int, input().split()))
num_hash = {}

is_ok = True
for i in range(len(a)):
    num = a[i]
    if num in num_hash:
        print('NO')
        is_ok = False
        break
    num_hash[num] = True
if is_ok:
    print('YES')


Measured memory_bytes: 32844
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#include <functional>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;
using lint = int64_t;

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];
    vector<pair<int, int>> S(N);
    rep(i, N) S[i] = pair<int, int>{A[i], i};
    sort(S.begin(), S.end());
    int cnt = 0;
    rep(i, N) {
        if (abs(S[i].second - i) & 1) ++cnt;
    }
    cout << cnt / 2 << "\n";
    return 0;
}


Measured memory_bytes: 1408
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    
   int x, a = 0;
   
   for(;;){
       cin >> x;
       a += 1;
       if(x == 0) break;
       cout << "Case " << a << ": " << x << endl;
   }
    
    
}


Measured memory_bytes: 3080
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return;std::cout << e << std::endl;}
template<class T> void DEBUG(string str, T e){if(DEBUG_OUT == false)return;std::cout <<str << ">>" << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == 1)return;for(const auto& v : vv){ DEBUG(v); } }
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
template<typename T> void SORT_(vector<int>& v,bool GREATER = 0){if(GREATER == 0)sort(v.begin(),v.end());else{sort(v.begin(),v.end(),std::greater<T>());}}


void solve(void)
{  
  string str;
  cin>>str;

  int ANS = INF;
  string str_zero(str.size(),'0');
  string str_one(str.size(),'1');

  if(str == str_zero) ANS = (int)str.size();
  if(str == str_one ) ANS = (int)str.size();

  for (int i = 0; i < str.size()-1; i++)
  {
    if(str[i] != str[i+1]) chmin(ANS,max(i+1,(int)str.size()-i-1));
  }
  cout<<ANS<<endl;
  
  return;
}


int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

 
  return 0;
}

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

int main(void){
	string s;
	int K;
	cin>>s;
	cin>>K;
	for(int i=0; i<s.size(); ++i)
	{
		if(s[i]=='a'){
			continue;
		}
		int m='z'-s[i]+1;//何回足せばaになるか
		if( K < m){
			continue;
		}
		s[i]='a';
		K-=m;
	}
	//最後の文字はここで
	s[s.size()-1]+=(K%26);
	if(s[s.size()-1]>'z'){
		s[s.size()-1]-=26;
	}
	
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 512
from collections import deque

INF=float('inf')

n=int(input())
g=[[] for _ in range(n)]
for _ in range(n-1):
    u,v,w=map(int,input().split())
    g[u-1].append((v-1,w))
    g[v-1].append((u-1,w))

q,k=map(int,input().split())
ds=[INF]*n
que=deque([(k-1,0)])
while len(que):
    u,d=que.popleft()
    if ds[u]!=INF:
        continue
    ds[u]=d
    for v,w in g[u]:
        que.append((v,d+w))

for _ in range(q):
    u,v=map(int,input().split())
    print(ds[u-1]+ds[v-1])


Measured memory_bytes: 90036
N, M, K = map(int, input().split())
friend = [[] for _ in range(N+1)]
block = [[] for _ in range(N+1)]

for i in range(M):
  A,B = map(int, input().split())
  friend[A].append(B)
  friend[B].append(A)

for i in range(K):
  C,D = map(int, input().split())
  block[C].append(D)
  block[D].append(C)
#print(friend)
#print(block)

#import queue
grouping = [False]*(N+1)
#print(grouping)
grouping[0] = True
group = [0]*(N+1)
g_num = 0
g_cnt = []
for i in range(1,N+1):
  cnt = 0
  if grouping[i] == True:
    continue 
  group[i] = g_num
  grouping[i] = True
  #q = queue.Queue()
  #q.put(i)
  stack = [i]
  #while not q.empty():
  while len(stack)>0:
    #print('v:',visited)
    #p = q.get()
    p = stack.pop()
    for f in friend[p]:
      #print(p,f)
      if grouping[f]==False:
        #q.put(f)
        stack.append(f)
        group[f]=g_num
        grouping[f] =True
        cnt += 1
  g_num += 1
  g_cnt.append(cnt)
  #print('g:',grouping)
ans = []
for i in range(1,N+1):
  c = g_cnt[group[i]]-len(friend[i])
  for b in block[i]:
    if group[b]==group[i]:
      c -= 1
  ans.append(c)
print(*ans)

Measured memory_bytes: 47632
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(void) {
	int N, M;
	vector<int> s;
	cin >> N;
	for (int i=0; i < N; i++) {
		int h, m;
		cin >> h >> m;
		s.push_back(h*60+m);
	}
	cin >> M;
	for (int i=0; i < M; i++) {
		int h, m;
		cin >> h >> m;
		s.push_back(h*60+m);
	}

	sort(s.begin(), s.end());
	
	for (int i = 0; i < N+M; i++) {
		if (i != 0 && s[i-1] == s[i]) {
			continue;
		}
		if (s[i]%60 < 10) {
			printf("%d:0%d", s[i]/60, s[i]%60);
		}
		else {
			printf("%d:%d", s[i]/60, s[i]%60);
		}
		if (i == N+M-1 || s[i] == s[N+M-1]) {
			cout << endl;
		}
		else {
			cout << ' ';
		}
	}
}

Measured memory_bytes: 1244
import java.util.*;
// warm-up
public class Main {

	static void solve() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(), K = sc.nextInt(), t = 1;
		while (N-->0) t = Math.min(2*t, t+K);
		System.out.println(t);
		sc.close();		
	}

	public static void main(String args[]) {
		solve();
	}

}

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

//for loop
#define rep(i,a,n) for(int i=(a);i<(n);++i)
#define repe(i,a,n) for(int i=(a);i<=(n);++i)
#define rrep(i,n,a) for(int i=(n);n>(a);--i)
#define rrepe(i,n,a) for(int i=(n);n>=(a);--i)

//abbreviati
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define ENDL << "\n"

using ll = long long;
using P = pair<int,int>;
using itn = int;

//constant
const int INF = 1<<30;
const ll INFLL = 1LL << 60;
const ll MOD = 1000000007;
const long double PI =(acos(-1));

/***Snippet***************************************************
ifelse, isprime, torad, todeg, lcm, bfs,chmin,chmax
**************************************************************/

//adjacency list
vector<int> to[100005];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int k;cin >> k;
    int x=7%k;
    int cnt=1;
    set<int> s;
    while(s.count(x)==0){
        if(x==0){
            cout << cnt ENDL;
            return 0;
        }
        s.insert(x);
        x=(x*10+7)%k;
        cnt++;
    }

    cout << -1 ENDL;
    return 0;
}

Measured memory_bytes: 52880
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    string S;
    ll N;
    cin >>S;
    N = S.size();
    ll cnt0 = 0;
    ll cnt1 = 0;
    rep(i,N){
        if(S[i]=='0'){
            cnt0++;
        }else{
            cnt1++;
        }
    }
    
    cout << 2*min(cnt0,cnt1) << endl;


    return 0;
    

}

Measured memory_bytes: 3744
#include <iostream>
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(n); ++i)
using namespace std;
int main(void){
    // Your code here!
    int n;
    cin >> n;
    map<string, int> cnt;
    rep(i, n){
        string s;
        cin >> s;
        cnt[s]++;
    }
    for(string s:{"AC", "WA","TLE", "RE"}){
        cout << s << " x " << cnt[s] << endl;
    }
    return 0;
}


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

#define fast ios_base::sync_with_stdio(false),cin.tie(nullptr)
int ans=0;
void call(int count)
{
        int current=0;
        for(int i=1;i<=100;i++)
        {
                current+=i;
                if(current<=count)
                        ++ans;
                else
                        break;
        }
}
int factor(ll n)
{
        int count=0;
        while(n%2==0)
        {
                count++;
                n=n>>1;
        }
        //cout<<"2 = "<<count<<endl;
        call(count);
        for(int i=3;i<=sqrt(n);i+=2)
        {
                count=0;
                while(n%i==0)
                {
                        count++;
                        n/=i;
                }
                if(count)//count should not be 0
                {
                      //cout<<i<<"="<<count<<endl;
                      call(count);
                }


        }
        if(n>2)
        {
           //cout<<n<<"="<<"1"<<endl;
           ++ans;
        }

        return ans;
}
int main()
{
        fast;
        ll n;
        cin>>n;
        cout<<factor(n)<<endl;
        return 0;
}

Measured memory_bytes: 3668
#include <set>
#include <map>
#include <queue>
#include <ctime>
#include <cmath>
#include <cstdio>
#include <vector>
#include <string>
#include <cctype>
#include <bitset>
#include <cstring>
#include <cstdlib>
#include <utility>
#include <iostream>
#include <algorithm>
#define REP(i,a,b) for(int i=(a);i<=(b);i++)
#define PER(i,a,b) for(int i=(a);i>=(b);i--)
#define RVC(i,S) for(int i=0;i<(S).size();i++)
#define RAL(i,u) for(int i=fr[u];i!=-1;i=e[i].next)
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
     
template<class T> inline
void read(T& num) {
    bool start=false,neg=false;
    char c;
    num=0;
    while((c=getchar())!=EOF) {
        if(c=='-') start=neg=true;
        else if(c>='0' && c<='9') {
            start=true;
            num=num*10+c-'0';
        } else if(start) break;
    }
    if(neg) num=-num;
}
/*============ Header Template ============*/

const int maxn=505;
char s[maxn][maxn];
char a[maxn][maxn];
char b[maxn][maxn];

int main() {
    int n,m;
    read(n);read(m);
    REP(i,1,n) {
        scanf("%s",s[i]+1);
    }
    REP(i,1,n) {
        REP(j,2,m-1) if(i&1) a[i][j]='#',b[i][j]='.'; else a[i][j]='.',b[i][j]='#'; a[i][m+1]=b[i][m+1]=0;
    }
    REP(i,1,n) a[i][1]='#',b[i][1]='.'; REP(i,1,n) b[i][m]='#',a[i][m]='.';
    REP(i,1,n) REP(j,1,m) if(s[i][j]=='#') a[i][j]=b[i][j]='#';
    REP(i,1,n) {
        printf("%s\n",a[i]+1);
    }
    putchar('\n');
    REP(i,1,n) {
        printf("%s\n",b[i]+1);
    }
    return 0;
}

Measured memory_bytes: 1536
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<map>
#include<numeric>
#include<set>
#include<string>
#include<utility>
#include<vector>

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define per(i, a, n)  for(int i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define MAX 1000000000+7
using namespace std;
typedef long long ll;

int main(){
  string s; cin >> s;
  int ans = 0;
  rep(i, 0, s.length()-1){
    if(s[i]!=s[i+1])  ans++;
  }
  cout << ans << endl;
  return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;

int main()
{
    ll N;
    cin >> N;
    ll Ai, Bi;
    vector<array<ll,2>> BA;
    for(int i=0;i<N;i++){
        cin >> Ai >> Bi;
        BA.push_back(array<ll,2>{Bi,Ai});
    }
    sort(BA.begin(), BA.end());
    ll res = 0;
    for(int i=0;i<N;i++){
        res += BA[i][1];
        if(res>BA[i][0]){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;

    return 0;
}

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

#define lint long long
#define P pair<int, int>
#define LLP pair<long long, long long>
#define REP(i, x, n) for(int i = x ; i < n ; ++i)
#define rep(i, n) for(int i = 0 ; i < n ; ++i)
#define repr(i, n) for(int i = n - 1 ; i >= 0 ; --i)
#define SORT(x) sort((x).begin(), (x).end())

const int IINF = 1e9 + 10;
const long long LLINF = (long long)1e18 + 10;
const long long MOD = (long long)1e9 + 7;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

lint solve(int k, vector<lint> v){
    int d = 0;
    vector<lint> w;
    for(int i = 42 ; i >= 0 ; --i){
        w.resize(0);
        rep(j, v.size()){
            if(v[j] >> i & 1){
                w.push_back(v[j]);
            }
        }
        if(w.size() >= k){
            d = i;
            break;
        }
    }
    if(w.size() < k){
        return 0;
    }
    lint res = 1LL << d;
    rep(i, w.size()){
        w[i] %= res;
    }
    res += solve(k, w);
    return res;
}

int main(){
    int n, k;
    cin >> n >> k;
    vector<lint> a(n);
    rep(i, n){
        cin >> a[i];
    }
    vector<lint> sum(n + 1);
    sum[0] = 0;
    REP(i, 1, n + 1){
        sum[i] = sum[i - 1] + a[i - 1];
    }
    vector<lint> v;
    rep(i, n){
        REP(j, i + 1, n + 1){
            v.push_back(sum[j] - sum[i]);
        }
    }
    lint ans = solve(k, v);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 10864
//http://arc024.contest.atcoder.jp/tasks/arc024_2

#include<iostream>
#include<map>
#include<vector>
#include<list>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<climits>
#include<ctime>
#include<cstring>

//FUNCTION
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define rep_split(tok,a_str,re) for(char *tok = strtok((char *)a_str.c_str(),re); tok != NULL; tok = strtok(NULL,re))

#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

//CONSTANT
#define INF 2000000000000
#define MAX 246912

//DEBUG
#define BAR() cout << "----------------------------" << endl;
#define DUMP(v) (cerr << #v << ": " << v << endl)
#define PRINT(list) cout << "{ "; for(auto nth : list){ cout << nth << " "; } cout << "}" << endl;

using namespace std;

int main()
{
	int n=0;
	int count=0;

	bool prime[MAX];
	prime[0] = true;
	prime[1] = true;
	for (int i=2; i<MAX; i++) prime[i] = true;
	for (int i=2; i<MAX; i++) 
	{
		if (prime[i]) {  
			for (int j=i+i; j<MAX; j+=i) prime[j] = false; 
		}
	}

	while(cin >> n && n)
	{
		count = 0;
		if(n==1){ 
			cout << 1 << endl;
		}else{
			REP(i, n+1, 2*n)
			{ 
				if(prime[i]){ count++; } 
			}
			cout << count << endl;
		}
	}

}

Measured memory_bytes: 1400