akhauriyash/Code-Regression huggingface dataset:
{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE LambdaCase #-}
module Main where

import           Data.List
import           Control.Monad
import           Debug.Trace
import qualified Data.ByteString.Char8         as BC
import           Data.Maybe                     ( fromJust )
import qualified Data.Set                      as S
import qualified Data.IntMap.Strict            as IM
import qualified Data.IntMap.Lazy            as IML
import qualified Data.Map.Strict               as M
import           Data.Char
import qualified Data.Array.IArray as A
import qualified Data.Array.Unboxed as UA
import Data.Bits
import Control.Monad.State.Strict
import qualified Data.Array.ST as STA
import qualified Data.Array.MArray as MA
import Control.Monad.ST



readTuple2 :: IO (Int, Int)
readTuple2 = do
    [a, b] <- readInts
    return (a, b)

readTuple3 :: IO (Int, Int, Int)
readTuple3 = do
    [a, b, c] <- readInts
    return (a, b, c)

readInt :: IO Int
readInt = fst . fromJust . BC.readInt <$> BC.getLine

readInts :: IO [Int]
readInts = map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine

split :: (a -> Bool) -> [a] -> [[a]]
split f [] = []
split f as =
    let (fo, la) = span f as
        las      = case la of
            [] -> []
            xs -> split f $ tail xs
    in  case fo of
            [] -> las
            xs -> xs : las

newtype MyGraph = MyGraph (A.Array Int [Int])

listToGraph :: Int -> [(Int, Int)] -> MyGraph
listToGraph n paths = MyGraph $ STA.runSTArray $ do
    a <- MA.newArray (1, n) []
    forM_ paths $ \(from, to) -> do
        f <- MA.readArray a from
        MA.writeArray a from $ to : f
        t <- MA.readArray a to
        MA.writeArray a to $ from : t
    pure a

getPaths :: Int -> MyGraph -> [Int]
getPaths i (MyGraph lst) = lst A.! i

solve :: Int -> [Int] -> [(Int, Int)] -> Int
solve n heights paths = let 
    hs :: UA.UArray Int Int 
    hs = A.listArray (1, n) heights
    grp = listToGraph n paths
    isGood i = case getPaths i grp of
        [] -> True
        paths -> let
            mine = hs A.! i
            in
            all ((mine>) . (hs A.!)) paths
    in 
    length $ filter isGood [1..n]


main :: IO ()
main = do
    (n, m) <- readTuple2
    heights <- readInts
    paths <- replicateM m readTuple2
    print $ solve n heights paths





Measured memory_bytes: 46600
/*
    なせば大抵なんとかなる！
*/

#define VERNIY st();int ver=0,niy=0

#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <limits.h>
#include <float.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <iterator>
#include <vector>
#include <map>
#include <queue>
#include <utility>
#include <functional>
#define LLU unsigned long long int
#define LL long long int
using namespace std;
#define Lfmax DBL_MAX
#define LLUmax ULLONG_MAX
#define LLmax LLONG_MAX
#define dmax INT_MAX
#define vd vector<int>
#define vpd vector<pair<int,int>>
#define vLL vector<long long int>
#define vpLL vector<pair<long long int,long long int>>
#define vLLU vector<unsigned long long int>
#define vpLLU vector<pair<unsigned long long int,unsigned long long int>>
#define pd pair<int,int>
#define pLL pair<long long int,long long int>
#define pLLU pair<unsigned long long int,unsigned long long int>
#define qd queue<int>
#define qpd queue<pair<int,int>>
#define maxpqd priority_queue<int>
#define minpqd priority_queue<int, vector<int>, greater<int>>
#define fr front
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define debugarr(a,b) for(int i=0 ; i<b ; i++)printf("%d ",a[i]);printf("\n")
#define newline printf("\n")
#define forin(a,b,c) for(int a=b ; a<c ; a++)
#define forineq(a,b,c) for(int a=b ; a<=c ; a++)
#define forde(a,b,c) for(int a=b ; a>=c ; a--)
#define UPC(oo) (oo>='A' && oo<='Z')
#define LWC(oo) (oo>='a' && oo<='z')
#define DGT(oo) (oo>='0' && oo<='9')
#define UPCVOC(oo) (oo=='A' || oo=='E' || oo=='I' || oo=='U' || oo=='O')
#define LWCVOC(oo) (oo=='a' || oo=='e' || oo=='i' || oo=='u' || oo=='o')

inline void scd(int &a){scanf("%d",&a);}
inline void scdd(int &a,int &b){scanf("%d %d",&a,&b);}
inline void sctd(int &a,int &b,int &c){scanf("%d %d %d",&a,&b,&c);}
inline void sctlld(LL &a,LL &b,LL &c){scanf("%I64d %I64d %I64d",&a,&b,&c);}
inline void scdlld(LL &a,LL &b){scanf("%I64d %I64d",&a,&b);}
inline void sclld(LL &a){scanf("%I64d",&a);}
inline void scllu(LLU &a){scanf("%I64u",&a);}
inline void scdllu(LLU &a,LLU &b){scanf("%I64u %I64u",&a,&b);}
inline void sctllu(LLU &a,LLU &b,LLU &c){scanf("%I64u %I64u %I64u",&a,&b,&c);}

template<class Ver>
inline void prd(Ver a){cout<<a<<endl;};
template<class Ver>
inline void prdd(Ver a,Ver b){cout<<a<<" "<<b<<endl;};
template<class Ver>
inline void prtd(Ver a, Ver b, Ver c){cout<<a<<" "<<b<<" "<<c<<endl;};

inline void debug(){printf("asd\n");}
template<class Ver>
inline void debugd(Ver a){cout<<"--- "<<a<<endl;};
template<class Ver>
inline void debugdd(Ver a,Ver b){cout<<"--- "<<a<<" "<<b<<endl;};
template<class Ver>
inline void debugtd(Ver a,Ver b,Ver c){cout<<"--- "<<a<<" "<<b<<" "<<c<<endl;};

#define grav 9.8
#define pi 3.14159265

void st()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
}

int main()
{
	VERNIY;
	int hbk;
	sctd(ver,niy,hbk);
	ver=(ver*100)+(niy*10)+hbk;
	if(ver%4==0)
	printf("YES");
	else
	printf("NO");

	return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const int N = 100005;
ll x[N], v[N], f[N], b[N], ff[N], bb[N];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	int n; ll c;
	cin>>n>>c;
	for(int i = 1; i <= n; i++){
		cin>>x[i]>>v[i];
	}
	x[0] = 0; x[n + 1] = c;
	{
		f[0] = 0; ll cur = 0;
		for(int i = 1; i <= n; i++){
			cur += v[i] - (x[i] - x[i - 1]);
			f[i] = max(f[i - 1], cur);
		}
	}
	{
		b[n + 1] = 0; ll cur = 0;
		for(int i = n; i >= 1; i--){
			cur += v[i] - (x[i + 1] - x[i]);
			b[i] = max(b[i + 1], cur);
		}
	}
	{
		ff[0] = 0; ll cur = 0;
		for(int i = 1; i <= n; i++){
			cur += v[i] - 2*(x[i] - x[i - 1]);
			ff[i] = max(ff[i - 1], cur);
		}
	}
	{
		bb[n + 1] = 0; ll cur = 0;
		for(int i = n; i >= 1; i--){
			cur += v[i] - 2*(x[i + 1] - x[i]);
			bb[i] = max(bb[i + 1], cur);
		}
	}
	ll ans = max(f[n], b[1]);
	for(int i = 1; i < n; i++){
		ans = max(ans, bb[i + 1] + f[i]);
		ans = max(ans, ff[i] + b[i + 1]);
	}
	cout<<ans<<'\n';

	return 0;
}

Measured memory_bytes: 4992
#include<bitset>
#include<math.h>
#include<limits.h>
#include<iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<sstream>
#include<list>
#include<queue>
#include<algorithm>
#include<functional>
#include<map>
#include<set>
#include<utility>
#include<initializer_list>
#include<tuple>
#include<regex>
using namespace std;
#define ull unsigned long long
#define ll long long
#define rep(i, a, n) for(int i=(a);i<(int)(n);i++)
#define repc(i, a, n) for(int i=(a);i<=(int)(n);i++)
#define all(t) t.begin(), t.end()
#define rall(t) t.rbegin(), t.rend()
#define mat(type, row, col, init) vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout<<(cond? "Yes":"No")<<endl;
#define YES(cond) cout<<(cond? "YES":"NO")<<endl;
#define DBG(str) cerr<<(str)<<endl;
int main() {
	int r;
	cin >> r;
	if (r < 1200)cout << "ABC";
	else if (r < 2800)cout << "ARC";
	else cout << "AGC";
	return 0;
}





Measured memory_bytes: 256
#include <stdio.h>


int main()
{
	int a, b, i, n, m, x, y, X[100], Y[100];

	scanf("%d %d %d %d", &n, &m, &x, &y);
	for (i = 0;i < n;i++) {
		scanf("%d", &X[i]);
	}
	for (i = 0;i < m;i++) {
		scanf("%d", &Y[i]);
	}

	a = X[0];
	b = Y[0];

	for (i = 0;i < n - 1;i++) {
		if (a <= X[i + 1]) {
			a = X[i + 1];
		}
	}
	for (i = 0;i < m - 1;i++) {
		if (b > Y[i + 1]) {
			b = Y[i + 1];
		}
	}
	a++;
	if (b < a) {
		printf("War\n");
	}
	else {
		if (a == b) {
			if (x < a&&a <= y) 	printf("No War\n");
			else printf("War\n");
		}
		else {
			if (y < a) {
				printf("War\n");
			}
			else {
				if (b <= x) {
					printf("War\n");
				}
				else {
					printf("No War\n");
				}
			}
		}
	}

	return 0;
}

Measured memory_bytes: 128
N,x = map(int,input().split())
A = list(map(int,input().split()))

tmp = A[0] + A[1]
red = max(0,tmp - x)
ans = red
if red > 0:
    if red <= A[1]:
        A[1] -= red
    else:
        A[0] -= red - A[1]
        A[1] = 0
tmp = A[0] + A[1]


for i in range(2,N):
    tmp += A[i]
    tmp -= A[i-2]
    
    red = max(0,tmp - x)
    ans += red
    if red > 0:
        if red <= A[i]:
            A[i] -= red
        else:
            A[i-1] -= red - A[i]
    tmp = A[i-1] + A[i]   
print(ans)


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

//#include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
// using cint = cpp_int;

// Define
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const ll MOD = 1e9 + 7;
const ll INF = LONG_MAX;
const ull MAX = ULONG_MAX;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define x first
#define y second
#define endl '\n'
#define space ' '
#define def inline auto
#define func inline constexpr ll
#define run __attribute__((constructor)) def _
#define all(v) begin(v), end(v)
#define input(a) scanf("%lld", &(a))
#define print(a) printf("%lld\n", (a))

// Debug
#define debug(...)                                                             \
    {                                                                          \
        cerr << __LINE__ << ": " << #__VA_ARGS__ << " = ";                     \
        for (auto &&X : {__VA_ARGS__}) cerr << "[" << X << "] ";               \
        cerr << endl;                                                          \
    }

#define dump(a, h, w)                                                          \
    rep(i, h) {                                                                \
        rep(j, w) cerr << a[i][j] << space;                                    \
        cerr << endl;                                                          \
    }
#define lldump(a, n) dump(vector<vector<ll>>{a}, 1, n)

// Loop
#define inc(i, a, n) for (ll i = (a), _##i = (n); i <= _##i; ++i)
#define dec(i, a, n) for (ll i = (a), _##i = (n); i >= _##i; --i)
#define each(i, a) for (auto &&i : a)
#define rep(i, n) inc(i, 0, n - 1)

// Stream
#define fout(n) cout << fixed << setprecision(n)
#define fasten cin.tie(0), ios::sync_with_stdio(0)

// Speed
run() { fasten, fout(10); }
#pragma GCC optimize("O3")
#pragma GCC optimization_level 3
#pragma GCC target("avx")

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

def in() {
    ll A;
    cin >> A;
    return A;
}

char a, b[] = {'a', 'i', 'u', 'e', 'o'};
signed main() {
    cin >> a;
    rep(i, 5) if (a == b[i]) {
        cout << "vowel" << endl;
        return 0;
    }
    cout << "consonant" << endl;
}

// for compilation: g++ -Ofast -march=native -o _ _.cpp -std=c++17


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        Main main = new Main();
        main.solve();
    }
    public void solve() throws Exception {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        long[] a_f = new long[N + 1];
        long[] a_b = new long[N + 1];
        for (int i = 0; i < N + 1; i++) {
            a_f[i] = scan.nextLong();
            a_b[i] = a_f[i];
        }
        long[] b = new long[N + 1];
        for (int i = 0; i < N; i++) {
            b[i] = scan.nextLong();
        }
        long answer = front(N, a_f, b);
        answer = Math.max(answer,back(N, a_b, b));
        System.out.println(answer);
    }
    private long front(int N, long[] a, long[] b) {
        long answer = 0;
        for (int i = 0; i < N; i++) {
            answer += Math.min(b[i],a[i]);
            long t = Math.max(0, b[i]-a[i]);
            answer += Math.min(a[i+1], t);
            a[i+1] = Math.max(0, a[i+1]-t);
        }
        return answer;
    }
    private long back(int N, long[] a, long[] b) {
        long answer = 0;
        for (int i = N-1; 0 <= i; i--) {
            answer += Math.min(b[i],a[i+1]);
            long t = Math.max(0, b[i]-a[i+1]);
            answer += Math.min(a[i], t);
            a[i] = Math.max(0, a[i]-t);
        }
        return answer;
    }
}


Measured memory_bytes: 66228
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	char a, b; cin >> a >> b;
	if (a < b)cout << '<' << endl;
	else if (a > b)cout << '>' << endl;
	else cout << '=' << endl;
	return 0;
}

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

using ll = long long;
#define REP(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}

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

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


int main() {
  string S; cin >> S;

  int N = S.size();
  vector<int> tmp;
  vector<string> str;
  ll ans = 0;
  for(int bit = 0; bit < (1 << (N - 1)); ++bit) {
    REP(i, N - 1) {
      if(bit & (1 << i)) tmp.push_back(i);
    }

    if(bit == 0) str.push_back(S);

    REP(i, tmp.size()) {
      if(i == 0) {
        if(tmp.at(0) == 0) {
          str.push_back(S.substr(0, 1));
        } else {
          str.push_back(S.substr(0, tmp.at(i) + 1));
        }
      } else {
        str.push_back(S.substr(tmp[i - 1] + 1, tmp[i] - tmp[i - 1]));
      }

      if(i == tmp.size() - 1) {
        str.push_back(S.substr(tmp.at(i) + 1));
      }
    }

    REP(i, str.size()) {
      ans += stoll(str[i]);
    }

    tmp.clear();
    str.clear();
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
  public static void main(String args[]) {
	  	Scanner scanner = new Scanner(System.in);
	  	long  a = scanner.nextInt();
	  	long  b = scanner.nextInt();
	  	long  n = 0;
        double x = 0.f;
        double y = 0.f;
        double z = 0.f;
        
        
		n = a / b;
        System.out.print(n + " ");
		n = a % b;
        System.out.print(n + " ");
        
        x = a/1000000;
        y = a%1000000;
        
        x = x / b;
        y = y / b;
        x *= 1000000;
        z = x + y;
        System.out.printf("%.6f",z);
        
        scanner.close();
  }
}


Measured memory_bytes: 26444
import java.util.*;

public class Main{
    Main(){
	Scanner sc = new Scanner(System.in);

	while(sc.hasNext()){
	    int r = sc.nextInt(), t, cnt=1, l=0;
	    if(r == 0) break;
	    int[] ary = new int[r+1];
	    
	    for(int i = 0; i < r; i++)
		ary[i] = sc.nextInt();
	    t = sc.nextInt();
	    r--;

	    for(;l <= r; cnt++){
		int v = (l+r)/2;

		if(ary[v] == t) break;
		if(ary[v] < t) l = v+1;
		else r = v-1;

		if(l > r) break;
	    }

	    System.out.println(Integer.toString(cnt));
	}
    }

    public static void main(String[] args){
	new Main();
    }
}

Measured memory_bytes: 12000
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <deque>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <utility>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

#define INF (1 << 30)
#define INFL (1LL << 62)
#define MOD7 1000000007
#define MOD9 1000000009
#define EPS 1e-10

#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pul pair<ull, ull>
#define all(a) (a).begin(), (a).end()
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);--i)
#define REP(i,n) for (int i=0;i<(n);++i)
#define RREP(i,n) for (int i=(n)-1;i>=0;--i)

void YES() { cout << "YES" << endl; }
void NO() { cout << "NO" << endl; }
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }
void yes() { cout << "yes" << endl; }
void no() { cout << "no" << endl; }
void Taka() { cout << "Takahashi" << endl; }
void Aoki() { cout << "Aoki" << endl; }
void digit(int d) { cout << fixed << setprecision(d); }
void IOup() { cin.tie(0); ios::sync_with_stdio(false); }

int main() {	

	int w;
	cin >> w;

	cout << w * 32 << endl;
	
	return 0;
}

Measured memory_bytes: 3096
#include <stdio.h>
 
typedef struct{
  char name[11];
  int time;
}process;
 
int main(){
  long long  n, q, i, j, sp, ep, stime = 0;
  process p[520000];
  scanf("%lld%lld", &n, &q);
  for(i = 0; i < n; ++i) scanf("%s%d", p[i].name, &p[i].time);
 
  sp = 0; ep = n - 1;
  while(sp <= ep){
    if(p[sp].time > q){
      stime += q;
      p[sp].time -= q;
      p[++ep] = p[sp];
    }
    else{
      stime += p[sp].time;
      printf("%s %lld\n", p[sp].name, stime);
    }
    sp++;
  }
  return 0;
}


Measured memory_bytes: 4644
n=int(input())
D=0
d=10**10
f=10**10
F=-10**10
for i in range(n):
    x,y=[int(x) for x in input().split()]
    l=x+y
    d=min(d,l)
    D=max(D,l)
    if y-x<f:
        m=[x,y]
        f=y-x
    if y-x>F:
        M=[x,y]
        F=y-x
e=abs(m[0]-M[0])+abs(m[1]-M[1])
ans=max(D-d,e)
print(ans)

Measured memory_bytes: 71088
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};



int main(){
    int n;cin >> n;
    string s;cin >> s;
    if(n%2){
        puts("No");
        return 0;
    }
    for (int i = 0; i < n/2; i++) {
        if(s[i] != s[i + n / 2]){
            puts("No");
            return 0;
        }
    }
    puts("Yes");
    return 0;
}


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



int main(){
    int K;
    char S[100];
    int i,num=0;
    int len;

    scanf("%d",&K);
    scanf("%s",S);

    len = strlen(S);

    if (len<=K){
        printf("%s\n",S);
    }else{
        for(i=0;i<K;i++){
            printf("%c",S[i]);
        }
        printf("...\n");
    }
    return 0;

}


Measured memory_bytes: 1660
#include <bits/stdc++.h>
using namespace std;
using lli = long long int;
using ulli = unsigned long long int;
#define debug(x) cerr << #x << " : " << x << endl
#define debugv(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x << ", ";}cerr << endl


namespace atcoder {
	template<typename T>
	T ncr(T left, T right) {
		right = min(left - right, right);
		T ans = 1;
		for (T i = 1; i <= right; i++) {
			ans = ans * (left - right + i) / i;
		}
		return ans;
	}

	const int MOD = 1000000007;
	const lli LIMIT = 10'000'000'000'000'000 * 5;
	const int tenfive = 100000;
}

using namespace atcoder;

int main() {
	string s;
	cin >> s;
	int r = 0, b = 0, ans = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == '0') {
			r++;
		}
		else {
			b++;
		}
		if (r > 0 && b > 0) {
			r--;
			b--;
			ans += 2;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define bFOR(i,n1,n2) for(ll i=n1;i>=n2;i--)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
const int INF=(ll)(1LL<<30)-1;
const double INFd=100000000000.0;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
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;}
int dx[4]={0,-1,0,1},dy[4]={-1,0,1,0};
int mdx[8]={0,1,0,-1,1,1,-1,-1},mdy[8]={-1,0,1,0,1,-1,1,-1};


template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

ll n;
ll a[20100],b[20100];
ll p[20100];
int main(){
	cin>>n;
	REP(i,n){
		int pq;
		cin>>pq;
		pq--;
		p[pq]=(i+1);
	}
	REP(i,n){
		a[i]=(i+1)*(3e4);
	}
	REP(i,n){
		b[n-i-1]=(i+1)*(3e4);
	}
	REP(i,n){
		b[i]+=p[i];
	}
	REP(i,n)
		cout<<a[i]<<" ";
	cout<<endl;
	REP(i,n)
		cout<<b[i]<<" ";
	cout<<endl;
	return 0;
}

Measured memory_bytes: 1152
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <utility>
#include <complex>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <tuple>
#include <bitset>
#include <limits>
#include <algorithm>
#include <array>
#include <random>
#include <complex>
#include <regex>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define fcout cout << fixed << setprecision(10)
#define rep(i,n)    for(int i=0; i<(int)n; i++)
#define mp(a,b) make_pair(a,b)
#define pb push_back
const ll inf = 1e18;
const ll mod = 1e9 + 7;

ll pow (ll x, ll n){
    ll ans = 1;
    while(n>0){
        if(n & 1 == 1){
            ans *= x;
        }
        x = x * x;
        n >>= 1;
    }
    return ans;
}

int main(){
    int n,k ;   cin >> n >> k ;
    vint a(n);
    rep(i,n)    cin >> a[i];
    sort(a.begin(),a.end(), greater<int>() );

    int ans =0;
    rep(i,k){
        ans += a[i];
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
package main

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

const (
	maxBufsize = 1000000
)

func inputs(lines int) []string {
	var strSlice []string

	rdr := bufio.NewReaderSize(os.Stdin, maxBufsize)

	for i := 0; i < lines; i++ {

		line := ReadLine(rdr)
		strSlice = append(strSlice, line)

	}

	return strSlice
}

// ReadLine is to read long line
func ReadLine(rdr *bufio.Reader) string {
	buf := make([]byte, 0, maxBufsize)
	for {
		l, p, e := rdr.ReadLine()

		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}

	return string(buf)
}

func main() {
	line1 := inputs(1)

	lineSlice := strings.Split(line1[0], " ")

	n, _ := strconv.Atoi(lineSlice[0])

	k, _ := strconv.Atoi(lineSlice[1])

	amari := n % k

	if amari < (k - amari) {
		fmt.Println(amari)
	} else {
		fmt.Println(k - amari)
	}
}


Measured memory_bytes: 640
n = int(input())
aaa = list(map(int, input().split()))
sa = sum(aaa)
bbb = list(map(int, input().split()))
for i, b in enumerate(bbb):
    c = min(aaa[i], b)
    aaa[i] -= c
    aaa[i + 1] -= min(aaa[i + 1], b - c)
print(sa - sum(aaa))


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

using ll = long long int;
using P = std::pair<int, int>;

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

int main()
{
    int n, t;

    std::cin >> n >> t;

    std::vector<int> a(n + 1), b(n + 1);

    for (int i = 1; i <= n; ++i)
    {
        std::cin >> a[i] >> b[i];
    }

    std::vector<std::vector<int>>
        d0(t, std::vector<int>(n + 1, 0)), d1(t, std::vector<int>(n + 2, 0));

    for (int i = 1; i <= t - 1; ++i)
    {
        for (int j = 1; j <= n; ++j)
        {
            d0[i][j] = std::max(d0[i][j - 1], d0[i - 1][j]);

            if (i >= a[j])
                d0[i][j] = std::max(d0[i - a[j]][j - 1] + b[j], d0[i][j]);
        }
    }

    for (int i = 1; i <= t - 1; ++i)
    {
        for (int j = n; j >= 1; --j)
        {
            d1[i][j] = std::max(d1[i][j + 1], d1[i - 1][j]);

            if (i >= a[j])
                d1[i][j] = std::max(d1[i][j], d1[i - a[j]][j + 1] + b[j]);
        }
    }

    int ans = 0;

    for (int i = 1; i <= n; ++i)
    {
        for (int j = 0; j <= t - 1; ++j)
            ans = std::max(ans, b[i] + d0[j][i - 1] + d1[t - j - 1][i + 1]);
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 73696
#if defined(_WIN32)
#include "stdc++.h"
#else
#include <bits/stdc++.h>
#endif

using ulong = unsigned long;
using ll = long long;
using ull = unsigned long long;

#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)

using namespace std;

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

	string a;
	cin >> a;

	a[3] = '8';

	cout << a << endl;
	return 0;
}


Measured memory_bytes: 764
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace C
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var n = long.Parse(Console.ReadLine());
            var res = n;
            for (long i = 1; i <= Math.Sqrt(n); i++)
            {
                if (n % i != 0) continue;
                var j = n / i;
                res = Math.Min(n, i + j - 2);
            }
            Console.WriteLine(res);
        }
    }
}


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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    while (1) {
        c -= b;
        if (c <= 0) {
            cout << "Yes\n";
            return 0;
        }
        a -= d;
        if (a <= 0) {
            cout << "No\n";
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 3636
// created by mtnshh
 
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
 
#define ll long long
#define ld long double
 
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
 
#define err() cout<<"=================================="<<endl;
#define errA(A) for(auto i:A)   cout<<i<<" ";cout<<endl;
#define err1(a) cout<<#a<<" "<<a<<endl
#define err2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define err3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl
#define err4(a,b,c,d) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<" "<<#d<<" "<<d<<endl
 
#define pb push_back
#define all(A)  A.begin(),A.end()
#define allr(A)    A.rbegin(),A.rend()
#define ft first
#define sd second
 
#define pll pair<ll,ll>
#define V vector<ll>
#define S set<ll>
#define VV vector<V>
#define Vpll vector<pll>
 
#define endl "\n"
 
const ll logN = 20;
const ll M = 1000000007;
const ll INF = 1e12;
#define PI 3.14159265
 
const ll N = 100005;

bool is_palin(string s){
	ll n = s.length();
	rep(i,0,n)
		if(s[i]!=s[n-1-i])
			return 0;
	return 1;
}

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	string s;
	cin>>s;
	ll n = s.length();
	string a,b;
	rep(i,0,(n-1)/2)	a += s[i];
	rep(i,(n+2)/2,n)	b += s[i];
	if(is_palin(s) and is_palin(a) and is_palin(b))
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
# p**7 は3**7がminでなし
# p1**3 * p2　は3**3 * 5,7=135,189のみ
# p1*p2*p3 は105,165,195
num_8 = [105,135,165,189,195]
n = int(input())
cnt = 0
for i in num_8:
  if i <= n:
    cnt += 1
print(cnt)

Measured memory_bytes: 38384
n = int(input())
seq = [int(x) for x in input().split()]
ans = 0
n = False
for i, val in enumerate(seq, 1):
    if val == i:
        if n:  # swap with next same
            n = False
            ans += 1
        else:
            n = True
    else:
        if n:
            ans += 1
            n = False
if n:
    ans += 1
print(ans)

Measured memory_bytes: 52908
#include <bits/stdc++.h>
using namespace std;
map <int,char> mp;
string s;
int num[14];
int main(){
	mp[-1]='-';
	mp[1]='+';
	cin>>s;
	for (int i=0;i<4;++i)num[i]=s[i]-'0';
	for (int a=-1;a<=1;a+=2){
		for (int b=-1;b<2;b+=2){
			for (int c=-1;c<2;c+=2){
				if (num[0]+num[1]*a+num[2]*b+num[3]*c == 7){
					printf("%d%c%d%c%d%c%d=7\n",num[0],mp[a],num[1],mp[b],num[2],mp[c],num[3]);
					return 0;
				}
			}
		}
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int k,n,m,i,j;
	scanf("%d %d",&n,&m);
	for(k=0;;k++)
	{
		j=k*n-(k-1);
		if(j>=m)
			break;
	}
	printf("%d",k);
	return 0;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cerr<<#x<<'='<<x<<' '
typedef long long ll;
typedef pair<int,int> pi;

const int MAXN = 1e5+5;
vector<int> adj[MAXN], topo;
bool visit[MAXN];

void dfs(int x) {
	if (visit[x]) return;
	visit[x] = 1;
	for (auto it: adj[x]) {
		dfs(it);
	}
	topo.emplace_back(x);
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
	int N,M; cin >> N >> M;
	for (int i = 0; i < M; i++) {
		int u,v; cin >> u >> v;
		adj[v].emplace_back(u);
	}
	for (int i = 1; i <= N; i++) {
		if (!visit[i]) dfs(i);
	}
		reverse(topo.begin(),topo.end());
	vector<int> dp(N+5,0);
	int ans = 0;
	for (auto u: topo) {
		for (auto v: adj[u]) {
			dp[v] = max(dp[v],dp[u]+1);
		}
		ans = max(ans,dp[u]);
	}
	cout << ans;
    return 0;
}


Measured memory_bytes: 11256
#include <time.h>

#include <stdlib.h>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <iomanip>
#include <numeric>
#include <cmath>

using namespace std;

int main(){
	int n,a,b;
	cin>>n>>a>>b;
	if((a-b)%2==0){
		cout<<"Alice"<<endl;
	}else{
		cout<<"Borys"<<endl;
	}
}


Measured memory_bytes: 256
import sys
x,y = map(int, input().split())
ans = 0

if(x == 1 and y == 1):
  print(1000000)
  sys.exit()

if(x == 3):
  ans += 100000
elif(x == 2):
  ans += 200000
elif(x == 1):
  ans += 300000
  
if(y == 3):
  ans += 100000
elif(y == 2):
  ans += 200000
elif(y == 1):
  ans += 300000
  
print(ans)


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

#define ff first
#define ss second
#define PI acos(-1)
#define pb push_back
#define int long long
#define ld long double
#define sp fixed<<setprecision
#define bp __builtin_popcountll
#define all(x) x.begin(),x.end()
#define pii pair<long long,long long>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

int MOD = (1e9)+7;
const int N = 1e6+5;

signed main()
{
    FAST
    int tc=1;
    //cin>>tc;
    for(int ti=1;ti<=tc;ti++)
    {
        int s,w;
        cin>>s>>w;
        cout<<((w>=s)?"unsafe":"safe")<<endl;
    }
    return 0;
}


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

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

Node *root, *NIL;

Node * treeMinimum(Node *x) {
  while(x->left != NIL)
    x = x->left;
  return x;
}

Node * find(Node *u, int k) {
  while(u != NIL && k != u->key) {
    if(k < u->key) u = u->left;
    else u = u->right;
  }
  return u;
}

Node * treeSuccessor(Node *x) {
  if(x->right != NIL) return treeMinimum(x->right);
  Node *y = x->parent;
  while(y != NIL && x == y->right) {
    x = y;
    y = y->parent;
  }
  return y;

}

void treeDelete(Node *z) {
  Node *y; // 削除する対象
  Node *x; // yの子

  // 削除する節点を決める
  if(z->left == NIL || z->right == NIL) y = z;
  else y = treeSuccessor(z);

  // yの子xを決める
  if(y->left != NIL) {
    x = y->left;
  } else {
    x = y->right;
  }

  if(x != NIL) {
    x->parent = y->parent;
  }

  if(y->parent == NIL) {
    root = x;
  } else {
    if(y == y->parent->left) {
      y->parent->left = x;
    } else {
      y->parent->right = x;
    }
  }

  if(y != z) {
    z->key = y->key;
  }
}

void insert(int k) {
  Node *y = NIL;
  Node *x = root;
  Node *z;
  
  z = (Node *)malloc(sizeof(Node));
  z->key   = k;
  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 *u) {
  if(u == NIL) return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}

void preorder(Node *u) {
  if(u == NIL) return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}
  
int main(void) {
  int n, i, x;
  char com[16];
  scanf("%d",&n);
  
  for(i=0;i<n;i++) {
    scanf("%s",com);
    if(!strcmp(com,"find")) {
      scanf("%d",&x);
      Node *t = find(root,x);
      if(t != NIL) printf("yes\n");
      else printf("no\n");
    } else if(!strcmp(com,"insert")) {
      scanf("%d",&x);
      insert(x);
    } else if(!strcmp(com,"print")) {
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if(!strcmp(com,"delete")) {
      scanf("%d",&x);
      treeDelete(find(root,x));
    }
  }

  return 0;
}


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

int main(){
	int n,x,k;
	cin >> n >> k;
	vector<int> h(n+4,0);
	for(int i = 1;i<=n;i++) cin >> h[i];
	h[0] = h[1];
	vector<int> dp(n+4,0);
	for(int i = 2;i<=n;i++){
		x = INT_MAX;
		for(int j = 1;j<i and j<=k;j++){
			x = min(x,abs(h[i]-h[i-j])+dp[i-j]);
		}
		dp[i] = x;
	}
	printf("%d\n",dp[n]);
	return 0;
}
	


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <queue>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)

int main() {
    int n;
    string s;
    cin>>s;
    n=s.size();
    cout<<s[0]<<n-2<<s[n-1];
	return 0;
}


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

using namespace std;

int main() {
  string w;
  cin >> w;
  int n=w.size();
  vector<int> a(1000);
  for(int i=0;i<n;i++){
    a.at(w.at(i))++;
  }
  int k =1 ;
  for(int i=0;i<1000;i++){
    if(a.at(i)%2 == 1){
      k = -1;
      break;
    }
  }
  if(k==1){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
  
  return 0;
}


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


char s[100002];

int main(void)
{	
	int i,lon,count=0;
	int alp[26]={0};
	scanf("%s",s);
	
	lon=strlen(s);
	
	for(i=0;i<lon;i++){
		if(s[i]=='a'){
			alp[0]++;
		} else if(s[i]=='b'){
			alp[1]++;
		} else if(s[i]=='c'){
			alp[2]++;
		} else if(s[i]=='d'){
			alp[3]++;
		} else if(s[i]=='e'){
			alp[4]++;
		} else if(s[i]=='f'){
			alp[5]++;
		} else if(s[i]=='g'){
			alp[6]++;
		} else if(s[i]=='h'){
			alp[7]++;
		} else if(s[i]=='i'){
			alp[8]++;
		} else if(s[i]=='j'){
			alp[9]++;
		} else if(s[i]=='k'){
			alp[10]++;
		} else if(s[i]=='l'){
			alp[11]++;
		} else if(s[i]=='m'){
			alp[12]++;
		} else if(s[i]=='n'){
			alp[13]++;
		} else if(s[i]=='o'){
			alp[14]++;
		} else if(s[i]=='p'){
			alp[15]++;
		} else if(s[i]=='q'){
			alp[16]++;
		} else if(s[i]=='r'){
			alp[17]++;
		} else if(s[i]=='s'){
			alp[18]++;
		} else if(s[i]=='t'){
			alp[19]++;
		} else if(s[i]=='u'){
			alp[20]++;
		} else if(s[i]=='v'){
			alp[21]++;
		} else if(s[i]=='w'){
			alp[22]++;
		} else if(s[i]=='x'){
			alp[23]++;
		} else if(s[i]=='y'){
			alp[24]++;
		} else if(s[i]=='z'){
			alp[25]++;
		}
	}
	
	for(i=0;i<26;i++){
		if(alp[i]==0){
			printf("%c\n",i+97);
			break;
		} else{
			count++;
		}
	}
		
	if(count>=26){
		printf("None\n");
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std; 
#define io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define rep(i,n) for (int i = 0; i < (n); ++i)

int main(void) {
    io;
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    int result = max (a*b, c*d);
    cout << result << endl;
    return 0;
}



Measured memory_bytes: 3584
N = int(input())
A = [int(input()) for _ in range(N)]
A.sort()

l = A.pop()
r = A.pop(0)
ans = abs(l-r)
while A:
	tmp = [abs(l-A[0]),abs(l-A[-1]),abs(r-A[0]),abs(r-A[-1])]
	cond = tmp.index(max(tmp))

	if cond == 0:
		ans += tmp[0]
		l = A.pop(0)
	elif cond == 1:
		ans += tmp[1]
		l = A.pop()
	elif cond == 2:
		ans += tmp[2]
		r = A.pop(0)
	else:
		ans += tmp[3]
		r = A.pop()

print(ans)


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

int n, m;
vector<int> s, c;

int solve();

int main() {
  cin >> n >> m;
  s.resize(m);
  c.resize(m);
  for(int i = 0; i < m; ++i) cin >> s[i] >> c[i];
  cout << solve() << endl;
  return 0;
}

int solve() {
  int ten = 1, f = 1;
  for(int i = 0; i < n - 1; ++i) f *= 10;
  for(int i = 0; i < n; ++i) ten *= 10;
  if(n == 1) f = 0;
  for(int i = f; i < ten; ++i) {
    bool ch = 1;
    for(int j = 0; j < m; ++j) {
      int x = i;
      for(int k = 0; k < n - s[j]; ++k) x /= 10;
      if(x % 10 != c[j]) ch = 0;
    }
    if(ch) return i;
  }
  return -1;
}

Measured memory_bytes: 256
#include <stdio.h>

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

	scanf("%d%d%d", &a, &b, &c);
	max = a;
	if (max < b)
		max = b;
	if (max < c)
		max = c;
	printf("%d\n", a + b + c - max);
	return 0;
}


Measured memory_bytes: 128
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007


#A
def A():
    n = I()
    a = LI()
    s = sum([i%2 for i in a])
    if s in (0,n):
        print(0)
    else:
        print(n-2+(s%2))
    return

#B
def B():
    n,Q,L,R = LI()
    a = LI()
    a.sort()
    query = LIR(Q)
    l = -1
    r = n
    while r-l > 1:
        m = (l+r)>>1
        am = a[m]
        for q,x,s,t in query:
            if q == 1:
                if am < x:
                    continue
                am += s
                am *= t
            else:
                if am > x:
                    continue
                am -= s
                if am < 0:
                    am = -((-am)//t)
                else:
                    am //= t
        if am < L:
            l = m
        else:
            r = m
    left = r
    l = 0
    r = n
    while r-l > 1:
        m = (l+r)>>1
        am = a[m]
        for q,x,s,t in query:
            if q == 1:
                if am < x:
                    continue
                am += s
                am *= t
            else:
                if am > x:
                    continue
                am -= s
                if am < 0:
                    am = -((-am)//t)
                else:
                    am //= t
        if am <= R:
            l = m
        else:
            r = m
    print(r-left)
    return

#C
def C():
    n,m = LI()
    lis = set()
    f = defaultdict(lambda : 0)
    for i in range(n):
        l,r = LI()
        f[l] += 1
        f[r+0.1] -= 1
        lis.add(l)
        lis.add(r)
        lis.add(r+0.1)
    l = list(lis)
    l.sort()
    k = len(l)
    for i in range(k-1):
        f[l[i+1]] += f[l[i]]
    s = [0,0]
    for i in l:
        j = f[i]
        if s[1] < j:
            s = [i,j]
        elif s[1] == j:
            if s[1]%2:
                s = [i,j]
                
    if s[1]%2:
        print((s[1]>>1)*2*m+round(s[0]))
    else:
        print(s[1]*m-round(s[0]))
    return

#D
def D():
    n = I()

    return

#E
def E():
    n = I()

    return

#F
def F():
    n = I()

    return

#G
def G():
    n = I()

    return

#H
def H():
    n = I()

    return

#I
def I_():
    n = I()

    return

#J
def J():
    n = I()

    return

#Solve
if __name__ == "__main__":
    C()



Measured memory_bytes: 93452
#include <algorithm>
#include <cassert>
#include <climits>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;

const int INF = 1e9;
const long long LINF = 1e18;
const double PI=3.14159265358979323846;

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

    cout << max({A + B, A + A - 1, B + B - 1}) << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(void){
  string s;
  cin >> s;
  int alpha[s.length()]={};
/*  for(int i=0;i<s.length();++i){
  	alpha[i] = 0;
  }
*/
  for(int i=0;i<s.length();++i){
  	alpha[s.at(i)-'a'] += 1;
  }
  for(int i=0;i<26;++i){
    if(alpha[i]==0){
      cout << (char)('a'+i);
      return 0;;
   }
  }
  	cout << "None";

  
return 0;}

Measured memory_bytes: 896
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <complex>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <stack> 
#include <bitset>
#include <queue>
#include <assert.h>
#include <unordered_map>
using namespace std;

const int N = 200010;
set<int> st;
int a[N], rak[N];

bool cmp(int x, int y) {
	return a[x] > a[y];
}

int main()
{
	int n;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
		rak[i] = i;
	}

	sort(rak + 1, rak + n + 1, cmp);

	long long ans = 0;
	for (int i = 1; i < n; i++)
		ans += a[rak[i / 2 + 1]];
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 4792
//Catchharsh
    #include<bits/stdc++.h>
    #define ll long long int 
    #define ld long double
    #define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
    #define F first
    #define S second
    #define pb push_back
    #define endl '\n'
    const ll MOD = 1e9+7;
    const ll INF = 1011111111;
    const ll LLINF = 1000111000111000111LL;
    const ld EPS = 1e-10;
    const ld PI = 3.14159265358979323;
    using namespace std;
    ll power (int x,int n)
    {
        if(n==0)
        return 1;
        else if(n%2==0)
        return power((x*x),n/2);
        else
        return x*power((x*x),(n-1)/2); 
    }
    vector<ll> seve;
    void  seveprime()
    {
      int prime[1000000]={0};
      for(int i=2;i*i<1000000;i++)
       {
        if(prime[i]==0)
         {
      	  for(int j=i*2;j<=1000000;j+=i)
           prime[j]=1;
         }
       }
       for(int i=2;i<=1000000;i++)
       {
       	if(prime[i]==0)
       		seve.pb(i);
       }
    }
    int main()
    {   
         IOS;
         ll a,b;
         cin>>a>>b;
         if(a>=13)
         	cout<<b;
         else if(a<=12&&a>=6)
         	cout<<(b/2);
         else
         	cout<<0;
    }

Measured memory_bytes: 256
package main

import (
	"bufio"
	"os"
	"fmt"
)

func solve() {
	var N int
	Readf("%d", &N)

	var c float32 = float32(N/2)
	if (N % 2 ) == 1 {
		c++
	}

	Writef("%f", c/float32(N))
}

func main()  {
	// If io still contains some buffered data flush it before
	// quiting
	defer io.Flush()

	// Solution of the problem goes here
	solve()
}

var (
	// fmt.Print and fmt.Scan is slow, we will use bufio
	// for read and write from stdin.
	io = bufio.NewReadWriter(
		bufio.NewReader(os.Stdin),
		bufio.NewWriter(os.Stdout),
	)
)

func Readf(format string, args ...interface{})  {
	fmt.Fscanf(io, format, args...)
}

func Writef(format string, args ...interface{})  {
	fmt.Fprintf(io, format, args...)
}


Measured memory_bytes: 640
#include<iostream>
#include<string>
using namespace std;
int main(){
  string s;
  int count[3]={0},a=0;
  int ans = 0;
  cin >> s;
  for(int i=0;i<s.size();i++){
    if(a==0&&s[i]=='J') count[0]++;
    else if(a==0&&count[0]>0&&s[i]=='O'){
      //cout << count[0] << endl;
      a = 1;
      count[1]=1;
    }
    else if(a==1&&s[i]=='O') count[1]++;
    else if(a==1&&s[i]=='I'&&count[0]>=count[1]){
      //cout << count[1] << endl; 
      a = 2;
      count[2]=1;
    }
    else if(a==2&&s[i]=='I') count[2]++;
    else if(a==2&&s[i]!='I'){
      if(count[2]>=count[1]&&count[1]>ans) ans = count[1];
      count[0] = 0;
      a = 0;
      if(s[i]=='J'){
	//cout << 'K' << endl;
	count[0] = 1;
      }
    }
    else{
      a = 0;
      count[0] = count[1] = count[2] = 0;
      if(s[i]=='J') count[0] = 1;
    }
  }
  if(count[2]>=count[1]&&count[1]>ans) ans = count[1];
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 2052
#include<stdio.h>


int main(void)
{
  int a,b,d,r;
  double f;

  scanf("%d %d",&a,&b);

  d = a/b;
  r = a%b;
  f = (double)(a)/(double)(b);


  printf("%d %d %f\n",d,r,f);

  return 0;
}



Measured memory_bytes: 2052
def int
  gets.to_i
end

def ints
  gets.split.map(&:to_i)
end

A = int
B = int
C = int
D = int
E = int

times = [A, B, C, D, E]

min_time = Float::INFINITY
times.permutation(times.size) do |tt|
  ct = 0
  tt.each.with_index do |t, i|
    ct += t
    if i < tt.size - 1
      ct += (ct % 10 == 0) ? 0 : 10 - (ct % 10)
    end
  end
  min_time = [min_time, ct].min
end

puts min_time


Measured memory_bytes: 1788
while True:
  h,w = map(int,input().split())
  if h == 0 and w == 0:
    break
  for i in range(h):
    for k in range(w):
      if i == 0 or k == 0 or k == w-1 or i == h-1:
        print("#", end="")
      else:
        print(".", end="")
    print()
  print()


Measured memory_bytes: 7004
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using Pair = pair<int, int>;
using Graph = vector<vector<int>>;
#define MOD 1000000007
#define INF 1000000007
#define SEP " "

int     main()
{
	ll n, m;
	cin >> n >> m;
	vector<ll> w(n+1), v(n+1);
	vector<vector<ll>> dp(n + 1, vector<ll>(m + 1, 0));
	for (int i = 1; i <= n; i++) {
		cin >> w[i] >> v[i];
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			if (j - w[i] < 0)
			{
				dp[i][j] = dp[i-1][j];
				continue ;
			}
			dp[i][j] = max(dp[i-1][j], dp[i-1][j-w[i]] + v[i]);
		}
	}
	cout << dp[n][m] << endl;
}


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


int main() {
  int N, M;
  cin >> N >> M;
  
  priority_queue<int> q;
  for(int i=0; i<N; i++){
    int a;
    cin >> a;
    q.push(a);
  }
  
  for(int i=0; i<M; i++){
    int a = q.top();
    q.pop();
    q.push(a/2);
  }
  
 long long ans = 0;
  while(!q.empty()){
    ans += q.top();
    q.pop();
  }
  
  cout << ans << endl;  
  return 0;
  
}

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

int main(){
    int N,Dd[100][2] ;
        cin >> N;
    for(int i = 1 ; i <= N ;i++){
        cin >> Dd[i][0] >> Dd[i][1];
    }
    for(int j = 1 ; j <= N-2 ; j++){
        if(Dd[j][0] == Dd[j][1] && Dd[j+1][0] == Dd[j+1][1] && Dd[j+2][0] == Dd[j+2][1]){
            cout << "Yes" << endl;
            return 0;
        }
        
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3656
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();

        if(a % 3 == 0 || b % 3 == 0 || (a+b) % 3 == 0) {
            System.out.println("Possible");
        }
        else {
            System.out.println("Impossible");
        }
    }
}


Measured memory_bytes: 22996