akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define int long long int
using namespace std;
#define mod 1000000007
#define H 1001
int DP[H][H] = {0};
signed main() {
    int h,w;
    cin>>h>>w;
    char G[h][w];

    for(int i=0;i<h;i++)
    {
        for(int j=0;j<w;j++)
        {
            cin>>G[i][j];
        }
    }
    //DP[0][0] =1;


    for(int i=0;i<w;i++)
    {
        if(G[0][i]!='#')
        DP[0][i]=1;
        else
        break;
    }
    
    for(int i=1;i<w;i++)
    {
        if(G[i][0]!='#')
        DP[i][0] = 1;
        else
        break;
    }

    for(int i=1;i<h;i++)
    {
        for(int j=1;j<w;j++)
        {
            if(G[i-1][j]!='#')
            DP[i][j] += DP[i-1][j];

            if(G[i][j-1]!='#')
            DP[i][j] += DP[i][j-1];

            DP[i][j] = DP[i][j]%mod;

        }
    }

    cout<<DP[h-1][w-1]%mod;
    return 0;
}


Measured memory_bytes: 9088
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <functional>
#include <climits>
#include <cstring>
#include <cmath>
#include <numeric>
#include <iomanip>

using namespace std;

#define int long long

#define rep(i, n) for (int i=0;i<(int)n;++i)
#define rep1(i, n) for (int i=1;i<=(int)n;++i)
#define rrep(i, n) for (int i=(int)n-1;i>=0;--i)
#define rrep1(i, n) for (int i=n;i>=1;--i)
#define range(i, l, r) for (int i=l;i<(int)r;++i)
#define rrange(i, l, r) for (int i=(int)r-1;i>=(int)l;--i)
#define unless(a) if(!(a))
#define all(a) begin(a),end(a)
#define fst first
#define scd second
#define PB emplace_back
#define PPB pop_back

using ll=long long;
using vi=vector<int>;
using pii=pair<int, int>;
using ld=long double;

bool chmin(int&a,int b){return a>b?(a=b,true):false;}
bool chmax(int&a,int b){return a<b?(a=b,true):false;}
constexpr int TEN(int n){return n==0?1:10*TEN(n-1);}

const int mod = TEN(9)+7;
const int inf = TEN(18) * 3 + 10;

int L;
int to[22];

signed main()
{
	cin >> L;

	int N = 20;

	vector<pair<pii, int>> edges;

	{
		int p = 0;
		for (int i = N; i >= 3; --i) {
			edges.PB(pii(i - 1, i), 0);
		}
		for (int i = N; i >= 3; --i) {
			edges.PB(pii(i - 1, i), 1 << p);
			to[i] = 1 << p;
			p++;
		}
		to[2] = 1 << p;
	}

	int sum = 0, cur = 0;

	{
		int L_ = L;
		while (L_ >= to[2] * 2) {
			edges.PB(pii(1, 2), cur);
			sum += to[2];
			cur += to[2];
			L_ -= to[2];
		}
	}

	for (int i = 2; i <= N; ++i) {
		if (sum + to[i] <= L) {
			edges.PB(pii(1, i), cur);
			sum += to[i];
			cur += to[i];
		}
	}

	printf("%lld %lld\n", N, (int)edges.size());

	for (auto p : edges) {
		printf("%lld %lld %lld\n", p.fst.fst, p.fst.scd, p.scd);
	}

	//printf("sum = %lld\n", sum);
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    double t,x;
    cin>>t>>x;
    cout<<fixed;
    cout<<setprecision(10);
    cout<<t/x<<endl;
}

Measured memory_bytes: 256
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <functional>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define VVVI vector<vector<vector<ll>>>
#define VVVVI vector<vector<vector<vector<ll>>>>
#define REP(i,n) for(ll i=0,_n=(n);(i)<(ll)_n;++i)
#define REPR(i,n) for(ll i=(ll)(n)-1;0<=(i);--i)
#define RANGE(i,a,b) for(ll i=(ll)a,_b=(ll)(b);(i)<_b;++i)
#define RANGER(i,a,b) for(ll i=(ll)(b)-1,_a=(ll)(a);(_a)<=i;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
#define FI first
#define SE second
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template<typename T>void maxUpdate(T& a, T b) {a = max(a, b);}
template<typename T>void minUpdate(T& a, T b) {a = min(a, b);}
string YN(bool v) { return v ? "Yes":"No"; }
void uniq(VI& es) { sort(ALL(es)); es.erase(unique(ALL(es)), es.end()); }

#define INF (1LL<<60)

/*
1 2 3 4
all = 4
5 6 7 0
5^6^7=101^110^111=100=4
me = all^A[i]
*/
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N,M,W,H,K;
	string s;
	while(cin>>N) {
		VI A(N);
		REP(i, N) cin>>A[i];
		ll all=0;
		REP(i, N) all^=A[i];
//		DD(all);
		VI B(N);
		REP(i, N) {
			B[i]=all^A[i];
		}
		cout<<B<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 6052
#include <iostream>
#include <cstdint>
#include <algorithm>
#include <cmath>

using namespace std;

int64_t lowest(int64_t n, int64_t d)
{
    return (n + d - 1) / d;
}

int64_t highest(int64_t n, int64_t d)
{
    return (n + d) / d - 1;
}

int main()
{
    int64_t N, K;

    cin >> N >> K;

    int64_t result1 = 0;
    {
        const int64_t ub = highest(N, K);
        const int64_t lb = lowest(1, K);
        result1 = ub - lb + 1;
    }
    result1 = result1 * result1 * result1;

    int64_t result2 = 0;
    if (K % 2 == 0)
    {
        const int64_t ub = highest(2 * N - K, 2 * K); // N / K - 1 / 2
        const int64_t lb = lowest(2 - K, 2 * K);      // 1 / K - 1 / 2
        result2 = ub - lb + 1;
    }
    result2 = result2 * result2 * result2;
    const int64_t result = result1 + result2;

    cout << result << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define sz 100005
#define faster_io ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long ll;

int main()
{
    faster_io
    int n,x,y;
    int mx1,mx2;

    mx1 = mx2 = -1;

    cin>>n;
    int a[n+5];

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

    for(int i=0;i<n;i++){
        if(a[i]==mx1) cout<<mx2<<endl;
        else cout<<mx1<<endl;
    }

    return 0;
}


Measured memory_bytes: 2432
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define Would
#define you
#define please


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	string A, B;
	cin >> A >> B;

	int kotae = 0;
	if (A.size() > B.size()) {
		kotae = 1;
	}
	else if (A.size() < B.size()) {
		kotae = -1;
	}
	else {
		rep(i, A.size()) {
			if (A[i] > B[i]) {
				kotae = 1;
				break;
			}
			else if (A[i] < B[i]) {
				kotae = -1;
				break;
			}
		}
	}

	if (kotae > 0) co("GREATER");
	else if (kotae < 0) co("LESS");
	else co("EQUAL");

	Would you please return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String args[]){
        Scanner scan = new Scanner(System.in);
        int x = scan.nextInt();
        int d[] = new int[4];
        for(int i=0;i<4;i++){
            d[i] = x%10;
            x /= 10;
        }
        int a = d[3];//1のくらい
        int b = d[2];
        int c = d[1];
        int e = d[0];
        int k = 1;
        int j = 0;

        switch(k){
            case 1:j = a+b+c+e; if(j==7){System.out.println(a+  "+" + b + "+" + c + "+" + e + "=7" ); break;}
            case 2:j = a-b+c+e; if(j==7){System.out.println(a+  "-" + b + "+" + c + "+" + e + "=7" ); break;}
            case 3:j = a-b+c-e; if(j==7){System.out.println(a+  "-" + b + "+" + c + "-" + e + "=7" ); break;}
            case 4:j = a-b-c+e; if(j==7){System.out.println(a+  "-" + b + "-" + c + "+" + e + "=7" ); break;}
            case 5:j = a-b-c-e; if(j==7){System.out.println(a+  "-" + b + "-" + c + "-" + e + "=7" ); break;}
            case 6:j = a+b-c+e; if(j==7){System.out.println(a+  "+" + b + "-" + c + "+" + e + "=7" ); break;}
            case 7:j = a+b+c-e; if(j==7){System.out.println(a+  "+" + b + "+" + c + "-" + e + "=7" ); break;}
            case 8:j = a+b-c-e; if(j==7){System.out.println(a+  "+" + b + "-" + c + "-" + e + "=7" ); break;}
            default:System.out.println("間違い"); break;
        }
    }

}


Measured memory_bytes: 21844
#include <iostream>
using namespace std;
int main (void) {
    char c;

    cin >> c;

    if (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o') cout << "vowel" << endl;
    else cout << "consonant" << endl;
    
    return 0;
}

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

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author anand.oza
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CAttention solver = new CAttention();
        solver.solve(1, in, out);
        out.close();
    }

    static class CAttention {
        static final char W = 'W';
        static final char E = 'E';

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            char[] s = in.next().toCharArray();

            int wTotal = 0;
            for (char c : s) {
                if (c == W) {
                    wTotal++;
                }
            }

            int eTotal = n - wTotal;

            int answer = Integer.MAX_VALUE;
            int wToLeft = 0;
            int eToRight = eTotal;
            for (int i = 0; i < n; i++) {
                if (s[i] == E) eToRight--;
                int cost = wToLeft + eToRight;
                answer = Math.min(answer, cost);
                if (s[i] == W) wToLeft++;
            }

            out.println(answer);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

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

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

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

    }
}



Measured memory_bytes: 26580
#include <iostream>
#include <string>
#include <algorithm>
#include <ctype.h>
using namespace std;

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

    for(int i = 0;i < n; i++){
        if(i == k-1){
            s[i] += 0x20;
        }
    }

    cout << s;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define puts(i) cout << i << endl
#define INF INT_MAX
#define INFL LLONG_MAX
typedef long long ll;
using namespace std;
int main(){

  ll sum=0,h=0,n;

  cin >> n;

  std::vector<ll> a(n);
  rep(i,n){
    cin >> a.at(i);
  }

  for(int j=1;j<n;j++){
    if(a.at(j-1)+h>=a.at(j)){
      h=(a.at(j-1)+h)-a.at(j);
      sum+=h;
    }
    else{
      h=0;
    }


  }


    cout << sum << endl;
}

Measured memory_bytes: 4840
//
#include <vector>
#include <set>
#include <map>
#include <array>
#include <iostream>
#include <cstdio>
#include <cstdint>
#include <algorithm>
#include <numeric>
#include <bitset>
//
using ll = long long;
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);++i)
inline void yes(bool cond) { cond ? puts("Yes") : puts("No"); }
template<typename Type> inline void chmin(Type& a, Type b) { if (a > b) a = b; }
template<typename Type> inline void chmax(Type& a, Type b) { if (a < b) a = b; }
template<typename Arr, typename Type> inline void fill(Arr& arr, Type v) { std::fill(arr.begin(), arr.end(), v); }
template<typename Type> inline void sort(Type& arr) { std::sort(arr.begin(), arr.end()); }
template<typename Type> inline Type nth(vector<Type>& arr, size_t pos) { std::nth_element(arr.begin(), arr.begin() + pos, arr.end()); return arr[pos]; }
constexpr double BIGP = 1000000007L;
constexpr double INF_I = std::numeric_limits<double>::max();
constexpr double INF_F = std::numeric_limits<float>::infinity();
constexpr double PI = 3.14159265358979323846L;
//
int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    ll A;
    double b;
    cin >> A >> b;
    ll B = ll((b + 0.005) * 100.0);
    cout << A * B/100;
    return 0;
}

Measured memory_bytes: 3168
#include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);
#define endl "\n"
#define MAXN 100123
#define ll long long
#define INF INT_MAX
#define FORE(i,m,n) for(int i=m;i<n;i++)
#define FOR(i,n) FORE(i,0,n)
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<ii>
#define ps(v) push_back(v)
#define ms(v,x) memset(v,x,sizeof(v)) 
#define PI M_PI
using namespace std;

// cout << fixed << setprecision(4);

int n,cont;
string item;
set<string> s;
int main(){_
    cin >> n;
    while(n--){
        cin >> item;
        if(s.count(item)==0){
            cont++;
            s.insert(item);
        }
    }
    cout << cont << endl;
    return 0;
}

Measured memory_bytes: 19212
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>
#include <cstdio>
#include <list>

//< in.txt > out.txt
using namespace std;
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
const long long MOD = 1e9 + 7;
typedef long long LL;
typedef long double LD;
typedef pair<LL, LL> PLL;
typedef pair<LD, LL> PDL;
typedef pair<LD, LD> PDD;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
//typedef boost::multiprecision::cpp_int bigint;

template<class T>
void in(T& x) {
	cin >> x;
}

template<class T1,class T2>
void in(pair<T1, T2>& p) {
	in(p.first);
	in(p.second);
}

template<class T>
void in(vector<T>& v,LL st=-1,LL en=-1) {
	if (st == -1) {
		st = 0;
		en = v.size() - 1;
	}
	for (LL n = st; n <= en; n++) {
		in(v[n]);
	}
}

void modinvs(long long N, vector<long long>& inv, vector<long long>& sinv, long long mod = 1e9 + 7) {
	inv.resize(N + 1);
	sinv.resize(N + 1);
	inv[1] = 1;
	sinv[0] = 1;
	sinv[1] = 1;
	for (int n = 2; n <= N; n++) {
		inv[n] = mod - (inv[mod % n] * (mod / n)) % mod;
		sinv[n] = (sinv[n - 1] * inv[n]) % mod;
	}
}

long long Comb(long long n, long long k, vector<long long>& st, vector<long long>& sinv, long long mod = 1e9 + 7) {
	if (n < 0)return 0;
	if (k > n || k < 0)return 0;
	long long ans = st[n];
	ans = (ans * sinv[n - k]) % mod;
	ans = (ans * sinv[k]) % mod;
	return ans;
}

VLL st, inv, sinv;

LL S(LL C, LL R) {
	LL ans = 0;
	for (LL c = 1; c <= C+1; c++) {
		LL temp = (st[R + c] * sinv[c]) % MOD;
		ans += temp;
	}
	ans %= MOD;
	ans = (ans * sinv[R]) % MOD;
	return ans;
}

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	LL R1, C1, R2, C2;
	cin >> R1 >> C1 >> R2 >> C2;
	st.resize(R2 + C2 + 2, 1);
	for (LL n = 2; n <= R2 + C2 + 1; n++) {
		st[n] = (st[n - 1] * n) % MOD;
	}
	modinvs(R2 + C2 + 1, inv, sinv);
	LL ans = 0;
	ans = S(C2, R2);
	if (C1 > 0)ans -= S(C1 - 1, R2);
	if (R1 > 0)ans -= S(C2, R1 - 1);
	if (C1 > 0 && R1 > 0)ans += S(C1 - 1, R1 - 1);
	ans = (ans + 2 * MOD) % MOD;
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 47104
n = int(input())

# 6**7 # 279936
# 9**6 # 531441
c = [1] + [6**i for i in range(1,7)] + [9**i for i in range(1,6)]
c.sort()
#[1, 6, 9, 36, 81, 216, 729, 1296, 6561, 7776, 46656, 59049]
INF = 10 ** 10

dp = [INF] * (n + 1)
dp[0] = 0

for ci in c:
    for i in range(ci, n+1):
        dp[i] = min(dp[i], dp[i-ci] + 1)
print(dp[n])

Measured memory_bytes: 40048
N,M,Q=map(int,input().split())
from copy import copy
A=[]
def DFS(n,s):
    if len(s)==n:
        A.append(copy(s))
        return
    ss=s[-1]
    for i in range(ss,M+1):
        s.append(i)
        DFS(n,s)
        s.pop()

DFS(N,[1])

q=[]
for i in range(Q):
    a,b,c,d=map(int,input().split())
    q.append([a,b,c,d])

L=len(A)
ans=0
for i in range(L):

    point=0
    for j in range(Q):
        a,b,c,d=q[j]
        if A[i][b-1]-A[i][a-1]==c:
            point+=d
    ans=max(ans,point)
print(ans)




Measured memory_bytes: 16428
N=int(input())
H=input()
ListA=[]
ListA=H.split()
for i in range(0,len(ListA),1):
  a=ListA.pop(i)
  b=int(a)
  ListA.insert(i,b)

c=0
for i in range(0,len(ListA),1):
  ListB=ListA[0:i+1]
  if ListA[i]>=max(ListB):
    c+=1

print(c)


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#define rep(i, n)   for(int i = 0; i < (n); i++)
using namespace std;

int main(){
    string a,b,c;   cin >> a >> b >> c;
    if(a[a.size()-1]==b[0] && b[b.size()-1]==c[0]){
	cout << "YES" << endl;
    }else{
	cout << "NO" << endl; 
    }
}


Measured memory_bytes: 256
#!/usr/bin/env python
import math

def main():
    A, B, C, X, Y = map(int, input().split())
    ans = float("inf")
    for k in range(2 * max(X, Y) + 1):
        i = max(0, math.ceil(X - 0.5 * k))
        j = max(0, math.ceil(Y - 0.5 * k))
        total = A * i + B * j + C * k
        if ans > total:
            ans = total
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 40684
#include <bits/stdc++.h>
#define int long long

using namespace std;

int kMod;

vector<int> down, up;
vector<vector<int>> graph;

void DFSDown(int node, int par) {
    down[node] = 1;
    if (par != -1)
        graph[node].erase(find(graph[node].begin(), graph[node].end(), par));
    for (auto vec : graph[node]) {
        DFSDown(vec, node);
        down[node] = 1LL * down[node] * (1 + down[vec]) % kMod;
    }    
}

void DFSUp(int node, int par, int buff) {
    up[node] = 1LL * buff * down[node];

    vector<int> pref(graph[node].size()), suff(pref);
    for (int i = 0; i < (int)pref.size(); ++i) {
        pref[i] = (down[graph[node][i]] + 1) % kMod;
        if (i > 0) pref[i] = 1LL * pref[i] * pref[i - 1] % kMod;
    }
    for (int i = (int)pref.size() - 1; i >= 0; --i) {
        suff[i] = (down[graph[node][i]] + 1) % kMod;
        if (i < (int)pref.size() - 1) 
            suff[i] = 1LL * suff[i] * suff[i + 1] % kMod;
    }

    for (int i = 0; i < (int)graph[node].size(); ++i) {
        int left = (i == 0) ? 1 : pref[i - 1];
        int right = (i == (int)graph[node].size() - 1) ? 1 : suff[i + 1];    
        int coef = (1LL * left * right % kMod * buff % kMod + 1) % kMod;
        DFSUp(graph[node][i], node, coef);
    }
}

int32_t main() {

    int n; cin >> n >> kMod;
    graph.resize(n);
    down.resize(n, 0);
    up.resize(n, 0);

    for (int i = 1; i < n; ++i) {
        int a, b; cin >> a >> b; --a; --b;
        graph[a].push_back(b);
        graph[b].push_back(a);    
    }

    DFSDown(0, -1);
    DFSUp(0, -1, 1);

    for (int i = 0; i < n; ++i) {
        cout << up[i] % kMod << '\n';
    } 

    return 0;
}


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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)
#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];
vector<int> v[101010];
void solve(){
	cin >> n >> m;
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	for(int i = 0; i < m; i++){
		int x,y;
		cin >> x >> y;
		x--; y--;
		v[x].push_back(y);
		v[y].push_back(x);
	}
	
	int cnt = 0;
	for(int i = 0; i < n; i++){
		bool ok = 1;
		for(auto j : v[i]){
			if(a[i] > a[j]) continue;
			ok = 0;
		}
		if(ok) cnt++;
	}
	cout << cnt << 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: 9192
n,m = map(int,input().split())
h_inputs = [int(i) for i in input().split()]
ab_inputs = [[int(j) for j in input().split()]for i in range(m)]

map_li = [1]*n
for line in ab_inputs:
    a,b = line[0],line[1]
    if h_inputs[a-1]>h_inputs[b-1]:
        map_li[b-1]=0
    if h_inputs[a-1]<h_inputs[b-1]:
        map_li[a-1]=0
    if h_inputs[a-1]==h_inputs[b-1]:
        map_li[a-1]=0
        map_li[b-1]=0
print(sum(map_li))

Measured memory_bytes: 30472
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int K = sc.nextInt();
    String[] D = new String[K];
    int answer = -1;
    for (int i = 0; i < K; i++) {
      D[i] = sc.next();
    }
    for (int i = 1; i <= Integer.MAX_VALUE; i++) {
      String i_string = Integer.toString(i);
      boolean skip = false;
      for (int j = 0; j < K; j++) {
        if (i_string.contains(D[j])) {
          skip = true;
        }
      }
      if (skip) {
        continue;
      }
      if (i >= N) {
        answer = i;
        break;
      }
    }
    System.out.println(answer);
  }
}

Measured memory_bytes: 24252
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <algorithm>
int main() {
  int N,i,K,j;
  long a=0;
  cin>>N>>K;
  if(K>N){
  K=N;
  }
  int H[N]={0};
  long Hm[N]={0};
  for(i=0;i<N;i++){
  cin>>H[i];
    if(i>0){
   a=a+abs(H[i]-H[i-1]);
    }
    Hm[i]=a;
  }
  for(i=1;i<K;i++){
  Hm[i]=abs(H[i]-H[0]);
   
  }
 
  for(i=K;i<N;i++){
   
  for(j=0;j<K;j++){
  a=Hm[i-j-1]+abs(H[i]-H[i-j-1]);
   
    if(a<Hm[i]){
    Hm[i]=a;
    }
     
  }
  }
  cout<<Hm[N-1]<<endl;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define ll long long
//#define endl "\n"
#define pb push_back
#define ms(v,x) memset(v,x,sizeof(v))
#define ff first
#define ss second
#define td(v) v.begin(),v.end()
#define rep(i,a,n) for (int i=(a);i<(n);i++)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define re(v) {for(auto &_re : v) cin >> _re;}
#define rre(v){for(auto &_re : v) for(auto &_rre : _re) cin >> _rre;}
#define pr(v) {for(auto _pr : v) cout << _pr << " "; cout << endl;}
#define prr(v) {for(auto _prr : v) cout << _prr.ff << " " << _prr.ss << endl;}
#define eb emplace_back
using namespace std;
const int M = 1e9 + 7;
const ll mod = 998244353;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
//#define int long long
int n;
string s;
int dp[3030][3030];
void solve(){
	cin >> n >> s;
	auto fix = [](int &val){
		if(val >= M) val-= M;
	};
	auto sum = [](int i,int l,int r){
		if(l > r) return 0;
		return (dp[i][r] - dp[i][l-1] + M) % M;
	};
	for(int i=1;i<=n;i++){
		dp[1][i] = 1;
	}
	for(int i=2;i<=n;i++){
		for(int j=1;j<=i;j++){
			if(s[i-2] == '<'){
				dp[i][j] = sum(i-1, 1, j-1);
				/*for(int k=1;k<j;k++){
					dp[i][j] += dp[i-1][k];
					fix(dp[i][j]);
				}*/
			}
			else{
				dp[i][j] = sum(i-1, j, i);
				/*for(int k=i;k>=j;k--){
					dp[i][j] += dp[i-1][k];
					fix(dp[i][j]);
				}*/
			}
		}
		for(int j=1;j<=n;j++){
			dp[i][j] += dp[i][j-1];
			fix(dp[i][j]);
		}
	}
	/*cout << dp[2][1] << " " << dp[2][2] << endl;
	cout << dp[3][1] << " " << dp[3][3] << endl;*/
	/*int ans = 0;
	for(int i=1;i<=n;i++){
		ans += dp[n][i];
		fix(ans);
	}*/
	//cout << ans << endl;
	cout << dp[n][n] << endl;
}
int32_t main(){
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  int t = 1;
  //cin >> t;
  while(t--){
    solve();
  }  
}

Measured memory_bytes: 39128
import queue

inpstr = input()
stack = queue.LifoQueue()
stack_areas = queue.LifoQueue()

cnt = 0  # 位置
area = 0  # 総面積
for s in inpstr:
	if s == '\\':
		stack.put(cnt)
	elif s == '/':
		if not stack.empty():
			i = stack.get()
			area = area + cnt - i
			# 個々の面積の再計算
			temp = [i, cnt - i]  # 今回の面積と開始位置
			if stack_areas.empty():
				stack_areas.put(temp)
			else:
				for j in range(0, stack_areas.qsize()):
					temp2 = stack_areas.get()
					if i > temp2[0]:
						stack_areas.put(temp2)
						break
					else:
						temp[1] = temp[1] + temp2[1]
				stack_areas.put(temp)
	elif s == '_':
		pass  # 何もしない、結果cntだけ増える
	cnt = cnt + 1

print(area)
# stackから出力用のリストに変換
areas = []
while not stack_areas.empty():
	areas.append(stack_areas.get()[1])
#print(areas)
areas.append(len(areas))
areas.reverse()
print(' '.join([str(n) for n in areas]))



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

using ll = long long;
using vi = vector<int>;
using vi2 = vector<vector<int>>;
#define MP(a,b) make_pair((a),(b))
#define MT(...) make_tuple(__VA_ARGS__)

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)

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

#define DCOUT(x,n) cout << fixed << setprecision(n) << (x) << endl;

#define sz(x) (int)(x).size()
#define HOGE cout << "hoge" << endl;
using P = pair<ll,ll>;

template<typename T>inline istream& operator>>(istream&i,vector<T>&v)
{REP(j,sz(v))i>>v[j];return i;}

const int INF = 1e9;

int main(){
    int k;
    cin >> k;
    ll a = 7;
    map <ll,int> amari;
    amari[a%k]++;
    ll ans = 1;
    while(amari[0]==0){
        a *= 10;
        a += 7;
        a %= k;
        if(amari[a]!=0){
            break;
        }else{
            amari[a]++;
            ans++;
        }
    }
    if(amari[0]==0) cout << -1 << endl;
    else cout << ans << endl;
}

Measured memory_bytes: 66124
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())

N = int(input())

for h in range(1,3501):
	for n in range(1,3501):
		si = h*n*N
		bo = 4*h*n-(h+n)*N
		if bo > 0 and si%bo == 0:
			print(h,n,si//bo)
			sys.exit()


Measured memory_bytes: 49000
n, a, b = map(int, input().split())
x = list(map(int, input().split()))

#end = x[n - 1]
#lim = 10 ** 18
dp = [0] * n

pre = x[0]
for i in range(1, n):
    distance = x[i] - x[i - 1]
    dp[i] = min(distance * a, b)

ans = sum(dp)
print(ans)

Measured memory_bytes: 19960
N, K = map(int, input().split())
points = {c: p for c, p in zip("spr", map(int, input().split()))}
strings = [[] for _ in range(K)]
counts = [1] * K
ans = 0
for i, c in enumerate(list(input()) + [""] * K):
    idx = i % K
    if strings[idx]:
        last = strings[idx][-1]
        if c == last:
            counts[idx] += 1
        else:
            ans += ((counts[idx] + 1) >> 1) * points[last]
            counts[idx] = 1
    strings[idx].append(c)
print(ans)

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

struct Node {
    int index = -1;
    int depth = -1;
    int parent = -1;
    vector<int> child;
};

int get_depth(Node *node, int index) {
    if (node[index].parent < 0) {
        return 0;
    } else {
        return get_depth(node, node[index].parent) + 1;
    }
}

int main() {
    int n;
    cin >> n;
    Node a[n];
    
    for (int i = 0; i < n; ++i) {
        int x, y;
        cin >> x >> y;
        a[x].index = x;
        for (int j = 0; j < y; ++j) {
            int b;
            cin >> b;
            a[x].child.push_back(b);
            a[b].parent = x;
            if (a[x].depth > -1) { a[b].depth = a[x].depth + 1; }
        }
    }
    
    for (auto& i : a) {
        string child = "";
        for (auto& j : i.child) {
            string c = child == "" ? "" : ", ";
            child += c + to_string(j);
        }
        cout << "node " << i.index << ": ";
        cout << "parent = " << i.parent << ", ";
        cout << "depth = " << get_depth(a, i.index) << ", ";
        cout << (i.parent < 0 ? "root" : (i.child.size() < 1 ? "leaf" : "internal node")) << ", ";
        cout << "[" << child << "]" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 8292
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
typedef long long ll;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define FOR(i,m,n) for (ll i = m; i < n; ++i)

struct BIT {
  vector<ll> data;
  int N;

  BIT(int n) {
    N = n;
    data = vector<ll>(N+1);
  }

  void add(ll i, ll x) {
    for (ll k = i; k <= N; k += k&-k) data[k] += x;
  }

  void update(int i, ll x) {
    add(i, x-get(i));
  }

  ll sum(int i) {
    ll res = 0;
    for (int k = i; k > 0; k -= k&-k) res += data[k];
    return res;
  }

  ll get(int i) {
    return sum(i) - sum(i-1);
  }
};

const int MAX = 2019;
ll N;
string s;
int a;
ll dp[MAX][MAX]; //dp[i][j]:左から黒をi個、白をj個並べるためにかかった回数
int b[MAX], w[MAX], x[MAX*2];

int main() {

  cin >> N;
  REP (i, 2*N) {
    cin >> s >> a;
    if (s == "B") {
      x[i] = a;
      b[a] = i;
    } else {
      x[i] = a+N;
      w[a] = i;
    }
  }
  dp[0][0] = 0;

  BIT bitBlack(N*2);
  BIT bitWhite(N*2);
  FOR (i, 1, N+1) {
    bitBlack.add(b[i]+1, 1);
    dp[i][0] = dp[i-1][0] + b[i] - bitBlack.sum(b[i]+1) + 1;

    bitWhite.add(w[i]+1, 1);
    dp[0][i] = dp[0][i-1] + w[i] - bitWhite.sum(w[i]+1) + 1;
  }

  bitBlack = BIT(N*2);
  FOR (i, 1, N+1) {
    bitBlack.add(b[i]+1, 1);
    bitWhite = BIT(N*2);
    FOR (j, 1, N+1) {
      bitWhite.add(w[j]+1, 1);
      int new_b = dp[i-1][j] + b[i] - bitBlack.sum(b[i]+1) - bitWhite.sum(b[i]+1) + 1;
      int new_w = dp[i][j-1] + w[j] - bitBlack.sum(w[j]+1) - bitWhite.sum(w[j]+1) + 1;
      dp[i][j] = min(new_b, new_w);
    }
  }
  
  cout << dp[N][N] << endl;
}

Measured memory_bytes: 32000
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    def dp(a,b,s):
        if mem[(a,b,s)] is not None:
            return mem[(a,b,s)]
        x = a&1
        y = b&1
        z = s&1
        if x^y != z:
            return float("inf")
        res = 2*dp(a>>1,b>>1,s>>1)
        if a > 1:
            nr = 2*dp((a-1)>>1,(b+1)>>1,s>>1)+1
            if nr < res:
                res = nr
        mem[(a,b,s)] = res
        return res
    n = I()
    a = LI()
    s = 0
    for i in a[2:]:
        s ^= i
    b = a[1]
    a = a[0]
    mem = defaultdict(lambda : None)
    mem[(0,0,0)] = 0
    ans = dp(a,b,s)
    if ans == float("inf"):
        ans = -1
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 66736
from collections import deque

slope = input()
down_slope   = deque()
total_slopes = deque()

for i in range(len(slope)):
    if slope[i] == '\\':
        down_slope.append(i)
    elif slope[i] == '/':
        area = 0
        if len(down_slope) > 0:
            while len(total_slopes) > 0 and total_slopes[-1][0] > down_slope[-1]:
                area += total_slopes[-1][1]
                total_slopes.pop()
            area += i-down_slope[-1]
            total_slopes.append([down_slope[-1],area])
            down_slope.pop()

if len(total_slopes) > 0:
    total_slopes = [i[1] for i in total_slopes]
    print(sum(total_slopes))
    print(len(total_slopes),end=' ')
    print(' '.join(map(str,total_slopes)))
else:
    print(0)
    print(0)


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

using namespace std;

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

#define debug(a) cout << #a << ": " << a << endl
#define debuga1(a, l, r) fto(i, l, r) cout << a[i] << " "; cout << endl
#define fdto(i, r, l) for(int i = (r); i >= (l); --i)
#define fto(i, l, r) for(int i = (l); i <= (r); ++i)
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define sz(a) (int)a.size()

const double PI = acos(-1.0);
const int MAXN = 200005;

double fRand(double fMin, double fMax)
{
    double f = (double)rand() / RAND_MAX;
    return fMin + f * (fMax - fMin);
}

template <class T>
T min(T a, T b, T c) {
    return min(a, min(b, c));
}

template <class T>
T max(T a, T b, T c) {
    return max(a, max(b, c));
}

int h, w, n;
vector<int> pos[MAXN];

int main () {
    scanf("%d%d%d", &h, &w, &n);
    fto(i, 1, n) {
        int x, y;
        scanf("%d%d", &x, &y);
        pos[x].pb(y);
    }

    int maxY = 1;
    fto(x, 2, h) {
        bool blocked = false;
        for(int y: pos[x]) {
            if (y == maxY+1)
                blocked = true;
            else if (y <= maxY) {
                printf("%d", x-1);
                return 0;
            }
        }

        if (!blocked)
            ++maxY;
    }

    printf("%d", h);

    return 0;
}


Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
 
#define pb push_back
 
const int N = 3e3+5;
 
string s , t;
char a[N] , b[N];
int dp[N][N];
vector<char> vec;
 
int LCS(int n , int m){
  if(dp[n][m] != -2) return dp[n][m];
  if(!n || !m) return dp[n][m] = 0;
  if(a[n] == b[m]) dp[n][m] = max(dp[n][m],1+LCS(n-1,m-1));
  return dp[n][m] = max(dp[n][m],max(LCS(n-1,m),LCS(n,m-1)));
}
 
void rec(int n , int m){
  if(!n || !m) return;
  if(a[n] == b[m] and dp[n][m] == dp[n-1][m-1]+1) vec.pb(a[n]), rec(n-1,m-1);
  else if(dp[n][m] == dp[n-1][m]) rec(n-1,m);
  else if(dp[n][m] == dp[n][m-1]) rec(n,m-1);
}
 
int main(){
 
  ios_base::sync_with_stdio(),cin.tie(0);
 
  cin >> s >> t;
  for(int i = 0 ; i < N ; i++)
    for(int j = 0 ; j < N ; j++) dp[i][j] = -2;
  for(int i = 0 ; i < s.size() ; i++) a[i+1] = s[i];
  for(int i = 0 ; i < t.size() ; i++) b[i+1] = t[i];
  
  LCS(s.size(),t.size()) , rec(s.size(),t.size());
  
  for(int i = vec.size()-1 ; i >= 0 ; i--) cout << vec[i];
  cout << "\n";
 
}


Measured memory_bytes: 39312
#４ｘ１３の空のリストの作成
cards = [[False for i in range(13)] for j in range(4)]

n = int(input())#足りない数の入力
for i in range(n):
    ch,rank = input().split()
    rank = int(rank)
    if ch == 'S':
        cards[0][rank-1] = True
    elif ch == 'H':
        cards[1][rank-1] = True
    elif ch == 'C':
        cards[2][rank-1] = True
    elif ch == 'D':
        cards[3][rank-1] = True

for i in range(4):
    for j in range(13):
        if cards[i][j]  == False:
            if i == 0:
                print('S',j+1)
            elif i == 1:
                print('H',j+1)
            elif i == 2:
                print('C',j+1)
            elif i == 3:
                print('D',j+1)



Measured memory_bytes: 5616
import java.util.List;
import java.util.PriorityQueue;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class Main {
    int V,E,r;
    List<ArrayList<Edge>> G;
    long[] ans;
 
    private class Edge{
        int n,c;
        public Edge(int n,int c){
            this.n = n;
            this.c = c;
        }
    }
 
    private class Com implements Comparable<Com>{
        int n;
        long c;
        public Com(int n,long c){
            this.n = n;
            this.c = c;
        }
 
        public int compareTo(Com d){
            if(this.c - d.c < 0){
                return -1;
            }else if(this.c - d.c > 0){
                return 1;
            }else{
                return 0;
            }
        }
    }
 
    public void dijkstra(int s){
        boolean[] used = new boolean[V];
 
        PriorityQueue<Com> pq = new PriorityQueue<Com>();
        pq.add(new Com(r,0));
        while(pq.size() > 0){
        	Com d = pq.poll();
 
            used[d.n] = true;
            ans[d.n] = Math.min(ans[d.n],d.c);
 
            for(Edge i : G.get(d.n)){
                if(used[i.n])continue;
                pq.add(new Com(i.n,d.c + i.c));
            }
        }
    }
    public static void main(String[] args) throws IOException {
    	Main m = new Main();
    	int r = m.init();
        m.dijkstra(r);
        m.display();
    }
    public void display(){
    	 for(int i = 0;i < V;i++){
             if(ans[i] == Long.MAX_VALUE)
             	System.out.println("INF");
             else 
             	System.out.println(ans[i]);
         }
    }
    public int init() throws IOException{
    	BufferedReader BR = new BufferedReader(new InputStreamReader(System.in));
		String str = BR.readLine();
		String [] arr = str.split("\\s+");
		V = Integer.parseInt(arr[0]);
		E = Integer.parseInt(arr[1]);
		r = Integer.parseInt(arr[2]);
		G = new ArrayList<ArrayList<Edge>>();
		ans = new long[V];
		for(int i = 0;i < V;i++){
            G.add(new ArrayList<Edge>());
        }
 
        for(int i = 0;i < V;i++){
            ans[i] = Long.MAX_VALUE;
        }
        for(int i = 0;i < E;i++){
            String tempstr = BR.readLine();
			String [] temparr = tempstr.split("\\s+");
            G.get(Integer.parseInt(temparr[0])).add(new Edge(Integer.parseInt(temparr[1]),Integer.parseInt(temparr[2])));
        }
        return r;
    }
    
}

Measured memory_bytes: 195392
N = int(input())
dict = {}
dict['AC'] = 0
dict['WA'] = 0
dict['TLE'] = 0
dict['RE'] = 0

for i in range(N):
  s = input()
  dict[s] += 1
  
print('AC x',dict['AC'])
print('WA x',dict['WA'])
print('TLE x',dict['TLE'])
print('RE x',dict['RE'])

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

using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define fore(i,a) for(auto &i:a)

typedef pair <int, int> P;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
const int  INF = 2147483647;
const ll INFL = 9223372036854775807;
const ll mod = 1000000007;





int main() {

	VI v(4);
	REP(i, 4)cin >> v[i];
	sort(ALL(v));

	if (v[0] == 1 && v[1] == 4 && v[2] == 7 && v[3] == 9)cout << "YES" << endl;
	else cout << "NO" << endl;
	
	return 0;
}

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

int main(){
  int n;
  cin >> n;
  vector<int> ans(60001);
  for(int x=1;x<=100;x++){
    for(int y=1;y<=100;y++){
      for(int z=1;z<=100;z++){
        int i=x*x+y*y+z*z+x*y+y*z+z*x;
        ans.at(i)++;
      }
    }
  }
  for(int j=1;j<=n;j++){
    cout << ans.at(j) << endl;
  }
}

Measured memory_bytes: 3540
#!/usr/bin/env python3
#ABC108 B

x1,y1,x2,y2 = list(map(int,input().split()))
x4 = x1 - (y2-y1)
y4 = y1 + (x2-x1)
x3 = x4 + x2 - x1
y3 = y4 + y2 - y1
print(x3,y3,x4,y4)


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

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


int main() {
  ll N,x,v;
  ll C,ans=0,tmp=0;
  cin >> N >> C;
  vector<vector<ll>> sushi(N);//,a2(N,0),ar2(N,0);
  vector<ll> a(N,0),ar(N,0);
  rep(i,N) {
    cin >> x >> v;
    sushi[i]={x,v};
  }
  rep(i,N) {
    if (i!=0) {
      tmp += sushi[i][1] - (sushi[i][0] - sushi[i-1][0]);
      a[i] = max(tmp, a[i-1]);
    }
    else {
      tmp += sushi[i][1] - sushi[i][0];
      a[i] = max((ll) 0, tmp);
    }
  }
  auto sushi0 = sushi;

  reverse(sushi.begin(),sushi.end());
  tmp = 0;
  rep(i,N) {
    if (i!=0) {
      tmp += sushi[i][1] - (sushi[i-1][0]-sushi[i][0]);
      ar[i] = max(tmp, ar[i-1]);
    }
    else {
      tmp += sushi[i][1] - (C-sushi[i][0]);
      ar[i] = max((ll)0, tmp);
    }
  }
  
  ans = max(a[N-1],ar[N-1]);
  if (N>=2) chmax(ans,max(a[0]-sushi0[0][0]+ar[N-2], ar[0]-(C-sushi[0][0]+a[N-2])));
  
  rep2(i,1,N) {
    // cout << ans << endl;
    auto t1 = ar[N-1-i] - (C - sushi0[i][0]) + a[i-1];
    chmax(ans, t1);
  }
  rep2(i,0,N-1) {
    // cout << ans << endl;
    auto t2 = a[i] - sushi0[i][0] + ar[N-i-2];
    chmax(ans,t2);
  }
  cout << ans << endl;
} 

Measured memory_bytes: 12800
#include <algorithm>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

using Graph = std::vector<std::vector<int>>;
using WGraph = std::vector<std::vector<std::pair<int, long long>>>;
using ll = long long;
using namespace std;

int dx[] = {-1, 0, 0, 1};
int dy[] = {0, -1, 1, 0};

void dfs(vector<string> &s, vector<vector<bool>> &visited, int i, int j, ll &tmpb, ll &tmpw, int h, int w) {
    if (s.at(i).at(j) == '.') tmpw++;
    else tmpb++;
    for (int k=0; k<4; k++) {
        int nx = i + dx[k], ny = j + dy[k];
        if (nx < 0 || nx >= h || ny < 0 || ny >= w) continue;
        if (!visited.at(nx).at(ny) && s.at(i).at(j) != s.at(nx).at(ny)) {
            visited.at(nx).at(ny) = true;
            dfs(s, visited, nx, ny, tmpb, tmpw, h, w);
        }
    }
}

int main() {
    int h = 0, w = 0;
    cin >> h >> w;
    vector<string> s(h);
    for (int i=0; i<h; i++) {
        cin >> s.at(i);
    }
    vector<vector<bool>> visited(h, vector<bool>(w, false));
    ll cnt = 0;
    for (int i=0; i<h; i++) {
        for (int j=0; j<w; j++) {
            if (!visited.at(i).at(j)) {
                ll tmpb = 0, tmpw = 0;
                visited.at(i).at(j) = true;
                dfs(s, visited, i, j, tmpb, tmpw, h, w);
                cnt += tmpb * tmpw;
            }
        }
    }
    cout << cnt << endl;
    return 0;
}
 

Measured memory_bytes: 30464
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

    	Scanner scanner=new Scanner(System.in);

    	int n =scanner.nextInt();
    	
    	

    	int[] data=new int[n];

    	
    	for (int i = 0; i < data.length; i++) {
			data[i]=scanner.nextInt();
			
		}
    	int result=0;

    	while(true){

        	boolean hasOdd=false;

        	for(int i=0;i<n;i++) {
        		if(data[i]%2 != 0) {
        			hasOdd=true;
        			break;
        		}
        	}

        	if(hasOdd) {break;};

        	for(int i=0;i<n;i++) {
        		data[i]/=2;
        	}

        	result++;

    	}

    	System.out.println(result);

    	scanner.close();


    }

}

Measured memory_bytes: 21844
#include<cstdio>
int main()
{
    int A,B,C,D;
    while(~scanf("%d %d %d %d",&A,&B,&C,&D)){
        if(A+B == C+D)
        {
            printf("Balanced\n");
        }
        else if(A+B > C+D)
        {
            printf("Left\n");
        }
        else if(A+B < C+D)
        {
             printf("Right\n");
        }
    }
    return 0;
}


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

using namespace std;

#define endl '\n'


int main(){

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

  string s,t;
  cin >> s >> t;
  int n = s.size();
  int ans = 0;

  for(int i=0;i<n;i++)
    if(s[i] != t[i])
      ans++;
  

  cout << ans << endl;
 
  return 0;
}

Measured memory_bytes: 3820
import java.util.Arrays;
import java.util.Scanner;

class Main{
	public static void main(String args[]){
		try(Scanner sc=new Scanner(System.in)){
			int v=sc.nextInt();//頂点数
			int e=sc.nextInt();//辺数
			int r=sc.nextInt();//始点
			int inf=10000*100000+100;
			int[] c=new int[v+1];//始点からの距離
			int[] S=new int[e+1];
			int[] T=new int[e+1];
			int[] D=new int[e+1];
			Arrays.fill(c, inf);
			Arrays.fill(D, inf);
			for(int i=0; i<e; i++) {
				S[i]=sc.nextInt();
				T[i]=sc.nextInt();
				D[i]=sc.nextInt();
			}
			c[r]=0;
			for(int k=0; k<v; k++) {
				boolean update=false;
				for(int i=0; i<e; i++) {
					int s=S[i], t=T[i], d=D[i];
					if(c[s]<inf && c[s]+d<c[t]) {
						c[t]=c[s]+d;
						update=true;
					}
				}
				if(! update) break;
			}
			for(int i=0; i<v; i++) {
				if(c[i]==inf) {
					System.out.println("INF");
				}
				else {
					System.out.println(c[i]);
				}
			}
		}
	}
}


Measured memory_bytes: 301356
#include <iostream>
using namespace std;
int main() {
  int h, w, occ[50][50] = {};
  cin >> h >> w;
  char s[h][w];
  for (int i = 0; i < h; i++) {
    string str;
    cin >> str;
    for (int j = 0; j < w; j++) {
      s[i][j] = str[j];
    }
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '#') {
        for (int k = i - 1; k <= i + 1; k++) {
          for (int l = j - 1; l <= j + 1; l++) {
            if (k >= 0 && k <= h - 1 && l >= 0 && l <= w - 1) {
              occ[k][l]++;
            }
          }
        }
      }
    }
  }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (s[i][j] == '#') {
        cout << '#';
      } else {
        cout << occ[i][j];
      }
    }
    cout << endl;
  }
  return 0;
}


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

int main() {
  string a, b;
  cin >> a >> b;
  sort(a.begin(), a.end());
  sort(b.begin(), b.end());  
  reverse(b.begin(), b.end());
  if(a < b) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3632