akhauriyash/Code-Regression huggingface dataset:
N, W = map(int, input().split())
items = [tuple(map(int, input().split())) for i in range(N)]

w0 = items[0][0]
sizeX = min(W, sum([items[i][0] for i in range(N)])) // w0 + 1
sizeY = min(w0, 3 * (N - 1) + 1)
memo = [[[-1 for y in range(sizeY)] for x in range(sizeX)] for i in range(N + 1)]

memo[0][0][0] = 0
for i, (wi, vi) in enumerate(items):
    for x in range(sizeX):
        for y in range(sizeY):
            if memo[i][x][y] == -1: continue

            wn = w0 * x + y + wi
            if wn <= W:
                memo[i + 1][wn // w0][wn % w0] = memo[i][x][y] + vi

            memo[i + 1][x][y] = max(memo[i + 1][x][y], memo[i][x][y])

print(max(map(max, [memo[N][x] for x in range(sizeX)])))


Measured memory_bytes: 28292
#include<bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define il inline
#define rg register
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define lch(x) ((x)<<1)
#define rch(x) ((x)<<1^1)
#define rep(i,st,ed) for(rg int i=(st);i<=(ed);++i)
#define per(i,ed,st) for(rg int i=(ed);i>=(st);--i)
#define rep0(i,n) for(rg int i=0;i<(n);++i)
#define per0(i,n) for(rg int i=int(n)-1;i>=0;--i)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef double dbl;
typedef long double ldb;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<typename T> il T qmin(const T &x,const T &y){return x<y?x:y;}
template<typename T> il T qmax(const T &x,const T &y){return x>y?x:y;}
template<typename T> il bool getmin(T &x,const T &y){return y<x?x=y,true:false;}
template<typename T> il bool getmax(T &x,const T &y){return y>x?x=y,true:false;}
il void fileio(const string &s){
	freopen((s+".in").c_str(),"r",stdin);
	freopen((s+".out").c_str(),"w",stdout);
}

const int inf=(int)1e9+7;
const ll linf=(ll)1e18+7;
const int N=400005;

int u[N],v[N],w[N],a[N],id[N],par[N];
int n,m;

il bool cmp(int x,int y){
	return w[x]<w[y];
}

il int find(int x){
	return par[x]<0?x:par[x]=find(par[x]);
}

il void join(int x,int y){
	if(x==y) return;
	if(par[x]<par[y]) par[x]+=par[y],par[y]=x;
	else par[y]+=par[x],par[x]=y;
}

int main(){
//	fileio("test");
	scanf("%d%d",&n,&m);
	rep0(i,n<<1) a[i]=inf<<1;
	rep(i,1,m){
		scanf("%d%d%d",u+i,v+i,w+i);
		getmin(a[u[i]],w[i]+1);
		getmin(a[v[i]],w[i]+2);
	}
	rep(i,1,(n<<1)-1) getmin(a[i],a[i-1]+2);
	rep0(i,n){
		getmin(a[i],a[i+n]);
		++m;
		u[m]=i,v[m]=(i+1)%n,w[m]=a[i];
	}
	rep(i,1,m) id[i]=i;
	sort(id+1,id+m+1,cmp);
	int rest=n-1;
	ll ans=0;
	memset(par,-1,sizeof(int)*n);
	rep(p,1,m){
		int i=id[p];
		int x=find(u[i]),y=find(v[i]);
		if(x==y) continue;
		ans+=w[i];
		join(x,y);
		if(!--rest) break;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 8832
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>


int main(){
  pii A[5];
  int a;
  rep(i,5) {
    cin >> a;
    A[i] = {(a+9)%10, a};
  }

  sort(A, A+5);
  int retval = 0;
  rep(i,5){
    if (i==0) retval += A[i].second;
    else retval += ((A[i].second+9)/10)*10;
  }

  cout << retval << endl;

  

  // cout << fixed << setprecision(6);
  return 0;
}


Measured memory_bytes: 256
import java.io.IOException;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        try (
            BufferedReader reader = new BufferedReader(
                new InputStreamReader(System.in))) {
            final String s = reader.readLine();

            final String sl[] = s.split(" ");
            int A = Integer.parseInt(sl[0]);
            int B = Integer.parseInt(sl[1]);

            A = A == 1 ? 14 : A;
            B = B == 1 ? 14 : B;

            System.out.println(A < B ? "Bob" : B < A ? "Alice" : "Draw");
        }
    }
}


Measured memory_bytes: 22484
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <iterator>  // std::back_inserter()
#include <set>
#include <map>
#include <algorithm>  // std::copy()
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <cmath>
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
#include <iomanip>  // std::setprecision()
using namespace std;

#define ALL(obj) (obj).begin(), (obj).end()
#define REP(i, n) for (int i=0; i < (int)(n); i++)  // 0 ~ n-1
#define REPN(i, n) for (int i=1; i <= (int)(n); i++)  // 1 ~ n
#define MIN(vec) min_element(ALL((vec)))  // イテレータのため、値を取り出すときは * を先頭につける
#define MAX(vec) max_element(ALL((vec)))
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(ALL((vec)), 0)  // 0 は初期値
#define COPY(vec1, vec2) copy(ALL(vec1), back_inserter(vec2))  // vec1をvec2にコピーする vec2は空にしておく必要あり
typedef long long ll;

const int MOD = 1000000007;  // 1 000 000 007

template <class T>
T factorial(T num) {
    if (num == 0 || num == 1) {
        // 0! = 1, 1! = 1;
        return 1;
    } else {
        return num * factorial(num - 1);
    }
}

template <class T>
T nCr(T n, T r) {
    return factorial(n)/(factorial(r)*factorial(n-r));
}


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

    // input
    ll balls, colors;
    cin >> balls >> colors;
    
    // calculation
    if (balls == colors) {
        cout << factorial(balls) << "\n";
    } else if (balls == 1) {
        cout << colors << "\n";
    } else if (balls == 2) {
        ll col_pattern = nCr(colors, (ll)2);
        cout << col_pattern*2 << "\n";
    } else if (colors == 2) {
        cout << 2 << "\n";
    } else {
        ll res, pattern;
        res = colors * (ll)pow(colors-1, balls-1);
        cout << res << "\n";
    }
    
    return 0;
}


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

int main(){
   char s[101];
   int len;
   int i,f,g;

   scanf("%s",s);
   len=strlen(s);

   f=g=0;
   for(i=0;i<len;++i){
      if(!f){
         if(s[i]=='C'){
            f=1;
            continue;
         }
      }else if(s[i]=='F'){
         g=1;
         break;
      }
   }

   printf("%s\n",(f*g)?"Yes":"No");

   return 0;
}


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

using i64 = int64_t;

int main(){
    int n, l;
    cin >> n >> l;
    int taste = 0;
    for(int i=1;i<=n;++i){
        taste += l + i -1;
    }
    int ans = 1e9;
    for(int i=1;i<=n;++i){
        int sum = 0;
        for(int j=1;j<=n;++j){
            if(i == j)continue;
            sum += l + j - 1;
        }
        if(abs(sum-taste) < abs(ans-taste)){
            ans = sum;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
   int n,k;
   cin >> n >> k;

   int h[n];

   for( int i=0 ; i<n ; i++ ){
      cin>>h[i];
   }
   
   vector<int> dp(n,INT_MAX);
    
   dp[0] = 0;
    
   for(int i=0 ; i<n ;i++){
        for(int j=i+1;j<=i+k;j++){
            if(j<n){
                dp[j]=min(dp[j],dp[i]+abs(h[i]-h[j]));
            }
        }
   }
   cout<<dp[n-1]<<"\n";
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<string>> vvs;
typedef vector<vector<char>> vvc;
typedef vector<vector<bool>> vvb;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define vrep(v,n) for(int i=0;i<n;i++){cin >> v.at(i);} 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repn(i, n) for (int i = 0; i <= (int)(n); i++)
#define srep(i, l, n) for (int i = l; i < (int)(n); i++)
#define srepn(i, l, n) for (int i = l; i <= (int)(n); i++)
#define pb push_back 
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const int mod = 1000000007;
const int inf = 1e9;
#define PI 3.14159265369;
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    string s;int K;
    cin >> s >> K;
    int n = s.length();
    int dp[n+1][2][4];
    repn(i,n)rep(j,2)rep(k,4) dp[i][j][k] = 0;
    dp[0][0][0] = 1;
    rep(i,n)repn(j,1)repn(k,K){
        int now = s[i] - '0';
        if(j==0){
            rep(l,10){
                int nk = k;
                if(l != 0) nk++;
                if(nk > K || now < l) continue;
                if(now==l) dp[i+1][0][nk] += dp[i][0][k]; 
                if(now > l) dp[i+1][1][nk] += dp[i][0][k];
            }
        }else if(j==1){
            rep(l,10){
                int nk = k;
                if(l != 0) nk++;
                if(nk > K) continue;
                dp[i+1][1][nk] += dp[i][1][k];
            } 
        }
    }
    ll ans = 0;
    repn(j,1) ans += dp[n][j][K];
    cout << ans << endl;

}

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

int n,p;
string s;
map<int,ll> mp;
int pp[200001];
int main(){
    cin>>n>>p>>s;
    ll ans=0,cur=0;
    int p10=1;
    if(p==2||p==5)rep(i,n){
        cur=(cur*10+(s[i]-'0'))%p;
        if(p==2||p==5){
            if(cur%p==0)ans+=i+1;
        }
    }
    else{
        for(int i=n;i>=0;--i){
            ans+=mp[pp[i]];
            ++mp[pp[i]];
            if(i>0)pp[i-1]=(pp[i]+p10*(s[i-1]-'0'))%p;
            p10*=10,p10%=p;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1796
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

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

fn main() {
    input! {
        s: String,
        t: String,
    }

    let ans = t + &s;

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


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

const int mod=1e9+7;

int mat[1005][1005];
int ans[1005][1005];


int countPaths(int H,int W){
    ans[0][0]=1;

    for(int i=1;i<H;i++) {
        if(mat[i][0]==1) {
            ans[i][0] = ans[i - 1][0];
        }
    }

    for(int i=1;i<W;i++) {
        if(mat[0][i]!=0) {
            ans[0][i] = ans[0][i - 1];
        }
    }
    
    for(int i=1;i<H;i++) {
        for(int j=1;j<W;j++) {
            if(mat[i][j]!=0)
            {
                ans[i][j] = (ans[i - 1][j] + ans[i][j - 1])%mod;
            }
        }
    }
    
   return ans[H-1][W-1]%mod;
}

#undef int
int main() {
#define int long long
    int H,W;
    cin >> H >> W;
    char x;

    memset(ans,0,sizeof(ans));
    ans[0][0]=1;
    for(int i=0;i<H;i++) {
        for(int j=0;j<W;j++) {
            cin >> x;
            if(x=='.')
                mat[i][j]=1;
            else
                mat[i][j]=0;
        }
    }
     cout << countPaths(H,W)%mod << endl;
     /*
     for (int i = 0; i < H; i++)
     {
         for (int j = 0; j < W; j++)
         {
             cout << ans[i][j] << " ";
         }
         cout << endl;
     }
     */
}

Measured memory_bytes: 16000
#include <bits/stdc++.h> 
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define size_of_array(array) (sizeof(array)/sizeof(array[0]))
#define MAX 100005
#define NIL -1
using ll =long long;
using namespace std;
using Graph=vector<vector<int>>;
using Field=vector<vector<char>>;
using P =pair<int,int>;

template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}

const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int INF=1001001001;

int main(){
    int h,w;
    cin>>h>>w;
    Field F(h,vector<char>(w));
    rep(i,h)rep(j,w)cin>>F[i][j];

    int ans=0;
    rep(j,h)rep(k,w){
        queue<pair<int,int>> q;
        vector<vector<int>> dist(h,vector<int>(w,INF));
        if(F[j][k]=='#')continue;
        q.push({j,k});
        dist[j][k]=0;
        while(!q.empty()){
            pair<int,int> p=q.front();
            q.pop();
            rep(i,4){
                int y=p.first+dy[i];
                int x=p.second+dx[i];
                if(y<0||y>=h||x<0||x>=w)continue;
                if(F[y][x]=='#')continue;
                if(dist[y][x]!=INF)continue;
                dist[y][x]=dist[p.first][p.second]+1;
                ans=max(ans,dist[y][x]);
                q.push({y,x});
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3580
import java.util.Scanner;

public class Main {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		
		int[] a = new int[n];
		for(int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		
		n = n - k;
		int count = 1;
		
		if(n <= 0) {
			System.out.println(count);
			System.exit(0);
		}
		
		while(n > 0) {
			n = n - (k - 1);
			count++;
		}
		
		System.out.println(count);
		
		
	}
}

Measured memory_bytes: 50440
import sys
input = sys.stdin.readline

def main():
    n, m = map(int, input().split())
    A = [list(map(int, input().split())) for i in range(n)]
    b = [list(map(int, input().split())) for i in range(m)]

    for i in range(n):
        ans = 0
        for j in range(m):
            ans += A[i][j] * b[j][0]
        print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 6020
INPUT = list(map(int,input().split()))
A=int(INPUT[0])
B=int(INPUT[1])
coin=0

if A>=B:
    coin = coin+A
    A=A-1
else:
    coin = coin+B
    B=B-1

if A>=B:
    coin = coin+A
else:
    coin = coin+B

print(coin)
    


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

int main() {
  string yearMonthDay;
  int year, month, day;
  int nowYear, nowMonth, nowDay;
  cin >> yearMonthDay;

  year = stoi(yearMonthDay.substr(0, 4));
  month = stoi(yearMonthDay.substr(5, 2));
  day = stoi(yearMonthDay.substr(8, 2));
  nowYear = 2019;
  nowMonth = 4;
  nowDay = 30;

  if(year > nowYear || (year == nowYear && month > nowMonth || (year == nowYear && month == nowMonth && day > nowDay))){
    cout << "TBD" << endl;
  } else {
    cout << "Heisei" << endl;
  }
}

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

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = LLONG_MAX;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

#define int long long

inline void my_io() {

	std::ios::sync_with_stdio(false);

	std::cin.tie(0);

	cout << fixed << setprecision(16);

	//cout << setprecision(10) << scientific << ans << endl;
}

signed main() {
	ll n, d;

	cin >> n >> d;

	ll x = n / (2 * d + 1);

	if ((2 * d + 1) * x < n) {
		x++;
	}

	cout << x << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int k = sc.nextInt();
    long sum = 0;
    for(int a = 1; a <= k; a++){
      for(int b = 1; b <= k; b++){
        int sur_1 = gcd(a,b);
        for(int c = 1; c <= k; c++){
          sum += gcd(sur_1,c);
        }
      }
    }
    System.out.println(sum);
  }
  public static int gcd(int x, int y){
    int big = Math.max(x,y);
    int small = Math.min(x,y);
    int surplus = big%small;
    if(surplus == 0){
      return small;
    }
    surplus = gcd(small,surplus);
    return surplus;
  }
}

Measured memory_bytes: 35888
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>
#include<map>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
using P=pair<int,int>;
using lint=long long;
using ll=long long;
const lint inf=1e18+7;
const int MOD=1000000007;
class Seg_Tree{
    private:
    int e=1000000007;
    int n;
    vector<int> node;
    public:
    int process(int left,int right){
        if(left==e)return right;
        if(right==e)return left;
        return left+right;
    }
    Seg_Tree(vector<int> v){
        int num=1;
        int size=v.size();
        while(num<size){
            num*=2;
        }
        n=num;
        node.resize(2*num-1,e);
        for(int i=0;i<size;i++)node[i+num-1]=v[i];
        for(int i=n-2;i>=0;i--)node[i]=process(node[i*2+1],node[i*2+2]);
    }
    void update(int x,int val){
        x+=(n-1);
        node[x]+=val;
        while(x>0){
            x=(x-1)/2;
            node[x]=process(node[x*2+1],node[x*2+2]);
        }
    }
    int out(int a,int b,int k=0,int l=0,int r=-1){
        if(r<0)r=n;
        if(a>=r||b<=l)return e;
        if(a<=l&&b>=r)return node[k];
        int vl=out(a,b,k*2+1,l,(l+r)/2);
        int vr=out(a,b,k*2+2,(l+r)/2,r);
        return process(vl,vr);
    }
};
bool judge(vector<int> const& a,int key){
  int n=a.size()-1;
  vector<int> sum(n+1,0);
  //cout<<"key="<<key<<endl;
  rep1(i,n){
    sum[i]=sum[i-1];
    if(a[i]>key){
      sum[i]++;
      //cout<<"u"<<" ";
    }
    else{
      sum[i]--;
      //cout<<"d"<<" ";
    }
  }
  int buf=0;
  Seg_Tree tree(vector<int> (2*n+5,0));
  rep(i,n+1){
    buf+=tree.out(0,sum[i]+n+1);
    tree.update(sum[i]+n,1);
    //printf("i=%lld, buf=%lld\n",i,buf);
  }
  //cout<<endl;
  //printf("buf=%lld\n",buf);
  int num=((n+1)*n)/2;
  if(buf>=(num+1)/2){
    return true;
  }
  else{
    return false;
  }
}
signed main(){
  int n;cin>>n;
  vector<int> a(n+1,0);
  rep1(i,n)cin>>a[i];
  int d=0;
  int u=inf;
  while(u-d>1){
    int mid=(u+d)/2;
    if(judge(a,mid)){
      d=mid;
    }
    else u=mid;
  }
  sort(a.begin(),a.end());
  auto it=upper_bound(ALL(a),d);
  cout<<*it<<"\n";
  return 0;
}


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

#define REP(i, stop) FOR(i, 0, stop)
#define FOR(i, start, stop) for (ll i = start, i##_len = stop; i < i##_len; ++i)

using namespace std;
using ll=long long;

int main() {
    ll n,k;
    cin>>n>>k;
    vector<ll> A(n);
    REP(i,n)cin>>A[i];
    sort(A.begin(),A.end());
    ll l=A[0]*A[n-1];
    ll r=max(A[0]*A[0],A[n-1]*A[n-1])+1;
    while(r-l>1){
        ll m=l+r>=0?(l+r)/2:(l+r-1)/2;
        ll c=0;
        REP(i,n){
            if((A[i]>=0)){
                c+=partition_point(A.begin(),A.end(),[&](auto aj){
                    return A[i]*aj<m;
                })-A.begin();
            }else{
                c+=partition_point(A.rbegin(),A.rend(),[&](auto aj){
                    return A[i]*aj<m;
                })-A.rbegin();
            }
            if(A[i]*A[i]<m)c--;
        }
        c/=2;
        if(c>=k){
            r=m;
        }else{
            l=m;
        }
    }
    cout<<l<<endl;
    return 0;
}


Measured memory_bytes: 1920
import scala.io.StdIn.readInt
import scala.collection.mutable.ArrayBuffer

object Main {
  def sieve(n:Int) = {
    val primes = Array.tabulate(n+1) { _ % 2 }
    primes(1) = 0
    primes(2) = 1

    for( i <- 3 to Math.sqrt(n).toInt by 2 )
    {
      if(primes(i) == 1)
        (i*i to n by i*2).foreach { primes(_) = 0 }
    }
    primes
  }

  def main(args:Array[String]) = {
    val p = sieve(10001)
    val b = new ArrayBuffer[String]
    var i = 0
    while({i=readInt;i}!=0) {
      val n =if(i.toInt % 2 == 0) i.toInt-1 else i.toInt
      b += (n to 5 by -2).find( j=> p(j)==1 && p(j-2)==1 ).map( j=>(j-2)+" "+j ).get
    }
    println( b.mkString("\n") )
  }
}

Measured memory_bytes: 55208
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int N;
    scanf("%d\n", &N);
    int *res = malloc(sizeof(int) * N);
    for(int ni=0; ni<N; ni++){
        int a;
        scanf("%d", &a);
        res[a-1] = ni;
    }

    for(int ni=0; ni<N; ni++){
        printf("%d ", res[ni]+1);
    }
    printf("\n");
    return 0;
}


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

int main(void){
	string s,t;
	cin >> s >> t;
	int n,m;
	n = s.length();
	m = t.length();
	int dp[n+1][m+1];
	//dp[i][j] : sのi文字目,tのj文字目のLCSの長さ
	for(int i=0;i<n+1;i++)for(int j=0;j<=m;j++)dp[i][j]=0;
	
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(s[i-1]==t[j-1]){
				dp[i][j]=dp[i-1][j-1]+1;
			}else{
				dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
			}
		}
	}
	
	string ans = "";
	int x = n;
	int y = m;
	//dp配列を逆から辿ってLCSを作成する
	//LCSの長さが更新されたときの文字を追加していく
	while(x>0&&y>0){
		if(dp[x][y] == dp[x-1][y]){
			x--;
		}else if(dp[x][y]== dp[x][y-1]){
			y--;
		}else{
			x--;
			y--;
			ans = s[x] + ans;
		}
	}
	//reverse(ans.begin(),ans.end());
	cout << ans << endl;
}

Measured memory_bytes: 35456
n = int(input())
lis = list(map(int, input().split(" ")))
big_num = 1000000
max_num, min_num, sum = -1*big_num, big_num, 0
for i in lis:
    if i > max_num:
        max_num = i
    if i < min_num:
        min_num = i
    sum += i
print("%d %d %d" % (min_num, max_num, sum))


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

ll N, M;
const ll prime = 1000000007;
ll dp[100010];
bool flags[100010];

int main() {
    cin >> N >> M;
    for (int i = 0; i < M; i++){
        ll temp; cin >> temp;
        flags[temp] = 1;
    }

    dp[0] = 1;
    for (int i = 0; i < N; i++) {
        if (!flags[i+1]) {
            dp[i+1] += dp[i];
            dp[i+1] %= prime;
        }
        if (!flags[i+2]) {
            dp[i+2] += dp[i];
            dp[i+2] %= prime;
        }
    }

    cout << dp[N] % prime << endl;
    return 0;
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
#define INF (1e9)
using namespace std;

string s;
int dp[1<<26];

int main(){
  cin>>s;
  for(int i=0;i<(1<<26);i++) dp[i]=INF;
  dp[0]=0;
  int S=0;
  for(int i=0;i<s.size();i++){
    S^=(1<<(s[i]-'a'));
    int minv=INF;
    minv=min(minv, dp[S]);
    for(int j=0;j<26;j++) minv=min(minv, dp[S^(1<<j)]);
    dp[S]=min(dp[S], minv+1);
  }
  if(dp[S]==0) dp[S]=1;
  cout<<dp[S]<<endl;
  return 0;
}


Measured memory_bytes: 262788
/*
Author: Srinjoy
Language: C++ 17
*/
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define de(a) cout << #a << " = " << a << endl
#define dd(a) cout << #a << " = " << a << " "
#define optimiza_io cin.tie(0); ios_base::sync_with_stdio(0);
#define ZERO(a) memset(a,0,sizeof(a))
#define fileinput(s) freopen(s,"r",stdin)
#define MINUS(a) memset(a,0xff,sizeof(a))
typedef long long ll;
const ll mod = 1000000007;

template<class T>
istream& operator >> (istream& in, vector<T>& v){ for (auto &x : v) { in >> x; } return in; }
 
template<class T>
istream& operator >> (istream& in, pair<T, T> & v){ in >> v.fi >> v.se;return in; }

void printArr(vector<int> arr){
	cout<<"\n------------------------------------\n";

	for(int i=0;i<arr.size();i++) cout<<arr[i]<<" ";
	
	cout<<"\n------------------------------------\n";
}

void printArr(vector<vector<int> > arr){
	cout<<"\n------------------------------------\n";

	for(vector<int> i:arr){
		for(int j:i){
			cout<<j<<" ";
		}
		cout<<endl;
	}
	
	cout<<"\n------------------------------------\n";

}


int main(){
	optimiza_io
	
	string s1;
	cin>>s1;

	int n = s1.length();

	for(int i=0;i<n;i++){
		cout<<"x";
	} 
	cout<<endl;
	
}

Measured memory_bytes: 256
N, K = input().split(" ")
N, K = int(N), int(K)
p_list = [int(i) for i in input().split(" ")]

for i in range(0, N):
  if i+K > N:
    break

  if i == 0:
    max_sum = sum(p_list[0:K])
    now_sum = max_sum
  else:
    now_sum += (p_list[i-1+K] - p_list[i-1])
    if max_sum < now_sum:
      max_sum = now_sum

print((max_sum + K)/2)


Measured memory_bytes: 24684
using System;

namespace ABC062
{
    class Program
    {
        static void Main(string[] args)
        {
            var groupA = new[] { 1, 3, 5, 7, 8, 10, 12 };
            var groupB = new[] { 4, 6, 9, 11 };

            var s = Console.ReadLine().Split(' ');
            var x = int.Parse(s[0]);
            var y = int.Parse(s[1]);

            if (x == 2)
            {
                Console.WriteLine(y == 2 ? "Yes" : "No");
                return;
            }

            if (Array.BinarySearch(groupA, x) >= 0)
            {
                Console.WriteLine(
                    Array.BinarySearch(groupA, y) >= 0
                        ? "Yes"
                        : "No"
                );
                return;
            }

            Console.WriteLine(
                Array.BinarySearch(groupB, y) >= 0
                    ? "Yes"
                    : "No"
            );
        }
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
int a[200000],tmp[200000]={0};
int main()
{
	int n,i,j,k;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
		tmp[i]=a[i];
	}
	sort(tmp,tmp+n);
	for(i=0;i<n;i++)
	{
		printf("%d\n",a[i]<=tmp[n/2-1]?tmp[n/2]:tmp[n/2-1]);
	}
	return 0;
}

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

#define name ""
#define ini freopen(name".inp","r",stdin); freopen(name".out","w",stdout)
#define foe(it,c) for (__typeof(c.begin()) it = c.begin(); it != c.end(); it++)
#define long long long 
#define db double 
#define pii pair <int, int>
#define pll pair <long, long>
#define all(c) c.begin(), c.end()
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define Data pair <long, pii> 
const long INF = 1e18;
const int MOD = 1e9+7;
const int dx[4] = {0,0,-1,1};
const int dy[4] = {-1,1,0,0};

const int N = 51;

struct Edge{
  int v, x, y;
  Edge(int v = 0, int x = 0, int y = 0) : v(v), x(x), y(y) {}
};

vector <Edge> a[N];
long dist[N][5001];
int n, m, C[N], D[N], s;
bool Chk[N][5001];

void dijkstra(){
  s = min(s, 5000);
  for (int i = 1; i <= n; i++){
    for (int j = 0; j <= 5000; j++){
      dist[i][j] = INF;
    }
  }
  dist[1][s] = 0;
  priority_queue <Data, vector <Data>, greater <Data> > Pr;
  Pr.push(Data(0, pii(1, s)));
  while (Pr.size()){
    int u = Pr.top().second.first;
    int c = Pr.top().second.second;
    long cur = Pr.top().first;
    Pr.pop();
    if (dist[u][c] != cur) continue;
    if (!Chk[u][c]){
      Chk[u][c] = true;
      int pre = c;
      for (int i = min(5000, c + C[u]); i <= 5000; i += C[u]){
        if (dist[u][i] > dist[u][pre] + D[u]){
          dist[u][i] = dist[u][pre] + D[u];
          Pr.push(Data(dist[u][i], pii(u, i)));
        }  
        pre = i; Chk[u][i] = true;
      }
    }
    for (Edge x : a[u]){
      int v = x.v;
      int cost = x.x;
      int Time = x.y;
      if (c - cost >= 0){
        if (dist[v][c - cost] > dist[u][c] + Time){
          dist[v][c - cost] = dist[u][c] + Time;
          Pr.push(Data(dist[v][c - cost], pii(v, c - cost)));
        }  
      }       
    }
  }
}

int main()
{
  fastio;
  cin >> n >> m >> s;
  for (int i = 1; i <= m; i++){
    int u, v, x, y; cin >> u >> v >> x >> y;
    a[u].push_back(Edge(v, x, y)); 
    a[v].push_back(Edge(u, x, y));
  }                               
  for (int i = 1; i <= n; i++) cin >> C[i] >> D[i];
  dijkstra();
  for (int i = 2; i <= n; i++){
    long mn = INF;
    for (int j = 0; j <= 5000; j++){
      mn = min(mn, dist[i][j]);
    }
    cout << mn << '\n';
  }
  return 0;
}

Measured memory_bytes: 13760
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    v = [[] for i in range(n)]
    for i in range(n-1):
        a,b = LI()
        a -= 1
        b -= 1
        v[a].append(b)
        v[b].append(a)
    d = [0]*n
    d[0] = 1
    q = deque([0])
    p = [None]*n
    while q:
        x = q.popleft()
        nd = d[x]+1
        for y in v[x]:
            if not d[y]:
                d[y] = nd
                p[y] = x
                q.append(y)
    V = list(range(n))
    V.sort(key = lambda x:-d[x])
    t = [1]*n
    for x in V[:-1]:
        t[p[x]] += t[x]
    ans = n
    for x in range(n):
        tx = t[x]
        s = 0
        for y in v[x]:
            ty = t[y]
            if tx < ty:
                s += pow(2,t[0]-tx,mod)-1
            else:
                s += pow(2,ty,mod)-1
            s %= mod
        ans += s
        ans %= mod
    print((n*pow(2,mod-2,mod)-ans*pow(2,(mod-2)*n%(mod-1),mod))%mod)
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 98808
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef vector<pair<ll,ll> > vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
const int MOD = 1000000007;
const int MAX = 510000;

int main(){
  string s;cin>>s;
  vll sum(s.size()+1,0),mod2019(2019,0);
  mod2019[0]++;
  ll t=1;
  rep(i,0,s.size()){
    int x=s[s.size()-1-i]-'0';
    sum[i+1]=x*t+sum[i];
    t=(t*10)%2019;
    sum[i+1]%=2019;
    mod2019[sum[i+1]]++;
  }
  ll ans=0;
  rep(i,0,2019){
    if(mod2019[i]!=0){ans+=(mod2019[i]*(mod2019[i]-1))/2;}
  }
  cout<<ans<<endl; 
}



Measured memory_bytes: 5120
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repI(i, d, n) for (int i = (d); i < (n); ++i)
#define reps1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using M = map<int, int>;
ll const INF = 1ll<<61;
double pi = 3.141592653589793238;

int main() {
  ll n, m;
  cin >> n >> m;
  vector<ll> foods(m, 0);
  rep(i, n) {
    ll k;
    cin >> k;
    rep(i, k) {
      ll a;
      cin >> a;
      foods[--a]++;
    }
  }

  cout << count(foods.begin(), foods.end(), n) << endl;


  return 0;
}


Measured memory_bytes: 384
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(1000000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v


# Width First Search (+ Distance)
def wfs_d(D, N, K):
    """
    D: 隣接行列(距離付き)
    N: ノード数
    K: 始点ノード
    """

    dfk = [-1] * (N + 1)
    dfk[K] = 0

    cps = [(K, 0)]
    r = [False] * (N + 1)
    r[K] = True
    while len(cps) != 0:
        n_cps = []
        for cp, cd in cps:
            for i, dfcp in enumerate(D[cp]):
                if dfcp != -1 and not r[i]:
                    dfk[i] = cd + dfcp
                    n_cps.append((i, cd + dfcp))
                    r[i] = True

        cps = n_cps[:]

    return dfk


# Depth First Search (+Distance)
def dfs_d(v, pre, dist):
    """
    v:  現在のノード
    pre: １つ前のノード
    dist: 現在の距離

    以下は別途用意する
    D: 隣接リスト(行列ではない)
    D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
    """

    global D
    global D_dfs_d

    D_dfs_d[v] = dist

    for next_v, d in D[v]:
        if next_v != pre:
            dfs_d(next_v, v, dist + d)

    return


def sigma(N):
    ans = 0
    for i in range(1, N + 1):
        ans += i
    return ans


def comb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def bisearch(L, target):
    low = 0
    high = len(L) - 1
    
    while low <= high:
        mid = (low + high) // 2
        guess = L[mid]
        if guess == target:
            return True
        elif guess < target:
            low = mid + 1
        elif guess > target:
            high = mid - 1
    if guess != target:
        return False

# --------------------------------------------

dp = None


def main():
    A, B, C, D = li_input()

    print(max(A*B, C*D))


main()


Measured memory_bytes: 4692
n=int(input())
arr=[int(x) for x in input().split(' ')]
arr2=sorted(arr)
for x in range(n):
	if x+1==arr[x]:
		continue
	else:
		t=arr[x]
		arr[x]=arr[t-1]
		arr[t-1]=t
		break
# print(arr,arr2)
if arr==arr2:
	print("YES")
else:
	print("NO")

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


int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int a=0;
  int b=0;
  int c=0;
  int d=0;
  int n;
  cin>>n;
  for(int i=0;i<n;i++){
    string s;
    cin>>s;
    if(s=="AC"){
      a++;
    }else if(s=="WA"){
      b++;
    }else if(s=="TLE"){
      c++;
    }else{
      d++;
    }
  }

  cout<<"AC x "<<a<<endl;
  cout<<"WA x "<<b<<endl;
  cout<<"TLE x "<<c<<endl;
  cout<<"RE x "<<d<<endl;
       
  
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep( i, n, m ) for(int i = ( n ); i < ( m ); i++)
#define rep_d( i, n, m ) for(int i = ( n ) - 1; i >= ( m ); i--)
#define sort_asc( X ) sort(( X ).begin(), ( X ).end())
#define sort_desc( X ) sort(( X ).begin(), ( X ).end(), greater <>())

template <class T> bool chmax( T& a, T b );
template <class T> bool chmin( T& a, T b );
int* eratosthenes( int N );
bool bit_search( int pattern, int N );
template <class T> void cumulative_sum( T array, size_t N );

const ll INF = 1LL << 60;
const int k_mod = 1e9 + 7;

typedef struct {
	vector <int> to;
	int cost;
} edge;
typedef struct {
	bool a;
	bool b;
} P;
int main( void ){
	string s, t; cin >> s >> t;
	sort_asc(s);
	sort_desc(t);
	if (s < t)
		cout << "Yes\n";
	else
		cout << "No\n";
}

int* eratosthenes( int N ){
	int* prime_array = new int[ N + 1 ];
	int lim = N;
	prime_array[ 0 ] = 0;
	prime_array[ 1 ] = 0;
	rep( i, 2, N + 1 ){
		prime_array[ i ] = 1;
	}
	rep( i, 2, lim ){
		if (prime_array[ i ] == 0)
			continue;
		lim = N / i;
		for(int j = i * 2; j < N + 1; j += i){
			prime_array[ j ] = 0;
		}
	}
	return prime_array;
}
template <class T> void cumulative_sum( T array, size_t N ) {
	rep( i, 1, N + 1 ){
		array[ i ] += array[ i - 1 ];
	}
}
template <class T> bool chmax( T& a, T b ) {
	if (a < b){
		a = b; return true;
	}
	return false;
}
template <class T> bool chmin( T& a, T b ) {
	if (a > b){
		a = b; return true;
	}
	return false;
}
bool bit_search( int pattern, int N ){
	int cnt = 0;
	rep( bit, 0, N ){
		if (pattern & ( 1 << bit )){
			cnt++;
		}
	}
	return true;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<utility>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<map>
using namespace std;
int g[505][505],ans = 1<<30;
int a[5],used[50],n,C;
int cnt[3][50],v[50][50];
void dfs(int x)
{
	if(x==3)
	{
/*		for(int i=0;i<3;i++)
			cout<<a[i]<<" ";
		cout<<endl;*/
		int cur = 0;
		for(int i=0;i<3;i++)
		for(int j=1;j<=C;j++)
		cur += cnt[i][j] * v[j][a[i]];
		if(cur<ans)ans = cur;
//		cout<<"->"<<cur<<endl;
		return ;
	}
	for(int i=1;i<=C;i++)
	if(!used[i])
	{
		used[i] = 1;
		a[x] = i;
		dfs(x+1);
		used[i] = 0;
	}
	return ;
}
int main()
{
	memset(cnt,0,sizeof(cnt));
	cin>>n>>C;
	for(int i=1;i<=C;i++)
	for(int j=1;j<=C;j++)
	scanf("%d",&v[i][j]);
	for(int i=1;i<=n;i++)
	for(int j=1;j<=n;j++)
	{
		scanf("%d",&g[i][j]);
		int k = (i+j)%3;
		cnt[k][g[i][j]]++;
	}
	memset(used,0,sizeof(used));
	dfs(0);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1280
import sys
def main():
    input = sys.stdin.readline
    N = int(input())
    *A, = map(int, input().split())
    if N == 0:
        if A[0] == 1: return 1
        else: return - 1
    elif A[0] != 0: return - 1
    mx = [0] * (N + 2)
    mx[0] = 1
    mx[N + 1] = 0
    mn = [0] * (N + 2)
    mn[0] = 1
    mn[N + 1] = 0
    n2 = 1
    for i in range(1, N + 1):
        n2 *= 2
        mx[i] = min(n2, (mx[i - 1] - A[i - 1]) * 2)
        mn[i] = mn[i - 1] - A[i - 1]
    for i in range(N, -1, -1):
        tmx = mx[i + 1] + A[i]
        tmn = A[i] + (mn[i + 1] + 1) // 2
        if tmx < 1 or tmx < mn[i]: return -1
        if tmn > mx[i]: return -1
        if tmx < tmn: return -1
        mx[i] = min(mx[i], tmx)
    return sum(mx)

if __name__ == '__main__':
    print(main())


Measured memory_bytes: 699504
#include<bits/stdc++.h>
using namespace std;
 
int main(){
        int w, h;
        char c;
         
        cin >> w >> h >> c;
        char maps[25][25];
         
        for(int i = 0;i < h;++i){
                for(int j = 0;j < w;++j){
                        maps[i][j] = '.';
                }
        }
         
        for(int i = 0;i < w;++i){
                maps[0][i] = '-';
                maps[h - 1][i] = '-';
        }
         
        for(int i = 0;i < h;++i){
                maps[i][0] = '|';
                maps[i][w - 1] = '|';
        }
         
        maps[0][0] = '+';
        maps[0][w - 1] = '+';
        maps[h - 1][0] = '+';
        maps[h - 1][w - 1] = '+';
         
        maps[h / 2][w / 2] = c;
         
        for(int i = 0;i < h;++i){
                for(int j = 0;j < w;++j){
                        cout << maps[i][j];
                }
                cout << endl;
        }
         
        return 0;
}



Measured memory_bytes: 3084
#include<stdio.h>

long factorial(int n)
{
	if(n > 0)
		return (n * factorial(n - 1));
	else
		return(1);
}

int main(void)
{
	int n;
	long result;
	
	scanf("%d", &n);
	
	result = factorial(n);
	
	printf("%ld\n", result);
	
	return 0;
}

Measured memory_bytes: 592
#include<bits/stdc++.h>
using namespace std;
#include <numeric> 
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define endl "\n"
#define int long long int
#define mod 1000000007


int32_t main()
{
	int n;
	cin>>n;
	int n1,n2,n3;
	n1=n/3;
	n2=n/5;
	n3=n/15;
	//cout<<n3<<endl;
	int sum=n1*(2*3+(n1-1)*3);
	
	
	int sum2=(n2*(2*5+(n2-1)*5));
	
	sum=sum+sum2;
	sum=sum/2;
	//cout<<sum<<endl;

	int sum1=(n3*(2*15+(n3-1)*15));
	sum1/=2;
	sum=sum-sum1;
	int ans=n*(n+1);
	ans/=2;
	//cout<<ans<<" "<<sum<<endl;
	ans=ans-sum;
	cout<<ans<<endl;
	return 0;
  }

Measured memory_bytes: 3636
import numpy as np
from functools import *
import sys
sys.setrecursionlimit(100000)
input = sys.stdin.readline




def acinput():
    return list(map(int, input().split(" ")))


def II():
    return int(input())

directions=np.array([[1,0],[0,1],[-1,0],[0,-1]])
directions = list(map(np.array, directions))

mod = 10**9+7


def factorial(n):
    fact = 1
    for integer in range(1, n + 1):
        fact *= integer
    return fact



def serch(x, count):
    #print("top", x, count)
            

    for d in directions:
        nx = d+x
        #print(nx)
        if np.all(0 <= nx) and np.all(nx < (H, W)):
            if field[nx[0]][nx[1]] == "E":
                count += 1 
                field[nx[0]][nx[1]] = "V"
                count = serch(nx, count)  
                continue
            if field[nx[0]][nx[1]] == "#":
                field[nx[0]][nx[1]] = "V"
                count = serch(nx, count)    
                 
    return count

X,Y,A,B,C=acinput()

p=acinput()
q=acinput()
r=acinput()



p=sorted(p,reverse=True)
q = sorted(q, reverse=True)
r=sorted(r, reverse = True)

tmp=p[:X]
tmp.extend(q[:Y])

tmp.extend(r)

tmp=sorted(tmp,reverse=True)

print(sum(tmp[:(X+Y)]))

Measured memory_bytes: 31604
#include<iostream>
#include<vector>
#include<utility>
#include<algorithm>
#include<string>
#include<cstdio>
#include<queue>
#include<functional>
#include<tuple>
#include<iomanip>
#include<stack>
#include<cmath>
#define int long long
#define INF 1<<40
#define N 100
using namespace std;
signed main() {
	string s; cin >> s;
	for (int i = 0; i < s.length(); ++i) cout << "x";
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<time.h>
#include<set>
#include<map>
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i>b;i--)
#define vint vector<int> 
#define vvint vector<vint>
#define ct(a) cout<<a<<endl
#define tget(a,b) get<a>(b)
using namespace std;
typedef long long ll;
const ll INF = 1e17;
const int MOD = 1e9 + 7;


ll N, K;
int main(void) {
	cin >> N >> K;
	if (N%2==0&&K<=N/2)ct("YES");
	else if (N%2==1&&(N + 1) / 2 >= K)ct("YES");
	else ct("NO");

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
#define acc(v) accumulate(v.begin(), v.end(), 0)
#define cinv(n,v) rep(i,n) cin >> v[i]
using namespace std;
const int INF = 1e9;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vint;
typedef vector<string> vstr;
typedef vector<char> vchar;
const ll LINF = 1e18;
const ll MOD = 1e9 + 7;
int x_pos[4] = {1,0,-1,0}, y_pos[4] = {0,1,0,-1};
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

char upper(char c){
	return c-0x20;
}

char lower(char c){
	return c+0x20;
}

void unique_vector(vector<int>& v){
	sort(all(v));
	v.erase(unique(all(v)), v.end());
}

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

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

int main() {
    ll n;cin>>n;
    ll tmp = n;
    int cnt = 0;
    while(tmp/10){
        cnt++;
        tmp /= 10;
    }
    if(cnt==0){
        cout << n << endl;
        return 0;
    }
    for(int i = 9; i>=1;i--){
        ll x = i;
        rep(j,cnt)x = x*10+9;
        if(x <= n){
            cout << i + 9*cnt << endl;
            return 0;
        }
    }
    cout << 9*cnt << endl;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#define N 100000
typedef struct p{
  char name[100];
  int o;
}P;
P U[N];
int head,t,n;
void enqueue(P a){
  U[t]=a;
  t=(t+1)%N;
}
P dequeue(){
  P a=U[head];
  head=(head+1)%N;
  return a;
}
int m(int x,int y){
  return x<y?x:y;
}
int main(){
  int s=0,c,i,q;
  P w;
  scanf("%d%d",&n,&q);
  for(i=1;i<n+1;i++){
    scanf("%s",U[i].name);
    scanf("%d",&U[i].o);
  }
  head=1;
  t=n+1;
  while(head!=t){
    w=dequeue();
    c=m(q,w.o);
    w.o=w.o-c;
    s=s+c;
    if(w.o>0) enqueue(w);
    else{
      printf("%s %d\n",w.name,s);
    }
  }
  return 0;
}



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

int main(){
    string s,t;
    cin>>s>>t;
    string str1;
    int ans=0;
    for(int i=0;i<=s.size()-t.size();i++){
        str1=s.substr(i,t.size());
        int cnt=0;
        for(int j=0;j<t.size();j++){
            if(t[j]==str1[j])cnt++;
        }
        ans=max(ans,cnt);
    }
    cout<<t.size()-ans<<endl;
    return 0;
}

Measured memory_bytes: 3576