akhauriyash/Code-Regression huggingface dataset:
def gcd_core(a,b):
    if b == 0:
        return a
    else:
        return gcd_core(b,a%b)

def gcd(arr):
    g = gcd_core(arr[0],arr[1])
    for i in range(2,len(arr)):
        g = gcd_core(g,arr[i])
    return g

n = int(input())
a = list(map(int,input().split()))

print(gcd(a))

Measured memory_bytes: 14252
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
#define def inf
template<class V, int NV> struct SegTree { //[l,r)
    V comp(V& l, V& r) { return min(l, r); };

    vector<V> val; SegTree() { val = vector<V>(NV * 2, def); }
    V get(int x, int y, int l = 0, int r = NV, int k = 1) {
        if (r <= x || y <= l)return def; if (x <= l && r <= y)return val[k];
        auto a = get(x, y, l, (l + r) / 2, k * 2); 
        auto b = get(x, y, (l + r) / 2, r, k * 2 + 1);
        return comp(a, b);
    }
    void update(int i, V v) {
        i += NV; val[i] = v;
        while (i>1) i >>= 1, val[i] = comp(val[i * 2], val[i * 2 + 1]);
    }
    void add(int i, V v) { update(i, val[i + NV] + v); }
    V operator[](int x) { return get(x, x + 1); }
};
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














int A, B, M;
int a[101010], b[101010];
vector<pair<int,int>> coupons[101010];
SegTree<int, 1 << 17> st;
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> A >> B >> M;
	rep(i, 0, A) cin >> a[i];
	rep(i, 0, B) cin >> b[i];
    rep(i, 0, B) st.update(i, b[i]);

	rep(i, 0, M) {
		int x, y, c; cin >> x >> y >> c;
		y--; x--;

		coupons[x].push_back({ y, c });
	}

	int ans = inf;
	rep(i, 0, A) {
        fore(cp, coupons[i]) {
            chmin(ans, a[i] + b[cp.first] - cp.second);
            st.update(cp.first, inf);
        }

        chmin(ans, a[i] + st.get(0, B));

        fore(cp, coupons[i]) st.update(cp.first, b[cp.first]);
	}
    cout << ans << endl;
}







Measured memory_bytes: 6528
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;
typedef long long  ll;
typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef double ld;
typedef complex<ld> Point;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
typedef vector<int> vec;

struct perm {
private:
	int sz;
	vector<ll> p, invp;
public:
	perm(int n) {
		sz = n + 1;
		p.resize(sz), invp.resize(sz);
		p[0] = 1;
		rep1(i, sz - 1) {
			p[i] = p[i - 1] * i%mod;
		}
		invp[sz - 1] = 1;
		ll cop = mod - 2, x = p[sz - 1];
		while (cop) {
			if (cop % 2)invp[sz - 1] = invp[sz - 1] * x%mod;
			cop >>= 1; x = x * x % mod;
		}
		per(i, sz - 1) {
			invp[i] = invp[i + 1] * (i + 1) % mod;
		}
	}
	ll comb(ll x, ll y) {
		if (x < y || y < 0)return 0;
		ll ret = p[x];
		(ret *= invp[y]) %= mod;
		(ret *= invp[x - y]) %= mod;
		return ret;
	}
	ll combP(ll x, ll y) {
		if (x < y || y < 0)return 0;
		return p[x] * invp[x - y] % mod;
	}
	ll pe(ll x) {
		return p[x];
	}
	ll invpe(ll x) {
		return invp[x];
	}
};
perm p(1 << 15);

ll dp[5001],rdp[5002];
const int mn = 5000;

void init(int t) {
	dp[0] = 1;
	rep(i, mn + 1) {
		rdp[i + 1] = rdp[i] + dp[i];
		if (rdp[i + 1] >= mod)rdp[i + 1] -= mod;
	}
	rep(i, t) {
		per(j, 5001) {
			dp[j] = rdp[j + 1];
		}
		rep(j, mn + 1) {
			rdp[j + 1] = rdp[j] + dp[j];
			if (rdp[j + 1] >= mod)rdp[j + 1] -= mod;
		}
	}
}

void solve() {
	int n, a, b, c; cin >> n >> a >> b >> c;
	if (b % 2) {
		cout << 0 << endl; return;
	}
	init(b/2);
	ll ans = 0;
	rep(s, a + 1) {
		rep(t, c / 3 + 1) {
			int r = c - (a - s) - 3 * t;
			if (r < 0)continue;
			int sum = a + t + b / 2;
			ll pro = p.pe(sum)*p.invpe(s) % mod*p.invpe(a - s) % mod*p.invpe(t) % mod*p.invpe(b / 2) % mod;
			ans = (ans + pro * dp[r]) % mod;
		}
	}
	cout << ans << endl;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(5);
	//while (cin >> n,n)solve();
	solve();
	//stop
	return 0;
}


Measured memory_bytes: 896
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
from collections import defaultdict
sys.setrecursionlimit(10**7)
import math
#from itertools import product, accumulate, combinations, product
#import bisect
#import numpy as np
#from copy import deepcopy
#from collections import deque
#from decimal import Decimal
#from numba import jit

INF = 1 << 50
EPS = 1e-8
mod = 10 ** 9 + 7

class factorials:
    '''
    args:
      n : max val when exploring factorials
    '''
    def __init__(self, n):
        self.n = 1# factorials to be searched
        self.factorials = []
        self.update_factorials(n)

    def update_factorials(self, n):
        if self.n >= n:
            return None
        for i in range(self.n+1, n+1):
            done = False
            limit = int(i ** 0.5)
            for j in self.factorials:
                if j > limit: break
                if not i % j:
                    done = True
                    break
            if not done:
                self.factorials.append(i)
        self.n = n
        return None

    def factorials_list(self):
        return self.factorials

    def check_fact(self, x):
        if x > self.n**2:
            self.update_factorials(int(x ** 0.5)+1)
        MAX = int(math.sqrt(x))
        for f in self.factorials:
            if f > MAX:break
            if not x % f:
                return False
        return True

    def prime_factorization(self, val, divisors=None):
        # divisors : default-dict of divisors. Should be specified only if appended vals are required
        max_n = int(math.sqrt(val))
        if self.n < max_n:
            self.update_factorials(max_n)
        if divisors == None:
            divisors = defaultdict(lambda: 0)
        for f in self.factorials:
            if f > val: break
            while True:
                if not val % f:
                    divisors[f] += 1
                    val //= f
                else:
                    break
        if val > 1:
            divisors[val] += 1
        return divisors



def run():
    N = int(input())
    if N == 1:
        print(0)
        return
    facts = factorials(int(N ** 0.5))
    dic = facts.prime_factorization(N)
    #print(dic)
    ret = 0

    def dfs(x, l, v):
        nonlocal ret
        #print(x,l,v)
        xx, ll = x[0], l[0]
        if len(x) == 1:
            for i in range(ll+1):
                tmp = v * (xx ** i)
                #print(tmp)
                if tmp == 1:continue
                if N % (tmp-1) == N // (tmp-1):
                    #print(tmp)
                    ret += tmp-1

        else:
            for i in range(ll + 1):
                tmp = v * xx ** i
                dfs(x[1:], l[1:], tmp)

    dfs(list(dic.keys()), list(dic.values()), 1)

    print(ret)

if __name__ == "__main__":
    run()


Measured memory_bytes: 12704
#pragma region Header
#ifdef DEBUG
#include "debug.hpp"
#else
#define NDEBUG
#define debug(...)
#define IFD(...)
#endif
#include <utility>
#include <cstdint>
#include <cmath>
#include <vector>
#include <array>
#include <deque>
#include <queue>
#include <stack>
#include <tuple>
#include <set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <string>
#include <functional>
#include <algorithm>
#include <numeric>
#include <stdexcept>
#include <iostream>
#include <iomanip>
using namespace std;
using i32 = int32_t;
using i64 = int64_t;
using u32 = uint32_t;
using u64 = uint64_t;
#define rep(i, n) for (int i = 0; i < static_cast<int>(n); ++i)
#define repd(i, n) for (int i = static_cast<int>(n) - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = static_cast<int>(a); i <= static_cast<int>(b); ++i)
#define FORD(i, a, b) for (int i = static_cast<int>(b); i >= static_cast<int>(a); --i)
template <typename T>
int SZ(T const &x)
{
    return static_cast<int>(x.size());
}
template <class T>
bool chmax(T &a, T const &b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
bool chmin(T &a, T const &b)
{
    if (b < a)
    {
        a = b;
        return true;
    }
    return false;
}
#pragma endregion

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);

    int x;
    cin >> x;

    int y = x / 100;
    cout << (x % 100 <= 5 * y ? 1 : 0) << endl;

    return 0;
}


Measured memory_bytes: 3560
def inpf() a=gets.chomp.split(" ").map(&:to_f)end

def inps() a=gets.chomp.split(" ")end

def copy(a) Marshal.load(Marshal.dump(a)) end

def kaijo(n,r = 10**9+7)(n < 2)? 1 : (2..n).inject{|memo,u|memo=(memo*u)%r} end

def na(n,d=0) Array.new(n,d)end

def na2(n,m,d=0) Array.new(n){Array.new(m,d)}end

def na3(n,m,l,d=0) Array.new(n){Array.new(m){Array.new(l,d)}}end

def inp() a=gets.chomp.split(" ").map(&:to_i)end

def r_up(a, b) (a+b-1)/b end

def r_sort(a) a.sort{|a,b|b<=>a} end

b = gets.chomp
h={"A"=>"T","C"=>"G","G"=>"C","T"=>"A"}
puts h[b]

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

int main() {
  int A, B;
  cin >> A >> B;

  if ((A * B) % 2 != 0 || (A * B * 2) % 2 != 0 || (A * B * 3) % 2 != 0 ) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define REP(i, n) for (ll i=0; i<(ll)n; ++i)
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)

const ll MOD = (ll)1e9 + 7;
const ll HIGHINF = (ll)1e18;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n; cin >> n;
  ll l=0, r=n-1;
  string ls, rs;
  cout << l << endl; cin >> ls;
  if (ls != "Vacant") {
    cout << r << endl; cin >> rs;
    if (rs != "Vacant") {
      REP(i, 18) {
        ll mid = (l + r) / 2;
        string ms;
        cout << mid << endl; cin >> ms;
        if (ms == "Vacant") break;
        if (ms == rs) {
          if (mid % 2 == 0) {
            r = mid;
          } else {
            l = mid;
          }
        } else {
          if (mid % 2 == 0) {
            l = mid;
          } else {
            r = mid;
          }
        }
      }
    }
  }
  return 0;
}


Measured memory_bytes: 852
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
#define REP(i, n) for (int i = 0; (i64)(i) < (i64)(n); ++i)

#ifdef ENABLE_DEBUG
template <typename T>
void debug(T value) {
  cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  cerr << value << ", ";
  debug(args...);
}
#define DEBUG(...)                              \
  do {                                          \
    cerr << " \033[33m (L" << __LINE__ << ") "; \
    cerr << #__VA_ARGS__ << ":\033[0m ";        \
    debug(__VA_ARGS__);                         \
    cerr << endl;                               \
  } while (0)
#else
#define debug(...)
#define DEBUG(...)
#endif

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int H, W;
  cin >> H >> W;
  vector<string> grid(H);
  REP(i, H) { cin >> grid[i]; }

  auto bfs = [&](int r, int c) -> tuple<int, int, int> {
    vector<int> dx = {0, 0, 1, -1};
    vector<int> dy = {1, -1, 0, 0};
    vector<string> g = grid;
    deque<tuple<int, int, int>> q;
    int maxd = -1;
    int mr = -1, mc = -1;
    q.emplace_back(r, c, 0);
    g[r][c] = 'x';
    while (q.size()) {
      auto [r1, c1, d1] = q.front();
      q.pop_front();
      if (maxd < d1) {
        maxd = d1;
        mr = r1;
        mc = c1;
      }
      REP(i, 4) {
        int r2 = r1 + dx[i];
        int c2 = c1 + dy[i];
        if (r2 < 0 || r2 >= H || c2 < 0 || c2 >= W) continue;
        if (g[r2][c2] != '.') continue;
        g[r2][c2] = 'x';
        q.emplace_back(r2, c2, d1 + 1);
      }
    }
    return {mr, mc, maxd};
  };
  int maxd = 0;
  REP(r, H) REP(c, W) {
    if (grid[r][c] == '.') {
      auto [r1, c1, d1] = bfs(r, c);
      if (maxd < d1) maxd = d1;
    }
  }
  cout << maxd << endl;
}

Measured memory_bytes: 3644
#![allow(unused_macros)]
#![allow(dead_code)]
#![allow(unused_imports)]

use num_traits::real::Real;
use text_io::*;

fn main() {
    let n: usize = read!();
    let k: usize = read!();
    const INF: isize = 1000000000000000;

    let mut hs = Vec::with_capacity(n);
    for _ in 0..n {
        let h: isize = read!();
        hs.push(h);
    }

    let mut dp = vec![INF; n + k + 10];
    dp[0] = 0;
    for i in 0..n {
        for j in 1..=k {
            dp[i + j] = dp[i + j].min(dp[i] + (hs[i] - *hs.get(i + j).unwrap_or(&INF)).abs());
        }
    }

    println!("{}", dp[n-1]);
}


Measured memory_bytes: 3604
#include <iostream>

using namespace std;

int main(void) {
    int x, n;
    cin >> x >> n;
    int p;
    bool pn[102];
    for (int i = 0; i < 102; i++) {
        pn[i] = true;
    }
    for (int i = 0; i < n; i++) {
        cin >> p;
        pn[p] = false;
    }
    if (n == 0) {
        cout << x << endl;
        return 0;
    }

    // 入力されたpiがpn[pi] = falseとなっている
    int ans = 0;
    int count = 0;
    while (ans == 0) {
        int shita = x - count;
        if (shita >= 0) {
            if (pn[shita] == true) {
                ans = shita;
                break;
            }
        }
        int ue = x + count;
        if (ue <= 101) {
            if (pn[ue] == true) {
                ans = ue;
                break;
            }
        }
        count++;
        if (count > 102) {
            break;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3632
using System;

namespace ConsoleApplication{
    public class Program{
        public static void Main(string[] args){
            string ring = Console.ReadLine();
            string keyword = Console.ReadLine();

            int len = ring.Length / 2;
            if(ring.Length % 2 == 1){len++;}
            string ring2 = ring.Substring(keyword.Length/2, len) + ring + ring.Substring(0,len);

            if(ring2.IndexOf(keyword) != -1){
                Console.WriteLine("Yes");
            }else{
                Console.WriteLine("No");
            }
        }
    }
}

Measured memory_bytes: 9812
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <functional>
using i64 = long long;

int main() {
    int n;
    std::cin >> n;
    std::vector<std::pair<i64, int>> v;
    for (int i = 0; i < n; i++) {
        i64 a;
        std::cin >> a;
        v.emplace_back(a, i);
    }

    std::sort(v.begin(), v.end(), std::greater<>());

    std::vector<i64> dp(n + 1);
    for (int i = 0; i < n; i++) {
        const auto [a, p] = v[i];
        std::vector<i64> next(n + 1);
        for (int j = 0; j <= i; j++) {
            next[j] = std::max(next[j], dp[j] + a * abs(n - 1 - i + j - p));
            next[j + 1] = std::max(next[j + 1], dp[j] + a * abs(p - j));
        }
        std::swap(dp, next);
    }

    std::cout << *std::max_element(dp.begin(), dp.end()) << std::endl;

    return 0;
}


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

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef pair<int,int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define EXIST(m,v) (m).find((v)) != (m).end()
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

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

#define en 


constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

vector< int64_t > divisor(int64_t n) {
  vector< int64_t > ret;
  for(int64_t i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

void Main(){
    int n;
    cin >> n;
    vector<int64_t> v;
    int ans = 0;
    REP(i, n) {
        v = divisor(i+1);
        if (v.size() == 8 && (i+1) % 2 == 1) { 
            ans++;
        }
    }
    cout << ans << endl;
    return;
}

int main(void){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t=1; //cin>>t;
    REP(_,t) Main();
    return 0;
}

Measured memory_bytes: 3648
#include <stdio.h>

#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define INF 3333333333
#define uint unsigned int
#define llong long long

llong merge(uint S[], int left, int mid, int right) {
  llong numInv = 0;
  int n1 = mid - left;
  int n2 = right - mid;
  uint L[n1 + 1], R[n2 + 1];
  REP(i, n1) {
    L[i] = S[left + i];
  }
  REP(i, n2) {
    R[i] = S[mid + i];
  }
  L[n1] = INF;
  R[n2] = INF;

  int i = 0, j = 0;
  FOR(k, left, right) {
    if(L[i] <= R[j]) {
      S[k] = L[i];
      i += 1;
    } else {
      S[k] = R[j];
      j += 1;
      numInv += n1 - i;
    }
  }
  return numInv;
}

llong mergeSort(uint S[], int left, int right) {
  llong numInv = 0, mid;
  if((left + 1) < right) {
    mid = (left + right) / 2;
    numInv += mergeSort(S, left, mid);
    numInv += mergeSort(S, mid, right);
    numInv += merge(S, left, mid, right);
  }
  return numInv;
}

int main(void) {
  int n;
  scanf("%d", &n);
  uint S[n];
  REP(i, n) {
    scanf("%d", &S[i]);
  }

  llong numInv = mergeSort(S, 0, n);

  printf("%lld\n", numInv);

  return 0;
}

Measured memory_bytes: 4288
import numpy as np
n=int(input())
d=np.zeros(101)
def factorization(n):
    temp = n
    for i in range(2, int(n**0.5)+1):
        if temp%i==0:
            while temp%i==0:
                d[i]+=1
                temp //= i
    if temp!=1:
        d[temp]+=1
def cnt(k):
    return len(d[d>=k])
for i in range(2,n+1):
    factorization(i)
print(cnt(74)+cnt(24)*(cnt(2)-1)+cnt(14)*(cnt(4)-1)+cnt(4)*(cnt(4)-1)*(cnt(2)-2)//2)

Measured memory_bytes: 12512
#include <bits/stdc++.h>
using namespace std;
int N,M;
vector<vector<int>> G;
vector<bool> visited;

void dfs(int v){
  visited.at(v) = true;
  for(int i = 0; i < N; i++){
    if(G.at(v).at(i) == 0) continue;
    if(visited.at(i)) continue;
    dfs(i);
  }
  return;
}

int main() {
  cin >> N >> M;
  G = vector<vector<int>>(N,vector<int>(N,0));
  visited = vector<bool>(N,false);
  for(int i = 0; i < M; i++){
    int a,b; cin >> a >> b;
    a--;
    b--;
    G.at(a).at(b) = 1;
    G.at(b).at(a) = 1;
  }
  
  int ans = 0;
  for(int i = 0; i < N; i++){
    for(int j = i; j < N; j++){
      if(G.at(i).at(j) == 1){
        vector<vector<int>> tempG(G);
        vector<bool> tempvisited(visited);
        G.at(i).at(j) = 0 , G.at(j).at(i) = 0;
        dfs(0);
        bool connect = true;
        for(int k = 0; k < N; k++) if(visited.at(k) == false) connect = false;
        if(!connect) ans++;
        G = tempG;
        visited = tempvisited;
      }
    }
  }
  cout << ans<< endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef pair< int, int > Pi;
struct edge
{
  int prev, to, cost;
  bool operator<(const edge& e) const {
    return(cost > e.cost);
  }
};
struct UnionFind
{
  vector< int > data;
  UnionFind(int size)
  {
    data.assign(size, -1);
  }
  int Find(int k)
  {
    if(data[k] < 0) return(k);
    else return(data[k] = Find(data[k]));
  }
  bool Unite(int x, int y)
  {
    x = Find(x), y = Find(y);
    if(x == y) return(false);
    if(data[y] < data[x]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return(true);
  }
  int Size(int k)
  {
    return(-data[Find(k)]);
  }
};
 
const int INF = 1 << 30;
 
int main()
{
  int N, M, K, Q;
  scanf("%d %d %d %d", &N, &M, &K, &Q);
 
  vector< vector< edge > > graph(N);
  vector< edge > edges;
 
  for(int i = 0; i < M; i++) {
    int A, B, L;
    scanf("%d %d %d", &A, &B, &L);
    --A, --B;
    graph[A].push_back((edge){A, B, L});
    graph[B].push_back((edge){B, A, L});
    edges.push_back((edge){A, B, L});
  }
 
  priority_queue< Pi, vector< Pi >, greater< Pi > > que;
  vector< int > min_cost(N, INF);
 
  for(int i = 0; i < K; i++) {
    int F;
    scanf("%d", &F);
    --F;
    que.push(Pi(0, F));
    min_cost[F] = 0;
  }
  while(!que.empty()) {
    Pi p = que.top(); que.pop();
    if(min_cost[p.second] < p.first) continue;
    for(edge& e : graph[p.second]) {
      if(min_cost[e.to] > p.first + e.cost) {
        min_cost[e.to] = p.first + e.cost;
        que.push(Pi(min_cost[e.to], e.to));
      }
    }
  }
  for(edge& e : edges) {
    e.cost = min(min_cost[e.prev], min_cost[e.to]);
  }
  sort(edges.begin(), edges.end());
 
  vector< unordered_set< int > * > query(N);
  for(int i = 0; i < N; i++) {
    query[i] = new unordered_set< int >();
  }
  for(int i = 0; i < Q; i++) {
    int S, T;
    scanf("%d %d", &S, &T);
    --S, --T;
    query[S] -> insert(i);
    query[T] -> insert(i);
  }
 
  UnionFind uf(N);
  vector< int > ret(Q);
  for(edge& e : edges) {
    int u = uf.Find(e.prev), v = uf.Find(e.to);
    if(u == v) continue;
    auto l = query[u], r = query[v];
    uf.Unite(u, v);
    if(l -> size() < r -> size()) swap(l, r);
    while(!r -> empty()) {
      int idx = *(r -> begin());
      if(l -> find(idx) != l -> end()) {
        l -> erase(idx);
        ret[idx] = e.cost;
      } else {
        l -> insert(idx);
      }
      r -> erase(r -> begin());
    }
    query[uf.Find(u)] = l;
  }
  for(int v : ret) printf("%d\n", v);
}

Measured memory_bytes: 40208
import java.util.Scanner;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    String S = sc.next();
    char[] s = S.toCharArray();

    String alp = "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ";
    char[] al = alp.toCharArray();

    for(int n = 0; n < s.length; n++){
      for(int i = 0; i < 26;i++){
        if(s[n] == al[i]){
          System.out.print(al[i+N]);
        }
      }
    }
  }
}


Measured memory_bytes: 26832
N, M = map(int, input().split())
MOD = 10 ** 9 + 7

fact = [0] * (max(N, M) + 1)
fact[1] = 1
for i in range(2, max(M, N) + 1):
    fact[i] = fact[i - 1] * i % MOD

if abs(N - M) > 1:
    print(0)
else:
    ans = fact[N] * fact[M] % MOD
    if N == M:
        ans *= 2
        ans %= MOD
    print(ans)


Measured memory_bytes: 6900
s = int(input())
x = 1
if s == 1 or s == 2 or s == 4:
    print(4)
else:
    while not s == 4:
        if s % 2 != 0:
            s = 3 * s + 1
            x = x + 1
               
        else:
            s = s // 2
            x = x + 1
        
if x != 1:
    print(x + 3)

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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int main(){
  int N; cin >> N;
  ll D; cin >> D; D = D * D;
  int ans = 0;
  for (int i = 0; i < N; i++){
    ll X, Y; cin >> X >> Y;
    if (X * X + Y * Y <= D)ans++;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3588
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <numeric>
#include <iostream>

using namespace std;

#define FOR(i, a, b)   for(int i = (a); i < (b); ++i)
#define RFOR(i, a, b)  for(int i = (a); i > (b); --i)
#define rep(i, n)      for(int i = 0; i < (n); ++i)
#define all(c)         begin(c), end(c)
#define rall(c)        rbegin(c), rend(c)
#define SZ(a)          ((ll) a.size())

typedef long long ll;
typedef unsigned long long ull;


int main(){
	ll N;
	cin >> N;
	map<ll,ll> a;
	ll tmp,tmp2;
	rep(i,N){
		cin >> tmp;
		auto itr=a.find(tmp);
		if(itr==a.end()){
			a[tmp]=1;
		}
		else{
			tmp2=a[tmp];
			a[tmp]=tmp2+1;
		}
	}
	ll ans=0;
	for(auto itr=a.begin(); itr!=a.end(); itr++){
		if(itr->first==itr->second) continue;
		else{
			if(itr->first>itr->second) ans+=itr->second;
			else ans+=itr->second-itr->first;
		}
	}
	cout << ans << endl;

  return 0;
}


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

int main() {
  int n, m = 0;
  cin >> n;
  vector<int> a1(n), a2(n), s1(n), s2(n);
  for(int i = 0; i < n; i++) {
    cin >> a1.at(i);
    s1.at(i) = a1.at(i);
    if(i)
      s1.at(i) += s1.at(i - 1);
  }
  for(int i = 0; i < n; i++)
    cin >> a2.at(i);
  for(int i = n - 1; i >= 0; i--) {
    s2.at(i) = a2.at(i);
    if(i != n - 1)
      s2.at(i) += s2.at(i + 1);
  }
  for(int i = 0; i < n; i++)
    m = max(m, s1.at(i) + s2.at(i));
  cout << m << endl;
}

Measured memory_bytes: 256
//----------------------------templates
    #pragma GCC optimize ("Ofast")
    #pragma GCC target ("tune=native")
    #pragma GCC target ("avx")
    //----------------------------
    #include <bits/stdc++.h>
    using namespace std;

    typedef long long ll;
    typedef unsigned long long ull;
    #define int ll

    #define FOR(i,j,n) for (int i=(int)(j);i<(n);i++)
    #define REP(i,n) for (int i=0;i<(int)(n);i++)
    #define REPS(i,n) for (int i=1;i<=(int)(n);i++)
    #define REPN(i,n) for (int i=(int)(n)-1;i>=0;i--)
    #define REPNS(i,n) for (int i=(int)(n);i>0;i--)

    #define I(n) scanf("%lld", &(n))
    #define LL(n) scanf("%lld", &(n))
    #define pb(n) push_back((n))
    #define mp(i,j) make_pair((i),(j))
    #define eb(i,j) emplace_back((i),(j))
    #define y0 y3487465
    #define y1 y8687969
    #define j0 j1347829
    #define j1 j234892
    #define uniq(v) v.erase( unique(v.begin(), v.end()), v.end() )

    #define all(x) (x).begin(),(x).end()
    #define sz(x) ((int)(x).size())

    typedef vector<int> vi;
    typedef pair<int,int> pi;
    typedef vector<pi> vpi;
    typedef vector<vi> vvi;
    typedef vector<vpi> vvpi;
    typedef vector<vvi> vvvi;

    const int mod = 1000000007;

//--------------------------------------

int n,v;
map<int,int> v1, v2;
map<int,int> v1s, v2s;

signed main(){
    I(n);
    n /= 2;
    REP(i,n){
        I(v); v1[v]++;
        I(v); v2[v]++;
    }
    int ret = 0;
    pi v1f = {0,0};
    pi v1s = {0,0};
    for(auto pv : v1){
        if (pv.second > v1f.second){
            v1s = v1f;
            v1f = pv;
        } else if (pv.second > v1s.second){
            v1s = pv;
        }
    }

    pi v2f = {0,0};
    pi v2s = {0,0};
    for(auto pv : v2){
        if (pv.second > v2f.second){
            v2s = v2f;
            v2f = pv;
        } else if (pv.second > v2s.second){
            v2s = pv;
        }
    }

    if (v1f.first != v2f.first){
        ret = 2 * n - v1f.second - v2f.second;
    } else {
        ret = 2*n  - max(v1f.second + v2s.second , v1s.second + v2f.second);
    }
    
    cout << ret << endl;

}

Measured memory_bytes: 6528
#include <iostream>

using namespace std;

int main() {
   int a, b;
   cin >> a >> b;
   if ( a > b ) {
   cout << "a > b" << endl;
   
   } else if ( a < b ) {
   cout << "a < b" << endl;
  
   } else if ( a = b ) {
   cout << "a == b" << endl;
   }
   return 0;
}


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

int main()
{
    ll n,k;
    ll mod=1000000007;
    cin>>n>>k;
    if(k==0)
    {
        cout<<1<<endl;
        return 0;
    }
    ll dp[k+1];
    for(ll i=0;i<=k;i++)
        dp[i]=1;
    for(int i=0;i<n;i++)
    {
        ll a;
        cin>>a;
        for(int j=k;j>0;j--)
        {
            if(j-a-1>=0)
                dp[j]=(dp[j]-dp[j-a-1]+mod)%mod;
        }
        for(int j=1;j<=k;j++)
            dp[j]=(dp[j]+dp[j-1])%mod;
    }
    cout<<((dp[k]-dp[k-1]+mod)%mod)<<endl;
    return 0;
}


Measured memory_bytes: 1024
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
	int ans = 0;
	int tmp;
	int n, m;
	cin >> n >> m;
	int pa[100002] ={};
	int l, r;
	REP(i, m){
		cin >> l >> r;
		pa[l] ++;
		pa[r+1] --;
	}
	REP1(i, n){
		pa[i] += pa[i-1];
	}
	REP1(i, n){
		if(pa[i] == m) ans ++;
	}
	cout << ans << endl;
}

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

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    if(max(a,max(b,c))==a) cout << a*10+b+c << endl;
    else if(max(a,max(b,c))==b) cout << b*10+a+c << endl;
    else if(max(a,max(b,c))==c) cout << c*10+b+a << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define inf 1000000000000000
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)
 
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
 
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
 
using namespace std;
 
int main()
{
   FAST/**/
   
   string s,t;
   cin>>s>>t;
   
   ll a,b;
   cin>>a>>b;
   
   map<string,ll> ma;
   ma[s] = a;
   ma[t] += b;
   
   string u;
   cin>>u;
   ma[u]--;
   cout<<ma[s]<<" "<<ma[t];
   
   return 0;        
}  

Measured memory_bytes: 256
module.exports=function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}return n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=0)}([function(e,t,n){n(1)(n(2).readFileSync("/dev/stdin","UTF-8").split("\n"))},function(e,t){e.exports=function(e){for(var t=e[0],n=t.length,r=0,o=0,u=0;u<n;u++)o>0?("g"==t[u]&&r++,o--):("p"==t[u]&&r--,o++);console.log(r)}},function(e,t){e.exports=require("fs")}]);

Measured memory_bytes: 21064
#include <iostream>
#include <cstdio>
using namespace std;
int main(void){
   int S,h,m,s,n;
   cin >>S;
   h=S/3600;
   n=S%3600;
   m=n/60;
   s=n%60;
   cout <<h;
   cout <<":";
   cout <<m;
   cout <<":";
   cout <<s;
   cout << endl;
}



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

int main(){
    int n;
    cin>>n;
    int u[4][3][10]={0};
    for(int i=0; i<n; ++i){
        int a,b,c,d; cin>>a>>b>>c>>d;
        a--,b--,c--;
        u[a][b][c]+=d;
    }
    for(int i=0; i<4; ++i){
        for(int j=0; j<3; ++j){
            for(int k=0; k<10; ++k){
                if(k!=9)cout<<" "<<u[i][j][k];
                else cout<<" "<<u[i][j][k]<<endl;
            }
        }
        if(i!=3)cout<<"####################"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
int main(){
  int H,W;cin>>H>>W;
  int N[H][W];char M[H][W];
  for(int i=0;i<H;i++)for(int j=0;j<W;j++)cin>>M[i][j];
  N[0][0]=0;
  if(M[0][0]=='#')N[0][0]=1;
  for(int i=1;i<H;i++){
    N[i][0]=N[i-1][0];
    if(M[i][0]!=M[i-1][0])N[i][0]++;
  }
  for(int i=1;i<W;i++){
    N[0][i]=N[0][i-1];
    if(M[0][i]!=M[0][i-1])N[0][i]++;
  }
  for(int i=1;i<H;i++)for(int j=1;j<W;j++){
    int x=N[i-1][j],y=N[i][j-1];
    if(M[i][j]!=M[i-1][j])x++;
    if(M[i][j]!=M[i][j-1])y++;
    N[i][j]=min(x,y);
  }
  cout<<(N[H-1][W-1]+1)/2<<endl;
}

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


main(){
  int N; cin >> N;
  int k; cin >> k;
  int x, y;
  rep(i, k){
    cin >> x >> y;
    if ( x >= (N+1)/2 ) x = N - x + 1;
    if ( y >= (N+1)/2 ) y = N - y + 1;
    int p = min(x, y);
    cout << (p-1)%3 + 1 << endl;
  }
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define vi vector<int>
#define mod 1000000007
#define size_f 100002
int main()
{
   int n,m;
   cin>>n>>m;

   int sum=3*n+m;

   cout<<sum/2<<"\n";
   return 0;
}


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

signed main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A[i];

  int p = 1, ans = 0;
  for (int i = 0; i < N; i++) {
    if (p == 1) {
      ans += A[i] - 1;
      p++;
    } else if (A[i] < p) {
      continue;
    } else if (A[i] == p) {
      p++;
    } else {
      ans += (A[i] - 1) / p;
    }
  }

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


Measured memory_bytes: 1024
s = list(input())
t = list(input())

ls, lt = len(s), len(t)
ans_i, ans_j = -1, -1
for i in range(ls-lt+1):
    for j in range(lt):
        if s[i+j] == '?' or s[i+j] == t[j]:
            pass
        else:
            break
        if j == lt-1:
            ans_i = i
            ans_j = j

if ans_i > -1 and ans_j > -1:
    idx = 0
    for i in range(ans_i, ans_i+lt):
        if s[i] == '?':
            s[i] = t[idx]
        idx += 1
    for i in enumerate(s):
        if i[1] == '?':
            s[i[0]] = 'a'
    for i in s:
        print(i, end='')
    print()
else:
    print('UNRESTORABLE')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
long long GCD(long long a, long long b) {
    if (a > b) swap(a, b);
    if (a == 0) return b;
    return GCD(b % a, a);
}
int main () {
    long long N, X;
    cin >> N >> X;
    long long x;
    cin >> x;
    long long ans = abs(X-x);
    for (int i = 0; i < N-1; i++) {
        cin >> x;
        ans = GCD(ans, abs(X-x));
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
#include"bits/stdc++.h"
#define F(i,j,n) for(register int i=j;i<=n;i++)
#define D(i,j,n) for(register int i=j;i>=n;i--)
#define ll long long
#define N 200010
using namespace std;
namespace io{
	const int L=(1<<19)+1;
	char ibuf[L],*iS,*iT,c;int f;
	char gc(){
		if(iS==iT){
			iT=(iS=ibuf)+fread(ibuf,1,L,stdin);
			return iS==iT?EOF:*iS++;
		}
		return*iS++;
	}
	template<class I>void gi(I&x){
		for(f=1,c=gc();c<'0'||c>'9';c=gc())if(c=='-')f=-1;
		for(x=0;c<='9'&&c>='0';c=gc())x=x*10+(c&15);x*=f;
	}
};
using io::gi;
using io::gc;
int f[N],g[N],s[20],r[20][N],l[20][N],x[N],p[1<<20],q[1<<20],n,v,d,t,m,ans[N];
int main(){
	gi(n);gi(v);
	F(i,1,n)gi(x[i]);
	D(i,n,2)x[i]-=x[i-1];
	x[1]=v+1;x[n+1]=v+1;
	D(i,n,1)g[i]=(x[i+1]>v)?i:g[i+1];
	F(i,1,n)f[i]=(x[i]>v)?i:f[i-1];
	F(i,1,n)if(x[i]>v)t++;
	for(d=0;v;d++){
		v/=2;
		D(i,n,1)r[d][i]=(x[i+1]>v)?i:r[d][i+1];
		F(i,1,n)l[d][i]=(x[i]>v)?i:l[d][i-1];
//		F(i,1,n)printf("%d ",l[d][i]);puts("");
	}
	if(d+1<t){F(i,1,n)puts("Impossible");return 0;}
	m=(1<<d)-1;d--; 
	F(i,0,m){
		q[i]=n+1;p[i]=0; 
		F(j,0,d)if((i>>j)&1)p[i]=max(p[i],r[j][min(n,p[i^(1<<j)]+1)]);
		F(j,0,d)if((i>>j)&1)q[i]=min(q[i],l[j][max(1,q[i^(1<<j)]-1)]);
	}
//	F(i,0,m)printf("%d %d %d\n",i,p[i],q[i]);
	F(i,1,n)if(f[i]==i){
		for(int j=m;j;j=m&(j-1))if(p[j]>=i-1&&q[m^j]<=g[i]+1)ans[i]=1;
		if(i==1&&q[m]<=g[i]+1)ans[i]=1;
//		printf("%d %d\n",f[i],g[i]);
	}
	else ans[i]=ans[f[i]];
	F(i,1,n)puts(ans[i]?"Possible":"Impossible");
	return 0;
}


Measured memory_bytes: 41088
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

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

vvi grid;
vector<vector<bool>> present;
int n;

void bfs(int sy, int sx) {
    queue<P> q;
    q.emplace(sy, sx);
    present[sy][sx] = false;
    while (!q.empty()) {
        int y = q.front().fi, x = q.front().se;
        q.pop();
        rep(i, 4) {
            int ny = y + dy[i], nx = x + dx[i];
            if (ny < 0 || n <= ny || nx < 0 || n <= nx) continue;
            if (chmin(grid[ny][nx], grid[y][x] + present[y][x])) q.emplace(ny, nx);
        }
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    cin >> n;
    grid.resize(n, vi(n));
    present.resize(n, vb(n, true));
    rep(i, n) rep(j, n) grid[i][j] = min({i, n-1-i, j, n-1-j});
    int ans = 0;
    rep(i, n*n) {
        int p;
        cin >> p;
        p--;
        int sy = p / n;
        int sx = p % n;
        ans += grid[sy][sx];
        bfs(sy, sx);
    }
    cout << ans << endl;
}

Measured memory_bytes: 4692
n = int(input())
ais = input().split()
ais_int = [int(a) for a in ais]
ais_sort = ais_int.sort()
alice = 0
bob = 0
if n % 2 == 0:
  for i in range(n):
    if i % 2 == 1:
      alice += int(ais_int[i])
    else:
      bob += int(ais_int[i])
else:
  for j in range(n):
    if j % 2 == 0:
      alice += int(ais_int[j])
    else:
      bob += int(ais_int[j])
print(alice - bob)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define scn(n) scanf("%d",&n)
using namespace std;

int main() {
	
	string s,t;
	cin>>s;
	cin>>t;
	
	int cnt=0;
	for(int i=0;i<s.size();i++)
	{
	    if(s[i]==t[i])
	    continue;
	    else
	    cnt++;
	}
	cout<<cnt;
	return 0;
}

Measured memory_bytes: 3820
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep1(i, n) for (int i = 1; i < n; ++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)
ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

void solve() {
  // main coding
  int n; cin>>n;
  if(n%2==0) cout<<0.5<<endl;
  else cout<<((double)(n/2+1)/n)<<endl;
}

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


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
#include<cmath>
#include<bitset>

#define Vsort(a) sort(a.begin(), a.end())
#define Vreverse(a) reverse(a.begin(), a.end())
#define Srep(n) for(int i = 0; i < (n); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define Lrep(i,a,n) for(int i = (a); i < (n); i++)
#define Brep(n) for(int bit = 0; bit < (1<<n); bit++)
#define vi vector<int>
#define vi64 vector<int64_t>
#define vvi vector<vector<int>>
#define vvi64 vector<vector<int64_t>>

using namespace std;

int main(){
    int64_t a,b,c,d;
    cin >> a >> b >> c >> d;
    vi64 ans(4);
    ans[0] = a * c;
    ans[1] = a * d;
    ans[2] = b * c;
    ans[3] = b * d;
    Vsort(ans);
    cout << ans[ans.size()-1] << endl;
}

Measured memory_bytes: 3624
import bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353


a, b = list(map(int, sys.stdin.buffer.readline().split()))

for c in range(1, 4):
    if a * b * c %2 == 1:
        print('Yes')
        exit()
print('No')


Measured memory_bytes: 13432
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

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

ll mod = 1e9 + 7;

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

	int ans = 0;
	if(s[0]==t[0]) ans++;
	if(s[1]==t[1]) ans++;
	if(s[2]==t[2]) ans++;

	cout << ans << endl;

	return 0;
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}


signed main(){
    int K;cin>>K;

    vint latte;
    while(K){
        if(K%2&&K>=3){
            K=(K-1)/2;
            latte.pb(0);
        }
        else{
            K--;
            latte.pb(1);
        }
    }

    deque<int>v;

    for(int i=latte.size()-1;i>=0;i--){
        if(latte[i])v.pb(i+1);
        else v.push_front(i+1);
    }

    for(int i=100;i>0;i--)v.push_front(i);
    cout<<v.size()<<endl;
    rep(i,v.size()){
        if(i)cout<<" ";

        cout<<v[i];
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
icase=0
if icase==0:
    a,b,k=map(int,input().split()) 
    if a+k-1<b-k+1:
        for i in range(a,a+k):
            print(i)
        for i in range(b-k+1,b+1):
            print(i)
    else:
        for i in range(a,b+1):
            print(i)

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

    int a,b,c,k,big=0,s=0,cnt=0,i;
    cin>>a>>b>>c>>k;
    if((c*pow(2,k)) < a || ( ( b*(pow(2,k))) < a ) )
       cout<<"No"<<endl;

       else
    {

       if(b<=a)
       {
           for(i=1;i>0;i++)
           {
               b=2*b;
               if(b>a)
               {
                  cnt=i;
                  break;
               }
           }

       }
       if(c<=b || c<=a)
       {
        for(i=1;i>0;i++)
        {
            c=2*c;
            if(c>b && c>a)
            {
                s=i;
                break;
            }
        }
       }

     //cout<<s<<cnt<<endl;

       if((s+cnt)<=k) cout<<"Yes"<<endl;
       else cout<<"No"<<endl;
    }

}



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

vector<int> parents;

int find_root(int now){
    if(parents[now] == now){
        return now;
    }else{
        return parents[now] = find_root(parents[now]);
    }
}

long triangular_number(long number){
    return number * (number - 1) / 2;
}

int main(){
    long N, M;
    cin >> N >> M;
    for(int i = 0; i < N; i++){
        parents.push_back(i);
    }
    for(int i = 0; i < M; i++){
        int start, goal;
        cin >> start >> goal;
        parents[find_root(start - 1)] = find_root(goal - 1);
    }
    long group_1 = 0, group_2 = 0;
    for(int i = 0; i < N; i++){
        group_1 += (find_root(i) == find_root(0));
        group_2 += (find_root(i) == find_root(1));
    }
    cout << triangular_number(max(group_1, group_2) + N - (group_1 + group_2)) + triangular_number(min(group_1, group_2)) - M << endl;
}


Measured memory_bytes: 2296
class cumulative_sum:
    def __init__(self,A):
        N = len(A)
        self.S = [0]*(N+1)
        for i in range(N):
            self.S[i+1] = self.S[i] + A[i]
    def get(self,i,j=None):
        if j==None:j=len(self.S)-1
        if j<=i:return 0
        return self.S[j]-self.S[i]

N,K = map(int,input().split())
*A, = map(int,input().split())
B = [max(0,a) for a in A]
SA = cumulative_sum(A)
SB = cumulative_sum(B)
ans = 0
for i in range(N-K+1):
    tmp = max(0,SA.get(i,i+K)) + SB.get(0,i) + SB.get(i+K)
    ans = max(ans,tmp)
print(ans)

Measured memory_bytes: 73376
D,G=list(map(int,input().split()))
l=[list(map(int,input().split())) for i in range(D)]
cnt=0
tmp=0
dep=0
import math
m=set(range(D))
def main(cnt,tmp,dep,m):
   if dep==D:
      if tmp>=G:
         return cnt
      else:
         tmp=G-tmp
         if tmp <= (max(m)+1)*l[max(m)][0]*100:
            cnt+=math.ceil(tmp/((max(m)+1)*100))
            return cnt
         else:
            return float("Inf")
   return(min(main(cnt+l[dep][0],tmp+100*(dep+1)*l[dep][0]+l[dep][1],dep+1,m-{dep}),main(cnt,tmp,dep+1,m))) 
print(main(0,0,0,m))

Measured memory_bytes: 3064
n = int(input())

dp = [[0] * 10 for _ in range(10)]
for i in range(1, n + 1):
    s = str(i)
    x = int(s[0])
    y = int(s[-1])
    dp[x][y] += 1

ans = 0
for i in range(1, 10):
    for j in range(1, 10):
        ans += dp[i][j] * dp[j][i]

print(ans)

Measured memory_bytes: 40428
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e18;

int main() {
  ll n;
  cin >> n;
  vec h(n);
  vec hk(n,0);
  for(ll i=0;i<n;i++) cin >> h[i];
  ll cnt=0;
  while(1) {
    ll f=1;
    ll ff=1;
    for(ll i=0;i<n;i++) {
      if(hk[i]<h[i]) {
        hk[i]++;
        if(ff) {
          cnt++;
          ff=0;
        }
        f=0;
      }
      else ff=1;
    }
    if(f) break;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long

using namespace std;

// 3 5 7

const int MOD = 1000000007;

int main() {
  int a, b, t;
  scanf("%d %d %d", &a, &b, &t);
  int sum = 0;

  for (int i = a;; i += a) {
    if (i > t) {
      break;
    }
    sum += b;
  }

  cout << sum << endl;
}


Measured memory_bytes: 256