akhauriyash/Code-Regression huggingface dataset:
def _get_distance(c1, c2):
    return ((c1[1] - c2[1]) ** 2 + (c1[2] - c2[2]) ** 2) ** 0.5 - c1[0] - c2[0]

from itertools import combinations

def _get_min_distance(circles):
    min_d = float("inf")
    for c1, c2 in combinations(circles, 2):
        min_d = min(min_d, _get_distance(c1, c2))
    return min_d

def closest_pair_distance(circles, axis =1):
    # axis: x; 1, y; 2
    n = len(circles)
    if n <= 3:
        return _get_min_distance(circles)
    else:
        mid = n // 2
        r, x, y = zip(*circles)
        
        if len(set(x)) > len(set(y)):
            if axis == 2:
                circles.sort(key = lambda c: c[1] - c[0])
            axis1 = 1
            axis2 = 2
        else:
            if axis == 1:
                circles.sort(key = lambda c: c[2] - c[0])
            axis1 = 2
            axis2 = 1
        
        A_circles = circles[:mid]
        B_circles = circles[mid:]
        
        d_Amin = closest_pair_distance(A_circles.copy(), axis1)
        d_Bmin = closest_pair_distance(B_circles.copy(), axis1)
        dist = min(d_Amin, d_Bmin)
        min_d = dist
        
        A_circles.sort(key = lambda c: c[axis] + c[0])
        B_edge = B_circles[0][axis1] - B_circles[0][0]
        for ac in A_circles[::-1]:
            ac_r = ac[0]
            ac_edge = ac[axis1] + ac_r
            if B_edge - ac_edge >= dist:
                break
            for bc in B_circles:
                bc_r = bc[0]
                if bc[axis1] - bc_r - ac_edge >= dist:
                    break
                if abs(ac[axis2] - bc[axis2]) - ac_r - bc_r < dist:
                    min_d = min(min_d, _get_distance(ac, bc))
        return min_d

# solve
def solve():
    import sys
    input_lines = sys.stdin.readlines()
    while True:
        N = int(input_lines[0])
        if N == 0:
            break
        circles = [tuple(map(float, l.split())) for l in input_lines[1:N+1]]
        print('{:.8f}'.format(closest_pair_distance(circles)))
        del input_lines[:N+1]

solve()


Measured memory_bytes: 63840
import heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop
import copy

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001


class Edge:
    def __init__(self,arg_to,arg_dist):
        self.to = arg_to
        self.dist = arg_dist


V,E = map(int,input().split())

POW = [None]*(V+1)
POW[0] = 1
for i in range(1,V+1):
    POW[i] = POW[i-1]*2

G = [[] for _ in range(V)]

for _ in range(E):
    from_,to_,dist = map(int,input().split())
    G[from_].append(Edge(to_,dist))

#経路は輪になるので、スタートは0として良い
start = 0
dp = [[BIG_NUM]*V for _ in range(POW[V])]

dp[POW[start]][start] = 0

for state in range(1,POW[V]):
    for last_node in range(V):
        if dp[state][last_node] == BIG_NUM:
            continue
        for edge in G[last_node]:
            if state & POW[edge.to] != 0:
                continue #訪問済
            next_state = state+POW[edge.to]
            if dp[next_state][edge.to] > dp[state][last_node]+edge.dist:
                dp[next_state][edge.to] = dp[state][last_node]+edge.dist

ans = BIG_NUM
#startに戻る
for last_node in range(V):
    if dp[POW[V]-1][last_node] == BIG_NUM:
        continue
    for edge in G[last_node]:
        if edge.to != start:
            continue
        ans = min(ans,dp[POW[V]-1][last_node]+edge.dist)

if ans == BIG_NUM:
    print("-1")
else:
    print("%d"%(ans))



Measured memory_bytes: 16308
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;

int main() {
  int S, A, B;
  cin >> S;
  B=S%100;
  A=(S-B)/100;
  if (1<=A && A<=12) {
    if (1<=B && B<=12) {
      cout << "AMBIGUOUS" << endl;
    }
    else {
      cout << "MMYY" << endl;
    }
  }
  else {
    if (1<=B && B<=12) {
      cout << "YYMM" << endl;
    }
    else {
      cout << "NA" << endl;
    }
  }
}

Measured memory_bytes: 3656
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <cstdio>
#define LL long long
#define pb push_back
#define mp make_pair
#define INF 0x3f3f3f3f
#define Inf 1000000000000000000LL
#define F first
#define S second
using namespace std;
typedef pair<int,int>pii;
int main(){
	int x,y;
	cin>>x>>y;
	if(2*x<=y&&y<=4*x&&y%2==0)puts("Yes");
	else puts("No");
	return 0;
}


Measured memory_bytes: 3128
n = int(input())
As = list(map(int, input().split()))
S = 0
for i in range(n-1):
  S += abs(As[i]-As[i+1])
S += abs(As[0]) + abs(As[n-1])
for i in range(n):
  if i == 0:
    sb1 = abs(As[i])
    sb2 = abs(As[i]-As[i+1])
    ad = abs(As[i+1])
  elif i == n-1:
    sb1 = abs(As[i-1]-As[i])
    sb2 = abs(As[i])
    ad = abs(As[i-1])
  else:
    sb1 = abs(As[i-1]-As[i])
    sb2 = abs(As[i]-As[i+1])
    ad = abs(As[i-1]-As[i+1])
    
  ans = S - sb1 - sb2 + ad
  print(ans)
  

Measured memory_bytes: 20596
#include<bits/stdc++.h>
using namespace std;
int n, k, a[300005];
int main() {
	scanf("%d %d", &k, &n);
	if (k & 1) {
		for (int i = 1; i <= n; i ++) a[i] = (k + 1) / 2;
		int now = n;
		for (int i = 1; i <= n / 2; i ++) {
			if (a[now] == 1) a[now --] = k;
			else -- a[now], now = n;
		}
		for (int i = 1; i <= now; i ++) if (a[i]) cout << a[i] << " ";
	} else {
		if (k / 2) cout << k / 2 << " ";
		for (int i = 2; i <= n; i ++) if (k) cout << k << " ";
	}
	return 0;
}

Measured memory_bytes: 3456
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define rrep(i, n) for (int i = (int)n-1; i >= 0; --i)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;

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; }

__attribute__ ((constructor))
void init() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
}

struct UnionFind{
    vector<int> d;
    UnionFind(int n) : d(n,-1) {}
    //根なら、-サイズを格納それ以外は、親を格納
    int find(int x){
        if(d[x] < 0) return x;
        return d[x] = find(d[x]); //経路縮約
    }
    bool unite(int x,int y){
        //二つ頂点を持ってくる
        x = find(x);
        y = find(y);
        if(x == y) return false;//根が一致するなら何もしない
        if(d[x] > d[y]) swap(x,y);
        //ex:d[x]=-5,d[y]=-2
        //小さい方が、大きい方に引っ付く
        d[x] += d[y];//この場合、yがxにくっつく
        d[y] = x;
        return true;
    }
    bool same(int x,int y) {return find(x) == find(y);}
    int size(int x) {return -d[find(x)];}
};

signed main(){
    int n, m;
    cin >> n >> m;
    UnionFind uf(n);
    rep(i,m){
        int a,b;
        cin >> a >> b;
        a--;
        b--;
        uf.unite(a, b);
    }
    int ans = 0;
    rep(i, n) { ans = max(ans, uf.size(i)); }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4048
#include<iostream>
#include<iomanip>
#include<string>
#include<algorithm>
#include<vector>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<math.h>
using namespace std;
using ll = int64_t;
using Graph = vector<vector<int> >;
const ll M = 1000000007;

int main(){
    ll n,m;
    cin >> n >> m;

    if(n>=3 && m>=3) {
        cout << (n-2)*(m-2) << endl;
        return 0;
    }

    if(n==2 || m==2) {
        cout << 0 << endl;
        return 0;
    }

    if((n==1 || m==1) && (n>=3 || m>=3)){
        if(n==1) cout << m-2 << endl;
        if(m==1) cout << n-2 << endl;
        return 0;
    }

    if(n==1 && m==1){
        cout << 1 << endl;
        return 0;
    }
}

Measured memory_bytes: 3608
N=int(input())
list1=list(map(int,input().split()))
list2=[]
for i in range(1,N):
  list2.append(i)
a=0
for j in range(0,N-1):
  if not list1[j]==list2[j]:
    a+=1
if a>2:
  print("NO")
else:
  print("YES")


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

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

int main() {
  deque<char> q;
  string s ;
  cin >> s ;
  
  rep(i,s.size()){
    if(s.at(i)=='B'){
     if(!q.empty())
      q.pop_back();
    }
    
    else
      q.push_back(s.at(i));
    
  }
  
  rep(i,q.size()){
    cout << q.at(i);
  }


}


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

char s[101];
ll st[101];
int top;
    
void initialize(){
    top=0;
}

bool isEmpty(){
    return top==0;
}

bool isFull(){
    return top>=Max-1;
}

void push(ll x){
    if(isFull()){
        cout<<"stack overflow"<<endl;
    }else{
        top++;
        st[top]=x;
    }
}

ll pop(){
    if(isEmpty()){
        cout<<"stack is empty"<<endl;
        return 0;
    }else{
        top--;
        return st[top+1];
    }
}

int main(){
    ll x;
    initialize();
    while(scanf("%s",s)!=EOF){
        if(s[0]=='+'){
            ll first=pop();
            ll second=pop();
            push(second+first);
        }else if(s[0]=='-'){
            ll first=pop();
            ll second=pop();
            push(second-first);
        }else if(s[0]=='*'){
            ll first=pop();
            ll second=pop();
            push(second*first);
        }else{
            x=atol(s);
            push(x);
        }
    }
    cout<<st[top]<<endl;
    return 0;
}


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define PI 3.14159265358979
#define MOD 1000000007 // = 10^9 + 7

using namespace std;
using ll = long long;


void solve()
{
	int a, b;

	cin >> a >> b;

	cout << a * b;

}

int main()
{
	fastio;
	solve();

	return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
using pii = pair<int, int>;
using ll = long long;
#define all(x) (x).begin(), (x).end()

const int MAX = 105;

char inp[MAX][MAX];
int H, W;

bool empty(int x, int y) {
  if (inp[x][y] == '#') return false;
  return true;
}

bool okay(int x, int y) { return x >= 0 && x < H && y >= 0 && y < W; }

int dp[MAX][MAX];

bool can[MAX][MAX][MAX][MAX];

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

void Visit(int startx, int starty, int x, int y) {
  can[startx][starty][x][y] = true;

  for (int i = 0; i < 2; i++) {
    int nx = x + dx[i];
    int ny = y + dy[i];
    if (!okay(nx, ny) || can[startx][starty][nx][ny]) continue;
    if (empty(nx, ny) == empty(x, y)) Visit(startx, starty, nx, ny);
  }
}

int main() {
  cin >> H >> W;
  for (int i = 0; i < H; i++) {
    scanf("%s", inp[i]);
  }

  if (!empty(0, 0)) {
    dp[0][0] = 1;
  }

  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      Visit(i, j, i, j);
    }
  }

  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (i == 0 && j == 0) continue;
      dp[i][j] = MAX * MAX;
      int add = 0;
      if (!empty(i, j)) add++;

      for (int k = 0; k <= i; k++)
        for (int l = 0; l <= j; l++) {
          if (!can[k][l][i][j]) continue;
          if (k == 0 && l == 0) {
            dp[i][j] = min(dp[i][j], add);
          }
          for (int d = 0; d < 2; d++) {
            int lastx = k - dx[d];
            int lasty = l - dy[d];
            if (!okay(lastx, lasty)) continue;
            dp[i][j] = min(dp[i][j], add + dp[lastx][lasty]);
          }
        }
    }
  }
  cout << dp[H - 1][W - 1] << endl;

  return 0;
}

Measured memory_bytes: 114944
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
using ll=long long;
static const ll mod = 1e9 + 7;
static const ll INF = 1LL << 50;
using namespace std;

int main(){	
	int n,a,b;
	cin>>n>>a>>b;
	int minv=min(n*a,b);
	cout<<minv<<endl;
}


Measured memory_bytes: 256
class Node
  attr_accessor :name, :child, :done, :cost
  def initialize(i)
    @name = i
    @child = {}
    @done = false
    @cost = 1.0 / 0.0
  end
  def >(other)
    return self.cost < other.cost ? true : false
  end
  def <(other)
    return self.cost > other.cost ? false : true
  end
end

class Graph
  attr_accessor :node
  def initialize(v)
    @node = Array.new(v){|i| Node.new(i)}
  end
  def print
    @node.size.times{|i|
      if @node[i].cost < 1.0 / 0.0
        puts @node[i].cost
      else
        puts "INF"
      end
    }
  end
end

class Heep
  def initialize
    @node = []
  end
  def insert(num)
    i = @node.size
    @node[i] = num
    p = (i+1)/2-1
    while i > 0 && @node[p] < @node[i]
      @node[i], @node[p] = @node[p], @node[i]
      i = p
      p = (i+1)/2-1
    end
  end
  def extract
    ret = @node[0]
    if @node.size > 1
      @node[0] = @node.pop()
      maxHeapify(0)
    else
      @node = []
    end
    return ret
  end
  def maxHeapify(i)
    h = @node.size
    largest = i
    l = 2 * i + 1
    largest = l if l < h && @node[l] > @node[largest]
    r = 2 * i + 2
    largest = r if r < h && @node[r] > @node[largest]
    if largest != i then
      @node[i], @node[largest] = @node[largest], @node[i]
      maxHeapify(largest)
    end
  end
  def size
    return @node.size
  end
  def contain(node)
    if @node.index(node) == nil
      return false
    else
      return true
    end
  end
end

v, e, r = gets.split.map(&:to_i)

graph = Graph.new(v)

e.times{
  s, t, d = gets.split.map(&:to_i)
  graph.node[s].child[t] = d
}

q = Heep.new
graph.node[r].cost = 0
q.insert(graph.node[r])

loop do
  break if q.size == 0
  doneNode = q.extract
  doneNode.done = true
  doneNode.child.each{|t,d|
    cost = doneNode.cost + d
    if cost < graph.node[t].cost then
      graph.node[t].cost = cost
      q.insert(graph.node[t])
    end
  }
end

graph.print

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

int main()
{
    int n, d;
    cin >> n >> d;
    int ans = 0;
    ans = n / (d * 2 + 1);
    if (n % (d * 2 + 1) != 0)
    {
        ans++;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#define ll long long
#define MOD 1000000007 
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define T long long t;cin>>t;while(t--)
#define foe(i) for(int i=1;i<=n;i++)
#define fo(i) for(int i=0;i<n;i++)
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll n;
  cin>>n;
  ll a[55];
  for(int i=0;i<n;i++)
  cin>>a[i];
  sort(a,a+n);
  a[1]+=a[0];
  long double ans=0;
  int j=1;
  for(ll i=1;i<=pow(2,n-2);i=i*2)
  {
    ans+=i*a[j];
    j++;
  }
  ans=ans/pow(2,n-1);
  cout<<ans;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = (n-1); i >= 0; i--)
using namespace std;
typedef long long ll;
//const int MOD = 1000000007;
const ll INF = 1LL<<60;
const int IINF = 1000000000;
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; }

const int MOD = 998244353;

struct mint {
    ll x;
    mint(ll x=0):x((x%MOD+MOD)%MOD){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    bool operator==(const mint a){
        return (x == a.x);
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime MOD
    mint inv() const {
        return pow(MOD-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
// 2項係数を求める
struct combination {
    vector<mint> fact, ifact;
    combination(int n):fact(n+1),ifact(n+1) {
        assert(n < MOD);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
};

//nが非常に大きく、aが小さい場合
mint choose(int n, int a){
    mint x = 1, y = 1;
    rep(i,a){
        x *= n-i;
        y *= i+1;
    }
    return x/y;
}
int main(){

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

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

    combination c(N+1);
    mint ans = 0;
    mint color_pattern = M;
    for(int x = N-1; x >= 0; --x){
        mint now = color_pattern;
        now *= c(N-1,(N-1-x));
        if (x <= K) ans += now;
        color_pattern *= (M-1);
    }
    cout << ans << endl;
}

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

typedef long long ll;
typedef long double ld;
typedef vector<vector<int>> Graph;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
#define pi 3.14159265359
#define inf 2147483647
#define INF 9223372036854775807
#define mod 1000000007
#define mod2 998244353

int main() {
	string S; cin >> S;
	if(S.back() == 's') S += "es";
	else S += "s";
	cout << S << endl;
	return 0;
}


Measured memory_bytes: 3596
use std::io;

fn main() {
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let n:u8 = match buf.trim().to_string().parse(){
		Ok(m) => m,
		_ => panic!(""),
	};
	
	let mut buf = String::new();
	io::stdin().read_line(&mut buf).expect("");
	let s = buf.trim().as_bytes();
	let a = ("A".as_bytes())[0];
	let ret = s.iter().map(|&m| (a + (m - a + n)%26) as char).collect::<String>();
	println!("{}", ret);
	//assert_eq!("NOPQRSTUVWXYZABCDEFGHIJKLM", ret);
}

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

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

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

const int MAX = 1e5 + 5;
const int INF = 1001001001;
const int MOD = 1e9 + 7;

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

    vector<ll> A(N);
    rep(i, N) cin >> A[i];

    ll ans = 0;
    ll d = 1;
    rep(i, 60) {
        int cnt = 0;
        rep(j, N) {
            if (A[j] >> i & 1) cnt++;
        }
        ans += (ll)cnt * (N - cnt) % MOD * d % MOD;
        ans %= MOD;
        d *= 2;
        d %= MOD;
    }

    cout << ans << endl;
}

Measured memory_bytes: 2560
x = int(input())

pow_li = [pow(i,5) for i in range(1000)]

for i in range(1000):
    for j in range(1000):
        if pow_li[i]-pow_li[j]==x:
            print(i,j);exit()
        elif pow_li[i]+pow_li[j]==x:
            print(i,-j);exit()

Measured memory_bytes: 9200
#include <iostream>
#include <vector>

using namespace std;

int main() {
    int N;
    cin >> N;
    while(N--) {
        vector<int> v(10);
        for(int i = 0; i < 10; ++i) cin >> v[i];
        bool ok = false;
        for(int pat = 0; pat < (1<<10); ++pat) {
            bool sorted = true;
            int prev = -1;
            for(int i = 0; i < 10; ++i) {
                if(pat & (1<<i)) {
                    if(v[i] < prev) {
                        sorted = false;
                        break;
                    }
                    prev = v[i];
                }
            }
            prev = -1;
            for(int i = 0; i < 10; ++i) {
                if(~pat & (1<<i)) {
                    if(v[i] < prev) {
                        sorted = false;
                        break;
                    }
                    prev = v[i];
                }
            }
            if(sorted) {
                ok = true;
                break;
            }
        }

        cout << (ok?"YES":"NO") << endl;
    }
    return 0;
}

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

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

    string s;
    cin >> s;

    int ans = 0;
    int x = 0;
    for(int i=0; i<n; i++) {
        if(s[i] == 'I'){
            x++;
            ans = max(ans,x);
        } else x--;
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()		//sort(all(vi S)) sort(all(string S))

typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

const int MOD = 1e9+7;
const int INF = 1e9;

int main() {
	int A,B,K;
	cin>>A>>B>>K;
	int cnt = 0,ans = 0;
	rep1(i,max(A,B)+1){
		int x = max(A,B) + 1 -i;
		if(A%x==0&&B%x==0)cnt++;
		if(cnt==K){
			ans = x;
			break;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
     
int main() {
  int N,a;
  int b = 0;
  cin >> N;
  vector<int> vec(N);
  for(int i = 0; i < N; i++){
  cin >> vec.at(i);
  }
  sort(vec.begin(),vec.end());
  int dan = 0;
  for(int i = 0; i < N; i++){
  a = vec.at(i);
    if(a > b){
      dan += 1;
    }
  b = vec.at(i);
  }
  cout << dan << endl;
}

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

using namespace std;  //min(cost[i-2]+abs(h[i]-h[i-2]),cost[i-1]+abs(h[i]-h[i-1]))

int main(){
    int N;
    int h[100005];
    int cost[100005];
    cost[0]=0;
    cin>>N;
    for(int i=0;i<N;i++){
        cin>>h[i];
        if(i>=1){
            cost[i]=abs(h[i]-h[i-1]);
        }
        if(i>=2){
            cost[i]=min(cost[i-2]+abs(h[i]-h[i-2]),cost[i-1]+abs(h[i]-h[i-1]));
        }
    }
    cout<<cost[N-1]<<endl;
    return 0;
}

Measured memory_bytes: 4428
N, K = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]


def solve():
    ans = 0
    bigable = True

    for i in range(41)[::-1]:

        tmp = 1 << i
        sum_ = 0
        for a in A:
            sum_ += (tmp & a > 0)

        # Kより大きい可能性があったら0確定
        if bigable and K & tmp == 0:
            ans += sum_ * tmp
            continue

        # 1のほうが多かったら、0を選択
        if sum_ >= N / 2:
            ans += sum_ * tmp
            if K & tmp > 0:
                bigable = False
        else:
            ans += (N - sum_) * tmp

    print(ans)


if __name__ == '__main__':
    solve()


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

using namespace std;

int main(){
    int K, T;
    int a[10000];

    cin >> K >> T;

    for (int i = 0; i < T; i++) {
        cin >> a[i];
    }

    for (int i = 0; i < T - 1; i++) {
        for (int j = i; j < T; j++) {
            if (a[i] < a[j]) {
                a[i] ^= a[j];
                a[j] ^= a[i];
                a[i] ^= a[j];
            }
        }
    }

    for (int i = 1; i < T; i++) {
        a[0] -= a[i];
    }

    if (a[0] > 0) {
        cout << a[0] - 1 << endl;
    }
    else {
        cout << 0 << endl;
    }

    return(0);
}


Measured memory_bytes: 384
import java.io.*;
import java.util.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
            reader.lines()
                .map(line -> Arrays.stream(line.split(" "))
                        .mapToInt(Integer::parseInt)
                        .toArray())
                .forEach(in -> {
                    int a = in[0];
                    int b = in[1];
                    int c = in[2];
                    int d = in[3];
                    
                    int start = Math.max(a,c);
                    int end = Math.min(b,d);
                    System.out.println( (end-start)>0 ? end-start : 0 );
                });
        }
    }
}

Measured memory_bytes: 28628
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
using namespace std;



#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1, T2> P)
{
	return s << '<' << P.first << ", " << P.second << '>';
}
template<class T> ostream& operator << (ostream &s, vector<T> P)
{
	for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s;
}
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{
	for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl;
}



vector<pair<string,int> > decode(string str) {
	vector<pair<string, int> > res;
    int num = 0;
	string tmp = "";
    for (auto c : str) {
		if (c >= '0' && c <= '9') {
			num *= 10, num += c - '0';
		}
		else {
			if (num != 0) {
				res.push_back({ tmp, num });
				tmp = "";
				num = 0;
			}
			tmp += c;
		}
    }
	if (tmp != "" || num != 0) res.push_back({ tmp, num });
	return res;
}

int main() {
    int N; cin >> N;
    string S0; cin >> S0;
    auto p0 = decode(S0);
	//COUT(p0);
    for (int i = 0; i < N; ++i) {
        string S; cin >> S;
        auto p = decode(S);
		//COUT(p);
        if (p >= p0) puts("+");
        else puts("-");
    }
}



Measured memory_bytes: 3204
using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] ans = { 0, 0, 0 };
            for (int i = 0; i < 10; i++)
            {
                string a = Console.ReadLine();
                int aa = int.Parse(a);

                if (ans[0] < aa)
                {
                    ans[2] = ans[1];
                    ans[1] = ans[0];
                    ans[0] = aa;
                }
                else if (ans[1] < aa)
                {
                    ans[2] = ans[1];
                    ans[1] = aa;
                }
                else if (ans[2] < aa)
                {
                    ans[2] = aa;
                }
            }

            Console.WriteLine(ans[0]);
            Console.WriteLine(ans[1]);
            Console.WriteLine(ans[2]);
            Console.ReadLine();

            //    for (int i = 1; i <= 9; i++)
            //    {
            //        for (int ii = 1; ii <= 9; ii++)
            //        {
            //            string ans;
            //            ans = i+"x"+ii+"="+i*ii;
            //            Console.WriteLine(ans);

            //        }

            //    }
            //            Console.ReadLine();        }
        }
    }
}

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

using namespace std;

typedef long long ll;

int main() {
    vector<bool> reached(1e6 + 1, false);
    int s;
    cin >> s;
    int i = 1;
    int cur;
    while (1) {
        if (i == 1) {
            cur = s;
            reached[cur] = true;
            i++;
            continue;
        }
        if (cur % 2 == 1) {
            cur = 3 * cur + 1;
        } else {
            cur = cur / 2;
        }
        if (reached[cur]) {
            cout << i;
            break;
        }
        reached[cur] = true;
        i++;
    }
    return 0;
}


Measured memory_bytes: 384
def binarySearch(a, val):
    left, right = -1, len(a)
    while left + 1 < right:
        mid = (left + right) >> 1
        if a[mid] < val:
            left = mid
        else:
            right = mid
    return a[right] if right < len(a) else 1 << 35

def binarySearch2(a, val):
    left, right = -1, len(a)
    while left + 1 < right:
        mid = (left + right) >> 1
        if a[mid] <= val:
            left = mid
        else:
            right = mid
    return a[left] if left >= 0 else -(1 << 35)

nShrines, nTemples, nQueries = map(int, input().split())
shrines = [int(input()) for _ in range(nShrines)]
temples = [int(input()) for _ in range(nTemples)]
starts = [int(input()) for _ in range(nQueries)]
ret = []
for start in starts:
    shrineToRight = binarySearch(shrines, start)
    templeToRight = binarySearch(temples, start)
    shrineToLeft = binarySearch2(shrines, start)
    templeToLeft = binarySearch2(temples, start)
    ret.append(min(
        max(shrineToRight, templeToRight) - start,
        start - min(shrineToLeft, templeToLeft),
        templeToRight - start + templeToRight - shrineToLeft,
        shrineToRight - start + shrineToRight - templeToLeft,
        start - shrineToLeft + templeToRight - shrineToLeft,
        start - templeToLeft + shrineToRight - templeToLeft
    ))
print('\n'.join(map(str, ret)))


Measured memory_bytes: 27156
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 2147483647 / 2;
const long long int llINF = 9223372036854775807 / 2;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VV(T, a, b, c) vector<vector<T>>(a, vector<T>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define VVV(T, a, b, c, d)                                                     \
  vector<vector<vector<T>>>(a, vector<vector<T>>(b, vector<T>(c, d)))
#define SP(a) setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))
#define UNIQUE(vec)                                                            \
  do {                                                                         \
    sort(ALL((vec)));                                                          \
    (vec).erase(std::unique(ALL((vec))), (vec).end());                         \
  } while (0)

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll N, M;
  cin >> N >> M;
  vl A;
  if (N == M)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}


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

using namespace std;
string s;
int main() {
G:
	while (getline(cin, s) && s != ".") {
		stack<char> p;
		for (int i = 0;i < s.length();i++) {
			if (s[i] == '(' || s[i] == '[')p.push(s[i]);
			if (s[i] == ')') { if (p.empty() || p.top() != '(') { cout << "no" << endl;goto G; }p.pop(); }
			if (s[i] == ']') { if (p.empty() || p.top() != '[') { cout << "no" << endl;goto G; }p.pop(); }
		}
		cout << (p.empty() ? "yes" : "no") << endl;
	}
	return 0;
}

Measured memory_bytes: 3212
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);
#define FO cout.tie(NULL);
#define FI cin.tie(NULL);
#define IN cin>>
#define OUT cout<<
#define loop(i,a,n) for(int i=a; i<n; i++)
#define rloop(i,a,n) for(int i=a; i>=n; i--)
#define endl "\n";
#define pb push_back
#define mp make_pair
#define set_bits(a) __builtin_popcountll(a)
#define ll long long int
#define ld long double
#define vll vector<long long int>
#define pll pair<long long int, long long int>
#define mod 1000000007
#define M 998244353
ll gcd(ll a, ll b)
{
    return (b?gcd(b,a%b):a);
}
ll P(ll B, ll power, ll modulo)
{
    ll ans=1LL;
    while(power>0LL)
    {
        if(power%2LL==1LL)
        {
            ans=(ans*B)%modulo;
        }
        B=(B*B)%modulo;
        power/=2LL;
    }
    return ans;
}
bool isPrime(ll n)
{
    if(n<=1LL)
    {
        return false;
    }
    if(n<=3LL)
    {
        return true;
    }
    if(n%2==0LL || n%3==0LL)
    {
        return false;
    }
    for(ll i=5LL; (i*i)<=n; i+=6LL)
    {
        if(n%i==0LL || n%(i+2LL)==0LL)
        {
            return false;
        }
    }
    return true;
}
using namespace std;
bool sortbysec(const pair<int,int> &a, const pair<int,int> &b)
{
    return (a.second<b.second);
}
bool sortbysecll(const pll &a, const pll &b)
{
    return (a.second<b.second);
}
ll modinv(ll x, ll y, ll modulo)
{
    return ((x%modulo)*(P(y,modulo-2LL,modulo)%modulo))%modulo;
}
void vok()
{
    FAST
    FO
    FI
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
}
const int mxN= 200010;
int t[mxN], ans[mxN];
int main()
{
    //vok();
    string s;
    IN s;
    if(s[2]==s[3] && s[4]==s[5])
    {
        OUT "Yes"<<endl
    }
    else
    {
        OUT "No"<<endl
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF (1ll << 60)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
using vl = vector<ll>;
using vvl = vector<vl>;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

int main() {
    int N;
    cin >> N;
    vector<ll> d(N);
    REP(i, N) { cin >> d[i]; }
    ll res = 0LL;
    for(int i = 0; i < N; i++) {
        for(int j = i + 1; j < N; j++) {
            res += d[i] * d[j];
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.util.Arrays;
import java.util.StringTokenizer;

class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(in, out);
        out.close();
    }

    static class Task {
        void solve(InputReader in, PrintWriter out) {
            // write your code here
            int N = in.nextInt();
            int K = in.nextInt();
            long h[] = new long[N];
            for (int i = 0; i < N; i++) {
                h[i] = in.nextLong();
            }

            Arrays.sort(h);

            long minDiff = Long.MAX_VALUE;
            for (int i = 0; i < N - K + 1; i++) {
                long diff = h[i + K - 1] - h[i];
                minDiff = Math.min(diff, minDiff);
            }

            out.println(minDiff);
        }
    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

        String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }
    }
}

Measured memory_bytes: 38808
#include<stdio.h>
#include<math.h>
#define N 100

int main(void){
  int i,n,j;
  double x1[N],y1[N],x2[N],y2[N],x3[N],y3[N];
  double a1,b1,c1;
  double a2,b2,c2;
  double xp,yp,r;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%lf%lf%lf%lf%lf%lf",&x1[i],&y1[i],&x2[i],&y2[i],&x3[i],&y3[i]);
  }
  for(i=0;i<n;i++){
    a1=2*(x2[i]-x1[i]);
    b1=2*(y2[i]-y1[i]);
    c1=x1[i]*x1[i]-x2[i]*x2[i]
      +y1[i]*y1[i]-y2[i]*y2[i];
    a2=2*(x3[i]-x1[i]);
    b2=2*(y3[i]-y1[i]);
    c2=x1[i]*x1[i]-x3[i]*x3[i]
      +y1[i]*y1[i]-y3[i]*y3[i];
    xp=(b1*c2-b2*c1)/(a1*b2-a2*b1);
    yp=(c1*a2-c2*a1)/(a1*b2-a2*b1);
    r=sqrt((xp-x1[i])*(xp-x1[i])+(yp-y1[i])*(yp-y1[i]));
    printf("%0.3f %0.3f %0.3f\n",xp,yp,r);
  }
  return 0;
}

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

int main(){
  int s, cnt = 0;
  cin >> s;
  if(s/100 == 1){
    cnt++;
    s -= 100;
  }
  if(s/10 == 1){
    cnt++;
    s -= 10;
  }
  if(s == 1){
    cnt++;
  }

  cout << cnt << endl;


  return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define RFOR(i,a,n) for(ll i=(ll)n-1;i >= (ll)a;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,0,n)
#define ALL(v) v.begin(), v.end()
#define bra(first,second) '(' << first << ',' << second << ')'
constexpr ll MOD = 1000000007;
ll INF = 1001001001001001001;
long double EPS = 1e-11;
long double PI = 3.141592653589793238;
template<typename T>
void remove(std::vector<T>& vector, unsigned int index){
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<ll>>;

int main(){
    ll N;
    cin >> N;
    vector<ll> A(N+1),B(N+1);
    rep(i,N) cin >> A[i+1];
    ll M;
    rrep(i,N+1){
        if(i == 0) break;
        ll cnt = 0;
        for(ll j = 0;j * i <= N;j++){
            cnt += B[i*j];
        }
        if(A[i] % 2 != cnt % 2){
            B[i]++;
                M++;
        }
    }
    cout << M << endl;
    rep(i,N+1){
        if(B[i] > 0) cout << i << endl;
    }
}


Measured memory_bytes: 3968
n=int(input())
a=list(map(int, input().split()))
two=0
four=0

for i in a:
    if i%4==0:
        four+=1
    elif i%2==0:
        two+=1
        
if 2*four+two>=n or 2*four+1>=n:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 15020
n,m=map(int,input().split())
a=list()
b=list() 

for i in range(n):
    a.append(list(map(int,input().split())))
    
for i in range(m):
    b.append(int(input()))
    
for i in range(n):
    c=0
    for j in range(m):
        c += a[i][j]*b[j]
    print(c)


Measured memory_bytes: 6004
S = input()

max_cnt = 0
tmp_cnt = 0
for i in range(len(S)):
    if S[i] in 'ACGT':
        tmp_cnt += 1
    else:
        max_cnt = max(max_cnt, tmp_cnt)
        tmp_cnt = 0

print(max(max_cnt, tmp_cnt))




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

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

#define MAX 1145141919

int main(){
        ll e;
        bool ok=false;
        while(cin>>e&&e){
                ll ans=MAX;
                for(ll i=0;i<=1000;i++){
                        for(ll j=0;j<=1000;j++){
                                ll x=e-i*i-j*j*j;
                                if(x<0)continue;
                                ll tmp=x+i+j;
                                if(tmp<ans)ans=tmp;
                        }
                }
                cout<<ans<<endl;
        }
        return 0;
}



Measured memory_bytes: 3080
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		
		int x = sc.nextInt();
		
		if(x<1200) {
			System.out.println("ABC");
		}else if(x >= 1200) {
			System.out.println("ARC");
		}
	}
}


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

int main(){
    int n; cin >> n;
    int ans = 0;
    int b = 0;
    int c = 0;
    for(int i = 0; i < n; i++){
        int mid; cin >> mid;
        if(mid <= c){
            b++;
        }else{
            ans = max(ans, b);
            b = 0;
        }
        c = mid;
    }
    ans = max(ans, b);
    cout << ans << endl;
}

Measured memory_bytes: 256
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

enum inf3 = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;


void main() {
    int n, m;
    scan(n, m);
    auto c = new int[][](n, n);
    fillAll(c, inf3);
    foreach (i ; 0 .. n) {
        c[i][i] = 0;
    }
    foreach (i ; 0 .. m) {
        int ai, bi, ci;
        scan(ai, bi, ci);
        ai--, bi--;
        c[ai][bi] = c[bi][ai] = ci;
    }

    auto d = new int[][](n, n);
    fillAll(d, inf3);
    foreach (i ; 0 .. n) {
        foreach (j ; 0 .. n) {
            d[i][j] = c[i][j];
        }
    }

    foreach (k ; 0 .. n) {
        foreach (i ; 0 .. n) {
            foreach (j ; 0 .. n) {
                d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
            }
        }
    }

    int ans;

    foreach (i ; 0 .. n) {
        foreach (j ; i + 1 .. n) {
            if (c[i][j] != inf3 && c[i][j] > d[i][j]) {
                ans++;
            }
        }
    }

    writeln(ans);
}







void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


Measured memory_bytes: 380
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef long long ll;

#define INF 10e17 // 4倍しても(4回足しても)long longを溢れない
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())

int main() {
  string s;
  cin >> s;
  int a = 0,b = 0;

  for (auto itr : s) {
    if (itr == '1') a += 1;
    else b += 1;
  }

  cout << s.size() - abs(a-b) << endl;
}


Measured memory_bytes: 512
#include <iostream> // cout, endl, cin
#include <vector> // vector
using namespace std;

int main(){
    int N,sum;
    cin>>N;
    vector<int> d(N);
    for(int i=0;i<N;i++){
        cin>>d.at(i);
    }
    sum=0;
    for(int i=0;i<N-1;i++){
        for(int j=i+1;j<N;j++){
            sum=sum+d.at(i)*d.at(j);
        }
    }
    cout<<sum;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    string s;
    cin >> s;
    set<char> kinds(ALL(s));
    if (kinds.size() == 26) {
        cout << "None" << endl;
        return 0;
    }

    for (char c = 'a'; c <= 'z'; c++) {
        if (kinds.find(c) == kinds.end()) {
            cout << c << endl;
            return 0;
        }
    }
    cout << "None" << endl;
    return 0;
}

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

using namespace std;

int main () {
  int K;
  string S;
  cin >> K;
  cin >> S;

  if ( S.length() <= K )
  {
    cout << S;
  }
    else if (S.length() > K)
  {
    cout << S.substr(0, K) + "...";
  }
}


Measured memory_bytes: 3632
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

h,w=map(int,input().split())
S=[list(input()) for i in range(h)]
dydx４=((-1,0),(0,-1),(0,1),(1,0))
for i in range(h):
    for j in range(w):
        if S[i][j]=="#": continue
        color=[[-1]*w for i in range(h)]
        color[i][j]=0
        que=collections.deque()
        que.append((i,j,0))
        while que:
            pi,pj,now = que.popleft()
            for di,dj in dydx４:
                ni=pi+di; nj=pj+dj
                if 0<=ni<h and 0<=nj<w:
                    if color[ni][nj]==-1 and S[ni][nj]==".":
                        que.append((ni,nj,now+1))
                        color[ni][nj]=now+1
        tmp=0
        for ci in color:
            tmp=max(tmp,max(ci))
        ans=max(ans,tmp)
        # print(tmp)
        # if i==j==0:
        #     print(*color,sep="\n")
print(ans)
            


Measured memory_bytes: 47196
#ifdef DEBUG
#include "../../lib/utils.cpp"
#endif
#include <bits/stdc++.h>

using namespace std;
using ll = int64_t;
#define int int64_t
#define INF 10e9

 
/* ==== declarations ====== */
// functions
void solve();
void getInput();
 
// global variables
int N;
vector<int> A;




void getInput() {
    cin>>N;
    A = vector<int>(N);
    for(int i=0; i<N; ++i) {
        cin>>A[i];
    }
}
 
vector<int> getDivisors(int n) {
    vector<int> ret;
    for (int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    return ret;
}

void solve() {
    int score = 0;
    map<int, int> cnt;
    for (auto a: A) {
        cnt[a] += 1;
    }
    for(auto a: A) {
        if (cnt[a] > 1) continue;
        auto divisors = getDivisors(a);
        bool ng = false;
        for(auto d: divisors) {
            if (d==a) continue;
            if (cnt.count(d) > 0) {
                ng=true;
            }
        }
        if (!ng) {
            score += 1;
        }
    }
    cout<<score<<endl;
}
 
 
signed main(){
    getInput();
    solve();
    
    return 0;
}


Measured memory_bytes: 17080