akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <sstream>
#include <queue> 
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm> 
#include <numeric>  
#include <functional>
#include <cassert>
#include <bitset>
#include <cctype>  
#include <iomanip> 
#include <limits>  
#include <regex>
// std::numeric_limits<int>::max(), min()
// std::setprecision(X)
// std::islower(), std::isupper(), std::tolower, std::toupper
// std::accumulate(m.begin(), m.end(), 0LL);
// std::sort(begin(),end()) // 0, 1, 2, 3 ,4 (default, less);
// std::priority_queue<int, vector<int>, less<int>> que; // 4, 3, 2, 1 (defualt, less) : 
// if ( std::regex_match(S, std::regex("(dream|dreamer|erase|eraser)*")) ) std::cout << "YES" << std::endl;

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

using ll = long long;

ll gcd ( ll a, ll b ) { if ( b == 0 ) return a; else return gcd ( b, a%b ); }
ll lcm ( ll a, ll b ) { return a * b / gcd(a, b); }

int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  int N, M; std::cin >> N >> M;
  int l = 1, r = N;

  if ( N % 2 == 1 ) {
    rep(i,M) {
      std::cout << l << " " << r << std::endl;
      l++, r--;
    }
  }

  else {
    int t = N/2+1;
    if ( M < t/2 ) {
      rep(i,M) {
        std::cout << l << " " << r << std::endl;
        l++, r--;
      }
    }

    else {
      if ( t % 2 == 0 ) {
        t = t / 2;
        rep(i,t-1) {
          std::cout << l << " " << r << std::endl;
          l++, r--;
        }
        r--;
        rep(i,M-t+1) {
          std::cout << l << " " << r << std::endl;
          l++, r--;
        }
      }
      else {
        if ( N == 4 ) std::cout << 2 << " " << 3 << std::endl;
        else {
          t = (t-1)/2;
          rep(i,t){
            std::cout << l << " " << r << std::endl;
            l++, r--;
          }
          r--;
          rep(i,M-t) {
            std::cout << l << " " << r << std::endl;
            l++, r--;
          }
        }
      }
    }
  }
  return 0;
}



Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
#define il inline
#define ll long long
#define outy printf("Yes\n")
#define outn printf("No\n")
#define outf printf("First\n")
#define outs printf("Second\n")
#define FOR(a,b,c) for(int a=b;a<=c;a++)
#define FORD(a,b,c) for(int a=b;a>=c;a--)
#define FORL(a,b) for(int a=head[b];a;a=nxt[a])
#define in(a)  a=read()
#define in2(a,b)  in(a),in(b)
#define in3(a,b,c)  in2(a,b),in(c)
#define in4(a,b,c,d)  in2(a,b),in2(c,d)
#define out(a) printf("%d\n",a)
#define out2(a,b) printf("%d %d\n",a,b)
#define out3(a,b,c) printf("%d %d %d\n",a,b,c)
#define out4(a,b,c,d) printf("%d %d %d %d\n",a,b,c,d)
#define outl(a) printf("%lld\n",a)
#define outl2(a,b) printf("%lld %lld\n",a,b)
#define outl3(a,b,c) printf("%lld %lld %lld\n",a,b,c)
#define outl4(a,b,c,d) printf("%lld %lld %lld %lld\n",a,b,c,d)
#define clr(x,y) memset(x,y,sizeof(x))
ll read(){
    ll f=1,x=0;char c=getchar();
    while(c>'9'||c<'0'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();
    return x*f;
}
/*------------------------------------------------------------*/
#define mod 1000000007
#define maxn 100010
#define inf 0x7fffffff
/*------------------------------------------------------------*/
int n,m;
int a[maxn];
int main(){
	int n;
	in(n);
	FOR(i,1,n)in(a[i]);
	int ans=0;
	FOR(i,2,n){
		if(a[i]==a[i-1]){
			a[i]=inf;
			ans++;
		}
	}
	out(ans);
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <cstdio>
#include <numeric>

using namespace std;

long long dp[100005][2];
long long N;
long long A[100005];
const long long inf = 1e15;

int main()
{
    cin >> N;
    for (int i = 1; i <= N;i++)
    {
        cin >> A[i];
    }
    for (long long i = 0; i < N;i++)
    {
        dp[i][0] = -inf;
        dp[i][1] = -inf;
    }
    dp[0][0] = 0;
    for (long long i = 1; i <= N;i++)
    {
        dp[i][0] = max(dp[i][0], dp[i - 1][0] + A[i]);
        dp[i][0] = max(dp[i][0], dp[i - 1][1] - A[i]);

        dp[i][1] = max(dp[i][1], dp[i - 1][0] - A[i]);
        dp[i][1] = max(dp[i][1], dp[i - 1][1] + A[i]);
    }
    cout << dp[N][0] << endl;
    return 0;
}

Measured memory_bytes: 2560
using System;
using System.Linq;
using static System.Console;
class Program
{
    static void Main(string[] args)
    {
        int N = int.Parse(ReadLine());
        long[] T = new long[N];
        for(int i = 0; i < N; i++)
        {
            T[i] = long.Parse(ReadLine());
        }
        long ans = T[0];
        for(int i = 1; i < N; i++)
        {
            ans = Lcm(ans, T[i]);
        }
        Write(ans);
    }

    static long Gcd(long a, long b)
    {
        if (b == 0) return a;
        return Gcd(b, a % b);
    }
    static long Lcm(long a, long b)
    {
        long g = Gcd(a, b);
        return a / g * b;
    }
}

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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;

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

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

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

ll dist[100000];
int A[333][333];

int main() {
   int H, W, D;
   cin >> H >> W >> D;
   vec<pair<int, int>> P(H*W+10);
   rep (i, H) {
      rep (j, W) {
         cin >> A[i][j];
         P[A[i][j]] = {i, j};
      }
   }

   repp (i, D+1, H*W+1) {
      dist[i] = dist[i-D] + abs(P[i].first - P[i-D].first) + abs(P[i].second - P[i-D].second);
   }

   int Q;
   cin >> Q;
   while (Q--) {
      int l, r;
      cin >> l >> r;
      cout << dist[r] - dist[l] << endl;
   }

   return 0;
}

Measured memory_bytes: 2944
package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	n := nextInt(sc)
	a := make([]int64, n)
	for i := int64(0); i < n; i++ {
		a[i] = nextInt(sc)
	}

	isIncomp := true
	cnt := 0

	for isIncomp {
		isIncomp = false
		for j := n - 1; j >= 1; j-- {
			if a[j] < a[j-1] {
				t := a[j-1]
				a[j-1] = a[j]
				a[j] = t
				isIncomp = true
				cnt++
			}
		}
	}

	fmt.Println(strings.Trim(fmt.Sprint(a), "[]"))
	fmt.Println(cnt)
}

func nextString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func nextInt(sc *bufio.Scanner) int64 {
	i, err := strconv.ParseInt(nextString(sc), 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}



Measured memory_bytes: 1140
parseInt(x) = parse(Int, x)
parseBigInt(x) = parse(BigInt, x)
parseFloat(x) = parse(Float64, x)
parseBigFloat(x) = parse(BigFloat, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
sumdigits(n) = sum(digits(n))

function main()
    k=parseInt(readline())
    a,b=parseMap(split(readline()))
    ans="NG"
    for i in a:b
        if i%k==0
            ans="OK"
        end
    end
    println(ans)
end
main()

Measured memory_bytes: 161004
import java.io.IOException;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        try (
            BufferedReader reader = new BufferedReader(
                new InputStreamReader(System.in))) {
            final String s = reader.readLine();

            final String sl[] = s.split(" ");
            double a = Integer.parseInt(sl[0]);
            double b = Integer.parseInt(sl[1]);

            System.out.println((int)Math.ceil((a + b) / 2));
        }
    }
}


Measured memory_bytes: 20564
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;

const vector<char> C = {'M', 'A', 'R', 'C', 'H'};

int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  for (int i = 0; i < n; i++) cin >> s[i];

  map<char, ll> m;
  for (auto c : C) m[c] = 0;

  for (int i = 0; i < n; i++) {
    bool ok = false;
    for (auto c : C) {
      if (s[i][0] == c) m[c]++;
    }
  }

  ll ans = 0;
  for (int i = 0; i < 5; i++) {
    for (int j = i + 1; j < 5; j++) {
      for (int k = j + 1; k < 5; k++) {
        ans += m[C[i]] * m[C[j]] * m[C[k]];
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 6376
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n, m;
    cin >> n >> m;

    const long long MOD = 1000000007;
    auto inverse = [&](long long a) {
        a %= MOD;
        long long b = MOD;
        long long u = 0, v = 1;
        while (a > 0) {
            long long d = b / a;
            b -= d * a;
            u -= d * v;
            swap(a, b);
            swap(u, v);
        }
        u %= MOD;
        if (u < 0) {
            u += MOD;
        }
        return u;
    };

    const int N = 100;
    vector<long long> F(n + N + 1, 1);
    vector<long long> IF(F.size(), 1);
    for (int i = 1; i < F.size(); ++i) {
        F[i] = F[i - 1] * i % MOD;
    }
    {
        int NN = (int)F.size() - 1;
        IF[NN] = inverse(F[NN]);
        for (int i = NN - 1; i > 0; --i) {
            IF[i] = IF[i + 1] * (i + 1) % MOD;
        }
    }

    auto nCr = [&](int n, int r) {
        if (r < 0 || r > n) {
            return 0LL;
        }

        long long res = F[n] * IF[r] % MOD * IF[n - r] % MOD;
        return res;
    };
    
    long long res = 1;

    long long x = m;
    for (int i = 2; i * i <= x; ++i) {
        int cnt = 0;
        while (x % i == 0) {
            x /= i;
            ++cnt;
        }
        // cout << i << " " << cnt << endl;
        (res *= nCr(n + cnt - 1, n - 1)) %= MOD;
    }
    if (x > 1) {
        (res *= n) %= MOD;
    }
    cout << res << '\n';

    return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<map>
using namespace std;

typedef long long ll;
ll mod = 1e9 + 7;


//素因数分解
map<ll, ll> prime_factor(ll n) {
	map<ll, ll> res;
	for (int i = 2; i * i <= n; i++) {
		while (n % i == 0) {
			res[i]++;
			n /= i;
		}
	}
	if (n != 1) {
		res[n] = 1;
	}
	return res;
}

//繰り返し自乗法
ll mpow(ll x, ll n) {
	ll ans = 1;
	while (n > 0) {
		if (n & 1) {
			ans = ans * x % mod;
		}
		x = x * x % mod;
		n >>= 1;
	}
	return ans;
}

//階乗
vector<ll> tfact(1e7 + 1, -1);
ll fact(ll n) {
	if (tfact[n] < 0) {
		if (n == 0) {
			tfact[n] = 1;
		}
		else {
			tfact[n] = fact(n - 1) * n % mod;
		}
	}
	return tfact[n];
}

//nCk
ll comb(ll n, ll k) {
	return fact(n) * mpow(fact(k), mod - 2) % mod * mpow(fact(n - k), mod - 2) % mod;
}

int main() {
	ll n, m;
	cin >> n >> m;
	map<ll, ll> prime = prime_factor(m);
	ll ans = 1;
	for (auto p : prime) {
		ans = ans * comb(p.second + n - 1, n - 1) % mod;
	}
	cout << ans << endl;
}

Measured memory_bytes: 81536
#include <iostream>
#include <string>
using namespace std;
int main(int argc, char* argv[])
{
	int N,K;
	cin>>N>>K;
	string S;
	cin>>S;
	S[K-1]=S[K-1]-'A'+'a';
	cout<<S<<endl;
	return 0;
}

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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  string s;
  cin >> s;
  // BW -> WB
  int b = 0, ans = 0;
  for (auto &c : s) {
    if (c == 'B') b++;
    else ans += b;
  }
  cout << ans << '\n';
}


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

const int maxn(1e5 + 5);

int n, a[maxn], cnt;

int main() {
	int i;
	scanf("%d", &n);
	for (i = 1; i <= n; ++i) scanf("%d", &a[i]), cnt += a[i] & 1;
	if (cnt & 1) puts("NO");
	else puts("YES");
    return 0;
}

Measured memory_bytes: 640
import sys
input = sys.stdin.readline

N = int(input())
c = input()[:-1]
R = c.count('R')
acc = [0]

for ci in c:
    acc.append(acc[-1]+(1 if ci=='R' else 0))

ans = 10**18

for i in range(N+1):
    if i>=R:
        ans = min(ans, i-R+acc[N]-acc[i])
    else:
        ans = min(ans, R-i+i-acc[i])
    
print(ans)

Measured memory_bytes: 81596
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Stack;

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

        Scanner scan=new Scanner(System.in);
        int n=0,w=0;
        if(scan.hasNext())
            n=scan.nextInt();
        if(scan.hasNext())
            w=scan.nextInt();

        long[] val=new long[n],weight=new long[n];
        for(int i=0;i<n;i++){
            if (scan.hasNext())
                weight[i] = scan.nextLong();
            if (scan.hasNext())
                val[i] = scan.nextLong();
        }
        long[][] dp=new long[n+1][w+1];
        for(int i=1;i<=n;i++){
            for(int j=1;j<=w;j++){
                if(j>=weight[i-1]){
                    dp[i][j]=Math.max(dp[i-1][j],val[i-1]+dp[i-1][j-(int)weight[i-1]]);
                }else{
                    dp[i][j]=dp[i-1][j];
                }
            }
        }
        System.out.println(dp[n][w]);
    }
}


Measured memory_bytes: 127572
x,n = map(int, input().split())

if n == 0:
    print(x)
    exit()

p = list(map(int,input().split()))

allList=[]

for i in range(-201,301):
    allList.append(i)

diff = set(allList) ^ set(p)



diff = list(diff)
diff.append(x)
diff = sorted(diff)

# print(diff)

ind = diff.index(x)
# print(ind)

# if x == 100:
    

a = diff[ind-1]
b = diff[ind+1]
# print(a,b)

ax = abs(x-a)
bx = abs(x-b)

# print(ax,bx)

if ax==bx:
    if a < b:
        print(a)
        exit()
    else:
        print(b)
        exit()

if ax > bx:
    print(b)
else:
    print(a)

Measured memory_bytes: 9284
input()
S = list(map(int,input().split()))
input()
T = list(map(int,input().split()))

def binarySearch(k,a):
    left = 0
    right = len(a)
    while left < right:
        middle = (left + right) // 2
        if a[middle] == k:
            return 1
        elif a[middle] < k:
            left = middle+1
        elif a[middle] > k:
            right = middle 
    return 0


count = 0
for t in T:
    count += binarySearch(t,S)
print(count)
    
    
    

Measured memory_bytes: 18684
//
//  main.cpp
//  atc-reg68-D
//
//  Created by 岩井聡 on 2017/02/10.
//  Copyright © 2017年 岩井聡. All rights reserved.
//

#include <iostream>
#include <string.h>


int n;

int map[100001];

int main(int argc, const char * argv[]) {
    //    freopen("/Volumes/4HOPE/Dropbox/17Todai/CodeJam/R1C-2015-C/in.txt","r",stdin);
    //    freopen("/Volumes/4HOPE/Dropbox/17Todai/CodeJam/R1C-2015-C/out.txt","w",stdout);
    
    scanf("%d",&n);
    memset(map,0,sizeof(map));
    int k;
    int sum = n;
    for(int i=0;i<n;i++){
        scanf("%d",&k);
        map[k] ++;
        if(map[k] >= 3){
            map[k]-=2;
            sum-=2;
        }
    }
    int cnt=0;
    for(int i=1;i<=100000;i++){
        if(map[i] >= 2){
            cnt ++;
            if(cnt == 2){
                sum-=2;
                cnt=0;
            }
        }
    }
    if(cnt == 1){
        sum -= 2;
    }
    printf("%d",sum);
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

using pi = pair<int,int>;
const int INF = INT_MAX/3;

int dist(pi p, pi q){
    return abs(p.fi-q.fi) + abs(p.se-q.se);
}

bool isnumber(string s){
    return isdigit(s[0]);
}

int main(){
    int w,h;
    while(cin >>w >>h,w){
        vector<vector<string>> s(h, vector<string>(w));
        rep(i,h)rep(j,w) cin >>s[i][j];

        int mx = 0;
        rep(i,h)rep(j,w)if(isnumber(s[i][j])) mx = max(mx, stoi(s[i][j]));

        vector<vector<pi>> pos(mx+2);
        rep(i,h)rep(j,w){
            if(isnumber(s[i][j])) pos[stoi(s[i][j])].pb({i,j});
            else if(s[i][j]=="S") pos[0].pb({i,j});
            else if(s[i][j]=="G") pos[mx+1].pb({i,j});
        }

        vector<int> dp(1,0);
        for(int i=1; i<=mx+1; ++i){
            int P = pos[i-1].size();
            int Q = pos[i].size();

            vector<int> nx(Q,INF);
            rep(j,P)rep(k,Q){
                nx[k] = min(nx[k], dp[j]+dist(pos[i-1][j], pos[i][k]));
            }

            dp = nx;
        }
        cout << dp[0] << "\n";
    }
    return 0;
}



Measured memory_bytes: 3288
import sys
from collections import deque
import copy


def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def bfs(X, Ma, Mb):
    #node_list = deque([0, 1])
    drug_dict = {}
    drug_dict[(0, 0)] = 0
    drug_dict[(X[0][0], X[0][1])] = X[0][2]
##    drug_dict[0] = ((0, 0) ,0)
##    drug_dict[1] = ((X[0][0], X[0][1]), X[0][2])
##    depth = 1
    min_cost = sys.maxint
    new_drug_dict = copy.deepcopy(drug_dict)
    for i in range(1, len(X)):
        for drug in drug_dict:
            cost = drug_dict[drug]
            new_drug = (drug[0] + X[i][0], drug[1] + X[i][1])
            if new_drug not in drug_dict:
                new_drug_dict[new_drug] = cost + X[i][2]
            else:
                new_drug_dict[new_drug] = min(drug_dict[new_drug], cost + X[i][2])
            if new_drug[1] * Ma == new_drug[0] * Mb:
                if new_drug_dict[new_drug] < min_cost:
                    min_cost = new_drug_dict[new_drug]
        drug_dict = copy.deepcopy(new_drug_dict)
    return min_cost


def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, Ma, Mb] = [int(input_raw[0]), int(input_raw[1]), int(input_raw[2])]
    X = []
    for i in range(N):
        input_raw = read_func().strip().split()
        [a, b, c] = [int(input_raw[0]), int(input_raw[1]), int(input_raw[2])]
        X.append((a, b, c))

    cost = bfs(X, Ma, Mb)
    if cost < sys.maxint:
        print cost
    else:
        print -1


if __name__ == '__main__':
    main()

Measured memory_bytes: 13348
#include<iostream>
#include<cmath>
#include<algorithm>
#include <cassert>
#include<string>
#include<vector>
#include <utility>
#include <math.h>
using namespace std;
int main(){
	int a = 0, b = 0, c = 0, d = 0, e[500] = { 0 },f=0, counto = 0, counto1 = 0;
	bool sin = false, gi[110] = {false};
	pair<int, int>n[110];
	vector<int> r;
	cin >> a;
	
	for (int i = 1; i < a+1; i++) {
		cin >> e[i];
		if (e[i] > e[i - 1]) {
			counto += e[i] - e[i - 1];
		}
	}
	cout << counto << endl;
	return 0;
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Joy
 */

#include <bits/stdc++.h>

#define REP(i, N) for (ll i = 0; i < (N); ++i)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define INF ll(1e9)
#define INFL ll(1e18)
#define PB push_back
#define MP make_pair
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
int ctoi(char c) {return c - '0';}

class BGoldenCoins {
public:
	void solve(std::istream& in, std::ostream& out) {
	    ll X; in >> X;
	    ll ans = 0;
	    ans += X/500 * 1000;
	    ans += (X % 500)/5 * 5;
	    out << ans << '\n';
	}
};


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

	BGoldenCoins solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

int main(){
  int64_t a,b,c,d;
  cin >> a >> b >> c >> d;
  int64_t A=a*c;
  int64_t B=a*d;
  int64_t C=b*c;
  int64_t D=b*d;
  cout <<  max({A,B,C,D}) << endl;
}

      

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

typedef long long ll;
#define rep(i,x) for(int i=0;i<x;i++)
#define put(ans)    cout << ans << endl;

double kaijyo(int n){
    int k(1);
    for(int i=n;i>0;i--){
        k *= i;
    }

    return k;
}

double distance(int x[],int y[],int i,int j){
    int dx = (x[i] - x[j]) * (x[i] - x[j]);
    int dy = (y[i] - y[j]) * (y[i] - y[j]);
    return sqrt(dx+dy);
}

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

    ll ans(l),sum(0);
    for(int i=0;i<n;i++){
        sum += a[i];
        ans = min(ans,abs(2*sum-l));
    }

    cout << ans << endl;

    return 0;
}

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

vector<long long> adj[200005];
vector<long long> res;
int visited[200005]={0};

void dfs(long long v)
{
    for(auto itr:adj[v])
    {
        if(visited[itr])continue;
        res[itr]+=res[v]; //
        visited[itr]=1;
        dfs(itr);
    }
}

int main()
{
    long long n,q;
    cin>>n>>q;
    long long a,b;
    for(int i=0;i<n-1;i++)
    {
        cin>>a>>b;
        a--;b--;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    long long p,x;
    res.resize(n);
    for(int i=0;i<q;i++)
    {
        cin>>p>>x;
        p--;
        res[p]+=x;
    }
    visited[0]=1;
    dfs(0);//Yo !
    
    for(int i=0;i<n;i++)
    {
        cout<<res[i]<<" ";
    }
}


Measured memory_bytes: 21888
import java.util.*;

public class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int ans = 1;
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		if(b == 1) {
			System.out.print(0);
		}
		else {
			while(true) {
				if(((a * ans) - (ans - 1)) >= b) {
					break;
				}
				ans++;
			}
			System.out.print(ans);
		}
	}
}

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

using namespace std;

int n, m;  

int get_dist(int i, int j) {
    return min(abs(i - j), n - abs(i - j));
}

void solve() {
    cin >> n >> m;
    //assert(n <= 100000);
    int ptr = 0;
    int maxd = n / 2 - 1;
    set<int> deltas;
    int cnt = 0;
    set<int> taken;
    while (maxd > 0 && cnt < m) {
        cout << ptr + 1 << ' ' << ptr + maxd + 1 << "\n";
        deltas.insert(maxd);
        deltas.insert(n - maxd);
        taken.insert(ptr);
        taken.insert(ptr + maxd);
         assert(ptr + maxd + 1 <= n);
        ++ptr;
        maxd -= 2;
        ++cnt;
    }
    maxd = n / 2;
    ptr = n / 2;
        if (ptr + maxd > n - 1) maxd -= 2;
    while (maxd > 0 && cnt < m) {
        cout << ptr + 1 << ' ' << ptr + maxd + 1 << "\n";
        assert(ptr + maxd + 1 <= n);
        deltas.insert(get_dist(ptr, ptr + maxd));
         taken.insert(ptr);
         deltas.insert(maxd);
        deltas.insert(n - maxd);
        taken.insert(ptr + maxd);
        maxd -= 2;
        ++ptr;
        ++cnt;
    }
    //assert(2 * m == int(deltas.size()));
    assert(2 * m == int(taken.size()));
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	solve();
	return 0; 
}

Measured memory_bytes: 20356
#include <iostream>
using namespace std;
int main() {
  int A,B,C,S;
  cin >> A >> B >> C;
  if ((A>B)&&(A>C))
    S=B*C/2;
  else if ((B>A)&&(B>C))
    S=A*C/2;
  else if ((C>A)&&(C>B))
    S=B*A/2;
  cout << S <<"\n";
}

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

const long long maxint = 1000000000000000000;

int main() {
  int N;
  long long A, ans = 1;

  cin >> N;

  for (int i = 1; i <= N; i++) {
    cin >> A;

    if (A == 0) {
      ans = 0;
      break;
    }

    if (A > maxint / ans) ans = -1;
    if (ans != -1) ans *= A;
    if (ans < 0) ans = -1;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3612
#D
N, K = map(int, input().split())
P = list(map(int, input().split()))
ans = sum(P[0:K])
sum_P = ans

for i in range(1, N-K+1):
    sum_P = sum_P - P[i-1] + P[i+K-1]
    ans = max(ans, sum_P)
#     ans = max(ans, K+0.5*(sum_P-K))
    
print(K+0.5*(ans-K))

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

using namespace std;
 
/*int BinarySearch(vector <int>v3,int n, int x){
      int low=0;
      int high=(n-1);
      while(low<=high){
         int mid=low+(high-low)/2;
          if(x==v3[mid]) return mid;
          if(x<v3[mid]) high=mid-1;
          if(x>v3[mid]) low=mid+1;
      }
    return -1;
}*/
/*long long int Power10(int q){
    long long int o,t=1;
    for(o=0;o<q;o++)
        {t*=10;}
    return t;
}*/
/*int digit(char ch){
    return(ch - '0');
}*/
/*int Search(vector<long long int> v1,long long int x1){
    long long int j;
    for(j=0;j<v1.size();j++){
        if(x1==v1[j]){return j;}
        else{continue;}
    }
    return -1;
}*/
/*int Search2(long long int v[],long long int x,long long int n){
    long long int i;
    for(i=0;i<n;i++){
        if(x==v[i]){return 1;}
        else{continue;}
    }
    return -1;
}*/
typedef map<char,int> mapsi;
int main(){
    long long int m,c=0,cont=0,p=0,j,a=0,b=0,i,e,r=0,g,pts,y,t,d=0,q,x,n,h,mr=17,ms=17,w,l,k,cnt=500,countA=0,sum,sumt,countB=0,countC=0,a1,a2,countD=0;
    long long int min[100000];
    set<char> s2;
    vector<char> v;
    vector<long long int> v2;
    string str1,str2;
    mapsi mp;
    string s;
    cin>>s;
    for(i=0;i<s.length();i++){
    s2.insert(s[i]);
    v.push_back(s[i]);  
    }
  for(auto it=s.begin();it!=s.end();++it){
        m=count(s.begin(),s.end(),*it);
        if(m%2==0){cont++;}
  }
  
  if(cont==s.length()){cout<<"Yes";}
  else{cout<<"No";}
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {int d;
            cin>>d;
            if(d==25)
              cout<<"Christmas"<<endl;
            else if(d==24)
              cout<<"Christmas Eve"<<endl;
            else if(d==23)
              cout<<"Christmas Eve Eve"<<endl;
            else if(d==22)
              cout<<"Christmas Eve Eve Eve"<<endl;
              }

Measured memory_bytes: 256
def binarysearch(arr,key)
    left = 0
    right = arr.count-1
    while left <= right
        mid = (left+right)/2
        if arr[mid] == key
            return mid
        elsif key < arr[mid]
            right = mid-1
        else
            left = mid +1
        end
    end
    return false
end

n =gets.to_i
S =gets.split(" ").map(&:to_i)
q =gets.to_i
T =gets.split(" ").map(&:to_i)

count = 0

T.each do |x|
    if binarysearch(S,x)
        count +=1
    end
end

puts count


Measured memory_bytes: 15348
s = input()
K = int(input())

list = []
for i in range(len(s)):
  for j in range(i+1,len(s)+1):
    tmp = s[i:j]
    if len(list)>=K:
      if tmp>list[-1]:
        break
      else:
        if not tmp in list:
          list.append(tmp)
          list.sort()
          list = list[:K]
    else:
      if not tmp in list:
        list.append(tmp)
        list.sort()
        if len(list)>K:
          list = list[:K]

print(list[K-1])

Measured memory_bytes: 3064
#pragma region header
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <algorithm>
using namespace std;
typedef long long ll;
template <class T> ll size(const T& x) { return x.size(); }
#define rep(i,a,b) for(ll i = (a); i < (b); i++)
#define iter(it,c) for(auto it = (c).begin(); it != (c).end();++it)
#define pb push_back
#define fs first
#define sc second
#define MOD 998244353
typedef pair<ll, ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;

const int INF = ~(1 << 31);
const double pi = acos(-1);
const double EPS = 1e-9;

ll mod_pow(ll b, ll e, ll m) {
	//formulan er b^e (mod m)
	ll res = 1;
	while (e)
	{
		if (1 & e) res = res * b % m;
		b = b * b % m;
		e /= 2;
	}
	return res % m;
}
ll f[1000010];
void find()
{
	f[0] = 1;
	f[1] = 1;
	rep(i, 2, 1000009) {
		f[i] = (i * f[i - 1]) % MOD;
	}
}

ll c(int a, int b)
{
	ll den = (f[b]) * (f[a - b]) % MOD;
	return (f[a] * mod_pow(den, MOD - 2, MOD)) % MOD;
}

ll n, m, k;
void solve() {
	cin >> n >> m >> k;
	ll sm = 0;
	rep(i, 0, k+1)
	{
		sm += (((c(n - 1, i) * m) % MOD )* mod_pow(m - 1, n - i-1, MOD)) % MOD;
	}
	cout << sm % MOD << endl;
}

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

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

int main(){
    unsigned long H, W;
    cin >> H >> W;
    deque<deque<bool>> poka(H, deque<bool>(W));
    for(auto& i : poka){
        string s;
        cin >> s;
        transform(s.begin(), s.end(), i.begin(), [](auto c){return c == '#';});
    }
    vector<vector<unsigned long>> score(H, vector<unsigned long>(W, 0));
    for(unsigned long i = 0; i < H; ++i){
        for(unsigned long j = 0, k = 0; j < W; ++j)score[i][j] = k += poka[i][j] ? -k : 1;
        for(unsigned long j = W, k = 0; j--;)score[i][j] += k += poka[i][j] ? -k : 1;
    }
    for(unsigned long j = 0; j < W; ++j){
        for(unsigned long i = 0, k = 0; i < H; ++i)score[i][j] += k += poka[i][j] ? -k : 1;
        for(unsigned long i = H, k = 0; i--;)score[i][j] += k += poka[i][j] ? -k : 1;
    }
    vector<unsigned long> tap(H);
    transform(score.begin(), score.end(), tap.begin(), [](auto a){return *max_element(a.begin(), a.end());});
    cout << max(3UL, *max_element(tap.begin(), tap.end())) - 3 << endl;
    return 0;
}

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

int main(){
  int i,j,cnt=0;
  int n;
  cin>>n;
  int a[n],b[n];
  for(i=0;i<n;i++)cin>>a[i]>>b[i];
  vector<pair<int,int>> v;
  for(i=0;i<n;i++){
    v.push_back(pair<int,int>(b[i],a[i]));
  }
  sort(v.begin(),v.end());
  ll S=0;
  for(i=0;i<n;i++){
    S+=v[i].second;
    if(S>v[i].first){
      cout<<"No";
      return 0;
    }
  }
  cout<<"Yes";
}

Measured memory_bytes: 3956
#include <iostream>
#include <cstring>
using namespace std;
const int M = 1e5 + 10;
int a[M];
int main() {
    int n;
    cin >> n;
    for(int i = 1 ; i <= n ; i++) {
        cin >> a[i];
    }
    int ans = 1;
    int flag = -1;
    for(int i = 2 ; i <= n ; i++) {
        if(flag == -1) {
            if(a[i] > a[i - 1]) {
                flag = 1;
                continue;
            }
            else if(a[i] < a[i - 1]) {
                flag = 0;
                continue;
            }
        }
        if(flag == 1) {
            if(a[i] < a[i - 1]) {
                ans++;
                flag = -1;
            }
            continue;
        }
        else if(flag == 0){
            if(a[i] > a[i - 1]) {
                ans++;
                flag = -1;
            }
            continue;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <vector> 
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
using namespace std;

int main(){
    string S;
    string T;
    cin>>S>>T;
    bool ans=true;
    for(int i=0;i<S.length();i++){
        if(S[i]==T[i]){

        }else{
            ans=false;
        }
    }
    if(ans)cout<<"Yes";
    else cout<<"No";
}

Measured memory_bytes: 3596
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<cmath>
#define pb(in,tmp) in.push_back(tmp)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) loop(i,0,b)
using namespace std;
int main(){
int n;
cin>>n;
rep(i,n){
int out=0;
int r1=0,r2=0,r3=0;
int tm=0;
while(out!=3){
char in[10];
cin>>in;
if(strcmp(in,"OUT")==0)out++;
if(strcmp(in,"HIT")==0){
if(r3==1){tm++;r3=0;}
if(r2==1){r3=1;r2=0;}
if(r1==1){r2=1;r1=0;}
r1++;
}
if(strcmp(in,"HOMERUN")==0){
if(r1==1){tm++;r1=0;}
if(r2==1){tm++;r2=0;}
if(r3==1){tm++;r3=0;}
tm++;
}
}
cout<<tm<<endl;
}
}

Measured memory_bytes: 1164
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
using namespace std;
#define ll int64_t
const long MOD = 1e9 + 7;




int main()
{
  string s, m; //かっている数//最大100
  cin >> s ;


  if (s.size() ==3){
    reverse(s.begin(),s.end());
  }
  bool ans = false;


  cout  << s;

  return 0;
}



























Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      int x = sc.nextInt();
      int y = sc.nextInt();
      int[] array1 = {1,3,5,7,8,10,12};
      int[] array2 = {4,6,9,11,0,0,0};
      int count1 = 0;
      int count2 = 0;
      for(int i = 0;i < 7;i++){
      	if(x == array1[i]||y == array1[i])count1++;
        if(x == array2[i]||y == array2[i])count2++;
      }
      if(count1 == 2||count2 == 2)System.out.println("Yes");
      else System.out.println("No");
      
    }
}


Measured memory_bytes: 21844
import std;

auto input()
{
    return readln().chomp();
}

alias sread = () => readln.chomp();
alias aryread(T = long) = () => readln.split.to!(T[]);

void main()
{
    string s;
    s = input();
    // writeln(s);
    string key;
    key = "keyence";

    foreach (i; 0 .. key.length + 1)
    {
        string tmp = s[0 .. i] ~ s[$ - (7 - i) .. $];
        // writeln(tmp);
        if (tmp == key)
        {
            writeln("YES");
            return;
        }

    }
    writeln("NO");

}

void scan(L...)(ref L A)
{
    auto l = readln.split;
    foreach (i, T; L)
    {
        A[i] = l[i].to!T;
    }
}


Measured memory_bytes: 3644
#include "iostream"
#include "string"


int main()
{
	int listA[101][101], listB[101][101];
	unsigned long int result[101][101] = { 0 };
	int n, m, l;
	std::cin >> n >> m >> l;

	for (int i = 0; i < n; i++) 
		for (int j = 0; j < m; j++)
			std::cin >> listA[i][j];

	for (int j = 0; j < m; j++)
		for (int k = 0; k < l; k++)
			std::cin >> listB[j][k];

	for (int i = 0; i < n; i++) {
		for (int k = 0; k < l; k++) {
			for (int j = 0; j < m; j++) {
				result[i][k] += listA[i][j] * listB[j][k];
			}
		}
	}

	for (int i = 0; i < n; i++)
		for (int k = 0; k < l; k++) {
			if (k < (l - 1))
				std::cout << result[i][k] << " ";
			else
				std::cout << result[i][k] << std::endl;

	}

    return 0;
}

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

int main(){
	LL a, b, c;
	cin >> a >> b >> c;
	if(a % 2 && b % 2 && c % 2){
		if(a <= c && b <= c){
			cout << a * b << endl;
		} else if(a <= b && c <= b){
			cout << a * c << endl;
		} else {
			cout << b * c << endl;
		}
	} else {
		cout << 0 << endl;
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define int long long
const int maxn=2e6+10,maxi=1e9+10;
long long a[maxn],fen[maxn];
int b[maxn],c[maxn];
void add(long long idx,long long val){
    for(;idx<maxn;idx+=(idx&-idx)){
	fen[idx]+=val;
    }
}
long long get(long long idx){
    long long sum=0;
    for(;idx;idx-=(idx&-idx)){
	sum+=fen[idx];
    }
    return sum;
}
int32_t main(){
    IOS;
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
	cin>>a[i];
    }
    if(n==1){
	cout<<a[1]<<endl;
	return 0;
    }
    long long s=1,e=maxi;
    while(s+1!=e){
	long long mid=(s+e)/2;
	memset(b,0,sizeof(b));
	//memset(c,0,sizeof(c));
	memset(fen,0,sizeof(fen));
	for(int i=1;i<=n;i++){
	    if(a[i]<mid){
		b[i]=b[i-1]+1;
		//c[i]=c[i-1]+1;
	    }
	    else{
		b[i]=b[i-1]-1;
		//c[i]=c[i-1]-1;
	    }
	}
	for(int i=1;i<=n;i++){
	    b[i]+=n+1;
	    //c[i]+=n+1;
	}
	long long ans=0;
	add(n+1,1);
	//long long ok=n*(n-1)/2+1;
	for(int i=1;i<=n;i++){
	    ans+=get(b[i]-1);
	    add(b[i],1);
	}
	if(ans>((n*(n+1))/4)){
	    e=mid;
	}
	else{
	    s=mid;
	}
    }
    cout<<s<<endl;
}


Measured memory_bytes: 35072
#include <bits/stdc++.h>
#define mod 1000000007
#define N 2000500

using namespace std;
typedef long long LL;
LL Fac[N],Inv[N],Iac[N];
int x[7],y[7];
inline int rd() {
	int x=0,f=1;char ch=getchar();
	while (ch>'9'||ch<'0') {if(ch=='-')f=-1;ch=getchar();}
	while (ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
	return x*f;
}

inline void inc(LL &x,LL y) {x=(x+y)%mod;}

inline LL C(int x,int y) {
    return 1LL * Fac[x+y] * Iac[x] % mod * Iac[y] % mod;
}

inline LL W(int x1,int y1,int x2,int y2) {
    x1 = abs(x1); y1=abs(y1); x2=abs(x2); y2=abs(y2);
    return (1LL *C(x2+1,y2+1) - C(x2+1,y1) - C(x1,y2+1) + C(x1,y1)+mod + mod) % mod;
}


void init() {
	for (int i=1;i<=6;i++) x[i] = rd();
	for (int i=1;i<=6;i++) y[i] = rd();
}

void prepare() {
	int n = 2000000;
	Fac[0] = Fac[1] = 1;
	for (int i=2;i<=n;i++) Fac[i] = 1LL * Fac[i-1] * i % mod;
	Inv[0] = Inv[1] = 1;
	for (int i=2;i<=n;i++) Inv[i] = 1LL * (mod - mod / i) * Inv[mod%i] % mod;
	Iac[0] = Iac[1] = 1;
	for (int i=2;i<=n;i++) Iac[i] = 1LL * Iac[i-1] * Inv[i] % mod;
}

void solve() {
	LL ans = 0LL;
	for (int _=x[3];_<=x[4];_++)
		inc(ans, 1LL*(mod-_-y[3])*W(_-x[2],y[3]-1-y[2],_-x[1],y[3]-1-y[1])%mod * W(_-x[5],y[3]-y[5],_-x[6],y[3]-y[6])%mod);
	
	for (int _=x[3];_<=x[4]; _++)
		inc(ans, 1LL*(_+y[4]+1)*W(_-x[2],y[4]-y[2],_-x[1],y[4]-y[1])%mod*W(_-x[5],y[4]-y[5]+1,_-x[6],y[4]-y[6]+1)%mod);

	for (int _=y[3];_<=y[4];_++)
		inc(ans, 1LL*(mod-_-x[3])*W(x[3]-1-x[2],_-y[2],x[3]-1-x[1],_-y[1])%mod *W(x[3]-x[5], _-y[5], x[3]-x[6], _-y[6])%mod);

	for (int _=y[3];_<=y[4];_++)
		inc(ans, 1LL*(_+x[4]+1)*W(x[4]-x[2],_-y[2],x[4]-x[1],_-y[1])%mod *W(x[4]-x[5]+1,_-y[5],x[4]-x[6]+1,_-y[6])%mod);

    cout<<ans<<endl;
}

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


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

#define MOD 1000000007
typedef unsigned long long ull;

int n;
string a,b;
int main() {
    cin >> n >> a >> b;
    for (int i = 0; i < n; i++) {
        cout << a[i] << b[i];
    }
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>

int main(void){
    int N,K,*h,c=0;
    scanf("%d %d",&N,&K);
    h = malloc(sizeof(int)*N);
    for(int i=0;i<N;i++){
        scanf("%d",&h[i]);
        if(h[i] >= K) c++;
    }
    printf("%d",c);
    return 0;
}

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

using namespace std;

int main() {
  long long n, m;
  cin >> n >> m;

  long long ans = min(n, m / 2);
  long long use = min(n, m / 2);
  n -= use;
  m -= use * 2;
  ans += m / 4;
  cout << ans << endl;
  return 0;
}

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

int main()
{
  int n, m, x, c[12], a[12][12], min = -1;
  cin >> n >> m >> x;
  for (int i = 0; i < n; i++)
  {
    cin >> c[i];
    for (int j = 0; j < m; j++)
    {
      cin >> a[i][j];
    }
  }

  for (int bit = 0; bit < (1 << n); ++bit)
  {
    int cost = 0;
    int skill[12] = {0};

    for (int i = 0; i < n; ++i)
    {
      if (bit & (1 << i))
      {
        cost += c[i];
        for (int j = 0; j < m; j++)
        {
          skill[j] += a[i][j];
        }
      }
    }
    for (int j = 0; j < m; j++)
    {
      if (skill[j] < x)
      {
        goto out;
      }
    }
    if (min == -1 || min > cost)
    {
      min = cost;
    }
  out:
    min;
  }
  cout << min << endl;
}


Measured memory_bytes: 3620
object Main extends App {
  import scala.io.StdIn._

  val Array(n, tLimit) = readLine.trim.split(' ').map(_.toInt)
  val routes = Array.tabulate(n){_ ⇒
    val Array(c, t) = readLine.trim.split(' ').map(_.toInt)
    (c, t)
  }
  println(
    routes.filter(_._2 <= tLimit).let(a ⇒ if (a.nonEmpty) a.minBy(_._1)._1 else "TLE")
  )
  implicit class ScopeFunc[T](value: T){
    def let[A](func: T ⇒ A): A = func(value)
    def also(func: T ⇒ Unit): T = {
      func(value)
      value
    }
  }
}

Measured memory_bytes: 25656
//In The Name Of GOD

#include <bits/stdc++.h>
using namespace std;
typedef long long ll ;
const ll mod = 998244353;
const ll inf = 2000000000;
const ll infll = (ll)2*1000*1000*1000*1000*1000*1000;
const ll maxn = 100*1000+1;
#define pb push_back
#define pp pop_back
#define X first
#define Y second
#define IO ios_base::sync_with_stdio(false);
ll a[maxn],par[maxn],plsz[maxn],mark[maxn];//par in pile and pile size

ll find_fad(ll x){//find the root in the pile
  if(par[x]==x)
    return x;
  else
    return find_fad(par[x]);
}

ll mergit(ll x,ll y){//for meging two pile
  if(x==y){
    return 0;
  }
  if(plsz[x]>plsz[y]){
    par[y]=x;
  }else if(plsz[x]<plsz[y]){
    par[x]=y;
  }else{
    par[y]=x;
    plsz[x]++;
  }
}

int main(){
  IO;
  ll n,m,comp=0,ans=0;
  cin>>n>>m;
  for(ll i=0;i<n;i++){
   cin>>a[i];
   par[i]=i,plsz[i]=1;
  }
  for(ll i=0;i<m;i++){
   ll u,v;
   cin>>u>>v;
   // u--,v--;
   mergit( find_fad(u) , find_fad(v) );
  }
  pair<ll,ll> mn[n];
  for(ll i=0;i<n;i++){
   if(find_fad(i)==i){
     mn[i]={infll,infll};
   }
  }
  for(ll i=0;i<n;i++){
   mn[find_fad(i)]=min(mn[find_fad(i)],{a[i],i});
  }
  for(ll i=0;i<n;i++){
   if(find_fad(i)==i){
     comp++;
     ans+=mn[i].X;
     // cout<<mn[i].X<<' ';
     mark[mn[i].Y]=true;
   }
  }
  vector<ll> all;
  for(ll i=0;i<n;i++){
   if(!mark[i]){
     all.pb(a[i]);
   }
  }
  // cout<<ans<<endl;
  sort(all.begin(),all.end());
  if((ll)all.size()<(comp-2)){
    cout<<"Impossible";
    return 0;
  }
  for(ll i=0;i<comp-2;i++){
    // cout<<all[i]<<' ';
    ans+=all[i];
  }
  // cout<<endl;
  if(comp-2>=0)
  cout<<ans;
  else
  cout<<0;
}


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

int main(void)
{
    string S;
    cin >> S;
    if (S.length() % 2 == 0) {
        int hug = 0;
        for (int i = 0; i < (S.length() / 2); i++) {
            if (S[i] != S[S.length()-1-i]) {
                hug++;
            }
        }
        cout << hug << endl;
    }
    else {
        int hug = 0;
        for (int i = 0; i < S.length()/2; i++) {
            if (S[i] != S[S.length()-1-i]) {
                hug++;
            }
        }
        cout << hug << endl;
    }
}

Measured memory_bytes: 256
/*
      author : nishi5451
      created: 12.08.2020 17:09:17
*/

#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,k;
    cin >> n >> k;
    ll ans = k;
    n--;
    while(n--){
        ans*=(k-1);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3560
#include<bits/stdc++.h>
#define ll                  long long
#define dl                 double
#define pb                push_back
#define F                  first
#define S                  second
#define endl              "\n"
#define rep(i,a,b)       for(i=a;i<b;i++)
#define all(v)             v.begin(),v.end()
#define allr(v)            v.rbegin(),v.rend()
#define mod              1000000007LL
#define CIN(V,s,n)      for(int i=s;i<n;i++){cin >> V[i];}
#define COUT(V,s,n)   {for(int i=s;i<n;i++){cout <<  V[i] << " "  ;} cout << endl;}
#define fast               ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define CLEAR(V);      for(ll i=0;i<V.size();i++) V[i] = 0;
#define N                  150
#define tmod             998244353LL
using namespace std;

bool sBs(const pair<int,int> &a,const pair<int,int> &b)
{   return (a.second < b.second);   }

ll SUMD(ll n);
ll BS(vector<pair< ll ,ll > > &PS,ll s,ll e,ll ser);
ll MI(ll a, ll m);
//bool P[N+1];
void Sieve(int n=N);
ll Powb(ll b,ll n,ll m);

int main()
{
fast;
ll q=1,t;
//cin >> q;
while(q--)
{
    ll i,j,n,m,k,l,r,a,b,c=0,d=0,e,g,p,q,u,v,w,x,y,flag=1;
    //n=m=k=i=j=l=r=a=b=c=d=u=v=w=p=x=y=0;
    cin >> x;
    map<ll,ll> M;
    for(i=-6000;i<=6000;i++)
        M[i*i*i*i*i] = i;
    for(i=-6000;i<=6000;i++)
    {
        b = x + i*i*i*i*i;
        if(M.find(b)!=M.end())
        {
            cout << M[b] <<  " " << i << endl; break;
        }
    }
}
    return 0;
}

//*****************************************************************************************************************************************

ll Powb(ll b,ll n,ll m)
{
    if(n==0) return 1LL;
    if(n==1) return b;
    ll temp = Powb(b,n/2,m);
    if(n%2==0){return (temp*temp)%m;}
    else{return (b*((temp*temp)%m))%m;}
}

ll SUMD(ll n)
{   ll sum=0;
    while(n>0){sum += n%10;n = n/10;}
    return sum;

}
ll BS(vector<pair<ll,ll> > &PS,ll s,ll e,ll ser)
{
    if(s>e)
        return s;
    ll mid = (s+e)/2;
    if(PS[mid].F==ser)
    {
        return mid;
    }
    else if(PS[mid].F > ser)
    {
        return BS(PS,s,mid-1,ser);
    }
    else
        return BS(PS,mid+1,e,ser);
}
ll MI(ll a, ll m)
{
    ll m0 = m;
    ll y = 0, x = 1;
    if (m == 1)
      return 0;
    while (a > 1)
    {
        ll q = a / m;
        ll t = m;
        m = a % m, a = t;
        t = y;
        y = x - q * y;
        x = t;
    }
    if (x < 0)
       x += m0;
    return x;
}
/*
void Sieve(int n)
{
    memset(P,true,sizeof(P));
    P[0] = false;
    P[1]= false;
    for(ll i=2;i*i<=n;i++)
    {
        if(P[i])
        {
            for(ll j=i*i;j<=n;j+=i)
            {
                P[j]=false;
            }
        }
    }

}

*/


Measured memory_bytes: 4404
N = int(input())
V = list(map(int,input().split()))

from collections import Counter
c1 = Counter(V[::2])
c2 = Counter(V[1::2])
m1 = c1.most_common()
m2 = c2.most_common()

if m1[0][0] != m2[0][0]:
    ans = N - m1[0][1] - m2[0][1]
    print(ans)
    exit()
if len(m1) == len(m2) == 1:
    print(N//2)
    exit()

ans = N
if len(m1) > 1 and m1[1][0] != m2[0][0]:
    ans = min(ans, N - m1[1][1] - m2[0][1])
if len(m2) > 1 and m1[0][0] != m2[1][0]:
    ans = min(ans, N - m1[0][1] - m2[1][1])
if len(m1) > 1 and len(m2) > 1 and m1[1][0] != m2[1][0]:
    ans = min(ans, N - m1[1][1] - m2[1][1])
print(ans)

Measured memory_bytes: 21052
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,n,s,f,r=0;
  int t[1001]={};
  cin >> a >> b >> n;
  for(int i=a; i<b; i++) t[i]++;

 // for(int i=0; i<11; i++) cout << t[i] << " ";

  for(int i=0; i<n; i++){
        cin >> s >> f;
        for(int i=s; i<f; i++) t[i]++;
  }
  /*cout << endl;
  for(int i=0; i<11; i++) cout << t[i] << " ";
  */
  for(int i=0; i<1000; i++) if(t[i]>=2) r++;
  if(r!=0) cout << 1 << endl;
  else cout << 0 << endl;

  return 0;
}


Measured memory_bytes: 3096
n = int(input())
A = [[int(i) for i in input().split()] for i in range(n)]

x, y = 1, 1
for i in range(n):
    a, b = A[i]
    m = max(-(-x // a), -(-y // b))
    x, y = a * m, b * m
    #print(x, y)
        
print(x + y)

Measured memory_bytes: 3188