akhauriyash/Code-Regression huggingface dataset:
#![allow(dead_code)]
use std::cmp;
use std::collections::*;

pub struct Scanner {
    line: Vec<String>,
    idx: usize,
}

impl Scanner {
    pub fn new() -> Self {
        let mut buffer: Vec<u8> = Vec::new();
        std::io::Read::read_to_end(&mut std::io::stdin(), &mut buffer).unwrap();
        let b: &str = unsafe { std::str::from_utf8_unchecked(&mut buffer) };
        Scanner {
            line: b
                .trim()
                .split_ascii_whitespace()
                .collect::<Vec<&str>>()
                .iter()
                .map(|&s| String::from(s))
                .collect(),
            idx: 0,
        }
    }
    pub fn next<T>(&mut self) -> T
    where
        T: std::str::FromStr,
        T::Err: std::fmt::Debug,
    {
        let ret: T = self.line[self.idx].parse::<T>().unwrap();
        self.idx += 1;
        ret
    }
    pub fn next_vec<T>(&mut self, n: usize) -> Vec<T>
    where
        T: std::str::FromStr,
        T::Err: std::fmt::Debug,
    {
        let mut v: Vec<T> = Vec::with_capacity(n);
        for _i in 0..n {
            v.push(self.next());
        }
        v
    }
    pub fn next_chars(&mut self) -> Vec<char> {
        let s: String = self.next();
        s.chars().collect::<Vec<char>>()
    }
}

fn lower_bound<T: std::cmp::Ord>(v: &Vec<T>, val: &T) -> usize {
    let mut lb: isize = -1;
    let mut ub: isize = v.len() as isize;
    while ub - lb > 1 {
        let mid = (lb + ub) / 2;
        if *val <= v[mid as usize] {
            ub = mid;
        } else {
            lb = mid;
        }
    }
    return ub as usize;
}

fn dfs(
    u: usize,
    p: usize,
    dp: &mut Vec<i32>,
    ans: &mut Vec<usize>,
    a: &Vec<i32>,
    edge: &Vec<Vec<usize>>,
) {
    let idx = lower_bound(dp, &a[u]);
    let prev = dp[idx];
    dp[idx] = a[u];
    ans[u] = lower_bound(dp, &i32::max_value());

    for v in &edge[u] {
        if *v == p {
            continue;
        }
        dfs(*v, u, dp, ans, a, edge);
    }
    dp[idx] = prev;
}

fn main() {
    let mut scan = Scanner::new();
    let n: usize = scan.next();
    let a: Vec<i32> = scan.next_vec(n);
    let mut edge: Vec<Vec<usize>> = vec![Vec::new(); n];
    for _ in 0..n - 1 {
        let u: usize = scan.next();
        let v: usize = scan.next();
        let (u, v) = (u - 1, v - 1);
        edge[u].push(v);
        edge[v].push(u);
    }
    let mut dp: Vec<i32> = vec![i32::max_value(); n];
    let mut ans: Vec<usize> = vec![0; n];
    dfs(0, 0, &mut dp, &mut ans, &a, &edge);
    for x in ans {
        println!("{}", x);
    }
}


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

const int MOD = 1000000007;
const int INF = 1e9;

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

  int l = 0;
  int r = s.size() - 1;
  int ans = 0;

  while(r > l){
    if(s[l] == s[r]){
      r --;
      l ++;
    }else{
      if(s[l] == 'x'){
        l ++; ans ++;
      }else if (s[r] == 'x'){
        r --; ans ++;
      }else{
        ans = -1; break;
      }
    }
  }

  cout << ans << endl;


  return 0;
}

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

import sys
import math


debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        # for line in sys.stdin:
        #     lines.append(line)
        lines.append(input())
        lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]

   
    (k, ) = [int(e) for e in lines[0].split(' ')]
    s = lines[1]

    return (k, s)


def solve(k, s):

    result = s
    if len(s) > k:
        result = s[:k] + '...'
    
    return result

    


def main():
    # 出力
    result = solve(*parse_input())
    if isinstance(result, list):
        for r in result:
            print("%s" % r, sep='')
    else:
        print("%s" % result, sep='')

if __name__ == '__main__':

    main()

Measured memory_bytes: 62076
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
#include <cstdint>
using namespace std;
using LL = long long;

#define FUTAGO(x) ((x) ? "Yay!" : ":(")
const LL MOD = 1000000007;

int main() {
	int N;
	cin >> N;
	multiset<int>S;
	S.insert(0);
	S.insert(0);
	S.insert(0);
	LL ans = 1;
	for (int i = 0; i < N; ++i) {
		int A;
		cin >> A;
		int cnt = S.count(A);
		ans *= cnt;
		ans %= MOD;
		if (cnt == 0)break;
		S.erase(S.find(A));
		S.insert(A + 1);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
package main

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

func main() {
	var N int
	fmt.Scanln(&N)

	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	b := make([]int, N-1)
	for i := range b {
		sc.Scan()
		b[i], _ = strconv.Atoi(sc.Text())
	}

	ans := b[0]
	for i := 0; i < N-2; i++ {
		if b[i] <= b[i+1] {
			ans += b[i]
		} else {
			ans += b[i+1]
		}
	}
	ans += b[N-2]
	fmt.Println(ans)
}


Measured memory_bytes: 640
import Control.Applicative
import Control.Monad
import Data.List
import Data.Ratio
import Text.Printf
import System.IO

untilEOF :: IO () -> IO ()
untilEOF x = do
  e <- isEOF
  unless e $ x >> untilEOF x

main :: IO ()
main = untilEOF $ do
  n <- readLn
  print $ solve n

solve :: Int -> Int
solve n = length $ 
  [ (a,b,c,d) | (a,b,c,d) <- liftM4 (,,,) [0..9] [0..9] [0..9] [0..9]
  , a + b + c + d == n ]



Measured memory_bytes: 4184
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>
#include<deque>
#include<random>
#include<set>
#include<bitset>
#include<cassert>

using namespace std;
typedef long long ll;
typedef double lldo;
#define mp make_pair
#define pub push_back
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
ll gcd(ll a, ll b) { if (a % b == 0) { return b; } else  return gcd(b, a % b); }
ll lcm(ll a, ll b) { if (a == 0) { return b; }return a / gcd(a, b) * b; }
template<class T>ll LBI(vector<T>& ar, T in) { return lower_bound(ar.begin(), ar.end(), in) - ar.begin(); }
template<class T>ll UBI(vector<T>& ar, T in) { return upper_bound(ar.begin(), ar.end(), in) - ar.begin(); }

ll n, l[105] = {}, ans = 0;

int main() {
	cin >> n;
	rep(i, n)cin >> l[i];
	rep(i, n) {
		for (int j = i + 1; j < n; j++) {
			for (int k = j + 1; k < n; k++) {
				if (l[i] != l[j] && l[j] != l[k] && l[k] != l[i] && l[i] + l[j] > l[k] && l[j] + l[k] > l[i] && l[k] + l[i] > l[j])ans++;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define IFOR(i, m, n) for(ll i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
/* テンプレートここまで */
const ll MOD = 1e9+7;
ll modpow(ll a , ll b, ll m){
  if (b == 0) return 1;
  ll ret;
  if (b%2 == 0){
    ll  t = modpow(a, b/2,m)%m;
    ret = t*t %m;
  }else{
    ll t = modpow(a, (b-1)/2,m)%m;
    ret = a*t %m * t % m;
  }
  ret %= m;
  return ret;
}

int main() {
  string s; cin >> s;
  ll n = s.size();
  reverse(ALL(s));
  vector<vector<ll>> dp(n+1, vector<ll>(13, 0));
  dp[0][0] = 1;
  REP(i,n){
    ll x = modpow(10,i,13LL);
    if(s[i]=='?'){
      REP(j,13){
        REP(l,10){
          ll k = (j+x*l%13)%13;
          dp[i+1][k] += dp[i][j];
          dp[i+1][k] %= MOD;
        }
      }
      continue;
    }
    ll t = s[i] - '0';
    REP(j, 13){
      ll k = (j+x*t%13)%13;
      dp[i+1][k] += dp[i][j] %= MOD;
      dp[i+1][k] %= MOD;
    }
  }
  cout << dp[n][5] << endl;
}


Measured memory_bytes: 13696
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define VSUM(V) accumulate(ALL(V), 0)
#define MID(a,b,c) (a) < (b) && (b) < (c)
#define MIDe(a,b,c) (a) <= (b) && (b) <= (c)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define IN4(a,b,c,d) cin >> a >> b >> c >> d
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define Vd vector<double>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b != 0 ? gcd(b, a % b) : a;} //最大公約数
int lcm(int a, int b){return a * b / gcd(a, b);}
string toStrUp(string str){char diff = 'A'-'a';REP(i,str.size()) str[i] += diff;return str;}
string gCh(string str, int key){return str.substr(key,1);}

signed main() {
  RAPID;
  // デフォルト変数定義
  int n=0,m=0,a=0,b=0,c=0,d=0,x=0,y=0,z=0;
  string s="",t="";
  //

  // ここから
  IN(n);
  Vi A(n);
  VIN(A)
  SORT(A);
  OUT(A[n-1]-A[0]);
}

Measured memory_bytes: 256
n, a, b, *x = map(int, open(0).read().split())

now = x[0]

ans = 0
for i in range(1, n):
    cost = (x[i] - now) * a
    if cost > b:
        ans += b
    else:
        ans += cost
    now = x[i]
print(ans)


Measured memory_bytes: 20076
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(container) container.begin(),container.end()
#define fast ios::sync_with_stdio(0); cin.tie(0)
// #ifndef ONLINE_JUDGE
// #include "debug.cpp"
// #endif
#define int long long
const int mod = 1e9+7;  
int power(int a,int b) { if(b==0) return 1; int res = power(a,b/2); if(b&1) return res * res * a; else return res * res; }


int32_t main(){
    
  fast;
  int n,k; cin >> n >> k;

  if(n<k){
    cout << min(n,abs(n-k));
  }
  else{
    int x = n/k;
    if(n%k!=0) x++;
    cout << abs(n - x*k);
  }

  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end() 
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000
using namespace std;
typedef long long ll;

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> A(N);
    double sum = 0;
    REP(i, N){
        cin >> A[i];
        sum += A[i];
    }

    
    int res = 0;
    REP(i, N){
        if(double(A[i]) >= double(sum/4/M)){
            res++;
        }
    }
    if(res >= M){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

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

// A:配列
// N:要素数
void bubbleSort(int* A, int N) {
	bool flag = true; // 逆の隣接要素が存在する
	int counter = 0;

	while (flag) {
		flag = false;
		for (int j = N - 1; j > 0; j--) {
			if (A[j] < A[j - 1]) {
				// 交換する
				swap(A[j], A[j - 1]);
				flag = true;
				counter++;
			}
		}
	}


	for (int i = 0; i < N; i++) {
		cout << A[i];
		if (i != N - 1) cout << " ";
	}
	cout << endl << counter << endl;
}

int N;
int A[100];
int main() {
	cin >> N;

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

	bubbleSort(A, N);
	return 0;
}


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

int main(){
	int i,j;
	int n, k, x, a, b, ans;
	
	scanf("%d", &n);
	scanf("%d", &k);
	
	ans = 0;
	for(i = 0; i < n; i++){
		scanf("%d", &x);
		a = x * 2;
		b = (k - x) * 2;
		b = ((b > 0) ? b : (-b));

		ans += ((a < b) ? a : b);
	}

	printf("%d\n", ans);

	return 0;
}


Measured memory_bytes: 128
abc = list(map(int, input().split()))
abc.sort()
ans = abc[2] - abc[1]
abc[0] += ans

if (abc[2]-abc[0]) % 2 == 0:
    ans += (abc[2]-abc[0]) // 2
else:
    ans += (abc[2]-abc[0]) // 2 + 2

print(ans)


Measured memory_bytes: 9120
package main

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

var sc *bufio.Scanner

func nextString() string {
	sc.Scan()
	i := sc.Text()
	return i
}

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func gcd(x, y int) (r int) {
	if x < y {
		x, y = y, x
	}
	if y == 0 {
		r = x
	} else {
		r = gcd(y, x%y)
	}
	return r
}

func main() {
	sc = bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	x, y := nextInt(), nextInt()
	fmt.Println(gcd(x, y))
}



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

struct Graph{
  ll n;
  ll edge[101][101];

  void init(ll n_){
    n=n_;
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
        edge[i][j]=1e9+7;
      }
    }
  }

  void update(ll c,ll d,ll e){
    if(edge[c][d]>e)edge[c][d]=e;
    if(edge[d][c]>e)edge[d][c]=e;
  }

  int dijkstra(ll a,ll b){
    int i,j;
    ll dist[101];
    for(i=0;i<n;i++){
      dist[i]=1e8+7;
    }

    priority_queue<pair<ll,ll> > q; //distance,n
    pair<ll,ll> node;
    ll from,to;
    ll tmp;
    dist[a]=0;
    q.push({0,a});

    while(!q.empty()){
      node=q.top();
      from=node.second;
      q.pop();
      if(node.first*-1>dist[from]){
        continue;
      }

      for(i=0;i<n;i++){
        tmp=dist[from]+edge[from][i];
        if(dist[i]>tmp){
          dist[i]=tmp;
          q.push({tmp*-1,i}); //greater
        }
      }
    }
    return dist[b];
  }
};

int main(void){
  ll n,k,o;
  ll a,b,c,d,e;
  Graph graph;
  
  cin>>n>>k;

  while(n!=0&&k!=0){
    graph.init(n);

    for(int i=0;i<k;i++){
      cin>>o;
      if(o){
        cin>>c>>d>>e;
        c--;
        d--;
        graph.update(c,d,e);
      }
      else{
        cin>>a>>b;
        a--;
        b--;
        int dist=graph.dijkstra(a,b);
        if(dist!=1e8+7)cout<<dist<<endl;
        else cout<<-1<<endl;
      }
    }
    cin>>n>>k;
  }
  return 0;
}



Measured memory_bytes: 3168
#include <iostream>
#include <vector>
#include <deque>
#include <algorithm>
#include <string>
#include <string.h>

using namespace std;

int main()
{
    string s;
    cin >> s;
    int K;
    cin >> K;

    vector<string> ss;
    for (int i=0;i<s.size();++i) {
        for (int j=i+1;j<=s.size();++j) {
            auto a = s.substr(i, j-i);
            ss.push_back(a);
            inplace_merge(ss.begin(), ss.end()-1, ss.end());
            ss.erase(unique(ss.begin(), ss.end()), ss.end());
            if (ss.size() > 5) {
                if (ss.back() == a) {
                    ss.pop_back();
                    break;
                }
                ss.pop_back();                
            }
        }
    }

    cout << ss[K-1] << endl;



    return 0;
}

Measured memory_bytes: 256
class Dice

  def initialize(dice)
    @top  = dice[0]
    @side   = [ dice[2], dice[1], dice[3], dice[4] ]
    @bottom = dice[5]
  end

  def roll(action)
    b = @bottom
    u = @top
    case action
    when "N"
      @top   = @side[2]
      @bottom  = @side[0]
      @side[2] = b
      @side[0] = u
    when "E"
      @top   = @side[3]
      @bottom  = @side[1]
      @side[3] = b
      @side[1] = u
    when "S"
      @top   = @side[0]
      @bottom  = @side[2]
      @side[0] = b
      @side[2] = u
    when "W"
      @top   = @side[1]
      @bottom  = @side[3]
      @side[1] = b
      @side[3] = u
    end
  end

  def same_dice?(sub)
    i = 0
    while true
      if south == sub.south
        4.times do
          if all_num == sub.all_num
            return true
          end
          roll("E")
        end
      end
      if i > 6
        return false
      elsif i == 3
        roll("E")
        roll("N")
      else
        roll("N")
      end
      i += 1
    end
  end

  def top
    @top
  end

  def bottom
    @bottom
  end

  def north
    @side[0]
  end

  def east
    @side[1]
  end

  def south
    @side[2]
  end

  def west
    @side[3]
  end

  def all_num
    [@top, @bottom, @side[2], @side[1], @side[3], @side[4]]
  end
end

num = (gets.to_i) - 1
dice = Dice.new(gets.split.map(&:to_i))

(1..num).each do |i|
  dice_2 = Dice.new(gets.split.map(&:to_i))
  if dice_2.same_dice?(dice)
    puts "No"
    break
  else
    if i == num
      puts "Yes"
    else
      next
    end
  end
end

Measured memory_bytes: 8776
// B.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <map>
#include <vector>

using namespace std;

typedef long long LL;

static const LL MOD = 1e9 + 7;

class BIT {
	std::vector<LL> bit;
	int size;
public:
	BIT() { }
	BIT(int sz) { init(sz); }
	void init(int sz) {
		bit.resize((size = sz) + 1);
	}
	LL sum(int i) {
		LL s = 0;
		while (i > 0) {
			s += bit[i];
			i -= i & -i;
		}
		return s;
	}
	void add(int i, LL x) {
		if (i == 163) {
			++i;
			--i;
		}

		while (i <= size) {
			bit[i] += x;
			i += i & -i;
		}
	}
};

struct modll {
	long long x;
	modll() { }
	modll(long long _x) : x(_x % MOD) { }
	operator int() const { return (int)x; }
	modll operator+(const modll& r) { return (x + r.x) % MOD; }
	modll operator+=(const modll& r) { return x = (x + r.x) % MOD; }
	modll operator-(const modll& r) { return (x + MOD - r.x) % MOD; }
	modll operator-=(const modll& r) { return x = (x + MOD - r.x) % MOD; }
	modll operator*(const modll& r) { return (x * r.x) % MOD; }
	modll operator*(int r) { return (x * r) % MOD; }
	modll operator*=(const modll& r) { return x = (x * r.x) % MOD; }
	static modll modinv(int a) { return modpow(a, MOD - 2); }
	static modll modpow(int a, int b) {
		modll x = a, r = 1;
		for (; b; b >>= 1, x *= x) if (b & 1) r *= x;
		return r;
	}
};

int main(int argc, char *argv[]) {
	LL n, k, sum = 0;
	cin >> n >> k;
	vector<int> a(n);
	map<int, LL> m;
	map<int, LL> lows;
	BIT bit(2000);
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		m[a[i]] += 1;
	}
	for (auto kv : m) {
		lows[kv.first] = sum;
		sum += kv.second;
	}
	modll ans = 0;
	for (int i = 0; i < n; ++i) {
		bit.add(a[i], 1);
		modll inv = i + 1 - bit.sum(a[i]);
		inv *= k;
		ans += inv;
		modll x = (k * (k - 1)) / 2;
		x *= lows[a[i]];
		ans += x;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 384
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

const int N = 3e3 + 10;
int a[N];
int64 dp[N][N];
bool visit[N][N];

int64 solve(int L, int R) {
  if (L > R) return 0;
  int64& ret = dp[L][R];
  if (visit[L][R]) return ret;
  visit[L][R] = true;
  ret = a[L] - solve(L + 1, R);
  ret = max(ret, a[R] - solve(L, R - 1));
  return ret;
}

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
  }
  int64 ret = solve(0, n - 1);
  printf("%lld\n", ret);
  return 0;
}


Measured memory_bytes: 78592
n = int(input())
a = sorted(list(map(int,input().split())), reverse=True)
ans = -a[0]
if n%2==0:
    a = a[:(n//2)]
    ans += sum(a)*2
    print(ans)
if n%2==1:
    a = a[:(n//2)+1]
    ans += sum(a)*2
    print(ans-a[n//2])

Measured memory_bytes: 31540
#pragma GCC optimize("Ofast")
#pragma GCC target("avx")
#include <bits/stdc++.h>
using namespace std;

#define INIT std::cin.tie(0);std::ios::sync_with_stdio(false);
#define ALL(c) (c).begin(), (c).end()
#define CALL(c) (c).cbegin(), (c).cend()
#define RALL(c) (c).rbegin(), (c).rend()
#define CRALL(c) (c).crbegin(), (c).crend()
#define REP(i, n) for (int i = 0; i < static_cast<int>(n); i++)
#define FOR(i, s, n) for (int i = s; i < static_cast<int>(n); i++)
#define ASC(t) [](t& x, t& y){ return x < y; }
#define DESC(t) [](t& x, t& y){ return x > y; }
#define PSORT(s,p,e) partial_sort((s), next((s), (p)), (e))
#define VIEW(v,t) for_each((v).begin(), (v).end(), [](t& a) { cout << a << " "; }); cout << endl;

#define IN(a, x, b) (a<=x && x<b)
template<class T> inline T CHMAX(T& x, const T y){return x=(x<y)?y:x;}
template<class T> inline T CHMIN(T& x, const T y){return x=(x>y)?y:x;}
#define OUT(dist) std::cout<<(dist);
#define WS std::cout<<" ";
#define NL std::cout<<"\n"

using PII = pair<int, int>;
using PLL = pair<long long, long long>;
using LL = long long;
using ULL = unsigned long long;
template<class T> using V = vector<T>;
template<class T> using V2 = vector<vector<T>>;
template<class T, int W=255> using A = array<T, W>;
template<class T, int W=255, int H=255> using A2 = array<array<T, W>, W>;

int N, K;

int main(){
    INIT;
    cin >> N >> K;
    int ans = 0;
    for(int i = 1; i <= N; i++) {
        if(i + (K-1) > N) break;
        ans++;
    }
    cout << ans << "\n";
}

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

int main() {
	int n;
	string s;
	cin >> n >> s;
	int ans = 0;
	for (int i = 1; i < n; i++) {
		int count = 0;
		for (char c = 'a'; c <= 'z'; c++) {
			bool left = false;
			bool right = false;
			for (int j = 0; j < i; j++) {
				if (s[j] == c)
					left = true;
			}
			for (int j = i; j < n; j++) {
				if (s[j] == c)
					right = true;
			}
			if (left&&right) count++;
		}
		ans = max(ans, count);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m;
    cin>>n>>m;
    vector<vector<int> > ab(m);
    for(int i=0;i<n;i++){
        int a,b;
        cin>>a>>b;
        if(a>m)continue;
        ab[m-a].push_back(b);
    }
    priority_queue<int> q;
    int ans=0;
    for(int i=m-1;i>=0;i--){
        for(int b : ab[i]){
            q.push(b);
        }
        if(!q.empty()){
            ans+=q.top();
            q.pop();
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 5504
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def gen_comb(n):
    c = []
    for i in range(n):
        for comb in itertools.combinations([j for j in range(n)], i):
            c.append(list(comb))
    return c

def count(C, arr1, arr2):
    n_row = len(C)
    n_col = len(C[0])
    s1 = set(arr1)
    s2 = set(arr2)
    cnt = 0
    for r in range(n_row):
        for c in range(n_col):
            if r in s1:
                continue
            if c in s2:
                continue
            if C[r][c] == '#':
                cnt += 1
    return cnt

def main():
    H, W, K = LI()
    C = []
    for i in range(H):
        C.append(S())

    h_comb = gen_comb(H)
    w_comb = gen_comb(W)
    cnt = 0
    for ixs in h_comb:
        for jxs in w_comb:
            if count(C, ixs, jxs) == K:
                cnt += 1
    print(cnt)


main()



Measured memory_bytes: 79192
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const ll INF=1e18;
const int MOD=1e9+7;
const double pi=acos(-1);

int main(){
  ll n;
  cin >> n;
  vector<ll>a(n+2);
  a[0]=0;
  a[n+1]=0;
  ll now=0;
  ll sum=0;
  rep(i,n){
    cin >> a[i+1];
    sum+=abs(a[i+1]-a[i]);
  }
  sum+=abs(a[n+1]-a[n]);
  rep(i,n){
     cout << sum-abs(a[i+1]-a[i])-abs(a[i+2]-a[i+1])+abs(a[i+2]-a[i]) << endl;   
  }
  
}

Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, l, r) for(int i = l; i <= r; ++i)
const int N = 100000 + 5;
bool book[N];
int n, m, k, tmp, cnt, a[N], d[N], p[N], dp[N], nxt[N], ans[N];
vector <int> G[N];
int read(){
    char c; int x = 0, f = 1;
    c = getchar();
    while(c > '9' || c < '0'){ if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}
signed main(){
    n = read();
    rep(i, 1, n) d[i] = read(), p[i] = i, dp[i] = d[i] - d[i - 1];
    m = read(), k = read();
    rep(i, 1, m) a[i] = read(), swap(p[a[i]], p[a[i] + 1]);
    rep(i, 1, n) nxt[i] = p[i]; 
    rep(i, 1, n) if(!book[i]){
        int x = i; G[++cnt].push_back(i), book[i] = true;
        while(nxt[x] != i) x = nxt[x], book[x] = true, G[cnt].push_back(x);
    }
    rep(i, 1, cnt){
        int S = G[i].size(), tr = k % S;
        rep(j, 0, S - 1) ans[G[i][j]] = dp[G[i][(j + tr) % S]];
    }
    rep(i, 1, n) tmp += ans[i], printf("%lld.0\n", tmp);
    return 0;
}

Measured memory_bytes: 13104
// I 
// A M 
// T H E
// B E S T

// I 
// B E L I E V E 
// I N
// M Y S E L F
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<pair<long long,long long> > vpll;
typedef vector<vector<pair<ll,ll> > > vvpll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
 
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define all(x) x.begin() , x.end()
#define pb push_back
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define mp make_pair
#define F first
#define S second
#define left (node << 1)
#define right (node << 1) + 1
#define pii pair<int,int> 
#define mii map<int,int>
#define vi vector<int>
#define umii unordered_map<int,int>
// #define mod 998244353
#define mod 1000000007 
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<": " <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define FILL(name,val) memset(name , val , sizeof(name))
#define repo(i,o,e) for(int i = o ; i < e ; i++)
#define rep(n) for(int i = 0 ; i < n ; i++)
#define repa(i,sta,end,inc) for(int i = sta ; i <= end ; i += inc)
#define repb(i,sta,end,inc) for(int i = sta ; i >= end ; i -= inc)
const ll sz = 1e5+5;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
 
const ll inf = 1000000000LL * 1000000000LL;

/*
ll power(ll x , ll y){
    ll res = 1;
    x %= mod;
    while(y){
        if(y&1){
            res = res * x % mod;
        }
        x = x*x % mod;
        y /= 2;
    }
    return res%mod;
}
*/

void solve(){
    int n;
    cin >> n;
    repa(i,1,9,1){
        if(n % i == 0){
            if(n / i < 10){
                cout << "Yes" << endl;
                return;
            }
        }
    }
    cout << "No" << endl;
    return;
}



int main(){
    FIO;
    int t = 1;
    // cin >> t;   
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atcoder
{

    class Atcoderrrrrrr
    {
        static void Main(string[] args)
        {
            string N = Console.ReadLine();
            List<long> lucas = new List<long>();
            for (int i = 0; i < 87; i++)
            {
                if (i==0)
                {
                    lucas.Add(2);
                }else if (i ==1)
                {
                    lucas.Add(1);
                }else{
                    lucas.Add(lucas[i-1]+lucas[i-2]);
                }
            }
            Console.WriteLine(lucas[int.Parse(N)]);
        }
    }
}


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

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

	for (int64_t a = 1; a <= n; a++)
	{
		int64_t ans = 0;

		for (int64_t x = 1; x * x <= a; x++)
		{
			for (int64_t y = 1; x * x + y * y <= a; y++)
			{
				int64_t ok = 1, ng = 101;
				while (1 < abs(ok - ng))
				{
					int64_t mid = (ok + ng) / 2;

					((x * x + y * y + mid * mid + x * y + y * mid + mid * x <= a) ? ok : ng) = mid;
				}

				if (0 < ok && x * x + y * y + ok * ok + x * y + y * ok + ok * x == a)
				{
					ans++;
				}
			}
		}

		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 3548
#include <iostream>
#include <algorithm>
#include <cstring>

using namespace std;

int main(){

  int n, m;

  while(cin >> n, n){
    int x, y, move, j;
    int lux[21][21];
    char c;
    memset(lux, 0, sizeof(lux));
    for(int i = 0; i < n; i++){
      cin >> x >> y;
      lux[x][y] = 1;
    }
    cin >> m;
    x = y = 10;
    for(int i = 0; i < m; i++){
      cin >> c >> move;
      if(c == 'N'){
        for(j = 1; j <= move; j++) lux[x][y+j] = 0;
        y += move;
      }else if(c == 'E'){
        for(j = 1; j <= move; j++) lux[x+j][y] = 0;
        x += move;
      }else if(c == 'S'){
        for(j = 1; j <= move; j++) lux[x][y-j] = 0;
        y -= move;
      }else if(c == 'W'){
        for(j = 1; j <= move; j++) lux[x-j][y] = 0;
         x -= move;
      }
    }
    int flag = 1;
    for(int i = 0; i < 21; i++){
      for(int j = 0; j < 21; j++){
        if(lux[i][j] == 1){
          flag = 0;
        }
      }
    }
    if(flag){
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 3064
// 問題URL
// https://atcoder.jp/contests/abc140/tasks/abc140_a

import java.util.Scanner;
import java.util.Arrays;

public class Main {
    public static void main(String[] args) {
        //コード
        Scanner scanner = new Scanner(System.in);

        int n = Integer.parseInt(scanner.next());
        int result;
        result = n * n * n;


        System.out.println(result);
    }
}

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

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

int main(){
  int n;
  cin >> n;
  int INF = 1e5 + 1;
  vector<int> dp(n+1, INF);
  dp[0] = 0;
  rep(i, n+1){
    int power = 1;
    while(power <= i){
      chmin(dp[i], dp[i - power] + 1);
      power *= 6;
    }
    power = 9;
    while(power <= i){
      chmin(dp[i], dp[i - power] + 1);
      power *= 9;
    }
  }
  cout << dp[n] << endl;
  return 0;
}

Measured memory_bytes: 3728
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

enum inf = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;

alias Pair = Tuple!(int, "a", int, "b");

void main() {
    int N;
    scan(N);
    if (N == 0) {
        writeln(0);
        return;
    }
    auto ans = f(N).stripLeft('0');
    writeln(ans);
}

string f(int N) {
    if (N == 0) {
        return "0";
    }
    int b = (N % 2 + 2) % 2;
    if (b) N -= 1;
    return f(N / (-2)) ~ b.to!string;
}





void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner scan=new Scanner(System.in);
        int n=scan.nextInt();
        int[] a=new int[n+1];
        for(int i=0;i<n-1;i++){
            int b=scan.nextInt();
            a[b]++;
        }
        for(int i=1;i<=n;i++){
            System.out.println(a[i]);
        }
    }
}

Measured memory_bytes: 60452
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++)
  {
    cin >> a[i];
  }
  for (int k = 0; k < n; k++)
  {
    if (k)
      cout << ' ';
    cout << a[k];
  }
  cout << endl;
  for (int i = 1; i < n; i++)
  {
    int key = a[i];
    int j = i - 1;
    while (j >= 0 and a[j] > key)
    {
      a[j + 1] = a[j];
      j--;
    }
    a[j + 1] = key;
    for (int k = 0; k < n; k++)
    {
      if (k)
        cout << ' ';
      cout << a[k];
    }
    cout << endl;
  }
}


Measured memory_bytes: 3108
#include <bits/stdc++.h>
#define L(i, m, n) for(int i(m);i < n;i++)
#define pb push_back
#define D(X) cout<<"  "<<#X": "<<X<<endl;
#define in(x) cin >> x
#define SZ(X) int(X.size())
#define clr(A, V) L(i, 0, 111) A[i]=V
#define ff first
#define ss second
#define RF(X) freopen(X, "r", stdin)
#define WF(X) freopen(X, "w", stdout)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef pair<int,int> pii;
typedef vector<pii> vpii;
typedef pair<int, string> pis;
typedef vector<string> vs;
typedef pair<pair<int, int>, pair<int, int > > piiii;
const int N=100005;
pair<pii,int> p[N];
vpii adj[N];
vi taken;
priority_queue<pii>pq;
void process(int vtx){
    taken[vtx]=1;
    L(j,0,SZ(adj[vtx])){
        pii v=adj[vtx][j];
        if(!taken[v.ff])pq.push({-v.ss,-v.ff});
    }
}
bool cmp(pair<pii, int> &p1,pair<pii, int> &p2){
    if(p1.ff.ss<p2.ff.ss)return 1;
    if(p1.ff.ss==p2.ff.ss && p1.ff.ff<p2.ff.ff) return 1;
    return 0;
}
int main(){
    int n;in(n);
    L(i,0,n){
        in(p[i].ff.ff),in(p[i].ff.ss);p[i].ss=i;
    }
    sort(p,p+n);

    for(int i=1;i<n;i++){
        int cost=p[i].ff.ff-p[i-1].ff.ff;
        adj[p[i].ss].pb({p[i-1].ss,cost});
        adj[p[i-1].ss].pb({p[i].ss,cost});
    }
    sort(p,p+n,cmp);
    for(int i=1;i<n;i++){
        int cost=p[i].ff.ss-p[i-1].ff.ss;
        adj[p[i].ss].pb({p[i-1].ss,cost});
        adj[p[i-1].ss].pb({p[i].ss,cost});
    }
    taken.assign(n+1,0);
    process(0);
    int mst_cost=0;
    while(!pq.empty()){
        pii front=pq.top();pq.pop();
        int u = -front.ss, w=-front.ff;
        if(!taken[u]) mst_cost+=w, process(u);
    }
    cout << mst_cost <<endl;
}


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

#define ll long long int
#define LD long double

const int N = 100010;

int inf = 1e9;
int mod = 1e9 + 7;

signed main()
{
    //freopen("IN.txt", "r", stdin);
    //freopen("OUT.txt", "w", stdout);

    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    int h, w, a, b; cin >> h >> w >> a >> b;

    int ans[h][w];

    for(int i = 0; i < h; i++) {
        for(int j = 0; j < w; j++) {
            ans[i][j] = 0;
        }
    }

    for(int i = 0; i < b; i++) {
        for(int j = 0; j < a; j++) {
            ans[i][j] = 1;
        }
    }

    for(int i = b; i < h; i++) {
        for(int j = a; j < w; j++) {
            ans[i][j] = 1;
        }
    }

    for(int i = 0; i < h; i++) {
        for(int j = 0; j < w; j++) {
            cout << ans[i][j];
        }
        cout << "\n";
    }


    return 0;
}


Measured memory_bytes: 5120
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std;
#define EPS (1.0e-9)
#define equals(a, b) (fabs((a) - (b)) < EPS)
#define COUNTER_CLOCKWISE 1
#define CLOCKWISE -1
#define ONLINE_BACK 2
#define ONLINE_FRONT -2
#define ON_SEGMENT 0

class Point {
public:
  double x, y;
  Point(double x = 0, double y = 0) : x(x), y(y) {}
  Point operator + (Point p) { return Point(x + p.x, y + p.y); }
  Point operator - (Point p) { return Point(x - p.x, y - p.y); }
  Point operator * (double a) { return Point(x*a, y*a); }
};

typedef Point Vector;

class Segment {
public:
  Point p1, p2;
};
typedef Segment Line;

double dot(Vector a, Vector b) { return a.x*b.x + a.y*b.y; }
double cross(Vector a, Vector b) { return a.x*b.y - a.y*b.x; }
double norm(Vector a) { return a.x*a.x + a.y*a.y; }

int ccw(Point p0, Point p1, Point p2) {
  Vector a = p1 - p0;
  Vector b = p2 - p0;
  if(cross(a, b) > EPS) return COUNTER_CLOCKWISE;
  if(cross(a, b) < -EPS) return CLOCKWISE;
  if(dot(a, b) < -EPS) return ONLINE_BACK;
  if(norm(a) < norm(b)) return ONLINE_FRONT;
  return ON_SEGMENT;
}

bool isIntersect(Point p1, Point p2, Point p3, Point p4) {
  return ( ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0 &&
	   ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0 );
}

bool isIntersect(Segment s1, Segment s2) {
  return isIntersect(s1.p1, s1.p2, s2.p1, s2.p2);
}

Point getCrossPoint(Segment s1, Segment s2) {
  Vector base = s2.p2 - s2.p1;
  double d1 = fabs(cross(s1.p1 - s2.p1, base));
  double d2 = fabs(cross(s1.p2 - s2.p1, base));
  double t = d1/(d1+d2);
  return s1.p1 + (s1.p2 - s1.p1)*t;
}
double getTofCrossPoint(Segment s1, Segment s2) {
  Vector base = s2.p2 - s2.p1;
  double d1 = fabs(cross(s1.p1 - s2.p1, base));
  double d2 = fabs(cross(s1.p2 - s2.p1, base));
  return d1/(d1+d2);
}

Segment S;
int N;
Segment Q[100];
int O[100], H[100];

class CrossPoint {
public:
  int o, l;
  double t;
  CrossPoint(int o, int l, double t) : o(o), l(l), t(t) {}
  bool operator < (const CrossPoint &cp) const {
    return t < cp.t;
  }
};

void solve() {
  vector<CrossPoint> cp;

  for(int i = 0; i < N; ++i) {
    if(!isIntersect(S, Q[i])) continue;
    cp.push_back(CrossPoint(O[i], H[i], getTofCrossPoint(S, Q[i])));
  }
  if(cp.size() == 0) {
    cout << 0 << endl;
    return;
  }
  sort(cp.begin(), cp.end());

  int ans = 0;
  int nl;

  if(cp[0].o == 1) nl = cp[0].l;
  else             nl = 1 - cp[0].l;
  for(int i = 1; i < cp.size(); ++i) {
    if(cp[i].o == 1 && cp[i].l != nl ||
       cp[i].o == 0 && cp[i].l == nl ) {
      nl = 1 - nl;
      ++ans;
    }
  }
  cout << ans << endl;
}

main() {
  int T;
  cin >> T;
  for(int t = 0; t < T; ++t) {
    cin >> S.p1.x >> S.p1.y >> S.p2.x >> S.p2.y;
    cin >> N;
    for(int i = 0; i < N; ++i) {
      cin >> Q[i].p1.x >> Q[i].p1.y >> Q[i].p2.x >> Q[i].p2.y
	  >> O[i] >> H[i];
    }
    solve();
  }
}

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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define spa << " " <<
ll MOD = 1e9+7;
void chmin(ll &a, ll b) { if (a > b) a = b; }
void chmax(ll &a, ll b) { if (a < b) a = b; }

int main(){
  ll i, j;
  ll n, m;
  cin >> n >> m;
  cout << n - m + 1 << endl;

  return 0;
}

Measured memory_bytes: 256
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    let A = ~~arg[0].split(" ")[0];
    let B = ~~arg[0].split(" ")[1];
    
    let answer = 0;
    
    if(A > B) {
        answer += A;
        A--;
    } else {
        answer += B;
        B--;
    }
    
    if(A > B) {
        answer += A;
        A--;
    } else {
        answer += B;
        B--;
    }
    
    console.log(answer);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

int main(){
  	ll N,Q; cin>>N>>Q;
  	string s; cin>>s;
  	s=s+'A';
  	vector<ll> l(Q+1);
  	vector<ll> r(Q+1);
  	rep1(i,Q) cin>>l[i]>>r[i];
  	vector<ll> x(N,0);
  	rep1(i,N-1){
    	if(s[i-1]=='A' && s[i]=='C') x[i]=x[i-1]+1;
      	else x[i]=x[i-1];
    }
  	rep1(i,Q){
    	ll tmpr=r[i]-1,tmpl=l[i]-1;
      	printf("%lld\n",x[tmpr]-x[tmpl]);
    }
}

Measured memory_bytes: 3452
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0; i<(n); i++)
#define REP2(i,x,n) for(ll i=x; i<(n); i++)
#define REP3(i,x,n) for(ll i=x; i>(n); i--)
#define ALL(n) begin(n),end(n)
#define MAX 500000
#define SENTINEL 2000000000
#define NIL -1
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();


struct Node{ll parent,left,right;};
struct Node T[MAX];
ll D[MAX],N,H[MAX];

//二分木のノードの高さ
ll setHeight(ll u){
    ll h1=0,h2=0;
    if(T[u].right!=NIL){
        h1 = setHeight(T[u].right)+1;
    }
    if(T[u].left!=NIL){
        h2 = setHeight(T[u].left)+1;
    }
    return H[u] = max(h1,h2);
}

//u:ノード番号　D:各ノードの深さ 右の兄弟の深さと、最左のこの深さを探索　
void setDepth(ll u,ll p){
    if(u==NIL)return;
    D[u] = p;
    setDepth(T[u].right,p+1);
    setDepth(T[u].left, p+1);
}
//節点uの兄弟を探す
ll getSibling(ll u){
    if(T[u].parent == NIL)return NIL;
    if(T[T[u].parent].left!=u&&T[T[u].parent].left!=NIL){
        return T[T[u].parent].left;
    }
    if(T[T[u].parent].right!=u&&T[T[u].parent].right!=NIL){
        return T[T[u].parent].right;
    }
    return NIL;
}

void printChildren(ll u){
    ll i,c;
    cout << "node " << u << ": ";
    cout << "parent = " << T[u].parent << ", ";
    cout << "sibling = " << getSibling(u) << ", ";
    int deg = 0;
    if(T[u].left!=NIL)deg++;
    if(T[u].right!=NIL)deg++;
    cout << "degree = " << deg << ", ";
    cout << "depth = " << D[u] << ", ";
    cout << "height = " << H[u] << ", ";
    if(T[u].parent == NIL)cout << "root"<<endl;
    else if(T[u].left == NIL&&T[u].right==NIL)cout << "leaf"<<endl;
    else cout << "internal node"<<endl;
    
    // cout << "[";
    // for(ll i = 0,c = T[u].left;c != NIL;i++,c = T[c].right){
    //     if(i)cout <<", ";
    //     cout << c;
    // }
    // cout << "]" << endl;
    // ll c = T[u].left;
    // while(c != NIL){
    //     cout << c;
    //     c = T[c].right;
    // }
}


int main(){
    ll i,j,d,v,c,left,right,root=0;
    cin >> N;
    //初期化
    REP(i,N){
        T[i].parent  = NIL;
    }

    REP(i,N){
        cin >> v >> left >> right;
        T[v].left = left;
        T[v].right = right;
        if(left!=NIL)T[left].parent = v;
        if(right!=NIL)T[right].parent = v;
    }
    REP(i,N){
        if(T[i].parent == NIL)root = i;
    }
    setDepth(root,0);
    setHeight(root);
    REP(i,N)printChildren(i);
    return 0;
}


Measured memory_bytes: 3172
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(container) container.begin(),container.end()
#define fast ios::sync_with_stdio(0); cin.tie(0)
#define int long long
const int mod = 1e9+7;  
int power(int a,int b) { if(b==0) return 1; int res = power(a,b/2); if(b&1) return res * res * a; else return res * res; }
 
int mat[20][20];
 
bool isValid(int x,int y,int n,int m){
  if(x>=0&&x<=n-1&&y>=0&&y<=m-1&&mat[x][y]==1) return true;
  else return false;
}
 
int bfs(pair<int,int> src,int n,int m){
 
  queue<pair<int,int>> qu;
  qu.push(src);
  int cost[n][m];
  bool vis[n][m];
 
  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
      vis[i][j] = false;
      cost[i][j] = 0;
    }
  }
  
  int maxx = 0;
 	vis[src.first][src.second] = 1;
  while(!qu.empty()){ 
    
    pair<int,int> p = qu.front();
    int x = p.first , y = p.second;
    qu.pop();
    maxx = max(maxx,cost[x][y]);
    
    if(isValid(x,y-1,n,m)&&!vis[x][y-1]){
      qu.push({x,y-1});
      cost[x][y-1] = cost[x][y] + 1;
      vis[x][y-1] = 1;
    }
    
    if(isValid(x,y+1,n,m)&&!vis[x][y+1]){
      qu.push({x,y+1});
      cost[x][y+1] = cost[x][y] + 1;
      vis[x][y+1] = 1;
    }
    
    if(isValid(x-1,y,n,m)&&!vis[x-1][y]){
      qu.push({x-1,y});
      cost[x-1][y] = cost[x][y] + 1;
      vis[x-1][y] = 1;
    }
    
    if(isValid(x+1,y,n,m)&&!vis[x+1][y]){      
      qu.push({x+1,y});
      cost[x+1][y] = cost[x][y] + 1;
      vis[x+1][y] = 1;
    }
  }
 
  return maxx;
}
 
 
int32_t main(){
    
  fast;
  int n,m; cin >> n >> m;
  
  vector<pair<int,int>> vp;
 
  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++){
      char c; cin >> c;
      if(c=='.'){
        vp.pb({i,j});
        mat[i][j] = 1;
      }else{
        mat[i][j] = 0;
      } 
    }
  }
 
  int ans = 0;
 
  for(int i=0;i<vp.size();i++){
    int ct = bfs({vp[i].fi,vp[i].se},n,m);
    ans = max(ans,ct);
  }
 
  cout << ans;
 
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <math.h>
#include <sstream>
#include <iterator>

using namespace std;

#define endl ("\n")
#define pi (3.141592653589)
#define mod 1000000007
#define int long long
#define float double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(c) c.begin(), c.end()
#define min3(a, b, c) min(c, min(a, b))
#define min4(a, b, c, d) min(d, min(c, min(a, b)))
#define rrep(i, n) for(int i=n-1;i>=0;i--)
#define rep(i,n) for(int i=0;i<n;i++)
#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)

struct debugger
{
    template<typename T> debugger& operator , (const T& v)
    {    
        cerr<<v<<" ";    
        return *this;    
    }
} dbg;

int32_t main() 
{
    fast;
    int N, K;
    cin >> N >> K;
    vector<int> x(N, 0);
    for(int i = 0; i < K; i++){
        int d;
        cin >> d;
        for(int i = 0; i < d; i++){
            int A;
            cin >> A;
            A--;
            x[A]=1;
        }
    }
    int res = 0;
    for(auto thing: x){
        if(thing==0) res++;
    }
    cout << res;
}




Measured memory_bytes: 3644
A,B,K= list(map(int,input().split()))

AK = A+K-1
BK = B-K+1
for i in range(A,A+K):
  if i <= B:
    if i >= A and i <= AK:
      print(i)
for i in range(BK,B+1): 
  if (i <= AK)!=1:
    if i >= BK and i <= B:
      print(i)

Measured memory_bytes: 3060