akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
        int W = sc.nextInt();

        String[] S = new String[H + 2];
        for (int i = 0; i <= H + 1; i++) {
            S[i] ="";
            if (i == 0 || i == H + 1) {
                for (int j = 0; j <= W + 1; j++) {
                    S[i] = S[i] + " ";
                }
            }else {
                S[i] = " " + sc.next() + " ";
            }
        }
        String[][] result = new String[H][W];
        for (int i = 1; i <= H; i++) {
            for (int j = 1; j <= W; j++) {
                if (S[i].charAt(j) == '#') {
                    result[i - 1][j - 1] = "#";
                }else {
                    int count = 0;
                    if (S[i - 1].charAt(j - 1) == '#') {
                        count++;
                    }
                    if (S[i - 1].charAt(j) == '#') {
                        count++;
                    }
                    if (S[i - 1].charAt(j + 1) == '#') {
                        count++;
                    }
                    if (S[i].charAt(j - 1) == '#') {
                        count++;
                    }
                    if (S[i].charAt(j + 1) == '#') {
                        count++;
                    }
                    if (S[i + 1].charAt(j - 1) == '#') {
                        count++;
                    }
                    if (S[i + 1].charAt(j) == '#') {
                        count++;
                    }
                    if (S[i + 1].charAt(j + 1) == '#') {
                        count++;
                    }
                    result[i - 1][j - 1] = String.valueOf(count);
                }
            }
        }
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                System.out.print(result[i][j]);
            }
            System.out.println();
        }
    }
}


Measured memory_bytes: 22484
#include <iostream>
#include <vector>

using namespace std;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};

int ans = 11;
vector<vector<int>> mp;
void dfs(int i, int j, int direction, int num, vector<vector<int>> mp){
	while(mp[i+dx[direction]][j+dy[direction]] == 0){
		i += dx[direction];
		j += dy[direction];
	}
	if(mp[i+dx[direction]][j+dy[direction]] == 3){
		ans = min(num,ans);
		return;
	}
	if(mp[i+dx[direction]][j+dy[direction]] == 1 && num < 10){
		mp[i+dx[direction]][j+dy[direction]] = 0;
		for(int k = 0;k<4;k++){
			if(mp[i+dx[k]][j+dy[k]] == 1)continue;
			if(mp[i+dx[k]][j+dy[k]] == -1)continue;
			//if(dx )
			dfs(i,j,k,num+1,mp);
		}
	}
}


int main(){
	int w,h;
	while(cin>>w>>h,w){
		mp.resize(h+2,vector<int>(w+2,-1));
		int def_i,def_j;
		for(int i = 1;i < h+1;i++){
			for(int j = 1;j < w+1;j++){
				cin >> mp[i][j];
				if(mp[i][j] == 2){
					def_i = i;
					def_j = j;
				}
			}
		}
		mp[def_i][def_j] = 0;
		for(int i = 0;i < 4;i++){
			if(mp[def_i+dx[i]][def_j+dy[i]] != 0 && mp[def_i+dx[i]][def_j+dy[i]] != 3)continue;
			dfs(def_i,def_j,i,1,mp);
		}
		if(ans == 11)cout << -1 << endl;
		else cout << ans << endl;
		ans = 11;
		mp.clear();
	}
}

Measured memory_bytes: 3124
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
    int n,m; cin >> n >> m;
    int id_min = 0;
    int id_max = 1e9;
    for(int i = 0; i < m; i++){
        int a,b;cin >> a >> b;
        id_min = max(id_min, a);
        id_max = min(id_max, b);
    }
    int dif = id_max - id_min;
    cout << ((dif >= 0) ? dif + 1 : 0)  << endl;
}

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

using namespace std;

char s[111111];
int n;

int main(){
//	freopen("input.inp", "r", stdin);
	scanf("%s",&s); n = strlen(s);
	if (n % 2 == 0 && s[0] == s[n - 1]) printf("First");
	else if (n % 2 && s[0] != s[n - 1]) printf("First");
	else printf("Second");
	return 0;
}

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

// template {{{  0 
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

int main() {

    int N;
    Scd(N);

    vi a(N);
    unordered_multiset<int> s;
    Rep(i,N){
        Scd(a[i]);
        s.insert(a[i]);
    }

    int tmp = 0x40000000;
    while( tmp ){
        // vector<unordered_multiset<int>::iterator> er;
        for( int t : a ){
            auto it = s.find(t);
            if( it == s.end() ) continue;
            auto tit = s.find(tmp-t);
            if( tit == s.end() ) continue;
            if( it == tit ) tit++;
            if( tit != s.end() && *it+*tit == tmp ){
                s.erase(it);
                s.erase(tit);
            }
        }
        tmp >>= 1;
        if( s.size() < 2 ) break;
    }

    printf ("%d\n", (N-s.size())/2 );

    return 0;
}





Measured memory_bytes: 9288
#include<stdio.h>

int main(){
    
    int S,h,m,s,k;

    scanf("%d",&S);

    h=S/3600;
    k=S%3600;
    m=k/60;
    s=k%60;

    printf("%d:%d:%d\n",h,m,s);

    return 0;
}

Measured memory_bytes: 1852
N=input()
n=int(N)

p=[]
for i in range(n):
    p.append(input())

ha = {}

for i in p :
    if (i not in ha.keys()) :
        ha[i] = 1
    else :
        ha[i] += 1

res = ha.items()

res = sorted(ha.items(), key = lambda x : x[1] , reverse = True )

i = 1
k = res[0][1]

while (i < len(res) and res[i][1] == k) :
    i += 1

res = res[ : i]

res.sort()
for i in res :
    print (i[0])


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

int main() {
	ll n,t,mi=1000000,i;
	cin>>n>>t;
	for(i=0;i<n;i++){
	   ll c,x;
	   cin>>c>>x;
	   if(t>=x){
	       mi = min(mi,c);
	   }
	}
	if(mi==1000000){
	    cout<<"TLE";
	}
	else{
	cout<<mi;
	}
}


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

struct Point {
    double x, y;

    Point() = default;
    Point(double x, double y) : x(x), y(y) {}

    Point operator+(const Point &rhs) const {
        return Point(x + rhs.x, y + rhs.y);
    }

    Point operator-(const Point &rhs) const {
        return Point(x - rhs.x, y - rhs.y);
    }

    double operator*(const Point &rhs) const {
        return x * rhs.x + y * rhs.y;
    }

    double operator%(const Point &rhs) const {
        return x * rhs.y - y * rhs.x;
    }

    bool operator<(const Point &rhs) const {
        return fabs(x - rhs.x) < 1e-9 ? y < rhs.y : x < rhs.x;
    }

    Point operator/(double d) const {
        return Point(x / d, y / d);
    }
    
    Point operator*(double d) const {
        return Point(x * d, y * d);
    }
};

array<Point, 2> tangent(Point o, double r, Point p) {
    double dist = sqrt((p - o) * (p - o));
    double len = sqrt(dist * dist - r * r);
    double ang = acos(len / dist);
    Point vec = (o - p) / dist * len;
    array<Point, 2> res;
    for (int i = 0; i < 2; ++i) {
        int z = i == 0 ? 1 : -1;
        Point v(vec.x * cos(z * ang) - vec.y * sin(z * ang), vec.x * sin(z * ang) + vec.y * cos(z * ang));
        res[i] = p + v; 
    }
    return res;
}

int main() {
    Point p, o;
    cin >> p.x >> p.y;
    cin >> o.x >> o.y;
    double r; cin >> r;
    array<Point, 2> ans = tangent(o, r, p);
    if (ans[1] < ans[0]) swap(ans[0], ans[1]);
    cout << fixed << setprecision(20) << ans[0].x << ' ' << ans[0].y << endl;
    cout << fixed << setprecision(20) << ans[1].x << ' ' << ans[1].y << endl;
    return 0;
}



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


int main(){
  int n; cin >> n;
  int p[10];
  rep(i,n) cin >> p[i];

  int mini = 0;
  int sum = 0;
  rep(i,n){
    sum += p[i];
    if( mini < p[i] ){
      mini = p[i];
    }
  }

  sum -= mini/2;
  cout << sum << endl;
}


Measured memory_bytes: 256
#include <stdbool.h>
#include <stdio.h>
int n, k, d[10];
bool isNumOK(int n) {
	while (n > 0) {
		for (int i = 0; i < k; i++) {
			if (n % 10 == d[i]) {
				return false;
			}
		}
		n /= 10;
	}
	return true;
}
int main() {
	scanf("%d%d", &n, &k);
	for (int i = 0; i < k; i++) {
		scanf("%d", &d[i]);
	}
	for (int i = n;; i++) {
		if (isNumOK(i)) {
			printf("%d\n", i);
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main(void){
    int N, a, min = 99999999;
    cin >> N;
    int X[N];
    
    for(int i = 0; i < N; i++){
        cin >> X[i];
    }
    
    for(int i = 1; i <= 100; i++){
        a = 0;
        for(int j = 0; j < N; j++){
            a += (X[j] - i) * (X[j] - i);
        }
        if(a < min)
            min = a;
    }
    cout << min << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;
static const int SIZE = 100005;

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

vector< P > color[SIZE];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    int a[SIZE];
    for( int i = 0; i < n; ++i ) cin >> a[i];

    multiset< int > mst;
    mst.insert( a[n - 1] );
    int pos = 1;
    int res = 1;
    for( int i = n - 2; i >= 0; --i ) {
        auto p = mst.upper_bound( a[i] );
        if( p == mst.end() ) {
            mst.insert( a[i] );
            ++res;

        } else {
            mst.erase( p );
            mst.insert( a[i] );

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


Measured memory_bytes: 7808
#include<stdio.h>
#include<math.h>
#include<stdlib.h>

int main(void){
	int N,i,ans(0);
	scanf("%d",&N);
	long long int H[N],max(-1);
	for(i = 0 ; i < N ; i ++){
		scanf("%lld",&H[i]);
		if(max < H[i]) max = H[i];
		if(H[i] < max - 1) ans = -1;
	}
	if(ans < 0){
		printf("No\n");
	} else {
		printf("Yes\n");
	}
	return 0;
}

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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const llint INF = 1<<21;
// static const llint MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

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

    map<int, int> mp;
    
    int a;
    for(int in=0;in<n;in++) {
        cin >> a;
        auto result = mp.insert(make_pair(a, 1));
        if(!result.second) mp[a]++;
    }

    int ans = 0;
    for(auto imp:mp) {
        if(imp.first<=imp.second) ans += imp.second - imp.first;
        else ans += imp.second;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4736
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;

typedef long long ll;

int main() {
  ll n, x = 1;
  int ans = 0;
  cin >> n;
  for(ll i=1; i*i<=n; i++) {
    if (n % i == 0) x = n / i;
  }
  while (0 < x) {
    ans++;
    x /= 10;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math

# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev
 
def main():
    a,b = map(int,input().split())
    
    if a*b % 2 == 0:
        print("Even")
    else:
        print("Odd")
    
	
if __name__ == "__main__":
	main()


Measured memory_bytes: 38256
#include <iostream>
#include <cstring>

const int MAXN = 3002;
const int P = 998244353;

int a[MAXN];
int64_t f[MAXN][MAXN];

int64_t solve(int n, int sum) {
  memset(f, 0, sizeof(f));
  int64_t ans = 0;
  for (int i = n; i > 0; --i) {
    if (sum > a[i]) ans += i * f[i + 1][sum - a[i]];
    else if (sum == a[i]) ans += i * (n + 1 - i);
    if (ans >= P) ans %= P;

    for (int j = 1; j <= sum; ++j) {
      f[i][j] = f[i + 1][j];
      if (j >= a[i]) f[i][j] += f[i + 1][j - a[i]];
      f[i][j] %= P;
    }
    f[i][a[i]] += n + 1 - i;
  }
  return ans;
}

int main() {
  int n, sum;
  std::cin >> n >> sum;
  for (int i = 1; i <= n; ++i) std::cin >> a[i];
  std::cout << solve(n, sum) << std::endl;
  return 0;
}


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

using namespace std;

using ll = long long;

int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    // cout << setprecision(8) << setiosflags(ios::fixed);

    constexpr ll MOD = 1e9 + 7;

    ll n, m;
    cin >> n >> m;

    vector<ll> s(n), t(m);
    for (ll &s_i : s) cin >> s_i;
    for (ll &t_i : t) cin >> t_i;

    vector<vector<ll>> dp(n + 1, vector<ll>(m + 1));
    for (int i = 0; i <= n; ++i) dp[i][0] = 1;
    for (int j = 0; j <= m; ++j) dp[0][j] = 1;

    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
            (dp[i][j] += dp[i][j - 1] + dp[i - 1][j] - dp[i - 1][j - 1] + MOD) %= MOD;
            if (s[i - 1] == t[j - 1]) (dp[i][j] += dp[i - 1][j - 1]) %= MOD;
        }
    }

    cout << dp[n][m] << endl;

    return 0;
}


Measured memory_bytes: 31616
H, N = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(N)]

dp = [10**9]*(H+1)
dp[0] = 0

for i in range(1, N+1):
    for j in range(H+1):
        a, b = ab[i-1]
        if j < a:
            dp[j] = min([dp[0]+b, dp[j]])
        else:
            dp[j] = min([dp[j-a]+b, dp[j]])
print(dp[H])


Measured memory_bytes: 44964
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define ALL(a) (a).begin(),(a).end()
#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 ll long long
#define ull unsigned long long
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

using namespace std;
int n,p;
int c;
vector<int> ro;
bool decide = false;
int solve(){
  REP(a,100000000){
  REP(i,n){
    if(c){
      ro[i]++;
      c--;
      if(ro[i] == p){
	cout << i <<endl;
	decide = true;
	break;
      }

    }
    else{
      c +=ro[i];
      ro[i] = 0;
    }
  }
  if(decide) break;
  }
  return 0;
}

  
int main(){

  while(true){
    cin >> n >> p;
    if(n==0&&p==0)break;
    c = p;
    ro.resize(n,0);
    solve();
    ro.clear();
    decide = false;
    
  }
  return 0;
}

Measured memory_bytes: 3056
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using pii=pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
#define all(c) begin(c),end(c)
#define rall(c) rbegin(c),rend(c)
#define fore(x,c) for(auto &&x:c)
#define rep(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define rrep(i, a, n) for(int i=(int)(n-1);i>=a;--i)
#define sz(c) ((int)c.size())
#define contains(c,x) (c.find(x)!=end(c))
#define inseg(l,x,r) ((l)<=(x)&&(x)<(r))
#define dump(...)
#define pb push_back
#define _ 0
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    for (auto i = begin(v); i != end(v); i++) os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    for (auto i = begin(v); i != end(v); i++) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a,const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a,const U &b){return a>b?a=b,1:0;}
template <class T> void psum(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        cin.tie(nullptr); ios::sync_with_stdio(0);
        cout << setprecision(15) << fixed;
        // #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int N, M;
    cin >> N >> M;
    vector<int> A(N), B(N);
    vector<vi> task(M+1);
    rep(i, 0, N) {
        cin >>A[i] >>B[i];
        if (M-A[i] >= 0) task[M-A[i]].push_back(B[i]);
    }
    priority_queue<int> pq;
    int ans = 0;
    rrep(i, 0, M+1) {
        while(sz(task[i])) {
            pq.push(task[i].back());
            task[i].pop_back();
        }
        if (sz(pq)) {
            ans += pq.top();
            dump(pq.top());
            pq.pop();
        }
    }
    cout << ans << endl;
    return (0^_^0);
}



Measured memory_bytes: 7168
ninnzuu = int(input())
zyousi_list = input().split()
zyousi_list_int = []
buka_list = []
for i in range(len(zyousi_list)):
    zyousi_list_int.append(int(zyousi_list[i]))
    buka_list.append(0)
buka_list.append(0)
for j in range(len(zyousi_list)):
    buka_list[zyousi_list_int[j]-1] += 1
for l in range(ninnzuu):
    print(buka_list[l])


Measured memory_bytes: 102772
#include<bits/stdc++.h>
#define range(i,a,b) for(long long i = (a); i < (b); i++)
#define rep(i,b) for(long long i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
using namespace std;
 
template <typename X, typename T>
auto vectors(X x, T a) {
	return vector<T>(x, a);
}
template <typename X, typename Y, typename Z, typename... Zs>
auto vectors(X x, Y y, Z z, Zs... zs) {
	auto cont = vectors(y, z, zs...);
	return vector<decltype(cont)>(x, cont);
}
template<typename T>
ostream& operator << (ostream& os, vector<T>& v){
	rep(i,v.size()){ os << v[i] << (i == v.size() - 1 ? "" : " "); } return os;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& v){
	for(T& x: v){ is >> x; } return is;
}

vector<string> getWord(string& s){
	vector<string> res;
	res.emplace_back("a");

	string u;
	rep(i,s.size()){
		u += s[i];
		if(s[i] == '"'){
			i++;
			string t = "a";
			while(s[i] != '"'){
				t += s[i++];
			}
			res.emplace_back(t);
		}
	}
	s = u;
	return res;
}

int main(){
	string s, t;
	while(cin >> s, s[0] != '.'){
		cin >> t;

		if(s == t){
			cout << "IDENTICAL" << endl;
			continue;
		}

		auto a = getWord(s), b = getWord(t);
		if(a.size() != b.size() or s != t){
			cout << "DIFFERENT" << endl;
			continue;
		}

		int diff = 0;
		rep(i,a.size()){
			diff += a[i] != b[i];
		}

		if(diff == 1){
			cout << "CLOSE" << endl;
		}else{
			cout << "DIFFERENT" << endl;
		}
	}
}



Measured memory_bytes: 3180
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

const ll INF = 1LL << 50;

static const long long mod = 1000000007;

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

  vll x1s(n), y1s(n), x2s(n), y2s(n);
  vll wxs, wys, vxs, vys;
  rep(i, n) {
    cin >> x1s[i] >> y1s[i] >> x2s[i] >> y2s[i];
    wxs.push_back(x1s[i]);
    wxs.push_back(x2s[i]);
    wys.push_back(y1s[i]);
    wys.push_back(y2s[i]);
  }
  Sort(wxs);
  Sort(wys);
  rep(i, 2*n) {
    if (i == 0 || wxs[i] != wxs[i - 1]) vxs.push_back(wxs[i]);
    if (i == 0 || wys[i] != wys[i - 1]) vys.push_back(wys[i]);
  }

  ll cW = vxs.size();
  ll cH = vys.size();
  vvll mp(cH, vll(cW, 0));
  rep(i, n) {
    ll ix = Lower_bound(vxs, x1s[i]);
    ll iy = Lower_bound(vys, y1s[i]);
    ll jx = Lower_bound(vxs, x2s[i]);
    ll jy = Lower_bound(vys, y2s[i]);
    mp[iy][ix]++;
    mp[jy][ix]--;
    mp[iy][jx]--;
    mp[jy][jx]++;
  }

  rep(i, cH) rep(j, cW - 1) mp[i][j + 1] += mp[i][j];
  rep(j, cW) rep(i, cH - 1) mp[i + 1][j] += mp[i][j];

  ll ans = 0;
  rep(i, cH-1) rep(j, cW-1) {
    if (mp[i][j] > 0) ans += (vys[i + 1] - vys[i]) * (vxs[j + 1] - vxs[j]);
  }

  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 128192
use itertools::Itertools;
use proconio::input;
use proconio::marker::{Chars, Usize1};
use std::cmp::*;
use std::collections::HashSet;
use std::iter::Iterator;

#[allow(unused_macros)]
macro_rules! max {
    ($x:expr) => {
      $x
    };
    ($x:expr, $($xs:tt)+) => {
      max($x,max!($($xs)+))
    };
  }

#[allow(unused_macros)]
macro_rules! min {
    ($x:expr) => {
      $x
    };
    ($x:expr, $($xs:tt)+) => {
      min($x,min!($($xs)+))
    };
  }

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    input! {
    n: u32,
    m: u32,
    }

    let mut s_connect_vec = vec![];

    for _ in 0..m {
        input! {
        k:u32,
        s:[u32;k]
        }
        s_connect_vec.push(s);
    }

    input! {
      p:[u32;m]
    }

    let mut cnt = 0;
    for i in 0..2u32.pow(n) {
        let mut s_vec = vec![];
        for op in 0..n {
            if i >> op & 1 == 1 {
                s_vec.push(1);
            } else {
                s_vec.push(0)
            }
        }

        let s_vec = s_vec.into_iter().rev().collect::<Vec<_>>();

        let mut allon = true;

        for i in 0..m{
            let mut on_cnt = 0;
            for &s in &(s_connect_vec[i as usize]) {

                if s_vec[(s-1) as usize] == 1 {
                    on_cnt += 1;
                }
            }

            if on_cnt % 2 == p[i as usize]{
            }else{
                allon = false;
                break;
            }
        }

        if allon {
            cnt += 1;
        }
    }

    println!("{}", cnt);
}


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

using namespace std;
#define ll long long
#define ld long double

#define endl '\n'
#define FAST                      \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0);
const ll mod = 1000000007;
const double PI = 3.141592653589793238463;
const int MAXN = 1e5 + 5;
ll fastPow(ll x, ll b)
{
    if (b == 0)
        return 1;
    else if (!(b & 1))
    {
        return fastPow(x * x, b / 2);
    }
    else
        return x * fastPow(x * x, (b - 1) / 2);
}
    //__builtin_popcount ();
    int main()
{
    FAST
int n,k;
cin>>n>>k;
ld arr[n];
for (int i = 0; i < n; i++)
{
    cin>>arr[i];
}
double ans=0;
double sum=0;
int pt=0;
int c=0;
for(int i=0;i<n;i++){
sum+=(((arr[i]*(arr[i]+1))/2)/arr[i]);
//cout<<sum<<endl;
if(c==k-1)
{
    ans=max(ans,sum);
    sum -= (((arr[pt] * (arr[pt] + 1)) / 2) / arr[pt]);
    pt++;
    c--;
}
c++;
}
//cout<<ans<<endl;
printf("%.12f",ans);

    return 0;
}

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

const int DIM = 11;

string str;

long long dp[DIM], nr[DIM];

int main( void ) {
    
    cin >> str;
    
    nr[str.length()] = 1;
    for( int i = (int) str.length() - 1; i >= 0; i -- ) {
        long long val = 0;
        
        for( int j = i; j <= (int) str.length() - 1; j ++ ) {
            val = val * 10 + ( str[j] - '0' );
            
            dp[i] += val * nr[j + 1] + dp[j + 1];
            nr[i] += nr[j + 1];
        }
    }
    
    cout << dp[0] << endl;
    return 0;
}

Measured memory_bytes: 256
//#pragma GCC target ("avx2,sse2")
//#pragma GCC optimization ("Ofast")
//#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree <pair <ll, int>, null_type, less <pair <ll, int> >, rb_tree_tag, tree_order_statistics_node_update>
#define ll long long
#define ull unsigned long long
#define db long double
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define fi first
#define se second
#define mp make_pair
#define up_b upper_bound
#define low_b lower_bound
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define endl "\n"

#define left fsdsdfoisf
#define sum dpsdfioppsf
#define assign xcvjlkdjfio
#define trie fksdfkjkfnjuiv
#define next sidlfjsfkl
#define merge sdfksdkfsldf

#define int long long

using namespace std;

void dout() {
    cerr << endl;
}
template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
    cerr << H << ' ';
    dout(T...);
}

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair <int, int> pii;

const int N = 1e5 + 7, inf = 1e18;
int n, h[N], dp[N];

void solve(int tc) {
    // check for (int i = 0; i < n; j++)
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> h[i];
    }
    for (int i = 0; i < N; i++) {
        dp[i] = inf;
    }
    dp[1] = 0;
    for (int i = 2; i <= n; i++) {
        if (i > 2) {
            dp[i] = min(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
        }
        dp[i] = min(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));
    }
    cout << dp[n];
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
    int tc = 1;
//    cin >> tc;
    for (int i = 0; i < tc; i++) {
        solve(i);
//        cleanup();
    }
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

#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--)

int main(){
    int n;
    scanf("%d",&n);
    int a = n / 100;
    int b = n % 10;
    if(a == b)
        printf("Yes\n" );
    else
        printf("No\n");
    return 0;
}


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

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

Measured memory_bytes: 3936
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace __gnu_pbds;
using namespace std;
 
typedef long long int ll;
typedef unsigned long long int sll;
typedef long double ld;
#define A 1000000007ll
#define D 100000000000000ll
#define B 998244353ll
#define C 1000000000000000000ll
#define M 4000
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define oset tree<pair<ll,ll>, null_type,less_equal<pair<ll,ll>>, rb_tree_tag,tree_order_statistics_node_update> 
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define ve vector
#define br break
#define PI acos(-1)
#define subt cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n" 

void change(ve<ll> &a,ll n)
{
    ll x[n+1];
    for(ll i=0;i<=n;i++)
        x[i]=0;
    for(ll i=0;i<n;i++)
    {
        x[max(1ll,i-a[i]+1)]++;
        if(i+a[i]+2<=n)
            x[i+a[i]+2]--;
    }
    for(int i=1;i<=n;i++)
        x[i]+=x[i-1];
    for(int i=1;i<=n;i++)
        a[i-1]=x[i];
}

int main() 
{
    FAST;
    ll n,k;
    cin>>n>>k;
    ve<ll> a(n);
    for(int i=0;i<n;i++)
        cin>>a[i];
    ll x=0;
    while(x<k)
    {
        bool b=0;
        for(int i=0;i<n;i++)
            if(a[i]<n)
                b=1;
        if(b)
        {
            change(a,n);
            x++;
        }
        else
            break;
    }
    for(int i=0;i<n;i++)
        cout<<a[i]<<' ';
    subt;
    return 0;
}


Measured memory_bytes: 6364
// https://atcoder.jp/contests/abc049/tasks/arc065_a

function main(arg) {
  let S = arg.trim();
  let T = S;
  
  do {
    S = T;
    T = S.replace(/(dreameraser|dreamerase|dreamer|dream|eraser|erase)$/, '');
  } while (T.length < S.length);
  if (T == '') {
    console.log('YES');
  } else {
    console.log('NO');
  }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 33176
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <deque>
#include <iomanip>
#include <queue>
using namespace std;
#define rep(i,n) for (ll i=0;i<n;i++)
#define REP(i,n) for (ll i=1;i<=n;i++)
#define PI 3.141592653589793238462643383279
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1e9 + 7;
const ll INF = 1000000000000000;



int main() {
	int s[] = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };
	int n;
	cin >> n;
	cout << s[n - 1] << endl;
	return 0;
}


Measured memory_bytes: 256
N = int(input())
H = [int(i) for i in input().split()]

ans = 0
while sum(H) > 0:
    pre = 0
    for i in range(N):
        if pre > 0 and H[i] == 0:
            break
        if H[i] != 0:
            H[i] -= 1
            pre = H[i] + 1
    ans += 1

print(ans)

Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
class Program
{
    static int GCD(int a, int b)
    {
        int mod = a % b;
        if(mod == 0)
            return b;
        else
            return GCD(b, mod);

    }
    public void slove()
    {
        int n = int.Parse(Console.ReadLine());
        int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray();
        int result = array.Aggregate(array[0], (ret, x) => GCD(ret, x));
        System.Console.WriteLine(result);        
    }
    
    static void Main(string[] args)
    {
        new Program().slove();
    }
}


Measured memory_bytes: 19680
#include <iostream>
#include <string>
#include <cmath>
#define EPS (1e-8)
using namespace std;
int main() {
    int N;
    cin >> N;
    int dig = to_string(N).size();
    int ans = dig % 2 ? N - pow(10, dig - 1) + 1 : 0;
    for (int i = 1; i < dig; i += 2) ans += 9 * pow(10, i - 1) + EPS;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<algorithm>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;
 
typedef long long ll;
const ll MOD = 998244353;
const ll INF = 1e18;
const ll MAX = 200010;

#define PB push_back
#define MP make_pair
#define F first
#define S second

template<typename T,typename U>
bool chmax(T& max, const U& x){
	if(max<x){
		max = x;
		return true;
	}
	return false;
}

template<typename T,typename U>
bool chmin(T& min, const U& x){
	if(min>x){
		min = x;
		return true;
	}
	return false;
}


long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

long long pow(long long x, long long n) {
    long long ret = 1;
    while (n > 0) {
        if (n & 1) ret = ret * x % MOD;  // n の最下位bitが 1 ならば x^(2^i) をかける
        x = x * x % MOD;
        n >>= 1;  // n を1bit 左にずらす
    }
    return ret;
}

int main(){
    COMinit();

    ll n,m,k;
    cin >> n >> m >> k;

    ll ans=0;

    for(ll i=0;i<=k;i++){
        ans = ans + COM(n-1,i)*m%MOD*pow(m-1,n-i-1)%MOD;
    }
    cout << ans%MOD << endl;
}

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

bool vis[101010];

int main() {
    int n,m;
    cin>>n>>m;
    vector<int> E[n];
    int ans[n];
    rep(i,m){
        int a,b;
        cin>>a>>b;
        a--,b--;
        E[a].push_back(b);
        E[b].push_back(a);
    }

    queue<int> que;
    que.push(0);
    vis[0]=true;

    while(!que.empty()){
        int cu=que.front();
        que.pop();
        for(auto to : E[cu]){
            if(!vis[to]){
                ans[to]=cu;
                vis[to]=true;
                que.push(to);
            }
        }
    }

    cout<<"Yes"<<endl;
    for(int i=1;i<n;i++) cout<<ans[i]+1<<endl;
}



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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

typedef long long ll;
typedef pair<ll,ll> P;

vector<pair<int,int>> make_seica(string str){
	vector<pair<int,int>> ret;
	if(str[0] == '0')ret.EB(1,0);
	else ret.EB(0,0);
	REP(i,str.size()-1){
		if(str[i] != str[i+1])ret.EB(str[i] - '0',i+1);
	}
	if(str[str.size() - 1] == '0')ret.EB(0,str.size());
	else ret.EB(1,str.size());
	
	while(ret.size() < 5005)ret.EB(1-ret.back().FI,str.size());
	
	return ret;
}

int solve_seica(vector<pair<int,int>>&a, vector<pair<int,int>> &b){
	int ret = INF;
	REP(i,a.size()){
		int now = 0;
		if(a[i].FI != b[b.size() - 1].FI)continue;
		REV(j,b.size()){
			int tmp = i - ((int)b.size() - 1 - j);
			if(tmp >= 0){
				now += (abs(a[tmp].SE - b[j].SE));
			}
			else{
				now += b[j].SE;
			}
		}
		ret = min(ret, now);
	}
	return ret;
}

int main(){
	
	int n;cin >> n;
	string s,t;cin >> s >> t;
	auto a = make_seica(s);
	auto b = make_seica(t);
		
	cout << min(solve_seica(a,b),solve_seica(b,a)) << endl;
	
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int inf = 1000000007;
vector<int> dx = {1,0,-1,0};
vector<int> dy = {0,1, 0,-1};

long long p2(int k) {
    long long  n = 1;
    while(k > 0) {
        n *= 2;
        n %= inf;
        k--;
    }
    return n;
}

int main(){
    int n;
    cin >> n;
    vector<int> a(n), l(n);
    rep(i,n) {
        cin >> a.at(i);
    }
    sort(a.begin(), a.end());
    
    l.at(0) = n-1;
    l.at(n-1) = n-1;
    rep(i,n) {
        if(i == 0 || i == n-1) continue;
        l.at(i) = abs(i - (n-i-1));
    }
    sort(l.begin(), l.end());
    
    //rep(i,n) cout << a.at(i) << " " << l.at(i) << endl;
    
    
    long long ans = 0;
    if(a != l) {
        cout << ans << endl;
        return 0;
    }else{
        int k = n/2;
        ans = p2(k);
    }
    
    cout << ans << endl;
    
}

Measured memory_bytes: 3992
#include <iostream>
#include <cmath>
#include <cassert>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
#include <queue>
#include <type_traits>
#include <fstream>
//#include <bits/stdc++.h>

typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

ll H, W, D;

// print(x, y, z);
// printVec(va.begin(), va.end());
void print(){ std::cout << std::endl; }
template <typename Head> void print(Head&& head) { std::cout << head << std::endl; }
template <typename Head, typename... Tail> void print(Head&& head, Tail&&... tail)
{
  std::cout << head << " ";
  print(std::forward<Tail>(tail)...); // or print(tail...);
}
template<typename Iterator> void printVec(Iterator begin, Iterator end)
{
  for (Iterator it = begin; it != end; it++) {
    std::cout << "[" << it - begin << "] " << *it << " ";
    if ((it - begin) % 20 == 19 || it == end - 1) { std::cout << std::endl; }
  }
}
template<typename Iterator> void printVecPair(Iterator begin, Iterator end)
{
  for (Iterator it = begin; it != end; it++) {
    std::cout << "[" << it - begin << "] " << it->first << " " << it->second << " ";
    if ((it - begin) % 10 == 9 || it == end - 1) std::cout << std::endl;
  }
}

template<typename T> T lminimum(const std::vector< T >& v) {return *std::min_element(v.begin(), v.end());}
template<typename T> T lmaximum(const std::vector< T >& v) {return *std::max_element(v.begin(), v.end());}
template<typename T> void lunique(std::vector< T >& v) {v.erase(std::unique(v.begin(), v.end()), v.end());}
template<typename T> void lsort(std::vector< T >& v) {std::sort(v.begin(), v.end());}
template<typename T> void lgreatersort(std::vector< T >& v) {std::sort(v.begin(), v.end(), std::greater<>());}
template<typename T> bool lnext_permutation(std::vector< T >& v) {return std::next_permutation(v.begin(), v.end());}

ll pos2idx(ll y, ll x)
{
  return y * W + x;
}

int main(int argc, char* argv[])
{
  ll Q;

  //std::ifstream ifs("input.txt");
  //std::cin.rdbuf(ifs.rdbuf());
  std::cin >> H >> W >> D;

  std::vector< std::pair< ll, ll > > grid(H*W+1);
  for (ll y = 0; y < H; y++) {
    for (ll x = 0; x < W; x++) {
      ll a;
      std::cin >> a;
      grid[a] = std::make_pair(y, x);
    }
  }

  std::vector< ll > dist(H*W+1);
  for (ll idx = 0; idx <= H*W; idx++) {
    if (idx < D) {
      dist[idx] = 0;
      continue;
    }
    ll tmp = abs(grid[idx].first - grid[idx-D].first) + abs(grid[idx].second - grid[idx-D].second);
    dist[idx] += dist[idx - D] + tmp;
  }

  std::cin >> Q;
  for (ll i = 0; i < Q; i++) {
    ll l, r;
    std::cin >> l >> r;
    std::cout << dist[r] - dist[l] << std::endl;
  }

  return 0;
}


Measured memory_bytes: 3200
/* Author: topcoderme123
   Date: 22nd june 2020 
*/

#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mod 1000000007
#define F first
#define S second
#define all(v) (v).begin(),(v).end()
#define np next_permutation
using namespace std;
using vi=vector<int>;
#define lp(i,n) for(int i=0;i<n;i++)
#define reps(i,j,n) for(int i=j;i<=n;i++)
#define vii vector<vi>
#define vb vector<bool>
#define pr pair<int,int>
#define vl vector<ll>
#define vs vector<string>
#define us unordered_map<int,int>
#define Mpq priority_queue<int>
#define mpq priority_queue<int,vi,greater<int>> 
#define eb emplace_back
#define prl pair<ll,ll>
#define vp vector<pr>

const int N=(int)5e5+11;

ll n,m;
ll fact[N];

ll invmod(ll x){
  ll y=mod-2,ans=1;
  while(y>0){
     if(y&1) ans=(ans*x)%mod;
     x=(x*x)%mod;
     y>>=1;
  }
  return (ans+mod)%mod;
}

void preprocess(){
  fact[0]=1;
  for(ll i=1;i<N;i++)
    fact[i]=(fact[i-1]*i)%mod;
}

ll comb(ll m,ll n){
  ll x=fact[m],y=invmod(fact[m-n]),z;
  z=invmod(fact[n]);
  ll ans=((x*y)%mod*z)%mod;
  return ans;
}
ll permut(ll m,ll n){
  ll x=fact[m],y=invmod(fact[m-n]);
  ll ans=(x*y)%mod;
  return ans;
}
void solve(){
    cin>>n>>m;
    ll ans=0;
    for(ll i=0;i<=n;i++){
       ll x=comb(n,i),y=permut(m,i),z,temp;
       z=permut(m-i,n-i);
       z=(z*z)%mod;
       temp=((x*y)%mod*z)%mod;
       if(i%2) ans=(ans-temp+mod)%mod;
       else ans=(ans+temp)%mod;
    }
    cout<<ans<<"\n";
}
int main(){
   ios_base::sync_with_stdio(0);
   cin.tie(nullptr);
   //assert(freopen("input.txt", "r", stdin));
   //assert(freopen("output.txt", "w", stdout));
   preprocess();
   solve();
   return 0;
}


Measured memory_bytes: 7488
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
#define why(n,x) int n;while(cin >>n,n!=x)
#define iFOR(i,x,n)for(int i=x;i<n;i++)
#define unless(flg) if ( !(flg) )
#define read cin<<
#define echo cout<<
#define fin <<'\n'
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
#define SWAP(a,b) ((a != b) && (a += b,b = a - b,a -= b))
#define cinf(n,x) for(int UNCH=0;UNCH<(n);UNCH++) cin >> x[UNCH];
#define fcin(n,x) for(int UNCH=1;UNCH<=(n);UNCH++) cin>> x[UNCH];
#define memmin(x) memset((x),-1,sizeof((x)))
#define memzer(x) memset((x), 0,sizeof((x)))
#define meminf(x) memset((x),0x3f,sizeof((x)))
#define int long long
typedef long long ll;
typedef pair < int , int >  pii;
typedef vector < int > vit;
typedef map < string , int > mstit;
typedef vector < pii > vpi ;
typedef greater < pii > gpi;
typedef priority_queue < pii , vpi , gpi > dijk ;
static const signed int INF = 0x3f3f3f3f;
static const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static const signed int SMOD = 1000000007;
static const signed int NMOD = 1000000009;
static const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static const signed int dy[]={0,-1,0,1,-1,1,-1,1};

bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>T abs(T &x){return x<0 ? -x : x;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}

inline void solve(){

  int n, temp,ans;
  cin >>n;
  temp=n;
  while(temp){
    ans+=temp%10;
    temp/=10;
  }
  cout <<(n%ans==0 ? "Yes" : "No" ) fin;


}


struct xyz{ xyz(){ cin.tie(0), ios::sync_with_stdio(false); cout <<fixed<<setprecision(12);};}xyzzy;
signed main(){solve();return 0;}


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

using namespace std;

int main(void){
	
  string s;
  int count = 0;
  int max = 0;
  cin >> s;
  
  for(int i = 0; i < 3 ; i++){
   if( s[i] == 'R' ){
     count++;
   }else{
    if(max < count)max = count;
     
     count = 0;
   }
    if(max < count)max = count;
  }
  
  cout << max;
  return 0;
}

Measured memory_bytes: 3588
S=input()
T=input()
for i in range(len(S)-1,len(T)-2,-1):
  a=''
  for j in range(len(T)):
    if S[i+1-len(T)+j]=='?':
      a=a+T[j]
    else:
      a=a+S[i+1-len(T)+j]
  if a==T:
    U=S[:i+1-len(T)]+a+S[i+1-len(T)+len(T):]
    c=''
    for k in range(len(U)):
      if U[k]=='?':
        c=c+'a'
      else:
        c=c+U[k]
    print(c)
    exit()
print('UNRESTORABLE')

Measured memory_bytes: 9096
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		String s = sc.nextLine();
		if((s.charAt(0)-0)>=97){
			System.out.println("a");
		}else{
			System.out.println('A');
		}
	}
}


Measured memory_bytes: 26840
from functools import reduce

N = int(input())
mod = 10**9 + 7


def powmod(val, n, mod):
    # vals = [val]*n
    # ret = reduce(lambda x, y: x * y % mod, vals)

    # return ret

    ret = 1
    for i in range(n):
        ret = ret * val % mod

    return ret


all = powmod(10, N, mod)
b = powmod(9, N, mod)
c = powmod(8, N, mod)

ans = (all - (2*b - c))%mod

print(ans)

Measured memory_bytes: 9492
n,k = gets.chomp.split(" ").map(&:to_i)
a = gets.chomp.split(" ").map(&:to_i)
b = Hash.new(0)
a.each do |num|
  b[num] += 1
end
c = b.sort_by{|k,v|v}
ans = 0
for i in 0..c.size-k-1
  ans += c[i][1]
end
puts ans

Measured memory_bytes: 43520
#include <bits/stdc++.h>
#define ll long long int
#define mp make_pair
#define pb push_back
#define ld long double
#define pii pair<int,int>
#define sz(x) (int)x.size()
#define piii pair<pii,pii>
#define precise cout<<fixed<<setprecision(10)
#define st first
#define nd second
#define ins insert
#define vi vector<int>
#define BOOST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
const int MAX=2005;
struct query
{
	int x,y,c;
};
query q[MAX*100];
int zlicz[MAX][MAX][2];
int pref[MAX*2][MAX*2][2];
int ans=0;
 
int get(int x1,int y1,int x2,int y2,int t)
{
	return pref[x2][y2][t]-pref[x2][y1-1][t]-pref[x1-1][y2][t]+pref[x1-1][y1-1][t];
}
 
int32_t main()
{
  BOOST;
  int n,k;
  cin>>n>>k;
  k*=2;
  int white=0,black=0;
  for (int i=1;i<=n;i++)
  {
  	int a,b;
  	char c;
  	cin>>a>>b>>c;
  	int c2;
  	if (c=='B')c2=0,black++;
  	else c2=1,white++;
  	q[i]={a,b,c2};
  	zlicz[(q[i].x)%k+1][(q[i].y)%k+1][q[i].c]++;
  }
  
  int xd1=0,xd2=0;
  for(int i=1;i<=k*2;i++)
    for (int j=1;j<=k*2;j++)
      for (int l=0;l<2;l++)
      {
      	xd1=0,xd2=0;
      	if (i>k)xd1=k;
      	if (j>k)xd2=k;
      	if (i-xd1>k || i-xd1<0 || j-xd2<0 || j-xd2>k)
      	{
      		while (true)
      		{
      			int a=0;
      			a++;
      		}
      	}
        pref[i][j][l]=
        pref[i][j-1][l]+pref[i-1][j][l]-pref[i-1][j-1][l]+zlicz[i-xd1][j-xd2][l];
      }
      
      int sum=0;
      int ile=k/2;
      int x,y;
	  for (int i=1;i<=k;i++)
	    for (int j=1;j<=k;j++)
       	for (int l=0;l<2;l++)
	      {
	        sum=0;
	        x=i,y=j;
	        sum+=get(x,y,x+ile-1,y+ile-1,l);
	        sum+=get(x+ile,y,x+ile*2-1,y+ile-1,l^1);
	        sum+=get(x,y+ile,x+ile-1,y+ile*2-1,l^1);
	        sum+=get(x+ile,y+ile,x+2*ile-1,y+2*ile-1,l);
	        ans=max(ans,sum);
	      } 
	    
	
  cout<<ans; 
  return 0;
}

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


public class Main {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();

		if (c >= b || a >= d) {
			pr.println(0);
		} else {
			pr.println(Math.min(b, d) - Math.max(a, c));
		}
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);

		solve();

		pr.close();
		sc.close();
	}

	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}


Measured memory_bytes: 23636