akhauriyash/Code-Regression huggingface dataset:
#include <cmath>
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<set>
#include<bitset>
#include<iomanip>
#include<stack>
#include<set>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll inf = 1000000007;
ll n, m;
class union_find {
	public:
	vector<int>par;
	vector<int>size;

	union_find(int n) : par(n), size(n, 1) {
		for (int i = 0; i < n; i++) {
			par[i] = i;//最初の親は自分自身
		}
	}
	void init(int n) {
		par.resize(n);
		size.assign(n, 1);
		for (int i = 0; i < n; i++) {
			par[i] = i;//最初の親は自分自身
		}
	}
	//木の根を求める
	int root(int x) {
		if (par[x] == x) {
			return x;
		}
		else {
			return par[x] = root(par[x]);
		}
	}
	//xとyが同じ集合に属すか否か
	bool same(int x, int y) {
		return(root(x) == root(y));
	}
	//xとyの属する集合を併合
	bool unite(int x, int y) {
		x = root(x);
		y = root(y);
		if (x == y)return false;//根が同じならもう併合済み
		//併合するときは"小さい方"を"大きい方"に併合させる
		if (size[x] < size[y]) {
			swap(x, y);
		}
		size[x] += size[y];
		par[y] = x;
		return true;
	}

	int getSize(int x) {
		return size[root(x)];
	}
};

//union_find tree;
//tree.init(); //これで初期化
//tree.unite(a,b) //aとbのグループを併合
//tree.same(a,b) //aとbが同じグループか(trueかfalse)
int main(void) {
	cin >> n >> m;
	union_find tree(n);
	
	int a, b;
	for (int i = 0; i < m; i++) {
		cin >> a >> b;
		a--; b--;
		if (!tree.same(a, b)) {
			tree.unite(a, b);
		}
	}
	int ans = -1;
	for (int i = 0; i < n; i++) {
		ans = max(ans, tree.getSize(i));
	}
	cout << ans << endl;
	return 0;
}

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

int L[500001], R[500001];
char LSuits[500001], RSuits[500001];

void merge(int *A, char *suits, int left, int mid, int right){
    int i;
    int n = mid - left + 1;
    int n2 = right - mid;
    for(i=0;i<n;i++) {
        L[i] = A[left+i];
        LSuits[i] = suits[left+i];
    }
    for(i=0;i<n2;i++) {
        R[i] = A[mid+i+1];
        RSuits[i] = suits[mid+i+1];
    }
    L[n] = R[n2] = INT_MAX;
    int r=0, l=0;
    for(i=left;i<=right;i++){
        if(L[l] <= R[r]){
            A[i] = L[l++];
            suits[i] = LSuits[l-1];
        }else{
            A[i] = R[r++];
            suits[i] = RSuits[r-1];
        }
    }
}

void mergeSort(int *A, char *suits, int left, int right){
    if(left<right){
        int mid = (left + right) / 2;
        mergeSort(A, suits, left, mid);
        mergeSort(A, suits, mid+1, right);
        merge(A, suits, left, mid, right);
    }
}

int partition(int *A, char *suits, int p, int r){
    int i, pos = p-1;
    int rep = A[r];
    for(i=p;i<r;i++){
        if(A[i] <= rep){
            swap(A[++pos], A[i]);
            swap(suits[pos], suits[i]);
        }
    }
    swap(A[r], A[++pos]);
    swap(suits[r], suits[pos]);
    return pos;
}

void quicksort(int *A, char *suits, int p, int r){
    if (p<r){
        int q = partition(A, suits, p, r);
        quicksort(A, suits, p, q-1);
        quicksort(A, suits, q+1, r);
    }
    return;
}

void compairSuits(char *s1, char *s2, int n){
    rep(i,n){
        if(s1[i]!=s2[i]){
            cout << "Not stable" << endl;
            return;
        }    
    }
    cout << "Stable" << endl;
}

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

    int i, A[n], A2[n];
    char suits[n], suits2[n];
    for(i=0;i<n;i++){
        cin>>suits[i];
        suits2[i] = suits[i];
        cin>>A[i];
        A2[i] = A[i];
    }

    quicksort(A, suits, 0, n-1);
    mergeSort(A2, suits2, 0, n-1);

    compairSuits(suits, suits2, n);

    rep(i,n){
        cout << suits[i]  << " "<< A[i] << endl;
    }

    return 0;
}




Measured memory_bytes: 4588
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

using ll = long long;

void read();
template<typename First, typename... Rest> void read(First& first, Rest&... rest);
void write();
template<typename First, typename... Rest> void write(First first, Rest... rest);
template<typename T> void write_vec(vector<T>& v, char divider);

int main(){
    ll X;
    read(X);
    int ans = 0;
    double a = 100;
    while(a < X){
        a = (ll)((a * 101) / 100);
        ans++;
    }
    write(ans);
    return 0;
}

//配列以外の入力を受け取る
void read(){

}
template<typename First, typename... Rest>
void read(First& first, Rest&... rest){
    cin >> first;
    read(rest...);
}
//
//配列以外を出力する
void write(){

}
template<typename First, typename... Rest>
void write(First first, Rest... rest){
    cout << first << " ";
    write(rest...);
}
//
//配列を区切って出力する
template<typename T>
void write_vec(vector<T>& v, char divider){
    for(size_t i = 0; i < v.size(); i++){
        cout << v[i] << divider;
    }
}
//

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

int main() {
  int n; cin >> n;
  
  bool able = true;
  for (int i = 0; i < n; ++i) {
    int a; cin >> a;
    if (a % 2 == 0 && a % 3 != 0 && a % 5 != 0) {
      able = false;
      break;
    }
  }
  
  if (able) cout << "APPROVED" << endl;
  else cout << "DENIED" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<queue>
#include<stack>
#include<map>
#include<math.h>
#include<string>
#include <cctype>
#include <cstdlib>
#include<bitset>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for (int i = s; i < (int)(n); i++)
#define out(x) cout << x << endl;
#define INF 1ll<<60;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

using namespace std;
using ll = long long;
typedef pair<int, int> P;

int main(){
    int n; cin >> n;
    int cnt=0;
    for(int i=1; i<=n; i++){
        int a;
        cin >> a;
        if(a%2!=0&&i%2!=0) cnt++;
    }
    out(cnt);
}

Measured memory_bytes: 3632
A=int(input())
B=int(input())
C=int(input())
D=int(input())
E=int(input())
F=int(input())

X=[]
X.append(A)
X.append(B)
X.append(C)
X.append(D)
X.remove(min(X))

Y=[]
Y.append(E)
Y.append(F)
Y.remove(min(Y))

Z=X+Y
W=sum(Z)
print(W)


Measured memory_bytes: 5592
class Solver:
    def __init__(self, N, M, edges) -> None:
        self.N = N
        self.M = M
        self.edges = edges

    def find_next_node(self, current, visited):
        candidates = []
        for edge in self.edges:
            if edge[0] == current:
                candidates.append(edge[1])
            if edge[1] == current:
                candidates.append(edge[0])
        ret = []
        for node in candidates:
            bit = 2**(node - 1)
            if visited & bit == 0:
                # AND演算でゼロの場合は未訪問ノード
                ret.append(node)
        return ret

    def dfs(self, node, visited):
        """
        visitedのn番目のビットでノードnを訪ずれたか管理する
        """
        visited += 2**(node - 1)
        if visited == 2**self.N - 1:
            return 1
        movable_nodes = self.find_next_node(node, visited)
        return sum([self.dfs(next_node, visited) for next_node in movable_nodes])


    def solve(self) -> int:
        return self.dfs(1, 0)


if __name__ == "__main__":
    N, M = list(map(int, input().split()))
    edges = []
    for _ in range(M):
        edges.append(list(map(int, input().split())))

    s = Solver(N, M, edges)
    print(s.solve())

Measured memory_bytes: 3064
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  int N,M;
  int inf=1e7;
  cin>>N>>M;
  int d[N][N],a[M],b[M],c[M];
  REP(i,N)REP(j,N)d[i][j]=(i==j?0:inf);
  REP(i,M){
    cin>>a[i]>>b[i]>>c[i];
    a[i]--;b[i]--;
    d[a[i]][b[i]]=c[i];d[b[i]][a[i]]=c[i];
  }
  REP(k,N)REP(i,N)REP(j,N)d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
  int ans=M;
  REP(m,M){
    REP(i,N)REP(j,N){
      if(d[i][j]==d[i][a[m]]+c[m]+d[b[m]][j]){
        ans--;
        i=N-1;
        j=N-1;
      }
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    int a=0,w=0,t=0,r=0;
    for(int i=0;i<n;i++){
        string s;
		cin>>s;
		if(s=="AC")	a++;
		else if(s=="WA")	w++;
		else if(s=="TLE")	t++;
		else if(s=="RE")	r++;
	}
	cout<<"AC x "<<a<<endl;
	cout<<"WA x "<<w<<endl;
	cout<<"TLE x "<<t<<endl;
	cout<<"RE x "<<r<<endl;
	return 0;
}

Measured memory_bytes: 3620
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<string>
#define ll long long
using namespace std;


int main()
{
    ll n;
    cin>>n;
    if(n&1) {cout<<0<<endl;return 0;}
    ll ans = 0;
    ll k = 10;
    while(k<=n)
    {
        ans += n/k;
        k*=5;
    }
    cout<<ans<<endl;
    return 0;
}


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

const int N = 50 + 10;

int n, a[100], b[100];
vector<int > adj[N];
bool vis[N], mark[N];

bool canDfs(int u, int v){
	if (u == v) return 1;
	vis[u] = 1;
	bool ans = 0;
	for (int x : adj[u])
		if (!vis[x]) 
			ans |= canDfs(x, v);
	return ans;
}

bool notNecc(int lim){
	// only use [1, lim)
	
	for (int i = 1; i <= 50; i++){
		adj[i].clear();
		for (int j = 1; j <= 50; j++)
			if (j < lim or mark[j] ) adj[i].push_back(i % j);
	}
	bool flag = 1;
	for (int i = 1; i <= n; i++)
		memset(vis, 0, sizeof vis),
		flag &= (canDfs(a[i], b[i]));
	return flag;
}

void solve(){
	long long ans = 0;
	for (int i = 50; i >= 1; i--){
		if (notNecc(i));
		else ans += (1LL << i), mark[i] = 1;
	}
	if (!notNecc(1)) cout << -1;
	else cout << ans;
}

main(){
	// freopen("C.inp", "r", stdin);
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	for (int i = 1; i <= n; i++)
		cin >> b[i];

	solve();
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int K,A,B;
  cin>>K>>A>>B;
  string flag="NG";
  for(int i=0;i<1000;i++){
    if(A<=K*i&&K*i<=B){flag="OK";break;}
  }
  cout<<flag<<endl;
}

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

#define ll long long int
#define vi vector<int> 
ll prime(int i){

    int j=2;
    for(j=2;j<sqrt(i);j++){
        if(i%j==0)return 0;
        
    }
return 1;    
}




int main() {
 int x;
  cin >> x;
  ll i=x;
  for( i=x;prime(i)==0;i++);
  cout<<i<<" ";
}


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

int cut[100010];
int a[100010];

int main(){
	int n;
	int ans=0;
	cin >> n;
	
	for(int i=0;i<n;i++)
		cin >> a[i];
	
	for(int i=0;i<n;i++){
		if(a[i]>n)
			ans++;
		else
			cut[a[i]]++;
	}
	for(int i=1;i<=n;i++){
		if(cut[i]<i)
			ans+=cut[i];
		else
			ans+=cut[i]-i;
	}
	cout << ans << endl;
}


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

#define MOD_1_000_000_007 (1000000007LL)
#define LINF (1LL<<60)
#define rep(i, n)   for (long long i = 0; i <  (long long)(n); i++)
#define rep1(i, n)  for (long long i = 1; i <  (long long)(n); i++)
#define rep2(i, n)  for (long long i = 2; i <  (long long)(n); i++)
#define rep0c(i, n) for (long long i = 0; i <= (long long)(n); i++)
#define rep1c(i, n) for (long long i = 1; i <= (long long)(n); i++)
#define rep2c(i, n) for (long long i = 2; i <= (long long)(n); i++)
#define repc0(n, i) for (long long i = (long long)(n); i >= 0; i--)
#define repc1(n, i) for (long long i = (long long)(n); i >= 1; i--)
#define repc2(n, i) for (long long i = (long long)(n); i >= 2; i--)

namespace solver {
  using namespace std;
  typedef long long ll;

  ll N, M, K;

  void init() {
    scanf("%lld %lld %lld", &N, &M, &K);
  }

  void solve() {
    ll da = min(N, K);
    N -= da;
    K -= da;
    ll db = min(M, K);
    M -= db;
    printf("%lld %lld\n", N, M);
  }
}

int main() {
  solver::init();
  solver::solve();
  return 0;
}

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

class Main{
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		String str = br.readLine();

		StringTokenizer st = new StringTokenizer(str," ");

		int a = Integer.parseInt(st.nextToken());
		int b = Integer.parseInt(st.nextToken());

		if (a < b) {
			System.out.println("a < b");
		}else if (a > b){
			System.out.println("a > b");
		}else if(a == b){
			System.out.println("a == b");
		}
	}
}

Measured memory_bytes: 24228
#include <iostream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <iomanip>
using namespace std;

int main() {
  int N;
  cin >> N;
  
  int x[N], y[N];
  vector<int> v;
  for (int i = 0; i < N; i++) {
    cin >> x[i] >> y[i];
    v.push_back(i);
  }
  
  //順列生成
  double patterns = 0;
  double totalDistance = 0;
  do{
    patterns++;
    double dist = 0;
    //vは次の順列になる
    for(int i=0;i<N-1;i++){
      dist += pow(pow(x[v[i]]-x[v[i+1]],2)+pow(y[v[i]]-y[v[i+1]],2), 0.5);
    }
    totalDistance += dist;
  }while(next_permutation(v.begin(),v.end()));
  double avg = totalDistance/patterns;
  cout << std::fixed << setprecision(6) << avg << endl;
  return 0;
}


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

import math

def primes(x):
    if x < 2: return []

    primes = [i for i in range(x)]
    primes[1] = 0 
    
    for prime in primes:
        if prime > math.sqrt(x): break
        if prime == 0: continue
        for non_prime in range(2 * prime, x, prime): primes[non_prime] = 0

    return [prime for prime in primes if prime != 0]

a = primes(55555)
ans = []
for i in range(len(a)):
    tmp = a[i]
    if tmp % 5 == 1:
        ans.append(a[i])
        if len(ans) == n:
            break
print(*ans)

Measured memory_bytes: 5272
from collections import deque

dll = deque()

n = int(input())
for _ in range(n):
    command = input()
    if command[0] == "i":
        dll.appendleft(command[7:])
    elif command[0] == "d":
        if command[6] == ' ':
            key = command[7:]
            if key in dll:
                dll.remove(key)
        elif command[6] == "F":
            dll.popleft()
        else:
            dll.pop()

print(' '.join(dll))


Measured memory_bytes: 69736
/*  -*- coding: utf-8 -*-
 *
 * 3002.cc: 
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 5;
const int INF = 1 << 30;

/* typedef */

typedef pair<int,int> pii;
typedef int vec[MAX_N + 1];

/* global variables */

char s[1024];

/* subroutines */

int num(char *(&cpt)) {
  int n = 0;
  while (*cpt >= '0' && *cpt <= '9')
    n = n * 10 + (*(cpt++) - '0');
  return n;
}

pii term(char *(&cpt)) {
  int c = (*cpt != 'x') ? num(cpt) : 1;
  if (*cpt != 'x') return pii(c, 0);

  cpt++; // 'x'
  int e = 1;
  if (*cpt == '^') {
    cpt++; // '^'
    e = num(cpt);
  }

  return pii(c, e);
}

int expr(char s[], vec fs) {
  memset(fs, 0, sizeof(vec));
  char *cpt = s;

  pii t0 = term(cpt);
  fs[t0.second] = t0.first;
  int en = t0.second;

  while (*cpt && (*cpt == '+' || *cpt == '-')) {
    char op = *(cpt++); // '+' || '-'
    pii t1 = term(cpt);
    fs[t1.second] = (op == '+') ? t1.first : -t1.first;
  }

  return en;
}

int eval(int n, vec fs, int x) {
  int sum = 0;
  for (int i = 0, xe = 1; i <= n; i++, xe *= x)
    sum += fs[i] * xe;
  return sum;
}

/* main */

int main() {
  scanf("%s", s);
  vec fs;
  int n = expr(s, fs);
  //for (int i = n; i >= 0; i--) printf("%d ", fs[i]); putchar('\n');

  vec ans;
  int k = 0, f0 = abs(fs[0]);
  for (int p = 1; p * p <= f0; p++)
    if (f0 % p == 0) {
      if (eval(n, fs, p) == 0) ans[k++] = -p;
      if (eval(n, fs, -p) == 0) ans[k++] = p;

      int q = f0 / p;
      if (q != p) {
	if (eval(n, fs, q) == 0) ans[k++] = -q;
	if (eval(n, fs, -q) == 0) ans[k++] = q;
      }
    }
  //printf("k=%d\n", k);

  sort(ans, ans + k);
  for (int i = 0; i < k; i++) printf("(x%+d)", ans[i]);
  putchar('\n');
  return 0;
}



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

int main()
{
    int n, x;
    std::cin >> n >> x;

    std::vector<int> arr;
    arr.reserve(n);
    for (int i = 0; i < n; ++i)
    {
        int tmp;
        std::cin >> tmp;
        arr.push_back(tmp);
    }

    int64_t count = 0;
    if (arr[0] + arr[1] > x)
    {
        const int d = arr[0] + arr[1] - x;
        count += d;
        arr[1] = std::max(arr[1] - d, 0);
        // arr[0]はもう参照しないので編集しない
    }
    for (int i = 2; i < n; ++i)
    {
        const int d = arr[i - 1] + arr[i] - x;
        if (d > 0)
        {
            arr[i] -= d;
            count += d;
        }
    }

    std::cout << count << std::endl;
    return 0;
}


Measured memory_bytes: 640
#include<stdio.h>
int main (){
    int A[1100];
    int N,a,b;
    int c=0;
    int d=0;
    scanf("%d",&N);

    for(a=0;a<N;a++){
        scanf("%d",&A[a]);
    }
    
  for(b=0;b<N;b++){
       
      if(A[b]%2==0){
            d++;
        }


        if(A[b]%2==0 && A[b]%3==0){
            c++;
        }else if(A[b]%2==0 && A[b]%5==0){
            c++;
        }

        //if(A[b]%15==0){
          //  --c;
        //}
   // printf("%d\n",c);
  }
        if(c==d){
            printf("APPROVED");
        }else{
            printf("DENIED");
        }
return 0;


}

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }

// ----------------------------------------------------------------------
// ----------------------------------------------------------------------

struct UnionFind {
  vector<int> par, s; 
  UnionFind(int N) : par(N), s(N) { rep(i,N) { par[i] = i; s[i] = 1; } }
  int root(int x) { return par[x]==x ? x : par[x] = root(par[x]); }
  int size(int x) { return par[x]==x ? s[x] : s[x] = size(root(x)); }
  void unite(int x, int y) { int rx=root(x), ry=root(y); if (rx!=ry) { s[rx] += s[ry]; par[ry] = rx; } }
  bool same(int x, int y) {  int rx=root(x), ry=root(y); return rx==ry; }
};

// ----------------------------------------------------------------------
// ----------------------------------------------------------------------

int main() {
  int N, K, L; cin >> N >> K >> L;
  UnionFind ufk(N), ufl(N);
  rep(i,K) {
    int p, q; cin >> p >> q; p--; q--;
    ufk.unite(p,q);
  }
  rep(i,L) {
    int r, s; cin >> r >> s; r--; s--;
    ufl.unite(r,s);
  }
  map<p_ll, int> count;
  rep(i,N) count[make_pair(ufk.root(i),ufl.root(i))]++;
  vector<int> result(N); rep(i,N) result[i] = count[make_pair(ufk.root(i),ufl.root(i))];
  debug(all(result));
  return 0;
}

Measured memory_bytes: 15872
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <memory.h>
#include <set>
#include <cmath>
#define fio ios::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
ll _pow(ll a, ll b) {
	ll ans = 1;
	for (ll i = 0; b >> i; i++) {
		if ((b >> i) & 1) ans *= a;
		a *= a;
	}
	return ans;
}
int front, rear;
int main(void) {
	scanf("%2d%2d", &front, &rear);
	if (0 < front && front < 13 && 0 < rear && rear < 13) printf("AMBIGUOUS\n");
	else if (0 < front && front < 13) printf("MMYY\n");
	else if (0 < rear && rear < 13) printf("YYMM\n");
	else printf("NA\n");
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.math.*;

public class Main {
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        String str=sc.next();
        BigInteger a=new BigInteger(str);
        str=sc.next();
        BigInteger b=new BigInteger(str);
        System.out.println(a.divide(b));
    }
}



Measured memory_bytes: 26356
#include <iostream>
#include <string>
#include <stdio.h>
#include <cmath>
#include <cfloat>
#include <algorithm>
#include <functional>
#include <numeric>
#include <vector>
using namespace std;

const double PI=acos(-1);

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

    vector<int> l(1000000);
    bool a = false;
    for(int i = 0; i < 1000000; i++){
        if(i == 0) l[i] = s;
        else if(l[i-1]%2 == 0) l[i] = l[i-1]/2;
        else l[i] = l[i-1]*3+1;
        for(int j = 0; j < i; j++){
            if(l[j] == l[i]){
                cout << i+1 << endl;
                a = true;
                break;
            }
        }
        if(a) break;
    }
    return 0;
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
#define fastio() ios_base::sync_with_stdio(false);
using namespace std;
typedef long long ll;
typedef long double ld;


int main(){
	int n, m;
	cin >> n >> m;
	if (n == m) puts("Yes");
	else puts("No");
	return 0;
}


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

#define WHITE -1
#define  GRAY  0
#define BRACK  1

typedef struct{
  int key;
  int d;
} edge;

typedef struct{
  int k;
  char color;
  int d;
  edge *A;
} Point;

void heapIN(int,edge);
void insert(int, int);
edge extract(void);
void Mheap(int);

int H=0;
edge *Q;

int main(){
  Point *p;
  edge mind;
  int i,j,n,v,u,id,qsize=0;

  scanf("%d",&n);
  p=(Point *)malloc(sizeof(Point)*n);

  for(i=0;i<n;i++){
    //   printf("test1\n");
      
    scanf("%d%d",&id,&p[i].k);
    
    p[i].A=(edge *)malloc(sizeof(edge)*p[i].k);
    qsize+=p[i].k;

    //printf("==%d\n",sizeof(edge));

    for(j=0;j<p[i].k;j++){
      scanf("%d%d",&p[i].A[j].key,&p[i].A[j].d);
      //printf("A=%d C=%d\n",p[i].A[j].key,p[i].A[j].d);
    }

    p[i].color=WHITE;
    p[i].d=INT_MAX;
  }

  Q=(edge *)malloc(sizeof(edge)*qsize);
    
  p[0].d=0;
  insert(0,0);

  while(H != 0){
    mind = extract();
    u=mind.key;

    //printf("u=%d\n",u);
    p[u].color = BRACK;
    if(p[u].d < mind.d) continue;
    
    for(i=0;i<p[u].k;i++){
      v = p[u].A[i].key;
;
      if(p[v].color != BRACK && p[u].d + p[u].A[i].d < p[v].d){
	//printf("v=%d,p[u].A[v].key=%d \n",v,p[u].A[i].key);
	p[v].d = p[u].d + p[u].A[i].d;
	p[v].color=GRAY;
	insert(v,p[v].d);
      }
    }
  }

  for(i=0;i<n;i++){
    printf("%d %d\n",i,p[i].d == INT_MAX ? -1 : p[i].d);
    //printf("color[%d]=%d\n",i,p[i].color);
  }

  return 0;
}

void insert(int key, int d){
  edge in;

  //printf("key=%d,d=%d ",key,d);

  in.key=key;
  in.d=d;
  
  H++;
  Q[H].d=INT_MAX;
  heapIN(H,in);
}

void heapIN(int i,edge in){
    edge swap;

    //printf("in.d=%d ",in.d);
    
    if (in.d>Q[i].d) return;
    Q[i]=in;

    //for(i=0;i<=H;i++){ printf("insert Q[%d].key=%d,Q[%d].d=%d  ",i,Q[i].key,i,Q[i].d);} printf("\n");
    
    while(i>1 && Q[i/2].d > Q[i].d){
        swap=Q[i/2];
        Q[i/2]=Q[i];
        Q[i]=swap;
        i/=2;
    }
    //for(i=0;i<=H;i++){ printf("insert H=%d,Q[%d].key=%d,Q[%d].d=%d  ",H,i,Q[i].key,i,Q[i].d);} printf("\n");
}

edge extract(){
    edge min;
    int i;
    
    if(H<1) return Q[0];
    min=Q[1];
    Q[1]=Q[H];
    H--;
    Mheap(1);
    //for(i=0;i<=H;i++) printf("extract Q[%d]=%d ",i,Q[i].key); printf("\n");
   
    return min;
}

void Mheap(int i){
    int l,r,small;
    edge swap;
    
    l = i*2;
    r = i*2+1;
    
    if(l <= H && Q[l].d < Q[i].d) small = l;
    else small=i;
    if(r <= H && Q[r].d < Q[small].d) small = r;
    
    if(small != i){
        swap=Q[small];
        Q[small]=Q[i];
        Q[i]=swap;
        
        Mheap(small);
    }
}






Measured memory_bytes: 5676
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Math;
using static System.Array;
using static AtCoder.Tool;
namespace AtCoder
{
    class AC
    {
        const int mod = 1000000007;
        const int INF = int.MaxValue / 2;
        const long SINF = long.MaxValue / 2;
        static readonly int[] dx = { 0, 1, 0, -1 };
        static readonly int[] dy = { 1, 0, -1, 0 };
        

        static void Main(string[] args)
        {
            //var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            //Console.SetOut(sw);
            var cin = new Scanner();

            int N = int.Parse(Console.ReadLine());
            var d = new Dictionary<string, long>();
            long ans = 0;
            for(var i = 0; i < N; i++)
            {
                var c = Console.ReadLine().ToArray();
                Sort(c);
                var s = new StringBuilder();
                foreach(var x in c)
                {
                    s.Append(x);
                }

                if (d.ContainsKey(s.ToString()))
                {
                    ans += d[s.ToString()];
                    d[s.ToString()]++;
                }
                else
                {
                    d[s.ToString()] = 1;
                }
            
                
            }

            Console.WriteLine(ans);
            

            //Console.Out.Flush();
        }
        
    }
    public class Scanner
    {
        public int[] SplitRead()
        {
            int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray();
            return array;
        }
        public long[] SplitReadL()
        {
            long[] array = Console.ReadLine().Split().Select(long.Parse).ToArray();
            return array;
        }
    }

    public static class Tool
    {
        static public void Initialize<T>(ref T[] array, T initialvalue)
        {
            for (var i = 0; i < array.Length; i++)
            {
                array[i] = initialvalue;
            }
        }
    }
}


Measured memory_bytes: 29880
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <vector>
#include <stack>
#include <queue>
#include <climits>
#include <utility>
#include <map>
#include <set>
#include <complex>
#include <numeric>

#include <time.h>
#include <float.h>

#define loop(i, n) for(i = 0; i < n; i++)
#define loop1(i, n) for(i = 1; i <= n; i++)
#define loop2(i, n, start) for(i = start; i <= n; i++)
#define loopIterators(it, vec) for(it = (vec).begin(); it != (vec).end(); it++)
#define loopRev(i, n) for(i = (n - 1); i >= 0; i--)
#define FLASH ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define testCases(t) cin >> t; while(t--)
#define PN(n) cout << (n)
#define PN1(n) cout << (n) << " "
#define PN2(a, b) cout << (a) << " " << (b) << " "
#define PNN1(n) cout << (n) << endl
#define PNN2(a, b) cout << (a) << " " << (b) << endl
#define PNN3(a, b, c) cout << (a) << " " << (b) << " " << (c) << endl
#define PrintArray(ar, n) for(i = 0; i < n; i++) cout << ar[i] << " "; cout << endl
#define PrintSet(ar, it) for(it = ar.begin(); it != ar.end(); it++) cout << *it << " "; cout << endl
#define PrintMap(map, it) for(it = map.begin(); it != map.end(); it++) PNN2(it -> first, it -> second)
#define sz(a) sizeof(a)
#define IN1(n) cin >> n
#define IN2(a, b) cin >> a >> b
#define IN3(a, b, c) cin >> a >> b >> c
#define ALL(s) s.begin(), s.end()
#define SWAP(a, b, c) c = a; a = b; b = c
#define STRSP(s) scanf("%[^\n]%*c", s)
#define ENTER PNN1("");
#define MOD7 1000000007
#define MOD9 10000009
#define MAX 100005
#define llPair std::pair<lli, lli>
#define iiPair std::pair<int , int>
#define ONLINE_JUDGE

typedef long long int lli;
typedef long int li;
typedef unsigned long long int ulli;
typedef long double ld;

using namespace std;

int main(void){
	FLASH

	#ifndef ONLINE_JUDGE
		freopen("input-stream.txt", "r", stdin);
    freopen("output-stream.txt", "w", stdout);
	#endif

	int a, b, i;
	IN2(a, b);

	loop2(i, b * 10 + 9, b * 10) if ((int)(i * .08) == a) {
		PNN1(i);
		return 0;
	}

	PNN1(-1);

	#ifndef ONLINE_JUDGE
		fclose(stdin);
    fclose(stdout);
	#endif

	return 0;
}


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


int main(){
	double tl500[]= {70,  55, 50, 43, 40, 37.5,  35.5};
	double tl1000[]={148,116,105, 89, 83, 77, 71};
	char *rank[]=    {"E","D","C","B","A","AA","AAA"};
	
	double a,b;
	while(cin>>a>>b){
		char *ans="NA";
		for(int i=0;i<7;i++){
			if(a<tl500[i]&&b<tl1000[i])ans=rank[i];
		}
		cout<<ans<<endl;
	}
	return 0;
}

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

using namespace std;

#define REP(i,m) for(ll i=0; i<m; i++)
#define FOR(i,n,m) for(ll i=n; i<m; i++)
#define INF 1000000007
#define INFL (1LL << 60)
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define SORT(v) sort(ALL(v))
#define pb push_back
#define ll long long int
#define P pair<ll, ll>
 
int main(){
    int n, k;
    cin >> n >> k;
    ll x[100010];
    REP(i, n) cin >> x[i];
    ll ans = INFL;
    REP(i, n-k+1){
        ll r = x[i];
        ll l = x[i+k-1];
        ll dis;
        if(r>=0) dis = l;
        else if(l<=0) dis = -r;
        else dis = l-r+(abs(l)<abs(r)?abs(l):abs(r));
        ans = (ans>dis?dis:ans);
    }
    cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<cmath>
#include<numeric>
#include<functional>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
#define ll long long
#define modbig (10*10*10*10*10*10*10*10*10+7)
using namespace std;

int main(){
  int a,b;
  cin>>a>>b;
  if((a+b)%2==0){
    cout<<(a+b)/2;
  }else{
    cout<<"IMPOSSIBLE";
  }
}


Measured memory_bytes: 256
n = int(input())
lst = list(map(int,input().split()))
stock = []
flg = True
for i in range(n):
    tmp = -100
    for j in range(len(lst)):
        if lst[j] == j+1:
            tmp = max(tmp, j)
    if tmp == -100:
        flg =  False
        break
    else:
        stock.append(lst[tmp])
        lst = lst[:tmp]+lst[tmp+1:]
if not flg:
    print(-1)
else:
    for x in stock[::-1]:
        print(x)

Measured memory_bytes: 3064
#include <stdio.h>
#include <math.h>

int main(void){
  int x,y,z;
  int xxx,yyy,zzz;
  int sq,mxy;
  int max;

  double d3 = 1.0/3.0;

  while( 1 ){
    scanf("%d ",&z );
    if( !z )
      break;

    zzz = z*z*z;
    sq = z/pow( 2.0,1.0/3.0 );
    x = sq;

    max = 0;
    for( x=1;x<=sq;x++ ){
      xxx = x*x*x;
      y = pow( zzz-xxx, d3 );
      yyy=y*y*y;
      mxy = xxx+yyy;
      if( max<mxy )
	max=mxy;
    }
    printf("%d\n",zzz-max);
  }
  return 0;
}

Measured memory_bytes: 0
def main():

    S = input()
    Q = int(input())

    reverse = False
    head = ''
    tail = ''

    for _ in range(Q):
        query= input()
        if query == '1':
            reverse = not reverse
            head, tail = tail, head
        else:
            _, f, c = query.split()
            if f == '1':
                head = ''.join([head,c])
            else:
                tail = ''.join([tail,c])

    if reverse:
        S = S[::-1]

    print(''.join([head[::-1], S, tail]))

if __name__ == "__main__":
    main()

Measured memory_bytes: 4516
import math
a, b = input().split()
a = int(a)

n = 1
if '.' in b:
    if b[-2] == '.':
        n = 10
    elif b[-3] == '.':
        n = 100
    b = b.replace('.', '')
b = int(b)
print(math.floor(a*b//n))




Measured memory_bytes: 9184
#include <bits/stdc++.h>
 using namespace  std;
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
const long double pi=3.1415926535897932384626433832;
const long long mod=1e9+7;
//long long primeset[5000000]={};
typedef complex<double> cd;
typedef long long ll;
//#define For(i,0,n) for(long long i = 0 ; i<n ;i++) 
cd fast_exp(cd a, long long b)
{
	if (b == 0)
		return 1;
	
	cd res = fast_exp(a, b / 2);
		
	res = res * res;
	
	if (b % 2 == 1)
		res = res * a;
	
	return res;
}

long long fastexpon(long long a,long long b,long long mod)
{
	if(b==0)
		return 1;
	
	long long res=fastexpon(a,b/2,mod);
	
	res=(res*res)%mod;
	if(b%2==1)
		res= (res * a)%mod;

	return res;
}



int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int h,w;
	cin>>h>>w;
	int n;
	cin>>n;
	
	int sh , sw;
	cin>>sh>>sw;
	string s,t;
	cin>>s>>t;
	int rr,lr,ur,dr;
	rr=w-sw+1;
	lr=sw;
	ur=sh;
	dr=h-sh+1;

	int check=1;
	int cur=0;
	for(int i=0 ;i<n ;i++)
	{
		if(s[i]=='U')
			cur++;

		if(cur>= ur)
			check=0;
		if(t[i]=='D' && cur-1>-dr)
			cur--;

	}
	 cur=0;
	for(int i=0 ;i<n ;i++)
	{
		if(s[i]=='D')
			cur++;
		if(cur>= dr)
			check=0;
		if(t[i]=='U' && cur-1> -ur)
			cur--;

		
	}

	cur=0;
	for(int i=0 ;i<n ;i++)
	{
		if(s[i]=='R')
			cur++;

		if(cur>= rr)
			check=0;
		if(t[i]=='L' && cur-1> -lr)
			cur--;


	}

	cur=0;
	for(int i=0 ;i<n ;i++)
	{
		if(s[i]=='L')
			cur++;
		if(cur>= lr)
			check=0;
		if(t[i]=='R' && cur-1>-rr)
			cur--;

		
	}
	if(check==1)
		cout<<"YES";
	else
		cout<<"NO";
	//cout<<'\n'<<"time elapsed: "<<clock()*1000.0 / CLOCKS_PER_SEC<<" ms"<<'\n';
	return 0;
}

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

template <typename T> void read_stdin(const size_t size, vector<T>& array)
{
   T value;
   for (size_t i(0); i < size; ++i) {
      cin >> value;
      array.push_back(value);
   }
}

template <typename T> void output_stdout(const vector<T>& array)
{
   for (const auto& value : array) {
      cout << value << endl;
   }
}

int main() {
   size_t N;
   string inputA, inputB;
   string outputA;

   // read
   {

      cin >> N;
      cin >> inputA;
      cin >> inputB;
   }

   // process
   {
      for (size_t i(0); i < N; ++i) {
         outputA += inputA.substr(i, 1) + inputB.substr(i, 1);
      }
   }

   // output
   {
      cout << outputA << endl;
   }
   
   return 0;
}


Measured memory_bytes: 256
S=input()
if len(S)%2==0:
	S_left=list(S)[:int(len(S)/2)]
	S_right=list(S)[int(len(S)/2):][::-1]

else:
	S_left=list(S)[:int(len(S)//2)]
	S_right=list(S)[int(len(S)/2)+1:][::-1]

ans=0
for i in range(len(S_left)):
	if S_left[i]!=S_right[i]:
		ans+=1

print(ans)

Measured memory_bytes: 8992
#include <bits/stdc++.h>
#define rep(i,n) for(int64_t i=0;i < (int64_t)(n);i++)
#define invrep(i,n) for(int64_t i=n-1;i >= 0;i--)
#define _GLIBCXX_DEBUG
using namespace std;

int64_t calcGCD(int64_t a,int64_t b){
	int64_t p = a;
	int64_t q = b;
	int64_t c = a%b;
	while(c != 0){
		p = q;
		q = c;
		c = p%q;
	}
	return q;
}

int main(){
  int64_t k;
  cin >> k;
  int64_t total = 0; 
  for(int64_t i=1; i <= k; i++){
    for(int64_t j=1; j <= k; j++){
      for(int64_t l=1; l <= k; l++){
        int64_t y = calcGCD(i,j);
        total += calcGCD(y,l);
      }
    }
  }
  cout << total << endl;
      
  

}
      

Measured memory_bytes: 3656
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <limits.h>
#include <cinttypes>
#include <string.h>
#include <bits/stdc++.h>

#define countof(a) (sizeof(a)/sizeof(*a))

#define vi vector<int>
#define vvi vector<vector<int> >
#define pi pair<int,int>
#define fi first
#define se second

#define FOR(var, to)          for (register s64 var = 0; var < (s64)to; var++)
#define FROMTO(var, from, to) for (register s64 var = from; var <= (s64)to; var++)

#define INIT(var) FOR(i,countof(var)) var[i] = 0
#define INPUT(var) FOR(i,countof(var)) var[i] = ri()
#define INPUT1(var) FOR(i,countof(var)) var[i] = ri() - 1

#define SORT(v) qsort(v,countof(v),sizeof(*v),int_less)
#define SORTT(v) qsort(v,countof(v),sizeof(*v),int_greater)

#define MOD 1000000007
#define INF (1 << 30)

typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int8_t s8;
typedef int16_t s16;
typedef int32_t s32;
typedef int64_t s64;

using namespace std;

static inline int ri() {
  int a;
  scanf("%d", &a);
  return a;
}

static inline s64 rs64() {
  s64 a;
  scanf("%" SCNd64, &a);
  return a;
}

static inline void wi(int a) {
  printf("%d", a);
}

static inline void wu64(u64 a) {
  printf("%" PRIu64, a);
}

static inline void ws64(s64 a) {
  printf("%" PRId64, a);
}

int int_less(const void *a, const void *b) {
  return (*((const int*)a) - *((const int*)b));
}
int int_greater(const void *a, const void *b) {
  return (*((const int*)b) - *((const int*)a));
}

int main() {
    int n = ri();
    string s[n];
    FOR(i,n)cin>>s[i];
    bool res = true;
    set<string> tmp;
    FOR(i,n) if (!tmp.insert(s[i]).se) res = false;
    
    FROMTO(i,1,n-1) if (s[i][0] != s[i-1][s[i-1].size()-1]) res = false;
    
    cout << (res?"Yes":"No") << endl;
  
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>

using namespace std;
int main(void){
  int a,b,c,d;
  scanf("%d%d%d%d%d", &a, &b, &c, &d);
  printf("%d\n", (a<b?a:b)+(c<d?c:d));
  
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <numeric>
#include <queue>
#include <numeric>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <map>
#include <functional>
#include <limits>
#include <set>
#include <stack>
#define rep(i,a,b) for((i)=a;i<(int)(b);i++)
#define Max(a,b) ((a) < (b) ? (b) : (a))
#define Min(a,b) ((a) > (b) ? (b) : (a))
#define AAA (1000000007) 


using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pairII;


ll gcd(ll a, ll b) {
	if (b == 0)return a;
	return gcd(b, a % b);
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}
ll powD(ll a, ll b) {
	ll ans = 1;
	a %= AAA;
	for (int i= 0; i <b; i++)
	{
		ans *= a;
		ans %= AAA;
	}
	return ans;
}

int main() {
	int i, j, k;

	int N, M, K;

	string S, T;
	cin >> S >> T;
	sort(S.begin(), S.end());
	sort(T.rbegin(), T.rend());

	if (S < T) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}
	return 0;
}

Measured memory_bytes: 256
def grid_repainting(H: int, W: int, S: int) -> int:
    # ルート探索用の行列。
    # R[h][w] は (0, 0) -> (h, w) の最短距離になる。
    INF = float('inf')
    R = [[INF] * W for _ in range(H)]
    R[0][0] = 1
    white_num = 0

    update = True
    while update:
        update = False
        white_num = 0
        for h in range(H):
            for w in range(W):
                if S[h][w] == '#':
                    # 黒いマス目は無視
                    continue
                white_num += 1

                before = R[h][w]
                if w > 0:
                    R[h][w] = min(R[h][w], R[h][w - 1] + 1)
                if h > 0:
                    R[h][w] = min(R[h][w], R[h - 1][w] + 1)
                if w < W - 1:
                    R[h][w] = min(R[h][w], R[h][w + 1] + 1)
                if h < H - 1:
                    R[h][w] = min(R[h][w], R[h + 1][w] + 1)

                if before != R[h][w]:
                    update = True

    if R[H - 1][W - 1] is INF:
        return - 1

    # R[H-1][W-1] は (0, 0) -> (H-1, W-1) に至るために必要な
    # 最小のマス数になっている。これ以外の全部の白ますは黒マスに変
    # えていいので、それが最大スコア。
    return white_num - R[H-1][W-1]


if __name__ == "__main__":
    H = 0
    H, W = map(int, input().split())
    S = [input() for _ in range(H)]
    ans = grid_repainting(H, W, S)
    print(ans)


Measured memory_bytes: 3064
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
typedef long long ll;
#define rep(i, a, b) for (int i = a; i <= b; ++ i)
#define per(i, a, b) for (int i = a; i >= b; -- i)
const int mo = 1000000007, N = 1005;
using namespace std;
int n, A, B, C, D, fac[N], inv[N], g[N], f[N];
void upd(int &x, int y) { x = (x + y) % mo; }
int mul(int a, int b) {
	int ans = 1, w = a % mo;
	for ( ; b; b /= 2, w = (ll) w * w % mo) 
		if (b & 1) ans = (ll) ans * w % mo;
	return ans;
}
int main() {
	scanf("%d%d%d%d%d", &n, &A, &B, &C, &D);
	fac[0] = 1; rep(i, 1, n) fac[i] = (ll) fac[i - 1] * i % mo;
	rep(i, 0, n) inv[i] = mul(fac[i], mo - 2);
	f[0] = 1;
	rep(i, A, B) {
		g[0] = 1;
		rep(j, 1, n / i) g[j] = (ll) g[j - 1] * inv[i] % mo; 
		per(j, n, 0) rep(k, max(1, C), min(n / i, D)) 
		if (j - k * i >= 0) 
			upd(f[j], (ll) f[j - k * i] * fac[n - (j - k * i)] % mo * g[k] % mo * inv[k] % mo * inv[n - j] % mo);
		else break;
	}
	printf("%d\n", f[n]);
	return 0;
}

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

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

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()

int cnt;
int ma;
int dp[100010];
vi g[100010];
vi g2[100010];

void dfs(int v, int p)
{
	multiset<int> st;
	for (int to : g[v]) {
		if (to != p) {
			dfs(to, v);
			dp[v] = max(dp[v], dp[to]);
			g2[v].pb(to);
			st.insert(dp[to]);
			if (st.size() > 2) st.erase(st.begin());
		}
	}

	if (st.size() == 2) {
		auto it = st.begin();
		auto it2 = it;
		++it2;
		ma = max(ma, *it + *it2);
	}

	if (g[v].size() == 2) {
		if (p != -1) {
			dp[v] = max(dp[v], dp[g2[v][0]] + 1);
		} else {
			ma = max(ma, dp[g2[v][0]] + dp[g2[v][1]] + 1);
		}
	}

	ma = max(ma, dp[v]);
}

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

	rep(i,N-1) {
		int a,b;
		cin >> a >> b;
		--a; --b;
		g[a].pb(b);
		g[b].pb(a);
	}

	rep(i, N) {
		if (g[i].size() == 1) {
			++cnt;
		}
	}

	dfs(0, -1);

	cout << cnt + ma << endl;

	return 0;
}

Measured memory_bytes: 10368
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
using PII = pair<int, int>;
using PLL = pair<LL, LL>;
using VI = vector<int>;
using VVI = vector<vector<int>>;
const int INF = 1e9;
const int MXN = 0;
const int MXV = 0;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define FOR(i, L, R) for (int i = L; i < (int)R; ++i)
#define FORD(i, L, R) for (int i = L; i > (int)R; --i)
#define IOS                                                                    \
    cin.tie(nullptr);                                                          \
    cout.tie(nullptr);                                                         \
    ios_base::sync_with_stdio(false);

int main()
{
    IOS;
    int n, k;
    cin >> n >> k;
    vector<int> h(n + 5), dp(n + 5);
    FOR(i, 0, n) { cin >> h[i]; }
    fill(dp.begin(), dp.end(), INF);
    dp[0] = 0;
    FOR(i, 1, n) FOR(j, 1, k + 1)
    {
        if (i - j < 0)
        {
            break;
        }
        dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
    }
    cout << dp[n - 1] << '\n';
}


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

int main(){
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);

    int x, n;
    cin>>x>>n;
    vector<bool> mask(105, 1);
    for (int i=0; i<n; i++){
        int curr;
        cin>>curr;
        mask[curr]=0;
    }
    int val = 200;
    int ans = -1;
    for (int i=105; i>=0; i--){
        if (mask[i]==1){
            if (abs(i-x)<=val){
                val = abs(i-x);
                ans = i;
            }
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3672
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 10e8+7;

ll powmod(int x, ll y, ll mod){
  ll ans = 1;
  for (int i = 0; i < y; i++){
    ans = (ans * x) % mod;
  }
  return ans;
}

int main() {
  int n;
  cin >> n;
  ll ans = 1;
  ans = powmod(10, n, INF) + powmod(8, n, INF)- powmod(9, n, INF) - powmod(9, n, INF);
  ans %= INF;
  ans = (ans+INF)%INF;
  cout << ans << endl;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = pow(10, 9) + 7;
//const int MOD = 998244353;
//const int MOD = ;
int mod(int A, int M) {return (A % M + M) % M;}
const int INF = 1LL << 60;
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const string abc = "abcdefghijklmnopqrstuvwxyz";
template <class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}

signed main()
{
  int K;
  cin >> K;
  
  int N = 50;
  vector<int> a(N, N - 1 + K / N);
  for (int i = 0; i < N; i++)
  {
    if (i < K % N) a.at(i) += N - K % N + 1;
    else a.at(i) -= K % N;
  }

  cout << N << endl;
  for (int i = 0; i < N; i++)
  {
    cout << a.at(i);
    if (i == N - 1) cout << endl;
    else cout << " ";
  }
  
  /*
  int ans = 0;
  while (true)
  {
    bool flg = true;
    for (int i = 0; i < N; i++)
    {
      if (a.at(i) > N - 1)
      {
        flg = false;
        break;
      }
    }
    if (flg) break;
    
    int M = -INF;
    int Mi;
    for (int i = 0; i < N; i++)
    {
      if (chmax(M, a.at(i))) Mi = i;
      a.at(i)++;
    }
    a.at(Mi) -= 1 + N;
    
    ans++;
  }
  cerr << ans << endl;
  */
}

Measured memory_bytes: 256
import std.stdio;
import std.array;
import std.algorithm;
import std.conv;
import std.numeric;
import std.string;

void main() {
  auto s = readln.chomp;
  auto t = new int[4];
  foreach (i, j; s) {
    t[i] = j.to!int - '0'.to!int;
  }

  foreach(i; 0..2) {
    foreach(j; 0..2) {
      foreach(k; 0..2) {
        int a = t[0], b, c, d;
        if (i == 0) b = t[1];
        else b = -t[1];
        if (j == 0) c = t[2];
        else c = -t[2];
        if (k == 0) d = t[3];
        else d = -t[3];
        if (a + b + c + d == 7) {
          char op1, op2, op3;
          if (i == 0) op1 = '+';
          else op1 = '-';
          if (j == 0) op2 = '+';
          else op2 = '-';
          if (k == 0) op3 = '+';
          else op3 = '-';
          writeln(t[0], op1, t[1], op2, t[2], op3, t[3], "=7");
          return;
        }
      }
    }
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <string>

using namespace std;
int main(int argc, const char * argv[]) {
    
    int n;
    cin >> n;
    cout << 1110 - n << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
def t(A,p,r):
 x=A[r][1];i=p-1
 for j in range(p,r):
  if A[j][1]<=x:i+=1;A[i],A[j]=A[j],A[i]
 A[i+1],A[r]=A[r],A[i+1]
 return i+1
def k(A,p,r):
 if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)
def s(A):
 for i in range(n-1):
  if A[i][1]==A[i+1][1]:
   if A[i][2]>A[i+1][2]:return'Not s'
 return'S'
n=int(input())
f=lambda x,y:(x,int(y))
A=[(*f(*e.split()),i)for i,e in enumerate(sys.stdin)]
k(A,0,n-1)
for e in[[s(A)+'table']]+A:print(*e[:2])


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

int main() {
  int a,b;
  cin >> b >> a;
  int sum=0;
  for(int i=1;i<=1000;i++) {
    for(int j=1;j<499500;j++){
      if(b==sum-j && a==sum+i-j) {
	cout << j << endl;
      }
    }
    sum+=i;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
const ll max_t=1e9;
int main(){
  ll n,k,s;
  cin>>n>>k>>s;
  vector<ll> ans;
  for(int i=0;i<n;i++) ans.push_back(s);
  if(s+n<max_t){
    for(int i=0;i<(n-k);i++) ans[i]++;
  }
  else{
    for(int i=0;i<(n-k);i++) ans[i]--;
  }
  for(int i=0;i<n;i++) cout<<ans[i]<<" ";
  cout<<endl;
}


Measured memory_bytes: 2292
n = int(input())
w = [input() for _ in range(n)]
f1 = len(w) == len(set(w))
f2 = len(w) == len([i for i in range(1, len(w)) if w[i][0] == w[i-1][-1]]) + 1
print("Yes" if f1 and f2 else "No")

Measured memory_bytes: 3060