akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
 
// Shrotening
#define fst first
#define snd second
#define pb push_back
 
// Loop
#define FOR(i,a,b) for(auto i=(a);i<(b);++i)
#define RFOR(i,a,b) for(auto i=(a);i>=(b);--i)
 
#define REP(i,a) for(long i=0;i<(a);++i)
#define RREP(i,a) for(long i=(a);i>=0;--i)
 
#define EACH(i,a) for(auto (i)=(a).begin(),_END=(a).end();i!=_END;++i)
#define REACH(i,a) for(auto (i)=(a).rbegin(),_END=(a).rend();i!=_END;++i)
 
//Algorithm
#define ALL(a) (a).begin(), a.end()
#define RALL(a) (a).rbegin(), a.rend()
#define EXIST(a,x) ((a).find(x)!=(a).end())
#define SORT(a) std::sort((a).begin(), (a).end())
#define UNIQUE(a) std::sort((a).begin(), a.end()), a.erase(std::unique((a).begin(), a.end()), a.end());
#define SUM(a) std::accumulate((a).begin(), (a).end(), 0);
 
//Setting
#define OPT std::cin.tie(0);std::ios::sync_with_stdio(false);
 
//debug message
bool debug = true;
#define MSG(s)   if(debug){std::cout << s << std::endl;}
#define DEBUG(x) if(debug){std::cout << "debug(" << #x << "): " << x << std::endl;}
 
//alias
typedef long long LL;
typedef std::vector<bool> VB;
typedef std::vector<char> VC;
typedef std::vector<int>  VI;
typedef std::vector<long> VL;
typedef std::vector<long long> VLL;
 
typedef std::vector< VB > VB2;
typedef std::vector< VC > VC2;
typedef std::vector< VI > VI2;
typedef std::vector< VL > VL2;
typedef std::vector< VLL > VLL2;
 
typedef std::pair<int,int> PII;
 
int N;
std::vector< PII > d(1000);
VI2 dp(1003, VI(1003));
 
int main() {
    while(std::cin >> N, N != 0) {
        REP(i, N) {
            std::cin >> d[i].fst >> d[i].snd;
        }
        std::sort(d.begin(), d.begin() + N);
 
        int sum = 0;
        REP(i, N-1) {
            //1~N-1までの和
            sum += d[i].fst;
        }
        if(sum >= d[N-1].fst) {
            int ans = 0;
            REP(i, N) {
                ans += (d[i].fst + d[i].snd);
            }
            std::cout  << ans << std::endl;
        } else {
            dp.assign(1003, VI(1003, 0));
            dp[0][0] = 1;
 
            int rem = d[N-1].fst - sum;
            REP(i, N-1) {
                REP(j, rem + 1) {
                    dp[i+1][j] |= dp[i][j];
                    dp[i+1][j + d[i].snd] |= dp[i][j];
                }
            }
 
            int maxi = 0;
            REP(i, rem + 1) {
                if(dp[N-1][i]) {
                    maxi = std::max(maxi, (int)i);
                }
            }
 
            int t = rem - maxi;
            REP(i, N) {
                t += d[i].snd;
            }
            std::cout << d[N-1].fst + sum + t << std::endl;
        }
    }
}


Measured memory_bytes: 6640
#include <iostream>

using namespace std;

int main()
{
	int n;
	int num[201];
	int kai = 0;
	int i, j;
	int guu = 0;
	
	cin >> n;
	
	for (i = 0; i < n; i++){
		cin >> num[i];
	}
	while (1){
		for (i = 0; i < n; i++){
			if (num[i] % 2 == 0){
				guu++;
			}
			if (guu == n){
				kai++;
				for (i = 0; i < n; i++){
					num[i] /= 2;
				}
			}
		}
		if (guu != n)break;
		guu = 0;
	}
	
	cout << kai << "\n";
	
	return (0);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
const int INF=1e9,MOD=1e9+7;
const long long LINF=1e18;
using namespace std;
#define int long long
//template
//main
signed main(){
  int N,K;;string s;cin>>N>>K>>s;
  std::vector<int> v;
  int tmp=0;char now=s[0];
  for(int i=0;i<N;i++){
    if(s[i]==now)tmp++;
    else{
      v.push_back(tmp);
      tmp=1;
      now=(now+1)%2+'0';
    }
  }
  v.push_back(tmp);
  if(s[0]=='0'){
    if(v.size()<=2*K){cout<<N<<endl;return 0;}
    int res=0,ans=0;
    if(v.size()%2)v.push_back(0);
    for(int i=0;i<2*K;i++){
      res+=v[i];
    }
    int l=-1;int r=2*K-1;
    ans=res;
    while(true){
      res+=v[r+1]+v[r+2];
      if(l==-1)res-=v[0];
      else res-=v[l]+v[l+1];
      ans=max(ans,res);
      l+=2;r+=2;
      if(r==v.size()-1)break;
    }
    cout<<ans<<endl;
  }
  else{
    if(v.size()<=2*K+1){cout<<N<<endl;return 0;}
    int res=0,ans=0;
    if(v.size()%2==0)v.push_back(0);
    for(int i=0;i<2*K+1;i++){
      res+=v[i];
    }
    int l=0;int r=2*K;
    ans=res;//cout<<ans<<endl;
    while(true){
      res+=v[r+1]+v[r+2];
      res-=v[l]+v[l+1];
      ans=max(ans,res);//cout<<ans<<endl;
      l+=2;r+=2;
      if(r==v.size()-1)break;
    }
    cout<<ans<<endl;
  }
  //for(int i:v)cout<<i<<" ";cout<<endl;
}


Measured memory_bytes: 1528
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#include<stack>
#include<set>
#include<algorithm>
#include<utility>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const int INF = 1001001001;

ll pow_mod(ll x, ll y) {
	ll res = 1;
	for (ll i = 0; i < y; i++) res = res * x % mod;
	return res;
}

ll gcd(ll x, ll y) {
	if (y == 0) {
		return x;
	}
	return gcd(y, x % y);
}

int main() {
	int n;
	cin >> n;
	ll ans = 0;
	for (int a = 1; a < n; a++) {
		if (n % a == 0) ans += n / a - 1;
		else ans += n / a;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3636
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <locale>
#include <iostream>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()

using namespace std;

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

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> int len(const T &x) { return x.size(); }

template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
  auto val = table(args...);
  return vector<decltype(val)>(n, move(val));
}

struct yes_no : numpunct<char> {
  string_type do_truename()  const { return "Yes"; }
  string_type do_falsename() const { return "No"; }
};

void solve(ll N, vector<ll> A) {
  map<ll,int> cnt;
  for (ll i: A) cnt[i]++;
  int res = 0;
  for (auto e: cnt) res += e.second % 2;
  cout << res << endl;
}

int main() {
  locale loc(locale(), new yes_no);
  cout << boolalpha << setprecision(12) << fixed;
  cout.imbue(loc);
	ll N;
	scanf("%lld", &N);
	vector<ll> A(N-1+1);
	for (int i = 0 ; i <= N-1 ; i++) {
	  scanf("%lld", &A[i]);
	}
	solve(N, A);
	return 0;
}


Measured memory_bytes: 8064
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <random>
#include <chrono>
#include <utility>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <sstream>
#include <assert.h>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <unordered_map>
using namespace std;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(bool x) {cerr << (x ? "true" : "false");}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}

template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";}
template <typename T, typename... V>void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef HOME
#warning CHECK int:ll::INT_MAX:LLONG_MAX
#define maxn 20
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define maxn 2000006
#define gcd __gcd
#define debug(x...)
#endif

#define ff first
#define endl '\n'
#define ss second
#define inf 0x3f3f3f3f
#define MOD 1000000007
#define PI 3.14159265358979323846264338327950L
#define f(i,x,n) for(int i=x;i<=n;i++)
#define fr(i,x,n) for(int i=x;i>=n;i--)
struct _ { ios_base::Init i; _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); } } _;

int dx[] = { -1, 0, 1, 0, -1, -1, 1, 1};
int dy[] = {0, 1, 0, -1, -1, 1, 1, -1};


int main() {

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

	//a[i]<tot/4m => a[i]*4m<tot

	int cnt = 0;
	for (int i = 0; i <= n - 1; i++) {
		if (a[i] * 4 * m >= tot) cnt++;
	}

	cout << ((cnt >= m) ? "Yes" : "No");

	return 0;

}

Measured memory_bytes: 3136
#include <stdio.h>

int main(void){
    int a,b;
    scanf("%d %d",&a,&b);
    if(a>b){
        printf("a > b");
    }else if(a<b){
        printf("a < b");
    }else{
        printf("a == b");
    }
    printf("\n");
}


Measured memory_bytes: 2060
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int GCD(const int& a, const int& b){
   const int& _a = max(a,b);
   const int& _b = min(a,b);
   if(_a % _b == 0){
      return _b;
   }
   else{
      return GCD(_b, _a % _b);
   }
}

int LCM(const int& a, const int& b){
   const int& _a = max(a,b);
   const int& _b = min(a,b);
   return (_a*_b)/(GCD(_a, _b));
}

int main(){
   vector<int> x(5), idx(5);
      for(int i = 0; i < 5; i++){
         cin >> x[i];
         idx[i] = i;
      }

   // 順列全探索(5! = 120通り)を行う解法.
   // idxに対してdo-while(next_permutation)を行い,
   // total経過時間の最小値を探索する.
   int ans = INF;
   do{
      int cost = 0;
      for(int i = 0; i < x.size(); i++){
         while(cost % 10 != 0){
            cost++;
         }
         cost += x[idx[i]];
      }
      ans = min(ans, cost);
   }while(next_permutation(idx.begin(), idx.end()));

   cout << ans << endl;

   return 0;
}

Measured memory_bytes: 256
//2020-05-18

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

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

    int n;
    cin >> n;
    
    string s, a;
    cin >> s;
    
    for (int i=0;i<min((int)s.length(), n);i++){
        a += s.at(i);
    }

    cout << a;
    if (s.length() > n)
        cout << "...";
    return 0;
}


Measured memory_bytes: 3128
#include<iostream>
int main()

{
    long n;
    std::cin>>n;
    long long a;
    long long ans=1;
    long double check=1;
    for(int i = 0; i < n; i++){
        std::cin>>a;
        ans*=a;
        check*=a;
    }
    if(check>1000000000000000000){
        std::cout << -1 << std::endl;
    }
    else{
        std::cout << ans << std::endl;
    }
}

Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <iomanip>
#define intt long long

intt func(intt n) {
	intt r = 0;
	while (n > 0) {
		r += n;
		--n;
	}
	return r;
}

int main() {
	std::string s; std::cin >> s;
	intt N = s.size();
	intt ans = 0;
	std::vector<intt> L(N + 1), R(N + 1);
	for (intt i = 0; i < N; ++i)
		if (s[i] == '<')
			L[i + 1] = L[i] + 1;
	for (intt i = N - 1; i >= 0; --i)
		if (s[i] == '>')
			R[i] = R[i + 1] + 1;
	for (intt i = 0; i < N + 1; ++i)
		ans += std::max(L[i], R[i]);
	std::cout << ans << std::endl;
}

Measured memory_bytes: 11676
#include<stdio.h>
int main()
{
	int friends=0,game=0,yosou=0,i=0,j=0,k=0,target[1000]={0},point[1000]={0};
	scanf("%d",&friends);
	scanf("%d",&game);
	for(i=0;game>i;i++){
		scanf("%d",&target[i]);
	}
	for(i=0;game>i;i++){
		for(j=1;friends>=j;j++){
			scanf("%d",&yosou);
			if(target[i]==yosou){
				k=j;
				point[k]=point[k]+1;
			}
			else if(target[i]!=yosou){
				k=target[i];
				point[k]=point[k]+1;
			}
		}
	}
	for(k=1;friends>=k;k++){
		printf("%d\n",point[k]);
	}
	return 0;
	
}


Measured memory_bytes: 1928
#define _USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <deque>
#include <climits>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
//#include <tuple>

#define break break
#define continue continue
#define INF INT_MAX>>1 
#define SIZE 100010
#define MOD 1000000007
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define rep2(i, from, to) for(int i=(from); i<(int)(to); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define LLPair pair<ll, ll>
#define vint vector<int>
#define vll vector<ll>
typedef long long ll;

using namespace std;

ll dp[100100];

int main(void){
	ll n; cin >> n;
	vll a(n);
	rep(i, n) cin >> a[i];

	dp[0] = 1;
	ll count[3];
	fill(count, count+3, 0);
	rep2(i, 0, n){
		int tmp = 0;
		rep(j, 3){
			if(count[j] == a[i]) tmp++;
		}
		dp[i+1] = dp[i]*tmp;
		dp[i+1] %= MOD;
		rep(j, 3){
			if(count[j] == a[i]){
				count[j]++;
				break;
			}
		}
	}
	cout << dp[n] << endl;
	return 0;
}

Measured memory_bytes: 1920
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        int n;
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        int[] a = new int[n];
        sc.reset();
        for(int i = 0; i<n;i++){
            a[i] = sc.nextInt();
        }
        insertionSort(a,n);
//        System.out.println(Arrays.toString(a));
    }

    static void insertionSort(int[] arrays, int n){
        showArrays(arrays);
        int i,j,v;
        for(i=1;i<n;i++){
            v=arrays[i];
            j=i-1;
            while(j>=0 && arrays[j]>v){
                arrays[j+1] = arrays[j];
                j--;
            }
            arrays[j+1] = v;
            showArrays(arrays);
        }
    }

    static void showArrays(int[] arrays){
        String str = "";
        for(int a: arrays){
            str += Integer.toString(a)+ " ";
        }
        System.out.println(str.trim());
    }
}

Measured memory_bytes: 46060
#include<stdio.h>
signed main(){
    int X, Y;
    scanf("%d%d", &X,&Y);
    if(X*2 <= Y && Y<=X*4 && Y % 2 == 0){
        printf("Yes\n");
    }else{
     printf("No\n");
    }
    return (0);
}

Measured memory_bytes: 1564
#include <bits/stdc++.h>
using namespace std;
vector<int> g[100005];
int data[100005];
vector<int> road;

set<int> tmp;

bool dfs(int n, int end, int from)
{
    //printf("%d\n", n);
    if (n == end)
        return true;
    for (auto each : g[n])
    {
        if (each != from && dfs(each, end, n) == true)
        {
            road.push_back(each);
            tmp.insert(each);
            return true;
        }
    }
    return false;
}

void calc(int n, int from, int first)
{
    if (tmp.find(n) != tmp.end() && n != first)
        return;
    ++data[first];
    for (auto each : g[n])
    {
        if (each != from)
        {
            calc(each, n, first);
        }
    }
}

int main()
{
    int n, a, b, black = 0;
    scanf("%d", &n);
    for (int i = 0; i < n - 1; ++i)
    {
        scanf("%d%d", &a, &b);
        g[a].push_back(b);
        g[b].push_back(a);
    }
    dfs(1, n, 0);
    road.push_back(1);
    tmp.insert(1);
    for (auto each : road)
    {
        calc(each, 0, each);
        
        //printf("%d\n", each);
        
    }
    //puts("end");
    //for (int i = 1; i <= n; ++i)
        //printf("%d\n", data[i]);
    for (int i = road.size()/2; i < road.size(); ++i)
    {
        black += data[road[i]];
        //printf("%d %d\n", data[road[i]], road[i]);
    }
    if (black > n - black)
        puts("Fennec");
    else
        puts("Snuke");
    return 0;
}


Measured memory_bytes: 18936
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<queue>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;
typedef pair<int, int> P;

struct edge {
	int to, num;
};
vector<edge> G[100010];
int a[100010], b[100010];
int color[100010];

void dfs(int v, int parent, int c) {
	ll cnt = 1;
	for (int i = 0; i < G[v].size(); i++) {
		if (G[v][i].to == parent) continue;
		if (cnt == c) {
			cnt++;
		}
		color[G[v][i].num] = cnt;
		dfs(G[v][i].to, v, cnt);
		cnt++;
	}
}
int main()
{
	int N; cin >> N;
	for (int i = 0; i < N - 1; i++) {
		cin >> a[i] >> b[i];
		a[i]--; b[i]--; 
		G[a[i]].push_back({ b[i],i });
		G[b[i]].push_back({ a[i],i });
	}
	dfs(0, -1, 0);
	int ans = 0;
	for (int i = 0; i < N - 1; i++) {
		ans = max(ans,(int) G[i].size());
	}
	cout << ans << endl;
	for (int i = 0; i < N - 1; i++) {
		cout << color[i] << endl;
	}
}

Measured memory_bytes: 9856
#include <stdio.h>
#include <string.h>

int main(void)
{
  char str[1001];
  int n;
  char com[1001];
  int a, b;
  char ch[1001];
  int i, j, k;
  char t;

  scanf("%s", str);

  scanf("%d", &n);

  for(i = 0; i < n; i++){
    scanf("%s %d %d", com, &a, &b);
    
    if(strcmp(com, "print") == 0){
      for(j = a; j <= b; j++)
	printf("%c", str[j]);

      putchar('\n');
    }
    
    if(strcmp(com, "reverse") == 0)
      for(j = a, k = b; j <= (a + b) / 2; j++, k--){
	t = str[j];
	str[j] = str[k];
	str[k] = t;
      }
    
    if(strcmp(com, "replace") == 0){
      scanf("%s", ch);
      
      for(j = 0; j <= b - a; j++)
	str[a + j] = ch[j];

    }
  }

  return 0;
}

Measured memory_bytes: 580
dp = {}

n = int(input())
a = [int(i) for i in input().split()]

q = int(input())
ms = [int(i) for i in input().split()]

def solve(i, m):
  global n, a

  if  (i, m) in dp:
    return dp[(i, m)]

  if m == 0:
    dp[(i, m)] = True
  elif n <= i:
    dp[(i, m)] = False
  elif solve(i + 1, m):
    dp[(i, m)] = True
  elif solve(i + 1, m - a[i]):
    dp[(i, m)] = True
  else:
    dp[(i, m)] = False
  
  return dp[(i, m)]

for m in ms:
  if solve(0, m):
    print('yes')
  else:
    print('no')



Measured memory_bytes: 9580
NM = list(map(int,input().split()))
N = NM[0]
M = NM[1]

A =[]
while True:
    try:
        A.append(int(input()))
    except:
        break;

countlist = [1,1,2]
if N >3:
    for i in range(3,N+1):
        a = countlist[i-2]+countlist[i-1]
        if a>1000000007:
            a = a%1000000007
        countlist.append(a)

t = 0
count = 0
out = []

if N >1:
    for i in range(1,N+1):
        count+=1
        if ((t<len(A))and(i==A[t])):
            t+= 1
            while ((t<len(A))and(i==A[t])):
                t+=1
            if count > 0:
                out.append(countlist[count-1])
            else:
                out.append(0)
                break
            count = -1


if count>=0:
    out.append(countlist[count])

output = 1

for i in range(len(out)):
    output = output*out[i]
    if output > 1000000007:
        output = output%1000000007

print(output)

Measured memory_bytes: 11040
//18
#include<iostream>
#include<algorithm>

using namespace std;

int main(){
  for(int n;cin>>n,n;){
    bool kn[100][101]={{}};
    for(int i=0;i<n;i++){
      int m;
      cin>>m;
      while(m--){
	int p;
	cin>>p;
	kn[i][p]=true;
      }
    }
    int k;
    cin>>k;
    bool pr[100];
    fill(pr,pr+100,true);
    while(k--){
      int l;
      cin>>l;
      for(int i=0;i<n;i++){
	if(!kn[i][l]){
	  pr[i]=false;
	}
      }
    }
    cout<<((count(pr,pr+n,true)!=1)?-1:find(pr,pr+n,true)-pr+1)<<endl;
  }
  return 0;
}

Measured memory_bytes: 1176
#include <iostream>
#include <string>
using namespace std;
int main() {
    string a;
    cin >> a;
    for (int i = 0; i < a.size(); i++) {
        if (a[i] == 'C') {
            for (int j = i; j < a.size(); j++) {
                if (a[j] == 'F') {
                    cout << "Yes";
                    return 0;
                }
            }
        }
    }
    cout << "No";
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<cctype>
using namespace std;
signed main()
{
	int a,b,c,d;
	scanf("%d%d%d%d",&a,&b,&c,&d);int e(a+b),f(c+d);
	puts(((e>f)?("Left"):((e<f)?("Right"):("Balanced"))));
	return 0;
}

Measured memory_bytes: 256
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;


int main(){
    int n;
    cin>>n;
    vector<pair<pair<string,int>,int>> A(n);
    for(int i=0;i<n;i++){cin>>A[i].first.first>>A[i].first.second; A[i].first.second*=-1; A[i].second=i+1;}
    sort(A.begin(),A.end());
    for(int i=0;i<n;i++){cout<<A[i].second<<endl;}
    
    return 0;
}


Measured memory_bytes: 256
import copy
import random

n = int(input())

D = []
for x in range(n):
    D.append(list(map(int, input().split())))

dup = 0

roll = [3,3,3,3,1,3,3,3,1,3,3,3,2,3,3,3,2,3,3,3,1,3,3,3]
for x in range(n):
    for r in roll:
        if r == 0:
            Dt = copy.copy(D[x])
            temp = Dt[0]
            Dt[0] = Dt[4]
            Dt[4] = Dt[5]
            Dt[5] = Dt[1]
            Dt[1] = temp
        elif r== 1:
            Dt = copy.copy(D[x])
            temp = Dt[0]
            Dt[0] = Dt[2]
            Dt[2] = Dt[5]
            Dt[5] = Dt[3]
            Dt[3] = temp
        elif r== 2:
            Dt = copy.copy(D[x])
            temp = Dt[0]
            Dt[0] = Dt[3]
            Dt[3] = Dt[5]
            Dt[5] = Dt[2]
            Dt[2] = temp
        elif r == 3:
            Dt = copy.copy(D[x])
            temp = Dt[0]
            Dt[0] = Dt[1]
            Dt[1] = Dt[5]
            Dt[5] = Dt[4]
            Dt[4] = temp

        D[x] = copy.copy(Dt)
        
        for y in range(n):
            if x == y:
                continue
            else:
                flag = 0           
                for z in range(6):
                    if D[x][z] == D[y][z]:
                        flag += 1
                if flag == 6:
                    dup  = 1
                    print("No")
                    exit()

print("Yes")                




Measured memory_bytes: 8236
#include<bits/stdc++.h>
#define pb push_back
#define pii pair<int,int>
#define int long long int
#define vec vector<int>
#define mp map<int,int>
#define inf 1e18
using namespace std;
int32_t main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int tt=1;
  //cin>>tt;
  while(tt--)
  {
    int n;
    cin>>n;
    int a[n],b[n],i;
    for(i=0;i<n;i++)
        cin>>a[i]>>b[i];
    int kh=1;
    for(i=0;i<n-2;i++)
    {
      if(a[i]==b[i] && a[i+1]==b[i+1] && a[i+2]==b[i+2])
            kh=0;
    }
    if(!kh)
        cout<<"Yes\n";
    else
        cout<<"No\n";
  }
}

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

int main() {
  int h,a;
  cin >> h >> a;
  cout << ((h%a == 0) ? (h/a) : (h/a+1)) << endl;


  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int MAX_N = 100010;
const ll mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}

/*------------------------------------------------------------------*/
int h, w;
const int INF = 100000;
vector<vector<int>> dist(55, vector<int>(55));
vector<string> maze;

int bfs(){
    queue<P> que;

    rep(i, h)rep(j, w) dist[i][j] = INF;

    que.push(P(0, 0));
    dist[0][0] = 0;

    while(que.size()){
        P p = que.front(); que.pop();

        if(p.first == h - 1 and p.second == w - 1) break;

        rep(i, 4){
            int nh = p.first + dx[i];
            int nw = p.second + dy[i];

            if(0 <= nh and nh < h and 0 <= nw and nw < w and maze[nh][nw] != '#' and dist[nh][nw] == INF){

                que.push(P(nh, nw));
                dist[nh][nw] = dist[p.first][p.second] + 1;
            }
        }
    }
    return dist[h - 1][w - 1];
}

int main(){
    cin >> h >> w;
    maze.resize(h);
    rep(i, h) cin >> maze[i];
    int count = 0;
    rep(i, h)rep(j, w) if(maze[i][j] == '.') count++;
    int ans = bfs();

    if(dist[h - 1][w - 1] >= 100000){
        cout << -1 << endl;
        return 0;
    }
    cout << count - ans - 1 << endl; 
}

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

signed main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int N, A, B;
    cin >> N >> A >> B;
    if ((B - A) % 2 == 0) {
        cout << "Alice" << endl;
    } else {
        cout << "Borys" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
let change n m d =
  let t = Array.make (n + 1) max_int in
  let rec doit = function
    | (i, _) when i = m -> t.(n)
    | (i, x) when x + d.(i) > n -> doit (i + 1, 0)
    | (i, x) ->
      t.(x + d.(i)) <-
        if t.(x + d.(i)) < t.(x) + 1 then t.(x + d.(i))
        else t.(x) + 1;
      doit (i, x + 1) in
  t.(0) <- 0;
  doit (0, 0)

let () =
  let (n, m) = Scanf.scanf "%d %d " (fun n m -> (n, m)) in
  let d = Array.init m (fun _ -> Scanf.scanf "%d " (fun i -> i)) in
  Printf.printf "%d\n" (change n m d)

Measured memory_bytes: 2788
#include <iostream>
#include <string>
#include <string.h>

using namespace std;

int v = 0, j = 0;

void insertionSort(int A[], int N);

int main() {
	int N;

	int A[1001];

	cin >> N;

	for (int i = 0; i < N; i++) {
		cin >> A[i];	
	}
	
	insertionSort(A, N);

	cout << A[0];
	for (int k = 1; k < N; k++) {
		cout << " " << A[k];
	}
	cout << endl;
}
		
void insertionSort(int A[], int N) {
	for (int i = 1; i < N; i++) {
		cout << A[0];
		for (int k = 1; k < N; k++) {
			cout << " " << A[k];
		}
		cout << endl;

		v = A[i];
		j = i - 1;
		while (j >= 0 && A[j] > v) {
			A[j + 1] = A[j];
			j--;
		}
		A[j + 1] = v;
	}
}


Measured memory_bytes: 3124
#include<stdio.h>
int main(void){
	int number;
	int i;
	int tate,yoko,takasa,omosa;
	int length;
	int sum=0;
	while(scanf("%d",&number)){
		if(number==0){
			break;
		}
		for(i=0;i<number;i++){
			scanf("%d %d %d %d",&tate,&yoko,&takasa,&omosa);
			length=tate+yoko+takasa;
			if(length<=60){
				if(omosa<=2){
					sum+=600;
				}
				else if(2<omosa && omosa<=5){
					sum+=800;
				}
				else if(5<omosa && omosa<=10){
					sum+=1000;
				}
				else if(10<omosa && omosa<=15){
					sum+=1200;
				}
				else if(15<omosa && omosa<=20){
					sum+=1400;
				}
				else if(20<omosa && omosa<=25){
					sum+=1600;
				}
				else{
					sum+=0;
				}
			}
			else if(60<length && length<=80){
				if(omosa<=5){
					sum+=800;
				}
				else if(5<omosa && omosa<=10){
					sum+=1000;
				}
				else if(10<omosa && omosa<=15){
					sum+=1200;
				}
				else if(15<omosa && omosa<=20){
					sum+=1400;
				}
				else if(20<omosa && omosa<=25){
					sum+=1600;
				}
				else{
					sum+=0;
				}
			}
			else if(80<length && length<=100){
				if(omosa<=10){
					sum+=1000;
				}
				else if(10<omosa && omosa<=15){
					sum+=1200;
				}
				else if(15<omosa && omosa<=20){
					sum+=1400;
				}
				else if(20<omosa && omosa<=25){
					sum+=1600;
				}
				else{
					sum+=0;
				}
			}
			else if(100<length && length<=120){
				if(omosa<=15){
					sum+=1200;
				}
				else if(15<omosa && omosa<=20){
					sum+=1400;
				}
				else if(20<omosa && omosa<=25){
					sum+=1600;
				}
				else{
					sum+=0;
				}
			}
			else if(120<length && length<=140){
				if(omosa<=20){
					sum+=1400;
				}
				else if(20<omosa && omosa<=25){
					sum+=1600;
				}
				else{
					sum+=0;
				}
			}
			else if(140<length && length<=160){
				if(omosa<=25){
					sum+=1600;
				}
				else{
					sum+=0;
				}
			}
			else{
				sum+=0;
			}
		}
		printf("%d\n",sum);
		sum=0;
	}
	return 0;
}

Measured memory_bytes: 600
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		// キーボード入力
		Scanner stdIn = new Scanner( System.in );
		int w = stdIn.nextInt();//縦棒の数
		int n = stdIn.nextInt();//横棒の数
		String[] yoko = new String[n];
		for(int i=0;i<n;i++){
			yoko[i] = stdIn.next();
		}
		int[] amida = new int[w];
		for(int i=0;i<w;i++){
			amida[i] = i+1;
		}
		for(int i=0;i<n;i++){
			String[] a = yoko[i].split(",");
			int[] b = {Integer.parseInt(a[0]),Integer.parseInt(a[1])};
			int temp = 0;

			temp = amida[b[0]-1];
			amida[b[0]-1] = amida[b[1]-1];
			amida[b[1]-1] = temp;
		}
		for(int i=0;i<amida.length;i++){
			System.out.println(amida[i]);
		}
	}
}

Measured memory_bytes: 12000
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>  
#include <stdbool.h>   
#define inf (INT_MAX-1)
#define INF 9223372036854775807;
#define PI 3.14159265358979323846;
#define EPS 1e-10
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
/*
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r)
*/
#define chsort(s,n) qsort(s,n,sizeof(char),cmp)
#define chsort_r(s,n) qsort(s,n,sizeof(char),char_cmp_r)
#define TYPE long long
#define ll long long
#define MEMSET(a) memset(a,0,sizeof(a))
#define MEMSET_U(a) memset(a,-1,sizeof(a))
#define bool    _Bool
const int mod = (int)1e09 + 7;

//#define DEBUG1
//#define DEBUG2
//#define DEBUGF
#define DUMMY

int in(void) { int i; scanf("%d", &i); return i; }
long long llin(void) { long long i; scanf("%lld", &i); return i; }
double din(void) { double i; scanf("%lf", &i); return i; }
void chin(char s[]) { scanf("%s", s); }

void print(int a) { printf("%d\n", a); }
void llprint(long long a) { printf("%lld\n", a); }
void dprint(double a) { printf("%.10f\n", a); }
void print2(int a, int b) { printf("%d %d\n", a, b); }
int Max(int a, int b) { if (a > b) { return a; }return b; }
int Min(int a, int b) { if (a < b) { return a; }return b; }
long long llmax(long long a, long long b) { return a > b ? a : b; }
long long llmin(long long a, long long b) { return a < b ? a : b; }
double dmax(double a, double b) { return a > b ? a : b; }
double dmin(double a, double b) { return a < b ? a : b; }
//long long llmax(long long a, long long b) { return a > b ? a : b; }
//long long llmin(long long a, long long b) { return a < b ? a : b; }
//double dmax(double a, double b) { return a > b ? a : b; }
int cmp(const void *a, const void *b) { return *(TYPE *)a - *(TYPE *)b; }
int cmp_r(const void *a, const void *b) { return *(TYPE *)b - *(TYPE *)a; }
int char_cmp(const void *a, const void *b) { return strcmp((char *)a, (char *)b); }
int char_cmp_r(const void *a, const void *b) { return strcmp((char *)b, (char *)a); }
void swap(int *a, int *b) { int t = *a; *a = *b; *b = t; }


int main() {
	int N, H, W;
	scanf("%d%d%d", &N, &H, &W);
	int ans;
	ans = ((N - H) + 1) * ((N - W) + 1);
	printf("%d\n", ans);

#ifdef DEBUGF
	getch();
#endif
	return 0;
}

Measured memory_bytes: 128
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long a = sc.nextLong();
    long b = sc.nextLong();
    //a,bの最大公約数を素因数分解して出てきた素数の種類数+1が答え
//cが素数の時は2が答え→勘違いしてた
//cが1の時は1が答え
//cが合成数の時は見つかり次第どんどん割ってく戦法で間に合う
    long c = gcd(a,b);
//    System.out.println(c);
    long answer = 1;
//    System.out.println(c);
    long tmp =0;
if(c==1){
System.out.println(1);
}else if(isPrime(c)){
System.out.println(2);
}else{
    for(long prime :primes(c)){
      if(tmp!=prime){
tmp=prime;
        if(isPrime(prime)){
//        System.out.println(prime);
// 素因数の約数のうち、素数or1だけカウントする
        answer = answer +1;
tmp=prime;
        }
      }
    }
    //なんで通らないケースあるんじゃーーーー
    System.out.println(answer);
}
  }
  
    //最大公約数
    static long gcd (long a, long b) {return b>0?gcd(b,a%b):a;}
  
//素数じゃない数を引数に、素因数分解してそいんすう列挙する
//cがクソデカ素数×小さい素数とかの時にクソデカ素数を詰めれてねえ…
//→商も詰めればええやん！
  static List<Long> primes(long c){ 
    List<Long> primenums= new ArrayList<Long>();
            long x = c;
            long y = x;
//       System.out.println(Math.floor(Math.sqrt(x))+2);
          for (long i = 2; i<=Math.sqrt(x)*3+10; i++) {
//            System.out.println(i);
//            boolean divflg=false;
            if ((y % i) == 0 ) {
//               if(!divflg){
                primenums.add(i);
primenums.add(y/i);
//               }
//                divflg=true;
            }
            
        }
    Collections.sort(primenums);
    return primenums;
  }
//素数判定
static boolean isPrime (long n) {
if (n==2) return true;
if (n<2||n%2==0) return false;
double d = Math.sqrt(n);
for (int i=3; i<=d; i+=2) if(n%i==0){return false;}
 return true;
}
  
}


Measured memory_bytes: 22996
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long
using namespace std;
int a[22][22];
void input(){
	#ifndef ONLINE JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
}
int dp[(1<<22)];
int ways(int n,int val){
	int i=__builtin_popcount(val)+1;
	if(i==n+1){
		return 1;
	}
	if(dp[val]!=-1){
		return dp[val];
	}
	int w=0;
	for(int j=1;j<=n;j++){
		if(((1<<(j-1))&val)==0 and a[i][j]==1){
			w=(w+ways(n, val|(1<<(j-1))))%mod;
		}
	}
	return dp[val]=w;
}
int main(){
	//input();
	int n; cin>>n;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			cin>>a[i][j];
		}
	}
	memset(dp,-1,sizeof(dp));
	cout<<ways(n,0)<<endl;	
}

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

int main() {
	int a, b, ans;
	char o;
	do {
	cin >> a >> o >> b;
	if (o == '?') break;
	if (o == '+')
		cout << a + b << endl;
	else if (o == '-')
		cout << a - b << endl;
	else if (o == '*')
		cout << a * b << endl;
	else if (o == '/') {
		if (b == 0)
			return 0;
		cout << a / b << endl;
	}
    } while (true);
	return 0;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long int ll;
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) { a = b; return 1; }return 0; }
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) { a = b; return 1; }return 0; }
#define all(a)  (a).begin(),(a).end()
#define rep(i, n) for (int i = 0; i < n; i++)
#define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i];
const ll INF =1LL << 62;

int main(){
  int N,K;
  cin >> N >> K;
  ll h[100010] ;
  cinf(N,h);
  ll dp[100010];
  rep(i,N) dp[i] = INF;
  
  dp[0] =0;
  for(int i=1;i<N;i++){
    for(int j=i-1;j>=0 && j>=i-K;j--){
      chmin(dp[i],dp[j]+abs(h[i]-h[j]));
    }
  }
  cout << dp[N-1] << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
const Int MOD = 998244353;
Int dp[3010][3010];
int main() {
    Int A, B, C, D; cin >> A >> B >> C >> D;
    dp[A][B] = 1;
    for (Int i = A; i <= C; i++) {
        for (Int j = B; j <= D; j++) {
            if (i == A && j == B) continue;
            dp[i][j] = dp[i - 1][j] * j + dp[i][j - 1] * i + MOD - dp[i - 1][j - 1] * (i - 1) * (j - 1) % MOD;
            dp[i][j] %= MOD;
        }
    }
    cout << dp[C][D] << endl;
    return 0;
}


Measured memory_bytes: 74112
import java.util.Map;
import java.util.Scanner;

public class Main {

    /**
     * 本処理を実行します。
     */
    public static void execute() {
        Scanner sc = new Scanner(System.in);

        int n = nextInt(sc);
        int a = nextInt(sc);
        int b = nextInt(sc);

        int na = n * a;

        if (na < b) {
            out(na);
        } else {
            out(b);
        }
    }

    /**
     * 次の標準入力をintで受け取ります。
     * @return 標準入力値(int)
     */
    public static int nextInt(Scanner sc) {
        return sc.nextInt();
    }

    /**
     * 次の標準入力をStringで受け取ります。
     * @return 標準入力値(String)
     */
    public static String nextString(Scanner sc) {
        return sc.next();
    }

    /**
     * 次の標準入力を指定回数分intで受け取ります。
     * @param n 取得回数
     * @return 取得した標準入力値の配列(int)
     */
    public static int[] nextInts(Scanner sc, int n) {
        int[] arr = new int[n];

        for (int i = 0; i < n; i++) {
            arr[i] = nextInt(sc);
        }

        return arr;
    }

    /**
     * 標準出力にオブジェクトを出力します。
     * @param o 出力対象
     */
    public static void out(Object o) {
        System.out.println(o);
    }

    public static void main(String[] args) {
        execute();
    }

    public static void putCountMap(Map<Integer, Integer> map, int value) {
        if (map.containsKey(value)) {
            map.put(value, map.get(value) + 1);
        } else {
            map.put(value, 1);
        }
    }
}

Measured memory_bytes: 21972
// Garg's Code
#include <bits/stdc++.h>
using namespace std;
#define set set <ll>
#define ll long long
#define ldb long double;
#define pa pair < ll, ll >
//#define map map < ll, ll >
#define vec vector < ll >
#define pb push_back
#define po pop_back
#define mp make_pair
#define mt make_tuple
#define F  first
#define S  second
#define f(i,x,n) for(ll i=x;i<n;i++) 
#define unique_sort(x) sort(all(x)), x.resize(distance(x.begin(), unique(all(x))))
#define all(c) c.begin(),c.end()
#define str string
#define edl "\n"
#define add insert
#define cot continue
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)
const int MOD = 1e9 + 7, INF = INT_MAX, N = 1e5 + 10;
#define llong 1e9+7
#define lsmall -1e9+7
const double PI = acos(-1);
const ll LINF = LLONG_MAX;
 int main() 
 
{
   fast();
  
 
  ll n, ans = 0;
  cin >> n;
  vector<string> v;
  map<string, ll> m;
  string s;
  f(i,0,n)
  {
  	cin >> s;
  	sort(s.begin(), s.end());
  	//cout << s << endl;
  	v.pb(s);
  	m[s] = 0; 
  }
  f(i,0,n)
  {
  	m[v[i]] += 1; 
  	//cout << m[v[i]] << " ";
  }
  map<string, ll>::iterator j;
  for(j = m.begin(); j != m.end(); j++)
  {
  	//cout << j->second << " ";
  	ll p = j->second;
  	ans += p*(p-1)/2;
  }
  cout << ans;
  return 0;   
}

Measured memory_bytes: 16628
#include<vector>
#include<iostream>
#include<algorithm>
#include<functional>
#include<string>
#include<limits.h>
#include<cmath>
#include<queue>
#define rep(i,n) for (int i=0; i<n; i++)
using namespace std;
typedef long long ll;

ll gcd(ll a,ll b){
  ll r;
  while ((r=a%b)){a=b;b=r;}
  return b;
}

int main(){

  int n,k; cin >> n >> k;
  string s; cin >> s;
  int a=0;
  if (s[0]=='R' && s[1]=='R'){a++;}
  if (s[n-2]=='L' && s[n-1]=='L'){a++;}
  for (int i=1; i<n-1; i++){
    if (s[i]=='L' && s[i-1]=='L'){a++;}
    else if (s[i]=='R' && s[i+1]=='R'){a++;}
  }

  cout << min(a+2*k,n-1);

  return 0;
}


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

int gcd_2(int x,int y){
    if(y==0) return x;
    return gcd_2(y,x%y);
}
int gcd_1(int x,int y,int z){
    return gcd_2(gcd_2(gcd_2(x,z),gcd_2(x,y)),gcd_2(y,z));
}
int main(){
    int n,i,j,k;
    ll ans=0;
    scanf("%d",&n);
    for(i=1;i<=n;i++){
        for(j=1;j<=n;j++){
            for(k=1;k<=n;k++){
                ans+=gcd_1(i,j,k);
                /*cout<<gcd_1(i,j,k)<<' '<<i<<' '<<j<<' '<<k<<endl;*/}
        }
    }
    printf("%lld",ans);
}


Measured memory_bytes: 3828
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include<map>
#include<cmath>
#include<deque>
using namespace std;

using ll = long long;
const int INF = 1001001001;

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

int main()
{
  int a, b, c;
  cin >> a >> b >> c;
  printf("%d %d %d\n", c, a, b);
}


Measured memory_bytes: 256
package main

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

const (
	initialBufSize = 1e4
	maxBufSize     = 1e6 + 7
)

var buf []byte = make([]byte, maxBufSize)
var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBufSize)
}

func main() {
	N := nextInt()
	var ans int
	if N < 100 {
		ans = MinOf(N, 9)
	} else if N < 10000 {
		ans = MinOf(N-99+9, 909)
	} else {
		ans = MinOf(N-9999+909, 90909)
	}
	fmt.Println(ans)
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

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

func abs(a int) int {
	if a > 0 {
		return a
	} else {
		return -a
	}
}

func pow(p, q int) int {
	res := p
	if q == 0 {
		return 1
	}
	for i := 0; i < q-1; i++ {
		res *= p
	}
	return res
}

func MinOf(vars ...int) int {
	min := vars[0]
	for _, i := range vars {
		if min > i {
			min = i
		}
	}
	return min
}

func MaxOf(vars ...int) int {
	max := vars[0]
	for _, i := range vars {
		if max < i {
			max = i
		}
	}
	return max
}

func gcdof2numbers(a int, b int) int {
	if b == 0 {
		return a
	}
	return gcdof2numbers(b, a%b)
}

func lcmof2numbers(a int, b int) int {
	return a / gcdof2numbers(a, b) * b
}

// マイナスの場合は考慮していない
func fuctorial(a int) int {
	if a == 1 || a == 0 {
		return 1
	} else {
		return fuctorial(a-1) * a
	}
}

func NextPermutation(x sort.Interface) bool {
	n := x.Len() - 1
	if n < 1 {
		return false
	}
	j := n - 1
	for ; !x.Less(j, j+1); j-- {
		if j == 0 {
			return false
		}
	}
	l := n
	for !x.Less(j, l) {
		l--
	}
	x.Swap(j, l)
	for k, l := j+1, n; k < l; {
		x.Swap(k, l)
		k++
		l--
	}
	return true
}

// 素因数分解したmapを返す
func primeFuctorize(n int) map[int]int {
	pf := map[int]int{}
	for i := 2; i*i <= n; i++ {
		for n%i == 0 {
			pf[i]++
			n /= i
		}
	}
	if n != 1 {
		pf[n]++
	}
	return pf
}


Measured memory_bytes: 1812
<?php
fscanf(STDIN, "%d%d%d%d", $A, $B, $H, $M);
$argH = ($H/12+$M/12/60)*2*pi();
$argM = $M/60*2*pi();
$dx = $A*cos($argH) - $B*cos($argM);
$dy = $A*sin($argH) - $B*sin($argM);
printf("%.18f", ($dx**2+$dy**2)**0.5);

Measured memory_bytes: 16744
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    s = str(readline().rstrip().decode('utf-8'))
    t = str(readline().rstrip().decode('utf-8'))
    k = len(t)
    for i in range(len(s) - k, -1, -1):
        ts = s[i:i+k]
        b = True
        for j in range(k):
            if ts[j] != "?" and ts[j] != t[j]:
                b = False
                break
        if b:
            a = []
            f = True
            for j in range(len(s)):
                if j < i or i + k <= j:
                    if s[j] == "?":
                        a.append("a")
                    else:
                        a.append(s[j])
                else:
                    if f:
                        a = a + list(t)
                        f = False
            print("".join(a))
            exit()
    print("UNRESTORABLE")


if __name__ == '__main__':
    solve()


Measured memory_bytes: 38384
#pragma optimization_level 3
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <math.h>
#include <cmath>
#include <string>
#include <time.h>
#include <random>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <string.h>
using namespace std;

//#define fast cin.tie(0);cout.tie(0);cin.sync_with_stdio(0);cout.sync_with_stdio(0);
//#define cin in
//#define cout out
#define pii pair<int,int>
#define ll long long
#define db double
#define ld long double
#define uset unordered_set
#define umap unordered_map

ifstream in("input.txt");
ofstream out("output.txt");

const int MAXN = 1e5, MAXM = 1e5;

int main()
{
	int n, m;
	cin >> n >> m;
	//{дни, деньги}
	vector<pii> jobs;

	vector<int> best(m+1, 0);

	for (int i = 0; i < n; i++) {
		int a, b;
		cin >> a >> b;
	
		if (a <= m)
			jobs.push_back({ a, b });
	}

	sort(jobs.begin(), jobs.end());

	ll ans = 0;
	
	priority_queue<int> maxes;
	int i = 0;

	for (int d = 1; d <= m; d++) {
		int cur_max = 0;

		while (i < jobs.size() && jobs[i].first <= d) {
			maxes.push(jobs[i].second);
			i++;
		}

		if (!maxes.empty()) {
			ans += maxes.top();
			maxes.pop();
		}
	}

	cout << ans;
}

Measured memory_bytes: 2296
from collections import Counter
from itertools import accumulate
N, M, *A = map(int, open(0).read().split())
B = [b%M for b in accumulate(A)]
C = Counter(B)
ans = C[0]
ans += sum(C[k]*(C[k]-1)//2 for k in C.keys())
print(ans)

Measured memory_bytes: 16600
process.stdin.resume();
process.stdin.setEncoding('utf8');

process.stdin.on('data', function (chunk) {
    const n = chunk.toString().replace("\n", "");
    const r = n.split("");
    sp(r);
});

function sp(rep){
    const c = rep.slice().map(x => x.toUpperCase());
    const d = rep.slice();
    const b = rep.slice().map(x => x.toLowerCase());
    var kaeru = [];
    for(var i=0; i<c.length; i++){
        if(c[i]!=d[i]){
            kaeru += c[i];
        }else{
            kaeru += b[i];
        }
    }
    console.log(kaeru);
}


Measured memory_bytes: 16500
#include <bits/stdc++.h>
using namespace std;
 
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define sz size()
#define all(x) (x).begin(), (x).end()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)

#define ll long long

int main() {

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

    // freopen("input.in","r",stdin);

    int n,x,t;
    cin>>n>>x>>t;

    int r = n/x;

    n-=r*x;
    if (n) r++;

    cout<<r*t<<"\n";

    return 0;
}

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

using namespace std;

using ll = long long;
using ld = long double;
using D = double;
using uint = unsigned int;
template<typename T>
using pair2 = pair<T, T>;

#ifdef WIN32
#define LLD "%I64d"
#else
#define LLD "%lld"
#endif

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second

const int maxn = 200005;

vector<pair<int, pair2<int>>> edges;
int n;
int p[maxn], s[maxn];
ll add[maxn];
int sz[maxn];

int find(int x)
{
    return p[x] == x ? x : find(p[x]);
}

void unite(int a, int b)
{
    a = find(a);
    b = find(b);
    if (s[a] > s[b]) swap(a, b);
    p[a] = b;
    add[a] -= add[b];
    if (s[a] == s[b]) s[b]++;
    sz[b] += sz[a];
}

ll calc(int x)
{
    return p[x] == x ? add[x] : add[x] + calc(p[x]);
}

int main()
{
    scanf("%d", &n);
    for (int i = 0; i < n - 1; i++)
    {
        int a, b, c;
        scanf("%d%d%d", &a, &b, &c);
        a--, b--;
        edges.pb({c, {a, b}});
    }
    for (int i = 0; i < n; i++)
    {
        p[i] = i;
        s[i] = 0;
        sz[i] = 1;
    }
    sort(all(edges));
    reverse(all(edges));
    for (auto t : edges)
    {
        int a = find(t.se.fi);
        int b = find(t.se.se);
//         cout << "merge " << a << ' ' << b << endl;
        add[a] += (ll)t.fi * sz[b];
        add[b] += (ll)t.fi * sz[a];
        unite(a, b);
    }
    for (int i = 0; i < n; i++) printf("%lld\n", calc(i));
    return 0;
}

Measured memory_bytes: 4980