akhauriyash/Code-Regression huggingface dataset:
{-# LANGUAGE BangPatterns #-}
import Control.Arrow
import Control.Monad.Fix
import Data.Foldable
import Data.List
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VMM
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VM
import qualified Data.ByteString.Char8 as B
import Data.ByteString.Internal (accursedUnutterablePerformIO)
import qualified Data.Set as S
import System.IO.Unsafe
import Debug.Trace

unew :: VU.Unbox a => Int -> VM.IOVector a
unew !n = accursedUnutterablePerformIO $ VM.unsafeNew n

uread :: VU.Unbox a => Int -> VM.IOVector a -> a
uread !i !v = accursedUnutterablePerformIO $ VM.unsafeRead v i

uwrite :: VU.Unbox a => Int -> a -> VM.IOVector a -> VM.IOVector a
uwrite !i !a !v =
  accursedUnutterablePerformIO $ VM.unsafeWrite v i a >> return v

umodify :: VU.Unbox a => Int -> (a -> a) -> VM.IOVector a -> VM.IOVector a
umodify !i !f !v =
  accursedUnutterablePerformIO $ VM.unsafeModify v f i >> return v

uthaw :: VU.Unbox a => VU.Vector a -> VM.IOVector a
uthaw !v = accursedUnutterablePerformIO $ VU.unsafeThaw v

ufreeze :: VU.Unbox a => VM.IOVector a -> VU.Vector a
ufreeze !v = accursedUnutterablePerformIO $ VU.unsafeFreeze v

solve :: Int -> Int -> B.ByteString -> Bool
solve !x !y !bs =
  foldl' go dpX rx VU.! toIndex x && foldl' go dpY ry VU.! toIndex y
 where
  go !prev !i = accursedUnutterablePerformIO $ VU.generateM
    (maxN * 2 + 1)
    (\(!k') ->
      let k = k' - maxN
      in  return
          $  (if (k + i) < maxN then prev VU.! toIndex (k + i) else False)
          || (if (k - i) >= -maxN then prev VU.! toIndex (k - i) else False)
    )

  maxN = B.length bs
  dpX  = VU.fromList [ i == rx0 | i <- [-maxN .. maxN] ]
  dpY  = VU.fromList [ i == 0 | i <- [-maxN .. maxN] ]

  toIndex !k = k + maxN

  (!rx0, !rx, !ry) =
    let
      (bs0, bs1)     = B.span (== 'F') bs
      (rx, ry, _, _) = if B.length bs1 == 0
        then ([], [], B.empty, 0)
        else fix
          (\f (!rx, !ry, !bs, !parity) ->
            let (bs0, bs1) = B.span (== 'F') bs
                r          = B.length bs0
                next       = if B.length bs1 == 0 then id else f
                bs1'       = if B.length bs1 == 0 then B.empty else B.tail bs1
                cons       = if r > 0 then (r :) else id
            in  if parity == 0
                  then next $ (cons rx, ry, bs1', 1)
                  else next $ (rx, cons ry, bs1', 0)
          )
          ([], [], B.tail bs1, 1)
    in
      (B.length bs0, rx, ry)

main = do
  let readInt = fmap (second B.tail) . B.readInt

  bs     <- B.getLine
  (x, y) <-
    (\vec -> (vec VU.! 0, vec VU.! 1)) . VU.unfoldrN 2 readInt <$> B.getLine
  putStrLn $ if solve x y bs then "Yes" else "No"


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

static const int N = 100;

int main() {
  int n, p[N + 1], m[N + 1][N + 1];
  cin >> n;
  for ( int i = 1; i <= n; i++ ) {
    cin >> p[i - 1] >> p[i];
  }

  for ( int i = 1; i <= n; i++ ) m[i][i] = 0;
  for ( int l = 2; l <= n; l++ ) {
    for ( int i = 1; i <= n - l + 1; i++ ) {
      int j = i + l - 1;
      m[i][j] = (1 << 21);
      for ( int k = i; k <= j - 1; k++) {
        m[i][j] = min(m[i][j], m[i][k] + m[k + 1][j] + p[i -1] * p[k] * p[j]);
      }
    }
  }

  cout << m[1][n] << endl;

  return 0;
}


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

using namespace std;

int a, b, c, d;
string s;

int main(){
    cin >> s;
    a = s[0] - '0';
    b = s[1] - '0';
    c = s[2] - '0';
    d = s[3] - '0';
    if (a+b+c+d == 7) cout << a << '+' << b << '+' << c << '+' << d << "=7";
    else if (a+b+c-d == 7) cout << a << '+' << b << '+' << c << '-' << d << "=7";
    else if (a+b-c+d == 7) cout << a << '+' << b << '-' << c << '+' << d << "=7";
    else if (a+b-c-d == 7) cout << a << '+' << b << '-' << c << '-' << d << "=7";
    else if (a-b+c+d == 7) cout << a << '-' << b << '+' << c << '+' << d << "=7";
    else if (a-b+c-d == 7) cout << a << '-' << b << '+' << c << '-' << d << "=7";
    else if (a-b-c+d == 7) cout << a << '-' << b << '-' << c << '+' << d << "=7";
    else if (a-b-c-d == 7) cout << a << '-' << b << '-' << c << '-' << d << "=7";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mk make_pair
int gcd(int a,int b){
    if(b==0)
     return a;
    return gcd(b,a%b);
}
int main(){
    int t;
    cin>>t;
    map<string,int> mp;
    while(t--){
        string str;
        cin>>str;
        mp[str]++;
    }
    cout<<"AC x "<<mp["AC"]<<endl;
    cout<<"WA x "<<mp["WA"]<<endl;
    cout<<"TLE x "<<mp["TLE"]<<endl;
    cout<<"RE x "<<mp["RE"]<<endl;
}


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

int main(){
    int A, B;
    cin >> A >> B;

    int cnt = 0;
    while(1 + (A - 1) * cnt < B){
        cnt++;
    }
    
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 3536
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
using ll = long long;
using ull = unsigned long long;
constexpr int MOD = 1000000007;

int mod(ll x){
    return x > 0 ? x % MOD : (x+MOD) % MOD;
}

int modm(ll x,ll m){
    return x * m % MOD;
}

int modpow(ll x, ll p) {
    int ret = 1;
    while(p > 0) {
        if (p & 1) ret = modm(ret,x);
        x = modm(x,x);
        p >>= 1;
    }
    return ret;
}

// x * modinv(d)
int modd(ll x,ll d) {
    return modm(x,modpow(d,MOD-2));
}

int main(void)
{
    constexpr int H = 100;
    constexpr int W = 8;

    IOS
    int h,w,k;
    cin >> h >> w >> k;

    int dp[H+1][W+1];
    memset(dp,0,sizeof dp);
    dp[0][0] = 1;

    vector<bitset<W-1>> r;
    REP(i,pow(2,w-1)) {
        bitset<W-1> tmp(i);
        bool b = true;
        FOR(j,1,W-1) {
            if (tmp[j-1] & tmp[j]) b = false;
        }
        if (b) r.emplace_back(tmp);
    }

    vector<vector<int>> r2(w,vector<int>(3,0));
    for (auto x: r) {
        REP(i,w-1){
            if (!x[i]) {
                if (i == 0 || !x[i-1]) r2[i][1]++;
                if (i == w-2) r2[i+1][1]++;
             } else {
                r2[i][2]++;
                r2[i+1][0]++;
            }
        }
    }
    // REP(i,w) {
    //     cerr << r2[i][0] << " " <<r2[i][1] << " " <<r2[i][2] << " " << endl;
    // }
    // cerr << endl;


    REP(i,h) {
        REP(j,w) {
            if (j != 0) dp[i+1][j] = mod(dp[i+1][j] + modm(dp[i][j-1],r2[j][0]));
            dp[i+1][j] = mod(dp[i+1][j] + modm(dp[i][j],r2[j][1]));
            if (j != w-1) dp[i+1][j] = mod(dp[i+1][j] + modm(dp[i][j+1],r2[j][2]));
        }
        // cerr << dp[i+1][0] << " " <<dp[i+1][1] << " " <<dp[i+1][2] << " " << endl;
    }

    if (w != 1) {
        cout << dp[h][k-1] << endl;
    } else {
        cout << 1 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using P = pair<ll, ll>;

// chmin, chmax関数
template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}
template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}

// Yes-Noを出力する問題で楽をする
void Ans(bool f){
    if(f) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

int main(){
    int a,b; cin >> a >> b;
    cout << max(max(a*b,a+b),a-b) << endl;
    return 0;
}

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

using namespace std;

int main(){

    int flag=0;
    string S;
    cin >> S;


    if(S.find("A")>=0&&S.find("A")<S.size()){
        if(S.find("C")==1+S.find("A")){
            flag=1;
        }
    }

    if(flag==1){
        cout <<"Yes"<<endl;
    }
    else{
        cout <<"No"<<endl;
    }

    return 0;
}

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

int main()
{
    int r, D, x;
    cin >> r >> D >> x;

    for(int i = 0; i < 10; i++){
        x = r * x - D;
        cout << x << endl;
    }

    return 0;
}

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

int main()
{
    int a[1000], i, n, count1 = 0, count2 = 0;
    scanf("%d", &n);

    for(i = 0; i < n; i++){
        scanf("%d", &a[i]);
    }

    for(i = 0; i < n; i++){
        if(a[i] % 2 == 0){
                count1++;
            if(a[i] % 3 == 0 || a[i] % 5 == 0){
                count2++;
            }
        }
    }
    if(count1 == count2){
        printf("APPROVED\n");
    }
    else{
        printf("DENIED\n");
    }
    return 0;
}


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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;

bool check(vector<ll> &A, int c) {
    ll sum = A[c];
    rep(i, A.size()) {
        if (i == c) continue;
        if (A[i] > 2 * sum) return false;
        sum += A[i];
    }
    return true;
}

int main() {
    int N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    sort(A.begin(), A.end());

    int l = -1;
    int r = N - 1;
    while (r - l > 1) {
        int c = (l + r) / 2;
        if (check(A, c)) r = c;
        else l = c;
    }

    cout << N - r << endl;
}

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

int main(){
    int H,W,i,j;

    while(1){
        cin >> H >> W;
        if(H==0 && W==0)break;

        for(int i=1;i<=H;i++){
            for(int j=1;j<=W;j++){
                if((i+j)%2==0){
                    cout << '#';
                }else{
                    cout << ".";
                }
            }
            cout << '\n';
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3100
def dot(x, y):
    return (x.conjugate() * y).real
     
def is_orthogonal(x, y):
    if abs(dot(x, y)) < 1e-10:
        return True
    return False
         
import sys
 
for line in sys.stdin:
    li = list(map(float, line.split()))
    p = []
    for i in range(0, len(li), 2):
        p.append(complex(li[i], li[i+1]))
    d1 = p[1] - p[0]
    d2 = p[3] - p[2]
     
    if is_orthogonal(d1, d2):
        print('YES')
    else:
        print('NO')


Measured memory_bytes: 5592
import collections as col

N = int(input())
A = list(map(int,input().split()))
L = col.Counter(A).most_common()
# ans[0] > ans[1]
ans = [0] * 2
square = 0

for _, item in enumerate(L):
    if item[1] >= 4:
        square = max(square, item[0])
    if item[1] >= 2:
        if ans[0] < item[0]:
            ans[1] = ans[0]
            ans[0] = item[0]
        elif ans[1] < item[0]:
            ans[1] = item[0]

print(max(ans[0]*ans[1],square**2))


Measured memory_bytes: 21540
#include <stdio.h>
#include <math.h>

int main(void){

  int x;
  scanf("%d", &x);

  int prime_list[110000+1];
  for (int i = 0; i < 110000+1; i++) {
    prime_list[i] = 1;
  }
  for (int i = 2; i <= sqrt(110000); i++) {
    if (prime_list[i] == 1) {
      for (int j = 2; i*j <= 110000; j++) {
        prime_list[i*j] = 0;
      }
    }
  }

  for (int i = x; i < 110000; i++) {
    if (prime_list[i] == 1) {
      printf("%d\n", i);
      break;
    }
  }

  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <utility>

using namespace std;

int p(int* a,int p,int r) {
	int x = a[r];
	int i = p-1;
	for(int j = p;j < r;j++) {
		if(a[j] <= x) {
			i++;
			swap(a[i],a[j]);
		}
	}
	swap(a[i+1],a[r]);
	return i+1;
}

int main(void) {
	int n,a[100000];
	cin >> n;
	for(int i = 0;i < n;i++)cin >> a[i];
	int sep = p(a,0,n-1);
	for(int i = 0;i < n;i++) {
		if(i == sep) cout << "[";
		cout << a[i];
		if(i == sep) cout << "]";
		if(i != n-1) cout << " ";
	}
	cout << endl;
}



Measured memory_bytes: 3388
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;
#define int long long
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
const int INF=100000000000000000;

int Ceil(int a,int b){return ((a%b==0)?a/b:a/b+1);}

signed main(){
	int N,A[1010],B[1010];
	int ans=0;
	cin>>N;
	REP(i,N){
		cin>>A[i]>>B[i];
	}
	if(N==1){
		cout<<A[0]+B[0]<<endl;
		return 0;
	}
	REP(i,N-1){
		int sum=A[i]+B[i];
		int sum2=A[i+1]+B[i+1];
		if(A[i]<=A[i+1]&&B[i]<=B[i+1]){
			ans=sum2;
		}
		else if(A[i]>A[i+1]&&B[i]<=B[i+1]){
			int s=Ceil(A[i],A[i+1]);
			A[i+1]*=s,B[i+1]*=s;
			ans=A[i+1]+B[i+1];
		}
		else if(A[i]<=A[i+1]&&B[i]>B[i+1]){
			int s=Ceil(B[i],B[i+1]);
			A[i+1]*=s,B[i+1]*=s;
			ans=A[i+1]+B[i+1];
		}
		else{
			int s=Ceil(B[i],B[i+1]);
			int s2=Ceil(A[i],A[i+1]);
			int s3=max(s,s2);
			A[i+1]*=s3,B[i+1]*=s3;
			ans=A[i+1]+B[i+1];
			DEB(s)DEB(s2)END
		}
	}
	cout<<ans<<endl;
	return 0;
}


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

int main() {
	long N; cin >> N;
	int m=15;
	int i;
	for(i=sqrt(N); i>0; --i){
	    if(N%i==0) break;
	}
	int n=max(log10(i), log10(N/i))+1;
	cout << n << endl;
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int main(){
  ll N,M;cin>>N>>M;
  vector<vector <ll> > s(M);
  vector<ll> p;
  vector<ll> K;
  ll i,j,k,l;
  ll ans=0;
  rep(i,M){
    ll a;cin>>a;
    K.pb(a);
    rep(j,a){
      ll c;cin>>c;
      c--;
      s[i].pb(c);
    }
  }
  rep(i,M){
    ll b;cin>>b;
    p.pb(b);
  }
  rep(i,1<<N){
    bool ok = true;
    rep(j,M){
      int cnt=0;
      rep(k,K[j]){
        if((i>>s[j][k])&1) cnt++;
      }
      if(cnt %2 != p.at(j)) ok=false;
    }
    if(ok) ans++;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<vector>
#include<map>
#include<queue>
using namespace std;
#define INF (1<<30)
int M,N;
int P[10001];
int C[501];
int E[501];
 
int dp[501][10001];
int H[10001];
int J[10001];
void memo(){
for(int id=0;id<=N;id++){
for(int k=0;k<=M;k++){
dp[id][k]=INF;
}
}
dp[0][0]=0;
for(int id=0;id<N;id++){
for(int k=0;k<=M;k++){
if( dp[id][k] != INF ){
// printf("%d %d %d %d\n",id,k,dp[id][k],E[id]);
dp[id+1][min(M,k+C[id])] = min(dp[id+1][min(M,k+C[id])],dp[id][k]+E[id]);
dp[id+1][k] = min(dp[id+1][k],dp[id][k]);
}
}
}
H[M] = dp[N][M];
// printf("H[%d] = %d\n",M,H[M]);
for(int i=M-1;i>-1;i--){
H[i] = INF;
H[i] = min(H[i+1],dp[N][i]);
//printf("H[%d] = %d\n",i,H[i]);
}
}
 
int solve(int K){
return J[K] - H[K];
}
 
int main(){
scanf("%d %d",&M,&N);
for(int i=0;i<M;i++){
scanf("%d",&P[i]);
}
sort(P,P+M);
for(int i=1;i<=M;i++){
J[i] = J[i-1]+P[M-i];
}
 
for(int i=0;i<N;i++){
scanf("%d %d",&C[i],&E[i]);
}
memo();
int res =0;
for(int i=0;i<=M;i++){
res = max(res,solve(i));
}
printf("%d\n",res);
}

Measured memory_bytes: 20896
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		while(in.hasNext()) {
			int T=in.nextInt();
			int max=0;
			int[] a=new int[100000+5];
			for(int i=0;i<T;i++) {
				int b=in.nextInt();
				a[b]++;
				max=(a[b]>max)?a[b]:max;
				if(b!=0) {
					a[b-1]++;
					max=(a[b-1]>max)?a[b-1]:max;
				}
				a[b+1]++;
				max=(a[b+1]>max)?a[b+1]:max;
			}
			System.out.println(max);
		}
	}
}

Measured memory_bytes: 49412
N = int(input())
An = list(map(int,input().split(' ')))


cache = [ 0 for _ in range(N+1)] 

cache[0] = 3
amount = 1
mod = 1000000007
for i in range(N):
    need_hat = An[i]
    amount = amount * cache[need_hat] % mod
    cache[need_hat] -= 1
    cache[need_hat+1] += 1
print(amount)

Measured memory_bytes: 55492
#include <bits/stdc++.h>
using namespace std;
//to set precision use fixed,setprecision(number_of_points_after_decimal)
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define mod 1000000007
#define sz(x) (int)(x).size()
#define ff first
#define ss second
#define pb push_back
#define debugvector(h) for(auto &l:h)cout<<l<<" "
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef map<int,int> mii;
typedef long double ld;
void solution(){
  int n,k;cin>>n>>k;
  ll dp[n];
  int nums[n];
  rep(i,0,n) cin>>nums[i];
  dp[0]=0;
  rep(i,1,n){
    ll minimum=1e+18;
    rep(j,1,k+1)
    { ll temp;
      if(i-j>=0)
        temp=(abs(nums[i]-nums[i-j])+dp[i-j]),minimum=min(minimum,temp);
    }
    dp[i]=minimum;
  }
  cout<<dp[n-1]<<endl;

}



int main() {
    #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
  #endif
  cin.tie(0)->sync_with_stdio(0);
  cin.exceptions(cin.failbit);
  //int t;cin>>t;
 //while(t--){
  solution();
  //}
  return 0;
}

Measured memory_bytes: 4728
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  ll N,M;
  cin >> N;
  vector<ll> A(N);
  for(ll i=0;i<N;i++){
    cin >> A.at(i);
  }
  
  ll cnt=1;
  int flag=0;
  ll i=0;
  
  while(i<N-1){
    if(A.at(i)>A.at(i+1) && flag == 0){
      flag = 1;
    }else if(A.at(i)<A.at(i+1) && flag == 0){
      flag = -1;
    }else if(A.at(i) < A.at(i+1) && flag == 1){
      cnt++;
      flag = 0;
    }else if(A.at(i) > A.at(i+1) && flag == -1){
      cnt++;
      flag = 0;
    }
    i++;
  }
  
  cout << cnt << endl;
  
  return(0);
}

Measured memory_bytes: 1024
#pragma GCC optimize("Ofast")
  
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <string>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <unordered_set>
#include <list>
#include <tuple>
#include <iomanip>
#include <climits>
#include <cstdlib>
#include <cassert>
#include <numeric>
#include <cmath>
#include <bitset>
#include <random>
#include <regex>

using namespace std;
  
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define Fixed fixed << setprecision(14)
#define int int64_t
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9+7; 
constexpr int mod2 = 998244353;
constexpr int dy[] = {0,1,0,-1,1,-1,-1,1};
constexpr int dx[] = {1,0,-1,0,1,1,-1,-1};
 
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class A, class B> inline A updiv(const A a,const B b){ return (a + b - 1) / b; }
template <class A, class B> inline A gcd(const A a,const B b){ return b ? gcd(b,a % b) : a; }
template <class A, class B> inline A lcm(const A a,const B b){ return a / gcd(a,b) * b; }

template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
template <class A,class B> using umap = unordered_map<A,B>;


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

    int n, x, y;
    cin >> n >> x >> y;

    if(x > y) swap(x,y);

    vector<int> cnt(n);

    reps(i,n-1){
        for(int j = i+1; j <= n; ++j){
            int a = i, b = j;
            if(a > b) swap(a,b);
            int dist = min(abs(a-b), abs(x-a) + abs(y-b) + 1);

            ++cnt[dist];
        }
    }

    reps(i,n-1){
        cout << cnt[i] << '\n';
    }

    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int k = sc.nextInt();
        int digit = s.length();

        String[] arr = new String[digit];
        for (int i=0; i<digit; i++) arr[i] = s.substring(i, i+1);

        int[] arrInt = new int[digit];
        for (int i=0; i<digit; i++) arrInt[i] = Integer.parseInt(arr[i]);

        int[][][] dp = new int[digit][4][2];

        for (int i=0; i<digit; i++){
            dp[i][0][0] = 1;
        }

        dp[0][1][0] = arrInt[0]-1;
        dp[0][1][1] = 1;


        for (int i=1; i<digit; i++){
            // true

            // k==1
            dp[i][1][0] = dp[i-1][0][0]*9 + dp[i-1][1][0] + ((arrInt[i]==0) ? 0 : dp[i-1][1][1]);
            // k==2
            dp[i][2][0] = dp[i-1][1][0]*9 + dp[i-1][2][0] + ((arrInt[i]==0) ? 0 : dp[i-1][1][1]*(arrInt[i]-1) + dp[i-1][2][1]);
            // k==3
            dp[i][3][0] = dp[i-1][2][0]*9 + dp[i-1][3][0] + ((arrInt[i]==0) ? 0 : dp[i-1][2][1]*(arrInt[i]-1) + dp[i-1][3][1]);



            // false

            // k==1
            dp[i][1][1] = (arrInt[i]==0 ? dp[i-1][1][1] : 0);
            // k==2
            dp[i][2][1] = (arrInt[i]==0 ? (dp[i-1][2][1]) : (dp[i-1][1][1]) );
            // k==3
            dp[i][3][1] = (arrInt[i]==0 ? (dp[i-1][3][1]) : (dp[i-1][2][1]) );
        }


        System.out.println(dp[digit-1][k][0]+dp[digit-1][k][1]);
//        System.out.println(dp[digit-1][k][0]);

//        System.out.println(dp[1][1][0]);
//        System.out.println(dp[2][1][0]);
//        System.out.println(dp[1][1][1]);
//        System.out.println(dp[2][1][1]);

    }
}


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

#define pb push_back
#define ll long long
#define pi pair<int,int>
#define pii pair<int,pi>
#define pl pair<ll,ll>
#define pll pair<ll,pl>
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int I_LIMIT = 999999999;
ll L_LIMIT = 999999999999999999;
ll mod = 1e9+7;

ll spf[1000005];
ll dp[1000005];

int gcd(int a,int b)
{
    if(b==0)
        return a;
    else
        return gcd(b,a%b);
}

void seive()
{
    ll i,j;
    for(i=1;i<1000005;i++)
        spf[i]=i;
    
    for(i=2;i<1000005;i++)
    {
        if(spf[i]==i)
        {
            for(j=i*i;j<1000005;j+=i)
                spf[j]=i;
        }
    }
}

void ffactor(int A[],int n)
{
    int i,x,temp;
    for(i=0;i<n;i++)
    {
        x = A[i];
        while(x>1)
        {
            temp = spf[x];
            dp[temp]++;
            while(x%temp==0)
                x = x/temp;
        }
    }
}

bool check(int x)
{
    int temp;
    while(x>1)
    {
        temp = spf[x];
        if(dp[temp]>1)
            return false;
        while(x%temp==0)
            x = x/temp;
    }
    return true;
}

void solve()
{
    int n,m,i,g;

    for(i=0;i<1000005;i++)
        dp[i]=0;

    cin>>n;
    int A[n];
    for(i=0;i<n;i++)
        cin>>A[i];
    g = A[0];
    for(i=1;i<n;i++)
        g = gcd(g,A[i]);
    
    if(g!=1)
        cout<<"not coprime\n";
    else
    {
        ffactor(A,n);
        for(i=0;i<n;i++)
        {
            if(!check(A[i]))
                break;
        }
        if(i==n)
            cout<<"pairwise coprime\n";
        else
            cout<<"setwise coprime\n";
    }
}
int main()
{
    IOS;
    for(int i=0;i<1000005;i++)
        spf[i]=0;
    seive();
    solve();
}


Measured memory_bytes: 23136
#include<bits/stdc++.h>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#define endl  "\n"
#define ll long long
#define int long long
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cin.exceptions(cin.failbit);cout.tie(NULL);
using namespace std;
bool isPrime(int n)
{
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;
    if (n % 2 == 0 || n % 3 == 0)
        return false;
    for (int i = 5; i * i <= n; i += 6)
    {
        if ((n % i == 0) || (n % (i + 2) == 0))
            return false;
    }
    return true;
}
int32_t main()
{
	int n;
	cin >> n;
	int a[n];
	map<int,int> mp;
	int s=0;
	for(int i=0;i<n;i++)
	{
		cin >> a[i];
		mp[a[i]]++;
		s+=a[i];
	}
	int q;
	cin >> q;
	while(q--)
	{
		int x,y;
		cin >> x >> y;
		int z=y-x;
		s=s+z*(mp[x]);
		mp[y]+=mp[x];
		mp[x]=0;
		cout << s << endl;
	}
	
}



Measured memory_bytes: 10136
#print#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code

#なお、任意の整数 M に対して M の −2 進数表現が一意に定まることが証明できます。
#2桁ごとに見るとよかった（もう実験したよ）
def resolve():
    N,=pin()
    A=lispin()
    A.sort()
    ans=0
    for i in range(N):
        t=A.pop()
        if i%2==0:ans+=t
        else: ans-=t
    print(ans)
#%%submit!
resolve()

Measured memory_bytes: 38492
def resolve():
    n = int(input())
    dd = list(map(int, input().split()))

    size = len(dd) // 2
    dd.sort()
    ans = 0


    if dd[size] == dd[size - 1]:
        ans = 0
    else:
        ans = dd[size] - dd[size - 1]

    print(ans)
    
resolve()

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

int main(){
  long long n,q,s=0;
  map<int, int> mp;
  long long ans[100005];

  cin >> n;
  rep(i, n){
    int tmp;
    cin >> tmp;
    s += tmp;
    mp[tmp]++;
  }
  
  cin >> q;
  rep(i, q){
    int b, c;
    cin >> b >> c;

    s+=(c-b)*mp[b];
    mp[c]+=mp[b];
    mp[b]=0;
    ans[i]=s;
  }
  
  rep(i, q)cout << ans[i] << endl;
  return 0;
}


Measured memory_bytes: 8656
import std.stdio;
import std.algorithm;

const int N = 101;

int[N][N] cost;
int[N] minCost, used;

void main(){
	int n, m, a, b, c, ans;
	while (readf("%d %d\n", &n, &m), n || m) {
		minCost[] = int.max;
		used[] = false;
		foreach (i; 0..n) cost[i][] = int.max;
		foreach (i; 0..m) {
			readf("%d %d %d\n", &a, &b, &c);
			cost[a][b] = cost[b][a] = c;
		}
		minCost[0] = ans = 0;
		
		// Prim
		while (1) {
			int v = -1;
			foreach (i; 0..n)
				if (!used[i] && (v == -1 || minCost[i] < minCost[v]))
					v = i;

			if (v == -1) break;

			used[v] = true;
			ans += minCost[v];
			foreach (i; 0..n) minCost[i] = min(minCost[i], cost[v][i]);
		}

		writeln(ans);
	}
}

Measured memory_bytes: 1036
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
using namespace std;

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (ll)(m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD1 = 1e9+7;
const ll MOD9 = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T1, typename T2>bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
template<typename T1, typename T2>bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++){cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++){for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>vector<vector<T>>vec(ll x, ll y, T w){vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,-1,0,0,1,1,-1,-1};vector<ll>dy={0,0,1,-1,1,-1,1,-1};
template<typename T>vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v(ts...))>(a,make_v(ts...));}
template<typename T1, typename T2>ostream &operator<<(ostream &os, const pair<T1, T2>&p){return os << p.first << " " << p.second;}
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v){for(auto &z:v)os << z << " ";cout<<"|"; return os;}
//mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  ll n;cin>>n;
  rep(a,1,n+1){
    for(ll b=1;a*b<=n;b++){
      if(a*b<n)res++;
    }
  }
  cout<<res<<endl;
  return 0;
}

Measured memory_bytes: 3648
#pragma GCC optimize(2,3,"Ofast","unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define in inline
namespace fast_io
{
	char buf[1<<12],*p1=buf,*p2=buf,sr[1<<23],z[23],nc;int C=-1,Z=0,Bi=0,ny;
	in char gc() {return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<12,stdin),p1==p2)?EOF:*p1++;}
	in ll read()
	{
		ll x=0;ny=1;while(nc=gc(),(nc<48||nc>57)&&nc!=EOF)if(nc==45)ny=-1;Bi=1;if(nc<0)return nc;
		x=nc-48;while(nc=gc(),47<nc&&nc<58&&nc!=EOF)x=(x<<3)+(x<<1)+(nc^48),Bi++;return x*ny;
	}
	in db gf() {int a=read(),y=ny,b=(nc!='.')?0:read();return (b?a+(db)b/pow(10,Bi)*y:a);}
	in int gs(char *s) {char c,*t=s;while(c=gc(),c<=32);*s++=c;while(c=gc(),c>32)*s++=c;return s-t;}
	in void ot() {fwrite(sr,1,C+1,stdout);C=-1;}
	in void flush() {if(C>1<<22) ot();}
	template <typename T>
	in void write(T x,char t)
	{
		int y=0;if(x<0)y=1,x=-x;while(z[++Z]=x%10+48,x/=10);
		if(y)z[++Z]='-';while(sr[++C]=z[Z],--Z);sr[++C]=t;flush();
	}
	in void write(char *s) {int l=strlen(s);for(int i=0;i<l;i++)sr[++C]=*s++;sr[++C]='\n';flush();}
};
using namespace fast_io;
#define pb push_back
const int N=1e7+5,M=1e6+5;
int n,p[M],m[N];
ll ans,d[N];
bool vis[N];
int main()
{
	n=read();
	d[1]=1;
	for(int i=2;i<=n;i++){
		if(!vis[i])p[++p[0]]=i,d[i]=2,m[i]=2;
		for(int j=1;j<=p[0]&&i*p[j]<=n;j++){
			vis[i*p[j]]=1;
			if(!(i%p[j])){
				d[i*p[j]]=d[i]/m[i]*(m[i]+1);
				m[i*p[j]]=m[i]+1;
				break;
			}
			d[i*p[j]]=d[i]*2,m[i*p[j]]=2;
		}
	}
	for(int i=1;i<=n;i++)ans+=i*d[i];
	cout<<ans;
	return ot(),0;
}
//Author: disangan233

Measured memory_bytes: 133172
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: usize,
        a: [usize; n],
    }

    let mut sum = 0u64;
    let mut a = a.into_iter();
    let mut current_height = a.next().unwrap();
    for item in a {
        if current_height <= item {
            current_height = item;
        } else {
            sum += current_height as u64 - item as u64;
        }
    }

    println!("{}", sum);
}


Measured memory_bytes: 5644
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <utility>
#include <tuple>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
using ll = long long int;
using P = pair<int, int>;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...) do{ } while(false)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template<typename T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }
template<typename T> void print(T a) { cout << a << endl; }
template<typename T, typename... Ts> void print(T a, Ts... ts) { cout << a << ' '; print(ts...); }
template<typename T> istream &operator,(istream &in, T &t) { return in >> t; }
// clang-format on

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, m;
    cin, n, m;
    vector<int> s(m), c(m);
    REP(i, 0, m) {
        cin, s[i], c[i];
        s[i] = n - s[i];
    }
    int start = 1, end = 10;
    REP(i, 0, n - 1) {
        start *= 10;
        end *= 10;
    }
    if (n == 1) {
        start = 0;
    }
    REP(i, start, end) {
        vector<int> vv;
        int tt = i;
        do {
            vv.push_back(tt % 10);
            tt /= 10;
        } while (tt);
        bool ok = true;
        REP(j, 0, m) {
            if (vv[s[j]] != c[j]) {
                ok = false;
            }
        }
        if (ok) {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;

    return 0;
}


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

using namespace std;

int main() {
    string A, B, C;
    cin >> A >> B >> C;
    if (A[A.size() - 1] == B[0] && B[B.size() - 1] == C[0]) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}

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

#define INF 1 << 29
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)

using namespace std;

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

void gen_sosuu(int sosuu[]){
  REP(i,100010){
    sosuu[i] = true;
  }
  sosuu[0] = false;
  sosuu[1] = false;
  sosuu[2] = true;
  FOR(i,2,sqrt(100000)+1){
    if(sosuu[i] == false) continue;
    for(int j = 2; i*j<=100000;j++){
      //printf("%d %d %d\n",i*j,i,j);
      sosuu[i*j] =false;
    }
  }
}

int a,b;

int main(){
  scanf("%d %d",&a,&b);
  printf("%d\n",(a+b)%24);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,a,b) for (int i = (a); i < (b); i++ )
typedef pair<int,int> P;
typedef long long ll;
const int INF = 100000000;

int main() {
    int N;
    cin >> N;
    cout << 24 + (24-N) << endl;
}

Measured memory_bytes: 256
#include<cmath>
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<map>
#include<queue>
#include<set>
#include<vector>
#include<bitset>
using namespace std;
const int maxn=100005;
int n,m,p[maxn],vis[maxn],cnt[maxn],ac,wa;
inline int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9')
    {
		if(ch=='-')
			f=-1;
		ch=getchar();
    }
    while(ch>='0'&&ch<='9')
    {
		x=(x<<1)+(x<<3)+(ch^48);
		ch=getchar();
    }
    return x*f;
}
inline void write(int a)
{
    if(a<0)
    {
		char a='-',b='1';
		putchar(a);
		putchar(b);
    }
    else
    {
		if(a>=10)
			write(a/10);
		putchar(a%10+'0');
    }
}

int main()
{
    n=read(),m=read();
	for(int i=1;i<=m;++i)
	{
		int x=read();
		char ch[3];
		cin>>ch;
		if(ch[0]=='A')
			vis[x]=1;
		else if(!vis[x])
			++cnt[x];
	}
	for(int i=1;i<=n;++i)
		if(vis[i])
			++ac,wa+=cnt[i];
	cout<<ac<<' '<<wa;
    return 0;
}


Measured memory_bytes: 1024
# -*- coding: utf-8 -*-
# 
import math
import sys
import itertools
import numpy as np

# いっこ入力
n =int(input())

# 空白区切りの数列をリストに代入
a = list(input())
b = list(input())
c = list(input())
answer = 0
for i in range(n):
    p = 0
    if a[i] == b[i]:
        p += 1
    if b[i] == c[i]:
        p += 1
    if c[i] == a[i]:
        p += 1
    if p == 0:
        answer += 2
    if p == 1:
        answer += 1
print(answer)



Measured memory_bytes: 21656
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
//const ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
const ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divceil(ll A, ll B) {return (A + (B - 1)) / B;}
ll myctoi(char C) {return C - '0';}
char myitoc(ll N) {return '0' + N;}
#define FINALANS(A) {cout << (A) << '\n'; exit(0);}

class combination
{
public:
  vector<ll> fac, finv, inv;

  combination(ll M)
  {
    fac = vector<ll>(M, 1);
    finv = vector<ll>(M, 1);
    inv = vector<ll>(M, 1);

    for (ll i = 2; i < M; i++)
    {
      fac.at(i) = fac.at(i - 1) * i % MOD;
      inv.at(i) = MOD - inv.at(MOD % i) * (MOD / i) % MOD;
      finv.at(i) = finv.at(i - 1) * inv.at(i) % MOD;
    }
  }

  ll P(ll N, ll K)
  {
    if (N < K) return 0;
    if (N < 0 || K < 0) return 0;
    return fac.at(N) * finv.at(N - K) % MOD;
  }

  ll C(ll N, ll K)
  {
    if (N < K) return 0;
    if (N < 0 || K < 0) return 0;
    return fac.at(N) * (finv.at(K) * finv.at(N - K) % MOD) % MOD;
  }

  ll H(ll N, ll K)
  {
    return C(N + K - 1, K);
  }
};

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

  combination com(N * M);

  ll ans = 0;
  for (ll i = 0; i < N; i++)
  {
    for (ll j = 0; j < M; j++)
    {
      if (i != 0 && j != 0)
        ans += 2 * (N - i) * (M - j) * (i + j);
      else
        ans += (N - i) * (M - j) * (i + j);
      ans %= MOD;
    }
  }

  ans *= com.C(N * M - 2, K - 2);
  ans %= MOD;

  cout << ans << endl;
}

Measured memory_bytes: 4992
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCorder
{
	public class Program
	{
		static void Main(string[] args)
		{
			Scanner cin = new Scanner();
			int n = cin.Int();
			int[] a = cin.ArrayInt(n);
			double ans = 0;
			for (int i = 0; i < n; i++) {
				ans += 1.0 / a[i];
			}

			ans = 1 / ans;
			Console.WriteLine(ans);
		}
	}

	public class Scanner
	{
		private readonly char[] delimiter_ = new char[] { ' ' };
		private string[] buf_;
		private int index_;
		
		public Scanner()
		{
			buf_ = new string[0];
			index_ = 0;
		}

		public string Next()
		{
			if (index_ < buf_.Length) {
				return buf_[index_++];
			}

			string st = Console.ReadLine();
			while (st == "") {
				st = Console.ReadLine();
			}

			buf_ = st.Split(delimiter_, StringSplitOptions.RemoveEmptyEntries);
			if (buf_.Length == 0) {
				return Next();
			}

			index_ = 0;
			return buf_[index_++];
		}

		public int Int()
		{
			return int.Parse(Next());
		}
		public int[] ArrayInt(int N, int add = 0)
		{
			int[] Array = new int[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Int() + add;
			}
			return Array;
		}

		public long Long()
		{
			return long.Parse(Next());
		}

		public long[] ArrayLong(int N, long add = 0)
		{
			long[] Array = new long[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Long() + add;
			}
			return Array;
		}

		public double Double()
		{
			return double.Parse(Next());
		}

		public double[] ArrayDouble(int N, double add = 0)
		{
			double[] Array = new double[N];
			for (int i = 0; i < N; i++) {
				Array[i] = Double() + add;
			}
			return Array;
		}
	}
}


Measured memory_bytes: 13140
import java.util.Scanner;

class Main {

	public static final String LIGHT_FLY = "light fly";
	public static final String FLY = "fly";
	public static final String BANTAM = "bantam";
	public static final String FEATHER = "feather";
	public static final String LIGHT = "light";
	public static final String LIGHT_WELTER = "light welter";
	public static final String WELTER = "welter";
	public static final String LIGHT_MIDDLE = "light middle";
	public static final String MIDDLE = "middle";
	public static final String LIGHT_HEAVY = "light heavy";
	public static final String HEAVY = "heavy";

	public static void main(String[] args) {

		try (Scanner scanner = new Scanner(System.in)) {
			while (scanner.hasNextDouble()) {
				double weight = scanner.nextDouble();
				System.out.println(getWeightClass(weight));
			}
		}
	}

	private static String getWeightClass(double weight) {
		String weghitClass = null;

		if (weight <= 48.00) {
			weghitClass = "light fly";
		} else if (48.00 < weight && weight <= 51.00) {
			weghitClass = "fly";
		} else if (51.00 < weight && weight <= 54.00) {
			weghitClass = "bantam";
		} else if (54.00 < weight && weight <= 57.00) {
			weghitClass = "feather";
		} else if (57.00 < weight && weight <= 60.00) {
			weghitClass = "light";
		} else if (60.00 < weight && weight <= 64.00) {
			weghitClass = "light welter";
		} else if (64.00 < weight && weight <= 69.00) {
			weghitClass = "welter";
		} else if (69.00 < weight && weight <= 75.00) {
			weghitClass = "light middle";
		} else if (75.00 < weight && weight <= 81.00) {
			weghitClass = MIDDLE;
		} else if (81.00 < weight && weight <= 91.00) {
			weghitClass = "light heavy";
		} else {
			weghitClass = "heavy";
		}
		return weghitClass;
	}
}

Measured memory_bytes: 27980
n=int(input())

class Restaurant:
    def __init__(self,number,name,point):
        self.number=number
        self.name=name
        self.point=point
    def __lt__(self,other):
        if self.name<other.name:
            return True
        if self.name==other.name:
            if self.point>other.point:
                return True
        return False
    def __gt__(self,other):
        if self.name>other.name:
            return True
        if self.name==other.name:
            if self.point<other.point:
                return True
        return False
    
    
restaurantlist=[]
number=1
for i in range(n):
    name,point=input().split()
    point=int(point)
    restaurant=Restaurant(number,name,point)
    number+=1
    restaurantlist.append(restaurant)
    
restaurantlist.sort()
for i in restaurantlist:
    print(i.number)
    

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

int gcd(int x, int y)
{
	if (x%y == 0)
	{
		return y;
	}
	else
	{
		return gcd(y, x%y);
	}
}

int gcd_three(int a, int b, int c)
{
	return gcd(gcd(a, b), c);
}

int main()
{
	int k;
	cin >> k;
	
	int sum = 0;
	for (int a = 1; a <= k; ++a)
	{
		for (int b = 1; b <= k; ++b)
		{
			for (int c = 1; c <= k; ++c)
			{
				sum += gcd_three(a, b, c);
			}
		}
	}
	
	cout << sum << endl;
	
	return 0;
}


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

int main()
{
  int n, k, q;
  cin >> n >> k >> q;
  vector<int> a(q);
  vector<int> hito(n);
  for (int i = 0; i < q; i++)
  {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++)
  {
    hito[i] = k - q;
  }
  for (int i = 0; i < q; i++)
  {
    hito[a[i] - 1]++;
  }
  for (int i = 0; i < n; i++)
  {
    if (hito[i] > 0)
    {
      cout << "Yes" <<endl;
      continue;
    }
    else
      cout << "No" << endl;
  }
}

Measured memory_bytes: 1408
#include<stdio.h>
int MIN(int a,int b){return a<b?a:b;}
int main(){
  int a,b,c,d,n;
  scanf("%d %d %d %d %d",&a,&b,&c,&d,&n);
  if(c<n)b+=(n-c)*d;
  printf("%d\n",MIN(a*n,b));
  return 0;
}

Measured memory_bytes: 596
#include"bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=1;i<=n;i++)
const long long mod = 1000000007;
const long long inf = 11451419198109130;
typedef pair<int, int> P;
typedef pair<P, int> PP;
typedef pair<int, PP> PPP;
struct edge { int to; int to2; int cost; };

signed main() {
	int n, a, b, c, d, e; cin >> n >> a >> b >> c >> d >> e;
	int m = min({ a,b,c,d,e });
	cout << (n + m - 1) / m + 4 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl
#define svec(v) cout<<#v<<":";rep(pachico,v.size())cout<<" "<<v[pachico];cout<<endl
#define svecp(v) cout<<#v<<":";each(pachico,v)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(pachico,s)cout<<" "<<pachico;cout<<endl
#define smap(m) cout<<#m<<":";each(pachico,m)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 100005;

vector<int> G[MAX_N];

bool dfs(int u, int p, int t, vi& route)
{
    if(u == t) return true;
    each(v,G[u]){
        if(v != p){
            route.pb(v);
            if(dfs(v, u, t, route)) return true;
            route.pop_back();
        }
    }
    return false;
}

void dfs(int u, int p, int& cnt){
    cnt++;
    each(v,G[u]){
        if(v != p){
            dfs(v, u, cnt);
        }
    }
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    rep(i,n-1){
        int u,v;
        cin >> u >> v;
        G[u-1].pb(v-1), G[v-1].pb(u-1);
    }
    int cnt = 0;
    vi route = {0};
    dfs(0, -1, n-1, route);
    rep(i,(len(route)+1)/2){
        int hoge = 1;
        int cand1 = -1, cand2 = -1;
        if(i >= 1){
            cand1 = route[i-1];
        }
        if(i < len(route)-1){
            cand2 = route[i+1];
        }
        each(v, G[route[i]]){
            if(v != cand1 && v != cand2){
                dfs(v, route[i], hoge);
            }
        }
        cnt += hoge;
    }
    if(cnt > n/2){
        cout << "Fennec\n";
    }else{
        cout << "Snuke\n";
    }
    return 0;
}

Measured memory_bytes: 12536
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
using namespace std;

int Solve(vector<int>& a)
{
    if (count(a.begin(), a.end(), 0) == a.size())
        return 0;
    int n = a.size();
    vector<int> fact(n);
    for (int i = 2; i < n; i += 2)
        fact[i] = fact[i / 2] + 1;
    partial_sum(fact.begin(), fact.end(), fact.begin());
    bool odd = false;
    for (int i = 0; i < n; ++i)
        if (fact[n - 1] - fact[n - 1 - i] - fact[i] == 0 && a[i] % 2)
            odd ^= 1;
    if (odd)
        return 1;
    else if (count(a.begin(), a.end(), 1))
        return 0;
    else {
        for (int& i: a)
            if (i) i = 1;
        return Solve(a) ? 2 : 0;
    }
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n;
    cin >> n;
    string b;
    cin >> b;
    vector<int> a(n - 1);
    for (int i = 0; i < n - 1; ++i)
        a[i] = abs(b[i + 1] - b[i]);
    cout << Solve(a);
}


Measured memory_bytes: 16120
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<(n);i++)
#define MOD 1000000007
#define all(n) (n).begin(),(n).end()
typedef long long ll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}else{return 0;}}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}else{return 0;}}
template <class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <class T> inline T LCM(T a,T b){return a*b/GCD(a,b);}

int main(){
	ll h;
	cin >> h;
	ll cnt=0;
	while(h){
		h/=2;
		cnt++;
	}
	cout << (1ll<<cnt)-1 << endl;
}

Measured memory_bytes: 256