akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define hackcyborg shresth_walia
#define ll long long
#define ld double
#define pb push_back
#define mod 1000000007
#define IO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int,null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define int long long
ll binpow(ll a,ll b,ll m=mod)
{
    ll res=1;
    while(b>0)
    {
        if(b&1)
        res=(a*res)%m;
        a=(a*a)%m;
        b/=2;
    }
    return res;
}
const int INF =1e9;
ll n;
vector<pair<ll,ll>> ar[200010];
void dijkstra(int s, vector<int> & d, vector<int> & p) {
    d.assign(n+1, INF);
    p.assign(n+1, -1);
    d[s] = 0;
    set<pair<int, int>> q;
    q.insert({0, s});
    while (!q.empty()) {
        int v = q.begin()->second;
        q.erase(q.begin());
        for (auto edge : ar[v]) {
            int to = edge.first;
            int len = edge.second;
            if (d[v] + len < d[to]) {
                q.erase({d[to], to});
                d[to] = d[v] + len;
                p[to] = v;
                q.insert({d[to], to});
            }
        }
    }
}
main()
{
    IO
    ll m;
    cin>>n>>m;
    ++n;
    ll a[n+1],b[n+1];
    for(int x=1;x<n;x++)
        {cin>>a[x]>>b[x];
        ++b[x];}
    b[n]=m;
    a[n]=1;
    set<pair<ll,ll>> ae;
    for(int x=1;x<=m;x++)
    {
         ae.insert({x,0ll});
    }
    for(int x=1;x<=n;x++)
    {
        auto it=ae.lower_bound(make_pair(a[x],-1ll));
        vector<pair<ll,ll>> as;
        if(it!=ae.end())
        while((it->first)<=(b[x]-1) && (it->first)>=a[x])
        {
            as.pb(*it);
            //cout<<it->second<<" "<<x<<"\n";
            ar[it->second].pb(make_pair(x,abs(it->first-b[x])+abs(it->second-x)));
            ++it;
            if(it==ae.end())break;
        }
        for(auto it : as)
            ae.erase(it);
        ae.insert(make_pair(b[x],x));
    }
    vector<ll> d,p;
    dijkstra(0,d,p);
    ll ans[n+1];
    for(int x=1;x<=n;x++)
        ans[x]=INF;
    for(int x=0;x<=n;x++)
    {   ans[x]=min(ans[x],d[x]);
        for(auto it : ar[x])
        {
            ans[it.first]=min(ans[it.first],d[x]+abs(x-it.first));
        }
    }
    ll mi=1e18;
    for(int x=n;x>=1;x--)
    {
        ans[x]=min(ans[x],mi+x);
        mi=min(mi,ans[x]-x);
    }
    for(int x=2;x<=n;x++)
         if(ans[x]<1e8)
        cout<<ans[x]-1<<"\n";
         else
            cout<<-1<<"\n";
}


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




int main() {
   #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  #endif
 ios_base::sync_with_stdio(0);
 cin.tie(0);
 cout.tie(0);
 string s; cin>>s;
  auto it=unique(begin(s),end(s))-begin(s)-1;
  cout<<it<<endl;
 return 0;
}


Measured memory_bytes: 3780
n,m,l = gets.split(" ").map(&:to_i)
a = []
b = []
c = Array.new(n).map{Array.new(l,0)}
n.times do
  a<<gets.split(" ").map(&:to_i)
end
m.times do
  b<<gets.split(" ").map(&:to_i)
end
n.times do |i|
  l.times do |j|
    c[i][j] = [a[i],b.transpose[j]].transpose.map{|t| t.inject(:*)}.inject(:+)
  end
  puts c[i].join(" ")
end

Measured memory_bytes: 13644
//
// Created by Myabu on 2020/01/30.
//

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <math.h>
#include <stack>
#include <queue>
#include <cstdio>
#include <numeric>
#include <iomanip>

using namespace std;


int main(void){
    int A,B,X;

    cin>>A>>B>>X;

    if(A+B>=X && A<=X){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }


    return 0;
}

Measured memory_bytes: 888
#include <iostream>
#include <bitset>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <regex>
#include <iomanip>
#include <climits>
using namespace std;
using ll = long long int;
using dd = long double;
const ll MOD = 1e9 + 7;

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

int main()
{
    ll N;
    cin >> N;
    vector<ll> V(N);
    for (ll i = 0; i < N; i++)
    {
        cin >> V[i];
    }
    sort(V.begin(), V.end());

    cout << (V.back() - V.front()) << endl;
}

Measured memory_bytes: 256
//  cout << char(i+48) << endl;//なぜかaは47と得る時がある。+48で出力もaにできる。
//  cout << char(97) << endl;//アスキーコードでaを出力
// sort(b.begin(), b.end());//bという配列を小さい方からソート
// reverse(b.begin(), b.end());//bという配列をリターン
// 10桁でdouble出力するパターン１ 
// printf("%.10f\n", ma);
// 10桁でdouble出力するパターン２
//cout << fixed << setprecision(10);
//  cout << ma << endl;

/*01 02 03 12 13 23　と６回見ていくパターン 
for(int i=0;i<n-1;i++){
  for(int j=i+1;j<n;j++){
    }
  }
*///vector<vector<int>> data(3, vector<int>(4));//int型の2次元配列(3×4要素の)の宣言
//int64_t a;
//10のi乗pow(10, i);
//10の1/2乗（ルート）pow(10, 0.5)
/*string s; stringでの文字列を数字型に変える方法
  cin >> s;
  rep(i,s.size()-2) {
  int a= (s.at(i)-'0')*100 + (s.at(i+1)-'0')*10+ s.at(i+2) -'0';
    */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  string a,b;
  cin >> a >> b;
  if(a.size() > b.size() ) cout<< "GREATER"<< endl;
  else if(a.size() < b.size() ) cout<<"LESS" << endl;
  else{
    for(int i=0;i<a.size() ;i++){
      if(a.at(i) > b.at(i) ){
        cout << "GREATER" << endl;
        return 0;
      }
      else if(a.at(i) < b.at(i) ){
        cout << "LESS" << endl;
        return 0;
      }
    }
    cout << "EQUAL"<<endl;
  }
}

Measured memory_bytes: 3616
n,q=map(int,input().split())
s=input()
t=[0]*(n+1)
for i in range(n-1):
    t[i+1]=t[i]+(1 if s[i:i+2]=="AC" else 0)
for i in range(q):
    l,r=map(int,input().split())
    print(t[r-1]-t[l-1])

Measured memory_bytes: 7748
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

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

func main() {
	sc.Split(bufio.ScanWords)
	n := nextInt()
	sm := make(map[string]int)
	for i := 0; i < n; i++ {
		s := nextString()
		sm[s]++
	}
	fmt.Println(len(sm))
}


Measured memory_bytes: 18292
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;

int main(){
    string S;
    cin >> S;
    bool d=false;
    if(S.at(0)==S.at(1) and S.at(2)==S.at(3) and S.at(1)!=S.at(2)) d=true;
    if(S.at(0)==S.at(2) and S.at(1)==S.at(3) and S.at(0)!=S.at(1)) d=true;
    if(S.at(0)==S.at(3) and S.at(1)==S.at(2) and S.at(0)!=S.at(1)) d=true;
    if(d){
        cout << "Yes";
    }else{
        cout << "No";
    }
}

Measured memory_bytes: 256
N = int(input())
L = list(map(int,input().split()))

v = L[:]
v.sort()

res = 0

import bisect

for i in range(N-2):
    a = v[i]
    for j in range(i+1,N-1):
        b = v[j]
        sup = a + b
        #inf = max(a-b,b-a)
        iterS = bisect.bisect_left(v,sup)
        #iterI = bisect.bisect_left(v,inf+1)
        #print(a,b,sup,inf,iterS,iterI)
        res += iterS - (j+1)

print(res)


Measured memory_bytes: 3188
local mfl = math.floor
local TFFT = {}

TFFT.initialize = function(self)
  self.size = 20
  self.n = 1048576
  self.mod = 998244353
  self.w = 646
  self.ninv = 998243401
  self.winv = 208611436
  self.p2 = {1}
  for i = 2, self.size do
    self.p2[i] = self.p2[i - 1] * 2
  end
  self.binv = {}
  for i = 1, self.n do
    local y, z = 0, i - 1
    for j = 1, self.size do
      y = y + (z % 2) * self.p2[self.size + 1 - j]
      z = mfl(z / 2)
    end
    self.binv[i] = y + 1
  end
  self.wmul = {1}
  for i = 2, self.n do
    self.wmul[i] = self:mul(self.wmul[i - 1], self.w)
  end
  self.winvmul = {1}
  for i = 2, self.n do
    self.winvmul[i] = self:mul(self.winvmul[i - 1], self.winv)
  end
end

TFFT.mul = function(self, x, y)
  local x0, y0 = x % 31596, y % 31596
  local x1, y1 = mfl(x / 31596), mfl(y / 31596)
  return (x1 * y1 * 62863 + (x1 * y0 + x0 * y1) * 31596 + x0 * y0) % self.mod
end

TFFT.add = function(self, x, y) return (x + y) % self.mod end

TFFT.fft_common = function(self, ary, wmul)
  local ret = {}
  for i = 1, self.n do
    ret[i] = ary[self.binv[i]]
  end
  for i = 1, self.size do
    local step_size = self.p2[i]
    local step_count = self.p2[self.size + 1 - i]
    for istep = 1, step_count do
      local ofst = (istep - 1) * step_size * 2
      for j = 1, step_size do
        local a1, a2 = ret[ofst + j], ret[ofst + step_size + j]
        ret[ofst + j] = self:add(a1, self:mul(a2, wmul[1 + (j - 1) * step_count]))
        ret[ofst + step_size + j] = self:add(a1, self:mul(a2, wmul[1 + (j + step_size - 1) * step_count]))
      end
    end
  end
  return ret
end

TFFT.fft = function(self, ary)
  return self:fft_common(ary, self.wmul)
end
TFFT.ifft = function(self, ary)
  local ret = self:fft_common(ary, self.winvmul)
  for i = 1, self.n do
    ret[i] = self:mul(ret[i], self.ninv)
  end
  return ret
end

-- sample (ATC001-C)
TFFT:initialize()
local a, b = {}, {}
local n, m = io.read("*n", "*n")
for i = 1, TFFT.n do
  a[i] = 0
  b[i] = 0
end
for i = 1, n do
  a[i] = io.read("*n")
end
for i = 1, m do
  b[i] = io.read("*n")
end

local at = TFFT:fft(a)
local bt = TFFT:fft(b)
for i = 1, TFFT.n do
  at[i] = TFFT:mul(at[i], bt[i])
end
local c = TFFT:ifft(at)
for i = 1, n + m - 1 do
  io.write(c[i])
  io.write(i == n + m - 1 and "\n" or " ")
end


Measured memory_bytes: 121652
package main

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

type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func NewIo() *Io {
	return &Io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

func (io *Io) NextLine() string {
	var buffer []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	r := io.tokens[io.nextToken]
	io.nextToken++
	return r
}

func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) NextFloat() float64 {
	i, err := strconv.ParseFloat(io.Next(), 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) PrintLn(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

func (io *Io) Printf(format string, a ...interface{}) {
	fmt.Fprintf(io.writer, format, a...)
}

func (io *Io) PrintIntLn(a []int) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.PrintLn(b...)
}

func (io *Io) PrintStringLn(a []string) {
	b := []interface{}{}
	for _, x := range a {
		b = append(b, x)
	}
	io.PrintLn(b...)
}

func Log(name string, value interface{}) {
	fmt.Fprintf(os.Stderr, "%s=%+v\n", name, value)
}

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

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

func main() {
	io := NewIo()
	defer io.Flush()
	N := io.NextInt()
	A := io.NextInt()
	B := io.NextInt()
	if N < 2 {
		if A == B {
			io.PrintLn(1)
		} else {
			io.PrintLn(0)	
		}
	} else if A > B {
		io.PrintLn(0)
	} else {
		io.PrintLn((B - A) * (N - 2) + 1)
	}
}

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

using namespace std;

const int mod = 1e9 + 7;

long long mulmod(long long a, long long b, long long m){
    a %= m;
    long long res = 0;
    while(b){
        if(b & 1) res = (res + a) % m;
        a = (a + a) % m;
        b >>= 1;
    }
    return res;
}

long long modfact(long long n, long long k, long long m){
	long long res = 1;
	for(long long i = n; i > n - k; i--) res = mulmod(res, i, m);
	return res;
}
 
long long binpow(long long a, long long b, long long m){
    a %= m;
    long long res = 1;
    while(b){
        if(b & 1) res = mulmod(res, a, m);
        a = mulmod(a, a, m);
        b >>= 1;
    }
    return res;
}
 
long long inv(long long k, long long m){
	long long val = modfact(k, k, m);
	return binpow(val, m - 2, m);
}
 
long long bin(long long n, long long k, long long m){
	long long a = modfact(n, k, m);
    long long b = inv(k, m);
    return mulmod(a, b, m);
}

int main(){
    int x, y;
    cin >> x >> y;
    if((x + y) % 3 != 0 || max(x, y) > 2 * min(x, y)) cout << "0\n";
    else{
        int k = (x + y) / 3;
        int n = (2 * x - y) / 3;
        cout << bin(1ll * k, 1ll * n, 1ll * mod) << '\n';
    }
}

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

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

void run(void){
  int n,m,x;
  scanf("%d%d%d",&n,&m,&x);
  int a[100];
  int i;
  for(i=0;i<m;i++) scanf("%d",a+i);
  int k=0;
  for(i=0;i<x;i++){
    if(a[k]==i){
      k++;
    }
  }
  printf("%d\n",MIN(k,m-k));
  return;
}

int main(void){
  run();
  return 0;
}

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

int main() {
  int K;
  cin >> K;
  
  if (K % 10 == 0 || K % 10 == 2 || K % 10 == 4 || K % 10 == 5 || K % 10 == 6 || K % 10 == 8){
    cout << -1 << endl;
    return 0;
  }
  
  if (K == 1){
    cout << 1 << endl;
    return 0;
  }
  
  int N = 7 % K;
  int M = N;
  int count = 1;
  
  while (M != 0){
    N = N*10 % K;
    M += N;
    if (M >= K){
      M -= K;
    }
    if (count > K){
      cout << -1 << endl;
      return 0;
    }
    count++;
  }
  cout << count << endl;
}
   

  

Measured memory_bytes: 3596
using System;
namespace ITP1_4_A
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = Console.ReadLine().Split();
            long a = long.Parse(S[0]);
            long b = long.Parse(S[1]);
            long d = (long)(a / b);
            long r = a % b;
            double f = (double)a / (double)b;
            Console.WriteLine("{0} {1} {2:0.00000}", d, r, f);
        }
    }
}


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

class UnionFind {
	vector<int>par, sz;
public:
	UnionFind() {}
	UnionFind(int n) {
		par = sz = vector<int>(n);
		for (int i = 0; i < n; i++) {
			par[i] = i;
			sz[i] = 1;
		}
	}
	int find(int x) {
		if (par[x] == x)return x;
		return par[x] = find(par[x]);
	}
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y)return;
		if (sz[x] > sz[y]) {
			par[y] = x;
			sz[x] += sz[y];
		}
		else {
			par[x] = y;
			sz[y] += sz[x];
		}
	}
	bool same(int x, int y) {
		return find(x) == find(y);
	}
	int size(int x) {
		return sz[find(x)];
	}
};
int cnt[2000][2];
bitset<2000>dp;
int main(){
	int n,m;scanf("%d%d",&n,&m);
	set<P>se;
	rep(i,m){
		int a,b;scanf("%d%d",&a,&b);a--;b--;
		if(a>b)swap(a,b);
		se.insert(P(a,b));
	}
	UnionFind uf(n*2);
	rep(i,n)for(int j=i+1;j<n;j++){
		if(!se.count(P(i,j))){
			uf.unite(i,j+n);
			uf.unite(i+n,j);
		}
	}
	rep(i,2*n){
		if(i<n&&uf.same(i,n+i)){
			puts("-1");return 0;
		}
		cnt[uf.find(i)][i>=n]++;
	}
	dp[0]=1;
	rep(i,n){
		if(uf.find(i)==i){
			dp=dp<<cnt[i][0]|dp<<cnt[i][1];
		}
	}
	int Min=INT_MAX;
	rep(i,n+1){
		if(dp[i]){
			Min=min(Min,i*(i-1)/2+(n-i)*(n-i-1)/2);
		}
	}
	cout<<Min<<endl;
}

Measured memory_bytes: 11648
require 'pp'
class Solve
  attr_reader :map

  SPREAD = (-3..3).map { |i| [[i, 0], [0, i]] }.flatten(1)

  def initialize(map)
    @map = map.dup
  end

  def bomb(x, y)
    @map[x][y] = 0

    SPREAD.each do |dx, dy|
      _x, _y = x + dx, y + dy

      next if (_x < 0 || _x >= 8) || (_y < 0 || _y >= 8)

      if @map[_x][_y] == 1
        bomb(_x, _y)

        @map[_x][_y] = 0
      end
    end
  end
end

n = gets.to_i
n.times do |i|
  gets

  map = []
  8.times do
    map.push(gets.chomp.split(//).map(&:to_i))
  end
  map = map.transpose

  x, y = gets.to_i - 1, gets.to_i - 1

  solve = Solve.new(map)
  solve.bomb(x, y)

  puts "Data #{i + 1}:"
  puts solve.map.transpose.map(&:join)
end

Measured memory_bytes: 9052
#include <iostream>
 
using namespace std;
 
int main()
{
    int n, a[100], i, j, r = 0;
 
    cin >> n;
    for (i = 0; i < n; ++i)
        cin >> a[i];
 
    for (i = 0; i < n; ++i)
        for (j = n-1; j > i; --j)
            if (a[j] < a[j-1])
                swap(a[j], a[j-1]), ++r;
 
    for (i = 0; i < n; ++i)
    {
        cout << a[i];
        if (i < n-1)
            cout << " ";
    }
    cout << endl << r << endl;
 
    return 0;
}

Measured memory_bytes: 3108
#include <iostream>
#include <string>
#include <stack>
#include <vector>
#include <algorithm>

// 19:48
using namespace std;

int main() {
	stack<int> S1;// location of backslashes 
	stack<pair<int, int> > S2;// index, area
	int sum = 0;
	string s;
	cin >> s;
	for (int i=0; i<s.length(); ++i) {
		char ch = s[i];
		//cout << "i: " << i << endl;
		if (ch == '\\') S1.push(i);
		if (ch == '/' && !S1.empty()) {
			int j = S1.top(); S1.pop();
  		int area = i-j;
  		sum += area; // 別にsumをここで計算しなくてもS2が計算できていれば集計したら良い...
			// DDUUDDUU のような例を考えるとよい(D:down, U:up)
			while (S2.size() > 0 && S2.top().first > j) {
				area += S2.top().second; S2.pop();
			}
  		S2.push(make_pair(j, area));
		}
	}
	vector<int> ans;
	while(S2.size() > 0) {
		//cout << "S2.size() = " << S2.size() << endl;
		ans.push_back(S2.top().second);
		S2.pop();
	}
	reverse(ans.begin(), ans.end());
	cout << sum << endl;
	cout << ans.size();
	for (int i=0; i<ans.size(); ++i) {
		cout << " " << ans[i];
	}
	cout << endl;
	return 0;
}



Measured memory_bytes: 3268
using System;

namespace myApp
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = Console.ReadLine();
            int count = 0;
            if(s.Substring(0,1) == "1")
                count++;
            if(s.Substring(1,1) == "1")
                count++;
            if(s.Substring(2,1) == "1")
                count++;
            Console.WriteLine(count);            
        }
    }
}


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

struct UnionFind{
    int num;
    vector<int> par,rank;
    UnionFind(int n):num(n),par(n),rank(n,1){
        iota(par.begin(),par.end(),0);
    }
    int root(int x){
        return (par[x]==x?x:par[x]=root(par[x]));
    }
    bool merge(int x, int y){
        x=root(x),y=root(y);
        if (x==y) return false;
        if (rank[x]<rank[y]) swap(x,y);
        par[y]=x;
        rank[x]+=rank[y];
        --num;
        return true;
    }
    bool same(int x, int y){return root(x)==root(y);}
    int size(int x){return rank[root(x)];}
    int count(){return num;}
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,Q; cin >> N >> Q;
    UnionFind UF(N);
    for (;Q--;){
        int t,u,v; cin >> t >> u >> v;
        if (!t) UF.merge(u,v);
        else cout << UF.same(u,v) << '\n';
    }
}

Measured memory_bytes: 4688
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define DEBUG(x) cerr << #x << " = " << x << endl
bool touch[200001];
signed main() {
  int N, M; cin >> N >> M;
  vector<int> ord;
  memset(touch, -1, sizeof(touch));
  REP(i,M) {
    int k; cin >> k;
    touch[k] = false;
    ord.push_back(k);
  }
  set<int> S;
  reverse(ord.begin(), ord.end());
  for(int k : ord) {
    if(!S.count(k)) {
      cout << k << endl;
      S.insert(k);
    }
  }
  // cout << "-" << endl;
  for(int i = 1; i <= N; ++i) {
    if(touch[i]) {
      cout << i << endl;
    }
  }
}

Measured memory_bytes: 8596
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a) = min((a), (b)))
#define chmax(a, b) ((a) = max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

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

const ll MOD = 1e9 + 7;
const ll INF = 1e18;
const double pi = acos(-1);
const double eps = 1e-10;

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

int main(){
    string s; cin>>s;
    int n = s.size();

    string t = "";
    for(int i=0; i<n; i++){
        if(i + 1 < n && s[i] == 'B' && s[i+1] == 'C'){
            t += "D";
            i++;
        }
        else{
            t += s[i];
        }
    }

    n = t.size();
    ll Asum = 0;
    ll ans = 0;
    for(int i=0; i<n; i++){
        if(t[i] == 'A'){
            Asum++;
        }
        else if(t[i] == 'D'){
            ans += Asum;
        }
        else{
            Asum = 0;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 776
s=list(input())
t=list(input())
set_s=sorted(set(s),key=s.index)
set_t=sorted(set(t),key=t.index)
s_dic={}
t_dic={}
k=0
for i in set_s:
    s_dic[i]=k
    k+=1
k=0
for i in set_t:
    t_dic[i]=k
    k+=1
flg=0
for a,b in zip(s,t):
    if s_dic[a]!=t_dic[b]:
        flg=1
if flg==0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 6704
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    A = [list(map(int, input().split())) for _ in range(2)]

    res = 0
    for i in range(n):
        point = sum(A[0][:i + 1]) + sum(A[1][i:])
        res = max(res, point)

    print(res)

if __name__ == '__main__':
    resolve()


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

using namespace std;
using ll = long long;

const int N = 1e6 + 5, MOD = 1e9 + 7;
const ll INF = 1e18 + 17;

int cnt[N];

void solve() {
	int n;
	cin >> n;
	ll res = 0;
	for (int i = 1; i < n; ++i) {
		for (int j = i; j <= n; j += i) {
			++cnt[j];
		}
		res += cnt[i];
	}
	cout << res;
}

main() {
	ios :: sync_with_stdio(0);		
	cin.tie(0);
	int tt = 1;
	//cin >> tt;
	while (tt--) {
		solve();
		cout << '\n';
	} 
	return 0;
}

Measured memory_bytes: 7396
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n, m;
    cin >> n >> m;
    vector<vector<pair<int, int> > >g(n + 3);
    for(int i = 1; i <= m; i++){
        int u, v, c;
        cin >> u >> v >> c;
        g[u].push_back(make_pair(c, v));
        g[v].push_back(make_pair(c, u));
    }
    for(int i = 1; i <= n; i++){
        sort(g[i].begin(), g[i].end());
    }
    priority_queue<pair<int, pair<int, int> >, vector<pair<int, pair<int, int> > >, greater<pair<int, pair<int, int> > > >pq;
    map<pair<int, int>, int>dist;
    dist[{1, 0}] = 0;
    pq.push({0, {1, 0}});
    while(!pq.empty()){
        int cost = pq.top().first, u = pq.top().second.first, c1 = pq.top().second.second;
        pq.pop();
        if(dist[{u, c1}] < cost){
            continue;
        }
        if(c1 == 0){
            for(int i = 0; i < g[u].size(); i++){
                int c2 = g[u][i].first, v = g[u][i].second;
                if(dist.find({v, c2}) == dist.end() || dist[{v, c2}] > cost + 1){
                    if(dist.find({v, 0}) == dist.end() || cost + 1 <= dist[{v, 0}]){
                        dist[{v, c2}] = cost + 1;
                        pq.push({cost + 1, {v, c2}});
                    }
                }
            }
        }
        else{
            int x = lower_bound(g[u].begin(), g[u].end(), make_pair(c1, 0)) - g[u].begin();
            for(int i = x; i < g[u].size(); i++){
                int c2 = g[u][i].first, v = g[u][i].second;
                if(c2 != c1){
                    break;
                }
                if(dist.find({v, c2}) == dist.end() || dist[{v, c2}] > cost){
                    if(dist.find({v, 0}) == dist.end() || cost <= dist[{v, 0}]){
                        dist[{v, c2}] = cost;
                        pq.push({cost, {v, c2}});
                    }
                }
            }
            if(dist.find({u, 0}) == dist.end() || dist[{u, 0}] > cost){
                dist[{u, 0}] = cost;
                pq.push({cost, {u, 0}});
            }
        }
    }
    int ans = 1e9;
    for(int i = 0; i <= 1000000; i++){
        if(dist.find({n, i}) != dist.end()){
            ans = min(ans, dist[{n, i}]);
        }
    }
    if(ans == 1e9){
        cout << "-1";
        return 0;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 31684
#include <stdio.h>
#include <stdlib.h>

int main(){
  long i,n,*a;
  long min,max,sum;
  min = 1000000;
  max = -1000000;
  sum = 0;
  scanf("%ld",&n);
  a = malloc(n*sizeof(long));
  for(i=0;i<n;i++){
    scanf("%ld",&a[i]);
    if(a[i]<min) min = a[i];
    if(a[i]>max) max = a[i];
    sum += a[i];
  }
  printf("%ld %ld %ld\n",min,max,sum);
  return 0;
}

Measured memory_bytes: 676
#include <iostream>
#include <vector>

using namespace std;


vector<int> era(int n){
	vector<int> prime;
	bool *is_prime = new bool[n+1];
	fill(is_prime,is_prime+n+1,true);
	is_prime[0] = is_prime[1] = false;
	for(int i = 2; i <= n; i++){
		if(is_prime[i]){
			prime.push_back(i);
			for(int j = i*2; j <= n; j+=i){
				is_prime[j] = false;
			}
		}
	}
	delete []is_prime;
	return prime;
}

int main(){

	int n;
	while(1){
		cin >> n;
		if(cin.eof())
			break;
		vector<int> p = era(n);
		cout << p.size() << endl;
	}

	return 0;
}

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

//bit全探索改
vector<string> bit_all_search(int n){
  vector<string> use(0);
  queue<string> Q;
  Q.push("");
  while(Q.size()){
    string S = Q.front();
    Q.pop();
    string T = S;
    T += '0';
    if(T.size() == n){
      use.push_back(T);
    }
    else{
      Q.push(T);
    }
    T = S;
    T += '1';
    if(T.size() == n){
      use.push_back(T);
    }
    else{
      Q.push(T);
    }
  }
  return use;
}

int main(){
  int H, W, K;
  cin >> H >> W >> K;
  vector<vector<char>> vec(H,vector<char>(W));
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      cin >> vec[i][j];
    }
  }
  
  int ans = 0;
  vector<string> A = bit_all_search(H);
  vector<string> B = bit_all_search(W);
  
  for(int i=0; i<A.size(); i++){
    for(int j=0; j<B.size(); j++){
      int cnt = 0;
      for(int h=0; h<H; h++){
        for(int w=0; w<W; w++){
          if(A[i][h] == '0' && B[j][w] == '0' && vec[h][w] == '#'){
            cnt++;
          }
        }
      }
      if(cnt == K){
        ans++;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3640
N, A, B = map(int, input().split())
NSUMlist = []
for i in range(1, N + 1):
    NN = list(str(i))
    NNN = [int(_) for _ in NN]
    NSUM = sum(NNN)
    if NSUM >= A and NSUM <= B:
        NSUMlist.append(i)
print(sum(NSUMlist))

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

int main() {
  int n;
  cin >> n;
  string s1, s2;
  cin >> s1 >> s2;
  int r = 0;
  int a = 1;
  int b = -1;
  ll ans = 1;
  while(1){
    if(r>= n) break;
    if(s1[r] == s2[r]){
      a = 1;
      r++;
    }else {
      a = 0;
      r += 2;
    }
    if(b == -1 && a == 1) ans *= 3;
    else if(b == -1 && a == 0) ans *= 6;
    else if(b == 1 && a == 1) ans *= 2;
    else if(b == 1 && a == 0) ans *= 2;
    else if(b == 0 && a == 1) ans *= 1;
    else if(b == 0 && a == 0) ans *= 3;
    ans %= mod;
    b = a;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>

int binarySearch(int);

int s[100000], t[50000], n;

int main()
{
  int q, i, count=0;

  scanf("%d",&n);
  for( i=0 ; i<n ; i++ )
    scanf("%d",&s[i]);
  scanf("%d",&q);
  for( i=0 ; i<q ; i++ )
    scanf("%d",&t[i]);

  for( i=0 ; i<q ; i++ )
    if(binarySearch(t[i])>=0) count++;
  printf("%d\n",count);

  return 0;
}

int binarySearch(int key)
{
  int left, right, mid;
  left = 0;
  right = n;
  while(left<right){
    mid = (left+right)/2;
    if(s[mid]==key) return mid;
    else if(key<s[mid]) right = mid;
    else left = mid +1;
  }
  return -1;
}

Measured memory_bytes: 1180
import sys, re
import math
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7


n, m = MAP()

ans = 0

for x in range(0, n ):
    ans += x
for x in range(0, m ):
    ans += x

print(ans)

Measured memory_bytes: 5332
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

vector<vector<long long>> combinations(int n) {
    auto res = vector<vector<long long>>(n + 1, vector<long long>(n + 1));
    for (int i = 0; i <= n; ++i)res[i][0] = 1;
    for (int i = 1; i <= n; ++i) for (int j = 1; j <= i; ++j)
        res[i][j] = res[i - 1][j - 1] + res[i - 1][j];
    return res;
}


// 11,111,1111,...
void hoge() {
    auto C = combinations(1000);
    const int L = 100;
    for (int i = 2; i <= L; ++i) {
        ll res = 0;
        for (int j = 2; j <= i; j += 2) {
            res += C[i][j];
        }
        if (res > 1000000000000ll)break;
        cout << res << endl;
    }
}

// 121,1212,12121,...
void piyo() {
    for (int len = 3; len <= 20; ++len) {
        int cnt = 0;
        
        rep(S, 1 << len) {
            vi v;
            rep(i, len)if (S >> i & 1) {
                if (i & 1)v.push_back(2);
                else v.push_back(1);
            }
            int m = sz(v) / 2;
            bool ok = true;
            rep(i, m) {
                if (v[i] != v[m + i]) {
                    ok = false;
                    break;
                }
            }
            if (ok)cnt++;
        }
        cout << cnt << endl;
    }
}

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

    ll N;
    cin >> N;

    int m = -1;
    for (int i = 60; i >= 1; --i) {
        if ((1ll << i)-1 <= N) {
            m = i;
            break;
        }
    }

    ll x = (1ll << m) - 1;
    vi ans(m);
    iota(all(ans), 1);
    
    for (int i = m; i >= 0; --i) {
        if (x + (1ll << i) <= N) {
            ans.insert(ans.begin() + i, ++m);
            x += 1ll << i;
        }
    }

    for (int i = 1; i <= m; ++i)ans.push_back(i);

    m *= 2;
    cout << m << endl;
    rep(i, m) {
        cout << ans[i] << (i != m - 1 ? ' ' : '\n');
    }
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<string>
#include<sstream>
#include<cmath>
#include<cstdlib>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#include<iostream>
#include<algorithm>
#define m(a,b) memset(a,b,sizeof(a));
using namespace std;
typedef long long LL;
typedef pair<int,int>PII;
const LL inf = 1 << 30;
map<LL,int>mp;
map<LL,int>::iterator it;
const int maxn = 1e5;
LL vis[2*maxn+5];
int main(){
	vis[0] = 0,vis[1] = 0;
	for(int i = 2;i<2*maxn+5;i++)
		vis[i] = vis[i-1]+i-1;
	int n;
	cin >> n;
	LL sum = 0;
	LL ans = 0;
	for(int i = 0;i<n;i++){
		int a;
		cin >> a;
		sum += a;
		mp[sum]++;
	}
	for(it = mp.begin();it!=mp.end();it++){
		if(it->first == 0) ans += it->second;
		ans += vis[it->second];
	}
	cout<< ans << endl;
    return 0;
}

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

int main(){
    int W,H,x,y,r;
    cin >> W >> H >> x >> y >> r;
    
    if ((r <= x && x <= W-r) && (r <= y && y <= H-r)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
}


Measured memory_bytes: 3112
using System;
using System.Linq;
using System.Collections.Generic;
public class Hello
{

    public static void Main()
    {
        string s = Console.ReadLine();
        string ans = "";
        ans += s[0];
        ans += s.Length - 2;
        ans += s[s.Length - 1];
        Console.WriteLine(ans);
    }
}

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

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto M = s[1];
    auto P = readln.split.map!(a => a.to!int-1).array;
    auto Q = new int[](N);
    foreach (i; 0..N) Q[P[i]] = i;
    auto uf = new  UnionFind(N);
    foreach (i; 0..M) {
        s = readln.split.map!(to!int);
        int a = s[0] - 1;
        int b = s[1] - 1;
        uf.unite(a, b);
    }

    auto B = new bool[int][](N);
    foreach (i; 0..N) {
        if (uf.find(i) != i) continue;
        foreach (x; uf.group[i]) B[i][x] = true;
    }

    int ans = 0;
    foreach (i; 0..N) {
        int j = uf.find(Q[i]);
        if (i in B[j]) ans += 1;
    }

    ans.writeln;
}

class UnionFind {
    int N;
    int[] table;
    int[][] group;

    this(int n) {
        N = n;
        table = new int[](N);
        fill(table, -1);
        group = new int[][](N);
        foreach (i; 0..N) group[i] = [i];
    }

    int find(int x) {
        return table[x] < 0 ? x : (table[x] = find(table[x]));
    }

    void unite(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return;
        if (table[x] > table[y]) swap(x, y);
        table[x] += table[y];
        group[x] ~= group[y].dup;
        group[y] = [];
        table[y] = x;
    }
}


Measured memory_bytes: 30780
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
    char s[3];
    cin >> s;
    int a, b, c;
    a = b = c = 0;
    for (int i = 0; i < 3; i++) {
        if (s[i] == 'a') a++;
        if (s[i] == 'b') b++;
        if (s[i] == 'c') c++;
    }
    cout << ((a==1&&b==1&&c==1) ? "Yes" : "No") << endl;
    return 0;
}


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

using namespace std;
int f(int a[][4], int n){
    
    int** f = new int*[n+1];
    for(int i = 0; i<=n; i++){
        f[i] = new int[4];
    }
    f[n][1] = a[n][1];
    f[n][2] = a[n][2];
    f[n][3] = a[n][3];
    // f[i][j] denotes the answer when we do jth activity on ith day
    for(int i = n-1; i>=1; i--){
        f[i][1] = a[i][1] + max(f[i+1][2], f[i+1][3]);
        f[i][2] = a[i][2] + max(f[i+1][1], f[i+1][3]);
        f[i][3] = a[i][3] + max(f[i+1][1], f[i+1][2]);
    }
    
    return max(f[1][1], max(f[1][2], f[1][3]));
}
int main() {
    int n; cin >> n;
    int grid[100002][4];
    for(int i = 1; i<=n; i++){
        for(int j = 1; j<=3; j++){
            cin >> grid[i][j];
        }
    }
    cout << f(grid, n) << "\n";
}

Measured memory_bytes: 5760
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <fstream>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
typedef long long ll;
#define REP(i, N) for (int i = 0; i < (int)N; i++)

const int UNVISITED = -1;
struct node {
  int reach, distance;
  bool isArticulationPoint;
  vector<node*> adjacentNodes;
};

vector<node> nodes;

int dfs(node* current, int dist, node* parent) {
  current->reach = dist;
  current->distance = dist;
  bool articulate = false;
  int numberOfChildren = 0;
  for(node* neighbor: current->adjacentNodes) {
    if(neighbor->distance == UNVISITED) {
      numberOfChildren++;
      current->reach = min(current->reach, dfs(neighbor, dist+1, current));
      articulate = articulate || (dist <= neighbor->reach);
    } else if(parent != neighbor) {
      current->reach = min(current->reach, neighbor->distance);
    }
  }
  if(parent == NULL) {
    current->isArticulationPoint = numberOfChildren > 1;
  } else {
    current->isArticulationPoint = articulate;
  }
  return current->reach;
}

int main () {
  int V, E;
  cin >> V >> E;
  nodes = vector<node>(V, (node){0, UNVISITED, false, vector<node*>(0)});

  for(int i = 0; i < E; i++) {
    int s, t;
    cin >> s >> t;
    nodes[s].adjacentNodes.push_back(&nodes[t]);
    nodes[t].adjacentNodes.push_back(&nodes[s]);
  }

  dfs(&nodes[0], 0, NULL);

  for(int i = 0; i < V; i++) {
    if(nodes[i].isArticulationPoint) cout << i << endl;
  }

  return 0;
}

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

long long n;
vector<long long> a, b, c;

int main() {
  cin >> n;
  a.resize(n);
  b.resize(n);
  c.resize(n);
  for(int i = 0; i < n; ++i) cin >> a[i];
  for(int i = 0; i < n; ++i) cin >> b[i];
  for(int i = 0; i < n - 1; ++i) cin >> c[i];
  long long ans = 0;
  for(int i = 0; i < n; ++i) {
    --a[i];
    ans += b[a[i]];
    if(i != 0 && a[i - 1] + 1 == a[i]) ans += c[a[i - 1]];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
	char c[100006],d[2][6]={"dream","erase"};
	long long i,l,n,m,o;
	gets(c);
	l=strlen(c);
	for(i=0;i<l;)
	{
		if(c[i]=='d')
		{
			for(o=1;o<5;o++)
			{
				if(d[0][o]==c[i+o])continue;
				else break;
			}
			if(o<5)break;
			if(c[i+5]=='e'&&c[i+6]=='r')
			{
				if(c[i+7]=='a'){
					i=i+5;
				}
				else i=i+7;
			}
			else i=i+5;
		}
		else if(c[i]=='e')
		{
		for(o=1;o<5;o++)
			{
				if(d[1][o]==c[i+o])continue;
				else break;
			}
			if(o<5)break;
			if(c[i+5]=='r') i=i+6;
			else i=i+5;
		}
		else break;
	}
	if(i==l)printf("YES");
	else printf("NO");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int M = 998244353;

int32_t main() {
  ios::sync_with_stdio(0);
  cout.tie(0);
  cin.tie(0);

  int n, s;
  cin >> n >> s;
  
  vector<int> a(n+1);
  vector<vector<int>> dp(n + 1, vector<int> (s + 1, 0));
  dp[0][0] = 1;

  for (int i = 1; i <= n; ++i) cin >> a[i];
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j <= s; ++j) {
      if (j >= a[i]) dp[i][j] = (dp[i][j] + dp[i-1][j-a[i]]) % M;
      dp[i][j] = (dp[i][j] + 2 * dp[i-1][j] % M) % M;
    }
  }
  cout << dp[n][s] << '\n'; 
}


Measured memory_bytes: 73688
parseInt(x) = parse(Int, x)
parseFloat(x) = parse(Float64, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    n = parseInt(readline())
    ans = 0
    for i = 1:n
        if i%2==0
            continue
        end
        res = 0
        for j = 1:i
            if i % j == 0
                res += 1
            end
        end
        if res == 8
            ans += 1
        end
    end
    println(ans)
end
main()

Measured memory_bytes: 111528
#include <cstdio>
#include <algorithm>
using namespace std;
long long read(){
	char c;while(c=getchar(),c<'0'||c>'9');
	long long x=c-'0';while(c=getchar(),c>='0'&&c<='9')x=x*10+c-'0';
	return x;
}
const int Maxn=2e5+5;
long long N,A[Maxn],Dev;
int main()
{
	N=read();
	for(long long i=1;i<=N;i++)
		A[i]=read()-i;
	sort(A+1,A+N+1);
	long long X=(N&1)?A[N+1>>1]:(A[N>>1]+A[(N>>1)+1]>>1);
	long long Ans=0;
	for(int i=1;i<=N;i++)Ans+=abs(A[i]-X);
	printf("%lld",Ans);
	return 0;
}

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

#define dump(...) cout<<"# "<<#__VA_ARGS__<<'='<<(__VA_ARGS__)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}

template<typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	print_tuple<Cdr...>(os,t);
	os<<(sizeof...(Cdr)?",":"")<<get<sizeof...(Cdr)>(t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

int main()
{
	for(int n,a,b;cin>>n>>a>>b && n|a|b;){
		string s; cin>>s;

		int x=0,y=0;
		for(char c:s){
			if(c=='a'){
				if(x+y<a+b){
					cout<<"Yes"<<endl;
					x++;
				}
				else{
					cout<<"No"<<endl;
				}
			}
			else if(c=='b'){
				if(x+y<a+b && y<b){
					cout<<"Yes"<<endl;
					y++;
				}
				else{
					cout<<"No"<<endl;
				}
			}
			else
				cout<<"No"<<endl;
		}
	}
}


Measured memory_bytes: 896
#include <algorithm>
#include <bitset>
// #include <boost/algorithm/string/replace.hpp>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

using namespace std;

#define FOR(i, j, n) for (int i = j; i < n; i++)
#define OUT(s) cout << s << endl;
#define IN(a) cin >> a;
#define PACK(a, n)                                                             \
  for (int i = 0; i < n; i++)                                                  \
    cin >> a[i];
#define LIST(a, n)                                                             \
  for (int i = 0; i < n; i++)                                                  \
    cout << i << ": " << a[i] << endl;
#define PP(label, obj) cout << "[" << label << "] " << obj << endl;

int main() {
  long long N;
  IN(N);
  
  long long s = 0;
  FOR(i, 1, N) {
    s += i;
  }
  
  OUT(s);
}

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

int main(){
	int n, x, ans=0; scanf("%d %d", &n, &x);
	vector<int> l(n+2), d(n+2, 0), bounces(100000, 0);
	for (int i=1; i<=n;++i)cin>>l[i];
	bounces[0]=1;
	d[1]=0;
	for (int i=2; i<=n+1; ++i){
		d[i]=d[i-1] + l[i-1];
		bounces[d[i]]++;
	}
	for(int i=0; i<=x; ++i) ans+=bounces[i];
	printf("%d", ans);
	return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;

int N;
vector<int> id;
vector<int> weight;
vector<int> dist;

double cost(int from, int to, int bit) {
    double w = 0;
    for(int i = 0; i < N; i++) {
        if(bit & (1 << i)) w += weight[i];
    }
    return abs(dist[from] - dist[to]) / (2000 / (70 + w));
}

typedef pair<int, int> P;
typedef pair<double, vector<int> > PP;

const double INF = 1e9;

const int MAX_N = 15;
PP dp[MAX_N][1 << MAX_N];

/*
pair<double, vector<int> > tsp(int v, int b) {
    if(dp[v][b].first != -1) return dp[v][b];
    if(b == (1 << N) - 1) {
        PP res;
        res.first = 0;
        res.second.push_back(id[v]);
        return dp[v][b] = res;
    }

    PP res;
    res.first = 1e9;

    for(int i = 0; i < N; i++) {
        if(b & (1 << i)) continue;
        PP r = tsp(i, b | (1 << i));
        r.first += cost(v, i, b);
        if(r.first < res.first) {
            res = r;
        }
    }

    if(b != 0) res.second.insert(res.second.begin(), id[v]);
    return dp[v][b] = res;
}
*/

int main() {
    cin >> N;
    id.clear();
    weight.clear();
    dist.clear();
    for(int i = 0; i < N; i++) {
        int num, d, box;
        cin >> num >> d >> box;
        id.push_back(num);
        dist.push_back(d);
        weight.push_back(box * 20);
    }

    for(int v = 0; v < N; v++) {
        for(int s = 0; s < (1 << N); s++) {
            dp[v][s].first = INF;
            dp[v][s].second.clear();
        }
    }

    for(int v = 0; v < N; v++) {
        dp[v][(1 << N) - 1].first = 0;
    }

    for(int S = (1 << N) - 2; S >= 0; S--) {
        for(int v = 0; v < N; v++) {
            for(int u = 0; u < N; u++) {
                PP r = dp[u][S | (1 << u)];
                r.first += cost(v, u, S);
                r.second.push_back(id[u]);
                if(r.first < dp[v][S].first) {
                    dp[v][S] = r;
                }
            }
        }
    }

    PP res;
    res.first = INF;
    for(int i = 0; i < N; i++) {
        // PP r = tsp(i, 0);
        PP r = dp[i][0];
        if(r.first < res.first) {
            res = r;
        }
    }

    cout << *res.second.rbegin();
    for(int i = res.second.size() - 2; i >= 0; i--) {
        cout << ' ' << res.second[i];
    }
    cout << endl;
}

Measured memory_bytes: 41800
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <algorithm>
using namespace std;
int main (){
    string n;
    cin >> n;
    int s = 0;
    int m = 0;
    for (int i = 0; i < n.size(); i++){
        s += n[i] - '0';
        m += (n[i] - '0')*pow (10, n.size() - i -1);
    }
    if (m % s == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
    }
    


Measured memory_bytes: 256
import heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop
import copy
from test.support import _MemoryWatchdog

BIG_NUM = 2000000000
HUGE_NUM = 99999999999999999
MOD = 1000000007
EPS = 0.000000001
sys.setrecursionlimit(100000)


#最大公約数
def gcd(x,y):
    x = abs(x)
    y = abs(y)

    if x < y:
        x,y = y,x

    if y == 0:
        return x
    else:
        return gcd(y,x%y)


class Info:
    def __init__(self,arg_numerator,arg_denominator):
        self.numerator = arg_numerator
        self.denominator = arg_denominator

while True:
    N = int(input())
    if N == 0:
        break

    ans = -1
    info = Info(1000,1)

    for i in range(N):
        ID,height,weight = map(int,input().split())
        height *= height
        weight *= 10000
        common = gcd(height,weight)
        height //= common
        weight //= common
        numerator = abs(22*height-weight)
        denominator = height

        if numerator*info.denominator < info.numerator*denominator:
            ans = ID
            info.numerator = numerator
            info.denominator = denominator

    print("%d"%(ans))


Measured memory_bytes: 13892