akhauriyash/Code-Regression huggingface dataset:
/* last edited at 27.8.2015 by charis
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_2_B
*/

#include<iostream>
using namespace std;

void SelectionSort(int N, int A[], int C){
	for(int i=0; i<N; i++){
		int mini=i;
		for(int j=i; j<N; j++){
			if(A[j]<A[mini]) mini = j;
		}
		if(mini != i){
		int t=A[i]; A[i]=A[mini]; A[mini]=t;
		C++;
		}
	}
	for(int i=0; i<N-1; i++){
		cout << A[i] << " ";
	}	
	cout << A[N-1] << endl;
	cout << C << endl ;
}

int main(){
	int N;
	cin >> N;
	int A[N];
	for(int i=0; i<N; i++){
		cin >> A[i];
	}
	
	int C=0;
	SelectionSort(N, A, C);
	
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
//#include <unistd.h>
//#include <stdio.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll inf = 2147483647;
const ll INF = 1LL << 60;
const ll mod = 1000000007;
const ld pi = 3.14159265358;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
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 gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
//素数判定O(sqrt(N))
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}

ll fac[510000], finv[510000], inv[510000];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < 510000; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}

// 二項係数計算
ll COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
//nのm乗をMODで割ったあまりO(logN)
ll modpow(ll n,ll m,ll MOD){
    ll res = 1;
    while(m){
        if(m & 1)res = (res * n) % MOD;
        m >>= 1;
        n *= n;
        n %= MOD;
    }
    return res;
}

//printf("%.10f\n", N);
/*  vector<ll> vec = {1,2,5,6,8,9,10};
    cout << binary_search(all(vec),5) << endl; -> true*/
/*
    vector<ll> vec = {1,2,5,6,8,9,10};
    auto n = upper_bound(all(vec),4);
    cout << *n << endl; -> 5*/

//    cout << fixed << setprecision(15);
const ll MAX = 100000;
ll par[MAX];
ll ran[MAX];
void init(ll n){
    rep(i,n){
        par[i] = i;
        ran[i] = 0;
    }
}
ll find(ll x){
    if(x == par[x])return x;
    else return par[x] = find(par[x]);
}
void unite(ll x,ll y){
    x = find(x);
    y = find(y);
    if(x == y)return;
    if(ran[x] < ran[y]){
        par[x] = y;
    }
    else{
        par[y] = x;
        if(ran[x] == ran[y])ran[x]++;
    }
}
bool same(ll x,ll y){
    return find(x) == find(y);
}
ll size(ll x){
    return ran[find(x)];
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll N;
    cin >> N;
    cout << N << ":";
    ll n = N;
    for(ll i = 2;i * i <= N;i++){
        while(n % i == 0){
            cout << " " << i;
            n /= i;
        }
    }
    if(n != 1)cout << " " << n;
    cout << "\n";
}


Measured memory_bytes: 3236
import sys


def main():
    n = int(sys.stdin.readline().strip())
    d = [int(s) for s in sys.stdin.readline().strip().split()]

    ans = 0
    for i in range(n-1):
        for j in range(i+1, n):
            ans += d[i] * d[j]
    print(ans)



main()


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

int main() {
  int W, a, b; cin >> W >> a >> b;
  if(b < a ) {
    cout << a - ( b + W ) << endl;
  } else if( a + W < b ) {
    cout << b - (a + W) << endl;
  } else{
    cout << 0 << endl;
  }

  return 0;
}


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

int main(){
  int N, K;
  cin >> N >> K;
  vector<int> a;
  for(int i = 0; i < N; i++){
    int n;
    cin >> n; 
    a.push_back(n);
  }
  sort(a.begin(), a.end());
  int ans = 0;
  for(int i = 0; i < K; i++){
    ans = a.at(i) + ans;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3632
N=int(input())
xy=list(sorted([list(map(int, input().split())) for _ in range(N)]))

if N==1:
    print(1)
    exit(0)
diff={}
for i in range(N):
    for j in range(i+1, N):
        a=(xy[i][0]-xy[j][0], xy[i][1]-xy[j][1])
        diff[a]=diff.get(a,0)+1
print(N-max(diff.values()))

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
using ll =long long;
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SORT(i) sort((i).begin(),(i).end())
constexpr int INF = 2000000000;
constexpr int mod = 1000000007;

int main() {
	int N; cin >> N;
	map<int, int>mp;
	rep(i, N) {
		int a;cin >> a;
		mp[a]++;
	}
	int ans = mp.size();
	for (auto p : mp) {
		if (p.second % 2 == 0)--ans;
	}
	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 4864
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main(void) {
  int N;
  cin >> N;
  vector<int> v(N);
  for (auto &u : v) {
    cin >> u;
  }

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

  double a = v[0];

  for (int i = 1; i < N; ++i) {
    a = (a + double(v[i])) / 2.0;
  }

  cout << a << endl;

  return 0;
}


Measured memory_bytes: 3764
#include <bits/stdc++.h>
using namespace std;int p[1024][100001],v[323456],w[323456],q,a,l,i;int f(int a,int l){if(l<0)return -1e9;if(!a)return 0;if(a>1023)return max(f(a/2,l),f(a/2,l-w[a])+v[a]);if(~p[a][l])return p[a][l];return p[a][l]=max({f(a/2,l),f(a,l-1),f(a/2,l-w[a])+v[a]});};int main(){memset(p,-1,sizeof(p));cin>>l;for(;i++<l;)cin>>v[i]>>w[i];cin>>q;while(q--){cin>>a>>l;cout<<f(a,l)<<" ";}}

Measured memory_bytes: 413464
A, B, C, X, Y = map(int, input().split())
minv = A*X + B*Y

tmp = C*X*2
if X > Y:
    minv = min(minv, tmp)
else:
    minv = min(minv, tmp+(Y-X)*B)

tmp = C*Y*2
if Y > X:
    minv = min(minv, tmp)
else:
    minv = min(minv, tmp+(X-Y)*A)
print(minv)


Measured memory_bytes: 3060
// AOJ Volume2 0277

#include <stdio.h>

int main(void)
{
    int t, n;
    int fee[4];
    int i;
    
    fee[0] = 6000;
    fee[1] = 4000;
    fee[2] = 3000;
    fee[3] = 2000;
    
    
    for (i = 0; i < 4; i++){
        scanf("%d%d", &t, &n);
        printf("%d\n", n * fee[t - 1]);
    }

    
    return (0);
}

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

int main() {
	int n, m, a[55], b[55], c[55];
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
	    cin >> a[i] >> b[i];
	}
  	for (int i = 0; i < n; i++) c[i] = 0;
	for (int i = 0; i < n; i++) {
	    for (int j = 0; j < m; j++) {
	        if (a[j] == i + 1) c[i]++;
	        if (b[j] == i + 1) c[i]++; 
	    }
	    cout << c[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 256
module PArray = struct
  type 'a t = 'a data ref
  and 'a data = Arr of 'a array | Diff of int * 'a * 'a t

  let init n f = ref (Arr (Array.init n f))
  let make n v = ref (Arr (Array.make n v))
  let of_list l = ref (Arr (Array.of_list l))

  let rec reroot k = function
    | { contents = Arr a } -> k a
    | { contents = Diff (i, v, t') } as t ->
        reroot (fun a ->
          t' := Diff (i, a.(i), t);
          a.(i) <- v;
          k a) t'
  let reroot k = function
    | { contents = Arr a } -> k a
    | { contents = Diff (_, _, _) } as t ->
        reroot (fun a -> t := Arr a; k a) t

  let rec get t i = reroot (fun a -> a.(i)) t

  let set t i v =
    reroot (fun a ->
      if v = a.(i) then t
      else begin
        let result = ref (Arr a) in
        t := Diff (i, a.(i), result);
        a.(i) <- v;
        result
      end) t

  let length t = reroot Array.length t
  let to_list t = reroot Array.to_list t
  let iter f = reroot (Array.iter f)
  let iteri f = reroot (Array.iteri f)
  let fold_left f x = reroot (Array.fold_left f x)
  let fold_right f t x = reroot (fun a -> Array.fold_right f a x) t
end

module PUnionFind = struct
  type t = { rank : int PArray.t; mutable parent : int PArray.t }

  type class_ = int

  let make n = { rank = PArray.make n 0; parent = PArray.init n (fun i -> i) }

  let rec find parent i k =
    let j = PArray.get parent i in
    if i = j then k parent i
    else find parent j (fun parent r -> k (PArray.set parent i r) r)
  let find ({ parent } as h) i = find parent i (fun parent r ->
    h.parent <- parent;
    r)

  let union uf x y =
    let cx = find uf x in
    let cy = find uf y in
    if cx = cy then uf
    else begin
      let rx = PArray.get uf.rank x in
      let ry = PArray.get uf.rank y in
      match compare rx ry with
      | -1 -> { uf with parent = PArray.set uf.parent cx cy }
      | 1 -> { uf with parent = PArray.set uf.parent cy cx }
      | 0 -> { rank = PArray.set uf.rank cx (cx + 1); parent = PArray.set uf.parent cy cx }
    end
end

let () =
  let n = Scanf.scanf "%d\n" @@ fun n -> n in
  let xys = Array.to_list @@ Array.init n @@ fun i ->
    Scanf.scanf "%d %d\n" @@ fun x y -> x, y, i in
  let xedges =
    List.sort (fun (x, _, _) (x', _, _) -> compare x x') xys
    |> (fun ((x, y, i) :: xys) ->
        List.fold_left (fun (acc, x, y, i) (x', y', j) ->
          ((x' - x, i, j) :: acc, x', y', j)) ([], x, y, i) xys)
    |> (fun (acc, _, _, _) -> acc) in
  let yedges =
    List.sort (fun (_, y, _) (_, y', _) -> compare y y') xys
    |> (fun ((x, y, i) :: xys) ->
        List.fold_left (fun (acc, x, y, i) (x', y', j) ->
          ((y' - y, i, j) :: acc, x', y', j)) ([], x, y, i) xys)
    |> (fun (acc, _, _, _) -> acc) in
  List.rev_append xedges yedges
    |> List.sort (fun (d, _, _) (d', _, _) -> compare d d')
    |> List.fold_left (fun (cost, connection) (d, i, j) ->
        if PUnionFind.find connection i = PUnionFind.find connection j then (cost, connection)
        else (d + cost, PUnionFind.union connection i j)) (0, PUnionFind.make n)
    |> fst
    |> Printf.printf "%d\n"

Measured memory_bytes: 34700
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007 

ll a[100010];

ll dep(ll t, ll r){
	if(r==0){
		return t;
	}
	dep(r,t%r);
}

int main() {
	ll n,x;
	cin>>n>>x;
	for(int i=0;i<n;i++){
		ll z;
		cin>>z;
		ll now=abs(z-x);
		a[i]=now;
	}
	ll ans=0;
	for(int i=0;i<n;i++){
		ans=dep(max(ans,a[i]),min(ans,a[i]));
	}
	cout <<ans;
	return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>

#define BUFSIZE (int)1e5+1 //10^5+1
#define BUFASCII 128

/// 与えられた手に勝つ手を返す関数。
char win_rsp(char hand){
    if(hand == 'r') return 'p';
    if(hand == 's') return 'r';
    if(hand == 'p') return 's';
    return '0';
}

int main(void){
    int N, K, R, S, P;
    char T[BUFSIZE];
    char showed[BUFSIZE]; // 出した手をメモする配列
    int i;
    int point[BUFASCII]; // 点数をメモする配列
    long long int ans = 0;


    scanf("%d %d", &N, &K);
    scanf("%d %d %d", &R, &S, &P);
    scanf("%s", T);

    // 文字を添字として使用。

    /*　？何故配列の添え字に文字を使用できるのか？について知らない場合読んで
    文字は数字と対応している
    printf("%c\n", 97); とするとアルファベット'a'が出力される
    10進数で'r' == 114, 's' == 115, 'p' == 112　である。
    詳しくはASCIIコードとか調べて分からなかったら教授に聞くといいかも
    */

    point['r'] = R;
    point['s'] = S;
    point['p'] = P;

    for(i = 0; i < N; i++){
        showed[i] = win_rsp(T[i]); // とりあえず勝つ手を出したい

        if(showed[i] == '0'){ // なんかミスってたら
            printf("error!\n");
            return 0;
        }

        if(i < K){ // K回目未満のとき
            ans += point[showed[i]];
        }else{ // K回目以上のとき
            if(showed[i] == showed[i-K]){ // K回前も同じ手を出していたら
                showed[i] = '0'; // K回前と違う手を出す
            }else{ // K回前に違う手を出していたら
                ans += point[showed[i]];
            }
        }
    }

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

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define MAX 524300
#define reg register

using namespace std;

int n, upp;
int stk[MAX / 2], top;

struct BST {
	int root, totNd;
	int fa[MAX], ch[MAX][2], val[MAX], rec[MAX], size[MAX];
	inline int cre_node(int _val) {
		val[++totNd] = _val, size[totNd] = rec[totNd] = 1;
		return totNd;
	}
	inline void link(int u, int f, bool ind) {
		fa[u] = f, ch[f][ind] = u;
		return;
	}
	inline void upd(int u) {
		size[u] = rec[u] + size[ch[u][0]] + size[ch[u][1]];
		return;
	}
	inline void rotate(int u) {
		int f = fa[u], g = fa[f]; bool ind = ch[f][1] == u;
		link(ch[u][ind ^ 1], f, ind), link(f, u, ind ^ 1), link(u, g, ch[g][1] == f);
		upd(f), upd(u);
		return;
	}
	inline void splay(int u, int tar = 0) {
		int f = fa[u], g;
		while(f != tar) {
			g = fa[f];
			if(g != tar)
				rotate( (ch[g][1] == f) ^ (ch[f][1] == u) ? u : f );
			rotate(u), f = fa[u];
		}
		if(!tar) root = u;
	}
	void insert(int _val) {
		int u = root, f = 0;
		while(u && val[u] != _val) f = u, u = ch[u][_val > val[u]];
		if(u) {
			++rec[u], ++size[u];
		} else {
			u = cre_node(_val);
			link(u, f, _val > val[f]);
		}
		splay(u);
	}
	int find(int _val) {
		int u = root;
		while(val[u] != _val) u = ch[u][_val > val[u]];
		return u;
	}
	int pre(int _val) {
		int u = find(_val); splay(u);
		u = ch[u][0];
		while(ch[u][1]) u = ch[u][1];
		return u;
	}
	int suf(int _val) {
		int u = find(_val); splay(u);
		u = ch[u][1];
		while(ch[u][0]) u = ch[u][0];
		return u;
	}
	void del(int _val) {
		int u = find(_val); splay(u);
		if(rec[u] > 1) --rec[u], --size[u];
		else {
			int p = pre(_val), s = suf(_val);
			splay(p), splay(s, p);
			ch[s][0] = 0, fa[u] = 0;
			upd(s), upd(p);
		}
		return;
	}
	void init() {
		insert(INT_MIN), insert(INT_MAX);
		return;
	}
}lsk;

inline int Rd() {
	int x = 0; char ch = getchar();
	while(ch < '0' || ch > '9') ch = getchar();
	while(ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
	return x;
}

int main() {
	//extra_test();
	n = Rd(), upp = 1 << n;
	lsk.init();
	for(reg int i = 1; i <= upp; ++i) lsk.insert(Rd());
	stk[++top] = lsk.val[lsk.pre(INT_MAX)], lsk.del(stk[top]);
	for(reg int i = 1; i <= n; ++i) {
		int tp = top;
		for(reg int j = 1; j <= tp; ++j) {
			lsk.insert(stk[j]);
			stk[++top] = lsk.val[lsk.pre(stk[j])];
			lsk.del(stk[j]);
			if(stk[top] == INT_MIN) {
				puts("No");
				return 0;
			}
			lsk.del(stk[top]);
		}
	}
	puts("Yes");
	return 0;
}

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

int main(void){
    int N;
    scanf("%d",&N);
    char s[N][11];
    int i,j,k;
    long long c[5]={0,0,0,0,0};
    for(i=0;i<N;i++){
        scanf("%s",s[i]);
        if(s[i][0]=='M'){
            c[0]++;
        }else if(s[i][0]=='A'){
            c[1]++;
        }else if(s[i][0]=='R'){
            c[2]++;
        }else if(s[i][0]=='C'){
            c[3]++;
        }else if(s[i][0]=='H'){
            c[4]++;
        }
    }
    long long ans = 0;
    for(i=0;i<3;i++){
        for(j=i+1;j<4;j++){
            for(k=j+1;k<5;k++){
                ans += c[i]*c[j]*c[k];
            }
        }
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 1280
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;

typedef long long ll, lint;
typedef long double ldouble;

#define sz(v) ((int) (v).size())
#define FOR(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define For(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define all(v) (v).begin(), (v).end()

#define mp make_pair
#define pb push_back
#define fst first
#define snd second

template<class T>
string to_string(T arr, int len = 1e9) {
    stringstream ss;
    int i = 0;
    for (auto item : arr) {
        ss << item << ' ';
        if (++i == len)
            break;
    }
    return ss.str();
}

#ifdef LOCAL
    #define dbg(expr) cout << "[line " << __LINE__ << "] " << (#expr) << ": " << (expr) << endl;
#else
    #define dbg(expr) (void) 0;
#endif


int main() {
#ifndef LOCAL
    cin.tie(0);
    ios_base::sync_with_stdio(false);
#endif

    lint a, b, c;
    cin >> a >> b >> c;
    lint x, y;
    cin >> x >> y;
    lint min_val = x * a + b * y;
    For (i, max(x, y) + 1) {
        lint left_a = max(0ll, x - i);
        lint left_b = max(0ll, y - i);
        lint cost = c * 2 * i + left_a * a + left_b * b;
        min_val = min(min_val, cost);
    }
    cout << min_val << endl;
}

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

#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
using namespace std;
#define int long long
//for set
// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;   
// for multiset
typedef tree<
pair<int, int>,
null_type,
less<pair<int, int>>,
rb_tree_tag,
tree_order_statistics_node_update> ordered_multiset;

#define ff first
#define ss second
#define endl "\n"
#define all(x) (x).begin(), (x).end()
#define PI 3.1415926535897932384626433832795
int MOD=1e9+7;
int powmod(int a,int l, int md){int res=1;while(l){if(l&1)res=res*a%md;l/=2;a=a*a%md;}return res;}
int binpow(int a,int l){int res=1;while(l){if(l&1)res=res*a;l/=2;a=a*a;}return res;}
typedef long long ll; typedef vector<ll> vi; typedef pair<ll, ll> ii; typedef vector<ii> vii;
#define pb push_back
int __set(int b, int i) {return b|(1<<i);} //set ith bit
int __unset(int b, int i) {return b&(~(1UL<<i));}
int __check(int b, int i) {return b&(1<<i);} //returns 0 if ith bit is 0
int mulmod(int a, int b, int md) {return ((a%md)*(b%md))%md;}
int addmod(int a, int b, int md) {return (a+b)%md;}
int submod(int a, int b, int md) {return (((a-b)%md)+md)%md;}
int divmod(int a, int b, int md) {return mulmod(a, powmod(b, md-2, md), md);} //if md is prime;
const ll inf = 0xFFFFFFFFFFFFFFFL; //very large number
priority_queue<int, vector<int>, greater<int> > pq; //for min priority_queue
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
clock_t time_p=clock();
void time()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}

const int SZ = 50;
struct matrix
{
	int arr[SZ][SZ];

	void reset() {
		memset(arr, 0, sizeof(arr));	
	}

	void makeiden() {
		reset();
		for(int i=0;i<SZ;i++) {
			arr[i][i] = 1;
		}
	}

	matrix operator + (const matrix &o) const {
		matrix res;
		for(int i=0;i<SZ;i++) {
			for(int j=0;j<SZ;j++) {
				res.arr[i][j] = (arr[i][j]+o.arr[i][j])%MOD;
			}
		}
		return res;
	}

	matrix operator * (const matrix &o) const {
		matrix res;
		for(int i=0;i<SZ;i++) {
			for(int j=0;j<SZ;j++) {
				res.arr[i][j] = 0;
				for(int k=0;k<SZ;k++) {
					res.arr[i][j] = (res.arr[i][j] + (arr[i][k]*o.arr[k][j])%MOD)%MOD;
				}
			}
		}
		return res;
	}
};

matrix power(matrix a, int b) {
	matrix res;
	res.makeiden();
	while(b) {
		if(b & 1) {
			res = res * a;
		}
		a = a * a;
		b >>= 1;
	}
	return res;
}

int32_t main(void)
{
	IOS;
	int n,k; cin>>n>>k;
	matrix m;
	m.reset();
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < n; j++) {
			int w; cin>>w;
			m.arr[i][j]=w;
		}
	}
	m = power(m,k);
	int ans=0;
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < n; j++) {
			ans += m.arr[i][j];
			ans %= MOD;
		}
	}
	cout<<ans<<endl;
	time();	
	return 0;
}

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

using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < (n); ++i)
double const PI = 3.1415926535897932384626433;
using P = pair<int, int>;

int main() {
    string s1, s2, s3;
    cin >> s1 >> s2 >> s3;
    cout << s1[0] << s2[1] << s3[2] << endl;
    return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define CLR(a) memset(a, 0, sizeof(a))
#define DBG(x) cout<<(#x)<<"="<<x<<endl
#define FOR(i, a, b)  for(int i=(a); i<(b); i++)
#define REP(i, a, b)  for(int i=(a); i<=(b); i++)
#define DOWN(i, a, b) for(int i=(a); i>=(b); i--)

using namespace std;

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

const double eps = 1e-8;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const ll mod = 1000000009;
const int N= 1e3 +10;

int n;
int ans=INF;

int digit(int n) {
	int ret=0;
	while(n) {
		ret+=n%10;
		n/=10;
	}
	return ret;
}

int main() {
	cin>>n;
	REP(i, 1, n-1) {
		ans=min(ans, digit(i)+digit(n-i));
	}
	cout<<ans<<endl;
	//cout<<1.*clock()/CLOCKS_PER_SEC<<"ms"<<"\n";
	return 0;
}

Measured memory_bytes: 764
#include <algorithm>
#include <iostream>
#include <limits.h>
#include <string>
#include <vector>

#define el endl
#define fd fixed
#define INF INT_MAX/2-1

using namespace std;

int main() {
  int n, m, sum_t, sum_h, dif, res_t, res_h;
  bool flag;
  while (cin >> n >> m, n | m) {
    vector<int> taro, hanako;
    int tmp;
    sum_t = 0;
    sum_h = 0;
    for (int i = 0; i < n; i++) {
      cin >> tmp;
      taro.push_back(tmp);
      sum_t += tmp;
    }
    for (int i = 0; i < m; i++) {
      cin >> tmp;
      hanako.push_back(tmp);
      sum_h += tmp;
    }
    flag = false;
    if (!((sum_t-sum_h) & 1)) {
      res_t = INF;
      res_h = INF;
      dif = sum_t - sum_h;
      for (int i = 0; i < taro.size(); i++) {
        for (int j = 0; j < hanako.size(); j++) {
          if (dif == 2*(taro[i] - hanako[j]) && taro[i] + taro[j] < res_t + res_h) {
            res_t = taro[i];
            res_h = hanako[j];
            flag = true;
          }
        }
      }
    }
    if (flag) cout << res_t << " " << res_h << el;
    else cout << "-1" << el;
  }
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
#include <vector>
#include <queue>
#include <set>
using namespace std;

int main(){
    int N,M;
    cin >> N;
    vector<string> S(N);
    for(int i=0; i<N; i++){
        cin >> S[i];
    }
    cin >> M;
    vector<string> T(M);
    for(int j=0; j<M; j++){
        cin >> T[j];
    }

    set<string> S2(S.begin(), S.end());

    int max_count = 0;
    for(string target : S2){
        int count =0;
        for(int i=0; i<N; i++){
            if(S[i] == target){count++;}
        }
        for(int i=0; i<M; i++){
            if(T[i] == target){count--;}
        }

        if(count > max_count ){max_count = count;}

    }

    cout << max_count << endl;
    return 0;


}

Measured memory_bytes: 3640
import java.util.Scanner;

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

    Scanner sc = new Scanner(System.in);

    String day = sc.next();
    int answer = 0;

    if(day.contains("SUN")){
      answer = 7;
    }else if(day.contains("SAT")){
      answer = 1;
    }else if(day.contains("FRI")){
      answer = 2;
    }else if(day.contains("THU")){
      answer = 3;
    }else if(day.contains("WED")){
      answer = 4;
    }else if(day.contains("TUE")){
      answer = 5;
    }else if(day.contains("MON")){
      answer = 6;
    }

    System.out.println(answer);

  }
}

Measured memory_bytes: 21716
N,M = list(map(int, input().split()))
p = []
s = []
for i in range(M):
  temp = list(map(str, input().split()))
  p_temp = int(temp[0])
  p.append(p_temp)
  s.append(temp[1])

ac_list = []
ac_num = 0
wa_num = 0
ques_list = []
wa_list = []
for i in range(N):
  ques_list.append(0)
  wa_list.append(0)

for i in range(M):
  if(s[i]=="AC" and ques_list[p[i]-1]==0):
    ac_num += 1
    ques_list[p[i]-1] = 1
  elif(s[i]=="WA" and ques_list[p[i]-1]==0):
    wa_list[p[i]-1] += 1
    
for i in range(N):
  if(ques_list[i]==1):
    wa_num += wa_list[i]
    
print(ac_num, wa_num)

Measured memory_bytes: 14976
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
#define rep(x,n) for(int x = 0 ; x < n ; x++)
#define all(c) (c).begin() , (c).end()
const ll INF = 1e9 + 7;
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    ll n, wt;
    cin >> n >> wt;
    vi w(n), val(n);
    rep(i,n)    cin >> w[i] >> val[i];
    ll value = accumulate(all(val), 0);
    vi dp(value + 1, INF);
    dp[0]=0;
    rep(i,n)
        for(int j = value; j >= val[i]; j--)
            dp[j] = min(dp[j], w[i] + dp[j - val[i]]);
    // Copied this part from markvoy
    cout << distance(find_if(rbegin(dp), rend(dp), [wt](auto x){return (x<=wt);}), rend(dp)) - 1 << endl;
    return 0;
}

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

struct Node {
    int key;
    Node *parent, *left, *right;
};

Node *root, *NIL;

Node *find(Node *u, int key) {
    while (u != NIL && u->key != key) {
        if (key < u->key) {
            u = u->left;
        } else {
            u = u->right;
        }
    }
    return u;
}

void insert(int key) {
    Node *x = root;
    Node *y = NIL;
    Node *z;

    z = (Node *)malloc(sizeof(Node));
    z->key = key;
    z->left = NIL;
    z->right = NIL;

    while (x != NIL) {
        y = x;
        if (z->key < x->key) {
            x = x->left;
        } else {
            x = x->right;
        }
    }

    z->parent = y;
    if (y == NIL) {
        root = z;
    } else {
        if (z->key < y->key) {
            y->left = z;
        } else {
            y->right = z;
        }
    }
}

Node *tree_minimum(Node *x) {
    while (x->left != NIL) {
        x = x->left;
    }
    return x;
}

Node *tree_successor(Node *x) {
    if (x->right != NIL) {
        return tree_minimum(x->right);
    }

    Node *y = x->parent;
    while (y != NIL && x == y->right) {
        x = y;
        y = y->parent;
    }
    return y;
}

void tree_delete(Node *z) {
    Node *y;
    Node *x;

    if (z->left == NIL || z->right == NIL) {
        y = z;
    }
    else {
        y = tree_successor(z);
    }


    if (y->left != NIL) {
        x = y->left;
    } else {
        x = y->right;
    }

    if (x != NIL) {
        x->parent = y->parent;
    }

    if (y->parent == NIL) {
        root = x;
    } else {
        if (y == y->parent->left) {
            y->parent->left = x;
        } else {
            y->parent->right = x;
        }
    }

    if (y != z) {
        z->key = y->key;
    }

    free(y);
}

void in_order(Node *u) {
    if (u == NIL)
        return;
    in_order(u->left);
    printf(" %d", u->key);
    in_order(u->right);
}

void pre_order(Node *u) {
    if (u == NIL)
        return;
    printf(" %d", u->key);
    pre_order(u->left);
    pre_order(u->right);
}

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

    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        if (s == "insert") {
            int x;
            cin >> x;
            insert(x);
        } else if (s == "find") {
            int x;
            cin >> x;
            if (find(root, x) != NIL)
                cout << "yes" << endl;
            else
                cout << "no" << endl;
        } else if (s == "delete") {
            int x;
            cin >> x;
            tree_delete(find(root, x));
        } else {
            in_order(root);
            cout << endl;
            pre_order(root);
            cout << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 21988
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int n;
  cin >> n;

  int ans = 0;
  rep(i, 0, n) {
    int a;
    cin >> a;
    while (!(a % 2)) {
      ans++;
      a /= 2;
    }
  }

  cout << ans << endl;
}


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

int dist;
vector<vector<int> > adj;
vector<bool> vis;
void dfs (int u) {
    vis[u] = true;
    dist++;
    for (auto v : adj[u]) {
        if (!vis[v]) {
            dfs(v);
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false), cin.tie(nullptr);
    int n, m;
    cin >> n >> m;
    adj.assign(n, {});
    vis.resize(n, false);
    
    for (int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        u--, v--;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    int ans = -1;
    for (int i = 0; i < n; i++) {
        if (!vis[i]) {
            dist = 0;
            dfs(i);
            ans = max(ans, dist);
        }     
    }
    cout << ans << "\n";
    return 0;
} 


Measured memory_bytes: 20288
m=10**9+7;L=input();N=len(L);a=0;o=0
for i in range(N):
 if L[i]=="1":
  a+=(pow(3,N-1-i,m)*pow(2,o,m))%m;a%=m;o+=1
a+=pow(2,o,m);a%=m;print(a)

Measured memory_bytes: 39920
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
using namespace std;

// vsをソートしたときnが何番目の要素になるかを返す
static int f(
    vector<int>::const_iterator begin,
    vector<int>::const_iterator end,
    int n)
{
    std::vector<int> vs(begin, end);
    sort(vs.begin(), vs.end());

    auto it = find(vs.begin(), vs.end(), n);
    return distance(vs.begin(), it);
}

static int lexicographical_index(
    vector<int>::const_iterator begin,
    vector<int>::const_iterator end,
    int N)
{
    if (N == 1)
    {
        return 0;
    }
    int pattern_num = 1;
    for (int i = 2; i <= N; ++i)
    {
        pattern_num *= i;
    }

    int index = f(begin, end, *begin) * pattern_num / N;

    return index + lexicographical_index(begin + 1, end, N - 1);
}

int main()
{
    fastio;
    int N;
    vector<int> Ps, Qs;
    cin >> N;
    copy_n(istream_iterator<int>(cin), N, back_inserter(Ps));
    copy_n(istream_iterator<int>(cin), N, back_inserter(Qs));

    auto p_index = lexicographical_index(Ps.cbegin(), Ps.cend(), N);
    auto q_index = lexicographical_index(Qs.cbegin(), Qs.cend(), N);

    cout << abs(p_index - q_index) << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int k;
  string s;
  vector<char> v;
  cin >> k >> s;
  if(s.length()<=k)
  {
    cout << s;
  }
  else
  {
    for(int i=0;i<k;i++)
    {
      v.push_back(s[i]);
    }
    for(int i=0;i<3;i++)
    {
      v.push_back('.');
    }
    for(int i=0;i<v.size();i++)
    {
      cout << v[i];
    }
  }
  return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define F first
#define S second

using namespace std;
typedef long long ll;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    vector<ll> a(n);
    for (int i = 0; i < n; ++ i) {
        cin >> a[i];
    }
    ll sum = 0;
    for (int i = 0; i < n; ++ i) {
        for (int j = i + 1; j < n; ++ j) {
            sum += a[i] * a[j];
        }
    }
    cout << sum;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define IOS                                                                    \
  ios::sync_with_stdio(0);                                                     \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<ll, ll>;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
ll bpow(ll b, ll p, ll m = 1000000007LL) {
  ll rt = 1;
  for (; p; p >>= 1, b = b * b % m)
    if (p & 1)
      rt = rt * b % m;
  return rt;
}
int main() {
  IOS;
  ll n;
  cin >> n;
  for (ll i = 1; i <= 3500; i++) {
    for (ll j = 1; j <= 3500; j++) {
      ll lhs = 4LL * i * j - n * j - n * i;
      if (lhs > 0 && n * i * j % lhs == 0) {
        cout << i << ' ' << j << ' ' << n * i * j / lhs << endl;
        return 0;
      }
    }
  }
}


Measured memory_bytes: 3684
#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()

using ll = long long;
using P = pair<int,int>;
using mp =  map<int,int>;

const int MOD = 1e9 + 7;

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


    int n;
    cin >> n;
    map<char, int> mp;
    rep(i, n){
        string s;
        cin >> s;
        if(s[0] == 'M' || s[0] == 'A' || s[0] == 'R' || s[0] == 'C' || s[0] == 'H'){
            mp[s[0]]++;
        }
    }

    ll ans = 0;
    for (auto& p : mp) {
        for (auto& q : mp) {
            for (auto& r : mp) {
                if(p.first != q.first && q.first != r.first && p.first != r.first){
                    ll x = p.second, y = q.second, z = r.second;
                    ans += x * y * z;
                    //cout << q.first << endl;
                }
            }
        }
    }

    cout << ans/6 << endl;

    return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
#define LEN 10
int main(void){
    // Your code here!
    int N,L[LEN];
    int max,sum=0;
    scanf("%d",&N);
    for(int i=0;i<N;i++){
        scanf("%d",&L[i]);
    }
    max=L[0];
    for(int i=1;i<N;i++){
        if(L[i]>max){
            sum += max;
            max=L[i];
        }else{
            sum += L[i];
        }
    }
    
    if(sum>max){
        printf("Yes");
    }else{
        printf("No");
    }
}


Measured memory_bytes: 128
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
using namespace std;
using LL = long long;

int N;
vector<pair<LL, LL>>rect;//first:left second:width

int main(void)
{
	cin >> N;
	for (int i = 0; i < N; ++i)
	{
		LL l, r;
		cin >> l >> r;
		rect.push_back({ l,r - l });
	}
	LL lefd = 0, rhtd = 0;
	multiset<LL>lef, rht;
	LL baseval = 0;
	for (int i = 0; i < N; ++i)
	{
		//minrangeする(i==0の時は無視)
		if (i > 0)
		{
			LL x = rect[i - 1].second;
			LL y = rect[i].second;
			lefd += y;
			rhtd += x;
		}
		//absをとる
		if (i == 0)
		{
			lef.insert(rect[i].first);
			rht.insert(rect[i].first);
		}
		else
		{
			//basevalを更新
			auto itr = lef.end();
			itr--;
			LL zlef = (*itr) - lefd;
			LL zrht = (*rht.begin()) + rhtd;
			if (zrht < rect[i].first)
			{
				baseval += rect[i].first - zrht;
			}
			else if (rect[i].first < zlef)
			{
				baseval += zlef - rect[i].first;
			}
			//setに導入する
			LL lim = (*rht.begin()) + rhtd;
			if (lim <= rect[i].first)
			{
				rht.insert(rect[i].first - rhtd);
				rht.insert(rect[i].first - rhtd);
				auto edge = rht.begin();
				LL val = (*edge) + rhtd;
				rht.erase(edge);
				lef.insert(val + lefd);
			}
			else
			{
				lef.insert(rect[i].first + lefd);
				lef.insert(rect[i].first + lefd);
				auto edge = lef.end();
				--edge;
				LL val = (*edge) - lefd;
				lef.erase(edge);
				rht.insert(val - rhtd);
			}
		}
		assert(lef.size() == rht.size());
	}
	cout << baseval << endl;
	return 0;
}


Measured memory_bytes: 11248
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define lb lower_bound
#define ub upper_bound

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
//template<class T> using oset=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

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

  	int sx, sy, tx, ty;
  	cin >> sx >> sy >> tx >> ty;

  	string ans = "";

  	int ld = tx - sx;
  	int ud = ty - sy;
  	for(int i = 0; i < ld; i++){
  		ans += "R";
  	}
  	for(int i = 0; i < ud; i++){
  		ans += "U";
  	}
  	for(int i = 0; i < ld; i++){
  		ans += "L";
  	}
  	for(int i = 0; i < ud; i++){
  		ans += "D";
  	}
  	ld++;
  	ud++;
  	ans += "D";
  	for(int i = 0; i < ld; i++){
  		ans += "R";
  	}
  	for(int i = 0; i < ud; i++){
  		ans += "U";
  	}
  	ans += "L";
  	ans += "U";
  	for(int i = 0; i < ld; i++){
  		ans += "L";
  	}
  	for(int i = 0; i < ud; i++){
  		ans += "D";
  	}
  	ans += "R";
  	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <algorithm>
using namespace std;
int n,l,a[110000];
int main() {
    while (scanf("%d%d", &n, &l) != EOF) {
        for (int i = 1; i <= n; i++)
            scanf("%d", &a[i]);
        int j = 1;
        while (a[j] + a[j + 1] < l && j < n) {
            j++;
        }
        if (j == n) {
            printf("Impossible\n");
        }else {
            printf("Possible\n");
            //printf("%d %d\n", n, j);
            for (int i = 1; i < j; i++)
                printf("%d\n", i);
            for (int i = n - 1; i > j; i--)
                printf("%d\n", i);
            printf("%d\n", j);
        }
    }



}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef vector<double> Vec;
typedef vector<Vec> Mat;
typedef pair<ll,ll> P;
typedef pair<double,ll> Pd;
typedef priority_queue<P,vector<P>,greater<P>> P_queue;
typedef priority_queue<Pd,vector<Pd>,greater<Pd>> Pd_queue;

const ll MOD=998244353;
const ll mod=1000000007;
const ll INF=1e15;
const double DEL=1e-6;
vec dx={1,0,-1,0};
vec dy={0,1,0,-1};

#define REP(i,a,b) for(int i=(int)a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define ALL(a) a.begin(),a.end()
#define SORT(a) sort(ALL(a))
#define U_ERASE(V) V.erase(unique(ALL(V)), V.end());
#define ADD(a,b) a=(a+b)%mod

vector<bool> a(105,false);
ll X,N;

ll Solve(){
    rep(i,110){
        if(X-i<0) return X-i;
        if(!a[X-i]) return X-i;
        if(!a[X+i]) return X+i;
    }
    return -1;
}
int main(){
    cin>>X>>N;
    rep(i,N){
        ll x; cin>>x; a[x]=true;
    }
    cout<<Solve()<<endl;

}

Measured memory_bytes: 3628
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int count = Integer.parseInt(br.readLine());
		for (int i = 0; i < count; i++) {
			String[] splited = br.readLine().split(" ");
			int[] array = new int[3];
			array[0] = Integer.parseInt(splited[0]);
			array[1] = Integer.parseInt(splited[1]);
			array[2] = Integer.parseInt(splited[2]);
			Arrays.sort(array);
			if(array[0] * array[0] + array[1] * array[1] == array[2] * array[2]) {
				System.out.println("YES");
			} else {
				System.out.println("NO");
			}
		}
		br.close();
	}
}

Measured memory_bytes: 20204
#include <bits/stdc++.h>
#define MOD 1e9 + 7
#define PI 3.141592653589793238
#define pb push_back
#define ALL(V) (V).begin(), (V).end()
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long long int lint;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<int> VI;
ll gcd(ll a, ll b) { return (a % b == 0 ? b : gcd(b, a % b)); }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
ll char_to_ll(char c) { return (int)(c - '0'); }
ll string_to_ll(string s) { return char_to_ll(atoi(s.c_str())); }
bool is_prime(ll x){ if(x <= 1) return false; for(ll i = 2; sqrt(i) <= x; i++) if(x % i == 0) return false; return true; }

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

    for (int i = 1; i <= min(H, W); i++){
        if (max(H, W) * i >= N){
            ans = i;
            break;
        }
    }

    cout << ans << endl;

    return 0;
}


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

using namespace std;
int main() {
	int n,S=0;

	cin>>n;

	int tmp=n;
	for(int i=0, m=log10(n); i<m+1; ++i) {
		S+=tmp%10; tmp/=10;
	}

	if(n%S==0)
		cout<<"Yes";
	else
		cout<<"No";
	cout<<endl;

	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define ll long long
#define INF INT_MAX 
#define mod 1000000007
using namespace std;
int main(){
    int A,B;
    cin >> A >> B;
    int ans = 0;
    if(A>B){
        ans = ans + A;
        A--;
    }else{
        ans = ans + B;
        B--;
    }
    if(A>B){
        ans = ans + A;
        A--;
    }else{
        ans = ans + B;
        B--;
    }
    cout << ans  << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define IOS ios_base::sync_with_stdio(false),cin.tie(0);
#define F first
#define S second
using namespace std;
typedef long long ll;
ll a,b,c,sum,t;
const ll maxn=200005;
const ll mod=1e9+7;
typedef pair<ll,ll> pii;
ll num[105];
ll n,k;

int main()
{
    //IOS
    double w,h,x,y;
    while(cin>>w>>h>>x>>y)
    {
        cout<<fixed<<setprecision(9)<<double((w*h)/2)<<"\n";
        if(x==w/2&&y==h/2) cout<<"1\n";
        else cout<<"0\n";
    }


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define EQ(x, y) (abs(x - y) < 1e-9)
typedef long long ll;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.precision(10);
	cout << fixed;

	int k, x;
	cin >> k >> x;
	for (int i = max(x - k + 1, -1000000); i < x; ++i){
		cout << i << ' ';
	}
	cout << x;
	for (int i = x + 1 ; i <= min(x + k - 1, 1000000); ++i){
		cout << ' ' << i;
	}
	cout << '\n';

#ifdef local
	cout << setprecision(3) << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s.\n";
#endif
	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
count = 0

for i in range(n):
    if a[i] >= b[i]:
        count += b[i]
    else:
        count += a[i]
        b[i] -= a[i]
        if a[i+1] >= b[i]:
            count += b[i]
            a[i+1] -= b[i]
        else:
            count += a[i+1]
            a[i+1] = 0
print(count)

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

int main() {
	int n;
	scanf("%d", &n);
	vector<int> a(n);
	for(int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
	sort(a.begin(), a.end());
	int ai = a[n-1];
	double mx = 1e9;
	int aj = -1;
	for(int i = 0; i < n; i++) {
		if(abs(ai/2.0 - a[i]) < mx) {
			mx = abs(ai/2.0 - a[i]);
			aj = a[i];
		}
	}
	printf("%d %d\n", ai, aj);
}

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

int main()
{
	int day[366];
	int month[12] = {0,31,60,91,121,152,182,213,244,274,305,335};
	int m,d;
	
	for(int i=0;i<366;++i)
		day[i] = i%7;
	
	while(cin >> m >> d){
		if(!m)
			break;

		switch(day[month[m-1] + d-1]){
		case 0:cout <<"Thursday"		<<endl;break;
		case 1:cout <<"Friday"			<<endl;break;
		case 2:cout <<"Saturday"		<<endl;break;
		case 3:cout <<"Sunday"			<<endl;break;
		case 4:cout <<"Monday"			<<endl;break;
		case 5:cout <<"Tuesday"			<<endl;break;
		case 6:cout <<"Wednesday"	<<endl;break;
		}

	}
	return 0;
}

Measured memory_bytes: 1148
import java.util.Scanner;

public class Main {
    
    public static void main (String[] args){
        
      Scanner sc = new Scanner (System.in);
        
        long L = sc.nextLong();
        long R = sc.nextLong();
        
        if (R>=2019&&L<=2019){
            System.out.println(0);
        } else {
            long min = Long.MAX_VALUE;
            boolean flag = true;
            
            for (long index=L; index<R; index++){
                if (flag==false){
                    break;
                }
                for (long index2=index+1; index2<=R; index2++){
                    if ((index*index2)%2019==0){
                        flag = false;
                        min=0;
                        break;
                    }
                    if (min>(index*index2)%2019){
                        min=(index*index2)%2019;
                    }
                }
            }
            System.out.println(min);
        }
    }
}

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

namespace Registration_0527_3問目
{
    class Program
    {
        static void Main(string[] args)
        {
            string S = Console.ReadLine();           
            string T = Console.ReadLine();
           
            
            if(S==T.Substring(0,T.Length-1))
            {
                Console.Write("Yes");
            }
            else
            {
                Console.Write("No");
            }
            Console.Read();
        }
    }
}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

ll nextLong() { ll x; scanf("%lld", &x); return x;}

const ll INF = 1LL << 61;
map< pair<string,string>, ll > memo;

struct State {
  pair<string, string> p;
  ll cost;

  bool operator < (const State& o) const {
    return cost > o.cost;
  }
};

pair<string, string> cut(pair<string, string> p) {
  while (p.first.size() > 0 && p.second.size() > 0) {
    if (p.first.back() == p.second.front()) {
      p.first = p.first.substr(0, p.first.size() - 1);
      p.second = p.second.substr(1);
    } else {
      break;
    }
  }
  return p;
}

int main2() {

  int N = nextLong();

  vector<string> S(N);
  vector<ll> C(N);
  REP(i, N) {
    cin >> S[i] >> C[i];
  }


  priority_queue<State> pq;
  memo.clear();

  REP(i, N) {
    for (int j = 0; j <= (int)S[i].size(); j++) {
      auto p = make_pair(S[i].substr(0, j), S[i].substr(j));
      p = cut(p);
      if (p.first.size() > 0 && p.second.size() > 0) continue;
      if (memo.count(p) == 0 || memo[p] > C[i]) {
        memo[p] = C[i];
        pq.push((State){ p, C[i] });
      }

    }
    for (int j = 0; j < (int)S[i].size(); j++) {
      auto p = make_pair(S[i].substr(0, j), S[i].substr(j+1));
      p = cut(p);
      if (p.first.size() > 0 && p.second.size() > 0) continue;
      if (memo.count(p) == 0 || memo[p] > C[i]) {
        memo[p] = C[i];
        pq.push((State){ p, C[i] });
      }
      
    }
  }


  ll ans = -1;
  while (!pq.empty()) {
    State state = pq.top(); pq.pop();
    if (state.cost != memo[state.p]) continue;

    if (state.p.first == "" && state.p.second == "") {
      ans = state.cost;
      break;
    }

    REP(i, N) {
      auto p = state.p;
      if (p.second == "") p.second += S[i];
      else p.first = S[i] + p.first;
      p = cut(p);
      if (p.first.size() > 0 && p.second.size() > 0) continue;
      ll cost = state.cost + C[i];
      if (memo.count(p) == 0 || memo[p] > cost) {
        memo[p] = cost;
        pq.push((State){ p, cost });
      }
    }
  }

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

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}

Measured memory_bytes: 3924