akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <iomanip> 

typedef long long ll;
typedef unsigned long long ull;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;(i) < ((int)(n));++(i))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define log(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

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

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

ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline void print(T&& x){cout<<x<<endl;}// 改行付き出力
template<typename T>inline T SUM(vector<T> vec){return accumulate(all(vec),(T)0);} // vectorの中身を全部足す
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
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; }
int ctoi(char c){return c-'0';}



// TODO: write
int main() {
  ll a;cin>>a;
  string s;cin>>s;
  ll b = ctoi(s[0]) * 100 + ctoi(s[2]) * 10 + ctoi(s[3]);
  print(a*b/100);

  return 0;
}


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

class Program
{
    static void Main(string[] args)
    {
        string[] input = Console.ReadLine().Split(' ');
        int a = int.Parse(input[0]);
        int b = int.Parse(input[1]);
        int min = 0;
        int max = 100001;
        for (int i = 0; i < b; i++)
        {
            string[] input2 = Console.ReadLine().Split(' ');
            int aa = int.Parse(input2[0]);
            int bb = int.Parse(input2[1]);
            if (aa > min) min = aa;
            if (bb < max) max = bb;
        }
        int num = max - min + 1;
        if (num < 0) num = 0;
        Console.WriteLine(num);
    }
}

Measured memory_bytes: 17216
#include <stdio.h>
#include <string.h>

int main(void)
{
    char buffer[1310720], *p;
    size_t i = 0;
    int ac_count = 0;
    int wa_count = 0;
    int tle_count = 0;
    int re_count = 0;

    // input
    if (scanf("%1310710[\x01-\xff]", buffer) != 1) {
        return 1;
    }

    // output
    for (i = 0, p = strtok(buffer, "\n"); p; ++i, p = strtok(NULL, "\n")) {
        // if(i == 0){ printf("%s\n", p); }
        // printf("%s\n", p);
        if(strcmp(p, "AC") == 0){ ac_count++; }
        if(strcmp(p, "WA") == 0){ wa_count++; }
        if(strcmp(p, "TLE") == 0){ tle_count++; }
        if(strcmp(p, "RE") == 0){ re_count++; }
    }

    printf("AC x %d\n", ac_count);
    printf("WA x %d\n", wa_count);
    printf("TLE x %d\n", tle_count);
    printf("RE x %d\n", re_count);

    return 0;
}


Measured memory_bytes: 2112
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
int const INF=1001001001;
ll const LINF=1001001001001001001;
ll const MOD=1000000007;

int I[]={1,0,-1,0};
int J[]={0,1,0,-1};
int H,W;
string S[400];
int chk[400][400];

int main(){
    cin>>H>>W;
    rep(i,H) cin>>S[i];

    ll ans=0;
    rep(i,H){
        rep(j,W){
            if(S[i][j]=='.') continue;
            ll b=0, w=0;
            queue<P> q;
            q.push(P(i,j));
            while(!q.empty()){
                P p=q.front(); q.pop();
                if(chk[p.first][p.second]==1) continue;
                //cout<<p.first<<' '<<p.second<<endl;
                chk[p.first][p.second]=1;
                if(S[p.first][p.second]=='#') b++;
                else w++;
                rep(k,4){
                    int x=p.first+I[k];
                    int y=p.second+J[k];
                    if(0<=x && x<H && 0<=y && y<W && chk[x][y]==0
                    && S[p.first][p.second]!=S[x][y]){
                        q.push(P(x,y));
                    }
                }
            }
            //cout<<"b="<<b<<" w="<<w<<endl;
            ans+=b*w;
        }
    }

    cout<<ans<<endl;
}

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

typedef long long int ll;
typedef unsigned long long int ull;
#define rep(i,n) for(auto i=0;i<(n);i++)

using namespace std;




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

    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

    double ave = 0.0;
    rep(i, n) ave += a[i];
    ave /= n;
    double d = 1000.0;
    int idx = 0;
    rep(i, n){
        if(abs(ave-1.0*a[i]) < d){
            idx = i;
            d = abs(ave-a[i]);
        }
    }

    cout << idx << endl;
    
    

    return 0;
}



Measured memory_bytes: 256
package main

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

const (
	initialBufSize = 1e4
	maxBufSize     = 1e6 + 7
)

var buf []byte = make([]byte, maxBufSize)
var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBufSize)
}

func main() {
	N, A, B := nextInt(), nextInt(), nextInt()
	if A > B || (N == 1 && B-A > 1) {
		fmt.Println(0)
	} else {
		N -= 2
		var ans int
		ans = (B-A)*N + 1
		fmt.Println(ans)
	}
}

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

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

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

func pow(p, q int) int {
	res := p
	if q == 0 {
		return 1
	}
	for i := 0; i < q-1; i++ {
		res *= p
	}
	return res
}

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

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

func gcdof2numbers(a int, b int) int {
	if b == 0 {
		return a
	}
	return gcdof2numbers(b, a%b)
}

func lcmof2numbers(a int, b int) int {
	return a / gcdof2numbers(a, b) * b
}

// マイナスの場合は考慮していない
func fuctorial(a int) int {
	if a == 1 || a == 0 {
		return 1
	} else {
		return fuctorial(a-1) * a
	}
}

func NextPermutation(x sort.Interface) bool {
	n := x.Len() - 1
	if n < 1 {
		return false
	}
	j := n - 1
	for ; !x.Less(j, j+1); j-- {
		if j == 0 {
			return false
		}
	}
	l := n
	for !x.Less(j, l) {
		l--
	}
	x.Swap(j, l)
	for k, l := j+1, n; k < l; {
		x.Swap(k, l)
		k++
		l--
	}
	return true
}

// 素因数分解したmapを返す
func primeFuctorize(n int) map[int]int {
	pf := map[int]int{}
	for i := 2; i*i <= n; i++ {
		for n%i == 0 {
			pf[i]++
			n /= i
		}
	}
	if n != 1 {
		pf[n]++
	}
	return pf
}


Measured memory_bytes: 640
n, a = map(int, raw_input().split())
f = [0 for i in range(6000)]
f[0] = 1
for x in map(int, raw_input().split()):
	x -= a
	g = f[::]
	for i in range(-3000, 3000):
		g[i + x] += f[i]
	f = g
print g[0] - 1

Measured memory_bytes: 2948
'use strict'

const main = input => {
	const args = input.split('\n')[0].split(' ')
	const a = parseInt(args[0], 10)
	const b = parseInt(args[1], 10)
	console.log((a + b) % 24)
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))


Measured memory_bytes: 21064
import java.util.*;
public class Main {
    public static void main(String [] args) {
        Scanner sc = new Scanner(System.in);
        long A = sc.nextLong();
        long B = sc.nextLong();
        long gcd = GCD(A,B);
        int num = DIV(gcd);
        System.out.println(num+1);
    }
    public static long GCD(long num1,long num2){
        if(num1%num2==0) return num2;
        return GCD(num2,num1%num2);
    }
    public static int DIV(long A){
        Set<Long> set = new HashSet<>();
        for(long i=2;i*i<=A;){
            if(A%i==0) {
                set.add(i);
                A/=i;
            }
            else i++;
        }
        if(A>(long)1) set.add(A);
        return set.size();
    }
}


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

int     main() {
	int H, W, D;
	cin >>H >>W >>D;
	vector<vector<int>> A(H*W+1, vector<int> (2, 0));
	for (int i=1; i<=H; i++)
		for (int j=1; j<=W; j++) {
			int AA;
			cin >>AA;
			A.at(AA).at(0)=i;
			A.at(AA).at(1)=j;
		}
	vector<int> LL(H*W+1, 0);
	for (int i=1; i<=H*W-D; i++) {
		LL.at(i+D)=abs(A.at(i+D).at(0)-A.at(i).at(0))+abs(A.at(i+D).at(1)-A.at(i).at(1));
		LL.at(i+D) +=LL.at(i);
	}
	int Q, L, R;
	cin >>Q;
	for (int i=0; i<Q; i++) {
		cin >>L >>R;
		cout <<LL.at(R)-LL.at(L) <<endl;
	}
	return 0;
};


Measured memory_bytes: 6400
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define ll long long
#define INF 999999999
using namespace std;
int main() {
  int n;
  std::cin >> n;
  std::vector<pair<ll,ll>> v;
  for (int i = 0; i < n; i++) {
    ll a,b;
   std::cin >> a >> b;
   v.push_back(make_pair(b,a));
  }
  ll t =0;
  bool ans = true;
  sort(v.begin(), v.end());
  for (int i = 0; i < n; i++) {
    t += v[i].second;
    if (t > v[i].first) {
      ans = false;
    }
  }
  if (ans) {
    std::cout << "Yes" << endl;
  }
  else{
    std::cout << "No" << endl;
  }
}


Measured memory_bytes: 6384
#include <bits/stdc++.h>
#define INT long long
#define oo 99999999987654231ll
using namespace std;
INT a[3], ans;
int main()
{
    ios::sync_with_stdio(false);
    cin>>a[0]>>a[1]>>a[2];
    while( a[0] != a[1] or a[1] != a[2] )
    {
        sort(a, a+3);
        if( a[0] == a[1] ) a[0]++, a[1]++;
        else a[0]+=2;
        ans++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
N, K, Q = gets.chomp.split.map(&:to_i)

pys = []
Q.times do
  pys << gets.split.map(&:to_i)
end

i = 1

has = pys.each_with_object(Hash.new(0)){|v,o| o[v]+=1}


while i < N + 1
	if has[[i]]+K-Q > 0
	  puts "Yes"
    else
      puts "No"
    end
    i += 1
end

Measured memory_bytes: 13820
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, K;
  cin >> N >> K;
  string S;
  cin >> S;
  if ( S.at(K-1) == 'A' ) S.at(K-1) = 'a';
  else if ( S.at(K-1) == 'B' ) S.at(K-1) = 'b';
  else if ( S.at(K-1) == 'C' ) S.at(K-1) = 'c';
  cout << S << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int replace(  int number)
{

    if (number == 0)
        return 0;


    int digit = number % 10;
    if (digit == 1)
        digit = 9;
    else if (digit == 9)
        digit = 1;



    return replace(number/10) * 10 + digit;
}
int Convert(  int number)
{
    if (number == 0)
        return 1;
    else
        return replace(number);
}
int main()
{
    int number;
    scanf("%d", &number);
    printf("%d\n", Convert(number));
    return 0;
}


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

class Main {
    public static void main(String[] args) {
        new Solver().run();
    }
}

class Solver {

    public void run() {
        Scanner sc = new Scanner(System.in);
        String A = sc.next();
        String B = sc.next();

        int NA = A.length();
        int NB = B.length();

        if (NA > NB) {
            System.out.println("GREATER");
        } else if (NA < NB) {
            System.out.println("LESS");
        } else {
            int ret = A.compareTo(B);
            if (ret > 0) {
                System.out.println("GREATER");
            } else if (ret < 0) {
                System.out.println("LESS");
            } else {
                System.out.println("EQUAL");
            }

        }


        return;
    }

}

Measured memory_bytes: 21844
/*
 * WelcomeToAtCoder.cpp
 *
 *  Created on: 2020/02/19
 *      Author: black
 */

#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <list>
#include <cstring>
#include <stdio.h>
using namespace std;

#define MAX 100000


void iswap(int A[], int a, int b){
	int tmp = A[a];
	A[a] = A[b];
	A[b] = tmp;
}

int partition(int A[], int p, int r){
	int x = A[r];
	int i = p - 1;
	for(int j=p; j<r; ++j){
		if(A[j] <= x){
			i++;
			iswap(A, i, j);
		}
	}
	iswap(A, i+1, r);
	return i+1;
}

int main(){
	int A[MAX];
	int n;

	scanf("%d", &n);
	for(int i= 0; i< n; ++i){
		scanf("%d", &A[i]);
	}

	int count = partition(A, 0, n-1);

	for(int i= 0; i< n; ++i){
		if(0 != i){
			cout << " ";
		}
		if (count == i){
			cout << "[";
		}
		cout << A[i];
		if (count == i){
			cout << "]";
		}

	}
	cout << endl;


	return 0;

}



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

using namespace std;

int main() {
  int s, w;
  cin >> s >> w;
  if (s <= w) {
    cout << "unsafe" << endl;
  } else {
    cout << "safe" << endl;
  }

  return 0;
}
/* vim:set fdm=marker: */


Measured memory_bytes: 3636
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main(string[] args) {
        long n = long.Parse(Console.ReadLine());
        long l = digitLength(n);
        long f = digitFirst(n);
        Console.WriteLine((l-1)*9 + f);
    }
    static long digitLength(long x) {
        long length = 0;
        while(x>0) {
            length++;
            x /= 10;
        }
        return length;
    }
    static long digitFirst(long x) {
        long first = 0;
        List<long> digit = new List<long>();
        while(x>0) {
            first = x%10;
            digit.Add(x%10);
            x/=10;
        }
        for(int i = 0; i < digit.Count()-1; i ++) {
            if(i == digit.Count()-1)　continue;
            if(digit[i] != 9) {
                first -= 1L;
                break;
            }
        }
        
        return first;
    }
}

Measured memory_bytes: 11220
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;

int main() {
	int N, K, Q;
	cin >> N >> K >> Q;
	
	vector<int> A(Q);
	vector<int> P(N, K - Q);
	for (int i = 0; i < Q; i++)
	{
		cin >> A[i];
		P[A[i] - 1]++;
	}

	for (int i = 0; i < N; i++)
	{
		if (P[i] <= 0) cout << "No" << endl;
		else cout << "Yes" << endl;
	}

	return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <string>
using namespace std;
 
int main() {
  string S, T;
  cin >> S >> T;
  for (int i = 0; i < S.size(); i++) {
    if (S[i] != T[i]) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

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

int N, M;
int A[100010], B[100010], C[100010];

int main() {
  cin >> N >> M;
  for (int i = 0; i < N; i++) cin >> A[i];
  for (int j = 0; j < M; j++) cin >> B[j] >> C[j];
  map<int, long> S;
  for (int i = 0; i < N; i++) S[A[i]]++;
  for (int j = 0; j < M; j++) S[C[j]] += B[j];
  long count = 0; long sum = 0;
  for (auto it = S.rbegin(); it != S.rend(); it++) {
    if (count + it->second >= N) {
      sum += (long)(it->first) * (N - count);
      break;
    } else {
      sum += (long)(it->first) * it->second;
    }
    count += it->second;
  }
  cout << sum << endl;
}

Measured memory_bytes: 17276
#include <iostream>
#include <algorithm>
#include <vector>

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

    int n;
    std::cin >> n;
    for(int i=0; i<n; ++i){
        std::vector<int> e(3);
        for(auto& j : e){
            std::cin >> j;
        }
        std::sort(e.begin(), e.end());
        std::cout << ((e[0]*e[0]+e[1]*e[1]==e[2]*e[2])?"YES":"NO") << "\n";
    }
    return 0;
}

Measured memory_bytes: 3144
while True:
  n, m = map(int, input().split())
  if n == 0:break
  max_score = [0] * n
  min_score = [0] * n
  for _ in range(m):
    line = list(map(int, input().split()))
    s, k = line[:2]
    for i in line[2:]:
      max_score[i - 1] += s
    if k == 1:
      min_score[line[2] - 1] += s
  
  print(max([max_score[i] - min(min_score[:i] + min_score[i + 1:]) + 1 for i in range(n)]))


Measured memory_bytes: 6608
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e9;
ll dp[101][101];
ll h,w;
vector<string>s;

void dfs(int x,int y)
{
	if(x==h||y==w)return;
	if(s[x][y]=='.')return;
	dfs(x+1,y);
	dfs(x,y+1);
	s[x][y] = '.';
}

int main()
{
	
	cin >> h >> w;
	s = vector<string>(h);
	for(ll i = 0;i<h;i++)cin>>s[i];
	
	if(s[0][0]=='#')
	{
		dp[0][0]=1;
		dfs(0,0);
	}
	
	//for(ll i = 0;i<h;i++)cout<<s[i]<<endl;

	for(ll i = 0;i<h;i++)
	{
		for(ll j = 0;j<w;j++)
		{
			ll a=INF,b=INF;
			if(i-1>=0)
			{
				if(s[i-1][j]=='.'&&s[i][j]=='#')a = dp[i-1][j]+1;
				else a = dp[i-1][j];
			}
			if(j-1>=0)
			{
				if(s[i][j-1]=='.'&&s[i][j]=='#')b = dp[i][j-1]+1;
				else b = dp[i][j-1];
			}
			if(a!=INF||b!=INF)dp[i][j] = min(a,b);
		}
	}
	//for(ll i = 0;i<h;i++){for(ll j = 0 ;j<w;j++){cout<<dp[i][j]<<' ';}cout<<endl;}
	cout<<dp[h-1][w-1]<<endl;
	return 0;
}

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

using i64 = long long;
using P = pair<i64, i64>;

#define overload3(_1, _2, _3, name, ...) name
#define rep1(i, n) for(i64 i = 0LL; i < (n); ++i)
#define rep2(i, a, b) for(i64 i = (a); i < (b); ++i)
#define rep(...) overload3(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
#define all(v) v.begin(), v.end()


void solve(long long X, long long N, std::vector<long long> p){
    for(i64 i = 0; i < 300; ++i){
        i64 a = X - i;
        bool flag = true;
        rep(j, N) if(p[j] == a) flag = false;
        if(flag){
            cout << a << endl;
            return;
        }
        a = X + i;
        flag = true;
        rep(j, N) if(p[j] == a) flag = false;
        if(flag){
            cout << a << endl;
            return;
        }
    }
}

struct IoSetup {
    IoSetup() {
        // cin.tie(nullptr);
        // ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
        cerr << fixed << setprecision(10);
    }
} iosetup;

int main(){
    long long X;
    scanf("%lld",&X);
    long long N;
    scanf("%lld",&N);
    std::vector<long long> p(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&p[i]);
    }
    solve(X, N, std::move(p));
    return 0;
}


Measured memory_bytes: 3696
#include<bits/stdc++.h>
using namespace std;
#define llt long long int
int main(){
    int a,b,a1,a3,a2;
    cin>>a>>b;
    for(int i=b-(a-1);i<=b+(a-1);i++){
        cout<<i<<" ";
    }
    cout<<endl;

return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <queue>
using namespace std;
typedef pair<int, int> P;

int h, w, map[102][102], dx[2][6] = {{-1, 0, -1, 1, -1, 0}, {0, 1, -1, 1, 0, 1}}, dy[6] = {-1, -1, 0, 0, 1, 1}, sum = 0;
bool checked[102][102];

int search(){
    queue<P> place;
    place.push(P(0, 0));
    checked[0][0] = 1;

    while(place.size()){
        int x1 = place.front().first, y1 = place.front().second;
        place.pop();

        for(int i = 0; i < 6; i++){
            int x2 = x1 + dx[y1 % 2][i], y2 = y1 + dy[i];

            if(x2 < 0 || x2 > w + 1 || y2 < 0 || y2 > h + 1){
                continue;
            }

            if(map[x2][y2]){
                sum++;
            } else if(!checked[x2][y2]){
                place.push(P(x2, y2));
            }

            checked[x2][y2] = 1;
        }
    }

    return sum;
}

int main(){
    scanf("%d%d", &w, &h);
    for(int i = 1; i <= h; i++){
        for(int j = 1; j <= w; j++){
            scanf("%d",&map[j][i]);
        }
    }

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

    return 0;
}

Measured memory_bytes: 1260
N, M, X = gets.split.map(&:to_i)
A_list = gets.split.map(&:to_i)

cost1 = 0
cost2 = 0
for i in 0..N
    if A_list.include?(i) then
        if i < X then
            cost1 += 1
        else
            cost2 += 1
        end
    end
end
print(cost1 > cost2 ? cost2 : cost1)

Measured memory_bytes: 1788
n = gets.to_i
a =  Array.new(n,0)
n.times do |i|
  a[i] = gets.to_i
end
a_g = a.group_by{|i|i}
count = 0
a_g.each do |k,v|
  count +=  v.length % 2
end
puts count

Measured memory_bytes: 13564
//                                      KiSmAt
#include "bits/stdc++.h"
using namespace std;
 
using ll = long long;
 
const ll inf = 1e18;
const int N = 3 * 1e3 + 10;

ll res;
ll a[N], dp[N][N];

void solve(){
    ll n;
    cin >> n;
    for(int i = 1; i <= n; ++i){
        cin >> a[i];
    }
    for(int i = 1; i <= n; ++i){
        dp[i][i] = a[i];
    }
    for(int j = 1; j < n; ++j){
        for(int i = 1; i <= n; ++i){
            if(j + i <= n){
                dp[i][i + j] = max(a[i] - dp[i + 1][i + j], a[i + j] - dp[i][i + j - 1]);
            }
        }
    }
    cout << dp[1][n];
}
 
int main(int argc, char const *argv[]){
    ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
    ll t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
}
// nEro

Measured memory_bytes: 70016
IDENTIFICATION DIVISION.
PROGRAM-ID. DUPLEX.
 
DATA DIVISION.
WORKING-STORAGE SECTION.
01 INP     PIC X(100).
01 IN-DATA.
   03 DT-X1 PIC X(10).
01 IN-LEN.
   03 DT-L1 PIC 9(2).
01 IN-N     PIC 9(3).
01 OUT-P    PIC Z9.
 
PROCEDURE DIVISION.
MAIN-001.
  ACCEPT INP.
  UNSTRING INP DELIMITED BY ALL ' '
      INTO DT-X1 COUNT IN DT-L1.
  MOVE DT-X1(1:DT-L1) TO IN-N.
 
  COMPUTE OUT-P = (IN-N + 1) / 2.
  DISPLAY OUT-P.
 
MAIN-EXIT.
  STOP RUN.


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

using namespace std;

#define int64 long long 
const int mod = (int) 1e9 + 7;


int main(){
	int d, t, s;
	cin>>d>>t>>s;
	if(d<= t*s){
		cout<<"Yes\n";
	}
	else{
		cout<<"No\n";
	}
}


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

#define rep(i,n) for(int i=0; i<(n); i++)
#define lep(j,n) for(int j=0; j<(n); j++)
#define reps(i,n) for(int i=1; i<(n); i++)
#define leps(j,n) for(int j=1; j<(n); j++)
#define pii pair<int,int>
#define gsort(x,n) sort((x),(x)+(n),greater<int>())
#define all(x) (x).begin(), (x).end()
#define int long long
#define setout(n,x) setw(n) << setfill(x)
#define Fixed fixed << setprecision(10)
const long long mod = 1000000007;
using namespace std;

#define return(Z) re:(Z)

long long h[10000010],x[10000010],z[10000010];

signed main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    string s;
    cin>>s;

    s[3]='8';
    cout<<s<<'\n';
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

const int NMAX = 100000 + 5;

int N;
int v[NMAX];

typedef long long int lint;
lint anss[NMAX];

vector <pair <int, lint> > sol;
vector <int> allV;

int normal(int nr) {
    return lower_bound(allV.begin(), allV.end(), nr) - allV.begin() + 1;
}


lint aib[NMAX];
lint aibSum[NMAX];

inline int lsb(int node) {
    return node & (-node);
}

void update(lint aib[], int pos, lint val) {
    for (; pos <= allV.size(); pos += lsb(pos))
        aib[pos] += val;
}

lint query(lint aib[], int pos) {
    lint ans = 0;
    for (; pos; pos -= lsb(pos))
        ans += aib[pos];
    return ans;
}

lint queryUp(lint aib[], int pos) {
    lint ans = query(aib, allV.size());
    if (pos > 0)
        ans -= query(aib, pos - 1);
    return ans;
}

int main()
{
    ios_base :: sync_with_stdio(false);

    cin >> N;
    for (int i = 1; i <= N; ++i) {
        cin >> v[i];
        allV.push_back(v[i]);
    }

    sort(allV.begin(), allV.end());
    allV.resize(unique(begin(allV), end(allV)) - begin(allV));

    for (int i = 1; i <= N; ++ i) {
        update(aib, normal(v[i]), 1);
        update(aibSum, normal(v[i]), v[i]);
    }

    int maximum = 0;
    for (int i = 1; i <= N; ++ i) {
        if (v[i] > maximum) {
            sol.push_back(make_pair(i, queryUp(aibSum, normal(maximum)) - 1LL * maximum * queryUp(aib, normal(maximum))));
            maximum = v[i];
        }

        update(aib, normal(v[i]), -1);
        update(aibSum, normal(v[i]), -v[i]);
    }

    reverse(sol.begin(), sol.end());

    anss[sol[0].first] = sol[0].second;
    for (int i = 1; i < sol.size(); ++ i)
        anss[sol[i].first] = sol[i].second - sol[i - 1].second;

    for (int i = 1; i <= N; ++ i)
        cout << anss[i] << '\n';
    return 0;
}


Measured memory_bytes: 5872
N,M,Q = map(int,(input().split()))
a = [0]*Q
b = [0]*Q
c = [0]*Q
d = [0]*Q
for i in range(Q):
    a[i],b[i],c[i],d[i] = map(int,(input().split()))

lun = [0]*N
l = []

def make(n):
    if len(n) > N:
        return 0
    if int(n) > 3234566667:
        return 0
    else:

        p = []
        for i in range(int(n[-1]),M):
            p.append(str(i))

        lun.append(n)
        for i in p:
            lun.append(n)
            if len(n) == N:
                l.append(n)
            make(n+i)
        return 0
for i in range(M):
    make(str(i))

l = list(set(l))

nax = 0
for x in l:
    score = 0
    for i in range(Q):
        if int(x[b[i]-1]) - int(x[a[i]-1]) == c[i]:
            score += d[i]
    nax = max(nax,score)

print(nax)

Measured memory_bytes: 126556
#include <bits/stdc++.h>
#define int long long
#define ld long double
#define endl '\n'
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define vpii vector<pii>
#define gr vector<vpii>
#define fi first
#define se second
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define GAME_OVER return 0
using namespace std;
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    string s;
    cin >> s;
    if (s[2] == s[3] && s[4] == s[5])
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    GAME_OVER;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
#define int long long

int length(int n) {
  int count = 0;
  while (n) {
    count++;
    n /= 10;
  }
  return count;
}

int power(int n) {
  int p = 1;
  for (int i = 0; i < n; i++) {
    p *= 10;
  }
  return p;
}

signed main() {
  string s;
  cin >> s;
  if (s.size() == 1) {
    cout << s << endl;
    return 0;
  }
  bool flag = true;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] != '9') flag = false;
  }
  if (flag) {
    cout << s.size() * 9 << endl;
    return 0;
  }
  int msb = s[0] - '0';
  int res = msb - 1 + (s.size() - 1) * 9;
  int su = 0;
  for (int i = 0; i < s.size(); i++) {
    su += s[i] - '0';
  }
  res = max(su, res);
  for (int i = 1; i < s.size(); i++) {
    int sum = 0;
    for (int j = 0; j < i; j++) {
      sum += s[j] - '0';
    }
    sum += s[i] - '0' - 1;
    sum += (s.size() - 1 - i) * 9;
    res = max(res, sum);
  }
  cout << res << endl;
  return 0;
}



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

#define rep(i,n)  for(int i = 0; i < (int)(n); i++)
#define sz(x)     ((int)(x).size())
#define all(x)    (x).begin(),(x).end()

using ll = long long;

ll gcd ( ll a, ll b ) { if ( b == 0 ) return a; else return gcd ( b, a%b ); }
ll lcm ( ll a, ll b ) { return a * b / gcd(a, b); }

int main (void) {
  std::cin.tie(0);  std::ios::sync_with_stdio(false);
  ll d, t, s; std::cin >> d >> t >> s;
  if ( t*s >= d ) std::cout << "Yes" << std::endl;
  else std::cout << "No" << std::endl;
  return 0;
}



Measured memory_bytes: 3608
#include<cstdio>
#include<algorithm>
using namespace std;
const int inf=0x3f3f3f3f;
int h,w,k,a[20][1010],pre[20][1010],flag,ans=inf;
char ch;
int main()
{
    scanf("%d %d %d",&h,&w,&k);
    for(int i=1; i<=h; i++)
    {
        for(int j=1; j<=w; j++)
        {
            scanf(" %c",&ch);
            pre[i][j]=pre[i][j-1]+ch-'0';
        }
    }
    for(int state=0; state<(1<<h-1); state++)
    {
        int last=0,sum=0,cnt=0,flag=1;
        for(int j=1; j<=w; j++)
        {
            for(int i=1; i<=h; i++)
            {
                sum=sum+pre[i][j]-pre[i][last];
                if(sum>k)
                {
                    if(j-last==1) //只有一列不能再切不满足条件
                    {
                        flag=0;
                        break;
                    }
                    i=0,sum=0,last=j-1;//第二轮循环再来一次
                    cnt++;
                }
                if(i==h||state&(1<<(i-1)))
                {
                    sum=0;
                }
            }
            if(!flag)
            {
                break;
            }
        }
        if(flag)
        {
            ans=min(ans, __builtin_popcountl(state)+cnt);
        }
    }
    printf("%d\n",ans);
    return 0;
}



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

int main() {
  int N;
  string S1,S2;
  cin >>N>> S1 >>S2;
  int row = 0 ;
  long ans =1;

  if(S1[0] == S2[0]) {
    ans *=3;
    row += 1;
  }
  else{
    ans *= 6;
    row +=2;
  }

  while(row<N){
    if(S1[row] == S2[row]) {
      if(S1[row-1]==S2[row-1]){
        ans *= 2;
        row +=1;
      }
      else{
        ans =ans;
        row +=1;
      }
    }
    else{
      if(S1[row-1]==S2[row-1]){
        ans *= 2;
        row +=2;
      }
      else{
        ans *=3;
        row +=2;
      }
    }
  //  cout << ans <<endl;
  }

  ans %= 1000000007;

  cout << ans <<endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(long long int i = 0; i < n; i++)
#define _rep(i,m,n) for(long long int i = m; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
const int N = 1000000;
const ll mod = 1000000007;

int main(){
    int a,b,c; cin >> a >> b >> c;
    print(max(c - (a - b),0));
}

Measured memory_bytes: 256
// C - One-stroke Path
package main

import "fmt"

func main() {
	var N, M int
	fmt.Scanf("%d %d", &N, &M)

	edges := map[int]map[int]bool{}
	for i := 0; i < M; i++ {
		var a, b int
		fmt.Scanf("%d %d", &a, &b)
		if edges[a] == nil {
			edges[a] = map[int]bool{}
		}
		if edges[b] == nil {
			edges[b] = map[int]bool{}
		}
		edges[a][b] = true
		edges[b][a] = true
	}

	rest := make([]int, N-1)
	for i := range rest {
		rest[i] = i + 2
	}

	ans := count(1, rest, edges)
	fmt.Println(ans)
}

func count(at int, rest []int, edges map[int]map[int]bool) (ans int) {
	if len(rest) == 0 {
		return 1
	}

	for i, r := range rest {
		if edges[at][r] {
			ans += count(r, remove(i, rest), edges)
		}
	}

	return
}

func remove(i int, xs []int) []int {
	return append(append([]int{}, xs[:i]...), xs[i+1:]...)
}


Measured memory_bytes: 640
n = int(input())
mons = list(map(int,input().split()))
def gcd(a,b):
    if a == 0:
        return b
    return gcd(b%a,a)
result = mons[0]
for i in range(n-1):
    result = gcd(result, mons[i+1])
print(result)

Measured memory_bytes: 14252
#include <stdio.h>
#include <stdlib.h>
#include<string.h>
int main(){
char s[100];
int size=0;
int counter=0;
scanf("%s",&s);
size=strlen(s);
for(int i=0;i<size;i++){
    if(s[i]!=s[size-i-1])
    counter++;
    }
printf("%d",counter/2);

return 0;
}


Measured memory_bytes: 128
#if 1
  #include <bits/stdc++.h>
#else
  #include "../../bits/stdc++.h"
#endif

#define FOR(i,a,b) for(int i = (a);i < (b);i++)
#define RFOR(i,a,b) for(int i = (b)-1;i >= (a);i--)
#define REP(i,n) FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))

using namespace std;

typedef pair<int, int> P;
#define pb push_back
#define mp make_pair
#define ft first
#define sd second

int n;
int a[1002];

bool input(){
  cin>>n;
  REP(i, n)cin>>a[i];
  return n;
}

void solve(){
  int d=abs(a[0]-a[1]);
  REP(i, n) {
    FOR(j, i+1, n) {
      d = min(d, abs(a[i]-a[j]));
    }
  }
  cout<<d<<endl;
}

int main(){
  cin.tie(0);
  
  while (input()){
      solve();
  }
  
  return 0;
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define all(x) x.begin(), x.end()
#define int long long
using namespace std;
typedef pair<int, int> pii;
const int INF = ((1LL << 30) + (1LL << 29));
const int MOD = 1000000007;
template <typename T1, typename T2>
inline void chmin(T1 &a, T2 b) {
  if (a > b) a = b;
}
template <typename T1, typename T2>
inline void chmax(T1 &a, T2 b) {
  if (a < b) a = b;
}

int N, M, K;
string S, T;
vector<int> V;
void input() {}
void solve() {
  cin>>N>>M;

  int i=0;
  int cnt=1;
  for(; cnt<M; ++i){
    cnt += N-1;
  }
  cout<<i<<endl;
}
signed main() {
  input();
  solve();
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<ll> a(51);
vector<ll> p(51);

ll num(ll n, ll k) {
  ll res;
  if(k==a[n]) {
    res=p[n];
  }
  else if(k<2) {
    res=0;
  }
  else if(k>1&&k<=1+a[n-1]) {
    res=num(n-1,k-1);
  }
  else if(k==a[n-1]+2) {
    res = p[n-1]+1;
  }
  else if(k>a[n-1]+2&&k<a[n]) {
    res = p[n-1]+1+num(n-1,k-(a[n-1]+2));
  }
  return res;
}

int main() {
  ll n,k;
  cin >> n >> k;
  a[0]=1;
  p[0]=1;
  for(int i=0;i<n;i++) {
    a[i+1]=2*a[i]+3;
    p[i+1]=2*p[i]+1;
  }
  cout << num(n,k) << endl;
}

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

int main(int argc, char const *argv[]) {
    int n, k, h;

    cin >> n >> k;

    int counter = 0;
    for (int i = 0; i < n; i++) {
        cin >> h;
        if (h >= k) {
            counter++;
        }
    }

    cout << counter << endl;

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

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

    int ans = 1;
    while (ans * (ans + 1) / 2 < X) {
        ans++;
    }

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

Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    ll n;
    double d;
    cin>>n>>d;
    ll ans=0;
    for(int i=0;i<n;i++)
    {
        double x,y;
        cin>>x>>y;
        if(sqrt(x*x+y*y)<=d)ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3800
#include<iostream>
#include<vector>
#include<cmath>
#include<string>
#include<algorithm>
#include<map>
#include<utility>
#include<cstdio>
#include<bits/stdc++.h>

using namespace std;
using ll = long long;
const long long INF = 1LL<<60;

typedef pair<long long,bool> Pair;

int main(){

double R;

cin >> R;

cout << 2.0*R*M_PI << endl;

return 0;

}

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


void solve(long long N, long long K, std::string S){
    ll ans = 0;
    rep(i, N) {
        if(S[i] == 'R' && i < N-1){
            if(S[i+1] == 'R') ans++;
        }
        else if (S[i] == 'L' && i > 0) {
            if (S[i - 1] == 'L') ans++;
        }
    }
    ans += K * 2;
    cout << min(ans, N - 1) << endl;
        
}

// Generated by 1.1.5 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    long long K;
    scanf("%lld",&K);
    std::string S;
    std::cin >> S;
    solve(N, K, S);
    return 0;
}


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

using namespace std;

#define ll long long
#define ini(arr, val) memset(arr, (val), sizeof(arr))
#define loop(i,n)  for(ll i=0; i<n; i++)

#define all(a)      (a).begin(),(a).end()
#define exist(s,e)  (s.find(e)!=s.end())
#define dbg(x)  cout << #x << " is " << x << endl;
#define pt(x) cout<<x<<"\n"
#define pts(x) cout<<x<<" "

#define mp make_pair
#define pb push_back
#define f first
#define s second


#define inf (int)1e9
#define eps 1e-9
#define PI 3.1415926535897932384626433832795
#define mod 1000000007


#define fast    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define test   int t; cin>>t; while(t--)

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef map<int,int> mii;
typedef set<int> si;

typedef pair<ll, ll> pll;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<pll> vpll;
typedef vector<vl> vvl;
typedef map<ll,ll> mll;
typedef set<ll> sl;


//////////////////////////////////////////////////////////////////////////////////////////
//                      main starts
//////////////////////////////////////////////////////////////////////////////////////////
int const lmt=1e5+5;



int main(){

 //    #ifndef ONLINE_JUDGE
 //    freopen("../input.txt", "r", stdin);
 //    freopen("../output.txt", "w", stdout);
	// #endif
 //    fast

    string s;
    cin>>s;
   	if((s[2]==s[3])&&(s[4]==s[5])) pt("Yes");
   	else pt("No");
}


/*

// 

*/

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int X, Y, ans;
    cin >> X >> Y;
    for(int i=0; i<=X; i++){
        if(2*i + 4*(X-i) == Y){
            cout << "Yes";
            return 0;
        }
    }
    cout << "No";
}

Measured memory_bytes: 3636
use std::f64::consts::PI;
 
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}
 
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
 
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}
 
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
 
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
 
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
 
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
 
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
 
fn main() {
    input! {
        r: f64,
    }
 
    println!("{}", r * 2.0 * PI);
}

Measured memory_bytes: 2196
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define m1(x) memset(x,-1,sizeof(x))
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589;

ll a, b, x;
ll func(ll s){
  if(s == -1) return 0;
  return s/x + 1;
}

int main(){
  cin >> a >> b >>x;
  cout << func(b) - func(a-1)<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MAX = 200005;
const long long int mod=998244353;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % mod;
        inv[i] = mod - inv[mod%i] * (mod / i) % mod;
        finv[i] = finv[i - 1] * inv[i] % mod;
    }
}
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
int main(){
    COMinit();
    int N,K;
    long long int M;
    cin >> N >> M >> K;
    long long int ans=0;
    long long int tmp=M;
    int x=1;
    while(x<N-K){
        tmp*=(M-1);
        tmp%=mod;
        x++;
    }
    for(int i=K;i>=0;i--){
        ans+=(tmp*COM(N-1,i));
        ans%=mod;
        tmp*=(M-1);
        tmp%=mod;
    }
    cout << ans << endl;
}

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

// macro
#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
int main()
{
  int n;cin>>n;
  vector<int> p(n);
  int i;
  rep(i,n)cin>>p[i];
  vector<bool> change(n,false);
  rep(i,n)if(i==p[i]-1)change[i]=true;
  i=0;
  int ans=0;
  while(i<n)
  {
    if(!change[i])
    {
      i++;
      continue;
    }
    if(i<n-1&&change[i+1])
    {
      change[i]=false;
      change[i+1]=false;
      ans++;
    }
    else
    {
      change[i]=false;
      ans++;
    }
    i++;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main() 
{
	int a,b;
	string s;
	cin>>a>>b;
	cin>>s;
	if(s[a]!='-') 
	{
		cout<<"No"<<endl;
		return 0;
	}
	for(int i=0;i<s.size();i++) 
	{
		if(i!=a && !(s[i]>='0' && s[i]<='9')) 
		{
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef complex<double> Point;
typedef pair<Point, Point> Line;
const double EPS = 1e-10;

// 内積 |a||b|cosθ
double dot(Point a, Point b){
	// return a.real() * b.real() + a.imag() * b.imag();
	return (conj(a) * b).real();
}

int main(){
    int q;
    cin >> q;
    for(int i = 0; i < q; i++){
        double x, y;
        Point p[4];
        for(int j = 0; j < 4; j++){
            cin >> x >> y;
            p[j] = {x, y};
        }
        Line s1 = {p[0], p[1]};
        Line s2 = {p[2], p[3]};
        double cost = dot(p[1] - p[0], p[3] - p[2]) / (abs(p[1] - p[0]) * abs(p[3] - p[2]));
        if(fabs(cost) < EPS) cout << 1 << endl;
        else if(fabs(cost) > 1 - EPS) cout << 2 << endl;
        else cout << 0 << endl;
    }
}


Measured memory_bytes: 3288
#include<stdio.h>
typedef struct{
 int left;
 int right;
}eyet;
eyet ts[4];
int main(){
 int i;
 double m[]={0.2,0.6,1.1},left,right;

 while(scanf("%lf %lf",&left,&right)!=EOF){
  for(i=0;i<3;i++)
    if(left<m[i]){
      ts[i].left++;
      break;
    }
  if(i==3) ts[i].left++;
  for(i=0;i<3;i++)
    if(right<m[i]){
      ts[i].right++;
      break;
    }
  if(i==3) ts[i].right++;
 }
 for(i=3;i>-1;i--) printf("%d %d\n",ts[i].left,ts[i].right);
 return 0;
}

Measured memory_bytes: 0
#if 0
2019.12.16

足够长的时间后，点一定是按速度排序的，不妨假定 v 升序。
考虑点 i 被染色后有哪些点会被染到，事实上染到的一定是一段区间 [l, r] ，
l 是最小的满足 x[l] >= x[i] 的下标，
r 是最大的满足 x[r] <= x[i] 的下标。

原因：
i 最开始在 l 左边 (x[l] >= x[i])，最后一定会在 l 右边 (v[l] <= v[i]) ，
可以反证最后在 [l, i] 区间内的点都会被经过，
对于 r 同理。

求出了所有点的 [l, r] 后，问题转换为选择若干 [l, r] 使得它们的并为 [1, n] 。
根据定义不难发现 l, r 都随 x[i] 的增大单调不降。
那么再将点按 x 升序，此时的 l, r 也就都是升序的了。

DP 设 f[i] 表示用前 i 个区间，钦定第 i 个区间必选，覆盖 [1, r[i]] 的方案数。
对于所有满足 r[j] >= l[i] - 1 且 j < i 的 j 都可以从 f[j] 转移到 f[i] 。
而 r 是升序的，这意味着只要 f[j] 能转移到 f[i] ，f[j + 1] 就能转移到 f[i] ，
换言之，f[i] 的转移是一段区间 [L, i - 1] ，其中 L 是满足条件的最小 j 。
而同时 l 也是升序的，这意味着 L 也是升序的，dp 的过程中维护这个 L 即可。
区间转移用前缀和优化即可做到 O(1) 。

实现上并不需要反复排序，只需要将 x 离散化后就可以替代第二次排序，
并且 x 离散化后求 l, r 相当于求一类前缀后缀最值。
总复杂度 O(nlogn) ，瓶颈在于排序和离散化。
#endif
#include <cstdio>
#include <algorithm>
#define debug(...) fprintf(stderr, __VA_ARGS__)

typedef long long ll;
typedef std::pair<int, int> Par;

struct {
	inline operator int () { int x; return scanf("%d", &x), x; }
	inline operator ll () { ll x; return scanf("%lld", &x), x; }
	template<class T> inline void operator () (T &x) { x = *this; }
	template<class T, class ...A> inline void operator () (T &x, A &...a)
	{ x = *this; this -> operator ()(a...); }
} read;

const int maxn = 200005, mod = 1000000007;
int l[maxn], r[maxn];
int p[maxn];
int tmp[maxn];
Par pr[maxn];
ll f[maxn], s[maxn];

int main() {
	int n = read;

	for(int i = 1; i <= n; i ++)
		read(pr[i].second, pr[i].first);
	std::sort(pr + 1, pr + n + 1);

	for(int i = 1; i <= n; i ++)
		tmp[i] = pr[i].second;
	std::sort(tmp + 1, tmp + n + 1);

	for(int i = 1; i <= n; i ++) {
		pr[i].second = int(std::lower_bound(tmp + 1, tmp + n + 1, pr[i].second) - tmp);
		p[pr[i].second] = i;
	}

	for(int i = 1; i <= n; i ++)
		r[i] = std::max(r[i - 1], p[i]);
	l[n] = p[n];
	for(int i = n - 1; i; i --)
		l[i] = std::min(l[i + 1], p[i]);

	/* for(int i = 1; i <= n; i ++) */
	/* 	debug("%d-%d\n", l[i], r[i]); */

	int L = 0;
	f[0] = s[0] = 1;

	for(int i = 1; i <= n; i ++) {
		while(r[L] < l[i] - 1)
			++ L;
		f[i] = (s[i - 1] - s[L - 1] + mod) % mod;
		s[i] = (s[i - 1] + f[i]) % mod;
		/* debug("%lld\n", f[i]); */
	}

	while(r[L] < n)
		++ L;
	printf("%lld\n", (s[n] - s[L - 1] + mod) % mod);
}


Measured memory_bytes: 7936
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner stdIn = new Scanner(System.in);
    int max = 0;
    int sum = 0;
    int temp;
    int n = stdIn.nextInt();
    
    for(int i = 0; i < n; i++){
      temp = stdIn.nextInt();
      max = Math.max(temp, max);
      sum += temp;
    }
    
    System.out.println(sum - max / 2);
    stdIn.close();
  }
}

Measured memory_bytes: 23636
#include<stdio.h>
int main(void) {
	int a, b, c;
	int hako[10000];
	int ans = 0;

	int i, j;

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

	if (a >= 13) {
		printf("%d\n",b);
	}
	else if(a<=12&&a>=6){
		printf("%d\n", b / 2);
	}
	else {
		printf("0\n");
	}


	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string s;
    cin>>s;
    if(s[s.size()-1]=='s'){cout<<s+"es";}
    else cout<<s+"s";

}


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

#define ll long long
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define vecbool vector<bool>
#define vecpairll vector<pair<long long,long long>>
#define forll(s,a,b) for(long long s = a;s < b;s++)
#define forllde(s,a) for(long long s = a;s > 0;s--)


int main()
{
  ll n, s=0, over, tmp=0;
  cin >> n;
  vecll a(n);
  forll(i, 0, n){
	cin >> a[i];
	s += a[i];
  }
  double m = (double)s / 2.0;
  forll(i, 0, n){
	tmp += a[i];
	if ((double)tmp > m){
	  over = i;
	  break;
	}
  }
  cout << (ll)(min(((double)tmp-m), (m - (double)(tmp - a[over]))) * 2) << endl;
}


Measured memory_bytes: 1792
/*author - Aryan Mittal*/
#include<bits/stdc++.h>
using namespace std;

#pragma GCC push_options
#pragma GCC optimize ("unroll-loops")


#define print(a)        for (auto x : a) cout << x << " "; cout << endl
#define print_upto(a,n)        for(int i=0;i<n;i++)    cout<<a[i]<<" "; cout<<endl
#define take(x,n)           for(int i=0;i<n;i++)  cin>>x[i];

#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define watch2(x,y) cout <<(#x)<<" is "<<(x)<<" and "<<(#y)<<" is "<<(y)<<"\n"

#define ll long long
#define pie_value 3.14159265358979323846

int main() {

	// Use ctrl+shift+b ( second option )
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	freopen("error.txt" , "w" , stderr);
#endif

	ll n;
	cin >> n;

	map<string, ll> mp;

	for (ll i = 1; i <= n; i++) {
		string s;
		cin >> s;

		mp[s]++;
	}

	cout << "AC x " << mp["AC"] << "\n";
	cout << "WA x " << mp["WA"] << "\n";
	cout << "TLE x " << mp["TLE"] << "\n";
	cout << "RE x " << mp["RE"] << "\n";


	return 0;
}


Measured memory_bytes: 3660
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <set>

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,j) FOR(i,0,j)
#define mp std::make_pair

const int INF = 1 << 24;
// S N E W(南北東西)
const int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1}, dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};

typedef unsigned long long ull;
typedef std::pair<int,int> P;
typedef std::pair<int,P> State;

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

    int h[500];
    REP(i, N){
        std::cin >> h[i];
    }
    std::sort(h, h+N, std::greater<int>());

    ull res = 0;
    int max_l[4];
    std::fill(max_l, max_l+4, 0);
    REP(i, N){
        int l = i / 4 + 1;
        if(h[i] >= l){
            res += h[i] - l;
            max_l[i%4] = l;
        }
    }

    REP(i, 4){
        res += max_l[i];
    }
    res++;

    std::cout << res << std::endl;
}

Measured memory_bytes: 1172