akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <string>
#include <bitset>
#include <fstream>
#include <iomanip>

#define INF 1000000007
#define PB push_back
#define MP make_pair
#define X first
#define Y second
#define Min(a,b) (((a) < (b))?(a):(b))
#define Max(a,b) (((a) > (b))?(a):(b))
#define Abs(a) (((a) > 0)?(a):(-1)*(a))
#define cil(a,b) ( ((a)%(b) == 0)?((a)/(b)):((a)/(b)+1) )
#define S(a) ((a)*(a))
#define gc getchar
#define pc putchar

using namespace std;

typedef long long ll;
typedef double db;
typedef vector<int> vi;
typedef vector<int>::iterator viit;
typedef vector<long long> vll;
typedef vector<long long>::iterator vllit;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;

inline void read(int &x) {
	register int c = gc();
	x = 0;
	bool neg = false;
	for(;(c<48)||(c>57);c=gc()) { if(c=='-') neg = true; }
	for(;(c>47)&&(c<58);c=gc()) { x = (x<<1) + (x<<3) + (c-48);	}
	if(neg) x = -x;
}

inline void write(long long int n) {
	bool neg = (n<0);
	if(n == 0) { pc('0'); pc('\n'); }
	else if(n == -1) { pc('-'); pc('1'); pc('\n'); }
	else {
		if(neg) n=-n,pc('-');
		char buf[20];
		buf[19] = '\n';
		int i = 18;
		while(n) { buf[i--] = n % 10 + '0'; n /= 10; }
		while(buf[i] != '\n') pc(buf[++i]);
	}
}

ll exp (ll b, ll e) {
	if (b == 1 || e == 0) return 1;
	if(e == 1) return b%INF;
	if(e == 2) return (b*b)%INF;
	return ( (e%2 == 0)? exp(exp(b,e/2),2)%INF : (b * (exp(exp(b,e/2),2)%INF))%INF );
}

ll gcd ( ll a, ll b ) {
	return ( (b == 0)?a:gcd(b,a%b) );
}

ll a[100003], b[100003];
int main() {
	ll n,i,j,k;
	scanf("%d",&n);
	for (i = 0 ; i < n ; ++i) {
		scanf("%d %d",&a[i], &b[i]);
	}
	ll ans = 0;
	for (i = n-1 ; i >= 0 ; --i) {
		ll inc = ((a[i]%b[i] != 0)?(b[i] - a[i]%b[i]): 0);
		ll h = Max((ans - inc),0), t;
		t = b[i]*cil(h,b[i]);
		ans = ((t == 0)?inc:inc+t);
	}
	printf("%lld\n",ans);

	return 0;
}


Measured memory_bytes: 1792
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		String S = stdIn.next();
		StringBuffer str = new StringBuffer(S);
        S = str.reverse().toString();
        
        String[] divide = {"dream", "dreamer", "erase", "eraser"};
        for(int i = 0; i < 4; i++) {
        	StringBuffer d = new StringBuffer(divide[i]);
        	divide[i] = d.reverse().toString();
        }
        
        boolean can = true;
        for(int i = 0; i < S.length();) {
        	boolean flag = false;
        	for(int j = 0; j < 4; j++) {
        		String d = divide[j];
        		if(i+d.length() <= S.length() && S.substring(i, i+d.length()).equals(d)) {
        			flag = true;
        			i += d.length();
        		}
        	}
        	if(!flag) {
        		can = false;
        		break;
        	}
        }
        if(can) System.out.println("YES");
        else System.out.println("NO");

	}

}

Measured memory_bytes: 28416
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, s, n) for(int i = s; i < (int)n; i++)
#define per(i, n) for(int i = n; i >= 0; i--)
#define ROF(i, s, n) for(int i = s; i >= (int)n; i--)
#define FORIT(i, A) for (auto i : A)
#define PRINT(x) cout << (x) << "\n"
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define MP make_pair
#define EACH(i, n) for (__typeof((n).begin()) i = (n).begin(); i != (n).end(); ++i)
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x) cout << #x << " = " << (x) << "\n";
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << "\n";
#define sq(n) (n) * (n)
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef priority_queue<int> maxpq;
typedef priority_queue< int, vector<int>, greater<int> > minpq;
static const double EPS = 1e-10;
static const double PI = acos( -1.0 );
static const int mod = 10007;
static const int INF = 1 << 25;
static const LL LL_INF = 1152921504606846976;
static const int dx[] = { 1, -1, 0, 0,  1, -1,  1, -1 };
static const int dy[] = { 0, 0, 1, -1 , 1,  1, -1, -1 };
static const char Move[] = { 'E', 'W', 'N', 'S' };

int n, y, m, d;
vector<PII> gems;

int gcd( int m, int n ) {
	if ( n == 0 ) return m;
	return gcd( n, m % n );
}

int main() {
	scanf( "%d", &n );
	for ( int i = 0; i < n; i++ ) {
		scanf( "%d %d %d", &y, &m, &d );
		int ans = 196470;
		ans -= (( ( y - 1 ) / 3 ) * 590 + ( ( y - 1 ) % 3 ) * 195);
		if ( !(y % 3) ) {
			ans -= (( m - 1 ) * 20);
		}
		else {
			ans -= (( ( m - 1 ) / 2 ) * 39 + ( ( m - 1 ) % 2 ) * 20);
		}
		ans -= (d - 1);
		printf( "%d\n", ans );
	}
	return 0;
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
int main() {
    // ifstream in("data1.txt");
    // cin.rdbuf(in.rdbuf());
    int ans = 0;
    vector<int> v(3);
    rep(i, 3) cin >> v[i];
    sort(v.begin(), v.end());
    cout << v[0] + v[1] << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{

    public static void main(String []args){
        Scanner sc = new Scanner(System.in);
        int a=0;
        int b=0;
        int c=0;
        int d=0;
        int score=0;
        String x="";
        a=sc.nextInt();


        x=sc.next();

        if(x.length()>a){
            x=x.substring(0,a)+"...";


        }
        System.out.print(x);



    }

}





Measured memory_bytes: 38468
#include <cstdio>

const int N = 52;
const int MOD = (int)1e9 + 7;

int n;
char buf[2][N + 1];

int main()
{
    scanf("%d%s%s", &n, buf[0], buf[1]);
    long long result;
    int i;
    char last = 'V';
    if (buf[0][0] == buf[1][0]) {
        result = 3;
        i = 1;
        last = 'V';
    } else {
        result = 6;
        i = 2;
        last = 'H';
    }
    while (i < n) {
        if (buf[0][i] == buf[1][i]) {
            if (last == 'V') {
                result *= 2;
            }
            i += 1;
            last = 'V';
        } else {
            if (last == 'V') {
                result *= 2;
            } else {
                result *= 3;
            }
            i += 2;
            last = 'H';
        }
        result %= MOD;
    }
    printf("%d\n", (int)result);
}

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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
using ull = unsigned long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

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

int cnter(int n){
  int cnt = 0;
  while(n&&n%2==0){
    cnt++;
    n/=2;
  }
  return cnt;
}

int main(){
  int cnt = 0;
  int n; cin >> n;
  int ans = 1;
  for(int i = 1; i <= n; ++i){
    if(ChangeMax(cnt,cnter(i))){
      ans = i;
    }
  }
  cout << ans << endl;
}

 













Measured memory_bytes: 3592
import java.util.Scanner;


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

		double a,b,c,d,e,f,x,y;

		while (sc.hasNext()) {
			a = sc.nextDouble();
			b = sc.nextDouble();
			c = sc.nextDouble();
			d = sc.nextDouble();
			e = sc.nextDouble();
			f = sc.nextDouble();

			x = (c * e - f * b) / (a * e - d * b);
			y = (a * f - d * c) / (a * e - d * b);
			if(x == 0) x = 0;
			if(y == 0) y = 0;
			System.out.printf("%.3f %.3f\n", x , y);
		}
	}
}

Measured memory_bytes: 12000
#if __has_include("../library/Basic/Debug.hpp")

#include "../library/Basic/Debug.hpp"

#else

/* ----- Header Files ----- */
// IO
#include <cstdio>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm
#include <algorithm>
#include <cmath>
#include <numeric>

// container
#include <vector>
#include <string>
#include <tuple>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>

// others
#include <random>
#include <limits>
#include <functional>
#include <ctime>
#include <cassert>
#include <cstdint>


/* ----- Type Alias ----- */
using Bool = bool;
using Int = long long int;
using Real = long double;
using Char = char;
using String = std::string;
template <class T, class U>
using Pair = std::pair<T, U>;
template <class... Ts>
using Tuple = std::tuple<Ts...>;

template <class T>
using Vector = std::vector<T>;
template <size_t N>
using Bits = std::bitset<N>;
template <class T>
using Queue = std::queue<T>;
template <class T>
using Stack = std::stack<T>;
template <class T>
using Deque = std::deque<T>;

template <class T>
using MaxHeap = std::priority_queue<T>;
template <class T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;
template <class T>
using Set = std::set<T>;
template <class T, class U>
using Map = std::map<T, U>;

template <class T, class... Us>
using Func = std::function<T(Us...)>;

template <class T>
T genv(T v) { return v; }

template <class T, class... Ts>
auto genv(size_t l, Ts... ts) {
    return Vector<decltype(genv<T>(ts...))>(l, genv<T>(ts...));
}

template <class Cost = Int>
struct Edge {
    Int src, dst;
    Cost cost;
    Edge(Int src = -1, Int dst = -1, Cost cost = 1)
        : src(src), dst(dst), cost(cost){};

    bool operator<(const Edge<Cost>& e) const { return this->cost < e.cost; }
    bool operator>(const Edge<Cost>& e) const { return this->cost > e.cost; }
};

template <class Cost = Int>
using Edges = Vector<Edge<Cost>>;
template <class Cost = Int>
using Graph = Vector<Vector<Edge<Cost>>>;

#endif

/* ----- Misc ----- */
void fastio() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
}

struct Fout {
    Int precision;
    Fout(Int precision) : precision(precision) {}
};
std::ostream& operator<<(std::ostream& os, const Fout& fio) {
    os << std::fixed << std::setprecision(fio.precision);
    return os;
}


/* ----- Constants ----- */
// constexpr Int INF = std::numeric_limits<Int>::max() / 3;
// constexpr Int MOD = 1000000007;
// constexpr Real PI = acos(-1);
// constexpr Real EPS = 1e-10;
// std::mt19937 mt(int(std::time(nullptr)));

int main() {
    Int n;
    std::cin >> n;

    Int ans = 0;
    for (Int x = 1; x <= n; ++x) {
        Int y = x;
        Int d = 0;
        while (y != 0) {
            y /= 10;
            ++d;
        }
        if (d % 2) ++ans;
    }

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


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
  int a[1000], n, i, j, k, v;
  scanf("%d", &n);
  for(k = 0; k < n; k++)
    {
      scanf("%d",&a[k]);
    }
  for(k = 0; k < n-1; k++)
    {
      printf("%d ",a[k]);
    }
  printf("%d", a[n-1]);
  printf("\n");
  for(i = 1; i < n; i++)
    {
      v = a[i];
      j = i - 1;
      while (j >= 0 && a[j] > v)
	{
	  a[j+1] = a[j];
	  j--;
	  a[j+1] = v;
	}
      for(k = 0; k < n-1; k++)
	{
	  printf("%d ",a[k]);
	}
      printf("%d", a[n-1]);
      printf("\n");
    }
  return 0;
}



Measured memory_bytes: 2136
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()
#define chmin(a,b) a=min(a,b);
#define chmax(a,b) a=max(a,b);

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

ll nums[100];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;
    cin>>N;
    
    nums[0]=2;
    nums[1]=1;
    
    for(int i=2;i<100;i++){
        nums[i]=nums[i-1]+nums[i-2];
    }
    
    cout1(nums[N])
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

char S[5];

int main() {
  int i, j, k;
  scanf ("%s", &S);
  
  if (S[1]==S[0]) {
    if (S[2]==S[3] && S[2]!=S[0]) printf ("Yes\n");
    else                          printf ("No\n");
  }
  else {
    if      (S[2]==S[0] && S[3]==S[1]) printf ("Yes\n");
    else if (S[2]==S[1] && S[3]==S[0]) printf ("Yes\n");
    else                               printf ("No\n");
  }
  
  return 0;
}




Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<ll, P> E;
#define cost first
#define from second.first
#define to second.second
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

int main(void){
	int h,w,i;
	string a[123];
	cin >> h >> w;
	for(i=0; i<h; ++i){
		cin >> a[i];
	}
	for(i=(w+1); i>=0; --i){
		cout << "#";
	}
	cout << endl;
	for(i=0; i<h; ++i){
		cout << "#" << a[i] << "#" << endl;
	}
	for(i=(w+1); i>=0; --i){
		cout << "#";
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
a,b,c,d=map(int,input().split())

x=c-a
y=d-b

t=''
t+='R'*x
t+='U'*y
t+='L'*x
t+='D'*y
t+='D'
t+='R'*(x+1)
t+='U'*(y+1)
t+='L'
t+='U'
t+='L'*(x+1)
t+='D'*(y+1)
t+='R'

print(t)

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

#define dump(x) cout << (x) << '\n'
#define Int int64_t
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()

Int INF = 1e18;
int inf = 1e9;
Int mod = 1e9+7;

int main() {
    Int a, b;
    cin >> a >> b;
    dump(max(a + b, max(a - b, a * b)));

    return 0;
}


Measured memory_bytes: 256
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return int(stdin.readline())

a = li()
b = li()
c = li()
d = li()
e = li()
total = 0
delta = 0
for elem in [a, b, c, d, e]:
    mod = elem % 10
    if mod == 0:
        total += elem
    else:
        d = 10 - mod
        total += elem + d
        delta = max(delta, d)
print(total - delta)


Measured memory_bytes: 3064
/*

*/
#include<iostream>
#include<iomanip>
#include<ios>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<string>
#include<algorithm>
#include<utility>
#include<math.h>
#include<cstdlib>
#define rep(i, n) for(int i=0;i<n;i++)
#define repb(i, a, b) for(int i=a;i<b;i++)
#define MAX_N 10000

using namespace std;
typedef pair<int, int> P;
typedef long long int ll;

const int INF = 1<<30;
const ll MOD = ll(1e9+7);

int main(){
  int a, b;cin>>a>>b;
  cout<<a*b<<endl;
  // system("read -n 1 -s -p \"Press any key to continue...\"");
}


Measured memory_bytes: 3584
def main():
    n,m=map(int,input().split())
    L=2**n
    cost=[0]+[10**8 for i in range(L-1)]

    for _ in range(m):
        a,_=map(int,input().split())
        c=sum([2**(int(i)-1) for i in input().split()])
        for j in range(L):
            q=j|c
            x=cost[j]+a
            if cost[q]>x:
                cost[q]=x
    print(cost[L-1] if cost[L-1]<10**8 else -1)

if __name__ == '__main__':
    main()

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

typedef long long ll;

int k;
ll res;

int gcd(int x, int y) { return x? gcd(y % x, x): y; }

int main()
{
    scanf("%d", &k);
    for (int i = 1; i <= k; i++)
        for (int j = 1; j <= k; j++)
            for (int z = 1; z <= k; z++)
                res += gcd(gcd(i, j), z);
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 3772
// Problem : C - Subarray Sum
// Contest : Keyence Programming Contest 2020
// URL : https://atcoder.jp/contests/keyence2020/tasks/keyence2020_c
// Memory Limit : 1024.000000 MB 
// Time Limit : 2000.000000 milisec 
// Powered by CP Editor (https://github.com/coder3101/cp-editor)

// writer: w33z8kqrqk8zzzx33
#include <bits/stdc++.h>
using namespace std;

#define iter(i, a, b) for(int i=(a); i<(b); i++)
#define rep(i, a) iter(i, 0, a)
#define rep1(i, a) iter(i, 1, (a)+1)
#define log(a) cerr<<"\033[32m[DEBUG] "<<#a<<'='<<(a)<<" @ line "<<__LINE__<<"\033[0m"<<endl
#define all(a) a.begin(), a.end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair

using ll=long long;
using pii=pair<int, int>;
//#define int ll
const int MOD = 1000000007;

#define a9 1000000000

signed main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	int N, K, S; cin >> N >> K >> S;
	rep(i, K) cout << S << ' ';
	rep(i, N-K) {
		if(S == a9) cout << 1 << ' ';
		else cout << a9 << ' ';
	}
	cout << endl;
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
#ifdef LOCAL_DEBUG
  #include "LOCAL_DEBUG.hpp"
#endif
#define int long long

signed main(){

  int x, k ; cin >> x >> k;
  if(x * 500 >= k){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
n,m = map(int,input().split())
a = set([int(input())for _ in range(m)])
dp = [0]*(n+1)
dp[0] = 1
if 1 in a :
    dp[1] = 0
else:
    dp[1] = 1

for i in range(2,n+1):
    if i in a:
        continue
    dp[i] = (dp[i-1]+dp[i-2])%1000000007
print(dp[n])

Measured memory_bytes: 18980
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr double eps = 1e-9;
constexpr ll MOD = 1000000007LL;
template <typename T>
bool chmin(T& a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T>
bool chmax(T& a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for(int i = 0; i < v.size(); i++) {
        os << v[i] << (i + 1 == v.size() ? "\n" : " ");
    }
    return os;
}
template <typename T>
vector<T> make_v(size_t a) {
    return vector<T>(a);
}
template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T& t, const V& v) {
    t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T& t, const V& v) {
    for(auto& e : t) {
        fill_v(e, v);
    }
};
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<ll> a(n);
    multiset<ll> s1, s2;
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(all(a));
    if(a[0] >= 0) {
        s2.insert(a[0]);
        for(int i = 1; i < n; i++) {
            s1.insert(a[i]);
        }
    } else if(a[n - 1] < 0) {
        s1.insert(a[n - 1]);
        for(int i = 0; i < n - 1; i++) {
            s2.insert(a[i]);
        }
    } else {
        for(int i = 0; i < n; i++) {
            if(a[i] >= 0) {
                s1.insert(a[i]);
            } else {
                s2.insert(a[i]);
            }
        }
    }
    vector<P> v;
    for(int i = 0; i < n - 1; i++) {
        auto x = s1.begin(), y = s2.begin();
        if(s1.size() == 1) {
            s1.insert(*x - *y);
            v.push_back(P(*x, *y));
        } else {
            s2.insert(*y - *x);
            v.push_back(P(*y, *x));
        }
        s1.erase(x);
        s2.erase(y);
    }
    cout << *s1.begin() << endl;
    for(int i = 0; i < n - 1; i++) {
        cout << v[i].first << " " << v[i].second << endl;
    }
}


Measured memory_bytes: 8952
#include<iostream>
#include<iomanip>
#include<string>
#include<array>
#include<cmath>
#include<vector>
#include<utility>
#include<algorithm>
#include<ctype.h>
using namespace std;


int main(){
	string s, t, u,v;
cin >> s;
for (int i = 0; i < s.size(); i++) {
	t += s[s.size() - 1 - i];
}
for (int i = 1; i < s.size() - 1;i++) {
		v = t.substr(i);
		u = v.substr(v.size() / 2);
		if (v==u+u) {
			cout << v.size() << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 256
//
#include <vector>
#include <set>
#include <map>
#include <array>
#include <iostream>
#include <cstdio>
#include <cstdint>
#include <algorithm>
#include <numeric>
#include <bitset>
//
using ll = long long;
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);++i)
inline void yes(bool cond) { cond ? puts("Yes") : puts("No"); }
template<typename Type> inline void chmin(Type& a, Type b) { if (a > b) a = b; }
template<typename Type> inline void chmax(Type& a, Type b) { if (a < b) a = b; }
template<typename Arr, typename Type> inline void fill(Arr& arr, Type v) { std::fill(arr.begin(), arr.end(), v); }
template<typename Type> inline void sort(Type& arr) { std::sort(arr.begin(), arr.end()); }
template<typename Type> inline Type nth(vector<Type>& arr, size_t pos) { std::nth_element(arr.begin(), arr.begin() + pos, arr.end()); return arr[pos]; }
constexpr double BIGP = 1000000007L;
constexpr double INF_I = std::numeric_limits<double>::max();
constexpr double INF_F = std::numeric_limits<float>::infinity();
constexpr double PI = 3.14159265358979323846L;
//
int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    ll N, K;
    cin >> N >> K;
    ll ans = 0;
    rep(i, N)
    {
        ll h;
        cin >> h;
        if (h >= K)
        {
            ++ans;
        }
    }
    cout << ans;
    //
    return 0;
}

Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>
#include <random>
#include <complex>
#include <functional>
#include <tuple>
#include <new>

using namespace std;

#define EPS (1e-9)
#define INF (1e9)
#define MOD (ll)(1e9 + 7)
#define PI (acos(-1))
#define REP(i,a,n) for(int i=a;i<n;i++)
#define rep(i, n) REP(i,0,n)
#define allof(a) (a).begin(), (a).end()

#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" ; "IMPOSSIBLE")

using ll = long long int;

ll gcd(ll a, ll b) {
    if (a < b) swap(a, b);
    if (b == 0) return a;
    return gcd(b, a % b);
}

ll beki(ll a, ll b) {
    ll tmp = 1;
    rep(i, b) tmp *= a;
    return tmp;
}

ll modPow(ll x, ll a) {
    if (a == 1) return x;
    if (a % 2) return (x * modPow(x, a - 1)) % MOD;
    ll t = modPow(x, a / 2);
    return ((t % MOD) * (t % MOD)) % MOD;
}

ll modInv(ll x) {
    return modPow(x, MOD - 2);
}

string S;
int main() {
    cin >> S;
    bool aru = false;
    rep(i, 2) {
        if (S[i] != S[i + 1]) aru = true;
    }
    cout << Yes(aru) << endl;
}

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

using ll = long long;
using pii = pair<int, int>;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define per(i, b) per2(i, 0, b)
#define per2(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define ALL(c) (c).begin(), (c).end()
#define SZ(x) ((int)(x).size())

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }

template <class T, class U>
void chmin(T& t, const U& u) {
    if (t > u) t = u;
}
template <class T, class U>
void chmax(T& t, const U& u) {
    if (t < u) t = u;
}

template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "{";
    rep(i, v.size()) {
        if (i) os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

#ifdef LOCAL
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << H;
    debug_out(T...);
}
#define debug(...) \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif

constexpr ll INF = TEN(18);

int main() {
    int N, K;
    cin >> N >> K;
    V<int> P(N), C(N);
    rep(i, N) cin >> P[i], --P[i];
    rep(i, N) cin >> C[i];

    ll ans = -INF;

    rep(i, N) {
        int v = i;
        ll cycle_sum = 0;
        int cycle_cnt = 0;

        while (true) {
            cycle_cnt++;
            cycle_sum += C[v];
            v = P[v];
            if (v == i) break;
        }

        ll path = 0;
        int cnt = 0;

        while (true) {
            cnt++;
            path += C[v];

            if (cnt > K) break;

            int num = (K - cnt) / cycle_cnt;
            ll score = path + max(0ll, cycle_sum) * num;
            chmax(ans, score);

            v = P[v];
            if (v == i) break;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3612
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.AGC_033
{
    class B
    {
        static void Main(string[] args)
        {
            Method(args);
        }

        static void Method(string[] args)
        {
            int[] hwn = ReadInts();
            int h = hwn[0];
            int w = hwn[1];
            int n = hwn[2];
            int[] spos = ReadInts();
            string s = Read();
            string t = Read();

            int x = spos[1];
            for(int i = 0; i < n; i++)
            {
                if (s[i] == 'R') x++;
                if (x > w)
                {
                    WriteLine("NO");
                    return;
                }
                if (x > 1 && t[i] == 'L') x--;
            }
            x = spos[1];
            for (int i = 0; i < n; i++)
            {
                if (s[i] == 'L') x--;
                if (x < 1)
                {
                    WriteLine("NO");
                    return;
                }
                if (x < h && t[i] == 'R') x++;
            }

            int y = spos[0];
            for (int i = 0; i < n; i++)
            {
                if (s[i] == 'D') y++;
                if (y>h)
                {
                    WriteLine("NO");
                    return;
                }
                if (y > 1 && t[i] == 'U') y--;
            }
            y = spos[0];
            for (int i = 0; i < n; i++)
            {
                if (s[i] == 'U') y--;
                if (y < 1)
                {
                    WriteLine("NO");
                    return;
                }
                if (y < h && t[i] == 'D') y++;
            }

            WriteLine("YES");
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 13124
s = [[[0]*10 for i in range (3)] for j in range (4)]
n = int(input())
k = 0
for i in range(n):
    t = list(map(int,input().split()))
    s[t[0]-1][t[1]-1][t[2]-1] = s[t[0]-1][t[1]-1][t[2]-1] + t[3]
for u in s:
    if k == 1:
        print("#"*20)
    else:
        k = 1
    for v in u:
        for w in v:
            print(" " + str(w),end ="")
        print()


Measured memory_bytes: 5620
#include <bits/stdc++.h>
#include <iostream>
#include <cstdlib>

#include <algorithm>
#include <string>
#include <cctype>
using namespace std;

typedef long long int ll;
typedef pair<ll, ll> p_ll;
typedef vector<pair<ll, ll>> vec_p; //vector<pair<ll, ll>> pairs(n) ,pairs.at(i) = make_pair(i*i, i)

#define ture ture
#define flase false
#define falg flag

#define REP(i, x) for (ll i = 0; i < (ll)(x); i++)
#define REPS(i, x) for (ll i = 1; i <= (ll)(x); i++)
#define RREP(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (ll i = ((ll)(x)); i > 0; i--)
#define all(x) (x).begin(), (x).end()

const ll MOD = pow(10, 9) + 7;
const ll LLINF = pow(2, 61) - 1;//llの最大9*10^18
const int INF = pow(2, 30) - 1;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

char upper(char c)
{
    if ('a' <= c && c <= 'z')
    {
        c = c - ('a' - 'A');
    }
    return c;
}

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

    ll N;
    char S;
    string T;
    cin >> S;

    if ((int)S > 96)
    {
        T.push_back(upper(S));
    }
    else
    {
        T.push_back(S);
    }

    //transform(S.begin(), S.end(), S.begin(), toupper);

    if(S==T.at(0)){
        cout << "A" << endl;
    }
    else{
        cout << "a" << endl;
    }
}


Measured memory_bytes: 3576
#include <iostream>
#include <numeric>
#include <stdio.h>
#include <iomanip>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)






int main() {
	int n,m,c;
	cin >> n>>m>>c;
	
	cout << max(max(n, m), c) * 9 + (n + m + c) << endl;
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(obj) (obj).begin(), (obj).end()
#define bit(n) (1LL << (n))

typedef long long ll;

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; }

const long long INF = 1LL << 60;

bool solve(int x, int y, int z) {
  return (x+y>z and y+z>x and z+x>y);
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n; cin>>n;
  ll as[n];
  
  rep(i, n) {
    ll a; cin>>a;
    as[i] = a;
  }
  
  ll res = 0;
  
  rep(i, n-1) {
    ll aL = as[i];
    ll aR = as[i+1];
    
    if(aL>aR) {
      ll add = aL -aR;
      as[i+1] = add + aR;
      res += add;
    }
  }
  
  cout<<res;
  return 0;
}

Measured memory_bytes: 5196
use proconio::{fastout, input};
use std::collections::BTreeMap;

#[fastout]
fn main() {
    input! {
        n: usize,
        k: i64,
        q: usize,
        a: [i64; q]
    };

    let a: Vec<i64> = a.iter().map(|x| x - 1).collect();
    let mut map = BTreeMap::new();

    for i in a.iter() {
        let count = map.entry(i.to_string()).or_insert(0);
        *count += 1;
    }

    for i in 0..n {
        let x = map.get(&i.to_string());
        if x == None {
            if k - q as i64 > 0 {
                println!("Yes")
            } else {
                println!("No")
            }
        } else {
            let value = x.unwrap();
            if k - (q as i64 - value) > 0 {
                println!("Yes")
            } else {
                println!("No")
            }
        }
    }
}


Measured memory_bytes: 9312
#include <iostream>

int main(){
  int a,b,n;
  std::cin >> n;
  std::string res = "No";
  for (int i=1;i<=9;i++){
    if (n % i == 0){
      b = n / i;
      if (1 <= b && b<=9){
        res = "Yes";
        break;
      }
    }
  }
  std::cout << res << std::endl;
  return 0;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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 (a>b) { a=b; return 1; } return 0; }

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,k; cin>>n>>k;
    vi cnt(40);
    rep(i,n){
        ll a; cin>>a;
        rep(i,40)if(a>>(39-i)&1){
            cnt[i]++;
        }
    }
    vector<vll> dp(2,vll(41));
    rep(i,41) dp[1][i]=-1;
    dp[0][0] = 0;
    rep(i,40){
        int now = (k>>(39-i)&1);
        int c[2];
        c[1] = n-cnt[i];
        c[0] = cnt[i];
        rep(s,2)rep(j,2){
            int ns = s;
            if (dp[s][i]==-1) continue;
            if (now==0 && j==1 && s==0) continue;
            if (now==1 && j==0) ns = 1;
            chmax(dp[ns][i+1],dp[s][i]+(1ll<<(39-i))*c[j]);
        }
    }
    cout<<max(dp[0][40],dp[1][40])<<endl;
    return 0;
}


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

using ll = long long;
#define int long long
using P = pair<int, int>;

#define LOG(variable) cerr << #variable":\t" << (variable) << endl
#define LOGCON(i, container) for(int (i) = 0; (i) < (container).size(); ++(i)) cerr << (i) << ":\t" << (container)[(i)] << endl
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, n, r) for(int i = (n); i >= (r); --i) // from n to r
#define REPOBJ(itr, obj) for(auto itr = (obj).begin(); itr != (obj).end() ; ++itr)
#define REPROBJ(itr, obj) for(auto itr = (obj).rbegin(), e = (obj).rend(); itr != e; ++itr)
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))
template<typename T = int>
T in() {T a; cin >> a; return a;}

/***** MAIN *****/
signed main() {
  int n; cin >> n;
  string s; cin >> s;
  int left = 0;
  int right = n-1;
  int ans = 0;
  while(left < right) {
    while(s[left] != 'W' && left < n) {
      ++left;
    }
    while(s[right] != 'R' && right >= 0) {
      --right;
    }
    if(s[left] == 'W' && s[right] == 'R' && left < right) {
      s[left] = 'R'; s[right] = 'W';
      ++ans;
    }
  }
  cout << ans;
  cout << "\n";
  return 0;
}
/***** MAIN *****/


Measured memory_bytes: 3752
n = int(input())
a_arr = list(map(int, input().split()))
b_arr = list(map(int, input().split()))
c_arr = list(map(int, input().split()))
ans = sum(b_arr)
for i in range(n - 1):
    if a_arr[i] + 1 == a_arr[i + 1]:
        ans += c_arr[a_arr[i] - 1]

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

struct SegmentTree {
  using T = lint;
  static T op(const T& x, const T& y) { return min(x, y); }
  static constexpr T e() { return 1e18; }

  const int n;
  V<T> t;
  SegmentTree(int n) : n(n), t(2 * n, e()) {}
  T& operator[](int i) { return t[i + n]; }
  void build() { for (int i = n - 1; i; --i) t[i] = op(t[2 * i], t[2 * i + 1]); }
  T acc(int l, int r) const {
    T resl = e(), resr = e();
    for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
      if (l & 1) resl = op(resl, t[l++]);
      if (r & 1) resr = op(t[--r], resr);
    }
    return op(resl, resr);
  }
  void set(int i, const T& x) {
    t[i += n] = x;
    while (i >>= 1) t[i] = op(t[2 * i], t[2 * i + 1]);
  }
};

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n, q, a, b; cin >> n >> q >> a >> b, --a, --b;
  --q;
  int x; cin >> x, --x;
  SegmentTree pos(n), neg(n);
  pos.set(a, abs(x - b) + a);
  neg.set(a, abs(x - b) - a);
  pos.set(b, abs(x - a) + b);
  neg.set(b, abs(x - a) - b);
  lint o = 0;
  while (q--) {
    int y; cin >> y, --y;
    o += abs(y - x);
    lint mn = min(neg.acc(0, y) + y, pos.acc(y, n) - y) - abs(y - x);
    pos.set(x, min(pos[x], mn + x));
    neg.set(x, min(neg[x], mn - x));
    x = y;
  }
  lint res = 1e18;
  for (int i = 0; i < n; ++i) {
    res = min(res, o + pos[i] - i);
  }
  cout << res << '\n';
}

Measured memory_bytes: 6528
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <vector>

#define MAX_LEN (8000)

// dp table
int dpx[MAX_LEN + 1][2 * MAX_LEN + 1], dpy[MAX_LEN + 1][2 * MAX_LEN + 1];

using namespace std;

int main(int argc, char *argv[]) {
  // read inputs
  char insts[MAX_LEN + 1];
  int x, y;
  scanf("%s", insts);
  scanf("%d %d", &x, &y);
  const int len = strlen(insts);

  // create list of distances to move along each axis
  int cnt = 0, dx_init, dir = 0;
  vector<int> dxs, dys;
  for (int i = 0; i < len; i++) {
    const char inst = insts[i];
    if (inst == 'F') {
      cnt++;
    } else {
      if (dir == 0) {
        if (dys.size() == 0) {
          dx_init = cnt;
        } else {
          dxs.push_back(cnt);
        }
      } else {
        dys.push_back(cnt);
      }
      cnt = 0;
      dir = !dir;
    }
  }
  // record last
  if (dir == 0) {
    if (dys.size() == 0) {
      dx_init = cnt;
    } else {
      dxs.push_back(cnt);
    }
  } else {
    dys.push_back(cnt);
  }

  // printf("dx_init = %d\n", dx_init);
  // printf("dxs = ");
  // for (int dx : dxs) {
  //   printf("%d ", dx);
  // }
  // printf("\n");
  // printf("dys = ");
  // for (int dy : dys) {
  //   printf("%d ", dy);
  // }
  // printf("\n");

  // solve dp for x
  for (int j = 0; j < 2 * len + 1; j++) {
    dpx[0][j] = 0;
  }
  dpx[0][dx_init + len] = 1;
  for (int i = 0, i_end = dxs.size(); i < i_end; i++) {
    const int dx = dxs[i];
    for (int j = 0; j < 2 * len + 1; j++) {
      dpx[i + 1][j] = (j - dx >= 0 ? dpx[i][j - dx] : 0) ||
                      (j + dx < 2 * len + 1 ? dpx[i][j + dx] : 0);
    }
  }
  // for (int j = 0; j < 2 * len + 1; j++) {
  //   printf("%d ", dpx[dxs.size()][j]);
  // }
  // printf("\n");

  // solve dp for y
  for (int j = 0; j < 2 * len + 1; j++) {
    dpy[0][j] = 0;
  }
  dpy[0][len] = 1;
  for (int i = 0, i_end = dys.size(); i < i_end; i++) {
    const int dy = dys[i];
    for (int j = 0; j < 2 * len + 1; j++) {
      dpy[i + 1][j] = (j - dy >= 0 ? dpy[i][j - dy] : 0) ||
                      (j + dy < 2 * len + 1 ? dpy[i][j + dy] : 0);
    }
  }
  // for (int j = 0; j < 2 * len + 1; j++) {
  //   printf("%d ", dpy[dys.size()][j]);
  // }
  // printf("\n");

  if (dpx[dxs.size()][x + len] && dpy[dys.size()][y + len]) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }

  return 0;
}


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

int main() {
    int N;
    cin >> N;
    vector<int> a(N);
    long long sum = 0;
    for (int i = 0; i < N; i++) {
        cin >> a[i];
        sum += a[i];
    }
    long long x = 0, ans = 1e18;
    for (int i = 0; i < N - 1; i++) {
        x += a[i];
        ans = min(ans, abs(sum - 2 * x));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))
#define POW(n) (1LL<<(n))
#define IN(i,a,b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a>b) { a=b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
template <typename T> inline T LB(vector<T>& v, T a) { return *lower_bound(ALL(v),a); }
template <typename T> inline int LBP(vector<T>& v, T a) { return lower_bound(ALL(v),a) - v.begin(); }
template <typename T> inline T UB(vector<T>& v, T a) { return *upper_bound(ALL(v),a); }
template <typename T> inline int UBP(vector<T>& v, T a) { return upper_bound(ALL(v),a) - v.begin(); }
template <typename T1, typename T2> ostream& operator<< (ostream& os, const pair<T1,T2>& p) { os << p.first << " " << p.second; return os; }
template <typename T1, typename T2> istream& operator>> (istream& is, pair<T1,T2>& p) { is >> p.first >> p.second; return is; }
template <typename T> ostream& operator<< (ostream& os, const vector<T>& v) { REP(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
template <typename T> istream& operator>> (istream& is, vector<T>& v) { for(T& in : v) is >> in; return is; }
template <typename T = int> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }
template <typename T, typename V> typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) { t = v; }
template <typename T, typename V> typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) { for(auto &e : t) fill_v(e,v); }
const int MOD = 1000000007;
const int INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;

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

  int N;
  cin >> N;
  int ans = 0;
  for (int i = 1; i <= N; i++) {
    string s = to_string(i);
    if (s.size() % 2 == 1) ans++;
  }
  cout << ans << endl;


  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>

#define SREP(s,i,m) for(unsigned int i = s; i < m; ++i)
#define REP(i,m) SREP(0,i,m)

using namespace std;
#ifdef _MSC_VER
using LONG = __int64;
using ULONG = unsigned __int64;
#else
using LONG = long long int;
using ULONG = unsigned long long int;
#endif

// 二乗を計算する。
int sq(int x) { return x * x; }

// 領域内にいるか。
bool within(int x, int min, int max) {
	return min <= x && x <= max;
}

// container の中から key より小さい値を見つける。
// 見つからない場合は container.end() を返す。
template<typename T>
typename T::iterator less_than(T& container, typename T::key_type& key) {
	typename T::iterator prev = container.lower_bound(key);
	if (prev == container.begin()) prev = container.end();
	else prev--;
	return prev;
}

// container の中から key より大きい値を見つける。
// 見つからない場合は container.end() を返す。
template<typename T>
typename T::iterator greater_than(T & container, typename T::key_type & key) {
	return container.upper_bound(key);
}

// b^e (mod m) を求める
LONG modpow(LONG b, LONG e, LONG m) {
	LONG result = 1;
	while (e > 0) {
		if ((e & 1) == 1) result = (result * b) % m;
		e >>= 1;
		b = (b * b) % m;
	}
	return result;
}

LONG dp[300 + 100][300 * 300 + 100];
LONG dp2[300 + 100][300 * 300 + 100];
const LONG MOD = 998244353;
int main(void) {
	int N; LONG sum = 0;
	vector<LONG> a;
	cin >> N;
	a.resize(N);
	REP(i, N) {
		cin >> a[i];
		sum += a[i];
	}

	LONG ans = 1; LONG p3 = 1;
	vector<LONG> power3; power3.resize(N + 1);
	for (int i = 0; i < power3.size(); ++i) {
		power3[i] = p3; p3 *= 3LL; p3 %= MOD;
	}
	ans = power3[N];

	dp[0][0] = 1;
	for (int i = 0; i < a.size(); i++) {
		for (int sum = 0; sum <= 300 * 300; sum++) {
			dp[i + 1][sum] += 2 * dp[i][sum];
			dp[i + 1][sum] %= MOD;
			if (sum + a[i] <= 300 * 300) {
				dp[i + 1][sum + a[i]] += dp[i][sum];
				dp[i + 1][sum + a[i]] %= MOD;
			}
		}
	}
	LONG s = 0;
	for (int th = (sum + 1) / 2; th <= 300 * 300; th++) {
		s += dp[N][th];
		s %= MOD;
	}
	LONG sub = (3LL * s) % MOD;
	ans += MOD - sub;
	ans %= MOD;

	for (int sum = 0; sum <= 300 * 300; sum++) dp2[0][sum] = 0;
	for (int i = 0; i < a.size(); i++) dp2[i][0] = 1;
	dp2[0][a[0]] = 1;
	for (int i = 1; i < a.size(); i++) {
		for (int sum = 1; sum <= 300 * 300; sum++) {
			dp2[i][sum] = dp2[i - 1][sum] + (sum - a[i] >= 0 ? dp2[i - 1][sum - a[i]] : 0);
			dp2[i][sum] %= MOD;
		}
	}
	if (sum % 2 == 0) {
		ans += 3LL * dp2[a.size() - 1][sum / 2];
		ans %= MOD;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 426240