akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define reps(i, a, n) for (int i = (a); i < (n); ++i)
#define rep(i, n) reps(i, 0, n)
#define deps(i, a, n) for (int i = (a); i >= (n); --i)
#define dep(i, n) deps(i, n, 0)
#define inf 2147483647
#define int long long

signed main(void)
{
	string s; cin >> s;
	if (s[0]=='S' && s[1]=='S' && s[2]=='S') {cout << 0 << endl; return 0;}
	if (s[0]=='S' && s[1]=='S' && s[2]=='R') {cout << 1 << endl; return 0;}
	if (s[0]=='S' && s[1]=='R' && s[2]=='S') {cout << 1 << endl; return 0;}
	if (s[0]=='S' && s[1]=='R' && s[2]=='R') {cout << 2 << endl; return 0;}
	if (s[0]=='R' && s[1]=='S' && s[2]=='S') {cout << 1 << endl; return 0;}
	if (s[0]=='R' && s[1]=='S' && s[2]=='R') {cout << 1 << endl; return 0;}
	if (s[0]=='R' && s[1]=='R' && s[2]=='S') {cout << 2 << endl; return 0;}
	if (s[0]=='R' && s[1]=='R' && s[2]=='R') {cout << 3 << endl; return 0;}
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define sqr(x) ((x) * (x))
#define bit(n) (1LL<<(n))
#define pcnt(x) __builtin_popcountll(x)
#define PB push_back
#define MP make_pair
#define endl "\n"
using Edge = pair<int,int>;
using Graph = vector<vector<Edge>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
// ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

// union by size + path having
class UnionFind {
public:
    vector <ll> par; // 各元の親を表す配列
    vector <ll> siz; // 素集合のサイズを表す配列(1 で初期化)

    // Constructor
    UnionFind(ll sz_): par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);  // resize だとなぜか初期化されなかった
        for (ll i = 0; i < sz_; ++i) par[i] = i; // 初期では親は自分自身
    }

    // Member Function
    // Find
    ll root(ll x) { // 根の検索
        while (par[x] != x) {
            x = par[x] = par[par[x]]; // x の親の親を x の親とする
        }
        return x;
    }

    // Union(Unite, Merge)
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        // merge technique（データ構造をマージするテク．小を大にくっつける）
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) { // 連結判定
        return root(x) == root(y);
    }

    ll size(ll x) { // 素集合のサイズ
        return siz[root(x)];
    }
};

int ans[100100];

int main() {
  ll n,m,k; cin >> n >> m >> k;
  vector<vector<ll>> follow(n);
  vector<vector<ll>> block(n);
  UnionFind uf(n);
  FOR(i,0,m-1){
    ll a,b; cin >> a >> b;
    --a; --b;
    uf.merge(a,b);
    follow[a].PB(b);
    follow[b].PB(a);
    --ans[a];
    --ans[b];
  }

  // map<ll,ll> mp;
  // ll ans = 0;
  // FOR(i,0,n-1){
  //   int r = uf.root(i);
  //   if(mp[r]==0){
  //     ++mp[r];
  //     ans += uf.size(i) * (uf.size(i) - 1) / 2;
  //   }
  // }
  // ans -= m;

  
  FOR(i,0,n-1) {
    ans[i] += uf.size(i) - 1;
  }
  FOR(i,0,k-1){
    ll c,d; cin >> c >> d;
    --c; --d;
    if(uf.root(c)==uf.root(d)) {
      --ans[c];
      --ans[d];
    }
  }
  FOR(i,0,n-1) cout << ans[i] << " ";
  cout << endl;


}



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

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef vector<pi> vpi;
typedef vector<bool> vbool;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define forall(it,s) for(auto it = s.begin(); it != s.end(); ++it)
#define F0(i,n) for(ll i = 0; i < n; i++)
#define F1(i,n) for(ll i = 1; i <= n; i++)
#define rep(i,a,b) for(int i = a; i <= b; i++)
#define per(i,a,b) for(int i = b-1; i >= a; i--)
#define FIN ios::sync_with_stdio(false);cin.tie(0);
#define db(x) cout<<#x<<" = "<<x<<"\n"
#define all(v) v.begin(),v.end()
#define modulo(a,b) ((a%b)+b)%b
#define F first
#define S second
#define INF 1000000010
#define INFLL 1000000000000000000
#define eps 0.000000000001
#define mod 1000000007
template<class C> void mini(C&a, C b){ a=min(a, b);}
template<class C> void maxi(C&a, C b){a=max(a,b);}
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;}

//=======================//
int n;
vvi adj;
vector<vector<ll>> dp;
#define blanco 0
#define negro 1

void dfs(int a, int parent=-1) {
	dp[a][blanco] = 1;
	dp[a][negro]  = 1;
	for (int b : adj[a]) {
		if (b != parent) {
			dfs(b, a);
			dp[a][blanco] *= (dp[b][blanco] + dp[b][negro]);
			dp[a][negro]  *= dp[b][blanco];
			dp[a][blanco] %= mod; dp[a][negro] %= mod;
		}
	}
}

int main () {
	//FIN

	cin >> n;
	adj = vvi(n);
	dp = vector<vector<ll>>(n, vll(2));
	F0(i,n-1) {
		int a,b; cin >> a >> b; a--; b--;
		adj[a].pb(b); adj[b].pb(a);
	}
	dfs(0);
	cout << ((dp[0][blanco] + dp[0][negro]) % mod) << "\n";

	return 0;
}










Measured memory_bytes: 21128
x=int(input())
k=[]
for i in range(1,32):
    if abs(x-i**2)<=min(abs(x-i**3),abs(x-i**7),abs(x-i**5)):
        if i**2<=x:
            k.append([abs(x-i**2),i**2])
    elif abs(x-i**3)<=min(abs(x-i**2),abs(x-i**7),abs(x-i**5)):
        if i**3<=x:
            k.append([abs(x-i**3),i**3])
    elif abs(x-i**5)<=min(abs(x-i**3),abs(x-i**2),abs(x-i**7)):
        if i**5<=x:
            k.append([abs(x-i**5),i**5])
    elif abs(x-i**7)<=min(abs(x-i**3),abs(x-i**2),abs(x-i**5)):
        if i**7<=x:
            k.append([abs(x-i**7),i**7])
k.sort()
print(k[0][1])

Measured memory_bytes: 3064
#include<stdio.h>
short n;
int main(){
  scanf("%hd", &n);
  if(n<105){
    puts("0");
  }else if(n<135){
    puts("1");
  }else if(n<165){
    puts("2");
  }else if(n<189){
    puts("3");
  }else if(n<195){
    puts("4");
  }else{
    puts("5");
  }
}

Measured memory_bytes: 128
t1,t2=gets.split.map(&:to_i)
a1,a2=gets.split.map(&:to_i)
b1,b2=gets.split.map(&:to_i)
d1=t1*(a1-b1)
d2=d1+t2*(a2-b2)
if d2==0
  puts "infinity"
elsif d1*d2>0
  puts 0
else 
  d1=d1.abs
  d2=d2.abs
  ans=0
  if d1%d2>0
    ans+=1
  end
  puts ans+(d1/d2)*2
end


Measured memory_bytes: 3836
# coding: utf-8

II = lambda: int(input())
MI = lambda: map(int, input().split())


def main():
    N, M = MI()
    ab = [tuple(MI()) for _ in range(M)]

    ab = sorted(ab, key=lambda x:x[1])
    lb = -1
    cnt = 0
    for a, b in ab:
        if lb <= a:
            lb = b
            cnt += 1
    return cnt


if __name__ == "__main__":
    print(main())


Measured memory_bytes: 19024
#include <iostream>
#include <vector>
#include <array>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <iomanip>

using namespace std;
using ll=long long int;

uint32_t popcnt(uint32_t n)
{
    n = (n & 0x55555555) + (n >> 1 & 0x55555555);
    n = (n & 0x33333333) + (n >> 2 & 0x33333333);
    n = (n & 0x0f0f0f0f) + (n >> 4 & 0x0f0f0f0f);
    n = (n & 0x00ff00ff) + (n >> 8 & 0x00ff00ff);
    n = (n & 0x0000ffff) + (n >> 16 & 0x0000ffff);
    return n;
}

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

    int n = 1;
    while ((1 << n) <= l) ++n;
    int m = 2 * (n-1) + popcnt(l) - 1;

    cout << n << " " << m << endl;

    for (int i = 1; i <= n-1; ++i) {
        cout << i << " " << i+1 << " " << 0 << endl;
        cout << i << " " << i+1 << " " << (1 << (i-1)) << endl;
    }
    for (int i = 1; i <= n-1; ++i) {
        int d = l >> (i-1) & 1;
        if (d == 0) continue;
        int c = l >> i << i;
        cout << i << " " << n << " " << c << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
#include <unordered_map>
#include <fstream>
#include <time.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 5020000;
ll dy[8] = {1,-1,0,0,1,-1,1,-1};
ll dx[8] = {0,0,1,-1,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    rep(i,a.size()) cout << a[i] << " ";
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
ll pcount(ll x) {return __builtin_popcountll(x);}
const int mod = 1e9 + 7;
//const int mod = 998244353;

vector<int> dfs(int n, int a, int b){
	if(n == 1) return {a,b};
	int pa = pcount(a);
	int pb = pcount(b);
	rep(bit,18){
		if((a>>bit & 1) != (b>>bit & 1)){
			int A = a, B = b;
			REP(b2,bit+1,20){
				int tmp = 1<<(b2-1);
				A &= ~tmp;
				A |= tmp * (a>>b2 & 1);
				B &= ~tmp;
				B |= tmp * (b>>b2 & 1);
			}
			bool f = a>>bit & 1;
			int t = 0;
			if(f) t = pa & 1;
			else t = pb & 1;
			auto l = dfs(n-1, A, t);
			auto r = dfs(n-1, t, B);
			for(auto &i : l) for(int b2=17; b2>=bit; b2--){
				i |= (1<<(b2+1)) * (i>>b2 & 1);
				i &= ~(1<<b2);
			}
			for(auto &i : r) for(int b2=17; b2>=bit; b2--){
				i |= (1<<(b2+1)) * (i>>b2 & 1);
				i &= ~(1<<b2);
			}
			if(f) for(auto &i : l) i += 1<<bit;
			else for(auto &i : r) i += 1<<bit;
			l.insert(l.end(), r.begin(), r.end());
			return l; 
		}
	}
}

int main(){
	int n,a,b; cin >> n >> a >> b;
	if(pcount(a) % 2 == pcount(b) % 2){
		cout << "NO" << "\n";
		return 0;
	}
	puts("YES");
	auto ans = dfs(n,a,b);
	print(ans);
}

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

#define lli long long int
#define MAX lli max = 9000000000000000000;
#define MIN lli min = 9000000000000000000;
#define LLI(n) \
  lli n;       \
  cin >> n;
#define LLIV(a, n)            \
  vector<lli> a(n);           \
  for (lli i = 0; i < n; i++) \
  {                           \
    cin >> a.at(i);           \
  };
#define STR(n) \
  string n;    \
  cin >> n;
#define Sort(n) sort(n.begin(), n.end());
#define Reve(n) reverse(n.begin(), n.end());
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
#define C45(n) (n + 1) / 2
#define OUT(n) cout << n << endl;
#define SRC(n, c)                    \
  for (lli i = 0; i < s.size(); i++) \
  {                                  \
    if (s.at(i) == c)                \
    {                                \
      n++;                           \
    }                                \
  };
//こぴー
/*#define ZISYO(s, S)                  \
  for (lli i = 0; i < s.size(); i++) \
  {                                  \
    S.at(i) = s.at(i);               \
  }                                  \
  Sort(S) Reve(S) for (lli i = 0; i < s.size(); i++) { s.at(i) = S.at(i); };
*/

//素数
bool IsPrime(lli num)
{
  if (num < 2)
    return false;
  else if (num == 2)
    return true;
  else if (num % 2 == 0)
    return false;
  long double sqrtNum = sqrt(num);
  for (lli i = 3; i <= sqrtNum; i += 2)
  {
    if (num % i == 0)
      return false;
  }
  return true;
}
//各桁の和
lli Sum(lli n)
{
  lli sum = 0;
  if (n < 0)
    return 0;
  while (n > 0)
  {
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

int main(void)
{
  ios::sync_with_stdio(false);
  LLI(N) LLI(T) LLI(A) LLIV(H, N) MAX lli ans;
  for(lli i  = 0;i < N;i++) {
    H[i] = T*1000 - H[i] * 6;
    if(abs(A * 1000 - H[i]) < max) {
      max = abs(A * 1000 - H[i]);
      ans = i+1;
    }
  }
  OUT(ans)
}


Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;

int main() {
    char X, Y;
    cin >> X >> Y;

    if ((int)X == (int)Y){
        cout << '=' << endl;
    }else if ((int)X < (int)Y){
        cout << '<' << endl;
    }else{
        cout << '>' << endl;
    }
}

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

int main() {
    string S;
    cin >> S;
    bool a = false, b = false, c = false;
    if (S[0] == 'A') a = true;
    int countC = 0;
    for(int i = 2; i <= S.size()-2; i++) {
        if (S[i] == 'C') countC++;
    }
    for(int i = 0; i < S.size(); i++) {
        if (S[i] >= 65 && S[i] <= 96 && S[i] != 'A' && S[i] != 'C')
            c = true;
    }

    if (a && !c && countC == 1) {
        cout << "AC" << endl;
    }
    else {
        cout << "WA" << endl;
    }
    return 0;
}

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

class UnionFind{
private:
    std::vector<int> par, sizes;
public:
    UnionFind() = delete;
    UnionFind(int sz) : par(sz), sizes(sz, 1){
        for(int i = 0; i < sz; i++){
            par[i] = i;
        }
    }
    bool unite(int x, int y){
        x = find(x);
        y = find(y);

        if(x == y) return false;

        if(sizes[x] < sizes[y]) swap(x, y);
        sizes[x] += sizes[y];
        sizes[y] = 0;
        par[y] = x;
        return true;
    }
    int find(int x){
        if(par[x] == x) return x;
        return par[x] = find(par[x]);
    }

    bool is_same(int x, int y){
        return find(x) == find(y);
    }

    int size(int x){
        return sizes[find(x)];
    }
};

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i = 0; i < N; i++) cin >> A[i];

    vector<bool> num_table(100100, 0);
    vector<int> prime;

    for(int i = 2; i*i < 100100; i++){
        if(num_table[i]) continue;
        for(int j = i+i; j < 100100; j += i){
            num_table[j] = i;
        }
    }

    for(int i = 2; i < 100100; i++){
        if(num_table[i] == 0) prime.emplace_back(i);
    }

    UnionFind uf(100100 + N);

    for(int i = 0; i < N; i++){
        uf.unite(N + A[i], i);
        for(int j = 0; prime[j] < A[i] && j < prime.size(); j++){
            if(A[i] % prime[j] == 0) {
                uf.unite(N + prime[j], i);
            } 
        }
    }

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

    bool can = true;
    for(int i = 0; i < N; i++){
        can &= uf.is_same(N + A[i], i);
    }

    cout << can << endl;
}


Measured memory_bytes: 4996
#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>
#include <cstdio>
#include <complex>
#include <cstring>

using namespace std;

const int MOD = (int)1e9 + 7;
const int N = 2000 + 5;

int n, m, k;
int f[N][N];

void solve()
{
    cin >> n;
    cin >> m;
    cin >> k;
    f[0][0] = 1;
    long long ans = 0;
    for(int i = 0; i <= n; ++ i) {
        for(int j = 0; j < m; ++ j) {
            if (f[i][j] == 0) continue;
            //cout << i << ' ' << j << ' ' << f[i][j] << endl;
            for(int ni = 0; ni <= k - 1; ++ ni) {
                int pi = i + ni;
                int pj = j + k - 1 - ni;
                if (pi <= n && pj <= m - 1) {
                    (f[pi][pj] += f[i][j]) %= MOD;
                    if (ni && pi % (k - 1) == n % (k - 1) && pj % (k - 1) == (m - 1) % (k - 1)) {
                        ans += f[i][j];
                        //cout << i << ' ' << j << ' ' << f[i][j] << ' ' << pi << ' ' << pj << endl;
                    }
                }
            }
        }
    }
    cout << ans % MOD << endl;
}

int main()
{
    solve();
    return 0;
}


Measured memory_bytes: 15872
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

var sc, wr = bufio.NewScanner(os.Stdin), bufio.NewWriter(os.Stdout)

func scanString() string   { sc.Scan(); return sc.Text() }
func scanRunes() []rune    { return []rune(scanString()) }
func scanInt() int         { a, _ := strconv.Atoi(scanString()); return a }
func scanInt64() int64     { a, _ := strconv.ParseInt(scanString(), 10, 64); return a }
func scanFloat64() float64 { a, _ := strconv.ParseFloat(scanString(), 64); return a }

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func debug(a ...interface{}) { fmt.Fprintln(os.Stderr, a...) }

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

//•*¨*•.¸¸♪main•*¨*•.¸¸♪(　-ω-)ノ　(　・ω・)
func main() {
	defer wr.Flush()
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 10000), 1001001)

	X := scanInt()
	Y := scanInt()
	Z := scanInt()
	K := scanInt()
	a := scanInts(X)
	b := scanInts(Y)
	c := scanInts(Z)

	bc := make([]int, Y*Z)
	for i := 0; i < Y; i++ {
		for j := 0; j < Z; j++ {
			bc[i*Z+j] = b[i] + c[j]
		}
	}

	sort.Ints(bc)

	n := Y * Z
	l, r := 0, 1<<40
	for l+1 < r {
		mid := (l + r) / 2
		cnt := 0
		for i := 0; i < X; i++ {
			cnt += n - sort.Search(n, func(j int) bool {
				return mid <= a[i]+bc[j]
			})
		}

		if cnt >= K {
			l = mid
		} else {
			r = mid
		}
	}

	arr := []int{}

	for i := 0; i < X; i++ {
		for j := 0; j < n; j++ {
			if a[i]+bc[n-1-j] < l {
				break
			}
			arr = append(arr, a[i]+bc[n-1-j])
		}
	}

	sort.Ints(arr)

	for i := 0; i < K; i++ {
		fmt.Fprintln(wr, arr[len(arr)-1-i])
	}
}


Measured memory_bytes: 266624
#include <bits/stdc++.h>
using namespace std;
int main() {
  string a, b;
  cin >> a >> b;
  int k = 0,
  	  j = 0;
  for (int i = 0;i < a.length() + b.length();i++) {
    if ((i + 1) % 2 == 0) {
      cout << b.at(k++);
    } else {
      cout << a.at(j++);
    }
  }
}

Measured memory_bytes: 256
#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 < (n); ++i)
#define int long long
#define vec(a,n) vector<int> (a)((n))
#define Vec(a,n) vector<string> (a)((n))
#define P pair<int,int>
#define PQ(n) priority_queue<P,vector<P>,greater<P>> (n)
#define pq(n) priority_queue<int> (n)
using namespace std;

signed main(){

    string s;
    cin >> s;
    int n = s.size();
    vec(x,n-2);
    int y = 753;
    FOR(i,2,n){
        char a = s[i];
        char b = s[i-1];
        char c = s[i-2];
        int l = a - '0';
        int j = b - '0';
        j *= 10;
        int k = c - '0';
        k *= 100;
        int t = l + j + k;
        t = abs(t-y);
        x[i-2] = t;
    }
    sort(x.begin(),x.end());
    cout << x[0] << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int n,k;
  cin>>n>>k;
  int a[1000];
  for(int i=0;i<n;i++)
    cin>>a[i];
  sort(a,a+n);
  int sum=0;
  for(int i=0;i<k;i++)
    sum+=a[i];
  cout<<sum<<endl;
  return 0;
}


Measured memory_bytes: 3564
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a, b, c, k, ans=0;
    cin >> a >> b >> c >> k;
    if(k<=a){
        cout << k << endl;
    }else if(k<=a+b){
        cout << a << endl;
    }else{
        cout << a-(k-a-b) << endl;
    }
    return 0;
}


Measured memory_bytes: 3616
import sys
sys.setrecursionlimit(1000000)
def main():
    N, M = map(int, input().split())
    d = {}
    for _ in range(M):
        x, y = map(int, input().split())
        if x in d:
            d[x].append(y)
        else:
            d[x] = [y]
    l = {}
    m = 0
    for i in d:
        m = max(m, dfs(i, d, l))
    print(m)
def dfs(node, d, l):
    if node in l:
        return l[node]
    if node not in d:
        return 0
    a = 1 + max(dfs(i, d, l) for i in d[node])
    l[node] = a
    return a

main()





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

namespace ABC060ChooseIntegers
{
    class Program
    {
        static void Main(string[] args)
        {
            int A, B, C;
            string[] vals = Console.ReadLine().Split(' ');

            A = int.Parse(vals[0]);
            B = int.Parse(vals[1]);
            C = int.Parse(vals[2]);

            bool[] flags = new bool[B];
            int i = 1;

            while(true)
            {
                int m = A * i % B;
                if(m == C)
                {
                    Console.WriteLine("YES");
                    return;
                }
                else
                {
                    if(flags[m] == true)
                    {
                        Console.WriteLine("NO");
                        return;
                    }
                    flags[m] = true;
                }
                i++;
            }

        }
    }
}


Measured memory_bytes: 11092
from itertools import groupby
n, k = map(int, input().split())
s = input()

t = []
if s[0] == "0":
    t.append(("1", 0))
for c, v in groupby(s):
    t.append((c, sum(1 for _ in v)))

if s[-1] == "0":
    t.append(("1", 0))

S = [t[0][1]]
rm = [0]
m = len(t)
for i in range(m//2):
    tmp = S[-1]
    S.append(tmp+t[2*i+1][1]+t[2*i+2][1])
    rm.append(tmp+t[2*i+1][1])

ans = []
for i in range(m//2+1):
    if i - k < 0:
        ans.append(S[i])
    else:
        ans.append(S[i]-rm[i-k])
print(max(ans))


Measured memory_bytes: 61660
n = int(input())
A = list(map(int, input().split()))
minA = min(A)
maxA = max(A)

ans = float("inf")
for i in range(minA, maxA+1):
    cost = 0
    for a in A:
        cost += (i - a)**2
    if cost < ans:
        ans = cost

print(ans)

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


int main() {
    int n;
    cin >> n;
    vector<int> v(n);

    vector<int> copy(n);

    for(int i = 0; i < n; i++) {
        cin >> v[i];
        copy[i] = v[i];
    }

    sort(copy.begin(), copy.end());
    for(int i = 0; i < n; i++) {
        int max = 0;
        if(v[i] == copy[n-1]) {
            max = copy[n-2];
        } else {
            max = copy[n-1];
        }
        cout << max << endl;
    }




}


Measured memory_bytes: 3200
#include <stdio.h>
#define MAX 100005
#define NIL -1
struct Node{
  int parent;
  int left;
  int right;
};

struct Node T[MAX];

int n,D[MAX];
int setDepth(int u,int p){
  D[u] = p;
  if(T[u].right != NIL){
    setDepth(T[u].right,p);
  }
  if(T[u].left != NIL){
    setDepth(T[u].left,p+1);
  }
}
void printChildren(int u){
  int c;
  c = T[u].left;
  printf("node %d: parent = %d, depth = %d, ",u,T[u].parent,D[u]);
  if(D[u] == 0) {printf("root, [");}

  else if(c != NIL) {printf("internal node, [");}

  else if(c == NIL) {printf("leaf, [");}

  while(c != NIL){
    printf("%d",c);
    if(T[c].right != -1) {printf(", ");}

    c = T[c].right;
  }
  printf("]\n");
}

int main()
{
  int i,v,d,j,c,l,r,u;

  scanf("%d",&n);
  for(i=0;i<n;i++){
          T[i].parent = NIL;
          T[i].left = NIL;
          T[i].right = NIL;
  }

  for(i = 0;i < n;i++){
    scanf("%d %d",&v,&d);
    for(j=0;j<d;j++){
      scanf("%d",&c);
      if(j==0) T[v].left = c;
      else T[l].right = c;
      l = c;
      T[c].parent = v;
    }
  }

  for(i=0;i<n;i++) {if(T[i].parent == NIL) r = i;}

  setDepth(r,0);

  for(u=0;u<n;u++){
    printChildren(u);
  }

  return 0;
}



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

using namespace std;

int main() {
	string a, b;
	cin >> a;
	cin >> b;
	int sa = a.size();
	int sb = b.size();
	if (sa > sb) {
		printf("GREATER\n");
	} else {
		if (sa < sb) {
			printf("LESS\n");
		} else {
			int i;
			for (i = 0; i < sa; i++) {
				if (a[i] > b[i]) {
					printf("GREATER\n");
					break;
				}
				if (a[i] < b[i]) {
					printf("LESS\n");
					break;
				}
			}
			if (i == sa) {
				printf("EQUAL");
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
from sys import stdin
import math
import fractions
from collections import deque
from collections import Counter
import itertools

INF = 10 ** 10

S = stdin.readline().rstrip()
s = [x for x in S]

a = Counter(s)

try:
    aa = a.most_common()
    if aa[0][1] == 2 and aa[1][1] == 2:
        print("Yes")
    else:
        print("No") 
except:
    print("No")



Measured memory_bytes: 64108
# coding=utf-8

class Tree():
    def __init__(self):
        self.root = None

    def insert(self, key):
        node = Node(key)
        flag = False

        if self.root == None:
            self.root = node
        else:
            search_node = self.root
            while search_node:
                final_node = search_node
                if final_node.key < key:
                    search_node = final_node.right
                    flag = 'right'
                else:
                    search_node = final_node.left
                    flag = 'left'
            node.parent = final_node
            if flag == 'right':
                final_node.right = node
            elif flag == 'left':
                final_node.left = node

    def tprint(self):
        self.root.inwalk()
        print()
        self.root.prewalk()
        print()

    def find(self, key):
        if self.root.find(key):
            print('yes')
        else:
            print('no')


class Node():
    def __init__(self, key):
        self.key = key
        self.parent = None
        self.left = None
        self.right = None

    def prewalk(self):
        print(" " + str(self.key), end = "")
        if self.left:
            self.left.prewalk()
        if self.right:
            self.right.prewalk()

    def inwalk(self):
        if self.left:
            self.left.inwalk()
        print(' ' + str(self.key), end = "")
        if self.right:
            self.right.inwalk()

    def find(self, key):
        find_flag = False
        node = self

        while node != None:
            if key > node.key:
                node = node.right
            elif key < node.key:
                node = node.left
            elif key == node.key:
                find_flag = True
                break

        return find_flag


n = int(input())
tree = Tree()

for _ in range(n):
    order, *key = input().split()
    if order == 'insert':
        tree.insert(int(key[0]))

    elif order == 'find':
        tree.find(int(key[0]))

    elif order == 'print':
        tree.tprint()

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


int main(){
    int ans;
    int n,k;
    cin>>n>>k;
    rep(i,n){
        int l;
        cin>>l;
        if(l>=k)ans++;
    }
    

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

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

int main() {
    long long x;
    cin >> x;
    
    long long sum = 0;
    for (int i = 1; i <= 50000; i++) {
        sum += (long long)i;

        if (sum >= x) {
            cout << i << endl;
            return 0;
        }
    }
}   

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll n;
double p[3010],dp[3010][3010];
double dp1(int i,int co)
{
    if(i==n)
    {
        if(co>n-co)
            return 1;
        return 0;
    }
    if(dp[i][co]>-0.5)
        return dp[i][co];
    double x1=p[i]*dp1(i+1,co+1);
    double x2=(1-p[i])*dp1(i+1,co);
    return dp[i][co]=x1+x2;
}
int main()
{
    //memset(dp,-1,sizeof(dp));
    for(int i=0;i<3010;i++)
    {
        for(int j = 0 ; j<3010;j++)
            dp[i][j]=-1;

    }
    cin>>n;
    for(int i = 0 ; i<n ;i++)
    {
        cin>>p[i];
        //cout<<p[i];
    }
    printf("%.30lf",dp1(0,0));
    return 0;
}


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

#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif // LOCAL_
// #define dump() fprintf(stderr, "#%s.%d\n", __func__, __LINE__);
#define dumpl(x1) fprintf(stderr, "#%s.%d (%s) = (%ld)\n", __func__, __LINE__, #x1, x1);
#define dumpll(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%ld, %ld)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define dumplll(x1, x2, x3) fprintf(stderr, "#%s.%d (%s, %s, %s) = (%ld, %ld, %ld)\n", __func__, __LINE__, #x1, #x2, #x3, x1, x2, x3);
#define dumpd(x1) fprintf(stderr, "#%s.%d (%s) = (%lf)\n", __func__, __LINE__, #x1, x1);
#define dumpdd(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%lf, %lf)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define loop for(;;)
typedef std::vector<long> LI;

template<typename T> void scan1(T& x) { fprintf(stderr, "unknown type\n"); }
template<> void scan1(long& x) { if( scanf("%ld", &x) < 0 ) exit(0); }
template<> void scan1(std::string& x) { if( not ( std::cin >> x ) ) exit(0); }
void scan() {}
template<typename Head, typename... Tail>
void scan(Head& x, Tail&... xs) {
  scan1(x); scan(xs...);
}

struct Solver {
   Solver() { fprintf(stderr, "--------Solver begin--------\n"); }
   ~Solver() { fprintf(stderr, "--------Solver end--------\n"); }
   void solve() {
      std::string str; scan(str);
      long res = true;
      long n = str.size();
      for(long i = 0; i < n; ++i) {
         for(long k = 0; k < n; ++k) {
            if( i == k ) continue;
            if( str[i] == str[k] ) res = false;
         }
      }
      puts(res ? "yes" : "no");
   }
};

int main() {
  loop std::unique_ptr<Solver>(new Solver())->solve();
}



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

#define int int64_t
#define pb push_back
#define pi pair<int, int>
#define pii pair<pi, int>
#define fir first.first
#define sec first.second
#define ter second
#define MAXN 100001
#define mod 1000000007

signed main()
{
  int n;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++)
    cin >> v[i];
  int maxx = -1, ans = 0;
  for (int i = 0; i < n; i++)
  {
    maxx = max(v[i], maxx);
    ans += (maxx - v[i]);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4816
def main():
    n = int(input())
    w = [input() for _ in range(n)]
    if len(set(w)) != n:
        print('No')
        return 0
    for i in range(1,n):
        if w[i][0] != w[i-1][-1]:
            print('No')
            return 0
    print('Yes')

if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
#![allow(unused_imports)]
#![allow(dead_code)]
use datastructure::*;
use input_scanner::*;

use std::cmp;
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, LinkedList, VecDeque};

fn main() {
    let mut scan = Scanner::new();
    let n: usize = scan.next();
    let mut bset: BTreeSet<String> = BTreeSet::new();
   
    for _ in 0..n {
        let a: String = scan.next();
        bset.insert(a);
    }
    println!("{}", bset.len());
}

mod datastructure {}
mod input_scanner {
    pub struct Scanner {
        bytes: Vec<u8>,
        begin: usize,
        end: usize,
    }
    
    impl Scanner {
        pub fn new() -> Self {
            use std::io::Read;
            let mut buffer: Vec<u8> = Vec::new();
            std::io::stdin().read_to_end(&mut buffer).unwrap();
            let end = (0..buffer.len())
                .find(|i| buffer[*i].is_ascii_whitespace())
                .unwrap_or(buffer.len());
            Scanner {
                bytes: buffer,
                begin: 0,
                end: end,
            }
        }
        pub fn next<T: std::str::FromStr>(&mut self) -> T {
            let s: &str = unsafe { std::str::from_utf8_unchecked(&self.bytes[self.begin..self.end]) };
            let ret: T = s.parse::<T>().ok().expect("Parse error.");
            self.skip();
            ret
        }
        pub fn next_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
            (0..n).map(|_| self.next()).collect()
        }
        pub fn next_word(&mut self) -> Vec<u8> {
            let r = Vec::from(&self.bytes[self.begin..self.end]);
            self.skip();
            r
        }
        fn skip(&mut self) {
            self.begin = (self.end..self.bytes.len())
                .find(|i| !self.bytes[*i].is_ascii_whitespace())
                .unwrap_or(self.bytes.len());
            self.end = (self.begin..self.bytes.len())
                .find(|i| self.bytes[*i].is_ascii_whitespace())
                .unwrap_or(self.bytes.len());
        }
    }  
}


Measured memory_bytes: 18288
#include <iostream>

using namespace std;
typedef long long  ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)

int main() {
	int a, b, c; cin >> a >> b >> c;

	cout << ((b - a == c - b) ? "YES" : "NO") << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
using Graph = vector<VecP>;
template <typename T>
using Vec1 = vector<T>;
template <typename T>
using Vec2 = vector<Vec1<T> >;
#define REP(i, m, n) for(ll i = (m); (i) < (n); ++(i))
#define REPN(i, m, n) for(ll i = (m); (i) <= (n); ++(i))
#define REPR(i, m, n) for(ll i = (m)-1; (i) >= (n); --(i))
#define REPNR(i, m, n) for(ll i = (m); (i) >= (n); --(i))
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
template <typename T>
ll pow2(const T n){return (1LL << n);}
template <typename T>
void cosp(const T n){cout << n << ' ';}
void co(void){cout << '\n';}
template <typename T>
void co(const T n){cout << n << '\n';}
template <typename T1, typename T2>
void co(pair<T1, T2> p){cout << p.fs << ' ' << p.sc << '\n';}
template <typename T>
void co(const Vec1<T> &v){for(T i : v) cosp(i); co();}
template <typename T>
void co(initializer_list<T> v){for(T i : v) cosp(i); co();}
template <typename T>
void ce(const T n){cerr << n << endl;}
void sonic(){ios::sync_with_stdio(false); cin.tie(0);}
void setp(const ll n){cout << fixed << setprecision(n);}
constexpr int INF = 1e9+1;
constexpr ll LINF = 1e18+1;
constexpr ll MOD = 1e9+7;
// constexpr ll MOD = 998244353;
constexpr ld EPS = 1e-11;
const ld PI = acos(-1);

int main(void){
	ll x, n;
	cin >> x >> n;
	set<ll> st;
	rep(i, 105) st.insert(i);

	rep(i, n){
		ll p;
		cin >> p;
		st.erase(p);
	}

	ll ans = LINF;

	for(ll i : st) if (abs(i - x) < abs(ans - x)) ans = i;

	co(ans);

	return 0;
}


Measured memory_bytes: 3636
def furui(n):
    if n < 2:
        return []
    plist = [1 for i in range(n)]
    plist[0] = plist[1] = 0
    for i in range(2, n):
        if plist[i]:
            for j in range(i*2, n, i):
                plist[j] = 0
    ret = []
    for i in range(n):
        if plist[i] != 0:
            ret.append(i)
    return ret


primes = furui(1000000)
count = 0
N = int(input())


if N == 1:
    print(0)
else:
    # 素因数分解する
    factors = []
    for p in primes:
        if N % p == 0:
            e = 1
            while N % (p ** (e+1)) == 0:
                e += 1
            factors.append((p, e))
            N /= p ** e
    if N != 1:
        # 10^6より大きい素数
        factors.append((N, 1))
    # print(factors)

    # 数える
    count = 0
    for p, e in factors:
        s = 0
        for i in range(1, e+1):
            s += i
            if s <= e:
                # print(p ** i)
                count += 1
            else:
                break
    print(count)


Measured memory_bytes: 19968
/**
 *      ABC 89 A
 *      author  : kyomukyomupurin
 *      created : 2018-09-01 00:21:09
**/

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int N; cin >> N;
    cout << N / 3 << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.math.BigInteger;

class Main {

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

        int[] dp = new int[n + 1];
        for(int i = 0; i < n + 1; i++) {
            dp[i] = 2 * n;
        }

        dp[0] = 0;
        for(int i = 0; i < n; i++) {
            dp[i + 1] = Math.min(dp[i+1],dp[i] + 1);
            for(int j = 1; j < n; j++) {
                int tmp = i + (int)Math.pow(6,j);
                if(tmp > n) break;
                dp[tmp] = Math.min(dp[tmp],dp[i]+1);
            }
            for(int j = 1; j < n; j++) {
                int tmp = i + (int)Math.pow(9,j);
                if(tmp > n) break;
                dp[tmp] = Math.min(dp[tmp],dp[i]+1);
            }            
        }

        System.out.println(dp[n]);
        





    }
}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll dp[1120005];
ll a[112005];
ll b[211005];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll h,n;
    cin>>h>>n;
    ll ans=999999999;
    for(int i=1;i<=n;i++)
        cin>>a[i]>>b[i];
    for(int i=1;i<=210004;i++)
      dp[i]=999999999;
    for(int i=1;i<=n;i++)
    {

        for(int j=a[i];j<=h+10000;j++)
        {

            dp[j]=min(dp[j],dp[j-a[i]]+b[i]);
        }
    }
    for(int i=h;i<=h+10000;i++)
    {

        ans=min(ans,dp[i]);
    }


    cout<<ans<<'\n';


}













Measured memory_bytes: 4352
n=int(input())
li=[]
cnt=[]
for i in range(n):
    x,y,h=map(int,input().split())
    li.append([x,y,h])
li=sorted(li,key=lambda x:x[2],reverse=True)    
for j in range(0,101):
    for k in range(0,101):
        for l in range(n):
            if li[l][2]!=0:
                cnt.append(li[l][2]+abs(li[l][0]-j)+abs(li[l][1]-k))
            elif l!=0 and li[l][2]==0:
                if len(cnt)!=0 and cnt[0]-abs(li[l][0]-j)-abs(li[l][1]-k)>0:
                    cnt.append(0)               
        if len(set(cnt))==1 and cnt[0]-abs(li[0][0]-j)-abs(li[0][1]-k)==li[0][2]:
            ans=[j,k,cnt[0]]
            break
        else:
            cnt=[]

print(ans[0],ans[1],ans[2])                
           
        
        
    
    

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
	int cakesMaxCount; // 4 dollar
	int donutsMaxCount; // 7 dpllar
	int N;
	
	string answer = "No" ;

	cin >> N;
	
	cakesMaxCount = N / 4;
	donutsMaxCount = N / 7;

	for (int i = 0 ; i <= cakesMaxCount; i++) {
		for (int j = 0; j <= donutsMaxCount ; j++) {
			if ( 4 * i + 7 * j == N ) {
				answer = "Yes";
			}
		}
	}
	
	cout << answer << endl;
	return 0;
}

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

string divide[4] = {"dream", "dreamer", "erase", "eraser"};

int main(){
    string S;
    cin >> S;

    //逆順にすることにより擬似的に後ろから解く
    reverse(S.begin(), S.end());
    for (int i = 0; i < 4; i ++){
        reverse(divide[i].begin(), divide[i].end());
    }
        //端から切っていく
        bool can = true;
        for (int i = 0; i < S.size();){
            bool can2 = false;
            for (int j = 0; j < 4; ++j){
                string d = divide[j];
                if (S.substr(i, d.size()) == d){
                    can2 = true;
                    i += d.size(); // divideできたら位置を進める
                }
            }
            if (!can2){ // divide出来ない時
                can = false;
                break;
            }
        }
    if (can) cout << "YES" << endl;
    else cout << "NO" << endl;
    
}

Measured memory_bytes: 512
#include <iostream>

using namespace std;

int* f;

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

	f = new int[N + 1];
	for (int i = 0; i < N + 1; i++) {
		f[i] = 1;
	}

	for (int i = 2; i <= N; i++) {
		int j = i;
		while (j <= N) {
			f[j]++;
			j += i;
		}
	}
	long long ans = 0;
	for (int i = 1; i <= N; i++) {
		ans += i * f[i];
	}

	cout << ans << endl;

	delete[] f;

	return 0;
}


Measured memory_bytes: 41824
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use itertools::Itertools;
use num::clamp;
use proconio::{input, marker::*, fastout};
use superslice::*;

#[fastout()]
fn main() {
    input! {
        h: usize, w: usize,
        mut a: [[i64; w]; h]
    }

    let mut opes = Vec::new();
    for y in 0..h {
        for x in 0..w {
            if a[y][x] % 2 == 0 {
                continue;
            }
            if x != w - 1 {
                a[y][x] -= 1;
                a[y][x + 1] += 1;
                opes.push((y, x, y, x + 1));
            } else if y != h - 1 {
                a[y][x] -= 1;
                a[y + 1][x] += 1;
                opes.push((y, x, y + 1, x));
            }
        }
    }

    println!("{}", opes.len());
    for (y1, x1, y2, x2) in opes {
        println!("{} {} {} {}", y1+1, x1+1, y2+1, x2+1);
    }
}


Measured memory_bytes: 8736
#include <stdio.h>
#include <stdlib.h>
#define MAX_LENGTH 100
int ini[3][3];
int changed[3][3];
int dxn[4] = {0, 1, 0, -1};
int dyn[4] = {1, 0, -1, 0};
void makeEmpty(int *row, int *column)
{
    for(int i=0;i<3;i++)
    {
        for(int j=0;j<3;j++)
        {
            if(!ini[i][j]){*column = i;*row = j;}
        }
    }
}
int calculate()
{
    int countSum = 0;
    for(int i=0;i<9;i++)
    {
        int temp = ini[i/3][i%3];
        if(temp)
        {
            temp--;
            countSum += abs(i/3-temp/3)+abs(i%3-temp%3);
        }
    }
    return countSum;
}
int depthFirstSearch(int x, int y, int k, int depth, const int limit)
{
    int length;
    length = calculate();
    if (length == 0)return depth;
    if (depth + length > limit)return -1;
    for (int i = 0; i < 4; i++)
    {
        int a = x + dxn[i];
        int b = y + dyn[i];
        if (~k && i == (k + 2) % 4)continue;
        if (!(0 <= a && a < 3 && 0 <= b && b < 3))continue;
        int tem = ini[y][x];
        ini[y][x]=ini[b][a];
        ini[b][a]=tem;
        int res = depthFirstSearch(a, b, i, depth + 1, limit);
        if (~res)return res;
        int te = ini[y][x];
        ini[y][x]=ini[b][a];
        ini[b][a]=te;
    }
    return -1;
}
int main() {
    int row, column=0;
    int step;
    for(int i=0;i<3;i++)
    {
        for(int j=0;j<3;j++){scanf("%d", &ini[i][j]);}
    }
    makeEmpty(&row, &column);
    for(int l=0;l<MAX_LENGTH;l++)
    {
        for(int i=0;i<3;i++)
        {
            for(int j=0;j<3;j++){changed[i][j]=ini[i][j];}
        }
        if((step = depthFirstSearch(row, column, -1, 0, l))!=-1)
        {
            printf("%d\n", step);
            break;
        }
        for(int i=0;i<3;i++)
        {
            for(int j=0;j<3;j++){ini[i][j]=changed[i][j];}
        }
        step = -1;
        if(l==MAX_LENGTH-1){printf("%d\n", step);}
    }
    return 0;
}




Measured memory_bytes: 2148
#include <iostream>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <sstream>
#include <string>
#include <functional>
#include <queue>
#include <stack>
#include <limits>
#include <unordered_map>
#include <unordered_set>
#include <math.h>
#include <fstream>
#include <iterator>
#include <random>
#include <chrono>


#define forr(i,start,count) for (int i = (start); i < (start)+(count); ++i)
#define set_map_includes(set, elt) (set.find((elt)) != set.end())
#define readint(i) int i; cin >> i
#define readll(i) ll i; cin >> i
#define readdouble(i) double i; cin >> i
#define readstring(s) string s; cin >> s

typedef long long ll;

using namespace std;



int main()   {
    cout.precision(17);
    ll modd = 1000 * 1000 * 1000 + 7;
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    uniform_int_distribution<int> rand_gen(0, modd);   // rand_gen(rng) gets the rand no
    ll infinit = 10000000000000000;

/*    int n = 50;
    vector<int> a(n*n);
    forr(i,0,n*n) { a[i] = i+1; }
    forr(i,0,n*n) {
        int k = rand_gen(rng) % (n*n);
        swap(a[0], a[k]);
    }

    cout << n << endl;
    for(auto x : a) {cout << x << " "; } cout << endl;
    return 0;  */

//    readint(test_cases);

// 3841 is correct for current ac2.in !!!!!!!

    forr(t, 1, 1) {
        readint(n);

        int ret = 0;
        vector<bool> already_gone(n*n, false);
        vector<int> answer(n*n);
        forr(i,0,n) {
            forr(j,0,n) {
                answer[n*i+j] = min({i,j,n-1-i,n-1-j});
            }
        }

        forr(i,0,n*n) {
          readint(kk); kk--;
          ret += answer[kk];
          already_gone[kk] = true;

          stack<int> todo;

          todo.push(kk);

          while (!todo.empty()) {
            int current = todo.top(); todo.pop();

            int val = answer[current] + !already_gone[current];
            for (int dir : vector<int>{-1,1,n,-n}) {
                int x = current + dir;
                if ((x >= 0) && (x < n*n) && ((x%n==current%n) || (x/n==current/n))) {
                  if (answer[x] > val) {
                    answer[x] = val;
                    todo.push(x);
                  }
                }
            }
          }
        }

        cout << ret << endl;
    }
    return 0;
}


Measured memory_bytes: 4912
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<iostream>
#include<string>
using namespace std;


int main() {

	int dept = 100000;

	int n;

	cin >> n;

	for (int i = 0; i < n; i++) {
		dept = (int)((double)dept*1.05);

		if (dept % 1000 != 0) {

			dept = dept - (dept % 1000) + 1000;
		}





	}
	printf("%d\n", dept);

	//system("pause");
	return 0;
}


Measured memory_bytes: 3068
#include <stdio.h>
int main(void){
    int W,H,x,y,r;
    scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
    if ( x-r>=0 && x+r<=W && y-r>=0 && y+r<=H )
    printf("Yes\n");
    else
    printf("No\n");
    return 0;
}



Measured memory_bytes: 2104
#include <iostream>
#include <cstdint>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <algorithm>

#include <iostream>
 
int main(void)
{
    int64_t N, A, B;
    std::cin >> N >> A >> B;

    int64_t cost_train = A * N;

    std::cout << ((cost_train < B) ? cost_train : B) << std::endl;

    return 0;
}

Measured memory_bytes: 256