akhauriyash/Code-Regression huggingface dataset:
import Data.List
import Data.List.Split
import Text.Printf
import System.Environment (getArgs)

choose n 0 = 1
choose n k | n == k = 1
           | k == 0 = 1
           | otherwise = (((fromIntegral n) :: Integer) * (choose (n - 1) k)) `div` fromIntegral (n - k)

search minCount maxCount (x:xs) | minCount <= x = (x, minCount, min x maxCount)
                                | otherwise = f (minCount - x) xs
  where f _ [] = (0, 0, 0)
        f count (x:xs) | count <= x = (x, x - count, x - count)
                       | otherwise = f (count - x) xs

combo minCount maxCount ls = (average, sum $ map (\i -> choose width i) [minK..maxK])
  where average = (fromIntegral (sum $ take minCount $ sortedList)) / (fromIntegral minCount :: Double)
        (width, minK, maxK) = search minCount maxCount $ map length $ groupBy (==) $ sortedList
        sortedList = reverse $ sort ls

solve minCount maxCount ls = [printf "%.6f" average, show n]
  where (average, n) = combo minCount maxCount ls

main = do
  l1 <- getLine
  let (x:minCount:maxCount:xs) = map (read::String->Int) $ splitOn " " l1
  l2 <- getLine
  let ls = map (read::String->Integer) $ splitOn " " l2
  let answer = solve minCount maxCount ls
  putStrLn $ answer!!0
  putStrLn $ answer!!1


Measured memory_bytes: 1020
#pragma GCC optimize("Ofast")
  
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <string>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <unordered_set>
#include <list>
#include <tuple>
#include <iomanip>
#include <climits>
#include <cstdlib>
#include <cassert>
#include <numeric>
#include <cmath>
#include <bitset>
#include <random>
#include <regex>

using namespace std;
  
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define Fixed fixed << setprecision(14)
#define int int64_t
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9+7; 
constexpr int mod2 = 998244353;
constexpr int dy[] = {0,1,0,-1,1,-1,-1,1};
constexpr int dx[] = {1,0,-1,0,1,1,-1,-1};
 
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class A, class B> inline A updiv(const A a,const B b){ return (a + b - 1) / b; }
template <class A, class B> inline A gcd(const A a,const B b){ return b ? gcd(b,a % b) : a; }
template <class A, class B> inline A lcm(const A a,const B b){ return a / gcd(a,b) * b; }

template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
template <class A,class B> using umap = unordered_map<A,B>;


signed main(void){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    int h,w;
    cin >> h >> w;

    vector<vector<char> > mat(h+1,vector<char>(w+1));
    
    for(int i = 1; i <= h; ++i){
        for(int j = 1; j <= w; ++j){
            cin >> mat[i][j];
        }
    }

    vector<vector<int> > cost(h+1,vector<int>(w+1,INF));
    cost[1][1] = (mat[1][1] == '#');

    reps(i,h){
        reps(j,w){
            if(i == 1 && j == 1) continue;
            cost[i][j] = min(cost[i-1][j] + (mat[i-1][j] == '.' && mat[i][j] == '#'),
                             cost[i][j-1] + (mat[i][j-1] == '.' && mat[i][j] == '#'));
        }
    }

    cout << cost[h][w] << '\n';

    return 0;
}

Measured memory_bytes: 384
/*input
3
1 2 10
2 3 20
*/
#ifdef UncleGrandpa
#include <prettyprint.hpp>
#endif
#include <bits/stdc++.h>
using namespace std;
#define sp ' '
#define endl '\n'
#define fi first
#define se second
#define int long long
#define loop(i,l,r) for(int i=(l); i<=(r); i++)
#define rloop(i,l,r) for(int i=(l); i>=(r); i--)
#define debug(x...) {cout << "[" << #x << "] ="; _co(x);}
void _co() {cout << endl;}
template<typename T, typename... Ts> void _co(const T& value, const Ts&... values) {cout << ' ' << value; _co(values...);}
template<typename T, typename... Ts> void co(const T& value, const Ts&... values) {cout << "deb: " << value; _co(values...);}
// change cout to cerr for debug in crash
const int N = 1e5 + 5;

struct Edge {
	int u, v, c;
};

int lazy[N];
struct dsu {
	vector<int> par, sz;
	void init(int n) {
		par.assign(n + 5, 0); sz.assign(n + 5, 1);
		iota(par.begin(), par.end(), 0);
	}
	int find(int x) {
		return par[x] == x ? x : find(par[x]);
	}
	void uni(int x, int y) {
		x = find(x); y = find(y);
		if (x != y) {
			if (sz[x] > sz[y]) swap(x, y);
			sz[y] += sz[x]; sz[x] = 0;
			par[x] = y;
		}
	}
} d;


int n;
vector<Edge> e;
signed main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	cin >> n; d.init(n);
	loop(i, 1, n - 1) {
		int u, v, c; cin >> u >> v >> c;
		e.push_back({u, v, c});
	}
	sort(e.begin(), e.end(), [&](Edge & X, Edge & Y) {
		return X.c > Y.c;
	});

	for (auto &cur : e) {
		int u = d.find(cur.u); int v = d.find(cur.v);
		int szu = d.sz[u]; int szv = d.sz[v];
		lazy[u] += cur.c * szv; lazy[v] += cur.c * szu;
		d.uni(u, v);
		if (d.par[u] == v) {
			lazy[u] -= lazy[v];
		}
		else {
			lazy[v] -= lazy[u];
		}
		// co(u, v, lazy[u], lazy[v]);
	}
	// loop(i, 1, n) cout << d.par[i] << sp;
	// cout << endl;
	loop(i, 1, n) {
		int res = lazy[i];
		int u = i;
		while (d.par[u] != u) {
			u = d.par[u];
			res += lazy[u];
		}
		cout << res << endl;
	}
}

Measured memory_bytes: 7152
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <utility>
#include <map>
#include <bitset>
#include <numeric>
#define ll long long
using namespace std;
using p = pair<ll, ll>;
ll dx[8]={ 0, 1, 0,-1, 1, 1,-1,-1}; // x軸方向への変位
ll dy[8]={ 1, 0,-1, 0, 1,-1, 1,-1}; // y軸方向への変位

int main(void){
    ll s, w;
    cin >> s >> w;
    if(w>=s)
        cout << "unsafe" << endl;
    else
        cout << "safe" << endl;
    return 0;
}


Measured memory_bytes: 3616
let area =
  [| [1; 4]
   ; [0; 2; 5]
   ; [1; 3; 6]
   ; [2; 7]
   ; [0; 5; 8]
   ; [1; 4; 6; 9]
   ; [2; 5; 7; 10]
   ; [3; 6; 11]
   ; [4; 9; 12]
   ; [5; 8; 10; 13]
   ; [6; 9; 11; 14]
   ; [7; 10; 15]
   ; [8; 13]
   ; [9; 12; 14]
   ; [10; 13; 15]
   ; [11; 14] |]

let m_d =
  [| [|0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0; 0|]
   ; [|0; 1; 2; 3; 1; 2; 3; 4; 2; 3; 4; 5; 3; 4; 5; 6|]
   ; [|1; 0; 1; 2; 2; 1; 2; 3; 3; 2; 3; 4; 4; 3; 4; 5|]
   ; [|2; 1; 0; 1; 3; 2; 1; 2; 4; 3; 2; 3; 5; 4; 3; 4|]
   ; [|3; 2; 1; 0; 4; 3; 2; 1; 5; 4; 3; 2; 6; 5; 4; 3|]
   ; [|1; 2; 3; 4; 0; 1; 2; 3; 1; 2; 3; 4; 2; 3; 4; 5|]
   ; [|2; 1; 2; 3; 1; 0; 1; 2; 2; 1; 2; 3; 3; 2; 3; 4|]
   ; [|3; 2; 1; 2; 2; 1; 0; 1; 3; 2; 1; 2; 4; 3; 2; 3|]
   ; [|4; 3; 2; 1; 3; 2; 1; 0; 4; 3; 2; 1; 5; 4; 3; 2|]
   ; [|2; 3; 4; 5; 1; 2; 3; 4; 0; 1; 2; 3; 1; 2; 3; 4|]
   ; [|3; 2; 3; 4; 2; 1; 2; 3; 1; 0; 1; 2; 2; 1; 2; 3|]
   ; [|4; 3; 2; 3; 3; 2; 1; 2; 2; 1; 0; 1; 3; 2; 1; 2|]
   ; [|5; 4; 3; 2; 4; 3; 2; 1; 3; 2; 1; 0; 4; 3; 2; 1|]
   ; [|3; 4; 5; 6; 2; 3; 4; 5; 1; 2; 3; 4; 0; 1; 2; 3|]
   ; [|4; 3; 4; 5; 3; 2; 3; 4; 2; 1; 2; 3; 1; 0; 1; 2|]
   ; [|5; 4; 3; 4; 4; 3; 2; 3; 3; 2; 1; 2; 2; 1; 0; 1|] |]

let h a =
  let rec doit i acc =
    if i = 16 then acc
    else doit (i + 1) (acc + m_d.(a.(i)).(i))
  in doit 0 0

let idx_by_val x (a : int array) =
  let n = Array.length a in
  let rec doit i =
    if i = n then raise Not_found
    else if x = a.(i) then i
    else doit (i + 1)
  in doit 0

let solve a =
  let goal = [|1; 2; 3; 4; 5; 6; 7; 8; 9; 10; 11; 12; 13; 14; 15; 0|] in
  let rec idastar i limit space_i moved lower =
    if i = limit then begin
      if a = goal then (Printf.printf "%d\n" (List.length moved - 1); exit 0)
    end else
      let rec move = function
        | [] -> ()
        | j :: js ->
          let x = a.(j) in
          if x <> List.hd moved then begin
            let new_lower = lower - m_d.(x).(j) + m_d.(x).(space_i) in
            if new_lower + i <= limit then begin
              a.(j) <- 0;
              a.(space_i) <- x;
              idastar (i + 1) limit j (x :: moved) new_lower;
              a.(j) <- x;
              a.(space_i) <- 0;
            end
          end;
          move js
      in move area.(space_i)
  in
  let lower = h a in
  let rec doit limit =
    if limit <= 45 then begin
      idastar 0 limit (idx_by_val 0 a) [-1] lower;
      doit (limit + 1)
    end in
  doit lower

let () =
  solve (Array.init 16 (fun _ -> Scanf.scanf "%d " (fun i -> i)))

Measured memory_bytes: 4520
using System;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        var input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList();
        input.Sort((x, y) => y - x);

        if (input.First() < input.Skip(1).Sum())
        {
            Console.WriteLine("Yes");
            return;
        }

        Console.WriteLine("No");
    }
}

Measured memory_bytes: 13396
#include<iostream>
int s,t,u,v,n,c,d,x,y,i,j,f[102][102],a[4]={1,0,-1,0};int r(int x,int y){if(f[x][y]==c)for(int i=4;i-->0;f[x][y]=9)r(x+a[i],y+a[(i+3)%4]);}main(){for(;std::cin>>x>>y>>s>>t>>u>>v>>n,x;puts(f[u][v]-9?"NG":"OK")){for(j=0;j++<101;)for(i=0;i++<101;)f[i][j]=0;for(;n-->0;c=f[s][t]){std::cin>>c>>d>>x>>y;for(i=2;d&i-->0;)for(j=4;j-->0;)f[x+i][y+j]=c;for(i=4;!d&i-->0;)for(j=2;j-->0;)f[x+i][y+j]=c;}c&&r(s,t);}}

Measured memory_bytes: 0
N,K = map(int, input().split())
d = [0]*2*K
for i in range(K):
    d[2*i], d[2*i+1] = map(int, input().split())
a=[0]*(N+1)
b=[0]*(N+1)
a[1]=1
b[1]=1
for i in range(2,N+1):
    t=0
    for j in range(K):
        if i-d[2*j]>0:
            t+=b[i-d[2*j]]
        if i-d[2*j+1]-1>0:
            t-=b[i-d[2*j+1]-1]
    a[i]=t%998244353
    b[i]=(b[i-1]+a[i])
print(a[N])


Measured memory_bytes: 76680
#!/usr/bin/env python3
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def sum_of_arithmetic_progression(s, d, n):
    return n * (2 * s + (n - 1) * d) // 2


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


def lcm(a, b):
    g = gcd(a, b)
    return a / g * b


def solve():
    A1, A2, A3 = map(int, input().split())
    if A1 + A2 + A3 >= 22:
        print("bust")
    else:
        print("win")


def main():
    solve()


if __name__ == '__main__':
    main()


Measured memory_bytes: 9976
/* AUTHOR :  SHIVANK JAIN */

#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false)
#define itt cin.tie(0)
#define now cout.tie(0)

using namespace std;

#define ll long long
#define li long int

#define pb push_back
#define rep(i,a,n) for(int i=a;i<n;i++)
#define reprev(i,n,a) for(int i=n;i>=a;i--)
#define endl "\n"

#define vi vector<int>
#define vll vector<ll>
#define vpi vector< pair<int , int> >
#define mapi map<int , int>
#define mapll map<ll ,ll >
#define seti set<int> 

#define fr first
#define se second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define mp make_pair
#define sort(v) sort(v.begin() , v.end())

#define BIG 1000000007
int gcd(int a, int b) 
{ // builtin function __gcd(a,b)
    if (a == 0) 
        return b; 
    return gcd(b % a, a); 
} 
int main(){

     fast;itt;now;
 
//    #ifndef ONLINE_JUDGE
//    // for getting input from input.txt
//    freopen("input.txt", "r", stdin);
//    // for writing output to output.txt
//     freopen("output.txt", "w", stdout);
//    #endif
    
     int n, m ;   cin>>n>>m;
     int sum = 0;
     
     rep(i,0,m){
     	int p;
     	cin>>p;
     	sum+=p;
	 }  
	 if(sum > n)
	  cout<<-1<<endl;
	 else
	  cout<<n - sum<<endl;    
}

Measured memory_bytes: 3656
//g++ -std=gnu++14 a.cpp
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <random>
#include <math.h>

using namespace std;

#define ll long long
#define rep(i, n) for(ll i = 0; i < (n); i++)
ll MOD = 1e9 + 7;
int INF = 1 << 30;
ll INFL = 1LL << 60;

int main() {
  ll N,W;
  cin >> N >> W;
  ll w[105],v[105];
  rep(i,N)cin >> w[i] >> v[i];

  vector<vector<ll>> dp(105,vector<ll>(100005, 0));
  //rep(i,105)rep(j,100005)dp[i][j] = 0;
  for(int i = 1;i <= N;i++){
    for(int sum = 0;sum <= W;sum++){
      if(w[i-1]<=sum){
        dp[i][sum] = max(dp[i][sum],dp[i-1][sum-w[i-1]]+v[i-1]);
        dp[i][sum] = max(dp[i][sum],dp[i-1][sum]);
      }else{
        dp[i][sum] = dp[i-1][sum];
      }
    }
  }
  cout << dp[N][W] << endl;
}


Measured memory_bytes: 83328
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define INF 1LL << 60;
#define LLINF 1e12
#define PI 3.14159265359
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
int ny, nx;
typedef long long ll;
using namespace std;

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

ll lcm(ll m, ll n)
{
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n);
}

ll llpow(ll x, ll y)
{
    ll ans = 1;
    REP(i, y)
    ans *= x;
    return ans;
}

ll llmin(ll x, ll y) { return x < y ? x : y; }
ll llmax(ll x, ll y) { return x > y ? x : y; }

template <typename Container>
bool exist_in(const Container &c, const typename Container::value_type &v)
{
    return (c.end() != std::find(c.begin(), c.end(), v));
}

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

ll nCr(int n, int r)
{
    if (n == r or n == 0)
        return 1;
    if (n < r)
        return 0;
    if (r == 1)
        return n;
    return nCr(n - 1, r - 1) + nCr(n - 1, r);
}

//std::cout << std::defaultfloat << std::setprecision(10);
////////////////////////////////////////
int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

    int n; cin >> n;
    vector<string> S(n);
    int res[n][27]={0};
    
    REP(i,n){
        cin >> S[i];
        REP(j,S[i].size()){
            res[i][S[i][j]-'a']++;
        }
    }

    string ans;

    REP(i,27){
        int cnt=0, hold=100000;
        REP(j,n){
            if(res[j][i]!=0){
                cnt = res[j][i];
                if(cnt<hold) hold=cnt;
            }else{
                hold = 0;
                goto label;
            }
        }
        label: int hoge=0;
        REP(j,hold) ans.push_back(i+'a');
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
N = int(input())
P = list(map(int, input().split()))
L = 2*N

for i in range(1, N+1):
    print(i*L, end=' ')
print()

B = [L*(N-i) for i in range(1, N+1)]
for i, p in enumerate(P):
    B[p-1] += i+1
print(' '.join([str(a) for a in B]))

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

using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fileio freopen("http://in.in", "r", stdin),freopen("out.out", "w", stdout);
#define ll long long
#define ld long double
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pll pair<long long ,long long >
#define ppll pair < pll , pll >
#define sd(x1) scanf("%d",&x1)
#define sld(x1) scanf("%lld",&x1)
#define INF 1e18
#define eps 0.00001

#define le length
#define debug(n1) cout << n1 << endl
#define rep(j , n) for(ll i = j ; i <= n ; i++)
#define per(j , n) for(ll i = j ; i >= n ; i--)

int main() {
    SPEED;
 	ll t;
 	cin>>t;
 	//ll arr[30];
 	//arr[0]=2;
 	ll ac=0,wa=0,tle=0,re=0;
 	while(t-->0){
			string s;
			cin>>s;
			if(s=="WA"){
				wa++;
			}
			if(s=="AC"){
				ac++;
			}
			if(s=="RE"){
				re++;
			}
			if(s=="TLE"){
				tle++;
			}
				
		}
		cout<<"AC x "<<ac<<endl;
		cout<<"WA x "<<wa<<endl;
		cout<<"TLE x "<<tle<<endl;
		cout<<"RE x "<<re<<endl;
}

 		
 
 	
 	



 

Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define N 1000005
#define mod 1000000007
using namespace std;
template<typename T>
inline void in(T &x)
{
	x=0;
	char c=getchar();
	bool fu=0;
	while(c<'0'||c>'9'){if(c=='-')fu=1;c=getchar();}
	while(c>='0'&&c<='9')x=(x<<1)+(x<<3)+(c^48),c=getchar();
}
int n,a[N],has[N];
bool not_prime[N],pairwise=1,setwise=1;
void produce(int lim)
{
	not_prime[1]=1;
	for(int i=2;i<=lim;++i)
	{
		if(!not_prime[i])
		{
			bool flag=0;
			int cnt=0;
			if(has[i])cnt+=has[i];
			for(int j=i+i;j<=lim;j+=i)
			{
				not_prime[j]=1;
				if(has[j])
				{
					cnt+=has[j];
				}
			}
			if(cnt>1)pairwise=0;
			if(cnt==n)setwise=0;
		}
	}
}
int main()
{
	in(n);
	bool flag=0;
	for(int i=0;i<n;++i)
	{
		in(a[i]);
		++has[a[i]];
		if(a[i]==1)
		{
			flag=1;
		}
	}
	produce(N-1);
	if(flag)setwise=1;
	if(pairwise)puts("pairwise coprime");
	else if(setwise)puts("setwise coprime");
	else puts("not coprime");
	return 0;
}

Measured memory_bytes: 12348
#include<iostream>

using namespace std;

int main() {
	int H, W;
	cin >> H >> W;

	while (H != 0 && W != 0) {
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				if (i % 2 == 0) {
					if (j % 2 == 0) {
						cout << '#';
					}
					else cout << '.';
				}
				else {
					if (j % 2 == 0) {
						cout << '.';
					}
					else cout << '#';
				}
			}
			cout << endl;
		}

		cout << endl;
		cin >> H >> W;
	}

	return 0;
}


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

int main(){
    int n,d,x;
    cin>>n>>d>>x;
    int p[d][n];
    for(int i=0;i<d;i++){
        for(int j=0;j<n;j++){
            cin>>p[i][j];
        }
    }
    for(int i=0;i<d-1;i++){
        int dp[x+1];
        fill(dp,dp+x+1,0);
        for(int j=0;j<n;j++){
            int gain=p[i+1][j]-p[i][j];
            int price=p[i][j];
            if(gain<=0) continue;
            for(int k=0;k+price<=x;k++){
                dp[k+price]=max(dp[k+price],dp[k]+gain);
            }
        }
        int maxiumum=0;
        for(int j=0;j<=x;j++){
            maxiumum=max(maxiumum,dp[j]);
        }
        x+=maxiumum;
    }
    cout<<x<<endl;
    return 0;
}

Measured memory_bytes: 3080
import java.util.Arrays;
import java.util.Scanner;


public class Main {
	
	

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		int[] d = new int[n];
		for(int i=0;i<n;i++) {
			d[i]=sc.nextInt();
		}
		Arrays.sort(d);
		
		System.out.println(d[n/2]-d[n/2-1]);
	}
}

Measured memory_bytes: 50936
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>

using namespace std;

#define ll long long
#define db double
#define clr(a, b) memset(a, b, sizeof(a))

const int maxn = 5e5 + 10;
const int inf = 0x7ffffff;

vector<ll> getdiv( ll N)
{
    vector<ll> div;
    for (ll i = 1; i * i <= N;i++)
    {
        if(N%i==0)
        {
            div.push_back(i);
            if(N/i!=i)
                div.push_back(N / i);
        }
    }
    return div;
}
ll opreation(ll n,ll k)
{
    if(k==1)
        return n;
    while (n>=k)
    {
        if(n%k==0)
            n /= k;
        else
            n %= k;
    }
    return n;
}
ll N;
void solve()
{
    cin >> N;
    int cnt = 0;
    vector<int> vc1, vc2;
    for(ll d:getdiv(N))
        if(opreation(N,d)==1)
            cnt++;
    for(ll d:getdiv(N-1))
        if(opreation(N,d)==1)
            cnt++;
    cout << cnt << "\n";
}

int main()
{
    //freopen("out","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    int T = 1;
    //cin >> T;
    while(T-- > 0)
        solve();

}

Measured memory_bytes: 384
#![allow(unused)]

use std::{cmp, collections, fmt, io, iter, ops, str};
use cmp::Ordering::{Equal, Greater, Less};
use collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, LinkedList, VecDeque};
use io::{Read, Write};

#[cfg(feature = "debug")]
macro_rules! debug {
    ($fmt: expr) => { eprintln!($fmt) };
    ($fmt: expr, $($arg: tt)*) => { eprintln!($fmt, $($arg)*) };
}

#[cfg(not(feature = "debug"))]
macro_rules! debug {
    ($fmt: expr) => {};
    ($fmt: expr, $($arg: tt)*) => {};
}

fn read_line() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().to_owned()
}

fn read_word() -> String {
    const CAPACITY: usize = 16;

    let mut stdin = io::stdin();
    let mut byte: [u8; 1] = [0];

    loop {
        let mut buf = Vec::with_capacity(CAPACITY);

        loop {
            let res = stdin.read(&mut byte);

            if res.unwrap_or(0) == 0 || byte[0] <= b' ' {
                break;
            } else {
                buf.push(byte[0]);
            }
        }

        if buf.len() > 0 {
            return String::from_utf8(buf).unwrap();
        }
    }
}

fn parse_line<T: str::FromStr>() -> T {
    read_line().parse().ok().unwrap()
}

fn parse_word<T: str::FromStr>() -> T {
    read_word().parse().ok().unwrap()
}

fn parse_vec<T: str::FromStr>() -> Vec<T> {
    read_line()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn flush() {
    io::stdout().flush();
}

fn main() {
    // (string, count) pair
    let mut strings = HashMap::new();

    let blue_num = parse_line::<usize>();
    for _ in 0..blue_num {
        let s = read_line();
        let e = strings.entry(s).or_insert(0);
        *e += 1;
    }

    let red_num = parse_line::<usize>();
    for _ in 0..red_num {
        let s = read_line();
        let e = strings.entry(s).or_insert(0);
        *e -= 1;
    }

    let max_count = strings.values().max().unwrap();
    let max_count = cmp::max(0, *max_count);
    println!("{}", max_count);
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test() {
        //
    }
}


Measured memory_bytes: 4352
var n,k,i:longint;
    b:array[1..200001] of longint;
    f:text;
begin
readln(n);
k:=1;
for i:=1 to n do
read(b[i]);
for i:=1 to n do
begin
if b[i]=k then inc(k);
end;
if k=1 then write('-1') else write(n-k+1);
end.



Measured memory_bytes: 896
#define _USE_MATH_DEFINES
#include<iostream>
#include<sstream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<unordered_map>
#include<math.h>
#include<iterator>
 
using namespace std;
 
int middle(int a,int b,int c){
  int hoge[]={a,b,c};
  sort(hoge,hoge+3);
  return hoge[1];
}
 
int main(){
  int n,x;
  cin >> n >>x;
  if(x==1|| x==(2*n-1)){
    cout <<"No"<<endl;
    return 0;
  }
 
  vector<int> ans(n*2-1);
  for (int i = 0; i < n*2-1; i++) {
    ans[i]=i+1;
  }
 
  if(n==(x+1)){
    ans[n-1]=ans[n-2];
    ans[n-2]=ans[n-3];
    ans[n-3]=n;
  }else if(n==(x-1)){
    ans[n-1]=ans[n];
    ans[n]=ans[n+1];
    ans[n+1]=n;
  }else if(x<n){
    int tmp = ans[n-1];
    int tmp1 = ans[n-2];
    ans[n-2]=ans[x-2];
    ans[n-1]=ans[x-1];
    ans[x-1]=tmp;
    ans[x-2]=tmp1;
  }else if(x>n){
    int tmp = ans[n-1];
    int tmp1 = ans[n];
    ans[n]=ans[x];
    ans[n-1]=ans[x-1];
    ans[x-1]=tmp;
    ans[x]=tmp1;
  }
 
  cout <<"Yes"<<endl;
  for (int i = 0; i < n*2-1; i++) {
    cout << ans[i] <<endl;
  }
  return 0;
}

Measured memory_bytes: 2304
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
int main()
{
	int n, cnt = 0, siz, siz_, on;
	char c[26], l[101];
	cin >> n;
	scanf("%s", c);
	siz = strlen(c);
	for (int w = 0; w < n; w++)
	{
		scanf("%s", l);
		siz_ = strlen(l);
		bool gj = false;
		for (int i = 0; i < siz_; i++)
		{
			for (int j = 1; i + j*(siz - 1) < siz_; j++)
			{
				on = i;
				bool jg = true;
				for (int k = 0; k < siz; k++)
				{
					if (c[k] != l[on])jg = false;
					on += j;
				}
				if (jg)gj = true;
			}
		}
		if (gj)cnt++;
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 3156
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    Init();
    ll n, a, b; string s;
    cin >> n >> a >> b >> s;
    ll cnt_a = 0, cnt_b = 0;
    rep(i, n){
        // 国内学生の場合
        if(s[i] == 'a'){
            if(cnt_a+cnt_b < a+b){
                cnt_a++;
                Yes();
            }
            else{
                No();
            }
        }
        // 海外学生の場合
        else if(s[i] == 'b'){
            if(cnt_a+cnt_b < a+b && cnt_b < b){
                cnt_b++;
                Yes();
            }
            else{
                No();
            }
        }
        // どちらでもない場合
        else{
            No();
        }
    }
}

Measured memory_bytes: 3720
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <assert.h>
#include <memory.h>
#include <queue>
#include <string.h>
#include <set>
#include <map>
#include <bitset>
using namespace std;

#define ll long long
#define N 200005

int A[N];
int preMod[N];

int add(int x,int y,int mod) {
  int ret = (x + y)%mod;
  return ret;
}
void solve() {
  int n,k;scanf("%d %d ", &n,&k);
  map<int,int> num;
  ++num[0];
  ll ret = 0;
  for(int i=1;i<=n;++i) {
    scanf("%d ", &A[i]);
    --A[i];
    preMod[i] = add(preMod[i-1], A[i],k);
    if(i-k>=0) {
      --num[preMod[i-k]];
    }
    if(num.count(preMod[i])) {
      ret += num[preMod[i]];
    }
    ++num[preMod[i]];
  }
  printf("%lld\n", ret);
}

int main() {
  //freopen("input.txt","r",stdin);
  solve();
  return 0;
}


Measured memory_bytes: 11136
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int main(){
    int n,m;
    cin>>n>>m;
    for(int i=m/n;i>=0;i--){
        int x=m-i*(n-1);
        if(x%i==0){
            cout<<i<<endl;
            return 0;
        } 
    }
} 


Measured memory_bytes: 3612
s = input()

if s[0] == s[1] != s[2] == s[3] :
	print("Yes")
elif s[0] == s[2] != s[1] == s[3]:
	print("Yes")
elif s[0] == s[3] != s[2] == s[1]:
	print("Yes")
else:
	print("No")	

Measured memory_bytes: 3064
# -*- coding: utf-8 -*-

while True:
    n = input().split()
    if n[1] == '+':
        print(int(n[0]) + int(n[2]))
    elif n[1] == '-':
        print(int(n[0]) - int(n[2]))
    elif n[1] == '*':
        print(int(n[0]) * int(n[2]))
    elif n[1] == '/':
        print(int(n[0]) // int(n[2]))
    else:
        break


Measured memory_bytes: 5604
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int price = 700;
        String order = sc.next();
        if(order.substring(0,1).equals("o")) {
            price +=100;
        }
        if(order.substring(1,2).equals("o")) {
            price +=100;
        }
        if(order.substring(2,3).equals("o") ){
            price +=100;
        }
        
        System.out.println(price);
    }
}


Measured memory_bytes: 21844
#include<iostream>
using namespace std;
int main(){
int i;
cin >> i;
int a[i];
int j;
for(j=0;j<i;j++){
cin >> a[j];
}
int b[i];
int k;
k=i/2;
int n;
n=i-1;
if(i==1){
b[0]=a[0];
}
else if((i%2)==1){
for(j=0;j<k;j++){
b[j]=a[n];
n=n-2;
}
int s;
s=j;
b[s]=a[0];
s++;
n=1;
for(j=0;j<k;j++){
b[s]=a[n];
n=n+2;
s++;
}
}
else{
for(j=0;j<k;j++){
b[j]=a[n];
n=n-2;
}
int s;
s=j;
b[s]=a[0];
s++;
n=2;
for(j=0;j<k-1;j++){
b[s]=a[n];
s++;
n=n+2;
}
}
for(j=0; j<i ; j++){
cout << b[j] <<" ";
}
return 0;
}

Measured memory_bytes: 3712
x,y,a,b,c=gets.split.map(&:to_i)
p=gets.split.map(&:to_i)
q=gets.split.map(&:to_i)
r=gets.split.map(&:to_i)
a=p.max(x)+q.max(y)+r
puts a.max(x+y).reduce(:+)


Measured memory_bytes: 31880
package main

import (
	"fmt"
)

func main() {
	n, m := ScanInt(), ScanInt()
	fmt.Println(Abs((n - 2) * (m - 2)))
}

func ScanInt() (i int) {
	fmt.Scan(&i)
	return
}

func Abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}


Measured memory_bytes: 512
import sys
import math

A,B,H,M = list(map(int, input().split()))

j = ((H + ( M / 60 )) / 12) * 360
h = M * 6

z_x_j = math.sin(math.radians(j)) * A
z_y_j = math.cos(math.radians(j)) * A
z_x_h = math.sin(math.radians(h)) * B
z_y_h = math.cos(math.radians(h)) * B

print(math.sqrt((z_x_j - z_x_h) ** 2 + (z_y_j - z_y_h) ** 2 ))

Measured memory_bytes: 9520
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        std::cin.tie(0);
        ios::sync_with_stdio(false);
        cout.precision(20);
    }
} fast;

/* define */
#define FOR(I, X, Y) for (long long(I) = (X); (I) < (Y); (I)++)
#define REP(I, X, Y) for (long long(I) = (Y)-1; (I) >= (X); (I)--)
#define ALL(X) (X).begin(), (X).end()
#define pb push_back
#define COUNT(V, X)                           \
    (upper_bound((V).begin(), (V).end(), X) - \
     lower_bound((V).begin(), (V).end(), X))
#define debug(x) cerr << #x << ':' << x << endl;
#define DEBUG(v)                             \
    {                                        \
        cerr << #v << ':';                   \
        for (auto xv : v) cerr << xv << ' '; \
        cerr << endl;                        \
    }
#define Yes(X) cout << (X ? "Yes" : "No") << endl;
#define YES(X) cout << (X ? "YES" : "NO") << endl;
#define ctoi(C) (C - '0')
#define pow2(x) ((long long)((long long)1 << x))

/* alias */
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using pi = pair<int, int>;
using pl = pair<long long, long long>;
template <typename T>
using PQ = priority_queue<T>;
template <typename T>
using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const long long dx[] = {1, 0, -1, 0};
const long long dy[] = {0, 1, 0, -1};
const long long dx8[] = {1, 1, 0, -1, -1, -1, 0, 1};
const long long dy8[] = {0, 1, 1, 1, 0, -1, -1, -1};
const long long dx9[] = {1, 1, 0, -1, -1, -1, 0, 1, 0};
const long long dy9[] = {0, 1, 1, 1, 0, -1, -1, -1, 0};
const int INF = 1000000007;
const long long LINF = 1000000000000000007;

/* func */
template <typename T1, typename T2>
inline bool chmin(T1 &a, const T2 &b) {
    if (a > b) a = b;
    return a > b;
}
template <typename T1, typename T2>
inline bool chmax(T1 &a, const T2 &b) {
    if (a < b) a = b;
    return a < b;
}
long long max(long long x, int y) {
    return max(x, (long long)y);
}
long long max(int x, long long y) {
    return max((long long)x, y);
}
long long min(long long x, int y) {
    return min(x, (long long)y);
}
long long min(int x, long long y) {
    return min((long long)x, y);
}

/* library */

/* main */

signed main() {
    ll N;
    cin >> N;
    vl A(N);
    for (auto &x : A) cin >> x;
    ll SUM = 0;
    for (auto x : A) SUM += x;
    vl d(N);
    FOR(i, 0, N) {
        d[i] = A[(i + 1) % N] - A[i];
    }
    vl ans(N, 0);
    FOR(i, 0, N) {
        if (i % 2 == 0) ans[(i + 2) % N] = ans[i] + d[i] * 2;
    }
    FOR(i, 0, N) {
        if (i % 2 == 1) ans[(i + 2) % N] = ans[i] + d[i] * 2;
    }
    ll SUM2 = 0;
    for (auto x : ans) SUM2 += x;
    assert((SUM - SUM2) % N == 0);
    for (auto x : ans) cout << x + (SUM - SUM2) / N << ' ';
}

Measured memory_bytes: 3712
#include <stdio.h>
int main(){
	int i,n,x,l,count,d;
	if(scanf("%d%d",&n,&x)==-1){
		return 1;
	};
	count=1;
	d=0;
	while(scanf("%d",&l)!=-1){
		if(d+l<=x){
			count+=1;
			d=d+l;
		}
		else{
			break;
		}
	}
	printf("%d",count);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#define llint long long

using namespace std;

string s;
string head, tail;
llint Q;

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

	cin >> s;
	cin >> Q;
	
	llint t;
	bool flip = false; llint f; char c;
	for(int q = 0; q < Q; q++){
		cin >> t;
		if(t == 1){
			flip = !flip;
		}
		else{
			cin >> f >> c;
			if(flip){
				if(f == 1) f = 2;
				else f = 1;
			}
			if(f == 1) head += c;
			else tail += c;
		}
	}
	reverse(head.begin(), head.end());
	
	string ans = head + s + tail;
	if(flip) reverse(ans.begin(), ans.end());
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 1300
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,K;
  int sum = 1;
  cin >> N >> K;
  for (int i = 0; i < N; i++) {
    if (sum * 2 <= sum + K ) sum = sum * 2;
    else sum = sum + K;
  }
  cout << sum << endl;  
}

Measured memory_bytes: 3620
#include<stdio.h>
int main(void)
{
	int N,h[10],i,n,f,a,k;
	char c;
	scanf("%d",&N);
	while(N!=0){
		for(i=0;i!=10;i++){
			h[i]=0;
		}
		f=0;
		for(i=1;i!=102;i++){
			n=i%N;
			scanf("%1c",&c);
			switch(c){
				case 'M':
				h[n]+=1;
				break;
				case 'S':
				f+=h[n]+1;
				h[n]=0;
				break;
				case 'L':
				h[n]+=f+1;
				f=0;
				break;
			}
		}
		for(i=0;i!=N;i++){
			for(a=i;a!=N;a++){
				if(h[i]>h[a]){
					k=h[i];
					h[i]=h[a];
					h[a]=k;
				}
			}
		}
		for(i=0;i!=N;i++){
			printf("%d ",h[i]);
		}
		printf("%d\n",f);
		scanf("%d",&N);
	}
	return 0;
}

Measured memory_bytes: 1028
import sys
import numpy as np
from collections import Counter
s=input()
t=input()
s1=set(s)
t1=set(t)
if s==t:
    print('Yes')
    sys.exit()
qu2=[]
if len(s1)==len(t1):
    for i in s1:
        if s.count(i)>1:
            qu=[j for j,e in enumerate(s) if e==i]
            for j in qu:
                j=int(j)
                qu2.append(t[j])
            qu3=set(qu2)
            if len(qu3)!=1:
                print('No')
                sys.exit()
            else:
                qu3.clear()
        qu2=[]
        qu=[]
    print('Yes')
elif len(s1)!=len(t1):
    print('No')


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

ll N,M;
ll mo=1000000007;

ll modpow(ll a, ll n) {
	ll r=1;
	while(n) r=r*((n%2)?a:1)%mo,a=a*a%mo,n>>=1;
	return r;
}

ll comb(int P_,int Q_) {
	if(P_<0 || Q_<0 || Q_>P_) return 0;
	ll p=1,q=1;
	Q_=min(Q_,P_-Q_);
	for(int i=1;i<=Q_;i++) p=p*P_%mo, q=q*i%mo,P_--;
	
	return p*modpow(q,mo-2)%mo;
}

ll hcomb(int P_,int Q_) { return (P_==0&&Q_==0)?1:comb(P_+Q_-1,Q_);}

map<ll,int> enumpr(ll n) {
	map<ll,int> V;
	
	for(int i=2;i*i<=n;i++) {
		while(n%i==0) {
			V[i]++;
			n/=i;
		}
	}
	if(n>1) V[n]++;
	return V;
}


void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M;
	auto V=enumpr(M);
	ll ret=1;
	FORR(v,V) {
		ret=ret*hcomb(N,v.second)%mo;
	}
	cout<<ret<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 256
/*****Here we go again!******/

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

#define pi 3.1415926535
#define endl "\n"
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define ll long long
#define llu unsigned long long
#define setbits(x) __builtin_popcountll(x)
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define tc int test_case; cin >> test_case; while(test_case--)
#define f(i,a,n) for(int i = a ; i < n ; i++)
#define rf(i,n,a) for(int i = n-1 ; i >= a ; i--)
#define F first
#define S second
#define all(c) (c).begin(),(c).end()
#define get(a,n) f(i,0,n) cin >> a[i];
#define show(a,n) f(i,0,n) cout << a[i] << " "; cout << endl;
#define sp(x) fixed << setprecision(10) << x
#define fast ios:: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define trace(x) cerr << '>' << #x << ':' << (x) << "\n"
#define trace2(x,y) cerr<< '>' << #x << ':' << (x) << " | " << #y << ':' << (y) << "\n"
#define trace3(a,b,c) cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<"\n"
#define trace4(a,b,c,d) cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<", "<<#d<<"="<<(d)<<"\n"

typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<pii,int> ppi;
typedef vector<pii> vpi;
typedef map<int,int> mii;
typedef map<ll,ll> mll;

const int inf = 1e9;
const ll inf64 = 1e18;
const int mod = inf + 7;
const int N = 2e5 + 10;

ll dp[105][N];

int main()
{
    fast;
    int n, k;
    cin >> n >> k;
    vi a(n+1);
    f(i,1,n+1) cin >> a[i];

    dp[0][0] = 1;
    f(i,1,k+1)
        dp[0][i] = 0;

    f(i,1,n+1)
    {
        vi sum(k+1);
        sum[0] = dp[i-1][0];
        f(j,1,k+1)
            sum[j] = (sum[j-1] + dp[i-1][j]) % mod;
        f(j,0,k+1)
        {
            if(j <= a[i])
                dp[i][j] = sum[j];
            else
                dp[i][j] = (sum[j] - sum[j - a[i] - 1] + mod) % mod;
        }
//        sum.clear();
    }
    cout << dp[n][k];
}


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

using namespace std;

int main() {
  int N, N_digits_sum = 0;
  
  cin >> N;
  
  int N_used = N;
  
  while (N_used != 0) {
    N_digits_sum += N_used % 10;
    N_used /= 10;
  }
  
  cout << (N % N_digits_sum == 0 ? "Yes" : "No") << endl;
  
  return 0;
}

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

int main(void){
	int a,b; //number of road

	while(std::cin >> a >> b){ //input road
		if(a == 0 && b == 0) //end of input
			break;

		//make matrix a x b
		int path[a+1][b+1];
		int array[a+1][b+1];

		for(int i = 0; i <= a; ++i){
			for(int j = 0; j <= b; ++j){
				path[i][j] = 0;
				array[i][j] = 0;
			}
		}
		
		int num; //number of construction
		std::cin >> num;
		
		int x, y; //point of construction
		for(int i = 0; i < num; ++i){
			std::cin >> x >> y;
			//path[x-1][y-1] = 0;
			array[x][y] = 1;
		}


		for(int i = 1; i <= a; ++i){
			for(int j = 1; j <= b; ++j){
				if(i == 1 && j == 1 && array[i][j] == 0){
					path[i][j] = 1;
				} else if(array[i][j] == 1){
					path[i][j] = 0;

				} else {
					path[i][j] = path[i-1][j] + path[i][j-1];
				}
			}
		}
		
		std::cout << path[a][b] << std::endl; //output answer
	}
	return 0;
}

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Dice1
{
    class Program {
        static void Main( string[ ] args ) {

            string st1 = Console.ReadLine( );
            string[ ] dice = st1.Trim( ).Split( ' ' );

            string st2 = Console.ReadLine( );
            

            for( int i = 0 ; i < st2.Length ; i++ ) {
                char tmp = st2[ i ];
                dice = Diceroll( dice, tmp );

            }

            Console.WriteLine(dice[ 0 ] );
        }


        public static string [] Diceroll( string []input, char command ) {

            string []Dice = input;
            string tmp = "";

            switch( command ) {

                case 'S':
                    tmp = Dice[ 0 ];
                    Dice[ 0 ] = Dice[ 4 ];
                    Dice[ 4 ] = Dice[ 5 ];
                    Dice[ 5 ] = Dice[ 1 ];
                    Dice[ 1 ] = tmp;
                    
                    break;

                case 'N':
                    tmp = Dice[ 0 ];
                    Dice[ 0 ] = Dice[ 1 ];
                    Dice[ 1 ] = Dice[ 5 ];
                    Dice[ 5 ] = Dice[ 4 ];
                    Dice[ 4 ] = tmp;
                    break;

                case 'W':
                    tmp = Dice[ 0 ];
                    Dice[ 0 ] = Dice[ 2 ];
                    Dice[ 2 ] = Dice[ 5 ];
                    Dice[ 5 ] = Dice[ 3 ];
                    Dice[ 3 ] = tmp;
                    break;

                case 'E':
                    tmp = Dice[ 0 ];
                    Dice[ 0 ] = Dice[ 3 ];
                    Dice[ 3 ] = Dice[ 5 ];
                    Dice[ 5 ] = Dice[ 2 ];
                    Dice[ 2 ] = tmp;
                    break;
            }
           


            return ( Dice );

        }
    }

}



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

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    int cnt = 0;
    bool co = 0;

    while(b > 0 || c > 0 || a > 0){
        if(co == 0 && c > 0){
            co = 1;
            c -= 1;
            cnt++;
            if(b == 0 && a == 0) break;
        }
        if(c == 0){
            cnt += b;
            break;
        }
        
        if(co == 1 && b > 0){
            cnt++;
            co = 0;
            b -= 1;
            continue;
        }
        if(b == 0){
            co = 0;
            a--;
        
        }
        
    
    }
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
A = list(map(int, input().split()))
BC = [list(map(int, input().split())) for _ in range(M)]

A.sort()
BC.sort(key=lambda x: -x[1])

idx = 0
X = [0] * N
for Bi, Ci in BC:
    for _ in range(Bi):
        if idx >= N: break
        X[idx] = Ci
        idx += 1
    #
    if idx >= N: break

ans = [None] * N
for i in range(N):
    ans[i] = max(A[i], X[i])

print(sum(ans))

Measured memory_bytes: 36088
H,N = gets.split.map(&:to_i)
abs = []
N.times do
  ab = gets.split.map(&:to_i)
  abs << ab
end

arr = Array.new(H+1,100000000)
arr[0] = 0
i = 0
while i <= H
  j = 0
  while j < N
    a,b = abs[j]
    n = (i-a < 0 ? 0 : arr[i-a]) + b
    arr[i] = n if n < arr[i]
    j += 1
  end
  i += 1
end

p arr[H]


Measured memory_bytes: 1916
import heapq

N, M = map(int, input().split())

# [0日後(今日), 1日後, ..., M-1日後]
jobs = [[] for _ in range(M)]
for i in range(N):
    a, b = map(int, input().split())
    if M - a >= 0:
        jobs[M - a].append(b)

ans = 0
q = []

# M-1日後にできる仕事, ..., 1日後, 0日後
# A >= 1なのでM日後にできる仕事はない

# heappop()で出てくるのは最小値
# 最大値が欲しい場合は-1倍してpush(), pop()して-1倍

# i = M-1, M-2, ..., 1, 0
for i in range(M - 1, -1, -1):
    for values in jobs[i]:
        heapq.heappush(q, -1 * values)
    if len(q) > 0:
        ans += heapq.heappop(q) * (-1)

print(ans)


Measured memory_bytes: 89108
import numpy as np
T=[]
T=list(input())
values = np.array(T)
searchval = '?'
ii = np.where(values == searchval)[0]

if len(ii)>0:
    for k in ii:
        if k==0:
            if len(T)>1:
                if T[k+1]=='D':
                    T[k]='P'
                else:
                    T[k]='D'
            else:
                T[k] = 'D'

        else:
            if T[k-1] == 'P':
                T[k] = 'D'
            else:
                if k+1<len(T):
                    if T[k+1] == 'D':
                        T[k] = 'P'
                    else:
                        T[k]='D'
                else:
                    T[k] = 'D'

newT=''.join(map(str,T))
print(newT)

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

int main() {
  string s, ans = "Yes";
  cin >> s;
  int n = s.size();
  if(n % 2 == 0) {
    for(int i = 0; i*2 < n; i++) {
      if (s.at(i*2) == 'L') ans = "No";
      if (s.at(i*2+1) == 'R') ans = "No";
    }
  }
  else {
    if (s.at(0) == 'L') ans = "No";
    for(int i = 0; i*2 < n-2; i++) {
      if (s.at(i*2+1) == 'R') ans = "No";
      if (s.at(i*2+2) == 'L') ans = "No";
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3616
#![allow(dead_code, unused_imports, unused_macros)]
use std::cmp::{max, min};
#[cfg(not(DBG))]
macro_rules! debug { ($($xs:expr),*) => () }
#[cfg(DBG)]
macro_rules! debug { ($($xs:expr),*) => { println!("{:?}", ($($xs),*))} }

fn read_line() -> Vec<String> {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).expect("Failed to read line");
    line.trim().split_whitespace().map(|s| s.to_string()).collect()
}
struct Reader { v: Vec<String>, n: usize }
impl Reader {
    fn new() -> Self { Reader { v: read_line(), n: 0 } }
    fn next<T: std::str::FromStr>(&mut self) -> T {
        if self.n == self.v.len() { self.v = read_line(); self.n = 0; }
        self.n += 1; self.v[self.n-1].parse().ok().unwrap()
    }
    fn nexts<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.next()).collect()
    }
}

fn gcd(x: u64, y: u64) -> u64 {
    if y == 0 { x } else { gcd(y, x%y) }
}

fn main() {
    let mut r = Reader::new();
    let n: i64 = r.next();
    let x: i64 = r.next();
    let d: i64 = r.next();

    if d == 0 {
        if x == 0 {
            println!("{}", 1);
        } else {
            println!("{}", n+1);
        }
        return;
    }

    let g = gcd(x.abs() as u64, d.abs() as u64);

    let x = x / g as i64 * (d / d.abs());
    let d = d / g as i64 * (d / d.abs());

    let mut left = vec![];
    let mut right = vec![];
    for m in 0..(n+1) {
        let k = (m - m%d) / d;
        left.push(m * (m-1) / 2 + k*x);
        right.push(m * (2*n as i64-m-1) / 2 + k*x + 1);
    }

    let mut ans = 0;
    for k in 0..min(n+1, d) {
        let mut vs = vec![];
        for i in (0..).map(|i| k + i * d).take_while(|&i| i <= n) {
            vs.push((left[i as usize], i));
            vs.push((right[i as usize], i+n+1));
        }

        vs.sort();

        let mut start = 1e18 as i64;
        let mut level = 0;
        for &(x, j) in vs.iter() {
            if j < n+1 {
                start = min(start, x);
                level += 1;
            } else {
                level -= 1;
                if level == 0 {
                    ans += x - start;
                    start = 1e18 as i64;
                }
            }
            //debug!(x, j, start, level, ans);
        }
    }

    println!("{}", ans);
}


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

int main(void){
    // Your code here!
     int n,a;
     cin>>n;
     a=n;
     vector <int>d(n);
     for(int i=0;i<n;i++){
         cin>>d[i];
     }
     sort(d.begin(),d.end());
     for(int i=0;i<n;i++){
         if(d[i]-d[i+1]==0){
             a --;
         }
     }
     cout<<a<<endl;
     
}


Measured memory_bytes: 256