akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define vsort(vec) sort(vec.begin(), vec.end())
#define vreverse(vec) reverse(vec.begin(), vec.end())
using ll =long long;
const ll INF =99999999999;

//最大公約数
ll gcd(ll a, ll b){
   if (a%b==0){
       return(b);
   }else{
       return(gcd(b,a%b));
   }
}
//最小公倍数
ll lcm(ll a, ll b){
   return a*b/gcd(a,b);
}

//素数判定
ll isprime(ll n){
  bool prime=true;
  for(int i=2;i<n;i++){
    if(n%i==0){
      prime=false; break;
    }
  }
if(prime){cout<<n<<" is prime"<<endl;
         }else{cout<<n<<" is not prime"<<endl;}

}
//階乗　20くらいが限界
ll factorial(ll n){
  ll a=1;ll b=n;
  for(int i=0;i<n;i++){
    a*=b;
    b--;
  }
  return a;
}

//組み合わせ　nCr
ll comb(ll a,ll b){
  ll c;
  c=factorial(a)/(factorial(a-b)*factorial(b));
  return c; 
}




//10億7。　　　100000007
//2*2行列 H*W
//vector<vector<int>> vec(H,vector<int>(W));
//for(int i=0;i<H;i++){
//for(int j=0;j<W;j++){
//cin>>vec[i][j];
//  }
//}

//文字列→数列
//string S;int A=atoi(S.c_str());
//数列→文字列
//int A;string S=to_string(A);
//数字判定　isdigit(a)
//pair宣言　pair<int,int> p(5,7);
//ソート　sort(vec.begin(),vec.end());



int main(){
cout<<fixed<<setprecision(10);
 
  ll N;cin>>N;
  vector<ll> H(N);
  for(int i=0;i<N;i++){
    cin>>H[i];
    //cout<<H[i]<<endl;
  }
  ll dp[100010];
  for(int i=0;i<100010;i++){
    dp[i]=INF;
  }
  dp[0]=0;

  for(int i=1;i<N;i++){
    dp[i]=min(dp[i],dp[i-1]+abs(H[i]-H[i-1]));
    if(i>1){
      dp[i]=min(dp[i],dp[i-2]+abs(H[i]-H[i-2]));
    }

  }
cout<<dp[N-1]<<endl;
  
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
using ll =  long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
const int INFTY =2147483647;
 
int n;
 
ll cal(int x){
    ll a=1,ans=2;
    if(x==1) return n;
    if(x==0) return 0;
    while(x>1){
        if(x%2==1) a=(a*ans)%MOD;
        x/=2;
        ans=(ans*ans)%MOD;//ここはpow(ans,2)だとうまくいかない
    }
    return ans=(ans*a)%MOD-1;
}
 
//モジュラ逆数
 
int64_t minv(const int64_t& a)
{
    int64_t x, u, s, t, k;
    s = a; t = MOD;
    x = 1; u = 0;
    while (t) {
        k = s / t;
        s -= k * t;
        std::swap(s, t);
        x -= k * u;
        std::swap(x, u);
    }
    x %= MOD;
    if (x < 0) x += MOD;
    return x;
}
 
ll cal2(ll x){
    ll a=1,b=1;
    for(int i=2;i<=x;i++) a=(a*i)%MOD;
    REP(i,x) b=(b*(n-i))%MOD;
    return (b*minv(a))%MOD;
}
 
 
ll check(ll x){
    if(x<0) return MOD+x;
    else return x;
}
 
int main(){
    int a,b;
    ll ans,l,r;
    cin>>n>>a>>b;
 
    ans=cal(n);
    r=cal2(a);
    l=cal2(b);
 
 
    cout<<check(check(ans-r)-l)<<endl;
 
 
}

Measured memory_bytes: 256
from itertools import*
N,K,Q,*A=map(int,open(0).read().split())
l=len
s=sorted
print(min(c[Q-1]-Y for c,Y in zip((s(sum((v[:l(v)-K+1]for v in(s(v)for k,v in groupby(A,lambda a:a>=Y)if k)if l(v)>=K),[]))for Y in A),A)if l(c)>=Q))

Measured memory_bytes: 65244
#include <stdio.h>

int N;
int X[100];
int M;
int A[100];

void succ(int a)
{
  int x = X[a - 1];

  if (x == 2019)
  {
    return;
  }

  for (int i = 0; i < N; ++i)
  {
    if (X[i] == x + 1)
    {
      return;
    }
  }

  ++X[a - 1];
  return;
}

int main(void)
{

  scanf("%d", &N);

  for (int i = 0; i < N; ++i)
  {
    if (i == N - 1)
    {
      scanf("%d", &X[i]);
    }
    else
    {
      scanf("%d ", &X[i]);
    }
  }

  scanf("%d", &M);

  for (int i = 0; i < M; ++i)
  {
    if (i == M - 1)
    {
      scanf("%d", &A[i]);
    }
    else
    {
      scanf("%d ", &A[i]);
    }
  }

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

  for (int j = 0; j < M; ++j)
  {
    succ(A[j]);
  }

  for (int i = 0; i < N; ++i)
  {
    printf("%d\n", X[i]);
  }

  return 0;
}


Measured memory_bytes: 2092
def main():
    a = list(map(int, input().split(' ')))
    b = sorted(a)
    tmp = [b[1]-b[0], b[2]-b[1], b[2]-b[0]]
    if tmp[0] % 2 == 0:
        c = int(tmp[0] / 2) + b[2] - b[1]
    elif tmp[1] % 2 == 0:
        c = int(tmp[1] / 2) + int((tmp[2]+1) / 2) + 1
    else:
        c = int(tmp[2] / 2) + int((tmp[1]+1) / 2) + 1
    print(c)

if __name__ == '__main__':
    main()


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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  ll n, x, t, ans = 0;
  cin >> n >> x >> t;
  while (n > 0) n -= x, ans += t;

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


Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;

//const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main()
{
	string s, t;
	cin >> s >> t;

	REP(i, (int)s.size()){
		if (s[i] != t[i]){
			char a = s[i], b = t[i];
			for (int j = 0; j < (int)s.size(); j++){
				if (s[j] == a){
					s[j] = b;
					continue;
				}
				if (s[j] == b){
					s[j] = a;
				}
				if (j < i && s[j] != t[j]) break;
			}
		}
	}

	if (s == t) cout << "Yes" << endl;
	else cout << "No" << endl;
}


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

int main(){
  int N;
  cin >> N;
  vector<int> vec(N);
  for(int i=0; i<N; i++){
    cin >> vec.at(i);
  }
  sort(vec.begin(),vec.end());
  int a = vec.at(N-1);
  int b = 0;
  double x = (double)a/2;

  double y = 1000000000;
  
  for(int i=0; i<N-1; i++){
    if(abs(vec.at(i) - x) < y){
      y = abs(vec.at(i) - x);
      b = vec.at(i);
    }
  }
  cout << a << " " << b << endl;
}

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

using namespace std;

//const long long int MOD = 1000000007;
const int MOD = 1000000007;
//const int MOD = 998244353;

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



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

	cin >> N;
	long long int sum = 0;
	int m = 0;
	long long int le = MOD;
	int zero = 0;
	for (int i = 0; i < N; i++) {
		cin >> M;
		sum += abs(M);
		le = min(le, abs(M));
		m += M < 0;
		zero += !M;
	}
	if ((m & 1)&&(!zero))sum -= le*2;
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

template<class T>
class BIT {
    vector<T> bit;
public:
    explicit BIT(int n): bit(vector<T>(n+1, 0)){}

    T sum(int k){
        T ret = 0;
        for (++k; k > 0; k -= (k & -k)) ret += bit[k];
        return ret;
    }

    void add(int k, T x){
        for (++k; k < bit.size(); k  += (k & -k)) bit[k] += x;
    }
};

int main() {
    int n, q;
    cin >> n >> q;
    BIT<int> s(n);
    for (int i = 0; i < q; ++i) {
        int c, x, y;
        scanf("%d %d %d", &c, &x, &y);
        if(c == 0) s.add(x-1, y);
        else printf("%d\n", s.sum(y-1) - s.sum(x-2));
    }
    return 0;
}


Measured memory_bytes: 3480
#include<stdio.h>

int main(){
  
  //Declarations
  int N,A,B;
  int sum=0;
  int cnt=0;
  int tmp;

  //Taking inputs
  scanf("%d",&N);
  scanf("%d",&A);
  scanf("%d",&B);

  for(int i=1; i <= N;i++){
    tmp = i;
    sum = 0;
    while(tmp > 0){
      sum += tmp % 10;
      tmp = tmp / 10;
    }
    if(A <= sum && sum <=B)
      cnt+=i;
  }

  printf("%d\n",cnt);

  return 0;
}


Measured memory_bytes: 128
import java.lang.IllegalArgumentException
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val s = sc.next()
    println(answer052b(s))
}

fun answer052b(s: String): Int {
    var x = 0
    var answer = x

    s.forEach {
        answer = Math.max(x, answer)
        when (it) {
            'I' -> x++
            'D' -> x--
            else -> throw IllegalArgumentException("wrong args")
        }
        answer = Math.max(x, answer)
    }
    return answer
}

Measured memory_bytes: 31392
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int num[5];
    while(cin>>num[0],num[0]){
        vector<int> hand(5,0);
        hand[num[0]]=1;
        for(int i=1;i<5;i++){
            cin>>num[i];
            hand[num[i]]++;
        }
        if(hand[1]&&hand[2]&&hand[3]||hand[1]==5||hand[2]==5||hand[3]==5)
            for(int i=0;i<5;i++)cout<<"3\n";
        else {
            int win;
            if(!hand[3])win=1;
            else if(!hand[1])win=2;
            else win=3;
            for(int i=0;i<5;i++){
                if(win==num[i])cout<<"1\n";
                else cout<<"2\n";
            }
        }
    }
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
long long ans = 1;
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    long long H;
    cin >> H;
    while ((H >>= 1) > 0) {
        ans = 2*ans+1;
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 256
//-------All power is within you,you can do Anything and Everything.---------//
 
    #include <bits/stdc++.h>
    using namespace std;
  
//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ M $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//
 
    #define pb push_back
    #define MP make_pair
    #define F first
    #define S second
    #define sc(x) scanf("%lld",&x)
    #define pf(x) printf("%lld\n",x)
    #define int long long
    #define all(x) x.begin(),x.end() 
    #define fo(i,a,b) for(int i=a;i<b;i++)
    #define rfo(i,b,a) for(int i=b;i>=a;i--)
    #define mem( a, val ) memset(a, val, sizeof( a ) )
    #define deci( x ) cout<<fixed<<setprecision( x );
    #define bitcount( x ) __builtin_popcountll( x )
    #define endl "\n" 
    
    #define XOX 
    
    typedef vector<int> vi;
    typedef pair<int,int> pi; 
    
    const int MOD =  1000000007 ;
    const int MAX = 2e6 + 7;
    const int INF = 1e15;
    const int dx[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
    const int dy[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
    
//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ DEB $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//
    
    #define deb(x) cout<<#x<<" "<<x<<endl;


    vector<string> vec_splitter(string s) 
    {
        for(char& c: s) c = c == ','?  ' ': c;
        stringstream ss; ss << s;
        vector<string> res;
        for(string z; ss >> z; res.push_back(z));
        return res;
    }
    void debug_out(vector<string> args, int idx) { cerr << endl; }
    template <typename Head, typename... Tail>
    void debug_out(vector<string> args, int idx, Head H, Tail... T) 
    {
        if(idx > 0) cerr << ", ";
        stringstream ss; ss << H;
        cerr << args[idx] << " = " << ss.str();
        debug_out(args, idx + 1, T...);
    }
    
    #ifdef XOX
    #define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __VA_ARGS__)
    #else
    #define debug(...) 42
    #endif

//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ V $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//  
    
    int i,j,k,t,n,q,l,r,mid;

//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ F $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//

    int x,y,z;
    void solve()
    {
        cin>>x>>y>>z;
        cout<<z<<" "<<x<<" "<<y<<endl;
        
    }
    
//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//
//                          GAME STARTS FROM HERE                            //
 
    int32_t main() 
    {
    
        // int start,stop=clock();
        // cout<<"time:"<<(stop-start)/double(CLOCKS_PER_SEC)*1000<<endl;
        ios_base::sync_with_stdio(0);
        cin.tie(NULL);

        // sc(t);while(t--)
        // cin>>t;while(t--)
            solve();
    
        return 0;
    }

Measured memory_bytes: 256
A, B, C = map(int, input().split())

K = int(input())

rest = K
while A >= B and rest > 0:
    B *= 2
    rest -= 1
while B >= C and rest > 0:
    C *= 2
    rest -= 1

if rest >= 0 and A < B and B < C:
    print("Yes")
else:
    print("No")



Measured memory_bytes: 61616
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        int M = sc.nextInt();
        
        int[] A = new int[N];
        for(int i= 0; i < N; i++){
            A[i] = sc.nextInt();
        }
        Arrays.sort(A);
        
        Data[] BC = new Data[M];
        for(int i= 0; i < M; i++) {
            int B = sc.nextInt();
            int C = sc.nextInt();
            BC[i] = new Data(B, C);
        }
        Arrays.sort(BC, new Comparator<Data>() {
            public int compare(Data d1, Data d2) {
                return d2.getB() - d1.getB();
            }
        });

        
        int cnt = 0;
        int A_cnt = 0;
        label: while(cnt < M){
            int C = BC[cnt].getB();
            for(int i = 0; i < BC[cnt].getA(); i++){
                if(A[A_cnt] < C){
                    A[A_cnt] = C;
                    A_cnt ++;
                    if(A_cnt >= N){
                        break label;
                    }
                } else{
                    break label;
                }
            }
            cnt ++;
        }
        
        long ans = 0;
        for(int i = 0; i < N; i++){
            ans += A[i];
        }
        System.out.println(ans);
    }
}

class Data{
    private int a;
    private int b;
    public Data(int a, int b) {
        this.a = a;
        this.b = b;
    }
    public int getA() {
        return a;
    }
    public int getB() {
        return b;
    }
}

Measured memory_bytes: 90712
import java.util.Scanner;

public class Main{
  public static void main(String[]args){
  	Scanner sc=new Scanner(System.in);
  	while(true){
  		int n=sc.nextInt();
  		int max=0,min=0,sum,score;
  		if(n==0){break;}

  		sum=0;
  		int s[]=new int[n];
  		for(int i=0;i<n;i++){
  			s[i]=sc.nextInt();
  			if(i==0){
  				max=s[i];
  				min=s[i];
  			}
  			if(s[i]<min) min=s[i];
  			if(s[i]>max) max=s[i];
  			sum+=s[i];
  		}
  		sum-=(max+min);
  		score=sum/(n-2);
  		System.out.println(score);
	}
  }
}

Measured memory_bytes: 21092
#include <cstdio>
#include <vector>
#include <queue>
#include <algorithm>

#define int long long

using namespace std;

signed main()
{
    int ncake[3];
    int K;
    scanf("%lld%lld%lld%lld", &ncake[0], &ncake[1], &ncake[2], &K);
    vector<int> vcake[3];
    for (int i = 0; i < 3; i++)
    {
        for (int j = 0; j < ncake[i]; j++)
        {
            int hoge;
            scanf("%lld", &hoge);
            vcake[i].push_back(hoge);
        }
    }

    for (int i = 0; i < 3; i++)
        sort(vcake[i].begin(), vcake[i].end(), greater<int>());

    int unlock[3] = {0, 0, 0};

    priority_queue<int> ans;
    int max_sum = vcake[0][0] + vcake[1][0] + vcake[2][0];
    ans.push(max_sum);

    while (true)
    {
        vector<int> next_max;
        for (int i = 0; i < 3; i++)
        {
            if (unlock[i] + 1 < ncake[i])
            {
                next_max.push_back(max_sum - vcake[i][0] + vcake[i][unlock[i] + 1]);
            }
            else
            {
                next_max.push_back(0);
            }
        }

        auto max_it = max_element(next_max.begin(), next_max.end());
        int max_cake = *max_it;
        int max_index = distance(next_max.begin(), max_it);
        unlock[max_index]++;
        int not_max_cake1 = (max_index + 1) % 3;
        int not_max_cake2 = (max_index + 2) % 3;

        if (ans.size() >= K)
        {
            vector<int> removed;
            for (int i = 0; i < K - 1; i++)
            {
                removed.push_back(ans.top());
                ans.pop();
            }
            int current_min = ans.top();
            for (int i = 0; i < K - 1; i++)
            {
                ans.push(removed[i]);
            }
            if (current_min >= max_cake)
            {
                break;
            }
        }

        for (int i = 0; i <= unlock[not_max_cake1]; i++)
        {
            for (int j = 0; j <= unlock[not_max_cake2]; j++)
            {
                ans.push(vcake[not_max_cake1][i] + vcake[not_max_cake2][j] + vcake[max_index][unlock[max_index]]);
            }
        }
    }

    for (int i = 0; i < K; i++)
    {
        printf("%lld\n", ans.top());
        ans.pop();
    }

    return 0;
}

Measured memory_bytes: 656
#include <cstdio>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main(void)
{
    int n,k;
    cin >>n >>k;

    vector<int> h;
    for(int i = 0; i < n; i++){
        int tmp;
        cin >>tmp;
        h.push_back(tmp);
    }

    sort(h.begin(), h.end(), greater<int>());

    long long sum = 0;
    for(int i = k; i < n; i++){
        sum += h[i];
    }

    printf("%lld\n", sum);

    return 0;
}

Measured memory_bytes: 1400
from collections import deque
N=int(input())
v=list(map(int,input().split()))
v.sort()

for i in range(N-1):
    x=(v[0]+v[1])/2
    V=deque(v)
    V.popleft()
    V.popleft()
    V.append(x)
    v=list(V)
    v.sort()
print(v[0])

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

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
const int INF = 1000000;

signed main()
{
    int n, m; cin >> n >> m;
    int t = n - m * 2;
    int ans = 0;
    if (t > 0)  ans = t;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <string>
#include <vector> 
#include <algorithm>
#include <numeric>
#include <map>   
#include <stdio.h>
#include <iomanip>

#define FOR(i,a,b) for(i=(a);i<(b);++i) 
#define FORR(i,a,b) for(i=(a);i>(b);--i)
#define REP(i,n) for(i=0;i<(n);++i)
#define REPR(i,n) for(i=(n);i>0;--i)
#define PB push_back
#define ull unsigned long long
#define ll long long
#define INT_MAX 2147483647
#define LL_MAX 9223372036854775807
#define sortR(a,b) sort(a, b, greater<int>())

using namespace std;
long long GCD(long long a, long long b) {
	if (a < b)
		swap(a, b);
	if (b == 0) return a;
	else return GCD(b, a % b);
}

vector<double> answer(200001, 0);
vector<bool> check(200001,false);

double ANS(int n, int k) {
	if (check[n]) {
		return answer[n];
	}
	check[n] = true;
	if (n >= k)
		answer[n] = 1.0;
	else 
		answer[n] = ANS(n * 2, k) / 2;
	return answer[n];
}

int main() {
	ll N, K;
	double ans = 0;
	cin >> N >> K;
	for (int i = 1; i <= N; i++) {
		ans += ANS(i,K) / N;
	}
	cout << std::setprecision(11)<<ans << endl;

}



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

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int getRand(int l, int r)
{
    uniform_int_distribution<int> uid(l, r);
    return uid(rng);
}
  
#define int long long 
#define pb push_back
#define S second
#define F first
#define f(i,n) for(int i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define vi vector<int>
#define pii pair<int,int>
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#define precise(x) fixed << setprecision(x) 

const int MOD = 1e9+7;

int mod_pow(int a,int b,int M = MOD)
{
    int res = 1;
    
    while(b)
    {
        if(b&1) res=(res*a)%M;
        a=(a*a)%M;
        b>>=1;
    }
    
    return res;
}


void solve()
{
  int n,k;
    cin >> n >> k;
    
  if(n > k)
  {
      int diff = (n-k)%k;
      n = diff;
  }
    
  if(n == k) cout << 0;
  else cout << min(n,k-n);
    
    
}

signed main()
{
    fast;
    
    int t = 1;
    
//    cin >> t;
    
    while(t--)
        
    solve();
}

Measured memory_bytes: 256
#include <iostream>	

void DFS_rec(char** board, int** region, int count, int x, int y, char c, int H, int W)
{
	region[x][y] = count;
	if (x>0) {
		if (board[x-1][y] == c && region[x-1][y] == -1) DFS_rec(board, region, count, x-1, y, c, H, W);
	}
	if (x<H-1) {
		if (board[x+1][y] == c && region[x+1][y] == -1) DFS_rec(board, region, count, x+1, y, c, H, W);
	}
	if (y>0) {
		if (board[x][y-1] == c && region[x][y-1] == -1) DFS_rec(board, region, count, x, y-1, c, H, W);
	}
	if (y<W-1) {
		if (board[x][y+1] == c && region[x][y+1] == -1) DFS_rec(board, region, count, x, y+1, c, H, W);
	}
}

int DFS(char** board, int** region, int H, int W)
{
	int count = 0;
	for (int i=0; i<H; i++) {
		for (int j=0; j<W; j++) {
			if (region[i][j] >= 0) continue;
			char c = board[i][j];
			DFS_rec(board, region, count, i, j, c, H, W);
			count++;
		}
	}
	return count;
}

int main()
{
	int H, W;
	while (std::cin >> H >> W) {
		if (H==0) break;
	
		char** board = new char*[H];
		for (int i=0; i<H; i++) board[i] = new char[W];
		
		for (int i=0; i<H; i++) {
			for (int j=0; j<W; j++) std::cin >> board[i][j];
		}
		
		int** region = new int*[H];
		for (int i=0; i<H; i++) region[i] = new int[W];
		
		for (int i=0; i<H; i++) {
			for (int j=0; j<W; j++) region[i][j] = -1;
		}
		
		std::cout << DFS(board, region, H, W) << std::endl;
		
		for (int i=0; i<H; i++) delete[] board[i];
		delete[] board;
		for (int i=0; i<H; i++) delete[] region[i];
		delete[] region;
	}
	return 0;
}
	



Measured memory_bytes: 4380
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#define cs ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define rep(i,b)  for(int i=0;i<(int)(b);i++)
#define Rep(i,n) for(int i=1;i<(int)(n);i++)
#define repp(i,a,b)  for(int i=a;i<=(int)(b);i++)
#define Repp(i,a,b)  for(int i=a;i>=(int)(b);i--)
typedef long long ll;
typedef long double ld;

using namespace std;

int main(){
    cs
    ll a,b,c;
    cin>>a>>b>>c;
    (4*a*b<(c-a-b)*(c-a-b))&&c>(a+b) ? cout<<"Yes" : cout<<"No"; 
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import numpy as np
import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect

sys.setrecursionlimit(10**6)


def zz():
    return list(map(int, sys.stdin.readline().split()))


def z():
    return int(sys.stdin.readline())


def S():
    return sys.stdin.readline()


def C(line):
    return [sys.stdin.readline() for _ in range(line)]


N, M = zz()
try_1 = ((N-M)*100 + M*1900)

print(try_1*pow(2, M))


Measured memory_bytes: 27152
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
 
public class Main {
 
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
 
        final int n = sc.nextInt();
        long[] vec1 = new long[n];
        long[] vec2 = new long[n];
        for(int i = 0; i < n; i++){
            vec1[i] = sc.nextInt();
        }
        for(int i = 0; i < n; i++){
            vec2[i] = sc.nextInt();
        }
         
        long m_dist = 0;
        for(int i = 0; i < n; i++){
            m_dist += Math.abs(vec1[i] - vec2[i]);
        }
        System.out.println(m_dist);
         
        long u_dist = 0;
        for(int i = 0; i < n; i++){
            u_dist += (vec1[i] - vec2[i]) * (vec1[i] - vec2[i]);
        }
        System.out.println(Math.sqrt(u_dist));
         
        long t_dist = 0;
        for(int i = 0; i < n; i++){
            t_dist += Math.abs((vec1[i] - vec2[i]) * (vec1[i] - vec2[i]) * (vec1[i] - vec2[i]));
        }
        System.out.println(Math.pow(t_dist, 1 / 3.0));
         
        long c_dist = 0;
        for(int i = 0; i < n; i++){
            c_dist = Math.max(c_dist, Math.abs(vec1[i] - vec2[i]));
        }
        System.out.println(c_dist);
    }
}


Measured memory_bytes: 26680
import math
s = input()
flag=False
for i in range(len(s)):
  S=s[:len(s)-1-i]
  if len(S)%2==1:
    continue
  if len(S)>1:
    if S[:round(len(S)/2)]==S[round(len(S)/2):]:
      ans = len(S)
      flag=True
  else:
    ans=1
  if flag:
    break
print(ans)

Measured memory_bytes: 3060
import java.util.*;
class Main{
	public static void main(String[] args){
		Scanner s=new Scanner(System.in);
		int a;
		while(true){
			a=s.nextInt();
			if(a==0)System.exit(0);
			s.nextLine();
			String c="";
			HashMap<String,Integer> map=new HashMap<String,Integer>();
			String wolf[]=new String[100000];
			int ind=0;
			int m=1;
			for(int i=0;i<a;i++){
				String b=s.nextLine();
				String[]d=b.split(" ");
				for(int j=0;j<d.length;j++){
					if(map.containsKey(d[j])){
						map.put(d[j],map.get(d[j])+1);
						m=Math.max(m,map.get(d[j]));
					}else{
						map.put(d[j],1);
						wolf[ind++]=d[j];
					}
				}
			}
			Arrays.sort(wolf,0,ind);
			String p=s.next();
			int count=0;
			for(int i=m;i>0;i--){
				if(count==5)break;
				for(int j=0;j<ind;j++){
					if(count==5)break;
					if(p.charAt(0)==wolf[j].charAt(0)&&map.get(wolf[j])==i){
						if(count>0)System.out.print(" ");
						System.out.print(wolf[j]);
						count++;
					}
				}
			}
			if(count==0)System.out.println("NA");
			else System.out.println();
		}
	}
}

Measured memory_bytes: 16000
using System;
using System.Collections.Generic;
using System.Linq;

namespace CSharpSample01
{

    
    class Program
    {


        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            int N = int.Parse(str[0]);
            int M = int.Parse(str[1]);

            long cost = 0;
            long drinkcnt = 0;

            var dic = new Dictionary<long, long>();
            for(int i = 0; i < N; i++)
            {
                str = Console.ReadLine().Split(' ');
                long a = int.Parse(str[0]);
                long b = int.Parse(str[1]);

                if (dic.ContainsKey(a))
                {
                    dic[a] += b;
                }
                else
                {
                    dic[a] = b;
                }
                
            }

            var dic_sort = dic.OrderBy(s => s.Key).ToDictionary(s => s.Key, s => s.Value);

            foreach(var s in dic_sort)
            {
                long price = s.Key;
                long limit = s.Value;
                if(drinkcnt + limit >= M)
                {
                    if(drinkcnt + limit > M)
                    {
                        cost += price * (M - drinkcnt);
                    }
                    else
                    {
                        cost += price * limit;
                    }
                    break;
                }
                else
                {
                    cost += price * limit;
                    drinkcnt += limit;
                }

            }

            Console.WriteLine(cost);

        }
    }
}


Measured memory_bytes: 33476
from collections import defaultdict
def main1():
    n = int(input())
    lis = [[] for _ in range(n)]
    for i in range(n):
        a = int(input())
        for j in range(a):
            lis[i].append(list(map(int, input().split())))
    res = 0

    for i in range(1<<n):
        f = True
        uso=set()
        syo=set()
        tmp=0
        for j in range(n):
            if(i&(1<<j)):
                tmp+=1
                for k in lis[j]:
                    if (i&(1<<(k[0]-1))) and k[1]==0:
                        f=False
                    if k[1]==1 and not (i&(1<<k[0]-1)):
                        f=False
        if f:
            res = max(res,tmp)
    print(res)


if __name__ == '__main__':
    main1()


Measured memory_bytes: 3316
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#define max(a, b)	(((a) > (b)) ? (a) : (b))		/* ２個の値の最大値 */
#define min(a, b)	(((a) < (b)) ? (a) : (b))		/* ２個の値の最小値 */
#define ENTER		printf("\n")					/* 改行プリント */
/********************************************************************************************************************************/
/* main *************************************************************************************************************************/
/********************************************************************************************************************************/
int DEBUG = 0;										/* デバッグプリント 提出時は0 */

int		a[101][101],b[101][101];
long long c[101][101] = { 0 };

int main()
{
	int		i,j,k,n,m,l;


	scanf("%d %d %d", &n, &m, &l);
	for(i=1;i<=n;i++) {
		for(j=1;j<=m;j++) {
			scanf("%d",&a[i][j]);
		}
	}
	for(i=1;i<=m;i++) {
		for(j=1;j<=l;j++) {
			scanf("%d",&b[i][j]);
		}
	}

	for(i=1;i<=n;i++) {
		for(j=1;j<=l;j++) {
			for(k=1;k<=m;k++) {
				c[i][j] += a[i][k]*b[k][j]; 
			}
		}
	}

	for(i=1;i<=n;i++) {
		for(j=1;j<=l;j++) {
			printf("%ld",c[i][j]);
			if (j!=l) printf(" ");
		}
		ENTER;
	}
	return 0;
}



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

int N, L;
string s[110];

int main() {
  cin >> N >> L;
  for (int i=0; i<N; i++) {
    cin >> s[i];
  }
  sort(s, s+N);
  for (int i=0; i<N; i++) {
    cout << s[i];
  }
  cout << "\n";
  return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include <iostream>
#include<cstdio>
#include<cmath>
#include<iomanip>
#include<string>
#include<cstdlib>
#include<ctime>
#include<vector>
using namespace std;

int main(){

   int n,k;
   cin>>n>>k;

   int h[n];
    int cnt=0;
   for(int i=0;i<n;i++){
       cin>>h[i];
       if(h[i]>=k){
           cnt+=1;
       }
   }

cout<<cnt<<endl;  


    

return 0;
}

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

#define int long long

signed main(){
  int a , b , n ;
  cin >> a >> b >> n ;
  if(n >= b){
    cout << a*(b-1)/b ;
  } else {
    cout << a*n/b ;
  }
  return 0 ; 
}

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

using namespace std;
typedef long long ll;
vector<ll> v;
ll n,x,ans,idx=-1;
int main(){
    ios_base::sync_with_stdio(0);cin.tie(nullptr);
    cin>>n;
    for(int i=1; i<=n; i++){
        cin>>x;
        v.push_back(x);
    }
    sort(v.rbegin(),v.rend());
    for(int i=1; i<v.size(); i++){
        if(i&1) idx++;
        ans += v[i-1 - idx];
    }
    cout<<ans<<'\n';
}


Measured memory_bytes: 5328
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#define MIN(a,b) ((a)<(b)?(a):(b))
int solve(int *cost, int **A, int N, int M, int X){
    int ans = 10000000;
    int p = 1;
    for (int i = 0; i < N; i++)  p *= 2; 
    for (int i = 0; i < p; i++) {
        int *exp = (int *)calloc(M , sizeof(int));
        int cst = 0;
        //for (int l = 0; l < M; l++) exp[i] = 0;
        //i(bit)のk番目に立ってたらk番目の本を読む
        for (int k = 0; k < N; k++) {
            if (i & (1 << k)) {
                for (int m = 0; m < M; m++) {
                    exp[m] += A[k][m];
                }
                cst += cost[k];
            }
        }
        for (int m = 0; m < M; m++) {
            if (exp[m] < X)   break; 
            if (m == M - 1) ans = MIN(ans, cst); 
        }
    }
    if (ans == 10000000) ans = -1;
    return ans;
}

int main(void){
    int N,M,X;
    scanf("%d%d%d", &N, &M, &X);
    int *cost = (int *)malloc(N * sizeof(int));
    int **A = (int **)malloc(N * sizeof(int *));
    for (int i = 0; i < N; i++) {
        A[i] = (int *)malloc(M * sizeof(int *));
    }
    for (int i = 0; i < N; i++) {
        scanf("%d", &cost[i]);
        for (int j = 0; j < M; j++) {
            scanf("%d", &A[i][j]);
        }
    }
    int ans = solve(cost,A, N, M, X);
    printf("%d\n",ans);
}


Measured memory_bytes: 1988
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define ld long double
#define mp make_pair
#define ff first
#define ss second
#define all(c) (c).begin(),(c).end()
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end()) //vector
int n,arr[100005][3],dp[100005][3];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<3;j++) cin>>arr[i][j];
    }
    dp[0][0]=arr[0][0];
    dp[0][1]=arr[0][1];
    dp[0][2]=arr[0][2];
    for(int i=1;i<n;i++)
    {
        for(int j=0;j<3;j++)
        {
            dp[i][j]=arr[i][j]+max(dp[i-1][(j+1)%3],dp[i-1][(j+2)%3]);
        }
    }
    // for(int i=0;i<n;i++)
    // {
    //     for(int j=0;j<3;j++) cout<<dp[i][j]<<" ";
    //     cout<<endl;
    // }
    int ans=INT_MIN;
    for(int i=0;i<3;i++) ans=max(ans,dp[n-1][i]);
    cout<<ans<<endl;
}

Measured memory_bytes: 2688
#include <iostream>
#include <vector>
#include <string.h>
#include <set>
#include <map>
#include <unordered_map>
#include <assert.h>
#include <algorithm>
#include <queue>
#include <bitset>
#include <stack>
#include <chrono>
#include <random>
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define ll long long
#define MOD 1000000007 
#define INF 1000000000000000000
#define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define uid uniform_int_distribution <int>
using namespace std;
// Read the question carefully and see all the given sample tests
// Think about the correctness before implementing

int main() {
	ll n;
	cin >> n;
	if(n & 1) {
		cout << "0";
		return 0;
	}
	ll val = 2;
	ll ans = 0;
	for (int i = 1; i <= 25; i++) {
		val *= 5;
		ans += (n / val);
	}
	cout << ans; 
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
template <class T>
inline bool chmax(T &a, T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmin(T &a, T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
const long long INF = 1LL << 60;

int N;
long long W, weight[110], value[110];

long long dp[110][100100] = {0};

int main()
{
  cin >> N >> W;
  for (int i = 0; i < N; i++)
  {
    cin >> weight[i] >> value[i];
  }
  for (int i = 0; i < N; i++)
  {
    for (int sum_w = 0; sum_w <= W; sum_w++)
    {
      if (sum_w - weight[i] < 0)
      {
        chmax(dp[i + 1][sum_w], dp[i][sum_w]);
        continue;
      }
      chmax(dp[i + 1][sum_w], dp[i][sum_w]);
      chmax(dp[i + 1][sum_w], dp[i][sum_w - weight[i]] + value[i]);
    }
  }
  cout << dp[N][W];
}

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

int main() {
    int n;
    int d[101000];
    int c1, c2;
    
    cin >> n;
    
    for (int i = 0; i < n; i++) {
        cin >> d[i];
    }
    
    sort(d, d + n);
    c1 = d[n / 2 - 1];
    c2 = d[n / 2];
    
    cout << (c2 - c1) << endl;
    return 0;
}

Measured memory_bytes: 768
import qualified Data.Vector.Unboxed as U
import qualified Data.ByteString.Char8 as C
import Data.List

r :: Int -> IO (U.Vector Int)
r n = U.unfoldrN n (C.readInt . C.dropWhile (==' ')) <$> C.getLine

r' :: IO [Int]
r'  =   unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine

mdl :: Num a => a
mdl = 10^9 + 7

t a b = a * b `mod` mdl

positivize x = if x < 0 then x + mdl else x

main :: IO ()
main = do
    [n,a,b] <- r' :: IO [Int]
    let al = powMod 2 n - 1 `mod` mdl
    let na = choose n a `mod` mdl
    let nb = choose n b `mod` mdl
    print $ positivize $ (al - na - nb) `mod` mdl

powMod :: Int -> Int -> Int
powMod cur 0 = 1
powMod cur n
    | even n = powMod (cur^2 `mod` mdl) (div n 2)
    | odd n  = (t cur) $! powMod (cur^2 `mod` mdl) (div n 2)

choose :: Int -> Int -> Int
choose n i = (prod' $ U.generate i (+ (n-i+1)) ) * modInv (prod' $ U.generate i succ)

prod' :: U.Vector Int -> Int
prod' = U.foldl' (\ac x -> t ac x) 1

prodInv' :: U.Vector Int -> Int
prodInv' = U.foldl' (\ac x -> t ac (modInv x)) 1

modInv :: Int -> Int
modInv a =  let (x,_,1) = eEA a mdl
            in  positivize x

eEA :: Int -> Int -> (Int, Int, Int)
eEA a 0 = (1, 0, a)
eEA a b =   let (q, r) = a `quotRem` b
                (s, t, g) = eEA b r
            in  (t, s-q*t, g)

Measured memory_bytes: 892
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <cstring>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <functional>
#include <ctime>
#include <unordered_map>
#include <sstream>

using namespace std;
typedef long long Long;
typedef long double Double;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int,int> PII;
typedef pair<Long,Long> PLL;

int read(int &x) { return scanf("%d", &x); }
int read(int &x, int &y) { return scanf("%d%d", &x, &y); }
int read(int &x, int &y, int &z) { return scanf("%d%d%d", &x, &y, &z); }
int read(Long &x) { return scanf("%lld", &x); }
int read(Long &x, Long &y) { return scanf("%lld%lld", &x, &y); }
int read(double &x) { return scanf("%lf", &x); }
char buff[2000010];
int read(string &s) { int r = scanf("%s", buff); s = buff; return r; }

#define dlog2(n) ((n) == -1 ? 0 : (31-__builtin_clz(n)))

#define sz(a) int(a.size())


Long dp(int p, int i, int k, VI &V) {
	if (i == V.size()) return 0;
	static bool cat[301][301][301];
	static Long mem[301][301][301];
	Long w = 1000000000000000000LL;
	if (cat[p][i][k]) return mem[p][i][k];
	// keep
	w = min(w, dp(i, i+1, k, V) + max(0, V[i] - V[p]));
	if (k > 0) {
		w = min(w, dp(p, i+1, k - 1, V));
	}
	cat[p][i][k] = 1;
	return mem[p][i][k] = w;
}

int main() {

	int N, K;
	read(N, K);
	VI V(N);
	for (auto &v : V) read(v);
	V.insert(V.begin(), 0);
	cout << dp(0, 1, K, V) << endl;
}
























Measured memory_bytes: 238080
#include "stdio.h"
int main(int argc, char const *argv[])
{
	int i,j,k,n,m,l;
	long num1[100][100],num2[100][100],num3[100][100];
	scanf("%d",&n); scanf("%d",&m); scanf("%d",&l);
	for(i=0;i<n;i++){
		for(j=0;j<m;j++){
			scanf("%ld",&num1[i][j]);
		}
	}
	for(i=0;i<m;i++){
		for(j=0;j<l;j++){
			scanf("%ld",&num2[i][j]);
		}
	}

	for(i=0;i<n;i++){
		for(j=0;j<l;j++){
			num3[i][j] = 0;
			for(k=0;k<m;k++){
				num3[i][j] += num1[i][k] * num2[k][j];
			}
		}
	}

	for(i=0;i<n;i++){
		for(j=0;j<l;j++){
			printf("%ld",num3[i][j]);
			if(j== l-1)
				printf("\n");
			else
				printf(" ");
		}
	}
	return 0;
}


Measured memory_bytes: 836
#include <stdio.h>

int main(void){

	int na,ma,nb,mb;
	int A[100][100],B[100],C[100];

	


	scanf("%d %d",&na,&ma);

	for(nb=0;nb<na;nb++){
		for(mb=0;mb<ma;mb++){
			scanf("%d ",&A[nb][mb]);
		}
		
	}
	
	for(mb=0;mb<ma;mb++){
		scanf("%d",&B[mb]);
	}

	for(nb=0;nb<na;nb++){
			C[nb] = 0;
		for(mb=0;mb<ma;mb++){
			C[nb] += (A[nb][mb]*B[mb]);
		}
		
	}

	for(nb=0;nb<na;nb++){
		printf("%d\n",C[nb]);
	}



	return 0;
}

Measured memory_bytes: 640
public class
Main
{
  public void
  run (
    final java.util.Scanner sc,
    final java.io.PrintStream out
    )
  {
    int[ ][ ] a;
    int N;
    int i, j, k, l;
    int res;

    N = sc.nextInt ( );
    a = new int[ N ][ N + 1 ];
    for ( i = 0; i < N; ++i )
    for ( j = 1; j <= N ; ++j )
      a[ i ][ j ] = sc.nextInt ( );

    for ( i = 0; i < N; ++i )
    for ( j = 1; j <= N; ++j )
      a[ i ][ j ] += a[ i ][ j - 1 ];

    res = a[ 0 ][ 1 ];
    for ( i = 0; i < N; ++i )
    for ( j = i + 1; j <= N; ++j )
    {
      for ( k = 0; k < N; ++k )
      {
        int t = 0;

        for ( l = k; l < N; ++l )
        {
          t += a[ l ][ j ] - a[ l ][ i ];
          res = Math.max ( res, t );
        }
      }
    }

    out.println ( res );
  }

  public static void
  main (
    String[ ] args
    )
  {
    ( new Main ( ) ).run ( new java.util.Scanner ( System.in ), System.out );
  }
}

Measured memory_bytes: 36788
import sys
input = sys.stdin.readline
A, B, K = [int(x) for x in input().rstrip().split()]
left = [int(x) for x in range(A, A+K)]
right = [int(x) for x in range(B, B-K, -1)]
ans = []
for i in left:
    if i not in ans and i <= B:
        ans.append(i)
for j in right:
    if j not in ans and j >= A:
        ans.append(j)
ans.sort()
for k in ans:
    print(k)

Measured memory_bytes: 3064
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> //tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;

int main() {
  int input, happiness = 0;
  cin >> input;
  int s1000, s5;
  s1000 = input / 500;
  s5 = (input - s1000 * 500) / 5;
  cout << s1000 * 1000 + s5 * 5 << endl;
}

Measured memory_bytes: 256
//ALDS1_5_A_ExhaustiveSearch

#include<bits/stdc++.h>
using namespace std;
const int INF=2E9;
typedef pair<int,int> Pair;
typedef long long LL;
const double r3 = 1.73205080757;

struct cord{
    double x;
    double y;
};

void cp(cord p){

    printf("%.8lf %.8lf\n",p.x,p.y);
}
void Koch(int d,cord p1,cord p2){
    if(d==0) return;
    cord s,u,t;
    s.x=p1.x+(p2.x-p1.x)/3.0;
    s.y=p1.y+(p2.y-p1.y)/3.0;
    t.x=p1.x+2.0*(p2.x-p1.x)/3.0;
    t.y=p1.y+2.0*(p2.y-p1.y)/3.0;
    u.x=s.x+(t.x-s.x)/2.0-r3*(t.y-s.y)/2.0;
    u.y=s.y+r3*(t.x-s.x)/2.0+(t.y-s.y)/2.0;
    Koch(d-1,p1,s);
    cp(s);
    Koch(d-1,s,u);
    cp(u);
    Koch(d-1,u,t);
    cp(t);
    Koch(d-1,t,p2);


}

int main(){
    int n;
    cin >> n;
    cord p1,p2;
    p1.x=0.0;
    p1.y=0.0;
    p2.x=100.0;
    p2.y=0.0;
    cp(p1);
    Koch(n,p1,p2);
    cp(p2);
    return 0;
}



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

int main() {
	ll n; cin >> n;
	vl a(n + 1);
	for (ll i = 1; i <= n; i++)
		cin >> a[i];

	ll cnt = 0;
	ll b = 1;
	while(1) {
		if (b == 2) {
			cout << cnt << endl;
			return 0;
		}
		b = a[b];
		cnt ++;
		if (cnt >= n+1) break;
	}
	cout << -1 << endl;
	return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cmath>
#define fo(i,a,b) for(i=a;i<=b;i++)
#define min(x,y) ((x)<(y)?(x):(y))
#define max(x,y) ((x)>(y)?(x):(y))

using namespace std;

const int maxn=2e5+5;

int fi[maxn],ne[maxn*2],dui[maxn*2],qc[maxn],f[maxn*10];
int cc[maxn];
int i,j,k,l,m,n,x,y,now,ans;

void add(int x,int y){
	if (fi[x]==0) fi[x]=++now; else ne[qc[x]]=++now;
	dui[now]=y; qc[x]=now;
}
void dfs(int x,int y){
	int i,t=0;
	for(i=fi[x];i;i=ne[i]){
		if (dui[i]==y) continue;
		dfs(dui[i],x);
		t=max(t,f[x] & f[dui[i]]);
		f[x]=f[x] | f[dui[i]];
	}
	fo(i,1,24) if (cc[i]>t && ((f[x] & cc[i])==0)){
		t=i; break;
	}
	ans=max(ans,t);
	f[x]=(f[x]&(cc[24]-cc[t]))|cc[t];
}
int main(){
//	freopen("009d.in","r",stdin);
	scanf("%d",&n);
	fo(i,1,n-1){
		scanf("%d%d",&x,&y);
		add(x,y);add(y,x);
	}
	cc[1]=1;
	fo(i,2,24) cc[i]=cc[i-1]*2;
	dfs(1,0);
	printf("%d\n",ans-1);
	return 0;
}

Measured memory_bytes: 8576
/*
Author: Racer5x
 ***************************************   UNAUTHORISED COPYING OF CODE PROHIBITED   **********************************
*/
 
// #pragma GCC optimize("O3")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#include<bits/stdc++.h>
#define int         long long
#define double      long double
#define pb          emplace_back
#define pf          emplace_front
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define x           first
#define y           second
#define endl        '\n'
#define hell        998244353 
#define PI          3.141592653589
#define tezz        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define MAX         2000000000000000000
#define M           1000000007
using namespace std;
 
signed main()
{
    tezz
    
    int n, m, l;
    cin>>n>>m>>l;

    int mat[n + 1][n + 1];
    for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) mat[i][j] = MAX;

    while(m--){
        int a, b, c;
        cin>>a>>b>>c;

        mat[a][b] = c;
        mat[b][a] = c;
    }

    for(int k=1;k<=n;k++){
        for(int i=1;i<=n;i++){
            for(int j=1;j<=n;j++){
                mat[i][j] = min(mat[i][j], mat[i][k] + mat[k][j]);
            }
        }
    }

    int dp[n + 1][n + 1];
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            if(mat[i][j] <= l) dp[i][j] = 1;
            else dp[i][j] = MAX;
        }
    }

    for(int k=1;k<=n;k++){
        for(int i=1;i<=n;i++){
            for(int j=1;j<=n;j++){
                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
            }
        }
    }

    int q;
    cin>>q;

    while(q--){
        int a, b;
        cin>>a>>b;

        if(dp[a][b] != MAX) cout<<dp[a][b] - 1<<endl;
        else cout<<-1<<endl;
    }
} 

Measured memory_bytes: 2048
import java.util.*;

public class Main{
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		int x = in.nextInt();
		int y = in.nextInt();
		System.out.print("a ");
		
		if(x>y){
			System.out.print(">");
		} else if(x<y){
			System.out.print("<");
		} else if(x==y){
			System.out.print("==");
		}
		
		System.out.println(" b");
	}
}

Measured memory_bytes: 17156
/*
 * A.cpp
 *
 *  Created on: 2020/06/14
 *      Author: admin
 */


#include <iostream>


using namespace std;


int main(){
	long long x[5];
	for(int i=0; i<5; i++){
			cin >> x[i];
	}
	for(int i=0; i<5; i++){
		if(x[i]==0) cout << i+1;
	}
}



Measured memory_bytes: 3580
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
vector<int> dx = {-1, -1, -1, 0, 0, 1, 1, 1};
vector<int> dy = {-1, 0, 1, -1, 1, -1, 0, 1};

int main () {
    ll n; cin >> n;
    
    vector<ll> p;//p[i]:したからiけた目
    while (n) {
        if (n%26 == 0) {
            p.push_back(25);
            n /= 26;
            n--;
            continue;
        }
        p.push_back(n%26-1);
        n /= 26;
    }
    reverse(all(p));
    int m = p.size();
    rep(i, m) {
        char c = 'a' + p[i];
        cout << c;
    } 
    cout << endl;
    
    return 0;
}

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

int main() {
    int n; cin >> n;
    vector<int> l(n, -1);
    int ans = 0;
    for (int i=0; i<n; ++i) {
        int num; cin >> num;
        num--;
        ans += (l[num] == i);
        l[i] = num;
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i, l, r) for (register int i = l; i <= r; i++)
#define per(i, r, l) for (register int i = r; i >= l; i--)
#define srep(i, l, r) for (register int i = l; i < r; i++)
#define sper(i, r, l) for (register int i = r; i > l; i--)
#define erep(i, x) for (register int i = h[x]; i; i = e[i].next)
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define ui unsigned int
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pdd pair<double, double>
#define fi first
#define se second
#define pb push_back
#define pi 3.141592653589793
#define maxn 519
#define maxm 
#define maxs 
#define M 
#define Base 
#define Hash 
#define Author Renatus
//#define DEBUG
//#define ONLINE_JUDGE
using namespace std;

int n, a[maxn];

int main(){
	
	scanf("%d", &n);
	rep(i, 1, 2 * n) scanf("%d", &a[i]);
	sort(a + 1, a + 1 + 2 * n);
	int ans = 0;
	for (int i = 1; i <= 2 * n; i += 2) ans += a[i];
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 256