akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

int main() {
	int n, m, x, y;

	scanf("%d %d", &n, &m);
	vector<int> box(n + 1, 1);
	vector<bool> red(n + 1, 0);
	box[0] = 0;
	red[1] = true;
	for (int i = 0; i < m; i++) {
		scanf("%d %d", &x, &y);
		box[x]--;
		box[y]++;
		if (red[x]) {
			red[y] = true;
			if (box[x] == 0) {
				red[x] = false;
			}
		}
	}

	int ans = count(red.begin(), red.end(), true);
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 640
#include <iostream>

using namespace std;

int main() {
  int S, h, m, s;
  cin >> S;
  h = S / 3600;
  m = (S-h*3600) / 60;
  s = S-h*3600-m*60;
  cout << h << ":" << m << ":" << s << endl;
  return 0;
}

Measured memory_bytes: 1164
/*
 * author Puneet;
 */
#include <bits/stdc++.h>
#define ll long long int
using namespace std;


int main() {

    int a,b;
    cin>>a>>b;
    ll c=a*b;
    if(c%2==0)
        cout<<"Even";
    else
        cout<<"Odd";

    return 0;
} 

Measured memory_bytes: 892
while 1:
  n, x = map(int, input().split())
  if n == x == 0: break
  arr = []
  for a in range(1, n + 1):
    for b in range(1, n + 1):
      c = x - (a + b)
      if (a != b) & (b != c) & (c != a) & (c > 0) & (max(a, b, c) <= n):
        s = {a, b, c}
        if s not in arr: arr.append(s)
  print(len(arr))


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

typedef long long ll;

int n, m, ans, t;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> t;
        if (t >= m) {
            m = t;
            ++ans;
        }
    }
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define all(x) begin(x), end(x)
#define dbg(x) cerr << #x << " = " << x << endl
#define _ << ' ' <<
using namespace std;
using ll = long long;
using vi = vector<int>;


int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    string a, b;
    cin >> a >> b;
    if (a == b)
        cout << "EQUAL";
    else if (a.size() != b.size())
        cout << (a.size() < b.size() ? "LESS" : "GREATER");
    else
        cout << (a < b ? "LESS" : "GREATER");
}


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

int main() 
{
	int n,b,f,r,v,univ[4][3][10];

	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < 3; j++) {
			for (int k = 0; k < 10; k++) {
				univ[i][j][k] = 0;
			}
		}
	}

	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> b>>f>>r>>v;
		univ[b - 1][f - 1][r - 1] += v;
	}

	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < 3; j++) {
			for (int k = 0; k < 10; k++) {
				printf(" %d", univ[i][j][k]);
			}
			printf("\n");
		}

		if(i!=3) printf("####################\n");
	}

	return 0;
}

Measured memory_bytes: 3228
// problem: "https://atcoder.jp/contests/agc043/tasks/agc043_b"

#include<bits/stdc++.h>
#define p 2

using namespace std;

int nCr(int n,int r)
{
    while(n)
    {
        //cout<<n<<' '<<r<<' '<<(n&1)<<' '<<(r&1)<<'\n';
        if((n&1) == 0 && (r&1) == 1)
            return 0;

        n = n>>1;
        r = r>>1;
    }

    return 1;
}

int func(int n,string &s)
{
    int i;
    vector<int>V(n);

    bool one,two,three;
    one = two = three = 0;
    for(i=0;i!=n;i++)
    {
        if(s[i] == '1')
            one = 1;
        else if(s[i] == '2')
            two = 1;
        else
            three = 1;
    }

    if(two)
    {
//        cout<<"Entered two:\n";

        for(i=0;i!=n;i++)
            V[i] = (s[i]-'1')%p;

        int S = 0;
        for(i=0;i!=n;i++)
            if(V[i])
            {
                S = (S + nCr(n-1,i))%p;
//                cout<<S<<'\n';
            }


        if(S)
            return 1;
        else
            return 0;
    }

    for(i=0;i!=n;i++)
    {
        if(s[i] == '1')
            V[i] = 0;
        else
            V[i] = 1;
    }

    int S = 0;
    for(i=0;i!=n;i++)
        if(V[i])
            S = (S + nCr(n-1,i))%p;

    if(S)
        return 2;

    return 0;
}

int main()
{
    int n;
    string s;
    cin>>n>>s;

    cout<<func(n,s)<<'\n';        // define

//    cout<<nCr(9,0)<<' '<<nCr(9,6)<<' '<<nCr(9,9);
    return 0;
}


Measured memory_bytes: 5252
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> t(n + 2), v(n + 2), u(n + 2);
    for (int i = 1; i <= n; i++) {
        cin >> t[i];
    }
    for (int i = 1; i <= n; i++) {
        cin >> v[i];
    }
    u = v;
    debug(u);
    for (int i = 1; i <= n; i++) {
        u[i] = min(u[i], u[i + 1]);
        for (int j = i; j >= 1; j--) {
            if (abs(u[j] - u[j - 1]) <= t[j]) {
                break;
            }
            if (u[j - 1] + t[j] < u[j]) {
                u[j] = u[j - 1] + t[j];
                break;
            }
            u[j - 1] = u[j] + t[j];
        }
    }
    debug(u);
    double ans = 0;
    for (int i = 1; i <= n; i++) {
        int v0 = u[i - 1];
        int v1 = u[i];
        if (v0 > v1) {
            swap(v0, v1);
        }
        double mv = min((double)v[i], (t[i] + v0 + v1) * 0.5);
        ans += t[i] * v0;
        ans += (mv - v0) * (mv - v0) * 0.5;
        ans += (mv - v0 + v1 - v0) * (mv - v1) * 0.5;
        ans += (mv - v0) * max(0.0, t[i] - (mv - v1) - (mv - v0));
    }
    cout << fixed << setprecision(10);
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3820
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
ll _sieve_size, n;
ll vis[10000011];
bitset<10000010> bs;
std::vector<ll> primes;
void sieve(ll upperbound) {
  _sieve_size = upperbound + 1;
  bs.set();
  bs[0] = bs[1] = 0;
  for (ll i = 2; i <= _sieve_size; i++)
    if (bs[i]) {
      for (ll j = i * i; j <= _sieve_size; j += i)
        bs[j] = 0;
      primes.push_back((ll)i);
    }
}

int main() {
  srand(time(0));
  sieve(55556);
  std::cin >> n;
  int i = 0;
  while (n) {
    if(primes[i]%5 == 1){
      std::cout << primes[i] << ' ';
      --n;
    }
    i++;
  }
}


Measured memory_bytes: 1536
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using Pair = pair<int64_t, int64_t>;
constexpr int64_t kInf = INT64_MAX / 2L;

// std::cout << std::setprecision(20) << 1.1 << endl;

const int64_t kMod = 1000000007LL;
// const int64_t kMod = 998244353LL;
struct Mint {
  int64_t value;
  Mint(int64_t value = 0LL) : value((value % kMod + kMod) % kMod) {}
  Mint operator-() const {
    return Mint(-value);
  }
  Mint &operator+=(const Mint rhs) {
    if ((value += rhs.value) >= kMod) {
      value -= kMod;
    }
    return *this;
  }
  Mint &operator-=(const Mint rhs) {
    if ((value += kMod - rhs.value) >= kMod) {
      value -= kMod;
    }
    return *this;
  }
  Mint &operator*=(const Mint rhs) {
    (value *= rhs.value) %= kMod;
    return *this;
  }
  Mint operator+(const Mint rhs) const {
    return Mint(*this) += rhs;
  }
  Mint operator-(const Mint rhs) const {
    return Mint(*this) -= rhs;
  }
  Mint operator*(const Mint rhs) const {
    return Mint(*this) *= rhs;
  }
  Mint Pow(int64_t p) const {
    if (p == 0LL) {
      return 1LL;
    } else if (p < 0LL) {
      return Pow(-p).Pow(kMod - 2LL);
    }
    Mint temp = Pow(p >> 1LL);
    temp *= temp;
    if (p & 1LL) {
      temp *= (*this);
    }
    return temp;
  }
  Mint Inv() const {
    return Pow(kMod - 2LL);
  }
  Mint &operator/=(const Mint a) {
    return *this *= a.Inv();
  }
  Mint operator/(const Mint a) const {
    return Mint(*this) /= a;
  }
};
std::ostream &operator<<(std::ostream &os, const Mint &a) {
  os << a.value;
  return os;
}

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

  int64_t N, K;
  cin >> N >> K;

  Mint result = 0;
  for (int64_t k = K; k <= N + 1; ++k) {
    const int64_t min = k * (k - 1) / 2;
    const int64_t max = k * N - min;
    const int64_t count = max - (min - 1);
    result += count;
  }
  cout << result.value << endl;
  return 0;
}


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

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		long n = Long.parseLong(br.readLine());
		long sum = sum(n);
		long tsum = 3 * sum(n / 3);
		long fsum = 5 * sum(n / 5);
		long ffsum = 15 * sum(n / 15);
		System.out.println(sum - tsum - fsum + ffsum);
	}

	public static long sum(long n) {
		return (n * (n + 1)) / 2;
	}
}


Measured memory_bytes: 25324
import java.util.Scanner;

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

        int a = scanner.nextInt();
        int b = scanner.nextInt();

        int result = (a <= 9 && b <= 9) ? a * b : -1;
        System.out.println(result);
    }
}

Measured memory_bytes: 23124
/* template.cpp {{{ */
#include <bits/stdc++.h>
using namespace std;
#define get_macro(a, b, c, d, name, ...) name
#define rep(...) get_macro(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep(...) get_macro(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define rep1(n) rep2(i_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, b) rep4(i, a, b, 1)
#define rep4(i, a, b, s) for (ll i = (a); i < (ll)(b); i += (ll)(s))
#define rrep1(n) rrep2(i_, n)
#define rrep2(i, n) rrep3(i, 0, n)
#define rrep3(i, a, b) rrep4(i, a, b, 1)
#define rrep4(i, a, b, s) for (ll i = (ll)(b) - 1; i >= (ll)(a); i -= (ll)(s))
#define each(x, c) for (auto &&x : c)
#define fs first
#define sc second
#define all(c) begin(c), end(c)
using ui = unsigned;
using ll = long long;
using ul = unsigned long long;
using ld = long double;
const int inf = 1e9 + 10;
const ll inf_ll = 1e18 + 10;
const ll mod = 1e9 + 7;
const ll mod9 = 1e9 + 9;
const int dx[]{-1, 0, 1, 0, -1, 1, 1, -1};
const int dy[]{0, -1, 0, 1, -1, -1, 1, 1};
template<class T, class U> void chmin(T &x, const U &y){ x = min<T>(x, y); }
template<class T, class U> void chmax(T &x, const U &y){ x = max<T>(x, y); }
struct prepare_ { prepare_(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(12); } } prepare__;
/* }}} */

ll n, m;
ll a[200000], b[200000];
ll c[15], d[15];
ll sa[200010], sb[200010];
ll dp[1 << 15];

int main(){
  cin >> n >> m;
  rep(i, n) cin >> a[i] >> b[i];
  rep(i, m) cin >> c[i] >> d[i];
  rep(i, n) sa[i + 1] = sa[i] + a[i];
  rep(i, n) sb[i + 1] = sb[i] + b[i];

  rep(i, 1 << m) rep(j, m){
    if (i >> j & 1) continue;
    ll lb = dp[i], ub = n + 1;
    while (ub - lb > 1){
      ll md = (lb + ub) / 2;
      bool f = true;
      f &= sa[md] - sa[dp[i]] <= c[j];
      f &= sb[md] - sb[dp[i]] <= d[j];
      (f ? lb : ub) = md;
    }
    chmax(dp[i | 1 << j], lb);
  }

  cout << dp[(1 << m) - 1] << endl;
}

Measured memory_bytes: 9608
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
#define ALL(a) a.begin(), a.end()
ll dx[4] = { 0, 1, 0, -1 };
ll dy[4] = { 1, 0, -1, 0 };
const ll INF = 1e14;
const ll MOD = 1e9 + 7;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int N, K, Q;
    cin >> N >> K >> Q;
    vector<int> A(Q);
    vector<int> people(N, K - Q);
    rep(i, Q)
    {
        cin >> A[i];
    }
    for (auto& a : A) {
        people[a-1]++;
    }

    for (auto& p : people) {
        if (p > 0) {
            puts("Yes");
        } else {
            puts("No");
        }
    }
    return 0;
}

Measured memory_bytes: 1408
#include<stdio.h>

//線形探索
int search(int A[], int n, int key){
    int i = 0;
    A[n] = key;
    while (A[i] != key) i++;
    return i != n;
}

int main(){
    int i, n, A[10000+1], q, key, sum = 0;

    scanf("%d", &n);
    for(i=0; i<n; i++) scanf("%d", &A[i]);

    scanf("%d", &q);
    for(i=0; i<q; i++){
        scanf("%d", &key);
        if(search(A, n, key)) sum++;
    }
    printf("%d\n", sum);

    return 0;
}


Measured memory_bytes: 2760
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;


int main() {
    int n;
    cin>>n;
    string s,s1;
    cin>>s;
    for(int i=0;i<s.size();i++)
    {
        int val=int(s[i]+n);
        s1=s[i]+n;
        if(val>90)
            {
                val=val-90;
                cout<<char(64+val);
               // cout<<s2;
            }
        else
        cout<<s1;
    }

}


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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define per(i, a, b) for(int i = (b)-1; i >= (a); --i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fst first
#define snd second

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pii> vii;

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

int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin.exceptions(cin.failbit);

  ll n, x, m;
  cin >> n >> x >> m;

  vi sn(m, -1);
  sn[x] = 0;

  vl seq = {x};

  ll cs = 0;
  bool zero=0, cyc=0;

  rep(i,0,m) {
    x *= x;
    x %= m;
    if (sn[x] != -1) {
      cyc = 1;
      cs = sn[x];
      break;
    } else if (x==0) {
      zero = 1;
      break;
    } else {
      sn[x] = i+1;
      seq.pb(x);
    }
  }

  if (zero) {
    cout << accumulate(all(seq), 0ll) << '\n';
    return 0;
  }

  assert(cyc);

  ll ans = 0;
  rep(i,0,min(n,cs)) {
    ans += seq[i];
  }

  int k = sz(seq)-cs;
  ll sm = 0;
  rep(i,cs,sz(seq)) sm += seq[i];

  n -= min(n,cs);
  ans += sm*(n/k);
  int rem = n%k;

  rep(i,cs,cs+rem) {
    ans += seq[i];
  }

  cout << ans << '\n';


}

Measured memory_bytes: 4228
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>
using namespace std;

int main()
{
  int r,g,b;
  cin>>r>>g>>b;
  string ans="NO";
  if((10*g+b)%4==0) ans="YES";
  cout<< ans <<endl;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
s = input()

i = 0
j = len(s)-1
result = 0
while i < j:
    if s[i] == s[j]:
        i += 1
        j -= 1
    elif s[i] == "x":
        result += 1
        i += 1
    else:
        result += 1
        j -= 1

if i == j:
    if s[:i].replace("x", "") == s[i+1:][::-1].replace("x", ""):
        print(result)
    else:
        print(-1)
else:
    if s[:j+1].replace("x", "") == s[i:][::-1].replace("x", ""):
        print(result)
    else:
        print(-1)


Measured memory_bytes: 3444
#include <cstdio>
const int N = 110, M = 11000;
int n, f[M];
int main() {
	f[0] = 1;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		int x; scanf("%d", &x);
		for (int j = M - 1; j >= x; j--) f[j] |= f[j - x];
	}
	for (int i = M - 1; ~i; i--) if (f[i] && i%10) {
		printf("%d\n", i);
		return 0;
	}
	puts("0");
}

Measured memory_bytes: 256
#include <iostream>
#include <locale>
using namespace std;
int main(void){
    char a,b;// Your code here!   char a,b;
    cin>>a>>b;
    if(a=='H'&&b=='H'){
        cout<<"H"<<endl;
    }
    else if(a=='D'&&b=='D'){
        cout<<"H"<<endl;
    }
    else{
        cout<<"D"<<endl;
    }
   
}


Measured memory_bytes: 256
import sys
N = None

for i,line in enumerate(sys.stdin):
    if i == 0:
        N = int(line)
    if i == 1:
        lines = [int(i) for i in line.split(" ")]
        if (sum(lines) - max(lines)) > max(lines):
            print("Yes")
        else:
            print("No")

Measured memory_bytes: 3060
l,r=map(int,input().split())
if (r-l)//2019>3:
  r=l+2019*2
ans=10000
for i in range(l,r):
  for j in range(i+1,r+1):
    i%=2019
    j%=2019
    ans=min(ans,i*j%2019)
print(ans)

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

#define FORE(i, a) for (auto i = a.begin(); i != a.end(); ++i)
#define REPU(i, a, b) for (int i = (a); i < (b); ++i)
#define REPD(i, a, b) for (int i = (a); i > (b); --i)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())

vector<string> split(const string &s, char c) {
	vector<string> v;
	stringstream ss(s);
	string x;
	while (getline(ss, x, c)) v.push_back(x);
	return v;
}

#define DEBUG(args...) { vector<string> _v = split(#args, ','); err(_v.begin(), args); }

void err(vector<string>::iterator it) {}

template<typename T, typename... Args>
void err(vector<string>::iterator it, T a, Args... args) {
	cerr << "[DEBUG] " << it -> substr((*it)[0] == ' ', it -> length()) << " = " << a << '\n';
	err(++it, args...);
}

typedef long long ll;
const int MOD = 1000000007;

template<class T, class U> inline T tmin(T a, U b) { return (a < b) ? a : b; }
template<class T, class U> inline T tmax(T a, U b) { return (a > b) ? a : b; }
template<class T, class U> inline void amax(T &a, U b) { if (b > a) a = b; }
template<class T, class U> inline void amin(T &a, U b) { if (b < a) a = b; }
template<class T> inline T tabs(T a) { return (a > 0) ? a : -a; }
template<class T> T gcd(T a, T b) { while (b != 0) { T c = a; a = b; b = c % b; } return a; }

int main(int argc, char *argv[]) {
	ios_base::sync_with_stdio(false);

	int n;

	cin >> n;
	vector<int> a(n);
	REPU(i, 0, n) {
		cin >> a[i];
	}
	int mx = 0;
	ll ans = 0;
	REPU(i, 0, n) {
		ans += (a[i] - 1) / (mx + 1);
		if ((a[i] - 1) / (mx + 1) > 0) {
			a[i] = 1;
		}
		amax(mx, a[i]);
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 640
N = int(input())

cnt = [[0 for i in range(10)] for j in range(10)]

for i in range(1, N+1):
    i_str = str(i)
    cnt[int(i_str[0])][int(i_str[-1])] += 1

ans = 0
for i in range(10):
    for j in range(10):
        ans += cnt[i][j] * cnt[j][i]

print(ans)

Measured memory_bytes: 73296
n, m = map(int, input().split())

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k]) 
    
    return result
if n >= 2 and m >= 2:
     print(cmb(n,2) + cmb(m,2))
if n < 2 and m < 2:
    print(0)
if n < 2 and m >= 2:
    print(cmb(m, 2))
if n >= 2 and m < 2:
    print(cmb(n, 2))

Measured memory_bytes: 38384
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define index_check(i,n) if(i > n-1 || i < 0) continue; 
#define LINF 1e18
#define INF 1e9
#define MOD (ll)(1e9+7)
using namespace std;

#define fs first
#define sc second

using P = pair<ll,ll>;
using Pll = pair<P,ll>;
using PQ = priority_queue<P,vector<P>,greater<P>>;


signed main(){
    ll n;
    cin >> n;
    
    Pll red[n],blue[n];
    rep(i,0,n){
        cin >> red[i].fs.fs >> red[i].fs.sc;
        red[i].sc = i;
    }
    rep(i,0,n){
        cin >> blue[i].fs.sc >> blue[i].fs.fs;
        blue[i].sc = i;
    }

    sort(red,red+n,greater<Pll>());
    sort(blue,blue+n);
    bool is_used[n] = {false};

    ll cnt = 0;
    rep(i,0,n){
        rep(j,0,n){
            if(!is_used[red[j].sc] && blue[i].fs.fs > red[j].fs.sc && blue[i].fs.sc > red[j].fs.fs){
                is_used[red[j].sc] = true;
                cnt++;
                break;
            }
        }
    }
    
    cout << cnt << endl;
    return 0;
}


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

int main() {
  int n, ans = 0;
  cin >> n;
  vector <int64_t> vec(n, 0);
  for (int i = 0; i < n; i++) {
    int64_t a;
    cin >> a;
    if (a > n) {
      ans++;
    } else {
      vec.at(a-1)++;
    }
  }
  for (int i = 0; i < n; i++) {
    if (vec.at(i) > 0) {
      if (vec.at(i) >= i+1) {
        ans += vec.at(i) - (i+1);
      } else {
        ans += vec.at(i);
      }
    }
  }
  cout << ans << endl;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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

  int a, b;
  cin >> a >> b;

  cout << max(a + b, max(a - b, a * b)) << endl;

  return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())

dp = [10**10 for B in range(1 << N)]
dp[0] = 0

for i in range(M):
    a, b = map(int, input().split())
    c = [int(j) for j in input().split()]
    C = sum([1 << (x-1) for x in c])

    for B in range(1 << N):
        dp[B | C] = min(dp[B | C], dp[B]+a)

if dp[(1 << N)-1] == 10**10:
    print(-1)
else:
    print(dp[(1 << N)-1])


Measured memory_bytes: 48344
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <string>

using namespace std;

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

	int ans = (10000 - n) % 1000;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3168
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdint.h>
#include<stdbool.h>
#include<tgmath.h>
#include<sys/queue.h>
#include<time.h>
#define ll long long
#define min(a, b) ((a) > (b) ? (b) : (a))
#define max(a, b) ((a) > (b) ? (a) : (b))
#define miin(a, b, c) min((a), min((b), (c)))
#define maax(a, b, c) max((a), max((b), (c)))
#define mod 1000000007

int n, k, h[111111];

int cmp(const int *a, const int *b){
    return *a - *b;
}

main(){
    scanf("%d%d", &n, &k);
    for(int i=0; i<n; i++){
        scanf("%d", &h[i]);
    }
    qsort(h, n, 4, cmp);
    int ans = h[k-1]-h[0];
    for(int i=1; i+k<=n; i++){
        ans = min(ans, h[i+k-1]- h[i]);
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 892
#include <stdio.h>

int main(void) {
  int N,K;
  char str[100];
  scanf("%d %d",&N,&K);
  scanf("%s",str);
  if( str[K-1] =='A')
    str[K-1] = 'a';
  if( str[K-1] =='B')
    str[K-1] = 'b'; 
  if( str[K-1] =='C')
    str[K-1] = 'c'; 
  printf("%s\n",str);
  return 0;
}

Measured memory_bytes: 1988
# -*- coding: utf-8 -*-
# abc136/abc136_d
import sys

s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in list(ss)]
ss2nnn = lambda ss: [s2nn(s) for s in list(ss)]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [i2s() for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))

def main():
    S = i2s()
    N = len(S)
    c = [0] * N
    M = 10**100
    for i in range(N):
        m = M
        if S[i] == 'R':
            L_index = S.find('L', i)
            R_index = S.rfind('R', 0, L_index)
            m -= R_index - i
        else:
            R_index = S.rfind('R', 0, i)
            L_index = S.find('L', R_index)
            m -= i - R_index
        diff = L_index - R_index
        one_round = diff * 2
        rem = m % one_round
        if rem > diff:
            c[R_index + one_round - rem] += 1
        else:
            c[R_index + rem] += 1
    print(' '.join(map(str, c)))
    return

main()


Measured memory_bytes: 10484
#include<stdlib.h>
m,S[40][2];
i,f,h,s,sp,st1,st2,d,d1;
M(int(*a)[],int(*b)[]){
	if((*a)[0]==(*b)[0])
		return(*a)[1]-(*b)[1];
	return(*b)[0]-(*a)[0];
}
main(){
	for(;scanf("%d",&m),m;){
		for(i=0;i<m;i++){
			scanf("%d",&S[i][1]);
			s=0;
			sp=st1=st2=0;
			d=0;
			for(f=1,h=0;h<3;){
				d1=d;
				scanf("%d",&d);
				s+=d+(sp+st1+st2)*d;
				sp=0;
				st2=st1;
				st1=0;
				if(f==10){
					if(h==1&&d+d1<10)
						h=3;
					else
						h++;
				}else if(h==0&&d==10){
					st1=1;
					f++;
				}else if(h==1&&d+d1==10){
					sp=1;
					f++;
					h=0;
				}else{
					if(h==1)
						f++;
					h^=1;
				}
			}
			S[i][0]=s;
		}
		qsort(S,m,sizeof(*S),M);
		for(i=0;i<m;i++)
			printf("%d %d\n",S[i][1],S[i][0]);
	}
	exit(0);
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
 
using namespace std;
 
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define rep(i,n) REP(i,0,n);
#define pb(n) push_back(n)
#define mp(n,m) make_pair(n, m)
#define all(r) r.begin(),r.end()
#define fi first
#define se second
#define println(X) cout<<X<<endl;

#define Rep(i) for(int i  =1; i <= 30; i++)
 
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1e9;


int main(){
	pii p[6];
	p[0] = mp(2, 380);
	p[1] = mp(3, 550);
	p[2] = mp(5, 850);
	p[3] = mp(2*5, 380*5*0.8);
	p[4] = mp(3*4, 550*4*0.85);
	p[5] = mp(5*3, 850*3*0.88);

	int dp[100];
	int w;
	while(cin>>w&&w){
		w/=100;
		for(int i = 0; i <= w; i++){
			dp[i] = INF;
		}
		dp[0]=0;
		for(int i = 0; i < 6; i++){
			for(int j = p[i].fi; j <= w; j++){
				dp[j]=min(dp[j], dp[j-p[i].fi]+p[i].se);
			}
		}
		cout<<dp[w]<<endl;
	}
}

Measured memory_bytes: 1160
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	int A, B, C, X;
	cin >> A >> B >> C >> X;
	int count = 0;
	for (int i = 0; i <= A; i++) {
		for (int j = 0; j <= B; j++) {
			for (int k = 0; k <= C; k++) {
				if (X == 500 * i + 100 * j + 50 * k) {
					count++;
				}
			}
		}
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 3600
import qualified Data.ByteString.Char8 as B
import Control.Monad (replicateM)
import qualified Data.Set as S

main = do
  n <- readLn
  an <- replicateM n $ B.readInt <$> B.getLine
  print $ S.size $ foldl (\acc x -> if S.member x acc then S.delete x acc else S.insert x acc) S.empty an

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

int N;
vector<int> G[100000];
vector<int> v(100000, 0);

void bfs() {
    queue<int> S;
    queue<int> F;
    F.push(0);
    S.push(N - 1);
    v[0] = 1;
    v[N - 1] = 2;
    bool check = true;
    while (check) {
        check = false;
        queue<int> S_next;
        queue<int> F_next;
        while (!F.empty()) {
            int k = F.front();
            F.pop();
            for (int i = 0; i < G[k].size(); i++) {
                if (v[G[k][i]] == 0) {
                    v[G[k][i]] = 1;
                    F_next.push(G[k][i]);
                    check = true;
                }
            }
        }
        F = F_next;
        while (!S.empty()) {
            int k = S.front();
            S.pop();
            for (int i = 0; i < G[k].size(); i++) {
                if (v[G[k][i]] == 0) {
                    v[G[k][i]] = 2;
                    S_next.push(G[k][i]);
                    check = true;
                }
            }
        }
        S = S_next;
    }
}

int main() {
    cin >> N;
    for (int i = 0; i < N - 1; i++) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    bfs();
    int cnt = 0;
    for (int i = 0; i < N; i++) {
        if (v[i] == 1) cnt++;
    }
    cout << (cnt > N - cnt ? "Fennec" : "Snuke") << endl;
}

Measured memory_bytes: 6368
import java.util.Arrays;

public class Main {


  private static void solve() {
    int n = ni();
    int[] p = na(n);
    int ret = 0;
    for (int i = 1; i < n - 1; i ++) {
      int[] a = {p[i], p[i - 1], p[i + 1]};
      Arrays.sort(a);
      if (a[1] == p[i]) {
        ret ++;
      }
    }
    System.out.println(ret);
  }

  public static void main(String[] args) {
    new Thread(null, new Runnable() {
      @Override
      public void run() {
        long start = System.currentTimeMillis();
        String debug = args.length > 0 ? args[0] : null;
        if (debug != null) {
          try {
            is = java.nio.file.Files.newInputStream(java.nio.file.Paths.get(debug));
          } catch (Exception e) {
            throw new RuntimeException(e);
          }
        }
        reader = new java.io.BufferedReader(new java.io.InputStreamReader(is), 32768);
        solve();
        out.flush();
        tr((System.currentTimeMillis() - start) + "ms");
      }
    }, "", 64000000).start();
  }

  private static java.io.InputStream is = System.in;
  private static java.io.PrintWriter out = new java.io.PrintWriter(System.out);
  private static java.util.StringTokenizer tokenizer = null;
  private static java.io.BufferedReader reader;

  public static String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }

  private static double nd() {
    return Double.parseDouble(next());
  }

  private static long nl() {
    return Long.parseLong(next());
  }

  private static int[] na(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++)
      a[i] = ni();
    return a;
  }

  private static char[] ns() {
    return next().toCharArray();
  }

  private static long[] nal(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++)
      a[i] = nl();
    return a;
  }

  private static int[][] ntable(int n, int m) {
    int[][] table = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[i][j] = ni();
      }
    }
    return table;
  }

  private static int[][] nlist(int n, int m) {
    int[][] table = new int[m][n];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        table[j][i] = ni();
      }
    }
    return table;
  }

  private static int ni() {
    return Integer.parseInt(next());
  }

  private static void tr(Object... o) {
    if (is != System.in)
      System.out.println(java.util.Arrays.deepToString(o));
  }
}


Measured memory_bytes: 22868
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize "03"
#pragma GCC target("sse4")

#define ll long long int
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define FRE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
#define f(i,n) for(ll i=0;i<n;i++)
#define fa(i,a,n) for(ll i=a;a<n?i<n:i>=n;a<n?i+=1:i-=1)
#define loop(i,a, n) for(ll i = a; i <= n; i++)
#define loopb(i,a, n) for(ll i = a; i >= n; i--)
#define pb push_back
#define pf push_front
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define setmem(x, k) memset(x, k, sizeof(x))
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define PI 3.1415926535897932384626
#define MOD 1000000007
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int>	vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef long double ld;
// const ll N = 1e6+5;	
// ll a[N], b[N], dp[N], in[N], out[N], level[N], vis[N];
// vl g[N];
ll n, m;

ll dp[100005];
vector<ll> a;

ll fun(vector<ll>& a, ll pos){
	if(pos == n - 1){
		return 0;
	}
	if(pos >= n){
		return INT_MAX;
	}
	if (dp[pos] != -1) return dp[pos];
	return dp[pos] = min(abs(a[pos] - a[pos+1]) + fun(a, pos + 1), abs(a[pos] - a[pos+2]) + fun(a, pos + 2));
}

void solve() {
	// ll k, x, y, p, q, r;
	cin>>n;
	a.resize(n);
	f(i,n) cin >> a[i];
	setmem(dp, -1);
	cout << fun(a, 0);
}

int32_t main() {
	IOS
	ll T;
	// cin >> T;
	// while(T--)
		solve();
	cerr<<"Time elapsed : "<<clock()*1000.0/CLOCKS_PER_SEC<<"ms"<<'\n'; 
	return 0;
}

Measured memory_bytes: 4224
N = int(input())
aList = [int(x) for x in input().split()]
x = [0] * 10**5

for a in aList:
    x[a] += 1
    if a > 0:
        x[a-1] += 1
    if N-1 > a:
        x[a+1] += 1
print(max(x))

Measured memory_bytes: 13964
#pragma GCC optimize(2)
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <queue>
#include <map>
#include <stack>
#include <vector>
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define debug  freopen("in.txt","r",stdin),freopen("out.txt","w",stdout);
#define pb push_back
#define all(x) x.begin(),x.end()
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;
const int maxn = 1e6+10;
const int maxM = 1e6+10;
const int inf = 0x3f3f3f3f;
const ll inf2 = 0x3f3f3f3f3f3f3f3f;
inline void read(int &x){
    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();
    x = s*w;
}

int N;
int cnt[maxn];
bool ans1 = 1;
bool ans2 = 0;

int gcd(int a,int b){
    return !b? a:gcd(b,a%b);
}
void solve(){
    for(int i = 2;i<maxn;i++){
        int coun = 0;
        for(int j = 1;j*i<maxn;j++){
            coun += cnt[j*i];
        }
        if(coun > 1) ans1 = 0;
    }
    if(ans1) cout<<"pairwise coprime\n";
    else if(ans2) cout<<"setwise coprime\n";
    else cout<<"not coprime\n";
}
int main(){
//    debug;
    ios;

    cin>>N;
    int g = 0;
    for(int i =1;i<=N;i++){
        int cur;cin>>cur;
        g = gcd(g,cur);
        cnt[cur]++;
    }
    if(g == 1) ans2 = 1;

    solve();

    return 0;
}

Measured memory_bytes: 7524
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;

int main(){
  int N;
  cin >> N;
  ll L[90];
  L[0] = 2;
  L[1] = 1;
  ll ans = 1;
  for (int i = 2; i <= N ; i++){
    L[i] = L[i-1] + L[i-2];
    ans = L[i];
  }
  cout << ans << endl;
}

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

int main()
{
   // freopen("C:\\Users\\parth\\Desktop\\input.txt","r",stdin);
   // freopen("C:\\Users\\parth\\Desktop\\output.txt","w",stdout);

    list<int> ls;
    list<int>::iterator ite,it  = ls.begin();
    ite = it;
    int test;
    cin>>test;
    while(test--)
    {
         ite = it;
        int command,value;
        cin>>command;
        switch(command)
        {
        case 0:
            cin>>value;
            ls.insert(it,value);
            it--;
            break;
        case 1:
            cin>>value;
            if(value>=0){ 
                for(int i = 0;i<value;i++)
                        it++;

            }
            else{ 
                for(int i = 0;i<abs(value);i++)
                it--;
            }
            break;
        case 2:
        
        if(!(ls.empty())) it = ls.erase(it);
            break;
        }
    }
    for(it = ls.begin();it != ls.end();it++) cout<<*it<<endl;




    return 0;
}



Measured memory_bytes: 18660
from math import floor,ceil,sqrt,factorial,log
from collections import Counter, deque
from functools import reduce
import numpy as np
def S(): return input()
def I(): return int(input())
def MS(): return map(str,input().split())
def MI(): return map(int,input().split())
def LS(): return list(MS())
def LI(): return list(MI())
def LLS(): return [list(map(str, l.split() )) for l in input()]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def LLSN(n: int): return [LS() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]

n, k = MI()

a = np.array(sorted([int(i) for i in input().split()]))

pos = a[a > 0]
zero = a[a == 0]
neg = a[a < 0]

# 2分探索, mid より小さいものを数える
l = -10 ** 18 - 1
r = 10 ** 18 + 1
while r - l > 1:
    mid = (r + l) // 2
    cnt = 0
    if mid >= 0:
        cnt += len(zero) * n
 
    cnt += a.searchsorted(mid // pos, side="right").sum()
    cnt += (n - a.searchsorted(-(-mid // neg), side="left")).sum()
    cnt -= np.count_nonzero(a * a <= mid)
    cnt //= 2
    if cnt >= k:
        r = mid
    else:
        l = mid

print(r)

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

const double PI = acos(-1);

int main() {
  double a, b, x;
  cin >> a >> b >> x;
  x /= a;
  if (x <= a * b / 2) {
    double d = x / b * 2;
    double theta = atan(b / d);
    printf("%.10lf\n", theta * 180 / PI);
  } else {
    double d = (a * b - x) / a * 2;
    double theta = atan(d / a);
    printf("%.10lf\n", theta * 180 / PI);
  }
  return 0;
}


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

int main()
{
    int64_t N, D;
    cin >> N >> D;
    vector<int64_t> X(N), Y(N);
    for (int i = 0; i < N; i++)
    {
        cin >> X[i] >> Y[i];
    }

    int count = 0;
    for (int i = 0; i < N; i++)
    {
        if (X[i] * X[i] + Y[i] * Y[i] <= D * D)
            count++;
    }

    cout << count << endl;
    return 0;
}

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

#define int long long
#define double long double

using namespace std;

#define REP(i, a, b) for (int(i) = (a); i < (b); (i)++)
#define rep(i, n) REP(i, 0, n)
#define PER(i, a, b) for (int(i) = (a - 1); i >= (b); (i)--)
#define per(i, n) PER(i, n, 0)
#define each(i, n) for (auto &i : n)
#define clr(a) memset((a), 0, sizeof(a))
#define mclr(a) memset((a), -1, sizeof(a))
#define all(a) (a).begin(), (a).end()
#define dum(val) cerr << #val " = " << val << " ";
#define dump(val) cerr << #val " = " << val << endl;
#define FILL(a, v) fill(a, a + sizeof(a) / sizeof(*a), v)

typedef pair<int, int> P;
typedef tuple<int, int, int> T;

const int mod = 1e9 + 7;
const int INF = 1e9;

signed main() {

	int n,k;
	cin >> n >> k;

	map<int,int> mp;

	rep(i,n) {
		int a;
		cin >> a;
		mp[a]++;
	}

	vector<int> c;

	each(i, mp) {
		c.push_back(i.second);
	}

	sort(all(c));
	reverse(all(c));

	int ans = 0;
	while(1) {
		if(c.size() > k) {
			ans += c.back();
			c.pop_back();
		}else{
			break;
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 14964
#include <iostream>
#include <string>
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <algorithm>
#include <ctime>
#include <vector>
#include <set>
#include <queue>
using namespace std;

#define PI 3.14159265358979323846264338327950L

int res;

int main()
{
    int n, a[8], p[8], q[8];
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> p[i];
    }
    for (int i = 0; i < n; i++)
    {
        cin >> q[i];
    }
    for (int i = 0; i < n; i++)
    {
        int now = i + 1;
        a[i] = now;
    }
    int A = 0, B = 0;
    int cnt = 0;
    do
    {
        for (int i = 0; i < n; i++)
        {
            //	cout <<a[i];
        }
        //	cout <<endl;
        for (int i = 0; i < n; i++)
        {
            if (a[i] != p[i])
            {
                break;
            }
            if (i == n - 1)
            {
                A = cnt;
            }
        }
        for (int i = 0; i < n; i++)
        {
            if (a[i] != q[i])
            {
                break;
            }
            if (i == n - 1)
            {
                B = cnt;
            }
        }
        cnt++;
    } while (next_permutation(a, a + n));
    cout << abs(A - B);
    // your code goes here
    return 0;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
a = list(map(int, input().split()))

pos = -1
seen = [False] * n
last = [-1] * n
hist = []
i = 0
cnt = 0

while(seen[i] == False):
    seen[i] = True
    last[i] = cnt
    cnt += 1
    hist.append(i)
    ne = a[i]-1
    i = ne
    if (seen[i] == True):
        pos = i

cycle = hist[last[pos]:]
preCircle = last[pos]

if (k <= preCircle):
    print(hist[k] + 1)
else:
    k -= preCircle
    ans = k % len(cycle)
    print(cycle[ans] + 1)



Measured memory_bytes: 34460
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
int cmp_char(const void *a, const void *b) { return *(char *)a - *(char *)b; }                     /* a,b,c,d.. */
int cmp_str(const void *a, const void *b) { return strcmp(*(const char **)a, *(const char **)b); } /* aaa,aab.. */
#define min(a, b) (a < b ? a : b)
#define max(a, b) (a > b ? a : b)
#define read(n) scanf("%d", &n)
#define readl(n) scanf("%lld", &n)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define MAX 100001
#define MOD 1000000007

typedef long long int lli;

lli a[MAX], b[MAX];

int acs(const void *x, const void *y)
{
  if (a[*(int *)x] - a[*(int *)y] > 0)
    return 1;
  if (a[*(int *)x] - a[*(int *)y] < 0)
    return -1;
  return 0;
}

int main(void)
{
  int n, m;
  read(n);
  read(m);

  rep(i, 0, n)
  {
    readl(a[i]);
    readl(b[i]);
  }

  int idx[MAX];
  rep(i, 0, n) idx[i] = i;

  qsort(idx, n, sizeof(int), acs);

  int rem = m;
  lli mny = 0;
  rep(i, 0, n)
  {
    if (rem <= 0)
      break;
    int drink = min(rem, b[idx[i]]);
    mny += a[idx[i]] * drink;
    rem -= drink;
  }

  printf("%lld\n", mny);
  return 0;
}


Measured memory_bytes: 2556
import sys


H, W, M = map(int, input().split())
bomb = [tuple(map(lambda x: int(x) - 1, s.split())) for s in sys.stdin.readlines()]
X = [0] * H
Y = [0] * W
for h, w in bomb:
    X[h] += 1
    Y[w] += 1
maxX = max(X)
maxY = max(Y)

R = [h for h, x in enumerate(X) if x == maxX]
C = [w for w, y in enumerate(Y) if y == maxY]

bomb = set(bomb)
for r in R:
    for c in C:
        if (r, c) not in bomb:
            print(maxX + maxY)
            exit()
print(maxX + maxY - 1)


Measured memory_bytes: 199472
#include <iostream>
#include <cmath>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#define debug(x) cerr << #x << ':' << x << endl
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
using namespace std;
typedef long long ll;

int main(){
    int n;
    cin >> n;
    vector<int> V(n,0);
    REP(i,n) cin >> V[i];

    map<int, int> even;
    map<int, int> odd;
    REP(i,n){
        if(i%2==1) continue;
        if(even.find(V[i])!=even.end())even[V[i]]++;
        else even[V[i]]=1;
    }
    REP(i,n){
        if(i%2==0) continue;
        if(even.find(V[i])!=odd.end())odd[V[i]]++;
        else even[V[i]]=1;
    }

    int mi =1e9;
    pair<int, int> ma1even=make_pair(1, 0), ma2even=make_pair(1, 0);
    pair<int, int> ma1odd=make_pair(1, 0), ma2odd=make_pair(1, 0);
    FOR(p, even){
        if(p->second > ma1even.second){
            ma2even = ma1even;
            ma1even = *p;
        }
        else if(p->second > ma2even.second){
            ma2even = *p;
        }
    }
    FOR(p, odd){
        if(p->second > ma1odd.second){
            ma2odd = ma1odd;
            ma1odd = *p;
        }
        else if(p->second > ma2odd.second){
            ma2odd = *p;
        }
    }

    int ans=0;
    if(ma1even.first == ma1odd.first){
        // cout << "a" << endl; 
        ans = min((n/2) -ma1even.second + (n/2) -ma2odd.second, (n/2) -ma2even.second + (n/2) -ma1odd.second);
    }
    else{
        ans = (n/2) - ma1even.second + (n/2) - ma1odd.second;
    }
    cout << ans << endl;


    return 0;
}

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

// 小数点以下桁数
// fixed << setprecision(i)

int64_t gcd(int64_t a,int64_t b){return (a%b==0?b:gcd(b, a%b));}
int64_t lcm(int64_t a,int64_t b){return a/gcd(a, b)*b;}
int factorial(int a){int b=1;while(a){b*=a--;}return b;} //13以下対応
bool is_prime(int a){if(a<=1)return false;for(int i=2;(int64_t)i*i<=a;i++){if(a%i==0)return false;}return true;}
int get_adp(double x, int n){return (int)round((x-(int)x)*pow(10,n))%10;} // 小数点以下の指定桁の値を取得
int64_t sigma(int64_t s, int64_t n){return n*(2*s+n-1)/2;}

//順列の全列挙
// vector<int> v(N);
// iota(v.begin(), v.end(), 1);       // v に 1, 2, ... N を設定
// do {
//	for(auto x : v) cout << x << " "; cout << "\n";     // v の要素を表示
// } while( next_permutation(v.begin(), v.end()) ); 

//bit全探索
// for (int tmp = 0; tmp < (1 << ビット数); tmp++) {
//	bitset<ビット数> s(tmp);
//	// (ビット列sに対する処理)
// }



int main()
{
	int n;
	int64_t ans, c = pow(10, 9) + 7, a = 1, b = 1, d = 1;

	cin >> n;
	for (int i = 0; i < n; i++)
	{
		a = a * 10 % c;
		b = b * 9 % c;
		d = d * 8 % c;
	}
	ans = (a - (2 * b % c) + d) % c;
	if (ans < 0)
		ans += c;
	cout << ans << endl;
}


Measured memory_bytes: 3684
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


s = input()
from queue import deque
q = deque(s)
ans = 0
while q:
    if q[0]==q[-1]:
        q.popleft()
        if q:
            q.pop()
    elif q[0]=="x":
        ans += 1
        q.popleft()
    elif q[-1]=="x":
        ans += 1
        q.pop()
    else:
        ans = -1
        break
print(ans)

Measured memory_bytes: 77836
//
// tested with : g++ (GCC) 8.3.0
//

#include <iostream>
#include <string>
using namespace std;

int main() {
    string s;
    cin >> s;

    s[0] = '2';
    s[1] = '0';
    s[2] = '1';
    s[3] = '8';

    cout << s << endl;

    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<map>
#include<queue>
#include<iostream>
#include<algorithm>
#define m(a,b) memset(a,b,sizeof(a));
using namespace std;
const int inf = 1 << 30;
const int maxn = 1e5;
typedef long long LL;
int main(){
	char a[maxn+5],b[maxn+5];
	cin >> a >> b;
	int c = strlen(a)-strlen(b);
	if(c>0) cout << "GREATER" << endl;
	else if(c<0) cout << "LESS" << endl;
	else{
		if(strcmp(a,b)>0) cout << "GREATER" << endl;
		else if(strcmp(a,b) == 0) cout << "EQUAL" << endl;
		else cout << "LESS" << endl;
	}
	return 0;
}

Measured memory_bytes: 256