akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
    int n; cin>>n;
    map<int,int>mp;
    vector<string>gotiusa;
    rep(i,n){
        string hoge; cin>>hoge;
        if(!i){mp[stoi(hoge)]=1; gotiusa.push_back(hoge); continue;}
        string temp=gotiusa[gotiusa.size()-1];
        mp[stoi(hoge)]=1;
        mp[stoi(temp+hoge)]=1;
        if(i>=2)mp[stoi(gotiusa[gotiusa.size()-2]+temp+hoge)]=1;
        if(i>=3)mp[stoi(gotiusa[gotiusa.size()-3]+gotiusa[gotiusa.size()-2]+temp+hoge)]=1;
        //mp[stoi(hoge+temp)]=1;
        //if(stoi(hoge+temp)==86||stoi(temp+hoge)==86)
        gotiusa.push_back(hoge);
        
    }
    rep(i,1000000)
    if(mp[i])continue;
    else {cout<<i<<endl; return 0;}
}

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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;
template<class T,class U> using umap = unordered_map<T,U>;
template<class T> using uset = unordered_set<T>;

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

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

template<class T, size_t N, class U>
void Fill(T (&a)[N], const U&v){
    fill((U*)a,(U*)(a+N),v);
}

template<class T>
istream& operator >> (istream&is, vector<T>&v){
  for(auto&e:v)is >> e;
  return is;
}

int main(){
  ll h,w; cin >> h >> w;
  if(h == 1 || w == 1) cout << 1 << endl;
  else cout << (h*w+1)/2 << endl;
  return 0;
}


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

int main(){
 long long n,sum=0,t,max,min;
    scanf("%lld",&t);
    for(int i=1; i<=t; i++)
    {
        scanf("%lld ",&n);
        if(i==1)
            max=min=n;
        if(max<n)
            max=n;
        else if(min>n)
            min=n;
        sum=sum+n;
    }
    printf("%d %d %lld\n",min,max,sum);
}



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

long long int h, w;
long long int ans=100000000000000;

int main() {
	cin >> h >> w;

	if (h%3==0 || w%3==0) ans = 0;

	for (int i = 1; i < w; ++i) ans = min(ans, max({abs(h*i - (w-i)*(h/2)), abs(h*i - (w-i)*(h/2+h%2)), h%2 ? w-i : 0}));
	for (int i = 1; i < h; ++i) ans = min(ans, max({abs(w*i - (h-i)*(w/2)), abs(w*i - (h-i)*(w/2+w%2)), w%2 ? h-i : 0}));

	cout << min({ans, h, w}) << endl;
}

Measured memory_bytes: 256
MOD = 10**9+7
n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort(reverse=True)
def inv_mod(a, p=MOD):
    def inv_mod_sub(a, p):
        if a == 1:
            return 1, 0
        else:
            d, r = p//a, p%a
            x, y = inv_mod_sub(r, a)
            return y-d*x, x
    if p < 0: p = -p
    a %= p
    return inv_mod_sub(a,p)[0] % p

def comb_mod(n, k):
    if k < 0 or k > n:
        return 0
    else:
        return f_mod[n]*f_mod_inverse[k]*f_mod_inverse[n-k] % MOD
f_mod=[1]*(n+1)
f_mod_inverse=[1]*(n+1)
for i in range(1,n+1):
  f_mod[i]=f_mod[i-1]*i%MOD
  f_mod_inverse[i]=f_mod_inverse[i-1]*inv_mod(i)%MOD
Ms=0;ms=0
for i in range(n-k+1):
  Ms+=comb_mod(n-i-1,k-1)*a[i]
  ms+=comb_mod(n-i-1,k-1)*a[n-i-1]
  Ms%=MOD;ms%=MOD
print((Ms-ms)%MOD)

Measured memory_bytes: 90408
'use strict';
function main(input) {
  const args = input.split('\n'),
        N = parseInt(args[0]),
        D = args[1].split(' ');
  let DSorted = D.sort((a,b) => parseInt(a) - parseInt(b));
  let ans = parseInt(DSorted[N/2]) - parseInt(DSorted[N/2-1]);
  console.log(ans);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

int main(){
  int N;
  cin >>N;
  rep(i,10){
    rep(j,10){
      if(i*j==N) {cout<<"Yes"<<endl;
      return 0;}
    }
  }
  cout<<"No"<<endl;
return 0;
}



Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define uniq(v) v.erase(unique(v.begin(),v.end()),v.end())
#define lb(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define ub(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
const ll mod=1000000007;
//const ll mod=998244353;
const ld pi=acos(-1.0);
const ll INF = 1LL<<61;
template<class T>bool chmax(T &a, const T &b) { 
  if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) {
  if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる



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

  int d;
  cin>>d;

  vector<ll> p(26);
  rep(i,26) {
    cin>>p[i];
  }


  vector<vector<ll>> q(d,vector<ll>(26));
  rep(i,d) {
    rep(j,26) {
      cin>>q[i][j];
    }
  }

  ll pre=0;
  vector<int> r(26,0);
  rep(i,d-5){
    ll ans=-INF;
    ll memo;
    rep(j,26){
      ll sum=pre;
      auto last=r;
      sum+=q[i][j];
      last[j]=i+1;
      rep(k,26){
        sum-=pow(p[k],1.1)*(i+1-last[k]);
      }
      if(sum>ans) {
        memo=j;
        chmax(ans,sum);
      }
    }
    cout << memo+1 << endl;
    pre=ans;
    r[memo]=i+1;
  }

  ll answer=-INF;
  ll A,B,C,D,E;
  vector<int> zen(5);
  rep(i,26){
    rep(j,26){
      rep(k,26){
        rep(l,26){
          rep(m,26){
            zen[0]=i;
            zen[1]=j;
            zen[2]=k;
            zen[3]=l;
            zen[4]=m;

            ll sum=0;
            auto last=r;
            rep(n,5){
              sum+=q[d-5+n][zen[n]];
              last[zen[n]]=d-5+n+1;
              rep(o,26){
                sum-=p[o]*(d-5+n+1-last[o]);
              }
            }

            if(sum>answer) {
              A=zen[0];
              B=zen[1];
              C=zen[2];
              D=zen[3];
              E=zen[4];
            }
            chmax(answer,sum);

          }
        }
      }
    }
  }

  cout << A+1 << endl;
  cout << B+1 << endl;
  cout << C+1 << endl;
  cout << D+1 << endl;
  cout << E+1 << endl;
  
}

Measured memory_bytes: 4168
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<bitset>
#include<math.h>
using namespace std;

template <typename T>
inline string to_bin_str(T n) {
    string str;
    while (n > 0) {
        str.push_back('0' + (n & 1));
        n >>= 1;
    }
    reverse(str.begin(), str.end());
    return str;
}

int main(){
 
  long long H;
  cin>>H;
  
  string bin = to_bin_str(H);
  for(int i=0;i<bin.length();i++){
    if(bin[i]=='0'){
      bin[i]='1';
    }
  }
  
  long long ans = stol(bin,0,2);
  
  cout<< ans <<endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
const ll INF=99999999999999999;
ll a,b,c,d,e,f,g,ans=0;
int main(){
    ll N,M;
    vector<pair<ll,ll>> A;
    cin>>N>>M;
    rep(i,N){
        cin>>a>>b;
        A.emplace_back(a,b);
    }

    sort(A.begin(),A.end());

    rep(i,N){
        if(M-A[i].second<0){
            ans+=M*A[i].first;
            break;
        }
        else{
            ans+=A[i].second*A[i].first;
            M-=A[i].second;
        }
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 2420
// https://atcoder.jp/contests/abc093/tasks/abc093_a
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;
using ll = long long;
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    bool flag = true;
    REP(i, 3) {
        if (find(ALL(s), 'a' + i) == s.end()) {
            flag = false;
            break;
        }
    }
    if (flag)
        cout << "Yes\n";
    else
        cout << "No\n";

    return 0;
}

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

int main(){
    int N,amari;
    scanf("%d",&N);
    amari = N%10;
    if(amari==2||amari==4||amari==5||amari==7||amari==9){
        printf("hon\n");
    }else if(amari==3){
        printf("bon\n");
    }else{
        printf("pon\n");
    }
    return 0;
}

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

#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)

typedef pair<int, int> pint;

#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front

#define MOD (1000 * 1000 * 1000 + 7)

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

    vector<int> P(N, 0);
    REP(i, N) {
        cin >> P[i];
    }

    vector<int> Q(N, 0);
    REP(i, N) {
        Q[P[i]-1] = i;
    }

    int ans = 1;
    int cnt = 1;
    REPS(i, N-1) {
        if (Q[i-1] < Q[i]) {
            cnt++;
        } else {
            ans = max(ans, cnt);
            cnt = 1;
        }
    }
    ans = max(ans, cnt);

    cout << N - ans << endl;

    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define DEBUG(x) cout << #x << " is " << (x) << endl;
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

int main() {
	int n;
	cin >> n;
	int a[n];
	for(int i = 0;i < n;i++)cin>>a[i];
	for(int i = 0;i < n;i++){
		if(a[i]%2 == 1 || ((a[i]%2 == 0) && ((a[i]%3 == 0)|| (a[i]%5 == 0)))){
			
		}else{
			cout<<"DENIED"<<endl;
			return 0;
		}
	}
	cout<<"APPROVED"<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define maxn 200005
using namespace std;
struct bag{
    int x,y;
}p[maxn];
bool operator < (bag a,bag b){
    if(a.x==b.x)return a.y<b.y;
    return a.x<b.x;
}
int n,Rmax,Rmin,Bmax,Bmin;
int main(){
    long long ans=1e18;
    scanf("%d",&n);
    if(n==1){
      cout<<0<<endl;
      return 0;
    }
    for(int i=0;i<n;i++){
        scanf("%d%d",&p[i].x,&p[i].y);
        if(p[i].x>p[i].y){
            int k=p[i].x;
            p[i].x=p[i].y;
            p[i].y=k;
        }
    }
    sort(p,p+n);
    int Max=p[0].y,Min=p[0].x,_max=0,_min=0;
    for(int i=1;i<n;i++){
        if(p[i].x<=Min&&p[i].y>=Max){
            Min=p[i].x;Max=p[i].y;
            _max=i;_min=i;
        }
        else if(p[i].x<Min){
            Min=p[i].x;
            _min=i;
        }else if(p[i].y>Max){
            Max=p[i].y;
            _max=i;
        }
    }
    Rmax=Max;Bmin=Min;
    Rmin=p[_min].y;Bmax=p[_max].x;
    for(int i=0;i<n;i++){
        Rmin=min(Rmin,p[i].y);
        Bmax=max(Bmax,p[i].x);
    }
    ans=(long long)(Rmax-Rmin)*(Bmax-Bmin);
    if(_max!=_min){
        Bmax=Max;Bmin=Min;
        Rmax=max(p[n-1].x,p[0].y);
        int premin=p[0].y;
        Rmin=min(p[0].y,p[1].x);
        long long ans0=Rmax-Rmin;
        for(int i=1;i<n-1;i++){
            Rmax=max(p[i].y,Rmax);
            Rmin=min(min(premin,p[i].y),p[i+1].x);
            premin=min(premin,p[i].y);
            if(Rmax-Rmin<ans0)ans0=Rmax-Rmin;
        }
        ans0*=Bmax-Bmin;
        ans=min(ans,ans0);
    }
    cout<<ans<<endl;
    return 0;
}

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

#define mp make_pair
#define eb emplace_back
#define ff first
#define ss second

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#ifdef ONPC
mt19937 rnd(228);
#else
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#endif


const int MAXN = 100;
//#define int long long
const int INF = 1e9;

struct ed {
  int a, b, c;
  ed() {}
  ed(int aa, int bb, int cc){
    a = aa;
    b = bb;
    c = cc;
  }

  int get(int u){
    if (u == a) return b;
    return b;
  }
};

int n, m;
vector<int> g[MAXN];
int d[MAXN][MAXN];
vector<ed> e;

void read(){
  cin >> n >> m;
  int a, b, c;
  memset(d, 0x3f, sizeof d);
  for (int i = 0; i < n; i++) d[i][i] = 0;
  for (int i = 0; i < m; i++){
    cin >> a >> b >> c;
    a--, b--;
    g[a].eb(i);
    g[b].eb(i);
    e.eb(a, b, c);
    d[a][b] = c;
    d[b][a] = c;
  }
}

void floyd(){
  for (int k = 0; k < n; k++){
    for (int i = 0; i < n; i++){
      for (int j = 0; j < n; j++){
        d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
      }
    }
  }
}

void solve(){
  read();

  floyd();

  int ans = 0;
  for (auto ei: e){
    int f = 1;
    for (int i = 0; i < n; i++){
      for (int j = 0; j < n; j++){
        if (i == j) continue;

        //cerr << d[i][j] << ' ' << i << ' ' << j << ' ' << d[i][ei.a] + ei.c + d[ei.b][j] << '\n';
        if (d[i][ei.a] + ei.c + d[ei.b][j] <= d[i][j]) f = 0;
      }
    }
    ans += f;
  }

  cout << ans << '\n';
}

signed main()
{
    #ifdef FILEIO
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(0);
    cin.tie(0);

    solve();

    return 0;
}


Measured memory_bytes: 3684
import sys

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))

N = ini()
d = []
for i in range(N):
    s, p = ins().split()
    p = int(p)
    d.append((s, -p, i + 1))
d.sort()


def solve():
    for _, _, i in d:
        print(i)


solve()


Measured memory_bytes: 9220
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <time.h>
#include <stdarg.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <functional>
#include <map>

#define ll long long

using namespace std;

ll mod = 1e9 + 7;

ll
get(ll from, ll index, ll color, vector<vector<ll>> & link, vector<vector<ll>> & values) {
  if (values[index][color] == -1) {
    ll v = 1;
    for (auto p : link[index]) {
      if (p == from) continue;
      if (color == 1) 
        v *= get(index, p, 0, link, values);
      else 
        v *= (get(index, p, 0, link, values) + get(index, p, 1, link, values));
      v %= mod;
    }
    //cout<<index<<","<<color<<":"<<v<<endl;
    values[index][color] = v;
  }

  return values[index][color];
}

void
solve() {
  ll n;
  cin>>n;

  vector<vector<ll>> link(n+1, vector<ll>()), values(n+1, vector<ll>(2, -1));
  ll x, y;
  for (ll i=0; i<n-1; i++) {
    cin>>x>>y;
    link[x].push_back(y);
    link[y].push_back(x);
  }

  ll ans = (get(-1, 1, 0, link, values) + get(-1, 1, 1, link, values)) % mod;
  cout<<ans<<endl;
}

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

  ll t = 1;
  //cin>>t;

  while (t > 0) {
    t--;
    solve();
  }

  return 0;
}



Measured memory_bytes: 23756
#include<bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n ; i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;

int main(void){
    int N; cin >> N;
    int res = 0;
    REP(i, N){
        int tmp; cin >> tmp;
        res += tmp - 1;
    }
    cout << res << endl;
}

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

int Count(std::string& s, std::string from){
    int pos = s.find(from);
    int length = from.length();

    if(pos == std::string::npos || from.empty()){
        return 0;
    }

    s.replace(pos, length, "abc");
    return 1;
}

int main(){
    std::string S;
    int N, ans = 0;
    std::cin >> N >> S;

    std::string findword = {"ABC"};
    std::string::size_type pos = S.find(findword);

    while(pos != std::string::npos){
        ans += Count(S, findword);
        pos = S.find(findword, findword.length() + pos);
    }

    std::cout << ans << std::endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define dbug(x) cout<<#x<<"="<<x<<endl
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while ('0'>ch||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do {(t*=10)+=ch-'0';ch=getchar();} while ('0'<=ch&&ch<='9'); t*=f;
}
typedef long long ll;
const int maxn=(1e5)+10;
int n,d[maxn],A[maxn],B[maxn],C[maxn],D[maxn];
struct node { int x,y; } e[maxn]; ll ans,tmp;
bool cmp(node a,node b) { return a.x>b.x; }
int tr[maxn];
void add(int x) {
	for (;x<=n;x+=x&(-x)) tr[x]++;
}
int query(int x) {
	int res=0;
	for (;x;x-=x&(-x)) res+=tr[x];
	return res;
}
int main() {
	//freopen("1.txt","r",stdin);
	read(n);
	for (int i=1;i<=n;i++) read(d[i]);
	int x,y,l,r,mid,res;
	for (int i=1;i<=n;i++) e[i]=(node){d[i],i};
	sort(e+1,e+n+1,cmp);
	for (int i=1;i<=n;i++) {
		x=e[i].y;
		l=1,r=x-1; res=0;
		while (l<=r) {
			mid=(l+r)/2;
			if (query(x)-query(mid-1)) res=mid,l=mid+1;
			else r=mid-1;
		}
		B[x]=res;
		l=1,r=res-1; res=0;
		while (l<=r) {
			mid=(l+r)/2;
			if (query(B[x]-1)-query(mid-1)) res=mid,l=mid+1;
			else r=mid-1;
		}
		A[x]=res; add(x);
	}
	memset(tr,0,sizeof(tr));
	for (int i=1;i<=n;i++) {
		x=e[i].y;
		l=x+1,r=n; res=n+1;
		while (l<=r) {
			mid=(l+r)/2;
			if (query(mid)-query(x)) res=mid,r=mid-1;
			else l=mid+1;
		}
		C[x]=res;
		l=res+1,r=n; res=n+1;
		while (l<=r) {
			mid=(l+r)/2;
			if (query(mid)-query(C[x])) res=mid,r=mid-1;
			else l=mid+1;
		}
		D[x]=res; add(x);
	}
	/*for (int i=1;i<=n;i++)
	for (int j=i+1;j<=n;j++) {
		tot=0;
		for (int k=i;k<=j;k++) v[++tot]=d[k];
		sort(v+1,v+tot+1);
		to[v[tot-1]]++;
	}
	for (int i=1;i<=n;i++) printf("%d ",to[i]); printf("\n");
	int cnt=0;
	for (int i=1;i<=n;i++)
		printf("%d %d %d %d\n",A[i],B[i],C[i],D[i]);*/
	for (int i=1;i<=n;i++) {
		tmp=(ll)(B[i]-A[i])*(C[i]-i);
		tmp+=(ll)(i-B[i])*(D[i]-C[i]);
		//printf("%d %lld\n",d[i],tmp);
		//cnt+=tmp;
		ans+=tmp*d[i];
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define all(X) X.begin(), X.end()
//for(int i = 0; i < n; i++)
using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    map< pair<int, int> , int> m;
    long long n, d; cin >> n >> d;
    int cnt = 0;
    for(int i = 0;i < n ; i++)
    {
        long long  x, y; cin >> x >> y;
        if((x*x + y*y) <= d*d )
            cnt++;
    }
    cout << cnt;

}


Measured memory_bytes: 3568
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
#define REP(i, b, e) for ( int i = b; i < (int)e; i++ )
#define rep(i, n) REP(i, 0, n)
static const int INFTY = (1<<30);
static const int NMAX = 150;
static const int MMAX = 80;
class Node{
public:
  int p, s, M[MMAX];
  Node(){}
  Node(int p, int s):p(p), s(s){
    rep(i, MMAX) M[i] = INFTY;
  }
};

int n, m;
vector<Node> P[NMAX];

int compute(){
  rep(j, P[0].size()) P[0][j].M[0] = 0;
  if ( n >= 2 ){
    rep(j, P[1].size()) P[1][j].M[1] = 0;
  }

  rep(i, n-1){
    rep(j, P[i].size()){
      Node src = P[i][j];
      rep(k, P[i+1].size()){
	Node tar = P[i+1][k];
	int cost = (src.s + tar.s)*(max(src.p, tar.p) - min(src.p, tar.p));
	rep(l, m+1){
	    P[i+1][k].M[l] = min(P[i+1][k].M[l], P[i][j].M[l] + cost);
	}
      }
      if (i == n-1) continue;
      rep(k, P[i+2].size()){
	Node tar = P[i+2][k];
	int cost = (src.s + tar.s)*(max(src.p, tar.p) - min(src.p, tar.p));
	rep(l, m){
	    P[i+2][k].M[l+1] = min(P[i+2][k].M[l+1], P[i][j].M[l] + cost);
	}
      }
    }
  }
  int minv = INFTY;
  rep(j, P[n-1].size()){
    rep(l, m+1) minv = min(minv, P[n-1][j].M[l]);
  }
  if ( n > 1 ){
    rep(j, P[n-2].size()){
      rep(l, m) minv = min(minv, P[n-2][j].M[l]);
    }
  }
  return minv;
}

main(){
  int k, p, s;
  while(1){
    cin >> n >> m;
    if ( n == 0 && m == 0 ) break;
    rep(i, n) P[i].clear();
    rep(i, n){
      cin >> k;
      rep(j, k){
	cin >> p >> s;
	P[i].push_back(Node(p, s));
      }
    }
    cout << compute() << endl;
  }
}

Measured memory_bytes: 1712
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    A,B,C,D=map(int,input().split())
    a,b=0,0
    for i in range(A,B):
        a|=1<<i
    for i in range(C,D):
        b|=1<<i
    print(bin(a&b).count('1'))

if __name__ == '__main__':
    main()


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

#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define ACC(c) (accumulate(ALL(c), 0LL))
#define ENDL "\n"
#define PRINT(x) cout << (x) << ENDL

using namespace std;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;

inline int in(int& a) {return scanf("%d", &a);}
inline void out(int n) {printf("%d\n", n);}
auto pint_compare = [](pint x, pint y) -> bool{return (x.first < y.first);};


signed main(){
    int L, R;
    const int MOD = 2019;
    cin >> L >> R;
    if(R - L >= MOD - 1){
        PRINT("0");
        return 0;
    }
    int ans = MOD;
    FOR(i, L, R){
        FOR(j, i + 1, R + 1){
            ans = min(ans, ((i % MOD) * (j % MOD)) % MOD);
        }
    }
    PRINT(ans);
    return 0;
}

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

#define ll long long
#define vi vector<int>
#define vc vector<char>
#define vt vector<string>
#define si set<int>
#define sc set<char>
#define st set<string>
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back;

using namespace std;
int main()
{
    int n;
    cin>>n;
    vi v(n);
    for(int i=1;i<=n;i++)
        cin>>v[i];
    for(int i=1;i<n;i++)
    {
        if(v[i]<=v[i+1])continue;
        else v[i+1]++;
    }
    bool check=true;
    for(int i=1;i<n;i++)
        {
            if(v[i]>v[i+1])
            {
                check=false;
                break;
            }
        }
        if(check)cout<<"Yes";else cout<<"No";
    return 0;
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int n = sc.nextInt();
		int a = (int) (Math.pow(10, 9) + 7);
		long ans = 1;
		for (int i = 1; i <= n; i++) {
			ans = (ans * i) % a;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 21716
/*
今天大吉，
天使保佑：

      ******
        __
      /`__`\
  .=.| ('') |.=.
 /.-.\ _)(_ /.-.\
|:    / ~~ \    :|
\ :  | (__) |  : /
 | :  \_/\_/  : |
 |:  /|    |\  :|
 \_/` |    | `\_/
      |    |
      |    |
      |~~~~|
      '----'
	|GoodLuck|
*/
#include<bits/stdc++.h>
using namespace std;
int cmp(int a,int b)
{
	return a>b;
}
int main()
{
	int n;
	cin>>n;
	int a[n+1];
	for(int i=0+1;i<=n;i++) cin>>a[i];
	sort(a+1,a+n+1,cmp); 
	int min1=0,min2=2147283647;
	for(int i=2;i<=n;i++)
	{
		if(fabs((a[1]*1.0/2)-a[i])<min2)
		{
			min1=i;
			min2=fabs((a[1]*1.0/2)-a[i]);
		}
	}
	cout<<a[1]<<' '<<a[min1]<<"\n";
	return 0;
}

Measured memory_bytes: 640
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力(スペース改行関係なし)
		int x = sc.nextInt();

		if(x >=1800){
			// 出力
			System.out.println(1);
		}else if(x >=1600){
			System.out.println(2);
        }else if(x >=1400){
          System.out.println(3);
        }else if(x >=1200){
          System.out.println(4);
        }else if(x >=1000){
          System.out.println(5);
        }else if(x >=800){
          System.out.println(6);
        }else if(x >=600){
          System.out.println(7);
        }else if(x >=400){
          System.out.println(8);
		}else{
			System.out.println("");
		}
		
	}
}

Measured memory_bytes: 35616
def main():
    n = int(input())
    lst = [[0, 0, 0]]
    for _ in range(n):
        lst.append(list(map(int, input().split())))

    flag = True
    for i in range(n):
        left_time = lst[i + 1][0] - lst[i][0]
        distance = abs(lst[i + 1][1] - lst[i][1]) + abs(lst[i + 1][2] - lst[i][2])

        if left_time < distance:
            flag = False
            break
        else:
            if left_time % 2 == 0:
                if distance % 2 == 0:
                    continue
                else:
                    flag = False
                    break
            else:
                if distance % 2 == 1:
                    continue
                else:
                    flag = False
                    break

    if flag:
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()

Measured memory_bytes: 27232
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

# 桁DP, Lを超えないものと保留のもの
MOD = 10 ** 9 + 7
L = sr()
dp_dec = 1 # decide
dp_res = 2 # reserve
length = len(L)
for i in range(1, length):
    x, y = dp_dec, dp_res
    if L[i] == '1':
        dp_dec = x * 3 + y
        dp_res = y * 2
    else:
        dp_dec = x * 3
        dp_res = y
    dp_dec %= MOD
    dp_res %= MOD

answer = dp_dec + dp_res
print(answer % MOD)


Measured memory_bytes: 39664
// Template from https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

// input macro for competive-programming from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };

    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, bytes) => {
        read_value!($iter, String).into_bytes()
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    use std::io::Read;
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();

    println!("{}", solve(&s));
}

macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
r#"At Be Co"# => r#"ABC"#,
}

fn solve(src: &str) -> String {
    input! {
        source = src,
        a: chars,
        b: chars,
        c: chars,
    }

    let mut ans = a[0].to_string();
    ans.push_str(&b[0].to_string());
    ans.push_str(&c[0].to_string());

    ans.to_string()
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
void solve()
{
    int a, b, m;
    cin >> a >> b >> m;
    int A[a], B[b];
    int ma = INT_MAX;
    int mb = INT_MAX;
    for (int i = 0; i < a; i++)
    {
        cin >> A[i];
        ma = min(ma, A[i]);
    }

    for (int i = 0; i < b; i++)
    {
        cin >> B[i];
        mb = min(mb, B[i]);
    }

    int x, y, c;
    long mn = LONG_MAX;
    for (int i = 0; i < m; i++)
    {
        cin >> x >> y >> c;
        long res = A[x - 1] + B[y - 1] - c;
        mn = min({mn, res, (long)(mb + ma)});
    }
    cout << mn;
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    solve();
    return 0;
}


Measured memory_bytes: 1024
#include "bits/stdc++.h"
#define rep(i, n) for (int (i) = 0; (i) < (n); (i)++)

using namespace std;
int main() {
	long long N;
	cin >> N;
	long long ans = 0;
	rep(i, N) {
		long long num = i + 1;
		if (num % 3 != 0 && num % 5 != 0) ans += num;
	}
	cout << ans << endl;
 }

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

int digitsum(int N){
  int ds=0;
  while(N>0){
    ds+=N%10;
    N/=10;
  }
  return ds;
}

int main() {
  int N;
  cin >>N;
  vector<int> V(N);
  vector<int> C(N);
  int ans=0;
  for(int i=0;i<N;i++){
    cin >>V.at(i);    
  }
  for(int i=0;i<N;i++){
    cin >>C.at(i);
  }

  for(int i=0;i<N;i++){
    if(V.at(i)>C.at(i)){
      ans+=V.at(i)-C.at(i);
    }
  }
  cout <<ans<<endl;
}


Measured memory_bytes: 256
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <queue>
#include <iostream>
#include <cmath>

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
typedef long long ll;
using namespace std;


void solve(long long N, std::vector<long long> P, std::vector<long long> Q){
    // 辞書順に数列を並べ替え
    vector<int> a(N);
    REP(i, N) a[i] = i+1;
    // next_permulationは辞書順に自動的に並べてくれる

    int res_p = 0;
    int res_q = 0;
    int idx = 0;
    do{
        // Pについてはんていする
        bool flag_p = true;
        REP(i, N) {
            if(a[i] != P[i]) {
                flag_p = false;
                break;
            }
        }
        bool flag_q = true;
         REP(i, N) {
            if(a[i] != Q[i]) {
                flag_q = false;
                break;
            }
        }       
        if(flag_p) res_p = idx;
        if(flag_q) res_q = idx;
        idx++;
    }while(next_permutation(a.begin(), a.end()));

    cout << abs(res_p - res_q) << endl;
}

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


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

int main(){
	int n,k;
	cin >> n >> k;
	if(n%k == 0) cout << 0 << endl;
	else cout << 1 << endl;
	return 0;
}

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

struct P{
    int num;
    int point;
    int rank;
    static bool more (const P& left,const P& right){
        return left.point > right.point;
    }
};

int main(){
    int n,cnt=0;
    vector <P> data;
    P tmp;
    while(1){
        scanf("%d,%d",&tmp.num,&tmp.point);
        if(tmp.num == 0 && tmp.point == 0) break;
        data.push_back(tmp);
        cnt++;
    }
    sort(data.begin(),data.end(),P::more);
    for(int i=0,rank=1;i<cnt;i++){
        if(i == 0) data[i].rank = rank;
        else if(data[i].point == data[i-1].point) data[i].rank = rank;
        else if(data[i].point < data[i-1].point){
            rank++;
            data[i].rank= rank;
        }
    }
    
    while(scanf("%d",&n) != EOF){
        for(int i=0;i<cnt;i++){
            if(data[i].num == n){
                cout << data[i].rank << endl;
                break;
            }
        }
    }
}

Measured memory_bytes: 1228
// Hail god Yato
 
#include <bits/stdc++.h> 
using namespace std;
 
#define add(x) accumulate(x)
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end() 
#define rep(i, a, b) for (int i=a; i<(b); i++)
#define hs ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
const ll mod = 1000000007;
const ll INF = 1e18;
const ll MAX = 100001;
//
//
                void solve(){
                        ll n;
                        string s,t;
                        cin>>n>>s>>t;
                        rep(i,0,n)
                                cout<<s[i]<<t[i];
                }
                int main(){ 
                        hs;
                        ll t;
                        t=1;
                        // cin>>t;
                        for (int i=1; i<=t; i++){
                                //printf("Case #%d: ", i);
                                solve();
                         }
        return 0; 
}         
 

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

using namespace std;

typedef pair<int, int> ii;
typedef long long ll;
const int oo = 1e9 + 7;

const int N = 1e3 + 5;
const int ver[] = { -1, +1, 0, 0 };
const int hor[] = { 0, 0, -1, +1 };
const char* mv = "LRDU";
int n;
ll cx[N], cy[N];

ll dist(ll x1, ll y1, ll x2, ll y2) {
  return abs(x2 - x1) + abs(y2 - y1);
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  int p = -1;
  for (int i = 1; i <= n; ++i) {
    cin >> cx[i] >> cy[i];
    int tmp = (cx[i] + cy[i]) % 2;
    if (tmp < 0) tmp += 2;
    if (p == -1) p = tmp;
    else {
      if (p != tmp) {
        cout << -1;
        return 0;
      }
    }
  }
  vector<ll> f;
  for (int i = 33; i >= 0; --i)
    f.push_back(1LL << i);
  if (!p)
    f.push_back(1LL);
  cout << int(f.size()) << '\n';
  for (ll v : f)
    cout << v << ' ';
  cout << '\n';
  for (int i = 1; i <= n; ++i) {
    ll x = 0, y = 0;
    for (ll e : f) {
      int w = 0;
      for (int k = 0; k < 4; ++k)
        if (dist(cx[i], cy[i], x + e * ver[w], y + e * hor[w]) > dist(cx[i], cy[i], x + e * ver[k], y + e * hor[k]))
          w = k;
      cout << mv[w];
      x += e * ver[w];
      y += e * hor[w];
    }
    cout << '\n';
    cerr << "DEBUG: " << x << ", " << y << '\n';
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
int32_t main(){
    string str1,str2;
    cin>>str1>>str2;
    int count=0;
    for(int i=0;i<str1.length();i++){
        if(str1[i]!=str2[i])count++;
    }
    cout<<count<<endl;
}

Measured memory_bytes: 3828
/**
 *    author:  yoseph
 *    created: 02.08.2020 20:16:03      
**/
#include <bits/stdc++.h>
using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int x;
	cin >> x;
	if (x >= 30)
		cout << "Yes\n";
	else
		cout << "No\n";
	return 0;
}


Measured memory_bytes: 3604
#include <cstdio>
int main()
{
	long long n, min, max;
	scanf("%lld %lld %lld", &n, &min, &max);
	if ((min > max) || (n == 1 && min != max))
	{
		printf("0\n");
		return 0;
	}
	else if (n == 1)
	{
		printf("1\n");
		return 0;
	}
	long long high = min + max * (n - 1);
	long long low = max + min * (n - 1); 
	printf("%lld\n", high - low + 1);
	return 0; 
}

Measured memory_bytes: 128
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <string>
#include <utility>
#include <vector>
#define REP(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;
const ll MOD = 1000000007;
using namespace std;

int main(){
    int n, ans=0; cin >> n;
    REP(i, n){
        int a; cin >> a;
        ans += a - 1;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int,int>
#define pll pair<LL,LL>

const double pi = 3.14159265358979323846264;
const int mod=1000000007;


//mod演算ライブラリ
//mod=1000000007

LL add(LL a,LL b){
  return (a+b)%mod;
}

LL sub(LL a,LL b){
  return (a+mod-b)%mod;
}

LL mul(LL a,LL b){
  return ((a % mod) * (b % mod)) % mod;
}

LL power(LL x,LL y){//繰り返し二乗法 単品利用可
  if(y==0)return 1;
  else if(y==1)return x%mod;
  else if(y%2==0){
    LL tmp=power(x, y/2) % mod;
    return tmp*tmp%mod;
  }else {
    LL tmp=power(x, y/2) % mod;
    return ((tmp*tmp)%mod)*x%mod;
  }
}

LL dvs(LL a,LL b){
  return mul(a,power(b,mod-2));
}

const int SIZE_mod=200005;
int invfact[SIZE_mod];
int fact[SIZE_mod];

LL factset(int a){//aまでの階乗%mod表を作成
  fact[0]=1;
  FORQ(i,1,a){
    fact[i]=mul(fact[i-1],i);
  }
}

LL cmbset(int a){//1~aまでの階乗と階乗数の逆元のmod(mod)を用意 O(a)
  factset(a);
  invfact[a]=power(fact[a],mod-2);
  invfact[0]=1;
  FORD(i,a,1){
    invfact[i]=mul(invfact[i+1],i+1);
  }

}

LL cmb(int n,int r){//nCr%mod  (cmbset後に使用)
  if(n<r||r<0||n<0)return 0;
  return mul(fact[n],mul(invfact[r],invfact[n-r]));
}

LL prm(int n,int r){//nPr%mod
    return mul(cmb(n,r),fact[n]);
}

LL homo(int n,int r){//nHr%mod
  return cmb(n+r-1,r);
}

inline LL f(const LL a){
	return ((a+1)*a/2)%mod;
}

inline LL f2(const LL a,const LL d,const LL r){
	LL t=(a+d*(r-1))%mod;
	return ((t+a)*r/2)%mod;
}

int main(){
	 //cin.tie(0);
	//ios::sync_with_stdio(false);
	//std::cout << std::fixed;
	//std::cout << std::setprecision(12);
	//std::cout << std::defaultfloat;
	int n,m,k;
	cin>>n>>m>>k;
	vector<LL> t(m,0);
	FOR(i,0,m){
		LL l=i-0,r=m-1-i;
		t[i]=add(f(l),f(r));
		if(i>0)t[i]=add(t[i],t[i-1]);
	}

	LL ans=1,nm=mul(n,m),dv=1;
	FOR(i,0,k-2){
		ans=mul(ans,sub(nm-2,i));
		dv=mul(dv,i+1);
	}
	ans=dvs(ans,dv);//*/

	LL aa=0;
	FOR(i,0,n){
		LL u=i+1,dw=n-i;
		LL a=t[m-1],d=mul(m,m);
		aa=add(aa,sub(f2(a,d,u)+f2(a,d,dw),a));
	}
	aa=dvs(aa,2);
	//cerr<<t[m-1]<<endl;
	//cerr<<aa<<endl;
	cout<<mul(aa,ans);

	return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const ll MOD=1000000007;
const ll INF=1000000010;
const ll LINF=4000000000000000010;
int dx[5]={0,1,0,-1,0};
int dy[5]={1,0,-1,0,0};
int main(){
    int n;cin>>n;
    for(int i=0;i<n;i++){
        int k,p;cin>>k>>p;
        int s=k%p;
        if(s==0){
            s=p;
        }
        cout<<s<<endl;
    }
}


Measured memory_bytes: 3076
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <functional>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define INF 100000000
template<class T, class C> void chmax(T& a, C b) { a>b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a<b ? : a = b; }


int main() {
	while (1) {
		int n, k;
		cin >> n >> k;
		if (n == 0 && k == 0) return 0;
		vector<string>s(n);
		set<string>se;
		for (int i = 0; i < n; i++) {
			cin >> s[i];
		}
		sort(s.begin(), s.end());
		do {
			string builts;
			for (int i = 0; i < k; i++) {
				builts += s[i];
			}
			se.insert(builts);
		} while (next_permutation(s.begin(), s.end()));
		long long cnt = se.size();
		cout << cnt << endl;
	}
	return 0;
}

Measured memory_bytes: 3260
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <iomanip>
#include <map>
using namespace std;

void solve(){
  int a, b, c; cin >> a >> b >> c;
  if(c - (a - b) > 0) cout << c - (a - b) << endl;
  else cout << 0 << endl;
  return;
}

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int INF = 1LL << 30;
int MOD = 1e9+7;
main(){
    int N;
    cin >> N;
    set<int> st;
    for(int i = 0;i < N;i++){
        int a;
        cin >> a;
        st.insert(a);
    }
    cout << st.size() << endl;
}

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

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

	ll N, Y;
	cin >> N >> Y;

	for(int i = 0; i <= N; i++){
		for(int j = 0; j <= N; j++){
			int k = N - i - j;
			if(k < 0) continue;
			ll t = 10000 * i + 5000 * j + 1000 * k;
			if(t == Y){
				cout << i << " " << j << " " << k << endl;
				return 0;
			}
		}
	}

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


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <cmath>
#include <numeric>

#define rep(i,n) for(int i = 0;i < (n);i++)
#define repp(i,j, n) for(int i = (j);i < (n);i++)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define INF 1e9

using namespace std;

typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pair<int, int> > vpi;
typedef vector<pair<ll, ll> > vpl;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  int one = 0, two = 0, four = 0;
  rep(i, n){
    ll a;
    cin >> a;
    if(a%4 == 0) four++;
    else if(a%2 == 0) two++;
    else one++;
  }
  if((one <= four && two%2 == 0) || (one <= four+1 && two == 0) || (one <= four && two%2 != 0 && four-one >= 0)) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        if (a == b && b == c)
            System.out.println(1);
        else if ((a == b && b != c) || (a == c && c != b) || (b == c && c != a))
            System.out.println(2);
        else
            System.out.println(3);
    }
}

Measured memory_bytes: 23764
let cnt = ref 0

let insertion_sort (a : int array) n g =
  for i = g to n - 1 do
    let v = a.(i) in
    let j = ref (i - g) in
    while !j >= 0 && a.(!j) > v do
      a.(!j+g) <- a.(!j);
      j := !j - g;
      incr cnt;
    done;
    a.(!j+g) <- v;
  done

let generate_g n =
  let rec doit i g acc =
    if g > n then acc
    else doit (i + 1) (int_of_float (4.**(float_of_int i) +. 3.*.2.**(float_of_int (i - 1)) +. 1.)) (g :: acc) in
  doit 1 1 []

let shell_sort (a : int array) n =
  cnt := 0;
  let g = generate_g n in
  List.iter (fun g -> insertion_sort a n g) g;
  g

let () =
  let n = read_int () in
  let a = Array.init n (fun _ -> read_int ()) in
  let g = shell_sort a n in
  Printf.printf "%d\n" (List.length g);
  print_int (List.hd g);
  List.iter (fun x -> print_string " "; print_int x) (List.tl g);
  print_newline ();
  Printf.printf "%d\n" !cnt;
  Array.iter (fun n -> Printf.printf "%d\n" n) a

Measured memory_bytes: 12616
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
 
#define REP(i,n) for(int i=0;i<(int)(n);i++)
 
 
int main()
{
    int x,y,s;
    int max=0;
    while(1==1)
    {
        max=0;
        scanf("%d %d %d\n",&x,&y,&s);
        if(x==0)break;
        REP(i,s-1)
        {
            int bu1=i+1;
            int bu2=s-i-1;
            int judge=0;
            int check=100+x;
            while(check<bu1*100)check+=100+x;
            if((check/100)!=bu1)judge=1;
            check=100+x;
            while(check<bu2*100)check+=100+x;
            if((check/100)!=bu2)judge=1;
            bu1*=100; bu1=bu1/(100+x)+(bu1%(100+x)!=0);
            bu2*=100; bu2=bu2/(100+x)+(bu2%(100+x)!=0);
            bu1*=(100+y); bu1/=100;
            bu2*=(100+y); bu2/=100;
            if(bu1+bu2>max && judge==0)
            {
                max=bu1+bu2;
                //printf("##%d %d %d %d##\n",max,bu1,bu2,i+1);
            }
        }
        printf("%d\n",max);
    }
    return 0;
}


Measured memory_bytes: 3164
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007
typedef pair<int,int> iP;
int power(int x,int y){
    int res=1;
    x=x%mod;
    while(y>0){
        if(y&1)res=(res*x)%mod;
        x=(x*x)%mod;
        y/=2;
    }
    return res;
}
int mulmod(int a,int b){ 
    int res=0;
    a=a%mod; 
    while(b>0){
        if(b%2==1) 
        res=(res+a)%mod; 
        a=(a*2)%mod; 
        b/=2;
    } 
    return res%mod; 
}
vector<int> pr;
void sieve() { 
    bool prime[1000000+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p<=1000000; p++) {
        if (prime[p] == true) {  
        pr.push_back(p);
            for (int i=p*p; i<=1000000; i += p) 
                prime[i] = false; 
        } 
    }
}
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);cout<<fixed;
    sieve();
    int n;
    cin>>n;
    for(int i=0;i<pr.size();i++){
        if(pr[i]>=n){
            cout<<pr[i];
            break;
        }
    }
}

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

using namespace std;

int main()
{
int n,k;
cin>>n>>k;
int arr[n];
for(int i=0; i<n; i++) cin>>arr[i];
sort(arr,arr+n);
int sum=0;
for(int i=0; i<k; i++) sum+=arr[i];
cout<<sum;
return 0;
}


Measured memory_bytes: 3592
N = int(input())
a = list( map( int, input().split()))
a = sorted(a)
a.reverse()
Alice = 0
Bob = 0
a.append(0)
a.append(0)

for i in range(N//2 + 1):
	Alice += int(a[2 * i])  
	Bob += int(a[2 * i + 1])
    
print(Alice -Bob)


Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int minn = 1000007;
int a;
int ans;
int main(){
	int n;
	cin >> n;
	for(int i = 1; i <= n; i++){
		cin >> a;
		if(a <= minn){
			ans++;
			minn = a;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256