akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define li long long int
#define rep(i, to) for (li i = 0; i < ((li)(to)); i++)
#define repp(i, start, to) for (li i = (li)(start); i < ((li)(to)); i++)

// Implement (union by size) + (path compression)
// Reference:
// Zvi Galil and Giuseppe F. Italiano,
// Data structures and algorithms for disjoint set union problems
struct dsu {
public:
	dsu() : _n(0) {}
	dsu(int n) : _n(n), parent_or_size(n, -1) {}

	int merge(int a, int b) {
		assert(0 <= a && a < _n);
		assert(0 <= b && b < _n);
		int x = leader(a), y = leader(b);
		if (x == y) return x;
		if (-parent_or_size[x] < -parent_or_size[y]) std::swap(x, y);
		parent_or_size[x] += parent_or_size[y];
		parent_or_size[y] = x;
		return x;
	}

	bool same(int a, int b) {
		assert(0 <= a && a < _n);
		assert(0 <= b && b < _n);
		return leader(a) == leader(b);
	}

	int leader(int a) {
		assert(0 <= a && a < _n);
		if (parent_or_size[a] < 0) return a;
		return parent_or_size[a] = leader(parent_or_size[a]);
	}

	int size(int a) {
		assert(0 <= a && a < _n);
		return -parent_or_size[leader(a)];
	}

	std::vector<std::vector<int>> groups() {
		std::vector<int> leader_buf(_n), group_size(_n);
		for (int i = 0; i < _n; i++) {
			leader_buf[i] = leader(i);
			group_size[leader_buf[i]]++;
		}
		std::vector<std::vector<int>> result(_n);
		for (int i = 0; i < _n; i++) {
			result[i].reserve(group_size[i]);
		}
		for (int i = 0; i < _n; i++) {
			result[leader_buf[i]].push_back(i);
		}
		result.erase(
		    std::remove_if(result.begin(), result.end(),
		[&](const std::vector<int>& v) { return v.empty(); }),
		result.end());
		return result;
	}

private:
	int _n;
	// root node: -1 * component size
	// otherwise: parent
	std::vector<int> parent_or_size;
};

li p[100100];

int main(void)
{
	li n, m;
	cin >> n >> m;
	dsu d(n);
	rep(i, n) {
		cin >> p[i];
		p[i]--;
	}

	rep(i, m) {
		li x, y;
		cin >> x >> y;
		x--;
		y--;
		d.merge(x, y);
	}


	li res = 0;
	auto groups = d.groups();

	for (auto && group : groups) {
		set<li> st;
		for (auto& idx : group) {
			st.insert(idx);
		}
		for (auto& idx : group) {
			if (st.count(p[idx]) > 0) {
				res++;
			}
		}
	}

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 11556
#include <stdio.h>

int main(void){
  int a, i;
  int b = 0;
  int c = 1;
  int n;
  
  scanf("%d",&n); 
  for(i=0;i<=n;i++){ 
    a = b+c;
    b = c;
    c = a;
  }
  printf("%d\n", b);
  
  return 0;
}

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

int main() {
	int N, X, m[101];
	cin >> N >> X;
	int S=0, M = 10000;
	for (int i = 0; i < N; i++) {
		cin >> m[i];
		S += m[i];
		if (m[i] < M) {
			M = m[i];
		}
	}
	int ans = N + (X - S) / M;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<(int)(n);i++)
#define N 200000

int main() {
	int x, y, z;
	int s, ans;
	ans = 0;


	scanf("%d %d %d", &x, &y, &z);


	if(x==y&&y==z)printf("Yes\n");
	else printf("No\n");


	return 0;
}



Measured memory_bytes: 128
N = int(input())
H = list(map(int,input().split()))
H.append(0)
ans = 0
maxH = max(H)
for h in range(maxH):
    state = 0
    for n in range(N+1):
        if H[n] > 0:
            H[n] -= 1
            state = 1
        elif H[n] == 0 and state == 1:
            state = 0
            ans += 1
        else:
            pass
print(ans)


Measured memory_bytes: 3060
program palindrome_phobia
  implicit none
  character(100) :: s
  integer :: h, w, n(26), i, j, g(3)
  logical :: f
  read(*,*) h, w
  n = 0
  do i = 1, h
    read(*,*) s
    s = trim(adjustl(s))
    do j = 1, w
      n(ichar(s(j:j))-96) = n(ichar(s(j:j))-96)+1
    end do
  end do
  g(1) = mod(h,2)*mod(w,2)
  g(2) = mod(w,2)*(h/2)+mod(h,2)*(w/2)
  g(3) = (h/2)*(w/2)
  do while (g(1).gt.0)
    do i = 1, 26
      if (mod(n(i),2).eq.1) then
        n(i) = n(i)-1
        exit
      end if
    end do
    g(1) = g(1)-1
  end do
  do while (g(2).gt.0)
    f = .false.
    do i = 1, 26
      if (mod(n(i),4).eq.2) then
        n(i) = n(i)-2
        f = .true.
        exit
      end if
    end do
    if (f) then
      g(2) = g(2)-1
      cycle
    end if
    if (g(1).eq.1) exit
    do i = 1, 26
      if (n(i).eq.0) cycle
      if (mod(n(i),4).eq.0) then
        n(i) = n(i)-4
        exit
      end if
    end do
    g(2) = g(2)-2
  end do
  do while (g(3).gt.0)
    do i = 1, 26
      if (n(i).eq.0) cycle
      if (mod(n(i),4).eq.0) then
        n(i) = n(i)-4
        exit
      end if
    end do
    g(3) = g(3)-1
  end do
  if (sum(n).eq.0) then
    write(*,'(a)') "Yes"
  else
    write(*,'(a)') "No"
  end if
  stop
end program palindrome_phobia

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int r, g, b;
  cin >> r >> g >> b;
  if (stoi(to_string(r) + to_string(g) + to_string(b)) % 4 == 0) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (n); i++)
typedef long long ll;
using namespace std;

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

    if (A >= K) {
        cout << A - K << " " << B << endl;
        return 0;
    }
    else if(K >= A + B){
        cout << 0 << " " << 0 << endl;
        return 0;
    }
    else {
        cout << 0 << " " << A + B - K << endl;
    }

    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

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

if x ==0:
    print(sum(a))
    exit()

ans = 0

if a[0]>x:
    ans += a[0]-x
    a[0]=x

for i in range(1,n):
    two = a[i-1]+a[i]
    if two > x:
        tmp = two-x
        ans += tmp
        if tmp > a[i]: a[i]=0
        else: a[i] = a[i]-tmp

print(ans)


Measured memory_bytes: 14196
/**
 *   author: Shubham Srivastava
 *   created: 27 January 2020  20:35:16
**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define MOD 1000000007
#define INF 0x7fffffff
#define sorti(v) sort(v.begin(),v.end())
#define sortd(v) sort(v.rbegin(),v.rend())
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;
ll parent[2000005];

ll helper(vector <ll> &arr, ll sum, ll i, ll j, vector <vector <ll> > &dp){
	if(i > j)
		return 0;
	if(i == j)
		return arr[j];
	if(i+1 == j)
		return max(arr[i],arr[j]);
	if(dp[i][j] != -1)
		return dp[i][j];
	return dp[i][j] = max(sum - helper(arr,sum-arr[i],i+1,j,dp), sum - helper(arr,sum-arr[j],i,j-1,dp));
}

int main(){
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    ll n;cin>>n;
    ll sum = 0;
    vector <ll> arr(n);
    vector <vector <ll> > dp(n, vector <ll> (n,-1));
    for(int i=0;i<n;i++){
    	cin>>arr[i];    
    	sum += arr[i];
    }
    ll val1 = helper(arr,sum,0,n-1,dp);
    ll val2 = sum - val1;
    cout<<val1-val2;
return 0;
}

Measured memory_bytes: 70912
#include <cstdio>
#include <climits>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <list>
#include <set>
#include <bitset>
#include <iterator>
#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;
using namespace std;
typedef long long int LL;
typedef unsigned long long int ULL;

using Edge = pair<LL, LL>;
using Graph = vector<vector<Edge> >;

int n;
Graph graph;
vector<int> res;

void dfs(int v, int parent, int color) {
    res[v] = color;
    for (auto e : graph[v]) {
        if (e.first == parent) continue;
        if (e.second % 2 != 0) dfs(e.first, v, 1 - color);
        else dfs(e.first, v, color);
    }
}
int main() {
    cin >> n;
    graph.assign(n, vector<Edge>());

    rep(i, n - 1) {
        LL u, v, w;
        cin >> u >> v >> w;
        u--;
        v--;
        graph[u].push_back(Edge(v, w));
        graph[v].push_back(Edge(u, w));
    }
    res.assign(n, 0);
    dfs(0, -1, 1);
    for (auto i: res) {
        cout << i << endl;
    }
}


Measured memory_bytes: 10496
function Main(input) {
  // 数字
  var N = parseInt(input[0], 10);
  var S = input[1];

  // 0番目から探索するためrightWには全ての白を初期値として入れる
  var leftB = 0;
  var rightW = S.split('.').length - 1;

  var result = rightW;
  
  for (var i = 0; i < S.length; i++) {
    if (S.charAt(i) === '.') {
      rightW--;
    } else {
      leftB++;
    }
    result = (rightW + leftB) < result ? (rightW + leftB) : result;
  }

  console.log(result);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim().split(/\n|\s/));

Measured memory_bytes: 9932
implicit none
character(100) :: s
integer :: l,i

read*,s
l = len_trim( s )

do i = 1,l
  if( mod(i,2)==1 )then
    if( s(i:i)=='L' ) goto 100
  else
    if( s(i:i)=='R' ) goto 100
  end if
end do

print*,'Yes'
stop

100 continue
print*,'No'
end


Measured memory_bytes: 256
#! /usr/bin/env python
# -*- coding: utf-8 -*-

import os
import sys
import itertools
import math
from collections import Counter, defaultdict

class Main(object):
    
    def __init__(self):
        pass

    def solve(self):
        '''
        insert your code
        '''
        n = int(input())
        candidate = int(math.sqrt(float(n)))

        for i in range(candidate, 0, -1):
            if n % i == 0:
                print(max(int(math.log10(i)) + 1, int(math.log10(n / i)) + 1))
                break
        return None

if __name__ == '__main__':
    m = Main()
    m.solve()


Measured memory_bytes: 3444
N,K = map(int,input().split())
P = [0 for i in range(N)]
for i in range(K):
    a = int(input())
    b = list(map(int,input().split()))
    for j in range(a):
        P[b[j]-1] = 1
m = 0
for i in range(N):
    if P[i]==0:
        m+=1
print(m)

Measured memory_bytes: 9172
import java.util.*;
import java.text.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.nextLine();
        if (S.compareTo("2019/04/30") > 0) {
            System.out.println("TBD");
        } else {
            System.out.println("Heisei");
        }
        try {
            Date date1 = DateFormat.getDateInstance().parse(S);
        }
        catch (ParseException e) {
        }
    }
}


Measured memory_bytes: 22224
#include <iostream>
#include <cstring>
#include <cstdio>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

int main() {
	bool card[2][200];
	int n;

	while (cin >> n, n != 0) {
		memset(card, 0, sizeof(card));
		REP(i,n) {
			int tmp;
			cin >> tmp;
			card[0][tmp-1] = true;
		}
		REP(i,2*n) if (!card[0][i]) card[1][i] = true;
	
		int turn = 0, field = -1;
		int num[2];
		num[0] = num[1] = n;
		while(num[0] != 0 && num[1] != 0) {
			int gcard = -1;
			FOR(i, field + 1, 2*n) {
				if (card[turn][i]) {
					gcard = i;
					break;
				}
			}
			if (gcard == -1) field = -1;
			else {
				card[turn][gcard] = false;
				field = gcard;
				num[turn]--;
			}
			turn = (turn+1)%2;
		}
	
		printf("%d\n%d\n", num[1], num[0]);
	}

	return 0;
}

Measured memory_bytes: 1144
#include <algorithm>
#include <cmath>
#include <iostream>
#include <utility>
#include <numeric>
#include <vector>

int main()
{
    int N;
    std::cin >> N;
    std::vector<std::pair<int, int>> ab(N);
    for (int i = 0; i < N; ++i)
        std::cin >> ab[i].first >> ab[i].second;

    std::sort(ab.begin(), ab.end(), [](auto l, auto r) { return l.second < r.second; });

    auto t = 0;
    for (int i = 0; i < N; ++i) {
        t += ab[i].first;
        if (t > ab[i].second) {
            std::cout << "No" << std::endl;
            return EXIT_SUCCESS;
        }
    }

    std::cout << "Yes" << std::endl;
    return EXIT_SUCCESS;
}


Measured memory_bytes: 1792
#include<iostream>
#include<cmath>
#include<cstdio>
#include<vector>
#include<queue>
#include<string>
#include<algorithm>
#include<set>
#include<map>
using namespace std;
using ll = long long;

int main(){
  ll n,k;
  cin >> n >> k;
  vector<ll> a(n+1);
  for(ll i=1;i<=n;i++) cin >> a[i];
  vector<ll> loop;
  set<ll> st;
  ll p = 1;
  ll start=1;
  while(1){
    if(st.find(p)==st.end()){
      st.insert(p);
      loop.push_back(p);
      p = a[p];
    }
    else{
      start = p;
      break;
    }
  }
  ll temp = loop.size();
  ll s_n;
  for(ll i=0;i<temp;i++){
    if(loop[i]==start) s_n = i;
  }
  if(k < temp){
    cout << loop[k];
  }
  else{
    k-=temp;
    k = k%(temp-s_n);
    cout << loop[s_n+k];
  }
}

Measured memory_bytes: 15488
n=int(input())
cnt=1
nl=[n]
for i in range(1000000):
    if n%2==0:
        n=int(n/2)
        cnt+=1
    elif n%2==1:
        n=3*n+1
        cnt+=1
    if n in nl:
        print(cnt)
        exit()
    nl.append(n)

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

int main() {
  ll n;
  cin >> n;
  string s;
  cin >> s;
  ll count=0;
  string ans;
  for(ll i=0;i<n;i++) {
    ans=ans+s[i];
    if(s[i]==')') {
      count--;
    }
    else {
      count++;
    }
    if(count<0) {
      ans='('+ans;
      count++;
    }
  }
  if(count!=0) {
    for(ll i=0;i<count;i++) {
      ans=ans+')';
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
x1 , y1 , x2 , y2 = map(int,input().split())
y3 = y2 + x2 - x1
x3 = x2 - (y2-y1)
y4 = y1 + x2 - x1
x4 = x1 - (y2-y1)

print(str(x3) + " " + str(y3) + " " + str(x4) + " " + str(y4))

Measured memory_bytes: 3060
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;
 
int main() {
    int N; scanf("%d", &N);
    vector< vector<int> > G(N);
    for(int i=0; i+1<N; i++) {
        int u, v; scanf("%d%d", &u, &v);
        u--; v--;
        G[u].emplace_back(v);
        G[v].emplace_back(u);
    }
    
    vector<int> d1(N), d2(N);
    auto dfs = [&](auto &&self, int cur, int par, vector<int> &d) -> void {
        for(auto to : G[cur]) {
            if(to == par) continue;
            d[to] = d[cur] + 1;
            self(self, to, cur, d);
        }
    };

    vector<int> diam(N), vtx;
    dfs(dfs, 0, -1, d1);
    int v0 = max_element(d1.begin(), d1.end()) - d1.begin();
    dfs(dfs, v0, -1, d2);
    int v1 = max_element(d2.begin(), d2.end()) - d2.begin();

    while(true) {
        diam[v1] = true;
        vtx.emplace_back(v1);
        if(d2[v1] == 0) break;
        for(auto to : G[v1]) {
            if(d2[to] == d2[v1] - 1) {
                v1 = to;
                break;
            }
        }
    }

    bool ok = true;
    for(int i=0; i<N; i++) {
        if(diam[i] or G[i].size() > 1) continue;
        int j = G[i][0];
        ok &= diam[j];
    }

    if(ok) {
        // fprintf(stderr, "ok\n");

        vector< vector<int> > cand(2);

        for(int iter=0; iter<2; iter++) {
            int ptr = 1;
            for(size_t i=0; i<vtx.size(); i++) {
                int deg = (i == 0 or i+1 == vtx.size() ? 1 : 2);
                int diff = G[ vtx[i] ].size() - deg;
                for(int j=0; j<diff; j++) cand[iter].emplace_back(ptr + 1 + j);
                cand[iter].emplace_back(ptr);
                ptr += diff + 1;
            }
            reverse(vtx.begin(), vtx.end());
        }

        vector<int> ans = min(cand[0], cand[1]);
        for(int i=0; i<N; i++) printf("%d%c", ans[i], " \n"[i + 1 == N]);
        // for(auto e : vtx) cerr << e+1 << " ";
        // cerr << endl;
    }
    else {
        puts("-1");
    }
    return 0;
}


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

//ライブラリ始まり (簡潔ver)

//定数
//円周率
const double pi = 3.1415926535897932384;
//天井
const int INF = 1000000000; // = 10^9
const ll LINF = 1000000000000000; // = 10^15
//ABC文字列
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZABC";
const string abc = "abcdefghijklmnopqrstuvwxyzabc";
//よくあるmodくん
const ll MOD = 1000000007; // = 10^9 + 7

//データ構造
//Union_Find木
struct UnionFind {
  vector<int> UF; // UF.at(i) : iの親の番号
  vector<int> SIZE; // SIZE.at(root(i)) : iと連結されてる要素の数
  UnionFind(int N) : UF(N), SIZE(N, 1) { // 最初は全てが根であるとして初期化
    for(int i = 0; i < N; i++) {
      UF.at(i) = i;
    }
  }
  int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
    if (UF.at(x) == x) {
      return x;
    }
    return UF.at(x) = root(UF.at(x));
  }
  void unite(int x, int y) { // xとyの木を併合
    int rx = root(x); // xの根をrx
    int ry = root(y); // yの根をry
    if (rx == ry) {
      return; // xとyの根が同じ(=同じ木にある)時はそのまま
    }
    // xとyの根が同じでない(=同じ木にない)時：小さい方の根を大きい方の根につける
    if (SIZE.at(rx) < SIZE.at(ry)) {
      UF.at(rx) = ry;
      SIZE.at(ry) += SIZE.at(rx);
      SIZE.at(rx) = 0;
    }
    else {
      UF.at(ry) = rx;
      SIZE.at(rx) += SIZE.at(ry);
      SIZE.at(ry) = 0;
    }
  }
  bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
  int size(int x) { // xと連結されてる要素の数を返す
    return SIZE.at(root(x));
  }
};

//ライブラリ終わり

//メイン処理
int main() {
  int N;
  cin >> N;
  vector<ll> L(N);
  for (int i = 0; i < N; i++) {
    cin >> L.at(i);
  }
  sort(L.begin(), L.end());
  int ans = 0;
  for (int i = 0; i < N; i++) {
    for (int j = i + 1; j < N; j++) {
      for (int k = j + 1; k < N; k++) {
        if (L.at(i) != L.at(j) && L.at(j) != L.at(k) && L.at(i) != L.at(k)) {
          if (L.at(k) < L.at(i) + L.at(j)) {
            ans++;
          }
        }
      }
    }
  }
  cout << ans << endl;
}
        

Measured memory_bytes: 3632
#include<stdio.h>
int main(){
	int n,a,b;
	scanf("%d%d%d",&n,&a,&b);
	int i,flag=0;
	for(i=a;i<=b;i++){
		if(i%n==0){
			flag = 1;
			break;
		}
	}
	if(flag==1) printf("OK\n");
	else printf("NG\n");
}

Measured memory_bytes: 1624
#include <cassert>
#include <cstdio>
#include <vector>

using namespace std;

int
main()
{
    int n;
    assert(scanf("%d", &n) == 1);
    const char *ans = "Three";
    for (int i = 0; i < n; i++) {
        char arare;
        assert(scanf("%c", &arare) == 1);
        if (arare == 'Y')
            ans = "Four";
    }
    printf("%s\n", ans);
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define endl '\n';
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr double INFD = 1e100;
constexpr ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
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; }
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
// ---------------------------------------------------------------------------

ll ce(ll a, ll b){
  if(a > 0){
    return (a+b-1)/b;
  }else{
    return a/b;
  }
}

ll fl(ll a,ll b){
  if(a < 0){
    return (a-b+1)/b;
  }else{
    return a/b;
  }
}


int main(){
  ll N,K;
  cin >> N >> K;
  vector<ll> A(N);
  for(int i=0; i<N; i++){
    cin >> A[i];
  }
  sort(A.begin(),A.end());
  ll ok=INF,ng=-INF-1;
  while(ok-ng>1){
    ll mid = (ok+ng)/2;
    ll sum = 0;
    for(int i=0; i<N; i++){
      if(A[i] < 0){
        ll v = ce(-mid,-A[i]);
        sum += i - (lower_bound(A.begin(),A.begin()+i,v) - A.begin());
      }else if(A[i] == 0){
        if(mid >= 0) sum += i;
      }else{
        ll v = fl(mid,A[i]);
        sum += upper_bound(A.begin(),A.begin()+i,v) - A.begin();
      }
    }
    if(sum >= K){
      ok = mid;
    }else{
      ng = mid;
    }
  }
  cout << ok << endl;
  return 0;
}

Measured memory_bytes: 1792
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array;

void main() {
    int x, a, b;
    scan(x);
    scan(a);
    scan(b);
    writeln((x-a)%b);
}



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: 256
N = gets.to_i
A = gets.split.map(&:to_i)

n4 = 0
n2 = 0
other = 0
A.each do |i|
  if i % 4 == 0
    n4 += 1
  elsif i % 2 == 0
    n2 += 1
  else
    other += 1
  end
end

if n2 == 0
  puts other <= n4 + 1 ? "Yes" : "No"
else
  puts other <= n4 ? "Yes" : "No"
end

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

typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1e9+7,inf=mod*mod*3ll;;
#define rep(i,N) for(ll i=0; i<(N); i++)
#define rep1(i,N) for(ll i=1; i<(N); i++)
#define pb push_back

ll N;
ll K;
ll cnt[105];
ll ans;

int main(){

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

cin>>N>>K;
rep(i,K){
	ll d; cin>>d;
	rep1(i,d+1){
		ll A; cin>>A;
		cnt[A]++;
	}
}

rep1(i,N+1){
	if(cnt[i]==0) ans++;
}

cout<<ans<<endl;

}
	


Measured memory_bytes: 3668
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline


def read_int():
    return int(input())


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


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, S):
    c = []
    d = Counter()
    for s in S:
        c = Counter(s)
        h = []
        for k in sorted(c.keys()):
            h.append(k + str(c[k]))
        d[''.join(h)] += 1

    ans = 0
    for v in d.values():
        if v ==1:
            pass
        else:
            ans += (v*(v-1))//2
    return ans


def main():
    N = read_int()
    S = [read_str() for _ in range(N)]
    print(slv(N, S))


if __name__ == '__main__':
    main()


Measured memory_bytes: 27944
#include<stdio.h>
long long R=1,C=1,H[6000010],N[6000010];
//評価関数（いまはMIN）
int hyouka(int a,int b){
  if(C<b)return 1;
  if(C<a||b==0)return 0;
  return N[H[a]]>N[H[b]]?1:0;
}
//挿入関数
void hin(long long a){
  int i=C++;
  for(N[H[0]=R]=a;hyouka(0,i/2);i/=2)H[i]=H[i/2];
  H[i]=R++;
}
//取り出す関数
int hout(){
  int rt=H[1],i,j=2,k=H[--C];
  for(i=1;hyouka(i,C);i=j)H[i]=H[j=i*2+1-hyouka(i*2,i*2+1)];
  H[j/2]=k;
  return rt;
}
long long n[3],m,i,j,k,d[3][1010],t[4010];
int main(){
  for(i=0;i<3;i++)scanf("%lld",&n[i]);
  scanf("%lld",&m);
  for(i=0;i<3;i++){
    for(j=0;j<n[i];j++)scanf("%lld",&d[i][j]);
  }
  for(i=0;i<n[0];i++){
    for(j=0;j<n[1];j++)hin(d[0][i]+d[1][j]);
  }
  k=n[0]*n[1];
  if(k>m)k=m;
  for(i=0;i<k;i++)t[i]=N[hout()];
  R=C=1;
  for(i=0;i<k;i++){
    for(j=0;j<n[2];j++)hin(t[i]+d[2][j]);
  }
  for(i=0;i<m;i++)printf("%lld\n",N[hout()]);
  return 0;
}


Measured memory_bytes: 51456
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <limits.h>
#include <cmath>
#include <queue>
#include <map>
#include <iomanip>
#include <random>
#include <fstream>
#define rep(i, n) for (int i = 0; i < n; i++)
#define pi 3.14159265358979323846
using namespace std;
typedef long long ll;

ll gcd(ll a, ll b)
{
  ll r;
  while ((r = a % b))
  {
    a = b;
    b = r;
  }
  return b;
}

int main()
{

  int r; cin >> r;
  if (r >= 2800){cout << "AGC" << endl;}
  else if (r >= 1200){cout << "ARC" << endl;}
  else {cout << "ABC" << endl;}

  return 0;
}


Measured memory_bytes: 256
// atcoder/abc171/E/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; for (auto& i: v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { for (auto& i: v) is >> i; return is; }
template<typename T> ostream& operator << (ostream& os, set<T> s) { os << "#{"; for (auto& i: s) os << i << ","; os << "}"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; for (auto& i: m) os << i << ","; os << "}"; return os; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

using lli = long long int;
using ull = unsigned long long;
using point = complex<double>;
using str = string;
template<typename T> using vec = vector<T>;

constexpr array<int, 8> di({0, 1, -1, 0, 1, -1, 1, -1});
constexpr array<int, 8> dj({1, 0, 0, -1, 1, -1, -1, 1});
constexpr lli mod = 1e9 + 7;

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.setf(ios_base::fixed);
  cout.precision(15);

  int n;
  while (cin >> n) {
    vec<lli> a(n);
    cin >> a;

    vec<lli> b(n, 0);

    for (int i = 0; i < 40; ++i) {
      vec<lli> c;
      each (j, a) {
        c.push_back(j & (1LL << i));
      }
      each (i, c) i = !!i;

      vec<lli> d;
      each (i, c) {
        if (i) d.push_back(0);
        else d.push_back(1);
      }
      lli x = 0;
      each (i, c) x ^= i;
      bool f = true;
      for (int j = 0; j < c.size(); ++j) {
        f = f && ((c[j] ^ x) == d[j]);
      }
      f = !f;
      for (int j = 0; j < c.size(); ++j) {
        b[j] |= (lli)(d[j] ^ f) << i;
      }
    }

    for (int i = 0; i < b.size(); ++i) {
      if (i) cout << ' ';
      cout << b[i];
    }
    cout << endl;
  }

  return 0;
}


Measured memory_bytes: 11504
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <ccomplex>
#include <cassert>
#include <random>
using namespace std;
using ll = long long;


int main() {
	string s; cin >> s;
	cout << string(s.size(), 'x') << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main
{
    int dx[] = {0, 0, 1, 1, 1, -1, -1, -1};
    int dy[] = {1, -1, 1, 0, -1, 1, 0, -1};
    int h, w;
    int mp[][];
    String s[][];
    
    public static void main(String args[])
    {
	new Main().run();
    }

    void run()
    {
	in();
	
	for(int i = 0; i < h; i++) {
	    for(int j = 0; j < w; j++) {
		
		if(s[i][j].equals(".")) continue;
		for(int k = 0; k < 8; k++) {
		    int mx = j + dx[k];
		    int my = i + dy[k];
		    if(mx < 0 || w <= mx || my < 0 || h <= my) continue;
		    mp[my][mx]++;
		}
		
	    }
	}
	
	out();
    }

    void in()
    {
	Scanner sc = new Scanner(System.in);

	h = sc.nextInt();
	w = sc.nextInt();
	mp = new int[51][51];
	s  = new String[51][51];

	for(int i = 0; i < h; i++) {
	    String line = sc.next();
	    for (int j = 0; j < w; j++)
		s[i][j] = String.valueOf(line.charAt(j));
	}
    }

    void out()
    {
	for(int i = 0; i < h; i++) {
	    for(int j = 0; j < w; j++) {
		if(s[i][j].equals("."))
		    System.out.print(mp[i][j]);
		else
		    System.out.print('#');
	    }
	    
	    System.out.println();
	}
    }
}


Measured memory_bytes: 23764
#include<bits/stdc++.h>
#define PI  3.141592653589793238
using namespace std;
int main()
{
   double a,b,h,m;
   cin>>a>>b>>h>>m;
   long double angle_one=(h/12)*2*PI + (m/60)*PI/6;
   long double angle_two=(m/60)*2*PI;
   long double delta = fabs(angle_one - angle_two);
   long double dist = sqrt(a*a + b*b -2*a*b*cos(delta));
   cout<<setprecision(20)<<dist<<endl;
}


Measured memory_bytes: 4020
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
#include <vector>
#include <set>
using namespace std;
int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a + b == c || a + c == b || a == b + c)cout << "Yes";
	else cout << "No";
}


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

int main() {
    int N;
    cin >> N;
    vector<int> a(200001);
    for (int i = 2; i <= N; i++) {
        cin >> a[i];
    }
    vector<int> d(200001);
    for (int i = 2; i <= N; i++) {
        ++d[a[i]];
    }
    erep1(i, N) cout << d[i] << endl;
}

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

int main() {
  vector<int> T(5);
  for (int i=0; i<5; i++) cin >> T[i];
  int max_gap = 0, total = 0;
  for (int i=0; i<5; i++) {
    total += ((T[i] + 9)  / 10) * 10;
    int mod = T[i] % 10;
    if (mod > 0) max_gap = max(max_gap, 10 - mod);
  }
  cout << total - max_gap << endl; return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = getInt(sc);
		System.out.println(n * n * n);
	}

	/**
	 * *汎用メソッド<br>
	 * 入力した配列に対する順列を取得
	 *
	 * @param numArray
	 * @return
	 */
	private static List<Integer[]> getPermutation(int[] numArray) {
		List<Integer[]> permutation = new ArrayList<>();
		Integer[] ans = new Integer[numArray.length];
		boolean[] used = new boolean[numArray.length];

		return buildPermutaion(permutation, numArray, ans, used, 0);
	}

	/**
	 * *汎用メソッド(内部)<br>
	 * 入力した配列に対する順列を作成
	 *
	 * @param list
	 * @param numArray
	 * @param ans
	 * @param used
	 * @param depth
	 * @return
	 */
	private static List<Integer[]> buildPermutaion(List<Integer[]> list, int[] numArray, Integer[] ans, boolean[] used,
			int depth) {

		// 全部使い切った時=>できた順列を返す
		if (depth == numArray.length) {
			list.add(ans.clone());
			return list;
		}
		// 使い切っていない場合

		for (int i = 0; i < numArray.length; i++) {
			if (used[i]) {
				continue;
			}
			ans[depth] = numArray[i];
			used[i] = true;
			list = buildPermutaion(list, numArray, ans, used, depth + 1);

			used[i] = false;
		}

		return list;
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をlongで返却
	 *
	 * @return
	 */
	public static long getLong(Scanner sc) {

		return Long.parseLong(sc.next());
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をintで返却
	 *
	 * @return
	 */
	public static int getInt(Scanner sc) {

		return Integer.parseInt(sc.next());
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をStringで返却
	 *
	 * @return
	 */
	public static String getString(Scanner sc) {

		return sc.next();
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をint配列で返却
	 *
	 * @return
	 */
	public static int[] getIntArray(Scanner sc) {
		String line = "";
		// 直前にnext()を実行していると改行コードだけ取ってしまうのでその対策
		while (line.equals("")) {
			line = sc.nextLine();
		}

		String[] strArray = line.split(" ");
		int[] intArray = new int[strArray.length];
		for (int i = 0; i < strArray.length; i++) {
			intArray[i] = Integer.parseInt(strArray[i]);
		}
		return intArray;
	}

}


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

using namespace std;

string s, t;
int a[105], b[105];

int main()
{
    cin >> s >> t;
    int S = s.size();
    int T = t.size();
    for (int i = 0; i < S; i++)
        a[i+1] = s[i] - 'a';
    for (int i = 0; i < T; i++)
        b[i+1] = t[i] - 'a';
    sort (a+1, a+S+1);
    sort (b+1, b+T+1);
    for (int i = 1; i <= T/2; i++)
        swap(b[i], b[T+1-i]);
    for (int i = 1; i <= min(S,T); i++)
    {
        if (a[i]<b[i])
        {
            cout << "Yes";
            return 0;
        }
        if (a[i]>b[i])
        {
            cout << "No";
            return 0;
        }
    }
    if(S<T) cout << "Yes";
    else cout << "No";
}


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

#define ll long long
#define pb push_back
const int N = 1e5+12;
int n,m,k;


int main()
{
    cin >> n;
    if(n == 1)
    {
        cout << "Hello World";
    }else{
        int x,y;
        cin >> x >> y;
        cout << x +y ;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <fstream>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <list>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <climits>
using namespace std;

struct score {
	long teamNum;
	long accepted;
	long time;
	vector<long> miss;
	bool operator==(score s) const {
		return this->accepted == s.accepted && this->time == s.time;
	};
	bool operator<(score s) const {
		return this->accepted != s.accepted ? this->accepted > s.accepted : (this->time != s.time ? this->time < s.time : this->teamNum > s.teamNum);
	};
};

int main() {
	while(1){
		int M, T, P, R;
		cin >> M >> T >> P >> R;
		
		if(!M && !T && !P && !R) break;
		
		score *sc = new score[1+T];
		for(int i = 1; i <= T; i++){
			sc[i].teamNum = i;
			sc[i].accepted = sc[i].time = 0;
		}
		for(int i = 0; i < R; i++){
			int m, t, p, r;
			cin >> m >> t >> p >> r;
			
			if(r){
				sc[t].miss.push_back(p);
			}else{
				sc[t].accepted++;
				sc[t].time += m + 20 * count(sc[t].miss.begin(), sc[t].miss.end(), p);
			}
		}
		
		sort(&sc[1], &sc[1+T]);
		for(int i = 1; i <= T; i++){
			cout << sc[i].teamNum << (i==T ? '\n' : (sc[i]==sc[i+1] ? '=' : ','));
		}
	}
	return 0;
}

Measured memory_bytes: 1396
/*
 * main.cpp
 *
 *  Created on: ??‏/??‏/????
 *      Author: Israa
 */

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

int main() {
	ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	string s, k;
	int cnt = 0;
	cin>>s>>k;
	for(int i=0; i<s.length(); i++) {
	    if(s[i] != k[i]) cnt++;
	}
	cout<<cnt;
	return 0;
}


Measured memory_bytes: 3692
import java.util.Scanner;

public class Main {

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

		int A = s.nextInt();
		int B = s.nextInt();
		int K = s.nextInt();
		int check = 0;

		if ((B - A + 1) / 2 < K) {
			for (int i = A; i <= B; i++) {
				System.out.println(i);
			}
		} else {
			for (int i = A; i < A + K; i++) {
				System.out.println(i);
				check = i;
			}

			for (int j = B - K + 1; j <= B; j++) {
				if (check < j) {
					System.out.println(j);
				}
			}
		}
	}
}


Measured memory_bytes: 21844
#include<stdio.h>
#include<string.h>
int main(void){
  int a,i;
  scanf("%d",&a);
  double num,sum=0;
  char coin[3],btc[]="BTC";
  for(i=0;i<a;i++){
    scanf("%lf",&num);
    scanf("%s",coin);
    if(strcmp(coin,btc)==0){
      num*=380000.0;
    }
    sum+=num;
  }
  printf("%lf",sum);
  return 0;
}


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

int main(){
    int n,k;
    cin >> n >> k;
    vector<int> a(n);
    vector<int> r(n);
    for(int i=0; i<n; i++) cin >> a[i];
    int sum=0;
    for(int i=0; i<n; i++) sum += a[i];
    
    int d[100000];
    int x=0;
    d[x]=sum;
    x++;
    int p=2;
    while(p*p <= sum){
        if(sum%p == 0){
            d[x] = p;
            x++;
            d[x] = sum/p;
            x++;
        }
        p++;
    }
    int ans=1;
    for(int j=0; j<x; j++){
        p=d[j];
        for(int i=0; i<n; i++) r[i]=a[i]%p;
        sort(r.begin(), r.end());
        int y=0;
        for(int i=0; i<n; i++) y += r[i];
        int z = 0;
        for(int i=n-y/p; i<n; i++) z += (p-r[i]);
        if(z <= k) ans = max(ans,p);
    }
    cout << ans << endl;


}

Measured memory_bytes: 256
package main

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

func main() {
	s := bufio.NewScanner(bufio.NewReader(os.Stdin))
	s.Split(bufio.ScanWords)

	n := nextInt(s)
	a := make([]int, n)

	for i := 0; i < n; i++ {
		a[i] = nextInt(s)
	}

	fmt.Println(solve(a))
}

func solve(a []int) int {
	return min(solveSub(1, a), solveSub(-1, a))
}

func solveSub(headSign int, a []int) int {
	sign := headSign
	s := 0
	r := 0

	for _, ax := range a {
		var n int
		if sign == 1 {
			n = max(s+ax, sign)
		} else {
			n = min(s+ax, sign)
		}

		r += (n - (s + ax)) * sign
		s = n
		sign = -sign
	}

	return r
}

func max(a int, b int) int {
	if a > b {
		return a
	}

	return b
}

func min(a int, b int) int {
	if a < b {
		return a
	}

	return b
}

func nextInt(s *bufio.Scanner) int {
	s.Scan()
	n, _ := strconv.Atoi(s.Text())
	return n
}


Measured memory_bytes: 3072
#include<stdio.h>
#include<stdlib.h>

int main(void)
{
    int n,a[3000],i,ans=0;

    scanf("%d",&n);
    for ( i = 0; i < n; i++)
    {
        scanf("%d",a+i);
    }

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

    printf("%d",ans);

    return 0;
}

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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

struct SPI{
    string s; 
    int p; 
    int id;
};

void Main(){
    int n; cin >> n;
    vector<SPI> data;
    
    rep(i, n){
        string s; int p; cin >> s >> p;
        data.pb({s, p, i + 1});
    }
    sort(all(data), [&](SPI x, SPI y){
        return x.s == y.s ? x.p > y.p : x.s < y.s;    
    });
    
    for(auto [s, p, id] : data){
        cout << id << endl;
    }
    return;
}

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

Measured memory_bytes: 3568
#include <stdio.h>
#include <string.h>
int main () {
	
	int k;
	scanf("%d", &k);
	char str[100];
	scanf("%s", str);
	int len = strlen(str);
	
	if (len <= k){
		printf("%s", str);
	}
	else {
		for (int i = 0; i < k; i++){
			printf("%c", str[i]);
		}
		puts("...");
	}
	
	return 0;
}

Measured memory_bytes: 1676
import java.util.Scanner;

public class Main {

	private static int gcd(int a, int b, int c) {
		// 最小値を探す
		int min = 201;
		if(a <= b && a <= c) {
			min = a;
		}
		if(b <= a && b <= c) {
			min = b;
		}
		if(c <= a && c <= b) {
			min = c;
		}
		int gcd = 1;

		for(int i = min; i > 1; i--) {
			if(a % i == 0 && b % i == 0 && c % i == 0) {
				gcd = i;
				break;
			}
		}
		return gcd;
	}

	public static void main(String[] args) {
		Scanner sca = new Scanner(System.in);
		int k = sca.nextInt();
		long ans = 0L;
		for(int i = 1; i <= k; i++) {
			for(int j = 1; j <= k; j++) {
				for(int l = 1; l <= k; l++) {
					ans += gcd(i, j, l);
				}
			}
		}
		System.out.println(ans);

		// 後始末
		sca.close();
	}
}

Measured memory_bytes: 35888
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
int main(){
  string s,t;
  cin>>s>>t;
  bool f=0;
  for(int i=0;i<s.size();i++){
    if(s==t)f=1;
    char c=t[0];
    t.erase(0,1);
    t+=c;
  }
  if(s==t)f=1;
  cout<<(f?"Yes":"No")<<endl;
  return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**5+10)

N,M=map(int,input().split())

G=[[] for i in range(N)] #グラフを隣接リストで表現
for j in range(M):
    x,y=map(lambda x:int(x)-1,input().split())
    G[x].append(y)

dp=[-1]*N

def longest_path(v): #vを始点とした時の最長パスの長さ
    if dp[v] != -1: #更新済みの場合
        return dp[v]
    
    #更新されていなかった場合
    tmp_max = 0
    for u in G[v]:
        tmp_max = max(tmp_max,longest_path(u)+1)
    dp[v] = tmp_max #きちんとメモする
    
    return dp[v]

ans=0
for i in range(N):
    ans = max(ans,longest_path(i))

print(ans)

Measured memory_bytes: 121096
'use strict'

const appear = arr => {
    let obj = {}
    arr.forEach(v => {
        if(obj[v] === undefined){
            obj[v] = 0
        }
        obj[v]++
    })
    return [maxObj(obj), obj]
}

const maxObj = (obj) => {
    let m = null
    let max = 0
    for(let key in obj){
        if(obj[key] > max){
            max = obj[key]
            m = key
        }
    }
    return m
}

const main = (input) => {
    const arr = input.split('\n')[1].split(' ').map(v => parseInt(v))
    const arr0 = arr.filter((v, i) => i % 2 === 0)
    const arr1 = arr.filter((v, i) => i % 2 !== 0)
    const m0d = appear(arr0)
    const m0 = m0d[0]
    const m0o = m0d[1]
    const m1d = appear(arr1)
    const m1 = m1d[0]
    const m1o = m1d[1]


    if(m0 === m1){
        // 最頻出の値をコピー
        const m0c = m0o[m0]
        const m1c = m1o[m1]

        // それぞれの最頻出を削除
        delete m0o[m0]
        delete m1o[m1]
        
        // 次に多く出てくるものの個数を取得
        const o0 = Object.keys(m0o).length === 0 ? 0 : m0o[maxObj(m0o)]
        const o1 = Object.keys(m1o).length === 0 ? 0 : m1o[maxObj(m1o)]

        // arr0は最頻出、arr1は次頻出を増やすパターンと
        // arr0は次頻出、arr1は最頻出を増やすパターンがある
        if(m0c + o1 > m1c + o0){
            console.log(arr.length - (m0c + o1))
        }else{
            console.log(arr.length - (m1c + o0))
        }
    }else{
        // 最頻出が同じでないとき
        console.log(arr.length - m0o[m0] - m1o[m1])
    }
}

main(require('fs').readFileSync('/dev/stdin', 'utf-8'))

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

using namespace std;

int main(){
	int a,sum = 0,i=0;
	char s[20010];
	stack<int> S;
	stack<pair<int,int> > S1;
	vector<int> res;
	scanf("%s",s);
	while(s[i]){
		if(s[i]=='\\') S.push(i);
		else if(s[i]=='/'&&S.size()){
			int j = S.top();S.pop();
			a = i - j;
			sum += a;
			while(S1.size()&&S1.top().first>j){
				a += S1.top().second;S1.pop();
			}
			S1.push(make_pair(j,a));
		}
		i++;
	}
	while(S1.size()){
		res.push_back(S1.top().second);
		S1.pop();
	}
	reverse(res.begin(),res.end());
	int n = res.size();
	cout<<sum<<endl;
	cout<<n;
	for(i=0;i<n;)
		printf(" %d",res[i++]);
	cout<<endl;
	return 0;
}


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

int main() {
  int n;
  cin >> n;
  if (n==0) {
    cout << 0;
  }
  if (n==1) {
    cout << 1;
  }
  if (n==10) {
    cout << 1;
  }
  if (n==11) {
    cout << 2;
  }
  if (n==100) {
    cout << 1;
  }
  if (n==101) {
    cout << 2;
  }
  if (n==110) {
    cout << 2;
  }
  if (n==111) {
    cout << 3;
  }
} 
    

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

using namespace std;

typedef long long ll;

ll n, m;

bool check(ll x)
{
    ll A = n, B = m;
    ll needs = x;
    needs -= n;
    needs = max(needs, 0ll);
    if (2 * needs > m)
    {
        return 0;
    }
    return (m - 2 * needs >= 2 * x);
}

int main()
{
#ifdef ONPC
    freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
#else
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
#endif
    cin >> n >> m;
    ll l = 0, r = 1e13 + 1;
    while (l < r - 1)
    {
        ll m = (l + r) / 2;
        if (check(m))
        {
            l = m;
        }
        else
        {
            r = m;
        }
    }
    printf("%lld\n", l);
}


Measured memory_bytes: 256
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N, K = LI()

    ans = 0
    for i in range(1, N + 1):
        tmp = 1 / N
        score = i
        while 1 <= score <= K - 1:
            score *= 2
            tmp *= 0.5
        ans += tmp

    print(ans)

if __name__ == '__main__':
    resolve()


Measured memory_bytes: 10032
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#include<time.h>
#include<stdlib.h>
#define pb push_back
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define ull unsigned long long
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/__gcd((a),(b))
#define clr(x) x.clear()
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vi>
#define mp make_pair
#define hell 1000000007

using namespace std;

int main()
{
   	IOS
	int n,m;
	cin>>n>>m;
	vi arr[m];
	for(int i=0;i<m;i++)
	{
	    int t;
	    cin>>t;
	    while(t--)
        {
            int temp;
            cin>>temp;
            arr[i].pb(temp);
        }
	}
	int p[m];
	for(int i=0;i<m;i++)
	{
	    cin>>p[i];
	}
	bool on[n+1];
	ll res=0;
	for(int i=0;i<(1<<n);i++){
	    memset(on,false,sizeof on);
        for(int j=0;j<n;j++)
            if(i&(1<<j))
            on[j+1]=true;
        bool flag=true;
        for(int j=0;j<m;j++)
        {
            int ctr=0;
            for(int k=0;k<arr[j].size();k++)
            {
                if(on[arr[j][k]])
                    ctr++;
            }
            if(ctr%2!=p[j])
            {
                flag=false;
                break;
            }
        }
        if(flag)
            res++;
	}
	cout<<res;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#define MAX 500000
#define INFTY 1000000001
using namespace std;

int L[MAX/2 + 2],R[MAX/2 + 2];
int res;

void merge(int A[],int left,int mid,int right){
	int n1 = mid - left;
	int n2 = right - mid;
	for(int i = 0;i < n1;i++){
		L[i] = A[left + i];
	}
	for(int i = 0;i < n2;i++){
		R[i] = A[mid + i];
	}
	L[n1] = INFTY;
	R[n2] = INFTY;
	int i = 0;
	int j = 0;
	for(int k = left;k < right;k++){
		if(L[i] <= R[j]){
			A[k] = L[i];
			i = i + 1;
		}
		else{
			A[k] = R[j];
			j = j + 1;
		}
		res++;
	}
}

void mergeSort(int A[],int left,int right){
	int mid;
	if(left+1 < right){
		mid = (left + right)/2;
		mergeSort(A, left, mid);
		mergeSort(A, mid, right);
		merge(A, left, mid, right);
	}
}

int main(){
	int n,a[MAX + 2];
	res = 0;
	cin >> n;
	for(int i = 0;i < n;i++){
		scanf("%d",&a[i]);
	}

	mergeSort(a,0,n);

	for(int i = 0;i < n;i++){
		if(i != n-1){
			printf("%d ",a[i]);
		}
		else cout << a[i] <<endl;
	}
	cout << res <<endl;
	return 0;
}

Measured memory_bytes: 5176
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


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

  cout << min(N*A, B) << endl;
  
  return 0;
}



Measured memory_bytes: 256