akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main(){
    int H,W,K,ans=0;
    cin >> H >> W >> K;
    vector<string> C(H);
    for(int i=0;i<H;i++) cin >> C.at(i);

    for(int i=0;i<(1<<H);i++){
        for(int j=0;j<(1<<W);j++){
            int cnt = 0;

            for(int m=0;m<H;m++){
                for(int n=0;n<W;n++){
                    if(i>>m&1) continue;
                    if(j>>n&1) continue;
                    if(C.at(m).at(n)=='#') cnt++;
                }
            }
            if(cnt==K) ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)

using ll = long long;
using P = std::tuple<int,int>;

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

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

    int A, B, C;
    std::cin >> A >> B >> C;
    string yesno[] = {"No", "Yes"};
    std::cout << yesno[A <= C && C <= B] << std::endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int a, b, c, d;
  cin >> a >> b >> c >> d;

  if (abs(a - c) <= d) {
    cout << "Yes" << endl;
  } else if (abs(a - b) <= d && abs(b - c) <= d) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')


def solve():
    w, h, x, y = [int(x) for x in input().split()]
    print((w*h)/2, int(w == 2 * x and h == 2 * y))

        



t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()


"""



"""


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

const int maxk = 3000;

int n, k, d[maxk + 1][maxk + 1], a[1000][1000], b[1000][1000];

void Paint(int x, int y) {
  int a = x - k + 1, b = y - k + 1;
  a %= 2 * k;
  b %= 2 * k;
  ++d[a][b];
  --d[a][b + k];
  --d[a + k][b];
  ++d[a + k][b + k];
}

int main(void) {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; ++i) {
    int x, y;
    char s[2];
    scanf("%d%d%s", &x, &y, s);
    if (s[0] == 'B') {
      Paint(x + k + k, y + k);
    } else {
      Paint(x + k, y + k);
    }
  }
  for (int i = 0; i < maxk; ++i) {
    for (int j = 0; j < maxk; ++j) {
      if (i) d[i][j] += d[i - 1][j];
      if (j) d[i][j] += d[i][j - 1];
      if (i && j) d[i][j] -= d[i - 1][j - 1];
      if ((i / k + j / k) & 1) {
        a[i % k][j % k] += d[i][j];
      } else {
        b[i % k][j % k] += d[i][j];
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < k; ++i) {
    for (int j = 0; j < k; ++j) {
      ans = max(ans, max(a[i][j], b[i][j]));
    }
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 43136
package main

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

func main() {
	a := nextInt()
	b := nextInt()
	array := []int{
		a,
		a - 1,
		b,
		b - 1,
	}
	sort.Ints(array)
	fmt.Printf("%v", array[2]+array[3])
}

func nextInt() int {
	v, _ := strconv.Atoi(nextReader())
	return v
}

func nextInt64() int64 {
	v, _ := strconv.ParseInt(nextReader(), 10, 64)
	return v
}

func nextString() string {
	return nextReader()
}

func nextInts(n int) []int {
	r := make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt()
	}
	return r
}

func nextInt64s(n int) []int64 {
	r := make([]int64, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt64()
	}
	return r
}

var nextReader func() string

func init() {
	nextReader = NewScanner()
}

func NewScanner() func() string {
	r := bufio.NewScanner(os.Stdin)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)
	return func() string {
		r.Scan()
		return r.Text()
	}
}

func Min(a int, b int) int {
	if a > b {
		return b
	}
	return a
}

func MaxIn2Values(a int, b int) int {
	if a > b {
		return a
	}
	return b
}

func MinIn2Values(a int, b int) int {
	if a < b {
		return a
	}
	return b
}

func Abs(a int) int {
	if a < 0 {
		return a * -1
	}
	return a
}


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

int main() {
    int n, count = 0;
    string s;
    cin >> n >> s;
    
    for(int i = 1; i<n;i++){
        if(s[i-1] !=s[i]) count++;
        
    }
    
    cout<<count+1<<endl;
    
    return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<vector>
#include <algorithm>
using namespace std;
int main() {
    int r,g,b;
    cin >> r >> g >> b;
    if((10*g+b)%4==0){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 3588
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

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

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;

bool flug = false;
string s;

void dfs(int index){
    if(index == s.size()){
        flug = true;
        return;
    }else if(index > s.size()){
        return;
    }

    if(s.substr(index, 5) == "dream"){
        dfs(index + 5);
    }
    if(s.substr(index, 7) == "dreamer"){
        dfs(index + 7);
    }
    if(s.substr(index, 5) == "erase"){
        dfs(index + 5);
    }
    if(s.substr(index, 6) == "eraser"){
        dfs(index + 6);
    }
}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> s;
    dfs(0);
    cout << (flug ? "YES" : "NO") << "\n";
    return 0;
}


Measured memory_bytes: 1872
#include<bits/stdc++.h>
#define int long long
using namespace std;


//https://www.geeksforgeeks.org/prime-factorization-using-sieve-olog-n-multiple-queries/

int MAXN = 10000001;
  
// stores smallest prime factor for every number 
int spf[10000001]; 

void sieve() 
{ 
    spf[1] = 1; 
    for (int i=2; i<MAXN; i++) 
  
        // marking smallest prime factor for every 
        // number to be itself. 
        spf[i] = i; 
  
    // separately marking spf for every even 
    // number as 2 
    for (int i=4; i<MAXN; i+=2) 
        spf[i] = 2; 
  
    for (int i=3; i*i<MAXN; i++) 
    { 
        // checking if i is prime 
        if (spf[i] == i) 
        { 
            // marking SPF for all numbers divisible by i 
            for (int j=i*i; j<MAXN; j+=i) 
  
                // marking spf[j] if it is not  
                // previously marked 
                if (spf[j]==j) 
                    spf[j] = i; 
        } 
    } 
} 
  
// A O(log n) function returning primefactorization 
// by dividing by smallest prime factor at every step 
int getFactorization(int x) 
{ 
    map<int, int> ret; 
    while (x != 1) 
    { 
        ret[spf[x]]++;
        x = x / spf[x]; 
    } 
    int mult = 1;
    for(auto x: ret)
        mult *= (x.second+1);
    return mult;
} 

int32_t main(){
    int n;
    cin >> n;
    sieve();
    int ans = 0;
    for(int i=1; i<n+1; i++){
        int fact = getFactorization(i);
        ans += i*fact;
    }
    cout << ans << "\n";
}



Measured memory_bytes: 81724
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int>P;
typedef pair<ll,ll>LLP;
const int MAXN=2e5+20;
const int MOD=1e9+7;
const int INF=0x3f3f3f3f;
const ll LLINF=0x3f3f3f3f3f3f3f3f;
const double PI=acos(-1.0);
const double RATE=0.995;
const double eps=1e-6;
std::mt19937 rnd(time(0));
int arr[MAXN];
signed main()
{
    int n;
    scanf("%d",&n);
    for(int i=0;i<n;++i)
    {
        scanf("%d",&arr[i]);
    }
    ll sum=0;
    for(int i=0;i<n;++i)
    {
        for(int j=i+1;j<n;++j)
        {
            sum+=1ll*arr[i]*arr[j];
        }
    }
    printf("%lld\n",sum);
    return 0;
}


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

char t[N][2];
int n ,i ,j ,m ,l ,min ,num[N] ,o[N] ,o2[N];

int main(){

  scanf("%d" ,&n);
  

  for(i=0;i<n;i++){
    scanf(" %s",&t[i][0]);
    o[i]=i;
    o2[i]=i;
    num[i]=atoi(&t[i][1]);

    ;
  }
    
  for(i=0;i<n;i++){
    for(j=n-1;j>i;j--){
      if(num[o[j]]<num[o[j-1]]){
	m=o[j];
	o[j]=o[j-1];
	o[j-1]=m;
      }
    }
  }
  
  for(i=0;i<n;i++){
    if(i==n-1) printf("%c%d" ,t[o[i]][0] ,num[o[i]]);
    else printf("%c%d " ,t[o[i]][0] ,num[o[i]]);
  }
  printf("\nStable\n");

  for(i=0;i<n;i++){
    min=o2[i];
    l=-0;
    for(j=i;j<n;j++){
      if(num[o2[j]]<num[min]) {
	min=o2[j];
	m=j;
	l++;
      }
    }
    if(l!=0){
    o2[m]=o2[i];
    o2[i]=min;
    }
  }
  m=0;

  for(i=0;i<n;i++){
    if(i==n-1) printf("%c%d" ,t[o2[i]][0] ,num[o2[i]]);
    else printf("%c%d " ,t[o2[i]][0] ,num[o2[i]]);
    if(o2[i]!=o[i]) m++;
  }
  if(m==0) printf("\nStable\n");
  else if(m!=0) printf("\nNot stable\n");
  
  return 0;
}



Measured memory_bytes: 2108
import sys
sys.setrecursionlimit(1000000)
N = int(input())
T = [[]for i in range(N+1)]
for i in range(N-1):
    a,b,c = map(int,input().split())
    T[a].append((b,c))
    T[b].append((a,c))
Q,K = map(int,input().split())
D = [0]*(N+1)
def f(v,p,cost):
    global T,K,D
    for C in T[v]:
        if C[0]!=p:
            D[C[0]] = cost+C[1]
            f(C[0],v,cost+C[1])
f(K,0,0)
for i in range(Q):
    x,y = map(int,input().split())
    print(D[x]+D[y])

Measured memory_bytes: 135600
using System;
class aizu{
    public static int Main(){
    	int[] n = new int[2];
    	string[] str = new string[2];
    	str = Console.ReadLine().Split(' '); 
    	n[0] = int.Parse(str[0]); 
    	n[1] = int.Parse(str[1]);  	
        Console.WriteLine("{0} {1}",n[0]*n[1],2*n[0]+2*n[1]);
        return 0;
    }
}

Measured memory_bytes: 9008
from collections import deque


def main():
    k = int(input())
    q = deque([i for i in range(1, 10)])
    answer = 0
    for i in range(k):
        now = q.popleft()
        answer = now
        if now % 10 != 0:
            q.append(10 * now + now % 10 - 1)
        q.append(10 * now + now % 10)
        if now % 10 != 9:
            q.append(10 * now + now % 10 + 1)
    print(answer)


if __name__ == '__main__':
    main()



Measured memory_bytes: 11916
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define print(x) cout << (x) << endl;
#define printa(x, n) for(ll i = 0; i < n; i++) {cout << (x[i]) << " ";} cout << endl;
#define printd(x) printf("%.12f\n", ans);
#define Yes() cout << "Yes" << endl;
#define No() cout << "No" << endl;
#define YES() cout << "YES" << endl;
#define NO() cout << "NO" << endl;
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;

int main(void) {
    int n;
    cin >> n;
    vi p(n), q(n);
    rep (i, n) cin >> p[i];
    rep (i, n) cin >> q[i];

    vector<int> num(n);
    rep (i, n) num[i] = i + 1;

    bool same = true;
    int a = 0, b = 0;
    do {
        same = true;
        a++;
        rep (i, n) if (num[i] != q[i]) same = false;
        if (same) break;
    } while (next_permutation(rng(num)));

    rep (i, n) num[i] = i + 1;

    same = true;
    do {
        same = true;
        b++;
        rep (i, n) if (num[i] != p[i]) same = false;
        if (same) break;
    } while (next_permutation(rng(num)));
    
    print(abs(a - b))
    return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
	int a,b,c;
	int n;
	
	int d[1001];
	int e[1001];
	int f[1001];
	int g[1001];
	
	int flg[301];
	while(1){
		scanf("%d%d%d",&a,&b,&c);
		if(a==0){
			break;
		}
		scanf("%d",&n);
		for(int i=0;i<301;i++){
			flg[i]=2;
		}
		
		for(int i=0;i<n;i++){
			scanf("%d%d%d%d",&d[i],&e[i],&f[i],&g[i]);
			if(g[i]==1){
				flg[d[i]]=1;
				flg[e[i]]=1;
				flg[f[i]]=1;
			}
		}
		
		for(int j=0;j<2;j++){
			for(int i=0;i<n;i++){
				if(g[i]!=0){
					continue;
				}
				if(flg[d[i]]==2 && flg[e[i]]==1 && flg[f[i]]==1){
					flg[d[i]]=0;
				}else
				if(flg[d[i]]==1 &&flg[e[i]]==2 && flg[f[i]]==1){
					flg[e[i]]=0;
				}else
				if(flg[d[i]]==1 && flg[e[i]]==1 &&flg[f[i]]==2){
					flg[f[i]]=0;
				}
			}
		}
		
		for(int i=1;i<a+b+c+1;i++){
			printf("%d\n",flg[i]);
		}
	}
}

Measured memory_bytes: 0
mod=998244353
N,A,B,K=map(int,input().split())
 
#繰り返し二乗法
def great_power(x, y):
    if   y == 0:
      return 1
    elif y == 1:
      return x % mod
    elif y % 2 == 0:
      return great_power(x, y//2)**2 % mod
    else:
      return great_power(x, y//2)**2 * x % mod

#階乗計算
factorial=[1]
for i in range(1,N+1):
    factorial.append(factorial[i-1]*i %mod)

#逆元計算
inverse=[0]*(N+1)
inverse[N] = great_power(factorial[N], mod-2)
for i in range(N-1, -1, -1):
    inverse[i] = inverse[i+1] * (i+1) % mod

#combination計算
def nCr(n,r):
  if n==r or n<r or r==0:
    return 1
  return factorial[n] * inverse[r] * inverse[n-r] % mod

ans=0

for i in range(N+1):
  if (K-A*i)%B==0 and (K-A*i)>=0:
    j=(K-A*i)//B
    if j <= N:
      ans+=( nCr(N,i) * nCr(N,j) ) %mod
      ans %= mod

print(ans)


Measured memory_bytes: 26840
#include <bits/stdc++.h>
using namespace std;
typedef complex <double> C;

class Point{
public:
  double x;
  double y;
  Point operator + (Point p)const{
    return (Point){x + p.x, y + p.y};
  }
  bool operator < (Point p)const{
    return x*x + y*y < p.x*p.x + p.y*p.y;
  }
};


bool throughO(Point p, Point v){
  if(abs(v.x) == 0 ){
    return abs(p.x) == 0;
  }
  double a = v.y / v.x;
  return abs(p.y - a*p.x) < 0.0000001;
}


int main(void){
  double D;
  while(cin >> D&&D){


    Point p, v;
    double ans = 0;

    cin >> p.x >> p.y >> v.x >> v.y;
    double len = sqrt(p.x * p.x + p.y * p.y);


    if(!throughO(p, v) ){
      cout << "impossible" << endl;
      //impossible
      continue;
    }

    double naiseki = -p.x * v.x + -p.y * v.y;
    if(abs(naiseki - len*sqrt(v.x*v.x + v.y*v.y)) > 0.000001){
      ans = 1 + (1 - len);
    }else{
      ans = len;
    }
    if(ans < D + 0.000001)
      printf("%.10f\n", ans);
    else
      cout << "impossible" << endl;
    //impossible
  }
}

Measured memory_bytes: 1272
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;

public class Main {
    private static Scanner sc;

    public Main() {
    }

    public static void main(String[] args) {
        sc = new Scanner(System.in);
        new Main().solve();

    }

    private void solve() {
        int N = sc.nextInt();
        Map<Integer, Integer> m = new HashMap<Integer, Integer>();

        for (int i = 0; i < N; i++) {
            int n = sc.nextInt();
            if (!m.containsKey(n)) {
                m.put(n, 1);
            } else {
                m.put(n, m.get(n) + 1);
            }
        }
        int cnt = 0;
        for (Entry<Integer, Integer> e : m.entrySet()) {
            if (e.getKey() > e.getValue()) {
                cnt += e.getValue();
            } else if (e.getKey() < e.getValue()) {
                cnt += e.getValue() - e.getKey();
            }
        }

        System.out.println(cnt);
    }
}


Measured memory_bytes: 63436
import java.util.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int X = sc.nextInt();
        int A = sc.nextInt();
        int B = sc.nextInt();
        String [] S = {"delicious","safe","dangerous"};
        System.out.println(S[judge(X,A,B)]);
    }
    static int judge(int X, int A, int B){
        if(A>=B)return 0;
        if(X>=B-A)return 1;
        return 2;
    }
}

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

using namespace std;

typedef long long          ll;
typedef unsigned long long ull;
typedef vector<int>	       vi;
typedef vector<bool>       vb;
typedef map<int, int>      mii;
typedef pair<int, int>     ii;

#define INF                0x3f3f3f3f
#define INFLL              0x3f3f3f3f3f3f3f3f
#define each(x, s)         for(auto& x : s)
#define loop(x)	           for(int i = 0;i < x;i++)
#define vloop(v, x)        for(int v = 0;v < x;v++)
#define avg(l, r)          l + (r - l) / 2
#define iter(a)            a.begin(), a.end()
#define riter(a)           a.rbegin(), a.rend()
#define endl               "\n"

const ll mod = 1000000007;

int main() {
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

	int x, y, z;
	cin >> x >> y >> z;
	cout << z << " " << x << " " << y << endl;
	return 0;
}



Measured memory_bytes: 256
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	a = readline() |> split |> parseMap
	a = sort(a)
	if a[1]==1&&a[2]==4&&a[3]==7&&a[4]==9
		println("YES")
	else
		println("NO")
	end
end

main()


Measured memory_bytes: 122776
def gcd(x,y):
  while y!=0:
    x,y=y,x%y
  return x

def lcm(x,y):
  return x*y//gcd(x,y)

a, b, c, d = map(int, input().split())
cd = lcm(c, d)

print(
    b - (b//c) - (b//d) + (b//cd) \
    -((a-1) - ((a-1)//c) - ((a-1)//d) + ((a-1)//cd))
    )

Measured memory_bytes: 3060
n = int(input())
s= list(input() for i in range(n))

acnt =0
bcnt =0
ecnt =0
cnt=0
nomal =0

for i in range(n):
    nomal += s[i].count('AB')
    t=0
    if s[i][0] == 'B':
        bcnt += 1
        cnt+=1
        t+=1
    if s[i][-1] == 'A':
        acnt += 1
        if not t:
            cnt+=1
        t+=1
    if t==2 :
        ecnt+=1

if cnt != 0 and cnt == ecnt:
    print(nomal + acnt-1)
else:
    print(nomal + min(acnt,bcnt))



Measured memory_bytes: 3700
#include <iostream>

using namespace std;

int main(void) {

  int a, b, c;
  int mon;
  int turi[3], turiidx;

  for(;;) {
    cin >> a >> b;
    if(a == 0 && b == 0) break;

    c = b - a;
    turiidx = 0;
    turi[0] = 0; turi[1] = 0; turi[2] = 0;

    mon = 1000;
    for(;;) {
      if (c - mon < 0) {
	switch(mon) {
	case 1000:
	  mon = 500;
	  turiidx = 1;
	  continue;
	case 500:
	  mon = 100;
	  turiidx = 2;
	  continue;
	case 100:
	  goto printres;
	}
      }
      c -= mon;
      turi[turiidx]++;
    }

  printres:
    cout << turi[2] << " " << turi[1] << " " << turi[0] << endl;
  }

  return 0;
}

Measured memory_bytes: 1160
import sys
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache, reduce
from operator import xor
INF = float("inf")
sys.setrecursionlimit(10**7)

# 4近傍（右, 下, 左, 上）
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]


def inside(y: int, x: int, H: int, W: int) -> bool: return 0 <= y < H and 0 <= x < W


def main():
    N = int(input())
    A = list(map(int, input().split()))
    for ans in count(0):
        for i in range(N):
            if A[i] % 2 != 0:
                print(ans)
                return
            else:
                A[i] //= 2


if __name__ == '__main__':
    main()


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

using namespace std;

#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long int
#define v(d_type) vector<d_type>
#define F first
#define S second
#define loop(i, s, n) for(int i = s; i < n; i++)
#define nl "\n"
#define fat 1000000007

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

    priority_queue< pair<int, pair<int, int> > > q;

    ll sum = 0;
    loop(i, 0, n)
    {
        int a;
        cin >> a;
        sum += a;
        q.push({a - a/2, {a, 1}});
    } 

    loop(i, 0, m)
    {
        if(q.empty()) break;
        pair<int, pair<int, int> > c = q.top();
        q.pop();

        sum -= c.F;

        int a = c.S.F;
        int exp = c.S.S;

        if(exp >= 30) continue; 
        int saving = a/(1 << exp) - a/(1 << (exp + 1));
        q.push({saving, {a, exp + 1}});
    }

    cout << sum << nl;
    return 0;
}

Measured memory_bytes: 1912
#line 1 "/mnt/c/Users/leafc/dev/compro/lib/template.hpp"


#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) (v).begin(), (v).end()
#define coutd(n) cout << fixed << setprecision(n)
#define ll long long int
#define vl vector<ll>
#define vi vector<int>
#define MM << " " <<

using namespace std;

template <class T> void say(bool val, T yes = "Yes", T no = "No") { cout << (val ? yes : no) << "\n"; }

template <class T> void chmin(T &a, T b) {
  if (a > b)
    a = b;
}

template <class T> void chmax(T &a, T b) {
  if (a < b)
    a = b;
}


#line 2 "tmp.cpp"

template <class T> T gcd(T n, T m) { return n ? gcd(m % n, n) : m; }

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int t;
  cin >> t;
  REP(num, t) {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    if (a < b) {
      cout << "No" << endl;
    } else if (d < b) {
      cout << "No" << endl;
    } else if (c >= b) {
      cout << "Yes" << endl;
    } else {
      if (a % b > c) {
        cout << "No" << endl;
      } else if (d % b == 0LL) {
        cout << "Yes" << endl;
      } else {
        ll g = gcd(b, d);
        if (b - g + (a % g) <= c) {
          cout << "Yes" << endl;
        } else {
          cout << "No" << endl;
        }
      }
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>

using namespace std;

vector<int> prime;

void Init() {
  enum { SIZE = 100000 };
  bool t[SIZE];
  fill(t, t + SIZE, true);
  t[0] = t[1] = false;
  for(int i = 0; i < SIZE; ++i) {
    if(t[i]) {
      prime.push_back(i);
      for(int j = i*2; j < SIZE; j += i)
	t[j] = false;
    }
  }
}

int m, a, b;

void Solve() {
  int pp = 0, qq = 0;
  for(int i = 0; i < (int)prime.size(); ++i)
    for(int j = i; j < (int)prime.size(); ++j) {
      long long p = prime[i];
      long long q = prime[j];
      if(p*q > m)
	break;
      if(a * q > p * b)
	continue;
      if(p*q > pp*qq) {
	pp = p;
	qq = q;
      }
    }
  cout << pp << " " << qq << endl;
}

int main() {
  Init();
  while(cin >> m >> a >> b && m) {
    Solve();
  }
}


Measured memory_bytes: 3224
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
  queue<int>st[1000];
  int n,tc,q,t;
  ll x;
  cin>>n>>tc;
  while(tc--)
  {
    cin>>q;
    if(q==0)
    {
      cin>>t>>x;
      st[t].push(x);
    }
    else if(q==1)
    {
      cin>>t;
      if(!st[t].empty())
      {
        cout<<st[t].front()<<endl;
      }
    }
    else if(q==2)
    {
      cin>>t;
      if(!st[t].empty())
      {
        st[t].pop();
      }
    }
  }
}



Measured memory_bytes: 4396
#!/usr/bin/perl
use strict;
use warnings FATAL => 'all';

my $line = <STDIN>;
my ($n, $l) = split(/ /, $line);

# 各リンゴの味
my @taste;
for (my $i = 1; $i <= $n; $i++) {
    my $taste = $l + $i - 1;
    push @taste, $taste;
}

# 絶対値が最小のリンゴ
my ($min);
for my $taste (@taste) {
    unless (defined $min) {
        $min = $taste;
        next;
    }

    if (abs($taste) < abs($min)) {
        $min = $taste;
    }
}

# アップルパイの味
my $sum = 0;
for my $taste (@taste) {
    next if $taste == $min;
    $sum += $taste;
}
print $sum;


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

using namespace std;

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

  int n;
  cin >> n;

  vector<int> A(n);
  map<int, int> hsh;
  for (auto &a : A) {
    cin >> a;
    hsh[a]++;
  }
  if (n%2 == 0) {
    for (auto &h : hsh) {
      if (h.first%2 == 0 || h.second != 2) {
        cout << 0 << endl;
        return 0;
      }
    }
  } else {
    for (auto &h : hsh) {
      if (h.first%2 == 1 || (h.first != 0 && h.second != 2)) {
        cout << 0 << endl;
        return 0;
      }
    }
  }
  long long res = 1;
  int mod = 1e9+7;
  for (int i = 0; i < n/2; ++i) {
    res = (res * 2)%mod;
  }
  cout << res << endl;

  return 0;
}



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

typedef pair<int, int> Pair;

int w;
int h;
char field[1145][1419];
bool used[1145][1419];
queue<Pair> q;

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

bool WithinRange(int y, int x) {
  if (y < 0 || h <= y) return false;
  if (x < 0 || w <= x) return false;
  return true;
}

int main() {
  while (1) {
    scanf("%d%d", &w, &h);
    if (w == 0 && h == 0) return 0;

    for (int i=0; i<h; i++) {
      for (int j=0; j<w; j++) {
        scanf(" %c", &field[i][j]);
        if (field[i][j] == '@') q.push(Pair(i, j));
        used[i][j] = false;
      }
    }

    int ans = 0;
    while (!q.empty()) {
      Pair p = q.front(); q.pop();
      int y = p.first;
      int x = p.second;
  
      if (used[y][x]) continue;    
      used[y][x] = true;
      ans++;

      for (int i=0; i<4; i++) {
        int newy = y + dy[i];
        int newx = x + dx[i];
        if (!WithinRange(newy, newx)) continue;
        if (field[newy][newx] == '#') continue;
        if (used[newy][newx]) continue;
        
        q.push(Pair(newy, newx));
      }
    }

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

Measured memory_bytes: 3228
#include <bits/stdc++.h>
 
using namespace std;
 
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
typedef long long ll;
#define int ll
 
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(int)(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
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 (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const long double pi = 3.1415926535897932384626433832795028841971L;
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl;
// int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
// int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
vi dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
vi dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
const ll MOD = 1000000007;
// const ll MOD = 998244353;
// #define mp make_pair
//#define endl '\n'


signed main() {
	fio();
	int n;
	cin >> n;
	ll zen = 0;
	vl a(n);
	rep (i, n) {
		cin >> a[i];
		zen ^= a[i];
	}	
	rep (i, n) {
		cout << (zen ^ a[i]) << " ";
	}
	cout << endl;
}

Measured memory_bytes: 4724
#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
int main(){
  int N,M;
  cin>>N>>M;
  scc_graph G(N);
  while(M--){
    int a,b;
    cin>>a>>b;
    G.add_edge(a,b);
  }
  vector<vector<int>> V=G.scc();
  cout<<V.size()<<endl;
  for(vector<int> v:V){
    cout<<v.size()<<' ';
    for(int i=0;i<v.size();i++)cout<<v[i]<<(i+1==v.size()?'\n':' ');
  }
}

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

int main(){
  	int maximum = 99;
	string s;
  	cin >> s;
  	int m,k;
  	bool ok;
	for(int i = 0; i< 26; i++) {
    	m = k=0;
      	ok = false;
      	for(int j = s.size()-1; j>= 0; j--) {
        	if(ok == false && s[j] == (char)(i+'a')) { 
            	m = s.size()-1-j;
              	ok = true;
              	k = 0;
            } else if(ok == true && s[j] != (char)(i+'a') ) {
            	 k++;
            } else if(ok == true && s[j] == (char)(i+'a')) {
              	if(k > m)
                  	m = k;
              	k=0;
            }
        }	
      	if(ok && maximum > max(m,k))
          	maximum = max(m,k);
        
    }
  	cout << maximum << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
typedef long long ll;

ll abs(ll a) {
  return a > 0 ? a : -a;
}

int main(void) {
  ll i, j, k, h, w;
  scanf("%lld%lld", &h, &w);
  ll a[h][w], b[h][w], d[h][w];
  bool dp[w][80 * (h + w)], tmp[w][80 * (h + w)];
  for(j = 0; j < w; ++j) for(k = 0; k < 80 * (h + w); ++k) dp[j][k] = false;
  for(i = 0; i < h; ++i) for(j = 0; j < w; ++j) scanf("%lld", &a[i][j]);
  for(i = 0; i < h; ++i) for(j = 0; j < w; ++j) scanf("%lld", &b[i][j]), d[i][j] = abs(a[i][j] - b[i][j]);
  for(i = 0; i < w; ++i) for(j = 0; j < 80 * (h + w); ++j) dp[i][j] = false;
  dp[0][d[0][0]] = true;
  for(i = 1; i < w; ++i) for(j = 0; j < 80 * (h + w); ++j) if(dp[i - 1][j]) {
    dp[i][j + d[0][i]] = true;
    dp[i][abs(j - d[0][i])] = true;
  }
  for(k = 1; k < h; ++k) {
    for(i = 0; i < w; ++i) for(j = 0; j < 80 * (h + w); ++j) tmp[i][j] = false;
    for(i = 0; i < 80 * (h + w); ++i) if(dp[0][i]) {
      tmp[0][i + d[k][0]] = true;
      tmp[0][abs(i - d[k][0])] = true;
    }
    for(i = 1; i < w; ++i) for(j = 0; j < 80 * (h + w); ++j) {
      if(tmp[i - 1][j]) {
        tmp[i][j + d[k][i]] = true;
        tmp[i][abs(j - d[k][i])] = true;
      }
      if(dp[i][j]) {
        tmp[i][j + d[k][i]] = true;
        tmp[i][abs(j - d[k][i])] = true;
      }
    }
    for(i = 0; i < w; ++i) for(j = 0; j < 80 * (h + w); ++j) dp[i][j] = tmp[i][j];
  }
  for(i = 0; ; ++i) if(dp[w - 1][i]) {
    printf("%lld", i);
    return 0;
  }
}

Measured memory_bytes: 2304
import sys

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

def insert(t, z):
    y = None
    x = t
    while x is not None:
        y = x
        if z.key < x.key:
            x = x.left
        else:
            x = x.right

    if y is None:
        return z
    else:
        if z.key < y.key:
            y.left = z
        else:
            y.right = z
        return t

def in_order(t):
    s = ""
    l = []
    curr = t
    while True:
        while curr is not None:
            l.append(curr)
            curr = curr.left
        if curr is None and len(l) == 0:
            break
        else:
            curr = l.pop()
            s += " " + str(curr.key)
            curr = curr.right
    return s

def pre_order(t):
    s = ""
    l = []
    curr = t
    while True:
        while curr is not None:
            s += " " + str(curr.key)
            l.append(curr)
            curr = curr.left
        if curr is None and len(l) == 0:
            break
        else:
            curr = l.pop()
            curr = curr.right
    return s

t = None
n = sys.stdin.readline()
lines = sys.stdin.readlines()
for line in lines:
    com = line.split()
    if line[0] == "i":
        t = insert(t, Node(int(com[1])))
    else:
        print(in_order(t))
        print(pre_order(t))

Measured memory_bytes: 152044
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
#define ll long long
#define ld long double
     
int main(){
  ll n;
  cin >> n;
  if(n%1000==0) cout << "0" << endl;
  else cout << ((n/1000)+1)*1000 - n << endl;
}

Measured memory_bytes: 3564
from collections import deque


N = int(input())
to = [[] for _ in range(N)]

for _ in range(N - 1):
    a, b = map(lambda x:int(x) - 1, input().split())
    to[a].append(b)
    to[b].append(a)

c = list(map(int, input().split()))
c.sort()


def main():
    ans = [0] * N
    ans[0] = c.pop()
    S = 0

    seen = [0] * N
    seen[0] = 1
    que = deque([0])

    while que:
        v = que.popleft()
        for nv in to[v]:
            if not seen[nv]:
                seen[nv] = 1
                ans[nv] = c.pop()
                S += ans[nv]
                que.append(nv)

    print(S)
    print(*ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 77032
#include<iostream>
#include<queue>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<utility>
#include<map>
#include<vector>

typedef long long ll;

using namespace std;

int main(void)
{
  ll a[112345]={};
  int i;
  int sum=0;
  int n;
  scanf("%d",&n);
  for(i=0;i<n;i++)
    {
      scanf("%d",&a[i]);
      if(a[i]%2==1)
	sum++;
    }

  if(sum%2)
    puts("NO");
  else
    puts("YES");
  return 0;
  
}


Measured memory_bytes: 1152
#include <iostream>
#define INF 1<<10;

using namespace std;

int main(){
    int n, cnt=0, max=0;
    long h, buf=0;
    cin >> n;
    for(int i=0; i<n; i++){
        cin >> h;
        if(h <= buf){
            cnt++;
        }else{
            max = (cnt > max) ? cnt : max;
            cnt = 0;
        }
        buf = h;
    }
    max = (cnt > max) ? cnt : max;
    cout << max << endl;
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <climits>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <list>
#include <ctime>
#include <complex>
#include <bitset>
#include <tuple>

#define ff first
#define ss second

using namespace std;
using pii=pair<int,int>;
using ll=long long;

int main()
{
    ios::sync_with_stdio(false);
	cin.tie(0);
    
    int n,m,x;
    cin>>n>>m>>x;
    vector<int> c(n);
    vector<vector<int>> a(n,vector<int>(m));
    for(int i=0; i<n; i++){
        cin>>c[i];
        for(int j=0; j<m; j++) cin>>a[i][j];
    }
    vector<int> v(n);
    int answer=INT_MAX;
    for(int i=0; i<n; i++){
        v[n-1-i]=1;
        do{
            int cost=0;
            vector<int> tmp(m);
            for(int j=0; j<n; j++){
                if(v[j]==1){
                    cost+=c[j];
                    for(int k=0; k<m; k++) tmp[k]+=a[j][k];
                }
            }
            bool check=true;
            for(int j=0; j<m; j++) if(tmp[j]<x) check=false;
            if(check) answer=min(answer,cost);
        }while(next_permutation(v.begin(),v.end()));
    }
    if(answer==INT_MAX) answer=-1;
    cout<<answer;

    return 0;
}


Measured memory_bytes: 3664
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define shosu(n) setprecision(n)
#define INF 999999999
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef vector<vb> vvb;
typedef vector<vpii> vvpii;
int main() {
  int a, b;
  cin >> a >> b;
  a--;
  b--;
  cout << a * b << endl;
  return 0;
}


Measured memory_bytes: 256
//
//AtCoder Beginner Contest 171
//X - XXXX
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <functional>
#include <cassert>

using namespace std;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SIZE(x) (int)(x).size()
#define SIZEL(x) (ll)(x).size()
#define MSG(a) cout << #a << " " << a << endl;

using ll = long long;
using ld = long double;

const double PI = 3.14159265358979323846;

ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }            //最小公倍数

int main()
{
    char a;
    cin >> a;

    if ('A'<=a && a<='Z') cout << "A" << endl;
    else cout << "a" << endl;

    return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

ll copy (ll i){
	return i;
}
int main(){
	ll n;cin >>n;
	vector<vector<ll>> v(10,vector<ll>(10,0));
	ll ans = 0;
	for(ll i = 1; i <= n; i++) {
		ll b = i % 10;
		ll a = copy(i); 
		while(a >= 10){
			a /= 10;
		}
		v[a][b]++;
		
	}

	for(int i = 1; i < 10; i++) {
		for(int j = 1; j < 10; j++) {
			ans += v[i][j] * v[j][i];
		}
	}
	cout <<ans << endl;
	return 0;
}

Measured memory_bytes: 256
import itertools,sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
N = I()
h = [None]+LI()
dp = [float('INF')]*(N+1) #1_indexed
dp[1] = 0
for i,j in itertools.product(range(1,N+1),[1,2]):
    if i+j>=N+1:
        continue
    dp[i+j] = min(dp[i+j],dp[i]+abs(h[i+j]-h[i]))
print(dp[-1])


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

#define ll                  long long int
#define llu                 long long unsigned
#define ld                  long double
#define fast                ios_base::sync_with_stdio(0);cin.tie(0);
#define endl                "\n"
#define pb                  push_back
#define bp                  pop_back
#define pf                  push_front
#define fp                  pop_front
#define mp                  make_pair
#define ms(a,b)             memset((a),(b),sizeof(a))
#define min3(a,b,c)         min(a,min(b,c))
#define max3(a,b,c)         max(a,max(b,c))
#define min4(a,b,c,d)       min(min(a,b),min(c,d))
#define max4(a,b,c,d)       max(max(a,b),max(c,d))
#define max5(a,b,c,d,e)     max(max3(a,b,c),max(d,e))
#define min5(a,b,c,d,e)     min(min3(a,b,c),min(d,e))
#define NUM                 1000000
#define PI		            2*acos(0.0)
#define maximum             (-1*INF)
#define READ(f) 	        freopen("f", "r", stdin)
#define WRITE(f) 	        freopen("f", "w", stdout)
const int INF = 1e5 + 10 ;

int main()
{
    ll n, sum = 0;
    cin>>n;
    for(ll i=1; i<=n; i++)
    {
        if(i%3 && i%5 && i%15)
            sum += i;
    }
    cout<<sum;
    return 0;
}


Measured memory_bytes: 3632
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
const int INF=100000000;

int main(){
	int n,t,a;
	double h[1010];
	pair<double,int> p[1010];
	cin>>n>>t>>a;
	REP(i,n){
		cin>>h[i];
	}
	REP(i,n){
		double d=(double)t-h[i]*0.006;
		p[i]={abs(d-(double)a),i};
	}
	sort(p,p+n);
	cout<<p[0].second+1<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<queue>
#include<cmath>
#include<algorithm>
#include<iomanip>
#include<functional>
#include<set>
#include<map>
#include<climits>
#include<numeric>
#include<utility>
#define ul unsigned long long int
#define ll long long int
#define MAX 1000000+1
using namespace std;
#define F first
#define S second
#define pi 2*acos(0.0)
#define PB push_back
#define CL clear()



int main()
{

ul a, b,c = 0;
cin >> a;
   b = (a/500);
   c = b*1000;
   a = a%500;
   c += (a-a%5);
   cout << c;

   return 0;

}




Measured memory_bytes: 256
ma = lambda :map(int,input().split())
ni = lambda:int(input())
import collections
import itertools
import math
n,k = ma()
A  = list(map(lambda x:int(x)-1,input().split()))
vis = [False]*n
cnt = [0]*n
vis[0] = 1
st = 0
c = 0
cyc = 0
l = 0
while True:
    c+=1
    nex = A[st]
    if c==k:
        print(nex+1)
        exit()
    if vis[nex]:
        cyc = cnt[st] - cnt[nex] +1
        l = cnt[st]+1
        break
    cnt[nex] = c
    vis[nex]=True
    st = nex
k = (k-l)%cyc
st = nex
while k>0:
    nex = A[st]
    st = nex
    k-=1
print(nex+1)


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

#define      pb    push_back
#define      ff    first
#define      ss    second
#define      ll    long long int
#define      endl  "\n"
#define      FASTIO        ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);


#define      TEST    int t ; cin >> t ; while( t -- )

const ll big = 10e17 + 11 ;

int  main (  ) {

    FASTIO ;

    double a , b , c , d ;

    cin >> a >> b >> c >> d ;

    int ans1 , ans2 ;

    ans1 = ceil( c / b ) ;
    ans2 = ceil( a / d ) ;

    if( ans1 <= ans2 ) cout << "Yes" ;
    else  cout << "No" ;


    return  0 ;
}


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

int main() {
    int s;
    cin >> s;
    
    bool flag = true;
    int j[10000] = {0};
    int count = 0;
    while (flag) {
        //cout << "s: " << s << endl;
        ++count;
        ++j[s];
        if (j[s] == 2) {
            cout << count << endl;
            return 0;
        }
        if (s%2 == 0) s/=2;
        else s = s*3+1;
        /*
        if (j[s] == 2) {
            cout << count << endl;
            return 0;
        }
        */
    }

    cout << "WTF!" << endl;

    return 0;
}


Measured memory_bytes: 256
n = int(input())

w = []

for i in range(n):
    w.append(input())

flag = True

if len(w) != len(set(w)):
    flag = False

for i in range(n-1):
    if w[i][-1] != w[i+1][0]:
        flag = False

if flag:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 38512
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>

using namespace std;

typedef long long ll;

map<int,int>mp;
map<int,int>mp2;
int a[100005];

int main(){

	int N;

	scanf("%d",&N);

	int i;

	for(i=0;i<N;i++){
		scanf(" %d",&a[i]);
		mp[a[i]]++;
	}
	ll ans=0ll;
	for(i=0;i<N;i++){
		if(mp2[a[i]]!=1){
			if(a[i]<mp[a[i]]){
				if(mp[a[i]]-a[i]<=mp[a[i]]){
					ans+=(ll)(mp[a[i]]-a[i]);
				}
				else{
					ans+=(ll)mp[a[i]];
				}
				mp2[a[i]]=1;
			}
			else if(a[i]>mp[a[i]]){
				ans+=(ll)mp[a[i]];
				mp2[a[i]]=1;
			}
		}
	}
	printf("%lld\n",ans);

	return 0;
}

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

using namespace std;

struct Node
{
	bool visited = false;
	vector<int> edges;
};

using Graph = vector<Node>;

inline int CanMove(const Graph &g, int node)
{
	for (int next : g[node].edges) {
		if (!g[next].visited) {
			return next;
		}
	}
	return -1;
}

vector<int> FindPath(Graph &g)
{
	vector<int> path;
	int node = 0;

	for (unsigned i = 1; i < g.size(); ++i) {
		if (g[i].edges.size() < g[node].edges.size()) {
			node = i;
		}
	}

	do {
		g[node].visited = true;
		path.push_back(node);
		node = CanMove(g, node);
	} while (node != -1);

	if ((node = CanMove(g, path[0])) != -1) {
		reverse(path.begin(), path.end());
		do {
			g[node].visited = true;
			path.push_back(node);
			node = CanMove(g, node);
		} while (node != -1);
	}
	return path;
}

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

	Graph graph(n);
	while (m--) {
		int x, y;
		cin >> x >> y;
		graph[x - 1].edges.push_back(y - 1);
		graph[y - 1].edges.push_back(x - 1);
	}

	auto path = FindPath(graph);
	cout << path.size() << "\n";

	for (int node : path) {
		cout << node + 1 << " ";
	}
	cout << "\n";

	return 0;
}

Measured memory_bytes: 7544
import math
n = int(input())
data = input().split(' ')
x_list = list(map(lambda x: int(x), data))
opt_p_center = sum(x_list) / n  # least squares
opt_p_left = math.floor(opt_p_center)
opt_p_right = math.ceil(opt_p_center)
opt_p = opt_p_left if opt_p_center < (opt_p_left + opt_p_right) / 2 else opt_p_right
ans = sum(list(map(lambda x: (x - opt_p)**2, x_list)))
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
map<char,int>mp;
map<char,int>::iterator it;
int main()
{
    string s;
    cin>>s;
    int d;
    for(int i=0;i<s.length();i++)
    {
        mp[s[i]]++;
    }
    for(it=mp.begin();it!=mp.end();++it)
    {
      d=it->second;
      if(d>1){cout<<"no"<<endl; return 0;}
    }
    cout<<"yes"<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
#include <map>
#include <cmath>
#include <string>
#include <queue>
#include <stack>

using namespace std;

typedef long long ll;

const int maxn = 1e5+10;

typedef struct APARTMENT
{
    ll x,p,t;
}Apartment;

Apartment apartment[maxn];

bool cmp(const Apartment &a,const Apartment &b)
{
    if(a.x<b.x)
    {
        return true;
    }
    else
    {
        return false;
    }
}

void car(int st,int en,int s)
{
    if(apartment[st].x>s)
    {
        for(int i=st;i<=en;i++)
        {
            apartment[i].t = apartment[i].x - s;
        }
    }
    else if(apartment[en].x<s)
    {
        for(int i=st;i<=en;i++)
        {
            apartment[i].t = s - apartment[i].x;
        }
    }
    else
    {
        if(apartment[st].p>=apartment[en].p)
        {
            apartment[st].p += apartment[en].p;
            car(st,en-1,s);
            apartment[en].t = apartment[st].t + apartment[en].x - apartment[st].x;
        }
        else
        {
            apartment[en].p += apartment[st].p;
            car(st+1,en,s);
            apartment[st].t = apartment[en].t + apartment[en].x - apartment[st].x;
        }
    }
    return ;
}

int main()
{
    ll n,s;
    ios::sync_with_stdio(false);
    cin >> n >> s;
    for(int i=0;i<n;i++)
    {
        cin >> apartment[i].x >>apartment[i].p ;
    }
    sort(apartment,apartment+n,cmp);
    car(0,n-1,s);
    ll sum = 0;
    for(int i=0;i<n;i++)
    {
        if(apartment[i].t>sum)
        {
            sum = apartment[i].t;
        }
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 6528