akhauriyash/Code-Regression huggingface dataset:
N = int(input())
A = list(map(int, input().split()))
A.sort()

result = {}

for i in range(N):
  if A[i] not in result:
    result[A[i]] = 1
  else:
    result[A[i]] += 1
  
count = 0

for i in result.keys():
  if result[i] > i:
    count += abs(i-result[i])
  elif result[i] < i:
    count += result[i]

  
print(count)

Measured memory_bytes: 18168
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n;
  long a,b;
  cin >> a >> b >> n;
  int count =0;
  while(1){
    if(a%2==1)
      a-=1;
    b+=a/2;
    a /= 2;
    //cout << "a " << a << " b " << b << endl;
    count++;
    if(count >= n)
      break;
    
    if(b%2==1)
      b-=1;
    a+=b/2;
    b /=2;
    //cout << "a " << a << " b " << b << endl;
    count++;
    if(count >= n)
      break;
  }
  cout << a << " " << b << endl;
}

Measured memory_bytes: 256
//#define _USE_MATH_DEFINES
//#include <cmath>
#include <iostream>
//#include <stdio.h>
//#include <stdlib.h>
//#include <iomanip>
#include <vector>
//#include <string>
//#include <algorithm>
//#include <functional>
//#include <time.h>
//#include <sstream>
//#include <queue>

using namespace std;


int main(){

	int a[4], b[4];
	int hit = 0, blow = 0;
	bool flag = false;

	while (1){

		for (int i = 0; i < 4; i++){
			if (!(cin >> a[i])){
				flag = true;
				break;
			}
		}
		if (flag)break;
		for (int i = 0; i < 4; i++){
			cin >> b[i];
		}

		hit = 0;
		blow = 0;

		//hit
		for (int i = 0; i < 4; i++){
			if (a[i] == b[i]) hit++;
		}

		//blow
		for (int i = 0; i < 4; i++){
			for (int j = 0; j < 4; j++){
				if (a[i] == b[j]) blow++;
			}
		}

		blow -= hit;

		cout << hit << " " << blow << endl;
	}


	


	return 0;
}

Measured memory_bytes: 1160
#include<stdio.h>
int main()
{
	int n,x,m,a=0,t=1001,c=0;

	scanf("%d%d",&n,&x);
	for(int i=0;i<n;i++){
		scanf("%d",&m);
		a+=m;
		c++;
		if(t>m)
			t=m;
	}
	while(x-a>=0){
		a+=t;
		c++;
	}
	printf("%d",c-1);
	return 0;
}


Measured memory_bytes: 128
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<fstream>
#include<list>
#include<typeinfo>
#include<functional>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;

vector<pair<ll,pll>> V;

ll judge(ll x,ll y){
    ll h=V[0].F+abs(x-V[0].S.F)+abs(y-V[0].S.S);
    if(h<=0){return -1;}
    for(int i=1;i<V.size();i++){
        ll H=h-abs(x-V[i].S.F)-abs(y-V[i].S.S);
        H=max(H,(ll)0);
        if(H!=V[i].F){return -1;}
    }
    return h;
}

    
int main(){
    ll n;
    cin>>n;
    V.resize(n);
    for(int i=0;i<n;i++){
        ll x,y,h;
        cin>>x>>y>>h;
        V[i]={h,{x,y}};
    }
    sort(V.begin(),V.end(),greater<pair<ll,pll>>());
    if(V[0].F==0){
        while(1);
    }
    for(int i=0;i<=100;i++){
        for(int t=0;t<=100;t++){
            ll ret=judge(i,t);
            if(ret!=-1){
                cout<<i<<" "<<t<<" "<<ret<<endl;
                return 0;
            }
        }
    }
    assert(false);
    
    
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ii> vii;
const int mod = 1e9+7;


main(){
    int count=0;
    int n;cin>>n;
    ll mat[n][2];
    for(int i=0;i<n;i++) cin>>mat[i][0]>>mat[i][1];
    for(int i=2;i<n;i++){
        if(mat[i][0]==mat[i][1] && mat[i-1][0]==mat[i-1][1] && mat[i-2][0]==mat[i-2][1]) count++;
    }
    if(count) cout<<"Yes";
    else cout<<"No";
}

Measured memory_bytes: 3620
defmodule Main do
  use Bitwise

  def main do
    [h, w, k] = IO.gets("")
                |> String.split()
                |> Enum.map(&String.to_integer/1)
    board = IO.stream(:stdio, :line)
           |> Enum.take(h)
           |> Enum.map(&String.trim/1)
           |> Enum.map(&String.codepoints/1)

    board
    |> calc(h, w, k)
    |> IO.puts()

  end

  def calc(board, h, w, k) do
    Enum.reduce(0..(1<<<h)-1, 0, fn x, acc0 ->
      Enum.reduce(0..(1<<<w)-1, 0, fn y, acc1 ->
        Enum.reduce(0..h-1, 0, fn i, acc2 ->
          Enum.reduce(0..w-1, acc2, fn j, acc3 ->
            board
            |> at(i, j)
            |> count({x, y}, {i, j}, acc3)
          end)
        end)
        |> add(k)
        |> Kernel.+(acc1)
      end) + acc0
    end)
  end

  defguard is_valid(cell, x, y, i, j) when (x>>>i &&& 1) == 0 and (y>>>j &&& 1) == 0 and cell=="#"

  def count(cell, {x, y}, {i, j}, acc) when is_valid(cell, x, y, i, j), do: acc+1
  def count(_, _, _, acc), do: acc

  def at(board, i, j) do
    board
    |> Enum.at(i)
    |> Enum.at(j)
  end

  def add(sum, k) when sum == k, do: 1
  def add(_, _), do: 0

end


Measured memory_bytes: 31196
chomp($s=<>);
chomp($a=<>);
@a=split/ /,$a;
if ($#a % 2) {
    $i = 1;
} else {
    $i = 0;
}

foreach (@a){
	if($i % 2){
		push @b,$_;
    }else{
    	unshift @b,$_;
    }
    $i++;
}
print join ' ',@b;

Measured memory_bytes: 42404
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#define numarr 22
using namespace std;

int main() {
	int N, H[numarr], ans = 0, i, j;
	cin >> N;
	for (i = 1; i <= N; i++)
	{
		cin >> H[i];
		j = 1;
		while (1)
		{
			if (H[j] > H[i])
				break;
			if (j == i)
			{
				ans++;
				break;
			}
			j++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#pragma warning(disable: 4996)

#include <iostream>
#include <iomanip>
#include <random>
#include <unordered_map>
#include <functional>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <vector>
#include <bitset>
#include <numeric>
#include <string>
#include <set>
#include <tuple>
#include <utility>
#include <regex>
#include <deque>
#include <map>
#include <queue>
using namespace std;

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	long long n, count = 0, len = 0;
	cin >> n;
	while (n >= 1) {
		count++;
		n /= 2;
	}
	len = (1ll << count) - 1;
	cout << len;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> t(N+1);
  vector<int> x(N+1);
  vector<int> y(N+1);
  bool flag = false;
  t[0]=0;
  x[0]=0;
  y[0]=0;
  
  int absx, absy;
  
  for(int i=1; i<N+1; i++){
  	cin >> t[i] >> x[i] >> y[i];
    absx = abs(x[i] - x[i-1]);
    absy = abs(y[i] - y[i-1]);
      
    if(absx + absy > t[i] || (absx + absy)%2 != (t[i]-t[i-1])%2) break;
    if(i==N) flag = true;
  }
    
    if(flag == false) cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;

}

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

int main(int argc, char const *argv[]) {
  int n;
  scanf("%d\n",&n);
  int i;
  int score1=0;
  int score2=0;
  char *word1 =(char*)malloc(sizeof(char)*100000);
  char *word2 =(char*)malloc(sizeof(char)*100000);
  for (i = 0;i<n;i++) {
    scanf("%s %s",&word1[i],&word2[i]);
    if(strcmp(&word1[i],&word2[i])>0){
      score1+=3;
    }else if(strcmp(&word1[i],&word2[i])<0){
      score2+=3;
    }else{
      score1+=1;
      score2+=1;
    }
  }
  printf("%d %d\n",score1,score2);
  return 0;
}

Measured memory_bytes: 612
#include <bits/stdc++.h>
#include <set>
#include <vector>
using namespace std;
#define rep(i,n) for(ll i = 0; i < n; ++i)
#define Rep(i,n) for(ll i = 0; i <= n; ++i)
#define yes "yes"
#define Yes "Yes"
#define no "no"
#define No "No"

namespace mydef
{
  void say(string some){
    cout << some << "\n";
  }
} // namespace mydef
using namespace mydef;
typedef long long ll;
const int INF = 1001001001;
const long double PI=3.14159265358979323846;

//ここからいじる

signed main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  
  long double a, b, h, m;
  cin >> a >> b >> h >> m;
  
  m += h*60;
  long double limit = 60*12/11;
  // while (m < limit)
  // {
  //   m -= limit;
  // }
  long double rad = m * 11 * PI/ 360;
  long double C = pow(a,2) + pow(b,2) - 2*a*b*cos(rad);
  long double c = pow(C, 0.5);
  cout << setprecision(11) << c << endl;
  
  
  

  return 0;
}

Measured memory_bytes: 4184
#include<iostream>
#include<set>
#include<string>

using namespace std;

int main(){
    set<string> st;
    string s;
    int n; cin >> n;
    for(int i=0;i<n;i++){
        cin >> s;
        st.insert(s);
    }

    cout << st.size() << endl;
    

    return 0;
}

Measured memory_bytes: 19124
use std::io::*;

fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let x: usize = itr.next().unwrap().parse().unwrap();
    let y = x / 100;
    let z = x % 100;
    println!("{}", if y * 5 >= z { 1 } else { 0 })
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#include <cassert>
typedef long long int ll;
using namespace std;

// @@ !! LIM()

int main(/* int argc, char *argv[] */) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  string s, t; cin >> s >> t;
  string s2 = s + s;
  ll n = s.size();
  ll m = t.size();
  vector<vector<ll>> nxt(n * 2, vector(128, -1LL));
  for (ll i = 2*n - 1; i >= 0; i--) {
    if (i+1 < 2*n) nxt[i] = nxt[i+1];
    nxt[i][s2[i]] = i;
  }
  ll pos = -1;
  ll cnt = 0;
  for (ll i = 0; i < m; i++) {
    ll prev = pos;
    pos = nxt[pos+1][t[i]];
    if (pos == -1) {
      cout << "-1\n";
      return 0;
    }
    pos = pos % n;
    if (prev >= 0 && pos <= prev) cnt++;
  }
  cout << cnt * n + pos + 1 << endl;

  return 0;
}



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

using namespace std;

int main()
{
    string s, ans;
    cin >> s;
    for(int i = 0; i <= 2; i++){
        if(s[i] == '1'){
            ans += '9';
        }else{
            ans += '1';
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N = 0;
  cin >> N;
  vector<char> moji{'M', 'A', 'R', 'C', 'H'};
  vector<int> moji_count(5, 0);

  for(int i=0; i<N; i++) {
    string name;
    cin >> name;
    for(int j=0; j<5; j++) {
      if(name.at(0) == moji.at(j)) moji_count.at(j)++;
    }
  }

  long solution = 0;

  for(int i=0; i<3; i++) {
    for(int j=i+1; j<4; j++) {
      for(int k=j+1; k<5; k++) {
        long a = moji_count.at(i);
        long b = moji_count.at(j);
        long c = moji_count.at(k);
        solution += a*b*c;
      }
    }
  }

  cout << solution << endl;
  return 0;
}


Measured memory_bytes: 3628
#include <cstdio>
#include <complex>
#include <cmath>
using namespace std;
typedef complex<double> xy_t;
xy_t P[21];
double area(xy_t A, xy_t B,xy_t C)
{
  double a=abs(B-C);
  double b=abs(A-C);
  double c=abs(A-B);
  double z=(a+b+c)/2.0;
  return sqrt(z*(z-a)*(z-b)*(z-c));
}
int main()
{
  int N=0;
  double x,y;
  while(scanf("%lf,%lf",&x,&y)!=EOF)
  {
    P[N++]=xy_t(x,y);
  }
  double sum=0.0;
  for(int i=1;i<N-1;i++)
  {
    sum+=area(P[0],P[i],P[i+1]);
  }
  printf("%6lf\n",sum);
  return 0;
}

Measured memory_bytes: 2628
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= end; --i)
#define iter(i, c) for (auto i = (c).begin(); i != (c).end(); ++i)
#define riter(i, c) for (auto i = (c).rbegin(); i != (c).rend(); ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S;
    int Q;
    cin >> S >> Q;
    bool is_head = true;
    deque<char> que;
    rep(i, 0, S.size()) {
        que.push_back(S[i]);
    }
    int q_type, F;
    char C;
    rep(i, 0, Q) {
        cin >> q_type;
        if (q_type == 1) {
            is_head ^= 1;
        }
        else {
            cin >> F >> C;
            if (F == 1) {
                if (is_head) {
                    que.push_front(C);
                }
                else {
                    que.push_back(C);
                }
            }
            else {
                if (is_head) {
                    que.push_back(C);
                }
                else {
                    que.push_front(C);
                }
            }
        }
    }
    if (is_head) {
        while (!que.empty()) {
            cout << que.front();
            que.pop_front();
        }
    }
    else {
        while (!que.empty()) {
            cout << que.back();
            que.pop_back();
        }
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 976
i, j, k, l = 0, 0, 0, 0

while True:
    # 引数:0 == AB, 1 == BC, 2 == CA と仮定
    listTRI = [int(i) for i in input().split()]
    sumList = sum(listTRI)
    # 三角形が不成立でbreak
    if min(listTRI) <= 0:
        break
    if sumList - max(listTRI) <= max(listTRI):
        break
    # 辺の最大値のインデックス取得
    maxIND = listTRI.index(max(listTRI))
    # 余弦定理を用いて、最大の辺の「対角のcos」を求める
    # 全ての辺の2乗の合計 から 一番長い辺の2乗を2回引く
    cos1 = sum(map(lambda x: x ** 2, listTRI)) - ((listTRI[maxIND] ** 2) * 2)
    # 全ての辺の2倍の合計　から　一番長い辺の2倍を引く
    cos2 = sumList * 2 - (listTRI[maxIND] * 2)
    # cos1 と cos2を割った結果
    cosTRI = cos1 / cos2
    # cosTRIが正なら鋭角、0なら直角、負なら鈍角
    if cosTRI < 0:
        i += 1
        l += 1
    elif 0 < cosTRI :
        i += 1
        k += 1
    else:
        i += 1
        j += 1

print(i, j, k, l)


Measured memory_bytes: 5612
#include<iostream>
#include<vector>
#include<cmath>
#include<cstdlib>
#include<time.h>
#include<algorithm>
using namespace std;

int main()
{
	int N;
	cin >> N;
	if (N == 25)cout << "Christmas";
	else if(N == 24)cout << "Christmas Eve";
	else if (N == 23)cout << "Christmas Eve Eve";
	else if (N == 22)cout << "Christmas Eve Eve Eve";
	return 0;
}

Measured memory_bytes: 256
/* */

#include <cstdio>
#include <cstring>
#include <cassert>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <bitset>
#include <map>
#include <set>
using namespace std;
typedef long long int ll;
typedef vector< int > vi;
typedef pair< int, int > ii;
typedef vector< ii > vii;
typedef vector< ll > vll;
#ifdef XVENOM
	#define errp(...) fprintf(stderr, __VA_ARGS__)
#else
	#define errp(...)
#endif
#define dbg(x) errp("%s = %s\n", #x, to_string(x).data())
string to_string (string s) { return "\"" + s + "\""; }
template<typename T> string to_string (vector<T>);
template<typename U, typename V> string to_string (pair<U, V> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template<typename T> string to_string (vector<T> v) {
	string res = "["; for (int i = 0; i < (int)v.size() - 1; i++) res += to_string(v[i]) + ", ";
	if (!v.empty()) res += to_string(v.back());	res += "]"; return res; }

int main () { 
#ifdef XVENOM
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
#endif

	int n;
	vi b;
	scanf("%d", &n);
	b.assign(n - 1, 0);
	for (int i = 0; i < n - 1; i++) scanf("%d", &b[i]);
	int ans = 0;
	ans += b[0] + b[n - 2];
	for (int i = 1; i < n - 1; i++) ans += min(b[i], b[i - 1]);
	printf("%d\n", ans);

}

Measured memory_bytes: 256
n = gets.to_i
s = gets.chomp
counter = 0
(1..n).each do |i|
  (i + 1..((n + i) / 2)).each do |j|
    if (s[i - 1] != s[j - 1]) && (s[i - 1] != s[2 * j - i - 1]) && (s[j - 1] != s[2 * j - i - 1])
      counter += 1
    end
  end
end
puts s.count('R') * s.count('G') * s.count('B') - counter

Measured memory_bytes: 14416
#include <iostream>
#include <cmath>

using namespace std;

void solve()
{
	int N;
	while(cin >> N, N)
	{
		if(N == 1)
		{
			cout << "deficient number" << endl;
			continue;
		}
		double rt = sqrt((double)N);
		int sum = 1;
		for(int i = 2; i <= rt; ++i)
		{
			if(i == rt && N % i == 0)
			{
				sum += i;
			}
			else if(N % i == 0)
			{
				sum += i + N / i;
			}
		}
		if(sum < N)
		{
			cout << "deficient number" << endl;
		}
		else if(sum > N)
		{
			cout << "abundant number" << endl;
		}
		else
		{
			cout << "perfect number" << endl;
		}
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 0
#include <iostream> 
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <string>
using namespace std;
#define MAX_N 21

int main() {
	string a,b,c;
	cin >> a >> b >> c;
	if (a[a.length() - 1] == b[0]) {
		if (b[b.length() - 1] == c[0]) {
			cout << "YES";
			return 0;
		}
	}
	cout << "NO";
    return 0;
 }

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define pb push_back
#define mp make_pair
#define INF (int)1e9
#define cBits(x) __builtin_popcount(x)
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) a/gcd(a,b)*b
#define FOR(i,a,b) for (int i=a;i<b;i++)
#define FORr(i,a,b) for (int i=a;i>=b;i--)
#define MAX3(a,b,c) max(a,max(b,c))
#define MIN3(a,b,c) min(a,min(b,c))
#define eachTest int t; cin >> t; while(t--) solve();

using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<ll,ll> PLL;
typedef pair<int,int> PII;

const int MOD=1000000007;

void solve() {
	;
}

int main() {

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

	// eachTest

	ll n;
	cin >> n;

	ll table[n][3];
	ll a, b, c;
	FOR(i,0,n) {
		cin >> a >> b >> c;
		table[i][0] = a;
		table[i][1] = b;
		table[i][2] = c;
		if (i==0) {
			continue;
		}
		table[i][0] += max(table[i-1][1], table[i-1][2]);
		table[i][1] += max(table[i-1][2], table[i-1][0]);
		table[i][2] += max(table[i-1][0], table[i-1][1]);
	}
	cout << MAX3(table[n-1][0], table[n-1][1], table[n-1][2]) << "\n";

	return 0;
}


Measured memory_bytes: 2560
import java.util.*;
import java.io.*;
 
public class Main {
  public static void main(String[] args) {
	Scanner s = new Scanner(System.in);
	int N = s.nextInt();
	int[] div = new int[N+1];
	for(int i = 1; i <= N; i++){
		for(int j = i; j <= N; j=j+i){
			div[j]++;
		}
	}

	long sum = 0;
	for(int i = 1; i <= N; i++){
		sum += (long)i*(long)div[i];
	}

	System.out.println(sum);
    
  }
}

Measured memory_bytes: 75416
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <cmath>

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

constexpr ll LLINF {1001002003004005006};//ll = 9*LLINF
constexpr int INTINF {1000000000};//int = 2*INTINF

#define  rep(i,n)   for(int i = 0; i < (n); ++i)
#define rrep(i,n)   for(int i = 1; i <= (n); ++i)
#define drep(i,n)   for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for(int i = s; i < t;  ++i)

template<typename T>
void maxs(T& x, T&& y) {
  x=std::max(x,y);
}
template<typename T>
void maxs(T& x, T& y) {
  x=std::max(x,y);
}

template<typename T>
void mins(T& x, T&& y) {
  x=std::min(x,y);
}
template<typename T>
void mins(T& x, T& y) {
  x=std::min(x,y);
}

int get_S(const string& S, int idx) {
  int c = S[idx] - '0';
  c*=10;
  c += S[idx+1] - '0';
  c*=10;
  c += S[idx+2] - '0';
  return c;
}

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

  string S;
  cin >> S;
  int S_size = S.size();
  int mins_target {10000};
  rep (i, S_size-2) {
    mins(mins_target, std::abs(753-get_S(S, i)));
  }
  cout << mins_target << '\n';
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
	string s;
	int a=0,b=0;
	cin>>s;
	for(int i=0;i<s.size();i++){
		if(s[i]=='g'&&a)a--,b++;
		else if(s[i]=='g')a++;
		if(s[i]=='p'&&a)a--;
		else if(s[i]=='p')a++,b--;
	}
	cout<<b<<endl;
	return 0;
}


Measured memory_bytes: 512
N=int(input())
ls=list(map(int,input().split()))
ls.sort()

#定数倍のやつに＋１する
M=max(ls)
A=[0]*(M+1)
for i in range(len(ls)):
  a=1
  while ls[i]*a<=M:
    b=ls[i]*a
    if A[b]<=1:
      A[b]+=1
    a+=1
    
ans=0     
for i in range(len(ls)):
  if A[ls[i]]==1:
    ans+=1
print(ans)


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

void solve(std::string S)
{
    int ans = 0;
    for (int i = 0; i < S.size(); i++)
    {
        if (S[i] == '+')
        {
            ans++;
        }
        else
        {
            ans--;
        }
    }
    cout << ans << endl;
}

// Generated by 1.1.4 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()
{
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 256
A, V = map(int, input().split())
B, W = map(int, input().split())
T = int(input())

dist = abs(B - A)
relv = W - V
if relv == 0:
  print("NO")
elif relv < 0 and dist/abs(relv) <= T:
  print("YES")
else:
  print("NO")

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

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

  int n, l;
  cin >> n >> l;
  int s = (l * 2 + n - 1) * n / 2;
  if (l < -(n - 1)) s -= l + (n - 1);
  else if (l > 0) s -= l;
  cout << s << '\n';
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
#define re cin>>
#define pr cout<<
#define in(x) scanf("%d",&x)
#define inn(x,y) scanf("%d%d",&x,&y)
#define innn(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)

const int N=2e6+5;
const int mod=1e9+7;

double d;

int main(){
    re d;
    printf("%.8lf",pow(d/3,3));
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <queue>
#include <algorithm>
#include <string>
#include <utility>
#include <vector>
#include <map>
#include <stack>
#include <iomanip>
#include <set>
#include <sstream>
#include <cmath>
#include <deque>
#include <list>
#include <bitset>
using namespace  std;
typedef pair<long long , long long> P;
typedef long long ll;
typedef long long lint;
#define REP(i, n) for(long long (i)=0; (i)<(n); ++i)
#define FOR(i, a, b) for(long long (i)=(a); (i)<(b); ++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define FST first
#define SND second

signed main(){
    string s;
    cin >>s;
    int a, b;
    a = (s[0]-'0')*10 + (s[1]-'0');
    b = (s[2]-'0')*10 + (s[3]-'0');
    bool yymm = true;
    bool mmyy = true;
    if(0 >= a or a > 12) mmyy=false;
    if(0 >= b or b > 12) yymm=false;
    if(0 > a or a > 99) yymm = false;
    if(0 > b or b > 99) mmyy = false;

    if(yymm and mmyy) cout << "AMBIGUOUS" <<endl;
    else if(yymm) cout <<"YYMM" <<endl;
    else if(mmyy) cout <<"MMYY" <<endl;
    else cout << "NA" <<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const int nmax = 8;
bool graph[nmax][nmax];

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

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}
int dfs(int v, ll N, bool visited[nmax])
{
    bool all_visited = true;

    for (int i = 0; i < N; i++)
    {
        if (!visited[i])
        {
            all_visited = false;
        }
    }

    if (all_visited)
    {
        return 1;
    }
    int ret = 0;
    for (size_t i = 0; i < N; i++)
    {
        if (!graph[v][i])
        {
            continue;
        }
        if (visited[i])
        {
            continue;
        }

        visited[i] = true;
        ret += dfs(i, N, visited);
        visited[i] = false;
    }

    return ret;
}

void solve(long long W, long long H, long long N, std::vector<long long> x, std::vector<long long> y, std::vector<long long> a)
{
    ll x1 = 0, x2 = W, y1 = 0, y2 = H;

    for (int i = 0; i < N; i++)
    {
        switch (a[i])
        {
        case 1:
            x1 = max(x1, x[i]);
            break;
        case 2:
            x2 = min(x2, x[i]);
            break;
        case 3:
            y1 = max(y1, y[i]);
            break;
        case 4:
            y2 = min(y2, y[i]);
            break;
        }
    }

    if (x1 < x2 && y1 < y2)
    {
        cout << (x2 - x1) * (y2 - y1) << endl;
    }
    else
    {
        cout << 0 << endl;
    }
}

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


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  double a,ans;
  double tans = 0,hans = 0;
  cin >> a;
  tans = a;
  hans = a;
  while(cin>>a){
    if(tans>a) tans = a;
    if(hans<a) hans = a;
  }
  ans = hans - tans;
  cout << ans << endl;
  return 0;
}

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

// L(1~n)
// c< a+b
// (a+b)　以上の数
// b 以上の数

// ex) n= 4, L =1,2,3,4
// a = 1, b= 2
// lb(3) = 3
// lb(2) = 2

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    ll n;
    cin>>n;
    vector<ll> L(n+1, 0);
    for(int i =1; i<=n; i++){
        ll t;
        cin>>t;
        L[i] = t;
    }
    sort(L.begin(), L.end());
    ll ans = 0;
    for(ll a = 1; a<(n-1); a++){
        for(ll b = a+1; b<n; b++){
            ll lc = b;
            ll rc = lower_bound(L.begin(), L.end(), (L[a]+L[b]) ) - L.begin();
            ll bc = rc - lc -1 ;
            if(bc >0){ 
                ans += bc;
            }
        }
    }
    cout<< ans << endl;
    return 0;
}


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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    string s; 
    cin >> n >> s;
    int black = 0;
    int left_black[n];
    for(int i = 0; i < n; i++){
        if(s[i] == '#') black++;
        left_black[i] = black;
    }
    int ans = n - black;
    for(int i = 0; i < n; i++){
        int tmp = left_black[i] + (n-1-i) - (black - left_black[i]);
        ans = min(ans, tmp);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1300
#include <cstdio>
#include <bitset>

using namespace std;

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

  int a,b,c ;

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

  if(a+b==c){printf("%s\n","Yes");std::exit(0) ;}
  if(b+c==a){printf("%s\n","Yes");std::exit(0) ;}
  if(c+a==b){printf("%s\n","Yes");std::exit(0) ;}
  printf("%s\n","No") ;
}


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

int main () {
  int N , K ;
  cin >> N >> K ;
  int pre = 1 ;
  for(int i = 0 ; i < N ; i++){
    if(K>pre) pre *= 2 ;
    else pre += K ;
  }
  cout << pre << endl ;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

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

int main() {
  int n, k; cin >> n >> k;
  vector<ll> v(n);
  REP(i, n){
    cin >> v[i];
  }

  ll ans = 0;
  for(int i=0; i<=n; i++)for(int j=n; j>=0; j--){
    if(i > j || i + (n-j) > k) continue;

    vector<ll> pv, nv;
    for(int l=0; l<i; l++){
      if(v[l] >= 0)
        pv.push_back(v[l]);
      else
        nv.push_back(v[l]);
    }
    for(int l=n-1; l>=j; l--){
      if(v[l] >= 0)
        pv.push_back(v[l]);
      else
        nv.push_back(v[l]);
    }

    sort(nv.begin(), nv.end());
    
    ll tmp = 0;
    for(ll x : pv) tmp += x;
    for(ll x : nv) tmp += x;
    for(int l=0; l<k-i-(n-j) && l<nv.size(); l++) tmp -= nv[l];

    ans = max(ans, tmp);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
// C - Switches
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using ull = unsigned long long;

int main(){
    int n, m;
    cin >> n >> m;
    vector<vector<int>> s;
    vector<int> p(m);
    s.resize(m);
    int k;
    rep(i, m){
        cin >> k;
        s[i].resize(k);
        rep(j, k){
            cin >> s[i][j];
            s[i][j] -= 1;
        }
    }
    rep(i, m) cin >> p[i];
    int ans = 0;
    
    for(int bit=0; bit<(1<<n); bit++){
        bool flag = true;
        rep(i, m){
            int cnt = 0;
            for(auto e : s[i]){
                if(bit&(1<<e)) cnt++;
            }
            if(cnt%2 != p[i]) flag=false;
        }
        if(flag) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3624
export class Main {
  static main(input): string {
    const [one, two, ...list]: string[] = input.split("\n");
    const [n, m, c]: number[] = one.split(" ").map(Number);
    const bList: number[] = two.split(" ").map(Number);
    let count: number = 0;
    list.slice(0, n).forEach(line => {
      const aList: number[] = line.split(" ").map(Number);
      let sum: number = c;
      for (let i: number = 0; i < m; i++) {
        sum += aList[i] * bList[i];
      }
      if (sum > 0) {
        count++;
      }
    });
    return `${count}`;
  }
}
console.log(Main.main(require("fs").readFileSync("/dev/stdin", "utf8")));

Measured memory_bytes: 7500
use std::io::Read;
use std::cmp::Reverse;

fn main() {
  let mut buf = String::new();
  std::io::stdin().read_to_string(&mut buf).unwrap();
  let mut iter = buf.split_whitespace().map(|s| s.parse().unwrap());
  
  let n:usize = iter.next().unwrap() as usize;
  let mut S : Vec<(i64, i64)> = (0 .. n).map(|_|(iter.next().unwrap(), iter.next().unwrap())).collect();
  S.sort_by_key(|(a,b)| Reverse(a + b));
  
  let (_, sa, sb) = S.into_iter().fold((true, 0, 0), |(first, sa, sb), (a,b)|{
    if first {
      (!first, sa + a, sb)
    } else {
      (!first, sa, sb + b)
    }       
  });
  println!("{}", sa - sb);
}

Measured memory_bytes: 6076
#include <stdio.h>
#define MAX_N (999)

int any(char entry[MAX_N], int n) {
	int i;
	for (i = 0; i < n; i++) {
		if (entry[i])
			return 1;
	}
	return 0;
}

int main(void) {
	char entry[MAX_N];
	int n, m, i, index, count;

	while (1) {
		scanf("%d %d ", &n, &m);
		if (!(n || m))
			break;

		for (i = 0; i < n; i++)
			entry[i] = 1;
		for (; i < MAX_N; i++)
			entry[i] = 0;

		index = n - 1;
		while (any(entry, n)) {
			count = m;
			while (count) {
				index = (index+1) % n;
				if (entry[index])
					count--;
			}
			entry[index] = 0;
		}
		printf("%d\n", index+1);
	}
	return 0;
}

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

#define ll long long
const ll mod=1e9+7;

using namespace std;

set < char > arr;
map < char,ll> countt;


int main()
{
    ll i,j,k,l,m,n;
    cin >> n;
    string s;
    cin >> s;
    for(i=0;i<n;i++)
    {
        arr.insert(s[i]);
        countt[s[i]]++;
    }
    ll ans=1;
    for(auto it:arr)
    {
        ans= ((ans%mod)*((countt[it]+1)%mod))%mod;
    }
    cout << ans-1 << endl;
}


Measured memory_bytes: 512
/****************************
/////  Shubham Singhal
/////  LNMIIT
*****************************/
#include <bits/stdc++.h>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define eb emplace_back
#define lwr lower_bound
#define upr upper_bound
#define pq priority_queue
#define umap unordered_map
#define rep(i,n) for(i=0; i<n;i++)
#define repp(i,a,n) for(i=a; i<n;i++)
#define precise(x) cout<<fixed<<setprecision(x)
#define all(x) x.begin(),x.end()
#define lcm(a,b) (a*b)/__gcd(a,b)
#define prn(x) cout<<x<<"\n"
#define prn2(x, y) cout<<x<<" "<<y<<"\n"
#define prn3(x, y, z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define prn4(x, y, z, a) cout<<x<<" "<<y<<" "<<z<<" "<<a<<"\n"
#define prnv(x) for(auto i:x) cout<<i<<" "; cout<<"\n"
#define MOD 1000000007

using namespace std;
 
typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd; 
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<pil> vpil;
typedef vector<pli> vpli;
typedef vector<pll> vpll;
const long long INF64 = 1'000'000'000'000'000'000ll;
clock_t time_p=clock();
void time()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
void doc()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
}
void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
}
int main()
{
    fast();
    ll a,b,k;
    cin>>a>>b>>k;
    if(a>=k)
    {
        cout<<a-k<<" "<<b;
    }
    else
    {
        cout<<0<<" "<<max(0LL,a+b-k);
    }
}

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

#include <queue> //C++
#include <string> //C++
#include <iostream> //C++
#include <vector> //C++
#include <algorithm> //C++
using namespace std; //C++




int main()
{
	int x, y, i=1;

	cin >> x >> y;
	
	if (x % y == 0) cout << "-1";

	else cout << x;	
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=500500;
int n,m;
int a[maxn];
int f[52][52][102],vis[52][52][102];
int dfs(int L,int R,int K)
{
    if(K==0){
        vis[L][R][K]=1;
        return f[L][R][K]=0;
    }
    if(L>R)return 0;
    if(L==R)
    {
       if(K>=1)
            f[L][R][K]=max(f[L][R][K],max(a[L],0));
        vis[L][R][K]=1;
        return f[L][R][K];
    }
    if(vis[L][R][K]||f[L][R][K]!=0)return f[L][R][K];
    int ans=max(dfs(L+1,R,K-1)+a[L],dfs(L,R-1,K-1)+a[R]);
    if(K>=2)ans=max(ans,max(dfs(L+1,R,K-2),dfs(L,R-1,K-2)));
    f[L][R][K]=max(f[L][R][K],ans);
    vis[L][R][K]=1;
    return f[L][R][K];
    
}
int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++)scanf("%d",&a[i]);
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
            for(int k=1;k<=m;k++)
                f[i][j][k]=0;
    printf("%d\n",dfs(1,n,m));
    return 0;
}
/*
10 10
-1 -1 -1 -1 -1 -1 -1 -1 -1 -1

50 100
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
*/


Measured memory_bytes: 3968
#include <stdio.h>
int main(){
  int a,b = 0;
  scanf("%d",&a);
  scanf("%d",&b);
  char c[a+1];
  for(int i=0;i<a;i++){
  scanf("%s",&c[i]);
  }
  c[b-1] = c[b-1] + 0x20;
  printf("%s",c);
  return 0;
}

Measured memory_bytes: 128
n, k = map(int, input().split())
a = list(map(int, input().split()))
f = list(map(int, input().split()))

a.sort()
f.sort(reverse = True)

left = -1
right = 10**18+1


while right - left > 1:
    mid = left + (right - left) // 2


    train = k
    for i in range(n):
        req = mid // f[i]
        if req < a[i]:
            train -= a[i] - req


    if train >= 0:
        right = mid
    else:
        left = mid



print(right)


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

int main(){
  string s,t;
  cin>>s>>t;
  int ans=0;
  
  for(int i=0;i<s.size();i++){
    if(s.at(i)!=t.at(i)){ans++;}
  }
  
  cout<<ans;
}

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

using namespace std;

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


Measured memory_bytes: 384
program sample
    implicit none
    character(100)::s,t
    integer(8) :: i,j,k,m,n
    integer(8)::a,b,c,d
    integer(8),allocatable::x(:),y(:)
  
    read(*,*) a
    if(mod(a,2)==0)then
        write(*,*)(a/2)**2
    else
        write(*,*)a/2*(a/2+1)
    endif
    stop
end program sample
  



Measured memory_bytes: 2804
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#include <bits/stdc++.h>
using namespace std;
 
const double TL = 1.5 * CLOCKS_PER_SEC;
mt19937 rng((unsigned int) chrono::steady_clock::now().time_since_epoch().count());
#define clr(x, y) memset(x, y, sizeof(x))
#define forn(i, n) for (int i = 0; i < n; i++)
#define LL long long
const double pi = acos(-1.0);


int n;
const LL mod = 1e9 + 7;
pair<int, int> p[200005];

int main() {
#ifdef LOCAL
  auto start_clock = clock();
  freopen("in", "r", stdin);
#endif

  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d%d", &p[i].first, &p[i].second);
  }
  sort(p, p + n);

  LL a = -2e9, b = -2e9, ans = -2e9;

  for (int i = 0; i < n; i++) {
    ans = max(ans, p[i].first + p[i].second + a); 
    ans = max(ans, p[i].first - p[i].second + b); 
    a = max(a, (LL)-p[i].first - p[i].second);
    b = max(b, (LL)-p[i].first + p[i].second);
  }
  cout << ans << endl;
  
 
#ifdef LOCAL
 auto end_clock = clock();
 cout << "Time:" << (end_clock - start_clock) * 1.0 / CLOCKS_PER_SEC << endl;
#endif
  return 0;
}

Measured memory_bytes: 5188
#include <iostream>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;

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

int main() {
    int N;
    cin >> N;
    vector<int> vec(N);
    for (int i = 0; i < N; i++) {
        cin >> vec.at(i);
    }
    sort(vec.begin(), vec.end());
    int sum = 0;
    for (int i = 0; i < N-1; i++) {
        sum += vec.at(i);
    }
    cout << sum + (vec.at(N-1)) / 2 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef pair<int, int> P;
const int MAX_F = 4;
const int INF = 1e9;
#define y first
#define x second

int main() {
  int N, F[MAX_F], ans = INF;
  P FS[MAX_F];
  cin >>N;
  REP(i, MAX_F){
    cin >>F[i];
    --F[i];
  }
  FOR(h, 1, N + 1){
    int w = N - h + 1;
    REP(y, h){
      REP(x, w){
        int c = y * w + x;
        REP(i, MAX_F) if(c == F[i]) FS[i] = P(y, x);
      }
    }
    int cnt = 0;
    for(int i = 0; i + 1 < MAX_F; i += 2) cnt += abs(FS[i + 1].x - FS[i].x) + abs(FS[i + 1].y - FS[i].y);
    ans = min(ans, cnt);
  }
  cout <<ans <<endl;
  return 0;
}

Measured memory_bytes: 1160
// agrawal117
//chahat agarwal
#include<bits/stdc++.h>  
#define mod 1000000007
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long int ll;
int main()
{
    ll n;
    cin>>n;
    ll val=1000000000;
    ll a=n/val;
    if(n%val!=0) a++;
    ll b=(val*a)-n;
    cout<<"0 0 1000000000 1 "<<b<<" "<<a<<endl;
    
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, int> pdi;

ll twoPow[100005];
const int MOD = 1000000007;
void solve() {
  twoPow[0] = 1;
  string s;
  cin >> s;
  for(int i = 1; i <= s.size(); i++) {
    twoPow[i] = twoPow[i-1] * 3;
    twoPow[i] %= MOD;
  }
  ll ret = 0;
  ll curr = 1;
  for(int i = 0; i < s.size(); i++) {
    if(s[i] == '1') {
      // both zeros
      ll inc = twoPow[s.size()-1-i];
      inc *= curr;
      inc %= MOD;
      ret += inc;
      ret %= MOD;
      curr *= 2;
      curr %= MOD;
    }
  }
  ret += curr;
  ret %= MOD;
  cout << ret%MOD << endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  solve();
  /*
  int t;
  cin >> t;
  for(int i = 1; i <= t; i++) {
    cout << "Case #" << i << ": ";
    solve();
  }
  */
}


Measured memory_bytes: 1232
//c++ -std=gnu++14 a.cpp
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <climits>
#include <fstream>
#include <random>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
//typedef pair<ll, ll> P;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define revrep(i, n) for(int i = (n)-1; i >= 0; i--)
#define pb push_back
#define f first
#define s second
#define chmin(x, y) x = min(x, y);
#define chmax(x, y) x = max(x, y);
#define sz(x) ((int)(x).size())

//const ll INFL = LLONG_MAX;//10^18 = 2^60
const ll INFL = 1LL<<60;
//const int INF = INT_MAX;
const int INF = 1 << 30;//10^9
const ll MOD = 1000000007;
//const ll MOD = 998244353;
double EPS = 1e-10;

vector<ll> dy = {0, 1, 0, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, 0, -1, 0, 1, -1, 1, -1, 0};

void pres(double A){printf("%.9lf\n", A);}
void BinarySay(ll x, ll y = 60){rep(i, y) cout << (x>>(y-1-i) & 1); cout << endl;}
ll cnt_bit(ll x){return __builtin_popcountll(x);}

ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x; k /= 2;
  }
  return res;
}

ll pow_mod(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}

ll inverse(ll x){return pow_mod(x, MOD - 2);};

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

ll lcm(ll x, ll y){
  ll res = x / gcd(x, y);
  res *= y;
  return res;
};


//コンビネーション
const int MAXcomb = 2000010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAXcomb; 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;
    }
}
ll comb(int n, int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * finv[k] % MOD * finv[n-k] % MOD;
}

const int MAXkai = 200010;
ll kai_memo[MAXkai];
ll kai(ll N){
  if(kai_memo[N] != 0) return kai_memo[N];
  if(N <= 1) return 1;
  return kai_memo[N] = N * kai(N-1) % MOD;
}

ll disit(ll s, ll base = 10){
  ll res = 0;
  while(s){
    res++;
    s /= base;
  }
  return res;
}


int N;
int A[200010], B[200010];

void solve(){
  cin >> N;
  rep(i, N) cin >> A[i] >> B[i];

  sort(A, A+N);
  sort(B, B+N);
  if(N % 2){
    cout << B[N/2] - A[N/2] + 1 << endl;
  }else{
    cout << (B[N/2] + B[N/2-1] - A[N/2] - A[N/2-1]) + 1 << endl;
  }
}

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


Measured memory_bytes: 5220
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
public class Main {
     
    public static void main(String[] args) {
        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
            String str = reader.readLine();
            double S = Double.parseDouble(str);
            int h = (int)Math.floor(S / 3600);
            int m = (int)Math.floor((S % 3600) / 60);
            int s = (int)Math.floor((S % 3600) % 60);
            System.out.println(h + ":" + m + ":" + s);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
 
}

Measured memory_bytes: 24388
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main(){
    ll n, k;
    cin >> n >> k;
    ll d = n / k;
    ll d2 = 0;
    ll num = k / 2;
    if ( !(k&1) ) {
        while(1) {
            if ( num > n ) break;
            num += k;
            ++d2;
        }
    }
    cout << d * d * d + d2 * d2 * d2 << endl;
    return 0;
}


Measured memory_bytes: 256
use proconio::input;

#[proconio::fastout]
fn main() {
    input! {
        n: usize,
        a: [usize; n-1],
    }
    let mut hm = std::collections::HashMap::new();
    for &a in a.iter() {
        if let Some(num) = hm.get_mut(&a) {
            *num += 1;
        } else {
            hm.insert(a, 1);
        }
    }

    for i in 1..n + 1 {
        if let Some(num) = hm.get(&i) {
            println!("{}", num);
        } else {
            println!("{}", 0);
        }
    }
}


Measured memory_bytes: 11504
import java.util.*;
public class Main {
	public static void main(String[] args){
 
        Scanner sc = null;
        sc = new Scanner(System.in);
        int n = sc.nextInt();
        sc.close();
        if (n >= 30) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }    
      }
}

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

int main() {
  string s;
  cin>>s;
  if(s.at(0)==s.at(1)
     ||s.at(1)==s.at(2)
     ||s.at(2)==s.at(3)){
    cout<<"Bad";
  }
  else{cout<<"Good";}
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
 
using namespace std;
 
int main()
{
    int n,m;
    map<string,int>ss;
    string blue,red;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>blue;
        ss[blue]++;
    }
    cin>>m;
    for(int j=0;j<m;j++){
        cin>>red;
        ss[red]--;
    }
    int res=0;
 
    map<string,int>:: iterator itr;
    for(itr=ss.begin();itr!=ss.end();itr++){
            res=max(res,itr->second);
    }
    cout<<res;
 
    return 0;
}

Measured memory_bytes: 3584
# after listening explanation
n = gets.to_i
s = gets.chomp.chars.map{|c| c.ord%3 }
ans = s.count(0) * s.count(1) * s.count(2)
n.times{|j| j.times{|i|
  k = 2*j - i
  ans -= 1 if k<n && s[i]!=s[j] && s[j]!=s[k] && s[k]!=s[i]
} }
p ans


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

int main(){
  int n; string s; cin >> n >> s;
  int reg=0, ans=0;
  for(int i=0; i<n; i++){
    if(s[i]=='I') reg++;
    else if(s[i]=='D') reg--;
    ans=max(ans,reg);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256