akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("O3")

#include "bits/stdc++.h"
#include "ext/pb_ds/tree_policy.hpp"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/rope"

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for(int i = 0; i < (a); ++i)
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define f first
#define s second

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

struct custom_hash 
{
    static uint64_t splitmix64(uint64_t x) 
    {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const 
    {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, l;
    cin >> n >> l;
    vector<int> fl(n, 0);
    F0R(i, sz(fl))
    {
        fl[i] = l + i;
    }
    ll r = 0;
    F0R(i, sz(fl))
    {
        r += fl[i];
    }
    ll dif = abs(fl[0]);
    ll idx = 0;
    F0R(i, sz(fl))
    {
        if(dif > abs(fl[i]))
        {
            dif = abs(fl[i]);
            idx = i;
        }
    }
    cout << r - fl[idx];
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 100000005
#define MAX 100001
#define fi first
#define se second
using namespace std;
//__gcd(a,b), __builtin_popcount(a);

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

Measured memory_bytes: 256
x,n = map(int,input().split())
if n != 0:
  a = list(map(int,input().split()))
else:
  print(x)
  exit(0)
b = [0]*100
c = [0]*100
for i in range(n):
  if a[i]-x > 0:
    b[a[i]-x] += 1
  elif a[i] -x <0:
    c[abs(a[i]-x)] += 1
  else:
    b[0]+=1
    c[0]+=1
for i in range(100):
  if b[i] == 0 and c[i] == 0:
    print(x-i)
    exit(0)
  elif b[i] == 0:
    print(x+i)
    exit(0)
  elif c[i] == 0:
    print(x-i)
    exit(0)

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

int  main()
{
	int n; cin >> n;
	string s; cin >> s;
	priority_queue<int> que;
	rep(i, n)
	{
		string l; string r;
		l = s.substr(0, i + 1);
		r = s.substr(i + 1, (n - 1) - i);
		int cnt = 0;
		for (char a = 'a'; a <= 'z'; a++)
		{
			if (count(l.cbegin(), l.cend(), a) && count(r.cbegin(), r.cend(), a))
				cnt++;
		}
		que.push(cnt);
	}
	cout << que.top() << endl;
	return (0);
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <numeric>
#include <functional>
#include <set>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <climits>
#include <fstream>
#include <bitset>
#include <time.h>
#include <assert.h>
#include <unordered_map>

#define LL long long
#define VI vector<int>
#define VL vector<long long>
#define FOR(i,a,b) for(int i= (a); i<((int)b); ++i)
#define RFOR(i,a) for(int i=(a); i >= 0; --i)
#define FOE(i,a) for(auto i : a)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v,x) (std::find(v.begin(), v.end(), x) != v.end())
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define bitcount(b) __builtin_popcount(b)
const double EPS = 1e-10;
const double PI = acos(-1.0);
#define MOD 1000000007

using namespace std;



int dfs(int v, int parent, int d, const vector<vector<int>> &graph, int K) {
    if (d >= K) {
        return 0;
    }

    int ans = 1;
    FOE(w, graph[v]) {
        if (w != parent && w != v) {
            ans += dfs(w, v, d + 1, graph, K);
        }
    }
    return ans;
}



int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K, A, B;
    cin >> N >> K;

    vector<vector<int>> graph(N);
    vector<pair<int, int>> e;
    FOR(i, 0, N - 1) {
        cin >> A >> B;
        --A; --B;
        graph[A].push_back(B);
        graph[B].push_back(A);
        e.push_back({A, B});
    }
    int ans = N - 1;
    if (K % 2 == 0) {
        FOR(v, 0, N) {
            int num = 1;
            FOE(w, graph[v]) {
                num += dfs(w, v, 0, graph, K / 2);
            }
            ans = min(ans, N - num);
        }
    }
    else {
        FOE(p, e) {
            int v = p.first;
            int w = p.second;
            int num = 0;
            num += dfs(v, w, 0, graph, K / 2 + 1);
            num += dfs(w, v, 0, graph, K / 2 + 1);
            ans = min(ans, N - num);
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(9), 0);
//int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv ./prog.exe") >> 8), 0);
int dp[1000][1000];
int main() {
    int H, W, Ch, Cw, Dh, Dw;
    cin >> H >> W >> Ch >> Cw >> Dh >> Dw;
    Ch--, Cw--, Dh--, Dw--;
    vector<string> S(H);
    for (auto &s : S) cin >> s;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            dp[i][j] = 1e9;
        }
    }
    deque<tuple<int, int, int>> Q;
    dp[Ch][Cw] = 0;
    Q.emplace_back(0, Ch, Cw);
    while (!Q.empty()) {
        auto [num, i, j] = Q.front();
        Q.pop_front();
        if (dp[i][j] != num) continue;
        for (int ni = i - 2; ni <= i + 2; ni++) {
            for (int nj = j - 2; nj <= j + 2; nj++) {
                int near = abs(ni - i) + abs(nj - j) <= 1;
                if (0 <= ni && ni < H && 0 <= nj && nj < W &&
                    S[ni][nj] == '.' && (num + !near) < dp[ni][nj]) {
                    if (near) {
                        dp[ni][nj] = num;
                        Q.emplace_front(num, ni, nj);
                    } else {
                        dp[ni][nj] = num + 1;
                        Q.emplace_back(num + 1, ni, nj);
                    }
                }
            }
        }
    }
    if (dp[Dh][Dw] == 1e9) dp[Dh][Dw] = -1;
    cout << dp[Dh][Dw] << endl;
    return 0;
}


Measured memory_bytes: 8640
#include <stdio.h>
#define NIL -1
int F[45];
int fibonacci(int n)
{
    if(n == 0||n == 1){return F[n] = 1;}
    if(F[n]!=NIL){return F[n];}
    return F[n] = fibonacci(n-2)+fibonacci(n-1);
}
int main(int argc, const char * argv[]) {
    int n;
    for(int i = 0;i<45;i++){F[i]=NIL;}
    scanf("%d", &n);
    int num = fibonacci(n);
    printf("%d\n", num);
    return 0;
}



Measured memory_bytes: 2112
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<ll,ll,ll> T;
const long long INF = 1LL<<60;
// const int MOD = 1000000000+7;
#define rev(s) (string((s).rbegin(), (s).rend()))
// cout << fixed << setprecision(10) << ans << endl; 有効桁数指定
// *min_element(c + l, c + r) *max_element(c + l, c + r) 配列の中のmin-max
// int dx[8]={1,1,0,-1,-1,-1,0,1};
// int dy[8]={0,1,1,1,0,-1,-1,-1};
// int dx[4]={1,0,-1,0};
// int dy[4]={0,1,0,-1};
// ~ は、-1の時だけfalse

const int MAX = 1000010;
const int MOD = 1000000007;

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

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

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

// int main() {
//     // 前処理
//     COMinit();

//     // 計算例
//     cout << COM(100000, 50000) << endl;
// }


int main () {

    string s;cin>>s;

    int n = s.size();

    rep(i,n-1) {
        if (s[i]==s[i+1]) {
            cout<<i+1<<" "<<i+2<<endl;
            return 0;
        }
    }

    rep(i,n-2) {
        if (s[i]==s[i+2]) {
            cout<<i+1<<" "<<i+3<<endl;
            return 0;
        }
    }

    cout<<-1<<" "<<-1<<endl;

}

Measured memory_bytes: 512
#include<stdio.h>
#define N 100

typedef struct {

  char moji;
  int num;

}data;

int isStable(data*,data*,int);

int main(){
  data A[N],B[N],C[N],temp1,temp2;
  int i,j,k,n,flag,minj;

  scanf("%d",&n);

  for(i = 0; i < n; i++){
    scanf(" %c%d",&A[i].moji,&A[i].num);
    B[i]=A[i];
    C[i]=A[i];
  }

  //babbule
  flag=1;

  while(flag==1){

    flag=0;

    for(j = n-1; j >= 1; j--){

      if(A[j].num < A[j-1].num){
	temp1 = A[j];
	A[j] = A[j-1];
	A[j-1] = temp1;
	flag = 1;
	
      }
      
    }//for

  }//while

  i=0;
  j=0;

  //serect

   for(i = 0; i <= n-1; i++){

    minj = i;
    
    for(j = i; j <= n-1; j++){

      if(B[j].num < B[minj].num){
	minj = j;
      }
      
    }//for

    if(i != minj){
      
      temp2 = B[i];
      B[i] = B[minj];
      B[minj] = temp2;
    
    }
    

  }//for

  for(k = 0; k < n; k++){
    printf("%c%d",A[k].moji,A[k].num);
    if(k != n-1) printf(" ");
    else printf("\n");
  }
  
  if(isStable(C,A,n)==1){
    printf("Stable\n");
  }else{
    printf("Not stable\n");
  }

  for(k = 0; k < n; k++){
    printf("%c%d",B[k].moji,B[k].num);
    if(k != n-1) printf(" ");
    else printf("\n");
  }

  if(isStable(C,B,n)==1){
    printf("Stable\n");
  }else{
    printf("Not stable\n");
  }

  return 0;
  
}

int isStable(data *in,data *out,int n){

  int a,b,i,j;

  for(i=0;i<n-1;i++){

    for(j=i+1;j<n-1;j++){

      for(a=0;a<n-1;a++){

	for(b=a+1;b<n-1;b++){

	  if(in[i].num==in[j].num && in[i].num == out[b].num && in[j].num == out[a].num && in[i].moji==out[b].moji && in[j].moji==out[a].moji) return 0;

	}
	
      }
    }
  }

  return 1;
  
}



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

const int mod = 1e9 + 7;
long long n, k, cnt = 1, dp[1500], ans = 0;
vector<long long> divisors;

long long power(long long a, long long n) {
    if(n == 0) return 1;
    if(n == 1) return a;
    long long b = power(a, n/2);
    b = (b*b) % mod;
    if(n&1) b = (b*a) % mod;
    return b;
}

int main() {
    scanf("%lld%lld", &n, &k);
    long long p = sqrt(n);
    for(int i = 1; i <= p; i++) {
        if(n % i == 0) {
            divisors.push_back(i);
            long long q = n/i;
            if(q > i) divisors.push_back(q);
        }
    }
    sort(divisors.begin(), divisors.end());
    for(int i = 0; i < divisors.size(); i++) {
        dp[i] = power(k, (divisors[i] + 1)/2) % mod;
        for(int j = 0; j < i; j++) {
            if(divisors[i] % divisors[j] == 0) dp[i] = (dp[i] - dp[j] + mod) % mod;
        }
        ans = ((divisors[i]&1 ? divisors[i] : divisors[i]>>1) * dp[i] + ans) % mod;
    }
    printf("%lld", ans);
}


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

int main(){
    int N;          // 入力
    char str[100];    // 入力
    
    scanf("%d", &N);
    scanf("%s", str);
    
    int mojisuu = strlen(str);

    if(N < mojisuu)
    {
        for(int i = 0;i < N ; i++)
        {
            printf("%c", str[i]);
        }
        printf("...");
    }
    else
    {
        printf("%s\n",str);
    }
    
}


Measured memory_bytes: 1708
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author cherrypi59
 */

#pragma GCC optimize ("O2")
#pragma GCC optimize ("tree-vectorize")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define FFOR(i, a, b) FOR(i, a, b+1)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) FOR(i, 1, n+1)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define LEN(x) (int)(x).size()
#define DUMP(x) cerr<<__LINE__<<' '<<#x<<"="<<(x)<<endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair

using namespace std;
using lint = long long;
using pii =  pair<int, int>;
using pll =  pair<lint, lint>;
template <typename T> using vc = vector<T>;
template <typename T> using vvc = vector<vector<T>>;
template <typename T> inline bool chmax(T &a, T b){if(a<b){a = b; return true;} return false;}
template <typename T> inline bool chmin(T &a, T b){if(a>b){a = b; return true;} return false;}

constexpr lint ten(int n) {return n==0 ? 1 : ten(n-1)*10;}

class BVotingJudges {
public:
    int N, M, V, P;
    vc<int> A;

    void solve(std::istream& in, std::ostream& out){
        ios_base::sync_with_stdio(false);
        in.tie(nullptr), out.tie(nullptr);
        in>>N>>M>>V>>P;
        A.resize(N);
        for(auto& a : A) in>>a;
        sort(ALL(A));
        int left = -1, right = N + 1;
        auto check = [&](int x){
            int cnt = A.end() - upper_bound(ALL(A), A[x]+M);
            if(cnt>=P) return false;
            if(N-x<=P) return true;
            lint sum = M;
            REP(i, N){
                if(i==x) continue;
                if(i>N-P) sum += M;
                else sum += min(M, A[x]+M-A[i]);
            }
            return sum >= 1ll * M * V;
        };
        while(1<right-left){
            int mid = (left+right) >> 1;
            if(check(mid)) right = mid;
            else left = mid;
        }
        out<<N-right<<'\n';
    }
};


int main() {
	BVotingJudges solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3708
from collections import *
from itertools import *
from bisect import *
from heapq import *
import copy
import math
from fractions import gcd
import sys
from decimal import *
#input = sys.stdin.readline


#N=int(input())

#A=list(map(int,input().split()))
#XY=[list(map(int,input().split())) for i in range(N)]

N=int(input())
lst=[i for i in range(1,N)]
lst2=[[] for i in range(N)]
lst2[0].append([0])

for l in lst:
    for l2 in lst2[l-1]:
        for i in range(max(l2)+2):
            lst2[l].append(l2+[i])

lst2=lst2[-1]
lst2=sorted(["".join([chr(m+ord("a"))for m in l]) for l in lst2 ])
for i in lst2:
    print(i)


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

void count(int input, int & sum)
{
  int temp = input / 10;
  if(temp != 0)
  {
    count(temp, sum);
  }
  sum+= input % 10;
}
 
int main(){
  int N = 0;
  int sum;
  cin >> N;
  count(N, sum);
  if((N % sum) == 0)
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }
}


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

#define ll long long
#define db double
#define deb(x) cout<<#x<<": "<<x<<"\n"
#define all(x) x.begin(),x.end()
#define fo(i, n) for(i=0 ; i<n ; i++)
#define Fo(i, k, n) for(i=k ; i<n ; i++)

using namespace std;
using namespace chrono;

const ll mod = 1000000007;
const ll N = 300005;  // array size
const ll inf = 10000000000000000;


void print(vector<ll> v) {
    ll i;
    fo(i, v.size())cout << v[i] << " ";
    cout << "\n";
}

vector<ll> read(ll n) {
    ll i;
    vector<ll> arr(n, 0);
    fo(i, n)cin >> arr[i];
    return arr;
}

vector<ll> read(ll n, ll k) {
    ll i;
    vector<ll> arr(n + k, 0);
    Fo(i, k, n + k)cin >> arr[i];
    return arr;
}

bool isEven(ll n) {
    return n % 2 == 0;
}

bool isOdd(ll n) {
    return n % 2 != 0;
}


void solve() {
    ll t;
    cin >> (t);
    while (t--) {

        ll i, j, k, n, m, p, q, x, y, a, b, l, r;


    }
}


ll find(ll n) {

    ll count = 0;

    for (ll i = 5; n / i >= 1; i *= 5)
        count += n / i;

    return count;
}

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
#endif

    auto start = high_resolution_clock::now();

    ll i, j, k, n, m, p, q, x, y, a, b, l, r;

    cin>>n;

    if(isOdd(n)){
        cout<<0<<"\n";
    } else {
        cout<<find(n/2);
    }

    auto stop = high_resolution_clock::now();
    auto duration = duration_cast<microseconds>(stop - start);
#ifndef ONLINE_JUDGE
    cerr << "Time: " << duration.count() / 1000.0 << endl;
#endif

//    124999999999999995
    

    return 0;
}




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

// マクロ //
#define rep(i,N) for(int i = 0; i < (int)(N); i++)
#define all(x) x.begin(), x.end()
#define sort(x) sort(all(x))
#define uniq(x) x.erase(unique(all(x)), x.end())
#define vsum(x) accumulate(all(x), 0)
#define cou(x) cout << x << endl
#define y() cout << "Yes" << endl
#define n() cout << "No" << endl
#define Y() cout << "YES" << endl
#define N() cout << "NO" << endl
#define x2(x) (x) * (x)
#define db(i) cout << #i << " = " << i;

// 型エイリアス //
using lint = long long;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vi = vector<int>;
using vli = vector<lint>;
using vc = vector<char>;
using vs = vector<string>;
using vb = vector<bool>;
using vvi = vector<vi>;
using vvli = vector<vli>;
using vvb = vector<vb>;
using vvc = vector<vc>;
using vvs = vector<vs>;
using mii = map<int, int>;
using mili = map<int, lint>;
using mci = map<char, int>;
using mcli = map<char, lint>;
using msi = map<string, int>;
using msli = map<string, lint>;


// 関数 //
template<class T, class Q> lint gcd_(T a, Q b) {
    int t;
    while (b != 0) {
        t = a % b;
        a = b;
        b = t;
    }
    return a;
}

template<class T, class Q> lint lcm_(T a, Q b) {
    return a * b / gcd(a, b);
}

double distance(pii a, pii b) {
    double dist;
    dist = sqrt(x2(a.first - b.first) + x2(a.second - b.second));
    return dist;
}

lint perm(int a) {
    lint perm = 1;
    for (int i = a; i >= 1; i--) {
        perm *= i;
    }
    return perm;
}

lint combination(int n, int m) {
    long double c = 1;
    for (int i = n, k = 1; i > m; i--, k++) {
        c *= i;
        c /= k;
    }
    return (lint)c;
}

template<class T, class Q> inline bool chmin(T& a, Q b) {
    if (a > b) { 
        a = b;
        return true; 
    }
    return false;
}

template<class T, class Q> inline bool chmax(T& a, Q b) {
    if (a < b) { 
        a = b; 
        return true; 
    }
    return false;
}

// 定数 //
const double pi = acos(-1);
const int mod = 1000000007;
const int MOD = 998244353;
const int inf = 1045141919;
const lint linf = ((1LL << 62) - 1);


// キーワード //
#define elif else if

// End of Template //



int main() {

    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
        
    lint N;
    cin >> N;
    lint sum = 100;
    int cnt = 0;
    while (sum < N) {
        sum *= 1.01;
        cnt++;
    }
    cou(cnt);

}

Measured memory_bytes: 3684
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const double EPS = 1e-7;
const int INF = INT_MAX;
const ll LLINF = INT64_MAX;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a,b,c;
  cin>>a>>b>>c;
  cout<<(b-a==c-b?"YES":"NO")<<endl;
}

Measured memory_bytes: 256
n,k = (int(i) for i in input().split())
p = [[int(i) for i in input().split()] for i in range(n)]
p,ans = sorted(p),float("inf")
q = list(enumerate(p))
for i,(a,b) in q[:n-k+1]:
	for j,(c,d) in q[i+k-1:]:
		r = sorted(y for x,y in p[i:j+1])
		r2 = r[k-1:]
		for i2,j2 in zip(r,r2):
			if i2<=b and d<=j2: ans = min(ans,(c-a)*(j2-i2))
print(ans)

Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<cstring>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
#include<time.h>
#include<cassert>

using namespace std;
#define ll long long
#define ld long double
#define int long long
#define all(a) (a).begin(),(a).end()
#define EPS (1e-13)
#define fs first
#define sc second
#define xx first
#define yy second.first
#define zz second.second
#define H pair<int, int>
#define P pair<int, pair<int, int>>
#define Q(i,j,k) mkp(i,mkp(j,k))
#define rep(i,n) for(int (i) = 0 ; (i) < (n) ; (i)++)
#define mkp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define crdcomp(b) sort(all((b)));(b).erase(unique(all((b))),(b).end())
#define ssp(i,n) (i==n-1?"\n":" ")
const int mod = 1e9 + 7;
const int Mod = 998244353;
const ll Inf = 3 * 1e18;
const int inf = 15 * 1e8;
ll read() {
	ll u, k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j % i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}
ll bcount(ll x) {
	int sum = 0;
	for (int i = 0; i < 20; i++)
		if ((1ll << i) & x) sum++;
	return sum;
}
const int fn_ = 2000000;
ll fact_[fn_], comp_[fn_];
ll comb(ll x, ll y, ll Mod = mod) {
	if (!fact_[0]) {
		fact_[0] = 1; comp_[0] = 1;
		for (int i = 1; i < fn_; i++) {
			fact_[i] = fact_[i - 1] * i % Mod;
			comp_[i] = mod_pow(fact_[i], Mod - 2, Mod);
		}
	}
	if (x < y) return 0;
	return fact_[x] * comp_[x - y] % Mod * comp_[y] % Mod;
}
//---------------------------------------------------
int x, y, z, n, m, s, t;
int a[400000];
//0~x-1 i番目の酸度を持つ人にのカツサンド
//x~x+y-1 i番目のカツを持つ任意の物品
//x+y~　i番目のカレーを持つ任意の物品
vector<int>e[400000];
signed main() {
	cin >> x >> y >> z >> n >> m >> s >> t;
	for (int i = 0; i < x + y + z; i++) {
		a[i] = inf;
	}
	priority_queue<H, vector<H>, greater<H>>p;
	for (int i = 0; i < n; i++) {
		int u, v;
		cin >> u >> v;
		u--; v--;
		e[u].push_back(v + x);
		e[v + x].push_back(u);
		if (i == s - 1) {
			a[u] = 1; a[v + x] = 1;
			p.push(H{ 1,u });
			p.push(H{ 1,v + x });
		}
	}
	int k, g;
	for (int i = 0; i < m; i++) {
		int u, v;
		cin >> u >> v;
		u--; v--;
		e[u + x].push_back(v + x + y);
		e[v + x + y].push_back(u + x);
		if (i == t - 1) {
			k = u + x; g = v + x + y;
		}
	}
	while (!p.empty()) {
		H t = p.top(); p.pop();
		if (t.fs != a[t.sc]) continue;
		for (auto g : e[t.sc]) {
			if (a[g] > a[t.sc] + 1) {
				a[g] = a[t.sc] + 1;
				p.push(H{ a[g],g });
			}
		}
	}
	if (a[k] == inf && a[g] == inf) {
		cout << -1 << endl;
	}
	else {
		cout << min(a[k], a[g]) << endl;
	}
}


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

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

	int w[N];
	int v[N];
	
	for(int i=0;i<N;i++){
		cin>>v[i]>>w[i];
	}
	
	int DP[N+1][W+1];
	for(int i=0;i<=W;i++){
		DP[0][i]=0;
	}
	for(int i=1;i<=N;i++){
		for(int j=0;j<=W;j++){
			if(j<w[i-1]){
				DP[i][j]=DP[i-1][j];
			}else{
				if(DP[i-1][j]>DP[i-1][j-w[i-1]]+v[i-1]){
					DP[i][j]=DP[i-1][j];
				}else{
						DP[i][j]=DP[i-1][j-w[i-1]]+v[i-1];
				}
			}
		}
	}
		cout<<DP[N][W]<<endl;


	return 0;
}

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

typedef long long ll;

int main()
{
    int n;
    cin>>n;
    int s[n];
    int sum =0;
    for(int i=0;i<n;i++)
    {
        cin>>s[i];
        sum += s[i];
    }
    sort( s,s+n);
    bool answered = false;
    if(sum%10!= 0 )
    {
        cout<<sum;
        answered = true;
    } else {
        for (int i = 0; i < n; i++) {
            if ( (sum - s[i]) % 10 != 0) {
                cout << sum - s[i];
                answered = true;
                break;
            }
        }
    }
    if( !answered )
        cout<<0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<double, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	long double a, b;
	cin >> a >> b;
	cout << ll(a * b) << endl;
	return 0;
}


Measured memory_bytes: 3740
#include <bits/stdc++.h>
using namespace std;
int main(){
      long long n,m,i,j,k,x=0,y=0,z,xx,yy;
      cin>>n>>m;
      z=m-x;
      vector<pair<long long,long long> >v;
      for(i=0;i<n;i++){
        cin>>xx>>yy;
        v.push_back({xx,yy});
      }
      sort(v.begin(),v.end());
    for(i=0;i<n;i++){
        if(x<m){
            if(z>=v[i].second){
                x=x+v[i].second;
                y=y+(v[i].second*v[i].first);
                z=m-x;
            }
            else{
                x=x+z;
                y=y+(z*v[i].first);
                z=m-x;
            }
        }
        //cout<<m-x<<endl;
    }
    cout<<y<<endl;
}


Measured memory_bytes: 2420
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Sort(a) sort(a.begin(), a.end())
#define Reve(a) reverse(a.begin(), a.end())
typedef long long ll;
const ll MOD = 1e9+7;

ll facctorialMethod(int k){
    ll sum = 1;
    for (ll i = 1; i <= k; ++i)
    {
        sum *= i;
        sum %= MOD;
    }
    return sum;
}

int main(){
  ll n, m, ans;
  cin >> n >> m;
  if(n==m) cout << facctorialMethod(n)*facctorialMethod(m)*2%MOD << endl;
  else if(n==m+1||m==n+1) cout << facctorialMethod(n)*facctorialMethod(m)%MOD << endl;
  else cout << 0 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define DEC(i, a, b) for (int i = (a); i > (b); --i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
typedef long long ll;
const int INF = (int)1e9;
const int MOD = (int)1e9 + 7;
const ll LINF = (int)1e18;
const double EPS = 1e-9;

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

  string S;
  cin >> S;
  if ( stoll(S.substr(5,2)) > 4 ) cout << "TBD" << endl;
  else cout << "Heisei" << endl;
  return 0;
}

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

using namespace std;

int main()
{
	int n,h,w;
	cin>>n>>h>>w;
	int cnt = 0;
	for(int i=0;i<n;i++){
		int a,b;
		cin>>a>>b;
		if(a>=h&&b>=w){
			cnt++;
		}
	}
	cout<<cnt;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 1003;
const int mod=1e9+7;
char g[N][N];
int dp[N][N];



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

    int h,w;cin>>h>>w;
    for(int i=1;i<=h;i++){
    	for(int j=1;j<=w;j++){
    		cin>>g[i][j];
    	}
    }
    memset(dp,0,sizeof(dp));
    dp[1][1]=1;
    for(int i=1;i<=h;i++){
    	for(int j=1;j<=w;j++){
    		if(i==1 && j==1){
    			continue;
    		}
    		if(g[i][j]=='#'){
    			dp[i][j]=0;
    		}
    		else
    		dp[i][j]=(dp[i-1][j]%mod+dp[i][j-1]%mod)%mod;
    	}
    }

    // for(int i=1;i<=h;i++){
    // 	for(int j=1;j<=w;j++){
    // 		cout<<dp[i][j]<<' ';
    // 	}
    // 	cout<<endl;
    // }

    cout<<dp[h][w];

	return 0;
}

Measured memory_bytes: 5120
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int N, A, B, C;
vector<int> vc;

int dfs(int l_a, int l_b, int l_c, int cnt_a, int cnt_b, int cnt_c, int depth)
{
  if (depth == N)
  {
    if (cnt_a == 0 || cnt_b == 0 || cnt_c == 0)
      return INT32_MAX;
    else
    {
      int res = abs(A - l_a) + abs(B - l_b) + abs(C - l_c);
      res += 10 * (cnt_a - 1);
      res += 10 * (cnt_b - 1);
      res += 10 * (cnt_c - 1);
      return res;
    }
  }
  int ans1 = dfs(l_a + vc[depth], l_b, l_c, cnt_a + 1, cnt_b, cnt_c, depth + 1);
  int ans2 = dfs(l_a, l_b + vc[depth], l_c, cnt_a, cnt_b + 1, cnt_c, depth + 1);
  int ans3 = dfs(l_a, l_b, l_c + vc[depth], cnt_a, cnt_b, cnt_c + 1, depth + 1);
  int ans4 = dfs(l_a, l_b, l_c, cnt_a, cnt_b, cnt_c, depth + 1);
  return min(min(ans1, ans2), min(ans3, ans4));
}

int main()
{
  cin >> N >> A >> B >> C;
  REP(i, N)
  {
    int l;
    cin >> l;
    vc.push_back(l);
  }
  cout << dfs(0, 0, 0, 0, 0, 0, 0) << endl;
  return 0;
}

Measured memory_bytes: 256
import sys

# 実行環境(0:vscode, 1:atcoder)
MODE = 1

# 入力の次元
DIMENSION = 0

# int型に変換
INT_TYPE = 1

if not (MODE):
    with open("input.txt", "r") as f:
        s = f.read()
else:
    s = sys.stdin.read()

if DIMENSION == 0:
    if INT_TYPE == 1:
        s = int(s)
elif DIMENSION == 1:
    if INT_TYPE == 0:
        s = s.split()
    elif INT_TYPE == 1:
        s = [int(x) for x in s.split()]
elif DIMENSION == 2:
    if INT_TYPE == 0:
        s = [x.split() for x in s.splitlines()]
    elif INT_TYPE == 1:
        s = [[int(y) for y in x.split()] for x in s.splitlines()]

if s == 1:
    print(0)
else:

    def factorization(n):
        arr = []
        temp = n
        for i in range(2, int(-(-n**0.5//1))+1):
            if temp % i == 0:
                cnt = 0
                while temp % i == 0:
                    cnt += 1
                    temp //= i
                arr.append([i, cnt])

        if temp != 1:
            arr.append([temp, 1])

        if arr == []:
            arr.append([n, 1])

        return arr

    F = factorization(s)

    cnt = 0
    for i in range(len(F)):
        num = 1
        while 1:
            F[i][1] -= num
            if F[i][1] < 0:
                break
            else:
                num += 1
                cnt += 1
    print(cnt)


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


int main(void)
{
	int hon, sen;
	cin >> hon >> sen;
	int test[100000];

	for (int i = 0; i < hon; i++) {
		cin >> test[i];
	}

	int ans=0, num=0;

	for (int i = 0; i < sen; i++) {

		for (int j = 0; j < hon; j++) {
			
			if (num < test[j]) {
				num = test[j];
			}

		}
		ans += num;
		for (int j = 0; j < hon; j++) {
			if (test[j] == num) {
				test[j] = 0;
				break;
			}
		}
		num = 0;
	}
	cout << ans << endl;
	
}


Measured memory_bytes: 256
import collections
H, W = map(int, input().split())
S = [input() for _ in range(H)]
def f():
    q = collections.deque()
    dist = [[float("inf")] * W for _ in range(H)]
    for i in range(H):
        for k in range(W):
            if S[i][k] == '#':
                q.append((i,k))
                dist[i][k] = 0
    dx = [(-1, 0), (1, 0), (0, -1), (0, 1)]
    while len(q) != 0:
        h, w = q.popleft()
        d = dist[h][w]
        for x, y in dx:
            h2 = h + y
            w2 = w + x
            if h2 >= 0 and h2 < H and w2 >= 0 and w2 < W:
                if dist[h2][w2] == float("inf"):
                    dist[h2][w2] = d+1
                    q.append((h2, w2))
    return dist
ans = 0
dist = f()
for i in range(H):
    for k in range(W):
        ans = max(ans,dist[i][k])
print(ans)

Measured memory_bytes: 120412
import java.util.*;
public class Main{
	public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a[] = new int[3];
        for(int i=0; i<3; i++){
            a[i] = sc.nextInt();
        }
        Arrays.sort(a);
        int k = sc.nextInt();
        for(int i =0; i<k; i++ ){
            a[2] *= 2; 
            Arrays.sort(a);
        }
        System.out.println(a[0]+a[1]+a[2]);
    }
}


Measured memory_bytes: 21844
#include<string>
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>
using ll = long long;
 
#define rep(i, n) for(ll i = 0; i < (int)(n); i++)
#define reps(i,x) for(ll i=1;i<=(int)(x);i++)
#define rrep(i,x) for(ll i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(ll i=(int)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define mp make_pair
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007 
using namespace std;
int x[50];
ll dp[51][51][2501];
int main() {
  int n, a;
  cin >> n >> a;
  reps(i,n)
    cin >> x[i];
  rep(i,n+1)
  dp[i][0][0] =1;
  reps(i,n)
     reps(j,n)
      rep(k,n*a+1){
        if(i > 0 && k < x[i]){
          dp[i][j][k] = dp[i-1][j][k];
	} else if(i > 0 && j > 0 && k >= x[i]){
          dp[i][j][k] = dp[i-1][j][k]+dp[i-1][j-1][k - x[i]];
        }else{
          dp[i][j][k] = 0;
        }
      }
  ll ans = 0;
  reps(j,n)
	if(dp[n][j][j*a]) ans+=dp[n][j][j*a];
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 50048
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String w = scanner.next();
        int n = 0;
        while(true) {
            String l = scanner.next();
            if (l.equals("END_OF_TEXT")) break;
            if (l.toLowerCase().equals(w)) n++;
        }
        System.out.println(n);

        scanner.close();
    }
}



Measured memory_bytes: 26296
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <set>
using namespace std;
bool calc(vector<vector<char> >, int y, int x);
int resultx;
int resulty;
set<string> passed;

int main() {
  while(true) {
    passed.clear();
  int width, height;
  cin >> width >> height;
  if(width == 0 && height == 0) break;
  vector<vector<char> > field(width, vector<char>(height));
  for(int w = 0; w < width; ++w) {
    for(int h = 0; h < height; ++h) {
      cin >> field[w][h];
    }
  }
  if(calc(field, 0, 0)) cout << resulty << " " << resultx << endl;
  }
  return 0;
}

bool calc(vector<vector<char> > field, int y, int x) {
  stringstream ss;
  ss << y << ',' << x;
  // cout << ss.str() << endl;
  if(passed.find(ss.str()) != passed.end()) {
    cout << "LOOP" << endl;
    return false;
  }
  passed.insert(ss.str());
  switch(field[x][y]) {
    case '>':
      return calc(field, y + 1, x);
      break;
    case '<':
      return calc(field, y - 1, x);
      break;
    case '^':
      return calc(field, y, x - 1);
      break;
    case 'v':
      return calc(field, y, x + 1);
      break;
    case '.':
      resultx = x;
      resulty = y;
      return true;
  }
}

Measured memory_bytes: 8164
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <set>
#include <map>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<str,str> p;

int main(){
  ll n;
  cin >> n;
  str s;
  cin >> s;
  map<p,ll> mp;
  str s_first = s.substr(0,n);
  str s_second = s.substr(n,n);
  reverse(s_second.begin(),s_second.end());
  REP(i,1<<n){
    str temp, temp2;
    REP(j,n){
      if(i>>j&1) temp += s_second[j];
      else temp2 += s_second[j];
    }
    mp[p(temp,temp2)]++;
  }
  ll ans = 0;
  REP(i,1<<n){
    str temp, temp2;
    REP(j,n){
      if(i>>j&1) temp += s_first[j];
      else temp2 += s_first[j];
    }
    ans += mp[p(temp,temp2)];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 91904
#include <iostream>
#include <vector>
using namespace std;
bool board[3][3];

int main() {
  vector<vector<int> > A(3);
  for(int i = 0; i < 3; i++) {
    A[i].resize(3);
    for(int j = 0; j < 3; j++) {
      cin >> A[i][j];
    }
  }
  int N; cin >> N;
  for(int i = 0; i < N; i++) {
    int b; cin >> b;
    for(int j = 0; j < 3; j++) {
      for(int k = 0; k < 3; k++) {
        if(A[j][k] == b) board[j][k] = true;
      }
    }
  }
  bool ok = false;
  for(int i = 0; i < 3; i++) {
    int cnt = 0;
    for(int j = 0; j < 3; j++) {
      if(board[i][j]) cnt++;
    }
    if(cnt == 3) ok = true;
  }

  for(int j = 0; j < 3; j++) {
    int cnt = 0;
    for(int i = 0; i < 3; i++) {
      if(board[i][j]) cnt++;
    }
    if(cnt == 3) ok = true;
  }
  if(board[0][0] && board[1][1] && board[2][2]) ok = true;
  if(board[2][0] && board[1][1] && board[0][2]) ok = true;
  if(ok) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


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

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ALL(a) begin(a), end(a)
#define SZ(a) ((int)(a).size())
#define rep(i, n) for (int i = 0; i < n; i++)

#ifdef __DEBUG
#define debug if (true)
#else
#define debug if (false)
#endif

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

template <typename T> struct vector2 : public vector<vector<T>> { vector2(int n, int m, const T& k = T()) : vector<vector<T>>(n, vector<T>(m, k)) {} };
template <typename T> struct vector3 : public vector<vector2<T>> { vector3(int n, int m, int k, const T &l = T()) : vector<vector2<T>>(n, vector2<T>(m, k, l)) {} };

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, k;
  cin >> n >> k;
  ll ans = 0;
  for (int b = k + 1; b <= n; b++) {
    ll mult = n / b;
    ans += mult * (b - k);
    ans += max(0LL, n - (mult * b + k) + 1);
    if (k == 0) {
      ans--;
    }
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ll TEN(int n) { return (n==0)?1:10*TEN(n-1); }
template<uint MD>
struct ModInt {
    uint v;
    ModInt() : v{0} {}
    ModInt(ll v) : v{normS(v%MD+MD)} {}
    static uint normS(const uint &x) {return (x<MD)?x:x-MD;};
    static ModInt make(const uint &x) {ModInt m; m.v = x; return m;}
    const ModInt operator+(const ModInt &r) const {return make(normS(v+r.v));}
    const ModInt operator-(const ModInt &r) const {return make(normS(v+normS(MD-r.v)));}
    const ModInt operator*(const ModInt &r) const {return make((ull)v*r.v%MD);}
    ModInt& operator+=(const ModInt &r) {return *this=*this+r;}
    ModInt& operator-=(const ModInt &r) {return *this=*this-r;}
    ModInt& operator*=(const ModInt &r) {return *this=*this*r;}
    static ModInt inv(const ModInt &x) {
        return pow(ModInt(x), MD-2);
    }
};
using Mint = ModInt<TEN(9)+7>;

/**
 * Fenwick Tree 
 *
 * 0-indexed
 */
template<class T>
struct Fenwick {
    int N;
    vector<T> seg;
    Fenwick(int N) : N(N) {
        seg.resize(N+1);
        fill_n(begin(seg), N+1, 0);
    }
    /// i番目の要素にxを追加する
    void add(int i, T x) {
        i++;
        while (i <= N) {
            seg[i] += x;
            i += i & -i;
        }
    }
    /// [0, i)のsum
    T sum(int i) {
        T s{0};
        while (i > 0) {
            s += seg[i];
            i -= i & -i;
        }
        return s;
    }
    /// [a, b)のsum
    T sum(int a, int b) {
        return sum(b) - sum(a);
    }
};

const int MN = 500500;
Mint fact[MN];

void first() {
    fact[0] = 1;
    for (int i = 1; i < MN; i++) {
        fact[i] = fact[i-1]*i;
    }
}

int main() {
    first();
    int n, m = 0;
    cin >> n;
    int a[n];
    Fenwick<int> unfw(n);
    for (int i = 0; i < n; i++) {
        unfw.add(i, 1);
    }
    for (int i = 0; i < n; i++) {
        cin >> a[i]; a[i]--;
        if (a[i] == -1) {
            m++;
        } else {
            unfw.add(a[i], -1);
        }
    }

    Mint ans = 0;
    int unfix = 0;
    Mint unfix_fix = 0;
    Fenwick<int> fw(n);
    for (int i = n-1; i >= 0; i--) {
        int d = a[i];
        Mint res = 0;
        if (d == -1) {
            res += unfix_fix * fact[m-1];
            if (unfix) {
                Mint mc2 = ull(m) * (m-1) / 2;
                res += Mint(unfix) * mc2 * fact[m-2];
            }
            unfix++;
        } else {
            int co = fw.sum(d);
            res += fact[m] * co;
            res += Mint(unfix) * unfw.sum(d) * fact[m-1];
            unfix_fix += unfw.sum(d, n);
            fw.add(d, 1);
        }
        ans += res * fact[n-1-i];
//        cout << res.v << " " << ans.v << endl;
    }
    ans += fact[m];
    cout << ans.v << endl;
    return 0;
}


Measured memory_bytes: 8064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
    
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new java.io.InputStreamReader(System.in));
        PrintWriter pw = new PrintWriter(System.out);
        StringTokenizer st = new StringTokenizer(br.readLine());

        int N = Integer.parseInt(st.nextToken());

        int counter = 0;
        boolean ansFlag = false;

        for(int i = 0; i < N; i++) {
            String[] input_array = br.readLine().split(" ");
            if(input_array[0].equals(input_array[1])) {
                counter += 1;
            } else {
                counter = 0;
            }

            if(counter == 3) {
                ansFlag = true;
            }
        }

        if(ansFlag){
            pw.println("Yes");
        } else {
            pw.println("No");
        }

        br.close();
        pw.close();
    }
}

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

int main() {
  int N,M;
  cin>>N>>M;
  vector<int> ans(N);
  for(int i=0;i<M;i++){
    int a,b;
    cin>>a>>b;
    ans.at(a-1)++;
    ans.at(b-1)++;
  }
  for(int i=0;i<N;i++){
    cout<<ans.at(i)<<endl;
  }
}

Measured memory_bytes: 256
//************************************JAI SAI RAM*************************************** 
// ED ROUND 85 DIV 2 PROBLEM D HARD TO THINK OF and hard TO IMPLEMENT .
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define endl "\n";
#define pair pair<ll,ll> 
ll MAX=LLONG_MAX;
ll MIN=LLONG_MIN;
ll P=1000000007;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll i,j,k,l,m,n,o,p,q,r,s,t,x,a[500],tt=0;
    string ss;
    cin>>ss;
    if
    (ss[0]=='7'||ss[1]=='7'||ss[2]=='7')
    cout<<"Yes\n";
    else 
    cout<<"No\n";
    return 0;
}  
    


Measured memory_bytes: 3652
#import pysnooper
#import os,re,sys,operator,math,heapq,string
#from collections import Counter,deque
#from operator import itemgetter
#from itertools import accumulate,combinations,groupby
from sys import stdin,setrecursionlimit
#from copy import deepcopy
setrecursionlimit(10**6)

a,b=map(int,stdin.readline().rstrip().split())
ans=10**10
tmpa,tmpb=a,b
for i in range(4):
    tmpa,tmpb=a,b
    cnt=0
    now=bin(i)[2:].zfill(2)
    #print(now)
    if now[0]=="1":
        tmpa=-a
        cnt+=1
    if now[1]=="1":
        tmpb=-b
        cnt+=1
    if tmpa<=tmpb:
        #print(tmpb-tmpa)
        ans=min(ans,cnt+tmpb-tmpa)
print(ans)

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

#define debug(s) cout << s << endl
#define debug1(s, t) cout << s << " " << t << endl
#define debug2(s, t, u) cout << s << " " << t << " " << u << endl
#define printvec(v)       \
    for (auto &&i : v)    \
        cout << i << " "; \
    cout << endl

using namespace std;
using i64 = long long;

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

    vector<int> lens;

    int len = 0;

    for (auto &&c : s)
    {
        if ((c == 'A') || (c == 'C') || (c == 'G') || (c == 'T'))
        {
            len++;
        }
        else
        {
            lens.push_back(len);
            len = 0;
        }
    }
    lens.push_back(len);

    int ans = 0;
    for (auto &&l : lens)
    {
        ans = max(ans, l);
    }

    cout << ans << endl;

    return 0;
}

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

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back

typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;

const int inf=1e+9;
const int mod=1e9+7;

int dp[100010];

int main(){
	dp[0]=0;

	for (int i = 1; i <= 100000; ++i){
		if(i<=5){
			dp[i]=i;
			continue;
		}
		dp[i]=inf;

		 int p=6;
		 while(p<=i){
		 	dp[i]=min(dp[i],dp[i-p]+1);
		 	p*=6;
		 }

		 p=9;
		 while(p<=i){
		 	dp[i]=min(dp[i],dp[i-p]+1);
		 	p*=9;
		 }
	}

	int n;
	cin>>n;
	cout<<dp[n]<<endl;

}


Measured memory_bytes: 640
//#include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <limits.h>
#include <string>
#include <deque>
#include <cmath>

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

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define mpa make_pair
#define all(a) (a).begin(), (a).end()

int sign(ll x) {
	return  int(x / abs(x));
}

int main() {
	ll t1, t2, a1, a2, b1, b2;
	cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2;
	ll a = a1 - b1, b = a2 - b2;
	if (a * t1 + b * t2 == 0) {
		cout << "infinity" << endl;
		return 0;
	}
	if (sign(t1*a)*sign(t1*a + t2 * b) > 0) {
		cout << 0 << endl;
	}
	else {
		ll ans = 0;
		if (abs(t1*a) % abs(t1*a + t2 * b)) {
			ans = 1;
		}
		ans += abs(t1*a) / abs(t1*a + t2 * b) * 2;
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#define N 10000
int isprime(int);
int main(){
  int a,b=0,i,n,w;
    scanf("%d",&w);
    for(i=0;i<w;i++){
        if(scanf("%d",&a)==EOF){
            break;
        }
        if(isprime(a)==1){
            b++;
        }
    }
    printf("%d\n",b);
}
int isprime(int x){
    int y;
    if(x==2){
        return 1;
    }
    if((x<2)||(x%2==0)){
        return 0;
    }
    y=3;
    while(y<=sqrt(x)){
        if(x%y==0){
            return 0;
        }
        y=y+2;
    }
    return 1;
}



Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=200010;
const ll mod=1e9+7;


int main(){
  string s;
  cin >> s;
  int sz=s.size();
  set<char> st;
  rep(i,sz){
    if(st.find(s[i])==st.end()){
      st.insert(s[i]);
    } else {
      cout << "no" << endl; return 0;
    }
  }

  cout << "yes" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
string n;
int len;
vector<int> dp[2];

int f(int x, int y){
    if(y <= -1) return x;
    if(dp[x][y] != -1) return dp[x][y];
    int d = n[y] - '0' + x;
    if(d == 10){
        return dp[x][y] = f(1, y-1);
    }
    int res = f(0, y-1) + d;
    int tmp = f(1, y-1) + 10 - d;
    if(tmp < res) res = tmp;
    return dp[x][y] = res;
}

int main(void){
    cin >> n;
    len = n.length();
    dp[0].assign(len, -1);
    dp[1].assign(len, -1);

    cout << f(0, len-1) << endl;
}


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

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

  long ans = 0, now = 0;
  vector<bool> used(M);
  vector<long> hist {-1};

  while (now < N) {
    if (used.at(X)) break;
    else now++;
    ans += X;
    used.at(X) = true;
    hist.push_back(X);
    X = X * X % M;
  }

  if (now == N) return cout << ans << "\n", 0;

  long x = -1;
  for (long i = 0; i < (long) hist.size(); i++) {
    if (hist.at(i) == X) x = i;
  }

  long rem = N - now;
  long len = now - x + 1;
  long sum = 0;
  for (long i = x; i <= now; i++) sum += hist.at(i);

  ans += rem / len * sum;
  rem %= len;

  for (long i = x; rem--; i++) ans += hist.at(i);
  cout << ans << "\n";
}

Measured memory_bytes: 3908