akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
    #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()
    {
       vector<int> a(5,0);
        vector<int> b(5,0);
        vector<int> d(5,0);
        int ans=0;
 
       for(int i=0; i<5; i++)
       {
           cin>>a[i];
 
           if(a[i]%10!=0)
           {
               b[i]=(a[i]/10+1)*10;
           }
           else {b[i]=a[i];}
           d[i]=b[i]-a[i];
           ans+=b[i];
       }
       sort(d.begin(),d.end(),greater<int>());
       cout<<ans-d[0]<<endl;
    }

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
using namespace std;
#define lli long long int
#define mod 1000000007
lli dp[5000];
lli solve(lli x)
{
	if(x==3 || x==4 || x==5)
	{
		dp[x]=1;
		return 1;
	}
	if(x<3)
	{
		dp[x]=0;
		return 0;
	}
	if(dp[x]!=-1)
	{
		return dp[x];
	}
	lli ans=1;
	for(lli i=3;i<x;i++)
	{
		ans+=solve(x-i);
	}
	ans=ans%mod;
	dp[x]=ans;
	return ans;
}
int main()
{
  lli x;
  cin>>x;
  for(lli i=0;i<=x+1;i++)
  {
  	dp[i]=-1;
  }
  cout<<solve(x)<<endl;
}//main

Measured memory_bytes: 3652
module MakeBinaryHeap (M : sig type t val compare : t -> t -> int end) = struct

  type t = { node : M.t array; mutable size : int }

  let make n (init : M.t) = { node = Array.make n init; size = 0 }

  let empty_p t = if t.size = 0 then true else false

  let pop t =
    if t.size <= 0 then failwith "out of size" else
    let rec max_heapify i =
      let l = 2*i in
      let r = 2*i + 1 in
      let m = if l <= t.size && M.compare t.node.(l) t.node.(i) > 0 then l else i in
      let m = if r <= t.size && M.compare t.node.(r) t.node.(m) > 0 then r else m in
      if m = i then ()
      else begin
        let tmp = t.node.(i) in
        t.node.(i) <- t.node.(m);
        t.node.(m) <- tmp;
        max_heapify m
      end in
    let ret = t.node.(1) in
    t.node.(1) <- t.node.(t.size);
    t.size <- t.size - 1;
    max_heapify 1;
    ret

  let push x t =
    let parent i = int_of_float (floor (float_of_int i) /. 2.) in
    let rec doit i =
      let p = parent i in
      if i <= 1 || M.compare t.node.(p) t.node.(i) >= 0 then ()
      else begin
        let tmp = t.node.(i) in
        t.node.(i) <- t.node.(p);
        t.node.(p) <- tmp;
        doit p
      end in
    t.size <- t.size + 1;
    t.node.(t.size) <- x;
    doit t.size

end

module H = MakeBinaryHeap(struct type t = (int * int) let compare (_, x) (_, y) = y - x end)

let dijkstra g n =
  let reached_p = Array.make n false in
  let min_costs = Array.make n max_int in
  min_costs.(0) <- 0;
  let h = H.make 10000 (0, 0) in
  H.push (0, 0) h;
  while not (H.empty_p h) do
    let (u, x) = H.pop h in
    reached_p.(u) <- true;
    if x > min_costs.(u) then ()
    else
      List.iter (fun (v, c) ->
        let x = min_costs.(u) + c in
        if not reached_p.(v) && x < min_costs.(v) then begin
          min_costs.(v) <- x;
          H.push (v, x) h;
        end) g.(u);
  done;
  min_costs

let rec make_pair acc = function
  | [] -> acc
  | v :: c :: tl -> make_pair ((v, c) :: acc) tl
  | _ -> assert false

let make_pair lst = make_pair [] lst

let split_on_char sep s =
  let open String in
  let r = ref [] in
  let j = ref (length s) in
  for i = length s - 1 downto 0 do
    if get s i = sep then begin
      r := sub s (i + 1) (!j - i - 1) :: !r;
      j := i
    end
  done;
  sub s 0 !j :: !r

let () =
  let n = read_int () in
  let g = Array.make n [] in
  for _ = 0 to n - 1 do
    match read_line () |> split_on_char ' ' |> List.map int_of_string with
    | u :: _ :: l -> g.(u) <- make_pair l
    | _ -> assert false
  done;
  dijkstra g n |> Array.iteri (fun i e -> Printf.printf "%d %d\n" i e)

Measured memory_bytes: 3372
class PriorityQueue
  def initialize(array = [])
    @data = []
    array.each{|a| push(a)}
  end

  def push(element)
    @data.push(element)
    bottom_up
  end

  def pop
    if size == 0
      return nil
    elsif size == 1
      return @data.pop
    else
      min = @data[0]
      @data[0] = @data.pop
      top_down
      return min
    end
  end

  private

  def swap(i, j)
    @data[i], @data[j] = @data[j], @data[i]
  end

  def size
    @data.size
  end

  def parent_idx(target_idx)
    (target_idx - (target_idx.even? ? 2 : 1)) / 2
  end

  def bottom_up
    target_idx = size - 1
    return if target_idx == 0
    parent_idx = parent_idx(target_idx)
    while (@data[parent_idx] > @data[target_idx])
      swap(parent_idx, target_idx)
      target_idx = parent_idx
      break if target_idx == 0
      parent_idx = parent_idx(target_idx)
    end
  end

  def top_down
    target_idx = 0

    # child がある場合
    while (has_child?(target_idx))
      a = target_idx*2+1
      b = target_idx*2+2

      # 右側の child が無い場合
      if @data[b].nil?
        if @data[target_idx] > @data[a]
          swap(target_idx, a)
        end
        return
      end

      if @data[a] < @data[b]
        if @data[target_idx] > @data[a]
          swap(target_idx, a)
          target_idx = a
        else
          return
        end
      else
        if @data[target_idx] > @data[b]
          swap(target_idx, b)
          target_idx = b
        else
          return
        end
      end
    end
  end

  # @param Integer
  # @return Integer
  def left_child_idx(idx)
    (idx * 2) + 1
  end

  # @param Integer
  # @return Integer
  def right_child_idx(idx)
    (idx * 2) + 2
  end

  # @param Integer
  # @return Boolent
  def has_child?(idx)
    ((idx * 2) + 1) < (@data.size - 1)
  end
end


N, M = gets.chomp.split(' ').map(&:to_i)

AB = []
N.times do |i|
  AB[i] = gets.chomp.split(' ').map(&:to_i)
end

group_by_day = Hash[AB.group_by{|v|v[0]}.sort]

day_fee = Array.new(M){[]}
group_by_day.each do |k,v|
  day_fee[k-1] = v.map{|j| j[1]}
end

# require 'pry'
# binding.pry

ans = 0
pq = PriorityQueue.new
day_fee.each_with_index do |fees, idx|
  break if idx > M - 1
  fees.each do |fee|
    pq.push(fee*(-1))
  end
  ans += pq.pop.to_i
  # p pq
  # p pq.pop*(-1)
end

puts ans*(-1)


Measured memory_bytes: 38284
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
vector<int> dx = {-1, -1, -1, 0, 0, 1, 1, 1};
vector<int> dy = {-1, 0, 1, -1, 1, -1, 0, 1};

int main () {
    int x, n; cin >> x >> n;
    map<int, int> mp;
    rep(i, n) {
        int p; cin >> p;
        mp[p]++;
    }
    int cnt = 10000, ans;
    for (int i = -200; i <= 200; i++) {
        if (mp[i] > 0) continue;
        if (abs(i-x) < cnt) {
            ans = i;
            cnt = abs(i-x);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    int c[4], n;
    for (auto& x : c) cin >> x; cin >> n;

    int t[4];
    for (int i = 0; i < 4; i++) t[i] = (1 << (3 - i)) * c[i];

    long long ans = n % 2 ? min({t[0], t[1], t[2]}) / 2 : 0;
    sort(t, t + 4);
    for (;n >= 2; n -= 2) ans += t[0];
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
//#include <iomanip>
//#include <algorithm>
//#include <numeric>
//#include <queue>
//#include <stack>
//#include <math.h>
#include <vector>
//#include <string>
//typedef long long LL;
using namespace std;

#define MATRIX 100010

int main(){
    int n;
    int ans;
    int tmp_a;
    int tmp_b;
    int a1=0;
    int b1=0;
    int a2=0;
    int b2=0;
    cin >> n;
    vector<int> a(MATRIX, 0);
    vector<int> b(MATRIX, 0);
    for(int i=0; i<n; i+=2){
        cin >> tmp_a;
        cin >> tmp_b;
        a[tmp_a]++;
        b[tmp_b]++;
    }
    for(int i=1; i<MATRIX; i++){
        if(a[a1]<=a[i]){
            a2=a1;
            a1=i;
        }else if(a[a2]<=a[i]){
            a2=i;      
        }
        if(b[b1]<=b[i]){
            b2=b1;
            b1=i;
        }else if(b[b2]<=b[i]){
            b2=i;      
        }
    }
    if(a1!=b1){
        ans = n-(a[a1]+b[b1]);
    }else if((a[a1]+b[b2])>(a[a2]+b[b1])){
        ans = n-(a[a1]+b[b2]);
    }else{
        ans = n-(a[a2]+b[b1]);
    }
    cout << ans << endl;
}

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

int main(){
    int X;
    int b,p=2;
    int max=0,tmp=0;

    scanf("%d",&X);

    if((1<=X)&&(X<=3)){
        printf("1\n");
        return 0;
    }

    for(b=2;b<=31;b++){
        p = 2;

        while(pow(b,p)<=X){
            
            tmp = (int)pow(b,p);

            p++;
        }
        if(max < tmp){
            max = tmp;
        }
    }

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

    return 0;
}

Measured memory_bytes: 128
x, y = map(int, raw_input().split())

def group(n):
    if n == 2:
        return 1
    elif n == 4 or n == 6 or n == 9 or n == 11:
        return 2
    else:
        return 3

if group(x) == group(y):
    print 'Yes'
else:
    print 'No'

Measured memory_bytes: 2568
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Scanner;

 class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        final int inf = (int) 1e9 + 5;
        int[] h = new int[n];
        for (int i = 0; i < n; i++) h[i] = sc.nextInt();
        int[] dp = new int[n];
        Arrays.fill(dp, 1, n, inf);
        dp[0] = 0;
        for (int i = 0; i < n; i++) {
          int[] a = {i + 1, i + 2};
          for (int j : a)
            if (j < n) {
              dp[j] = Math.min(dp[j], dp[i] + Math.abs(h[i] - h[j]));
            }
        }
        System.out.println(dp[n - 1]);
  }
}


Measured memory_bytes: 48736
def resolve():
    a, b = map(int, input().split())
    ans = 0
    for d1 in range(1, 10):
        for d2 in range(10):
            for d3 in range(10):
                d = d1 * 10000 + d2 * 1000 + d3 * 100 + d2 * 10 + d1
                if a <= d <= b:
                    ans += 1
    print(ans)


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 38256
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<vector>
#include<string.h>
#include<math.h>
#include<stdio.h>
#include<queue>
#include<utility>
#include<cstdio>
#include<cstring>
#define fo(i,w,n) for(int i=(int) w;i<(int) n;i++)
#define qui queue<int>
#define vit vector<int>
#define ll long long
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define prq priority_queue
#define pii pair<int,int>
#define mp make_pair
#define sz size()
#define em empty()
#define ct continue
#define ms multiset
#define all(a) (a).begin(),(a).end()
int a[202020],n,ans=0;
using namespace std;
int main()
{
	cin>>n;
	fo(i,0,n){
		cin>>a[i];
		ans+=a[i]-1;
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

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


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 1120000000

bool solve(){
  int n;
  cin>>n;
  vector<vector<int>> tree(n);
  vector<int> rev(n), cnt(n), a(n, -1);

  rep(i,n){
    int p; cin>>p; p--;
    tree[p].pb(i);
    cnt[p]++;
    rev[i] = p;
  }

  auto mex = [&](int v, vector<int> &num){
    vector<int> vv;
    for(auto d : tree[v]) vv.pb(num[d]);
    uniq(vv);
    int x = 0;
    while(x < vv.size() && vv[x]==x) x++;
    return x;
  };

  auto bfs = [&](queue<int> &q, vector<int> &num, vector<int> &c){
    int last = -1;
    while(!q.empty()){
      int v = q.front(); q.pop();
      num[v] = mex(v, num);
      c[rev[v]]--;
      if(c[rev[v]]==0 && num[rev[v]]==-1) q.push(rev[v]);
      last = v;
    }
    return last;
  };

  {
    queue<int> q;
    rep(i,n) if(cnt[i]==0) q.push(i);
    bfs(q,a,cnt);
  }

  int s = -1;
  rep(i,n) if(a[i]==-1) s=i;

  if(s==-1) return true;

  vector<int> vv;
  for(auto d : tree[s]) if(a[d]!=-1) vv.pb(a[d]);
  uniq(vv);
  int c1=0;
  while(c1 < vv.size() && vv[c1]==c1) c1++;
  int c2 = c1+1;
  while(c2-1 < vv.size() && vv[c2-1]==c2) c2++;


  rep(_,2){
    // try c1
    vector<int> b(a);
    vector<int> cc(cnt);
    cc[s] = 0;
    b[s] = c1;
    queue<int> q;
    q.push(rev[s]);

    int last = bfs(q,b,cc);
    if(b[last]!=b[s] && b[s]==mex(s,b)) return true;

    swap(c1,c2);
  }

  return false;
}

int main(){
  if(solve()) cout << "POSSIBLE" << endl;
  else cout << "IMPOSSIBLE" << endl;

  return 0;
}


Measured memory_bytes: 14080
#include <algorithm>
#include <iostream>

using std::cin;
using std::cout;
using std::endl;
using std::min;

int
main()
{
  int N;
  cin >> N;
  // 9 0 1000 0 100000
  cout << ((10000 <= N ? min(99999, N) - 9999 : 0)
           + (100 <= N ? min(999, N) - 99 : 0) + min(9, N))
       << endl;
  return 0;
}


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

int n, a[300000];
long long int ans;

int main(void){
  cin >> n;
  for(int i = 0; i < 3 * n; i++){
    cin >> a[i];
  }
  sort(a, a + 3 * n);
  
  for(int i = 1; i <= n; i++){
    ans += a[3 * n - 2 * i];
  }

  cout << ans << endl;
}


Measured memory_bytes: 1408
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
			　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <iostream>
#include <vector>
#include <array>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <climits>
#include <tuple>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cmath>
#include <algorithm>
#include <memory>
#include <iomanip>
#include <type_traits>

#ifdef _MSC_VER
#include <intrin.h>
#define __builtin_popcount __popcnt
#endif
#define rep(i, n) for(Int (i) = 0; (i) < (n); ++(i))
#define all(n) std::begin(n), std::end(n)
#define rall(n) std::rbegin(n), std::rend(n)
#define debug(var) std::cout << #var << ": " << var << "\n"
using Int = int64_t;
constexpr Int INF = INT_MAX;
constexpr Int mod = 1e9 + 7;


void init() {
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
}

void calc() {

	Int N; std::cin >> N;
	Int T, A; std::cin >> T >> A;
	double x = (double)500 * (double)(T - A) / (double)3;
	std::vector<Int> H(N);
	rep(i, N)std::cin >> H[i];
	Int ans = 0;
	double diff = INF;

	rep(i, N) {
		if (std::abs(x - (double)H[i]) < diff) {
			ans = i + 1;
			diff = std::abs(x - (double)H[i]);
		}
	}

	std::cout << ans;

}


int main() {

	init();
	calc();

	return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args) {
	Scanner s = new Scanner(System.in);
	while(s.hasNext()) {
	    int n = s.nextInt();
	    if(n == 0) break;
	    int[] dat = new int[n];
	    for(int i = 0; i < n; ++i) {
		dat[i] = s.nextInt();
	    }
	    int target = s.nextInt();
	    int l, r;
	    l = 0; r = dat.length-1;
	    int cnt = 0;
	    while(l <= r) {
		++cnt;
		int m = (l+r)/2;
		if(dat[m] == target) break;
		else if(dat[m] < target) l = m+1;
		else r = m-1;
	    }
	    System.out.println(cnt);
	}
    }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#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 ll long long
#define pb(a) push_back(a)
#define INF 1000000000
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  set<int> a;
  int N,b;
  cin >> N;
  
  REP(i,N){
    cin >> b;
    if(a.find(b) == a.end()) a.insert(b);
    else a.erase(b);
  }
  cout << a.size() << endl;
}


Measured memory_bytes: 4992
package main

import (
	"fmt"
)

func main() {
	var n,m,c,a int
	fmt.Scan(&n,&m,&c)
	
	b := make([]int,m)
	for i := 0; i < m; i++ {
		fmt.Scan(&b[i])
	}
	
	
	ans := 0
	for row := 0; row < n; row++ {
		sum := 0
		for column := 0; column < m; column++ {
			fmt.Scan(&a)
			sum += a * b[column]
		}
		sum += c
		if sum > 0 {
			ans++
		}
	}
	fmt.Println(ans)
}



Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include<algorithm>
#include <stdio.h>
#include <bitset>
#include<math.h>
#include<list>
#include<map>
#include <queue>
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
#define PI 3.14159265358979323846  
typedef pair<int, int> P;



int main() {
	int c;
	cin >> c;
	cout << c + pow(c, 2) + pow(c, 3) << endl;
}

Measured memory_bytes: 4284
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define MAX_N 1000100
long long inv[MAX_N];

void get_inv(){
    for (int i = 1; i < MAX_N; i++) {
        if (i == 1) inv[i] = 1;
        else {
            inv[i] = (mod - (mod / i) * inv[mod % i]) % mod;
            if (inv[i] < 0) inv[i] += mod;
        }
    }
}

long long modpow(int n, int r) {
    long long ret = 1; long long tmp = (long long) n;
    while (r != 0) {
        if (r % 2) ret *= tmp;
        tmp *= tmp; tmp %= mod; ret %= mod;
        r /= 2;
    }
    return ret;
}


int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    get_inv();
    int n; cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    set<int> s;
    for (auto &x: a) s.insert(x);
    map<int, int> m;
    for (auto &x: s) {
        int p = x;
        for (int i = 2; i * i <= p; i++) {
            if (p % i == 0) {
                int cnt = 0;
                while (p % i == 0) cnt++, p /= i;
                m[i] = max(m[i], cnt);
            }
        }
        if (p != 1) m[p] = max(m[p], 1);
    }
    long long lcm = 1;
    for (auto &iter: m) {
        lcm *= modpow(iter.first, iter.second);
        lcm %= mod;
    }
    long long ans = 0;
    for (auto &x: a) {
        ans = (ans + lcm * inv[x] % mod) % mod;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 9088
#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <algorithm>
#include <utility>
#include <cstring>
#include <cmath>
#include <cassert>
using namespace std;

constexpr long long INF=123456789012;

int main() {
    int a,b,q;
    cin>>a>>b>>q;
    vector<long long>s,t;
    vector<pair<long long,int>>x;
    long long m;
    for(int i=0;i<a;++i)cin>>m,t.push_back(m);
    for(int i=0;i<b;++i)cin>>m,s.push_back(m);
    for(int i=0;i<q;++i)cin>>m,x.push_back({m,i});
    sort(x.begin(),x.end());
    int i=0,j=0;
    vector<long long>ans(q);
    for(int qq=0;qq<q;++qq){
        long long dist=x[qq].first;
        int idx=x[qq].second;
        while(i<a&&dist>t[i])++i;
        while(j<b&&dist>s[j])++j;
        long long s1,s2,t1,t2;
        t1=i?dist-t[i-1]:INF;
        t2=i<a?t[i]-dist:INF;
        s1=j?dist-s[j-1]:INF;
        s2=j<b?s[j]-dist:INF;
        if(t1==0||t2==0)t1=t2=0;
        if(s1==0||s2==0)s1=s2=0;
        ans[idx]=min(
            min(max(s1,t1),
                max(s2,t2)),
            min(
                min(s1*2+t2,s2*2+t1),
                min(t2*2+s1,t1*2+s2))
        );
    }
    for(long long m:ans)cout<<m<<endl;
    return 0;
}


Measured memory_bytes: 5232
#include<bits/stdc++.h>
using namespace std;
#define forr(x,n) for(int x = 0; x < n; ++x)
#define pr pair<int,int>
#define ll long long int
const ll mod=998244353;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    long double l;
    int n;
    cin>>n;
    ll a[n],b[n];
    memset(b,0,sizeof(b));
    forr(i,n)
    {
        cin>>a[i];
        a[i]--;
        b[a[i]]++;
    }
    ll sum=0;
    forr(i,n)
    {
        sum=sum+(b[i]*(b[i]-1))/2;
    }

    ll x,m;
    forr(i,n)
    {
        m=b[a[i]];
        x=sum-(m*(m-1))/2;
        m--;
        x+=(m*(m-1))/2;
        cout<<x<<endl;
    }
}


Measured memory_bytes: 5760
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
#define MAXN 2000000

int H,A[MAXN + 1];

void keepMaxHeap(int i){
	int l = 2*i,r = l + 1,largest;
	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]);
		keepMaxHeap(largest);
	}
}
void insert(int key){
	H++;
	A[H] = key;
	int i = H;
	while(i > 1 && A[i/2] < A[i]){
		swap(A[i/2],A[i]);
		i = i/2;
	}
}

int extract(){
	int MaxV;
	if(H<1)return -1;
	MaxV = A[1];
	A[1] = A[H--];
	
	keepMaxHeap(1);
	
	return MaxV;
}
int main()
{
	char s[15];
	int key;
	H = 0;
	
	while(1){
		scanf("%s",s);
		if(s[0]=='e' && s[1]=='n')break;
		else if(s[0]=='i'){
			scanf("%d",&key);
			insert(key);
		}else{
			printf("%d\n",extract());
		}
	}
	return 0;
}

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

constexpr int64_t INF = 1e18;
constexpr int D = 365;
constexpr int N = 26;
int c[N];
int s[D + 1][N];
int last[D + 1][N];
int64_t score[D + 1];
int t[D + 1];

constexpr int64_t CYCLES_PER_SEC = 2800000000;
constexpr double TIMELIMIT = 1.95;
struct Timer {
	int64_t start;
	Timer() { reset(); }
	void reset() { start = getCycle(); }
	void plus(double a) { start -= (a * CYCLES_PER_SEC); }
	inline double get() { return (double)(getCycle() - start) / CYCLES_PER_SEC; }
	inline int64_t getCycle() {
		uint32_t low, high;
		__asm__ volatile ("rdtsc" : "=a" (low), "=d" (high));
		return ((int64_t)low) | ((int64_t)high << 32);
	}
};
mt19937 mt{random_device{}()};
uniform_int_distribution<int> rnd_contest(0, N - 1);
// uniform_int_distribution<int> rnd_day(1, D);
normal_distribution<> rnd_day(0, 1);

void input() {
	int _d; cin >> _d;
	for(int i = 0; i < N; ++i) {
		cin >> c[i];
	}
	for(int i = 1; i <= D; ++i) {
		for(int j = 0; j < N; ++j) {
			cin >> s[i][j];
		}
	}
}

void greedy(int day, int contest = -1) {
	if(contest != -1) {
		for(int j = 0; j < N; ++j) {
			last[day][j] = last[day - 1][j];
		}
		last[day][contest] = day;
		++day;
	}
	for(int i = day; i <= D; ++i) {
		for(int j = 0; j < N; ++j) {
			last[i][j] = last[i - 1][j];
		}
		int64_t loss = 0;
		for(int j = 0; j < N; ++j) {
			loss += c[j] * (i - last[i][j]);
		}
		int64_t maxi = -INF;
		int midx = 0;
		for(int j = 0; j < N; ++j) {
			int64_t los = loss - c[j] * (i - last[i][j]);
			if(s[i][j] - los > maxi) {
				maxi = s[i][j] - los;
				midx = j;
			}
		}
		last[i][midx] = i;
		t[i] = midx;
	}
}

int64_t calc(int day) {
	int64_t ans = score[day - 1];
	for(int i = day; i <= D; ++i) {
		for(int j = 0; j < N; ++j) {
			last[i][j] = last[i - 1][j];
		}
		last[i][t[i]] = i;
		ans += s[i][t[i]];
		for(int j = 0; j < N; ++j) {
			int64_t loss = c[j] * (i - last[i][j]);
			ans -= loss;
		}
		score[i] = ans;
	}
	return ans;
}

void output() {
	for(int i = 1; i <= D; ++i) {
		cout << t[i] + 1 << '\n';
	}
}

int main() {
	Timer timer;
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	input();
	greedy(1);
	calc(1);
	int cnt = 0, update = 0;
	while(timer.get() < TIMELIMIT) {
		int q = rnd_contest(mt);
		double pro = rnd_day(mt);
		if(pro < 0) continue;
		++cnt;
		int d = max<int>(1, D - pro / 2 * D);
		int64_t score_pre = score[D];
		int contest_pre = t[d];
		greedy(d, q);
		int64_t score_nxt = calc(d);
		if(score_nxt > score_pre) {
			update++;
		} else {
			t[d] = contest_pre;
			greedy(d, t[d]);
		}
	}
	// cerr << cnt << " " << update << '\n';
	// cerr << score[D] << '\n';
	output();
	return 0;
}


Measured memory_bytes: 4096
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <cstring>

using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vii;
typedef vector<pair<int,int>> vip;

#define ZOOM ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb push_back
#define ff it->first
#define ss it->second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(auto i=0;i<n;++i)
#define LOOP_IT(it,s) for(auto it=(s).begin();it!=(s).end();++it)


#ifdef LOCAL
#define cerr cout
#else
#endif

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::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...);
}
#else
#define trace(...)
#endif


void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif


int main(int argc,char* argv[])
{
    ZOOM

    int k,sum=0;
    cin>>k;
    for(int i=1;i<=k;++i)
    {
        for(int j=1;j<=k;++j)
        {
            for(int j2=1;j2<=k;++j2)
            {
                sum+=__gcd(i,__gcd(j,j2));
            }
        }
    }
    cout<<sum;



    return 0;
}



Measured memory_bytes: 3656
#include <cmath>
#include <iostream>
#include <string>
#include <vector> 
#include <algorithm>
#include <numeric>
#include <map>   
#include <stdio.h>

#define FOR(i,a,b) for(i=(a);i<(b);++i) 
#define FORR(i,a,b) for(i=(a);i>(b);--i)
#define REP(i,n) for(i=0;i<(n);++i)
#define REPR(i,n) for(i=(n);i>0;--i)
#define PB push_back
#define ll long long
#define INT_MAX 2147483647
#define LL_MAX 9223372036854775807
#define sortR(a,b) sort(a, b, greater<int>())

using namespace std;

long long GCD(long long a, long long b) {
	if (a < b)
		swap(a, b);
	if (b == 0) return a;
	else return GCD(b, a % b);
}
bool sosuu_check(int num) {
	int i;
	for (i = 2; i <= sqrt(num); ++i) {
		if (num%i == 0)
			return false;
	}
	return (num < 2) ? false : true;
}



int main() {
	int N, i, MAX,k;
	ll sum = 0;
	cin >> N;
	cin >> MAX;
	REP(k, N - 1) {
		cin >> i;
		if (i <= MAX)
			sum += i;
		else {
			sum += MAX;
			MAX = i;
		}
	}
	cout << sum+MAX/2 << endl;
}

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

int main(){
    long long n;
    cin >> n;
    vector<long long> a(n);
    bool flag = true;
    for(long long i = 0; i < n; i++){
        cin >> a[i];

        if(a[i] > i) flag = false;
    }

    if(flag == false){
        printf("-1\n");
        return 0;
    }

    for(long long i = 0; i < n; i++){
        if(i + 1 < n and a[i+1] - a[i] > 1){
            printf("-1\n");
            return 0;
        }
    }

    long long ans = 0;
    long long before = 0;
    for(long long i = n-1; i >= 0; i--){
        if(a[i] >= before) ans += a[i];

        before = a[i];
    }

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

Measured memory_bytes: 4852
#!/usr/bin/env python3
import sys


def solve(M: int, K: int):
    if M == 0:
        if K == 0:
            print('0 0')
        else:
            print(-1)
    elif M == 1:
        if K == 0:
            print('0 0 1 1')
        else:
            print(-1)
    else:
        if K >= 2 ** M:
            print(-1)
        else:
            ans = [i for i in range(2 ** M) if i != K]
            ans = ans + [K] + ans[::-1] + [K]
            print(*ans)
    return


# Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools
# (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    M = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(M, K)


if __name__ == '__main__':
    main()


Measured memory_bytes: 69360
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstddef>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

// clang-format off
template <typename T> T gcd(T a, T b) { return b == 0 ? a : gcd(b, a % b); }
template <typename T> T lcm(T a, T b) { return a * b / gcd(a, b); }
template <typename T> T clamp(T val, T min, T max) { return val < min ? min : (max < val ? max : val); }
template <typename T> size_t max_index(T begin, T end) { return distance(begin, max_element(begin, end)); }
template <typename T> size_t min_index(T begin, T end) { return distance(begin, min_element(begin, end)); }
// clang-format on

#define int long long
#define YES "Yes"
#define NO  "No"

using namespace std;

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

  int num = 0;

  int a, b; cin >> a >> b;

  num = max(a + b, max(a + a - 1, b + b - 1));
  
  cout << num << endl;
  
  return 0;
}


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

struct Way{
    int cost;
    int tim;
};

int main(void){
    // Your code here!
    int N, T;
    Way* way;
    cin >> N >> T;
    way = new Way[N];
    for(int i = 0;i < N;i++ ){
        cin >> way[i].cost >> way[i].tim;
    }
    Way min = way[0];
    int j = 0;
    for(int i = 0;i < N;i++){
        if(min.cost > way[i].cost){
            if(way[i].tim <= T){
                min = way[i];
            }
        }
        if(way[i].tim > T){
            j++;
        }
    }
    if(j == N){
        cout << "TLE";
    }else{
        cout << min.cost;
    }
}


Measured memory_bytes: 256
package main
import "fmt"
func main() {
  var n,m int
  var a,b,c string
  fmt.Scan(&n,&a,&b,&c)
  for i:=0;i<n;i++ {
    s := make(map[string]struct{})
    s[a[i:i+1]] = struct{}{}
    s[b[i:i+1]] = struct{}{}
    s[c[i:i+1]] = struct{}{}
    m += len(s)-1
  }
  fmt.Println(m)
}

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

int main() {
	int h,w,n;
	cin >> h >> w;
	cin >> n;
	vector<int> a(n);
	rep(i,n) {
		cin >> a[i];
	}
	vector<vector<int>> c(h, vector<int>(w));
	int cnt_color = 1;
	int cnt_grid = 0;
	rep(i,h) {
		if (i%2 == 1) {
			for(int j=0;j<w;j++) {
				c[i][j] = cnt_color;
				cnt_grid++;
				if (cnt_grid >= a[cnt_color-1]) {
					cnt_color++;
					cnt_grid = 0;
				}
			}
		}
		else {
			for(int j=w-1;j>=0;j--) {
				c[i][j] = cnt_color;
				cnt_grid++;
				if (cnt_grid >= a[cnt_color-1]) {
					cnt_color++;
					cnt_grid = 0;
				}
			}
		}
	}
	rep(i,h) {
		rep(j,w) {
			cout << c[i][j] << " ";
		}
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
const int INF=1001001000;
const int mINF=-1001001000;
int main(){
    int n,m;cin >> n >> m;
    vector<int> jobs[m+1];
    for(int i=0; i<n; i++){
        int a,b;cin >> a >> b;
        if(m-a>=0) jobs[m-a].push_back(b);
    }
    priority_queue<int> pq;
    int ans=0;
    for(int i=m-1; i>=0; i--){
        for(auto p: jobs[i]){
            pq.push(p);
        }
        if(!pq.empty()){
            ans+=pq.top();
            pq.pop();
        }
    }
    cout << ans << endl;
    return 0;
}

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
	for(auto &e:u) fill_v<T>(e,v...);
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  int64 Q;
  cin >> Q;
  int64 rev = 0;
  deque<char> ds[2];
  REP(_, Q) {
    int64 T;
    cin >> T;
    if (T == 1) {
      rev ^= 1;
    } else {
      int64 f; char c;
      cin >> f >> c; f--;
      ds[rev^f].push_back(c);
    }
  }
  while (ds[rev].size()) {
    cout << ds[rev].back(); ds[rev].pop_back();
  }
  if (rev) reverse(all(s));
  cout << s;
  while (ds[rev^1].size()) {
    cout << ds[rev^1].front(); ds[rev^1].pop_front();
  }
  cout << endl;
}


Measured memory_bytes: 848
#include<iostream>
using namespace std;
int main() {
    string S, T;
    cin >> S >> T;

    int max = 0;
    for(int i = 0; i <= (int)S.size() - (int)T.size(); i++) {
        int cnt = 0;
        for (int j = 0; j < (int) T.size(); j++) {
            if (S[i + j] == T[j]) cnt++;
        }
        if (max < cnt) max = cnt;
    }
    int ret = (int)T.size() - max;
    cout << (ret) << endl;

    return 0;
}


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


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;cin>>n;
    cout<<n*n*n<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef vector<int>Vl;
typedef pair<int,int>pii;
typedef vector<pii>Vll;
typedef vector<pair<int,pair<int,int> > >Vlll;
#define S second
#define F first
#define mp make_pair
#define ms(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define sl(n) cin>>n 
#define pl(n) cout<<n<<" "
const int Nx=1e5+2;
const int inf=(int)(1e9+10LL);
void solve()
{
	int n,k;
	sl(n);sl(k);
	Vl arr(n+1);
	for(int i=1;i<=n;i++)sl(arr[i]);
	unordered_map<int,int>freq;
	int i=1;
	int pivot,start=1;
	freq[1]=0;
	int value;
	for(i=1;i<=k;i++){
		start=arr[start];
		if(freq[start]>0){
			pivot=i-freq[start];
			value=start;
			break;
		}
		freq[start]=i;
		//cout<<start<<" ";
	}
	if(i>=k){
		cout<<start<<endl;
		return;
	}
	
	k=(k-freq[value])%pivot;
	start=value;
	for(int i=1;i<=k;i++){
		start=arr[start];
	}
	cout<<start<<endl;
	
	
	
	

}

signed main(){
  int test=1;
// sl(test);
 while(test--){
 	solve();
 }
 
}

Measured memory_bytes: 11956
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
using namespace std;


typedef long long ll;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)

const int mod = 1000000007;

int main(){
  int n;
  cin >> n;
  int ans = 0;
  for(int i = 1; i <= n; ++i){
    int count = 0;
    int tmp = i;
    while(tmp > 0){
      tmp /= 10;
      count++;
    }
    if(count % 2 == 1) ans++;
  }

  cout << ans << endl;
}


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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

int main()
{
    int n, m; cin >> n >> m;
    int c[10][10];
    rep(i,10){
        rep(j,10){
            cin >> c[i][j];
        }
    }

    rep(k,10){
        rep(i,10){
            rep(j,10){
                c[i][j] = min(c[i][j], c[i][k]+c[k][j]);
            }
        }
    }

    int ans = 0;
    rep(i,n) rep(j,m){
        int ai; cin >> ai;
        if(ai == -1) continue;
        else ans += c[ai][1];
    }
    cout << ans << endl;
} 

Measured memory_bytes: 3604
#pragma GCC optimize("O3")
#define _CRT_SECURE_NO_WARNINGS
#define _CRT_DISABLE_PERFCRIT_LOCKS
#define POPCNTI(a) __builtin_popcount(a)
#define fs  first  
#define sc  second
#define ARR array
 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
 
#include <bits/stdc++.h>
using namespace  __gnu_pbds; 
using namespace std;
 
 
// #ifndef _LOCAL_DEFINE
// inline int getchar_unlocked(){return _getchar_nolock();}
// inline void putchar_unlocked(char c) {_putchar_nolock(c);}
// #endif
 
typedef long long ll;  
inline void WRITE_CHAR(char c)  {putchar_unlocked(c);} 
template<typename T> 
inline bool READn (T &result) {
  int minus = 1;
  char ch;
  result=0;
  ch = (char) getchar_unlocked();
  while (!isdigit(ch) && ch!=EOF) minus = (ch == '-'? -1 : minus),ch= (char) getchar_unlocked();
 
  if(ch==EOF) return false;
  while (isdigit(ch))  result = result*10 + (int) (ch - '0'),ch = (char) getchar_unlocked();
  
  result *= minus;
  return ch != '\n';
}
template<typename T>
inline void WRITEn(T x) {
  if (x < 0) {putchar_unlocked('-'); x = -x; }
  char writeBuffer[20], *writePtr = writeBuffer;
  do {
    *writePtr++ = (char)('0' + x % 10);
    x /= 10;
  }
  while (x);
  do  { putchar_unlocked(*--writePtr); }
  while (writePtr > writeBuffer);
}
inline bool Read_CHAR(char &c)
{
  char READ_CHARACTER = (char)getchar_unlocked();
  while ((READ_CHARACTER == '\n' || READ_CHARACTER == '\t' || READ_CHARACTER == ' ')) READ_CHARACTER = (char)getchar_unlocked();
  if(READ_CHARACTER == EOF) return false;
  c = READ_CHARACTER;
  return true;
} 
inline bool READ_CHAR_ARRAY(char *x) {
  char READ_CHARACTER = (char)getchar_unlocked();
  while ((READ_CHARACTER == '\n' || READ_CHARACTER == '\t' || READ_CHARACTER == ' ')) READ_CHARACTER = (char)getchar_unlocked();
  if(READ_CHARACTER == EOF) return false;
  char *ptr = &x[0];
  while ((READ_CHARACTER != '\n' && READ_CHARACTER != '\t' && READ_CHARACTER != ' ' && READ_CHARACTER != EOF)) *ptr++ = READ_CHARACTER, READ_CHARACTER = (char)getchar_unlocked();
 
  *ptr = '\0';
  return true;
}
inline void WRITE_CHAR_ARRAY(const char *x) {
  while(*x != '\0')
    putchar_unlocked(*x++);
}
inline void WRITE_STRING(string &x) {
  for(char c: x) 
    putchar_unlocked(c);
}
const ll OOl = 1e18 ;
const int N = 1e5+1,OO = 1e9,OOm = 0x3f3f3f3f, MOD = 1e9 + 7;
ll val[N],wt[N],dp[100][N];
int main()
{
  
  int n;
  ll rem;
  READn(n),READn(rem);
  for(int i=0;i<n;++i) READn(wt[i]),READn(val[i]);

  for(int idx=1;idx<=n;++idx)
  {
    for(int w=0;w<=rem;++w)
    {
      dp[idx][w] = dp[idx-1][w];
      if((w-wt[idx-1])>=0) dp[idx][w] = max(dp[idx][w],dp[idx-1][w-wt[idx-1]]+val[idx-1]); 
    }
  }
  WRITEn(dp[n][rem]);
  return 0; 
}

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





int main(void){
  int h,w;
  cin >> h >> w;

  int s[h][w],white = 0;
  rep(i,h){
	rep(j,w){
	  char x;
	  cin >> x;
	  if(x == '.'){
		s[i][j] = MAX;
		white++;
	  }
	  else{
		s[i][j] = -1;
	  }
	}
  }

  queue<int> que;
  que.push(0);
  s[0][0] = 1;
  while(!que.empty()){
	int x = que.front()/50,y = que.front()%50;
	que.pop();
	if(-1 < x-1 && s[x-1][y] != -1 && s[x][y]+1 < s[x-1][y]){
	  s[x-1][y] = s[x][y]+1;
	  que.push((x-1)*50+y);
	}
	if(x+1 < h && s[x+1][y] != -1 && s[x][y]+1 < s[x+1][y]){
	  s[x+1][y] = s[x][y]+1;
	  que.push((x+1)*50+y);
	}
	if(-1 < y-1 && s[x][y-1] != -1 && s[x][y]+1 < s[x][y-1]){
	  s[x][y-1] = s[x][y]+1;
	  que.push(x*50+y-1);
	}
	if(y+1 < w && s[x][y+1] != -1 && s[x][y]+1 < s[x][y+1]){
	  s[x][y+1] = s[x][y]+1;
	  que.push(x*50+y+1);
	}
  }
  if(s[h-1][w-1] == MAX) cout << -1 << endl;
  else cout << white-s[h-1][w-1] << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] grid = new int[n];
        for (int i = 0; i < n; i++) {
            grid[i] = sc.nextInt();
        }
        int num = n - 1;
        int cnt = 0;
        int max = 0;
        for (int i = 0; i < num; i++) {
            if (grid[i] >= grid[i + 1]) {
                cnt++;
            } else {
                cnt = 0;
            }
            max = Math.max(max, cnt);
        }
        System.out.println(max);
    }    
}


Measured memory_bytes: 51776
package main

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

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

func main() {
	/*/TODO:!!!!!!!テスト用!!!!!!!!!
	sc = bufio.NewScanner(strings.NewReader(`
										`))
	//TODO:!!!!!!!テスト用!!!!!!!!!*/

	buf := make([]byte, 1024*1024)
	sc.Buffer(buf, bufio.MaxScanTokenSize)
	sc.Split(bufio.ScanWords)
	defer out.Flush() // !!!!caution!!!! you must use Fprint(out, ) not Print()
	/* --- code --- */
	//fmt.Fprintln(out, "[DEBUG]", time.Now())

	s := next()
	t := next()

	ans := len(t)
	for i := 0; i < len(s)-len(t)+1; i++ {
		w := 0
		for j := 0; j < len(t); j++ {
			if s[i+j] != t[j] {
				w++
			}
		}
		ans = minInt(ans, w)
	}

	//fmt.Fprintln(out, "[DEBUG]", a)
	fmt.Fprintln(out, ans)

}

// 挿入ソート配列
type slist struct {
	l []int
}

func makeSlist() slist {
	return slist{[]int{}}
}

func (s *slist) add(a int) {
	pos := sort.Search(len(s.l), func(i int) bool { return s.l[i] >= a })
	if pos < len(s.l) {
		s.l = append(s.l[:pos+1], s.l[pos:]...)
		s.l[pos] = a
	} else {
		s.l = append(s.l, a)
	}
}
func (s slist) contains(a int) bool {
	pos := sort.Search(len(s.l), func(i int) bool { return s.l[i] >= a })
	return pos < len(s.l) && s.l[pos] == a
}

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

// -*-*-*-*-*-*-*-*-
// * I/O utilities *
// -*-*-*-*-*-*-*-*-

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func chars(s string) []string {
	ret := make([]string, len([]rune(s)))
	for i, v := range []rune(s) {
		ret[i] = string(v)
	}
	return ret
}

func printArray(a []int) {
	for i := 0; i < len(a); i++ {
		if i >= 1 {
			fmt.Fprint(out, " ")
		}
		fmt.Fprint(out, a[i])
	}
	fmt.Fprintln(out)
}

func absInt(x int) int {
	return int(math.Abs(float64(x)))
}
func minInt(x, y int) int {
	if x < y {
		return x
	}
	return y
}
func maxInt(x, y int) int {
	if x > y {
		return x
	}
	return y
}
func sign(x int) int {
	if x == 0 {
		return 0
	}
	if x > 0 {
		return 1
	}
	return -1
}
func log10(x int) float64 {
	return math.Log10(float64(x))
}
func divCeil(shi, bo int) int {
	ans := shi / bo
	if shi%bo != 0 {
		ans++
	}
	return ans
}


Measured memory_bytes: 1828
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
typedef pair<ll,ll> pll;
void read(int& x){ scanf("%d",&x); }
void read(ll& x){ scanf("%lld",&x); }
template<typename T,typename... Args>
void read(T& a,Args&... b){ read(a); read(b...); }
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
#define x first
#define y second

char s[30];
char t[30];

int main()
{
	scanf("%s", s);
	int n = strlen(s);
	if(n < 26){
		for(int i=0; i<26; ++i){
			bool exi=0;
			for(int j=0; j<n; ++j) if(s[j]-'a' == i) exi=1;
			if(!exi){
				s[n]=i+'a';
				puts(s);
				return 0;
			}
		}
	}
	for(int i=0; i<n; ++i) t[i]=s[i];
	if(next_permutation(t, t+n)){
		for(int i=0; i<n; ++i){
			putchar(t[i]);
			if(t[i] != s[i]) break;
		}
	} else puts("-1");
	return 0;
}


Measured memory_bytes: 256