akhauriyash/Code-Regression huggingface dataset:
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

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

	int N, K;
	cin >> N >> K;
	vector<int> a(N);
	for (int i = 0; i < N; i++) cin >> a[i];
	vector<int> dp(K + 1, -1);
	dp[0] = 0;

	auto dfs = [&](auto &&f, int now) -> bool {
		
		if (now < 0) return true;
		if (dp[now] != -1) return dp[now];

		bool res = false;
		for (int i = 0; i < N; i++) {
			res |= (f(f, now - a[i]) ^ 1);
		}

		return dp[now] = res;
	};

	if (dfs(dfs, K)) cout << "First" << "\n";
	else cout << "Second" << "\n";

	return 0;
}

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


double dp[303][303];
int n,h;

int main(){
  r(i,303)r(j,303)dp[i][j]=1e15;
  cin>>n;
  dp[0][1]=0;
  for(int i=0;i<n;i++){
    cin>>h;
    for(int j=1;j<303;j++){
      if(dp[i][j]==1e15)continue;
      for(int k=0;k<303;k++){

        if(j==k){
          if(j!=h)dp[i+1][k] = min( dp[i+1][k] , dp[i][j]+abs(h-j) );
          else dp[i+1][k] = min( dp[i+1][k] , dp[i][j] );
        }

        if(j<k){
          if(k<=h) dp[i+1][k] = min( dp[i+1][k] , dp[i][j]+(double)abs(k-j)/2+h-k );
          else if(h<=j) dp[i+1][k] = min( dp[i+1][k] , dp[i][j]+(double)abs(k-j)/2+j-h );
          else{
            double x=(double)(h-j)/(k-j);
            dp[i+1][k] = min( dp[i+1][k] , dp[i][j]+(x*(h-j))/2+(1.0-x)*(k-h)/2 );
          }
        }

        if(j>k){
          if(j<=h) dp[i+1][k] = min( dp[i+1][k] , dp[i][j]+(double)abs(k-j)/2+h-j );
          else if(h<=k) dp[i+1][k] = min( dp[i+1][k] , dp[i][j]+(double)abs(k-j)/2+k-h );
          else{
            double x=-(double)(h-j)/(j-k);
            dp[i+1][k] = min( dp[i+1][k] , dp[i][j]+(x*(j-h))/2+(1.0-x)*(h-k)/2 );
          }
        }

      }
    }
  }

  double ans = 1e15;
  r(i,302) ans=min(ans,dp[n][i+1]);
  printf("%.9f\n",ans);
}


Measured memory_bytes: 3948
#include<stdio.h>

int main(void)
{
  int n, k, ans=0;
  int i, j, tmp;
  scanf("%d%d", &n, &k);
  int a[n];
  for(i=0;i<n;i++)
  {
    scanf("%d", &a[i]);
  }

  for(i=0;i<n-1;i++)
  {
    for(j=0;j<n-1;j++){
      if(a[j+1] < a[j]){
        tmp = a[j];
        a[j] = a[j+1];
        a[j+1] = tmp;
      }
    }
  }

  for(i=0;i<k;i++)
  {
    ans = ans + a[n-1];
    n--; 
  }
  printf("%d", ans);

  return 0;
}

Measured memory_bytes: 128
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using P = pair<ll, ll>;

constexpr long double PI = 3.14159265358979323846264338327950288L;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

class BBattle {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;
      int a, b, c, d; cin >> a >> b >> c >> d;
      while(true) {
        c -= b;
        if (c <= 0) {
          cout << "Yes" << endl;
          return;
        }
        a -= d;
        if (a <= 0) {
          cout << "No" << endl;
          return;
        }



      }
    }
};

signed main() {
  BBattle solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

Measured memory_bytes: 3656
#125

import math
import fractions

N = int(input())
A =list(map(int, input().split()))

L = [0] *(N+2)
R = [0] *(N+2)
ans = 0

#漸化式的に最大公約数算出(前から順に算出)
for j in range(0,N-1):
    L[j + 1] = fractions.gcd(L[j], A[j])
#漸化式的に最大公約数算出(後ろから順に算出)
for j in range(N -1,0,-1):
    R[j - 1] = fractions.gcd(R[j], A[j])
for j in range(0,N):
    if ans < fractions.gcd(L[j],R[j]):
        ans = fractions.gcd(L[j],R[j])

print(ans)

Measured memory_bytes: 16144
import java.util.*;
class Main
{
        public static void main(String[] args)
        {
            Scanner sc = new Scanner(System.in);
            
            int n = sc.nextInt();
            int k = sc.nextInt();
            
            int total = n;
            int count = 0;
            
            while(total!=0){
                total/=k;
                count++;
            }
            
            System.out.println(count);
        }
        
}  

Measured memory_bytes: 25044
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const long long INF = 1LL << 60;

int main(){
    ll A;
    string B;
    cin >> A >> B;
    ll B100 = (B[0] - '0') * 100 + (B[2] - '0') * 10 + (B[3] - '0');
    cout << A * B100 / 100 << endl;
    return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
#define fr first
#define se second
#define r_0 return 0
#define ll long long
#define pb push_back
#define TIME ios_base::sync_with_stdio(0);
using namespace std;

const long long INF = 1e7;
const long long N = 5e5 + 7;
const long long mod = 1e9 + 7;
const long double eps = 1E-7;

long long cnt, n, m , x , y , z;
long double a , b , c;
string s;
char ch;
ll arr[33] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int main(){
    TIME
    cin >> n;
   -- n;
    cout << arr[n];
}


Measured memory_bytes: 256
#if 0
date +%Y.%m.%d

每个叶子 u 可以视为初始有 a[u] 个单元在上面，
单元不断向上移动，来源不同的两个单元到同一个点可以选择一起消失，
需要保证每个点 u 有恰好 a[u] + k 个单元到达过，其中 k 是在 u 点消失的对数。

从下向上考虑，对于每个点 u ，每个儿子都有若干单元到 u 点，
设此时一共有 tot 个单元，最多有 max 个来自同一个儿子。
那么需要消失的单元对数就是 k = tot - a[u] 。
设可以配对的数量为 K ，分两种情况：
1) max > tot - max: K = tot - max （配对的瓶颈在于 max 太大）
2) max <= tot - max: K = tot / 2 （配对的瓶颈在于总数的奇偶性）
配对后剩下的单元数为 tot - 2k ，向上递归即可。
#endif
#include <cstdio>
#include <algorithm>
#define debug(...) fprintf(stderr, __VA_ARGS__)

typedef long long ll;

struct {
	inline operator int () { int x; return scanf("%d", &x), x; }
	inline operator ll () { ll x; return scanf("%lld", &x), x; }
	template<class T> inline void operator () (T &x) { x = *this; }
	template<class T, class ...A> inline void operator () (T &x, A &...a)
	{ x = *this; this -> operator ()(a...); }
} read;

const int maxn = 100005;
int head[maxn], nxt[maxn << 1], to[maxn << 1], hp = 1;
ll a[maxn];

inline void add(int u, int v) {
	nxt[++ hp] = head[u];
	head[u] = hp;
	to[hp] = v;
}

inline __attribute__((noreturn)) void shit() { puts("NO"); exit(0); }

ll dfs(int u, int fa) {
	if(!nxt[head[u]]) return a[u];

	ll tot = 0, max = 0;

	for(int i = head[u]; i; i = nxt[i])
		if(to[i] != fa) {
			ll x = dfs(to[i], u);
			tot += x;
			max = std::max(max, x);
		}

	ll k = tot - a[u];
	ll K = max >= tot - max ? tot - max : tot >> 1;
	/* debug("%d : %d %d\n", u, tot, k); */
	if(k < 0 or k > K) shit();

	return tot - (k << 1);
}

int main() {
	int n = read;

	for(int i = 1; i <= n; i ++)
		read(a[i]);

	if(n == 2) return puts(a[1] == a[2] ? "YES" : "NO"), 0;

	for(int i = 1; i < n; i ++) {
		int u = read, v = read;
		add(u, v);
		add(v, u);
	}

	int root = 1;
	while(!nxt[head[root]])
		++ root;

	if(!dfs(root, 0)) puts("YES");
	else puts("NO");
}


Measured memory_bytes: 8192
input_string = raw_input()

s_num = 0
str_len = len(input_string)

for c in input_string:
    if c == 'S':
        s_num += 1

    elif c == 'T':
        if s_num > 0:
            s_num -= 1
            str_len -= 2

print str_len

Measured memory_bytes: 2948
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 5e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//
ll A[20];
ld P[20];
ll mob[1 << 20];

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

int main() {
    init();
    ld ans = 0;
    ll N, M;
    cin >> N >> M;
    rep(i, N) cin >> A[i];
    rep(i, N) cin >> P[i], P[i] /= 100.0L;

    rep(bit, 1<<N){
        ll lc = 1;
        rep(i,N){
            if (!(bit >> i & 1)) continue;
            lc = (ll)min<ld>(M + 1, 1.0L * lc / gcd(lc, A[i]) * A[i]);
            if (lc == M + 1) break;
        }
        // err(bit, lc, M / lc);
        mob[bit] = M / lc;
    }
    
    rep(i,N)rep(bit,1<<N){
        if (bit >> i & 1) mob[bit] -= mob[bit ^ 1 << i];
    }

    rep(bit, 1<<N){
        ld p = 1;
        rep(i, N) p *= (bit >> i & 1 ? P[i] : 1.0L - P[i]);
        // err(p, mob[bit]);
        ans += p * (M - abs(mob[bit]));
    }

    cout << ans << endl;
}


Measured memory_bytes: 11492
n,m = gets.strip.split.map(&:to_i)
penalty = Array.new(n,0)
clear = Array.new(n,0)
m.times do
  a,b = gets.strip.split
  if b == "WA"
    if clear[a.to_i-1] == 0
      penalty[a.to_i-1] += 1
    end
  else
    clear[a.to_i-1] += 1
  end
end
seitou = 0
machigai = 0
for i in 1..n
  if clear[i-1] != 0
    seitou += 1
    machigai += penalty[i-1]
  end
end
puts [seitou,machigai].join(" ")

Measured memory_bytes: 15884
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

ll n, p;
string s;

int main(){
	cin >> n >> p;
	cin >> s;
	int len = s.length();
	
	ll result = 0;
	if ( p == 2 || p == 5 ){
		for ( int i = len-1; i >= 0; i-- ){
			if ( (s[i]-'0') % p == 0 )
				result += i+1;
		}
	}
	else {
		ll x = 0;
		ll mul = 1;
		map<int,ll> m;
		m[0] = 1;
		
		for ( int i = len-1; i >= 0; i-- ){
			x = (x + (s[i]-'0')*mul) % p;
			m[x]++;
			mul = mul * 10 % p;
		}
		
		for ( auto it : m ){
			//cout << it.first << " " << it.second << endl;
			result += it.second * (it.second-1) / 2;
		}
	}
	
	cout << result << endl;
	
	return 0;
}



Measured memory_bytes: 4136
O=input()
E=input()
a=[b for b in O]
c=[d for d in E]
answer=[]
count=0
while not count==len(c):
    answer.append(O[count])
    answer.append(E[count])
    count+=1
if len(a)-len(c)==1:
    answer.append(O[len(a)-1])
moji=''
for z in answer:
    moji+=z
print(moji)


Measured memory_bytes: 3064
S = input()
n = len(S)
N = []
M = []
for i in range(n):
    N.append(S[i])
Nsum = 0
a = 0
for Ni in N:
    n = len(S) - a
    m = 2 ** a
    Nsum += m * int(Ni) * 10 ** (n - 1)
    n -= 1
    while n > 0:
        Nsum += m * int(Ni) * 10 ** (n - 1)
        m *= 2
        n -= 1
    a += 1
print(Nsum)

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

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n; cin >> n;
  V<> h(n); for (auto&& e : h) cin >> e;
  int res = 0;
  for (int i = 0; i < n; ++i) {
    bool f = true;
    for (int j = 0; j < i; ++j) if (h[j] > h[i]) {
      f = false;
      break;
    }
    res += f;
  }
  cout << res << '\n';
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <tuple>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const ll mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int n, k;
int a[100100];

int gcd(int p, int q) {
    if (q == 0) return p;
    return gcd(q, p%q);
}

bool solve() {
    sort(a, a+n);
    if (n == 1) return a[0] == k;
    if (a[n-1] < k) return false;
    int g = a[0];
    for (int i = 1; i < n; i++) g = gcd(g, a[i]);
    return k % g == 0;
}

void input() {
    cin >> n >> k;
    for (int i = 0; i < n; i++) cin >> a[i];
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);

    input();
    cout << (solve()?"POSSIBLE":"IMPOSSIBLE") << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート

int main(){
    int N,M;
    cin >> N >> M;
    vector<int> X(M);

    if(N >= M){
        cout << 0 << endl;
    }
    else {
    rep(i,M){
        cin >> X[i];
    }

    sort(all(X));


    vector<int> L(M);

    rep(j,M-1){
        L[j] = abs(X[j+1] - X[j]);
    }

    sort(rall(L));

    int sum = 0;
    rep(k,N-1){
        sum += L[k];
    }
    int temp = X[M-1] - X[0];
    cout << temp - sum << endl;
    }
    
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define f(i,a,b) for(int(i)=int (a);i<=int (b);i++)
#define ff(i,a,b) for(int(i)=int (a);i<int (b);i++)
#define F(i,a,b) for(int(i)=int (a);i>=int (b);i--)
#define foreach(i,x) for(typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define vt vector
#define ll long long
#define lower(p,x) lower_bound(all(p),x)
#define upper(p,x) upper_bound(all(p),x)
#define ms(a,x) memset(a,x,sizeof a)
#define minn(a,b,c,d) min(a,min(b,min(c,d))) 
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
const double pi=acos(-1.0);//NOTE:PI
const double eps=1e-5;
const int INF=1e9,mod=1e9+7,N=1e6+6;
int a[N];
ll dp[55][3000];
int n,k;
int main(){
	cin>>n>>k;
	dp[0][0]=1;
	f(i,1,n){
		int x;cin>>x;
		F(j,i,1){
			f(l,x,k*n){
				dp[j][l]+=dp[j-1][l-x];	
			}
		}
	}
	ll ans=0;
	f(i,1,n) ans+=dp[i][i*k];
	cout<<ans;
}

Measured memory_bytes: 1408
N = int(input())
X = list(map(int, input().split()))

Y = sorted(X)

for i in range(N):
    if Y[N // 2 - 1] == Y[N // 2]:
        print(Y[N // 2])
    else:
        if X[i] < Y[N // 2]:
            print(Y[N // 2])
        else:
            print(Y[N // 2 - 1])


Measured memory_bytes: 25620
while True:
    n,x= map(int,input().split())
    
    if n == 0 and x == 0:
        break
    
    
    cnt = 0
    
    for i in range(1,n+1):
        for j in range(1,i):
            for k in range(1,j):
                if x == i + j + k:
                    cnt += 1
                    
    
    print(cnt)



Measured memory_bytes: 5596
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream> 
#include<map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
using namespace std;
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)
int main() {
	long long n, m;
	cin >> n >> m;
	long long ans = min(n, m/2);
	m -= ans * 2;
	ans += m / 4;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
    int n;
    int h[20];
    int i;
    int x=0;
    int max=0;
  
    scanf("%d\n", &n);
    for(i=0;i<n;i++){
      scanf("%d ",&h[i]);
    }
    
    for(i=0;i<=n;i++){
      if(h[max]<=h[i+1]){
        x++;
        max=i+1;
      }
    }
   
 
    printf("%d\n",x);
 
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cmath>
#include <string>

typedef long long lint;

using namespace std;

// dpテンプレ
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;
}

const lint INF = 1e9;

//入力
int n;
lint h[100000];
//dpテーブル
lint dp[100000];

int main(){
  lint n,i,k,j,ans;
  cin >> n >> k;
  for(i = 0; i < n; i++){
    cin >> h[i];
  }

  for(i = 0; i < n; i++){
    dp[i] = INF;
  }
  //初期条件
  dp[0] = 0;

  for(i = 1; i < n; i++){
    for(j = 1; j <= k && j <= i; j++){
      chmin(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
    }
  }
  ans = dp[n - 1];
  cout << ans;
}


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

using namespace std;

#ifdef LOCAL
#define err cerr
#else
#define err if (false) cerr
#endif

typedef long long ll;

const int MAXN = 100000;

vector<int> e[MAXN];
vector<int> mx(MAXN, -1);
vector<int> par(MAXN, -1);
vector<int> deep(MAXN, -1);

void dfs(int u, int p, int d)
{
    deep[u] = d;
    par[u] = p;
    mx[u] = 0;
    for (int v : e[u])
    {
        if (v == p) continue;
        dfs(v, u, d + 1);
        mx[u] = max(mx[u], mx[v] + 1);
    }
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n; cin >> n;
    int u, v; cin >> u >> v; u--, v--;
    for (int i = 0; i < n - 1; i++)
    {
        int x, y; cin >> x >> y; x--, y--;
        e[x].emplace_back(y);
        e[y].emplace_back(x);
    }
    dfs(v, -1, 0);
    for (int i = 0; i < n; i++)
    {
        err << mx[i] << " ";
    }
    err << endl;
    int dist = deep[u];
    int ans = dist / 2;
    for (int q = 0; q <= (dist - 1) / 2; q++)
    {
        int val = q + mx[u] + ((dist % 2 == 0) ? 1 : 0);
        err << q << " " << u << " " << mx[u] << " " << val << endl;
        ans = max(ans, val);
        u = par[u];
    }
    cout << ans;
}


Measured memory_bytes: 13312
#include<iostream>
#include <cstring>
#include<vector>
#include <queue>
#include<algorithm>
using namespace std;

vector<int> t;
int dp[2][2][1024][2];
int n;
struct NODE{
	int a,b,x,me;
	int cost;
	NODE(int a,int b,int x,int me,int cost) : a(a) , b(b) , x(x) , me(me) , cost(cost) {}
};
bool operator <(const NODE &a,const NODE &b){
	return a.cost > b.cost;
}
int main(){
	cin >> n;
	for(int i=0;i<n;i++){
		int c;cin>>c;
		t.push_back(c);
	}
	sort(t.begin(), t.end());
	int ans=0;
	if(n<2){
		cout << t[t.size()-1] << endl;
		return 0;
	}
	priority_queue<NODE> Q;
	Q.push(NODE(0,0,2,0,0));
	while(Q.size()){
		NODE q = Q.top(); Q.pop();
		int a = q.a;
		int b = q.b;
		int x = q.x;
		int me = q.me;
		if( dp[q.a][q.b][q.x][q.me]++ ) continue;
		if( q.a == 1 && q.b == 1 && q.x >= n && q.me == 1 ){
			cout << q.cost << endl;
			return 0;
		}
		//cout << a << " " << b << " " << x << " " << me << " " << q.cost << endl;
		
		
		if( me == 0 ){
			if( x + 1 < n ) Q.push(NODE(a,b,x+2,me^1,q.cost+t[x+1]));
			if( x < n ){
				if(a == me) Q.push(NODE(a^1,b,x+1,me^1,q.cost+t[x]));
				if(b == me) Q.push(NODE(a,b^1,x+1,me^1,q.cost+t[x]));
			}
			if( a == 0 && b == 0 ){
				Q.push(NODE(a^1,b^1,x,me^1,q.cost+t[1]));
			}
		}
		
		if(a == me) Q.push(NODE(a^1,b,x,me^1,q.cost+t[0]));
		if(b == me) Q.push(NODE(a,b^1,x,me^1,q.cost+t[1]));
	}
}

/*
int main(){
	int n;
	cin>>n;
	
	vector<int> t;
	for(int i=0;i<n;i++){
		int c;cin>>c;
		t.push_back(c);
	}
	sort(t.begin(), t.end());
	int ans=0;
	if(n<3){
		ans = t[t.size()-1];
	}else{
		int a=t[0],b=t[1];
		for(int i=3;i<t.size();i+=2){
			int c=t[i-1],d=t[i];
			if(2*b<a+c){
				ans += b+a+d+b;
			}else{
				ans += d+a+c+a;
			}
		}
		if(t.size()%2){
			ans+=b+a+t[t.size()-1];
		}else{
			ans += b;
		}
	}
	cout<<ans<<endl;
}
*/


Measured memory_bytes: 1264
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

typedef long double ld;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const long long infll = (long long) 1.01e18;
const ld eps = 1e-9;
const ld pi = acos((ld) -1);

mt19937 mrand(random_device{} ()); 

int rnd(int x) {
  return mrand() % x;
}

void precalc() {
}

int n;

int read() {
  if (scanf("%d", &n) < 1) {
    return false;
  }
  return true;
}

int get(int x) {
  int res = 0;
  while (x) {
    res += x % 10;
    x /= 10;
  }
  return res;
}

void solve() {
  int res = inf;
  for (int a = 1; a < n; a++) {
    int b = n - a;
    res = min(res, get(a) + get(b));
  }
  printf("%d\n", res);
}

int main() {
  precalc();
#ifdef DEBUG
  assert(freopen(TASK ".in", "r", stdin));
  assert(freopen(TASK ".out", "w", stdout));
#endif
  while (read()) {
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


Measured memory_bytes: 256
def getMaxValue(s)
  v = s.split(/[a-z]?/).sort.reverse
  max = ""
  v.each{|n|  max += n.to_s }
  return max.to_i
end

def getMinValue(s)
  v = s.split(/[a-z]?/).sort
  min = ""
  v.each{|n|  min += n.to_s  }
  return min.to_i
end

$stdin.gets.to_i.times{
  input = $stdin.gets.chomp
  p getMaxValue(input) - getMinValue(input)
}

Measured memory_bytes: 6096
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Numerics;

namespace abc148
{
    class Program
    {
        static void Main(string[] args)
        {
            //Console.SetIn(new StreamReader("input.txt"));
            solve_abc148C();
        }
        public static void solve_abc148C()
        {
            long[] ab = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
            Console.WriteLine(lcm(ab[0], ab[1]));
        }

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

        public static void solve_abc148B()
        {
            int n = Convert.ToInt32(Console.ReadLine());
            string[] st = Console.ReadLine().Split();
            char[] ans = new char[2 * n];
            int k = 0;
            for (int i = 0; i < n; i++)
            {
                ans[k++] = st[0][i];
                ans[k++] = st[1][i];

            }

            Console.WriteLine(new string(ans));
        }

        public static void solve_abc148A()
        {
            int a  = Convert.ToInt32(Console.ReadLine());
            int b = Convert.ToInt32(Console.ReadLine());

            if ((a == 1 && b == 2) || (a == 2 &&  b == 1))
            {
                Console.WriteLine(3);
            }
            else if ((a == 1 && b == 3) || (a == 3 && b == 1))
            {
                Console.WriteLine(2);
            }
            else
            {
                Console.WriteLine(1);
            }


        }
    }
}


Measured memory_bytes: 13140
using namespace std;
#include <cstdio>
#include <cstring>
#include <algorithm>
#define N 200010
#define ll long long
int n;
int fa[N],a[N],b[N];
int dsu[N];
int getdsu(int x){return dsu[x]==x?x:dsu[x]=getdsu(dsu[x]);}
struct Info{
	int a,b,x;
} h[N*2];
bool cmph(Info son,Info fa){return (ll)fa.b*son.a<(ll)son.b*fa.a;}
int nh;
int main(){
	scanf("%d",&n);
	for (int i=2;i<=n;++i)
		scanf("%d",&fa[i]);
	for (int i=1;i<=n;++i){
		int x;
		scanf("%d",&x);
		(x==0?a[i]:b[i])=1;
	}
	for (int i=1;i<=n;++i)
		h[nh++]={a[i],b[i],i};
	make_heap(h,h+nh,cmph);
	for (int i=1;i<=n;++i)
		dsu[i]=i;
	ll ans=0;
	while (nh){
		int x=h[0].x;
		pop_heap(h,h+nh--,cmph);
		if (fa[x] && dsu[x]==x){
			int y=getdsu(fa[x]);
			dsu[x]=y;
			ans+=(ll)a[x]*b[y];
			a[y]+=a[x],b[y]+=b[x];
			h[nh++]={a[y],b[y],y};
			push_heap(h,h+nh,cmph);
		}
	}
	printf("%lld\n",ans);
	return 0;
}
















Measured memory_bytes: 8080
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX=200000;

int main(){
    int n, R[MAX];
    cin>>n;
    for(int i=0;i<n;i++) cin>>R[i];
    int maxv = -2000000000;
    int minv = R[0];
    for(int i=1;i<n;i++){
        maxv = max(maxv,R[i]-minv);
        minv = min(minv,R[i]);
    }
    
    cout<<maxv<<endl;
    
    return 0;
}


Measured memory_bytes: 3872
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner stdIn = new Scanner(System.in);
        int n = stdIn.nextInt();
        n = n % 1000;
        if(n == 0){
            System.out.println(n);
        }else {
            System.out.println(1000 - n);
        }
    }
}


Measured memory_bytes: 35684
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int dp[105][105];
int slow(vector<pii> edges) {
  memset(dp, 1, sizeof(dp));
  for(int i = 1; i <= 100; i++) dp[i][i] = 0;
  for(pii out: edges) {
    dp[out.first][out.second] = 1;
    dp[out.second][out.first] = 1;
  }
  for(int i = 1; i <= 100; i++) for(int j = 1; j <= 100; j++) for(int k = 1; k <= 100; k++) dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
  for(int i = 1; i <= 100; i++) for(int j = 1; j <= 100; j++) for(int k = 1; k <= 100; k++) dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
  for(int i = 1; i <= 100; i++) for(int j = 1; j <= 100; j++) for(int k = 1; k <= 100; k++) dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
  int ans = 0;
  for(int i = 1; i <= 100; i++) {
    for(int j = 1; j < i; j++) {
      ans += dp[i][j] == 2;
    }
  }
  return ans;
}

void solve() {
  // n vertices
  // k pairs of vertices that are have shortest distance 2
  // maximum is star graph, (n-1) choose 2
  int n, k;
  cin >> n >> k;
  if(2*k > (n-1) * (n-2)) {
    cout << "-1\n";
    return;
  }
  // make 1 the center
  vector<pii> edges;
  for(int i = 2; i <= n; i++) {
    edges.emplace_back(1, i);
  }
  // incrementally connect 2 to 3 through n
  int curr = (n-1)*(n-2)/2;
  for(int i = 2; i <= n; i++) {
    for(int j = i+1; curr > k && j <= n; j++) {
      edges.emplace_back(i, j);
      curr--;
    }
  }
  assert(slow(edges) == k);
  cout << edges.size() << "\n";
  for(pii out: edges) {
    cout << out.first << " " << out.second << "\n";
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  solve();
  /*
  ll t;
  cin >> t;
  for(ll i = 1; i <= t; i++) {
    cout << "Case #" << i << ": ";
    solve();
  }
  */
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#define fi first
#define se second
#define pb push_back
#define forn(i,n) for(int i=0;i<(n);i++)
#define for1(i,n) for(int i=1;i<=n;i++)
#define forr(i,n) for(int i=n;i>=0;i--)
#define all(x) x.begin(), x.end()
const int MAXN = 2e5 +5;

void fio(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}

int vis[MAXN];

int main(){
  fio();
  LL n, k; cin>>n>>k;
  vector <LL> v(n+1);
  for1(i,n) cin>>v[i];
 // for1(i,n) cout<<v[i]<<" ";
  LL x = v[1];
  LL co = 1;
  vector<LL> an= {1};
  vis[1]=1;
  //cout<<v[1]<<endl;
  while(vis[x]==0){
  		an.pb(x);
  		vis[x]=1;
  		x = v[x];
  }
   LL xx = 0;
  // vector<LL> an = {3,1,2,5,6,7,8};
  // LL x = 4, k = 4;
  vector <LL> bb, bd;
  for(LL i=0;i<an.size();i++){
  	if(an[i]==x || xx == 1){
  		bd.pb(an[i]);
  		xx = 1;
  	}
  	else{
  		bb.pb(an[i]);
  	}
  }
  if(k<bb.size()){
  	cout<<bb[k]<<endl;
  	return 0;
  }
  k-=(LL)bb.size();
  cout<<(bd[k%((LL)bd.size())])<<endl;
  return 0;
}

Measured memory_bytes: 10116
#include <bits/stdc++.h>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x)      begin(x),end(x)

using namespace std;
using vecint = vector<int>;
using ll = int64_t;

int main()
{
  int n;
  cin>>n;
  vecint a(n);
  REP(i,n)cin>>a[i];
  multiset<int> s;
  s.insert(a[0]);
  int cnt=0;
  FOR(i,1,n) {
    auto itr = s.lower_bound(a[i]);
    if (itr != s.begin()) {
      --itr;
      ++cnt;
      s.erase(itr);
    }
    s.insert(a[i]);
  }
  cout<<n-cnt<<endl;
  return 0;
}


Measured memory_bytes: 5376
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Library;
using static Library.Input;

namespace AtCoderTemplate
{
    class ProgramE
    {
        static void Main()
        {
            long n = NextInt, k = NextInt;
            var a = IntList.OrderBy(x => x).ToArray();
            var fac = new List<long>();

            int sum = a.Sum();
            long sqrt = MyMath.Sqrt(sum);
            for (int i = 1; i <= sqrt; i++)
            {
                if (sum % i == 0)
                {
                    fac.Add(i);
                    fac.Add(sum / i);
                }
            }
            if (sqrt * sqrt == sum) fac.RemoveAt(fac.Count - 1);

            fac.Sort((x, y) => - x.CompareTo(y));

            foreach (var element in fac)
            {
                var array = a.Select(x => x % element).OrderBy(x => x).ToArray();
                for (int i = 0; i < array.Length - 1; i++)
                {
                    array[i + 1] += array[i];
                }

                long left = array.Length - array.Last() / element - 1;

                if (array[left] <= k)
                {
                    System.Console.WriteLine(element);
                    return;
                }
            }
        }
    }
}

namespace Library
{
    class Input
    {
        static IEnumerator<string> enumerator = new string[] { }.AsEnumerable().GetEnumerator();

        public static string Line => Console.ReadLine();

        public static string[] StrArr => Line.Split(' ');

        public static int NextInt => int.Parse(NextWord());

        public static long NextLong => long.Parse(NextWord());

        public static List<int> IntList => StrArr.Select(int.Parse).ToList();

        public static List<long> LongList => StrArr.Select(long.Parse).ToList();

        public static IEnumerable<long[]> TakeLine(int N)
        {
            return Enumerable.Repeat(0, N).Select(_ => Console.ReadLine().Split(' ').Select(long.Parse).ToArray());
        }

        public static string NextWord()
        {
            while (!enumerator.MoveNext())
            {
                enumerator = StrArr.AsEnumerable().GetEnumerator();
            }
            return enumerator.Current;
        }
    }
}
namespace Library
{
    class MyMath
    {
        public static long Gcd(long a, long b)
        {
            return b == 0 ? a : Gcd(b, a % b);
        }

        public static long Sqrt(long n)
        {
            if (n < 0) return 0;
            long a = 0, tmp = 0, b = 0;
            for (int i = 62; i >= 0; i -= 2)
            {
                tmp = (b << 1) + 1 <= (n >> i) ? 1 : 0;
                a = a << 1 | tmp;
                n -= (((b << 1) + 1) * tmp) << i;
                b = (b << 1) + tmp + tmp;
            }
            return a;
        }

        public static long Nck(int n, int k)
        {
            if (k == 0) return 1;
            if (n == 0) return 0;
            return n * Nck(n - 1, k - 1) / k;
        }
    }
}


Measured memory_bytes: 16000
#include <bits/stdc++.h>
using namespace std;
int a[100];
int main(){
	int n;
	cin >> n;
	for(int i=0;i<n-1;i++)cin >> a[i];
	int sum=0;
	if(n==2){
		cout << 2*a[0] << endl;
	}
//	else if(n==3){
//		cout << min(a[0],a[1])*2+a[n-2];
//	}
	else {
		for(int i=0;i<n-2;i++){
		int t=min(a[i],a[i+1]);
		sum+=t;
	}
	cout << sum+a[0]+a[n-2] << endl;
	}
}

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

using namespace std;

int main()
{
	// 入力
	int H, W;
	cin >> H >> W;
	vector<vector<char>> squares(H, vector<char>(W));
	for (int i = 0; i < H; i++)
	{
		for (int j = 0; j < W; j++)
		{
			char a;
			cin >> a;
			squares[i][j] = a;
		}
	}
	
	// 行
	vector<bool> isAllRowWhite(H, true);
	// 列
	vector<bool> isAllColWhite(W, true);
	
	for (int i = 0; i < H; i++)
	{
		for (int j = 0; j < W; j++)
		{
			// 黒の場合
			if (squares[i][j] == '#') {
				isAllRowWhite[i] = false;
				isAllColWhite[j] = false;
			}
		}
	}
	
	// 出力
	for (int i = 0; i < H; i++)
	{
		// 行が黒の場合
		if (!isAllRowWhite[i])
		{
			for (int j = 0; j < W; j++)
			{
				// 列が黒の場合
				if (!isAllColWhite[j])
				{
					cout << squares[i][j];
				}
			}
			cout << endl;
		}
	}
	
	return 0;
}



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

using namespace std;

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

	int a, b;
	cin >> a >> b;
	if (a == 1) a += 13;
	if (b == 1) b += 13;
	if (a > b) {
		cout << "Alice\n";
	} else if (b > a) {
		cout << "Bob\n";
	} else {
		cout << "Draw\n";
	}

	return 0;
}



Measured memory_bytes: 256
/*
ID: vamaddu1
LANG: C++11
TASK: cowfood
*/

#define __USE_MINGW_ANSI_STDIO 0
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <deque>
#include <string.h>
#include <sstream>
#include <bitset>
#include <math.h>
#include <assert.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
template <class T>
using ordered_set = __gnu_pbds::tree<T, __gnu_pbds::null_type, less<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;
template <class T>
using ordered_multiset = __gnu_pbds::tree<T, __gnu_pbds::null_type, less_equal<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;

#define PI atan2(0, -1)
#define epsilon 1e-9
#define INF 5000000000000000000
#define MOD 1000000007

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

template <typename T, bool isMin>
struct ConvexHullTrick{
    using P = pair<T, T>;
    deque<P> L;
    inline T getY(const P &a,const T &x){ return a.first*x+a.second; }
    inline bool check(const P &a,const P &b,const P &c){
        return (b.first-a.first)*(c.second-b.second)
        >= (b.second-a.second)*(c.first-b.first);
    }
    void add(T a, T b){
        if(!isMin) a *= -1, b*= -1;
        P line(a, b);
        if(!L.empty() && L.back().first == a){
            line.second = min(line.second, L.back().second);
            L.pop_back();
        }
        while(L.size() > 1 && check(L[L.size()-2], L[L.size()-1], line)) L.pop_back();
        L.emplace_back(line);
    }
    T get(T x){
        if(L.empty()) return isMin ? INF : -INF;
        int lo = -1, hi = L.size()-1;
        while(lo+1 < hi){
            int mid = (lo+hi)/2;
            if(getY(L[mid], x) >= getY(L[mid+1],x)) lo = mid;
            else hi = mid;
        }
        return (!isMin ? -1 : 1)*getY(L[hi], x);
    }
};

int N;
long long C, arr [1000010];
ConvexHullTrick<long long, true> cht;

int main(){
    //freopen("sort.in", "r", stdin); freopen("sort.out", "w", stdout);
    ios_base::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(10);
    cin >> N >> C;
    for(int i = 0; i < N; i++) cin >> arr[i];
    cht.add(-2*arr[0], arr[0]*arr[0]);
    for(int i = 1; i < N; i++){
        long long val = cht.get(arr[i])+arr[i]*arr[i]+C;
        if(i == N-1) cout << val << '\n';
        else cht.add(-2*arr[i], val+arr[i]*arr[i]);
    }
    return 0;
}

/******************************
Kateba ii dake no hanashi darou
Success is only a victory away
- No Game No Life Opening
******************************/


Measured memory_bytes: 5120
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#include <bits/stdc++.h>
 
using namespace std;
 
int main(void) {
    ll n, sum = 0;
    cin >> n;
    rep(i, n+1){
        if(i % 3 != 0 && i % 5 != 0){
            sum += i;
        }
    }
    cout << sum << endl;
    return 0;
}


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

#define forn(i, n) for (int (i) = 0; (i) != (n); (i)++)
#define all(v) (v).begin(), (v).end()

ll n, c, good, all_ways, we, le, m2, wc;

signed main()
{
    cin >> n >> c, c *= n;
    ll k = (1 << (n - 1));
    vector<ll> Len(n), p(n - 1);
    forn(i, n) cin >> Len[i], Len[i] *= n;
    sort(all(Len));
    iota(all(p), 0);
    do {
        all_ways++;
        vector<vector<ll> > dp(c + 1, vector<ll>(k));
        dp[Len.back()][0] = 1;
        forn(i, c)
        {
            if (i % n == 0) continue;
            we = p[i % n - 1];
            le = Len[we];
            forn(mask, k)
            {
                if ((1 << we) & mask) continue;
                m2 = mask + (1 << we);
                for (ll ac = i; ac <= c; ac++)
                {
                    wc = max(ac, min(c, le + i));
                    dp[wc][m2] += dp[ac][mask];
                }
            }
        }
        good += dp[c][k - 1];
    } while (next_permutation(all(p)));
    printf("%.15f", 1.0 * good / all_ways / pow(c / n, n - 1));
}


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

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll n, k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  combination comb(n);

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

  mint max_sum = 0;
  for(int i = 0; i < n; ++i){
    max_sum += comb(i, k - 1) * (mint)a[i];
  }

  mint min_sum = 0;
  for(int i = 0; i < n; ++i){
    min_sum += comb(n - i - 1, k - 1) * (mint)a[i];
  }

  cout << max_sum - min_sum << endl;
  return 0;
}

Measured memory_bytes: 2560
#include <iostream>

using namespace std;

int step = 0, x1, y1, x2, y2;
int steps( int x, int y, int _max )
{

            x1 = ( _max - x );
            y1 = ( _max - y );

            step += (x1/2) + (y1/2);

            x2 = x1 % 2;
            y2 = y1 % 2;


        if( x2 == 1 && y2 == 1 )
        {
            step++;

        }
        else if( x2 == 0 && y2 == 1 )
        {

            step +=2;

        }
        else if( x2 == 1 && y2 == 0 )
        {

            step +=2;

        }

        return step;
}



int main()
{
    int a, b, c, result = 0;

    cin >> a >> b >> c;

    if ( a > b )
    {
        if ( a > c ) //b,a
        {
            result = steps( b, c, a );
            cout << result <<endl;

        }

        else
        {
            result = steps(a, b, c);
            cout << result <<endl;

        }
    }

    else
        if ( b > c )   // c,a
        {
            result = steps(a, c, b);
            cout << result <<endl;

        }
        else
           {
             result = steps(a, b, c);
            cout << result <<endl;

           }


    return 0;

}


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

int main(){
  int N,K,Q;
  cin >> N >> K >> Q;
  vector<int>P(N,K-Q);
  for(int i=0;i<Q;i++){
    int ans;
    cin >> ans;
    P.at(ans-1)++;
  }
  for(int i=0;i<N;i++){
    if(P.at(i)>0){
      cout << "Yes" << endl;
    }
    else{
      cout << "No" << endl;
    }
  }
}


Measured memory_bytes: 1024
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-9;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;

vector<int> Prime(int num) {
	vector<int>ret;
	ret.push_back(2);
	ret.push_back(3);
	for (int i = 5; i <= num; i += 6) {
		bool flag = true;
		for (int j = 2; j < ret.size(); j++) {
			if (ret[j] * ret[j] > i)break;
			if (i%ret[j] == 0) {
				flag = false;
				break;
			}
		}
		if (flag)ret.push_back(i);
		flag = true;
		for (int j = 2; j < ret.size(); j++) {
			if (ret[j] * ret[j] > i + 2)break;
			if ((i + 2) % ret[j] == 0) {
				flag = false;
				break;
			}
		}
		if (flag)ret.push_back(i + 2);
	}
	return ret;
}

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

	cin >> N;
	auto P = Prime(1000000);
	map<long long int, int>mp;
	for (auto i : P) {
		while (N%i == 0) {
			mp[i]++;
			N /= i;
		}
	}
	if (N > 1)mp[N]++;
	int ans = 0;
	for (auto &i : mp) {
		for (int j = 1; j <= 100; j++) {
			if (i.second >= j) {
				ans++;
				i.second -= j;
			}
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 3888
#include<bits/stdc++.h>
using namespace std;
#define MAXN 100000
#define ff first
#define ss second
#define ll long long
#define mod 1000000007
#define pii pair<ll,ll>
#define vi vector<ll>
#define mii map<ll,ll>
#define pb push_back
#define mp make_pair
#define ps(x,y) fixed<<setprecision(y)<<x
#define mk(arr,n,type) type *arr=new type[n];
#define w(x) ll x; cin>>x; while(x--)
#define endl '\n'
void kehsihba(){
   ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
   freopen("input.txt", "r", stdin);
   freopen("output.txt", "w", stdout);
#endif
}
int32_t main() {
	//kehsihba();
	ll n,m;
	cin>>n>>m;
	ll ans=((n*(n-1))/2)+((m*(m-1))/2);
	cout<<ans;
    return 0;
}

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

using namespace std;

typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef long double ld;

const int inf = 1e9;
const ll inf64 = 1e18;

const int N = 20;

int n;
int a[N][2],x[N];
int perm[N];

int main() {

#ifdef DEBUG
    freopen("input.txt", "r", stdin);
#endif

    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin >> n;

    for (int j = 0; j < 2; j++) {
        for (int i = 0; i < n; i++) {
            cin >> a[i][j];
            perm[i] = i;
        }
    }

    int res = inf;

    for (int mask = 0; mask < (1 << n); mask++) {
        if (__builtin_popcount(mask) % 2)
            continue;
        for(int i = 0; i < n; i++)
            x[i] = a[i][(mask >> i) & 1];
        sort(perm, perm + n, [&](int i, int j) {
            return x[i] < x[j];
        });
//        for (int i = 0; i < n; i++) {
//            cout << ((mask >> i) & 1);
//        }
//        cout << "\n";
//        cout << "x[] : ";
//        for (int i = 0; i < n; i++) {
//            cout << x[i] << " ";
//        }
//        cout << "\n";
        int ok = 1;
        for (int i = 0; i < n; i++) {
            int j = i;
            while (j < n && x[perm[i]] == x[perm[j]])
                j++;
            j--;
            // [i, j]
            int need[2] = {0, 0};
            vector<int> hlist[2];
            for (int q = i; q <= j; q++) {
                need[q & 1]++;
                hlist[(perm[q] & 1) ^ ((mask >> perm[q]) & 1)].push_back(perm[q]);
            }
            if (need[0] != (int) hlist[0].size() || need[1] != (int) hlist[1].size()) {
                ok = 0;
                break;
            }
            sort(hlist[0].begin(), hlist[0].end());
            sort(hlist[1].begin(), hlist[1].end());
            int ptr[2] = {0, 0};
            for (int q = i; q <= j; q++) {
                perm[q] = hlist[q & 1][ptr[q & 1]++];
            }
            i = j;
        }
        int tmp = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < i; j++) {
                if (perm[j] > perm[i])
                    tmp++;
            }
        }
        if (ok)
            res = min(res, tmp);
    }

    if (res == inf)
        res = -1;
    cout << res << "\n";

    return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
	static int W, N;
	static int w[], v[];
	static int loop = 0;
	static int dp[][];

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			loop++;
			W = sc.nextInt();
			if (W == 0)
				break;
			N = sc.nextInt();
			w = new int[N+1];
			v = new int[N+1];
			sc.nextLine();
			for (int i = 1; i <= N; i++) {
				String str = sc.nextLine();
				String s[] = str.split("\\,");
				v[i] = Integer.parseInt(s[0]);
				w[i] = Integer.parseInt(s[1]);
			}
			int value = dp();
			int weight = 0;
			int v = -1;;
			for (int i = 0; i <= W; i++) {
				if (dp[N][i] > v) {
					v = dp[N][i];
					weight = i;
				}
			}
			System.out.println("Case " + loop + ":");
			System.out.println(value);
			System.out.println(weight);
		}

	}

	private static int max(int a, int b) {
		if (a > b)
			return a;
		return b;
	}

	private static int dp() {
		dp = new int[N + 1][W + 1];
		for (int i = 1; i <= N; i++) {
			for (int j = 0; j <= W; j++) {
				if (w[i] > j)
					dp[i][j] = dp[i - 1][j];
				else
					dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - w[i]] + v[i]);
			}
		}
		return dp[N][W];
	}
}

Measured memory_bytes: 30020