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

#define DEBUG1  false
#define DEBUG2  false

int main()
{
    std::vector<int> T;
    T.push_back(5);
    T.push_back(7);
    T.push_back(5);

    int i = 3;
    std::vector<int> S;
    while (i--)
    {
        int X;
        std::cin >> X;
        S.push_back(X);
    }
#if DEBUG1
    std::cout << "DEBUG1: S:";
    for (auto itr = S.begin(); itr != S.end(); ++itr)
    {
        std::cout << " " << *itr;
    }
    std::cout << std::endl;
#endif // DEBUG1

    for (auto itr = S.begin(); itr != S.end(); ++itr)
    {
        auto m = std::find(T.begin(), T.end(), *itr);
        if (T.end() != m)
        {
            T.erase(m);
        }
#if DEBUG2
    std::cout << "DEBUG2: T:";
    for (auto itr = T.begin(); itr != T.end(); ++itr)
    {
        std::cout << " " << *itr;
    }
    std::cout << std::endl;
#endif // DEBUG2
    }

    if (!T.size())
    {
        std::cout << "YES" << std::endl;
    }
    else
    {
        std::cout << "NO" << std::endl;
    }

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LOOP(val, times)   for(val = 0; val < (times); val++)
using namespace std;

int main(){
    int i,j,n;
    cin >> n;
    vector<int> vec(n);
    LOOP(i,n){cin>>vec.at(i);
                   }
    reverse(vec.begin(),vec.end());
    LOOP(j,n-1){cout<<vec.at(j)<<" ";
                   }
    cout<<vec.at(n-1)<<endl;
}


Measured memory_bytes: 3092
#include <bits/stdc++.h>
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define mkp make_pair
#define lP pair<ll, ll>
#define iP pair<int,int>
typedef long long ll;
using namespace std;

string S;
ll res;
int cnt;

ll pw(ll x, int y) {
	ll a = 1;
	while (y) {
		if (y & 1) {
			a = a*x%mod;
		}
		x = x*x%mod;
		y >>= 1;
	}
	return a;
}

int main() {
	cin >> S;
	for (int i = 0; i < S.size(); ++i) {
		if (S[i] == '1') {
			res += pw(2, cnt)*pw(3, S.size() - 1 - i);
			res %= mod;
			++cnt;
		}
	}
	res += pw(2, cnt);
	res %= mod;
	cout << res << endl;
}

Measured memory_bytes: 512
import std.stdio, std.string, std.range, std.conv, std.algorithm, std.typecons;
void main(){
	alias Tuple!(int, int) Data;
	int N, M;
	auto input = readln.split.map!(to!int);
	N = input[0], M = input[1];
	int[] A = new int[N]; //?????¨
	foreach (i; 0..N) {
		A[i] = readln.chomp.to!int;
	}
	int[] vote = new int[N];
	foreach (i; 0..M) {
		int B = readln.chomp.to!int;
		foreach (j; 0..N) {
			if (A[j] <= B) {
				vote[j]++;
				break;
			}
		}
	}
	int max, idx;
	foreach (i; 0..N) {
		if (vote[i] > max) {
			max = vote[i];
			idx = i;
		}
	}
	writeln(idx+1);
}

Measured memory_bytes: 2464
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <map>
#include <algorithm>
#include <queue>
#include <tuple>
#include <functional>

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define irep(i,n) for(int  i = 0; i < n; i++)
#define irep2(i,a,n) for(int i = a; i < n; i++)
#define lrep(i,n) for(long long  i = 0; i < n; i++)
#define lrep2(i,a,n) for(long long i = a; i < n; i++)
#define in(a) cin >> a
#define out(a) cout << a << endl
typedef long long ll;

typedef std::vector<int> v_int;
typedef std::vector<std::vector<int> > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<std::vector<ll> > v2_ll;

using namespace std;

int main() 
{
    int a,b,c,d;
    cin >> a;
    cin >> b;
    cin >> c;
    cin >> d;

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



Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define PI 3.141592
#define MOD7 1000000007
#define LL_INF 9000000000000000000
#define LL_MINF -9000000000000000000
#define INT_INF 2000000000
#define INT_MINF -2000000000
#define all(a) (a).begin(), (a).end()
#define fi first
#define se second
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};


int main(){
    vector<vector<int>> G(3, vector<int>(3));
    for(int i = 0; i < 3; i++) for(int j = 0; j < 3; j++) cin >> G[i][j];
    bool ok = true;
    for(int i = 0; i < 2; i++){
        int c;
        for(int j = 0; j < 3; j++){
            if(j == 0) c = G[i][j] - G[i + 1][j];
            else if(c != G[i][j] - G[i + 1][j]) ok = false;
        }
    }
    for(int j = 0; j < 2; j++){
        int c;
        for(int i = 0; i < 3; i++){
            if(i == 0) c = G[i][j] - G[i][j + 1];
            else if(c != G[i][j] - G[i][j + 1]) ok = false;
        }
    }
    if(ok) puts("Yes");
    else puts("No");
}

Measured memory_bytes: 3596
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>
#include <vector>
#include <bitset>
#include <string>
#include <cmath>
#include <set>
#include <map>
#define Rep(i, x, y) for (int i = x; i <= y; i ++)
#define Dwn(i, x, y) for (int i = x; i >= y; i --)
#define RepE(i, x) for (int i = pos[x]; i; i = g[i].nex)
#define ev g[i].y
#define eps 1e-10
#define fr first
#define sd second
#define pb push_back
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
const int N = 200005, mod = 998244353;
int n, m, T, q, k, f1, f2;
char s[N];
ll ans;
ll power(ll x, int y) {
	ll z = 1;
	while (y) {
		if (y & 1) (z *= x) %= mod;
		y >>= 1; (x *= x) %= mod;
	}
	return z;
}
int main()
{
	scanf ("%s", s + 1);
	n = strlen(s + 1);
	Rep(i, 1, n) {
		k += s[i] - 'a';
	}
//	cout <<k<<endl;
	ans = (power(3, n - 1) - power(2, n - 1) + mod) % mod;
	Rep(i, 1, n - 1) {
		if (s[i] != s[i + 1]) f1 = 1;
		if (s[i] == s[i + 1]) f2 = 1;
	}
	if (!f1) {
		puts("1");
		return 0;
	}
	if (n == 3 && k == 3) {
		puts("3");
		return 0;
	}
	ans += !f2;
	if (n % 3 == 0) {
		ll z = power(2, n / 3 - 1); // % mod;
		if (k % 3 == 0) ans -= z * 2 % mod;
		else ans += z;
	}
	printf("%lld\n", (ans + mod) % mod);
	return 0;
}

Measured memory_bytes: 384
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
t = [0]*n
for i in range(n):
  t[i] = b[i]-a[i]
tot = sum(t)
k = 0
for x in t:
  if x > 0:
    k += (x-1)//2 + 1
if k <= tot:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 4596
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String s = sc.next();
		
		long r = s.replaceAll("[^R]", "").length();
		long g = s.replaceAll("[^G]", "").length();
		long b = s.replaceAll("[^B]", "").length();
		
		long cnt = r * g * b;
		
		for (int i = 0; i < n - 2; i++) {
			for (int j = i + 1 ; j < n - 1; j++) {
				int k = j + (j - i);
				if (k >= n) continue;
				if (s.charAt(i) != s.charAt(j)
					&& s.charAt(j) != s.charAt(k)
					&& s.charAt(k) != s.charAt(i))
					cnt--;
			}
		}
		
		System.out.println(cnt);
		
		sc.close();
	}
}



Measured memory_bytes: 29624
n,k = gets.chomp.split(" ").map{|i|i = i.to_i}
total=0.0
n.times do|_i_|
  i = 1 + _i_
  j=i
  count=0
  while (j<k) do
    j = j*2
    count+=1
  end
  #puts "now j = #{j}, count = #{count}"
  #puts "1/#{n} = #{1.0/n}"
  #puts "1/(2**#{count}) = #{1.0/(2**count)}"
  total += ( 1.0/n * 1.0/(2**count) )
  #puts "now i = #{i}, total = #{total}"
end

puts total

Measured memory_bytes: 3836
#include <iostream>
#include <climits>
using namespace std;
using ll = long long;

int dig(ll n){
    int cnt = 0;
    while(n > 0){
        cnt++;
        n /= 10;
    }
    return cnt;
}

int main(void){
    ll n,ans = INT_MAX;
    cin >> n;
    
    for(ll i = 1;i*i <= n;i++){
        if(n % i != 0){
            continue;
        }
        ll b = (n/i);
        int tmp = max(dig(i),dig(b));
        if(ans > tmp){
            ans = tmp;
        }
    }
    
    cout << ans << endl;
    return 0;
}

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

if X >= 400 and X <= 599:
  print(8)
elif X >= 600 and X <= 799:
  print(7)
elif X >= 800 and X <= 999:
  print(6)
elif X >= 1000 and X <= 1199:
  print(5)
elif X >= 1200 and X <= 1399:
  print(4)
elif X >= 1400 and X <= 1599:
  print(3)
elif X >= 1600 and X <= 1799:
  print(2)
else:
  print(1)

Measured memory_bytes: 9188
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>

#define DIV 998244353

using namespace std;
using ll = long long;
using ldb = long double;

int main() {
    ll N, M; cin >> N >> M;
    map<ll,ll> cnt;
    ll total = 0.;
    for (int i = 0; i < N; i++) {
        ll a; cin >> a;
        total += a;
        cnt[total % M]++;
    }
    cnt[0]++;
    ll ans = 0;
    for (auto x:cnt) {
        //cout << x.first << " " << x.second << endl;
        ans += (x.second - 1) * x.second / 2;
    }
    cout << ans << endl;
}


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

//types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<pll> vpl;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[8] = {-1, 0, 1, 0, -1, -1, 1, 1};
const int dy[8] = {0, -1, 0, 1, -1, 1, -1, 1};

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

  ll a,b,k;
  cin>>a>>b>>k;
  REP(i,k/2){
    ll ta=a;
    ll tb=b;
    a=ta/2+(tb+ta/2)/2;
    b=(tb+ta/2)/2;
  }

  if(k%2==1){
    b = b+a/2;
    a = a/2;
  }

  cout<<a<<" "<<b<<endl;
}



Measured memory_bytes: 256
use std::collections::HashMap;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn main() {
    let n: i8 = read();
    let strings: Vec<_> = (0 .. n).map(|_n| read::<String>()).collect();
    let strings_uses_chars = strings.iter().map(|s| {
        let mut uses_chars = HashMap::new();
        let chars = s.chars().collect::<Vec<_>>();
        for c in chars.iter() {
            let mut count = uses_chars.entry(*c).or_insert(0);
            *count += 1;
        }
        uses_chars
    }).collect::<Vec<_>>();
    let min_maps = strings_uses_chars.get(0).unwrap().clone();
    let min_map: HashMap<_, _> = strings_uses_chars.iter().fold(min_maps, |uses_chars, sets| {
        let mut same_chars: HashMap<char, i8> = HashMap::new();
        for map in &[sets, &uses_chars] {
            for (c, num) in map.iter() {
                let mut count = same_chars.entry(*c).or_insert(*num);
                if *count > *num {
                    *count = *num;
                }
            }
        }
        same_chars.into_iter().filter(|pair| {
            let (c, _) = *pair;
            uses_chars.get(&c).is_some() && sets.get(&c).is_some()
        }).collect::<HashMap<_, _>>()
    });
    let mut min_map_pairs: Vec<_> = min_map.into_iter().collect();
    min_map_pairs.sort_by(|pair_a, pair_b| {
        let (a, _) = *pair_a;
        let (b, _) = *pair_b;
        a.cmp(&b)
    });
    let result = min_map_pairs.iter().map(|pair| {
        let (c, num) = *pair;
        String::from_utf8(vec![c as u8; num as usize]).unwrap()
    }).collect::<Vec<_>>().concat();
    println!("{}", result);
}


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

const int N = 100001;
int f[N], inv[N], k, n;

inline int read() {
	int x = 0, flag = 1;
	char ch = getchar();
	while (!isdigit(ch)) {
		if (ch == '-') flag = -1;
		ch = getchar();
	}
	while (isdigit(ch)) {
		x = x * 10 + ch - 48;
		ch = getchar();
	}
	return x * flag;
}


inline int qp(int base, int pow) {
	int res = 1;
	while (pow) {
		if (pow & 1)
		res = res * base, res %= mo;
		base = base * base;
		base %= mo;
		pow >>= 1;
	}
	return res;
}

inline void pre() {
	f[0] = 1;
	for (register int i = 1; i <= 100000; ++i) {
		f[i] = f[i - 1] * i;
		f[i] %= mo;
	}
	inv[100000] = qp(f[100000], mo - 2);
	for (register int i = 99999; i >= 0; --i) {
		inv[i] = inv[i + 1] * (i + 1) % mo;
	}
}

inline int C(int n, int m) {
	if (n < m) return 0;
	return f[n] * inv[n - m] % mo * inv[m] % mo;
}

void solve(int x) {
	int t = 0;
	for (int i = 1; i <= x / 2; ++i) {
		int a = i, b = x - i;
		if (a <= k && b <= k) t++;
	}
//	printf("%lld %lld\n", x, t);
	int flag = 1, w = t, res = 0;
	for (int i = 1; i <= t; ++i) {
		(res += C(n + k - 1 - 2 * i, k - 1) * flag * C(t, i) % mo) %= mo;
		w--;
		flag = -flag;
	}
	int ans = (C(n + k - 1, k - 1) - res + mo) % mo;
	printf("%lld\n", ans);
}

signed main() {
	pre();
	k = read(), n = read();
	for (int i = 2; i <= 2 * k; ++i) {
		solve(i);
	}
	return 0;
}

Measured memory_bytes: 5320
#include <stdint.h>
#include <stdio.h>
#include <algorithm>

uint64_t f(uint64_t A, uint64_t B, uint64_t bit) {
    B ^= bit;
    for (uint64_t bit = 1; bit < B; B |= bit, bit *= 2);
    if (B + 1 >= A) {
        return bit;
    }
    return B + 1 + (bit - A);
}

uint64_t solve(uint64_t A, uint64_t B) {
    uint64_t bit = 1;
    for (; 2 * bit <= B; bit *= 2);
    uint64_t count = 0;
    for (; A != B; bit /= 2) {
        A &= (bit << 1) - 1;
        B &= (bit << 1) - 1;
        if ((A ^ B) & bit) {
            count += f(A, B, bit);
            B = bit - 1;
        }
    }
    return count + 1;
}

int main() {
    for (long long unsigned A, B; scanf("%llu%llu", &A, &B) == 2;) {
        printf("%llu\n", (long long unsigned)solve(A, B));
    }
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,o,n) for(long long i = o;i<n;i++)
#define oneforall ios::sync_with_stdio(false);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define int long long 
const long long inf=1e18;
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;
typedef vector<pair<long, long > > vpll;
typedef vector<pair<int, int > > vpii;
#define FORR(x,arr) for(auto& x:arr)
#define ZERO(a) memset(a,0,sizeof(a))





//3111111111111111111111111111111

	
	void solve(){

		ins(morty);
		int tmp = -1;
		int tmp1 = -1;
		FOR(i,0,morty.size()-1){
			if(morty[i] == morty[i+1]){tmp = i+1;tmp1 = i+2;break;}
		}
		FOR(i,0,morty.size()-2){
			if(morty[i] == morty[i+2]){tmp = i+1;tmp1 = i+3;break;}
		}
		out(tmp,tmp1);




















	}























int32_t main() {
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall 
	oneforall

	solve();
	


	return 0;
}


Measured memory_bytes: 512
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

const int INF = 1001001001;

int main()
{
	int n;
	while(scanf("%d", &n), n){
		pii data[200];
		rep(i, n){
			int m, a, b;
			scanf("%d%d%d", &m, &a, &b);
			data[i*2] = pii(a, m);
			data[i*2+1] = pii(b, -m);
		}
		sort(data, data+2*n);
		
		int w = 0;
		bool ok = true;
		rep(i, 2*n){
			w += data[i].second;
			if(w > 150){
				ok = false;
				break;
			}
		}
		puts(ok ? "OK" : "NG");
	}
	return 0;
}

Measured memory_bytes: 1012
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<queue>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

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


	int N = getint(), X = getint();
	ll kotae = 0;
	int A[2002], B[2001];
	rep(i, N) {
		A[i] = getint();
		kotae += A[i];
		B[i] = 1;
	}

	int dai[2002], shou[2002];
	rep(i, N - 1) dai[i + 1] = i;
	dai[0] = N - 1;
	rep1(i, N - 1) shou[i - 1] = i;
	shou[N - 1] = 0;

	queue<int> P[2], Q[2];
	rep(i, N) {
		int a = i - 1 < 0 ? N - 1 : i - 1;
		int b = i + 1 >= N ? 0 : i + 1;
		if (A[a] < A[i] && A[i] >= A[b]) {
			P[0].push(i);
		}
		if (A[a] > A[i] && A[i] <= A[b]) {
			Q[0].push(i);
		}
	}

	ll kari = kotae;
	rep(i, N) {
		int mae = i & 1;
		int tugi = mae ^ 1;
		while (P[mae].size()) {
			int j = P[mae].front();
			P[mae].pop();
			kari -= A[j];
			if (B[j] >= 2) {
				B[j]--;
				P[tugi].push(j);
			}
			else {
				B[j] = 0;
				int l = j - 1 < 0 ? N - 1 : j - 1;
				l = shou[l];
				int l2 = l - 1 < 0 ? N - 1 : l - 1;
				int r = j + 1 >= N ? 0 : j + 1;
				r = dai[r];
				int r2 = r + 1 >= N ? 0 : r + 1;
				if (A[l2] < A[r2]) {
					int r3 = r2 + 1 >= N ? 0 : r2 + 1;
					r3 = dai[r3];
					int r4 = r3 + 1 >= N ? 0 : r3 + 1;
					if (A[r2] >= A[r4]) P[tugi].push(r2);
				}
				else {
					int l3 = l2 - 1 < 0 ? N - 1 : l2 - 1;
					l3 = shou[l3];
					int l4 = l3 - 1 < 0 ? N - 1 : l3 - 1;
					if (A[l4] < A[l2]) P[tugi].push(l2);
				}
				dai[l] = r;
				shou[r] = l;
			}
		}
		while (Q[mae].size()) {
			int j = Q[mae].front();
			Q[mae].pop();
			B[j]++;
			kari += A[j];
			int l = j - 1 < 0 ? N - 1 : j - 1;
			l = shou[l];
			int l2 = l - 1 < 0 ? N - 1 : l - 1;
			int r = j + 1 >= N ? 0 : j + 1;
			r = dai[r];
			int r2 = r + 1 >= N ? 0 : r + 1;
			if (A[l2] > A[j] && A[j] <= A[r2]) {
				Q[tugi].push(j);
			}
		}
		kari += X;
		chmin(kotae, kari);
	}

	printf("%lld\n", kotae);

	Would you please return 0;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
int a[100005], b[100005];
vector<int>d[100005];
signed main() {
	int n, m; cin >> n >> m;
	rep(i, n)cin >> a[i] >> b[i];

	int ans = 0;
	rep(i, n) {
		if (m - a[i] >= 0) {
			d[m - a[i]].push_back(b[i]);
		}
	}
	priority_queue<int>Q;
	for (int i = m; i >= 0; i--) {
		rep(j, d[i].size())Q.push(d[i][j]);
		if (Q.size()) {
			ans += Q.top();
			Q.pop();
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 7296
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()

const int N = 1234567;

ll mpow(ll a, ll b){
	if(b==0) return 1;
	else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
	else return mpow(a,b-1) * a % MOD;
}
ll gcd(ll a, ll b){
	if(b==0) return a;
	else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
	if(kaijo_memo.size() > n) return kaijo_memo[n];
	if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
	while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
	return kaijo_memo[n];
}
ll nCr(ll n, ll r){
	if(n < r || r < 0) return 0;
	ll ret = 1;
	ret *= kaijo(n); ret %= MOD;
	ret *= mpow(kaijo(r), MOD-2); ret %= MOD;
	ret *= mpow(kaijo(n-r), MOD-2); ret %= MOD;
	return ret;
}

int main(void){
	int x;
	cin>>x;
	cout<<(x==7||x==5||x==3?"YES":"NO")<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
  int n; cin>>n;
  string s="";
  ll ba=0,a=0,b=0,ans=0;
  for(int i=0;i<n;i++){
    string t; cin>>t;
    for(int j=0;j<t.size()-1;j++){
      if(t[j]=='A' && t[j+1]=='B'){
        ans++;
      }
    }
    if(t[0]=='B' && t[t.size()-1]=='A'){
      ba++;
    }else if(t[0]=='B'){
      b++;
    }else if(t[t.size()-1]=='A'){
      a++;
    }
  }
  if(ba==0){
    ans+=min(a,b);
  }else if(a==0 && b==0){
    ans+=ba-1;
  }else{
    ans+=min(a,b)+ba;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    static int max=410000;	//nCr の n の最大値?
    static int MOD=1000000007;
    static long[] fac=new long[max];
    static long[] finv=new long[max];
    static long[] inv=new long[max];
    public static void main(String[] args) {
        COMinit();
        Scanner sc = new Scanner(System.in);
        long m=1000000007L;
        int N=sc.nextInt();
        int K=sc.nextInt();

        long ans=0;
        for(int i=0; i<=Math.min(N-1,K); i++){
            ans += COM(N,i) * COM(N-1 , N-i-1);
            ans %= m;
        }
        pl(ans);
    }
    public static void pl(Object o){
        System.out.println(o);
    }
    public static void p(Object o){
        System.out.println(o);
    }
    static void COMinit() {		//テーブルを作るみたい nCrの　または　階乗の？
        fac[0] = fac[1] = 1;
        finv[0] = finv[1] = 1;
        inv[1] = 1;
        for (int i = 2; i < max; i++){
            fac[i] = fac[i - 1] * i % MOD;
            inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
            finv[i] = finv[i - 1] * inv[i] % MOD;
        }
    }
    static long COM(int n, int k){			//二項係数の計算
        if (n < k) return 0;
        if (n < 0 || k < 0) return 0;
        return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
    }
}


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

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;
using std::bitset;

#define rep(i,n)    for(int i=0; i<(int)n; i++)
#define reps(i,s,e) for(int i=s; i<(int)e; i++)
#define coutd(i) cout << std::fixed << std::setprecision(i)
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, ll> pll;

template<class T>
using Graph = vector<vector<T>>;

const int INT_BIG = 1<<28;

int main() {
    int N;
    cin >> N;
    vll As(N);
    rep(i, N) {
        cin >> As[i];
    }
    std::sort(As.begin(), As.end());


    ll nNumber = As[N-1];
    int left = -1;
    int right = N;
    while(right - left > 1) {
        int mid = (left + right) / 2;
        if (As[mid] <= nNumber / 2) {
            left = mid;
        } else {
            right = mid;
        }
    }
    ll rNumber = ((As[right] - nNumber/2.0 >= nNumber/2.0 - As[left] || nNumber == As[right]) ? As[left] : As[right]);

    
    cout << nNumber << " " << rNumber << endl;
}

Measured memory_bytes: 1024
import sys
input = sys.stdin.readline
N = int(input())
S = list(input())

e, w = 0, 0
right, left = [], []
for s in S:
    if s == 'E':
        e += 1
    else:
        w += 1
    left.append([e, w])
ss = list(reversed(S))
e, w = 0, 0
for s in ss:
    if s == 'E':
        e += 1
    else:
        w += 1
    right.append([e, w])
right.reverse()
ans = float('inf')

for i in range(N):
    if i == 0:
        ans = min(ans, right[1][0])
    elif i == N - 1:
        ans = min(ans, left[-2][1])
    else:
        ans = min(ans, right[i + 1][0] + left[i - 1][1])
print(ans)


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

long long dp[100001][8], a[100001][3], n, k;

long long magic(int idx, int last){
	if(idx == n)
		return 0;
	long long &ret = dp[idx][last];
	if(~ret)
		return ret;
	ret = INT_MIN;
	if(last != 0)
		ret = max(ret, a[idx][0] + magic(idx + 1, 0));
	if(last != 1)
		ret = max(ret, a[idx][1] + magic(idx + 1, 1));
	if(last != 2)
		ret = max(ret, a[idx][2] + magic(idx + 1, 2));
	return ret;
}

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

	memset(dp, -1, sizeof dp);
	cin >> n;
	for(int i = 0; i < n; ++i){
		for(int j = 0; j < 3; ++j)
			cin >> a[i][j];
	}
	cout << magic(0, 5);
	return 0;
}

Measured memory_bytes: 15104
#include <stdio.h>
#include <math.h>
int main(void)
{
    int n, i, x[1000], y[1000];
    double p2, p3, max = 0;
    double dp1, dp2, dp3;
 
    dp1 = dp2 = dp3 = 0;
    p2 = p3 = 0;
 
    scanf("%d", &n);
 
    for (i = 0;i < n;i++)
    {
        scanf("%d", &x[i]);
    }
    for (i = 0;i < n;i++)
    {
        scanf("%d", &y[i]);
    }
    for (i = 0;i < n;i++)
    {
        dp1 += abs(x[i] - y[i]);
        p2 += pow((x[i] - y[i]), 2);
        p3 += pow(abs(x[i] - y[i]), 3);
    }
    dp2 = sqrt(p2);
    dp3 = cbrt(p3);
    for (i = 0;i < n;i++)
    {
        if (max < abs(x[i] - y[i]))
        {
            max = abs(x[i] - y[i]);
        }
    }
    printf("%.6f\n %.6f\n %.6f\n %.6f\n", dp1, dp2, dp3, max);
 
    return 0;
}


Measured memory_bytes: 2112
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
    int n, a[101], cnt = 0;
    scanf("%d", &n);
    for(int i = 1; i <= n; i++){
        scanf("%d", &a[i]);
    }
    for(int i = 1; i <= n ; i += 2){
        if(a[i] % 2 != 0)
            cnt++;
    }
    printf("%d\n", cnt);
    return 0;
}


Measured memory_bytes: 3716
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
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; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1367>
 問題文============================================================
 =================================================================
 解説=============================================================
 先に1..nまで昇順になるように優先順位を割り振っておく、
 各クエリが与えられるごとにそれまでよりも優先順位が高い数字を
 与えられた値に割り当てて、最後に優先順位に応じてソートしてやればいい
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    int n,m; cin >> n >> m;
    vector<int> e(m);
    for(auto& in:e) cin >> in;
    vector<pii> integers(n);
    for(int i = 0; i < n;i++){
        integers[i] = {i+1,i+1};
    }
    for(int i = 0; i < m;i++){
        integers[e[i]-1].first = -i;
    }
    sort(integers.begin(),integers.end());
    for(auto p:integers){
        cout << p.second << endl;
    }
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    solve(0);
    // cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}



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

long long K,A,B,n,N,M;

int main(){
	cin >> K >> A >> B;
	n=1;
	N=0;
	for(int i=0;i<K;i++){
		if(A<B){
			if(M>=1&&B>=1){
				M--;
				n+=B;
				continue;
			}
			else if(B>=2&&i<=K-2&&n>=A&&B-A>=2){
				M++;
				n-=A;
				continue;
			}
			else{
				n+=1;
				continue;
			}
		}
		else{
			n+=1;
			continue;
		}
	}
	cout << n <<endl;
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <string>
#define ll long long
using namespace std;
int main(){
    ll n;
    cin>>n;
    ll total=0;
    ll price[1001];
    ll p;
    cin>>p;
    for (ll i = 0; i <n ; ++i) {
        cin>>price[i];
    }
    sort(price,price+n);
    for (int j = 0; j <p ; ++j) {
        total+=price[j];
    }
    cout<<total<<endl;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 100;
int n , a[N] , b[N] , w;
long long dp[200][N] , INF = -2e12 - 1 ,ans = 0;
int main(){
    scanf("%d%d", &n , &w);
    for(int i = 0 ; i < n ; i++){
        scanf("%d%d", &a[i] , &b[i]);
    }
    for(int i = 0 ; i < n ; i++)
        for(int j = 1 ; j <= w ; j++)
            dp[i][j] = INF;
    for(int i = 0 ; i < n ; i++)
        dp[i][0] = 0;
    dp[0][a[0]] = b[0];
    for(int i = 0; i < n ; i++){
        for(int j = 0 ; j <= w ; j++){
            if(i > 0)
            dp[i][j] = dp[i - 1][j];
            if(a[i] <= j && i)
            dp[i][j] = max(dp[i][j] , dp[i - 1][j - a[i]] + b[i]);
            ans = max(dp[i][j] , ans);
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 80128
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Map<String, Integer> map = new HashMap<String, Integer>();
		
		int N = sc.nextInt();
		String [] s = new String[N];
		for (int i=0; i<N; i++) {
			s[i] = sc.next();
			Integer c = map.get(s[i]);
			if (c == null) c =1;
			else c++;
			map.put(s[i],c);
		}
		int M = sc.nextInt();
		String [] t = new String[M];
		for (int i=0; i<M; i++) {
			t[i] = sc.next();
			Integer c = map.get(t[i]);
			if (c == null) c =-1;
			else c--;
			map.put(t[i],c);
		}
		Object[] a = map.values().toArray();
		int res = 0;
		for (int i=0; i<a.length; i++) {
			res = Math.max(res, (Integer)a[i]);
		}
		System.out.println(res);
	}
}


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

int main() {
  int A,B,C,D,X,Y,S=0;
  cin >> A>> B;
for(int i = A;i<B+1;i++){
C=i/10000;
D=(i-C*10000)/1000;
  X=i-C-D*10;
  Y=X%100;
  if(Y==0){
    S=S+1;
  }
  
}
cout<<S<<endl;
}


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

N = int(input())

alpha = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k']

ans = []
def dfs(idx, cnt, lis):
    if idx==N:
        ans.append(''.join(lis))
        return
    for i in range(cnt):
        dfs(idx+1, cnt, lis+[alpha[i]])
    dfs(idx+1, cnt+1, lis+[alpha[cnt]])
    return

dfs(0, 0, [])
ans.sort()
for a in ans:
    print(a)

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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;

template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	os << v[0];
	for (int i = 1; i < v.size(); i++) os << " " << v[i];
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u; return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}


void Main() {
	ll a, b, c;
	cin >> a >> b >> c;
	if (c-a-b >= 0 && a*b*4 < (c-a-b) * (c-a-b)) { 
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(20);
	Main();
	return (0);
}


Measured memory_bytes: 256
from collections import Counter
N = int(input())
A = list(map(int, input().split()))

C = Counter(A)

if C[0] == N:
  print('Yes')
elif N%3 > 0:
  print('No')
elif len(C) == 2 and C[0] == N//3:
  print('Yes')
elif len(C) == 3:
  k = list(C.keys())
  v = list(C.values())
  if v[0] == v[1] and v[1] == v[2]:
    if k[0] ^ k[1] ^ k[2] == 0:
      print('Yes')
      exit(0)
      
  print('No')
else:
  print('No')
 
      

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

int main(){
 int t;
  cin>>t;
  set<string> s;
  while(t--){
    string g;
    cin>>g;
    s.insert(g);
  }
  
  cout<<s.size()<<"\n";
  
  return 0;
}


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

// aを常に小さい値にする　大きい値にする
template<class T> bool chmin(T &a, T b){ if(a>b) a = b; }
template<class T> void chmax(T &a, T b){ if(a<b) a = b; }

// 二分探索 前方のindexを返すもの（自分自身を含む） 前方: -INF側のこと
template<class T> int former(const vector<T> &v, T x){
    return upper_bound(v.begin(), v.end(), x) - v.begin() -1; // upper_bound : keyより大きい要素の内の一番左側のイテレータを返す
}
// 二分探索 後方のindexを返すもの（自分自身を含む）後方: INF側のこと
template<class T> int latter(const vector<T> &v, T x){
    return lower_bound(v.begin(), v.end(), x) - v.begin(); // lower_bound : key以上の要素の内の一番左側のイテレータを返す
}

// 最大公約数を求める GCD
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }


// 素因数分解 pair
vector<pair<ll, ll> > prime_factorize(ll n) {
    vector<pair<ll, ll> > res;
    for (ll p = 2; p * p <= n; ++p) {
        if (n % p != 0) continue;
        int num = 0;
        while (n % p == 0) {
            ++num;
            n /= p;
        }
        res.push_back(make_pair(p, num));
    }
    if (n != 1) res.push_back(make_pair(n, 1));
    return res;
}

const int MAX = 210000;
const int MOD = 1000000007;

//  二項係数の計算nCk セット
//  https://drken1215.hatenablog.com/entry/2018/06/08/210000
//  使い方としては、最初に一度前処理として COMinit() をしておけば、あとは COM(n, k) 関数を呼べばよい
//  前処理 COMinit(): O(n)
//　クエリ処理 COM(n, k): O(1)
ll fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int vector_finder(std::vector<int> vec, int number) {
    auto itr = std::find(vec.begin(), vec.end(), number);
    size_t index = std::distance( vec.begin(), itr );
    if (index != vec.size()) { // 発見できたとき
        return 1;
    }
    else { // 発見できなかったとき
        return 0;
    }
}

/*
 * 「配列連続する区間」は、「累積和をとった配列上の 2 点」と同一視することができるという超頻出視点
 * A[left, right) が M の倍数
⇔ S[right] - S[left] が M の倍数
⇔ S[right] と S[left] を M で割ったあまりが等しい

 A の累積和配列 S を考える (スタートの「0」を忘れないように)
 S の各要素について M で割った余りで分類し、各余りについて何個あるのかを計上する
 (ただし M <= 10^9 なので、登場しうる余りが高々 N+1 個であることを利用して連想配列なりを用意する)
 各余りについて個数を p としたとき、p(p-1)/2 を加算する(同じ値の数から 2 つ選ぶときの組み合わせの個数が解になります。)

 *
 * */

int main() {

    int N, M;
    cin >> N >> M;

    vector<ll> A(N);
    rep(i,N) cin >> A[i];

    map<ll, ll> nums;
    ll sum = 0;
    nums[sum]++;

    rep(i,N){
        sum += A[i];
        nums[sum % M]++;
    }

    ll res = 0;
    for(map<ll, ll>::iterator it = nums.begin(); it != nums.end(); ++it){
        res += it->second * (it->second - 1) / 2;
    }
    cout << res << endl;
}

Measured memory_bytes: 4992
# -*- coding: utf-8 -*-

# AtCoder Beginner Contest
# Problem C

if __name__ == '__main__':
    n = int(input())
    a = list(map(int, input().split()))
    count = 0

    from collections import Counter
    counted_a = Counter(a)

    for x in counted_a:
        if counted_a[x] >= x:
            count += counted_a[x] - x
        else:
            count += counted_a[x]

    print(count)


Measured memory_bytes: 18168
def solve(N, K):
    M = N//K
    rem = 0

    ans = M ** 3

    if K % 2 == 0:
        for i in range(1,N+1):
            if i % K == K/2:
                rem += 1
        ans += rem ** 3

    return ans


if __name__ == '__main__':
    N, K = map(int, input().split())
    print(solve(N, K))


Measured memory_bytes: 2940
#include <stdio.h>

int main()
{
    int l, r;
    int i, j;
    int ijmod;
    int min = 2019;

    char buf[256];
    fgets(buf, 256, stdin);
    sscanf(buf, "%d %d", &l, &r);

    if((r -l)/673 >= 1){ //2019 = 673 / 3
        //printf("673, 3 must included.\n");
        printf("%d", 0);
    }else{
        for (i = l; i <= r-1; i++){
            for (j = i+1; j <= r; j++){
                ijmod = ((unsigned long)i * j) % 2019;
                if (min > ijmod){
                    //printf("i = %d j = %d : change %d -> %d\n", i, j ,min, ijmod);
                    min = ijmod;
                }
            }
        }
        printf("%d", min);
    }

}


Measured memory_bytes: 128
const lines: string[] = [];
const reader = require("readline").createInterface({
  input: process.stdin,
  output: process.stdout,
});
reader.on("line", function (line: string) {
  lines.push(line);
});

reader.on("close", function () {
  const x = Number(lines[0]);

  let a = 119;
  // let a = 10;

  while (true) {
    let b = a - x;
    b < -119 ? (b = -119) : "";
    for (let i = b; i < a; i++) {
      const sa = a - i;
      if (x % sa === 0) {
        const a5 = a * a * a * a * a;
        const b5 = i * i * i * i * i;
        if (a5 - b5 === x) {
          console.log(`${a} ${i}`);
          return;
        }
      }
    }
    a--;
  }
});


Measured memory_bytes: 32628
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>

int64_t power(int64_t a, int64_t b) {
    int64_t tmp = b;
    int64_t base = 1;
    
    while(tmp > 0) {

        if((tmp % 2) == 0){
            a *= a;
            tmp >>= 1;
        } else {
            base *= a;
            tmp--;
        }

    }
    return base;
}

int main(int argc, char *argv[]) {
    char buf[16];
    char *p;
    int N,K;
    int64_t pattern;

    p = fgets(buf, 16, stdin);
    
    (void)sscanf(buf, "%d %d", &N, &K);

    pattern = power((K-1),(N-1)) * K;
    printf("%ld\n", pattern);

    return 0;
}


Measured memory_bytes: 128
import sys
def solve():
    input = sys.stdin.readline
    N = int(input())
    if N == 2: print(1)
    else:
        K = {N, N-1}
        for i in range(2, N + 1):
            if i ** 2 > N: break
            if N % i == 0:
                k = N
                while k % i == 0:
                    k //= i
                if k % i == 1: K |= {i}
            
            if (N - 1) % i == 0:
                K |= {i}
                if i ** 2 != N - 1: K |= {(N - 1) // i}
        print(len(K))
        #print(K)
    return 0

if __name__ == "__main__":
    solve()

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

const int MAX = 110000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    // 前処理
    COMinit();
	int n, k;
	long long max_sum, min_sum;
	cin >> n >> k;

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

	max_sum = 0;
	min_sum = 0;
	sort(a.begin(), a.end(), greater<int>());
	for(int i=0; i<n-k+1; i++){
		max_sum += (a[i]*(COM(n-i-1, k-1)))%MOD;
	}
	for(int i=0; i<n-k+1; i++){
		min_sum += (a[n-i-1]*(COM(n-i-1, k-1)))%MOD;
	}
	cout << (max_sum - min_sum)%MOD << endl;
	return 0;
}

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

typedef long long ll;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const ll INF = 1<<21;
// static const ll MOD = 1e9 + 7;

// bool compPair(const pair<int, int>& arg1, const pair<int, int>& arg2) {
//     return arg1.first > arg2.first;
// }

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

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

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

    int n=s.size();
    vector<int> a(n);
    for(int in=0;in<n;in++) {
        a.at(in) = s.at(in)-'0';
    }

    int ans=1000, diff;
    for(int in=0;in<n-2;in++) {
        diff = abs(a.at(in)*100+a.at(in+1)*10+a.at(in+2)-753);
        ans = min(ans, diff);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
	int a,b,c,i,I=0;
	cin>>a>>b>>c;
	for(i=a;i<=b;i++)
	{
		if(c%i==0)
			I++;
	}
	cout<<I<<endl;
    return 0;
}


Measured memory_bytes: 3136
#include<stdio.h>
long long div[100000];
long long inde;

void getDiv(long long n){
  inde = 0;
  long long i;
  for(i=1;i*i<=n;i++)
    if(n%i == 0)
	{
	  div[inde++] = i;
	  if(i != n/i)
	    div[inde++] = n/i;
	}
}

long long gcd(long long x,long long y)
{
  long long r;
  if(x < y)
    {
      long long tmp = x;
      x = y;
      y = tmp;
    }
  while(y > 0)
    {
      r = x%y;
      x = y;
      y = r;
    }
  return x;
}

int main()
{
  long long n;
  
  while(1)
    {
      scanf("%lld",&n);
      if(n == 0)
	break;
      long long cnt = 0;
      long long i,j;
      getDiv(n);
      for(i=0;i<inde;i++)
	{
	  for(j=i;j<inde;j++)
	    {
	      long long a,b;
	      a = div[i];
	      b = div[j];
	      if(a/gcd(a,b)*b == n)
		cnt++;
	    }
	}
      printf("%lld\n",cnt);
    }
  
  return 0;
}

Measured memory_bytes: 612
def main():
    result = sub()
    print(result)


def sub():
    N = int(input())
    As = [int(i) for i in input().split()]

    abssum = 0
    negative_count = 0
    is_zero_contained = False
    absmin = 10**9

    for i in range(N):
        val = As[i]
        if val > 0:
            abssum += val
            absmin = min(absmin, val)
        elif val < 0:
            abssum -= val
            negative_count += 1
            absmin = min(absmin, -val)
        else:  # 0
            is_zero_contained = True
            absmin = 0

    if is_zero_contained:
        return abssum
    elif negative_count % 2 == 0:
        return abssum
    else:
        return abssum - 2 * absmin

    return abssum


if __name__ == '__main__':
    main()


Measured memory_bytes: 14468
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
#include <functional> // for less
/*
#pragma GCC optimize ("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
*/

#define FASTIO ios::sync_with_stdio(0); cin.tie(0);
#define show(x) cout << #x << " = " << x << "\n"
#define mem( a , b ) memset( a , b , sizeof a )
#define popcnt(x) __builtin_popcount(x)
#define all(x) x.begin() , x.end()
#define mod(x,m) ((x%m + m )%m)
#define SZ(a) (int)a.size()
#define ll  long long
#define ld  long double
#define vii vector  <ll>
#define dqi deque   <ll>
#define sii set     <ll>
#define vpi vector  <pii>
#define mii map     <ll,ll>
#define pii pair    <ll,ll>
#define pi  pair    <int,int>
#define pb  push_back
#define F   first
#define S   second
#define L   length()
#define OO  (ll)1e18
#define lSOne(x)(x&-x)
#define EPS 1e-20
using namespace std;
using namespace __gnu_pbds;
void ONLINE__JUDGE();

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

pii swapii( pii pr ){ return { pr.S , pr.F }; }
ll binEXP( ll x , ll pw , ll MOD = LLONG_MAX );
int dx[] = {  0 ,  0 , -1 , +1 , -1 , +1 , -1 , +1 };
int dy[] = { -1 , +1 ,  0 ,  0 , -1 , +1 , +1 , -1 };

const ll MOD = 1e9 + 7;
const ll MAX = 2e5 + 9;

ll x , y;
vii adj[MAX];
vii cnt;

int main(){
    FASTIO //ONLINE__JUDGE();

    cin >> x >> y; cnt.resize(MAX , 0);
    for ( int i = 0; i < x-1; ++i ){
        int u , v; cin >> u >> v;
        adj[u].pb(v); adj[v].pb(u);
    }

    for ( int i = 0; i < y; ++i ){
        int u , c; cin >> u >> c;
        cnt[u] += c;
    }

    vector<bool> vis(MAX);
    queue<pi> q; q.push({1,0});
    while ( !q.empty() ){
        pi node = q.front(); q.pop(); vis[node.F] = 1;
        cnt[node.F] += cnt[ node.S ];

        for ( auto i : adj[node.F] ){
            if ( !vis[ i ] ){
                q.push( {i , node.F} );
            }
        }
    }

    for ( int i = 1; i <= x; ++i ){
        cout << cnt[i] << " ";
    }
    return 0;
}

void ONLINE__JUDGE()
{
    #ifndef ONLINE_JUDGE
    freopen( "inp.c"         , "r" , stdin  );
    //freopen( "OutPut.txt"   , "w" , stdout );
    #endif // ONLINE_JUDGE
}

ll binEXP( ll x , ll pw , ll MOD )
{ ll res=1; while(pw>0){ pw%2 ? res *= x : 0; x *= x; x%=MOD; pw /= 2; res%= MOD; } return res%=MOD; }


Measured memory_bytes: 17904
#include <bits/stdc++.h>
using namespace std;
bool InString(string S, char c){
  for (int i = 0; i < S.size(); i++){
    if (c == S[i]) return true;
  }
  return false;
}
int main(){
  string S;
  cin >> S;
  string T = "abcdefghijklmnopqrstuvwxyz0";
  int i = 0;
  while (InString(S,T[i])) i++;
  if (T[i] == '0'){
    cout << "None";
  } else {
    cout << T[i];
  }
}

Measured memory_bytes: 512