akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define int long long
#define all(a) a.begin(), a.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e15;

map<int,int> prime_factor(int n){
    map<int,int> res;
    for(int i=2;i*i<=n;i++){
        while(n%i==0){
            ++res[i];
            n/=i;
        }
    }
    if(n!=1) res[n]=1;//
    return res;
}

long long mod_pow(long long x, long long n){
    if(n == 0) return 1;
    long long res = mod_pow(x*x % mod, n / 2);
    if(n & 1) res = res*x % mod;
    return res;
}

const int MAX_NUM = 200010;
long long fact[MAX_NUM], inv[MAX_NUM];

long long comb(long long n, long long k){
    if(n < k || n < 0 || k < 0) return 0;
    if(fact[0] == 0){
        fact[0] = 1; inv[0] = 1;
        for(int i = 1; i < MAX_NUM; i++){
            fact[i] = fact[i - 1] * i % mod;
            inv[i] = mod_pow(fact[i], mod - 2);
        }
    }
    return (((fact[n] * inv[k]) % mod) * inv[n - k]) % mod; 
}

long long hcomb(long long n, long long k){
    if(n == 0 && k == 0) return 1;
    return comb(n + k - 1, k);
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    map<int, int> mp = prime_factor(m);
    int ans = 1;
    for(auto it = mp.begin(); it != mp.end(); it++){
        int tmp = it -> second;
        ans = ans * comb(tmp + n - 1, n - 1) % mod;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3328
#include <queue>
#include <string>
#include <iostream>
#include <algorithm>
using namespace std;
struct state { int x, y, c; };
bool operator<(const state& s1, const state& s2) { return s1.c > s2.c; }
int dx[] = { 0, 1, 1, 1, 0, -1, -1, -1 };
int dy[] = { 1, 1, 0, -1, -1, -1, 0, 1 };
int H, W, dist[1009][1009]; string s[1009];
int main() {
	ios::sync_with_stdio(false);
	cin >> H >> W;
	priority_queue<state> que;
	for (int i = 0; i < H; i++) {
		cin >> s[i];
		for (int j = 0; j < W; j++) {
			if (s[i][j] == '.') {
				dist[i][j] = 0;
				que.push(state{ i, j, 0 });
			}
			else dist[i][j] = 1012345678;
		}
	}
	int ret = 0;
	while (!que.empty()) {
		state u = que.top(); que.pop();
		ret = max(ret, dist[u.x][u.y]);
		for (int i = 0; i < 8; i++) {
			int tx = u.x + dx[i], ty = u.y + dy[i];
			if (0 <= tx && tx < H && 0 <= ty && ty < W) {
				vector<int> v;
				for (int j = 0; j < 8; j++) {
					int rx = tx + dx[j], ry = ty + dy[j];
					if (0 <= rx && rx < H && 0 <= ry && ry < W && dist[rx][ry] != -1) {
						v.push_back(dist[rx][ry]);
					}
				}
				sort(v.begin(), v.end());
				if (v.size() >= s[tx][ty] - 48 && dist[tx][ty] > v[s[tx][ty] - 49] + 1) {
					dist[tx][ty] = v[s[tx][ty] - 49] + 1;
					que.push(state{ tx, ty, dist[tx][ty] });
				}
			}
		}
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 8232
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    a = int(readline())
    s = readline().strip()
    if a >= 3200:
        print(s)
    else:
        print('red')
    
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9080
H,N = map(int,input().split())
AB = []
 
for i in range(N):
    a,b = map(int,input().split())
    AB.append([a,b])
INF = 10**15
dp = [[INF]*(2*10**4+1) for i in range(N+1)]
for i in range(N+1):
    dp[i][0] = 0
 
for i in range(N):
    for j in range(1,2*10**4+1):
        dp[i+1][j] = min(dp[i][j],dp[i+1][j-AB[i][0]]+AB[i][1])
        
ans = float('inf')
for i in range(H,2*10**4+1):
    ans = min(ans,dp[N][i])
print(ans)

Measured memory_bytes: 192904
import sys
a = -1
count = 0
if __name__ == '__main__':
    N, Y = map(int, input().split())
    for x in range(N + 1):
        for y in range(N + 1):
            z = N - x - y
            if z < 0:
                break
            if 10000*x + 5000*y + 1000*z == Y:
                print(x, y, z)
                sys.exit()
    print(a, a, a)

Measured memory_bytes: 9196
#include <bits/stdc++.h>
using namespace std;
    
#define int long long
#define pb push_back
#define ub upper_bound
#define lb upper_bound
#define mp make_pair
#define F first
#define S second
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define rep(i,n) FOR(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define ve vector
#define vi vector<int>
#define vp vector<pair<int,int>>
#define vvi vector<vector<int>>
    
using ll = long long;
const ll INF = LLONG_MAX / 4 - 100;
ll mod = 1e9 + 7;
int dx[] = {-1,0,1,0}, dy[] = {0,1,0,-1};
int ddx[] = {-1,0,1,-1,1,-1,0,1}, ddy[] = {1,1,1,0,0,-1,-1,-1};
vector<ll> prime;
    
class fact {
public:
    int fmod = 1e9+7;
    vector<int> fac, inv;
    fact (int n, int Mod = 1e9+7) {
        fmod = Mod;
        fac = vector<int>(n + 1,0);
        inv = vector<int>(n + 1,0);
        fac[0] = 1; for (int i = 1; i < n + 1; i++) fac[i] = fac[i-1] * i % fmod;
        for (int i = 0;i < n + 1;i++) inv[i] = fact::POW(fac[i],fmod-2);
    }
    ll nCr(ll n, ll r) {if (n<r) return 0; return (fac[n] * inv[r] % fmod) * inv[n-r] % fmod;}
    ll POW(ll a, ll b) {ll c = 1; while (b > 0) {if (b & 1) {c = a * c%fmod;}a = a * a%fmod; b >>= 1;}return c;}
};
    
template <class T = ll> T in() {T x; cin >> x; return (x);}
void DEBUG(vector<int> a) {for(int i=0;i<a.size();i++)cout<<a[i]<<" ";cout<<endl;}
void EMP(int x) {cout<<"!!!"<<x<<"!!!"<<endl;}
ll GCD(ll a, ll b) {ll c; while (b != 0) {c = a % b; a = b; b = c;}return a;}
ll LCM(ll a, ll b) {return (a / GCD(a,b)) * b;}
ll POW(ll a, ll b) {ll c = 1; while (b > 0) {if (b & 1) {c = a * c%mod;}a = a * a%mod; b >>= 1;}return c;}
void PRI(ll n) {bool a[n + 1LL]; for (int i = 0; i < n + 1LL; i++) {a[i] = 1LL;}for (int i = 2; i < n + 1LL; i++) {if (a[i]) {prime.pb(i); ll b = i; while (b <= n) {a[b] = 0; b += i;}}}}
template <typename T> bool chmin(T& a, T b) {bool res=false;if(a>b)a=b,res=true;return res;}
template <typename T> bool chmax(T& a, T b) {bool res=false;if(a<b)a=b,res=true;return res;}
bool isSqrt(ll a) {return (pow(sqrt(a),2) == a) ? 1 : 0;}
void YesNo(bool a) {if (a) cout << "Yes"; else cout << "No"; cout << endl;}
void yesno(bool a) {if (a) cout << "yes"; else cout << "no"; cout << endl;}
void YESNO(bool a) {if (a) cout << "YES"; else cout << "NO"; cout << endl;}

long long extGCD(long long a, long long b, long long &x, long long &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    long long d = extGCD(b, a % b, y, x);
    y -= a / b * x;
    return d;
}

long long mul(long long a, long long b, long long mod) {
    long long keta[20] = {};
    long long c = b;
    long long now = 0;
    while (c != 0ll) {
        keta[now] = c % 10; c /= 10; now++;
    }
    long long res = 0;
    for (int i = 19; i >= 0; --i) {
        res *= 10; res %= mod;
        res += keta[i] * a % mod;
    }
    return res % mod;
}

void solve() {
    string s, t; cin >> s >> t;
    cout << t << s << endl;
}

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();    
}


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

signed main() {
    string S;
    cin >> S;

    vector<int> cnt(3);
    for (char c : S) cnt[c - 'a']++;
    sort(cnt.begin(), cnt.end());

    int ma = 0;
    for (int x : cnt) ma = max(ma, x - cnt[0]);
    cout << (ma > 1 ? "NO" : "YES") << endl;
}


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

int n;
vector<int> x;
vector<int> y;
double sum = 0.0;

void foreach_permutation(int n, std::function<void(int *)> f) {
  int indexes[n];
  for (int i = 0; i < n; i++) indexes[i] = i;
  do {
    f(indexes);
  } while (std::next_permutation(indexes, indexes + n));
}

int fact(int k){
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

int main() {
  cin >> n;
  // x.assign(n);
  // y.assign(n);


  for (int i = 0; i < n; i++)
  {
    int xx,yy;
    cin >> xx >> yy;
    x.push_back(xx);
    y.push_back(yy);
  }

  
  foreach_permutation(n, [](int *indexes) {
    for (int i = 0; i < n-1; i++)
    {
      // cout << "sum+" << sqrt((x[i]-x[i+1])*(x[i]-x[i+1]) + (y[i]-y[i+1])*(y[i]-y[i+1])) << endl;
      sum += sqrt((x[indexes[i]]-x[indexes[i+1]])*(x[indexes[i]]-x[indexes[i+1]]) + (y[indexes[i]]-y[indexes[i+1]])*(y[indexes[i]]-y[indexes[i+1]]));
    }    
  });

  printf("%.10lf\n",sum/fact(n));
  // cout << sum/fact(n) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define double long double
using namespace std;
const int MOD = 1000000007;
const int INF = 1e12;
using Graph = vector<vector<int>>;

int gcd(int a, int b){
	if(!a) return b;
	return gcd(b%a,a);
}

signed main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for( int i = 0; i < N; i++ ) cin >> A[i];

  vector<bool> IsPrime(1000100, true);
  vector<int> D(1000100, 1);
  IsPrime.at(0) = false;
  IsPrime.at(1) = false;
  for( int i = 2; i <= 1000000; i++ ){
    if( IsPrime.at(i) == true ){
      D[i] = i;
      for( int j = 2; i*j <= 1000000; j++ ){
        IsPrime.at(i*j) = false;
        D[i*j] = i;
      }
    }
  }

  bool fg1 = 1;
  bool fg2 = 1;
  set<int> fac;
  for( int i = 0; i < N; i++ ){
    int B = A[i];
    set<int> Afac;
    while( D[B] != B ){
      Afac.insert(D[B]);
      B /= D[B];
    }
    Afac.insert(B);
    for( auto m : Afac ){
      if( fac.count(m) ) fg1 = 0;
      if( m != 1 ) fac.insert(m);
    }
    if( fg1 == 0 ) break;
  }

  int G = gcd(A[0], A[1]);
  for( int i = 2; i < N; i++ ){
    G = gcd(G, A[i]);
  }
  if( G != 1 ) fg2 = 0;

  if( fg1 ) cout << "pairwise coprime" << endl;
  else if ( fg2 ) cout << "setwise coprime" << endl;
  else cout << "not coprime" << endl;



}

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

using namespace std;
string a="",b="";
string hanten(string str){
  string temp="";
  for(int i=0;i<str.size();i++){
    switch(str[i]){
      case 'U': temp+='D';break;
      case 'D': temp+='U';break;
      case 'R': temp+='L';break;
      case 'L': temp+='R';break;
    }
  }
  return temp;
}
int main(){
  int sx,sy,tx,ty;
  cin>>sx>>sy>>tx>>ty;
  for(int i=0;i<ty-sy;i++){a+='U';}
  for(int i=0;i<tx-sx;i++){a+='R';}
  b=hanten(a);
  cout<<a<<b<<"LU"<<a<<"RD"<<"RD"<<b<<"LU"<<"\n";
}


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

using namespace std;
const int N = 10000+ 5;
const int INF = 0x3f3f3f3f;

int a[N];
vector<int> v;
//using P = pair<int,int>;
//using LL = long long;

void Init(){
    for(int i = 0; i < N; i++)
        a[i] = 0;
}

char mat[N][N];

const int dir[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};

int main(){
    int n, m;
    cin >> n >> m;
    for(int i = 0; i < n; i++){
        cin >> mat[i];
    }

    auto fun = [=](int i, int j) -> bool {
        if(i < 0 || i >= n || j < 0 || j >= m) return false;
        return true;
    };

    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            if(mat[i][j] == '.') continue;
            bool is = false;
            for(int d = 0; d < 4; d++){
                int x = i + dir[d][0];
                int y = j + dir[d][1];
                if(fun(x, y)){
                    if(mat[x][y] == '#')
                        is = true;
                }
            }
            if(!is){
                printf("No\n");
                return 0;
            }
        }
    }
    printf("Yes\n");
}


Measured memory_bytes: 384
import java.util.*;

public class Main {
    public static void main(String args[])
    {
        Scanner s = new Scanner(System.in);
        int n=s.nextInt();
        int[] arr=new int[n];
        for(int i=0;i<n;i++)
        {
            arr[i]=s.nextInt();
        }
        int temp;
        int count=0;
        for(int i=0;i<n;i++)
        {
            temp=arr[0];
            for(int j=0;j<i;j++)
            {
                if(arr[j]>temp)
                    temp=arr[j];
            }
            if(arr[i]>=temp)
                count++;
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 21844
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#include<random>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define rrep(i,a) for(int i=(int)a-1;i>=0;--i)
#define REP(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RREP(i,a,b) for(int i=(int)a-1;i>=b;--i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
typedef std::vector<int> vi;
typedef std::vector<std::vector<int>> vvi;
typedef std::vector<long long> vl;
typedef std::vector<std::vector<long long>> vvl;
#define out(x) cout<<x<<"\n";
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n) / gcd(n, m)*abs(m);//gl=xy
}
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
using namespace std;


void solve(){
  int v,e;
  cin>>v>>e;
  vvi cost(v,vi(v,1e7));
  rep(i,e){
    int s,t,d;
    cin>>s>>t>>d;
    cost[s][t]=d;
  }
  int ans=1e7;
  rep(V,v){
    vvi dp(1<<v,vi(v,1e7));//dp[S][i]:訪問済み頂点が集合Sで表され,最後に訪れた頂点がiとなるときの最小コスト
    dp[0][V]=0;
    rep(bit,1<<v){
      rep(i,v){
        rep(j,v){
          if(bit&(1<<j))continue;
          chmin(dp[bit|1<<j][j],dp[bit][i]+cost[i][j]);
        }
      }
    }
    chmin(ans,dp[(1<<v)-1][V]);
  }
  if(ans!=1e7) cout<<ans<<"\n";
  else out(-1);
}

int main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
	cout<<fixed<<setprecision(15);
  solve();
	return 0;
}



Measured memory_bytes: 6228
package main

import (
	"fmt"
)

func main() {
	var s, t string
	fmt.Scan(&s, &t)

	var maxSubstrCount int
	for i := 0; i < len(s)-len(t)+1; i++ {
		var substrCount int
		for j := 0; j < len(t); j++ {
			if s[i+j] == t[j] {
				substrCount++
			}
		}
		if substrCount > maxSubstrCount {
			maxSubstrCount = substrCount
		}
	}
	fmt.Println(len(t) - maxSubstrCount)
}


Measured memory_bytes: 1788
#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
#include <algorithm>
#include <climits>
#include <iomanip>
#include <numeric>
#include <queue>
#include <math.h>
using namespace std;
struct hash_pair {
	template <class T1, class T2>
	size_t operator()(const pair<T1, T2>& p) const
	{
		auto hash1 = hash<T1>{}(p.first);
		auto hash2 = hash<T2>{}(p.second);
		return hash1 ^ hash2;
	}
};
#define FAST_IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
#define ff first
#define ss second 
#define pp pair
#define ULRED 1000000007
#define MS(x,y) (x-y>0?x-y:y-x) 
#define MAX(x,y) x>y?x:y
#define MIN(x,y) x>y?y:x
/*------------------------------------------------------------------*/

int main() {
	FAST_IO
		ll n, k;
	cin >> n >> k;
	vector<ll> h(n + 1, LLONG_MAX);
	vector<ll> dp(n + 1,LLONG_MAX);
	for (ll i = 1; i < n + 1; i++)
		cin >> h[i];
	
	dp[1] =0;
	for (ll i = 2; i < n + 1; i++)
	{
		for (ll j = i-1;(j>=i-k && j>0);j--)
		{
			//cout << j << " ";
			dp[i] = min( dp[j]+(MS(h[i],h[j])) , dp[i]);
		}
		//cout << endl;
	}
	/*
	for (ll i = 1; i < n + 1; i++)
		cout << dp[i] << " ";
	cout << endl;
	*/
	cout << dp[n]<<endl;
  return 0;
}




Measured memory_bytes: 1792
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<stdlib.h>
#include<cassert>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=500000004;
const double EPS=1e-10;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
char in[1100][1100];
int bfs[1100][1100];
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int main(){
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	for(int i=0;i<a;i++)scanf("%s",in[i]);
	int sr,sc;
	for(int i=0;i<a;i++)for(int j=0;j<b;j++){
		if(in[i][j]=='S'){
			sr=i;sc=j;
		}
	}
	for(int i=0;i<a;i++)for(int j=0;j<b;j++)bfs[i][j]=-1;
	bfs[sr][sc]=0;
	queue<pair<int,int> >Q;
	Q.push(make_pair(sr,sc));
	while(Q.size()){
		int row=Q.front().first;
		int col=Q.front().second;
		Q.pop();
		for(int i=0;i<4;i++){
			int tr=row+dx[i];
			int tc=col+dy[i];
			if(tr<0||tr>=a||tc<0||tc>=b){
				if(bfs[row][col]<=c){printf("1\n");return 0;}
				continue;
			}
			if(~bfs[tr][tc]||in[tr][tc]=='#')continue;
			bfs[tr][tc]=bfs[row][col]+1;
			Q.push(make_pair(tr,tc));
		}
	}
	int ret=mod;
	for(int i=0;i<a;i++)for(int j=0;j<b;j++){
		if(~bfs[i][j]&&bfs[i][j]<=c){
			int d=min(min(i,j),min(a-1-i,b-1-j));
			ret=min(ret,(d+c-1)/c);
		}
	}
	printf("%d\n",ret+1);
}

Measured memory_bytes: 5248
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.next().toLong()
    val aList = (0..n).map { sc.next().toLong() }
    val bList = (0 until n).map { sc.next().toLong() }
    println(problem135c(aList, bList).toString())
}

fun problem135c(aList: List<Long>, bList: List<Long>): Long {
    var count = 0L
    var takeOver = 0L
    bList.forEachIndexed { i, h ->
        var hero = h
        var m1 = aList[i] - takeOver
        if (m1 <= hero) {
            hero -= m1
            count += m1
        } else {
            m1 -= hero
            count += hero
            takeOver = 0L
            return@forEachIndexed
        }

        if (hero > 0L) {
            val m2 = aList[i + 1]
            if (m2 <= hero) {
                count += m2
                takeOver = m2
            } else {
                count += hero
                takeOver = hero
            }
            return@forEachIndexed
        }
        takeOver = 0L
    }
    return count
}

Measured memory_bytes: 58772
#include <stdio.h>


int main()

{

	int x, y;

	while (1) {

		scanf("%d %d", &x, &y);

		if (x == 0 && y == 0) {

			break;

		}

		if (x > y) {

			printf("%d %d\n", y, x);

		} else {

			printf("%d %d\n", x, y);

		}

	}

	return 0;

}

Measured memory_bytes: 600
#include <iostream>
#include <assert.h>
#include <vector>
#include <unordered_map>
#include <queue>
#include <climits>
#include <cmath>
#include <algorithm>
#include <unordered_set>
using namespace std;
constexpr int64_t MOD = 1e9 + 7;

// Combination
void COMinit(vector<int64_t>& fac, vector<int64_t>& finv, vector<int64_t>& inv) {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int32_t i = 2; i < (int32_t)fac.size(); 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;
  }
}

int64_t COM(int32_t n, int32_t k, vector<int64_t>& fac, vector<int64_t>& finv) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int64_t modpow(int64_t a, int64_t b, int64_t mod = 1000000007) {
  int64_t res = 1;
  for (a %= mod; b; a = a * a % mod, b >>= 1)
    if (b & 1) res = res * a % mod;
  return res;
}

void PowInit(vector<int64_t>& vec, int64_t base, int64_t N, int64_t MOD) {
  int64_t cur = base;
  vec[0] = 1;
  for (int i = 1; i <= N; i++) {
    vec[i] = cur;
    cur *= base;
    cur %= MOD;
  }
  return;
}

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

  int32_t N;
  cin >> N;
  if (N < 2) {
    cout << 0 << endl;
    return 0;
  }

  vector<int64_t> fac(N+1, 0);
  vector<int64_t> finv(N+1, 0);
  vector<int64_t> inv(N+1, 0);
  COMinit(fac, finv, inv);
  vector<int64_t> pow2(N+1,0);
  vector<int64_t> pow8(N+1,0);
  PowInit(pow2, 2, N, MOD);
  PowInit(pow8, 8, N, MOD);

  int64_t res = 0;
  for (int i = 2; i <= N; i++) {
    int64_t cur = COM(N, i, fac, finv) * (pow2[i] - 2);
    cur %= MOD;
    cur *= pow8[N-i];
    cur %= MOD;
    res += cur;
    res %= MOD;
  }
  cout << res << endl;

  
  return 0;
}


Measured memory_bytes: 42080
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main(int argc, char const *argv[])
{
    int n;cin>>n;
    double t,a;cin>>t>>a;
    double h;
    double min_val=100000.0;
    int ret = n+1;
    for(int i=0;i<n;++i){
        cin>>h;
        if(abs(a-(t-h*0.006))<min_val){
            min_val = abs(a-(t-h*0.006));
            ret = i;
        }
    }
    cout << ret+1 << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll MOD = 1e9+7;
int main()
{
  ll n;
  cin >> n;
  ll dp[n+5];
  memset(dp, 0, sizeof(dp));
  dp[0] = 1;
  for(int i = 3; i<=n; i++)
  {
    dp[i] = (dp[i-1] + dp[i-3])%MOD;
  }
  cout << dp[n] <<endl;
}

Measured memory_bytes: 3696
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define mod 1000000007
#define F first
#define S second


int main()
{
	ll n;
	cin>>n;
	ll a[n+10];
	ll c4=0,ce=0,co=0;
	for(ll i=1;i<=n;i++)
	{
		cin>>a[i];
		if(a[i]%4==0) c4++;
		if(a[i]%2==0 && a[i]%4!=0) ce++;
		if(a[i]%2!=0) co++;
	}
	//cout<<c4<<" "<<ce<<" "<<co<<endl;
	if(n/2<=c4)
	{
		cout<<"Yes"<<endl;
		return 0;
	}
	ll q=n-(c4*2)-1;
	if(co<=c4)
	{
		cout<<"Yes"<<endl;
		return 0;
	}
	cout<<"No"<<endl;

}  

Measured memory_bytes: 1024
/**   Created by: Marcos Portales
          Codeforces User: marcosportales
          Country: Cuba
          Copyright                    */
#include<bits/stdc++.h>
using namespace std;
/// Pragmas:
#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags
#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX
#pragma GCC target("avx2") //Enable AVX
/// Macros:
#define int long long
#define f first
#define s second
#define db(x) cerr << #x << ": " << (x) << '\n';
#define pb push_back
#define lb lower_bound
#define up upper_bound
#define all(x) x.begin() , x.end()
#define rall(x) x.rbegin() , x.rend()
#define enl '\n'
#define vi vector<int>
#define sz(a) int((a).size())
#define rep(i,n) for(int i=0;i<n;i++)
#define inv(i,x,y) for(int i=x;i>y;i--)
#define REP(i,x,y) for(int i=(x);i<(y);i++)
typedef pair<int,int> ii;
typedef long double ld;
typedef unsigned long long ull;
/// Constraints:
const int maxn = 400010;
const int mod = 1000000007;
const ld eps = 1e-9;
const int inf = ((1ll<<31ll)-1ll);
const int INF = 2000000000000000000ll;
const ld pi = acos(-1);
/// Prime Numbers:
// 2, 173, 179, 181, 197, 311, 331, 737, 1009, 2011, 2027, 3079, 4001, 10037, 10079, 20011, 20089;
// 100003, 100019, 100043, 200003, 200017, 1000003, 1000033, 1000037, 1000081;
// 2000003, 2000029, 2000039, 1000000007, 1000000021, 2000000099;
/// Functions:
#define lg2(x) 31 - __builtin_clz(x)
#define lgx(x,b) ( log(x) / log(b) )
/// Red-Black Tree Test.insert(x)late ---------------------------------
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//typedef tree < long long ,  null_type ,  less<long long> ,  rb_tree_tag ,  tree_order_statistics_node_update > ordered_set;
/// Quick Pow------------------------------------------------
int qpow(int b,int e){
    if( !e ) return 1;
    if( e & 1 ) return qpow(b,e-1) * b % mod;
    int pwur = qpow(b,e>>1);
    return (pwur * pwur) % mod;
}
int modinv(int x){
    return qpow(x,mod-2);
}
/// My Code -------------------------------------------------

int32_t main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout.setf(ios::fixed); cout.precision(0);
    srand(time(NULL));
    //freopen("a.in","r",stdin);
    //freopen("a.in","w",stdout);
    string s;
    cin>>s;
    int n=s.size();
    inv(i,n/2-1,0){
        if(s.substr(0,i)==s.substr(i,i)){
            cout<<2*i;
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,a,b,c,d; string s; int count=0;
  cin>>n>>a>>b>>c>>d>>s; string ans="Yes";
  for(int i=min(a-1,b-1);i<max(c-1,d-1)-1;i++){if(s.at(i)=='#'&&s.at(i+1)=='#'){ans="No"; break;}}
  if(ans=="Yes"&&c>d){for(int i=b-2;i+1<d;i++){if(s.at(i)=='.'&&s.at(i+1)=='.'&&s.at(i+2)=='.'){break;} else if(i==d-2){ans="No"; break;}}}
  cout<<ans<<endl;
}


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

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

using namespace std;

char top[8] = {'a', 'd', 'g', 'j', 'm', 'p', 't', 'w'};
char mark[5] = {'.', ',', '!', '?', ' '};

int main(){
  int n;
  cin >> n;
  REP(i, n){
    string line;
    cin >> line;
    int cnt = 0;
    REP(j, line.size()){
      if(line[j] == '0'){
        if(cnt == 0) continue;
        if(line[j-1] == '1')
          cout << mark[(cnt-1)%5];
        else{
          int kind = line[j-1] == '7' or line[j-1] == '9' ? 4 : 3;
          cout << char(top[line[j-1] - '2'] + (cnt - 1) % kind);
        }
        cnt = 0;
      }
      else cnt++;
    }
  cout << endl;
  }
  return 0;
}

Measured memory_bytes: 3180
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main(void){
  int n,i,x;
  const int mod=1e9+7;
  vector<P> px;
  
  cin >> n;
  for (i=0;i<n*2;i++){
    cin >> x;
    px.push_back(P(x,i));
  }
  
  sort(px.begin(),px.end());
  
  ll ans=1,an,bn;
  an=bn=0;
  for (i=0;i<n*2;i++){
    if (px[i].second < n){
      if (bn>0){
        ans=ans*bn%mod;
        bn--;
      }else{
        an++;
      }
    }else{
      if (an>0){
        ans=ans*an%mod;
        an--;
      }else{
        bn++;
      }
    }
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 2420
MAX = 5 * 10**5
SENTINEL = 2 * 10**9
cnt = 0

def merge(A, left, mid, right):
    n1 = mid - left;
    n2 = right - mid;
    L = A[left:left+n1]
    R = A[mid:mid+n2]

    global cnt

    L.append(SENTINEL)
    R.append(SENTINEL)
    i = 0
    j = 0

    for k in range(left, right):
        cnt += 1
        if L[i] < R[j]:
            A[k] = L[i]
            i += 1
        else:
            A[k] = R[j]
            j+= 1

def mergeSort(A, left, right):
    if left + 1 < right:
        mid = (left + right) // 2;
        mergeSort(A, left, mid)
        mergeSort(A, mid, right)
        merge(A, left, mid, right)

n = int(input())
s = list(map(int, input().split()))
mergeSort(s, 0, len(s))

ans = []
for item in s:
    ans.append(str(item))
print(' '.join(ans))
print(cnt)


Measured memory_bytes: 71728
N = int(input())
*A, = map(int,input().split())

P = [0]*N
for i,a in enumerate(A):
    P[a-1] = i

class UnionFind:
    def __init__(self,N):
        self.Parent = [-1]*N
        self.Min = [-1]*N
        self.Max = [-1]*N
    def get_Parent(self,n):
        if self.Parent[n] == -1:return n
        p = self.get_Parent(self.Parent[n])
        self.Parent[n] = p
        return p
    def get_min(self,n):
        p = self.get_Parent(n)
        return self.Min[p]
    def get_max(self,n):
        p = self.get_Parent(n)
        return self.Max[p]
    def merge(self,x,y):
        x = self.get_Parent(x)
        y = self.get_Parent(y)
        if x!=y: 
            self.Min[x] = min(self.Min[x],self.Min[y])
            self.Max[x] = max(self.Max[x],self.Max[y])
            self.Parent[y] = x
        return
    def is_united(self,x,y):
        return self.get_Parent(x)==self.get_Parent(y)
    def create(self,n):
        if self.Min[n] == -1:
            self.Min[n] = n
            self.Max[n] = n

T = UnionFind(N)
ans = 0
for i in range(N-1,-1,-1):
    p = P[i]
    T.create(p)
    if p-1>=0 and T.get_min(p-1)!=-1:
        T.merge(p,p-1)
    if p+1<N and T.get_min(p+1)!=-1:
        T.merge(p,p+1)
    ans += (i+1)*(p-T.get_min(p)+1)*(T.get_max(p)-p+1)
print(ans)

Measured memory_bytes: 25700
import java.util.Scanner;
 public class Main {
 
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
      int N = scanner.nextInt();
      int M = scanner.nextInt();
      int a =0;
      for(int i=0; i<M; i++){ 
        a +=scanner.nextInt();
      }
      if(N<a){
      System.out.println("-1");
      }
      else{
      System.out.println(N-a);
    }
    }
 }

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

int main(){
  int N;
  cin >> N;
  long ans = 1;
  
  for(int i=1; i<N+1; i++){
    ans = ans * i;
    ans = ans %1000000007;
  }
  
  cout << ans << endl;

}

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

long long as[200001];

int main() {
  int N;
  long long sum = 0;
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", as + i);
    sum += as[i];
  }

  long long best_diff = LLONG_MAX;
  long long current_sum = 0;
  for (int i = 0; i <= N - 2; i++) {
    current_sum += as[i];
    sum -= as[i];

    long long diff = llabs(current_sum - sum);
    if (diff < best_diff) {
      best_diff = diff;
    }
  }
  
  printf("%lld\n", best_diff);
}


Measured memory_bytes: 1664
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		ArrayList<Integer> num = new ArrayList<Integer>();
		ArrayList<String> param = new ArrayList<String>();
		int system = 0; // 文字の空白区切り 0:ON 1:OFF

		while (sc.hasNext()) {
			if (sc.hasNextInt()) {
				num.add(sc.nextInt());
			} else {
				if (system == 0)
					param.add(sc.next());
				if (system == 1)
					param.add(sc.nextLine());
			}
		}
		Method(num, param);
	}

	static void Method(ArrayList<Integer> num, ArrayList<String> param) {
		int total = 0;
		int answer = 0;

		for(int i = 1; i <= num.get(0); i++){
			total += num.get(i);
		}

		try{
		for(int i = 0; i < num.size(); i+=2){
			answer = total - num.get(num.get(num.get(0)+2+i));
			answer = answer + num.get(num.get(0)+3+i);
			System.out.println(answer);
		}
		} catch(Exception e){
			System.exit(0);
		}
	}
}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
using namespace std;
int main(){
  string w[110];
  int n;
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> w[i];
  }
  bool ans = true;
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      if(w[i]==w[j]){
        ans = false;
      }
    }
  }
  for(int i=0;i<n-1;i++){
    if(w[i].back() != w[i+1].front()){
      ans = false;
    }
  }
  if(ans == true){
    cout << "Yes" <<endl;
  }else{
    cout << "No" << endl;
  }
  }


Measured memory_bytes: 256
l=list(input())
n=len(l)
p=10**9+7
dp1=[0]*n
dp2=[0]*n
dp1[0]=1
dp2[0]=2
for i in range(1,n):
    if l[i]=="1":
        dp1[i]=(3*dp1[i-1]+dp2[i-1])%p
        dp2[i]=(dp2[i-1]*2)%p
    else:
        dp1[i]=(3*dp1[i-1])%p
        dp2[i]=dp2[i-1]
print((dp1[n-1]+dp2[n-1])%p)


Measured memory_bytes: 72544
#include <iostream>

using namespace std;

int main()
{
    int N; cin >> N;
    int* H;
    H = new int [N];
    for (int i=0; i<N; i++) {
        cin >> H[i];
    }

    int rightCntMax = 0;
    int rightCnt = 0;
    int ptr = 0;

    while(ptr < N -1) {
        if (H[ptr] >= H[ptr+1]) {
            rightCnt++;
            if (rightCnt > rightCntMax) {
                rightCntMax = rightCnt;
            }
        }
        else {
            rightCnt = 0;
        }
        ptr++;
    }

    cout << rightCntMax << endl;
    delete [] H;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
int main() {
    ll a,b,c,x,y;
    cin >> a >> b >> c >> x >> y;
    ll ans = a*x+b*y;
    if(x>y){
        ans = min(ans,c*y*2+a*(x-y));
        ans = min(ans,c*2*x);
    }
    else {
        ans = min(ans,c*x*2+b*(y-x));
        ans = min(ans,c*2*y);
    }
    cout << ans << endl;
}

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

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

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



const int md = (int) 1e9 + 7;
const int maxn = 100100;
int n, m;
ll dp[maxn];
bool bad[maxn];

void add(ll& a, ll b) {
    a += b;
    if (a >= md) a -= md;
}


int main() 
{
    memset(bad, true, sizeof(bad));
    scanf("%d %d", &n, &m);
    for (int i = 0; i < m; ++i) {
        int a;
        scanf("%d", &a);
        bad[a] = false;
    }
    dp[1] = bad[1];
    dp[2] = dp[1] + bad[2];
    eprintf("dp[1] = %lld\n", dp[1]);
    eprintf("dp[2] = %lld\n", dp[2]);
    for (int i = 3; i <= n; ++i) {
        if (bad[i] == 0) continue;
        if (bad[i - 1] == false && bad[i - 2] == false) {
            return !printf("0\n");
        }
        if (bad[i - 1]) {
            add(dp[i], dp[i - 1]);
        }
        if (bad[i - 2]) {
            add(dp[i], dp[i - 2]);
        }
    }
    printf("%lld\n", dp[n]);
}


Measured memory_bytes: 1152
# A
Q, H, S, D = map(int, input().split())
N = int(input())

# UPDATE
H = min(2*Q, H)
S = min(2*H, S)
D = min(2*S, D)

if N % 2 == 0:
    print((N //2) * D)
else:
    print((N //2) * D + S)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <algorithm>
#include <math.h>
#include <queue>
#include <cstdio>
using namespace std;

template <class T> using V = vector<T>;
template <class S, class T> using P = pair<S, T>;
template <class... T> using TP = tuple<T...>;

using ll = long long;
using db = double;
using ldb = long db;
using str = string;
using vll = V<ll>;
using vvll = V<V<ll>>;
using pll = P<ll,ll>;
using tpll = TP<ll,ll,ll>;
using vpll =V<pll>;
using vvpll = V<vpll>;
using vtpll = V<tpll>;
using vst = V<str>;
using vch = V<char>;

#define FOR(i,a,b) for(ll i=(a);i<(ll)(b);i++)
#define rFOR(i,a,b) for(ll i=(b);i>(ll)(a);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(ll)(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) __lcm(a,b)
#define co(a) cout<<a<<endl
#define ci(a) cin>>a
#define pb(a) push_back(a)
#define pob pop_back()
#define mp make_pair
#define mt make_tuple
#define pbmp(a,b) push_back(mp(a,b))
#define subs(a,b) substr(a,b)
#define cfs(a) cout<<fixed<<setprecision(a) //
#define INF 1e16
#define mod 1e9+7
/*vvll v(n,vll(m)) n行m列
A.erase(A.begin()+i); 配列Aのi番目を消せる
std::binary_search(v.bgn,v.en,a); 二分探索
abs(a,b)   pow(a,n)  to_string  stoll
auto Iter=lower_bound(v.bgn,v.en,a); v[i]>=aのv[i]
v.insert(lower_bound(v.bgn,v.en,a),b); bを入れられる
lower upper  co(*Iter) co(Iter-v.bgn) v[i]>=aのi
priority_queue<ll> pque;  pque.push(ai);
pque.top()=max(ai)  pque.pop() pque.sz
*/

const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
void Comuse() {
    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;
    }
}
#define comuse Comuse()
ll combi(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;
}

int main(){
  ll n,m;
  cin>>n>>m;
  vpll v(n);
  FOR(i,0,n){
    cin>>v[i].fi>>v[i].se;
  }
  priority_queue<ll> pque;
  SORT(v);
  ll c=0;
  ll ans=0;
  FOR(i,1,m+1){
    FOR(j,c,n){
      if(v[j].fi==i){
        pque.push(v[j].se);
      }
      else{
        c=j;
        break;
      }
      //co(pque.top());
    }
    if(pque.sz>0){
      ans+=pque.top();
      pque.pop();
    }
  }
  co(ans);
}


Measured memory_bytes: 2936
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
using namespace std;
int main(){
  string s;
  cin >> s;
  int length = (s.size()+1)/2;
  rep(i,length){
    cout << s[2*i];
  }
  cout << endl;
}
//(ノ)>◡<(ヾ)ﾓﾁﾓﾁ

Measured memory_bytes: 512
#include <stdio.h>
#include <string.h>

int main(){
    char str[20], C;
    int i;
    unsigned long l;
    
    scanf("%s",str);
    l = strlen(str);
    for (i=0; i<=l/2-1; i++) {
        C=str[i];
        str[i]=str[l-i-1];
        str[l-i-1]=C;
    }
    printf("%s\n",str);
    
    return 0;
}

Measured memory_bytes: 524
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1e9+7;
const LL LINF=1LL<<62;
const int INF=1<<17;

int main(){
    string s;
    cin >> s;
    int a[3]={};
    for(int i=0;i<s.length();i++){
        a[s[i]-'a']++;
    }
    int mini=INF;
    if(max({a[0],a[1],a[2]})-min({a[0],a[1],a[2]})<=1) puts("YES");
    else puts("NO");
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
# define ll int64_t
# define str string
# define rep(i,n) for(ll i=0;i<n;i++)
# define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007
# define PI 3.141592653589793
# define vec vector
#define dump(x) cerr<<#x<<"="<<x<<endl
using namespace std;



#define INF 2000000000
#define MAX_V 10



bool compare_by_b(pair<string,ll> a,pair<string,ll> b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

bool my_compare(pair<string,ll> a,pair<string,ll> b){
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}

ll modpow(ll a,ll n,ll mod1) {
    ll res=1;
    while(n>0){
        if(n&1) res=res*a%mod1;
        a = a*a%mod1;
        n >>= 1;
    }
    return res;
}

ll factorial(ll n){
    ll x=1;
    rrep(i,n) (x*=i)%=mod;
    return x;
}

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

ll lcm(ll a,ll b){
   return a/gcd(a,b)*b;
}
const ll MAX = 5100000;
const ll MOD = 1000000007;
 
ll fac[MAX], finv[MAX], inv[MAX];
 
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll 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;
    }
}

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

using graph = vector<vector<ll>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll sx,sy,gx,gy;
    cin>>sx>>sy>>gx>>gy;
    string u,d,l,r;
    rep(i,gy-sy){
        u=u+"U";
        d=d+"D";
    }
    rep(i,gx-sx){
        l=l+"L";
        r=r+"R";
    }
    cout<<u<<r<<d<<l<<"L"<<u<<"UR"<<r<<"DR"<<d<<"DL"<<l<<"U"<<endl;
    return 0;
}

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

// 比較関数
bool my_compare(pair<int, int> a, pair<int, int> b) {
    // 基本はfirstで比較
    if(a.first != b.first){
        // return a.first < b.first; // 昇順
        return a.first > b.first; // 降順
    }

    // それ以外はsecondで比較
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        // どちらも同じ
        return true;
    }
}

int main(){
    vector<pair<int, int> > V;
  int n,d;cin>>n;
for(int i=0;i<n;i++){
  cin>>d;
    V.push_back(make_pair((-1)*d,i+1));
}
    

    sort(V.begin(), V.end(), my_compare);

    for(int i=0; i<V.size(); i++){
        //cout << V[i].first << ' ' << V[i].second << endl;
      cout<<V[i].second<<" ";
    }
}

Measured memory_bytes: 1780
import sys
import heapq
from collections import Counter
h, w = [int(i) for i in sys.stdin.readline().split()]
c_ls = []
A = dict()
for i in range(10):
    c_ls.append([int(i) for i in sys.stdin.readline().split()])
c_ls_true = {i : [0 for j in range(10)] for i in range(10)}
for i in range(10):
    for j in range(10):
        c_ls_true[i][j] = c_ls[j][i]

shortest_path = {-1 : 0}
que = [(0, 1)]
already = set()
while len(que) > 0:
    cur_cost, cur = heapq.heappop(que)
    if cur in already:
        continue
    already.add(cur)
    shortest_path[cur] = cur_cost
    for _next, cost in enumerate(c_ls_true[cur]):
        if _next not in already:
            heapq.heappush(que, (cur_cost + cost, _next))
    if len(already) == 10:
        break
ct = Counter()
for i in range(h):
    inp = [int(i) for i in sys.stdin.readline().split()]
    A[i] = inp
    ct.update(inp)
res = 0
for k, v in ct.items():
    res += shortest_path[k] * v
print(res)

Measured memory_bytes: 40428
Ss = input()

c1 = 0
c2 = 0
for i in range(0, len(Ss)):
    if i & 1:
        if Ss[i] == '0':
            c1 += 1
        else:
            c2 += 1
    else:
        if Ss[i] == '1':
            c1 += 1
        else:
            c2 += 1
print(min([c1, c2]))

Measured memory_bytes: 39536
a, b, c, d = map(int, input().split())
if a < c:
    if c < b and b < d:
        print(b - c)
    elif c < b and d <= b:
        print(d - c)
    else:
        print(0)
else:
    if a < d and d < b:
        print(d - a)
    elif a < d and b <= d:
        print(b - a)
    else:
        print(0)


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

using namespace std;

int main(int, char**)
{
	int y, m, d;
	char c, c2;
	cin >> y >> c >> m >> c2 >> d;
	if(m > 4) 
		cout << "TBD" << endl;
	else
		cout << "Heisei" << endl;
	return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

typedef pair<int, int> P;

int main() {
	int n;
	while(cin >> n && n){
		int x, y;
		vector<P> poles;
		for(int i = 0; i < n; ++i){
			scanf("%d %d", &x, &y);
			poles.push_back(P(x, y));
		}
		sort(poles.begin(), poles.end());
		int ans = 0;
		for(int i = 0; i < n; ++i){
			for(int j = n - 1; j >= i; --j){
				int nx = poles[j].first - poles[i].first;
				int ny = poles[j].second - poles[i].second;
				if(ans > (nx * nx + ny * ny))
					continue;
				if(!(binary_search(poles.begin(), poles.end(), P(poles[i].first - ny, poles[i].second + nx))))
					continue;
				if(!(binary_search(poles.begin(), poles.end(), P(poles[j].first - ny, poles[j].second + nx))))
					continue;
					
				ans = max(ans, (nx * nx + ny * ny));
			}
		}
		cout << ans << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1300
from collections import deque

H, W = map(int, input().split())

S = [[c == '.' for c in input()] for _ in range(H)]

INF = 10 ** 5


def get_new_maze():
    return [[INF for _ in range(W)] for _ in range(H)]


def get_max_distance(w_start, h_start):
    if not S[h_start][w_start]:
        return -1
    maze_map = get_new_maze()
    q = deque()
    q.append([w_start, h_start, 0])

    ret_dist = 0

    while len(q) > 0:
        next_q = q.popleft()
        h = next_q[1]
        w = next_q[0]
        g = next_q[2]
        if S[h][w] and maze_map[h][w] > g:
            maze_map[h][w] = g
            ret_dist = max(g, ret_dist)
            if h > 0:
                q.append([w, h - 1, g + 1])
            if h < H - 1:
                q.append([w, h + 1, g + 1])
            if w > 0:
                q.append([w - 1, h, g + 1])
            if w < W - 1:
                q.append([w + 1, h, g + 1])

    return ret_dist


ans = 0

for c in range(W):
    for r in range(H):
        ans = max(ans, get_max_distance(c, r))

print(ans)

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

int main(){
    int n;
    cin >> n;
    priority_queue<ipair,vector<ipair>,greater<ipair>> p;
    for(int i=0; i<n; i++){
        int a,b;
        cin >> a >> b;
        p.push(make_pair(b,a));
    }
    ll sum=0;
    bool flag=true;
    while(!p.empty()){
        ipair tmp=p.top();p.pop();
        sum+=tmp.second;
        if(tmp.first<sum){
            flag=false;
            break;
        }
    }
    if(flag)cout << "Yes";
    else cout << "No";
    cout << endl;
}

Measured memory_bytes: 2420
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}
 
ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------

ll dp[1010][100100] = {0};
int main(void){
    int h, n;
    cin >> h >> n;

    for(int i = 0; i < 1010; i++){
        for(int j = 0; j < 100100; j++){
            dp[i][j] = INF;
        }
    }

    dp[0][0] = 0;

    vector<int> w(n);
    vector<int> v(n);
    for(int i = 0; i < n; i++) cin >> v[i] >> w[i];

    for(int i = 0; i < n; i++){
        for(int j = 0; j <= h * 10; j++){
            dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
            if(j >= v[i]){ 
                dp[i + 1][j] = min(dp[i + 1][j], dp[i + 1][j - v[i]] + w[i]);
            }
            //cout << i + 1 << "-" << j << " " << dp[i + 1][j] << endl;
        }
    }

    ll ans = INF;
    for(int i = h; i <= h * 10; i++){
        ans = min(ans, dp[n][i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 790144
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;

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 INF = 1LL << 60;

int main(){
  int n; cin >> n;
  vector<int> t(n+1), x(n+1), y(n+1);
  t[0]=0, x[0]=0, y[0]=0;
  REP(i, 1, n) cin >> t[i] >> x[i] >> y[i];

  REP(i, 1, n){
    int tmp = (t[i]-t[i-1]) - abs(x[i]-x[i-1]) - abs(y[i]-y[i-1]);
    if(tmp%2 == 1 || tmp<0){
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;

  return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
typedef vector<pii > vii;
typedef vector<pair<int, pair<int, int> > > viii;
typedef pair<ll,ll> pll;
typedef vector<string> vs;
typedef vector<vii> vvii;

#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define MEM(a,b) memset(a,(b),sizeof(a))
#define all(a) a.begin(),a.end()
#define loop(x,a,b) for(int (x) = (a);(x)<(b);(x)++)
#define rep(x,n)   for(int (x)=0;(x)<(n);(x)++)
#define tr(c,it) for(typeof((c).begin()) it = (c).begin(); it != (c).end(); it++)
#define present(c,x) ((c).find(x) != (c).end()) 
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define ain(a,n) int ((a)[(n)]); for(int i=0; i<(n); i++) cin>>((a)[i])  
#define md 1000000007
#define MAXN 200005

int main()
{   
    ios::sync_with_stdio(false);

    int k, a, b;
    cin >> k >> a >> b;
    if (a%k == 0 || b%k == 0)
    	cout << "OK\n";
    else {
    	if (b/k - a/k > 0) {
    		cout << "OK\n";
    	}
    	else {
    		cout << "NG\n";
    	}
    }
    return 0;
}




Measured memory_bytes: 3640