akhauriyash/Code-Regression huggingface dataset:
/*
 * †全方位木DP†
 */

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;

// template {{{  0 
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0
// random {{{ 1
ll rnd(){
    static ll x = time(0);
    x = x ^ (x << 13); x = x ^ (x >> 7);
    return x = x ^ (x << 17);
}
// }}}

int N,M;
vector<vi> e;
vector<vl> d;
vector<vl> df;
vector<vl> db;
vl ans;

// solve d
void dfs1( int from, int par = -1 ){
    for( int to : e[from] ){
        if( to == par ) continue;
        dfs1( to, from );
        d[from].push_back(df[to][df[to].size()-1]+1);
    }
    int n = d[from].size();
    df[from].assign( n+1, 1 );
    db[from].assign( n+1, 1 );
    Rep(i,n) df[from][i+1] = df[from][i] * d[from][i] % M;
    Rep(i,n) db[from][n-i-1] = db[from][n-i] * d[from][n-i-1] % M;
}

// solve ans
void dfs2( int from, ll d_par, int par = -1 ){
    int fi = 0;
    d_par++;
    for( int to : e[from] ){
        if( to == par ) continue;
        ll dd = df[from][fi] * db[from][fi+1];
        dd %= M;
        dfs2( to, dd * d_par % M , from);
        fi++;
    }
    ans[from] = d_par * df[from][fi] % M;
}

int main() {

    Scd2(N,M);
    e.resize(N);
    d.resize(N);
    df.resize(N);
    db.resize(N);
    ans.resize(N);

    int x,y;
    Rep(i,N-1){
        Scd2( x,y );
        x--,y--;
        e[x].push_back(y);
        e[y].push_back(x);
    }

    dfs1(0);

    dfs2(0,0);

    Rep(i,N){
        printf ("%lld\n", ans[i] % M );
    }

    return 0;
}




Measured memory_bytes: 29952
#include <stdio.h>
#include <string.h>
#include <queue>
using namespace std;

struct mData {
    int typ,index;
    int mh;
};

queue<mData>que;

int route[1010];

char map[110][110];
int LH,H;
int n,m,num,t,p;
int reduce[13];

char str[100];
int dam[26];

short vis[1010][1<<12];

inline int minnum(const int &x,const int &y){
	if(x<y)return x;return y;
}

void dfs(int index,int typ,int mh,int damage,int np){
	if(np==p){
		if(mh>damage && vis[mh][typ]<index){
			mData tem;
			vis[mh][typ]=index;
			tem.index=index;tem.mh=mh-damage;tem.typ=typ;que.push(tem);
		}
		return;
	}
	if(mh<=damage && (typ&(1<<np))==0)dfs(index,typ+(1<<np),minnum(mh+reduce[np],LH),damage,np+1);
	dfs(index,typ,mh,damage,np+1);
}

int main() {
    int i,j,k,ans;
    int x,y;
    mData tem;
    while(scanf("%d%d",&H,&LH)!=EOF) {
        if(H==0 && LH==0)break;
        scanf("%d%d",&n,&m);
        for(i=0; i<n; i++)scanf("%s",map[i]);
        scanf("%d",&i);
        for(; i>0; i--) {
            scanf("%s%d",str,&j);
            dam[str[0]-'A']=j;
        }
        scanf("%d",&t);
        x=0;y=0;num=0;
        for(i=0; i<t; i++) {
            scanf("%s%d",str,&j);
            if(str[0]=='U')for(; j>0; j--) {
                    x--;route[num++]=dam[map[x][y]-'A'];
                }
            if(str[0]=='D')for(; j>0; j--) {
                    x++;route[num++]=dam[map[x][y]-'A'];
                }
            if(str[0]=='L')for(; j>0; j--) {
                    y--;route[num++]=dam[map[x][y]-'A'];
                }
            if(str[0]=='R')for(; j>0; j--) {
                    y++;route[num++]=dam[map[x][y]-'A'];
                }
        }
        scanf("%d",&p);
        for(i=0;i<p;i++)scanf("%d",&reduce[i]);
        memset(vis,-1,sizeof(vis));
        while(!que.empty())que.pop();
        tem.mh=H;tem.typ=0;tem.index=-1;
        if(H>0)que.push(tem);
        for(ans=0;ans==0 && !que.empty();){
        	tem=que.front();que.pop();
        	if(tem.index==num-1){
        		ans=1;continue;
        	}
        	dfs(tem.index+1,tem.typ,tem.mh,route[tem.index+1],0);
        }
        if(ans==1)printf("YES\n");else printf("NO\n");
    }
    return 0;
}

Measured memory_bytes: 9208
#include <iostream>
#include<algorithm>
//#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb emplace_back
#define mp make_pair
#define MOD (int) 1e9+7
#define for0(i, n) for (int i = 0; i < n; i++)
#define ff first
#define ss second
#define endl "\n"
#define bits(n) __builtin_popcount(n)
#define ini(a, i) memset(a, i, sizeof(a))

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll t;
	// cin >> t;
	t  = 1;
	while (t--)
	{
		ll a, b, c, k;
		cin >> a >> b >> c >> k;
		ll cc = 0;
		while (a >= b)
		{
			b = b * 2;
			cc++;
		}
		while (b >= c)
		{
			c = c * 2;
			cc++;
		}
		if (cc <= k)
			cout << "Yes" << endl;
		else
			cout << "No" << endl;
	}
	return 0;
}


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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

int main() {
    string S, T;
    cin >> S >> T;
    cout << T << S << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;
import java.util.stream.Collectors;

public class Main {
    public static void main(String[] args) {
        PrintWriter out = new PrintWriter(System.out);
        InputStreamScanner in = new InputStreamScanner(System.in);
        new Main().solve(in, out);
        out.flush();
    }

    private void solve(InputStreamScanner in, PrintWriter out) {
        int n = in.nextInt();
        int k = in.nextInt();

        Map<Integer, Integer> a = new HashMap<>();
        for (int i = 0; i < n; i++) {
            int x = in.nextInt();
            a.put(x, a.getOrDefault(x, new Integer("0")) + 1);
        }

        a = a.entrySet().stream()
                .sorted(Map.Entry.<Integer, Integer>comparingByValue().reversed())
                .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, LinkedHashMap::new));

        int c = -1;
        int t = 0;
        for (int i : a.values()) {
           c++;
           if (c < k) {
               continue;
           }
           t += i;
        }

        out.println(t);
    }

    static class InputStreamScanner {

        private InputStream in;

        private byte[] buf = new byte[1024];
        private int len = 0;
        private int off = 0;

        InputStreamScanner(InputStream in)	{
            this.in = in;
        }

        String next() {
            StringBuilder sb = new StringBuilder();
            for (int b = skip(); !isSpace(b);){
                sb.appendCodePoint(b);
                b = read();
            }
            return sb.toString();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        char nextChar() {
            return (char)skip();
        }

        int skip() {
            for (int b; (b = read()) != -1;) {
                if (!isSpace(b)) {
                    return b;
                }
            }
            return -1;
        }

        private boolean isSpace(int c) {
            return c < 33 || c > 126;
        }

        private int read() {
            if (len == -1) {
                throw new InputMismatchException("End of Input");
            }
            if (off >= len){
                off = 0;
                try {
                    len = in.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException(e.getMessage());
                }
                if (len <= 0) {
                    return -1;
                }
            }
            return buf[off++];
        }
    }
}


Measured memory_bytes: 63888
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		String S = scan.next();
		String T = scan.next();
		String[] Sarray = S.split("");
		String[] Tarray = T.split("");

		int count = 0;
		for(int i=0; i<S.length(); i++) {
			if(!(Sarray[i].equals(Tarray[i]))) {
				count = count + 1;
			}

		}
		System.out.println(count);

	}

}

Measured memory_bytes: 66344
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
	ll n;
	scanf("%lld", &n);
	ll sum = 0;
	for (ll i = 1; i <= n; i++) {
		if (i % 3 && i % 5)
			sum += i;
	}
	printf("%lld", sum);
}

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



int main() {
  int N;
  cin>>N;
  vector<int> vec(N);
  for(int i=0;i<N;i++){
    cin>>vec.at(i);
  }
  int64_t sum=0;
  int G=vec.at(0);
  for(int i=1;i<N;i++){
    if(vec.at(i)>G){
      G=vec.at(i);
    }
    else{
      sum+=(G-vec.at(i));
    }
  }
  cout<<sum<<endl;
  
}

Measured memory_bytes: 3976
#include<bits/stdc++.h>
using namespace std;
int n,x,a[200005],b,e,i;
int main(){
    cin>>n;
    b=ceil((double)(n+1)/2);
    if(n%2==0){
        e=-1;
    }else{
        e=1;
    }
    for(i=1;i<=n;i++){
        cin>>x;
        a[b]=x;
        b+=i*e;
        e*=-1;
    }
    for(i=1;i<=n;i++){
        cout<<a[i]<<" ";
    }
    return 0;
}

Measured memory_bytes: 2944
//In The Name Of The God

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define ld long double
#define F first
#define S second
#define X first.first
#define Y first .second
#define A second.first
#define B second.second
#define mp make_pair
#define pb push_back
#define pf push_front
#define P push
#define pob pop_back
#define pof pop_front
#define PO pop
#define rep(i,j,k) for(int i = j ; i <= k ; ++ i)
#define rrep(i,j,k) for(int i = j ; i>=k ; --i)
#define FR(i,j,k) for(int i = j ; i < k ; ++ i )
#define rFR(i,j,k) for(int i = j ; i > k ; -- i )
#define lb(x) x&-x
#define p2(x) (1LL<<x)
#define SZ size()
#define LB lower_bound
#define UB upper_bound
#define IT iterator
#define RIT reverse_iterator
#define E end()
#define BE begin()
#define RE rend()
#define RBE rbegin()
#define UN unsigned

typedef pair<int,int> pii;
typedef pair<int,ll> pil;
typedef pair<ll,int> pli;
typedef pair<ll,ll> pll ;
typedef pair<int,pii> pip;
typedef pair<pii,int> ppi;
typedef pair<pii,pii> ppp;
typedef pair<int,pll> pipl;
typedef pair<pll,int> ppli ;
typedef pair<pll,pll> plpl ;
typedef pair<ll,pii> lpip;
typedef pair<pii,ll> lppi;
typedef pair<pii,pii> lppp;
typedef pair<ll,pll> lpipl;
typedef pair<pll,ll> lppli ;
typedef pair<pll,pll> lplpl ;
typedef vector<int> vi ;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef set<int> sti;
typedef set<ll> stl;
typedef set<pii > stpi;
typedef set<pll> stpl;
typedef vi::IT vit;
typedef vl::IT vlt;
typedef vpi::IT vpit;
typedef vpl::IT vplt;
typedef sti::IT stit;
typedef stl::IT stlt;
typedef stpi::IT stpit;
typedef stpl::IT stplt;
typedef vpi::RIT rvpit;
typedef vpl::RIT rvplt;
typedef sti::RIT rstit;
typedef stl::RIT rstlt;
typedef stpi::RIT rstpit;
typedef stpl::RIT rstplt;

const int MAXN = 500000;
const int SUPERN = 5000000;
const int MAXS = 325;
const int SUPERS = 1000;
const int MD = 1e9+7;
//......Structures.......

//......Variables........
ll n,a[MAXN],x,y;
//......Funcs............
ll sum(ll a,ll b)
{
    return (a+b)%MD;
}
ll mu(ll a,ll b)
{
    return (a*b)%MD;
}
ll mn(ll a,ll b)
{
    return(a-b+MD)%MD;
}
//......Code.............
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    cin>>n;
    rep(i,1,n)cin>>a[i];
    sort(a+1,a+n+1);
    rrep(i,n-1,1)
    {
        if(a[i]==a[i+1])
        {
            if(x)
            {
                y=a[i];
                break;
            }
            else x=a[i],i--;
        }
    }
    if(x&&y)
    {
        cout<<x*y;
    }
    else cout<<0;
    return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
bool f[10][10000];
int max(int a,int b){return a>b?a:b;}
int main(){
	int r,c;
	while(1){
	scanf("%d %d",&r,&c);
	if(r==0)return 0;
	int i,j,k;
	for(i=0;i<r;i++){
		for(j=0;j<c;j++){
			int x;
			scanf("%d",&x);
			f[i][j]=x==0;
		}
	}
	int ans=0;
	for(i=0;i<1<<r;i++){
		bool rv[10];
		for(j=0;j<r;j++)rv[j]=i>>j&1;
		int res=0;
		for(j=0;j<c;j++){
			int p=0;
			for(k=0;k<r;k++)if(f[k][j]^rv[k])p++;
			if(p>=r-p)res+=p;
			else res+=r-p;
		}
		ans=max(ans,res);
	}
	printf("%d\n",ans);
	}
}

Measured memory_bytes: 1124
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
typedef int64_t Int;

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

    vector<int> A(N);
    rep (i,N) {
        Int a;
        cin >> a;
        if (a >= (Int)N) A[i] = N;
        else A[i] = a; //A[i]がN以上の奴らは絶対ペアにはならないから上限をNにしてよい
    }

    vector<int> x(N), y(N);

    rep(i,N) {
        x[i] = min(A[i]+i+1, N); //yの中にN以上の値は出てこないから無視
        y[i] = max(0, i+1-A[i]); //xの中に0以下の値は出てこないから無視
    }

	vector<Int> x_cnt(N+1,0), y_cnt(N+1,0);
  
  	rep(i,N) {
      x_cnt[x[i]]++;
      y_cnt[y[i]]++;
    }
  
  	Int ans = 0;
  
  	rep1(i,N-1) {
      ans += x_cnt[i] * y_cnt[i];
    }

    cout << ans << endl;
}


Measured memory_bytes: 8804
#include <stdio.h>

int main(void)
{
	int a, b;

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

	if (a < b) {
		printf("a < b\n");
	}
	else if (a > b) {
		printf("a > b\n");
	}
	else if (a == b) {
		printf("a == b\n");
	}

	return 0;
}


Measured memory_bytes: 2104
package main

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

/*-----------Main-----------*/

func main() {
	n := readI()
	s := readSs(n)

	fmt.Println(len(unique(s)))
}

func unique(a []string) map[string]bool {
	u := make(map[string]bool, len(a))
	for _, v := range a {
		u[v] = true
	}
	return u
}

func isContain(a []string, b string) bool {
	for _, v := range a {
		if v == b {
			return true
		}
	}
	return false
}

/*-----------Utilities-----------*/

var sc = bufio.NewScanner(os.Stdin)

func init() {
	if len(os.Args) >= 2 {
		if os.Args[1] == "debug" {
			debug()
		}
	}
	const maxBuf = 200100
	var buf []byte = make([]byte, maxBuf)
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBuf)
}

func debug() {
	testFile, err := os.Open("./test/sample-1.in")
	if err != nil {
		fmt.Fprintln(os.Stderr, "Error : There is no testfile.")
		os.Exit(1)
	}
	sc = bufio.NewScanner(testFile)
}

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

func readSs(a int) []string {
	b := make([]string, a)
	for i := 0; i < a; i++ {
		b[i] = readS()
	}
	return b
}

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

func readIs(a int) []int {
	b := make([]int, a)
	for i := 0; i < a; i++ {
		b[i] = readI()
	}
	return b
}

func readF() float64 {
	sc.Scan()
	r, _ := strconv.ParseFloat(sc.Text(), 64)
	return r
}

func readFs(a int) []float64 {
	b := make([]float64, a)
	for i := 0; i < a; i++ {
		b[i] = readF()
	}
	return b
}

func max(a []int) int {
	l := len(a)
	m := a[0]
	for i := 1; i < l; i++ {
		if a[i] > m {
			m = a[i]
		}
	}
	return m
}

func min(a []int) int {
	l := len(a)
	m := a[0]
	for i := 1; i < l; i++ {
		if a[i] < m {
			m = a[i]
		}
	}
	return m
}

func sortI(a []int) []int {
	sort.Ints(a)
	return a
}

func reverse(a []int) []int {
	l := len(a)
	r := make([]int, l)
	for i := 0; i < l; i++ {
		r[i] = a[l-i-1]
	}
	return r
}

func countI(a []int, b int) int {
	l := len(a)
	var c int
	for i := 0; i < l; i++ {
		if a[i] == b {
			c++
		}
	}
	return c
}


Measured memory_bytes: 14460
def z_algorithm(s):
    res = [0 for _ in range(len(s))]
    res[0] = len(s)
    i, j = 1, 0
    while i < len(s):
        while i + j < len(s) and s[j] == s[i + j]:
            j += 1
        res[i] = j
        if j == 0:
            i += 1
            continue
        k = 1
        while k < j and k + res[k] < j:
            res[i + k] = res[k]
            k += 1
        i += k
        j -= k
    return res

N = int(input())
S = input()

res = 0

for i in range(N):
    z = z_algorithm(S[i:])
    for j in range(N - i):
        res = max(res, min(j, z[j]))

print(res)

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

int insertion_sort(vector<int>& a, int n, int g) {
  int cnt = 0;
  for (size_t i = g; i < n; i++) {
    int v = a[i];
    int j = i - g;
    while (j >= 0 && a[j] > v) {
      a[j + g] = a[j];
      j -= g;
      cnt++;
    }
    a[j + g] = v;
  }
  return cnt;
}

void shell_sort(vector<int>& a, int n) {
  vector<int> g;
  for (int i = 1; i <= n; i = 3 * i + 1) {
    g.push_back(i);
  }
  reverse(g.begin(), g.end());
  int m = g.size();
  int cnt = 0;
  for (int i = 0; i < m; i++) {
    cnt += insertion_sort(a, n, g[i]);
  }
  cout << m << "\n";
  for (int i = 0; i < m; i++) {
    cout << (i ? " " : "") << g[i];
  }
  cout << "\n" << cnt << "\n";
  for (int i = 0; i < n; i++) {
    cout << a[i] << "\n";
  }
}

int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  int n, t;
  cin >> n;
  vector<int> a;
  for (int i = 0; i < n; i++) {
    cin >> t;
    a.push_back(t);
  }
  shell_sort(a, n);
}


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

#define rep(l, r) for (int i = (l); i < (r); i++)

typedef long long ll;
 
using namespace std;

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

    bool found = false;
    for (int i = 1; i <= 9; i++) {
        for (int j = 1; j <= 9; j++) {
            if (i * j == n) {
                found = true;
                break;
            }
        }
    }

    cout << (found ? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
        String s = scan.next();
		if (s.equals("ARC")) {
			System.out.println("ABC");
		} else if (s.equals("ABC")) {
			System.out.println("ARC");
		}
	}
}

Measured memory_bytes: 35580
#include <bits/stdc++.h>
using namespace std;
// int N が既に与えられているとする.

vector<int> ssplit(const string& src, char delim) {
  vector<int> vec;
  string::size_type len = src.length();

  for (string::size_type i = 0, n; i < len; i = n + 1) {
    n = src.find_first_of(delim, i);
    if (n == string::npos) {
      n = len;
    }
    // cout << ":" << src.substr(i, n - i);
    vec.push_back(atoi(src.substr(i, n - i).c_str()));
  }

  return vec;
}

int main() {
  int N, K;
  cin >> N >> K;
  bool okasi[N];
  for (int i = 0; i < N; i++) okasi[i] = false;
  for (int i = 0; i < K * 2; i++) {
    string str;
    if (i % 2 == 0) {
      cin >> str;
      cin.ignore();
      continue;
    }
    string s;
    getline(cin, s);
    vector<int> v;
    v = ssplit(s, ' ');
    for (int j = 0; j < v.size(); ++j) {
      okasi[v[j] - 1] = true;
    }
  }
  int cnt = 0;

  for (int i = 0; i < N; i++)
    if (!okasi[i]) ++cnt;
  cout << cnt;
}

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

int seach(int S[],int T[],int numS,int numT);

int main(void)
{ 
  int numS,numT;
  int *S,*T;
  int i;

  scanf("%d",&numS);
  
  S=calloc(numS+1,sizeof(int));

  for(i=0;i<numS;i++)
    {
      scanf("%d",&S[i]);
    }

  scanf("%d",&numT);

  T=calloc(numT,sizeof(int));

  for(i=0;i<numT;i++)
    {
      scanf("%d",&T[i]);
    }

  printf("%d\n",seach(S,T,numS,numT));

  free(S);
  free(T);

  return 0;
}
  
int seach(int S[],int T[],int numS,int numT)
{
  int i,j;
  int count=0;

  for(i=0;i<numT;i++)
    {
      S[numS]=T[i];
      
      j=0;

      while(1)
	{
	  if(S[j]==T[i])
	    {
	      if(j!=numS)
		{
		  count++;
		}
	      break;
	    }	  
	  j++;    
	}
    }
  return count;
}



Measured memory_bytes: 2108
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define PII pair<int,int>
#define VI vector<int>
#define VPII vector<pair<int,int> >
#define PLL pair<long long,long long>
#define VPLL vector<pair<long long,long long> >
#define F first
#define S second
typedef long long LL;
using namespace std;
const int MOD = 1e9+7;
const int SIZE = 1e6+10;

int main(){
    DRI(n);
    set<int>d;
    int sp=0;
    REP(i,n){
        DRI(x);
        if(x<400)d.insert(1);
        else if(x<800)d.insert(2);
        else if(x<1200)d.insert(3);
        else if(x<1600)d.insert(4);
        else if(x<2000)d.insert(8);
        else if(x<2400)d.insert(5);
        else if(x<2800)d.insert(6);
        else if(x<3200)d.insert(7);
        else sp++;
    }
    printf("%d %d\n",max(SZ(d),1),SZ(d)+sp);
    return 0;
}


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

int main(){
	int n,k;
	string str;
	cin >> n >> k;
	map<char,int> q;
	int r,s,p;
	cin >> r >> s >> p; 
	q['r'] = p;
	q['s'] = r;
	q['p'] = s;
	cin >> str;
	vector<string> v(k,"");
	for(int i = 0;i < n;i++){
		v[i % k].pb(str[i]);
	}
	// for(int i = 0; i < k; i++) {
	// 	cout << v[i] << endl;
	// }
	int ans = 0;
	for(int i = 0; i < k; i++) {
		for(int j = 0; j < v[i].size(); j++) {
			if (j == 0){
				ans += q[v[i][j]];
			}
			else if (v[i][j] == v[i][j - 1]){
				v[i][j] = 'x';
			}
			else{
				ans += q[v[i][j]];
			}
		}

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

Measured memory_bytes: 5120
n,i;
ea[2<<17],eb[2<<17],next[2<<17],first[1<<17];
long M,dp1[1<<17],dp2[1<<17],R[2<<17];
/*dfs1(u,p,i)
{
	dp1[u]=1;
	for(i=first[u];i;i=next[i])eb[i]-p?dfs1(eb[i],u),dp1[u]=dp1[u]*-~dp1[eb[i]]%M:0;
}*/
dfs1(u,p,i,I)
{
	dp1[u]=1;
	for(i=first[u];I=eb[i];i=next[i])I-p?dfs1(I,u),dp1[u]=dp1[u]*-~dp1[I]%M:0;
}
/*dfs2(u,p,x,i)
{
	i=first[u];
	dp2[u]=dp1[u]*x%M;
	make(i,p,x);
	for(;i;i=next[i])
	{
		if(eb[i]!=p)dfs2(eb[i],u,L[i]*R[next[i]]%M+1);
	}
}
make(i,p,x,t)
{
	if(i)
	{
		L[i]=x;
		t=eb[i]-p?-~dp1[eb[i]]:1;
		make(x=next[i],p,t%M*x%M);
		R[i]=R[x]*t%M;
	}
}*/
/*
dfs2(u,p,x,i)
{
	i=first[u];
	dp2[u]=dp1[u]*x%M;
	make(i,p);
	for(;i;i=next[i])eb[i]-p?dfs2(eb[i],u,R[next[i]]*x%M+1),x=x%M*-~dp1[eb[i]]%M:0;
}
*/
/**/
dfs2(u,p,x,i,I)
{
	//dp2[u]=dp1[u]*x%M;
	for(make(i=first[u],p);I=eb[i];i=next[i])I-p?dfs2(I,u,R[next[i]]*x%M+1,0,0),x=x%M*-~dp1[I]%M:0;
	dp2[u]=x%M;
}
/**/
make(i,p)
{
	if(i)make(next[i],p),R[i]=R[next[i]]*(eb[i]-p?-~dp1[eb[i]]:1)%M;
}
main(u,v)
{
	/*for(scanf("%d%d",&n,&M);~scanf("%d%d",&u,&v);)
	{
		i++;
		ea[i]=u;
		eb[i]=v;
		i++;
		ea[i]=v;
		eb[i]=u;
	}*/
	//for(;~scanf("%d%d",&u,&v);)i++?ea[i]=eb[i+1]=u,ea[i+1]=eb[i]=v,i++:(n=u,M=v);
	for(;~scanf("%d%d",&u,&v);i++)i++?ea[i-1]=eb[i]=u,ea[i]=eb[i-1]=v:(n=u,M=v);
	//for(;~scanf("%d%d",&u,&v);)i++?ea[i-1]=eb[i]=u,eb[i-1]=ea[i++]=v:(n=u,M=v);
	for(;--i;first[ea[i]]=i)next[i]=first[ea[i]];
	dfs1(*R=1,0);
	dfs2(1,0,1);
	for(;i++<n;)printf("%d\n",dp2[i]);
}

Measured memory_bytes: 13824
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <map>
using namespace std;



int main() {
  map<string, int> str;
  int N, M, max = -10000;
  cin >> N;
  string s[N];
  for(int i=0; i<N; ++i) {
    cin >> s[i];
    str[s[i]] = 0;
  }

  cin >> M;
  string t[M];
  for(int i=0; i<M; ++i) {
    cin >> t[i];
    str[t[i]] = 0;
  }

  for(int i=0; i<N; ++i) str[s[i]] += 1;
  for(int i=0; i<M; ++i) str[t[i]] -= 1;

  for(int i=0; i<N; ++i) {
    if(max < str[s[i]]) max = str[s[i]];
  }
  for(int i=0; i<M; ++i) {
    if(max < str[t[i]]) max = str[t[i]];
  }

  if(max < 0) cout << 0 << endl;
  else cout << max << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll 				long long
#define ld 				long double
#define fastio 			ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define debug(x) 		cerr<<#x<<" "<<x<<endl
#define cina(a,n) 		for(ll i = 0;i<n;i++)	cin>>a[i];
#define couta(a,n) 		for(ll i = 0;i<n;i++) cout<<a[i]<<" ";
#define mod 			1000000007
#define siz 			105
#define f 				first
#define s 				second
#define pb 				push_back
#define endl 			"\n"
#define ci 				cin.ignore()
using namespace std;
int main()
{
	string a,b;
	cin>>a>>b;
	
	ll n = a.length(),m = b.length(),i,j;
	
	ll dp[n+1][m+1];
	for(i = 0;i<=n;i++)
	dp[i][0] = 0;
	for(i = 0;i<=m;i++)
	dp[0][i] = 0;
	
	for(i = 1;i<=n;i++)
	{
		for(j = 1;j<=m;j++)
		{
			if(a[i-1] == b[j-1])
			{
				dp[i][j] = dp[i-1][j-1]+1;
			}
			else
			{
				dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
			}
		}
	}
	
	string s = "";
		i = n;
		j = m;
		while(i > 0 && j > 0)
		{
			if(a[i-1] == b[j-1])
			{
				s += a[i-1];
				i--;
				j--;
			}
			else
			if(dp[i-1][j] >= dp[i][j-1])
			{
				i--;			
			}		
			else
			{
				j--;
			}	
			
		}
		
		reverse(s.begin(),s.end());
	
	cout<<s<<endl;
}

Measured memory_bytes: 70656
#include<stdio.h>
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
using ll=long long;
int main() {
	ll N;
	vector<ll>a;
	cin >> N;
	ll g;
	for (ll i=0; i < N * 3; i++) {
		cin >> g;
		a.push_back(g);


	}
	sort(a.begin(), a.end());
	ll sum=0;
	for (int i=0; i < N; i++) {

		sum +=a[3*N-i*2-2];
		
	}
	cout << sum;

}


Measured memory_bytes: 6384
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author ShekharN
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int num = in.nextInt(), total = in.nextInt();
            for (int i = 0; i <= num; i++) {
                for (int j = 0; j <= num; j++) {
                    int x = num - i - j;
                    if (x >= 0) {
                        int tmpX = total - 10000 * i - 5000 * j;
                        if (1000 * x == tmpX) {
                            out.println(i + " " + j + " " + x);
                            return;
                        }
                    }
                }
            }

            out.println("-1 -1 -1");
        }

    }

    static class FastScanner {
        private BufferedReader br;
        private StringTokenizer st;

        public FastScanner(File f) {
            try {
                br = new BufferedReader(new FileReader(f));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        public FastScanner(InputStream f) {
            br = new BufferedReader(new InputStreamReader(f));
        }

        public String nextString() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return null;
                st = new StringTokenizer(s);
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextString());
        }

    }
}



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

typedef long long int ll;

ll powk(ll a, ll n = 2){
    ll r = 1;
    for(ll i = 0;i < n;i++){
        r *= a;
    }

    return r;
}


int main()
{
    ll n;
    cin >> n;
    vector<ll> a(n);
    ll m = 0;
    for(ll i = 0;i < n;i++){
        cin >> a[i];
        m = max(a[i], m);
    }

    vector<ll> kurai(30);
    vector<vector<ll>> ans(n, vector<ll>(30));


    for(ll i = 0;i < n;i++){
        ll c = 0;
        while(a[i] != 0){
            if(a[i] % 2 != 0){
                kurai[c]++;
                ans[i][c]++;
            }
            a[i] /= 2;
            c++;
        }
    }

    for(ll i = 0;i < n;i++){
        ll hoka = 0;
        for(ll j = 0;j < 30;j++){
            ans[i][j] = n - kurai[j] - ans[i][j];
            if(ans[i][j] % 2 != 0){
                hoka += powl(2, j);
            }
        }
        cout << hoka << "\n";
    }


    return 0;
}


Measured memory_bytes: 59468
import java.util.Scanner;

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

		int train = n * a;
		int taxi = b;

		if(train <= taxi) {
			System.out.println(train);
		}else {
			System.out.println(taxi);
		}
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
#define LL long long
using namespace std;
const int64_t MOD = 1e9 + 7;

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

	vector<int> v(N+2);
	for (int i = 1; i <= N; i++) cin >> v.at(i);

	int sum = 0;
	for (int i = 1; i < v.size(); i++) {
		sum += abs(v.at(i) - v.at(i - 1));
	}

	for (int i = 1; i <= N; i++) {
		int n = sum;
		n -= (abs(v.at(i) - v.at(i - 1)) + abs(v.at(i + 1) - v.at(i)));
		n += abs(v.at(i + 1) - v.at(i - 1));
		cout << n << endl;
	}
}

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

def readInts():
  return [int(s) for s in input().split(" ")]

def main():
  a = readInts()[0]
  s = input()

  if a >= 3200:
    print(s)
  else:
    print("red")

if __name__ == "__main__":
  main()


Measured memory_bytes: 3316
#include <bits/stdc++.h>
#include <iostream>
#include <utility>
#include <algorithm>
#include <numeric>
#define load ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
#define ll long long
#define ull unsigned long long
#define fori(i,n) for (int i=0; i<int(n);i++)
#define srt(v) sort(v.begin(), v.end())
#define MOD 1000000007
const int INF = 1e9;
const double PI = 3.14159265358979323846;

ll gcd(ll a, ll b) {
    return b != 0 ? gcd(b, a % b) : a;
}
 
ll lcm(ll a, ll b) {
    return (a * b) / gcd(a, b);
}

void solve(){

}

int main(){
	load;
    int a,b;
    cin>>a>>b;
    cout << a*b;
	
	return 0;
}



Measured memory_bytes: 3584
#include<stdio.h>

int main(){
    int N; 
    int C[500], S[500], F[500];
    int i, j, t;

    scanf("%d", &N);
    for(i=0; i<N-1; i++){
        scanf("%d %d %d", &C[i], &S[i], &F[i]);
    }

    for(i=0; i<N; i++){
        t = 0;
        for(j=i; j<N-1; j++){
            if(t<S[j]){
                t=S[j];
            }else if((t%F[j])!=0){
                t=t+F[j]-t%F[j];
            }
            t+=C[j];
        }
        printf("%d\n", t);
    }

    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include <math.h>
typedef long long ll;

ll n, x[8], y[8], t[8];
double ans = 0.0, now = 0.0;
bool flg[8];

void dfs(ll a) {
  ll i;
  if(a == n) {
    ans += now;
    return;
  }
  for(i = 0; i < n; ++i) if(flg[i]) {
    if(a) now += sqrt((double)(x[i] - x[t[a - 1]]) * (x[i] - x[t[a - 1]]) + (double)(y[i] - y[t[a - 1]]) * (y[i] - y[t[a - 1]]));
    t[a] = i, flg[i] = false;
    dfs(a + 1);
    if(a) now -= sqrt((double)(x[i] - x[t[a - 1]]) * (x[i] - x[t[a - 1]]) + (double)(y[i] - y[t[a - 1]]) * (y[i] - y[t[a - 1]]));
    flg[i] = true;
  }
}

int main(void) {
  ll i;
  scanf("%lld", &n);
  for(i = 0; i < n; ++i) scanf("%lld%lld", &x[i], &y[i]), flg[i] = true;
  dfs(0);
  for(i = 1; i <= n; ++i) ans /= i;
  printf("%lf", ans);
  return 0;
}

Measured memory_bytes: 128
#%%
import sys
def input():
    return sys.stdin.readline().rstrip()

def main():
    N, M = map(int, input().split())

    print(N*(N-1)//2+M*(M-1)//2)

# %%
if __name__ == '__main__':
    main()

# %%
# from atcoder_test import doTest
# doTest("abc159","a",main)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N, Q;
  cin >> N >> Q;
  vector<vector<int>> G(N,vector<int>(0));
  for(int i=0; i<N-1; i++){
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    G.at(a).push_back(b);
    G.at(b).push_back(a);
  }
  vector<int> query(N,0);
  for(int i=0; i<Q; i++){
    int a, b;
    cin >> a >> b;
    a--;
    query.at(a) += b;
  }
  vector<bool> seen(N,false);
  seen.at(0) = true;
  queue<int> q;
  q.push(0);
  while(q.size()){
    int x = q.front();
    q.pop();
    for(int i=0; i<G.at(x).size(); i++){
      int y = G.at(x).at(i);
      if(!seen.at(y)){
        query.at(y) += query.at(x);
        q.push(y);
        seen.at(y) = true;
      }
    }
  }
  for(int i=0; i<N; i++){
    cout << query.at(i) << endl;
  }
}

Measured memory_bytes: 15604
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    cout << fixed << setprecision(10);
    double a,b,x;
    cin >> a >> b >> x;
    double s = x/a;
    double h = 2*(a*b - s)/a;
    double w = 2*x/(a*b);
    if(a*b/2 < s) cout << atan2(h,a)/acos(-1) * 360.0/2  << endl;
    else cout << atan2(b,2*x/(a*b))/acos(-1) * 360.0/2 << endl;
    return 0;
}

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

using namespace std;

int main(){
    int n,d;
    cin >> n >> d;
    int a = n % (2*d + 1);
    if(a){
        cout << (n / (2*d + 1)) + 1 << endl;
    }else{
        cout << (n / (2*d + 1)) << endl;
    }
}

Measured memory_bytes: 256
import Data.List
main = getContents >>= putStr . fout . switching_cars . fin . lines
fin = id
fout = unlines . map head
  
switching_cars cs = filter (not . null) $ zipWith (\\) keeplog (tail keeplog)
 where keeplog = scanl (\acc c -> if c=="0" then tail acc else c:acc) [] cs

Measured memory_bytes: 3524
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int A,B;
  cin>>A>>B;
  for(int i=1;i<=B;i++){
    if(B==A*i){
      cout<<A+B<<endl;
      return 0;
    }
  }
  cout<<B-A<<endl;
}


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

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))


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

    int n;
    cin >> n;

    vs64 a(n); rep (i, n) cin >> a[i];

    map<s64, s64> dp[n + 1];
    dp[0][0] = 1000;

    rep (i, n)
    {
        for (auto item : dp[i])
        {
            s64 kabu = item.first;
            s64 money = item.second;
            // rep (j, money / a[i] + 1) // buy
            // {
            //     dp[i + 1][kabu + j] = max(dp[i + 1][kabu + j], money - j * a[i]);
            // }
            dp[i + 1][kabu + money / a[i]] = max(dp[i + 1][kabu + money / a[i]], money - money / a[i] * a[i]);
            dp[i + 1][0] = max(dp[i + 1][0], money + kabu * a[i]);
            dp[i + 1][kabu] = max(dp[i + 1][kabu], money);
            // rep (j, kabu + 1) // sell
            // {
            //     dp[i + 1][kabu - j] = max(dp[i + 1][kabu - j], money + j * a[i]);
            // }
        }
    }

    s64 ans = 0;
    for (auto item : dp[n])
    {
        ans = max(ans, item.second);
    }

    cout << ans << "\n";
    return 0;
}



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

int main() {
	int x, y, grupx, grupy;
	scanf("%d%d", &x, &y);
	if(x == 2) grupx = 1;
		else if(x == 4 || x == 6 || x == 9 || x == 11) grupx = 2;
		else grupx = 3;
	if(y == 2) grupy = 1;
		else if(y == 4 || y == 6 || y == 9 || y == 11) grupy = 2;
		else grupy = 3;
	if(grupy == grupx) printf("Yes");
	else printf("No");
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

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

        int total = 0;
        for (int i = 0; i < n; i++) {
            int l = sc.nextInt();
            int r = sc.nextInt();

            total += r - l + 1;
        }
        System.out.println(total);
    }
}


Measured memory_bytes: 25168
using System;
using System.Linq;

namespace AtCoder {
    class Program {
        static void Main() {
            int[] nm = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int[] h = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            bool[] isNotGood = new bool[nm[0]];
            for(int i = 0; i < nm[1]; i++) {
                int[] ab = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
                if(h[ab[0] - 1] > h[ab[1] - 1]) {
                    isNotGood[ab[1] - 1] = true;
                } else if(h[ab[0] - 1] < h[ab[1] - 1]) {
                    isNotGood[ab[0] - 1] = true;
                } else {
                    isNotGood[ab[0] - 1] = true;
                    isNotGood[ab[1] - 1] = true;
                }
            }
            Console.WriteLine(isNotGood.Count(x => !x));
        }
    }
}

Measured memory_bytes: 54856
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;

int main(){
    int N;
    cin >> N;
    int L[11];
    for(size_t i = 0; i < N; i++)
        cin >> L[i];
    int max = -1;
    int total = 0;
    for(size_t i = 0; i < N; i++)
    {
        total += L[i];
        if (L[i] > max)
            max = L[i];
    }
    string ret = max < total - max ? "Yes" : "No";
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.PriorityQueue;
import java.util.StringTokenizer;

public class Main {


	static long f(long b,long[] arr) {
		long sum = 0;
		for (int i = 0 ; i < arr.length ; ++i) {
			sum += Math.abs(arr[i] - (b + i + 1));
		}
		return sum;
	}
	public static void main(String[]args) throws Throwable {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int n = sc.nextInt();

		long arr[] = new long[n];
		for (int i = 0 ; i < n ; ++i) {
			arr[i] = sc.nextLong();
		}
		
		long left = -1L << 35, right = 1L << 35; // set your range
		while (right-left > 3) { // We need 4 different positions
			long g = left + (right - left) / 3, h = left + 2 * (right - left) / 3;

			if (f(g,arr) < f(h,arr)) // use > if f increase then decrease
				right = h;
			else
				left = g;
		}

		long solIdx = left, answer = f(left++,arr);
		for (long i = left; i <= right; ++i)	// iterate on the remaining
			if(answer > f(i,arr)) {
				answer = f(i,arr);
			}

		out.println(answer);
		out.flush();
		out.close();
	}
	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public Scanner(String s) throws FileNotFoundException {
			br = new BufferedReader(new FileReader(new File(s)));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public boolean ready() throws IOException {
			return br.ready();
		}
	}
}

Measured memory_bytes: 45708
use proconio::{input, fastout};
use proconio::marker::{Chars};
use proconio::marker::Usize1;
use std::cmp::*;

macro_rules! debug {
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

#[fastout]
fn main() {
    input!{
        a: usize,
        b: usize,
    }

    println!("{}",(a+b)%24);

}


Measured memory_bytes: 2160
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int solve(string s1,string s2)
{
    ll x = min(s1.length(),s2.length());
    for(ll i =0;i<x;i++)
    {
        if(s1[i]>s2[i]) return 1;
    }
    return 0;
}
string s = "abcdefghijklmnopqrstuvwxyz";
int main()
{
string s1,s2;
cin>>s1>>s2;
int a[26] = {0},b[26] = {0};
for(int i =0;i<s1.length();i++)
{
    a[s1[i]-'a']++;

}
for(int i =0;i<s2.length();i++)
{
    b[s2[i]-'a']++;

}
string ans1,ans2;
for(int i =0;i<26;i++)
{
    for(int j =0;j<a[i];j++)
    {
        ans1+=s[i];
    }
}
for(int i =25;i>=0;i--)
{
    for(int j =0;j<b[i];j++)
    {
        ans2+=s[i];
    }
}
//cout<<ans1<<" "<<ans2;
if(ans2>ans1) cout<<"Yes";
else cout<<"No";
return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intput(i) cout << i << endl

int main(){
    int N;
    cin >> N;
    string s;
    vector <string> S(N);
    int j = 0;
    cin >> s;
    rep(i,N){
        S[i] = s[i];
    }
    
    rep(i,N-2){
        if(S[i] == "A" && S[i+1] == "B" && S[i+2] == "C"){
            j++;
        }
    }
    cout << j << endl;
}


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

int main(){
    int n;
    cin>>n;
    int index=1;
    int count=0;
    int p[n];
    for(int i=0;i<n;i++) cin>>p[i];
    for(int i=0;i<n;i++){
        if(p[i]==index) index++;
        else count++;
    }
    if(count==n) count=-1;
    cout<<count<<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int(i)=0;i<(n);i++)
#define SIZE 51
int h,w,sx,sy,gx,gy;
typedef pair<int,int> P;
vector<string> s(SIZE);
vector<vector<int>> hi(SIZE,vector<int>(SIZE,-1));

int main(){
    int ttl=0;
    cin>>h>>w;
    REP(i,h) cin>>s.at(i);
    REP(i,h)REP(j,w) if(s.at(i).at(j)=='.') ttl++;

    queue<P> q;
    q.push({0,0});
    hi.at(0).at(0)=1;
    int dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
    while(!q.empty()){
        P now=q.front();q.pop();
        REP(i,4){
            int xx=now.first+dx[i],yy=now.second+dy[i];
            if(xx>=0&&xx<w&&yy>=0&&yy<h){
                if(xx==w-1&&yy==h-1){
                  cout<<ttl-hi.at(now.second).at(now.first)-1<<endl;
                  return 0;
                }
                if(s.at(yy).at(xx)=='.'&&hi.at(yy).at(xx)==-1){
                  hi.at(yy).at(xx)=hi.at(now.second).at(now.first)+1;
                  q.push({xx,yy});
                }
            }
        }
    }
    cout<<"-1";
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<string>

#define MAX 10001
#define YES 1
#define NO  0

using namespace std;

int main(void){
	unsigned int T;
	cin >> T;

	for(unsigned int D = 0; D < T; ++D){
		int main_passage = 0;
		int Book[2*MAX] = {NO,};
		int NoBookForward[MAX] = {NO,};
		string in;
		unsigned int cost = 0;
		unsigned int N;
		unsigned int Off = MAX+1;

		cin >> N;
		cin >> in;

		for(unsigned int i = 1; i <= in.length(); ++i){
			if( in[i-1] == 'Y' ){
				if( i <= 2*N )
					Book[(i/2)+1] = YES;
				else
					Book[Off+((i-2*N)/2)+1] = YES;
			}
		}

		NoBookForward[N+1] = YES;
		for(unsigned int i = N; i > 0; --i){
			if( Book[Off+i+1] == YES || NoBookForward[i+1] == NO )
				NoBookForward[i] = NO;
			else
				NoBookForward[i] = YES;
		}

		for(unsigned int i = 1; i <= N; ++i){
			if( Book[i] == YES && Book[Off+i] == NO ){
				if( NoBookForward[ i ] == YES )
					main_passage = 0;
				else
					main_passage = 1;
				cost += 1;
			}
			if( Book[i] == NO  && Book[Off+i] == YES ){
				if( main_passage == 0 ){
					main_passage = 1;
					cost += 2;
				}else
					cost += 1;
			}

			if( Book[i] == YES && Book[Off+i] == YES ){
				if( main_passage == 0 ){
					if( NoBookForward[i] == YES )
						cost += 3;
					else{
						cost += 2;
						main_passage = 1;
					}
				}else{
					cost += 2;
					if( NoBookForward[i] == YES )
						main_passage = 0;
				}
			}
			cost += 1;
		}

		if( main_passage == 0 ){
			if( Book[N+1] == YES )		cost += 1;
			if( Book[Off+N+1] == YES )	cost += 3;
		}
		if( main_passage == 1 ){
			if( Book[Off+N+1] == YES )	cost += 2;
			else						cost += 1;
		}

		cout << cost << endl;
	}
	return 0;
}

Measured memory_bytes: 0
import java.util.*;
 
public class Main {
	
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int N = sc.nextInt();
    	int[] Hi = new int[N];
    	int tmp = sc.nextInt();
    	int line = 0;
    	boolean flg = true;
    	for (int i = 1; i < N; i++) {
    		int h = sc.nextInt();
    		if (h + 1 < tmp) {
    			flg = false;
    		} else if (h + 1 == tmp) {
    			if (h < line) {
    				flg = false;
    			}
    			line = h;
    		}
    		tmp = h;
    	}
    	System.out.println(flg ? "Yes" : "No");
    }
}

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

int main() {
  int A , N , Q;
  cin >> N >> A;
  
  Q = N % 500;
  
  if (A >= Q){
    cout << "Yes" << endl;
  }
  
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repb(i,a,b) for(int i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

signed main(){
	int n;
	cin>>n;
	int a[101][101]={};
	rep(i,1,n+1) rep(j,1,n+1) cin>>a[i][j];
	//int sum[101][101]={};
	rep(i,1,n+1){
		rep(j,2,n+1){
			a[i][j]+=a[i][j-1];
		}
	}
	rep(i,1,n+1){
		rep(j,2,n+1){
			a[j][i]+=a[j-1][i];
		}
	}
	int MAX=-1000000000;
	rep(y1,0,n+1){
		rep(y2,y1+1,n+1){
			rep(x1,0,n+1){
				rep(x2,x1+1,n+1){
					MAX=max(MAX,a[y2][x2]-a[y2][x1]-a[y1][x2]+a[y1][x1]);
				}
			}
		}
	}
	o(MAX);
}

Measured memory_bytes: 1244