akhauriyash/Code-Regression huggingface dataset:
-- extension section
{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}
{-# LANGUAGE BangPatterns      #-}
{-# LANGUAGE CPP               #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TupleSections     #-}
-- not supported extension
--{-# LANGUAGE Strict, StrictData #-}


module Main where

-- @@@@@@@@@@@@@@@@@--
-- import section   --
-- @@@@@@@@@@@@@@@@@--
--    import A.B.C( function name )  ...
-- or import A.B.C 

--
import Prelude hiding(
  getLine,
  getContents,
  lines,
  words
  )

-- standard library
import Control.Monad.ST


-- bytestring


-- containers


-- deepseq


-- regex-posix


-- text
import Data.Text.Lazy.IO as TIO
import Data.Text.Lazy as T
import Data.Text.Lazy.Read as TR

-- import Data.Text.IO as TIO
-- import Data.Text as T
-- import Data.Text.Read as TR



-- unordered-containers


-- vectors
import Data.Vector.Unboxed as UV
import Data.Vector.Unboxed.Mutable as MV


-- mtl


-- @@@@@@@@@@@@@@@@@--
-- main section     --
-- @@@@@@@@@@@@@@@@@--

main :: IO ()
main = do
  input <- getInput
  Prelude.putStr . show . getAnswer $ input 

-- main :: IO()
-- main = do
--   answer <- getInputandanser
--   putStr . show $ answer


-- @@@@@@@@@@@@@@@@@@@@@--
-- I/O DataType section --
-- @@@@@@@@@@@@@@@@@@@@@--
data Input = I (Int,[Int])
  deriving(Show)

type Answer = Int



-- @@@@@@@@@@@@@@@@@--
-- answerSection    --
-- @@@@@@@@@@@@@@@@@--
getInput :: IO Input
getInput = do
  Right (n, _) <- getLine >>= ( return . TR.decimal )
  numTexts <- getLine >>= ( return . (fmap textToInt) .words) 
  return (I (n, numTexts) )
  where 
    textToInt t = case TR.decimal t of
      Right (n , _) -> n


getAnswer :: Input -> Answer 
getAnswer ( I (_ , nums) ) = occur
  where go !n ind (x:l@(x':l'@(x'':xs))) 
          | ind == x && (ind+1) == x' = go (n+1) (ind+2) l'
          | ind == x = go (n+1) (ind+1) l
          | (ind+1) == x' && (ind+2) == x''  = go (n + 1) (ind+3) xs
          | otherwise = go n (ind + 1) l
        go !n ind (x:x':xs) | ind == x && (ind+1) == x' = go (n+1) (ind+2) xs
                           | ind == x = go (n+1) (ind+1) (x':xs)
                           | otherwise = go n (ind+1) (x':xs)
        go !n ind (x:xs)  | ind == x = go (n+1) (ind+1) xs
                         | otherwise = go n (ind + 1) xs
        go !n _ [] = n
        occur = go 0 1 nums 

getInputAndAnser :: IO Answer
getInputAndAnser = undefined


-- @@@@@@@@@@@@@@@@@@@@@@@@@@--
-- question unique section    --
-- @@@@@@@@@@@@@@@@@@@@@@@@@@--





-- @@@@@@@@@@@@@@@@@--
-- util section     --
-- @@@@@@@@@@@@@@@@@--

-- standard Input Function
gLine :: IO Text
gLine = getLine

gContents :: IO Text
gContents = getContents



Measured memory_bytes: 3068
#include <iostream>
#include <queue>
using namespace std;
int H, W;
char s[50][50];
int black, white;
int d[50][50];
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int sx, sy, gx, gy;
typedef pair<int, int> P;

int bfs() {
  queue<P> que;
  for(int i = 0; i < 50; ++i) {
    for(int j = 0; j < 50; ++j) {
      d[i][j] = (1<<30);
    }
  }
  que.push(P(sx, sy));
  d[sx][sy] = 0;
  while(que.size()) {
    P p = que.front(); que.pop();
    if(p.first == gx && p.second == gy) break;
    for(int i = 0; i < 4; ++i) {
      int nx = p.first + dx[i], ny = p.second + dy[i];
      if(0 <= nx && nx < W && 0 <= ny && ny < H && s[ny][nx] != '#' && d[nx][ny] == (1<<30)) {
        que.push(P(nx, ny));
        d[nx][ny] = d[p.first][p.second] + 1;
      }
    }
  }
  return d[gx][gy];
}

int main() {
  cin >> H >> W;
  black = 0, white = 0;
  sx = 0, sy = 0, gx = W-1, gy = H-1;
  for(int i = 0; i < H; ++i) {
    for(int j = 0; j < W; ++j) {
      cin >> s[i][j];
      if(s[i][j] == '.') white++;
      else black++;
    }
  }
  int res = bfs();
  if(res == (1 << 30)) {
    cout << -1 << endl;
  } else {
    cout << white - (res+1) << endl;
  }
  return 0;
}

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

def get_input() -> tuple:
    """
    標準入力を取得する.

    Returns:\n
        tuple: 標準入力
    """
    A, B = list(map(int, input().split()))

    return A, B


def main(A: int, B: int) -> None:
    """
    メイン処理.

    Args:\n
        A (int): 切れ(1 <= A <= 16)
        B (int): 切れ(1 <= B <= 16)
    """
    # 求解処理
    ans = str()
    if (A <= 8) and (B <= 8):
        ans = "Yay!"
    else:
        ans = ":("

    # 結果出力
    print(ans)


if __name__ == "__main__":
    # 標準入力を取得
    A, B = get_input()

    # メイン処理
    main(A, B)


Measured memory_bytes: 9200
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>

#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, n) for (int i = 1; i <= n; i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl;

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<long long, long long> pll;

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
//const int MAX = 100000;
const int N = 100000;

const int R = 0;
const int U = 0;
const int L = 1;
const int D = 1;
const int C = 2;
const int MAX = 0;
const int MIN = 1;

double x[3][2], y[3][2];

double box(double d) {
	double x_min = x[C][MIN];
	x_min = min(x[R][MIN] + d, x_min);
	x_min = min(x[L][MIN] - d, x_min);
	double x_max = x[C][MAX];
	x_max = max(x[R][MAX] + d, x_max);
	x_max = max(x[L][MAX] - d, x_max);
	double y_min = y[C][MIN];
	y_min = min(y[U][MIN] + d, y_min);
	y_min = min(y[D][MIN] - d, y_min);
	double y_max = y[C][MAX];
	y_max = max(y[U][MAX] + d, y_max);
	y_max = max(y[D][MAX] - d, y_max);
	return (x_max - x_min) * (y_max - y_min);
}

int main() {
	cout << fixed << setprecision(15);
	int n;
	cin >> n;

	rep(i, 3) {
		x[i][MAX] = (double)(-INFL);
		x[i][MIN] = (double)INFL;
		y[i][MAX] = (double)(-INFL);
		y[i][MIN] = (double)INFL;
	}

	rep(i, n) {
		double x_tmp, y_tmp;
		string d;
		cin >> x_tmp >> y_tmp >> d;
		int dir;
		if(d == "R" || d == "L") {
			if(d == "R") dir = R;
			else dir = L;
			x[dir][MAX] = max(x_tmp, x[dir][MAX]);
			x[dir][MIN] = min(x_tmp, x[dir][MIN]);
			y[C][MAX] = max(y_tmp, y[C][MAX]);
			y[C][MIN] = min(y_tmp, y[C][MIN]);
		}
		else {
			if(d == "U") dir = U;
			else dir = D;
            y[dir][MAX] = max(y_tmp, y[dir][MAX]);
            y[dir][MIN] = min(y_tmp, y[dir][MIN]);
            x[C][MAX] = max(x_tmp, x[C][MAX]);
            x[C][MIN] = min(x_tmp, x[C][MIN]);
		}
	}

	vector<double> vd;
	vd.push_back(0.0);
	for(int i = 0; i < 2; i++) {
		if(x[C][i] < x[L][i]) vd.push_back(x[L][i] - x[C][i]);
		if(x[R][i] < x[C][i]) vd.push_back(x[C][i] - x[R][i]);
		if(x[R][i] < x[L][i]) vd.push_back((x[L][i] - x[R][i]) / 2.0);
		if(y[C][i] < y[D][i]) vd.push_back(y[D][i] - y[C][i]);
		if(y[U][i] < y[C][i]) vd.push_back(y[C][i] - y[U][i]);
		if(y[U][i] < y[D][i]) vd.push_back((y[D][i] - y[U][i]) / 2.0);
	}

	double ans = (double)INFL;
	for(auto i : vd) {
		ans = min(box(i), ans);
	}
	cout << ans << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds; 
using namespace std;
#define int long long
#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mll map<ll,ll>
#define mii map<int,int>
#define mp make_pair
#define pb push_back
#define rep(i,b) for(ll (i)=0;i<(b);i++)
#define all(c) (c).begin(), (c).end()
#define F first
#define S second
#define CLR(p) memset(p, 0, sizeof(p))
#define SET(p) memset(p, -1, sizeof(p))
#define DEBUG true
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);
//typedef long long int ll;
typedef tree<int, null_type, less<int>, rb_tree_tag, 
tree_order_statistics_node_update> new_data_set; 
const int MAX=1e6+5;
#define MOD 1000000007
/*std::cout << std::fixed;
std::cout << std::setprecision(6);*/
//(a%mod-b%mod+mod)%mod

// #define LOCAL 1

/************************************


 
*************************************/

vector<int>par,dep,tin,tout;
vector<vector<int>>v;
vector<int>deg;
vector<pll>req;
bool visited[MAX];






void solve(){
    int t=1;
    // cin>>t;
    while(t--){
        int n,m;
        cin>>n>>m;
        int a[m];
        int sum=0;
        for(int i=0;i<m;i++){
            cin>>a[i];
            sum+=a[i];
        }
        if(sum>n){
            cout<<-1<<endl;
        }
        else{
            cout<<n-sum<<endl;
        }
        

        
    }
}


signed main() 
{ 
    boost;

    #ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    while (cin.peek() != EOF) {
        solve();
        cout << endl << endl;
        string s;
        do getline(cin, s);
        while (!cin.eof() && !s.empty());
        while (isspace(cin.peek())) cin.get();
    }
    #else
        solve();
    #endif




    

    
	return 0; 
} 

Measured memory_bytes: 3700
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
#define OUT 0
#define IN 1
#define MAX 100

class Event{
	public:
	int id, type, t;
	Event(int id=0, int type=0, int t=0):id(id), type(type),t(t){}
	bool operator < (const Event &e) const{
		if(t == e.t) return type < e.type;
		return t < e.t;
	}
};

int main(){
	int s=150,n,a,b,M[MAX];
	
	while(cin >> n && n){
		Event events[MAX*2];
		int ne = 0;
		for(int i=0; i<n; i++){
			cin >> M[i] >> a >> b;
			events[ne++] = Event(i,IN,a);
			events[ne++] = Event(i,OUT,b);
		}
		
		sort(events, events+ne);
		
		bool fail = false;
		int cur = 0;
		
		for(int i=0; i<ne; i++){
			if(events[i].type == OUT) cur -= M[events[i].id];
			if(events[i].type == IN)  cur += M[events[i].id];
			if(cur > s) fail = true;
		}
		
		if(fail) cout << "NG" << endl;
		else cout << "OK" << endl;
	}
}

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

int main() {

    int n; string s; cin >> n >> s;
	for (int i = 0; i < s.size(); i++) {
		int tmp = s[i] - 'A';
		tmp += n;
		if (26 <= tmp) {
			tmp -= 26;
		}
		s[i] = (char)(tmp + 'A');
	}
    cout << s << endl;
	return 0;
}

Measured memory_bytes: 3576
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>

#define REP(n) for(int i = 0;i < n;i++)
#define LLREP(n) for(long long int  i = 0;i < n;i++)
typedef long long int ll;
using namespace std;
#define MAX_A 100005

int main(){

    string s;
    cin >> s;
    for(int i = 0;i < s.length();i++){
        if(i%2 == 0){
            cout << s[i];
        }
    }
    cout << endl;
}

Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<cmath>
using namespace std;
using ll =long long;
int main() {
	ll N, A, B;
	cin >> N >> A >> B;
	N%(A+B)<A?cout << N / (A + B) * A + N % (A + B) : cout << N / (A + B) * A +A;


}

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

#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; i++)
typedef long long ll;

// ナップサック問題
int main() {
    ll N, W; cin >> N >> W;
    vector<ll> weight(N);
    vector<ll> value(N);
    for(int i = 0; i < N; i++){
        cin >> weight[i] >> value[i];
    }

    // dpテーブル初期化
    vector<vector<ll> > dp(N + 1, vector<ll>(W + 1, 0));

    // 配るDP
    for(int i = 0; i < N; i++){
        for(int w = 0; w <= W; w++){
            if(w >= weight[i]){
                dp[i + 1][w] = max(dp[i][w - weight[i]] + value[i], dp[i][w]);
            }else{
                dp[i + 1][w] = dp[i][w];
            }
        }
    }
    cout << dp[N][W] << endl;
}


Measured memory_bytes: 80256
#include <iostream>
using namespace std;
int main(void){
        int a,b;
    cin>>a>>b;
    if (a > b){
      cout<<"a > b"<<endl;
    } else if (a < b){
      cout<<"a < b"<<endl;
    } else if (a == b){
      cout<<"a == b"<<endl;
    }
    return 0;
}



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

int main(){
  long int A;
  int N;
  long int x;//xはマイナスの数
  long int min = 1000000000;
  long int sum = 0;
  cin >> N;
  for(int i = 0; i < N; i++){
    cin >> A;
    if(A < 0){
      A = -A;
      x++;
    }
    if(min > A){
      min = A;
    }
    sum += A;
  }
  if(x%2 == 1){
    sum -= 2*min;
  }
  cout << sum << endl;
}
      


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

using namespace std;


#define rep(i,n) for(int i=0; i<n; i++)
#define rept(i,a,b) for(int i=a; i<b; i++)
#define ll long long

#define IMIN INT_MIN;
#define IMAX INT_MAX;


int main(){
	char yes[4] = {'A', 'T', 'G', 'C'};
	string S;
	int cnt = 0;
	int ans = 0;
	cin >> S;
	bool flag = false;
	rep(i, S.size()) {
		flag = false;
		rep(j, 4) {
			if (S[i] == yes[j]) {
				cnt++;
				ans = max(ans, cnt);
				//cout << ans << endl;
				flag = true;
			}
		}
		if (!flag) cnt = 0;
	}
	cout << ans << endl;


	return 0;
}



Measured memory_bytes: 256
import math
import sys

a=[int(input()) for i in range(5)]

tmp=100
p=100
for i in range(5):
    if a[i]%10!=0 and a[i]%10<tmp:
        tmp=a[i]%10
        p=i


if p==100: print(sum(a))
else:
    ans=0
    for i in range(5):
        if i==p: ans+=a[p]
        else: ans+=math.ceil(a[i]/10)*10
    print(ans)

Measured memory_bytes: 3064
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.range;
import std.container;
import std.bigint;
import std.math;

void main()
{
	while (1) {
    auto x = readln.chomp.split.map!(to!int);
    if (x[0] == 0) break;
    foreach (i; 0..x[0]) {
      foreach (j; 0..x[1]) {
        if (i == 0 || j == 0 || i == x[0] - 1 || j == x[1] - 1) write("#");
        else write(".");
      }
      writeln("");
    }
    writeln("");
  }
}

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

int main() {
    int n, l, m=0, sum=0;
    cin >> n;
    for(int i=0; i<n; i++) {
        cin >> l;
        sum += l;
        m = max(m, l);
    }
    if(m<sum-m) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}



Measured memory_bytes: 256
#define _crt_secure_no_warnings
#include<bits/stdc++.h>
#include<functional>
#define ll long long
#define Test int t;cin>>t;while(t--)
#define PI 3.14159265
#define endl "\n"
int dx[]= {-1,-1,-1,0,0,0,1,1,1};
int dy[]= {-1,0,1,-1,0,1,-1,0,1};
using namespace std;
void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
ll a[100001];
ll b[100001];
int main()
{
    fast();
    int k,a,b;
    cin>>k>>a>>b;
    for(int i=a;i<=b;i++){
        if(i%k==0){cout<<"OK";return 0;}
    }
    cout<<"NG";
    return 0;
}


Measured memory_bytes: 3648
package main

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

//Util
func nextStr() string {
	sc.Scan()
	return sc.Text()
}

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

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

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

func absInt(a int) int {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func absFloat64(a float64) float64 {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func maxFloat64(a, b float64) float64 {
	if a > b {
		return a
	} else {
		return b
	}
}

func minFloat64(a, b float64) float64 {
	if a > b {
		return b
	} else {
		return a
	}
}

func str2Int(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}

func reverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

func powInt(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func isPrime(x int) bool {
	if x == 1 {
		return false
	}
	if x == 2 {
		return true
	}
	if x%2 == 0 {
		return false
	}

	b := true
	rootx := int(math.Sqrt(float64(x)))
	i := 3
	for i <= rootx {
		if x%i == 0 {
			b = false
			break
		}
		i += 2
	}
	return b
}

func PrimeFactors(n int) (pfs []int) {
	// Get the number of 2s that divide n
	for n%2 == 0 {
		pfs = append(pfs, 2)
		n = n / 2
	}

	// n must be odd at this point. so we can skip one element
	// (note i = i + 2)
	for i := 3; i*i <= n; i = i + 2 {
		// while i divides n, append i and divide n
		for n%i == 0 {
			pfs = append(pfs, i)
			n = n / i
		}
	}

	// This condition is to handle the case when n is a prime number
	// greater than 2
	if n > 2 {
		pfs = append(pfs, n)
	}

	return
}

func sumInts(x []int) int {

	total := 0
	for _, v := range x {
		total += v
	}

	return total
}

//Main
const (
	initialBufSize = 10000
	maxBufSize     = 1000000
	mod            = 1e9 + 7
)

var (
	sc *bufio.Scanner = func() *bufio.Scanner {
		sc := bufio.NewScanner(os.Stdin)
		buf := make([]byte, initialBufSize)
		sc.Buffer(buf, maxBufSize)
		return sc
	}()
)

var N, K int

func main() {
	sc.Split(bufio.ScanWords)

	N, K = nextInt(), nextInt()
	Kf := float64(K)
	//p := 0
	// for true {
	// 	if powInt(2, p) >= K {
	// 		break
	// 	}
	// 	p++
	// }
	// coin := 0.5
	// for i := 0; i < p; i++ {
	// 	coin *= 0.5
	// }

	ans := 0.0
	if N >= K {
		ans += float64(N-K+1) / float64(N)
	}
	p := 1.0
	for i := float64(minInt(K-1, N)); i > 0; i-- {
		for i*math.Pow(2, p) < Kf {
			p++
		}
		//fmt.Println(i, 1/float64(N), math.Pow(0.5, p), float64(1.0/float64(N)*math.Pow(float64(1/2), p)))
		// tmp := 1 / float64(N) * math.Pow(0.5, p)
		// ans += tmp
		ans += 1 / float64(N) * math.Pow(0.5, p)
	}

	fmt.Println(ans)
}


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

using namespace std;

int main() {
    int h, n, sum = 0;
    cin >> h >> n;
    for (int i = 1; i <= n; ++i) {
        int x;
        cin >> x;
        sum += x;
    }   
    if (sum >= h) cout << "Yes\n";
    else cout << "No\n";
}

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

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    int p = min(min(a,b),c);
    int q = max(max(a,b),c);
    int r = a+b+c-p-q;
    a=p;b=r;c=q;
    //cout << a << " " << b << " " << c << endl;
    p = c - b;
    q = c - a;
    r = b - a;
    if(p%2==0&&q%2==0) {
        cout << p/2 + q/2 << endl;
        return 0;
    }
    else if(p%2==0){
        cout << p/2 + (q+1)/2 + 1 << endl; 
    }else if(q%2==0){
        cout << (p+1)/2 + q/2 + 1 << endl;
    }else{
        cout << p/2 + q/2 + 1 << endl;
    }
}

Measured memory_bytes: 256
#include <assert.h>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <algorithm>
#include <numeric>
#include <functional>
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <bitset>
typedef long long ll;
typedef unsigned long long ull;

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define DEBUG(vec) for (auto v : vec) { cout << v << " "; } cout << endl;

using namespace std;

ll a[300030] = {};
ll l[100010] = {};
ll r[100010] = {};

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

  int N;
  cin >> N;
  REP(i, 3 * N) {
    cin >> a[i];
  }

  ll left = 0;
  priority_queue<ll, vector<ll>, greater<ll>> leftq;
  REP(i, N) {
    leftq.push(a[i]);
    left += a[i];
  }
  l[0] = left;
  for (int i = 1; i <= N; i++) {
    leftq.push(a[N + i - 1]);
    left += a[N + i - 1];
    left -= leftq.top();
    leftq.pop();
    l[i] = left;
  }

  ll right = 0;
  priority_queue<ll> rightq;
  REP(i, N) {
    rightq.push(a[3 * N - 1 - i]);
    right += a[3 * N - 1 - i];
  }
  r[N] = right;
  for (int i = 1; i <= N; i++) {
    rightq.push(a[2 * N - i]);
    right += a[2 * N - i];
    right -= rightq.top();
    rightq.pop();
    r[N - i] = right;
  }

  ll mx = l[0] - r[0];
  REP(i, N + 1) {
    // cout << l[i] << " " << r[N - i] << endl;
    mx = max(mx, l[i] - r[i]);
  }
  cout << mx << endl;
  return 0;
}


Measured memory_bytes: 5876
int main(void) {
  int n;
  scanf("%d", &n);
  long long people[n], total = 0;
  for (int i = 0; i < n; i++) {
  	scanf("%lld", &people[i]);
  }
 
  for (int i = 1; i < n; i++) {
    long long diff = people[i-1] - people[i];
    if (diff > 0) {
      people[i] = people[i-1];
      total += diff;
    }
  }
  
  printf("%lld", total);
  return 0;
}

Measured memory_bytes: 3228
n,a,b=map(int,input().split())
x=[]
y=[]
for i in range(1,n+1):
  x.append(i)
for j in range(n):
  s=sum(list(map(int,str(x[j]))))
  if s>=a and s<=b:
    y.append(x[j])
print(sum(y))


Measured memory_bytes: 3572
// #include <bits/stdc++.h>
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;

#define all(x) begin(x), end(x)
#define rep(i,n) for(int i=0; i<n; i++)

struct UnionFind {
    vector<int> par, rank, _size;
    
    UnionFind(int n) : par(n), rank(n, 1), _size(n, 1) {
        for (int i=0; i<n; i++) par[i] = i;
    }
    
    int find(int x) {
        if (par[x]==x) return x;
        else return par[x] = find(par[x]);
    }

    bool same(int x, int y) {
        x = find(x); y = find(y);
        return x == y;
    }

    void unite(int x, int y) {
        x = find(x); y = find(y);
        if(x == y) return;

        _size[x] = _size[y] = _size[x] + _size[y];
        if(rank[x] == rank[y]) rank[y]++;

        if(rank[x] > rank[y]) par[y] = x;
        else par[x] = y;
    }

    int size(int x) {
        return _size[find(x)];
    }
};


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

    int a[m], b[m];
    rep(i, m) {
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
    }

    ll ans[m];
    UnionFind island(n);
    ans[m-1] = (ll)n*(n-1)/2;

    for (int i=m-1; i>=0; i--) {
        ll size_a = island.size(a[i]);
        ll size_b = island.size(b[i]);
        if (island.same(a[i], b[i])) ans[i-1] = ans[i];
        else ans[i-1] = ans[i] - size_a*size_b;
        island.unite(a[i], b[i]);
    }

    rep(i, m) cout << ans[i] << endl;

    return 0;
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>                                           
 
#define int long long
//#pragma GCC optimize("Ofast")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
 
 
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define forev(i, b, a) for(int i = (b); i >= (a); --i)
#define forn(i, a, b) for(int i = (a); i <= (b); ++i)
#define all(x) x.begin(), x.end()
#define sz(s) (int)s.size()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define s second
#define f first
 
 
using namespace std;
 
 
typedef pair < long long, long long > pll;    
typedef pair < int, int > pii;
typedef unsigned long long ull;         
typedef vector < pii > vpii;
typedef vector < int > vi;
typedef long double ldb; 
typedef long long ll;  
typedef double db;                         
 
 
const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}, block = 555;
const pii base = mp(1171, 3307), Mod = mp(1e9 + 7, 1e9 + 9);
const int inf = 1e9, N = 1e3 + 48, mod = 1e9 + 7, maxn = 102;
const db eps = 1e-12, pi = 3.14159265359;
const ll INF = 1e18;


int n, m, dp[N][N];
char c;


main () {
	scanf("%d%d", &n, &m);
	dp[1][1] = 1;
	forn (i, 1, n) {
		scanf("\n");
		forn (j, 1, m) {
			scanf("%c", &c);
			if (c != '#')
				dp[i][j] += (dp[i - 1][j] + dp[i][j - 1]) % mod; 
		}
	}

	cout << dp[n][m] << endl;
}                       

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

int main(){
  int N,t=0,k=1;
  
  cin>>N;
  int s[N];
  
  for(int i=0;i<N;i++){cin>>s[i];}
  
  for(int i=0;i<N;i++){
    if(s[i]!=k){t++;}
    else{k++;}
  }
  if(k==1){
    cout<<-1<<endl;
  }else{cout<<t<<endl;}
}
    

Measured memory_bytes: 1024
N = int(input())
A,B = map(int,input().split())
P = list(map(int,input().split()))
#P.sort()
q1 = []
q2 = []
q3 = []
for i in range(N):
  if P[i] <= A:
    q1.append(P[i])
  elif P[i] <= B:
    q2.append(P[i])
  else:
    q3.append(P[i])
print(min(len(q1),len(q2),len(q3)))

Measured memory_bytes: 9140
def ret_distance(list1,list2,D):
    result = 0
    for i in range(D):
        result += (list1[i]-list2[i])**2
    return result**(1/2)

N,D = map(int,input().split())
s = [list(map(int,input().split())) for i in range(N)]
count = 0

for n in range(N):
    I = n
    for i in range(N-I-1):
        if ret_distance(s[n],s[N-i-1],D).is_integer():
            count+=1

print(count)

Measured memory_bytes: 38256
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i, n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i, n) for(ll i=(ll)(n-1);i>=0;i--)
#define FOR(i, a, b) for(ll i=(ll)(a); i<=(ll)(b); i++)
#define RFOR(i, a, b) for(ll i=(ll)(a);i>=(ll)(b); i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

signed main()
{
	const double PI = 3.1415926536897932384626;
	int A, B, H, M;
	cin >> A >> B >> H >> M;
	double theta = (60*H+M)/(360.0)*PI;
	double phi = M/30.0*PI;
	cout << fixed << setprecision(15) << sqrt(A*A+B*B-2*A*B*cos(theta-phi));
	cout << endl;
}


Measured memory_bytes: 4192
while(l=gets.split.map(&:to_i)).inject(:+)>0 do
p=[l[0]+l[3],l[1]+l[4],l[2]+l[5]]
a=0
3.times{|i|
break if p.find{|v|v<i}
a=[a,i+p.inject(0){|s,v|s+=(v-i)/3}].max}
p a
end

Measured memory_bytes: 6112
import java.util.Scanner;
public class Main {
	public static void main(String [] args){
		Scanner sc = new Scanner(System.in);
		int w = sc.nextInt();
		int n = sc.nextInt();
		int stem;
		int [] kuji = new int [w];
		for(int i=0; i<w; i++){
			kuji[i] = i+1;
		}
		for(int i=0;i<n;i++){
			String str = sc.next();
			String [] ab = str.split(",");
			int a = Integer.parseInt(ab[0])-1;
			int b = Integer.parseInt(ab[1])-1;
			stem = kuji[a];
			kuji[a] = kuji[b];
			kuji[b] = stem;
		}
		for(int i=0;i<w;i++){
		System.out.println(kuji[i]);
		}
		
	}

}

Measured memory_bytes: 17196
let g(x,y)(s,t)=(x-.s,y-.t)and h(x,y)(s,t)=x*.t-.y*.s;;let rec f()=f(Scanf.scanf"%f %f %f %f %f %f %f %f
"(fun a b c d e i j k->let l=h(g(a,b)(e,i))(g(j,k)(a,b))and m=h(g(c,d)(a,b))(g(j,k)(c,d))and n=h(g(e,i)(c,d))(g(j,k)(e,i))in print_endline(if l>0.&&m>0.&&n>0.||l<0.&&m<0.&&n<0.then"YES"else"NO")));;try f()with _->()

Measured memory_bytes: 2292
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/
enum SegType{RMQ,RSQ};

struct SegmentTree{
	using Func=function<ll(ll,ll)>;
	using Attr=tuple<ll,Func,Func>;
	int n;
	vl val;
	ll e;
	Func f,g;
	const vector<Attr> tmpAttr{
		Attr(LINF,[](ll a,ll b){return min(a,b);},[](ll a,ll b){return b;}),
		Attr(0,[](ll a,ll b){return a+b;},[](ll a,ll b){return a+b;}),
	};
	SegmentTree(int N){
		n=1; while(n<=N)n*=2;
	}
	SegmentTree(int N,int t):SegmentTree(N){tie(e,f,g)=tmpAttr[t];val.assign(n*2,e);}
	SegmentTree(int N,ll E,Func F,Func G):SegmentTree(N){tie(e,f,g)=Attr(E,F,G);val.assign(n*2,e);}
	void update(ll k,ll a){
		k+=n;
		val[k]=g(val[k],a);
		while(k){
			k/=2;
			val[k]=f(val[k*2],val[k*2+1]);
		}
	}
	ll query(int a, int b){return query(a,b,1,0,n);}
	ll query(int a, int b, int k, int l, int r){
		if(r<=a or l>=b) return e;
		if(a<=l and r<=b) return val[k];
		int m=(l+r)/2;
		return f(query(a,b,k*2,l,m),query(a,b,k*2+1,m,r));
	}	
};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n,m;
	cin>>n>>m;
	SegmentTree st(n,RSQ);
	rep(i,m){
		ll t,a,b;
		cin>>t>>a>>b;
		if(t==0) st.update(a,b);
		else puta(st.query(a,b+1));
	}

	return 0;
}


Measured memory_bytes: 4936
import sys
input = sys.stdin.readline

def main():
    N, M, L = map(int, input().split())
    dist = [[float('inf')] * N for _ in range(N)]
    for _ in range(M):
        A, B, C = map(int, input().split())
        if C > L:
            continue
        A -= 1
        B -= 1
        dist[A][B] = C
        dist[B][A] = C

    for k in range(N):
        for i in range(N):
            for j in range(N):
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])

    e = [[float('inf')] * N for _ in range(N)]
    for i in range(N):
        for j in range(N):
            if dist[i][j] <= L:
                e[i][j] = 1
    
    for k in range(N):
        for i in range(N):
            for j in range(N):
                e[i][j] = min(e[i][j], e[i][k] + e[k][j])


    Q = int(input())
    for _ in range(Q):
        s, t = map(int, input().split())
        s -= 1
        t -= 1
        if e[s][t] == float('inf'):
            print(-1)
            continue
        ans = e[s][t]
        print(ans-1)


if __name__ == "__main__":
    main()

Measured memory_bytes: 126044
package main

import (
	"io"
	"os"

	"fmt"
)

func Solve(in io.Reader, out io.Writer) {
	var h, w int
	fmt.Fscan(in, &h, &w)

	s := make([]string, h)
	for i := 0; i < h; i++ {
		fmt.Fscan(in, &s[i])
	}

	for i := 0; i < h; i++ {
		for j := 0; j < w; j++ {
			if s[i][j] == "."[0] {
				continue
			}

			if (i > 0 && s[i-1][j] == "#"[0]) ||
				(j > 0 && s[i][j-1] == "#"[0]) ||
				(i < (h-1) && s[i+1][j] == "#"[0]) ||
				(j < (w-1) && s[i][j+1] == "#"[0]) {
				continue
			}

			fmt.Fprintln(out, "No")
			return
		}
	}

	fmt.Fprintln(out, "Yes")
}

func main() {
	Solve(os.Stdin, os.Stdout)
}


Measured memory_bytes: 512
use whiteread::parse_line;

fn main() {
    let (h, w): (usize, usize) = parse_line().unwrap();
    let mut frame = String::new();

    for _ in 0..w + 2 {
        frame.push('#');
    }

    println!("{}", frame);
    for _ in 0..h {
        let pic: String = parse_line().unwrap();
        println!("#{}#", pic);
    }
    println!("{}", frame);
}


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

using namespace std;

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

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

    int r = N % 10;

    if (r == 3) {
        cout << "bon" << endl;
    } else if ( r == 0 || r == 1 || r == 6 || r == 8 ) {
        cout << "pon" << endl;
    } else {
        cout <<"hon" << endl;
    }
}

Measured memory_bytes: 3088
#include "bits/stdc++.h"
using namespace std;
#define int long long
#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--)
#define REP1(i, n) for(int i=1; i<=(n); i++)
#define RREP1(i, n) for(int i=(n); i>=1; i--)
#define ALL(a) (a).begin(),(a).end()
#define UNIQUE_SORT(l) sort(ALL(l)); l.erase(unique(ALL(l)), l.end());
#define CONTAIN(a, b) find(ALL(a), (b)) != (a).end()
#define out(...) printf(__VA_ARGS__)
#if DEBUG
#define debug(...) printf(__VA_ARGS__)
#else
#define debug(...) /* ... */
#endif
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;}

void solve();
signed main()
{
#if DEBUG
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

/*================================*/
#if DEBUG
#define SIZE 100
#else
#define SIZE 223450
#endif

int N,M,K;
int A[SIZE],B[SIZE];

void solve() {
    cin>>N>>M>>K;
    REP(i,N)cin>>A[i];
    REP(i,M)cin>>B[i];
    vector<int> AS(N), BS(M);
    int ans = 0;
    REP(i,N) {
        if (i) {
            AS[i] = AS[i-1] + A[i];
        } else {
            AS[i] = A[i];
        }
        if (AS[i]<=K) {
            chmax(ans, i+1);
        }
    }
    REP(i,M) {
        if (i) {
            BS[i] = BS[i-1] +B[i];
        } else {
            BS[i] = B[i];
        }
        if (BS[i]<=K) {
            chmax(ans, i+1);
        }
    }
    REP(i,N) {
        int remain = K-AS[i];
        if (remain<B[0]) break;
        auto it = upper_bound(ALL(BS), remain);
        int j = it-BS.begin()-1;
        chmax(ans,i+j+2);
    }
    cout << ans << endl;
}


Measured memory_bytes: 9512
#include<stdio.h>
#define MAX 2000000
int H;
int right(int i){
  return 2*i + 1;
}
int left(int i){
  return 2 * i;
}
void swap(int *a,int *b){
  int tmp;
  tmp = *a;
  *a = *b;
  *b = tmp;
}
void MaxHeapify(int i,int *A){
  int l,r,largest;
  l = left(i);
  r = right(i);
  if(l <= H&&A[l] > A[i]){
    largest = l;
  }else{
    largest = i;
  }
  if(r <= H&&A[r] > A[largest]){
    largest = r;
  }
  if(largest != i){
    swap(&A[i],&A[largest]);
    MaxHeapify(largest,A);
  }
}
int main(){
  int i,A[MAX + 1];
  scanf("%d",&H);
  for(i = 1;i <= H;i++) scanf("%d",&A[i]);
  for(i = H/2;i > 0;i--) MaxHeapify(i,A);
  for(i =1;i <= H;i++) printf(" %d",A[i]);
  printf("\n");
  return 0;
}



Measured memory_bytes: 3656
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>

using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < int(n);i++)

int cost[501][501];
int maze[501][501];

int main(){
    int n,c;
    cin >> n >> c;
    rep(i,c) rep(j,c) cin >> cost[i][j];
    rep(i,n) rep(j,n) cin >> maze[i][j];

    vector<vector<int>> ccost(3,vector<int> (c,0));

    rep(i,n) rep(j,n){
        if (((i+1)+(j+1))%3 == 0){
            for (int h = 0; h < c;h++){
                ccost[0][h] += cost[maze[i][j]-1][h];
            }
        }
        else if (((i+1)+(j+1))%3 == 1){
            for (int h = 0; h < c;h++){
                ccost[1][h] += cost[maze[i][j]-1][h];
            }
        }
        else if (((i+1)+(j+1))%3 == 2){
            for (int h = 0; h < c;h++){
                ccost[2][h] += cost[maze[i][j]-1][h];
            }
        }
    }
    //rep(i,c) cout << ccost[0][i];
    //cout << endl;
    //rep(i,c) cout << ccost[1][i];
    //cout << endl;
    //rep(i,c) cout << ccost[2][i];
    //cout << endl;
    int res = 1e9;
    for (int i = 0;i < c;i++){
        for (int j = 0; j < c; j++){
            for (int k = 0; k < c; k++){
                if (i == j || j == k || k == i) continue;
                res = min(res,ccost[0][i]+ccost[1][j]+ccost[2][k]);
            }
        }
    }
    cout << res << endl;

    return 0;

}


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

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

using namespace std;

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

    int N;
    cin >> N;
    vector<int> n_children(N, 0);
    REP(_, N - 1) {
        int A;
        cin >> A;
        --A;
        ++n_children[A];
    }
    REP(i, N) {
        cout << n_children[i] << '\n';
    }
    cout << flush;
    return 0;
}


Measured memory_bytes: 3940
#include <stdio.h>

int main(){
unsigned long long int N,M;
unsigned long long int W=0;
unsigned long long int count;
  
scanf("%ld %ld",&N,&M);
  
unsigned long long int A;
  
for(count=0;count<M;count++){
  scanf("%ld" , &A);
  W+=A;
}
  
if(W > N) printf("-1\n");

else printf("%ld\n" , N-W);

return 0;

}

Measured memory_bytes: 1708
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000000;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

///////////////////////////

	
int main() {

	string s;
	cin >> s;

	ll ans = 1;
	repn(i, 3) {
		if (s[i - 1] == s[i]) { ans = 0; }
	}

	if (ans == 1) { cout << "Good"; }
	else { cout << "Bad"; }
	

	
	system("PAUSE");
}

Measured memory_bytes: 504
#include <iostream>
#include <vector>
#include <algorithm>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

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

  string tmp;
  int frag = 0;
  REP(i,S.size()){
    tmp = S[S.size()-1];
    tmp.append(S.substr(0, S.size()-1));
    S = tmp;
    if(S == T){
      cout << "Yes" << endl;
      frag = 1;
      break;
    }
  }

  if(frag == 0){
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;

long long modinv(long long,long long);
int main(){
    ll x,y;
    cin >> x >> y;
    ll minnum = min(x,y);
    ll maxnum = max(x,y);
    ll sq = 0;
    ll a,b;
    REP(i,333335){
        if((maxnum-(i*3))==(minnum-(i*3))*2){
            sq = i;
        }
    }
    ll answer = 1;
    a = sq;
    if((maxnum-sq*3)!=(minnum-sq*3)*2){
        cout << "0" << endl;
        return 0;
    }
    b = (minnum-sq*3)+a;
    for(ll i=0;i<a+b;i++){
        answer = (answer * (i+1))%MOD;
    }
    for(ll i = 1;i <= a;i++){
        answer = answer * modinv(i,MOD) %MOD; 
    }
    for(ll i = 1;i <=b;i++){
        answer = answer * modinv(i,MOD) % MOD;
    }
    
    cout << answer << endl;
    return 0;
}

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>
#include<cstring>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,b) for (int (i)=a;(i)<(b);(i)++)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long int;

const int inf = 1001001000;
const long long int Inf = 1001001001001001000;



void print(vector<vector<int>> a){
	for (int i = 0; i < a.size(); i++)
	{
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<vector<long long int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(vector<long long int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(set<int> a){
	for (auto x:a)
		cout << x << " ";
	cout << endl;
}

//幅優先探索のテンプレ.デフォルトではstartからの距離を返す.
//graphは隣接リスト.startは探索開始地点
vector<int> bfs(vector<vector<int>> &graph, int start){
	queue<int> todo;
	vector<int> dist(graph.size(),-1);
	dist[start] = 0;
	todo.push(start);
	while(!todo.empty()){
		int now = todo.front();
		todo.pop();
		for (int i=0;i<graph[now].size();i++){
			int nxt = graph[now][i];
			if (dist[nxt] != -1) continue;
			dist[nxt] = dist[now] + 1;
			todo.push(nxt);
		}
	}
	return dist;
}

int main(){
	string s, t;
	cin >> s >> t;
	int ans = 0;
	rep(i, 3)
	{
		if(s[i]==t[i])
			ans++;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
x,n = map(int, input().split())
l = list(map(int, input().split()))

l.sort()

if x not in l:
    print(x)
    exit()
else:
    a = l.index(x)

if a == n-1:
    if l[a-1] == x-1:
        print(x+1)
        exit()
    else:
        print(x-1)
        exit()
elif a == 0:
    print(x-1)
    exit()
    
p=a-1
f=a+1
while p >= 0 and f <= n-1:
    if l[p] < x-(a-p):
        print(x-(a-p))
        exit()
    elif l[f] > x+(f-a):
        print(x+(f-a))
        exit()
    p -= 1
    f += 1

if p == -1:
    print(l[0]-1)
elif f == n:
    print(l[-1]+1)

Measured memory_bytes: 9252
#include<stdio.h>
 
int main(){
    int a, b, ab, count;
     
    while( scanf("%d %d", &a, &b) != EOF ){
        ab = a + b;
	count = 0;
         
        while( ab > 0 ){
            ab /= 10;
            count++;
        }
         
        printf("%d\n", count);
    }
     
	return 0;
}

Measured memory_bytes: 0
#include <cstdio>
using namespace std;
long long v[2005][2005];
const int mod=1e9+7;
int main() {
    long long n,k;
    scanf("%lld%lld",&n,&k);
    v[0][0]=1;
    for(int i=1;i<=n;i++){
        v[i][0]=1;
        for(int j=1;j<=i;j++)
            v[i][j]=(v[i-1][j-1]+v[i-1][j])%mod;
    }
    for(int i=1;i<=k;i++)
        printf("%lld\n",v[n-k+1][i]*v[k-1][i-1]%mod);//外部红球可能情况数量*内部蓝球可断的情况数量
    //std::cout << "Hello, World!" << std::endl;
    return 0;
}

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

int main(){ 
  int k;
  string s;
  cin >> k >> s;
  if (s.size() <= k){
    cout << s << endl;
  }else {
    for (int i = 0; i < k; i++){
      cout << s.at(i);
    }
    cout << "...";
    cout << endl;
  }
}

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

using namespace std;
typedef pair<int, int> P;

const int MN = 300100;
int n, m;
vector<P> mtp[MN];
vector<int> g[MN];
int ans[MN];

struct Fenwick {
    int n;
    vector<int> seg;
    Fenwick(int _n) : n(_n), seg(n + 1) {}
    void add(int k, int v) {
        while (k <= n) {
            seg[k] += v;
            k += k & -k;
        }
    }
    int sum(int k) {
        if (k > n) return 0;
        int r = 0;
        while (k) {
            r += seg[k];
            k -= k & -k;
        }
        return r;
    }
};

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

    cin >> n >> m;
    for (int i = 0; i < n; i++) {
        int x, y;
        cin >> x >> y;
        g[x].push_back(y);
    }
    for (int d = 1; d <= m; d++) {
        for (int i = d; i <= m; i += d) {
            mtp[i].push_back(P(i, d));
        }
    }

    Fenwick fw(m);
    for (int l = 1; l <= m; l++) {
        for (int i = 0; i < int(g[l].size()); i++) {
            int r = g[l][i];
            fw.add(l, 1);
            fw.add(r + 1, -1);
        }
        for (int i = 0; i < int(mtp[l].size()); i++) {
            P &x = mtp[l][i];
            ans[x.second] += fw.sum(x.first) - fw.sum(x.first + x.second);
        }
    }

    for (int i = 1; i <= m; i++) {
        cout << ans[i] << '\n';
    }
    return 0;
}

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

typedef pair<string, int> P;

bool myfunction (P i, P j) {
  if(i.first == j.first) {
    return (i.second > j.second);
  } else {
    return (i.first < j.first);
  }
}

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

  vector<P> vec1(n);

  for(int i=0;i<n;i++) {
    cin >> vec1[i].first;
    cin >> vec1[i].second;
  }

  vector<P> vec2 = vec1;

  sort(vec1.begin(), vec1.end(), myfunction);

  for(int i=0;i<n;i++) {
    for(int j=0;i<n;j++) {
      if(vec1[i] == vec2[j]) {
        cout << j+1 << endl;
        break;
      }
    }
  }

  return 0;
}

Measured memory_bytes: 256
object Main {
  def main(args: Array[String]): Unit = {
    io.Source.stdin.getLines().foreach(rec)
  }

  def rec(s: String): Unit = {
    if (!s.matches(""".*(the|that|this).*""")) {
      rec(s.map({
        case cc if 'a' to 'z' contains cc => (((cc - 'a' + 1) % 26) + 'a').toChar
        case ch => ch
      }))
    } else println(s)
  }
}

Measured memory_bytes: 47372
import sys
input = sys.stdin.readline
N, K = map(int, input().split())
ws = [[0] * K for _ in range(K)]
bs = [[0] * K for _ in range(K)]
for _ in range(N):
  x, y, c = input().split()
  x = int(x)
  y = int(y)
  t = x // K + y // K
  if t % 2:
    if c == "W": c = "B"
    elif c == "B": c = "W"
  ws[y % K][x % K] += int(c == "W")
  bs[y % K][x % K] += int(c == "B")
csw = [[0] * (K + 1) for _ in range(K + 1)]
csb = [[0] * (K + 1) for _ in range(K + 1)]
for i in range(K):
  for j in range(K):
    csw[i + 1][j + 1] = csw[i + 1][j] + csw[i][j + 1] - csw[i][j] + ws[i][j]
    csb[i + 1][j + 1] = csb[i + 1][j] + csb[i][j + 1] - csb[i][j] + bs[i][j]
res = 0
for i in range(K + 1):
  for j in range(K + 1):
    u = csw[-1][-1] - csw[i][-1] - csw[-1][j] + csw[i][j] * 2
    v = csb[i][-1] + csb[-1][j] - csb[i][j] * 2
    res = max(res, u + v)
    u = csb[-1][-1] - csb[i][-1] - csb[-1][j] + csb[i][j] * 2
    v = csw[i][-1] + csw[-1][j] - csw[i][j] * 2
    res = max(res, u + v)
print(res)

Measured memory_bytes: 76508
n = input()
arr = map(int,raw_input().split())
brr = map(int,raw_input().split())
drr = []
for i in range(n):
	drr.append(arr[i]-brr[i])
drr.sort()
ans = 0
negsum = 0
for i in range(n):
	if drr[i] >= 0:
		break
	else:
		negsum += abs(drr[i])
		ans += 1
drr = drr[::-1]
possum = 0
for i in range(n):
	if drr[i] <= 0:
		break
	else:
		if possum >= negsum:
			break
		else:
			possum += drr[i]
			ans += 1
if possum >= negsum:
	print ans
else:
	print "-1"

Measured memory_bytes: 15848
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

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

Measured memory_bytes: 3664