akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <bitset>
#include <iostream>
#include <string>
#include <stack>
#include <queue>
using namespace std;

class Data
{
public:
    int g;
    int e;
    Data(){
        g = e = -1;
    }
    Data(int g0, int e0){
        g = g0;
        e = e0;
    }
    bool operator<(const Data& d) const{
        return g < d.g || (g == d.g && e < d.e);
    }
};

bool check[32][32][33][33];
Data memo[32][32][33][33];

Data solve(int y, int x, int h, int w, int s)
{
    if(check[y][x][h][w])
        return memo[y][x][h][w];

    int tmp = 0;
    for(int i=y; i<y+h; ++i){
        for(int j=x; j<x+w; ++j){
            tmp += memo[i][j][1][1].e;
        }
    }
    if(tmp < s)
        return Data();

    Data ret(1, tmp);
    for(int i=1; i<h; ++i){
        Data d1 = solve(y, x, i, w, s);
        Data d2 = solve(y+i, x, h-i, w, s);
        if(d1.g == -1 || d2.g == -1)
            continue;
        Data d3(d1.g + d2.g, min(d1.e, d2.e));
        ret = max(ret, d3);
    }
    for(int i=1; i<w; ++i){
        Data d1 = solve(y, x, h, i, s);
        Data d2 = solve(y, x+i, h, w-i, s);
        if(d1.g == -1 || d2.g == -1)
            continue;
        Data d3(d1.g + d2.g, min(d1.e, d2.e));
        ret = max(ret, d3);
    }

    check[y][x][h][w] = true;
    memo[y][x][h][w] = ret;
    return ret;
}

int main()
{
    for(;;){
        int h, w, s;
        cin >> h >> w >> s;
        if(h == 0)
            return 0;

        for(int i=0; i<32; ++i){
            for(int j=0; j<32; ++j){
                for(int k=0; k<33; ++k){
                    for(int l=0; l<33; ++l){
                        check[i][j][k][l] = false;
                        memo[i][j][k][l] = Data();
                    }
                }
            }
        }

        for(int i=0; i<h; ++i){
            for(int j=0; j<w; ++j){
                memo[i][j][1][1].g = 1;
                cin >> memo[i][j][1][1].e;
                s -= memo[i][j][1][1].e;
            }
        }
        s *= -1;

        Data d = solve(0, 0, h, w, s);
        cout << d.g << ' ' << (d.e-s) << endl;
    }
}

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

#define TRACE(x) x
#define WATCH(x) TRACE(cout << #x" = " << x << endl)
#define WATCHR(a, b) TRACE(for (auto it=a; it!=b;) cout << *(it++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})

#define all(x) (x).begin(), (x).end()

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<string> vs;

pair<int, int> go(auto &pts) {
    vvi ct(600, vi(600));
    for (auto p : pts) {
        int y = p[1];
        int x = p[0];
        ct[y][x]++;
    }
    for (int y = 0; y < 600; y++) {
        for (int x = 1; x < 600; x++) {
            ct[y][x] += ct[y][x-1];
        }
    }

    auto get_ct = [&](int x0, int x1, int y) {
        if (y < 0 || y >= 600) return 0;
        x0 = max(x0, 0);
        x1 = min(x1, 599);
        if (x0 > x1) return 0;
        int res = ct[y][x1];
        if (x0) res -= ct[y][x0-1];
        return res;
    };

    int r1 = 0, r2 = 0;
    for (auto p : pts) {
        int x1 = p[0];
        int y1 = p[1];
        for (int dist = 1; dist <= 600; dist++) {
            int x2 = x1 + dist;

            r1 += get_ct(x2, x2, y1) *
                  ( get_ct(x1+1, x2-1, y1 - dist)
                  + get_ct(x1+1, x2-1, y1 + dist));
            r2 += get_ct(x2, x2, y1) *
                  ( get_ct(x1, x1, y1 - dist)
                  + get_ct(x1, x1, y1 + dist) );
            r2 += get_ct(x2, x2, y1) *
                  ( get_ct(x2, x2, y1 - dist)
                  + get_ct(x2, x2, y1 + dist));
        }
    }
    return { r1, r2 };
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    cout << fixed << setprecision(15);

    int R, C;
    cin >> R >> C;

    vector<array<int, 2>> p1, p2;
    for (int r = 0; r < R; r++) {
        string row;
        cin >> row;
        for (int c = 0; c < C; c++) {
            if (row[c] == '#') {
                p1.push_back({ r + c, r + 300 - c });
                p2.push_back({ r + 300 - c, r + c });
            }
        }
    }

    auto r1 = go(p1), r2 = go(p2);
    cout << r1.first + r2.first + r1.second << endl;
    return 0;
}



Measured memory_bytes: 3052
local mce, mfl, msq, mmi, mma, mab = math.ceil, math.floor, math.sqrt, math.min, math.max, math.abs
local mod = 1000000007
local function bmul(x, y)
  local x1, y1 = mfl(x / 31623), mfl(y / 31623)
  local x0, y0 = x - x1 * 31623, y - y1 * 31623
  return (x1 * y1 * 14122 + (x1 * y0 + x0 * y1) * 31623 + x0 * y0) % mod
end
local function badd(x, y)
  return (x + y) % mod
end

local function bsub(x, y)
  return x < y and x - y + mod or x - y
end

local function modpow(src, pow)
  local res = 1
  while 0 < pow do
    if pow % 2 == 1 then
      res = bmul(res, src)
      pow = pow - 1
    end
    src = bmul(src, src)
    pow = mfl(pow / 2)
  end
  return res
end

local n, k = io.read("*n", "*n")
local ret = 0

local primecnt = {}
local t = {}
for i = 1, k do t[i] = 0 end
for i = k, 1, -1 do
  local c = mfl(k / i)
  local z = modpow(c, n)
  for j = 2, c do
    z = bsub(z, t[j * i])
  end
  t[i] = z
  ret = badd(ret, bmul(i, z))
end
print(ret)


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

int main(){
    int H, W, h, w;
    cin >> H >> W;
    int A[H][W], B[H][W];
    for(int i = 0; i < H*W; i++)    cin >> A[i/W][i%W];
    for(int i = 0; i < H*W; i++)    cin >> B[i/W][i%W];
    cin >> h >> w;
    int C[h][w];
    for(int i = 0; i < h*w; i++)    cin >> C[i/w][i%w];
    int ans = -1e9;
    for(int i = 0; i <= H-h; i++){
        for(int j = 0; j <= W-w; j++){
            int match = 0, tmp = 0;
            for(int ni = 0; ni < h; ni++){
                for(int nj = 0; nj < w; nj++){
                    match += (B[i+ni][j+nj]==C[ni][nj]);
                    tmp += A[i+ni][j+nj];
                }
            }
            if(match == h*w)    ans = max(ans, tmp);
        }
    }
    if(ans == -1e9) cout << "NA" << endl;
    else            cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3156
{-# LANGUAGE CPP #-}
{-# LANGUAGE ViewPatterns #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE OverloadedStrings #-}

import qualified Data.ByteString.Char8 as S
import Data.Monoid

main :: IO ()
main = do
  (S.lines -> [S.words -> [S.unpack -> read -> (i0 :: Int)]]) <- S.getContents
  print (111 + (999 - i0))


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

class UnionFind {
  vector<int> P, S;
public:
  UnionFind(int n) : P(n), S(n, 1) {
    iota(P.begin(), P.end(), 0);
  }
  int root(int x) {
    if (P.at(x) == x) return x;
    else return P.at(x) = root(P.at(x));
  }
  void unit(int x,int y) {
    x = root(x), y = root(y);
    if (x == y) return;
    if (S.at(x) < S.at(y)) swap(x, y);
    P.at(y) = x;
    S.at(x) += S.at(y);
  }
  int size(int x) {
    x = root(x);
    return S.at(x);
  }
  bool same(int x, int y) {
    return root(x) == root(y);
  }
};

int main() {
  int N, M;
  cin >> N >> M;
  UnionFind UF(N);
  for (int i = 0; i < M; i++) {
    int A, B;
    cin >> A >> B;
    A--, B--;
    UF.unit(A, B);
  }
  int mx = 0;
  for (int i = 0; i < N; i++) {
    mx = max(mx, UF.size(i));
  }
  cout << mx << "\n";
}

Measured memory_bytes: 4820
#include <iostream>
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
using namespace std;
int main(void){

  int result = 0;
  char P[4] = {'0','0','0','0'};
  char A[4] = {'0','0','0','0'};

  REP(i,3)cin >> P[i];
  REP(i,3)cin >> A[i];

  REP(i,3)if(P[i] == A[i])result++;

  cout << result << endl;
  return 0;
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

int n;
vvl dp;
vl a;

ll Rec(int l,int r){
	if(dp[l][r]>=0) return dp[l][r];
	if(l+1==r) return dp[l][r]=0;
	ll t=INF;
	for(int i=l+1;i<r;i++) t=min(t,Rec(l,i)+Rec(i,r));
	for(int i=l;i<r;i++) t+=a[i];
	return dp[l][r]=t;
}

int main(){
	cin>>n;
	dp=vvl(n+1,vl(n+1,-1));
	a=vl(n);
	for(auto &i:a) cin>>i;
	cout<<Rec(0,n)<<endl;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T> void assign(V<T>& v, int n, const T& a = T()) { v.assign(n, a); }
template<class T, class... U> void assign(V<T>& v, int n, const U&... u) { v.resize(n); for (auto&& i : v) assign(i, u...); }

int main() {
  cin.tie(NULL); ios::sync_with_stdio(false);
  int n, m, k; cin >> n >> m >> k;
  V<> l(m), r(m); for (int i = 0; i < m; i++) cin >> l[i] >> r[i];
  V<> p(k), q(k); for (int i = 0; i < k; i++) cin >> p[i] >> q[i];
  VV<> a; assign(a, n + 1, n + 1);
  for (int i = 0; i < m; i++) for (int j = 1; j <= l[i]; j++) a[j][r[i]]++;
  for (int i = 1; i <= n; i++) {
    for (int j = i; j < n; j++) a[i][j + 1] += a[i][j];
  }
  for (int i = 0; i < k; i++) cout << a[p[i]][q[i]] << '\n';
}

Measured memory_bytes: 4352
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 998244353

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N,num):
    if N<=0:
        return [[]]*num
    elif num==1:
        return [I() for _ in range(N)]
    else:
        read_all = [tuple(II()) for _ in range(N)]
        return map(list, zip(*read_all))

#################

N = I()
D = III()

if D[0]!=0:
    print(0)
    exit()

count = [0]*(N+1)
for i in range(N):
    count[D[i]] += 1

if count[0]>=2:
    print(0)
    exit()

for i in range(N+1)[::-1]:
    if count[-1]==0:
        count.pop()
    else:
        break

ans = 1
for i in range(1,len(count)):
    ans *= count[i-1]**count[i]
    ans %= mod

print(ans)

Measured memory_bytes: 55340
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N,H;
    cin >> N >> H;
    vector<P> V(N);
    int maxi = 0;
    rep(i,0,N){
        int a,b;
        cin >> a >> b;
        V[i] = P(b,a);
        maxi = max(maxi, a);
    }
    sort(V.rbegin(), V.rend());
    ll cnt = 0;
    rep(i,0,N){
        if(V[i].first < maxi)break;
        H -= V[i].first;
        cnt++;
        if(H <= 0)break;
    }
    if(H > 0)cnt += (H + maxi - 1) / maxi;
    cout << cnt << endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define eps 1e-6
#define ll long long
#define IOS cin.sync_with_stdio(false);cin.tie(0);cout.tie(0);
//#define int long long
#define MEM(x,y) memset(x,y,sizeof(x))
#define rep(i,a,n) for (int i=a;i<n;i++)
#define fi first
#define se second
#define endl "\n"
#define pii pair<int,int>
#define fi first
#define se second
const ll mod=1000000007;
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;
ll Max(ll a,ll b){return a>=b?a:b;}
ll Min(ll a,ll b){return a<=b?a:b;}
ll qpow(ll a,ll b){ll s=1;while(b>0){if(b%2==1){s=s*a;}a=a*a;b=b>>1;}return s;}
ll qpowmod(ll a, ll b, ll c){ll res,t;res=1;t=a%c;while(b){if(b&1){res=res*t%c;}t=t*t%c;b>>=1;}return res;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline long long read(){long long k=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){k=k*10+ch-'0';ch=getchar();}return k*f;}
inline void write(long long x){if(x<0)x=-x,putchar('-');if(x>9)write(x/10);putchar(x%10+'0');}
using namespace std;
//head file
int main()
{
    int l,r,d;
    cin>>l>>r>>d;
    int cnt=0;
    rep(i,l,r+1)
    {
        if(i%d==0)
          cnt++;

    }
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 3628
a,b,n=map(int,input().split())

ans=-float("inf")
i=0

while True:
    x=b*i-1
    i+=1
    if x>n:
        ans=max(int((a*n)/b)-a*int(n/b), ans)
        print(ans)
        break
    if ans<int((a*x)/b)-a*int(x/b):
        ans=int((a*x)/b)-a*int(x/b)
    else:
        print(ans)
        break

Measured memory_bytes: 9200
N = int(input())
MAX_N = int(1e5) + 2
acc = [0] * (MAX_N + 1)
acc[0] += 1
acc[MAX_N] -= 1
for _ in range(N):
    a, b = map(int, input().split())
    acc[a] += 1
    acc[b + 1] -= 1
for i in range(MAX_N):
    acc[i + 1] += acc[i]
for i in reversed(range(MAX_N)):
    if acc[i] >= i:
        print(i - 1)
        break

Measured memory_bytes: 11400
/* 
	Author: ankrypt
*/


#include <bits/stdc++.h>

using namespace std;

#define MOD 1000000007
#define ll long long int
#define u64 unsigned long long int
#define ff first
#define ss second
#define MAX_INT 15

ll N, M, A, B, C;
ll arr[MAX_INT];
vector<ll> V;
ll mat[3][3];
ll marked[3][3];


int main() {
	for(int i = 0; i < 3; i++) {
		for(int j = 0; j < 3; j++) {
			scanf("%lld", &mat[i][j]);
		}
	}	
	scanf("%lld", &N);
	for(int i = 0; i < N; i++) {
		scanf("%lld", &arr[i]);
	}
	for(int k = 0; k < N; k++) {
		for(int i = 0; i < 3; i++) {
			for(int j = 0; j < 3; j++) {
				if(mat[i][j] == arr[k]) {
					marked[i][j] = 1;
					break;
				}
			}
		}
	}
	for(int i = 0; i < 3; i++) {
		int cnt = 0;
		for(int j = 0; j < 3; j++) {
			if(marked[i][j]) {
				cnt++;
			}
		}
		if(cnt == 3) {
			printf("Yes\n");
			exit(0);
		}
	}
	for(int i = 0; i < 3; i++) {
		int cnt = 0;
		for(int j = 0; j < 3; j++) {
			if(marked[j][i]) {
				cnt++;
			}
		}
		if(cnt == 3) {
			printf("Yes\n");
			exit(0);
		}
	}
	if((marked[0][0] && marked[1][1] && marked[2][2]) || (marked[2][0] && marked[1][1] && marked[0][2])) {
		printf("Yes\n");
		exit(0);
	}
	printf("No\n");
	return 0;
}
/*
	Powered by Buggy Plugin
*/


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

int main(){
    string str;

    cin >> str;

    if(str[0] == 'a' || str[0] == 'i' || str[0] == 'u' || str[0] == 'e' || str[0] == 'o'){
        cout << "vowel\n";
    }
    else{
        cout << "consonant\n";
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define forn(i, s, t) for (int i = s ; i < (int)t ; i++)
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define pf2(x,y) printf("%d %d\n",x,y)
#define pf(x) printf("%d\n",x)
#define each(x) for(auto it:x)  cout<<it<<endl;
#define pi pair<int,int>
#define pb push_back
#define sc(x) scanf("%d",&x)
#define sc2(x,y) scanf("%d%d",&x,&y)
#define pf(x) printf("%d\n",x)
#define pf2(x,y) printf("%d %d\n",x,y)
#define mem(a,x) memset(a,x,sizeof(a))
#define copy(b,a) memcpy(a,b,sizeof(a))
#define SZ(x) (int)x.size()
#define VI vector<int>
#define VII vector<pair<int,int>>
#define PI pair<int,int>
using namespace std;
typedef long long ll;
ll qpow(ll x,ll y,ll p){ll ans=1;for(x%=p;y;y>>=1,x=x*x%p)if(y&1) ans=ans*x%p;return ans;}
ll inv(ll x,ll p){return x<=1?1:(p-p/x)*inv(p%x,p)%p;}
ll sqrt2(ll x){ll l=1,r=2e9;while(l<r){ll mid=(l+r+1)>>1;if(mid*mid<=x) l=mid;else r=mid-1;}return l;}
ll sqrt3(ll x){ll y=(ll)(powl((long double)x,1.0/3.0)+0.5);while(y*y*y<x) y++;while(y*y*y>x) y--;return y;}
ll comb(ll n,ll m,ll p){if(m>n||n<0) return 0;if(m>n-m) m=n-m;ll ans=1;for(int i=1;i<=m;i++)ans=ans*n%p,ans=ans*inv(i,p),n--;return ans;}
ll comb(ll n,ll m){if(m>n||n<0) return 0;if(m>n-m) m=n-m;ll ans=1;for(int i=1;i<=m;i++)ans=ans*n,ans/=i,n--;return ans;}
ll ceil(ll x,ll y){return (x+y-1)/y;}
int lowerbit(int x) {return x&-x;}
int HighBit(int x){for(int i=30;i>=0;i--)if(x>>i&1) return i;}
const int maxn=2e5+5;
int A[maxn],B[maxn],n;
 
int main(){
	sc(n);
	for(int i=1;i<=n;i++){
		sc2(A[i],B[i]);
	}	
	sort(A+1,A+n+1);
	sort(B+1,B+n+1);
	if(n&1) {
		cout<<B[(n+1)/2]-A[(n+1)/2]+1;
	}
	else {
		cout<<B[n/2]+B[n/2+1]-A[n/2]-A[n/2+1]+1;
	}
}

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

#define pb push_back
#define ll long long
#define maxn 100005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define F first
#define S second
const ll mod =1e9+7;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll n;
    cin >> n;
    n--;
    cout<<(1+n)*n/2<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int bun_kai(int x, int k){
    if(k == 4){
        return x / 10000;
    }else if(k == 3){
        return (x % 10000) / 1000;
    }else if(k == 2){
        return (x % 1000) / 100;
    }else if(k == 1){
        return (x % 100) / 10;
    }else {
        return x % 10;
    }
}
int main(void){
    int N, A, B = 0;
    scanf("%ld %ld %ld", &N, &A, &B);
    int sum = 0;
    for(int n = 1; n <= N; n++){
        int degit[5] = {0};
        int subsum = 0;
        for(int i = 4; i >= 0; i--){
            degit[i] = bun_kai(n, i);
            subsum += degit[i];
        }

        if(subsum >= A && subsum <= B){
            sum += n;
        }
    }
    printf("%d\n", sum);
    return 0;
}

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

const int INF=INT_MAX/2;

int main(){
  int N; cin>>N;
  if(N<6){
    cout<<N<<endl;
    return 0;
  }
  int x=6;
  vector<int> V;
  while(x<=N){
    V.push_back(x);
    x*=6;
  }
  x=9;
  while(x<=N){
    V.push_back(x);
    x*=9;
  }
  sort(V.rbegin(),V.rend());
  int n=V.size();
  int dp[n+1][N+1];
  rep(i,n+1) rep(j,N+1) dp[i][j]=INF;
  dp[0][0]=0;
  rep(i,n) rep(j,N+1) if(dp[i][j]!=INF){
    dp[i+1][j]=min(dp[i+1][j],dp[i][j]);
    for(int k=1;j+k*V[i]<=N;k++){
      dp[i+1][j+k*V[i]]=min(dp[i+1][j+k*V[i]],dp[i][j]+k);
    }
  }
  int ans=INF;
  rep(i,N+1) ans=min(ans,dp[n][i]+(N-i));
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 4992
import std.stdio;
import std.ascii;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.regex;
import std.typecons;

struct Point {
    double y, x;
    Point opBinary(alias op)(in Point a) const {
        return Point(mixin("y" ~ op ~ "a.y"), mixin("x" ~ op ~ "a.x"));
    }
    Point opBinary(alias op)(double a) const {
        return Point(mixin("y" ~ op ~ "a"), mixin("x" ~ op ~ "a"));
    }
}

void main() {
    Point[] P = new Point[3];

    bool input() {
        scanf("%lf %lf %lf %lf %lf %lf\n", &P[0].x, &P[0].y, &P[1].x, &P[1].y, &P[2].x, &P[2].y);
        if (P[0 .. 3].all!"a.y == 0 && a.x == 0") return false;
        return true;
    }
    size_t next(size_t n) {
        return (n + 1) % 3;
    }
    double distance2D(in Point a, in Point b) {
        double dx = a.x - b.x,
               dy = a.y - b.y;
        return sqrt(dx * dx + dy * dy);
    }
    void solve() {
        double L0 = distance2D(P[0], P[1]);
        double L1 = distance2D(P[0], P[2]);
        double L2 = distance2D(P[1], P[2]);
        double theta = acos( (L0 * L0 + L1 * L1 - L2 * L2) / (2 * L0 * L1) ) / 2;
        double theta1 = acos( (L2 * L2 + L0 * L0 - L1 * L1) / (2 * L2 * L0) ) / 2;
        double theta2 = acos( (L1 * L1 + L2 * L2 - L0 * L0) / (2 * L1 * L2) ) / 2;
        double r1, r2;
        bool C(double R) {
            double a = (L0 - R / tan(theta)) / tan(theta1) + R;
            r1 = ((sqrt(a) - sqrt(R)) * tan(theta1)) ^^ 2;
            a = (L1 - R / tan(theta)) / tan(theta2) + R;
            r2 = ((sqrt(a) - sqrt(R)) * tan(theta2)) ^^ 2;
            double d = L2 - (r1 / tan(theta1)) - (r2 / tan(theta2));
            //writeln([R, r1, r2], [d]);
            if (d < 0) return false;
            return d ^^ 2 + (r1 - r2) ^^ 2 >= (r1 + r2) ^^ 2;
        }
        double area = L0 * L1 * sin(theta * 2) / 2;
        double lb = 0, ub = area * 2 / (L0 + L1 + L2);
        foreach (_; 0 .. 100) {
            double mid = (lb + ub) / 2;
            //writeln("[lb, ub]:", [lb, ub]);
            if (C(mid)) {
                ub = mid;
            } else {
                lb = mid;
            }
        }
        C(lb);
        writefln("%.10f %.10f %.10f", lb, r1, r2);
    }
    while (input) solve;
}

Measured memory_bytes: 1164
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
const int maxn=105;
int H,W,N;
int a[maxn][maxn];
int main(){
    int ans=0;
    scanf("%d%d%d",&H,&W,&N);
    int x=max(H,W);
    if(N%x)
        ans=N/x+1;
    else
    {
        ans=N/x;
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define ll long long
#define pb push_back
#define mp make_pair
bool isPrime(ll n) 
{ 
    
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
   
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (ll i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
} 
int minthis(int a, int b){
if(a < b){
return a;
}
return b;
}
int maxthis(int a, int b){
if(a > b){
return a;
}
return b;
}
int gcd(int a, int b){
    if( a<0 ) a = -a;
    if( b<0 ) b = -b;
    while( b!=0 ){
        a %= b;
        if( a==0 ) return b;
        b %= a;
    }
    return a;
}
 
int findLargestDivisor(int n) 
{ 
	int max = 1;
    for (int i = 2; i < n; i++) {        
        if(n %(i) == 0) { 
            max = i;
        } 
    }
    return max;     
} 
 
 
ll power(ll x, ll y)  
{  
    ll temp;  
    if(y == 0)  
        return 1;  
    temp = power(x, y / 2);  
    if (y % 2 == 0)  
        return temp * temp;  
    else
    {  
        if(y > 0)  
            return x * temp * temp;  
        else
            return (temp * temp) / x;  
    }  
}  
 /*
const int mxN = 200005;
int father[mxN] = {}, level[mxN] = {}, subtree[mxN] = {}, count_sons[mxN] = {};vector<int> e[mxN];priority_queue<pair<int,int>> pq; 
 
 
void dfs(int node, int fr){
	father[node] = fr;
	for(auto x : e[node]){
		if(x != fr){
			count_sons[node]++;
			level[x] = level[node]+1;
			dfs(x,node);
		}
	}
	if(count_sons[node] == 0){
		
		pq.push({node, level[node]});
		cout << node << endl;
	}
} 
	
 */
 
const int mxN = 2e5;
vector<int> arr[mxN];
void solve(){	
	int n,k;
	cin >> n >> k;
	vector<int> v;
	for(int i = 0 ; i < n ; i++){
		int x;cin  >> x;
		v.pb(x);
	}
	int ans = 0;
	sort(v.begin() , v.end());
	for(int i = 0 ; i < k ;i++){
		ans += v[i];
	}
	cout << ans << "\n";
}
  
int main(){ 
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t = 1;    
    //cin >> t;
    while(t--){
		solve();
	}
    return 0; 
}


Measured memory_bytes: 8168
using System;


namespace ConsoleApp9
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ');
            int a = int.Parse(input[0]);
            int b = int.Parse(input[1]);
            if(a > b){
                Console.WriteLine("a > b");
            }
            else if(a < b)
            {
                Console.WriteLine("a < b");
                            }
            else
            {
                Console.WriteLine("a == b");
            }
            Console.ReadKey();
        }
    }
}

Measured memory_bytes: 8944
#include <bits/stdc++.h>
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define pb push_back
#define ALL(s) s.begin(),s.end()
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define SZ(s) int(s.size())
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;

int main(){FIN;
	int n; cin>>n;
	int ans=0;
	fore(i,0,n){
		int x; cin>>x;
		ans+=x%2&&i%2==0;
	}
	cout<<ans<<"\n";
}

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

int main()
{
    string a, b;
    cin >> a >> b;
    if (a.size() < b.size())
        cout << "LESS" << endl;
    else if (a.size() > b.size())
        cout << "GREATER" << endl;
    else if (a == b)
        cout << "EQUAL" << endl;
    else
    {
        if (a < b)
            cout << "LESS" << endl;
        else
            cout << "GREATER" << endl;
    }
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {

	public static void main(String[] args) {
		Main ans = new Main();
		System.out.println(ans.solve());
	}

	private long solve() {

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();		 
		long [] array = new long[N+1];
		for(int i=1;i<=N;i++) {
			array[i] = sc.nextLong();
		}
		long[][]sum = preprocess(array, N);
		long [][] dp = new long[500][500];
		return solve(dp, array, 1, N, sum);
	}

	private long solve(long[][]dp, long[]array, int start, int end, long[][] sum) {
		if (start==end) return 0;
		if (dp[start][end]!=0) return dp[start][end];
		long bestSlime= (long) (1e15);
		for(int k=start;k<end;k++){
			long combine = solve(dp, array, start, k, sum) + solve(dp, array, k+1, end, sum) + sum[start][end];
			bestSlime = Math.min(bestSlime, combine);
		}
		dp[start][end] = bestSlime;
		return bestSlime;
	}

	private long [][] preprocess(long[] array, int N ) {
 
		long[][] sum = new long[N+1][N+1];
		for(int i=1;i<=N;i++){
			for(int j=i;j<=N;j++){
				sum[i][j] = array[j] + ((j==i) ? 0: sum[i][j-1]);
			}
		}
		return sum;

	}
}

Measured memory_bytes: 40924
import java.util.Scanner;

public class Main 
{

	public static void main(String[] args) 
	{
		Scanner sc = new Scanner(System.in);
		while(true)
		{
			int n = sc.nextInt();
			if(n == 0)return;
			int[] x = new int[n];
			int[] y = new int[n];
			int x1 = 0;
			int x2 = 0;
			int y1 = 0;
			int y2 = 0;
			
			x[0] = 0;
			y[0] = 0;
			
			for(int i = 1; i < n; i++)
			{
				int sq1 = sc.nextInt();
				int dir = sc.nextInt(); //left down right up
				
				if(dir == 0)
				{
					x[i] = x[sq1] - 1;
					y[i] = y[sq1];
				}
				else if(dir == 1)
				{
					x[i] = x[sq1];
					y[i] = y[sq1]+1;
				}
				else if(dir == 2)
				{
					x[i] = x[sq1]+1;
					y[i] = y[sq1];
				}
				else if(dir == 3)
				{
					x[i] = x[sq1];
					y[i] = y[sq1]-1;
				}
					
				x1 = Math.min(x1, x[i]);
				x2 = Math.max(x2, x[i]);
				y1 = Math.min(y1, y[i]);
				y2 = Math.max(y2, y[i]);
			}
			
			int w = x2-x1+1;
			int h = y2-y1+1;
			System.out.println(w + " " + h);
		}
	}

}



Measured memory_bytes: 42184
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;



int main()
{
    int m, d;
    cin >> m >> d;


    int count = 0;
    for (size_t i = 1; i <= m; i++)
    {
        for (size_t j = 1; j <= d; j++)
        {
            int d10 = j / 10;
            int d1 = j % 10;
            if (i == d10 * d1 && d10 >= 2 && d1 >= 2)
            {
                //cout << i << "/" << d10 << d1 << endl;
                count++;
            }
        }
    }
    cout << count << endl;
    return 0;
}




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

namespace ABC
{
    class Program
    {
        static void Main(string[] args)
        {
            ABC124_C();
        }

        static void ABC124_C()
        {
            var S = Console.ReadLine().ToArray();
            var count = 0;
            for (var i = 1; i < S.Length; i++)
            {
                if (S[i - 1] == S[i])
                {
                    count++;
                    S[i] = S[i] == '1' ? '0' : '1';
                }
            }
            Console.WriteLine(count);
        }
    }
}

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

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

  string S; cin >> S;
  string T; cin >> T;

  vector<int> al[26];
  for (ll i = 0; i < T.size(); i++) {
    int temp = T[i] - 'a';
    al[temp].emplace_back(i);
  }

  ll INF = 1e8;
  vector<string> ans(3010, ""), ans2(3010, "");
  vector<int> pos(3010, INF), pos2(3010, INF);

  for (ll i = 0; i < S.size(); i++) {
    pos[0] = pos2[0] = -1;
    char c = S[i];
    ll p = c - 'a';
    for (ll j = 0; j <= i; j++) {
      ll s = pos2[j];
      if (s == INF) break;
      s++;
      auto it = lower_bound(al[p].begin(), al[p].end(), s);
      if (it != al[p].end()) {
        if (*it < pos2[j + 1]) {
          pos[j + 1] = *it;
          ans[j + 1] = ans2[j] + c;
        }
      }
    }
    // for (ll j = 0; j < 10; j++) {
    //   cout << pos[j] << " ";
    //   cout << ans[j] << " ";
    // }
    // cout << '\n';
    pos2 = pos;
    ans2 = ans;
  }

  for (ll i = 3000; i >= 0; i--) {
    string temp = ans[i];
    if (temp != "") {
      cout << temp << '\n';
      return 0;
    }
  }
  cout << "" << '\n';
  return 0;
}

Measured memory_bytes: 7808
#include <iostream>
int main(){
    int a,b;
    while(1){
    std::cin>>a>>b;
    if(a==0&&b==0) break;
    if(a<=b)std::cout<<a<<" "<<b<<std::endl;
    else std::cout<<b<<" "<<a<<std::endl;
    }
    return 0;
}


Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
const ll INF = 1e9;

void solver(int N, int  K, ll S, vector<ll> &ans){

    for(int i = 0; i < K; ++i){
        ans.at(i) = S;
    }
    if(S == (ll)1e9){
        for(int i = K; i < N; ++i){
            ans.at(i) = 1e9-1;
        }
    }
    return;
}

int main(){

    int N, K;
    ll S;
    cin >> N >> K >> S;

    vector<ll> ans(N, INF);
    solver(N, K, S, ans);

    for(int i = 0; i < N; ++i){
        cout << ans.at(i) << " "s;
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 4056
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect, bisect_left, bisect_right

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
L = input()
S = list(map(int, list(L)))

# print(S)
cnt = 0
# 000-999 1000
for i in range(0, 10):
    for j in range(0, 10):
        for k in range(0, 10):
            num = 0
            flag = False
            exist = [False] * 3
            while num != N and flag != True:
                # print(num)
                if exist[0] == False:
                    # print(S[num])
                    if S[num] != i:
                        num += 1
                    elif S[num] == i:
                        num += 1
                        exist[0] = True
                else:
                    if exist[1] == False:
                        if S[num] != j:
                            num += 1
                        elif S[num] == j:
                            num += 1
                            exist[1] = True
                    else:
                        if exist[2] == False:
                            if S[num] != k:
                                num += 1
                            elif S[num] == k:
                                num += 1
                                exist[2] == True
                                flag = True
            if flag == True:
                cnt += 1            
print(cnt)
                        
                

Measured memory_bytes: 80764
s = input()
t = input()

ls_s_1st = sorted(list(s))
ls_t_last = list(reversed(sorted(list(t))))

ls_org = ["".join(ls_s_1st), "".join(ls_t_last)]

ls_sort = sorted(ls_org)

if ls_org[0] == ls_sort[0] and ls_org[1] == ls_sort[1] and s != t:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
s=list(input())
k=int(input())
n=len(s)
x=[]
for i in range(n):
    x.append(s[i])
if n>=2:
    for i in range(n-1):
        z=s[i]+s[i+1]
        x.append(z)
if n>=3:
    for i in range(n-2):
        z=s[i]+s[i+1]+s[i+2]
        x.append(z)
if n>=4:
    for i in range(n-3):
        z=s[i]+s[i+1]+s[i+2]+s[i+3]
        x.append(z)
if n>=5:
    for i in range(n-4):
        z=s[i]+s[i+1]+s[i+2]+s[i+3]+s[i+4]
        x.append(z)
x=set(x)
x=sorted(x)
print(x[k-1])


Measured memory_bytes: 74948
N = int(input())
M = []
A = []
R = []
C = []
H = []

for i in range(N):
    temp = input()
    init_temp = list(temp)   
    if 'M' == init_temp[0]:
        M.append(temp)
    elif 'A' == init_temp[0]:
        A.append(temp)
    elif 'R' == init_temp[0]:
        R.append(temp)
    elif 'C' == init_temp[0]:
        C.append(temp)
    elif 'H' == init_temp[0]:
        H.append(temp)
    else:
        pass

M = len(list(set(M)))
A = len(list(set(A)))
R = len(list(set(R)))
C = len(list(set(C)))
H = len(list(set(H)))

D = [M, A, R, C, H]
#10通り書き出す
A = [0, 0, 0, 0, 0, 0, 1, 1, 1, 2]
B = [1, 1, 1, 2, 2, 3, 2, 2, 3, 3]
C = [2, 3, 4, 3, 4, 4, 3, 4, 4, 4]

ans = 0

for i in range(10):
    ans += D[A[i]] * D[B[i]] * D[C[i]]

print(ans)

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

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

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define what_is(x) cerr << #x << " is " << x << endl;
#define MT make_tuple
#define eb emplace_back
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

#define REP(i,a,b) for (int i = a; i <= b; i++)
#define FOR(i,n) for (int i=0;i < n ; i++)
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

int main(){
	ll x;
	cin >> x;
	x=abs(x);
	ll i=x;
	for(ll size=x; size > 0; size/=2){
		while(i-size >= 0 && (i-size)*(i-size+1) >= 2*x) i-=size;
	}
	cout << i;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e18;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

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

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}
int main()
{
    string A;
    cin >> A;

    ll length = A.size();
    map<char, ll> cnt;
    for (int i = 0; i < length; i++)
    {
        cnt[A[i]]++;
    }

    ll sum = 0;

    for (auto &&i : cnt)
    {
        sum += (i.second * (i.second - 1)) / 2;
    }

    cout << (length * (length - 1)) / 2 - sum + 1 << endl;
}


Measured memory_bytes: 640
//============================================================================
// Name        : Cpp.cpp
// Author      :
// Version     :
// Copyright   :
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <vector>
using namespace std;

int main() {
	int n = 0;
	vector<int> A(n);
	std::cin >> n;

	for(int i=0; i < n; i++)
	{
		int v;
		std::cin >> v;
		A.push_back(v);
	}

	int C[10001] = {0};
	vector<int> B(n, 0);

	for(int i=0; i < n; i++)
	{
		C[A[i]]++;
	}

	for(int i=1; i < 10001; i++)
	{
		C[i] += C[i - 1];
	}

	for(int i = n - 1; i >= 0; i--)
	{
		B[C[A[i]] - 1] = A[i];
		C[A[i]]--;
	}

	for(int i=0; i < n; i++)
	{
		if(i == n - 1) std::cout << B[i] << std::endl;
		else std::cout << B[i] << " ";
	}
	return 0;
}

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

int main()
{
    int n,m,x,a;
    int c[101] = {0};
    cin >> n >> m >> x;
    for (size_t i = 0; i < m; i++)
    {
        cin >> a;
        c[a] = 1;
    }
    
    int ans = 0;
    for (size_t i = x; i <= n; i++)
    {
        ans += c[i];
    }
    
    cout << min(ans,m - ans) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define ALL(x) (x).begin(), (x).end()
#define REP(i ,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back
typedef vector<int>vint;
typedef vector<ll>vll;
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int main()
{
    const ll INF = 1LL << 60;

    ll dp[100010];

    REP(i,100010)dp[i]=INF;

    dp[0] = 0;

    int N,K;
    cin >> N >> K;
    vint H(N);
    cin >> H;
    for(int i=1; i<N; i++){

        for(int j=1; (i-j) >= 0 && j <= K; j++){
            chmin(dp[i],dp[i-j] + abs(H[i] - H[i-j]));
        }

    }
    cout << dp[N-1] << endl;
}

Measured memory_bytes: 4528
ONE = '1'.freeze
MOD = 10 ** 9 + 7

def nCk(n, k)
  res = 1
  i = k
  j = 1
  while i > 0
    res = res * (n - i + 1)
    res %= MOD
    j *= i
    j %= MOD
    i -= 1
  end
  res *= inv(j)
  res %= MOD
  res
end

def inv(x)
  res = 1
  beki = x
  (MOD - 2).to_s(2).reverse.chars do |digest|
    res = (beki * res) % MOD if digest == ONE
    beki = (beki * beki) % MOD
  end
  res
end

# 繰り返し二乗法(MODを取る)
def modpow(base, exp, mod = 10 ** 9 + 7)
  if exp == 0
    1
  elsif exp.even?
    modpow(base, exp / 2, mod) ** 2 % mod
  else
    modpow(base, exp / 2, mod) ** 2 * base % mod
  end
end

n, a, b = gets.split.map(&:to_i)
ans = modpow(2, n) - 1 - nCk(n, a) - nCk(n, b)
2.times { ans += MOD if ans < 0 }
puts ans % MOD

Measured memory_bytes: 3836
def main():
    n, k = map(int, input().split())
    a = sorted([int(i) for i in input().split()], reverse=True)
    mod = 10**9 + 7
    p = 1
    if n == k:
        for ai in a:
            p = p * ai % mod
        print(p)
        return
    if a[0] < 0 and k % 2:
        for ai in a[:k]:
            p = p * ai % mod
        print(p)
        return
    b = sorted([(abs(ai), ai) for ai in a], reverse=True)
    s = 0
    for ba, bb in b[:k]:
        p = p * ba % mod
        if bb < 0:
            s += 1
    if s % 2 == 0:
        print(p)
        return
    pa, na, pb, nb = [-1] * 4
    for ba, bb in b[:k]:
        if bb < 0:
            na = ba
        else:
            pa = ba
    for ba, bb in b[k:][::-1]:
        if bb < 0:
            nb = ba
        else:
            pb = ba
    if pa == -1 or nb == -1:
        print(p * pb * pow(na, mod - 2, mod) % mod)
    elif pb == -1 or na == -1:
        print(p * nb * pow(pa, mod - 2, mod) % mod)
    elif pa * pb > na * nb:
        print(p * pb * pow(na, mod - 2, mod) % mod)
    else:
        print(p * nb * pow(pa, mod - 2, mod) % mod)


if __name__ == '__main__':
    main()


Measured memory_bytes: 39652
import java.util.Scanner;

public class Main {

	public static final int BIG_NUM = 2000000000;
	public static final int MOD = 1000000007;

	public static boolean check[];
	public static final int NUM = 2000;
	public static int N;
	public static int table[];

	public static void main(String[] args) {

		check = new boolean[NUM+1];

		Scanner sc = new Scanner(System.in);
		N = sc.nextInt();

		table = new int[N];

		for(int i = 0; i < N; i++){
			table[i] = sc.nextInt();
		}

		recursive(0,0);

		int num_query = sc.nextInt();

		int tmp;
		StringBuilder ans = new StringBuilder();

		for(int loop = 0; loop < num_query; loop++){

			tmp = sc.nextInt();
			if(check[tmp]){
				ans.append("yes\n");
			}else{
				ans.append("no\n");
			}
		}

		System.out.print(ans.toString());
	}

	public static void recursive(int index,int sum){
		if(index == N){
			check[sum] = true;
			return;
		}

		recursive(index+1,sum);
		if(sum+table[index] <= NUM){
			recursive(index+1,sum+table[index]);
		}
	}

}




Measured memory_bytes: 26592
//#include "pch.h"
//#include "stdafx.h"
#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <string>

using namespace std;

/*-----------------------------------------------------------------------------
定義
-------------------------------------------------------------------------------*/
#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define INF			2e9
#define MOD			1e9+7
#define MIN(a, b)	((a) < (b) ? a : b)
#define MAX(a, b)	((a) > (b) ? a : b)
#define IsOdd(x)	(((x)&0x01UL) == 0x01UL)		/* 奇数 */
#define IsEven(x)	(!IsOdd((x)))					/* 偶数 */

typedef long long int QWORD;
typedef long long int ll;

/*-----------------------------------------------------------------------------
処理
-------------------------------------------------------------------------------*/
int main()
{
	int N, K;
	string S;

	cin >> N >> K;
	cin >> S;

	S[K - 1] = S[K - 1] + 0x20;

	cout << S << endl;

	return 0;
}



Measured memory_bytes: 256
using System;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] array = Console.ReadLine().Split(' ');
            int a = int.Parse(array[0]);
            int b = int.Parse(array[1]);

            int ans = (a - 1) * (b - 1);
            Console.WriteLine(ans);

        }
    }
}


Measured memory_bytes: 11092
import java.util.*;
public class Main{
    public static double area(Point p1, Point p2){
    	return (p1.x*p2.y - p1.y*p2.x)/2.0;
    }
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        Point[] p = new Point[n];
	for(int i = 0 ; i < n ; i++)
		p[i] = new Point(sc.nextDouble(),sc.nextDouble());
        double ans = 0;
	for(int i = 0 ; i < n-1 ; i++)
		ans += area(p[i],p[i+1]);
	System.out.printf("%.1f\n",ans+area(p[n-1],p[0]));
    }
}
class Point{
    double x;
    double y;
    Point(double x, double y){
        this.x = x;
        this.y = y;
    }
}


Measured memory_bytes: 28848
#include <bits/stdc++.h>
using namespace std;
string s,t;
int m,n,memo[2001][2001][2];
 
int check(int i,int j,int idx){
  if(memo[i][j][idx]) return memo[i][j][idx];
  int res=0;
  char ima[2]={'I','O'};
  if(s[i]&&s[i]!=ima[idx]) res=1+check(i+1,j,(idx+1)%2);
  if(t[j]&&t[j]!=ima[idx]) res=max(res,1+check(i,j+1,(idx+1)%2));
  return memo[i][j][idx]=res;
}
 
int main(){
  cin>>m>>n;
  cin>>s>>t;
 
  int ans=0;
  for(int i=0;i<s.size();i++)
    for(int j=0;j<t.size();j++){
      if(s[i]=='I') ans=max(ans,1+check(i+1,j,0));
      if(t[j]=='I') ans=max(ans,1+check(i,j+1,0));
    }
  if(ans)ans-=!(ans%2);
    
  cout <<ans<<endl;
  return 0;
}

Measured memory_bytes: 32860
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cmath>
#include <iomanip>

typedef long long ll;
using namespace std;
const int mod = 1000000007;

int main() {

    ll N; cin >> N;
    cout << (N - 1) * N / 2 << '\n';

}


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

//#define int long long
//using ll = boost::multiprecision::cpp_int;
using ll = long long;
//constexpr int INF = 1e9;//INT_MAX=(1<<31)-1=2147483647
constexpr ll INF = (ll)1e18;//(1LL<<63)-1=9223372036854775807
constexpr ll MOD = (ll)1e9 + 7;
constexpr double EPS = 1e-9;
constexpr int dx[4]={1,0,-1,0};
constexpr int dy[4]={0,1,0,-1};
#ifdef LOCAL_ENV
	#define debug(var) std::cout<<#var" = "<<var<<std::endl
#else
	#define debug(var)
#endif
#define p(var) std::cout<<var<<std::endl
#define rep(i, n)   for(ll i=0, i##_length=(n); i< i##_length; ++i)
#define repeq(i, n) for(ll i=1, i##_length=(n); i<=i##_length; ++i)
#define all(a) (a).begin(), (a).end()
#define PI (acos(-1))
template<typename T> inline T power(T x, T n){ return n ? power(x*x%MOD,n/2)*(n%2?x:1)%MOD : 1; }
template<typename T> inline T gcd(T a, T b) { return b ? gcd(b,a%b) : a; }
template<typename T> inline T lcm(T a, T b) { return a / gcd(a,  b) * b; }
template<typename T1, typename T2>inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template<typename T1, typename T2>inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
	for (int i = 0, len = v.size(); i < len; ++i){
		s << v[i]; if (i < len - 1) s << "\t";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
	for (int i = 0, len = vv.size(); i < len; ++i){
		s << vv[i] << endl;
	}
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const map<T1, T2>& m) {
	s << "{" << endl;
	for (typeof(m.begin()) itr = m.begin(); itr != m.end(); ++itr){
		s << "\t" << (*itr).first << " : " << (*itr).second << endl;
	}
	s << "}" << endl;
	return s;
}

/*-----8<-----8<-----*/

constexpr ll W_MAX = 100;

ll H, W;
ll N;
ll a[10000];

void input() {
	scanf("%lld%lld", &H, &W);
	scanf("%lld", &N);
	rep(i, N) scanf("%lld", a + i);
}

void solve() {
	ll ans[H][W];
	ll c=1;
	rep(h,H){
		rep(i,W){
			ll w=h%2?i:W-i-1;
			ans[h][w]=c;
			a[c-1]--;
			if(!a[c-1])c++;
		}
	}

	rep(i,H){
		rep(j,W){
			cout<<ans[i][j];
			if(j==W-1)cout<<endl;
			else cout<<' ';
		}
	}
}

signed main() {
	input();
	solve();
	return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<algorithm>
#include<regex>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;

int main(){
	string w,t;
	int wcnt = 0;
	cin >> w;
    regex re(w, std::regex_constants::icase);
    smatch m;
	while(true){
		cin >> t;
		if(t == "END_OF_TEXT") break;
		if(w.size() == t.size() && std::regex_search(t, m, re)){
            wcnt++;
        }
	}
	cout << wcnt << endl;
}



Measured memory_bytes: 3252