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

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

const int IINF = (1 << 30) - 1;
const long long LLINF = 1LL << 61;
const long long MOD = 1000000007LL;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

template<typename T>
bool chmax(T &_a, T _b){
    if(_a < _b){
        _a = _b;
        return true;
    }else{
        return false;
    }
}

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

    lint n;
    cin >> n;

    vector< LLP > v(5);
    rep(i, 5){
        cin >> v[i].first;
        v[i].second = i;
    }
    SORT(v);

    lint ans = (n - 1LL) / v[0].first + 1LL;
    ans += 4LL;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long  
#define pb push_back
#define mk make_pair
#define mod 1000000007
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
#define all(x) x.begin(),x.end()
int main()
{
    ios::sync_with_stdio(0) ;
    cin.tie(0); 
    ll n;
    cin>> n;
    ll a,b;
    cin>>a>>b;
    ll ans=1; ll aa=2;
   for(ll i=0;i<=31;i++)
   {   
       if(1<<i&n)
       {
           ans*=aa;
           ans%=mod;
        }
       aa*=aa;
       aa%=mod;
      
   }ans--;
   ll ans1=1;
   for(ll i=n;i>=n-a+1;i--)
   {
       ans1*=i;
       ans1%=mod;
   }
   ans1%=mod;ll ansa=ans1;ans1=1;
   for(ll i=n;i>=n-b+1;i--)
   {
       ans1*=i;
       ans1%=mod;
   }
   ll ansb=ans1;
   ll m=1000000005;
   ll bit[32]={0};
   for(ll i=0;i<=31;i++)
   {
       if(1<<i&m)
       bit[i]=1;
     
   }
   
   
   ll ans2=1;ll ans3=0;
   for(ll j=1;j<=a;j++)
   {    ll aa=j;
     for(ll i=0;i<=31;i++)
    {
       if(bit[i]==1)
       {
           ansa*=aa;
           ansa%=mod;
           
       }
       aa*=aa;
       aa%=mod;
     }
    }
    
    for(ll j=1;j<=b;j++)
   {    ll aa=j;
     for(ll i=0;i<=31;i++)
    {
       if(bit[i]==1)
       {
           ansb*=aa;
           ansb%=mod;
           
       }
       aa*=aa;
       aa%=mod;
     }
    }
    ans=ans-ansa-ansb;
    ans+=mod;
    ans+=mod;
    ans+=mod;
    ans%=mod;
    cout<<ans;
    return 0;
}
//make all values ll


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
typedef	long long ll;
typedef unsigned long long ull;
#define all(v) ((v).begin()),((v).end())
#define PI(n) ((double)acos(n))
int dx8[8] = { 1, -1, 0, 0, 1, 1, -1, -1 };
int dy8[8] = { 0, 0, 1, -1, 1, -1, 1, -1 };
void file()
{
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
#else
	// online submission
#endif
}
void fast()
{
	std::ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
}
int main()
{
	fast();
	int k, n;
	cin >> k >> n;
	vector<int>v(k);
	for (int i = 0; i < k; i++)
		cin >> v[i];

	sort(all(v));
	reverse(all(v));
	int sum = 0;
	for (int i = 0; i < n; i++){
		sum += v[i];
	}
	cout << sum << endl;

}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define enld endl //* missspell check
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

ll strDiff(string S1, string S2){
    ll n = S1.length();
    ll ans = 0;
    REP(i, n){
        if(S1[i] != S2[i]) ans ++;
    }
    return ans;
}

void solve(std::string S, std::string T){
    ll N = S.length(), M = T.length();
    ll ans = INF;
    REP(i, N-M+1){
        ll tmp = 0;
        tmp = strDiff(S.substr(i, M), T);
        chmin(ans, tmp);
    }
    cout<<ans<<endl;
}
int main(){
    std::string S;
    std::cin >> S;
    std::string T;
    std::cin >> T;
    solve(S, T);
    return 0;
}


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

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

typedef long long ll;
typedef pair<ll,ll> P;

template<typename T>
class segtree{
	int n;vector<T> dat;T ZERO;
public:
	segtree(int n_,T zero):ZERO(zero){
	  n = 1;
	  while(n < n_)n*=2;
	  dat.resize(2*n);
	  for(int i = 0;i < 2*n;i++)dat[i] = ZERO;
	}
	void update(int k, int a){
	  k += n - 1;dat[k] = a;
	  while(k > 0){
		k = (k-1)/2;
		dat[k] = function(dat[k*2+1],dat[k*2+2]);
	  }
	}
	
	T function(T a,T b){
		return a + b;
	}

	// 外からの呼び出しはquery(a,b,0,0,n) [l,r)に対応していることを示す。
	T query(int a,int b,int k,int l,int r){
	  if( r <= a || b <= l) return ZERO;
	  //[a,b)が[l,r)を完全に含んでいればこの節点の値
	  if(a <= l && r <= b)  return dat[k];
	  else{
		T vl = query(a,b,k*2+1,l,(l+r)/2);
		T vr = query(a,b,k*2+2,(l+r)/2,r);
		return function(vl,vr);
	  }
	}
	
	T get(int k){return dat[k+n-1];}
	T que(int a,int b){return query(a,b,0,0,n);}
};

bool check(ll mid,vector<ll> &v){
	ll ret = 0;
	vector<ll> now;
	REP(i,v.size()){
		if(v[i] >= mid)now.PB(1);
		else now.PB(-1);
	}
	
	DBG(SHOW1d(now,now.size()));
	
	ll mi = 0;
	REP(i,now.size()){
		if(i < now.size() - 1)now[i+1] += now[i];
		mi = min(mi,now[i]);
	}
	DBG(SHOW1d(now,now.size()));
	REP(i,now.size())now[i] -= mi;
	
	segtree<ll> sg(v.size()+2,0);
	sg.update(-mi,1);
	
	DBG(SHOW1d(now,now.size()));
	DBG(cout << "   ";REP(i,now.size())cout << sg.get(i) << ' ';cout << ret << endl;)
	REP(i,now.size()){
		ret += sg.que(0,now[i]+1);
		sg.update(now[i],sg.get(now[i])+1);
		DBG(cout << "   ";REP(i,now.size())cout << sg.get(i) << ' ';cout << ret << endl;)
	}
	
	DBG(cout << ret << ' ' << v.size() * (v.size()+1) / 4 << endl;)
	return ret >= v.size() * v.size() / 4;
}

int main(){
	
	int n;cin >> n;
	vector<ll> v(n);
	REP(i,n)cin >> v[i];
	
	ll tb = LLINF;
	ll ub = -LLINF;
	
	if(n == 1){
		cout << v[0] << endl;
		return 0;
	}
	
	while(abs(tb-ub) > 1){
		ll mid = (tb + ub) / 2;
		if(check(mid,v))ub = mid;
		else tb = mid;
		DBG(cout << mid << endl;)
	}
	
	cout << ub << endl;
	
	return 0;
}


Measured memory_bytes: 4972
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: u64,
    }
    println!("{}", n / 3);
}


Measured memory_bytes: 4352
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
using namespace std;
using ll = long long;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

int main () {
  int n;
  cin >> n;
  vector<vector<int> > adja(n), cost(n);

  REP(i, n-1){
    int a, b, w;
    cin>>a>>b>>w;
    a--;
    b--;
    adja[a].push_back(b);
    cost[a].push_back(w);
    adja[b].push_back(a);
    cost[b].push_back(w);
  }
  vector<int> ans(n, -1);
  queue<int> q;
  
  ans[0]=0;
  q.push(0);
  
  while (!q.empty()){
    int v = q.front();
    q.pop();
    
    REP(i, adja[v].size()){
      int node = adja[v][i];
      int weight = cost[v][i];
      if (ans[node]!=-1) continue;
      ans[node] = (ans[v]+weight)%2;
      q.push(node);
    }
  }
  REP(i, n){
    cout<<ans[i]<<'\n';
  }
  return 0;
}


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

#define int long long
#define vec vector
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define sq(x) (x)*(x)
#define fast_io ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)

using namespace std;
typedef pair<long long, long long> PII;
typedef long double ld;

signed main()
{
    int n;
    cin >> n;
    int ans = ceil(n/2.0);
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int A[100];
  int number,key,i,j,k;

  scanf("%d", &number);
  for(i = 0 ; i < number ; i ++){
    scanf("%d", &A[i]);
  }
  
  for( i = 0 ; i < number ; i ++){
    key = A[i];
    j = i-1;
    while(j >= 0 && A[j] > key){
      A[j+1] = A[j];
      j--;
    }
    A[j+1] = key;
    
    for(k = 0 ; k < number ; k++){
      printf("%d", A[k]);
      if( k == number-1){
	printf("\n");
	break;
      }
      printf(" ");
    }
  }
  return 0;
}

Measured memory_bytes: 604
#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 k;
  cin >> k;

  int evenSum = 0;
  int oddSum = 0;
  for (int i = 1; i <= k; i++) {
    if (i % 2 == 0) {
      evenSum++;
    } else {
      oddSum++;
    }
  }
  cout << (evenSum * oddSum) << endl;

  return 0;
}


Measured memory_bytes: 256
object Main extends App {
  val inputs: Seq[String] = scala.io.Source.stdin.getLines().toList
  val nums = inputs.head.split(" ").map(_.toInt)
  val n = nums(0)
  val m = nums(1)
  val images = inputs.tail

  println(solve(n, m, images))

  private def solve(n: Int, m: Int, images: Seq[String]): String = {
    val loopEnd = n - m
    val imagesTup = images.splitAt(n)
    val nImage  = imagesTup._1
    val mImage  = imagesTup._2
    val checkStart = mImage(0)(0)

    (0 to loopEnd).foreach { i =>
      val line = nImage(i)

      (0 to loopEnd).foreach { j =>
        if(line(j) == checkStart) {
          var ok = true
          (0 until m).foreach { k =>
            val checkLine = images(i + k).splitAt(j)._2.splitAt(m)._1
            if( checkLine != mImage(k)) {
              ok = false
            }
          }

          if(ok) {
            return "Yes"
          }
        }
      }

    }
    return "No"
  }
}


Measured memory_bytes: 56100
N,A,B=list(map(int, input().split()))

S_i=[]
for i in range(1,N+1):
    S=[]
    x=str(i)
    y=len(x)
    for j in range(y):
        S.append(int(x[j]))
    if A<=sum(S)<=B:
        S_i.append(i)
        
print(sum(S_i))

Measured memory_bytes: 3292
#include <iostream>
#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
#include<set>
#include<queue>
#include<map>
#include<cmath>
using namespace std;
#define LL long long
#define rep(i,a,n) for(int i=a;i<n;++i)
#define per(i,a,n) for(int i=n-1;i>=a;--i)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define sz(v) ((int)sizeof(v))
#define N 200005
char str[N];

int main()
{
    int x1,x2,y1,y2;
    int xx,yy,x0,y0;
    while(~scanf("%d%d%d%d",&x1,&y1,&x2,&y2)){
        xx=x2-x1;
        yy=y2-y1;

        y0=yy;
        while(y0--) cout<<'U';
        x0=xx;
        while(x0--) cout<<'R';

        y0=yy;
        while(y0--)cout<<'D';
        x0=xx;
        while(x0--) cout<<'L';

        cout<<'L';
        y0=yy+1;
        while(y0--)cout<<'U';
        x0=xx+1;
        while(x0--) cout<<'R';
        cout<<'D';

        cout<<'R';
        y0=yy+1;
        while(y0--)cout<<'D';

        x0=xx+1;
        while(x0--) cout<<'L';

        cout<<'U';
        cout<<'\n';
    }
    return 0;
}


Measured memory_bytes: 256
# define M_PIl          3.1415926535897932384626433832795029L 
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <limits>

#define FOR(i,k,n) for(long(i)=(k);(i)<(n);++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v),end(v)
#define deg_to_rad(deg) (((deg)/360)*2*M_PI)
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)

using namespace std;

int main()
{
  double  a,b,x;
  cin >>a>>b>>x;
  double  h = b - x/(a*a);
  if(h<=(b/2))
  {
  double tan = h/(a/2);
  double rad = atan(tan);
  cout << fixed << setprecision(10) <<rad_to_deg(rad);
  }
  else
  {
    double y = 2*x/(a*b);
    double tan2 = y/b;
    double rad2 = atan(tan2);
     cout << fixed << setprecision(10) <<90-rad_to_deg(rad2);
  }

  
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#define REP(i,n) for(int i = 0;i < (n);i++)
#define pb push_back
using namespace std;
const int INF = 1e9;
typedef long long ll;


string t;

int main(){
  string s;
  string a[4] = {"dream","dreamer","erase","eraser"};
  cin >> s;
  int f = 1;
  while(!s.empty()){
    string r,p;
    if(s.size() < 5){
      f = 0;
      break;
    }
    if(s.size() >= 5){
      r = s.substr(s.size()-5,5);
    }
    string q;
    if(s.size() >= 6){
       q = s.substr(s.size()-6,6);
    }
    
    if(s.size() >= 7){
       p = s.substr(s.size()-7,7);
    }
    //cout << r << "  " << q << "  " << p << endl;
    if(r == "dream"||r == "erase"){
      s.erase(s.end()-5,s.end());
    }
    else if(q == "eraser"){
      s.erase(s.end()-6,s.end());
    }
    else if(p == "dreamer"){
      s.erase(s.end()-7,s.end());
    }
    else{
      f = 0;
      break;
    }
  }
  if(f == 0){
    cout << "NO" << endl;
  }
  else{
    cout << "YES" << endl;
  }
  return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main () {
	int n;
	int a;
	int b;
	cin >> n >> a >> b;
	int train;
	int taxi;
	train = n*a;
	taxi = b;
	if(train < taxi){
	  cout << train << endl;
	}else {
	  cout << taxi << endl;
	}

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cerr << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cerr<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 500010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = (1 << 30) - 1;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
mt19937 rng; //use it by rng() % mod, shuffle(all(vec), rng)
///////////////////////////////////////////////////////////////////////////////////////////////////

ll Q, H, S, D;
ll N;

void solve() {
	cin >> Q >> H >> S >> D;
	cin >> N;
	ll O = min(min(4 * Q, 2 * H), S);
	cout << min(N / 2 * D + N % 2 * O, N * O) << "\n";
}

uint32_t rd() {
	uint32_t res;
#ifdef __MINGW32__
	asm volatile("rdrand %0" :"=a"(res) ::"cc");
#else
	res = std::random_device()();
#endif
	return res;
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
    cerr << fixed;
	cerr.precision(6);
	rng.seed(rd());
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
	if(!freopen("in.txt", "rt", stdin)) return 1;
#endif	
	solve();
    cerr << "Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
	return 0;
}



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

int main(){
  string S;
  cin >> S;
  
  int count_z = 0;
  int count_o = 0;
  
  for(int i = 0; i < S.size(); i++){
    if(i%2 == 1){
      if(S.at(i) == '0')
        count_o++;
      else
        count_z++;
    }
    else{
      if(S.at(i) == '0')
        count_z++;
      else
        count_o++;
    }
  }
  
  cout << min(count_z, count_o) << endl;
}

Measured memory_bytes: 512
n=int(input())
a=[int(i) for i in input().split()]
ans=[0]*n
for i in range(n):
    if i%2: ans[0]-=a[i]
    else: ans[0]+=a[i]

for i in range(1,n):
    ans[i]=(a[i-1]-ans[i-1]//2)*2
print(*ans)


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

int main(){
	ll a,b,c;
	cin >> a >> b >> c;
	if(4*a*b < (c-a-b)*(c-a-b) && c > a+b){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
 
#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v), end(v)
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl
 
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
typedef deque<bool> db;
template<class T> using vv=vector<vector< T > >;

int main() {
  int n;
  scanf("%d", &n);
  vi a(n);
  rep (i, n) {
    scanf("%d", &a[i]);
  }
  sort(all(a));
  vll accum(n, 0);
  accum[0] = a[0];
  rep (i, n-1) {
    accum[i+1] = accum[i] + a[i+1];
  }

  int sep = 0;
  for (int i = n-1; i > 0; --i) {
    if (a[i] > accum[i-1] * 2) {
      sep = i;
      break;
    }
  }
  printf("%d\n", n - sep);

  return 0;
}


Measured memory_bytes: 2040
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};

mod util {
    use std::io::stdin;
    use std::str::FromStr;
    use std::fmt::Debug;

    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn get<T: FromStr>() -> T
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    }

    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }

    #[allow(dead_code)]
    pub fn get2<T: FromStr, U: FromStr>() -> (T, U)
    where
        <T as FromStr>::Err: Debug,
        <U as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
        )
    }

    #[allow(dead_code)]
    pub fn get3<S: FromStr, T: FromStr, U: FromStr>() -> (S, T, U)
    where
        <S as FromStr>::Err: Debug,
        <T as FromStr>::Err: Debug,
        <U as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
        )
    }
}


#[allow(unused_macros)]
macro_rules! debug {
    ($x: expr) => {
        println!("{}: {:?}", stringify!($x), $x)
    }
}

fn main() {
    let n: usize = util::get();
    let a: usize = util::get();

    println!("{}", n * n - a);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;


signed main(){
    int h, w;
    cin >> h >> w;
    string s[110];
    rep(i, 0, h) cin >> s[i];
    int d[110][110] = {0};

    rep(i, 0, h){
        int p = 1000;        
        rep(j, 0, w){
            if(s[i][j] == 'c'){
                d[i][j] = 1;
                p = j;
            }
            if(j != 0 && p != 1000 && s[i][j] == '.') d[i][j] = j - p + 1;
        }
    }
    
    rep(i, 0, h){
        rep(j, 0, w){
            cout << d[i][j] - 1;
            if(j != w - 1) cout << ' ';
        }
        cout << endl;
    }
}

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


int main()
{

	ll x;
	cin >> x;

	ll val, rem;
	val = x / 500;

	rem = x%500;

	ll rem_val = rem/5;

	ll result = (val*1000) + (rem_val*5);

	cout << result << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int const NMAX = 50;
int freq[1 + NMAX];

int main() {

  int n, g = 0, GGY = 0, GGX = 0;
  cin >> n >> g;
  for(int i = 1;i <= g;i++){
    cin >> GGX >> GGY;
    freq[GGX]++;
    freq[GGY]++;
  }
  for(int i = 1;i <= n;i++){
    cout << freq[i] << '\n';
  }
  return 0;
}


Measured memory_bytes: 3568
#include<iostream>
#include<cmath>
typedef long long int lli;
using namespace std ;

lli gcd(lli x,lli y);
lli lcm(lli x,lli y,lli z);

int main(){
	lli a,b,c,d,count=0;
	cin>>a>>b>>c>>d;	

	count = b-a+1-b/c-b/d+b/lcm(c,d,gcd(c,d))+(a-1)/c+(a-1)/d-(a-1)/lcm(c,d,gcd(c,d));
	cout<<count<<'\n';
	return 0;
}

lli gcd(lli x,lli y){
    if (y == 0)  /* 餘 0，除數 x 即為最大公因數 */
        return x;
    else
        return gcd(y, x % y);  /* 前一步驟的除數為被除數，餘數為除數 */
}

lli lcm(lli x,lli y,lli z){
	return x*y/z;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <map>
using namespace std;
typedef long long lint;

int main() {
    int k;
    cin>>k;
    vector<lint> a;
    for(int i=1; i<=9; ++i) a.push_back(i);
    while(1) {
        if(k<=a.size()) {
            cout<<a[k-1]<<endl;
            return 0;
        }
        k-=a.size();
        vector<lint> old;
        swap(old, a);
        for(lint x:old) {
            for(int i=-1; i<=1; ++i) {
                int d=x%10 + i;
                if(d<0 || d>9) continue;
                lint nx=x*10+d;
                a.push_back(nx);
            }
        }
    }
    return 0;
}


Measured memory_bytes: 1712
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pqueue priority_queue
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

bool D[10];

int main() {
  int N, K;
  cin>>N>>K;
  int tmp;
  for(int i=0;i<K;++i) {
    cin>>tmp;
    D[tmp] = true;
  }
  int ans;
  string tmpans;
  bool can;
  for(int i=N;i<1000000;++i) {
    tmpans = to_string(i);
    can = true;
    for(int j=0;j<tmpans.size();++j) {
      if(D[tmpans[j]-'0']) can = false;
    }
    if(can) {
      ans = i;
      break;
    }
  }
  cout<<ans<<endl;
}



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

using namespace std;
#define pb push_back
#define db(x) cerr << #x << " = " << x << endl;
#define INF 0x3f3f3f3f3f3f3f3f
#define fi first
#define se second
#define vi vector<int>
#define vll vector<ll>
#define all(x) x.begin(), x.end()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vii vector<pii>
#define ll long long
#define ull unsigned long long
typedef long double ld;

#define MAXN 112345

const int mod = 1e9+7;

int n;
vi adj[MAXN];
int vis[MAXN][2];
ll dp[MAXN][2];

ll mul_mod(ll a, ll b)
{
    return ((a % mod) * (b % mod)) % mod;
}

ll add_mod(ll a, ll b)
{
    return ((a % mod) + (b % mod)) % mod;
}

ll solve(int u, int p_black, int pu)
{
    if (adj[u].size() == 1 && pu != 0)
    {
        return p_black ? 1:2;
    }

    if (vis[u][p_black])
        return dp[u][p_black];
    vis[u][p_black] = 1;

    ll res = 1;
    ll res_b = 1;
    for (int v : adj[u])
    {
        if (v != pu)
        {
            res = mul_mod(res, solve(v, 0, u));
            res_b = mul_mod(res_b, solve(v, 1, u));
        }
    }        

    if (!p_black)
        res = add_mod(res, res_b);

    return dp[u][p_black] = res;
}

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

    if (n == 1)
        return !printf("2\n");

    for (int i = 0; i < n - 1; i++)
    {
        int u, v;
        scanf("%d%d", &u, &v);
        adj[u].pb(v);
        adj[v].pb(u);
    }

    printf("%lld\n", solve(1, 0, 0));
    
}

Measured memory_bytes: 16768
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
# define ll int64_t
# define str string
# define rep(i,n) for(ll i=0;i<n;i++)
# define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007
# define PI 3.141592653589793
# define vec vector
#define dump(x) cerr<<#x<<"="<<x<<endl
using namespace std;



#define INF 2000000000
#define MAX_V 10



bool compare_by_b(pair<string,ll> a,pair<string,ll> b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

bool my_compare(pair<string,ll> a,pair<string,ll> b){
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}

ll modpow(ll a,ll n,ll mod1) {
    ll res=1;
    while(n>0){
        if(n&1) res=res*a%mod1;
        a = a*a%mod1;
        n >>= 1;
    }
    return res;
}

ll factorial(ll n){
    ll x=1;
    rrep(i,n) (x*=i)%=mod;
    return x;
}

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

ll lcm(ll a,ll b){
   return a/gcd(a,b)*b;
}

using graph = vector<vector<ll>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n,k;
    cin>>n>>k;
    cout<<modpow(k,n,mod)<<endl;
    return 0;
}



Measured memory_bytes: 3220
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
template<class T> bool umin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool umax(T &a, T b) { return a < b ? (a = b, true) : false; }
#define ALL(x) (x).begin(), (x).end()
LL POW(LL a,LL p,LL M){ if(!p) return 1LL;LL T = POW(a,p/2,M);T = T*T%M; if(p&1) T=T*(a%M)%M; return T; }
LL SQRT(LL a) { LL b = (LL)sqrtl(((double)a)+0.5); while(b*b<a) ++b; while(b*b>a) --b; return (b*b==a)?b:-1; }
//endl
//<------------------------edits---------------------------------------------->
const LL MOD = 1e9+7;//998244353
// #define LOCAL LDD
// #define int LL

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.precision(10);cout << fixed;
#ifdef LOCAL
  freopen("input.txt", "rt", stdin);
#endif
  LL ans = 1;
  LL mx = 1e18;
  int n;cin >> n;
  vector<LL> a(n);
  for(int i=0;i<n;i++) cin >> a[i];
  int cnt = 0;
  for(auto it:a) cnt += (it==0);
  if(cnt){
    cout << 0 << endl;
    return 0;
  }
  for(int i=0;i<n;i++){
    if(ans>mx/a[i]){
      cout << -1 << endl;
      return 0; 
    }
    ans *= a[i];
  } 
  cout << ans << endl;
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s\n";
  return 0;
}

Measured memory_bytes: 3940
#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstring>
using namespace std;

const int maxn = 1000 + 5;
int dp[maxn][maxn];
char x[maxn];
char y[maxn];

int main()
{
    int q;
    scanf("%d", &q);
    while (q--)
    {
        scanf("%s %s", x + 1, y + 1);
        memset(dp, 0, sizeof(dp));
        int m = strlen(x + 1);
        int n = strlen(y + 1);
        for (int i = 1; i <= m; i++)
            for (int j = 1; j <= n; j++)
            {
                if (x[i] == y[j])
                    dp[i][j] = dp[i-1][j-1] + 1;
                else
                    dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
            }
        printf("%d\n", dp[m][n]);
    }
    return 0;
}



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

using namespace std;

#ifndef aa
#define trace(...)
#define endl '\n'
#endif
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define fi first
#define se second
#define int long long
typedef long long ll;
typedef long double ld;
#define double long double
#define pii pair<int,int>
#define pdd pair<double,double>
#define pll pair<ll,ll>
#define sz(x) ((long long)x.size())
#define fr(a,b,c) for(int a=b; a<=c; a++)
#define frev(a,b,c) for(int a=c; a>=b; a--)
#define rep(a,b,c) for(int a=b; a<c; a++)
#define trav(a,x) for(auto &a:x)
#define all(con) con.begin(),con.end()
#define deb(x) cout << x << endl
#define done(x) {cout << x << endl;return;}
const ll infl = 0x3f3f3f3f3f3f3f3fLL;
const int infi = 0x3f3f3f3f;
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());
//const int mod = 998244353;
const int mod = 1e9 + 7;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<pair<int, int>> vpii;
typedef map<int, int> mii;
typedef set<int> si;
typedef set<pair<int,int>> spii;
typedef queue<int> qi;


const int N = 1e7+5;
int dp[N];

void solve() {

  int n,ans=0;
  cin>>n;
  fr(i,1,n){
    for(int j = i; j <= n; j+=i)
       dp[j]++;
    ans+=i*dp[i];
  }
  cout<<ans;

}


signed main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    //srand(chrono::high_resolution_clock::now().time_since_epoch().count());
    cout << fixed << setprecision(15);
    int t = 1;
   //cin >> t;

    while (t--)
        solve();
#ifdef aa
    cout << endl << endl << endl << endl << "Time elapsed: " << (double)(clock() - clk) / CLOCKS_PER_SEC << endl;
#endif
    return 0;
}




int powm(int a, int b) {
    int res = 1;
    while (b) {
        if (b & 1)
            res = (res*a) % mod;
        a = (a * a) % mod;
        b >>= 1;
    }
    return res;
}


int divide(int a, int b) {
    return (a % mod) * powm(b, mod - 2) % mod;
}

int norm(int a) {
    while (a >= mod) a -= mod;
    while (a < 0) a += mod;
    return a;
}


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

Measured memory_bytes: 81732
n = int(input())
a = list(map(int,input().split(" ")))
b = list(map(int,input().split(" ")))
fb = sum(b)
for i in range(n):
  tmp = min(a[i],b[i])
  a[i] -= tmp
  b[i] -= tmp
  tmp = min(a[i+1],b[i])
  a[i+1] -= tmp
  b[i] -= tmp
result = fb - sum(b)
print(result)
  

Measured memory_bytes: 18624
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
using namespace std;

template<typename T>
ostream& operator << (ostream& os, vector<T>& v){
	rep(i,v.size()){ os << v[i] << (i == v.size() - 1 ? "" : " "); } return os;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& v){
	for(T& x: v){ is >> x; } return is;
}

bool check(vector<string>& s, int n){
	rep(i,n){
		rep(j,n){
			if(s[i][j] != s[j][i]){
				return false;
			}
		}
	}
	return true;
}

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

	vector<string> s(n);
	rep(i,n){
		cin >> s[i];
		s[i] += s[i];
	}

	int cnt = 0;
	rep(i,n){
		vector<string> t(n);
		rep(j,n){
			rep(k,n){
				t[j] += s[j][i + k];
			}
		}
		if(check(t, n)) cnt++;
	}
	cout << cnt * n << endl;
}


Measured memory_bytes: 784
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val a = Array(n) {
        readLine()!!.toInt()
    }
    val m = a.sortedDescending()
    for (i in 0 until n) {
        println(if (a[i] == m[0]) m[1] else m[0])
    }
}

Measured memory_bytes: 61492
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>
#include <cmath>
#include <sstream>

#define all_range(C) std::begin(C), std::end(C)



long long A[50000];
int main()
{
	using std::endl;
	using std::cout;
	using std::cin;

	while (true)
	{
		int n;
		cin >> n;
		if (n == 0) { break; }

		long long sum = 0;
		for (int i = 0; i < n; ++i) {
			cin >> A[i];
			sum += A[i];
		}
		long long ave = sum / n;
		int count = 0;
		for (int i = 0; i < n; ++i) {
			if (A[i] <= ave) {
				++count;
			}
		}
		cout << count << endl;
	}

	return 0;
}
#endif



Measured memory_bytes: 3148
n=int(input())
s=[]
ac=0
wa=0
tle=0
re=0
for i in range(n):
  s.append(input())
  if s[i]=="AC":
    ac=ac+1
  elif s[i]=="WA":
    wa=wa+1
  elif s[i]=="TLE":
    tle=tle+1
  elif s[i]=="RE":
    re=re+1
print("AC x "+str(ac))
print("WA x "+str(wa))
print("TLE x "+str(tle))
print("RE x "+str(re))

Measured memory_bytes: 16040
B, A, R = map(int, input().split())

P = [list(map(int,input().split())) for i in range(B)]

V = 100000000

for i in range(1, 2 ** B):
	bag = []
	choniki = [0]*A
	for j in range(B):
		check = 0  
		if ((i >> j) & 1):  
			bag.append(P[j][0])
			for k in range (0, A):
				choniki[k]+=P[j][k+1]
			for l in range (0, A):
				if choniki[l] < R:
					check = 1
			if check == 0 and sum(bag) < V:
				V = sum(bag)

if V < 100000000:
	print(V)
else:
	print(-1)

Measured memory_bytes: 9168
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
    int tmp = N;
    int count=0;
	while(tmp>=1){
        tmp /= 10;
        count++;
    }
    switch(count){
        case(1):
        cout << N << endl;
        break;
        case(2):
        cout << 9 << endl;
        break;
        case(3):
        cout << 9+(N-99) << endl;
        break;
        case(4):
        cout << 9+999-99 << endl;
        break;
        case(5):
        cout << 9+999-99+(N-9999)<< endl;
        break;
        case(6):
        cout << 9+999-99+99999-9999<< endl;
        break;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl
#define svec(v) cout<<#v<<":";rep(pachico,v.size())cout<<" "<<v[pachico];cout<<endl
#define svecp(v) cout<<#v<<":";each(pachico,v)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(pachico,s)cout<<" "<<pachico;cout<<endl
#define smap(m) cout<<#m<<":";each(pachico,m)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100005;

template<typename T> class Dijkstra {
public:
	struct edge{
		int to; T cost;
	};
	int V;
	vector<vector<edge> > G;
	vector<T> d;
	using pti = pair<T,int>;
	Dijkstra(int node_size) : V(node_size), G(V), d(V, numeric_limits<T>::max()){}
	//無向グラフの場合
	void add_edge(int u,int v,T cost){
		G[u].pb((edge){v,cost});
	}
	void solve(int s){
		priority_queue<pti,vector<pti>,greater<pti> > que;
		d[s] = 0;
		que.push(pti(0,s));
		while(!que.empty()){
			pti p = que.top();
			que.pop();
			int v = p.second;
			if(d[v] < p.first) continue;
			for(auto& w : G[v]){
				if(d[w.to] > d[v] + w.cost){
					d[w.to] = d[v] + w.cost;
					que.push(pti(d[w.to],w.to));
				}
			}
		}
	}
};

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int K;
    cin >> K;
    Dijkstra<int> dj(K);
    rep(i,K){
        dj.add_edge(i, (i+1)%K, 1);
        rep(j,10){
            dj.add_edge(i, (i*10+j)%K, j);
        }
    }
    dj.solve(1);
    cout << dj.d[0]+1 << "\n";
    return 0;
}

Measured memory_bytes: 19192
<?php
  list($n) = explode(" ", trim(fgets(STDIN)));
  list($s) = explode(" ", trim(fgets(STDIN)));
  
  $wc = 0;
  for ($i=0; $i<$n; $i++) {
    if($s[$i] == "R"){
      $wc++;
    }
  }
  $rc = 0;
  for ($i=0; $i<$wc; $i++) {
    if($s[$i] == "W"){
      $rc++;
    }
  }

  echo $rc;
  

Measured memory_bytes: 16200
#include<bits/stdc++.h> 
using namespace std; 
#define MAXC 3000

char cads[MAXC+1], cadt[MAXC+1];
int dp[MAXC+1][MAXC+1];

int s,t;
char lcs[MAXC+1];

int main() { 
	int i,j;
        int posicion;
	scanf("%s",cads);
	scanf("%s",cadt);
	s=strlen(cads); t = strlen(cadt);
	for (i=0; i<=s; i++) {
		dp[i][0]=0;
	}
	for (j=1; j<=t; j++) {
		dp[0][j]=0;
	}

	for (i=1;i<=s; i++) {
		for (j=1; j<=t; j++) {
			if (cads[i-1]==cadt[j-1]) {
				dp[i][j]=dp[i-1][j-1]+1;
			}
			else {
				dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
			}
		}
	}
	/*for (i=0; i<=s; i++) {
		for (j=0; j<=t; j++) {
			printf("%5d", dp[i][j]);
		}
		printf("\n");
	}
	printf("%d\n",dp[s][t]);*/
	posicion=dp[s][t];
	lcs[posicion]=0;
	for (i=s, j=t; i>0 && j>0; ) {
		if (cads[i-1]==cadt[j-1]) {
			posicion--; i--; j--;
			lcs[posicion]=cads[i];
		}
		else if (dp[i-1][j]>dp[i][j-1]) {
			i--;
		}
		else { 
			j--; 
		}
	}
	printf("%s\n", lcs);
	return 0; 
} 


Measured memory_bytes: 38852
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define ll          long long
#define pb          push_back
#define eb 			emplace_back
#define mp 			make_pair
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define vii         vector<pii>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define all(a)      (a).begin(),(a).end()
#define fi          first
#define si          second
#define sz(x)       (ll)x.size()
#define endl        '\n'
#define checkbit(n, b) ((n >> b) & 1)
#define mod        1000000007
#define inf        1000000000000000000
#define puts(n)		cout<<n;
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define setbits(x) __builtin_popcount(x)
#define mset(m,v) memset(m,v,sizeof(m))
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll a;
	cin>>a;
	ll b=a*a,c =b*a;
	cout<<a+b+c;
	
	return 0;
}

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

int main(){
    string inp[2];
    int output[81],n;
    cin >> n;
    while(n--){
        cin >> inp[0] >> inp[1];
        if(inp[0].size()>80||inp[0].size()>80) cout << "overflow" << endl;
        else{
            fill(output,output+81,0);
            reverse(inp[0].begin(),inp[0].end());
            reverse(inp[1].begin(),inp[1].end());
            for(int i=0;i<81;i++){
                if(i<inp[0].size()) output[i]+=inp[0][i]-'0';
                if(i<inp[1].size()) output[i]+=inp[1][i]-'0';
                if(i!=80&&output[i]>9){
                    output[i+1]+=output[i]/10;
                    output[i]%=10;
                }
            }
            if(output[80]>0) cout << "overflow" << endl;
            else{
                bool flag=false;
                for(int i=79;i>=0;i--){
                    if((!flag&&output[i]!=0)||i==0) flag=true;
                    if(flag) cout << output[i];
                }
                cout << endl;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 1204
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner scanner = new Scanner(System.in);
    long n = scanner.nextLong();
    long k = scanner.nextLong();
    long r = n%k;
    
    long ans = Math.min(r, (k-r));
    System.out.println(ans);
    scanner.close();
  }

	
}


Measured memory_bytes: 21716
#include <stdio.h>

int main(void) {
    
    int height[10],i,j,x;
    
    for(i=0;i<10;i++)
        scanf("%d",&height[i]);
    
    for(i=10;i>0;i--){
        for(j=0;j<i;j++){
            if(height[j]>height[j+1]){
                x=height[j+1];
                height[j+1]=height[j];
                height[j]=x;
            }
        }
    }
    
    
    for(i=9;i>6;i--)
        printf("%d\n",height[i]);
    
    
    return 0;
}

Measured memory_bytes: 600
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}

int main(){
  int n;
  cin >> n;
  int a[n];
  vector<bool> flag(n,false);
  for(int i = 0; i < n; i++){
    cin >> a[i];
    a[i]--;
  }
  int current = 0;
  int cnt = 0;
  while(true){
    if(current == 1){
      cout << cnt << endl;
      return 0;
    }else if(flag[current]){
      cout << -1 << endl;
      return 0;
    }
    flag[current] = true;
    current = a[current];
    cnt++;
  }
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <sstream>
#include <iomanip>
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define min_3(a,b,c) min(a,min(b,c))
#define max_3(a,b,c) max(a,max(b,c))
#define nout(ans) cout << (ans) << "\n"
#define sout(ans) cout << (ans) << " "
using namespace std;

const double pi = 3.14159265359;
const ll INF = 1e12;
const ll MOD = 1e9 + 7;
const ll N = 1e5 + 5;
/*
Decimal Places: cout << fixed << setprecision(n) << ans << endl

String to integer:
stringstream dark(s);
int x = 0; dark >> x;
*/

bool compare(const pair<int, int>&i, const pair<int, int>&j)
{
    return i.second < j.second;
}


string s;

void solve()
{
    cin >> s;
    for (int i=0; i<s.size()-1;i++) {
        if (s[i]==s[i+1]) {
            nout("Bad");return;
        }
    }nout("Good");
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int t = 1;
    //cin >> t;
    for (int i=1; i<=t; i++)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
def GCD(a, b):
    """ Euclidean algorithm"""
    if a < b: (a, b) = (b, a)
    if b == 0: return a
    m = a % b
    while m != 0:
        a = b
        b = m
        m = a % b
    return b

N = int(input())
A = [ int(v) for v in input().split() ]
AR = list(reversed(A))

if N < 2 and 1e5 < N: raise()
for v in A:
    if v < 1 and v < 1e9: raise()

l_list = [0]
r_list = [0]
for i in range(0, N):
    l_list.append( GCD(l_list[i],  A[i]) )
    r_list.append( GCD(r_list[i], AR[i]) )

n = []
j = -2   
for i in range(0, N):
    n.append(GCD(l_list[i], r_list[j]))
    j -= 1
print(max(n))

Measured memory_bytes: 14400
#include <bits/stdc++.h>
#define mem(ar,num) memset(ar,num,sizeof(ar))
#define me(ar) memset(ar,0,sizeof(ar))
#define lowbit(x) (x&(-x))
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int    prime = 999983;
const int    INF = 0x7FFFFFFF;
const LL     INFF =0x7FFFFFFFFFFFFFFF;
const double pi = acos(-1.0);
const double inf = 1e18;
const double eps = 1e-6;
const LL     mod = 1e9 + 7;
LL solve(LL a,LL b,LL c,LL d,LL v)
{
    if(v%5==0)
        return a;
    int tmp = v%5;
    v = v-tmp+5;
    LL sum = b*5+c*10+d*50;
    return a + sum/v*(5-tmp);
}
int main(void)
{

   int n;
   cin>>n;
   cout<<n/3<<endl;
   return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <iomanip>
#include <queue>
#include <numeric>
#define repl(i, l, r) for (ll i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)

using namespace std;
using ll = long long;

int main() {

    ll x, y;
    cin >> x >> y;

    ll ans;

    if (abs(x) == abs(y)) {
        ans = 1;
    }
    else if (x < y) {
        ans = abs(abs(y) - abs(x));
        if (abs(y) - abs(x) < y - x && y > 0) {
            ans += 1;
        }
    }
    else if (x > y) {
        ans = abs(abs(y) - abs(x)) + 2;
        if (y == 0) {
            ans--;
        }
        if (x == 0) {
            ans--;
        }
        if (x > 0 && y < 0) {
            ans --;
        }
    }

    cout << ans;
   
    return 0;
}


Measured memory_bytes: 3632