akhauriyash/Code-Regression huggingface dataset:
W, H, N = list(map(int, input().split()))
floor = [[0 for row in range(W)] for col in range(H)]
for i in range(N):
  x, y, a = list(map(int, input().split()))
  if a == 1:
    for row in floor:
      for i in range(len(row[:x])):
        row[i] = 1
  elif a == 2:
    for row in floor:
      for i in range(len(row[x:])+x)[x:]:
        row[i] = 1
  elif a == 3:
    for (h, row) in enumerate(floor):
      if H-y < h+1:
        for i in range(len(row)):
          row[i] = 1
  elif a == 4:
    for (h, row) in enumerate(floor):
      if h < H-y:
        for i in range(len(row)):
          row[i] = 1
res = 0
for row in floor:
  res += row.count(0)
print(res)

Measured memory_bytes: 42608
// {{{
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
// }}}

using ll = long long;

int N, M;
vector<vector<int>> graph;
vector<char> visited;

deque<int> deq;

int main() {
    scanf("%d%d", &N, &M);
    graph.resize(N+1);
    visited.resize(N+1); fill(begin(visited), end(visited), 0);
    for (int j = 0; j < M; ++j) {
        int a, b; scanf("%d%d", &a, &b);
        graph[a].push_back(b);
        graph[b].push_back(a);
    }

    int v = 1;
    while (true) {
        deq.push_back(v);
        visited[v] = true;

        int w = -1;
        for (int nxt : graph[v]) {
            if (!visited[nxt]) {
                w = nxt;
                break;
            }
        }
        if (w == -1) { break; }
        v = w;
    }

    int x = -1;
    for (int nxt : graph[1]) {
        if (!visited[nxt]) {
            x = nxt;
            break;
        }
    }
    if (x != -1) {
        while (true) {
            deq.push_front(x);
            visited[x] = true;

            int w = -1;
            for (int nxt : graph[x]) {
                if (!visited[nxt]) {
                    w = nxt;
                    break;
                }
            }
            if (w == -1) { break; }
            x = w;
        }
    }

    for (int v : graph[deq.front()]) {
        assert(visited[v]);
    }
    for (int v : graph[deq.back()]) {
        assert(visited[v]);
    }

    cout << deq.size() << endl;
    for (bool first = true; !deq.empty(); deq.pop_front(), first = false) {
        if (!first) cout << " ";
        cout << deq.front();
    }
    cout << endl;
    return 0;
}


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

int main(){
    int n,k,x[100000],minc=1000000000;
    cin>>n>>k;
    for(int i=0;i<n;i++){
        cin>>x[i];
    }
    for(int i=0;i<n-k+1;i++){
        minc=min(minc,min(abs(x[i]),abs(x[i+k-1]))+x[i+k-1]-x[i]);
    }
    cout<<minc<<endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;

int main() {
  int n;
  cin>>n;
  int d=n%10;
  n/=10;
  int c=n%10;
  n/=10;
  int b=n%10;
  int a=n/10;
  char op1,op2,op3;
  for(int i=0;i<2;i++){
    for(int j=0;j<2;j++){
      for(int k=0;k<2;k++){
        int res=0;
        if(i==0) res+=a+b;
        else res+=a-b;
        if(j==0) res+=c;
        else res-=c;
        if(k==0) res+=d;
        else res-=d;
        if(res==7){
          if(i==0) op1='+';
          else op1='-';
          if(j==0) op2='+';
          else op2='-';
          if(k==0) op3='+';
          else op3='-';
        }
      }
    }
  }
  cout<<a<<op1<<b<<op2<<c<<op3<<d<<"=7"<<endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;


class Program
{


    static void Main(string[] args)
    {

        char[] cs = new char[] { ' ', ',' };
        //int val = int.Parse(Console.ReadLine());
        //int[] vals = parseAry(Console.ReadLine().Split(cs));
        //string str = Console.ReadLine();
        //string[] strs = Console.ReadLine().Split(cs);

        //string res="";
        //int res = 0; ;
        //int t = int.Parse(Console.ReadLine());
        //string str = Console.ReadLine();
        ///int[] vals = parseAry(Console.ReadLine().Split(cs));
        //int n = int.Parse(Console.ReadLine());
		string res="No";


		int n = int.Parse(Console.ReadLine());
		string str = Console.ReadLine();


		int r = 0;
		for ( int i = 0; i < str.Length; i++ ) {
			if ( str[i] == 'R' ) { r++; }
		}
		if ( r > ( n - r ) ) { res = "Yes"; }

			Console.WriteLine(res);

        return;
    }

    //　String[]  ----->  int[]
    static int[] parseAry(string[] str)
    {
        int[] nums = new int[str.Length];
        for (int i = 0; i < str.Length; i++) { nums[i] = int.Parse(str[i]); }
        return nums;
    }
    //　String[]  ----->  long[]
    static long[] parseAryL(string[] str)
    {
        long[] nums = new long[str.Length];
        for (int i = 0; i < str.Length; i++) { nums[i] = long.Parse(str[i]); }
        return nums;
    }

    //文字列を1文字ずつString[]に入れる
    static string[] strAry(String str)
    {
        string[] re = new string[str.Length];
        for (int i = 0; i < str.Length; i++) { re[i] = str[i].ToString(); }
        return re;
    }

}

Measured memory_bytes: 13140
// written by newbiechd
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>

// DELETE the debugging information!
#define debug(x) std::cerr << #x << " = " << (x) << std::endl

const int mod = 1e9 + 7;
int power(int x, int y) {
  int ret = 1;
  while (y) {
    if (y & 1)
      ret = 1ll * ret * x % mod;
    x = 1ll * x * x % mod, y >>= 1;
  }
  return ret;
}

int c[503], fac[503], iFac[503], bin[103][503], dp[503][503][503];
void add(int &x, const int &y) {
  x += y - mod;
  x += (x >> 31) & mod;
}
void dec(int &x, const int &y) {
  x -= y;
  x += (x >> 31) & mod;
}

int main() {
  int n, X;
  scanf("%d%d", &n, &X);
  for (int i = 1; i <= n; ++i) {
    int l;
    scanf("%d", &l);
    ++c[l];
  }
  fac[0] = 1;
  for (int i = 1; i <= X + 1; ++i)
    fac[i] = 1ll * fac[i - 1] * i % mod;
  iFac[X + 1] = power(fac[X + 1], mod - 2);
  for (int i = X + 1; i; --i)
    iFac[i - 1] = 1ll * iFac[i] * i % mod;
  for (int i = 0; i <= n; ++i) {
    bin[i][0] = 1;
    for (int j = 1; j <= X; ++j)
      bin[i][j] = 1ll * bin[i][j - 1] * i % mod;
  }
  
  dp[X + 1][0][0] = 1;
  for (int i = X; i; --i)
    for (int k = 0; k <= X; ++k)
      for (int j = 0; i * j <= k; ++j) {
        for (int l = 0; l <= j; ++l)
          add(dp[i][j][k], 1ll * dp[i + 1][j - l][k - i * l] * iFac[l] % mod);
        dp[i][j][k] = 1ll * dp[i][j][k] * power(k - (i - 1) * j, c[i]) % mod;
      }
  int ans = 0;
  for (int i = 0; i <= X; ++i)
    for (int j = 0; j <= X - i + 1; ++j) {
      int temp = 1ll * fac[X - j + 1] * iFac[X - j + 1 - i] % mod *
        dp[1][i][j] % mod;
      (X - j) & 1 ? dec(ans, temp) : add(ans, temp);
    }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 495104
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll=long long;
using P=pair<int,int>;
int main() {
    int n;cin>>n;
    vector<int> a(n);
    rep(i,n) cin>>a[i];
    vector<int> copy(n);
    rep(i,n) copy[i]=a[i];
    sort(copy.begin(),copy.end());
    reverse(copy.begin(),copy.end());
    int ma1=copy[0],ma2=copy[1];
    for(int i=0;i<n;i++){
        if(ma1==a[i]){
            cout<<ma2<<endl;
        }
        else cout<<ma1<<endl;
    }
}

Measured memory_bytes: 3200
//Author: Fuadul Hasan(fuadul202@gmail.com)
#include<bits/stdc++.h>
using namespace std;

#define ll long long
const int N   = 2e5 + 5;

int main(){
	
	ll r,d,x;	
	cin>>r>>d>>x;
	for(int i=0;i<10;i++){
		x = (r*x - d);
		cout<<x<<endl;
	}

	

	return 0;
}

Measured memory_bytes: 3556
import fractions
def lcm(x, y):
    return (x*y) // fractions.gcd(x,y)
A, B, C, D = map(int,input().split())
L = lcm(C,D)
#A-1以下のCorDで割り切れる個数
a = (A-1)//C + (A-1)//D - (A-1)//lcm(C,D)
#B以下のCorDで割り切れる個数
b = B//C + B//D - B//lcm(C,D)
ans = B-(A-1) - (b-a)
print(ans)

Measured memory_bytes: 5048
n = int(input())
room = [[[0 for i in range(10)]for j in range(3)]for k in range(4)]


for i in range(n) :
    b, f, r, v = map(int,input().split())
    room[b-1][f-1][r-1] += v


for i in range(4) :
    for j in range(3):
        print(end = " ")
        print(*room[i][j])
    if i != 3 :
        print("#"*20)


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

ll ebob(ll a, ll b){
	if(a == 0) return b;
	return ebob(b%a, a);
}
int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int n; cin>>n;
	bool check = 0;
	int u = 1;
	int res = 0;
	for(int i = 0; i < n; i++){
		int sayi; cin>>sayi;
		if(sayi != u){
			res++;
		}else{
			u++;
		}
		if(sayi == 1) check = 1;
	}
	if(!check){
		cout<<-1;
		return 0;
	}else{
		cout<<res;
	}
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
//コピペここから

// extended Euclidean Algorithm
// ax + by = gcd(a, b)
// return : gcd(a, b)
template<typename Integer = int_fast64_t>
constexpr Integer extgcd(Integer a, Integer b, Integer &x, Integer &y){
    Integer u = 0, v = 1, q = 0, tmp = 0;
    x = v = 1;
    y = u = 0;

    while(b){
        q = a / b;
        x ^= u ^= x ^= u;
        u = u - q * x;
        y ^= v ^= y ^= v;
        v = v - q * y;
        a ^= b ^= a ^= b;
        b = b - q * a;
    }

    return a;
}

// mod inverse(設計が変わるかもしれません)
// return : val^(-1) mod MOD
template<uint_fast64_t MOD, typename Integer = int_fast64_t>
constexpr Integer modinv(Integer val){
    int_fast64_t ret = 0, tmp = 0;

    extgcd<int_fast64_t>(static_cast<int_fast64_t>(val), static_cast<int_fast64_t>(MOD), ret, tmp);

    return static_cast<Integer>(ret > 0 ? ret % MOD : (MOD - (-ret % MOD)));
}

// const expression factorial mod MOD
template<std::size_t N, std::uint_fast64_t MOD>
struct Fact {
    std::uint_fast64_t val[N + 1];

    constexpr Fact() : val() {
        val[0] = 1;
        for (std::size_t i = 1; i <= N; ++i) val[i] = val[i - 1] * i % MOD;
    }
};

// const expression factorial inverse mod MOD
template<std::size_t N, std::uint_fast64_t MOD, std::uint_fast64_t F>
struct IFact {
    std::uint_fast64_t val[N + 1];

    constexpr IFact() : val() {
        val[N] = F;
        for (std::size_t i = N; i; --i) val[i - 1] = val[i] * i % MOD;
    }
};

constexpr std::uint_fast64_t MOD = 1000000007, maxN = 300000;

constexpr auto fact = Fact<maxN, MOD>();
constexpr auto ifact = IFact<maxN, MOD, modinv<MOD>(fact.val[maxN])>();

// const expression binomial mod MOD
constexpr std::uint_fast64_t binommod(std::uint_fast64_t n, std::uint_fast64_t r){
    if(r < 0 || r > n)return 0;
    return fact.val[n] * (ifact.val[r] * ifact.val[n - r] % MOD) % MOD;
}

//コピペここまで(ある部分を使うためにはそれより上を全てコピーしてください)

template<size_t max_N, size_t prime_size>
struct Prime{
    bool sieve[max_N];
    int_fast64_t prime[prime_size];
    size_t counter = 0;
    constexpr Prime() : sieve(), prime() {
        for(int_fast64_t i = 0; i < max_N; ++i)
            sieve[i] = true;
        sieve[0] = sieve[1] = false;
        for(int_fast64_t i = 2; i < max_N; ++i){
            if(sieve[i]){
                prime[counter] = i;
                ++counter;
                if(counter > prime_size)break;
            }
            for(int_fast64_t j = i * i; j < max_N; j += i)
                sieve[j] = false;
        }
    }
};

constexpr auto p = Prime<100000, 9592>();

long long int N, M, f[10000], ans;

int main(){
    scanf("%lld%lld", &N, &M);
    for(int i = 0; i < 9592; ++i){
        while(!(M % p.prime[i])){
            ++f[i];
            M /= p.prime[i];
        }
    }
    ans = (M > 1) ? N : 1;
    for(int i = 0; i < 9592; ++i){
        ans *= binommod(N - 1 + f[i], N - 1);
        ans %= 1000000007;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SZ(x) ((int)(x).size())
typedef long long ll;
typedef long double ld;
using namespace std;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout.setf(ios::fixed); cout.precision(20);
    int n, m; cin >> n >> m;
    priority_queue<ll> X;
    for (int i = 0; i < n; i++) {
        ll x; cin >> x;
        X.push(x);
    }
    while (!X.empty() && m > 0) {
        ll x = X.top();
        X.pop();
        m--;
        x /= 2;
        if (x > 0) {
            X.push(x);
        }
    }
    ll res = 0;
    while (!X.empty()) {
        res += X.top(); X.pop();
    }
    cout << res << "\n";
}


Measured memory_bytes: 1400
#include <stdio.h>
#include <vector>
#include <algorithm>

struct union_find {
	std::vector<int> data;

public:
	union_find(int n) : data(n, -1) {}
	bool unite(int x, int y) {
		x = find(x); y = find(y);
		if(x == y) return false;
		if(data[x] > data[y]) std::swap(x, y);
		data[x] += data[y];
		data[y] = x;
		return true;
	}
	int find(int k) {
		if(data[k] < 0) return k;
		return data[k] = find(data[k]);
	}
};

int main() {
	using P = std::pair<int, std::pair<int, int>>;

	int n, m;
	while(scanf("%d%d", &n, &m), n) {
		int ans = 0;
		std::vector<P> vec;
		for(int i = 0; i < m; i++) {
			int a, b, c; scanf("%d%d%d", &a, &b, &c);

			vec.push_back({c, {a, b}});
		}
		sort(begin(vec), end(vec));
		
		union_find uf(n);
		for(auto v: vec) {
			if(uf.unite(v.second.first, v.second.second)) ans += v.first;
		}
		printf("%d\n", ans);
	}
	return 0;
}



Measured memory_bytes: 2732
import sys
input = sys.stdin.readline
import numpy as np
N,W=map(int,input().split())
dp=np.ones(10**5+1, dtype='int64')
dp[0]=0
dp[1:]=dp[1:]*(10**9+1)
for i in range(N):
  wi,vi=map(int,input().split())
  dp[vi:]=np.minimum(dp[vi:],dp[:-vi]+wi)
print(np.max(np.where(dp <= W)))

Measured memory_bytes: 14808
#include <bits/stdc++.h>
#define ll long long
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define bitrep(X,N) for(ll X = 0; X < (1 << (N)); X++)
#define PI (acos(-1.0))
#define sorta(V) sort(V.begin(), V.end())
#define pback push_back
#define mpair make_pair
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end() 


using namespace std;


int main(){

    int n;
    cin >> n;
    int ans;

    rep(i,9){
        ans = 111 * (i + 1);

        if(n <= ans) break;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
A,B,C = map(int,input().split())
ans = 0
if(A>=B and A>=C):
    ans = max(A*10+B+C,ans)
if(B>=A and B>=C):
    ans = max(B*10+A+C,ans)
else:
    ans = max(C*10+A+B,ans)
print(str(ans))

Measured memory_bytes: 9068
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int main()
{
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	if(a+b==c||a+c==b||b+c==a)
	printf("Yes");
	else printf("No"); 
	return 0;
}

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

#define REP(i, n) for(int (i) = 0; (i) < (n); (i)++)

int main(void){
	int n, k;
	cin >> n >> k;

	vector<int> p(n);
	REP(i, n){
		cin >> p[i];
	}

	if(n == k){
		cout << 1 << endl;
		return 0;
	}

	int ans = n-k+1;
	int cnt = 0, sum = 0;
	REP(i, n-1){
		if(p[i] < p[i+1]) cnt++;
		else cnt = 0;
		if(cnt == k-1) sum++;
	}
	if(sum > 1) ans -= sum-1;

	set<int> st;
	REP(i, n){
		st.insert(p[i]);
		if(i >= k){
			if(p[i] == *st.rbegin() && p[i-k] == *st.begin()) ans--;
			st.erase(p[i-k]);
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 10368
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main() {
    int a[3];
    REP(i,3){
        cin>>a[i];
    }
    sort(a,a+3);
    cout<<a[0]+a[1]<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
int main(){
    int n;
    ll y;
    cin >> n >> y;
    rep(i,0,n+1){
        rep(j,0,n-i+1){
            if(y-i*10000-j*5000==1000*(n-i-j)){
                cout<<i<<" "<<j<<" "<<n-i-j<<endl;
                return 0;
            }
        }
    }
    cout<<"-1 -1 -1"<<endl;

  return 0;
}

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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define ALPHABET    (26)
#define INF         INT_MAX
#define MOD         (1000000007LL)

using LL  = long long;
// }}}

int main() {
    std::ios::sync_with_stdio(false);
    int n;cin >> n;
    int ans = 0;
    vector<int> a(n);
    for(int i=0;i<n;i++) cin >> a[i];
    while(true){
        bool flag = true;
        for(int i=0;i<n;i++){
            if(a[i]%2 == 1) flag = false;
        }
        if(flag){
            for(int i=0;i<n;i++){
                a[i] /= 2;
            }
            ans++;
        }else{
            break;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
s = int(input())
mod = 10 ** 9 + 7

dp = [0] * (s + 1)
dp[0] = 1

x = 0
for i in range(3, s + 1):
    x += dp[i - 3]
    dp[i] = x % mod

ans = dp[s] % mod
print(ans)


Measured memory_bytes: 9128
#include <stdio.h>
#include <stdlib.h>
#define ll long long
#define max(p,q)((p)>(q)?(p):(q))
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

ll a[100010];
ll b[100010];
int main(){
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		int t;
		scanf("%d",&t);
		if(i%2)b[t]+=2e5;
		else a[t]+=2e5;
	}
	for(int i=0;i<100005;i++){
		a[i]+=i;
		b[i]+=i;
	}
	sortdown(a,100003);
	sortdown(b,100003);
	if(a[0]%200000!=b[0]%200000){
		printf("%d",n-a[0]/200000-b[0]/200000);
	}else{
		int a1=a[1]/200000,b1=b[1]/200000;
		printf("%d",n-a[0]/200000-max(a1,b1));
	}
}


Measured memory_bytes: 2556
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;

int n,x,a,b,t[105];

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&x);
		t[x]++,a=max(a,x);
	}
	b=a+1>>1;
	for(int i=b+1;i<=a;i++)
    	if(t[i]<2){
    	    printf("Impossible");
    	    return 0;
    	}
	if(a&1){
		if(t[b]<2){
			printf("Impossible");
			return 0;
		}t[b]-=2;
	}else{
		if(t[b]<1){
			printf("Impossible");
			return 0;
		}t[b]-=1;
	}
	for(int i=1;i<=b;i++)
		if(t[i]){
			printf("Impossible");
			return 0;
		}
	printf("Possible");
}

Measured memory_bytes: 256
M, D = list(map(int, input().split()))

cnt = 0
for m in range(1, M+1):
  for d in range(22, D+1):
    d1 = int(d/10)
    d2 = d%10
    if d1 < 2 or d2 < 2:
      continue
    if m == d1*d2:
      cnt += 1

print(cnt)


Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int main()
{
int a,b,c,d,e;
int MAX_p,MAX_q;

cin>>a>>b>>c>>d>>e;

if(a<=b&&a<=c)
{
MAX_p=a;
}
else if(b<=a&&b<=c)
{
MAX_p=b;
}
else
{
MAX_p=c;
}

if(d<=e)
{
MAX_q=d;
}
else
{
MAX_q=e;
}

cout<<MAX_p+MAX_q-50<<endl;
}


Measured memory_bytes: 3108
H,W = map(int,input().split())
if H % 3 == 0 or W % 3 == 0:
	print(0)
else:
	A = []
	for j in range(2):
		if j == 1:
			H,W = W,H
		n = H // 3
		for i in range(3):
			S1 = (n + i) * W
			if W % 2 == 0:
				S2 = (H - n - i) * (W // 2)
				A.append(abs(S2 - S1))
			else:
				S2 = (H - n - i) * (W // 2)
				S3 = (H - n - i) * (W // 2 + 1)
				s = max(S1,S2,S3) - min(S1,S2,S3)
				A.append(s)
		A.append(W)
	print(min(A))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long int LL;
typedef LL ll;
typedef long double ld;
typedef string str;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef stringstream strs;
 
#define X first
#define Y second
#define PB push_back
#define For(i,a,b) for (int i=a;i<b;i++)
#define Ford(i,a,b) for (int i=a;i>=b;i--)
#define smax(a,b) a=max(a,b)
#define smin(a,b) a=min(a,b)
#define SZ(a) ((ll)a.size())
#define ER(a) cout << #a << ' ' << a << endl
#define LB(a,n,x) (lower_bound(a,(a)+(n),x)-(a))
#define RET(x) { cout << x; exit(0); } 
const ll M=2e5+5,LG=19,SM=600+5,inf=1e18+1;
ll mod=1e9+7;

ll n,res;
ll a[M];

int main()
{
	ios::sync_with_stdio(0);
    cin >> n;
    For(i,0,n) cin >> a[i];
    sort(a,a+n);
    ll su=0;
    For(i,0,n-1)
    {
        su+=a[i];
        if (2*su<a[i+1]) res=i+1;
        //ER(res);
    }
    RET(n-res);
}    

Measured memory_bytes: 1024
L, R = map(int, input().split())
diff = R-L
for n in range(1):
    if diff > 2019:
        ret = 0
        break
        
        [inner for outer in init for inner in outer]
    ret = min([ (i*j)%2019 for i in range(L, R) for j in range(i+1,R+1) ])
print(ret)

Measured memory_bytes: 75392
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
	    Scanner sc = new Scanner(System.in);
	    int n,x,count=0;
	    int data[] = new int[100];
	    while(true){
	        n = sc.nextInt();
	        x = sc.nextInt();
	        if(n==0&&x==0)break;
	        for(int i=0;i<n;i++)data[i]=i+1;

	        for(int i=0;i<n-2;i++){
	            for(int j = i+1;j<n-1;j++){
	                for(int k=j+1;k<n;k++){
	                    if(x==data[i]+data[j]+data[k])count++;
	                }
	            }
	        }
	        System.out.println(count);
	        count=0;
	    }
	        sc.close();
	}
}



Measured memory_bytes: 26708
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr=input.trim().split("\n");
var [m,n]=arr.shift().split(" ").map(Number);
var a=arr.shift().split(" ");
if(m==2){
   var cnt=[0,0];
   for(var i=0;i<n;i++){
      if(a[i]-1==i%2)cnt[0]++;
      if(a[i]-1==(i+1)%2)cnt[1]++;
   }
   console.log(Math.min(...cnt));
}else{
   var cnt=0;
   for(var i=1;i<n;i++){
      if(a[i-1] == a[i]){
         cnt++;
         i++;
      }
   }
   console.log(cnt);
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  cout << a.back() - a[0] << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define up(i,a,b) for(int (i) = (a);(i)<=(b);++(i))
#define down(i,b,a) for(int (i) = (b);i>=(a);--i)
#define debug(x) cerr << (x) << '\n';
#define bits(x,i) ((x >> i) & 1)
using namespace std;
const int N = 105;
long long a,b,n;
int main(){
    cin >> a >> b >> n;
    int ans = 0;
    if (n < b) {
        ans = (a*n)/b;
        ans -= a * (long long)(n/b);
    }
    else {
        ans = (a*(b-1))/b;
    }
    cout << ans;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    while(cin>>s)
    {
        int len=s.length()-2;
        bool flag=false;
        if(s.length()<4) {cout<<'1'<<endl;continue;}
        for(int i=len/2;i>0;i--)
        {
            int j=0;
            for(;j<i;j++)
                if(s[j]==s[j+i])continue;
                else break;
            if(j==i){
                cout<<i*2<<endl;
                flag=true;
                break;
            }
        }
        if(!flag) cout<<'1'<<endl;
    }
    return 0;
}


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


using namespace std;


int main(){
  string str;

  cin >> str;

  int i;
  int m,b;

  while(str!="-"){
    cin >> m;
    
    for(i=0;i<m;i++){
      cin >> b;
      
      str = str.substr(b) + str.substr(0,b);      

    }
    cout << str << endl;
    cin >> str;
  }

  return 0;

}



Measured memory_bytes: 3164
use proconio::input;

#[allow(non_snake_case)]
fn main() {
    input! {
        N: usize
    }

    let m = 1000_000_000 + 7;
    let mut a: i64 = 1;
    let mut b: i64 = 1;
    let mut c: i64 = 1;

    for _ in 0..N {
        a = (a * 10) % m;
        b = (b * 9) % m;
        c = (c * 8) % m;
    }

    let ans = ((a + c + m) - 2 * b + m) % m;
    println!("{}", ans);
}


Measured memory_bytes: 2172
class UnionFind:
    def __init__(self, n):
        self.par = list(range(n))
        self.rank = [0] * n
        self.size = [1] * n

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.rank[x] == self.rank[y]:
            self.rank[x] += 1
        elif self.rank[x] < self.rank[y]:
            x, y = y, x

        self.par[y] = x
        self.size[x] += self.size[y]

    def is_same(self, x, y):
        return self.find(x) == self.find(y)

    def get_size(self, x):
        return self.size[self.find(x)]


N, M = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(M)]

tree = UnionFind(N + 1)
res = [N * (N - 1) // 2]
for a, b in reversed(X[1:]):
    if not tree.is_same(a, b):
        num0 = tree.get_size(a)
        num1 = tree.get_size(b)
        res.append(res[-1] - num0 * num1)
    else:
        res.append(res[-1])
    tree.unite(a, b)

print(*res[::-1], sep="\n")


Measured memory_bytes: 107356
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD=1e9+7;
ll powmod(ll a, ll k){
    ll ap=a, ans=1;
    while(k){
        if(k&1){
            ans*=ap;
            ans%=MOD;
        }
        ap=ap*ap;
        ap%=MOD;
        k>>=1;
    }
    return ans;
}
ll inv(ll a){
	return powmod(a, MOD-2);
}
ll f[15001], invf[15001];
void fac(int n){
    f[0]=1;
    for(ll i=1; i<=n; i++) f[i]=f[i-1]*i%MOD;
    invf[n]=inv(f[n]);
    for(ll i=n-1; i>=0; i--) invf[i]=invf[i+1]*(i+1)%MOD;
}
ll comb(int x, int y){
    if(!(0<=y && y<=x)) return 0;
    return f[x]*invf[y]%MOD*invf[x-y]%MOD;
}
int main()
{
    int n, a, b, c; cin>>n>>a>>b>>c;
    if(b&1){
        cout<<0<<endl;
        return 0;
    }
    fac(2*n);
    ll ans=0;
    for(int x=0; x<=a; x++){
        for(int y=0; 3*y+x<=c; y++){
            if(b==0){
                if(3*y+x==c) (ans+=f[a+y]*invf[x]%MOD*invf[y]%MOD*invf[a-x])%=MOD;
                else continue;
            }else{
                (ans+=f[b/2+a+y]*invf[x]%MOD*invf[y]%MOD*invf[a-x]%MOD*invf[b/2]%MOD*comb(c-3*y-x+b/2-1, b/2-1))%=MOD;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 384
// ~/Remember,remember the 6th of March
#include <functional>
#include <iomanip>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include<complex>
#include <unordered_map>
#include<unordered_set>
#include <numeric>
#include <string>
#include<iostream>
#include <fstream>
#include <assert.h>
#include <ctype.h>
#include <limits.h>
#include <math.h>
#include<cmath>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <sstream>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double PI = acos(-1.0);
const double  EPS = 1e-9;
const ll MOD = 1e9 + 7;
const int N = 1000007;
void fast()
{
	std::ios_base::sync_with_stdio(0);
}
ll n;
vector<ll>arr;
vector<ll>cs1, cs2;
int main()
{
/*#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	//	freopen("output.txt","w",stdout);
#endif*/

	scanf("%lld", &n);
	arr.resize(n);
	cs1.resize(n);
	cs2.resize(n);
	for (ll &i : arr)scanf("%lld", &i);
	
	for (int i = 0; i < n; i++)
	{
		if (!i)
			cs1[i] = arr[i];
		else
			cs1[i] = cs1[i - 1] + arr[i];
	}
	for (int i = n-1; i > -1; i--)
	{
		if (i==n-1)
			cs2[i] = arr[i];
		else
			cs2[i] = cs2[i + 1] + arr[i];
	}
	ll ans = 2e18;
	for (int i = 0; i < n-1; i++)
		ans = min(ans, abs(cs1[i] - cs2[i + 1]));
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 4992
import Control.Applicative ((<$>), (<*>))
import Control.Monad
import Data.List

main :: IO ()
main = do
  solve <$> getl words >>= print

solve :: [String] -> Int
solve [a, op, b]
  | op == "+" = (read a) + (read b)
  | otherwise = (read a) - (read b)

getl :: (String -> a) -> IO a
getl f = f <$> getLine


Measured memory_bytes: 636
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

int main()
{
    double a, b, s;
    cin >> a >> b >> s;
    s /= a;

    double ans;
    if(s < a * b / 2.0){
        double x = (2.0 * s) / b;
        ans = atan2(b, x);
    }
    else{
        double x = (2.0 * s) / a - b;
        ans = atan2(b - x, a);
    }
    ans *= 180.0 / M_PI;
    printf("%.10f\n", ans);

    return 0;
}


Measured memory_bytes: 256
s=input()
f=int(s[:2])
b=int(s[2:])
if f>=13 or f==0:
	if 0<b and b<13:
		print("YYMM")
	else:
		print("NA")
elif 0<f and f<13:
	if 0<b and b<13:
		print("AMBIGUOUS")
	else:
		print("MMYY")
else:
	print("NA")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<ll, ll>;
using vi = vector<ll>;
using vvi = vector<vi>;
using vb = vector<bool>;
using vs = vector<string>;
using vp = vector<pii>;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(x) (ll)((x).size())
#define all(x) (x).begin(), (x).end()
#define each(a, x) for (auto&& a : (x))
#define _overload4(_1, _2, _3, _4, name, ...) name
#define rep1(n) rep2(_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, n) rep4(i, a, n, 1)
#define rep4(i, a, n, s) for (ll i = (a); i < (n); i += (s))
#define rep(...) _overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
const int INF = 1e9;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
const double PI = acos(-1.0);
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
template<typename T> inline void chmax(T& a, const T& b) {if (a < b) a = b;}
template<typename T> inline void chmin(T& a, const T& b) {if (a > b) a = b;}
template<typename T> inline void print(const T& x) {cout << x << "\n";}
struct Init {Init() {cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10);}} init;

int main() {
    ll n; cin >> n;
    vi a(n);
    rep(i,n) cin >> a[i];
    ll sum = 0;
    rep(i,n) sum ^= a[i];
    rep(i,n) {
        ll tmp = sum^a[i];
        cout << tmp << " ";
    }
}

Measured memory_bytes: 4720
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }



int main()
{
	string str;
	map<char, int> p;

	p.insert(map<char, int>::value_type('I', 1));
	p.insert(map<char, int>::value_type('V', 5));
	p.insert(map<char, int>::value_type('X', 10));
	p.insert(map<char, int>::value_type('L', 50));
	p.insert(map<char, int>::value_type('C', 100));
	p.insert(map<char, int>::value_type('D', 500));
	p.insert(map<char, int>::value_type('M', 1000));


	while(cin >> str)
	{
		int len = str.size();
		vint num(len);

		rep(i, len)
			num[i] = p[str[i]];

		int res = num[len-1];
		rep(i, len-1)
		{
			if(num[i+1] <= num[i])
			{
				res += num[i];
			}
			else
			{
				res -= num[i];
				if(i + 1 != len - 1) res += num[i+1];
				i++;
			}
		}

		cout << res << endl;
	}
}

Measured memory_bytes: 0
import numpy as np
import sys
input = sys.stdin.readline

N,M,Q = map(int,input().split())
lis = np.zeros((N,N))
for i in range(M):
    L,R = map(int,input().split())
    lis[N-L,R-1] += 1
#二次元累積和
np.cumsum(lis,axis=0,out=lis)
np.cumsum(lis,axis=1,out=lis)
for _ in range(Q):
    p,q = map(int,input().split())
    print(int(lis[N-p,q-1]))


Measured memory_bytes: 15200
#include<stdio.h>
#define     sz      510
int city[sz][sz];


int main(){
    int n,m,q;
    int a,b,sum=0;
    scanf("%d%d%d",&n,&m,&q);

    for(int i=0;i<m;i++){
        scanf("%d%d",&a,&b);
        city[a][b] = city[a][b]+1;
    }

    for(int i=0;i<sz;i++){
        for(int j=1;j<sz;j++){
            city[i][j] = city[i][j]+city[i][j-1];
        }
    }


    for(int i=0;i<q;i++){
        scanf("%d%d",&a,&b);
        for(int j=a;j<=b;j++){
            sum = sum+(city[j][b]-city[j][a-1]);
        }
        printf("%d\n",sum);
        sum = 0;
    }
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
using namespace std;
int main()
{
  int W, H, N;
  cin >> W >> H >> N;
  int x[N], y[N], a[N];
  for (int i = 0; i < N; i++)
    cin >> x[i] >> y[i] >> a[i];
  bool rect[H][W];
  for (int i = 0; i < H; i++)
  {
    for (int j = 0; j < W; j++)
      rect[i][j] = true;
  }
  for (int i = 0; i < N; i++)
  {
    int miny = 0;
    int maxy = H;
    int minx = 0;
    int maxx = W;
    if (a[i] == 1)
      maxx = x[i];
    else if (a[i] == 2)
      minx = x[i];
    else if (a[i] == 3)
      maxy = y[i];
    else
      miny = y[i];
    for (int j = miny; j < maxy; j++)
    {
      for (int k = minx; k < maxx; k++)
        rect[j][k] = false;
    }
  }
  int ans = 0;
  for (int i = 0; i < H; i++)
  {
    for (int j = 0; j < W; j++)
    {
      if (rect[i][j])
        ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cstdio>
#include <map>
#include <set>
#include <cmath>
#include <vector>
#include <ctime>
#include <queue>
#include <sstream>
#include <utility>
#include <bitset>

using namespace std;

#define MP make_pair 
#define PB push_back 
#define INF (1000000007) 
#define eps 1e-8
#define MOD (1000000007)

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

int n;
vector<int> v[100005],p,ans;
int c[100005],dep[100005];

int dfs(int x,int pre)
{
	if(v[x].size()==1 && pre!=-1) 
	{
		c[x]=1;
		return 1;
	}
	int ret=1;
	for(int i=0;i<v[x].size();i++) if(v[x][i]!=pre) ret+=dfs(v[x][i],x);
	c[x]=ret;
	return ret;
}

void dfs2(int x,int d,int pre)
{
	dep[x]=d;
	for(int i=0;i<v[x].size();i++) if(v[x][i]!=pre) dfs2(v[x][i],d+1,x);
}

void dfs3(int x,int pre)
{
	p.PB(x);
//	for(int i=0;i<p.size();i++) cout<<p[i]<<" ";
//	cout<<endl;
	if(x==n) 
	{
//		for(int i=0;i<p.size();i++) cout<<p[i]<<" ";
//		cout<<endl;
		ans=p;
		return;
	}
	for(int i=0;i<v[x].size();i++) if(v[x][i]!=pre) dfs3(v[x][i],x);
	p.pop_back();
}

int main()
{
	cin>>n;
	for(int i=1;i<n;i++)
	{
		int f,t;
		cin>>f>>t;
		v[f].PB(t);
		v[t].PB(f);
	}
	c[1]=dfs(1,-1);
	dfs2(1,1,-1);
	dfs3(1,-1);
//	for(int i=1;i<=n;i++) cout<<c[i]<<" ";
	int tmp=(ans.size()+1)/2;
	int snu=c[ans[tmp]];
	int fen=n-snu;
//	cout<<snu<<" "<<fen<<endl;
	if(fen>snu)
	{
		cout<<"Fennec";
	}
	else cout<<"Snuke";
	return 0;
}

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

int main() {
  int n,a;
  cin >> n;
  vector<vector<int>> vec(n, vector<int>(2));
  vector<int> ans(n);
  a = 0;
  for(int i=0;i<n;i++){
    cin >> vec.at(i).at(0) >> vec.at(i).at(1);
    ans.at(i) = vec.at(i).at(1) - vec.at(i).at(0) +1;
  }
  for(int i=0;i<n;i++){
    a += ans.at(i);
  }
  
  cout << a << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define MOD 1000000009
const long long INF = 1LL<<60;

int main() {
    int n;
    cin>>n;
    vector<int> a(n),b(n),c(n);
    rep(i,n) cin>>a[i];
    rep(i,n) cin>>b[i];
    rep(i,n) cin>>c[i];

    sort(all(a));
    sort(all(c));

    ll ans=0;
    rep(i,n){
        ll num1=lower_bound(all(a),b[i])-a.begin();
        ll num2=c.end()-upper_bound(all(c),b[i]);
        //cout<<num1<<" "<<num2<<endl;
        ans+=(num1*num2);
    }

    cout<<ans<<endl;
}

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

int main(){
    int N,A;
    int mai;

    cin >> N;
    cin >> A;

    mai = N % 500;
    if (mai == 0){
        cout << "Yes" << endl;
    }else if (mai <= A){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
module CharMap = Map.Make (Char)

module RegExp : sig
  type t
  val empty_set : t
  val empty_str : t
  val char : Char.t -> t
  val app : t -> t -> t
  val union : t -> t -> t
  val star : t -> t

  val matches : t -> Char.t list -> bool
end = struct
  type t =
    { body : regexp;
      is_nullable : bool;
      derivatives : t CharMap.t ref }
  and regexp =
    | EmptySet
    | EmptyStr
    | Char of Char.t
    | App of t * t
    | Union of t * t
    | Star of t

  let empty_set =
    { body = EmptySet;
      is_nullable = false;
      derivatives = ref CharMap.empty }

  let empty_str =
    { body = EmptyStr;
      is_nullable = true;
      derivatives = ref CharMap.empty }

  let char c =
    { body = Char c;
      is_nullable = false;
      derivatives = ref CharMap.empty }

  let app re1 re2 =
    match re1, re2 with
    | { body = EmptySet }, _ -> empty_set
    | _, { body = EmptySet } -> empty_set
    | { body = EmptyStr }, _ -> re2
    | _, { body = EmptyStr } -> re1
    | _, _ ->
        { body = App (re1, re2);
          is_nullable = re1.is_nullable && re2.is_nullable;
          derivatives = ref CharMap.empty }

  let union re1 re2 =
    match re1, re2 with
    | { body = EmptySet }, _ -> re2
    | _, { body = EmptySet } -> re1
    | _, _ ->
        { body = Union (re1, re2);
          is_nullable = re1.is_nullable || re2.is_nullable;
          derivatives = ref CharMap.empty }

  let star = function
    | { body = EmptySet } -> empty_str
    | { body = EmptyStr } -> empty_str
    | { body = Star re } -> re
    | re -> { body = Star re; is_nullable = true; derivatives = ref CharMap.empty }

  let rec derive c re =
    try CharMap.find c !(re.derivatives)
    with Not_found ->
      let d =
        match re with
        | { body = EmptySet } -> empty_set
        | { body = EmptyStr } -> empty_set
        | { body = Char c' } ->
            if Char.compare c c' = 0 then empty_str else empty_set
        | { body = App (re1, re2) } ->
            union (if re1.is_nullable then derive c re2 else empty_set) (app (derive c re1) re2)
        | { body = Union (re1, re2) } ->
            union (derive c re1) (derive c re2)
        | { body = Star re0 } ->
            app (derive c re0) re in
      re.derivatives := CharMap.add c d !(re.derivatives); d

  let matches re s =
    (List.fold_left (fun re c -> derive c re) re s).is_nullable
end

let () =
  let s = read_line () in
  print_endline @@
  if
    let open RegExp in
    matches
      (star @@
        union
          (app (char 'd') @@ app (char 'r') @@ app (char 'e') @@ app (char 'a') @@ app (char 'm') @@
            union empty_str @@ app (char 'e') @@ char 'r')
          (app (char 'e') @@ app (char 'r') @@ app (char 'a') @@ app (char 's') @@ app (char 'e') @@
            (union empty_str @@ char 'r'))) @@
      Array.to_list @@ Array.init (String.length s) (String.get s)
  then "YES"
  else "NO"

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef pair<ll , ll> PLL;
typedef long double ld;

#define pb push_back
#define all(c) c.begin(),c.end()
#define allr(c) c.rbegin(),c.rend()
#define MOD 1000000007
#define PI 3.14159265
#define endl '\n'
#define MAX 200001


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

    int n;
    cin >> n;
    if (n == 1) {
    	cout << "Hello World" << endl;
    }else {
    	int a , b;
    	cin >> a >> b;
    	cout << a + b << endl;
    }

    return 0;
}

Measured memory_bytes: 384
/**
 *    author:  Mohamad Milhem
 *    created: 2020-01-26-19.28.52
**/

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

using namespace std;
typedef long long ll;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mp make_pair
#define pb push_back
#define lp(i,s,f) for(ll i = s; i < ll(f); i++)
#define inF freopen("input.in", "r", stdin);
#define outF freopen("output.in", "w", stdout);
#define MOD ll(1000000007)
#define debug(x) cout << '[' << #x << " is: " << x << "] " <<endl;


long long sum ;

long long half(long long now , long long p){
    if (now == 1){sum+=p;return 0;}

    sum+=p;

    p*=2;

    half(now/2, p);


}



int main(){

    FAST;


    long long h;
    cin >> h;


    half(h,1);

    cout << sum <<endl;


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007 

ll n,ans;
ll a[11];

void cal(){
	bool b[3],c[1];
	b[0]=b[1]=b[2]=c[0]=0;
	ll sum=0;
	for(int i=0;i<10;i++){
		sum*=10;
		sum+=a[i];
		if(c[0]==1&&a[i]==0){
			return;
		}
		if(a[i]==3){
			b[0]=c[0]=1;
			continue;
		}
		if(a[i]==5){
			b[1]=c[0]=1;
			
			continue;
		}
		if(a[i]==7){
			b[2]=c[0]=1;
			continue;
		}
	}
	if(b[0]==0||b[1]==0||b[2]==0){
		return;
	}
	if(sum<=n){
		ans++;
	}
}
void dep(ll now){
	if(now==10){
		cal();
		return;
	}
	a[now]=0;dep(now+1);
	a[now]=3;dep(now+1);
	a[now]=5;dep(now+1);
	a[now]=7;dep(now+1);
}
int main() {
	cin>>n;
	dep(0);
	cout <<ans;
	return 0;
}

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

#define rep(i,n) for(int i = 0; i < n; i++)
#define REP(i,n) for(int i = 1; i < n; i++)
#define per(i,n) for(int i = n-1; i >= 0; i--)
#define PER(i,n) for(int i = n; i >= 1; i--)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
using vb = vector<bool>;
using vc = vector<char>;
using vcc = vector<vc>;
using vP = vector<P>;
using vPl = vector<Pl>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }



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

  int h, w;
  cin >> h >> w;
  vs v(h);
  rep(i,h) cin >> v[i];
  rep(i,h) {
    rep(j,w) {
      if(v[i][j] == '.') continue;
      bool ok = false;
      rep(d,4) {
        int nx = j + dx[d];
        int ny = i + dy[d];
        if(nx < 0 || nx >= w || ny < 0 || ny >= h) continue;
        if(v[ny][nx] == '#') ok = true;
      }
      if(ok == false) {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI = 3.141592653589793238462643383279;
ll getDigit(ll x) {
  return x == 0 ? 1 : log10(x) + 1;
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

ll lcm(ll a, ll b) {
  return a / gcd(a, b) * b;
}

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

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

template <typename T>
void debugV(const vector<T> v) {
#ifdef _DEBUG
  rep(i, v.size()) {
    cout << i << ":" << v[i] << " ";
  }
  cout << endl;
#else
  (void)v;
#endif
}

signed main() {
  ll N, D;
  cin >> N >> D;

  vector<vll> X;

  rep(i, N) {
    vll temp(D);
    rep(j, D) {
      cin >> temp[j];
    }
    X.pb(temp);
  }

  ll ans = 0;
  rep(i, N) {
    rep2(j, i + 1, N) {
      ll sum = 0;
      rep(k, D) {
        sum += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
      }
      vector<P> f = factorize(sum);
      bool ok = true;
      for (auto p : f) {
        if (p.second % 2 == 1) {
          ok = false;
          break;
        }
      }
      if (ok) {
        ans++;
      }
    }
  }
  COUT(ans);
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <iomanip>
#include <map>
#include <queue>
#include <list>

#define REP(i, n ,N) for(ll i = (n); i < (N); i++)
//#define RREP(i, n ,N) for(ll i = (N-1); i >= (n); i--)
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
#define INF 1e9

using namespace std;
typedef long long  ll;

const long long MOD = 1e9+7;

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

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

#define lli long long int
#define ii pair<int, int>
#define ll pair<lli, lli>
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mp make_pair
#define fi first
#define se second

using namespace std;

int main() {
	int n, t[55], ans = 0;
	char s[105];
	string ss;
	map<string, int> id;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%s %d", s, &t[i]);
		ss = s;
		id[ss] = i;
	}
	scanf("%s", s);
	ss = s;
	for (int i = id[ss] + 1; i < n; i++)
		ans += t[i];
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
v = []
m = [False for _ in range(9)]
for i in range(3):
    a, b, c = map(int, input().split())
    v += [a, b, c]

n = int(input())
for i in range(n):
    a = int(input())
    if a in v:
        m[v.index(a)] = True

def control():
    for i in range(3):
        if all(m[3*i:3*i+3]):
            return True
        if all(m[i::3]):
            return True

    if all(m[::4]) or all(m[2:8:2]):
        return True
    return False

print("Yes" if control() else "No")

Measured memory_bytes: 3064
import sys
import heapq
input = sys.stdin.readline

N, M, = map(int, input().split())
L = [[int(v) for v in input().split()] for _ in range(M)]
t = [set() for _ in range(N)]

for i in range(M):
    x, y = L[i]
    
    t[x - 1].add(y - 1)
    t[y - 1].add(x - 1)

ans = 0
def dfs(now, visited):
    global ans
    
    if len(visited) == N:
        ans += 1
        return
    
    for v in t[now]:
        if v not in visited:
            dfs(v, visited + [v])

    return

dfs(0, [0])
print(ans)

Measured memory_bytes: 3064