akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MAX 510000
#define rrep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define dcout cout<<fixed<<setprecision(15);
#define mp make_pair
#define pb push_back

using namespace std;
typedef long long int  ll;
typedef pair<ll, ll> P;

constexpr int MOD = 1e9 + 7;
constexpr ll inf = 1LL << 60;

template< typename S, typename T >
inline void chmax(S &a, const T &b) { if(a < b) a = b; }
 
template< typename S, typename T >
inline void chmin(S &a, const T &b) { if(a > b) a = b; }
 

//lcm//
ll gcd(ll x, ll y) {
	if (x == 0) return y;
	return gcd(y%x, x);
}
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

//a^n mod p//
ll modpow(ll a, ll n, ll p) {
	if(n==0) return (ll)1;
  if (n == 1) return a % p;
  if (n % 2 == 1) return (a * modpow(a, n - 1, p)) % p;
  ll t = modpow(a, n / 2, p);
  return (t * t) % p;
}

//inversemod//
ll modinv(ll a, ll m) {
	if(m==0)return (ll)1;
	ll b = m, u = 1, v = 0;
	while (b) {
		ll t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}

//Cmonp//
ll fac[MAX], finv[MAX], inv[MAX];
// 
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

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

//LARGE n
ll com(ll n,ll m){
    if(n<m || n<=0 ||m<0){
		return 0;
	}
	if( m==0 || n==m){
		return 1;
	}
	ll k=1;
	for(ll i=1;i<=m;i++){
       k*=(n-i+1); 
	   k%=MOD;
	   k*=modinv(i,MOD);
	   k%=MOD;
	}
	return k;
}

//radP
ll rad(ll u, ll p){
ll cnt=0;
	while(u%p==0){
		u/=p;
		cnt++;
	}
	return cnt;
}


////////////////////////////////////////////////////////////////////

vector<ll> pr{};
ll ans;
ll n;

void zen(ll val, ll k, ll p, ll pnum, ll pk){
if(val>=2){ans+=val*k*(pk+1);}

if(val*p<=n && val>=2){
	zen(val*p,k,p,pnum,pk+1);
}

for(ll i=pnum+1;i<pr.size();i++){
	ll v=val*pr[i];
	if(v>n) break;
zen(v, k*(pk+1), pr[i], i, (ll)1);
}

return ;
}



int main() {
 ios::sync_with_stdio(false);
ans=1;
ll val=1;


cin>>n;



ll er[n+1];
rep(i,n){
	er[i]=0;
}
for(ll i=2;i<=n;i++){
if(er[i])continue;
pr.push_back(i);
for(ll j=1;j<=n;j++){
	if(i*j>n)break;
	if(er[i*j]==0)er[i*j]=1;
}
}

zen(1,1,0,-1,0);

cout<<ans<<endl;

return 0;
}




Measured memory_bytes: 89724
N=int(input())
r=[(0,0) for i in range(N)]
b=[(0,0) for i in range(N)]

for i in range(N):
    x,y=map(int,input().split())
    r[i]=(x,y)
for i in range(N):
    x,y=map(int,input().split())
    b[i]=(x,y)
b.sort()
ru=[0 for i in range(N)]
ans=0
for i in range(N):
    k=-1
    for j in range(N):
        if b[i][0]>r[j][0] and b[i][1]>r[j][1]:
            if k==-1 and ru[j]==0:
                k=j
            elif r[k][1]<r[j][1] and ru[j]==0:
                k=j
    if k!=-1:
        ru[k]=1
        ans+=1
print(ans)


Measured memory_bytes: 3064
#include <stdio.h>

int main(void)
{
	int n ,i;
	long ans;
	
	ans = 1;
	
	scanf("%d", &n);
	
	for (i = n; i > 1; i--){
		ans *= i;
	}
	printf("%lld\n", ans);
	
	return (0);
}

Measured memory_bytes: 592
A,B=map(int, input().split())
S=str(input())
isHaihun = S[A]=="-"
num_list = "1234567890"
num_count = 0
for i in range(A+B+1):
  num_count = num_count + len([1 for x in num_list if x==S[i]])
isNum = num_count == A+B
if isHaihun & isNum:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3064
# ABC153c


def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10 ** 6)

    n, k = map(int, input().split())
    h = list(map(int, input().split()))
    h.sort(reverse=True)
    print(sum(h[k:]) if k < n else 0)


if __name__ == '__main__':
    main()


Measured memory_bytes: 26032
#include<iostream>
using namespace std;
int main(){
int a,b;
  cin>>a;
  for(int i=1;i<10;i++)
    for(int j=1;j<10;j++)
      if(i*j == a){
      	cout<<"Yes\n";
        return 0;
      }

    cout<<"No"<<endl;


return 0;
}

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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define all(x) begin(x), end(x)
typedef long long ll;
typedef pair<int, int> pii;
const int inf=1010001000;
const ll  INF=1001000100010001000;
const int mod=(int)1e9+7;

int main(){
    ll n,k;
    cin>>n>>k;
    vector<vector<int>>a(n,vector<int>(2));
    vector<ll>v(n+1,0);
    rep(i,0,n){
        cin>>a[i][0]>>a[i][1];
    }
    sort(all(a));
    rep(i,0,n){
        v.at(i+1)=a[i][1]+v.at(i);
    }
    rep(i,0,n+1){
        if(k<=v.at(i)){
            cout<<a[i-1][0]<<endl;
            return 0;
        }
    }
return 0;
}

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

using namespace std;

int n,d1,d2;
int col[603][603],col1[605][605],col2[605][605];
int dx[4803],dy[4803],cnt;
vector<pair<int,int> > typ[2][2];

void Col(int x,int y,int tar)
{
	col[x][y] = tar;
	for(int i = 1;i <= cnt; ++ i)
	{
		int nx = x + dx[i],ny = y + dy[i];
		if(nx >= 1 && nx <= n && ny >= 1 && ny <= n && !col[nx][ny])
			Col(nx,ny,tar ^ 1);
	}
}

int main()
{
	scanf("%d%d%d",&n,&d1,&d2);
	n *= 2;
	for(int i = 0;i <= n; ++ i)
		for(int j = i;j <= n; ++ j)
			if(i * i + j * j == d1)
			{
				dx[++ cnt] = i; dy[cnt] = j;
				dx[++ cnt] = j; dy[cnt] = i;
				dx[++ cnt] = -i; dy[cnt] = -j;
				dx[++ cnt] = -j; dy[cnt] = -i;
				dx[++ cnt] = i; dy[cnt] = -j;
				dx[++ cnt] = j; dy[cnt] = -i;
				dx[++ cnt] = -i; dy[cnt] = j;
				dx[++ cnt] = -j; dy[cnt] = i;
			}
	for(int i = 1;i <= n; ++ i)
		for(int j = 1;j <= n; ++ j)
		{
			if(!col[i][j])
				Col(i,j,2);
			col1[i][j] = col[i][j] - 2;
		}
	cnt = 0;
	for(int i = 0;i <= n; ++ i)
		for(int j = i;j <= n; ++ j)
			if(i * i + j * j == d2)
			{
				dx[++ cnt] = i; dy[cnt] = j;
				dx[++ cnt] = j; dy[cnt] = i;
				dx[++ cnt] = -i; dy[cnt] = -j;
				dx[++ cnt] = -j; dy[cnt] = -i;
				dx[++ cnt] = i; dy[cnt] = -j;
				dx[++ cnt] = j; dy[cnt] = -i;
				dx[++ cnt] = -i; dy[cnt] = j;
				dx[++ cnt] = -j; dy[cnt] = i;
			}
	memset(col,0,sizeof(col));
	for(int i = 1;i <= n; ++ i)
		for(int j = 1;j <= n; ++ j)
		{
			if(!col[i][j])
				Col(i,j,2);
			col2[i][j] = col[i][j] - 2;
			typ[col1[i][j]][col2[i][j]].push_back(make_pair(i,j));
		}
	for(int i = 0;i < 2; ++ i)
		for(int j = 0;j < 2; ++ j)
			if(typ[i][j].size() >= n * n / 4)
			{
				for(int k = 0;k < n * n / 4; ++ k)
					printf("%d %d\n",typ[i][j][k].first - 1,typ[i][j][k].second - 1);
				return 0;
			}
	return 0;
}

Measured memory_bytes: 30680
#include<bits/stdc++.h>
#define f0(i,n) for(int i=0;i<n;i++)
#define f1(i,n) for(int i=1;i<=n;i++)
#define f2(i,a,b) for(int i=a;i<=b;i++)
#define sp <<" "                // giving space
#define sp1 <<" "<<              // giving space between two elements
                 // new line
#define M 1000000007              // for mod
#define ll long long
#define ld long double
#define vii vector <pair<int,int>>
#define vll vector <pair<ll,ll>>
#define vi vector <int>
#define vl vector <ll>
#define pb(v,x) v.push_back(x)
#define mp(a,b) make_pair(a,b)
#define F first
#define S second
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define Sort(v) sort(v.begin(),v.end())
using namespace std;
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#include <set>
#include <map>


int main()
{
	ll h,ans=0,i=1;
	cin>>h;
	while(h)
	{
		ans+=i;
		i*=2;
		h/=2;
	}
	cout<<ans;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<utility>
#include<array>
#include<cassert>
#include<list>

using namespace std;

#define SPEEDY cin.tie(0);ios::sync_with_stdio(false);

#define REP(i,n) for(int i=0;i<(n);i++)
#define ARREP(i,n,X) for(int i=0;i<(n);i++)cin>>X[i]
#define FOR(i,X,n) for(int i=(X);i<(n);i++)
#define EREP(i,n) for(int i=1;i<=n;i++)

#define DEB(X) if(mode==1)cout<< #X <<": "<<X<<" ";
#define DEB2(X) if(mode==1)cout<<X<<" ";
#define ARDEB(i,X) if(mode==1)cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define FORDEB(n,X) if(mode==1)for(int i=0;i<(n);i++)ARDEB(i,X)
#define END if(mode==1)cout<<endl;

typedef long long int ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
#define ALL(X) X.begin(),X.end()
struct edge{int to,cost;};
struct P2{int x,y;};
//struct edge{int from,cost,to;};

const int MOD7=1000000007;
const int INF=100000000;
int mode=0;

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

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

int main() {
	int N;
	cin >> N;
	vector<int> X(N);
	for(int i = 0; i < N; i++)
		cin >> X.at(i);

	int L = X.at(0), R = X.at(0);
	for(int i = 0; i < N; i++) {
		L = min(L, X.at(i));
		R = max(R, X.at(i));
	}

	int ans = 1000000;
	for(int i = 0; i <= R; i++) {
		int power = 0;
		for(int j = 0; j < N; j++)
			power += (X.at(j) - i) * (X.at(j) - i);
		ans = min(ans, power);
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
x, y = map(int, input().split())
ans = 0
if x == 1:
    ans += 300000
elif x == 2:
    ans += 200000
elif x == 3:
    ans += 100000
if y == 1:
    ans += 300000
elif y == 2:
    ans += 200000
elif y == 3:
    ans += 100000
if x == 1 and y == 1:
    ans += 400000
print(ans)


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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;

#define rep(i,n) for(int i=0; i<(n); ++i)
#define all(n) begin(n),end(n)

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; }

#define DEBUG

int main()
{
	ios::sync_with_stdio(false); cin.tie(0);
	char a, b;
	cin >> a >> b;
	if(a == b) cout << 'H' << endl;
	else cout << 'D' << endl;;
	return 0;
}

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

using LL = long long;
const LL MOD = 1e9+7;

LL modpow(LL a, LL n) {
    LL ret = 1, tmp = a;
    while (n) {
        if (n & 1) (ret *= tmp) %= MOD;
        (tmp *= tmp) %= MOD;
        n >>= 1;
    }
    return ret;
}


int main()
{
    // O(KlogN + KloglogK)

    int N, K; cin >> N >> K;

    vector<LL> f(K+1);
    for (int d = 1; d <= K; ++d) {
        f[d] = modpow(K / d, N);
    }

    vector<bool> sieve(K+1, true);
    for (int p = 2; p <= K; ++p) {
        if (!sieve[p]) continue;
        for (int i = 1; i * p <= K; ++i) {
            sieve[i * p] = false;
            f[i] -= f[i * p];
            if (f[i] < 0) f[i] += MOD;
        }
    }

    LL ans = 0;
    for (int d = 1; d <= K; ++d) {
        (ans += f[d] * d) %= MOD;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3980
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cstdlib>
#include <math.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0, i##_len=(n); i<i##_len; ++i)
#define INF 1145141919
typedef long long int ll;
using namespace std;

int main(){
          int x;
          cin >> x;
          vector<bool>        expo(x+1);

          expo[1]=1;
          FOR(i,2,x+1){
                    int v=i*i;
                    while(v<=x){
                              expo[v] = 1;
                              v *= i;
                    }
          }
          for(int i=x;i>=1;i--)         if(expo[i]){
                    cout << i << endl;
                    return 0;
          }
}


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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            switch (Console.ReadLine())
            {
                case "A":
                    Console.WriteLine("T");
                    break;
                case "C":
                    Console.WriteLine("G");
                    break;
                case "G":
                    Console.WriteLine("C");
                    break;
                case "T":
                    Console.WriteLine("A");
                    break;
                default:
                    break;
            }
        }
    }
}

Measured memory_bytes: 11092
/*
	LINES :
		* easy
*/
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

#define pb push_back
#define F first
#define S second
#define WLL(t) while(t--)
#define FOR(i,a,b) for(int i = a; i < b; i++)
#define STF(i, a, b) for(size_t i = a; i < b; i++)
#define RFOR(i, a, b) for(int i = a; i >= b; i--)
#define SRF(i, a, b) for(size_t i = a;i >= b;i--)
#define ALL(v) v.begin(),v.end()
#define PRECISION(x) cout<<fixed<<setprecision(x)
#define FASTIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define READ freopen("input.txt", "r", stdin)
#define WRITE freopen("output.txt", "w", stdout)
#define MOD 1000000007
#define FILL fill(begin(v), end(v), x)

void solve(int n, int x, int t);
int main()
{
#ifdef OJ
	READ;
	WRITE;
#endif

	FASTIO;
	int n, x, t;
	cin >> n >> x >> t;
	solve(n, x, t);
	return 0;
}
void solve(int n, int x, int t)
{
	(n % x == 0) ? cout << t*(n / x) : cout << t*(n / x + 1);
	cout << "\n";
}

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

int main() {
  string S;
  cin >> S;
  string T = "";
  int pos = 0;
  while(pos < S.length()) {
    if(S[pos] == 'B' && S[pos+1] == 'C') {
      T += 'D';
      pos += 2;
    }
    else {
      T += S[pos];
      pos += 1;
    }
  }
  int64_t ans = 0;
  int64_t Anum = 0;
  for(int i = 0; i < T.length(); i++) {
    if(T[i] == 'A') {
      Anum++;
    }
    else if(T[i] == 'D') {
      ans += Anum;
    }
    else {
      Anum = 0;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 776
#include <iostream>
#include <string>
 
using namespace std;
 
int main() {
  string s; cin >> s;
  if (s == "RRR") {
    cout << 3 << endl;
  	return 0;
  }
  if (s == "SRR" || s == "RRS") {
    cout << 2 << endl;
  	return 0;
  }
  if (s == "SSS") {
    cout << 0 << endl;
  	return 0;
  }
  cout << 1 << endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define pb push_back
#define INF 0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f
#define endl '\n'
#define ll long long
#define f first
#define int long long
#define s second
#define FAST cin.tie(0), cout.tie(0), ios::sync_with_stdio(0)
#define debug(x) cout << "DEBUG " << x << endl
#define debug2(x, y) cout << "DEBUG " << x << " " << y << endl
#define debug3(x, y, z) cout << "DEBUG " << x << " " << y << " " << z<< endl
#define debug4(x, y, z, o) cout << "DEBUG " << x << " " << y << " " << z<< " " << o << endl
using namespace std;
typedef pair<int, int> pii;
typedef pair<int, pair<int, int>> ppi;
typedef vector<vector<int>> mat;
const ll mod = 1e9+7;
const ll cfmod = 998244353;
const int MAXN = 5 * 1e5+5;

int fat[MAXN], inv[MAXN];

ll expo(ll a, ll b){
    if(b == 0) 
		return 1;
    ll x = expo(a, b/2);
    return (b & 1 ? ((x*x)%mod*a)%mod : (x*x) % mod);
}
 
ll c(ll n, ll k) {
	if(n < k) return 0;
	if(n == k) return 1;
	return (((fat[n] * inv[k])%mod)*inv[n-k])%mod;
}

int32_t main() {
	int n, k;
	cin >> n >> k;
	vector<int> v(n);
	for(int &i : v)
		cin >> i;

	sort(v.begin(), v.end());
	
	fat[0] = inv[0] = fat[1] = inv[1] = 1;
	for(int i = 2; i < MAXN; i++) {
		fat[i] = (fat[i-1] * i)%mod;
		inv[i] = expo(fat[i], mod-2);
	}
	
	ll ans = 0;
	
	for(int i = 0; i < n; i++) 
		ans = (ans + v[i] * c(i, k-1))%mod;
		
	for(int i = 0; i < n; i++) {
		ans -= (v[i] * c( n - i - 1, k-1))%mod;
		if(ans < 0) ans += mod;
	}


	cout << ans%mod << endl;
}


Measured memory_bytes: 8832
#include<iostream>
#include<cmath>
#include<numeric>
#include<functional>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
#define ll long long
#define modbig (10*10*10*10*10*10*10*10*10+7)
using namespace std;

ll gcd(ll a,ll b){
  if(a<b){
    ll tmp=a; a=b; b=tmp;
  }
  ll r=a%b;
  while(r!=0){
    a=b;
    b=r;
    r=a%b;
  }
  return b;
}

int main(){
  ll k,ans=0; cin>>k;
  for(ll a=1;a<=k;a++){
    for(ll b=1;b<=k;b++){
      for(ll c=1;c<=k;c++){
        ans+=gcd(gcd(a,b),c);
      }
    }
  }
  cout<<ans;
}

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

int main() {
    ll x,n;
    cin>>x>>n;
    if(n == 0) {
        cout<<x<<endl;
        return 0;
    }
    ll ans1,ans2;
    vector<ll> a(n);
    for(int i=0; i<n; i++) cin>>a[i];
    sort(a.begin(),a.end());
    ll max = a[n-1];
    bool ok = true;
    for(int i=0; i<=x; i++) {
        for(int j=0; j<n; j++) {
            if(i == a[j]) ok = false;
        }
        if(!ok) {
            ok = true;
            continue;
        }
        ans2 = i;
    }
    ok = true;
    for(int i=max+1; i>=x; i--) {
        for(int j=0; j<n; j++) {
            if(i == a[j]) ok = false;
        }
        if(!ok) {
            ok = true;
            continue;
        }
        ans1 = i;
    }
    if(abs(ans1 - x) < abs(ans2 - x)) {
        cout<<ans1<<"\n";
    }
    else cout<<ans2<<"\n";
}

Measured memory_bytes: 3636
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<map>
using namespace std;
const int maxn = 1e3+10;

int read(){
	int x=0,f=1;
	char c=getchar();
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c)){x=(x<<3)+(x<<1)+c-48;c=getchar();}
	return x*f;
}

int k,m,n,t=0;
int pd[maxn*maxn],now[maxn],a[maxn][maxn];
queue<int> q[2];
int main(){
	n=read();
	for(register int i=1;i<=n;i++){
		for(register int j=1;j<n;j++){
			a[i][j]=read();
		}
		now[i]=1;
	}
	int num=0;
	for(register int i=1;i<=n;i++){
		int x=a[i][now[i]],y=i;
		if(x>y)swap(x,y);
		if(pd[x*1001+y]){
			pd[x*1001+y]=0;
			now[x]++;now[y]++;
			t=1;
			q[t].push(x);q[t].push(y);
			num++;
		}
		else pd[x*1001+y]=1;
	}
	if(num==n*(n-1)/2){
		puts("1");
		return 0;
	}
	//cout<<num<<endl;
	for(register int i=t;i<=n*n;i++){
		//cout<<q[i%2].size()<<endl;
		while(!q[i%2].empty()){
			int u=q[i%2].front();q[i%2].pop();
			if(now[u]==n)continue;
			int x=a[u][now[u]],y=u;
			if(x>y)swap(x,y);
			//cout<<u<<" "<<now[u]<<" "<<x<<" "<<y<<" "<<x*1001+y<<" "<<pd[x*1001+y]<<endl;
			if(pd[x*1001+y]){
				pd[x*1001+y]=0;
				now[x]++;now[y]++;
				q[(i+1)%2].push(x);q[(i+1)%2].push(y);
				num++;
			}
			else pd[x*1001+y]=1;
			//cout<<q[(i+1)%2].size()<<endl;
		}
		//cout<<num<<endl;
		if(num==n*(n-1)/2){
			printf("%d\n",i+1);
			return 0;
		}
	}
	puts("-1");
	return 0;
}

Measured memory_bytes: 8192
#include<iostream>
#include<cmath>

using namespace std;

#define REP(i,n) for(int i = 0;i < n;i++)
	
int e,r,t;
int main()
{
	while(cin >> e,e)
	{
		int z;r = 1e9;
		for(int z = 0;z*z*z <= e;z++)
		{
			t = sqrt(e-z*z*z);
			r = min(r,e-z*z*z-t*t+t+z);
		}
		
		cout << r << endl;
		
	}
	
	return 0;
}

Measured memory_bytes: 3060
import sys
input=sys.stdin.readline
n=int(input())
XL=[list(map(int,input().split())) for _ in range(n)]
XL.sort(key=lambda x:x[0]+x[1])
edge=XL[0][0]-XL[0][1]-1
ans=0
for x,l in XL:
    left=x-l
    right=x+l
    if left>=edge:
        ans+=1
        edge=right
print(ans)

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

#define gcd(m,n) __gcd(m,n)
#define lcm(m,n) m*(n/gcd(m,n))
#define fast std::ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pi acos(-1.0)
#define endl '\n'
#define MOD 1000000007
#define ull unsigned long long
#define ll long long
#define ld long double
#define pb push_back
#define dbg(x) cout << #x << "  " << x << endl;

using namespace std;

ll mod(ll a, ll b) { return (a % b + b) % b; }
ll power(ll base, ll exp) 
{ll res=1;while(exp>0) {if(exp%2==1) res=(res*base);base=(base*base);exp/=2;}return res;}

int main()
{
    fast;
    ll N,L; 
	string s;
	cin>>N>>L;
    vector<string>v;
    for(ll i = 0; i < N; i++)
    {
    	cin>>s;
    	v.pb(s);
	}
	sort(v.begin(),v.end());
	string str;
	for(ll i = 0; i < N; i++)
	{
		str += v[i];
	}
	cout << str << endl;
   	return 0;
} 

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

#define CHMIN(a, b) a=min((a), (b))
#define CHMAX(a, b) a=max((a), (b))

const ll MOD=1000000007ll;
// const ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int alf[30];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int h, w;
	char a;
	cin>>h>>w;
	REP(i, h){
		REP(j, w){
			cin>>a;
			++alf[a-'a'];
		}
	}
	int cnt=0, cnt2=0;
	REP(i, 26){
		if(alf[i]%2!=0){
			++cnt;
		}
		if(alf[i]%4!=0){
			++cnt2;
		}
	}
	bool ok=false;
	if(h&1 && w&1){
		if(cnt2<=(h+w)/2 && cnt==1){
			ok=true;
		}
	}
	else if(h&1){
		if(cnt2<=w/2 && cnt==0){
			ok=true;
		}
	}
	else if(w&1){
		if(cnt2<=h/2 && cnt==0){
			ok=true;
		}
	}
	else{
		if(cnt2==0){
			ok=true;
		}
	}
	cout<<(ok ? "Yes" : "No")<<'\n';
	return 0;
}


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

using ll = long long;
const int INF = 1001001001;

#define rep(i,n) for (int i = 0; i < (n); ++i)

class UnionFind {

public :
    int* par;
    // 自分のグループに何人属しているかを管理
    int* depth;
    UnionFind(int n);
    virtual ~UnionFind();
    // 同じグループにいるかどうか
    bool same(int x, int y);
    // 同じグループに所属させる
    void unite(int x,int y);
    // どのグループに属しているかを見つける
    int find(int x);
};

UnionFind::UnionFind(int n)
{
    par = new int[n];
    depth = new int[n];
    for (int i = 0; i < n; i++) {
        par[i] = i;
        depth[i] = 1;
    }
}

UnionFind::~UnionFind()
{
    delete[] par;
    delete[] depth;
}

int UnionFind::find(int x)
{
    if (par[x] == x) {
        return x;
    } else {
        par[x] = find(par[x]);
        return par[x];
    }
}

void UnionFind::unite(int x,int y) 
{
    int rootX, rootY;
    rootX = find(x);
    rootY = find(y);
    if (rootX == rootY) {
        return;
    }

    if (depth[rootX] < depth[rootY]) {
        par[rootX] = rootY;
        depth[rootY] += depth[rootX];
    } else {
        par[rootY] = rootX;
        depth[rootX] += depth[rootY];
    }
}

bool UnionFind::same(int x, int y)
{
    return find(x) == find(y);
}

typedef struct P {
  int x;
  int y;
  int z;
} P;

int main(void)
{
  ll n, m;
  cin >> n >> m;
  UnionFind u(n);
  rep(i, m) {
    int x, y, z;
    cin >> x >> y >> z;
    x--; y--;
    u.unite(x, y);
  }

  set<int> s;
  rep(i, n) {
    int root = u.find(i);
    s.insert(root);
  }
  cout << s.size() << endl;
}


Measured memory_bytes: 5760
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <climits>
using namespace std;
 
int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> x(n);
    for (int i = 0; i < n; i++)
    {
        cin >> x[i];
    }
    int ans = INT_MAX;
    for (int i = 0; i <= n - k; i++)
    {
        int temp = x[i + k - 1] - x[i] + min(abs(x[i]), abs(x[i + k - 1]));
        ans = min(ans,temp);
    }
    cout << ans << endl;
}

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

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

  vector<pair<int, int>> pairs(N);

  rep(i, N)
  {
    int A;
    cin >> A;
    pairs[i] = make_pair(A, i + 1);
  }
  sort(pairs.begin(), pairs.end());

  rep(i, N)
  {
    cout << pairs[i].second << " ";
  }

  cout << endl;
  return 0;
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
int a[100];
bool cmp(int x,int y)
{
	return x>y;
}
int main()
{
	int n,k;
	long long ans=0;
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)
	    scanf("%d",&a[i]);
	sort(a+1,a+n+1,cmp);
	for(int i=1;i<=k;i++)
	    ans+=a[i];
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 256
(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter OPT
    #+swank '(optimize (speed 3) (safety 1))
    #-swank '(optimize (speed 3) (safety 0) (debug 0)))
  #+swank (ql:quickload :cl-debug-print))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)

;; BEGIN_INSERTED_CONTENTS
(declaim (inline read-line-into))
(defun read-line-into (buf-str &optional (in *standard-input*) (terminate-char #\Nul))
  (declare (optimize (speed 3) (safety 1))
	   (simple-base-string buf-str))
  (loop for ch of-type base-char =
           #-swank (code-char (read-byte in nil #\Newline))
           #+swank (read-char in nil #\Newline)
        for idx = 0 then (1+ idx)
        until (char= ch #\Newline)
        do (setf (aref buf-str idx) ch)
        finally (setf (aref buf-str idx) terminate-char)
                (return buf-str)))

(defmacro println (obj &optional (stream '*standard-output*))
  `(let ((*read-default-float-format* 'double-float))
     (prog1 (princ ,obj ,stream) (terpri ,stream))))

;; Hauptteil
(deftype uint nil `(integer 0 ,(expt 10 9)))
(defun main ()
  (declare #.OPT)
  (let* ((n (read))
         (k (read))
         (table (make-array (list n) :element-type 'uint))
         (buf (make-string 11 :element-type 'standard-char :initial-element #\Newline)))
    (declare (uint k))
    (dotimes (idx n)
      (setf (aref table idx)
            (parse-integer (read-line-into buf *standard-input* #\Newline) :junk-allowed t)))
    (sort table #'<)
    (println
     (loop for begin-idx from 0
           for end-idx from (- (min k (length table)) 1) below (length table)
           minimize (- (aref table end-idx) (aref table begin-idx))))))

#-swank(main)


Measured memory_bytes: 20960
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>

using namespace std;



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

	int n;
	cin >> n;

	cout << n * 1LL * (n - 1) / 2LL;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
char s[4];
int main(){
	cin >> s;
	int flagA = 0, flagB = 0;
	for(int i = 0; i < 3; ++i)
		if(s[i] == 'A') flagA = 1;
		else if(s[i] == 'B') flagB = 1;
	if(flagA and flagB)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
    int n;
    cin >> n;
    double ii = 1;
    rep(i,n){
        if(int(floor(1.08*ii))==n){
            cout << ii << endl;
            return 0;
        }
        ii++;
    }
    cout << ":(" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
string S;
 cin >> S;
if(S=="SAT"){cout << "1" << endl;}
if(S=="FRI"){cout << "2" << endl;}
if(S=="THU"){cout << "3" << endl;}
if(S=="WED"){cout << "4" << endl;}
if(S=="TUE"){cout << "5" << endl;}
if(S=="MON"){cout << "6" << endl;}
if(S=="SUN"){cout << "7" << endl;}

return 0;
}


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

typedef long long int ll;


int main()
{
    ll n;
    cin >> n;
    vector<ll> a(n);
    for(ll i = 0;i < a.size();i++){
        cin >> a[i];
    }

    ll ans = 0;
    for(ll i = 0;i <= 60;i++){
        ll cnt = 0;
        for(ll j = 0;j < a.size();j++){
            ll t = a[j];
            t = t >> i;
            if(t % 2 != 0){
                cnt++;
            }
        }
        ans += ((cnt * (n - cnt)) % 1000000007) * (((ll)1 << i) % 1000000007);
        ans %= 1000000007;
    }

    cout << ans;


    return 0;
}

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

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int a, b;
	cin >> a >> b;
	if(a < 10 && b < 10) {
		cout << a*b << endl;
	} else {
		cout << -1 << endl;
	}
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    long long k;    cin >> k;
    long long a = 0;

    for (long long i = 1; i <= k; i++) {
        a = (a*10) % k + 7;
        a %= k;
        if (a == 0) {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 3636
n, m = map(int, input().split())
a = {int(input()) for _ in range(m)}
dp = [0] * (n + 1)
dp[0] = 1
dp[1] = 0 if 1 in a else 1
for i in range(2, n+1):
    dp[i] = (dp[i - 1] + dp[i - 2]) % (10 ** 9 + 7)
    if i in a: dp[i] = 0
print(dp[n])


Measured memory_bytes: 11884
#include<bits/stdc++.h>
using namespace std;
int vmax=10000;
int A[1005],B[1005],T[20000];
bool M[1005];
int main()
{
	int S;//记录每个环内元素值的总和
	int Min;//记录整个数组的最小值 
	int num=0;//记录最小成本 
	int m;//记录整个环内最小值，方便调换元素 
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%d",&A[i]);
		B[i]=A[i];
		M[i]=false;//false表示该位置的元素没有合理归为 
	}
	sort(B,B+n);
	Min=B[0]; 
	for(int i=0;i<n;i++) T[B[i]]=i;//B[i]这个数排序后的位置 
	for(int i=0;i<n;i++)
	{
		int weizhi=i;
		int S=0;//记录环内元素总值 
		int m=vmax;
		int ans=0;//记录环内元素个数
		if(M[weizhi]) continue;//该位置元素归为则跳过 
		 
		while(1)
		{
			M[weizhi]=true;//没有归为
			ans++;
			int cur=A[weizhi];
			S+=cur;
			m=min(m,cur);
			weizhi=T[cur];
			if(M[weizhi]) break;
		 }
		  num+=min((S+(ans-2)*m),S+m+(ans+1)*Min);
	}
	printf("%d\n",num);
	
	
} 


Measured memory_bytes: 3284
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
const long long linf = 1e18;

using Matrix = vector<vector<long long>>;

void warshall_floyd(Matrix& m)
{
    const int V = m.size();
    for (int k = 0; k < V; k++) {
        for (int i = 0; i < V; i++) {
            for (int j = 0; j < V; j++) {
                m[i][j] = min(m[i][j], m[i][k] + m[k][j]);
            }
        }
    }
}

int main()
{
    int v, e; cin >> v >> e;
    Matrix m(v, vector<ll>(v, linf));
    for (int i = 0; i < v; i++) m[i][i] = 0;
    for (int i = 0; i < e; i++) {
        int s, t, d; cin >> s >> t >> d;
        m[s][t] = d;
    }
    warshall_floyd(m);
    for (int i = 0; i < v; i++) {
        if (m[i][i] < 0) {
            cout << "NEGATIVE CYCLE" << endl;
            return 0;
        }
    }
    for (int i = 0; i < v; i++) {
        for (int j = 0; j < v; j++) {
            cout << (m[i][j] >= linf/2 ? "INF" : to_string(m[i][j])) << " \n"[j==v-1];
        }
    }
    return 0;
}


Measured memory_bytes: 3292
#include<bits/stdc++.h>
using namespace std;
#define REP(i,st,ed) for(int i=(int)(st),i##end=(int)(ed);i<=i##end;++i)
#define DREP(i,st,ed) for(int i=(int)(st),i##end=(int)(ed);i>=i##end;--i)
template<typename T>bool chkmin(T &x,const T &y){return x>y?x=y,1:0;}
template<typename T>bool chkmax(T &x,const T &y){return x<y?x=y,1:0;}
#ifdef __linux__
#define getchar getchar_unlocked
#define putchar putchar_unlocked
#endif
template<typename T>T read(){
	T x=0,f=1;
	char c=getchar();
	while((c<'0')||(c>'9')){if(c=='-')f=-1;c=getchar();}
	while((c>='0')&&(c<='9'))x=(x<<1)+(x<<3)+(c^48),c=getchar();
	return x*f;
}
#define read() read<int>()
template<typename T>void write(T x,char c){
	static char t[25];
	static int tlen;
	t[tlen=1]=c;
	if(x<0)putchar('-'),x=-x;
	do t[++tlen]=(x%10)^48;
	while(x/=10);
	while(tlen)putchar(t[tlen--]);
}
const int maxn=100005;
int n,cnt[maxn];
int main(){
	int ans=0,k;
	n=read();
	REP(i,1,n){
		k=read();
		if(k>n)++ans;
		else ++cnt[k];
	}
	REP(i,1,n){
		if(cnt[i]>=i)ans+=cnt[i]-i;
		else ans+=cnt[i];
	}
	write(ans,'\n');
	return 0;
}

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

using namespace std;

int a, b, c, x, y, hv;
long long ans = LLONG_MAX, cur;

int main() {
	scanf("%d%d%d%d%d", &a, &b, &c, &x, &y);
	for (int i = 0; i <= max(x, y) * 2; i++) {
		hv = i / 2;
		cur = (long long)max(0, x - hv) * a;
		cur += (long long)max(0, y - hv) * b;
		cur += (long long)i * c;
		ans = min(ans, cur);
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.util.Scanner;

class Main {

	public static void main(String[] args) throws IOException {

		Scanner scane = new Scanner(System.in);

		int H =scane.nextInt();
		int W =scane.nextInt();;

		do {

			for(int i =0; i<H; i++){
				for (int j = 0; j < W; j++) {
					System.out.print("#");
				}
				System.out.println();
			}
			System.out.println();

			H = scane.nextInt();

			W= scane.nextInt();


		} while (H !=0 && W !=0);
	}
}

Measured memory_bytes: 35452
#include"bits/stdc++.h"
using namespace std;
#define REP(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define rep(i,n) REP((i),0,(n))
using ll=long long;

int main()
{
	int N;
	cin>>N;
	vector<int> a(N);
	rep(i,N)cin>>a[i];

	int cnt=1;
	rep(i,N)if(a[i]==cnt)cnt++;
	if(cnt==1){
		cout<<-1<<endl;
	}else{
		cout<<N-cnt+1<<endl;
	}

	return 0;
}


Measured memory_bytes: 1152
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

using namespace std;

#define fori(x) for (int i = 0; i < x; ++i)
#define forj(x) for (int j = 0; j < x; ++j)

typedef long long ll;

const int INF = 2e9 + 5;
const int alength=100100;

int main() {
	int r;
	cin>>r;
	if(r<1200){
		cout<<"ABC";
	}else if(r<2800){
		cout<<"ARC";
	}else{
		cout<<"AGC";
	}
}

Measured memory_bytes: 256
#include <stdio.h>
int num;
int  makeFibonacci(){
  int F[num+1],i;
  F[0]=1;
  F[1]=1;
  for(i=2;i<=num;i++){
    F[i]= F[i-2]+F[i-1];
  }
  return F[i-1];
}
int main(){
  scanf("%d",&num);
   
  printf("%d\n",makeFibonacci());
   
  return 0;
}

Measured memory_bytes: 596
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <iomanip>


using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy


ll findCommon(set<char> X, set<char> Y){
  ll ans = 0;
  for (auto it = X.begin(); it != X.end(); it++) {
    if(Y.find(*it) != Y.end()) ans ++;
  }
  return ans;
}

set<char> getSet(string s){
  set<char> ans;
  F0R(i,s.length()) ans.insert(s[i]);
  return ans;
}

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

    ll n;
    string s;
    cin >> n;
    cin >> s;
    ll ans = 0;

    F0R(i,s.length()){
      ll temp = findCommon(getSet(s.substr(0,i)),getSet(s.substr(i,n-i)));
      if(ans < temp)  ans = temp;
    }
    cout << ans << endl;
    return 0;
}

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


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

int main() {
    double A, B, H, M;
    cin >> A >> B >> H >> M;
    double rad = abs(30*H-5.5*M) * M_PI / 180;
    double ans = sqrt(A*A + B*B - 2*A*B*cos(rad));
    printf("%.10f\n", ans);
}

Measured memory_bytes: 4228
#include"bits/stdc++.h"
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pii;

void Main()
{
	int n, a, b;
	cin >> n >> a >> b;
	auto wa = [&](int x){
		int sum = 0;
		while(x>0){
			sum += x%10;
			x = (x-x%10)/10;
		}      
		return sum;
	};
	ll ans = 0;    
	rep3(i,1,n){
		if(a <= wa(i) && wa(i) <= b) ans += i;
	}
	cout << ans << endl;
	return;
}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long int lli;
const lli M=1e9+7,N=5e5+5;
lli fact[N];

lli binpow(lli a,lli b) 
{
    if (b == 0) return 1;
    lli res = binpow(a,b/2);
    res= (res*res)%M;
    
    if(b%2) return (res*a)%M;
    return res;
}
 
lli inv(lli a)
{
    return binpow(a,M-2);
}

lli add(lli a, lli b)
{
	lli res = a + b;
	if(res >= M)
		return res - M;
	return res;
}
 
lli mul(lli a, lli b)
{
	lli  res = a * b;
		return res % M;
}
 
lli sub(lli a, lli b)
{
	return (a%M -b%M +M) %M;
}

void pre()
{
    fact[0]=1;
    for(int i=1;i<N;i++)
        fact[i] = mul(fact[i-1], i);
}

lli npr(lli n, lli r)
{
    return mul(fact[n], inv(fact[n-r]));
}

lli ncr(lli n, lli r)
{
    return mul(fact[n], inv(mul(fact[n-r], fact[r])));    
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    pre();
    
    lli n,m;
    cin>>n>>m;
    lli i, ans=0, rem=0, sign=-1;
    
    ans=mul(npr(m, n), npr(m, n));
    
    for(i=1;i<=n;i++)
    {
        sign*=-1;
        rem=add(rem, mul(mul(mul(mul(ncr(m, i), npr(n, i)), npr(m-i, n-i)), npr(m-i, n-i)), sign));
    }
    ans=sub(ans, rem);
    cout<<ans;
    return 0;
}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  string s; cin >> s;
  char ope[2] = {'+', '-'};
  rep(i, 2) rep(j, 2) rep(k, 2) if(s[0]-'0' + (int)pow(-1, i)*(s[1]-'0') + (int)pow(-1, j)*(s[2]-'0') + (int)pow(-1, k)*(s[3]-'0') == 7) {
    cout << s[0] << ope[i] << s[1] << ope[j] << s[2] << ope[k] << s[3] << "=7" << endl;
    return 0;
  }
}

Measured memory_bytes: 3752
#include<iostream>
#include<algorithm>
using namespace std;
using ll = long long;

int main (){
    int n,s;
    cin >> n;
    s = n%10;
    if(s == 3){
        cout << "bon" << endl;
    }else if (s == 0 || s == 1 || s == 6 || s == 8){
        cout << "pon" << endl;
    }else cout << "hon" << endl;

return 0;
} 

Measured memory_bytes: 3128
import sys
input=sys.stdin.readline
n=int(input())
INF=10**9
D=[INF]*26
for i in range(n):
    d=[0]*26
    s=input().rstrip()
    for j in s:
        d[ord(j)-97]+=1
    for j in range(26):
        D[j]=min(D[j],d[j])
allzero=True
for i in range(26):
    if D[i]!=0:
        allzero=False
    print((chr(i+97))*D[i],end='')
if allzero:
    print('')


Measured memory_bytes: 39920
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstring>

typedef long long ll;
constexpr double PI = 3.141592653589793;
constexpr ll INF = 1e18 + 10;
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;
}

using namespace std;
//    cout << setprecision(20) << ans << "\n";

vector<pair<ll, ll>> primeFactorize(ll N)
{
    vector<pair<ll, ll>> res;
    for (ll a = 2; a * a <= N; ++a)
    {
        if (N % a != 0)
            continue;
        ll ex = 0;

        while (N % a == 0)
        {
            ++ex;
            N /= a;
        }
        res.push_back({a, ex});
    }

    if (N != 1)
        res.push_back({N, 1});
    return res;
}

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

    int a, b, c, x;
    cin >> a >> b >> c >> x;
    int count = 0;
    for (int i = a; i >= 0; --i)
    {
        for (int j = b; j >= 0; --j)
        {
            for (int k = c; k >= 0; --k)
            {
                int sum = 500 * i + 100 * j + 50 * k;
                if (sum == x)
                {
                    count++;
                }
            }
        }
    }

    cout << count << "\n";

    return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ul;
typedef signed long long ll;
ul over = 1000000007;

void dfs(int idx, int invalid, vector< vector< tuple< int, int > > > & path, vector< bool > & visited)
{
  visited[idx] = true;
  for (auto c : path[idx]) {
    if (get<1>(c)==invalid) continue;
    if (visited[get<0>(c)]) continue;
    dfs(get<0>(c), invalid, path, visited);
  }
}

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  int n, m;
  cin >> n >> m;
  vector< vector< tuple< int, int > > > path(n);
  for (int i=0; i<m; ++i) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    path[a].push_back(make_tuple(b, i));
    path[b].push_back(make_tuple(a, i));
  }
  int ans = 0;
  for (int i=0; i<m; ++i) {
    vector< bool > visited(n, false);
    dfs(0, i, path, visited);
    for (int i=0; i<n; ++i) {
      if (visited[i]==false) {
        ans++;
        break;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()

template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }

template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a) {
    out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
    out<<'[';
    for(const T &i: a) out<<i<<',';
    out<<']';
    return out;
}
template<class T>
ostream &operator <<(ostream& out, const set<T>& a) {
    out<<'{';
    for(const T &i: a) out<<i<<',';
    out<<'}';
    return out;
}
template<class T, class S>
ostream &operator <<(ostream& out, const map<T,S>& a) {
    out<<'{';
    for(auto &i: a) out<<i<<',';
    out<<'}';
    return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;

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

    ll n;
    string s;
    cin >> n >> s;

    ll x = 0, y = 0;
    REP(i, n) {
        if('A' <= s[i] && s[i] <= 'M') {
            y--;
        } else if('N' <= s[i] && s[i] <= 'Z') {
            y++;
        } else if('a' <= s[i] && s[i] <= 'm') {
            x++;
        } else if('n' <= s[i] && s[i] <= 'z') {
            x--;
        }
    }

    string ans = "";
    if(y < 0) ans += string(abs(y), 'A');
    else ans += string(y, 'N');
    if(x < 0) ans += string(abs(x), 'n');
    else ans += string(x, 'a');
    cout << ans.size() << endl << ans << endl;

    return 0;
}



Measured memory_bytes: 3352
# -*- coding: utf-8 -*-

def abc159d(n, arr):
    dic = {}
    for a in arr:
        if a in dic:
            dic[a] += 1
        else:
            dic[a] = 1
    
    # delete non-paired ball
    del_list = []
    for k, val in dic.items():
        if val == 1:
            del_list.append(k)
    for item in del_list:
        del dic[item]

    typ_ans = 0
    for val in dic.values():
        typ_ans += val * (val-1) // 2
    
    ans = []
    for a in arr:
        sum = typ_ans
        if a in dic:
            sum -= dic[a] * (dic[a]-1) // 2
            new_val = dic[a] - 1
            sum += new_val * (new_val-1) // 2

        ans.append(sum)

    return ans

###
# main
if(__name__ == '__main__'):
    # input
    n = int(input())
    arr = input().split(" ")
    
    ans = abc159d(n, arr)
    
    # output
    for a in ans:
        print(a)
# else:
    # do nothing


Measured memory_bytes: 28956
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func readInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func readString() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc.Split(bufio.ScanWords)
	n := readInt()

	p := ""
	rest := ""
	for i := 0; i < n; i++ {
		p += readString()
		rest += strconv.Itoa(i + 1)
	}
	q := ""
	for i := 0; i < n; i++ {
		q += readString()
	}
	permList := make([]string, 0)
	permutation("", rest, &permList)

	pi, qi := 0, 0
	for i, str := range permList {
		if str == p {
			pi = i
		}
		if str == q {
			qi = i
		}
	}
	fmt.Println(abs(pi - qi))
}

func abs(x int) int {
	if x < 0 {
		return x * -1
	}
	return x
}

func permutation(head, rest string, result *[]string) {
	if len(rest) == 0 {
		*result = append(*result, head)
		return
	}
	for i := 0; i < len(rest); i++ {
		headx := head + string(rest[i])
		restx := rest[:i] + rest[i+1:]
		permutation(headx, restx, result)
	}
}


Measured memory_bytes: 5120