akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;
 
class Node {
    static Node root;
 
    int key;
    int priority;
    Node left;
    Node right;
 
    Node(int key, int priority) {
        this.key = key;
        this.priority = priority;
    }
 
    private Node rightRotate() {
        Node s = left;
        left = s.right;
        s.right = this;
        return s;
    }
 
    private Node leftRotate() {
        Node s = right;
        right = s.left;
        s.left = this;
        return s;
    }
 
    Node insert(Node t) {
        if(t == null) return this;
        if(key == t.key) return t;
 
        if(key < t.key) {
            t.left = insert(t.left);
            if(t.priority < t.left.priority) t = t.rightRotate();
        }else {
            t.right = insert(t.right);
            if(t.priority < t.right.priority) t = t.leftRotate();
        }
 
        return t;
    }
 
    static Node find(int key) {
        Node x = root;
        while(x != null) {
            if(key < x.key) x = x.left;
            else if(x.key < key) x = x.right;
            else return x;
        }
        return null;
    }
 
    static Node delete(Node t, int key) {
        if(t == null) return null;
        if(key < t.key) t.left = delete(t.left, key);
        else if(key > t.key) t.right = delete(t.right, key);
        else return _delete(t, key);
        return t;
    }
 
    static Node _delete(Node t, int key) {
        if(t.left == null && t.right == null) return null;
        else if(t.left == null) t = t.leftRotate();
        else if(t.right == null) t = t.rightRotate();
        else {
            if(t.left.priority > t.right.priority) t = t.rightRotate();
            else t = t.leftRotate();
        }
        return delete(t, key);
    }
 
    static String inorder(Node x) {
        String str = "";
        if(x == null) return str;
 
        if(x.left != null) str += inorder(x.left);
        str += " " + x.key;
        if(x.right != null)str += inorder(x.right);
 
        return str;
    }
 
    static String preorder(Node x) {
        String str = "";
        if(x == null) return str;
 
        str += " " + x.key;
        if(x.left != null) str += preorder(x.left);
        if(x.right != null) str += preorder(x.right);
 
        return str;
    }
}
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
  
        Node.root = null;
        int m = sc.nextInt();
        for(int i = 0; i < m; i++) {
            String cmd = sc.next();
            if(cmd.equals("insert")) {
                Node.root = new Node(sc.nextInt(), sc.nextInt()).insert(Node.root);
            }else if(cmd.equals("find")) {
                System.out.println(Node.find(sc.nextInt()) != null? "yes" : "no");
            }else if(cmd.equals("delete")) {
                Node.root = Node.delete(Node.root, sc.nextInt());
            }else {
                System.out.println(Node.inorder(Node.root));
                System.out.println(Node.preorder(Node.root));
            }
        }
 
        sc.close();
    }
}


Measured memory_bytes: 456428
#include<iostream>
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;
const int inf=1<<28;

int dp[1<<16];

int main()
{
	int n;
	while(cin>>n,n){
		int t[20][20];
		rep(i,n)rep(j,n+1)cin>>t[i][j];
		
		rep(i,1<<n)dp[i]=inf;
		dp[0]=0;
		rep(i,1<<n){
			rep(j,n)if(!(i&1<<j)){
				rep(k,n)if(i&1<<k)dp[i|1<<j]=min(dp[i|1<<j],dp[i]+t[j][k+1]);
				dp[i|1<<j]=min(dp[i|1<<j],dp[i]+t[j][0]);
			}
		}
		cout<<dp[(1<<n)-1]<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 1124
import java.io.*;

class Main
{
 
  public static void main(String[] args)
  {
    try{
    	// ??\???????????????
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      int n = Integer.parseInt(br.readLine());
      String[] str = br.readLine().split(" ");
      int[] array = new int[n];
 
      for(int i = 0; i < n; i++){
        array[i] = Integer.parseInt(str[i]);
      }
      insertionSort(array, array.length);
 
    }catch(Exception e){
      System.out.println(e);
    }
  }
 
  public static void insertionSort(int[] A, int N)
  {
    StringBuilder sb = new StringBuilder();
    sb.append(show(A));
 
    for(int i = 1; i < N; ++i){
    	// key??£??\
      int key = A[i];
      // ????????????????????????????????£??\??????
      int j = i - 1;
      while(j >= 0 && A[j] > key){
    	  // ????????????
        A[j+1] = A[j];
        j--;
      }
      A[j+1] = key;
      sb.append(show(A));
    }
    System.out.print(sb);
  }
 
  public static String show(int[] B)
  {
    StringBuilder sb = new StringBuilder();
 
    for(int i = 0; i < B.length; i++){
      sb.append(B[i]).append(" ");
    }
    sb.deleteCharAt(sb.length() - 1);
    sb.append("\n");
 
    return sb.toString();
  }
}

Measured memory_bytes: 26640
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <random>
#include <cmath>
#include <iomanip>
#include <climits>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>
#include <new>
#include <typeinfo>

typedef  long long ll;
#define mop 1000000007
#define mop2 998244353

using namespace std;

int main() {

	ll n, k;
	cin >> n >> k;
	vector <ll> v(n + 1, 0);
	for (ll i = 0; i < k; i++) {
		ll d;
		cin >> d;
		for (ll j = 0; j < d; j++) {
			ll tmp;
			cin >> tmp;
			v[tmp]++;
		}
	}
	ll ans = 0;
	for (ll i = 1; i <= n; i++) {
		if (v[i] == 0) {
			ans++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define all(v) v.begin(), v.end()
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<int> G(2), S(2), B(2);
  rep(i, 2) cin >> G[i] >> S[i] >> B[i];
  vector<int> choice[] = {G, S, B};
  vector<ll> dp(N+1, N);
  rep(i, N+1) {
    rep(j, 3) {
      if(choice[j][1] < choice[j][0]) continue;
      if(i+choice[j][0] <= N) {
        dp[i+choice[j][0]] = max(dp[i]+choice[j][1]-choice[j][0],
                                 dp[i+choice[j][0]]);
      }
    }
  }
  N = *max_element(all(dp));
  dp = vector<ll>(N+1, N);
  rep(i, N+1) {
    rep(j, 3) {
      if(choice[j][0] < choice[j][1]) continue;
      if(i+choice[j][1] <= N) {
        dp[i+choice[j][1]] = max(dp[i]+choice[j][0]-choice[j][1],
                                 dp[i+choice[j][1]]);
      }
    }
  }
  cout << *max_element(all(dp)) << endl;
  return 0;
}


Measured memory_bytes: 195584
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ALL(x) (x).begin(), (x).end() //sortなどの引数を省略
int main(){
  string s;
  int q;
  bool is_r = false;
  cin >> s;
  cin >> q;
  deque<int> deq;
  for(int i = 0; i < s.size(); i++){
    deq.push_back(s[i]);
  }
  int t, f;
  char c;
  for(int i = 0; i < q; i++){
    cin >> t;
    if(t == 1){
      if(is_r == true){
        is_r = false;
      }else{
      	is_r = true;
      }
    }else{
      cin >> f >> c;
      if(is_r == true){
        if(f == 1){
          deq.push_back(c);
      	}else{
      	  deq.push_front(c);
      	}
      }else{
      	if(f == 1){
          deq.push_front(c);
      	}else{
      	  deq.push_back(c);
      	}
      }   
    }
  }
  if(is_r == true){
    reverse(ALL(deq));
  }
  while(!deq.empty()){
    char ch = deq.front();
    cout << ch;
    deq.pop_front();
  }
}

Measured memory_bytes: 1920
#include<iostream>
#include<algorithm>
using namespace std;
int a[2];
int main(){
	while(cin>>a[0]>>a[1]){
		sort(a,a+2);
		for(int i=a[0];;i--){
			if(a[0]%i==0&&a[1]%i==0){
				cout<<i<<" "<<(long long)a[0]*a[1]/i<<endl;
				goto loop;
			}
		}
		loop:;
		age:;
	}
	return 0;
}				


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

int main() {
  int N,M;
  cin>>N;
  vector<string> s(N);
  int max_point=0;
  int count=0;
  string word;
  
  for(int i=0;i<N;i++){
  	  cin>>s.at(i);
  }
  
  cin>>M;
  vector<string> t(M);
  
  for(int i=0;i<M;i++){
  	  cin>>t.at(i); 
  }
  
  for(int i=0;i<N;i++){
   	word=s.at(i);
    
    for(int j=0;j<N;j++){
     	if(word==s.at(j)){
           count++; 
        }
    }
    
    for(int j=0;j<M;j++){
     	if(word==t.at(j)){
           count--; 
        }
    }
    
    if(max_point<count){
		max_point=count;
    }
    count=0;
    
  }
  
  for(int i=0;i<M;i++){
   	word=t.at(i);
    
    for(int j=0;j<N;j++){
     	if(word==s.at(j)){
           count++; 
        }
    }
    
    for(int j=0;j<M;j++){
     	if(word==t.at(j)){
           count--; 
        }
    }
    
    if(max_point<count){
		max_point=count;
    }
    count=0;
    
  }
  
  cout<<max_point<<endl;
  
}


Measured memory_bytes: 256
/*{{{*/
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#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 <ctime>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
#include <cassert>
using namespace std;
typedef pair<int, int> PP;
typedef long long LL;
#define pb push_back
#define fr first
#define sc second
#define bitcnt __builtin_popcount
#define all(x) x.begin(), x.end()
inline int ri() {int x; scanf("%d", &x); return x;}
#define rep2(i, n, ...) for (int i = 0; i < (n); i ++) 
#define rep3(i, a, b, ...) for (int i = (a); i < (b); i ++)
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define rep(...) GET_MACRO(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define drep2(i, n, ...) for (int i = (n) - 1; i >= 0; i --)
#define drep3(i, a, b) for (int i = (a) - 1; i >= (b); i --)
#define drep(...) GET_MACRO(__VA_ARGS__, drep3, drep2)(__VA_ARGS__)
template<typename T>inline bool smax(T&a, T b){if(a<b){a=b;return true;}return false;} 
template<typename T>inline bool smin(T&a, T b){if(a>b){a=b;return true;}return false;} 
/*}}}*/

const int maxn = 1e5 + 5;

int p[maxn], n, res;
int main() {
  #ifdef _TEST_
  freopen("input.txt", "r", stdin);
  //freopen("out.txt", "w", stdout);
  #endif
  cin >> n;
  rep(i, n) cin >> p[i];
  map<int, int> s;
  rep(i, n) s[p[i]] = i;
  sort(p, p + n);
  rep(i, n) res += (i & 1) != (s[p[i]] & 1);
  cout << res / 2 << endl;
  return 0;
}


Measured memory_bytes: 5376
N = int(input())
B = list(map(int,input().split()))

ans = B[-1]
pre = B[-1]
for i in reversed(range(0,N-2)):
  
  now = B[i]
  if now <= pre:
    ans += now
  else:
    ans += pre
  pre = now
print(ans+B[0])

Measured memory_bytes: 3060
#include<stdio.h>

	int num[10000000]={0};
int main(void){
	int N;

	scanf("%d",&N);
	int i,j;

	int sum=0;

	for(i=1;sum<N;i++){
		sum += i;
		num[i] = 1;
	}

	i--;

	if(sum==N){
		for(j=1;j<=i;j++){
			printf("%d\n",j);
		}
	}
	else{
		num[sum-N]=0;
		for(j=1;j<=i;j++){
			if(num[j]==1)printf("%d\n",j);
		}
	}
	return 0;
}



Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(clippy::many_single_char_names)]
#![allow(clippy::suspicious_arithmetic_impl)]

// using Rust(1.42.0)
// My Library Repo is at "https://github.com/Loptall/prcn_lib"
// check available crates on AtCoder at "https://atcoder.jp/contests/language-test-202001"

/*
    AtCoder Language Update 2020204 お疲れ様でした! 有難いです(p.s. 過去問対応もありがとうございます)
*/

// from std...
use std::cmp::{
    max, min,
    Ordering::{Equal, Greater, Less},
};
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
use std::mem::swap;
use std::ops::*;
use std::usize::{MAX, MIN};
use std::{i128, i16, i32, i64, i8, isize, u128, u16, u32, u64, u8, usize};

// Dep crates are...
use itertools::*;
use itertools_num::*;
use lazy_static::lazy_static;
use maplit::{btreemap, btreeset, hashmap, hashset};
use num_bigint::{BigInt, BigUint};
use num_complex::Complex;
use num_integer::{binomial, gcd, lcm, Integer};
use num_rational::Rational;
use num_traits::{One, Zero};
use permutohedron::Heap;
use petgraph::unionfind::UnionFind;
use proconio::{fastout, input, is_stdin_empty, marker::*};
use rand::random;

// code...
// #[fastout]
fn main() {
    input! {
        a: u128, b: Chars
    }

    let ans: u128 = (a * 100 * b[0].to_string().parse::<u128>().unwrap()
        + a * 10 * b[2].to_string().parse::<u128>().unwrap()
        + a * b[3].to_string().parse::<u128>().unwrap())
        / 100;
    println!("{}", ans);
}


Measured memory_bytes: 2104
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		Integer[] A = new Integer[N];
		for(int i=0; i<N; i++)
			A[i] = sc.nextInt();
		Arrays.sort(A);
		
		int[] coef = new int[N];
		for(int i=0; i<N-1; i++) {
			if(i%2==0) {
				coef[i]++;
				coef[i+1]--;
			} else {
				coef[i]--;
				coef[i+1]++;
			}
		}
		Arrays.sort(coef);
		long sum1 = 0;
		for(int i=0; i<N; i++)
			sum1 += (long)coef[i]*A[i];

		Arrays.fill(coef, 0);
		for(int i=0; i<N-1; i++) {
			if(i%2==0) {
				coef[i]--;
				coef[i+1]++;
			} else {
				coef[i]++;
				coef[i+1]--;
			}
		}
		Arrays.sort(coef);
		long sum2 = 0;
		for(int i=0; i<N; i++)
			sum2 += (long)coef[i]*A[i];
		
		System.out.println(Math.max(sum1, sum2));
		sc.close();
	}
}


Measured memory_bytes: 62880
S=input()
T=input()
lenS=len(S)
lenT=len(T)
lendiff=lenS-lenT
ans=lenT
for i in range(lendiff+1):
    cost=lenT
    for j in range(lenT):
        if T[j]==S[i+j]:
            cost-=1
    ans=min(ans,cost)
print(ans)

Measured memory_bytes: 9020
A, B, C = map(int, input().split())

if C - A >= 0:
    ans = A
    C -= A
else:
    ans = B + C
    print (ans)
    exit()

if C - B >= 1:
    ans += 2 * B + 1
elif C == B:
    ans += 2 * C
else:
    ans += B + C

print (ans)

Measured memory_bytes: 3060
#include<stdio.h>
int main()
{
  char str[3];
  int i;

  scanf("%s",&str);

      if(str[0]=='R')
	{
	  if (str[1]=='S')
	    {
	      printf( "1\n");
	    }
	  else if (str[1]=='R' && str[2]=='S' )
	    {
	      printf( "2\n" );
	    }
	  else printf( "3\n" );
	}
      else
	{
	  if (str[1]=='R')
	    {
	      if (str[2]=='R')
		{
		  printf("2\n");
		}
	      else
		{
		  printf("1\n");
		}
	    }
	  else
	    {
	      if (str[2]=='S')
		{
		  printf("0\n");
		}
	      else
		{
		  printf("1\n");
		}

	    }
	}

  
  return 0;
}


Measured memory_bytes: 1656
(* O(n) *)
let rec fold_btw f a i n = if i >= n then a else fold_btw f (f a i) (i + 1) n

(* O(n^2) *)
let solve n a_s =
  let a_s = Array.of_list a_s in
  fold_btw
    (fun acc_i i ->
      fold_btw
        (fun acc_j j ->
          max acc_j (abs (a_s.(i) - a_s.(j))))
          acc_i
        (i + 1)
        n)
    0
    0
    n

let read_ints () = read_line () |> Str.split (Str.regexp " ") |> List.map int_of_string

let _ =
  let n = read_int () in
  read_ints () |> solve n |> string_of_int |> print_endline

Measured memory_bytes: 384
#include <iostream>
#include <cstring>
#include <queue>
#include <set>
#include <vector>
#include <cmath>
#include <stack>
#include <string>
#include <queue>
#include <algorithm>
#include <cstdio>
#include <map>
using namespace std;
#define INF 0x3f3f3f3f
int a[10];
bool judge() {
	if(a[0] == a[4] && a[1] == a[3])
		return true;
	return false;
}
int main(){
	int A, B, sum = 0;
	scanf("%d%d", &A, &B);
	for (int i = A; i <= B; ++i) {
		int t = i, k = 0;
		while (t) {
			a[k++] = t % 10;
			t /= 10;
		}
		if (judge()) {
		//	cout << i << endl;
			sum++;
		}
	}
	printf("%d\n", sum);
	//system("pause");
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<utility>
#include<cmath>
#include<algorithm>

using namespace std;

typedef pair<int, int> P;

int cave_num[1000][1000];
bool is_prime[1000001];
P trans[1000001];
P dp[1000001];
int m;

void prime() {
	int p = 0;
	for (int i = 0; i <= 1000000; i++)is_prime[i] = true;
	is_prime[0] = is_prime[1] = false;
	for (int i = 2; i <= 1000000; i++) {
		if (is_prime[i]) {
			for (int j = 2 * i; j <= 1000000; j += i)is_prime[j] = false;
		}
	}
}

P dfs(int n) {
	if (dp[n].first != -1)return dp[n];
	int res1 = 0, res2 = 0;
	P now = trans[n];
	for (int i = -1; i <= 1; i++) {
		if (now.second + 1 > 999)break;
		if (now.first + i < 0 || now.first + i>999)continue;
		if (cave_num[now.first + i][now.second + 1] > m)continue;
		P next = dfs(cave_num[now.first + i][now.second + 1]);
		if (res1 <= next.first) {
			if (res1 == next.first) {
				res2 = max(res2, next.second);
			}
			else {
				res2 = next.second;
			}
			res1 = next.first;
		}
	}
	if (is_prime[n]) {
		if (res2 == 0)res2 = n;
		res1++;
	}
	return dp[n] = P(res1, res2);
}

void num() {
	int sx = 499, sy = 500;
	int x = 1; cave_num[sx][sy] = x; trans[x] = P(sx, sy);
	for (int i = 1; i <= 999; i++) {
		if (i % 2) {
			for (int j = 0; j < i; j++) {
				cave_num[++sx][sy] = ++x;
				trans[x] = P(sx, sy);
			}
			for (int j = 0; j < i; j++) {
				cave_num[sx][--sy] = ++x;
				trans[x] = P(sx, sy);
			}
		}
		else {
			for (int j = 0; j < i; j++) {
				cave_num[--sx][sy] = ++x;
				trans[x] = P(sx, sy);
			}
			for (int j = 0; j < i; j++) {
				cave_num[sx][++sy] = ++x;
				trans[x] = P(sx, sy);
			}
		}
	}
	for (int i = 0; i < 999; i++) {
		cave_num[--sx][sy] = ++x;
		trans[x] = P(sx, sy);
	}
}

int main() {
	int n;
	prime();
	num();
	while (scanf("%d %d", &m, &n), m) {
		for (int i = 0; i <= m; i++)dp[i] = P(-1, -1);
		P p = dfs(n);
		printf("%d %d\n", p.first, p.second);
	}
}

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

int main(){
    lint n, s; cin >> n >> s;

    if(n == s){
        cout << n + 1 << endl;
        return 0;
    }

    for(lint b=2;b*b<=n;b++){
        lint a = n, d = 0;
        while(a){
            d += a % b;
            a /= b;
        }
        if(d == s){
            cout << b << endl;
            return 0;
        }
    }

    vector<lint> ans;
    lint m = n - s;
    for(lint i=1;i*i<=m;i++){
        if(m % i == 0){
            lint b = m / i + 1, a = n, d = 0;
            while(a){
                d += a % b;
                a /= b;
            }
            if(d == s) ans.push_back(b);
        }
    }
    
    if(!ans.size()) cout << -1 << endl;
    else cout << *min_element(ans.begin(), ans.end()) << endl;

    return 0;
}

Measured memory_bytes: 256
def CountingSort(A,B,num):

	k = max(A)
	C = [0 for _ in range(k+1)]
	#C[i]にiの出現回数を記録する
	for i in A:
		C[i] += 1

	#C[i]にi以下の数の出現数を記録する =>累積度数分布を出力
	for j in range(1,k+1):
		C[j] += C[j-1]
	for h in range(num-1,-1,-1):
		B[C[A[h]]-1] = A[h]
		C[A[h]] -= 1

if __name__ == '__main__':

	num = int(input())
	A = [int(i) for i in input().split()]

	B = [0 for _ in range(num+1)]
	CountingSort(A,B,num)

	B.pop()
	print(" ".join(map(str,B)))



Measured memory_bytes: 242188
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<deque>
#include<functional>
#include<iterator>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<utility>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(n);i>=1;i--)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;
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;}
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll digsz(ll x){if(x==0) return 1;else{ll ans=0;while(x){x/=10;ans++;}return ans;}}
ll digsum(ll x){ll sum=0;while(x){sum+=x%10;x/=10;}return sum;}
vector<ll> pw2(62,1);vector<ll> pw10(19,1);


int main(){
    {rep1(i,61) pw2[i]=2*pw2[i-1];}
    {rep1(i,18) pw10[i]=10*pw10[i-1];}
    ll N,K; cin>>N>>K;
    double ans=0.0;
    rep1(i,N){
        //1/N*1/pw2[now]
        //
        ll now=0,tmp=i;
        while(tmp<K){
            tmp*=2;
            now++;
        }
        //cout<<now<<endl;
        ans+=1/(double)(pw2[now]);
    }
    printf("%.13f\n",ans/N);
}


Measured memory_bytes: 3728
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <numeric>
#include <sstream>
#include <string>
#include <string.h>
#include <tuple>
#include <vector>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i >= 0; i--)
#define REP1O(i,x) for(int i{ 1 }; i < (int)(x); i++)
#define REP1C(i,x) for(int i{ 1 }; i <= (int)(x); i++)

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

using namespace std;

typedef int64_t ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef pair<int, int> pii;
typedef tuple<int, int, int> tupiii;
typedef tuple<ll, ll, ll> tuplll;

const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INTMAX = 2147483647;
const ll LLMAX = 9223372036854775807;

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; }
void SWAP(ll& a, ll& b) { a ^= b; b ^= a; a ^= b; }
void SWAP(int& a, int& b) { a ^= b; b ^= a; a ^= b; }


class C {
	int n, tle;
public:
	C()
	{
		cin >> n >> tle;
	}
	void solve()
	{
		ll ac{ (n - tle) * 100 + tle * 1900};

		ac <<= tle;

		cout << ac << endl;
	}
};


int main()
{
	C solution;
	solution.solve();

	return 0;
}

Measured memory_bytes: 256
N = int(input())
P = [int(x) for x in input().split()]

buf_1 = P[0]
buf_2 = 1
for i in range(1,N) :
    if buf_1 > P[i] :
        buf_2 = buf_2 + 1
    buf_1 = min(buf_1,P[i])

print(buf_2)

Measured memory_bytes: 26012
import math
import numpy as np

n,m=(int(x) for x in input().split())
a=list(map(int,input().split()))
a_sort=np.sort(a)[::-1]
sum=np.sum(a)
if a_sort[m-1] >= (sum/4/m):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 21656
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<map>
using namespace std;
const int maxn = 1e6+10;

int read(){
	int x=0,f=1;
	char c=getchar();
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c)){x=(x<<3)+(x<<1)+c-48;c=getchar();}
	return x*f;
}

int k,m,n;
int num=1e6;
int prime[maxn],vis[maxn],tot=0;
inline void init(){
	for(register int i=2;i<=num;i++){
		if(!vis[i]){prime[++tot]=i;}
		for(register int j=1;j<=tot && prime[j]*i<=num;j++){
			vis[prime[j]*i]=1;
			if(i%prime[j]==0)break;
		}
	}
	return ;
}

int main(){
	init();
	n=read();
	for(register int i=1;i<=n;i++){
		if(prime[i]>=n){printf("%d\n",prime[i]);return 0;}
	}
	return 0;
}


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

int dp[100][100];

int main(void)
{   
    int n;
    cin >> n;
    pair<int, int> rc[n];
    rep(i, n) cin >> rc[i].first >> rc[i].second;

    vector<vector<int> > dp(n, vector<int>(n, 1e9));
    
    rep(i, n) {
        dp[i][i] = 0;
    }

    for(int i = 1; i <= n-1; i++) {
        for(int j = 0; j <= n - 1 - i; j++) {
            for(int k = j; k < j + i; k++) {
                dp[j][j+i] = min(dp[j][j+i], dp[j][k] + dp[k+1][j+i] + rc[j].first*rc[k].second*rc[j+i].second);
            }
        }
    }

    cout << dp[0][n-1] << endl;
    return 0;
}


Measured memory_bytes: 3188
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class D
{
	public static void Main() => (new Solver()).Solve();
}


public class Solver
{
	public void Solve()
	{
		int N = GetInt();
		int K = GetInt();
		string S = GetString();

		int cnt = 1;
		for(int i = 1; i < N; i++)
			if(S[i] != S[i - 1])
				cnt++;

		Console.WriteLine(N - 1 - Math.Max(0, cnt - 1 - 2 * K));
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(int N) => Enumerable.Range(0, N).Select(_ => GetInt()).ToArray();
	public static long[] GetLongs(int N) => Enumerable.Range(0, N).Select(_ => GetLong()).ToArray();
	public static double[] GetDoubles(int N) => Enumerable.Range(0, N).Select(_ => GetDouble()).ToArray();
	public static string[] GetStrings(int N) => Enumerable.Range(0, N).Select(_ => GetString()).ToArray();
}


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

int N;
long long int v[111111];
long long int MAX = 1000000000000000000;

int main () {
    cin >> N;
    for(int i=0;i<N;i++){
        cin >> v[i];
        if(v[i] == 0) {
            cout << "0" << endl;
            return 0;
        }
    }
    for(int i=0;i<N-1;i++){
        if(MAX / v[i] < v[i+1]) {
            cout << "-1" << endl;
            return 0;
        } else {
            v[i+1] *= v[i];
        }
    }
    cout << v[N-1] << endl;
    return 0;
}

Measured memory_bytes: 4388
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
using namespace std;

int main() {
    int AB, BC, CA;
    cin >> AB >> BC >> CA;

    if (AB*AB == BC*BC + CA*CA) {
        cout << BC * CA / 2 << endl;
    } else if (BC*BC == CA*CA + AB*AB) {
        cout << CA * AB / 2 << endl;
    } else {
        cout << AB * BC / 2 << endl;
    }

    return 0;
}


Measured memory_bytes: 256
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	n = readline() |> parseInt
	a = Array{Int}(2,n)
	for i in 1:n
		a[:,i] = readline() |> split |> parseMap
	end
	a = sortcols(a, by=z->z[2])
	t = 0
	flg = 0
	for i in 1:n
		t += a[1,i]
		if t > a[2,i]
			flg = 1
			break
		end
	end
	println(flg==0?"Yes":"No")
end

main()

Measured memory_bytes: 185708
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
using namespace std;

int main(){
  long a,b,c,x;
  cin >> a >> b >> c >> x;
  long ans = 0;
  for(long i = 0; i <= a; i++){
    for(long j = 0; j <= b; j++){
      for(long k = 0; k <= c; k++){
        if(i*500+j*100+k*50==x){
          ans++;
        }
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

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

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

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

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

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

fn main() {
    input!{
        x: usize,
    }
    let mut sum = 0;
    for i in 0..x {
        sum += i + 1;
        if sum - x <= i {
            println!("{}", i + 1);
            return;
        }
    }
    panic!();
}


Measured memory_bytes: 4352
from sys import stdin,stdout
from collections import defaultdict
import math
from bisect import bisect
input=stdin.readline
#def print(x):stdout.write(str(x)+'\n')
n,m=map(int,input().split())
l=[0]*n
d=defaultdict(set)
for i in range(m):
    v1,v2=map(int,input().split())
    d[v1-1].add(v2-1)
    d[v2-1].add(v1-1)
for i in d:
    d[i]=list(d[i])
ans=[]
for i in range(n):
    s=[]
    c=0
    if not l[i]:
        s.append(i)
        l[i]=1
        c=1
        for j in s:
            for k in d[j]:
                if not l[k]:
                    s.append(k)
                    l[k]=1
                    c+=1
        ans.append(c)
#print(ans)
print(max(ans))

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

namespace ConsoleApp11
{
    class Class18
    {
        static void Main()
        {
            var I = Console.ReadLine().Split().Select(long.Parse).ToArray();
            if (I[0] == I[1])
            {
                Console.WriteLine(0);
                return;
            }
            else if ((I[0] + I[1]) % 2 != 0)
            {
                Console.WriteLine("IMPOSSIBLE");
            }
            else
            {
                long K = I.Sum()/2;
                Console.WriteLine(K);

            }
        }
    }
}

Measured memory_bytes: 13396
MOD = 10**9+7
n = int(input())

dp = [[[[0] * 4 for _ in range(4)] for _ in range(4)] for _ in range(n+1)]
dp[0][0][0][0] = 1

for i in range(n):
    for c1 in range(4):
        for c2 in range(4):
            for c3 in range(4):
                for nxt in range(4):
                    if nxt == 3 and c1 == 2 and c2 == 1: continue
                    if nxt == 2 and c1 == 3 and c2 == 1: continue
                    if nxt == 3 and c1 == 1 and c2 == 2: continue
                    if nxt == 3 and c2 == 2 and c3 == 1: continue
                    if nxt == 3 and c1 == 2 and c3 == 1: continue
                    dp[i+1][nxt][c1][c2] += dp[i][c1][c2][c3]
                    dp[i+1][nxt][c1][c2] %= MOD

ans = 0
for i in range(4):
    for j in range(4):
        for k in range(4):
            ans += dp[n][i][j][k]
            ans %= MOD

print(ans)


Measured memory_bytes: 3444
#include<iostream>
using namespace std;
int main(void)
{
    long long n,a,b,cnt=0;
    cin >> n >> a >> b;
    cnt+=n/(a+b)*a;
    n%=(a+b);
    if(n>=a)
    {
        n-=a;
        cnt+=a;
    }
    else cnt+=n;
    cout << cnt;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string t;
  cin >> t;
  
  for(int i=0; i < t.size(); i++) {
    if(t[i]=='?'){
      t[i]='D';
    }
  }
  
  cout << t << endl;
      
  
  
}


Measured memory_bytes: 3756
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<queue>
#include<algorithm>
using namespace std;
int read()
{
	char c=getchar();
	int res=0;
	while(c<'0'||c>'9') c=getchar();
	while(c>='0'&&c<='9') res=(res<<1)+(res<<3)+(c^48),c=getchar();
	return res;
}
int n,h[200005],cnt=1,pre[200005],s,t,p[200005],num;
vector<int> e[200005];
struct que
{
	int x,y;
}hs[200005];
struct Edge
{
	int to,next,d;
}w[800005];
void add(int x,int y,int d)
{
	w[++cnt]=(Edge){y,h[x],d};
	h[x]=cnt;
	w[++cnt]=(Edge){x,h[y],0};
	h[y]=cnt;
}
bool bfs()
{
	memset(pre,0,sizeof(pre));
	pre[s]=1;
	queue<int> q;
	q.push(s);
	while(!q.empty())
	{
		int u=q.front();
		q.pop();
		for(int i=h[u];i;i=w[i].next)
		{
			int to=w[i].to;
			if(w[i].d&&!pre[to])
			{
				pre[to]=pre[u]+1;
				if(to==t) return 1;
				q.push(to);
			}
		}
	}
	return 0;
}
int dfs(int x,int p)
{
	if(x==t||!p) return p;
	int r=p;
	for(int i=h[x];i;i=w[i].next)
	{
		int to=w[i].to;
		if(r&&w[i].d&&pre[to]==pre[x]+1)
		{
			int p2=dfs(to,min(r,w[i].d));
			if(p2)
			{
				w[i].d-=p2,w[i^1].d+=p2;
				r-=p2;
			}
			if(!r) return p;
		}
	}
	if(r==p) pre[x]=0;
	return p-r;
}
int Dinic()
{
	int ans=0;
	while(bfs()) ans+=dfs(s,0x3f3f3f3f);
	return ans;
}
bool Solve()
{
	for(int i=1;i<n;i++)
	for(int j=h[i];j;j=w[j].next)
	{
		int to=w[j].to;
		if(!to) continue;
		if(!w[j].d) p[i]=to-n+1;
	}
	queue<int> q;
	q.push(n);
	while(!q.empty())
	{
		int u=q.front();
		q.pop();
		num++;
		int sz=e[u].size();
		for(int i=0;i<sz;i++)
		{
			int x=e[u][i];
			if(p[x]) hs[x]=((que){u,p[x]}),q.push(p[x]),p[x]=0;
		}
	}
	return num==n;
}
int main()
{
	n=read();
	s=0,t=2*n-1;
	for(int i=1;i<=n-1;i++) add(s,i,1),add(i+n-1,t,1);
	for(int i=1;i<n;i++)
	{
		int num=read();
		while(num--)
		{
			int x=read();
			if(x!=n) add(i,x+n-1,1);
			e[x].push_back(i);
		}
	}
	if(Dinic()<n-1){puts("-1");return 0;}
	if(!Solve()){puts("-1");return 0;}
	for(int i=1;i<n;i++) printf("%d %d\n",hs[i].x,hs[i].y);
}

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

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

	bool ans = false;

	for(int i=1;i<=9;i++){
		for(int j=1;j<=9;j++){
			if(N==i*j) ans =true;
		}
	}

	if(ans) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;

	return 0;
}

Measured memory_bytes: 3636
solve :: [Int] -> Int
solve [] = 0
solve (a0:a1) = (beki a0) + (solve a1)
    
beki :: Int -> Int
beki 0 = 0
beki n 
    | n `mod` 2 == 0   = beki(n `div` 2)+1
    |otherwise         = 0   

main = do
    getLine 
    a <- map read . words <$> getLine
    print $ solve a
    

Measured memory_bytes: 4988
def FindBlack(s, i, j, h, w)
  adjacent = false
  x = [1,0,-1,0]
  y = [0,1,0,-1]
  4.times do |k|
    if( (i+y[k]>=0) && (j+x[k]>=0) && (i+y[k]<=h-1) && (j+x[k]<=w-1) )
      if( s[i+y[k]][j+x[k]] == "#")
        adjacent = true
      end
    end
  end
  adjacent
end

h, w = gets.split.map(&:to_i)
s = []
h.times do |i|
  s[i] = gets.chomp
end

flag = false
h.times do |i|
  w.times do |j|
    if s[i][j] == "#"
      flag = FindBlack(s, i, j, h, w)
      if not flag 
        puts("No")
        exit
      end
    end
  end
end
puts("Yes")

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


int main() {
  vector<int> list(3);
  for(int i = 0; i<3; i++){
    cin >> list.at(i); 
  }
  
  sort(list.begin(),list.end());
  
  int answer = list.at(0) + list.at(1) + 10*list.at(2);
  cout << answer << endl;
  
}

Measured memory_bytes: 256
//do not think about past and stay in this moment
//organize and work - Abhinav IIITA
#include <bits/stdc++.h>
#include <ctime>
using namespace std;
#define int long long
#define ld long double
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end() 
const ld pi = acos(-1.0);
const int day[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int mod;
int h,w;
int mx=-1;
vector<int> adj[1000];
bool vis[20][20];
int level[20][20];
string s[20];
int zrr[100005];
void fact(){
	zrr[0]=1;
	for(int i=1;i<100005;++i){
		zrr[i]=i*zrr[i-1];
		zrr[i]%=mod;
	}
}
int modexp(int x){
	int y=mod-2;
	int res=1;
	while(y>0){
		if(y&1){
			res*=x;
			res%=mod;
		}
		x*=x;
		x%=mod;
		y/=2;
	}
	return res;
}
void dfs(int x,int y){
	queue<pair<int,int>> q;
	q.push({x,y});
	queue<int> r;
	r.push(0);
	while(!q.empty()){
		pair<int,int> xp = q.front();	q.pop();
		int lpp=r.front(); r.pop();
		int cor[4][2];
		cor[0][0]=xp.first-1 ;cor[0][1]=xp.second ;
		cor[1][0]=xp.first+1 ;cor[1][1]=xp.second ;
		cor[2][0]=xp.first ;cor[2][1]=xp.second-1 ;
		cor[3][0]=xp.first ;cor[3][1]=xp.second+1 ;
		for(int i=0;i<4;++i){
				if(cor[i][0]<0 || cor[i][0]>=h)
				continue;
				if(cor[i][1]<0 || cor[i][1]>=w)
				continue;
				if(s[cor[i][0]][cor[i][1]]=='#')
				continue;
				if(!vis[cor[i][0]][cor[i][1]]){
					q.push({cor[i][0],cor[i][1]});
					r.push(lpp+1);
				}
		}
		level[xp.first][xp.second]=lpp;
		vis[xp.first][xp.second]=true;
	}
	/*for(int i=0;i<h;++i){
		for(int j=0;j<w;++j)
		cout<<vis[i][j]<<" ";
		cout<<endl;
	}*/
}
void solve(){	
	cin>>h>>w;
	for(int i=0;i<h;++i)
		cin>>s[i];
	for(int i=0;i<h;++i)
	for(int j=0;j<w;++j)	
	if(s[i][j]=='.'){
		for(int ii=0;ii<h;++ii)
		for(int jj=0;jj<w;++jj)
		{vis[ii][jj]=false; level[ii][jj]=0;}
		dfs(i,j);
		for(int ii=0;ii<h;++ii){
		for(int jj=0;jj<w;++jj){
		mx=max(mx,level[ii][jj]);
		//cout<<level[ii][jj]<<" ";
		}//cout<<endl;}
	}
	}
	cout<<mx;
}

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


void spp(){
	int n,k;
	cin>>n>>k;
	int arr[n];
	for(int i=0;i<n;++i)
	cin>>arr[i];
	sort(arr,arr+n);
	fact();
	int mxs=0;
	for(int i=k-1;i<n;++i){
		int res=(((zrr[i]*modexp(zrr[k-1]))%mod)*modexp(zrr[i-k+1]))%mod;
		//cout<<res<<" res is\n";
		mxs+=(res*arr[i])%mod;
		//cout<<mxs<<" mxs is\n";
		mxs%=mod;
	}
	int mns=0;
	for(int i=n-k;i>=0;--i){
		int res=(((zrr[n-i-1]*modexp(zrr[k-1]))%mod)*modexp(zrr[n-i-k]))%mod;
		mns+=(res*arr[i])%mod;
		mns%=mod;
	}
	//cout<<mxs<<" "<<mns<<endl;
	cout<<(mxs-mns+mod)%mod<<endl;
}

int32_t main()
{
	mod=1e9+7;
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); 	
	int t=1;
	//cin>>t;
	while(t--)
	spp();
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define P(x) cout << (x) << "\n"
#define p(x) cout << (x)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i));
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a), i##_len=(n); i>i##_len; --i)
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
#define fi first
#define se second
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS)
struct Point {
	double x, y;
	Point(double x = 0, double y = 0) : x(x), y(y) {}
	Point operator + (Point p) { return Point(x + p.x, y + p.y); }
	Point operator - (Point p) { return Point(x - p.x, y - p.y); }
	Point operator * (Point p) { return Point(x * p.x, y * p.y); }
	Point operator * (double p) { return Point(x * p, y * p); }
	Point operator / (Point p) { return Point(x / p.x, y / p.y); }
	Point operator / (double p) { return Point(x / p, y / p); }
	void insert(double a, double b) { x = a; y = b; }
	double norm() { return x * x + y * y; }
	double abs() { return sqrt(norm()); }
	bool operator < (const Point &p) const {
		return x != p.x ? x < p.x : y < p.y;
	}
	bool operator == (const Point &p) const {
		return fabs(x - p.x) < EPS && fabs(y - p.y) < EPS;
	}
};
typedef Point Vector;
struct Segment {
	Vector p1, p2;
	Segment(double x1 = 0.0, double y1 = 0.0, double x2 = 0.0, double y2 = 0.0):
		p1(x1, y1), p2(x2, y2) {}
	Segment(Point a1, Point a2) : p1(a1), p2(a2) {}
	void insert(Vector a1, Vector a2) { p1 = a1; p2 = a2; }
};
inline double dot(Vector a, Vector b) { return a.x * b.x + a.y * b.y; }
inline double cross(Vector a, Vector b) { return a.x * b.y - a.y * b.x; }
inline bool isOrthogonal(Vector a, Vector b) { return equals(dot(a, b), 0.0); }
inline bool isOrthogonal(Vector a1, Vector a2, Vector b1, Vector b2) {
	return isOrthogonal(a1 - a2, b1 - b2);
}
inline bool isOrthogonal(Segment s1, Segment s2) {
	return equals(dot(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0);
}
inline bool isParallel(Vector a, Vector b) { return equals(cross(a, b), 0.0); }
inline bool isParallel(Vector a1, Vector a2, Vector b1, Vector b2) {
	return isParallel(a1 - a2, b1 - b2);
}
inline bool isParallel(Segment s1, Segment s2) {
	return equals(cross(s1.p2 - s1.p1, s2.p2 - s2.p1), 0.0);
}
Point project(Segment s, Point p) {
	Vector base = s.p2 - s.p1;
	double r = dot(p - s.p1, base) / base.norm();
	return s.p1 + base * r;
}
Point reflect(Segment s, Point p) {
	return p + (project(s, p) - p) * 2.0;
}
int main() {
	cout << setprecision(10) << fixed;
	Segment s; cin >> s.p1.x >> s.p1.y >> s.p2.x >> s.p2.y;
	int q; cin >> q;
	Point p1, p2;
	rep(i, 0, q) {
		cin >> p1.x >> p1.y;
		p2 = reflect(s, p1);
		cout << p2.x << " " << p2.y << "\n";
	}
	return 0;
}

Measured memory_bytes: 3308
#include <stdio.h>

int search(char str[]);

int main(){
      char str[10];
      scanf("%s",str);
      printf("%d",search(str));

}

int search(char str[]){
      int i,num=0;
      for(i=0;str[i]!='\0';i++){
            if(str[i]=='2')num++;
      }
      return num;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()

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

    int a, b, h;
    cin >> a >> b >> h;
    cout << (a + b) * h / 2 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <set>
#include <queue>
#include <map>
#include <stack>
using namespace std;

#define mod 1000000007
#define ten5 100005
#define ten52 200005
#define ten6 1000005
#define PI 3.1415926
#define pb(x) push_back(x)
#define mkpr(x,y) make_pair(x,y)
#define all(x) x.begin(),x.end()

typedef long long int ll;

ll general,total;
//ll chk[55];
//ll num[55];
//ll num2[55];
//ll num[ten5];
//ll num2[ten5];
//char cmap[10][10];
//priority_queue<ll> pqll;   //decrease
priority_queue<double> pqd;
//stack<int> stk;
vector<pair<ll,ll>> vpll;
vector<pair<double,double>> vpdd;
//vector<ll> vll;
//vector<double> vd;
//deque<ll> deq[55];
//list<int> li;
//set<int> sint;
//set<ll> sll;
//map<ll,ll> mp;

/*ll cmp(pair<ll,ll> a,pair<ll,ll> b)
{
    return a.first<b.first;
    //arrising
}*/

int main()
{
    double ans=0.0,half,d,d1,d2;
    //float f,g,h;
    long long int sum,sum2,n1,n2,n3;
    long long int m,n,o,i,j,k=1;
    long long int a,a1,a2,a3,a4,a5,a6;
    sum=sum2=n1=n2=n3=0;
    a=a1=a2=a3=a4=a5=a6=0;
    //string s,s1;
    //char now,pre,c;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>a1>>a2;
        vpll.pb(mkpr(a1,a2));
        //vpdd.pb(mkpr(d1,d2));
    }
    for(i=0;i<n;i++)
    {
        for(j=i+1;j<n;j++)
        {
            /*d1=abs(vpdd[i].first-vpdd[j].first);
            d2=abs(vpdd[i].second-vpdd[j].second);*/
            d1=(double)abs(vpll[i].first-vpll[j].first);
            d2=(double)abs(vpll[i].second-vpll[j].second);
            ans+=sqrt(d1*d1+d2*d2);
        }
    }
    ans=ans*2/n;
    printf("%.7lf",ans);
    return 0;
}





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

#define NEW(p,n){p=malloc((n)*sizeof(p[0]));if(p==NULL){printf("not enough memory\n");exit(1);};}
//pの型の変数n個の要素分のメモリを確保し、そのアドレスをpに代入するマクロ

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define SWAP(type, x, y) do { type tmp = x; x = y; y = tmp; } while (0)

#define MOD 1000000007 

typedef struct{
    int l;
    int r;
}data;

int main(void){
    int Q;
    scanf("%d",&Q);

    //A[0]~A[N-1]に格納する
    data* A;
    NEW(A,Q);
    for(int i=0;i<Q;i++){
        scanf("%d%d",&A[i].l,&A[i].r);
    }

    //iが素数のとき、prime[i]は1、そうでないなら0
    int* prime;
    int N=1e5;
    NEW(prime,N+1);
    prime[1]=0;
    for(int i=2;i<=N;i++) prime[i]=1;
    for(int i=2;i<=N;i++){
        if(prime[i]==1){
            int j=2;
            while(i*j<=N){
                prime[i*j]=0;
                j++;
            }
        }
    }

    int* ans;
    NEW(ans,N+1);
    ans[0]=0;
    for(int i=1;i<=N;i++){
        if(prime[i]){
            if(prime[(i+1)/2]) ans[i]=1;
        }
    }
    for(int i=1;i<=N;i++) ans[i]+=ans[i-1];

    for(int i=0;i<Q;i++){
        printf("%d\n",ans[A[i].r]-ans[A[i].l-1]);
    }

    return 0;
}

Measured memory_bytes: 2176
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111;
using namespace std;
typedef long long lint;

inline lint Bsize(lint n) { return (1LL << (n + 2)) - 3; }
inline lint patty(lint n) { return (1LL << (n + 1)) - 1; }

lint dfs(lint N, lint X) {

	if (X <= 1) return N == 0 && X == 1 ? 1LL : 0LL;
	else if (X <= Bsize(N - 1) + 1) return dfs(N - 1, X - 1);
	else if (X <= Bsize(N) - 1) return patty(N - 1) + dfs(N - 1, X - 2 - Bsize(N - 1)) + 1;
	else return 2 * patty(N - 1) + 1;

}

int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);

	lint N, X;
	cin >> N >> X;

	cout << dfs(N, X) << "\n";

	return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.util.regex.Pattern;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s=sc.next();
        String t=sc.next();
        flag:for(int i=s.length()-t.length();i>=0;i--){
            for(int j=0;j<t.length();j++){
                if(s.charAt(i+j)!=t.charAt(j)&&s.charAt(i+j)!='?'){
                    continue flag;
                }
            }
            System.out.println(s.substring(0,i).replaceAll(Pattern.quote("?"), "a")+t+s.substring(i+t.length()).replaceAll(Pattern.quote("?"),"a"));
            return;
        }
        System.out.println("UNRESTORABLE");
    }
}

Measured memory_bytes: 21844