akhauriyash/Code-Regression huggingface dataset:
/*
    ____        __
   / __ \____  / /_  ____ _____ ___
  / /_/ / __ \/ __ \/ __ `/ __ `__ \
 / _, _/ /_/ / / / / /_/ / / / / / /
/_/ |_|\____/_/ /_/\__,_/_/ /_/ /_/
*/
#include<bits/stdc++.h>

typedef long long ll ;

#define X   first
#define Y   second
#define mp  make_pair
#define pii pair<int , int>
#define vec vector
#define vpii vector<pair<int , int>>
#define i_n   int i = 0 ; i< n ; i++
#define cn  int n ; cin>>n
#define file_io freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define cina int a[n] ; for(int i = 0 ; i < n ; i++) cin>>a[i]
#define pb push_back
#define SZ(x) ll(x.size())

using namespace std;
const int maxn = 1000*100+5 ;

int main()
{
	migmig ;int a , b ; 
	cin>>a>>b ; 
	if(a+b <= 16 && a < 9 && b < 9) cout<<"Yay!" ; 
	else cout<<":(" ; 

}
//////
////////
///////////



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

void Main() {
    // input
    int A, B, C, D;
    cin >> A >> B >> C >> D;


    // translate
    while (true) {
        C -= B;
        if (C <= 0) {
            cout << "Yes" << endl;
            break;
        }

        A -= D;
        if (A <= 0) {
            cout << "No" << endl;
            break;
        }
    }


    // output

}

int main() {
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


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

double pi = 3.14159265358979;

signed main(){
    ios::sync_with_stdio(false);
	cin.tie(0);
    cout << fixed << setprecision(20);

    int n;
    double eps = 1e-6;
    double b = 2*pi/3000;
    while(cin>>n){
        if(n==0) break;
        double x[n],y[n];
        for(int i=0;i<n;i++){
            cin>>x[i]>>y[i];
        }
        int ans = 0;
        for(int i=0;i<n;i++){
            int ret = 0;
            for(int j=0;j<n;j++){
                double d = (x[i] - x[j]) * (x[i] - x[j]);
               d += (y[i] - y[j]) * (y[i]-y[j]);
                if(d <= 1.0) ret++;
            }
            ans = max(ans,ret);
        }
        //cerr << " a " << ans << endl;
        for(int i=0;i<n;i++){
            for(int cnt=0;cnt<3000;cnt++){
                double theta = b*cnt;
                double ox = x[i] + cos(theta);
                double oy = y[i] + sin(theta);
                int ret = 0;
                for(int j=0;j<n;j++){
                    double d = (ox - x[j]) * (ox - x[j]);
                    d += (oy - y[j]) * (oy - y[j]);
                    if(d <= 1.0 + eps) ret++;
                }
                ans = max(ans,ret);
            }
        }
        cout << ans << "\n";
    }
}


Measured memory_bytes: 3408
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.NoSuchElementException;
import java.util.Set;

public class Main {
	public static void main(String args[]) throws IOException {
		FastScanner fs = new FastScanner();
		String hitachiStr = fs.next();
		String res = hitachiStr.replaceAll("hi", "");
		if("".equals(res)) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
}
}



class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}



Measured memory_bytes: 22996
#include<bits/stdc++.h>                                                                                               
using namespace std;
 
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define int long long
#define mk_p(a,b)   make_pair((a),(b))
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;

int gcd(int a,int b){return b ? gcd(b,a%b) : a;} 
int lcm(int a,int b){return a/gcd(a,b)*b;}

signed main(){
    int n;
    cin >> n;; 
    cout << lcm(2,n) << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {
  int A, B;
  cin >> A >> B;
  if(B == 1)
    cout << 0 << endl;
  else
    cout << 1 + int(ceil(1.0 * max(0, B-A) / (A-1))) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <atcoder/all>
#define rep(i, n) for (int i=0; i < (n); i++)
using namespace std;
//using namespace atcoder;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> P;
const int INF = 1 << 30;
const ll LINF = 1LL << 61;
const int NIL = -1;
const int MAX = 10000;
const int MOD = 1000000007;
const double pi = 3.141592653589;

int main() {
    ll n;
    cin >> n;
    ll lcm;
    lcm = 2 / gcd(2, n) * n;
    cout << lcm << endl;
    return 0;
}

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


int main(){
  int cnt;
  int t[100002], x[100002], y[100002];
  scanf("%d", &cnt);
  int i;
  t[0]=x[0]=y[0]=0; 
  for(i=1; i<=cnt; i++){
    scanf("%d %d %d", &t[i], &x[i], &y[i]);
  }
  
  for(i=1; i<=cnt; i++){
    int dist_x = abs(x[i-1]-x[i]);
    int dist_y = abs(y[i-1]-y[i]);
    int dist=dist_x+dist_y;
    
    int time = t[i]-t[i-1];
    if( time < dist ) {
      printf("No\n");
      return 0;
    }else if( ((time-dist)%2) != 0){
      printf("No\n");
      return 0;
    }
  }
  printf("Yes\n");  
  return 0;
}


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

int main(){
    int n,q,count=0;
    
    cin>>n;
    int a[n+1];
    for(int i=0;i<n;i++)cin>>a[i];
    cin>>q;
    int b[q];
    for(int i=0;i<q;i++)cin>>b[i];
    for(int i=0;i<q;i++){
        int j=0;
        a[n]= b[i];
        while(a[j]!=b[i]){
            j++;
        }
        if(j!=n){
            count++;
        }
    }
    cout<<count<<endl;
    return 0;
}


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

int h[500];
int main(){
    int n, k;
    cin >> n >> k;
    int res =0; 
    for(int i=0; i<n; ++i){
        int hi;
        cin >> hi;
        if(hi >= k){
            res++;
        }
    }
    cout << res;

}


Measured memory_bytes: 256
//shan61916
#include <bits/stdc++.h>
  using namespace std;
typedef   long long ll;
typedef   unsigned long long ull ;
typedef   double dll ;

#define   mp make_pair
#define   pb push_back
#define   ff first 
#define   ss second
#define   IOS ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define   endl "\n" 
#define   pll pair<ll, ll>
#define   all(x) x.begin(), x.end()
#define   vll vector<ll> 

const ll inf = (ll)(1e17 + 17);
const ll mod = (ll)(1e9 + 7);


int main(){
 IOS
#ifdef SHAN
    freopen("input.txt" , "r" , stdin);  
#endif
  ll n, m;
  cin >> n >> m;
  vll a(n);
  ll tot = 0;
  for(ll i = 0; i < n; i++) {
  	cin >> a[i];
  	tot+=a[i];
  }
  sort(all(a), greater<ll>());
  bool foo = true;
  ll tocomp = (tot + 4*m - 1)/(4*m);
  for(ll i = 0; i < m; i++) {
  	if(a[i] < tocomp) foo = false;
  }
  foo ? cout << "Yes" : cout << "No";
  return 0;
} //good night.

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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int result = 0;
		int N = sc.nextInt();
		HashMap<String,Integer> map = new HashMap<String,Integer>();
		for(int i = 0; i < N; i++) {
			String s = sc.next();
			if(map.containsKey(s)) {
				int num = map.get(s) +1;
				map.replace(s, num);
			}else {
				map.put(s, 1);
			}
		}

		int M = sc.nextInt();
		for(int i = 0; i < M; i++) {
			String t = sc.next();
			if(map.containsKey(t)) {
				int num = map.get(t) -1;
				map.replace(t, num);
			}
		}

		for(int num : map.values()) {
			result = Math.max(result, num);
		}

		System.out.println(result);
	}
}


Measured memory_bytes: 22228
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    int n;
    cin >> n;
    bool ok=true;
    vi h(n);
    rp(i,n){
        cin >> h.at(i);
        if(i==0){
            h[0]--;
            continue;
        }
        if(h.at(i)>h.at(i-1)){
            h[i]--;
            continue;
        }
        if(h.at(i)==h.at(i-1)){
            continue;
        }
        if(h.at(i)<h.at(i-1)){
            ok=false;
            break;
        }
    }
    Yes(ok);
    return 0;
}

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

#define pb push_back
#define fst first
#define snd second
#define fill(a,c) memset(&a, c, sizeof(a))
#define fore(i,x,y) for(ll i=x;i<y;i++)
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)

typedef long long ll;
typedef unsigned long long ull;

using namespace std;

int main() {FIN;
    

    string al,bo,ch;cin>>al>>bo>>ch;
    string arr[3] = {al,bo,ch};
    int curr =0;
    while(1){
        if(arr[curr].empty())
            break;
       char act = arr[curr][0];
        arr[curr].erase(arr[curr].begin()+0);
        if(act=='a')curr=0;
        else if(act=='b')curr=1;
        else curr = 2;
    }

    if(curr==0)cout<<"A\n";
        else  if(curr==1)cout<<"B\n";
        else cout<<"C\n";
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <string>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int N;
    cin >> N;
    VEC(int) H(N);
    READVEC(H);

    int ret = 1;
    FOR(i, 1, N)
        if (H[i] >= *max_element(BEGIN(H), BEGIN(H) + i))
            ret++;

    cout << ret << endl;
    return 0;
};


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

const int N = 2e5 + 100;

int n, k, h[N][4];
long long dp[N][4];

int main(){
    # ifdef FILEs
        freopen( "input.txt", "r" ,stdin );
        freopen( "output.txt", "w", stdout );
    # endif
    ios_base::sync_with_stdio(false);
    cin >> n;
    for( int i = 1; i <= n;  i++ ){
        cin >> h[i][1] >> h[i][2] >> h[i][3];
    }
    for( int i = 2; i <= n; i ++ ){
        h[i][1] += max( h[i-1][2], h[i-1][3] );
        h[i][2] += max( h[i-1][1], h[i-1][3] );
        h[i][3] += max( h[i-1][2], h[i-1][1] );     
    }
    cout << max({h[n][1], h[n][2],h[n][3]});
    return 0;
}   

Measured memory_bytes: 2432
import math

n,d = map(int,input().split())
cnt = 0
x = [[int(i) for i in input().split()] for i in range(n)]

for i in range(n):
  for j in range(i+1,n):
    nakami = 0
    for k in range(d):
      nakami += (x[i][k] - x[j][k])*(x[i][k] - x[j][k])
    tmp = math.sqrt(nakami)
    if tmp%1 == 0:
      cnt += 1
print(cnt)

Measured memory_bytes: 3064
n = int(input())
s = input()
dist = 0
mlow = 0
for i in s:
    if i == ")":
        dist -= 1
        if dist < mlow:
            mlow = dist
    else:
        dist += 1

left = "("*(-mlow)
right = ")"*(dist-mlow)
print(left+s+right)


Measured memory_bytes: 2940
#include<iostream>
using namespace std;
int main()
{
  long h;
  cin>>h;
  long n=1,s=0;
  for(;h!=1;)
  {
    s+=n;
    n*=2;
    
      h/=2;
    
  }
  cout<<(s+(n));
  return 0;
}

Measured memory_bytes: 256
import sys
import math
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7

def main():
    N = int(input())
    ans = math.factorial(N)%MOD
    print(ans)



if __name__ == '__main__':
    main()

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

public class Main {
    static StringBuilder sb;

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

        int n = sc.nextInt();
        TreeSet<Integer> a = new TreeSet<>();
        for (int i = 0; i < n; i++) {
            a.add(sc.nextInt());
        }

        int m = sc.nextInt();
        for (int i = 0; i < m; i++) {
            int tmp = sc.nextInt();
            if (a.contains(tmp)) a.remove(tmp);
            else a.add(tmp);
        }

        Iterator<Integer> it = a.iterator();
        while (it.hasNext()) {
            sb.append(it.next()).append("\n");
        }

        PrintWriter out = new PrintWriter(System.out);
        out.print(sb);
        out.flush();
        
        sc.close();
    }
}



Measured memory_bytes: 195360
def solve():
    N = int(input())
    A = list(map(int, input().split()))
    ans = 0
    while True:
        for i in range(N):
            if A[i] % 2 != 0:
                return ans // N
            A[i] //= 2
            ans += 1

    return ans

print(solve())


Measured memory_bytes: 3060
function Main(input) {
  var tmp = input.trim().split("\n");
  var XYZK = tmp[0].split(/\s/).map(val => Number(val));
  var X = XYZK[0];
  var Y = XYZK[1];
  var Z = XYZK[2];
  var K = XYZK[3];
  var AAry = tmp[1].split(/\s/).map(val => Number(val));
  var BAry = tmp[2].split(/\s/).map(val => Number(val));
  var CAry = tmp[3].split(/\s/).map(val => Number(val));

  AAry.sort((a, b) => b - a);
  BAry.sort((a, b) => b - a);
  CAry.sort((a, b) => b - a);

  var ABSumAry = [];
  var ABCSumAry = [];

  for (var i = 0; i < X; i++) {
    for (var j = 0; j < Y; j++) {
      ABSumAry.push(AAry[i] + BAry[j]);
    }
  }

  ABSumAry.sort((a, b) => b - a);

  for (var k = 0; k < Math.min(K, ABSumAry.length); k++) {
    for (var l = 0; l < Z; l++) {
      if (Math.min(K, ABSumAry.length) < k * l) continue;
      ABCSumAry.push(ABSumAry[k] + CAry[l]);
    }
  }
  ABCSumAry.sort((a, b) => b - a);

  for (var m = 0; m < K; m++) {
    console.log(ABCSumAry[m]);
  }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

namespace NSPGY001
{
    class B
    {
        static void Main(string[] args)
        {
            long[] input = Console.ReadLine().Split().Select(long.Parse).ToArray();
            long N = input[0];
            long K = input[1];
            int[] A = Console.ReadLine().Split().Select(int.Parse).ToArray();

            long mod = 1000000000 + 7;

            long res = 0;
            for (int i = 0; i < N - 1; i++)
            {
                for (int j = i + 1; j < N; j++)
                {
                    if (A[i] > A[j]) res++;
                }
            }

            long res2 = 0;
            for (int i = 0; i < N; i++)
            {
                for (int j = 0; j < N; j++)
                {
                    if (A[i] > A[j]) res2++;
                }
            }

            long ans = 0;
            long c = K * (K - 1) / 2 % mod;
            ans = (res * K % mod + res2 * c % mod) % mod;
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13396
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
#include <iomanip>
//cout << fixed << setprecision(20) << *** << endl;
#define rep(i,N) for(int i=0;i<(int)N;++i)
typedef long long ll;
using namespace std;
int main()
{
	ll H,W,ANS=0,F=0;
	char Ch='A';
	cin>>H>>W;
	rep(i,H){
		rep(j,W){
			//cout<<Ch<<j+1<<endl;
			string s;
			cin>>s;
			if(s=="snuke"){
				ANS=i+1;
				F=1;
				break;
			}
			Ch++;
		}
		if(F==1)break;
		Ch='A';
	}
	cout<<Ch<<ANS<<endl;
}

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

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = 1LL << 60;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
	ll n, a, cnt;
	ll ans = 0;

	cin >> n;

	REP(i, n) {
		cin >> a;

		cnt = 0;

		while (true) {
			if (a == 0 || a % 2 == 1) {
				break;
			}
			cnt++;
			a /= 2;
		}

		ans += cnt;
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll ZERO = 0;
const int Inf = 1000000000;
const ll INF= 1e18;
const ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<ll,ll> P;

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

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main(){
    int n;// 最初のスライムの数
    cin >> n;
    string slime;
    cin >> slime;
    int population = 0;
    for(int i=0;i<slime.size();){
        population++;
        int j=i+1;
        for(;j<slime.size() && slime[i]==slime[j];j++);
        i = j;
    }
    cout << population << endl;
    return 0;
}

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

typedef struct{
  int to;
  int cap;
  int rev;
}EDGE;

int INF = (1 << 21);
vector<EDGE> Edge[10000];

int maxFlow(int s, int t);
int dfs(int v, int t, int f);
void edgeAdd(int from, int to, int cap);

bool used[10000];

int main(){
  int v, e;
  cin >> v >> e;
  for(int i = 0; i < e; i++){
    int u, v, c;
    cin >> u >> v >> c;
    edgeAdd(u, v, c);
  }
  cout << maxFlow(0, v - 1) << endl;
}

void edgeAdd(int from, int to, int cap){
  Edge[from].push_back((EDGE){to, cap, Edge[to].size()});
  Edge[to].push_back((EDGE){from, 0, Edge[from].size() - 1});
}

int maxFlow(int s, int t){
  int flow = 0;
  while(1){
    memset(used, 0, sizeof(used));
    int f = dfs(s, t, INF);
    if(f == 0) return flow;
    flow += f;
  }
}

int dfs(int v, int t, int f){
  if(v == t) return f;
  used[v] = true;
  for(int i = 0; i < Edge[v].size(); i++){
    EDGE &e = Edge[v][i];
    if(!used[e.to] && e.cap > 0){
      int d = dfs(e.to, t, min(f, e.cap));
      if(d > 0){
	e.cap -= d;
	Edge[e.to][e.rev].cap += d;
	return d;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 1512
#pragma region include
#include "bits/stdc++.h"
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = (int)(n); i >= 0; i--)
#define FOR(i,n,m) for(int i = (int)(n); i < int(m); i++)
#define MOD (int)(1e9+7)
#define INF (int)(1e9)
#define LLINF (int)(4e18)
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
void input() {}
template<typename... R> void input(int& f, R&... r) { scanf("%d", &f); input(r...); }
template<typename... R> void input(double& f, R&... r) { scanf("%lf", &f); input(r...); }
template<typename... R> void input(ll& f, R&... r) { scanf("%lld", &f); input(r...); }
template<typename... R> void input(char& f, R&... r) { scanf("%c", &f); input(r...); }
template<typename... R> void input(string& f, R&... r) { cin >> f; input(r...); }
template<typename T, typename... R> void input(vector<T>& f, R&... r) { REP(i, f.size())input(f[i]); input(r...); }
#pragma endregion

ll N, A, B;
vector<ll> h;

bool f(int k) {
    vector<ll> a = h;
    ll cnt = 0;
    REP(i, N) {
        a[i] -= B * k;
        if (a[i] > 0) {
            cnt += (a[i] + (A - B - 1)) / (A - B);  
        }
    }
    return cnt <= k;
}

int main() {
    input(N,A,B);
    h.resize(N); input(h);
    int l = 0, r = INF;
    while (r - l > 1) {
        int k = (l - r) / 2 + r;
        if (f(k)) {
            r = k;
        }
        else {
            l = k;
        }
    }
    cout << r << endl;
    getchar(); getchar();
}

Measured memory_bytes: 1792
#include<iostream>
#include<string>
using namespace std;
int main()
{
	int K;
	string s;
	cin>>K>>s;
int n=s.length();
if(n<=K)
{
	cout<<s;
}
else
{
	string r=s.substr(0,K);
	string app="...";
	r.append(app);
	cout<<r;
}
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,k,cnt=0;
  cin>>a>>b>>k;
  for(int i=100;i>=1;i--){
    if(a%i==0&&b%i==0){cnt++;
      if(cnt==k){cout<<i<<endl;
                 return 0;
                }
                      }
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N,X,c=1,d=0,a;cin>>N>>X;
  for(int i=0;i<N;i++){
    cin>>a;d+=a;
    if(d>X)break;
    c++;
  }
  cout<<c<<endl;
}

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

int main() {
	int N;
	cin >> N;
	vector<int> vec(N);
	for (int i = 0; i < N; i++) {
		cin >> vec.at(i);
	}
	sort(vec.begin(), vec.end());
	reverse(vec.begin(), vec.end());

	int result = 0;
	int s = 1;
	for (int i = 0; i < N; i++) {
		result += vec.at(i) * s;
		s *= -1;
	}

	cout << result << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
 int n,i,a[1009],sum=0,k;

  cin>>n>>k;
  for(i=0; i<n; i++)
  {
      cin>>a[i];
  }
  sort(a,a+n);
 for(i=0; i<k; i++)
 {
     sum=sum+a[i];
 }
 cout<<sum;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  vector<string> w={"Sunny","Cloudy","Rainy","Sunny"};
  for(int i=0;i<3;i++)
    if(s==w.at(i))
      cout<<w.at(i+1)<<endl;
}

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

struct point{
    int x,y,cnt;
};

char maze[60][60]={0};
int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};
int checked[60][60] = {0};

int main(){
    int w,h;
    while(scanf("%d %d",&w,&h),w!=0||h!=0){
        for(int i=0;i<2*h-1;++i){
            for(int j=0;j<2*w-1;++j){
                checked[i][j] = INT_MAX;
                maze[i][j] = 0;
            }
        }
        maze[0][0] = 'S';
        maze[2*(h-1)][2*(w-1)] = 'G';

        for(int i=0;i<2*h-1;++i){
            if((i&1) == 0){
                for(int j=0;j<w-1;++j){
                    int c;
                    scanf(" %d",&c);
                    if(c == 1)maze[i][2*j+1] = '#';
                }
            }else{
                for(int j=0;j<w;++j){
                    int c;
                    scanf("%d ",&c);
                    if(c == 1)maze[i][2*j] = '#';
                }
            }
        }

        queue<point> que;
        checked[0][0] = 0;
        que.push((point){0,0,1});
        bool flag = false;
        while(!que.empty()){
            point now = que.front(); que.pop();
            if(maze[now.y][now.x] == 'G'){
                printf("%d\n",now.cnt);
                flag = true;
                break;
            }
            for(int i=0;i<4;++i){
                if(now.x+dx[i]*2 >= 0 && now.x+dx[i]*2 < 2*w-1 && now.y+dy[i]*2 >= 0 && now.y+dy[i]*2 < 2*h-1 \
                    && maze[now.y+dy[i]][now.x+dx[i]] != '#'){
                    if(now.cnt+1 < checked[now.y+dy[i]*2][now.x+dx[i]*2]){
                        que.push((point){now.x+dx[i]*2,now.y+dy[i]*2,now.cnt+1});
                        checked[now.y+dy[i]*2][now.x+dx[i]*2] = now.cnt + 1;
                    }
                }
            }
        }
        if(!flag)printf("0\n");
    }

    return 0;
}

Measured memory_bytes: 3152
N = int(input())

Bs = []
Bs = list(map(int,input().split()))
tBs = []
for i,b in enumerate(Bs):
	tBs.append((b,i))
tBs = sorted(tBs,reverse=True)

As = [0 for _ in range(N)]

for tb in tBs:
	i = tb[1]
	As[i] = tb[0]
	As[i+1] = tb[0]

#print(N,As,tBs)
print(sum(As))

Measured memory_bytes: 38384
import java.util.Scanner;

/**
 * ZAKIREN第5章
 *
 * @author K.Yamauchi
 *
 */
public class Main {

	/**
	 *
	 * @param args
	 */
	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in); // 入力
		int n = Integer.parseInt(scan.nextLine()); // 要素数

		// ソート対象配列の読み込み
		String[] targetArrayStr = scan.nextLine().split(" ");
		int[] targetArray = new int[targetArrayStr.length];
		for (int i = 0; i < targetArrayStr.length; i++) {
			targetArray[i] = Integer.parseInt(targetArrayStr[i]);
		}

		// 読み込み終了
		scan.close();

		// ソート
		int exchangingCount = selectionSort(n, targetArray);

		// 結果出力
		for (int i = 0; i < targetArray.length; i++) {
			if (i < targetArray.length - 1) {
				System.out.print(targetArray[i] + " ");
			} else {
				System.out.println(targetArray[i]);
			}
		}
		System.out.println(exchangingCount);
		;

	}

	/**
	 * 指定された整数配列を選択ソートする。
	 *
	 * @param n 要素数
	 * @param targetArray 選択ソートしたい整数配列
	 * @return 入れ替え回数
	 */
	private static int selectionSort(int n, int[] targetArray) {

		int exchangingCount = 0; // 入れ替え回数
		for (int i = 0; i < n; i++) {
			int minIndex = i; // 最小値の要素番号
			for (int j = i; j < n; j++) {
				// 最小値より低い値があったら
				if (targetArray[j] < targetArray[minIndex]) {
					// 最小値の要素番号を更新
					minIndex = j;
				}
			}
			// 最小値の値と左端を入れ替える
			if (i != minIndex) {
				exchangeArrayValue(targetArray, minIndex, i);
				exchangingCount++;
			}
		}

		return exchangingCount;
	}

	/**
	 * 配列内の2つの要素を入れ替える。
	 *
	 * @param array
	 *            入れ替えたい要素を含む配列
	 * @param a
	 *            入れ替えたい要素のindex
	 * @param b
	 *            入れ替えたい要素のindex
	 */
	private static void exchangeArrayValue(int[] array, int a, int b) {
		int temp = array[a];
		array[a] = array[b];
		array[b] = temp;
	}

}



Measured memory_bytes: 26308
def two_int():
    N, K = map(int, input().split())
    return N,K

def one_int():
    return int(input())

def one_str():
    return input()

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

S=one_str()

aaa = list('abcdefghijklmnopqrstuvwxyz')

print(aaa[aaa.index(S)+1])

Measured memory_bytes: 3060
#include <iostream>

using namespace std;

typedef long long ll;

int n;
ll br[30], sol = 1;
string s;
const ll mod = (ll)1e9 + 7;

int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
cin >> s;
for(int i = 0 ; i < n ; ++i){
	br[s[i] - 'a']++;
}
for(int i = 0 ; i < 26 ; ++i){
	sol = (sol * (br[i] + 1)) % mod;
}
sol = (sol - 1 + mod) % mod;
cout << sol << endl;

return 0;
}



Measured memory_bytes: 512
#include<stdio.h>

int main(){
  int Tou[4][3][10]={0};
  int n,i,j,k,tou,kai,ban,nin;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d%d%d%d",&tou,&kai,&ban,&nin);
    Tou[tou-1][kai-1][ban-1]=Tou[tou-1][kai-1][ban-1]+nin;
  }
  for(j=0;j<4;j++){
    for(k=0;k<3;k++){
      for(i=0;i<10;i++){
        printf(" %d",Tou[j][k][i]);
      }
      printf("\n");
    }
    if(!(j==3)) printf("####################\n");
  }
  return 0;
}

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

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; }
#define ll long long 
#define INF 999999999
#define rep(i,n) for(int i=0;i<n;i++)
using Graph = vector<vector<int>>;
queue<int> quex,quey;
const int MOD = 1000000007;
 
int main(){
    int n;  cin >> n;
    map<string , int > memo;
    rep(i,n){
        string s;
        cin >> s;
        memo[s]  += 1;
        }

        int maxv=0;

        for(const auto& x : memo){
            int v=x.second ;
            if (maxv <= v) maxv = v;
        }

        for(auto it = memo.begin() ; it != memo.end() ; it++ ){
            if(it->second == maxv){
                cout << it->first << endl;
            }
        }

}



Measured memory_bytes: 25216
from functools import reduce
import math

def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)

    # N の逆元
    # N_inv = pow(N,MOD-2,MOD)

    # nCr
    # Nの階乗 * rの階乗の逆元 * n-rの階乗の逆元
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")

    # 大きな素数
    MOD = 10**9+7
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    X, Y = (_ for _ in input().split())
    if X>Y:        
        print('>')
    elif X == Y:
        print('=')
    else:
        print('<')
        
if __name__ == '__main__':
    main()


Measured memory_bytes: 3572
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
using namespace std;
int main()
 {  ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
	
        int n,m,p;
        cin>>n>>m;
        string s;
        unordered_map<int,int>a;
       
        while(m--){
            cin>>p>>s;
            if(a[p]>=0 && s=="AC") a[p] = -(a[p]+1);
            else if(a[p]>=0) a[p]++;
        }
        int pen=0,c=0;
        for(auto i:a)
            if(i.second<0){
                c++;
                pen += -(i.second)-1;
            }
        cout<<c<<" "<<pen<<"\n";
        
	return 0;
}

Measured memory_bytes: 4388
#include "bits/stdc++.h"

using namespace std;
typedef long long int ll;

int main(){

    ll N, x;
    cin >> N >> x;
    priority_queue<ll ,vector<ll >, greater<ll > > que;
    for(ll i = 0; i < N; i++){
        ll in = 0;
        cin >> in;
        que.push(in);  
    }

    ll ans = 0;
    while(!que.empty() || x > 0){
        if(x - que.top() >= 0){
            x -= que.top();
            que.pop();
            ans++;
        }else
        {
            break;
        }
    }

    if(x > 0 && ans != 0 && que.empty()) ans--;

    cout << ans << endl;

} 

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;
use std::cmp;
use std::collections::HashMap;
use std::collections::HashSet;
use std::char;
use std::cmp::{min, max};
use itertools::Itertools;
use std::ops::{Add, AddAssign};
use num_integer::{Integer, gcd, lcm};
use std::collections::VecDeque;
use smallvec::alloc::collections::LinkedList;
use regex::internal::Char;
use std::iter::once;

fn read<T: FromStr>(stdin: &mut StdinLock) -> T {
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn read_tuple2<T: FromStr, S: FromStr>(stdin: &mut StdinLock) -> (T, S) {
    let a = read(stdin);
    let b = read(stdin);
    (a, b)
}

fn read_tuple3<T: FromStr, S: FromStr, R: FromStr>(stdin: &mut StdinLock) -> (T, S, R) {
    let a = read(stdin);
    let b = read(stdin);
    let c = read(stdin);
    (a, b, c)
}

fn lower_bound<T: Copy, F>(v: &Vec<T>, f: F) -> Option<usize> where
    F: Fn(T) -> bool
{
    let mut left = 0;
    let mut right = v.len() - 1;
    if !f(v[left]) {
        return None;
    }
    if f(v[right]) {
        return Some(right);
    }
    loop {
        if right - left == 1 {
            return Some(left);
        }
        let mid = (left + right) / 2;
        if f(v[mid]) {
            left = mid;
        } else {
            right = mid;
        }
    }
}


fn main() {
    // template
    let stdin = stdin();
    let mut stdin = stdin.lock();
    let out = stdout();
    let mut out = BufWriter::new(out.lock());
    // template ends
    let (l, r, d): (u32, u32, u32) = read_tuple3(&mut stdin);
    let mut ans = 0;
    for i in (l..r+1) {
        if i % d == 0 {
            ans += 1;
        }
    }
    write!(out, "{}", ans);

}



Measured memory_bytes: 2108
#include<bits/stdc++.h>
using namespace std;
int main(){
    vector<int> A(3);
    int K;
    
    for (int i = 0; i < 3; i++)
    {
        cin>>A[i];
    }
    cin>>K;
    sort(A.begin(),A.end(),greater<int>());
    for (int i = 0; i < K; i++)
    {
        A[0]*=2;
    }
    int sum=0;
    for (int i = 0; i < 3; i++)
    {
        sum+=A[i];
    }
    
    cout <<sum<<endl;;
    
}

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

typedef long long LL;
typedef long double LD;
typedef pair < int, int > PII;
typedef pair < LL, LL > PLL;
typedef pair < LD, LD > PDD;

#define _upgrade ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
template < typename _T > inline void _DBG(const char *s, _T x) { cerr << s << " = " << x << "\n"; }
template < typename _T, typename... args > void _DBG(const char *s, _T x, args... a) { while(*s != ',') cerr << *s++; cerr << " = " << x << ','; _DBG(s + 1, a...); }

#ifdef LOCAL
#define DBG(...) _DBG(#__VA_ARGS__, __VA_ARGS__)
#else
#define DBG(...) (__VA_ARGS__)
#define cerr if(0) cout
#endif

// ********************** CODE ********************** //

int main()
{
    _upgrade
    int n, m;
    cin >> n >> m;
    cout << (n - 1) * (m - 1) << "\n";
	return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split(" ")))
ans = A[0]
max_ans = 10 ** 18
if 0 in A:
    ans = 0
else:
    for i in range(1,len(A)):
        ans *= A[i]
        if ans > max_ans:
            ans = -1
            break
print(ans)

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

int main()
{
  unsigned long long X;
  std::cin>>X;
  
  unsigned long long result=1;
  unsigned long long a=100;
  long double b=1.01L;
  for(;;)
  {
    a=static_cast<unsigned long long>(std::floor(a*b));
    if(a>=X)
    {
      break;
    }
    result++;
  }
  
  std::cout<<result<<std::endl;
  
  return 0;
}

Measured memory_bytes: 3544
import sys
from collections import deque
sys.setrecursionlimit(20000000)
input = sys.stdin.readline


# def main():
#     n = int(input())
#
#     nums = list(map(int, input().split()))
#
#     ans = 'Yes'
#
#     for x in reversed(range(1, len(nums))):
#         if nums[x-1] - nums[x] >= 2:
#             ans = 'No'
#
#         elif nums[x-1] - nums[x] == 1:
#             nums[x-1] -= 1
#
#         else:
#             continue
#
#     print(ans)
#
#
# if __name__ == '__main__':
#     main()


def main():
    n = int(input())

    nums = list(map(int, input().split()))

    for x in reversed(range(1, len(nums))):
        if nums[x-1] > nums[x]:
            nums[x-1] -= 1

        if nums[x-1] > nums[x]:
            print('No')
            sys.exit()

    print('Yes')


if __name__ == '__main__':
    main()

Measured memory_bytes: 14636
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define int long long
typedef long long ll;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
using namespace std;

signed main() {
  int k,x;cin>>k>>x;
  repd(i,x-k+1,x+k){
    cout << i << endl;
  }
}



Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n=I()
  l=LI()

  l2=[]
  c=0
  for x in l:
    if x>=3200:
      c+=1
      l2.append(8)
    else:
      l2.append(x//400)

  l2=list(set(l2))

  if len(l2)!=1 and l2.count(8):
    l2.remove(8)

  if len(l2)==1 and l2[0]==8:
    c=max(0,c-1)

  print(len(l2),len(l2)+c)

main()


Measured memory_bytes: 6172
#include <iostream>
#include<string>
using namespace std;
int main(void){
    int a,b,c;
    cin>>a>>b>>c;
    if(b>=c){
        cout<<"delicious"<<endl;
    }
    if(b<c && c-b<=a){
        cout<<"safe"<<endl;
    }
    if(b<c && c-b>a){
        cout<<"dangerous"<<endl;
    }
    
}


Measured memory_bytes: 256
import sys

if sys.platform =='ios':
    sys.stdin=open('input_file.txt')
   
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N=input()

if N[-1]=="2" or N[-1]=="4" or N[-1]=="5" or N[-1]=="7" or N[-1]=="9":
	print("hon")
elif N[-1]=="0" or N[-1]=="1" or N[-1]=="6" or N[-1]=="8":
	print("pon")
else:
	print("bon")

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

#define int long long
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define fr(i,j,k) for(i = j; i < (k); i++)
#define all(x) x.begin(), x.end()
#define el '\n'
#define remax(a,b) a = max(a, b)
#define remin(a,b) a = min(a, b)
#define sz(x) int32_t(x.size())

typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpi;
// --------------------------------------------------------------------

const pii dxy[] = { {-1, 0}, {1, 0}, {0, 1}, {0, -1} };
const int mod = 1e9 + 7;
const int INF = 2e18;
const ld EPS = 1e-9;
const int NN = 500 + 2;

bool state[NN][NN];
int dis[NN][NN];
int n;

bool conclusive(int x, int y) {
      return x < 0 or y < 0 or x >= n or y >= n;
}

void bfs(int x, int y)
{
      queue<pii> q;
      q.push({x, y});
      state[x][y] = 0;
      while(!q.empty()) {
            pii v = q.front();
            q.pop();
            for(auto add : dxy) {
                  int i = add.fi + v.fi, j = add.se + v.se;
                  if(conclusive(i, j))
                        continue;
                  if(dis[i][j] > dis[v.fi][v.se] + state[v.fi][v.se]) {
                        dis[i][j] = dis[v.fi][v.se] + state[v.fi][v.se];
                        q.push({i, j});
                  }
            }
      }
}


void solve() {
      int i = 0, j = 0, k = 0, m = 0; 
      cin >> n;
      m = n*n;
      vi p(m);
      
      memset(state, 1, sizeof state);
      fr(i, 0, n) {
            fr(j, 0, n) {
                  dis[i][j] = min( min(i, j), min(n - i - 1, n - j - 1) );
            }
      }
      fr(i, 0, m) {
            cin >> p[i];
            p[i]--;
            int x = p[i]/n,  y = p[i] % n;
            k += dis[x][y];
            bfs(x, y);
      }

      cout << k << endl;
}

int32_t main() {
      ios::sync_with_stdio(false); cin.tie(0); 
      int T = 1;
      // cin >> T;
      for(int tc = 1; tc <= T; tc++) {
            solve();
       }
      return 0;
}

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

int main() {
    ll n,o;
    cin>>n;
  o=n%10;
    if(o==2||o==4||o==5||o==7||o==9)
    cout<<"hon";
    else if(o==0||o==1||o==6||o==8)
    cout<<"pon";
    else
    if(o==3)
    cout<<"bon";

}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define modulo 998244353
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000000000000



int main(){
	
	int N,S;
	cin>>N>>S;
	
	vector<int> A(N);
	for(int i=0;i<N;i++)cin>>A[i];
	
	vector<vector<int>> dp(N+1,vector<int>(S+1,0));
	dp[0][0] = 1;
	
	for(int i=0;i<N;i++){
		for(int j=0;j<=S;j++){
			dp[i+1][j] = mod(dp[i+1][j] + mod(dp[i][j]*2));
			int k = j+A[i];
			if(k>S)continue;
			dp[i+1][k] = mod(dp[i+1][k] + dp[i][j]);
		}
	}
	
	cout<<dp.back().back()<<endl;
	
	return 0;
}

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

#define rep(i, n) for (int i=0; i<(n); ++i)
using ll = long long;
using P = pair<int, int>;

int main() {
  vector<int> a(3);
  rep(i, 3) cin >> a[i];

  sort(a.begin(), a.end());
  rep(i, 3) {
    printf("%d%c", a[i], i==2 ? '\n' : ' ');
  }
  return 0;
}



Measured memory_bytes: 3268
#include <cstdio>  
#include <algorithm>
using namespace std;  
int main() { 	
	int a,b,c;
	int d;
	scanf("%d %d %d", &a, &b, &c);
	if(a>=b && a>=c){
		if(b>=c){
		printf("%d", a-b + b-c);
				}
		else{
			printf("%d", a-c + c-b);
		}
	}
	else if(b>=a && b>=c){
		if(a>=c){
			printf("%d", b-a + a-c);
		}
		else{
			printf("%d", b-c + c-a);
		}
		
	}
	else if(c>=a && c>=b){
		 if(a>=b){
		printf("%d", c-a + a-b);
	}	
		else{
			printf("%d", c-b + b-a);
		}
}
	
	
}






Measured memory_bytes: 128
class UnionFindTree:

    def __init__(self):
        self.cnt = []
        self.par = []

    def add(self, n):
        assert n == len(self.par), "Invalid Value"
        self.par.append(n)
        self.cnt.append(1)

    def root(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.root(self.par[x])
            return self.par[x]

    def same(self, x, y):
        return self.root(x) == self.root(y)

    def unite(self, x, y):
        x = self.root(x)
        y = self.root(y)
        if x != y:
            cnt = self.cnt[x] + self.cnt[y]
            self.cnt[x] = cnt
            self.cnt[y] = cnt
            if x < y:
                self.par[y] = x
            else:
                self.par[x] = y

    def size(self, x):
        x = self.root(x)
        return self.cnt[x]


def main():
    n, q = map(int, input().split())
    uf = UnionFindTree()
    for i in range(n):
        uf.add(i)
    for _ in range(q):
        com, x, y = map(int, input().split())
        if com == 0:
            uf.unite(x, y)
        else:
            print(1 if uf.same(x, y) else 0)


if __name__ == '__main__':
    main()



Measured memory_bytes: 6136
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const ll inf =1LL << 62;
const ll mod=1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b,const ll &mod) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1,6);
uniform_real_distribution<double> score(0.0,10.0);

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

    int n; cin >> n;
    vi a(n); for(auto& e : a) cin >> e;

    rep(i, n){
    	a[i] -= (i + 1);
    }
    sort(_all(a));

    int b = a[n / 2];
    if(n % 2 == 0) b = (a[n / 2 - 1] + a[n / 2]) / 2;

    ll res = 0;
    for(auto& e : a) res += abs(e - b);
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 1024