akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
using namespace std;

int N;
vector<vector<long long>> A;
vector<vector<long long>> G;
vector<vector<long long>> bell;

int main() {
	cin >> N;
	A.resize(N, vector<long long>(N, 0));
	G.resize(N, vector<long long>(N, -1));   //存在しない
	for (int y = 0; y < N; y++) {
		for (int x = 0; x < N; x++) {
			cin >> A[x][y];
		}
	}
	for (int x = 0; x < N; x++) {
		for (int y = x + 1; y < N; y++) {
			bool flag = false;
			for (int k = 0; k < N; k++) {
				if (A[x][k] == 0 || A[k][y] == 0)continue;
				if (A[x][k] + A[k][y] == A[x][y]) {
					flag = true;
					break;
				}
			}
			if (!flag) {
				G[x][y] = A[x][y];
				G[y][x] = A[y][x];
			}
		}
	}
	bell.resize(N, vector<long long>(N, -1));   //存在しない
	for (int x = 0; x < N; x++) {
		for (int y = 0; y < N; y++) {
			if (G[x][y] != -1)bell[x][y] = G[x][y];
			else if (x == y)bell[x][y] = 0;
		}
	}
	for (int k = 0; k < N; k++) {
		for (int x = 0; x < N; x++) {
			for (int y = 0; y < N; y++) {
				if (bell[x][k] == -1 || bell[k][y] == -1)continue;
				if (bell[x][y] == -1)bell[x][y] = bell[x][k] + bell[k][y];
				else bell[x][y] = min(bell[x][y], bell[x][k] + bell[k][y]);
			}
		}
	}
	long long ans = 0;
	bool flag = false;
	for (int x = 0; x < N; x++) {
		for (int y = 0; y < N; y++) {
			if (G[x][y] != -1)ans += G[x][y];
			if (bell[x][y] != A[x][y]) {
				flag = true;
				break;
			}
		}
	}
	if (flag)cout << -1 << endl;
	else cout << ans / 2 << endl;
	return 0;
}

Measured memory_bytes: 2432
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

int main() {
	int M, D;
	cin >> M >> D;
	int ans = 0;
	for(int i = 1; i < M+1; i++){
		for(int j = 1; j < D+1; j++){
			int d1=j%10;
			int d2=j/10;
			if(d1>=2&&d2>=2&&d1*d2==i){
				ans++;
			}
		}
	}
	cout << ans << endl;
}

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

int main() {
	long long A,B,K;
    cin>>A>>B>>K;
	long long diff=A-K;
	if(diff>=0){
		cout<<diff<<" "<<B<<endl;
		return 0;
	}
	else{
      	if(B-abs(diff)>=0){
		cout<<0<<" "<<B-abs(diff)<<endl;
        }
      	else{
        cout<<0<<" "<<0<<endl;
	}
}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005
ll MOD = 1000000007;

int main() {
    int n;
    cin >> n;
    char c[n+1];
    srep(i,1,n+1) cin >> c[i];

    ll dp[n+1][n+1];
    rep(i,n+1)rep(j,n+1)dp[i][j] = 0;
    dp[0][0] = 1;
    srep(i,1,n+1){
        if(c[i] == '-'){
            rep(j,n+1) dp[i][j] = dp[i-1][j];
        }else if(c[i] == 'U'){
            srep(j,1,n+1){
                dp[i][j] += dp[i-1][j-1];
            }
            rep(j,n+1){
                dp[i][j] += dp[i-1][j] * j;
            }
            rep(j,n+1) dp[i][j] %= MOD;
        }else if(c[i] == 'D'){
            rep(j,n){
                dp[i][j] += dp[i-1][j+1] * (j+1) * (j+1);
            }
            rep(j,n+1){
                dp[i][j] += dp[i-1][j] * j;
            }
            rep(j,n+1) dp[i][j] %= MOD;
        }
        // rep(j,n+1) cout << dp[i][j] << ' ';
    }


    cout << dp[n][0] << endl;
    return 0;
}
 
 



Measured memory_bytes: 3380
#include <iostream>
#include <string>
using namespace std;
int main(){
    int Rcnt=0;
    int N;
    string s;
    cin >> N;
    cin >> s;
    for(int i=0; i<N; ++i){
      if(s[i]=='R') ++Rcnt;
    }
    if(Rcnt>N-Rcnt) cout << "Yes" << "\n";
    else cout << "No" << "\n";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pi acos(-1)
#define el << endl
using namespace std;
typedef long long ll;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    ll n,a,b,i,j,k;


    cin>>n>>a>>b;

    ///ll x = abs(a-b);


    for(i=a; i<=b; i++)
    {
        if(i%n==0)
        {
            cout<< "OK" << endl;
            return 0;
        }

    }

    cout << "NG" << endl;
    //return 0;


    return 0;
}


Measured memory_bytes: 3672
#line 2 "../../library/template.hpp"
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using pl = pair<ll, ll>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0; i < (ll)n; i++)
#define rep3(i, l, r) for(ll i = l; i < (ll)r; i++)
#define per(i, n) for(ll i = n-1; i >= 0; i--)
#define per3(i, l, r) for(ll i = r-1; i >= (ll)l; i--)
#define all(v) begin(v), end(v)
template<class T, class U>
inline void cmax(T& a, U b) { if (a < b) a = b; }
template<class T, class U>
inline void cmin(T& a, U b) { if (a > b) a = b; }

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    cerr << fixed << setprecision(15);
  }
} io_setup;

constexpr char el = '\n';
#line 2 "b2.cpp"

bool f(string s) {
  ll n = s.size();
  rep(i, n) {
    if (s[i] != s[n-1-i]) {
      return false;
    }
  }
  return true;
}

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

  ll n = s.size();

  if (f(s) and f(s.substr(0, (n-1)/2))) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


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

AC,WA = 0,0

cnt_AC = [False]*(N+1)
cnt_WA = [0]*(N+1)

for i in range(M):
  p,S = input().split()
  p = int(p)
  if S == 'AC' and not cnt_AC[p]:
    AC += 1
    cnt_AC[p] = True
  elif S == 'WA' and not cnt_AC[p]:
    cnt_WA[p] += 1

for i in range(N+1):
  if cnt_AC[i]:
    WA += cnt_WA[i]
print(AC,WA)
  

Measured memory_bytes: 4596
import math
a, b, h, m = map(int, input().split())
at = 0
bt = 0
if m is not 0:
	at = 360 * m / 60
	if h is not 0:
		bt = 360*h/12 + 30*m/60
	else:
		bt = 30*m/60
elif h is not 0:
	bt = 360*h/12
t = math.radians(at-bt)
c = a*a + b*b - 2*a*b*math.cos(t)
print(math.sqrt(c))

Measured memory_bytes: 62568
using static System.Math;
using System;

public class Hello
{
    public static void Main()
    {
        var s = Console.ReadLine().Trim();
        var ans = int.MaxValue;
        for (int i = 0; i <= s.Length-3; i++)
            ans = Min(ans, Abs(753 - int.Parse(s.Substring(i, 3))));
        Console.WriteLine(ans);
    }
}


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

int main()
{
    int a, b;
    cin >> a >> b;
    int s = a - 1;
    int t = b - 1;
    int ans = (t + s - 1) / s;
    cout << ans << endl;

    return 0;
}

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

using namespace std;

#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF ((long long)1e18)
#define EPS (1e-5)
#define MOD ((int)1e9+7)
#define endl "\n"

#define yn(f) ((f)?"Yes":"No")
#define YN(f) ((f)?"YES":"NO")

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(10);
	
	int N, sum = 0, mal = 0, L;
	
	cin>>N;
	
	rep(i,N){
		cin>>L;
		mal = max(mal,L);
		sum += L;
	}
	
	sum -= mal;
	
	cout<<yn(mal < sum)<<endl;
	
	return 0;
}

Measured memory_bytes: 256
# ABC137.py

SELECT = "AB"[1]

if SELECT == "A":  # +-x

    a, b = map(int, input().split())
    plu = a + b
    dis = a - b
    multi = a * b
    print(max(plu, dis, multi))

else:  # OneClue

    k, x = map(int, input().split())
    xs = [i for i in range(x - (k - 1), (x + k))]
    print(" ".join(map(str, xs)))


Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int main() {
  int N, A;
  cin >> N;
  int ans{1};
  int o{1};
  while (cin >> A) {
    ans *= 3;
    if (A%2==0) o *= 2;
  }
  cout << ans - o << endl;
  return 0;
}


Measured memory_bytes: 256
X,N = map(int,input().split())
p = sorted(list(map(int,input().split())))
for i in range(X,-1,-1):
    if i not in p:
        ans = i
        break
for i in range(X+1,102):
    if i not in p:
        ans2 = i
        break
if X-ans > ans2-X:
    print(ans2)
else:
    print(ans)


Measured memory_bytes: 61904
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

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

    int n;
    cin >> n;
    vi a(n);
    rep(i, n) cin >> a[i];
    const int inf = 1001001001;
    vector<int> dp(n, inf);
    rep(i, n) {
        *lower_bound(all(dp), a[i]) = a[i];
    }
    int ans = lower_bound(all(dp), inf) - dp.begin();
    cout << ans << endl;
}



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

using namespace std;
typedef long long ll;

#define MOD (long long)(1e9+7)
#define REP(i,n) for(ll i = 0; i < n; i++)
#define REP1(i,n) for(ll i = 1; i <= n; i++)

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

int main(void)
{
  ll w,h,n;
  cin >> w >> h >> n;
  vector<ll> x(n), y(n), a(n);
  REP(i, n) {
    cin >> x[i] >> y[i] >> a[i];
  }

  ll x1 = 0, y1 = 0, x2 = w, y2 = h;
  REP(i, n) {
    switch(a[i]) {
    case 1:
      x1 = max(x1, x[i]);
      break;
    case 2:
      x2 = min(x2, x[i]);
      break;
    case 3:
      y1 = max(y1, y[i]);
      break;
    case 4:
      y2 = min(y2, y[i]);
      break;
    }
  }
  ll ans = max(0ll, (x2 - x1)) * max(0ll,(y2 - y1));
  cout << ans << endl;
    
}


Measured memory_bytes: 256
/*
    In the name of Allah

    MohammadErfan Gooneh

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;

#define endl                        '\n'
#define all(a, n)                   for (int i = 0; i < n; i++) cout << a[i] << " "; cout << endl;
#define IOS                         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);


const ll MAXN = 1e6 + 10;
const ll INF = 8e18;
const ll MOD = 1e9 + 7;
int main() {
    IOS ;
    string a , b  ,c ;
    cin >> a >> b >> c ; 
    cout << a[0] << b[1] << c[2] ; 




















return 0 ;
}


Measured memory_bytes: 3660
def s_in():
    return input()

def n_in():
    return int(input())

def l_in():
    return list(map(int, input().split()))

class Interval():
    def __init__(self, li):
        self.li = li
        self.n = len(li)
        self.sum_li = [li[0]]
        for i in range(1, self.n):
            self.sum_li.append(self.sum_li[i-1] + li[i])

    def sum(self, a, b=None):
        if b is None:
            return self.sum(0, a)

        res = self.sum_li[min(self.n-1, b-1)]
        if a > 0:
            res -= self.sum_li[a-1]
        return res


K, X = l_in()

if 500*K >= X:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3064
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
int N, T, A;
double H[1001];

int main() {
  INCANT;
  cin >> N >> T >> A;
  rep(i, N) cin >> H[i];
  double d = T-A;
  double mn = 1000000.0;
  int ans=0;
  rep(i, N) {
    if (mn>abs(d-H[i]*0.006)) {
      mn = abs(d-H[i]*0.006);
      ans = i+1;
    }
  }
  
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 256
X = int(input())
exps = set()

for b in range(X):
    if b**2 > X:
        break
    for p in range(1, X):
        tmp = b**p
        if tmp <= X:
            exps.add(tmp)
        else:
            break

print(max(exps) if X > 1 else 1)

Measured memory_bytes: 2940
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    int n = Integer.parseInt(in.readLine());
    String[] str = in.readLine().split(" ");
    int[] d = new int[n];
    int sum = 0;
    
    for(int i=0; i<n; i++) {
      d[i] = Integer.parseInt(str[i]);
    }
    
    for(int i=0; i<n; i++) {
      for(int j=i+1; j<n; j++) {
        sum += d[i] * d[j];
      }
    }
    System.out.println(sum);
  }
}

Measured memory_bytes: 22356
#include<iostream>
#include<string>
#include<cstring>
using namespace std;

int main()
{
	//??¬?????????
	int num1=0,num2=0,num3=0,num4=0,num5=0,num6=0,num7=0,num8=0,num9=0,num10=0,num11=0,num12=0;
	for(int i=0;i<1000;i++){
	cin>>num1>>num2>>num3>>num4>>num5>>num6>>num7>>num8>>num9>>num10;
	if(num1==0){
		return 0;
	}
	num11=num1-num2-num3-num4-num5-num6-num7-num8-num9-num10;
	cout<<num11;
	cout<<"\n";
	}
}

Measured memory_bytes: 1160
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        short a = Short.parseShort(sc.next());
        short b = Short.parseShort(sc.next());
        if((a*b) % 2 == 0){
            System.out.println("Even");
        }else {
            System.out.println("Odd");
        }
    }
}


Measured memory_bytes: 35628
import itertools
import numpy as np
import sys
input = sys.stdin.readline
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

A,B,C = IL()

if A+B < C:
    print(B*2+A+1)
else:
    print(B+C)

Measured memory_bytes: 20652
#include<bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
const int M = 1000000007;

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> h(n);
    for (int i = 0; i < n; ++i) {
        cin >> h[i];
    }
    sort(h.begin(), h.end());
    int ans = M;
    for (int i = 0; i + k - 1 < n; ++i) {
        ans = min(ans, h[i + k - 1] - h[i]);
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 640
N, K = map(int, input().split())
a_list = list(map(int, input().split()))

dp = [False] * (K+1)
for i in range(1, K+1):
    for a in a_list:
        if i >= a:
            dp[i] = dp[i] or ~dp[i-a]
if dp[K]:
    print('First')
else:
    print('Second')

Measured memory_bytes: 9512
cards = {
        'S': [0 for _ in range(13)],
        'H': [0 for _ in range(13)],
        'C': [0 for _ in range(13)],
        'D': [0 for _ in range(13)],
        }
   
n = int(input())
for i in range(n):
    (s, r) = input().split()
    r = int(r)
    cards[s][r - 1] = r
   
for s in ('S', 'H', 'C', 'D'):
    for r in range(13):
        if cards[s][r] == 0:
            print( '{} {}'.format(s, r+1))


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

int main(){
  int a,b;
  cin >> a >> b;
  double fa=a,fb=b;
  cout << a/b << " " << a%b << " ";
  cout << fixed << setprecision(5) << fa/fb << endl;
  return 0;
}

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

class Main{
    public static void main(String[] args){
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line;
        try{
            while(null != (line = br.readLine()))
            {
                String[] strArr = line.split(" ");
                System.out.println(String.valueOf(Integer.parseInt(strArr[0]) + Integer.parseInt(strArr[1])).length());
            }
        }
        catch(Exception e){
        }
    }
}

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

 int main() {
     int N;
     string S;

     cin >> N >> S;

     vector<int> Esum(N, 0), Wsum(N, 0);

     rep(i, 0, N) {
       if (S.at(i) == 'E') {
         if (!i) Esum.at(i) = 1;
         else Esum.at(i) = Esum.at(i - 1) + 1;
       }
       else if (i) Esum.at(i) = Esum.at(i - 1);
     }

     rep(i, 0, N) {
       if (S.at(i) == 'W') {
         if (!i) Wsum.at(i) = 1;
         else Wsum.at(i) = Wsum.at(i - 1) + 1;
       }
       else if (i) Wsum.at(i) = Wsum.at(i - 1);
     }

     int ans = 300000;

     rep(i, 0, N) {
       if (!i) ans = min(ans, Esum.at(N - 1) - Esum.at(i));
       else if (i == N - 1) ans = min(ans, Wsum.at(N - 2));
       else ans = min(ans, Wsum.at(i - 1) + Esum.at(N - 1) - Esum.at(i));
     }
     cout << ans << endl;
 }


Measured memory_bytes: 3076
import math
n=int(input())
a=list(map(int,input().split()))

ave=sum(a)/n
ave_upper=math.ceil(ave)
ave_lower=math.floor(ave)

ans_lower=0
ans_upper=0
for i in a:
    ans_lower+=(ave_lower-i)**2
    ans_upper+=(ave_upper-i)**2

print(min(ans_lower, ans_upper))


Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int s = sc.nextInt();
		int w = sc.nextInt();

		if(s <= w) {
			System.out.println("unsafe");
		}else {
			System.out.println("safe");
		}

	}


}


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

int main() {
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  int ans = min(b,d) - max(a,c);
  if (ans <= 0) cout << 0 << endl;
  else cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3604
x,K=map(int,input().split())

def d(i,j):
    if i>=j:
        i=i-j
        return i-j
    if i<j:
        i=j-i
        return j-i
    else:
        return "aho"

def sa(i,j):
    if i-j>=0:
        return i-j
    else:
        return -(i-j)

    
    
A=x%K

if A<sa(A,K):
    print(A)
else:
    print(sa(A,K))


Measured memory_bytes: 3060
fn main() {
    let mut v: Vec<Vec<char>> = Vec::new();
    v.resize(2, Vec::new());
    for i in 0..2 {
        let mut buff = String::new();
        std::io::stdin().read_line(&mut buff).ok();
        v[i] = buff.trim().chars().collect();
    }

    if (0..2).all(|i| (0..3).all(|j| v[i][j] == v[1 - i][2 - j])) {
        println!("YES");
    } else {
        println!("NO");
    }
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define m 1000000007

/*ll binpow(ll a,ll b,ll mod) 
{
    ll res=1;
    a%=mod;
    while (b > 0) 
    {
        if(b & 1)
        {
            res = (res * a)%mod;
        }
        a=(a*a)%mod;
        b >>= 1;
     
    }
    return res;
}*/


int main() {
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   
    ll x;
    cin>>x;
    if(x==0)
    {
        cout<<1<<endl;
    }
    else
    {
        cout<<0<<endl;
    }
  
	return 0;
}

Measured memory_bytes: 3636
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define REP(i, start, end) for (ll i = start, i##Len = (end); i < i##Len; ++i)
#define REPR(i, start, end) for (ll i = start, i##Len = (end); i > i##Len; --i)
using ll = long long;
using namespace std;

int main()
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);

    string s;
    cin >> s;
    if (s == "RRR")
        cout << 3 << endl;
    else if (s == "RRS" || s == "SRR")
        cout << 2 << endl;
    else if (s == "SSR" || s == "SRS" || s == "RSS" || s == "RSR")
        cout << 1 << endl;
    else
        cout << 0 << endl;
}


Measured memory_bytes: 3652
N, M = map(int, input().split())
A = [input() for _ in range(N)]
B = [input() for _ in range(M)]

for i in range(0, N - M + 1):
    for j in range(0, N - M + 1):
        isOk = True
        for p in range(M):
            for q in range(M):
                if A[i + p][j + q] != B[p][q]:
                    isOk = False
                    break
            if not isOk:
                break
        else:
            print("Yes")
            exit()

print("No")


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define DIM 100007
#define INF 1000000000000000007LL
using namespace std;

long long n,m,d[DIM],res;
vector<long long> a[DIM];

long long dfs(int v)
{
    if(d[v]) return d[v];
    d[v] = 1;
    for(auto to:a[v])
        d[v] = max(d[v],dfs(to)+1);
    res = max(res,d[v]);
    return d[v];
}

int main()
{
    cin>>n>>m;
    for(int i = 1; i <= m; ++i)
    {
        int v1,v2;
        cin>>v1>>v2;
        a[v1].push_back(v2);
    }
    for(int i = 1; i <= n; ++i)
        if(!d[i]) dfs(i);
    cout<<res-1;
    return 0;
}


Measured memory_bytes: 7808
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main() {
	int n;
	cin >> n;
	long long int a[100000];
	for (int i = 0; i < n; ++i) {
		a[i] = 0;
		cin >> a[i];
	}
	/*
	for (int s = 0; s < n - 1; s++) {
		for (int t = s + 1; t < n; t++) {
			if (a[t] > a[s]) {
				int tmp = a[t];
				a[t] = a[s];
				a[s] = tmp;
			}
		}
	}
	*/
	sort(a, a + n);
	
	cout << a[n / 2] - a[n / 2 - 1] << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <climits>
#include <cmath>
#include <vector>
#include <map>
#include <set>
 
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

#define MOD 1000000007LL

ll n;
vector<ll> a, v, as;

ll t2(int);

ll vn(int, ll);

int main()
{
  ll ans;
  int i, d;
//  int j;
//  ll dn;
//  ll tx;
/*
  for (i=0; i<=100; i++) {
    printf("2^%d = %lld\n", i, t2(i));
  }
*/

  cin >> n;
  a.resize(n+1);
  as.resize(n+1);
  v.resize(n+1);
  for (i=0; i<=n; i++) {
    cin >> a[i];
  }

  if (n==0) {
    if (a[0] == 1) {
      printf("1\n");
    } else {
      printf("-1\n");
    }
    return 0;
  } else {
    if (a[0] != 0) {
      printf("-1\n");
      return 0;
    }
  }

  as[n]=a[n];
  for (i=n-1; i>=0; i--) {
    as[i] = as[i+1] + a[i];
//printf("as[%d] = %lld a[%d] = %lld\n", i, as[i], i, a[i]);
  }

  as[0] = 1;
  for (d=1; d<n; d++) {
    as[d] = min((as[d-1] - a[d-1])*2, as[d]);
//printf("as[%d] = %lld a[%d] = %lld\n", d, as[d], d, a[d]);
    if (as[d] - a[d] < 1) {
      printf("-1\n");
      return 0;
    }
  }
  if ((as[n-1] - a[n-1])*2 < a[n]) {
    printf("-1\n");
    return 0;
  }

  ans=0;
  for (i=0; i<=n; i++) {
    ans += as[i];
  }

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

ll t2(int i) {
  if (i > 62) {
    return 4611686018427387904LL;
  }
  switch(i) {
  case 0: return 1; 
  case 1: return 2; 
  case 2: return 4; 
  case 3: return 8; 
  case 4: return 16; 
  case 5: return 32; 
  case 6: return 64; 
  case 7: return 128; 
  case 8: return 256; 
  case 9: return 512; 
  case 10: return 1024; 
  case 11: return 2048; 
  case 12: return 4096; 
  case 13: return 8192; 
  case 14: return 16384; 
  case 15: return 32768; 
  case 16: return 65536; 
  case 17: return 131072; 
  case 18: return 262144; 
  case 19: return 524288; 
  case 20: return 1048576; 
  case 21: return 2097152LL; 
  case 22: return 4194304LL; 
  case 23: return 8388608LL; 
  case 24: return 16777216LL; 
  case 25: return 33554432LL; 
  case 26: return 67108864LL; 
  case 27: return 134217728LL; 
  case 28: return 268435456LL;
  case 29: return 536870912LL;
  case 30: return 1073741824LL;
  case 31: return 2147483648LL;
  case 32: return 4294967296LL;
  case 33: return 8589934592LL;
  case 34: return 17179869184LL;
  case 35: return 34359738368LL;
  case 36: return 68719476736LL;
  case 37: return 137438953472LL;
  case 38: return 274877906944LL;
  }
  return t2(i-38)*274877906944LL;
}


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

int main(){

  int N;
  cin >> N;
  vector<int> numA;
  vector<int> numB;

  int a,b;
  for(int i=0;i<N;i++){
    cin >> a >> b;
    numA.emplace_back(a);
    numB.emplace_back(b);
  }

  sort(numA.begin(),numA.end());
  sort(numB.begin(),numB.end());

  int maxC;
  int minC;
  if(N%2==0){
    minC=(numA[(N/2)-1]+numA[N/2]);
    maxC=(numB[(N/2)-1]+numB[N/2]);
    cout << (maxC-minC)+1 << endl;
  }else{
    minC=numA[(N-1)/2];
    maxC=numB[(N-1)/2];
    cout << maxC-minC+1 << endl;
  }

}

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

int main() {
  int N;
  cin >> N;
  N = N % 10;
  if(N==2 or N==4 or N==5 or N==7 or N==9){
    cout << "hon" <<endl;
  }
  if(N == 0 or N==1 or N==6 or N==8){
    cout << "pon" << endl;
  }
  if(N == 3){
    cout << "bon" << endl;
  }
}

Measured memory_bytes: 3636
from itertools import combinations as comb
import sys
n = int(input())
li = [[] for i in range(n)]
for i in range(n):
    a = int(input())
    for _ in range(a):
        x, y = map(int, input().split())
        li[i].append((x-1, y))

for i in range(n, 0, -1):
    honests_list = comb(range(n), i)
    for honests in honests_list:
        for j in honests:
            for k, l in li[j]:
                if ((k in honests) and l==0) or ((k not in honests) and l==1):
                    break
            else:
                continue
            break
        else:
            print(i)
            sys.exit()
print(0)

Measured memory_bytes: 3064
#include <cstdio> 
using namespace std;
 
const int maxn=2e6+5;
#define ls (x<<1)
#define rs (x<<1|1)
 
int n, p, t1, t2, a[maxn], seg[maxn], fst[maxn], mn[maxn], pos[maxn], c[maxn];
 
int main(){
	scanf("%d", &n);
	for (int i=1; i<=n; ++i){
		scanf("%d", a+i);
		if ((a[i]&1)!=(i&1)){ puts("No"); return 0; }
		pos[a[i]]=i; }
	for (int i=1; i<=n-2; ++i)
		if (a[i]!=i&&a[i+1]!=i+1&&a[i+2]!=i+2){ puts("No"); return 0; }
	p=t1=t2=0;
	for (int i=1;i<=n;i+=2) c[++p]=a[i];
	for (int i=1;i<=p;++i)
		if (c[i]>t2) t2=c[i];
		else{
			if (c[i]>t1) t1=c[i];
			else{puts("No"); return 0;} }
	p=t1=t2=0;
	for (int i=2; i<=n; i+=2) c[++p]=a[i];
	for (int i=1; i<=p; ++i)
		if (c[i]>t2) t2=c[i];
		else{
			if (c[i]>t1) t1=c[i];
			else{puts("No"); return 0;}
		}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 6912
#include <iostream>
#include <vector>
#include <algorithm>
#include <ios>
#include <iomanip>

using namespace std;
typedef long long ll;

int main()
{
    ll K,A,B;
    cin >> K >> A >> B;
    if ((B-A) <= 1){
        cout << 1 + K << endl;
        return 0;
    }
    ll bisk = 1;
    ll en = 0;
    for (int i=0;i<K;i++){
        if (en>0 && i<K-1){
            bisk = bisk + en * B;
            en--;
            K++;
        }
        else if (bisk >= A && i<K-1){
            bisk = bisk - A;
            en++;
            K--;
        }
        else{
            bisk++;
        }
    }
    ll ans;
    ans = bisk + en*B;
    cout << ans << endl;
    // system("pause");
}

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

using namespace std;

const string n = "0123456789";

int main() {

	int n, k;
	cin >> n >> k;

	double p = 0.0;
	double d = 1.0 / n;

	int q;
	if (n >= k) {
		p += d * (n - k + 1);
	}
	q = k - 1;
	n = min(n, q);
	while (q > 0) {
		d /= 2.0;
		q = q / 2;
		if (n > q) {
			p += d * (n - q);
			n = q;
		}
	}

	cout << setprecision(10) << p << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <tuple>
#include <cmath>
using namespace std;

int main(int argc, const char * argv[]) {
  int n, t;
  cin >> n >> t;
  vector<pair<int,int>> p;
  int a, b;
  for(int i = 0; i < n; i++){
    cin >> a >> b;
    if(b <= t){
      p.push_back(make_pair(a,b));
    }
  }
  if(p.size() == 0){
    cout << "TLE" << endl;
  }else{
    sort(p.begin(), p.end());
    cout << p.at(0).first << endl;
  }
  return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
	"reflect"
	"sort"
)

// NextPermutation test
func NextPermutation(x sort.Interface) bool {
	n := x.Len() - 1
	if n < 1 {
		return false
	}
	j := n - 1
	for ; !x.Less(j, j+1); j-- {
		if j == 0 {
			return false
		}
	}
	l := n
	for !x.Less(j, l) {
		l--
	}
	x.Swap(j, l)
	for k, l := j+1, n; k < l; {
		x.Swap(k, l)
		k++
		l--
	}
	return true
}
func main() {
	var n int
	fmt.Scan(&n)

	listp := make([]int, n)
	listq := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&listp[i])
	}
	for i := 0; i < n; i++ {
		fmt.Scan(&listq[i])
	}

	permu := make([]int, n)
	copy(permu, listp)
	sort.Sort(sort.IntSlice(permu))

	numP := 1
	numQ := 1
	for i := 1; NextPermutation(sort.IntSlice(permu)); i++ {
		if reflect.DeepEqual(permu, listp) {
			numP = i + 1
		}
		if reflect.DeepEqual(permu, listq) {
			numQ = i + 1
		}
	}
	fmt.Println(math.Abs(float64(numP) - float64(numQ)))

}


Measured memory_bytes: 5504
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
V a;
ll func(ll b){
	ll res=0LL;
	repi(itr,a){
		res+=abs(b+(*itr));
	}
	return res;
}
//三部探索、(下限、上限、探す場所(falseで最大値))->極値の場所と値
pair<ll,ll>TripleSearch(ll begin,ll end,bool comp=true){
	pair<ll, ll> down,up, pup, pdown,res;
	down = mp(begin, func(begin));
	up = mp(end, func(end));
	if((down.S <up.S)xor comp){
		res=up;
	}else{
		res=down;
	}
	while (down.F + 2 < up.F)
	{
		pup.F = down.F + 2 * (up.F - down.F) / 3;
		pdown.F = down.F + (up.F - down.F) / 3;
		pup.S = func(pup.F);
		pdown.S = func(pdown.F);
		//	clog<<down.F<<" "<<pdown.F<<" "<<pup.F<<" "<<up.F<<endl;
		//	clog << down.S << " "<< pdown.S << " " << pup.S << " " << up.S <<endl <<endl;
		if (pdown.S < pup.S)
		{
			up = pup;
			if((pdown.S <res.S)== comp){
				res=pdown;
			}
		}
		else
		{
			down = pdown;
			if ((pup.S < res.S) == comp)
			{
				res = pup;
			}
		}
	}
	return res;
}
int main(){
	int n;
	ll ans=0LL;
	cin >>n;
	a.resize(n);
	rep(i,n){
		cin>>a[i];
		a[i]-=(i+1);
		a[i]*=-1LL;
	//	clog<<a[i]<<endl;
	}
	//=----------------//triple tharch
	cout<<TripleSearch(-1e10,1e10).S<<endl;
	//----------------//
	//cout<<min(up.S,min(down.S,min(pup.S,pdown.S)))<<endl;
}
/*
|a-b|:a-b or b-a

2 2 3 5 5
|2-b-1| |2-b-2| |3-b-3| |4-b-5| |5-b-5|

|1-b| |b| |b| |1-b| |b| =>2

|2-b-6| |2-b-5| |3-b-4| |4-b-3| |5-b-2| |6-b-1|

|4+b| |3+b| |1+b| |1-b| |3-b| |5-b|
|1-b| |1+b| |3-b| |3+b| |4+b| |5-d|

-4->

|1-b-1| |2-b-1| |3-b-1| |4-b-2| |5-b-3| |6-b-4|
|1-b| |1-b|  |2-b| |2-b| |2-b| |2-b|
0=>10
1=>4
2->2
3->8
*/

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__);fflush(stderr);
#else
	#define eprintf(...) 42
#endif

using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
template<typename T>
using pair2 = pair<T, T>;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
	return (ull)rng() % B;
}

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second

clock_t startTime;
double getCurrentTime() {
	return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}


const ll MOD = 998244353;
ll add(ll x, ll y) {
	x += y;
	if (x >= MOD) return x - MOD;
	return x;
}
ll sub(ll x, ll y) {
	x -= y;
	if (x < 0) return x + MOD;
	return x;
}
ll mult(ll x, ll y) {
	return (x * y) % MOD;
}
ll bin_pow(ll x, ll p) {
	if (p == 0) return 1;
	if (p & 1) return mult(x, bin_pow(x, p - 1));
	return bin_pow(mult(x, x), p / 2);
}
ll rev(ll x) {
	return bin_pow(x, MOD - 2);
}

const int N = 303;
char s[N];
int n;
bool dp1[N][N][N];
ll dp2[N][N][N];

int main()
{
	startTime = clock();
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	scanf("%s", s);
	n = strlen(s);

	dp1[0][0][0] = 1;
	for (int len = 0; len <= n; len++)
		for (int x = 0; x <= n; x++)
			for (int y = 0; y <= n; y++) {
				if (!dp1[len][x][y]) continue;
				int xx = x, yy = y;
				int nlen = len;
				for (int it = 0; it < 2; it++) {
					if (xx >= 2) dp1[nlen][xx - 1][yy] = 1;
					if (yy >= 2) dp1[nlen][xx][yy - 1] = 1;
					if (xx >= 1 && yy >= 1) {
						dp1[nlen][xx - 1][yy] = 1;
						dp1[nlen][xx][yy - 1] = 1;
					}
					if (nlen == n) break;
					if (s[nlen] == '0')
						xx++;
					else
						yy++;
					nlen++;
				}
				if (xx > x) dp1[nlen][xx - 1][yy] = 1;
				if (yy > y) dp1[nlen][xx][yy - 1] = 1;
			}

	dp2[n][0][0] = 1;
	for (int x = 0; x <= n; x++)
		for (int y = 0; y <= n; y++) {
			for (int p = n; p >= 0; p--) {
				if (dp2[p][x][y] == 0) continue;
				int np = p;
				if (p > 0 && s[p - 1] == '0') np--;
				dp2[np][x + 1][y] = add(dp2[np][x + 1][y], dp2[p][x][y]);
				np = p;
				if (p > 0 && s[p - 1] == '1') np--;
				dp2[np][x][y + 1] = add(dp2[np][x][y + 1], dp2[p][x][y]);
			}
		}

	ll ans = 0;
	for (int x = 0; x <= n; x++)
		for (int y = 0; y <= n; y++) {
			if (x + y == 0) continue;
			if (x + y > n) break;
			int wx = x, wy = y;
			int p = n;
			while(p >= 0) {
				if (dp1[p][wx][wy]) break;
				p--;
				if (p >= 0) {
					if (s[p] == '0')
						wx = max(0, wx - 1);
					else
						wy = max(0, wy - 1);
				}
			}
			for (int i = 0; i <= p; i++)
				ans = add(ans, dp2[i][x][y]);
		}
	printf("%lld\n", ans);

	return 0;
}


Measured memory_bytes: 217036
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>

using namespace std;
#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 (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define VI vector<int>
#define debug(x) cout<<#x<<": "<<x<<endl
#define DEBUG(x) cout<<#x<<": "<<x<<endl
int H,W;
vector <string > S;





int main()
{

	cin >> H >> W;

	S.resize(H);

	REP(i,H){
		cin >> S[i];
	}

	REP(i,H){
		REP(j,W){
			if(S[i][j] != '#'){
				S[i][j]='0';
			}
		}
	}

	REP(i,H){
		REP(j,W){
			if(S[i][j] == '#'){
				REP(k,3){
					REP(m,3){
						if(i-1+k<0 || i-1+k>=H ||j-1+m<0 || j-1+m>=W || (k==1&&m==1))
							continue;
						if(S[i-1+k][j-1+m]!='#')
						S[i-1+k][j-1+m]++;
					}
				}
			}
		}
	}

	REP(i,H){
		cout << S[i] << endl;
	}

}





Measured memory_bytes: 256
/*
* @author:  codancer
* @createTime:  2020-08-15, 20:02:19
*/

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9+7;
#define pb push_back
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define fep(i,a,b) for(int i=(a);i>=(b);i--)
#define deb(x) cerr<<#x<<" = "<<(x)<<"\n"
typedef vector<int> VI;
typedef vector<ll> VII;
typedef pair<int,int> pii;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll Rand(ll B) {
	return (ull)rng() % B;
}
int main(){
	int n;
	cin>>n;
	vector<int> a(n+1);
	rep(i,1,n) cin>>a[i];
	int ans=0;
	rep(i,1,n){
		rep(j,i+1,n){
			rep(k,j+1,n){
				if(a[i]!=a[j]&&a[j]!=a[k]&&a[i]!=a[k]){
					if(a[i]+a[j]>a[k]&&a[i]+a[k]>a[j]&&a[j]+a[k]>a[i]) ++ans;
				}
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S; int w; cin >> S >> w;
    string ans="";
    for (int i=0;i<S.size();++i){
        if (i%w==0) ans+=S[i];
    }
    cout << ans << '\n';
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
int n, a, k, ans, d, m;
int main(){
	scanf("%d", &n);
	rep(i,n){
		scanf("%d%d", &a, &k);
		while(true){
			d = a / k;
			m = a % k;
			if(!m) break;
			a -= (m+d)/(d+1)*(d+1);
		}
		ans ^= d;
	}
	puts(ans ? "Takahashi" : "Aoki");
}

Measured memory_bytes: 256
#過去問10選3つ目
#フラグのつけかたがなんとも

n =gets.to_i

a = gets.split.map(&:to_i)
flag, count = 0, 0
while flag == 0
  for i in a
    if i%2 == 1
      flag = 1
      break
    end
  end
  a.map!{|j| j / 2} if flag == 0
  count += 1 if flag == 0
end

puts count

Measured memory_bytes: 1788
n=int(input())
a=list(map(int, input().split()))
b=[]
for i in range(n):
  if a[i]%2==0:
    b.append(a[i])
ans="APPROVED"
for i in range(len(b)):
  if b[i]%3!=0 and b[i]%5!=0:
    ans="DENIED"
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
using namespace std;
int main(void){
    // Your code here!
    
    int sheep_num,wolf_num;
    int i, j, k;
    long long ans;
    string ans_str, tmp_str;
    
    cin >> sheep_num >> wolf_num;
    
    if(sheep_num <= wolf_num){
        ans_str = "unsafe";
    }else{
        ans_str = "safe";
    }
    
    cout << ans_str << endl;
    
}


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

long long mod = 998244353;

int main(){
  long long A,B,C,D;
  cin >> A >> B >> C >> D;
  
  vector<vector<long long>> dp(C+1,vector<long long>(D+1,0));
  for(int i=1;i<=C;i++){
    for(int j=1;j<=D;j++){
      if(i>A && j>B){
        long long now=0;
        now = dp[i][j-1]*i; now %= mod;
        dp[i][j] += now; dp[i][j] %= mod;
        now = dp[i-1][j]*j; now %= mod;
        dp[i][j] += now; dp[i][j] %= mod;
        now = dp[i-1][j-1]*(i-1); now %= mod;
        now *= j-1; now %= mod;
        dp[i][j] += mod;
        dp[i][j] -= now; dp[i][j] %= mod;
      }
      else if(i==A && j>B){
        dp[i][j] = dp[i][j-1]*i;
        dp[i][j] %= mod;
      }
      else if(i>A && j==B){
        dp[i][j] = dp[i-1][j]*j;
        dp[i][j] %= mod;
      }
      else dp[i][j] = 1;
    }
  }
  
  cout << dp[C][D] << endl;
  return 0;
}


Measured memory_bytes: 73720
#include<iostream>
#include<stack>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
	stack<int>S1;
	stack<pair<int,int> >S2;
	char ch;
	int sum=0;
	for(int i=0;cin>>ch;i++){
		if(ch=='\\') S1.push(i);
		else if(ch=='/' && S1.size()>0){
			int j=S1.top();S1.pop();
			sum+=i-j;
			int a=i-j;
			while(S2.size()>0 && S2.top().first>j){
				a+=S2.top().second;S2.pop();
			}
			S2.push(make_pair(j,a));
		}
	}
	vector<int>ans;
	while(S2.size()>0){ans.push_back(S2.top().second);S2.pop();}
	reverse(ans.begin(),ans.end());
	cout<<sum<<endl;
	cout<<ans.size();
	for(int i=0;i<ans.size();i++){
       cout<<" ";
       cout<<ans[i];
	}
	cout<<endl;
	return 0;
}



Measured memory_bytes: 3180
#include <iostream>
#include <list>

int main()
{
    std::list<int> List;

    int q, m, x, d;
    auto itr = List.end();

    std::cin >> q;
    for (int i = 0; i < q; i++)
    {
        std::cin >> m;
        if (m == 0)
        {
            std::cin >> x;
            itr = List.insert(itr, x);
        }
        else if (m == 1)
        {
            std::cin >> d;
            itr = next(itr, d);
        }
        else if (m == 2)
        {
            itr = List.erase(itr);
        }

        // std::cout << m << " " << x << " " << d << std::endl;
        // for (auto &x : List)
        // {
        //     std::cout << x;
        // }
        // std::cout << " " << *itr << std::endl;
    }

    for (auto &x : List)
    {
        std::cout << x << std::endl;
    }

    return 0;
}




Measured memory_bytes: 18636
#include <bits/stdc++.h>
#define endl        '\n'
#define db          double
#define ld          long double
#define ll          long long
#define ull         unsigned long long
#define sqr(x)      (x) * (x)
#define gcd(a, b)   __gcd(a, b)
#define lcm(a, b)   ((a/gcd(a,b)) * b)
#define pf(x) 		push_front(x)
#define pb(x)       push_back(x)
#define eb(x)		emplace_back(x)
#define all(x)      (x).begin(), (x).end()
#define rall(x) 	(x).rbegin(), (x).rend()
#define sz(x) 		(int)x.size()
#define debug(x) 	cerr << #x << " = " << (x) <<endl
#define unsyncIO    ios_base::sync_with_stdio(0); cin.tie(0)

const ld PI = acos((ld)-1);
const int MOD = 1e9+7;
const ll INF = 1e18; 

using namespace std;

int main()
{
    //freopen("/home/taalpatar_shepai/Documents/my_codes/out.txt", "w", stdout);
    char a, b;
    cin >> a >> b;
    if (a == 'H')
        cout << b << endl;
    else {
        if(b == 'H')
            cout << 'D';
        else if(b == 'D')
            cout << "H" << endl;
    }
    return 0;
}

Measured memory_bytes: 3636
if __name__ == '__main__':

    n = int(input())
    A = list(map(int,input().split()))

    #全体
    sm = sum(A) ** 2
    #共通部分
    com = sum([i * i for i in A])

    ans = (sm - com) // 2
    print(ans%(10**9+7))

Measured memory_bytes: 31560
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] lines = Console.ReadLine().Split(' ');
            long n = long.Parse(lines[0]);
            long a = long.Parse(lines[1]);
            long b = long.Parse(lines[2]);

            long ans = 0;

            if ((n == 1 && a < b) || a > b)
            {
                ans = 0;
            }
            else if ((n == 2 && a < b) || a == b)
            {
                ans = 1;
            }
            else
            {
                for (int i = 0; i < n - 2; i++)
                {
                    ans += (b - a);
                }
                ans++;
            }

            Console.WriteLine(ans);
        }
    }
}


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

int main(void){
    int a,b;
    cin >> a;
    cin >> b;
    if(a>b){
        cout << "a > b";
    }
    else if(a<b){
        cout << "a < b";
    }
    else{
        cout << "a == b";
    }
    cout << endl;
}



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

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

void solve() {
    int H, W;
    cin >> H >> W;
    vector<string> A(H);
    for (int i = 0; i < H; i++) {
        cin >> A[i];
    }
    pii now = {0, 0};
    vector<vector<int>> flag(H, vector<int>(W, 0));
    flag[0][0] = 1;
    while(now != make_pair(H - 1, W - 1)) {
        int fl1 = 0, fl2 = 0;
        if (now.first + 1 < H && A[now.first + 1][now.second] == '#') {
            fl1 = 1;
        }
        if (now.second + 1 < W && A[now.first][now.second + 1] == '#') {
            fl2 = 1;
        }
        if (fl1 && fl2) {
            cout << "Impossible" << endl;
            return;
        }
        if (!fl1 && !fl2) {
            cout << "Impossible" << endl;
            return;
        }
        if (fl1) {
            now.first += 1;
        } else {
            now.second += 1;
        }
        flag[now.first][now.second] = 1;
    }

    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (A[i][j] == '#' && !flag[i][j]) {
                cout << "Impossible" << endl;
                return;
            }
        }
    }
    cout << "Possible" << endl;

}

int main() {
    #ifdef LOCAL_ENV
    cin.exceptions(ios::failbit);
    #endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    
    solve();
}

Measured memory_bytes: 256
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
var n=Arr.shift()-0;
var obj={};
for(var i=0;i<n;i++){
   obj[Arr.shift()]=true;
}
var n=Arr.shift()-0;
var flag=false;
for(var i=0;i<n;i++){
   var v=Arr.shift();
   if(obj.hasOwnProperty(v)){
      flag=!flag;
      if(flag){console.log("Opened by "+v);}
      else {console.log("Closed by "+v);}
   }else{
      console.log("Unknown "+v);
   }
}

Measured memory_bytes: 9236
N=int(input())
A=list(map(int,input().split()))
# 1,7,6,8,1,
# L[i]=A[i]

def gcd(a,b):
  if a<b:
    a,b=b,a
  while a%b>0:
    a,b=b,a%b
  return b

L=[1]*len(A)
L[0]=A[0]
for i in range(len(A)-1):
  L[i+1]=gcd(L[i],A[i+1])
  
R=[1]*len(A)
R[-1]=A[-1]
for i in range(len(A)-1,0,-1):
  R[i-1]=gcd(R[i],A[i-1])

ans=1
for i in range(len(A)):
  if i==0:
    if ans<R[i+1]:
      ans=R[i+1]
  elif i==len(A)-1:
    if ans<L[i-1]:
      ans=L[i-1]
  else:
    p=gcd(L[i-1],R[i+1])
    if ans<p:
      ans=p
print(ans)


Measured memory_bytes: 14076
#include <bits/stdc++.h>
using namespace std;
const int INF = 1001001001;;

int main() {
  int n, m;  cin >> n >> m;
  vector<int> r(n,INF);
  for(int i=0; i<m; i++){
    int a, b;  cin >> a >> b;
    --a; --b;
    r[a] = min(r[a], b);
  }

  int x = INF, ans = 0;
  for(int i=0; i<n; i++){
    if (x == i) x = INF, ans++;
    x = min(x, r[i]);
  }

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


Measured memory_bytes: 3784
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int mo=1000000007;
int n,K,x; LL f[105][4000],ans,g[105][10005];
LL po(LL x,LL y){
	LL z=1;
	for (;y;y>>=1,x=x*x%mo)
	if (y&1) z=z*x%mo;
	return z;
}
int main(){
	scanf("%d%d",&n,&K);
	f[n+1][0]=1;
	for (int i=n;i;--i){
		for (int k=0;k<4000;++k)
		if (f[i+1][k]){
			for (int j=0;j<=K;++j){
				if (j>i) (f[i][k]+=f[i+1][k])%=mo;
				else (f[i][k+(j+k)/i]+=f[i+1][k])%=mo;
			}
		}
	}
	g[0][0]=1;
	for (int i=1;i<=n;++i)
	for (int k=0;k<=n*K;++k)
	if (g[i-1][k]){
		for (int j=0;j<=K;++j) (g[i][j+k]+=g[i-1][k])%=mo;
	}
	for (int k=0;k<=n*K;++k) (ans+=1ll*k*g[n][k])%=mo;
	for (int k=0;k<4000;++k) (ans-=1ll*f[1][k]*k)%=mo;
	printf("%lld\n",(ans%mo+mo)%mo);
	return 0;
}

Measured memory_bytes: 8960