akhauriyash/Code-Regression huggingface dataset:
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

fn main(){
    let s : Vec<i64> = read_vec();
    let mut n : i64 = s[0];
    let k : i64 = s[1];
    let mut digit : i64 = 1;

    if k > 1 {
        if n >= k {
            loop {
                digit += 1;
                n /= k;
                if(n < k) { break; }
            }
        }
    }
    else{
        digit = n;
    }
    println!("{}", digit);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD=1000000007;
#define REP(i,n) for(ll i=0; i<(n); i++)
#define REP2(i,x,n) for(ll i=x; i<(n); i++)
const long long INF = numeric_limits<long long>::max();
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main()
{
    ll N;
    cin >>N;

    ll digit = INF;
    for ( ll i = 1; i * i <= N; ++ i ){
        if ( (N%i) == 0 ){
            ll d1 = 0;
            for ( ll v = i; v > 0; v /= 10 )    d1++;
            ll d2  = 0;
            for ( ll v = N/i; v > 0; v /= 10 )    d2++;
            chmin(digit, max(d1,d2));
        }
    }
    #ifdef SOURCE_TEST
        for ( auto& p : pairs ){
            cout << p.first << ":" << p.second << endl;
        }
    #endif

    cout << digit << endl;
    return 0;
}

Measured memory_bytes: 3636
import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
       
        int N = sc.nextInt();//羊
		int X = sc.nextInt();//  
           String x = (N>X) ?"safe":"unsafe";
           System.out.println(x);
     }
    }


Measured memory_bytes: 35688
#include <stdio.h>
int main()
{
	int a[3][105];
	int i, j, n;
	scanf("%d", &n);
	for(i = 1 ; i <= 2 ; i++)
	{
		for(j = 1 ; j <= n ; j++)
		{
			scanf("%d", &a[i][j]);
		}
	}
	int max = 0;
	int all = 0;
	for(i = 1 ; i <= n ; i++)
	{
		all = 0;
		for(j = 1 ; j <= i ; j++)
		{
			all = all + a[1][j];
		}
		for(j = i ; j <= n ; j++)
		{
			all = all + a[2][j];
		}
		if(max < all)
		{
			max = all;
		}
	}
	printf("%d\n",max);
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <map>
#define llint long long
#define mod 1000000007

using namespace std;
typedef pair<llint, llint> P;

struct edge{
	llint to, cost, color;
	edge(llint a, llint b, llint c){
		to = a, cost = c, color = b;
	}
};

llint n, Q;
map<P, P> mp;
vector<edge> G[100005];
vector<int> vec[100005];
llint x[100005], y[100005], u[100005], v[100005];

int Prev[100005][17];
llint depth[100005], dist[100005];

int getLCA(int u, int v){
	int x = u, y = v;
	if(depth[y] > depth[x]) swap(x, y);
	
	for(int i = 16; i >= 0; i--){
		if(depth[x] - (1<<i) >= depth[y]) x = Prev[x][i];
	}
	if(x == y) return x;
	for(int i = 16; i >= 0; i--){
		if(Prev[x][i] != Prev[y][i]){
			x = Prev[x][i];
			y = Prev[y][i];
		}
	}
	x = Prev[x][0];
	return x;
}

void dfs(int v, int p, int dep, llint dis)
{
	Prev[v][0] = p;
	depth[v] = dep, dist[v] = dis;
	for(int i = 0; i < G[v].size(); i++){
		if(G[v][i].to == p) continue;
		dfs(G[v][i].to, v, dep+1, dis + G[v][i].cost);
	}
}

llint num[100005], sum[100005];
void dfs2(int v, int p)
{
	for(int i = 0; i < vec[v].size(); i++){
		llint c = vec[v][i];
		mp[make_pair(v, c)] = make_pair(num[c], sum[c]);
		//cout << v << " " << c << " " << num[v] << " " << sum[v] << endl;
	}
	for(int i = 0; i < G[v].size(); i++){
		if(G[v][i].to == p) continue;
		num[G[v][i].color]++;
		sum[G[v][i].color] += G[v][i].cost;
		dfs2(G[v][i].to, v);
		num[G[v][i].color]--;
		sum[G[v][i].color] -= G[v][i].cost;
	}
}

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> Q;
	for(int i = 1; i <= n-1; i++){
		llint u, v, c, d;
		cin >> u >> v >> c >> d;
		G[u].push_back(edge(v, c, d));
		G[v].push_back(edge(u, c, d));
	}
	dfs(1, -1, 0, 0);
	
	for(int i = 1; i < 17; i++){
		for(int j = 1; j <= n; j++){
			Prev[j][i] = Prev[Prev[j][i-1]][i-1];
		}
	}
	for(int i = 0; i < Q; i++){
		cin >> x[i] >> y[i] >> u[i] >> v[i];
		vec[u[i]].push_back(x[i]);
		vec[v[i]].push_back(x[i]);
		vec[getLCA(u[i], v[i])].push_back(x[i]);
		//cout << u[i] << " " << v[i] << " " << getLCA(u[i], v[i]) << endl;
	}
	dfs2(1, -1);
	
	for(int i = 0; i < Q; i++){
		llint lca = getLCA(u[i], v[i]);
		llint ans = dist[u[i]] + dist[v[i]] - 2*dist[lca];
		llint cnt = mp[make_pair(u[i], x[i])].first + mp[make_pair(v[i], x[i])].first - 2*mp[make_pair(lca, x[i])].first;
		llint sum = mp[make_pair(u[i], x[i])].second + mp[make_pair(v[i], x[i])].second - 2*mp[make_pair(lca, x[i])].second;
		//cout << cnt << " " << sum << endl;
		ans -= sum;
		ans += cnt * y[i];
		cout << ans << "\n";
	}
	flush(cout);
	
	return 0;
}

Measured memory_bytes: 51252
import java.io.*;
import java.util.*;
import java.lang.Math;
import java.util.Arrays;

public class Main {
    public static void main(final String[] args) {

        Scanner sc = new Scanner(System.in);
        
        int n;
        while (true) {
            n = sc.nextInt();
            if (n == 0)
                break;
            double s[] = new double[n];
            double ave = 0;
            for (int i = 0; i < n; i++) {
                s[i] = sc.nextDouble();
                ave += s[i];
            }

            ave /= (double) n;
            double d = 0;
            for (int i = 0; i < n; i++) {
                d += (s[i] - ave) * (s[i] - ave);
            }
            d /= (double) n;
            System.out.printf("%.7f\n", Math.sqrt(d));
        }
    }
  
}


Measured memory_bytes: 39516
import math

a, b, x = map(int, input().split())

sa = a ** 2
sb = a * b

if x / sa >= b / 2:
    y = ((b - x / sa) * 2) / a
    ans = math.atan(y) * 180 / math.pi
else:
    y = b / (2 * x / sb)
    ans = math.atan(y) * 180 / math.pi

print(ans)

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

typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1e18+7;
#define rep(i,N) for(ll i=0; i<(N); i++)
#define rep1(i,N) for(ll i=1; i<(N); i++)
#define pb push_back

string S,T;
map<char,ll> s,t;
map<char,char> cs,ct;
map<char,bool> ss,tt;
string s1,t1;

int main(){

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

cin>>S>>T;

//種類おけ？
rep(i,S.size()){
	s[S[i]]++;
	t[T[i]]++;
}
ll s_cnt=0,t_cnt=0;
rep(i,26){
	char c='a'+i;
	if(s[c]) s_cnt++;
	if(t[c]) t_cnt++;
}
if(s_cnt!=t_cnt){
	cout<<"No"<<endl; return 0;
}
//構造おけ？
ll k1=0; cs[S[0]]='a'; ss[S[0]]=true;
rep(i,S.size()){
	if(ss[S[i]]!=true){
		k1++; 
		cs[S[i]]='a'+k1;
		ss[S[i]]=true;
	}
	s1+=cs[S[i]];
}
ll k2=0; ct[T[0]]='a'; tt[T[0]]=true;
rep(i,T.size()){
	if(tt[T[i]]!=true){
		k2++; 
		ct[T[i]]='a'+k2;
		tt[T[i]]=true;
	}
	t1+=ct[T[i]];
}
if(s1!=t1){
	cout<<"No"<<endl; return 0;
}
cout<<"Yes"<<endl;

}
	


Measured memory_bytes: 1300
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

#define INF 1000000000;

int main(){
  int D,G;
  cin >> D >> G;
  int p[D],c[D];
  for(int i=0;i<D;i++){
    cin >> p[i] >> c[i];
  }

  int ans=INF;
  for(int i=0 ; i< (1 << D) ; i++){
    int itmp = i;
    vector<int> use;
    vector<int> unuse;
    for(int j=0;j<D;j++){
      if(itmp%2 == 1) use.push_back(j);
      else unuse.push_back(j);
      itmp/=2;
    }

    /*cout << "use:";
    for(int j=0;j<use.size();j++){
      cout << use[j] ;
    }
    cout << endl;*/
    reverse(unuse.begin(),unuse.end());
    /*cout << "unuse:";
    for(int j=0;j<unuse.size();j++){
      cout << unuse[j] ;
    }
    cout << endl;*/

    int score=0;
    int res=0;
    for(int j=0;j<use.size();j++){
      res+=p[use[j]];
      score+=p[use[j]]*(use[j]+1)*100;
      score+=c[use[j]];
    }

    if(score>=G){
      //cout << "res=" << res << endl;
    //  cout << "score=" << score << endl;
    //  cout << endl;
      ans=min(ans,res);
      continue;
    }else{
      int pcpy[D];
      for(int j=0;j<D;j++) pcpy[j]=p[j];
      int jtmp = 0;
      while(score<G){
        if(jtmp==unuse.size()-1 && pcpy[unuse[jtmp]]==0) break;
        if(pcpy[unuse[jtmp]]>0){
          //cout << 'a';
          score+=(unuse[jtmp]+1)*100;
          res++;
          pcpy[unuse[jtmp]]--;
        }else{
          //cout << 'b';
          score += c[unuse[jtmp]];
          jtmp++;
        }
      }
      //cout << "res=" << res << endl;
      //cout << "score=" << score << endl;
      //cout << endl;
      ans = min(ans,res);
    }
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

int main() {
    int a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;
    int min_price = numeric_limits<int>::max();
    for (size_t ab = 0; ab <= 2 * max(x, y); ab += 2) {
        int price = ((ab <= 2 * x) ? (x - ab / 2) * a : 0) + ((ab <= 2 * y) ? (y - ab / 2) * b : 0) + c * ab;
        if (price <= min_price) min_price = price;
    }
    cout << min_price << endl;
    return EXIT_SUCCESS;
}

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

double getSmallestDiago( double diago1, double diago2, double diago3 );

int main( void )
{
	int cheeseX;
	int cheeseY;
	int cheeseZ;
	
	double diagoXtoY;
	double diagoYtoZ;
	double diagoZtoX;
	
	double smallestDiago;
	
	int numOfEntrance;
	
	int sizeOfR;
	
	int i;
	
	while( 1 )
	{
		
		scanf( "%d%d%d", &cheeseX, &cheeseY, &cheeseZ );
		if( cheeseX == 0 && cheeseY == 0 && cheeseZ == 0 )break;
		diagoXtoY = sqrt( cheeseX * cheeseX + cheeseY * cheeseY );
		diagoYtoZ = sqrt( cheeseY * cheeseY + cheeseZ * cheeseZ );
		diagoZtoX = sqrt( cheeseZ * cheeseZ + cheeseX * cheeseX );
		
		smallestDiago = getSmallestDiago( diagoXtoY, diagoYtoZ, diagoZtoX );
		
		scanf( "%d", &numOfEntrance );
		for( i = 0; i < numOfEntrance; i++ )
		{
			scanf( "%d", &sizeOfR );
			if( sizeOfR * 2 > smallestDiago )
			{
				printf( "OK\n" );
			}
			else
			{
				printf( "NA\n" );
			}
		}
	}
	return (0);
}

double getSmallestDiago( double diago1, double diago2, double diago3 )
{
	double smallestDiago;
	if( diago1 <= diago2 && diago1 <= diago3 )
	{
		return ( diago1 );
	}
	else if( diago2 <= diago3 && diago2 <= diago1 )
	{
		return ( diago2 );
	}
	else
	{
		return ( diago3 );
	}
}

Measured memory_bytes: 584
n = int(input())
nums = list(map(int, input().split()))

counts = []
for i in range(n):
    num = nums[i]
    count = 0
    while True:
        k = num % 2
        if k == 0:
            count += 1
            num //= 2
        else:
            break
    counts.append(count)
print(min(counts))

Measured memory_bytes: 38512
using System;
using System.Linq;
using System.Collections.Generic;

namespace Competition
{
    class Program
    {
        static void Main(string[] args)
        {
            var nk = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var N = nk[0]; var K = nk[1];
            var h = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var res = 0;

            for(var i = 0; i < N; i++)
            {
                if (h[i] >= K) res++;
            }
            Console.WriteLine(res);

        }
    }
}


Measured memory_bytes: 17248
#define _CRT_SECURE_NO_WARNINGS
#define __STDC_FORMAT_MACROS
#include <algorithm>
#include <cinttypes>
#include <cstdio>
#include <vector>

using namespace std;

template<class T> void gc(T &x)
{
    char c;
    int s = 0;
    x = 0;

    c = getchar_unlocked();

    if (c == '-') s = 1;
    else if ('0' <= c && c <= '9')  x = c - '0';

    while (true)
    {
        c = getchar_unlocked();

        if (c < '0' || c > '9') break;
        x = x * 10 + (c - '0');
    }

    if (s) x = -x;
}

int main()
{
    int N;

    gc(N);

    vector<int> A(N);
    vector<int> B(N);
    vector<int> C(N);

    for (int i = 0; i < N; i++) gc(A[i]);
    for (int i = 0; i < N; i++) gc(B[i]);
    for (int i = 0; i < N; i++) gc(C[i]);

    sort(A.begin(), A.end());
    sort(C.begin(), C.end());

    int64_t ans = 0;

    for (int i = 0; i < N; i++)
    {
        // 以上
        vector<int>::iterator
            lba = lower_bound(A.begin(), A.end(), B[i]);

        int a = distance(A.begin(), lba);

        // より大きい
        vector<int>::iterator
            ubc = upper_bound(C.begin(), C.end(), B[i]);

        int c = distance(C.begin(), ubc);

        ans += (int64_t)a * (N - c);
    }

    printf("%" PRId64 "\n", ans);
    return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
 
#define int         long long
#define uint        unsigned int
#define ld          long double
#define showoff     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb          push_back
#define pii         pair<int,int>
#define FOR(i,a,b)  for(int i=a;i<b;++i)
#define RFOR(i,a,b) for(int i=a;i>b;--i)
#define f           first
#define se          second
#define maxn        200005
#define all(v)      v.begin(),v.end()
#define sz(x)       (int)x.size()
#define mod         1000000007
#define pqueue      priority_queue<int>
#define pdqueue     priority_queue< int,vector<int> ,greater< int >>
 
using namespace std;
 
 
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
 
int power(int a,int n)
{
    a %= mod;
    if(n == 1)return a;
    if(n == 0)return 1;
    if(n%2)return (a*(power((a*a)%mod,n/2)%mod))%mod;
    return power((a*a)%mod,n/2)%mod;
}
const int inf = (int) 1e18;
 
int inverse(int x){
    return power(x,mod-2)%mod;//little fermat....
}

signed main()
{
    showoff;
    string s,t;
    cin >> s >> t;
    vector<int>adj[30];
    FOR(i,0,sz(s)){
        adj[s[i]-'a'].pb(i);
    }
    int ans = 0,pi = -1;
    FOR(i,0,sz(t)){
        int j = upper_bound(adj[t[i]-'a'].begin(),adj[t[i]-'a'].end(),pi)-adj[t[i]-'a'].begin();
        if(j < sz(adj[t[i]-'a'])){
            ans += adj[t[i]-'a'][j]-pi;
            pi = adj[t[i]-'a'][j];
            continue;
        }
        ans += sz(s)-1-pi;
        pi = -1;
        j = upper_bound(adj[t[i]-'a'].begin(),adj[t[i]-'a'].end(),pi)-adj[t[i]-'a'].begin();
        if(j < sz(adj[t[i]-'a'])){
            ans += adj[t[i]-'a'][j]-pi;
            pi = adj[t[i]-'a'][j];
            continue;
        }
        cout << -1;
        return 0;
    }
    cout << ans;
    return 0;
}
//*->for large size of matrix take int not long long if possible......
//*->always take maximum as inf for safer side ...   

Measured memory_bytes: 1736
(let* ((n (read))
       (a (make-array `(,n) :initial-element 0))
       (ans 0))
  (loop :for i :from 1 :to n
        :do (setf (aref a (1- i)) (read)))
  ;;
  (setf a (sort a #'>))
  ;;
  (incf ans (aref a 0))
  ;;
  (loop :for i :from 1 :to (floor (/ (- n 2) 2))
        :do (incf ans (* 2 (aref a i))))
  (when (oddp (- n 2))
    (incf ans (aref a (ceiling (/ (- n 2) 2)))))
  (format t "~A~%" ans))


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

typedef long long ll;

int main() {
	ll L, R, mod = 2019;
	cin >> L >> R;
	if (L / 2019 != R / 2019) { cout << 0 << endl; return 0; }
	L %= 2019; R %= 2019;

	ll mini = 2019;

	for (int i = L; i < R; i++) {
		for (int j = i + 1; j <= R; j++) {
			mini = min(mini, (ll)i * j % 2019);
		}
	}
	cout << mini << endl;

	return 0;
}

Measured memory_bytes: 256
program lru_puzzle
  implicit none
  integer :: n, m, q, a(100000) = 0, i, k
  integer :: x = 0, p(100000) = 0, r(100000) = 0, c(0:100000) = 0
  logical :: u(100000) = .false.
  read(*,*) n, m
  read(*,*) q
  read(*,*) a(1:q)
  do i = q, 1, -1
    if (u(a(i))) cycle
    x = x+1
    p(x) = a(i)
    u(a(i)) = .true.
  end do
  do i = 1, m
    if (u(i)) cycle
    x = x+1
    p(x) = i
  end do
  do i = 1, m
    r(p(i)) = i
  end do
  c(0) = n
  do i = q, 1, -1
    k = r(a(i))
    if (c(k-1) > 0) then
      c(k-1) = c(k-1)-1
      c(k) = c(k)+1
    end if
  end do
  k = 0
  do while (c(k) == 0)
    k = k+1
  end do
  do i = k+1, m-1
    if (p(i) > p(i+1)) then
      write(*,'(a)') "No"
      stop
    end if
  end do
  write(*,'(a)') "Yes"
end program lru_puzzle

Measured memory_bytes: 2688
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int a = scanner.nextInt();
			int b = scanner.nextInt();
			int c = scanner.nextInt();
			if (a == b && b == c) {
				System.out.println("0");
				return;
			}

			List<Integer> list = Arrays.asList(a, b, c);
			Collections.sort(list);

			int result = 0;
			int max = list.get(2);
			int min = list.get(0);
			if (list.get(1) != max) {
				result += max - list.get(1);
				min += result;
			}

			result += (max - min) / 2;
			if ((max - min) % 2 == 1) {
				result += 2;
			}

			System.out.println(result);
		}
	}
}


Measured memory_bytes: 21844
#include <iostream>
using namespace std;
int main(void){
    int n;
    long long a[100000], x, sum = 0;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> a[i];
        if(i%2 == 0){
            sum += a[i];
        }else{
            sum -= a[i];
        }
    }
    x = sum / 2;
    cout << x*2;
    for(int i=1;i<n;i++){
        x = a[i-1] - x;
        cout << " " << x*2;
    }
    cout << endl;
}


Measured memory_bytes: 2048
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <iostream>
#include <queue>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <string>
#include <random>
#include <stack>
#include <set>
#include <unordered_set>

#define bug(x) cout<<"zdongdebug1: "<<x<<endl;
#define bug2(x, y) cout<<"zdongdebug2: "<<x<<" "<<y<<endl;
#define bug3(x, y, z) cout<<"zdongdebug3: "<<x<<" "<<y<<" "<<z<<endl;
using namespace std;
typedef long long ll;
const int maxn = 200005;
const int mod = 1000000007;

int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif
  ll n;
  cin>>n;
  if(n&1L){
    cout<<0<<endl;
    return 0;
  }
  if(n==0){
    cout<<0<<endl;
    return 0;
  }
  ll x = 0, tn = n;
  while(tn){
    x += (tn>>1L);
    tn>>=1L;
  }
  tn = n/2;
  ll y = 0;
  while(tn){
    y+=tn/5;
    tn/=5;
  }
  cout<<min(x, y)<<endl;
  return 0;
}

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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;

int main()
{
    int a, b, c, x;
    cin >> a >> b >> c >> x;
    int ans = 0;

    rep(i, a + 1)
    {
        rep(j, b + 1)
        {
            int num = x / 50 - 10 * i - 2 * j;
            if (0 <= num && num <= c)
            {
                ans++;
            }
        }
    }

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


Measured memory_bytes: 3608
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		long s = sc.nextLong();

		System.out.println(ans(n,s));
	}

	static long ans(long n, long s) {
		if(n<s) {
			return -1;
		} else if (n==s) {
			return n+1;
		} else {
			List<Long> divisor = new ArrayList<Long>();

			for(long i=1;i<=Math.sqrt(n-s);i++) {
				if(digitSum(n,i+1)==s) {
					return i+1;
				}
				if((n-s)%i == 0) {
					divisor.add(i);
				}
			}
			Collections.reverse(divisor);
			for (Long l : divisor) {
				if(digitSum(n,(n-s)/l+1)==s) {
					return (n-s)/l+1;
				}
			}
			return -1;
		}
	}

	static long digitSum(long n, long b) {
		if(n < b) {
			return n;
		} else {
			return (n%b+digitSum(n/b, b));
		}
	}

}


Measured memory_bytes: 24916
import java.util.Scanner;

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

        if (a + b >= 10) {
            System.out.println("error");
        } else {
            System.out.println(a + b);
        }
    }
}

Measured memory_bytes: 22868
#include<bits/stdc++.h>
using namespace std;
#define PI 3.141592653589793238462
typedef long long ll;
typedef double db;
ll p1[200005],p0[200005];
ll cal(ll x){
    ll v=1;
    while(x){
        ll t=x,num=0;
        while(t){
            num+=t%2;t/=2;
        }
        x%=num;v++;
    }
    return v;
}
int main(){
    ll n,num=0;cin>>n;
    string s;cin>>s;
    for(int i=0;i<s.length();i++){
        if(s[i]=='1') num++;
    }
    ll sum1=0,sum0=0;
    if(num==0){
        for(int i=1;i<=n;i++){
            cout<<1<<endl;
        }
        return 0;
    }
    else if(num==1){
        if(s[n-1]=='1'){
            for(int i=1;i<n;i++){
                cout<<2<<endl;
            }
            cout<<0<<endl;
        }
        else{
            for(int i=1;i<n;i++){
                if(s[i-1]!='1') cout<<1<<endl;
                else cout<<0<<endl;
            }
            cout<<2<<endl;
        }
        return 0;
    }
    else{
        for(int i=0;i<n;i++){
            sum1=(sum1*2%(num-1)+(s[i]-'0'))%(num-1);
            sum0=(sum0*2%(num+1)+(s[i]-'0'))%(num+1);
        }p1[0]=1;p0[0]=1;
        for(int i=1;i<=n;i++){
            p1[i]=(p1[i-1]*2)%(num-1);
            p0[i]=(p0[i-1]*2)%(num+1);
        }
        for(int i=0;i<n;i++){
            if(s[i]=='0'){
                ll x=(sum0+p0[n-i-1])%(num+1);
                cout<<cal(x)<<endl;
            }
            else{
                ll x=((sum1-p1[n-i-1])%(num-1)+(num-1))%(num-1);
                cout<<cal(x)<<endl;
            }
        }
    }
}

Measured memory_bytes: 6832
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <functional>
#include <set>
#include <sstream>
#include <map>
#include <queue>

using namespace std;
 
const double eps=1e-10;

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

int main()
{

	int w,h;
	while(cin>>w>>h,w){
		vector<string> t(h);
		vector< vector<bool> > visited(h,vector<bool>(w,false));
		int x,y,res=0;
		for(int i=0;i<h;i++){
			cin>>t[i];
			if(t[i].find("@")!=string::npos){
				x=t[i].find("@"); y=i;
			}
		}

		queue< pair<int,int> > q;
		q.push(make_pair(y,x));

		while(!q.empty()){
			pair<int,int> p=q.front();
			q.pop();
			y=p.first; x=p.second;

			if(!visited[y][x]){
				res++;
				visited[y][x]=true;
				for(int i=0;i<4;i++){
					int nx=x+dx[i],ny=y+dy[i];
					if(0<=nx && nx<w && 0<=ny && ny<h && t[ny][nx]=='.') q.push(make_pair(ny,nx));
				}
			}
		}
		cout<<res<<endl;

	}


	return 0;
}

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

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

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

        a[i] += (n+1) * (i+1);
        b[i] += (n+1) * (n-i);
    }

    // output
    for(int i=0; i<n; i++){
        cout << a[i];
        if(i == n-1) break;
        cout << " ";
    }
    cout << endl;

    for(int i=0; i<n; i++){
        cout << b[i];
        if(i == n-1) break;
        cout << " ";
    }
    cout << endl;
    return 0;
}

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

using namespace std;

int main()
{
    int N;
    cin >> N;
    vector<long> A(N);
    for (int i = 0; i < N; i++)
    {
        cin >> A.at(i);
    }
    long answer = 0;
    sort(A.begin(),A.end(),greater<long>());
    for (int i = 0; i < N; i++)
    {
        if (i == 0)
        {
            answer += 0;
        }else if (i == 1)
        {
            answer += A.at(0);
        }else
        {
            answer += A.at((i)/2);
        }
    }
    cout << answer;
}

Measured memory_bytes: 4836
#include<bits/stdc++.h>
#define pb push_back
#define pp pop_back()
#define mp make_pair
#define fr first
#define sc second
#define sz size()
#define smin(x,y) ((x)=min((x),(y)))
#define smax(x,y) ((x)=max((x),(y)))
#define all(x) x.begin(),x.end()
#define CS ios_base::sync_with_stdio(false);
#define show(x) cerr << #x << " is " << x <<endl;
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi; 
int32_t main()
{
	CS; int n; cin>>n;
	int cnt=0;
	while(n--){
		int x; cin>>x;
		if(x&1) cnt++;
	}
	if(cnt&1) cout<<"NO"<<endl;
	else cout<<"YES"<<endl;
	return 0;
}


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

using namespace std;

int main()
{
    long long int a, b, c;
    
    cin >> a >> b >> c;
    
    if(a == b || b == c || c == a)
    {
        if(a == b)
        {
            if(a == c)
            {
                cout << "No";
            }
            else
            {
                cout << "Yes";
            }
        }
        else
        {
            if(b == c)
            {
                if(a == b)
                {
                    cout << "No";
                }
                else{
                    cout << "Yes";
                }
            }
            else
            {
                if(a == c)
                {
                    if(a == b)
                    {
                        cout << "No";
                    }
                    else{
                        cout << "Yes";
                    }
                }
            }
        }
    }
    else{
        cout << "No";
    }
}

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

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n , m;
    cin >> n >> m;
    int a[m];
    for(int i = 0; i < m; i++) cin >> a[i];
    int sum = 0;
    for(int i = 0; i < m; i++) sum += a[i];
    if(sum > n) cout << -1 << "\n";
    else cout << n-sum << "\n";

    return 0;
}


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

int main()
{
  string s;
  int K;

  cin >> s;
  cin >> K;

  set<string> substrs;
  for(string::size_type i = 0; i < s.size(); ++i) {
    for(string::size_type l = 1; l <= K; ++l) {
      substrs.emplace(s.substr(i, l));
    }
  }

  cout << *(next(begin(substrs), K-1)) << endl;
}


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

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

	vector<int> l(m), r(m); for (int i = 0; i < m; i++) { cin >> l[i] >> r[i]; }
	
	int L = 0;
	int R = 2147483647;
	
	for (int i = 0; i < m; i++) { L = max(L, l[i]);	}
	for (int i = 0; i < m; i++) { R = min(R, r[i]); }

	int ans = 0;

	for (int i = 1; i <= n; i++) { 
		
		if (L <= i && i <= R) ans++;
	
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int n, a[5000];
	for(;;){
		cin >> n;
		if(n == 0) break;
		for(int i = 0; i < n; i++) cin >> a[i];
		for(int i = 1; i < n; i++) a[i] += a[i - 1];
		int min_sum = 0, ans = a[0];
		for(int i = 1; i < n; i++){
			min_sum = min(min_sum, a[i - 1]);
			ans = max(ans, a[i] - min_sum);
		}
		cout << ans << endl;
	}
	return 0;
}


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

ll d[200001];
int main() {
	int n; scanf("%d", &n);
	map<ll, vector<int>>mp;
	mp[0].push_back(0);
	ll s = 0;
	rep(i, n) {
		ll a; scanf("%lld", &a);
		s += a;
		mp[s].push_back(i + 1);
	}
	int Max = 0;
	for (auto&p : mp) {
		Max = max(Max, p.second.back() - p.second.front());
	}
	printf("%d\n", Max);
}

Measured memory_bytes: 25072
import math
import itertools
from heapq import heapify, heappop, heappush
from sys import stdin, stdout, setrecursionlimit
from bisect import bisect, bisect_left, bisect_right
from collections import defaultdict, deque


# d = defaultdict(lambda: 0)
# setrecursionlimit(10**7)
# inf = float("inf")


##### stdin ####
def LM(t, r): return list(map(t, r))
def R(): return stdin.readline()
def RS(): return R().split()
def I(): return int(R())
def F(): return float(R())
def LI(): return LM(int,RS())
def LF(): return LM(float,RS())
def ONE_SL(): return list(input())
def ONE_IL(): return LM(int, ONE_SL())
def ALL_IL(): return LM(int,stdin)

##### tools #####
def ap(f): return f.append
def pll(li): print('\n'.join(LM(str,li)))
def pljoin(li, s): print(s.join(li))



##### main #####
def main():
	n = I()
	A = LI()
	A.append(0)

	prev = 0
	skip = []
	sum_all = 0

	for i in range(n):
		t1 = abs(prev - A[i])
		t2 = abs(A[i] - A[i+1])

		skipped = (t1+t2) - abs(prev - A[i+1])
		sum_all += t1

		skip.append(skipped)

		prev = A[i]
	sum_all += abs(A[n-1] - A[n])

	for s in skip:
		print(sum_all - s)

if __name__ == '__main__':
  main()

Measured memory_bytes: 14308
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <algorithm>
#include <vector>
#include <math.h>
#include <bitset>
#include <cmath>
#include <set>

#define rep(i,s,n)for(int i = s;i<n;i++)
#define repe(i,s,n)for(int i = s;i<=n;i++)
#define rep_r(i,s,n)for(int i = n-1;i>=0;i--)
using namespace std;
typedef long long ll;
static const ll MOD = 1e9 + 7;
static const ll INF = 1e25;
static const ll MAX_M = 100001;

int main() {
	string s; cin >> s;
	string t = s;
	ll ans = 0;

	for (int i = 0; i < s.size();)
	{
		if (t.size() == 1 && t[0] == s[i]) {
			if (i == s.size() - 1) {
				break;
			}

			ans++;
			t = s.substr(i, 2);
			i += 2;
		}
		else {
			t = s.substr(i, 1);
			ans++;
			i++;
		}
	}

	cout << ans << endl;

	return 0;
}


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

#define LL long long

#define FOR(INDEX, START, END) for (LL INDEX = (START); INDEX < (END); ++INDEX)
#define REP(INDEX, COUNT) for (LL INDEX = 0; INDEX < (COUNT); ++INDEX)

int main()
{
	set<int> value;
	REP(i, 4) {
		int v;
		cin >> v;
		value.insert(v);
	}

	if (value.find(1) != value.end() &&
		value.find(9) != value.end() &&
		value.find(7) != value.end() &&
		value.find(4) != value.end()) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <map>
#include <queue>
#include <unordered_map>
#include <bitset>
#include <unordered_set>
#include <stack>
#define speed ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define eps 1e-7
#define inf 0x3f3f3f3f
#define mod 1000000007
using namespace std;

int main() {
	speed;
	int n;
	cin >> n;
	cout << (n == 3 || n == 5 || n == 7 ? "YES" : "NO");
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
int32_t main(){
	int n,w;
	cin>>n>>w;
	vector<int>weights(n);
	vector<int>values(n);
	for(int i=0;i<n;i++){
		cin>>weights[i];
		cin>>values[i];
	}
	int dp[n+1][w+1];
	memset(dp,-1,sizeof(dp));
	for(int i=0;i<=w;i++)dp[0][i]=0;
	for(int i=0;i<=n;i++)dp[i][0]=0;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=w;j++){
			dp[i][j]=dp[i-1][j];
			if(j>=weights[i-1]){
				dp[i][j]=max(dp[i-1][j-weights[i-1]]+values[i-1],dp[i][j]);
			}
		}
	}
	// for(int i=0;i<=n;i++){
	// 	for(int j=0;j<=w;j++)cout<<dp[i][j]<<" ";
	// 	cout<<endl; 
	// }
	cout<<dp[n][w]<<endl;
}

Measured memory_bytes: 82480
N,M=map(int,input().split())
ab=[[int(x) for x in input().split()] for _ in range(N)]
cd=[[int(x) for x in input().split()] for _ in range(M)]

for a,b in ab:
  ans=list()
  for c,d in cd:
    ans.append(abs(a-c)+abs(b-d))
  print(ans.index(min(ans))+1)


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

int main() {
    int H, W;

    while(1) {
        cin >> H >> W;
        if(H==0) break;

        for(int i = 1; i <= H; i++) {
            for(int j = 1; j <= W; j++) {
                if(i%2 == 0){
                    if(j%2==0) cout << '#';
                    else cout << '.';

                    if(j==W) cout << endl;
                }

                else {
                    if(j%2==0) cout << '.';
                    else cout << '#';

                    if(j==W) cout << endl;
                }
            }
        }

        cout << endl;
    }

}


Measured memory_bytes: 3120
#include<stdio.h>
#include<stdlib.h>

#define MA 100
//static const int MA=100;
static const int I=(1<<21);
static const int W=0;
static const int G=1;
static const int B=2;

int n,M[MA][MA];

void dij(){
    int minv;
    int d[MA],color[MA];
    int i;
    
    for(i=0;i<n;i++){
        d[i]=I;
        color[i]=W;
    }
    
    d[0]=0;
    color[0]=G;
    
    while(1){
        minv=I;
        int u=-1;
        
        for(i=0;i<n;i++){
            if(minv>d[i]&&color[i]!=B){
                u=i;
                minv=d[i];
            }
        }
        if(u==-1)
            break;
        color[u]=B;
        int v;
        for(v=0;v<n;v++){
            if(color[v]!=B && M[u][v]!=I){
                if(d[v]>d[u]+M[u][v]){
                    d[v]=d[u]+M[u][v];
                    color[v]=G;
                }
            }
        }
    }
    
    for(i=0;i<n;i++){
        printf("%d %d\n",i,(d[i]==I?-1:d[i]));
    }
}

int main(){
    int i,v,j;
    
    scanf("%d",&n);
    
    for(i=0;i<n;i++){
        for(j=0;j<n;j++){
            M[i][j]=I;
        }
    }
    
    int k,c,u;
    
    for(i=0;i<n;i++){
        scanf("%d%d",&u,&k);
        for(j=0;j<k;j++){
            scanf("%d%d",&v,&c);
            M[u][v]=c;
        }
    }
    
    dij();
    
    return 0;
}



Measured memory_bytes: 2112
#include <stdio.h>

int main(void){
    char c[3][4];
    
    scanf("%s",c[0]);
    scanf("%s",c[1]);

    if(c[0][1]==c[1][1] && c[0][0]==c[1][2] && c[0][2]==c[1][0])
        printf("YES\n");
    else
        printf("NO\n");
}


Measured memory_bytes: 128
A,V=map(int,input().split())
B,W=map(int,input().split())
T=int(input())
if A<B:
    if B+W*T > A+V*T:
        print("NO")
    else:
        print("YES")
elif B<A:
    if B-W*T<A-V*T:
        print("NO")
    else:
        print("YES")
else:
    print("YES")

Measured memory_bytes: 61580
#include <bits/stdc++.h>
#define _CRT_SECURE_NO_WARNINGS
#define ll long long
#define BUF 1e5
#define INF 1<<30
using namespace std;
ll MOD = 1e9 + 7;
ll A, B, C, D, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;
int main() {
	cin >> N;
	int f = N / 100;
	int s = N - f * 100;
	if (f <= 12 && f > 0) {
		if (s <= 12 && s > 0) {
			cout << "AMBIGUOUS" << endl;
		}
		else{
			cout << "MMYY" << endl;
		}
	}
	else if(f>0){
		if (s <= 12 && s > 0) {
			cout << "YYMM" << endl;
		}
		else cout << "NA" << endl;
	}
	else {
		if (s <= 12 && s > 0) {
			cout << "YYMM" << endl;
		}
		else {
			cout << "NA" << endl;
		}
	}
}


Measured memory_bytes: 256
a, b = map(int, input().split())
e = 0
for i in range(1, a + 1):
    c = i
    d = 0.5
    if c >= b:
        e += 1 / a
    else:
        while True:
            c *= 2
            if c >= b:
                e += 1 / a * d
                break
            d = d * 1 / 2
print(e)


Measured memory_bytes: 2940
import sys
from collections import defaultdict, Counter, deque
from itertools import accumulate, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right, bisect
from heapq import heappop, heappush
from fractions import gcd
from math import ceil, floor, sqrt, cos, sin, pi
from copy import deepcopy

# If you use recursive call, uncomment this code
#sys.setrecursionlimit(10**6)

def main():
    N,K = map(int, input().split())
    A = list(map(int, input().split()))
    A = sorted(A)
    print(sum(A[:K]))

if __name__ == '__main__':
    main()


Measured memory_bytes: 10680
package main

import "fmt"

func main() {
    chr := [2]string{"#", "."}
    var h, w, idx_h, idx_w int

    for {
        fmt.Scanf("%d %d", &h, &w)
        if h == 0 && w == 0 {
            break
        }

        idx_h = 0
        for i:=0; i<h; i++ {
            idx_w = idx_h 
            for j:=0; j<w; j++ {
                fmt.Print(chr[idx_w])
                idx_w = (idx_w + 1) % 2
            }
            fmt.Println("")
            idx_h = (idx_h + 1) % 2
        }
        fmt.Println("")
    }
}


Measured memory_bytes: 1932
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define endl "\n"

int main()
{
  i64 H1, M1, H2, M2, K;
  cin >> H1 >> M1 >> H2 >> M2 >> K;
  cout << H2 * 60 + M2 - (H1 * 60 + M1) - K << endl;
  return 0;
}


Measured memory_bytes: 3628
h,w = gets.chomp.split(" ").map(&:to_i)
maze = ["#" * (w + 2)] + h.times.map{"#" + gets.chomp + "#"} + ["#" * (w + 2)]

dot_count = maze.map{|arr| arr.count(".")}.sum

sy, sx = 1, 1
gy, gx = h, w
# 座標, 回数
bfs = [[sy, sx, 0]]
maze[sy][sx] = "#"

# bfs
y, x, result = nil # 最短経路
while bfs.length > 0 do
  y, x, result = bfs.shift
  break if y == gy && x == gx
  [[-1, 0], [1, 0], [0, 1], [0, -1]].each do |(dy, dx)|
    tmp_y = y + dy
    tmp_x = x + dx
    next if maze[tmp_y][tmp_x] == "#"
    maze[tmp_y][tmp_x] = "#"
    bfs << [tmp_y, tmp_x, result + 1]
  end
end

if y == gy && x == gx
  # スタートのdotも対象から外すため
  puts (dot_count - 1) - result
else
  puts -1
end


Measured memory_bytes: 14408
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include <limits>
#include <iomanip>
#include <map>

using namespace std;

int main(){
	int a,b;
	
	cin >> a >> b;
	
	cout << (a+(b-1))/b << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
  char c;
  cin >> c;
  string ans = "consonant";
  if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u')
    ans = "vowel";
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[100001];
int f[100001];
int main()
{
	int n,k;
	scanf("%d %d",&n,&k);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	for(int i=2;i<=n;i++)
	{
		f[i]=INT_MAX;
		for(int j=1;j<=min(i-1,k);j++)
		{
			f[i]=min(f[i-j]+abs(a[i-j]-a[i]),f[i]);
		}
	}
	printf("%d",f[n]);
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <chrono>
#include <math.h>
using namespace std;

using lli = long long int;
using Vint = vector<int>;
using Vlli = vector<lli>;
using Wint = vector<Vint>;
using Wlli = vector<Vlli>;
using pii = pair<int, int>;
using pll = pair<lli, lli>;

constexpr int MOD = 1e9 + 7;
constexpr int INFi = 2e9 + 1;
constexpr lli INFl = (lli)(9e18) + 1;
const vector<pii> DXDY = {make_pair(1, 0), make_pair(-1, 0), make_pair(0, 1), make_pair(0, -1)};
constexpr char BR = '\n';

#define FOR(i, a, b) for(int (i) = (a); (i) < (b); (i)++)
#define FOReq(i, a, b) for(int (i) = (a); (i) <= (b); (i)++)
#define rFOR(i, a, b) for(int (i) = (b); (i) >= (a); i--)
#define FORstep(i, a, b, step) for(int (i) = (a); i < (b); i += (step))
#define REP(i, n) FOR(i, 0, n)
#define rREP(i, n) rFOR(i, 0, (n-1))
#define vREP(ele, vec) for(auto &(ele) : (vec))
#define vREPcopy(ele, vec) for(auto (ele) : (vec))
#define SORT(A) std::sort((A).begin(), (A).end())


template <class T> inline int argmin(vector<T> vec){return min_element(vec.begin(), vec.end()) - vec.begin();}
template <class T> inline int argmax(vector<T> vec){return max_element(vec.begin(), vec.end()) - vec.begin();}
template <class T> inline void chmax(T &a, T b){a = max(a, b);}
template <class T> inline void chmin(T &a, T b){a = min(a, b);}
inline int toInt(string &s){int res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;}
inline int toInt(const string s){int res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;}
inline long long int toLong(string &s){lli res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;}
inline long long int toLong(const string s){lli res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;}
template <class T> inline std::string toString(T n){
  if(n == 0) return "0";
  std::string res = "";
  if(n < 0){n = -n;while(n != 0){res += (char)(n % 10 + '0'); n /= 10;}
  std::reverse(res.begin(), res.end()); return '-' + res;}
  while(n != 0){res += (char)(n % 10 + '0'); n /= 10;} std::reverse(res.begin(), res.end()); return res;
}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



constexpr int MAX_SIZE = 201;
int L[MAX_SIZE], n, dn;

int main(void){
  scanf("%d\n", &n);
  dn = 2 * n;
  REP(i, dn) scanf("%d", L + i);
  sort(L, L + dn);
  int ans = 0;
  for(int i = 0; i < dn; i += 2) ans += i[L];
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 256
n,*a=map(int,open(0).read().split());_=10**9+7;x=m=1;z=0
for i in range(2,n):x=m=m*i%_
for i in range(n):z=z+x*(a[i]-a[i-1])%_;x=x+m*pow(i+1,_-2,_)%_
print(z%_)

Measured memory_bytes: 14052
#include<stdio.h>

int main(void)
{
	int car[4][13], i, num = 0, n, a = 0, b;
	char card[4][13], in;
	
	scanf("%d", &a);
	for (i = 0; i < 4; i++)
	{
		for (n = 0; n < 13; n++)
		{
			car[i][n] = 0;
			switch (i)
			{
			case 0:
				card[i][n] = 'S';
				break;
			case 1:
				card[i][n] = 'H';
				break;
			case 2:
				card[i][n] = 'C';
				break;
			case 3:
				card[i][n] = 'D';
			}
		}
	}
	i = 0;
	for (b = 0; b < a * 2; b++)
	{
		scanf("%c %d", &in,&num);
		switch (in)
		{
		case 'S':
			car[0][num - 1] = 1;
			break;
		case 'H':
			car[1][num - 1] = 1;
			break;
		case 'C':
			car[2][num - 1] = 1;
			break;
		case 'D':
			car[3][num - 1] = 1;
			break;
		default:;
			break;
		}
		i++;
	}
	
	for (i = 0; i < 4; i++)
	{
		for (n = 0; n < 13; n++)
		{
			if (car[i][n] == 0)
			{
				printf("%c %d\n", card[i][n], n + 1);
			}
		}
	}
	
	return 0;
}

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

constexpr int D = 365;
constexpr int T = 26;
int c[D];
int s[D][T];
vector<int> ans;

void Input() {
    int tmp; cin >> tmp;
    REP(i, T) cin >> c[i];
    REP(i, D) REP(j, T) cin >> s[i][j];
    return;
}

void Commit(int day, int contest, int& score, vector<int>& last) {
    last[contest] = day;
    score += s[day - 1][contest];
    REP(type, T) score -= c[type] * (day - last[type]);
    return;
}

void Output() {
    for(auto contest: ans) cout << contest + 1 << endl;
    return;
}

double lambda = 5.0; // 6.1 is better
int FindMaxProfitContest(int day, vector<int>& last) {
    double max_profit = -1e9;
    int argmax = -1;
    REP(type, T) {
        double profit = 0;
        profit += s[day - 1][type];
        profit += lambda * c[type] * (day - last[type]);
        if(profit > max_profit) {
            max_profit = profit;
            argmax = type;
        }
    }
    return argmax;
}

int Greedy(int start_day, vector<int>& last) {
    int score = 0;
    vector<int> last_copy = last;
    for(int day = start_day; day <= D; day++) {
        int contest = FindMaxProfitContest(day, last_copy);
        Commit(day, contest, score, last_copy);
    }
    return score;
}

int FindMaxProfitContestWithPredict(int day, vector<int>& last) {
    double max_profit = -1e9;
    int argmax = -1;
    REP(type, T) {
        double profit = 0;

        profit += s[day - 1][type];
        profit += lambda * c[type] * (day - last[type]);

        int tmp = last[type];
        last[type] = day;
        profit += Greedy(day + 1, last);
        last[type] = tmp;

        if(profit > max_profit) {
            max_profit = profit;
            argmax = type;
        }
    }
    return argmax;
}

int main() {
    Input();
    int score = 0;
    vector<int> last(T, 0);
    for(int day = 1; day <= D; day++) {
        int contest = FindMaxProfitContestWithPredict(day, last);
        ans.push_back(contest);
        Commit(day, contest, score, last);
    }
    Output();
    // cerr << score << endl;
    return 0;
}


Measured memory_bytes: 3668
from collections import deque
def main():
    H,W = map(int, input().split())
    start = list(map(int, input().split()))
    goal = list(map(int, input().split()))
    field = [input() for _ in range(H)]

    wmap = [[-1] * W for _ in range(H)]
    wmap[start[0]-1][start[1]-1] = 0

    d = deque()
    d.appendleft((start[1]-1,start[0]-1))

    warpd = d.copy()

    def flood():
        while len(d) > 0:
            pos = d.pop()
            warpd.append(pos)
            posx, posy = pos
            w = wmap[posy][posx]
            for x,y in [(posx-1, posy), (posx+1, posy), (posx, posy-1), (posx, posy+1)]:
                if 0 <= x < W and 0 <= y < H and field[y][x] == "." and wmap[y][x] == -1:
                    wmap[y][x] = w
                    d.appendleft((x,y))
                    warpd.append((x,y))

    # くばる
    def warp():
        movable = set()
        while len(warpd) > 0:
            x,y = warpd.pop()
            w = wmap[y][x]
            
            for my in range(-2, 3):
                for mx in range(-2, 3):
                    px = x + mx
                    py = y + my
                    if 0 <= px < W and 0 <= py < H and field[py][px] == "." and wmap[py][px] == -1:
                        wmap[py][px] = w+1
                        movable.add((px,py))

        for item in movable:
            d.append(item)

    while len(d) != 0 and wmap[goal[0]-1][goal[1]-1] == -1:
        flood()
        warp()

    print(wmap[goal[0]-1][goal[1]-1])

if __name__ == "__main__":
    main()


Measured memory_bytes: 100672
#include<iostream>
#include<string>
#include<cmath>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int h[n];
    for(int i=0;i<n;i++)
    {
        cin>>h[i];
    }
    int dp[n];
    dp[0]=0;
    dp[1]=abs(h[1]-h[0]);
    for(int i=2;i<n;i++)
    {
        dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
    }
    cout<<dp[n-1]<<"\n";
}

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

int main(void)
{
	int n, sc1=0,sc2=0;
	string card1,card2;
	cin>>n;
	for (;n--;){
		cin>>card1>>card2;
		if (card1>card2){
			sc1+=3;
		}else if (card2>card1){
			sc2+=3;
		}else if (card1==card2){
			sc1++;
			sc2++;
		}
	}
	cout<<sc1<<" "<<sc2<<endl;
	return 0;
}

Measured memory_bytes: 1208
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long p = 1;
		for(int i = 1; i <= n; i++) {
			p = (p * i)%1000000007;
		}
		System.out.println(p);
	}
}

Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;cin>>n;
	int a[n+1];
	int d[n+1];
	for(int i=1;i<=n;i++)cin>>a[i];
	d[1]=0,d[2]=abs(a[1]-a[2]);
	for(int i=3;i<=n;i++){
		d[i]=min(d[i-1]+abs(a[i]-a[i-1]),d[i-2]+abs(a[i]-a[i-2]));
	}
	//for(int i=1;i<=n;i++)cout<<d[i]<<' ';
	cout<<d[n];
}

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

#define debug(x) cerr << #x << ": " << x << endl
#define debugArray(x,n) for(long long hoge = 0; (hoge) < (n); ++ (hoge)) cerr << #x << "[" << hoge << "]: " << x[hoge] << endl
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
const ll INF = LLONG_MAX/2;
const ll MOD = 1e9+7;
const double EPS=1e-12;

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll N,L;cin>>N>>L;
  ll ans = L*N+N*(N-1)/2;
  if(L>0)ans-=L;
  if(L<-N+1)ans-=L+N-1;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256