akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

internal static class CR
{
    public static string Get() { return Console.ReadLine(); }
    public static IEnumerable<string> GetTexts() { return Console.ReadLine().Split(' '); }
    public static int GetInteger() { return int.Parse(Console.ReadLine()); }
    public static IEnumerable<int> GetIntegers() { return Console.ReadLine().Split(' ').Select(x => int.Parse(x)); }
}

namespace AtCoderBeginnerContest
{
    internal class Program
    {
        public static int N { get; private set; }
        public static List<int> P { get; private set; }
        public static List<int> Q { get; private set; }

        private static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.WriteLine(r); }

        private static object GetResult()
        {
            N = CR.GetInteger();
            P = CR.GetIntegers().ToList();
            Q = CR.GetIntegers().ToList();

            var a = GetOrder(N, P);
            var b = GetOrder(N, Q);

            return Math.Abs(a - b);
        }

        private static int GetOrder(int n, List<int> p)
        {
            var sum = 0;
            for (int i = 0; i < n; i++)
            {
                var x = GetX(p, i);
                sum += x * Factorial(n - (i + 1));
            }
            return sum;
        }

        private static int GetX(List<int> p, int i)
        {
            var main = p[i];
            var before = Enumerable.Range(0, i).Select(x => p[x]).ToList();
            var after = i == N - 1
                ? new List<int>()
                : Enumerable.Range(i + 1, N - (i + 1)).Select(j => p[j]).ToList();

            return after.Count(x => x < main && !before.Contains(x));
        }

        public static int Factorial(int n)
        {
            if (n == 0) return 1;
            return n * Factorial(n - 1);
        }
    }
}


Measured memory_bytes: 13396
#include "bits/stdc++.h"
using namespace std;
int main() {

double n, d;
cin >> n >> d;

double range;
range =  2 * d +1;

double ans;
ans = n / range;

if (ans >= 0 && ans  <= 1)
    cout << 1 << endl;

else if (ans >= 1.0001 && ans <= 2)
    cout << 2 << endl;

else if (ans >= 2.0001 && ans <= 3)
    cout << 3 << endl;

else if (ans >= 3.0001 && ans <= 4)
    cout << 4 << endl;

else if (ans >= 4.0001 && ans <= 5)
    cout << 5 << endl;

else if (ans >= 5.0001 && ans <= 6)
    cout << 6 << endl;

else if (ans >= 6.0001 && ans <= 7)
    cout << 7 << endl;

else if (ans >= 7.0001 && ans <= 8)
    cout << 8 << endl;

else if (ans >= 8.0001 && ans <= 9)
    cout << 9 << endl;

else if (ans >= 9.0001 && ans <= 10)
    cout << 10 << endl;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
using namespace std;
const ll MAX_N=2e5,MAX_A=2e5;
typedef vector<ll> vec;
ll N,K,A[MAX_N];
vec p,invp;
bool flg[MAX_A+1];
vec pmul(vec a,vec b){
    vec ret(a.size());
    REP(i,a.size()){
        ret[i]=a[b[i]];
    }
    return ret;
}
vec ppow(vec a,ll n){
    vec ret(a.size());
    REP(i,a.size())ret[i]=i;
    while(n){
        if(n&1){
            ret=pmul(ret,a);
        }
        a=pmul(a,a);
        n>>=1;
    }
    return ret;
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>N>>K;
    REP(i,N)cin>>A[i];
    REP(i,MAX_A+1){
        p.push_back(i);
        invp.push_back(i);
    }
    REP(i,N){
        swap(invp[0],invp[A[i]]);
    }
    REP(i,MAX_A+1){
        p[invp[i]]=i;
    }
    p=ppow(p,K-1);
    vec st;
    if(p[0]!=0){
        st.push_back(p[0]);
        flg[p[0]]=true;
    }
    REP(i,N){
        if(flg[A[i]]){
            while(flg[A[i]]){
                flg[st.back()]=false;
                st.pop_back();
            }
        }else{
            st.push_back(A[i]);
            flg[A[i]]=true;
        }
    }
    bool sflg=false;
    for(auto ite:st){
        if(sflg){
            cout<<' ';
        }
        sflg=true;
        cout<<ite;
    }
    if(sflg){
        cout<<endl;
    }
}                


Measured memory_bytes: 13028
#include <bits/stdc++.h>
#define rep(i, m, n) for(int i = m; i < (n); i++)
#define print(x) cout << (x) << endl;
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]) << " ";} cout << endl;
#define printa2(x,m,n) for(int i = 0; i < m; i++){ for(int j = 0; j < n; j++){ cout << x[i][j] << " ";} cout << endl;}
#define INF (1e9)
typedef long long ll;
typedef struct{
    int x;
    int y;
} P;

using namespace std;
int N;
int a[100010], b[100010];
int dto1[100010]={}, dtoN[100010]={};
vector<int> edge[100010];

void dfs1(int v, int p, int d){
    dto1[v] = d;
    for(auto &e : edge[v]){
        if(p == e) continue;
        dfs1(e, v, d+1);
    }
}

void dfs2(int v, int p, int d){
    dtoN[v] = d;
    for(auto &e : edge[v]){
        if(p == e) continue;
        dfs2(e, v, d+1);
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    rep(i,0,N-1){
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
        edge[a[i]].push_back(b[i]);
        edge[b[i]].push_back(a[i]);
    }

    dfs1(0, -1, 0);
    dfs2(N-1, -1, 0);
    int ans_1 = 0;
    int ans_2 = 0;

    rep(i,0,N){
        if(dto1[i] <= dtoN[i]){
            ans_1++;
        }else{
            ans_2++;
        }
    }
    if(ans_1 > ans_2){
        print("Fennec");
    }else{
        print("Snuke");
    }


}


Measured memory_bytes: 12032
S = input()
T = input()

match = 0
k = 0
result = 0
for i in range(len(S)-len(T)+1) :
    k = i # start
    match = 0
    for j in range(len(T)) :
        #print(T[j],S[k])
        if T[j] == S[k] :
            match = match + 1
        k += 1
    result = max(result,match)
#print(result)
print(len(T) - result)

Measured memory_bytes: 9124
#include<iostream>
#include<string>
#include<cmath>
 
using std::cout;
using std::cin;
using std::endl;
using std::pow;
using std::string;
 
int main(){
    long long int a,out,c;
    double b;
    cin >> a >> b;
    c = b*100 + 1e-9;
    out = a*c/100;
    cout << out;
}

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

using namespace std;

using int64 = long long;


int main()
{
  int N, A[100];

  cin >> N;
  for(int i = 0; i < N; i++) {
    cin >> A[i];
  }
  sort(A, A + N, greater< int >());

  int latte = 0, malta = 0;
  for(int i = 0; i < N; i++) {
    if(i & 1) latte += A[i];
    else malta += A[i];
  }
  cout << malta - latte << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl

ll gcd_ori(ll a, ll b){
    if(a<b) swap(a, b);
    if(b == 0){
        return a;
    }

    return gcd_ori(b, a % b);
}

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }

    return true;
}

ll mod = 1e9+7;

int main() {
    int n; cin >> n;
    vector<int> a(n); rep(i, n) cin >> a.at(i);

    vector<ll> b(1e6+1, 0);
    for(int i=0; i<n; i++){
       int tmp = a.at(i);
       if(IsPrime(tmp)){
           b.at(tmp) = max(b.at(tmp), 1LL);
           continue;
       }
       for(int j=2; j<=tmp; j++){
           int cnt = 0;
           while(tmp%j==0){
               cnt++;
               if(b.at(j)<cnt) b.at(j) = cnt;
               tmp /= j;
           }
       }
    }

    ll res = 1;
    for(int i=2; i<1e6+1; i++){
        res *= (ll)pow(i, b.at(i));
        res %= mod;
    }
    ll ans = 0;
#if 1
    for(int i=0; i<n; i++){
        ans += res * modinv(a.at(i), mod) % mod;
        ans %= mod;
    }
#endif
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define ALL(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int>;
using vs = vector<string>;
using vb = vector<bool>;
using vll = vector<long long>;
using vpii = vector<pair<int,int>>;
using vivi = vector<vector<int>>;
using vbvb = vector<vector<bool>>;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const int mod = 1000000007;
const int inf = 1001001001;



int main(void) {
  ll n;
  cin >> n;
  ll cnt = 0;
  ll sum = 0;
  rep(i,500000000){
    if(i>n)break;
    if(i%3 && i%5){
      sum+=i;
      
    }
  }
  cout << sum << endl;
    
}






Measured memory_bytes: 3636
#include <bits/stdc++.h>
#ifdef DEMETRIO
#define deb(...) fprintf(stderr,__VA_ARGS__)
#define deb1(x) cerr << #x << " = " << x << endl
#else
#define deb(...) 0
#define deb1(x) 0
#endif
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define SZ(x) ((int)x.size())
#define MOD 1000000007
using namespace std;
typedef long long ll;

int n,m;
int dp[302][302][302];

int f(int m, int k, int b){
	if(dp[m][k][b]>=0)return dp[m][k][b];
	int r=0;
	if(m==0)r=!k&&!b;
	else {
		r=(1LL*(n-k)*f(m-1,k-b,0))%MOD;
		r+=(1LL*b*f(m-1,k,b))%MOD;r%=MOD;
		if(k-b){r+=(1LL*(k-b)*f(m-1,k,b+1))%MOD;r%=MOD;}
	}
	return dp[m][k][b]=r;
}

int main(){
	scanf("%d%d",&n,&m);
	memset(dp,-1,sizeof(dp));
	printf("%d\n",f(m,n-1,0));
	return 0;
}

Measured memory_bytes: 107904
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String x = sc.next();
        int len = x.length();
        int res = 0;
        int numS = 0;
        for(int i=0;i<len;i++){
            if(x.charAt(i)=='S') numS++;
            else{
                if(numS>0){
                    numS--;
                    res += 2;
                }
            }
        }
        System.out.println(len-res);
    }
}


Measured memory_bytes: 26532
import java.util.*;
import java.io.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        int n = sc.nextInt();
        int c = sc.nextInt();
        int[][] grid = new int[3][c];
        int[][] map = new int[c][c];
        for(int i = 0; i < c; i++){
            for(int j = 0; j < c; j++){
                map[i][j] = sc.nextInt();
            }
        }
        for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++){
                grid[(i+j)%3][sc.nextInt()-1]++;
            }
        }
        long ans = Long.MAX_VALUE;
        for(int i = 0; i < c; i++){
            long ans1 = calc(map,grid,0,i,c);
            for(int j = 0; j < c; j++){
                if(i == j) continue;
                long ans2 = calc(map,grid,1,j,c);
                for(int k = 0; k < c; k++){
                    if(i == k || j == k) continue;
                    long ans3 = calc(map,grid,2,k,c);
                    ans = Math.min(ans,ans1+ans2+ans3);
                }
            }
        }
        System.out.println(ans);
    }
    
    public static long calc(int[][] map, int[][] grid, int mod, int change, int c){
        long ret = 0;
        for(int j = 0; j < c; j++){
            ret += map[j][change] * grid[mod][j];
        }
        return ret;
    }
}

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

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

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

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

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

    public double nextDouble() {
         return Double.parseDouble(next());
    }
    
    public String[] nextArray(int n) {
        String[] a = new String[n];
        for (int i = 0; i < n; i++)
            a[i] = next();
        return a;
    }

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

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


Measured memory_bytes: 44036
#include<bits/stdc++.h>
using namespace std;
 
 
int main(){

    long long A,V,B,W,T;
    cin >> A >> V >> B >> W >> T;

    if(abs(A-B) + W*T <= V*T){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }

}

Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

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

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

int main(void) {
  long A, B, C, D;
  cin >> A >> B >> C >> D;
  long CD, tmp_c, tmp_d, tmp_cd;
  CD = lcm(C, D);
  tmp_c = B / C - (A - 1) / C;
  tmp_d = B / D - (A - 1) / D;
  tmp_cd = B / CD - (A - 1) / CD;
  //cout << CD << endl << tmp_c << endl << tmp_d << endl << tmp_cd << endl;
  cout << B - A + 1 - (tmp_c + tmp_d - tmp_cd) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main() {
ll n,x;
cin >> n >> x;
ll l[n];
ll d[n+1];

for(ll i=0;i<n;i++){
    cin >>l[i];
}
d[0]=0;
for(ll i=0;i<n;i++){
d[i+1]=d[i]+l[i];
}
ll ans=0;
for(ll i=0;i<n+1;i++){
    if(d[i]<=x){
        ans++;
    }
}
cout << ans << endl;
}


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

string s;
int n;
long long int resultado = 0, contador = 0;
long long int cr, cg, cb;

int main()
{
  cin >> n >> s;
  for (int i = 0; i < n; ++i)
  {
    for (int j = i + 1; j < n; ++j)
    {
      int k = j + (j - i);
      if (k > n - 1)
        break;
      else if (s[i] != s[k] && s[i] != s[j] && s[j] != s[k])
        contador++;
    }
  }

  for (int i = 0; i < n; ++i)
  {
    if (s[i] == 'R')
      cr++;
    else if (s[i] == 'G')
      cg++;
    else
      cb++;
  }
  resultado = cr * cg * cb - contador;
  cout << resultado << endl;

  return 0;
}


Measured memory_bytes: 3628
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
#include <numeric>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
//#define mod 998244353
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pint> vpint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=5050;
//templete
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(auto i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

typedef int Weight;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) { }
};
bool operator < (const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

typedef vector<Weight> Array;
typedef vector<Array> Matrix;
void shortestPath(const Graph &g, int s,
    vector<Weight> &dist, vector<int> &prev) {
  int n = g.size();
  dist.assign(n, INF); dist[s] = 0;
  prev.assign(n, -1);
  priority_queue<Edge> Q; // "e < f" <=> "e.weight > f.weight"
  for (Q.push(Edge(-2, s, 0)); !Q.empty(); ) {
    Edge e = Q.top(); Q.pop();
    if (prev[e.dst] != -1) continue;
    prev[e.dst] = e.src;
    FOR(f,g[e.dst]) {
      if (dist[f->dst] > e.weight+f->weight) {
        dist[f->dst] = e.weight+f->weight;
        Q.push(Edge(f->src, f->dst, e.weight+f->weight));
      }
    }
  }
}
vector<int> buildPath(const vector<int> &prev, int t) {
  vector<int> path;
  for (int u = t; u >= 0; u = prev[u])
    path.push_back(u);
  reverse(path.begin(), path.end());
  return path;
}

int N;
int num(int i, int a){
	return i+N*a;
}
int main() {
	cin>>N;
	int M;
	cin>>M;
	Graph G;
	for(int i=0;i<N*3;i++){
		Edges E;
		G.pb(E);
	}
	for(int i=0;i<M;i++){
		int s, t;
		cin>>s>>t;
		s--;
		t--;
		for(int j=0;j<3;j++){
			G[num(s,j)].pb(Edge(num(s,j), num(t,(j+1)%3), 1));
		}
	}

	int S,T;
	cin>>S>>T;
	S--;
	T--;
	vector<Weight> dist;
	vector<int> prev;

	shortestPath(G, num(S, 0), dist, prev);

	if(dist[num(T,0)]==INF)
		cout<<-1<<endl;
	else
		cout<<dist[num(T,0)]/3<<endl;
	return 0;
}

Measured memory_bytes: 20584
import java.util.Scanner;
     
    public class Main { //クラス名はMain
        public static void main(String[] args) {
            //コード
          Scanner sc = new Scanner(System.in);
    	  String n = sc.nextLine();
          boolean b1 = false;
          boolean b2 = false;
          boolean b3 = false;
          boolean b4 = false;
          String[] strArray = n.split(" ");
                //day
                  switch (strArray[1]) {
            		case "30":
                	b1 = true;
                	break;
            		case "31":
                	b2 = true;
                	break;
           			case "28":
                	b3 = true;
                	break;
            		default:
                    b1 = false;
               		b2 = false;
                    b3 = false;
                  }
            
            switch (strArray[0]) {
              case "4":
              case "6":
              case "9":
              case "11":
                if (b1 == true){
                	b4 = true;
                }
                	break;
            		case "1":
                case "3":
                case "5":
                case "7":
                case "8":
                case "10":
                case "12":
                	if (b2 == true){
                	b4 = true;
                }
                	break;
           			case "2":
                	if (b3 == true){
                	b4 = true;
                }
                break;
            		default:
               		b4 = false;
                    break;
           }
          if (((b1 == true) || (b2 == true) || (b3 == true)) && b4 == true){
           System.out.println("1");
          }
          else{
            System.out.println("0");
          }
        }
    }

Measured memory_bytes: 23252
#include<bits/stdc++.h>
using namespace std;
long long l,r,mod=2019,ans=1e5,t1,t2;
int main(){
    cin>>l>>r;
    if((r/mod)!=(l/mod)) cout<<0;
    else
	{
        l%=mod,r%=mod;
        t1=min(l,r),t2=max(l,r);
        for(long long i=t1;i<=t2;i++)
            for(long long j=i+1;j<=t2;j++)
                ans=min(ans,i*j%mod);
        cout<<ans;
    }
	return 0;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<char, ll> pcl;

#define m0(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
#define rep(i, n) for(int i = 0; i < (n); i++)
#define asort(x) sort(all(x));
#define dsort(x, t) sort(x.begin(), x.end(), greater<t>());
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define MINS(m, s) m.insert(mp(s, 1));
#define MFIN(m, s) m.find(s) != m.end()
#define mp make_pair
#define pb push_back
#define INF (1 << 29)
const int mod = 1000000007;

int main() {
    ll n, a, b, cnt;
    cin >> n;
    string str;
    cnt = 0;
    while(n > 0) {
        b = n % 26;
        a = n / 26;

        if(b == 0) {
            str += 'z';
            a--;
        } else {
            str += 'a' + b - 1;
        }
        cnt++;
        n = a;
    }
    reverse(all(str));
    cout << str << endl;

    return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 998244353
#define INF2 1000000000000000000
#define int long long 

int dp[3010][3010];
int Mul(int a, int b) {
	return ((a % mod) * (b % mod)) % mod;
}
signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    dp[C][D] = 1;
    RREP(i, C - 1, 0) dp[i][D] = Mul(dp[i + 1][D], D);
    RREP(i, D - 1, 0) dp[C][i] = Mul(dp[C][i + 1], C);
    // rep(i, C) {
    //     rep(j, D) {
    //         cout << dp[i + 1][j + 1] << " ";
    //     }
    //     cout << endl;
    // }

    RREP(i, C - 1, 1) {
        RREP(j, D - 1, 1) {
            int tmp1 = Mul(dp[i + 1][j], j);
            int tmp2 = Mul(dp[i][j + 1], i);
            int tmp3 = Mul(Mul(dp[i + 1][j + 1], i), j);
            //cout << i << " " << j << " " << tmp1 << " " << tmp2 << endl;
            dp[i][j] = (tmp1 + tmp2 - tmp3 + mod) % mod;
        }
    }
    // rep(i, C) {
    //     rep(j, D) {
    //         cout << dp[i + 1][j + 1] << " ";
    //     }
    //     cout << endl;
    // }
    cout << dp[A][B] << endl;


    return 0;
}


Measured memory_bytes: 74060
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define endl "\n"
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
    ll n, c, k;
    cin >> n >> c >> k;
    vector<ll> arr(n, 0);
    for(auto& val: arr) {
        cin >> val;
    }
    sort(arr.begin(), arr.end());
    ll ans = 0, last = -1e9;
    ll used = 0;
    for(int i = 0; i < n; i++) {
        if (used >= c || arr[i]-last > k) {
            ans += 1;
            last = arr[i];
            used = 1;
        } else {
            used += 1;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3936
/*
* Note: This template uses some c++11 functions , so you have to compile it with c++11 flag.
*       Example:-   $ g++ -std=c++11 c++Template.cpp
*
* Author : Akshay Pratap Singh
* Handle: code_crack_01
*
*/
 
/********   All Required Header Files ********/
#include <iostream>
#include <string>
#include <vector>
// #include <unordered_map>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <climits>

using namespace std;

/*******  All Required define Pre-Processors and typedef Constants *******/
#define SCD(t) scanf("%d",&t)
#define SCLD(t) scanf("%ld",&t)
#define SCLLD(t) scanf("%lld",&t)
#define SCC(t) scanf("%c",&t)
#define SCS(t) scanf("%s",t)
#define SCF(t) scanf("%f",&t)
#define SCLF(t) scanf("%lf",&t)
#define MEM(a, b) memset(a, (b), sizeof(a))
#define FOR(i, j, k, in) for(int i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for(int i=j ; i>=k ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)
#define IN(A, B, C) assert( B <= A && A <= C)
#define MP make_pair
#define PB push_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define read(type) readInt<type>()
typedef long long int ll;
typedef unsigned long long int  ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<pii> vii;
typedef vector<ll> vll;
typedef vector<vi> vvi;

#define UNION_FIND_MAX_N 100005
int par[UNION_FIND_MAX_N];
int ran[UNION_FIND_MAX_N];

void init(int n){
    for(int i=0; i<n; i++){
        par[i] = i;
        ran[i] = 0;
    }
}

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

void unite(int x, int y){
    x = find(x);
    y = find(y);
    if( x == y ) return;

    if( ran[x] < ran[y] ){
        par[x] = y;
    } else {
        par[y] = x;
        if( ran[x] == ran[y] ) ran[x]++;
    }
}

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

int main() {

    int N, M; cin >> N >> M;
    vi p(N);
    REP(i, N) {
        cin >> p[i];
        p[i]--;
    }

    init(N);

    int x, y;
    REP(i, M) {
        cin >> x >> y;
        x--;
        y--;
        unite(x, y);
    }

    vi used(N, 0);

    int res = 0;
    REP(i, N) {
        if( same(i, p[i]) ) res++;
        else if ( i == p[i] ) res++;
    }

    cout << res << endl;
    
    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<iterator>
#include<vector>
#include<string>
#include<map>

using namespace std;


#define mod(cans) cans%10**9+7
#define cin_pl(x,y) for(int i=0;i<x;i++){cin>>y[i];}
#define pl_twin(x,y,z) for(int i=0;i<x;i++){cin>>y[i]>>z[i];}
#define debug(x) cout << "Debug" << x << "\n"
#define rep(i,n) for(int i=0;i<n;i++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define st(s) size_t size = s.length()
#define prians(Answer) cout<<Answer<<"\n"
#define com_div(x,Co) for(int i=1;i<x+1;i++){if(x%i==0){Co++;}}
#define TF(X) X==1?cout<<"Yes\n":cout<<"No\n"
#define elcon else{continue;}

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<vector<int>> matrix;
typedef pair<int,int> pr;
typedef vector<pr> vpt;
typedef greater<int> gi;

int main()
{
    int n;
    cin>>n;
    vi a(n);
    rep(i,n)cin>>a[i];
    int tmp[2];
    sort(rall(a));
    tmp[0]=a[0];
    sort(all(a));
    tmp[1]=a[0];
    cout<<abs(tmp[0]-tmp[1]);
}

Measured memory_bytes: 256
(* 素集合データ構造 *)
module UnionFind = struct
  module Make (Set : sig
    type t
    val union : t -> t -> t
  end) : sig
    type t
    (* 与えられた集合から素集合データ構造を作る *)
    val make : Set.t -> t
    (* 与えられた素集合同士が同一かどうか判定する *)
    val equal : t -> t -> bool
    (* 与えられた素集合同士を合併する *)
    val unite : t -> t -> unit
    (* 与えられた素集合に属する要素を列挙する *)
    val elements : t -> Set.t
  end = struct
    type t = node ref
    and node =
      | Root of int * Set.t (* 木の高さと要素の集合の二つ組 *)
      | Link of t

    let make s = ref @@ Root (0, s)

    let rec find uf =
      match !uf with
      | Root _ -> uf
      | Link parent ->
          let root = find parent in
          uf := Link root; root

    let equal uf uf' = find uf == find uf'

    let unite uf uf' =
      let root = find uf in
      let root' = find uf' in
      if root != root' then begin
        let Root (rank, elts) = !root in
        let Root (rank', elts') = !root' in
        let root, root' =
          if rank <= rank'
          then root, root'
          else root', root in
        root := Link root';
        root' := Root (rank' + (if rank = rank' then 1 else 0), Set.union elts elts')
      end

    let elements uf =
      match find uf with
      | { contents = Root (_, elts) } -> elts
  end
end

module UF = UnionFind.Make (struct
  type t = int * int
  let union (w, b) (w', b') = (w + w', b + b')
end)

let () = Scanf.scanf "%d %d\n" @@ fun h w ->
  let ss = Array.init h @@ fun _ -> Scanf.scanf "%s\n" @@ fun s -> s in
  let uf =
    Array.init h @@ fun i ->
      Array.init w @@ fun j ->
        UF.make @@ if ss.(i).[j] = '.' then (1, 0) else (0, 1) in
  for i = 0 to h - 1 do
    for j = 0 to w - 2 do
      if ss.(i).[j] <> ss.(i).[j + 1] then
        UF.unite uf.(i).(j) uf.(i).(j + 1)
    done
  done;
  for i = 0 to h - 2 do
    for j = 0 to w - 1 do
      if ss.(i).[j] <> ss.(i + 1).[j] then
        UF.unite uf.(i).(j) uf.(i + 1).(j)
    done
  done;
  Printf.printf "%d\n" @@
  Array.fold_left (Array.fold_left ( + )) 0 @@
  Array.init h @@ fun i ->
    Array.init w @@ fun j ->
      if ss.(i).[j] = '.'
      then 0
      else fst @@ UF.elements uf.(i).(j)


Measured memory_bytes: 17920
#include <bits/stdc++.h>
#define ll long long
#define maxn 100005 /*rem*/
#define mod 998244353
#define db double
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define pi pair<int, int>
#define fi first
#define se second
using namespace std;
ll ksm(ll a, ll b) {
   if (!b) return 1;
   ll ns = ksm(a, b >> 1);
   ns = ns * ns % mod;
   if (b & 1) ns = ns * a % mod;
   return ns;
}
int n, s;
ll ans;
int x[maxn];
ll p[maxn];
ll ttm[maxn];
int ls[maxn], pp[maxn];
void caltm(int a) {
	if (!ls[a]) return ;
	else if (ttm[a]) return ;
	else caltm(ls[a]), ttm[a] = ttm[ls[a]] + pp[a];
}
int main() {
	cin >> n >> s;
	for (int i = 1; i <= n; i++)
		scanf("%d%d", &x[i], &p[i]);
	int l = 1, r = n;
	while (1) {
		if (s <= x[l] || s >= x[r]) {
			for (int i = l; i <= r; i++)
				ttm[i] = abs(s - x[i]);
			break;
		}
		if (p[l] >= p[r]) {
			ls[r] = l, pp[r] = x[r] - x[l];
			p[l] += p[r], r--;
		}
		else {
			ls[l] = r, pp[l] = x[r] - x[l];
			p[r] += p[l], l++;
		}
	}
	for (int i = 1; i <= n; i++)
		caltm(i), ans = max(ans, ttm[i]);//, cout << ttm[i] << ' ' << ls[i] << ' ' << pp[i] << endl;
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 2816
import sys
input = sys.stdin.buffer.readline

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()

import heapq

def main():
	t=II()
	for _ in range(t):
		n=II()
		L=[]
		R=[]
		ans=0
		for _ in range(n):
			k,l,r=MI()
			if l>=r:
				ans+=r
				L.append((k,l-r))
			else:
				ans+=l
				R.append((n-k,r-l))
		L.sort()
		R.sort()
		#print(L,R,ans)

		Q=[]
		heapq.heapify(Q)

		for k,v in L:
			ans+=v
			heapq.heappush(Q,v)
			if len(Q)>k:
				#print(Q,k,ans)
				vv=heapq.heappop(Q)
				ans-=vv

		Q=[]
		heapq.heapify(Q)

		for k,v in R:
			ans+=v
			heapq.heappush(Q,v)
			if len(Q)>k:
				#print(Q,k,ans)
				vv=heapq.heappop(Q)
				ans-=vv
		print(ans)






if __name__ == "__main__":
	main()


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

int main() {
    int n;
    cin >> n;
    vector<int> d(n,0);
    rep(i, n-1) {
        int ai;
        cin >> ai;
        d[ai-1]++;
    }
    
    rep(i, n)
        cout << d[i] << endl;
    
    return 0;
}


Measured memory_bytes: 4060
#include <iostream>      // cout, endl, cin
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <cmath>         // sqrt
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <bits/stdc++.h> // isupper, islower, isdigit, toupper, tolower
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, n) for (int i = (a); i < (n); i++)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> Pl;
typedef pair<int, int> P;
typedef tuple<ll, ll, string> Tlls;

// Greatest Common Divisor (最大公約数)
ll gcd(ll a, ll b)
{
  // Eucledean algorithm
  while (a)
  {
    if (a < b)
    {
      std::swap(a, b);
    }
    a %= b;
  }
  return b;
}

// Least Common Multiple 最小公倍数
ll lcm(ll a, ll b)
{
  return a / gcd(a, b) * b;
}

// key: value of prime factor素因数分解
// value: number of prime factor
map<ll, ll> prime_factorization(ll n)
{
  map<ll, ll> prime_factors;
  for (ll i = 2; i * i <= n; i++)
  {
    while (n % i == 0)
    {
      prime_factors[i]++;
      n /= i;
    }
  }
  if (n != 1)
    prime_factors[n] = 1;
  return prime_factors;
}

// 約数リスト約数の列挙
vector<ll> get_divisors(const ll n)
{
  vector<ll> divs;
  for (ll i = 1; i < (ll)sqrt((ld)n) + 1; i++)
  {
    if (n % i == 0)
    {
      divs.push_back(i);
      if (i != n / i)
      {
        divs.push_back(n / i);
      }
    }
  }

  // 必要に応じてソート
  // sort(divs.begin(), divs.end());

  return divs;
}

int main()
{
  ll N, M;
  cin >> N >> M;
  vector<ll> A(N);
  ll ans = 0;
  rep(i, N)
  {
    cin >> A.at(i);
    ans += A.at(i);
  }
  if (N - ans < 0)
  {
    cout << -1 << endl;
  }
  else
  {
    cout << N - ans << endl;
  }

  return 0;
}


Measured memory_bytes: 11244
#include<iostream>
#include<cstdio>
#include<string>
#include<map>
using namespace std;
map<string,int> mp;
int main(){
	int n;
	cin>>n;
	string now,last;
	cin>>last;
	mp[last]=1;
	for(int i=2;i<=n;++i){
		cin>>now;
		if(now[0]!=last[last.length()-1]){
			cout<<"No";
			return 0;
		}
		if(mp[now]){
			cout<<"No";
			return 0;
		}
		mp[now]=1;
		last=now;
	}
	cout<<"Yes";
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>//printf("%.*f\n",*********);
#include<vector>//s.erase(n),vector
#include<algorithm>//next_permutation
#include<set>
#include<string>//char('a'=32+'A')
//to_string,string,substr
#include<sstream>
#include<complex>
#include<time.h>
#include<random>
#include<cmath>//min,max
#include<math.h>
#include<queue>
#include<time.h>
#include<iomanip>
#include<locale>
#include<utility>//swap

#define rt "\n"
#define rep(i,n) for(int i=0;i<n;i++)
#define rop(i,n) for(int i=1;i<=n;i++)//start==1
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define drop(i,n) for(int i=n;0<i;i--)//end==1
#define yes(ans) if(ans)cout<<"yes"<<rt;else cout<<"no"<<rt;
#define Yes(ans) if(ans)cout<<"Yes"<<rt;else cout<<"No"<<rt;
#define YES(ans) if(ans)cout<<"YES"<<rt;else cout<<"NO"<<rt;
#define Yay(ans) if(ans)cout<<"Yay!"<<rt;else cout<<":("<<rt;
#define sec(a,b,ans) if(ans)cout<<a<<rt;else cout<<b<<rt;
#define vcin(a,n) rep(i,n)cin>>a[i];//vcin(配列名),(繰り返し回数)
#define sort(s) sort(s.begin(),s.end())//昇順
#define reve(s) reverse(s.begin(),s.end())//反転
#define please return
#define AC 0
#define rapid_pleaseAC_fast cin.tie(0);ios::sync_with_stdio(false)
#define pi 3.1415926535897932384626//pi
#define nine 1000000000//10^9

using namespace std;
typedef vector<int> vint;
typedef long double ldouble;
typedef vector<string> vstr;
typedef vector<char> vchar;
typedef vector<double> vdou;
typedef vector<double> vdouble;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<char>> vvchar;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<string>> vvstr;
typedef vector<vector<bool>> vvbool;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;

long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

long long LCM(long long a, long long b) {
	return a * b / GCD(a, b);
}

unsigned GetDigit(unsigned num) {
	return std::to_string(num).length();
}

int tow(int n) {//2のn乗
	if (n == 0)return 1;
	int x = tow(n / 2);
	x *= x;
	if (n % 2 == 1)x *= 2;
	return x;//@domino
}

int KETA(int n) { //Sum of Each Digit
	int sum = 0;
	while (n > 0) {
		sum += n % 10; n /= 10;
	}
	return sum;
}

unsigned ND(unsigned num) {//Number of Digits
	return std::to_string(num).length();//outmax=10
}

bool KIBN(string s) {
	rep(i, s.size() / 2) {
		if (s[i] != s[s.size() - 1 - i])return false;
	}
	return true;
}

/*

 (char)toupper(a[n])=文字列のn文字目を大文字で出力

  pow(a,b)=aのb乗

  */

int main(void) {

	int a, b;
	cin >> a >> b;
	if (a + b >= 10) {
		cout << "error" << rt;
	}
	else {
		cout << a + b << rt;
	}

	please AC;
}
//参考：---


Measured memory_bytes: 256
(n, l) = gets.split.map {|x| x.to_i}
a = gets.split.map {|x| x.to_i}
a.unshift(0)

#p a

n.times { |i|
  if (a[i+1] >= l)
    puts "Possible"
    1.upto(i) { |j|
      puts j
    }
    (n-1).downto(i+1) { |j|
      puts j
    }
    exit
  end
  if (a[i] + a[i+1] >= l)
    puts "Possible"
    1.upto(i-1) { |j|
      puts j
    }
    (n-1).downto(i+1) { |j|
      puts j
    }
    puts i
    exit
  end
}
puts "Impossible"


Measured memory_bytes: 12180
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<unordered_map>
#include<queue>
#include<iomanip>
#include<math.h>
#include<bitset>
#include<cassert>
#include<random>
#include<time.h>
using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
#define MOD 1000000007LL
#define INF 1000000000LL
#define EPS 1e-10
#define FOR(i,n,m) for(ll i=n;i<(ll)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v)  sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back

/* --------------------------------------- */
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n, k;
	cin >> n >> k;
	vector<ll> a(n);
	REP(i,n) cin >> a[i];
	vector<ll> acm(n, 0);
	acm[0] = a[0];
	FOR(i,1,n) acm[i] = acm[i - 1] + a[i];
	vector<ll> v;
	REP(i,n) FOR(j,i,n) {
		ll tmp = acm[j];
		if(i > 0) tmp -= acm[i - 1];
		v.pb(tmp);
	}
	bitset<50> ans(0);
	for(ll i = 49; i >= 0; i--) {
		ll cnt = 0;
		vector<ll> nv;
		REP(j,v.size()) {
			bitset<50> bi(v[j]);
			if(bi[i]) {
				cnt++;
				nv.pb(v[j]);
			}
		}
		if(cnt >= k) {
			ans[i] = 1;
			REP(j,nv.size()) v[j] = nv[j];
			v.resize((ll)nv.size());
		}
	}
	cout << ans.to_ullong() << endl;
	return 0;
}
/* --------------------------------------- */


Measured memory_bytes: 6256
#ifdef LOCAL111
#else
	#define NDEBUG
#endif
#include <bits/stdc++.h>
const int INF = 1e8;
using namespace std;

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define RBP(i,a) for(auto& i : a)
#ifdef LOCAL111
	#define DEBUG(x) cout<<#x<<": "<<(x)<<endl
#else
	#define DEBUG(x) true
#endif
#define F first
#define S second
#define SNP string::npos
#define WRC(hoge) cout << "Case #" << (hoge)+1 << ": "
#define rangej(a,b,c) ((a) <= (c) and (c) < (b))
#define rrangej(b,c) rangej(0,b,c)
template<typename T> void pite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;}
template<typename T> bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;}

typedef pair<int,int> P;
typedef long long int LL;
typedef unsigned long long ULL;
typedef pair<LL,LL> LP;

void ios_init(){
	//cout.setf(ios::fixed);
	//cout.precision(12);
#ifdef LOCAL111
	return;
#endif
	ios::sync_with_stdio(false); cin.tie(0);	
}

const LL mod = 2;

//res.first*a+res.second*b == 1 となるresを返す (a,bは互いに素)
pair<long long, long long> extgcd(long long a,long long b)
{
	if(b==1){
		return pair<long long, long long>(0,1);
	}
	pair<long long, long long> t=extgcd(b,a%b);
	return pair<long long, long long>(t.second,t.first-a/b*t.second);
}

//modの逆元を返す
long long inverse(long long a,long long modl = mod)
{
	return (extgcd(modl,a).second+modl)%modl;
}

//xCyを返す
long long Cinv(long long x, long long y, const long long modl){
	long long n = 1 ,r = 1;
	for(int i = 0; i < y; i++){
		n = n*(i+1)%modl;
		r = r*(x-i)%modl;
	}
	return r*inverse(n,modl)%modl;
}

int main()
{
	ios_init();
	const LL mod = 1e9+7;
	int h,w,a,b;
	cin >> h >> w >> a >> b;
	w--; h--; a--; b--;
	b++;
	LL ans = 0;
	LL c1 = -1, c2 = -1;
	REP(i,h-a){
		if(i == 0){
			c1 = Cinv(b-1+i,i,mod);
			c2 = Cinv(h-i+w-b,w-b,mod);
		}else{
			c1 = c1*(b-1+i)%mod*inverse(i,mod)%mod;
			c2 = c2*inverse(h-(i-1)+w-b,mod)%mod*(h-i+1)%mod;
		}
		ans += c1*c2%mod;
		ans %= mod;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
using namespace std;
 
typedef pair<int,int> P;
const int MAX_W = 10;
 
int w, h, ans;
bool memo[MAX_W][MAX_W];
int dx[4] = {0,0,-1,1};
int dy[4] = {-1,1,0,0};
char C[3] = {'R','G','B'};
int c_to_n[256] = {0};
 
void debug(vector<string>& v, vector<string>& v_, int cnt=0){
    cout << "[debug] cnt:" << cnt-1 << " -> " << cnt << endl;
    cout << "before:" << endl;
    for(int y=0 ; y < h ; y++ ){
        cout << v[y] << endl;
    }
    cout << "after:" << endl;
    for(int y=0 ; y < h ; y++ ){
        cout << v_[y] << endl;
    }
    cout << endl;
}
 
bool check(vector<string>& v, char c){
    for(int y=0 ; y < h ; y++ ){
        for(int x=0 ; x < w ; x++ ){
            if( v[y][x] != c ){
                return false;
            }
        }
    }
    return true;
}
 
void dfs(int x, int y, char c, vector<string>& v, vector<P>& vp){
    memo[y][x] = true;
    if( v[y][x] == c ){
        vp.push_back( P(x,y) );
    }
     
    for(int i=0 ; i < 4 ; i++ ){
        int mx = x + dx[i];
        int my = y + dy[i];
        if( mx < 0 || my < 0 || w <= mx || h <= my ) continue;
        if( !memo[my][mx] && v[my][mx] == c ){
            dfs(mx,my,c,v,vp);
        }
    }
}
 
void solve(vector<string>& v, int cnt){
    if( ans < cnt ) return;
    if( check(v,v[0][0]) ){
        ans = min( ans , cnt );
        return ;
    }
    for(int y=0 ; y < h ; y++ ){
        for(int x=0 ; x < w ; x++ ){
            memo[y][x] = false;
        }
    }
    vector<P> vp;
    dfs(0,0,v[0][0],v,vp);
    bool color[3] = {false};
    for(int i=0 ; i < vp.size() ; i++ ){
        for(int j=0 ; j < 4 ; j++ ){
            int mx = vp[i].first + dx[j];
            int my = vp[i].second + dy[j];
            if( mx < 0 || my < 0 || w <= mx || h <= my ) continue;
            if( v[0][0] == v[my][mx] ) continue;
            color[ c_to_n[v[my][mx]] ] = true;
             
            if( (color[0] && color[1]) || (color[0] && color[2]) || (color[1] && color[2]) ){
                break;
            }
        }
        if( (color[0] && color[1]) || (color[0] && color[2]) || (color[1] && color[2]) ){
            break;
        }
    }
     
    for(int i=0 ; i < 3 ; i++ ){
        if( !color[i] ) continue;
        //if( v[0][0] == C[i] ) continue;
         
        vector<string> next = v;
        for(int j=0 ; j < vp.size() ; j++ ){
            next[ vp[j].second ][ vp[j].first ] = C[i];
        }
        if( cnt+1 <= ans ){
            //debug(v,next,cnt+1);
            solve(next,cnt+1);
        }
    }
}
 
int main(){
    c_to_n['R'] = 0;
    c_to_n['G'] = 1;
    c_to_n['B'] = 2;
    while( cin >> w >> h , w || h ){
        vector<string> v(h);
        for(int y=0 ; y < h ; y++ ){
            v[y] = string(w,' ');
            for(int x=0 ; x < w ; x++ ){
                cin >> v[y][x];
            }
        }
        ans = min(w*h-1,17);
        solve(v,0);
        cout << ans << endl;
    }
}

Measured memory_bytes: 1252
#include <iostream>
#include <iomanip>
#define PI 3.14159265359
using namespace std;

int main(void) {
	double r;
	cin >> r;
	cout << fixed << setprecision(6) << r * r * PI << ' ' << fixed << setprecision(6) << (r + r) * PI << endl;
	return 0;
}

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

int main()
{
    string S;
    cin>>S;
    short int len = S.length(),i,j,count=0;
    for(i=0,j=len-1;i<j;i++,j--)
    {
        if(S[i]!=S[j])
        count++;
    }
    cout<<count;
    return 0;
}

Measured memory_bytes: 256
from collections import Counter
import sys

def input():
    return sys.stdin.readline().strip()
def combi(num):
    return num * (num - 1) // 2
def main():
    N = int(input())
    A = list(map(int,input().split()))
    counterdic = Counter(A)
    ma = 0
    for value in counterdic.values():
        ma += combi(value)
    for i in A:
        print(ma-combi(counterdic[i])+combi(counterdic[i]-1))
if __name__ == "__main__":
    main()

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


int main() {

    int n; cin >> n;
    int Min = 101;
    int p = 0;
    vector<int> h(n);
    rep(i,n) cin >> h[i];
    int ans = 0;
    bool flag = false;

    while(1) {
        Min = 101;
        p = 0;
        rep(i, n) {
            if(h[i] == 0){
                for(int j = p; j < i; j ++){
                      if(Min != 101) h[j] -= Min;
                }
                if(Min != 101)ans += Min;
                p = i+1;
                Min = 101;

            }else{
                Min = min(Min,h[i]);
            }

            if(i == n-1){
                for(int j = p; j <= i; j ++){
                    if(Min != 101) h[j] -= Min;
                }
                if(Min != 101) ans += Min;
            }

        }

        for(int k =  0; k < n; k ++){
            if(h[k] != 0) break;
            if(k == n-1) flag = true;
        }

        if(flag) break;
    }

    cout << ans;

    return 0;
}











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


int main() {
    int N; cin >> N;
    int K; cin >> K;
    string S; cin >> S;

    int ans=0;
    for (int i = 0; i < N - 1; i++){
        if (S[i] == S[i+1])
            ans++;
    }
    cout << min(N - 1, ans + (2 * K)) << endl;

    return 0;
}


Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
    static char[] c;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        StringBuilder sb = new StringBuilder(sc.next());
        sb.reverse();
        c = sb.toString().toCharArray();
        String str = "";
        boolean ok = true;
        for (int i = 0; i < c.length; i++) {
            if (str.equals("dream") || str.equals("dreamer")
            || str.equals("erase") || str.equals("eraser")) {
                str = "" + c[i];
            } else if (str.length() > 7) {
                ok = false;
                break;
            } else {
                str = c[i] + str;
            }
        }
        if (str.equals("dream") || str.equals("dreamer")
                || str.equals("erase") || str.equals("eraser")) {
        } else {
            ok = false;
        }
        System.out.println(ok?"YES":"NO");
    }
}

Measured memory_bytes: 38508