akhauriyash/Code-Regression huggingface dataset:
<?php
while (true) {
    list($a, $operator, $b) = getSpacesByExplodeTrimInput();
    echo calc($a, $operator, $b), PHP_EOL;
}

function getSpacesByExplodeTrimInput()
{
    return explode(' ', trim(fgets(STDIN)));
}

function calc($a, $operator, $b)
{
    switch ($operator) {
        case '+':
            $result = addTwoNum($a, $b);
            break;
        case '-':
            $result = subTractTwoNum($a, $b);
            break;
        case '*':
            $result = multiplyTwoNum($a, $b);
            break;
        case '/':
            $result = divideTwoNumByFloorPoint($a, $b);
            break;
        case '?':
            exit;
    }
    
    return $result;
}

function addTwoNum($a, $b)
{
    return $a + $b;
}

function subTractTwoNum($a, $b)
{
    return $a - $b;
}
  
function multiplyTwoNum($a, $b)
{
    return $a * $b;
}

function divideTwoNumByFloorPoint($a, $b)
{
    return floor($a / $b);
}

Measured memory_bytes: 15364
# import sys
# import math #sqrt
# import decimal
# import queue # queue
# import bisect
# import heapq # priolity-queue
# import time
# from itertools import permutations #順列生成
# import collections # deque
# from operator import itemgetter
# from fractions import Fraction

mod = int(1e9+7)
INF = 1<<29
lINF = 1<<35

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

def main():
    n = int(input())
    k = int(input())
    ans = 1
    for i in range(n):
        ans = min(ans*2,ans+k)
    print(ans)
    return

if __name__=='__main__':
    main()

Measured memory_bytes: 3060
N, x = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
s = 0
ans = 0
for i in range(N):
    s += a[i]
    if s <= x and i < N - 1:
        ans += 1
    elif i == N - 1 and s == x:
        ans += 1
    else:
        break
print(ans)

Measured memory_bytes: 3064
/*input
5
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

const int MOD = 1e9 + 7;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n; cin >> n;
    if(n & 1) cout << 0;
    else
    {
    	ll cnt = 0;
    	for(ll i = 5; n/2/i > 0; i *= 5) cnt += n/2/i;
    	cout << cnt;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define INF 10000000
using ll = long long ;
ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}
template< int id > struct CompTupleBy
{
  template<class T> 
  bool operator()( const T& a, const T& b ) const {
    return std::get<id>(a) < std::get<id>(b);
  }
};

using namespace std;

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

    int n;
    cin >> n;

    map<int,int> mp;
    rep(i,n){
        int a;
        cin >> a;
        mp[a] += 1;
    }
    int ans = 0;
    for(auto& item : mp){
        if (item.first > item.second) ans += item.second;
        else if(item.first < item.second) ans += item.second-item.first;
    }
    cout << ans << endl;
}

Measured memory_bytes: 4736
#include<bits/stdc++.h>
using namespace std;
long long int t[101][1000001];

long long int ans(long long int v[],long long int w[],long long int wt,long long int n)
{
    if(n==0||wt==0)
    return 0;
    if(t[n][wt]!=-1)
    return t[n][wt];
    if(w[n-1]<=wt)
    return t[n][wt]=max((v[n-1]+ans(v,w,wt-w[n-1],n-1)),ans(v,w,wt,n-1));
    else
    return t[n][wt]=ans(v,w,wt,n-1);
}
int main()
{
   long long int n,wt,p;
    for(int i=0;i<101;i++)
{
    for(int j=0;j<1000001;j++)
    t[i][j]=-1;
}
    cin>>n>>wt;
      long long int v[n],w[n];
    for(int i=0;i<n;i++)
    cin>>w[i]>>v[i];
    p=ans(v,w,wt,n);
    cout<<p<<endl;
}

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

int main(){
  int n,alice=0,bob=0;
  cin >> n;
  vector<int> cards(n);
  for(int i=0;i<n;i++){
    cin >> cards.at(i);
  }
  sort(cards.begin(),cards.end());
  reverse(cards.begin(),cards.end());
  for(int i=0;i<n;i++){
    if(i%2==0)alice+=cards.at(i);
    else bob+=cards.at(i);
  }
  cout << alice - bob << endl;
}

Measured memory_bytes: 3508
#include <iostream>
#include <math.h>
#include <iomanip>
using namespace std;

int main(){
int A, B, C, K;
cin >> A >> B >> C >> K;

if(A >= K){
    cout << K <<endl;
}
else if (B >= K-A){
    cout << A <<endl;
}
else{
    cout << 2 * A - K +B <<endl;
}

return 0;
}

Measured memory_bytes: 3632
import numpy as np
from numba import jit

@jit
def solve():
    
    n = int(input())
    
    divisors = np.zeros(n+1, np.int64)
    
    for i in range(1, n+1):
        for j in range(i, n+1, i):
            divisors[j] += 1
    #print(divisors)
    
    ans = 0
    for k in range(n+1):
        ans += (k * divisors[k])
    
    print(ans)

solve()


Measured memory_bytes: 191336
n = int(input())
a_i = list(map(int, input().split()))
duplicationCheckList = [0] * 10 ** 5
duplicationMaisuu = 0
for x in a_i:
    if duplicationCheckList[x - 1] == 1: duplicationMaisuu += 1
    else: duplicationCheckList[x - 1] = 1
count = (duplicationMaisuu + 1) // 2
print(n - count * 2)

Measured memory_bytes: 14008
#include<iostream>
using namespace std;
int a[100];
int main(){
  for(int i=0;i<100;i++) a[i]=0;
  int k;
  cin>>k;
  int t=1;
  while(k--){
    for(int i=0;i<t;i++){
      if(i==t-1){
        if(a[i]==9){
          t++;
          a[i+1]=1;
          for(int j=i;j>=0;j--) a[j]=0;
        }
        else{
          a[i]++;
          for(int j=i-1;j>=0;j--){
          if(a[j+1]-1>=0) a[j]=a[j+1]-1;
          else a[j]=0;
        }
        }
        break;
      }
      else if(a[i]<=a[i+1]&&a[i]!=9){
        a[i]++;
        for(int j=i-1;j>=0;j--){
          if(a[j+1]-1>=0) a[j]=a[j+1]-1;
          else a[j]=0;
        }
        break;
      }
    }
  }
  for(int i=t-1;i>=0;i--){
    cout<<a[i];
  }
  cout<<endl;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
h, w = map(lambda x: int(x)+2, input().split())
MAZE = ['#'*w]
for _ in range(h-2):
    MAZE.append('#'+input()+'#')
else:
    MAZE.append('#'*w)

L = [[0]*w for _ in range(h)]
R = [[0]*w for _ in range(h)]
U = [[0]*w for _ in range(h)]
D = [[0]*w for _ in range(h)]

LAMP = [[0]*w for _ in range(h)]

for i in range(1, h-1):
    for j in range(1, w-1):
        if MAZE[i][j] == '.':
            L[i][j+1] = L[i][j]+1
        if MAZE[i][w-j] == '.':
            R[i][w-j-1] = R[i][w-j]+1

for j in range(1, w-1):
    for i in range(1, h-1):
        if MAZE[i][j] == '.':
            U[i+1][j] = U[i][j]+1
        if MAZE[h-i][j] == '.':
            D[h-i-1][j] = D[h-i][j]+1

ans = 0
for i in range(1, h-1):
    for j in range(1, w-1):
        if MAZE[i][j] == '#':
            continue
        LAMP[i][j] = L[i][j]+R[i][j]+U[i][j]+D[i][j]+1
        ans = max(ans, LAMP[i][j])

print(ans)

Measured memory_bytes: 209288
using System;

class test
{
    static void Main()
    {
        int top1 = 0, top2 = 0,top3 = 0;
        for (int i = 0; i < 10; i++)
        {
            int n = int.Parse(Console.ReadLine());
            if (top1 <= n)
            {
                top3 = top2;
                top2 = top1;
                top1 = n;
            }
            else if(top2 <= n)
            {
                top3 = top2;
                top2 = n;
            }
            else if(top3 <= n)
            {
                top3 = n;
            }
        }
        Console.WriteLine(top1);
        Console.WriteLine(top2);
        Console.WriteLine(top3);
    }
}

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

int main(){
    int n;
    cin>>n;
    vector<ll> x(n);
    rep(i,n){
        cin>>x[i];
    }
    vector<ll> y=x;
    sort(y.begin(),y.end());
    rep(i,n){
        if(x[i]>=y[n/2]) cout<<y[n/2-1]<<endl;
        else cout << y[n/2] <<endl;
    }
    
    return 0;
}



Measured memory_bytes: 5376
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include <cmath>
#include <limits>
#include<set>
#include <iomanip>
#include <queue>
#include <map>
#include <string>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
typedef double ld;
const long long INF=(1LL<<62);
const double inf=pow(10,10);
double pi=3.141592653589793;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};
const ll MOD = 1000000007;
void init(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
}
ll gcd(ll a,ll b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}

long long lcm(long long a,long long b){
	return a/gcd(a,b)*b;
}

map< int64_t, int > prime_factor(int64_t n) {
  map< int64_t, int > ret;
  for(int64_t i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if(n != 1) ret[n] = 1;
  return ret;
}

int main(){
	init();
	ll ans=1;
	ll N,P;cin>>N>>P;
	for(auto p : prime_factor(P)) {
   	 if(p.second>=N) ans*=pow(p.first,p.second/N);
 	}
 	cout<<ans<<endl;
}


Measured memory_bytes: 256
//om namah shivaay
//faith over fear
//no one wants to die,yet death is the destination we all share 
// don't think you are,know you are!!

#include<bits/stdc++.h>
using namespace std;
 
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define ll long long 
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i,n) for(i=0;i<n;i++)
#define forn(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i)
#define ford(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); ++i)
#define fora(it,x) for(auto it:x)
#define PI 3.14159265
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl "\n"
 
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef long double ld;
 
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

int main(){
    ll n;
    cin>>n;
    string s;
    cin>>s;
    ll f=0,l=n-1,ans=0;
    while(f<l){
        while((f<n)&&(s[f]!='W')) f++;
        if(f==n) break;
        while((l>=0)&&(s[l]!='R')) l--;
        if(l==-1) break;
        if(f<l){
            swap(s[f],s[l]);
            f++;
            l--;
            ans++;
        }
    }
    cout<<ans;
}

Measured memory_bytes: 3760
import math
def ccw(p1,p2,p3):
    return (p2[0]-p1[0])*(p3[1]-p2[1])-(p2[1]-p1[1])*(p3[0]-p2[0])
while True:
    n=input()
    if n==0:
        break
    p=[0]*n
    for i in xrange(n):
        p[i]=map(float,raw_input().strip().split(","))
    P=min(p,key=lambda a:(a[1],a[0]))
    p.sort(key=lambda x:math.atan2(x[1]-P[1],x[0]-P[0]))
    M=0
    ans=0
    while M<len(p)-1:
        if all([ccw(p[M-1],p[M],p[i])>=0 for i in xrange(M+1,len(p))]):
            M+=1
        else:
            ans+=1
            p.remove(p[M])
    print ans

Measured memory_bytes: 4492
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(
				new InputStreamReader(System.in));
		String str = br.readLine();
		if(str.indexOf("AC") !=-1){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 21332
#include <iostream>

using namespace std;

int a[31];
int func(int n)
{
	if(a[n] > 0){
		return a[n];
	}
	
	return a[n] = func(n-1)+func(n-2)+func(n-3);
}

int main()
{
	int n, s;
	a[0] = a[1] = 1;
	a[2] = 2;
	a[30] = func(30);
	
	while(cin>>n && n){
		s = 0;
		for(int i = 1; i <= n; i++){
			s += a[i];
		}
		
		cout << a[n]/3650+1 << endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
#include <vector>
#include <list>
#include <map>
#include <set>
#include "queue"
#include <deque>
#include <stack>
#include <numeric>
#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 <climits>
#include <cassert>
#include <iostream>
#include <cassert>
#include <unordered_map>
#include <regex>
#include <stdio.h>
#include <fstream>
using namespace std;
#define ll long long int
const int N = 200021;
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define mem(a,b) memset(a,b,sizeof(a))
#define getchar_unlocked getchar
//if ( a > b || a > j || b < i ) {
//return ( ( sum ) { 0, 0 } );
//if ( a >= i && b <= j ) {
//return tree[ node ]
//ll bin1(ll val){
//    //finding the smallest element equal to or larger than this val
//    ll lo=1,hi=n;
//    while(lo<=hi){
//        if(lo==hi)break;
//        if(lo+1==hi){
//            if(Q[lo].v==val)break;
//            else if(Q[lo].v<val){lo=hi; break;}
//            break;
//        }
//        ll mid=(lo+hi)>>2;
//        if(Q[mid].v<val){
//            lo=mid+1;
//        }
//        else{
//            hi=mid;
//        }
//    }
//    if(Q[lo].v<val)lo++;
//    return lo;
//}
//ll BIN(ll val){
//    //finding the largest element equal to or smaller than this val
//    ll lo=1,hi=n;
//    while(lo<=hi){
//        if(lo==hi)break;
//        if(lo+1==hi){
//            if(Q[lo].v==val)break;
//            else if(Q[lo].v>val){lo=hi; break;}
//            break;
//        }
//        ll mid=(lo+hi)>>2;
//        if(Q[mid].v>val){
//            hi=mid;
//        }
//        else{
//            lo=mid+1;
//        }
//    }
//    if(Q[lo].v>val)lo--;
//    return lo;
//}
inline int scan(){
    char c = getchar_unlocked();
    int x = 0;
    while(c<'0'||c>'9'){
        c=getchar_unlocked();
    }
    while(c>='0'&&c<='9'){
        x=(x<<1)+(x<<3)+c-'0';
        c=getchar_unlocked();
    }
    return x;
}
ll a[N];
int main(){
    ll n; cin >> n;
    n*=2;
    for(ll i=1;i<=n;i++)cin >> a[i];
    sort(a+1,a+n+1);
    ll ans =0;
    for(ll i=1;i<=n;i+=2){
        ans+=min(a[i],a[i+1]);
    }
    cout << ans <<endl;
    return 0;
}

Measured memory_bytes: 256
A,B,M=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))

ans=min(a)+min(b)

for i in range(M):
    x,y,c=map(int,input().split())
    ans=min(ans,a[x-1]+b[y-1]-c)
print(ans)

Measured memory_bytes: 18608
#include <bits/stdc++.h>
#define INF LLONG_MAX
#define ll  long long
#define ull unsigned long long
#define rep(i,n) for(int i=0; i<n; ++i)
#define MOD 1000000007
using namespace std;
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;}

int main() {
  int H, W;
  int c[10][10];
  cin >> H >> W;
  vector<vector<int>> A(H, vector<int>(W));
  rep(i,10) { rep(j,10) { cin >> c[i][j]; } }
  rep(h,H)  { rep(w, W) { cin >> A[h][w]; } }
  rep(k,10) { rep(i,10) { rep(j,10) { c[i][j] = min(c[i][j], c[i][k]+c[k][j]); } } }
  int ans = 0;
  rep(h, H) { rep(w, W) { if(A[h][w] != -1) { ans += c[A[h][w]][1]; } } }
  cout << ans << endl;
}

Measured memory_bytes: 384
x, y, z, k = map(int, input().split())
a = sorted(list(map(int, input().split())), reverse=True)
b = sorted(list(map(int, input().split())), reverse=True)
c = sorted(list(map(int, input().split())), reverse=True)

ans = []
for i in range(x):
    for j in range(y):
        for l in range(z):
            if (i+1) * (j+1) * (l+1) <= k:
                ans.append(a[i] + b[j] + c[l])
            else:
                break

ans.sort(reverse=True)
for i in range(k):
    print(ans[i])

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

#define NIL NULL

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;


Node root;
void insert(int);
void inorder(Node);
void preorder(Node);

int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }

  return 0;
}

void insert(int num){
  Node x = root;
  Node y = NIL;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = num;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;
    if(z ->key < x ->key){
      x = x->left;
    }
    else{
      x = x->right;
    }
  }
  z->parent = y;
if(y == NIL){
  root = z;
}
  else{
    if( z->key < y->key){
      y->left = z;
    }
    else{
      y->right = z;
    }
  }
}

void inorder(Node n){
  if(n== NIL)return;
  inorder(n -> left);
  printf(" %d",n -> key);
  inorder(n -> right);
}

void preorder(Node n){
  if(n == NIL)return;
	printf(" %d",n->key);
	preorder(n->left);
	preorder(n->right);
}



Measured memory_bytes: 25140
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;

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

	cin >> N >> M >> K;
	long double ans = 0;
	int box = N - K * 2;
	box = max(0, box);
	int bag = N - box;
	ans = (long double)box * 2 / N * (M - 1) / N;
	if (!K)ans /= 2;
	ans += (long double)bag / N * (M - 1) / N;
	cout << setprecision(15) << ans << endl;
	return 0;
}

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

int main()
{
	int n,k,x[100];
	cin>>n>>k;
	for(int i=0;i<n;i++) cin>>x[i];
	
	int sum=0;
	for(int i=0;i<n;i++){
		sum+=min(x[i],k-x[i])*2;
	}
	
	cout<<sum<<endl;
	
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
int a[maxn];
void read(int &x){
	char c=getchar();
	int f=1;
	x=0;
	while(c<'0' || c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0' && c<='9'){x=x*10+c-'0';c=getchar();}
	x*=f;
}
int main(){
	int i,j,k,m,n;
	read(n);read(k);read(m);
	for(register int i=1;i<=m;i++){
		int x;
		read(x);
		a[x]++;
	}
	for(register int i=1;i<=n;i++){
		a[i]=a[i]+k-m;
		if(a[i]>0)printf("Yes\n");
		else printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 1024
using System;
using System.Linq;
using System.Collections.Generic;
using System.Numerics;
using static System.Console;

class Solver {
    Scanner sc = new Scanner();


    public void Solve() {
        var N = sc.nextInt();
        var a = sc.ArrayInt(N);
        var ans = 0;
        for (int i = 0; i < N; i++) {
            var tmp = a[i];
            while (tmp % 2 == 0 || tmp == 0) {
                tmp /= 2;
                ans++;
            }
        }
        WriteLine(ans);

    }
}



class Scanner {
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner() {
        s = new string[0];
        i = 0;
    }

    public string next() {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt() {

        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0) {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong() {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0) {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble() {
        return double.Parse(next());
    }

    public double[] ArrayDouble(int N, double add = 0) {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

class Program {
    static void Main(string[] args) {
        Solver s = new Solver();
        s.Solve();
    }
}

Measured memory_bytes: 13792
n,m = map(int,input().split())
li = list(map(int,input().split()))
if n>=m:
    print(0)
    exit()

li.sort()
all_li = []
for i,l in enumerate(li):
    if i==0:
        continue
    all_li.append(l-li[i-1])
all_li.sort(reverse=True)
#print(n,all_li,all_li[n-1:])
print(sum(all_li[n-1:]))

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

int main(){

  int n;
  cin>>n;
  string s;
  map<string,int> mp;
  
  rep(i,n){

    cin>>s;
    mp[s]=1;
    
  }

  cout<<mp.size()<<endl;
}


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

using namespace std;

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

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

int stick[8];

int calc(vector<int> &hist, int a, int b, int c)
{
    int len[4] = {};
    int cnt[4] = {};
    for(int i=0;i<hist.size();++i)
    {
        len[hist[i]] += stick[i];
        cnt[hist[i]]++;
    }
    if(cnt[1] == 0 || cnt[2] == 0 || cnt[3] == 0) return 1 << 30;

    return abs(a - len[1]) + abs(b - len[2]) + abs(c - len[3]) + 10 * (cnt[1] + cnt[2] + cnt[3] - 3);
}
int dfs(vector<int> &hist, int n, int a, int b, int c)
{
    int ret = 1 << 30;
    if(hist.size() == n)
    {
        return calc(hist, a, b, c);
    }

    for(int i=0;i<4;i++)
    {
        hist.push_back(i);
        ret = min(ret, dfs(hist, n, a, b, c));
        hist.pop_back();
    }

    return ret;
}
int main(){
    std::ios::sync_with_stdio(false);
    int n, a, b, c;
    cin >> n >> a >> b >> c;
    for(int i=0;i<n;++i)
    {
        cin >> stick[i];
    }
    vector<int> hist;

    cout << dfs(hist, n, a, b, c) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()
#define let auto const

template<typename F>
static inline constexpr decltype(auto) fix(F&& f) noexcept {
  return [f = std::forward<F>(f)](auto&&... args) {
    return f(f, std::forward<decltype(args)>(args)...);
  };
}
template<typename T>
static inline T fin() { T t; cin >> t; return std::move(t); }


int main() {
  i64 n, k;
  cin >> n >> k;
  vector<i64> h(n + 1);
  for(int i = 0;i < n;i++) cin >> h[i + 1];
  vector<i64> dp(n + 1, 1e18);
  dp[1] = 0;
  for(int i = 2;i <= n;i++) {
    for(int j = max(1ll, i - k);j < i;j++) {
      dp[i] = min(dp[i], dp[j] + abs(h[j] - h[i]));
    }
  }
  cout << dp[n] << endl;
}


Measured memory_bytes: 1792
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<map>
#include<numeric>
#include<set>
#include<string>
#include<utility>
#include<vector>

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define per(i, a, n)  for(int i=n-1; i>=a; i--)
#define all(x)  (x).begin(), (x).end()
#define MAX 1e18
using namespace std;
typedef long long ll;

int main(){
  int x, y, s;
  while(true){
    int ans = 0;
    cin >> x >> y >> s;
    if(x + y + s == 0)  break;
    rep(i, 1, s){
      rep(j, 1, s){
        int prop1 = i*(100+x)/100;
        int prop2 = j*(100+x)/100;
        if(prop1+prop2 != s)  continue;
        prop1 = i*(100+y)/100;
        prop2 = j*(100+y)/100;
        ans = max(ans, prop1+prop2);
      }
    }
    cout << ans << endl;
  }
  return 0;
}



Measured memory_bytes: 3004
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
#include <climits>
typedef long long ll;
using namespace std;

int main(void){
  int N,C,i,j,k;
  static int c[500][500],d[30][30];
  cin>>N>>C;
  for(i=0;i<C;i++){
    for(j=0;j<C;j++){
      cin>>d[i][j];
    }
  }
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      cin>>c[i][j];
      c[i][j]--;
    }
  }

  int sum[3][30];
  for(i=0;i<3;i++){
    for(j=0;j<30;j++){
      sum[i][j]=0;
    }
  }

  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      for(k=0;k<C;k++){
        sum[(i+j+2)%3][k]+=d[c[i][j]][k];
      }
    }
  }

  int t,min=1<<30;
  for(i=0;i<C;i++){
    for(j=0;j<C;j++){
      for(k=0;k<C;k++){
        if(i==j||j==k||k==i){
          continue;
        }
        else{
          t=sum[0][i]+sum[1][j]+sum[2][k];
          if(t<min)min=t;
        }
      }
    }
  }

  cout<<min<<endl;

  return 0;
}

Measured memory_bytes: 1280
gets
As = gets.split.map(&:to_i)

counts = As.group_by(&:itself).map { |n, ns| [n, ns.size] }.to_h

fours = counts.select { |n, count| count >= 4 }
twos = counts.select { |n, count| count >= 2 }

fours_score = 0
twos_score = 0

if fours.size > 0
  fours_score = fours.sort.reverse[0][0] ** 2
end

if twos.size >= 2
  twos_score = twos.sort_by { |n, c| n }.reverse.take(2).map { |n, _| n }.inject(:*)
end

puts [fours_score, twos_score].max


Measured memory_bytes: 33420
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <utility>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <cstdio>
#include <math.h>
#include <stdio.h>

using namespace std;

#define REP(i,n,m) for( long long int i = (n); i < (m); i++ )
#define ll long long
#define ALL(a) (a).begin(), (a).end()
#define SORT(v) sort( ALL(v) );
#define LAST(v) v[v.size()-1]
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,-1,sizeof(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define pi pair<int, int>
#define MP make_pair
#define PB push_back
#define IIN(a) int a; cin >> a;
#define LIN(a) ll a; cin >> a;
#define SIN(a) string a; cin >> a;
#define EPS (1e-10)
#define INF 1000000000000LL

int MOD=1000000007;
int dx[4] = {0, 0, -1, 1};
int dy[4] = {1, -1, 0, 0};
//I ASCII code: '0' = 48; 'A' = 65; 'a' = 97

signed main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    LIN(n)
    LIN(m)
    LIN(c)
    vector<ll> b(m);
    ll ans=0;
    REP(i, 0, m ){
      cin >> b[i] ;
    }
    REP(i, 0, n ){
      int polya = 0;
      vector<ll> a(m);
      REP(j,0,m){
        cin>>a[j];
      }
      REP(j,0,m){
        polya+=a[j]*b[j];
      }
      if(polya> -c){
        ans++;
      }
    }
    cout << ans << endl;
    return 0;
}


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

int main()
{
	int A,B;
	string S,T,U;
	cin >> S >> T;
	cin >> A >> B;
	cin >> U;
	if (S == U)
	{
		cout << A-1 << " " << B << endl;
	}
	else
	{
		cout << A << " " << B-1 << endl;
	}
	return 0;
}

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

int main() {
  int a,b,c,d;
  cin >> a >> b  >> c >> d;
 if ((abs(c-a) <= d) ||( (abs(c-b) <= d) && (abs(b-a) <= d))){
  cout << "Yes" << endl;
 }
   else {
  cout << "No" << endl;
  
}

}

  




Measured memory_bytes: 256
#!/usr/bin/python
N, M = list(map(int, input().split()))
X = list(map(int, input().split()))
x = sorted(X)
i = 0
diff = []
while i + 1 < len(x):
    diff.append(x[i] - x[i + 1])
    i += 1
d = sorted(diff)[N - 1:]
print(abs(sum((d))))

Measured memory_bytes: 13968
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
using namespace std;

int main()
{
    string s;
    cin>>s;
    int o=0;
    for(int i=0;i<3;i++)
        if(s[i]=='o')o++;
    cout<<700+o*100;
    return 0;
}


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

int main(){
	int H, W, K;
	cin >> H >> W >> K;
    vector<vector<char>> c(H,vector<char>(W));
    vector<int> hcnt(H), wcnt(W);
    int total=0;
    for(int i=0; i<H; i++){
        int cnt=0;
        for(int j=0; j<W; j++){
            cin >> c.at(i).at(j);
            if( c.at(i).at(j) == '#' ){
                cnt++;
                total++;
            }
        }
        hcnt.at(i) = cnt;
    }
    for(int j=0; j<W; j++){
        int cnt=0;
        for(int i=0; i<H; i++){
            if( c.at(i).at(j) == '#' ) cnt++;
        }
        wcnt.at(j) = cnt;
    }

    int ans=0;
    for(int i=0; i<(1<<6); i++){
        bitset<6> row(i);
        for(int j=0; j<(1<<6); j++){
            bitset<6> col(j);

            int cnt=0;
            vector<vector<int>> used(H,vector<int>(W,0));
            for(int m=0; m<H; m++){
                if( row.test(m) ){
                    cnt += hcnt.at(m);
                    for(int l=0; l<W; l++){
                        used.at(m).at(l) = 1;
                    }
                }
            }
            for(int m=0; m<W; m++){
                if( col.test(m) ){
                    cnt += wcnt.at(m);
                    for(int l=0; l<H; l++){
                        if( used.at(l).at(m)==1 ){ 
                            if( c.at(l).at(m) == '#' ){
                                cnt--;
                            }
                        }
                    }
                }
            }
            if( K==total-cnt ) ans++;
            
            if( j == pow(2,W)-1 ) break; 
        }
        if( i == pow(2,H)-1 ) break; 
    }

	cout << ans << endl;
}


Measured memory_bytes: 4112
import java.util.Scanner;

class Main
{
	public static void main(String args[])
	{
		Scanner sc = new Scanner(System.in);
		
		while (true)
		{
			int m = sc.nextInt();
			int n = sc.nextInt();
			if (n == 0 && m == 0)
				break;
			int x = 1;
			int y = 1;
			int dx[] = { 0, 1, 0,-1};
			int dy[] = { 1, 0,-1, 0};
			int d = 0;
			while (true)
			{
				String str = sc.next();
				if (str.equals("STOP"))
				{
					System.out.printf("%d %d\n", x, y);
					break;
				}
				else if (str.equals("FORWARD"))
				{
					int k = sc.nextInt();
					for (int i = 0; i < k; i++)
					{
						if (x + dx[d] < 1 || m < x + dx[d])
							break;
						x += dx[d];
					}
					for (int i = 0; i < k; i++)
					{
						if (y + dy[d] < 1 || n < y + dy[d])
							break;
						y += dy[d];
					}
				}
				else if (str.equals("BACKWARD"))
				{
					int k = sc.nextInt();
					for (int i = 0; i < k; i++)
					{
						if (x - dx[d] < 1 || m < x - dx[d])
							break;
						x -= dx[d];
					}
					for (int i = 0; i < k; i++)
					{
						if (y - dy[d] < 1 || n < y - dy[d])
							break;
						y -= dy[d];
					}
				}
				else if (str.equals("RIGHT"))
				{
					d++;
					if (d == 4) d = 0;
				}
				else if (str.equals("LEFT"))
				{
					d--;
					if (d == -1) d = 3;
				}
			}
		}
	}
}

Measured memory_bytes: 13000
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
      return Array.new(size1){init}
  else
      return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

H,W=get_i
Dir_=[[1,0],[-1,0],[0,-1],[0,1]]
$visit=array(W,false,H)
def bfs(s,r)
    que=[r]
    $visit[r[1]][r[0]]=true
    b=1
    w=0
    until que==[]
        p=que.shift
        Dir_.each do|x,y|
            nx=p[0]+x
            ny=p[1]+y
            next unless nx.between?(0,W-1) and ny.between?(0,H-1) and not $visit[ny][nx] and s[ny][nx]!=s[p[1]][p[0]]
            $visit[ny][nx]=true
            if s[ny][nx]=="#"
                b+=1
            else
                w+=1
            end
            que.push([nx,ny])
        end
    end
    return b,w
end
s=array(H)
H.times do|i|
    s[i]=get_nsp
end
ans=0
H.times do|i|
    W.times do|j|
        if not $visit[i][j] and s[i][j]=="#"
          b,w=bfs(s,[j,i])
          ans+=b*w
        end
    end
end
puts ans

Measured memory_bytes: 25836
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(int argc, char const *argv[])
{
	ios::sync_with_stdio(false);
	ll q,h,s,d;
	while(cin>>q>>h>>s>>d){
		q*=4,h*=2;
		ll temp=min(q,min(h,s));
		ll n,ans=0;
		cin>>n;
		if(n&1){
			ans=min((n/2)*d+temp,n*temp);
		}
		else{
			ans=min((n/2)*d,n*temp);
		}
		cout<<ans<<endl;
	}
	return 0;
}

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

class Dice{
    public:
        int side1;
        int side2;
        int side3;
        int side4;
        int side5;
        int side6;

    void SetDice(int s1,int s2,int s3,int s4,int s5,int s6)
    {
        side1=s1;
        side2=s2;
        side3=s3;
        side4=s4;
        side5=s5;
        side6=s6;
    }

    int GetTop(void){
        return(side1);
    }

    void Rotate(char direction){
        if(direction=='N'){
            int wk=side1;
            side1=side2;
            side2=side6;
            side6=side5;
            side5=wk;
        }
        else if(direction=='S'){
            int wk=side1;
            side1=side5;
            side5=side6;
            side6=side2;
            side2=wk;
        }
        else if(direction=='W'){
            int wk=side1;
            side1=side3;
            side3=side6;
            side6=side4;
            side4=wk;
        }
        else if(direction=='E'){
            int wk=side1;
            side1=side4;
            side4=side6;
            side6=side3;
            side3=wk;
        }
    }
};

int main() {
    int s1,s2,s3,s4,s5,s6;
    cin>>s1>>s2>>s3>>s4>>s5>>s6;

    Dice dice;
    dice.SetDice(s1,s2,s3,s4,s5,s6);

    string s;
    cin>>s;

    for(int i=0;i<s.size();i++){
        dice.Rotate(s.at(i));
    }


    cout<<dice.GetTop()<<endl;

    return 0;
}


Measured memory_bytes: 3180
#include <iostream>
using namespace std;
int main(){
	int i,n,a,b,pass=0,passb=0;
	char s[100001];
	cin>>n>>a>>b;
	for(i=0;i<n;i++){
		cin>>s[i];
	}
	for(i=0;i<n;i++){
		if(s[i]=='a'){
			if(pass<a+b){
				cout<<"Yes"<<endl;
				pass++;
			}else{
				cout<<"No"<<endl;
			}
		}else if(s[i]=='b'){
			if(pass<a+b && passb<b){
				cout<<"Yes"<<endl;
				pass++;
				passb++;
			}else{
				cout<<"No"<<endl;
			}
		}else{
			cout<<"No"<<endl;
		}
	}


	return 0;
}

Measured memory_bytes: 768
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int N = Integer.parseInt(sc.next());
		String S = sc.next();
		
		char[] arr = S.toCharArray();
		
		for (int i = 0; i < arr.length; ++i) {
			arr[i] += N;
			if (arr[i] > 90) arr[i] -= 26;
		}
		
		System.out.println(arr);
		
	}
}


Measured memory_bytes: 22740
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e3+5;
bool is[maxn][maxn];
typedef pair<int,int>Node;
Node s,e;
int h,w,dx[]={0,0,1,-1},dy[]={-1,1,0,0},d[maxn][maxn];
char mp[maxn][maxn];
void bfs(){
    memset(d,0x3f,sizeof(d));
    deque<Node>q;
    d[s.first][s.second]=0;
    q.push_front(s);
    while(!q.empty()){
        Node n1=q.front();
        q.pop_front();
        if(is[n1.first][n1.second])continue;
        is[n1.first][n1.second]=1;
        for(int i=0;i<4;++i){
            int xx=n1.first+dx[i],yy=n1.second+dy[i];
            if(xx<1||yy<1||xx>h||yy>w||mp[xx][yy]=='#'||d[xx][yy]<=d[n1.first][n1.second])continue;
            d[xx][yy]=d[n1.first][n1.second];
            q.push_front({xx,yy});
        }
        for(int i=n1.first-2;i<=n1.first+2;++i){
            if(i<1||i>h)continue;
            for(int j=n1.second-2;j<=n1.second+2;++j){
                if(j<1||j>w||mp[i][j]=='#'||d[i][j]<=d[n1.first][n1.second]+1)continue;
                d[i][j]=d[n1.first][n1.second]+1;
                q.push_back({i,j});
            }
        }
    }   
}
int main(){
    scanf("%d%d",&h,&w);
    scanf("%d%d%d%d",&s.first,&s.second,&e.first,&e.second);
    for(int i=1;i<=h;++i)
        scanf("%s",mp[i]+1);
    bfs();
    if(d[e.first][e.second]==0x3f3f3f3f)puts("-1");
    else cout<<d[e.first][e.second]<<endl;      
    return 0;
}

Measured memory_bytes: 9656
#include <iostream>
#include <vector>
#include <set> 
#include <map>
#include <algorithm>
#include <cmath>
#include <iomanip>
using namespace std;
typedef long long int ll;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int a,b,c;
    cin>>a>>b>>c;
    int k;
    cin>>k;
    int steps=0;
    while(b<=a){
        steps++;
        b*=2;
    }
    while(c<=b){
        steps++;
        c*=2;
    }
    if(steps<=k)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

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

#define rep(i,l,n) for(int (i)=(l);(i)<(n);(i)++)
#define min(a,b) (a)<(b)?(a):(b)
#define max(a,b) (a)>(b)?(a):(b)
#define abs(a) (a)>0?(a):-(a)

int int_cmp(const void*,const void*);

int main(){
	int X,Y,A,B,C; scanf("%d %d %d %d %d",&X,&Y,&A,&B,&C);
	int p[A],q[B],r[C];
	rep(i,0,A) scanf("%d",&p[i]);
	rep(i,0,B) scanf("%d",&q[i]);
	rep(i,0,C) scanf("%d",&r[i]);
	qsort(p,A,sizeof(int),int_cmp);
	qsort(q,B,sizeof(int),int_cmp);
	qsort(r,C,sizeof(int),int_cmp);
	int a=A-X,b=B-Y;
	rep(i,0,C){
		if( a==A ){
			if( b==B ) break;
			if( q[b]<r[C-1-i] ){
				q[b]=r[C-1-i];
				b++;
			}else break;
		}else if( b==B ){
			if( p[a]<r[C-1-i] ){
				p[a]=r[C-1-i];
				a++;
			}else break;
		}else{
			if( p[a]<q[b] ){
				if( p[a]<r[C-1-i] ){
					p[a]=r[C-1-i];
					a++;
				}
				else break;
			}else{
				if( q[b]<r[C-1-i] ){
					q[b]=r[C-1-i];
					b++;
				}
				else break;
			}
		}
	}
	long ans=0;
	rep(i,0,X) ans += p[A-1-i];
	rep(i,0,Y) ans += q[B-1-i];
	printf("%ld",ans);
}

// 昇順に並び替え
int int_cmp(const void *a,const void *b){
	int *a0 = (int*)a;
	int *b0 = (int*)b;
	return *a0-*b0;
}

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

int main()
{

    long long int k,n,m,i,s=0,x,y,d,e,f,p,q,r;

    cin>>x>>y>>n>>m>>k;
    long long int a[n],b[m],c[k];
    for(i=0; i<n; i++)
    {
        cin>>a[i];
    }
    for(i=0; i<m; i++)
    {
        cin>>b[i];
    }
    for(i=0; i<k; i++)
    {
        cin>>c[i];
    }
    d=n-x;
    e=m-y;
    f=k-1;
    sort(a,a+n);
    sort(b,b+m);
    sort(c,c+k);
    while(1)
    {
        if(a[d]>b[e])
        {
            if((c[f]>b[e]&&e!=m)&&f>=0)
            {
                s=s+c[f];
                f--;
                e++;
                //cout<<c[f+1]<<" is add in b"<<endl;
            }
            else if(e!=m)
            {
                s=s+b[e];
                e++;

            }
            /* if((c[f]>a[d]&&d!=n)&&f>=0)
            {
             s=s+c[f];
             f--;
             d++;
             cout<<c[f+1]<<" is add in a";
            }
            else if(d!=n)
            {
            s=s+a[d];
             d++;

            }*/
        }
        else
        {
            if((c[f]>a[d]&&d!=n)&&f>=0)
            {
                s=s+c[f];
                f--;
                d++;
                //cout<<c[f+1]<<" is add in a"<<endl;
            }
            else if(d!=n)
            {
                s=s+a[d];
                d++;

            }
            /* if((c[f]>b[e]&&e!=m)&&f>=0)
            {
             s=s+c[f];
             f--;
             e++;
             cout<<c[f+1]<<" is add in b";
            }
            else if(e!=m){
            s=s+b[e];
             e++;

            }*/
        }
        if(e==m||d==n)
            break;

    }

        while(e!=m)
        {
            if((c[f]>b[e]&&e!=m)&&f>=0)
            {
                s=s+c[f];
                f--;
                e++;
                //cout<<c[f+1]<<" is add in b"<<endl;
            }
            else if(e!=m)
            {
                s=s+b[e];
                e++;

            }
        }

    while(d!=n){
        if((c[f]>a[d]&&d!=n)&&f>=0)
        {
            s=s+c[f];
            f--;
            d++;
            //cout<<c[f+1]<<" is add in a"<<endl;
        }
        else if(d!=n)
        {
            s=s+a[d];
            d++;

        }
    }

    cout<<s<<endl;
}



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

int main()
{
	char s[100001];
	long long K;
	scanf("%s", s);
	scanf("%lld", &K);
	
	int i;
	for (i = 0; s[i] != 0; i++) {
		if (s[i] == 'a') continue;
		else if (K >= 26 - s[i] + 'a') {
			K -= 26 - s[i] + 'a';
			s[i] = 'a';
		}
	}
	s[i-1] = (s[i-1] - 'a' + K % 26) % 26 + 'a';
	
	printf(s);
	fflush(stdout);
	return 0;
}

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

using namespace std;

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

  long long n, a, b;
  cin >> n >> a >> b;
  cout << n / (a + b) * a + min(a, n % (a + b));

  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main() {
  ll a, b;
  cin >> a >> b;
  for (ll c = 1; c <= 100000; ++c) {
    int aa = (c * 8) / 100;
    int bb = (c * 10) / 100;
    if (aa == a && bb == b) {
      cout << c << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}

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

#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back
#define REACH cerr<<"reached line "<<__LINE__<<endl
#define DBG(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl

using uint=unsigned int;
using ll=long long;
using pii=pair<int,int>;
using vi=vector<int>;
using ld=long double;

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"[";
	REP(i,(int)v.size()){
		if(i)os<<",";
		os<<v[i];
	}
	os<<"]";
	return os;
}

int read(){
	int i;
	scanf("%d",&i);
	return i;
}

void Yes(){
	cout<<"Yes"<<endl;
	exit(0);
}

void No(){
	cout<<"No"<<endl;
	exit(0);
}

template<class T>
void chmax(T& a,T b){
	a=max(a,b);
}

template<class T>
void chmin(T& a,T b){
	a=min(a,b);
}

int main(){
	int n=read();
	int least=1;
	ll ans=0;
	REP(_,n){
		int a=read();
		if(a>least){
			ans+=(a-1)/least;
			chmax(least,2);
		}else
			chmax(least,a+1);
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 384
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

m, n = MAP()
print(pow(m, n, MOD))



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

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

string s[200010];
map <string, int> m;
vector <pair<int, string> > v;
vector <string> ans;

int main(void) {
	int N;
	cin >> N;
	REP(i,N) {
		cin >> s[i];
		m[s[i]]++;
	}
	for(map <string, int> :: iterator it=m.begin(); it!=m.end(); it++)
		v.push_back({it->second, it->first});
	sort(v.rbegin(), v.rend());
	//REP(i,v.size()) cout << v[i].second << endl;
	ans.push_back(v[0].second);
	for(int i=1; i<v.size(); i++) {
		if(v[i].first < v[i-1].first) break;
		ans.push_back(v[i].second);
	}
	sort(ans.begin(), ans.end());
	REP(i,ans.size()) cout << ans[i] << endl;
	return 0;
}

Measured memory_bytes: 33520
#include <iostream>
#define R 100
#define C 100
using namespace std;

void Input(int ary[R][C], int m, int n) {
	int i, j;

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

	return;
}

void OutputAndSum(int ary[R][C], int m, int n) {
	int i, j;
	int *Rsum = new int[n];
	int Csum = 0;
	int sum = 0;

	for (i = 0; i < m; i++) {
		for (j = 0; j < n; j++) {
			cout << ary[i][j] << " ";
			Rsum[j] += ary[i][j];
			Csum += ary[i][j];
		}
		cout << Csum << endl;
		Csum = 0;
	}

	for (j = 0; j < n; j++) {
		cout << Rsum[j] << " ";
		sum += Rsum[j];
	}

	cout << sum << endl;

	delete [] Rsum;

	return;
}

int main()
{
	int table[R][C];
	int r, c;

	cin >> r >> c;

	Input(table, r, c);

	OutputAndSum(table, r, c);

	return 0;
}

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

int main() {
  ll l,r;
  cin >> l >> r;
  ll ans=10000000;
  r=min(r,l+3000);
  for(ll i=l;i<r;i++){
    for(ll i2=i+1;i2<=r;i2++){
      ll g=(i*i2)%2019;
      ans=min(ans,g);
    }
  }
  cout << ans << endl;
}

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

int main() {
    int64_t a,b,c,d;

    cin >> a >> b >> c;

    d = c-a-b;

    if(d > 0 && 4*a*b < d*d) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func solve() {
	sx, sy := getInt(), getInt()
	tx, ty := getInt(), getInt()
	dx, dy := tx-sx, ty-sy

	ans := ""
	ans += strings.Repeat("R", dx)
	ans += strings.Repeat("U", dy)
	ans += strings.Repeat("L", dx)
	ans += strings.Repeat("D", dy)

	ans += "D" + strings.Repeat("R", dx+1)
	ans += strings.Repeat("U", dy+1) + "L"
	ans += "U" + strings.Repeat("L", dx+1)
	ans += strings.Repeat("D", dy+1) + "R"

	fmt.Fprintln(wr, ans)
}

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

const (
	inf = 1 << 60
	// mod = 1000000007
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wr = bufio.NewWriter(os.Stdout)
)

func main() {
	// buf := 200001
	// sc.Buffer(make([]byte, buf), buf)
	sc.Split(bufio.ScanWords)
	solve()
	wr.Flush()
}

func getInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func getIntSlice(n int) []int {
	is := make([]int, n)
	for i := range is {
		is[i] = getInt()
	}
	return is
}

func getString() string {
	sc.Scan()
	s := sc.Text()
	return s
}

func getRunes() []rune {
	return []rune(getString())
}


Measured memory_bytes: 768
#include <iostream>

using namespace std;

long long gcd(long long a, long long b) {
    return a == 0 ? b : gcd(b % a, a);
}

int main() {
    long long a, b, c, d;
    cin >> a >> b >> c >> d;
    long long answer = b - a + 1;
    answer -= (b / c) - (a / c);
    if (a % c == 0) --answer;
    answer -= (b / d) - (a / d);
    if (a % d == 0) --answer;
    long long g = gcd(c, d);
    long long e = g * (c / g) * (d / g);
    answer += (b / e) - (a / e);
    if (a % e == 0) ++answer;
    cout << answer << endl;
}


Measured memory_bytes: 256
import java.util.*;

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

		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		while( a != b ){
			if( a < b ){
				b -= a;
			} else if( a > b ){
				a -= b;
			}
		}
		
		System.out.println(a);
	}
}

Measured memory_bytes: 12000