akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<int,int>;
/* ちゃんと考えてわかって実装 */

const ll mod = 1e9 + 7;

int main(void){
    ll n;
    cin >> n;

    vector<bool> isP(n+1);
    vector<ll> num(n+1);
    for(int i=0; i<=n; i++){
        isP[i] = true;
        num[i] = i;
    }
    isP[0] = false;
    isP[1] = false;

    vector<ll> prime;
    ll cnt = 0;
    for(int i=2; i<=n; i++){
        if(isP[i]){
            prime.push_back(i);
            cnt++;
            for(int j=2*i; j<=n; j+=i){
                isP[j] = false;
            }
        }
    }

    ll ans = 1;
    for(int i=0; i<cnt; i++){
        ll prm = prime[i];
        ll joo = 0;
        for(int j=2; j<=n; j++){
            if(num[j] % prm == 0){
                while(num[j] % prm == 0){
                    num[j] /= prm;
                    joo++;
                }
            }
        }
        joo %= mod;
        ans *= (joo+1);
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
const unsigned int MOD = 1000000007;
#define ll long long
#define PI 3.1416
string day[]={"SUN","MON","TUE","WED","THU","FRI","SAT"};
vector<string>v;
void dfs(string str,string t="",int cnt=0){
    if(cnt==2){
        v.push_back(t);
        return;
    }else{
        for(int i=0;i<str.size();i++){
            dfs(str,t+str[i],cnt+1);
        }
    }
}
int main(){
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int n;
    while(cin>>n){
        if(n%2==0)cout<<n<<endl;
        else cout<<n*2<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
N=(int)(input())
S=input()

ER=[]
WL=[]


w=0

for i in S:
    if i=='W':
        w+=1
    WL.append(w)

e=0

for i in reversed(S):
    if i=='E':
        e+=1
    ER.append(e)
    


result=N

for i in range(N):
    if i==0:
        result=min(result,ER[N-2])
    elif i==(N-1):
        result=min(result,WL[N-2])
    else:
        result=min(result,(ER[N-i-2]+WL[i-1]))
print(result)




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

#define INF (2 << 28)
#define fr first
#define sc second
using namespace std;

typedef long long ll;
typedef pair<int, int> iP;

struct result{
  int v, m, k, r;
  static bool judge(const result& l, const result& r1){
    return l.r > r1.r;
  }
};

int main(){
  
  int np[3];
  while(cin >> np[0] >> np[1] >> np[2], np[0]){
    int n; cin >> n;
    vector <int> parts(np[0] + np[1] + np[2] + 1, 2);
    vector <result> check(n);
    for(int i = 0; i < n; i++)
      cin >> check[i].v >> check[i].m >> check[i].k >> check[i].r;
    sort(check.begin(), check.end(), result::judge);
    
    for(int i = 0; i < n; i++){
      if(check[i].r)
         parts[check[i].v] = 1, parts[check[i].m] = 1, parts[check[i].k] = 1;
      else {
        int cnt = 0, idx = -1, c[3];
        c[0] = check[i].v, c[1] = check[i].m, c[2] = check[i].k;
        for(int i = 0; i < 3; i++){
          if(parts[c[i]] == 1) cnt++;
          else idx = c[i];
        }
        if(cnt == 2 && ~idx) parts[idx] = 0;
      }
    }
    for(int i = 1; i < parts.size(); i++)
      cout << parts[i] << endl;
  }
}

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

using namespace std;
const int maxn = 2e5+10;

int main(){
    int n,a[maxn];
    stack<int>q1,q2,q3;
    while(~scanf("%d",&n)){
        for(int i = 1;i <= n;i++)
            scanf("%d",&a[i]);
        while(!q1.empty()) q1.pop();
        while(!q2.empty()) q2.pop();
        while(!q3.empty()) q3.pop();
        for(int i = 2;i <= n;){
            if(i <= n)
                q1.push(a[i]),i++;
            if(i <= n)
                q2.push(a[i]),i++;
        }
        if(n&1){
            while(!q2.empty()){
                printf("%d ",q2.top());
                q2.pop();
            }
            printf("%d ",a[1]);
            while(!q1.empty()){
                q3.push(q1.top());
                q1.pop();
            }
            while(!q3.empty()){
                printf("%d ",q3.top());
                q3.pop();
            }
            puts("");

        }
        else{
            while(!q1.empty()){
                printf("%d ",q1.top());
                q1.pop();
            }
            printf("%d ",a[1]);
            while(!q2.empty()){
                q3.push(q2.top());
                q2.pop();
            }
            while(!q3.empty()){
                printf("%d ",q3.top());
                q3.pop();
            }
            puts("");
        }
    }
    return 0;
}


Measured memory_bytes: 3840
#pragma GCC optimize("O3")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld  double
#define pii pair<int,int>
#define pb push_back
#define N 200003
#define inf (ll)1e9+11
#define warmup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int mod=1e9+7;
ld pre[N];

signed main()
{
    warmup
    
    int n,k;
    cin>>n>>k;
    int x,i;
    pre[0]=0.0;
    for(i=1;i<=n;++i)
    {
        cin>>x;
        pre[i]=(x+1.0)/2.0 + pre[i-1];
    }   
    
    ld ma=0.0;
    for(i=k;i<=n;++i)
        ma=max(ma,pre[i]-pre[i-k]);
    
    cout.precision(7);
    cout<<ma;
    
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define FORR(i, a, b) for (int i = b - 1; i >= a; --i)
#define SORT(v) sort(v.begin(), v.end())
#define SORTR(v) sort(v.rbegin(), v.rend())
#define REV(v) reverse(v.begin(), v.end())
#define ITER(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define LB(v, x) (lower_bound(v.begin(), v.end(), x) - v.begin())
#define UB(v, x) (upper_bound(v.begin(), v.end(), x) - v.begin())
#define SZ(v) (int)v.size()
using namespace std;
using ll = long long;
using P = pair<int, int>;

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

	int a, b;
	cin >> a >> b;
	cout << a * b << endl;

	return 0;
}


Measured memory_bytes: 3648
import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
sys.setrecursionlimit(10**7)

A,B=list(map(int,input().split()))
C = math.gcd(A,B)

def factorization(n):
    arr = [[1,1]]
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    return arr

Cfac = factorization(C)
print(len(Cfac))


Measured memory_bytes: 27220
from copy import copy
import random
import math
import sys
input = sys.stdin.readline
D = int(input())
c = list(map(int,input().split()))
s = [list(map(int,input().split())) for _ in range(D)]
last = [0]*26
ans = [0]*D
score = 0
for i in range(D):
    ps = [0]*26
    for j in range(26):
        pl = copy(last)
        pl[j] = i+1
        ps[j] += s[i][j]
        for k in range(26):
            ps[j] -= c[k]*(i+1-pl[k])
    idx = ps.index(max(ps))
    last[idx] = i+1
    ans[i] = idx+1
    score += max(ps)
T = 300
for k in range(42000):
    na = copy(ans)
    x = random.randint(1,365)
    y = random.randint(1,365)
    if x == y:
        continue
    na[x-1],na[y-1] = na[y-1],na[x-1]
    last = [0]*26
    ns = 0
    for i in range(D):
        last[na[i]-1] = i+1
        ns += s[i][na[i]-1]
        for j in range(26):
            ns -= c[j]*(i+1-last[j])
    if k%80 == 0:
        T *= 0.99
    p = pow(math.e,-abs(ns-score)/T)
    if ns > score or random.random() < p:
        ans = na
        score = ns
for a in ans:
    print(a)

Measured memory_bytes: 89872
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

type Weight struct {
	value int
	count int
}

func main() {
	sc := bufio.NewScanner(os.Stdin)

	n := scanInt(sc)
	ns := make([]int, n)

	for i := 0; i < n; i++ {
		ns[i] = scanInt(sc)
	}

	sort.Ints(ns)
	if n == 2 {
		fmt.Println(ns[1] - ns[0])
		return
	}

	wss := make_weights(n)
	sums := make([]int, len(wss))

	var w int
	for _, m := range ns {
		for i, ws := range wss {
			w, wss[i] = consume_weight(ws)
			sums[i] += m * w
		}
	}

	max := 0
	for _, sum := range sums {
		if max < sum {
			max = sum
		}
	}

	fmt.Println(max)
}

func consume_weight(ws []Weight) (int, []Weight) {
	for ws[0].count == 0 {
		ws = ws[1:]
	}

	value := ws[0].value
	ws[0].count -= 1

	return value, ws
}

func make_weights(n int) [][]Weight {
	if n%2 == 0 {
		return [][]Weight{
			{
				{value: -2, count: (n - 2) / 2},
				{value: -1, count: 1},
				{value: 1, count: 1},
				{value: 2, count: (n - 2) / 2},
			},
		}
	}
	return [][]Weight{
		// /\/\../\
		{
			{value: -2, count: (n - 2) / 2},
			{value: -1, count: 2},
			{value: 2, count: (n-2)/2 + 1},
		},
		// \/\/..\/
		{
			{value: -2, count: (n-2)/2 + 1},
			{value: 1, count: 2},
			{value: 2, count: (n - 2) / 2},
		},
	}
}

func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	v, _ := strconv.Atoi(sc.Text())
	return v
}


Measured memory_bytes: 2944
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include <climits>
#include<fstream>
using namespace std;
//---------------------------------------------------
//library zone!!!!!
typedef long long ll;
typedef long double ld;
#define rep(i,j) for(ll i=0;i<(long long)(j);i++)
#define all(a) (a).begin(),(a).end()
const ll Mod = 1000000007;
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
};
bool operator<(E a, E b) {
	return a.cost < b.cost;
}
struct H {
	ll x, y;
};
bool operator<(H a, H b) {
	if (a.x != b.x) return a.x < b.x;
	return a.y < b.y;
}
bool operator>(H a, H b) {
	if (a.x != b.x) return a.x > b.x;
	return a.y > b.y;
}
bool operator==(H a, H b) {
	return a.x == b.x&&a.y == b.y;
}
bool operator!=(H a, H b) {
	return a.x != b.x || a.y != b.y;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j%i, i);
}
ld mod_pow(ld x, ll n, ll p) {
	ld res = 1;
	while (n > 0) {
		if (n & 1) res = res * x;
		x = x * x;
		n >>= 1;
	}
	return res;
}//x^n%p
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
int n, m;
int a[200000];
E b[200000];
vector<B>e[200000];
int f[200000];//この連結成分のダメな辺の数
int pa[200000];
int root(int x) {
	if (pa[x] == x) return x;
	return pa[x] = root(pa[x]);
}
void unite(int x, int y) {
	x = root(x); y = root(y);
	a[x] += a[y];
	f[x] += f[y];
	pa[y] = x;
}
signed main() {
	cin >> n >> m;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		pa[i] = i;
	}
	for (int i = 0; i < m; i++) {
		cin >> b[i].from >> b[i].to >> b[i].cost;
		b[i].from--; b[i].to--;
	}
	sort(b, b + m);
	for (int i = 0; i < m; i++) {
		int u1 = b[i].from, u2 = b[i].to;
		if (root(u1) != root(u2)) {
			unite(u1, u2);
			u1 = root(u1);
			if (a[u1] >= b[i].cost) f[u1] = 0;
			else f[u1]++;
		}
		else {
			if (a[root(u1)] < b[i].cost) f[root(u1)]++;
		}
	}
	cout << f[root(0)] << endl;
}

Measured memory_bytes: 10752
#include <bits/stdc++.h>
using namespace std;
const int INF = 2147483647;
using ll = long long;

int gcd(int a,int b){
    if(a<b) swap(a,b);
    int have_mod =true;
    while(have_mod){
        int mod = a % b;
        if(mod == 0 ) have_mod = false;
        a = b;
        b = mod;
    }
    return a;
}

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i=0;i<n;i++){
        cin >> a.at(i);
    }
    int num = a.at(0);
    for (int i=1;i<n;i++){
        num = gcd(num,a.at(i));
    }
    cout << num << endl;

    return 0;
}

Measured memory_bytes: 640
/*    _                     _     
  __| | _____   _____  ___| |__  
 / _` |/ _ \ \ / / _ \/ __| '_ \ 
| (_| |  __/\ V /  __/\__ \ | | |
 \__,_|\___| \_/ \___||___/_| |_|
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
#define faster       ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll          long long
#define pb          push_back
#define ppb         pop_back
#define  endl    '\n'
#define mii         map<ll int,ll int>
#define msi         map<string,ll int>
#define mis         map<ll int, string>
#define mpi         map<pair<ll int,ll int>,ll int>
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define vs          vector<string>
#define all(a)      (a).begin(),(a).end()
#define maxpq       priority_queue<ll>
#define minpq       priority_queue<ll, vector<ll>, greater<ll> >
#define F           first
#define S           second
#define rep(i,j,k)  for(int i=j;i<k;i++)
#define rrep(i,a,b)  for(ll i=a;i>=b;i--)
#define present(c,x) ((c).find(x) != (c).end())
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define what_is(x)  cout << #x << " is " << x << endl;
#define DECIMAL(n)  cout << fixed ; cout << setprecision(n);
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }


using namespace std;
using namespace __gnu_pbds;
 
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
#define N  100005

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}
 
vector<int> adj[N];
int in_degree[N];
int dis[N];
bool vis[N];
void dfs(int s){
	vis[s]=1;
	for(auto i:adj[s]){
		dis[i]=max(dis[i],dis[s]+1);
		--in_degree[i];
		
		if(in_degree[i]==0)dfs(i);
	}
}
int main(){
  faster
   int n,m;
   cin>>n>>m;
   rep(i,0,m){
   	int x,y;
   	cin>>x>>y;
   	adj[x].pb(y);
   	in_degree[y]++;
   }
   rep(i,1,n+1){
   	if(!vis[i] && in_degree[i]==0){
   		dfs(i);
   	}
   }
   int ans=INT_MIN;
   rep(i,1,n+1)ans=max(ans,dis[i]);
   cout<<ans<<endl;


  
}


 

Measured memory_bytes: 14504
#include<stdio.h>
int main()
{
    int i,n,x[10000];
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        x[i]=i+1;
    }
    for(i=0;i<n;i++)
    {
        if(x[i]%3==0)
        {
            printf(" %d",x[i]);
        }
        else if(x[i]%10==3)
        {
            printf(" %d",x[i]);
        }
        else if(29<(x[i]%100) && 40>(x[i]%100))
        {
            printf(" %d",x[i]);
        }
        else if(299<(x[i]%1000) && 400>(x[i]%1000))
        {
            printf(" %d",x[i]);
        }
        else if(2999<(x[i]%10000) && 4000>(x[i]%10000))
        {
            printf(" %d",x[i]);
        }
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 2100
parseInt(x) = parse(Int, x)
parseBigInt(x) = parse(BigInt, x)
parseFloat(x) = parse(Float64, x)
parseBigFloat(x) = parse(BigFloat, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    s=chomp(readline())
    if count(x->x=='o',s)+15-length(s)>=8
        println("YES")
    else
        println("NO")
    end
end
main()

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

int main(void){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    int a[n];
    for(int i=0; i<n; i++){
    	cin>>a[i];
	}
	int ans = 0;
	for(int i=0; i<n; i++){
		int count = 0;
		while(a[i]%2==0){
			a[i]/=2;
			count++;
		}
		ans+=count;
	}
	cout<<ans<<endl;
}

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

void solve(){
    ll H, N;
    cin >> H >> N;
    ll sum = 0;
    REP(i, N){
        ll Ai;
        cin >> Ai;
        sum += Ai;
    }

    if(H-sum > 0) cout << "No" << endl;
    else cout << "Yes" << endl;

}

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

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<bitset>
#include<string>
#include<cmath>
#include<algorithm>
#include<stack>
#include<list>
#include<queue>
#include<map>
#include<numeric>
using namespace std;
#define rep(i,x) for(int i=0;i<x;i++)
#define re(i,x,y) for(int i=x;i<y;i++)
int INF=1e9;
const long long mod=1e9+7;
typedef long long ll;
int main(){
    map<string,int>m;
    int q;
    cin>>q;
    while(q--){
        int t,y;
        string x;
        cin>>t;
        if(t==0){
            cin>>x>>y;
            m[x]=y;
        }
        if(t==1){
            cin>>x;
            cout<<m[x]<<endl;
        }
        if(t==2){
            cin>>x;
            m.erase(x);
        }
    }
    return 0;
}


Measured memory_bytes: 27820
N = int(input())
a = list(map(int, input().split()))
sum_a = 0
sum_b = 0

a.sort(reverse=True)

for i in range(len(a)):
  if i % 2 == 0:
    sum_a += a[i]
  else:
    sum_b += a[i]
print(sum_a - sum_b)


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

typedef long long ll;


int main(){
  stack<int> S;
  int a, b, x;
  string s;
  while(cin >> s){
    if(s[0] == '+'){
      a = S.top(); S.pop();
      b = S.top(); S.pop();
      S.push(a + b);
    }
    else if(s[0] =='-'){
      a = S.top(); S.pop();
      b = S.top(); S.pop();
      S.push(b - a);
    }
    else if(s[0] =='*'){
      a = S.top(); S.pop();
      b = S.top(); S.pop();
      S.push(a * b);
    }
    else{
      S.push(atoi(s.c_str()));
    }
  }
  cout << S.top() << endl;
}



Measured memory_bytes: 3188
n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]

ans = 0

for i in range(n):
    if b[i] >= a[i]:
        ans += a[i]
        b[i] -= a[i]
    else:
        ans += b[i]
        b[i] = 0

    if b[i] >= a[i+1]:
        ans += a[i+1]
        a[i+1] = 0
    else:
        ans += b[i]
        a[i+1] -= b[i]

print(ans)

Measured memory_bytes: 18624
def main():
    import math
    n,k = map(int,input().split())
    a = list(map(int,input().split()))
    def f(a,l):
        ans = 0
        for i in range(len(a)):
            ans += math.ceil(a[i]/l)-1
        return ans
    l,r = 1,max(a)
    while r-l>1:
        mid = (l+r)//2
        g = f(a,mid)
        if g>k:
            l = mid+1
        else:
            r = mid
    if f(a,l)<=k:
        print(l)
    else:
        print(r)

if __name__ == "__main__":
    main()


Measured memory_bytes: 31036
/*
 * @Author: clorf 
 * @Date: 2020-08-31 20:27:12 
 * @Last Modified by: clorf
 * @Last Modified time: 2020-08-31 21:35:03
 */
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<ctime>
#define INF 1e9
using namespace std;
const int maxn=200010;
const double Pi=acos(-1.0);
template<class T>void read(T &x)
{
    x=0;int f=0;char ch=getchar();
    while(ch<'0'||ch>'9') {f|=(ch=='-');ch=getchar();}
    while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
    x=f?-x:x;
    return;
}
int n,q,cnt;
int fa[maxn];
long long p[maxn],ans;
struct edge
{
    int x;
    int y;
    long long z;
}s[maxn],e[maxn<<1];
inline bool cmp(edge a,edge b)
{
    return a.z<b.z;
}
inline int sub(int x)
{
    return (x+1)%n;
}
int getfa(int x)
{
    if(fa[x]==x)
        return x;
    return fa[x]=getfa(fa[x]);
}
int main()
{
    memset(p,0x3f,sizeof(p));
    scanf("%d%d",&n,&q);
    for(int i=1;i<=q;i++)
    {
        scanf("%d%d%lld",&s[i].x,&s[i].y,&s[i].z);
        e[++cnt]=(edge){s[i].x,s[i].y,s[i].z};
        p[s[i].x]=min(p[s[i].x],s[i].z+1);
        p[s[i].y]=min(p[s[i].y],s[i].z+2);
    }
    int now=s[1].x,tot=2*n;
    long long sum=p[now];
    while(tot--)
    {
        if(sum<p[now])
            p[now]=sum;
        else
            sum=p[now];
        sum+=2;
        now=sub(now);
    }
    for(int i=0;i<n;i++)
        e[++cnt]=(edge){i,sub(i),p[i]};
    for(int i=0;i<=n;i++)
        fa[i]=i;
    sort(e+1,e+cnt+1,cmp);
    for(int i=1;i<=cnt;i++)
    {
        int x=getfa(e[i].x);
        int y=getfa(e[i].y);
        if(x!=y)
        {
            fa[x]=y;
            ans+=e[i].z;
        }
    }
    printf("%lld",ans);
    return 0;
}


Measured memory_bytes: 19632
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}

int main(){
    int n,k,c;
    cin >> n >> k >> c;
    string s; cin >> s;
    vector<int> f(n, -1), b(n, -1);
    for(int i = 0,cnt = 1; cnt <= k ; i++){
        if(s[i] == 'o'){
            f[i] = cnt;
            cnt++;
            i += c;
        }
    }
    for(int i = n-1,cnt = k; cnt >= 1 ; i--){
        if(s[i] == 'o'){
            b[i] = cnt;
            cnt--;
            i -= c;
        }
    }
    rep(i, n) if(f[i] != -1 && f[i] == b[i]) cout << i+1 << endl;
    return 0;
}


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

using namespace std;


int main() {
//    int _;
//    scanf("%d", &_);
//    while (_--) {
        int x;
        scanf("%d", &x);
        int y = __gcd(x, 360);
        printf("%d\n", 360 / y);
//    }

    return 0;
}


Measured memory_bytes: 3780
// #define DEBUGGING
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()

template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
using ll = int64_t;
using ull = uint64_t;
using PLL = pair<ll, ll>;

template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return max(low, min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { t = clamp(t, low, high); }

namespace init__ {

struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

}

#ifdef DEBUGGING
// #include "../debug/debug.cpp"
#include "../../debug/debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

template <typename T>
T make_v(T init) { return init; }

template <typename T, typename... Tail>
auto make_v(T init, size_t s, Tail... tail) {
#define rec make_v(init, tail...)
    return V<decltype(rec)>(s, rec);
#undef rec
}

const ll inf = 5e15;

ll solve() {
    bool exist[26] = {};
    VV<ll> idx_v(26);
    string S, T;
    cin >> S >> T;
    auto make_idx = [](char c) { return c - 'a'; };
    for(ll i = 0; i < S.size(); i++) {
        ll idx = make_idx(S[i]);
        exist[idx] = true;
        idx_v[idx].push_back(i);
    }
    for(auto &&ele : idx_v) ele.push_back(inf);
    ll ans = 0, look = 0;
    ll cur_s_idx = 0, cur_t_idx = 0;
    while(cur_t_idx < T.size()) {
        ll cidx = make_idx(T[cur_t_idx]);
        if(!exist[cidx]) return -1;
        auto ite = lower_bound(ALL(idx_v[cidx]), cur_s_idx);
        if(*ite == inf) {
            ans += S.size();
            cur_s_idx = 0;
            continue;
        }
        look = *ite;
        cur_s_idx = *ite + 1;
        cur_t_idx++;
    }
    return ans + look + 1;
}

int main() {
    cout << solve() << endl;
    return 0;
}


Measured memory_bytes: 1736
#include <stdio.h>
#include <vector>

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

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

                if (max > cur + 1) {
                        printf("No");
                        return 0;
                }

                if (max < cur) {
                        max = cur;
                }
        }

        printf("Yes");
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
int main(){
    int h1, m1, h2, m2, k;
    while(cin>>h1>>m1>>h2>>m2>>k){
        ll ans=0;
        ans=h2*60+m2-h1*60-m1;
        if(ans<0){
        	ans+=60*24;
        }
        // cout<<k<<endl;
        ans-=k;
        cout<<ans<<endl;
    }
  return 0;
}




Measured memory_bytes: 3620
#ifndef DEBUG
#    pragma GCC optimize("O3,no-stack-protector")
#    pragma GCC optimize("unroll-loops")

#    if __cplusplus < 201703L
#        pragma GCC target("avx")
#    else
#        pragma GCC target("avx2")
#    endif

#endif

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i <= i##_len; ++i)
#define rep3(i, l, r) for (int i = l, i##_len = (r); i < i##_len; ++i)
#define REP3(i, l, r) for (int i = l, i##_len = (r); i <= i##_len; ++i)
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
typedef int64_t Int;
typedef long double Ld;

using namespace std;
template <class T>
using Graph = vector<vector<T>>;

const Ld pi = M_PI;
const Int MOD = 1000000007;
const Int INF = 1LL << 62;

Int Floor(Int a, Int b) {
    return (a - (a % b)) / b;
}

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

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

template <typename T>
inline T Gcd(T a, T b) {
    T c;
    while (b) {
        c = b;
        b = a % b;
        a = c;
    }
    return a;
}

Int Lcm(Int a, Int b) {
    if (a < b) {
        swap(a, b);
    }

    return a / Gcd(a, b) * b;
}

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

    Int n, a, b;
    cin >> n >> a >> b;

    Int ans = 0;
    if (b < a) {
        ans = 0;
    } else if (n == 1) {
        if (a != b) {
            ans = 0;
        } else {
            ans = 1;
        }
    } else {
        ans = (b * (n - 1) + a) - (a * (n - 1) + b) + 1;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3604
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#include<cmath>
#include<bitset>
#include<queue>
#define ll long long
#define itn int
#define co(ans) cout<<ans<<endl;
#define COYE cout<<"YES"<<endl;
#define COYe cout<<"Yes"<<endl;
#define COye cout<<"yes"<<endl;
#define CONO cout<<"NO"<<endl;
#define CONo cout<<"No"<<endl;
#define COno cout<<"no"<<endl;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define INF ((1LL<<62)-(1LL<<31))
#define MOD 1000000007
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
using namespace std;


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


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

#define o cout<<"Hello did you expect this?"<<endl;
#define ll long long
#define pb push_back
#define mp make_pair//with Z
#define F first
#define S second

using namespace std;

const int N = 2e5 + 100;
const int mod = 1e9 + 7;

void hey ()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}
vector<int> g[N];
int was[N];
int a[N];
int ans = 0;
void dfs(int v)
{
	was[v] = 1;
	bool f = 0;
	for (int i = 0; i < g[v].size(); i++)
	{
		if (a[v] <= a[g[v][i]])
		{
			f = 1;
		}
		if (!was[g[v][i]])
		{
			dfs(g[v][i]);
		}
	}
	if (!f)
	{
		ans++;
	}
}
int main ()
{
	hey();
	int n, m;
	cin >> n >> m;
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i];
	}
	for (int i = 1; i <= m; i++)
	{
		int u, v;
		cin >> u >> v;
		g[u].pb(v);
		g[v].pb(u);
	}
	for (int i = 1; i <= n; i++)
	{
		if (!was[i])
		{
			dfs(i);
		}
	}
	cout << ans;
}	




Measured memory_bytes: 13484
import sys
import itertools
# import numpy as np
import time
import math
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

# map(int, input().split())
# list(map(int, input().split()))

class UnionFind(object):
    def __init__(self, n = 1):
        self.link = [i for i in range(n)]
        self.size = [1 for _ in range(n)]

    def find(self, x):
        if self.link[x] == x:
            return x

        # re-connect union find to make the height of tree lower
        # you can use while, but recursion makes it easier to reconnect
        self.link[x] = self.find(self.link[x])
        return self.link[x]

    def is_same(self, x, y):
        return self.find(x) == self.find(y)

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return

        if self.size[x] < self.size[y]:
            x, y = y, x
        self.link[y] = x
        self.size[x] += self.size[y]
    
    def get_size(self, x):
        x = self.find(x)
        return self.size[x]


N = int(input())

townsX = [0] * N
townsY = [0] * N
for i in range(N):
    x, y = map(int, input().split())
    townsX[i] = (x - 1, y - 1, i)
    townsY[i] = (y - 1, x - 1, i)
townsX = sorted(townsX)
townsY = sorted(townsY)

edges = []
for i in range(1, N):
    a = townsX[i]
    b = townsX[i - 1]
    c = townsY[i]
    d = townsY[i - 1]
    e1 = (abs(a[0] - b[0]), a[2], b[2])
    e2 = (abs(c[0] - d[0]), c[2], d[2])
    edges.append(e1)
    edges.append(e2)
edges = sorted(edges)

u = UnionFind(N)


ans = 0
for e in edges:
    w, s, t = e
    if u.is_same(s, t):
        continue
    u.unite(s, t)
    ans += w
print(ans)

Measured memory_bytes: 64868
#include<iostream>
using namespace std;
int main(void){
  int a,b;
  char c;
  while(1){
    cin>>a>>c>>b;
    if(c=='?')break;
    if(c=='+')cout<<a+b<<endl;
    if(c=='-')cout<<a-b<<endl;
    if(c=='*')cout<<a*b<<endl;
    if(c=='/')cout<<a/b<<endl;
  }
  return 0;
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

ll nextLong() { ll x; scanf("%lld", &x); return x;}

int main2() {
  int N = nextLong();
  vector<int> count(N+1);
  for (int x = 1; x <= 100; x++) {
    for (int y = 1; y <= 100; y++) {
      for (int z = 1; z <= 100; z++) {
        int n = x*x + y*y + z*z + x*y + y*z + z*x;
        if (n <= N)
          count[n]++;
      }
    }
  }
  for (int i = 1; i <= N; i++) {
    cout << count[i] << '\n';
  }

  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

Measured memory_bytes: 3656
#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, T;
    cin >> S >> T;
    int N = S.length();
    int ans = 0;
    for (int i = 0; i < N; i++)
    {
        if (S[i] != T[i])
        {
            ans++;
        }
        
    }
    cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3924
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    int count=0;
    for(int i=1;i<=c;i++){
        if(c%i==0){
            if(a<=i && i<=b){
                count++;
            }
        }
    }
    cout<<count<<endl;
}


Measured memory_bytes: 3096
n,m = map(int,input().split())
V = n
from collections import defaultdict
g = defaultdict(list)
deg = defaultdict(int)

abl = []
for _ in range(n+m-1):
    a,b = map(int,input().split())
    g[a-1].append(b-1)
    deg[b-1] += 1
    abl.append((a,b))

# V: 頂点数
# G[v] = [w, ...]:
#    有向グラフ上の頂点vから到達できる頂点w
# deg[v]:
#    頂点vに到達できる頂点の数

from collections import deque
ans = list(v for v in range(V) if deg[v]==0)
deq = deque(ans)
used = [0]*V

while deq:
    v = deq.popleft()
    for t in g[v]:
        deg[t] -= 1
        if deg[t]==0:
            deq.append(t)
            ans.append(t)

dic = defaultdict(int)
for idx, a in enumerate(ans):
    dic[a] = idx

headl = [-1 for i in range(n)]
for a,b in abl:
    if headl[b-1] == -1:
        headl[b-1] = a-1
    else:
        if dic[headl[b-1]] < dic[a-1]:
            headl[b-1] = a-1

for i in headl:
    print(i+1)


Measured memory_bytes: 66256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef vector<int> vi;
typedef pair<int,int> ii;
#define inf 1e9
#define F first
#define S second
#define dbg(x) cout<<#x<<" value : "<<x<<"\n";
#define rep(i,j,k) for(int i = (j); i <= (k); i++)
#define rep__(i,j,k) for(int i = (j); i < (k); i++)
#define per(i,j,k) for(int i = (j); i >= (k); i--)
#define per__(i,j,k) for(int i = (j); i > (k); i--)
#define mst(a,b) memset(a,b,sizeof(a))
#define sf(n) scanf("%d",&n)
#define stf(n,m) scanf("%d%d",&n,&m)
#define pf(n) printf("%d\n",n)
#define slf(n) scanf("%lld",&n)
#define plf(n) printf("%lld\n",n)
priority_queue<int,vector<int>,less<int> > q;
const int N=105;
const int mod=1e9+7;
int n,a[N],b[N],c[N],sum;
string s,f;
int main()
{
	sf(n);
	rep(i,1,n-1)sf(b[i]);
	sum+=b[1];sum+=b[n-1];
	rep(i,1,n-2){
		if(b[i]<=b[i+1])sum+=b[i];
		else sum+=b[i+1];
	}
	pf(sum);
	return 0;
}

Measured memory_bytes: 256
#C問題
import numpy as np
X,K,D = map(int, input().split())
ans = 0
if X >= 0 :
    if int(X/D)<=K:
        if int(X/D)%2==K%2:
            ans = X%D
        else:
            ans = D-X%D
    else:
        ans = abs(X-K*D)       
if X < 0 :
    if abs(int(X/D))<=K:
        if abs(int(X/D))%2==K%2:
            ans = abs(X)%D
        else:
            ans = D-abs(X)%D
    else:
        ans = abs(X+K*D)          
print(ans)

Measured memory_bytes: 27068
#!/usr/bin/env python3
import sys
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
mod = 10**9+7

s=input()
n=len(s)
ss={si for si in s}
if len(ss)==n:
    print('yes')
else:
    print('no')

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

using i64 = long long;
using P = pair<i64, i64>;

#define overload3(_1, _2, _3, name, ...) name
#define rep1(i, n) for(i64 i = 0LL; i < (n); ++i)
#define rep2(i, a, b) for(i64 i = (a); i < (b); ++i)
#define rep(...) overload3(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
#define all(v) v.begin(), v.end()


void solve(long long N, std::vector<long long> A, long long Q, std::vector<long long> B, std::vector<long long> C){
    vector<i64> table(100010);
    rep(i, N) table[A[i]]++;
    i64 s = 0;
    rep(i, 100010) s += i * table[i];
    rep(i, Q){
        s += table[B[i]] * (C[i] - B[i]);
        table[C[i]] += table[B[i]];
        table[B[i]] = 0;
        cout << s << endl;
    }
}

struct IoSetup {
    IoSetup() {
        // cin.tie(nullptr);
        // ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
        cerr << fixed << setprecision(10);
    }
} iosetup;

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    long long Q;
    scanf("%lld",&Q);
    std::vector<long long> B(Q);
    std::vector<long long> C(Q);
    for(int i = 0 ; i < Q ; i++){
        scanf("%lld",&B[i]);
        scanf("%lld",&C[i]);
    }
    solve(N, std::move(A), Q, std::move(B), std::move(C));
    return 0;
}


Measured memory_bytes: 6424
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vb=vector<bool>;
using vvb=vector<vb>;
using vc=vector<char>;
using vvc=vector<vc>;
using pii = pair<int,int>;
using pil = pair<int,ll>;
using pli = pair<ll,int>;
using pll = pair<ll,ll>;
using tiii = tuple<int,int,int>;
using vpii = vector<pii>;
using vpil = vector<pil>;
using vpli = vector<pli>;
using vpll = vector<pll>;

#define rep(i, n) for(int i=0;i<(int)n;i++)
#define rep2(i, s, n) for(int i=(s);i<(int)n;i++)
int INF=1e9+7;

int main() {
  int N;
  cin >> N;
  
  vi f(N+1);
  rep2(x,1,100) {
    rep2(y,1,100) {
      rep2(z,1,100) {
        int n=x*x+y*y+z*z+x*y+y*z+z*x;
        if(n<=N) f[n]++;
      }
    }
  }
  
  rep2(i,1,N+1) cout << f[i] << endl;
}

Measured memory_bytes: 3588
#include <cstdio>
#include <utility>
#include <vector>
#include <string>
using namespace std;

#define gcu getchar_unlocked
#define ii inline int in
#define is inline bool scan
ii(int c) {
	int n = 0;
	bool minus = false; if (c == '-') minus = true, c = gcu();
	do {n = 10 * n + (c - '0'), c = gcu();} while (c >= '0');
	//return n; }
	return minus ? -n : n; }
ii() {return in(gcu());}
is(int &n){int c=gcu();return c==EOF?false:(n=in(c),true);}
is(char &c){c=gcu();gcu();return c!=EOF;}
is(string &s){int c; s = "";
	for(;;){c=gcu();if(c=='\n'||c==' ')return true;else if(c==EOF)return false;s+=c;}}
#undef ii
#define pcu putchar_unlocked
template <typename T>
void out(T n) {
	static char buf[20];
	char *p = buf;
	if(n < 0) pcu('-'), n *= -1;
	if (!n) *p++ = '0';
	else while (n) *p++ = n % 10 + '0', n /= 10;
	while (p != buf) pcu(*--p); }
void out(const char *s){while(*s)pcu(*s++);}
void out(char c){pcu(c);}
void out(string &s){for (char c: s) pcu(c);}
template <typename head, typename... tail>
void out(head&& h, tail&&... t){out(h);out(move(t)...);}
//template <typename T>
//void out(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);out('\n');}
#undef svo

typedef vector<string> v;

char pat_search(v &a) {
	static auto p = [&a](int i, int j) {
		return i < 8 && j < 8 && a[i][j] == '1';};
	for (int i = 0; i < 8; i++)
		for (int j = 0; j < 8; j++)
			if (a[i][j] == '1') {
				return p(i + 1, j + 1) ? p(i, j + 1) ? p(i + 1, j + 2) ? 'E' : 'A' : 'F' :
					p(i, j + 1) ? p(i, j + 2) ? 'C' : 'G' :
					p(i + 2, j) ? 'B' : 'D';
			}
	return 'X';
}

int main() {
	v a(8);
	do {
		for (auto &s: a)
			scan(s);
		out(pat_search(a), '\n');
	} while (gcu() == '\n');
}


Measured memory_bytes: 2664
#include <iostream>
#include <string>
using namespace std;
int main(void){
  string s,t;
  cin >> s >> t;
  int a,b;
  cin >> a >> b;
  
  string u;
  cin >> u;
  
  if(u == s) a--;
  if(u == t) b--;
  
  cout << a << " " << b << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(int i=(n);i<(k);i++)
#define ALL(a)  (a).begin(),(a).end()
ll ans=0;
void Main(){
    ll n;cin>>n;
    ll k;cin>>k;
    For(i,0,n){ll a;cin>>a;
    ans+=min(a,k-a);
    }
    cout<<ans*2<<endl;
}
int main(){
    Main();
    /*
    東方風神録は神が出てくるので当然神ゲー
    */
    return 0;
}

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

int main()
{
  string s;
  cin >> s;
  int zero = 0;
  int one = 0;
  for (int i = 0; i < s.length(); i++) {
    if (s[i] == '0') {
      zero++;
    } else {
      one++;
    }
  }
  cout << min(zero, one) * 2 << endl;
}


Measured memory_bytes: 512
import sys
input = sys.stdin.readline
INF = 10 ** 9
MOD = 10 ** 9 + 7

def main(): 
    h,w,d = map(int,input().split())
    n = h * w

    idx = [0]*(1+n)
    for i in range(h):
        a = tuple(map(int,input().split()))
        for j in range(w):
            idx[a[j]] = (i + 1 , j + 1)
    idx[0] = idx[d]

    D = [0] * (n + 1)
    
    def dist(i,j):
        return abs(idx[i][0] - idx[j][0]) + abs(idx[i][1] - idx[j][1])
        
    for i in range(d):
        for j in range(i,n - d + 1,d):
            D[j + d] = D[j] + dist(j,j + d)
    
    q = int(input())
    for _ in range(q):
        l,r = map(int,input().split())
        print(D[r] - D[l])        

if __name__=='__main__':
    main()



Measured memory_bytes: 14944
#include <iostream>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <queue>
#include <cmath>
// #include <atcoder/all>
using namespace std;
// using namespace atcoder;

int main() {
	int n;
	cin >> n;
	vector<int> v(n + 1, 0), c(n + 1, 0);
	for (int i = 2; i <= n; i++) {
		cin >> v[i];
		c[v[i]]++;
	}
	vector<int> res(n + 1, 0);
	vector<int> nodes;
	for (int i = 1; i <= n; i++) {
		if (c[i] == 0) {
			nodes.push_back(i);
		}
	}
	vector<vector<int>> children(n + 1, vector<int>(0));
	while (nodes.size() > 0) {
		int node = nodes.back();
		nodes.pop_back();
		if (children[node].size() == 0) {
			children[v[node]].push_back(0);
		} else {
			sort(children[node].begin(), children[node].end(), greater<int>());
			int min_res = 0;
			for (int i = 0; i < children[node].size(); i++) {
				min_res = max(min_res, children[node][i] + i + 1);
			}
			if (v[node] == 0) {
				cout << min_res  << endl;
				return 0;
			}
			children[v[node]].push_back(min_res);
		}
		c[v[node]]--;
		if (c[v[node]] == 0) {
			nodes.push_back(v[node]);
		}
	}

}






Measured memory_bytes: 9664
#include<iostream>
#include<algorithm>
using namespace std;
int i[114514];
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a,b,c,d=0,e;
	cin >>a>>b;
	for(int n=b-a+1;n<a+b;n++){
		if(n!=b-a+1) cout <<' ';
		cout <<n;
	}
	cout <<'\n';
	return 0;
}

Measured memory_bytes: 256
n,m,c = map(int,input().split())
b = list(map(int,input().split()))
k = 0
for _ in [0]*n:
  a = list(map(int,input().split()))
  s = c
  for i in range(m):
    s += a[i]*b[i]
  if s>0:
    k += 1
print(k)

Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <list>

using ll = long long;
using ld = long double;
using namespace std;
const int INF = 1e9+100;
const ll INF64 = 7e18l;
const int mod = 1000000007;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(), (a).end()
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);


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

    int ans[h][w];
    int i=0,j=0;
    int color = 1;
    int count_num = 0;
    int count_color = 0;
    int flag = 0;

    for(int p=0;p<h*w;p++){
        ans[i][j] = color;
        count_color++;
        if(count_color == a[color-1]){
            color++;
            count_color = 0;
        }

        count_num++;
        if(count_num % w == 0){
            i++;
            flag = 1-flag;
            if(flag == 0) j--;
            else j++;
        }

        if(flag == 0) j++;
        else j--;

    }


    for(int x=0;x<h;x++){
        for(int y=0;y<w;y++){
            cout << ans[x][y] << " ";
        }
        cout << endl;
    }


    return 0;
}


Measured memory_bytes: 3636
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;

vector<int> dx(4010, 0), dy(4010, 0);

int main() {
	string s;
	int x, y;

	cin >> s >> x >> y;

	int l = s.size();
	int tcnt = 0, j = 1, k = 1;
	for (int i = 0; i < l; i++) {
		if (s[i] == 'F') {
			if (tcnt % 2 == 0) {
				dx[j]++;
			}
			else {
				dy[k]++;
			}
		}
		else {
			if (tcnt % 2 == 0) {
				if (dx[j]) j++;
			}
			else {
				if (dy[k]) k++;
			}
			tcnt++;
		}
	}

	vector<vector<bool>> dpx(j+10, vector<bool>(2*l + 10, false));
	vector<vector<bool>> dpy(k+10, vector<bool>(2*l + 10, false));

	if (s[0] == 'F') {
		dpx[1][l + dx[1]] = true;
	}
	else {
		dpx[1][l + dx[1]] = true, dpx[1][l - dx[1]] = true;
	}
	int i;
	for (i = 2; dx[i] > 0; i++) {
		for (int j = dx[i]; j + dx[i] <= 2*l; j++) {
			dpx[i][j] = dpx[i - 1][j - dx[i]] || dpx[i - 1][j + dx[i]];
		}
	}
	int ansx = i - 1;

	dpy[1][l + dy[1]] = true, dpy[1][l - dy[1]] = true;

	for (i = 2; dy[i] > 0; i++) {
		for (int j = dy[i]; j + dy[i] <= 2*l; j++) {
			dpy[i][j] = dpy[i - 1][j - dy[i]] || dpy[i - 1][j + dy[i]];
		}
	}
	int ansy = i - 1;

	if (dpx[ansx][x + l] && dpy[ansy][y + l]) {
		cout << "Yes" << endl;
		return 0;
	}
	cout << "No" << endl;
}


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

class Combination {
private:
  const int max;
  const int mod;
  std::vector<long long> fac;  // fac[k] = k! in Fp
  std::vector<long long> finv; // finv[k] = (k!)^-1 in Fp
public:
  Combination(int max, int mod)
      : max(max), mod(mod), fac(max, -1), finv(max, -1) {
    std::vector<long long> inv(max, -1); // inv[k] = k^-1 in Fp
    fac[0] = fac[1] = 1;
    inv[1] = 1;
    finv[0] = finv[1] = 1;
    for (int i = 2; i < max; ++i) {
      fac[i] = fac[i - 1] * i % mod;
      inv[i] = mod - inv[mod % i] * (mod / i) % mod;
      finv[i] = finv[i - 1] * inv[i] % mod;
    }
  }
  long long operator()(int n, int k) const {
    if (n < k || n < 0 || k < 0)
      return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
  }
};

long long modpow(int a, long long n, int mod) {
  long long res = 1;
  long long apow = a; // a^1, a^2, a^4, ...
  while (n) {
    if (n & 1LL)
      res = (res * apow) % mod;
    apow = apow * apow % mod;
    n = n >> 1;
  }
  return res;
}

int main() {

  const int MAX = 1000000;
  const int MOD = 998244353;
  Combination comb(MAX, MOD);

  int N, M, K;
  std::cin >> N >> M >> K;

  long long res = 0;

  for (int k = 0; k <= K; ++k) {
    long long tmp = 1;
    tmp = (tmp * comb(N - 1, k)) % MOD;
    tmp = (tmp * M) % MOD;
    tmp = (tmp * modpow(M - 1, N - (k + 1), MOD));
    // std::cout << "tmp " << tmp << std::endl;

    res = (res + tmp) % MOD;
  }
  std::cout << res << std::endl;
}


Measured memory_bytes: 26540
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#define ll long long
#define rgi register int
#define il inline

using namespace std;

const int N = 100 + 10;

int n, a[N];

double up = 1.0, down;

il int read()
{
	rgi f = 0, x = 0, ch;
	while(!isdigit(ch = getchar())) f |= ch == '-';
	while(isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
	return f ? -x : x;
}

int main()
{
	n = read();
	for(rgi i = 1; i <= n; ++i)
		a[i] = read();
	for(rgi i = 1; i <= n; ++i)
		up *= a[i];
	for(rgi i = 1; i <= n; ++i)
		down += up / a[i];
//	cout << up << " " << down << endl;
	printf("%.4lf", up / down);
	return 0;
}


Measured memory_bytes: 256