akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<functional>
#include<vector>
#include<stack>
#include<queue>
#include<iostream>
using namespace std;
int main(void)
{
	int i,j,k,n,x;
	int a,b,c,d,e,f,g,h,p;
	while(1){
		cin >> n;
		if(n==0) break;
		for(p=0;p<n;p++) {
			cin >>a>>b>>c>>d>>e>>f>>g>>h;
			x=(a*e)+(b*f*-1)+(c*g*-1)+(d*h*-1);
			i=(a*f)+(b*e)+(c*h)+(d*g*-1);
			j=(a*g)+(c*e)+(b*h*-1)+(d*f);
			k=(a*h)+(d*e)+(b*g)+(c*f*-1);
			cout <<x<<" "<<i<<" "<<j<<" "<<k<<endl;
		}
	}
}

Measured memory_bytes: 1160
N = int(input())

dp = [[[[0]*4 for i in range(4)] for j in range(4)] for k in range(N+1)]


dp[0][3][3][3] = 1

mod = 10**9+7

for length in range(N):
    for c3 in range(4):
        for c2 in range(4):
            for c1 in range(4):
                if dp[length][c3][c2][c1] == 0:
                    continue

                for a in range(4):
                    if c2 == 0 and c1 == 1 and a == 2:
                        continue
                    if c2 == 1 and c1 == 0 and a == 2:
                        continue
                    if c2 == 0 and c1 == 2 and a == 1:
                        continue
                    if c3 == 0 and c1 == 1 and a == 2:
                        continue
                    if c3 == 0 and c2 == 1 and a == 2:
                        continue

                    dp[length+1][c2][c1][a] += dp[length][c3][c2][c1]
                    dp[length+1][c2][c1][a] %= mod

ans = 0
for c3 in range(4):
    for c2 in range(4):
        for c1 in range(4):
            ans += dp[N][c3][c2][c1]
            ans %= mod

print(ans)


Measured memory_bytes: 3316
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long LL;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define rep(i,n) for (int i = 0; i < (n); ++i)

const int MOD = 1000000007;

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

    int N;
    cin >> N;

    vector<int> ans(N+1);
    rep(i, N-1) {
        int A;
        cin >> A;
        ++ans[A];
    }

    for (int i = 1; i <= N; ++i) {
        cout << ans[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 3996
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include<algorithm>

const int STRING_LEN = 10;
const int ALPHABET = 26;

using namespace std;


int main() {
	int n;
	cin >> n;
	long long ans = 0;
	vector<int> facto(n);
	
	

	map<string, int> map;
	for (int i = 0; i < n; i++) {
		string s;
		cin >> s;
		vector<int> cnt(ALPHABET);
		for (int i = 0; i < STRING_LEN; i++) {
			cnt[s[i] - 'a']++;
		}
		string new_s;
		for (int i = 0; i < ALPHABET; i++) {
			for (int j = 0; j < cnt[i]; j++) {
				new_s += ('a' + i);
			}
		}


		map[new_s]++;
		
	}

	for (auto i = map.begin(); i != map.end(); ++i) {
		long long num = i->second;
		


		ans += num * (num - 1) / 2;
		
	}

	cout << ans << endl;
}

Measured memory_bytes: 13184
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <map>
#include <string>

#define INF 99999999
#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 N_PRIME 1000000007

using namespace std;

void end(){cout<<0<<endl;exit(0);}

int main(void){
    int n;
    cin >> n;
    bool flag = false;
    vector<int> a(n);
    
    REP(i,n){
        int temp;
        cin >> temp;
        if( temp%2 == n%2 )
            end();
        
        a[temp]++;
    }
    
    REP(i,n)
        if( a[i] >= 3 )
            end();
    
    if( n % 2 == 1 ){
        if( a[0] != 1 ) 
            end();
    }
    
    
    int ret = 1;
    for(int i = 0 ; i < (n/2) ; i++ )
        ret = (ret * 2) % N_PRIME;
    
    cout << ret << endl;
    
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define N 1000000007
#define N2 998244353
#define Nmax 100005
#define INF (ll)1e18
#define pll pair<ll,ll>
#define mp make_pair
#define fi first
#define se second
#define vv vector
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(ll i=m;i<(n);i++)
#define repr(i,n) repr2(i,n,0)
#define repr2(i,m,n) for(ll i=m;i>=(n);i--)
#define get(n) ll (n); scanf("%lld",&(n));
#define get2(n,k) ll (n),(k); scanf("%lld%lld",&(n),&(k));
#define get3(n,m,k) ll (n),(m),(k); scanf("%lld%lld%lld",&(n),&(m),&(k));
#define gets(s) string (s); cin >> (s);
#define ALL(c) (c).begin(),(c).end()
#define fill_nums(A,n) vector<ll> A((n)); for(ll i=0;i<n;i++) scanf("%lld",&A[i]);
#define fill_edges(adj,m) for(ll i=0;i<m;i++) {ll a, b; scanf("%lld %lld",&a,&b); adj[a-1].pb(b-1); adj[b-1].pb(a-1);}
#define fill_direct(adj,m) for(ll i=0;i<m;i++) {ll a, b; scanf("%lld %lld",&a,&b); adj[a-1].pb(b-1);}
#define StarBurstStream ios_base::sync_with_stdio(false); cin.tie(0); //cout.tie(0);
#define pi 3.1415926535897
#define db long double  /* print with %Lf */
#define EPS 1e-9
#define flu fflush(stdout)
#define imp {cout<<"0\n"; return 0;}
#define yup {cout<<"YES\n"; return 0;}
#define debug_vec(vec,n) {rep(idxi,n) cout<<vec[idxi]<<" "; cout<<"\n";}
#define debug_pvec(vec,n) {rep(idxi,n) cout<<vec[idxi].fi<<"-"<<vec[idxi].se<<"  "; cout<<"\n";}
#define debug_set(seta) {cout<<seta.size()<<"\n"; for(auto idxi:seta) cout<<idxi<<" "; cout<<"\n";}
#define debug_map(mappa) {cout<<mappa.size()<<"\n";for(auto idxi:mappa) cout<<idxi.fi<<"-"<<idxi.se<<"  "; cout<<"\n";}
#define debug_vecvec(vec,n) {rep(idxi,n) {for(auto idxi2:vec[idxi]) cout<<idxi2<<" "; cout<<"\n";}}

int main() {

	get3(n,x,y); --x; --y;
	vv<ll> res(n-1);

	rep(i,n) {
		rep2(j,i+1,n) {
			int dist1 = abs(i-j);
			int dist2 = 1 + abs(i-x) + abs(y-j);
			int dist3 = 1 + abs(j-x) + abs(y-i);
			res[min(min(dist1,dist2),dist3)-1]++;
		}
	}

	for(auto i:res)
		printf("%lld\n", i);

	return 0;
}

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

#define en "\n"
#define INF (int) 9e18
#define HELL (int) (1e9 + 7)
#define int long long
#define double long double
#define uint unsigned long long
#define pii pair<int, int>
#define pb push_back
#define fs first
#define sc second
#define size(a) (int) a.size()
#define deb(x) cerr << #x << " => " << x << en
#define debp(a) cerr << #a << " => " <<"("<<a.fs<<", "<<a.sc<<") " << en;
#define deba(x) cerr << #x << en; for (auto a : x) cerr << a << " "; cerr << en;
#define debpa(x) cerr << #x << en; for (auto a : x)cerr<<"("<<a.fs<<", "<<a.sc<<") "; cerr << en;
#define debm(x) cerr << #x << en; for (auto a : x){for(auto b : a) cerr << b << " "; cerr << en;}
#define getMat(x, n, m, val) vector<vector<int>> x(n, vector<int> (m, val))
#define fastio ios_base :: sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define pout cout << fixed << setprecision(10)
int fastpow(int a, int b, int m = HELL) { int res = 1; a %= m;
while (b > 0) { if (b & 1) res = (res * a) % m; a = (a * a) % m; b >>= 1; } return res;}
#define inv(a) fastpow(a, HELL - 2)
#define mul(a, b) ((a % HELL) * (b % HELL)) % HELL

int32_t main() { fastio;
	int a, b; cin >> a >> b;
	cout << a * b << endl;
	return 0;
}


Measured memory_bytes: 3612
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define ll long long
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define vi vector<int>
using namespace std;
const int INF = 1001001001;
const int MOD = 1e9+7;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }

int main(){
  cin.tie(0), ios::sync_with_stdio(false);
  int n,k; cin >> n >> k;
  vi cnt(n);
  rep(i,k){
    int d; cin >> d;
    rep(j,d){
      int a; cin >> a;
      cnt[--a]++;
    }
  }
  int ans = 0;
  rep(i,n) if(!cnt[i]) ans++;
  cout << ans;
  cout << endl;
  return 0;
}


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

int N;

signed main(){
  
  cin>>N;
  
  set<int> div;
  
  for(int i=1;i*i<=N;i++){
    
    if( N % i == 0 ){
      div.insert(i);
      div.insert(N/i);
    }
    
  }
  
  vector<int> D;
  
  for(auto p : div ){
    if( p != N ) D.push_back(p);
  }
  
  int minv = 0;
  
  set<int> del;
  
  for(int i=(int)D.size()-1;i>=0;i--){
    
    if( del.count(D[i]) == 0 ){
      
      minv++;
      
      for(int j=i-1;j>=0;j--){
	
	if( D[i] % D[j] == 0 ){
	  del.insert(D[j]);
	}
	
      }
      
    }
    
  }
  
  cout<<minv<<' '<<D.size()<<endl;
  
  
  return 0;
}



Measured memory_bytes: 3160
A,B=map(int,input().split())
S=input()

N={"0","1","2","3","4","5","6","7","8","9"}
F=True
for i in range(A+B+1):
    if i!=A:
        F&=(S[i] in N)
    else:
        F&=(S[i]=="-")

if F:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 61768
N = int(input())
h = [int(i) for i in input().split()]

# 高さが全部0になるまでやる
ans = 0
while True:
    # 高さの最大が0だったらおしまい
    if max(h) == 0:
        break

    # 区間分割する
    i = 0
    while i < N:
        if h[i] == 0:  # 0なら何もせずに次に進む
            i += 1
        else:
            ans += 1  # 区間の始まり
            while i < N and h[i] > 0:
                h[i] -= 1  # ついでに引いとく
                i += 1
print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include<string>
#include<time.h>
#include<math.h>
#include<stdlib.h>
#include<map>
using namespace std;

int main() {
	int S, W;
	cin >> S >> W;
	if (S > W)cout << "safe" << endl;
	else cout << "unsafe" << endl;
	return 0;
}

Measured memory_bytes: 3592
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <cmath>
#include <cassert>
#include <string>
#include <iostream>

using namespace std;

typedef long long ll;

ll MOD = pow(10,9) + 7;


int main(){

    int a,b,c;
    cin >> a >> b >> c;

    if(a + b >= c){
        cout << b+c << endl;
    }else{
        cout << a + b*2 + 1 << endl;
    }


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	string s;
	cin>>s;
	if(s.size()%2){
		ll now=s.size()/2;
		char ch=s[now];
		ll cnt=1;
		for(ll i=1;now+i<s.size();i++){
			if(s[now+i]==ch&&ch==s[now-i]){
				cnt++;
			}
			else{
				break;
			}
		}
		cout << now+cnt;
	}
	else{
		ll now=s.size()/2;
		char ch=s[now];
		ll cnt=0;
		for(ll i=0;now+i<s.size();i++){
			if(s[now+i]==ch&&ch==s[now-i-1]){
				cnt++;
			}
			else{
				break;
			}
		}
		cout << now+cnt;
	}
	// your code goes here
	return 0;
}

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

int main()
{
    char c;
    int n;
    cin >> n;
    int r = 0,b =0;
    string str;
    cin >> str;
    for(int i = 0; i < n; i++){
        c = str[i];
        if(c == 'R')r++;
        else b++;
    }
    cout << ((r > b) ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int F[45];

int fibo(int n){
  if(n==0 || n==1) return F[n] = 1;
  if(F[n] != -1) return F[n];
  return F[n] = fibo(n-2) + fibo(n-1);
}

int main(){
  int i,n;
  for(i=0; i<45; i++){
    F[i] = -1;
  }

  scanf("%d",&n);
  printf("%d\n",fibo(n));
}



Measured memory_bytes: 2048
//Codes by: Umar Bin Qamar

#include <bits/stdc++.h>
using namespace std;
#define int long long

bool compare(int a,int b){
    return a>b;
}

int32_t main(){

//int count=0;
  int n,m,k;
  cin>>n>>m;
  //cin>>p;
  int arr[10010];
  int count=0;
  for(int i=0;i<m;i++){
   cin>>k;
   count+=k;
  }
  if(n-count>=0){
    cout<<n-count<<endl;
  }
  else{
    cout<<"-1"<<endl;
  }


    return 0;
}



Measured memory_bytes: 3636
package main

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

func solve() {
	n := getInt()
	cSum := make([]int, n+1)
	max := 0
	for i := 1; i <= n; i++ {
		a := getInt()
		max += a
		cSum[i] = cSum[i-1] + a
	}

	idxl, idxr := -1, -1
	for i, cs := range cSum {
		if cs*2 >= max {
			idxl = i - 1
			idxr = i
			break
		}
	}

	dl := max - cSum[idxl]*2
	dr := cSum[idxr]*2 - max
	ans := min(dl, dr)
	fmt.Fprintln(wr, ans)
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}

// -----------------------------------------

const (
	inf = 1 << 60
	// mod = 1000000007
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func main() {
	// buf := 200001
	// sc.Buffer(make([]byte, buf), buf)
	sc.Split(bufio.ScanWords)
	solve()
	wr.Flush()
}

func getInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func getIntSlice(n int) []int {
	is := make([]int, n)
	for i := range is {
		is[i] = getInt()
	}
	return is
}

func getString() string {
	sc.Scan()
	s := sc.Text()
	return s
}

func getRunes() []rune {
	return []rune(getString())
}


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

using namespace std;
typedef long long LL;

#ifdef BTK
#define DEBUG if(1)
#else
#define CIN_ONLY if(1)
struct cww {cww() {CIN_ONLY{ios::sync_with_stdio(false); cin.tie(0);}}
}star;
#define DEBUG if(0)
#endif

#define ALL(v) (v).begin(),(v).end()
#define REC(ret, ...) std::function<ret (__VA_ARGS__)>
template <typename T>inline bool chmin(T &l, T r){bool a = l>r; if (a)l = r; return a;}
template <typename T>inline bool chmax(T &l, T r){bool a = l<r; if (a)l = r; return a;}
template <typename T>istream& operator>>(istream &is, vector<T> &v){for (auto &it : v)is >> it;return is;}

class range {private: struct I { int x; int operator*() { return x; }bool operator!=(I& lhs) { return x<lhs.x; }void operator++() { ++x; } }; I i, n;public:range(int n) :i({ 0 }), n({ n }) {}range(int i, int n) :i({ i }), n({ n }) {}I& begin() { return i; }I& end() { return n; }};
typedef pair<LL, LL> P;

int main() {
	int N;
	cin >> N;
	int k = N;
	N = 1 << N;
	
	vector<LL> A(N);
	cin >> A;
	vector<vector<P>> dp(N);
	for (int i : range(N)) {
		dp[i].push_back({ A[i],i });
	}
	for (int i : range(k)) {
		dp[1<<i].push_back({ A[0],0 });
	}
	LL ret = 0;
	for (int b : range(1,N)) {
		sort(ALL(dp[b]));
		reverse(ALL(dp[b]));
		unique(ALL(dp[b]));
		chmax(ret, dp[b][0].first + dp[b][1].first);
		cout << ret << endl;
		for (int i : range(k)) {
			int nb = b | (1 << i);
			if (b == nb)continue;
			dp[nb].push_back(dp[b][0]);
			dp[nb].push_back(dp[b][1]);
		}
	}
	return 0;
}


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


int main(void) {
    int n;
    cin >> n;
    char s;
    bool flag = false;
    rep(i,n){
        cin >> s;
        if(s == 'Y')flag = true;
    }
    if(flag)puts("Four");
    else puts("Three");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
typedef long long ll;
int main() {
  int N, A, B; cin >> N >> A >> B;
  if((B-A)%2==0) cout << "Alice" << endl;
  else cout << "Borys" << endl;
}

Measured memory_bytes: 512
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.PrintWriter;
import java.io.IOException;
import java.util.Arrays;

public class Main {

    public static void main(String[] args) throws IOException{
        BufferedReader reader = null;
        PrintWriter writer = null;
        
        try {
            reader =new BufferedReader(new InputStreamReader(System.in));
            writer = new PrintWriter(System.out);
            
            int N = Integer.parseInt(reader.readLine());
            int[] topLine = Arrays.asList(reader.readLine().split(" ")).stream()
                            .mapToInt(w -> Integer.parseInt(w))
                            .toArray();
            int[] bottomLine = Arrays.asList(reader.readLine().split(" ")).stream()
                               .mapToInt(w -> Integer.parseInt(w))
                               .toArray();
            int[] amechanNum = new int[N];
            
            for(int i = 0; i < N; i++){
                int topAmechanNum = 0;
                int bottomAmechanNum = 0;
                
                for(int a = 0; a < i + 1; a++) topAmechanNum += topLine[a];
                for(int b = i; b < N; b++) bottomAmechanNum += bottomLine[b];
                
                amechanNum[i] = topAmechanNum + bottomAmechanNum;    
                
            }
            Arrays.sort(amechanNum);
                    
            writer.println(amechanNum[N - 1]);
            
        }finally{
            if(reader != null){
                reader.close();
            }
            if(writer != null){
                writer.close();
            }
        }

    }
}

Measured memory_bytes: 28116
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ll INF = 1e18;
const long double EPS = 1e-10;

int main() {
  int n, k, x, y;
  cin >> n >> k >> x >> y;

  if (n <= k) cout << n * x << endl;
  else cout << k * x + (n - k) * y << endl;
  


  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pi acos(-1)
#define mx 1000000000
#define mod 1000000009
#define pii pair<int,int>
#define psi pair<string,int>
#define vi vector<int>
typedef long long ll;
using namespace std;
void fastio()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("inputf.txt", "r", stdin);
    freopen("outputf.txt", "w", stdout);
#endif
    fastio();
    int i,j,t,n,m,r;
    //cin>>t;
    //while(t--){
    cin>>n>>m;
    if(n>m)swap(n,m);
    for(i=1;i<=m;i++)cout<<n; 
    //}
 return 0;
}



Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
#define rep(i, a, n) for (int i = a; i < n; ++i)

vector<vector<int>> G;
vector<int> memo;

int dp(int i) {
    if (memo[i] != -1) {
        return memo[i];
    }

    int tmp = 0;
    for (auto v : G[i]) {
        tmp = max(tmp, dp(v) + 1);
    }

    return memo[i] = tmp;
}

int main() {
    int n, m;
    cin >> n >> m;
    G.resize(n);
    rep(i, 0, m) {
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        G[x].push_back(y);
    }

    memo.resize(n, -1);
    int ans = 0;
    rep(i, 0, n) {
        ans = max(ans, dp(i));
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 8192
eval"H,W,*A="+`dd`.split*?,
B=A.pop H*W
d=[1<<t=10**4]+[0]*~-W
H.times{N=0
d=d.zip(A.shift(W).zip(B.shift W).map{|a,b|(a-b).abs}).map{|d,t|d|=N
N=d<<t|d>>t}}
p (0..2*t).map{|i|(t-i*N[i]).abs}.min

Measured memory_bytes: 27400
N = int(input())
xs, ys = [], []
for _ in range(N):
    x, y = map(int, input().split())
    xs.append(x)
    ys.append(y)

from operator import itemgetter
xis = sorted(list(enumerate(xs)), key=itemgetter(1))
yis = sorted(list(enumerate(ys)), key=itemgetter(1))

xds, yds = [], []
for i in range(N - 1):
    xds.append((xis[i + 1][1] - xis[i][1], (xis[i][0], xis[i + 1][0])))
    yds.append((yis[i + 1][1] - yis[i][1], (yis[i][0], yis[i + 1][0])))

from collections import deque
xdq, ydq = deque(sorted(xds)), deque(sorted(yds))

par = list(range(N))
def find(x):
    if x == par[x]:
        return x
    else:
        par[x] = find(par[x])
        return par[x]

def union(x, y):
    rx, ry = find(x), find(y)
    par[ry] = rx

ans = 0
while xdq or ydq:
    if xdq and (not ydq or xdq[0] < ydq[0]):
        d, (i, j) = xdq.popleft()
    else:
        d, (i, j) = ydq.popleft()
    if find(i) != find(j):
        ans += d
        union(i, j)

print(ans)


Measured memory_bytes: 73588
def factorial(num)
  result = 1
  (1..num).each do |i|
    result *= i
    if result > (10**9+7)
      result %= 10**9+7
    end
  end
  return result
end
line = gets
data = line.split(" ")
n = data[0].to_i
m = data[1].to_i
result = 0
if (n-m) == 0
  fac = factorial(n)
  result = 2 * fac ** 2 
elsif (n-m) == 1
  fac = factorial(m)
  result = fac ** 2 * n
elsif (m-n) == 1
  fac = factorial(n)
  result = fac ** 2 * m
end
if result > (10**9+7)
  result %= 10**9+7
end
puts result

Measured memory_bytes: 1788
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
 
#define  rep(i, n) for(int i = 0; i < (int)(n);    i++)
#define rrep(i, n) for(int i = ((int)(n)-1); i>=0; i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()

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; }
typedef long long ll;

ll gcd ( ll a, ll b ) { if ( b == 0 ) return a; else return gcd ( b, a%b ); }
ll lcm ( ll a, ll b ) { return a * b / gcd(a, b); }


int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  int N; std::cin >> N;
  std::vector<int>  P(N);   rep(i, N) std::cin >> P[i];
  std::vector<int> UP(N+1); rep(i, N) UP[P[i]] = i;

  std::set<int> idx;
  ll ans = 0;
  for(int X=N; X>=1; X--) {
    int index = UP[X];

    int LL = -1, L = -1, R = N, RR = N;
    auto itr = idx.lower_bound(index);
    if (itr != idx.end()) {
      R  = *itr;
      itr++;
    }
    if (itr != idx.end()) RR = *itr;

    itr = idx.lower_bound(index);
    if (itr != idx.begin()) {
      itr--;
      L  = *itr;
    }
    if (itr != idx.begin()) {
      itr--;
      LL = *itr;
    }

    ll l1 = index - L, l2 = L - LL;
    ll r1 = R - index, r2 = RR - R;
    ans += (l1 * r2 + l2 * r1) * X;

    idx.insert(index);
  }
  std::cout << ans << std::endl;
  return 0;
}



Measured memory_bytes: 5760
if __name__ == "__main__":
    x, n = [int(a) for a in input().split()]
    p = list(map(int, input().split()))
    p.sort()
    i = 0
    ans =-1
    if x not in p:
        print(x)
        exit()
    while True:
        i += 1
        if (x-i) not in p:
            ans = x-i
            break
        elif (x+i) not in p:
            ans = x+i
            break
    print(ans)


Measured memory_bytes: 9192
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>

using namespace std;

typedef long long ll;
typedef double db;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef string S;
typedef queue<int> qi;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define sort(a) sort(a.begin(),a.end())
#define reverse(a) reverse(a.begin(),a.end())
#define pb push_back
#define ft first
#define sd second
#define elif else if
#define unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define mp make_pair
#define fr(i,n)for(ll i=0;i<(n);i++)
#define ifr(i,n)for(ll i=(n)-1;i>=0;i--)
const int MOD = 1e9+7;
const ll INF =1e18;

int main(){
    ll n, k;cin>>n>>k;
    vl h(n);
    fr(i,n) cin>>h[i];
    if(n<=k+1){
        cout<< abs(h[n-1]-h[0])<<endl;
    }else{
        vl dp(n);
        fr(i,k) dp[i+1] = abs(h[i+1]-h[0]);
        for(ll i = k+1;i<n;i++){
            ll p = INF;
            for(ll j=i-k;j<i;j++){
                p = min(p, dp[j] + abs(h[i]-h[j]));
            }
            dp[i] = p;
        }
        cout << dp[n-1] << endl;
    }
}

Measured memory_bytes: 1792
#include<cstdio>
using namespace std;
int main(){
  int n,b;
  long ans=1,a[1001];
  for(int i=0;i<=1000;i++)
    a[i]=1;
  scanf("%d",&n);
  for(int i=1;i<=n;i++){
    b=i;
    for(int j=2;j<=n;j++){
      while(b%j==0){
        a[j]++;
        b/=j;
      }
      if(b==1)
        break;
    }
  }
  for(int i=2;i<=n;i++){
    ans*=a[i];
    ans%=1000000007;
  }
  printf("%ld\n",ans);
}

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

main() {
  string A; cin >> A;
  ll n = A.length();
  ll ans = n * (n - 1) / 2;
  for (int i = 0; i < 26; i++) {
    ll cnt = 0;
    for (int j = 0; j < n; j++) {
      if (A[j] == 'a' + i) cnt++;
    }
    ans -= cnt * (cnt - 1) / 2;
  }
  ans++;
  cout << ans << endl;
}


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

int main()
{
    string S;
    cin >> S;
    for (int i = 0;i < 3;i++)
    {
        if(S[i] == S[i+1]){
            cout << "Bad" << endl;
            return 0;
        }
    }
    cout << "Good" << endl;
}

Measured memory_bytes: 256
X=int(input())
if X>=1800:
  a=1
elif X>=1600:
  a=2
elif X>=1400:
  a=3
elif X>=1200:
  a=4
elif X>=1000:
  a=5
elif X>=800:
  a=6
elif X>=600:
  a=7
else:
  a=8
print(a)

Measured memory_bytes: 9168
n,m=list(map(int,input().split()))
a=list(map(int,input().split()))
a=list(map(lambda x:x*(-1),a))

import heapq
heapq.heapify(a)
for i in range(m):
  q=heapq.heappop(a)
  heapq.heappush(a,int(q/2))
print(sum(a)*(-1))

  
  

Measured memory_bytes: 20020
// 問題の URL を書いておく
// 

#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <bitset>
#include <numeric>
using namespace std;

//#define ENABLE_PRINT

template<typename T>
T Input()
{
    T v;
    cin >> v;
    return v;
}

template<typename T>
vector<T> InputVector(int n)
{
    vector<T> v(n);
    for(int i = 0; i < n; ++i)
    {
        cin >> v[i];
    }
    return v;
}

template<typename T>
void InputArray(T* begin, int n)
{
    for(int i = 0; i < n; ++i)
    {
        cin >> begin[i];
    }
}

#if defined(ENABLE_PRINT)

#define Print(v) \
do {\
    cout << #v << ": " << v << endl; \
}while(0)

#define PrintVec(v) \
do {\
    for(int __i = 0; __i < v.size(); ++__i) \
    { \
        cout << #v << "[" << __i << "]: " << v[__i] << endl; \
    }\
}while(0)

#else

#define Print(v) ((void)0)
#define PrintVec(v) ((void)0)

#endif

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

#if 0
int main(int, const char**)
{
    int n, k;
    cin >> n >> k;
    vector<vector<int>> as(k + 1, vector<int>(n, 0));
    rep(i, n)
    {
        cin >> as[0][i];
    }
    rep(i, k)
    {
        rep(j, n)
        {
            auto a = as[i][j];
            rep(l, a + 1)
            {
                if(l == 0)
                {
                    as[i + 1][j]++;
                    continue;
                }
                auto i0 = j - l;
                auto i1 = j + l;
                if(i0 >= 0)
                {
                    as[i + 1][i0]++;
                }
                if(i1 <= n - 1)
                {
                    as[i + 1][i1]++;
                }
            }
        }
    }
    rep(i, n)
    {
        cout << as[k][i] << " ";
    }
    cout << endl;
    return 0;
}
#endif

int main(int, const char**)
{
    int n, k;
    cin >> n >> k;
    k = min(k, 50);
    vector<vector<int>> as(k + 1, vector<int>(n, 0));
    rep(i, n)
    {
        cin >> as[0][i];
    }
    int ei = 0;
    rep(i, k)
    {
        rep(j, n)
        {
            auto a = as[i][j];
            auto pi = max(0, j - a);
            as[i + 1][pi]++;
            auto mi = j + a + 1;
            if(mi <= n - 1)
            {
                as[i + 1][mi]--;
            }
        }
#if 0        
        rep(j, n)
        {
            cout << as[i + 1][j] << " ";
        }
        cout << endl;
#endif   
        for(int j = 1; j < n; ++j)
        {
            as[i + 1][j] += as[i + 1][j - 1];
        }
        ei = i + 1;
    }
    rep(i, n)
    {
        cout << as[ei][i] << " ";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 43916
def check(m, e):
    return len(list(filter(lambda x: x >= m - 1, e)))


def main():
    N = int(input())
    e = [0] * (N + 1)

    for i in range(2, N + 1):
        ii = i
        for j in range(2, i + 1):
            while ii % j == 0:
                e[j] += 1
                ii //= j

    print(check(75, e) +
          check(25, e) * (check(3, e) - 1) +
          check(15, e) * (check(5, e) - 1) +
          check(5, e) * (check(5, e) - 1) * (check(3, e) - 2) // 2)


if __name__ == '__main__':
    main()


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

int n,m,q;
int a[60],b[60],c[60],d[60];

int ans = 0;

void dfs(int depth, int val, vector<int> A ){ 
  if( depth == n ){ 
    
    int sum = 0;
    
    for(int i = 0; i < q; i++){ 

      if( A[b[i]]-A[a[i]] == c[i] ){ 
        sum += d[i];
      }
    }
    
    ans = max(ans, sum);
    
    return;
  }//caliculate
  
  for(int i = val; i <= m; i++){ 
    A.push_back(i);
    dfs(depth+1,i,A);
    A.pop_back();
  }
  
  return ;
}
  
  
                        
signed main(void){
  
  cin >> n >> m >> q;
  for(int i = 0; i < q; i++){ 
    cin >> a[i] >> b[i] >> c[i] >> d[i];
    a[i]--; b[i]--;
  }
  
  vector<int> vec;
  
  dfs( 0,1,vec );
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 3620
function F()
  N = parse(BigInt,readline())
  S = Vector{Char}(readline())
  
  
  
  C = []
  wl = 0
  rl = 0
  
  wr = count(x->x=='W',S)
  
  rr = count(x->x=='R',S)
  if rr<=wl
    C = append!(C,wl)
  else
    C = append!(C,wr)
  end
  
  for i=1:N
    if S[i] == 'W'
      wl += 1
      wr -= 1
    else
      rl += 1
      rr -= 1
    end
    if wl<=rr
      c = rr
    else
      c = wl
    end
    C = append!(C,c)
  end
  ans = minimum(C)
  println(ans)
end

F()

Measured memory_bytes: 237468
#include <stdio.h>

int main() {
    int R, G, B, N;
    int Ri, Gi, Bi;
    int N_tmp, N_tmp_tmp;
    long A = 0;

    scanf("%d %d %d %d", &R, &G, &B, &N);

    Ri = N / R;
    for (; Ri >= 0; Ri--) {
        N_tmp = N;
        N_tmp -= Ri * R;
        if (N_tmp == 0) {
            A++;
            continue;
        }
        Gi = N_tmp / G;
        for (; Gi >= 0; Gi--) {
            N_tmp_tmp = N_tmp;
            N_tmp_tmp -= Gi * G;
            if (N_tmp_tmp == 0) {
                A++;
                continue;
            }
            Bi = N_tmp_tmp / B;
            N_tmp_tmp -= Bi * B;
            if (N_tmp_tmp == 0) {
                A++;
            }
        }
    }

    printf("%ld", A);

    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <utility>
#include <algorithm>
#include <functional>
#include <numeric>
#include <list> 
#include <cmath>
#include <stdio.h>

using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(),x.end()
#define INF (1e9)

typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> P;

#define CAPITAL
void Yes(bool ex=true){
	#ifdef CAPITAL
	cout<<"YES"<<endl;
	#else
	cout<<"Yes"<<endl;
	#endif
	if(ex)exit(0);
}
void No(bool ex=true){
	#ifdef CAPITAL
	cout<<"NO"<<endl;
	#else
	cout<<"No"<<endl;
	#endif
	if(ex)exit(0);
}

int main() {
    string S;
    cin >> S;
    ll count = 0;
    ll ans = 0;
    REP(i, S.size()) {
        if (S[i] == 'B') {
            count += 1;
        } else {
            ans += count;
        }
    }
    printf("%lld", ans);
}

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


int main() {
	int N; cin >> N;
	string S; cin >> S;
	int ans = 0;
	for (int l = 0; l < N; l++) {
		string s = S.substr(l);
		vector<int> V(N - l);
		for (int x = 0; x < N - l; x++) {
			V[x] = 0;
		}
		V[0] = N - l;
		int i = 1; int j = 0;
		while (i < N - l) {
			while (i + j < N - l and s[j] == s[i + j]) {
				j++;
			}
			if (j == 0) {
				i++;
				continue;
			}
			V[i] = j;
			int k = 1;
			while (i + k < N - l and k + V[k] < j) {
				V[i + k] = V[k];
				k++;
			}
			i += k;
			j -= k;
		}
		for (int x = 0; x < N - l; x++) {
			if (V[x] <= x) {
				ans = max(ans, V[x]);
			}
		}
	}
	cout << ans << endl;
	
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define all(a) (a).begin(),(a).end()
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=10000000000000000;

int main(){
    ll n;
    cin >> n;
    cout << (n)*(n-1)/2 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    string s;
    cin >> s;
    for (int i = 0; i < 3; i++) {
        if(s.at(i) == s.at(i + 1)) {
        cout << "Bad" <<endl;
        return 0;
        }
    }
    cout << "Good" <<endl;
}

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

int main()
{
	string s;
   int t = 0;

   cin >> s;

   for(int i=0; i<s.length(); i++){
		if(t==0){
			if(i%2==0){
				if(s.substr(i,1)=="R" || s.substr(i,1)=="U" || s.substr(i,1)=="D"){
              t=0;
            }
            else{t=1;}
         }
         else{
				if(s.substr(i,1)=="L" || s.substr(i,1)=="U" || s.substr(i,1)=="D"){
              t=0;
            }
            else{t=1;}				
         }
      }
      else{
			break;
      }
   }

   if(t==0){
    cout << "Yes" << endl;
   }
   else{
    cout << "No" << endl;
   }

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    static long x;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] abx = sc.nextLine().split(" ");
        long a = Long.parseLong(abx[0]);
        long b = Long.parseLong(abx[1]);
        x = Long.parseLong(abx[2]);

        long ans = solve(b) - solve(a - 1);
        System.out.println(ans);
    }

    private static long solve(long n) {
        if (n >= 0) {
            return n / x + 1;
        } else {
            return 0;
        }
    }
}


Measured memory_bytes: 25044
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(), (c).end()
#define sz(c) (static_cast<int>(c.size()))
#define endl "\n"
#ifdef DEBUG
#define dump(v) cerr << "["#v << ":" << (v) << "]" << endl;
#else
#define dump(v)
#endif
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
const ll MOD = (1e9+7);
const ll INF = (1e9+123456789);
const ll INFL = (INF*INF);
inline ll addm(ll a, ll b, ll m = MOD) {return ((a+b)%m);}
inline ll subm(ll a, ll b, ll m = MOD) {return (((a-b)%m+m)%m);}
inline ll mulm(ll a, ll b, ll m = MOD) {return ((a*b)%m);}
ll powm(ll a, ll b, ll m = MOD) {ll ret=(!b)?1:powm(a, b/2, m);return (!b)?1:mulm(mulm(ret,ret,m),b%2?a:1,m);}
ll inv(ll x, ll m = MOD) {return powm(x,m-2,m);}

void solve()
{
    int r,g,b,n;
    cin >> r >> g >> b >> n;
    ll ans = 0;
    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= n; j++) {
            ll rem = n-r*i-g*j;
            if (0 <= rem && rem <= n && (rem % b) == 0)
                ++ans;
        }
    }
    cout << ans << endl;
}

int main()
{
    cin.sync_with_stdio(0); cin.tie(NULL);
    solve();
    return 0;
}


Measured memory_bytes: 256
K, A, B = map(int, input().split())

# 交換するまで枚数が増えない
# 交換しない方が価値がある
if K + 2 < A or A + 2 > B:
    cookie = 1 + K
else:

    exchangeCount = (K - (A - 1)) // 2
    extraTapCount = (K - (A - 1)) % 2

    cookie = A

    cookie += (B - A) * exchangeCount

    cookie += extraTapCount

print(cookie)


Measured memory_bytes: 3060
#include<stdio.h>
#include<math.h>

int main(){
	int a[3],d,n,i,t;
	double e;
	
	while(0<=scanf("%d%d%d",&a[0],&a[1],&a[2])){
	if(a[0]==0 && a[1]==0 && a[2]==0){
		break;
	}
	
	for(n=0;n<3;n++){
	for(i=n;i<3;i++){
	if(a[n]>a[i]){
		t=a[n];
		a[n]=a[i];
		a[i]=t;
	}
	}
	}
	
	e=sqrt(a[0]*a[0]+a[1]*a[1]);
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&d);
		if(d*2>e){
			printf("OK\n");
		}else{
			printf("NA\n");
		}
	}
	}
	return 0;
		}

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

using namespace std;
typedef long long int lld;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define trav(a,v) for(auto a:v)
lld fact[1000000];
lld inv[1000000];
lld M;
lld ModPow(lld base, lld exp){
  if(exp==0)return 1;
  if(exp%2==1)return (base*ModPow(base,exp-1))%M;
  lld a=ModPow(base,exp/2);
  return (a*a)%M;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin>>N>>M;
  fact[0]=1;
  inv[0]=1;
  rep(i,1,6*N+5){
    fact[i]=i*fact[i-1];
    fact[i]%=M;
    inv[i]=ModPow(fact[i],M-2);
  }
  lld ans=0;
  rep(x1,0,3*N+1){
    rep(x2,0,x1+1){
      lld x3=3*N-2*x2-x1;
      if(x3>=0 && x3%3==0){
	x3/=3;
	//cout<<x1<<" "<<x2<<" "<<x3<<endl;
	lld can=1;
	can*=fact[3*N];
	can%=M;
	can*=inv[3*N-3*x3];
	can%=M;
	can*=ModPow(ModPow(3,M-2),x3);
	can%=M;
	can*=inv[x3];
	can%=M;

	can*=fact[3*N-3*x3];
	can%=M;
	can*=inv[3*N-3*x3-2*x2];
	can%=M;
	can*=ModPow(ModPow(2,M-2),x2);
	can%=M;
	can*=inv[x2];
	can%=M;
	ans+=can;
	ans%=M;
	//cout<<can<<endl;
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 2432
def main():
    _ = input()
    A = [(i+1, int(a)) for (i, a) in enumerate(input().split())]
    A.sort(key=lambda x: x[1])
    ans = list(zip(*A))[0]
    print(*ans, sep=" ", end="\n")
    
    
if __name__ == '__main__':
    main()


Measured memory_bytes: 73900
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>

using namespace std;

int main ()
{
	int n,a,b1=0,b2=0;
	scanf ("%d",&n);
	for (int i=1;i<=n;i++)
	{
		scanf ("%d",&a);
		if (a%2==1) b1++;
		if (a%4==0) b2++;
	}
	if ((b2>=b1)||(b2+1==b1 && b2+b1==n)) 
		printf ("Yes\n");
	else printf ("No\n");
	return 0;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  int64_t a, b, n;
  cin >> a >> b >> n;
  cout << floor(1.0*a*min(n, b-1)/b) << endl;
  return 0;
}

Measured memory_bytes: 3712
from sys import stdin, setrecursionlimit


def main():
    input = stdin.readline
    s, t = map(str, input().split())
    a, b = map(int, input().split())
    u = input()[:-1]
    print(a - 1, b) if s == u else print(a, b - 1)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


Measured memory_bytes: 38256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repf(i,a,b) for (int i = (a); i < (b); i++)
#define repi(i,a,b) for (int i = (a); i <= (b); i++)
#define repr(i,a,b) for (int i = (a); i >= (b); i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SORT(x) sort(all(x));
#define RSORT(x) sort(rall(x));
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vd = vector<double>;
using vb = vector<bool>;
using pii = pair<int, int>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;
using tiii = tuple<int, int, int>;
const int inf = 1<<29;
const ll mod = 1000000007;
const double eps = 1e-9;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

int main () {
  int N; cin >> N;
  
  if(1<=N && N<=9) {
    cout << N-1+1 << endl;
  }
  else if(N<=99) {
    cout << 9 << endl;
  }
  else if(N<=999) {
    cout << 9+(N-100+1) << endl;
  }
  else if(N<=9999) {
    cout << 9+900 << endl;
  }
  else if(N<=99999) {
    cout << 9+900+(N-10000+1) << endl;
  }
  else {
    cout << 90909 << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i = 0;i<((ll)(n));i++)
#define reg(i,a,b) for(ll i = ((ll)(a));i<=((ll)(b));i++)
#define irep(i,n) for(ll i = ((ll)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(ll i = ((ll)(b));i>=((ll)(a));i--)
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

/*
AC
順番に行っても最適性を失わない
*/

ll n,a,b,x[100010],ans=0;

int main(void){
	cin>>n>>a>>b;
	rep(i,n){
		cin>>x[i];
		if(i==0)continue;
		if(a*(x[i]-x[i-1])<b){
			ans+=a*(x[i]-x[i-1]);
		}else{
			ans+=b;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>

int main(){
  int ans=0,n;scanf("%d",&n);
  if(n%10==2){
  ans++;
  }   n=(n-(n%10))/10;
  if(n%10==2){
  ans++;
  }   n=(n-(n%10))/10;
  if(n%10==2){
  ans++;
  }   n=(n-(n%10))/10;
  if(n%10==2){
  ans++;
  }   n=(n-(n%10))/10;
  printf("%d\n",ans);
  return 0;
}

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

int w,sum;
string str;

int main(){
	while(1){
		cin>>w;
		if(w==-1){break;}
		if(w<=10){cout<<4280-1150<<endl;}
		else if(w<=20){cout<<4280-(1150+(w-10)*125)<<endl;}
		else if(w<=30){cout<<4280-(1150+1250+(w-20)*140)<<endl;}
		else {cout<<4280-(1150+1250+1400+(w-30)*160)<<endl;}
	}
	
	return 0;
}

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

int main() {

    int N;
    cin >> N;

    vector<int> V, C;
    int tmp;

    for (int i = 0; i<N; i++) {
        cin >> tmp;
        V.push_back(tmp);
    }
    for (int i = 0; i<N; i++) {
        cin >> tmp;
        C.push_back(tmp);
    }

    int sum = 0;
    for (int i = 0; i<N; i++) {
        if (V[i] > C[i]) {
            sum += (V[i] - C[i]);
        }
    }
    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 256
def main():
    K, X = map(int, input().split(" "))
    lower = max(X - K + 1, -1000000)
    upper = min(X + K, 1000000)
    ans = ""
    for i in range(lower, upper):
        ans = ans + str(i) + " "
    print(ans[:-1])


if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <fstream>
//#define REP(i, n) for(int i = 0; i < n; i++)
//#define REPR(i, n) for(int i = n; i >= 0; i--)
//#define FOR(i, m, n) for(int i = m; i < n; i++)
//#define INF 1e9
//#define ALL(v) v.begin(), v.end()

using namespace std;
//typedef long long ll;

int main() { //int argc, const char * argv[]


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

    //std::cout << "Hello, World!\n";
    
    int A, B, ans;
    cin>>A>>B;
    ans=max(0,A-2*B);
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main(void){
int a,b,c,d,e=0;
char s[100];
int i;
scanf("%d%d",&a,&b);
scanf("%s",s);
c=strlen(s);
d=a+b+1;
for(i=0;i<c;i++){
	if(s[i]=='-'){
		
		e++;
		
	}
	
	
}
if((s[a]=='-')&&(c==d)&&(e==1)){
	
	
	printf("Yes\n");
	
	
}else{
	
	printf("No\n");
	
}
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
main(){
  int a[4],b[4];
  int i,j,hit,blow,tmp;
  while(1){
    hit=0,blow=0,tmp=0;
    if(scanf("%d",&a[0])==EOF)
      break;
    for(i=1;i<4;i++)
      scanf("%d",&a[i]);
    for(i=0;i<4;i++)
      scanf("%d",&b[i]);
    for(i=0;i<4;i++)
      for(j=0;j<4;j++)
        if(a[i]==b[j])
          tmp++;
    for(i=0;i<4;i++)
      if(a[i]==b[i])
        hit++;
    blow=tmp-hit;
    printf("%d %d\n",hit,blow);
  }
  return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int k;
    cin>>k;
    string s;
    cin>>s;
    int l=s.length();
    if(l<=k)
        cout<<s<<endl;
    else{
        for(int i=0;i<k;i++){
            cout<<s[i];
        }
        cout<<"..."<<endl;
    }
}


Measured memory_bytes: 3596
A=int(input())
B=int(input())
C=int(input())
X=int(input())
cnt=0

for i in range(0,A+1):
  for j in range(0,B+1):
    for k in range(0,C+1):
      if 500*i+100*j+50*k==X:
        cnt +=1
print(cnt)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>

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

  unsigned N = 0;
  std::cin >> N;
  std::vector<int> vec(N, 0);
  for (unsigned i = 0; i < N; ++i)
  { 
    std::cin >> vec[i];
  }
  int f = vec[0], s = vec[1];
  vec[0] = 0;
  vec[1] = abs(f - s);
  for (size_t i = 2; i < vec.size(); ++i)
  { 
    int m = std::min(vec[i-2] + abs(f - vec[i]), vec[i-1] + abs(s - vec[i]));
    f = s;
    s = vec[i];
    vec[i] = m;
  }
  std::cout << vec[N-1];

  return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K =sc.nextInt();
        int[] d = new int[K];
        int[] A = new int[N];
        boolean[] Sunuke = new boolean[N];
        int ans = 0;
        
        for(int i = 0; i < K; i++) {
        	d[i] = sc.nextInt();
        	for(int j = 0; j < d[i]; j++) {
        		A[j] = sc.nextInt();
        		Sunuke[A[j]-1] = true;
        	}
        }
        
        for(int i = 0; i < N; i++) {
        	if(Sunuke[i] == false) ans++; 
        }
        
        System.out.println(ans);

 

        
        }
	}



Measured memory_bytes: 46312
#include <iostream>
#include <string>
#include <stdio.h>
#include <cmath>
#include <cfloat>
#include <algorithm>
#include <numeric>
#include <vector>
#include <iterator>
#include <set>
#include <map>
using namespace std;

const double PI=acos(-1);

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

    vector<long> l;
    for(long i = 1; i * i <= n; i++){
        if(n%i == 0){
            l.push_back(i);
            if(i*i != n) l.push_back(n/i);
        }
    }
    long ans = 9999999999999999;
    for(int i = 0; i < l.size(); i++){
        for(int j = 0; j < l.size(); j++){
            if(l[i] * l[j] == n){
                ans = min(ans, l[i] + l[j] - 2);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
	string s; cin >> s; ll k; cin >> k;
	bool al = true;
	for (int i = 0; i < s.length() - 1; i++)if (s.at(i) != s.at(i + 1))al = false;
	ll ans = 0;
	if (s.at(0) != s.at(s.length() - 1)) {
		for (int i = 0; i < s.length() - 1; i++) {
			if (s.at(i) == s.at(i + 1)) {
				s.at(i + 1) = 'A';
				ans++;
			}
		}
		ans *= k;
	}
	else if (al == true) ans = s.length() * k / 2;
	else {
		string sl, sm, sr;
		for (int i = 0; i < s.length(); i++) {
			if (s.at(i) != s.at(i + 1)) {
				sl = s.substr(0, i + 1);
				sr = s.substr(i + 1);
				sm = sr + sl;
				break;
			}
		}
		ans += sl.length() / 2;
		ll x = 0;
		for (int i = 0; i < sm.length() - 1; i++) {
			if (sm.at(i) == sm.at(i + 1)) {
				sm.at(i + 1) = 'A';
				x++;
			}
		}
		ans += x * (k - 1);
		for (int i = 0; i < sr.length() - 1; i++) {
			if (sr.at(i) == sr.at(i + 1)) {
				sr.at(i + 1) = 'A';
				ans++;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
A,B,Q = gets.chomp.split(" ").map(&:to_i)
s = A.times.map{gets.to_i}
t = B.times.map{gets.to_i}
x = Q.times.map{gets.to_i}
s.sort!
t.sort!
Q.times do |i|
  x1 = (0...s.size).bsearch{|j| s[j] >= x[i]}
  y1 = (0...t.size).bsearch{|j| t[j] >= x[i]}
  x2 = x1 == nil ? A-1 : x1-1
  y2 = y1 == nil ? B-1 : y1-1
  min = 10 ** 12
  if x1 != nil && y2 != -1
    d = [s[x1] - x[i], x[i] - t[y2]].min * 2 + [s[x1] - x[i], x[i] - t[y2]].max
    min = d if d < min
  end
  if y1 != nil && x2 != -1
    d = [t[y1] - x[i], x[i] - s[x2]].min * 2 + [t[y1] - x[i], x[i] - s[x2]].max
    min = d if d < min
  end
  if x1 != nil && y1 != nil
    d = [s[x1],t[y1]].max - x[i]
    min = d if d < min
  end
  if x2 != -1 && y2 != -1
    d = x[i] - [s[x2],t[y2]].min
    min = d if d < min
  end
  puts min
end

Measured memory_bytes: 17936
#include <iostream>
using namespace std;
int main()
{
	int N,Y,x,y,z;
	cin>>N>>Y;
	for(x=0;x<=Y/10000;x++)
		for(y=0;y<=Y/5000;y++)
		{
			z=N-x-y;
			if(z>=0&&x*10000+y*5000+z*1000==Y)
			{
				cout<<x<<' '<<y<<' '<<z;
				return 0;
			}
		}
	cout<<"-1 -1 -1";
	return 0;
}

Measured memory_bytes: 384