akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
#include <stack>
using namespace std;

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

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
using Graph=vector<vector<int>>;
using edge= struct{int to;ll cost;};


template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}
using Graph =vector<vector<int>>;


int main(){
  ll h,w;cin>>h>>w;
  if(h==1||w==1){
    cout<<1<<endl;
    return 0;
  }
  if(h%2==0){
    if(w%2==0){
      cout<<h*w/2<<endl;
    }
    else{
      cout<<h*w/2<<endl;
    }
  }
  else{
    if(w%2==0){
      cout<<h*w/2<<endl;
    }
    else{
      cout<<(h*w+1)/2<<endl;
    }
  }
}

Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mod 1000000007
int main(){
  string w[7] = {"SUN","MON","TUE","WED","THU","FRI","SAT"};
  string s;
    cin >> s;
    for(int i=0; i<7; i++)
      if(s==w[i]) cout << 7-i;

    cout << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define f0(i, n) for(int i(0); i<(n); i++)
#define f1(i, n) for(int i(1); i<=(n); i++)

using namespace std;
typedef long long ll;

ll n;

void solve(){
if(n==1){ cout << 1; return ;}
    ll ans = 0;
    ll u = n;
    while(u){
        ans += u%10;
        u /= 10;
    }
    ll t = 0, res = 1;
    while(res <= n){
        res *= 10; ++t;
    }
    if(n==res - 1){
        int val = t*9;
        cout << val;
        return ;
    }
    ll a[19], cnt = 0;
    while(n){
        a[++cnt] = n%10;
        n /= 10;
    }
    reverse(a + 1, a + cnt + 1);
    if(a[1] != 1){
        ll val = max(9*(t - 1), 9*(t - 1) + a[1] - 1);
        cout << max(val, ans);
        return ;
    }
    ll val = max(9*(t - 1), a[1] + a[2] - 1 + (t - 2)*9);
    cout << max(val, ans);
}

int main(){
    ios_base::sync_with_stdio(0);

    cin >> n;
    ll x = n;
    solve();
}


Measured memory_bytes: 256
X,N = map(int,input().split())
l=list(map(int,input().split()))
if N==0:
    print(X)
else:
    for i in range(101):
        if  X-i not in l:
            print(X-i)
            exit()
        elif X+i not in l:
            print(X+i)
            exit()


Measured memory_bytes: 9108
//Think simple yet elegant.
#include <bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll  long long
#define all(v) v.begin(),v.end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pi pair<int,int>
const ll maxn=2e5+10;
const ll mod=1e9+7;


int main() {
  	fast;
  	int a,b,c,d;
  	cin>>a>>b>>c>>d;
  	if(ceil(1.0*a/d) >=  ceil(1.0*c/b))
  		cout<<"Yes";
  	else
  		cout<<"No";
}

Measured memory_bytes: 3648
arr = []
gets.to_i.times do |i|
  arr << gets.chomp
end

if arr.size != arr.uniq.size
  puts 'No'
else
  lastword = arr[0][0]
  arr.each do |word|
    # puts "lastword:#{lastword}, word[0]:#{word[0]}"
    if lastword != word[0]
      puts 'No'
      exit
    else
      lastword = word[-1]
    end
  end
  puts 'Yes'
end

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

ll DP[101][5][5][5]; // 先に宣言すれば0で初期化

int main() {
    int N;
    cin >> N;

    string S = " ACGT"; // バグ回避の特効薬

    DP[0][0][0][0] = 1;
    for (int i = 0; i < N; ++i) {
        // 1番外側のforループだけ別格
        for (int j = 0; j < 5; ++j) {
            for (int k = 0; k < 5; ++k) {
                for (int l = 0; l < 5; ++l) {
                    // DP[i][j][k][l] に対してDP[i+1][][][]を計算
                    for (int m = 1; m < 5; ++m) {
                        if(S[k] == 'A' && S[l] == 'G' && S[m] == 'C') continue;
                        if(S[j] == 'A' && S[k] == 'G' && S[m] == 'C') continue;
                        if(S[j] == 'A' && S[l] == 'G' && S[m] == 'C') continue;

                        if(S[k] == 'G' && S[l] == 'A' && S[m] == 'C') continue;
                        if(S[k] == 'A' && S[l] == 'C' && S[m] == 'G') continue;

                        DP[i+1][k][l][m] += DP[i][j][k][l];
                        DP[i+1][k][l][m] %= mod;
                    }
                }
            }
        }
    }

    ll ans = 0;
    for (int i = 0; i < 5; ++i) {
        for (int j = 0; j < 5; ++j) {
            for (int k = 0; k < 5; ++k) {
                ans += DP[N][i][j][k];
                ans %= mod;
            }
        }
    }
    cout << ans;
    return 0;
}

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

#define F first
#define S second
#define prev azaza
#define MP make_pair
#define PB push_back

using namespace std;
typedef long long ll;
typedef long double ld;

const int max_n = 1, inf = 1000111222;

int main()
{
    //freopen("input.txt", "r", stdin);
    int w, h, x, y;
    cin >> w >> h >> x >> y;
    ld res = (1LL * w * h) / 2.0;
    cout << fixed << setprecision(10) << res << " ";
    if (w % 2 == 0 && x == w / 2 && h % 2 == 0 && y == h / 2) {
        cout << 1;
    } else {
        cout << 0;
    }

    return 0;
}




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

main(){
	int Q ;
	string s ;
	cin >> Q ;
	while(Q--){
		cin >> s ;
		int b[32] = {} ;
		for( int i=0 ; i<8 ; i++ ){
			int c = s[i] - '0' ;
			if( c >= 10 ) c -= 39 ;
			
			for( int j=3 ; j>=0 ; j-- ){
				int q=1 ;
				for( int k=0 ; k<j ; k++ ) q*=2 ;
				if( c&q ) b[4*i+3-j] = 1 ;
			}
		}
		if( b[0] ) cout << '-' ;
		
		int sum = 0 ;
		for( int i=1 ; i<=24 ; i++ ){
			sum += b[i] * pow(2,24-i) ;
		}
		
		double sum2 = 0 ;
		for( int i=1 ; i<=7 ; i++ ) sum2 += b[24+i] * pow(0.5,i) ;
		
		int k = 10000000 ;
		int sum3 = sum2 * k ;
		
		k /= 10 ;
		int p[7] = {} ;
		for( int i=0 ; i<7 ; i++ ){
			p[i] = sum3 / k ;
			sum3 -= p[i]*k ;
			k /= 10 ;
		}
		
		cout << sum << '.' ;
		cout << p[0] ;
		for( int i=1 ; i<7 ; i++ ){
			bool t = false ;
			if( p[i] ) t = true ;
			else {
				for( int j=i+1 ; j<7 ; j++ ){
					if( p[j] ) t = true ;
				}
			}
			if( t ) cout << p[i] ;
		}
		cout << endl ;
	}
}

Measured memory_bytes: 1248
#include <iostream>
using namespace std;
int p, q, x, y, a, b, i;
string s;
int main() {
	cin>>p>>q>>x>>y;
	a = x-p, b = y-q;
	for(i=0; i<b; i++) s+='U';
	for(i=0; i<a; i++) s+='R';
	for(i=0; i<b; i++) s+='D';
	for(i=0; i<a; i++) s+='L';
	s+='L';
	for(i=0; i<=b; i++) s+='U';
	for(i=0; i<=a; i++) s+='R';
	s+="DR";
	for(i=0; i<=b; i++) s+='D';
	for(i=0; i<=a; i++) s+='L';
	s+="U";
	cout<<s;
	return 0;
}

Measured memory_bytes: 256
#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
#define X first
#define Y second
#define all(x) x.begin(), x.end()
#define ordered_set tree<int, null_type,less<int>, 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__) << "] "

const int MOD = (int)1e9 + 7;
const int MX = (int)1e5 + 10;

void add_self(int &x, int y, int md = MOD){x += y; if(x >= md) x -= md;}
void sub_self(int &x, int y, int md = MOD){x -= y; if(x < 0) x += md;}
void mul_self(int &x, int y, int md = MOD){x = x * 1LL * y % md;}
inline int mul(int x, int y, int md = MOD){return x * 1LL * y % md;}
inline int add(int x, int y, int md = MOD){x += y; if(x >= md) x -= md; return x;}
inline int sub(int x, int y, int md = MOD){x -= y; if(x < 0) x += md; return x;}

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

vector<int> read(int n, int k){
	vector<int> vec(n);
	for(int i = 0; i < k; ++i) cin >> vec[i];
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	for(int i = k; i < n; ++i)
		vec[i] = (a * 1ll * vec[i - 2] + b * 1ll * vec[i - 1] + c) % d;
	return vec;
}

int dp[669][2002];

int check(int idx, int sum){
	if(sum == 0) return 1;
	int& res = dp[idx][sum];
	if(res != -1) return res;
	res = 0;
	for(int i = 3; i <= sum; ++i){
		add_self(res, check(idx + 1, sum - i));
	}
	return res;
}

void solve(){

	int s;
	cin >> s;
	memset(dp, 0xff, sizeof dp);
	cout << check(0, s) << '\n';

	return;
}

int main(){

	cin.tie(0); cout.tie(0);
	ios_base::sync_with_stdio(0);

	// freopen("input.in", "r", stdin);
	// freopen("output.out", "w", stdout);

	int t;
	t = 1;
	// cin >> t;
	// pre();
	for(int i = 1; i <= t; ++i){
		// cout << "Case #" << i << ": ";
		solve();
		// cout << '\n';
		// cout << endl;
	}

	return 0;
}


Measured memory_bytes: 8884
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)

int main(){
    string s;
    cin >> s;
    string ans="";
    rep(i,s.size()){
        if(i%2==0) ans += s[i];
    }
    cout << ans << endl;
}


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

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	ll x; cin >> x;
	ll ans = 0;
	for(ll i = sqrt(x); i > 0; i--) {
		if(x % i == 0) {
			ll tmp = x/i;
			while(tmp > 0)
				ans++, tmp /= 10;
			break;
		}
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define itn int
#define nibu(K,x) binary_search(K.begin(),K.end(),x)
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) x.begin(),x.end()
#define sz(x) x.size()
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define out(x) cout<<x<<endl
#define put(x) out(x)
#define in(x) cin>>x
#define maxx(a,b,c) max(a,max(b,c))
#define minn(a,b,c) min(a,min(b,c))
using ll = long long;
using vl = vector<ll>;
using vs = vector<string>;
const double pi = 3.14159265358979;
const ll mod = 1000000007;

int main() {
int N;
  in(N);
vl A(N,0);
  rep(i,N-1){
   int a;
    in(a);
    A[a-1]++;
  }
  rep(i,N)out(A[i]);
  
  
}


Measured memory_bytes: 4780
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    double pi = std::atan(1.0) * 4;
    double a, b, x;
    std::cin >> a >> b >> x;

    std::cout << std::fixed << std::setprecision(10);
    if (a * a * b < 2 * x) {
        std::cerr << "asdf" << std::endl;
        std::cout << std::atan(2.0 * (a * a * b - x) / a / a / a) * 180 / pi << std::endl;
    } else {
        std::cout << std::atan(a * b * b / 2.0 / x) * 180 / pi << std::endl;
    }

    return 0;
}


Measured memory_bytes: 256
N = int(input())
W = [input() for _ in range(N)]
checked = []

pre = W[0][0]
ok = True
for w in W:
    if w[0] != pre[-1] or w in checked:
        ok = False
        break
    pre = w
    checked.append(w)

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

Measured memory_bytes: 3064
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author amotoma3
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            long[] a = in.nextLongArray(4);
            long n = in.nextLong();

            for (int i = 0; i < 3; i++) {
                a[i + 1] = Math.min(a[i + 1], 2 * a[i]);
            }

            out.println(a[3] * (n / 2) + a[2] * (n % 2));
        }

    }

    static class InputReader {
        BufferedReader in;
        StringTokenizer tok;

        public String nextString() {
            while (!tok.hasMoreTokens()) {
                try {
                    tok = new StringTokenizer(in.readLine(), " ");
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
            }
            return tok.nextToken();
        }

        public long nextLong() {
            return Long.parseLong(nextString());
        }

        public long[] nextLongArray(int n) {
            long[] res = new long[n];
            for (int i = 0; i < n; i++) {
                res[i] = nextLong();
            }
            return res;
        }

        public InputReader(InputStream inputStream) {
            in = new BufferedReader(new InputStreamReader(inputStream));
            tok = new StringTokenizer("");
        }

    }
}



Measured memory_bytes: 21588
#include<stdio.h>

int main(){
		long n,m;
		scanf("%ld%ld",&n,&m);
		if(n==m/2){
				printf("%ld",n);
				return 0;
		}
		if(n>m/2){
				printf("%ld",m/2);
				return 0;
		}
		if(n<m/2){
				long i=(m-n*2)/4;
				printf("%ld",n+i);
				return 0;
		}
		return 0;
}


Measured memory_bytes: 128
// Kyoto University Programming Contest 2016
// B - 作問委員会 / Problem Committee

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#define MAX_N 10000
#define MAX_K 26
#define MAX_C MAX_N
#define MAX_P 10
#define MAX_V (MAX_N + MAX_K + MAX_C + 2)
#define S (MAX_N + MAX_K + MAX_C + 0)
#define T (MAX_N + MAX_K + MAX_C + 1)
#define INF 100000000
using namespace std;


struct edge{
  int to, cap, rev; // 行き先, 容量, 逆辺番号
};

class Graph{
public:
  void add_edge(int from, int to, int cap);
  int max_flow(int s, int t);
private:
  void bfs(int s);
  int dfs(int v, int t, int f);
private:
  vector<edge> g[MAX_V];
  int level[MAX_V];
  int iter[MAX_V];
};

void Graph::add_edge(int from, int to, int cap){
  g[from].push_back((edge){to, cap, (int)g[to].size()});
  g[to].push_back((edge){from, 0, (int)g[from].size() - 1});
  return;
}

int Graph::max_flow(int s, int t){
  int f;
  int flow = 0;

  while(true){
    bfs(s);
    if(level[t] < 0){
      break;
    }
    memset(iter, 0, sizeof(iter));
    while((f = dfs(s, t, INF)) > 0){
      flow += f;
    }
  }
  return flow;
}

void Graph::bfs(int s){
  queue<int> que;
  int v;
  int i;

  memset(level, -1, sizeof(level));
  level[s] = 0;
  que.push(s);
  while(!que.empty()){
    v = que.front();
    que.pop();
    for(i = 0; i < (int)g[v].size(); i++){
      if(g[v][i].cap > 0 && level[g[v][i].to] < 0){
        level[g[v][i].to] = level[v] + 1;
        que.push(g[v][i].to);
      }
    }
  }
  return;
}

int Graph::dfs(int v, int t, int f){
  int d;

  if(v == t){
    return f;
  }
  for( ; iter[v] < (int)g[v].size(); iter[v]++){
    edge &e = g[v][iter[v]];
    if(e.cap > 0 && level[v] < level[e.to]){
      d = dfs(e.to, t, min(f, e.cap));
      if(d > 0){
        e.cap -= d;
        g[e.to][e.rev].cap += d;
        return d;
      }
    }
  }
  return 0;
}


int N, K, C;
int initial[MAX_K];

int main() {

  int l, r, m, sum_initial;
  char buff[MAX_P + 2];

  scanf("%d%d", &N, &K);
  C = N / K;
  memset(initial, 0, sizeof(initial));
  for (int i = 0; i < N; i++) {
    scanf("%s", buff);
    initial[buff[0] - 'A']++;
  }

  l = 0; r = C + 1;
  while (r - l > 1) {
    Graph G;

    m = (l + r) / 2;
    for (int i = 0; i < m; i++) {
      G.add_edge(S, N + MAX_K + i, K);
    }
    for (int i = 0; i < m; i++) {
      for (int j = 0; j < MAX_K; j++) {
        G.add_edge(N + MAX_K + i, N + j, 1);
      }
    }
    sum_initial = 0;
    for (int i = 0; i < MAX_K; i++) {
      for (int j = sum_initial; j < sum_initial + initial[i]; j++) {
        G.add_edge(N + i, j, 1);
      }
      sum_initial += initial[i];
    }
    for (int i = 0; i < N; i++) {
      G.add_edge(i, T, 1);
    }

    if (G.max_flow(S, T) == K * m) {
      l = m;
    } else {
      r = m;
    }
  }

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

  return 0;

}




Measured memory_bytes: 9704
#include<iostream>
#include<algorithm>
#include<map>

using namespace std;

int main(){
  int n;
  cin >> n;
  map<int,int> mp;
  for(int i=0;i<n;i++){
    int p;
    cin >> p;
    mp[p]++;
  }
  int m;
  cin >> m;
  for(int i=0;i<m;i++){
    int p;
    cin >> p;
    if(mp.count(p)==0 || mp[p]==0){
      cout << "NO" << endl;
      return 0;
    }else {
      mp[p]--;
    }
  }
  cout << "YES" << endl;
  return 0;
}


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

using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define M 1000000007

ll powll(ll x, ll y) {
    ll re=1;
    rep(i, y) {
        re = re * x % M;
    }
    return re;
}


int main() {

    int n;
    cin >> n;
    
    ll out = 0;
    ll total = 0;

    out = powll(10, n) - (powll(9, n) * 2) + powll(8, n);
    out = out % M;
    out = (out + M) % M;

    cout << out;

    return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
template<typename T> using v = vector<T>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template<typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto& i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

template<class T>
void dump_debug(T list) {
#ifdef MY_DEBUG
    each(e, list) cout << e << " ";
    printf("\n");
#endif
}

inline ll inl() {
    ll x;
    cin >> x;
    return x;
}

inline string ins() {
    string x;
    cin >> x;
    return x;
}

/* ------------- ANSWER ------------- */
/* ---------------------------------- */

ll c_d(ll n) {
    ll ret = 0;
    while (n > 0) n /= 10, ret++;
    return ret;
}

int main() {
#ifdef MY_DEBUG
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
    while (true) {
#pragma clang diagnostic pop
#endif
        ll n;
        cin >> n;

        ll ans = 0;
        for (long long i = 1; i <= n; ++i) {
            if (c_d(i) % 2 == 1) ans++;
        }
        cout << ans << endl;
#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0;i<static_cast<int>(n);++i)
#define per(i, n) for(int i=static_cast<int>(n)-1;i>=0;--i)
#define eee(a) (cerr<<(#a)<<": "<<(a)<<'\n');
#define ppp(a) (cout<<(a)<<'\n'); 
#define cop(a) for(auto x:(a)){cerr<<(x)<<'\n';}
using ll = long long;
constexpr int dx[4]={1,0,-1,0};
constexpr int dy[4]={0,1,0,-1};
constexpr ll MOD = 1e9+7;
constexpr ll Mod = 998244353;
constexpr int INF = 1e9;
constexpr ll LINF = 1e18;
constexpr double phi = (1+sqrt(5))/2;
constexpr double pi = 3.14159265358979323846264338327950288;
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline ll inverse(ll n,ll m=MOD){ll a=n,b=m,x=1,y=0;while(b){ll t=a/b;a-=t*b;swap(a,b);x-=t*y;swap(x,y);}return (a%m+m)%m;}
inline void Yes(){puts("Yes");}
inline void No(){puts("No");}
inline void Judge(bool b){b?Yes():No();}
inline void YES(){puts("YES");}
inline void NO(){puts("NO");}
inline void JUDGE(bool b){b?YES():NO();}
inline ll powmod(ll b, ll e, ll m=MOD){ll r=1;while(e>0){if(e&1)r=(r%m)*(b%m)%m;b=(b%m)*(b%m)%m;e>>=1;}return r;}
inline double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));}
inline double d2r(double d){return d*pi/180;}
inline double r2d(double r){return r*180/pi;}
template<class T>inline bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(b<a){a=b;return 1;}return 0;}
template<typename T1,typename T2>ostream& operator<<(ostream& s,const pair<T1, T2>& p){return s <<"("<<p.first<<", "<<p.second<<")";}
template<typename T> ostream& operator<<(ostream& s,const vector<T>& v){s<<'[';for(size_t i=0;i<v.size();++i){s<<v[i];if(i<v.size()-1)s<<", ";}s<<']';return s;}

int main(){
    cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);
    
    int a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;


    int ans = 0;
    if(x <= y){
        ans = 2*c*x;
        ans += min(b*(y-x), 2*c*(y-x));
    }else{
        ans = 2*c*y;
        ans += min(a*(x-y), 2*c*(x-y));
    }
    ans = min(ans, a*x+b*y);
    cout << ans << '\n';
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PI;
typedef pair<ll, ll> PL;
typedef map<int, int> MI;
typedef set<int> SI;
#define VV(T) vector<vector< T > >
#define dump(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl

#define rep(i, n) REP(i, 0, n)                              // 0, 1, ..., n-1
#define REP(i, x, n) for(int i = x; i < n; i++)             // x, x + 1, ..., n-1
#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(v) (v).begin() , (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define COUT(x) cout << (x) << endl

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


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

    int n, m; cin >> n >> m;
    vector<vector<int>> s(m, vector<int>(10, 0));
    vector<int> p(m);
    rep(i, m) {
        int k; cin >> k;
        rep(j, k) cin >> s[i][j];
    }
    rep(i, m) cin >> p[i];

    int ans = 0;
    for(int bit = 0; bit < (1<<n); bit++) {
        int flg = 1;
        for(int i = 0; i < m; i++) {
            int cnt = 0;
            for(int j = 0; j < s[i].size(); j++) {
                if(bit & (1<<s[i][j])) cnt++;
            }
            if(cnt % 2 != p[i]) flg = 0;
        }
        if(flg) ans++;
    }
    cout << ans << endl;
}


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

int main()
{
    map<string,int> m;                  //通常のmapはkeyに対して1つの値を持つ。multimapになると、keyにいくつもの値を持たせることが出来る。
    int n, q, x;
    string k;

    cin >> n;

    for( int i = 0; i < n; i++ )
    {
        cin >> q >> k;

        if( q == 0 )
        {
            cin >> x;
            m[k] = x;
        }
        else if( q == 1 )
            cout << m[k] << endl;
        else
            m[k] = 0;
    }
    return 0;
}



Measured memory_bytes: 27744
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define fst first
#define secnd second
#define PB push_back
#define MP make_pair
#define LL long long
#define uLL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

using namespace std;

typedef pair<int, int> point_t;

vector<point_t> points(8);

int main(void){
  int H,W;
  cin>>H>>W;
  vector<string> meiro = vector<string>(H+3,string(W+3,'0'));
  vector<string> memo = vector<string>(H+3,string(W+3,'0'));
  

  FORQ(i,1,H){
    cin>>meiro[i];
  }
  FORQ(i,0,H+2){
    meiro[i].insert(meiro[i].begin() , '0');
  }


  points[0]=make_pair(-1,-1);
  points[1]=make_pair(0,-1);
  points[2]=make_pair(1,-1);
  points[3]=make_pair(1,0);
  points[4]=make_pair(1,1);
  points[5]=make_pair(0,1);
  points[6]=make_pair(-1,1);
  points[7]=make_pair(-1,0);
  
  FORQ(i,1,H){
    FORQ(j,1,W){
      if(meiro[i][j]=='#'){
        memo[i][j]='#';
      }
    }
  }

 
  FORQ(i,1,H){
    FORQ(j,1,W){
      if(meiro[i][j]=='#'){
        for(auto x:points){
          if(meiro[i+x.first][j+x.second]!='#'){
            memo[i+x.first][j+x.second]+=1;
          }
        }
      }
    }
  }

  FORQ(i,1,H){
    FORQ(j,1,W){
      cout<<memo[i][j];
    }
    cout<<endl;
  }
  
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define double long double
#define INF 1e18
using namespace std;
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) a = b;
  return a > b;
}
template<class T> inline bool chmax(T&a, T b) {
  if (a < b) a = b;
  return a < b;
}

signed main() {
  int E, Y;
  cin >> E >> Y;
  int a[4] = { 1989, 1926, 1912, 1868 };
  char b[4] = { 'H', 'S', 'T', 'M' };
  if (E == 0) {
    for (int i = 0; i < 4; i++) {
      if (Y-a[i]+1 > 0) {
        cout << b[i] << Y-a[i]+1 << endl;
        break;
      }
    }
  } else {
    cout << Y+a[4-E]-1 << endl;
  }
}



Measured memory_bytes: 3104
def color rate
	return -1 if rate>=3200
	return rate / 400
end

n = gets.to_i
a = gets.split.map(&:to_i).map{|r| color r}
free = a.count(-1)
colors = a.reject{|x|x==-1}.uniq.size
puts "#{[colors, 1].max} #{colors+free}"

Measured memory_bytes: 1788
n=int(input())
A=input().split()
B=A[::]

flag=1
while flag:
  flag=0
  for i in range(n-1,0,-1):
    if int(A[i-1][1])>int(A[i][1]):
      A[i-1],A[i]=A[i],A[i-1]
      flag=1
print(*A)
print("Stable")

for i in range(n-1):
  minj=i
  for j in range(i,n):
    if int(B[minj][1])>int(B[j][1]):
      minj=j
  if minj!=i:
    B[i],B[minj]=B[minj],B[i]
print(*B)
if A==B:
  print("Stable")
else:
  print("Not stable")


Measured memory_bytes: 5616
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st;
        PrintWriter pw = new PrintWriter(System.out);
        
        try {
            int n = Integer.parseInt(br.readLine());
            int[] a = new int[n];
            st = new StringTokenizer(br.readLine());
            int xor = 0;
            for(int i=0 ; i<n ; i++) {
                a[i] = Integer.parseInt(st.nextToken());
                xor ^= a[i];
            }

            for(int i=0 ; i<n ; i++) {
                pw.print((a[i]^xor) + " ");
            }

        }
        finally {
            pw.flush();
            pw.close();
        }
    }
}


Measured memory_bytes: 59900
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define debug(var) do{cout << #var << " : "; view(var);}while(0)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
template<class T> void view(T e) {cout << e << endl;}
template<class T> void view(const vector<T> &v) {for(const auto &e : v){cout << e << " ";} cout << endl;}
template<class T> void view(const vector<vector<T>> &vv) {for(const auto &v : vv){view(v);}}
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1<<30;
const ll inf_l = 1LL<<61;
const int MAX = 20000;

int main() {
    int n, ma, mb; cin >> n >> ma >> mb;
    vint a_l, a_r, b_l, b_r, c_l, c_r;
    rep(i,n) {
        int a, b, c; cin >> a >> b >> c;
        if (i < n / 2) {
            a_l.push_back(a);
            b_l.push_back(b);
            c_l.push_back(c);
        } else {
            a_r.push_back(a);
            b_r.push_back(b);
            c_r.push_back(c);
        }
    }
    int n_l = a_l.size();
    int n_r = a_r.size();
    map<int,int> mp;
    int ans = inf;
    rep(i,1<<(n_l)) {
        int weight = 0, value = 0;
        rep(j,n_l) {
            if (i >> j & 1) {
                weight += ma * b_l[j] - mb * a_l[j];
                value += c_l[j];
            }
        }
        if (weight == 0 && value != 0) chmin(ans, value);
        if (!mp.count(weight)) mp[weight] = value;
        else if (weight != 0) chmin(mp[weight], value);
    }
    rep(i,1<<(n_r)) {
        int weight = 0, value = 0;
        rep(j,n_r) {
            if (i >> j & 1) {
                weight += mb * a_r[j] - ma * b_r[j];
                value += c_r[j];
            }
        }
        if (!mp.count(weight)) continue;
        if (weight == 0 && value != 0) chmin(ans, value);
        if (weight != 0) chmin(ans, mp[weight] + value);
    }
    printf("%d\n", ans == inf ? -1 : ans);
}

Measured memory_bytes: 3732
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7/*998244353*/;
const ll INF = 1LL << 60;
ll mod_pow(ll, ll, ll); ll mod_fact(ll, ll); ll mod_inv(ll, ll); ll gcd(ll, ll); ll lcm(ll, ll);
//
int main(){
    int n, m;
    cin >> n >> m;
    vector<bool> broken(n + 1);
    vector<int> way(n + 1);
    for(int i = 0; i < m; i++){
        int t;
        cin >> t;
        broken[t] = true;
    }
    way[0] = 1;
    if(!broken[1]) way[1] = 1;
    for(int i = 2; i <= n; i++){
        if(!broken[i]) way[i] = (way[i - 1] + way[i - 2]) % MOD;
    }
    cout << way[n];
}

Measured memory_bytes: 640
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <random>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
typedef vector<int> vi;
typedef long long ll;
typedef pair<int, int> pii;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod = 1000000007;
int rnd(int x) { return mrand() % x; }
ll powmod(ll a, ll b) { ll res = 1; a %= mod; assert(b >= 0); for (; b; b >>= 1) { if (b & 1)res = res * a % mod; a = a * a % mod; }return res; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
// head

int t;

int main()
{
	ios::sync_with_stdio(false);
#ifdef RG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ll x;
	cin >> x;
	ll a = x / 500;
	ll b = x % 500;
	b = b / 5;
	cout << a * 1000 + b * 5 << endl;
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-falign-jumps")
#pragma GCC optimize("-falign-loops")
#pragma GCC optimize("-falign-labels")
#pragma GCC optimize("-fdevirtualize")
#pragma GCC optimize("-fcaller-saves")
#pragma GCC optimize("-fcrossjumping")
#pragma GCC optimize("-fthread-jumps")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-fwhole-program")
#pragma GCC optimize("-freorder-blocks")
#pragma GCC optimize("-fschedule-insns")
#pragma GCC optimize("inline-functions")
#pragma GCC optimize("-ftree-tail-merge")
#pragma GCC optimize("-fschedule-insns2")
#pragma GCC optimize("-fstrict-aliasing")
#pragma GCC optimize("-fstrict-overflow")
#pragma GCC optimize("-falign-functions")
#pragma GCC optimize("-fcse-skip-blocks")
#pragma GCC optimize("-fcse-follow-jumps")
#pragma GCC optimize("-fsched-interblock")
#pragma GCC optimize("-fpartial-inlining")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("-freorder-functions")
#pragma GCC optimize("-findirect-inlining")
#pragma GCC optimize("-fhoist-adjacent-loads")
#pragma GCC optimize("-frerun-cse-after-loop")
#pragma GCC optimize("inline-small-functions")
#pragma GCC optimize("-finline-small-functions")
#pragma GCC optimize("-ftree-switch-conversion")
#pragma GCC optimize("-foptimize-sibling-calls")
#pragma GCC optimize("-fexpensive-optimizations")
#pragma GCC optimize("-funsafe-loop-optimizations")
#pragma GCC optimize("inline-functions-called-once")
#pragma GCC optimize("-fdelete-null-pointer-checks")
#include <bits/stdc++.h>
using namespace std;
inline int read()
{
   int s=0,w=1;
   char ch=getchar();
   while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
   while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
   return s*w;
}
inline void write(int x)
{
    if(x<0)
	{
    	putchar('-');
		x=-x;
	}
    if(x>9)
		write(x/10);
    putchar(x%10+'0');
}
int main()
{
	ios::sync_with_stdio(false);
	int a,b;
	a=read();
	b=read();
	write((a+b)%24);
	puts("");
	return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split(' ')))
count = 0
tmp_arr = []
inc = -1
for i, a in enumerate(A):
    if N-1 == i:
        count += 1
    if len(tmp_arr) == 0:
        tmp_arr.append(a)
        continue
    if inc == 0 and a > tmp_arr[-1]:
        tmp_arr = []
        inc = -1
        count += 1
    elif inc == 1 and a < tmp_arr[-1]:
        tmp_arr = []
        inc = -1
        count += 1
    else:
        if a > tmp_arr[-1]:
            inc = 1
        elif a < tmp_arr[-1]:
            inc = 0
    tmp_arr.append(a)
print(count)

Measured memory_bytes: 14436
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#define LL long long
using namespace std;
const LL mod=1e9+7;
LL n,k,f[2010][2010];
LL fac[4100010],inv[4100010];
void pre()
{
	fac[0]=fac[1]=inv[0]=inv[1]=1;
	for(LL i=2;i<=4100000;i++) fac[i]=fac[i-1]*i%mod,inv[i]=(mod-mod/i)*inv[mod%i]%mod;
	for(LL i=2;i<=4100000;i++) inv[i]=inv[i-1]*inv[i]%mod;
}
LL C(LL m,LL n) {return fac[m]*inv[m-n]%mod*inv[n]%mod;}
LL get(LL k,LL n)
{
	return C(k+n,n);
}//k->n+1
int main()
{
	pre();
	scanf("%lld %lld",&n,&k);
	if(k==1) return puts("1"),0;
	f[1][0]=1;
	for(LL i=1;i<=n;i++)
		for(LL j=0;j<=i;j++)
		{
			if(j<i) f[i][j+1]=(f[i][j+1]+f[i][j])%mod;
			if(i<n) (f[i+1][j]+=f[i][j]*get(k-2,i*(k-1)+j))%=mod;
		}
	printf("%lld",f[n][n]*fac[n]%mod);
}

Measured memory_bytes: 95744
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
const ll MOD = 1000000007;
const ll INF = 1000000000000000;
#define all(v) v.begin(), v.end()


int main(){
  ll N,K,k=0,m=0,ans=1;
  cin >> N >> K;
  vector<ll> A(N);
  rep(i,N){
    cin >> A.at(i);
    if(A.at(i)<0) k++;
    if(A.at(i)==0) m++;
  }
  if(K+m>N){
    cout << 0 << endl;
    return 0;
  }else if(K==N){
    rep(i,N){
      if(A.at(i)<0) ans*=(MOD+A.at(i));
      else ans*=A.at(i);
      ans%=MOD;
    }
    cout << ans << endl;
    return 0;
  }else if(k+m==N&&K%2==1){
    sort(all(A));
    reverse(all(A));
    rep(i,K){
      ans*=(MOD+A.at(i));
      ans%=MOD;
    }
    cout << ans << endl;
    return 0;
  }else{
    vector<ll> B,C;
    rep(i,N){
      if(A.at(i)>=0) B.push_back(A.at(i));
      else C.push_back(A.at(i));
    }
    if(B.size()!=0){
      sort(all(B));
      reverse(all(B));
    }
    if(C.size()!=0){
      sort(all(C));
    }
    if(K%2==1){
      ans=B.at(0);
      ll t=1,s=0;
      rep(i,K/2){
        if(t>=B.size()-1||B.size()==0){
          ans*=(C.at(s)*C.at(s+1))%MOD;
          s+=2;
          ans%=MOD;
        }else if(s>=C.size()-1||C.size()==0){
          ans*=(B.at(t)*B.at(t+1))%MOD;
          t+=2;
          ans%=MOD;
        }else{
          if(B.at(t)*B.at(t+1)>C.at(s)*C.at(s+1)){
            ans*=(B.at(t)*B.at(t+1))%MOD;
            t+=2;
            ans%=MOD;
          }else{
            ans*=(C.at(s)*C.at(s+1))%MOD;
            s+=2;
            ans%=MOD;
          }
        }
      }
    }else{
      ans=1;
      ll t=0,s=0;
      rep(i,K/2){
        if(t>=B.size()-1||B.size()==0){
          ans*=(C.at(s)*C.at(s+1))%MOD;
          s+=2;
          ans%=MOD;
        }else if(s>=C.size()-1||C.size()==0){
          ans*=(B.at(t)*B.at(t+1))%MOD;
          t+=2;
          ans%=MOD;
        }else{
          if(B.at(t)*B.at(t+1)>C.at(s)*C.at(s+1)){
            ans*=(B.at(t)*B.at(t+1))%MOD;
            t+=2;
            ans%=MOD;
          }else{
            ans*=(C.at(s)*C.at(s+1))%MOD;
            s+=2;
            ans%=MOD;
          }
        }
      }
      
    }
    cout << ans << endl;
    return 0;
  }
      
}

Measured memory_bytes: 6836
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, M, X = mapint()
As = set(list(mapint()))
to_zero = 0
for i in range(X, 0, -1):
    if i in As:
        to_zero += 1

to_N = 0
for i in range(X, N+1):
    if i in As:
        to_N += 1
print(min(to_zero, to_N))

Measured memory_bytes: 61832
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;
    
#define rep(i,n) for(ll (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(ll i=(a);i<(b);i++)
#define rrrep(i,a,b) for(ll i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 
#define U_MAP unordered_map<ll,ll>
#define pq priority_queue<ll>
#define rpq priority_queue<ll,vector<ll>,greater<ll>>
#define p_b push_back
    
ll n,cnt,ans,a[ohara],b[ohara],c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k,q;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
P p[ohara];
    
//------ Believe yourself as a genius!!!!!! ------
    
int main(void){
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>n;
    rep(i,n){
        cin>>a[i]>>b[i];
        p[i]=m_p(a[i]+b[i],i);
    }
    sort(p,p+n);
    reverse(p,p+n);
    rep(i,n){
        if(i%2==0)ans+=a[p[i].se];
        else ans-=b[p[i].se];
    }
    Cout(ans);
    return 0;
}

Measured memory_bytes: 7936
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
int main(){
  ll n;
  cin>>n;
  vll a(n);
  rep(i,n) cin>>a[i];
  rep(i,n){
    a[i]=a[i]-i-1;
  }
  sort(all(a));
  ll ans=0;
  if(n%2==0){
   int h=(a[n/2]+a[n/2-1])/2;
    rep(i,n){
      ans+=abs(a[i]-h);
    }
  }
  else{
    rep(i,n){
      ans+=abs(a[i]-a[n/2]);
    }
    
  }
  COUT(ans);
}


Measured memory_bytes: 1792
A, B, C, X, Y = map(int, input().split())

min_value = X if (X < Y) else Y

total = 0
if (A + B > C * 2):
  total = C * 2 * min_value
else:
  total = (A + B) * min_value

current_X = X - min_value
current_Y = Y - min_value
if(current_X != 0):
  if(A > C * 2):
    total += current_X * C * 2
  else:
    total += current_X * A
else:
  if(B > C * 2):
    total += current_Y * C * 2
  else:
    total += current_Y * B
print(total)

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

int main () {
  int n; cin >> n;
  
  int a[1005], even =0;
  for (int i=0; i<n; i++) {
    cin >>a[i];
  }
  for (int i=0; i<n; i++) {
    if (a[i] %2 == 0 && a[i] %3 != 0 && a[i] %5 != 0 )
    {
      cout << "DENIED" << endl;
      return 0;
    }
  }
      cout << "APPROVED" << endl;
}

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

using namespace std;

typedef long long ll;

int n, m;
int a[17][17];

bool ppf(int x) {
  int r = sqrt(x);
  return (r * r == x);
}

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

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

  int ans = 0;
  for (int i1 = 1; i1 <= n; i1++) {
    for (int i2 = i1 + 1; i2 <= n; i2++) {
      int sum = 0;
      for (int j = 1; j <= m; j++) {
        int dif = a[i1][j] - a[i2][j];
        sum += dif * dif;
      }
      ans += ppf(sum);
    }
  }

  cout << ans << "\n";

  return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
 
K,S=map(int,input().split())
 
z = list(range(K+1))
ans = []
 
for i in z:
  s_z = S - i
  if s_z < 0:
    pass
  elif K < s_z:
    if (K + 1) > (s_z - K):
      ans.extend([2*K - s_z + 1])
  else:
    ans.extend([s_z + 1])
 
print(sum(ans))

Measured memory_bytes: 3188
import bisect
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
def main():
    N = int(input())
    l = [0] * (N+1)
    for i in range(1, N+1):
        a = prime_factorize(i)
        for j in a:
            l[j] += 1
    l = l[2:]
    l.sort()
    r = 0
    a = bisect.bisect_left(l, 2)
    b = bisect.bisect_left(l, 4)
    c = bisect.bisect_left(l, 14)
    d = bisect.bisect_left(l, 24)
    e = bisect.bisect_left(l, 74)
    if e < N-1:
        r += N - e - 1
    if d < N-1:
        r += (N - d - 1) * (N - a - 2)
    if c < N-1:
        r += (N - c - 1) * (N - b - 2)
    if b < N-2:
        r += (N - a - 3) * (N - b - 1) * (N - b - 2) // 2
    print(r)
main()


Measured memory_bytes: 3064
#include <iostream>  
#include <cstdio>  
#include <cstring>  
#include <algorithm>  
  
using namespace std;  
const int maxn=2e5+100;  
int par[maxn],sum[maxn];  
int N,K,p,tot;  
  
void init(int n)  
{  
    for(int i=0;i<=n;i++)  
        par[i]=i;  
}  
  
int find(int x)  
{  
    if(par[x]==x)  
        return x;  
    return par[x]=find(par[x]);  
}  
void unit(int x,int y)  
{  
    int fx=find(x),fy=find(y);  
    if(fx!=fy)  
        par[fx]=fy;  
}  
bool same(int x,int y)  
{  
    return find(x)==find(y);  
}  
int main()  
{  
    while(~scanf("%d%d",&N,&K))  
    {  
        int ans=0;  
        memset(sum,0,sizeof(sum));  
        memset(par,0,sizeof(par));  
        tot=0;  
        init(N);  
        int t;  
        scanf("%d",&t);  
        sum[t]++;  
        p=t;  
        tot++;  
        for(int i=2;i<=N;i++)  
        {  
            scanf("%d",&t);  
            sum[t]++;  
            if(!same(t,p))  
            {  
                tot++;  
                unit(t,p);  
            }  
        }  
        sort(sum,sum+N+1);  
        if(tot<=K)  
            ans=0;  
        else  
        {  
            int cnt=tot-K;  
            int pos0=lower_bound(sum,sum+N+1,1)-sum;  
            while(cnt--)  
                ans+=sum[pos0++];         
        }  
        printf("%d\n",ans);  
    }  
    return 0;  
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
using namespace std;

long long H, W;

long long calc(long long h, long long w){
  long long p = INT_MAX, pp = 0;
  for(int i=w/3; i<=w/2; ++i){
    long long left_ar = i*h;
    long long right_ar = h*w - left_ar;
    if(abs(left_ar - right_ar) < p){
       p = abs(left_ar - right_ar);
       pp = left_ar;
    }
  }
  return pp;
}

int main(){
  ios_base::sync_with_stdio(false); 
  cin >> H >> W;
   if(H < W)
    swap(H, W);
  long long ar = H*W;
  long long res = 0;
  if(ar%3 != 0){
    res = INT_MAX;
    for(int i=H/3; i<=H/2; ++i){
      long long top_ar = i*W;
      long long left_ar = calc(H-i, W);
      long long  right_ar = H*W - (top_ar+left_ar);
      res = min(res, max({top_ar, left_ar, right_ar}) - min({top_ar, left_ar, right_ar}));
    }
    for(int i=W/3; i<=W/2; ++i){
      long long top_ar = i*H;
      long long left_ar = calc(W-i, H);
      long long right_ar = H*W - (top_ar+left_ar);
      res = min(res, max({top_ar, left_ar, right_ar}) - min({top_ar, left_ar, right_ar}));
    }
    for(int i=W/3; i<=W/2; ++i){
      long long left_ar = i*H;
      for(int j=i+W/3; j<=W; ++j){
        long long middle_ar = i*H;
        long long right_ar = ar - left_ar - middle_ar;
        res = min(res, max({left_ar, middle_ar, right_ar}) - min({left_ar, middle_ar, right_ar}));
      }
    }
    for(int i=H/3; i<=H/2; ++i){
        long long left_ar = i*W;
        for(int j=i+H/3; j<=H; ++j){
            long long middle_ar = i*W;
            long long right_ar = ar - left_ar - middle_ar;
            res = min(res, max({left_ar, middle_ar, right_ar}) - min({left_ar, middle_ar, right_ar}));
        }
    }
  }
  cout << res << "\n";
  return 0;
}


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

#define ll long long int

using namespace std;

ll inf=1e9+5;

unordered_map<ll,int> s;
vector<ll> pot;
ll h,w;
void goo(ll x)
{
    ll H,W;
    W=x%inf;
    x-=x%inf;
    H=x/inf;
    for(int i=H-2;i<=H;i++)
    {
        for(int j=W-2;j<=W;j++)
        {
            if(i>=1 && i<=h && j>=1 && j<=w)
            {
                ll res=(ll)i*inf+j;
                pot.push_back(res);
            }
        }
    }
}

int cnt[10];

void doo(ll x)
{
    ll H,W;
    W=x%inf;
    x-=x%inf;
    H=x/inf;
    int res=0;
    if(H>=1 && H+2<=h && W>=1 && W+2<=w)
    {
        for(int i=H;i<=H+2;i++)
        {
            for(int j=W;j<=W+2;j++)
            {
                ll akt=(ll)i*inf+j;
                res+=s[akt];
            }
        }
    }
    else return;
    cnt[res]++;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin>>h>>w;
    int n; cin>>n;
    vector<ll> a;
    for(int i=0;i<n;i++)
    {
        int x,y; cin>>x>>y;
        a.push_back((ll)x*inf+y);
        s[a[i]]=1;
    }
    for(int i=0;i<n;i++)
    {
        goo(a[i]);
    }
    sort(pot.begin(),pot.end());
    for(int i=0;i<pot.size();i++)
    {
        if(i==0 || pot[i]!=pot[i-1])
        {
            doo(pot[i]);
        }
    }
    ll cnn=0;
    for(int i=1;i<=9;i++)
    {
        cnn+=cnt[i];
    }
    cout<<(ll)(w-2)*(h-2)-cnn<<endl;
    for(int i=1;i<=9;i++) cout<<cnt[i]<<endl;
    return 0;
}


Measured memory_bytes: 126964