akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<int,int>;
/* ちゃんと考えてわかって実装 */

# define MAX_N 1000010 // 10^6 + 10

// UnionFindTree
// 使い方(インスタンス名 : tree)
// インスタンス生成 : UnionFind tree;
// tree.init(要素数)
// uniteしたりsameかどうか判定したり

class UnionFind{
    private:
        int par_[MAX_N];
        int rank_[MAX_N];
        int size[MAX_N];
        int groups_;
    
    public:
        void init(int n){ // initializes the tree 
            for(int i=0; i<n; i++){
                par_[i] = i;
                rank_[i] = 0;
                size[i] = 1;
            }
            groups_ = n;
        } 
        int rootOf(int x){ // returns the root of x 
            if(par_[x] == x){
                return x;
            }
            else{
                return par_[x] = rootOf(par_[x]);
            }
        } 
        void unite(int x, int y){ // unites x and y 
            x = rootOf(x);
            y = rootOf(y);
            if(x == y) return;
            if(rank_[x] < rank_[y]){
                par_[x] = y;
                groups_--;
                size[y] += size[x];
            }
            else{
                par_[y] = x;
                groups_--;
                size[x] += size[y];
                if(rank_[x] == rank_[y]) rank_[x]++;
            }
        }
        bool isSameGroupe(int x, int y){ // whether x and y are united
            return rootOf(x) == rootOf(y);
        }
        int countGroups(){ // returns the number of groups
            return groups_;
        }
        // 6 / 19 Updated!! (連結成分のサイズを返す)
        int sizeOf(int x){
            return size[rootOf(x)];
        }
};

int main(void){
    int n, m;
    cin >> n >> m;
    vector<int> p(n+1);
    for(int i=1; i<=n; i++){
        cin >> p[i];
    }

    UnionFind tree;
    tree.init(n);
    for(int i=0; i<m; i++){
        int x, y;
        cin >> x >> y;
        tree.unite(x, y);
    }

    int ans = 0;
    for(int i=1; i<=n; i++){
        if(tree.isSameGroupe(i, p[i])) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4784
#include <iostream>
#include<string>
#include<math.h>
#include<vector>
#include<algorithm>
#include<array>
#include<functional>
using namespace std;
#define FOR(i,n) for(int (i)=0;(i)<(n);(i)++)


int main(){
    int n;
    cin >> n;
    vector<int> a;
    FOR(i,n){
        int tmp;
        cin >> tmp;
        a.push_back(tmp);
    }
    sort(a.begin(),a.end());

    int amax=a[n-1];
    int tmpmax=-1;
    int tmpmaxpointer=-1;
    //int Maxpo=-1;
    FOR(i,n){
        
        if(min(a[i],amax-a[i])>tmpmax){
            tmpmax=min(a[i],amax-a[i]);
            tmpmaxpointer=i;
        }    
    }
    cout << amax << " "<< a[tmpmaxpointer];
    return 0;
}

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

#define MOD_1_000_000_007 (1000000007LL)
#define LINF (1LL<<60)
#define rep(i, n)   for (long long i = 0; i <  (long long)(n); i++)
#define rep1(i, n)  for (long long i = 1; i <  (long long)(n); i++)
#define rep2(i, n)  for (long long i = 2; i <  (long long)(n); i++)
#define rep0c(i, n) for (long long i = 0; i <= (long long)(n); i++)
#define rep1c(i, n) for (long long i = 1; i <= (long long)(n); i++)
#define rep2c(i, n) for (long long i = 2; i <= (long long)(n); i++)
#define repc0(n, i) for (long long i = (long long)(n); i >= 0; i--)
#define repc1(n, i) for (long long i = (long long)(n); i >= 1; i--)
#define repc2(n, i) for (long long i = (long long)(n); i >= 2; i--)
#define REP(i, n, m) for (long long i = (long long)(n); i < (long long)(m); i++)

namespace solver {
  using namespace std;
  typedef long long ll;

  ll A, B, C, D;

  void init() {
    scanf("%lld %lld %lld %lld", &A, &B, &C, &D);
  }

  void solve() {
    bool turn = true;
    while(1) {
      if(turn) C-=B;
      else A-=D;
      if(A<=0) {
        printf("No\n");
        break;
      } else if(C<=0) {
        printf("Yes\n");
        break;
      }
      turn = !turn;
    }
  }
}

int main() {
  solver::init();
  solver::solve();
  return 0;
}

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

typedef uint32_t u32;
typedef uint64_t u64;

void revj(std::string& str) {
  std::string temp;
  temp += str[str.size() - 1];
  for(int i = 0; i < (int)str.size() - 1; ++i) {
    temp += str[i];
  }
  str = temp;
}

void revc(std::string& str) {
  std::string temp;
  for(int i = 1; i < (int)str.size(); ++i) {
    temp += str[i];
  }
  temp += str[0];
  str = temp;
}

void reve(std::string& str) {
  for(int i = 0; i < (int)str.size() / 2; ++i) {
    std::swap(str[i], str[(str.size() + 1) / 2 + i]);
  }
}

void reva(std::string& str) {
  std::reverse(str.begin(), str.end());
}

void revp(std::string& str) {
  for(int i = 0; i < (int)str.size(); ++i) {
    if( '0' <= str[i] and str[i] <= '9' ) {
      str[i] = (str[i] - '0' + 10 - 1) % 10 + '0';
    }
  }
}

void revm(std::string& str) {
  for(int i = 0; i < (int)str.size(); ++i) {
    if( '0' <= str[i] and str[i] <= '9' ) {
      str[i] = (str[i] - '0' + 1) % 10 + '0';
    }
  }
}

int main() {

  int n;
  std::cin >> n;
  for(int i = 0; i < n; ++i) {
    std::string order;
    std::cin >> order;
    std::string message;
    std::cin >> message;
    for(int j = (int)order.size(); j >= 0; --j) {
      switch( order[j] ) {
      case 'J' :
        revj(message);
        break;
      case 'C' :
        revc(message);
        break;
      case 'E' :
        reve(message);
        break;
      case 'A' :
        reva(message);
        break;
      case 'P' :
        revp(message);
        break;
      case 'M' :
        revm(message);
        break;
      }
    }
    std::cout << message << std::endl;
  }
   
  return 0;
}

Measured memory_bytes: 3060
import java.util.*;


class Main{

    int n;
    int[] t = new int[10];
    
    Main(){
        Scanner sc = new Scanner(System.in);
        n=sc.nextInt();
        while(n>0){
            n--;
            for(int i=0;i<10;i++){
                t[i]=sc.nextInt();
            }
            System.out.println(solve());
        }
    }

    String solve(){
        int L=0,R=0;
        for(int i=0;i<10;i++){
            if(L<t[i])L=t[i];
            else if(R<t[i])R=t[i];
            else return "NO";
        }
        return "YES";
    }
    

    public static void main(String[] args){
        new Main();
    }
}

Measured memory_bytes: 18128
//gauravsinghh
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long int
#define ld long double
#define db double
#define pii pair<int,int>
#define pll pair<long long,long long>
#define sii set<int>
#define sll set<long long>
#define vii vector<int> 
#define vll vector<long long>
#define mii map<int,int>
#define mll map<long long, long long>
#define lob lower_bound
#define upb upper_bound
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define pf pop_front
#define ins insert
#define mp make_pair
#define w(t) cin >> t;while(t--)
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define os cout<<" "
#define bitcount __builtin_popcount
#define gcd __gcd
#define endl "\n"
#define present(s,x) (s.find(x) != s.end()) 
#define cpresent(s,x) (find(all(s),x) != s.end()) 
#define ford(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++) 
#define fors(container, it, a, b) for(__typeof(container.begin()) it = a; it != b; it++) 
#define MOD 1000000007
#define EPSILON 1e-9
#define PI 3.14159265358979323846
#define inf 999999999999999999
#define siz 100005
#define fbo find_by_order
#define ook order_of_key
#define sz(s) (int)s.size()
#define mem(n,m) memset(n,m,sizeof(n))
#define rep(i,n) for(ll i = 0; i < n; i++)
#define ren(i,n) for(ll i = n-1; i >= 0; i--)
#define all(x) x.begin(),x.end()
#define fo(i, a, b) for(int i = a; i <= b; i++)
#define ffo(i, a, b) for(int i = a; i >= b; i--)
#define MAX 100005
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;

//#pragma GCC target ("avx2")
//#pragma GCC optimization ("O3")
//#pragma GCC optimization ("unroll-loops")

void io_set() {
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}

bool comp(const pair < ll, ll >&a, const pair < ll, ll >&b){
    return ((a.ss < b.ss) || (a.ss == b.ss && a.ff < b.ff));
}

signed main(){ 
    IOS
    //io_set();
    ll n = 3;
    deque < char > q[n];
    string s;
    rep(i, n){
        cin >> s;
        rep(j, sz(s)){
            q[i].pb(s[j]);
        }
    }
    char x = q[0].front();
    q[0].pf();
    while(1){
        if(x == 'a'){
            if(q[0].empty()){
                cout << "A";
                return 0;
            }
            x = q[0].front();
            q[0].pf();
        }
        else if(x == 'b'){
            if(q[1].empty()){
                cout << "B";
                return 0;
            }
            x = q[1].front();
            q[1].pf();
        }
        else if(x == 'c'){
            if(q[2].empty()){
                cout << "C";
                return 0;
            }
            x = q[2].front();
            q[2].pf();
        }
    }
}



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

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

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

	int tmp = 0;
	while(N > 0) {
		tmp += N % 10;
		N /= 10;
	}
	if(n % tmp == 0) cout << "Yes" << endl;
	else cout << "No" << endl;

}


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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  int N;
  cin >> N;
  if(N / 10 == 9 || N % 10 == 9){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
//include
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const long long INF = 1000000007;
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
// chmax chmin
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(void){
    int N; cin >> N;
    cout << (N%10==9 || N/10==9 ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int sum = 0;
    for(int i=0; i<N; i++){
      int li = sc.nextInt();
      int ri = sc.nextInt();
      sum = sum+ri-li+1;
    }
    System.out.println(sum);
  }
}


Measured memory_bytes: 24788
#include <bits/stdc++.h>
#include <unordered_map>
using namespace std;
#define all(v)          ((v).begin()), ((v).end())
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define clr(v,d)		memset(v, d, sizeof(v))
const double EPS = 1e-8;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int>P;
const ll mod = 998244353;
int dx[] = { 0, 0, -1, 1, 1, 1, -1, -1 };
int dy[] = { 1, -1, 0, 0, 1, -1, -1, 1 };
const int N = 500001;
#define endl '\n'
#define F first
#define S second
#define pii pair<int,int>
#define pll pair<ll,ll>
void stop(){
#ifndef ONLINE_JUDGE
	system("pause");
#endif
}
struct point{
	double x, y;
};
ll gcd(ll a, ll b){ return !b ? a : gcd(b, a % b); }
ll fixMod(ll a, ll b){ return ((a%b) + b) % b; }
double triangle_area(int x1, int y1, int x2, int y2, int x3, int y3) {
	return abs((x2 - x1) * (y3 - y1) - (y2 - y1) * (x3 - x1)) / 2.;
};
ll dis(point a, point b) {
	ll x = a.x - b.x, y = a.y - b.y;
	return x * x + y * y;
}
double traingleArea(double a, double b, double c) {
	double s = (a + b + c) / 2.0;
	return sqrt(s * (s - a) * (s - b) * (s - c));
}
double circleArea(double r) {
	return acos(-1) * r * r;
}
ll power(ll x, ll y)
{
	if (y == 0)return 1;
	if (y == 1)return x;
	ll r = power(x, y / 2) % mod;
	return r%mod*r%mod*power(x, y % 2) % mod;
}

int main(){
	fast
		ll n, h, w;
	cin >> n >> h >> w;
	cout << (n - h+1)*(n - w+1);
	return 0;
}

Measured memory_bytes: 256
<?php
while( fscanf( STDIN, "%d", $n ) ){
  $cnt=0;
  for($a=0;$a<10;$a++){
    if($a>$n) break;
    for($b=0;$b<10;$b++){
      $t=$a+$b;
      if($t>$n) break;
      for($c=0;$c<10;$c++){
        $u=$t+$c;
        if($u>$n) break;
        $d=$n-$u;
        if($d<0) continue;
        if($d>9) continue;
        ++$cnt;
      }
    }
  }
  printf("%d\n",$cnt);
}

Measured memory_bytes: 15020
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + (ll)b) % mod
#define MUL(a, b) a = (a * (ll)b) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define rer(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<int, pi> ppi;
typedef vector<ll> vi;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest) { 
	cout << arg << " "; Debug(rest...); }
template<class T>ostream& operator<< (ostream& out, const vector<T>& v) {
	out << "[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<< ", ";out<<v.back();}out << "]";return out;}
template<class S, class T>ostream& operator<< (ostream& out, const pair<S, T>& v) {
	out << "(" << v.first << ", " << v.second << ")";return out;}
const int MAX_N = 200010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 30;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

ll N = 1;


bool all_nine(ll v) {
	while(v) {
		if(v % 10 != 9) return false;
		v /= 10;
	}
	return true;
}


string ll_to_str(ll N) {
	string str;
	while(N) {
		str += (N % 10 + '0');
		N /= 10;
	}
	reverse(all(str));
	return str;
}

char get_ans(ll res) {
	string sn = ll_to_str(N);
	string sres = ll_to_str(res);
	bool s;
	if(N <= res && sn <= sres) s = true;
	else if(N > res && sn > sres) s = true;
	else s = false;
	return s ? 'Y' : 'N';
}

bool ok(ll res) {
	//char c = get_ans(res);
	cout << "? " << res << endl;
	char c; cin >> c;
	return c == 'Y';
}


void solve() {
	ll res = 0;
	for(ll i = 0; i < 10; i++) {
		ll lv, rv = 10;
		if(i == 0) lv = 1;
		else lv = 0;
		while(rv - lv > 1) {
			ll m = (lv + rv) / 2;
			if(ok(res * 10 + m)) lv = m;
			else rv = m;
		}
		res = res * 10 + lv;
		//char c = get_ans(res + 1);
		cout << "? " << res + 1 << endl;
		char c; cin >> c;

		if((all_nine(res) && c == 'N') || (!all_nine(res) && c == 'Y')) {
			res -= 9;
			if(i == 0) lv = 0;
			else lv = -1;
			rv = 9;
			while(rv - lv > 1) {
				ll m = (lv + rv) / 2;
				if(ok(res * 10 + m * 10)) rv = m;
				else lv = m;
			}
			cout << "! " << res + rv << endl;
			return;
		}
	}
	cout << "!  1" << endl;
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(5);
	/*
#ifdef LOCAL
    freopen("in.txt", "rt", stdin);
#endif	
*/
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}






Measured memory_bytes: 596
read N
read S

for n in `seq 1 $((N-1))`; do
        X=`echo $S | awk '{print substr($0,1,'$n')}'`
        Y=`echo $S | awk '{print substr($0,'$((n+1))')}'`
        cat <(echo $X | fold -s1 | sort | uniq) <(echo $Y | fold -s1 | sort | uniq) | sort | uniq -d | wc -l
done | sort -nr | head -1

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

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

#define int                     long long int
#define ld                      long double
#define pb                      push_back
#define MOD                     1000000007
#define inf                     3e18
#define vi                      vector<int>
#define vld                     vector<ld>
#define pii                     pair<int,int>
#define mii                     map<int,int>
#define fi                      first
#define se                      second
#define fastIO                  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define db(...)                 __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) { cerr << " "<< name << " : " << arg1 <<'\n'; }
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...);
}

typedef tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> pbds; 
		//order_of_key (k) : Number of items strictly smaller than k .
		//find_by_order(k) : K-th element in a set (counting from zero) (returns an iterator)           


void inp_out()
{
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	freopen("debug.txt", "w", stderr);
	#endif
}

int32_t main()
{
	fastIO
	inp_out();
	string s; 
	cin >> s; 
	if(s[s.size() - 1] == 's')
		s += 'e'; 
	s += 's'; 
	cout << s; 
	

	return 0;
}

Measured memory_bytes: 3660
//????????????????????????(????????????????????§???)

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

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

    int v[n],w[n],dp[110][10010];
    rep(i,0,n) {
        cin >> v[i] >> w[i];
    }

    rep(i,0,W) dp[0][i] = 0;

    rep(i,0,n) {
        rep(j,0,W+1) {
            if(j < w[i]) dp[i+1][j] = dp[i][j];
            else dp[i+1][j] = max(dp[i][j], dp[i][j-w[i]] + v[i]);
        }
    }

    cout << dp[n][W] << endl;
}

Measured memory_bytes: 5268
const main = (input) => {
  input = input.split(' ');
  const x = parseInt(input[0], 10);
  
  if (1200>x) {
    console.log('ABC');
  }else{
    console.log('ARC');
  }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 11468
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 998244353
#define pii pair<ll,ll>
#define inf 1000000000000000000
#define bpc(x) __builtin_popcountll(x)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)

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

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 

using namespace std;
mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count());

void upd(ll st[], ll l, ll r, ll l1, ll i, ll val, bool ty)           //0 - min, 1 - max
{
    if(l1>r || l1<l)
        return;
    if(l == r)
    {
        st[i] = max(st[i],val);
        return;
    }
    ll mid = (l+r)/2;
    upd(st,l,mid,l1,2*i+1,val,ty);
    upd(st,mid+1,r,l1,2*i+2,val,ty);
    
    st[i] = max(st[2*i+1], st[2*i+2]);
}

ll que(ll st[], ll l, ll r, ll i, ll val, bool ty)              //0 - min, 1 - max
{
    if(l == r)
    {
        if(st[i]<val)
            return l;
        return l-1;    
    }
    
    ll mid = (l+r)/2;
    if(st[2*i+1]<val)
        return que(st,mid+1,r,2*i+2,val,ty);
    return que(st,l,mid,2*i+1,val,ty);
    
        
    
}

int main()
{
  FAST/**/
   
   ll n,q;
   cin>>n>>q;
   
   
   ll ht = ceil(log2(n-1));
   ht = (1ll<<(ht+1)) - 1;
   ll upmax[ht], leftmax[ht];
   rep(ht)
        upmax[i] = leftmax[i] = -1;
        
   upd(upmax,0,n-2,n-2,0,n-2,1);
   upd(leftmax,0,n-2,n-2,0,n-2,1);
   
   ll tot = (n-2)*(n-2);
   
   while(q--)
   {
       ll ty;
       cin>>ty;
       ll x;
       cin>>x;
       x-=2;
       
       if(ty == 1)
       {
           ll temp = que(leftmax,0,n-2,0,x,1);
           if(temp>-1)
           {
               upd(upmax,0,n-2,x,0,temp,1);
               tot-=(temp+1);
               continue;
           }
           continue;
       }
       
       ll temp = que(upmax,0,n-2,0,x,1);
       if(temp>-1)
       {
           upd(leftmax,0,n-2,x,0,temp,1);
           tot-=(temp+1);
           continue;
       }
   }
   
   cout<<tot;
           
   
   return 0;        
}  

  
          
   

Measured memory_bytes: 12056
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i=0; i < n; i++)
#define repd(i, n) for (int i = n-1; i > -1; i--)
#define repran(i, a,b) for (int i = a; i<b;i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> P;

int main()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    vector<set<int>> p(26);
    rep(i, n){
        int v = s[i]-'a';
        p[v].insert(i);
    }
    int q;
    cin >> q;
    rep(i, q){
        int t;
        cin >> t;
        if (t == 1){
            int j;char c;
            cin >> j >> c;
            j--;
            p[s[j]-'a'].erase(j);
            p[c-'a'].insert(j);
            s[j] = c;
        }else{
            int l, r;
            cin >> l >> r;
            l--;r--;
            int ans = 0;
            
            rep(j, 26){
                auto it = p[j].lower_bound(l);
                if (*it <= r && it != p[j].end()) ans++;
            }
            cout << ans << endl;
        }
    }
    return 0;

}

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

int A, B, C;
int main(){
	cin>>A>>B>>C;
	int sisaA, sisaC;
	sisaA=A-B;
	sisaC=C-sisaA;
	if(sisaC<=0){
	sisaC=0;
	}
	cout<<sisaC;
}


Measured memory_bytes: 256
#include <stdio.h>

int main() {
  int i, number_n;
  scanf("%d", &number_n);
  long long int lucas_number[number_n+1];
  lucas_number[0] = 2;
  lucas_number[1] = 1;
  for(i = 2; i <= number_n; i++) {
    lucas_number[i] = lucas_number[i-1] +lucas_number[i-2];
  }
  printf("%lld\n", lucas_number[number_n]);
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <algorithm>
#include <functional>
#include <deque>
#include <cctype>
#include <ctime>
#include <cstdlib>
#include <iomanip>
using namespace std;

int main(){
  ;;
    int a, b;
    cin >> a >> b;
    ;
    cout << ((a-1)*(b-1)) << endl;;
}

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

using namespace std;

typedef pair<int, int> P;
#define MAX_HW 35

int dx[4] = {1,0,-1,0};
int dy[4] = {0,-1,0,1};
int w,h;
int maze[MAX_HW*2-1][MAX_HW-1];
int sx=0,sy=0;
int gx,gy;

int d[MAX_HW][MAX_HW];

int bfs(){
    queue<P> que;
    memset(d,-1,sizeof(d));
    que.push(P(sx,sy));
    d[sx][sy]= 1;
    while(que.size()){
        P p=que.front();
        que.pop();
        if(p.first == gx && p.second == gy)break;
        for(int i=0;i<4;i++){
            int nx = p.first + dx[i], ny = p.second + dy[i];

            if(0 <= nx && nx <h && 0 <= ny&& ny < w && d[nx][ny] == -1){
                if(i==3){
                    if(maze[p.first*2][p.second+1]==0){
                        que.push(P(nx,ny));
                        d[nx][ny] = d[p.first][p.second] +1;
                    }
                }
                if(i==0){
                    if(maze[p.first*2+1][p.second]==0){
                        que.push(P(nx,ny));
                        d[nx][ny] = d[p.first][p.second] +1;
                    }
                }
                if(i==1){
                    if(maze[p.first*2][p.second]==0){
                        que.push(P(nx,ny));
                        d[nx][ny] = d[p.first][p.second] +1;
                    }
                }
                if(i==2){
                    if(maze[p.first*2-1][p.second]==0){
                        que.push(P(nx,ny));
                        d[nx][ny] = d[p.first][p.second] +1;
                    }
                }
            }
        }
    }
    if(d[gx][gy] == -1)return 0;
    else return d[gx][gy];

}


int main(){
    while(1){
        memset(maze,0,sizeof(maze));
        cin >> w >> h;
        gx = h-1;
        gy = w-1;
        if(w==0 && h==0)break;
        for(int i=0;i<2*h-1;i++){
            
            if(i%2==1){
                for(int j=0;j<w;j++){
                    cin >> maze[i][j];
                }
            }else{
                for(int j=1;j<w;j++){
                    cin >> maze[i][j];
                }
            }

        }
        cout << bfs() << endl;
    }


}


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstring>
#include <climits>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;

constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr double PI = 3.14159265358979323846;
constexpr int di[] = {0, 0, 1, -1};
constexpr int dj[] = {1, -1, 0, 0};

vector<int> g[212345];
ll x[212345];
ll res[212345];
bool vi[212345];

void dfs(int p, ll v)
{
    v += x[p];

    res[p] = v;

    vi[p] = true;

    for (int i : g[p])
    {
        if (!vi[i])
            dfs(i, v);
    }
}

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

    int n, q;
    cin >> n >> q;

    REP(i, n - 1)
    {
        int a, b;
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    memset(x, 0, sizeof(x));

    REP(i, q)
    {
        int p, y;
        cin >> p >> y;

        x[p] += y;
    }

    memset(res, 0, sizeof(res));
    memset(vi, 0, sizeof(vi));

    dfs(1, 0);

    REP(i, n)
    {
        cout << res[i + 1] << (i == n - 1 ? "\n" : " ");
    }

    return 0;
}

Measured memory_bytes: 23424
#include <bits/stdc++.h>
using namespace std;
int main() {
  string a;
  cin >> a;
  for(int bit=0; bit<(1<<a.size()-1); bit++){
    vector<char> x(a.size()-1, '-');
    for(int i=0; i<a.size()-1; i++){
      if(bit & (1<<i)){
        x[i] = '+';
      }
    }
    int sum = a[0]-'0';
    for(int i=0; i<a.size()-1; i++){
      if(x[i]=='+') sum += a[i+1]-'0';
      else sum -= a[i+1]-'0';
    }
    if(sum==7){
      cout << a[0];
      for(int i=0; i<a.size()-1; i++){
        cout << x[i] << a[i+1];
      }
      cout << "=7" << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 384
n = gets.to_i
restrant = {}
n.times do |i|
 city, score = gets.chomp.split(" ")
 if  restrant[city] == nil
   restrant[city] = []
 end
 restrant[city].push([score.to_i, i+1])
end


for city, scores in  restrant.sort{|k, v| k<=>v}
  for score in scores.sort.reverse{|s, n| s<=>n}
    puts score[1]
  end
end

Measured memory_bytes: 1916
#include <bits/stdc++.h>
#include <numeric>
typedef long long ll;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
using namespace std;

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

    int N; string s, t;
    cin >> N >> s >> t;

    int overlap = 0;
    rep(i, 0, s.size()) {
        if (s.substr(s.size()-1-i) == t.substr(0, i+1)) overlap = i+1;
    }

    cout << s.size() + t.size() - overlap << endl;
}

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

typedef long long   signed int LL;
typedef long long unsigned int LU;

#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)
#define  inc(i, n) incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define  dec(i, n) decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)

#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))

#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define PQ priority_queue

#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)
#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)

template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }

// ---- ----

int a, b, c, x, y;

int main() {
	cin >> a >> b >> c >> x >> y;
	
	int ans = 1e9;
	incII(i, 0, max(x, y) * 2) {
		if(i % 2 != 0) { continue; }
		
		setmin(ans, a * max(0, (x - i / 2)) + b * max(0, (y - i / 2)) + c * i);
		// cout << a * max(0, (x - i / 2)) + b * max(0, (y - i / 2)) + c * i << endl;
	}
	
	cout << ans << endl;
	
	return 0;
}


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

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

ll lcm(ll a, ll b){
   return a*b/gcd(a, b);
}

int main(){
	ll A, B, C, D;
	cin >> A >> B >> C >> D;

	ll E = lcm(C,D);
	ll ans = B - B/C - B/D + B/E;
	A--;
	ans -= A - A/C - A/D + A/E;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3676
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
    int m, k; cin>>m>>k;
    if(k>=(1<<m) || (m==1 && k==1)){
        cout<<-1<<endl; return 0;
    }
    if(k==0){
        for(int i=0; i<(1<<m); i++){
            cout<<i<<" "<<i;
            if(i<(1<<m)-1) cout<<" ";
        }
        cout<<endl;
        return 0;
    }else{
        cout<<0<<" "<<k<<" "<<0<<" ";
        for(int i=(1<<m)-1; i>=1; i--){
            if(i==k) continue;
            cout<<i<<" ";
        }
        cout<<k<<" ";
        int c=0;
        for(int i=1; i<(1<<m); i++){
            if(i==k) continue;
            cout<<i;
            c++;
            if(c<(1<<m)-2) cout<<" ";
        }
        cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
using namespace std;
int main(void) {
	string s;
	long long k;
	cin >> s >> k;
	long long cnt = 0;
	char c;
	for (int i = 0; i < s.size(); ++i) {
		if (s[i] == '1') ++cnt;
		else {
			c = s[i];
			break;
		}
	}
	if (cnt >= k) cout << 1 << endl;
	else cout << c << endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static String lcs(String s, String t){
        StringBuilder sb = new StringBuilder();
        State[][] dpState = new State[t.length()+1][s.length()+1];
        for (int i = 0; i < t.length() + 1; i++) {
            for (int j = 0; j < s.length() + 1; j++) {
                dpState[i][j] = new State();
            }
        }
        for (int i = 0; i < s.length() + 1; i++) {
            dpState[0][i].length = 0;
        }
        for (int i = 0; i < t.length() + 1; i++) {
            dpState[i][0].length = 0;
        }
        for (int i = 1; i < t.length() + 1; i++) {
            for (int j = 1; j < s.length() + 1; j++) {
                if (t.charAt(i-1) == s.charAt(j-1)){
                    dpState[i][j].length = dpState[i-1][j-1].length + 1;
                    dpState[i][j].direction = Direction.Diag;
                }else {
                    if (dpState[i-1][j].length > dpState[i][j-1].length){
                        dpState[i][j].length = dpState[i-1][j].length;
                        dpState[i][j].direction = Direction.Down;
                    }else {
                        dpState[i][j].length = dpState[i][j-1].length;
                        dpState[i][j].direction = Direction.Right;
                    }
                }
            }
        }
        int i = t.length();
        int j = s.length();
        while (i > 0 && j > 0){
            switch (dpState[i][j].direction){
                case Diag:
                    sb.insert(0, s.charAt(j-1));
                    i--;
                    j--;
                    break;
                case Down:
                    i--;
                    break;
                case Right:
                    j--;
                    break;
            }
        }
        return sb.toString();
    }

    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String s = reader.readLine();
        String t = reader.readLine();
        System.out.println(lcs(s,t));
    }

    private static class State{
        int length;
        Direction direction;
    }

    private enum Direction{
        Right,
        Down,
        Diag
    }
}


Measured memory_bytes: 379340
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
using namespace std;
const int mod = 1000000007;
#define ll long long

int main()
{
	string s;
	for (int i = 0; i < 3; i++) {
		cin >> s;
		cout << s[0];
	}
	cout << endl;
}

Measured memory_bytes: 256
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
from collections import Counter,defaultdict,deque
from itertools import permutations, combinations
from heapq import heappop, heappush
from fractions import gcd
# input = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

def main():
    n = inp()
    s = list(input())
    r = [0 for _ in range(n+1)]
    g = [0 for _ in range(n+1)]
    b = [0 for _ in range(n+1)]
    R = []
    G = []
    B = []
    for i in range(n):
        r[i+1] = r[i]
        g[i+1] = g[i]
        b[i+1] = b[i]
        if s[i] == 'R':
            r[i+1] += 1
            R.append(i)
        if s[i] == 'G':
            G.append(i)
            g[i+1] += 1
        if s[i] == 'B':
            B.append(i)
            b[i+1] += 1
    ans = len(R)*len(G)*len(B)
    for i in range(n-2):
        for e in range(1,(n//2)+3):
            if i+2*e >= n:
                continue
            if s[i] != s[i+e] and s[i] != s[i+2*e] and s[i+e] != s[i+e*2]:
                ans -= 1
    print(ans)

    
if __name__ == "__main__":
    main()

Measured memory_bytes: 74160
"use strict";
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill(0).map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill(0).map(x=>"+r+")";return eval(r);}
var mod = 1e9+7;
function mul(){for(var a=arguments,r=a[0],i=a.length;--i;)r=((r>>16)*a[i]%mod*65536+(r&65535)*a[i])%mod;return r;}

var bit = xArray(0,60);
var y = 30;
var z = 1 << y;

console.log(main());
function main(){
  var n = o.a();
  var a = o.l(1);
  for(var i = 0; i < n; i++){
    if(a[i] > 9e15){
      big(a[i]);
    }else{
      small(+a[i]);
    }
  }
  var ans = 0, x = 1;
  for(var i = 0; i < 60; i++){
    ans += mul(x,bit[i],n-bit[i]);
    x = x*2%mod;
  }
  return ans%mod;
}

function small(x){
  var j = 0;
  while(x){
    if(x&1)bit[j]++;
    x = Math.floor(x * 0.5);
    j++;
  }
}

function big(x){
  var h = +x.slice(0,-5);
  var l = +x.slice(-5);
  var u = h / z | 0;
  var v = h - u * z;
  u *= 1e5;
  l += v * 1e5;
  v = l / z | 0;
  u += v;
  v = l - v * z;
  for(var i = y; u; i++, u >>>= 1){
    if(u&1)bit[i]++;
  }
  small(v);
}

Measured memory_bytes: 63364
#include <iostream>
#include <stdlib.h>
#include <string>
#include <stack>

using namespace std;

void solve()
{
	string str;
	stack<int> num;
	char c;
	while(cin >> str)
	{
		if(str == "+")
		{
			c = '+';
		}
		else if(str == "-")
		{
			c = '-';
		}
		else if(str == "*")
		{
			c = '*';
		}
		else if(str == "/")
		{
			c = '/';
		}
		else if(str == "=")
		{
			cout << num.top() << endl;
			num.pop();
		}
		else
		{
			if(num.empty())
			{
				num.push(atoi(str.c_str()));
			}
			else
			{
				int a = num.top();
				num.pop();
				if(c == '+')
				{
					num.push(a + atoi(str.c_str())); 
				}
				else if(c == '-')
				{
					num.push(a - atoi(str.c_str())); 
				}
				else if(c == '*')
				{
					num.push(a * atoi(str.c_str())); 
				}
				else if(c == '/')
				{
					num.push(a / atoi(str.c_str())); 
				}
			}
		}
	}
}

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

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

#define ll long long int
#define ff first
#define ss second
#define int long long int
#define pb push_back

#define N 100010
#define MOD 1000000007

int isprime(int n)
{
	for(int i = 2; i <= sqrt(n); ++i)
		if(n % i == 0)
			return 0;
	return 1;
}

int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);

 	int x;
 	cin >> x;

 	while(1)
 	{
 		if(isprime(x))
 		{
 			cout << x;
 			break;
 		}
 		x++;	
 	}
 	return 0;
}


Measured memory_bytes: 256
//~ while (clock()<=69*CLOCKS_PER_SEC)
//~ #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
//~ #pragma GCC optimize("Ofast")
//~ #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//~ #pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define shandom_ruffle random_shuffle

using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;
const int nax=1000*1007;
const ll mno=1007;

int main() {
    
    ll x;
    cin >> x;
    ll sum = 0;
    sum += (ll)(1000 * (x / 500));
    x %= 500;
    sum += (ll)(5 * (x/5));
    cout << sum;
    return 0;
}

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

int top, S[1000];

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

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

int main() {
	int a, b;
	top = 0;
	char s[100];

	while (scanf("%s",s) != EOF) {
		if (s[0] == '+') {
			a = pop();
			b = pop();
			push(a + b);
		}
		else if (s[0] == '-') {
			b = pop();
			a = pop();
			push(a - b);
		}
		else if (s[0] == '*') {
			a= pop();
			b= pop();
			push(a*b);
		}
		else {
			push(atoi(s));
		}
	}
	printf("%d\n", pop());

	return 0;
}

Measured memory_bytes: 2736
n = int(input())
l = list(map(int,input().split()))

l.sort()
j = [0]*(10**6+1)

for i in l:
    j[i] += 1
    if j[i] == 1:
        for k in range(2*i,10**6+1,i):
            j[k] += 100

print(j.count(1))

Measured memory_bytes: 40436
#include<iostream>
using namespace std;
int main(){
    int H, W;
    
    while(1){
        cin >> H >> W;
        
        if((H == 0) && (W == 0))break;
        
        for(int i = 0; i < H; i++){
            for(int j = 0; j < W; j++){
                if((i+j) % 2 == 0){
                    cout << "#";
                }
                
                if((i+j) % 2 == 1){
                    cout << ".";
                }
                
                
            }
            
            cout << endl;
        }
        
        cout << endl;
    }
}


Measured memory_bytes: 3068
/*
 * cpp_filepath
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> ostream & operator << (ostream & out, vector<T> const & v) {
  for (auto &&a: v) out << a << " "; out << endl; return out;
}
template <class T> void dump(T &a) { cout << a << endl; }
void solve();
int main() { solve(); return 0; }


void solve() {
  vector<string> S {"Sunny", "Cloudy", "Rainy"};
  string s; cin >> s;
  auto it = find(S.begin(), S.end(), s);
  it++;
  if (it == S.end()) it = S.begin();
  cout << *it << endl;
}


Measured memory_bytes: 3444
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <regex>
#include <map>
#include <set>
#include <iomanip>

using namespace std;
using ll = long long;

int main(){
    string S;
    cin >> S;
    
    string youbi[7] = {"SUN","MON","TUE","WED","THU","FRI","SAT"};
    
    for(int i=0;i<7;i++){
        if(S==youbi[i]){
            cout << 7-i << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#define MOD 1000000007
typedef long long ll;
using namespace std;

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

  ll ans=0;
  int ma=0;
  for(int i=0;i<n;i++){
      if(ma+1==a[i]) ma=a[i];
      else{
          ll z=(a[i]-1)/(ma+1);
          ans+=z;
      }
      if(ma==0) ma=1;
  }

  cout<<ans<<endl;

  return 0;
}


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

// int/long:		-2,147,483,648 - 2,147,483,647 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

#define	INF (1<<30)
//1,073,741,824
//= 536,870,912 *2

#define	MOD 1000000007

#define	Rep0(i, n)	for (auto i=0; i<n; i++)
#define	Rep1(i, n)	for (auto i=1; i<=n; i++)
#define Sort(P)	sort(P.begin(), P.end())
#define Rev(P)	reverse(P.begin(), P.end())

int	main() {
	ll N;
	cin >>N;
	ll S=0;
	ll SQ=sqrt(N);
	Rep1(i, SQ) {
		ll D=N/i; // i..
		ll NN=(D+1)*D/2;
		//NN *=i;
		NN -=(i-1)*i/2;
		NN *=2;
		//NN -=i*i; // Except i*i
		NN-=i;
		NN *=i;
		S +=NN;
	}
	//S+=(N+1)*N/2;
	//S-=(SQ+1)*SQ/2;
	cout <<S <<endl;
	return 0;
}



Measured memory_bytes: 3532
#include<bits/stdc++.h>
#define ll long long int 
#define fori(i,n) for(int i=0; i<n; ++i)
#define ford(i,n) for(int i=n-1; i>=0; --i)
#define vi vector<int> 
#define vs vector<string>
#define vll vector<ll>
#define di deque<int>
#define vpii vector<pair<int,int>>
#define vpll vector<pair<ll,ll>>
#define pqi priority_queue<int>
#define pqll priority_queue<ll>
#define mod1 1000000007
#define mod2 998244353
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define gcd __gcd

#define fast_cin() ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> i_set;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,tree_order_statistics_node_update> ll_set; 
/* new_data_set p; */
/* *p.find_by_order(3); The value at third place */
/* p.order_of_key(7); The expected index in the set in sorted order */



int main(int argc, char const *argv[]){
    fast_cin();
    ll n,i;
    cin>>n;
    vector<ll> h(n);
    for(i=0; i<n; ++i) cin>>h[i];
    ll dp[100005]={0};
    dp[1]=0;
    dp[2]=abs(h[1]-h[0]);
    for(i=3; i<=n; ++i){
        dp[i]=min(dp[i-1]+abs(h[i-1]-h[i-2]),
                  dp[i-2]+abs(h[i-1]-h[i-3]));
    }
    cout<<dp[n]<<"\n";
    return 0;
}


Measured memory_bytes: 1792
n=int(input())
import math
from fractions import Fraction
a=[0]*n
b=[0]*n
for i in range(n):
    a[i],b[i]=map(int,input().split())
dp=[0]*n
dp[0]=1
for i in range(1,n):
    dp[i]=math.ceil(max(Fraction(a[i-1],a[i]),Fraction(b[i-1],b[i]))*dp[i-1])
x=dp[-1]
print(x*(a[-1]+b[-1]))


Measured memory_bytes: 5176