akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;
import java.util.Arrays;
import java.util.Comparator;
class Main{
public static void main(String[] args){
 Scanner scan = new Scanner(System.in);
 
 int N = scan.nextInt();
 int M = scan.nextInt();
 int PV[] = new int[N];
 double b = 0;
 int count = 0;
  //4M分の1
  for (int i = 0; i < N; i++){
    int a = scan.nextInt();
    PV[i] = a;
        b = b + a;
  }
    b = b /( 4 * M ); 

  //M個選べるか
  for (int i = 0; i < N; i++){
   if ( PV[i] >= b ){
     count += 1;
   }
   else {
   }
  }

  if ( count >= M ){
    System.out.println("Yes");
  }
  else{
    System.out.println("No");
  }
 }
}

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int b[112345];
    for (int i = 0; i < n - 1; i++)
    {
        cin >> b[i];
    }
    int sum = 0;
    sum += b[0];
    sum += b[n - 2];
    for (int i = 0; i < n - 2;i++){
        sum += min(b[i], b[i + 1]);
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#pragma region Header
#include <iostream>
#include <iomanip>
#include <cstdint>
#include <cmath>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <string>
#include <functional>
#include <algorithm>
#include <numeric>
#include <stdexcept>
using namespace std;
using i32 = int32_t;
using i64 = int64_t;
using u32 = uint32_t;
using u64 = uint64_t;
#define rep(i, n) for (int i = 0; i < static_cast<int>(n); ++i)
#define repd(i, n) for (int i = static_cast<int>(n) - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = static_cast<int>(a); i <= static_cast<int>(b); ++i)
#define FORD(i, a, b) for (int i = static_cast<int>(b); i >= static_cast<int>(a); --i)
template <typename T>
int SZ(T const &x)
{
    return static_cast<int>(x.size());
}
template <class T>
bool chmin(T &a, T const &b)
{
    if (b < a)
    {
        a = b;
        return true;
    }
    return false;
}
#pragma endregion

// {waapu, h, w}
using p = tuple<int, int, int>;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);

    int h_size, w_size;
    cin >> h_size >> w_size;
    auto in_sq = [&](int h, int w) {
        return 0 <= h and h < h_size and 0 <= w and w < w_size;
    };
    int h_from, w_from;
    cin >> h_from >> w_from;
    --h_from;
    --w_from;
    int h_to, w_to;
    cin >> h_to >> w_to;
    --h_to;
    --w_to;
    vector can_go(h_size, vector<bool>(w_size));
    rep(h, h_size)
    {
        rep(w, w_size)
        {
            char c;
            cin >> c;
            can_go[h][w] = (c == '.');
        }
    }

    // 01bfs
    int ans = -1;
    vector dist(h_size, vector<int>(w_size, 1000'000));
    // priority_queue<p, vector<p>, greater<p>> pq;
    deque<p> qu;
    vector used(h_size, vector<bool>(w_size, false));

    qu.emplace_back(0, h_from, w_from);
    while (not qu.empty())
    {
        auto [cost, h_old, w_old] = qu.front();
        qu.pop_front();
        if (h_old == h_to and w_old == w_to)
        {
            ans = cost;
            break;
        }
        if (used[h_old][w_old])
        {
            continue;
        }
        used[h_old][w_old] = true;
        FOR(dh, -2, 2)
        {
            FOR(dw, -2, 2)
            {
                auto h_new = h_old + dh, w_new = w_old + dw;
                if (not in_sq(h_new, w_new) or not can_go[h_new][w_new] or used[h_new][w_new])
                {
                    continue;
                }
                int dcost = (abs(dh) + abs(dw) > 1);
                chmin(dist[h_new][w_new], cost + dcost);
                if (dcost)
                {
                    qu.emplace_back(cost + dcost, h_new, w_new);
                }
                else
                {
                    qu.emplace_front(cost + dcost, h_new, w_new);
                }
            }
        }
    }

    cout << ans << endl;

    return 0;
}


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

typedef long long ll;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define ANS(n) cout << (n) << endl

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(a);i>=(b);i--)

#define ALL(obj) (obj).begin(),(obj).end()

#define pii pair<int,int>

#define pb(a) push_back(a)
#define mp make_pair

int main()
{
	int h,w;
	cin >> h >> w;
	char c[h][w];
	FOR(i,0,h)FOR(j,0,w)cin >> c[i][j];
	FOR(i,0,h){
		FOR(j,0,2){
			FOR(k,0,w){
				cout << c[i][k];
			}
			cout << endl;
		}
	}
	return 0;
}


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

int main()
{
    long a, b;
    char op;

    cin >> a >> op >> b;

    if (op == '+')
    {
        cout << a + b << endl;
    }
    else if (op == '-')
    {
        cout << a - b << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

int main(int argc, const char *argv[]) {
  using ll = long long;
  ll n, k, q;
  cin >> n >> k >> q;

  vector<ll> pts(n, k - q);
  for (int i = 0; i < q; i++) {
    int a;
    cin >> a;
    a--;
    pts[a]++;
  }

  for (int i = 0; i < n; i++) {
    cout << (pts[i] > 0 ? "Yes" : "No") << '\n';
  }

  return 0;
}

Measured memory_bytes: 1408
#include <iostream>

int main() {
    int n; std::cin >> n;
    int m = 1000;
    int M = 0;
    for (int i = 0; i < n; i++) {
        int l; std::cin >> l;
        m = std::min(l, m);
        M = std::max(l, M);
    }

    std::cout << M-m << std::endl;

    return 0;
}

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

#define M_C 10e5
int main()
{
	vector<int> D(M_C, INT32_MAX);
	D[0] = 0;

	vector<int> H(M_C);
	int N;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> H[i];
	}

	for (int i = 0; i < N - 1; i++) {
		D[i + 1] = min (D[i + 1], D[i] + abs(H[i] - H[i + 1]));
		if (i + 2 < N)
			D[i + 2] = min(D[i + 2], D[i] + abs(H[i] - H[i + 2]));
	}

	cout << D[N - 1] << endl;
}

Measured memory_bytes: 8064
#include <algorithm>
#include <iostream>
#include <queue>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

int main(int argc, char* argv[]) {
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  unordered_map<int, int> map;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    if (map.count(A[i]) > 0) {
      map[A[i]]++;
    } else {
      map[A[i]] = 1;
    }
  }
  if (map.size() < K) {
    cout << "0" << endl;
    return 0;
  }

  vector<int> count;
  for (auto p : map) {
    count.push_back(p.second);
  }

  int sum = 0;
  sort(count.begin(), count.end(), greater<int>());
  for (int i = 0; i < K; i++) {
    sum += count[i];
  }
  cout << N - sum << endl;

  return 0;
}


Measured memory_bytes: 11080
a,b,c,d=map(int,input().split())

# c,dの最大公約数
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a

#最小公倍数
def lcm(a,b):
    return a*b//gcd(a,b)

cd = lcm(c,d)

ans=0
# a-1までで割り切れない個数
ans-=(a-1) - ((a-1)//c+(a-1)//d-(a-1)//cd)

# bまでで割り切れない個数
ans+=b-(b//c+b//d-b//cd)

print(ans)

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

using namespace std;

#define INF ((int64_t)2e18)
#define eb emplace_back
#define ii pair<int, int>
#define OK (cerr << "OK" << endl)
#define debug(x) cerr << #x " = " << (x) << endl
#define ff first
#define ss second
#define int long long
#define tt tuple<int, int, int>
#define all(x) x.begin(), x.end()
#define Matrix vector<vector<int>>
#define Mat(n, m, v) vector<vector<int>>(n, vector<int>(m, v))
#define endl '\n'
const int MOD = 1e9 + 7;
const int MAXN = 2e5 + 3;

bool pal(string s) {
  string rev = s;
  reverse(all(rev));
  return (rev == s);
}

signed main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  string s;
  cin >> s;
  int n = s.size();

  int a = ((n - 1) / 2);
  int b = (n + 3) / 2 - 1;

  string ans = "Yes";
  if (!pal(s) || !pal(s.substr(0, a)) || !pal(s.substr(b)))
    ans = "No";

  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {

	public static void main(String[] args) {
		try (Scanner sc = new Scanner (System.in)){
			int n = sc.nextInt();
			int taro = 0;
			int hanako = 0;
			for (int i=0; i<n; i++) {
				String tcard = sc.next();
				String hcard = sc.next();
				if (tcard.equals(hcard)) {  //同じカードでしたら
					taro++;
					hanako++;
				} else {
					if (tcard.compareTo(hcard) > 0) taro+= 3;
					else hanako+= 3;
				}
			}
			System.out.println(taro + " " + hanako);
		}
	}
}


Measured memory_bytes: 29700
import itertools

N = []
[N.append(num) for num in range(1, int(input())+1)]
Pn = tuple(map(int, input().split()))
Qn = tuple(map(int, input().split()))

permutation = []
for x in itertools.permutations(N):
    permutation.append(x)

print(abs(permutation.index(Pn) - permutation.index(Qn)))

Measured memory_bytes: 13924
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

namespace AtCoder
{
    class Program
    {
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        static int Count(int n)
        {
            int cnt = 0;
            while (n > 0)
            {
                if ((n & 1) != 0) { ++cnt; }
                n >>= 1;
            }
            return cnt;
        }

        static int Solve(int N, int M, int[] masks, int[] P)
        {
            var counts = new int[1 << N];
            for (int i = 0; i < (1 << N); ++i) { counts[i] = Count(i); }

            int ans = 0;
            for (int i = 0; i < (1 << N); ++i)
            {
                if (Enumerable.Range(0, M).All(j => (counts[i & masks[j]] + P[j]) % 2 == 0)) { ++ans; }
            }
            return ans;
        }

        static void Main(string[] args)
        {
            int[] V1 = ReadInts();
            int N = V1[0], M = V1[1];
            var masks = new int[M];
            for (int i = 0; i < M; ++i)
            {
                int[] V2 = ReadInts();
                int k = V2[0];
                for (int j = 0; j < k; ++j)
                {
                    masks[i] |= 1 << (V2[j + 1] - 1);
                }
            }
            int[] P = ReadInts();
            Console.WriteLine(Solve(N, M, masks, P));
        }
    }
}


Measured memory_bytes: 13268
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
using namespace std;
namespace adaptor = boost::adaptors;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
typedef long long ll;

void Main()
{
	int N, SZ; 
  	string S;
  	cin >> N >> S;
	SZ = S.size();
  
  	string ans(SZ,'A');
  
  	rep(i,SZ){
      	// (s-'A'+1) は s が何番目のアルファベットかを表す
      	if((S[i]-'A'+1) + N <= 26) {
     		ans[i] = S[i]+N;
        }
      	else{
      		ans[i] = S[i]+N-26;
        }
    }

  	cout << ans << endl;
  	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}

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

public class Main {
  private static class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
      reader = new BufferedReader(new InputStreamReader(in));
      tokenizer = null;
    }

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

    public String nextLine() {
      if (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          return reader.readLine();
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }

      return tokenizer.nextToken("\n");
    }

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

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

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

    public int[] nextIntArray(int n) {
      int[] a = new int[n];
      for (int i = 0; i < n; i++)
        a[i] = nextInt();
      return a;
    }

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

  public static void main(String[] args) {
    FastScanner sc = new FastScanner(System.in);
    long n = sc.nextLong();
    long k = sc.nextLong();
    long positive = n % k;
    long negative =  k - positive;
    System.out.println(Math.min(positive, negative));
  }
}

Measured memory_bytes: 21332
#include <iostream>
#include <string>

int main() {
	int n, k;
	std::string s;

	std::cin >> n;
	std::cin >> s;
	std::cin >> k;

	char ch = s[k - 1];
	std::string str_out;
	for(int i = 0; i < n; ++i) {
		if(ch == s[i]) str_out.push_back(s[i]);
		else str_out.push_back('*');
	}

	std::cout << str_out << std::endl;

	return 0;
}


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

int n,m;

vector<int> g[100010],rg[100010];
vector< pair<int,int> > e;

int dp[100010];
int f[100010];
vector<int> depth[100010];

map< pair<int,int> , int > pos;
int main(){
	cin >> n >> m;
	for(int i = 0; i < m; i++){
		int a,b;
		cin >> a >> b;
		g[a].push_back(b);
		rg[b].push_back(a);
		pos[make_pair(a,b)] = i;
	}
	
	for(int i = 1; i <= n; i++){
		g[0].push_back(i);
		rg[i].push_back(0);
	}
	
	for(int i = 0; i <= n; i++)
		for(int j = 0; j < g[i].size(); j++)
			dp[g[i][j]] = max(dp[g[i][j]],dp[i]+1);
	
	int maximum = *max_element(dp,dp+100010);
	
	for(int i = n; i >= 0; i--){
		if(maximum == dp[i]) f[i] = 1;
		else if(f[i] == 0) continue;
		for(int j = 0; j < rg[i].size(); j++){
			if(dp[rg[i][j]]+1 == dp[i]){
				f[rg[i][j]] |= f[i];
				e.push_back(make_pair(rg[i][j],i));
			}
		}
	}
	for(int i = 0; i < e.size(); i++){
		depth[dp[e[i].first]].push_back(pos[make_pair(e[i].first,e[i].second)]);
	}
	vector<int> ans;
	for(int i = 1 ; i < 100010 ; i++){
		if( depth[i].size() == 1 ){
			ans.push_back(depth[i][0]+1);
		}
	}
	sort(ans.begin(),ans.end());
	for(int i = 0 ; i < ans.size() ; i++)
		cout << ans[i] << endl;
	if( ans.size() == 0 ) cout << -1 << endl;
}

Measured memory_bytes: 27888
#include<stdio.h>


#define MAX_N 100 +1


int main( void )
{
	int N ;
	int M[ 3 ] ;

	char a[ MAX_N ] = { 0 } ,b[ MAX_N ] = { 0 } ,c[ MAX_N ] = { 0 } ;

	scanf( "%d" ,&N ) ;

	int i ,j ;
	for( i = 0 ; i < 3 ; ++i )
	{
		scanf( "%d" ,&M[ i ] ) ;

		for( j = 0 ; j < M[ i ] ; ++j )
		{
			int No ;
			scanf( "%d" ,&No ) ;

			if( i == 0 )
			{	a[ No ] = 1 ;	}

			else if( i == 1 )
			{	b[ No ] = 1 ;	}

			else
			{	c[ No ] = 1 ;	}
		}
	}

	int cnt = 0 ;
	for( i = 1 ; i <= N ; ++i )
	{
		// C B A
		if( c[ i ] > 0 )
		{
			if( a[ i ] < 1 || b[ i ] > 0 )
			{
				++cnt ;
			}
		}
	}

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

	return 0 ;
}


Measured memory_bytes: 2760
import sys
import math  # noqa
import bisect  # noqa
import queue  # noqa


def input():
    return sys.stdin.readline().rstrip()


def main():
    N, M, X = map(int, input().split())
    C = []
    A = []
    for _ in range(N):
        CA = list(map(int, input().split()))
        C.append(CA[0])
        A.append(CA[1:])

    ans = 10 ** 9 + 7
    for i in range(2 ** N):
        x = [0 for _ in range(M)]
        money = 0
        for j in range(N):
            if ((i >> j) & 1):
                money += C[j]
                for k, a in enumerate(A[j]):
                    x[k] += a
        flag = True
        for r in x:
            if r < X:
                flag = False
                break
        if flag:
            ans = min(ans, money)

    if ans == 10 ** 9 + 7:
        print(-1)
    else:
        print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 70952
#include <bits/stdc++.h>
using namespace std;
int main() {
	long long a, N, s, A = (LLONG_MAX), l = 0, r = 0, S[100002] = { 0 }; cin >> N >> s;
	for (int i = 1; i <= N;i++) { cin >> a;S[i] += S[i - 1] + a; }
	for(;;){
		if (S[r] - S[l] >= s) { A = min(A, r - l); l++; }else r++;
		if (r > N || l > N) { if (A == (LLONG_MAX))A = 0; cout << A << endl; return 0; }
	}
}

Measured memory_bytes: 3864
//For higher stack size use g++ -O2 -std=c++11 -Wall -Wl,--stack=268435456 a.cpp -o a.exe in cmd
    #include <bits/stdc++.h>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <cstring>
    #include <chrono>
    #include <complex>
    #define ll long long
    #define int ll
    #define ld long double
    #define vi vector<int>
    #define vll vector<ll>
    #define vvi vector < vi >
    #define pii pair<int,int>
    #define pll pair<long long, long long>
    #define mod 1000000007
    #define inf 1000000000000000001;
    #define all(c) c.begin(),c.end()
    #define mp(x,y) make_pair(x,y)
    #define mem(a,val) memset(a,val,sizeof(a))
    #define eb emplace_back
    #define pb push_back
    #define f first
    #define s second
    
    using namespace std;

    vector<int> v;

    void func(int x,int d)
    {
        if(x>3234566667)
            return;
        if(x==0 && d==0)
            return;
        if(x!=0)
        v.pb(x);
        if(d-1>=0)
        {
            func(x*10+d-1,d-1);
        }
        func(x*10+d,d);
        if(d+1<=9)
        {
            func(x*10+d+1,d+1);
        }
    }

    signed main()
    {
        std::ios::sync_with_stdio(false);
        int T;
        T=1;
        // cin.ignore(); must be there when using getline(cin, s)
        while(T--)
        {
            int n,i,j,k;
            cin>>k;
            for(i=1;i<=9;++i)
            {
                func(i,i);
            }
            sort(v.begin(),v.end());
            cout<<v[k-1]<<endl;
        }
        return 0;
    }


Measured memory_bytes: 1400
s = input()
ops = ['+', '-']
post = '=7'
for a in ops:
    for b in ops:
        for c in ops:
            now = s[0] + a + s[1] + b + s[2] + c + s[3]
            if eval(now) == 7:
                ans = now + post
                break
print(ans)


Measured memory_bytes: 38384
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e16;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}

ll N, A, B;
bool ok(ll l, vl& h){
    ll cnt = 0;
    REP(i, N){
        if(h[i] <= B*l) continue;
        cnt += (h[i] - B*l + (A-B)-1) / (A-B);
    }
    return cnt <= l;
}

int main(){
    cin >> N >> A >> B;
    vl h(N, 0); REP(i, N) cin >> h[i];
    sort(h.begin(), h.end());
    ll l = 0ll, r = 1e9;
    while(abs(r-l) > 1){
        ll mid = (l+r)/2;
        if(ok(mid, h)) r = mid;
        else l = mid;
    }
    bool lok = ok(l, h);
    cout << (lok ? l : r) << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
long long func(long long n){
    long long result = 1;
    long long i;
    for(i = 1; i <= n; i++) {
        result*=i;
        result%=1000000007;
    }
    return result;
}
int main(){
    long long n,m,ans;
    scanf("%lld %lld",&n,&m);
    if(n==m){
        ans=func(n)*func(m)%1000000007;
        ans=ans*2%1000000007;
        printf("%lld\n",ans);
    }else if(((n-m)==1)||((n-m)==-1)){
        ans=func(n)*func(m)%1000000007;
        printf("%lld\n",ans);
    }else{
        printf("0\n");
    }
}


Measured memory_bytes: 128
#include<iostream>

using namespace std;

int main(){
    int N;
    cin >> N;
    int a[N+1],b[N];
    for(int i=0;i<=N;i++){
        cin >> a[i];
    }
    for(int i=0;i<N;i++){
        cin >> b[i];
    }
    long long int sum;
    for(int i=0;i<N;i++){
        if(a[i]>=b[i]){
            sum = sum+b[i];
            a[i] = a[i]-b[i];
        } else {
            sum = sum + a[i];
            b[i] = b[i]-a[i];
            a[i]=0;
            if(a[i+1]>=b[i]){
                sum = sum+b[i];
                a[i+1]= a[i+1]-b[i];
            } else {
                sum = sum+a[i+1];
                a[i+1]=0;
            }
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 1024
#define _USE_MATH_DEFINES
#define INF 100000000

#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>

using namespace std;

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


static const double EPS = 1e-8;

int tx[] = {-1,0,1,0};
int ty[] = {0,1,0,-1};

P formula(const string &str, int pos=0);
P factor(const string &str, int pos = 0);
P term(const string &str, int pos = 0);

P formula(const string &str, int pos){
	if(str[pos] == '('){
		P res1_ = formula(str,pos+1);
		pos = res1_.second;
		char ch = str[pos];
		P res2_ = formula(str,pos+1);

		if(ch=='*') return P(min(res1_.first,res2_.first),res2_.second+1);
		if(ch=='+') return P(max(res1_.first,res2_.first),res2_.second+1);
	}
	else if(isdigit(str[pos])){
		return P(str[pos]-'0',pos+1);
	}

	else if(str[pos] == '-'){
		P res_ = formula(str,pos+1);
		if(res_.first==0) res_.first=2;
		else if(res_.first==2) res_.first=0;

		return res_;
	}
}


int main()
{
	string str;
	while(getline(cin,str)){
		if(str == ".") break;
		int res = 0;
		for(int p=0;p<=2;p++){
			for(int q=0;q<=2;q++){
				for(int r=0;r<=2;r++){
					string tmp = str;
					for(int i=0;i<tmp.size();i++){
						if(tmp[i]=='P') tmp[i] = '0' + p;
						else if(tmp[i]=='Q') tmp[i] = '0' + q;
						else if(tmp[i]=='R') tmp[i] = '0' + r;
					}
					P result;
					result = formula(tmp,0);
					//printf("%s = %d\n",tmp.c_str(),result.first);
					if(formula(tmp,0).first == 2) res++;
				}
			}
		}

		printf("%d\n",res);
	}
}

Measured memory_bytes: 0
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

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

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" \
                      << " " << __FILE__ << endl;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

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

    int a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;

    int ans = 0;

    //min(x,y)までn枚買う
    int n = min(x, y);
    ans += c * n * 2;
    //min(aかbを買う場合, cを買う場合)
    ans += min(a*(x-n) + b*(y-n), c * (x+y-n*2) * 2);
    //aとbのみ買う場合
    ans = min(ans, a*x + b*y);


    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int ans=0;

		if(n%2 == 0) {
			ans = n/2;
		}else {
			ans = n/2 + 1;
		}

		System.out.println(ans);

		scanner.close();


	}

}


Measured memory_bytes: 35732
# include <bits/stdc++.h>
# define ll long long int
# define pb push_back
# define pf push_front
# define mpi make_pair
# define pi pair<ll,ll>
# define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
# define mod 1000000007
# define endl "\n"
using namespace std;
int main()
{
  fast
  ll n;
  cin>>n;
  cout<<pow(n,3);
  return 0;
}


Measured memory_bytes: 384
from math import ceil
from fractions import Fraction
n = int(input())
res1,res2 = 1,1
for i in range(n):
    t,a = map(int,input().split())
    r = ceil(max(Fraction(res1,t),Fraction(res2,a)))
    res1 = t*r
    res2 = a*r
print(res1+res2)

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

using namespace std;

int main(){
	string S;
	cin>>S;
	int a=0,b=0;
	for(int i=0;i<S.size();i++){
		if(S[i] == 'C'){
			a=1;
		}
		if(S[i] == 'F' && a==1){
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
}

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

int sum(int n) {
  int sum=0;
  if (n<0) return 0;
  while (n>0) {
    sum += n%10;
    n /= 10;
  }
  return sum;
}
int main(void){
  int n, a, b;
  cin >> n >> a >> b;

  int res = 0; 

  for(int i = 1; i <= n; i ++){
    if(a <= sum(i) && sum(i) <= b) res += i;
  }

  cout << res << endl;

  return 0;
}


Measured memory_bytes: 256
X, Y = map(int, input().split())

if (X+Y)%3 != 0 or X*2 < Y or Y*2 < X:
    print(0)
    exit()

n = (2*X - Y) // 3
m = (2*Y - X) // 3

P = 10 ** 9 + 7
N = 10 ** 6
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1]
for i in range(2, N+1):
    fact.append((fact[-1]*i)%P)
    inv.append((-inv[P%i] * (P // i)) %P)
    factinv.append((factinv[-1] * inv[-1])%P)
print(fact[n+m]*factinv[n]*factinv[m]%P)


Measured memory_bytes: 127740
N, M = map(int, input().split())
P, Y = zip(*(map(int, input().split()) for _ in range(M)))
ans = ['' for _ in range(M)]
c = [1 for _ in range(N + 1)]
for i, t in sorted(enumerate(zip(P, Y)), key=lambda t: t[1][1]):
    ans[i] = '{:06}{:06}'.format(t[0], c[t[0]])
    c[t[0]] += 1
print('\n'.join(ans))

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

int main(){
  int N,zero=0,flag =0;
  cin >> N;
  vector<long double> A(N);
  long double ans = 1,ed = 1e18;
  long double ansLog, aLog;
  for(int i=0; i<N; i++){
    cin >> A[i];
    if(A[i] == 0) zero = 1;
  }
  if(zero) cout << 0;
  else{
    for(int i=0; i<N; i++){
      ansLog = log10(ans);
      aLog = log10(A[i]);
      if(ansLog + aLog > 18.01){
        flag = 1;
        break;
      }
      ans *= A[i];
      if((ans < 0) || (ans > ed)){
        flag = 1;
        break;
      }
    }
    if(flag) cout << -1;
    else cout << (long long)ans;
  }
  return 0;
}

Measured memory_bytes: 4844
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const long long mod = 1000000007;
ll modu(ll a) {
    if(a>=0) return a;
    else return 1LL*-1*a;
}
ll fact(ll n) {
    ll ans = 1;
    if(n==0 || n==1) return 1;
    int i=1;
    while(i<=n) {
        ans = ((ans%mod)*(i%mod))%mod;
        i++;
    }
    return ans;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    ll n,m;
    cin>>n>>m;
    if(modu(n-m)>1) {
        cout<<"0";
        return 0;
    }
    if(n==m) {
        ll temp = fact(n);
        temp = ((temp%mod)*(temp%mod))%mod;
        temp = ((temp%mod)*2)%mod;
        cout<<temp;
        return 0;
    }
    else {
        ll temp = fact(n);
        ll temp1 = fact(m);
        ll ans = ((temp%mod)*(temp1%mod))%mod;
        cout<<ans;
        return 0;
    }
	return 0;
}


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

for _ in range(min(k, 100)):
    new_a = [0]*n
    for i in range(n):
        d = a[i]
        new_a[max(i-d, 0)] += 1
        if i+d+1 <= n-1:
            new_a[i+d+1] -= 1
    for i in range(n-1):
        new_a[i+1] += new_a[i]

    a = new_a

print(*a)


Measured memory_bytes: 220540
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
#define F first
#define S second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
#define int ll

signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int a, b, m;
  cin >> a >> b >> m;
  vector<int> c1(a + 1), c2(b + 1);
  for (int i = 1; i <= a; i++) {
    cin >> c1[i];
  }
  for (int i = 1; i <= b; i++) {
    cin >> c2[i];
  }
  int mn1 = c1[1], mn2 = c2[1];
  for (int i = 1; i <= a; i++) {
    mn1 = min(mn1, c1[i]);
  }
  for (int i = 1; i <= b; i++) {
    mn2 = min(mn2, c2[i]);
  }
  int ans = mn1 + mn2;
  for (int i = 0; i < m; i++) {
    int x, y, z;
    cin >> x >> y >> z;
    ans = min(ans, c1[x] + c2[y] - z);
  }
  cout << ans << '\n';
} 

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

#define int long long int
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define vvi vector<vi>
#define mii map<int,int>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define MOD 998244353
#define all(v) v.begin(), v.end()

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

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

    int n, cum=0, i;
    cin>>n;
    vi a(n);
    for (i=0; i<n; i++)
    {
        cin>>a[i];
        cum^=a[i];
    }
    for (i=0; i<n; i++)
        cout<<(cum^a[i])<<' ';
}


Measured memory_bytes: 4776
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;


int a, b, tmp = 1, cnt;

int main(){
	
	cin >> a >> b;

	while (tmp < b){
		tmp += a - 1;
		cnt++;
	}

	cout << cnt << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;

using ll = long long;

int main() {
    ll X;
    cin >> X;
    ll ret = 1;
    for (auto && i: irange(2LL, 1000LL)){
        ll j = i * i;
        while (j <= X){
            ret = max(ret, j);
            j *= i;
        }
    }
    cout << ret << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
typedef long long int ll;
using namespace std;
int cnt[200200];
int main(){
	string s; cin >>s;
	int n=s.size();
	ll ans=0;
	for(int i=0;i<n-2;i++){
		if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C'){
			ans+=cnt[i]+1;
			cnt[i+2]+=cnt[i];
			s[i]='C'; s[i+2]='A';
		}
		else if(s[i]=='A'){
			cnt[i+1]=cnt[i]+1;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 1412
import java.util.*

fun main(args: Array<String>) {
    val pw = java.io.PrintWriter(System.out)
    Problem.solve(Scanner(System.`in`), pw)
    pw.flush()
}

object Problem {
    fun solveMulti(sc: Scanner, pw: java.io.PrintWriter) {
        for (t in 1..sc.next().toInt()) {
            solve(sc, pw)
        }
    }

    fun solve(sc: Scanner, pw: java.io.PrintWriter) {
        val A = sc.next().toDouble()
        val B = sc.next().toDouble()
        val H = sc.next().toDouble()
        val M = sc.next().toDouble()

//        val A = 100.0
//        val B = 100.0
//        val H = 0.0
//        val M = 45.0
        val degH = 2.0 * Math.PI * (H / 12 + M / 720)
        val degM = 2.0 * Math.PI * (M / 60)
//        lib.dprint("degH=$degH")
//        lib.dprint("degM=$degM")
        val hx = A * Math.cos(Math.PI / 2.0 - degH)
        val hy = A * Math.sin(Math.PI / 2.0 - degH)
        val mx = B * Math.cos(Math.PI / 2.0 - degM)
        val my = B * Math.sin(Math.PI / 2.0 - degM)
//        lib.dprint("hx=$hx, hy=$hy")
//        lib.dprint("mx=$mx, my=$my")

        val dx = Math.abs(hx - mx)
        val dy = Math.abs(hy - my)
//        lib.dprint("dx=$dx, dy=$dy")
        val l = Math.sqrt(dx * dx + dy * dy)
        pw.println(l)
    }
}


Measured memory_bytes: 36596
H,W = map(int,input().split())
b = []
for i in range(H):
    a = input()
    if "#" in a:
        b.append(a)

c = [i for i in range(W)]
for i in range(len(b)):
    for j in range(W):
        if b[i][j] == "#":
            if j in c:
                c.remove(j)
c.sort()
cnt = 0
for i in range(len(c)):
    c[i] -= cnt
    cnt += 1
for i in c:
    for j in range(len(b)):
        b[j] = b[j][:i]+b[j][i+1:]
for i in range(len(b)):
    print(b[i]) 

Measured memory_bytes: 9156
#include <bits/stdc++.h>
#define REP(i, n) for(int i=0; i<(int)(n); i++)
#define REP1(i,a,b) for(int i=a; i<=(int)(b); i++)
#define ALL(x) begin(x),end(x)
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef vector<int> VI;
typedef pair<int,int> PII;

template<class T> inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; }
template<class T> inline bool chmin( T &a, const T &b ) { return b<a ? a=b,true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template<class T, class F=less<T>> void sort_uniq( vector<T> &v, F f=F() ) {
    sort(begin(v),end(v),f);
    v.resize(unique(begin(v),end(v))-begin(v));
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n,m;
    cin >> n >> m;
    vector<int> H(n);
    REP(i,n) cin >> H[i];
    vector<set<int>> e(n);
    REP(i,m) {
        int a,b;
        cin >> a >> b;
        --a;--b;
        if ( H[a]<H[b] ) {
            swap(a,b);
        }
        e[b].insert(a);
        if ( H[a]==H[b] ) e[a].insert(b);
    }
    int ans=0;
    REP(i,n) {
        if ( e[i].size()==0 ) ans++;
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 12968
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <functional>
#include <string>
#include <iostream>
using namespace std;
using ll = long long;

int a, b, c;
int main() {
	scanf("%d %d %d", &a, &b, &c);
	bool same = (a == b) || (b == c) || (c == a);
	bool diff = (a != b) || (b != c) || (c != a);
	printf(same && diff ? "Yes\n" : "No\n");
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;
const int INF=1e9;

int main(){
    int n;
    cin>>n;
    int a[3*n];
    for(int i=0; i<3*n; i++) cin>>a[i];
    sort(a, a+3*n, greater<long long>());
    long long ans=0;
    for(int i=1; i<=2*n; i+=2) ans+=a[i];
    cout<<ans<<endl;
    
}


Measured memory_bytes: 1408
#include "bits/stdc++.h"
using namespace std;

int main() {
	int w, h, n;
	cin >> w >> h >> n;
	int x[n-1], y[n-1], a[n-1];
	for(int i=0;i<n;i++) cin >> x[i] >> y[i] >> a[i];

	int left = 0, right = w, top = h, bottom = 0, sum = h*w;

	for(int i=0;i<n;i++) {
		if(a[i] == 1) {
			left = max(left, x[i]);
		}
		if(a[i] == 2) {
			right = min(right, x[i]);
		}
		if(a[i] == 3) {
			bottom = max(bottom, y[i]);
		}
		if(a[i] == 4) {
			top = min(top, y[i]);
		}
	}
	int ans = max(0, (right - left)) * max(0, (top - bottom));
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(ll i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;

int main() {
    string s;
    int k, n;
    cin >> n >> k >> s;
    s[k-1] = s[k-1] + 0x20;
    cout << s;
}
    

Measured memory_bytes: 256
//2019/12/8
//bit全探索.
//Refering to exp.
#include<iostream>
#include<vector>
#include<bitset>
#define REP(i,n) for(int i=0;i<(n);++i)
using namespace std;
typedef vector<int>  vi;
typedef vector<vi >  vvi;
typedef vector<vvi > vvvi;

int main(){
	int n;
	cin>>n;
	
	vi a(n);
	vvvi v(n);
	REP(i,n){
		cin>>a[i];
		v[i].resize(a[i],vi(2));
		REP(j,a[i])REP(k,2) cin>>v[i][j][k];
	}
	
	int ans=0;
	REP(i,(1<<n)){//point.
		bitset<15> bit(i);
		
		bool flag=true;
		REP(j,n){
			if(bit[j]){
				REP(k,a[j]){
					if(!(bit[v[j][k][0]-1]^v[j][k][1])){}//point.
					else{
						flag=false;
						break;//REP(k).
					}
				}
			}
			if(!flag) break;//REP(j).
		}
		if(flag) ans=max(ans,(int)bit.count());
	}
	
	cout<<ans<<endl;
}


Measured memory_bytes: 384
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
# from fractions import gcd
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from functools import reduce
from bisect import bisect_left, insort_left
from heapq import heapify, heappush, heappop

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
MAP = lambda: map(int, INPUT().split())
S_MAP = lambda: map(str, INPUT().split())
LIST = lambda: list(map(int, INPUT().split()))
S_LIST = lambda: list(map(str, INPUT().split()))

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    N, M = MAP()
    A = LIST()

    ans = N - sum(A)
    print(ans if ans >= 0 else -1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 10800
import java.util.*;

public class Main{
      public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            String str1 = sc.next();
            String str2 = sc.next();
            String str3 = sc.next();
            String[] str1a = str1.split("");
            String[] str2a = str2.split("");
            String[] str3a = str3.split("");
            System.out.println(str1a[0] + str2a[1] + str3a[2]);
            
          }
}

Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define MN 200005
#define ll long long
inline int read(){
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
ll fac[MN],inv[MN];
int n,x,y,cnt=0,c[MN],w[MN],ge[MN];bool vis[MN];
vector<pair<int, int> >r[MN];
vector<pair<int, int> >p;
vector<int> v[MN],tmp;
void dfs(int u){
    vis[u]=1;
    ++cnt,++ge[c[u]],tmp.push_back(c[u]);
    for(int i=0;i<v[u].size();i++)
        if(!vis[v[u][i]]) dfs(v[u][i]);
}
int main(){
	n=read(),x=read(),y=read();
	fac[0]=fac[1]=inv[0]=inv[1]=1;
    for(ll i=2;i<=n;i++){
        fac[i]=fac[i-1]*i%mod;
        inv[i]=(mod-mod/i)*inv[mod%i]%mod;
    }
    for(int i=2;i<=n;i++) inv[i]=inv[i-1]*inv[i]%mod;
    for(int i=1;i<=n;i++) c[i]=read(),w[i]=read(),r[c[i]].push_back(make_pair(w[i],i));
    for(int i=1;i<=n;i++)if(r[i].size()){
    	sort(r[i].begin(),r[i].end());p.push_back(r[i][0]);
    	for(int j=1;j<r[i].size();j++)
    		if(r[i][j].first+r[i][0].first<=x)
    			v[r[i][0].second].push_back(r[i][j].second),
    			v[r[i][j].second].push_back(r[i][0].second);
	}
    sort(p.begin(),p.end());
    int id=p[0].second;
    for(int i=1;i<=n;i++){
    	if(c[i]==c[id]||w[i]+w[id]>y) continue;
    	v[id].push_back(i),v[i].push_back(id);
	}
    if(p.size()>1){
    	id=p[1].second;int cmin=c[p[0].second];
    	for(int i=0;i<r[cmin].size();i++)
    		if(r[cmin][i].first+w[id]<=y)
			v[r[cmin][i].second].push_back(id),v[id].push_back(r[cmin][i].second);
	}
	dfs(p[0].second);
    ll ans=fac[cnt];
    for(int i=0;i<tmp.size();i++)
        ans=(ans*inv[ge[tmp[i]]])%mod,ge[tmp[i]]=0;
    printf("%lld\n",ans);
    return 0;
}

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

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

    vector<int> l(n), r(n);
    for(int i=0; i<n; i++){
        cin >> l[i] >> r[i];
        r[i] *= -1;
    }
    sort(l.begin(), l.end());
    sort(r.begin(), r.end());

    long long int ans1 = 0, ans2 = 0, ans3 = 0, left = 0, right = 0;
    for(int i=n-1; i>=0; i--){
        ans1 = max(ans1, left + right + 2 * l[i]);
        ans2 = max(ans2, left + right + 2 * r[i]);
        left  += 2 * l[i];
        right += 2 * r[i];
        ans3 = max(ans3, left + right);
    }

    cout << max({ans1, ans2, ans3}) << endl;
    return 0;
}

Measured memory_bytes: 4044
N, K = map(int, input().split())
RSP = list(map(int, input().split()))
T = input()

hands = "rsp"

def f(t):
    n = len(t)
    if n == 0:
        return 0
    dp = [[-1 for hand in hands] for i in range(n)]
    for i in range(n):
        for j in range(len(hands)):
            point = RSP[j] if hands[(j + 1) % 3] == t[i] else 0
            if i == 0:
                dp[i][j] = point
            else:
                dp[i][j] = point + max(dp[i - 1][(j + 1) % 3], dp[i - 1][(j + 2) % 3])
    return max(dp[n - 1])

print(sum(map(lambda i: f(T[i::K]), range(K))))

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

int main(){
  int N;
  cin >> N;
  const int M = 1e6+1;
  vector<int> A(N), B(M);
  int g = 0;
  for(int i = 0; i < N; ++i){
    cin >> A[i];
    ++B[A[i]];
    g = __gcd(g,A[i]);
  }
  if(g != 1){
    cout << "not coprime" << endl;
    return 0;
  }
  for(int i = 2; i < M; ++i){
    int c = 0;
    for(int j = 1; i*j < M; ++j){
      c += B[i*j];
    }
    if(c > 1){
      cout << "setwise coprime" << endl;
      return 0;
    }
  }
  cout << "pairwise coprime" << endl;
}


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

int x,y,t;
int xx,yy,tt;
int n;

int Abs(int k)
{
    if (k>=0) return k;
    else return -k;
}

int main()
{
    x=y=t=0;
    scanf ("%d",&n);
    for (int i=1;i<=n;i++)
        {
        scanf ("%d %d %d",&tt,&xx,&yy);
        if ((Abs(xx-x)+Abs(yy-y)-(tt-t))%2!=0 || Abs(xx-x)+Abs(yy-y)>tt-t) {printf ("No"); return 0;}
        t=tt;
        x=xx;
        y=yy;
        }
    printf ("Yes");
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>

#define MAX 1000005
using namespace std;

int main(){
    int n,m;
    int cnt;
    int ans = 0;
    scanf("%d%d",&n,&m);
    for(int i =0;i<m;i++){
        scanf("%d",&cnt);
        ans+=cnt;
    }
    if(n-ans>=0)printf("%d",n-ans);
    else printf("-1");


}

Measured memory_bytes: 1736
#include <bits/stdc++.h>
using namespace std;
template <typename T> inline void read(T &x){
    char c;
    bool nega=0;
    while((!isdigit(c=getchar()))&&(c!='-'));
    if(c=='-'){
        nega=1;
        c=getchar();
    }
    x=c-48;
    while(isdigit(c=getchar())) x=x*10+c-48;
    if(nega) x=-x;
}
template <typename T> inline void writep(T x){
    if(x>9) writep(x/10);
    putchar(x%10+48);
}
template <typename T> inline void write(T x){
    if(x<0){
        putchar('-');
        x=-x;
    }
    writep(x);
}
template <typename T> inline void writeln(T x){
    write(x);
    putchar('\n');
}
#define pb push_back
#define mp make_pair
#define NMAX 100001
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
int n,k;
string s;
set <string> v;
inline bool cmp(const string &x,const string &y){
    for(int i=0;i<min(x.size(),y.size());i++){
        if(x[i]!=y[i]) return x[i]<y[i];
    }
    if(x.size()<y.size()) return true;
    return false;
}
int main(){
    //freopen("C.inp","r",stdin);
    cin>>s>>k;
    for(int i=0;i<s.size();i++){
        for(int j=0;j<5;j++){
            if(i+j<s.size()){
                v.insert(s.substr(i,j+1));
        //        cout<<s.substr(i,j+1)<<" ";
            }
        }
        //cout<<'\n';
    }
    vector <string> res (v.begin(),v.end());
  //  sort(v.begin(),v.end(),cmp);
    cout<<res[k-1];
}


Measured memory_bytes: 1792
import sys
sys.setrecursionlimit(10**9)

N = int(input())
edge = [[] for _ in range(N)]

for i in range(N-1):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    edge[a].append(b)
    edge[b].append(a)

C = list(map(int, input().split()))
C.sort(reverse=True)
nodes = [0] * N

#print(nodes)
cidx = -1
ans = []
def dfs(v, pv, w):
    global cidx
    cidx += 1
    nodes[v] = C[cidx]
    ans.append(min(w, C[cidx]))
    for nv in edge[v]:
        if pv == nv: continue
        dfs(nv, v, C[cidx])

dfs(0, 0, 0)
print(sum(ans))
print(*nodes, sep=" ")


Measured memory_bytes: 82040
#include<iostream>
#include<cmath>
#include<bits/stdc++.h>
#include<string.h>
#include<stdio.h>
long long int n,x,a[100005],ans=0;
using namespace std;

int main()
{
     scanf("%lld %lld",&n,&x);
    for(int i=1;i<=n;i++)
    {
        scanf("%lld",&a[i+1]);
    }
    for(int i=1;i<=n;i++)
    {
        if(a[i+1]+a[i]>x)
        {
            ans+=a[i+1]+a[i]-x;
            a[i+1]=x-a[i];
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <algorithm> // sort
#include <map>

#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;
using namespace std;


int main(){
    ll m1,d1,m2,d2;
    cin >> m1 >> d1;
    cin >> m2 >> d2;
    ll res = 0;
    if(d1 > d2)
    {
        res = 1;
    }
    cout << res << endl;

    return 0;    
}



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

typedef long long int ll;
int main() {
    int N;
    cin >> N;
    vector<ll> A(N), B(N);
    for (int i = 0; i < N; i++) cin >> A[i] >> B[i];
    ll c = 0;
    for (int i = N - 1; i > -1; i--) {
        c += ((A[i] + c) % B[i]) ? (B[i] - ((A[i] + c) % B[i])) : 0LL;
    }

    cout << c << endl;

    return 0;
}


Measured memory_bytes: 1920