akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

typedef long long lint;
typedef long double ldouble;
#define REP(i, x, n) for(int i = x ; i < n ; i++)
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for(int i = n - 1 ; i >= 0 ; i--)
#define SORT(c) sort((c).begin(), (c).end())

const int IINF = 1e9 + 10;
const lint LLINF = 1e18;
const lint MOD = 1e9 + 7;
const lint inv = MOD - 2;

int main(){
    int a, b;
    while(cin >> a >> b && a){
        int n;
        cin >> n;
        set< pair<int, int> > st;
        rep(i, n){
            int x, y;
            cin >> x >> y;
            st.insert(make_pair(x, y));
        }
        int dp[20][20];
        REP(i, 1, a+1){
            REP(j, 1, b+1){
                if(st.count(make_pair(i, j))){
                    dp[i][j] = 0;
                    if(i == 1){
                        st.insert(make_pair(1, j+1));
                    }
                    if(j == 1){
                        st.insert(make_pair(i+1, 1));
                    }
                }else if(i == 1 || j == 1){
                    dp[i][j] = 1;
                }else{
                    dp[i][j] = dp[i-1][j] + dp[i][j-1];
                }
            }
        }
        cout << dp[a][b] << endl;
    }
    return 0;
}


Measured memory_bytes: 3012
import java.io.File

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readLong() = readLn().toLong() // single long
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map(String::toInt) // list of ints
private fun readLongs() = readStrings().map(String::toLong) // list of longs

var n: Int = 0

fun main(args: Array<String>) {
    val L = readInt()
    val d = L / 3.0

    println("%.8f".format(d * d * d))
}


Measured memory_bytes: 31920
#include <iostream>

char rot_n(char c, int n) {
  char cc = c + n;
  if (cc > 'Z')
    return cc - 26;
  return cc;
}

int main(int argc, char *argv[]) {
  int n;
  std::cin >> n;
  std::string s;
  std::cin >> s;
  for (auto c : s)  {
    std::cout << rot_n(c, n);
  }
  std::cout << std::endl;
}


Measured memory_bytes: 3128
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Competitive
{
    internal class Solution
    {
        public int N, M;
        public long MOD = 1000000007;

        public void Run()
        {
            {
                var line = Input.ReadIntArray();
                N = line[0];
                M = line[1];
            }

            for (int p = 1; p * p <= M; p++)
            {
                if (M % p != 0) continue;
                if (p < N) continue;
                int v = M / p;
                Console.WriteLine(v);
                return;
            }

            int vm = 1;
            while (vm * vm < M)
            {
                vm++;
            }


            for (int v = vm; v >= 1; v--)
            {
                if (M % v != 0) continue;
                int p = M / v;
                if (p < N) continue;
                Console.WriteLine(v);
                return;
            }

        }
    }

    // libs ----------


    // common ----------

    internal static class Input
    {
        public static string ReadString()
        {
            string line = Console.ReadLine();
            return line;
        }

        public static int ReadInt()
        {
            string line = Console.ReadLine();
            return int.Parse(line);
        }

        public static int[] ReadIntArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(int.Parse).ToArray();
        }

        public static long ReadLong()
        {
            string line = Console.ReadLine();
            return long.Parse(line);
        }

        public static long[] ReadLongArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] ReadDoubleArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(double.Parse).ToArray();
        }
    }

    internal class Program
    {
        public static void Main(string[] args)
        {
            var s = new Solution();
            s.Run();
        }
    }
}

Measured memory_bytes: 13396
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; ++i)
#define rrep(i, n) for(int i = n-1; i >= 0; --i)
#define fi first
#define se second
using namespace std;
using lint = long long;
using uint = unsigned int;
using ulint = unsigned long long;
using ldouble = long double;
using pii = pair<int, int>;
using pli = pair<lint, lint>;
using pdd = pair<double, double>;
using pld = pair<ldouble, ldouble>;
using v1i = vector<int>;
using v1li = vector<lint>;
using v2i = vector<vector<int>>;
using v2li = vector<vector<lint>>;
using v3i = vector<vector<vector<int>>>;
using v3li = vector<vector<vector<lint>>>;
using v1b = vector<bool>;
using v2b = vector<vector<bool>>;
using v3b = vector<vector<vector<bool>>>;
using v1c = vector<char>;
using v2c = vector<vector<char>>;
using v3c = vector<vector<vector<char>>>;
constexpr lint mod1 = 1e9+7;
constexpr lint mod2 = 998244353;

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  swap(a, b);
  swap(a, c);
  cout << a << " " << b << " " << c << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int INF=999999999;
int a,b,ans1=INF,ans2=INF;
vector<int> p;
int main(){
	cin>>a>>b;
	if(b==0){
		cout<<a;return 0;
	}
	for(int i=0;i<b;i++){
		int x;cin>>x;p.push_back(x);
	}
	sort(p.begin(),p.end());
	if(p[0]==a){
		cout<<a-1;return 0;
	}
	int fbd=-1;
	for(int i=1;i<b;i++){
		if(i==b-1 || (p[i]>=a && p[i-1]<a)){
			fbd=i;break;
		}
	}
	if(p[fbd]!=a){
		cout<<a;return 0;
	}
	int i=fbd-1,j=fbd+1;
	for(;i>=0;i--){
		if(p[i+1]-p[i]>1){
			ans1=p[i+1]-1;break;
		}
		if(i==0){
			ans1=p[i]-1;break;
		}
	}
	for(;j<b;j++){
		if(p[j-1]+1<p[j]){
			ans2=p[j-1]+1;break;
		}
		if(j==b-1){
			ans2=p[j]+1;break;
		}
	}
	if(ans1==INF){
		ans1=a-1;
	}
	if(ans2==INF){
		ans2=a+1;
	}
	if(a-ans1<=ans2-a){
		cout<<ans1;
	}
	else {
		cout<<ans2;
	}
	return 0;
}

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

using namespace std;
using ll = long long;


int n;
void dfs(string s, char nax){
    
    if((int)s.size() == n){
        cout << s << endl;
        return;
    }

    for(int i = 'a' ; i <= nax + 1; i++){
        string S = s;
        S.push_back(i);
        dfs(S ,(i <= nax ? nax : nax + 1));
    }



}   




int main()
{
    cin >> n;
    dfs("a", 'a');

}


Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
#define forn(i, n)             for(int i = 0; i < n; i ++)
#define forn1(i, n)            for(int i = 1; i <= n; i ++)
#define loop(i, sta, end, inc) for(int i = sta; i <= end; i += inc)
#define itr(it, l)             for(auto it = l.begin(); it != l.end(); it ++)
#define in(a, b, c)            assert( b <= a && a <= c)
#define pb push_back
#define ll long long int
#define fi first
#define se second
#define ii  pair<long long int, long long int>
#define vi  vector <long long int>
#define vii vector <pair <long long int, long long int > >
#define all(cont)  cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define what_is(x) cerr<<#x<<" ="<<x<<" ";
#define error(args...)  { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define LINT_MAX  9223372036854775807
#define LINT_MIN -9223372036854775808
#define EPS 1e-9
#define MOD 998244353
#define DEBUG 0
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#pragma GCC optimize ("Ofast")
#define endl '\n'
#endif

template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }
void err(istream_iterator<string> it) { cerr<<endl;}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    if(DEBUG == 0)return;
	cerr << *it << " = " << a <<" ";
	err(++it, args...);
}

ll cnt[2][3];

map <char,int > mapp = {
						{'B',0},
						{'G',1},
						{'R',2}
					   };

int main(){

	//freopen("input.txt","r",stdin);
	clock_t clk = clock();
	int n;cin>>n;
	string s;cin>>s;
	
	ll ans =1;
	forn(i,s.size()){
		ll t = mapp[s[i]];

		if(cnt[1][t]){
			ans *= cnt[1][t];
			ans %= MOD;
			cnt[1][t] --;
		}
		else{
			if(cnt[0][(t+1)%3] || cnt[0][(t+2)%3]){
				ll x = (cnt[0][(t+1)%3])?(t+1)%3:(t+2)%3;
				ans *= cnt[0][x];
				ans %= MOD;
				cnt[0][x]--;
				cnt[1][3-t-x]++;
				}
			else{
				cnt[0][t]++;
			}
		}
	}
	forn1(i,n){
		ans *= i;
		ans %= MOD;
	}
	cout<<ans;

    cerr << endl << setprecision(10) << fixed << (double)(clock() - clk) / CLOCKS_PER_SEC;
    return 0;
}





Measured memory_bytes: 900
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
ll N;
cin>>N;
ll ca=0;
ll cb=0;
ll cc=0;
ll N1=N;
ll cd=0;
if(N==2){
cout<<1<<endl;}
else{
for(long long i=1;i*i<=N-1;i++){
if((N-1)%i==0){
ca+=2;}
if(i*i==N-1){
ca--;}}
ca--;
for(long long i=2;i*i<=N;i++){
if(N%i==0){
while(N!=1){
if(N%i==0){
cb++;
N/=i;}
else{
cc++;
goto asd;}}
asd:
if(cc==1){
cb=0;
cc=0;}
else{
goto as;}}
N=N1;}
as:
cc=0;
for(long long i=1;i*i<=cb;i++){
if(cb%i==0){
cc+=2;}
if(i*i==cb){
cc--;}}
if(cc!=0){
cc--;}
N=N1;
for(long long i=2;i*i<=N;i++){
if(N%i==0){
while(N%i==0){
N/=i;}
if((N-1)%i==0&&N!=1){
cd++;}}
N=N1;}
cd++;
cout<<ca+cc+cd<<endl;}}


Measured memory_bytes: 3584
#include<bits/stdc++.h>
#define same(a,b) (find(a)==find(b))
#define uni(a,b) fa[find(a)]=find(b)
#define init(n) for(int i=0;i<n;i++) fa[i]=i

int fa[100100];

int find(int x)
{
	if(x==fa[x]) return x;
	return fa[x]=find(fa[x]);
}

int main()
{
	int n,q;
	scanf("%d%d",&n,&q);
	init(n);
	for(int i=0;i<q;i++)
	{
		int t,u,v;
		scanf("%d%d%d",&t,&u,&v);
		if(t==0) uni(u,v);
		else if(same(u,v)) printf("1\n");
		else printf("0\n");
	}
	return 0;
}

Measured memory_bytes: 3160
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;cin >>N;
  int A[N],B[N],C[N];
  int ans=0;
  for(int i=0;i<N;++i) cin >>A[i];
  for(int i=0;i<N;++i) {
    cin >>B[i];
    ans+=B[i];
  }
  for(int i=0;i<N-1;++i) cin >>C[i];
  for(int i=0;i<N-1;++i) {
    if(A[i+1]-1==A[i]) ans+=C[A[i]-1];
  }
  cout <<ans;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <functional>
#include <iterator>
#include <numeric>
#include <cstdint>
#include <cmath>
#include <bitset>
#include <string>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>

#define N_TIMES(i, n)     for ( uint64_t i = 0;     i <  n; ++i )
#define N_TIMES_REV(i, n) for (  int64_t i = n - 1; i >= 0; --i )

std::string N;
uint64_t D;

uint64_t dp(uint64_t d, bool f, bool z, std::bitset<3> deg)
{
  if (d == D) {
    return deg.all() ? 1 : 0;
  }
  
  uint64_t X = f ? N[d] - '0' : 9, S = 0;
  for (uint64_t x = 0; x <= X; ++x) {
    if (z && x == 0) {
      bool g = f && (x == X);
      S += dp(d + 1, g, true, deg);
    } else if (x == 3 || x == 5 || x == 7) {
      std::bitset<3> new_deg(deg);
      if (x == 3) new_deg.set(0);
      if (x == 5) new_deg.set(1);
      if (x == 7) new_deg.set(2);
      
      bool g = f && (x == X);
      S += dp(d + 1, g, false, new_deg);
    }
  }
  
  return S;
}

int main(int argc, char **argv)
{
  std::cin >> N;
  
  D = N.size();
  
  uint64_t S = dp(0, true, true, std::bitset<3>(0));
  
  std::cout << S << std::endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int LinearSearch(int s[], int n, int key){
  int i = 0;
  s[n] = key;
  while(s[i] != key){
i++; }
  return i != n;
}
int main(){
  int i, n, p, key, count = 0;
  int s[10000];
  scanf("%d", &n);
  for (i = 0; i < n; i++){
    scanf("%d", &s[i]);
  }
  scanf("%d", &p);
  for (i = 0; i < p; i++){
    scanf("%d", &key);
    if (LinearSearch(s, n, key) == 1){
count++;
}
}
  printf("%d\n", count);
return 0; }


Measured memory_bytes: 2128
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;

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

	int n = 64, m = 32;

	if (N >= n)
	{
		cout << n << endl;
		return 0;
	}
	else if (N == 1)
	{
		cout << N << endl;
		return 0;
	}
	else if (N < 2)
	{
		cout << '0' << endl;
		return 0;
	}

	for (int i = 0; i < 6; i++)
	{
		if (N <= n && N >= m)
		{
			cout << m;
			break;
		}
		n /= 2, m /= 2;
	}

	return 0;
}


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

int main() {
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		int x = i;
		if (x % 3 == 0) {
			cout << ' ' << i;
		}
		else {
			while (x) {
					if (x % 10 == 3) {
						cout << ' ' << i;
						break;
						}
					x /= 10;
				}
			}
		}
	cout <<endl;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define rep(i, n) for(ll i=0; i<(n); ++i)
#define rep1(i,n) for(ll i=1; i<=(n); ++i)
#define repi(i,a,b) for(ll i=a; i<=(b); ++i)
#define rrep(i,n) for(ll i=(n-1); i>=0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
#define to_s to_string
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define pr(x) cout<<(x)<<'\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
using Edge = pair<int,long long>;
using Graph = vector<vector<Edge>>;
typedef pair<ll,ll> P;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}
ll devc(ll x, ll y){return 1 + (x-1)/y;}

ll solve(ll N, ll A, ll B, ll C, vector<ll>& L){
    
    ll ans = 1e15;
    rep(i,pow(4,N)){
        ll a = 0, b = 0, c = 0, MP = 0;
        string s = "";
        
        
        ll tp = i, x = pow(4,N-1);
        rep(j,N) s += to_s(tp / x), tp %= x, x /= 4;
        rep(j,N){
            if(s[j] == '1'){
                if(a != 0) MP += 10;
                a += L[j];
            }
            if(s[j] == '2'){
                if(b != 0) MP += 10;
                b += L[j];
            }
            if(s[j] == '3'){
                if(c != 0) MP += 10;
                c += L[j];
            }
        }
        
        if(a*b*c == 0) continue;
        
        ans = min(ans,abs(A-a)+abs(B-b)+abs(C-c)+MP);
    }
    
    return ans;
}

int main(){
    ll N,A,B,C; cin >> N >> A >> B >> C;
    vector<ll> L(N); rep(i,N) cin >> L[i];
    
    pr(solve(N,A,B,C,L));
    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)
#define all(a) (a).begin(),(a).end()
typedef long long ll;

class modint {
  public:
    using ll = long long;
    ll num;
    static const ll MOD = 1e9+7;
    static vector<modint> factorial;

    modint(): num(0) {};
    modint(ll n_): num((n_ + MOD) % MOD) {}
    modint(const modint &r): num(r.num) {}
    operator ll() const { return (num+MOD)%MOD; }
    friend istream& operator>>(istream& is, modint &r){
        ll num_;
        is >> num_;
        r = num_;
        return is;
    }
    modint operator+(const modint &r) const { return modint(num + r.num); }
    modint operator-(const modint &r) const { return modint(num - r.num); }
    modint operator*(const modint &r) const { return modint(num * r.num); }

    template<typename T>
    modint operator^(const T &r) const {
        if(r == 0) return 1;
        return (((*this)*(*this)) ^ (r/2)) * modint(r&1 ? num : 1);
    }
    modint operator/(const modint &r) const { return num * (r^(MOD-2)); }

    modint operator+=(const modint &r) { return *this = *this + r; }
    modint operator-=(const modint &r) { return *this = *this - r; }
    modint operator*=(const modint &r) { return *this = *this * r; }
    modint operator/=(const modint &r) { return *this = *this / r; }

    template<typename T>
    modint operator^=(const T &r) { return *this = *this ^ r; }

    static modint pow(const modint x, ll r) {
        return x^r;
    }

    static modint fact(int n){
        if((int)factorial.size() <= n) factorial.resize(n+1);
        if(factorial[n]) return factorial[n];
        if(n == 0) return 1;
        return factorial[n] = modint(n) * fact(n-1);
    }

    static modint C(ll n,ll r){
        return n >= r ? fact(n)/(fact(n-r)*fact(r)) : modint(0);
    }
};
vector<modint> modint::factorial;
#define fact(n) modint::fact(n)
#define C(n,r) modint::C(n,r)
#define H(a,b) C(a+b, a)


vector<vector<int>> g;

ll n, k;

modint dfs(int pre, int cur, int minus){
    modint res = k - minus >= 0 ? k - minus : 0;
    int cnt = 0;
    for(int to : g[cur]) if(to != pre) {
        res *= dfs(cur, to, (pre >= 0) + 1 + cnt);
        cnt++;
    }
    return res;
}

int main(void){
    cin >> n >> k;
    g.resize(n);
    rep(i,n-1){
        int a,b;
        cin >> a >> b;
        a--, b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    cout << dfs(-1, 0, 0) << endl;
    return 0;
}


Measured memory_bytes: 12800
#include <iostream>
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<ll,ll>P;
ll n,m,s,g,aa,bb,a,b,loc1[100000],loc2[100000],flag[100000];
int main(void){
  cin>>n>>m>>s>>g;
  s--,g--;
  vector<vector<P>>G1(n),G2(n);
  for(int i=0;i<m;i++){
    cin>>aa>>bb>>a>>b;
    aa--,bb--;
    G1[aa].push_back({bb,a});
    G1[bb].push_back({aa,a});
    G2[aa].push_back({bb,b});
    G2[bb].push_back({aa,b});
  }
  for(int i=0;i<n;i++)loc1[i]=(1LL<<60);
  priority_queue<P,vector<P>,greater<P>>pque;
  pque.push({0,s});
  loc1[s]=0;
  while(pque.size()){
    auto p=pque.top();
    pque.pop();
    if(!flag[p.S]){
      flag[p.S]=1;
      for(auto x:G1[p.S]){
        if(loc1[p.S]+x.S<loc1[x.F]){
          loc1[x.F]=loc1[p.S]+x.S;
          pque.push({loc1[x.F],x.F});
        }
      }
    }
  }
  for(int i=0;i<n;i++){loc2[i]=(1LL<<60);flag[i]=0;}
  pque.push({0,g});
  loc2[g]=0;
  while(pque.size()){
    auto p=pque.top();
    pque.pop();
    if(!flag[p.S]){
      flag[p.S]=1;
      for(auto x:G2[p.S]){
        if(loc2[p.S]+x.S<loc2[x.F]){
          loc2[x.F]=loc2[p.S]+x.S;
          pque.push({loc2[x.F],x.F});
        }
      }
    }
  }
  for(int i=0;i<n;i++)loc1[i]+=loc2[i];
  for(int i=n-1;i>=1;i--){
    loc1[i-1]=min(loc1[i-1],loc1[i]);
  }
  for(int i=0;i<n;i++)cout<<1000000000000000LL-loc1[i]<<endl;
}


Measured memory_bytes: 19576
#include<stdio.h>
 
#define INF 1000000
#define K 2000000
 
int n = 0;
int s[K];
 
void increase(int *s, int i, int key){
  int tmp;
 
  s[i] = key;
 
  while(i > 1 && s[i/2] < s[i]){
    tmp = s[i];
    s[i] = s[i/2];
    s[i/2] = tmp;
    i = i/2;
  }
}
 
void insert(int *s, int k){
  n += 1;
  s[n] = -INF;
  increase(s, n, k);
}
 
void maxHeapify(int *s, int i){
  int l, r, tmp, largest;
 
  l = 2*i;
  r = 2*i + 1;
 
  if(l <= n && s[l] > s[i]) largest = l;
  else largest = i;
 
  if(r <= n && s[r] > s[largest]) largest = r;
 
  if(largest != i){
    tmp = s[i];
    s[i] = s[largest];
    s[largest] = tmp;
    maxHeapify(s, largest);
  }
}
 
int extractMax(int *s){
  int max;
 
  max = s[1];
  s[1] = s[n];
  n--;
  maxHeapify(s, 1);
 
  return max;
}
 
int main(){
  int i=0, k, j, max[K];
  char chil[10];
 
  while(1){
    scanf("%s", chil);
 
    if(chil[0] == 'i'){
      scanf("%d", &k);
      insert(s, k);
    }
 
    else if(chil[1] == 'x'){
      max[i] = extractMax(s);
      i++;
    }
    else if(chil[1] == 'n') break;
  }
 
  for(j = 0; j < i; j++) printf("%d\n", max[j]);
 
  return 0;
}

Measured memory_bytes: 8000
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int x;
  cin>>x;
  int c1=0,c2=0,r1,res;
  if(x<5)
    res=0;
  if(x>=500)
  {c1=x/500;
   r1=x%500;
   c2=r1/5;  
  }
  if(x<500&&x>=5)
    c2=x/5;
  res=c1*1000+c2*5;
  cout<<res;
} 

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

using namespace std;
typedef long long LL;

LL N,A,B,C,D;

bool solve()
{
	LL L=A-(N-1)*D;
	LL R=A+(N-1)*D;
	
	if (B<L || B>R)
	{
		//printf("id1");
		return false;
	}
	if (N*C-N*D+2*D<0)
	{
		//printf("id2");
		return true;
	}
	else
	{
		LL pos=(B-L)%(C+D);
		if (pos<=(N-1)*(D-C))
		{
			//printf("id3");
			return true;
		}
		else
		{
			//printf("id4");
			return false;
		}
	}
}

int main(void)
{
	#ifdef ex
	freopen ("in","r",stdin);
	#endif
	
	while (scanf("%lld%lld%lld%lld%lld",&N,&A,&B,&C,&D)==5)
	{
		if (solve()) printf("YES\n");
		else printf("NO\n");
	}
}

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

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back

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

int main(){
	int m,d;
	cin>>m>>d;

	if(d<22){
		cout<<0<<endl;
		return 0;
	}

	int ans=0;
	for (int i = 1; i <= m; ++i){
		for (int j = 22; j <= d ; ++j){
			if(((j/10)*(j%10))==i && j/10>=2&&j%10>=2){
				ans++;
			}
		}
	}

	cout<<ans<<endl;

	return 0;
}


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

using namespace std;

#define ff first
#define ss second

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<long long, long long> pl;

const int MOD = 1e9 + 7;
const ll INF = 1e18;
const double EPS = 1e-6;
const int MAX_N = 2e5 + 5;

class SegmentTree {
public:
	int N;
	vector<ll> maximum, delta;

	SegmentTree() {}

	SegmentTree(int N) {
		this->N = N;
		maximum = vector<ll>(4 * N + 1);
	}
	
	void update(int l, int r, ll val) {update(1, 0, N - 1, l, r, val);} //inclusive range
	
	ll query(int l, int r) {return query(1, 0, N - 1, l, r);} //inclusive range

	void pull(int i) {
		maximum[i] = max(maximum[2 * i], maximum[2 * i + 1]);
	}
	
	void update(int i, int lo, int hi, int l, int r, ll val) {
		if (r < lo || hi < l) return;
		if (l <= lo && hi <= r) {
			maximum[i] = max(maximum[i], val);
			return;
		}
		
		int m = (lo + hi) / 2;
		update(2 * i, lo, m, l, r, val);
		update(2 * i + 1, m + 1, hi, l, r, val);
		
		pull(i);
	}
	
	ll query(int i, int lo, int hi, int l, int r) {
		if (r < lo || hi < l) return 0;
		if (l <= lo && hi <= r) {
			return maximum[i];
		}
		
		int m = (lo + hi) / 2;
		ll maxLeft = query(2 * i, lo, m, l, r);
		ll maxRight = query(2 * i + 1, m + 1, hi, l, r);
		
		pull(i);
		
		return max(maxLeft, maxRight);
	}
};

int N;
ll height[MAX_N], beauty[MAX_N];
ll dp[MAX_N];
SegmentTree st(MAX_N);

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	cin >> N;
	for (int i = 0; i < N; ++i) {
		cin >> height[i];
	}
	for (int i = 0; i < N; ++i) {
		cin >> beauty[i];
	}

	for (int i = 0; i < N; ++i) {
		dp[i] = st.query(0, height[i]) + beauty[i];
		st.update(height[i], height[i], dp[i]);
	}

	ll ans = 0;
	for (int i = 0; i < N; ++i) {
		ans = max(ans, dp[i]);
	}
	cout << ans << '\n';

	return 0;
}

Measured memory_bytes: 11264
import java.util.*;

public class Main {

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

    static class Period {
        int s;
        int e;

        public Period(int s, int e) {
            this.s = s;
            this.e = e;
        }
    }

    static void solve(Scanner scanner) {
        int N = scanner.nextInt(), C = scanner.nextInt();
        scanner.nextLine();
        List<TreeSet<Period>> m = new ArrayList<>();
        for (int i = 0; i < C; i++) {
            m.add(new TreeSet<>(Comparator.comparingInt(x -> x.s)));
        }
        for (int i = 0; i < N; i++) {
            int s = scanner.nextInt(), t = scanner.nextInt(), c = scanner.nextInt() - 1;
            if (scanner.hasNext())
                scanner.nextLine();
            m.get(c).add(new Period(s, t));
        }

        int[] imos = new int[100_002];
        for (TreeSet<Period> s : m) {
            int pe = -1;
            for (Period p : s) {
                if (pe == -1) {
                    imos[p.s]++;
                    pe = p.e;
                } else {
                    if (pe != p.s) {
                        imos[pe + 1]--;
                        imos[p.s]++;
                    }
                    pe = p.e;
                }
            }
            if (pe != -1) {
                imos[pe + 1]--;
            }
        }

        int ans = 0;
        for (int i = 1; i < 100_002; i++) {
            imos[i] += imos[i - 1];
            ans = Math.max(ans, imos[i]);
        }

        // System.out.println(Arrays.toString(imos));
        System.out.println(ans);
    }

}

Measured memory_bytes: 165932
import java.util.*;
public class Main{
    
    static final int MOD = (int)1e9 + 7;
    
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        
        long ans;
        if(n==1){
            ans = 0;
        }else if(n==2){
            ans = 2;
        }else{
            long[][] dp = new long[n+1][4];
            dp[0][0] = 1;
            for(int i=0; i<n; i++){
                for(int j=0; j<4; j++){
                    if(j==0){
                        dp[i+1][1] += dp[i][j];
                        dp[i+1][1] %= MOD;
                        dp[i+1][2] += dp[i][j];
                        dp[i+1][2] %= MOD;
                        dp[i+1][0] += dp[i][j]*8;
                        dp[i+1][0] %= MOD;
                    }else if(j==1){
                        dp[i+1][3] += dp[i][j];
                        dp[i+1][3] %= MOD;
                        dp[i+1][1] += dp[i][j]*9;
                        dp[i+1][1] %= MOD;
                    }else if(j==2){
                        dp[i+1][3] += dp[i][j];
                        dp[i+1][3] %= MOD;
                        dp[i+1][2] += dp[i][j]*9;
                        dp[i+1][2] %= MOD;
                    }else if(j==3){
                        dp[i+1][3] += dp[i][j]*10;
                        dp[i+1][3] %= MOD;
                    }
                }
            }
            ans = dp[n][3];
        }
        
        System.out.println(ans);
    }
}

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

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

  if (max({a, b, c, d, e}) - min({a, b, c, d, e}) > k)
    cout << ":(" << endl;
  else
    cout << "Yay!" << endl;
  return 0;
}

Measured memory_bytes: 3592
#include <stdio.h>
#include <string.h>

void addstr(char *str1, char *str2)
{
    char temp[1000];
    int max;
    int i;
    
    if (strlen(str1) > strlen(str2)){
        max = strlen(str1);
    }
    else {
        max = strlen(str2);
    }
    
    memset(temp, '\0', 1000);
    strcpy(&temp[max - strlen(str1) + 1], str1);
    i = 0;
    while (temp[i] == '\0'){
         temp[i] = '0';
         i++;
    }
    strcpy(str1, temp);
    
    memset(temp, '\0', 1000);
    strcpy(&temp[max - strlen(str2) + 1], str2);
    i = 0;
    while (temp[i] == '\0'){
         temp[i] = '0';
         i++;
    }
    strcpy(str2, temp);
    
    for (i = max; i >= 0; i--){
        str1[i] += str2[i] - '0';
        if (str1[i] > '9'){
            str1[i] -= 10;
            str1[i - 1] += 1;
        }
    }
    if (str1[0] == '0'){
        memset(temp, '\0', 1000);
        strcpy(temp, &str1[1]);
        memset(str1, '\0', 1000);
        strcpy(str1, temp);
    }
}

int main( void ) {

    char a[1000], b[1000];
    int n;
    
    scanf( "%d", &n );
    
    while ( n-- != 0 ){
        
        scanf( "%s", a );
        scanf( "%s", b );
        
        addstr( a, b );
        
        if ( strlen( a ) <= 80 ) {

            printf( "%s\n", a );

        } else {

            printf( "overflow\n" );

        }

    }
    
    return 0;

}

Measured memory_bytes: 596
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <math.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 10e+6

using namespace std;


int main(){
    int n,m;
    cin >> n >> m;
    long ans;
    long t=100*n+1800*m;
    long A=pow(2,m);
    ans=t*A;
    cout << ans << endl;
}


Measured memory_bytes: 256
MAIN : {
	my $s1 = <STDIN>;
	chomp $s1;
	my ($n, $m) = split(" ", $s1);

	my %a;

	for ($i = 0; $i < $n; $i++) {
		$s1 = <STDIN>;
		chomp $s1;
		my @k = split(" ", $s1);
		
		for ($j = 1; $j < scalar(@k); $j++) {
			$a{$k[$j]} += 1;
		}
	}
	
	my $ans = 0;
	foreach my $key (keys(%a)) {
		if ($a{$key} eq $n) {
			$ans++;
		}
	}
	print STDOUT $ans, "\n";
}





__END__

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
#define acc(v) accumulate(v.begin(), v.end(), 0)
#define cinv(n,v) rep(i,n) cin >> v[i]
using namespace std;
const int INF = 1e9;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
int x_pos[4] = {1,0,-1,0}, y_pos[4] = {0,1,0,-1};
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

char upper(char c){
	return c-0x20;
}

char lower(char c){
	return c+0x20;
}

void unique_vector(vector<int>& v){
	sort(all(v));
	v.erase(unique(all(v)), v.end());
}

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

//ユークリッドの互除法
//最大公約数
ll gcd(ll x, ll y) {
  if (y == 0) return x;
  return gcd(y, x%y);
}

//最小公倍数
ll lcm(ll x, ll y){
	ll g = gcd(x,y);
	return x/g*y;
}

ll myPow(ll x, ll n, ll m){
  if(n == 0)
    return 1;
  if(n % 2 == 0)
    return myPow(x * x % m, n / 2, m);
  else
    return x * myPow(x, n - 1, m) % m;
}

int main() {
	int n;
	int ans = 0;
	cin >> n;
	vector<int> b(n);
	rep(i,n-1){
		cin >> b[i];
	}
	ans += b[0];
	rep(i, n-1)
	{
		if (i == n - 2)
		{
			ans += b[i];
			continue;
		}
		ans += min(b[i], b[i + 1]);
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include<algorithm>
#include <iomanip>
#include <math.h>

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,a,b) for(int i=(int)(a); i<(int)(b); i++)
#define FORR(i,a,b) for(int i=(int)(b)-1; i>=(int)(a); i--)
#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))
#define ALL(v) (v).begin(),(v).end()
//定義場所//
ll i, j, k, l, m, n;
ll N, M, K, H, W, T, P;
ll MOD = 1000000000+7;
ll ans = 0;
//関数リスト//
int ctoi(char c) {
	switch (c) {
	case '0': return 0;
	case '1': return 1;
	case '2': return 2;
	case '3': return 3;
	case '4': return 4;
	case '5': return 5;
	case '6': return 6;
	case '7': return 7;
	case '8': return 8;
	case '9': return 9;
	default: return 0;
	}
}
//(注)pairの型・比較する場所(first/second)は毎回変えて使用する
bool pairCompare(const pair<int ,int> firstElof, pair<int,int> secondElof)
{
	return firstElof.second < secondElof.second;
}
int Keta(ll F) {
	int keta = 1;
	while (F/10 > 0) {
		keta++;
		F /= 10;
	}
	return keta;
}
ll modinv(ll a, ll m) {
	ll b = m, u = 1, v = 0;
	while (b) {
		ll t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
//////////////

int main() {
	cin >> N >> i;
	cout << N - i + 1;
}

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

int main() 
{
  int n;
  cin >> n;
  priority_queue<int> card;
  for(int i = 0; i < n; i++)
  {
    int a;
    cin >> a;
    card.push(a);
  }
  int alice = 0;
  int bob = 0;
  for(int i = 1; i <= n; i++)
  {
    if(card.empty())
    {
      break;
    }
    
    if(i % 2 != 0)
    {
      alice += card.top();
      card.pop();
    }
    else
    {
      bob += card.top();
      card.pop();
    }
    
  }
  cout << alice - bob << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using LL  = long long;
using VI  = vector<LL>;
using VVI = vector<VI>;
using VB  = vector<bool>;
using VS  = vector<string>;
using PII = pair<LL, LL>;
using VP  = vector<PII>;
#define PB           push_back
#define MP           make_pair
#define SZ(a)        LL((a).size())
#define EACH(x, c)   for (auto x : (c))
#define ALL(c)       (c).begin(), (c).end()
#define REVERSE(c)   reverse(ALL(c))
#define SORT(c)      stable_sort(ALL(c))
#define RSORT(c)     stable_sort((c).rbegin(), (c).rend())
#define FSORT(c)     stable_sort(ALL(c), [] (auto& x, auto& y) {return x.first < y.first;});
#define FRSORT(c)    stable_sort(ALL(c), [] (auto& x, auto& y) {return x.first > y.first;});
#define SSORT(c)     stable_sort(ALL(c), [] (auto& x, auto& y) {return x.second < y.second;});
#define SRSORT(c)    stable_sort(ALL(c), [] (auto& x, auto& y) {return x.second > y.second;});
#define FOR(i, a, b) for (LL i = (a); i < (b); ++i)
#define REP(i, n)    FOR(i, 0, n)
#define DEBUG true
#define $(x) {if (DEBUG) {cout << #x << " = " << (x) << endl;}}


int main() {
    LL X;
    cin >> X;
    LL ans = (LL)sqrt(2 * X);
    while (ans * (ans + 1) < 2 * X) {
        ans++;
    }
    cout << ans << endl;
	
    return 0;
}


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

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

  vector<int64_t> d(n), a(n);
  int64_t max_d = 0;
  for (int64_t i = 0; i < n; i++) {
    cin >> d[i];
    a[d[i]]++;
    max_d = max(max_d, d[i]);
  }

  bool flag = true;
  int64_t ans = 0;

  if (d[0] != 0) {
    ans = 0;
    flag = false;
  }
  if (n > 1) {
    for (int64_t i = 0; i < max_d; i++) {
      if (a[i] == 0) {
        ans = 0;
        flag = false;
        break;
      }
    }
  }
  if (a[0] > 1) {
    ans = 0;
    flag = false;
  }

  if (flag) {
    ans = 1;
    for (int64_t i = 0; i < max_d; i++) {
      for (int64_t j = 0; j < a[i+1]; j++) {
        ans *= a[i];
        ans %= 998244353;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=3.14159265359;

int DP[10][10005]; // DP[使う数][桁数] = いくつ作ったか
bool okDP[10005];

int main() {
    int N, M;
    cin>>N>>M;
    vector<int> A(M);
    bool change;
    for(int i=0;i<M;++i){
        cin>>A[i];
    }
    sort(A.begin(), A.end());
    okDP[0] = true;
    map<int, int> match;
    match[1] = 2;
    match[2] = 5;
    match[3] = 5;
    match[4] = 4;
    match[5] = 5;
    match[6] = 6;
    match[7] = 3;
    match[8] = 7;
    match[9] = 6;
    int bef[10], aft[10];
    int befketa, aftketa;
    for(int i=1;i<=N;++i){
        for(int j=0;j<M;++j){
            if(match[A[j]] > i) continue;
            if(okDP[i-match[A[j]]] == false) continue;
            okDP[i] = true;
            for(int k=0;k<10;++k){
                bef[k] = DP[k][i];
                aft[k] = DP[k][i-match[A[j]]];
            }
            aft[A[j]]++;
            change = false;
            befketa = 0;
            aftketa = 0;
            for(int k=0;k<10;++k){
                befketa += bef[k];
                aftketa += aft[k];
            }
            if(befketa > aftketa) change = false;
            else if(befketa==aftketa) {
                for(int k=9;k>=0;--k){
                    if(aft[k]>bef[k]) {
                        change = true;
                        break;
                    }
                    if(aft[k]<bef[k]){
                        change = false;
                        break;
                    }
                }
            }
            else change = true;
            if(change){
                for(int k=0;k<10;++k){
                    DP[k][i] = aft[k];
                }
            }
        }
    }
    string ans;
    for(int i=9;i>=1;--i){
        for(int j=0;j<DP[i][N];++j){
            ans += i + '0';
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;

int main(){
    int64_t A,B ;
    cin >> A >> B ;
    if (B > A)
    {
        int64_t temp = A ;
        A = B ;
        B = temp ;
    }
    
    int64_t a = A ;
    int64_t b = B ;
    int64_t r = B ;
    while (r != 0)
    {
        r = a % b ;
        a = b ;
        b = r ;
    }
    int64_t gcd = a ;
    int ans = 1 ;
    int64_t now = 1 ;
    while (gcd != 1 )
    {
        now ++ ;
        if (now > pow(a,0.5))
        {
            ans ++;
            break;
        }
        if (gcd % now == 0)
        {
            ans ++ ;
            while (gcd % now == 0)
            {
                gcd = gcd / now ;
            }
            
        }
        
        
        
        
    }
    
    cout << ans << endl ;
    
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>

using namespace std;

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

	int a[n];

	int d, m;

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

	if (n == 1) {
		if (a[0] == p) {
			cout << "POSSIBLE";
		} else {
			cout << "IMPOSSIBLE";
		}

		return 0;
	}


	d = __gcd (a[0], a[1]);
	m = max (a[0], a[1]);

	if (n > 2) {
		for (int i = 2; i < n; i++) {
			d = __gcd (d, a[i]);
			m = max (m, a[i]);
		}
	}

	if (p % d == 0 && p <= m) {
		cout << "POSSIBLE";
	} else {
		cout << "IMPOSSIBLE";
	}


	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
static const int WHITE = 0;
static const int GRAY  = 1;
static const int BLACK = 2;
static const int N     = 100;

int n, tt;
vector<vector<int>> M(N, vector<int>(N));
vector<int> color(N), d(N), f(N);

void dfs_visit(int u) {
  color[u] = GRAY;
  d[u]     = ++tt;
  for (int v = 0; v < n; v++) {
    if (M[u][v] == 0) continue;
    if (color[v] == WHITE) { dfs_visit(v); }
  }
  color[u] = BLACK;
  f[u]     = ++tt;
}

void dfs() {
  tt = 0;

  for (int u = 0; u < n; u++) {
    if (color[u] == WHITE) dfs_visit(u);
  }
  for (int u = 0; u < n; u++) {
    printf("%d %d %d\n", u + 1, d[u], f[u]);
  }
}

int main() {
  int u, v, k;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> u >> k;
    u--;
    for (int j = 0; j < k; j++) {
      cin >> v;
      v--;
      M[u][v] = 1;
    }
  }

  dfs();
}


Measured memory_bytes: 3268
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	static PrintWriter out = new PrintWriter(System.out);
	public static void main(String[] args) {
		// 入力
		final int n, l;
		final String[] s;
		try(Scanner scan = new Scanner(System.in)) {
			n = scan.nextInt();
			l = scan.nextInt();
			s = new String[n];
			for (int i = 0; i < n; i++) {
				s[i] = scan.next();
			}
			
		}
		Arrays.sort(s);
		
		// 出力
		Arrays.stream(s).forEach(out::print);
		out.println();
		out.flush();
	}

}

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



template <typename Monoid, bool COMMUTATIVE = false>
class SegmentTree{
  using value_type = typename Monoid::value_type;
  
protected:
  const int depth, size, hsize;
  std::vector<value_type> data;

public:
  SegmentTree(int n):
    depth(n > 1 ? 32-__builtin_clz(n-1) + 1 : 1),
    size((1 << depth) - 1),
    hsize(size / 2 + 1),
    data(size + 1, Monoid::id())
  {}

  inline auto operator[](int i) const {return at(i);}
  inline auto at(int i) const {return data[hsize + i];}
  
  inline auto get(int x, int y) const { // [x,y)
    std::vector<int> memo;
    value_type ret = Monoid::id();
    
    int l = x + hsize, r = y + hsize;
    while(l < r){
      if(r & 1){
        if(COMMUTATIVE) ret = Monoid::op(ret, data[--r]);
        else memo.push_back(--r);
      }
      if(l & 1) ret = Monoid::op(ret, data[l++]);
      l >>= 1, r >>= 1;
    }

    if(not COMMUTATIVE){
      std::reverse(memo.begin(), memo.end());
      for(auto i : memo) ret = Monoid::op(ret, data[i]);
    }
    
    return ret;
  }

  inline void update(int i, const value_type &x){
    i += hsize;
    data[i] = x;
    while(i > 1) i >>= 1, data[i] = Monoid::op(data[i << 1 | 0], data[i << 1 | 1]);
  }

  template <typename T>
  inline void init_with_vector(const std::vector<T> &val){
    data.assign(size + 1, Monoid::id());
    for(int i = 0; i < (int)val.size(); ++i) data[hsize + i] = val[i];
    for(int i = hsize-1; i >= 1; --i) data[i] = Monoid::op(data[i << 1 | 0], data[i << 1 | 1]);
  }

  template <typename T>
  inline void init(const T &val){
    init_with_vector(std::vector<value_type>(hsize, val));
  }  

  auto debug(){
    return data;
  }
};



template <typename T>
struct MaxMonoid{
  using value_type = T;

  static value_type NINF;

  constexpr inline static value_type id(){
    return NINF;
  }

  constexpr inline static value_type op(const value_type &a, const value_type &b){
    return std::max(a, b);
  }
};

template <> int64_t MaxMonoid<int64_t>::NINF = std::numeric_limits<int64_t>::min();

using Mon = MaxMonoid<int64_t>;

int main(){
  int N; scanf("%d", &N);

  std::vector<int64_t> h(N), a(N);
  for(int i = 0; i < N; ++i) scanf("%lld", &h[i]);
  for(int i = 0; i < N; ++i) scanf("%lld", &a[i]);

  SegmentTree<Mon> seg(N+1);
  seg.init(0);

  for(int i = 0; i < N; ++i){
    int64_t t = seg.get(0, h[i] + 1);
    seg.update(h[i], t + a[i]);
  }

  printf("%lld\n", seg.get(0, N+1));
  

  return 0;
}


Measured memory_bytes: 9472
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 6)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")
al = "abcdefghijklmnopqrstuvwxyz"
AL = al.upper()

N, M = I()
A = l()
A.sort()
 
ans = 0
 
for i in range(M):
    ans += A[i]
 
print(ans)

Measured memory_bytes: 10556
#include <iostream>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <sstream>
#include <limits.h>
using namespace std;
 
int main()
{
    int n,m,k;
    cin >> n >> m >> k;
    int a[n], b[m];
    std::vector<long long int> va, vb; // sum of a[i],b[i]
    
    long long int tmp = 0;
    for(int i=0; i<n; i++){
        cin >> a[i];
        tmp += a[i];
        va.push_back(tmp);
    }
    tmp = 0;
    for(int i=0; i<m; i++){
        cin >> b[i];
        tmp += b[i];
        vb.push_back(tmp);
    }
    
    long long int ans = 0;
    for(int i=0; i<=n; i++){
        long long int num = k;
        if(i != 0) num = k - va[i-1];
        if(num < 0) continue;
        
        std::vector<long long int>::iterator itr = std::upper_bound(vb.begin(), vb.end(), num);
        std::size_t pos = std::distance(vb.begin(), itr);
        
        long long int sum;
        if(pos == 0){
            sum = i; // Bからは取れない
        }else{
            sum = i + pos;
        }
        
        if(ans < sum) ans = sum;
        //cout << num << ":" << i << ":" << pos << ":" << *itr << ":" << ans << endl;
    }
    cout << ans << endl;
 
    return 0;
}

Measured memory_bytes: 9256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    int n,m;
    cin >> n>> m;
    vector<ll>h(n);
    vector<vector<ll>>graph(n);
    REP(i,n)cin >> h[i];
    vector<ll>a(m),b(m);
    REP(i,m){
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
        graph[a[i]].push_back(b[i]);
        graph[b[i]].push_back(a[i]);
    }
    ll answer = 0;
    REP(i,n){
        bool ok = true;
        REP(j,graph[i].size()){
            if(h[i] <= h[graph[i][j]])ok=false;
        }
        if(ok)answer++;
    }
    cout << answer << endl;

    return 0;
}

Measured memory_bytes: 11336
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include<queue>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include<iomanip>

//#include<bits/stdc++.h>


using namespace std;


int main() {
	
	int w, a, b;
	cin >> w >> a >> b;
	if (a > b)swap(a, b);
	
	if (a + w >= b)cout << 0 << endl;
	else cout << b - a - w << endl;

	return 0;

}


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

using namespace std;

int p[10000];
int r[10000];

int findSet(int x) {
	while (x != p[x]) {
		x = p[x];
	}
	return x;
}

bool same(int x, int y) {
	return findSet(x) == findSet(y);
}

void link(int x, int y) {
	if (r[x] > r[y]) {
		p[y] = x;
		return;
	}
	if (r[x] < r[y]) {
		p[x] = y;
		return;
	}
	p[y] = x;
	r[x]++;
}

void unite(int x, int y) {
	link(findSet(x), findSet(y));
}




int main() {
	int n, q;
	int com;
	int x, y;

	cin >> n >> q;
	for (int i = 0; i < n; i++) {
		p[i] = i;
		r[i] = 0;
	}

	for (int i = 0; i < q; i++) {
		cin >> com >> x >> y;
		if (com == 0) {
			unite(x, y);
			continue;
		}
		if (com == 1) {
			cout << (same(x, y) ? 1 : 0) << endl;
			continue;
		}
	}

	return 0;
}

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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 60)
#define PI 3.14159265358979

typedef long long i64;
typedef pair<i64,i64> P;

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

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



int n, m, a[101010];
void solve(){
	cin >> n >> m;
	int gcd;
	for(int i = 0; i < n; i++){
		cin >> a[i];
		if(i == 0) gcd = abs(m-a[0]);
		else gcd = __gcd(gcd, abs(a[i]-m));
	}
	cout << gcd << endl;
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}


Measured memory_bytes: 640
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

a = int(input())
b = int(input())
c = int(input())
print((a + b) * c // 2)

Measured memory_bytes: 3572
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define fbo find_by_order
#define ook order_of_key
#define f first
#define s second
#define pb push_back
#define reset(a,b) memset(a,b,sizeof a);
#define MOD 998244353
#define MID (l+r)/2
#define ALL(x) x.begin(),x.end()
#define debug(x) cout<<#x<<" = "<<(x)<<endl
#define mx 100003
#define pc(x) putchar_unlocked(x);
typedef tree<long long, null_type, less<long long>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int main(){
	int a,b;
	cin>>a>>b;
	if(a+b==15){
		cout<<'+';
	}
	else if(a*b==15){
		cout<<'*';
	}
	else cout<<'x';
}




Measured memory_bytes: 256
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int t = sc.nextInt();

		double v = t + 0.5;

		int p = 0;
		p = (int)v / a;
		int r = 0;
		r = (int)p * b;

		System.out.println(r);

	}

}


Measured memory_bytes: 23764
inp = gets.split.map!(&:to_i)
X = []
inp[0].times do |i|
  X[i] = gets.split.map!(&:to_i)
end
#p X  #for debug
#puts X[0][0]  #for debug

count = 0
inp[0].times do |i|
  (i+1).upto(inp[0]-1) do |j|
    dist = 0
    inp[1].times do |k|
      d = (X[i][k] - X[j][k]).abs
      dist += d**2  #これが2点の距離
    end
    (dist+1).times do |x|
      if x**2 == dist
        count += 1
        break
      end
    end
  end
end
puts count


Measured memory_bytes: 1916