akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int k = sc.nextInt();
        int saidai = 0;
        for(int i = 0; i < a; i++){
            saidai = saidai + 1;
            k = k - 1;
            if(k == 0){
                System.out.println(saidai);
                System.exit(0);
            }
        }
        for(int i = 0; i<b; i++){
            k = k - 1;
            if(k == 0){
                System.out.println(saidai);
                System.exit(0);
            }
        }
        for(int i = 0; i < c; i++){
            saidai = saidai - 1;
            k = k - 1;
            if(k==0){
                System.out.println(saidai);
                System.exit(0);
            }
        }
    }        
}

Measured memory_bytes: 35928
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair <int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int mod = 1e9 + 7;
const char nl = '\n';

void solve() {
    ll n, x, ans(0);
    cin >> n >> x;
    vl a(10000000);
    for(int i = 0; i < n; ++i){
        cin >> a[i];
    }
    for(int i = 0; i < n - 1; ++i){
        if((a[i] + a[i + 1]) > x){
            ans += (a[i] + a[i + 1] - x);
            a[i + 1] = a[i + 1] - (a[i] + a[i + 1] - x);
            if(a[i + 1] < 0){
                a[i] += a[i + 1];
                a[i + 1] = 0;
            }
        }
    }
    cout << ans << nl;
}

int main() {
#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    solve();
    return 0;
}

Measured memory_bytes: 78336
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define PB push_back
#define MP make_pair
#define ll long long

inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}

int main(){
    std::ios::sync_with_stdio(false);
    int n,m,x,y,z;
    cin >> n >> m;
    vector<int> edges[n];
    for(int i=0;i<m;++i)
    {
        cin >> x >> y >> z;
        x--;
        y--;
        edges[x].push_back(y);
        edges[y].push_back(x);
    }

    bool visited[n] = {};
    int res = 0;
    for(int i=0;i<n;++i)
    {
        if(!visited[i])
        {
            res++;
            deque<int> q;
            q.push_back(i);
            visited[i] = true;
            while(!q.empty())
            {
                int src = q.front();
                q.pop_front();
                for(int dst: edges[src])
                {
                    if(!visited[dst])
                    {
                        visited[dst] = true;
                        q.push_back(dst);
                    }
                }
            }
        }
    }
    cout << res << endl;

}

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

const int mod = 1000000007;

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

    int n;
    cin >> n;

    vector<ll> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];

    ll ans = 0;

    for(int i = 0; i < 60; i++){
        ll cnt_1 = 0;
        for(int j = 0; j < n; j++){
            if(a[j] >> i & 1) cnt_1++;
        }
        ll add = cnt_1 * (n - cnt_1) % mod;
        for(int j = 0; j < i; j++){
            add = add * 2 % mod;
        }
        ans += add;
        ans %= mod;
    }
    cout << ans << endl;
}

Measured memory_bytes: 2560
#include <cstdio>
#include <algorithm>
#include <queue>

int ts[100005];

int main(){
  int N,C,K;
  scanf("%d %d %d",&N,&C,&K);
  for(int i=0;i<N;i++){
    scanf("%d",&ts[i]);
  }
  std::sort(ts,ts+N);
  int cost=0;
  int part=0;
  std::priority_queue<int> buses;
  for(int i=0;i<N;i++){
    while(buses.size()&&-buses.top()<ts[i]){
      buses.pop();
      part=0;
    }
    if(buses.empty()){
      buses.emplace(-ts[i]-K);
      cost++;
    }
    if(++part==C){
      buses.pop();
      part=0;
    }
  }
  printf("%d\n",cost);
  return 0;
}


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

int main(){
  int N;
  string S;
  cin >> N >> S;
  
  int ans = 0;
  for (int pos = 0; pos < N; pos++){
    vector<bool> check(1000, false);
    int num = 0;
    
    for (int i = 0; i < pos; i++){
      check.at(S.at(i)) = true;
    }
    
    for (int i = pos; i < N; i++){
      if (check.at(S.at(i)) == true){
        num++;
        check.at(S.at(i)) = false;
      }
    }
    
    ans = max(ans, num);
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3592
import heapq
import sys

input = sys.stdin.readline

def dijkstra_heap(s,edge):
    #始点sから各頂点への最短距離
    d = [10**20] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d

################################
n,w,s = map(int,input().split()) #n:頂点数　w:辺の数

edge = [[] for i in range(n)]
#edge[i] : iから出る道の[重み,行先]の配列
for i in range(w):
    x,y,z = map(int,input().split()) #0-indexed
    edge[x].append([z,y])
for i in dijkstra_heap(s,edge):
    if i==10**20:
        print('INF')
    else:
        print(i)


Measured memory_bytes: 98232
#include<iostream>

using namespace std;

int main(){
  int a1, a2, a3, sum;
  
  cin >> a1 >> a2 >> a3;
  
  sum = a1 + a2 + a3;
  
  if(sum<=21){
    cout << "win" <<endl;
  }
  else if(sum >= 22){
    cout << "bust" <<endl;
  }
}

Measured memory_bytes: 256
import scala.io.Source
import scala.math._

object Main{
  def main(args: Array[String]){
    val lines = for{
      in <- Source.stdin.getLines.toList
    }yield in.toString.split(" ").toList.map(_.toInt)

    println(dimDis(lines(1), lines(2), 1).sum)
    println(sqrt(dimDis(lines(1), lines(2), 2).sum))
    println(pow(dimDis(lines(1), lines(2), 3).sum, (1.0/3.0)))
    println(dimDis(lines(1), lines(2), 1).max)
  }

  def dimDis(from: List[Int], to: List[Int], n: Int): List[Double] ={
    if(from == Nil) List()
    else if(to == Nil) List()
    else pow(abs(from.head - to.head), n) :: dimDis(from.tail, to.tail, n)
  }
}

Measured memory_bytes: 44120
#include<iostream>
using namespace std;
int main (void){

    int p, q, r, a, b, c, min;

    cin >> p >> q >> r;

    a = p + q;
    min = a;
    b = q + r;
    if(b < min)
    min = b;


    c = r + p;
    if(c< min)
    min = c;
    cout << min << endl;

    return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"sort"
)

func main() {
	nums := make([]int, 3)
	for i := 0; i < 3; i++ {
		fmt.Scan(&nums[i])
	}
	sort.Ints(nums)
	fmt.Println(nums[2] - nums[0])
}


Measured memory_bytes: 512
n = gets.to_i
a = Array.new(n).map{[0,0]}
n.times do |i|
    a[i] = [gets.to_i,i%2]
end
a.sort!
ans = 0
((n+1)/2).times do |i|
    ans += 1 if a[i*2][1] == 1
end
puts ans

Measured memory_bytes: 17400
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#include<random>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n * m) / gcd(n, m);//gl=xy
}
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
using namespace std;

//ここから

void solve(){
  ll n;
  cin>>n;
  for(ll i=1;i<=3500;++i){
    for(ll j=1;j<=3500;j++){
      ll x=4*i*j-n*i-n*j;
      if(x==0)continue;
      if(((n*i*j)/x>0)&&((n*i*j)%x==0)){
        cout<<i<<" "<<j<<" "<<(n*i*j)/x<<endl;
        return;
      }
    }
  }
}

int main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
	cout<<fixed<<setprecision(15);
  solve();
	return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;


public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			final int m = sc.nextInt();
			final int n = sc.nextInt();
			
			if(m == 0 && n == 0){
				break;
			}
			
			int[] books = new int[n];
			for(int i = 0; i < n; i++){
				books[i] = sc.nextInt();
			}
			
			int upper = 1000000 * n;
			int lower = 1;
			
			while((upper - lower) != 1){
				int med = (upper + lower) / 2;
				
				//System.out.println(med);
				
				int col = 0;
				int wid = 0;
				boolean flag = true;
				for(int i = 0; i < n; i++){
					if(col >= m){
						flag = false;
						break;
					}
					
					if(wid + books[i] > med){
						col++;
						i--;
						wid = 0;
					}else{
						wid += books[i];
					}
				}
				
				if(!flag){
					lower = med;
				}else{
					upper = med;
				}
			}
			
			System.out.println(upper);
		}

	}

}

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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    set<int> s;
    for (int i = 0; i < n; i++) {
        int d;
        cin >> d;
        s.insert(d);
    }
    cout << s.size() << '\n';
    return 0;
}

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

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define AND(x,y,z) 
#define DUMP(xs) for (auto x:xs) cout<<x<<' ';cout<<endl
#define DUMPP(xs) for (auto x:xs) cout<<'('<<x.first<<','<<x.second<<')';cout<<endl
#define FOR(i,a,b) for (ll i=(ll)(a);i<(ll)(b);++i)
#define OUT(x) cout<<x<<endl
#define REP(i,n) FOR(i,0,n)
#define YES(cond) cond ? OUT("YES") : OUT("NO")
#define Yes(cond) cond ? OUT("Yes") : OUT("No")

template<class T> T gcd(const T x,const T y){if(!y){return x;}return gcd(y,x%y);}
template<class T> T lcm(const T x,const T y){return x/gcd(x,y)*y;};
template<class T> T modpow(const T x,const T n,const T mod) {
  T res=1;while(n>0){if(n%2)res=res*x%mod;x=x*x%mod;n/=2;};return res;
}
template<class T> bool alltrue(const T &a){return all_of(ALL(a),[](bool x){return x;});}
template<class T> bool anytrue(const T &a){return any_of(ALL(a),[](bool x){return x;});}
template<class T> bool contain(const T &a,const T &b){for(auto x:b){if (a.find(x)==a.end()){return false;}}return true;}
template<class T> bool mmax(T &m,const T q){ if (m < q) {m = q; return true;} else return false; }
template<class T> bool mmin(T &m,const T q){ if (m > q) {m = q; return true;} else return false; }
template<class T> int siz(const T &a) {return (int)a.size();}
template<class T> set<T> devisers(T n) {
  set<T> res;for(T i=1;i<(T)sqrt(n)+1;i++){if(n%i==0){res.insert(i);res.insert(n/i);}}return res;
}
template<class T> void concat(T &a, const T &b){a.insert(a.end(),b.begin(),b.end());}
template<class T> void getand(const T &a,const T &b,T &c) {
  set_intersection(a.begin(),a.end(),b.begin(),b.end(),inserter(c,c.end()));
}
template<class T> void getor(const T &a,const T &b,T &c) {
  set_union(a.begin(),a.end(),b.begin(),b.end(),inserter(c,c.end()));
}

typedef long long ll;
typedef pair<ll, ll> P;

const int MOD=1e9+7;

int calc(int v, vector<vector<int>> &G, vector<int> &d) {
  int res = 1;
  for (int nv:G[v]) {
    if (d[nv]==0) {
      OUT(-1);
      exit(0);
    }
    if (d[nv]==-1) {
      d[nv] = 0;
      d[nv] = calc(nv,G,d);
    }
    mmax(res,d[nv]+1);
  }

  return res;
}

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

  // code
  vector<int> offset(N-1,0);
  REP(i,N-2) offset[i+1] = offset[i]+(N-i-1);
  auto code = [&](int i,int j) -> int {
    if (i>j) swap(i,j);
    return offset[i]+(j-i-1);
  };

  // graph
  vector<vector<int>> G(N*(N-1)/2);
  REP(i,N) {
    int a;cin>>a;
    a--;
    int prevcode = code(i,a);
    REP(j,N-2) {
      int b;cin>>b;
      b--;
      int curcode = code(i,b);
      G[prevcode].push_back(curcode);
      prevcode = curcode;
    }
  }

  // その試合から全部で何日で終わるか（最低でも１）
  vector<int> d(N*(N-1)/2,-1);
  REP(i,N*(N-1)/2) {
    if (d[i]!=-1) continue;
    d[i] = 0;
    d[i] = calc(i,G,d);
  }
  OUT(*max_element(ALL(d)));

  return 0;
}

Measured memory_bytes: 29696
#include <iostream>

using namespace std;

struct Input
{
    int n;
    int k;
};

static Input read_input()
{
    Input input{};
    cin >> input.n >> input.k;
    return input;
}

static void solve(const Input& input)
{
    int num = 0;
    for (auto i = 0; i < input.n; ++i) {
        int h;
        cin >> h;

        if (h >= input.k) {
            num += 1;
        }
    }

    cout << num << endl;
}

int main(int argc, char** argv)
{
    const auto input = read_input();
    solve(input);
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.Queue;

public class Main {

	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int k = Integer.parseInt(br.readLine());

		Queue<Long> que = new ArrayDeque<>();
		for (int i = 1; i < 10; i++) {
			que.add((long) i);
		}
		int i = 0;
		long val = 1;

		while (k-- > 0) {
			val = que.poll();
			if (val % 10 != 0)
				que.add(10 * val + val % 10 - 1);
			que.add(10 * val + val % 10);
			if (val % 10 != 9)
				que.add(10 * val + val % 10 + 1);
			i++;
		}
		System.out.println(val);
	}
}


Measured memory_bytes: 29652
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
bool edge[10][10];
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	int a,b;
	for(int i=0;i<m;++i){
		scanf("%d%d",&a,&b);
		--a;--b;
		edge[a][b]=edge[b][a]=true;
	}
	int path[10]={0,1,2,3,4,5,6,7,8,9};
	int f=1;
	for(int i=1;i<n;++i)
		f*=i;
	int ans=0;
	for(int i=0;i<f;++i){
		bool chk=true;
		for(int i=1;i<n;++i){
			if(!edge[path[i-1]][path[i]])
				chk=false;
		}
		if(chk)
			++ans;
		next_permutation(path+1,path+n);
	}
	printf("%d",ans);
}
/*

3 3
1 2
1 3
2 3

7 7
1 3
2 7
3 4
4 5
4 6
5 6
6 7

*/

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<string>
#include<cctype>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
        int w[26];
        for(int i=0;i<26;i++){
                w[i]=0;
        }
        char c;
    while(scanf("%c",&c)!=EOF){
                c=tolower(c);
                int chk=c-'a';
                if(chk>=9 || chk<27){
                        w[chk]+=1;
                }
        }
        for(int i=0;i<26;i++){
                printf("%c : %d\n",(char)(i+97),w[i]);
        }
        return 0;
}

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

int main(){
	int n; cin>>n;
	vector<int> v(n);
	for(int i=1; i<n; i++){
		int a; cin>>a;
		v[a-1]++;
	}
	for(auto x:v) cout<<x<<endl;
}

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

int main()
{
    ll n;
    cin >> n;
    ll count = 0;
    if (n==1) {
        cout << '1';
    }
    else {
        while (n>1) {
            count++;
            count *= 2;
            n/=2;
        }
    cout << count+1;
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
  int age, fee;
  scanf("%d %d", &age, &fee);
  if(age <= 5) {
    printf("0\n");
  } else if(age <= 12) {
    printf("%d\n", fee / 2);
  } else {
    printf("%d\n", fee);
  }
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
    int N,M;
    cin >> N >> M;
    vector<int> H(N);
    vector<bool> H_good(N,true);
    vector<int> A(M);
    vector<int> B(M);
    for (int i = 0; i < N ; i++) {
        cin >> H.at(i);
    }
    for (int i = 0; i < M; i++)
    {
        cin >> A.at(i) >> B.at(i);
        if (H.at(A.at(i)-1) > H.at(B.at(i)-1))
        {
            H_good.at(B.at(i)-1) = false;
        }else if (H.at(A.at(i)-1) < H.at(B.at(i)-1))
        {
            H_good.at(A.at(i)-1) = false;
        }else if (H.at(A.at(i)-1) == H.at(B.at(i)-1))
        {
            H_good.at(A.at(i)-1) = false;
            H_good.at(B.at(i)-1) = false;
        }
    }
    int count = 0;
    for (int i = 0; i < N; i++)
    {
        if (H_good.at(i) == true)
        {
            count++;
        }
        
    }
    cout << count;
}

Measured memory_bytes: 4580
#include<cstdio>
int main() {
	int a, b, c;
	scanf("%d%d%d", &a, &b, &c);
	if (a == b) printf("%d", b == c ? 1 : 2);
	else if (b == c)printf("2");
	else printf("%d", a == c ? 2 : 3);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); ++i)
typedef long long ll;
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 ll INF = 1LL << 60;

int main(){
	int a, b;
	cin >> a >> b;
	if(a+b >= 24) cout << a+b -24;
	else cout << a+b;
}



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

long long dp[55][55][5000];

int main(void){
	int N,A;
	cin >> N >> A;
	int x[N];
	for(int i=0;i<N;i++)cin >> x[i];
	dp[0][0][0]=1;
	//dp[i][j][k]はx[0]~x[i]までの中からj個選んだ時、k=Σx;
	for(int i=0;i<N;i++){
		for(int j=0;j<=i;j++){
			for(int k=0;k<=2501;k++){
				//x[i]を選ばなかった場合
				dp[i+1][j][k] += dp[i][j][k];
				//x[i]を選んだ場合
				dp[i+1][j+1][k+x[i]] += dp[i][j][k];
			}
		}
	}
	long long ans = 0;
	for(int i=1;i<=N;i++){
		ans += dp[N][i][A*i];
	}
	cout << ans << endl;
}

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

int main()
{
    ll N,K;
    cin>>N>>K;
    ll h[N];
    for(ll i=0;i<N;i++)
    {
        cin>>h[i];
    }
    ll dp[N];
    dp[0]=0;
    for(ll i=1;i<N;i++)
    {
        ll temp=i-1;
        ll minm=abs(h[i]-h[i-1])+dp[i-1];
        while(temp>=0 && i-temp<=K)
        {
            minm=min(abs(h[i]-h[temp])+dp[temp],minm);
            temp--;
        }
        dp[i]=minm;
    }
    cout<<dp[N-1];
}

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

int main(){
  string n;
  cin >> n;
  int ans;
  rep(i, n.size()){
    ans += (n[i] - '0');
    ans %= 9;
  }
  if (ans == 0){
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 3748
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
      Scanner scanner = new Scanner(System.in);
      String input = scanner.nextLine();

      if(input.equals("ABC")) {
        System.out.println("ARC");
      }
      else {
        System.out.println("ABC");
      }
	}
}

Measured memory_bytes: 35716
#include <stdio.h>
#include <stdlib.h>
struct N{
  struct N *oya;
  struct N *left;
  struct N *right;
  int key;
};
typedef struct N*NODE;
NODE root;

void Ins(int ke){
  NODE y=NULL;
  NODE x=root;
  NODE z;
  z=malloc(sizeof(struct N));
  z->left=NULL;
  z->right=NULL;
  z->key=ke;

  while(x!=NULL){
    y=x;
    if(x->key > z->key){
      x=x->left;
    }
    else{
      x=x->right;
    }
  }

  z->oya=y;
  
    if(y==NULL){
      root=z;
    }
    else if(y->key > z->key){
      y->left=z;
    }
    else(y->right=z);
}

void preorder(NODE a){
  if(a==NULL)return;
  printf(" %d",a->key);
  preorder(a->left);
  preorder(a->right);
}

void inorder(NODE a){
  if(a==NULL)return;
 
  inorder(a->left);
  
  printf(" %d",a->key);
  
  inorder(a->right);
}
        
  
int main(void){
  int i,n,j;
  char c[20];
  scanf("%d",&n);

  for(i=0;i < n;i++){

    scanf("%s",c);

    if(c[0]=='i'){
      scanf("%d",&j);
      Ins(j);
    }

    else if(c[0]=='p'){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }
  return 0;
}



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

using namespace std;

int main()
{
    char str[100005];

    int flag[27] = {0};

    cin >> str;

    int len = strlen(str);

    for(int i = 0; i < len; i++)
    {
        flag[str[i] - 'a'] = 1;
    }
    int n = 0;
    for(int i = 0; i < 26; i++)
    {
        if(flag[i] == 0)
        {
            n = 1;
            printf("%c\n",i + 'a');
            return 0;
        }
    }
    if(n == 0)
    {
        cout << "None" << endl;
    }
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(int i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+7  
using ll = long long; 
using P=pair<int,int>;
using lP=pair<ll,ll>;
using fP=pair<double,double>;


int main(){
    int n,q;
    cin>>n>>q;
    string s;
    cin>>s;
    
    vector<int>ac(n+1);
    ac[0]=0;
    arep(i,1,n+1){
        
        if(s[i]=='C'&&s[i-1]=='A'){
            ac[i]=ac[i-1]+1;
        }
        else{
            ac[i]=ac[i-1];
        }

    }
    vector<int>ans;
    rep(i,q){
        int l,r;
        cin>>l>>r;
        ans.push_back(ac[r-1]-ac[l-1]);
    }
    rep(i,q)cout<<ans[i]<<endl;
    return 0;
}

Measured memory_bytes: 1912
#include <bits/stdc++.h>
#define ENDL '\n'
#define io ios_base::sync_with_stdio(false);cin.tie(0);
#define sayY cout<<"YES"<<ENDL;
#define sayN cout<<"NO"<<ENDL;
#define sayy cout<<"Yes"<<ENDL;
#define sayn cout<<"No"<<ENDL;

typedef long long ll;
using namespace std;

int main(){
    io

    int n;
    cin >> n;

    vector<int> v(n);
    for(int i(0); i<n; i++){
        cin >> v[i];
    }

    for(int i(n-2); i>=0; i--){
        if(v[i] <= v[i+1]) continue;
        if(v[i]-v[i+1] == 1) v[i]--;
        else{
            sayn
            return 0;
        }
    }
    sayy

    return 0;
}

Measured memory_bytes: 3728
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] h = new int[n];
		for(int i = 0;i < n;i ++) {
			h[i] = sc.nextInt();
		}
		int sum = 0;
		int point = 0;
		for(int i = 0;i < n;i ++) {
			if(point < h[i]) {
				sum += h[i] - point;
				point = h[i];
			}else {
				point = h[i];
			}
		}
		System.out.println(sum);
	}
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
int main(){
  int64_t N,K;
  cin>>N>>K;
  vector<int64_t>A(N);
  int64_t sum=0;
  for(int i=0;i<N;i++){
  cin>>A.at(i); sum+=A.at(i);
  }
  vector<int64_t>C;
  for(int64_t i=1;i*i<=sum;i++)
    if(sum%i==0)C.push_back(i);
  int64_t M=C.size();
  for(int64_t i=0;i<M;i++)
    C.push_back(sum/C[M-1-i]);
  vector<int64_t>D(N,0);
  int64_t ans=-1;
  for(int i=2*M-1;0<=i;i--){
   int64_t sum1=0;int64_t a=C[i];
    for(int j=0;j<N;j++){
    D.at(j)=A[j]%a; sum1+=D.at(j);
    }sum1/=a;
    sort(D.begin(),D.end());int64_t x=0;
    for(int j=0;j<N-sum1;j++)
      x+=D.at(j);
    if(x<=K){ans=a;break;}
  }cout<<ans<<endl;
    
  return 0;
}

Measured memory_bytes: 3628
#include<iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <bitset>
#include <stack>
#include <queue>
#include <fstream>
#include <functional>

using namespace std;
using ll = long long;

#define all(x) (x).begin(),(x).end()
#define PRI(n) cout << n << " "<<endl;
#define PRI2(n, m) cout << n << " " << m << " "<<endl;

#define REP(i, n)  for(int i = 0; i < (int)n; ++i)
#define FOR(i, t, n)  for(int i = t; i <= (int)n; ++i)

const char alphabet[26] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
                           's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};
const ll MOD = 1e9 + 7;

struct edge;
struct UnionFind;

bool isPrime(ll x);

ll GCD(ll a, ll b);

ll LCM(ll a, ll b);

ll nCr(int n, int r);


struct UnionFind {
    vector<int> par;
    vector<int> rank;

    UnionFind(int N) {
        for (int i = 0; i < N; ++i) {
            par.push_back(i);
            rank.push_back(0);
        }
    }

    int find(int x) {
        if (par[x] == x)return x;
        else return par[x] = find(par[x]);
    }

    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y)return;
        if (rank[x] < rank[y])par[x] = y;
        else {
            par[y] = x;
            if (rank[x] == rank[y])rank[x]++;
        }
    }

    bool same(int x, int y) {
        return find(x) == find(y);
    }
};

int M, N;
bool W[3010];
bool S[3010];

int main() {
    cin >> N >> M;
    vector<int> A(N);
    REP(i, N) {
        int a;
        cin >> a;
        A[a - 1]++;
    }
    sort(all(A), greater<>());
    int i = 0;
    while (M > 0) {
        N -= A[i];
        M--;
        i++;
    }
    PRI(N)
    return 0;
}

struct edge {
    int to, cost;
    bool flag = false;
};

bool isPrime(ll x) {
    if (x == 0)return 0;
    if (x == 1)return 0;
    if (x == 2)return 1;
    if (x % 2 == 0)return 0;
    FOR(i, 3, x - 1) {
        if (x % i == 0)return 0;
    }
    return 1;
}

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

ll LCM(ll a, ll b) {
    ll gcd = GCD(a, b);
    return a / gcd * b;
}

ll nCr(int n, int r) {
    vector<ll> C(r + 1);
    C[0] = 1;
    FOR(i, 1, n) for (int j = min(i, r); j < 1; --j)C[j] = (C[j] + C[j - 1]) % MOD;
    return C[r];
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()

using namespace std;

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

int main()
{
//	cut here before submit 
//	freopen ("testcase.SRC", "r", stdin );
	string str = "";
	stack<int> st;
	while (getline (cin, str ) ){
		stringstream ss (str );
		int car = -1;
		ss >> car;
		if (car != 0 ){
			st.push (car );
		}else{
			cout << st.top() << endl;
			st.pop();
		} // end if
	} // end while
		
	return 0;
}

Measured memory_bytes: 1228
//inlclude before define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
#include<assert.h>
//#include<deque>
#include<iomanip>
#include<set>
#include<tuple>
#include<map>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef pair<int, int> P1;
typedef long long int ll;

//define
#define INF 1e9
#define NUM 1000000007
#define all(x) begin(x),end(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define REP(i,a,b) for(int i=int(a);i<int(b);i++)
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))

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


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

int main() {
	ll n, m;
	cin >> n >> m;

	cout << abs((n - 2)*(m - 2)) << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
  int x, y;
  char T[2], U[2];
  string S;
  cin >> S;
  U[0] = S[5];
  U[1] = 0;
  y = atoi(U);
  if (y == 1){
    cout << "TBD" << endl;
  }else{
    T[0] = S[6];
    T[1] = 0;
    x = atoi(T);
    if (x <= 4){
      cout << "Heisei" << endl;
    }
    if (x > 4){
      cout << "TBD" << endl;
    }
  }
  return 0;


}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <cmath>

using namespace std;

template<typename T>
class P2 {
public:
	T x, y;
	P2(T x = 0, T y = 0) : x(x), y(y){}
	bool operator < (const P2<T>& p) const { return make_pair(x, y) < make_pair(p.x, p.y); }
	T length() const { return sqrt(x*x+y*y); }
	void sub(const P2<T>& p){ x -= p.x; y -= p.y; }
	void scale(T s){ x *= s; y *= s; }
};

template<typename T>
auto dot(const P2<T>& a, const P2<T>& b, const P2<T>& c){
	auto dx1 = b.x - a.x;
	auto dy1 = b.x - a.x;
	auto dx2 = c.x - b.x;
	auto dy2 = c.y - b.y;
	return dx1 * dx2 + dy1 * dy2;
}

template<typename T>
auto cross(const P2<T>& a, const P2<T>& b, const P2<T>& c){
	auto dx1 = b.x - a.x;
	auto dy1 = b.y - a.y;
	auto dx2 = c.x - b.x;
	auto dy2 = c.y - b.y;
	return dx1 * dy2 - dy1 * dx2;
}

template<typename T>
vector<P2<T>> convexHull(const vector<P2<T>>& ps){
	if(ps.size() <= 2) return ps;
	vector<P2<T>> pt = ps;
	sort(pt.begin(), pt.end());
	vector<P2<T>> res;
    auto addPoint = [&](auto& p, int lower){
		while(res.size() >= lower){
			int k = res.size();
			auto cr = cross(res[k-2], res[k-1], p);
			auto dt = dot(res[k-2], res[k-1], p);
			if(cr < 0 || (cr == 0 && dt >= 0)){
				res.pop_back();
			} else {
				break;
			}
		}
		res.push_back(p);
    };
	for(int i=0;i<pt.size();i++) addPoint(pt[i], 2);
	for(int i=pt.size()-2, t=res.size()+1;i>=0;i--) addPoint(pt[i], t);
	res.pop_back();
	return res;
}

int main(){
    int N; cin >> N;
    vector<P2<long long>> vp(N);
    for(auto& p : vp) cin >> p.x >> p.y;
    vector<double> res(N, 0.0);
    auto hull = convexHull(vp);
    for(int i=0;i<hull.size();i++){
        auto& prev = hull[(i+hull.size()-1)%hull.size()];
        auto& cur  = hull[i];
        auto& next = hull[(i+1)%hull.size()];
        auto x1 = cur.x - prev.x;
        auto y1 = cur.y - prev.y;
        auto x2 = next.x - cur.x;
        auto y2 = next.y - cur.y;
        auto rate = 0.5 * abs(atan2(x1*y2-x2*y1, x1*x2+y1*y2)) / acos(-1.0);
        for(int j=0;j<N;j++){
            if(cur.x == vp[j].x && cur.y == vp[j].y) res[j] = rate;
        }
    }
    for(auto& d : res) printf("%.8lf\n", d);
}

Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main(void){
    string a;
    int i,len;
    getline(cin,a);
    len=(int)a.length();
    for(i=0;i<len;i++){
        if(a[i]>='a' && a[i]<='z') a[i]=a[i]-32;
        else if(a[i]>='A' && a[i]<='Z') a[i]=a[i]+32;
    }
    cout << a << endl;
}



Measured memory_bytes: 3140
let () = Scanf.scanf "%d\n" @@ fun n ->
  let as_ = Array.init n @@ fun _ -> Scanf.scanf "%d " @@ fun a -> a in
  let d = Array.fold_left max min_int as_ in
  let count_as = Array.make n 0 in
  Array.iter (fun a -> count_as.(a) <- 1 + count_as.(a)) as_;
  print_endline @@
  if
    Array.fold_right (fun n -> ( && ) (n = 0))
      (Array.sub count_as 0 ((d + 1) / 2)) true &&
    count_as.((d + 1) / 2) = 1 + d mod 2 &&
    Array.fold_right (fun n -> ( && ) (1 < n))
      (Array.sub count_as ((d + 1) / 2 + 1) (d / 2)) true
  then "Possible"
  else "Impossible"


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

int main(void){
    int N, Abuf, Xbuf, Ybuf;
    cin >> N;
    vector<int> A;
    vector<vector<int>>  Testimony(N, vector<int>(N, -1));
    for(int i=0; i<N; i++){
        cin >> Abuf;
        A.push_back(Abuf);
        for(int j=0; j<Abuf; j++){
            cin >> Xbuf >> Ybuf;
            Testimony[i][Xbuf-1] = Ybuf;            
        }
    }
    
    int maxCases = 1<<N;
    vector<bool> bolCases(maxCases, true);
    for(int numCase=0; numCase < maxCases; numCase++){
        for(int i=0; i<N; i++){
            int iHonesty = (numCase >> i) & 1;
            if(iHonesty == 1){
                for(int j=0; j<N; j++){
                    int jHonesty = (numCase >> j) & 1;
                    if((jHonesty != Testimony[i][j])&&(Testimony[i][j]!=-1)){
                        bolCases[numCase] = false;
                        break;
                    }
                }
                if(!bolCases[numCase])break;
            }
        }
    }

    int res = 0;

    for(int numCase=0; numCase < maxCases; numCase++){
        if(!bolCases[numCase])continue;
        res = max(res, __builtin_popcount((unsigned int)numCase));
    }

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<utility>
#include<cmath>

using namespace std;
typedef vector< vector<int> > vv;
typedef vector< vector< pair<int,int> > > vvp;

int make_distance(pair<int,int>& S,pair<int,int>& T){
  return abs(S.first-T.first)+abs(S.second-T.second);
}

int main(){

  int h,w,d;cin >> h >> w >> d;
  vv a(h,vector<int>(w,0));
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){cin >> a[i][j];}
  }
  
  vv x1;
  vvp x2;
  for(int i=1;i<d+1;i++){
    int l=int((h*w-i)/d);
    vector<int> v1(l+1,0); vector< pair<int,int> > v2(l+1);
    x1.push_back(v1);x2.push_back(v2);
  }

  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      int p=a[i][j]%d;if(p==0){p=d-1;}else{p-=1;}
      int l=int((a[i][j]-(p+1))/d);
      x2[p][l]=make_pair(i,j);
    }
  }

  for(int i=1;i<d+1;i++){
    int l=int(x1[i-1].size());
    for(int j=0;j<l-1;j++){
      x1[i-1][j+1]=x1[i-1][j]+make_distance(x2[i-1][j],x2[i-1][j+1]);
    }
  }

  int q;cin >> q;
  for(int i=0;i<q;i++){
    int l,r;cin >> l >> r;
    int p=l%d;
    if(p==0){
      cout << x1[d-1][int(r/d)-1]-x1[d-1][int(l/d)-1] << endl;
    }else{
      cout << x1[p-1][int(r/d)]-x1[p-1][int(l/d)] << endl;
    }
  }

}


Measured memory_bytes: 11104
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
  string S;
  cin >> S;
  string S1 = S.substr(0,2);
  string S2 = S.substr(2,2);
  int s1 = atoi(S1.c_str());
  int s2 = atoi(S2.c_str());
  if (1 <= s1 && s1 <= 12 && 1 <= s2 && s2 <= 12) {
    cout << "AMBIGUOUS" << endl;
  } else if ((1 > s1 || s1 > 12) && (1 > s2 || s2 > 12)) {
    cout << "NA" << endl;
  } else if (1 <= s1 && s1 <= 12) {
    cout << "MMYY" << endl;
  } else {
    cout << "YYMM" << endl;
  }
  return 0;
}

Measured memory_bytes: 3584
import sys
sys.setrecursionlimit(10**7)
N,M = map(int,input().split())
ALL = [i for i in range(N)]
ALL = set(ALL)
Graph = [[] for _ in range(N)]
gyaku = [set([]) for _ in range(N)]
for i in range(N-1+M):
  a,b = map(int,input().split())
  a-=1;b-=1
  Graph[a].append(b)
  gyaku[b].add(a)
  ALL.discard(b)
#print(Graph,gyaku)
ALL = list(ALL);root = ALL[0]

used = set([])
TS = []
def dfs(v):
  if v in used:
    return
  used.add(v)
  for w in Graph[v]:
    if w in used:
      continue
    dfs(w)
    TS.append(w)
    
dfs(root)
TS.append(root)
TS.reverse()
#print(TS)
ans = [0 for _ in range(N)]
for i in range(N):
  now = TS[i]
  for nxt in Graph[now]:
    ans[nxt] = now+1
    
for x in ans:
  print(x)

Measured memory_bytes: 235388
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stdio.h>
#include<cstring>
#include<math.h>
#include<map>
#include<bitset>
#include<iomanip>
#include<queue>
#include<functional>
#include<stack>
#include<tuple>
#include<cassert>
using namespace std;

#define rep(i, n) for (long long i = 0; i < (long long)(n); ++i)
using P = pair<long long, pair<long long, long long>>;

  long long H, W;
  long long ch, cw;
  long long dh, dw;
  long long dx[4] = {0, -1, 0, 1};
  long long dy[4] = {1, 0, -1, 0};
  string s[1000];
  long long dist[1000][1000] = {0};
  const long long INF = 1000000000;
  const long long INF2 = 1000000000000000000;

int main() {
  cin >> H >> W;
  cin >> ch >> cw;
  cin >> dh >> dw;
  ch--;cw--;
  dh--;dw--;
  rep(i, H) {
    string temp;
    cin >> temp;
    s[i] = temp;
  }
  priority_queue<P, vector<P>, greater<P>> que;


  rep(i, H) {
    rep(j, W) {
      dist[i][j] = INF2;
    }
  }

  que.push({0, {ch, cw}});
  dist[ch][cw] = 0;

  while(que.size()) {
    bool f = true;
    P p = que.top();
    que.pop();
    rep(i, 4) {
      long long nx = p.second.first + dx[i];
      long long ny = p.second.second + dy[i];
      if(0 <= nx && nx < H && 0 <= ny && ny < W && s[nx][ny] == '.' && dist[nx][ny] > dist[p.second.first][p.second.second] + 1) {
        dist[nx][ny] = dist[p.second.first][p.second.second] + 1;
        que.push({dist[nx][ny], {nx, ny}});
      }
    }
    for(long long i = -2; i <= 2; i++) {
      for(long long j = -2; j <= 2; j++) {
        long long nx = p.second.first + i;
        long long ny = p.second.second + j;
        if(0 <= nx && nx < H && 0 <= ny && ny < W && s[nx][ny] == '.' && dist[nx][ny] > dist[p.second.first][p.second.second] + INF) {
          dist[nx][ny] = dist[p.second.first][p.second.second] + INF;
          que.push({dist[nx][ny], {nx, ny}});
        }
      }
    }
  }
  if(dist[dh][dw] == INF2) {
    cout << -1 << endl;
    return 0;
  }
  long long ans = dist[dh][dw] / INF;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 12488
mod=10**9+7
n,k=map(int,input().split())
a=sorted(list(map(int,input().split())))
pi=1
ni=0
ans=1
i=0
while i<k-1:
  if a[ni]*a[ni+1]>a[-pi]*a[-pi-1]:
    ans=ans*a[ni]*a[ni+1]%mod
    ni+=2
    i+=2
  else:
    ans=ans*a[-pi]%mod
    pi+=1
    i+=1
if i==k-1:
  ans=ans*a[-pi]%mod
if a[-1]<0 and k%2==1:
  ans=1
  for i in a[n-k:]:
    ans=ans*i%mod
print(ans)

Measured memory_bytes: 33060
#include <bits/stdc++.h>
#define P pair<int,int>
#define All(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
typedef long long ll;
using namespace std;
const int INF = 1e9, MOD = 1e9 + 7;
const ll LINF = 1e18;
int check(string x) {
	int tmp = 0;
	for (int i = 0; i < (int)x.size(); i++) {
		tmp += x[i] - '0';
	}
	return tmp;
}
int main() {
	string s;
	cin >> s;
	int size = s.size();
	string y = "";
	y += s[0] - 1;
	for (int i = 0; i < size - 1; i++) {
		y += '9';
	}
	cout << max(check(s), check(y)) << endl;
	return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back

using namespace std;
const long long MOD = (long long)1e9 + 7;

int n, m;

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> m;
    if (n >= 13) cout << m;
    else if (n >= 6) cout << m/2;
    else cout << "0";
    //system("pause");
    return 0;
}

Measured memory_bytes: 256
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container;

long P = 10^^9+7;
long[10^^5*2] F, RF;

long pow(long x, long n) {
    long y = 1;
    while (n) {
        if (n%2 == 1) y = (y * x) % P;
        x = x^^2 % P;
        n /= 2;
    }
    return y;
}

long inv(long x)
{
    return pow(x, P-2);
}

void init()
{
    F[0] = F[1] = 1;
    foreach (i, ref x; F[2..$]) x = (F[i+1] * (i+2)) % P;

    {
        RF[$-1] = 1;
        auto x = F[$-1];
        auto k = P-2;
        while (k) {
            if (k%2 == 1) RF[$-1] = (RF[$-1] * x) % P;
            x = x^^2 % P;
            k /= 2;
        }
    }
    foreach_reverse(i, ref x; RF[0..$-1]) x = (RF[i+1] * (i+1)) % P;
}

long comb(N)(N n, N k)
{
    if (k > n) return 0;
    auto n_b = F[n];    // n!
    auto nk_b = RF[n-k]; // 1 / (n-k)!
    auto k_b = RF[k];    // 1 / k!

    auto nk_b_k_b = (nk_b * k_b) % P; // 1 / (n-k)!k!

    return (n_b * nk_b_k_b) % P;  // n! / (n-k)!k!
}

Tuple!(N, N)[] prime_division(N)(N n)
{
    Tuple!(N, N)[] res;
    foreach (N i; 2..10^^6+1) {
        if (n%i == 0) {
            N cnt;
            while (n%i == 0) {
                ++cnt;
                n /= i;
            }
            res ~= tuple(i, cnt);
        }
    }
    if (n != cast(N)1) res ~= tuple(n, cast(N)1);
    return res;
}

void main()
{
    init();
    auto nm = readln.split.to!(long[]);
    auto N = nm[0];
    auto M = nm[1];

    long r = 1;
    foreach (p; prime_division(M)) {
        (r *= comb(N+p[1]-1, N-1)) %= P;
    }
    writeln(r);
}

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

int main(void){
    int n,m;
    cin >> n >> m;
    vector<int> vec(n);
    for(int i=0;i<n;i++) cin >> vec[i];
    sort(vec.begin(),vec.end());

    vector<pair<int,int>> p(m);
    for(int i=0;i<m;i++) cin >> p[i].second >> p[i].first;
    sort(p.begin(),p.end());

    ll ans = 0;
    for(int i=0;i<n;i++){
        if(p.size()==0 || vec[i]>p.back().first) ans += vec[i];
        else{
            ans += p.back().first;
            p.back().second--;
            if(p.back().second==0) p.pop_back();
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1408
# pragma GCC optimize("O3")
# include <bits/stdc++.h>
std::pair<int,int> DR[] = {{-1,0},{0,1},{1,0},{0,-1},{-1,1},{-1,-1},{1,1},{1,-1}};
# define ll long long
# define clock (clock() * 1000.0 / CLOCKS_PER_SEC)
# define rc(s) return cout << s,0
# define rcg(s) cout << s;exit(0)
# define _ ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
# define db(x) cerr << #x << " = " << x << '\n'
# define pb push_back
# define mp make_pair
# define all(s) s.begin(),s.end()
# define sz(x) (int)((x).size())
# define int ll
using namespace std;
int gcd(int a, int b)
{
    if(b) return gcd(b,a%b);
    return a;
}mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int mod = 1e9 + 7;

map<char,int>m;

int p[1 << 17];

int32_t main(){_
    //freopen("in","r",stdin);
	int n;string s;
	cin >> n >> s;
	p[0] = 1;
	for(int i = 1;i <= n;i++) p[i] = (p[i - 1] * 2) % mod;
	for(auto it : s) m[it]++;
	int ans = 1;
	for(auto it : m)
	{
		ans *= it.second + 1;
		ans %= mod;
	}	
	rc((ans - 1 + mod) % mod);
}

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

namespace Certpro
{
  static class Constants
  {
    public const int MAX   = 100;
    public const int WHITE = 0;
    public const int GRAY  = 1;
    public const int BLACK = 2;
  }

  class SingleSourceShortestPath1
  {
    // ??????????????£
    int n;
    int[,] M = new int[Constants.MAX, Constants.MAX];

    // ???????????????
    SingleSourceShortestPath1()
    {
      n = int.Parse(Console.ReadLine());
      for (var i = 0; i < n; i++) {
        for (var j = 0; j < n; j++) {
          M[i,j] = int.MaxValue;
        }
      }

      int u, k, v, c; // u k (v1 c1) (v2 c2) (v3 c3) ...
      for (var i = 0; i < n; i++) {
        var splitStrs = Console.ReadLine().Split(' ');
        var numbers = splitStrs.Select(s => int.Parse(s)).ToArray();
        u = numbers[0];
        k = numbers[1];
        var offset = 2;
        for (var j = 0; j < k; j++) {
          v = numbers[offset];
          c = numbers[offset + 1];
          M[u, v] = c;
          offset += 2;
        }
      }

      dijkstra();
    }

    // ??????????????????????????????????????¢?´¢
    void dijkstra()
    {
      int[] d = new int[Constants.MAX];
      int[] color = new int[Constants.MAX];
      for (var i = 0; i < n; i++) {
        d[i] = int.MaxValue;
        color[i] = Constants.WHITE;
      }
      d[0] = 0;
      color[0] = Constants.GRAY;

      int minV;
      while (true) {
        minV = int.MaxValue;
        var u = -1;
        for (var i = 0; i < n; i++) {
          if (minV > d[i] && color[i] != Constants.BLACK) {
            u = i;
            minV = d[i];
          }
        }
        if (u == -1) break;
        color[u] = Constants.BLACK;
        for (var v = 0; v < n; v++) {
          if (color[v] != Constants.BLACK && M[u, v] != int.MaxValue) {
            if (d[v] > d[u] + M[u, v]) {
              d[v] = d[u] + M[u, v];
              color[v] = Constants.GRAY;
            }
          }
        }
      }

      for (var i = 0; i < n; i++) {
        Console.WriteLine(i + " " + (d[i] == int.MaxValue ? -1 : d[i]));
      }
    }

    // ??????????????????
    static void Main()
    {
      new SingleSourceShortestPath1();
    }

  }
}

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

int main(){
	int n;cin>>n;
	int cnt[9]={0};
	for(int i=0;i<n;i++){
		int a;cin>>a;
		if(a<400){
			cnt[1]++;
		}else if(a<800){
			cnt[2]++;
		}else if(a<1200){
			cnt[3]++;
		}else if(a<1600){
			cnt[4]++;
		}else if(a<2000){
			cnt[5]++;
		}else if(a<2400){
			cnt[6]++;
		}else if(a<2800){
			cnt[7]++;
		}else if(a<3200){
			cnt[8]++;
		}else{
			cnt[0]++;
		}
	}
	int how=0;
	for(int i=1;i<9;i++){
		if(cnt[i])how++;
	}
	cout<<max(how,1)<<' '<<how+cnt[0];
	return 0;
}

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

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back

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

int main(){
	string s;
	cin>>s;
	sort(all(s));

	if(s[0]==s[1]&&s[2]==s[3]&&s[1]!=s[2])
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <algorithm>
#define fr first
#define sc second
#define INF (2 << 28)
using namespace std;

typedef pair<int, int> iP;

int n, k, dp[2001][2001];
iP book[2001];
map <int, int> tag;

int rec(int sum, int idx){
    
    if(sum == k) return 0;
    if(idx == n) return -INF;
    if(sum > k) return -INF;
    if(dp[sum][idx]) return dp[sum][idx];
    
    int ret = 0, s = 0;
    for(int i = idx, cnt = 1; i < tag[book[idx].fr + 1]; i++, cnt++){
        s -= book[i].sc;
        ret = max(rec(sum + cnt, tag[book[idx].fr + 1]) + s + cnt * (cnt - 1), ret);
    }
    ret = max(ret, rec(sum, tag[book[idx].fr + 1]));
    
    return dp[sum][idx] = ret;
}

int main(){
    
    cin >> n >> k;
    for(int i = 0; i < n; i++){
        cin >> book[i].sc >> book[i].fr;
        book[i].sc = -book[i].sc;
    }
    
    sort(book, book + n);
    
    int prev = book[0].fr, idx = 1;
    tag[idx] = 0;
    for(int i = 0; i < n; i++){
        if(book[i].fr != prev){
            tag[++idx] = i;
            prev = book[i].fr;
        }
    }
    tag[idx + 1] = n;
    
    cout << rec(0, 0) << endl;
    
}

Measured memory_bytes: 14880