akhauriyash/Code-Regression huggingface dataset:
open Batteries
module EnumL = Enum.Labels
module ListL = List.Labels
module ArrayL = Array.Labels

let dbg0 x = Printf.eprintf "[debug]%s\n" @@ dump x
let dbg1 x = dbg0 x; x

let id = identity

let (++) n m = List.range n `To m
let (++-) n m = if n >= m then List.range n `Downto m else []
let (++^) n m = if n < m then List.range n `To (pred m) else []

let scan fmt = Scanf.sscanf (read_line ()) fmt

let scan_lines n fmt f =
  if n = 0 then []
  else List.map (fun _ -> scan fmt f) (1 ++ n)

let scan_list sep cnv =
  let line = read_line () in
  (match sep with
   | None -> List.map String.of_char @@ String.to_list line
   | Some sep -> String.split_on_char sep line)
  |> List.map cnv

let scan_array ?sep cnv = Array.of_list @@ scan_list sep cnv

let scan_matrix n m e ?sep conv =
  let arr = Array.make_matrix n m e in
  ListL.iter (0 ++^ n)
    ~f:(fun i -> arr.(i) <- Array.of_list @@ scan_list sep conv);
  arr

let rec powerset e =
  match Enum.get e with
  | None -> Enum.singleton @@ Enum.empty ()
  | Some v ->
    let f = powerset e in
    let g = Enum.clone f in
    EnumL.map f ~f:(fun x -> let y = Enum.clone x in push y v; y)
    |>  Enum.append g

let permutations l =
  let rec aux l =
    let rec interleave x = function
      | [] -> [[x]]
      | (hd::tl) as lst ->
        (x::lst) ::
        (ListL.map ~f:(List.cons hd)  @@ interleave x tl)
    in
    match l with
    | [] -> [[]]
    | hd::tl -> List.concat @@ List.map (interleave hd) @@ aux tl in
  let l = List.sort (List.compare Int.compare) @@ aux @@ List.of_enum l in
  List.enum % ListL.map ~f:List.enum @@ l

let intersection l =
  EnumL.filter ~f:(fun x -> EnumL.exists ~f:((=) x) @@ Enum.clone l)

let zip l m =
  let n = min (List.length l) (List.length m) in
  List.combine (List.take n l) (List.take n m)

let lower_bound n f =
  let rec aux l u =
    if u - l > 1 then
      let m = (l + u) / 2 in
      if f m then aux l m
      else aux m u
    else u in aux (-1) n

let between n x m = n <= x && x < m

module Comb = struct
  let prime = 1_000_000_007

  let ( * ) a b = a * b mod prime

  let rec pow n m =
    if m = 0 then 1
    else if m mod 2 = 0 then pow (n*n) (m/2)
    else n * pow (n*n) (m/2)

  let fact n =
    let rec aux m acc =
      if m = 0 then acc
      else aux (pred m) @@ m * acc
    in aux n 1

  let comb n k =
    if n <= 0 || k <= 0 then 1
    else
      fact n * (pow (fact k) (prime-2)) * (pow (fact (n - k)) (prime-2))
end

let (x,y) = scan "%d %d" Tuple2.make

exception Found

let () =
  try
    ListL.iter (0 ++ x) ~f:(fun k ->
        if (x-k) mod 2 = 0 &&  (x - k) / 2 = (y - 2*k) then
          (Printf.printf "%d\n" @@ Comb.comb (k+ (x-k)/2) k;
           raise Found)
      );
    Printf.printf "0\n"
  with Found -> ()


Measured memory_bytes: 26624
#include<bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long int ll;
typedef  long double ld;
#define F first
#define S second
#define pb push_back
#define forn(i, n) for(int i = 0; i < n; i++)
#define forl(i, n) for(long long i=0;i<n;++i)
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vi>
#define vvl vector<vl>
#define vpi vector<pi>
#define vpl vector<pl>
#define pi pair<int,int>
#define pl pair<ll,ll>
#define pd pair<double,double>
#define vd vector<double>
#define all(x) x.begin(),x.end()
#define mp make_pair
#define TT int T;cin>>T;for(int tt=1;tt<=T;tt++)
ll exp(ll n, ll m, ll md){
    ll a = 1;
    while (m > 0){
        if (m&1) a = (a * n%md) % md;
        m /= 2;
        n = (n*n) % md;
    }
    return a % md;
}

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    fast;
    int a;
    cin>>a;
    cout<<a + a*a +a*a*a;
    return 0;
}   

Measured memory_bytes: 3584
#include <iostream>
#include <vector>
#include <math.h>
#include <string>
#include <stack>
using namespace std;

int main()
{
	stack<int> s;
	int n;
	while (cin >> n)
	{
		if (n == 0)
		{
			cout << s.top() << endl;
			s.pop();
		}
		else
		{
			s.push(n);
		}
	}
	return 0;
}

Measured memory_bytes: 1204
import sys
import math
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def make_adjlist_nond(n, edges):
    res = [[] for _ in range(n+1)]
    for edge in edges:
        res[edge[0]].append(edge[1])
        res[edge[1]].append(edge[0])
    return res


def main():
    N, K = NMI()
    edges = [NLI() for _ in range(N-1)]
    tree = make_adjlist_nond(N, edges)
    stack = deque()
    stack.append(1)
    ans = K
    seen = [False] * (N+1)
    while stack:
        now = stack.pop()
        seen[now] = True
        tmp = K - 2
        if now == 1:
            tmp += 1
        cnt = 0
        for i, goto in enumerate(tree[now]):
            if seen[goto]:
                cnt += 1
                continue
            ans = ans * (tmp - i + cnt) % MOD
            stack.append(goto)

    print(ans % MOD)


if __name__ == "__main__":
    main()

Measured memory_bytes: 40132
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
char STRAWBERRY = '#';
char CAKE = '.';
ll h,w,k;

int main() {
    cin >> h >> w >> k;
    string cakes[h];
    string cakesTemp = "";
    ll cut[h][w] = {0};
    ll noberryLine = 9999;
    ll cakeNumber = 1;
    for(ll i=0; i<h; i++){
        cin >> cakes[i];
        if(cakes[i].find('#') < 0 || cakes[i].find('#') > w){
            if(noberryLine > h){
                noberryLine = i;
            }
        }else{
            if(noberryLine <= h){
                cakesTemp = cakes[i];
                cakes[i] = cakes[noberryLine];
                cakes[noberryLine] = cakesTemp;
                cakesTemp = "";
                noberryLine = 9999;
            }
        }
    }
    for(ll j=0; j<h; j++){
        ll berryNum = 0;
        ll berryNumTemp = 0;
        for(ll k=0; k<cakes[j].length(); k++){
            if(cakes[j][k] == '#')berryNum++;
        }
        for(ll kk=0; kk<cakes[j].length(); kk++){
            if(berryNum == 0){
                cut[j][kk] = cut[j-1][kk];
            }else{
                cut[j][kk] = cakeNumber;
                if(cakes[j][kk] == '#'){
                    berryNumTemp++;
                    if(berryNumTemp < berryNum){
                        cakeNumber++;
                    }
                }
                if(kk == cakes[j].length() - 1){
                    cakeNumber++;
                }
            }
            cout << cut[j][kk];
            if(kk == cakes[j].length() - 1){
                cout << endl;
            }else{
                cout << ' ';
            }
        }
    }
}

Measured memory_bytes: 1664
#include<stdio.h>
using namespace std;
int main()
{
   int A, B;
   scanf("%d %d", &A, &B);
   if(A >= 1 && A <= 13 && B >= 1 && B <= 13){
        if(A==B){
            printf("Draw\n");
        }
    else if(A==1){
        printf("Alice\n");
    }
    else if(B == 1){
        printf("Bob\n");
    }
    else{
        if(A>B){
            printf("Alice\n");
        }
        else{
            printf("Bob\n");
        }
    }
   }
   return 0;
}

Measured memory_bytes: 128
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    TreeMap<Integer,Integer> start = new TreeMap<>();
    TreeMap<Integer,Integer> end = new TreeMap<>();
    for(int i = 0;i<m;i++){
      int a = sc.nextInt();
      int b = sc.nextInt();
      if(a == 1){
        start.put(b,1);
      }
      if(b == n){
        end.put(a,1);
      }
    }
    for(int i = 2;i<n;i++){
      if(start.containsKey(i) && end.containsKey(i)){
        System.out.println("POSSIBLE");
        return;
      }
    }
    System.out.println("IMPOSSIBLE");
  }
}


Measured memory_bytes: 70584
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <map>
using namespace std;

int main(){
    int N;
    cin >> N;
    int C[N],S[N],F[N];
    for(int i=0;i<N;i++){
        cin >> C[i] >> S[i] >> F[i];
    }

    for(int i=0;i<N-1;i++){
        int now = S[i];
        for(int j=i+1;j<N;j++){
            now = now + C[j-1];
            if(j==N-1) break;
            if(now <= S[j]){
                now = S[j];
            }else{
                int k = ((now - S[j]) + (F[j]-1))/F[j];
                if(k < 0) k = 0;
                int Loss = (S[j] + F[j]*k) - now;
                now = now + Loss;
            }
        }
        cout << now << endl;
    }
    cout << 0 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long int ll;
#define pb push_back
typedef pair<ll,ll> pp;

ll mod = 1e9+7;
ll INF = 1e15;

ll powm(ll a , ll b , ll mod)
{
  ll res = 1;
  while(b)
  {
    if(b & 1)
    res = (res *a)%mod;
    a = (a*a)%mod;
    b>>1;
  }
  return res;
}
ll gcd(ll a , ll b);
ll power(ll x , ll y , ll m);

ll modInverse(ll a , ll m)
{
  ll g = gcd(a,m);
  if(g != 1)
  return 1;
  else
  return power(a,m-2,m);

}

ll power(ll x , ll y , ll m)
{
  if(y == 0)
  return 1;
  ll p = power(x , y/2 , m)%m;
  p = (p*p)%m;

  return (y%2 == 0) ? p : (x *p) % m;
}

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





void solve()
{
  string s;
  cin>>s;
  ll sum = 0 , x = 1 , ans = 0;
  ll freq[2019] = {0};
  reverse(s.begin() , s.end());
  for(int i  = 0; i<s.length();i++)
  {
    ++freq[sum];
    sum = (sum + (s[i] - '0')*x)%2019;
    x = x*10 % 2019;
    ans += freq[sum];
  }
  cout<<ans<<"\n";


}



int main()
{
  int tc;
  // cin>>tc;
  tc = 1;
  while(tc--)
  {
    solve();
  }
}


Measured memory_bytes: 3740
#include <iostream>
// #include <vector>
// #include <algorithm>
// #include <string>
// #include <set>
// #include <cmath>
// #include <map>
// #include <iomanip>

#define MOD 1000000007

using namespace std;
typedef unsigned long long ull;
// typedef long long ll;

// void p() {
//     cout << "\n";
// }
// template<class Head, class... Body>
// void p(Head head, Body... body) {
//     cout << head << ",";
//     p(body...);
// }


int main(int argc, char const *argv[]) {
    ull X, Y;
    cin >> X >> Y;
    ull diff = (X > Y) ? X - Y : Y - X;
    if (diff <= 1) {
        cout << "Brown" << endl;
    } else {
        cout << "Alice" << endl;        
    }
    return 0;
}


Measured memory_bytes: 384
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        String S = sc.next();
        char[]text = new char[S.length()];
        for(int i=0;i<S.length();i++){
            text[i]=S.charAt(i);
        }
        for(int j=0;j<S.length();j++){
            for(int k=0;k<N;k++){
                if(text[j] =='Z'){
                    text[j]='A';
                }else {
                    text[j]++;
                }
            }
        }
        for (char s : text) {
            System.out.print(s);
        }
    }
}

Measured memory_bytes: 39592
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;

int main() {
  int a, b;
  cin >> a >> b;
  if(a+b<10){
    cout << a + b << endl;
  } else {
    cout << "error" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
	int ans = 0;
	int N;

	cin >> N;

	for (int i = 0; i < N; i++) {
		int tmp;
		cin >> tmp;
		while (tmp > 1 && tmp % 2 == 0) {
			ans++;
			tmp /= 2;
		}
	}

	cout << ans << endl;

	return 0;
}

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

typedef struct t_verdict{
	int			AC;
	int			WA;
}			t_verdict;

int		main()
{
	t_verdict	*problems;
	int		N, M, p, i;
	int		answers;
	int		penalties;
	char	s1, s2;

	i = 0;
	answers = 0;
	penalties = 0;
	scanf("%d %d\n", &N, &M);
	problems = (t_verdict *)malloc(sizeof(t_verdict) * (N + 2));
	while (i < M)
	{
		scanf("%d %c%c\n", &p, &s1, &s2);
		if (problems[p].AC == 0)
		{
			if (s1 == 'A')
			{
				answers++;
				problems[p].AC++;
			}
			else if (s1 == 'W')
				problems[p].WA++;
		}
		i++;
	}
	i = 1;
	while (i <= N)
	{
		if (M && problems[i].AC > 0)
			penalties += problems[i].WA;
		i++;
	}
	printf("%d %d\n", answers, penalties);
	return (0);
}


Measured memory_bytes: 896
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long int ll;

int main() {
	ll N;
	cin >> N;
	vector<ll> A(N);
	for (int i = 0; i < N; ++i) cin >> A[i];

	vector<ll> sm(N);
	sm[0] = A[0];
	for (int i = 1; i < N; ++i) sm[i] = sm[i - 1] + A[i];
	sort(sm.begin(), sm.end());

	ll ans = 0;
	ll conti = 1;
	ll val = sm[0];
	for (int i = 1; i < N; ++i) {
		if (sm[i] == val) {
			++conti;
		}
		else {
			if (val == 0) ans += conti;
			ans += conti * (conti - 1) / 2;
			conti = 1;
			val = sm[i];
		}
	}
	ans += conti * (conti - 1) / 2;
	if (val == 0) ans += conti;

	cout << ans << endl;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
using namespace std;
int main(){
    string n;
    cin>>n;
    int s=n.size();
    int c[s];
    for(int i=0;i<s;i++){
        n[i]-='0';
        c[i]=9-n[i];
    }
    c[s-1]++;
    int dp[s+1][2];
    dp[0][0]=0;
    dp[0][1]=1;
    for(int i=0;i<s;i++){
        dp[i+1][0]=min(dp[i][0]+n[i],dp[i][1]+c[i]+1);
        dp[i+1][1]=min(dp[i][0]+n[i]+1,dp[i][1]+c[i]);
    }
    cout<<min(dp[s][0],dp[s][1])<<endl;
    return 0;
}

Measured memory_bytes: 16024
#include<cstdio>
#include<vector>
#include<queue>
using namespace std;
const int INF = 1000000000;
typedef pair<int, int> P;

int w, h, s[30][30], c[4];
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int ndir[4] = {2, 3, 0, 1};

int getNum(int y, int x, int dir) { // dir: 0=right, 1=down, 2=left, 3=up
  return (y * w + x) * 4 + dir;
}

int V;
struct edge { int to, cost; };
vector<edge> G[3601];
int d[3601];

int dijkstra() {
  for (int i = 0; i < V; i++) d[i] = INF;
  d[0] = 0;
  priority_queue<P> que;
  que.push(P(0, 0));
  while (!que.empty()) {
    P p = que.top(); que.pop();
    int num = p.second;
    if (d[num] < p.first) continue;
    for (int i = 0; i < G[num].size(); i++) {
      edge e = G[num][i];
      int to = e.to, cost = e.cost;
      if (d[to] > d[num] + cost) {
        d[to] = d[num] + cost;
        que.push(P(d[to], to));
      }
    }
  }
  int ans = INF;
  for (int i = 0; i < 4; i++) ans = min(ans, d[getNum(h - 1, w - 1, i)]);
  return ans;
}

int main() {
  while (1) {
    scanf("%d%d", &w, &h);
    if (w == 0) break;
    V = w * h * 4;
    for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) scanf("%d", &s[i][j]);
    for (int i = 0; i < 4; i++) scanf("%d", &c[i]);
    for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) {
      for (int k = 0; k < 4; k++) for (int r = 0; r < 4; r++) {
        int dir = (k + r) % 4;
        int ny = i + dy[dir], nx = j + dx[dir];
        if (ny < 0 || nx < 0 || ny >= h || nx >= w) continue;
        int cost = c[r];
        if (s[i][j] == r) cost = 0;
        edge e; e.cost = cost; e.to = getNum(ny, nx, dir);
        G[getNum(i, j, k)].push_back(e);
      }
    }
    printf("%d\n", dijkstra());
    for (int i = 0; i < w * h * 4; i++) G[i].clear();
  }
}



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

using namespace std;

int main() {
  int n, t;
  scanf("%d%d", &n, &t);
  int t0 = 0, t1;
  long long int ans = 0;
  for (int i = 0; i < n; i++) {
    scanf("%d", &t1);
    if (i) {
      if (t0 < t1) {
        ans += t;
      } else {
        ans += t - (t0 - t1);
      }
    }
    t0 = t1 + t;
  }
  ans += t;
  printf("%lld\n", ans);
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<math.h>
#define LEN 100005
#define MAX 100005


void initialize();
int isEmpty();
int isFull();

typedef struct pp{
	char name[100];
	int t;
}P;

P  Q[LEN+1];
int head,tail,n;

void enqueue(P x){
	if(isFull()==0){
		fprintf(stderr,"error:full\n");
	}
	Q[tail]=x;
	
	if(tail+1==MAX){
		tail=0;
	}
	else{
		tail++;
	}
}

P dequeue(){
	P x;
	
	if(isEmpty()==0){
		fprintf(stderr,"error;empty\n");
	}
	x=Q[head];
	
	if(head+1==MAX){
		head=0;
	}
	else{
		head++;
	}
	return x;
}

int main(void){
	int elaps=0,c;
	int i,q,count=0;
	P u;
	
	scanf("%d %d",&n,&q);
	
	for(i=1;i<=n;i++){
		scanf("%s",Q[i].name);
		scanf("%d",&Q[i].t);
	}
	head=1;
	tail=n+1;
	while(head!=tail){
		u=dequeue();
		if(q<u.t){
		    c=q;
		}
		else{
		    c=u.t;
		}
		u.t-=c;
		elaps+=c;
		if(u.t>0){
			enqueue(u);
		}
		else{
			printf("%s %d\n",u.name,elaps);
			count++;
		}
	}
	
	return 0;
}

void initialize(){
	head=tail=0;
}

int isEmpty(){
	if(head==tail){
		return 0;
	}
	else{
		return 1;
	}
}

int isFull(){
	if(head==(tail+1)%MAX){
		return 0;
	}
	else{
		return 1;
	}
}



Measured memory_bytes: 11836
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int N; cin>>N;
    int ans=0;
    REP(i,N){
        int l,r; cin>>l>>r;
        ans+=r-l+1;
    }
    cout<<ans<<endl;
 
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

const long long mod = 1000000007;
const long long inf = 1e18;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n;
    cin>>n;
    int a[2][n];
    for(int i=0;i<2;i++){
        for(int j=0;j<n;j++){
            cin>>a[i][j];
        }
    }
    int ans=0;
    for(int i=0;i<n;i++){
        int count=0;
        for(int j=0;j<=i;j++){
            count+=a[0][j];
        }
        for(int j=i;j<n;j++){
            count+=a[1][j];
        }
        ans=max(count,ans);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3660
#include<stdio.h>
#include<ctype.h>
int main(){
    char a;                             
    while(1){
        scanf("%c",&a);
        if(islower(a)){
            a=toupper(a);              
        }else if(isupper(a)){
            a=tolower(a);
       }
        printf("%c",a);
        if(a == '\n'){                    
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 1812
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define lb lower_bound
#define maxn 100005
#define lowbit(x) (x)&(-x)
#define forup(i,a,b) for(int i=(a);i<=(b);i++)
#define fordown(i,a,b) for(int i=(a);i>=(b);i--)
#define int long long
typedef long long  ll;
typedef unsigned long long ull;
template<class T> inline
void read(T &num)
{num=0; bool f=true; char ch=getchar();
 while(ch<'0'||ch>'9') {if(ch=='-')  f=false;  ch=getchar();}
 while(ch>='0'&&ch<='9') {num=num*10+ch-'0';ch=getchar();}
 num=f?num:-num;
}
int out[100];
template<class T> inline
void  write(T x,char ch)
{if(x==0) {putchar('0');putchar(ch);return;}
 if(x<0) {putchar('-'); x=-x;}
 int num=0;
 while(x){out[num++]=(x%10);x=x/10;}
 fordown(i,num-1,0) putchar(out[i]+'0');
 putchar(ch);
}
string s;
int n;
struct P
{string A,B;
 bool operator <(const P &y) const
  {if(A<y.A) return 1;
   if(A==y.A) return B<y.B; 
  } 
};
map<unsigned long long,ll> mp;
int ans=0ll; 
int a[20];

unsigned long long H(const string &s){
  unsigned long long res=0;
  for(int i=0;i<s.size();++i)res=(res+s[i])*233ll;
  return res;
}

void dfs1(int x)
{if(x>n) 
{string A="",B="";
 forup(i,1,n) if(a[i]==1){A=A+s[i-1];}else B=s[i-1]+B;
 //A=A+'*'+B;
 //P tmp; tmp.A=A;tmp.B=B;
 //mp[tmp]++; 
 mp[H(A+'*'+B)]++;
 return;
}
 a[x]=0;
 dfs1(x+1);
 a[x]=1; 
 dfs1(x+1); 
}
void dfs2(int x)
{if(x>n)
 {string A="",B="";
  forup(i,1,n) if(a[i]==1) A=A+s[n+i-1]; else B=s[n+i-1]+B; 
  //P tmp; tmp.A=B;tmp.B=A; 
  ans+=mp[H(B+'*'+A)];	
  return;
 }
  a[x]=0;
  dfs2(x+1);
  a[x]=1;
  dfs2(x+1);	
}
signed main()
{ cin>>n;
  cin>>s;
  dfs1(1);
  
  dfs2(1);	
  cout<<ans<<endl;
return 0;
 } 


Measured memory_bytes: 33024
s = input("")
L = s.split(" ")
a,b,c,k = int(L[0]),int(L[1]),int(L[2]),int(L[3])
if (k<=a):
	print (k)
elif (a<k and k<=(a+b)):
	print (a)
elif ((a+b)<k and k<=(a+b+c)):
	print (a-(k-(a+b)))


Measured memory_bytes: 9060
#include<iostream>
#include<string>
#include<vector>

using namespace std;

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

  int c[n];
  int alg[n][m]={0};

  for(int i=0;i<n;i++){
    cin >> c[i];
    for(int j=0; j<m ; j++){
      cin >> alg[i][j];
    }
  }

  int cost =100000000;
  for( int i=0;i<(1<<n);i++){
    int now_cost = 0;
    int rikai[m] = {0};
    for (int j=0;j<n;j++){
      if (i>>j&1){
        now_cost+=c[j];
        for (int k=0;k<m;k++){
          rikai[k]+=alg[j][k];
        }
      }
      bool check = true;
      for (int j=0;j<m;j++) if (rikai[j]<x) check=false;
      if (check) cost = min(cost,now_cost);
    }

  }
  if (cost ==100000000) cout << -1 << endl;
  else cout << cost << endl;

  return 0;
}

Measured memory_bytes: 3640
from collections import defaultdict

def getlist():
	return list(map(int, input().split()))
D = defaultdict(int)
V = []

N, K = getlist()
for i in range(N):
	t, d = getlist()
	V.append([d, t])

V = sorted(V)

ans = []
ex = []
k = 0
for i in range(N):
	x = V[-1 - i][1]
	if k < K:
		if D[x] == 0:
			ans.append(V[-1 - i])
			D[x] += 1
			k += 1
		else:
			ex.append(V[-1 - i])
	else:
		ex.append(V[-1 - i])


if k < K:
	for i in range(K - k):
		ans.append(ex[i])
	eex = []
	for i in range(K - k, len(ex)):
		eex.append(ex[i])
else:
	eex = ex
ans = sorted(ans)
eex = sorted(eex)


A = 0
for i in range(K):
	A += ans[i][0]
A += k * k
n = min(k, N - K)
for i in range(n):
	if ans[i][0] + ((k - i) ** 2) - ((k - i - 1) ** 2) < eex[-1 - i][0]:
		A += eex[-1 - i][0] - ans[i][0] - ((k - i) ** 2) + ((k - i - 1) ** 2)
	else:
		break

print(A)

Measured memory_bytes: 26540
#include <iostream>

int main(void) {
    int N, A;
    int counter = 0;
    
    std::cin >> N;
    
    /*
     N is divisible by A = 1,...,N.
     for each A, B = 1,...,[N/A]
     But if N%A=0, C=0. So [N/A]-1 patterns.
     Thus, result is [N/1]+[N/2]+...[N/3]
     But if N%
    */
    
    for(A = 1; A < N; A++) {
        counter += N/A;
        if(N%A==0) {
            counter -= 1;
        }
    }
    
    std::cout << counter << std::endl;
    
    return 0;
}

Measured memory_bytes: 3612
#include <cstdio>
#define maxn 10000
#define NIL -1

struct Node{
    int p,l,r;
}T[maxn];

int n;

void preorder(int u){
    if(u==NIL) return;
    printf(" %d",u);
    preorder(T[u].l);
    preorder(T[u].r);
}


void inorder(int u){
    if(u==NIL) return;
    inorder(T[u].l);
    printf(" %d",u);
    inorder(T[u].r);
}


void postorder(int u){
    if(u==NIL) return;
    postorder(T[u].l);
    postorder(T[u].r);
    printf(" %d",u);
}


int main(){
   // freopen("data.in","r",stdin);
    int v,l,r,root;

    scanf("%d",&n);
    for(int i=0;i<n;i++) T[i].p=NIL;

    for(int i=0;i<n;i++){
        scanf("%d %d %d",&v,&l,&r);
        T[v].l=l;
        T[v].r=r;
        if(l!=NIL) T[l].p=v;
        if(r!=NIL) T[r].p=v;
    }


    for(int i=0;i<n;i++) if(T[i].p==NIL) root=i;

    printf("Preorder\n");
    preorder(root);
    printf("\n");
    printf("Inorder\n");
    inorder(root);
    printf("\n");
    printf("Postorder\n");
    postorder(root);
    printf("\n");
    return 0;
}

Measured memory_bytes: 2716
import numpy as np

N, L = map(int, input().split())
taste = [L + i for i in range(N)]
remove = np.argmin(np.abs(taste))
taste_sum = 0
for i in range(N):
    if i == remove:
        continue
    else:
        taste_sum += taste[i]
print(taste_sum)

Measured memory_bytes: 26892
//(・ω・)
#include <stdio.h>
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, atoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <iomanip> //setprecision
#include <limits>
#include <sstream> //istringstream
#include <stdlib.h>
#include <list>
#include <iterator>//std::advance()
using namespace std;

int main(){
   long long x;
   cin >> x;
   bool s=0;
   for(int i=-118; i<120; i++){
      for(int j=-119; j<i; j++){
         long long a=i,b=j;
         if(a*a*a*a*a-b*b*b*b*b==x){
            cout << a << " " << b << endl;
            s=1;
            break;
         }
      }
      if(s) break;
   }
   
}

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

typedef long long LL;
const int Maxn = 111111;
class Perm {
	public:
		int n, a[Maxn];

		void init(const int &size) {
			n = size;
			for (int i = 1; i <= n; ++i){
				a[i] = i;
			}
		}
		friend Perm operator*(const Perm &a, const Perm &b) {
			Perm ret;
			ret.n = a.n;
			for (int i = 1; i <= ret.n; ++i) {
				ret.a[i] = b.a[a.a[i]];
			}
			return ret;
		}
		friend Perm operator^(Perm base, LL k) {
			Perm ret;
			for (ret.init(base.n); k; k >>= 1, base = base*base) {
				if (k&1) {
					ret = base*ret;
				}
			}
			return ret;
		}
} base, p;

int n, d[Maxn], m;
LL k;

int main() {
	scanf("%d", &n);
	int firstpos;
	scanf("%d", &firstpos);
	for (int i = 2, x, last = firstpos; i <= n; ++i) {
		scanf("%d", &x);
		d[i] = x-last, last = x;
	}
	base.init(n), p.init(n);
	scanf("%d%lld", &m, &k);
	for (int a; m--; ) {
		scanf("%d", &a);
		swap(base.a[a], base.a[a+1]);
	}
	p = base^k;
	LL curans = firstpos;
	printf("%lld\n", curans);
	for (int i = 2; i <= n; ++i) {
		curans += d[p.a[i]];
		printf("%lld\n", curans);
	}
	return 0;
}

Measured memory_bytes: 4096
#include<bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define rep(i, x) for(ll i = 0; i < x; i++)
#define rep2(i, x) for(ll i = 1; i <= x; i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
const ll INF = 1000000000000000000;
const ll mod = 1000000007;
const ld pi = 3.141592653589793238;

char maze[2134][2134];
ll d[1234][1234], dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 };
signed main() {
	ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	
	ll n, m; cin >> n >> m;
	typedef pair<ll, ll>P;
	rep2(i, n) {
		rep2(j, m) {
			cin >> maze[i][j];
		}
	}
	queue<P> que;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			d[i][j] = INF;
		}
	}
	rep2(i, n) {
		rep2(j, m) {
			if (maze[i][j] == '#') { que.push(P(i, j)); d[i][j] = 0; }
		}
	}
	ll ans = 0;
	while (que.size()) {
		P p = que.front(); que.pop();
		for (int i = 0; i < 4; i++) {
			int nx = p.first + dx[i], ny = p.second + dy[i];
			if (0 < nx && nx <= n && 0 < ny && ny <= m && maze[nx][ny] != '#' && d[nx][ny] == INF) {
				que.push(P(nx, ny));
				ll cnt = d[p.first][p.second] + 1;
				d[nx][ny] = cnt; ans = max(ans, cnt);
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 31152
#include<stdio.h>
#define free 0
#define notfree 1
#define N 8

void putqueen(int);
void printboard(void);

int row[N];//盤面の行
int col[N];//盤面の列
int dpos[15];//右上から左下
int dneg[15];//左上から右下
int A[N][N];

int main(){
  int k;
  scanf("%d",&k);
  int i;
  int r,c;//rはチェス盤の行、cは列を表している
  for(i=0;i<k;i++){
    scanf("%d%d",&r,&c);
    A[r][c]=notfree;
  }
  putqueen(0);
  
  return 0;
}

void putqueen(int i){
  int j;
  
  if(i==N){
    printboard();
    return;
  }
  
  for(j=0;j<N;j++){
    if(col[j]==notfree||dpos[i+j]==notfree||dneg[i-j+N-1]==notfree)
      continue;
    
    row[i]=j;
    col[j]=dpos[i+j]=dneg[i-j+N-1]=notfree;
    
    putqueen(i+1);
    
    row[i]=col[j]=dpos[i+j]=dneg[i-j+N-1]=free;
  }
  
}

void printboard(){
  int i,j;
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(A[i][j]==1){
	if(row[i]!=j)
	  return;
      }
    }
  }

  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(row[i]==j)
	printf("Q");
      else printf(".");
    }
    printf("\n");
  }
}



Measured memory_bytes: 2104
l,r = gets.chomp.split(' ').map(&:to_i)
if r - l >= 673
  puts 0
else
  min = 2019
  arr = (l..r).to_a
  i = 0
  while i < arr.size - 1
    j = i + 1
    while j < arr.size
      prod = ((arr[i] % 2019) * (arr[j] % 2019)) % 2019
      if prod < min
        min = prod
      end
      j += 1
    end
    i += 1
  end
  puts min
end

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

const int N = 1e5+7;

vector < vector <int> >v;

vector < vector <int> >ans;

int main() {
	int n, k , i , j , l;
	cin >> k >> n;
	v.resize(n);
	ans.resize(n);
	int cnt[N+1] = {0};
	for(i=0;i<n;++i) {
	    cin >> j >> l;
	    v[i] = {j , l , i};
	}
	
	sort(v.begin() , v.end() , [&](vector <int> &a , vector <int> &b) {
	    if(a[0] == b[0]) return a[1] < b[1];
	    return a[0] < b[0];
	});
	
	for(auto x:v) {
	    ans[x[2]] = {x[0] , ++cnt[x[0]]};
	}
	for(auto x:ans) {
	    cout << setfill('0') << setw(6) << x[0] << setfill('0') << setw(6) << x[1];
	    cout << endl;
	}
	return 0;
}

Measured memory_bytes: 13696
<?php

    // AtCoder Beginner Contest 164
    // A - Sheep and Wolves

    list($s, $w) = in_ints();
    if ($s <= $w) {
        out('unsafe');
    } else {
        out('safe');
    }
    

    // -----------------------------------------------------
    function in() { return trim(fgets(STDIN)); }
    function in_int() { return (int)in(); }
    function in_vals() { return explode(' ', in()); }
    function in_ints() { return array_map('intval', in_vals()); }
    function out($s) { echo $s . PHP_EOL; }
    function yes() { out('Yes'); }
    function no() { out('No'); }


Measured memory_bytes: 16120
s = input()
n = len(s)
for i in range(n-1):
    if s[i] == s[i+1]:
        print(i+1,i+2)
        break
    if i != n-2:
        if s[i] == s[i+2] or s[i+1] == s[i+2]:
            print(i+1,i+3)
            break
    if i == n-2:
        print(-1,-1)

Measured memory_bytes: 3188
/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/
 
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x
 
using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<int, II> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;
 
const ll MODBASE = 1000000007LL;
const int MAXN = 300010;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

int n;
ll a[MAXN];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n;
    FOR(i,1,n) cin >> a[i];
    ll res = 0;
    FOR(j,0,59) {
        ll cnt1 = 0, cnt0 = 0;
        FOR(i,1,n)
            if (a[i] & (1LL << j)) cnt1++;
            else cnt0++;
        ll cnt = cnt1 * cnt0 % MODBASE;
        ll p = (1LL << j) % MODBASE;
        res = (res + cnt * p % MODBASE) % MODBASE;
    }
    cout << res;
    return 0;
}


Measured memory_bytes: 2560
// abc.058 C - Dubious Document

// Sn（すべて）の中の文字を用いて、文字列を作る。複数できる場合は辞書順で最小のもの

#include <bits/stdc++.h>
using namespace std;

int main( void ) {

    int n;
    cin >> n;
    vector<int> res( 26, 55 );

    for( int i = 0; i < n; i++ ) {
        string s;
        cin >> s;

        vector<int> AB( 26, 0 );

        for( int j = 0; j < s.length(); j++ ) {
            char c = s.at( j );
            AB.at( c - 'a' )++;
        }
        // ABとresの少ない方を保存する
        for( int j = 0; j < 26; j++ ) {
            res.at( j ) = min( AB.at( j ), res.at( j ) );
        }
    }

    string ans;

    for( int i = 0; i < 26; i++ ){
        ans +=string(res.at(i), i + 'a');
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import numpy as np
from scipy.sparse.csgraph import floyd_warshall

h,w=map(int,input().split())
c=np.array([list(map(int,input().split())) for _ in range(10)])
cost=floyd_warshall(c)

ans=0
for _ in range(h):
    inp=map(int,input().split())
    for a in inp:
        if a==-1:
            continue
        ans+=int(cost[a][1])

print(ans)

Measured memory_bytes: 17976
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using TP = tuple<ll,ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(18);
}
signed main(){
  init_io();
  ll x,n;
  cin >> x >> n;
  vector<ll> p(n);
  set<ll> st;
  for(int i=0;i<n;i++){
    cin >> p[i];
    st.insert(p[i]);
  }
  for(int dis=0;;dis++){
    ll v = x-dis;
    if(st.find(v)==st.end()){
      cout << v << endl;
      break;
    }
    v = x + dis;
    if(st.find(v)==st.end()){
      cout << v << endl;
      break;
    }
  }
}


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

// #define ANS  //for answer
#define CMP  //for compe

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
#define nv(x) #x,(x)
#define ncv(x) #x,":",(x)
#define ncvc(x) #x,":",(x),","
using ll = long long;
void pPRINT(std::ostream& ost) {}
template <class T, class... U>void pPRINT(std::ostream& ost,const T t,const U... u) {ost<<t<<" ";pPRINT(ost, u...);}
template <class... T>void PRINT(const T... t) {pPRINT(std::cout, t...);}
template <class... T>void PRINTl(const T... t){pPRINT(std::cout,t...);std::cout<<"\n";}
template <class T>void PRINTa(const T* const t,const ll size){REP(i,size)PRINT(t[i]);PRINTl();}
template <class T>void PRINTal(const T* const t,const ll size){REP(i,size)PRINTl(i,":",t[i]);}
#ifdef ANS
#define DEBUG(...)
#else
#define DEBUG(...) PRINTl("##DEBUG##","file :",__FILE__,", line :",__LINE__,"\n##DEBUG##",__VA_ARGS__)
#endif
#ifdef CMP
using namespace std;
#else
#endif

int main(int argc, char *argv[]) {

  ll n,k;
  cin>>n>>k;
  string s;
  cin>>s;
  auto c = s[k-1];
  s[k-1] = c-('Z'-'z');
  PRINT(s);

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include <set>
typedef long long ll;
using namespace std;
int a[1000005],maxx=-1,minn=1e9,mid;
double midd;
ll sum,sum1;
int main()
{
	ll n;
	int b;
	cin>>n;
	for(int i=1;i<=n;i++)
	{cin>>a[i];
	a[i]=a[i]-i;
	//cout<<a[i]<<" ";
	sum+=a[i];
	}
	sort(a+1,a+1+n);
	if(n&1) mid=a[(n+1)/2];
	else 
	{midd=a[n/2]+a[n/2+1]; 
	if(midd>0)
	mid=(int)(midd/2+0.5);
	else
	mid=(int)(midd/2-0.5); 
	}
	for(int i=1;i<=n;i++)
	sum1+=abs(a[i]-mid);
	cout<<sum1;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>
#include <math.h> 
#include <stack>
#include <queue>
#include <bitset>

using namespace std;

int main() {
	int i, j, k;
	int n;
	string s;

	cin >> n >> s;


	int cnt1, cnt2 = 0;
	for (i = 0; i < s.length(); i++) {
		cnt1 = 0;
		string st1, st2;
		for (j = 0; j <= i; j++) {
			st1.push_back(s[j]);

		}
		for (k = j; k < s.length(); k++) {
			if (st2.find(s[k]) == string::npos) {
				st2.push_back(s[k]);
			}
			

		}

		for (int m = 0; m < st2.length(); m++) {
			if (st1.find(st2[m]) != string::npos) {
				cnt1++;
			}
		}
		if (cnt1 > cnt2)cnt2 = cnt1;
	}

	cout << cnt2 << endl;










	getchar();
	getchar();
	return 0;
}

Measured memory_bytes: 256
/* vo0_02.cpp */
#include <iostream>
using namespace std;

int main()
{
	int a, b, c;
	int count;

	while (true) {

		cin >> a >> b;
		if (cin.eof()) break;

		c = a + b;
		
		count = 1;
		for (; c >= 10; c /= 10) count++;

		cout << count << '\n';
	}

	return 0;
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  vector<int> V(N);
  for (int i = 0; i < N; i++) {
    cin >> V[i];
  }

  vector<map<int, int>> cnt(2);
  for (int i = 0; i < N; i++) {
    cnt[i & 1][V[i]]++;
  }

  vector<vector<pair<int, int>>> cand(2);
  for (int i = 0; i < 2; i++) {
    for (auto itr = cnt[i].begin(); itr != cnt[i].end(); itr++) {
      cand[i].emplace_back(make_pair(itr->second, itr->first));
    }
    sort(cand[i].begin(), cand[i].end(),
         [](pair<int, int> a, pair<int, int> b) { return a.first > b.first; });
  }

  int i = 0, j = 0;
  if (cand[0][i].second == cand[1][j].second) {
    if (cand[0][i].first > cand[1][j].first) {
      j++;
    } else if (cand[0][i].first < cand[1][j].first) {
      i++;
    } else {
      if (cand[0][i + 1].first > cand[1][j + 1].first) {
        i++;
      } else {
        j++;
      }
    }
  }
  cout << N - cand[0][i].first - cand[1][j].first << '\n';
  return 0;
}


Measured memory_bytes: 6524
#include <iostream>
#include <string.h>
#include <queue>

using namespace std;
typedef pair<int, int> P;
int dx[] = {-1, -1,  0, 0, 1, 1};
int dy[] = {-1,  0, -1, 1, 0, 1};
bool Field[1000][1000];

void solve()
{
	int t, n;
	while(cin >> t >> n, t || n)
	{
		memset(Field, 0, sizeof(Field));
		for(int i = 0; i < n; ++i)
		{
			int x ,y;
			cin >> x >> y;
			Field[y + 500][x + 500] = true;
		}
		int count = 1;
		P p;
		cin >> p.first >> p.second;
		p.first += 500;
		p.second += 500;
		queue<P> Que;
		Que.push(p);
		Field[p.second][p.first] = true;
		queue<P> NextQue;
		for(int a = 0; a < t; ++a)
		{
			while(!Que.empty())
			{
				P p1 = Que.front();
				Que.pop();
				for(int i = 0; i < 6; ++i)
				{
					P next;
					next.first = p1.first + dx[i];
					next.second = p1.second + dy[i];
					if(Field[next.second][next.first] == false)
					{
						Field[next.second][next.first] = true;
						NextQue.push(next);
						count++;
					}
				}
			}
			while(!NextQue.empty())
			{
				Que.push(NextQue.front());
				NextQue.pop();
			}
		}
		cout << count << endl;
	}
}

int main()
{
	solve();
	return(0);
}

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

int a,b,c;

int main(void){
    cin>>a>>b>>c;
    int M=max({a,b,c});
    int r;
    r=(M-a)/2+(M-b)/2+(M-c)/2;
    int p=(M-a)%2+(M-b)%2+(M-c)%2;
    if(p==1)r+=2;
    if(p==2)r+=1;
    cout<<r<<endl;
}


Measured memory_bytes: 256
a = list(input())
b = list(input())
ans = []
if len(a) == len(b):
    for i in range(len(a)):
        ans.append(a[i])
        ans.append(b[i])
elif len(a) > len(b):
    for i in range(len(b)):
        ans.append(a[i])
        ans.append(b[i])
    ans.append(a[-1])

print(''.join(ans))        

Measured memory_bytes: 3064
def distance_to_right(p, point_list):
    if p == len(point_list) - 1:
        return None
    else:
        return point_list[p+1] - point_list[p]


# main

num_koma, num_to_visit = [int(element) for element in input().split(' ')]
points = [int(element) for element in input().split(' ')]

points.sort()

costs = [distance_to_right(p, points) for p in range(0, num_to_visit-1)]
costs.sort()

if num_koma == 1:
    print(sum(costs))
else:
    print(sum(costs[:-(num_koma-1)]))


Measured memory_bytes: 13832
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF (1<<29)
#define LINF (1LL<<60)
#define EPS (1e-10)
#define PI 3.1415926535897932384626433832795028
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define max_heap priority_queue<int>
#define min_heap priority_queue<int,vector<int>,greater<int>>
using ll = long long;
#define int long long
#define endl "\n"
#define vi vector<int>
#define pb push_back
#define inp_arr(a,n) for(ll i=0;i<n;i++)cin>>a[i];
#define out_arr(a) for(ll i=0;i<a.size();i++)cout<<a[i]<<" ";
#define deb(n) cerr << #n << " = " << n << "\n";
int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a);}
ll mypower(ll x,ll n,ll c){
    if(n == 0)
        return 1;
    ll temp = mypower(x,n/2,c)%c;
    if(n%2)
        return (n<0)? (1/x)*temp*temp%c: ((x*temp)%c)*temp%c;
    else
        return temp*temp%c;
}
bool codejam = 0;

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif

	ll n;
	cin>>n;
	n>=30? cout<<"Yes":cout<<"No";
	cout<<endl;
	return 0;
}


Measured memory_bytes: 3636
#include<stdio.h>
int heaps[500001],H;
int maxHeapify(int);
int main(void)
{
    int i;
    scanf("%d",&H);
    for(i=1;i<=H;i++)   scanf("%d",&heaps[i]);
    for(i=H/2;i>=1;i--) maxHeapify(i);
    for(i=1;i<=H;i++)   printf(" %d",heaps[i]);
    printf("\n");
    return 0;
}
int maxHeapify(int num)
{
    int max,tmp;
    if(num*2<=H&&heaps[num]<heaps[num*2]) max=num*2;
    else                        max=num;
    if(num*2+1<=H){
        if(heaps[max]<heaps[num*2+1]) max=num*2+1;
    }
    if(max!=num){
        tmp=heaps[num];
        heaps[num]=heaps[max];
        heaps[max]=tmp;
        maxHeapify(max);
    }
    return 0;
}

Measured memory_bytes: 2552
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define inf 1000000000
#define pb push_back
#define mp make_pair
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define yoi cout<<"yo"<<endl;
#define debug(x) cerr << #x << " is " << x << endl;
#define all(x) x.begin(),x.end()
const int mod=1e9+7;
int main(){
IOS;
lli k,x,i;
cin>>k>>x;
for(i=x-k+1;i<x+k;i++){
    cout<<i<<" ";
}
cout<<endl;
}


Measured memory_bytes: 256
N, A, B = gets.split.map(&:to_i)
@h = N.times.map { gets.to_i }

def enough?(n)
  @h.map do |i|
    t = i - (B * n)
    if t <= 0
      0
    else
      (t / (A - B).to_f).ceil
    end
  end.inject(:+) <= n
end

p (1..(10**9)).bsearch { |i| enough?(i) }


Measured memory_bytes: 26548
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using P = pair<int, int>;
vector<string> divide = {"dream", "dreamer", "erase", "eraser"};

int main(){
    string s;
    cin >> s;
    reverse(s.begin(), s.end());
    rep(i, divide.size()) reverse(divide.at(i).begin(),divide.at(i).end());

    string ans = "YES";
    for (int i = 0; i < s.size();) { //i=s.size()の時break
        if(s.substr(i, 5) == divide.at(0) || s.substr(i, 5) == divide.at(2)) i += 5;
        else if(s.substr(i, 6) == divide.at(3)) i += 6;
        else if(s.substr(i, 7) == divide.at(1)) i +=7;
        else{
            ans = "NO";
            break;
        }
    }
    cout << ans << endl;

    return 0;
}

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

using namespace std;

void funcA() {
  string s;
  cin >> s;

  if (s[s.size() - 1] == 's') {
    s += "es";
  }
  else s += 's';

  cout << s;
}

int main() {

  funcA();

  return 0;
}

Measured memory_bytes: 3628
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <cmath>
#include <deque>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define REP(e,v) for(auto e:v)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define mt make_tuple
#define pq priority_queue<ll>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vecpll vector<pll>
#define vecbl vector<bool>
#define endl "\n"
#define ALL(c) (c).begin(),(c).end()
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
string stin(){string s;cin>>s;return s;}

int main(){
    ll x=in();
    for(ll b=-200;b<=200;b++){
        for(ll a=b+1;a<=200;a++){
            if(pow(a,5)-pow(b,5)==x){
                cout<<a<<" "<<b<<endl;
                return 0;
            }
        }
    }
}

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

int main() {
	int n, c;
	set <string, greater<string>> item;
	string s;
	cin>>n;
	while (n--)
	{
	    cin>>s;
	    item.insert(s);
	    s.clear();
	}
	cout<<item.size();
	//cout<<"GfG!";
	return 0;
}

Measured memory_bytes: 19204
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iomanip>
#include <float.h>
#include <math.h>
using namespace std;
using ll = long long;


unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

int main() {
    string s;
    ll p = 2019;
    cin>> s;
    ll n = s.size();
    ll ans = 0;
    if (p == 2 || p==5) {
        for (int i = 0; i < n; i++) {
            if ((s[i] - '0') % p == 0)ans += i + 1;
        }
        cout << ans << endl;
    }
    else {
        ll now = 0;
        vector<ll> z(p);
        z[0]++;
        for (int i = n-1; i > -1; i--) {
            now = ((s[i] - '0')*modpow(10,n-1-i,p) + now);
            now %= p;
            z[now]++;
        }
        for (int i = 0; i < p; i++) {
            ans += z[i] * (z[i] - 1) / 2;
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 3732