akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

using ll = long long;

ll dp[51], dp2[51];

ll solve(int level, ll rest) {
    if (rest == 0) return 0;
    if (level == 0) return 1;

    if (rest <= 1) return 0;
    rest--;
    if (rest == 0) return 0;
    
    ll hoge = min(rest, dp[level - 1]);
    ll res = (hoge == dp[level - 1] ? dp2[level - 1] : solve(level - 1, hoge));
    rest -= hoge;

    if (rest == 0) return res;

    rest--;
    res++;

    hoge = min(rest, dp[level - 1]);
    res += (hoge == dp[level - 1] ? dp2[level - 1] : solve(level - 1, hoge));
    rest -= hoge;

    if (rest == 0) return res;
    rest--;
    return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    ll x;
    cin >> n >> x;

    dp[0] = 1;
    dp2[0] = 1;
    for (int i = 1; i <= n; i++) {
        dp[i] = 2 * dp[i - 1] + 3;
        dp2[i] = 2 * dp2[i - 1] + 1;
    }
    cout << solve(n, x) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 60;
int n;
int v[N];
double ans;
int main(){
	scanf("%d",&n);
	for(int i=1; i<=n; i++){
		scanf("%d",&v[i]);
	}
	sort(v+1, v+1+n);
	ans=v[1];
	for(int i=1; i<=n; i++){
		ans=(ans+v[i])/2;
	}
	printf("%lf\n",ans);
	return 0;
}


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

void fnInput(int &a_riLoadingCnt, int &a_riTrackCnt, vector<int> &a_rviLoading)
{
  cin >> a_riLoadingCnt >> a_riTrackCnt;

  a_rviLoading.resize(a_riLoadingCnt);
  for (int i = 0; i < a_riLoadingCnt; i++)
    cin >> a_rviLoading[i];
}

int fnSimuAlloc(const vector<int> &a_cnrviLoading, int a_iTrackCnt, int a_iMinLoading)
{
  int iCurLoading;
  int iTrackCnt = 0;

  for (int i = 0; i < a_cnrviLoading.size();    )
  {
    if (a_cnrviLoading[i] > a_iMinLoading  ||
        ++iTrackCnt       > a_iTrackCnt      ) return 0;

    iCurLoading = 0;
    while (i < a_cnrviLoading.size())
    {
      iCurLoading += a_cnrviLoading[i];
      if (iCurLoading > a_iMinLoading)
        break;

      i++;
    }
  }
  return 1;
}

void fnAllocation(const vector<int> &a_cnrviLoading, int a_iTrackCnt, int &a_riMinLoading)
{
  const int cniMinLoading = 0;
  const int cniMaxLoading = 1000000000;

  int iLow  = cniMinLoading;
  int iHigh = cniMaxLoading;
  a_riMinLoading = cniMaxLoading;

  while (iLow < iHigh)
  {
    int iMid = (iLow + iHigh) / 2;
    if (fnSimuAlloc(a_cnrviLoading, a_iTrackCnt, iMid))
    {
      a_riMinLoading = min(a_riMinLoading, iMid);
      iHigh = iMid;
    }
    else
      iLow = iMid + 1;
  }
}

void fnResultOut(int a_iMinLoading)
{
  cout << a_iMinLoading << endl;
}

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

  int iLoadingCnt, iTrackCnt;
  vector<int> viLoading;
  int iMinLoading = 0;

  fnInput(iLoadingCnt, iTrackCnt, viLoading);
  fnAllocation(viLoading, iTrackCnt, iMinLoading);
  fnResultOut(iMinLoading);

  return 0;
}

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

#define int long long
#define debug(x) cout<<#x<<" "<<x<<endl;

const int N=1e6+5;
const double eps=1e-9;
const int INF=1e18;

signed main()
{
    //freopen("a.in","r",stdin);
    //freopen("a.out","w",stdout);
    int h,a;
    cin>>h>>a; 
    for(int i=1;i<=a;i++){
        int x;cin>>x;
        h-=x;
    }
    if(h<=0) puts("Yes");
    else puts("No");
    return 0;
}

//Created Time  :2020/1/26 20:09:32


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> i_i;

#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define ALL(v) v.begin(), v.end()
#define SZ(x) ((int)(x).size())

const double PI  = acos(-1.0);
const double EPS = 1e-9;
const ll INF = 1e9+10;
const ll mod = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define print(x) cerr << #x << " is " << x << endl;
//#define print(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl; 
int main()
{
    int A, B;
    cin >> A >> B;
    rep(x, 10000){
        if (A == x * 8/100 && B == x * 10/100){
            cout << x;
            return 0;
        }
    }
    cout << -1;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef pair<int, int> P;

int yoko[2020][2020];
int tate[2020][2020];
int sum[2020][2020];

signed main(){
    int n, m, q;
    cin >> n >> m >> q;
    vector<string> s(n);
    rep(i, 0, n){
        cin >> s[i];
    } 
    rep(i, 0, n){
        rep(j, 0, m){
            if(s[i][j] == '1'){
                sum[i + 1][j + 1] = 1;
            }
        }
    }
    rep(i, 0, n){
        rep(j, 0, m - 1){
            if(s[i][j] == '1' && s[i][j + 1] == '1'){
                yoko[i + 1][j + 1] = 1;
            }
        }
    }
    rep(i, 0, m){
        rep(j, 0, n - 1){
            if(s[j][i] == '1' && s[j + 1][i] == '1'){
                tate[j + 1][i + 1] = 1;
            }
        }
    }
    rep(i, 1, n + 1){
        rep(j, 1, m + 1){
            sum[i][j] += sum[i][j - 1];
        }
    }
    rep(i, 1, m + 1){
        rep(j, 1, n + 1){
            sum[j][i] += sum[j - 1][i];
        }
    }
    rep(i, 1, n + 1){
        rep(j, 1, m){
            yoko[i][j] += yoko[i][j - 1];
        }
    }
    rep(i, 1, m){
        rep(j, 1, n + 1){
            yoko[j][i] += yoko[j - 1][i];
        }
    }
    rep(i, 1, n){
        rep(j, 1, m + 1){
            tate[i][j] += tate[i][j - 1];
        }
    }
    rep(i, 1, m + 1){
        rep(j, 1, n){
            tate[j][i] += tate[j - 1][i];
        }
    }
    // // vector<int> y1(q), y2(q), x1(q), x2(q);
    // rep(i, 0, n){
    //     rep(j, 0, m + 1){
    //         cout << tate[i][j] << " ";
    //     }
    //     cout << endl;
    // }
    rep(i, 0, q){
        int y1, y2, x1, x2;
        cin >> y1 >> x1 >> y2 >> x2;
        // cin >> y1[i] >> x1[i] >> y2[i] >> x2[i];
        int cnt = sum[y2][x2] + sum[y1 - 1][x1 - 1] - sum[y2][x1 - 1] - sum[y1 - 1][x2];
        // cout << cnt << endl;
        int myoko = 0, mtate = 0;
        if(x2 != x1) myoko = yoko[y2][x2 - 1] + yoko[y1 - 1][x1 - 1] - yoko[y2][x1 - 1] - yoko[y1 - 1][x2 - 1];
        // cout << myoko << endl;
        if(y2 != y1) mtate = tate[y2 - 1][x2] + tate[y1 - 1][x1 - 1] - tate[y2 - 1][x1 - 1] - tate[y1 - 1][x2];
        // cout << mtate << endl;
        cout << cnt - myoko - mtate << endl;
    }
    
}

Measured memory_bytes: 101248
# Disjoint Set
# https://onlinejudge.u-aizu.ac.jp/problems/DSL_1_A


class UnionFind:
    __slots__ = ["_size", "_first_index", "_parents"]

    def __init__(self, size: int, is_zero_indexed: bool = True) -> None:
        self._size = size
        self._first_index = 0 if is_zero_indexed else 1
        self._parents = [-1] * (size + self._first_index)

    def find(self, x: int) -> int:
        """Find the group (root) of vertex x"""
        if self._parents[x] < 0:
            return x
        self._parents[x] = self.find(self._parents[x])
        return self._parents[x]

    def is_same(self, x: int, y: int) -> bool:
        """Return whether two vertices x and y are in the same group or not."""
        return self.find(x) == self.find(y)

    def unite(self, x: int, y: int) -> None:
        """Unite two groups of vertices x and y."""
        x, y = self.find(x), self.find(y)
        if x == y:
            return
        if self._parents[x] > self._parents[y]:
            x, y = y, x
        self._parents[x] += self._parents[y]
        self._parents[y] = x

    def get_size(self, x: int) -> int:
        """Get the size of the group vertex x belongs"""
        return -self._parents[self.find(x)]

    @property
    def groups(self) -> int:
        """Return the number of groups."""
        return len({self.find(x) for x in range(self._first_index, self._size + self._first_index)})


def main():
    N, Q = map(int, input().split())
    uf = UnionFind(N)
    ans = []
    for _ in range(Q):
        com, x, y = map(int, input().split())
        if com:
            ans.append(uf.is_same(x, y) * 1)
        else:
            uf.unite(x, y)
    print("\n".join(map(str, ans)))


if __name__ == "__main__":
    main()



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

using namespace std;

#define llong long long int
#define ldouble long double
#define fore(i, n) for(auto &i : n)
#define rep(i, n) for (int i = 0; i < n; ++i)
#define repr(i, n) for (int i = n; i >= 0; --i) 
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

const static int mod = 1000000000 + 7;
const static int inf = INT_MAX / 2;
const static llong INF = LLONG_MAX / 2;
const static double eps = 1e-6;
const static int dx[] = {1, 0, -1, 0};
const static int dy[] = {0, 1, 0, -1};

template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

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

    string S;
    cin >> S;
    map<char, int> M;
    M['a'] = 0;
    M['b'] = 0;
    M['c'] = 0;
    const int n = S.size();
    rep(i, n) ++M[S[i]];

    if (M['a'] == M['b'] && M['b'] == M['c'] && M['a'] == M['c']) {
        cout << "YES" << endl;
    } else {
        int max_cnt = -1, min_cnt = inf;
        rep(i, 3) {
            chmax(max_cnt, M['a' + i]);
            chmin(min_cnt, M['a' + i]);
        }

        if (max_cnt - min_cnt >= 2) cout << "NO" << endl;
        else cout << "YES" << endl;
    }

    return 0;
}

Measured memory_bytes: 512
import math
A, B, H, M = map(int, input().split())

A_angle = (( H+( M/60 ))/12)*2*math.pi
B_angle = (M/60)*2*math.pi

ans_pos_x = A*math.cos(A_angle) - B*math.cos(B_angle)
ans_pos_y = A*math.sin(A_angle) - B*math.sin(B_angle)

ans = math.sqrt( ans_pos_x**2 + ans_pos_y**2 )

print(ans)

Measured memory_bytes: 9508
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;
int main(){
  int N;
  cin>>N;
  int judge=0;
  int answer=0;
  for(int i=0;i<N;i++){
    int d,e;
    cin>>d>>e;
    if(d==e){
      judge++;
      if(judge==3){
        answer++; break;
      }
    }
    else judge=0;
  }
  if(answer==1) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  
  return 0;
}

Measured memory_bytes: 3104
import fractions

N, M = map(int,input().split(" "))
S = input()
T = input()

gcd = fractions.gcd(N,M)
if N >= M:
    high = N
    high_s = S
    high_r = N//gcd
    low = M
    low_s = T
    low_r = M//gcd
else:
    high = M
    high_s = T
    high_r = M//gcd
    low = N
    low_s = S
    low_r = N//gcd

cnt = low // low_r
ans = high * low_r
for i in range(0,cnt):
    high_c = high_s[ i * high_r ]
    low_c = low_s[ i * low_r ]
    if high_c != low_c:
        ans = -1
print(ans)

Measured memory_bytes: 5368
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {

    vector<vector<ll>>c(3,vector<ll>(3));
    rep(i,3){
        rep(j,3){
            cin>>c[i][j];
        }
    }

    vector<ll>sum(3);
    rep(i,3){
        rep(j,3){
            sum[i]+=c[i][j];
        }
    }
    vector<ll>sum2(3);
    rep(i,3){
        rep(j,3){
            sum2[i]+=c[j][i];
        }
    }
    if((sum[0]-sum[1])%3==0&&(sum[0]-sum[2])%3==0&&(sum[1]-sum[2])%3==0){
        if((sum2[0]-sum2[1])%3==0&&(sum2[0]-sum2[2])%3==0&&(sum2[1]-sum2[2])%3==0){
            cout<<"Yes"<<endl;
        }else{
            cout<<"No"<<endl;
        }
        
    }else{
        cout<<"No"<<endl;
    }




    return 0;
    

}

Measured memory_bytes: 3632
import           Data.Maybe
import           Data.List

main :: IO ()
main = do
    input <- getContents
    let [n, m] : list : _ = map read . words <$> lines input :: [[Int]]
    ( putStrLn
        . show
        . sum
        . map (\n -> n * (n - 1) `div` 2)
        . map length
        . group
        . sort
        . map (`mod` m)
        . scanl (+) 0
        )
        list


Measured memory_bytes: 13820
/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Code author: Saurabh Singhal
Code copy karne vaale tera muh kaala
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/

#include<bits/stdc++.h>
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define ppb pop_back

using namespace std;
typedef long long int ll;
typedef vector<int> vi_t;
typedef vector<ll> vll_t;
int t=1;
vll_t a,b;

int main(){
	//scanf("%d",&t);
	while(t--){
		int n,m;
		cin>>n>>m;
		vector<int>freq(m+1);
		for(int i=0;i<n;i++){
			int k;
			cin>>k;
			for(int i=0;i<k;i++){
				int a;
				cin>>a;
				freq[a]++;
			}
		}
		int count=0;
		for(int i=1;i<=m;i++){
			if(freq[i]==n){
				count++;
			}
		}
		cout<<count<<endl;
	}
}

Measured memory_bytes: 256
from collections import deque
import numpy as np

N = int(input())
graph = {i:[] for i in range(N)}
for _ in range(N-1):
    a,b = map(int,input().split())
    graph[a-1].append(b-1)
    graph[b-1].append(a-1)

# グラフのうち最も遠い2点の距離(木の直径)を求める
# 1. 適当な点からの最も遠い点uを求める
# 2. uから最も遠い点を求める
# 全探索×2

def bfs(graph,root):
    distance  = [0]*N
    visited = set()
    queue = deque([root])
    while len(queue) > 0:
        vertex = queue.popleft()
        for neighbour in graph[vertex]:
            if neighbour not in visited:
                distance[neighbour] = distance[vertex] + 1
                visited.add(neighbour)
                queue.append(neighbour)

    farthest_node = np.argmax(distance)
    farthest_dist = distance[farthest_node]
    return farthest_node, farthest_dist

u, _ = bfs(graph, root=0)
_, diamiter = bfs(graph, root=u)

if diamiter%3==1:
    ans = 'Second'
else:
    ans = 'First'
print(ans)

Measured memory_bytes: 88240
#include <stdio.h>

int main(){
  char s[10];
  scanf("%s",s);
  if(s[0]-'R'==0){
    printf("Sunny");
  }
  if(s[0]-'C'==0){
    printf("Rainy");
  }
  if(s[0]-'S'==0){
    printf("Cloudy");
  }
  return 0;
}

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

#define ll long long

int main(){
    string s;
    cin >> s;
    set<char> ss;
    for(int i=0; i<(int)s.length(); ++i){
        ss.insert(s[i]);
    }
    if(ss.size()==s.length())
        cout << "yes";
    else
        cout << "no";
    return 0;
}

Measured memory_bytes: 3624
import qualified Data.ByteString.Char8 as B
import qualified Data.IntSet as S
import Data.Array.IArray
import Data.Maybe

type Vertex = Int
type Vertexes = S.IntSet
type Edge = (Vertex, Vertex)
type Graph = Array Vertex Vertexes

buildG :: Int -> [Edge] -> Graph
buildG n = accumArray (flip S.insert) S.empty (1, n)

from :: Graph -> Vertex -> Vertexes
from g = (g !)

readUndirectedEdge :: B.ByteString -> [Edge]
readUndirectedEdge = concatMap ((\[v,w] -> [(v,w),(w,v)]) . map readVertex . B.words) . B.lines

readVertex :: B.ByteString -> Vertex
readVertex = fst . fromJust . B.readInt

main :: IO ()
main = do
 [n,_] <- map read . words <$> getLine
 es <- readUndirectedEdge <$> B.getContents
 let g = buildG n es
 print (one_stroke n g 1 S.empty)

one_stroke :: Int -> Graph -> Vertex -> Vertexes -> Int
one_stroke n g v visited
  | S.size visited == n - 1 = 1
  | S.null next = 0
  | otherwise = S.foldr (\w acc -> acc + one_stroke n g w (S.insert v visited)) 0 next
  where next = S.difference (from g v) visited

Measured memory_bytes: 892
S = input()
Ok = ["KIHBR", "AKIHBR", "KIHABR", "KIHBAR", "KIHBRA",\
    "AKIHABR", "AKIHBAR", "AKIHBRA", "KIHABAR", "KIHABRA", "KIHBARA",\
    "AKIHABAR", "AKIHABRA", "AKIHBARA", "KIHABARA", "AKIHABARA"]

print("YES" if S in Ok else "NO")
                


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

namespace ABC133
{
    class Program
    {
        static void Main(string[] args)
        {
            var nd = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var n = nd[0];
            var d = nd[1];
            List<int[]> vs = new List<int[]>();
            for(int i = 0; i < n; i++)
            {
                var tmpx = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
                vs.Add(tmpx);
            }
            var count = 0;
            for(int i = 0; i < n; i++)
            {
                for (int j = i + 1; j < n; j++)
                {
                    var x1 = vs[i];
                    var x2 = vs[j];
                    var tmpdis = 0.0;
                    for(int k = 0; k < d; k++)
                    {
                        tmpdis += (x1[k] - x2[k]) * (x1[k] - x2[k]);
                    }
                    tmpdis = Math.Sqrt(tmpdis);
                    if((int)tmpdis == tmpdis)
                    {
                        count++;
                    }
                }
            }
            Console.WriteLine(count);

        }
    }
}


Measured memory_bytes: 13396
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include <cctype>
#include <limits>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <iostream>
using namespace std;
int main() {
	double n, k, cnt = 0, dou;
	double ans = std::numeric_limits<double>::max_digits10;
	ans = 0;
	cin >> n >> k;
	for (int i = 1; i < n + 1; ++i) {
		dou = 1 / n;
		for (int j = i; j < k; j = j * 2) {

			dou = dou / 2;

		}

		ans = ans + dou;

	}
	cout <<setprecision(15) <<ans << endl;

	return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> ii;
typedef tuple<int, int, int> iii;

typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ld> vd;
typedef vector<ll> vl;

typedef set<int> si;
typedef set<ii> sii;
typedef set<ld> sd;
typedef set<ll> sl;

typedef map<int, int> mii;
typedef priority_queue<int> pqi;
typedef queue<int> qi;
 
#define mp make_pair
#define pb push_back
#define f first
#define s second

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  ll n, m;
  cin >> n >> m;
  vector<pair<ll, ll>> a(n); for (auto &x : a) cin >> x.f >> x.s;
  sort(a.begin(), a.end());
  ll ans = 0;
  for (auto &x : a) {
    if (m >= x.s) {
      ans += x.f * x.s;
      m -= x.s;
    }
    else if (m > 0) {
      ans += x.f * m;
      m = 0;
    }
    else break;
  }
  cout << ans << endl;
}

/*
USE LONG LONG!!!!

:pray: :fishy15:
:pray: :summitosity:
:pray: :prodakcin:

          .=     ,        =.
  _  _   /'/    )\,/,/(_   \ \
   `//-.|  (  ,\\)\//\)\/_  ) |
   //___\   `\\\/\\/\/\\///'  /
,-"~`-._ `"--'_   `"""`  _ \`'"~-,_
\       `-.  '_`.      .'_` \ ,-"~`/
 `.__.-'`/   (-\        /-) |-.__,'
   ||   |     \O)  /^\ (O/  | .        <-  BESSIE THE COW
   `\\  |         /   `\    /
     \\  \       /      `\ /
      `\\ `-.  /' .---.--.\
        `\\/`~(, '()      ('
         /(O) \\   _,.-.,_)    
        //  \\ `\'`      /
       / |  ||   `""""~"`
     /'  |__||
           `o
*/

Measured memory_bytes: 1792
using System;

namespace Test
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            Console.ReadLine();
            var nums = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);

            var swapNum = 0;
            for (int i = 0; i < nums.Length; i++)
            {
                var min = i;
                for (int j = i + 1; j < nums.Length; j++)
                {
                    if (nums[j] < nums[min])
                    {
                        min = j;
                    }
                }
                if (nums[min] < nums[i])
                {
                    Swap(ref nums[min], ref nums[i]);
                    swapNum++;
                }
            }

            Console.WriteLine(string.Join(" ",Array.ConvertAll(nums,x=>x.ToString())));
            Console.WriteLine(swapNum);
        }

        private static void Swap<T>(ref T p1, ref T p2)
        {
            var temp = p1;
            p1 = p2;
            p2 = temp;
        }
    }
}

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

int main()
{
	int n, hMax = 0, num = 0;
	cin >> n;
	vector<int> ls(n);
	for_each(ls.begin(), ls.end(), [](int& x) {cin >> x; });

	for_each(ls.begin(), ls.end(), [&](int& h) {
		if (h >= hMax) {
			++num;
			hMax = h;
		}
		});
	cout << num << endl;

	return 0;
}

Measured memory_bytes: 256
a,b=map(int,input().split())

cnt=abs(abs(a)-abs(b))
if a<0 and b<0:
    if abs(a)<abs(b):
        cnt+=2
    #elif a<b
    #a<bの時は符号変換不要
if a>0 and b>0:
    if a>b:
        cnt+=2
    #elif a<b
    #符号変換不要

if a<0 and b>0:
    cnt+=1
if a>=0 and b<=0 and a!=b:
    cnt+=1

print(cnt)

Measured memory_bytes: 38256
import java.util.Scanner;

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

		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();

		int plus = A + B;
		int minus = A - B;
		int times = A * B;
		
		int culc = Math.max(plus, minus);
		int result = Math.max(culc, times);
		System.out.print(result);

		sc.close();
	}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rrep(i,n) for(int (i) = (n) - 1; (i) >= 0; --(i)) //Reversi rep
#define nfor(i,a,b) for(int (i) = (a); (i) < (b); ++(i)) //Natural for
#define rfor(i,a,b) for(int (i) = (b); (i) >= (a); --(i)) //Reversi for

int main()
{
    int N,K,X,Y,ans;
    cin >> N >> K >> X >> Y;
    if(N >= K){
        ans = (N * X) - ((X - Y) * (N - K));
    }else{
        ans = N * X;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,b,a) for(int i=b;i>=a;i--)
#define For(i,a,b) for(int i=a;i<=b;i++)
#define Forenska(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define sqr(x) ((x)*(x))
#define lowbit(x) ((x)&(-x))
#define GREATER(x) x,vector<x>,greater<x>
#define randIn(L,R) (((LL)rand()*rand())%(R-L)+L)
#define __lcm(a,b) ((a)/__gcd(a,b)*(b))
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pLL;
typedef vector<int> vec;
typedef vector<LL> vecL;
typedef vector<pii> vecP;
typedef vector<pLL> vecPL;
typedef vector<string> vecS;
typedef vector<vec> mat;
typedef complex<double> point;
const long double PI=3.14159265358979323846264338327950288419716939937510582097;
const LL INFLL=0x3f3f3f3f3f3f3f3f;
const int INF=0x3f3f3f3f;
const long double EPS=1e-10;
int read()
{
    int x=0;
    char ch=' ';
    bool flag=false;
    while(ch<'0' || ch>'9')
    {
        if(ch=='-')flag=true;
        ch=getchar();
    }
    while(ch>='0' && ch<='9')
    {
        x=(x<<3)+(x<<1)+ch-'0';
        ch=getchar();
    }
    return flag?-x:x;
}

int main()
{
	int n=read();
	vec a(n);
	rep(i,0,n)cin>>a[i];
	sort(all(a));
	cout<<a.back()-a[0]<<endl;
	return 0;
}



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

int main() {
    int N, M;
    cin >> N >> M;
    int K;
    
    set<int> favorit;
    cin >> K;

    for (int i = 0; i < K; i++) {
        int temp;
        cin >> temp;
        favorit.insert(temp);
    }

    for (int j = 1; j < N; j++) {
        cin >> K;
        set<int> sub;
        for (int i = 0; i < K; i++) {
            int temp;
            cin >> temp;
            if (favorit.find(temp) != favorit.end()) sub.insert(temp);
        }
        favorit = sub;
    }
    cout << favorit.size() << endl;
    return 0;
}



Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>

#define int long

const int INF = 1000000009;
const long LINF = 1123456789012345678;

int n, m;
int cnt[50];

signed main(){
	scanf("%ld %ld", &n, &m);
	for(int i = 0; i < n; i++){
		int k;
		scanf("%ld", &k);
		for(int i = 0; i < k; i++){
			int a;
			scanf("%ld", &a);
			cnt[a]++;
		}
	}
	int ans = 0;
	for(int i = 1; i <= m; i++){
		if(cnt[i] == n){
			ans++;
		}
	}
	printf("%ld\n", ans);
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define SUM(a,b) a+b

int main(void){
    int r,c,i,j,m=0,n=0;
    scanf("%d %d",&r,&c);
    int ary[r+1][c+1];
    for(i=0;i<r;i++){
        for(j=0;j<c;j++) scanf("%d",&ary[i][j]);
    }
    for(i=0;i<r;i++,m=0){
        for(j=0;j<c+1;j++){
            if (j<c){
                printf("%d ",ary[i][j]);
                m=SUM(m,ary[i][j]);
            }
            else {
                ary[i][j]=m;
                printf("%d",m);
            }
        }
        printf("\n");
    }
    for(j=0;j<c+1;j++,m=0){
        for(i=0;i<r;i++){
            m=SUM(m,ary[i][j]);
        }
        printf("%d",m);
        if (j<c) printf(" ");
    }
    printf("\n");
    return 0;
}
            


Measured memory_bytes: 2048
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
    int N;
  	float ans  = 0;
    cin >> N;
    float v[N];
    for(int i = 0; i < N; i++) {
        cin >> v[i];
    }
    sort(v, v + N);
    for(int i = 0; i < N - 1; i++) {
        ans = (v[i] + v[i + 1]) / 2;
        v[i + 1] = ans;
    }
    cout << ans << endl;
     return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdio>
using namespace std;
int main() {
	int N, T;
	cin >> N >> T;

	vector<pair<int, int>>go(N);
	for (int i = 0;i < N;++i) {
		int c, t;
		cin >> c >> t;
		go[i] = make_pair(c, t);
	}
	sort(go.begin(), go.end());
	int ans = 0;
	for (int i = 0;i < N;++i) {
		if (go[i].second <= T) {
			ans = go[i].first;
			break;
		}
	}
	if (ans) {
		cout << ans << endl;
	}
	else {
		cout << "TLE" << endl;
	}

	return 0;
}

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

public class Main{

static BufferedReader s1;
static BufferedWriter out;
static String read() throws IOException{String line="";while(line.length()==0){line=s1.readLine();continue;}return line;}
static int int_v (String s1){return Integer.parseInt(s1);}
static long long_v(String s1){return Long.parseLong(s1);}
static int[] int_arr() throws IOException{String[] a=read().split("\\s+");int[] b=new int[a.length];for(int i=0;i<a.length;i++){b[i]=int_v(a[i]);}return b;}
static long[] long_arr() throws IOException{String[] a=read().split("\\s+");long[] b=new long[a.length];for(int i=0;i<a.length;i++){b[i]=long_v(a[i]);}return b;}
static void assign(){s1=new BufferedReader(new InputStreamReader(System.in));out=new BufferedWriter(new OutputStreamWriter(System.out));}
static long Modpow(long a,long p,long m){long res=1;while(p>0){if((p&1)!=0){res=(res*a)%m;}p >>=1;a=(a*a)%m;}return res;}
//......................................@uthor_Alx..............................................
static long mod=(long)1e9+7;

public static void main(String[] args) throws  IOException{
                assign();
                long n=long_v(read()),n1=n;
                int res=0;
                for(int i=2;(long)i*i<=n;i++){
                    if(n%i!=0) continue;
                    int c=0;
                    while(n1%i==0){c++;n1/=i;}
                    double k=(double)Math.sqrt(1+8*c);k-=1d;
                    k/=2d;k=(int)Math.floor(k);
                    res+=k;
                }
                if(n1>1) res++;
                out.write(res+"");
                out.flush();

    }
}


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

int top,S[1000];

void push(int x){
  S[++top] =x;
}

int pop(){
  top--;
  return S[top+1];
}

int main(){
  int a,b;
  top=0;
  char s[100];
  
  while(scanf("%s",s)!=EOF){
    if(s[0]=='+'){
      a=pop();
      b=pop();
      push(a+b);
    }else if(s[0]=='-'){
      b=pop();
      a=pop();
      push(a-b);
    }else if(s[0]=='*'){
      a=pop();
      b=pop();
      push(a*b);
    }else{
      push(atoi(s));
    }
  }


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

return 0;
}

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

using namespace std;

constexpr int MOD = 1000000007;

using Long = long long;
template<typename T>
using V = vector<T>;
template<typename T>
using Vv = V<V<T>>;
using Vb = V<bool>;
using Vvb = V<Vb>;
using Vi = V<int>;
using Vvi = V<Vi>;
using Vl = V<Long>;
using Vvl = V<Vl>;
using Vd = V<double>;
using Vvd = V<Vd>;
using Vs = V<string>;

template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    for (auto& x : v) {
        is >> x;
    }
    return is;
}

template <typename First, typename Second>
istream& operator>>(istream& is, pair<First, Second>& v) {
    for (auto& x : v) {
        is >> v.first >> v.second;
    }
    return is;
}

// *** SOLUTION BEGIN ***

void solve() {
    string s;
    cin >> s;
    if (s.size() == 26) {
        string t = s;
        if (next_permutation(begin(t), end(t))) {
            for (int i = 0; i < s.size(); ++i) {
                if (s[i] != t[i]) {
                    t.resize(i + 1);
                    break;
                }
            }
            cout << t;
        } else {
            cout << -1;
        }
        return;
    }
    for (char c = 'a'; c <= 'z'; ++c) {
        if (find(begin(s), end(s), c) == end(s)) {
            cout << s << c;
            return;
        }
    }
}

// *** SOLUTION END ***

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cout.precision(10);
    cout << fixed;
    solve();
    return 0;
}


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

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	ll a,b;
	cin>>a>>b;
	if (a==b)
		cout<<1;
	else
	{
		if ((a+b)%2)
			cout<<"IMPOSSIBLE";
		else
			cout<<(a+b)/2;
	}
}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

signed main(){
    string s;cin>>s;
    sort(all(s));
    if(s=="abc")cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
#define inf 100000000
#define Edge pair<int,int>
#define Graph vector<vector<Edge>>

int N,M,R;
vector<int> r;
int dist[200][200];

Graph G;

void dijkstra(int k){
	int prev[N];
	priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>> > que; // pair<distance,node>
	dist[k][k] = 0;
	que.push({0,k});
	while(!que.empty()){
		auto cur = que.top().second; que.pop();
		for(auto edge:G[cur]){
			auto node = edge.first;
			auto weight = edge.second;
			if(dist[k][cur] + weight < dist[k][node]){
				dist[k][node] = dist[k][cur] + weight;
				prev[node] = cur;
				que.push({dist[k][node], node});
			}
		}
	}
}

int sub_solve(vector<int> v){
	int ans =0;
	for(int i=0;i<v.size()-1;i++){
		auto cur = v[i];
		auto next = v[i+1];
		ans += dist[cur][next];
	}
	return ans;
}


void solve(){
	int ans = inf;
	for(int i=0;i<N;i++){
		for(int j=0;j<N;j++){
			dist[i][j] = inf;
		}
	}

	for(int node=0;node<N;node++){
		dijkstra(node);
	}

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

	do {
		ans = min(ans, sub_solve(r));
	}while(next_permutation(r.begin(),r.end()));

	cout << ans << endl;

}

int main(){
	cin >> N >> M >> R;
	r.resize(R);
	for(int i=0;i<R;i++){
		cin >> r[i];
		r[i]--;
	}
	int a,b,c;
	G.resize(N);
	for(int i=0;i<M;i++){
		cin >> a >> b >> c;
		a--;b--;
		G[a].push_back({b,c});
		G[b].push_back({a,c});
	}
	solve();
	return 0;
}


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

/*BigInteger
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/rational.hpp>
namespace xxx = boost::multiprecision;
using Bint = xxx::cpp_int;
using Real = xxx::number<xxx::cpp_dec_float<1024>>;
*/

#define int long long
#define pb(x) push_back(x)
#define m0(x) memset((x), 0LL, sizeof(x))
#define mm(x) memset((x), -1LL, sizeof(x))

//container
#define ALL(x) (x).begin(), (x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
#define PERM(c) \
  sort(ALL(c)); \
  for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c)))

// debug
#define GET_VAR_NAME(variable) #variable
#define test(x) cout << GET_VAR_NAME(x) << " = " << x << endl;

// bit_macro
#define Bit(n) (1LL << (n))
#define Bitset(a, b) (a) |= (1LL << (b))
#define Bitunset(a, b) (a) &= ~(1LL << (b))
#define Bitcheck(a, b) ((((a) >> (b)) & 1LL) == 1LL)
#define Bitcount(a) __builtin_popcountll((a))

//typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

//constant
constexpr int INF = (int)1e18;
constexpr int MOD = (int)1e9 + 7;
constexpr double PI = (double)acos(-1);
constexpr double EPS = (double)1e-10;
constexpr int dx[] = {-1, 0, 0, 1, 0, -1, -1, 1, 1};
constexpr int dy[] = {0, -1, 1, 0, 0, 1, -1, 1, -1};

//
template <typename T>
void chmax(T &a, T b) { a = max(a, b); }
template <typename T>
void chmin(T &a, T b) { a = min(a, b); }
//
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
struct Accelerate_Cin {
  Accelerate_Cin() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
} Accelerate_Cin;

int N;

bool C(int mid) {
  return mid * (mid + 1) / 2 >= N;
}

signed main() {
  cin >> N;

  int ok = N, ng = 0;
  while (abs(ok - ng) > 1) {
    int mid = (ok + ng) / 2;
    if (C(mid)) {
      ok = mid;
    } else {
      ng = mid;
    }
  }

  int now = ok * (ok + 1) / 2;

  for (int i = 1; i <= ok; i++) {
    if (i != now - N) cout << i << endl;
  }

  return 0;
}


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

int main(){
    int N;
    cin >> N;
    int A = 0;
    for (int i = 1; i < 100000000; i *= 10){
        A = A + N / i % 10; 
    }
    if (N % A == 0){
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
  // ここにプログラムを追記
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
n = int(input())
nums = list(map(int, input().split()))

for i in range(1, n):
    print(" ".join(map(str, nums)))
    v = nums[i]
    j = i - 1
    while j >= 0 and nums[j] > v:
        nums[j + 1] = nums[j]
        j -= 1
    nums[j + 1] = v

print(" ".join(map(str, nums)))



Measured memory_bytes: 5600
#include<iostream>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<math.h>
#include<functional>
#include<bitset>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
#define MOD 1000000007LL
#define INF 1000000000LL
#define EPS 1e-10
#define FOR(i,n,m) for(ll i=n;i<(int)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v)  sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back

ll n, a, b;
vector<ll> dfs(vector<bool>& used, ll tgt) {
	bitset<20> bi(tgt);
	vector<ll> c;
	for(ll i = n - 1; i >= 0; i--) {
		if(used[i]) continue;
		if(bi[i]) c.pb(i);
	}
	vector<ll> ret;
	if((ll)c.size() == 1) {
		ll p = c[0];
		ret.pb(0);
		REP(i, n) {
			if(p == i || used[i]) continue;
			vector<ll> nret = ret;
			for(ll j = (ll)ret.size() - 1; j >= 0; j--) {
				bitset<20> bii(ret[j]);
				bii[i] = 1;
				nret.pb(bii.to_ullong());
			}
			ret = nret;
		}
		vector<ll> nret = ret;
		for(ll j = (ll)ret.size() - 1; j >= 0; j--) {
			bitset<20> bii(ret[j]);
			bii[p] = 1;
			nret.pb(bii.to_ullong());
		}
		ret = nret;
	} else {
		ll p = c[0], q= c[1], r = c[2];
		bi[p] = 0; bi[q] = 0;
		used[q] = true;
		vector<ll> ret1 = dfs(used, bi.to_ullong());
		used[q] = false;
		bi[p] = 1; bi[q] = 1;
		vector<ll> ret2;
		ret2.pb(0);
		REP(i, n) {
			if(i == p || i == q || used[i]) continue;
			vector<ll> nret = ret2;
			for(ll j = (ll)ret2.size() - 1; j >= 0; j--) {
				bitset<20> bii(ret2[j]);
				bii[i] = 1;
				nret.pb(bii.to_ullong());
			}
			ret2 = nret;
		}
		vector<ll> nret = ret2;
		for(ll i = (ll)ret2.size() - 1; i >= 0; i--) {
			bitset<20> bii(ret2[i]);
			bii[p] = 1;
			nret.pb(bii.to_ullong());
		}
		ret2 = nret;
		REP(i, ret2.size()) {
			ret2[i] = ret2[i] ^ (1ll << q);
			ret2[i] = ret2[i] ^ ret1[(ll)ret1.size() - 1];
		}
		REP(i, ret1.size()) ret.pb(ret1[i]);
		REP(i, ret2.size()) ret.pb(ret2[i]);
	}
	return ret;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n >> a >> b;
	bitset<20> bi(a ^ b);
	if((ll)(bi.count()) % 2 == 0) {
		cout << "NO" << endl;
		return 0;
	}
	cout << "YES" << endl;
	vector<bool> used(n, false);
	vector<ll> ans = dfs(used, a ^ b);
	REP(i, ans.size()) ans[i] = ans[i] ^ a;
	DUMP(ans);
	return 0;
}

/* --------------------------------------- */


Measured memory_bytes: 3020
import java.util.*;
 
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    String S = sc.next();

    int red = 0;
    int blue = 0;
    for(int i=0; i<N;i++){
        if(S.charAt(i)=='R'){
            red++;
        }
        else{
            blue++;
        }
    }
    if(red>blue){
        System.out.println("Yes");
    }
    else{
        System.out.println("No");
    }
  } 
}

Measured memory_bytes: 22996
/* ****mittal**** */
#include<bits/stdc++.h>
#define ll          long long int 
#define pb          push_back
#define endl        '\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define jell        998244353
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define repr(i,a,b)   for(ll int i=a;i>=b;i--)
#define lbnd    lower_bound
#define ubnd        upper_bound
#define mp          make_pair
#define DEC(N)  cout << std::fixed; cout << setprecision(N);
using namespace std;
ll add(ll x,ll y)
{
return (x%hell+y%hell)%hell;
}
ll mul(ll x,ll y)
{
return ((x%hell)*(y%hell))%hell;
}
ll sub(ll x,ll y)
{
return (x-y+hell)%hell;
}
#define N  100005
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int TESTS=1;
//    cin>>TESTS;
    while(TESTS--)
    {
        ll x;
        cin>>x;
        ll ans=(x/500)*1000;
        ans+=((x%500)/5)*5;
        cout<<ans;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define REPr(i,n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m , n) for(int i = (n);i >=(m);--i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define VSCD(v,N) REP(i,N){int x; SCD(x); v.PB(x);}
#define VSCLLD(v,N) REP(i,N){long long x; SCLLD(x); v.PB(x);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x,S) (S.count(x) != 0)
using namespace std;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector < VI > VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
////////////////////////////////////////////////////////////////////
int dx[9] = {0,0,1,1,1,0,-1,-1,-1};
int dy[9] = {0,1,1,0,-1,-1,-1,0,1};

int main(){
    map<PII,ll> f;
    ll H,W,N;
    SCLLD3(H,W,N);
    REP(i,N){
        int a,b;
        SCD2(a,b);
        REP(j,9){
            PII p = MP(a+dx[j],b+dy[j]);
            f[p] = f[p] + 1;
        }
    }

    ll ans[10] = {};

    for(pair<PII, ll> p:f){
        int a = (p.first).first;
        int b = (p.first).second;

        if ((a <= 1) or (b <= 1) or (a >= H) or (b >= W)) continue;
        ans[p.second]++;

		//cout << p.first << " " << p.second << endl;
	}
    
    ll em = 0;
    FORq(i,1,9){
        em += ans[i];
    }


    PRINTLLD((H-2)*(W-2)-em);
    FORq(i,1,9){
        PRINTLLD(ans[i]);
    }

}

Measured memory_bytes: 56448
#include <bits/stdc++.h>
#define int long long
#define lint long long
#define pii pair<int,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))
#define POW(n) (1LL<<(n))
#define IN(i,a,b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a>b) { a=b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
template <typename T> inline T LB(vector<T>& v, T a) { return *lower_bound(ALL(v),a); }
template <typename T> inline int LBP(vector<T>& v, T a) { return lower_bound(ALL(v),a) - v.begin(); }
template <typename T> inline T UB(vector<T>& v, T a) { return *upper_bound(ALL(v),a); }
template <typename T> inline int UBP(vector<T>& v, T a) { return upper_bound(ALL(v),a) - v.begin(); }
template <typename T1, typename T2> ostream& operator<< (ostream& os, const pair<T1,T2>& p) { os << p.first << " " << p.second; return os; }
template <typename T1, typename T2> istream& operator>> (istream& is, pair<T1,T2>& p) { is >> p.first >> p.second; return is; }
template <typename T> ostream& operator<< (ostream& os, const vector<T>& v) { REP(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
template <typename T> istream& operator>> (istream& is, vector<T>& v) { for(T& in : v) is >> in; return is; }
template <typename T = int> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }
template <typename T, typename V> typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) { t = v; }
template <typename T, typename V> typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) { for(auto &e : t) fill_v(e,v); }
const lint MOD = 1000000007;
const lint INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    int N;
    cin >> N;
    cout << N*(N-1)/2 << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) FOR(i,0,b)
#define INF 1e9

using ll = long long;
const ll mod = LLONG_MAX;

ll n,a,b;
int main(){
    cin>>n>>a>>b;

    if((b-a)*(n-2)+1<0){
      cout<<0<<endl;
      return 0;
    }

    ll ans=(b-a)*(n-2)+1;

    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int N, M, a[333][333], ans = 1e9, num[333];
bool mark[333];
int main(){
	cin>>N>>M;
	for(int i = 1;i <= N; i++){
		for(int j = 1;j <= M; j++){
			scanf("%d", &a[i][j]);
		}
	}
	for(int i = 1;i <= M; i++){
		int p = 1;
//		printf("i=%d\n", i);
		for(int j = 1;j <= N; j++){
			int k = 1;
			while(mark[a[j][k]] && k <= M)k++;
			num[a[j][k]]++;
		}
		for(int j = 1;j <= M; j++){
//			printf("j=%d, num=%d\n", j, num[j]);
			if(num[j] > num[p])p = j;
		}
		mark[p] = true;
		ans = min(ans, num[p]);
		memset(num, 0, sizeof(num));
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 640
/**************************
 * Cavaliers are invincible !!!
 * Au: Hany01
 * Contest: 
 * Date: 
 * Email: hany01@foxmail.com
****************************/

#include<bits/stdc++.h>

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
#define Rep(i , j) for (register int i = 0 , i##_end_ = j; i < i##_end_ ; ++ i)
#define For(i , j , k) for (register int i = (j) , i##_end_ = (k) ; i <= i##_end_ ; ++ i)
#define Fordown(i , j , k) for (register int i = (j) , i##_end_ = (k) ; i >= i##_end_ ; -- i)
#define Set(a , b) memset(a , b , sizeof(a))
#define SZ(a) ((int)(a.size()))
#define ALL(a) a.begin(), a.end()
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define INF (0x3f3f3f3f)
#define INF1 (2139062143)
#define Mod (1000000007)
#define y1 wozenmezhemecaia 
#ifdef hany01
#define debug(...) fprintf(stderr , __VA_ARGS__)
#else
#define debug(...)
#endif

inline void File() {
#ifdef hany01 
	freopen("a.in" , "r" , stdin);
    freopen("a.out" , "w" , stdout);
#endif
}

template<typename T> inline bool chkmax(T &a, T b) { return a < b ? a = b, 1 : 0; }
template<typename T> inline bool chkmin(T &a, T b) { return b < a ? a = b, 1 : 0; }

inline int read() {
    register char c_; register int _ , __;
    for (_ = 0 , __ = 1 , c_ = getchar() ; !isdigit(c_) ; c_ = getchar()) if (c_ == '-')  __ = -1;
    for ( ; isdigit(c_) ; c_ = getchar()) _ = (_ << 1) + (_ << 3) + (c_ ^ 48);
    return _ * __;
}

int n, a[110], b[110], c[110], d[110], ans;

vector<int> A[105];
int vis[105], mat[105];
bool dfs(int n){
    Rep(i, SZ(A[n])) {
        int v=A[n][i];
        if (!vis[v]){
            vis[v]=1;
            if (!mat[v]||dfs(mat[v])){
                mat[v]=n; return 1;
            }
        }
    }
    return 0;
}

int main()
{
	File();
    n = read();
    For(i, 1, n) a[i] = read(), b[i] = read();
    For(i, 1, n) c[i] = read(), d[i] = read();
    For(i, 1, n) For(j, 1, n) if (a[i] < c[j] && b[i] < d[j]) A[i].pb(j);
    For(i,1,n){
        memset(vis,0,sizeof(vis));
        if (dfs(i)) ans++;
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 256