akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;

int main(){
    ll n,m; cin >> n >> m;
    vvl s(m);
    vl k(m);
    rep(i,m){
        cin >> k[i];
        rep(j,k[i]) {
            ll t; cin >> t; t--;
            s[i].push_back(t);
        }
    }
    vl p(m);
    rep(i,m) cin >> p[i];
    ll ans = 0;
    bool flag = true;
    for(ll bit=0; bit < (1<<n); bit++){
        flag = true;
        rep(i,m){
            ll cnt = 0;
            rep(j,k[i]){
                if(bit & 1<<s[i][j]) cnt++;
            }
            if(cnt % 2 != p[i]){
                flag = false;
                break;
            }
        }
        if(flag) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int n,k;
long h[125252];
int main(){
  cin>>n>>k;
  for(int i=0;i<n;++i) cin>>h[i];
  sort(h,h+n);
  long ans = 1ll<<60;
  for(int i=0;i<n;++i)if(i+k<=n) ans = min(ans,h[i+k-1]-h[i]);
  cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <unordered_set>
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1LL << 50;
static const int NIL = -1;
static const int MOD = 1000000007;
 
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define SORT(v) sort(v.begin(), v.end());
#define pb push_back
#define mp make_pair
#define np next_permutation
#define pq priority_queue
 
int gcd(int a, int b) { int c; while (b != 0) { c = a%b; a = b; b = c; }return a; }
int lcm(int a, int b) { int c = gcd(a, b); a /= c; return a*b; }
int nCr(int a, int b) { int i, r = 1; for (i = 1; i <= b; i++) { r *= (a + 1 - i); r /= i; }return r; }
int pow(int a, int b) { int i, r = 1; for (i = 1; i <= b; i++) { r *= a; }return r; }
long long llpow(long long a, long long b) { long long i, r = 1; for (i = 1; i <= b; i++) { r *= a; }return r; }
long long llgcd(long long a, long long b) { long long c; while (b != 0) { c = a%b; a = b; b = c; }return a; }
long long lllcm(long long a, long long b) { long long c = llgcd(a, b); a /= c; return a*b; }
long long llnCr(long long a, long long b) { long long i, r = 1; for (i = 1; i <= b; i++) { r *= (a + 1 - i); r /= i; }return r; }
 
//int dx4[4] = {0,1,0,-1}, dy4[4] = {-1,0,1,0};
//int dx5[5] = {-1,0,0,0,1}, dy5[5] = {0,-1,0,1,0};
//int dx8[8] = {-1,0,1,1,1,0,-1,-1}, dy8[8] = {1,1,1,0,-1,-1,-1,0};
//int dx9[9] = {-1,0,1,1,1,0,-1,-1,0}, dy9[9] = {1,1,1,0,-1,-1,-1,0,0};
 
struct edge{
    int from, to; ll cost;
};

int main(){
    int n;
    vector<ll> a;
    cin >> n;
    REP(i, n){
        ll tmp;
        cin >> tmp;
        a.pb(tmp);
    }
    sort(a.begin(), a.end(), greater<ll>());
    ll x, y;
    bool flag = true;
    x = y = 0;
    REP(i, n - 1){
        if(a[i] == a[i + 1] && flag){
            x = a[i];
            flag = false;
            i++;
        }else if(a[i] == a[i + 1]){
            y = a[i];
            break;
        }
    }
    cout << x * y << endl;
}

Measured memory_bytes: 1400
#pragma region template
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vvvld = vector<vvld>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
template <typename T>
using pqrev = priority_queue<T, vector<T>, greater<T>>;
#define rep(i, n) for (ll i = 0, i##_end = (n); i < i##_end; i++)
#define repb(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for (ll i = (a), i##_end = (b); i < i##_end; i++)
#define reprb(i, a, b) for (ll i = (b)-1, i##_end = (a); i >= i##_end; i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
//
constexpr ll MOD = 1e9 + 7;
/*/
const ll MOD = 998244353;
//*/
constexpr ll INF = 1e+18;
constexpr ld EPS = 1e-12L;
constexpr ld PI = 3.14159265358979323846L;
constexpr ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
constexpr ll LCM(ll a, ll b) { return a / GCD(a, b) * b; }
template <typename S, typename T>
inline bool chmax(S &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename S, typename T>
inline bool chmin(S &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif
template <typename T>
bool print_(const T &a) {
  cout << a;
  return true;
}
template <typename T>
bool print_(const vector<T> &vec) {
  for (auto &a : vec) {
    cout << a;
    if (&a != &vec.back()) {
      cout << " ";
    }
  }
  return false;
}
template <typename T>
bool print_(const vector<vector<T>> &vv) {
  for (auto &v : vv) {
    for (auto &a : v) {
      cout << a;
      if (&a != &v.back()) {
        cout << " ";
      }
    }
    if (&v != &vv.back()) {
      cout << "\n";
    }
  }
  return false;
}
void print() { cout << "\n"; }
template <typename Head, typename... Tail>
void print(Head &&head, Tail &&... tail) {
  bool f = print_(head);
  if (sizeof...(tail) != 0) {
    cout << (f ? " " : "\n");
  }
  print(forward<Tail>(tail)...);
}
#pragma endregion

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  ll n, k;
  cin >> n >> k;
  vll a(n);
  rep(i, n){
    cin >> a[i];
  }
  vll bn;
  rep(i, n){
    ll sum = 0;
    repr(j, i, n){
      sum += a[j];
      bn.emplace_back(sum);
    }
  }
  sort(ALL(bn));
  //dump(bn);
  ll c = SZ(bn);
  vi f(c, 1);
  ll ans = 0;
  repb(bt, 60){
    ll cnt = 0;
    rep(i, c){
      cnt += (((bn[i] >> bt) & 1) && f[i]);
    }
    //dump(bt, cnt);
    if(cnt >= k){
      ans += (1ll << bt);
      rep(i, c){
        if(!((bn[i] >> bt) & 1)){
          f[i] = 0;
        }
      }
    }
  }
  print(ans);
}


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

int main() {
    int n, sum = 0;
    cin >> n;
    for(int i=0;i<n;i++){
        int l, r;
        cin >> l >> r;
        sum = sum + (r-l+1);
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc  __builtin_popcountl
#define m_p make_pair
#define inf 1000000000000000000
#define MAXN 1000001
#define eps 0.0000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
    return uniform_int_distribution<T>()(rng);
}

// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();

//////////////

#define S second
#define F first
#define int long long  

//////////

signed main()
{
	fastio;
	// #ifndef ONLINE_JUDGE
	// 	freopen("inputf.in","r",stdin);
	// 	freopen("outputf.in","w",stdout);
	// #endif
	int a,b;
	cin>>a>>b;
	--a;
	int ans=0;
	int t=0;
	if(((a+1)/2)%2==1)
		++t;
	if(((b+1)/2)%2==1)
		++t;
	if(t%2==1)
	{
		ans=1;
	}
	for(int i=2;i<=55;++i)
	{
		int v=(1ll<<i);
		int r=(1ll<<(i-1));
		int x=0;
		if(a%v>=r)
		{
			int j=(a%v)-r+1;
			x+=j%2;
		}
		if(b%v>=r)
		{
			int j=(b%v)-r+1;
			x+=j%2;
		}
		if(x%2==1)
			ans+=r;
	}
	cout<<ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
const ll INF = 1e10;
const ll MOD = 1e9 + 7;

int main() {
    int a,b,c; cin >> a >> b >> c;
    cout << a * b / 2 << endl;
}

Measured memory_bytes: 256
#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>;

int main()
{
    int n, x, t;
    cin >> n >> x >> t;
    cout << (n + x - 1) / x * t << endl;

    return 0;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s1,s2;
  cin>>s1;
  for(int i=0;i<s1.size();i++){
    if(s1.at(i)=='0') 
      if(s2.empty()) s2='0';
      else s2+='0';
    if(s1.at(i)=='1') 
      if(s2.empty()) s2='1';
      else s2+='1';
    if(s1.at(i)=='B')
      if(s2.size()!=0) s2.erase(s2.size()-1);
  }
  cout<<s2<<endl;
  
}

Measured memory_bytes: 256
cnt = [0] * 2020
cnt[0] = 1
s = gets.chomp
n = s.length
d = 1
cur = 0
ans = 0
n.times do |i|
  cur += s[-i-1].to_i * d
  cur %= 2019
  ans += cnt[cur]
  cnt[cur] += 1
  d *= 10
  d %= 2019
end
p ans

Measured memory_bytes: 14600
#include<stdio.h>
int main(){
  int a,b,k;
  scanf("%d%d",&a,&b);
  for(k=10;k<=b;k*=10);
  b+=a*k;
  for(k=1;k*k<b;k++);
  printf(k*k==b?"Yes":"No");
}


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

using namespace std;

int main()
{
    vector<int> vec(3);
    cin >> vec.at(0) >> vec.at(1) >> vec.at(2);
    sort(vec.begin(),  vec.end()); 
    reverse(vec.begin(),  vec.end());
    cout << vec.at(0) * 10 + vec.at(1) + vec.at(2) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <map>

#define F(n, a, b) (((a) * (n) + (b)) % 26 + 'a')
#define N(n) ((n) - 'a')

using namespace std;

int gcd(int a, int b) {
	if (a < b)
		swap(a, b);
	if (b == 0)
		return a;
	return gcd(b, a % b);
}

int main() {
	string str, ans = "";
	string _this = "this", _that = "that";
	string __this = "", __that = "";
	int n, a, b;
	getline(cin, str);
	sscanf(str.c_str(), "%d", &n);
	for (int i = 0; i < n; i++) {
		getline(cin, str);
		for (a = 1; a < 26; a++) {
			if (gcd(a, 26) != 1)
				continue;
			for (b = 0; b < 26; b++) {
				__this = __that = "";
				for (int j = 0; j < 4; j++) {
					__this += (char)F(N(_this[j]), a, b);
					__that += (char)F(N(_that[j]), a, b);
				}
				if (str.find(__this) != string::npos || str.find(__that) != string::npos)
					goto END;
			}
		}
END:
		string alpha = "abcdefghijklmnopqrstuvwxyz";
		map<char, char> decrypt;
		for (int j = 0; j < 26; j++)
			decrypt[(char)F(N(alpha[j]), a, b)] = alpha[j];
		ans = "";
		for (int j = 0; j < str.size(); j++) {
			if (isalpha(str[j]))
				ans += (char)decrypt[str[j]];
			else
				ans += (char)str[j];
		}
		cout << ans << endl;
	}
	return 0;
}

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

int main(void)
{
    int v[3];
    std::cin >> v[0] >> v[1] >> v[2];

    std::sort(&v[0], &v[3]);

    std::cout << v[0] << " " << v[1] << " " << v[2] << std::endl;

    return 0;
}

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

#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define endl '\n'
#define fcin ios::sync_with_stdio(false); cin.tie(nullptr);
#define INF 0x3f3f3f3f
#define all(x) x.begin(), x.end()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef long long ll;
typedef pair<int, int> pii;

int main(){
    fcin;
    int n;
    cin >> n;
    vector<int> ans(n);
    for(int i = 0; i < n; i++){
        int x;  cin >> x;
        ans[x-1] = i+1;
    }
    for(int i = 0; i < n; i++) cout << ans[i] << " ";
    return 0;
}



Measured memory_bytes: 1280
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>

using ll = long long;
using llp = std::pair<ll, ll>;

int main()
{
	int N, K;
	std::cin >> N >> K;

	std::vector<llp> v( N );
	for ( int i = 0; i < N; i++ )
	{
		ll t, d;
		std::cin >> t >> d;
		v.emplace_back( std::make_pair( t, d ) );
	}

	// 基礎ポイントの降順にソート
	std::sort( v.begin(), v.end(), []( llp a, llp b ) {
			return ( a.second > b.second );
		} );

	std::map<ll, ll> m;
	ll pt = 0;
	for ( int i = 0; i < K; i++ )
	{
		pt += v[i].second;	//	大きい順にとりあえず詰める
		m[v[i].first]++;	//	出てきた種類をカウントしておく
	}

	ll ptmax = pt + m.size() * m.size();	//	暫定最高値
	ll prev = ptmax;	//	前回の値
	ll pp = m.size();	//	種類をメモ
	ll big = K;	// 基礎ポイントが高く、かつまだ詰めていない種類のネタを探す
	ll sml = K - 1; // 基礎ポイントが低く、かつ詰めてしまったものを探す

	// 最大K種類入れられるので、続きを探す
	for ( int i = 1; pp + i <= K; i++ )
	{
		// すでに入れてしまった中で、重複して入れたものを探す（削っても種類が減らないもの）
		while ( ( sml >= 0 ) && ( m[v[sml].first] <= 1 ) ) --sml;

		if ( sml < 0 )
		{
			// 削れるものがなにもないので、終了
			break;
		}

		ll ppp = pp + i;
		ll tmp = prev - v[sml].second + 2 * ppp - 1; // 1種類増えるので再計算
		m[v[sml].first]--; // 個数が一つ減る
		--sml;	//	さらに前を探す

		// まだ入れていないものを探す
		while ( ( big < N ) && ( m[v[big].first] > 0 ) ) ++big;

		if ( big >= N )
		{
			// これ以上のものがないので終了
			break;
		}

		tmp += v[big].second;	// 再計算
		m[v[big].first]++;		//	新規追加
		++big;

		if ( tmp > ptmax )
		{
			ptmax = tmp;
		}
		prev = tmp;
	}

	std::cout << ptmax << std::endl;

	return ( 0 );
}


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

public class Main {
    public static void main(String[] args) {
        FastReader sc = new FastReader();
        long x = sc.nextLong();
        long k = sc.nextLong();
        long d = sc.nextLong();
        x = Math.abs(x);
        long numberofhops = (x / d);
        if (x > 0 && numberofhops >= k) {
            long distancecovered = (d * k);
            x -= distancecovered;
            System.out.println(x);
        } else {
            long distancecovered = (d * numberofhops);
            x -= distancecovered;
            k -= numberofhops;
            if (k % 2 == 0)
                System.out.println(x);
            else {
                long v1 = Math.abs(x + d);
                long v2 = Math.abs(x - d);
                System.out.println(Math.min(v1, v2));
            }
        }

    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}

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

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); cerr << endl << "Time elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms"; return 0
#define speed() cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(false)
#define exit(a, b) return cout << a, b;

#define PB push_back
#define MP make_pair

#define sd(n) scanf("%d", &n)
#define pdn(n) printf("%lld\n", n);
#define pds(n) printf("%lld ", n);
#define endl '\n'

#define forn(a, b, i) for (int i = a; i < b; i += 1)
#define all(v) v.begin(), v.end() 

using vi = vector<int>;
using vb = vector<bool>;
using pii = pair<int, int>;
using mii = map<int, int>;

#define print(stuff) cout << stuff << endl
#define len(stuff) stuff.size()

#define int long long
#define float long double 
#define ll long long

const int inf = (int) 1e16;
const int upper = (int) 4e5 + 15;
const int M = (ll) 1e9 + 7;
const int mod = (ll) 998244353;
const double eps =  1e-8;

signed main () {
	start_routine();
	speed();
	#ifndef ONLINE_JUDGE
	// freopen("input.txt", "r", stdin);	
	// freopen("output.txt", "w", stdout);
	// freopen("errlog.txt", "w", stderr);
	#endif

	int n; cin >> n;
	int arr[n + 1][3];

	for (int i = 1; i <= n; i += 1) {
		for (int j = 0; j < 3; j += 1){
			cin >> arr[i][j];
		}
	}

	int dp[n + 1][3];
	for (int i = 0; i <= n; i += 1) for (int j = 0; j < 3; j += 1) dp[i][j] = -inf;

	for (int j = 0; j < 3; j += 1) dp[1][j] = arr[1][j];

	for (int i = 2; i <= n; i += 1) {
		for (int j = 0; j < 3; j += 1) {
			for (int k = 0; k < 3; k += 1) {
				if (j == k) continue;
				dp[i][j] = max(dp[i][j], dp[i - 1][k] + arr[i][j]);
			}
		}
	}

	cout << max(max(dp[n][0], dp[n][1]), dp[n][2]);
 	end_routine();	
}

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

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);

int main(void)
{
    ll n,q,sum=0;
    cin>>n;
    map<ll,ll> mp;
    rep(i,n){
        ll a; cin>>a;
        mp[a]++;
        sum+=a;
    }
    cin>>q;
    rep(i,q){
        ll b,c;
        cin>>b>>c;
        sum+=mp[b]*(c-b);
        mp[c]+=mp[b];
        mp[b]=0;
        cout<<sum<<endl;
    }
    return 0;
}

Measured memory_bytes: 9568
N, M = list(map(int, input().split()))
AB_list = list()

for _ in range(N):
    A, B = list(map(int, input().split()))
    AB_list.append({'A': A, 'B': B})

AB_list.sort(key=lambda t: t['A'])

total_count = 0
total_money = 0
for t in AB_list:
    count = t['B'] if M - total_count > t['B'] else M - total_count
    total_count += count
    total_money += t['A'] * count
    if total_count == 0:
        break

print(total_money)


Measured memory_bytes: 41612
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
#define int long long
#define ull  unsigned long long
#define pb push_back

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

const int N = 2500000;
vector < pair < int, int > > g[N];
int depth[N];
void dfs(int v, int p = -1, int h = 0){
    for (auto u: g[v]){
        if (u.F == p) continue;
        dfs(u.F, v, h + u.S);
    }
    depth[v] = h;
}
main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt",  "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n;
    cin >> n;
    for (int i = 1; i < n; i++){
        int u, v, c;
        cin >> u >> v >> c;
        g[u].pb({v, c});
        g[v].pb({u, c});
    }
    int q, s;
    cin >> q >> s;
    dfs(s);
    for (int i = 1; i <= q; i++){
        int u, v;
        cin >> u >> v;
        cout << depth[u] + depth[v] << endl;
    }
}


Measured memory_bytes: 71680
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
const int maxx=100010;

int pre[maxx];

int find(int u){
	if(pre[u]!=u) pre[u]=find(pre[u]);
	return pre[u];
}

int main(){
	int n,m,x,y;
	cin>>n>>m;
	for(int i=0;i<n;i++) pre[i]=i;
	while(m--){
		cin>>x>>y;
		pre[find(x)]=find(y);
	}
	cin>>m;
	while(m--){
		cin>>x>>y;
		if(find(x)==find(y)) cout<<"yes"<<endl;
		else cout<<"no"<<endl;
	}
	return 0;
}


Measured memory_bytes: 4068
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
	int n,i,p,t;
	string s;
	cin >>n;
	t=0;
	p=0;
	for(i=0; i<n; i++)
	{
		cin >> s;
		if(s[0]=='A') t++;
		else t--;
		if(t<0) p=1;
	}
	if(p==0 && t==0) cout << "YES" << endl;
	else cout << "NO" << endl;
}



Measured memory_bytes: 3164
#include <bits/stdc++.h>
using namespace std;
int main(void){
    char x,y;
    //int X,Y;
    cin>>x>>y;
    if (x<y) {
        cout<<"<"<<endl;
    } else if (x>y) {
        cout<<">"<<endl;
    } else {
        cout<<"="<<endl;
    }
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def gcd(a, b):
    if b==0:
        return a
    return gcd(b, a%b)

def main():
    N, K = map(int, input().split())
    a = list(map(int, input().split()))

    gcd_ = a[0]
    for i in range(1, N):
        gcd_ = gcd(gcd_, a[i])
    
    if K%gcd_ == 0 and K <= max(a):
        print("POSSIBLE")
    else:
        print("IMPOSSIBLE")


if __name__ == "__main__":
    main()

Measured memory_bytes: 14040
#include<iostream>
using namespace std;
int main(){

  long long n;
  int a=0;

  cin >> n;
  int tmp = n;

  while(1){
    if(tmp >= 1){
      a += tmp % 10;
      tmp /= 10;
    } else {
      break;
    }
  }
  if(n % a == 0){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


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

#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<vs> vvs;

typedef vector<pair<int, int>> vpi;
typedef vector<pair<ll, ll>> vpl;
typedef vector<tuple<int, int, int>> vti;

int h, w;
int table[2001][2001];
pair<int, int> table_wh[2001][2001];


pair<int, int> dig(int y, int x){
    if (table_wh[y][x].first==0){
        int _x = x;
        while (_x < w && table[y][_x] == 0){
            _x++;
        }
        for (int i=x;i<_x;i++)
            table_wh[y][i].first = _x - x;
    }

    if (table_wh[y][x].second==0){
        int _y = y;
        while (_y < h && table[_y][x] == 0){
            _y++;
        }
        for (int i=y;i<_y;i++)
            table_wh[i][x].second = _y - y;
    }
    
    return table_wh[y][x];
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    cin >> h >> w;
    rep(i, h) rep(j, w){
        char c;
        cin >> c;
        if (c=='#') table[i][j] = 1;
    }
    int ans = 0;
    rep(i, h){
        rep(j, w){
            if (table[i][j] == 0){
                auto v = dig(i, j);
                // printf("%d %d %d %d\n", i, j, v.first, v.second);
                ans = max(ans, v.first + v.second - 1);
            }
        }
    }
    cout <<  ans << endl;
}


Measured memory_bytes: 47232
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**3
eps = 1.0 / 10**10
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []

    def f(c):
        return c in 'qwertasdfgzxcvb'

    while True:
        n,a,b,c,x = LI()
        if n == 0:
            break
        y = LI()
        i = 0
        for yi,yy in zip(y,range(n)):
            if yy == 0 and yi == x:
                continue
            while True:
                i += 1
                if i > 10000:
                    break
                x = (a*x + b) % c
                if x == yi:
                    break
        if i > 10000:
            rr.append(-1)
        else:
            rr.append(i)

    return '\n'.join(map(str, rr))


print(main())




Measured memory_bytes: 9056
#include <bits/stdc++.h>
#define endl '\n'
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define zy -2147382637
#define bql 2147483647
#define ll long long
#define ull unsigned long long
#define ld long double
#define il inline
#define sz(x) x.size()
#define maxn 100010
#define rp(i, l, r) for (int i = l; i <= r; i++)
#define rb(i, r, l) for (int i = r; i >= l; i--)
#define fi first
#define se second
#define pb push_back
#define mp make_pair

using namespace std;
ll max(ll a,ll b){if(a>b)return a;else return b;}
ll min(ll a,ll b){if(a<b)return a;else return b;}
ll lowbit(ll x){return x&(-x);}
ll prime(ll x){
   if(x<=1)return false;
   for(int i=2;i<=int(sqrt(x));i++){
	   if(x%i==0)return false;
   }return true;
}
bool cmp(ll a,ll b){return a>b;}
ll gcd(ll a,ll b){ll r;while(b>0){r=a%b;a=b;b=r;}return a;}
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
inline ll read() {
	char c = getchar(); ll w = 1; ll x = 0;
	while (!isdigit(c))
		(c == '-') && (w = -w), c = getchar();
	while (isdigit(c))
		x = (x << 1) + (x << 3) + (c ^ '0'), c = getchar();
	x *= w;
}
void fl(string name){
	freopen((name+".in").c_str(),"r",stdin);
	freopen((name+".out").c_str(),"w",stdout);
}
const int dx[8] = {-1, 1, 0, 0, -1, 1, -1, 1},
		  dy[8] = {0, 0, -1, 1, -1, -1, 1, 1};
int main(){
	fast;
	string a,b;
	cin>>a>>b;
	ll x,y;
	cin>>x>>y;
	string s;
	cin>>s;
	if(s==a)cout<<x-1<<' '<<y<<endl;
	else cout<<x<<' '<<y-1<<endl;
}/*『你强归你强，Siyuan比你强』*/





Measured memory_bytes: 256
// #define _GLIBCXX_DEBUG

#include <algorithm>
#include <chrono>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <string>
#include <vector>

#include <cmath>

#define int long long

using namespace std;

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

  if (s[0] == 'S') {
    cout << "Cloudy" << endl;
  } else if (s[0] == 'C') {
    cout << "Rainy" << endl;
  } else {
    cout << "Sunny" << endl;
  }


  return 0;
}


Measured memory_bytes: 764
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> P;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const ll MOD = 1e9 + 7;

int main(){
	int N,C,a; cin>>N>>C;
	// Y,X
	vector<vector<int>> discom(C, vector<int>(C));
	vector<vector<int>> grid(3, vector<int>(C,0));
	rep(i,C)rep(j,C)cin>>discom[i][j];
	REP(i,N)REP(j,N){
		cin>>a;
		--a;
		grid[(i+j)%3][a] ++;
	}
	ll ans = INF;
	rep(f, C){
		rep(s, C){
			rep(t, C){
				if((f-s)*(s-t)*(t-f) == 0)continue;
				ll e_ans = 0;
				rep(k,3){
					int to;
					if(k == 0)to = f;
					if(k == 1)to = s;
					if(k == 2)to = t;
					rep(i,C){
						int el_dis_com = discom[i][to];
						e_ans += grid[k][i] * el_dis_com;
					}
				}
				// printf("[f-s-t] -> [%d-%d-%d] e_ans. %lld\n", f,s,t,e_ans);
				ans = min(ans, e_ans);
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3660
int main(){
    int m,f,r;
    while(1){
        scanf("%d %d %d",&m,&f,&r);
        if(m==-1 && f==-1 && r==-1)break;
        if(m==-1 ||f==-1)printf("F\n");
        else if(m+f>=80)printf("A\n");
        else if(m+f>=65)printf("B\n");
        else if(m+f>=50)printf("C\n");
        else if(m+f>=30){
            if(r>=50)printf("C\n");
            else printf("D\n");
        }
        else printf("F\n");
    }
}


Measured memory_bytes: 2076
#include <bits/stdc++.h>
using namespace std;
int main() {
long long N;
cin>>N;
long long K;
cin>>K;
long long a[N+10]={};
long long b,c;
for(long long i=1; i<=K;i++){
cin>>b>>c;
a[b]++;
a[c+1]--;}
long long rui=0;
long long counter=0;
for(long long i=0; i<=N;i++){
rui+=a[i];
if(rui==K){
counter++;}}
cout<<counter<<endl;}


Measured memory_bytes: 1024
#include <iostream>

using namespace std;
int main(){
	int x,y;
	int sum = 0;
	int a[4];
	a[1] = 300000,a[2] = 200000,a[3] = 100000;
	cin >> x >> y;
	if(x<=3){
		sum += a[x];
	}
	if(y<=3){
		sum += a[y];
	}
	if(x==1 && y==1){
		sum += 400000;
	}
	cout << sum << endl;
}

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

int main()
{
  int a, b;
  cin >> a >> b;
  if (a < b) {
    for (int i = 0; i < b; i++) {
      cout << a;
    }
    cout << endl;
  } else {
    for (int i = 0; i < a; i++) {
      cout << b;
    }
    cout << endl;
  }
}


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

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
template<typename T> void view(T cont) {std::cout << cont << std::endl;}
template<typename T> void view(T* cont, ll sz) {rep(i, sz) std::cout << cont[i] << " "; std::cout << std::endl;}
template<typename T> void view(const std::vector<T>& v) {for (const auto& f: v) std::cout << f << " "; std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv) { for (const auto& v: vv) {view(v);}}
const long long INF = 1LL<<60;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

const int MOD = 1000000007;

int main(){
    int N, M; cin >> N >> M;
    vector<int> a;
    rep(i, M) {
        int temp; cin >> temp;
        a.push_back(temp);
    }
    vector<int> dp(N + 2, 0);
    rep(i, M) dp[a[i] + 1] = -1;
    dp[0] = -1;
    dp[1] = 1;
    for (int i = 2; i <= N + 1; i++) {
        if (dp[i] < 0) continue;
        dp[i] = max(dp[i - 2], 0) % MOD + max(dp[i - 1], 0) % MOD;
    }
    // view(dp);
    cout << dp[N + 1] % MOD << endl;
}

Measured memory_bytes: 1144
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void){
	int n, i, j;
	int a[10][10];
	memset(a, 0, sizeof(a));
	scanf("%d", &n);
	for(i=1; i<=n; i++){
		j=i;
		int c=j%10;
		while(j>=10) j/=10;
		a[c][j]++;
	}
	long ans = 0;
	for(i=0; i<=9; i++){
		for(j=0; j<=9; j++){
			ans += a[i][j]*a[j][i];
		}
	}
	printf("%ld\n", ans);
}


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

using namespace std;

int main() {
  int d, n;
  std::cin >> d >> n;
  if (n == 100) {
    n++;
  }
  switch (d) {
    case 0:
      std::cout << n << std::endl;
      break;
    case 1:
      std::cout << 100 * n << std::endl;
      break;
    case 2:
    default:
      std::cout << 10000 * n << std::endl;
      break;
  }
  return 0;
}


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

count4 = 0
count2 = 0

for i in lst:
    if i%4==0:
        count4+=1
    elif i%2==0:
        count2+=1
count1 = n-count4-count2

if count2==0 and count4>=count1-1:
    print("Yes")
elif count2!=0 and count4>=count1:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 15020
/**
 *    author:  milos
 *    created: 04.08.2020 23:11:59      
**/
#include <bits/stdc++.h>

using namespace std;

const int md = 1e9 + 7;

int main() {
  ios::sync_with_stdio(false); 
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  vector<int> b(m);
  vector<string> s(n);
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }    
  vector<vector<long long>> dp(n, vector<long long>(m, 0));
  dp[0][0] = s[0][0] == '.' ? 1 : 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (s[i][j] == '#') continue;
      if (i > 0) dp[i][j] += dp[i - 1][j];
      if (j > 0) dp[i][j] += dp[i][j - 1];
      dp[i][j] %= md;
    }
  }
  cout << dp[n - 1][m - 1] << '\n';
  return 0;   
}

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

int main(){
 int n;
 float sum=0;
 cin>>n;
 float a[1000];
 for(int i=0;i<n;i++)
    cin>>a[i];
for(int i=0;i<n;i++)
    sum=sum + (1.0/a[i]);
cout<<1.0/sum;
   return 0;
}


Measured memory_bytes: 384
#include <iostream>
using namespace std;
string a, s;
int main() {
  cin >> a >> s;
  int x = 0;
  for (int i = 0; i < (int)a.size(); i++) {
    x = x*10 + a[i] - '0';
  }
  cout << (x >= 3200 ? s : string("red"));
}

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

int main(){
	int n,q;
	cin >> n >> q;
	vector<long long > a(n);
	cinf(n,a);
	for(int j=0;j<q;j++){
		ll x; cin >> x;
		ll ans=0;
		int right=0;
		ll sum=0;
		for(int left=0;left<n;left++){
			while(right<n&& sum + a[right]<=x){
				sum+= a[right];
				++ right;
			}
			ans += (right - left);

			if(right == left) ++right;
			else sum-= a[left];
		}
		cout << ans << endl;
	}
}


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

using namespace std;

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

  map < int, pair < int, int >> plan;
  for (int i = 0; i < N; i++) {
    int t, x, y;
    cin >> t >> x >> y;
    plan[t] = make_pair(x, y);
  }
    
  int counter = 0;
  int end = plan.rbegin()->first;
  pair < int, int > prev = make_pair(0, 0);
  for (int t = 1; t <= end; t++) {
    counter += 1;
    if (plan.count(t)) {
      pair < int, int > current = plan.at(t);
      int dist = abs(prev.first - current.first) + abs(prev.second - current.second);
      if ((counter < dist) || ((counter-dist) % 2 != 0)) {
        cout << "No" << endl;
        return 0;  
      } else {
        prev = current;
        counter = 0;
      }
    } 
  }

  cout << "Yes" << endl;
}

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

using namespace std;

const int BUFFER_SIZE = 1 << 20;
char rb[BUFFER_SIZE], *rp = rb, *rt = rb;
inline char read_char() {
    return rp == rt ? (rt = rb + fread(rb, 1, BUFFER_SIZE, stdin), rp = rb, *rp ++) : *rp ++;
}
inline int read_int() {
    int x = 0;
    char ch = read_char(), flag = 0;
    while (ch != '-' && (ch < '0' || ch > '9')) {
        ch = read_char();
    }
    if (ch == '-') {
        flag = 1;
        ch = read_char();
    }
    for (x = 0; ch >= '0' && ch <= '9'; ch = read_char()) {
        x = x * 10 + (ch - '0');
    }
    return flag ? -x : x;
}

const int MAX_N = 200000 + 5;

int N, K, a[MAX_N], b[MAX_N];
int ey[MAX_N << 1], enext[MAX_N << 1], elast[MAX_N];

void dfs(int u, int fa, int x) {
    a[u] = x;
    for (int j = elast[u]; j; j = enext[j]) {
        if (ey[j] != fa) {
            dfs(ey[j], u, x ^ 1);
        }
    }
}

int main() {
    N = read_int();
    for (int i = 1, j = 1; i < N; i ++) {
        int x = read_int();
        int y = read_int();
        ey[j] = y;
        enext[j] = elast[x];
        elast[x] = j ++;
        ey[j] = x;
        enext[j] = elast[y];
        elast[y] = j ++;
    }
    dfs(1, 0, -1);
    for (int i = 1; i <= N; i ++) {
        K += a[i] == -1;
    }
    if (K <= N / 3) {
        for (int i = 1, j = 3; i <= N; i ++) {
            if (a[i] == -1) {
                a[i] = j;
                b[j] = 1;
                j += 3;
            }
        }
        for (int i = 1, j = 1; i <= N; i ++) {
            if (a[i] < 0) {
                a[i] = j;
                b[j] = 1;
                for (; b[j]; j ++);
            }
        }
    } else if (N - K <= N / 3) {
        for (int i = 1, j = 3; i <= N; i ++) {
            if (a[i] == -2) {
                a[i] = j;
                b[j] = 1;
                j += 3;
            }
        }
        for (int i = 1, j = 1; i <= N; i ++) {
            if (a[i] < 0) {
                a[i] = j;
                b[j] = 1;
                for (; b[j]; j ++);
            }
        }
    } else {
        for (int i = 1, j = 1, k = 2; i <= N; i ++) {
            if (a[i] == -1 && j <= N) {
                a[i] = j;
                j += 3;
            } else if (a[i] == -2 && k <= N) {
                a[i] = k;
                k += 3;
            }
        }
        for (int i = 1, j = 3; i <= N; i ++) {
            if (a[i] < 0) {
                a[i] = j;
                j += 3;
            }
        }
    }
    for (int i = 1; i <= N; i ++) {
        printf("%d%c", a[i], i < N ? ' ' : '\n');
    }
    return 0;
}

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

#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;

typedef tree<
ll,
null_type,
less<ll>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
// ordered_set X;
// *X.find_by_order(i) = ith largest element (counting from zero)
// X.order_of_key(k) = number of items in X < k (strict lt)

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

    string S;
    ll K;
    cin >> S;
    cin >> K;

    vi chunks;

    int cur = 1;
    for (int i=1; i<S.size(); i++) {
        if (S[i] == S[i-1]) cur++;
        else {
            chunks.push_back(cur);
            cur = 1;
        }
    }
    chunks.push_back(cur);


    if (chunks.size() == 1) {
        ll ans = (K * S.size())/2;
        cout << ans << endl;
        return 0;
    }

    if (S[0] == S[S.size() - 1]) {
        int midchunk = (chunks[0] + chunks[chunks.size() - 1]);
        ll ans = 0;
        ans += (K-1) * (midchunk / 2);
        ans += (chunks[0])/2;
        ans += (chunks[chunks.size() -1])/2;
        for (int i = 1; i+1 < chunks.size();i++) {
            ans += K*(chunks[i]/2);
        }
        cout << ans << endl;
    } else {
        ll ans = 0;
        for (int chunk : chunks) {
            ans += chunk / 2;
        }
        ans *= K;
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ms(x, n) memset(x,n,sizeof(x));
#define forn(i, n) for(int i = 0; i < (int)n; i++)
#define rep(i, a, b) for (int i = a; i <= b; ++i)
#define rep2(i, a, b) for (int i = a; i >= b; --i)
#define INF 0x3f3f3f3f
#define PI acos(-1.0)
#define mod(x) (x % 1000003)
#define deb(x) cout << #x << " " << x << endl;
#define yes cout << "yes" << endl;
typedef long long int ll;
typedef unsigned long long int ull;
using namespace std;

int a, b;

int main()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> a >> b;
    if (a > b) {
        for (int i = b; i <= a; ++i) {
            if (a - i == i - b) {
                cout << i << endl;
                return 0;
            }
        }
    } else if (a == b) {
        cout << 0 << endl;
        return 0;
    } else {
        for (int i = a; i <= b; ++i) {
            if (b - i == i - a) {
                cout << i << endl;
                return 0;
            }
        }
    }
    cout << "IMPOSSIBLE" << endl;
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;
using static System.Console;
using System.Numerics;

namespace atcorder2
{
    class Program
    {
        public static long Read()
        {
            return long.Parse(Console.ReadLine());
        }

        public static long[] Reads()
        {
            return Console.ReadLine().Split().Select(long.Parse).ToArray();
        }


        public static long gcd(long x, long y)
        {
            if (y < x) gcd(y, x);
            while (y != 0)
            {
                var z = x % y;
                x = y;
                y = z;
            }
            return x;
        }
        public static long keta(long x)
        {
            var z = 1;
            while (x > 0)
            {
                x /= 10;
                z++;
            }
            return z;
        }
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            var nab = Reads();
            var n = nab[0];
            var a = nab[1];
            var b = nab[2];
            WriteLine(Math.Max(0,(n-1) * b+a - (n-1) * a-b + 1));












          
            Console.Out.Flush();
        }
    }
}



Measured memory_bytes: 18864
#include<stdio.h>
int main(){
	int n,w=0;
	int a[105];
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	scanf("%d",&a[i]);
	for(int i=0;i<n;i++)
	{
	if(a[i]%2==0)
	 	if(a[i]%3!=0&&a[i]%5!=0)
	 	{
	 		w=1;
	 		break;
		 }
} 
if(w)
printf("DENIED\n");
else
printf("APPROVED\n");
return 0;
}

Measured memory_bytes: 760
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>
using namespace std;

using ll = long long;


int main(void){
    
    int N, M;
    cin >> N >> M;
    
    vector<vector<int>> B(M);

    int a, b;
    for(const auto i : boost::irange(0,N)){
        cin >> a >> b;
        if (a <= M)
            B[a-1].push_back(b);
    }
    
    ll ans = 0;

    priority_queue<int>q;

    for(const auto i : boost::irange(0,M)){
        if (B[i].size() > 0){
            for(const auto& j: B[i]) {
                q.push(j);
            }
        }

        if (!q.empty()){
            ans += q.top();
            q.pop();
        }

    }

    cout << ans << endl;
} 

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

bool comp(P& a, P& b){
    if(a.second > b.second){
        return true;
    }else if(a.second == b.second){
        return a.first < b.first;
    }else{
        return false;
    }
}
int main(){
    int N;
    cin >> N;
    map<string,int> S;
    string str;
    rep(i,N){
        cin >> str;
        S[str];
        S[str]++;
    }
    int M = 0;
    for(auto& e:S){
        M = max(M,e.second);
    }
    vector<string> T;
    for(auto& e:S){
        if(M == e.second){
            T.push_back(e.first);
        }
    }
    
    sort(T.begin(),T.end());
    rep(i,T.size()){
        cout << T[i] <<endl;
    }
}


Measured memory_bytes: 27248
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

typedef long long ll;
using namespace std;

ll gcd(ll a,ll b){
    ll r;
    while(b!=0){
        r=a%b;
        a=b;
        b=r;
    }
    return a;
}

int main(){
    ll n,x;cin >> n >> x;
    vector<ll>v(n);
    for(int i=0;i<n;i++){
        cin >> v[i];
    }
    vector<ll>t(n);
    for(int i=0;i<n;i++){
        t[i]=abs(x-v[i]);
    }
    ll max=10000000;
    ll tmp;
    for(ll i=1;i<n;i++){
        tmp=gcd(t[i],t[i-1]);
        if(tmp<max){
            max=tmp;
        }
    }
    if(n==1){
        max=abs(x-v[0]);
    }
    cout << max << endl;
    return 0;
}


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

int N, X;
int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> N >> X;
  vector<int> v(N);
  for(int i=0; i<N; ++i) cin >> v[i];
  for(int i=0; i<N; ++i)
    v[i] = abs(v[i] - X);
  int res = 0;
  for(int i=0; i<N; ++i)
    res = __gcd(res, v[i]);
  cout << res << "\n";
  return 0;
}


Measured memory_bytes: 640
n = int(input())
p = input()
o = p.split()
k = []
for i in range(n):
    k.append(int(o[i]))
a = sum(k)/n
l = 99999
m = None
for i in range(n):
    w = k[i]
    if (abs(w - a) < l):
        m = i
        l = abs(w - a)
print(m)

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

int add(int x, int y){
    return x+y;
}

int main (){
    int a ,b, c;
    cin >> a >> b >> c;
    if(add(a,b)<=add(a,c)&& add(a,b)<= add(b,c)){
        cout << add(a,b) << endl;
    }else if(add(a,c) <= add(b,c)){
        cout << add(a,c) << endl;
    }else{
        cout << add (b,c) << endl;
    }
}


Measured memory_bytes: 256
#!/usr/bin/env python
import sys
sys.setrecursionlimit(10**9)
from collections import deque,defaultdict
import heapq
from itertools import combinations
import bisect


def fact(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

n=int(input())
if n==1:
    print(0)
    exit()
p=fact(n)
ans=0
for a,b in p:
    t=1
    g=b
    while g>=t:
        g-=t
        t+=1
    ans+=t-1
print(ans)


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

string str[100];

int H, W;

char ss(int i, int j){
	if(i < 0 || j < 0 || i >= H || j >= W){
		return '.';
	}
	return str[i][j];
}

int main() {
	
	cin >> H >> W;
	
	
	for(int i = 0; i < H; i++){
		cin >> str[i];
	}
	
	bool flag = true;
	
	for(int i = 0; i < H; i++){
		for(int j = 0; j < W; j++){
			if(str[i][j] == '#'){
				bool ff = false;
				if(ss(i + 1, j) == '#'){
					ff = true;
				}
				if(ss(i - 1, j) == '#'){
					ff = true;
				}
				if(ss(i, j + 1) == '#'){
					ff = true;
				}
				if(ss(i, j - 1) == '#'){
					ff = true;
				};
				flag = (flag && ff);
			}
		}
	}
	
	if(flag){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	
	return 0;
}



Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.*;

public class Main {
    // static int INF = (1 << 30) - 1;
    // static long L_INF = (1L << 62) - 1;
    // static long MOD = (long) 1e9 + 7;

    static class Solver {
        int n;
        int[] A;
        int q;

        // write your code
        void solve(InputReader in, PrintWriter out) {
            n = in.nextInt();
            A = new int[n];
            for (int i = 0; i < n; i++) {
                A[i] = in.nextInt();
            }
            q = in.nextInt();

            for (int k = 0; k < q; k++) {
                int m = in.nextInt();
                boolean flag = false;
                int max = 1 << n;
                for (int i = 1; i < max; i++) {
                    int sum = 0;
                    int bit = i;
                    int digit = 0;
                    while (bit > 0) {
                        if (bit % 2 == 1) {
                            sum += A[digit];
                        }
                        bit /= 2;
                        digit++;
                    }
                    if (sum == m) {
                        flag = true;
                        break;
                    }
                }
                if (flag) {
                    out.println("yes");
                } else {
                    out.println("no");
                }
            }
        }

        void debug(Object... os) {
            System.err.println(Arrays.deepToString(os));
        }
    }

    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Solver solver = new Solver();
        solver.solve(in, out);
        out.close();
    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

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

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }
}



Measured memory_bytes: 25204
#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 int INF = 1001001001;
int main(){
  int A,B,C,X,Y;
  cin>>A>>B>>C>>X>>Y;
  int ans=INF;
  for(int c=0;c<=max(X,Y);c++){
   ans=min(C*2*c+max(0,X-c)*A+max(0,Y-c)*B,ans);
  }
  cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
N=io.read("n")
local a={}
local t={}
for i=1,N do
  a[i]=io.read("n")
  t[a[i]]=(t[a[i]] or 0)+1
end
local count=0
for i,v in pairs(t) do
  if i<v then
    count=count+v-i
    elseif i>v then
      count=count+v
  end
end
print(count)

Measured memory_bytes: 8808