akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main(void)
{
  int x,h,m,s;

  scanf("%d", &x);
  h=x/3600;
  x=x-h*3600;
  m=x/60;
  x=x-m*60;
  s=x;
  printf("%d:%d:%d\n", h,m,s);
  return 0;
}

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

int main(){
  int a, b, tmp;

  for(;;){
    cin >> a >> b;
    if (a == 0 && b == 0) break;
    if ( a > b) {
      tmp = a;
      a = b;
      b = tmp;
      cout << a << " " << b << endl;
    } else {
      cout << a << " " << b << endl;
    }
  }

  return 0;
}



Measured memory_bytes: 3068
#include<iostream>
using namespace std;
int n,m,cnt,id;
bool t[1000];
int main(){
  while(cin>>n>>m){
    if(n==0&&m==0)break;
    for(int i=0;i<n;i++)t[i]=true;
    id=0;
    cnt=0;
    for(int i=0;i<n-1;i++){
      
      while(1){
	if(t[id])cnt++;
	id++;
	if(id==n)id=0;
	
	if(t[id]==true&&cnt==m)break;

      }
      
      t[id]=false;
      cnt=1;
    }

    for(int i=0;i<n;i++){
      if(t[i])cout<<(i==0?n:i)<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(ll i=0;i<n;i++)
const ll INF=1e18;
const int inf=2e9;
const ll MOD=1000000007;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};

int main(){
    while(true){
        int N;cin>>N;
        if(N==0)break;
        int info[N];
        rep(i,N)cin>>info[i];
        sort(info,info+N);
        int sum=0;
        rep(i,N-2)sum+=info[i+1];
        int ans=sum/(N-2);
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include<unordered_map>
#define _CRT_SECURE_NO_WARNINGS
#define ll long long
#define BUF 50
using namespace std;
ll MOD = 1e9 + 7;
ll A, B, C, D, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
ll ans = 0;
int main() {
	cin >> N;
	int l=0, r=0;
	int Xor = 0, Sum = 0;
	vector<int>A(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	for (int l = 0; l < N; l++) {
		while (r < N && (Sum + A[r]) == (Xor ^ A[r])) {
			Sum += A[r];
			Xor ^= A[r];
			r++;
		}
		ans += (r - l);
		if (r == l)r++;
		else {
			Sum -= A[l];
			Xor ^= A[l];
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int maxof(int* p, int N){
    int r = -1000000000;
    for(int i=0; i<N; i++){
        if(r < p[i]) r = p[i];
    }
    return r;
}

int main() {
    int N;
    cin >> N;
    int p[N];
    int i, r=0;
    for(i=0; i<N; i++) cin >> p[i];
    bool f = true;
    for(i=0; i<N; i++){
        if(f && p[i] == maxof(p, N)){
            r+= p[i]/2; 
            f=false;
            }
        else r+= p[i];
    }
    cout << r << endl;
}

Measured memory_bytes: 256
n, t = map(int, input().split())
a = list(map(int, input().split()))
cur = 0
s = 0
for i in range(n):
    if cur < a[i]:
        s += t
    elif cur < a[i] + t:
        s += min(t, a[i] + t - cur)
    cur = a[i] + t
print(s)

Measured memory_bytes: 25196
#include <stdio.h>
#include <string.h>
#define rep(i,n) for(i=0;i<n;i++)
#define MEMSET(a) memset(a,0,sizeof(a))
int in(void){
	int i;
	scanf("%d",&i);
	return i;
}
long long llin(void){
	long long i;
	scanf("%lld",&i);
	return i;
}

int main(void){
	int i;
	while(1){
		int n;
		scanf("%d",&n);
		if(!n)break;
		int bote[26]={};
		char c[300];
		getchar();
		fgets(c,2*n+1,stdin);
		int maxb=0;
		char maxc;
		rep(i,n){
			int t=c[2*i]-'A';
			bote[t]++;
			if(maxb<bote[t]){
				maxb=bote[t];
				maxc=c[2*i];
			}
			int j;
			for(j=0;j<26;j++){
				if(j==maxc-'A')continue;
				if(bote[j]+(n-i-1)>=maxb)break;
			}
			if(j==26){
				printf("%c %d\n",maxc,i+1);
				goto END;
			}
		}
		puts("TIE");
		END:;
	}
	return 0;
}



Measured memory_bytes: 2048
import java.util.*;

public class Main{

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

        int N = sc.nextInt();
        int K = sc.nextInt();
        int Q = sc.nextInt();
        int[] P = new int[N];
        int[] A = new int[Q];

        if(K>Q){
            for(int i=0; i<N; i++){
                System.out.println("Yes");
            }
        }
        else if(K<=Q){
            for(int i=0; i<Q; i++){
                A[i] = sc.nextInt();
                P[A[i]-1] += 1;
            }
            for(int i=0; i<N; i++){
                if(P[i]>Q-K){
                    System.out.println("Yes");
                }
                else{
                    System.out.println("No");
                }
            }
        }

    }
}

Measured memory_bytes: 56700
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mp make_pair
#define pb push_back
#define popb pop_back
#define all(x) (x).begin(), (x).end()
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
 
typedef vector<int> vi;
 
int main(){
    fast;
    ll t;cin>>t;
    string s;cin>>s;
    if(s.size()>t) {
        for(int i=0;i<t;i++) cout<<s[i];
        cout<<"...";
    }
    else{
        cout<<s;
    }
}

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

using namespace std;  

int solvio1(int p){
     while (p >= 10) 
     p /= 10; 
     return p; 
} 
void solve(){ 
    int i,j,n;   
    cin >> n; 
    int tot[10][10] = {}; 
    for (i = 1; i <= n; i++) { 
        int pro1  = i % 10; 
        int pro = solvio1(i); 
        tot[pro][pro1]++; 
    } 
    int ans = 0; 
    for(i=0; i<10; i++)
    for(j=0;j<10;j++)
      ans = ans + tot[i][j] * tot[j][i];
      cout << ans << endl; 
} 

    
int main(){
    
    solve();
    return 0;
}


Measured memory_bytes: 3528
#include<stdio.h>

int main(void) {
	int n, i;
	int a[1000000];
	int buka[1000000] = { 0 };

	scanf("%d", &n);

	for (i = 0; i < n - 1; i++) {
		scanf("%d", &a[i]);
	}


	for (i = 0; i < n - 1; i++) {
		buka[a[i] - 1]++;
	}

	for (i = 0; i < n; i++) {
		printf("%d\n", buka[i]);
	}

	return 0;
}

Measured memory_bytes: 6424
input_list = list(map(int, input().split()))

flag = False
for idx in input_list:
    if idx>=1 and idx<=100:
        flag = True
    if flag is False:
        break
  
turn = 0
if flag:
    A, B, C, D = input_list
    continue_flag = True
    while continue_flag:
        if turn%2==0:
          C -= B
          if C<=0:
            print("Yes")
            continue_flag = False
          turn += 1
        else:
          A -= D
          if A<=0:
            print("No")
            continue_flag = False
          turn += 1
      

Measured memory_bytes: 9192
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
  int N;
  cin >> N;
  ll a[N];
  bool s = true;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
    if (a[i] % 2 != 0) {
      s = false;
    }
  }
  if (s) {
    cout << "second" << endl;
  } else {
    cout << "first" << endl;
  }
  return 0;
}

Measured memory_bytes: 4372
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>
#include <atcoder/all>


using namespace std;
using namespace atcoder;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;


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





















template <typename T>
class SegmentTree {
private:
    int n;    // 配列の要素数
    T init;    // 配列を初期化するときの値
    vector<T> data;     // セグメントツリーを持つ配列
    
public:
    SegmentTree(int m, T init = 0) : n(1), init(init){
        while(n < m) n <<= 1;
        data.assign(2 * n - 1, init);
    }
    
    T operation(T t1, T t2){
        return t1 + t2;
    }
    
    void update(int k, T val){
        k += n - 1;
        data[k] = val;
        
        while(k > 0){
            k = (k - 1) / 2;
            data[k] = operation(data[k * 2 + 1], data[k * 2 + 2]);
        }
    }
    
    // [a, b) の値を求める
    T query(int a, int b){
        return query(a, b, 0, 0, n);
    }
    
    T query(int a, int b, int k, int l, int r){
        if(r <= a || b <= l) return init;
        if(a <= l && r <= b){
            return data[k];
        }
        else{
            T vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
            T vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
            return operation(vl, vr);
        }
    }
};


int main(){
    ll n, Q;
    cin >> n >> Q;
    vector<ll> a(n);
    SegmentTree<ll> tree(n);
    REP(i, n){
        cin >> a[i];
        tree.update(i, a[i]);
    }
    REP(i, Q){
        ll q;
        cin >> q;
        if(q == 0){
            ll p, x;
            cin >> p >> x;
            tree.update(p, tree.query(p, p + 1) + x);
        }
        else{
            ll l, r;
            cin >> l >> r;
            cout << tree.query(l, r) << endl;
        }
    }
}

Measured memory_bytes: 16440
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

long long dp_table(int l, int r, vector<vector<bool>>& flag,
                   vector<vector<long long>>& dp, const vector<long long>& a)
{
    if (l >= r) return dp[l][r] = 0;
    if (flag[l][r]) return dp[l][r];

    long long res = max(a[l] - dp_table(l + 1, r, flag, dp, a),
                        a[r - 1] - dp_table(l, r - 1, flag, dp, a));
    flag[l][r] = true;
    return dp[l][r] = res;
}
int main()
{
    int n;
    cin >> n;
    vector<long long> a(n);
    for (int i = 0; i < n; i++) { cin >> a[i]; }
    vector<vector<bool>> flag(n, vector<bool>(n, false));
    vector<vector<long long>> dp(n + 1, vector<long long>(n + 1));
    cout << dp_table(0, n, flag, dp, a) << endl;
    return 0;
}

Measured memory_bytes: 72192
#include <bits/stdc++.h>
using namespace std;
const int N=2e5+20;
int a[N],n;
int main()
{
	while(cin>>n)
	{
		int mx=0,mn=1e5;
		for(int i=1;i<=n;i++)
			scanf("%d",&a[i]),mx=max(mx,a[i]),mn=min(mn,a[i]);
		if(mx==mn)
		{
			if(a[1]==n-1||2*a[1]<=n)
				puts("Yes");
			else
				puts("No");
		}
		else if(mx-mn==1)
		{
			int x=0,y=0,A=mx;
			for(int i=1;i<=n;i++)
			{
				if(a[i]==mn)
					x++;
				if(a[i]==mx)
					y++;
			}
			if(A>=x+1&&A<=x+y/2)
				puts("Yes");
			else
				puts("No");
		}	
		else
			puts("No");
	}
	return 0;	
} 

Measured memory_bytes: 640
#!/usr/bin/env python
# -*- coding: utf-8 -*-

a, b, c = map(int, raw_input().split())
for i in range(10000):
	if a % 2 == 1 or b % 2 == 1 or c % 2 == 1:
		print(i)
		quit()
	a, b, c = b / 2 + c / 2, a / 2 + c / 2, a / 2 + b / 2
print(-1) 

Measured memory_bytes: 2948
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<string>
typedef long long ll;
typedef unsigned long long ull;
const ll LINF = 1e18;
const int INF = 1e8;
using namespace std;


//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()		
#define debug system("pause")				//デバッグ用


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

	int n;
	cin >> n;

	vector<int> a(n);
	vector<int> b(n);

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

	int cost = 0;

	for (int i = 0; i < n; i++)
	{
		if (a[i] - b[i] > 0)
		{
			cost += a[i] - b[i];
		}
	}

	cout << cost << endl;

}

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

int main() {
  string s, t;
  cin >> s >> t;

  int count = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s.at(i) != t.at(i)) {
      count++;
    }
  }

  cout << count << endl;

  return 0;
}


Measured memory_bytes: 3916
#include<iostream>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include <algorithm>
#include <set>
#include<math.h>
#include<cmath>
#include<vector>
#include<map>
#include<random>
using namespace std;

int main(){
    int N,M;
    cin >> N >> M;
    int total = (1900*M + (N-M)*100)*pow(2,M);
    cout << total << endl;


}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int dp[110][10010];
int main(){
    int N, W; cin >> N >> W;
    int v[110], w[110];
    for (int i = 0; i < N; i++) {
        cin >> v[i] >> w[i];
    }
    

    for (int i = 0; i < N; i++) {
        for (int j = 0; j <= W; j++) {
            if(j>=w[i]){
                dp[i+1][j] = max(dp[i][j], dp[i+1][j-w[i]]+v[i]);
            }
            dp[i+1][j] = max(dp[i+1][j], dp[i][j]);
        }
    }

    cout << dp[N][W] << endl;
    
    return 0;
}


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

int main()
{
  int n;
  cin >> n;
  set<int> s;
  for (int i = 0; i < n; i++)
  {
    int num;
    cin >> num;
    s.insert(num);
  }
  int ans = s.size();
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import numpy as np

N,M,X = list(map(int, input().split()))

C = []
for i in range(N):
    C.append(list(map(int, input().split())))

ans = 1000000000
found = False

for i in range(2 ** N):
    tmp = [0] * (M + 1)
    books = np.array(tmp)
    for j in range(N): 
        if ((i >> j) & 1):
            books = books + np.array(C[j])

    skill_good = True
    for k in range(1,M+1):
        if books[k] < X:
            skill_good = False

    if books[0] < ans and skill_good:
        ans = books[0]
        found = True

if found:
    print(ans)
else:
    print(-1)
    


Measured memory_bytes: 27232
#include<iostream>
using namespace std;
typedef long long ll;
#define fr(i,n) for(int i=0;i<n;i++)

int main(){
  ll n,p,a[20010],b[20010];
  cin>>n;
  fr(i,n){
    cin>>p;
    a[--p]=i;
    b[p]=i;
  }
  fr(i,n) cout<<a[i]+1+i*n<<" ";
  cout<<endl;
  fr(i,n) cout<<b[i]+1+(n-1-i)*n<<" ";
  cout<<endl;
}

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

using namespace std;

long long v[110];
long long dp[110][100010];
long long prefix[110][100010];
const int mod = 1e9 + 7;

int main() {
    
    int n,k;
    scanf("%d %d", &n, &k);

    for (int i = 1; i <= n; ++i)
        scanf("%lld", v + i);
    
    for (int i = 0; i <= n; ++i)
        dp[i][0] = prefix[i][0] = 1;

    for (int i = 0; i <= k; ++i)
        prefix[0][i] = 1;
    
    
    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= k; ++j) {
            dp[i][j] += (prefix[i - 1][j] - (j - v[i] - 1 >= 0 ? prefix[i - 1][j - v[i] - 1] : 0) + mod) % mod;
            dp[i][j] %= mod;
            prefix[i][j] = prefix[i][j - 1] + dp[i][j];
            prefix[i][j] %= mod;
        }
   

    printf("%lld\n", dp[n][k]);
    return 0;
}


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

int main()
{
    int N; cin >> N;
    int H[N];
    for(int i = 0; i < N; ++i) {
        cin >> H[i];
    }
    int max = 0;
    int cnt = 0;
    for(int i = 0; i < N; ++i) {
        if(H[i] >= max) {
            max = H[i];
            cnt++;
        }
    }
    cout << cnt << "\n";
    return 0;
}


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

long long dp[100];

int main()
{
        dp[0]=2;
        dp[1]=1;

        for(int i=2;i<100;i++) dp[i] = dp[i-1] + dp[i-2];

        int n;
        cin>>n;
        cout<<dp[n]<<"\n";

        return 0;
}


Measured memory_bytes: 256
def main():
    n = int(input())
    dp = [-1 for _ in range(n)]
    for _ in range(n):
        x = int(input()) - 1
        if x > 0 and dp[x - 1] != -1:
            dp[x] = dp[x - 1] + 1
        else:
            dp[x] = 1
    print(n - max(dp))

main()


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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i = 0; i < n; ++i) cin >> a[i];

  bool isDenied = false;
  for(vector<int>::iterator it = a.begin(); it != a.end(); ++it) {
    if( (((*it) % 2) == 0) && ( (((*it) % 3) != 0) && (((*it) % 5) != 0) )) {
      isDenied = true;
      break;
    }
  }
  cout << (isDenied ? "DENIED" : "APPROVED") << endl;
  return 0;
}

Measured memory_bytes: 256
//
//  main.cpp
//  ProgrammingContestChallengeBook2
//
//  Created by Hisaki Kobayashi on 2020/04/04.
//  Copyright © 2020 Hisaki Kobayashi. All rights reserved.
//

#include <iostream>
#include <stdio.h>
#include <string>
#include <bits/stdc++.h>
#include <stdlib.h>
//#include "mylibrary.hpp"



using namespace std;

int main(){
    int N,R;
    cin >> N >> R;
    int ANS;
    if(N>=10){
        ANS = R;
    }else{
        ANS = R+100*(10-N);
    }
    cout << ANS << endl;
    return 0;
 
}


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

using namespace std;
using ll = long long;
using vl = vector<ll>;
using pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0, xxx_rep_end = (n); i < xxx_rep_end; ++i)
#define all(x) (x).begin(), (x).end()

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

constexpr ll INF = 0x3f3f3f3f3f3f3f3fLL;
constexpr ll mod = 1000000007;

int main() {
    ll K;
    string S;
    cin >> K >> S;
    if (S.size() <= K) {
        cout << S << endl;
    } else {
        rep(i, K) { cout << S[i]; }
        cout << "..." << endl;
    }
}

Measured memory_bytes: 3624
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>

using namespace std;
using ll = long long int;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i, a, b)  for(int i = (a); i < (b) ; i++)
#define pb push_back
#define SORT(v,n) sort(v, v+n)
#define ALL(x) (x).begin(),(x).end()
#define debug(x) cerr << #x << ": " << x << '\n'
#define elif else if
#define itn ll
#define int ll
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
///                →,↑,←,↓,↗,↖,↙,↘
int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };

int left(int i) {
	return i * 2;
}
int right(int i) {
	return i * 2 + 1;
}
int parent(int i) {
	return i / 2;
}

int A[2000000];
int h;
#define INFTY (1<<30)

void maxHeapify(int i) {
	int l = left(i);
	int r = right(i);
	int largest;
	if (l <= h && A[i] < A[l])
		largest = l;
	else
		largest = i;
	if (r <= h && A[largest] < A[r])
		largest = r;
	if (largest != i) {
		swap(A[largest], A[i]);
		maxHeapify(largest);
	}
}

void buildMaxHeap() {
	for (int i = h / 2; i >= 1; i--) {
		maxHeapify(i);
	}
}

void increaseKey(int i,int key) {
	if (A[i] > key)
		return;
	A[i] = key;
	while(i > 1 && A[parent(i)] < key){
		swap(A[parent(i)], A[i]);
		i = parent(i);
	}
}

void insert(int key) {
	h++;
	A[h] = -INFTY;
	increaseKey(h,key);
}

int HeapExtractMax() {
	int max;
	if (h < 1)
		return -INFTY;
	max = A[1];
	A[1] = A[h--];
	maxHeapify(1);
	return max;
}

signed main() {
	int i;
	while (true) {
		string com;
		cin >> com;
		if (com == "end")
			break;
		if (com == "insert") {
			int k;
			cin >> k;
			insert(k);
		}
		if (com == "extract") {
			cout << HeapExtractMax() << endl;;
		}
	}
	return 0;
}


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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
ll N, K, A[555],B[555],Bl[555],Br[555], Asum;
ll i,j,k,ans;

bool ck(ll a){
    ll i;
    fornum(i,0,N){
        B[i] = A[i] % a;
    }
    sort(B, B + N);
    Bl[0] = 0;
    Br[N] = 0;
    fornum(i,0,N){
        Bl[i + 1] = Bl[i] + B[i];
        Br[N - i - 1] = Br[N - i] + (a-B[N - i - 1]);
    }
    fornum(i,0,N){
        //ll b = Bl[i] + Br[i];
        
        if(max(Bl[i],Br[i])<=K&&Bl[i]%a==Br[i]%a){
            return true;
        }
    }
    return false;
}

int main(){
    scanf("%lld%lld", &N,&K);
    fornum(i,0,N){
        scanf("%lld", &A[i]);
        Asum += A[i];
    }
    for (j = 0; j * j <= Asum;j++)
        ;
    fornum(i,0,j){
        if(Asum%(i+1)==0){
            if(ck(i+1))
                ans = i + 1;
            if(ck(Asum/(i+1))){
                ans = Asum/(i+1);
                break;
            }
        }
    }
    printf("%lld", ans);

    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	C
# CreatedDate:  2020-09-04 13:28:04 +0900
# LastModified: 2020-09-04 13:47:38 +0900
#


import os
import sys
# import numpy as np
# import pandas as pd


def main():
    n = int(input())
    b = list(map(int, input().split()))
    if n == 1:
        print(b[0]*2)
        return
    a = [-float('inf')]*n
    a[0] = b[0]
    a[1] = b[0]
    for i in range(1, n-1):
        if a[i] > b[i]:
            a[i] = b[i]
        a[i+1] = b[i]
    print(sum(a))



if __name__ == "__main__":
    main()


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

typedef long long LL;

const int N=1000000;

map<int,int>mp[2];

int n,cq,vis[2][N+9];

void work(){
  scanf("%d%d",&n,&cq);
  mp[0][n]=mp[1][n]=n;
  LL ans=(LL)(n-2)*(n-2);
  for (int i=1;i<=cq;++i){
	int opt,x;
	scanf("%d%d",&opt,&x);--opt;
	if (vis[opt][x]) continue;
	vis[opt][x]=1;
	map<int,int>::iterator it=mp[opt^1].lower_bound(x);
	int t=it->second-1;
	//printf("%d   %d\n",t,x);
	ans-=t-1;
	if (mp[opt][t]) mp[opt][t]=min(mp[opt][t],x);
	else mp[opt][t]=x;
  }
  printf("%lld\n",ans);
}

int main(){
  int T=1;
  for (;T--;) work();
  return 0;
}

Measured memory_bytes: 9080
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0; i<n; ++i)
        cin >> a[i];
    sort(a.rbegin(), a.rend());

    long long ans = 0;
    for(int i=0; i<n-1; ++i)
        ans += a[(i+1)/2];
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3960
#include <stdio.h>
#include<stdlib.h>
int main() {
	int n;
	scanf("%d", &n);
	int *a = NULL;
	a = (int *)malloc(sizeof(int)*n);
	int i;
	for (i = 0; i < n; i++)
		scanf("%d", &a[i]);
	int x=0, y=0;
	for (i = 0; i < n; i++)
	{
		 if (a[i] % 4 == 0) x++;
		 else if (a[i] % 2 == 1) y++;
	}
	if ((x + y) == n) x++;
	if (x >= y) printf("Yes");
	else printf("No");
	free(a);
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long       ll;
#define MOD ((int)1e9+7)
#define N ((int)2e5+123)
void reads(string& x){ char kk[N]; scanf("%s",kk); x = kk;}

int ans;
char n;
void solve(){
    scanf("%c", &n);
    //printf("%d %d",'a','A');
    if(n>='a'){
        printf("a\n");
    }
    else{
        printf("A\n");
    }
}

int main(){
    ios_base::sync_with_stdio(0);
    int t = 1; //scanf("%d",&t);
    for(int caso=1;caso<=t;caso++){
        solve();
    }
}

Measured memory_bytes: 3716
//
//  main.cpp
//  AOJ1187
//
//  Created by aki33524 on 2014/07/07.
//  Copyright (c) 2014年 aki33524. All rights reserved.
//

#include <iostream>
#include <string.h>
#include <algorithm>
using namespace std;

typedef struct {int m, t, p; bool ac;} Submit;

typedef struct _Team{
    int solved, penalty[20], alltime, id;
    
    bool operator<(const _Team& right) const{
        return (solved < right.solved) || (solved == right.solved && alltime > right.alltime) || (solved == right.solved && alltime == right.alltime && id < right.id);
    }
    bool operator==(const _Team& right) const{
        return solved == right.solved && alltime == right.alltime;
    }
    
} Team;

int M, T, P, R;

Submit submits[3000];
Team teams[60];

void solve(){
    memset(teams, 0, sizeof(teams));
    for(int t=0; t<T; t++)
        teams[t].id = t+1;
    
    for(int r=0; r<R; r++){
        Submit &submit = submits[r];
        Team &team = teams[submit.t];
        
        if(submit.ac){
            team.solved++;
            team.alltime += team.penalty[submit.p] + submit.m;
        }else{
            team.penalty[submit.p] += 20;
        }
    }
    
    sort(teams, teams+T);
    
    for(int t=T-1; 0<=t; t--){
        Team &team = teams[t];
        if(0<t){
            cout << team.id;
            cout << (team==teams[t-1] ? "=" : ",");
        }else{
            cout << team.id << endl;
        }
    }
}

int main(int argc, const char * argv[])
{
    while(cin>>M>>T>>P>>R, M|T|P|R){
        for(int r=0; r<R; r++){
            Submit &s = submits[r];
            int m, t, p, j;
            cin>>m>>t>>p>>j;
            s.m = m;
            s.t = t-1;
            s.p = p-1;
            s.ac = j==0;
        }
        solve();
    }
    
    return 0;
}

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

int main() {
	int i,j,n,a,b,c,d,e,f,g,m[5050];
	while(cin >> n) {
		if (n==0) break;
		for (j=0;j<5050;j++) m[j]=0; d=1;
		for (i=0;i<n;i++) {
			cin >> a >> b >> c;
			f=a >1 ? 1 << (c-1) : ((1 << b)-1)  << (c-1);  
			for (j=d;j>=0;j--) if ( m[j]+f != (m[j] | f)) break;
			e=g=j+1; 
			if (a==1) { m[e]+=f; d++;}  else for (j=0;j<b;j++) { m[e+j]+=f; d++;}
			for (j=g; j<d+5; j++) if (m[j]<31) m[e++]=m[j]; 
		}
		f=0;
		for (i=0;i<5050;i++) for (j=0;j<5;j++) f+=(m[i] & ( 1 << j))>0;
		cout << f << endl;
	}
	return 0;
}

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

using namespace std;

int main() {
	int a, b;
	cin >> a >> b;

	for (int i = 1; i <= 2000; i++) {
		if (floor(i * 0.08) == a && floor(i * 0.1) == b) {
			cout << i;
			return 0;
		}
	}

	cout << -1;
}

Measured memory_bytes: 256
import java.util.*;
import java.util.Scanner;
import java.lang.*;

public class Main
{
  public static void main(String args[])
  {
    try
    {
    int n,rem=0,res=0;
    Scanner s=new Scanner(System.in);
    n=s.nextInt();
    rem=n%1000;
    if(rem!=0)
    {
       res=1000-rem;
    }
    System.out.println(res);
    }
    catch(Exception e)
    {
      return ;
    }
  }
}
      
   
    

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

#define REP(i, n) for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n) for (ll (i) = m ; (i) < (ll)(n) ; ++(i))
#define REP_REV(i, n) for (ll (i) = (ll)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (ll (i) = (ll)(n) - 1 ; (i) >= m ; --(i))

#define INF             2e9
#define INF_LL          1LL<<60
#define ll              long long
#define Ceil(x, n)      (((((x))+((n)-1))/n))
#define CeilN(x, n)     (((((x))+((n)-1))/n)*n)
#define FloorN(x, n)    ((x)-(x)%(n))
#define ALL(x)          (x).begin(),(x).end()
typedef pair<ll, ll>    P;

int main() {
    ll a, b, c, k;
    cin >> a >> b >> c >> k;

    if(k % 2 == 0) {
        cout << a - b << endl;
    } else {
        cout << b - a << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
public class Main {
	public static void main (String[] args){
	Scanner sc=new Scanner(new InputStreamReader(System.in));
	while(true){
	int a=sc.nextInt();
	String op=sc.next();
	int b=sc.nextInt();
	if(op.equals("?")) break;
	else if(op.equals("+")){
		System.out.println(a+b);
	}else if(op.equals("-")){
		System.out.println(a-b);
	}else if(op.equals("*")){
		System.out.println(a*b);
	}else if(op.equals("/")){
		System.out.println(a/b);
	}
	}
	sc.close();
	}
}

Measured memory_bytes: 26336
#include <iostream>
#include <vector>
#include <tuple>

int main(){
  int N,K,Q;
  std::cin >> N >> K >> Q;

  std::vector<int> a_arr(N, K-Q);
  for(int i = 0; i < Q; i++){
    int A;
    std::cin >> A;
    A--;
    a_arr[A]++;
  }

  for(int i = 0; i < N; i++){
    if(a_arr[i] > 0) std::cout << "Yes\n";
    else std::cout << "No\n";
  }

  return 0;
}



Measured memory_bytes: 1024
import Control.Applicative
import Control.Monad
import Data.List

main :: IO ()
main = do
    x <- readLn :: IO Int
    let (q, r) = x `divMod` 11
    case () of
        _ | r == 0    -> print $ q * 2
          | r <= 6    -> print $ q * 2 + 1
          | otherwise -> print $ q * 2 + 2

Measured memory_bytes: 508
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 result = (B%A) !=0 ? B-A : A+B;
        System.out.println(result);
    }
}

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

int N, Q;
int L;
vector<int> x = {0};
int memo[20][100010];

void build(){
    for(int i = 1; i <= N + 1; i++){
        memo[0][i] = (upper_bound(x.begin(), x.end(), x[i] + L) - x.begin()) - 1;
    }

    for(int i = 0; i < 19; i++){
        for(int j = 1; j <= N + 1; j++){
            memo[i + 1][j] = memo[i][memo[i][j]];
        }
    }
}

int solve(int a, int b){
    int res = 0;
    for(int i = 0; i < 20; i++){
        if(memo[i][a] == b){
            res = 1 << i;
            break;
        }
        if(memo[i][a] > b){
            if(i != 0){
                res += 1 << (i - 1);
                res += solve(memo[i - 1][a], b);
            }else{
                res = 1;
            }
            break;
        }
    }
    return res;
}

int main(){
    cin >> N;
    x.resize(N + 1, 0);
    for(int i = 1; i <= N; i++){
        cin >> x[i];
    }
    x.push_back(x[N] + L);
    cin >> L;

    build();

    cin >> Q;
    for(int i = 0; i < Q; i++){
        int a, b;
        cin >> a >> b;
        cout << solve(min(a, b), max(a, b)) << endl;
    }
    return 0;
}


Measured memory_bytes: 9080
#include <bits/stdc++.h>
#define itn int
#define REP(i, n) for (ll i = 0; i < n; i++)
#define IREP(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define all(v) v.begin(), v.end()
#define SENTINEL 2000000000
#define NIL -1
using namespace std;
typedef long long ll;


const ll MAX = 510000;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
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(ll x)
{
    int n;cin >> n;
    vector<ll> l(n);
    REP(i,n){
        cin >> l[i];
    }
    int ans=0;
    REP(i,n){
        FOR(j,i+1,n){
            FOR(k,j+1,n){
                if(l[i]!=l[j]&&l[i]!=l[k]&&l[j]!=l[k]){
                    if (l[i] + l[j] > l[k] && l[i] + l[k] > l[j] && l[j] + l[k] > l[i]){
                        ans++;
                    }
                }
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
void program(); int main() {cin.sync_with_stdio(0); cin.tie(0); cin.exceptions(cin.failbit); program();}
#define int long long
#define endl "\n"
#define all(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define vi vector<int>
#define pii pair<int,int>

#define MOD 1000000007
#define N 107
#define K 100007

int a[N], dp[N][K];

void program(){
    int n,k;
    cin>>n>>k;
    for(int i=0;i<n;i++)cin>>a[i];
    for(int c=0;c<=a[n-1];c++)dp[n-1][c] = 1;
    for(int i=n-2;i>=0;i--){
        int rs = 0;
        for(int c=0;c<=a[i];c++){
            rs = (rs + dp[i+1][c])%MOD;
            dp[i][c] = rs;
        }
        for(int c=a[i]+1;c<K;c++){
            rs = (rs + dp[i+1][c])%MOD;
            rs = (rs - dp[i+1][c-a[i]-1] + MOD)%MOD;
            dp[i][c] = rs;
        }
    }
    cout<<dp[0][k]<<endl;
}

/*
WA:
-bounds on loops
-truncating
-intialization
-0 vs 1 indexing

TLE:
-might need unordered_set/map
-infinite while loop

Stuck:
-different perspective?
-bruteforce?
-greedy?
-reduce dimensionality with problem contraints?
*/


Measured memory_bytes: 80128
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	static boolean[] isPrime=new boolean[12997090];
	static{
		Arrays.fill(isPrime,true);
		isPrime[0]=isPrime[1]=false;
		for(int i = 2;i*i<=isPrime.length;i++){
			if(isPrime[i]){
				for(int j = i+i;j<isPrime.length;j+=i){
					isPrime[j]=false;
				}
			}
		}
		
	}
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		while(true){
			int N =cin.nextInt();
			if(N==0){
				break;
			}
			int min,max;
			min=max=N;
			for(;max<isPrime.length;max++){
				if(isPrime[max]){
					break;
				}
			}
			for(;min>0;min--){
				if(isPrime[min]){
					break;
				}
			}
			System.out.println(max-min);
		}

	}

}

Measured memory_bytes: 25000
#include <bits/stdc++.h>
using namespace std;
// ----------------------R00TDADA------------------------------
#define rep(i, a, b) for (__typeof((b)) i = (a); i < (b); i++)
#define nrep(i, a, b) for (__typeof((b)) i = (a); i > (b); i--)
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
#define ppi pair<int, int>
#define pppi pair<ppi, int>
#define vi vector<int>
#define vii vector<ppi>
#define viii vector<pppi>
#define vs vector<string>
#define pb push_back
#define bitcount __builtin_popcount //count no's of ones in a set bit
#define prq priority_queue
#define mp make_pair
#define mem(x, val) memset((x), (val), sizeof(x));
#define sz(x) (int)x.size()
#define M_PI 3.14159265358979323846
#define rootdada                      \
    ios_base::sync_with_stdio(false); \
    cin.tie(0);                       \
    cout.tie(0);
#define test  \
    int t;    \
    cin >> t; \
    while (t--)
#define int long long
#define M 1000000007
signed main()
{
    rootdada;
    // #ifndef ONLINE_JUDGE
    // // for getting input from input.txt
    // freopen("input.txt", "r", stdin);
    // // for writing output to output.txt
    // freopen("output.txt", "w", stdout);
    // #endif
    int x;
    cin >> x;
    int ans = 0;
    int y = x / 500;
    int z = x % 500;
    ans += y * 1000;
    int l = z / 5;
    int r = z % 5;
    ans += l * 5;
    cout << ans << endl;
}

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

char s[2000];
vector<string>ans;

int main() {
	gets(s);
	char*split;
	split = strtok(s, " ,.");
	do {
		if (3 <= strlen(split) && strlen(split) <= 6)
			ans.push_back(string(split));
	} while (split = strtok(NULL, " ,."), split);
	rep(i, ans.size()) {
		cout << ans[i] << (i == ans.size() - 1 ? '\n' : ' ');
	}
	return 0;
}

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

int N;
int V[30];
int C[30];

int main(){
  cin >> N;
  rep(i, N) cin >> V[i];
  rep(i, N) cin >> C[i];
  int ans = 0;
  rep(i, N){
    if (V[i] - C[i] > 0) ans += V[i] - C[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 3496
#include <bits/stdc++.h>
using namespace std;
 int main(){
     int n,k;
     cin >> n >> k;
     vector<int> p(n);
    for(int i=0;i<n;i++){
        cin >> p.at(i);
    } 
    sort(p.begin(),p.end());
    int sum=0;
    for(int i=0;i<k;i++){
     sum+=p.at(i);
    }
    cout << sum << endl;
 }

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

int main(){
    int x[6];
    for(int i=1;i<=5;i++){
    cin >> x[i];
    }
    for(int i=1;i<=5;i++){
     if(x[i] == 0){
         cout << i << endl;
        return 0;
     }
    }
    
}

Measured memory_bytes: 3628
using System;
using System.Collections.Generic;
using System.Linq;

namespace CSharpSample01
{
	class Program
	{
		public class Value
		{
			public long money { get; set; }
			public List<long> skill { get; set; }
		}

		static void Main(string[] args)
		{
			var inputNum = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();

			var N = inputNum[0];
			var M = inputNum[1];
			var X = inputNum[2];

			var valueList = new List<Value>();
			
			// 整数を格納するキュー
			var que = new Queue<Value>();
			var nextQue = new Queue<Value>();

			for (int i = 0;i < N; i++)
			{ 
				que = nextQue;
				nextQue = new Queue<Value>();

				var inputSkillNum = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

				if (que.Any())
				{
					// キューから全てを取り出す
					while (que.Count > 0)
					{
						var value = que.Dequeue();

						var newValue = new Value();

						newValue.money = value.money + inputSkillNum[0];
						newValue.skill = new List<long>();
						for (int x = 0; x < M; x++)
						{
							newValue.skill.Add(value.skill[x] + inputSkillNum[x + 1]);
						}
						nextQue.Enqueue(newValue);
						nextQue.Enqueue(value);
					}
					/*					foreach (var value in valueList)
										{
											var newValue = new Value();

											newValue.money = value.money + inputSkillNum[0];
											newValue.skill = new List<int>();
											for(int x = 0; x < M; x++)
											{
												newValue.skill.Add(value.skill[x] + inputSkillNum[x + 1]);
											}
											valueList.Add(newValue);
										}
					*/
				}

				var addValue = new Value();
				addValue.skill = new List<long>();
				addValue.money = inputSkillNum[0];
				for (int x = 0; x < M; x++)
				{
					addValue.skill.Add(inputSkillNum[x + 1]);
				}

				nextQue.Enqueue(addValue);
			}

			var flag = false;
			var first = true;
			long answer = 0;
			while (nextQue.Count > 0)
			{
				var targetValue = nextQue.Dequeue();

				if(targetValue.skill.All(x => x >= X))
				{
					flag = true;
					if (first)
					{
						first = false;
						answer = targetValue.money;
					}
					if(answer > targetValue.money)
						answer = targetValue.money;
				}
			}

			if (flag)
			{
				Console.WriteLine(answer);
			}
			else
			{

				Console.WriteLine(-1);
			}



		}
	}
}

Measured memory_bytes: 30004
#include <iostream>
using namespace std;
int main(){
    int d;
    cin >> d;
    int last[26] = {0};
    int s[d][26] , c[26];
    for (int i = 0 ; i < 26 ; i++)
        cin >> c[i];
    for (int i = 0 ; i < d ; i++){
        for (int j = 0 ; j < 26 ; j++)
            cin >> s[i][j];
    }
    for (int i = 0 ; i < d ; i++){
        int maks = -2e9 , idx;
        for (int j = 0 ; j < 26 ; j++){
            int nilai = s[i][j] - c[j] * (i - last[j]);
            if (nilai > maks)
                maks = nilai,
                idx = j;
        }
        last[idx] = i + 1;
        cout << idx + 1 << endl;
    }
}


Measured memory_bytes: 3712
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <map>
#define N 100005
using namespace std;
typedef long long ll;
const ll mod = 1000000007LL;
ll x,y;
int main() {
  cin>>x>>y;
  if(abs(x-y)<=1) {
  	cout<<"Brown"<<endl;
  } else {
  	cout<<"Alice"<<endl;
  }
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
/* テンプレートここまで */

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

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

  //隣接リスト
  vector<vector<int>> edge(N);
  //入次数を管理
  vector<int> indeg(N, 0);

  REP(i, M){
    int x,y;
    cin >> x >> y;
    x--; y--;
    edge[x].push_back(y);
    indeg[y]++;
  }

  //入次数0のノード集合
  stack<int> st;
  REP(i, N) if(indeg[i] == 0) st.push(i);

  //トポロジカルソートしつつdpテーブル更新
  //dp[i] = ノードiを始点とした有向パスの長さの最大値
  vector<int> dp(N);
  while(st.size()){
    int i = st.top(); st.pop();
    FOREACH(j, edge[i]){
      indeg[j]--;
      chmax(dp[j], dp[i] + 1);
      if(indeg[j] == 0) st.push(j);
    }
  }

  cout << *max_element(ALL(dp)) << endl;
}


Measured memory_bytes: 6528
//#include "stdafx.h"
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <functional>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <tuple>
#include <numeric>
#include <assert.h>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#define REP(i, n)				for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n)			for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define INF						2e9
#define MOD						(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)				(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)				(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)			((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)				(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)				(!IsOdd((x)))						
#define	BitSetV(Val,Bit)		((Val) |= (Bit))			
#define	BitTstV(Val,Bit)		((Val) & (Bit))				
#define ArrayLength(x)			(sizeof( x ) / sizeof( x[ 0 ]))
#define MAX_DWORD				(0xFFFFFFFF)
#define	MAX_SDWORD				((SDWORD)0x7FFFFFFF)
#define	MIN_SDWORD				((SDWORD)0x80000000)
#define	MAX_QWORD				((QWORD)0xFFFFFFFFFFFFFFFF)
#define	MIN_QWORD				((QWORD)0x0000000000000000)
#define	MAX_SQWORD				((SQWORD)0x7FFFFFFFFFFFFFFF)
#define	MIN_SQWORD				((SQWORD)0x8000000000000000)
#define M_PI					3.14159265358979323846

typedef long					SDWORD;
typedef long long				SQWORD;
typedef unsigned long			DWORD;
typedef unsigned long long int	QWORD;
typedef long long ll;
typedef pair<ll, ll>			P;

/*-----------------------------------------------------------------------------
　処理
 -------------------------------------------------------------------------------*/
#define N_MAX	(200 * 1000)
#define K_MAX	(10)
#define M_MAX	(10)
#define Q_MAX	(10)
#define H_MAX	(1000)
#define W_MAX	(1000)

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

	int ans = 0;
	int nowCnt = 1;
	int nextCnt = 0;
	char nowChar = S[0];
	for (int i = 1; i < S.size(); ) {
		for (; i < S.size(); i++) {
			if (nowChar != S[i]) {
				break;
			}
			nowCnt++;
		}

		for (; i < S.size(); i++) {
			if (nowChar == S[i]) {
				break;
			}
			nextCnt++;
		}

		int delNum = min(nowCnt, nextCnt);
		ans += (delNum * 2);
		nowCnt -= delNum;
		nextCnt -= delNum;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 512
# E - Flatten

n = int(input())
a = list(map(int, input().split()))
assert len(a) == n

modulus = 10 ** 9 + 7
binmod = (bin(modulus - 2))[2:]  # modulus - 2 in binary

MAX = 10 ** 6

def factorize(x):
    vec = {}
    d = 2
    while d * d <= x:
        if x % d == 0:
            if d not in vec:
                vec[d] = 0
            vec[d] += 1
            x //= d
        else:
            d += 1
    if x > 1:
        if x not in vec:
            vec[x] = 0
        vec[x] += 1
    return vec

def value(x):
    p = 1
    for i in x:
        p = (p * (i ** x[i])) % modulus
    return p

def inverse(x):
    p = 1
    for b in binmod:
        p = p * p % modulus
        if b == '1':
            p = p * x % modulus
    return p

def div(n, d):
    return n * inverse(d) % modulus

l = {}
for x in a:
    f = factorize(x)
    for k in f:
        l[k] = max(l[k], f[k]) if k in l else f[k]
lcm = value(l)

s = sum(div(lcm, x) for x in a) % modulus
print(s)


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

l = L % 2019
r = R % 2019

lst = []
if (R - L >= 2019):
  print(0)
else:
  for i in range(L, R):
    for j in range(i+1, R+1):
      lst.append((i * j) % 2019)
  print(min(lst))
    

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

int main() {
  int N;
  string A,B,C;
  int cnt[100];
  for ( int i = 0; i < 100; i++ ) cnt[i] = 0;
    
  cin >> N >> A >> B >> C;
  for ( int i = 0; i < N; i++ ) {
    if (A[i] == B[i] ) cnt[i]++;
    if (B[i] == C[i] ) cnt[i]++;
    if (C[i] == A[i] ) cnt[i]++;
  }
  int ans = 0;
  for ( int i = 0; i < N; i++ ) {
    if ( cnt[i] == 1 ) ans++;
    else if ( cnt[i] == 0 ) ans += 2;
  }
  cout << ans << endl;
  return 0;
}


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

// #define int ll
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using si = set<int>;
using ii = pair<int, int>;
using vii = vector<ii>;

#define rep(i, n) for (int i = 0; i < n; i++)
#define dotc()    int tcs; if (cin >> tcs) rep(tc, tcs)
#define sz(x)     (int)x.size()
#define eb        emplace_back
#define pb        push_back
#define mp        make_pair
#define all(x)    x.begin(), x.end()
#define rall(x)   x.rbegin(), x.rend()
#define fi        first
#define se        second

int inf(0x3fffffff);
int mod(1000000007);
double pi(acos(-1.0));

int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
#ifdef LOCAL
  freopen("io\\in.txt", "r", stdin);
  freopen("io\\out.txt", "w", stdout);
#endif

  string s;
  int k0;
  cin >> s >> k0;

  vvi dp1(100, vi(4, -1)), dp2(100, vi(4, -1));
  function<int (int, int, bool)> count = [&](int i, int k, bool lim) {
    if (k == 0) return 1;
    if (i == sz(s)) return 0;

    int& ret = lim ? dp1[i][k] : dp2[i][k];
    if (ret == -1) {
      int cur = s[i] - '0';
      ret = 0;

      ret += count(i + 1, k, lim && cur == 0);

      if (lim) {
        if (cur != 0) {
          ret += (cur - 1) * count(i + 1, k - 1, false);
          ret += count(i + 1, k - 1, lim);
        }
      } else {
        ret += 9 * count(i + 1, k - 1, false);
      }

      // cout << i << ' ' << k << ' ' << lim << ' ' << ret << endl;
    }
    
    return ret;
  };
  cout << count(0, k0, true);

  return 0;
}


Measured memory_bytes: 3664