akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <boost/range.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/algorithm_ext.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/adaptors.hpp>
#include <boost/range/irange.hpp>
using namespace std;
constexpr char nl = '\n';
using ll = long long;
using boost::irange;
using boost::adaptors::reversed;
namespace rng { using namespace boost; using namespace boost::range; }
struct init_ { init_(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); } } init_;

template<class C> auto operator>>(istream& in, C& c) -> typename enable_if<!is_void<decltype(c.begin())>::value && !is_same<C, string>::value, istream&>::type {
    for (auto& v : c) { in >> v; } return in; }
template<class C> auto operator<<(ostream& out, const C& c) -> typename enable_if<!is_void<decltype(c.begin())>::value && !is_same<C, string>::value, ostream&>::type {
    int i = 0; for (const auto& v : c) { if (i++) { out << ' '; } out << v; } return out; }
template<size_t N, class T, class R> using when_last = typename enable_if<N == tuple_size<remove_reference_t<T>>::value - 1, R>::type;
template<size_t N, class T, class R> using when_init = typename enable_if<N != tuple_size<remove_reference_t<T>>::value - 1, R>::type;
template<size_t N = 0, class T> auto operator>>(istream& in, T&& t) -> when_last<N, T, istream&> { return in >> get<N>(t); }
template<size_t N = 0, class T> auto operator>>(istream& in, T&& t) -> when_init<N, T, istream&> { return operator>><N + 1>(in >> get<N>(t), forward<T>(t)); }
template<size_t N = 0, class T> auto operator<<(ostream& out, const T& t) -> when_last<N, T, ostream&> { return out << get<N>(t); }
template<size_t N = 0, class T> auto operator<<(ostream& out, const T& t) -> when_init<N, T, ostream&> { return operator<<<N + 1>(out << get<N>(t) << ' ', t); }

#ifdef LOCAL
constexpr auto color_s_ = "\033[2m\033[33m", color_e_ = "\033[0m";
template<class T> void trace_(const T& v) { cerr << v; }
template<class T> void trace_(const vector<vector<T>>& m) { cerr << "\n"; for (const auto& v : m) { trace_(v); cerr << "\n"; } }
template<class T> void trace_(const char* s, const T& v) { cerr << color_s_ << s << "="; trace_(v); cerr << color_e_ << "\n"; cerr.flush(); }
template<class T, class... Ts> void trace_(const char* s, const T& v, const Ts&... vs) { cerr << color_s_; for (; *s != ','; ++s) { cerr << *s; } cerr << "="; trace_(v); cerr << ","; trace_(++s, vs...); }
#define TRACE(...) trace_(#__VA_ARGS__, __VA_ARGS__)
#else
#define TRACE(...)
#endif

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    cin >> a;
    int negs = 0;
    ll sum = 0;
    int min_a = numeric_limits<int>::max();
    for (int& ai : a) {
        if (ai < 0) {
            negs++;
            ai = -ai;
        }
        sum += ai;
        min_a = min(min_a, ai);
    }
    if (negs % 2 == 0) {
        cout << sum << nl;
    } else {
        cout << (sum - 2 * min_a) << nl;
    }
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int x;
  cin>>x;
  if(x>=0&&x<=1)
  {
    if(x==0)
      cout<<"1"<<endl;
    else if(x==1)
    cout<<"0"<<endl;
  }
  return 0;
}

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

int main(){
	int N,M;
	cin >> N >> M;
	vector<int> L(M),R(M);
	rep(i, M){
		cin >> L[i] >> R[i];
	}
	sort(L.begin(),L.end());
	sort(R.begin(),R.end());
	int ans = max(0, R[0]-L[M-1]+1);
	cout << ans << endl;
	return 0;
}

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

#define ll long long

void exgcd(int a, int b, int& x, int& y) {
  if (!b) {
    x = 1, y = 0;
  } else {
    exgcd(b, a % b, y, x);
    y -= (a / b) * x;
  }
}

int inv(int a, int n) {
  int x, y;
  exgcd(a, n, x, y);
  return (x < 0) ? (x + n) : (x);
}

const int Mod = 1e9 + 7;

template <const int Mod = :: Mod>
class Z {
  public:
    int v;

    Z() : v(0) {	}
    Z(int x) : v(x){	}
    Z(ll x) : v(x % Mod) {	}

    friend Z operator + (const Z& a, const Z& b) {
      int x;
      return Z(((x = a.v + b.v) >= Mod) ? (x - Mod) : (x));
    }
    friend Z operator - (const Z& a, const Z& b) {
      int x;
      return Z(((x = a.v - b.v) < 0) ? (x + Mod) : (x));
    }
    friend Z operator * (const Z& a, const Z& b) {
      return Z(a.v * 1ll * b.v);
    }
    friend Z operator ~(const Z& a) {
      return inv(a.v, Mod);
    }
    friend Z operator - (const Z& a) {
      return Z(0) - a;
    }
    Z& operator += (Z b) {
      return *this = *this + b;
    }
    Z& operator -= (Z b) {
      return *this = *this - b;
    }
    Z& operator *= (Z b) {
      return *this = *this * b;
    }
};

Z<> qpow(Z<> a, int p) {
  Z<> rt = Z<>(1), pa = a;
  for ( ; p; p >>= 1, pa = pa * pa) {
    if (p & 1) {
      rt = rt * pa;
    }
  }
  return rt;
}

typedef Z<> Zi;

const int N = 5005;

int n, A, B;
Zi f[N], g[N][2];

int main() {
  scanf("%d%d%d", &n, &A, &B);
  if (A > B) {
    swap(A, B);
  }
  f[0] = 1;
  for (int i = 1; i <= B; i++) {
    f[i] = f[i - 1];
    for (int j = A; j <= i; j++) {
      if (j == i) {
        f[i] += 1;
      } else {
        f[i] += f[i - j - 1];
      }
    }
  }
  g[0][0] = 1;
  for (int i = 1; i < B; i++) {
    g[i][0] = f[i - 1]; 
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j < B && j <= i; j++) {
      g[i][0] += g[i - j][1] * ((j == 1) ? 1 : f[j - 2]);
    }
    for (int j = 1; j < A && j <= i; j++) {
      g[i][1] += g[i - j][0];
    }
  }
  Zi ans = g[n][1];
  for (int i = 1; i < B; i++) {
    ans += g[n - i][1] * f[i - 1];
  }
  ans = qpow(2, n) - ans;
  printf("%d\n", ans.v);
  return 0;
}


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

using namespace std;

#define int long long
#define endl '\n'
#define MOD 1000000007
#define maxn 100010

void solve() {
    int k, x;
    cin >> k >> x;

    string ans = (500 * k >= x) ? "Yes" : "No";
    cout << ans << endl;
}

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

    int t = 1;
//    cin >> t;

    while (t--)
        solve();
    return 0;
}

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


void solve(long long n, std::vector<long long> a){
  sort(a.begin(), a.end());
  auto m = a.back();
  long long r=INF;
  if(m%2==0){
    long long half=m/2;
    for(auto it=a.begin();it!=a.end();++it){
      if(abs(half-r)>abs(half-*it)){
        r = *it;
      }
    }
  }else{
    long long r2=INF;
    for(auto it=a.begin();it!=a.end();++it){
      long long it2 = (m/2 > *it) ? *it : m-*it;
      long long half = m/2;
      if(abs(half-r2)>abs(half-it2)){
        r=*it;
        r2=it2;
      }
    }
  }
  cout << m <<" "<<  r << "\n";
}

// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
  long long n;
  scanf("%lld",&n);
  std::vector<long long> a(n);
  for(int i = 0 ; i < n ; i++){
    scanf("%lld",&a[i]);
  }
  solve(n, std::move(a));
  return 0;
}


Measured memory_bytes: 1024
// #define DEBUGGING
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()

template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
using ll = int64_t;
using ull = uint64_t;
using PLL = pair<ll, ll>;

template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return max(low, min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { t = clamp(t, low, high); }

namespace init__ {

struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

}

#ifdef DEBUGGING
// #include "../debug/debug.cpp"
#include "../../debug/debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

template <typename T>
T make_v(T init) { return init; }

template <typename T, typename... Tail>
auto make_v(T init, size_t s, Tail... tail) {
#define rec make_v(init, tail...)
    return V<decltype(rec)>(s, rec);
#undef rec
}

bool solve() {
    ll N;
    cin >> N;
    V<ll> H(N);
    for(auto &&ele : H) cin >> ele;
    ll maxh = H[0], minh = H[0] - 1;
    for(ll i = 1; i < N; i++) {
        if(H[i] < minh) return false;
        if(H[i] == minh) {
            maxh = minh = H[i];
        } else {
            maxh = H[i];
            minh = H[i] - 1;
        }
    }

    return true;
}

int main() {
    cout << (solve() ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define RI register int
typedef long long LL;
#define int LL

#define FILEIO(name) freopen(name".in", "r", stdin), freopen(name".out", "w", stdout);

using namespace std;

char buf[1000000], *p1 = buf, *p2 = buf;
inline char gc() {
  if (p1 == p2) p2 = (p1 = buf) + fread(buf, 1, 1000000, stdin);
  return p1 == p2 ? EOF : *(p1++);
}
template <class T> inline void read(T &n) {
  n = 0; RI ch = gc(), f;
  while ((ch < '0' || ch > '9') && ch != '-') ch = gc();
  f = (ch == '-' ? ch = gc(), -1 : 1);
  while (ch >= '0' && ch <= '9') n = n * 10 + (ch ^ 48), ch = gc();
  n *= f;
}

int const MAXN = 2e5 + 5;
int a[MAXN], vis[MAXN];

signed main() {
  
#ifdef LOCAL
  FILEIO("a");
#endif

  int n; LL k;
  read(n), read(k);
  for (RI i = 1; i <= n; ++i) read(a[i]);
  int now = 1;
  if (k > n) {
    int cnt = 0;
    while (666) {
      now = a[now];
      if (vis[now]) {
        int tim = cnt - vis[now] + 1;
        k -= vis[now];
        k %= tim;
        k += vis[now];
        break;
      }
      else vis[now] = ++cnt;
    }
  }
  now = 1;
  for (RI i = 1; i <= k; ++i) now = a[now];
  printf("%lld\n", now);

  return 0;
}

// created by Daniel yuan
/*
     ________
    /        \
   / /      \ \
  / /        \ \
  \            /
   \  ______  /
    \________/
*/


Measured memory_bytes: 7800
import sys
sys.setrecursionlimit(10 ** 6)

def dfs(here_w, here_h):
    if 0 <= here_w < width and 0 <= here_h < height:
        if target[here_h][here_w]:
            target[here_h][here_w] = 0
            for x, y in all_move:
                dfs(here_w + x, here_h + y)
                
all_move = [[1, 1], [1, 0], [1, -1], [0, 1], [0, -1], [-1, 1], [-1, 0], [-1, -1]]
while True:
    width, height = map(int, input().split(" "))
    if not width:
        break
    target = []
    for h in range(height):
        temp = [int(n) for n in input().split(" ")]
        target.append(temp)
    # print(width, height, temp)
    answer = 0
    for h in range(height):
        for w in range(width):
            if target[h][w]:
                answer += 1
                dfs(w, h)
    print(answer)
                
            


Measured memory_bytes: 7920
import sys
input = lambda: sys.stdin.readline().rstrip()

n = int(input())
edges = []
ans = 0
for _ in range(n-1):
   u, v = map(int, input().split())
   edges.append([min(u, v), max(u, v)])

for l in range(1, n+1):
   ans += (n - l + 1) * (n - l + 2) // 2

for l, r in edges:
   ans -= (l) * (n - r + 1)
print(ans)


Measured memory_bytes: 96172
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

int n, x, col[10];

int judge( int a )
{
	if(a >= 1 && a <= 399) return 1;
	else if(a <= 799) return 2;
	else if(a <= 1199) return 3;
	else if(a <= 1599) return 4;
	else if(a <= 1999) return 5;
	else if(a <= 2399) return 6;
	else if(a <= 2799) return 7;
	else if(a <= 3199) return 8;
	else return 9;
}

int main()
{
	int ans = 0, cnt = 0;
	cin >> n;
	for(int i = 1; i <= n; i++)
	{
		scanf( "%d", &x );
		int jud = judge(x);
		//cout << x << " " << jud << endl;
		if(jud == 9)
				cnt++;
		else
		{
			if(!col[jud]) ans++, col[jud] = 1;
		}
	}
	if(ans != 0)
		cout << ans << " " << ans + cnt << endl;
	else cout << "1" << " " << cnt << endl;
	return 0;
}

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

#define __STDC_FORMAT_MACROS
#define p64 PRId64

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR (i, 0, n)
#define ALL(f, x, ...)                                                         \
    ([&] (decltype ((x)) ALL) {                                                \
        return (f) (begin (ALL), end (ALL), ##__VA_ARGS__);                    \
    }) (x)

using namespace std;
using ll = int64_t;

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

    c = getchar_unlocked();

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

    while (true) {
        c = getchar_unlocked();

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

    if (s)
        x = -x;
}

int main() {
    int H, N;
    gc (H);
    gc (N);
    int A, accum;
    accum = 0;
    REP (i, N) {
        gc (A);
        accum += A;
    }
    cout << (1 < (double)H / accum ? "No" : "Yes") << endl;
    return 0;
}


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

using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
typedef long int li;
const int MAX_N=100;
string s[MAX_N];
int main()
{
    IOS;
    //freopen("fr1.txt","r",stdin);
    int r;
    cin>>r;
    cout<<r*r<<endl;
    return 0;
}

Measured memory_bytes: 3600
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>
#include <functional>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
template<typename T> using VT = vector<T>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back
template<typename T> inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

int main(void) {
    int N, K;
    cin >> N >> K;
    VL x(N);
    REP(i, N) cin >> x[i];
    LL ans = LLINF;
    REP(i, N) {
        if (i + K - 1 < N) {
            LL left = x[i], right = x[i + K - 1];
            if (left < 0) {
                if (right < 0) {
                    chmin(ans, -left);
                } else {
                    chmin(ans, llabs(left) * 2 + llabs(right));
                    chmin(ans, llabs(left) + llabs(right) * 2);
                }
            } else {
                if (right >= 0) {
                    chmin(ans, right);
                } else {
                    assert(false);
                }
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
import           Control.Monad

main :: IO ()
main = do
    [n, t] <- fmap (map read . words) getLine :: IO [Int]
    cts    <- replicateM n $ fmap (map read . words) getLine :: IO [[Int]]
    solve t cts

solve :: Int -> [[Int]] -> IO ()
solve t cts =
    let cs = map (\v -> if last v <= t then head v else 10000) cts
    in  case minimum cs of
            10000 -> putStrLn "TLE"
            c     -> print c


Measured memory_bytes: 1020
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>
#include <cassert>
#include <random>

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll conbinationMemo[100][100];

void cmemoInit(){
    rep(i, 100){
        rep(j, 100){
            conbinationMemo[i][j] = -1;
        }
    }
}
 
ll nCr(ll n, ll r){
    if(conbinationMemo[n][r] != -1) return conbinationMemo[n][r];
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return conbinationMemo[n][r] = (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
//-----------------------ここから-----------
int main(void){
    ll n;
    cin >> n;
    vector<ll> a(n), b(n);
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> b[i];;

    vector<ll> rb = b;

    reverse(all(rb));

    vector<ll> same;

    rep(i, n){
        if(a[i] == rb[i]){
            same.push_back(i);
        }
    }

    vector<ll> ans = rb;
    ll bidx = n - 1;
    rep(i, same.size() / 2){
        swap(ans[same[i]], ans[bidx]);
        bidx--;
    }
    ll fidx = 0;
    for(ll i = (ll)same.size() - 1; i >= (ll)same.size() / 2; i--){
        swap(ans[same[i]], ans[fidx]);
        fidx++;
    }
    bool ok = true;
    rep(i, n){
        if(ans[i] == a[i]) ok = false;
    }

    if(ok){
        cout << "Yes" << endl;
        rep(i, n) cout << ans[i] << " ";
        cout << endl;
    } else {
        cout << "No" << endl;
    }

}



Measured memory_bytes: 11076
from collections import Counter

def gcd(a, b):
    while b:
        a, b = b, a%b
    return a

K = int(input())

Gs = []
for a in range(1, K+1):
    for b in range(1, K+1):
        Gs.append(gcd(a, b))

cnt = Counter(Gs)
#print('cnt:', cnt)

ans = 0
for G, num in cnt.items():
    for c in range(1, K+1):
        ans += gcd(G, c) * num

print(ans)


Measured memory_bytes: 9772
#python3

def main():
    n = int(input())
    t = [int(i) for i in input().split()]
    m = int(input()) 
    for _ in range(m):
        newt = t.copy()
        p, x = map(int, input().split()) 
        newt[p-1] = x
        print(sum(newt)) 
main()



Measured memory_bytes: 3060
n,k = map(int,input().split())
a = list(map(int,input().split()))

b = []
for i in range(n):
    r = 0
    for j in range(i,n):
        r += a[j]
        b.append(r)


n2 = n*(n+1)//2

res = 0
for i in range(41):
    p = res + 2**(40-i)
    
    c = 0
    for j in range(n2):
        if p == p&b[j]:
            c+=1
    
    if c >= k:
        res = p

print(res)

Measured memory_bytes: 67196
import java.util.Arrays;
import java.util.Scanner;
public class Main{

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan =new Scanner(System.in);
		int N=scan.nextInt();
		int K=scan.nextInt();
		int[] kingaku=new int[N];
		int goukei=0;
		for(int i=0;i<kingaku.length;i++) {
			kingaku[i]=scan.nextInt();
		}
		Arrays.sort(kingaku);
		for(int i=0;i<K;i++) {
			goukei+=kingaku[i];
		}
		System.out.println(goukei);
	}
}

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

Measured memory_bytes: 3608
#include<stdio.h>
int main()
{
    int i,n;
    double t=0;
    double m;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        if(i%2!=0)
            t++;
    }
    m=t/n;
    printf("%lf",m);
}


Measured memory_bytes: 128
#!/usr/bin/env python
# -*- coding: utf-8 -*-

s = input()
K = int(input())

os = sorted(list(set(s).union()))

nth = 0
found = []
for o in os:
  samehead = []
  for i in range(len(s)):
    if s[i] == o:
      for j in range(i+1, len(s)+1):
        if j-i>K: break
        if s[i:j] in samehead: continue
        samehead.append(s[i:j])
  cands = sorted(samehead)
  if nth + len(cands) < K:
    found += samehead
    nth += len(cands)
    continue
  print(cands[K-nth-1])
  break


Measured memory_bytes: 3064
#include<iostream>
#include<string>

using namespace std;

int main() {
	char b;
	cin >> b;
	if(b == 'A') {
		cout << "T";
	}
	else if(b == 'C') {
		cout << "G";
	}
	else if(b == 'G') {
		cout << "C";
    }
	else {
		cout << "A";
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<cmath>
#include<bitset>
#include<bits/stdc++.h>

#define ll long long int
#define N 1000000
using namespace std;

main()
{
	ll n;
	cin>>n;
	ll a[n];
	ll x=0;
	for(ll i=0;i<n;i++)
		{
		cin>>a[i];
			x=x^a[i];
		}
			
	for(ll i=0;i<n;i++)
		cout<<(a[i]^x)<<" ";
		
	
}

Measured memory_bytes: 5120
package main

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

//============================================================
var sc = bufio.NewScanner(os.Stdin)

func setScSplit() { sc.Split(bufio.ScanWords) }

func readStr() string {
	sc.Scan()

	return sc.Text()
}

func readInt() int {
	i, _ := strconv.Atoi(readStr())

	return i
}

func readFloat() float64 {
	f, _ := strconv.ParseFloat(readStr(), 64)

	return f
}

//=============================================================

func main() {
	setScSplit()

	S := readStr()

	s1 := "2018"
	s2 := S[4:]

	fmt.Println(s1 + s2)
}

Measured memory_bytes: 640
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
const int MAXN = 1005;
const int MAXV = 1000000;
//各試合にidを割り振って、グラフを書く。DAGなら最長路をdfsで検出する

int id[MAXN][MAXN];
int dp[MAXV];
bool visited[MAXV];
bool finished[MAXV];
vector<int> to[MAXV];

int toId(int i, int j){
  if(i > j) swap(i,j);
  return id[i][j];
}

int dfs(int v){
  if(visited[v]){
    if(!finished[v]) return -1;
    return dp[v];
  }
  visited[v] = 1;
  dp[v]=1;
  for(auto &u : to[v]){
    int res = dfs(u);
    if(res == -1) return -1;
    dp[v] = max(dp[v],dfs(u)+1);
  }
  finished[v] = 1;
  return dp[v];
}

int main(){
  int n; cin >> n;
  vector<vector<int>> a(n,vector<int>(n-1));
  rep(i,n){
    rep(j,n-1){
      cin >> a[i][j];
      a[i][j]--;
    }
  }
  int num_of_vertex = 0;
  //試合にidを割り振る
  rep(i,n){
    rep(j,n){
      if(i < j) id[i][j] = num_of_vertex++;
    }
  }
  int list[MAXN][MAXN];  //iの人はj番目にidが何の試合をしますか（試合の順番）
  rep(i,n){
    rep(j,n-1) list[i][j] = toId(i,a[i][j]);
    rep(j,n-2) to[list[i][j+1]].push_back(list[i][j]);
  }
  int ans = 0; 
  rep(i,num_of_vertex){
    int res = dfs(i);
    if(res == -1){
      cout << -1 << endl;
      return 0;
    }
    ans = max(ans,dfs(i));
  }
  cout << ans << endl;
  return 0;
} 

Measured memory_bytes: 56960
#include <iostream>

int main(){
  long Num;
  long Sum=0;
  std::cin >> Num;
  for(int i=1;i<=Num;i++){
    if(i % 5 != 0 && i % 3 != 0)
      Sum += i;
  }

  std::cout << Sum << std::endl;
  
  return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define mp make_pair
using namespace std;

using ll = long long;
using ii = pair<int, int>;
const int INF = (int)10e9;

int dp[3005][3005];

string res = "";
string s, t;

void reconstruct(int i, int j) {
	if(i <= 0 || j <= 0) return;
	if(s[i-1] == t[j-1]) {
		res = s[i-1] + res;
		reconstruct(i-1, j-1);
	} else {
		if(dp[i-1][j] > dp[i][j-1]) reconstruct(i-1, j);
		else reconstruct(i, j-1);
	}
}

int main() {
	std::ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	
	cin >> s >> t;
	
	for(int i = 1; i <= s.length(); i++) {
		for(int j = 1; j <= t.length(); j++) {
			if(s[i-1] == t[j-1]) dp[i][j] = 1 + dp[i-1][j-1];
			else dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
		}
	}
	reconstruct(s.length(), t.length());
	cout<<res<<endl;

    return 0;
}


Measured memory_bytes: 35968
import copy
n=int(input())
a=list(map(int,input().split()))
absa=[]

for i in a:
  absa.append(abs(i))

mi=0
pl=0
for i in a:
  if i<0:
    mi+=1
  else:
    pl+=1

#その配列が-がいるか全部非負にできるかの判定…
def jud(x):
  temp=copy.copy(x)
  for i in range(len(temp)-1):
    if temp[i]>=0:
      continue
    else:
      temp[i]*=-1
      temp[i+1]*=-1
  if temp[-1]>=0:
    return 1
  else:
    return 0

if jud(a)==1:
  print(sum(absa))
else:
  print(sum(absa)-min(absa)*2)

Measured memory_bytes: 15680
n, m, x, y = readline.split.map(&:to_i)
xs = readline.split.map(&:to_i)
ys = readline.split.map(&:to_i)
xm = xs.max
ym = ys.min
if xm < ym and x < ym and xm < y then
	print("No War")
else
	print("War")
end

Measured memory_bytes: 1788
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  int N;
  cin>>N;
  lint a[N],b[N];
  REP(i,N)cin>>a[i];
  REP(i,N)cin>>b[i];
  lint sum=0;
  REP(i,N)sum+=b[i]-a[i];
  lint c=0;
  REP(i,N){
    if(a[i]<b[i]){
      int k=(b[i]-a[i]+1)/2;
      c+=k;
    }
  }
  cout<<(sum>=c?"Yes":"No")<<endl;
  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int findSmallestElement(int arr[], int n){

   int temp = arr[0];
   for(int i=0; i<n; i++) {
      if(temp>arr[i]) {
         temp=arr[i];
      }
   }
   return temp;
}
int main()
{

    int a,b,c,a_1,a_2,a_3,a_4,a_5,a_6;
    cin>>a>>b>>c;

    a_1=a+b;
    a_2=c+b;
    a_3=a+c;
    a_4= b+c;
    a_5=c+a;
    a_6=b+a;
    int arr[]={a_1,a_2,a_3,a_4,a_5,a_6};
     int n=sizeof(arr)/sizeof(arr[0]);
     int smallest = findSmallestElement(arr, n);
   cout<<smallest<<endl;
   return 0;


}


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

int solve(int x, int y, int s) {
  int max_price = 0;
  for (int i = 1; i < s/2 + 1; i++) {
    int a = i * (100 + x) / 100;
    int _b = (s - a) * 100 / (100 + x);
    while(true) {
      int b = _b * (100 + x) / 100;
      if (a + b > s) break;
      if (a + b == s) {
        int price = i * (100 + y) / 100 + _b * (100 + y) / 100;
        max_price = max(max_price, price);
      }
      _b++;
    }
  }
  return max_price;
}                                                                                                              

int main() {
  int x, y, s;
  while(cin >> x >> y >> s && x > 0) {
    cout << solve(x, y, s) << endl;
  }
  return 0;
}



Measured memory_bytes: 3084
//Optional FAST

//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")

//Required Libraries

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//Required namespaces

using namespace std;
using namespace __gnu_pbds;

//Required defines

#define endl '\n'

#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(long long i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define FORI(a,b,c) for(long long a=b;a<c;a++)
#define FORD(a,b,c) for(long long a=b;a>c;a--)

//Required typedefs

typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;

//Required Constants

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);
const long double PI=3.14159265358979;

// Required random number generators

// mt19937 gen_rand_int(chrono::steady_clock::now().time_since_epoch().count());
// mt19937_64 gen_rand_ll(chrono::steady_clock::now().time_since_epoch().count());

//Required Functions

ll power(ll x,ll y) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2) % MOD; 
    p = (p * p) % MOD; 
  
    return (y%2 == 0)? p : (x * p) % MOD; 
}
ll modInverse(ll a) 
{ 
   return power(a,MOD-2); 
   
}

//Work

ll dp[INIT];

int main()
{
    #ifndef ONLINE_JUDGE
    if (fopen("INPUT.txt", "r"))
    {
        freopen ("INPUT.txt" , "r" , stdin);
        //freopen ("OUTPUT.txt" , "w" , stdout);
    }
    #endif
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    clock_t clk;
    clk = clock();
//-----------------------------------------------------------------------------------------------------------//

    memset(dp,0,sizeof(dp));
    READV(N);
    vector<ll> A;
    ll all_false=false;
    FORI(i,0,N)
    {
        READV(x);
        A.pb(x);
        dp[x]++;
    }
    ll ans=0;
    FORI(i,0,N)
    {
        bool ok=true;
        dp[A[i]]--;
        for (ll j = 1; j*j <= A[i]; j++)
        {
            if(A[i]%j==0)
            {
                if(dp[A[i]/j] || dp[j])
                {
                    ok=false;
                }
            }
        }
        dp[A[i]]++;
        if(ok)
        {
            ans++;
        }
    }
    cout<<ans<<endl;

//-----------------------------------------------------------------------------------------------------------//


    clk = clock() - clk;
    cerr << fixed << setprecision(6) << "Time: " << ((double)clk)/CLOCKS_PER_SEC << endl;

    return 0;
}

Measured memory_bytes: 13204
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
 

public class Main{
          
     
     public static void main(String args[]){
         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
         
         try{
             String line;
             int count=0;
            while((line=br.readLine())!= null){if(line.isEmpty())break;
                char[] chars = line.toCharArray();
                char[] charsR=new char[chars.length];
                for(int i=0; i<chars.length;i++){
                    charsR[chars.length-1-i]=chars[i];
                }
                String r = String.valueOf(charsR);//System.out.println(r);
                if(r.equals(line)){count++;}
                
            }             br.close();
             System.out.println(count);
         }catch(Exception e){e.printStackTrace();}         
     }
     
}
  

Measured memory_bytes: 16868
function main(input) {
  const [a, b, c, d, e, k] = input.trim().split("\n").map(n => Number(n));
  let result = "Yay!";
  if (k < e-a) {
    result = ":(";
  }
  console.log(result);
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include<bits/stdc++.h>
#define _USE_MATH_DEFINES
using namespace std;
    
#define ll long long int
#define pb push_back
#define rep(i , j , n) for(ll i = j ; i < n ; i++)
#define pre(i , j , n) for(ll i = j ; i >= n ; i--)
#define all(x) x.begin(), x.end()
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vll;
typedef vector<char>	vc;
typedef vector<bool>	vb;
#define br "\n"
#define MAXIM 100003
ll mod = 1e9 + 7;


void solve(){
	ll n;
	cin >> n;
	if(n >= 30) cout << "Yes";
	else cout << "No";
}
 
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif  
	ll t = 1;
	// cin >> t;
	rep(i,0,t){
		solve();
	}
 
}

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

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    int ans=0, sum=a+b+c;
    if(a%2!=0&&a==b&&b==c){
        cout << ans << endl;
        return 0;
    }
    if(a==b&&b==c){
        cout << -1 << endl;
        return 0;
    }
    while(a%2==0&&b%2==0&&c%2==0){
        a = (sum-a)/2;
        b = (sum-b)/2;
        c = (sum-c)/2;
        ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    static Scanner scanner = new Scanner(System.in);

    public static void main(String[]$) {
        int n = scanner.nextInt();
        int[] h = new int[n];
        int[] t = new int[n];
        int[] a = new int[n];

        for (int i = 0; i < n; i++) {
            t[i] = scanner.nextInt();
            if (i == 0 || t[i - 1] != t[i]) {
                h[i] = t[i];
            }
        }
        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
            if (i == n - 1) {
                if (h[i] != 0 && h[i] != a[i]) {
                    System.out.println(0);
                    return;
                }
                h[i] = a[i];
            }
            if (i != 0 && a[i - 1] != a[i]) {
                if (h[i - 1] != 0 && h[i - 1] != a[i - 1]) {
                    System.out.println(0);
                    return;
                }
                h[i - 1] = a[i - 1];
            }
        }

        for (int i = 0; i < n; i++) {
            if (h[i] > t[i] || h[i] > a[i]) {
                System.out.println(0);
                return;
            }
        }

        long ans = 1;
        for (int i = 0; i < n; i++) {
            if (h[i] == 0) {
                ans = ans * Math.min(t[i], a[i]) % 1000000007;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 86696
use Math::Trig 'pi';

my ($a, $b, $h, $m) = map { int $_ } glob <>;

my $theta = abs(6 * $m - 30 * $h - 0.5 * $m);
my $theta_rad = (($theta > 180) ? 360 - $theta : $theta) * pi / 180;

my $c = sqrt($a**2 + $b**2 - 2 * $a * $b * cos($theta_rad));

printf("%.15f", $c);

Measured memory_bytes: 8008
D, G = map(int, input().split())
PC = [0] + [list(map(int, input().split())) for _ in range(D)]
def dfs(i, g):
    if i == 0:
        return 1e9
    m = min(g // (i * 100), PC[i][0])
    s = 100 * i * m
    if m == PC[i][0]:
        s += PC[i][1]
    if s < g:
        m += dfs(i - 1, g - s)
    return min(m, dfs(i - 1, g))
print(dfs(D, G))

Measured memory_bytes: 3188
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int main() {
  int n, k;
  string s;
  cin >> n >> k;
  cin >> s;
  --k;
  if (s[k] >= 'A' && s[k] <= 'Z') s[k] = s[k] - 'A' + 'a';
  cout << s << endl;
  return 0;
}


Measured memory_bytes: 768
N = int(input())
S = input()


def check(vlen):
    part = set()
    for l1 in range(N - vlen * 2 + 1):
        part.add(S[l1:l1 + vlen])
        l2 = l1 + vlen
        if S[l2:l2 + vlen] in part:
            return True
    return False


oklen = 0
nglen = N // 2 + 1

while nglen - oklen > 1:
    midlen = (oklen + nglen) // 2
    if check(midlen):
        oklen = midlen
    else:
        nglen = midlen
print(oklen)


Measured memory_bytes: 135644
import java.util.Scanner

//整数a(1~10^9)の2の因数の数を数える
fun num_two(a: Int): Int{
	var a_ = a
	var count = 0

	while(a_%2 == 0){
		count += 1
		a_ /= 2
	}

	return count
}

fun main(args: Array<String>){
	val sc = Scanner(System.`in`)
	
	val n = sc.nextLine()
	val s = sc.nextLine()

	val N = Integer.parseInt(n)
	val arr = s.split(" ")

	var sum = 0

	for(i in 0..N-1){
		var a = Integer.parseInt(arr[i])
		sum += num_two(a)
	}

	println(sum)
}

Measured memory_bytes: 41564
N = int(input())
S = " " + input() + " "

# 左を白、右を黒にする
# 白の個数、黒の個数、白、黒、、、、黒の個数
# という数列を作る
# 0は白、1は黒を意味する
num01 = []
white = 0
black = 0
if("#" == S[1]):
    num01 = [0]
for i in range(1, N + 1):
    if("." == S[i]):
        white += 1
    else:
        black += 1
    if(S[i - 1] != S[i]):
        st = i
    if(S[i] != S[i + 1]):
        num01.append(i - st + 1)
if("." == S[-2]):
    num01.append(0)
#print("num01= {}".format(num01))

minchg = N
# iの右側までを白とする
btow = 0
wtob = white
for i in range(len(num01)):
    if(i % 2):  # b | w
        btow += num01[i]
    else:   # w | b
        wtob -= num01[i]
    minchg = min(minchg, btow + wtob)

print(minchg)


Measured memory_bytes: 5156
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int> a(n); 
  vector<int> b(n); 
  vector<int> c(n);
  for(int i=0;i<n;i++){ 
    cin>>a[i]>>b[i]>>c[i];}
  vector<vector<int>> answer(3,vector<int>(n,0));
  answer[0][0]=a[0];
  answer[1][0]=b[0];
  answer[2][0]=c[0];
  for(int i=1;i<n;i++) 
  { answer[0][i]=a[i]+max(answer[1][i-1],answer[2][i-1]);
   answer[1][i]=b[i]+max(answer[0][i-1],answer[2][i-1]);
   answer[2][i]=c[i]+max(answer[1][i-1],answer[0][i-1]); } 
  cout<<max(answer[0][n-1],max(answer[1][n-1],answer[2][n-1])); 
  return 0; } 


Measured memory_bytes: 2944
#include <cstdio>
int ans[100005],n;
char a[100005];
int check() {
	for(int i = 1;i <= n;i ++) {
		int l = i - 1,r = i + 1;
		if(l == 0) l = n; 
		if(r == n + 1) r = 1;
		if(ans[i] == 1) {
			if(a[i] == 'o' && ans[l] != ans[r]) return 0;
			if(a[i] == 'x' && ans[l] == ans[r]) return 0;
		}
		else {
			if(a[i] == 'o' && ans[l] == ans[r]) return 0;
			if(a[i] == 'x' && ans[l] != ans[r]) return 0;
		}
	}
	return 1;
}
void init() {
	for(int i = 2;i <= n - 1;i ++) {
		if(ans[i] == 1) {
			if(a[i] == 'o') ans[i + 1] = ans[i - 1];
			if(a[i] == 'x') {
				if(a[i] == 'o') ans[i + 1] = ans[i - 1];
				else ans[i + 1] = (ans[i - 1] == 1?2:1);
			}
		}
		if(ans[i] == 2) {
			if(a[i] == 'x') ans[i + 1] = ans[i - 1];
			if(a[i] == 'o') {
				if(a[i] == 'o') ans[i + 1] = (ans[i - 1] == 1?2:1);
				else ans[i + 1] = ans[i - 1];
			}
		}
	}
}

void print() {
	for(int i = 1;i <= n;i ++) {
		if(ans[i] == 1) printf("S");
		else printf("W");
	}
}
int main() {
	scanf("%d",&n);
	scanf("%s",a + 1);
	ans[1] = ans[2] = 1;
	init();
	if(check()) {
		print();
		printf("\n");
		return 0;
	}
	ans[1] = ans[2] = 2;
	init();
	if(check()) {
		print();
		printf("\n");
		return 0;
	}
	ans[1] = 1,ans[2] = 2;
	init();
	if(check()) {
		print();
		printf("\n");
		return 0;
	}
	ans[1] = 2,ans[2] = 1;
	init();
	if(check()) {
		print();
		printf("\n");
		return 0;
	}
	printf("-1\n");
	return 0;
} 

Measured memory_bytes: 768
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<set>
using namespace std;

int a[105];

int main(){
    int n;
    while(scanf("%d",&n)!=EOF){
            int s=0;
        for(int i=0;i<n;i++){
            scanf("%d",&a[i]);
            s+=a[i];
        }
        float sum=(float)s;
        if(s>0)
        s=(int)(sum/(double)n+0.5);
        else
            s=(int)(sum/(double)n-0.5);
        int ans=0;
        for(int i=0;i<n;i++){
            ans+=(a[i]-s)*(a[i]-s);
        }
        printf("%d\n",ans);
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
	int k,a,b;
	cin>>k>>a>>b;
	for(int i=a;i<=b;++i)
	{
		if(i%k==0){
			cout<<"OK";
			return 0;
		}
	}
	cout<<"NG";
    return 0;
}

Measured memory_bytes: 3592
#うまい人のを見て説いた。
require 'prime'
n = gets.chomp.to_i
a = n.prime_division
aa = a.size
ans = 0
(0...aa).each do |i|
    s = a[i][1]
    x = 1
    s -= x
    while s >= 0 
        ans += 1
        x += 1
        s -= x
    end
end
puts ans

Measured memory_bytes: 14444
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

class Program
{
    static void Main()
    {
        var n = ReadLine().Split().Select(int.Parse).ToArray();
        int c=0;
        for (int i = n[0]; i <= n[1]; i++)
        {
           var s= i.ToString();
           if(s[0]==s[4]&&s[1]==s[3])c++;
        }
        WriteLine(c);
    }
}

Measured memory_bytes: 15316
#include<stdio.h>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<bitset>
#include<vector>
#include<math.h>
#define ls(x) (x<<1)
#define rs(x) ((x<<1)|1)
using namespace std;

int main()
{
    int a,b;
    scanf("%d%d",&a,&b);
    printf("%d\n",a+1-b);
}

Measured memory_bytes: 256
import sys

def propare():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))
    K = int(next(tokens))
    H_list = []
    for i in range(N):
        H_list.append(int(next(tokens)))

    solve(N, K, H_list)

def solve(H: int, N: int, H_list: list):
    H_ranking_list = sorted(H_list, reverse=True)
    H_ranking_list = H_ranking_list[N:]

    count = sum(H_ranking_list)

    print(count)

    return
 
if __name__ == "__main__":
    propare()

Measured memory_bytes: 30592
object Main extends App {
  val in = scala.io.Source.stdin.getLines.toSeq
  val B = in.tail.head.split(' ').map(_.toInt.toChar).toArray
  
  private def func(b:Array[Char]):Seq[Int] = {
    if(b.isEmpty) return Seq()
    //println(b)
    var i=b.size - 1
    val sz=b.size
    while(i >= 0){
      if((i+1) < b(i)) return null
      if((i+1) == b(i)){ 
        val sub = func(b.take(i) ++ b.drop(i+1) )
        //println(sub)
        if(sub != null) return sub :+ (i+1)
      }
      i -= 1
    }
    return null
  }
  val ret = func(B)
  if(ret == null) println(-1) else println(ret.mkString("\n"))
}


Measured memory_bytes: 26476
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int ans = sc.nextInt();
        int cnt = 0;
        while(ans != 0) {
            cnt ++;
            System.out.println("Case " + cnt + ": " + ans);
            ans = sc.nextInt();
        }
        sc.close();
    }
}


Measured memory_bytes: 42732
import java.util.*;
import java.io.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import static java.lang.Math.*;

public class Main {
	int len = 393;
	
	void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int s[] = new int[n], l[] = new int[n], p[] = new int[n];
		for(int i=0;i<n;i++) {
			s[i] = sc.nextInt(); l[i] = sc.nextInt(); p[i] = sc.nextInt();
		}
		int[] dp = new int[len+1]; fill(dp, -1); dp[0] = 0;
		for(int j=0;j<=len;j++) for(int i=0;i<n;i++) if(dp[j] >= 0){
			for(int k=s[i];k<=l[i];k++) if(j+k<=len) dp[j+k] = max(dp[j+k], dp[j]+p[i]);
		}
		
		int m = sc.nextInt();
		int[] ans = new int[m];
		boolean flg = true;
		for(int i=0;i<m;i++) {
			int r=sc.nextInt();
			ans[i] = dp[r];
			if(ans[i] == -1) flg = false;
		}
		if(!flg) System.out.println(-1);
		else {
			for(int i: ans) System.out.println(i);
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 23636
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <queue>
#include <utility>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;

#define For(i, a, b) for(int i = (a); i < (b); i++)
#define Rep(i, n) For(i, 0, (n))
#define Rrep(i, n) for(int i = (n - 1); i >= 0; i--)
#define pb push_back

const int inf = 999999999;
const int mod = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int a[100010];

int main(){
	int n; cin >> n; int ans = 0;
	For(i, 1, n + 1){
		int x; cin >> x;
		if(x > n){
			ans += 1;
			continue;
		}
		if(a[x] >= x){
			ans += 1;
		}else{
			a[x] += 1;
		}
	}
	For(i, 1, n + 1){
		if(a[i] < i) ans += a[i];
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
    int n;
    cin >> n;
    int *x = new int[n + 5];
    for (int i = 0; i < n; i++) {
        cin >> x[i];
    }

    int min = INT_MAX;
    for (int i = 0; i <= 100; i++) {
        int sum = 0;
        for (int j = 0; j < n; j++) {
            sum += (x[j] - i) * (x[j] - i);
        }
        min = (min < sum) ? min : sum;
    }
    cout << min << endl;
    return 0;
}

Measured memory_bytes: 3576
local read = setmetatable({}, {__index = function(t, k) local a = {} for i=1,#k do table.insert(a, '*'..string.sub(k, i, i)) end local r = io.read local u = table.unpack or unpack return function() return r(u(a)) end end})
read.N = function(N) local t={} for i=1,N do t[i]=read.n() end return t end
string.totable = function(s) local t={} local u=string.sub for i=1,#s do t[i] = u(s, i, i) end return t end
string.split = function(s) local t={} for w in string.gmatch(s, "[^%s]+") do table.insert(t, w) end return (table.unpack or unpack)(t) end
----
local N, M = read.nnl()
local task_completed = {}
local ac_count = 0
local wa_count = {}
for i=1,M do
    local p, s = read.l():split()
    if not task_completed[p] then
        if s == 'AC' then
            ac_count = ac_count + 1
            task_completed[p] = true
        else
            wa_count[p] = (wa_count[p] or 0) + 1
        end
    end
end
local wa_total = 0
for p in pairs(task_completed) do
    wa_total = wa_total + (wa_count[p] or 0)
end
print(ac_count .. " " .. wa_total)

Measured memory_bytes: 28516