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

using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<string> vs;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;
struct Edge {
	ll to;
 	ll cost;
 };
using Graph = vector<vector<Edge>>;

const int MAX = 10000000;
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 3.1415926535897932;
const ll INF = LLONG_MAX;
string abc = "abcdefghijklmnopqrstuvwxyz";
string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
/****** define constant end ********/

/****** define variable start ******/
ll n;
vl a;
/******* define variable end *******/
ll gcd(ll a, ll b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}

map<int64_t, ll> ret;
void prime_factor(int64_t n) {
  map<int64_t, ll> ret_tmp;
  for (int64_t i = 2; i * i <= n; i++) {
	while (n % i == 0) {
	  if(ret_tmp[i] == 0) ret[i]++; ret_tmp[i] = 1;
	  n /= i;
	}
  }
  if (n != 1)
	ret[n]++;
  return;
}
int solve() {
	cin >> n;
	a.resize(n);
	ll ma = 0;
	REP(i, n){
		cin >> a[i];
		ma = max(a[i], ma);
		prime_factor(a[i]);
	}
	ll gc = gcd(a[0], a[1]);
	REP(i, n){
		gc = gcd(gc, a[i]);
	}
	bool hoge = true;
	FOR(i, 1, ma+1){
		if(ret[i] > 1){
			hoge = false;
			break;
		}
	}
	if(hoge){
		cout <<"pairwise coprime" << endl;
	}else if(gc == 1){
		cout << "setwise coprime" << endl;
	}else{
		cout << "not coprime" << endl;
	}

	return 0;
}

int main() {
	// clock_t start = clock();
	cout << std::fixed << std::setprecision(10);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int end_solve = solve();
	/*
	clock_t end = clock();
	const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC *
	1000.0; printf("time %lf[ms]\n", time);
	*/

	return end_solve;
}


Measured memory_bytes: 66268
#include<stdio.h>
#include<math.h>

struct Point{double x,y;};

void koch(int n,Point a,Point b)
{
if(n==0)return;

Point A, B, C;
double th = M_PI * 60.0 / 180.0;
A.x = (2.0 * a.x + 1.0 * b.x) / 3.0;
 A.y = (2.0 * a.y + 1.0 * b.y) / 3.0;
 B.x = (1.0 * a.x + 2.0 * b.x) / 3.0;
B.y = (1.0 * a.y + 2.0 * b.y) / 3.0;
 C.x = (B.x - A.x) * cos(th) - (B.y - A.y) * sin(th) + A.x;
C.y = (B.x - A.x) * sin(th) + (B.y - A.y) * cos(th) + A.y;

koch(n - 1, a, A);
 printf("%.8f %.8f\n", A.x, A.y);
 koch(n - 1, A, C);
 printf("%.8f %.8f\n", C.x, C.y);
 koch(n - 1, C, B);
 printf("%.8f %.8f\n", B.x, B.y);
koch(n - 1, B, b);
}

int main() {
Point a, b;
 int n;

scanf("%d", &n);

a.x = 0;
 a.y = 0;
b.x = 100;
b.y = 0;

printf("%.8f %.8f\n", a.x, a.y);
koch(n, a, b);
printf("%.8f %.8f\n", b.x, b.y);

return 0;
}



Measured memory_bytes: 2660
#include <cstdio>
#include <algorithm>
int main() {
	long long n, a, b, c, d, e, MinMove;
	scanf("%lld %lld %lld %lld %lld %lld", &n, &a, &b, &c, &d, &e);
	MinMove = std::min({ a,b,c,d,e });
	printf("%lld\n", (n + MinMove - 1) / MinMove + 4 );
	return 0;
}

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

using namespace std;
typedef vector<int> V;
const int p[6][3]=
{
    {0,1,2},
    {0,2,1},
    {1,0,2},
    {1,2,0},
    {2,0,1},
    {2,1,0}
};
const int MAX_LEN=43200*2;

inline int calc(int h,int m,int s){
    return (((h%60)/5)*60+m%60)*60+s%60;
}

inline bool check(vector<int>& cnt){
    bool f=true;
    for(auto& it : cnt)f&=(it>0);
    return f;
}
int main() {
    while(true){
        int n;cin>>n;if(n==0)return 0;
        vector<V> stu(n,V(3));
        vector<V> seg(MAX_LEN,V(n,0));
        for(int i = 0; i < n; i++)
            for(auto& it : stu[i])cin>>it;
        for(int i = 0; i < n; i++){
            for(int j = 0; j < 6; j++){
                int h=stu[i][p[j][0]],m=stu[i][p[j][1]],s=stu[i][p[j][2]];
                for(int t = 0; t < 60; t++){
                    if((h+t)%5==((m+t)%60)/12){
                        seg[calc(h+t,m+t,s+t)][i]=1;
                        seg[MAX_LEN/2+calc(h+t,m+t,s+t)][i]=1;
                    }
                }
            }
        }
        //for(int i = 0; i < n; i++){
        //    for(int t=0;t<MAX_LEN;t++)
        //    if(seg[t][i]>0)
        //    printf("%02d:%02d:%02d ,",t/3600,(t%3600)/60,t%60);
        //    cout<<endl;
        //}

        int st=-1,ed=-1,res=MAX_LEN+1,b,g;
        V cnt(n,0);
        while(true){
            if(check(cnt)){
                if(ed-st<res){
                    res=ed-st;
                    b=st+1;
                    g=ed;
                }
                st++;
                for(int i = 0; i < n; i++)cnt[i]-=seg[st][i];
            }
            else{
                ed++;
                if(ed>=MAX_LEN)break;
                for(int i = 0; i < n; i++)cnt[i]+=seg[ed][i];
            }
        }
        //cout<<b<<" "<<g<<endl;
        printf("%02d:%02d:%02d %02d:%02d:%02d\n",(b/3600)%12,(b%3600)/60,b%60,(g/3600)%12,(g%3600)/60,g%60);
    }

    return 0;
}

Measured memory_bytes: 7048
fn read_stdin() -> String {
    use std::io::Read;
    let mut input = String::new();
    std::io::stdin().read_to_string(&mut input).unwrap();
    input
}

fn scan<'a, I: Iterator<Item = &'a str>, T: std::str::FromStr>(tokens: &mut I) -> T {
    tokens.next().unwrap().parse().ok().unwrap()
}

fn vec<T, F: FnMut(usize) -> T>(n: usize, mut f: F) -> Vec<T> {
    (0..n).map(|i| f(i)).collect()
}

fn main() {
    let input = read_stdin();
    let tokens = &mut input.split_whitespace();
    let n: usize = scan(tokens);
    let a: Vec<i64> = vec(n, |_| scan(tokens));
    let mut c: Vec<i64> = vec![0; n + 2];
    for i in 0..n {
        c[i + 2] = c[i] + a[i];
    }
    if n % 2 == 0 {
        // find i which maximize (c[2 * i] - c[0]) + (c[n + 1] - c[2 * i + 1])
        let mut ans = c[n + 1] - c[1];
        for i in 1..=n / 2 {
            ans = std::cmp::max(ans, (c[2 * i] - c[0]) + (c[n + 1] - c[2 * i + 1]));
        }
        println!("{}", ans);
    } else {
        // find i, j which maximize (c[2 * i] - c[0]) + (c[2 * j + 1] - c[2 * i + 1]) + (c[n + 1] - c[2 * j + 2])
        let mut ans = c[n + 1] - c[2];
        let mut d = 0;
        for j in 1..=n / 2 {
            d = std::cmp::max(d + a[2 * j - 1], c[2 * j] - c[0]);
            ans = std::cmp::max(ans, d + c[n + 1] - c[2 * j + 2]);
        }
        println!("{}", ans);
    }
}


Measured memory_bytes: 7332
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i=0;i < (int)(n);i++)
const ll mod = 1e9+7;
int main(){
    ll n,m;
    string s;
    cin >> n >> m;
    ll ans=0LL;
    if (m >= 2*n) {
        ans+=n;
        m-=2*n;
        if (m >= 4 ) ans+=m/4;
    }
    else{
        ans+=m/2;
    }
    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 rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 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; }
//---------------------------------------------------------------------------------------------------
void _main() {
	int K, X;
	cin >> K >> X;

	rep(i, (X - K + 1), (X + K - 1) + 1) {
		cout << i << endl;
	}
}

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

using namespace std;

typedef pair<int,int> P;
typedef long long ll;
const int MAX = 2;
const ll INF = (1LL<<60);

int N,M;
vector<ll> V[MAX];
ll ans;
void init(){
  for(int i = 0; i < MAX; i++)
    V[i].clear();
  ans = 0;
}


void solve(){
  
  sort(V[0].begin(),V[0].end());

  for(int i = 0; i < V[0].size(); i++)
    for(int j = 0; j < V[0].size(); j++)
      if(V[0][i]+V[0][j] <= M) V[1].push_back(V[0][i]+V[0][j]);

  V[1].push_back(INF);
  sort(V[1].begin(),V[1].end());

   vector<ll> :: iterator ite1;

   /*
  for(int i = 0; i < V[0].size(); i++)
    for(ite1 = V[1].end(); ite1 != V[1].end(); ite1 = upper_bound(V[1].begin(),V[1].end(),*ite1))
      if(*ite1 + V[0][i] <= M) ans = max(ans,*ite1+V[0][i]);
      else break;

  for(ite1 = V[1].begin(); ite1 != V[1].end(); ite1 = upper_bound(V[1].begin(),V[1].end(),*ite1))
    for(ite2 = V[1].begin(); ite2 != V[1].end(); ite2 = upper_bound(V[1].begin(),V[1].end(),*ite2))
      if(*ite1 + *ite2 <= M) ans = max(ans,*ite1+*ite2);
      else break;
   */
   
   for(int i = 0; i < V[0].size(); i++){
     vector<ll> :: iterator ite = lower_bound(V[1].begin(),V[1].end(),M-V[0][i]);
    
     while(1){
       if(V[0][i]+*ite <= M){
	 ans = max(ans,V[0][i]+*ite);
	 break;
       }else if(ite == V[1].begin()) break;
       else ite--;
     }
   }

   for(ite1 = V[1].begin(); ite1 != V[1].end(); ite1 = upper_bound(V[1].begin(),V[1].end(),*ite1)){
     vector<ll> :: iterator ite = lower_bound(V[1].begin(),V[1].end(),M-*ite1);
     while(1){
       if(*ite1+*ite <= M) {
	 ans = max(ans,*ite1+*ite);
	 break;
       }else if(ite == V[1].begin()) break;
       else ite--;
     }
     
   }
   
   for(int i = 0; i < MAX; i++){
     vector<ll> :: iterator ite;
     ite = upper_bound(V[i].begin(),V[i].end(),M);
     /*while(1){
       if(*ite <= M) {
	 ans = max(ans,*ite);
	 break;
       }else if(ite == V[i].begin()) break;
       else ite--;
       }*/
     ans = max(ans,*(ite-1));
   }
   cout << ans << endl;
}

int main(){
  while(cin >> N >> M && N+M){
    init();
    for(int i = 0; i < N; i++){
      ll in;
      cin >> in;
      V[0].push_back(in);
    }
    solve();
  }
  return 0;
}

Measured memory_bytes: 10984
#include<stdio.h>

int main()
{
	int n,k,x,y;
	int tmp1;   // X円で泊まる日数
	int tmp2;   // Y円で泊まる日数
	int total;  // 合計金額
	
	scanf("%d",&n);
	scanf("%d",&k);
	scanf("%d",&x);
	scanf("%d",&y);
	
	
	/* Y円で泊まるかどうかと日数 */
	if(n > k){ 
		tmp1 = k;
		tmp2 = n-k;
	}else{
		tmp1 = n;
		tmp2 = 0;
	}
	
	total = ((tmp1 * x) + (tmp2 * y));
	
	printf("%d\n",total);
	
	return 0;
}

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

int main() {
    int N; cin >> N;
    string S; cin >> S;
    int ans = 1;
    rep(i, N - 1) ans += S[i] != S[i + 1];
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 512
//C
#include <cassert>
//#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

//ここまで標準include

using namespace std;

long aCb(long a, long b) {
	long out = 1;
	for (long i = 1; i <= b; i++) {
		out = out * (a + 1 - i) / i;
	}
	return out;
}

int main() {
	int x, a;
	cin >> x >> a;
	if (x < a) {
		cout << 0;
	}
	else {
		cout << 10;
	}
	cout << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).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 (b<a) { a=b; return 1; } return 0; }

typedef long long ll;

using namespace std;


int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  string a,b;
  cin>>a>>b;
  int res=0;
  rep(i,3)
  {
    res+=(a[i]==b[i]);
  }
  cout<<res<<endl;
  return 0;

}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n;
int a[100010],tot,f[100010];
int main()
{
    cin>>n;
    int now=6;
    while(now<=n)
    {
        a[++tot]=now;
        now*=6;
    }
    now=9;
    while(now<=n)
    {
        a[++tot]=now;
        now*=9;
    }
    a[++tot]=1;
    memset(f,127,sizeof(f));
    f[0]=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=tot;j++)
        {
            if(a[j]<=i)   f[i]=min(f[i],f[i-a[j]]+1);
        }
    }
    cout<<f[n]<<endl;
    return 0;
}

Measured memory_bytes: 640
def main():
    N = int(input())
    S = input()
    ans = 0
    for i in range(N - 2):
        if S[i] == "A" and S[i + 1] == "B" and S[i + 2] == "C":
            ans += 1
    print(ans)



if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;


int main() {
    ios::sync_with_stdio(false);
    int a, b;
    cin >> a >> b;
    if (b % a) cout << b - a;
    else cout << b + a;
}


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

int main()
{
	int n; cin>>n;
	int t = 0;
	while(n > 0) {
		int x = n;
		int c = 0;
		while(x > 0) {
			c++;
			x /= 10;
		}
		if(c%2 == 1) t++;
		n--;
	}
	cout<<t<<endl;
}

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

using namespace std;

const int N = 3005;
const int mod = 1000000007;

int dp[N][N];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    string s;
    cin >> s;

    fill(dp[0], dp[0] + n, 1);
    for(int i = 1; i < n; i++){
        int sum = 0;
        if(s[i - 1] == '>'){
            for(int j = n - i - 1; j >= 0; j--){
                sum = (sum + dp[i - 1][j + 1]) % mod;
                dp[i][j] = sum;
            }
        }
        else{
            for(int j = 0; j < n - i; j++){
                sum = (sum + dp[i - 1][j]) % mod;
                dp[i][j] = sum;
            }
        }
    }

    int ans = 0;
    for(int i = 0; i < n; i++)
        ans = (ans + dp[n - 1][i]) % mod;
    cout << ans << endl;
}

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

template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}


// std::vector Declaration
template<typename T>
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...));
}

// std::vector Initialization
template<typename T>
void fill_all(T& arr, const T& v) { arr = v; }
template<typename T, typename U>
void fill_all(T& arr, const U& v) { for (auto& i : arr) fill_all(i, v); }

// std::vector Debug
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
   os << "[";
   bool a = 1;
   for (auto e : v ) {
      os << (a ? "" : " "); 
      os << e;
      a = 0;
   }
   os << "]";
   return os;
}

// std::pair Debug
template<typename T, typename U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
   os << "(" << p.first << " " << p.second << ")";
   return os;
}

// std::set Debug
template<typename T>
ostream& operator<<(ostream& os, const set<T>& st) {
   os << "{";
   bool a = 1;
   for (auto e : st) {
      os << (a ? "" : " ");
      os << e;
      a = 0;
   }
   os << "}";
   return os;
}

// std::map Debug
template<typename T, typename U>
ostream& operator<<(ostream& os, const map<T, U>& mp) {
   os << "{";
   bool a = 1;
   for (auto e : mp) {
      os << (a ? "" : " ");
      os << e.first << ":" << e.second;
      a = 0;
   }
   os << "}";
   return os;
}

// std::tuple Debug
template<int N,class Tuple>
void out(ostream &os,const Tuple &t){}
template<int N,class Tuple,class H,class ...Ts>
void out(ostream &os,const Tuple &t){
   if(N)os<<" ";
   os<<get<N>(t);
   out<N+1,Tuple,Ts...>(os,t);
}
template<class ...Ts>
ostream& operator<<(ostream &os, const tuple<Ts...> &t){
   os<<"(";
   out<0,tuple<Ts...>,Ts...>(os,t);
   os<<")";
   return os;
}

// Debug
#define DUMP(x) cout<<#x<<" = "<<(x)<<endl

struct edge { int to, cost; };

const LL LINF = 1LL<<60;
const int IINF = 1<<30;
const LL MOD = 1e9+7;

int main()
{
   int a, p; cin >> a >> p;

   cout << (3*a + p) / 2 << endl;

   return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
PY = []
for num in range(M):
    PY.append(list(map(int, input().split())) + [num])

PY.sort(key=lambda x:x[1])
#print(PY)

prefecture=[[] for _ in range(N)]
for el in PY:
    p, y, num = el
    prefecture[p-1].append((y, num))
#print(prefecture)

ans=[None]*M
for j, p in enumerate(prefecture):
    for i, city in enumerate(p):
        ans[city[1]] = str(j+1).zfill(6) + str(i+1).zfill(6)
#print(ans)
for val in ans:
    print(val)

Measured memory_bytes: 95064
import java.util.Scanner;

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

		long k = sc.nextLong(), a = sc.nextLong(), b = sc.nextLong();

		// 交換しない場合
		if (k <= a || b - a < 3) {
			System.out.println(k + 1);
			sc.close();
			return;
		}

		// 交換する場合
		long ans = a + (1 + (k - (a + 1)) / 2) * (b - a);
		if ((k - (a + 1)) % 2 == 1) {
			ans++;
		}
		System.out.println(ans);
		sc.close();
	}

}

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

struct node
{
  struct node *ramu;
  struct node *lemu;
  struct node *beti;
  int key;
};
typedef struct node *Node;

Node root;

void insert(int k)
{
  Node y = NULL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->lemu = NULL;
  z->ramu = NULL;

  while (x != NULL)
  {
    y = x;
    if (z->key < x->key) x = x->lemu;
    else x = x->ramu;
  }
  z->beti = y;

  if (y == NULL) root = z;
  else if (z->key < y->key) y->lemu = z;
  else y->ramu = z;
}

void inorder(Node u)
{

  if (u == NULL)
    return;
  inorder(u->lemu);
  printf(" %d", u->key);
  inorder(u->ramu);
}
void preorder(Node u)
{

  if (u == NULL)
    return;
  printf(" %d", u->key);
  preorder(u->lemu);
  preorder(u->ramu);
}
Node find(int key)
{
  Node X = root;

  while (1)
  {
    if (X == NULL) return NULL;
    if (X->key == key) return X;
    if (X->key < key)  X = X->ramu;
    else X = X->lemu;
  }
  }


Node treeSuccessor(Node A)
{
  Node X;
  Node B;
  A = A->ramu;
  while (A->lemu != NULL)A = A->lemu;
  
  return A;
}

void treeDelete (Node X)
{
  Node B;
  Node child;

  if (X->ramu == NULL && X->lemu == NULL)
  {
    if (X->beti->ramu == X)X->beti->ramu = NULL;
    else X->beti->lemu = NULL;
    free(X);
  }

  else if (X->ramu != NULL && X->lemu != NULL)
  {
    B = treeSuccessor(X);
    X->key = B->key;
    treeDelete(B);
  }

  else
  {
    if (X->ramu==NULL)child=X->lemu;
    else child=X->ramu;

    if (X->beti==NULL)
    {
      child->beti=NULL;
      return;
    }
    if (X->beti->key < X->key) X->beti->ramu=child;
    else X->beti->lemu=child;
    child->beti=X->beti;
    free(X);
  }
}

int main()
{
  int n, i, x,count = 0;;
  char a[10];
  scanf("%d", &n);
  
  for (i = 0; i < n; i++)
  {
    scanf("%s", a);
    if (a[0] == 'i')
    {
      scanf("%d", &x);
      insert(x);
    }
    else if (a[0] == 'f')
    {
      scanf("%d", &x);
      
      if (count) printf("\n");
      if (find(x) != NULL)printf("yes\n");
      else printf("no\n");
    }
    else if (a[0] == 'd')
    {
      scanf("%d", &x);
      treeDelete (find(x));
    }
    else if (a[0] == 'p')
    {
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
  return 0;
}





Measured memory_bytes: 20468
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

int n, l, q;
int x[100005];
int a[25][100005];

int main()
{    scanf("%d", &n);
    for(int i = 1; i <= n; i++)
    {
        scanf("%d", &x[i]);
    }
    scanf("%d", &l);
    for(int i = 1; i < n; i++)
    {
        a[0][i] = upper_bound(x + 1, x + n + 1, x[i] + l) - x - 1;
    }
    for(int i = 1; i < 20; i++)
    {
        for(int j = 1; j <= n; j++)
        {
            a[i][j] = a[i - 1][a[i - 1][j]];
        }
    }
//    for(int i = 0; i < 20; i++)
//    {
//        for(int j = 1; j <= n; j++)
//        {
//            printf("%d ", a[i][j]);
//        }
//        puts("");
//    }
    scanf("%d", &q);
    while(q--)
    {
        int cnt = 0;
        int s, e;
        scanf("%d%d", &s, &e);
        if(s > e) swap(s, e);
        for(int i = 19; i >= 0; i--)
        {
            if(a[i][s] != 0 && a[i][s] <= e) s = a[i][s], cnt += (1 << i);
        }
        if(s < e) s = a[0][s], cnt++;
        printf("%d\n", cnt);
    }
    return 0;
}


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

int main() {
  int N;
  string S;
  cin >> N >> S;
  int c = 0;
  for(int i = 0; i < N - 2; i++) {
    if(S.at(i) == 'A' && S.at(i + 1) == 'B' && S.at(i + 2) == 'C') c++;
  }
  cout << c << endl;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var k, a, b int
	fmt.Scan(&k, &a, &b)

	for i := a; i <= b; i++ {
		if i%k == 0 {
			fmt.Println("OK")
			return
		}
	}
	fmt.Println("NG")
}


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

int main() {
  int N, K;
  cin >> N >> K;
  string S;
  cin >> S;

  char c;
  if (S[K-1] == 'A') c = 'a';
  else if (S[K-1] == 'B') c = 'b';
  else if (S[K-1] == 'C') c = 'c';
  S[K-1] = c;
  cout << S << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <cctype>
#include <limits.h>
#include <math.h>
#include <complex>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <iostream>

#define VARIABLE(x) cerr << #x << "=" << x << endl
#define BINARY(x) static_cast<bitset<16> >(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for (int i=m;i<(int)(n);i++)
#define if_range(x, y, w, h) if (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))

const int INF = 1e9;
const double EPS = 1e-8;
const double PI = 3.14159;
int dx[4]={0, 1, 0, -1}, dy[4]={-1, 0, 1, 0};
using namespace std;
typedef long long ll;
typedef pair<double, int> P;

int main()
{
    int N; cin>>N;
    if (N == 0 || N == 2) cout << 1 << endl;
    else if (N == 1) cout << 2 << endl;
    else cout << 0 << endl;
}

Measured memory_bytes: 1164
// AOJ 2515: Seishun 18 Kippu 2013
// 2017.10.5 bal4u@uu

#include <stdio.h>
#include <stdlib.h>

typedef struct { char nm[52]; int t[2]; } T;
T stn[11];

int main()
{
	int n, t, i, j, hh, mm, ans;
	char date[52];

	scanf("%d%d", &n, &t); n--;
	scanf("%s%s", date, date);
	for (i = 0; i < n; i++) for (j = 0; j < 2; j++) {
		scanf("%s%s", date, stn[i].nm);
		hh = atoi(date), mm = atoi(date+3);
		stn[i].t[j] = hh*60 + mm;
	}
	for (ans = 0, i = 0; i < n; i++)
		if (stn[i].t[1] - stn[i].t[0] >= t) ans++;

	printf("%d\n", ans);
	if (ans > 0) {
		for (i = 0; i < n; i++)
			if (stn[i].t[1] - stn[i].t[0] >= t)
				printf("%s %d\n", stn[i].nm, stn[i].t[1]-stn[i].t[0]);
	}
	return 0;
}

Measured memory_bytes: 1812
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <set>

typedef long long ll;
typedef std::pair<int, std::pair<int,int>> PP;
int X, Y, Z, K;
std::vector<ll> A, B, C;

struct Pair{
  ll sum;
  PP p;
};

bool operator< (const Pair &p, const Pair &q) { return p.sum < q.sum; }

void sol_3 () {
  std::set<PP> memo;
  std::priority_queue<Pair> Q;
  Q.push( {A[0]+B[0]+C[0], {0, {0, 0}}} );

  for(int i=0; i<K; i++){
    Pair cur = Q.top(); Q.pop();
    std::cout << cur.sum << std::endl;
    int x = cur.p.first;
    int y = cur.p.second.first;
    int z = cur.p.second.second;

    if ( x+1 < X ) {
      PP p_ = { x+1, {y, z} };
      if ( memo.count(p_) == 0 ) {
        Q.push( {A[x+1]+B[y]+C[z], p_  } );
        memo.insert(p_);
      }
    }
    if ( y+1 < Y ) {
      PP p_ = { x, {y+1, z} };
      if ( memo.count(p_) == 0 ) {
        Q.push( {A[x]+B[y+1]+C[z], p_  } );
        memo.insert(p_);
      }
    }
    if ( z+1 < Z ) {
      PP p_ = { x, {y, z+1} };
      if ( memo.count(p_) == 0 ) {
        Q.push( {A[x]+B[y]+C[z+1], p_  } );
        memo.insert(p_);
      }
    }
  }
}


int main (void){
  std::cin >> X >> Y >> Z >> K;
  for(int i=0; i<X; i++) {
    ll t_; std::cin >> t_;
    A.push_back(t_);
  }
  for(int i=0; i<Y; i++) {
    ll t_; std::cin >> t_;
    B.push_back(t_);
  }
  for(int i=0; i<Z; i++) {
    ll t_; std::cin >> t_;
    C.push_back(t_);
  }


  std::sort(A.begin(), A.end(), std::greater<ll>() );
  std::sort(B.begin(), B.end(), std::greater<ll>() );
  std::sort(C.begin(), C.end(), std::greater<ll>() );

  sol_3();

  return 0;
}

Measured memory_bytes: 896
n = int(input())
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort(key=lambda x: x[1])
t = 0

for i in range(n):
    t += ab[i][0]
    if t > ab[i][1]:
        print('No')
        exit(0)

print('Yes')

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

#define pp push_back
#define pf push_front
#define mp make_pair
#define fs first
#define sc second
#define sf scanf

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;

const int N = (int) 2e3;
const int INF = (int) 1e9 + 7;

pair<ll, int> p[N + 7];
ll dp[N + 7][N + 7];
int n;

ll f(int i, int l, int r) {
	if (i == 0) return 0;
	if (dp[l][r] != -1) return dp[l][r];

	ll x = f(i - 1, l + 1, r) + p[i].fs * abs(l - p[i].sc);
	ll y = f(i - 1, l, r - 1) + p[i].fs * abs(r - p[i].sc);

	return dp[l][r] = max(x, y);
}

int main(int argc, char *argv[])
{
	// ios_base::sync_with_stdio(false);
	// cin.tie(NULL);

	cin >> n;
	for (int i = 1; i <= n; ++i) {
		cin >> p[i].fs;
		p[i].sc = i;
	}

	sort(p + 1, p + n + 1);

	memset(dp, -1, sizeof(dp));
	cout << f(n, 1, n);

	return 0;
}


Measured memory_bytes: 35232
#include <stdio.h>
#include <math.h>

int main(){

  int N = 0, M = 0;
  scanf("%d %d",&N, &M);

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

  int sum = 0;
  for( i = 0; i < M; i++ ){
    sum = sum + A[i];
  }

  int res = 0;
  res = N - sum;

  if( res >= 0 ){
    printf("%d",res);
  }
  else{
    printf("-1");
  }

  return 0;
}

Measured memory_bytes: 1768
import sys
from collections import defaultdict
import bisect
import itertools
readline = sys.stdin.buffer.readline
# sys.setrecursionlimit(10**5)


def geta(fn=lambda s: s.decode()):
    return map(fn, readline().split())


def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip())


def main():
    N, M = geta(int)
    A = list(geta(int))
    A.sort()

    def c(x):
        """
        @return  # of handshake where hapiness >= x
        """
        ret = 0
        for a in A:
            ret += bisect.bisect_left(A, x - a)
        return N * N - ret

    left, right = 0, 2 * A[-1] + 1

    while left + 1 < right:
        middle = (left + right) // 2
        if c(middle) >= M:
            left = middle
        else:
            right = middle

    ans = 0
    Acum = list(itertools.accumulate(A[::-1]))[::-1]
    for a in A:
        idx = bisect.bisect_left(A, right - a)
        if idx < N:
            ans += Acum[idx] + a * (N - idx)
    ans += left * (M - c(right))

    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 12800
var lines = [];
var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});

rl.on('line', function (x) {
    lines.push(x);
});

rl.on('close', function () {
    var S = lines[0].split("").map(i => Number(i));
    var a = S[0] * 10 + S[1]
    var b = S[2] * 10 + S[3]

    if (a <= 12 && a !== 0) {
        if (b <= 12 && b !== 0) {
            console.log("AMBIGUOUS"); return (0)
        }
        console.log("MMYY"); return (0);
    }

    if (a > 12 || a === 0) {
        if (b <= 12 && b !== 0) {
            console.log("YYMM"); return (0);
        }
        console.log("NA"); return (0);
    }
    console.log("NA")
});


Measured memory_bytes: 21192
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <bitset>
#include <cmath>
#include <string>
#define FI first
#define SE second
#define PF push_front
#define PB push_back
#define PPF pop_front
#define PPB pop_back
#define MA make_pair
#define ll long long
#define PA pair<int,int>
#define VE vector<int>
#define VP vector<PA>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
using namespace std;
//
const int INF=1e9+7;
const int mod=1e9+7;
//
//
struct poi{
  int X;int Y;int Z;
  bool operator<(const poi&R)const{
    return X==R.X ? Y==R.Y ? Z<R.Z : Y<R.Y : X<R.X;
  }
};
//
//
int main(){
	int N,A,B;
	string S;
	cin>>N>>A>>B;
	cin>>S;
	int kokunai=0,kaigai=0;
	FOR(i,0,N){
		if(S[i]=='a'){
			if(kokunai+kaigai<A+B){
				kokunai++;
				Yes(1);
			}else{
				Yes(0);
			}
		}else if(S[i]=='b'){
			if(kokunai+kaigai<A+B&&kaigai<B){
				kaigai++;
				Yes(1);
			}else{
				Yes(0);
			}
		}else if(S[i]=='c'){
			Yes(0);
		}
	}
	return 0;
}


Measured memory_bytes: 896
#include<iostream>
#include<string>
using namespace std;
int main (){
    int x=0;
    string a;
    cin>>a;
    for(int i=0;i<4;i++){
        if(a[i]=='+'){
            x=x+1;
        }else{
            x=x-1;
        }
    }
    cout<<x<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
 
typedef struct _card {
    int number;
    char suit;
} CARD;
 
CARD A[100000], I[100000];
char inputs[1000000];
char *ptr = inputs;
 
void exchange(CARD *a, CARD *b);
int Partition(CARD A[], int p, int r);
void Quicksort(CARD A[], int p, int r);
 
int nextInt(void) {
    int v = 0;
    while (*ptr < '0' || *ptr > '9') ++ptr;
    while (*ptr >= '0' && *ptr <= '9') {
        v = v * 10 + (int)(*ptr - '0');
        ++ptr;
    }
    return v;
}
 
char nextSuit(void) {
    while (*ptr < 'A' || *ptr > 'Z') ++ptr;
    return *ptr;
}
 
int main(void) {
    int n;
    int stable = 1;
    int i, j, c, d;
     
    fread(inputs, sizeof(char), 1000000, stdin);
     
    n = nextInt();
     
    for (i = 0; i < n; ++i) {
        A[i].suit = nextSuit();
        A[i].number = nextInt();
        I[i] = A[i];
    }
     
    Quicksort(A, 0, n - 1);
     
    for (i = 0; i < n; ++i) {
        if (i == 0) {
            c = 0;
        } else if (A[i].number != A[i - 1].number) {
            c = 0;
        } else {
            ++c;
        }
        d = 0;
        for (j = 0; j < n; ++j) {
            if (I[j].number == A[i].number) {
                if (c == d) {
                    if (I[j].suit != A[i].suit) {
                        stable = 0;
                    }
                    break;
                }
                ++d;
            }
        }
        if (stable == 0) {
            break;
        }
    }
     
    if (stable == 1) {
        puts("Stable");
    } else {
        puts("Not stable");
    }
     
    for (i = 0; i < n; ++i) {
        printf("%c %d\n", A[i].suit, A[i].number);
    }
     
    return 0;
}
 
void exchange(CARD *a, CARD *b) {
    CARD t = *a;
    *a = *b;
    *b = t;
}
 
int Partition(CARD A[], int p, int r) {
    CARD x = A[r];
    int i = p - 1;
    int j;
    for (j = p; j < r; ++j) {
        if (A[j].number <= x.number) {
            ++i;
            exchange(&A[i], &A[j]);
        }
    }
    exchange(&A[i + 1], &A[r]);
    return i + 1;
}
 
void Quicksort(CARD A[], int p, int r) {
    int q;
    if (p < r) {
        q = Partition(A, p, r);
        Quicksort(A, p, q - 1);
        Quicksort(A, q + 1, r);
    }
}

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

int main()
{
	int a,b,c;
	cin>>a>>b>>c;
	if((a==b&&b!=c) || (a==c&&a!=b) || (b==c&&a!=b)) puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 256
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
#include<tuple>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;

const ll MX=100000;

vector<ll> cnt(MX);
ll n=0;
ll b;
vector<vector<ll>> edge(MX);
vector<pll> node(MX); //amari,takasa
vector<ll> ans(MX);

void init(){for(int i=0;i<n;i++){edge[i].clear(); cnt[i]=0;}}

void dfs(ll w){
    ll mx=0;
    ll ch=1;
    for(auto &I:edge[w]){
        dfs(I);
        mx=max(mx,node[I].S);
    }
    for(auto &I:edge[w]){
        if(node[I].S==mx){ch+=node[I].F;}
    }
    if(ch>b){mx++; ch=1;}
    else if(ch==b){mx++; ch=0;}
    node[w]={ch,mx};
}

void dfs2(ll w,pll p){
    //cout<<w<<" "<<p.F<<" "<<p.S<<endl;
    pll mx1={p.S,-1},mx2={p.S,-1};
    for(auto &I:edge[w]){
        if(node[I].S>mx2.F){mx2={node[I].S,I};}
        if(mx2>mx1){swap(mx2,mx1);}
    }
    ll cnt1=1,cnt2=1;
    for(auto &I:edge[w]){
        if(node[I].S==mx1.F){cnt1+=node[I].F;}
        if(node[I].S==mx2.F){cnt2+=node[I].F;}
    }
    if(p.S==mx1.F){cnt1+=p.F;}
    if(p.S==mx2.F){cnt2+=p.F;}
    ans[w]=mx1.F+1;
    if(cnt1>b){ans[w]++;}
    
    for(auto &I:edge[w]){
        if(I==mx1.S){
            ll cnt=cnt2;
            ll high=mx2.F;
            if(node[I].S==mx2.F){cnt-=node[I].F;}
            if(cnt>b){high++; cnt=1;}
            else if(cnt==b){high++; cnt=0;}
            dfs2(I,{cnt,high});
        }
        else{
            ll cnt=cnt1;
            ll high=mx1.F;
            if(node[I].S==mx1.F){cnt-=node[I].F;}
            if(cnt>b){high++; cnt=1;}
            else if(cnt==b){high++; cnt=0;}
            dfs2(I,{cnt,high});
        }
    }
}


int main(){
    for(int C=1;;C++){
    init();
    cin>>n>>b;
        if(n==0){break;}
        cout<<"Case "<<C<<":"<<endl;
    for(int i=1;i<n;i++){
        ll p;
        cin>>p;
        p--;
        edge[p].push_back(i);
    }
    dfs(0);
    dfs2(0,{0,0});
    for(int i=0;i<n;i++){cout<<ans[i]<<endl;}
    //for(int i=0;i<n;i++){cout<<node[i].F<<" "<<node[i].S<<endl;}
    }
    
    return 0;
}



Measured memory_bytes: 24412
#include <stdio.h>
#include <math.h>

int isPrime(double);

int main()
{
  int i,j, N, c=0;
  double number[10000];

  scanf("%d",&N);

  for(i = 0 ; i < N ; i++){
    scanf("%lf",&number[i]);
    j = isPrime(number[i]);
    if(j == 1) 
      c++;
  }
  printf("%d\n",c);
  return 0;
}
int isPrime( double x ){
  double i;
  if(x == 2.0) 
    return 1;
  
  if(x < 2.0 || fmod(x, 2.0) == 0)
    return 0;

  i = 3.0; 
  while(i <= sqrt( x )){
    if( fmod(x, i) == 0.0 ) 
      return 0;
    i = i + 2.0;
  }
  return 1;
}  

  

Measured memory_bytes: 712
n = int(input())
S = []
count = [0] * n
for i in range(n):
    a, b = input().split()
    S.append([a, -int(b), i + 1])

S.sort(key=lambda x:(x[0], x[1]))

for i in range(n):
    print(S[i][2])


    

Measured memory_bytes: 3060
#include <cstring>
#include <map>
#include <unordered_map>
#include <string>
#include <list>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdio>
#include <iostream>
#include <set>
#include <tuple>
#include <unordered_set>
using namespace std;

#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int, int> pii;

int gi() {
    int a;
    scanf("%d", &a);
    return a;
}

ll gli() {
    ll a;
#ifndef ONLINE_JUDGE
    scanf("%lld", &a);
#else
    scanf("%I64d", &a);
#endif
    return a;
}

int main() {
    int n = gi();
    int m = gi();

    vector<tuple<int, int, int, int> > res;

    int o = 0;
    for (int i = 0; i < n; i++) {
        int p = 0;
        for (int j = 0; j < m; j++) {
            p = (gi()+p)%2;
            if (p) {
                if (j == m-1)
                    o = 1-o;
                else
                    res.push_back(make_tuple(i, j, i, j+1));
            }
        }
        if (o && i < n-1)
            res.push_back(make_tuple(i, m-1, i+1, m-1));
    }

    int l = res.size();
    printf("%d\n", l);
    for (int i = 0; i < l; i++) {
        tuple<int, int, int, int> &t = res[i];
        printf("%d %d %d %d\n", get<0>(t)+1, get<1>(t)+1, get<2>(t)+1, get<3>(t)+1);
    }

    return 0;
}


Measured memory_bytes: 4208
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <tuple>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main(){
	string n;
	cin >> n;
	for(char c:n){
		if(c == '7'){
			cout << "Yes" << endl;
			return 0;
		}
	}

	cout << "No" << endl;
}


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

class Main {

	public static void main(String[] args) throws Exception {
		final Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] p = new int[N];
		for (int i = 0; i < N; i++) {
			p[i] = sc.nextInt();
		}

		int a = 0;
		if (p[N - 1] == N) {
			a++;
			int t = p[N - 1];
			p[N - 1] = p[N - 2];
			p[N - 2] = t;
		}

		for (int i = 0; i < N - 1; i++) {
			if (p[i] == i + 1) {
				int t = p[i + 1];
				p[i + 1] = p[i];
				p[i] = t;
				a++;
			}
		}

		System.out.println(a);
	}
}


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

constexpr int MaxM = 10000;

int main()
{
	int N, M;
	int A;
	int sum = 0;

	cin >> N >> M;
	for (int i = 0; i < M; ++i)
	{
		cin >> A;
		sum += A;
	}

	int out = N < sum ? -1 : N - sum;
	cout << out << endl;

	return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>
#include <random>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
//#define int long long

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;
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; }

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    int x;
    cin >> x;
    LL ans = 0;
    ans += (1LL * x / 500) * 1000;
    x %= 500;
    ans += (x / 5) * 5;
    cout << ans << endl;
}

signed main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
    class Program
    {
        static void Main(string[] args)
        {
            var inputs = Console.ReadLine().Split(' ').Select(c=>int.Parse(c)).ToArray();
            var N = inputs[0];
            var C = inputs[2];
            var Bs = Console.ReadLine().Split(' ').Select(c => int.Parse(c)).ToList();
            var result = 0;
            for (int i = 0;i<N;i++)
            {
                var As = Console.ReadLine().Split(' ').Select(c => int.Parse(c)).ToList();
                var sum = 0;
                for(int k = 0; k < Bs.Count; k++)
                {
                    sum += Bs[k] * As[k];
                }
                if (sum + C > 0) result++;
            }
            Console.WriteLine(result);
        }
    }

Measured memory_bytes: 13396
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using vec = vector<ll>;
using vect = vector<double>;
using Graph = vector<vector<ll>>;
#define loop(i, n) for (ll i = 0; i < n; i++)
#define Loop(i, m, n) for (ll i = m; i < n; i++)
#define pool(i, n) for (ll i = n; i >= 0; i--)
#define Pool(i, m, n) for (ll i = n; i >= m; i--)
#define mod 1000000007ll
#define flagcount __builtin_popcount
#define flag(x) (1 << x)
#define flagadd(bit, x) bit |= flag(x)
#define flagpop(bit, x) bit &= ~flag(x)
#define flagon(bit, i) bit &flag(i)
#define flagoff(bit, i) !(bit & (1 << i))
#define all(v) v.begin(), v.end()
#define low2way(v, x) lower_bound(all(v), x)
#define high2way(v, x) upper_bound(all(v), x)
#define idx_lower(v, x) (distance(v.begin(), low2way(v, x)))  //配列vでx未満の要素数を返す
#define idx_upper(v, x) (distance(v.begin(), high2way(v, x))) //配列vでx以下の要素数を返す
#define idx_lower2(v, x) (v.size() - idx_lower(v, x))         //配列vでx以上の要素数を返す
#define idx_upper2(v, x) (v.size() - idx_upper(v, x))         //配列vでxより大きい要素の数を返す
#define putout(a) cout << a << endl
#define Gput(a, b) G[a].push_back(b)
#define Sum(v) accumulate(all(v), 0ll)
#define gcd(x, y) __gcd(x, y)
ll ctoi(char c)
{
    if (c >= '0' && c <= '9')
    {
        return c - '0';
    }
    return 0;
}
template <typename T>
T lcm(T x, T y)
{
    T z = gcd(x, y);
    return x * y / z;
}
template <typename T>
bool primejudge(T n)
{
    if (n < 2)
        return false;
    else if (n == 2)
        return true;
    else if (n % 2 == 0)
        return false;
    double sqrtn = sqrt(n);
    for (T i = 3; i < sqrtn + 1; i++)
    {
        if (n % i == 0)
        {
            return false;
        }
        i++;
    }
    return true;
}
//場合によって使い分ける
//const ll dx[4]={1,0,-1,0};
//const ll dy[4]={0,1,0,-1};
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//2次元配列の宣言
//vector<vector<ll>> field(h, vector<ll>(w));

int main()
{
    cout << fixed << setprecision(30);
    ll n;
    cin >> n;
    vec a(n), b(n);
    loop(i, n) cin >> a[i] >> b[i];
    vector<pair<ll, ll>> ab(n);
    vector<pair<ll, ll>> ba(n);
    loop(i, n)
    {
        ab[i] = make_pair(a[i], b[i]);
        ba[i] = make_pair(b[i], a[i]);
    }
    sort(all(ab));
    sort(all(ba));
    if (n % 2 == 1)
    {
        putout(ba[n / 2].first - ab[n / 2].first + 1);
    }
    if (n % 2 == 0)
    {
        putout(ba[n / 2].first + ba[n / 2 - 1].first - ab[n / 2].first - ab[n / 2 - 1].first + 1);
    }
    return 0;
}


Measured memory_bytes: 12760
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <chrono>
#include <random>

using namespace std;

#define int long long
#define ll long long
//#define double long double
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

const int INF = 2e9;
const int MB = 20;
const int MOD = 998244353;

vector<vector<int>> g;
vector<int> dp;
vector<bool> used;

void dfs(int v) {
    used[v] = true;
    int res = 1;
    for (int u : g[v]) {
        dfs(u);
        res = res * (dp[u] + 1) % MOD;
    }
    dp[v] = res;
}

void solve() {
    int n;
    cin >> n;
    vector<pair<int, int>> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i].first >> a[i].second;
    }

    sort(all(a));

    map<int, int> mp;
    for (int i = 0; i < n; i++) {
        mp[a[i].first] = i;
    }

    g.resize(n);
    set<int> st;
    for (int i = n - 1; i >= 0; i--) {
        while (!st.empty()) {
            auto it = st.lower_bound(a[i].first);
            if (it == st.end() || *it >= a[i].first + a[i].second) break;
            int id = mp[*it];
            st.erase(it);
            g[i].push_back(id);
        }
        st.insert(a[i].first);
    }

    dp.resize(n);
    used.resize(n);
    int ans = 1;
    for (int i = 0; i < n; i++) {
        if (!used[i]) {
            dfs(i);
            ans = ans * (dp[i] + 1) % MOD;
        }
    }
    cout << ans;
}
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    solve();
}

Measured memory_bytes: 40960
#include<stdio.h>
#include<stdlib.h>
#define MAX 100
#define NIL -1
#define a(x,y) ((x) > (y) ? (x) : (y))
struct Node {int p,l,r;};
struct Node T[MAX];
int D[MAX];
int getDepth(int);
int setHight(int*,int);
int getSibling(int);

int main(){
  int n,i,c,l,r;
  scanf("%d",&n);

  for(i = 0; i < n; i++){
    T[i].p = NIL;
    T[i].l = NIL;
    T[i].r = NIL;
  }

  for(i = 0; i < n; i++){
    scanf("%d%d%d",&c,&l,&r);
    T[c].l = l;
    T[c].r = r;
    if(l != NIL) T[l].p = c;
    if(r != NIL) T[r].p = c;
  }

  for(i = 0; i < n; i++){
    if(T[i].p == NIL) r = i;
  }
  for(i = 0; i < n; i++){
      int d=0;
    printf("node %d: ",i);
    printf("parent = %d, ",T[i].p);
    printf("sibling = %d, ",getSibling(i));
    if(T[i].l != NIL) d++;
    if(T[i].r != NIL) d++;
    printf("degree = %d, ",d);
    printf("depth = %d, ",getDepth(i));
    setHight(D,i);
    printf("height = %d, ",D[i]);

    if(T[i].p == NIL) printf("root\n");
    else if(T[i].l == NIL && T[i].r == NIL) printf("leaf\n");
    else printf("internal node\n");

  }

}

int getDepth(int u){
 int a = 0;
 while(T[u].p != NIL){
   u = T[u].p;
   a++;
 }
 return a;
}

int setHight(int D[],int u){
 int h1 = 0, h2 = 0;
 if(T[u].r != NIL){
   h1 = setHight(D,T[u].r) + 1;
 }
 if(T[u].l != NIL){
   h2 = setHight(D,T[u].l) + 1;
 }

 return D[u] = a(h1,h2);
}

int getSibling(int u){
 if(T[u].p == NIL) return NIL;
 if(T[T[u].p].l != u && T[T[u].p].l != NIL){
   return T[T[u].p].l;
 }
 if(T[T[u].p].r != u && T[T[u].p].r != NIL){
   return T[T[u].p].r;
 }
 return NIL;
}



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

int main() {

	string S;
	cin >> S;

	//初期値は大きい値
	int ans = S.size();

	//iは最初に使う色 (0 or 1)
	for (int i = 0; i < 2; i++)
	{
		// iを最初に使った時に変えなければならないタイルの数
		int cnt = 0;

		for (int j = 0; j < S.size(); j++)
		{
			// (char)(0 + '0') -> '0';
			// (char)(1 + '0') -> '1';
			if (j % 2 == 0 && S[j] != (char)(i + '0')) cnt++;
			if (j % 2 == 1 && S[j] == (char)(i + '0')) cnt++;
		}

		ans = min(ans, cnt);
	}

	cout << ans << endl;
}



Measured memory_bytes: 512
N = int(input())
L = list(map(int, input().split()))
ma = max(L)
mi = L.index(ma)
S = 0
nma = L[0]

for i in range(1, len(L)):
  if mi <= i:
    S += ma - L[i]
  else:
    nma = max(nma, L[i])
    S += nma - L[i]
print(S)

Measured memory_bytes: 32384