akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	double a[110];
	cin>>n;
	double ave=0;
	for(int i=0;i<n;i++)
	   cin>>a[i],ave+=a[i];
	ave=ave/n;
	int pos=0;
	a[0]=abs(a[0]-ave);
	for(int i=1;i<n;i++)
	   {
	   	a[i]=abs(a[i]-ave);
	   	if(a[pos]>a[i])pos=i;
	   }
	
	cout<<pos;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
L = list(map(int,input().split()))
t = max(L)
maxstr = ''
cur = 1
while t >= cur:
    if t&cur != 0:
        maxstr = '1'+maxstr
    else:
        maxstr = '0'+maxstr
    cur *= 2
calc = [0]*len(maxstr)
for i in range(n):
    cur = 1
    temp = len(maxstr)-1
    while L[i] >= cur:
        if L[i]&cur != 0:
            calc[temp] += 1
        cur *= 2
        temp -= 1
ans = 0
cur = 1
for i in range(len(maxstr)):
    ans += cur*calc[len(maxstr)-i-1]*(n-calc[len(maxstr)-i-1])
    ans %= 10**9+7
    cur *= 2
print(ans)


Measured memory_bytes: 123056
#include <bits/stdc++.h>
typedef long long ll;
#define fr first
#define sc second
#define int ll

using namespace std;
const int MN = 21;
const int MK = 1e5+7;
const int MOD = 1e9+7;

int a[MN][MN];
int dp[1 << MN];

signed main(){
    int n, k;
    cin >> n;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            cin >> a[i][j];
        }
    }
    dp[0] = 1;
    for(int mask = 1; mask < (1 << n); mask++){
        int i = __builtin_popcount(mask)-1;
        for(int k = 0; (mask >> k) > 0; k++){
            if(!((mask >> k) & 1))continue;
            if(a[k][i])dp[mask] += dp[mask - (1 << k)];
            dp[mask] %= MOD;
        }
    }
    cout << dp[(1 << n)-1];
}


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

int main() {
  
  int A;
  int B;
  int K;
  cin >> K;
  cin >> A >> B;
  
  int i;
  i = 0;

  
  while(true) {
    if (A <= K*i && K*i <= B) {
      cout << "OK" << endl;
      break;
    }
    else {
      i++;
    }
    if (B < K*i) {
      cout << "NG" << endl;
      break;
    }
  }

}


Measured memory_bytes: 3628
N = list(input())
N.reverse()
if N[0] == '2' or N[0] == '4' or N[0] == '5' or N[0] == '7' or N[0] == '9':
    print('hon')
elif N[0] == '0' or N[0] == '1' or N[0] == '6' or N[0] == '8':
    print('pon')
else:
    print('bon')

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


int main (){

    long long int N,A,B;
    cin >> N >> A >> B;

    if(A > B) {
        cout << 0 << endl;
    }else if(N == 1 && A != B){
        cout << 0 << endl;
    }else {
        cout << (N - 2) * (B - A) + 1 << endl;
    }

    return 0;
}


Measured memory_bytes: 256
/*
    author: kartik8800
*/
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define fr(a,b) for(ll i = a; i < b; i++)
#define mod 1000000007
#define inf (1LL<<60)
#define all(x) (x).begin(), (x).end()
#define prDouble(x) cout << fixed << setprecision(10) << x 
#define triplet pair<ll,pair<ll,ll>>
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
using namespace std;

ll dp[3001][3001];
ll sum[3001][3001];

ll solve(vector<int>& v, int i, int j)
{
    if(i == j)
        return 0;
    if(dp[i][j] != -1)
        return dp[i][j];
    
    ll minCost = inf;
    for(int k = i; k < j; k++)
    {
            minCost = min(minCost, sum[i][j] + solve(v, i, k) + solve(v, k + 1, j));
    }
    return dp[i][j] = minCost;
}

void preprocess(vector<int>& v, int n)
{
    for(int i = 1; i  <= n; i++)
    {
        for(int j = i; j <= n; j++)
        {
            sum[i][j] = v[j] + ((j == i) ? 0 : sum[i][j-1]);
        }
    }
}
int main() {
   int n;
   cin >> n ;
   memset(dp, -1, sizeof dp);
   vector<int> v(n+1);
   for(int i = 1; i <= n; i++)
        cin>>v[i];
    preprocess(v,n);
   cout<<solve(v, 1, n);
   return 0;
}


Measured memory_bytes: 80128
import java.util.Scanner;

public class  Main{
	public static void main(String[] args)
	{
		Scanner sc =new Scanner(System.in);
		int a=sc.nextInt();
		int b=sc.nextInt();
		int total=a+b;
		
		if(total<10) System.out.println(total);
		else System.out.println("error");
	}
} 

Measured memory_bytes: 23764
const main = (input) => {
  var a = input[0]-0;
  var ans = 0;
  var b = input[1].split(" ").forEach(v=>{
    ans += 1/v;
  });
  console.log(1/ans);
}

main(require('fs').readFileSync('/dev/stdin', 'UTF-8').trim().split("\n"));


Measured memory_bytes: 21064
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
const int N=1e6+4;
ll inv[N];
double x,y;
inline void init() {
	inv[1]=1;
	for (register int i=2;i<N;i++)
		inv[i]=(MOD-(MOD/i))*inv[MOD%i]%MOD;
}
int main() {
	init();
	scanf("%lf%lf",&x,&y);
	double a=(x*2-y)/3,b=x-a*2;
	if (ceil(a)!=a||a<0||b<0) {
		puts("0");
		return 0;
	}
	int n=a+b;
	ll ans=1;
	for (register int i=1;i<=a;++i) {
		(ans*=(ll)(n-i+1))%=MOD;
		(ans*=inv[i])%=MOD;
	}
	printf("%lld\n",ans);
	return 0;
} 

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

int main()

{
	
	float a,b,c;
	cin >>a >>b >>c;
	if (max (a,max(b,c))==c)
	cout <<a*b/2;
	else if (max (a,max(b,c))==b)
	cout <<a*c/2;
	else 
	cout<< b*c/2;

}


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

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

    double a, b, x;
    cin >> a >> b >> x;

    double r;
    if(a * a * b / 2 <= x){
        r = atan((2 * a * a * b - 2 * x) / (a * a * a));
    }else{
        r = atan(a * b * b / (2 * x));
    }

    double ans = r * 180.0 / M_PI;

    cout << fixed << setprecision(15) << ans << endl;

    return 0;
}

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

// Begin Header {{{
using namespace std;

#ifndef DEBUG
#define dump(...)
#endif

#define all(x) x.begin(), x.end()
#define rep(i, n) for (intmax_t i = 0, i##_limit = (n); i < i##_limit; ++i)
#define reps(i, b, e) for (intmax_t i = (b), i##_limit = (e); i <= i##_limit; ++i)
#define repr(i, b, e) for (intmax_t i = (b), i##_limit = (e); i >= i##_limit; --i)
#define var(Type, ...) Type __VA_ARGS__; input(__VA_ARGS__)

constexpr size_t    operator""_zu(unsigned long long value) { return value; };
constexpr intmax_t  operator""_jd(unsigned long long value) { return value; };
constexpr uintmax_t operator""_ju(unsigned long long value) { return value; };

constexpr int INF = 0x3f3f3f3f;
constexpr intmax_t LINF = 0x3f3f3f3f3f3f3f3f_jd;

template <class T, class Compare = less<>>
using MaxHeap = priority_queue<T, vector<T>, Compare>;
template <class T, class Compare = greater<>>
using MinHeap = priority_queue<T, vector<T>, Compare>;

inline void input() {}
template <class Head, class... Tail>
inline void input(Head&& head, Tail&&... tail) {
    cin >> head;
    input(forward<Tail>(tail)...);
}

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

inline void output() { cout << "\n"; }
template <class Head, class... Tail>
inline void output(Head&& head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail)) {
        cout << " ";
    }
    output(forward<Tail>(tail)...);
}

template <class T>
inline ostream& operator<<(ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = {" ", ""};
    for (const auto &e: vec) {
        os << e << delim[&e == &vec.back()];
    }
    return os;
}

template <class T>
inline vector<T> makeVector(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeVector(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeVector<T>(initValue, args...))>(sz, makeVector<T>(initValue, args...));
}

template <class Func>
class FixPoint : Func {
public:
    explicit constexpr FixPoint(Func&& f) noexcept : Func(forward<Func>(f)) {}

    template <class... Args>
    constexpr decltype(auto) operator()(Args&&... args) const {
        return Func::operator()(*this, std::forward<Args>(args)...);
    }
};

template <class Func>
static inline constexpr decltype(auto) makeFixPoint(Func&& f) noexcept {
    return FixPoint<Func>{forward<Func>(f)};
}

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

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

template <class T>
inline T diff(const T &a, const T &b) noexcept {
    return a < b ? b - a : a - b;
}
// End Header }}}

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

    var(intmax_t, H, N);

    vector<intmax_t> a(N);
    input(a);

    cout << ((accumulate(all(a), 0_jd) >= H) ? "Yes" : "No") << "\n";

    return 0;
}


Measured memory_bytes: 1024
from bisect import bisect_left as lower_bound
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def MI(): return map(int, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YN = ['No', 'Yes']
MOD = 10**9+7
inf = float('inf')
IINF = 10**19
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']

show_flg = False
# show_flg = True


def main():
    N = I()
    XL = []
    ans = 0

    for i in range(N):
        x, l = MI()
        XL.append((x + l, x - l))

    # print(XL)
    XL.sort()

    cur = -10**19
    r = 0

    for i in range(N):
        if XL[i][1] >= cur:
            r += 1
            cur = XL[i][0]
        # print(i, cur)

    print(r)


if __name__ == '__main__':
    main()


Measured memory_bytes: 49496
class List:
    def __init__(self, value=None):
        self.value = value
        self.next = None
        self.prev = None

    def insert(self, value):
        node = self.__class__(value)
        node.prev, node.next = self.prev, self
        if self.prev is not None:
            self.prev.next = node
        self.prev = node
        return node

    def delete(self):
        p, n = self.prev, self.next
        self.prev, self.next = None, None
        if p is None:
            n.prev = None
        else:
            n.prev, p.next = p, n
        return n

    def move(self, i):
        node = self
        if i > 0:
            for _ in range(i):
                node = node.next
        else:
            for _ in range(-i):
                node = node.prev
        return node

    def __iter__(self):
        return List.ListIterator(self)

    class ListIterator:
        def __init__(self, node):
            while node.prev is not None:
                node = node.prev
            self.node = node

        def __iter__(self):
            return self

        def __next__(self):
            val = self.node.value
            if val is None:
                raise StopIteration
            self.node = self.node.next
            return val


def run():
    n = int(input())
    li = List()

    for _ in range(n):
        command = input()
        if command.startswith('0'):
            li = li.insert(int(command[2:]))
        elif command.startswith('1'):
            li = li.move(int(command[2:]))
        elif command.startswith('2'):
            li = li.delete()
        else:
            raise ValueError('invalid command')

    for v in li:
        print(v)


if __name__ == '__main__':
    run()



Measured memory_bytes: 89080
//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define bged(v) (v).begin(),(v).end()
#define foreach(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)
typedef long long ll;
const int Imx=2147483647;
const ll Lbig=2e18;
const int mod=1e9+7;
//My i/o stream
struct fastio
{
	char s[100000];
	int it,len;
	fastio(){it=len=0;}
	inline char get()
	{
		if(it<len)return s[it++];it=0;
		len=fread(s,1,100000,stdin);
		if(len==0)return EOF;else return s[it++];
	}
	bool notend()
	{
		char c=get();
		while(c==' '||c=='\n')c=get();
		if(it>0)it--;
		return c!=EOF;
	}
}_buff;
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putchar(' ')
#define putii(x,y) puti(x),puti(y)
#define putiii(x,y,z) putii(x,y),puti(z)
#define putsi(x) putnum(x),putchar('\n')
#define putsii(x,y) puti(x),putsi(y)
#define putsiii(x,y,z) putii(x,y),putsi(z)
inline ll getnum()
{
	ll r=0;bool ng=0;char c;c=_buff.get();
	while(c!='-'&&(c<'0'||c>'9'))c=_buff.get();
	if(c=='-')ng=1,c=_buff.get();
	while(c>='0'&&c<='9')r=r*10+c-'0',c=_buff.get();
	return ng?-r:r;
}
template<class T> inline void putnum(T x)
{
	if(x<0)putchar('-'),x=-x;
	register short a[20]={},sz=0;
	while(x)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1;i>=0;i--)putchar('0'+a[i]);
}
inline char getreal(){char c=_buff.get();while(c==' '||c=='\n')c=_buff.get();return c;}
int n;
ll t,a[2011],na[2011];
int main()
{
	getii(n,t);
	for(int i=0;i<n;i++)geti(a[i]);
	ll ans=1ll*mod*mod;
	for(int i=0;i<n;i++)
	{
		ll sum=t*i;
		for(int j=0;j<n;j++)sum+=a[j];
		ans=min(ans,sum);
		for(int j=0;j<n;j++)na[j]=min(a[j],a[(j+1)%n]);
		swap(a,na);
	}
	cout<<ans<<endl;
	return 0;
}


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

int main(){
  int M,N,x,y;
  cin>>N;
  x=0;
  vector<long long>a(N);
  for(int i=0;i<N;i++){
    cin>>a[i];
  }
    cin>>M;
  vector<long long>b(M);
  for(int i=0;i<M;i++){
    cin>>b[i];
  }
  if(N<M){
    cout<<"NO"<<endl;
    return 0;
  }
 sort(a.begin(),a.end());
  sort(b.begin(),b.end());

    for(int i=0;i<M;i++){
   for(int j=x;j<N;j++){
    if(b[i]==a[j]){
      x=j+1;
      break;
    }
     if(j==N-1){
       cout<<"NO"<<endl;
       return 0;
     }
  }
      if(x==N&&i!=M-1){
        cout<<"NO"<<endl;
        return 0;
      }
  }

        cout<<"YES"<<endl;

}


Measured memory_bytes: 3328
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
  int a,p;
  cin >> a >> p;
  cout << (3*a+p)/2 << endl;
return 0;}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//型に気を付けよう
//a=0x61=97 '0'=0x30=48
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long  ll;
typedef long double  ld;
typedef string str;
typedef pair<int,int> pairii;
typedef vector<int> veci;
const double pi=3.1415926535;
const ll  mod=1000000007;
//桁数指定　cout << fixed << setprecision(2)

ll sim( int x/*current score*/,vector<veci> s/*sid*/,veci &cc,veci c,int t,int l);

int main(){
  
  ll x=0;
  int d;cin>>d;
  veci c(26);
  rep(i,26)cin>>c[i];
  vector<veci> s(d);
  rep(j,d){
    rep(k,26){
      int tmp;
      cin>>tmp;
      s[j].push_back(tmp);
    }
  }
  
  
  veci cc(26,0);
  veci cb(26,0);
  
  rep(cn,d){
    int mem=0;ll ma=INT_MIN;
    rep(i,26){
      
      int cur=sim(x,s,cc,c,i,cn);
      if(ma<cur){mem=i;ma=cur;}
      cc=cb;
  }
    x=sim(x,s,cc,c,mem,cn);cerr<<x<<endl;
    cb=cc;
    cout<<mem+1<<endl;
  }
  return 0;
}
  
  ll sim( int x/*current score*/,vector<veci> s/*sid*/,veci &cc,veci c,int t,int l) {
   rep(ss,26)cc[ss]++;
    cc[t]=0;
    x+=s[l][t];
    rep(st,26)x-=cc[st]*c[st];
  return x;
}

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

using namespace std;


void pln()
{
	cout << endl;
	return;
}

void print(int x)
{
	cout << x << endl;
	return;
}

void print(string str) {
	cout << str << endl;
	return;
}

int ri() {
	int x;
	cin >> x;
	return x;
}

string rs() {
	string str;
	cin >> str;
	return str;
}

int main(void)
{
	int a = ri();
	int b = ri();

	int sum = a * b;

	if (sum%2==0)
	{
		print("Even");
	}
	else {
		print("Odd");
	}

}



Measured memory_bytes: 256
while True:
    s = input().split()
    H = int(s[0])
    W = int(s[1])
    if H==0 and W==0:
        break
    for i in range(H):
        for j in range(W):
            if i==0 or i==H-1:
                print("#",sep="",end="") #end="" eliminates '\n' 
            else:
                if j==0 or j==W-1:
                    print("#",sep="",end="") #end="" eliminates '\n' 
                else:
                    print(".",sep="",end="") #end="" eliminates '\n' 
        print("")

    #print blank
    print("")    



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

using namespace std;
using ll = long long;
using ld = long double;

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

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

  ll a;
  cin >> a;
  cout << a + (a * a) + (a * a * a) << '\n';

  return 0;
}


Measured memory_bytes: 3636
# -*- coding: utf-8 -*-
# モジュールのインポート
import sys

# 標準入力を取得
S = input()
T = input()

# 求解処理
ans = len(T)
for i in range(len(S) - len(T) + 1):
    diff = 0
    for j in range(len(T)):
        if T[j] != S[i + j]:
            diff += 1
    ans = min(ans, diff)

# 結果出力
print(ans)


Measured memory_bytes: 8920
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,i;
    cin>>n;
    char s[n],a[n];
    for(i=0;i<n;i++)
    {
        cin>>s[i];
       
    }
    for(i=0;i<n;i++)
     cin>>a[i];
    for(i=0;i<n;i++)
    {
        cout<<s[i];
        cout<<a[i];
    }
}

Measured memory_bytes: 3580
N,A,B=map(int, input().split())
ans=0

def my_sum(x):
  ret=0
  while x>0:
    ret+=x%10
    x=x//10
  return ret 

for i in range(N+1):
  if A<=my_sum(i)<=B:
    ans+=i

print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <set>
using namespace std;
typedef long long ll;

pair<vector<ll>, vector<ll>> prime_factor_decomp(ll n) {
    vector<ll> p, e;
    ll m = n;
    for (ll i = 2; i * i <= n; i++) {
        if (m % i != 0){
            continue;
        }
        int c = 0;
        while (m % i == 0){
            c++;
            m /= i;
        }
        p.push_back(i);
        e.push_back(c);
    }
    if (m > 1) {
        p.push_back(m);
        e.push_back(1);
    }
    return make_pair(p, e);
}

template<typename Int, Int MOD>
struct comb_util {
    int sz;
    vector<Int> mfact, minv_fact;
    comb_util(int N) : sz(N + 1), mfact(sz), minv_fact(sz) {
        mfact[0] = 1;
        for (int i = 1; i <= sz; i++) mfact[i] = mfact[i - 1] * i % MOD;
        minv_fact[sz] = inv(mfact[sz]);
        for (int i = sz - 1; i >= 0; i--) minv_fact[i] = minv_fact[i + 1] * (i + 1) % MOD;
    }

    // res = first * p^second
    pair<Int, Int> fact_willson(Int n) const {
        Int e = 0;
        if (n <= sz) return std::make_pair(mfact[n], 0);
        Int res;
        tie(res, e) = fact_willson(n / MOD);
        e += n / MOD;
        if ((n / MOD) % 2 != 0) res = MOD - res;
        return make_pair(res * mfact[n % MOD] % MOD, e);
    }

    // find n!
    Int fact(Int n) const { return mfact[n]; }

    // find n ** -1
    Int inv(Int n) const {
        return pow(n, MOD - 2);
    }

    // find n ** a
    Int pow(Int n, Int a) const {
        Int res = 1, exp = n;
        for(; a; a /= 2) {
            if (a & 1) res = res * exp % MOD;
            exp = exp * exp % MOD;
        }
        return res;
    }

    // find nPr
    Int perm(Int n, Int r) {
        if (r < 0 || n < r) return 0;
        else return mfact[n] * minv_fact[n - r] % MOD;
    }

    Int binom_lucus(Int n, Int r) const {
        if (n < 0 || r < 0 || n < r) return 0;
        assert(n <= sz);
        if (n >= MOD) return binom(n % MOD, r % MOD) * binom(n / MOD, r / MOD);
        else return r > n ? 0 : mfact[n] * minv_fact[n - r] * minv_fact[r];
    }

    // find nCr
    Int binom(Int n, Int r) const {
        if (n < 0 || r < 0 || n < r) return 0;
        return mfact[n] * minv_fact[r] % MOD * minv_fact[n - r] % MOD;
    }

    // find nHr
    Int homo(Int n, Int r) const {
        if (n < 0 || r < 0) return 0;
        return r == 0 ? 1 : binom(n + r - 1, r);
    }
};
using comb = comb_util<long long, 1000000007>;

int main(){
    ll n, m;
    const ll div = 1000000000 + 7;
    comb cm(2000010);
    cin >> n >> m;
    pair<vector<ll>, vector<ll>> p = prime_factor_decomp(m);
    ll ans = 1;
    for (ll i=0; i<(ll)p.first.size(); ++i){
        ans *= cm.binom(p.second[i] + n - 1, p.second[i]);
        // cout << p.first[i] << " -> " << p.second[i] << endl;
        ans = ans % div;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 31616
main :: IO ()
main = do
  n <- readLn
  s <- getLine
  print $ solve n s

solve :: Int -> String -> Int
solve n s = if length xs == 0 then n else snd (head xs)
  where
    xs = filter (\(a, b) -> a == "xx") $ zip (zipWith (\a b -> [a, b]) s (tail s)) [1..]

Measured memory_bytes: 10280
#include <bits/stdc++.h>
using namespace std;
#define retunr return
#define pb push_back
#define mp make_pair
#define null NULL
#define sc(x) scanf("%d", &x)
#define sc64(x) scanf("%I64d", &x)
#define pr(x) printf("%d", (x))
#define sp putchar(' ')
#define ln putchar('\n')
#define pr64(x) printf("%I64d", (x))
#define rep(i,l,r) for (int i = l, lim = r;i <= lim; ++i)
#define repr(i,l,r) for (int i = r, lim = l;i >= lim; --i)
#define fi first
#define se second
#define SET(__set, val) memset(__set, val, sizeof __set)
#define prf(x) printf("%.20f", x)
typedef unsigned int uint;
typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define N 100010
#define M 1024
#define MOD 1000000007
void _add(int &a, int b){a = (a+b)%MOD;}
void _sub(int &a, int b){a = (a+MOD-b)%MOD;}
void _mul(int &a, int b){a = (ll)a*b%MOD;}
void _max(int &a, int b){a = max(a,b);}
void _min(int &a, int b){a = min(a,b);}
ll gcd(ll a, ll b){if(!b)return a;return gcd(b,a%b);}
ll pw(ll a, ll b){ll res(1);while(b){if(b&1)res=res*a%MOD;a=a*a%MOD;b>>=1;}return res;}
ll pwM(ll a, ll b, ll mod){ll res(1);while(b){if(b&1)res=res*a%mod;a=a*a%mod;b>>=1;}return res;}

const int infi = 2147483647;
const ll infl = 9223372036854775807ll;
const db PI = 3.14159265358979323846;

/*
struct E{
	int v, w, n;
}G[N];
int cnt, point[N];
void adde(int u, int v, int w = 0){
	G[++cnt]=(E){v,w,point[u]},point[u]=cnt;
	G[++cnt]=(E){u,w,point[v]},point[v]=cnt;
}
void Ginit(){
	cnt = 0;
	SET(point,0);
}
*/
/*
struct hh{
	int a, b;
	bool operator < (const hh &x) const{
		if(a==x.a)return b<x.b;
		return a<x.a;
	}
}a[N];
*/
int n, m, k,q;
string s,t;
int main(){
//	freopen("1", "r", stdin);
	cin>>s>>t;
	s = s+s;
	int p = s.find(t);
	if(p<0)puts("No");
	else puts("Yes");
/*
	int Case;
	sc(Case);
	rep(ca, 1, Case){
	    printf("Case #%d: ", ca);
	}
*/
	return 0;
}


Measured memory_bytes: 256
import sys
## io ##
def IS(): return sys.stdin.readline().rstrip()
def II(): return int(IS())
def MII(): return list(map(int, IS().split()))
def MIIZ(): return list(map(lambda x: x-1, MII()))
## dp ##
def DD2(d1,d2,init=0): return [[init]*d2 for _ in range(d1)]
def DD3(d1,d2,d3,init=0): return [DD2(d2,d3,init) for _ in range(d1)]
## math ##
def to_bin(x: int) -> str: return format(x, 'b') # rev => int(res, 2)
def to_oct(x: int) -> str: return format(x, 'o') # rev => int(res, 8)
def to_hex(x: int) -> str: return format(x, 'x') # rev => int(res, 16)
MOD=10**9+7
def divc(x,y) -> int: return -(-x//y)
def divf(x,y) -> int: return x//y
def gcd(x,y):
    while y: x,y = y,x%y
    return x
def lcm(x,y): return x*y//gcd(x,y)
def enumerate_divs(n):
    """Return a tuple list of divisor of n"""
    return [(i,n//i) for i in range(1,int(n**0.5)+1) if n%i==0]
def get_primes(MAX_NUM=10**3):
    """Return a list of prime numbers n or less"""
    is_prime = [True]*(MAX_NUM+1)
    is_prime[0] = is_prime[1] = False
    for i in range(2, int(MAX_NUM**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i*2, MAX_NUM+1, i):
            is_prime[j] = False
    return [i for i in range(MAX_NUM+1) if is_prime[i]]
## libs ##
from itertools import accumulate as acc
from collections import deque, Counter
from heapq import heapify, heappop, heappush
from bisect import bisect_left
#======================================================#

def main():
    n = II()
    aa = MII()
    cnt = 3**n
    m = list(acc([2 if a%2==0 else 1 for a in aa ],lambda x,y: x*y))
    print(cnt-m[-1])


if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
#include <algorithm>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;

int main() {
  int N;
  while (cin >> N) {
    vector<int> A(N);
    for (int i = 0; i < N; i++) {
      cin >> A[i];
    }
    int res = 1, pre = 0;
    for (int i = 1; i < N; i++) {
      int cur = A[i] - A[i - 1];
      if (cur == 0) {
        continue;
      }
      if (pre == 0) {
        pre = cur;
        continue;
      }
      if ((pre < 0) ^ (cur < 0)) {
        ++res;
        pre = 0;
      }
    }
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb emplace_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
#define dame(a) {out(a);return 0;}
#define decimal cout<<fixed<<setprecision(15);
#define dupli(a) a.erase(unique(all(a)),a.end())
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef tuple<ll,ll,ll,ll> PPP;
typedef multiset<ll> S;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vvvvi=vector<vvvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
using vvb=vector<vb>;
const ll inf=1001001001001001001;
const ll INF=1001001001;
const ll mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outvvp(T v){rep(i,v.size())outvp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
void outs(ll a,ll b){if(a>=inf-100)out(b);else out(a);}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){ll res=1;a%=mod;while(b){if(b&1)res=res*a%mod;a=a*a%mod;b>>=1;}return res;}
vi dijkstra(int from,vvp g){
    vi dis(g.size(),inf);
    dis[from]=0;
    SPQ(P) pq;
    pq.push(P(0,from));
    while(!pq.empty()){
        auto t=pq.top();pq.pop();
        if(t.fi!=dis[t.se])continue;
        for(auto x:g[t.se]){
            if(chmin(dis[x.fi],t.fi+x.se))pq.push(P(dis[x.fi],x.fi));
        }
    }
    return dis;
}
int main(){
    ll n,m;cin>>n>>m;
    vvp g(n);
    rep(i,n-1)g[i+1].pb(i,0);
    rep(i,m){
        ll l,r,c;cin>>l>>r>>c;
        g[l-1].pb(r-1,c);
    }
    outs(dijkstra(0,g)[n-1],-1);
}

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

typedef long long ll;

string s;
ll mod = 998244353;
map<string, ll> f, g;

ll F(string s);

ll G(string s);

ll G(string s) {
	if(g[s]) return g[s];
	int n = s.size();
	if(n == 1) return s[0] - '0' + 1;
	for(int i = 1; i < n; i++) {
		if(n%i != 0) continue;
		string t;
		for(int j = 0; j < i; j++) {
			int p = 1;
			for(int k = 0; k < n/i; k++)
				if(s[j + k*i] == '0') p = 0;
			t += (char)('0' + p);
		}
		g[s] = (g[s] + F(t))%mod;
	} 
	return g[s];
}

ll F(string s) {
	if(f[s]) return f[s];
	int n = s.size();
	if(!n) return f[s] = 1;
	for(int i = 1; i <= n; i++) 
		f[s] = (f[s] + G(s.substr(0, i))*F(s.substr(i, n - i))%mod)%mod;
	return f[s]; 
}

int main() {
	cin>>s;
	cout<<F(s);
	return 0;
}

Measured memory_bytes: 12928
N, K = map(int, input().split())
P = list(map(int, input().split()))
C = list(map(int, input().split()))

result = -float('inf')
for i in range(N):
    p = P[i] - 1
    c = C[p]
    k = K - 1
    t = c
    while p != i and k != 0:
        p = P[p] - 1
        c += C[p]
        t = max(t, c)
        k -= 1
    if k == 0 or c <= 0:
        result = max(result, t)
        continue
    l = K - k
    c = c * (K // l - 1)
    k = K - (K // l - 1) * l
    t = c
    while k != 0:
        p = P[p] - 1
        c += C[p]
        t = max(t, c)
        k -= 1
    result = max(result, t)
print(result)


Measured memory_bytes: 74036
import java.util.*;


public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated m ethod stub
		Scanner sc = new Scanner(System.in); 
		int X = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();
		
		int result = (X-A)%B;
		System.out.println(result);
	}

} 

Measured memory_bytes: 23764
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int main(){

    ll H, W;
    cin >> H >> W;
    if(H == 1 && W == 1)cout << 1 << endl;
    else if(H == 1)cout << W - 2 << endl;
    else if(W == 1)cout << H - 2 << endl;
    else cout << (H - 2) * (W - 2) << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		ArrayList<Integer> value = new ArrayList<>();
		for(int i = 0; i < N; i++) {
			value.add(Integer.parseInt(sc.next()));
		}
		sc.close();

		Collections.sort(value);

		double tmp = (double)(value.get(0) + value.get(1)) / 2;
		if(N == 2) {
			System.out.println(tmp);
			return;
		}else {
			for(int i = 2; i < value.size(); i++) {
				tmp = (double) (tmp + value.get(i)) / 2;
			}
			System.out.println(tmp);
			return;
		}
	}

}

Measured memory_bytes: 23892
X, Y = map(int, input().split())
index = 0

for i in range (0, X + 1):
    tsuru = i
    kame = X - i
    if tsuru*2 + kame*4 == Y:
        index = 1
        break

if index == 1:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 9168
#include <stdio.h>

int main(void){
	int a, b, c, temp;
	
	scanf("%d %d %d", &a, &b, &c);
	
	if(a > b){
		temp = a;
		a = b;
		b = temp;
	}
	
	if(b > c){
		temp = b;
		b = c;
		c = temp;
	}
	
	if(a > b){
		temp = a;
		a = b;
		b = temp;
	}
	
	printf("%d %d %d\n", a, b, c);
	
	return 0;
}

Measured memory_bytes: 596
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;
procedure abc170a is
	x   : Integer;
	tmp : Integer;
begin
	get(x);
	get(tmp);
	x := x + tmp;
	get(tmp);
	x := x + tmp;
	get(tmp);
	x := x + tmp;
	get(tmp);
	x := x + tmp;
	put(Integer'Image(15-x));
end abc170a;

Measured memory_bytes: 3664
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
#define rep(i, n)   for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

int main(){
    int n,k;    cin>>n>>k;
    vector<ll>x(n);
    rep(i, n)   cin>>x[i];
    ll ans = 1e12;
    rep(i, n-k+1){
        ans = min(ans, abs(x[i]) + abs(x[i+k-1]-x[i]));
        ans = min(ans, abs(x[i+k-1]) + abs(x[i+k-1]-x[i]));
    }
    cout<<ans<<endl;
}


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

struct t3
{
	int a,b,c;
}arr[100001];

int n;
int memo[100001][3];

int VACA(int i, int ch)
{
	if(i == n)
	return 0;
	if(memo[i][ch] != -1)
	return memo[i][ch];
	int ans = 0;
	if(!i)
	{
		for(int j=0;j<3;j++)
		{
			if(j == 0)
			ans = std::max(ans, arr[i+1].a + VACA(i+1, j));
			else if(j == 1)
			ans = std::max(ans, arr[i+1].b + VACA(i+1, j));
			else if(j == 2)
			ans = std::max(ans, arr[i+1].c + VACA(i+1, j));	
		}	
	}	
	else
	{
		for(int j=0;j<3;j++)
		{
			if(j != ch)
			{	
				if(j == 0)
				ans = std::max(ans, arr[i+1].a + VACA(i+1, j));
				else if(j == 1)
				ans = std::max(ans, arr[i+1].b + VACA(i+1, j));
				else if(j == 2)
				ans = std::max(ans, arr[i+1].c + VACA(i+1, j));	
			}
		}	
	}
	memo[i][ch] = ans;
	return ans;
}

int main(void)
{
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(NULL);
	std::cout.tie(NULL);
	memset(memo, -1, sizeof(memo));
	std::cin>>n;
	for(int i=1;i<=n;i++)
	std::cin>>arr[i].a>>arr[i].b>>arr[i].c;
	int ans = VACA(0, 0);	
	std::cout<<ans<<"\n";
	return 0;
}

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

int main() {
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    int start = max(a,c);
    int end = min(b,d);
    
    if(end-start<=0) cout << 0 << endl;
    else cout << end-start << endl;
    }

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

int main(){
  int a,b,i,j,s,k,res = 0;
  float sum;
  
  scanf("%d %d",&a,&b);
  int map[a][b];
  for(i = 0;i < a;i++){
    for(j =0;j < b;j++){
      scanf("%d",&map[i][j]);
    }
  }
  
  for(i = 0;i < a - 1;i++){
    for(j = i + 1;j < a;j++){
      for(k = 0,sum = 0;k < b;k++){
        sum += pow(map[i][k] - map[j][k],2);
      }
      float tmp = sqrt(sum);
      float tmpo = floorf(tmp);
      if(tmp - tmpo == 0){
        res++;
      }
    }
  }

  printf("%d",res);
  return 0;
}

Measured memory_bytes: 128
n,m = map(int,input().split())
d = []
for i in range(1,int(m ** (1/2)) + 1):
    if m % i == 0:
        d.append(i)
        d.append(m//i)

d = sorted(d,reverse = True)
#print(d)

for j in range(len(d)):
    if m // d[j] >= n:
        print(d[j])
        break

Measured memory_bytes: 3060
use std::io;

fn main() {
    let mut line = String::new();
    io::stdin().read_line(&mut line).ok();

    let output = line.chars().map(|c| {
        if c.is_lowercase() { c.to_uppercase().to_string() } else { c.to_lowercase().to_string() }
    }).collect::<String>();

    print!("{}", output);
}



Measured memory_bytes: 5044
import numpy as np

# i 番目のブロックを取り除くときに、i 番目のブロックが
# i+k 番目のブロックが連結であるということは
# i, i+1, ..., i+k 番目のブロックのうち i 番目のブロックを取り除くのが
# 最も早いということである
# したがって、i 番目のブロックを取り除くとき、
# k 個隣のブロックは 1/(k+1) の確率で連結である

def make_modinv_list(n, mod=10**9+7):
    # 0 から n までの mod 逆元のリストを返す O(n)
    modinv = [0, 1]
    for i in range(2, n+1):
        modinv.append(mod - mod//i * modinv[mod%i] % mod)
    return modinv

def garner(A, M, mod):
    # Garner のアルゴリズム
    # 参考: https://math314.hateblo.jp/entry/2015/05/07/014908
    M.append(mod)
    coffs = [1] * len(M)
    constants = np.zeros((len(M),) + A[0].shape, dtype=np.int64)
    for i, (a, m) in enumerate(zip(A, M[:-1])):
        v = (a - constants[i]) * pow(coffs[i], m - 2, m) % m
        for j, mm in enumerate(M[i + 1:], i + 1):
            constants[j] = (constants[j] + coffs[j] * v) % mm
            coffs[j] = coffs[j] * m % mm
    return constants[-1]

# for i in range(100000, 100000+100):
#     if miller_rabin(i):
#         print(i)

def convolve_mod(A, B, mod=10**9+7):
    # 任意 mod 畳み込み
    #mods = [1000003, 1000033, 1000037, 1000039]  # 要素数が 10**3 程度の場合（誤差 6*2+3=15<16  復元 6*4=24>21=9*2+3）
    mods = [100003, 100019, 100043, 100049, 100057]  # 要素数が10**5 程度の場合（誤差 5*2+5=15<16  復元 5*5=25>23=9*2+5）
    mods_np = np.array(mods, dtype=np.int32)
    fft, ifft = np.fft.rfft, np.fft.irfft
    a, b = len(A), len(B)
    if a == b == 1:
        return np.array([A[0] * B[0]]) % mod
    n = a + b - 1  # 畳み込みの結果の長さ
    k = 1 << (n - 1).bit_length()  # n 以上の最小の 2 冪
    AB = np.zeros((2, len(mods), k), dtype=np.int64)  # ここの dtype は fft 後の dtype に関係しない
    AB[0, :, :a] = A
    AB[1, :, :b] = B
    AB[:, :, :] %= mods_np[:, None]
    C = ifft(fft(AB[0]) * fft(AB[1]))[:, :n]
    C = ((C + 0.5) % mods_np[:, None]).astype(np.int64)
    assert (C>=0).all()
    return garner(C, mods, mod)

def main():
    mod = 10**9+7
    N = int(input())
    A = np.array(list(map(int, input().split())))
    modinv_list = np.array(make_modinv_list(N, mod))
    C = np.zeros(N*2-1, dtype=np.int64)  # 確率
    C[N-1:] = modinv_list[1:]
    C[:N] = modinv_list[:0:-1]
    Ans = convolve_mod(C, A, mod)
    frac_N = 1
    for i in range(2, N+1):
        frac_N = frac_N * i % mod
    print(Ans[N-1:2*N-1].sum() % mod * frac_N % mod)

main()


Measured memory_bytes: 157656
import java.util.*;

public class Main{
    public static void main(String[] args){

        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();

        int minN = 1;
        int maxN = 10000;
        if(N < minN || N > maxN ){
            return;
        }

        if(N % 1000 == 0){
            System.out.println(0);
        }else{
            System.out.println( 1000 - N % 1000 );
        }
    }
}

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

public class Main{
	public static void main(String args[]){
		try{
			new Main();
		}catch(IOException e){
			e.printStackTrace();
		}
	}
	
	public final String[] SHOP = {"A", "B", "C", "D", "E"};
	
	public Main() throws IOException{
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String line;
		
		while(true){
			Shop[] shops = new Shop[5];
			for(int i=0; i<5; i++){
				line = in.readLine();
				String[] tmp = line.split(" ");
				int am = Integer.parseInt(tmp[0]);
				int pm = Integer.parseInt(tmp[1]);
				if(am==0 && pm==0) return;
				shops[i] = new Shop(SHOP[i], am + pm);
			}
			Arrays.sort(shops, new shop_comparator());
			
			System.out.printf(shops[4].name + " %d\n", shops[4].sales);
		}
	}
}

class shop_comparator implements Comparator<Shop>{
	public int compare(Shop s1, Shop s2){
		return s1.sales - s2.sales;
	}
}

class Shop{
	String name;
	int sales;
	
	public Shop(String name, int sales){
		this.name = name;
		this.sales = sales;
	}
}

Measured memory_bytes: 12000
import sys
import math
from functools import reduce
from operator import mul
sys.setrecursionlimit(10**6)

def InMap(): return list(map(int, sys.stdin.readline().split(' ')))
def In(): return int(sys.stdin.readline())
def InS(): return sys.stdin.readline()

S = InS()[:-1]

if S[2] == S[3]:
    if S[4] == S[5]:
        print('Yes')
        sys.exit()

print('No')

Measured memory_bytes: 3828
using System;
using System.Linq;

public class B{
  static void Main(string[] args)
  {
    var inputs = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
    Console.WriteLine(inputs[0] % 2 == 1 && inputs[1] % 2 == 1 ? "Yes" : "No");
  }
}

Measured memory_bytes: 11092
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define MAX 2000000
#define INFTY (1<<30)

int H, A[MAX + 1];

void maxHeapify(int i) {
	int l, r, largest;
	l = 2 * i;
	r = 2 * i + 1;
	if (l <= H && A[l] > A[i]) largest = l;
	else largest = i;
	if (r <= H && A[r] > A[largest]) largest = r;
	if (largest != i) {
		swap(A[i], A[largest]);
		maxHeapify(largest);
	}
}

int extract() {
	int maxv;
	if (H < 1) return -INFTY;
	maxv = A[1];
	A[1] = A[H--];
	maxHeapify(1);
	return maxv;
}
void increaseKey(int i, int key) {
	if (key < A[i]) return;
	A[i] = key;
	while (i > 1 && A[i / 2] < A[i]) {
		swap(A[i], A[i / 2]);
		i = i / 2;
	}
}
void insert(int key) {
	H++;
	A[H] = -INFTY;
	increaseKey(H, key);
}

int main() {
	int key;
	char com[10];
	while (1) {
		scanf("%s", com);
		if (com[0] == 'e' && com[1] == 'n') break;
		if (com[0] == 'i') {
			scanf("%d", &key);
			insert(key);
		}
		else printf("%d\n", extract());
	}
	return 0;
}


Measured memory_bytes: 6592
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
#define F firt
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for(int i=a;i<=b;i++)
int main()
{
  int a,b;cin>>a>>b;cout<<a*b<<endl;
   return 0;
} 


Measured memory_bytes: 3632
/*
     _              ,_,                 
    / \   _ __, ___,| |__   __ _,_ __  
   / ^ \ | '_ \/ _ \| '_ \ / _` | /_/  
  /-/-\-\|-| |--| |-|-|_)-|-(_|-|-|    
 /_/   \_\_| |__| |_|_.__/ \__,_|_|    
 
*/
#include <bits/stdc++.h>
using namespace std;
 
#define int long long int
#define ld long double
#define ll long long
#define pb push_back
#define F first
#define S second
#define all(a)       (a).begin(),(a).end()
#define rep(i,a,n)   for(int i=a ; i<n ; i++)
 
typedef vector<ll> vi;
typedef pair<ll,ll> pii;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef map<ll,ll> mii;
typedef map<char,ll> mci;
 
ll gcd(ll a, ll b){
	if(b==0)return a;
	else return gcd(b, a%b);
}

signed main(){
    ll test=1;
    // cin>>test;
    while(test--){
        ll n, w; cin>>n>>w;
        vi wt(n), val(n);
        rep(i, 0, n)cin>>wt[i]>>val[i];
        ll dp[n+1][w+1];
        memset(dp, 0, sizeof(dp));
        for(int i=1; i<n+1; i++){
        	for(int j=1; j<w+1; j++){
        		if(j>=wt[i-1])dp[i][j]=max(dp[i-1][j], val[i-1]+dp[i-1][j-wt[i-1]]);
        		else dp[i][j]=dp[i-1][j];
        	}
        }
        cout<<dp[n][w]<<endl;
 
    }    
}

Measured memory_bytes: 82380
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
#define MAXN 50

int main(int argc,char const* argv[])
{
  int n,k,i,ans=0;
  cin >> n >> k;
  vector<int> l(MAXN,0);
  for(i=0;i<n;i++)
    {
      cin >> l[i];
    }
  sort(l.begin(),l.end());
  for(i=MAXN-1;i>MAXN-1-k;i--)
    {
      ans+=l[i];
    }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
//Therefore, the optimal
//choice of vertex that Takahashi will be cornered into is ”the furthest vertex from Aoki which
//Takahashi can reach before Aoki can.” This can be obtained by calculating the distance from u
//and v by DFS or BFS, 
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < (int)b; i++)
#define all(v) v.begin(), v.end()
const int MOD = 1e9 + 7;
const int INF = 1e9;
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int n;
vector<vector<int>> g(100010);
int dist1[100010], dist2[100010];

void dfs1(int v, int p) {
    for (int nv : g[v]) {
        if (nv == p) continue;
        dist1[nv] = dist1[v] + 1;
        dfs1(nv, v);
    }
}

void dfs2(int v, int p) {
    for (int nv : g[v]) {
        if (nv == p) continue;
        dist2[nv] = dist2[v] + 1;
        dfs2(nv, v);
    }
}

int main() {
    int n, u, v;
    cin >> n >> u >> v;
    u--;
    v--;
    rep(i, 0, n - 1) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    dfs1(u, -1);
    dfs2(v, -1);

    int ans = 0;
    rep(i, 0, n) {
        if (dist1[i] < dist2[i]) ans = max(ans, dist2[i]);
    }
    cout << ans - 1 << endl;
    return 0;
}


Measured memory_bytes: 10368
S = input()
l = ['eraser', 'erase', 'dreamer','dream']

s = "".join(S[-1::-1].split(l[0][-1::-1]))

for i in range(1, 4):
    s = "".join(s.split(l[i][-1::-1]))

print("YES") if s == "" else print("NO")


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

int main() {

  long long N, M;

  cin >> N >> M;
  vector <pair<int, int>> pairs(N);

  rep(i, N)
  {
    int A , B;
    cin >> A >> B;
    pairs[i] = make_pair(A, B);
  }
  sort(pairs.begin(), pairs.end());

  long long buy_count = 0;
  long long price = 0;
  rep(i, N)
  {
      long long buy_price = pairs[i].first;
      price += buy_price * pairs[i].second;
      buy_count += pairs[i].second;
      if(buy_count >= M)
      {
        price -= buy_price * pairs[i].second;
        buy_count -= pairs[i].second;
        long rest = M - buy_count;
        price += rest * buy_price;
        break;
      }
  }
  cout << price << endl;
  return 0;  
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <math.h>

#define MOD 1000000007
#define REP(i,n) for ((i)=0;i<(n);i++)
#define SET(a,c) memset(a,c,sizeof a)
#define CLR(a) memset(a,0,sizeof a)
#define MIN(a,b) (a>b?b:a)
#define MAX(a,b) (a>b?a:b)
#define LL long long
#define ULL unsigned long long

int compare_ll(const void *a, const void *b){
	return *(ULL*)b - *(ULL*)a;
}

int compare_int(const void *a, const void *b)
{
    return *(int*)b - *(int*)a;
}

int main(void) {

	int a,b,c;

	scanf("%d %d %d", &a, &b, &c);

	if(a == b+c || b == a+c || c == a+b){
		puts("Yes");
	}else{
		puts("No");
	}


	return 0;
}

/* 最後の改行忘れるな！！ */


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
signed main(){
  int N; cin>>N;
  int ans=N*N*3;
  cout<<ans<<endl;
  }


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

#define MAXN 2010
#define mod 1000000007

int n,k,fac[MAXN*MAXN],inv[MAXN*MAXN],f[MAXN][MAXN];

int qpow(int a,int b)
{
	int res=1;
	while(b)
	{
		if(b&1)res=(long long)res*a%mod;
		a=(long long)a*a%mod;
		b>>=1;
	}
	return res;
}

int c(int n,int m)
{
	if(n<0 || n<m)return 0;
	return (long long)fac[n]*inv[m]%mod*inv[n-m]%mod;
}

int main()
{
	scanf("%d%d",&n,&k);
	if(k==1)
	{
		puts("1");
		return 0;
	}
	fac[0]=inv[0]=1;
	for(int i=1;i<=n*k;++i)fac[i]=(long long)fac[i-1]*i%mod;
	inv[n*k]=qpow(fac[n*k],mod-2);
	for(int i=n*k-1;i>=1;--i)inv[i]=(long long)inv[i+1]*(i+1)%mod;
	f[0][0]=1;
	for(int i=0;i<=n;++i)
		for(int j=i;j>=0;--j)
		{
			f[i+1][j+1]=(f[i+1][j+1]+(long long)f[i][j]*c(i*k-j+k-2,k-2)%mod)%mod;
			if(j)f[i][j-1]=(f[i][j-1]+f[i][j])%mod;
		}
	printf("%lld\n",(long long)f[n][0]*fac[n]%mod);
}

Measured memory_bytes: 46592
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,m,s,x;
  cin>>n>>m;
  int i;
  priority_queue<int> q;
  for(i=0;i<n;i++){
   cin>>x;
   q.push(x);
}
  for(i=0;i<m;i++){
    s=q.top();
    q.pop();
    q.push(s/2);
}
  int64_t ans=0;
  while(!q.empty()){
   ans+=q.top();
   q.pop();
}
  cout<<ans;
  return 0;
}

Measured memory_bytes: 892
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
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;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (int i = 0; i < sz(v); i++) {
        os << v[i];
        if (i < sz(v) - 1) os << " ";
    }
    return os;
}
int main() {
    int n;
    cin >> n;
    if (n % 1000 == 0)
        cout << 0 << endl;
    else
        cout << 1000 - n % 1000 << endl;
}

Measured memory_bytes: 3628