akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

long long f(long long b, long long n)
{
    if (n < b) {
        return n;
    } else {
        return f(b, (long long) (n / b)) + (n % b);
    }
}

int main()
{
    long long n, s, b;
    cin >> n >> s;

    if (s == n) {
        cout << n + 1 << endl;
        return 0;
    }

    for (b = 2; b * b <= n; ++b) {
        if (f(b, n) == s) {
            cout << b << endl;
            return 0;
        }
    }

    for (long long p = b; p >= 1; --p) {
        long long b = (n - s) / p + 1;
        if (b >= 2) {
            if (f(b, n) == s) {
                cout << b << endl;
                return 0;
            }
        }
    }

    cout << "-1" << endl;

    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
  int n,cont;
  while(scanf("%d",&n)!=EOF){
    cont=0;
    for(int i=0;i<10;i++){
      for(int j=0;j<10;j++){
	for(int k=0;k<10;k++){
	  for(int l=0;l<10;l++){
	    if(i+j+k+l==n)cont++;
	  }
	}
      }
    }
    cout<<cont<<endl;
  }
}

Measured memory_bytes: 1208
#include<iostream>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
using namespace std;

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

  map<string,long long> cnt;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    cnt[s]++;
  }

  long long ans = 0;

  for (auto &iter: cnt) {
    string s = iter.first;
    long long c = iter.second;
    if (c == 1) continue;

    ans += c * (c - 1) / 2;
  }

  cout << ans << endl;
}


Measured memory_bytes: 11136
n,m=gets.split.map &:to_i;
d=[0]*m;
d[0]=1;
$<.map{|s|
	a=0;
	d=s.chop.chars.zip(d).map{|c,d|a=c==?. ? d+a : 0}
}
p d[-1].%10**9+7

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

int main() {
  
  long long N,M;
  cin >> N >> M;

  long long ans = 0;

  if(M >= 2 * N) {
    ans += N;
    M -= 2 * N;
    ans += M / 4;
  }else {
    ans += M / 2;
  }

    cout << ans << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define rep(i, a, b) for (int i = a; i < b; i++)
#define ff first
#define pii pair<int, int>
#define vii vector< pair<int,int> >
#define vi vector<int>
#define vvi vector< vector< int> >
#define vs vector<string>
#define ss second
#define pb push_back
#define mp make_pair
#define int long long
#define ll long long
#define all(a) a.begin(), a.end()
#define inf (1LL<<61)
#define ull unsigned long long
#define tr1(x)                cout<<#x<<": "<<x<<endl
#define tr2(x, y)             cout<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define tr4(x, y, z, d)          cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<" | "<<#d<<": "<<d<<endl
#define tr3(x, y, z)          cout<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define db1(x) cerr << #x << ": " << x <<'\n'
#define db2(x, y) cerr << #x << ": " << x << '\t' << #y << ": " << y <<'\n'
#define db3(x, y, z) cerr << #x << ": " << x << '\t' << #y << ": " << y << '\t' << #z << ": " << z <<'\n'
using namespace std;
int dx[]={1,0,-1, 0};int dy[]={0,1,0, -1}; //4 Direction
//int dx[]={1,1,0,-1,-1,-1,0,1};int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction
bool compare(const pair<pair<string,int>, int> &a,const pair<pair<string,int>, int> &b)
{
    if(a.ff.ff == b.ff.ff) {
        return (a.ff.ss > b.ff.ss);
    }
    return (a.ff.ff<b.ff.ff);
}
int min(int a, int b){
    if(a<b){
        return a;
    }
    else{
        return b;
    }
}
int max(int a, int b){
    if(a>b){
        return a;
    }
    else{
        return b;
    }
}
int max(int a, int b, int c){
    return(max( max(a,b), c ));
}
int min(int a, int b, int c){
    return (min ( min(a,b) , c));
}
int poww(int a, int b)
{
    int res = 1;
    for(int i = 1; i<=b; ++i)
        res *= a;

    return res;
}
int findlcm(int arr[], int n) 
{ 
    // Initialize result 
    int ans = arr[0]; 
  
    // ans contains LCM of arr[0], ..arr[i] 
    // after i'th iteration, 
    for (int i = 1; i < n; i++) 
        ans = (((arr[i] * ans)) / 
                (__gcd(arr[i], ans))); 
  
    return ans; 
}
bool prime[100001];
void SieveOfEratosthenes(int n) 
{
    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++)
    {
        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
  }
}

//Define mx for maximum range and MOD for large numbers
#define mx 500005
#define mod 1000000007 

// Declare all the variables and global functions here -
int n, m;
int fact(int n){
    if(n==1 || n==0){
        return 1;
    }
    return(n*fact(n-1));
}
int32_t main(){
    IOS;
    int n,k;
    cin >> n >>k;
    if(k == 1){
        cout << 0 << endl;
        return 0;
    }
    cout << n-k << endl;

}   

Measured memory_bytes: 256
#include <iostream>
using namespace std;
void knapSack(long int W, long int wt[],long int val[],long int n) 
{ 
   long int i, w; 
long    int K[n + 1][W + 1]; 
  
    // Build table K[][] in bottom up manner 
    for (i = 0; i <= n; i++) { 
        for (w = 0; w <= W; w++) { 
            if (i == 0 || w == 0) 
                K[i][w] = 0; 
            else if (wt[i - 1] <= w) 
                K[i][w] = max( 
                    val[i - 1] + K[i - 1][w - wt[i - 1]], 
                    K[i - 1][w]); 
            else
                K[i][w] = K[i - 1][w]; 
        } 
    } 
  
    cout<<K[n][W]; 
} 
int main() {
   long int n,i,w,j;
   cin>>n>>w;
   long int a[n],b[n];
   for(i=0;i<n;i++)
   cin>>a[i]>>b[i];
   knapSack(w,a,b,n);
   /*long int dp[n+1][w+1];
   for(i=0;i<=n;i++)
   {
       for(j=0;j<=w;j++)
       {
           if(i==0||j==0)
           dp[i][j]=0;
           else if(w>=a[i-1])
           {
               dp[i][j]=max(dp[i-1][j],b[i-1]+dp[i-1][j-a[i-1]]);
           }
           else
           dp[i][j]=dp[i-1][j];
       }
   }
   cout<<dp[n][w];*/
	return 0;
}

Measured memory_bytes: 79104
#include <bits/stdc++.h>
using namespace std;
int main() {
    int a, b, c, d;
    while (cin >> a >> b >> c >> d) {
        int ta, tb;
        ta = a / d + (a % d != 0);
        tb = c / b + (c % b != 0);
        cout << (ta >= tb ? "Yes" : "No") << '\n';
    }
    return 0;
}

Measured memory_bytes: 3648
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include <iomanip>
using namespace std;

int main(){
	long long int a,b,ans=0;
	cin>>a>>b;
	for(int i=0;b>=a;i++){
		a=a*2;
		ans++;
	}
	cout<<ans<<endl;
	
	return 0;
	
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    int n, k, a[100001];
    int pre = 0;
    int max = 0;

    cin >> n >> k;
    while (n != 0 && k != 0) {
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    for (int i = 0; i < k; i++) {
        pre += a[i];
    }

    for (int i = 1; i <= n-k; i++) {
        pre = pre - a[i-1] + a[i+k-1];
        if (pre > max) {
            max = pre;
        }
    }

    cout << max << endl;
    cin >> n >> k;
    max = 0;
    pre = 0;
    }
}



Measured memory_bytes: 3464
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    ll N,A,B;
    cin >>N>>A>>B;
    vector<ll>h(N);
    vector<ll>h2(N);
    rep(i,N)cin>>h[i];
    h2=h;
    sort(all(h));
    reverse(all(h));
    ll l=0,r=1000000001;
    map<ll,bool>m;
    while(1){
        ll now=(l+r)/2;
        h=h2;
        rep(i,N){
            h[i]-=B*now;
        }
        ll cnt=0;
        ll C=A-B;
        rep(i,N){
            if(h[i]>0){
                cnt+=(h[i]-1)/C+1;
            }
        }
        //cout<<now<<endl;
        if(cnt>now){
            l=now+1;
            if(m[now]==1){
                l++;
            }
            
        }else{
            if(m[now]==1){
                cout<<now<<endl;
                return 0;
            }
            r=now-1;
            
        }
        m[now]=1;
    }



    return 0;
    

}

Measured memory_bytes: 4772
#include<bits/stdc++.h>
using namespace std;
int n, a[10000];
long long ans;
inline long long Pow(long long x, long long y){
	long long res = 1;
	while (y){
		if (y&1) res = res * x; 
		x = x * x;
		y >>= 1;
	}
	return res;
}
inline void dfs(int step, long long num){
	if (step == n + 1){
		if (num % 2 == 0) ++ ans;
		return;
	}
	for (int i = -1; i <= 1; ++i) dfs(step + 1, num * (a[step] + i));
}
int main(){
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
	dfs(1, 1);
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using LL = long long int;
#define incID(i, l, r) for(int i = (l)    ; i <  (r); ++i)
#define decID(i, l, r) for(int i = (r) - 1; i >= (l); --i)
#define incII(i, l, r) for(int i = (l)    ; i <= (r); ++i)
#define decII(i, l, r) for(int i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define dec(i, n)  decID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define FI first
#define SE second
#define FR front()
#define BA back()
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
auto setmin   = [](auto & a, auto b) { return (b <  a ? a = b, true : false); };
auto setmax   = [](auto & a, auto b) { return (b >  a ? a = b, true : false); };
auto setmineq = [](auto & a, auto b) { return (b <= a ? a = b, true : false); };
auto setmaxeq = [](auto & a, auto b) { return (b >= a ? a = b, true : false); };
#define SI(v) static_cast<int>(v.size())
#define RF(e, v) for(auto & e: v)
#define until(e) while(! (e))
#define if_not(e) if(! (e))
#define ef else if
#define UR assert(false)
#define IN(T, ...) T __VA_ARGS__; IN_(__VA_ARGS__);
void IN_() { };
template<typename T, typename ... U> void IN_(T &  a, U &  ... b) { cin >> a; IN_(b ...); };
template<typename T                > void OUT(T && a            ) { cout << a << endl; }
template<typename T, typename ... U> void OUT(T && a, U && ... b) { cout << a << " "; OUT(b ...); }

// ---- ----

int main() {
	IN(int, h1, m1, h2, m2, k);
	OUT((h2 * 60 + m2) - (h1 * 60 + m1) - k);
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;

int main() {
    lint h1, m1, h2, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;

    lint begin = h1*60 + m1;
    lint end = h2*60 + m2;

    cout << end-k-begin << endl;
}

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

#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 VI         vector<int>
#define MOD 1000000007

using ll = long long int;
using P = pair<int,int>;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const ll INF=(ll)1e19;
//const int INF=(1<<30);

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

  cout << (s == "ABC" ? "ARC" : "ABC") << endl;
}



Measured memory_bytes: 3624
import math

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

n = int(input())
stock = []
for i in range(n):
	x, y = [int(j) for j in input().split()]
	lengths = []
	for xx, yy, _ in stock:
		lengths.append(((x - xx) * (x - xx) + (y - yy) * (y - yy)) ** 0.5)
	stock.append((x, y, lengths))

sum_length = 0
n_appear_by = math.factorial(n) * (n - 1) / n
for _, _, ls in stock:
	for l in ls:
		sum_length += l
print(sum_length * (n - 1) / combinations_count(n, 2))

Measured memory_bytes: 9336
#include<iostream>
#include<string>
using namespace std;
 
int main(){
    string s;
    cin>>s;
    int a,b;
    a=stoi(s.substr(0,2));
    b=stoi(s.substr(2,2));
    if(1<=a&&a<=12&&1<=b&&b<=12) cout<<"AMBIGUOUS"<<endl;
    else if(1<=a&&a<=12&&0<=b&&b<=99) cout<<"MMYY"<<endl;
    else if(0<=a&&a<=99&&1<=b&&b<=12) cout<<"YYMM"<<endl;
    else cout<<"NA"<<endl;
}

Measured memory_bytes: 3604
#include<bits/stdc++.h>
#define ll long long
#define inf 1000000000
#define infll 1000000000000000000ll
#define vi vector<int>
#define vll vector<ll>
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define mpr make_pair
#define fi first
#define se second
#define pq priority_queue<int>
#define pqll priority_queue<ll>
#define up(x,y) (x<(y)?x=(y):0)
#define dn(x,y) (x>(y)?x=(y):0)
#define ad(x,y) (x=(x+(y))%mod)
#define mod 998244353
#define N 2009
using namespace std;

int n,dp[N][N],cbn[N][N]; char s[N];
int read(){
	int x=0; char ch=getchar(); bool flag=0;
	while (ch<'0' || ch>'9'){ if (ch=='-') flag=1; ch=getchar(); }
	while (ch>='0' && ch<='9'){ x=x*10+ch-'0'; ch=getchar(); }
	return flag?-x:x;
}
ll readll(){
	ll x=0; char ch=getchar(); bool flag=0;
	while (ch<'0' || ch>'9'){ if (ch=='-') flag=1; ch=getchar(); }
	while (ch>='0' && ch<='9'){ x=x*10+ch-'0'; ch=getchar(); }
	return flag?-x:x;
}
int ksm(int x,int y){
	int ans=1;
	for (; y; y>>=1,x=(ll)x*x%mod) if (y&1) ans=(ll)ans*x%mod;
	return ans;
}
int calc(int x,int y){
	if (y==1 || y==5) return x;
	if (y==2 || y==4) return x==0?2:(x&1);	
	return x&1^1;
}
int main(){
	scanf("%s",s+1); n=strlen(s+1);
	int i,j,x=0,y=0;
	dp[0][0]=1;
	for (i=1; i<=n; i++){
		x+=s[i]-'0'; y+='2'-s[i];
		for (j=0; j<=x; j++){
			if (j) ad(dp[i][j],dp[i-1][j-1]);
			if (i-j<=y) ad(dp[i][j],dp[i-1][j]);	
		}
	}
	for (i=0; i<=n; i++)
		for (j=cbn[i][0]=1; j<=i; j++)
			cbn[i][j]=(cbn[i-1][j]+cbn[i-1][j-1])%mod;
	int ans=0;
	for (i=0; i<=n; i++)
		ad(ans,(ll)dp[n][i]*cbn[n][x-i]);
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 30848
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); (i)--)
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
using namespace std;

string x, y;
int n, m;
int dp[1010][1010];

int solve(int i, int j){
    if(i==0 || j==0) return dp[i][j] = 0;
    if(dp[i][j] >= 0) return dp[i][j];
    if(x[i-1] == y[j-1]){
        dp[i][j] = max(solve(i-1, j), solve(i, j-1));
        return dp[i][j] = max(dp[i][j], solve(i-1, j-1)+1);
    }
    return dp[i][j] = max(solve(i-1, j), solve(i, j-1));
}

int main(){
    int q; cin >> q;
    rep(i, q){
        cin >> x >> y;
        n = (int)(x.size()); m = (int)(y.size());
        rep(i, n+1)rep(j, m+1) dp[i][j] = -1;
        cout << solve(n, m) << endl;
    }
}


Measured memory_bytes: 7328
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		//BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		//String line = br.readLine();
		Scanner scan = new Scanner(System.in);

		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();

		if(a*b>c)
			System.out.println(c);
		else
			System.out.println(a*b);


	}
}


Measured memory_bytes: 21588
/*
For Bantako San
By shyyhs.

Using hash to insert and search for a perticular number.
Every insert and search is O(1) ideally.
*/

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<string>
using namespace std;
#define ll long long
#define Hsize 100009
#define MAXN 210001 
ll sumZ=0; //sum from the beginning
int Ai; //This is Ai in the problem, we use it only once so array is not necessary.
int N; //N in the problem

struct T
{
    ll number,times;
    T* next;
}hashBucket[MAXN];
int top=0;
int hashIndex[Hsize];


//x->hash(x)
inline int hashFunc(ll x)
{
    if (x<0) x=-x;
    return (x%100007);
}

//add the current sumZ to the hash table
inline void addToHash(ll sumZ)
{
    int HsumZ;
    T* index, *beginP;
    HsumZ = hashFunc(sumZ);
    for (beginP=index=&hashBucket[hashIndex[HsumZ]]; (index->times>0); index=index->next)
        if (index->number==sumZ)
        {
            index->times++;
            return;
        }
    /*
    for (beginP=index=hashIndex[HsumZ]; index>0; index=hashBucket[index].next)
        if (hashBucket[index].number == sumZ) // there is already that number in the hashbucket
        {
            hashBucket[index].times+=1;
            return;
        } 
        */
    top++;
    hashIndex[HsumZ]=top;
    index=&hashBucket[top];
    index->number = sumZ;
    index->times = 1;
    index->next = beginP;
    /*
    hashBucket[top].number = sumZ;
    hashBucket[top].times = 1;
    hashBucket[top].next = beginP;
    */
}

void init()
{
    scanf("%d",&N);
    addToHash(0);
    for (int i=0; i<N; ++i)
    {
        scanf("%d",&Ai);
        sumZ=sumZ+Ai;
        addToHash(sumZ);
    }
}

void work()
{
    ll answer=0;
    for (int i=1; i<=top; ++i)
        answer=answer+(((hashBucket[i].times)*(hashBucket[i].times-1))>>1) ;
    cout<<answer<<endl;
}
    
int main()
{
    init();
    work();
    return 0;
}


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

struct Card {
    char trump;
    int num;
};

void BubbleSort(struct Card *c, int n);
void SelectionSort(struct Card *c, int n);
void printDeck(struct Card *c, int n);
bool isStable(struct Card *stable, Card *c, int n);

int main() {
    int n;
    struct Card c_b[36], c_s[36];

    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> c_b[i].trump;
        cin >> c_b[i].num;
        c_s[i].trump = c_b[i].trump;
        c_s[i].num = c_b[i].num;
    }
    BubbleSort(c_b, n);
    SelectionSort(c_s, n);

    printDeck(c_b, n);
    cout << "Stable" << endl;
    printDeck(c_s, n);
    if (isStable(c_b, c_s, n)) {
        cout << "Stable" << endl;
    } else {
        cout << "Not stable" << endl;
    }
}

void BubbleSort(struct Card *c, int n) {
    struct Card tmp;
    for (int i = 0; i < n; i++) {
        for (int j = n-1; j > i; j--) {
            if (c[j].num < c[j-1].num) {
                tmp = c[j];
                c[j] = c[j-1];
                c[j-1] = tmp;
            }
        }
    }
}

void SelectionSort(struct Card *c, int n) {
    int minj;
    struct Card tmp;
    for (int i = 0; i < n; i++) {
        minj = i;
        for (int j = i; j < n; j++) {
            if (c[j].num < c[minj].num) {
                minj = j;
            }
        }
        tmp = c[i];
        c[i] = c[minj];
        c[minj] = tmp;
    }
}

void printDeck(struct Card *c, int n) {
    int i;
    for (i = 0; i < n-1; i++) {
        cout << c[i].trump << c[i].num << " ";
    }
    cout << c[i].trump << c[i].num << endl;
}

bool isStable(struct Card *stable, struct Card *c, int n) {
    for (int i = 0; i < n; i++) {
        if ((stable[i].trump != c[i].trump) || (stable[i].num != c[i].num)) {
            return false;
        }
    }
    return true;
}

Measured memory_bytes: 3088
#include <iostream>
using namespace std;
//B - Christmas Eve Eve
int main(void){
    int n;
    std::cin >> n;
    int max=0;
    int sum=0;
    for(int i=0;i<n;i++){
        int p;
        std::cin >> p;
        sum+=p;
        if(max<p){
            max=p;
        }
    }
    std::cout << sum-max/2 << std::endl;
    
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

class Combination {
public:
  static const int MOD = 1e9 + 7;
  static const int MAX = 10000;

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

  long long max;
  long long mod;

public:
  // テーブルを作る前処理
  Combination(long long aMax, long long aMod) : max(aMax), mod(aMod) {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(long long i = 2; i < max; i++) {
      fac[i] = fac[i - 1] * i % mod;
      inv[i] = mod - inv[mod % i] * (mod / i) % mod;
      finv[i] = finv[i - 1] * inv[i] % mod;
    }
  }

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

using ll = long long;

int main() {
  ll N, K;
  cin >> N >> K;

  ll R = N - K; // rest

  Combination C(2000, Combination::MOD);

  for(int i = 1; i <= K; ++i) {
    ll div = C.combi(K - 1, i - 1);
    ll pos = (R + 1 < i) ? 0 : C.combi(R + 1, i);
    ll ans = (div * pos) % Combination::MOD;
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define ll long long int
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mem(x) memset(x, 0, sizeof x)
#define mem1(x) memset(x, -1, sizeof x)
#define MX 100005
ll arr[MX], dp[MX],n;
//ll rec(ll i, ll score)
//{
//    if(i==n-1) return score;
//    else if(i>=n) return 1e9;
//    else if(dp[i]<score && dp[i]!=-1) return dp[i];
//    else if(!i || dp[i]==-1 || score<dp[i])
//    {
//        ll ret1=1e9, ret2=1e9;
//        if(i+1<=n-1) ret1= rec(i+1, score+llabs(arr[i+1]-arr[i]));
//        if(i+2<=n-1) ret2= rec(i+2, score+llabs(arr[i+2]-arr[i]));
//        return dp[i]=min(ret1,ret2);
//    }
//}
int main()
{
    ll i,j,k,l, m;
    scanf("%lld",&n);
    for(i=0; i<n; i++) scanf("%lld",&arr[i]);
    for(i=1; i<n; i++) dp[i]=1e9;
    for(i=0; i<n; i++)
    {
        if(i+1<=n-1) dp[i+1]=min(dp[i+1], dp[i]+llabs(arr[i]-arr[i+1]));
        if(i+2<=n-1) dp[i+2]=min(dp[i+2], dp[i]+llabs(arr[i]-arr[i+2]));
    }
    printf("%lld\n",dp[n-1]);
    return 0;
}


Measured memory_bytes: 1792
#include "bits/stdc++.h"
#define FI first.first
#define SE first.second
#define TH second
#define fi first
#define se second
#define th second

using namespace std;

void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef DEBUG
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

class DebugStream {}LOG;
template <typename T>DebugStream &operator<<(DebugStream &s, const T&) { return s; }
#ifdef DEBUG
#define LOG clog
#endif

typedef long long ll;
typedef pair<ll, ll> ii;
typedef long double ld;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int maxN = 1e5 + 9, maxV = 1e6 + 9, MOD = 1e9 + 7, SQ = 335, lg = 20, bs = 29;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	#ifdef DEBUG
	freopen("input.txt", "r", stdin);
	#endif

	ll len;
	cin >> len;
	ld sd = ld(len) / 3;
	cout << fixed << setprecision(13) << sd * sd * sd << '\n';
}


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

int main() {
    int n, k, q;
    cin >> n >> k >> q;
    vector<int> cnt(100001);
    for (int i = 0; i < q; i++) {
        int a;
        cin >> a;
        cnt.at(a)++;
    }

    for (int i = 1; i <= n; i++) {
        if (k - (q - cnt.at(i)) > 0) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}  

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

int main(){
  double W,H,x,y;
  cin >> W >> H >> x >> y;
  double ans = W*H/2;
  int ans1;
  if(x==W/2 && y==H/2) ans1 = 1;
  else ans1 = 0;
  cout << fixed << setprecision(10) << ans << ' ' << ans1 << endl;
  return 0;
}


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

const int INF = 1 << 30;
int n,r[200000];

void solve(){
  int ans = -INF, pos = 0;
  for(int i=1;i<n;i++){
    ans = max(ans,r[i] - r[pos]);
    if(r[pos] > r[i]){
      pos = i;
    }
  }
  cout << ans << endl;
}

int main(){
  while(cin >> n){
    for(int i=0;i<n;i++) {
      cin >> r[i];
      assert(r[i] <= (int)(1e+9));
    }
    solve();
  }
}

Measured memory_bytes: 1940
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int k = scan.nextInt();
		int x = scan.nextInt();

		int left;
		int right;
		if(x - k + 1 >= -1000000)
			left = x - k + 1;
		else
			left = -1000000;

		if(1000000 >= x + k - 1)
			right = x + k - 1;
		else
			right = 1000000;

		int i;
		for(i = left; i <= right; i++)
			System.out.println(i);
	}
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
//debug
#ifdef grief
#define debug(...) do{\
	fprintf(stderr , "%s - %d : (%s) = " , __PRETTY_FUNCTION__ , __LINE__ , #__VA_ARGS__ );\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){
	cerr<<x<<endl;
}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){
	cerr<<x<<" , ";
	_DO(tail...);
}
#else
#define debug(...)
#endif
//type
typedef long long ll;
typedef pair<int,int> pii;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef priority_queue<pll,vector<pll>,greater<pll> > heap;
//macro
#define SZ(x) ((ll)(x).size())
#define ALL(x) (x).begin(),(x).end()
#define F first
#define S second
#define REP(i,n) for(ll i=0;i<(n);i++)
#define REP1(i,a,b) for(ll i=(a);i<=(b);i++)
#define mkp make_pair
#define pb push_back
const ll INF=1e18;
const ll MA=1e5+5;
const ll MOD=1e9+7;
//}}}
ll n;
vector<int> in[MA];
vector<int> out[MA];
int deg[MA];
int depth[MA];
int tmp[MA];
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin>>n;
	int x;
	queue<int> qu;	while(SZ(qu))	qu.pop();
	for(int i=2;i<=n;i++){
		cin>>x;
		in[x].pb(i);
		out[i].pb(x);
		deg[x]++;
	}
	for(int i=1;i<=n;i++)
		if(!deg[i])	qu.push(i);
	while(SZ(qu)){
		int now=qu.front();
		qu.pop();
		int si=SZ(in[now]);
		for(int i=0;i<si;i++){
			tmp[i]=depth[ in[now][i] ];
		}
		sort(tmp,tmp+si);
		depth[now]=0;
		for(int i=0;i<si;i++){
			depth[now]=max(depth[now],si-i+tmp[i]);
		}
		for(int i=0;i<SZ(out[now]);i++){
			int v=out[now][i];
			deg[v]--;
			if(!deg[v]){
				qu.push(v);
			}
		}
	}
	int ma=0;
	for(int i=1;i<=n;i++)
		ma=max(ma,depth[i]);
	cout<<ma<< '\n';
	return 0;
}

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

using ll = long long;
using db = double;
using pll = pair < ll, ll >;

#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1) {
	cerr << name << " : " << arg1 << std :: endl;
}
template < typename Arg1, typename... Args >
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << " : " << arg1 << " | ";
	__f(comma + 1, args...);
}
#else
#define trace(...)
#endif

#define pb push_back
#define mp make_pair
#define fastIo() ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)

const int MOD = 1e9 + 7, INF = INT_MAX, N = 1e5 + 10;

// int main(){
// 	fastIo();
// 	ll n, k; cin >> n >> k;
// 	ll a[n];
// 	for(ll i = 0; i < n; i++) {
// 		cin >> a[i];
// 	}
// 	ll dp[n];
// 	dp[0] = 0;
// 	for(ll i = 1; i < n; i++) dp[i] = INF;
// 	for(ll i = 0; i < n; i++){
// 		for(ll j = 1; i + j < n && j <= k; j++){
// 			dp[i + j] = min(dp[i + j], abs(a[i] - a[i + j]) + dp[i]);
// 			trace(i, j, dp[i+j]);
// 		}
// 	}
// 	cout << dp[n - 1] << endl;
// }


int main() {
 
	ll N, K;
	cin >> N >> K;
	vector<ll> H(N);
	for (int i = 0; i < N; i++)
	{
		cin >> H[i];
	}
 
	vector<ll> ans(N, INF);
	ans[0] = 0;
	for (int i = 0; i < N; i++)
	{
		for (int k = 1; i + k < N && k <= K; k++)
		{
			ans[i + k] = min(ans[i + k], ans[i] + abs(H[i] - H[i + k]));
		}
	}
 
	cout << ans[N - 1] << endl;
 
 
 
}

Measured memory_bytes: 1792
class Array
  def cumsum; s = 0; map{|k| s += k } end
  def fd(n=nil); n = self.max if n.nil?; res = Array.new(n+1,0);self.map{|e| res[e]+=1 };res;end
  # cumlative frequency dist.
  def cfd(n=nil); fd.cumsum; end
end

n, m = gets.to_s.split.map{|t|t.to_i}
a    = gets.to_s.split.map{|t|t.to_i}.sort

sum_min = a[0]  * 2
sum_max = a[-1] * 2

CFD = a.fd.reverse.cumsum.reverse
def number_greater_than(x)
  return CFD[0] if x <= 0
  return 0 if  CFD.size <= x+1
  CFD[x+1]
end

sum_x = (sum_min .. sum_max).bsearch do |sum_x|
  cnt = 0
  a.each do |r|
    cnt += number_greater_than(sum_x-r)
    break if cnt >= m
  end
  cnt < m
end

c = ([0] + a).cumsum
s = c[-1]

ans = 0
a.each do |r|
  pos = a.bsearch_index{|l| sum_x < r + l } || n
  cnt = n - pos
  ans += cnt * r + (s - c[pos])
  m -= cnt
end

ans += m * sum_x

puts ans

Measured memory_bytes: 14472
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int n,k;
  cin >> n >> k;
  vector<int> x(n);
  rep(i,n) cin >> x[i];

  int l = 0, r = k - 1;
  int ans = 1e9;
  while(r<n){
    int res;
    if(x[r]<=0) res = -x[l];
    if(0<=x[l]) res = x[r];
    if(x[l]<0 && 0<x[r]) res = x[r] - x[l] + min(-x[l],x[r]);
    ans = min(ans,res);
    ++l; ++r;
  }
  cout << ans << endl;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>
#define MAX 101

void initialize();
int isEmpty();
int isFull();
void push(int);
int pop();

int S[MAX],top;

int main(){
  char x[MAX];
  int a,b;

  initialize();

  while(scanf("%s", x) != EOF){
    if(x[0] == '+'){
     b = pop();
     a = pop();
     push(a+b);
   }
   else if(x[0] == '-'){
    b = pop();
    a = pop();
    push(a-b);
  }
  else if(x[0] == '*'){
    b = pop();
    a = pop();
    push(a*b);
  }
  else {
    push(atoi(x));
  }
}

printf("%d\n", S[top]);
return 0;
}

void initialize(){
  top = 0;
}

int isEmpty(){
  return top == 0;
}

int isFull(){
  return top >= MAX - 1;
}

void push(x){
  if(isFull()){
    printf("WTF1\n");
    exit(1);
  }
  top++;
  S[top] = x;
}

int pop(){
  if (isEmpty()){
    printf("WTF2\n");
    exit(2);
  }
  top--;
  return S[top+1];
}

Measured memory_bytes: 548
# coding: utf-8
import re
import bisect
from datetime import datetime as dt

n = input()
v = map(int, raw_input().split())
c = map(int, raw_input().split())

ans = 0
for i in range(len(v)):
    if v[i] - c[i] > 0:
        ans += v[i] - c[i]
print ans


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

struct DP{
	int mi, dsum, vnum;
};

int N, x, ans = 1e9, dmi = 1e9;
string S;
vector<int> G[2020];
DP dp[2020];
int used[2020][2020];

DP dfs(int v, int p = -1){
	if(used[x][v]) return dp[v];
	dp[v].dsum = 0, dp[v].vnum = S[v] - '0';
	int ma = 0, mami = 0;
	rep(i, G[v].size()){
		int to = G[v][i];
		if(to == p) continue;
		int dis = dfs(to, v).dsum + dfs(to, v).vnum;
		dp[v].dsum += dis;
		dp[v].vnum += dfs(to, v).vnum;
		if(ma < dis){ ma = dis; mami = dfs(to, v).mi + dfs(to, v).vnum; }
	}
	if(dp[v].dsum % 2 == 0){
		if(dp[v].dsum - ma >= mami){
			dp[v].mi = 0;
		}else{
			dp[v].mi = mami - (dp[v].dsum - ma);
		}
	}else{
		if(dp[v].dsum - ma >= mami){
			dp[v].mi = 1;
		}else{
			dp[v].mi = mami - (dp[v].dsum - ma);
		}
	}
	used[x][v] = 1;
	return dp[v];
}

int main(){
	cin >> N >> S;
	rep(i, N-1){
		int a, b; cin >> a >> b;
		a--; b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	for(x=0; x<N; x++){
		if(ans > dfs(x).mi) ans = dfs(x).mi;
		if(dfs(x).mi == 0 && dmi > dfs(x).dsum) dmi = dfs(x).dsum;
	}
	if(ans == 0) cout << dmi/2 << endl;
	else cout << -1 << endl;
	return 0;
}


Measured memory_bytes: 16512
#include <iostream>
#include <vector>
#include <deque>
#include <cmath>
#include <map>
#include <set>
#include <unordered_set>
#include <algorithm>
#include "iomanip"
#include <cstdio>
#include <cstring>
#include <set>
#include <vector>
#include <fstream>
#include <algorithm>
#include <queue>
#include <cassert>
#include <stack>


using namespace std;

void print(vector<int> &b);


void print(vector<int> &b) {
    for (auto i : b) {
        cout << i << " ";
    }
    cout << endl;
}


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

    int a, b;
    string s;
    cin >> a >> b >> s;
    if (s[a] != '-') {
        cout << "No";
        return 0;
    }
    for (int i = 0; i < a + 1 + b; ++i) {
        if (i != a) {
            if (s[i] > '9' || s[i] < '0') {
                cout << "No";
                return 0;
            }
        }
    }
    cout << "Yes";
    return 0;
}




Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <complex>
#include <iomanip>
#include <queue>
#include <bitset>
#include <numeric>
//定数
#define MOD 1000000007
//マクロ
#define rep(i,n)    for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))

#define vsort(v) sort((v).begin(), (v).end());

typedef unsigned long long int ull;
typedef long long lint;

using namespace std;




int main(){
    string N;

    //入力
    cin >> N;
    
    if(N[1]=='B') cout << "ARC" << endl;
    else cout << "ABC" << endl;

    return 0;
}

Measured memory_bytes: 3552
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <complex>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
#include <limits>
#include <time.h>
#include <cstdint>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(ll i=n-1;i>=0;i--)
#define rRep(i,a,b) for(ll i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template <class T, class U> inline bool chmax(T& lhs, const U& rhs) { if (lhs < rhs) { lhs = rhs; return 1; } return 0; }
template <class T, class U> inline bool chmin(T& lhs, const U& rhs) { if (lhs > rhs) { lhs = rhs; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}

ll  A,B,C,D,E,F,G,H,K,L,M,N,P,Q,R,W,X,Y,Z;
string S,T;

int main(){
  cin >> N;
  cout << N/500*1000+(N%500)/5*5 << endl;
}


Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
namespace ORIGIN {
#define LL long long
#define VLL vector<long long>
#define SORT(x) sort(x.begin(),x.end())
#define REVE(x) reverse(x.begin(),x.end())
#define rep(i,n) for(int i=0;i<n;i++)
#define COUT(x) cout<<x<<endl
#define WHOLE(x) x.begin(),x.end()
	double pai = 3.1415926535;
	string atc = "atcoder";
	typedef pair<long long, long long> data_t;
	string strnum = "0123456789";
	string alpS = "abcdefghijklmnopqrstuvwxyz";
	string alpL = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	int sizealp = (int)(alpS.size());
	int mod = 1e9 + 7;
	bool test = false;
}
using namespace ORIGIN;

void Test(char a) {
	if (test) {
		printf("%c", a);
	}
}
int gcd(LL a, LL b) {
	if (a == 0 || b == 0)return 0;
	if (a < b)swap(a, b);
	if (a % b == 0)return b;
	else gcd(b, a % b);
}

int main() {
	int n;
	cin >> n;
	VLL a(n);
	rep(i, n)cin >> a[i];
	LL sum = 0;
	for (int i = 0; i < n; i++) {
		if (i % 2 == 0) {
			sum += a[i];
		}
		else {
			sum -= a[i];
		}
	}
	int ans = sum;
	cout << ans << ' ';
	for (int i = 1; i < n; i++) {
		ans = a[i-1] * 2 - ans;
		cout << ans << ' ';
	}
}

Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace  std ;
typedef long long  ll;
typedef pair<ll, ll> Pll;
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define rad(X) cout << (X) << endl
#define ASH(X) cout << (X) << " "
#define debug(x) cout << #x << " " << x << endl;
#define debug2(x,y) cout << #x << " " << x << " " << #y << " " << y << endl;
#define FOR(I,A,B) for(ll I = (A); I <= (B); I++)
#define cir(I,B,A) for(ll I = (A); I >=(B); I--)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define SORT(c) (sort(c.begin(),c.end()))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASES int ___T; cin >> ___T; for(int cs=1;cs<=___T;cs++)
#define FAST()  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
ll fx[] = {1, 1, 0, -1, -1, -1, 0, 1};
ll fy[] = {0, 1, 1, 1, 0, -1, -1, -1};
vector<ll>a,b,c;
map<ll,ll>m1,m2,m3;

/************************************************/

void Execute()
{
      ll N,NB,VAL,A,B,C,G,INC,DEC,L,R,D,Q;
      cin >> N;
      cin >> A >> B;
      A=min(A,B);
      B=max(A,B);
      bool Ok = false;

      FOR(i,A,B)
      {
         // N*i;
         //debug(N*i);
         if(i%N==0)
         {
          Ok = true;
         }
      }

    if(Ok==true) cout<<"OK"<<endl; else cout<<"NG"<<endl;




}

int main()
{
    //freopen("atomm.txt", "r", stdin);
    FAST();
    //CASES

        Execute();

}


Measured memory_bytes: 3612
#!/usr/bin/env python3
# Generated by https://github.com/kyuridenamida/atcoder-tools
from typing import *
import collections
import functools
import itertools
import math
import operator
import sys

INF = float('inf')


def solve(N: int, P: "List[int]", Q: "List[int]"):
    return abs(operator.sub(*[list(itertools.permutations(range(1, N+1))).index(tuple(i)) for i in [P, Q]]))


def main():

    sys.setrecursionlimit(10 ** 6)

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    P = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    Q = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    print(f'{solve(N, P, Q)}')


if __name__ == '__main__':
    main()


Measured memory_bytes: 79276
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VL = vector<LL>;
using PII = pair<int, int>;
using PLL = pair<LL, LL>;

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define F first
#define S second
#define FOR(i, a, b) for (int i = (a); i<(b); ++i)
#define RFOR(i, b, a) for (int i = (b)-1; i>=(a); --i)
#define FILL(a, b) memset(a, b, sizeof(a))

void dout() { cerr << endl; }

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


LL div_floor(LL x, LL y) {
    LL q = x / y;
    LL r = x % y;
    if ((r != 0) && ((r < 0) != (y < 0))) --q;
    return q;
}

LL solve(const VL& a, LL k)
{
    LL left = -1.5e18, right = 1.5e18;
    while (left + 1 < right)
    {
        LL mid = (left + right) / 2;
        LL cnt = 0;
        FOR(i, 0, SZ(a))
        {
            if (a[i] == 0)
            {
                if (mid >= 0)
                    cnt += a.end() - (a.begin() + i + 1);
            }
            if (a[i] < 0)
            {
                cnt += a.end() - lower_bound(a.begin() + i + 1, a.end(), div_floor(mid + a[i] + 1, a[i]));
            }
            if (a[i] > 0)
            {
                cnt += upper_bound(a.begin() + i + 1, a.end(), div_floor(mid, a[i])) - (a.begin() + i + 1);
            }
        }
        if (cnt < k)
            left = mid;
        else
            right = mid;
    }
    return right;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n; LL k;
    cin >> n >> k;
    VL a(n);
    FOR(i, 0, n)
    {
        cin >> a[i];
    }
    sort(ALL(a));
    cout << solve(a, k);
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repe(i,n) for (int i = 0; i <= (n); ++i)
#define repe1(i,n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define eb(k,v) emplace_back(k,v)
#define ct(res) cout << res << "\n";
#define vi vector<int>
#define vl vector<ll>
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1e9;
const ll MOD = 1000000007;
const double pi = 3.141592653589;
using Graph = vector<vector<int>>;

int main() {
int counts[30]={0};

char cs[1201];
while(scanf("%[^\n]\n",cs)!=EOF){
	for(int i=0;cs[i]!='\0';i++){
		if(isalpha(cs[i])){
			counts[tolower(cs[i])-'a']++;
		}
	}
}

for(char c='a';c<='z';c++){
	printf("%c : %d\n",c,counts[c-'a']);
}
return 0;
}


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

#define get_variable_name(x) #x
#define debug(x) cout << #x << " = " << x << endl

#define ALL(x) (x).begin(), (x).end()
#define SORT(x) sort((x).begin(), (x).end())
#define REVERSE(x) reverse( (x).begin(),(x).end())
#define UNIQUE(x) (x).erase(unique(ALL((x))), (x).end())
#define PW(x) (1LL<<(x))

using namespace std;
using ll = int64_t;
using P = pair<int, int>;

template<class T,class U>
ostream& operator<<(ostream &os, const pair<T, U> &p) {
    os << get_variable_name(p) << " = (" << p.first <<", " << p.second << ")";
    return os;
}

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


const int INF = 1e8;

int main() {
    ios::sync_with_stdio(false);
    int A, B, C;
    map<int, int> cnt;
    cin >> A >> B >> C;
    cnt[A]++; cnt[B]++; cnt[C]++;
    if(cnt[5] == 2 and cnt[7] == 1) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#define PP std::pair<int,int>
#define LL long long
LL A,B,C,K;
LL j=1e18;
int main(){
    std::cin>>A>>B>>C>>K;
    LL ans;
    if(K%2)ans=B-A;
    else ans=A-B;
    if(std::abs(ans)>j)std::cout<<"Unfair"<<std::endl;
    else std::cout<<ans<<std::endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		if(b%a == 0){
			System.out.print(a+b);
		}else{
			System.out.print(b-a);
		}
	}
}


Measured memory_bytes: 22740
def solve(num):
    result = []
    for i in range(2, int(num**(1/2)+1)):
        counter = 0
        while num%i == 0:
            num /= i
            counter += 1
        if counter >= 1:
            result.append((i, counter))
    if len(result) == 0:
        result = [(1,1)]
    numbers = 1
    for i in result:
        numbers *= i[1]+1
    return numbers
def main():
    n = int(input())
    c = 0
    for i in range(1, n+1, 2):
        r = solve(i)
        if r == 8:
            c += 1
    print(c)

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++ )
#define repf(i,m,n) for(int (i)=m;(i)<n;(i)++)
#define all(v) (v).begin(), (v).end()
#define ll long long
#define vec(name,num) vector<ll> name((num),0);
#define op(i) cout<<(i)<<endl;
#define opf(i) cout<<fixed<<setprecision(10)<<(i)<<endl;
#define ip(i) cin>>(i);
#define opN cout<<"No"<<endl;
#define opY cout<<"Yes"<<endl;
#define opP cout<<"Possible"<<endl;
#define opI cout<<"Impossible"<<endl;
#define mat(name,fnum,snum); vector<vector<ll>> name((fnum),vector<ll>((snum),0));
#define matC(name,fnum,snum); vector<vector<char>> name((fnum),vector<char>((snum),0));
#define debugP int debug_point; cin>>debug_point;
#define FI first
#define SE second
const ll MOD= 1e9 + 7;

const string YES = "Yes";
const string NO = "No";


struct UnionFind {
    vector<pair<ll,ll>> par; //FI is parent number, SE is dis from the parent
    UnionFind(ll n){
        par.resize(n);
        rep(i,n){
            par[i].FI=i;
        }
    }

    pair<ll,ll> root(ll x){
        if(par[x].FI==x) return par[x];
        else{
            pair<ll,ll> tmp=root(par[x].FI);
            par[x].SE+=tmp.SE;
            par[x].FI=tmp.FI;
            return par[x];
        }
    }

    void unite(ll x, ll y, ll dis){
        pair<ll,ll> rx = root(x);
        pair<ll,ll> ry = root(y);
        if(rx.FI == ry.FI) return;
        par[rx.FI].FI = ry.FI;
        par[rx.FI].SE = par[y].SE+dis-par[x].SE;
    }

    bool same(ll x, ll y){
        ll rx = root(x).FI;
        ll ry = root(y).FI;
        return rx == ry;
    }

    bool dis_chk(ll x,ll y,ll d){
        //cout<<"called chkF"<<x<<" "<<y<<endl;
        if((par[x].SE-par[y].SE)==d){
            return true;
        }
        return false;
    }
};

void solve(long long N, long long M, std::vector<long long> L, std::vector<long long> R, std::vector<long long> D){
    UnionFind uf(N);
    rep(i,M){
        if(!uf.same(L[i],R[i])){
            uf.unite(L[i],R[i],D[i]);
        }else{
            if(uf.dis_chk(L[i],R[i],D[i]))continue;
            else {
                //uf.unite(L[i],R[i],D[i]);
                op(NO)
                return;
            }
        }
    }
    op(YES);
    /*rep(i,N){
        cout<<uf.par[i].FI<<" "<<uf.par[i].SE<<endl;
    }*/
    return;
}

// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    long long M;
    scanf("%lld",&M);
    std::vector<long long> L(M);
    std::vector<long long> R(M);
    std::vector<long long> D(M);
    for(int i = 0 ; i < M ; i++){
        scanf("%lld",&L[i]);
        scanf("%lld",&R[i]);
        scanf("%lld",&D[i]);
        L[i]--;R[i]--;
    }
    solve(N, M, std::move(L), std::move(R), std::move(D));
    return 0;
}


Measured memory_bytes: 6528
/*  TAHMID RAHMAN
    DAMIAN FOREVER
     MATH LOVER
    NEVER GIVE UP
*/
#include<bits/stdc++.h>
using namespace std;
#define pi acos(-1.0)
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long
#define pb push_back
#define fi first
#define se second
#define in insert
#define mp make_pair
#define GCD(a,b) __gcd(a,b);
#define endl "\n"
#define FRU freopen("out.txt","w",stdout)
#define FRO freopen("in.txt","r",stdin)
#define INFLL 9223372036854775807
#define debug 0
#define MAXN   100001
//Don't hesitate to ask me if you don't understand my code.......Happy coding,Tahmid...;
int main()
{
    fastio;
    ll i;
    vector<ll>v(5);
    for(i=0;i<5;i++)
    {
        cin>>v[i];
    }
    for(i=0;i<5;i++)
    {
        if(v[i]==0)
            break;
    }
    cout<<i+1<<endl;
}


Measured memory_bytes: 3632