akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <bitset>
#include <functional>
#include <random>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<',';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head



const int N = 1e6+50;
int n,k,p,a[N];

int chk(int x) {
	//先右后左
	int now = p;
	PER(i,p+1,n) {
		while (now>1&&2*a[i]-a[now-1]<=x) --now;
		if (2*a[i]-a[now]<=x&&i-now+1>=k) return 1;
	}
	//先左后右
	now = p+1;
	REP(i,1,p) {
		while (now<n&&-2*a[i]+a[now+1]<=x) ++now;
		if (-2*a[i]+a[now]<=x&&now-i+1>=k) return 1;
	}
	//直接右
	REP(i,p+1,n) if (a[i]<=x&&i-p>=k) return 1;
	//直接左
	REP(i,1,p) if (-a[i]<=x&&p+1-i>=k) return 1;
	return 0;
}

int main() {
	scanf("%d%d",&n, &k);
	REP(i,1,n) scanf("%d",a+i);
	REP(i,1,n-1) if (a[i]<0&&a[i+1]>=0) p = i;
	if (p==0) {
		if (a[1]<0) printf("%d\n",-a[n-k+1]);
		else printf("%d\n",a[k]);
		return 0;
	}
	int l=0,r=1e9,ans;
	while (l<=r) {
		if (chk(mid))ans=mid,r=mid-1;
		else l=mid+1;
	}
	printf("%d\n",ans);
}









Measured memory_bytes: 640
#!/usr/bin/env python3
S = input()
y = int(S[:4])
m = int(S[5:7])
d = int(S[8:10])
ans = False


def solve():
    if y != 2019:
        return y < 2019
    if m != 4:
        return m < 4
    if d != 30:
        return d < 30
    return True

print(['TBD', 'Heisei'][solve()])

Measured memory_bytes: 3064
#include <vector>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <math.h>
#include <list>

using namespace std;

int sum_digit(int n) {
	if (n == 0) return 0;
	else return n % 10 + sum_digit(n / 10);
}
int absolute(int a) {
	if (a < 0) return -a;
	else return a;
}
void uniq(list<int> &lst) {
	auto itr = lst.begin();
	if (itr == lst.end()) return;
	int prev = *itr++;
	while(itr != lst.end()) {
		if (*itr == prev) {
			itr = lst.erase(itr);
		}
		else {
			prev = *itr++;
		}
	}
}
int main()
{
  int N; cin >> N;
  vector<int> H(N); for(int i = 0;i < N;i++) cin >> H.at(i);
  
  int count = 0;
  int localmax;
  for(int i = 0;i < N; i++){
    if(i == 0){
      count++;
      localmax = H.at(0);
    }else if(localmax <= H.at(i)){
      count++;
      localmax = H.at(i);
    }
  }
  
  cout << count << endl;
}

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

int n,m,a[N];
long long k[N],b[N],ans;

int read(){
	int x=0,f=1;char ch=getchar();
	for (;!isdigit(ch);ch=getchar()) if (ch=='-')  f=-f;
	for (;isdigit(ch);ch=getchar()) x=x*10+ch-'0';
	return x*f;
}

int main(){
	n=read();m=read();
	for (int i=1;i<=n;i++) a[i]=read();
	for (int i=1;i<=n-1;i++){
		int x=a[i],y=a[i+1];
		if (y<x) y+=m;
		k[x+1]+=-1;b[x+1]+=y+1;
		k[y+1]-=-1;b[y+1]-=y+1;
		b[y+1]+=y-x;b[x+m+1]-=y-x;
	}
	for (int i=1;i<=2*m;i++)
		k[i]+=k[i-1],b[i]+=b[i-1];
	ans=1ll<<60;
	for (int i=1;i<=m;i++)
		ans=min(ans,k[i]*i+b[i]+k[m+i]*(m+i)+b[m+i]);
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 7936
#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;

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    LL x, y, z, k;
    cin >> x >> y >> z >> k;

    LL a[1005], b[1005], c[1005];
    for( int i = 0; i < x; ++i ) cin >> a[i];
    sort( a, a + x, greater<LL>() );
    for( int i = 0; i < y; ++i ) cin >> b[i];
    sort( b, b + y, greater<LL>() );
    for( int i = 0; i < z; ++i ) cin >> c[i];
    sort( c, c + z, greater<LL>() );

    vector< LL > ab;
    for( int i = 0; i < x; ++i ) {
        for( int j = 0; j < y; ++j ) {
            ab.pb( a[i] + b[j] );

        }
    }
    sort( ab.begin(), ab.end(), greater<LL>() );

    vector< LL > ans;
    for( int i = 0; i < min( k, x * y ); ++i ) {
        for( int j = 0; j < z; ++j ) {
            ans.pb( ab[i] + c[j] );

        }
    }
    sort( ans.begin(), ans.end(), greater<LL>() );

    for( int i = 0; i < k; ++i ) cout << ans[i] << endl;

    return 0;
}



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

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    long long n, k;
    cin>>n>>k;
    long long arr[n];

    for (int i=0;i<n;i++)
        cin>>arr[i];

    sort(arr, arr+n, greater<int>());

    if (k>=n)
        cout<<0;
    else
    {
        long long sum=0;
        for (int i=k;i<n;i++)
            {
                sum+=arr[i];
            }
        cout<<sum;
    }



}


Measured memory_bytes: 1792
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Random;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) {
		FastScanner fs=new FastScanner();
		char[] line=fs.next().toCharArray();
		int sum=0;
		for (char c:line) sum+=c-'0';
		System.out.println(sum%9==0?"Yes":"No");
	}

	static final Random random=new Random();
	
	static void ruffleSort(int[] a) {
		int n=a.length;//shuffle, then sort 
		for (int i=0; i<n; i++) {
			int oi=random.nextInt(n), temp=a[oi];
			a[oi]=a[i]; a[i]=temp;
		}
		Arrays.sort(a);
	}
	
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		
		int nextInt() {
			return Integer.parseInt(next());
		}
		int[] readArray(int n) {
			int[] a=new int[n];
			for (int i=0; i<n; i++) a[i]=nextInt();
			return a;
		}
		long nextLong() {
			return Long.parseLong(next());
		}
	}

	
}


Measured memory_bytes: 36524
N, W = map(int, input().split())

dp = [0]  * (W + 1)
def knapsack():
  for i in range(N):
    w, v = map(int, input().split())
    for wk in range(W, w - 1, -1):
      tv = dp[wk - w] + v
      if tv > dp[wk]:
        dp[wk] = tv
  return max(dp)
print(knapsack())


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

#define mp make_pair
#define pb push_back
#define f first
#define s second 
#define sz(s) (int)s.size()
#define int long long	
#define all(s) s.begin(), s.end()
#define forn(i, x, y) for(int i = x; i <= y; i++)
#define forev(i, y, x) for(int i = y; i >= x; i--)

using namespace std;

const int maxn = (int)3e5 + 100;
const int mod = (int)998244353;
const int P = (int)1e6 + 7;
const int inf = (int)1e9 + 7;

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

int n, t[maxn], pw[maxn];
pii a[maxn];
vi vals;
void upd(int pos, int val){
	for(; pos < maxn; pos = (pos | (pos + 1)))
		t[pos] += val;
}
int get(int r){
	int res = 0;
	for(; r >= 0; r = (r & (r + 1)) - 1)
		res += t[r];
	return res;
}
void add(int &a, int b){
	a += b;
	if(a >= mod)
		a -= mod;
	if(a < 0)
		a += mod;
}
int ans;
main () {
	pw[0] = 1;
	forn(i, 1, maxn - 1)
		pw[i] = pw[i - 1] * 2ll % mod;
	cin >> n;
	forn(i, 1, n){
		cin >> a[i].f >> a[i].s;
		vals.pb(a[i].s);
	}
	sort(all(vals));
	sort(a + 1, a + n + 1);
	forn(i, 1, n){
		a[i].s = lower_bound(all(vals), a[i].s) - vals.begin() + 1;
		int tot = pw[n];
		add(tot, -pw[n - a[i].s]);
		add(tot, -pw[i - 1]);
		add(tot, -pw[n - i]);
		add(tot, -pw[a[i].s - 1]);
		add(tot, pw[i - get(a[i].s) - 1]);
		add(tot, pw[get(a[i].s)]);
		add(tot, pw[n - a[i].s - i + get(a[i].s) + 1]);
		add(tot, pw[a[i].s - 1 - get(a[i].s)]);
		upd(a[i].s, 1);
		add(ans, tot);
	}
	add(ans, -n);
	cout << ans;
}

Measured memory_bytes: 10612
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
using namespace std;
typedef pair<ll,ll> P;
const ll MAX_N=1e5;
ll A[MAX_N],N;
			
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>N;
	REP(i,N)cin>>A[i];
	sort(A,A+N);
	ll ans=0;
	ans-=A[0];
	ans+=A[N-1];
	REP(i,N-2){
		ll a=A[i+1];
		ans+=llabs(a);
	}
	cout<<ans<<endl;
	ll ite=1;
	FOR(i,1,N-1){
		if(A[i]<0){
			ite++;
		}else{
			break;
		}
	}
	FOR(i,ite,N-1){
		cout<<A[0]<<' '<<A[i]<<endl;
		A[0]-=A[i];
	}
	REP(i,ite){
		cout<<A[N-1]<<' '<<A[i]<<endl;
		A[N-1]-=A[i];
	}
}

Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
constexpr long long MOD = 1000000007;
using ll = long long;
int main() {
ll n;
ll border = 0;
ll x = 0;
cin >> n;
for (ll i = 1; i <= n; i++) {
    border += i;
    if (border >= n){
        x = border;
        border = i;
        break;
        }
}
for (ll i = 1; i <=border;i++){
    if (x-n==i) continue;
    cout << i << endl;
}
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <math.h>
using namespace std;

int main(void){
    int N, M;
    cin >> N >> M;
    int stuX[N], stuY[N];
    int checkX[M], checkY[M];
    for(int i = 0; i < N; i++)
        cin >> stuX[i] >> stuY[i];
    for(int i = 0; i < M; i++)
        cin >> checkX[i] >> checkY[i];

    double dis = INFINITY;
    int number;
    
    for(int i = 0; i < N; i++){
        dis = INFINITY;
        number = 0;
        for(int j = M-1; j >= 0; j--){
            if(dis >= abs(stuX[i]-checkX[j])+abs(stuY[i]-checkY[j])){
                dis = abs(stuX[i]-checkX[j])+abs(stuY[i]-checkY[j]);
                number = j+1;
            }
        }      
       cout << number << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF    	((ll)1ll<<60)
#define INF     	((int)1<<30)
#define EPS     	(1e-9)
#define MOD     	(1000000007ll)
#define fcout(a)	cout<<setprecision(a)<<fixed
#define fs 			first
#define sc			second
#define PI			(3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s; a=0;} return os;}
template<class T> void chmax(T &a, const T &b){if(a<b)a=b;}
template<class T> void chmin(T &a, const T &b){if(a>b)a=b;}
void YN(bool b){cout<<(b?"YES":"NO")<<endl;}
void Yn(bool b){cout<<(b?"Yes":"No")<<endl;}
void yn(bool b){cout<<(b?"yes":"no")<<endl;}

vl v;
int n;

bool check(int k){
	map<int,int> mp;
	rep(i,n-1){
		if(v[i+1]<=v[i]){
			if(k==1)return false;
			mp.erase(mp.upper_bound(v[i+1]),mp.end());
			int t=v[i+1];
			while(t!=0&&mp[t]==k-1){
				mp.erase(t);
				t--;
			}
			if(t==0)return false;
			else mp[t]++;
		}
	}
	return true;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin>>n;
	v.resize(n);
	rep(i,n)cin>>v[i];
	int ok=n,ng=0;
	while(ok-ng>1){
		int mid=(ok+ng)/2;
		if(check(mid))ok=mid;
		else ng=mid;
		//cout<<ok<<endl;
	}
	cout<<ok<<endl;
}



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

using namespace std;

#define DEBUG_MODE
#ifdef DEBUG_MODE
	#define _(n) n;
#else
	#define _(n) ;
#endif
#define DBG cerr << '!' << endl;
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(ll (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(ll (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define MOD 1000000007


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

int main()
{
	int n;cin >> n;
	vector<int> v(n);
	set<int> A;
	set<int> B;
	REP(i,n){
		cin >> v[i];
		if(i % 2 == 0)A.insert(v[i]);
		else B.insert(v[i]);
	}
	
	sort(ALL(v));
	int ans = 0;
	REP(i,n){
		if(i % 2 == 0){
			if(A.count(v[i]) == 0)ans++;
		}
		else{
			if(B.count(v[i]) == 0)ans++;
		}
	}
	
	cout << ans / 2 << endl;
	
	return 0;
}

Measured memory_bytes: 5376
n, x = map(int, input().split())

l = list(map(int, input().split()))

tmp = 0
li = []
for i in range(n):
    tmp += l[i]
    if tmp <= x:
        li.append(i)
    if tmp >= x:
        break

print(max(li) + 2)
# if tmp == x:
#     print(max(li) + 2)
# elif tmp > x:
#     print(max(li) + 1)





Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <vector>
#define rep(i, x, n) for (int i = x; i < n; i++)
using namespace std;
const long long INF = 1LL << 60;
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
int N;
long long h[100010];
long long dp[100010];
int main()
{
    int N;
    cin >> N;
    rep(i, 0, N) cin >> h[i];
    rep(i, 0, N) dp[i]=INF;
    dp[0]=0;
    rep(i, 1, N){
        chmin(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));
        if (i > 1) chmin(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
    }
    cout << dp[N-1]<<endl;
}

Measured memory_bytes: 1792
import java.awt.*;
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws Exception {
        FastReader sc = new FastReader();
//        double r=sc.nextInt();
        ArrayList<Double> arr=new ArrayList<>();
        for (double r=1;r<=100;r++) {
            arr.add(Math.PI * 2 * r);
        }
        System.out.println(arr.get(sc.nextInt()-1));
    }
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Measured memory_bytes: 25472
import sys

n = int(input())

c = [0]*(n+1)
c[0],c[1] = map(int,input().split())

for i in range(2,n+1):
    c[i] = int(input().split()[1])

dp = [[sys.maxsize]*(n+1) for i in range(n+1)]

for i in range(1,n+1):
    dp[i][i] = 0

for l in range(2,n+1) :#length of chain j-i+1
    for i in range(1,n-l+2):
        j = i +l - 1
        for k in range(i,j):
            dp[i][j] = min(dp[i][j],dp[i][k]+ dp[k+1][j]+c[i-1]*c[k]*c[j])


print(dp[1][n])

Measured memory_bytes: 7732
#! /usr/bin/env python
#coding utf-8
import numpy as np

N = int(input())
T, A = map(int, input().split())

heights = list(map(int, input().split()))
temps = [T - height * 0.006 for height in heights]
rank = np.array([abs(A - temp) for temp in temps])

print(rank.argmin() + 1)


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

using namespace std;

const int mod = 1007050321;
const int base = 521;
const int N = 2e5 + 5;
const int MOD = 1e9 + 7;
const int inf = 2e9;

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

    long long n,k;
    cin >> n >> k;

    if (n >= k) n = (n-k)%k + k;
    cout << min(min(n,abs(n-k)),abs(abs(n-k)-k));

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> 
#define ff first 
#define endl "\n"
#define ss second 
#define li list<int>
#define vi vector<int>
#define ll long long int
#define pii pair<int,int>
#define vii vector<pair<int,int> >
#define mp make_pair
#define pb push_back
#define setbits(x) __builtin_popcountll(x)
#define custom  pair<int,pair<int,int> >
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> pbds; 
#define mod 1000000007
ll power(int a,int n,int m){
    ll ans=1;
    while(n>0){
        if(n&1){
            ans=(ans*a)%m;
        }
        n=n>>1;
        a=((a%m)*(a%m))%m;
    }
    return ans;
}
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    ll n;
    cin>>n;
    ll weight;
    cin>>weight;
    ll w[n];
    ll v[n];
    for(int i=0;i<n;i++){
        cin>>w[i]>>v[i];
    }
    ll dp[n+1][weight+1];
    memset(dp,0,sizeof(dp));
    for(int i=1;i<=n;i++){
        for(int j=1;j<=weight;j++){
            if(w[i-1]<=j){
                dp[i][j]=v[i-1]+dp[i-1][j-w[i-1]];
            }
            dp[i][j]=max(dp[i][j],dp[i-1][j]);
        }
    }
    cout<<dp[n][weight];
    return 0;
}

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

#define rep(i, n) for ( ll i = 0; i < (n); ++i )
#define reps(i, n) for ( ll i = 1; i <= (n); ++i )
#define _rep(i, n) for ( ll i = (n) - 1; i >= 0; --i )
#define _reps(i, n) for ( ll i = n; i > 0; --i )
#define all(x) (x).begin(), (x).end()
#define _all(x) (x).rbegin(), (x).rend()

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

ll n, m, q;
ll a[50], b[50], c[50], d[50];
ll x[11];
ll ans = 0;

void dfs( ll r, ll num )
{
	if ( r > n ) {
		ll tmp = 0;
		rep( i, q ) {
			if ( x[b[i]] - x[a[i]] == c[i] ) {
				tmp += d[i];
			}
		}
		ans = max(ans, tmp);
		return;
	}

	for ( int i = num; i <= m; i++ ) {
		x[r] = i;
		dfs(r + 1, i);
	}
}


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

	rep( i, q ) {
		cin >> a[i] >> b[i] >> c[i] >> d[i];
	}

	dfs( 1, 1 );

	cout << ans << endl;

	return 0;
}


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

using namespace std;

using VI = vector<int>;
using VVI = vector<VI>;
using VB = vector<bool>;
using VVB = vector<VB>;
using VD = vector<double>;
using VVD = vector<VD>;
using VS = vector<string>;
using PII = pair<int, int>;
using VPII = vector<PII>;
using VL = vector<long long>;
using VVL = vector<VL>;

#define sz(var) (int)var.size()
#define REP(var, start, end) for(int var = start; var < (int)end; ++var)
#define REPC(var, start, end) for(int var = start; var <= (int)end; ++var)
#define CLEAR(var, with) memset(var, with, sizeof(var))
#define ALL(x) x.begin(), x.end()
#define LL long long
#define ULL unsigned long long
#define TIME cerr << "Time elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms" << endl;
#define DBG(x) cerr << x << endl;

/*
	http://abc072.contest.atcoder.jp/tasks/arc082_a
*/

const int MAXN = (int)1e5;
int n, cnt[MAXN + 10];
int solve()
{
	int ret = 1;
	for(int i = 0; i < MAXN; ++i)
	{
		int tmp = cnt[i], before = i - 1, after = i + 1;
		if(before >= 0) tmp += cnt[before];
		if(after < MAXN) tmp += cnt[after];
		ret = max(ret, tmp);
	}
	return ret;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
//	freopen("tmp.in", "r", stdin);
	//freopen("tmp.out", "w", stderr);
#endif
	cin >> n;
	
	CLEAR(cnt, 0);
	REP(i, 0, n) {
		 int x; cin >> x;
		 ++cnt[x];
	}

	cout << solve() << endl;

	return 0;
}

Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("3");
            WillReturn.Add("1 2 3");
            //YES
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("5");
            WillReturn.Add("1 2 3 4 5");
            //NO
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();
        int[] wkArr = InputList[1].Split(' ').Select(X => int.Parse(X)).ToArray();

        int OddCnt = wkArr.Count(X => X % 2 == 1);

        ////奇数の個数が2の倍数ならOK
        Console.WriteLine(OddCnt % 2 == 0 ? "YES" : "NO");
    }
}


Measured memory_bytes: 21728
def solve(n: int):
    l = len(str(n))

    digits = [0]*l

    for i in reversed(range(l)):
        digits[i] = n % 10
        n //= 10

    ans = max(sum(digits), 9*(l-1)+digits[0]-1)
    print(ans)


N = int(input())
solve(N)


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

using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    
    int year, month, day;
    
    scanf("%d/%d/%d", &year, &month, &day);
    
    if(year <= 2019 && month <= 4 && day <= 30){
        cout << "Heisei" << endl;
    }else{
        cout << "TBD" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin >> n;
  string s;
  cin >> s;
  string ans = "No";
  if (s.size()%2) {
    cout << ans << endl;
    return 0;
  }
  for (int i=0; i<n/2; i++) {
    if (s[i] != s[i+n/2]) {
      cout << ans << endl;
      return 0;
    }
  }
  ans = "Yes";
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
const int inf = 100100100;

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) {
    cin >> a[i];
    a[i]--;
  }
  vector<bool> seen(n,false);

  int cnt = 0;
  int current = 0;
  while(seen[a[current]] == false){
    seen[a[current]] = true;
    cnt++;
    if(seen[1] == true){
      cout << cnt << endl;
      return 0;
    }
    current = a[current];
  }
  cout << -1 << endl;
  
}


Measured memory_bytes: 3784
#include<stdio.h>
int N;//??°
	int i,i2,i3,i4;
	char map[8][8];//2????¬???????
	char kmap[100][8][8];
	int x,y;
int owari=0;

void ch(int x,int y){
	int i;
	for(i=-3;i<=3;i++){
		if(x+i>=0 && x+i<=7 && map[y][x+i]=='1'){
			map[y][x+i]='2';	
		}
	}
	for(i=-3;i<=3;i++){
		if(y+i>=0 && y+i<=7 &&map[y+i][x]=='1'){
			map[y+i][x]='2';
		}
	}	
}


int main(){
	scanf("%d",&N);
	
	for(i4=0;i4<N;i4++){
	for(i=0;i<8;i++){
		scanf("%s",map[i]);
	}
	scanf("%d %d",&x,&y);
	
		map[y-1][x-1]='2';
		owari=0;
		while(owari!=64){
		owari=0;
		for(i2=0;i2<8;i2++){
			for(i3=0;i3<8;i3++){
				if(map[i2][i3]=='2'){
					ch(i3,i2);
					map[i2][i3]='0';
					}
				else {owari++;}
					kmap[i4][i2][i3]=map[i2][i3];
			    }
		}
	}
}
	for(i4=0;i4<N;i4++){
		printf("Data %d:\n",i4+1);
	for(i=0;i<8;i++){
			for(i2=0;i2<=7;i2++){
			printf("%c",kmap[i4][i][i2]);
		}
		printf("\n");
	}
	}
	
	
return 0;
}

Measured memory_bytes: 604
R,G,B,N=map(int,input().split())
count=0
wa=0
for i in range(int(N/R)+1):
    for j in range(int((N-i*R)/G)+1):
        b=(N-i*R-j*G)/B
        if b>=0 and float.is_integer(b)==True:
            count=count+1

print(count)

Measured memory_bytes: 40556
def main():
    import sys
    N = int(input())
    A = ["?"]*N
    pos = N//2
    left = 0
    right = N
    if A[left] == "?":
        print(left)
        sys.stdout.flush()
        S = input()[0]
        if S == "V":
            return
        A[left] = S
    if A[right-1] == "?":
        print(right-1)
        sys.stdout.flush()
        S = input()[0]
        if S == "V":
            return
        A[right-1] = S
    for i in range(20):
        pos = (left+right)//2
        if A[pos] == "?":
            print(pos)
            sys.stdout.flush()
            S = input()[0]
            if S == "V":
                return
            A[pos] = S

        if (pos - left) % 2 == 0:
            if A[pos] == A[left]:
                left = pos
            else:
                right = pos
        else:
            if A[pos] != A[left]:
                left = pos
            else:
                right = pos


if __name__ == '__main__':
    main()


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

//#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

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;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{   
    gearup;
    ll h,w; cin >> h >> w;
    vvc c(h,vc(w));
    rep(i,h)rep(j,w)cin>>c[i][j];
    
    ll res = 0;
    rep(i,h){
        rep(j,w){
            if(c[i][j] == '#')continue;
            queue<pair<int,int>> que;
            que.push(make_pair(i,j));
            vvl dist(h,vl(w,-1));
            dist[i][j] = 0;

            while(!que.empty()){
                int x = que.front().first;
                int y = que.front().second;
                que.pop();

                res = max(dist[x][y],res);
                for(int k=0;k<8;k+=2){
                    int ex = x + dx[k];
                    int ey = y + dy[k];
                    if(ex < 0 || ex >= h || ey < 0 || ey >= w)continue;
                    if(c[ex][ey] == '#')continue;
                    if(dist[ex][ey] == -1){
                        dist[ex][ey] = dist[x][y] + 1;
                        que.push(make_pair(ex,ey));
                    }
                }
            }
        }
    }
    out(res);
}


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

#include <set>
#include <iterator>
using namespace std;
// using namespace __gnu_pbds;


#define f first
#define s second
#define pb push_back
#define all(x) x.begin(),x.end()

#define ll long long int
#define vi vector<int>
#define vii vector<pair<int,int> >
#define pii pair<int,int>
#define plii pair<pair<ll, int>, int>
#define piii pair<pii, int>
#define viii vector<pair<pii, int> >
#define vl vector<ll>
#define vll vector<pair<ll,ll> >
#define pll pair<ll,ll>
#define pli pair<ll,int>
#define mp make_pair
#define ms(x, v) memset(x, v, sizeof x)
#define pr_vec(v) for(int i=0;i<v.size();i++) cout << v[i] << " " ;

#define f_in(st) freopen(st,"r",stdin)
#define f_out(st) freopen(st,"w",stdout)

#define INF (ll)1e17
#define matrix vector<vector<ll> >

#define fr(i, a, b) for(i=a; i<=b; i++)
#define fb(i, a, b) for(i=a; i>=b; i--)
#define ASST(x, l, r) assert( x <= r && x >= l )
#define maxbits 9
#define maxmask (1ll<<maxbits)
// typedef tree<pll, null_type, less<pll>, rb_tree_tag,
//              tree_order_statistics_node_update>
//     new_data_set;
const int  N=(ll)2e3 +10, M=(ll)1e9+1 ;
const int mod =(ll)1e9+7 , MAX=(ll)1e6+10;
string fir="Monocarp",sec="Bicarp";

void work(){
	ll n,k;
	cin >> n >> k;
	vl a(n);
	for(ll i=0;i<n;i++)
		cin >> a[i];

	vl pref(n,0);
	for(ll i=1;i<n;i++)
		pref[i]=a[i-1]<=a[i];

	for(ll i=1;i<n;i++)
		pref[i]+=pref[i-1];

	vl mini(n,0),maxi(n,0);

	set<ll> s;

	for(ll i=0;i<k-1;i++){
		s.insert(a[i]);
		// s_maxi.insert(-a[i]);
	}

	for(ll i=k-1;i<n;i++){
		if(i>=k)
			s.erase(a[i-k]);
		s.insert(a[i]);

		mini[i-k+1]=(a[i-k+1]==*(s.begin()));
		maxi[i]=(a[i]==*(s.rbegin()));

	}

	for(ll i=0;i<n;i++){
	//	cout << pref[i] << " ";
	}

	vl issorted(n,0);
	ll anysorted=0;
	for(ll i=0;i<n;i++){
		if(i-k+1>=0)
			issorted[i]=(pref[i]-pref[i-k+1] == k-1);

		anysorted|=issorted[i];
	}

	ll ans=anysorted;
	if(issorted[k-1]==0)
		ans++;
	// cout << anysorted << "\n";

	for(ll i=k;i<n;i++){
		if(issorted[i])
			continue;
		if(mini[i-k] && maxi[i])
			continue;
		// cout << i << " ";
		ans++;
	}

	cout << ans << "\n";
	return;
	
}

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

	

	// to avoid printing in Scientific Notation like 2.14748e+09 and instead print: 2147483648.000000
	cout << fixed ;
	
	// precomp();
	ll t,z;
	// cin >> t;
	t=1;
	// z=t;
	while(t--){
			// cout << "Case #" << z-t << ": " << "\n";
	        work();
	
	}

	return 0;
}
	

Measured memory_bytes: 17408
#include "bits/stdc++.h"

using namespace std;

using ll = long long;

template<typename T> using V = std::vector<T>;
using Vi = V<int>;
using VVi = V<V<int>>;
using Vl = V<ll>;
using VVl = V<V<ll>>;
using Vs = V<string>;

template<typename T1, typename T2> using P = std::pair<T1, T2>;
using Pii = P<int, int>;
using Pll = P<ll, ll>;
using Pdd = P<double, double>;

template<typename T1, typename T2> using M = std::map<T1, T2>;
using Mii = M<int, int>;
using Msi = M<string, int>;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REP2(i,s,e) for(int i=(int)(s);i<(int)(e);++i)
#define RREP(i,s,e) for(int i=(int)(s);i>=(int)(e);--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin(),ie=(c).end();i!=ie;++i)
#define ALL(c) (c).begin(), (c).end()

const double PI = acos(-1);
const ll MOD = 1e9+7;

int n, m, a, b, k;
string s;

long long gcd(long long a, long long b) {
    return b ? gcd(b, a % b) : a;
}

std::vector<long long> divisors(long long n) {
    std::vector<long long> divisors;
    long long i = 1;
    while (i * i <= n) {
        if (n % i == 0) {
            divisors.push_back(i);
            if (i * i != n) {
                divisors.push_back(n/i);
            }
        }
        i++;
    }

    sort(divisors.begin(), divisors.end());
    return divisors;
}

int main() {
    cin >> a >> b >> k;

    int x = gcd(a, b);
    Vl v = divisors(x);
    std::cout << v[v.size()-k] << '\n';

    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

namespace {
}

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

    long base = (long) 1e10;
    long max_profit = (long) -1e10;

    for (int i = 0; i < n; i++) {
        long in;
        cin >> in;

        long profit = in - base;

        if (profit > max_profit)
            max_profit = profit;

        if (in < base)
            base = in;
    }

    cout << max_profit << endl;
    return 0;
}

Measured memory_bytes: 1164
# include <stdio.h>
# include <string.h>
# include <stdlib.h>
# include <iostream>
# include <vector>
# include <queue>
# include <stack>
# include <map>
# include <math.h>
# include <algorithm>
using namespace std;
# define lowbit(x) ((x)&(-x))
# define pi acos(-1.0)
# define MAXN 100005
# define eps 1e-5
# define MAXM 500001
# define MOD 100000007
# define INF 1000000000
# define mem(a,b) memset(a,b,sizeof(a))
# define FOR(i,a,n) for(int i=a; i<=n; ++i)
# define FO(i,a,n) for(int i=a; i<n; ++i)
# define bug puts("H");
typedef long long LL;
typedef unsigned long long ULL;
int _MAX(int a, int b){return a>b?a:b;}
int _MIN(int a, int b){return a>b?b:a;}


int main ()
{
    LL n, s, ans=-1, kk;
    scanf("%lld%lld",&n,&s);
    if (n<s) {puts("-1"); return 0;}
    LL temp=(LL)sqrt(n+0.5);
    for (LL i=2; i<=temp; ++i) {
        LL val=0, x=n;
        if (i!=temp && (n-s)%i==0) {
            kk=(n-s)/i+1;
            if (n/kk+n%kk==s) ans=kk;
        }
        while (x) val+=x%i, x/=i;
        if (val==s) {printf("%d\n",i); return 0;}
    }
    if (ans==-1) {
        kk=n-s+1;
        if (n/kk+n%kk==s) ans=kk;
    }
    if (ans==1) ans=-1;
    if (ans==-1 && n==s) ans=n+1;
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 256
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")
 
//#include <x86intrin.h>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <bitset> 
#include <vector>
#include <cmath>
#include <deque>
#include <queue>
#include <iomanip>
#include <stack>
#include <map>
#include <set>
//#include <ordered_set>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
 
//using namespace __gnu_pbds;
using namespace std;
 
//template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
     
#define F first
#define S second           
#define lb lower_bound               
#define ub upper_bound
#define pb push_back
#define pf push_front    
#define ppb pop_back
#define mp make_pair                                     
#define bpp __builtin_popcountll                                                                                        
#define sqr(x) ((x) * (x)) 
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define in insert
#define ppf pop_front
#define endl '\n'
//#define int long long
 
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
 
const int mod = (int)1e9 + 7;
const int N = (int)3e5 + 123;
const ll inf = (ll)1e18 + 1;
 
const double pi = acos (-1.0);
const double eps = 1e-9;                  
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};

int n, a[N]; 
vector <pii> v;
ll cnt[N];

inline void boost () {
   ios_base :: sync_with_stdio (0);
   cin.tie (0), cout.tie (0);
}
 
inline void Solve () {
   cin >> n;
   for (int i = 1; i <= n; i ++) cin >> a[i], v.pb ({a[i], i});
   v.pb ({0, 0});
   sort (all (v));
   int will = n + 1;
   for (int i = sz (v) - 1; i > 0; i --) {
      will = min (will, v[i].S);
      cnt[will] += 1ll * (v[i].F - v[i - 1].F) * (sz (v) - i);
   }
   for (int i = 1; i <= n; i ++) cout << cnt[i] << '\n';
}               

 
signed main () {                                       
   //#ifdef QWERTY
   //   freopen("input", "r", stdin);
   //#endif
// freopen (".in", "r", stdin);    
// freopen (".out", "w", stdout);              
   boost ();
   int tt = 1;
   //cin >> tt;   
   while (tt --) {
      Solve ();
   }                                               
   return 0;      
}                   

Measured memory_bytes: 5256
fun main(args: Array<String>) {
    val (N, K) = readIntList()
    val H = readLongList()
    println(H.sortedDescending().drop(K).sum())
}

fun readString() = readLine()!!
fun readStringList() = readLine()!!.split(" ")
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)


Measured memory_bytes: 82720
import java.util.Scanner;

public class Main {
    private static final int MOD = 1000000007;
    private static final int T = 0;
    private static final int A = 1;
    private static final int G = 2;
    private static final int C = 3;

    public static void main(final String[] args) {
        final Scanner scanner = new Scanner(System.in);
        final int length = scanner.nextInt();

        // A,G,C,T
        final int[][][][] table = new int[length + 1][4][4][4];

        table[0][0][0][0] = 1;

        for (int i = 0; i < length; i++) {
            for (int a = 0; a < 4; a++) {
                for (int b = 0; b < 4; b++) {
                    for (int c = 0; c < 4; c++) {
                        for (int d = 0; d < 4; d++) {
                            if (b == A && c == G && d == C
                                    || b == A && c == C && d == G
                                    || b == G && c == A && d == C) {
                                continue;
                            }

                            if (a == A && c == G && d == C
                                    || a == A && b == G && d == C) {
                                continue;
                            }

                            table[i + 1][b][c][d] = (table[i + 1][b][c][d] + table[i][a][b][c]) % MOD;
                        }
                    }
                }
            }
        }

        int result = 0;
        for (int a = 0; a < 4; a++) {
            for (int b = 0; b < 4; b++) {
                for (int c = 0; c < 4; c++) {
                    result = (result + table[length][a][b][c]) % MOD;
                }
            }
        }
        System.out.println(result);
    }
}


Measured memory_bytes: 23764
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int lld;

const lld mod = 1e9+7;
const lld INF = 1e9;
//const lld MAXN = 1e9;

int main()
{
	lld n=0;
	cin >> n;
	vector<vector<lld> > a(3,vector<lld>(n,0));
	for(int i = 0; i < 3; i++)
	{
		for(int j = 0; j < n; j++)
		{
			cin >> a[i][j];
		}
	}

	priority_queue<lld> front,back;

	lld A=0,C=0;
	for(int i = 0; i < n; i++)
	{
		A += a[0][i];
		C += a[2][i];
	}
	lld AA = A, CC = C;

	for(int i = 0; i < n; i++)
	{
		front.push(-a[0][i]);
		back.push(a[2][i]);
	}
	A *= -1;

	vector<lld> f(n),b(n);
	for(int i = 0; i < n; i++)
	{
		//cout << A << endl;
		front.push(-a[1][i]);
		A += -a[1][i];
		A -= front.top();
		front.pop();
		f[i] = -1*A;
	}
	for(int i = n-1; i >= 0; i--)
	{
		back.push(a[1][i]);
		C += a[1][i];
		C -= back.top();
		back.pop();
		b[i] = C;
	}

	lld ans = -INF * INF;
	ans = max(ans,AA-b[0]);
	ans = max(ans,f[n-1]-CC);
	for(int i = 0; i < n-1; i++)
	{
		ans = max(ans,f[i]-b[i+1]);
	}
	cout << ans << endl;

	return 0;
}

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

int n,k,res;

main(){
			ios::sync_with_stdio(false); cin.tie(0);
			cin>>n;
			cin>>k;
			for(int i=1; i<=n; i++){
				int x;
				cin>>x;
				res+= min(2*x, 2*abs(x-k));
			}
			
			cout<<res;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sz(c)       int(c.size())
#define rep(i,a,b)  for (int i=a; i<(b); ++i)
#define per(i,a,b)  for (int i=(b)-1; i>=(a); --i)
#define fore(c,...) for (auto &__VA_ARGS__:(c))
using namespace std;
using ll = long long;



int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	cout<<fixed<<setprecision(10);

	int N;
	cin>>N;
	vector<int> a(N),b(N);
	fore(a,i) cin>>i;
	fore(b,i) cin>>i;

	vector<int> c(N);
	iota(c.begin(),c.end(),1);

	int pa=0, pb=0, i=0;
	do {
		i++;
		if (c==a) pa=i;
		if (c==b) pb=i;
	} while (next_permutation(c.begin(),c.end()));

	cout<<abs(pa-pb)<<'\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O0")
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
const ll mod = 1e9+7;
const ll INF = 1e18;
#define All(a) (a).begin(),(a).end()
#define Pi acos(-1)

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << setprecision(15) << fixed;
  chrono::system_clock::time_point start,end;
  start = chrono::system_clock::now();

  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n) {
    cin >> a[i];
  }
  vector<ll> b;
  vector<ll> c;
  b.push_back(a[0]);
  rep(i,n-1) {
    if (a[i] < a[i+1]) {
      b.push_back(a[i+1]);
      c.push_back(1);
    }
    if (a[i] > a[i+1]) {
      b.push_back(a[i+1]);
      c.push_back(-1);
    }
  }
  ll money = 1000;
  ll kabu = 0;
  rep(i,c.size()) {
    if (c[i] == 1) {
      // 買う
      if (money >= b[i]) {
        kabu += money/b[i];
        money -= kabu*b[i];
      }
    }
    if (c[i] == -1) {
      // 売る
      money += kabu * b[i];
      kabu = 0;
    }
  }
  money += b[c.size()]*kabu;
  cout << money << '\n';

  end = chrono::system_clock::now();
  auto elapsed = chrono::duration_cast< chrono::milliseconds >(end - start).count();
  cerr << elapsed << "ms" << '\n';
}

Measured memory_bytes: 3648
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>

// container library
#include <bitset>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

using ll = long long;
using ld = long double;

template <class T>
ostream& operator<<(ostream& os, vector<T> v) {
    os << "[";
    for (auto vv : v) os << vv << ",";
    return os << "]";
}

template <class T>
ostream& operator<<(ostream& os, set<T> v) {
    os << "[";
    for (auto vv : v) os << vv << ",";
    return os << "]";
}

template <class L, class R>
ostream& operator<<(ostream& os, pair<L, R> p) {
    return os << "(" << p.first << "," << p.second << ")";
}

template <class K, class T>
ostream& operator<<(ostream& os, map<K, T> v) {
    os << "[";
    for (auto vv : v) os << vv << ",";
    return os << "]";
}

const ll MOD = 1000000007;
// const ll MOD = 998244353;
// const int INF = 1 << 25;
// const ll INF = 1LL << 50;
// const ld PI = acos(-1);
// const ld EPS = 1e-10;
// mt19937 mt(ll(time(0)));

template <typename T>
inline T sq(T a) { return a * a; }

template <typename T>
inline T iceil(T n, T d) { return (n + d - 1) / d; }

template <typename T>
T gcd(T a, T b) {
    if (a < b) return gcd(b, a);
    return b == 0 ? a : gcd(b, a % b);
}

template <typename T, typename U>
T ipow(T b, U n) {
    if (n == 0) return 1;
    if (n == 1) return b;
    return n % 2 == 0 ? mypow(b * b, n / 2) : mypow(b, n - 1) * b;
}

template <typename T, typename U>
T mpow(T b, U n) {
    if (n == 0) return 1;
    if (n == 1) return b % MOD;
    return n % 2 == 0 ? mypow(b * b % MOD, n / 2) : mypow(b, n - 1) * b % MOD;
}

int main() {
    int N, K;
    cin >> N >> K;
    int a[N];
    for (int i = 0; i < N; ++i) cin >> a[i];

    int idx[N];
    iota(idx, idx + N, 0);
    int pass = -1;
    vector<int> ans;

    for (int k = 0; k <= K; ++k) {
        sort(idx, idx + N, [&](int i, int j) { return a[i] < a[j]; });

        int last = idx[0];
        if (last == pass) last = idx[1];

        for (int i = 0; i < N; ++i) {
            if (i != pass && i != last) {
                ans.push_back(i + 1);
                --a[i];
            }
        }

        ans.push_back(last + 1);
        --a[last];
        pass = last;
    }

    if (any_of(a, a + N, [](int v) { return v < 0; })) {
        cout << -1 << endl;
    } else {
        cout << ans.size() << endl;
        for (int x : ans) cout << x << " ";
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#define ll long long
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;

int N;
ll W, w[110], v[110];
ll dp[110][100100] = {0};

int main() {
    cin >> N >> W;
    for (int i = 0; i < N; i++) cin >> w[i] >> v[i];

    for (int i = 0; i < N; i++) {
        for (int sum_w = 0; sum_w <= W; sum_w++) {
            // i番目の品物を選ぶ
            if (sum_w - w[i] >= 0) {
                chmax(dp[i+1][sum_w], dp[i][sum_w - w[i]] + v[i]);
            }

            // i番目の品物を選ばない
            chmax(dp[i+1][sum_w], dp[i][sum_w]);
        }
    }
    cout << dp[N][W] << endl;
}


Measured memory_bytes: 79360
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;

long long int power(long long int x, long long int n, long long int M) {
	long long int tmp = 1;

	if (n > 0) {
		tmp = power(x, n / 2, M);
		if (n % 2 == 0) tmp = (tmp*tmp) % M;
		else tmp = (((tmp*tmp) % M)*x) % M;
	}
	return tmp;
}

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

	cin >> N >> M;

	vector<int>divisor;
	long long int ans = 1;
	vector<long long int>by(200001);
	by[0] = 1;
	for (int i = 1; i <= 200000; i++) {
		by[i] = by[i - 1] * i;
		by[i] %= MOD;
	}
	for (int i = 2; i <= sqrt(M); i++) {
		int bag = 0;
		while (M%i == 0) {
			M /= i;
			bag++;
		}
		if (!bag)continue;
		ans *= by[N - 1 + bag];
		ans %= MOD;
		ans *= power(by[bag], MOD - 2, MOD);
		ans %= MOD;
		ans *= power(by[N - 1], MOD - 2, MOD);
		ans %= MOD;
	}
	if (M > 1) {
		ans *= N;
		ans %= MOD;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
string s;
int main(){
int ind=0;
cin>>s;
for(int k=0;k<s.size();k++){
   if(s[k]=='L' && k%2==0)
        ind=1;
   if(s[k]=='R' && k%2==1)
    ind=1;
}
if(!ind)
    cout<<"Yes";
        else cout<<"No";

return 0;
}

Measured memory_bytes: 256
n,k=map(int,input().split())
mod=1000000007

fac = [1]*(n+1)
inv = [1]*(n+1)
for i in range(2,n+1):
    fac[i] = fac[i-1]*i % mod
    inv[i] = pow(fac[i],mod-2,mod)

def nCk(n,k):
    return fac[n]*inv[k]%mod*inv[n-k]%mod
ans = 0
for i in range(min(k+1,n)):
    ans += nCk(n,i)*nCk(n-1,i)%mod
    ans %=mod
print(ans)

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

using namespace std;
using ll = long long;

#define REP(i, n) for (ll i = 0; i < n; i++)
#define INF 9223372036854775807
#define all(x) (x).begin(), (x).end()

ll ts = 1000000007;

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

  ll a, b;
  cin >> a >> b;

  cout << (a - 1) * (b - 1) << "\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define swap(a, b, type) { type _tmp = a; a = b; b = _tmp; }
typedef long long ll;
typedef unsigned long long ull;

int A[100];

int main()
{
	int N;

	cin >> N;
	rep(i, N) cin >> A[i];

	sort(A, A + N);

	cout << A[N - 1] - A[0] << endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
//
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
		int n=sc.nextInt();
		int ans =0;
		for (int i=1;i<=n;i++) {
			int digCount=digCount(i);
			if (digCount%2!=0) {
				ans++;
			}
		}
		System.out.println(ans);
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
	}
	//----------------------------------------
	//置き場
	static int digCount(int n) {
		int res = 0;
		while(n > 0) {
			res ++;
			n /= 10;
			}
		return res;
	}
	//----------------------------------------
}

Measured memory_bytes: 21844