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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ll long long
#define db double
#define el "\n"
#define ld long double
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n;i>=0;i--)
#define rep_a(i,a,n) for(int i=a;i<n;i++)
#define tr(ds, it) for(auto it=ds.begin(); it!=ds.end(); it++)
#define rtr(ds, it) for(auto it=ds.rbegin(); it!=ds.rend(); it--)
#define all(ds) ds.begin(), ds.end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
typedef priority_queue <int> pq;
typedef vector< long long > vi;
typedef pair<long long, long long> ii;
#define o_set tree<ii, null_type,less<ii>, rb_tree_tag,tree_order_statistics_node_update>
#define graph vector<vi>
#define Mod 1000000007
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int main()
{
    fastio;
//	#ifndef ONLINE_JUDGE
//    freopen("input.txt", "r" , stdin);
//    freopen("output.txt", "w" , stdout);
//    #endif
    
     int n, count[3];
     cin >> n >> count[0] >> count[1] >> count[2];
     
     string arr[n];
     
     rep(i, n)
     	cin >> arr[i];
    
    vector<char> ans;
    
    if (count[0] + count[1] + count[2] == 0)
    	cout << "No\n";
    else {
    	
    	bool flag = false;
    	rep(i, n) {
    		
    		int x = count[arr[i][0] - 'A'];
    		int y = count[arr[i][1] - 'A'];
    		
    		if (x == 0 && y == 0) {
    			flag = true;
    			break;
			}
			else if (x == 0) {
				count[arr[i][1] - 'A']--;
				count[arr[i][0] - 'A']++;
				ans.pb(arr[i][0]);
			}
			else if (y == 0) {
				count[arr[i][0] - 'A']--;
				count[arr[i][1] - 'A']++;
				ans.pb(arr[i][1]);
			}
			else if (x == 1 && y == 1){
				
				if (i == n - 1 || (i < n - 1 && arr[i] == arr[i + 1])) {
					count[arr[i][0] - 'A']--;
					count[arr[i][1] - 'A']++;
					ans.pb(arr[i][1]);
				}
				else {
					
					if (arr[i][0] == 'A') {
						
						if (arr[i + 1][0] == 'A') {
							count[arr[i][0] - 'A']++;
							count[arr[i][1] - 'A']--;
							ans.pb(arr[i][0]);
						}
						else {
							count[arr[i][0] - 'A']--;
							count[arr[i][1] - 'A']++;
							ans.pb(arr[i][1]);
						}
					}
					else {
						
						if (arr[i + 1][1] == 'C') {
							count[arr[i][0] - 'A']--;
							count[arr[i][1] - 'A']++;
							ans.pb(arr[i][1]);
						}
						else {
							count[arr[i][0] - 'A']++;
							count[arr[i][1] - 'A']--;
							ans.pb(arr[i][0]);
						}
					}
				}
			}
			else if (x == 1) {
				count[arr[i][0] - 'A']++;
				count[arr[i][1] - 'A']--;
				ans.pb(arr[i][0]);
			}
			else if (y == 1) {
				count[arr[i][0] - 'A']--;
				count[arr[i][1] - 'A']++;
				ans.pb(arr[i][1]);
			}
			else {
				count[arr[i][0] - 'A']--;
				count[arr[i][1] - 'A']++;
				ans.pb(arr[i][1]);
			}
		}
		if (flag)
			cout << "No\n";
		else {
			cout << "Yes\n";
			
			for (int i = 0; i < ans.size(); i++)
				cout << ans[i] << "\n";
		}
	}
	
	
    
	//code
	return 0;
}


Measured memory_bytes: 6864
Roman = {'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000}

while 1:
    try:
        roman = raw_input()
    except EOFError:
        break
    phase = 1000
    ret = 0
    cnt = 0
    for x in roman:
        cur = Roman[x]
        if cur < phase:
            ret += phase * cnt
            phase = cur
            cnt = 1
        elif cur == phase:
            cnt += 1
        elif cur > phase:
            ret += cur - cnt * phase
            phase = cur
            cnt = 0
    else:
        ret += phase * cnt
    print ret

Measured memory_bytes: 4224
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <iomanip>
#define endl "\n"
#define ll long long int
using namespace std;

ll binCoeff(ll n, ll r)
{
	ll res = 1;
	if(r > n - r)
		r = n - r;

	for(ll i = 0; i < r; i ++)
	{
		res = res * (n - i);
		res = res / (i + 1);
	}
	return res;
}

ll fastExp(ll base, ll exp)
{
	ll result = 1;
	while(exp > 0)
	{
		if(exp % 2 == 1)
			result = result * base;
		base = base * base;
		exp /= 2;
	}
	return result;
}

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

    vector <ll> v(n);

    for(ll i = 0; i < n; i ++)
    {
    	cin >> v[i];
    }
    sort(v.begin(), v.end(), greater<ll>());

    ll sum = 0;
    for(ll i = 0; i < a; i ++)
    	sum = sum + v[i];

    ll lastIndex = a - 1;
    double avg = (double)sum / (lastIndex + 1);
    for(ll i = a; i < b; i ++)
    {
    	if(v[i] > avg)
    	{
    		sum = sum + v[i];
    		lastIndex = i;
    		avg = (double)sum / (lastIndex + 1);
    	}
    }

    ll inc = 0, exc = 0;
    for(int i = 0; i < n; i ++)
    {
    	if(v[i] == v[lastIndex] && i <= lastIndex)
    	{
    		inc ++;
    		exc ++;
    	}
    	else if(v[i] == v[lastIndex] && i > lastIndex)
    		exc ++;
    }
    cout << fixed << setprecision(6) << avg << endl;
    ll poss = 0;

    if(v[0] == v[lastIndex])
    {
    	poss = fastExp(2, exc);
	    for(int i = 0; i < inc; i ++)
	    {
	    	poss = poss - binCoeff(exc, i);
	    }

	    for(int i = b + 1; i <= exc; i ++)
	    	poss = poss - binCoeff(exc, i);
    }
    else
    	poss = binCoeff(exc, inc);
    // cout << inc << " " << exc << endl;
    cout << poss << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
  
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL); 
  
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define ld long double


#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...) 1
#endif
template<class T> ostream& operator<<(ostream &os, vector<T> V) {os << "[ "; for(auto v : V) os << v << " "; return os << "]";}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {return os << "(" << P.first << "," << P.second << ")";}
  
typedef long long int ll;
  
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ll mod =998244353;
const ll maxn=1000001;
const ll LOGMAXN=30;
ll power(ll x, ll n) {
      ll res = 1;
      for (; n > 0; n >>= 1) {
        if (n & 1) res = (res * x) % mod;
        x = (x * x) % mod;
      }
      return res;
}

int main()
{
  
  IOS
  ll n;
  cin>>n;
  ll dp[100001];
  memset(dp,0,sizeof(dp));
  dp[100]=dp[101]=dp[102]=dp[103]=dp[104]=dp[105]=1;
  for(ll i=106;i<=n;i++)
  {
    dp[i]=(dp[i-100]||dp[i-101]||dp[i-102]||dp[i-103]||dp[i-104]||dp[i-105]);
  }
  cout<<dp[n]<<endl;
  

}
    

  
  
	

 

Measured memory_bytes: 1024
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size,n=1,init=nil) #nに配列の次元数、sizeに配列の大きさ、initに初期値を投げることでその配列を返す
  if n==1
    return Array.new(size){init}
  else
    return Array.new(n).map{Array.new(size){init}}
  end
end

n=gets.to_i
a=get_i
a.sort!{|x,y| y<=>x}
max=0
ans=-1
(n-1).times do|i|
  if max<a[i+1] and max<a[0]-a[i+1]
    max=(a[i+1]>a[0]-a[i+1]) ? a[0]-a[i+1] : a[i+1]
    ans=i+1
  end
end
puts [a[0],a[ans]].join(" ")

Measured memory_bytes: 10248
N=int(input())
a=list(map(int,input().split()))

Alice=[]    #Aliceが持っているカード
Bob=[]      #Bobが持っているカード
for i in range(N):
    if i%2==0:      #偶数だったらAlieがとる番
        Alice.append(max(a))
        a.remove(max(a))
    else:           #奇数だったらBobがとる番
        Bob.append(max(a))
        a.remove(max(a))

print(sum(Alice)-sum(Bob))



Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>//sort
#include <functional>
#include <stdio.h>
#include <vector>
#include <string>
#include <map>//pair
#define rep(i, n) for(int i = 0; i < n; i++)

using namespace std;

int main(){
  int H, N, ans;
   cin >> H >> N;
   int A[1000000];
   rep(i, N)cin >> A[i];
   
   rep(i, N){
    ans += A[i];
   }
   if(ans >= H)cout << "Yes" << endl;
   else cout << "No" << endl;
}


Measured memory_bytes: 2560
n, m = [int(x) for x in input().split()]

skip_flag = [False] * (n + 1)
wa_count_list = [0] * (n + 1)

ac = 0
wa = 0

for _ in range(m):
    p, s = input().split()
    p = int(p)

    if skip_flag[p]:
        continue

    if s == "AC":
        ac += 1
        wa += wa_count_list[p]
        skip_flag[p] = True
    elif s == "WA":
        wa_count_list[p] += 1

print(ac, wa)

Measured memory_bytes: 4596
from numpy import*
M=10**9+7
m=lambda*z:map(int,raw_input().split())
n,k=m()
b=[1]*n
a=matrix(map(m,b),'O')
while k:b=[b,b*a][k&1];a=a*a%M;k/=2
print sum(b)%M

Measured memory_bytes: 10672
h,w=map(int,input().split())
s=[input() for _ in range(h)]
for i in range(h):
    l=""
    for j in range(w):
        if s[i][j]=="#":
            l+="#"
        else:
            l+=str(sum([t[max(0,j-1):min(w,j+2)].count("#") for t in s[max(0,i-1):min(h,i+2)]]))
    print(l)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int n;
    int a,b,c,d;
    int cnt = 0;
    cin >> n;
    a=n/1000;
    b=(n%1000)/100;
    c=((n%1000)%100)/10;
    d=((n%1000)%100)%10;
    if (a==b && a==c) cout <<"Yes"<<endl;
    else if(b==c && b==d) cout <<"Yes"<<endl;
    else cout <<"No"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}

vector<vector<int>> v(100010);

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    int n,m;
    cin>>n>>m;
    int h[n];
    for(int i=0;i<n;i++){
        cin>>h[i];
    }
    for(int i=0;i<m;i++){
        int a,b;
        cin>>a>>b;
        a--,b--;
        v[b].push_back(a);
        v[a].push_back(b);
    }
    int ans = 0;
    for(int i=0;i<n;i++){
        bool pos = 1;
        for(auto j:v[i]){
            if(h[j] >= h[i])pos=false;
        }
        ans += pos;
    }
    cout << ans << endl;
}

Measured memory_bytes: 8744
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
double dp[3105][3105];
double arr[3105];
int main()
{
    int t=1;
    //cin>>t;
    while(t--)
    {
    	int n;
    	cin>>n;
    	for(int i=0;i<n;i++)cin>>arr[i];
    	dp[0][0]=1;
    	for(int i=1;i<=n;i++)
    	{
    		for(int j=0;j<=i;j++)
    		{
    			if(j)dp[i][j]=arr[i-1]*dp[i-1][j-1];
    			dp[i][j]+=(1-arr[i-1])*dp[i-1][j];
    		}
    	}
    	double ans=0;
    	for(int i=0;i<=n;i++)
    	{
    		if(i>n-i)ans+=dp[n][i];
    	}
    	cout<<fixed<<setprecision(12)<<ans<<endl;
    }
	return 0;
}

Measured memory_bytes: 72320
#include <stdio.h>
int main()
{
  int s,n,i;
  for(;;){
    scanf("%d",&s);
    if(s==0)break;
    for(i=0;i<9;i++){
      scanf("%d",&n);
      s -= n;
    }
    printf("%d\n",s);
  }
  return 0;
}

Measured memory_bytes: 0
def factorization(n):
    arr = []
    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])

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

    return arr

import fractions
a, b = map(int,input().split())

if fractions.gcd(a, b) == 1:
    print(1)
else:
    print(len(factorization(fractions.gcd(a, b))) + 1)

Measured memory_bytes: 5048
data = input().rstrip().split(" ")
day = int(data[0])
task = int(data[1])
need = 0
hw = input().rstrip().split(" ")
for i in range(task):
    need += int(hw[int(i)])
answer = day - need
if answer >= 0:
    print(answer)
else:
    print("-1")

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> res(n);
    rep(i, n) res[i] = i + 1;
    int sum = 0;
    for (int i = 0; i < n; i++) {
        if (to_string(res[i]).size() % 2 != 0) sum++;
    }
    cout << sum << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#include<iostream>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=1e9+7;
//エラトステネスの篩
vector<bool> IsPrime(1000010,true);
void sieve(ll n){
    IsPrime[0]=0;
    IsPrime[1]=0;
    REP(i,2,n+1){
        if(IsPrime[i]){
            ll k=2;
            while(k*i<=n){
                IsPrime[k*i]=0;
                k++;
            }
        }
    }
}
//Combination
long long extGCD(long long a,long long mod,long long &x,long long &y){
    if(mod==0){
        x=1;
        y=0;
        return a;
    }
    long long d=extGCD(mod,a%mod,y,x);
    y-=(a/mod)*x;
    return d;
}
long long invmod(long long a,long long mod){
    long long x,y;
    extGCD(a,mod,x,y);
    x%=mod;
    if(x<0)x+=mod;
    return x;
}
ll fac[2000010],finv[2000010],inv[2000010];
void combinit(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    REP(i,2,2000010){
        fac[i]=fac[i-1]*i%mod;
        inv[i]=invmod(i,mod);
        finv[i]=finv[i-1]*inv[i]%mod;
    }
}
ll comb(ll n,ll k){
    if(n<k)return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%mod)%mod;
}
ll rui(ll a,ll b){
    ll res=1;
    ll x=a;
    while(b){
        if(b&1)res=(res*x)%mod;
        x=x*x%mod;
        b/=2;
    }
    return res;
}
signed main(){
    ll n;cin>>n;
    sieve(1000010);
    combinit();
    vector<ll>a(n);
    vector<ll>prcnt(1000010);
    rep(i,n){
        cin>>a[i];
        ll k=a[i];
        REP(j,2,sqrt(a[i])+1){
            ll cnt=0;
            while(k%j==0){
                k/=j;
                cnt++;
            }
            prcnt[j]=max(prcnt[j],cnt);
        }
        if(k>1){
            prcnt[k]=max(1LL,prcnt[k]);
        }
    }
    ll ans=0;
    ll b=1;
    REP(i,2,1000010){
        b=(b*rui(i,prcnt[i]))%mod;
    }
    rep(i,n){
        ans=(ans+b*invmod(a[i],mod))%mod;
    }
    if(ans<0)ans+=mod;
    cout<<ans<<endl;
}

Measured memory_bytes: 55168
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    string s, t;
    cin >> s >> t;
    string res = "";
    rep(i, N) {
        res += s[i];
        res += t[i];
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
int main(void){
    char s[5];
    scanf("%s",s);
    if(s[0]==s[1]&&s[1]!=s[2]&&s[2]==s[3])
    printf("Yes");
    else if(s[0]==s[2]&&s[1]!=s[2]&&s[1]==s[3])
    printf("Yes");
    else if(s[0]==s[3]&&s[1]!=s[3]&&s[1]==s[2])
    printf("Yes");
    else
    {printf("No");}
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	vector<int> A(N);
	vector<int> B(N);
	int res = 0;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	for (int i = 0; i < N; i++) {
		cin >> B[i];
	}
	for (int i = 1; i < N; i++) {
		A[i] += A[i - 1];
	}
	for (int i = N - 2; i >= 0; i--) {
		B[i] += B[i + 1];
	}
	for (int i = 0; i < N; i++) {
		res = max(res, A[i] + B[i]);
	}
	cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxx = 1e5 + 7;
const int Inf = 1 << 30;
const ll INF = 1ll << 60;
typedef pair <int, int> PR;
priority_queue <PR> qua;
#define mst(x) memset(x, 0, sizeof(x))
vector <int> vec;
int n;
int a[17];

void Init() {
	 cin >> n;
	 for(int i = 1; i <= n; i++) cin >> a[i];
}

int main() {
	Init();
	sort(a + 1, a + n + 1);
	a[n] /= 2;
	int ans = 0;
	for(int i = 1; i <= n; i++) ans += a[i];
	cout << ans << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define RFOR(i, a, b) for(int i=(b-1);i>=(a);i--)
#define REP(i, n) for(int i=0; i<(n); i++)
#define RREP(i, n) for(int i=(n-1); i>=0; i--)
#define REP1(i, n) for(int i=1; i<=(n); i++)
#define RREP1(i, n) for(int i=(n); i>=1; i--)
#define ALL(a) (a).begin(),(a).end()
#define UNIQUE_SORT(l) sort(ALL(l)); l.erase(unique(ALL(l)), l.end());
#define CONTAIN(a, b) find(ALL(a), (b)) != (a).end()
#define out(...) printf(__VA_ARGS__)
#if DEBUG
#define debug(...) printf(__VA_ARGS__)
#else
#define debug(...) /* ... */
#endif
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}
void _OUT() {}; template<class H, class... T> void _OUT(H &h, T &... t) { cout<<' '<<h; _OUT(t...); };
template<class H, class... T> void _P(H &h, T &... t) { cout<<h; _OUT(t...); };
#define _PN(...) _P(__VA_ARGS__); cout << endl;
#define EXEC(...) void exec() { (__VA_ARGS__ - 1) ? multi() : solve(0); }

void exec();
void solve(int t);
void multi() { int TT; cin>>TT; REP1(t,TT) solve(t); }
signed main()
{
#if DEBUG
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    exec();
    return 0;
}

/*================================*/
#if DEBUG
#define SIZE 100
#else
#define SIZE 223450
#endif

int N,K;
vector<double> A(SIZE);

int ok(double n) {
    int cnt = 0;
    REP(i,N) {
        cnt += ceil(A[i]/n)-1;
    }
    return cnt <= K;
}

void solve(int _t) {
    cin>>N>>K;
    REP(i,N) cin>>A[i];
    double l=0.1,r=1e9+1;
    REP(i,100) {
        double m = (l+r)/2;
        debug("l:%lf, r:%lf\n",l,r);
        if (ok(m)) r = m;
        else l = m;
    }
    int ans = ceil(r);
    _PN(ans);
}
EXEC(1)



Measured memory_bytes: 4944
#include<bits/stdc++.h>
#include <iomanip>
#include <unordered_map>
using namespace std;
#define ll long long 
#define pi pair<ll,ll>
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define rrep(i,a) for(ll i=a;i>=0;i--)
ll mod=1e9+7;
/*ll power(ll x,ll n)
{
    ll ans=1;
    while(n>=1)
    {
       if(n&1)
       ans=(ans*x);
       n>>=1;
       x=(x*x);
    }
    return ans;
}
/*
struct comp {
    bool operator()(const pair& x, const pair& y) const {
        if (x.second != y.second)
            return x.second < y.second;

        return x.first < y.first;
    }
};
void dfs(int source,vector<int> graph[],vector<int> &path,bool status[])
{
 path.push_back(source);
 status[source]=0;
 //int j=graph[source].size();
 for(int i=0;i<graph[source].size();i++)
 {
     if(status[graph[source][i]]==1)
     dfs(graph[source][i],graph,path,status);
 }
 return;
}*
bool solve(int i,int j,string s)
{
    while(i<j)
    {
      if(s[i]<s[j])
      return 0;
      if(s[i]>s[j])
      return 1;
      i++;
      j--;
    }
    return 1;
}
bool isprime(ll x)
{
    for(ll i=2;i<=sqrt(x);i++)
    {
        if(x%i==0)
        return 0;
    }
    return 1;
    
}
ll lg(ll x,ll n)
{
    ll ans=0;
    while(x/n!=0)
    {
        ans++;
        x/=n;
    }
    return ans;
}
long long ncr(long long n,long long r)
{
    long long C[n+1][r+1];
    long long i,j;
    for (i = 0; i <= n; i++) 
    { 
        for (j = 0; j <= min(i, r); j++) 
        { 
            
            if (j == 0 || j == i) 
                C[i][j] = 1; 
  
           
            else
                C[i][j] = (C[i - 1][j - 1]%mod + C[i - 1][j]%mod)%mod; 
                          
        } 
    } 
    return C[n][r];
}*/
 void dfs(vector<vector<ll>>& v,bool visi[],ll node)
 {
     if(visi[node]==1)
     return;
     visi[node]=1;
     for(long long i=0;i<v[node].size();i++)
     {
         dfs(v,visi,v[node][i]);
     }
 }
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,i,j,k,q,t,y,x,k1,i1,j1,z,x1,y1,m,z1,h;
      cin>>n>>m;
      vector<vector<ll>> v(n+1);
      for(i=1;i<=m;i++)
      {
          cin>>j>>k;
          v[j].push_back(k);
          v[k].push_back(j);
      }
     bool visi[n+1];
     for(i=1;i<=n;i++)visi[i]=0;
     ll ans=0;
     for(i=1;i<=n;i++)
     {
         if(visi[i]==0)
         {
             ans++;
             dfs(v,visi,i);
         }
     }
     ans--;
    cout<<ans;
}




 
     


Measured memory_bytes: 10328
import sys
from collections import defaultdict

(n, m), *q = [[*map(int, i.split())] for i in sys.stdin]
d = defaultdict(list)
for k, v in q:
    d[k].append(v)
c = defaultdict(dict)
for k, v in d.items():
    for i, j in enumerate(sorted(v)):
        c[k][j] = i + 1
for p, y in q:
    print("{:0>6}{:0>6}".format(p, c[p][y]))


Measured memory_bytes: 75876
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define RFOR(i,a,n) for(ll i=(ll)n-1;i >= (ll)a;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,0,n)
#define ALL(v) v.begin(), v.end()
#define bra(first,second) '(' << first << ',' << second << ')'
ll MOD = 1000000007;
//ll INF = 21474836470000000;
ll INF = 100100100100100100;
long double EPS = 1e-11;
long double PI = 3.141592653589793238;
template<typename T>
void remove(std::vector<T>& vector, unsigned int index){
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<ll>>;

ll N,K;
vector<ll> A,F;

bool f(ll x){
    ll cnt = 0;
    rep(i,N){
        cnt += max(A[i] - x / F[i],0LL);
    }
    return cnt <= K;
}

int main(){
    cin >> N >> K;
    rep(i,N){
        ll a;cin >> a;
        A.push_back(a);
    }
    rep(i,N){
        ll f;cin >> f;
        F.push_back(f);
    }
    sort(ALL(A));
    sort(ALL(F));
    reverse(ALL(A));
    ll l = -1,r = 100000000000000001;
    while(r-l>1){
        ll mid = (l+r)/2;
        if(f(mid)) r = mid;
        else l = mid;
    }
    cout << r << endl;
}


Measured memory_bytes: 4848
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cstring>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
using namespace std;
#define INT(x) int x; scanf("%d",&x)
#define INPUT(x) scanf("%d",&x)
#define REP1(x,n) for(int x = 0; x < n; x++)
#define REP2(x,s,e) for(int x = s; x <= e; x++)
#define RREP1(x,n) for(int x = n-1; x >= 0; x--)
#define RREP2(x,s,e) for(int x = s; x >= e; x--)
#define BR printf("\n")
#define INF 2000000000

typedef long long ll;

int main(){
    char s[200001];
    cin >> s;
    int len = strlen(s);
    
    int imos = 0;
    int dpair = 0;
    REP1(i,len){
        if (s[i] == 'S') {
            imos++;
        }else{
            if(imos > 0){
                dpair++;
                imos--;
            }
        }
    }
    
    cout << len - dpair*2 << endl;
    return 0;
}

Measured memory_bytes: 384
/* Blog: https://misteer.hatenablog.com/entry/AOJ-1620 */

#include <iostream>
#include <vector>
#include <string>

using namespace std;

constexpr int mask = (1 << 16) - 1;
constexpr int INF = 1 << 30;

/* ----- 真理値表埋め ----- */
vector<vector<int>> T(17);
// T[l] = 長さlの論理式で表せる真理値表の集合(lは最小)

vector<int> U(1 << 16, INF);
// T[t] = 真理値表tを表す最短の論理式の長さ

void init() {
    // 長さ1は0, 1, a, b, c, dのみ
    T[1] = {0b0000000000000000,
            0b1111111111111111,
            0b1010101010101010,
            0b1100110011001100,
            0b1111000011110000,
            0b1111111100000000};
    for (auto t : T[1]) U[t] = 1;

    for (int k = 2; k <= 16; ++k) {
        for (auto t : T[k - 1]) {
            int v = mask ^ t;  // notを合成
            if (U[v] == INF) {
                U[v] = k;
                T[k].push_back(v);
            }
        }

        for (int i = 1; i <= k - 3 - i; ++i) {
            // 長さの和がk-3になる組を全て試す
            for (auto t1 : T[i]) {
                for (auto t2 : T[k - 3 - i]) {
                    int v = t1 & t2;  // andを合成
                    if (U[v] == INF) {
                        U[v] = k;
                        T[k].push_back(v);
                    }

                    v = t1 ^ t2;  // xorを合成
                    if (U[v] == INF) {
                        U[v] = k;
                        T[k].push_back(v);
                    }
                }
            }
        }
    }
}

/* ----- 構文解析 ----- */
string S;
int pat;  // a, b, c, dの割り振り

bool expr(int&);

// expr^expr, expr*expr
bool bin(int& i) {
    bool ret = expr(i);
    if (S[i] == '*') {
        ++i;
        ret = expr(i) && ret;
    } else if (S[i] == '^') {
        ++i;
        ret = expr(i) != ret;
    }
    return ret;
}

// 0, 1, a, b, c, d
bool term(int& i) {
    bool ret;
    if ('0' <= S[i] && S[i] <= '1') {
        ret = S[i] - '0';
    } else if ('a' <= S[i] && S[i] <= 'd') {
        ret = (pat >> (S[i] - 'a')) & 1;
    }
    ++i;
    return ret;
}

// term, -expr, (bin)
bool expr(int& i) {
    bool ret;
    if (S[i] == '(') {
        ++i;
        ret = bin(i);
        ++i;
    } else if (S[i] == '-') {
        ++i;
        ret = !expr(i);
    } else {
        ret = term(i);
    }
    return ret;
}

/* ----- main ----- */
bool solve() {
    cin >> S;
    if (S == ".") return false;

    // 真理値表を計算
    int i, tab = 0;
    for (pat = 0; pat < (1 << 4); ++pat) {
        i = 0;
        tab += expr(i) << pat;
    }

    // 前計算で得たテーブルを参照
    cout << U[tab] << endl;
    return true;
}

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



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

int main() {
  int N, M;
  cin >> N >> M;
  int max_l = 0;
  int min_r = (int)pow(10,5);
  
  for (int i = 0; i < M; i++) {
    int l, r;
    cin >> l >> r;
    if (l > max_l) {
      max_l = l;
    }
    if (r < min_r) {
      min_r = r;
    }
  }
  int num = min_r - max_l + 1;
  if (num < 0) {
    num = 0;
  }
  cout << num << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
string s;
ll sum=0;
void dfs(int i,ll now)
{
	if(i==s.size())
	{
		sum+=now;
		return ;
	}
	ll cur=0;
	for(int j=i;j<s.size();j++)
	{
		cur=cur*10+s[j];
		dfs(j+1,now+cur);
	}
}
int main()
{
	cin>>s;
	for(int i=0;i<s.size();i++)
		s[i]-='0';
	dfs(0,0);
	cout<<sum<<endl;
	return 0;
}

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

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

    if (a > b)
    {
        swap(a, b);
    }

    if ((a == 2) & (b == 3))
    {
        cout << 1 << endl;
    }
    else if ((a == 1) & (b == 3))
    {
        cout << 2 << endl;
    }
    else
    {
        cout << 3 << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define FOR(i, x, y) for(int i = x; i < y; i++)
typedef long long ll;
using namespace std;

pair<int, int> A[100001], B[100001];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    FOR(i, 0, 100001) {
        A[i] = {0, i};
        B[i] = {0, i};
    }
    FOR(i, 0, n) {
        int a;
        cin >> a;
        if (i & 1) A[a].first++;
        else B[a].first++;
    }
    sort(A, A + 100001, greater<pair<int, int>>());
    sort(B, B + 100001, greater<pair<int, int>>());
    if (A[0].second == B[0].second) {
        cout << n - max(A[0].first + B[1].first, B[0].first + A[1].first) << '\n';
    } else cout << n - A[0].first - B[0].first << '\n';
    return 0;
}

Measured memory_bytes: 1792
macro_rules! extract {
    (String, $iter:expr) => {
        $iter.next().unwrap().trim().to_owned()
    };
    ($t:tt, $iter:expr) => {
        $iter.next().unwrap().trim().parse::<$t>().unwrap()
    };
}

macro_rules! read_split_impl {
    ( $e:expr, $( $t:tt ),* ) => {{
        let mut s = String::new();
        $e.read_line(&mut s).unwrap();
        let s = s.trim_right();
        let mut iter = s.split_whitespace();
        ( $(extract!($t, iter)),* )
    }};
}

macro_rules! read_split {
    ( $( $t:tt ),* ) => {
        read_split_impl!(std::io::stdin(), $($t),* )
    };
}

macro_rules! read_vec_impl {
    ($input:expr, $t:tt, $size: expr) => {
        {
            let mut s = String::new();
            $input.read_line(&mut s).unwrap();
            let s = s.trim_right();
            let mut v = Vec::with_capacity($size);
            for x in s.split_whitespace() {
                v.push(x.parse::<$t>().unwrap());
            }
            v
        }
    };
}

macro_rules! read_vec {
    ($t: tt, $size: expr) => {
        read_vec_impl!(std::io::stdin(), $t, $size)
    };
}

fn solve(v: &[i64]) -> i64 {
    let i = v.iter().position(|x| { *x == 1 });
    if let Some(i) = i {
        let mut result = i;
        let mut next = 2;
        for x in &v[i + 1 ..] {
            if *x == next {
                next += 1;
            } else {
                result += 1;
            }
        }
        result as i64
    } else {
        -1
    }
}

fn main() {
    let n = read_split!(usize);
    let v = read_vec!(i64, n);

    print!("{}", solve(&v));
}

Measured memory_bytes: 8444
from collections import deque
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
a_stack=deque([])
now=0
mn=0
j=0
for i in a:
  mn+=i
  if mn>k:
    mn-=i
    break
  else:
    now+=1
    a_stack.append(i)
for i in b:
  mn+=i
  if mn>k:
    mn-=i
    break
  else:
    now+=1
    j+=1
    if j==m:
      print(now)
      exit()
ans=now
while a_stack:
  if j>=m:
    break
  else:
    q=a_stack.pop()
    mn-=q
    now-=1
    while k-mn>0:
      mn+=b[j]
      now+=1
      if k-mn<0:
        now-=1
        mn-=b[j]
        break
      j+=1
      if j==m:
        break
    ans=max(now,ans)
print(ans)

Measured memory_bytes: 121484
#include <stdio.h>

void output( int a[], int n )
{
    int i;

    for( i = 0; i < n; i++ ) {
    printf( "%d", a[i] );
    if(i!=n-1)printf(" ");
    }
    printf( "\n" );
};

void bubbleSort( int a[], int n )
{
    int i, j, temp,change;
    change=0;
    for( i = 0; i < n-1; i++ ) {
        for( j = n-1; j > i; j-- ) {
            if( a[j-1] > a[j] ) {
                
                temp = a[j];
                a[j] = a[j-1];
                a[j-1] = temp;
                change=change+1;
               
            }
        }
    
    }
    output( a, n );
    printf("%d\n",change);
};

int main(void)
{
    int a[100], N, i;
    scanf("%d",&N);
    for(i=0;i<N;i++){
		scanf("%d",&(a[i]));
		
	}
  

 
    bubbleSort(a, N);
 
    
}

Measured memory_bytes: 2748
import java.util.Scanner

import scala.collection.mutable
import scala.collection.mutable.ArrayBuffer

object Main extends App {
  val in = new Scanner(System.in)
  val V = in.nextInt()
  val E = in.nextInt()
  val dinitz = new Dinitz(V)
  for (_ <- 0 until E) {
    val s = in.nextInt()
    val t = in.nextInt()
    val c = in.nextInt()
    dinitz.addEdge(s, t, c)
  }

  val f = dinitz.maxFlow(0, V - 1)
  println(f)
}

class Dinitz(val V: Int) {

  class Edge(var to: Int, var cap: Long, var rev: Int)

  private val graph = (for (_ <- 0 until V) yield new ArrayBuffer[Edge]()).toArray

  def addEdge(from: Int, to: Int, cap: Long): Unit = {
    graph(from).append(new Edge(to, cap, graph(to).size))
    graph(to).append(new Edge(from, 0, graph(from).size - 1))
  }

  def maxFlow(source: Int, sink: Int): Long = {
    var flow = 0L

    while (true) {
      val queue = new mutable.Queue[Int]()
      val level = Array.fill[Int](V)(-1)
      level(source) = 0
      queue.enqueue(source)
      while (queue.nonEmpty) {
        val v = queue.dequeue()
        for (e <- graph(v)) {
          if (e.cap > 0 && level(e.to) < 0) {
            level(e.to) = level(v) + 1
            queue.enqueue(e.to)
          }
        }
      }

      if (level(sink) < 0) return flow
      val iter = new Array[Int](V)

      def dfs(v: Int, t: Int, f: Long): Long = {
        if (v == t) return f

        while (iter(v) < graph(v).size) {
          val e = graph(v)(iter(v))
          if (e.cap > 0 && level(v) < level(e.to)) {
            val d = dfs(e.to, t, Math.min(f, e.cap))
            if (d > 0) {
              e.cap -= d
              graph(e.to)(e.rev).cap += d
              return d
            }
          }

          iter(v) += 1
        }
        0
      }

      var f = 1L
      while (f > 0) {
        f = dfs(source, sink, Long.MaxValue)
        flow += f
      }
    }

    throw new IllegalStateException()
  }
}

Measured memory_bytes: 53664
#include <iostream>
#include <vector>
using namespace std;
struct Node{
    int value;
    int id;
    vector<Node*> adjacent_nodes;
};
struct Result{
    vector<bool> marked;
    vector<int> route;
    vector<bool> last_marked;
};
Result* dfs(Node* head,Result *rt){
    rt->marked[head->id-1] = true;
    rt->route.push_back(head->value);
    for(Node* node:head->adjacent_nodes){
        if(!rt->marked[node->id-1]){
            rt = dfs(node,rt);
        }
    }
    return rt;
}
int main() {
    int N, M;
    cin >> N >> M;
    int count = 0;
    vector<Node*> graph;
    Result *rt = new Result;
    for (int i = 0; i < N; i++) {
        Node* node = new Node;
        cin >> node->value;
        node->id = i+1;
        graph.push_back(node);
        rt->marked.push_back(false);
        rt->last_marked.push_back(false);
    }
    for (int j = 0; j < M; j++) {
        int a, b;
        cin >> a >> b;
        graph[a - 1]->adjacent_nodes.push_back(graph[b - 1]);
        graph[b - 1]->adjacent_nodes.push_back(graph[a - 1]);
    }
    for (Node *head:graph) {
        if(!rt->marked[head->id-1]) {
            rt = dfs(head, rt);
            for (int i = 0; i < rt->route.size(); i++) {
                if(rt->marked[rt->route[i]-1]^rt->last_marked[rt->route[i]-1]) {
                    count++;
                }
            }
            rt->last_marked = rt->marked;
            rt->route.clear();
        }
    }
    cout<<count<<endl;
}


Measured memory_bytes: 12788
#include <iostream>
#include <vector>
#include <climits>
using namespace std;
using uint = unsigned int;
using ull = unsigned long long;

template <typename T> T mod_div(T a, T b, T m);
template <typename T> T mod_pow(T n, T r, T m);

int main() {
	uint H, N;
	cin >> H >> N;
	
	vector<uint> A(N);
	vector<uint> B(N);
	
	for(uint i=0; i<N; i++) {
		cin >> A[i] >> B[i];
	}

	vector<uint> dp(H+1, UINT_MAX);
	dp[0] = 0;
	
	for(uint k=1; k<=H; k++) {
		for(uint i=0; i<N; i++) {
			uint p = A[i];
			uint c = B[i];
			
			if(k >= p) {
				uint nc = c + dp[k - p];
				dp[k] = min(dp[k], nc);
			} else {
				dp[k] = min(dp[k], c);
			}
		}
	}

	cout << dp[H];
	return 0;
}

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

#define sz(a) int((a).size())
#define all(c) c.begin(), c.end()
#define ll long long
#define pb push_back
#define zoom                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define pl pair<ll, ll>
#define MOD 1000000007
#define endl "\n"
#define ff first
#define ss second
#define trace1(x) cerr << #x << ": " << x << endl
#define trace2(x, y) cerr << #x << ": " << x << " | " << #y << ": " << y << endl
#define trace3(x, y, z) cerr << #x << ":" << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl
#define trace4(a, b, c, d) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl
#define trace5(a, b, c, d, e) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl
#define trace(v)                                   \
    for (auto it = v.begin(); it != v.end(); it++) \
        cerr << *it << " ";                        \
    cerr << endl;
#define tr(container, it) \
    for (typeof(container.begin()) it = container.begin(); it != container.end(); it++)

#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

typedef pair<int, int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef vector<vi> vvi;

void solve()
{
    ll n,d;
    cin>>n>>d;

    int cnt=0;
    forn(i,n){
        ll x,y;
        cin>>x>>y;
        if(x*x+y*y<=d*d)cnt++;
    }   

    cout<<cnt<<endl;
}

int main()
{
    zoom;
    ll t=1;
    //cin >> t;

    while (t--)
    {
        solve();
    }
}

Measured memory_bytes: 3652
#include<iostream>
#include<string>
#include <vector>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<bitset>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using vs = vector<string>;
using pii = pair<int, int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define vsort(v) sort(v.begin(), v.end())
#define rv(v) reverse(v.begin(), v.end())
#define ll long long
#define PI 3.141592653589793
using vll = vector<ll>;
using Graph = vii;
const ll MOD = 1e9 + 7;

int main() {
	string s="win";
	vi a(3);
	rep(i, 3) {
		cin >> a[i];
	}
	int sum = 0;
	rep(i, 3) sum += a[i];
	if (sum >= 22) s = "bust";
	cout << s << endl;
}

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

using namespace std;
const int MAX = 1e5+5;

long int A[MAX], B[MAX], C[MAX];
long int DP[MAX][3];

int main() {
    int N; cin >> N;
    for(int i = 0; i < N; i++) {
        cin >> A[i] >> B[i] >> C[i];
    }

    DP[0][0] = A[0];
    DP[0][1] = B[0];
    DP[0][2] = C[0];

    for(int i = 1; i < N; i++) {
        DP[i][0] = max(DP[i][0], max(DP[i-1][1], DP[i-1][2]) + A[i]);
        DP[i][1] = max(DP[i][1], max(DP[i-1][0], DP[i-1][2]) + B[i]);
        DP[i][2] = max(DP[i][2], max(DP[i-1][0], DP[i-1][1]) + C[i]);
    }

    cout << max({DP[N-1][0], DP[N-1][1], DP[N-1][2]}) << "\n";
 

    return 0;
}

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

string s;
int cnt[26];

int main() {
int i;
cin >> s;
for (i = 0; i < s.length(); i++) {
cnt[s[i]-'a']++;
}
for (i = 0; i < 26; i++) { if (cnt[i] >= 2) break; }
if (i < 26) cout << "no" << endl;
else cout << "yes" << endl;
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
string s;
  cin>>s;
  int sum=0;
  int N=s.size();
  vector<int>vec(N);
  reverse(s.begin(),s.end());
  for(int i=0;i<N;i++)vec[i]=s[i]-'0';
  for(int i=0;i<N;i++){
    if(vec[i]<5)sum+=vec[i];
    else if(vec[i]==5){
      if(i!=N-1 &&vec[i+1]>=5){
        vec[i+1]++;
        sum+=5;
      }
      else sum+=5;
    }
    else {
      
      sum+=10-vec[i];
      if(i!=N-1)vec[i+1]++;
      else sum++;
    }
  }
  
    cout<<sum<<endl;
  }
 

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

struct UnionFind {
    UnionFind(int n) : p(n, -1) {}
    int root(int u) {
        return p[u] < 0 ? u : p[u] = root(p[u]);
    }
    bool same(int u, int v) {
        return root(u) == root(v);
    }
    void unite(int u, int v) {
        u = root(u);
        v = root(v);
        if (u == v) return;
        if (p[u] > p[v]) swap(u, v);
        p[u] += p[v];
        p[v] = u;
    }
    vector<int> p;
};

struct Edge {
    bool operator<(Edge o) { return c < o.c; }
    int i, j;
    int c;
};

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

    vector<int[2]> r(n);
    for (int i = 0; i < n; i++) {
        cin >> r[i][0] >> r[i][1];
    }

    vector<Edge> e;
    e.reserve(n * 2);
    vector<int> p(n);

    for (int j = 0; j < 2; j++) {
        for (int i = 0; i < n; i++) {
            p[i] = i;
        }
        sort(p.begin(), p.end(), [&](int i0, int i1) {
            return r[i0][j] < r[i1][j];
        });

        for (int i = 1; i < n; i++) {
            e.push_back({ p[i], p[i - 1], abs(r[p[i]][j] - r[p[i - 1]][j]) });
        }
    }

    sort(e.begin(), e.end());
    UnionFind uf(e.size());
    int c = 0, k = 0;

    for (const Edge& o : e) {
        if (uf.same(o.i, o.j)) continue;
        uf.unite(o.i, o.j);
        c += o.c;
        if (++k == n - 1) break;
    }

    cout << c << endl;

    return 0;
}

Measured memory_bytes: 4608
#ifndef LOCAL
#pragma GCC optimize("O3")
#endif
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);
typedef long long ll;
int main(){
	ll n ;
	cin >> n ;
	vector<ll> a(n) ,b(n) , c(n) ;
	for(ll i=0;i<n;i++){
		cin >> a[i] ;
	}
	for(ll i=0;i<n;i++){
		cin >> b[i] ;
	}
	for(ll i=0;i<n;i++){
		cin >> c[i] ;
	}
	sort(a.begin(),a.end()) ;
	sort(b.begin(),b.end()) ;
	sort(c.begin(),c.end()) ;
	ll ans = 0 ;
	for(ll i=0;i<n;i++){
		ll index1 = lower_bound(a.begin(),a.end(),b[i]) - a.begin() ;
		ll index2 = upper_bound(c.begin(),c.end(),b[i]) - c.begin() ;
		debug() << imie(index1) imie(index2) ;
		ans += index1 * (n-index2) ;
	}
	cout << ans << endl;
	return 0 ;
}
/*
1 2 3 4 4 5 6 7 8
0 1 2 3
*/


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

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

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

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, k;
    cin >> n >> k;

    vector< LLP > sushi(n);
    rep(i, n){
        cin >> sushi[i].second >> sushi[i].first;
        --sushi[i].second;
    }
    SORT_INV(sushi);

    vector<int> cnt(n);
    deque< LLP > deq;
    int x = 0;
    lint sum = 0;
    rep(i, k){
        if(cnt[sushi[i].second] > 0){
            deq.push_front(sushi[i]);
        }else{
            deq.push_back(sushi[i]);
            ++x;
        }
        ++cnt[sushi[i].second];
        sum += sushi[i].first;
    }

    vector<lint> v(n + 1);
    v[x] = sum;

    REP(i, k, n){
        while(i < n && cnt[sushi[i].second] > 0){
            ++i;
        }
        LLP tmp = deq.front();
        if(cnt[tmp.second] == 1 || i == n){
            break;
        }
        deq.pop_front();
        --cnt[tmp.second];
        ++cnt[sushi[i].second];
        ++x;
        sum += sushi[i].first - tmp.first;
        v[x] = sum;
    }

    lint ans = 0;
    rep(i, n + 1){
        if(v[i] == 0){
            continue;
        }
        ans = max(ans, (lint)i * (lint)i + v[i]);
    }

    cout << ans << endl;

    return 0;

}

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

int main(){
    int l, r,d;
    cin >> l >> r >>d;

    int ans = 0;

    for(int i = l; i <= r; i++){
        if(i%d == 0){
            ans++;
        }
    }

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

Measured memory_bytes: 3620
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

A,B,T=MAP()
T+=0.5
print(int((T//A)*B))


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

using namespace std;

int sum=100000;
int n,k;

void dfs(int a,int b){
	if(a==n+1)
	{
		sum=min(sum,b);
	}
	else {
		dfs(a+1,2*b);
		dfs(a+1,b+k);
	}
}

int main(){
	cin>>n>>k;
	dfs(1,1);
	cout<<sum;
}

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

int main()
{
	int q,i,j,x,y;
	cin>>q;
	int a[100005],b[100005],c[100005];
	for(i=2;i<=100000;i++)
		a[i]=1;
	for(i=2;i<=int(sqrt(100000));i++)
	{
		if(a[i]==1)
			for(j=i+i;j<=100000;j+=i)
				a[j]=0;
	}
	b[0]=0;
	b[1]=0;
	for(i=3;i<=100000;i++)
	{
		b[i]=0;
		if(a[i]==1 && a[(i+1)/2]==1)
			b[i]=1;
	}
	c[1]=0;
	c[2]=0;
	for(i=3;i<=100000;i++)
		c[i]=c[i-1]+b[i];
	for(i=1;i<=q;i++)
	{
		cin>>x>>y;
		cout<<c[y]-c[x-1]<<endl;
	}
	return 0;
}

Measured memory_bytes: 1792
import Data.List
import Data.Bool

main = putStrLn . unwords . map show . solve . map read . words =<< getContents

solve :: [Int] -> [Int]
solve (n:xs) = bool [cs+1, cs+1] [max 1 cs, cs+ts] ((head $ head xs') == 0)
    where
        ts = length $ head xs'
        cs = length xs' - 1
        xs' = group . sort $ map colorize xs

colorize x
    | x <= 399 = 1
    | x <= 799 = 2
    | x <= 1199 = 3
    | x <= 1599 = 4
    | x <= 1999 = 5
    | x <= 2399 = 6
    | x <= 2799 = 7
    | x <= 3199 = 8
    | otherwise = 0


Measured memory_bytes: 1020
n,m=map(int,input().split())
h=list(map(int,input().split()))
top=[]
for i in range(n):
  top.append(1)
for i in range(m):
  a,b=map(int,input().split())
  if h[a-1]<=h[b-1]:
    top[a-1]=0
  if h[b-1]<=h[a-1]:
    top[b-1]=0
print(sum(top))

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

typedef long long int ll;
ll powk(ll a, ll n = 2){
    ll r = 1;
    for(ll i = 0;i < n;i++){
        r *= a;
    }

    return r;
}

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

    vector<ll> ans(n);
    for(ll i = 0;i < n - 1;i++){
        ans[a[i] - 1]++;
    }

    for(ll i = 0;i < n;i++){
        cout << ans[i] << "\n";
    }

    return 0;
}

Measured memory_bytes: 6360