akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
    int H, W;
    cin >> H >> W;

    vector<vector<char>> frame(H + 2);

    vector<char> line(W + 2);
    rep(i, W + 2) {
        line.at(i) = '#';
    }
    frame.at(0) = line;
    frame.at(H + 1) = line;

    rep(i, H) {
        rep(j, W) {
            cin >> line.at(j + 1);
        }
        frame.at(i + 1) = line;
    }

    rep(i, H + 2) {
        rep(j, W + 2) {
            cout << frame.at(i).at(j);
        }
        cout << endl;
    }
}

Measured memory_bytes: 256
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
#include<bits/stdc++.h>
#include<atcoder/all>
using namespace atcoder;

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please



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


	int N, M;
	cin >> N >> M;

	string S[50];
	rep(i, N) cin >> S[i];

	mcf_graph<int, ll> g(N * M + 2);
	rep(i, N) rep(j, M - 1) {
		if (S[i][j] != '#' && S[i][j + 1] != '#') g.add_edge(i * M + j, i * M + j + 1, 200, 0);
	}
	rep(i, N - 1) rep(j, M) {
		if (S[i][j] != '#' && S[i + 1][j] != '#') g.add_edge(i * M + j, i * M + j + M, 200, 0);
	}
	int kazu = 0;
	int are = 0;
	rep(i, N) rep(j, M) if (S[i][j] != '#') g.add_edge(i* M + j, N* M + 1, 1, N + M - i - j);
	rep(i, N) rep(j, M) if (S[i][j] == 'o') {
		g.add_edge(N * M, i * M + j, 1, 0);
		kazu++;
		are += N + M - i - j;
	}

	auto kotae = g.flow(N * M, N * M + 1, kazu);

	co(are - kotae.second);

	Would you please return 0;
}

Measured memory_bytes: 4268
N, A, B, C = map(int, input().split())
l = [int(input()) for i in range(N)]
INF = 10**9


# cur 番目の竹をA,B,Cどの竹の合成に使うか(使わないか)で場合分けして全探索
def dfs( cur, a, b, c ):
    if cur == N:
        if min(a, b, c) > 0:
            return abs(a - A) + abs(b - B) + abs(c - C) - 30  # そもそも1本はあるのでその分引く
        else: return INF  # A,B,Cに一本も竹を使わない場合は除外
    ret0 = dfs( cur + 1, a, b, c )                # cur 番目の竹を合成に使わない
    ret1 = dfs( cur + 1, a + l[cur], b, c ) + 10  # cur 番目の竹をAの合成に使う
    ret2 = dfs( cur + 1, a, b + l[cur], c ) + 10  #          :
    ret3 = dfs( cur + 1, a, b, c + l[cur] ) + 10  #          :
    return min(ret0, ret1, ret2, ret3)

print( dfs(0, 0, 0, 0) )

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;

#include<map>
#include<set>
#include<queue>

typedef long long ll;
typedef unsigned long long ull;

const int MAX_N = 1000000;
const int INFTY = (1 << 21); // 2097152
// const ll INFTY = (1 << 60);

class Edge{
public:
	int from, to, cost;
	Edge(int from = 0, int to = 0, int cost = 0) :
			from(from), to(to), cost(cost){}

	bool operator < (const Edge &e) const{
		return cost < e.cost;
	}
	bool operator >(const Edge &e) const{
		return cost > e.cost;
	}

};

class Node{
public:
	vector<Edge> edges;
	int dist;

	Node(){
		dist = INFTY;
	}
};

class Graph{
public:
	vector<Node> nodes;
	Graph(int n) {
		rep(i, n) { Node n;  nodes.push_back(n); }
	}
	Node& operator[](int i){
		return nodes[i];
	}
};

class Data{

public:
	int dist;
	Edge *edge;
	Data(int dist, Edge *edge) {
		this->dist = dist;
		this->edge = edge;
	}

	bool operator < (const Data &d) const{
		return dist < d.dist;
	}
	bool operator >(const Data &d) const{
		return dist > d.dist;
	}
};

Graph G(0);
int N;

void dijkstra(){

    priority_queue<Data, vector<Data>, greater<Data>> pq;
    Edge e0 = Edge(-1, 0, 0);
    Data d0 = Data(0, &e0);
    pq.push(d0);

    while(!pq.empty()){
        Data d = pq.top(); pq.pop();
        Edge &e = *d.edge;
        Node &n = G[e.to];
        if(n.dist <= d.dist) continue;
        n.dist = d.dist;
        // cerr << n.dist << endl;

        for(auto &ee: n.edges){
            pq.push(Data(n.dist + ee.cost, &ee));
        }
    }

}

int main() {
	cin >> N;
	G = Graph(N);

    rep(i, N){
        int from; cin >> from;
        int NN; cin >> NN;
        rep(i, NN){
            int to, cost;
            cin >> to >> cost;
            G[from].edges.push_back(Edge(from, to, cost));
        }
    }

    dijkstra();
    rep(i, N){
        cout << i << " " << G[i].dist << endl;
    }
}

Measured memory_bytes: 17948
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

int main()
{
	LL N;
	in >> N;
	std::vector<LL>d(N);
	rep(i, N) in >> d[i];

	std::sort(d.begin(), d.end());
	out << d[N / 2] - d[N / 2 - 1] << std::endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    int c[3][3],i,j;
    for (i=0;i<3;i++)
    {
        for (j=0;j<3;j++)
            cin>>c[i][j];
    }
    int a[3],b[3];
    //int a1,a2,a3,b1,b2,b3;
    a[0]=0;
    b[0]=c[0][0];
    b[1]=c[0][1];
    b[2]=c[0][2];
    a[1]=c[1][0]-b[0];
    a[2]=c[2][0]-b[0];
    int f=0;
    for (i=0;i<3;i++)
    {
        for (j=0;j<3;j++)
        {
            if (a[i]+b[j]!=c[i][j])
            {
                f=1;
                break;
            }
        }
        if (f)
            break;
    }
    if (f)
        cout<<"No\n";
    else
        cout<<"Yes\n";
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int a[200010];
long long ans=0;
bool cmp(int x,int y){
	return x>y;
}
int main(){
	int n,need,j;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	sort(a+1,a+1+n,cmp);
	ans=a[1];
	need=n-2;
	if(need%2==0){
		need=need/2;
		for(j=2;j<=need+1;j++){
			ans+=2*a[j];
		}
	}
	else{
		need=need/2;
		for(j=2;j<=need+1;j++){
			ans+=2*a[j];
		}
		ans+=a[j];
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 4384
hash = {}
que = []
n, q = gets.split(' ').map(&:to_i)
n.times do
  line = gets.chomp.split
  hash[line[0]] = line[1].to_i
  que.push(line[0])
end
done_hash = {}
time_stamp = 0
i = 0
while done_hash.length < n do
  res = hash[que[i]] - q
  if(res > 0)
    time_stamp += q
    hash[que[i]] = res
    que.push(que[i])
  else
    time_stamp += hash[que[i]]
    done_hash[que[i]] = time_stamp
  end
  que.delete_at(i)
end
done_hash.each do |key, val|
  puts "#{key} #{val}"
end


Measured memory_bytes: 17272
#include <bits/stdc++.h>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define endl "\n"
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
const ll INF = 2e+9 + 10;
typedef pair<ll, ll> P;

int SOD(int x) {
  int sum = 0;
  while(x) {
    sum+=x%10;
    x/=10;
  }
  return sum;
}

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

  int N; cin >> N;

  int res;
  reps(a, 1, N) {
    if(a==1)res = SOD(a)+SOD(N-a);
    res = min(res, SOD(a)+SOD(N-a));
  }
  cout << res << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define int long long
#define double long double
#define all(a) a.begin(), a.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;

//ABC137
signed main(void){

    int a, b; cin >> a >> b;
    cout << max<int>({ a + b, a - b, a * b}) << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 100005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 +c - '0';
	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}
const int MOD = 1000000007;
int H,W,A,B;
int fac[1000005],invfac[1000005];
int inc(int a,int b) {
    return a + b >= MOD ? a + b - MOD : a + b;
}
int mul(int a,int b) {
    return 1LL * a * b % MOD;
}
int fpow(int x,int c) {
    int res = 1,t = x;
    while(c) {
	if(c & 1) res = mul(res,t);
	t = mul(t,t);
	c >>= 1;
    }
    return res;
}
int C(int n,int m) {
    return mul(fac[n],mul(invfac[m],invfac[n - m]));
}
void update(int &x,int y) {
    x = inc(x,y);
}
int Way(int x1,int y1,int x2,int y2) {
    return C(abs(y2 - y1) + abs(x2 - x1),abs(x2 - x1));
}
void Solve() {
    read(H);read(W);read(A);read(B);
    fac[0] = 1;
    for(int i = 1 ; i <= 1000000 ; ++i) fac[i] = mul(fac[i - 1],i);
    invfac[1000000] = fpow(fac[1000000],MOD - 2);
    for(int i = 999999 ; i >= 0 ; --i) invfac[i] = mul(invfac[i + 1],i + 1);
    int ans = 0;
    while(1) {
	++A;++B;
	if(A > H || B > W) break;
	update(ans,mul(Way(H,1,A,B),Way(A,B,1,W)));
    }
    out(ans);enter;
}

int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
    return 0;
}


Measured memory_bytes: 8064
package main

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

type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func main() {
	sc := NewScanner()
	S := sc.nextRuneSlice()
	mi := int(1e+9)
	for i := 0; i < len(S)-2; i++ {
		num, _ := strconv.Atoi(string(S[i : i+3]))
		mi = min(mi, abs(753-num))
	}
	fmt.Println(mi)
}


Measured memory_bytes: 640
from collections import deque


def main():
    n, q = map(int, input().split())
    processes = deque()
    elapsed_time = 0

    for _ in range(n):
        name, time = input().split()
        processes.append([name, int(time)])

    while True:
        if len(processes) == 0:
            break

        process = processes.popleft()
        if process[1] <= q:
            elapsed_time += process[1]
            print(process[0], elapsed_time)
        else:
            elapsed_time += q
            process[1] -= q
            processes.append(process)


if __name__ == "__main__":
    main()



Measured memory_bytes: 13304
const t={input:require('fs').readFileSync('/dev/stdin','utf8').split(/[\s]/),n:(arg:number=0):any=>{if(arg){const a=[];for(let i=0;i<arg;i++){a.push(t.n())}return a}else{const a=t.input[0];t.input.shift();return Number(a)}},s:(arg:number=0):any=>{if(arg){const a=[];for(let i=0;i<arg;i++){a.push(t.s())}return a}else{const a=t.input[0];t.input.shift();return String(a)}},c:(arg:number=0):any=>{if(arg){const a=[];for(let i=0;i<arg;i++){a.push(t.c())}return a}else{let a=t.input[0].split('');const b=a[0];a.shift();if(a.length>0){t.input[0]=a.join('')}else{t.input.shift()}return String(b)}},o:(...arg)=>{console.log(...arg)},abs:(a)=>{return Math.abs(a)},min:(...a)=>{return Math.min(...a)},max:(...a)=>{return Math.max(...a)},floor:(a)=>{return Math.floor(a)},asc:(ar:number[])=>{return ar.sort((a,b)=>{return a-b})},desc:(ar:number[])=>{return ar.sort((a,b)=>{return b-a})},sw:(a,arr:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<arr.length;i+=2){if(eval(a+op+arr[i]))return arr[i+1];}return arr[arr.length-1]}};
const main=()=>{
  let [a,b]=t.n(2)
  let ans =''
  for(let i=b-a+1;i<=b+a-1;i++){
    ans+=i+' '
  }
  t.o(ans)
}
main()

Measured memory_bytes: 7372
#include <iostream>
using namespace std;
int main(void){
    int n;
    cin >> n;
    
    if(n==1||n==2||n==3||n==5||n==7||n==11||n==13||n==15||n==17||n==19||n==23||n==29||n==31){
        cout << "1" << endl;
    }
    else if(n==4||n==6||n==9||n==10||n==14||n==21||n==22||n==25||n==26){
        cout << "2" << endl;
    }
    else if(n==28||n==30){
        cout << "4" << endl;
    }
    else if(n==8||n==12||n==18||n==20||n==27){
        cout << "5" << endl;
    }
    else if(n==16){
        cout << "14" << endl;
    }
    else if(n==24){
        cout << "15" << endl;
    }
    else if(n==32){
        cout << "51" << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int dp[10001]={0};
	int N,W;
	cin>>N>>W;
	int v,w;
	for(int i=0;i<N;i++){
		cin>>v>>w;
		for(int j=0;j<=W;j++){
			if(j>=w){
				dp[j] = max(dp[j-w]+v,dp[j]);
			}
		}
	}
	cout<<dp[W]<<endl;
	return 0;
}

Measured memory_bytes: 1208
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <math.h>
using namespace std;
#define F first
#define S second
const int N=1e5+10;
double min(double a,double b){return a>b?b:a;}
int main(){
    int n;
    double ans=1e9;
    pair<double,double>a[N];
    scanf("%d",&n);
    for(int i=0;i<n;i++)scanf("%lf%lf",&a[i].F,&a[i].S);
    sort(a,a+n);
    for(int i=0;i<n;i++)for(int j=1;j<300;j++)if(j+i<n)ans=min(ans,sqrt((a[i].F-a[i+j].F)*(a[i].F-a[i+j].F)+(a[i].S-a[i+j].S)*(a[i].S-a[i+j].S)));
    printf("%.20lf\n",ans);
}


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

int main() {
    //
    int num, m;
    cin >> num >> m;

    vector<long long> vec(m);
    vector<long long> vec2(m);
    vector<vector<long long>> data(num);
    for (int i = 0; i < m; i++) {
        cin >> vec.at(i) >> vec2.at(i);
        vec.at(i)--;
    }

    for (int i = 0; i < m; i++) { data.at(vec.at(i)).push_back(vec2.at(i)); }

    for (int i = 0; i < num; i++) {
        sort(data.at(i).begin(), data.at(i).end());
        data.at(i).erase(unique(data.at(i).begin(), data.at(i).end()), data.at(i).end());
    }

    for (int i = 0; i < m; i++) {
        int j = vec.at(i);
        long long id = lower_bound(data.at(j).begin(), data.at(j).end(), vec2.at(i)) - data.at(j).begin();
        cout << setfill('0') << right << setw(6) << vec.at(i)+1;
        cout << setfill('0') << right << setw(6) << id+1 << endl;
    }

    //
}


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

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

    if(s=="SUN"){
        cout << 7 << "\n";
    }else if(s=="MON"){
        cout << 6 << "\n";
    }else if(s=="TUE"){
        cout << 5 << "\n";
    }else if(s=="WED"){
        cout << 4 << "\n";
    }else if(s=="THU"){
        cout << 3 << "\n";
    }else if(s=="FRI"){
        cout << 2 << "\n";
    }else if(s=="SAT"){
        cout << 1 << "\n";
    }

    return 0;
}

Measured memory_bytes: 760
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner stdIn = new Scanner(System.in);
		
		int x = stdIn.nextInt();
		
		System.out.println(x/100 + (x/10)%10 + x%10);

	}

}


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

int main(void) {
	const char *SEP = " ";
	long long int n, d, sq_d, x, y, cnt = 0;
	char input_str[256];
	char *num_str;
	int i;

	fgets(input_str, sizeof(input_str), stdin);
	num_str = strtok(input_str, SEP);
	n = atoi(num_str);
	num_str = strtok(NULL, SEP);
	d = atoi(num_str);

	sq_d = d * d;
	for ( i = 0; i < n; i++ ) {
		fgets(input_str, sizeof(input_str), stdin);
		num_str = strtok(input_str, SEP);
		x = atoi(num_str);
		num_str = strtok(NULL, SEP);
		y = atoi(num_str);

		if ( (x*x) + (y*y) <= sq_d ) {
			cnt++;
		}
	}

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

	return 0;
}


Measured memory_bytes: 1708
#include<bits/stdc++.h>
using namespace std;
const int maxn=200009;

int n;
int a[maxn];

long long ans;

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

Measured memory_bytes: 4604
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <map>
#include <iomanip>

using namespace std;

int main() {
	int i, j, W, H, N, WW, HH, k, m;
	int x[200] = { 0 }, y[200] = { 0 }, a[200] = { 0 };
	int matrix[100][100] = { 0 };
	cin >> WW >> HH >> N;

	for (i = 0; i < 100; i++) {
		for (j = 0; j < 100; j++) {
			matrix[i][j] = 0;
		}
	}

	W = WW;
	H = HH;

	for (i = 0; i < N; i++) {
		cin >> x[i] >> y[i] >> a[i];
	}

	for (i = 0; i < N; i++) {
		if (a[i] == 1) {	//1 のときは長方形の x<xi をみたす領域
			/*
			if (W > WW - x[i]) {
				W = WW - x[i];
			}*/

			for (k = 0; k < 100; k++) {
				for (m = x[i] - 1; m >= 0; m--) {
					matrix[k][m] = 1;
				}
			}

		}
		else if (a[i] == 2) {	// 2 のときは長方形の x>xi をみたす領域
			/*
			if (W > x[i]) {
				W = x[i];
			}*/
			
			for (k = 0; k < 100; k++) {
				for (m = x[i] ; m < W; m++) {
					matrix[k][m] = 1;
				}
			}


		}
		else if (a[i] == 3) { // 3 のときは長方形の y<yi をみたす領域
			/*
			if (H > HH - y[i]) {
				H = HH - y[i];
			}*/
			for (k = y[i]-1; k >=0; k--) {
				for (m = 0; m < W; m++) {
					matrix[k][m] = 1;
				}
			}
		}
		else if (a[i] == 4) {	// 4 のときは長方形の y>yi をみたす領域
			/*
			if (H > y[i]) {
				H = y[i];
			}*/
			for (k = y[i]; k < H; k++) {
				for (m = 0; m < W; m++) {
					matrix[k][m] = 1;
				}
			}


		}
	
	}

	int cnt = 0;
	for (i = 0; i < H; i++) {
		for (j = 0; j < W; j++) {
			//cout << matrix[i][j];
			if (matrix[i][j] == 0) cnt++;
		}
		//cout << endl;
	}

	cout << cnt << endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.next());
        HashSet<Integer> set = new HashSet<Integer>();
        int[] array = new int[N-1];
        Arrays.fill(array, -1);
        for (int i=0;i<N;i++) {
            int P = Integer.parseInt(sc.next());
            if (P!=N) {
                if (set.contains(P+1)) {
                    array[P-1]=0;
                } else {
                    array[P-1]=1;
                }
            }
            set.add(P);
        }

        int max = 0;
        int tmp = 0;
        for (int i=0;i<N-1;i++) {
            if (array[i]==1) {
                tmp++;
            } else {
                tmp=0;
            }
            max = Math.max(max, tmp);
        }
        System.out.println(N-max-1);
    }
}

Measured memory_bytes: 72628
#include <bits/stdc++.h>
using namespace std;
int main () {
	int A,B;
	cin >> A >> B;
	int count = 0;
	for (int i = A; i <= B; ++i)
	{
		string str;
		str = to_string(i);
		if(str[0] == str[4] && str[1] == str[3]){
			count++;
		}
	}
	cout << count << endl;
}

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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//==================================

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif

    ll A, B;
    cin >> A >> B;

    int c1, c2;  // c1が下地の色
    if (A <= B) {
        c1 = 0, c2 = 1;
    }
    else {
        c1 = 1, c2 = 0;
    }

    if (A > B) {
        swap(A, B);
    }

    --A;

    vector<Vi> mas(100, Vi(100, c1));
    int pvi = 0, pvj = 0;
    while (A > 0) {
        if (pvj == 100) {
            pvi += 4;
            pvj = 0;
        }
        mas[pvi][pvj] = c2;
        mas[pvi][pvj + 1] = c2;
        mas[pvi][pvj + 2] = c2;

        mas[pvi + 1][pvj] = c2;
        mas[pvi + 1][pvj + 2] = c2;

        mas[pvi + 2][pvj] = c2;
        mas[pvi + 2][pvj + 1] = c2;
        mas[pvi + 2][pvj + 2] = c2;

        --A;
        --B;
        pvj += 4;
    }

    pvi = 99, pvj = 99;
    while (B > 0) {
        if (pvj < 0) {
            pvi -= 2;
            pvj = 99;
        }

        mas[pvi][pvj] = c2;

        --B;
        pvj -= 2;
    }

    cout << 100 << " " << 100 << "\n";

    for (ll i = 0; i < 100; i++) {
        for (ll j = 0; j < 100; j++) {
            cout << (mas[i][j] == 1 ? '#' : '.');
        }
        cout << "\n";
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
    using namespace std;
    #define ll long long int
    #define f(i,n) for(ll i=0;i<n;i++)
    #define fz for(ll j=i+1;j<n;j++)
    #define f2(i,n) for(ll i=1;i<=n;i++)
    #define endl "\n"
    #define vll vector <ll>
    #define mod 1000000009
    #define pb push_back
    #define inf 1e13+5

    ll gcd(ll a, ll b){if(b==0)return a;return gcd(b, a%b);}
    ll lcm(ll a, ll b){return a*b/gcd(a, b);}
    ll fexp(ll a, ll b){ll ans = 1;while(b){if(b&1) ans = ans*a%mod; b/=2;a=a*a%mod;}return ans;}
    ll inverse(ll a, ll p){return fexp(a, p-2);}

    
    void solve(){
        ll n,k;cin>>n>>k;
        ll a[n+1]={0};f2(i,n)cin>>a[i];
        ll dp[n+1]={0};
        dp[1]=0;dp[2]=abs( a[2]-a[1] );
        for(ll i=3;i<=n;i++){
            dp[i]=inf;
            for(ll j=1;j<=k;j++){
                if(i-j>=1)dp[i]=min(dp[i],dp[i-j] + abs( a[i]-a[i-j]  )  );
            }
        }
        // f2(i,n)cout<<dp[i]<<" ";
        // cout<<endl;
        cout<<dp[n]<<endl;

    }


    int main(){
        ios_base::sync_with_stdio(0) ;
        cin.tie(0) ; cout.tie(0) ;

       

        ll t;
        t=1;
        // cin>>t;
        while(t--){
            solve();
        }

       

        
        return 0;
    }

Measured memory_bytes: 1792
#include <stdio.h>
#include <iostream>
#include <string.h>
using namespace std;

int main(void){
  int X,Y;
  cin >> X >> Y;
  int kame = (Y-2*X)/2;
  int kame_amari = (Y-2*X)%2;
  int turu = (4*X-Y)/2;
  int turu_amari = (4*X-Y)%2;

  int answer = -1;
  if(kame_amari!=0 || turu_amari!=0 || kame<0 || turu <0) answer = 1;
  if(answer==1) printf("No\n");
  else printf("Yes\n");
  return 0;
}

Measured memory_bytes: 3640
#pragma GCC optimize ("O3")
#include <iostream>
#include <algorithm>
 
inline void fastin(int &num) {
    bool neg = false;
    int c;
    num = 0;
    c = getchar_unlocked();
    if (c == '-') {
        neg = true;
        c = getchar_unlocked();
    }
    for (; (c > 47 && c < 58); c = getchar_unlocked()) num = num * 10 + c - 48;
    if (neg) num *= -1;
}
 
inline void fastout(int n) {
    int N = n, rev, count = 0;
    rev = N;
    if (N == 0) { putchar_unlocked('0'); putchar_unlocked('\n'); return ;}
    while ((rev % 10) == 0) { ++count; rev /= 10;}
    rev = 0;
    while (N != 0) { rev = (rev<<3) + (rev<<1) + N % 10; N /= 10;}
    while (rev != 0) { putchar_unlocked(rev % 10 + '0'); rev /= 10;}
    while (count--) putchar_unlocked('0');
}
 
int main(){
    int n, c, k; fastin(n); fastin(c); fastin(k);
    int t[n];
    for (int i = 0; i < n; ++i) fastin(t[i]);
 
    std::sort(t, t + n);
 
    int ans = 0;
    int beg = 0;
    while (beg < n){
        int end = beg;
        while (end - beg + 1 < c && t[end + 1] - t[beg] <= k){
            ++end;
            if (end == n - 1) break;
        }
        ++ans; beg = end + 1;
        if (beg == n - 1){
            ++ans; break;
        }
    }
    fastout(ans);
    
    return 0;
}

Measured memory_bytes: 640
import math
import string
import collections
from collections import Counter


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
a, p = map(int, input().split())
print((a*3+p)//2)


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

int main(){
    int prime[1000000];
    for(int i=2;i<1000000;++i){
        prime[i] = 1;
    }
    for(int i=2;i<1000000;++i){
        if(prime[i]){
            for(int j=2;j*i<1000000;++j){
                prime[i*j]=0;
            }
        }
    }
    while(true){
        int a, d, n;
        int cnt=0;
        int ans;
        cin >> a >> d >> n;
        if(!(a||d||n)) break;
        for(int i=0;a+i*d<1000000;++i){
            if(prime[a+i*d]){
                ++cnt;
                if(cnt == n){
                    ans = a+i*d;
                    break;
                }
            }
        }
        cout << ans << endl;
    }
}

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

using namespace std;

int main() {
    string o, e;
    cin >> o >> e;
    for (int i = 0; i < e.size(); ++i) cout << o.at(i) << e.at(i);
    if (o.size() - e.size()) cout << o.back();
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
//============================================================================
// Name        : JOI.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <math.h>
using namespace std;
typedef long long ll;
int N;
int main() {
    cin>>N;
    ll total=1;

    for(int i=1;i<N+1;i++){
    	total*=i;
    	total=total%1000000007;
    }
    cout<<total<<endl;

    return 0;
}


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

template <typename T>
std::size_t partition(std::vector<T> &A, std::size_t l, std::size_t r) {
    T key = A[r - 1];
    std::size_t mid = l;
    for(std::size_t j = l; j + 1 < r; ++j) {
        if(A[j] <= key) {
            std::swap(A[mid], A[j]);
            ++mid;
        }
    }
    std::swap(A[mid], A[r - 1]);
    return mid;
}

using namespace std;
int main() {
    int n; cin >> n;
    vector<int> A(n);
    for(int i=0; i<n; ++i) cin >> A[i];

    int pivot = partition<int>(A, 0, n);
    for(int i=0; i<n; ++i) {
        if(i == pivot) cout << '[' << A[i] << ']' << (i + 1 == n ? '\n' : ' ');
        else cout << A[i] << (i + 1 == n ? '\n' : ' ');
    }    
}


Measured memory_bytes: 3080
//PRZEMYSL ASSERTY

//SPRAWDZ CORNER CASE'Y, MINIMALNE I MAKSYMALNE WEJŚCIE I WYJŚCIE

//MODULO = 1

//while (clock()<=69*CLOCKS_PER_SEC)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  for (auto it = d.b; it != d.e; ++it) 
    *this << ", \0[" + 3 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};

#define imie(x) "[" << #x ": " << (x) << "] "

#define shandom_ruffle random_shuffle

int n;

int wyn;

vector <int> wek;

int wym=0;

int main()
{
	scanf("%d", &n);
	for (int i=1; i<=n; i++)
	{
		int x;
		scanf("%d", &x);
		int r=wek.size();
		if (r && ( (wym>=0 && x>=wek[r-1] ) || (wym<=0 && x<=wek[r-1] ) ))
		{
			wek.push_back(x);
			r++;
			if (wek[r-1]>wek[r-2])
				wym=1;
			if (wek[r-1]<wek[r-2])
				wym=-1;
		}
		else
		{
			wyn++;
			wek.clear();
			wek.push_back(x);
			wym=0;
		}
	}
	printf("%d\n", wyn);
	return 0;
}


Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
int a[100005];
void solve()
{
	int n;cin>>n;
	int mn=n,mx=0; 
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		mn=min(mn,a[i]);
		mx=max(mx,a[i]);
	}
	if(mx-mn>=2)
	{
		puts("No");
		return ;
	}
	if(mn==mx&&mx==n-1)
	{
		puts("Yes");
		return ;
	}
	int cnt1=0,cnt2=0; 
	for(int i=1;i<=n;i++)
		if(a[i]==mx-1) cnt1++;
		else cnt2++;
	int p=mx-cnt1;
	if(p*2>cnt2||p<=0)
	{
		puts("No");
		return ;
	}
	puts("Yes");
}
int main()
{
//	freopen("hat.in","r",stdin);
//	freopen("hat.out","w",stdout); 
	solve();
	return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		if (A==B) {
			System.out.println(A+B);
		} else if (A>B) {
			System.out.println(A*2-1);
		} else {
			System.out.println(B*2-1);
		}
	}
}

Measured memory_bytes: 21332
#include<iostream>

using namespace std;

static const int MAX = 100;
static const int INFTY = (1 << 21);
static const int WHITE = 0, GRAY = 1, BLACK = 2;

int n, M[MAX][MAX];

int prim(){
  int u, minv;
  int d[MAX], p[MAX], color[MAX];

  for(int i = 0; i < n; i++){
    d[i] = INFTY;
    p[i] = -1;
    color[i] = WHITE;
  }

  d[0] = 0;

  while(1){
    minv = INFTY;
    u = -1;

    for(int i = 0; i < n; i++){
      if(minv > d[i] && color[i] != BLACK){
	u = i;
	minv = d[i];
      }
    }
    if(u == -1) break;
    color[u] = BLACK;

    for(int v = 0; v < n; v++){
      if(color[v] != BLACK && M[u][v] != INFTY){
	if(d[v] > M[u][v]){
	  d[v] = M[u][v];
	  p[v] = u;
	  color[v] = GRAY;
	}
      }
    }
  }
  int sum = 0;
  for(int i = 0; i < n; i++){
    if(p[i] != -1) sum += M[i][p[i]];
  }

  return sum;
}

int main(){
  cin >> n;

  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
      int e;
      cin >> e;

      M[i][j] = (e == -1) ? INFTY : e;
    }
  }

  cout << prim() << endl;

  return 0;
}
      
	  



Measured memory_bytes: 3132
#include<stdio.h>
int main() {
	int x , y , c;
	scanf("%d%d",&x,&y) ;
	c=4*x-y ;
	if(c>=0) {
		if(c%2==0 && c/2<=x )  
		    printf("Yes") ;
		else
		    printf("No") ;
	}
	else
	    printf("No") ;
}

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

using namespace std;

int32_t main() {

    ios_base::sync_with_stdio(false);

    cin.tie(0);

    long long a;

    cin >> a;

    long long b;

    cin >> b;

    b*=2;

    a-=b;

    a= max(0LL,a);

    cout << a << '\n';

    return 0;

}



Measured memory_bytes: 3652
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	fmt.Println(resolve())
}

func resolve() int {
	n, d := scanInt(sc), scanInt(sc)
	xs, ys := make([]int, n), make([]int, n)
	for i := range loop0(n) {
		xs[i] = scanInt(sc)
		ys[i] = scanInt(sc)
	}
	num := 0
	for i := range loop0(n) {
		if isNear(xs[i], ys[i], d) {
			num++
		}
	}
	return num
}

func isNear(x, y, d int) bool {
	return x*x+y*y <= d*d
}

func loop0(n int) chan int {
	return loop(0, n-1, 1)
}

func loop1(n int) chan int {
	return loop(1, n, 1)
}

func loop(s, e, d int) chan int {
	ch := make(chan int)
	go func() {
		for i := s; i <= e; i += d {
			ch <- i
		}
		close(ch)
	}()
	return ch
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 7612
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef long long ll;

void dump(vector<int> d)
{
    rep(i, d.size())
    {
        printf("%d ", d[i]);
    }
    cout << endl;
}

int main()
{
    int N, N2, X;

    cin >> N;
    // cout << N << endl;

    X = N / 1.08;
    // cout << X << endl;

    N2 = X * 1.08;
    // cout << N2 << endl;

    if (N == N2)
    {
        cout << X << endl;
    }
    else if (N2 < N)
    {
        N2 = (X + 1) * 1.08;
        if (N == N2)
        {
            cout << X + 1 << endl;
        }
        else
        {
            cout << ":(" << endl;
        }
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define Repr(i, n, a) for (int i = (n); i >= (a); i--)
#define rep(i, n) Rep(i, 0, n)
#define repr(i, n) Repr(i, n, 0)
#define all(a) a.begin(), a.end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

int n;
vector<int> e[10010];
vector<int> c;
int num[10010];

void solve()
{
    queue<int> que;
    int p = 0;
    que.push(0);
    while (!que.empty())
    {
        int x = que.front();
        que.pop();
        num[x] = c[p++];
        rep(i, e[x].size()) if (num[e[x][i]] == 0) que.push(e[x][i]);
    }
}

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

    cin >> n;
    rep(i, n - 1)
    {
        int a, b;
        cin >> a >> b;
        a--, b--;
        e[a].push_back(b);
        e[b].push_back(a);
    }
    c.resize(n);
    rep(i, n) cin >> c[i];
    sort(c.rbegin(), c.rend());
    solve();
    int ans = -c[0];
    rep(i, n) ans += c[i];
    cout << ans << endl;
    rep(i, n) cout << num[i] << " ";
    cout << endl;
}

Measured memory_bytes: 1152
import queue
def bfs(G, s):
    st = set()
    q = queue.Queue()
    st.add(s)
    q.put(s)
    while not q.empty():
        p = q.get()
        for v, _ in G[p]:
            if not v in st:
                st.add(v)
                q.put(v)
    return st

def solve(G, st):
    n = len(G)
    score = [-float("inf")]*n
    score[0] = 0
    for i in range(n):
        f = True
        for s in range(n):
            for t, u in G[s]:
                if not s in st or not t in st:
                    continue
                if score[t] < score[s] + u:
                    f = False
                    score[t] = score[s] + u
        if f:
            break
        if i == n-1:
            return "inf"
    return score[n-1]

def main():
    n, m = map(int, input().split())
    G = [[] for _ in range(n)]
    revG = [[] for _ in range(n)]
    for _ in range(m):
        a, b, c = map(int, input().split())
        a, b = a-1, b-1
        G[a].append([b, c])
        revG[b].append([a, c])
    st1 = bfs(G, 0)
    st2 = bfs(revG, n-1)
    st = st1 & st2
    print(solve(G, st))

if __name__ == "__main__":
    main()

Measured memory_bytes: 4720
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    //*
    int a;
    cin >> a ;
    //*/
    
    /*
    vector<int> vec(3);
    cin >> vec.at(0) >> vec.at(1) >> vec.at(2) ;
    
    sort(vec.begin(), vec.end());
    //*/
    
    //*
    if( a == 1 ){
        cout << "Hello World" << endl;
    } else {
        int b, c;
        cin >> b >> c ;
        cout << b + c << endl;
    }
    //*/
    
    //cout << a << endl;

    return 0; 
}


Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (a * b) % mod
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define fi first
#define se second
typedef pair<int,int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;

int a[10000];
int solve(vector<int> vec){
	int n = vec.size();
	int d = vec[1]-vec[0];
	//printf("*%lld*", vec[0]);
	rep(i,n-1){
		if(vec[i+1]-vec[i] != d)return 0;
	}
	return 1;
}

signed main(){
	while(1){
		int n, ans = -1;
		scanf("%lld", &n);
		if(n == 0)break;
		rep(i,n+1)scanf("%lld", &a[i]);
		rep(i,n+1){
			vector<int> vec;
			rep(j,n+1)if(i != j)vec.pb(a[j]);
			int res = solve(vec);
			if(res)ans = a[i];
		}
		printf("%lld\n", ans);
	}
	return 0;
}





Measured memory_bytes: 3284
def gridbfs(grid,sy,sx):
    INF = 10**18

    gridy = len(grid)
    gridx = len(grid[0])

    dist = [[INF]*gridx for _ in range(gridy)]
    dist[sy][sx] = 0
    q = [(sy,sx)]
    d = 1

    while q:
        qq = []
        for y,x in q:
            for dy,dx in [(-1,0),(1,0),(0,-1),(0,1)]:
                yy,xx = y+dy, x+dx
                if not (0 <= yy < gridy and 0 <= xx < gridx):
                    continue
                if grid[yy][xx] == '#':
                    continue
                if dist[yy][xx] != INF:
                    continue
                dist[yy][xx] = d
                qq.append((yy,xx))
        q = qq
        d += 1

    return dist

H,W = map(int,input().split())
grid = [input() for i in range(H)]
d = gridbfs(grid,0,0)
b = 0
for h in range(H):
    for w in range(W):
        if grid[h][w] == '#':
            b += 1

print(max(H*W-b-d[H-1][W-1]-1,-1))

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

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

int main()
{
    long A, B;
    cin >> A >> B;
    cout << (abs(A - B) % 2 == 0 ? to_string(abs(A - B) / 2 + min(A, B)) : "IMPOSSIBLE") << endl;
}

Measured memory_bytes: 256
# include <bits/stdc++.h>
# define rep(i, n) for (ll i = 0; i < (n); i++)
# define reps(i, n) for (ll i = 1; i <= (n); i++)
# define foreps(i, m, n) for (ll i = (m); i < (n); i++)
# define len(x) ((int)(x).size())
# define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
const long long mod = 1e9 + 7;
const long long inf = 1e18;

int main() {
    ll N; cin >> N;
    vector<ll> A(N);
    map<ll, ll> mp;
    rep(i, N) cin >> A[i];

    ll res = 0;
    rep(i, N) {
        if (i + 1 == A[i]) {
            if (i == N - 1) {
                swap(A[i - 1], A[i]);
                res++; continue;
            } else {
                swap(A[i], A[i + 1]);
                res++; continue;
            }
        }
    }
    cout << res << endl;
}

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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);  
	int n, m;
	cin >> n >> m;
	vector<vector<long long>> a(3, vector<long long>(n));
	for(int i = 0; i < n; i++) {
		for(int j = 0; j < 3; j++) {
			cin >> a[j][i];
		}
	}
	long long ans = LLONG_MIN;
	for(int i = 0; i < (1 << 3); i++) {
		vector<long long> v(n);
		for(int j = 0; j < n; j++) {
			for(int k = 0; k < 3; k++) {
				if(1 & (i >> k)) {
					v[j] += a[k][j];
				}
				else {
					v[j] -= a[k][j];
				}
			}
		}
		sort(v.rbegin(), v.rend());
		long long tmp = 0;
		for(int j = 0; j < m; j++) {
			tmp += v[j];
		}
		ans = max(tmp, ans);
	}
	cout << ans << endl;
	return 0;	
}


Measured memory_bytes: 256
s = input()
s = s[::-1] + '0'

ans = 0
up = 0
for i in range(len(s)):
    int_s = int(s[i])
    if int_s+up <= 4:
        ans += int_s + up
        up = 0
    elif int_s+up == 5:
        if int(s[i+1]) < 5:
            ans += int_s + up
            up = 0
        else:
            ans += 10 - (int_s + up)
            up = 1
    else:
        ans += 10 - (int_s + up)
        up = 1
print(ans)


Measured memory_bytes: 5492
#include <bits/stdc++.h>
#define int long long
#define double long double
#define INF 1e18
using namespace std;
// x[H][W]
// 1: accessible
// INF: not arrived
// -1: can't access
int a[20][20];
int H, W;

void dfs(int x, int y) {
  int moveX[4] = { 1, 0, -1, 0 };
  int moveY[4] = { 0, 1, 0, -1 };
  a[y][x] = 1;
  for (int i = 0; i < 4; i++) {
    int nx = moveX[i]+x;
    int ny = moveY[i]+y;
    if (a[ny][nx] == INF && nx >= 0 && nx < W && ny >= 0 && ny < H) {
      dfs(nx, ny);
    }
  }
}

signed main() {
  while (cin>>W>>H, W+H!=0) {
    int startX, startY;
    for (int i = 0LL; i < H; i++) {
      for (int j = 0LL; j < W; j++) {
        char c; cin >> c;
        if (c == '.') {
          a[i][j] = INF;
        } else if (c == '#') {
          a[i][j] = -1;
        } else {
          a[i][j] = INF;
          startX = j;
          startY = i;
        }
      }
    }
    dfs(startX, startY);
    
    int ans = 0;
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        if (a[i][j] == 1) ans++;
      }
    }

    cout << ans << endl;
  }
}



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

int main() {
    int D; cin >> D;
    int c[27];
    for (int i = 1; i <= 26; i++) cin >> c[i];
    int s[D+1][27];
    for (int i = 1; i <= D; i++) {
        for (int j = 1; j <= 26; j++) cin >> s[i][j];
    }
    int ans[D+1];

    for (int i = 1; i <= D; i++) {
        int res = 0, t;
        for (int j = 1; j <= 26; j++) {
            if (res < s[i][j]) {
                res = s[i][j];
                t = j;
            }
        }    
        ans[i] = t;    
    }
    for (int i = 1; i <= D; i++) {
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 3688
#include <bits/stdc++.h>
#include <complex>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,C,L,R;
string S,T;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;

int main() {
    cin>>N;
    vec a(N), b(N), c(N);
    rep(i,N) cin>>a[i];
    rep(i,N) cin>>b[i];
    rep(i,N) cin>>c[i];
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());
    vec btoa(N);
    rep(i,N){
        btoa[i] = lower_bound(a.begin(), a.end(), b[i]) - a.begin();
        if(i > 0) btoa[i] += btoa[i-1];
    }
    ll ans = 0;
    rep(i,N){
        ll ctob = lower_bound(b.begin(), b.end(), c[i]) - b.begin();
        if(ctob != 0) ans += btoa[ctob - 1];
    }
    cout<<ans<<endl;
}

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

int main() {
  int Q;
  cin >> Q;
  vector<int> l(Q), r(Q);
  rep(i, Q) cin >> l[i] >> r[i];
  
  vector<bool> prime(100100, true);
  vector<int> like(100100, 0), sum(100100, 0);
  
  prime[0] = false;
  prime[1] = false;
  for(int i = 2; i < 317; ++i) {
    int j = 2;
    while(i * j <= 100100) {
      prime[i * j] = false;
      ++j;
    }
  }
  rep(i, 100100) {
    if(prime[i] && prime[(i + 1) / 2]) like[i] = 1;
  }
  for (int i = 1; i < 100100; ++i) {
    sum[i] = sum[i - 1] + like[i - 1];
  }
  
  rep(i, Q) {
    cout << sum[r[i] + 1] - sum[l[i]] << endl;
  }
  return 0;
}

Measured memory_bytes: 2176
import java.util.Scanner;

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

		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();

		double h = b * Math.sin(Math.toRadians(c));
		double s = a * h / 2;
		double l = a + b + Math.sqrt( a * a + b * b - 2 * a * b * Math.cos(Math.toRadians(c)) );
		System.out.printf("%.5f\n", s);
		System.out.printf("%.5f\n", l);
		System.out.printf("%.5f\n", h);

	}
}


Measured memory_bytes: 26600
#include <bits/stdc++.h>
using namespace std;
int main()
{
   string s,s1;
   cin>>s>>s1;
   int L1=s.length();
   int L2=s1.length();

   if(L1==L2)
   {
    if(s==s1)cout<<"EQUAL"<<endl;
    else if(s[0]>s1[0])cout<<"GREATER"<<endl;
    else cout<<"LESS"<<endl;
   }
   else if(L1>L2)cout<<"GREATER"<<endl;
   else cout<<"LESS"<<endl;

    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<vector>
#include<queue>
#include<cmath>
#define ll long long
using namespace std;
int a[200],b[200];
int main()
{
   //freopen("data.in","r",stdin);
   //freopen("data.out,"w",stdout);
    int A,B,C,D;
    cin>>A>>B>>C>>D;
    for(int i=A+1;i<=B;i++)
    a[i]++;
    for(int i=C+1;i<=D;i++)
    b[i]++;
    int sum=0;
    for(int i=0;i<=100;i++)
    if(a[i]&&b[i])
    sum++;
    cout<<sum<<endl;
   return 0;
}


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

int main(){
  string s;
  cin >> s;
  
  int ans = 99999;
  
  for (int i = 0; i < s.size() -2; i++) {
    int check = (s.at(i) - '0') * 100 + (s.at(i+1) - '0') * 10 + (s.at(i+2) - '0') * 1;
    int diff = abs(753 - check);
    ans = min(ans, diff);
  }
  
  cout << ans << endl;
  
}

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

int main(){
	int n,x;
	cin >> n >> x;
	vector<int> d(n+1);
	for(int i = 0; i < n; ++i){
      	int x;
      	cin >> x;
		d[i+1] = d[i]+x;
	}
	int ans = 0;
	
	for(int i = 0; i <= n;++i){
		if(d[i] <= x) ++ans;
	}
	
	cout << ans << endl;
	
	return 0;
}
		

Measured memory_bytes: 256
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    String first = s.substring(0,1),last = s.substring(s.length()-1,s.length());
    int a = s.length() - 2;
    System.out.println(first + a + last);
  }
}


Measured memory_bytes: 22996
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  int n, m;
  cin >> n >> m;
  cout << m*(m-1)/2 + n*(n-1)/2 << endl;
  return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast",3,"inline")
#include<bits/stdc++.h>
using namespace std;
typedef priority_queue<int> p_queue;
typedef long long ll;
int read(){
	char c=getchar();
	int sum=0;
	while(c>'9'||c<'0')c=getchar();
	while(c<='9'&&c>='0')sum=sum*10+c-'a',c=getchar();
	return sum;
}
ll n,m;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	cin>>n>>m;
	n*=500;
	if(n>=m)cout<<"Yes";
	else cout<<"No";
	return 0;
}


Measured memory_bytes: 256