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

using ll = long long;
using ld = long double;

const int nax = 1e5+10;
const  ll mod =  1e9+7;

const ll INFL = 1e18L + 5;

//Modular Addition
inline void add_self(ll& a, ll b){
    a+=b;
    if(a>=mod)
        a-=mod;
}

//Modular Subtraction
inline void sub_self(int& a , int b){
    a -= b;
    if(a < 0)
        a+= mod;
}

inline void mul_self(ll& a, ll b){
    a *= b;
    if(a >= mod)
        a-= mod;
}


ll dp[nax][2];
int n;

vector<int>adj[nax];

void dfs(int v, int parent){
    dp[v][0] = 1ll; dp[v][1] = 1ll;
    for(auto child : adj[v]){
        if(child == parent) continue;
        dfs(child,v);
        mul_self(dp[v][0],(dp[child][0] + dp[child][1])%mod), dp[v][0]%=mod;
        mul_self(dp[v][1], dp[child][0]), dp[v][1] %= mod;
    }
}


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


    cin>>n;
    for(int i = 0; i < n-1; i++){
        int u,v;
        cin>>u>>v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }

    dfs(1,-1);

    cout<<(dp[1][0]+dp[1][1])%mod;

}

Measured memory_bytes: 14208
let s = read_line ()
let n = String.length s
let eo, ans = Array.(make 2 0, make n 0)
let g a i = a.(i) <- a.(i) + 1
let rec f i p j = if i < n then
  if p = 'R' then if s.[i] = 'R' then (g eo @@ i mod 2; f (i + 1) p j)
    else (ans.(i - 1) <- eo.(1 - i mod 2); ans.(i) <- eo.(i mod 2) + 1; f (i + 1) 'L' i)
  else if s.[i] = 'L' then (g ans @@ j - (i - j) mod 2; f (i + 1) p j) else (eo.(0) <- 0; eo.(1) <- 0; eo.(i mod 2) <- 1; f (i + 1) 'R' j)
let _ = eo.(0) <- 1; f 1 'R' 0; Array.iteri (fun i n -> Printf.printf (if i = 0 then "%d" else " %d") n) ans; print_newline ()

Measured memory_bytes: 5888
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
const int N=1e2+10;
int n,ans;char a[N],b[N],c[N];
int main(){
	scanf("%d",&n);
	scanf("%s%s%s",a+1,b+1,c+1);
	for(register int i=1;i<=n;i++){
		if(a[i]==b[i]&&b[i]==c[i])continue;
		else if(a[i]==b[i]||a[i]==c[i]||c[i]==b[i])ans++;
		else ans+=2;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
L,R = map(int,input().split())


if R-L >= 2019:
    print(0)
else:
    ans = 2020
    for i in range(L,R+1):
        for j in range(i,R+1):
            if i == j:
                continue
            ans = min(ans,(i%2019)*(j%2019)%2019)
    print(ans)


Measured memory_bytes: 41196
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());

            for (int i = 1; i <= 9; i++)
            {
                if (N % i == 0 && (N/i) <=9)
                {
                    Console.WriteLine("Yes");
                    return;
                }
            }

            Console.WriteLine("No");
        }
    }
}


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

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

ll N, X;
ll x[100010];

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N >> X;
  for (int i = 0; i < N; i++) {
    cin >> x[i];
  }
  ll ans = abs(X - x[0]);
  for (int i = 1; i < N; i++) {
    ans = gcd(ans, abs(X - x[i]));
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1024
#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 imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using ll = long long;
using ii = pair<int,int>;
using vi = vector<int>;
using vii = vector<ii>;
const int oo = 1e9+7;
const int mod = 1e9+7;
const int MAXK = 10005;

char k[MAXK];

int add(const int& a, const int& b) {
    return (a + b) % mod;
}

int sub(const int& a, const int b) {    
    return (a - b + mod) % mod;
}

int main() {
    
    int d;
    int n;
    
    scanf("%s", k);
    scanf("%d", &d);
    
    n = strlen(k);
    
    vector<int> smaller(d, 0); // all possible sums of the digits up to ind index
    int equalsum = 0;
    
    for(int ind = 0; ind < n; ++ind) {
        vector<int> new_smaller(d, 0);
        
        for(int sum = 0; sum < d; ++sum) {
            for(int digit = 0; digit < 10; ++digit) {
                new_smaller[(sum+digit)%d] = add(new_smaller[(sum+digit)%d], smaller[sum]);
            }
        }
        
        for(int digit = 0; digit < k[ind]-'0'; ++digit) {
            new_smaller[(equalsum+digit)%d] = add(new_smaller[(equalsum+digit)%d], 1);
        }
        
        equalsum += k[ind]-'0';
        equalsum %= d;
        smaller = new_smaller;
    }
    
    if(equalsum != 0) smaller[0] = sub(smaller[0], 1);
    printf("%d\n", smaller[0]);
    
    return 0;
}




Measured memory_bytes: 256
import collections
import sys

N = int(input())
s = [sorted(collections.Counter(sys.stdin.readline().rstrip()).items()) for _ in range(N)]

counted = {}
for s_count in s:
    if str(s_count) not in counted:
        counted[str(s_count)] = 1
    else:
        counted[str(s_count)] += 1


count = 0        
for n in counted.values():
    count += n * (n - 1) // 2
            
print(count)

Measured memory_bytes: 98464
#include <iostream>

int main() {
  int S;
  int h, m, s;

  std::cin >> S;
  h = S/3600;
  m = (S%3600)/60;
  s = (S%3600)%60;
  std::cout << h << ":" << m << ":" << s << std::endl;
  return 0;
}



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

using namespace std;
typedef long long ll;
const int maxn = 1e4 + 7;
int a[maxn][maxn];

void flip(int x, int y) {
    a[x][y] = !a[x][y];
    a[x][y + 1] = !a[x][y + 1];
    a[x][y - 1] = !a[x][y - 1];
    a[x - 1][y] = !a[x - 1][y];
    a[x + 1][y] = !a[x + 1][y];
    a[x - 1][y + 1] = !a[x - 1][y + 1];
    a[x - 1][y - 1] = !a[x - 1][y - 1];
    a[x + 1][y - 1] = !a[x + 1][y - 1];
    a[x + 1][y + 1] = !a[x + 1][y + 1];
}

int main() {
    int n, m;
    while (scanf("%d %d", &n, &m) != EOF) {
//        for (int i = 0; i <= n + 1; i++)
//            for (int j = 0; j <= m + 1; j++) a[i][j] = 1;
//
//        for (int i = 1; i <= n; i++)
//            for (int j = 1; j <= m; j++) flip(i, j);
//
//        ll ans = 0;
//        for (int i = 1; i <= n; i++)
//            for (int j = 1; j <= m; j++)
//                ans += !a[i][j];
        printf("%lld\n", (n - 2LL) * (m - 2LL) < 0 ? -(n - 2LL) * (m - 2LL) : (n - 2LL) * (m - 2LL));
    }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n,N) for(int i=n;i<N;i++)
#define p(S) cout<<(S)<<endl
#define ck(n,a,b) ((a)<=(n)&&(a)<(b))
#define F first
#define S second
using namespace std;
int D[210];
int main(){
	int N,K,T,U,V,L;
	cin>>N>>K>>T>>U>>V>>L;
	REP(i,0,N) cin>>D[i];
	int d=0,cnt=0,t=0,have=0;
	REP(i,0,L){
		t=max(t-1,0);
		if(i==D[d]){
			d++;
			if(t==0||have==K){
				t=T*V;
			}else if(have<K){
				have++;
			}
		}else{
			if(t==0&&have>0){
				t=T*V;
				have--;
			}
		}
		if(t>0) cnt++;
	}
	double ans=1.0*cnt/V + 1.0*(L-cnt)/U;
	printf("%.7lf",ans);
	return 0;
}

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (register int i = a; i <= b; i++)

int n, x, t;
int ans;
inline void solve(int T)
{
    cin >> n >> x >> t;
    ans = ceil(1.0 * n / x) * t;
    cout << ans << endl;
}

int main()
{
    // ios_base::sync_with_stdio(0);
    // cin.tie(0);
    // cout.tie(0);
 
    int T = 1;
    // cin >> T;
    rep(i, 1, T) solve(i);
    
    // system("pause");
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse2")
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
typedef long long int lld;
typedef vector<lld> vi;
typedef pair<lld, lld> pi;
#define F first
#define S second
#define N 1007
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define rep(i, a, b) for (lld i = a; i < b; i++)
lld r, j, l, m, n, s, q, i, k, t, p,z,timer,x,y;string s1, s2;
lld a[N][N],dp[N][N];
int main()
{
  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  cin>>n>>m;
  rep(i,1,n+1)
  {
  	rep(j,1,m+1)
  	{
  		char ch;
  		cin>>ch;
  		if(ch=='#')a[i][j]=1;
  	}
  }
  for(i=n;i>=1;i--)
  {
  	for(j=m;j>=1;j--)
  	{
  		if(i==n&&j==m)dp[i][j]=1;
  		else
  		{
  			if(i==n)
  			{
  				if(a[i][j+1]==0)dp[i][j]=dp[i][j+1];
  			}
  			else if(j==m)
  			{
  				if(a[i+1][j]==0)dp[i][j]=dp[i+1][j];
  			}
  			else
  			{
  				p=q=0;
  				if(a[i][j+1]==0)p=dp[i][j+1];	
  				if(a[i+1][j]==0)q=dp[i+1][j];
  				dp[i][j]=p+q;
  				dp[i][j]%=MOD;
  			}
  		}
  	}
  }
  cout<<dp[1][1];
}

Measured memory_bytes: 16000
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    int C = sc.nextInt();
    int K = sc.nextInt();
    
    int max = Math.max(Math.max(A, B), C);
    long ans = A + B + C - max + power(max, K);
    
    System.out.println(ans);
  }
  
  private static long power(int max, int K) {
    long ret = max;
    for (int i = 0; i < K; i++) {
      ret *= 2;
    }
    return ret;
  }
}

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

int main() {
  int n, x, t;
  cin >> n >> x >> t;

  int res = (n / x) * t;
  if (n%x) res += t;

  cout << res << endl;

  return 0;
}



Measured memory_bytes: 3616
fun main() {
    val n = readInt()
    val a = readInts().map { it.toLong() }

    val occurrences = mutableMapOf<Long, Int>()
    a.forEach { num -> occurrences[num] = occurrences[num]?.plus(1) ?: 1 }

    var currSum = a.sum()

    val q = readInt()
    repeat(q) {
        val (b, c) = readInts().map { it.toLong() }
        if (occurrences.containsKey(b)) {
            val occur = occurrences[b]!!
            occurrences[c] = occur + (occurrences[c] ?: 0)
            occurrences[b] = 0

            currSum -= occur * b
            currSum += occur * c
        }

        println(currSum)
    }
}

// Input Reader
private fun readLn() = readLine()!!

private fun readStrings() = readLn().trim().split(" ")
private fun readInt() = readLn().toInt()
private fun readInts() = readStrings().map { it.toInt() }


Measured memory_bytes: 75184
#include <algorithm>
#include <vector>
#include <cfloat>
#include <string>
#include <cmath>
#include <set>
#include <cstdlib>
#include <map>
#include <ctime>
#include <iomanip>
#include <functional>
#include <deque>
#include <iostream>
#include <cstring>
#include <queue>
#include <cstdio>
#include <stack>
#include <climits>
#include <sys/time.h>
#include <cctype>

using namespace std;

typedef long long ll;

// ????????°????????§??°
#define MAX_V 100000

int V;
vector <int> graph[MAX_V];
bool vis[MAX_V];

bool cycledetectDirected() {
  for (int i = 0; i < V; i++) {
    memset(vis, false, sizeof(vis));

    stack<int> st;
    st.push(i);
    while(!st.empty()) {
      int p = st.top(); st.pop();
      vis[p] = true;

      for (int j = 0; j < graph[p].size(); j++) {
	int np = graph[p][j];
	if (np == i) return true;
	if (vis[np]) continue;

	st.push(np);
      }
    }
  }

  return false;
}

int main() {
  int E;
  cin >> V >> E;
  for (int i = 0; i < E; i++) {
    int s, t;
    cin >> s >> t;
    graph[s].push_back(t);
  }
  cout << cycledetectDirected() << endl;
}

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

int main(){
	string str;
	getline(cin, str);
	for(int i = 0; i < str.size(); i++)
		if(islower(str[i])) str[i] = toupper(str[i]);
		else str[i] = tolower(str[i]);
	cout << str << '\n';
}



Measured memory_bytes: 3196
#include<stdio.h>
int main(void)
{
	int n,a[21],b[101],i,z,zz,max;
	max=-1;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d %d",&a[i],&b[i]);
		if(b[i]>max){
			max=b[i];
			z=a[i];
		}
		if(max==b[i]){
			if(z<a[i]){
			z=z;
			}
			else if(z>a[i]){
			z=a[i];
			}
		}
	}
	printf("%d %d\n",z,max);
	return 0;
}		

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

int main(){
  int n,m;
  cin >> n >> m;
  long long int a[n];
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  int l=n-m+1;
  long long int ans=10000000000000000;
  for(int i=0;i<l;i++){
    if(a[i]*a[i+m-1]<0){
      long long int t=min(abs(a[i]),abs(a[i+m-1]))*2+max(abs(a[i]),abs(a[i+m-1]));
      ans=min(ans,t);
    }
    else{
      long long int t=max(abs(a[i]),abs(a[i+m-1]));
      ans=min(ans,t);
    }
  }
  cout << ans << endl;
}

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

using namespace std;
 
int main(){
	long long n,m,c,ans = 0;
	vector<long long>b;
	
	cin >> n >> m >> c;

	for(int i = 0; i < m; i++){
		long long j;
		cin >> j;
		b.push_back(j);
	}

	for(int k = 0; k < n; k++){
		long long sum = 0;

		for(int l = 0; l < m; l++){
			long long a;
			cin >> a;
			sum += a * b[l];
		}

		if((sum + c) > 0){
			ans++;
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 3624
s = input()

ym = False
my = False

first = int(s[:2])
second = int(s[2:])

#first check if ym
if 0<=first<=99 and 1<=second<=12:
	ym = True
if 0<=second<=99 and 1<=first<=12:
	my = True

if ym and my:
	print("AMBIGUOUS")
elif ym:
	print("YYMM")
elif my:
	print("MMYY")
else:
	print("NA")

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

namespace ABC083_B
{
    class Program
    {
        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            string[] str = input.Split(' ');

            int amount = int.Parse(str[0]);
            int minNum = int.Parse(str[1]);
            int maxNum = int.Parse(str[2]);

            int sum = 0;

            for (int num = 1; num <= amount; num++)
            {
                int comparisonNum = num;
                int tempSum = 0;
                while (comparisonNum > 0)
                {
                    tempSum += comparisonNum % 10;
                    comparisonNum /= 10;
                }
                if (tempSum <= maxNum && tempSum >= minNum)
                {
                    sum += num;
                }
            }

            Console.WriteLine(sum);
        }
    }
}


Measured memory_bytes: 11092
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
using namespace std;

#define rep(i,n) for(int (i)=0; (i)<(int)(n); ++(i))
#define foreach(c,i) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)

int h, w;
string s[102];
const int dx[4] = {-1,1,0,0}, dy[4] = {0,0,-1,1};

void rec(int x, int y, char c) {
  if (s[y][x] != c) return;
  s[y][x] = ' ';
  rep (i,4) {
    int tx = x + dx[i], ty = y + dy[i];
    if (tx < 0 || ty < 0 || tx >= w || ty >= h) continue;
    if (s[ty][tx] == c) rec(tx, ty, c);
  }
}

int main() {
  while (cin >> h >> w, h) {
    rep (i,h) cin >> s[i];
    int ans = 0;
    rep (i,h) rep (j,w) if (s[i][j] != ' ') {
      rec(j, i, s[i][j]);
      ans++;
    }
    cout << ans << endl;
  }
  return 0;
}

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

using namespace std;
typedef long long ll;
typedef long double db;
#define pll pair<ll,ll>
#define pii pair<int,int>
#define plll pair<pll,ll>
#define fr first
#define sc second
#define pb push_back
#define mp make_pair
#define mod 1000000007
ll a[26],n,ans=1;
string x;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin>>n>>x;
for(int i=0;i<n;i++)
    a[x[i]-'a']++;
for(int i=0;i<26;i++)
    ans=1LL*ans*(a[i]+1),ans%=mod;
ans--;if(ans<0)ans+=mod;
cout<<ans<<endl;
return 0;
}


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

using namespace std;

int main() {
    map<string, int> mp;

    int q;
    cin >> q;
    while (q--) {
        int op;
        string s;
        cin >> op;
        if (op == 0) {
            int x;
            cin >> s >> x;
            mp[s] = x;
        } else if (op == 1) {
            cin >> s;
            if (!mp.count(s)) {
                cout << 0 << endl;
            } else {
                cout << mp[s] << endl;
            }
        } else if (op == 2) {
            cin >> s;
            mp.erase(s);
        } else {
            string l, r;
            cin >> l >> r;
            for (auto it = mp.lower_bound(l); it != mp.upper_bound(r); it++) {
                cout << it->first << " " << it->second << endl;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 27788
#include<set>
#include<cstdio>

using int64=long long;
using uchar=unsigned char;

constexpr int maxn(200000);

template<class _Tpx,class _Tpy>
	inline _Tpx Min(const _Tpx&x,const _Tpy&y)
		{return x<y?x:y;}

namespace IOManager{
	constexpr int FILESZ(131072);
	char buf[FILESZ];
	const char*ibuf=buf,*tbuf=buf;

	struct IOManager{
		inline char gc()
			{return(ibuf==tbuf)&&(tbuf=(ibuf=buf)+fread(buf,1,FILESZ,stdin),ibuf==tbuf)?EOF:*ibuf++;}

		template<class _Tp>
			inline operator _Tp(){
				_Tp s=0u;char c=gc();
				for(;c<48;c=gc());
				for(;c>47;c=gc())
					s=(_Tp)(s*10u+c-48u);
				return s;
			}
	};
}IOManager::IOManager io;

std::multiset<int>s;

int main(){
	const int n=io;
	for(int i=0;i!=n;++i)
		s.insert((int)io);

	int ans=0;
	for(;1<s.size();){
		const int v1=*--s.end();
		s.erase(--s.end());

		for(int t=(1<<30);t!=1;t>>=1)
			if(s.count(t-v1))
				{s.erase(s.find(t-v1));++ans;break;}
	}
	printf("%d",ans);

	return 0;
}


Measured memory_bytes: 9728
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,x,n) for(int i=x;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
#define MP(a,b) make_pair(a,b)
typedef long long LL;
typedef pair<int, int> PI;
typedef vector<int> VI;
const LL MOD = 1000000007LL;
int solve(string &A, string &B, int N) {
	bool rev[2000];
	int L[2000];
	int R[2000];
	int ans = 1 << 30;
	rep(i, N) {
		if (B[i] == 1) {
			R[N - 1] = i + 1;
			break;
		}
	}
	if (B[N - 1] == 1) R[N - 1] = 0;
	for (int i = N - 2; i >= 0; i--) {
		if (B[i] == 1) {
			R[i] = 0;
		}
		else {
			R[i] = R[i + 1] + 1;
		}
	}
	for (int i = N - 1; i >= 0; i--) {
		if (B[i] == 1) {
			L[0] = N - i;
			break;
		}
	}
	if (B[0] == 1) L[0] = 0;
	REP(i, 1, N) {
		if (B[i] == 1) {
			L[i] = 0;
		}
		else {
			L[i] = L[i - 1] + 1;
		}
	}
	rep(k, N) {
		memset(rev, 0, sizeof(rev));
		int flip = 0;
		rep(i, N) {
			if (A[i] != B[(i - k + N) % N]) {
				rev[i] = 1;
				flip++;
			}
		}
		vector<PI> v;
		rep(i, N) {
			if(rev[i]) v.push_back(MP(max(L[i] - k, 0), R[i]));
		}
		sort(ALL(v));
		reverse(ALL(v));
		int sum = 1 << 30;
		int ma = 0;
		rep(i,v.size()) {
			sum = min(sum, v[i].first + ma);
			ma = max(ma, v[i].second);
		}
		sum = min(sum, ma);
		ans = min(ans, k + flip + 2 * sum);
	}
	return ans;
}
int main() {
	string A, B;
	cin >> A >> B;
	int N = A.size();
	rep(i, N) A[i] -= '0';
	rep(i, N) B[i] -= '0';
	if (count(ALL(B), 1) == 0) {
		if (count(ALL(A), 1) == 0) {
			cout << 0 << endl;
		}
		else {
			cout << -1 << endl;
		}
		return 0;
	}
	int ans = solve(A, B, N);
	reverse(ALL(A));
	reverse(ALL(B));
	ans = min(ans, solve(A, B, N));
	cout << ans << endl;
}

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

using namespace std;

using ll = int_fast64_t;
constexpr ll llmax = INT_FAST64_MAX; // std::numeric_limits<int_fast64_t>::max()
constexpr ll llmin = INT_FAST64_MIN; // std::numeric_limits<int_fast64_t>::min()
using ull = uint_fast64_t;
constexpr ull ullmax = UINT_FAST64_MAX; // std::numeric_limits<uint_fast64_t>::max()

#define FOR(i, b, e) for (int i = (b); i < (e); ++i)
#define RFOR(i, b, e) for (int i = ((e) - 1); (b) <= i; --i)
#define REP(i, N) for (int i = 0; i < (N); ++i)
#define RREP(i, N) for (int i = ((N) - 1); 0 <= i; --i)
#define scanInt(x) int x; scanf("%d", &(x)); getchar();
#define scanLLInt(x) ll x; scanf("%lld", &(x)); getchar();
#define scanVecInt(A, N) vector<int> A(N); REP(i, N){scanf("%d", &(A[i])); getchar();}
#define scanVecLLInt(A, N) vector<ll> A(N); REP(i, N){scanf("%lld", &(A[i])); getchar();}

int main()
{
    scanInt(N);
    int r = 0;
    int b = 0;
    REP(n, N){
        char c = getchar();
        if (c == 'R') r++;
        if (c == 'B') b++;
    }
    if (b < r){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}


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


string s;
int k;
int ans;

int main(){
    
    cin >> s;
    cin >> k;
    int n = s.size();
    for(int i=0;i<n;i++){
        for(int d=1;d<=9;d++){
            if(i==0 and d > s[i]-'0')
                continue;
            bool less1 = i || d < s[i]-'0';
            if(k==1){
                ans++;
            }else{
                for(int j=i+1;j<n;j++){
                    for(int d=1;d<=9;d++){
                        if(!less1 and d > s[j]-'0')
                            continue;
                        bool less2 = less1 || d < s[j]-'0';
                        if(k==2){
                            ans++;
                        }else{
                            for(int k=j+1;k<n;k++){
                                for(int d=1;d<=9;d++){
                                    if(!less2 and d > s[k]-'0')
                                        continue;
                                    ans++;
                                }
                                if(s[k] > '0')
                                    less2 = 1;
                            }
                        }
                    }
                    if(s[j] > '0')
                        less1 = 1;
                }
            }
        }
    }
    cout << ans ;
    
    return 0;
}

Measured memory_bytes: 3488
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
       Scanner scan= new Scanner(System.in);
       int n=scan.nextInt();
       int m =scan.nextInt();
       int a[][] = new int[n][m];
       int b[] = new int[m];
       int c[] = new int[n];

       for(int i=0;i<n;i++){
           for( int j=0;j<m;j++){
               a[i][j]=scan.nextInt();
           }
       }
       for(int i=0;i<m;i++){
           b[i]=scan.nextInt();
       }

       for(int i=0;i<n;i++){
           for(int j=0;j<m;j++){
               c[i]+=a[i][j]*b[j];
           }
           System.out.println(c[i]);
       }
    }
}



Measured memory_bytes: 40200
#include <iostream>
#include <vector>
#include <numeric>
#include <iomanip>

using namespace std;
using ll = long long;
using ld = long double;

void solve(ll N, ll K, vector<ll> p) {
  int ma2{0};

  int psum = accumulate(p.begin(),p.begin()+K,0);
  ma2 = psum;

  for (auto i = K; i != N; ++i) {
    psum += p[i] - p[i-K];
    ma2 = max(ma2,psum);
  }
  
  cout << fixed << (ma2+K)/2. << endl;
}

int main() {
  ll N;
  cin >> N;
  ll K;
  cin >> K;
  vector<ll> p(N);
  for (int i = 0; i < N; i++) {
    cin >> p[i];
  }
  solve(N, K, move(p));
  return 0;
}


Measured memory_bytes: 1792
gcd, lcm = [], []
while True:
	try:
		a, b = map(int, raw_input().split())
		if a > b:
			m, n = a, b
		else:
			m, n = b, a		

		while n != 0:
			m, n = n, m % n 
		gcd.append(m)
		lcm.append(a * b / m)
	except EOFError:
		break

for gcd, lcm in zip(gcd, lcm):
	print '%d %d' % (gcd, lcm)

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

#define fi first
#define se second
#define sz(x) ((int)x.size())
using namespace std;
typedef long long lli;
typedef pair<int,int> pii;

const int inf=1e9;
int n,k,q,arr[2000];
pii a[2000];
int get(int val) {
	int mx=0;
	priority_queue<int,vector<int>,greater<int>> aq,qq;
	for(int i=0;i<n;i++) if(arr[i]>=val) {
		int j=i;
		while(!aq.empty()) aq.pop();
		for(;j<n && arr[j]>=val;j++) aq.push(arr[j]);
		
		int s=sz(aq)-k+1;
		while(s>0) {
			qq.push(aq.top()); aq.pop();
			s--;
		}
		i=j-1;
	}
	if(sz(qq)<q) return inf;
	for(int i=0;i<q;i++) {
		mx=qq.top(); qq.pop();
	}
	return mx-val;
}
int main() {
	scanf("%d%d%d",&n,&k,&q);
	for(int i=0;i<n;i++) {
		scanf("%d",arr+i);
		a[i].fi=arr[i]; a[i].se=i;
	}
	sort(a,a+n);
	
	int ans=inf;
	for(int i=0;i<n;i++) if(i==0 || a[i].fi!=a[i-1].fi)
		ans=min(ans,get(a[i].fi));

	printf("%d\n",ans);
	
	return 0;
}


Measured memory_bytes: 384
# TLE
s = input()
loop = int(input())
is_head = True
to_head = []
to_tail = []
for i in range(loop):
    q_li = input().split()
    t = int(q_li[0])
    if t == 1:
        is_head = not is_head
    else:
        f = int(q_li[1])
        c = q_li[2]
        if f == 1:
            # 先頭に追加
            to_head.append(c) if is_head else to_tail.append(c)
        else:
            # 末尾に追加
            to_tail.append(c) if is_head else to_head.append(c)

if is_head:
    print("".join(to_head[::-1]) + s + "".join(to_tail))
else:
    print("".join(to_tail[::-1]) + s[::-1] + "".join(to_head))


Measured memory_bytes: 72152
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)
INF = float('inf')

import collections
N = int(input())
A = list(map(int, input().split()))
cA = collections.Counter(A)

LIM = 10 ** 6 + 1
# LIM = 25

A.sort()
dp = [1] * LIM

for i in set(A):
    s = i * 2
    while s < LIM:
        dp[s] = 0
        s += i

ans = 0
# print(dp)
for a in A:
    # print("{} {}".format(dp[a], cA[a]))
    if dp[a] and cA[a] == 1:
        # print(a)
        ans += 1
print(ans)

Measured memory_bytes: 52960
#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()
{
  string s;
  cin >> s;
  int t = 0;
  rep(i, s.size())
  {
    if (s[i] == 'o')
      t += 100;
  }
  cout << 700 + t << endl;
  return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
 int A[200005],B[200005],dp[100005][1],i,n,sum,say,a,b,c,d,e,f,mak,S,g,sum2,x,y,m,j,C[1000005],l,r=-1,D[200005],k,T,say1,say2,say3,I,K,bas,son,mid,t,h ;
 //char s[1000005],ch;
vector<int> v1,v2,v;
string s,s1,s2;
 map<char,int> mp[1005];
double dam;
int main(){
m=1;
scanf("%d",&n);
for(i=1;i<=n;i++ ){scanf("%d",&A[i] ); }
sort(A+1,A+n+1 );
//reverse(A+1,A+n+1 );
dam= (double)(A[1]+A[2] )/2;
for(i=3;i<=n;i++ ){; dam+=(double)A[i]; dam/=2;  }

printf("%.12lf",dam);

	return 0;
}

Measured memory_bytes: 2304
#include <iostream>
using namespace std;
long long X;

long long find(long long X){
	long long L=0,R=1<<16,M;
	while(L<R){
		M = L+(R-L)/2;
		if(X <= M*(M+1)/2)
			R = M;
		else
			L = M+1;
	}
	return L;
}

int main(){
	cin>>X;
	cout<<find(X)<<endl;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll N,K;
ll h[100010];
ll dp[100010];
ll call(int i)
{
    if(i==N) return 0;
    
    if(dp[i]!=-1) return dp[i];
    
    dp[i]=abs(h[i+1]-h[i]) + call(i+1);
    for(ll j=2;j<=K;j++)
    {
        if(i+j<=N)
    dp[i]=min(dp[i],abs(h[i+j]-h[i]) + call(i+j));
        else break;
    
        
    }
    return dp[i];
}
int main()
{
    cin>>N>>K;
    for(ll i=1;i<=N;i++)
    {
        cin>>h[i];
    }
    memset(dp,-1,sizeof(dp));
    cout<<call(1);
}

Measured memory_bytes: 6528
n = int(input())
arr_a = []
arr_b = []
for i in range(n):
    a, b = map(int, input().split())
    arr_a.append(a)
    arr_b.append(b)
arr_a.sort()
arr_b.sort()
if n % 2 == 1:
    print(arr_b[n//2] - arr_a[n//2] + 1)
else:
    median_a = (arr_a[int(n/2 -1)] + arr_a[int(n/2)])
    median_b = (arr_b[int(n/2 -1)] + arr_b[int(n/2)])
    print(median_b - median_a + 1)

Measured memory_bytes: 25412
#include<stdio.h>
#include<string.h>
int main(void)
{
  char s[100],bef[50];
  int len,ans=0;

  scanf("%s",s);
  len=strlen(s);
  if(len%2){
    strncpy(bef,s,(int)len/2);
    for(int i=len-1;i>=(int)len/2+1;i--){
      if(bef[len-1-i]!=s[i]){
        ans++;
        //printf("i=%d\n",i);
      }
    }
  }else{
    strncpy(bef,s,(int)len/2);
    for(int i=len-1;i>=(int)len/2;i--){
      if(bef[len-1-i]!=s[i]){
        ans++;
      //  printf("i=%d\n",i);
      }
    }
  }
  printf("%d",ans);
  return 0;

}


Measured memory_bytes: 128
import Foundation

func readInt() -> [Int]{
    return readLine()!.split(separator:" ").map{Int($0)!}
}

let A = readInt()
let B = readInt()
let c = Int(readLine()!)!

if(A[1] <= B[1]){
  print("NO")
}else{
  if(abs(A[0] - B[0]) <= c * (A[1] - B[1])){
    print("YES")
  }else{
    print("NO")
  }
}

Measured memory_bytes: 13640
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<climits>
#include<bitset>
#define ld long double
#define ll long long int
#define ull unsigned long long int
#define rep(i,n) for(i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define INF INT_MAX;
using namespace std;
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;}
const long long LLINF=1LL<<60;
//set<int>::iterator it;



int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
	
	int n,q,i;
	string s;
	vector<int> v,w;
	
	cin>>n>>q>>s;
	for(i=0;i<s.length()-1;i++){
		if(s[i]=='A'&&s[i+1]=='C'){
			v.push_back(1);
		}
		else v.push_back(0);
	}
	w.push_back(0);
	for(i=0;i<v.size();i++){
		w.push_back(v[i]+w[i]);
	}
//	for(i=0;i<w.size();i++)cout<<w[i]<<endl;
	int r,l;
	for(i=0;i<q;i++){
		cin>>l>>r;
		cout<<w[r-1]-w[l-1]<<endl;
	}
	
//////////////////////////////////////////////////////
	return 0;
}


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

#define int long long

void read(int &x) {
    x=0;int f=1;char ch=getchar();
    for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=-f;
    for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';x*=f;
}

void print(int x) {
    if(x<0) putchar('-'),x=-x;
    if(!x) return ;print(x/10),putchar(x%10+48);
}
void write(int x) {if(!x) putchar('0');else print(x);putchar('\n');}

#define lf double
#define ll long long 

#define pii pair<int,int >
#define vec vector<int >

#define pb push_back
#define mp make_pair
#define fr first
#define sc second

#define data asd09123jdf02i3h

#define FOR(i,l,r) for(int i=l,i##_r=r;i<=i##_r;i++)

const int maxn = 1e6+10;
const int inf = 1e9;
const lf eps = 1e-8;
const int mod = 1e9+7;

map<int,int > t;

signed main() {
    int s=0,x=1,n,ans=0;t[0]=1;read(n);
    for(int i=1;i<=n;i++) read(x),s+=x,ans+=t[s],t[s]++;
    write(ans);
    return 0;
}


Measured memory_bytes: 12800
//dlang template---{{{
import std.stdio;
import std.conv;
import std.string;
import std.array;
import std.algorithm;
import std.typecons;
import std.math;
import std.range;

// MIT-License https://github.com/kurokoji/nephele
class Scanner
{
  import std.stdio : File, stdin;
  import std.conv : to;
  import std.array : split;
  import std.string;
  import std.traits : isSomeString;

  private File file;
  private char[][] str;
  private size_t idx;

  this(File file = stdin)
  {
    this.file = file;
    this.idx = 0;
  }

  this(StrType)(StrType s, File file = stdin) if (isSomeString!(StrType))
  {
    this.file = file;
    this.idx = 0;
    fromString(s);
  }

  private char[] next()
  {
    if (idx < str.length)
    {
      return str[idx++];
    }

    char[] s;
    while (s.length == 0)
    {
      s = file.readln.strip.to!(char[]);
    }

    str = s.split;
    idx = 0;

    return str[idx++];
  }

  T next(T)()
  {
    return next.to!(T);
  }

  T[] nextArray(T)(size_t len)
  {
    T[] ret = new T[len];

    foreach (ref c; ret)
    {
      c = next!(T);
    }

    return ret;
  }

  void scan()()
  {
  }

  void scan(T, S...)(ref T x, ref S args)
  {
    x = next!(T);
    scan(args);
  }

  void fromString(StrType)(StrType s) if (isSomeString!(StrType))
  {
    str ~= s.to!(char[]).strip.split;
  }
}

//Digit count---{{{
int DigitNum(int num) {
  int digit = 0;

  while (num != 0) {
    num /= 10;
    digit++;
  }

  return digit;
}
//}}}
//}}}

void main() {
  Scanner sc = new Scanner;

  int N, K;
  sc.scan(N, K);

  if ((N - K) >= N / 2) {
    writeln("YES");
  } else {
    writeln("NO");
  }
}


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

#define int             long long int
#define ld              long double
#define ff              first
#define ss              second
#define mp              make_pair
#define pb              push_back
#define si              set <int>
#define vi              vector <int>
#define pii             pair <int, int>
#define vpii            vector <pii>
#define vpp             vector <pair<int, pii>>
#define mii             map <int, int>
#define mpi             map <pii, int>
#define msi             map < string, int >
#define loop(i,s,e)     for(int i=s;i<e;i++)
#define rloop(i,e,s)    for(int i=e;i>=s;i--)
#define mset(a,f)       memset(a,f,sizeof(a))
#define spi             set <pii>
#define endl            "\n"
#define M               1000000007
#define sz(x)           ((int) x.size())
#define all(p)          p.begin(), p.end()
#define que_max         priority_queue <int>
#define que_min         priority_queue <int, vi, greater<int>>
#define bug(...)        __f (#__VA_ARGS__, __VA_ARGS__)
#define print(a)        for (auto x : a) cout << x << " "; cout << endl
#define Print(a,x,y)    for (int i=x; i<y; i++) cout<< a[i]<< " "; cout << endl

inline int power(int a, int b)
{
	int x = 1;
	while (b)
	{
		if (b & 1) x *= a;
		a *= a;
		b >>= 1;
	}
	return x;
}

template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr (names + 1, ',');
	cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

const int N = 200005;
int arr[N];

void solve()
{
	int n, k;
	cin >> n >> k;
	int a[n];
	int sum = 0;
	loop(i, 0, n) cin >> a[i];
	sort(a, a + n);
	loop(i, 0, n)
	{

		if (i < n - k)
			sum += a[i];
	}
	cout << sum;
	return;
}

int32_t main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);


	clock_t z = clock();
	int t = 1;
	//cin >> t;
	while (t--)
	{
		solve();
	}
	cerr << "Total Time : " << ((double)(clock() - z) / CLOCKS_PER_SEC);

	return 0;
}

Measured memory_bytes: 1792
# coding: utf-8


def main():
    _ = int(input())
    ints = list(map(int, input().split(' ')))

    for int_ in ints:
        if int_ % 2 == 0:
            if int_ % 3 == 0 or int_ % 5 == 0:
                pass
            else:
                print('DENIED')
                return 0
        else:
            pass

    print('APPROVED')

    return 0


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    int n;

    public static void main(String args[]) {
        new Main().run();
    }

    void run() {
        FastReader sc = new FastReader();
        n = sc.nextInt();
        solve();
    }

    void solve() {
        System.out.println("ABC" + n);
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Measured memory_bytes: 22100
//#include<iostream>
//#include<algorithm>
//#include<string>
//#include <cmath>
//#include <vector>
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define REP(x,n) for(int x=0;x<n;x++)

//vector//
#define vei vector<int> 
#define velli vector<long long int> 
#define pb(x) push_back(x) // 末尾にxを加える
#define pb2 pop_back() // 末尾削除
#define all(x) (x).begin(),(x).end() //イテレーター
#define be(x) (x).begin()
//auto  auto begin = v.begin()とか

typedef pair<int,int> P;  //q(p.first,p.second)

// 木のdfs 
// 木は隣接要素の親以外へ向かう有効グラフ↓
// seenの代わりに親ノードには逆走しない形にする
/////////////////////////////////////////////////////////////////////////
using Graph = vector<vector<int>>;

// vector<bool> seen;
vector<ll int> ans;

void dfs(const Graph &G, int v, int p, vector<ll int> &res) {
    
    // 最初は親がいないのでこうする
    if(p!=-1){
        res[v] += res[p];
    }
    // v から行ける各頂点 next_v について
    // 範囲for文
    for (auto next_v : G[v]) { 
        if(next_v==p) continue; // nextが親の時はダメ
        dfs(G, next_v, v, res); // 再帰的に探索
    }
}
// 累積和を使った考え方（普通にやるとO(QN)でやばい）
int main() {
    // 入力
    int N, Q; cin >> N >> Q;

    // グラフ入力受取 
    Graph G(N);
    for (int i = 0; i < N-1; i++) {
        int a, b;
        cin >> a >> b;
        G[a-1].push_back(b-1);
        G[b-1].push_back(a-1); // 無効グラフの場合
    }

    // 入力p,x
    vector<P> px(N);
    for(int i=0;i<Q;i++){
        cin >> px[i].first >> px[i].second;
    }

    ans.assign(N,0); //0で初期化
    for(int i=0;i<Q;i++){
        ans[px[i].first-1]+=px[i].second;
    }

    // seen.assign(N, false); // 全頂点を「未訪問」に初期化
    dfs(G, 0, -1, ans); // 0からdfs

    // 出力
    for(int i=0; i<N;i++){
        cout << ans[i] << ' ';
    }
}

// 行きがけ順、帰りがけ順
// タイムスタンプ

// 辺に重みがある場合qiitaのpageへgo(構造体を作ってあげる)

// 豊富な例　https://qiita.com/drken/items/a803d4fc4a727e02f7ba
// ・grid探索
// ・連結成分個数
// ・二部グラフ判定
// ・木の場合のDFS(木の深さ、部分木の大きさ)

Measured memory_bytes: 29828
N=int(input())
L_list = list(map(int,input().split()))

def binary_search_left(list,target):
    '''
    配列に対してある数nを配列のソート順を崩さないように挿入するためのindexを返す関数。
    同一の数が配列に複数含まれていた場合は最も小さいindexを返す。
    '''
    result = -1
    left = 0
    right = len(list) - 1

    while left <= right:
        center = (left + right)//2
        if list[center] == target:          # 一致した場合
            if list[center - 1] == target:  # -> その一つ前も一致した場合、rightをcenterにしてもう一周
                right = center
            else:                           # -> その一つ前は一致しない場合、一番左で一致したということでcenterを返す
                return center
        elif list[center] < target:
            left = center + 1
        elif list[center] > target:
            right = center - 1
    return left                             # 一致したらcenterを返すが（上記）、なければleftのインデックスを返す

L_list = sorted(L_list)

ans = 0
for a_index in range(0, N-2):
    for b_index in range(a_index+1, N-1):
        a = L_list[a_index]
        b = L_list[b_index]
        c_right_index = binary_search_left(L_list, a+b)
        if c_right_index > b_index:
            ans += c_right_index - b_index - 1
        else:
            pass

print(ans)

Measured memory_bytes: 46072
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
#include <bits/stdc++.h>
#include <utility>
#include <iomanip>

#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,a,b) for(int i = (a); (b) <= i; i--)
#define REP(i,n) for(int i = 0; i < (n); i++)
#define RREP(i,n) for(int i = n; n <= i; i--)
#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))
#define elif else if
#define MOD 1000000007
#define INF (1<<30)

using namespace std;

#define ld long double
#define ll long long

map <int ,int> mpa,mpb;
typedef pair<ll, ll> P;
priority_queue<P, vector<P>, greater<P>> pque;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  string S;
  cin >> S;
  int N=S.size();
  int zero=0;
  int one=0;
  for(int i=0;i<N;i++){
    if(S[i]=='0'){
      zero++;
    }else{
      one++;
    }
  }
  int ans=min(one,zero)*2;
  cout << ans << endl;
  return 0;
}

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

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define debug(i) cout << i << endl;
#define debugarr(a) for(auto i : a) cout << i << " ";

#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define pi pair<int,int>
#define pll pair<ll, ll>
#define vpi vector<pi>

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);

    int k, x;
    cin >> k >> x;
    vi ans;
    for(int i = x; i >= max(-1000000, x-k+1); i--) {
        ans.PB(i);
    }
    for(int i = x+1; i <= min(1000000, x+k-1); i++) {
        ans.PB(i);
    }

    sort(ans.begin(), ans.end());
    debugarr(ans);
    cout << endl;

}


Measured memory_bytes: 256
# B - Some Sums
# coding: utf-8

N, A, B = map(int, raw_input().split())
result = 0

for num in range(1, N+1):
  wa = num/10000 + (num%10000)/1000 + (num%1000)/100 +(num%100)/10 +(num%10)
  if wa >= A and wa <= B : result += num

print result


Measured memory_bytes: 2948
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef long long ll;

#define INF 10e17 // 4倍しても(4回足しても)long longを溢れない
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())

ll n,s;

ll f(ll b, ll n) {
  ll res = 0;
  while (n > 0) {
    res += n % b;
    n /= b;
  }
  return res;
}

int main() {
  cin >> n >> s;

  if (n == s) {
    cout << n + 1 << endl;
    return 0;
  }

  for (ll b = 2; b * b <= n; ++b) {
    if (f(b,n) == s) {
      cout << b << endl;
      return 0;
    }
  }

  ll ans = INF;
  for (ll p = 1; p * p <= n; ++p) {
    ll b = (n - s) / p + 1;
    if (b < 2) continue;
    if (f(b,n) == s) ans = min(ans,b);
  }

  cout << (ans == INF ? -1 : ans) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
using ll = long long int;
ll fun(ll K){
    if (K % 2 == 0 || K % 5 == 0) 
		return -1; 
	ll number = 0; 
	ll len = 1; 
	for (len = 1; len <= K; len++) {
		number = (number * 10 + 7) % K;
		if (number == 0) 
			return len; 
	} 
	return -1;
}
int main(){ 
    ll K;
    cin>>K;
    cout<<fun(K); 
    return 0; 
} 


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

int main() {
  
  string s1, s2, s3;
  cin >> s1 >> s2 >>s3;
  
  cout << s1.at(0) << s2.at(0) << s3.at(0) << endl;
  
  return 0;
  
}

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

string tobin(int val)
{
  if(val == 0) {
    return string("0");
  }

  string s;
  while(val != 0) {
    if (val % 2 == 0) {
      s.insert(s.begin(), '0');
    } else {
      s.insert(s.begin(), '1');
    }
    val /= 2;
  }

  return s;
}

int main() {
  string S;
  cin >> S;

  int len = S.size() - 1;
  long int n = pow(2, len);
  long int total = 0;
  for (long int i = 0; i < n; ++i) {
    string b = tobin(i);
    int diff = len - b.size();
    if (diff > 0) {
      for (int j = 0; j < diff; ++j) {
	b.insert(b.begin(), '0');
      }
    }
    //    cout << b << endl;                                                                                                                                                
    long int tmp = 0;
    long int res = 0;
    for (int j = 0; j < len + 1; ++j) {
      tmp = tmp * 10 + S.at(j) - '0';
      if (j == len) {
        res += tmp;
        break;
      }
      if (b.at(j) == '1') {
        res += tmp;
        tmp = 0;
      }
      //      cout << "tmp: " << tmp << " res: " << res << endl;                                                                                                            
    }
    total += res;
    //    cout << "total: " << total << endl;                                                                                                                               
  }
  cout << total << endl;
}

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

int main(){
  long n,k;
  cin >> n >> k;
  vector<long> c(200000);
  long a[200000], b[200000];
  
  for(long i=1; i<=n; i++) cin >> a[i] >> b[i];
  for(long i=1; i<=n; i++) c[a[i]]+=b[i];
   long ans=0; 
   for(long i=0; i<200000;i++){
  	k-=c[i];
    if(k<=0){
     ans=i;
     break;             
    }
  }
  cout << ans << endl;
  
}

Measured memory_bytes: 4608
from collections import Counter
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
ct = Counter(A)
for j in range(M):
  b, c = list(map(int, input().split()))
  ct[c] += b
ky = list(ct.keys())
ky.sort()
cc = 0
s = 0
for k in ky[::-1]:
  ad = min(N-cc, ct[k])
  s += k * ad
  cc += ad
print(s)

Measured memory_bytes: 32440
#include "iostream"
#include "vector"
#include "string"
#include "algorithm"
#include "math.h"
#include "cstring"
#include "queue"

using namespace std;
typedef long long ll;
typedef pair<long long, long long> pll;

int main()
{
  int n;
  cin >> n;
  ll a[100100], b[100100];
  ll sum[100100];
  vector<pll> p;
  for (int i = 0; i < n; i++)
  {
    cin >> a[i] >> b[i];
    sum[i] = a[i] + b[i];
    p.push_back(make_pair(sum[i], a[i]));
  }
  sort(p.begin(), p.end());
  reverse(p.begin(), p.end());

  ll ans = 0;
  for (int i = 0; i < n; i++)
  {
    if (i % 2 == 0)
    {
      ans += p[i].second;
    }
    else
    {
      ans -= p[i].first - p[i].second;
    }
  }
  cout << ans << "\n";
}


Measured memory_bytes: 3444