akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <numeric>
#include <iomanip>
#include <tuple>
#include <deque> 

using namespace std;

int main(){
   long long n;
   cin>>n;
   int ans=0;
   int d=0;
   int h;
   while(n>0){
       ans+=(int)(n%10);
       h=(int)(n%10);
       n/=10;
       d++;
   }
   ans=max(ans,h-1+9*(d-1));
   cout<<ans<<endl;
}

   


Measured memory_bytes: 888
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<stdbool.h>
#include<assert.h>
typedef long long ll;
typedef long double ld;
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define rrep(i,l,r)for(ll i=(l);i>=(r);i--)
#define INF (1LL<<60)
#define MOD1 1000000007
#define MOD2 998244353
#define MAX_N (1 << 17)
#define YES printf("Yes\n")
#define NO printf("No\n")
#define PN printf("\n")
#define charsize 100005 //10^5+5

void swap(ll *a, ll *b){ll c;c=*b;*b=*a;*a= c;}
ll max2(ll a,ll b){return a>=b?a:b;}
ll min2(ll a,ll b){return a>=b?b:a;}
ll min3(ll a, ll b, ll c){return (a<=b && a<=c) ? a : b<=c ? b : c;}
ll max3(ll a, ll b, ll c){return (a>=b && a>=c) ? a : b>=c ? b : c;}
ll minn(ll n, ll a[n]){ll b=INF;rep(i,0,n) b=min2(b,a[i]);return b;}
ll maxn(ll n, ll a[n]){ll b=-INF;rep(i,0,n) b=max2(b,a[i]);return b;}
ll ABS(ll a){return a>=0?a:(-a);}
ll POW(ll a, ll b){ll c=1;rep(i,0,b) c*=a;return c;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll mod(ll n){n+= n<0?((-n)/MOD1+1)*MOD1:0; return n%=MOD1;}
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

typedef struct{ ll a , b;}fr;
int cmp1( const void *p, const void *q ) { return ((fr*)p) ->a - ((fr*)q)->a;}
int cmp2( const void *p, const void *q ) { return ((fr*)q) ->a - ((fr*)p)->a;}
void strsortup(fr*a,int n){qsort(a,n,sizeof(fr),cmp1);}
void strsortdown(fr*a,int n){qsort(a,n,sizeof(fr),cmp2);}

// 約数記録
#define divi_size 1000001
ll divi[divi_size]={},rest1=-1,rest2=-1;
void makedivi(ll n){
    ll cnt=0;
    while(n%2==0){
        n/=2;
        cnt++;
        // divi[2]++;
    }
    divi[2]=min2(cnt,divi[2]);
    repp(i,3,divi_size,2){
        // if(n<i) break;
        cnt=0;
        while(n%i==0){
            n/=i;
            cnt++;
            // divi[i]++;
        }
        divi[i]=min2(cnt,divi[i]);
    }
    if(n>1){
        if(rest1==-1){
            rest1=n;
        }else{
            rest2=n;
        }
    }
    // return n>1?2:1;
}

void inidivi(){
    rep(i,0,1000001){
        divi[i]=INF;
    }
}

int main(void){
    // char ;
    ll a,b,ans=0;
    scanf("%lld%lld",&a,&b);
    // ll [n];
    inidivi();
    makedivi(a);
    makedivi(b);
    rep(i,0,1000001){
        if(divi[i]!=INF && divi[i]!=0){
            // printf("%lld ",i);
            ans++;
        }
    }
    // 1
    ans++;
    if(rest1!=-1 && rest1==rest2) ans++;

    
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 7936
def partition(A, p, r):
    x = A[r]
    i = p - 1
    for j in range(p, r):
        if A[j] <= x:
            i += 1
            A[i], A[j] = A[j], A[i]

    A[i+1], A[r] = A[r], A[i+1]
    return i + 1

n = int(input())
A = list(map(int, input().split()))

p = partition(A, 0, n-1)

for i in range(n):
    if i:
        print(' ', end = '')
    if i == p:
        print('[', end = '')
    print(A[i], end = '')
    if i == p:
        print(']', end = '')
print()



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

const int MAX_N = 1e6;

void optimizeIO() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
}

int main() {
	int N, A[MAX_N + 1], gcdOfAll;
	set<int> primes;
	bool setwise = false, pairwise = false;
	optimizeIO();
	cin >> N >> A[1];
	gcdOfAll = A[1];
	for (int i = 2; i <= N; ++i) {
		cin >> A[i];
		gcdOfAll = gcd(gcdOfAll, A[i]);
	}
	if (gcdOfAll == 1) {
		setwise = true;
		pairwise = true;
		for (int i = 1; i <= N and pairwise; ++i) {
			int original = A[i];
			for (int divisor = 2; divisor * divisor <= original; ++divisor) {
				if (A[i] % divisor == 0) {
					while (A[i] % divisor == 0)
						A[i] /= divisor;
					auto result = primes.insert(divisor);
					if (result.second == false) {
						pairwise = false;
						break;
					}
				}
			}
			if (A[i] > 1) {
				int divisor = A[i];
				while (A[i] % divisor == 0)
					A[i] /= divisor;
				auto result = primes.insert(divisor);
				if (result.second == false) {
					pairwise = false;
					break;
				}
			}
		
		}
	}
	if (pairwise)
		cout << "pairwise coprime" << endl;
	else if (setwise)
		cout << "setwise coprime" << endl;
	else
		cout << "not coprime" << endl;
	return 0;
}


Measured memory_bytes: 7584
#define _USE_MATH_DEFINES
#define MAX_N 1000000
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>

using namespace std;

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

static const double eps = 1e-8;

struct COLOR{
	string name;
	string R;
	string G;
	string B;
};

int hex2dec(string str){
	const char hex[] = {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
	return 16 * (int)lower_bound(hex,hex+16,str[0]) + (int)lower_bound(hex,hex+16,str[1]);
}

int main(){

	struct COLOR color[] = {
		"black","00","00","00",
		"blue","00","00","ff",
		"lime","00","ff","00",
		"aqua","00","ff","ff",
		"red","ff","00","00",
		"fuchsia","ff","00","ff",
		"yellow","ff","ff","00",
		"white","ff","ff","ff",
	};

	string str;
	while(cin >> str){
		if(str.size() == 1 && str[0] == '0') break;
		int r = hex2dec(str.substr(1,2));
		int g = hex2dec(str.substr(3,2));
		int b = hex2dec(str.substr(5,2));

		int dk = 10000000;
		int idx=0;
		for(int i=0;i<sizeof(color)/sizeof(struct COLOR); i++){
			int tmp;
			if(dk > (tmp=((r - hex2dec(color[i].R)) * (r - hex2dec(color[i].R))
				+ (g - hex2dec(color[i].G)) * (g - hex2dec(color[i].G))
				+ (b - hex2dec(color[i].B)) * (b - hex2dec(color[i].B))))){
					dk = tmp;
					idx=i;
			}
		}

		printf("%s\n",color[idx].name.c_str());
	}

}

Measured memory_bytes: 0
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

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

ll H, W, M;
vector<Pll> hw, wh;
map<ll, ll> hcnt, wcnt;
vector<Pll> hvec, wvec, hvec2, wvec2;
map<ll, map<ll, bool>> isexist;

int main() {
  //
  cin >> H >> W >> M;
  rep(i, 0, M) {
    ll h, w;
    cin >> h >> w;
    hw.push_back(Pll(h, w));
    wh.push_back(Pll(w, h));
    isexist[h][w] = true;
  }

  sort(hw.begin(), hw.end());
  sort(wh.begin(), wh.end());

  for (auto e : hw) {
    ll ch = e.first;
    hcnt[ch]++;
  }
  for (auto e : wh) {
    ll cw = e.first;
    wcnt[cw]++;
  }

  for (auto e : hcnt) {
    hvec.push_back(Pll(e.second, e.first));
  }
  for (auto e : wcnt) {
    wvec.push_back(Pll(e.second, e.first));
  }
  sort(hvec.begin(), hvec.end());
  reverse(hvec.begin(), hvec.end());
  sort(wvec.begin(), wvec.end());
  reverse(wvec.begin(), wvec.end());

  ll htop = hvec[0].first;
  ll wtop = wvec[0].first;

  for (auto e : hvec) {
    if (e.first != htop) break;

    hvec2.push_back(e);
  }

  for (auto e : wvec) {
    if (e.first != wtop) break;

    wvec2.push_back(e);
  }

  ll ans = 0;
  for (ll i = 0; i < hvec2.size(); ++i) {
    for (ll j = 0; j < wvec2.size(); ++j) {
      auto ch = hvec2[i];
      auto cw = wvec2[j];
      if (!isexist[ch.second][cw.second]) {
        cout << ch.first + cw.first << endl;
        // cout << ch.second << " " << cw.second;
        return 0;
      } else {
        chmax(ans, ch.first + cw.first - 1);
      }
    }
  }

  cout << ans;
}


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

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;

using ll  = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rep1r(i, n) for (int i = ((int)(n)); i > 0; --i)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

struct Point {
    double x, y;
};

void koch(int n, Point a, Point b) {
    cout << fixed << setprecision(4);

    if (n == 0) return;
    Point  s, t, u;
    double th = PI * 60 / 180;
    s.x       = (2 * a.x + 1 * b.x) / 3;
    s.y       = (2 * a.y + 1 * b.y) / 3;
    t.x       = (1 * a.x + 2 * b.x) / 3;
    t.y       = (1 * a.y + 2 * b.y) / 3;
    u.x       = (t.x - s.x) * cos(th) - (t.y - s.y) * sin(th) + s.x;
    u.y       = (t.x - s.x) * sin(th) + (t.y - s.y) * cos(th) + s.y;
    koch(n - 1, a, s);
    cout << s.x << " " << s.y << endl;
    koch(n - 1, s, u);
    cout << u.x << " " << u.y << endl;
    koch(n - 1, u, t);
    cout << t.x << " " << t.y << endl;
    koch(n - 1, t, b);
}

int main() {
    cout << fixed << setprecision(4);

    int   n;
    Point a, b;
    cin >> n;
    a.x = 0;
    a.y = 0;
    b.x = 100;
    b.y = 0;
    cout << a.x << " " << a.y << endl;
    koch(n, a, b);
    cout << b.x << " " << b.y << endl;
    return 0;
}



Measured memory_bytes: 3216
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<set>
#include<map>
#include<stack>
#include<queue>

using namespace std;

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

#define PRINT(str) printf(#str "\n")
#define yOUT PRINT(Yes)
#define nOUT PRINT(No)
#define YOUT PRINT(YES)
#define NOUT PRINT(NO)
 
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

int main(){
	vector<int> a(5);
	REP(i,5) cin >> a[i];
	sort(all(a));
	int k; cin >> k;
	if(a[4] - a[0] > k) cout << ":(" << endl;
	else PRINT(Yay!);
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;

namespace ConsoleApp2
{
	class Program
	{
		static void Main(string[] args)
		{
			var s = Console.ReadLine();
			GetAnswer(s);
		}

		public static void GetAnswer(string s)
		{
			s = s.Replace("BC", "X");
			var regex = new Regex("[AX]+");
			var matches = regex.Matches(s);
			long totalCount = 0;
			foreach (Match match in matches)
			{
                string substr = match.Value;
              	int length = substr.Length;
				long aCount = 0;
				for (int i = 0; i < length; i++)
				{
					if (substr[i] == 'A')
					{
						aCount++;
					}
					else
					{
						totalCount += aCount;
					}
				}
			}
			Console.WriteLine(totalCount);
		}
	}
}

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

int main() {
    int n;
    while(std::cin >> n, n != 0) {
        std::string step;

        bool last = false; //false is floor
        bool left = false, right = false;
        int cnt = 0;
        for(int i=0; i<n; ++i) {
            std::cin >> step;

            if(step == "lu") {
                left = true;
            } else if(step == "ru") {
                right = true;
            } else if(step == "ld") {
                left = false;
            } else if(step == "rd") {
                right = false;
            }

            if(!last && left && right) {
                last = true;
                ++cnt;
            } else if(last && !left && !right) {
                last = false;
                ++cnt;
            }
        }
        std::cout << cnt << std::endl;
    }
}


Measured memory_bytes: 3152
#include <stdio.h>

#define SIZE 4500

int main(){
    int N;
    char S[SIZE] = {};
    scanf("%d%s", &N, S);
    long r, g, b;
    r = g = b = 0;
    for(int i=0; i<N; i++){
        switch(S[i]){
            case 'R': r++; break;
            case 'G': g++; break;
            case 'B': b++; break;
        }
    }
    long ans = r*g*b; //int r, g, b だと途中でオーバーフロー
    
    long i, p;
    for(i=0; i<N-2; i++){
        for(p=1; i+p+p<N; p++){
            if(S[i]!=S[i+p] && S[i]!=S[i+p+p] && S[i+p]!=S[i+p+p]){
                ans--;
            }
        }
    }

    printf("%ld\n", ans);
}

Measured memory_bytes: 1740
#include <iostream>
#include <vector>
#include <utility>
using namespace std;

int a[550][550];
int h, w;
vector<string> v;

int main()
{
    cin >> h >> w;
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            cin >> a[i][j];
        }
    }
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w - 1; j++)
        {
            if (a[i][j] % 2 == 1)
            {
                a[i][j + 1]++;
                string s = to_string(i + 1) + " " + to_string(j + 1) + " " + to_string(i + 1) + " " + to_string(j + 2);
                v.push_back(s);
            }
        }
    }
    for (int i = 0; i < h - 1; i++)
    {
        if (a[i][w - 1] % 2 == 1)
        {
            a[i + 1][w - 1]++;
            string s = to_string(i + 1) + " " + to_string(w) + " " + to_string(i + 2) + " " + to_string(w);
            v.push_back(s);
        }
    }
    cout << v.size() << endl;
    for (int i = 0; i < v.size(); i++)
    {
        cout << v[i] << endl;
    }
}

Measured memory_bytes: 12020
card_num = int(input())
card_list = input().split()
card_list = list(map(int, card_list))
# print(card_list)
card_list.sort(reverse = True)
# print(card_list)

Alice = 0
Bob = 0
for i, j in enumerate(card_list):
    if (i + 1) % 2 == 0:
        Bob += j
    else:
        Alice += j

# print(Alice ,Bob)
diff = abs(Alice - Bob)
print(diff)


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

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

using namespace std;

const int MAX = 310;
const long long INF = 1LL << 50;

long long G[MAX][MAX];
using pll = pair<long long, long long>;

int main(void) {
    int N, M;
    long long L;
    cin >> N >> M >> L;

    rep(i, MAX) {
        rep(j, MAX) G[i][j] = INF;
        G[i][i] = 0;
    }

    rep(i, M) {
        int a, b;
        long long c;
        cin >> a >> b >> c;
        --a;
        --b;
        G[a][b] = G[b][a] = c;
    }

    vector<vector<pll>> dist(N, vector<pll>(N, {INF, INF}));
    rep(s, N) {
        dist[s][s] = {0, 0};
        priority_queue<
                pair<pll, int>,
                vector<pair<pll, int>>,
                greater<pair<pll, int>>> que;

        que.push(make_pair(pll(0, 0), s));
        while (!que.empty()) {
            auto p = que.top();
            que.pop();

            long long v = p.second;
            long long kaisuu = p.first.first;
            long long used = p.first.second;

            if (p.first > dist[s][v])continue;

            rep(nv, N) {
                if (nv == v) continue;
                if (G[v][nv] > L) continue;

                long long nused = used + G[v][nv];
                pll np = {0, 0};
                if (nused > L) {
                    np = {kaisuu + 1, G[v][nv]};
                } else {
                    np = {kaisuu, nused};
                }

                if (dist[s][nv] > np) {
                    dist[s][nv] = np;
                    que.push(make_pair(np, nv));
                }
            }

        }
    }

    int Q;
    cin >> Q;
    while (Q--) {
        int a, b;
        cin >> a >> b;
        --a;
        --b;

        long long res = dist[a][b].first;
        if (res >= INF) {
            cout << -1 << endl;
        } else {
            cout << res << endl;
        }
    }
}


Measured memory_bytes: 3936
#include<bits/stdc++.h>
#include<algorithm>
#define ll long long
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

using namespace std;
int main()
{
    fast_io
    ll t,i,j,n,r,g,b,k,opt;
    cin>>r>>g>>b>>k;
    opt=0;
    while(g<=r){
        opt++; g*=2;
    }    while(b<=g){
        opt++; b*=2;
    }
    if(opt<=k)
        cout<<"Yes"<<endl;
    else    cout<<"No"<<endl;


    return 0;
}





Measured memory_bytes: 3616
S = input()
i = len(S)
w1 = 'dream'
w2 = 'dreamer'
w3 = 'erase'
w4 = 'eraser'
a,b,c,d = 0,5,2,1
answer = ''
flag = True

while flag:
    if S[a:b] == w1:
        if i == b :
            answer = 'YES'
            break
        elif S[a:b + c] == w2:
            if i == b + c:
                answer = 'YES'
                break
            
            if S[b :b + 5] == w3:
                if i == b + 5 :
                    answer = 'YES'
                    break
                if S[b :b + 6] == w4:
                    if i == b + 6:
                        answer = 'YES'
                        break
                    a += len(w4)+len(w1)
                    b += len(w4)+len(w1)
                    
                else:
                    a += len(w3)+len(w1)
                    b += len(w3)+len(w1)
            
            else:
                a += len(w2)
                b += len(w2)
        else:
            a += len(w1)
            b += len(w1)
    elif S[a:b] == w3:
        if i == b :
            answer = 'YES'
            break

        if S[a:b + d] == w4:
            if i == b + d :
                answer = 'YES'
                break
            a += len(w4)
            b += len(w4)
        else:
            a += len(w3)
            b += len(w3)
    else:
        answer = 'NO'
        break

print(answer)

Measured memory_bytes: 3444
package main

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

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() []int {
	n := readInt()
	return readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func minInt(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func minUint(a, b uint) uint {
	if a < b {
		return a
	}
	return b
}

func minInt64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func minUint64(a, b uint64) uint64 {
	if a < b {
		return a
	}
	return b
}

func maxInt(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func maxUint(a, b uint) uint {
	if a < b {
		return b
	}
	return a
}
func maxInt64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func maxUint64(a, b uint64) uint64 {
	if a < b {
		return b
	}
	return a
}

func absInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func absInt64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int
func solve(a []int) string {
	var rec func(x []int, acm int, op []string) (string, bool)
	rec = func(x []int, acm int, op []string) (string, bool) {
		if len(x) == 0 {
			if acm == 7 {
				return fmt.Sprintf("%d%s%d%s%d%s%d=7", a[0], op[0], a[1], op[1], a[2], op[2], a[3]), true
			}
			return "", false
		}

		s, ok := rec(x[1:], acm+x[0], append(op, "+"))
		if ok {
			return s, ok
		}
		s, ok = rec(x[1:], acm-x[0], append(op, "-"))
		return s, ok
	}

	s, _ := rec(a[1:], a[0], []string{})
	return s
}

func main() {
	defer stdout.Flush()

	s := readString()
	sb := []byte(s)
	a := int(sb[0] - '0')
	b := int(sb[1] - '0')
	c := int(sb[2] - '0')
	d := int(sb[3] - '0')

	println(solve([]int{a, b, c, d}))
}


Measured memory_bytes: 640
n = int(input())
s = list(input())

ans = 0
for i in range(n-1):
  x = s[:i+1]
  y = s[i+1:]
  count = 0
  
  for j in range(len(x)):
    if (x[j] in y) and not(x[j] in x[:j]) :
      count += 1
  
  
  if ans < count:
    ans = count
  

print(ans)  

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF (1ll << 60)
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
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;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

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

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    int N,M;
    cin>>N;
    map<string,int> m1,m2;
    for(int i=0;i<N;i++){
        string s;
        cin>>s;
        m1[s]++;
    }
    cin>>M;
    for(int i=0;i<M;i++){
        string s;
        cin>>s;
        m2[s]++;
    }
    int ans=0;
    for(auto p : m1){
        string s=p.first;
        int tmp=m1[s]-m2[s];
        ans=max(ans,tmp);
    }
    cout<<ans<<endl;
    
}

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

int main(){long N;
cin >> N;
vector<long> l(N + 1);
l.at(0) = 2;
l.at(1) = 1;
for(int i = 2; i <= N; i++){
    l.at(i) = l.at(i - 1) + l.at(i - 2);
}
long ans = l.at(N);

cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define endl "\n"
#define pb push_back
#define ll long long
#define d1(x)  cerr << #x << "--> " << x << endl
#define d2(x,y)  cerr << #x << "--> " << x << " | " << #y << "--> " << y <<endl
#define d3(x,y,z)  cerr << #x << "--> " << x << " | " << #y << "--> " << y <<" | " << #z << "--> "<< z<< endl
#define d4(x,y,z,w)  cerr << #x << "--> " << x << " | " << #y << "--> " << y <<" | " << #z << "--> "<< z << " | "<< #w << "--> " << w <<endl
#define vpll vector<pair<ll,ll>>
#define F first
#define S second
#define T ll tt; cin>>tt; while(tt--)
using namespace std;
ll mode=1e9+7;
const long long maxn=2*1e5+10;
const long long inf=99999999999;
ll lcm(ll a, ll b){ return (a*b)/__gcd(a,b); }
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll getRand(ll l, ll r){ uniform_int_distribution<ll> uid(l, r); return uid(rng); }

ll power(ll x, ll y){  
	ll p=mode, res=1;
    x = x % p;
    while (y > 0) {  
        if (y & 1)  
            res = (res*x) % p;  
        y = y>>1;
        x = (x*x) % p;  
    }  
    return res;  
}

ll up[maxn][63];

void solve(){
	
	ll n,k;
	cin>>n>>k;
	vector<ll> go(n+1);
	
	for (int i=1;i<=n;i++){
		ll x;
		cin>>x;
		go[i]=x;
		up[i][0]=x;
	}
	
	for (int i=1;i<63;i++){
		for (int j=1;j<=n;j++){
			up[j][i]=up[up[j][i-1]][i-1];
		}
	}
	
	
	
	vector<ll> pos;
	ll ind=0;
	while(k){
		if (k&(1ll)){
			pos.pb(ind);
		}
		k/=2;
		ind++;
	}
	ll ans=1;
	for (auto i:pos){
		ans=up[ans][i];
	}
	cout<<ans<<endl;
	
	
	
	
	return;
}
 
int main(){ 
    
    #ifndef ONLINE_JUDGE
		//freopen("input.txt", "r", stdin);
    #endif
    srand(time(0)); 
    
    ios::sync_with_stdio(0);
    cin.tie(0);
 	
	//T{ solve(); }
	solve();
	
	return 0;
}


Measured memory_bytes: 103288
L=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
K=int(input())
ans=L[K-1]
print(ans)

Measured memory_bytes: 2940
h,w,k=map(int,input().split())
field = [list(input()) for j in range(h)]
dp = [[float('inf') for i in range(w)]for j in range(h)]
    

check = 0
for y in range(h):
    for x in range(w):
        if field[y][x]=='#':
            check+=1
            dp[y][x]=check
            nx = x+1
            while nx < w:
                if field[y][nx]=='#':
                    break
                if dp[y][nx]!=float('inf'):
                    break
                dp[y][nx] = check
                nx+=1
            nx = x-1
            while nx >= 0:
                if field[y][nx]=='#':
                    break
                if dp[y][nx]!=float('inf'):
                    break
                dp[y][nx] = check
                nx-=1
for y in range(h):
    for x in range(w):
        if dp[y][x] == float('inf'):
            ny = y+1
            length = 1
            temp = 0
            while ny < h:
                if dp[ny][x]==float('inf'):
                    ny+=1
                    length+=1
                else:
                    temp = dp[ny][x]
                    while length >0:
                        ny-=1
                        dp[ny][x]=temp
                        length-=1
                    break
                if ny ==h:
                    ny = y-1
                    length = 1
                    temp= 0
                    while ny >=0:
                        if dp[ny][x]==float('inf'):
                            ny-=1
                            length+=1
                        else:
                            temp = dp[ny][x]
                            while length>0:
                                ny+=1
                                dp[ny][x]=temp
                                length-=1
                            break
        if y==h-1 and dp[y][x] == float('inf'):
            ny = y-1
            length = 1
            temp= 0
            while ny >=0:
                if dp[ny][x]==float('inf'):
                    ny-=1
                    length+=1
                else:
                    temp = dp[ny][x]
                    while length>0:
                        ny+=1
                        dp[ny][x]=temp
                        length-=1
                    break
for i in dp:
    temp =[]
    for j in i:
        temp.append(str(j))
    print(' '.join(temp))


Measured memory_bytes: 52444
N = int(input())
F = [list(map(int, input().split())) for _ in range(N)]
P = [list(map(int, input().split())) for _ in range(N)]

ans = -(1<<30)
for b in range(1, (1<<10)):
    tmp = 0
    for i in range(N):
        cnt = 0
        for j in range(10):
            if (b>>j&1) and F[i][j]:
                cnt += 1
        tmp += P[i][cnt]
    ans = max(ans, tmp)

print(ans)


Measured memory_bytes: 3064
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,j,n) for(int i = j; i < n; i++)
#define rrep(i,j,n) for(int i = j-1; i >= n; i--)
#define prec(n) fixed << setprecision(n)
#define print_array(v) rep(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define acc(v) accumulate(v.begin(), v.end(),0);
#define MOD 1e+7
#define inf 1e9
#define fi first
#define se second
using namespace std;

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

  int n, k;
  cin >> n >> k;
  map<int, int> mp;
  vector<pair<int, int>> vec(0);

  rep(i,n) {
    int a;
    cin >> a;
    mp[a]++;
  }

  int kind = (int)mp.size() - k;
  if(kind <= 0) { cout << 0 << endl; return 0; }
  for(auto p : mp) {
    int a = p.fi;
    int b = p.se;
    vec.push_back(make_pair(b, a));
  }
  sort(vec.begin(), vec.end());

  int res = 0;
  rep(i,kind) res += vec[i].fi;

  cout << res << endl;

  return 0;
}
//templete by private_yusuke

Measured memory_bytes: 11764
paper = [[0 for i in range(10)] for j in range(10)]

def drop(x,y):
    global paper
    if 0 <= x < 10 and 0<= y < 10:
        paper[y][x] += 1
    return

def ink(x,y,s):
    drop(x,y)
    drop(x+1,y); drop(x,y+1)
    drop(x-1,y); drop(x,y-1)
    if s == 1: return
    drop(x+1,y+1); drop(x+1,y-1)
    drop(x-1,y+1); drop(x-1,y-1)
    if s == 2: return
    drop(x+2,y); drop(x,y+2)
    drop(x-2,y); drop(x,y-2)
    return

while True:
    try:
        x, y, s = map(int, raw_input().split(","))
        ink(x,y,s)
    except:
        break

print sum([i.count(0) for i in paper])
print max([max(i) for i in paper])

Measured memory_bytes: 4272
package main

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

func main() {
	scanner := makeWordScanner()
	n := eGetInt(scanner)
	as := make([]int, n)
	for i := 0; i < n; i++ {
		as[i] = eGetInt(scanner)
	}
	asCopy := make([]int, n)
	copy(asCopy, as)
	sort.Ints(asCopy)

	max := asCopy[len(asCopy)-1]
	max2nd := asCopy[len(asCopy)-2]

	for i := 0; i < n; i++ {
		if as[i] == max {
			fmt.Println(max2nd)
		} else {
			fmt.Println(max)
		}
	}
}

////////////////////////////////////////////////////////////////////////////////
// ライブラリ
////////////////////////////////////////////////////////////////////////////////
func makeScanner(maxByte int) *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]uint8, 0, 8192), maxByte)
	return scanner
}
func makeWordScanner() *bufio.Scanner {
	scanner := makeScanner(8192)
	scanner.Split(bufio.ScanWords)
	return scanner
}
func eGetLine(r *bufio.Scanner) string {
	if r.Scan() {
		return r.Text()
	}
	err := r.Err()
	if err != nil {
		log.Fatal(err)
	}
	// EOF
	return ""
}
func eGetInt(r *bufio.Scanner) int {
	line := eGetLine(r)
	return eAtoi(line)
}
func eGetInt64(r *bufio.Scanner) int64 {
	line := eGetLine(r)
	return eAtoInt64(line)
}
func eGetFields(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Fields(line)
}
func eGetInts(r *bufio.Scanner) []int {
	fields := eGetFields(r)
	ints := make([]int, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoi(fields[i])
	}
	return ints
}
func eGetInt64s(r *bufio.Scanner) []int64 {
	fields := eGetFields(r)
	ints := make([]int64, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoInt64(fields[i])
	}
	return ints
}
func eGetChars(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Split(line, "")
}
func eAtoi(s string) int {
	n, err := strconv.Atoi(s)
	if err != nil {
		log.Fatal(err)
	}
	return n
}
func eAtoInt64(s string) int64 {
	n, err := strconv.ParseInt(s, 10, 64)
	if err != nil {
		log.Fatal(err)
	}
	return n
}


Measured memory_bytes: 6912
from collections import defaultdict, deque
n, m = map(int, input().split())
outs = defaultdict(list)
rv = defaultdict(list)
ins = defaultdict(int)
for i in range(m):
    x, y = map(int, input().split())
    outs[x].append(y)
    rv[y].append(x)
    ins[y] += 1
q = deque(i for i in range(1, n + 1) if ins[i] == 0)
ans = []
while q:
    st = q.popleft()
    ans.append(st)
    for to in outs[st]:
        ins[to] -= 1
        if ins[to] == 0:
            q.append(to)

dp = [0] * (n + 1)
for value in ans:
    dp[value] += max([0]+[dp[i]+1 for i in rv[value]])
print(max(dp))

Measured memory_bytes: 109272
n,m=map(int, input().split())
ab=[list(map(int, input().split())) for _ in range(m)]
graph=[[False for _ in range(n)] for _ in range(n)]
visited=[False for _ in range(n)]
visited[0]=True

for x in ab:
    graph[x[0]-1][x[1]-1]=True
    graph[x[1]-1][x[0]-1]=True
def dfs(v,n,visited):
    all_visited=True
    for i in range(n):
        if visited[i]==False:
            all_visited=False
    if all_visited:
        return 1
    ret=0
    for i in range(n):
        if graph[v][i]==False:
            continue
        if visited[i]:
            continue
        visited[i]=True
        ret+=dfs(i,n,visited)
        visited[i]=False
    return ret
print(dfs(0,n,visited))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define REP(i,n) for (ll i = 0; i < (n); ++i)

string n;

array<vector<ll>, 2> dp;
array<vector<bool>, 2> flag;

ll solve(ll pos, ll state){
    if(flag.at(state).at(pos)){
        return dp.at(state).at(pos);
    }

    ll d = n.at(pos) - '0';
    if(state == 1){
        d = 10 - d;
    }
    ll ret = 0;
    if(state == 0){
        if(pos == n.size() - 1){
            if(d <= 5){
                ret = d;
            }else{
                ret = 1 + solve(pos, 1 - state);
            }
        }else{
            ret = d + solve(pos + 1, state);
            ret = min(
                ret,
                d + 1 + solve(pos + 1, 1 - state)
            );
        }
    }else{
        if(pos == n.size() - 1){
            if(d <= 5){
                ret = d;
            }else{
                ret = 1 + solve(pos, 1 - state);
            }
        }else{
            assert(d > 0);
            ret = d - 1 + solve(pos + 1, state);
            ret = min(
                ret,
                d + solve(pos + 1, 1 - state)
            );
        }
    }
    flag.at(state).at(pos) = true;
    dp.at(state).at(pos) = ret;
    return ret;
}

int main(){
    cin >> n;
    const ll l = n.size();
    // n = "1";
    // REP(i, 1000000){
    //     n += '0';
    // }
    REP(i, 2){
        dp.at(i).resize(n.size());
        flag.at(i).resize(n.size());
        fill(flag.at(i).begin(), flag.at(i).end(), false);
    }

    // // pos == n.size() - 1;
    // const ll d = n.at(0) - '0';
    // if(d <= 5){
    //     dp.at(0).at(l - 1) = d;
    //     dp.at(1).at(l - 1) = 1 + dp.at(0).at(l - 1);
    // }else{
    //     dp.at(1).at(l - 1) = 10 - d;
    //     dp.at(0).at(l - 1) = 1 + dp.at(1).at(l - 1);
    // }

    // for(ll pos = n.size() - 2; pos >= 0; --pos){
    //     // state == 0
    //     ll d = n.at(pos) - '0';
    //     dp.at(0).at(pos) = min(
    //         d + dp.at(0).at(pos + 1),
    //         d + 1 + dp.at(1).at(pos + 1)
    //     );

    //     // state == 1
    //     d = 10 - d;
    //     dp.at(1).at(pos) = min(
    //         d - 1 + dp.at(1).at(pos + 1),
    //         d + dp.at(0).at(pos + 1)
    //     );
    // }
    ll ans = min(solve(0, 0), 1 + solve(0, 1));
    // ll ans = min(dp.at(0).at(0), 1 + dp.at(1).at(0));
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 110852
#include <bits/stdc++.h>
#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mod 1000000007
using namespace std;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int a[] = {0, 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	int k;
	cin>>k;
	cout<<a[k]<<endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
h = list(map(int, input().split(" ")))
result = 1

for i in range(n):
  viewable = False
  for j in range(i):
    if h[j] > h[i]:
      break
    elif j == i - 1:
      viewable = True
      
  if viewable == True:
    result += 1

print("{}".format(result))

Measured memory_bytes: 3060
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <bitset>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <queue>


typedef long long ll;
typedef long double ld;

using namespace std;


int n;
int a[120];
int main() {
	cin >> n;
	for (int i = 0; i < n; ++i)
		cin >> a[i];
	int ans = 100 * 100 * 100 * 100;
	for (int x = -100; x <= 100; ++x) {
		int sum = 0;
		for (int i = 0; i < n; ++i)
			sum += (a[i] - x) * (a[i] - x);
		ans = min(ans, sum);
	}
	cout << ans << "\n";
	return 0;
}




Measured memory_bytes: 256
N, M = map(int, input().split())
bulbs = []
for i in range(M):
    k, *s = map(int, input().split())
    bulbs.append((k, s))
p = list(map(int, input().split()))

ans = 0
for i in range(1 << N):
    on_cnt = [0] * M
    for j in range(N):
        if i >> j & 1:
            for k in range(M):
                if j + 1 in bulbs[k][1]:
                    on_cnt[k] ^= 1
    if on_cnt == p:
        ans += 1
print(ans)


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

using namespace std;

int main() {
    string s, head, tail;
    cin >> s;

    int q;
    scanf("%d", &q);

    int mode = 0;

    while (q--) {
        int t;
        scanf("%d", &t);

        if (t == 1) {
            mode ^= 1;
        }
        else {
            int x;
            char c;
            scanf("%d%c%c", &x, &c, &c);

            x--;

            if (x ^ mode == 0) head += c;
            else tail += c;
        }
    }

    if (mode == 0) {
        reverse(head.begin(), head.end());
        cout << head << s << tail << endl;
    }
    else {
        reverse(tail.begin(), tail.end());
        reverse(s.begin(), s.end());
        cout << tail << s << head << endl;
    }
}


Measured memory_bytes: 3980
void main(){
  import std.stdio, std.string, std.conv, std.algorithm;

  int n, m; rd(n, m);
  auto a=readln.split.to!(int[]);

  auto b=new int[](n);
  foreach(e; a) b[e-1]=1;
  int c=0;
  bool f(){
    return reduce!((r, e)=>(r && e==1))(true, b[0..m]);
  }
  foreach_reverse(i; 0..n){
    if(f()) break;
    if(b[i]){
      foreach(j; 0..n){
        if(b[j]==0){
          swap(b[j], b[i]);
          break;
        }
      }
      c++;
    }
  }
  writeln(c);
}

void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  assert(l.length==x.length);
  foreach(i, ref e; x) e=l[i].to!(typeof(e));
}



Measured memory_bytes: 2484
#include<iostream>

long long calc_sum(int n, int a[]){
	long long sum=0;
	for(int i=0; i<n; i++) {
		sum += a[i];
	}
	return sum;
}

int seek_answer(int n, int a[], int minmax[]){
	minmax[0] = a[0];
	minmax[1] = a[0];
	for(int i=1; i<n; i++) {
		if(minmax[0] > a[i]) {
			minmax[0] = a[i];
		}
		if(minmax[1] < a[i]) {
			minmax[1] = a[i];
		}
	}
}


int main()
{
	int n;
	std::cin >> n;
	int a[n];
	for(int i=0; i<n; i++) {
		std::cin >> a[i];
	}
	long long sum;
	int minmax[2]; 
	sum = calc_sum(n, a);
	seek_answer(n, a, minmax);
	std::cout << minmax[0] << " " << minmax[1] << " " << sum << std::endl;

	return 0;
}

Measured memory_bytes: 1204
using System;
using System.Collections.Generic;
using System.Linq;

namespace CSharp
{
    class Program
    {
        static void Main(string[] args)
        {
            var inputs = Console.ReadLine()
                .Split(' ')
                .Select(s => int.Parse(s))
                .ToArray();
            var lower = inputs[0];
            var upper = inputs[1];
            var range = upper - lower;
            //
            var minMod = 2019;
            foreach (var i in Enumerable.Range(0, 2019))
            {
                foreach (var j in Enumerable.Range(i + 1, 2019 - i - 1))
                {
                    var residual = i * j % 2019;
                    if (residual >= minMod) continue;
                    var lhs = lower - i;
                    var rhs = upper - j;
                    if (Has2019Multiple(lhs, rhs)) minMod = residual;
                }
            }
            Console.WriteLine(minMod);
        }
        static bool Has2019Multiple(int from, int to)
        {
            for (var i = from; i <= to; i++)
            {
                if (i % 2019 == 0) return true;
            }
            return false;
        }
    }
}


Measured memory_bytes: 13396
// tested by Hightail - https://github.com/dj3500/hightail
import std.stdio, std.string, std.conv, std.algorithm;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;

int r, c, n;

void main() {
    scan(r, c, n);

    long x1, y1, x2, y2;

    alias Point = Tuple!(long, "d", int, "idx");

    auto p = new Point[](0);

    foreach (i ; 0 .. n) {
        scan(x1, y1, x2, y2);

        if (ontheEdge(x1, y1) && ontheEdge(x2, y2)) {
            if (x1 == 0 || y1 == c) {
                p ~= Point(x1 + y1, i);
            }
            else {
                p ~= Point(2L * r + 2L * c - x1 - y1, i);
            }

            if (x2 == 0 || y2 == c) {
                p ~= Point(x2 + y2, i);
            }
            else {
                p ~= Point(2L * r + 2L * c - x2 - y2, i);
            }
        }
    }

    p.sort();

    debug {
        writeln(p);
    }

    auto st = Stack!int(n + 10);

    foreach (i ; 0 .. p.length.to!int) {
        if (st.empty || st.top != p[i].idx) {
            st.push(p[i].idx);
        }
        else {
            st.pop();
        }
    }

    if (st.empty) {
        writeln("YES");
    }
    else {
        writeln("NO");
    }
}

bool ontheEdge(long x, long y) {
    return x == 0 || x == r || y == 0 || y == c;
}


void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}


struct Stack(T) {
private:
    int N, peek;
    T[] data;

public:
    this(int size) 
    {
        N = size;
        data = new T[](N);
    }

    bool empty() @property
    {
        return peek == 0;
    }

    bool full() @property
    {
        return peek == N;
    }

    void push(T x) @property
    {
        assert(!full);
        data[peek++] = x;
    }

    void pop() @property
    {
        assert(!empty);
        --peek;
    }

    T top() @property
    {
        return data[peek - 1];
    }

    void clear() @property
    {
        peek = 0;
    }

    int length() @property
    {
        return peek;
    }

}

Measured memory_bytes: 5372
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#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() {
  int x;
  cin >> x;
  ll ans = 0;
  ll a = x / 500;
  ans += a * 1000;
  x -= a * 500;
  a = x / 5;
  ans += a * 5;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H,W;
  cin >> H >> W;
  vector<string>vec(H);
string O;
  O = "##";
  for(int i=0; i<W; i++){
    O+="#";}
  cout << O <<endl; 
  for(int j=0;j<H;j++){
    cin>> vec.at(j);
    cout << '#'+vec.at(j)+'#'<< endl;
  }
  cout << O << endl;
}

Measured memory_bytes: 3628
N,M = list(map(int,input().split()))

H = list(map(int,input().split()))

e_list = [[] for i in range(N)]

for i in range(M):
    a,b = list(map(int,input().split()))
    a,b = a-1,b-1
    e_list[a].append(b)
    e_list[b].append(a)
count = 0
for i in range(N):
    flag=True
    for v in e_list[i]:
        if H[i]<=H[v]:
            flag=False
            break
    if flag:
        count+=1

print(count)

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

using namespace std;

int main()
{
	int N, K, A;
	int i;
	cin >> N >> K;
	for(i = 0; i < N; i++) cin >> A;
	int r; 
	if(N <= K) {
		r = 1;
	} else {
		r = (N - 1) / (K - 1);
		if((N - 1) % (K - 1) > 0) r++;
	}
	cout << r << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int a,b,c,k,d=0;
  scanf("%d %d %d %d",&a, &b, &c, &k);
  
  if (a >= k)
    d = k;
  else if (a + b >= k)
    d = a;
  else
    d = 2*a + b - k;
  
  printf("%d",d);
  
  return 0;
}

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

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String s = scan.next();
		ArrayList<Character> c = new ArrayList<Character>();
		for (int i = 0; i < s.length(); i++) {
			c.add(s.charAt(i));
		}
		Collections.reverse(c);
		boolean f = true;
		int i = 0;
		while(f) {
			if ((c.get(i) == 'm') && (c.get(i+1) == 'a') && (c.get(i+2) == 'e') && (c.get(i+3) == 'r') && (c.get(i+4) == 'd')) {
				i += 5;
				if (i >= s.length()) break;
				continue;
			}
			if ((c.get(i) == 'e') && (c.get(i+1) == 's') && (c.get(i+2) == 'a') && (c.get(i+3) == 'r') && (c.get(i+4) == 'e')) {
				i += 5;
				if (i >= s.length()) break;
				continue;
			}
			if ((c.get(i) == 'r') && (c.get(i+1) == 'e') && (c.get(i+2) == 'm') && (c.get(i+3) == 'a') && (c.get(i+4) == 'e') && (c.get(i+5) == 'r') && (c.get(i+6) == 'd')) {
				i += 7;
				if (i >= s.length()) break;
				continue;
			}
			if ((c.get(i) == 'r') && (c.get(i+1) == 'e') && (c.get(i+2) == 's') && (c.get(i+3) == 'a') && (c.get(i+4) == 'r') && (c.get(i+5) == 'e')) {
				i += 6;
				if (i >= s.length()) break;
				continue;
			}
			f = false;
		}
		if (f) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
}


Measured memory_bytes: 28576